Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial shadow volume code.

git-svn-id: http://ogldev.googlecode.com/svn/trunk@108 3d42d2e4-7448-fe72-c4ee-b187089d8254
  • Loading branch information...
commit 24115538e7dff6584e623d16f2e158ec7c14a011 1 parent b12931f
etay.meiri authored
Showing with 1,083 additions and 1,108 deletions.
  1. +3 −2 tutorial39/glut_backend.cpp
  2. +237 −0 tutorial39/lighting_technique.cpp
  3. +148 −0 tutorial39/lighting_technique.h
  4. +32 −66 tutorial39/log
  5. +73 −2 tutorial39/mesh.cpp
  6. +13 −0 tutorial39/models/box.mtl
  7. +46 −0 tutorial39/models/box.obj
  8. +0 −2  tutorial39/models/f.mtl
  9. +0 −122 tutorial39/models/f.obj
  10. +0 −2  tutorial39/models/g.mtl
  11. +0 −186 tutorial39/models/g.obj
  12. +0 −2  tutorial39/models/l.mtl
  13. +0 −98 tutorial39/models/l.obj
  14. +2 −0  tutorial39/models/quad.mtl
  15. +15 −0 tutorial39/models/quad.obj
  16. BIN  tutorial39/models/test.png
  17. +0 −2  tutorial39/models/x.mtl
  18. +0 −145 tutorial39/models/x.obj
  19. +12 −0 tutorial39/nbproject/Makefile-Debug.mk
  20. +12 −0 tutorial39/nbproject/Makefile-Release.mk
  21. +6 −0 tutorial39/nbproject/configurations.xml
  22. +51 −0 tutorial39/null_technique.cpp
  23. +39 −0 tutorial39/null_technique.h
  24. +166 −0 tutorial39/shaders/lighting.glsl
  25. +16 −0 tutorial39/shaders/null_technique.glsl
  26. +63 −161 tutorial39/shaders/shadow_volume.glsl
  27. +6 −171 tutorial39/shadow_volume_technique.cpp
  28. +5 −108 tutorial39/shadow_volume_technique.h
  29. +138 −39 tutorial39/tutorial39.cpp
5 tutorial39/glut_backend.cpp
View
@@ -115,8 +115,9 @@ void GLUTBackendRun(ICallbacks* pCallbacks)
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glFrontFace(GL_CW);
glCullFace(GL_BACK);
- glEnable(GL_CULL_FACE);
- glEnable(GL_DEPTH_TEST);
+
+ // glDisable(GL_CULL_FACE);
+ glEnable(GL_CULL_FACE);
s_pCallbacks = pCallbacks;
InitCallbacks();
237 tutorial39/lighting_technique.cpp
View
@@ -0,0 +1,237 @@
+/*
+
+ Copyright 2011 Etay Meiri
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <limits.h>
+#include <string>
+#include <glfx.h>
+
+#include "lighting_technique.h"
+#include "util.h"
+
+using namespace std;
+
+static const char* pEffectFile = "shaders/lighting.glsl";
+
+LightingTechnique::LightingTechnique() : Technique(pEffectFile)
+{
+}
+
+
+bool LightingTechnique::Init()
+{
+ if (!CompileProgram("Lighting")) {
+ return false;
+ }
+
+ m_WVPLocation = GetUniformLocation("gWVP");
+ m_WorldMatrixLocation = GetUniformLocation("gWorld");
+ m_colorTextureLocation = GetUniformLocation("gColorMap");
+ m_eyeWorldPosLocation = GetUniformLocation("gEyeWorldPos");
+ m_dirLightLocation.Color = GetUniformLocation("gDirectionalLight.Base.Color");
+ m_dirLightLocation.AmbientIntensity = GetUniformLocation("gDirectionalLight.Base.AmbientIntensity");
+ m_dirLightLocation.Direction = GetUniformLocation("gDirectionalLight.Direction");
+ m_dirLightLocation.DiffuseIntensity = GetUniformLocation("gDirectionalLight.Base.DiffuseIntensity");
+ m_matSpecularIntensityLocation = GetUniformLocation("gMatSpecularIntensity");
+ m_matSpecularPowerLocation = GetUniformLocation("gSpecularPower");
+ m_numPointLightsLocation = GetUniformLocation("gNumPointLights");
+ m_numSpotLightsLocation = GetUniformLocation("gNumSpotLights");
+ m_colorLocation = GetUniformLocation("gColor");
+
+ if (m_dirLightLocation.AmbientIntensity == INVALID_UNIFORM_LOCATION ||
+ m_WVPLocation == INVALID_UNIFORM_LOCATION ||
+ m_WorldMatrixLocation == INVALID_UNIFORM_LOCATION ||
+ m_colorTextureLocation == INVALID_UNIFORM_LOCATION ||
+ m_eyeWorldPosLocation == INVALID_UNIFORM_LOCATION ||
+ m_dirLightLocation.Color == INVALID_UNIFORM_LOCATION ||
+ m_dirLightLocation.DiffuseIntensity == INVALID_UNIFORM_LOCATION ||
+ m_dirLightLocation.Direction == INVALID_UNIFORM_LOCATION ||
+ m_matSpecularIntensityLocation == INVALID_UNIFORM_LOCATION ||
+ m_matSpecularPowerLocation == INVALID_UNIFORM_LOCATION ||
+ m_numPointLightsLocation == INVALID_UNIFORM_LOCATION ||
+ m_numSpotLightsLocation == INVALID_UNIFORM_LOCATION ||
+ m_colorLocation == INVALID_UNIFORM_LOCATION) {
+ return false;
+ }
+
+ for (unsigned int i = 0 ; i < ARRAY_SIZE_IN_ELEMENTS(m_pointLightsLocation) ; i++) {
+ char Name[128];
+ memset(Name, 0, sizeof(Name));
+ snprintf(Name, sizeof(Name), "gPointLights[%d].Base.Color", i);
+ m_pointLightsLocation[i].Color = GetUniformLocation(Name);
+
+ snprintf(Name, sizeof(Name), "gPointLights[%d].Base.AmbientIntensity", i);
+ m_pointLightsLocation[i].AmbientIntensity = GetUniformLocation(Name);
+
+ snprintf(Name, sizeof(Name), "gPointLights[%d].Position", i);
+ m_pointLightsLocation[i].Position = GetUniformLocation(Name);
+
+ snprintf(Name, sizeof(Name), "gPointLights[%d].Base.DiffuseIntensity", i);
+ m_pointLightsLocation[i].DiffuseIntensity = GetUniformLocation(Name);
+
+ snprintf(Name, sizeof(Name), "gPointLights[%d].Atten.Constant", i);
+ m_pointLightsLocation[i].Atten.Constant = GetUniformLocation(Name);
+
+ snprintf(Name, sizeof(Name), "gPointLights[%d].Atten.Linear", i);
+ m_pointLightsLocation[i].Atten.Linear = GetUniformLocation(Name);
+
+ snprintf(Name, sizeof(Name), "gPointLights[%d].Atten.Exp", i);
+ m_pointLightsLocation[i].Atten.Exp = GetUniformLocation(Name);
+
+ if (m_pointLightsLocation[i].Color == INVALID_UNIFORM_LOCATION ||
+ m_pointLightsLocation[i].AmbientIntensity == INVALID_UNIFORM_LOCATION ||
+ m_pointLightsLocation[i].Position == INVALID_UNIFORM_LOCATION ||
+ m_pointLightsLocation[i].DiffuseIntensity == INVALID_UNIFORM_LOCATION ||
+ m_pointLightsLocation[i].Atten.Constant == INVALID_UNIFORM_LOCATION ||
+ m_pointLightsLocation[i].Atten.Linear == INVALID_UNIFORM_LOCATION ||
+ m_pointLightsLocation[i].Atten.Exp == INVALID_UNIFORM_LOCATION) {
+ return false;
+ }
+ }
+
+ for (unsigned int i = 0 ; i < ARRAY_SIZE_IN_ELEMENTS(m_spotLightsLocation) ; i++) {
+ char Name[128];
+ memset(Name, 0, sizeof(Name));
+ snprintf(Name, sizeof(Name), "gSpotLights[%d].Base.Base.Color", i);
+ m_spotLightsLocation[i].Color = GetUniformLocation(Name);
+
+ snprintf(Name, sizeof(Name), "gSpotLights[%d].Base.Base.AmbientIntensity", i);
+ m_spotLightsLocation[i].AmbientIntensity = GetUniformLocation(Name);
+
+ snprintf(Name, sizeof(Name), "gSpotLights[%d].Base.Position", i);
+ m_spotLightsLocation[i].Position = GetUniformLocation(Name);
+
+ snprintf(Name, sizeof(Name), "gSpotLights[%d].Direction", i);
+ m_spotLightsLocation[i].Direction = GetUniformLocation(Name);
+
+ snprintf(Name, sizeof(Name), "gSpotLights[%d].Cutoff", i);
+ m_spotLightsLocation[i].Cutoff = GetUniformLocation(Name);
+
+ snprintf(Name, sizeof(Name), "gSpotLights[%d].Base.Base.DiffuseIntensity", i);
+ m_spotLightsLocation[i].DiffuseIntensity = GetUniformLocation(Name);
+
+ snprintf(Name, sizeof(Name), "gSpotLights[%d].Base.Atten.Constant", i);
+ m_spotLightsLocation[i].Atten.Constant = GetUniformLocation(Name);
+
+ snprintf(Name, sizeof(Name), "gSpotLights[%d].Base.Atten.Linear", i);
+ m_spotLightsLocation[i].Atten.Linear = GetUniformLocation(Name);
+
+ snprintf(Name, sizeof(Name), "gSpotLights[%d].Base.Atten.Exp", i);
+ m_spotLightsLocation[i].Atten.Exp = GetUniformLocation(Name);
+
+ if (m_spotLightsLocation[i].Color == INVALID_UNIFORM_LOCATION ||
+ m_spotLightsLocation[i].AmbientIntensity == INVALID_UNIFORM_LOCATION ||
+ m_spotLightsLocation[i].Position == INVALID_UNIFORM_LOCATION ||
+ m_spotLightsLocation[i].Direction == INVALID_UNIFORM_LOCATION ||
+ m_spotLightsLocation[i].Cutoff == INVALID_UNIFORM_LOCATION ||
+ m_spotLightsLocation[i].DiffuseIntensity == INVALID_UNIFORM_LOCATION ||
+ m_spotLightsLocation[i].Atten.Constant == INVALID_UNIFORM_LOCATION ||
+ m_spotLightsLocation[i].Atten.Linear == INVALID_UNIFORM_LOCATION ||
+ m_spotLightsLocation[i].Atten.Exp == INVALID_UNIFORM_LOCATION) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+void LightingTechnique::SetWVP(const Matrix4f& WVP)
+{
+ glUniformMatrix4fv(m_WVPLocation, 1, GL_TRUE, (const GLfloat*)WVP.m);
+}
+
+
+void LightingTechnique::SetWorldMatrix(const Matrix4f& WorldInverse)
+{
+ glUniformMatrix4fv(m_WorldMatrixLocation, 1, GL_TRUE, (const GLfloat*)WorldInverse.m);
+}
+
+
+void LightingTechnique::SetColorTextureUnit(unsigned int TextureUnit)
+{
+ glUniform1i(m_colorTextureLocation, TextureUnit);
+}
+
+
+void LightingTechnique::SetDirectionalLight(const DirectionalLight& Light)
+{
+ glUniform3f(m_dirLightLocation.Color, Light.Color.x, Light.Color.y, Light.Color.z);
+ glUniform1f(m_dirLightLocation.AmbientIntensity, Light.AmbientIntensity);
+ Vector3f Direction = Light.Direction;
+ Direction.Normalize();
+ glUniform3f(m_dirLightLocation.Direction, Direction.x, Direction.y, Direction.z);
+ glUniform1f(m_dirLightLocation.DiffuseIntensity, Light.DiffuseIntensity);
+}
+
+
+void LightingTechnique::SetEyeWorldPos(const Vector3f& EyeWorldPos)
+{
+ glUniform3f(m_eyeWorldPosLocation, EyeWorldPos.x, EyeWorldPos.y, EyeWorldPos.z);
+}
+
+
+void LightingTechnique::SetMatSpecularIntensity(float Intensity)
+{
+ glUniform1f(m_matSpecularIntensityLocation, Intensity);
+}
+
+
+void LightingTechnique::SetMatSpecularPower(float Power)
+{
+ glUniform1f(m_matSpecularPowerLocation, Power);
+}
+
+
+void LightingTechnique::SetPointLights(unsigned int NumLights, const PointLight* pLights)
+{
+ glUniform1i(m_numPointLightsLocation, NumLights);
+
+ for (unsigned int i = 0 ; i < NumLights ; i++) {
+ glUniform3f(m_pointLightsLocation[i].Color, pLights[i].Color.x, pLights[i].Color.y, pLights[i].Color.z);
+ glUniform1f(m_pointLightsLocation[i].AmbientIntensity, pLights[i].AmbientIntensity);
+ glUniform1f(m_pointLightsLocation[i].DiffuseIntensity, pLights[i].DiffuseIntensity);
+ glUniform3f(m_pointLightsLocation[i].Position, pLights[i].Position.x, pLights[i].Position.y, pLights[i].Position.z);
+ glUniform1f(m_pointLightsLocation[i].Atten.Constant, pLights[i].Attenuation.Constant);
+ glUniform1f(m_pointLightsLocation[i].Atten.Linear, pLights[i].Attenuation.Linear);
+ glUniform1f(m_pointLightsLocation[i].Atten.Exp, pLights[i].Attenuation.Exp);
+ }
+}
+
+void LightingTechnique::SetSpotLights(unsigned int NumLights, const SpotLight* pLights)
+{
+ glUniform1i(m_numSpotLightsLocation, NumLights);
+
+ for (unsigned int i = 0 ; i < NumLights ; i++) {
+ glUniform3f(m_spotLightsLocation[i].Color, pLights[i].Color.x, pLights[i].Color.y, pLights[i].Color.z);
+ glUniform1f(m_spotLightsLocation[i].AmbientIntensity, pLights[i].AmbientIntensity);
+ glUniform1f(m_spotLightsLocation[i].DiffuseIntensity, pLights[i].DiffuseIntensity);
+ glUniform3f(m_spotLightsLocation[i].Position, pLights[i].Position.x, pLights[i].Position.y, pLights[i].Position.z);
+ Vector3f Direction = pLights[i].Direction;
+ Direction.Normalize();
+ glUniform3f(m_spotLightsLocation[i].Direction, Direction.x, Direction.y, Direction.z);
+ glUniform1f(m_spotLightsLocation[i].Cutoff, cosf(ToRadian(pLights[i].Cutoff)));
+ glUniform1f(m_spotLightsLocation[i].Atten.Constant, pLights[i].Attenuation.Constant);
+ glUniform1f(m_spotLightsLocation[i].Atten.Linear, pLights[i].Attenuation.Linear);
+ glUniform1f(m_spotLightsLocation[i].Atten.Exp, pLights[i].Attenuation.Exp);
+ }
+}
+
+
+void LightingTechnique::SetColor(const Vector4f& Color)
+{
+ glUniform4f(m_colorLocation, Color.x, Color.y, Color.z, Color.w);
+}
148 tutorial39/lighting_technique.h
View
@@ -0,0 +1,148 @@
+/*
+ Copyright 2011 Etay Meiri
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef LIGHTING_TECHNIQUE_H
+#define LIGHTING_TECHNIQUE_H
+
+#include "technique.h"
+#include "math_3d.h"
+
+struct BaseLight
+{
+ Vector3f Color;
+ float AmbientIntensity;
+ float DiffuseIntensity;
+
+ BaseLight()
+ {
+ Color = Vector3f(0.0f, 0.0f, 0.0f);
+ AmbientIntensity = 0.0f;
+ DiffuseIntensity = 0.0f;
+ }
+};
+
+struct DirectionalLight : public BaseLight
+{
+ Vector3f Direction;
+
+ DirectionalLight()
+ {
+ Direction = Vector3f(0.0f, 0.0f, 0.0f);
+ }
+};
+
+struct PointLight : public BaseLight
+{
+ Vector3f Position;
+
+ struct
+ {
+ float Constant;
+ float Linear;
+ float Exp;
+ } Attenuation;
+
+ PointLight()
+ {
+ Position = Vector3f(0.0f, 0.0f, 0.0f);
+ Attenuation.Constant = 1.0f;
+ Attenuation.Linear = 0.0f;
+ Attenuation.Exp = 0.0f;
+ }
+};
+
+struct SpotLight : public PointLight
+{
+ Vector3f Direction;
+ float Cutoff;
+
+ SpotLight()
+ {
+ Direction = Vector3f(0.0f, 0.0f, 0.0f);
+ Cutoff = 0.0f;
+ }
+};
+
+class LightingTechnique : public Technique {
+public:
+
+ static const unsigned int MAX_POINT_LIGHTS = 2;
+ static const unsigned int MAX_SPOT_LIGHTS = 2;
+
+ LightingTechnique();
+
+ virtual bool Init();
+
+ void SetWVP(const Matrix4f& WVP);
+ void SetWorldMatrix(const Matrix4f& WVP);
+ void SetColorTextureUnit(unsigned int TextureUnit);
+ void SetDirectionalLight(const DirectionalLight& Light);
+ void SetPointLights(unsigned int NumLights, const PointLight* pLights);
+ void SetSpotLights(unsigned int NumLights, const SpotLight* pLights);
+ void SetEyeWorldPos(const Vector3f& EyeWorldPos);
+ void SetMatSpecularIntensity(float Intensity);
+ void SetMatSpecularPower(float Power);
+ void SetColor(const Vector4f& Color);
+
+private:
+
+ GLuint m_WVPLocation;
+ GLuint m_WorldMatrixLocation;
+ GLuint m_colorTextureLocation;
+ GLuint m_eyeWorldPosLocation;
+ GLuint m_matSpecularIntensityLocation;
+ GLuint m_matSpecularPowerLocation;
+ GLuint m_numPointLightsLocation;
+ GLuint m_numSpotLightsLocation;
+ GLuint m_colorLocation;
+
+ struct {
+ GLuint Color;
+ GLuint AmbientIntensity;
+ GLuint DiffuseIntensity;
+ GLuint Direction;
+ } m_dirLightLocation;
+
+ struct {
+ GLuint Color;
+ GLuint AmbientIntensity;
+ GLuint DiffuseIntensity;
+ GLuint Position;
+ struct {
+ GLuint Constant;
+ GLuint Linear;
+ GLuint Exp;
+ } Atten;
+ } m_pointLightsLocation[MAX_POINT_LIGHTS];
+
+ struct {
+ GLuint Color;
+ GLuint AmbientIntensity;
+ GLuint DiffuseIntensity;
+ GLuint Position;
+ GLuint Direction;
+ GLuint Cutoff;
+ struct {
+ GLuint Constant;
+ GLuint Linear;
+ GLuint Exp;
+ } Atten;
+ } m_spotLightsLocation[MAX_SPOT_LIGHTS];
+};
+
+
+#endif /* LIGHTING_TECHNIQUE_H */
98 tutorial39/log
View
@@ -1,85 +1,51 @@
+First time vector -29.009998 14.676008 -27.403046 on index 0
+First time vector -39.236671 24.546705 -25.209332 on index 1
+First time vector -31.282593 24.546705 -25.209333 on index 2
Edge 0 1
First neighbor 0
Edge 1 2
First neighbor 0
Edge 0 2
First neighbor 0
-Edge 0 2
-Second neighbor 1
-Edge 2 5
+First time vector -40.372967 3.517826 -18.628197 on index 3
+First time vector -41.509262 18.109295 -18.628197 on index 4
+First time vector -29.009998 17.680134 -18.628197 on index 5
+Edge 3 4
+First neighbor 1
+Edge 4 5
First neighbor 1
-Edge 0 5
+Edge 3 5
First neighbor 1
+First time vector -39.236668 49.438030 30.730330 on index 6
+First time vector -49.463341 43.429783 30.730330 on index 7
+First time vector -49.463341 40.425655 30.730330 on index 8
Edge 6 7
First neighbor 2
Edge 7 8
First neighbor 2
Edge 6 8
First neighbor 2
-Edge 6 8
-Second neighbor 3
-Edge 8 11
+First time vector 5.078910 15.534330 15.374343 on index 9
+First time vector 9.624096 17.250973 -16.434484 on index 10
+First time vector 9.624097 17.250973 14.277487 on index 11
+Edge 9 10
+First neighbor 3
+Edge 10 11
First neighbor 3
-Edge 6 11
+Edge 9 11
First neighbor 3
-Edge 0 6
+First time vector 5.078909 15.534330 -16.434484 on index 12
+13
+Vector 9.624096 17.250973 -16.434484 already on index 10
+14
+Vector 5.078910 15.534330 15.374343 already on index 9
+Edge 10 12
First neighbor 4
-Edge 6 11
+Edge 9 10
Second neighbor 4
-Edge 0 11
+Edge 9 12
First neighbor 4
-Edge 0 11
-Second neighbor 5
-Edge 1 11
-First neighbor 5
-Edge 0 1
-Second neighbor 5
-Edge 1 11
-Second neighbor 6
-Edge 8 11
-Second neighbor 6
-Edge 1 8
-First neighbor 6
-Edge 1 8
-Second neighbor 7
-Edge 2 8
-First neighbor 7
-Edge 1 2
-Second neighbor 7
-Edge 2 8
-Second neighbor 8
-Edge 7 8
-Second neighbor 8
-Edge 2 7
-First neighbor 8
-Edge 2 7
-Second neighbor 9
-Edge 5 7
-First neighbor 9
-Edge 2 5
-Second neighbor 9
-Edge 0 6
-Second neighbor 10
-Edge 0 5
-Second neighbor 10
-Edge 5 6
-First neighbor 10
-Edge 5 6
-Second neighbor 11
-Edge 5 7
-Second neighbor 11
-Edge 6 7
-Second neighbor 11
-0 11 1 8 2 5
-0 1 2 7 5 6
-6 5 7 2 8 11
-6 7 8 1 11 0
-0 5 6 8 11 1
-0 6 11 8 1 2
-1 0 11 6 8 2
-1 11 8 7 2 0
-2 1 8 6 7 5
-2 8 7 6 5 0
-6 11 0 2 5 7
-6 0 5 2 7 8
-Good!
+First time vector -89.233734 47.721390 12.083777 on index 15
+First time vector -92.642624 52.012997 8.793209 on index 16
+17
+Vector -89.233734 47.721390 12.083777 already on index 15
75 tutorial39/mesh.cpp
View
@@ -374,13 +374,84 @@ void Mesh::Render()
m_Textures[MaterialIndex]->Bind(GL_TEXTURE0);
}
- assert(m_Entries[i].NumIndices == 72);
-
glDrawElementsBaseVertex(GL_TRIANGLES_ADJACENCY,
m_Entries[i].NumIndices,
GL_UNSIGNED_INT,
(void*)(sizeof(uint) * m_Entries[i].BaseIndex),
m_Entries[i].BaseVertex);
+
+// glDrawElementsBaseVertex(GL_TRIANGLES_ADJACENCY,
+// 6,
+// GL_UNSIGNED_INT,
+// 0,
+// 0);
+//
+//
+// glDrawElementsBaseVertex(GL_TRIANGLES_ADJACENCY,
+// 6,
+// GL_UNSIGNED_INT,
+// (void*)(sizeof(uint) * 6),
+// 0);
+ // top bottom left
+// glDrawElementsBaseVertex(GL_TRIANGLES_ADJACENCY,
+// 6,
+// GL_UNSIGNED_INT,
+// (void*)(sizeof(uint) * 12),
+// 0);
+ // top upper right
+// glDrawElementsBaseVertex(GL_TRIANGLES_ADJACENCY,
+// 6,
+// GL_UNSIGNED_INT,
+// (void*)(sizeof(uint) * 18),
+// 0);
+ // right upper left
+// glDrawElementsBaseVertex(GL_TRIANGLES_ADJACENCY,
+// 6,
+// GL_UNSIGNED_INT,
+// (void*)(sizeof(uint) * 24),
+// 0);
+ // right bottom right
+// glDrawElementsBaseVertex(GL_TRIANGLES_ADJACENCY,
+// 6,
+// GL_UNSIGNED_INT,
+// (void*)(sizeof(uint) * 30),
+// 0);
+ // back upper left
+// glDrawElementsBaseVertex(GL_TRIANGLES_ADJACENCY,
+// 6,
+// GL_UNSIGNED_INT,
+// (void*)(sizeof(uint) * 36),
+// 0);
+ // back bottom right
+// glDrawElementsBaseVertex(GL_TRIANGLES_ADJACENCY,
+// 6,
+// GL_UNSIGNED_INT,
+// (void*)(sizeof(uint) * 42),
+// 0);
+ // left top left
+// glDrawElementsBaseVertex(GL_TRIANGLES_ADJACENCY,
+// 6,
+// GL_UNSIGNED_INT,
+// (void*)(sizeof(uint) * 48),
+// 0);
+ // left bottom right
+// glDrawElementsBaseVertex(GL_TRIANGLES_ADJACENCY,
+// 6,
+// GL_UNSIGNED_INT,
+// (void*)(sizeof(uint) * 54),
+// 0);
+ // front bottom right
+// glDrawElementsBaseVertex(GL_TRIANGLES_ADJACENCY,
+// 6,
+// GL_UNSIGNED_INT,
+// (void*)(sizeof(uint) * 60),
+// 0);
+ // front top left
+// glDrawElementsBaseVertex(GL_TRIANGLES_ADJACENCY,
+// 6,
+// GL_UNSIGNED_INT,
+// (void*)(sizeof(uint) * 66),
+// 0);
}
// Make sure the VAO is not changed from the outside
13 tutorial39/models/box.mtl
View
@@ -0,0 +1,13 @@
+# Blender MTL File: ''
+# Material Count: 1
+newmtl Material_test.png
+Ns 96.078431
+Ka 0.000000 0.000000 0.000000
+Kd 0.640000 0.640000 0.640000
+Ks 0.500000 0.500000 0.500000
+Ni 1.000000
+d 1.000000
+illum 2
+map_Kd /home/cl/tutorials/Tutorial26/test.png
+
+
46 tutorial39/models/box.obj
View
@@ -0,0 +1,46 @@
+# Blender v2.57 (sub 0) OBJ File: ''
+# www.blender.org
+#mtllib box.mtl
+o Cube
+v 1.000000 -1.000000 -1.000000
+v 1.000000 -1.000000 1.000000
+v -1.000000 -1.000000 1.000000
+v -1.000000 -1.000000 -1.000000
+v 1.000000 1.000000 -1.000000
+v 0.999999 1.000000 1.000001
+v -1.000000 1.000000 1.000000
+v -1.000000 1.000000 -1.000000
+vt 0.750000 0.500000
+vt 0.500000 0.500000
+vt 0.500000 0.250000
+vt 0.750000 0.250000
+vt 0.000000 0.500000
+vt 0.000000 0.250000
+vt 0.250000 0.250000
+vt 0.250000 0.500000
+vt 0.749999 0.750001
+vt 0.499999 0.750000
+vt 0.500000 0.000000
+vt 0.750000 0.000000
+vt 1.000000 0.500000
+vt 1.000000 0.250000
+vn -0.000000 -1.000000 0.000000
+vn 0.000000 1.000000 -0.000000
+vn 1.000000 0.000000 0.000000
+vn -0.000000 -0.000000 1.000000
+vn -1.000000 -0.000000 -0.000000
+vn 0.000000 0.000000 -1.000000
+#usemtl Material_test.png
+s off
+f 1/1/1 2/2/1 3/3/1
+f 1/1/1 3/3/1 4/4/1
+f 5/5/2 8/6/2 7/7/2
+f 5/5/2 7/7/2 6/8/2
+f 1/1/3 5/9/3 6/10/3
+f 1/1/3 6/10/3 2/2/3
+f 2/2/4 6/8/4 7/7/4
+f 2/2/4 7/7/4 3/3/4
+f 3/3/5 7/11/5 8/12/5
+f 3/3/5 8/12/5 4/4/5
+f 5/13/6 1/1/6 4/4/6
+f 5/13/6 4/4/6 8/14/6
2  tutorial39/models/f.mtl
View
@@ -1,2 +0,0 @@
-# Blender MTL File: 'glfx.blend'
-# Material Count: 0
122 tutorial39/models/f.obj
View
@@ -1,122 +0,0 @@
-# Blender v2.58 (sub 0) OBJ File: 'glfx.blend'
-# www.blender.org
-mtllib f.mtl
-o Cube.002
-v -2.737500 6.167860 -1.037541
-v -2.737501 6.167860 0.962459
-v -4.817796 6.164631 0.962458
-v -4.817795 6.164631 -1.037542
-v -2.898090 8.161403 -1.037541
-v -2.898092 8.161403 0.962459
-v -4.817796 8.164631 0.962458
-v -4.817796 8.164631 -1.037541
-v -4.989292 1.769833 -1.037542
-v -4.989293 1.769833 0.962458
-v -3.021181 2.007528 0.962458
-v -3.021181 2.007528 -1.037542
-v -1.999431 -2.379405 -1.037542
-v -1.999431 -2.379405 0.962458
-v -3.996041 -2.263000 0.962457
-v -3.996040 -2.262999 -1.037543
-v -5.470451 -6.186082 -1.037544
-v -5.470452 -6.186082 0.962457
-v -3.591331 -6.870847 0.962457
-v -3.591331 -6.870847 -1.037543
-v 2.466425 9.020319 0.962460
-v 2.466426 9.020319 -1.037540
-v 2.451795 7.020372 0.962460
-v 2.451795 7.020372 -1.037540
-v 6.249423 6.080140 -1.037540
-v 6.249423 6.080140 0.962460
-v 6.598416 8.049456 -1.037539
-v 6.598416 8.049456 0.962461
-v -4.592523 0.158854 0.962458
-v -2.669254 0.246707 0.962458
-v -2.669254 0.246707 -1.037542
-v -4.592522 0.158854 -1.037542
-v 1.371860 -0.070010 -1.037541
-v 1.371860 -0.070010 0.962459
-v 1.409280 1.725245 -1.037541
-v 1.409280 1.725245 0.962459
-v 5.771692 2.518440 0.962460
-v 5.771692 2.518440 -1.037540
-v 5.395453 0.762653 0.962459
-v 5.395453 0.762653 -1.037541
-usemtl (null)
-s off
-f 5 8 7
-f 5 7 6
-f 2 6 7
-f 2 7 3
-f 3 7 8
-f 3 8 4
-f 5 1 4
-f 5 4 8
-f 3 4 9
-f 3 9 10
-f 4 1 12
-f 4 12 9
-f 1 2 11
-f 1 11 12
-f 2 3 10
-f 2 10 11
-f 15 16 17
-f 15 17 18
-f 16 13 20
-f 16 20 17
-f 13 14 19
-f 13 19 20
-f 14 15 18
-f 14 18 19
-f 20 19 18
-f 20 18 17
-f 1 5 22
-f 1 22 24
-f 6 2 23
-f 6 23 21
-f 5 6 21
-f 5 21 22
-f 2 1 24
-f 2 24 23
-f 23 24 25
-f 23 25 26
-f 22 21 28
-f 22 28 27
-f 21 23 26
-f 21 26 28
-f 24 22 27
-f 24 27 25
-f 25 27 28
-f 25 28 26
-f 10 29 30
-f 10 30 11
-f 29 15 14
-f 29 14 30
-f 30 14 13
-f 30 13 31
-f 12 31 32
-f 12 32 9
-f 31 13 16
-f 31 16 32
-f 9 32 29
-f 9 29 10
-f 32 16 15
-f 32 15 29
-f 30 31 33
-f 30 33 34
-f 31 12 35
-f 31 35 33
-f 11 30 34
-f 11 34 36
-f 12 11 36
-f 12 36 35
-f 35 36 37
-f 35 37 38
-f 36 34 39
-f 36 39 37
-f 33 35 38
-f 33 38 40
-f 34 33 40
-f 34 40 39
-f 37 39 40
-f 37 40 38
2  tutorial39/models/g.mtl
View
@@ -1,2 +0,0 @@
-# Blender MTL File: 'glfx.blend'
-# Material Count: 0
186 tutorial39/models/g.obj
View
@@ -1,186 +0,0 @@
-# Blender v2.58 (sub 0) OBJ File: 'glfx.blend'
-# www.blender.org
-mtllib g.mtl
-o Cube
-v 7.166001 -2.202501 -4.655609
-v 7.166001 -2.202501 -2.655610
-v 0.732996 -2.202501 -2.655611
-v 0.732996 -2.202501 -4.655611
-v 7.166001 -0.202501 -4.655609
-v 7.166000 -0.202501 -2.655609
-v 0.732996 -0.202501 -2.655611
-v 0.732996 -0.202501 -4.655611
-v 5.008879 -2.367598 -2.655610
-v 2.890119 -2.037405 -2.655610
-v 5.021667 -2.202501 -4.655610
-v 2.877332 -2.202501 -4.655611
-v 5.021666 -0.202501 -2.655610
-v 2.877330 -0.202501 -2.655610
-v 5.021667 -0.202501 -4.655610
-v 2.877331 -0.202501 -4.655610
-v 1.457610 -4.712874 -2.655611
-v 2.669297 -5.924711 -2.655611
-v -1.353345 -7.694439 -2.655612
-v -1.377997 -5.702250 -2.655612
-v -4.813012 -4.552977 -2.655612
-v -6.203203 -6.185626 -2.655612
-v -8.351633 -2.207067 -2.655612
-v -6.509114 -1.680079 -2.655612
-v -6.441174 1.884493 -2.655611
-v -8.367695 2.304410 -2.655611
-v -6.750615 5.115611 -2.655611
-v -5.184847 3.985793 -2.655611
-v -1.256950 5.973645 -2.655610
-v -1.457107 8.108619 -2.655610
-v 4.282665 5.183837 -2.655609
-v 2.332502 4.362199 -2.655610
-v 2.889337 1.846121 -2.655610
-v 5.009670 1.879850 -2.655610
-v 0.767797 5.687207 -2.655610
-v 1.437264 7.533667 -2.655609
-v -3.192354 5.603918 -2.655610
-v -4.201497 7.333159 -2.655610
-v -4.201496 7.333159 -4.655334
-v -3.192354 5.603918 -4.655334
-v 1.437264 7.533667 -4.655333
-v 0.767797 5.687207 -4.655334
-v 5.009670 1.879850 -4.655334
-v 2.889337 1.846121 -4.655334
-v 2.332502 4.362199 -4.655334
-v 4.282665 5.183837 -4.655333
-v -1.457107 8.108619 -4.655334
-v -1.256950 5.973645 -4.655334
-v -5.184847 3.985793 -4.655334
-v -6.750614 5.115611 -4.655334
-v -8.367694 2.304410 -4.655335
-v -6.441174 1.884493 -4.655335
-v -6.509114 -1.680079 -4.655335
-v -8.351633 -2.207067 -4.655336
-v -6.203203 -6.185626 -4.655336
-v -4.813012 -4.552977 -4.655335
-v -1.377997 -5.702250 -4.655335
-v -1.353345 -7.694439 -4.655335
-v 2.669297 -5.924711 -4.655334
-v 1.457610 -4.712874 -4.655334
-usemtl (null)
-s off
-f 1 5 6
-f 1 6 2
-f 3 7 8
-f 3 8 4
-f 11 1 2
-f 11 2 9
-f 9 10 12
-f 9 12 11
-f 10 3 4
-f 10 4 12
-f 5 15 13
-f 5 13 6
-f 15 16 14
-f 15 14 13
-f 16 8 7
-f 16 7 14
-f 6 13 9
-f 6 9 2
-f 13 14 10
-f 13 10 9
-f 14 7 3
-f 14 3 10
-f 1 11 15
-f 1 15 5
-f 11 12 16
-f 11 16 15
-f 12 4 8
-f 12 8 16
-f 9 10 17
-f 9 17 18
-f 38 27 50
-f 38 50 39
-f 30 38 39
-f 30 39 47
-f 37 29 48
-f 37 48 40
-f 28 37 40
-f 28 40 49
-f 31 36 41
-f 31 41 46
-f 36 30 47
-f 36 47 41
-f 29 35 42
-f 29 42 48
-f 35 32 45
-f 35 45 42
-f 34 31 46
-f 34 46 43
-f 33 34 43
-f 33 43 44
-f 32 33 44
-f 32 44 45
-f 27 26 51
-f 27 51 50
-f 25 28 49
-f 25 49 52
-f 26 23 54
-f 26 54 51
-f 24 25 52
-f 24 52 53
-f 23 22 55
-f 23 55 54
-f 21 24 53
-f 21 53 56
-f 22 19 58
-f 22 58 55
-f 20 21 56
-f 20 56 57
-f 19 18 59
-f 19 59 58
-f 17 20 57
-f 17 57 60
-f 18 17 60
-f 18 60 59
-f 59 60 57
-f 59 57 58
-f 58 57 56
-f 58 56 55
-f 55 56 53
-f 55 53 54
-f 54 53 52
-f 54 52 51
-f 51 52 49
-f 51 49 50
-f 46 45 44
-f 46 44 43
-f 48 42 41
-f 48 41 47
-f 42 45 46
-f 42 46 41
-f 49 40 39
-f 49 39 50
-f 40 48 47
-f 40 47 39
-f 11 59 60
-f 11 60 12
-f 11 9 18
-f 11 18 59
-f 10 12 60
-f 10 60 17
-f 31 34 33
-f 31 33 32
-f 31 32 35
-f 31 35 36
-f 29 30 36
-f 29 36 35
-f 29 37 38
-f 29 38 30
-f 27 38 37
-f 27 37 28
-f 25 26 27
-f 25 27 28
-f 23 26 25
-f 23 25 24
-f 21 22 23
-f 21 23 24
-f 19 22 21
-f 19 21 20
-f 17 18 19
-f 17 19 20
2  tutorial39/models/l.mtl
View
@@ -1,2 +0,0 @@
-# Blender MTL File: 'glfx.blend'
-# Material Count: 0
98 tutorial39/models/l.obj
View
@@ -1,98 +0,0 @@
-# Blender v2.58 (sub 0) OBJ File: 'glfx.blend'
-# www.blender.org
-mtllib l.mtl
-o Cube.001
-v -3.368974 6.029388 -1.037541
-v -3.368974 6.029388 0.962459
-v -5.367133 5.943604 0.962459
-v -5.367133 5.943604 -1.037542
-v -3.368053 7.986496 -1.037540
-v -3.368054 7.986496 0.962460
-v -5.368054 7.986496 0.962458
-v -5.368053 7.986496 -1.037541
-v -5.022678 2.085662 -1.037542
-v -5.022678 2.085662 0.962458
-v -3.028831 1.928899 0.962458
-v -3.028831 1.928899 -1.037541
-v -4.138438 -2.464639 -1.037542
-v -4.138439 -2.464639 0.962458
-v -6.138008 -2.506125 0.962457
-v -6.138007 -2.506125 -1.037543
-v -4.381489 -6.470642 -1.037543
-v -4.381490 -6.470642 0.962457
-v -3.883955 -4.404767 0.962457
-v -3.883955 -4.404767 -1.037542
-v -0.825916 -4.404661 -1.037542
-v -0.825917 -4.404661 0.962458
-v -1.010725 -6.394675 0.962457
-v -1.010724 -6.394675 -1.037543
-v 2.134202 -5.758570 -1.037542
-v 2.134202 -5.758570 0.962458
-v 2.061007 -3.852226 0.962458
-v 2.061007 -3.852226 -1.037541
-v 6.036469 -4.571403 -1.037541
-v 6.036469 -4.571403 0.962459
-v 5.499137 -6.627285 0.962458
-v 5.499137 -6.627285 -1.037542
-usemtl (null)
-s off
-f 5 8 7
-f 5 7 6
-f 1 5 6
-f 1 6 2
-f 2 6 7
-f 2 7 3
-f 3 7 8
-f 3 8 4
-f 5 1 4
-f 5 4 8
-f 3 4 9
-f 3 9 10
-f 4 1 12
-f 4 12 9
-f 1 2 11
-f 1 11 12
-f 2 3 10
-f 2 10 11
-f 11 10 15
-f 11 15 14
-f 12 11 14
-f 12 14 13
-f 9 12 13
-f 9 13 16
-f 10 9 16
-f 10 16 15
-f 15 16 17
-f 15 17 18
-f 16 13 20
-f 16 20 17
-f 13 14 19
-f 13 19 20
-f 14 15 18
-f 14 18 19
-f 19 18 23
-f 19 23 22
-f 20 19 22
-f 20 22 21
-f 17 20 21
-f 17 21 24
-f 18 17 24
-f 18 24 23
-f 23 24 25
-f 23 25 26
-f 24 21 28
-f 24 28 25
-f 21 22 27
-f 21 27 28
-f 22 23 26
-f 22 26 27
-f 27 26 31
-f 27 31 30
-f 28 27 30
-f 28 30 29
-f 25 28 29
-f 25 29 32
-f 26 25 32
-f 26 32 31
-f 29 30 31
-f 29 31 32
2  tutorial39/models/quad.mtl
View
@@ -0,0 +1,2 @@
+# Blender MTL File: ''
+# Material Count: 0
15 tutorial39/models/quad.obj
View
@@ -0,0 +1,15 @@
+# Blender v2.57 (sub 0) OBJ File: ''
+# www.blender.org
+o Cube_Cube.001
+v -1.000000 1.000000 0.000000
+v 1.000000 1.000000 0.000000
+v -1.000000 -1.000000 0.000000
+v 1.000000 -1.000000 0.000000
+vt 1.000000 1.000000
+vt 0.000000 1.000000
+vt 0.000000 0.000000
+vt 1.000000 0.000000
+usemtl (null)
+s off
+f 4/4 3/3 1/2
+f 2/1 4/4 1/2
BIN  tutorial39/models/test.png
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2  tutorial39/models/x.mtl
View
@@ -1,2 +0,0 @@
-# Blender MTL File: 'glfx.blend'
-# Material Count: 0
145 tutorial39/models/x.obj
View
@@ -1,145 +0,0 @@
-# Blender v2.58 (sub 0) OBJ File: 'glfx.blend'
-# www.blender.org
-mtllib x.mtl
-v -1.361902 6.142535 -1.037541
-v -1.361902 6.142535 0.962459
-v -3.146315 5.239279 0.962458
-v -3.146314 5.239280 -1.037542
-v -3.437076 8.878069 -1.037541
-v -3.437078 8.878068 0.962459
-v -5.371002 8.368231 0.962458
-v -5.371001 8.368231 -1.037542
-v -1.803183 1.692944 -1.037542
-v -1.803184 1.692944 0.962458
-v -0.257417 2.939734 0.962458
-v -0.257417 2.939734 -1.037542
-v 3.201405 -0.761281 -1.037542
-v 3.201405 -0.761281 0.962458
-v 1.560467 -1.904661 0.962458
-v 1.560467 -1.904661 -1.037542
-v 3.197801 -5.874071 -1.037543
-v 3.197800 -5.874071 0.962458
-v 4.915561 -4.849721 0.962458
-v 4.915561 -4.849721 -1.037542
-v -0.553559 0.419430 0.962458
-v 1.043249 1.644951 0.962458
-v 1.043249 1.644951 -1.037542
-v -0.553559 0.419431 -1.037542
-v 2.429640 3.888695 -1.037541
-v 2.429640 3.888695 0.962459
-v 1.360640 5.005366 -1.037541
-v 1.360641 5.005366 0.962459
-v 3.484005 6.748034 0.962459
-v 3.484003 6.748033 -1.037541
-v 4.670327 5.347736 0.962459
-v 4.670325 5.347735 -1.037541
-v 6.161980 8.342769 -1.037540
-v 6.161979 8.342770 0.962460
-v 5.013402 9.362542 -1.037540
-v 5.013403 9.362543 0.962460
-v -1.836429 -1.855563 -1.037543
-v -1.836430 -1.855564 0.962458
-v -3.123029 -0.619416 0.962458
-v -3.123028 -0.619416 -1.037543
-v -4.879093 -2.628445 -1.037543
-v -4.879094 -2.628445 0.962457
-v -3.312938 -3.483171 0.962457
-v -3.312938 -3.483171 -1.037543
-v -3.822395 -5.930495 -1.037544
-v -3.822395 -5.930496 0.962457
-v -5.558083 -5.517236 0.962457
-v -5.558083 -5.517235 -1.037544
-usemtl (null)
-s off
-f 5 8 7
-f 5 7 6
-f 1 5 6
-f 1 6 2
-f 2 6 7
-f 2 7 3
-f 3 7 8
-f 3 8 4
-f 5 1 4
-f 5 4 8
-f 3 4 9
-f 3 9 10
-f 4 1 12
-f 4 12 9
-f 1 2 11
-f 1 11 12
-f 2 3 10
-f 2 10 11
-f 15 16 17
-f 15 17 18
-f 16 13 20
-f 16 20 17
-f 13 14 19
-f 13 19 20
-f 14 15 18
-f 14 18 19
-f 20 19 18
-f 20 18 17
-f 10 21 22
-f 10 22 11
-f 21 15 14
-f 21 14 22
-f 22 14 13
-f 22 13 23
-f 12 23 24
-f 12 24 9
-f 23 13 16
-f 23 16 24
-f 24 16 15
-f 24 15 21
-f 22 23 25
-f 22 25 26
-f 23 12 27
-f 23 27 25
-f 11 22 26
-f 11 26 28
-f 12 11 28
-f 12 28 27
-f 27 28 29
-f 27 29 30
-f 28 26 31
-f 28 31 29
-f 25 27 30
-f 25 30 32
-f 26 25 32
-f 26 32 31
-f 31 32 33
-f 31 33 34
-f 32 30 35
-f 32 35 33
-f 29 31 34
-f 29 34 36
-f 30 29 36
-f 30 36 35
-f 36 34 33
-f 36 33 35
-f 24 21 38
-f 24 38 37
-f 9 24 37
-f 9 37 40
-f 21 10 39
-f 21 39 38
-f 10 9 40
-f 10 40 39
-f 39 40 41
-f 39 41 42
-f 38 39 42
-f 38 42 43
-f 40 37 44
-f 40 44 41
-f 37 38 43
-f 37 43 44
-f 44 43 46
-f 44 46 45
-f 41 44 45
-f 41 45 48
-f 43 42 47
-f 43 47 46
-f 42 41 48
-f 42 48 47
-f 48 45 46
-f 48 46 47
12 tutorial39/nbproject/Makefile-Debug.mk
View
@@ -34,6 +34,8 @@ OBJECTDIR=${CND_BUILDDIR}/${CND_CONF}/${CND_PLATFORM}
# Object Files
OBJECTFILES= \
+ ${OBJECTDIR}/lighting_technique.o \
+ ${OBJECTDIR}/null_technique.o \
${OBJECTDIR}/FreetypeGL/font-manager.o \
${OBJECTDIR}/FreetypeGL/freetypeGL.o \
${OBJECTDIR}/FreetypeGL/texture-font.o \
@@ -81,6 +83,16 @@ ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/tutorial39: ${OBJECTFILES}
${MKDIR} -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}
${LINK.cc} -o ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/tutorial39 ${OBJECTFILES} ${LDLIBSOPTIONS}
+${OBJECTDIR}/lighting_technique.o: lighting_technique.cpp
+ ${MKDIR} -p ${OBJECTDIR}
+ ${RM} $@.d
+ $(COMPILE.cc) -g -I/usr/include/ImageMagick -I/usr/local/include/assimp -I/usr/include/freetype2 -IFreetypeGL -I../../../assimp/code -I../../../assimp/tools/assimp_view -MMD -MP -MF $@.d -o ${OBJECTDIR}/lighting_technique.o lighting_technique.cpp
+
+${OBJECTDIR}/null_technique.o: null_technique.cpp
+ ${MKDIR} -p ${OBJECTDIR}
+ ${RM} $@.d
+ $(COMPILE.cc) -g -I/usr/include/ImageMagick -I/usr/local/include/assimp -I/usr/include/freetype2 -IFreetypeGL -I../../../assimp/code -I../../../assimp/tools/assimp_view -MMD -MP -MF $@.d -o ${OBJECTDIR}/null_technique.o null_technique.cpp
+
${OBJECTDIR}/FreetypeGL/font-manager.o: FreetypeGL/font-manager.c
${MKDIR} -p ${OBJECTDIR}/FreetypeGL
${RM} $@.d
12 tutorial39/nbproject/Makefile-Release.mk
View
@@ -34,6 +34,8 @@ OBJECTDIR=${CND_BUILDDIR}/${CND_CONF}/${CND_PLATFORM}
# Object Files
OBJECTFILES= \
+ ${OBJECTDIR}/lighting_technique.o \
+ ${OBJECTDIR}/null_technique.o \
${OBJECTDIR}/FreetypeGL/font-manager.o \
${OBJECTDIR}/FreetypeGL/freetypeGL.o \
${OBJECTDIR}/FreetypeGL/texture-font.o \
@@ -81,6 +83,16 @@ ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/tutorial39: ${OBJECTFILES}
${MKDIR} -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}
${LINK.cc} -o ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/tutorial39 ${OBJECTFILES} ${LDLIBSOPTIONS}
+${OBJECTDIR}/lighting_technique.o: lighting_technique.cpp
+ ${MKDIR} -p ${OBJECTDIR}
+ ${RM} $@.d
+ $(COMPILE.cc) -O2 -Werror -I/usr/include/ImageMagick -I/usr/local/include/assimp -I/usr/include/freetype2 -IFreetypeGL -MMD -MP -MF $@.d -o ${OBJECTDIR}/lighting_technique.o lighting_technique.cpp
+
+${OBJECTDIR}/null_technique.o: null_technique.cpp
+ ${MKDIR} -p ${OBJECTDIR}
+ ${RM} $@.d
+ $(COMPILE.cc) -O2 -Werror -I/usr/include/ImageMagick -I/usr/local/include/assimp -I/usr/include/freetype2 -IFreetypeGL -MMD -MP -MF $@.d -o ${OBJECTDIR}/null_technique.o null_technique.cpp
+
${OBJECTDIR}/FreetypeGL/font-manager.o: FreetypeGL/font-manager.c
${MKDIR} -p ${OBJECTDIR}/FreetypeGL
${RM} $@.d
6 tutorial39/nbproject/configurations.xml
View
@@ -26,8 +26,10 @@
<itemPath>callbacks.h</itemPath>
<itemPath>camera.h</itemPath>
<itemPath>glut_backend.h</itemPath>
+ <itemPath>lighting_technique.h</itemPath>
<itemPath>math_3d.h</itemPath>
<itemPath>mesh.h</itemPath>
+ <itemPath>null_technique.h</itemPath>
<itemPath>ogldev_types.h</itemPath>
<itemPath>pipeline.h</itemPath>
<itemPath>shadow_volume_technique.h</itemPath>
@@ -36,6 +38,8 @@
<itemPath>util.h</itemPath>
</logicalFolder>
<logicalFolder name="ResourceFiles" displayName="Shaders" projectFiles="true">
+ <itemPath>shaders/lighting.glsl</itemPath>
+ <itemPath>shaders/null_technique.glsl</itemPath>
<itemPath>shaders/shadow_volume.glsl</itemPath>
</logicalFolder>
<logicalFolder name="SourceFiles"
@@ -47,8 +51,10 @@
</logicalFolder>
<itemPath>camera.cpp</itemPath>
<itemPath>glut_backend.cpp</itemPath>
+ <itemPath>lighting_technique.cpp</itemPath>
<itemPath>math_3d.cpp</itemPath>
<itemPath>mesh.cpp</itemPath>
+ <itemPath>null_technique.cpp</itemPath>
<itemPath>pipeline.cpp</itemPath>
<itemPath>shadow_volume_technique.cpp</itemPath>
<itemPath>technique.cpp</itemPath>
51 tutorial39/null_technique.cpp
View
@@ -0,0 +1,51 @@
+/*
+
+ Copyright 2011 Etay Meiri
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <limits.h>
+#include <string.h>
+
+#include "null_technique.h"
+#include "util.h"
+
+static const char* pEffectFile = "shaders/null_technique.glsl";
+
+NullTechnique::NullTechnique() : Technique(pEffectFile)
+{
+}
+
+bool NullTechnique::Init()
+{
+ if (!CompileProgram("NullTechnique")) {
+ return false;
+ }
+
+ m_WVPLocation = GetUniformLocation("gWVP");
+
+ if (m_WVPLocation == INVALID_UNIFORM_LOCATION) {
+ return false;
+ }
+
+ return true;
+}
+
+
+void NullTechnique::SetWVP(const Matrix4f& WVP)
+{
+ glUniformMatrix4fv(m_WVPLocation, 1, GL_TRUE, (const GLfloat*)WVP.m);
+}
+
39 tutorial39/null_technique.h
View
@@ -0,0 +1,39 @@
+/*
+ Copyright 2011 Etay Meiri
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef NULL_TECHNIQUE_H
+#define NULL_TECHNIQUE_H
+
+#include "technique.h"
+#include "math_3d.h"
+
+class NullTechnique : public Technique {
+public:
+
+ NullTechnique();
+
+ virtual bool Init();
+
+ void SetWVP(const Matrix4f& WVP);
+
+private:
+
+ GLuint m_WVPLocation;
+};
+
+
+#endif
166 tutorial39/shaders/lighting.glsl
View
@@ -0,0 +1,166 @@
+struct VSInput
+{
+ vec3 Position;
+ vec2 TexCoord;
+ vec3 Normal;
+};
+
+interface VSOutput
+{
+ vec2 TexCoord;
+ vec3 Normal;
+ vec3 WorldPos;
+};
+
+struct VSOutput1
+{
+ vec2 TexCoord;
+ vec3 Normal;
+ vec3 WorldPos;
+};
+
+
+uniform mat4 gWVP;
+uniform mat4 gWorld;
+
+shader VSmain(in VSInput VSin:0, out VSOutput VSout)
+{
+ gl_Position = gWVP * vec4(VSin.Position, 1.0);
+ VSout.TexCoord = VSin.TexCoord;
+ VSout.Normal = (gWorld * vec4(VSin.Normal, 0.0)).xyz;
+ VSout.WorldPos = (gWorld * vec4(VSin.Position, 1.0)).xyz;
+}
+
+
+
+const int MAX_POINT_LIGHTS = 2;
+const int MAX_SPOT_LIGHTS = 2;
+
+
+struct BaseLight
+{
+ vec3 Color;
+ float AmbientIntensity;
+ float DiffuseIntensity;
+};
+
+struct DirectionalLight
+{
+ struct BaseLight Base;
+ vec3 Direction;
+};
+
+struct Attenuation
+{
+ float Constant;
+ float Linear;
+ float Exp;
+};
+
+struct PointLight
+{
+ struct BaseLight Base;
+ vec3 Position;
+ Attenuation Atten;
+};
+
+struct SpotLight
+{
+ struct PointLight Base;
+ vec3 Direction;
+ float Cutoff;
+};
+
+uniform int gNumPointLights;
+uniform int gNumSpotLights;
+uniform DirectionalLight gDirectionalLight;
+uniform PointLight gPointLights[MAX_POINT_LIGHTS];
+uniform SpotLight gSpotLights[MAX_SPOT_LIGHTS];
+uniform sampler2D gColorMap;
+uniform vec3 gEyeWorldPos;
+uniform float gMatSpecularIntensity;
+uniform float gSpecularPower;
+uniform vec4 gColor;
+
+vec4 CalcLightInternal(struct BaseLight Light, vec3 LightDirection, VSOutput1 In)
+{
+ vec4 AmbientColor = vec4(Light.Color, 1.0f) * Light.AmbientIntensity;
+ float DiffuseFactor = dot(In.Normal, -LightDirection);
+
+ vec4 DiffuseColor = vec4(0, 0, 0, 0);
+ vec4 SpecularColor = vec4(0, 0, 0, 0);
+
+ if (DiffuseFactor > 0) {
+ DiffuseColor = vec4(Light.Color, 1.0f) * Light.DiffuseIntensity * DiffuseFactor;
+
+ vec3 VertexToEye = normalize(gEyeWorldPos - In.WorldPos);
+ vec3 LightReflect = normalize(reflect(LightDirection, In.Normal));
+ float SpecularFactor = dot(VertexToEye, LightReflect);
+ SpecularFactor = pow(SpecularFactor, gSpecularPower);
+ if (SpecularFactor > 0) {
+ SpecularColor = vec4(Light.Color, 1.0f) *
+ gMatSpecularIntensity * SpecularFactor;
+ }
+ }
+
+ return (AmbientColor + DiffuseColor + SpecularColor);
+}
+
+vec4 CalcDirectionalLight(VSOutput1 In)
+{
+ return CalcLightInternal(gDirectionalLight.Base, gDirectionalLight.Direction, In);
+}
+
+vec4 CalcPointLight(struct PointLight l, VSOutput1 In)
+{
+ vec3 LightDirection = In.WorldPos - l.Position;
+ float Distance = length(LightDirection);
+ LightDirection = normalize(LightDirection);
+
+ vec4 Color = CalcLightInternal(l.Base, LightDirection, In);
+ float Attenuation = l.Atten.Constant +
+ l.Atten.Linear * Distance +
+ l.Atten.Exp * Distance * Distance;
+
+ return Color / Attenuation;
+}
+
+vec4 CalcSpotLight(struct SpotLight l, VSOutput1 In)
+{
+ vec3 LightToPixel = normalize(In.WorldPos - l.Base.Position);
+ float SpotFactor = dot(LightToPixel, l.Direction);
+
+ if (SpotFactor > l.Cutoff) {
+ vec4 Color = CalcPointLight(l.Base, In);
+ return Color * (1.0 - (1.0 - SpotFactor) * 1.0/(1.0 - l.Cutoff));
+ }
+ else {
+ return vec4(0,0,0,0);
+ }
+}
+
+shader FSmain(in VSOutput FSin, out vec4 FragColor)
+{
+ VSOutput1 In;
+ In.TexCoord = FSin.TexCoord;
+ In.Normal = normalize(FSin.Normal);
+ In.WorldPos = FSin.WorldPos;
+
+ vec4 TotalLight = CalcDirectionalLight(In);
+
+ for (int i = 0 ; i < gNumPointLights ; i++) {
+ TotalLight += CalcPointLight(gPointLights[i], In);
+ }
+
+ for (int i = 0 ; i < gNumSpotLights ; i++) {
+ TotalLight += CalcSpotLight(gSpotLights[i], In);
+ }
+
+ FragColor = texture(gColorMap, In.TexCoord.xy) * TotalLight + gColor;
+}
+
+program Lighting
+{
+ vs(410)=VSmain();
+ fs(410)=FSmain();
+};
16 tutorial39/shaders/null_technique.glsl
View
@@ -0,0 +1,16 @@
+uniform mat4 gWVP;
+
+shader VSmain(in vec3 Position)
+{
+ gl_Position = gWVP * vec4(Position, 1.0);
+};
+
+shader FSmain()
+{
+};
+
+program NullTechnique
+{
+ vs(410) = VSmain();
+ fs(410) = FSmain();
+};
224 tutorial39/shaders/shadow_volume.glsl
View
@@ -9,7 +9,6 @@ struct VSInput
interface VSOutput
{
- vec3 PosL;
vec2 TexCoord;
vec3 Normal;
vec3 WorldPos;
@@ -23,12 +22,12 @@ struct VSOutput1
};
uniform mat4 gWVP;
+uniform mat4 gVP;
uniform mat4 gWorld;
shader VSmain(in VSInput VSin:0, out VSOutput VSout)
{
vec4 PosL = vec4(VSin.Position, 1.0);
- VSout.PosL = VSin.Position;
gl_Position = gWVP * PosL;
VSout.TexCoord = VSin.TexCoord;
vec4 NormalL = vec4(VSin.Normal, 0.0);
@@ -38,6 +37,20 @@ shader VSmain(in VSInput VSin:0, out VSOutput VSout)
uniform vec3 gLightDir;
+void EmitQuad(int StartIndex, VSOutput1 StartVertex, int EndIndex, VSOutput1 EndVertex)
+{
+ gl_Position = gl_in[StartIndex].gl_Position;
+ EmitVertex();
+ gl_Position = gVP * vec4(StartVertex.WorldPos + gLightDir * 100.0, 1.0);
+ EmitVertex();
+ gl_Position = gl_in[EndIndex].gl_Position;
+ EmitVertex();
+ gl_Position = gVP * vec4(EndVertex.WorldPos + gLightDir * 100.0, 1.0);
+ EmitVertex();
+
+ EndPrimitive();
+}
+
shader GSmain(in VSOutput GSin[])
{
vec3 e1 = GSin[2].WorldPos - GSin[0].WorldPos;
@@ -47,187 +60,76 @@ shader GSmain(in VSOutput GSin[])
vec3 e5 = GSin[4].WorldPos - GSin[2].WorldPos;
vec3 e6 = GSin[5].WorldPos - GSin[0].WorldPos;
- vec3 n0 = normalize(cross(e1,e2));
-
- /* gl_Position = gl_in[0].gl_Position;
- EmitVertex();
+ vec3 n0 = cross(e1,e2);
- vec3 EndOfNormal = GSin[0].PosL + n0;
- gl_Position = gWVP * vec4(EndOfNormal, 1.0);
- EmitVertex();
+ // gl_Position = gl_in[0].gl_Position;
+ // EmitVertex();
- EndPrimitive();
+ // gl_Position = gl_in[2].gl_Position;
+ // EmitVertex();
- gl_Position = gl_in[0].gl_Position;
- EmitVertex();
- gl_Position = gl_in[2].gl_Position;
- EmitVertex();
- gl_Position = gl_in[4].gl_Position;
- EmitVertex();
+ // gl_Position = gl_in[4].gl_Position;
+ // EmitVertex();
+ // EndPrimitive();
- EndPrimitive();*/
+ if (dot(n0, -gLightDir) > 0.00001) {
- if (dot(n0, -gLightDir) > 0.000001) {
- vec3 n1 = normalize(cross(e3,e1));
- vec3 n2 = normalize(cross(e4,e5));
- vec3 n3 = normalize(cross(e2,e6));
+ vec3 n1 = cross(e3,e1);
+ vec3 n2 = cross(e4,e5);
+ vec3 n3 = cross(e2,e6);
if (dot(n1, -gLightDir) <= 0) {
- gl_Position = gl_in[2].gl_Position;
- EmitVertex();
- gl_Position = gl_in[0].gl_Position;
- EmitVertex();
- EndPrimitive();
+ VSOutput1 StartVertex;
+ StartVertex.TexCoord = GSin[0].TexCoord;
+ StartVertex.Normal = GSin[0].Normal;
+ StartVertex.WorldPos = GSin[0].WorldPos;
+
+ VSOutput1 EndVertex;
+ EndVertex.TexCoord = GSin[2].TexCoord;
+ EndVertex.Normal = GSin[2].Normal;
+ EndVertex.WorldPos = GSin[2].WorldPos;
+
+ EmitQuad(0, StartVertex, 2, EndVertex);
}
if (dot(n2, -gLightDir) <=0) {
- gl_Position = gl_in[4].gl_Position;
- EmitVertex();
- gl_Position = gl_in[2].gl_Position;
- EmitVertex();
- EndPrimitive();
+ VSOutput1 StartVertex;
+ StartVertex.TexCoord = GSin[2].TexCoord;
+ StartVertex.Normal = GSin[2].Normal;
+ StartVertex.WorldPos = GSin[2].WorldPos;
+
+ VSOutput1 EndVertex;
+ EndVertex.TexCoord = GSin[4].TexCoord;
+ EndVertex.Normal = GSin[4].Normal;
+ EndVertex.WorldPos = GSin[4].WorldPos;
+
+ EmitQuad(2, StartVertex, 4, EndVertex);
}
if (dot(n3, -gLightDir) <= 0) {
- gl_Position = gl_in[4].gl_Position;
- EmitVertex();
- gl_Position = gl_in[0].gl_Position;
- EmitVertex();
- EndPrimitive();
+ VSOutput1 StartVertex;
+ StartVertex.TexCoord = GSin[0].TexCoord;
+ StartVertex.Normal = GSin[0].Normal;
+ StartVertex.WorldPos = GSin[0].WorldPos;
+
+ VSOutput1 EndVertex;
+ EndVertex.TexCoord = GSin[4].TexCoord;
+ EndVertex.Normal = GSin[4].Normal;
+ EndVertex.WorldPos = GSin[4].WorldPos;
+
+ EmitQuad(0, StartVertex, 4, EndVertex);
}
}
}
-const int MAX_POINT_LIGHTS = 2;
-const int MAX_SPOT_LIGHTS = 2;
-
-struct BaseLight
-{
- vec3 Color;
- float AmbientIntensity;
- float DiffuseIntensity;
-};
-
-struct DirectionalLight
-{
- struct BaseLight Base;
- vec3 Direction;
-};
-
-struct Attenuation
-{
- float Constant;
- float Linear;
- float Exp;
-};
-
-struct PointLight
-{
- struct BaseLight Base;
- vec3 Position;
- Attenuation Atten;
-};
-
-struct SpotLight
-{
- struct PointLight Base;
- vec3 Direction;
- float Cutoff;
-};
-
-uniform int gNumPointLights;
-uniform int gNumSpotLights;
-uniform DirectionalLight gDirectionalLight;
-uniform PointLight gPointLights[MAX_POINT_LIGHTS];
-uniform SpotLight gSpotLights[MAX_SPOT_LIGHTS];
-uniform sampler2D gColorMap;
-uniform vec3 gEyeWorldPos;
-uniform float gMatSpecularIntensity;
-uniform float gSpecularPower;
-
-
-vec4 CalcLightInternal(struct BaseLight Light, vec3 LightDirection, VSOutput1 In)
-{
- vec4 AmbientColor = vec4(Light.Color, 1.0f) * Light.AmbientIntensity;
- float DiffuseFactor = dot(In.Normal, -LightDirection);
-
- vec4 DiffuseColor = vec4(0, 0, 0, 0);
- vec4 SpecularColor = vec4(0, 0, 0, 0);
-
- if (DiffuseFactor > 0) {
- DiffuseColor = vec4(Light.Color, 1.0f) * Light.DiffuseIntensity * DiffuseFactor;
-
- vec3 VertexToEye = normalize(gEyeWorldPos - In.WorldPos);
- vec3 LightReflect = normalize(reflect(LightDirection, In.Normal));
- float SpecularFactor = dot(VertexToEye, LightReflect);
- SpecularFactor = pow(SpecularFactor, gSpecularPower);
- if (SpecularFactor > 0) {
- SpecularColor = vec4(Light.Color, 1.0f) *
- gMatSpecularIntensity * SpecularFactor;
- }
- }
-
- return (AmbientColor + DiffuseColor + SpecularColor);
-}
-
-vec4 CalcDirectionalLight(VSOutput1 In)
-{
- return CalcLightInternal(gDirectionalLight.Base, gDirectionalLight.Direction, In);
-}
-
-vec4 CalcPointLight(struct PointLight l, VSOutput1 In)
-{
- vec3 LightDirection = In.WorldPos - l.Position;
- float Distance = length(LightDirection);
- LightDirection = normalize(LightDirection);
-
- vec4 Color = CalcLightInternal(l.Base, LightDirection, In);
- float Attenuation = l.Atten.Constant +
- l.Atten.Linear * Distance +
- l.Atten.Exp * Distance * Distance;
-
- return Color / Attenuation;
-}
-
-vec4 CalcSpotLight(struct SpotLight l, VSOutput1 In)
-{
- vec3 LightToPixel = normalize(In.WorldPos - l.Base.Position);
- float SpotFactor = dot(LightToPixel, l.Direction);
-
- if (SpotFactor > l.Cutoff) {
- vec4 Color = CalcPointLight(l.Base, In);
- return Color * (1.0 - (1.0 - SpotFactor) * 1.0/(1.0 - l.Cutoff));
- }
- else {
- return vec4(0,0,0,0);
- }
-}
-
-shader FSmain(in VSOutput FSin, out vec4 FragColor)
+
+shader FSmain()
{
- VSOutput1 In;
- In.TexCoord = FSin.TexCoord;
- In.Normal = normalize(FSin.Normal);
- In.WorldPos = FSin.WorldPos;
-
- vec4 TotalLight = CalcDirectionalLight(In);
-
- for (int i = 0 ; i < gNumPointLights ; i++) {
- TotalLight += CalcPointLight(gPointLights[i], In);
- }
-
- for (int i = 0 ; i < gNumSpotLights ; i++) {
- TotalLight += CalcSpotLight(gSpotLights[i], In);
- }
-
- FragColor = texture(gColorMap, In.TexCoord.xy) * TotalLight;
-
- FragColor = vec4(1.0);
}
program Lighting
{
vs(420)=VSmain();
- gs(420)=GSmain() : in(triangles_adjacency), out(line_strip, max_vertices = 10);
+ gs(420)=GSmain() : in(triangles_adjacency), out(triangle_strip, max_vertices = 10);
fs(420)=FSmain();
};
177 tutorial39/shadow_volume_technique.cpp
View
@@ -39,195 +39,30 @@ bool ShadowVolumeTechnique::Init()
return false;
}
+ m_VPLocation = GetUniformLocation("gVP");
m_WVPLocation = GetUniformLocation("gWVP");
m_WorldMatrixLocation = GetUniformLocation("gWorld");
- m_colorTextureLocation = GetUniformLocation("gColorMap");
- m_eyeWorldPosLocation = GetUniformLocation("gEyeWorldPos");
- m_dirLightLocation.Color = GetUniformLocation("gDirectionalLight.Base.Color");
- m_dirLightLocation.AmbientIntensity = GetUniformLocation("gDirectionalLight.Base.AmbientIntensity");
- m_dirLightLocation.Direction = GetUniformLocation("gDirectionalLight.Direction");
- m_dirLightLocation.DiffuseIntensity = GetUniformLocation("gDirectionalLight.Base.DiffuseIntensity");
- m_matSpecularIntensityLocation = GetUniformLocation("gMatSpecularIntensity");
- m_matSpecularPowerLocation = GetUniformLocation("gSpecularPower");
- m_numPointLightsLocation = GetUniformLocation("gNumPointLights");
- m_numSpotLightsLocation = GetUniformLocation("gNumSpotLights");
m_lightDirLocation = GetUniformLocation("gLightDir");
- if (m_dirLightLocation.AmbientIntensity == INVALID_UNIFORM_LOCATION ||
- m_WVPLocation == INVALID_UNIFORM_LOCATION ||
- m_WorldMatrixLocation == INVALID_UNIFORM_LOCATION ||
- m_colorTextureLocation == INVALID_UNIFORM_LOCATION ||
- m_eyeWorldPosLocation == INVALID_UNIFORM_LOCATION ||
- m_dirLightLocation.Color == INVALID_UNIFORM_LOCATION ||
- m_dirLightLocation.DiffuseIntensity == INVALID_UNIFORM_LOCATION ||
- m_dirLightLocation.Direction == INVALID_UNIFORM_LOCATION ||
- m_matSpecularIntensityLocation == INVALID_UNIFORM_LOCATION ||
- m_matSpecularPowerLocation == INVALID_UNIFORM_LOCATION ||
- m_numPointLightsLocation == INVALID_UNIFORM_LOCATION ||
- m_numSpotLightsLocation == INVALID_UNIFORM_LOCATION) {
- // return false;
- }
-
- for (unsigned int i = 0 ; i < ARRAY_SIZE_IN_ELEMENTS(m_pointLightsLocation) ; i++) {
- char Name[128];
- memset(Name, 0, sizeof(Name));
- snprintf(Name, sizeof(Name), "gPointLights[%d].Base.Color", i);
- m_pointLightsLocation[i].Color = GetUniformLocation(Name);
-
- snprintf(Name, sizeof(Name), "gPointLights[%d].Base.AmbientIntensity", i);
- m_pointLightsLocation[i].AmbientIntensity = GetUniformLocation(Name);
-
- snprintf(Name, sizeof(Name), "gPointLights[%d].Position", i);
- m_pointLightsLocation[i].Position = GetUniformLocation(Name);
-
- snprintf(Name, sizeof(Name), "gPointLights[%d].Base.DiffuseIntensity", i);
- m_pointLightsLocation[i].DiffuseIntensity = GetUniformLocation(Name);
-
- snprintf(Name, sizeof(Name), "gPointLights[%d].Atten.Constant", i);
- m_pointLightsLocation[i].Atten.Constant = GetUniformLocation(Name);
-
- snprintf(Name, sizeof(Name), "gPointLights[%d].Atten.Linear", i);
- m_pointLightsLocation[i].Atten.Linear = GetUniformLocation(Name);
-
- snprintf(Name, sizeof(Name), "gPointLights[%d].Atten.Exp", i);
- m_pointLightsLocation[i].Atten.Exp = GetUniformLocation(Name);
-
- if (m_pointLightsLocation[i].Color == INVALID_UNIFORM_LOCATION ||
- m_pointLightsLocation[i].AmbientIntensity == INVALID_UNIFORM_LOCATION ||
- m_pointLightsLocation[i].Position == INVALID_UNIFORM_LOCATION ||
- m_pointLightsLocation[i].DiffuseIntensity == INVALID_UNIFORM_LOCATION ||
- m_pointLightsLocation[i].Atten.Constant == INVALID_UNIFORM_LOCATION ||
- m_pointLightsLocation[i].Atten.Linear == INVALID_UNIFORM_LOCATION ||
- m_pointLightsLocation[i].Atten.Exp == INVALID_UNIFORM_LOCATION) {
- // return false;
- }
- }
-
- for (unsigned int i = 0 ; i < ARRAY_SIZE_IN_ELEMENTS(m_spotLightsLocation) ; i++) {
- char Name[128];
- memset(Name, 0, sizeof(Name));
- snprintf(Name, sizeof(Name), "gSpotLights[%d].Base.Base.Color", i);
- m_spotLightsLocation[i].Color = GetUniformLocation(Name);
-
- snprintf(Name, sizeof(Name), "gSpotLights[%d].Base.Base.AmbientIntensity", i);
- m_spotLightsLocation[i].AmbientIntensity = GetUniformLocation(Name);
-
- snprintf(Name, sizeof(Name), "gSpotLights[%d].Base.Position", i);
- m_spotLightsLocation[i].Position = GetUniformLocation(Name);
-
- snprintf(Name, sizeof(Name), "gSpotLights[%d].Direction", i);
- m_spotLightsLocation[i].Direction = GetUniformLocation(Name);
-
- snprintf(Name, sizeof(Name), "gSpotLights[%d].Cutoff", i);
- m_spotLightsLocation[i].Cutoff = GetUniformLocation(Name);
-
- snprintf(Name, sizeof(Name), "gSpotLights[%d].Base.Base.DiffuseIntensity", i);
- m_spotLightsLocation[i].DiffuseIntensity = GetUniformLocation(Name);
-
- snprintf(Name, sizeof(Name), "gSpotLights[%d].Base.Atten.Constant", i);
- m_spotLightsLocation[i].Atten.Constant = GetUniformLocation(Name);
-
- snprintf(Name, sizeof(Name), "gSpotLights[%d].Base.Atten.Linear", i);
- m_spotLightsLocation[i].Atten.Linear = GetUniformLocation(Name);
-
- snprintf(Name, sizeof(Name), "gSpotLights[%d].Base.Atten.Exp", i);
- m_spotLightsLocation[i].Atten.Exp = GetUniformLocation(Name);
-
- if (m_spotLightsLocation[i].Color == INVALID_UNIFORM_LOCATION ||
- m_spotLightsLocation[i].AmbientIntensity == INVALID_UNIFORM_LOCATION ||
- m_spotLightsLocation[i].Position == INVALID_UNIFORM_LOCATION ||
- m_spotLightsLocation[i].Direction == INVALID_UNIFORM_LOCATION ||
- m_spotLightsLocation[i].Cutoff == INVALID_UNIFORM_LOCATION ||
- m_spotLightsLocation[i].DiffuseIntensity == INVALID_UNIFORM_LOCATION ||
- m_spotLightsLocation[i].Atten.Constant == INVALID_UNIFORM_LOCATION ||
- m_spotLightsLocation[i].Atten.Linear == INVALID_UNIFORM_LOCATION ||
- m_spotLightsLocation[i].Atten.Exp == INVALID_UNIFORM_LOCATION) {
- // return false;
- }
- }
-
return true;
}
+
void ShadowVolumeTechnique::SetWVP(const Matrix4f& WVP)
{
glUniformMatrix4fv(m_WVPLocation, 1, GL_TRUE, (const GLfloat*)WVP.m);
}
-void ShadowVolumeTechnique::SetWorldMatrix(const Matrix4f& WorldInverse)
+void ShadowVolumeTechnique::SetVP(const Matrix4f& VP)
{
- glUniformMatrix4fv(m_WorldMatrixLocation, 1, GL_TRUE, (const GLfloat*)WorldInverse.m);
+ glUniformMatrix4fv(m_VPLocation, 1, GL_TRUE, (const GLfloat*)VP.m);
}
-void ShadowVolumeTechnique::SetColorTextureUnit(unsigned int TextureUnit)
-{
- glUniform1i(m_colorTextureLocation, TextureUnit);
-}
-
-
-void ShadowVolumeTechnique::SetDirectionalLight(const DirectionalLight& Light)
-{
- glUniform3f(m_dirLightLocation.Color, Light.Color.x, Light.Color.y, Light.Color.z);
- glUniform1f(m_dirLightLocation.AmbientIntensity, Light.AmbientIntensity);
- Vector3f Direction = Light.Direction;
- Direction.Normalize();
- glUniform3f(m_dirLightLocation.Direction, Direction.x, Direction.y, Direction.z);
- glUniform1f(m_dirLightLocation.DiffuseIntensity, Light.DiffuseIntensity);
-}
-
-
-void ShadowVolumeTechnique::SetEyeWorldPos(const Vector3f& EyeWorldPos)
-{
- glUniform3f(m_eyeWorldPosLocation, EyeWorldPos.x, EyeWorldPos.y, EyeWorldPos.z);
-}
-
-
-void ShadowVolumeTechnique::SetMatSpecularIntensity(float Intensity)
-{
- glUniform1f(m_matSpecularIntensityLocation, Intensity);
-}
-
-
-void ShadowVolumeTechnique::SetMatSpecularPower(float Power)
-{
- glUniform1f(m_matSpecularPowerLocation, Power);
-}
-
-
-void ShadowVolumeTechnique::SetPointLights(unsigned int NumLights, const PointLight* pLights)
-{
- glUniform1i(m_numPointLightsLocation, NumLights);
-
- for (unsigned int i = 0 ; i < NumLights ; i++) {
- glUniform3f(m_pointLightsLocation[i].Color, pLights[i].Color.x, pLights[i].Color.y, pLights[i].Color.z);
- glUniform1f(m_pointLightsLocation[i].AmbientIntensity, pLights[i].AmbientIntensity);
- glUniform1f(m_pointLightsLocation[i].DiffuseIntensity, pLights[i].DiffuseIntensity);
- glUniform3f(m_pointLightsLocation[i].Position, pLights[i].Position.x, pLights[i].Position.y, pLights[i].Position.z);
- glUniform1f(m_pointLightsLocation[i].Atten.Constant, pLights[i].Attenuation.Constant);
- glUniform1f(m_pointLightsLocation[i].Atten.Linear, pLights[i].Attenuation.Linear);
- glUniform1f(m_pointLightsLocation[i].Atten.Exp, pLights[i].Attenuation.Exp);
- }
-}
-
-void ShadowVolumeTechnique::SetSpotLights(unsigned int NumLights, const SpotLight* pLights)
+void ShadowVolumeTechnique::SetWorldMatrix(const Matrix4f& WorldInverse)
{
- glUniform1i(m_numSpotLightsLocation, NumLights);
-
- for (unsigned int i = 0 ; i < NumLights ; i++) {
- glUniform3f(m_spotLightsLocation[i].Color, pLights[i].Color.x, pLights[i].Color.y, pLights[i].Color.z);
- glUniform1f(m_spotLightsLocation[i].AmbientIntensity, pLights[i].AmbientIntensity);
- glUniform1f(m_spotLightsLocation[i].DiffuseIntensity, pLights[i].DiffuseIntensity);
- glUniform3f(m_spotLightsLocation[i].Position, pLights[i].Position.x, pLights[i].Position.y, pLights[i].Position.z);
- Vector3f Direction = pLights[i].Direction;
- Direction.Normalize();
- glUniform3f(m_spotLightsLocation[i].Direction, Direction.x, Direction.y, Direction.z);
- glUniform1f(m_spotLightsLocation[i].Cutoff, cosf(ToRadian(pLights[i].Cutoff)));
- glUniform1f(m_spotLightsLocation[i].Atten.Constant, pLights[i].Attenuation.Constant);
- glUniform1f(m_spotLightsLocation[i].Atten.Linear, pLights[i].Attenuation.Linear);
- glUniform1f(m_spotLightsLocation[i].Atten.Exp, pLights[i].Attenuation.Exp);
- }
+ glUniformMatrix4fv(m_WorldMatrixLocation, 1, GL_TRUE, (const GLfloat*)WorldInverse.m);
}
113 tutorial39/shadow_volume_technique.h
View
@@ -15,134 +15,31 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef LIGHTING_TECHNIQUE_H
-#define LIGHTING_TECHNIQUE_H
+#ifndef SHADOW_VOLUME_TECHNIQUE_H
+#define SHADOW_VOLUME_TECHNIQUE_H
#include "technique.h"
#include "math_3d.h"
-struct BaseLight
-{
- Vector3f Color;
- float AmbientIntensity;
- float DiffuseIntensity;
-
- BaseLight()
- {
- Color = Vector3f(0.0f, 0.0f, 0.0f);
- AmbientIntensity = 0.0f;
- DiffuseIntensity = 0.0f;
- }
-};
-
-struct DirectionalLight : public BaseLight
-{
- Vector3f Direction;
-
- DirectionalLight()
- {
- Direction = Vector3f(0.0f, 0.0f, 0.0f);
- }
-};
-
-struct PointLight : public BaseLight
-{
- Vector3f Position;
-
- struct
- {
- float Constant;
- float Linear;
- float Exp;
- } Attenuation;
-
- PointLight()
- {
- Position = Vector3f(0.0f, 0.0f, 0.0f);
- Attenuation.Constant = 1.0f;
- Attenuation.Linear = 0.0f;
- Attenuation.Exp = 0.0f;
- }
-};
-
-struct SpotLight : public PointLight
-{
- Vector3f Direction;
- float Cutoff;
-
- SpotLight()
- {
- Direction = Vector3f(0.0f, 0.0f, 0.0f);
- Cutoff = 0.0f;
- }
-};
-
class ShadowVolumeTechnique : public Technique {
public:
- static const uint MAX_POINT_LIGHTS = 2;
- static const uint MAX_SPOT_LIGHTS = 2;
-
ShadowVolumeTechnique();
virtual bool Init();
void SetWVP(const Matrix4f& WVP);
+ void SetVP(const Matrix4f& VP);
void SetWorldMatrix(const Matrix4f& WVP);
- void SetColorTextureUnit(uint TextureUnit);
- void SetDirectionalLight(const DirectionalLight& Light);
- void SetPointLights(uint NumLights, const PointLight* pLights);
- void SetSpotLights(uint NumLights, const SpotLight* pLights);
- void SetEyeWorldPos(const Vector3f& EyeWorldPos);
- void SetMatSpecularIntensity(float Intensity);
- void SetMatSpecularPower(float Power);
void SetLightDir(const Vector3f& Dir);
private:
GLuint m_WVPLocation;
+ GLuint m_VPLocation;
GLuint m_WorldMatrixLocation;
- GLuint m_colorTextureLocation;
- GLuint m_eyeWorldPosLocation;
- GLuint m_matSpecularIntensityLocation;
- GLuint m_matSpecularPowerLocation;
- GLuint m_numPointLightsLocation;
- GLuint m_numSpotLightsLocation;
GLuint m_lightDirLocation;
-
- struct {
- GLuint Color;
- GLuint AmbientIntensity;
- GLuint DiffuseIntensity;
- GLuint Direction;
- } m_dirLightLocation;
-
- struct {
- GLuint Color;
- GLuint AmbientIntensity;
- GLuint DiffuseIntensity;
- GLuint Position;
- struct {
- GLuint Constant;
- GLuint Linear;
- GLuint Exp;
- } Atten;
- } m_pointLightsLocation[MAX_POINT_LIGHTS];
-
- struct {
- GLuint Color;
- GLuint AmbientIntensity;
- GLuint DiffuseIntensity;
- GLuint Position;
- GLuint Direction;
- GLuint Cutoff;
- struct {
- GLuint Constant;
- GLuint Linear;
- GLuint Exp;
- } Atten;
- } m_spotLightsLocation[MAX_SPOT_LIGHTS];
};
-#endif /* LIGHTING_TECHNIQUE_H */
+#endif /* SHADOW_VOLUME_TECHNIQUE_H */
177 tutorial39/tutorial39.cpp
View
@@ -30,9 +30,11 @@
#include "camera.h"
#include "texture.h"
#include "shadow_volume_technique.h"
+#include "lighting_technique.h"
#include "glut_backend.h"
#include "mesh.h"
#include "freetypeGL.h"
+#include "null_technique.h"
using namespace std;
@@ -51,7 +53,6 @@ class Tutorial39 : public ICallbacks
Tutorial39()
{
m_pGameCamera = NULL;
- m_pEffect = NULL;
m_scale = 0.0f;
m_directionalLight.Color = Vector3f(1.0f, 1.0f, 1.0f);
m_directionalLight.AmbientIntensity = 0.55f;
@@ -66,13 +67,10 @@ class Tutorial39 : public ICallbacks
m_frameCount = 0;
m_fps = 0.0f;
-
- m_position = Vector3f(0.0f, 0.0f, 0.0f);
}
~Tutorial39()
{
- SAFE_DELETE(m_pEffect);
SAFE_DELETE(m_pGameCamera);
}
@@ -83,23 +81,30 @@ class Tutorial39 : public ICallbacks
Vector3f Up(0.0, 1.0f, 0.0f);
m_pGameCamera = new Camera(WINDOW_WIDTH, WINDOW_HEIGHT, Pos, Target, Up);
+
+ if (!m_nullTech.Init()) {
+ printf("Error initializing the null technique\n");
+ return false;
+ }
- m_pEffect = new ShadowVolumeTechnique();
+ if (!m_ShadowVolTech.Init()) {
+ printf("Error initializing the shadow volume technique\n");
+ return false;
+ }
- if (!m_pEffect->Init()) {
+ if (!m_LightingTech.Init()) {
printf("Error initializing the lighting technique\n");
return false;
}
+
+ m_LightingTech.Enable();
+
+ m_LightingTech.SetColorTextureUnit(COLOR_TEXTURE_UNIT_INDEX);
+ m_LightingTech.SetDirectionalLight(m_directionalLight);
+ m_LightingTech.SetMatSpecularIntensity(0.0f);
+ m_LightingTech.SetMatSpecularPower(0);
- m_pEffect->Enable();
-
- m_pEffect->SetColorTextureUnit(COLOR_TEXTURE_UNIT_INDEX);
- m_pEffect->SetDirectionalLight(m_directionalLight);
- m_pEffect->SetMatSpecularIntensity(0.0f);
- m_pEffect->SetMatSpecularPower(0);
- m_pEffect->SetLightDir(Vector3f(-1.0f, 0.0f, 0.0f));
-
- if (!m_mesh.LoadMesh("../../../models/box.obj")) {
+ if (!m_mesh.LoadMesh("models/box.obj")) {
printf("Mesh load failed\n");
return false;
}
@@ -110,7 +115,17 @@ class Tutorial39 : public ICallbacks
m_glutTime = glutGet(GLUT_ELAPSED_TIME);
gettimeofday(&m_startTime, NULL);
-
+
+ if (!m_quad.LoadMesh("models/quad.obj")) {
+ return false;
+ }
+
+ m_pGroundTex = new Texture(GL_TEXTURE_2D, "models/test.png");
+
+ if (!m_pGroundTex->Load()) {
+ return false;
+ }
+
return true;
}
@@ -118,35 +133,36 @@ class Tutorial39 : public ICallbacks
{
GLUTBackendRun(this);
}
-
+
virtual void RenderSceneCB()
{
CalcFPS();
- m_scale += 0.5f;
-
+ m_scale += 0.01f;
+
m_pGameCamera->OnRender();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- m_pEffect->Enable();
-
- m_pEffect->SetEyeWorldPos(m_pGameCamera->GetPos());
- Pipeline p;
- p.SetCamera(m_pGameCamera->GetPos(), m_pGameCamera->GetTarget(), m_pGameCamera->GetUp());
- p.SetPerspectiveProj(m_persProjInfo);
- // p.Scale(0.1f, 0.1f, 0.1f);
-
- Vector3f Pos(m_position);
- p.WorldPos(Pos);
- // p.Rotate(m_scale, m_scale, m_scale);
- m_pEffect->SetWVP(p.GetWVPTrans());
- m_pEffect->SetWorldMatrix(p.GetWorldTrans());
-
- m_mesh.Render();
-
+ RenderSceneIntoDepth();
+
+ glEnable(GL_STENCIL_TEST);
+
+ RenderShadowVolIntoStencil();
+
+ RenderScene();
+
+ glDisable(GL_STENCIL_TEST);
+//
+//
+// p.Scale(1.0f, 1.0f, 1.0f);
+// p.WorldPos(0.0f, 2.0f, 0.0f);
+// p.Rotate(0.0f, 0.0f, 0.0f);
+// m_LightingTech.SetWVP(p.GetWVPTrans());
+// m_LightingTech.SetWorldMatrix(p.GetWorldTrans());
+// m_mesh.Render();
+
RenderFPS();
glutSwapBuffers();
@@ -186,6 +202,86 @@ class Tutorial39 : public ICallbacks
private:
+ void RenderSceneIntoDepth()
+ {
+ glDrawBuffer(GL_NONE);
+ glEnable(GL_DEPTH_TEST);
+ glDepthMask(GL_TRUE);
+
+ m_nullTech.Enable();
+
+ Pipeline p;
+ p.SetCamera(m_pGameCamera->GetPos(), m_pGameCamera->GetTarget(), m_pGameCamera->GetUp());
+ p.SetPerspectiveProj(m_persProjInfo);
+ Vector3f Pos(0.0f, 1.0f, 0.0f);
+ p.WorldPos(Pos);
+ m_nullTech.SetWVP(p.GetWVPTrans());
+
+ m_mesh.Render();
+
+ p.Scale(10.0f, 10.0f, 10.0f);
+ p.WorldPos(0.0f, 0.0f, 0.0f);
+ p.Rotate(90.0f, 0.0f, 0.0f);
+ m_nullTech.SetWVP(p.GetWVPTrans());
+ m_quad.Render();
+
+ glDepthMask(GL_FALSE);
+ }
+
+ void RenderShadowVolIntoStencil()
+ {
+ glDisable(GL_CULL_FACE);
+
+ glClear(GL_STENCIL_BUFFER_BIT);
+
+ // We need the stencil test to be enabled but we want it
+ // to succeed always. Only the depth test matters.
+ glStencilFunc(GL_ALWAYS, 0, 0);
+
+ glStencilOpSeparate(GL_BACK, GL_KEEP, GL_INCR, GL_KEEP);
+ glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_DECR, GL_KEEP);
+
+ m_ShadowVolTech.Enable();
+
+ m_ShadowVolTech.SetLightDir(Vector3f(1.0f, -1.0f, 0.0f));
+
+ Pipeline p;
+ p.SetCamera(m_pGameCamera->GetPos(), m_pGameCamera->GetTarget(), m_pGameCamera->GetUp());
+ p.SetPerspectiveProj(m_persProjInfo);
+ // p.Scale(0.1f, 0.1f, 0.1f);
+
+ Vector3f Pos(0.0f, 1.0f, 0.0f);
+ p.WorldPos(Pos);
+ m_ShadowVolTech.SetWVP(p.GetWVPTrans());
+ m_ShadowVolTech.SetVP(p.GetVPTrans());
+ m_ShadowVolTech.SetWorldMatrix(p.GetWorldTrans());
+
+ m_mesh.Render();
+
+ glEnable(GL_CULL_FACE);
+ }
+
+ void RenderScene()
+ {
+ glDisable(GL_DEPTH_TEST);
+ glDrawBuffer(GL_BACK);
+
+ glStencilFunc(GL_NOTEQUAL, 0, 0xFF);
+
+ m_LightingTech.Enable();
+
+ Pipeline p;
+ p.SetPerspectiveProj(m_persProjInfo);
+ p.SetCamera(m_pGameCamera->GetPos(), m_pGameCamera->GetTarget(), m_pGameCamera->GetUp());
+ p.Scale(10.0f, 10.0f, 10.0f);
+ p.WorldPos(0.0f, 0.0f, 0.0f);
+ p.Rotate(90.0f, 0.0f, 0.0f);
+ m_LightingTech.SetWVP(p.GetWVPTrans());
+ m_LightingTech.SetWorldMatrix(p.GetWorldTrans());
+ m_pGroundTex->Bind(GL_TEXTURE0);
+ m_quad.Render();
+ }
+
void CalcFPS()
{
m_frameCount++;
@@ -216,12 +312,15 @@ class Tutorial39 : public ICallbacks
return RunningTime;
}
- ShadowVolumeTechnique* m_pEffect;
+ ShadowVolumeTechnique m_ShadowVolTech;
+ LightingTechnique m_LightingTech;
+ NullTechnique m_nullTech;
Camera* m_pGameCamera;
float m_scale;
DirectionalLight m_directionalLight;
Mesh m_mesh;
- Vector3f m_position;
+ Mesh m_quad;
+ Texture* m_pGroundTex;
PersProjInfo m_persProjInfo;
FontRenderer m_fontRenderer;
int m_glutTime;
@@ -235,7 +334,7 @@ int main(int argc, char** argv)
{
GLUTBackendInit(argc, argv);
- if (!GLUTBackendCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, 32, false, "Tutorial 39t m")) {
+ if (!GLUTBackendCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, 32, false, "Tutorial 39")) {
return 1;
}
Please sign in to comment.
Something went wrong with that request. Please try again.