=== modified file 'data/shaders/light-basic.frag'
@@ -18,7 +18,7 @@
varying float Diffuse;
void main(void)
-{
-//Multiply the light Diffuse intensity by the color of the cube
- gl_FragColor = Diffuse * vec4(0,0,1,1);
+{
+ // Multiply the light Diffuse intensity by the color of the
+ gl_FragColor = Diffuse * vec4(0.0, 0.0, 1.0, 1.0);
}
=== modified file 'data/shaders/light-basic.vert'
@@ -58,15 +58,25 @@
// lesson, but it even cleared up some stuff for me without even
// thinking about it. GO MATHS :)
+attribute vec3 position;
+attribute vec3 normal;
+attribute vec2 texture;
+
+uniform mat4 ModelViewProjectionMatrix;
+uniform mat4 NormalMatrix;
+uniform vec4 LightSourcePosition;
+uniform vec3 LightSourceDiffuse;
+uniform vec3 MaterialDiffuse;
+
varying float Diffuse;
void main(void)
-{
- vec3 Normal = normalize(gl_NormalMatrix * gl_Normal);
-
- vec3 Light = normalize(gl_LightSource[0].position.xyz);
-
- Diffuse = max(dot(Normal, Light),0.0);
-
- gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
+{
+ vec3 N = normalize(vec3(NormalMatrix * vec4(normal, 1.0)));
+
+ vec3 L = normalize(LightSourcePosition.xyz);
+
+ Diffuse = max(dot(N, L), 0.0);
+
+ gl_Position = ModelViewProjectionMatrix * vec4(position, 1.0);
}
=== modified file 'sceneshading.cpp'
@@ -1,4 +1,5 @@
#include "scene.h"
+#include "matrix.h"
SceneShading::~SceneShading()
{
@@ -79,8 +80,18 @@
glDisable(GL_TEXTURE_2D);
mShader[1].use();
break;
- };
-
+ }
+
+ if (mCurrentPart == 0) {
+ glUniform4fv(mShader[mCurrentPart].mLocations.LightSourcePosition, 1,
+ lightPosition);
+ glUniform3fv(mShader[mCurrentPart].mLocations.LightSourceDiffuse, 1,
+ lightDiffuse);
+ glUniform3fv(mShader[mCurrentPart].mLocations.MaterialDiffuse, 1,
+ mat_diffuse);
+ }
+
+
mCurrentFrame = 0;
mRunning = true;
mStartTime = SDL_GetTicks() / 1000.0;
@@ -128,5 +139,27 @@
glColor3f(0.0f, 1.0f, 1.0f);
- mMesh.render_vbo();
+ if (mCurrentPart == 0) {
+ // Load the ModelViewProjectionMatrix uniform in the shader
+ Matrix4f model_view(1.0f, 1.0f, 1.0f);
+ Matrix4f model_view_proj(mScreen.mProjection);
+
+ model_view.translate(0.0f, 0.0f, -5.0f);
+ model_view.rotate(2 * M_PI * mRotation / 360.0, 0.0f, 1.0f, 0.0f);
+ model_view_proj *= model_view;
+
+ glUniformMatrix4fv(mShader[mCurrentPart].mLocations.ModelViewProjectionMatrix, 1,
+ GL_FALSE, model_view_proj.m);
+
+ // Load the NormalMatrix uniform in the shader
+ // The NormalMatrix is the inverse transpose of the model view matrix.
+ model_view.invert().transpose();
+ glUniformMatrix4fv(mShader[mCurrentPart].mLocations.NormalMatrix, 1,
+ GL_FALSE, model_view.m);
+
+ mMesh.render_vbo_attrib();
+ }
+ else {
+ mMesh.render_vbo();
+ }
}