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!
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) :
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