Jump to content
  • Advertisement
Sign in to follow this  

GLSL Parallax Mapping Problem

This topic is 3445 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'm trying to implement a simple parallax mapping shader in GLSL. My guideline was http://cowboyprogramming.com/2007/01/05/parallax-mapped-bullet-holes/ My vertex shader looks like:
attribute vec3 rm_Tangent;

uniform vec3 LightPosition;
uniform vec3 EyePosition;

varying vec2 Texcoord;
varying vec3 ViewDirection;
varying vec3 LightDirection;
varying vec3 Normal;
void main( void )
   gl_Position            = ftransform();
   Texcoord               = gl_MultiTexCoord0.xy;
   Normal                 = gl_NormalMatrix * gl_Normal;
   vec3 Tangent           = gl_NormalMatrix * rm_Tangent;
   vec3 Binormal          = cross(Normal, Tangent);
   mat3 TangentMat        = mat3(Tangent, Binormal, Normal);
   vec4 fvObjectPosition  = gl_ModelViewMatrix * gl_Vertex;
   ViewDirection          = TangentMat * (EyePosition - fvObjectPosition.xyz);
   LightDirection         = TangentMat * (LightPosition - fvObjectPosition.xyz);
And my fragment shader like:
uniform vec4 Ambient;
uniform vec4 Specular;
uniform vec4 Diffuse;
uniform float SpecularPower;

uniform sampler2D BaseMap;
uniform sampler2D HeightMap;

varying vec2 Texcoord;
varying vec3 ViewDirection;
varying vec3 LightDirection;
varying vec3 Normal;

void main( void )
   // Normalize vectors
   vec3  nLightDirection  = normalize(LightDirection);
   vec3  nViewDirection   = normalize(ViewDirection);
   vec3  nNormal          = normalize(Normal);

   // Calc angles
   float NDotL            = dot(nNormal, nLightDirection); 
   vec3  Reflection       = normalize(((2.0 * nNormal) * NDotL ) - LightDirection); 
   float RDotV            = max(0.0, dot(Reflection, nViewDirection));
   // Modify texture coordinates
   vec4  TexColor         = texture2D(HeightMap, Texcoord);
   float MaxDepth         = 0.1;
   float Depth            = (TexColor.r + TexColor.g + TexColor.b) / 3.0 * MaxDepth;
   vec2  NewTexcoord      = Depth * nViewDirection.xy + Texcoord;
   // Calc color
   vec4  BaseColor        = texture2D(BaseMap, NewTexcoord);
   vec4  TotalAmbient     = Ambient * BaseColor; 
   vec4  TotalDiffuse     = Diffuse * NDotL * BaseColor; 
   vec4  TotalSpecular    = Specular * (pow(RDotV, SpecularPower));
   gl_FragColor           = BaseColor;
The shader looks pretty "incorrect" in Rendermonkey, but I don't know why. Hopefully someone can tell what's wrong. Greetings matrium

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!