Skybox makes world darker (Directx, c++)

Started by
9 comments, last by KnightAdz 13 years, 11 months ago
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
Advertisement
Have you tried rendering the Skybox last?
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.
I'm assuming the original code is just this part?

pDevice->SetRenderState(D3DRS_LIGHTING, TRUE);
terrain->Render();
car->Render();
etc.
Quote:Original post by way2lazy2care
I'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.
I guess it's time to show the actual code.
(between [source] [/source] tags)
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);		// Set the texture if we have one		if (textures!= NULL)	        pDevice->SetTexture(0, textures);		        // 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
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).
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
You have to disable textures for things that doesn't use textures, and enable them for things that are textured.
Think a bit, man!

This topic is closed to new replies.

Advertisement