Jason McKesson avatar Jason McKesson committed 334c5a4

Tut17: Double Projection finished.

Comments (0)

Files changed (10)

 * Documents/Positioning/Coord_system_SZ_0.svg
 * Documents/Illumination/GammaCorrectFunc.svg
 * Documents/Texturing/Torus.png
+* data/wood4_rotate.dds : created by Luke.RUSTLTD, of OpenGameArt.org
 
 The following files are copywritten and distributed under the Creative Commons Attribution 3.0 Unported (CC BY 3.0) license, as described in the "./CC BY 3.0 legalcode.txt" file. Attribution for these works is presented here:
 
 Attributed to Etory, of OpenGameArt.org:
 * data/seamless_rock1_small.dds
 
+Attributed to p0ss, of OpenGameArt.org:
+* data/concrete649_small.dds
+* data/dsc_1621_small.dds
+* data/rough645_small.dds
+

Tut 17 Spotlight on Textures/Double Projection.cpp

 	nodes.push_back(pScene->FindNode("rightBar"));
 	nodes.push_back(pScene->FindNode("leaningBar"));
 	nodes.push_back(pScene->FindNode("spinBar"));
+//	nodes.push_back(pScene->FindNode("diorama"));
+//	nodes.push_back(pScene->FindNode("floor"));
 
 	AssociateUniformWithNodes(nodes, g_lightNumBinder, "numberOfLights");
 	SetStateBinderWithNodes(nodes, g_lightNumBinder);
 		0, sizeof(ProjectionBlock));
 
 	CreateSamplers();
-	LoadTextures();
+//	LoadTextures();
 
 	try
 	{
 int g_currSampler = 0;
 
 bool g_bDrawCameraPos = false;
+bool g_bDepthClampProj = true;
 
 int g_displayWidth = 700;
 int g_displayHeight = 350;
 	LightBlock lightData;
 	lightData.ambientIntensity = glm::vec4(0.2f, 0.2f, 0.2f, 1.0f);
 	lightData.lightAttenuation = 1.0f / (5.0f * 5.0f);
-	lightData.maxIntensity = 3.0f;
+	lightData.maxIntensity = 4.0f;
 	lightData.lights[0].lightIntensity = glm::vec4(2.0f, 2.0f, 2.5f, 1.0f);
 	lightData.lights[0].cameraSpaceLightPos = camMatrix *
 		glm::normalize(glm::vec4(-0.2f, 0.5f, 0.5f, 0.0f));
 		glutil::PushStack stackPush(modelMatrix);
 		//Draw lookat point.
 		modelMatrix.SetIdentity();
+		modelMatrix.Scale(0.5f);
 		modelMatrix.Translate(glm::vec3(0.0f, 0.0f, -g_viewPole.GetView().radius));
 
 		glDisable(GL_DEPTH_TEST);
 		glBindBuffer(GL_UNIFORM_BUFFER, 0);
 	}
 
+	if(!g_bDepthClampProj)
+		glDisable(GL_DEPTH_CLAMP);
 	glViewport(displaySize.x + (g_displayWidth % 2), 0,
 		(GLsizei)displaySize.x, (GLsizei)displaySize.y);
 	g_pScene->Render(modelMatrix.Top());
+	glEnable(GL_DEPTH_CLAMP);
 
     glutPostRedisplay();
 	glutSwapBuffers();
 	case 32:
 		g_persViewPole.Reset();
 		break;
+	case 't':
+		g_bDrawCameraPos = !g_bDrawCameraPos;
+		break;
 	case 'y':
-		g_bDrawCameraPos = !g_bDrawCameraPos;
+		g_bDepthClampProj = !g_bDepthClampProj;
 		break;
 	case 'p':
 		g_timer.TogglePause();

Tut 17 Spotlight on Textures/data/GenDiorama.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 =
+{
+    --Frontside
+	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),
+	
+	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),
+
+	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),
+	
+	--Backside
+	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),
+	
+	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),
+
+	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 =
+{
+	--Frontside
+	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),
+	
+	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),
+	
+	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),
+	
+	--Backside
+	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),
+	
+	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),
+	
+	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 texCoords =
+{
+	--Frontside
+	vmath.vec2(0.0, 0.0),
+	vmath.vec2(0.0, 1.0),
+	vmath.vec2(1.0, 1.0),
+	vmath.vec2(1.0, 0.0),
+
+	vmath.vec2(0.0, 0.0),
+	vmath.vec2(0.0, 1.0),
+	vmath.vec2(1.0, 1.0),
+	vmath.vec2(1.0, 0.0),
+
+	vmath.vec2(0.0, 0.0),
+	vmath.vec2(0.0, 1.0),
+	vmath.vec2(1.0, 1.0),
+	vmath.vec2(1.0, 0.0),
+
+	--Backside
+	vmath.vec2(0.0, 0.0),
+	vmath.vec2(0.0, 1.0),
+	vmath.vec2(1.0, 1.0),
+	vmath.vec2(1.0, 0.0),
+
+	vmath.vec2(0.0, 0.0),
+	vmath.vec2(0.0, 1.0),
+	vmath.vec2(1.0, 1.0),
+	vmath.vec2(1.0, 0.0),
+
+	vmath.vec2(0.0, 0.0),
+	vmath.vec2(0.0, 1.0),
+	vmath.vec2(1.0, 1.0),
+	vmath.vec2(1.0, 0.0),
+}
+
+local indices =
+{
+	--Frontside
+	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),
+	
+	--Backside
+	vmath.vec3(12, 15, 14),
+	vmath.vec3(14, 13, 12),
+	
+	vmath.vec3(16, 19, 18),
+	vmath.vec3(18, 17, 16),
+	
+	vmath.vec3(20, 23, 22),
+	vmath.vec3(22, 21, 20),
+};
+
+local function WriteVAO(writer, name, ...)
+	local attribs = {...}
+	
+	writer:PushElement("vao");
+		writer:AddAttribute("name", name);
+		for i, attrib in ipairs(attribs) do
+			writer:PushElement("source");
+			writer:AddAttribute("attrib", tostring(attrib));
+			writer:PopElement();
+		end
+	writer:PopElement();
+end
+
+do
+	local writer = XmlWriter.XmlWriter("UnitDiorama.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", "2");
+			writer:AddAttribute("type", "float");
+			writer:AddAttribute("size", "3");
+			writer:AddText(GenStringFromArray(normals));
+		writer:PopElement();
+		writer:PushElement("attribute");
+			writer:AddAttribute("index", "5");
+			writer:AddAttribute("type", "float");
+			writer:AddAttribute("size", "2");
+			writer:AddText(GenStringFromArray(texCoords));
+		writer:PopElement();
+		WriteVAO(writer, "lit", 0, 2);
+		WriteVAO(writer, "lit-tex", 0, 2, 5);
+		WriteVAO(writer, "tex", 0, 5);
+		WriteVAO(writer, "flat", 0);
+		writer:PushElement("indices");
+			writer:AddAttribute("cmd", "triangles");
+			writer:AddAttribute("type", "ushort");
+			writer:AddText(GenStringFromArray(indices, true));
+		writer:PopElement();
+	writer:PopElement();
+	writer:Close();
+end

Tut 17 Spotlight on Textures/data/UnitDiorama.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="2" type="float" size="3" > 
+        1 0 0
+        1 0 0
+        1 0 0
+        1 0 0
+        0 0 1
+        0 0 1
+        0 0 1
+        0 0 1
+        -1 0 0
+        -1 0 0
+        -1 0 0
+        -1 0 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
+        1 0 0
+        1 0 0
+        1 0 0
+        1 0 0</attribute>
+	<attribute index="5" type="float" size="2" > 
+        0 0
+        0 1
+        1 1
+        1 0
+        0 0
+        0 1
+        1 1
+        1 0
+        0 0
+        0 1
+        1 1
+        1 0
+        0 0
+        0 1
+        1 1
+        1 0
+        0 0
+        0 1
+        1 1
+        1 0
+        0 0
+        0 1
+        1 1
+        1 0</attribute>
+	<vao name="lit" >
+		<source attrib="0" />
+		<source attrib="2" />
+	</vao>
+	<vao name="lit-tex" >
+		<source attrib="0" />
+		<source attrib="2" />
+		<source attrib="5" />
+	</vao>
+	<vao name="tex" >
+		<source attrib="0" />
+		<source attrib="5" />
+	</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 15 14
+        14 13 12
+        16 19 18
+        18 17 16
+        20 23 22
+        22 21 20</indices>
+</mesh>

Tut 17 Spotlight on Textures/data/dp_scene.xml

     <mesh xml:id="m_cube" file="UnitCube.xml"/>
 	<mesh xml:id="m_shortBar" file="ShortBar.xml"/>
 	<mesh xml:id="m_longBar" file="LongBar.xml"/>
+	<mesh xml:id="m_diorama" file="UnitDiorama.xml"/>
+	<mesh xml:id="m_floor" file="UnitPlane.xml"/>
     <texture xml:id="t_stone" file="seamless_rock1_small.dds"/>
+    <texture xml:id="t_concrete_wall" file="concrete649_small.dds"/>
+    <texture xml:id="t_sandy_ground" file="dsc_1621_small.dds"/>
+    <texture xml:id="t_stone_pillar" file="rough645_small.dds"/>
+    <texture xml:id="t_wood_pillar" file="wood4_rotate.dds"/>
     <prog
         xml:id="p_unlit"
         vert="Unlit.vert"
         pos="3 -7 -10"
         orient="0.64278 0 0 0.76604"
         scale="5">
-        <texture name="t_stone" unit="0" sampler="anisotropic"/>
+        <texture name="t_wood_pillar" unit="0" sampler="anisotropic"/>
     </node>
     <node
         name="spinBar"
         pos="-7 0 8"
         orient="-0.148446 0.554035 0.212003 0.791242"
         scale="4">
-        <texture name="t_stone" unit="0" sampler="anisotropic"/>
+        <texture name="t_stone_pillar" unit="0" sampler="anisotropic"/>
     </node>
+<!--
+	<node
+		name="diorama"
+        mesh="m_diorama"
+        prog="p_lit"
+        pos="0 -10 0"
+        scale="47">
+        <texture name="t_concrete_wall" unit="0" sampler="anisotropic"/>
+	</node>
+	<node
+		name="floor"
+        mesh="m_floor"
+        prog="p_lit"
+        pos="0 -33.5 0"
+        scale="47">
+        <texture name="t_sandy_ground" unit="0" sampler="anisotropic"/>
+	</node>
+-->
 </scene>
Add a comment to this file

data/concrete649_small.dds

Binary file added.

Add a comment to this file

data/dsc_1621_small.dds

Binary file added.

Add a comment to this file

data/rough645_small.dds

Binary file added.

Binary file added.

framework/Scene.cpp

 	public:
 		SceneTexture(const std::string &filename)
 		{
-			std::string pathname(Framework::FindFileOrThrow("seamless_rock1_small.dds"));
+			std::string pathname(Framework::FindFileOrThrow(filename));
 
 			std::auto_ptr<glimg::ImageSet> pImageSet;
 			std::string ext = GetExtension(pathname);
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.