Sign in to follow this  

Skybox makes world darker (Directx, c++)

Recommended Posts

In my latest attempt at a game, I have a car driving on a terrain. I have included a skybox in the program, and now the world appears much darker (or perhaps blue-er?) and I can't figure out why, or how to stop this occurring. My rendering code basically goes (in pseudocode): pDevice->Clear(); pDevice->SetRenderState(D3DRS_LIGHTING, FALSE); pDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); pDevice->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_MIRROR); pDevice->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_MIRROR); skyBox->Render(); pDevice->SetRenderState(D3DRS_LIGHTING, TRUE); terrain->Render(); car->Render(); etc. And here is an image illustrating the world with and without the skybox: Does anyone have any suggestions? Many thanks, Adz

Share this post

Link to post
Share on other sites
Original post by way2lazy2care
I'm assuming the original code is just this part?

pDevice->SetRenderState(D3DRS_LIGHTING, TRUE);

If by original you mean without the skybox then yes, although it obviously includes Clear()ing the backbuffer too.

Share this post

Link to post
Share on other sites
Here is the code then:

//Clear the backbuffer
pScreenManager->pDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(255,255,255), 1.0f, 0);

//Reset the rendering state
pScreenManager->pDevice->SetRenderState(D3DRS_LIGHTING, TRUE);
//Render the terrain
//Render the car

RECT rcText = {0,0,SCREEN_WIDTH,200};
pScreenManager->DrawTextW("CarYvel:", &rcText, DT_LEFT, car->GetVelocity().y); = 40;
pScreenManager->DrawTextW("TerY:", &rcText, DT_LEFT, terrain->GetNormal(car->GetPosition()).y);

//Draw the skybox
pScreenManager->pDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
pScreenManager->pDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
pScreenManager->pDevice->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_MIRROR);
pScreenManager->pDevice->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_MIRROR);

Pretty much the same as above (I have moved the skybox to last here)

The skybox and the car model both have the same render function, as the car owns a Model and I decided to just make the skybox a model for now (Might make it into its own class later):

//set the transformation matrices
D3DXMatrixScaling(&scaleMatrix, scale.x,scale.y,scale.z);
D3DXMatrixTranslation(&transMatrix, position.x, position.y, position.z);

// Position the object for rendering based on the position, rotation and scaling.
pDevice->SetTransform(D3DTS_WORLD, &(scaleMatrix*rotationMatrix*transMatrix));

//render the object
for (DWORD i = 0; i < materialCount; i++)
// Set the material
// Set the texture if we have one
if (textures[i]!= NULL)
pDevice->SetTexture(0, textures[i]);

// Draw the subset

EDIT: If there is any other part of code you need, just let me know. I don't know if it is worth mentioning that both the skybox and the car models are from the DirectX samples

Share this post

Link to post
Share on other sites
Sorry, I'm not into DirectX, some questions:
Do you use texturing for the terrain and the car?
If not, do you switch off texturing when rendering them? (and switch it back when rendering the sky).

The sky has to be rendered first, depth test disabled (completely).

Share this post

Link to post
Share on other sites
Thank you for the suggestion. I don't use textures for the terrain yet, and the skybox has the textures 'built-in'. I'm not too sure about the car, it is provided with directX but I don't think it has any textures.

I tried your suggestion of disabling the depth buffer, adding:

pScreenManager->pDevice->SetRenderState(D3DRS_ZENABLE, FALSE);
pScreenManager->pDevice->SetRenderState(D3DRS_ZWRITEENABLE, FALSE);

before drawing the skybox, then setting those states back to true and drawing the rest of the scene, but it didn't change anything. Thanks though

Share this post

Link to post
Share on other sites
Awesome. I should 'think man think' more often. I've managed to get the effect I want, not sure if it is the 'correct' way to do it though. I now do (aswell as all the zBuffer enabling/disabling etc.)

pScreenManager->pDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );
pScreenManager->pDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_DISABLE );

Thanks a lot everyone!

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this