Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Bump mapping in fragment shader

  1. #1
    Newbie Newbie
    Join Date
    May 2013
    Posts
    2

    Question Bump mapping in fragment shader

    Hello, I'm learning about bump mapping and I've made this code in a DOJO class:

    uniform sampler2D sampler2d0;
    uniform sampler2D sampler2d1;
    uniform sampler2D sampler2d2;

    void main()
    {
    vec2 coordTex = (gl_Vertex.xy + 1.0) / 2.0;

    vec4 color = texture2D(sampler2d0, coordTex);

    vec4 normalMap = texture2D(sampler2d1, coordTex);
    vec4 heightMap = texture2D(sampler2d2, coordTex);

    vec4 modelVertex = gl_Vertex;
    modelVertex.z = 0.05*heightMap.z;

    vec4 eyeVertex = gl_ModelViewMatrix * modelVertex;

    vec3 normal = gl_NormalMatrix * normalMap.xyz;
    normal = normalize(2*(normal-0.5));

    vec3 lightDir = gl_LightSource[0].position.xyz - eyeVertex.xyz;
    lightDir = normalize(lightDir);

    float diffuse = dot(lightDir, normal);

    gl_Position = gl_ProjectionMatrix * eyeVertex;
    gl_FrontColor.rgb = diffuse * color.rgb;
    gl_FrontColor.a = 1.0;
    }

    It works pretty well. Now, I would like to try it in the fragment shader. I have no idea how to do it. How can I start?

  2. #2
    Intern Newbie
    Join Date
    Mar 2013
    Posts
    42
    This example uses vertex and fragment shader:
    http://fabiensanglard.net/bumpMapping/index.php

  3. #3
    Newbie Newbie
    Join Date
    May 2013
    Posts
    2
    Thanks. I will try to follow this example to refactor my code.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •