World Matrix does not get set for shaders

I discovered a bug with the World matrix in shaders, which apparently does not get set and stays at the identity.

Using Renderdoc one can easily see that this is off:
grafik

The transformation here should be a scaling by 4, which is reflected in the WorldInverse but not in the World Matrix.

@tonfilm said:

this is indeed a bug, the world matrix doesnt get written in some cases

Matrix thread for reference:

here is a quick shader for tryout:

shader ConstantColorVSTextured_DrawFX : ConstantColor_DrawFX, Texturing
{
    float mix = 0.5;
    
    override stage void VSMain()
    {
        streams.ShadingPosition = mul(streams.Position, WorldViewProjection); // works
        
        // float4 pos = mul(streams.Position, World);              // world matrix is ignored?
        // streams.ShadingPosition = mul(pos, ViewProjection);

        streams.Color = Texture0.SampleLevel(LinearSampler, streams.TexCoord, 0);
    }
    
    override stage void PSMain() 
    {
        float4 texColor = Texture0.Sample(LinearSampler, streams.TexCoord);
        streams.ColorTarget = lerp(streams.Color, texColor, mix);
    }
};

Finally had a look at this. Turns out the World matrix was only working in DrawFX when writing the pin, it didn’t take the matrix from downstream into account. Fixed in upcoming previews, for details see [Stride] Fixes world matrix from downstream not taken into account in… · vvvv/VL.StandardLibs@5a45eae · GitHub

3 Likes

It seems that the compute shader doesn’t get a world pin anymore after this change, which is breaking. It should also have the “World” pin and apply the parent transformation to it.

It never had a world pin, see https://github.com/vvvv/VL.StandardLibs/blob/main/VL.Stride.Runtime/src/Rendering/Effects/EffectShaderNodes.Utils.cs#L102 - it always filtered it out. So if that’s desired it can be added in a separate commit.

1 Like

You are right, the matrix is only available in compute shader code when inheriting from Transformation, it worked once, then for a while not anymore, and this new commit fixes it.

Having a pin when World is used would be nice so that you can add one local transformation on top.