Jason McKesson avatar Jason McKesson committed 7ddfca4

Tut17: Projective texturing finished.

Comments (0)

Files changed (9)

Tut 17 Spotlight on Textures/Projected Light.cpp

 
 GLuint g_projectionUniformBuffer = 0;
 GLuint g_lightUniformBuffer = 0;
-GLuint g_lightProjTex;
 
-const int NUM_SAMPLERS = 1;
+const int NUM_SAMPLERS = 2;
 GLuint g_samplers[NUM_SAMPLERS];
 
 void CreateSamplers()
 
 	for(int samplerIx = 0; samplerIx < NUM_SAMPLERS; samplerIx++)
 	{
-		glSamplerParameteri(g_samplers[samplerIx], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
-		glSamplerParameteri(g_samplers[samplerIx], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
+		glSamplerParameteri(g_samplers[samplerIx], GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+		glSamplerParameteri(g_samplers[samplerIx], GL_TEXTURE_MIN_FILTER, GL_LINEAR);
 	}
 
-	glSamplerParameteri(g_samplers[0], GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-	glSamplerParameteri(g_samplers[0], GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+	glSamplerParameteri(g_samplers[0], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+	glSamplerParameteri(g_samplers[0], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+
+	glSamplerParameteri(g_samplers[1], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
+	glSamplerParameteri(g_samplers[1], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
 
 	float color[4] = {0.0f, 0.0f, 0.0f, 1.0f};
-	glSamplerParameterfv(g_samplers[0], GL_TEXTURE_BORDER_COLOR, color);
+	glSamplerParameterfv(g_samplers[1], GL_TEXTURE_BORDER_COLOR, color);
 }
 
+struct TexDef { const char *filename; const char *name; };
+
+TexDef g_texDefs[] =
+{
+	{"Flashlight.dds", "Flashlight"},
+	{"PointsOfLight.dds", "Multiple Point Lights"},
+	{"Bands.dds", "Light Bands"},
+};
+
+GLuint g_lightTextures[ARRAY_COUNT(g_texDefs)];
+const int NUM_LIGHT_TEXTURES = ARRAY_COUNT(g_texDefs);
+int g_currTextureIndex = 0;
+
 void LoadTextures()
 {
 	try
 	{
-		std::string filename(Framework::FindFileOrThrow("testLightImg.dds"));
+		for(int tex = 0; tex < NUM_LIGHT_TEXTURES; ++tex)
+		{
+			std::string filename(Framework::FindFileOrThrow(g_texDefs[tex].filename));
 
-		std::auto_ptr<glimg::ImageSet> pImageSet(glimg::loaders::dds::LoadFromFile(filename.c_str()));
-		g_lightProjTex = glimg::CreateTexture(pImageSet.get(), 0);
+			std::auto_ptr<glimg::ImageSet> pImageSet(glimg::loaders::dds::LoadFromFile(filename.c_str()));
+			g_lightTextures[tex] = glimg::CreateTexture(pImageSet.get(), 0);
+		}
 	}
 	catch(std::exception &e)
 	{
 GLuint g_colroedProg;
 Framework::Mesh *g_pAxesMesh = NULL;
 
+
 void LoadAndSetupScene()
 {
 	std::auto_ptr<Framework::Scene> pScene(new Framework::Scene("proj2d_scene.xml"));
 
 int g_currSampler = 0;
 
+const float g_lightFOVs[] = { 10.0f, 20.0f, 45.0f, 75.0f, 90.0f, 120.0f, 150.0f, 170.0f };
+int g_currFOVIndex = 3;
+
 bool g_bDrawCameraPos = false;
-bool g_bDepthClampProj = true;
+bool g_bShowOtherLights = true;
 
 int g_displayWidth = 500;
 int g_displayHeight = 500;
 {
 	LightBlock lightData;
 	lightData.ambientIntensity = glm::vec4(0.2f, 0.2f, 0.2f, 1.0f);
-	lightData.lightAttenuation = 1.0f / (20.0f * 20.0f);
-	lightData.maxIntensity = 3.0f;
-	lightData.lights[0].lightIntensity = glm::vec4(2.0f, 2.0f, 2.5f, 1.0f);
+	lightData.lightAttenuation = 1.0f / (30.0f * 30.0f);
+	lightData.maxIntensity = 2.0f;
+	lightData.lights[0].lightIntensity = glm::vec4(0.2f, 0.2f, 0.2f, 1.0f);
 	lightData.lights[0].cameraSpaceLightPos = camMatrix *
 		glm::normalize(glm::vec4(-0.2f, 0.5f, 0.5f, 0.0f));
-	lightData.lights[1].lightIntensity = glm::vec4(3.5f, 6.5f, 3.0f, 1.0f) * 1.5f;
+	lightData.lights[1].lightIntensity = glm::vec4(3.5f, 6.5f, 3.0f, 1.0f) * 0.5f;
 	lightData.lights[1].cameraSpaceLightPos = camMatrix *
 		glm::vec4(5.0f, 6.0f, 0.5f, 1.0f);
 
-	g_lightNumBinder.SetValue(2);
+	if(g_bShowOtherLights)
+		g_lightNumBinder.SetValue(2);
+	else
+		g_lightNumBinder.SetValue(0);
 
 	glBindBuffer(GL_UNIFORM_BUFFER, g_lightUniformBuffer);
 	glBufferData(GL_UNIFORM_BUFFER, sizeof(LightBlock), &lightData, GL_STREAM_DRAW);
 	}
 
 	glActiveTexture(GL_TEXTURE0 + g_lightProjTexUnit);
-	glBindTexture(GL_TEXTURE_2D, g_lightProjTex);
-	glBindSampler(g_lightProjTexUnit, g_samplers[0]);
+	glBindTexture(GL_TEXTURE_2D, g_lightTextures[g_currTextureIndex]);
+	glBindSampler(g_lightProjTexUnit, g_samplers[g_currSampler]);
 
 	{
 		glutil::MatrixStack lightProjStack;
 		lightProjStack.Translate(0.5f, 0.5f, 0.0f);
 		lightProjStack.Scale(0.5f);
 		//Project. Z-range is irrelevant.
-		lightProjStack.Perspective(45.0f, 1.0f, 1.0f, 100.0f);
+		lightProjStack.Perspective(g_lightFOVs[g_currFOVIndex], 1.0f, 1.0f, 100.0f);
 		//Transform from main camera space to light camera space.
 		lightProjStack.ApplyMatrix(lightView);
 		lightProjStack.ApplyMatrix(glm::inverse(cameraMatrix));
 	case 't':
 		g_bDrawCameraPos = !g_bDrawCameraPos;
 		break;
-	case 'y':
-		g_bDepthClampProj = !g_bDepthClampProj;
+	case 'g':
+		g_bShowOtherLights = !g_bShowOtherLights;
+		break;
+	case 'h':
+		g_currSampler = (g_currSampler + 1) % NUM_SAMPLERS;
 		break;
 	case 'p':
 		g_timer.TogglePause();
 			}
 		}
 		break;
+	case 'y':
+		g_currFOVIndex = std::min(g_currFOVIndex + 1, int(ARRAY_COUNT(g_lightFOVs) - 1));
+		printf("Curr FOV: %f\n", g_lightFOVs[g_currFOVIndex]);
+		break;
+	case 'n':
+		g_currFOVIndex = std::max(g_currFOVIndex - 1, 0);
+		printf("Curr FOV: %f\n", g_lightFOVs[g_currFOVIndex]);
+		break;
+
+	}
+
+	{
+		int possibleIndex = (int)key - (int)'1';
+		if((0 <= possibleIndex) && (possibleIndex < NUM_LIGHT_TEXTURES))
+		{
+			g_currTextureIndex = key - '1';
+			printf("%s\n", g_texDefs[g_currTextureIndex].name);
+		}
 	}
 
 	g_viewPole.CharPress(key);
Add a comment to this file

Tut 17 Spotlight on Textures/data/Bands.dds

Binary file added.

Add a comment to this file

Tut 17 Spotlight on Textures/data/Bands.pdn

Binary file added.

Add a comment to this file

Tut 17 Spotlight on Textures/data/Flashlight.dds

Binary file added.

Add a comment to this file

Tut 17 Spotlight on Textures/data/Flashlight.pdn

Binary file added.

Add a comment to this file

Tut 17 Spotlight on Textures/data/PointsOfLight.dds

Binary file added.

Add a comment to this file

Tut 17 Spotlight on Textures/data/PointsOfLight.pdn

Binary file added.

Tut 17 Spotlight on Textures/data/projLight.frag

 	PerLight currLight;
 	currLight.cameraSpaceLightPos = vec4(cameraSpaceProjLightPos, 1.0);
 	currLight.lightIntensity =
-		textureProj(lightProjTex, lightProjPosition.xyw) * 2.0;
+		textureProj(lightProjTex, lightProjPosition.xyw) * 4.0f;
 		
 	currLight.lightIntensity = lightProjPosition.z > 0 ?
 		currLight.lightIntensity : vec4(0.0);
 		accumLighting += ComputeLighting(diffuseColor, Lgt.lights[light]);
 	}
 
-	
+//	accumLighting = vec4(0.0f);
 	accumLighting += ComputeLighting(diffuseColor, currLight);
 
 	outputColor = accumLighting / Lgt.maxIntensity;

data/Colored.frag

 #version 330
 
-in vec4 objectColor;
+smooth in vec4 objectColor;
 
 out vec4 outputColor;
 
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.