Archived

This topic is now archived and is closed to further replies.

Khanh

how about skybox coordinates?

Recommended Posts

dear all, I heard I can draw a skybox in size (1,1,1) and it will be looked "outside" all other objects if I disable Z Buffer and ZWriteable? is that true? how about skykox coordinates? can it be at (0,0,0) and other objects at (100,100,100)? In fact, what are the functions SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE) and SetRenderState( D3DRS_ZWRITEENABLE, FALSE ) when we did clear Z buffer with value 1.0f (farthest distance)? Many thanks? Khanh

Share this post


Link to post
Share on other sites
quote:
Original post by Khanh
dear all,

I heard I can draw a skybox in size (1,1,1) and it will be looked "outside" all other objects if I disable Z Buffer and ZWriteable? is that true?

yes.
quote:

how about skykox coordinates? can it be at (0,0,0) and other objects at (100,100,100)?

You will want the center of your skybox to be at the location of your camera. After you render the skybox with the Z-Buffer turned off, all the other objects in the world will be drawn on top of the the skybox. This will create the illusion that the bound of the sky box are really far away, when in fact they are probably only a few units away.
quote:

In fact, what are the functions SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE) and SetRenderState( D3DRS_ZWRITEENABLE, FALSE ) when we did clear Z buffer with value 1.0f (farthest distance)?

I''m don''t understand what you mean by this. When you first start to render your scene, you clear the Z-Buffer with the value 1.0f. Then you turn off the Z-Buffer and render your skybox at the camera''s location. Then you turn the Z-Buffer back on and render the rest of your scene normally.

By the way, if you disable the Z-Buffer with SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE), there is no need to specifically disable Z writing.

Hope this helps,
neneboricua

Share this post


Link to post
Share on other sites
please correct me if this loop is wrong, many thanks.
//main loop
{
setup mainviewport
setup camera
set up projection

//draw skybox in small size (1,1,1)
clear Zbuffer
translate to eye position //in order to center camera
turn off Z-Buffer + turn off Z-Writing
draw skybox
turn on Z-buffer and+ turn on Z-Writing

//draw all other objects
clear target
draw terrain
draw trees, building,etc...

setup second small viewport
}

regards,
Khanh

Share this post


Link to post
Share on other sites
quote:
Original post by Khanh
please correct me if this loop is wrong, many thanks.
//main loop
{
setup mainviewport
setup camera
set up projection


Unless you''re doing something out of the ordinary, you typically don''t have to setup your viewport and projection matrices every frame. You can set those up during initialization. The camera is probably the only one you''ll need to update each frame.
quote:

//draw skybox in small size (1,1,1)
clear Zbuffer
translate to eye position //in order to center camera
turn off Z-Buffer + turn off Z-Writing
draw skybox
turn on Z-buffer and+ turn on Z-Writing


This is correct. But normally, you would clear both the Zbuffer and the render target at the same time by using D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER in the Clear method. The reason for this is that it is much faster for the hardware to clear both buffers at the same time than for it to clear them one at a time. Also, if you don''t clear your render target.

In your case however, since you''re using a skybox, the entire render target will definately be overwritten each frame. So you REALLY only need to clear the Zbuffer. You don''t have to clear the render target because your skybox is drawing on top of whatever was there in the last frame anyway.
quote:

//draw all other objects
clear target
draw terrain
draw trees, building,etc...

setup second small viewport
}


This is correct, except for the render target issue I mentioned above. I''m not sure if this is your entire render loop but if it is, why are you setting up a second small viewport right before your loop ends? If you''re drawing some kind of HUD over the screen then I guess this is ok, but if not, make sure that you really need a second viewport.

neneboricua

Share this post


Link to post
Share on other sites
You should not clear the target at all, the skybox will cover the whole screen anyway. And if you clear it after drawing the the Box, the sky will be erased.

Share this post


Link to post
Share on other sites