//VERTEX
#version 110
varying vec3 Vertex;
void main()
{
Vertex = gl_Vertex.xyz;
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_TexCoord[1] = gl_MultiTexCoord1;
gl_Position = ftransform();
}
//FRAGMENT
#version 110
varying vec3 Vertex;
uniform sampler2D horizons;
uniform sampler2D normals;
uniform float angle;
uniform vec3 ViewPos;
void main()
{
// PARALLAXMAPPING
float TrueHeight = texture2D(normals, gl_TexCoord[0].st).a;
float GeoHeight = Vertex.y;
float HeightDiff = (TrueHeight-GeoHeight);
float s = 0.042;
float b = -s/2.0;
float HeightDev = (HeightDiff*s)+b;
vec3 nView = ViewPos-Vertex;
vec2 ViewSlope = nView.xy/nView.z;
vec2 NewTexCoord = gl_TexCoord[0].st + HeightDev*ViewSlope;
// BUMP AND HORIZON MAPPING
vec3 Normal = texture2D(normals, NewTexCoord).rgb*2.0-1.0;
vec3 LightDir = vec3(-cos(angle*0.01745329), -sin(angle*0.01745329), 0.0);
float LightSlope = LightDir.y/LightDir.x;
float OffsetSlope = sin(10.0*0.01745329);
float HorizonSlope = texture2D(horizons, NewTexCoord).x;
float minslope = LightSlope - OffsetSlope/2.0;
float maxslope = LightSlope + OffsetSlope/2.0;
float Shadow = HorizonSlope < minslope ? 1.0 : HorizonSlope > maxslope ? 0.0 : (maxslope-HorizonSlope)/(maxslope-minslope);
float Intensity = dot(LightDir, Normal)*Shadow;
gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0)*Intensity ;
}
_________________________
ShaderProgram->sendUniform("normals", 0);
ShaderProgram->sendUniform("horizons", 1);
ShaderProgram->sendUniform("angle", SunAngle);
ShaderProgram->sendUniform("ViewPos", (float)m_Cam->Position.x, (float)m_Cam->Position.y, (float)m_Cam->Position.z );
help with parallax mapping
ive been trying to figure this out for so long that i have no idea what im doing anymore... please help me out.. im tring to do some parallax mapping for a mesh... but all i get is a mess... please ignore the rest of the code and just how i would calc the new texcoords using parallax mapping
[Edited by - Dragon_Strike on October 7, 2006 5:25:28 AM]
ive amde a nother try.. but same problem.. now im just trying to do it on a flat surface...
this is waht i get...
shouldnt parallax mapping be pssible without tangent vectors?
[Edited by - Dragon_Strike on October 7, 2006 8:49:29 AM]
//VERTEX#version 110uniform vec4 Eye;varying vec3 EyeDir;varying float Height;void main(){ // Also, transform the vertex into view-space. vec3 m_Vector = vec3(gl_ModelViewMatrix * gl_Vertex); Height = m_Vector.y; vec3 dirEye = Eye.xyz - m_Vector; vec3 m_Tangent = vec3(gl_ModelViewMatrix * vec4(1.0, 0.0, 0.0, 0.0)); vec3 m_Normal = vec3(gl_ModelViewMatrix * vec4(0.0, 0.0, 1.0, 0.0)); vec3 m_BiNormal = vec3(gl_ModelViewMatrix * vec4(1.0, 1.0, 0.0, 0.0)); EyeDir.x = dot(m_Tangent.xyz , dirEye); EyeDir.y = dot(m_BiNormal.xyz , dirEye); EyeDir.z = dot(m_Normal.xyz , dirEye); gl_TexCoord[0] = gl_MultiTexCoord0; gl_TexCoord[1] = gl_MultiTexCoord1; gl_Position = ftransform(); }// FRAGMENT#version 110uniform sampler2D tex;uniform sampler2D bump;uniform float angle;varying float Height;varying vec3 EyeDir;void main(){ vec3 EyeT = normalize(EyeDir); float HeightDiff = texture2D(bump, gl_TexCoord[0].st).a; vec4 Offset = vec4(HeightDiff,HeightDiff,HeightDiff,1.0); Offset = Offset * 0.04 - 0.02; vec2 TexCoords = Offset.xy * EyeT.xy + gl_TexCoord[0].st; gl_FragColor = tex(bump, TexCoords );}______________ShaderProgram->sendUniform("bump", 0);ShaderProgram->sendUniform("tex", 1);ShaderProgram->sendUniform("Eye", (float)m_Cam->Position.x, (float)m_Cam->Position.y, (float)m_Cam->Position.z, 1.0f );
this is waht i get...
shouldnt parallax mapping be pssible without tangent vectors?
[Edited by - Dragon_Strike on October 7, 2006 8:49:29 AM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement