• Advertisement
Sign in to follow this  

Vertex Shader Weirdness

This topic is 3870 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

Hey guys, I have a weird situation occuring. In my shader I am animating vertices using bones and weights, etc. It works great assuming my World is identity. If I Translate to (0,10,0). My model is completely wrong and it looks likes rays of vertices are going into the screen (think cone shapes). It's all messed up basically. The weird thing is, if I just Rotate the World, then my model renders fine. The first thought that came into my head was maybe its a handedness issue. However, I tried reversing the mutl call in my shader from (pos,wvp) to (wvp,pos), that of course did not help. Any thoughts on why if I translate my models goes nuts, but if I rotate its ok? Thanks Jeff.

Share this post

Link to post
Share on other sites

Here's my shader... this works as long as I don't translate to any position, rotating works fine.

texture tex0;
float4x4 Bones[29];
float3 LightVec;
float4 Diffuse;
float4 Ambient;

struct vertexInput {
float3 Position: POSITION;
float4 Weight:BLENDWEIGHT;
float4 Indices:BLENDINDICES;
float3 Normal: NORMAL;
float2 TexCoord:TEXCOORD0;

struct vertexOutput {
float4 HPosition: POSITION;
float2 TexCoord: TEXCOORD0;
float4 Color: COLOR0;

vertexOutput main(vertexInput IN)
vertexOutput OUT;

float4 tempPos;
tempPos.xyz = IN.Position.xyz;
tempPos.w = 1.0;

float3 pos= 0;
float3 normal= 0;

float4 i;

i = IN.Indices;

pos = mul(Bones[i.x], tempPos) * IN.Weight.x;
pos += mul(Bones[i.y], tempPos) * IN.Weight.y;
pos += mul(Bones[i.z], tempPos) * IN.Weight.z;
pos += mul(Bones[i.w], tempPos) * IN.Weight.w;

float3x3 m;

m[0].xyz = Bones[i.x][0].xyz;
m[1].xyz = Bones[i.x][1].xyz;
m[2].xyz = Bones[i.x][2].xyz;

normal += mul(m, IN.Normal)* IN.Weight.x;

m[0].xyz = Bones[i.y][0].xyz;
m[1].xyz = Bones[i.y][1].xyz;
m[2].xyz = Bones[i.y][2].xyz;

normal += normalize(mul(m, IN.Normal)* IN.Weight.y);

normal = normalize(normal);

OUT.Color.xyzw = (max(dot(normal, LightVec),0).xxxx+Ambient)*Diffuse;

OUT.TexCoord.xy = IN.TexCoord.xy;

float4 tempPos2;

tempPos2.xyz = pos.xyz;
tempPos2.w = 1.0;

OUT.HPosition = mul(tempPos2,matWVP);

return OUT;

struct pixelInput {
float4 Color : COLOR;
float2 Tex : TEXCOORD0;

sampler Sampler = sampler_state
Texture = (tex0);
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;

float4 mainps( pixelInput IN) : COLOR
return tex2D(Sampler, IN.Tex);

technique technique0
pass p0
VertexShader = compile vs_2_0 main();
PixelShader = compile ps_2_0 mainps();

Let me know if you have any suggestions.


Share this post

Link to post
Share on other sites
What application code do you use to generate mWVP? I can't see anything obviously wrong with your code.

By process of elimination, what happens if you comment out the bone animations and do a translation? How about 1-bone, 2-bone etc... can you identify which calculation step causes things to go crazy? Have you tried debugging via PIX?


Share this post

Link to post
Share on other sites

Thanks for the tips, I found the problem. My internal translate function was building the translation matrix wrong. Once I fixed that, it worked!

thanks again!

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement