• Create Account

Banner advertising on our site currently available from just \$5!

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

4 replies to this topic

### #1swdever  Members   -  Reputation: 176

Like
0Likes
Like

Posted 05 June 2013 - 04:50 AM

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！

### #2nfactorial  Members   -  Reputation: 731

Like
0Likes
Like

Posted 05 June 2013 - 06:38 AM

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!

### #3swdever  Members   -  Reputation: 176

Like
0Likes
Like

Posted 05 June 2013 - 06:54 AM

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.

### #4unbird  Crossbones+   -  Reputation: 7379

Like
1Likes
Like

Posted 05 June 2013 - 03:45 PM

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.

### #5swdever  Members   -  Reputation: 176

Like
0Likes
Like

Posted 05 June 2013 - 09:07 PM

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!

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS