Jump to content

  • Log In with Google      Sign In   
  • Create Account

marx_86

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:

gl_FragColor=vec4(vec3(col.xyz)*0.5+0.7,1.0);
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( )
  { 
  gl_Position=ftransform();
gl_TexCoord[0]=gl_MultiTexCoord0;
  position=gl_Vertex.xyz;
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);
  lightvec=gl_LightSource[0].position.xyz-position;
  lightvec*=TBNMatrix;

 } 


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;
if(nxDir!=0.0)
{
vec3 cameraVector=normalize(CAMERA_POSITION-position.xyz);
vec3 halfVector=normalize(lightVector+cameraVector);
float nxHalf=max(0.0,dot(norm,halfVector));
specularPower=pow(nxHalf,kshi);

}
vec4 specular=gl_LightSource[0].specular*specularPower;
gl_FragColor=gl_LightSource[0].ambient+(diffuse*vec4(baseColor.rgb,1.0))+specular;

}

PARTNERS