Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 02 Apr 2012
Offline Last Active Apr 02 2012 12:49 PM

Posts I've Made

In Topic: Nightmare with tangent space and tbnMatrix

02 April 2012 - 12:53 PM

I've used:

Posted Image
where col is gl_Vertex form the vertex shader and the cube is colored.
But if I use the normal from the normal map, or the tangent or the binormal the cube is black.. so their value is 0.. so the problem is in my opengl application that doesen't feed the shader with the correct datas

but I can't properly find where is the problem

In Topic: Nightmare with tangent space and tbnMatrix

02 April 2012 - 03:22 AM

the problem is that if I try to apply the normal mapping shader to a cube I see a black cube... but the light has a totaly different color. The problem dipends on everything that comes from lightVec, that is incorrect because the tbn matrix is not working properly I think...

In Topic: Nightmare with tangent space and tbnMatrix

02 April 2012 - 03:20 AM

I forgot the shader source code...
normal mapping vertex shader

#version 110
  attribute vec3 tangent;
attribute vec3 binormal;
varying vec3 position;
varying vec3 lightvec;
uniform vec3 CAMERA_POSITION;
void main( )
vec3 t=normalize(tangent);
  vec3 b=normalize(binormal);
  vec3 n=normalize(gl_Normal);
  mat3 TBNMatrix=mat3(t.x,b.x,gl_Normal.x,t.y,b.y,gl_Normal.y,t.z,b.z,gl_Normal.z);


normal mapping fragment shader

#version 110
  #pragma debug(on)
  uniform sampler2D base;
uniform sampler2D specular;
uniform sampler2D gloss;
uniform sampler2D normalMap;
uniform float kshi;
uniform vec4 kdiff;
uniform vec3 CAMERA_POSITION;
varying vec3 position;
varying vec3 lightvec;
void main()
vec3 norm=texture2D(normalMap,gl_TexCoord[0].st).rgb*2.0-1.0;
vec3 baseColor=texture2D(base,gl_TexCoord[0].st).rgb;
float dist=length(lightvec);
vec3 lightVector=normalize(lightvec);
float nxDir=max(0.0,dot(norm,lightVector));
vec4 diffuse=gl_LightSource[0].diffuse*nxDir;
float specularPower=0.0;
vec3 cameraVector=normalize(CAMERA_POSITION-position.xyz);
vec3 halfVector=normalize(lightVector+cameraVector);
float nxHalf=max(0.0,dot(norm,halfVector));

vec4 specular=gl_LightSource[0].specular*specularPower;