Jump to content
  • Advertisement
Sign in to follow this  
Hulag

Bumpmapping GLSL shader.

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

Can someone help me develop a bumpmapping shader? The information I have available to pass to the shader is the following: 1. Position of the light. (Multiplied by any matrix if needed) 2. Position of the camera. (Multiplied by any matrix if needed) 3. Texture unit 0 as base map. 4. Texture unit 1 as normal map. 5. gl_MultiTexCoord2 for the tangents. 6. gl_MultiTexCoord3 for the bitangents. Now, here is my best attempt but it doesn't work. Vertex shader:
uniform vec3 vertex_parameter0; //Light position.
uniform vec3 vertex_parameter1; //Camera position.

varying vec2  vTexCoord;
varying vec3  vLightVecDot;
varying vec3  vViewVec;
varying vec3  vNormal;

void main(void)
{   
   gl_Position = ftransform();

   vTexCoord = vec2(gl_MultiTexCoord0);
   vNormal = gl_NormalMatrix * gl_Normal;

   // Transform light vector into tangent space
   vec3 lightVec = vertex_parameter0.xyz - gl_Vertex.xyz;
   vLightVecDot.x = dot(lightVec, gl_MultiTexCoord2.xyz);
   vLightVecDot.y = dot(lightVec, gl_MultiTexCoord3.xyz);
   vLightVecDot.z = dot(lightVec, gl_Normal);
}
Fragment shader:
uniform sampler2D texture0;
uniform sampler2D texture1;

varying vec2  vTexCoord;
varying vec3  vLightVecDot;
varying vec3  vNormal;

void main(void)
{
   vec4 base = texture2D(texture0, vTexCoord);
   vec3 bump = texture2D(texture1, vTexCoord) * 2.0 - 1.0;

   bump          = normalize(bump);
   vec3 lightVec = normalize(vLightVecDot);

   float diffuse = clamp(dot(lightVec, bump), 0.0, 1.0);

   gl_FragColor = base * diffuse;
}
I would really appreciate some help with this since I have been trying to get this working for a week already

Share this post


Link to post
Share on other sites
Advertisement
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!