The bug of the day award.

So today i found out that when i render the scene to a renderTargetCube then draw it as a reflection it required me to reverse the culling…

So nearly my entire scene from depth map to lighting and shadow, uses custom DrawUserIndexedPrimitives with polygons wound for counterclockwise culling.

When i render the scene to a rendertargetcube then map that to a sphere i get a funny look… so im staring and staring like what am i seeing then i realized its culled backwards ? I seperate the draw some more and flip on clockwise and sure enough it all looks normal again.

That has got to be one of the strangest bugs ive seen in a while.

How in the world does rendering to a reflection cube actually cause the culling direction to change when the view is at its center and the polygons are wound counter clockwise ?.

In the above image nearly everything uses counter clockwise winding other then the grid and a couple debug cube shaders. The primary exception is the reflection sphere nearly dead center it was rendered with the entire scene set to clockwise even though that is actually the backface of all these cubes and spheres shown and even the skybox.

I now just have one super nasty bug to squash well for the moment.
SpriteBatch destroys my depthbuffer and makes the shadow depth go haywire and turning it off doesn’t undo whatever it did.

Did you flip an axis in your view or projection matrix for the cube render? Each axis-flip means a culling flip.

Same projection matrix.

The same view is actually created by the same LeftHanded create look at needed for the depth map scene rendering to line up with the cube faces.

Looks basically the same. I dunno i could be missing something pretty tired.

You probably wouldn’t notice the problem with shadow-mapping since drawing backfaces instead of front is a common per-object option to deal with Z artifacts of the shadow incorrectly appearing on a lit face (along with constant and slope bias).

If your regular rendering is using XNA’s right-handed-system then that’d be your backfaces problem. As per the ARB extension cubemaps (DX does the same) are left-handed (which you already figured out), that means a single-axis flip which twists the face winding the other way.

Well all my objects are wound counterclockwise so i just fliped to clockwise and it rendered properly in the reflection.

Considering i have to do 12 switches anyways because i have to do that ridiculous depth buffer clear with my skysphere i guess one more doesn’t matter.

Ya there was a lot of bugs associated with that spritebatch was turning on a blendstate to which i had to also clear by calling a empty blendstate at the begining of each draw.