Jason McKesson avatar Jason McKesson committed ad14d09

Tut13: Basic scene works.

Comments (0)

Files changed (13)

Tut 12 Dynamic Range/data/PCN.vert

 #version 330
 
+layout(std140) uniform;
+
 layout(location = 0) in vec3 position;
 layout(location = 1) in vec4 inDiffuseColor;
 layout(location = 2) in vec3 normal;

Tut 12 Dynamic Range/data/PN.vert

 #version 330
 
+layout(std140) uniform;
+
 layout(location = 0) in vec3 position;
 layout(location = 2) in vec3 normal;
 

Tut 12 Dynamic Range/data/PosTransform.vert

 #version 330
 
+layout(std140) uniform;
+
 layout(location = 0) in vec3 position;
 
 uniform Projection

Tut 13 Imposters/BasicImposter.cpp

 #include "../framework/MatrixStack.h"
 #include "../framework/MousePole.h"
 #include "../framework/ObjectPole.h"
+#include "../framework/Timer.h"
 #include "../framework/UniformBlockArray.h"
 #include <glm/glm.hpp>
 #include <glm/gtc/type_ptr.hpp>
 	g_Unlit = LoadUnlitProgram("Unlit.vert", "Unlit.frag");
 }
 
-Framework::RadiusDef radiusDef = {5.0f, 3.0f, 200.0f, 1.5f, 0.5f};
-glm::vec3 objectCenter = glm::vec3(0.0f, 10.0f, 0.0f);
+Framework::RadiusDef radiusDef = {10.0f, 3.0f, 70.0f, 3.5f, 1.5f};
+glm::vec3 objectCenter = glm::vec3(0.0f, 30.0f, 25.0f);
 
 Framework::MousePole g_mousePole(objectCenter, radiusDef);
 Framework::ObjectPole g_objectPole(objectCenter, &g_mousePole);
 	glm::vec4 lightIntensity;
 };
 
-const int NUMBER_OF_LIGHTS = 1;
+const int NUMBER_OF_LIGHTS = 2;
 
 struct LightBlock
 {
 	glm::vec4 ambientIntensity;
 	float lightAttenuation;
-	float maxIntensity;
-	float gamma;
-	float padding;
+	float padding[3];
 	PerLight lights[NUMBER_OF_LIGHTS];
 };
 
 
 Framework::Mesh *g_pPlaneMesh = NULL;
 Framework::Mesh *g_pSphereMesh = NULL;
+Framework::Mesh *g_pCubeMesh = NULL;
 
 GLuint g_lightUniformBuffer = 0;
 GLuint g_projectionUniformBuffer = 0;
 
 int g_materialBlockOffset = 0;
 
+enum MaterialNames
+{
+	MTL_TERRAIN = 0,
+	MTL_BLUE_SHINY,
+	MTL_GOLD_METAL,
+	MTL_DULL_GREY,
+	MTL_BLACK_SHINY,
+
+	NUM_MATERIALS,
+};
+
 void CreateMaterials()
 {
-	Framework::UniformBlockArray<MaterialBlock, 1> ubArray;
+	Framework::UniformBlockArray<MaterialBlock, NUM_MATERIALS> ubArray;
 	g_materialBlockOffset = ubArray.GetArrayOffset();
 
 	MaterialBlock mtl;
 	mtl.diffuseColor = glm::vec4(0.5f, 0.5f, 0.5f, 1.0f);
 	mtl.specularColor = glm::vec4(0.5f, 0.5f, 0.5f, 1.0f);
 	mtl.specularShininess = 0.6f;
-	ubArray[0] = mtl;
+	ubArray[MTL_TERRAIN] = mtl;
+
+	mtl.diffuseColor = glm::vec4(0.1f, 0.1f, 0.8f, 1.0f);
+	mtl.specularColor = glm::vec4(0.8f, 0.8f, 0.8f, 1.0f);
+	mtl.specularShininess = 0.1f;
+	ubArray[MTL_BLUE_SHINY] = mtl;
+
+	mtl.diffuseColor = glm::vec4(0.803f, 0.709f, 0.15f, 1.0f);
+	mtl.specularColor = glm::vec4(0.803f, 0.709f, 0.15f, 1.0f) * 0.75;
+	mtl.specularShininess = 0.18f;
+	ubArray[MTL_GOLD_METAL] = mtl;
+
+	mtl.diffuseColor = glm::vec4(0.4f, 0.4f, 0.4f, 1.0f);
+	mtl.specularColor = glm::vec4(0.1f, 0.1f, 0.1f, 1.0f);
+	mtl.specularShininess = 0.8f;
+	ubArray[MTL_DULL_GREY] = mtl;
+
+	mtl.diffuseColor = glm::vec4(0.05f, 0.05f, 0.05f, 1.0f);
+	mtl.specularColor = glm::vec4(0.95f, 0.95f, 0.95f, 1.0f);
+	mtl.specularShininess = 0.3f;
+	ubArray[MTL_BLACK_SHINY] = mtl;
 
 	g_materialUniformBuffer = ubArray.CreateBufferObject();
 }
 	{
 		g_pPlaneMesh = new Framework::Mesh("LargePlane.xml");
 		g_pSphereMesh = new Framework::Mesh("UnitSphere.xml");
+		g_pCubeMesh = new Framework::Mesh("UnitCube.xml");
 	}
 	catch(std::exception &except)
 	{
 	CreateMaterials();
 }
 
+void DrawMeshSphere(Framework::MatrixStack &modelMatrix,
+					const glm::vec3 &position, float radius, MaterialNames material)
+{
+	Framework::MatrixStackPusher push(modelMatrix);
+	modelMatrix.Translate(position);
+	modelMatrix.Scale(radius * 2.0f); //The unit sphere has a radius 0.5f.
+
+	glm::mat3 normMatrix(modelMatrix.Top());
+	normMatrix = glm::transpose(glm::inverse(normMatrix));
+
+	glUseProgram(g_litMeshProg.theProgram);
+	glUniformMatrix4fv(g_litMeshProg.modelToCameraMatrixUnif, 1, GL_FALSE,
+		glm::value_ptr(modelMatrix.Top()));
+	glUniformMatrix3fv(g_litMeshProg.normalModelToCameraMatrixUnif, 1, GL_FALSE,
+		glm::value_ptr(normMatrix));
+
+	glBindBufferRange(GL_UNIFORM_BUFFER, g_materialBlockIndex, g_materialUniformBuffer,
+		material * g_materialBlockOffset, sizeof(MaterialBlock));
+
+	g_pSphereMesh->Render("lit");
+
+	glUseProgram(0);
+	glBindBufferRange(GL_UNIFORM_BUFFER, g_materialBlockIndex, 0, 0, 0);
+}
+
+void DrawSphereOrbit(Framework::MatrixStack &modelMatrix,
+					 const glm::vec3 &orbitCenter, const glm::vec3 &orbitAxis,
+					 float orbitRadius, float orbitAlpha, float sphereRadius, MaterialNames material)
+{
+	Framework::MatrixStackPusher push(modelMatrix);
+
+	modelMatrix.Translate(orbitCenter);
+	modelMatrix.Rotate(orbitAxis, 360.0f * orbitAlpha);
+
+	glm::vec3 offsetDir = glm::cross(orbitAxis, glm::vec3(0.0f, 1.0f, 0.0f));
+	if(glm::length(offsetDir) < 0.001f)
+		offsetDir = glm::cross(orbitAxis, glm::vec3(1.0f, 0.0f, 0.0f));
+
+	offsetDir = glm::normalize(offsetDir);
+
+	modelMatrix.Translate(offsetDir * orbitRadius);
+
+	DrawMeshSphere(modelMatrix, glm::vec3(0.0f), sphereRadius, material);
+}
+
+bool g_bDrawCameraPos = false;
+bool g_bDrawLights = true;
+
+Framework::Timer g_sphereTimer(Framework::Timer::TT_LOOP, 6.0f);
+
+float g_lightHeight = 20.0f;
+
+glm::vec4 CalcLightPosition()
+{
+	const float fLoopDuration = 5.0f;
+	const float fScale = 3.14159f * 2.0f;
+
+	float timeThroughLoop = g_sphereTimer.GetAlpha();
+
+	glm::vec4 ret(0.0f, g_lightHeight, 0.0f, 1.0f);
+
+	ret.x = cosf(timeThroughLoop * fScale) * 20.0f;
+	ret.z = sinf(timeThroughLoop * fScale) * 20.0f;
+
+	return ret;
+}
+
+const float g_fHalfLightDistance = 25.0f;
+const float g_fLightAttenuation = 1.0f / (g_fHalfLightDistance * g_fHalfLightDistance);
+
 //Called to update the display.
 //You should call glutSwapBuffers after all of your rendering to display what you rendered.
 //If you need continuous updates of the screen, call glutPostRedisplay() at the end of the function.
-
 void display()
 {
-	glClearColor(0.5f, 1.0f, 0.5f, 1.0f);
+	g_sphereTimer.Update();
+
+	glClearColor(0.75f, 0.75f, 1.0f, 1.0f);
 	glClearDepth(1.0f);
 	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
 		LightBlock lightData;
 
 		lightData.ambientIntensity = glm::vec4(0.2f, 0.2f, 0.2f, 1.0f);
-		lightData.lightAttenuation = 25.0f;
-		lightData.maxIntensity = 1.0f;
-		lightData.gamma = 2.2f;
+		lightData.lightAttenuation = g_fLightAttenuation;
 
-		lightData.lights[0].cameraSpaceLightPos = worldToCamMat * glm::vec4(0.0f, 1.0f, 0.0f, 0.0f);
+		lightData.lights[0].cameraSpaceLightPos = worldToCamMat * glm::vec4(0.707f, 0.707f, 0.0f, 0.0f);
 		lightData.lights[0].lightIntensity = glm::vec4(0.6f, 0.6f, 0.6f, 1.0f);
 
+		lightData.lights[1].cameraSpaceLightPos = worldToCamMat * CalcLightPosition();
+		lightData.lights[1].lightIntensity = glm::vec4(0.4f, 0.4f, 0.4f, 1.0f);
+
 		glBindBuffer(GL_UNIFORM_BUFFER, g_lightUniformBuffer);
 		glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(lightData), &lightData);
 		glBindBuffer(GL_UNIFORM_BUFFER, 0);
 
 		{
 			glBindBufferRange(GL_UNIFORM_BUFFER, g_materialBlockIndex, g_materialUniformBuffer,
-				0 * g_materialBlockOffset, sizeof(MaterialBlock));
+				MTL_TERRAIN * g_materialBlockOffset, sizeof(MaterialBlock));
 
 			glm::mat3 normMatrix(modelMatrix.Top());
 			normMatrix = glm::transpose(glm::inverse(normMatrix));
 			glUseProgram(0);
 			glBindBufferRange(GL_UNIFORM_BUFFER, g_materialBlockIndex, 0, 0, 0);
 		}
+
+		DrawMeshSphere(modelMatrix, glm::vec3(0.0f, 10.0f, 0.0f), 4.0f, MTL_BLUE_SHINY);
+		DrawSphereOrbit(modelMatrix, glm::vec3(0.0f, 10.0f, 0.0f), glm::vec3(0.6f, 0.8f, 0.0f),
+			20.0f, g_sphereTimer.GetAlpha(), 2.0f, MTL_DULL_GREY);
+		DrawSphereOrbit(modelMatrix, glm::vec3(-10.0f, 1.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f),
+			10.0f, g_sphereTimer.GetAlpha(), 1.0f, MTL_BLACK_SHINY);
+		DrawSphereOrbit(modelMatrix, glm::vec3(10.0f, 1.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f),
+			10.0f, g_sphereTimer.GetAlpha() * 2.0f, 1.0f, MTL_GOLD_METAL);
+
+		if(g_bDrawLights)
+		{
+			Framework::MatrixStackPusher push(modelMatrix);
+
+			modelMatrix.Translate(glm::vec3(CalcLightPosition()));
+			modelMatrix.Scale(0.5f);
+
+			glUseProgram(g_Unlit.theProgram);
+			glUniformMatrix4fv(g_Unlit.modelToCameraMatrixUnif, 1, GL_FALSE,
+				glm::value_ptr(modelMatrix.Top()));
+
+			glm::vec4 lightColor(1.0f);
+			glUniform4fv(g_Unlit.objectColorUnif, 1, glm::value_ptr(lightColor));
+			g_pCubeMesh->Render("flat");
+		}
+
+		if(g_bDrawCameraPos)
+		{
+			Framework::MatrixStackPusher push(modelMatrix);
+
+			modelMatrix.SetIdentity();
+			modelMatrix.Translate(glm::vec3(0.0f, 0.0f, -g_mousePole.GetLookAtDistance()));
+
+			glDisable(GL_DEPTH_TEST);
+			glDepthMask(GL_FALSE);
+			glUseProgram(g_Unlit.theProgram);
+			glUniformMatrix4fv(g_Unlit.modelToCameraMatrixUnif, 1, GL_FALSE,
+				glm::value_ptr(modelMatrix.Top()));
+			glUniform4f(g_Unlit.objectColorUnif, 0.25f, 0.25f, 0.25f, 1.0f);
+			g_pCubeMesh->Render("flat");
+			glDepthMask(GL_TRUE);
+			glEnable(GL_DEPTH_TEST);
+			glUniform4f(g_Unlit.objectColorUnif, 1.0f, 1.0f, 1.0f, 1.0f);
+			g_pCubeMesh->Render("flat");
+		}
 	}
 
 	glutPostRedisplay();
 		glutLeaveMainLoop();
 		break;
 
+	case 'p': g_sphereTimer.TogglePause(); break;
+	case '-': g_sphereTimer.Rewind(0.5f); break;
+	case '=': g_sphereTimer.Fastforward(0.5f); break;
+	case 't': g_bDrawCameraPos = !g_bDrawCameraPos; break;
+	case 'g': g_bDrawLights = !g_bDrawLights; break;
+
 	}
 
-	glutPostRedisplay();
 	g_mousePole.GLUTKeyOffset(key, 5.0f, 1.0f);
 }
 

Tut 13 Imposters/data/GenCube.lua

+require "XmlWriter"
+require "vmath"
+
+local function GenStringFromArray(theArray, bAsInt)
+	local array = {" "}
+	for i, vector in ipairs(theArray) do
+		local elements = vector;
+		if(bAsInt) then
+			elements = {};
+			for i, value in ipairs(vector) do
+				elements[#elements + 1] = string.format("%i", value);
+			end
+		end
+		
+		array[#array + 1] = "        " .. table.concat(vector, " ");
+	end
+	
+	return table.concat(array, "\n");
+end
+
+local positions =
+{
+	--Front
+	vmath.vec3( 0.5,  0.5,  0.5),
+	vmath.vec3( 0.5, -0.5,  0.5),
+	vmath.vec3(-0.5, -0.5,  0.5),
+	vmath.vec3(-0.5,  0.5,  0.5),
+
+	--Top
+	vmath.vec3( 0.5,  0.5,  0.5),
+	vmath.vec3(-0.5,  0.5,  0.5),
+	vmath.vec3(-0.5,  0.5, -0.5),
+	vmath.vec3( 0.5,  0.5, -0.5),
+
+	--Left
+	vmath.vec3( 0.5,  0.5,  0.5),
+	vmath.vec3( 0.5,  0.5, -0.5),
+	vmath.vec3( 0.5, -0.5, -0.5),
+	vmath.vec3( 0.5, -0.5,  0.5),
+
+	--Back
+	vmath.vec3( 0.5,  0.5, -0.5),
+	vmath.vec3(-0.5,  0.5, -0.5),
+	vmath.vec3(-0.5, -0.5, -0.5),
+	vmath.vec3( 0.5, -0.5, -0.5),
+
+	--Bottom
+	vmath.vec3( 0.5, -0.5,  0.5),
+	vmath.vec3( 0.5, -0.5, -0.5),
+	vmath.vec3(-0.5, -0.5, -0.5),
+	vmath.vec3(-0.5, -0.5,  0.5),
+
+	--Right
+	vmath.vec3(-0.5,  0.5,  0.5),
+	vmath.vec3(-0.5, -0.5,  0.5),
+	vmath.vec3(-0.5, -0.5, -0.5),
+	vmath.vec3(-0.5,  0.5, -0.5),
+};
+
+local normals =
+{
+	--Front
+	vmath.vec3(0.0,  0.0,  1.0),
+	vmath.vec3(0.0,  0.0,  1.0),
+	vmath.vec3(0.0,  0.0,  1.0),
+	vmath.vec3(0.0,  0.0,  1.0),
+
+	--Top
+	vmath.vec3(0.0,  1.0,  0.0),
+	vmath.vec3(0.0,  1.0,  0.0),
+	vmath.vec3(0.0,  1.0,  0.0),
+	vmath.vec3(0.0,  1.0,  0.0),
+
+	--Left
+	vmath.vec3(1.0,  0.0,  0.0),
+	vmath.vec3(1.0,  0.0,  0.0),
+	vmath.vec3(1.0,  0.0,  0.0),
+	vmath.vec3(1.0,  0.0,  0.0),
+
+	--Back
+	vmath.vec3(0.0,  0.0, -1.0),
+	vmath.vec3(0.0,  0.0, -1.0),
+	vmath.vec3(0.0,  0.0, -1.0),
+	vmath.vec3(0.0,  0.0, -1.0),
+
+	--Bottom
+	vmath.vec3(0.0, -1.0,  0.0),
+	vmath.vec3(0.0, -1.0,  0.0),
+	vmath.vec3(0.0, -1.0,  0.0),
+	vmath.vec3(0.0, -1.0,  0.0),
+
+	--Right
+	vmath.vec3(-1.0,  0.0,  0.0),
+	vmath.vec3(-1.0,  0.0,  0.0),
+	vmath.vec3(-1.0,  0.0,  0.0),
+	vmath.vec3(-1.0,  0.0,  0.0),
+}
+
+local colors =
+{
+	vmath.vec4(0.25, 1.0, 0.25, 1.0),
+	vmath.vec4(0.25, 1.0, 0.25, 1.0),
+	vmath.vec4(0.25, 1.0, 0.25, 1.0),
+	vmath.vec4(0.25, 1.0, 0.25, 1.0),
+
+	vmath.vec4(0.5, 0.5, 1.0, 1.0),
+	vmath.vec4(0.5, 0.5, 1.0, 1.0),
+	vmath.vec4(0.5, 0.5, 1.0, 1.0),
+	vmath.vec4(0.5, 0.5, 1.0, 1.0),
+
+	vmath.vec4(1.0, 0.5, 0.5, 1.0),
+	vmath.vec4(1.0, 0.5, 0.5, 1.0),
+	vmath.vec4(1.0, 0.5, 0.5, 1.0),
+	vmath.vec4(1.0, 0.5, 0.5, 1.0),
+
+	vmath.vec4(1.0, 1.0, 0.5, 1.0),
+	vmath.vec4(1.0, 1.0, 0.5, 1.0),
+	vmath.vec4(1.0, 1.0, 0.5, 1.0),
+	vmath.vec4(1.0, 1.0, 0.5, 1.0),
+
+	vmath.vec4(0.5, 1.0, 1.0, 1.0),
+	vmath.vec4(0.5, 1.0, 1.0, 1.0),
+	vmath.vec4(0.5, 1.0, 1.0, 1.0),
+	vmath.vec4(0.5, 1.0, 1.0, 1.0),
+
+	vmath.vec4(1.0, 0.5, 1.0, 1.0),
+	vmath.vec4(1.0, 0.5, 1.0, 1.0),
+	vmath.vec4(1.0, 0.5, 1.0, 1.0),
+	vmath.vec4(1.0, 0.5, 1.0, 1.0),
+}
+
+local indices =
+{
+	vmath.vec3(0, 1, 2),
+	vmath.vec3(2, 3, 0),
+
+	vmath.vec3(4, 5, 6),
+	vmath.vec3(6, 7, 4),
+
+	vmath.vec3(8, 9, 10),
+	vmath.vec3(10, 11, 8),
+
+	vmath.vec3(12, 13, 14),
+	vmath.vec3(14, 15, 12),
+
+	vmath.vec3(16, 17, 18),
+	vmath.vec3(18, 19, 16),
+
+	vmath.vec3(20, 21, 22),
+	vmath.vec3(22, 23, 20),
+};
+
+do
+	local writer = XmlWriter.XmlWriter("UnitCube.xml");
+	writer:AddPI("oxygen", [[RNGSchema="../../Documents/meshFormat.rnc" type="compact"]]);
+	writer:PushElement("mesh", "http://www.arcsynthesis.com/gltut/mesh");
+		writer:PushElement("attribute");
+			writer:AddAttribute("index", "0");
+			writer:AddAttribute("type", "float");
+			writer:AddAttribute("size", "3");
+			writer:AddText(GenStringFromArray(positions));
+		writer:PopElement();
+		writer:PushElement("attribute");
+			writer:AddAttribute("index", "1");
+			writer:AddAttribute("type", "float");
+			writer:AddAttribute("size", "4");
+			writer:AddText(GenStringFromArray(colors));
+		writer:PopElement();
+		writer:PushElement("attribute");
+			writer:AddAttribute("index", "2");
+			writer:AddAttribute("type", "float");
+			writer:AddAttribute("size", "3");
+			writer:AddText(GenStringFromArray(normals));
+		writer:PopElement();
+		writer:PushElement("vao");
+			writer:AddAttribute("name", "lit");
+			writer:PushElement("source"); writer:AddAttribute("attrib", "0"); writer:PopElement();
+			writer:PushElement("source"); writer:AddAttribute("attrib", "2"); writer:PopElement();
+		writer:PopElement();
+		writer:PushElement("vao");
+			writer:AddAttribute("name", "lit-color");
+			writer:PushElement("source"); writer:AddAttribute("attrib", "0"); writer:PopElement();
+			writer:PushElement("source"); writer:AddAttribute("attrib", "1"); writer:PopElement();
+			writer:PushElement("source"); writer:AddAttribute("attrib", "2"); writer:PopElement();
+		writer:PopElement();
+		writer:PushElement("vao");
+			writer:AddAttribute("name", "color");
+			writer:PushElement("source"); writer:AddAttribute("attrib", "0"); writer:PopElement();
+			writer:PushElement("source"); writer:AddAttribute("attrib", "1"); writer:PopElement();
+		writer:PopElement();
+		writer:PushElement("vao");
+			writer:AddAttribute("name", "flat");
+			writer:PushElement("source"); writer:AddAttribute("attrib", "0"); writer:PopElement();
+		writer:PopElement();
+		writer:PushElement("indices");
+			writer:AddAttribute("cmd", "triangles");
+			writer:AddAttribute("type", "ushort");
+			writer:AddText(GenStringFromArray(indices, true));
+		writer:PopElement();
+	writer:PopElement();
+	writer:Close();
+end

Tut 13 Imposters/data/GenSphere.lua

 local iSegCount, iColorRepeatCount, iRingCount = ...;
 iSegCount = iSegCount or 10;
 iColorRepeatCount = iColorRepeatCount or 3;
-iRingCount = iRingCount or 5;
+iRingCount = iRingCount or 8;
 
 local rhoAngle = math.pi * 2.0 / iSegCount;
 local thetaAngle = math.pi / (iRingCount + 1);
 			writer:AddText(GenStringFromArray(normals));
 		writer:PopElement();
 		writer:PushElement("vao");
-			writer:AddAttribute("name", "tint");
+			writer:AddAttribute("name", "lit-color");
 			writer:PushElement("source"); writer:AddAttribute("attrib", "0"); writer:PopElement();
 			writer:PushElement("source"); writer:AddAttribute("attrib", "1"); writer:PopElement();
 			writer:PushElement("source"); writer:AddAttribute("attrib", "2"); writer:PopElement();
 		writer:PopElement();
 		writer:PushElement("vao");
-			writer:AddAttribute("name", "flat");
+			writer:AddAttribute("name", "lit");
 			writer:PushElement("source"); writer:AddAttribute("attrib", "0"); writer:PopElement();
 			writer:PushElement("source"); writer:AddAttribute("attrib", "2"); writer:PopElement();
 		writer:PopElement();
 		writer:PushElement("vao");
-			writer:AddAttribute("name", "tint-unlit");
+			writer:AddAttribute("name", "color");
 			writer:PushElement("source"); writer:AddAttribute("attrib", "0"); writer:PopElement();
 			writer:PushElement("source"); writer:AddAttribute("attrib", "1"); writer:PopElement();
 		writer:PopElement();
+		writer:PushElement("vao");
+			writer:AddAttribute("name", "flat");
+			writer:PushElement("source"); writer:AddAttribute("attrib", "0"); writer:PopElement();
+		writer:PopElement();
 		writer:PushElement("indices");
 			writer:AddAttribute("cmd", "tri-fan");
 			writer:AddAttribute("type", "ushort");

Tut 13 Imposters/data/Lighting.frag

 	vec4 lightIntensity;
 };
 
-const int numberOfLights = 1;
+const int numberOfLights = 2;
 
 uniform Light
 {
 	vec4 ambientIntensity;
 	float lightAttenuation;
-	float maxIntensity;
-	float gamma;
 	PerLight lights[numberOfLights];
 } Lgt;
 
 		accumLighting += ComputeLighting(Lgt.lights[light]);
 	}
 	
-	accumLighting = accumLighting / Lgt.maxIntensity;
-	vec4 gamma = vec4(1.0 / Lgt.gamma);
-	gamma.w = 1.0;
-	outputColor = pow(accumLighting, gamma);
+	outputColor = sqrt(accumLighting); //2.0 gamma correction
 }

Tut 13 Imposters/data/PN.vert

 #version 330
 
+layout(std140) uniform;
+
 layout(location = 0) in vec3 position;
 layout(location = 2) in vec3 normal;
 

Tut 13 Imposters/data/UnitCube.xml

+<?xml version="1.0" encoding="UTF-8"?>
+<?oxygen RNGSchema="../../Documents/meshFormat.rnc" type="compact"?>
+
+<mesh xmlns="http://www.arcsynthesis.com/gltut/mesh" >
+	<attribute index="0" type="float" size="3" > 
+        0.5 0.5 0.5
+        0.5 -0.5 0.5
+        -0.5 -0.5 0.5
+        -0.5 0.5 0.5
+        0.5 0.5 0.5
+        -0.5 0.5 0.5
+        -0.5 0.5 -0.5
+        0.5 0.5 -0.5
+        0.5 0.5 0.5
+        0.5 0.5 -0.5
+        0.5 -0.5 -0.5
+        0.5 -0.5 0.5
+        0.5 0.5 -0.5
+        -0.5 0.5 -0.5
+        -0.5 -0.5 -0.5
+        0.5 -0.5 -0.5
+        0.5 -0.5 0.5
+        0.5 -0.5 -0.5
+        -0.5 -0.5 -0.5
+        -0.5 -0.5 0.5
+        -0.5 0.5 0.5
+        -0.5 -0.5 0.5
+        -0.5 -0.5 -0.5
+        -0.5 0.5 -0.5</attribute>
+	<attribute index="1" type="float" size="4" > 
+        0.25 1 0.25 1
+        0.25 1 0.25 1
+        0.25 1 0.25 1
+        0.25 1 0.25 1
+        0.5 0.5 1 1
+        0.5 0.5 1 1
+        0.5 0.5 1 1
+        0.5 0.5 1 1
+        1 0.5 0.5 1
+        1 0.5 0.5 1
+        1 0.5 0.5 1
+        1 0.5 0.5 1
+        1 1 0.5 1
+        1 1 0.5 1
+        1 1 0.5 1
+        1 1 0.5 1
+        0.5 1 1 1
+        0.5 1 1 1
+        0.5 1 1 1
+        0.5 1 1 1
+        1 0.5 1 1
+        1 0.5 1 1
+        1 0.5 1 1
+        1 0.5 1 1</attribute>
+	<attribute index="2" type="float" size="3" > 
+        0 0 1
+        0 0 1
+        0 0 1
+        0 0 1
+        0 1 0
+        0 1 0
+        0 1 0
+        0 1 0
+        1 0 0
+        1 0 0
+        1 0 0
+        1 0 0
+        0 0 -1
+        0 0 -1
+        0 0 -1
+        0 0 -1
+        0 -1 0
+        0 -1 0
+        0 -1 0
+        0 -1 0
+        -1 0 0
+        -1 0 0
+        -1 0 0
+        -1 0 0</attribute>
+	<vao name="lit" >
+		<source attrib="0" />
+		<source attrib="2" />
+	</vao>
+	<vao name="lit-color" >
+		<source attrib="0" />
+		<source attrib="1" />
+		<source attrib="2" />
+	</vao>
+	<vao name="color" >
+		<source attrib="0" />
+		<source attrib="1" />
+	</vao>
+	<vao name="flat" >
+		<source attrib="0" />
+	</vao>
+	<indices cmd="triangles" type="ushort" > 
+        0 1 2
+        2 3 0
+        4 5 6
+        6 7 4
+        8 9 10
+        10 11 8
+        12 13 14
+        14 15 12
+        16 17 18
+        18 19 16
+        20 21 22
+        22 23 20</indices>
+</mesh>

Tut 13 Imposters/data/UnitSphere.xml

 <mesh xmlns="http://www.arcsynthesis.com/gltut/mesh" >
 	<attribute index="0" type="float" size="3" > 
         0 0.5 0
-        0.25 0.43301270189222 0
-        0.20225424859374 0.43301270189222 0.14694631307312
-        0.077254248593737 0.43301270189222 0.23776412907379
-        -0.077254248593737 0.43301270189222 0.23776412907379
-        -0.20225424859374 0.43301270189222 0.14694631307312
-        -0.25 0.43301270189222 3.0615158845559e-017
-        -0.20225424859374 0.43301270189222 -0.14694631307312
-        -0.077254248593737 0.43301270189222 -0.23776412907379
-        0.077254248593737 0.43301270189222 -0.23776412907379
-        0.20225424859374 0.43301270189222 -0.14694631307312
+        0.17101007166283 0.46984631039295 0
+        0.13835005418451 0.46984631039295 0.10051719811689
+        0.052845018353093 0.46984631039295 0.16264024300704
+        -0.052845018353093 0.46984631039295 0.16264024300704
+        -0.13835005418451 0.46984631039295 0.10051719811689
+        -0.17101007166283 0.46984631039295 2.0942002032593e-017
+        -0.13835005418451 0.46984631039295 -0.10051719811689
+        -0.052845018353093 0.46984631039295 -0.16264024300704
+        0.052845018353093 0.46984631039295 -0.16264024300704
+        0.13835005418451 0.46984631039295 -0.10051719811689
+        0.32139380484327 0.38302222155949 0
+        0.26001305000503 0.38302222155949 0.18891053866504
+        0.099316147583396 0.38302222155949 0.30566367239308
+        -0.099316147583396 0.38302222155949 0.30566367239308
+        -0.26001305000503 0.38302222155949 0.18891053866504
+        -0.32139380484327 0.38302222155949 3.9358089549022e-017
+        -0.26001305000503 0.38302222155949 -0.18891053866504
+        -0.099316147583396 0.38302222155949 -0.30566367239308
+        0.099316147583396 0.38302222155949 -0.30566367239308
+        0.26001305000503 0.38302222155949 -0.18891053866504
         0.43301270189222 0.25 0
         0.35031463461102 0.25 0.25451848022756
         0.13380828366491 0.25 0.41181955177317
         -0.13380828366491 0.25 -0.41181955177317
         0.13380828366491 0.25 -0.41181955177317
         0.35031463461102 0.25 -0.25451848022756
-        0.5 3.0615158845559e-017 0
-        0.40450849718747 3.0615158845559e-017 0.29389262614624
-        0.15450849718747 3.0615158845559e-017 0.47552825814758
-        -0.15450849718747 3.0615158845559e-017 0.47552825814758
-        -0.40450849718747 3.0615158845559e-017 0.29389262614624
-        -0.5 3.0615158845559e-017 6.1230317691119e-017
-        -0.40450849718747 3.0615158845559e-017 -0.29389262614624
-        -0.15450849718747 3.0615158845559e-017 -0.47552825814758
-        0.15450849718747 3.0615158845559e-017 -0.47552825814758
-        0.40450849718747 3.0615158845559e-017 -0.29389262614624
+        0.4924038765061 0.086824088833465 0
+        0.39836310418954 0.086824088833465 0.28942773678193
+        0.15216116593649 0.086824088833465 0.46830391540012
+        -0.15216116593649 0.086824088833465 0.46830391540012
+        -0.39836310418954 0.086824088833465 0.28942773678193
+        -0.4924038765061 0.086824088833465 6.0300091581614e-017
+        -0.39836310418954 0.086824088833465 -0.28942773678193
+        -0.15216116593649 0.086824088833465 -0.46830391540012
+        0.15216116593649 0.086824088833465 -0.46830391540012
+        0.39836310418954 0.086824088833465 -0.28942773678193
+        0.4924038765061 -0.086824088833465 0
+        0.39836310418954 -0.086824088833465 0.28942773678193
+        0.15216116593649 -0.086824088833465 0.46830391540012
+        -0.15216116593649 -0.086824088833465 0.46830391540012
+        -0.39836310418954 -0.086824088833465 0.28942773678193
+        -0.4924038765061 -0.086824088833465 6.0300091581614e-017
+        -0.39836310418954 -0.086824088833465 -0.28942773678193
+        -0.15216116593649 -0.086824088833465 -0.46830391540012
+        0.15216116593649 -0.086824088833465 -0.46830391540012
+        0.39836310418954 -0.086824088833465 -0.28942773678193
         0.43301270189222 -0.25 0
         0.35031463461102 -0.25 0.25451848022756
         0.13380828366491 -0.25 0.41181955177317
         -0.13380828366491 -0.25 -0.41181955177317
         0.13380828366491 -0.25 -0.41181955177317
         0.35031463461102 -0.25 -0.25451848022756
-        0.25 -0.43301270189222 0
-        0.20225424859374 -0.43301270189222 0.14694631307312
-        0.077254248593737 -0.43301270189222 0.23776412907379
-        -0.077254248593737 -0.43301270189222 0.23776412907379
-        -0.20225424859374 -0.43301270189222 0.14694631307312
-        -0.25 -0.43301270189222 3.0615158845559e-017
-        -0.20225424859374 -0.43301270189222 -0.14694631307312
-        -0.077254248593737 -0.43301270189222 -0.23776412907379
-        0.077254248593737 -0.43301270189222 -0.23776412907379
-        0.20225424859374 -0.43301270189222 -0.14694631307312
+        0.32139380484327 -0.38302222155949 0
+        0.26001305000503 -0.38302222155949 0.18891053866504
+        0.099316147583396 -0.38302222155949 0.30566367239308
+        -0.099316147583396 -0.38302222155949 0.30566367239308
+        -0.26001305000503 -0.38302222155949 0.18891053866504
+        -0.32139380484327 -0.38302222155949 3.9358089549022e-017
+        -0.26001305000503 -0.38302222155949 -0.18891053866504
+        -0.099316147583396 -0.38302222155949 -0.30566367239308
+        0.099316147583396 -0.38302222155949 -0.30566367239308
+        0.26001305000503 -0.38302222155949 -0.18891053866504
+        0.17101007166283 -0.46984631039295 0
+        0.13835005418451 -0.46984631039295 0.10051719811689
+        0.052845018353093 -0.46984631039295 0.16264024300704
+        -0.052845018353093 -0.46984631039295 0.16264024300704
+        -0.13835005418451 -0.46984631039295 0.10051719811689
+        -0.17101007166283 -0.46984631039295 2.0942002032593e-017
+        -0.13835005418451 -0.46984631039295 -0.10051719811689
+        -0.052845018353093 -0.46984631039295 -0.16264024300704
+        0.052845018353093 -0.46984631039295 -0.16264024300704
+        0.13835005418451 -0.46984631039295 -0.10051719811689
         0 -0.5 0</attribute>
 	<attribute index="1" type="float" size="4" > 
         1 1 1 1
         1 1 1 1
         1 1 1 1
         1 1 1 1
+        1 1 1 1
+        1 1 1 1
+        1 1 1 1
+        1 1 1 1
+        1 1 1 1
+        1 1 1 1
+        1 1 1 1
+        1 1 1 1
+        1 1 1 1
+        1 1 1 1
+        1 1 1 1
+        1 1 1 1
+        1 1 1 1
+        1 1 1 1
+        1 1 1 1
+        1 1 1 1
+        1 1 1 1
+        1 1 1 1
+        1 1 1 1
+        1 1 1 1
+        1 1 1 1
+        1 1 1 1
+        1 1 1 1
+        1 1 1 1
+        1 1 1 1
+        1 1 1 1
+        1 1 1 1
+        1 1 1 1
+        1 1 1 1
+        1 1 1 1
         1 1 1 1</attribute>
 	<attribute index="2" type="float" size="3" > 
         0 1 0
-        0.5 0.86602540378444 0
-        0.40450849718747 0.86602540378444 0.29389262614624
-        0.15450849718747 0.86602540378444 0.47552825814758
-        -0.15450849718747 0.86602540378444 0.47552825814758
-        -0.40450849718747 0.86602540378444 0.29389262614624
-        -0.5 0.86602540378444 6.1230317691119e-017
-        -0.40450849718747 0.86602540378444 -0.29389262614624
-        -0.15450849718747 0.86602540378444 -0.47552825814758
-        0.15450849718747 0.86602540378444 -0.47552825814758
-        0.40450849718747 0.86602540378444 -0.29389262614624
+        0.34202014332567 0.93969262078591 0
+        0.27670010836902 0.93969262078591 0.20103439623379
+        0.10569003670619 0.93969262078591 0.32528048601408
+        -0.10569003670619 0.93969262078591 0.32528048601408
+        -0.27670010836902 0.93969262078591 0.20103439623379
+        -0.34202014332567 0.93969262078591 4.1884004065185e-017
+        -0.27670010836902 0.93969262078591 -0.20103439623379
+        -0.10569003670619 0.93969262078591 -0.32528048601408
+        0.10569003670619 0.93969262078591 -0.32528048601408
+        0.27670010836902 0.93969262078591 -0.20103439623379
+        0.64278760968654 0.76604444311898 0
+        0.52002610001006 0.76604444311898 0.37782107733008
+        0.19863229516679 0.76604444311898 0.61132734478617
+        -0.19863229516679 0.76604444311898 0.61132734478617
+        -0.52002610001006 0.76604444311898 0.37782107733008
+        -0.64278760968654 0.76604444311898 7.8716179098043e-017
+        -0.52002610001006 0.76604444311898 -0.37782107733008
+        -0.19863229516679 0.76604444311898 -0.61132734478617
+        0.19863229516679 0.76604444311898 -0.61132734478617
+        0.52002610001006 0.76604444311898 -0.37782107733008
         0.86602540378444 0.5 0
         0.70062926922204 0.5 0.50903696045513
         0.26761656732982 0.5 0.82363910354633
         -0.26761656732982 0.5 -0.82363910354633
         0.26761656732982 0.5 -0.82363910354633
         0.70062926922204 0.5 -0.50903696045513
-        1 6.1230317691119e-017 0
-        0.80901699437495 6.1230317691119e-017 0.58778525229247
-        0.30901699437495 6.1230317691119e-017 0.95105651629515
-        -0.30901699437495 6.1230317691119e-017 0.95105651629515
-        -0.80901699437495 6.1230317691119e-017 0.58778525229247
-        -1 6.1230317691119e-017 1.2246063538224e-016
-        -0.80901699437495 6.1230317691119e-017 -0.58778525229247
-        -0.30901699437495 6.1230317691119e-017 -0.95105651629515
-        0.30901699437495 6.1230317691119e-017 -0.95105651629515
-        0.80901699437495 6.1230317691119e-017 -0.58778525229247
+        0.98480775301221 0.17364817766693 0
+        0.79672620837908 0.17364817766693 0.57885547356386
+        0.30432233187298 0.17364817766693 0.93660783080025
+        -0.30432233187298 0.17364817766693 0.93660783080025
+        -0.79672620837908 0.17364817766693 0.57885547356386
+        -0.98480775301221 0.17364817766693 1.2060018316323e-016
+        -0.79672620837908 0.17364817766693 -0.57885547356386
+        -0.30432233187298 0.17364817766693 -0.93660783080025
+        0.30432233187298 0.17364817766693 -0.93660783080025
+        0.79672620837908 0.17364817766693 -0.57885547356386
+        0.98480775301221 -0.17364817766693 0
+        0.79672620837908 -0.17364817766693 0.57885547356386
+        0.30432233187298 -0.17364817766693 0.93660783080025
+        -0.30432233187298 -0.17364817766693 0.93660783080025
+        -0.79672620837908 -0.17364817766693 0.57885547356386
+        -0.98480775301221 -0.17364817766693 1.2060018316323e-016
+        -0.79672620837908 -0.17364817766693 -0.57885547356386
+        -0.30432233187298 -0.17364817766693 -0.93660783080025
+        0.30432233187298 -0.17364817766693 -0.93660783080025
+        0.79672620837908 -0.17364817766693 -0.57885547356386
         0.86602540378444 -0.5 0
         0.70062926922204 -0.5 0.50903696045513
         0.26761656732982 -0.5 0.82363910354633
         -0.26761656732982 -0.5 -0.82363910354633
         0.26761656732982 -0.5 -0.82363910354633
         0.70062926922204 -0.5 -0.50903696045513
-        0.5 -0.86602540378444 0
-        0.40450849718747 -0.86602540378444 0.29389262614624
-        0.15450849718747 -0.86602540378444 0.47552825814758
-        -0.15450849718747 -0.86602540378444 0.47552825814758
-        -0.40450849718747 -0.86602540378444 0.29389262614624
-        -0.5 -0.86602540378444 6.1230317691119e-017
-        -0.40450849718747 -0.86602540378444 -0.29389262614624
-        -0.15450849718747 -0.86602540378444 -0.47552825814758
-        0.15450849718747 -0.86602540378444 -0.47552825814758
-        0.40450849718747 -0.86602540378444 -0.29389262614624
+        0.64278760968654 -0.76604444311898 0
+        0.52002610001006 -0.76604444311898 0.37782107733008
+        0.19863229516679 -0.76604444311898 0.61132734478617
+        -0.19863229516679 -0.76604444311898 0.61132734478617
+        -0.52002610001006 -0.76604444311898 0.37782107733008
+        -0.64278760968654 -0.76604444311898 7.8716179098043e-017
+        -0.52002610001006 -0.76604444311898 -0.37782107733008
+        -0.19863229516679 -0.76604444311898 -0.61132734478617
+        0.19863229516679 -0.76604444311898 -0.61132734478617
+        0.52002610001006 -0.76604444311898 -0.37782107733008
+        0.34202014332567 -0.93969262078591 0
+        0.27670010836902 -0.93969262078591 0.20103439623379
+        0.10569003670619 -0.93969262078591 0.32528048601408
+        -0.10569003670619 -0.93969262078591 0.32528048601408
+        -0.27670010836902 -0.93969262078591 0.20103439623379
+        -0.34202014332567 -0.93969262078591 4.1884004065185e-017
+        -0.27670010836902 -0.93969262078591 -0.20103439623379
+        -0.10569003670619 -0.93969262078591 -0.32528048601408
+        0.10569003670619 -0.93969262078591 -0.32528048601408
+        0.27670010836902 -0.93969262078591 -0.20103439623379
         0 -1 0</attribute>
-	<vao name="tint" >
+	<vao name="lit-color" >
 		<source attrib="0" />
 		<source attrib="1" />
 		<source attrib="2" />
 	</vao>
-	<vao name="flat" >
+	<vao name="lit" >
 		<source attrib="0" />
 		<source attrib="2" />
 	</vao>
-	<vao name="tint-unlit" >
+	<vao name="color" >
 		<source attrib="0" />
 		<source attrib="1" />
 	</vao>
+	<vao name="flat" >
+		<source attrib="0" />
+	</vao>
 	<indices cmd="tri-fan" type="ushort" >0 1 2 3 4 5 6 7 8 9 10 1</indices>
-	<indices cmd="tri-fan" type="ushort" >51 50 49 48 47 46 45 44 43 42 41 50</indices>
+	<indices cmd="tri-fan" type="ushort" >81 80 79 78 77 76 75 74 73 72 71 80</indices>
 	<indices cmd="tri-strip" type="ushort" >1 11 2 12 3 13 4 14 5 15 6 16 7 17 8 18 9 19 10 20 1 11</indices>
 	<indices cmd="tri-strip" type="ushort" >11 21 12 22 13 23 14 24 15 25 16 26 17 27 18 28 19 29 20 30 11 21</indices>
 	<indices cmd="tri-strip" type="ushort" >21 31 22 32 23 33 24 34 25 35 26 36 27 37 28 38 29 39 30 40 21 31</indices>
 	<indices cmd="tri-strip" type="ushort" >31 41 32 42 33 43 34 44 35 45 36 46 37 47 38 48 39 49 40 50 31 41</indices>
+	<indices cmd="tri-strip" type="ushort" >41 51 42 52 43 53 44 54 45 55 46 56 47 57 48 58 49 59 50 60 41 51</indices>
+	<indices cmd="tri-strip" type="ushort" >51 61 52 62 53 63 54 64 55 65 56 66 57 67 58 68 59 69 60 70 51 61</indices>
+	<indices cmd="tri-strip" type="ushort" >61 71 62 72 63 73 64 74 65 75 66 76 67 77 68 78 69 79 70 80 61 71</indices>
 </mesh>

Tut 13 Imposters/data/Unlit.vert

 #version 330
 
+layout(std140) uniform;
+
 layout(location = 0) in vec3 position;
 
 uniform Projection

framework/MatrixStack.cpp

 
 namespace Framework
 {
-	void MatrixStack::Rotate( glm::vec3 &axisOfRotation, float fAngDeg )
+	void MatrixStack::Rotate( const glm::vec3 &axisOfRotation, float fAngDeg )
 	{
 		float fAngRad = DegToRad(fAngDeg);
 
 		RotateRadians(axisOfRotation, fAngRad);
 	}
 
-	void MatrixStack::RotateRadians( glm::vec3 &axisOfRotation, float fAngRad )
+	void MatrixStack::RotateRadians( const glm::vec3 &axisOfRotation, float fAngRad )
 	{
 		float fCos = cosf(fAngRad);
 		float fInvCos = 1.0f - fCos;

framework/MatrixStack.h

 			return m_currMat;
 		}
 
-		void Rotate(glm::vec3 &axisOfRotation, float fAngDeg);
-		void RotateRadians(glm::vec3 &axisOfRotation, float fAngRad);
+		void Rotate(const glm::vec3 &axisOfRotation, float fAngDeg);
+		void RotateRadians(const glm::vec3 &axisOfRotation, float fAngRad);
 		void RotateX(float fAngDeg);
 		void RotateY(float fAngDeg);
 		void RotateZ(float fAngDeg);
 
 		void Scale(const glm::vec3 &scaleVec);
 		void Scale(float fScaleX, float fScaleY, float fScaleZ) {Scale(glm::vec3(fScaleX, fScaleY, fScaleZ));}
+		void Scale(float uniformScale) {Scale(glm::vec3(uniformScale));}
 		void Translate(const glm::vec3 &offsetVec);
 		void Translate(float fTransX, float fTransY, float fTransZ) {Translate(glm::vec3(fTransX, fTransY, fTransZ));}
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.