void main(in float4 position: POSITION,
in float3 transformedPosition: NORMAL,
in float2 texCoord: TEXCOORD0,
in float4 color: COLOR,
out float4 oPosition: POSITION,
out float2 oTexCoord: TEXCOORD0,
out float4 oColor: COLOR,
uniform float4x4 ModelViewProj)
{
float angle = position.w;
position.w = 1.0f;
float4x4 translate = { 1.0f, 0.0f, 0.0f, transformedPosition.x,
0.0f, 1.0f, 0.0f, transformedPosition.y,
0.0f, 0.0f, 1.0f, transformedPosition.z,
0.0f, 0.0f, 0.0f, 1.0f };
float4x4 rotationZ = { cos(angle), -sin(angle), 0.0f, 0.0f,
sin(angle), cos(angle), 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f };
float4x4 transformMatrix = rotationZ * translate;
position = mul(transformMatrix, position);
oPosition = mul(ModelViewProj, position);
oTexCoord = texCoord;
oColor = color;
}
- position.w keeps the angle which i want to use to rotate the vertex. But of course this value needs to be 1.0 so i copy the angle to a specific variable and assign 1.0 to position.w
- trasnformedPosition is a translation vector of the vertex
I want this code to (first) translate the vertex, and after that, rotate it. Unfortunately it doesn't work. When i run this shader i can only see my vertices going away from and returning to the camera.
But the most strange in that is that when i use separately rotationZ or translate matrix in transformMatrix it's all okay. But when i multiply these two matrices it's all messed up. Does anyone know what could be wrong? Probably it's something with mutliplying the matrices, but why..?
vertex transform in vertex shader
i've got a problem with that shader:
you could try transposing your final transformation matrix, maybe its a problem of column/row major order
or just multiply the position vector from the left
or just multiply the position vector from the left
Well... transposing didn't work. However, i multiplied those two matrices manually. I got matrix:
And this fully works! Besides i read in user manual that to multiply the matrcies i need to use mul function. Using "*" is unaccetable i guess. That's quite strange...
float4x4 macierz = { cos(angle), -sin(angle), 0.0f, transformedPosition.x, sin(angle), cos(angle), 0.0f, transformedPosition.y, 0.0f, 0.0f, 1.0f, transformedPosition.z, 0.0f, 0.0f, 0.0f, 1.0f };
And this fully works! Besides i read in user manual that to multiply the matrcies i need to use mul function. Using "*" is unaccetable i guess. That's quite strange...
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement