🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Change winding order with a shader?

Started by
6 comments, last by Funkymunky 3 years, 6 months ago

I have a situation where I'm drawing several instances of a mesh, but I want to render some of the instances with Clockwise front faces and some with Counter-Clockwise front faces. I'm using DirectX 12 for reference, but this seems like a general problem anyway. As I see it, there are 3 ways to accomplish this:

  • Create a separate PSO and switch pipeline states when I want to draw CCW
  • Add a geometry shader stage that checks a value in a cbuffer and emits the vertices accordingly
  • Create a separate index buffer with CCW ordering and just change that binding for those calls

I'm leaning toward the third option since it seems like the least expensive. Does anyone know of any other ways to accomplish this? Or have any insights into the problem in general?

Advertisement

I'd be mildly surprised if swapping PSOs that differ only by a single flag were noticeably more expensive than swapping the index buffer out, but I guess you'll have to profile it and see.

What sort of effect are you creating here, that uses the same shader on both front and back facing versions of the mesh?

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

I'm implementing CDLOD on a sphere. I'm projecting out a curvilinear projection to map a cube to a sphere, and instancing a grid mesh a bunch of times to draw each face. But due to the way CDLOD requires morphing of the odd vertices, and the way I'm doing the projection, 3 of the 6 faces need to be rendered on the inside of the sphere in order for the LOD transitions to remain seemless.

Funkymunky said:
But due to the way CDLOD requires morphing of the odd vertices, and the way I'm doing the projection, 3 of the 6 faces need to be rendered on the inside of the sphere in order for the LOD transitions to remain seemless.

this sounds odd ?

in cdlod, in every block of 8 triangles, 2 will be gradually enlarging and the remaining 6 will be degenerating (so this is how u'd go from a hi-lod to lo-lod), and u can still render all these triangles with the same winding order…

if u switch the winding order u could be potentially creating holes where none would normally be, so your explanation for willing to change the winding order (respectfully) doesn't seem to make sense ?

but anyway, if i had to change the winding, yes, i'd pick your 3rd option;

all the best ?

It's because it's wrapped around a sphere. The odd/even warping doesn't line up along half of the edges when I project the face out for half of the sphere. I implemented my 3rd method and it works beautifully, perfect morphing at all 8 corners!

Excited to see the result - I tried out CDLOD on a sphere a very long time ago, but I don't recall actually solving it at the time. I ended up swapping a separate index buffer per neighbour with a different LOD to roughly accomplish the same thing (without the smooth morph).

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

The green face is being swapped. No cracks/seems, so no dancing black pixels as you move around!

This topic is closed to new replies.

Advertisement