Sign in to follow this  

Parallax Mapping on Earth

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

I use a parallax mapping shader on my bump mapped Earth. But at hills it seems to be buggy. What's the problem? [Vertex]
varying vec2 textureCoordinate;
varying vec3 lightVector;
varying vec3 eyeVector;

uniform vec4 lightPosition;
const vec3 tangent = vec3( 1.0, 0.0, 0.0 );

void main()
{
   gl_Position = ftransform();
   vec3 cameraInWorldSpace = gl_Position.xyz - gl_ModelViewMatrixInverse[ 3 ].xyz;
   textureCoordinate = gl_MultiTexCoord0.xy;
   lightVector = ( lightPosition - gl_Vertex ).xyz;
   vec3 normal = gl_NormalMatrix * gl_Normal;
   vec3 binormal = cross( tangent, normal );
   mat3 tangentBinormalNormalMatrix = mat3( tangent, binormal, normal );
   lightVector = tangentBinormalNormalMatrix * lightVector;
   eyeVector = cameraInWorldSpace - ( gl_ModelViewMatrixInverse * gl_Vertex ).xyz;
   eyeVector = tangentBinormalNormalMatrix * eyeVector;
}



[Fragment]
varying vec2 textureCoordinate;
varying vec3 lightVector;
varying vec3 eyeVector;
uniform sampler2D texture;
uniform sampler2D heightMap;
uniform sampler2D normalMap;
uniform float scale;
uniform vec4 ambientColor;
uniform vec4 diffuseColor;

void main()
{
   vec3 normalizedLightDirection = normalize( lightVector );
   vec3 normalizedEyeVector = normalize( eyeVector );
   vec3 heightVector = texture2D( heightMap, textureCoordinate ).xyz;
   float height = scale * length( heightVector ) - 0.2;
   vec2 nextTextureCoordinate = height * normalizedEyeVector.xy + textureCoordinate;
   vec3 offsetNormal = texture2D( normalMap, nextTextureCoordinate ).xyz;
   // [0, 1] -> [-1, 1]
   offsetNormal = offsetNormal * 2.0 - 1.0;
   float diffuseContribution = clamp( dot( offsetNormal, normalizedLightDirection ), 0.0, 1.0 );
   vec4 textureColor = texture2D( texture, nextTextureCoordinate );
   gl_FragColor = ( ambientColor + diffuseColor * diffuseContribution ) * textureColor;
}




Share this post


Link to post
Share on other sites
Have you tried it with a different texture?
Try your shader out with a simple quad with a texture and normal-map you know is working, take one from a working example or tutorial. Perhaps something is wrong with your normal map, your screenshot looks very strange..

EDIT: Also, there are several tutorials and examples on parallax mapping, search for one and compare your shader, making sure you haven't missed something. I don't remember exactly how to do it right now so I can't look at your code and see what's wrong if that's the problem, but it should be relatively easy for you to figure out if you double-check the algorithm.

Share this post


Link to post
Share on other sites

This topic is 3318 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.

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