VL.Addons

Hey, spending some time with the TextureArrays in the Addons and have two questions, if you don’t mind.

  1. Is it also possible to sample TextureArrays as GPU(Float32) for a Displacement map?
  2. And could I somehow also apply TextureFX to these?

It should be, but for some reason it doesn’t work. As soon as an “instanced sample” is used as input for Displacement the material doesn’t compile. It works when using it for Metalness or Roughness on the Material directly or as input for Blend [Transparency] for example (see the Displacement patch for details).
So I guess this is a bug in VL.Stride or Stride. Idk if the devvvvs (@Elias ?) have time to look into it. If you need it for a commercial project maybe you can speed things up by requesting support.

You could use the existing TextureFX like this for example:

Other than that I think you’ll have to rewrite the shaders so they sample from the correct array slice. Made an example for ‘Bias’ (also attached).
There might be better ways to do this, maybe @tonfilm has an idea.

shader BiasTextureArrayFloat32_ShaderFX : ComputeFloat, ShaderBaseStream, Texturing
{
    cbuffer PerMaterial //when used in materials
    {
        stage uint ArrayTextureSize = 1;
        stage compose ComputeFloat Amount = 1;
    }

    rgroup PerMaterial //when used in materials
    {
        stage Texture2DArray ArrayTexture;
    }

    float bias(float x, float ctrl = 0.5)
    {
 	    return ctrl > 0 ?  (x / ((((1.0/ctrl) - 2.0)*(1.0 - x))+1.0)) :  1-(x / ((((1.0/abs(ctrl)) - 2.0)*(1.0 - x))+1.0));
    }

    override float Compute()
    {
        float3 uvz = float3(streams.TexCoord, streams.InstanceID % ArrayTextureSize);
       
        float4 color = ArrayTexture.Sample(LinearSampler, uvz);

        float amount = Amount.Compute();

        return bias(color.r, amount);
    }
};

Displacement Instanced and TextureFX.7z (1.3 MB)

1 Like