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

Thread: Parallax mapping troubles :(

  1. #1
    Advanced Member Frequent Contributor
    Join Date
    Nov 2002
    Location
    Latvia
    Posts
    628

    Parallax mapping troubles :(

    I've been experimenting with parallax, maping yesterday, but faced some problems.

    What I've been doing was:
    1st: gluLookAt
    2nd: draw geometry stage + passing tangent, binormal, normal to vp
    3rd: passing eyepos, + MVP,MV,MVIT matrices to cg vp
    4th: cg vp -> mul(mvit,eyepos), E=eyepos-IN.pos, mul(TBN, E)
    5th: cg fp, fetch height from texture, normalize E, use the function to calculate offset offset=(h*E.xy/E.z)
    The problem seems to be connected with transformations, as the texture appears to rotate vhen crossing some point (moving with gluLookAt)

  2. #2
    Super Moderator OpenGL Guru dorbie's Avatar
    Join Date
    Jul 2000
    Location
    Bay Area, CA, USA
    Posts
    4,388

    Re: Parallax mapping troubles :(

    Moving to the Advanced forum.

  3. #3
    Senior Member OpenGL Pro Zengar's Avatar
    Join Date
    Sep 2001
    Location
    Germany
    Posts
    1,979

    Re: Parallax mapping troubles :(

    Is MVIT the inverse-transpose? I thought it should be simply inverce. But MVI*eye is always (0, 0, 0). I don't know if this can help, but...

  4. #4
    Advanced Member Frequent Contributor
    Join Date
    Nov 2002
    Location
    Latvia
    Posts
    628

    Re: Parallax mapping troubles :(

    Whoups, yes you're right must start coding more carefully.

    Now it's only sharp angle artifacts to get rid of
    I'll have to sit a while to translate fp code to Cg, unfortunately I mised good ol' assembly But docs rely on it...

    Hope vp is correct now:
    Code :
    struct a2v
    {
        float4 Position		: POSITION;
        float2 TexCoord0	: TEXCOORD0;
    };
     
    struct v2f
    {
        float4 HPosition	: POSITION;
    	float2 TexCoord0	: TEXCOORD0;
    	float3 Eye			: TEXCOORD1;
    };
     
    v2f main(a2v IN,
    		 uniform float4x4 ModelViewProj,
    		 uniform float4 EyePos,
    		 uniform float4 T,
    		 uniform float4 B,
    		 uniform float4 N
    		 )
    {
        v2f OUT;
     
    	OUT.HPosition = mul(ModelViewProj, IN.Position);
    	OUT.TexCoord0 = IN.TexCoord0;
     
    	float3x3 TBN = float3x3(T.xyz, B.xyz, N.xyz);
    	float3 E = EyePos.xyz-IN.Position.xyz;
    	E = mul(TBN, E);
     
    	OUT.Eye = E;
     
        return OUT;
    }
    [This message has been edited by M/\dm/\n (edited 02-09-2004).]

  5. #5
    Senior Member OpenGL Pro Zengar's Avatar
    Join Date
    Sep 2001
    Location
    Germany
    Posts
    1,979

    Re: Parallax mapping troubles :(

    Well, I also wrote a parallax mapping app (about 5 minutes ago) and so far i can see, my vp looks exact ys yours one.
    Are you drawing some sort of patch? This would explain your static TBN vectors

  6. #6
    Advanced Member Frequent Contributor
    Join Date
    Nov 2002
    Location
    Latvia
    Posts
    628

    Re: Parallax mapping troubles :(

    Yup, right now I'm trying to sort things out on plane, then I'll go into 3D + I think I'll pass only 2 of 3 TBN vectors to GPU, 3rd will be cross on GPU (gonna see how FX5200 will handle that). And I've learned that uniform parameters are real pain in a** when you have 10+ shaders in one app.

    [This message has been edited by M/\dm/\n (edited 02-09-2004).]

  7. #7
    Advanced Member Frequent Contributor
    Join Date
    Nov 2002
    Location
    Latvia
    Posts
    628

    Re: Parallax mapping troubles :(

    Huh, I think I've finally got algo working

    But I noticed that there are prety ugly artifacts when parallax is applied on some of my textures:
    W/O parallax
    http://www.lapas.dau.lv/salitis/1.bmp
    W parallax
    http://www.lapas.dau.lv/salitis/2.bmp
    Tried experimenting with biases, but that doesn't seem to be a good solution, as you'll have flaws or no parallax
    Of course my textures arn't very nice as they have a lot of sharp angles.

    BTW, cg fp:
    Code :
    void main(float2 TexCoord0	: TEXCOORD0,
    	  float3 Eye		: TEXCOORD1,
     
    	  out float4 color : COLOR,
     
    	  uniform sampler2D   diffuseMap,
    	  uniform sampler2D   heightMap
    	  )
    {
    	normalize(Eye);
    	float3 height = tex2D(heightMap, TexCoord0).xyz*0.04-0.02;
     
    	float4 tmpcol = tex2D(diffuseMap, TexCoord0+(height*Eye.yx));
     
    	float3 C = tmpcol.xyz*tmpcol.w;
    	color.xyz = C;
    	color.w = 1;
    }
    I'm storing lightmap in alpha of diffuse map. Still can't understand why I had to swap Eye.xy to Eye.yx.

Posting Permissions

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