Commits

Jason McKesson committed a532a85

Tut10: Added the ability to set dark colors on the objects. Makes the specular look more distinct.

Comments (0)

Files changed (4)

Tut 10 Shinies/Blinn vs Phong Lighting.cpp

 	GLuint depthRangeUnif;
 	GLuint lightAttenuationUnif;
 	GLuint shininessFactorUnif;
+	GLuint baseDiffuseColorUnif;
 
 	void SetWindowData(const glm::mat4 cameraToClip, const glm::mat4 clipToCamera, int w, int h)
 	{
 	data.depthRangeUnif = glGetUniformLocation(data.theProgram, "depthRange");
 	data.lightAttenuationUnif = glGetUniformLocation(data.theProgram, "lightAttenuation");
 	data.shininessFactorUnif = glGetUniformLocation(data.theProgram, "shininessFactor");
+	data.baseDiffuseColorUnif = glGetUniformLocation(data.theProgram, "baseDiffuseColor");
 
 	return data;
 }
 
 static bool g_bUseFragmentLighting = true;
 static bool g_bDrawColoredCyl = false;
-static bool g_bDrawLight = false;
+static bool g_bDrawLightSource = false;
 static bool g_bScaleCyl = false;
+static bool g_bDrawDark = false;
 
 const float g_fLightAttenuation = 1.2f;
 
+const glm::vec4 g_darkColor(0.2f, 0.2f, 0.2f, 1.0f);
+const glm::vec4 g_lightColor(1.0f);
+
 class MaterialParams
 {
 public:
 		glUniform3fv(whiteProg.cameraSpaceLightPosUnif,1, glm::value_ptr(lightPosCameraSpace));
 		glUniform1f(whiteProg.lightAttenuationUnif, g_fLightAttenuation);
 		glUniform1f(whiteProg.shininessFactorUnif, g_matParams);
+		glUniform4fv(whiteProg.baseDiffuseColorUnif, 1,
+			g_bDrawDark ? glm::value_ptr(g_darkColor) : glm::value_ptr(g_lightColor));
 
 		glUseProgram(colorProg.theProgram);
 		glUniform4f(colorProg.lightIntensityUnif, 0.8f, 0.8f, 0.8f, 1.0f);
 			}
 
 			//Render the light
-			if(g_bDrawLight)
+			if(g_bDrawLightSource)
 			{
 				Framework::MatrixStackPusher push(modelMatrix);
 
 	case 'O': g_matParams.Increment(false); bChangedShininess = true; break;
 	case 'U': g_matParams.Decrement(false); bChangedShininess = true; break;
 
-	case 'y': g_bDrawLight = !g_bDrawLight; break;
+	case 'y': g_bDrawLightSource = !g_bDrawLightSource; break;
 	case 't': g_bScaleCyl = !g_bScaleCyl; break;
 	case 'b': g_bRotateLight = !g_bRotateLight; break;
+	case 'g': g_bDrawDark = !g_bDrawDark; break;
 	case 'h':
 		g_eLightModel += 2;
 		g_eLightModel %= LM_MAX_LIGHTING_MODEL;

Tut 10 Shinies/Gaussian Specular Lighting.cpp

 	GLuint depthRangeUnif;
 	GLuint lightAttenuationUnif;
 	GLuint shininessFactorUnif;
+	GLuint baseDiffuseColorUnif;
 
 	void SetWindowData(const glm::mat4 cameraToClip, const glm::mat4 clipToCamera, int w, int h)
 	{
 	data.depthRangeUnif = glGetUniformLocation(data.theProgram, "depthRange");
 	data.lightAttenuationUnif = glGetUniformLocation(data.theProgram, "lightAttenuation");
 	data.shininessFactorUnif = glGetUniformLocation(data.theProgram, "shininessFactor");
+	data.baseDiffuseColorUnif = glGetUniformLocation(data.theProgram, "baseDiffuseColor");
 
 	return data;
 }
 
 static bool g_bUseFragmentLighting = true;
 static bool g_bDrawColoredCyl = false;
-static bool g_bDrawLight = false;
+static bool g_bDrawLightSource = false;
 static bool g_bScaleCyl = false;
+static bool g_bDrawDark = false;
 
 const float g_fLightAttenuation = 1.2f;
 
+const glm::vec4 g_darkColor(0.2f, 0.2f, 0.2f, 1.0f);
+const glm::vec4 g_lightColor(1.0f);
+
 class MaterialParams
 {
 public:
 		glUniform3fv(whiteProg.cameraSpaceLightPosUnif,1, glm::value_ptr(lightPosCameraSpace));
 		glUniform1f(whiteProg.lightAttenuationUnif, g_fLightAttenuation);
 		glUniform1f(whiteProg.shininessFactorUnif, g_matParams);
+		glUniform4fv(whiteProg.baseDiffuseColorUnif, 1,
+			g_bDrawDark ? glm::value_ptr(g_darkColor) : glm::value_ptr(g_lightColor));
 
 		glUseProgram(colorProg.theProgram);
 		glUniform4f(colorProg.lightIntensityUnif, 0.8f, 0.8f, 0.8f, 1.0f);
 			}
 
 			//Render the light
-			if(g_bDrawLight)
+			if(g_bDrawLightSource)
 			{
 				Framework::MatrixStackPusher push(modelMatrix);
 
 	case 'O': g_matParams.Increment(false); bChangedShininess = true; break;
 	case 'U': g_matParams.Decrement(false); bChangedShininess = true; break;
 
-	case 'y': g_bDrawLight = !g_bDrawLight; break;
+	case 'y': g_bDrawLightSource = !g_bDrawLightSource; break;
 	case 't': g_bScaleCyl = !g_bScaleCyl; break;
 	case 'b': g_bRotateLight = !g_bRotateLight; break;
+	case 'g': g_bDrawDark = !g_bDrawDark; break;
 	case 'h':
 		g_eLightModel += 2;
 		g_eLightModel %= LM_MAX_LIGHTING_MODEL;

Tut 10 Shinies/Phong Lighting.cpp

 	GLuint depthRangeUnif;
 	GLuint lightAttenuationUnif;
 	GLuint shininessFactorUnif;
+	GLuint baseDiffuseColorUnif;
 
 	void SetWindowData(const glm::mat4 cameraToClip, const glm::mat4 clipToCamera, int w, int h)
 	{
 	data.depthRangeUnif = glGetUniformLocation(data.theProgram, "depthRange");
 	data.lightAttenuationUnif = glGetUniformLocation(data.theProgram, "lightAttenuation");
 	data.shininessFactorUnif = glGetUniformLocation(data.theProgram, "shininessFactor");
+	data.baseDiffuseColorUnif = glGetUniformLocation(data.theProgram, "baseDiffuseColor");
 
 	return data;
 }
 
 static bool g_bUseFragmentLighting = true;
 static bool g_bDrawColoredCyl = false;
-static bool g_bDrawLight = false;
+static bool g_bDrawLightSource = false;
 static bool g_bScaleCyl = false;
+static bool g_bDrawDark = false;
 
 const float g_fLightAttenuation = 1.2f;
 static float g_fShininessFactor = 4.0f;
 
+const glm::vec4 g_darkColor(0.2f, 0.2f, 0.2f, 1.0f);
+const glm::vec4 g_lightColor(1.0f);
+
 //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.
 		glUniform3fv(pWhiteProg->cameraSpaceLightPosUnif,1, glm::value_ptr(lightPosCameraSpace));
 		glUniform1f(pWhiteProg->lightAttenuationUnif, g_fLightAttenuation);
 		glUniform1f(pWhiteProg->shininessFactorUnif, g_fShininessFactor);
+		glUniform4fv(pWhiteProg->baseDiffuseColorUnif, 1,
+			g_bDrawDark ? glm::value_ptr(g_darkColor) : glm::value_ptr(g_lightColor));
 
 		glUseProgram(pColorProg->theProgram);
 		glUniform4f(pColorProg->lightIntensityUnif, 0.8f, 0.8f, 0.8f, 1.0f);
 			}
 
 			//Render the light
-			if(g_bDrawLight)
+			if(g_bDrawLightSource)
 			{
 				Framework::MatrixStackPusher push(modelMatrix);
 
 	case 'O': g_fShininessFactor += 0.1f; bChangedShininess = true; break;
 	case 'U': g_fShininessFactor -= 0.1f; bChangedShininess = true; break;
 
-	case 'y': g_bDrawLight = !g_bDrawLight; break;
+	case 'y': g_bDrawLightSource = !g_bDrawLightSource; break;
 	case 't': g_bScaleCyl = !g_bScaleCyl; break;
 	case 'b': g_bRotateLight = !g_bRotateLight; break;
+	case 'g': g_bDrawDark = !g_bDrawDark; break;
 	case 'h':
 		g_eLightModel += 1;
 		g_eLightModel %= LM_MAX_LIGHTING_MODEL;

Tut 10 Shinies/data/PN.vert

 
 uniform mat4 cameraToClipMatrix;
 uniform mat4 modelToCameraMatrix;
+uniform vec4 baseDiffuseColor;
 
 uniform mat3 normalModelToCameraMatrix;
 
 	gl_Position = cameraToClipMatrix * (modelToCameraMatrix * vec4(position, 1.0));
 
 	vertexNormal = normalModelToCameraMatrix * normal;
-	diffuseColor = vec4(1.0);
+	diffuseColor = baseDiffuseColor;
 }