From b4aa0acfdab1b5a6ab680f3fa8779e3726f002a6 Mon Sep 17 00:00:00 2001 From: Anselme Date: Mon, 30 Nov 2015 09:39:59 +0100 Subject: [PATCH] removed all deprecated classes and methods, added crappyModule for opengl 2.1 rendering --- CMakeLists.txt | 3 +- asciientity.cpp | 27 -------------- asciientity.h | 66 ---------------------------------- asciimodule.cpp | 23 ------------ asciimodule.h | 24 ------------- crappymodule.cpp | 55 ++++++++++++++++++++++++++++ crappymodule.h | 15 ++++++++ deferredmodule.h | 8 ----- forwardmodule.cpp | 9 +++-- togbuffer.frag => gbuffer.frag | 0 togbuffer.vert => gbuffer.vert | 0 lights.cpp | 20 ----------- lights.h | 30 ---------------- material.h | 7 ---- phong.vert | 52 --------------------------- phongbump.frag | 50 -------------------------- phongbump.vert | 57 ----------------------------- phongcolor.frag | 46 ------------------------ phongentity.cpp | 45 ++++------------------- phongentity.h | 7 ++-- phongmaterial.cpp | 46 +----------------------- phongmaterial.h | 14 ++------ phongmodule.cpp | 59 ------------------------------ phongmodule.h | 49 ------------------------- phongtexture.frag | 49 ------------------------- 25 files changed, 89 insertions(+), 672 deletions(-) delete mode 100644 asciientity.cpp delete mode 100644 asciientity.h delete mode 100644 asciimodule.cpp delete mode 100644 asciimodule.h create mode 100644 crappymodule.cpp create mode 100644 crappymodule.h rename togbuffer.frag => gbuffer.frag (100%) rename togbuffer.vert => gbuffer.vert (100%) delete mode 100644 lights.cpp delete mode 100644 lights.h delete mode 100644 phong.vert delete mode 100644 phongbump.frag delete mode 100644 phongbump.vert delete mode 100644 phongcolor.frag delete mode 100644 phongmodule.cpp delete mode 100644 phongmodule.h delete mode 100644 phongtexture.frag diff --git a/CMakeLists.txt b/CMakeLists.txt index ec23c9a..1117918 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,11 +14,10 @@ endif(WIN32) set(LIB_SRC_LIST framebuffer.cpp gbuffer.cpp - lights.cpp meshbuilder.cpp phongentity.cpp phongmaterial.cpp - phongmodule.cpp + crappymodule.cpp shader.cpp skyboxmodule.cpp sparrowrenderer.cpp diff --git a/asciientity.cpp b/asciientity.cpp deleted file mode 100644 index 9035a8e..0000000 --- a/asciientity.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include "asciientity.h" -#include -#include "texture.h" - -#define TEX_ID 0 - -void ASCIIMaterial::bindAttributes() -{ - shader->bindVec4(shader->getLocation("backColor"), backColor); - shader->bindVec4(shader->getLocation("fontColor"), fontColor); - if(glyphMap != NULL) - { - glyphMap->bind(TEX_ID); - shader->bindInteger(shader->getLocation("glyphMap"), TEX_ID); - } -} - -void ASCIIEntity::updateModelView() -{ - modelView = glm::translate(glm::mat4(), glm::vec3(position, 0)); - modelView = glm::scale(modelView, glm::vec3(size, 1)); -} - -void ASCIIEntity::draw(const glm::mat4 viewMatrix, const glm::mat4 projectionMatrix) -{ - -} diff --git a/asciientity.h b/asciientity.h deleted file mode 100644 index 48a1bd0..0000000 --- a/asciientity.h +++ /dev/null @@ -1,66 +0,0 @@ -#ifndef ASCIIENTITY_H -#define ASCIIENTITY_H - -#include -#include -#include -#include -#include "material.h" -#include "asciimodule.h" - -class Texture; - -#include "entity.h" - -class ASCIIMaterial : public Material -{ - Texture* glyphMap; - glm::vec4 backColor; - glm::vec4 fontColor; - -public: - ASCIIMaterial(Texture* myGlyphMap = NULL, - glm::vec4 myBackColor = glm::vec4(1, 1, 1, 0), - glm::vec4 myFontColor = glm::vec4(0)) : - glyphMap(myGlyphMap), - backColor(myBackColor), - fontColor(myFontColor) - { - shader = ASCIIModule::getShader(); - } - - virtual void bindAttributes(); -}; - -class ASCIIEntity : public Entity -{ - glm::vec2 position; - glm::vec2 size; - glm::mat4 modelView; - - ASCIIMaterial* mat; - - GLuint rows; - GLuint columns; - - char* textBuffer; - - void updateModelView(); - -public: - ASCIIEntity(int nbRows = 10, int nbColumns = 40, ASCIIMaterial* myMat = NULL) : - position(glm::vec2(0)), - size(glm::vec2(1)), - mat(myMat), - rows(nbRows), - columns(nbColumns) - { - textBuffer = new char[rows*columns]; - // TODO set all chars to ' ' - updateModelView(); - } - - virtual void draw(const glm::mat4 viewMatrix, const glm::mat4 projectionMatrix); -}; - -#endif // ASCIIENTITY_H diff --git a/asciimodule.cpp b/asciimodule.cpp deleted file mode 100644 index 77b2898..0000000 --- a/asciimodule.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include "asciimodule.h" - -Shader* ASCIIModule::shader; - -ASCIIModule::ASCIIModule() -{ - -} - -void ASCIIModule::renderGL(Camera* myCamera) -{ - -} - -Shader* ASCIIModule::getShader() -{ - return shader; -} - -void ASCIIModule::setShader(Shader* myShader) -{ - shader = myShader; -} diff --git a/asciimodule.h b/asciimodule.h deleted file mode 100644 index f99bd26..0000000 --- a/asciimodule.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef ASCIIMODULE_H -#define ASCIIMODULE_H - -#include "module.h" -#include - -class ASCIIEntity; -class Shader; - -class ASCIIModule : public Module -{ - static Shader* shader; - std::vector entities; - -public: - ASCIIModule(); - void addEntity(ASCIIEntity* myEntity); - virtual void renderGL(Camera* myCamera); - - static Shader* getShader(); - static void setShader(Shader* myShader); -}; - -#endif // ASCIIMODULE_H diff --git a/crappymodule.cpp b/crappymodule.cpp new file mode 100644 index 0000000..93af711 --- /dev/null +++ b/crappymodule.cpp @@ -0,0 +1,55 @@ +#include "crappymodule.h" +#include "shader.h" +#include "phongentity.h" +#include "camera.h" +#include "mesh.h" +#include "sparrowrenderer.h" +#include "scene.h" +#include "glassert.h" +#include + +void CrappyModule::renderGL(Camera* myCamera, Scene* scene) +{ + glAssert(glEnable(GL_LIGHTING)); + glAssert(glClearColor(0, 0.1f, 0.05f, 1.0)); + glAssert(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)); + glLoadIdentity(); + glAssert(glEnable(GL_LIGHT0)); + glAssert(glLightfv(GL_LIGHT0, GL_AMBIENT, glm::value_ptr(glm::vec4(glm::vec3(0.1f), 1)))); + glAssert(glLightfv(GL_LIGHT0, GL_POSITION, glm::value_ptr(glm::vec4(0)))); + glAssert(glLightfv(GL_LIGHT0, GL_DIFFUSE, glm::value_ptr(glm::vec4(0, 0, 0, 1)))); + glAssert(glLightfv(GL_LIGHT0, GL_SPECULAR, glm::value_ptr(glm::vec4(0, 0, 0, 1)))); + + int i=1; + for(SceneIterator* lightIt = scene->getLights(); + lightIt->isValid(); lightIt->next()) + { + Light* l = lightIt->getItem(); + glAssert(glEnable(GL_LIGHT0 + i)); + glAssert(glLightfv(GL_LIGHT0 + i, GL_AMBIENT, glm::value_ptr(glm::vec4(glm::vec3(0), 1)))); + if(l->isDirectionnal()){ + glAssert(glLightfv(GL_LIGHT0 + i, GL_POSITION, glm::value_ptr(glm::vec4(l->getDir(), 0)))); + }else{ + glAssert(glLightfv(GL_LIGHT0 + i, GL_POSITION, glm::value_ptr(glm::vec4(l->getPos(), 1)))); + } + glAssert(glLightfv(GL_LIGHT0 + i, GL_DIFFUSE, glm::value_ptr(glm::vec4(l->getColor(), 1)))); + glAssert(glLightfv(GL_LIGHT0 + i, GL_SPECULAR, glm::value_ptr(glm::vec4(l->getColor(), 1)))); + ++i; + } + + for(SceneIterator* entityIt = scene->getGeometry(); + entityIt->isValid(); entityIt->next()) + { + PhongEntity* entity = entityIt->getItem(); + glMatrixMode(GL_MODELVIEW); + glm::mat4 modelViewMatrix = myCamera->getViewMatrix() * entity->modelMatrix; + glLoadMatrixf(glm::value_ptr(modelViewMatrix)); + glMatrixMode(GL_PROJECTION); + glLoadMatrixf(glm::value_ptr(myCamera->getProjectionMatrix())); + entity->drawDisplayList(); + } + + glAssert(glDisable(GL_LIGHTING)); + for(int j=0; j +#include + +class CrappyModule : public Module +{ +public: + virtual void renderGL(Camera* myCamera, Scene* scene = NULL); + virtual bool requiresModernOpenGL() {return false;} +}; + +#endif // CRAPPYMODULE_H diff --git a/deferredmodule.h b/deferredmodule.h index 4cf32fc..183bd21 100644 --- a/deferredmodule.h +++ b/deferredmodule.h @@ -5,7 +5,6 @@ #include #include #include -#include "lights.h" class Shader; class PhongEntity; @@ -17,14 +16,7 @@ public: virtual void renderGL(Camera* myCamera, Scene* scene); private: - /*Lights::Light* dirLight; - Lights* pointLights; - GLuint dirLightLocation; - GLuint nbPointLightsLocation; - GLuint pointLightsLocation; - std::vector entities; - static Shader* shaders[NB_SHADERS];*/ }; #endif // DEFERREDMODULE_H diff --git a/forwardmodule.cpp b/forwardmodule.cpp index 45a3f96..42e167d 100644 --- a/forwardmodule.cpp +++ b/forwardmodule.cpp @@ -121,14 +121,16 @@ void ForwardModule::compileShaders(Scene* scene) for(int i=0; i* EntityIt = scene->getGeometry(); - EntityIt->isValid(); EntityIt->next()) + // get material flags + for(SceneIterator* entityIt = scene->getGeometry(); + entityIt->isValid(); entityIt->next()) { - Mesh* m = EntityIt->getItem()->getMesh(); + Mesh* m = entityIt->getItem()->getMesh(); for(Mesh::Group &g : m->indiceGroups) geometryFlags[g.material->getFlags()] = true; } + // shader compilation for(int i=0; i defines; defines.push_back(lightStr[AMBIENT_LIGHT]); + // set defines if(i & NORMAL_MAP_FLAG) defines.push_back(flagStr[NORMAL_MAP]); if(i & AMBIENT_TEXTURE_FLAG) diff --git a/togbuffer.frag b/gbuffer.frag similarity index 100% rename from togbuffer.frag rename to gbuffer.frag diff --git a/togbuffer.vert b/gbuffer.vert similarity index 100% rename from togbuffer.vert rename to gbuffer.vert diff --git a/lights.cpp b/lights.cpp deleted file mode 100644 index 695b524..0000000 --- a/lights.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include "lights.h" -#include "shader.h" - -void Lights::addLight(const glm::vec3 &myPosition, const glm::vec3 myColor) -{ - if(lights.size() < MAX_LIGHTS) - { - Light l; - l.position = myPosition; - l.color = myColor; - lights.push_back(l); - } -} - -void Lights::bind(GLuint lightsLocation, GLuint nbLocation, Shader* shader) -{ - if(lights.size() > 0) - shader->bindVec3Array(lightsLocation, (glm::vec3*)lights.data(), lights.size()*2); - shader->bindInteger(nbLocation, (GLuint)lights.size()); -} diff --git a/lights.h b/lights.h deleted file mode 100644 index 8dbe27a..0000000 --- a/lights.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef LIGHTS_H -#define LIGHTS_H - -#include -#include -#include - -#define MAX_LIGHTS 4 - -class Shader; - -class 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); - - typedef struct - { - glm::vec3 position; - glm::vec3 color; - bool shadowCaster; - // Shadowmap fbo - } Light; - -private: - std::vector lights; -}; - -#endif // LIGHTS_H diff --git a/material.h b/material.h index 6d0af72..fd1dded 100644 --- a/material.h +++ b/material.h @@ -25,15 +25,8 @@ class Shader; class Material { public: - /** - * deprecated, you should use bindAttributes(Shader*) instead - */ - virtual void bindAttributes() = 0; - virtual void bindAttributes(Shader*) = 0; virtual unsigned int getFlags() = 0; - - }; #endif // MATERIAL_H diff --git a/phong.vert b/phong.vert deleted file mode 100644 index 6874b58..0000000 --- a/phong.vert +++ /dev/null @@ -1,52 +0,0 @@ -#version 330 core - -// Matrices -uniform mat4 modelViewMatrix; -uniform mat4 MVP; -uniform mat4 normalMatrix; -uniform mat4 viewMatrix; - -uniform vec3 dirLight[2]; -uniform int nbPointLights; -uniform vec3 pointLights[8]; - -layout(location = 0)in vec3 inPosition; -layout(location = 1)in vec3 inNormal; -layout(location = 2)in vec4 inTexCoord; - -out vec3 lightDirInView[5]; -out vec3 halfVecInView[5]; - -out vec3 varNormal; -out vec2 varTexCoord; - -void computeDirectionnalLightingVectorsInView(in vec3 posInView, in vec3 lightDirInWorld, out vec3 lightDir, out vec3 halfVec){ - lightDir = mat3(viewMatrix)*lightDirInWorld; - halfVec = normalize(normalize(lightDir) - normalize(posInView)); - lightDir = normalize(lightDir); -} - -void computePointLightingVectorsInView(in vec3 posInView, in vec3 lightPosition, out vec3 lightDir, out vec3 halfVec){ - lightDir = vec3(viewMatrix*vec4(lightPosition, 1.0)) - posInView; - halfVec = normalize(lightDir - posInView); - lightDir = normalize(lightDir); -} - -void main(void) { - int i; - computeDirectionnalLightingVectorsInView(vec3(modelViewMatrix*vec4(inPosition, 1.0)), dirLight[0], lightDirInView[0], halfVecInView[0]); - for(i=1; iindiceGroups.size(); ++i) - { - PhongMaterial* mat = (PhongMaterial*)mesh->indiceGroups[i].material; - mat->bindAttributes(); - Shader* shader = mat->getShader(); - shader->bindMat4(shader->getLocation("viewMatrix"), viewMatrix); - shader->bindMat4(shader->getLocation("modelViewMatrix"), modelViewMatrix); - shader->bindMat4(shader->getLocation("normalMatrix"), normalMatrix); - shader->bindMat4(shader->getLocation("MVP"), mvp); - shader->bindVec3Array(shader->getLocation("dirLight"), (glm::vec3*)dirLight, 2); - pointLights->bind(shader->getLocation("pointLights"), shader->getLocation("nbPointLights"), shader); - drawGroup(i); - } -} - -void PhongEntity::crappyDraw(const glm::mat4 &viewMatrix, const glm::mat4 &projectionMatrix, Lights::Light* dirLight, Lights* pointLights) -{ - glMatrixMode(GL_MODELVIEW); - glm::mat4 modelViewMatrix = viewMatrix * modelMatrix; - glLoadMatrixf(glm::value_ptr(modelViewMatrix)); - glMatrixMode(GL_PROJECTION); - glLoadMatrixf(glm::value_ptr(projectionMatrix)); - glCallList(displayList); -} - void PhongEntity::modernInit(bool isDynamic) { GLenum buffer_type = isDynamic ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW; @@ -121,7 +83,7 @@ void PhongEntity::crappyInit() for(int i=0; iindiceGroups.size(); ++i) { PhongMaterial* mat = (PhongMaterial*)(mesh->indiceGroups[i].material); - mat->bindAttributes(); + mat->bindAttributes(NULL); glAssert(glBegin(GL_TRIANGLES)); for(int j=0; jindiceGroups[i].indices.size(); ++j) { @@ -185,6 +147,11 @@ void PhongEntity::drawGroup(int groupId) glAssert(glDrawElements(GL_TRIANGLES, mesh->indiceGroups[groupId].indices.size(), GL_UNSIGNED_INT, mesh->indiceGroups[groupId].indices.data())); } +void PhongEntity::drawDisplayList() +{ + glAssert(glCallList(displayList)); +} + PhongEntity* PhongEntity::clone() { PhongEntity* myClone = new PhongEntity(mesh); diff --git a/phongentity.h b/phongentity.h index d7e4000..48f6b5d 100644 --- a/phongentity.h +++ b/phongentity.h @@ -4,7 +4,6 @@ #include #include #include -#include "lights.h" class Mesh; class Material; @@ -31,14 +30,12 @@ protected: GLuint* vbo; void modernInit(bool isDynamic); - void modernDraw(const glm::mat4 &viewMatrix, const glm::mat4 &projectionMatrix, Lights::Light* dirLight, Lights* pointLights); // old opengl : GLuint displayList; void crappyInit(); - void crappyDraw(const glm::mat4 &viewMatrix, const glm::mat4 &projectionMatrix, Lights::Light* dirLight, Lights* pointLights); public: /** @@ -48,7 +45,7 @@ public: PhongEntity(Mesh* myMesh); - void draw(const glm::mat4 &viewMatrix, const glm::mat4 &projectionMatrix, Lights::Light* dirLight, Lights* pointLights); + void drawDisplayList(); void drawGroup(int groupId); // temporarily public void initGL(bool isDynamic = false); @@ -58,7 +55,7 @@ public: /** * @brief this method returns a clone of the current entity. - * The same VAO will be used to render both, so there is no need to call initGL on the clone + * The same VAO/displayList will be used to render both, so there is no need to call initGL on the clone */ PhongEntity* clone(); }; diff --git a/phongmaterial.cpp b/phongmaterial.cpp index f9ef5dc..783362a 100644 --- a/phongmaterial.cpp +++ b/phongmaterial.cpp @@ -1,51 +1,13 @@ #include "phongmaterial.h" #include "texture.h" -#include "phongmodule.h" #include "sparrowrenderer.h" #include "glassert.h" #include "shader.h" #include -void PhongMaterial::updateShader() -{ - shader = PhongModule::getShader(diffuse_texture == NULL ? PhongModule::PHONG_COLOR : PhongModule::PHONG_TEXTURE); -} - -void PhongMaterial::bindAttributes() -{ - if(SparrowRenderer::isModernOpenGLAvailable()) - { - shader->bind(); - shader->bindVec3(shader->getLocation("materialAmbient"), ambient); - shader->bindVec3(shader->getLocation("materialKd"), diffuse); - shader->bindVec3(shader->getLocation("materialKs"), specular); - shader->bindFloat(shader->getLocation("materialNs"), shininess); - if(diffuse_texture != NULL) - { - diffuse_texture->bind(DIFFUSE_TEXTURE); - shader->bindInteger(shader->getLocation("baseTexture"), DIFFUSE_TEXTURE); - } - } - else - { - glAssert(glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, glm::value_ptr(glm::vec4(ambient, 1)))); - glAssert(glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, glm::value_ptr(glm::vec4(diffuse, 1)))); - glAssert(glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, glm::value_ptr(glm::vec4(specular, 1)))); - glAssert(glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess)); - if(diffuse_texture != NULL) - diffuse_texture->bind(DIFFUSE_TEXTURE); - else - { - GLenum texSlot = GL_TEXTURE0+DIFFUSE_TEXTURE; - glAssert(glActiveTexture(texSlot)); - glAssert(glBindTexture(GL_TEXTURE_2D, 0)); - } - } -} - void PhongMaterial::bindAttributes(Shader* myShader) { - if(SparrowRenderer::isModernOpenGLAvailable()) + if(SparrowRenderer::isModernOpenGLAvailable() && myShader != NULL) { // TODO store the attributes location (in the shader class maybe) myShader->bindFloat(myShader->getLocation("materialNs"), shininess); @@ -112,12 +74,6 @@ unsigned int PhongMaterial::getFlags() return flags; } -void PhongMaterial::setTexture(Texture* myTexture) -{ - setDiffuseTexture(myTexture); - updateShader(); -} - void PhongMaterial::setAmbientTexture(Texture* myTexture) { ambient_texture = myTexture; diff --git a/phongmaterial.h b/phongmaterial.h index f86da70..28e5fdb 100644 --- a/phongmaterial.h +++ b/phongmaterial.h @@ -27,9 +27,7 @@ public: diffuse_texture(NULL), specular_texture(NULL), normal_map(NULL) - { - updateShader(); - } + {} PhongMaterial(glm::vec3 myKd, glm::vec3 myKs, float myNs) : ambient(0), @@ -40,13 +38,9 @@ public: diffuse_texture(NULL), specular_texture(NULL), normal_map(NULL) - { - updateShader(); - } + {} - virtual void bindAttributes(); - - virtual void bindAttributes(Shader* myShader); + virtual void bindAttributes(Shader* myShader = NULL); virtual unsigned int getFlags(); Shader* getShader() {return shader;} @@ -61,8 +55,6 @@ public: void setSpecularTexture(Texture* myTexture); void setNormalMap(Texture* myNormalMap); - void updateShader(); - private: Shader* shader; }; diff --git a/phongmodule.cpp b/phongmodule.cpp deleted file mode 100644 index 2d1838e..0000000 --- a/phongmodule.cpp +++ /dev/null @@ -1,59 +0,0 @@ -#include "phongmodule.h" -#include "lights.h" -#include "shader.h" -#include "phongentity.h" -#include "camera.h" -#include "mesh.h" -#include "sparrowrenderer.h" -#include "glassert.h" -#include - -Shader* PhongModule::shaders[NB_SHADERS] = {0, 0}; - -PhongModule::PhongModule(Lights::Light* myDirLight, Lights* myPointLights) : - dirLight(myDirLight), - pointLights(myPointLights) -{ - if(!SparrowRenderer::isModernOpenGLAvailable()) - { - glAssert(glEnable(GL_LIGHTING)); - glAssert(glEnable(GL_LIGHT0)); - glAssert(glLightfv(GL_LIGHT0, GL_AMBIENT, glm::value_ptr(glm::vec4(glm::vec3(0.1f), 1)))); - glAssert(glLightfv(GL_LIGHT0, GL_POSITION, glm::value_ptr(glm::vec4(dirLight->position, 0)))); - // TODO add point lights - } -} - -void PhongModule::addEntity(PhongEntity* myEntity) -{ - entities.push_back(myEntity); -} - -void PhongModule::clearEntities() -{ - entities.clear(); -} - -void PhongModule::renderGL(Camera* myCamera, Scene* scene) -{ - glAssert(glClearColor(0, 0, 0, 1.0)); - glAssert(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)); - if(!SparrowRenderer::isModernOpenGLAvailable()) - { - glLoadIdentity(); - glAssert(glLightfv(GL_LIGHT0, GL_DIFFUSE, glm::value_ptr(glm::vec4(dirLight->color, 1)))); - glAssert(glLightfv(GL_LIGHT0, GL_SPECULAR, glm::value_ptr(glm::vec4(dirLight->color, 1)))); - } - for(PhongEntity* e : entities) - e->draw(myCamera->getViewMatrix(), myCamera->getProjectionMatrix(), dirLight, pointLights); -} - -void PhongModule::setShader(ShaderType slot, Shader* myShader) -{ - shaders[slot] = myShader; -} - -Shader* PhongModule::getShader(ShaderType slot) -{ - return shaders[slot]; -} diff --git a/phongmodule.h b/phongmodule.h deleted file mode 100644 index 44e53e3..0000000 --- a/phongmodule.h +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef PHONGMODULE_H -#define PHONGMODULE_H - -#include "module.h" -#include -#include -#include -#include "lights.h" - -class Shader; -class PhongEntity; - -class PhongModule : public Module -{ -public: - enum ShaderType { - PHONG_COLOR, // rendering untextured mesh - PHONG_TEXTURE, // rendering textured mesh - //TODO : rendering bump mapped mesh - NB_SHADERS - }; - - PhongModule(Lights::Light* myDirLight, Lights* myPointLights); - - void addEntity(PhongEntity* myEntity); - void clearEntities(); - - virtual void renderGL(Camera* myCamera, Scene* scene = NULL); - virtual bool requiresModernOpenGL() {return false;} - - // modern opengl methods - - /** - * @brief all used shaders shall be provided through this method before rendering - */ - static void setShader(ShaderType slot, Shader* myShader); - static Shader* getShader(ShaderType slot); -private: - Lights::Light* dirLight; - Lights* pointLights; - GLuint dirLightLocation; - GLuint nbPointLightsLocation; - GLuint pointLightsLocation; - std::vector entities; - - static Shader* shaders[NB_SHADERS]; -}; - -#endif // PHONGMODULE_H diff --git a/phongtexture.frag b/phongtexture.frag deleted file mode 100644 index edcf858..0000000 --- a/phongtexture.frag +++ /dev/null @@ -1,49 +0,0 @@ -#version 330 core - -// material -uniform vec3 materialAmbient; -uniform vec3 materialKd; -uniform vec3 materialKs; -uniform float materialNs; - -uniform vec3 dirLight[2]; -uniform int nbPointLights; -uniform vec3 pointLights[8]; - -// texture -uniform sampler2D baseTexture; - -// fragment -in vec3 varNormal; -in vec2 varTexCoord; - -in vec3 lightDirInView[5]; -in vec3 halfVecInView[5]; - -// resultat -layout(location = 0)out vec4 outColor; - -// -------------------- - -vec3 computeLight(in vec3 kd, in vec3 ks, in float ns, in vec3 color, in vec3 normal, in vec3 lightDir, in vec3 halfVec){ - float diffuse = 0; - float specular = 0; - - diffuse = dot(normal, lightDir); - diffuse = diffuse < 0 ? 0 : diffuse; - specular = dot(halfVec, normal); - specular = specular < 0 ? 0 : specular; - - return color*diffuse*(kd+ks*pow(specular, ns)); -} - -void main(void) { - int i; - vec3 kd = vec3(texture2D(baseTexture, varTexCoord))*materialKd; - vec3 light = 0.1*kd + computeLight(kd, materialKs, materialNs, dirLight[1], varNormal, lightDirInView[0], halfVecInView[0]); - for(i=1; i