PDA

View Full Version : OpenGL 4, problems following opengl.org tutorial (Parallax)



fredvam
01-04-2014, 03:43 PM
The tutorial points to deprecated GLSL calls, I have issues following its example, any help would be greatly appreciated (http://www.opengl.org/sdk/docs/tutorials/TyphoonLabs/Chapter_4.pdf)

From the tutorial:

Vertex:


attribute vec3 tangent;
attribute vec3 binormal;
uniform vec3 CAMERA_POSITION;
varying vec3 eyeVec;

void main()
{
gl_Position = ftransform();
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;

mat3 TBNMatrix = mat3(tangent, binormal, gl_Normal);
eyeVec = CAMERA_POSITION - gl_Vertex.xyz;
eyeVec *= TBNMatrix;
}

Fragment:



uniform sampler2D basetex;
uniform sampler2D heightMap;
uniform vec2 scaleBias;
varying vec3 eyeVec;

void main()
{
float height = texture2D(heightMap, gl_TexCoord[0].st).r;
//Our heightmap only has one color channel.
float v = height * scaleBias.r - scaleBias.g;
vec3 eye = normalize(eyeVec);
vec2 newCoords = texCoord + (eye.xy * v);

vec3 rgb = texture2D(basetex, newCoords).rgb;
gl_FragColor = vec4(rgb, 1.0);
}



My Vertex:



layout( location = 0 ) in vec3 VertexPosition;
layout( location = 1 ) in vec3 VertexNormal;
layout( location = 2 ) in vec2 VertexTexCoord;
layout( location = 3 ) in vec3 VertexTangent;

out vec3 Position;
out vec3 Tangent;
out vec3 Normal;
out vec2 TexCoord;

uniform float TexTile;
uniform vec3 gEyeWorldPos;

out vec3 EyeVec;


uniform mat4 M;
uniform mat4 V;
uniform mat4 P;

void main() {

gl_Position = (P*V*M) * vec4(VertexPosition,1.0);

Normal = (M * vec4(VertexNormal, 0.0)).xyz;
Tangent = (M * vec4(VertexTangent, 0.0)).xyz;
Position = (M * vec4(VertexPosition, 1.0)).xyz;

TexCoord = VertexTexCoord * TexTile;


vec3 Bitangent = cross(Tangent, Normal);
mat3 TBN = mat3(Tangent, Bitangent, Normal);
EyeVec = gEyeWorldPos - VertexPosition.xyz;
EyeVec *= TBN;
}


My Fragment:


.... same in as out from vertex


void main()
{

float height = texture2D(gNormalMap, TexCoord.st).r;
//Our heightmap only has one color channel.
float v = height * 0.04 - 0.02;
vec3 eye = normalize(EyeVec);
vec2 newCoords = TexCoord + (eye.xy * v);



TangentData = normalize(Tangent);
ColorData.xyz = texture(gColorMap, newCoords).xyz;
ColorNormalData = texture(gNormalMap, newCoords).xyz;
ColorPropData.r = 5.0f; //intBitsToFloat(5);
}


Results show some elevation where expected, but allot of noise etc. I also used the same or similar normal(height) texture and diffuse as what demonstrated in the tutorial, so something is wrong around TBN I think, but not sure..

tonyo_au
01-07-2014, 10:43 PM
eyeVec *= TBNMatrix;

I see the example has this line but I was wondering if it should be


eyeVec = TBNMatrix * eyeVec;


also you can look at this example
http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-13-normal-mapping/

fredvam
01-08-2014, 12:45 PM
Hello, normal mapping is something I already support. Parallax, relief mapping etc generate superior results

tonyo_au
01-08-2014, 06:39 PM
Here is a slightly different version http://www.pythonstuff.org/glsl/media/demo_parallax.py