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 4 of 4

Thread: OpenGL 4, problems following opengl.org tutorial (Parallax)

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2013
    Location
    Norway
    Posts
    17

    OpenGL 4, problems following opengl.org tutorial (Parallax)

    The tutorial points to deprecated GLSL calls, I have issues following its example, any help would be greatly appreciated (http://www.opengl.org/sdk/docs/tutor.../Chapter_4.pdf)

    From the tutorial:

    Vertex:

    Code :
    attribute vec3 tangent; 
    attribute vec3 binormal; 
    uniform vec3 CAMERA_POSITION; 
    varying vec3 eyeVec; 
     
    void main() 
    { 
     gl_Position = ftransform(); 
     gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0; 
     
     mat3 TBNMatrix = mat3(tangent, binormal, gl_Normal); 
     eyeVec = CAMERA_POSITION - gl_Vertex.xyz; 
     eyeVec *= TBNMatrix; 
    }

    Fragment:

    Code :
    uniform sampler2D basetex; 
    uniform sampler2D heightMap; 
    uniform vec2 scaleBias; 
    varying vec3 eyeVec; 
     
    void main() 
    { 
     float height = texture2D(heightMap, gl_TexCoord[0].st).r; 
     //Our heightmap only has one color channel. 
     float v = height * scaleBias.r - scaleBias.g; 
     vec3 eye = normalize(eyeVec); 
     vec2 newCoords = texCoord + (eye.xy * v); 
     
     vec3 rgb = texture2D(basetex, newCoords).rgb; 
     gl_FragColor = vec4(rgb, 1.0); 
    }



    My Vertex:

    Code :
    layout( location = 0 ) in vec3 VertexPosition;
    layout( location = 1 ) in vec3 VertexNormal;
    layout( location = 2 ) in vec2 VertexTexCoord;
    layout( location = 3 ) in vec3 VertexTangent;
     
    out vec3 Position;
    out vec3 Tangent;
    out vec3 Normal;
    out vec2 TexCoord;
     
    uniform float TexTile;
    uniform vec3 gEyeWorldPos;
     
    out vec3 EyeVec; 
     
     
    uniform mat4 M;
    uniform mat4 V;
    uniform mat4 P;
     
    void main() {
     
    gl_Position = (P*V*M) * vec4(VertexPosition,1.0);
     
    Normal =  (M * vec4(VertexNormal, 0.0)).xyz;
    Tangent =  (M * vec4(VertexTangent, 0.0)).xyz;
    Position = (M * vec4(VertexPosition, 1.0)).xyz;
     
    TexCoord = VertexTexCoord * TexTile;
     
     
    vec3 Bitangent = cross(Tangent, Normal);
    mat3 TBN = mat3(Tangent, Bitangent, Normal);
    EyeVec = gEyeWorldPos - VertexPosition.xyz;
    EyeVec *= TBN;
    }


    My Fragment:


    .... same in as out from vertex

    Code :
    void main()
    {
     
    	float height = texture2D(gNormalMap, TexCoord.st).r; 
    	//Our heightmap only has one color channel. 
    	float v = height * 0.04 - 0.02; 
    	vec3 eye = normalize(EyeVec); 
    	vec2 newCoords = TexCoord + (eye.xy * v); 
     
     
     
    	TangentData = normalize(Tangent);
        ColorData.xyz = texture(gColorMap, newCoords).xyz;
    	ColorNormalData = texture(gNormalMap, newCoords).xyz;
    	ColorPropData.r = 5.0f; //intBitsToFloat(5);
    }


    Results show some elevation where expected, but allot of noise etc. I also used the same or similar normal(height) texture and diffuse as what demonstrated in the tutorial, so something is wrong around TBN I think, but not sure..

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,109
    Code :
    [COLOR=#333333] eyeVec *= TBNMatrix;[/COLOR]


    I see the example has this line but I was wondering if it should be

    Code :
    [COLOR=#333333] eyeVec = TBNMatrix * [/COLOR][COLOR=#333333]eyeVec[/COLOR][COLOR=#333333];[/COLOR]



    also you can look at this example
    http://www.opengl-tutorial.org/inter...ormal-mapping/

  3. #3
    Junior Member Newbie
    Join Date
    Feb 2013
    Location
    Norway
    Posts
    17
    Hello, normal mapping is something I already support. Parallax, relief mapping etc generate superior results

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,109
    Here is a slightly different version http://www.pythonstuff.org/glsl/media/demo_parallax.py

Posting Permissions

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