# 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: http://img696.imageshack.us/img696/6987/skyboxissuea.jpg Does anyone have any suggestions? Many thanks, Adz

##### Share on other sites
Have you tried rendering the Skybox last?

##### Share on other sites
Yes, I've tried rendering the skybox last, and for a second it all looks fine, then it just reverts to the darkness again, and stays that way.

##### Share on other sites
I'm assuming the original code is just this part?

pDevice->SetRenderState(D3DRS_LIGHTING, TRUE);
terrain->Render();
car->Render();
etc.

##### Share on other sites
Quote:
 Original post by way2lazy2careI'm assuming the original code is just this part?pDevice->SetRenderState(D3DRS_LIGHTING, TRUE);terrain->Render();car->Render();etc.

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

##### Share on other sites
I guess it's time to show the actual code.
(between [source] [/source] tags)

##### 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	terrain->Render(pScreenManager->pDevice);	//Render the car	car->Render(pScreenManager->pDevice);	RECT rcText = {0,0,SCREEN_WIDTH,200};	pScreenManager->DrawTextW("CarYvel:", &rcText, DT_LEFT, car->GetVelocity().y);	rcText.top = 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);	skyBox->Render(pScreenManager->pDevice);

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);	D3DXMatrixRotationYawPitchRoll(&rotationMatrix,rotation.x,rotation.y,rotation.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 		pDevice->SetMaterial(&materials[i]);		// Set the texture if we have one		if (textures[i]!= NULL)	        pDevice->SetTexture(0, textures[i]);		        // Draw the subset		mesh->DrawSubset(i);	}

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 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 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.

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 on other sites
You have to disable textures for things that doesn't use textures, and enable them for things that are textured.
Think a bit, man!

##### 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 );skybox->render();pScreenManager->pDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_DISABLE );everythingelse->Render();

Thanks a lot everyone!

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628333
• Total Posts
2982121

• 22
• 9
• 9
• 13
• 11