I'm rendering mirrored geometry by flipping it's world matrix. Before rendering mirrored geometry I set CULL_FRONT rasterizer state (for normal geometry it's CULL_BACK). This works perfectly.

However, I've started implementing instancing and would like to instance mirrored and not mirrored geometry together. What's optimal way to do it?

So far I've considered:

  • CULL_NONE, but it has huge impact on shading performance
  • Geometry shader to flip triangles, but GS is generally slow

Is there any other option? I've found SV_IsFrontFace, but there's not much documentation about it. I would like to tell GPU in VS: Hey, this triangle should be flipped.

  • 1
    \$\begingroup\$ The VS generally only has knowledge of vertices. I'd suggest that you write up the GS code (it shouldn't take too long) then benchmark it and compare with keeping the two passes separate. \$\endgroup\$ Feb 10, 2017 at 16:24
  • 1
    \$\begingroup\$ GS seems very slow, 14k primitives, 0.26ms. Without GS 0.16ms. When primitive count is higher, it's even worse (7.5ms vs 1.3ms for 935k primitives). Tested with simple pass-through GS, triangle in, maxvertexcount 3, release, measure through GPU queries. When there's no other option, I'll have to keep passes separate. \$\endgroup\$ Feb 10, 2017 at 17:16
  • \$\begingroup\$ so there is a super cool thing you can do if your GPU supports VPAndRTArrayIndexFromAnyShaderFeedingRasterizer you can use uint RT : SV_RenderTargetArrayIndex; in your vertex shader to select different Rendertargets\viewports. Setup two render targets and draw with instancing one is for standard meshes other is for reflection meshes Give each mesh an ID vertex element that maps to the correct RT for that mesh. It works like a GS just with vertex and pixel shaders. \$\endgroup\$ Feb 11, 2017 at 2:39
  • \$\begingroup\$ @JustinWilliamStanleyBryant Unfortunately no, I'm targeting DirectX 11.0, but it's a great idea, thanks! \$\endgroup\$ Feb 12, 2017 at 0:19

1 Answer 1


I would sort the instances mirror/no mirror. Make the first draw call, update the rasterizer with the cull mode you want then render the mirror'd instances. Its overhead on CPU, but it shouldnt be much.

If you need to multiply the mirrored by some inversion matrix, then I would pass this in a constant buffer and get the GPU to multiply this in VS.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .