Commits

Jason McKesson committed c2984fe

Tut16: Basic code complete. Need to add details to the texture.
Also, export with SRGB mipmaps.

  • Participants
  • Parent commits 2b9f51d

Comments (0)

Files changed (5)

File Tut 16 Gamma and Textures/Gamma Landscape.cpp

 bool g_drawGammaProgram = false;
 bool g_bDrawCameraPos = false;
 
-bool g_useGammaDisplay = false;
+bool g_useGammaDisplay = true;
 
 //Called to update the display.
 //You should call glutSwapBuffers after all of your rendering to display what you rendered.
 			glUniformMatrix4fv(g_progUnlit.modelToCameraMatrixUnif, 1, GL_FALSE,
 				glm::value_ptr(modelMatrix.Top()));
 
-			glm::vec4 lightColor = g_pLightEnv->GetSunlightIntensity(), gamma;
+			glm::vec4 lightColor = g_pLightEnv->GetSunlightScaledIntensity(), gamma;
+			glUniform4fv(g_progUnlit.objectColorUnif, 1, glm::value_ptr(lightColor));
+			g_pSphere->Render("flat");
+		}
+
+		//Draw lights
+		for(int light = 0; light < g_pLightEnv->GetNumPointLights(); light++)
+		{
+			push.ResetStack();
+
+			modelMatrix.Translate(g_pLightEnv->GetPointLightWorldPos(light));
+
+			glUseProgram(g_progUnlit.theProgram);
+			glUniformMatrix4fv(g_progUnlit.modelToCameraMatrixUnif, 1, GL_FALSE,
+				glm::value_ptr(modelMatrix.Top()));
+
+			glm::vec4 lightColor = g_pLightEnv->GetPointLightScaledIntensity(light);
 			glUniform4fv(g_progUnlit.objectColorUnif, 1, glm::value_ptr(lightColor));
 			g_pSphere->Render("flat");
 		}
 			glUniform4f(g_progUnlit.objectColorUnif, 1.0f, 1.0f, 1.0f, 1.0f);
 			g_pSphere->Render("flat");
 		}
+
 	}
 
 	glutPostRedisplay();

File Tut 16 Gamma and Textures/LightEnv.cpp

 #include "../framework/framework.h"
 #include <glm/gtc/matrix_transform.hpp>
 
-const float g_fHalfLightDistance = 20.0f;
-const float g_fLightAttenuation = 1.0f / (g_fHalfLightDistance * g_fHalfLightDistance);
 
 typedef std::pair<float, float> MaxIntensityData;
 typedef std::vector<MaxIntensityData> MaxIntensityVector;
 }
 
 LightEnv::LightEnv( const std::string& envFilename )
+	: m_fLightAttenuation(40.0f)
 {
 	std::ifstream fileStream(envFilename.c_str());
 	if(!fileStream.is_open())
 
 	TiXmlHandle docHandle(&theDoc);
 
+	const TiXmlElement *pRootNode = docHandle.FirstChild("lightenv").ToElement();
+
+	if(!pRootNode)
+		throw std::runtime_error("The root node must be a 'lightenv' element.");
+
+	pRootNode->QueryFloatAttribute("atten", &m_fLightAttenuation);
+	m_fLightAttenuation = 1.0f / (m_fLightAttenuation * m_fLightAttenuation);
+
 	const TiXmlElement *pSunNode = docHandle.FirstChild("lightenv").FirstChild("sun").ToElement();
 
 	if(!pSunNode)
 			throw std::runtime_error("Too many lights specified.");
 
 		float lightTime = 0;
-		if(pSunNode->QueryFloatAttribute("time", &lightTime) != TIXML_SUCCESS)
+		if(pLightNode->QueryFloatAttribute("time", &lightTime) != TIXML_SUCCESS)
 			throw std::runtime_error("'light' elements must have a 'time' attribute that is a float.");
 
 		m_lightTimers.push_back(Framework::Timer(Framework::Timer::TT_LOOP, lightTime));
 	return sunDirection;
 }
 
+glm::vec4 LightEnv::GetSunlightScaledIntensity() const
+{
+	return m_sunlightInterpolator.Interpolate(m_sunTimer.GetAlpha()) /
+		m_maxIntensityInterpolator.Interpolate(m_sunTimer.GetAlpha());
+}
+
 int LightEnv::GetNumLights() const
 {
 	return 1 + m_lightPos.size();
 }
 
+int LightEnv::GetNumPointLights() const
+{
+	return m_lightPos.size();
+}
+
+glm::vec4 LightEnv::GetPointLightIntensity( int pointLightIx ) const
+{
+	return m_lightIntensity.at(pointLightIx);
+}
+
+glm::vec4 LightEnv::GetPointLightScaledIntensity( int pointLightIx ) const
+{
+	return m_lightIntensity.at(pointLightIx) /
+		m_maxIntensityInterpolator.Interpolate(m_sunTimer.GetAlpha());
+}
+
+glm::vec3 LightEnv::GetPointLightWorldPos( int pointLightIx ) const
+{
+	return m_lightPos.at(pointLightIx).Interpolate(m_lightTimers.at(pointLightIx).GetAlpha());
+}
+
 LightBlock LightEnv::GetLightBlock( const glm::mat4 &worldToCamera ) const
 {
 	LightBlock lightData;
 	lightData.ambientIntensity = m_ambientInterpolator.Interpolate(m_sunTimer.GetAlpha());
-	lightData.lightAttenuation = g_fLightAttenuation;
+	lightData.lightAttenuation = m_fLightAttenuation;
 	lightData.maxIntensity = m_maxIntensityInterpolator.Interpolate(m_sunTimer.GetAlpha());
 
 	lightData.lights[0].cameraSpaceLightPos =
 
 	for(size_t light = 0; light < m_lightPos.size(); light++)
 	{
-		glm::vec4 worldLightPos =
-			glm::vec4(m_lightPos[light].Interpolate(m_lightTimers[light].GetAlpha()), 1.0f);
+		glm::vec4 worldLightPos = glm::vec4(GetPointLightWorldPos(light), 1.0f);
 		glm::vec4 lightPosCameraSpace = worldToCamera * worldLightPos;
 
 		lightData.lights[light + 1].cameraSpaceLightPos = lightPosCameraSpace;
 	m_sunTimer.Fastforward(secFF);
 	std::for_each(m_lightTimers.begin(), m_lightTimers.end(), FFTimer(secFF));
 }
+

File Tut 16 Gamma and Textures/LightEnv.h

 		return m_sunlightInterpolator.Interpolate(m_sunTimer.GetAlpha());
 	}
 
+	glm::vec4 GetSunlightScaledIntensity() const;
+
 	float GetElapsedTime() const
 	{
 		return m_sunTimer.GetProgression();
 
 	LightBlock GetLightBlock(const glm::mat4 &worldToCamera) const;
 
+	int GetNumPointLights() const;
+	glm::vec4 GetPointLightIntensity(int pointLightIx) const;
+	glm::vec4 GetPointLightScaledIntensity(int pointLightIx) const;
+	glm::vec3 GetPointLightWorldPos(int pointLightIx) const;
+
 private:
 	typedef Framework::ConstVelLinearInterpolator<glm::vec3> LightInterpolator;
 	typedef std::map<std::string, Framework::Timer> ExtraTimerMap;
 
+	float m_fLightAttenuation;
+
 	Framework::Timer m_sunTimer;
 	Framework::TimedLinearInterpolator<glm::vec4> m_ambientInterpolator;
 	Framework::TimedLinearInterpolator<glm::vec4> m_backgroundInterpolator;

File Tut 16 Gamma and Textures/LightEnv.xml

 <?xml version="1.0" encoding="UTF-8"?>
-<lightenv>
-    <sun time="15">
-        <key time="0" ambient="0.4 0.4 0.4 1.0" intensity="0 0 0 1.0" background="0.65 0.65
-            1.0 1.0" max-intensity="10" />
-        <key time="12" ambient="0.4 0.4 0.4 1.0" intensity="0 0 0 1.0" background="0.0 0.0
-            0.0 1.0" max-intensity="10" />
+<lightenv atten="50">
+    <sun time="48">
+        <key time="0" ambient="1 1 1 1.0" intensity="12 12 12 1.0"
+			background="0.65 0.65 1.0 1.0" max-intensity="15" />
+        <key time="4" ambient="1 1 1 1.0" intensity="12 12 12 1.0"
+			background="0.65 0.65 1.0 1.0" max-intensity="15" />
+        <key time="5" ambient="0.8 0.8 0.8 1.0" intensity="8 8 8 1.0"
+			background="0.65 0.65 1.0 1.0" max-intensity="12" />
+        <key time="6" ambient="0.8 0.4 0.4 1.0" intensity="8 4 4 1.0"
+			background="0.65 0.3 0.3 1.0" max-intensity="10" />
+        <key time="6.5" ambient="0.4 0.2 0.2 1.0" intensity="3 1 1 1.0"
+			background="0.3 0.1 0.1 1.0" max-intensity="8" />
+        <key time="7.5" ambient="0.01 0.01 0.01 1.0" intensity="0 0 0 1.0"
+			background="0 0 0 1.0" max-intensity="6" />
+        <key time="16.5" ambient="0.01 0.01 0.01 1.0" intensity="0 0 0 1.0"
+			background="0 0 0 1.0" max-intensity="6" />
+        <key time="17.5" ambient="0.4 0.2 0.2 1.0" intensity="3 1 1 1.0"
+			background="0.3 0.1 0.1 1.0" max-intensity="8" />
+        <key time="18" ambient="0.8 0.4 0.4 1.0" intensity="8 4 4 1.0"
+			background="0.65 0.3 0.3 1.0" max-intensity="10" />
+        <key time="19" ambient="0.8 0.8 0.8 1.0" intensity="8 8 8 1.0"
+			background="0.65 0.65 1.0 1.0" max-intensity="12" />
+        <key time="20" ambient="1 1 1 1.0" intensity="12 12 12 1.0"
+			background="0.65 0.65 1.0 1.0" max-intensity="15" />
     </sun>
-    <light time="30" intensity="16 16 16 1.0">
-        <key>0.0 40 0.0</key>
+    <light time="10" intensity="2 2 2 1.0">
+        <key>-100.0 25 0.0</key>
+        <key>100.0 25 0.0</key>
     </light>
 </lightenv>

File Tut 16 Gamma and Textures/data/terrain_tex.dds

Binary file added.