aboutsummaryrefslogtreecommitdiff
path: root/data/shaders/light-basic-texgen.vert
diff options
context:
space:
mode:
authorFathi Boudra <fathi.boudra@linaro.org>2013-03-30 17:38:14 +0200
committerFathi Boudra <fathi.boudra@linaro.org>2013-03-30 17:38:14 +0200
commit341f04dca0008c290cf065c4b36348fd80fe9700 (patch)
treeab372775bee83fd6c6500c75fd066315f725981d /data/shaders/light-basic-texgen.vert
Imported Upstream version 2012.12HEADupstream/2012.12upstreammaster
Diffstat (limited to 'data/shaders/light-basic-texgen.vert')
-rw-r--r--data/shaders/light-basic-texgen.vert30
1 files changed, 30 insertions, 0 deletions
diff --git a/data/shaders/light-basic-texgen.vert b/data/shaders/light-basic-texgen.vert
new file mode 100644
index 0000000..6198a64
--- /dev/null
+++ b/data/shaders/light-basic-texgen.vert
@@ -0,0 +1,30 @@
+attribute vec3 position;
+attribute vec3 normal;
+
+uniform mat4 ModelViewProjectionMatrix;
+uniform mat4 NormalMatrix;
+uniform vec3 CenterPoint;
+
+varying vec4 Color;
+varying vec2 TextureCoord;
+
+void main(void)
+{
+ // Transform the normal to eye coordinates
+ vec3 N = normalize(vec3(NormalMatrix * vec4(normal, 1.0)));
+
+ // The LightSourcePosition is actually its direction for directional light
+ vec3 L = normalize(LightSourcePosition.xyz);
+
+ // Multiply the diffuse value by the vertex color (which is fixed in this case)
+ // to get the actual color that we will use to draw this vertex with
+ float diffuse = max(dot(N, L), 0.0);
+ Color = vec4(diffuse * MaterialDiffuse.rgb, MaterialDiffuse.a);
+
+ // Compute the texture coordinate and as a varying
+ vec3 vnorm = normalize(position - CenterPoint);
+ TextureCoord = asin(vnorm.xy) / PI + 0.5;
+
+ // Transform the position to clip coordinates
+ gl_Position = ModelViewProjectionMatrix * vec4(position, 1.0);
+}