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)

Moving to the Advanced forum.

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…

Whoups, yes you’re right :eek: 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:

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/
(edited 02-09-2004).]

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

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/
(edited 02-09-2004).]

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:

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.