Cull mode inverted for some reason?

Started by
7 comments, last by L. Spiro 10 years, 1 month ago

I've been learning basic 3D engine programming and finally got to a stage where I have a very simple engine running, displaying a bunch of spinning rainbow cubes. I had built a similar demo a little while ago, but this is the first time the code has been properly integrated into some semblance of an engine, with different areas properly segregated and so forth.

I'm experiencing a weird issue where I have to set CullMode.Front by default, or all of the back faces render, while the front faces are ignored. Obviously this is backwards to what should actually by happening but I'm having trouble figuring out why. Any suggestions would be appreciated.

All the code is on Github if you want to take a look. Here's the part where I'm setting the cull mode.

Advertisement

Maybe the winding order of your triangles is inverted (clockwise instead of counterclockwise or vice versa)?

Maybe the winding order of your triangles is inverted (clockwise instead of counterclockwise or vice versa)?

Just checked and the vertex indices for the triangles appear to be specified in counterclockwise winding order.

https://github.com/axefrog/game-dev-learning/blob/master/Grasshopper/Grasshopper.Engine/Geometry/Primitives/Cube.cs#L34

Then you have found your own problem it would seem.

The D3D11_RASTERIZER_DESC::FrontCounterClockwise member defaults to FALSE.

L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

Then you have found your own problem it would seem.

The D3D11_RASTERIZER_DESC::FrontCounterClockwise member defaults to FALSE.

L. Spiro

Ah thanks! I'm assuming counterclockwise is the standard most engines use? I'm confused why the default settings for the rasterizer description put the winding direction at odds with cull mode...

It’s not. First you define which direction defines a front face (clockwise or counter clockwise) and then you decide whether you want to cull front faces or back faces. I personally use clockwise, but whether one is used more than the other or by whom one is used is rather arbitrary—there is no reason to pick one over the other except that that is how your toolchain works.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

It’s not. First you define which direction defines a front face (clockwise or counter clockwise) and then you decide whether you want to cull front faces or back faces. I personally use clockwise, but whether one is used more than the other or by whom one is used is rather arbitrary—there is no reason to pick one over the other except that that is how your toolchain works.


L. Spiro

Ah, thanks, that's helpful. I wonder if it's a bug in SharpDX for configuring the Rasterizer.Default() method to have the winding order mismatched with the cull mode.

That doesn't make sense. How can it be mismatched if it's arbitrary?

I said the decision on which to use is fairly arbitrary, even though there might or might not be a most-common direction (CW/CCW).


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

This topic is closed to new replies.

Advertisement