Sign in to follow this  
stratius

Stub Relief Map Shader

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)
			break;		
		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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this