Jump to content

  • Log In with Google      Sign In   
  • Create Account


GLSL BumpMap Math error


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 I CAN DO   Members   -  Reputation: 164

Like
-1Likes
Like

Posted 02 December 2013 - 10:17 AM

I have a problem with OpenGL and GLSL to implement Bump Map.

Vertex shader:

#version 330 core



layout (std140) uniform Matrices {



mat4 projViewModelMatrix;

mat3 normalMatrix;

mat4 modelViewMatrix;

};



uniform mat4 View;

uniform vec3 LightPosition;

uniform vec3 CameraPosition;



in vec3 position;

in vec3 normal;

in vec2 texCoord;



out vec2 TexCoord;

out vec3 Normal;



// BUMP MAPPING

/////////////////////////////////////

out vec3 lightVec;

out vec3 eyeVec;

in vec3 vTangent;

in vec3 bTangent;







void main()

{

Normal = normalize(normalMatrix * normal);

gl_Position = projViewModelMatrix * vec4(position, 1.0);

TexCoord = vec2(texCoord);



// BUMP MAPPING

vec3 n = normalize(normalMatrix * normal);

vec3 t = normalize(normalMatrix * vTangent);

vec3 b = normalize(normalMatrix * bTangent);



vec3 vVertex = vec3(modelViewMatrix * vec4(position, 1.0));

// vec3 tmpVec = LightPosition.xyz - vVertex.xyz;

vec3 tmpVec = (View * vec4(LightPosition, 1.0)).xyz - vVertex.xyz;



lightVec.x = dot(tmpVec, t);

lightVec.y = dot(tmpVec, b);

lightVec.z = dot(tmpVec, n);



tmpVec = -vVertex;





eyeVec.x = dot(tmpVec, t);

eyeVec.y = dot(tmpVec, b);

eyeVec.z = dot(tmpVec, n);





}

FragmentShader

#version 330
layout (std140) uniform Material {

vec4 diffuse;

vec4 ambient;

vec4 specular;

vec4 emissive;

float shininess;

int texCount;

};



uniform sampler2D texUnit;



in vec3 Normal;

in vec2 TexCoord;



out vec4 outputF;



//BUMP MAPPING ///////////////////////////////////////////



in vec3 lightVec;

in vec3 eyeVec;



uniform sampler2D normalMap;



uniform vec4 diffuseLight;

uniform vec4 ambientLight;

uniform vec4 specularLight;







main()

{

vec3 N2 = normalize(texture(normalMap, TexCoord).xyz * 2.0 - 1.0);

vec3 L2 = normalize(lightVec);

vec3 V2 = normalize(eyeVec);

vec3 R2 = normalize(-reflect(L2, N2));



float NdotL = max(0.0, dot(N2, L2));

float RdotV = max(0.0, dot(R2, V2));



// Compute final colours.

vec4 ambient = ambientLight * ambient;

vec4 diffuse = diffuseLight * diffuse * NdotL;

vec4 specular2 = specularLight * specular * (pow(RdotV, shininess) * 1);



vec4 base = texture2D(texUnit, TexCoord);



// Final colour.

outputF = base * ambient + base * diffuse + specular2;

}

There is some error there? I feel that the calculation of the direction of the light is wrong. Could it be?

 

The line:

vec3 tmpVec = (View * vec4(LightPosition, 1.0)).xyz - vVertex.xyz;

is OK?

the line:

tmpVec = -vVertex;

 

OK? or I need change to:

tmpVec = (View * vec4(CameraPosition, 1.0)).xyz - vVertex.xyz;

 

or

tmpVec = (CameraPosition).xyz - vVertex.xyz;

 

Please help me.

Thank you, best regards.

 

Attached Thumbnails

  • CarScreenshot4.jpg
  • CarScreenshot3.jpg
  • CarScreenshot2.jpg
  • CarScreenshot1.jpg

Edited by swiftcoder, 02 December 2013 - 08:41 PM.
Please use [code] [/code] tags in future.


Sponsor:

#2 I CAN DO   Members   -  Reputation: 164

Like
-2Likes
Like

Posted 02 December 2013 - 03:16 PM

Come on guys.



#3 assainator   Members   -  Reputation: 558

Like
0Likes
Like

Posted 03 December 2013 - 04:10 AM

Come on guys.

Be a bit more patient, most people have jobs, education, family and lives to attend to beside roaming forums.

 

EDIT: Unfortunately, I can't help you with this.


Edited by assainator, 03 December 2013 - 04:10 AM.

"What? It disintegrated. By definition, it cannot be fixed." - Gru - Dispicable me

"Dude, the world is only limited by your imagination" - Me


#4 N.I.B.   Members   -  Reputation: 1022

Like
0Likes
Like

Posted 03 December 2013 - 04:12 AM

Read this.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS