1
\$\begingroup\$

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:

  1. Turn off culling.
  2. 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. 
\$\endgroup\$
7
  • \$\begingroup\$ You never flip geomatry. thats impossible with out geomatry shader. and pretty pointless. do the full model in your modeling tool instead- \$\endgroup\$ Commented Oct 24, 2013 at 11:06
  • \$\begingroup\$ There IS a point for us. We will need to add a lot more animations if we don't flip it. Could you please explain WHY it is impossible? \$\endgroup\$ Commented Oct 24, 2013 at 12:06
  • \$\begingroup\$ Befor hand, do you have a Half object and just want to flip it to the otherside? or do you have a Whole object and just want to invert it? your question was quite diffuse. \$\endgroup\$ Commented Oct 24, 2013 at 12:16
  • \$\begingroup\$ Nope I want to flip the whole object, this is not reflection. \$\endgroup\$ Commented Oct 24, 2013 at 12:17
  • \$\begingroup\$ You do know that both input.Position.x += World[3][0] - input.Position.x; and input.Position.x -= input.Position.x - World[3][0]; are equivalent to input.Position.x = World[3][0];, right? You're setting the X coordinates of all vertices to the same value... \$\endgroup\$ Commented Oct 24, 2013 at 12:33

1 Answer 1

4
\$\begingroup\$

why don't you use a transformation matrix and pass it into the shader? Flipping can be done with a negative scale value. But maybe misunderstood you, Iam not sure.

\$\endgroup\$
1
  • \$\begingroup\$ I won't try it as I found my own way (it should be the same really but in the shader). Good thing it flips the TexCoords as well. Check the main question for solution. \$\endgroup\$ Commented Oct 24, 2013 at 12:58

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.