From fc9eb93c75d8173506fcea484876f628acbb43c0 Mon Sep 17 00:00:00 2001 From: Anselme Date: Thu, 6 Aug 2015 14:25:17 +0200 Subject: [PATCH] only one directionnal light is allowed now, phongEntity now handles the mesh's opengl initialization --- lights.h | 9 +++++---- phong.frag | 15 ++++++--------- phong.vert | 21 +++++++++++---------- phongentity.cpp | 6 ++++++ phongentity.h | 3 ++- phongmodule.cpp | 9 ++++----- phongmodule.h | 9 ++++----- 7 files changed, 38 insertions(+), 34 deletions(-) diff --git a/lights.h b/lights.h index 76e5175..f3af153 100644 --- a/lights.h +++ b/lights.h @@ -11,17 +11,18 @@ class Shader; class Lights { -private: +public: + void addLight(const glm::vec3 &myPosition = glm::vec3(0), const glm::vec3 myColor = glm::vec3(1)); + void bind(GLuint lightsLocation, GLuint nbLocation, Shader* shader); + typedef struct { glm::vec3 position; glm::vec3 color; } Light; +private: std::vector lights; -public: - void addLight(const glm::vec3 &myPosition = glm::vec3(0), const glm::vec3 myColor = glm::vec3(1)); - void bind(GLuint lightsLocation, GLuint nbLocation, Shader* shader); }; #endif // LIGHT_H diff --git a/phong.frag b/phong.frag index 194c649..7dd50ba 100644 --- a/phong.frag +++ b/phong.frag @@ -5,8 +5,7 @@ uniform vec3 materialKd; uniform vec3 materialKs; uniform float materialNs; -uniform int nbDirLights; -uniform vec3 dirLights[8]; +uniform vec3 dirLight[2]; uniform int nbPointLights; uniform vec3 pointLights[8]; @@ -17,8 +16,8 @@ uniform sampler2D baseTexture; in vec3 varNormal; in vec2 varTexCoord; -in vec3 lightDirInView[4]; -in vec3 halfVecInView[4]; +in vec3 lightDirInView[5]; +in vec3 halfVecInView[5]; // resultat layout(location = 0)out vec4 outColor; @@ -40,11 +39,9 @@ vec3 computeLight(in vec3 kd, in vec3 ks, in float ns, in vec3 color, in vec3 no void main(void) { int i; vec3 kd = vec3(texture2D(baseTexture, varTexCoord)); - vec3 light = 0.1*kd; - for(i=0; iindiceGroups.size(); // create VBOs + vbo = new GLuint[nb_buffers](); glAssert(glGenBuffers(nb_buffers, vbo)); for(const Mesh::Group &g : mesh->indiceGroups) diff --git a/phongentity.h b/phongentity.h index f6620f4..9acf5f2 100644 --- a/phongentity.h +++ b/phongentity.h @@ -13,7 +13,7 @@ class Shader; class PhongEntity : public Entity { -private: +protected: enum { // required buffers POSITION_BUFFER, @@ -34,6 +34,7 @@ public: glm::mat4 modelMatrix; PhongEntity(Mesh* myMesh); + ~PhongEntity(); virtual void draw(const glm::mat4 viewMatrix, const glm::mat4 projectionMatrix); diff --git a/phongmodule.cpp b/phongmodule.cpp index f47eab5..01ea8c1 100644 --- a/phongmodule.cpp +++ b/phongmodule.cpp @@ -5,13 +5,12 @@ #include "phongentity.h" #include "camera.h" -PhongModule::PhongModule(Lights* myDirLights, Lights* myPointLights) : - dirLights(myDirLights), +PhongModule::PhongModule(Lights::Light* myDirLight, Lights* myPointLights) : + dirLight(myDirLight), pointLights(myPointLights), shader(ResourceBase::getShader("phong")) { - nbDirLightsLocation = shader->getLocation("nbDirLights"); - dirLightsLocation = shader->getLocation("dirLights"); + dirLightLocation = shader->getLocation("dirLight"); nbPointLightsLocation = shader->getLocation("nbPointLights"); pointLightsLocation = shader->getLocation("pointLights"); } @@ -24,7 +23,7 @@ void PhongModule::addEntity(PhongEntity* myEntity) void PhongModule::renderGL(Camera* myCamera) { shader->bind(); - dirLights->bind(dirLightsLocation, nbDirLightsLocation, shader); + shader->bindVec3Array(dirLightLocation, (glm::vec3*)dirLight, 2); pointLights->bind(pointLightsLocation, nbPointLightsLocation, shader); for(PhongEntity* e : entities) e->draw(myCamera->getViewMatrix(), myCamera->getProjectionMatrix()); diff --git a/phongmodule.h b/phongmodule.h index 038494d..aea88ce 100644 --- a/phongmodule.h +++ b/phongmodule.h @@ -5,18 +5,17 @@ #include #include #include +#include "lights.h" class Shader; class PhongEntity; -class Lights; class PhongModule : public Module { private: - Lights* dirLights; + Lights::Light* dirLight; Lights* pointLights; - GLuint nbDirLightsLocation; - GLuint dirLightsLocation; + GLuint dirLightLocation; GLuint nbPointLightsLocation; GLuint pointLightsLocation; @@ -24,7 +23,7 @@ private: std::vector entities; public: - PhongModule(Lights* myDirLights, Lights* myPointLights); + PhongModule(Lights::Light* myDirLight, Lights* myPointLights); void addEntity(PhongEntity* myEntity);