Skip to main content
gamedev.net
🔒 Locked

Skybox

Started by Marusu Jun 12, 2010 at 1:30 PM 7 replies 2.4k views
Original Post
Marusu
Marusu
I've been trying to create a realistic skybox, but I don't know how.
Here's what I have so far:
Skybox
Skybox
The quality of sides isn't quite good, but still, they say that using cube is the best way, but then how do I remove thoose edges?

here's the method:
HRESULT CSkybox::Render (IDirect3DDevice9 *&pDevice){	pDevice->SetRenderState(D3DRS_ZENABLE, FALSE);	pDevice->SetRenderState(D3DRS_ZWRITEENABLE, FALSE);	pDevice->SetRenderState(D3DRS_LIGHTING, FALSE);	D3DXMATRIX view, viewSave, world;	pDevice->GetTransform(D3DTS_VIEW, &viewSave);	view = viewSave;	view._41 = 0.0f; view._42 = -10.0f; view._43 = 0.0f;	pDevice->SetTransform(D3DTS_VIEW, &view);	D3DXMatrixIdentity(&world);	pDevice->SetTransform(D3DTS_WORLD, &world);	for (DWORD i = 0; i < nMaterials; i++)	{		pDevice->SetMaterial(&pMeshMaterials);		pDevice->SetTexture(0, ppMeshTextures);		pMesh->DrawSubset(i);	}	pDevice->SetTransform(D3DTS_VIEW, &viewSave);	pDevice->SetRenderState(D3DRS_ZENABLE, TRUE);	pDevice->SetRenderState(D3DRS_ZWRITEENABLE, TRUE);	pDevice->SetRenderState(D3DRS_LIGHTING, TRUE);	return S_OK;}

Does anyone know, why, when I rotate camera up abd back, I go out of the skybox?
I use mesh for skybox.
If you can give me any ideas how to improve this, I'd really appreciate it.
Also, how and where am I supposed to use:
//pDevice->SetSamplerState(i, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
//pDevice->SetSamplerState(i, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
And how to turn them off afterwards?

P.S. I used 3ds studio max, created cube and then added textures to each side checking 2-sided option. because of that I need to use cullmode none. How could I go without it?
Aqua Costa
Aqua Costa
Search for skydomes

http://www.gamedev.net/community/forums/topic.asp?topic_id=359215
Sik_the_hedgehog
Sik_the_hedgehog
In order to implement skyboxes properly, you need to take into account the deformation and compensate for it in the texture first of all. That's why it doesn't look properly in your case.
Don't pay much attention to "the hedgehog" in my nick, it's just because "Sik" was already taken =/ By the way, Sik is pronounced like seek, not like sick.
szecs
szecs
Wrong.
Wrong.

Obviously the OP uses downloaded texture, so the deformation is taken into account.

Get the transformation matrix
Set the translation part: last row or column (depending on the matrix representation) to [0,0,0,1].

Why do you set one of the elements -10?

Could you post a screen-shot from 3ds Max and outside the skybox?
Marusu
Marusu
I've taken texture from: http://www.3delyvisions.com/skf1.htm

"Why do you set one of the elements -10?"
I changed, to -0.4. It solves the problem with going out of box, somewhat. But the sky itself looks very high and even more deformed.

Skybox

Here's the screen from max:
Skybox

P.S. What does OP mean?
Evil Steve
Evil Steve
1. A skybox should always be "fixed" to the camera, but should rotate with it. Hence (0, 0, 0) for the translation component.
2. OP = Original Poster
3. You want to model the skybox inside out - you only care what the inside looks like, not the outside. As it is, it's modeled so the outside is the front face.
I'd also move it so the centre of the box is at (0, 0, 0), rather than sitting on the XZ plane, otherwise the camera would be inside the ground plane when it's at (0, 0, 0).
szecs
szecs
I was curious about the screenshot from outside, because it gives more information simultaneously.

Yes, the center of the cube has to be in 0,0,0, so the x-y plane should 'cut" the cube in half. So you have to fix it in 3ds Max (or build the cube inside your program, it's simpler than using a model for that)
On the other hand, the texture itself looks okay.

An other important thing: lighting should be disabled when rendering the skybox.
Marusu
Marusu
Thank you Steve and szecs,
I used this tutorial: http://www.toymaker.info/Games/html/skybox.html and it said to translate to matView._41 = 0.0f; matView._42 = -0.4f; matView._43 = 0.0f; Didn't get why he needed -0.4f, but using 0, 0, 0 works. Also I moved the cube so now 0, 0, 0 is at the center of the cube and the skybox finally looks like a real sky:
Skybox
Szecs, didn't I turn off light before rendering with this?
pDevice->SetRenderState(D3DRS_ZENABLE, FALSE);
pDevice->SetRenderState(D3DRS_ZWRITEENABLE, FALSE);
pDevice->SetRenderState(D3DRS_LIGHTING, FALSE);

And after that turn it on:
pDevice->SetRenderState(D3DRS_ZENABLE, TRUE);
pDevice->SetRenderState(D3DRS_ZWRITEENABLE, TRUE);
pDevice->SetRenderState(D3DRS_LIGHTING, TRUE);

It would be also great if you could tell me where should I put this:
pDevice->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
pDevice->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
If I understand correctly it should make sky look even better? I just don't know where to put it. Does it make a big difference if this is used correctly?
Foofles
Foofles
Been a while since I've used FFP but I think:

pDevice->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
pDevice->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);

Will just set the internal pixel shader to clamp the texture lookup to the 0.0f - 1.0f range so the texture doesn't tile. This isn't really necessary here I think.

I guess the reason the toymaker tutorial sets a -0.4f in Y is to set the player a little lower in the skybox, and since like they said your skybox isn't centered you just end up under it altogether. I recommend centering your skybox model in 3DS as recommended and leaving the translation at 0,0,0.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.