Jump to content
  • Advertisement
Sign in to follow this  
KnightAdz

Skybox makes world darker (Directx, c++)

This topic is 3031 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
Share on other sites
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.

Share this post


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

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

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
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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!