Sign in to follow this  
maxest

vertex transform in vertex shader

Recommended Posts

i've got a problem with that shader:
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..?

Share this post


Link to post
Share on other sites
Well... transposing didn't work. However, i multiplied those two matrices manually. I got matrix:


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...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this