Results 1 to 2 of 2

Thread: Problem with Vertex Displacement Mapping (GLSL)

  1. #1
    Newbie Newbie
    Join Date
    Nov 2012

    Problem with Vertex Displacement Mapping (GLSL)


    I am new to GLSL programming. Right now, I am trying to make simple "Displacement Mapping" by following this tutorial

    I can load images of colormap and displacementmap into glTexImage2D() without any problem. (displacement texture filter is nearest already)

    The problem is I did not see any bump/displace on my plane.... I could see it be mapped with correct colorMap.
    I felt that the whole plane is move along z-axis (normal) according to vertex shader when I changed value that multiply df at line "newVertexPos = vec4(gl_Normal * df * 100.0, 0.0) + gl_Vertex;"

    uniform sampler2D displacementMap;

    void main(void)
    vec4 newVertexPos;
    vec4 dv;
    float df;

    gl_TexCoord[0].xy = gl_MultiTexCoord0.xy;

    dv = texture2D( displacementMap, gl_MultiTexCoord0.xy );

    df = 0.30*dv.x + 0.59*dv.y + 0.11*dv.z;

    newVertexPos = vec4(gl_Normal * df * 100.0, 0.0) + gl_Vertex;

    gl_Position = gl_ModelViewProjectionMatrix * newVertexPos;

    uniform sampler2D colorMap;

    void main(void)
    gl_FragColor = texture2D(colorMap, gl_TexCoord[0].xy);

    Render function
    GLfloat position[] = { 0, 0,30.f, 0.0f };
    glLightfv(GL_LIGHT0, GL_POSITION, position);

    glBindTexture(GL_TEXTURE_2D, m_imageTexture);
    int colorMap_location = glGetUniformLocation(m_program, "colorMap");

    glBindTexture(GL_TEXTURE_2D, m_displacementTexture);
    int displacementMap_location = glGetUniformLocation(m_program, "displacementMap");


    glMultiTexCoord2d(GL_TEXTURE0, 0.0,0.0);
    glVertex3d(-1.0, -1.0 ,0);

    glMultiTexCoord2d(GL_TEXTURE0, 1.0,0.0);
    glVertex3d(1.0, -1.0,0);

    glMultiTexCoord2d(GL_TEXTURE0, 1.0,1.0);
    glVertex3d(1.0, 1.0,0);

    glMultiTexCoord2d(GL_TEXTURE0, 0.0,1.0);
    glVertex3d(-1.0, 1.0,0);


    Any idea what wrong with my coding ?

    Thank in advance!

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    There is nothing wrong that's what you asked to code to do - all your vertices have the same normal which point along the z-axis. In you shader you multiply this normal by a values and add it to
    the vertex so you will get a displacement along the z axis. Try putting different values in each normal like (0,1,0), (0.5,0.5,0) , (0,0.5,0.5), (0,0,0) and see what happens

Similar Threads

  1. opengl bump mapping (normal mapping) problem with VBO and GLSL
    By emrekaya413 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 03-29-2018, 03:52 AM
  2. Displacement Mapping/Coloring
    By in forum OpenGL: Basic Coding
    Replies: 10
    Last Post: 08-14-2003, 07:26 PM
  3. Displacement mapping
    By DopeFish in forum OpenGL: Advanced Coding
    Replies: 18
    Last Post: 07-11-2003, 08:06 AM
  4. displacement mapping
    By zed in forum OpenGL: Advanced Coding
    Replies: 16
    Last Post: 09-01-2002, 10:46 AM
  5. Is this displacement mapping?
    By rapso in forum OpenGL: Advanced Coding
    Replies: 28
    Last Post: 05-03-2002, 06:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Proudly hosted by Digital Ocean