Thank you very much, If you are ever in croatia (or I in spain) you have a drink on me
But I was trying to implement relief mapping, not parallax mapping

The fragment shader is long
Code: Select all
uniform vec4 fvAmbient;
uniform vec4 fvSpecular;
uniform vec4 fvDiffuse;
uniform float fSpecularPower;
uniform sampler2D baseMap;
uniform sampler2D reliefMap;
uniform float depth;
uniform float tile;
//uniform int linear_search_steps; min 11
//uniform int binary_search_steps; min 5
varying vec2 Texcoord;
varying vec3 eyeSpaceTangent;
varying vec3 eyeSpaceBinormal;
varying vec3 eyeSpaceNormal;
varying vec3 eyeSpaceLight;
varying vec3 eyeSpacePos;
float ray_intersect_rm(in vec2 dp,in vec2 ds);
void main(void)
{
vec4 relief,color;
vec3 t_eyeSpacePos,norm_eyeSpacePos,l,viewRay, lightRay;
vec2 dp,ds,uv;
float realDepth,a;
// ray intersect in view direction
t_eyeSpacePos = eyeSpacePos;
norm_eyeSpacePos = normalize(t_eyeSpacePos);
a = dot(eyeSpaceNormal,-norm_eyeSpacePos);
viewRay = normalize(vec3(dot(norm_eyeSpacePos,eyeSpaceTangent),dot(norm_eyeSpacePos,eyeSpaceBinormal),a));
viewRay *= depth/a;
dp = Texcoord*tile;
ds = viewRay.xy;
realDepth = ray_intersect_rm(dp,ds);
// get rm and color texture points
uv=dp+ds*realDepth;
relief=texture2D(reliefMap,uv);
color=texture2D(baseMap,uv);
// expand normal from normal map in local polygon space
relief.xy=relief.xy*2.0-1.0;
relief.z=sqrt(1.0-dot(relief.xy,relief.xy));
relief.xyz=normalize(relief.x*eyeSpaceTangent+relief.y*eyeSpaceBinormal+relief.z*eyeSpaceNormal);
// compute light direction
t_eyeSpacePos += norm_eyeSpacePos*realDepth*a;
l=normalize(t_eyeSpacePos-eyeSpaceLight.xyz);
// ray intersect in light direction
dp+= ds*realDepth;
a = dot(eyeSpaceNormal,-l);
lightRay = normalize(vec3(dot(l,eyeSpaceTangent),dot(l,eyeSpaceBinormal),a));
lightRay *= depth/a;
ds = lightRay.xy;
dp-= ds*realDepth;
float dl = ray_intersect_rm(dp,ds);
float shadow = 1.0;
vec3 specular_shadow=fvSpecular.xyz;
if (dl<realDepth-0.05) // if pixel in shadow
{
shadow=dot(fvAmbient.xyz,vec3(1.0))*0.333333;
specular_shadow=vec3(0.0);
}
// compute diffuse and specular terms
float att=max(0.0,dot(-l,eyeSpaceNormal));
float diff=shadow*max(0.0,dot(-l,relief.xyz));
float spec=max(0.0,dot(normalize(-l-norm_eyeSpacePos),relief.xyz));
// compute final color
vec4 finalcolor;
finalcolor.xyz=fvAmbient.xyz*color.xyz+
att*(color.xyz*fvDiffuse.xyz*diff+specular_shadow*pow(spec,fSpecularPower));
finalcolor.w=1.0;
gl_FragColor = vec4(finalcolor.rgb,1.0);
}
float ray_intersect_rm(in vec2 dp, in vec2 ds)
{
const int linear_search_steps=11;
const int binary_search_steps=6;
float depth_step=1.0/float(linear_search_steps);
// current size of search window
float size=depth_step;
// current depth position
float depth=0.0;
// best match found (starts with last position 1.0)
float best_depth=1.0;
// search front to back for first point inside object
for( int i=0;i<linear_search_steps-1;i++ )
{
depth+=size;
vec4 t=texture2D(reliefMap,dp+ds*depth);
if (best_depth>0.996) // if no depth found yet
if (depth>=t.w)
best_depth=depth; // store best depth
}
depth=best_depth;
// recurse around first point (depth) for closest match
for( int i=0;i<binary_search_steps;i++ )
{
size*=0.5;
vec4 t=texture2D(reliefMap,dp+ds*depth);
if (depth>=t.w)
{
best_depth=depth;
depth-=2.0*size;
}
depth+=size;
}
return best_depth;
}
and the vertex i posted before (with this i get the last pictures i posted)
Code: Select all
uniform vec3 fvLightPosition;
uniform vec3 fvEyePosition;
varying vec2 Texcoord;
varying vec3 eyeSpacePos;
varying vec3 eyeSpaceLight;
varying vec3 eyeSpaceTangent;
varying vec3 eyeSpaceBinormal;
varying vec3 eyeSpaceNormal;
//uniform vec3 rm_Binormal;
//uniform vec3 rm_Tangent;
//uniform vec4 Tangent;
//uniform vec4 BiNormal;
void main(void)
{ //vec3 rm_Tangent = vec3(gl_ModelViewMatrix * Tangent);
//vec3 rm_Binormal = vec3(gl_ModelViewMatrix * BiNormal);
vec3 rm_Tangent = normalize(gl_NormalMatrix * gl_MultiTexCoord1.xyz);
vec3 rm_Binormal = normalize(gl_NormalMatrix * gl_MultiTexCoord2.xyz);
eyeSpacePos = vec3(gl_ModelViewMatrix * gl_Vertex);
eyeSpaceLight = (gl_ModelViewMatrix * vec4(fvLightPosition ,1.0)).xyz;
eyeSpaceTangent = normalize(gl_NormalMatrix * rm_Tangent);
eyeSpaceBinormal = normalize(gl_NormalMatrix * rm_Binormal);
eyeSpaceNormal = normalize(gl_NormalMatrix * gl_Normal);
Texcoord = gl_MultiTexCoord0.xy;
gl_Position = ftransform();
}
The data i use is here
http://rapidshare.com/files/383489314/N ... 2_.7z.html
(the normalmap has the heightmap in the alpha chanell Photoshop ftw)
I found the shader creator but it wont start on my pc for some reason :/
It runs on the laptop but relief mapping is cpu intensive so it runs at 1fps if it doesen't crash the system. I use rendermonkey for shader editing
p.s your code runs fine but i get this (i only pass the textures to the shader since they are the only uniform vars )
http://www.imagesforme.com/show.php/111 ... oard01.jpg