motzi
April 4, 2023, 1:27pm
1
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:
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
{
var worldInverse = world;
worldInverse.Invert();
Matrix.Multiply(ref world, ref renderView.View, out var worldView);
foreach (var perDraw in perDrawParams)
{
switch (perDraw)
{
case PerDrawParameters.World:
parameters.Set(TransformationKeys.World, ref world);
break;
case PerDrawParameters.WorldInverse:
parameters.Set(TransformationKeys.WorldInverse, ref worldInverse);
break;
case PerDrawParameters.WorldInverseTranspose:
var worldInverseTranspose = worldInverse;
worldInverseTranspose.Transpose();
parameters.Set(TransformationKeys.WorldInverseTranspose, ref worldInverseTranspose);
break;
case PerDrawParameters.WorldView:
parameters.Set(TransformationKeys.WorldView, ref worldView);
Matrix thread for reference:
You're invited to talk on Matrix. If you don't already have a client this link will help you pick one, and join the conversation. If you already have one, this link will help you join the conversation
motzi
April 4, 2023, 1:32pm
2
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);
}
};
Elias
November 6, 2023, 11:57am
3
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.
Elias
November 7, 2023, 11:05am
5
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.