Jump to content
  • Advertisement
Sign in to follow this  

Problem with Displacement

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

Hi, I am tring to use displacement to render an heightmap. I can render a basic displacement without any problem. But to optimize rendering, i want to displace only the part of the screen which is in the camera frustum. I have an idea to avoid the use of quad tree or ROAM. I want to project a flat grid of vertices from the camera to the ground, and than, displace the projected vertices with the texture of the heightmap. But i have a problem and i don't know how to solve it. When i project the grid to the ground, It seems to be Ok. But when i displace the projected vertices, their heights are heigher and heigher when vertices are far from the camera. You can see the problem on this video: http://texelinside.free.fr/bugs/displacement.avi.SWF You can see the projector which project the grid on the ground. In the beginning of the video the displacement texture is 100% black (the projection seems to be good). But when i select an height map texture, you can see the problem. When vertices are close to the camera the height of vertices is low and increase with distance. Maybe i have done an error in my shader ?
Vs_Output VertexShaderEffect(App_Input IN)
	Vs_Output vs_out;
	float4 pos = mul(float4(IN.position, 1), g_matWorld); // Position * WorldMatrix
		// Compute texture coordinates. pos could be used instead of posTexture.
		// But it allow me to do some tests
		float4 posTexture = mul(float4(IN.position, 1), g_matWorld);
		float4 texCoord;
		texCoord.x = (posTexture.x / 4096.0f);
		texCoord.y = (posTexture.z / 4096.0f);
		texCoord.z = 0;
		texCoord.w = 0;

		float4 d = tex2Dlod(diffuseSampler,texCoord); // Texture color
		float displace = d.x; // Height
		pos.y = pos.y + 100.0f*displace; // Displacement
	pos = mul(pos, g_matViewProj); // Position * ViewMatrix * ProjectionMatrix

	vs_out.position = pos;
	vs_out.color = float4(0.0, displace, 0.0, 1.0);
	vs_out.texture0 = texCoord;

   return vs_out;
Where: g_matWorld = TransformationMatrix * TerrainPlanarProjectionMatrix; TransformationMatrix: Translation and rotation of the projector. TerrainPlanarProjectionMatrix: Computed using D3DXMatrixShadow.

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!