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: Parallax mapping trouble!

  1. #1
    Advanced Member Frequent Contributor yooyo's Avatar
    Join Date
    Apr 2003
    Location
    Belgrade, Serbia
    Posts
    872

    Parallax mapping trouble!

    Hi,

    I have problem with GLSL version of parralax mapping. It just wont work. I have tried following code in ShaderDesigner and in my app, but it wont work as well.
    Please help!
    Code :
    bump.vert:
    attribute vec3 tangent;
    attribute vec3 binormal;
    uniform mat4 MODELVIEW_INVERSE;
     
    varying vec3 eyeVec;
     
    void main()
    {
     mat3 mTangent = mat3(tangent, binormal, gl_Normal); 
     gl_Position = ftransform();
     
     gl_TexCoord[0] = gl_MultiTexCoord0;
     
     vec3 temp = MODELVIEW_INVERSE[3].xyz - gl_Vertex.xyz; 
     eyeVec = temp * mTangent;
    }
     
     
    ----------------------------------
    bump.frag:
    uniform sampler2D basetex;
    uniform sampler2D bumptex;
     
    varying vec3 eyeVec;
     
    void main()
    {
     vec2 texUV;
     vec3 eye = normalize(eyeVec);
     
     float height = texture2D(bumptex, gl_TexCoord[0].xy).r;
     height = height * 0.04 - 0.02;
     texUV = gl_TexCoord[0].xy + (eye.xy * height);
     vec3 col = texture2D(basetex, texUV).rgb;
     gl_FragColor = vec4(vec3(col), 1.0);
    }
    Here are compiled version (using reg-tweak WriteProgramObjectAssembly = 1) :
    Code :
    Vertex program:
    !!VP2.0
    # cgc version 1.2.1001, build date Apr  4 2004 16:52:59
    # command line args: -q -profile vp30 -entry main -oglsl -D__GLSL_CG_DATA_TYPES -D__GLSL_CG_STDLIB -D__GLSL_SAMPLER_RECT
    #vendor NVIDIA Corporation
    #version 1.0.02
    #profile vp30
    #program main
    #semantic gl_ModelViewProjectionMatrixTranspose
    #semantic MODELVIEW_INVERSE
    #var float3 gl_Normal : $vin.ATTR2 : ATTR2 : -1 : 1
    #var float4 gl_Vertex : $vin.ATTR0 : ATTR0 : -1 : 1
    #var float4 gl_MultiTexCoord0 : $vin.ATTR8 : ATTR8 : -1 : 1
    #var float4 gl_Position : $vout.HPOS : HPOS : -1 : 1
    #var float4 gl_TexCoord[0] : $vout.TEX0 : TEX0 : -1 : 1
    #var float4 gl_TexCoord[1] : $vout.<null atom> :  : -1 : 0
    #var float4 gl_TexCoord[2] : $vout.<null atom> :  : -1 : 0
    #var float4 gl_TexCoord[3] : $vout.<null atom> :  : -1 : 0
    #var float4 gl_TexCoord[4] : $vout.<null atom> :  : -1 : 0
    #var float4 gl_TexCoord[5] : $vout.<null atom> :  : -1 : 0
    #var float4 gl_TexCoord[6] : $vout.<null atom> :  : -1 : 0
    #var float4 gl_TexCoord[7] : $vout.<null atom> :  : -1 : 0
    #var float4x4 gl_ModelViewProjectionMatrixTranspose :  : c[0], 4 : -1 : 1
    #var float3 tangent : $vin.ATTR1 : ATTR1 : -1 : 1
    #var float3 binormal : $vin.ATTR3 : ATTR3 : -1 : 1
    #var float4x4 MODELVIEW_INVERSE :  : c[4], 4 : -1 : 1
    #var float3 eyeVec : $vout.TEX1 : TEX1 : -1 : 1
    BB1:
    ADD   R0.xyz, c[7], -v[0];
    MOV   o[TEX0], v[8];
    DP3   o[TEX1].z, v[2], R0;
    DP3   o[TEX1].y, v[3], R0;
    DP3   o[TEX1].x, v[1], R0;
    DP4   o[HPOS].w, c[3], v[0];
    DP4   o[HPOS].z, c[2], v[0];
    DP4   o[HPOS].y, c[1], v[0];
    DP4   o[HPOS].x, c[0], v[0];
    END
    # 9 instructions, 1 R-regs
     
     
     
    Fragment program:
    !!FP1.0
    # cgc version 1.2.1001, build date Apr  4 2004 16:52:59
    # command line args: -q -profile fp30 -entry main -oglsl -D__GLSL_CG_DATA_TYPES -D__GLSL_CG_STDLIB -D__GLSL_SAMPLER_RECT
    #vendor NVIDIA Corporation
    #version 1.0.02
    #profile fp30
    #program main
    #semantic basetex
    #semantic bumptex
    #var float4 gl_TexCoord[0] : $vin.TEX0 : TEX0 : -1 : 1
    #var float4 gl_TexCoord[1] : $vin.<null atom> :  : -1 : 0
    #var float4 gl_TexCoord[2] : $vin.<null atom> :  : -1 : 0
    #var float4 gl_TexCoord[3] : $vin.<null atom> :  : -1 : 0
    #var float4 gl_TexCoord[4] : $vin.<null atom> :  : -1 : 0
    #var float4 gl_TexCoord[5] : $vin.<null atom> :  : -1 : 0
    #var float4 gl_TexCoord[6] : $vin.<null atom> :  : -1 : 0
    #var float4 gl_TexCoord[7] : $vin.<null atom> :  : -1 : 0
    #var float4 gl_FragColor : $vout.COL : COL : -1 : 1
    #var sampler2D basetex :  : texunit 0 : -1 : 1
    #var sampler2D bumptex :  : texunit 1 : -1 : 1
    #var float3 eyeVec : $vin.TEX1 : TEX1 : -1 : 1
    TEX   R0, f[TEX0], TEX1, 2D;
    MULR  R0.x, R0, {0.04, 0, 0, 0};
    ADDR  R0.z, R0.x, {-0.02, 0, 0, 0}.x;
    DP3R  R0.x, f[TEX1], f[TEX1];
    RSQR  R0.x, R0.x;
    MULR  R0.xy, R0.x, f[TEX1];
    MULR  R0.xy, R0, R0.z;
    ADDR  R0.xy, f[TEX0], R0;
    MOVR  o[COLR].w, {1, 0, 0, 0}.x;
    TEX   o[COLR].xyz, R0, TEX0, 2D;
    END
    # 10 instructions, 1 R-regs, 0 H-regs
    yooyo

  2. #2
    Member Regular Contributor
    Join Date
    Apr 2002
    Location
    Austria
    Posts
    328

    Re: Parallax mapping trouble!

    - Do you have stored a height-map in "bumptex"?
    - Should this line
    Code :
    eyeVec = temp * mTangent;
    rather be
    Code :
    eyeVec = mTangent * temp;
    There is a theory which states that if ever anybody discovers exactly what the Universe is for and why it is here, it will instantly disappear and be replaced by something even more bizarre and inexplicable.

    There is another theory which states that this has already happened...

  3. #3
    Advanced Member Frequent Contributor yooyo's Avatar
    Join Date
    Apr 2003
    Location
    Belgrade, Serbia
    Posts
    872

    Re: Parallax mapping trouble!

    Originally posted by Corrail:
    - Do you have stored a height-map in "bumptex"?
    - Should this line
    Code :
    eyeVec = temp * mTangent;
    rather be
    Code :
    eyeVec = mTangent * temp;
    Yep... height-map are in bumptex (grayscale image)
    After your patch looks better. Thanx... But if I test this shader on Cube model in ShaderDesigner in some cases (just rotate model) I got very strange "displacement". Try to modify line in bump.frag:
    gl_FragColor = vec4(vec3(col)+eye, 1.0);
    This line add eye vector as color to final color.
    and take a look when "eye color" wraps.
    Remove +eye from gl_FragColor and rotate camera.

    Is this artifact because of bad tangents and binormals?

    yooyo

    yooyo

  4. #4
    Member Regular Contributor
    Join Date
    Apr 2002
    Location
    Austria
    Posts
    328

    Re: Parallax mapping trouble!

    please post a screenshot
    There is a theory which states that if ever anybody discovers exactly what the Universe is for and why it is here, it will instantly disappear and be replaced by something even more bizarre and inexplicable.

    There is another theory which states that this has already happened...

Posting Permissions

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