it's been long since the last time I worked on my project, so my question may be silly: I've implemented support for sprites (2D images) in my 3D engine. In this case, I don't need the sprites to face the camera, but to remain in their normal position & rotation, as any other 3D object (I think it's called "world-oriented billboard").
I've achieved this, but there's a problem: when I move the camera, the sprite will slightly move as well (it's not an optical illusion, it's really moving). I'm almost sure there's something missing in my shaders, although I cannot get to understand why this is happening. I've checked several times the HLSL & I cannot find anything. Also checked the vertex declaration & I find nothing.
(I think the erroneous translation may be the camera's delta in the opposite way: you 'look' up in a 10º angle : the sprite moves down in a 10º angle. Although I'm not sure it's exactly like this, it may be something about it).
I attach HLSL Vertex Shader code & images:
VS_OUTPUT output; // Calculate the position of this billboard vertex. float3 position = input.Position; position.x+=(input.TexCoord.x) * width; position.y+=(input.TexCoord.y) * height; // Apply the camera transform. float4 viewPosition = mul(float4(position, 1), View); output.Position = mul(viewPosition, Projection); output.TexCoord = input.TexCoord; // Compute lighting. float diffuseLight = max(-dot(input.Normal, LightDirection), 0); output.Color.rgb = diffuseLight * LightColor + AmbientColor; output.Color.a = 1; return output;
Do you think you can help me with this one?
Thanks so much!