Skybox rendering

Started by
1 comment, last by andyhansen 12 years, 9 months ago
I've been trying to implement skybox rendering. I have it mostly working, except that when I move the camera, the polygons of my skybox will sometimes flicker out of view, showing the backdrop color behind it.

I'm using a textured cube with the vertex order reversed to represent the skybox.

I'm setting the depthstencilstate to this:


DepthEnable=TRUE;
DepthWriteMask=D3D11_DEPTH_WRITE_MASK_ALL;
DepthFunc=D3D11_COMPARISON_LESS_EQUAL;
StencilEnable=FALSE;
StencilReadMask=D3D11_DEFAULT_STENCIL_READ_MASK;
StencilWriteMask=D3D11_DEFAULT_STENCIL_WRITE_MASK;



My vertex shader looks like this:


VS_OUT VS(float3 Pos : POSITION, float2 Tex: TEXCOORD0)
{
VS_OUT output = (VS_OUT)0;
output.posH=mul(float4(Pos,1),World);
//make z and w the same so that the depth is always considered 1
output.posH=mul(output.posH,ViewProjection).xyww;
output.tex0=Tex;
return output;
}



I'm rendering the skybox after everything else. Could this just be a problem with my graphics card? I'm currently running on an intel integrated card on my laptop with dx9.

It all works perfectly except for when I start to move or rotate the camera.


Edit: I was able to try it on another computer, and the problem disappeared. So it must have something to do with the intel card. Is there any way I could prevent this problem from occurring though?
Advertisement
Messing with the projected z and w coordinates can screw things up. An easier approach is to use the viewport to force the Z value to 1. Just set MinDepth and MaxDepth to 1.0.
In my implementation [DX10], I had to set the depth test to D3D10_COMPARISON_LESS_EQUAL so that the skybox is always in front of the background of the scene (I mean even if the sybox depth and z buffer cleaning value are both 1.0)

If I don't apply this test type (just LESS), some pixels of the skybox are not rendered (because these are exactly at the same depth than the background : 1.0)

I hope that may help (?) :rolleyes:
Thanks for the reply! I'm still having some trouble getting it to work though.

My skybox cube is 2 units long along each side. My scene is 4096 units long.

If I use the regular depth settings on the viewport when rendering the skybox, I can't see anything except the skybox, which is how it should behave since the geometry is so small.

When I set the depth settings on the viewport to both 1, I can see for a little ways, but my skybox still appears to intersect the scene geometry. I've made sure i'm using the same viewprojection matrix for both the scene and the skybox.

If I increase the scale factor of the world matrix of the skybox to a very high value (1000), I am able to get it to not intersect the geometry. If I have the scale set to 1000, but I set the viewport depth settings back to normal, it will still intersect the scene geometry. So I at least know that settings the depth values to 1 is helping to some degree. Should this be expected? I'd rather not have to worry about setting the scale of the skybox depending on how large the scene is. My understanding is that setting the viewport to always use 1 as the depth value, and LESS_EQUAL as the comparison operator should cause the skybox to never intersect the scene geometry.

This topic is closed to new replies.

Advertisement