HLSL How to flip geometry horizontally
Posted
by
cubrman
on Game Development
See other posts from Game Development
or by cubrman
Published on 2013-10-24T10:57:38Z
Indexed on
2013/10/24
16:12 UTC
Read the original article
Hit count: 294
I want to flip my asymmetric 3d model horizontally in the vertex shader alongside an arbitrary plane parallel to the YZ plane. This should switch everything for the model from the left hand side to the right hand side (like flipping it in Photoshop). Doing it in pixel shader would be a huge computational cost (extra RT, more fullscreen samples...), so it must be done in the vertex shader. Once more: this is NOT reflection, i need to flip THE WHOLE MODEL.
I thought I could simply do the following:
- Turn off culling.
Run the following code in the vertex shader:
input.Position = mul(input.Position, World); // World[3][0] holds x value of the model's pivot in the World. if (input.Position.x <= World[3][0]) input.Position.x += World[3][0] - input.Position.x; else input.Position.x -= input.Position.x - World[3][0]; ...
The model is never drawn. Where am I wrong? I presume that messes up the index buffer. Can something be done about it?
P.S. it's INSANELY HARD to format code here.
Thanks to Panda I found my problem. SOLUTION:
// Do thins before anything else in the vertex shader.
Position.x *= -1; // To invert alongside the object's YZ plane.
© Game Development or respective owner