Jump to content
  • Advertisement
Sign in to follow this  

Stub Relief Map Shader

This topic is 3944 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've been trying to get this temporary relief map shader working and it does for the most part... but there's a large annoyance whenever the camera's z value (set up so that it's also the z value in tangent space). What it looks like when you get closer is the whole texture gets smaller and eventually wraps around and inverts in both x/y direction.. The new 'relief map' part of the shader is as follows
	float depth = 0.4; //apparent depth of the texture

	float numsteps = 300.0; //large but just to reduce aliasing in the stub
	float stepsize = 1.0/numsteps; 

	float3 rayPos = float3(texCoords, 0.0f); //entry point for the ray

/* The following direction I'm iffy about, it works when z is larger than 1.6 making the relief map look correct. This is reflecting about the tangent plane I believe... */
	float3 rayDir = -vEyeVector/vEyeVector.z; //direction for the ray
	rayDir.z = 1.0f/depth;
	rayDir = normalize(rayDir);

	float3 rayEnd = rayPos + rayDir/rayDir.z; //ray hits the bottom boundary
	float delta = length(rayPos-rayEnd)/numsteps;

	float3 lastPos = rayPos;

	for (int i = 0; i < numsteps; i++) {
		float height = tex2D(heightmapTexture, rayPos.xy).r;
		if (rayPos.z > height)
		lastPos = rayPos;
		rayPos += delta*rayDir;

Is there something I'm missing? Can't seem to find any simple relief map code/help, maybe should just hop on and try cone mapping, but I'd like to learn the basics first. Thanks

Share this post

Link to post
Share on other sites
False alarm, passing in the wrong parameter to the code block for the camera's center position. Never underestimate quick and messy code!

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!