Jump to content
  • Advertisement
Sign in to follow this  
lucky6969b

The "Sky" is too short!

This topic is 505 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

Advertisement

To expand just a bit on Kylotan's accurate response - in your specific application, what does a "unit" mean?  In other words, is the value "1 unit" representative of 1 meter, 1 centimeter, or some other value altogether?  If 1 unit = 1 cm, then a sky 1000 units away would be 10 meters away.

Alternatively, if your app takes place entirely on the ground and the sky is supposed to look infinitely far away, you could always force the geometry to the far plane in the vertex shader and have its position transform with the camera position to give the illusion that it's so far away it doesn't move when the camera moves a bit.

Share this post


Link to post
Share on other sites

In other words, sky planes are more than enough. I just push them to the far clip plane at render stage? BTW, it's 1000 meters anyway

Edited by lucky6969b

Share this post


Link to post
Share on other sites

You could use them, or keep your sky dome and in the vertex shader do something like:

//... some code

posH = mul(inputPos, viewProjMtx); // this is your SV_Position output
posH.z = posH.w; // when the divide by w occurs, this will make the depth 1.0 (far plane)

//... whatever else

You could also just use a full-screen triangle or quad and use the same "push it to the far plane" logic.  Then in the pixel shader, color it based off the y component of a view ray (a ray from starting at the camera and extending out into the scene) - all depends on how fancy you want to get.

If you stick with the dome, make sure you only transform it by the camera's position, and not rotation - otherwise the entire sky will spin as the camera spins.

Share this post


Link to post
Share on other sites

It could be the FOV of your camera. Try using 90 degrees or something in that range, you will see more of the sky.

Share this post


Link to post
Share on other sites

Get something to work today.

But the problem is the sky disappears with a quick flash.

Does that mean the sky actually lies beyond the far clip plane?

	const D3DXMATRIX* v = m_pCam->GetViewMatrix();
    const D3DXMATRIX* p = m_pCam->GetProjMatrix();
    D3DXMATRIX vp = *v * *p;
    
    D3DXVECTOR3 camPos = m_pCam->GetPos();
    
    D3DXMATRIX matCam;
    D3DXMatrixTranslation(&matCam, camPos.x, camPos.y, camPos.z);
    D3DXMATRIX target = matCam * vp;
    
    // Do not light sky box.
    d3d::GetInstance().GetDevice()->SetRenderState(D3DRS_LIGHTING, false);
	    // Don't write skybox to the depth buffer; in this way,
    // the skybox will never occlude goemtry, which it should not
    // since it is "infinitely" far away.
    d3d::GetInstance().GetDevice()->SetRenderState(D3DRS_ZWRITEENABLE, false);
    d3d::GetInstance().GetDevice()->SetRenderState(D3DRS_ZENABLE, false);
    
	    // Set sampler states to clamp so that edge seam does not show where
    // two box faces coincide.
    d3d::GetInstance().GetDevice()->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
    d3d::GetInstance().GetDevice()->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
      
	    d3d::GetInstance().GetDevice()->SetTransform(D3DTS_WORLD, &target);
      
    DrawMesh(m_SkyPlaneMesh);

Edited by lucky6969b

Share this post


Link to post
Share on other sites

How come I got a teared sky after writing this code?

 

	const D3DXMATRIX* v = m_pCam->GetViewMatrix();
    const D3DXMATRIX* p = m_pCam->GetProjMatrix();
    D3DXMATRIX vp = *v * *p;
    
    D3DXVECTOR3 camPos = m_pCam->GetPos();
    D3DXVECTOR4 camPosVec4(camPos.x, camPos.y, camPos.z, 1);
    
    D3DXMATRIX matCam;
    //D3DXMatrixTranslation(&matCam, camPos.x, camPos.y, camPos.z);
    // camPosVec4 * vp;
    D3DXVECTOR4 targetVec4;
    D3DXVec4Transform(&targetVec4, &camPosVec4, &vp);
    D3DXVECTOR3 targetPos(targetVec4.x, targetVec4.y, targetVec4.z);
    //D3DXMATRIX target = matCam * vp;
    D3DXMATRIX target;
    D3DXMatrixTranslation(&target, targetPos.x, targetPos.y, targetPos.z);
     

2017_07_26_11_19_34_TestWalkUpstairs_Running_Microsoft_Visual_C_2010_Express_Administrator_.png

 

Update2:

Now it works better now, but why the sky is below the line of ground (the horizon).... seems like if my camera pos is at a y position of 150, the sky is at 150 as well. which is pretty low.

The skyplane size is calculated as follows:

the variable f denotes the far clip plane distance which is 10000.

Then the farHeight is about 8000 meters

	FLOAT farHeight = 2 * tan(fov/2) * f;
FLOAT depth = 0.0f;
FLOAT farWidth = farHeight * m_pCam->GetAspect();
	

2017_07_26_13_46_50_Perfect_Simulation.png

Edited by lucky6969b

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!