Jump to content
  • Advertisement
Sign in to follow this  
maxest

vertex transform in vertex shader

This topic is 4271 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!