Skip to content

Instantly share code, notes, and snippets.

@kvisle
Created April 8, 2013 20:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kvisle/22310f3553804f74bd79 to your computer and use it in GitHub Desktop.
Save kvisle/22310f3553804f74bd79 to your computer and use it in GitHub Desktop.
--- fragment.glsl.orig 2013-04-08 22:27:04.903386987 +0200
+++ fragment.glsl 2013-04-08 22:20:22.923377816 +0200
@@ -1,20 +1,19 @@
uniform sampler2D DiffuseMap;
uniform sampler2D NormalMap;
-
-attribute vec2 ex_TexCoord;
-attribute vec3 ex_LightVec;
+varying vec2 ex_TexCoord;
+varying vec3 ex_LightVec;
void main()
{
vec3 DiffuseColor = texture2D( DiffuseMap, ex_TexCoord ).rgb;
//get normal from map, and rescale from [0,1] to [-1,1]
- vec3 Ntex = texture( NormalMap, ex_TexCoord ).rgb;
- N = Ntex*2.0 - 1.0;
+ vec3 Ntex = texture2D( NormalMap, ex_TexCoord ).rgb;
+ vec3 N = Ntex*2.0 - 1.0;
N = normalize( N );
vec3 L = normalize( ex_LightVec );
float LambertFactor = max( dot( N, L ), 0.0 );
- out_Color = vec4( DiffuseColor*LambertFactor, 1.0 );
+ gl_FragColor = vec4(DiffuseColor * LambertFactor, 1.0);
}
--- vertex.glsl.orig 2013-04-08 22:26:50.099386651 +0200
+++ vertex.glsl 2013-04-08 22:20:10.643377535 +0200
@@ -1,3 +1,6 @@
+#version 120
+
+uniform mat3 u_normalMatrix;
uniform mat4 u_projectionMatrix;
uniform mat4 u_viewMatrix;
uniform mat4 u_modelMatrix;
@@ -6,26 +9,24 @@
attribute vec2 in_TexCoord;
attribute vec3 in_Normal;
attribute vec3 in_Tangent;
-attribute vec3 in_Bitangent;
varying vec2 ex_TexCoord;
varying vec3 ex_LightVec;
void main()
{
-
mat4 MVMatrix = u_viewMatrix * u_modelMatrix;
mat4 MVPMatrix = u_projectionMatrix * MVMatrix;
- //Normalmatrix should be passed as uniform, calculated on clientside(in your program)
- mat3 NormalMatrix = mat3( inverse( MVMatrix ) );
+ // Normalmatrix should be passed as uniform, calculated on clientside(in your program)
+ mat3 NormalMatrix = mat3( MVMatrix );
vec4 E_VertexPos = MVMatrix * vec4(in_Position, 1.0);
- vec3 E_Normal = normalize( NormalMatrix * in_Normal );
- vec3 E_Tangent = normalize( NormalMatrix * in_Tangent );
+ vec3 E_LightVec = normalize( vec3(15.0, 26.5, 0.5) - in_Position);
+ vec3 E_Normal = normalize( u_normalMatrix * in_Normal );
+ vec3 E_Tangent = normalize( u_normalMatrix * in_Tangent );
vec3 E_BiTangent = normalize(cross( E_Normal, E_Tangent ));
// Eye -> TBN matrix
- // no need to inverse, transpose will do as we wont do non-uniform scaling
mat3 E_TBN = transpose( mat3( E_Tangent, E_BiTangent, E_Normal ) );
vec3 T_LightVec = normalize( E_TBN * E_LightVec );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment