Jump to content
  • Advertisement
Sign in to follow this  
swdever

Problem about vertex shader in Skybox

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!