• ### Popular Now

• 10
• 9
• 13
• 10
• 18

This topic is 1749 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Suppose my skybox is a sphere. I have learned that when draw a skybox, we can make the sphere's z value equal to its w value in the vertex shader, like this:

VertexOut VS(VertexIn vin)
{
VertexOut vout;

//PosH stand for position in Homogeneous coordinate
vout.PosH = mul(float4(vin.PosL, 1.0f), gWorldViewProj).xyww;

//PosL stan for position in local coordinate,used as a lookup vector in cubemap
vout.PosL = vin.PosL;

return vout;
}


I can't totally undestand why we can do like that.  If we do so, after perspective divide, wouldn't there be two part of the sphere becomes in  the view frustum's far plane, one behind the camera originally and the other in front of the camera originally? If they already in the view frustum, then, how can the pipeline clip out the one which behind the camera originally? Hope someone help me figure it out?

##### Share on other sites

Hey, culling will be performed based on the winding order of the vertices, so the back faces will still be culled correctly.

However, in the example you give, if you're using PosL as your cube-map lookup vector. You do not want to copy the w coordinate into that vectors z element.

You will want something more akin to:

    vout.PosH = mul(float4(vin.PosL, 1.0f), gWorldViewProj);
vout.PosL = vin.PosL;
vout.PosH.z = vout.PosH,w;


n!

##### Share on other sites

Hey, culling will be performed based on the winding order of the vertices, so the back faces will still be culled correctly.

However, in the example you give, if you're using PosL as your cube-map lookup vector. You do not want to copy the w coordinate into that vectors z element.

You will want something more akin to:

    vout.PosH = mul(float4(vin.PosL, 1.0f), gWorldViewProj);
vout.PosL = vin.PosL;
vout.PosH.z = vout.PosH,w;


n!

Thank you for your answer. But the sample code,which I am studying, sets CullMode =  None. But the result is still perfect. After read you answer, I try to modify the code like this: CullMode = Front. Still the demo works well. Then I try to modify the code like this: CullMode = Back. This time, the skybox disappear. But other objects in my scene are rendered still. So I think maybe the CullMode isn't the key point in my problem.

##### Share on other sites
Interesting. I put that sample through PIX and yes, the behind-the-camera triangles don't get rasterized, even with cullmode = none. I think the reason is the clipping rules:

0 <= zc <= wc (clip space)

Behind the camera w (and so z) are negative, so get clipped.

##### Share on other sites

Interesting. I put that sample through PIX and yes, the behind-the-camera triangles don't get rasterized, even with cullmode = none. I think the reason is the clipping rules:

0 <= zc <= wc (clip space)

Behind the camera w (and so z) are negative, so get clipped.

Good job! This should be the right answer.Thank you!