From 021ba006a0df130918a8e11d52dcfa7f44734216 Mon Sep 17 00:00:00 2001 From: Anselme Date: Wed, 27 Apr 2016 22:01:19 +0200 Subject: [PATCH] bug fixes --- shaders/forward.frag.glsl | 2 +- src/forwardmodule.cpp | 9 --------- src/forwardmodule.h | 12 +----------- src/material.h | 3 +-- src/mesh.cpp | 2 +- src/phongmaterial.h | 11 +---------- src/pipeline.cpp | 13 +++++-------- src/pipeline.h | 3 +++ src/shadersource.cpp | 8 +++----- 9 files changed, 16 insertions(+), 47 deletions(-) diff --git a/shaders/forward.frag.glsl b/shaders/forward.frag.glsl index 611109b..571c570 100644 --- a/shaders/forward.frag.glsl +++ b/shaders/forward.frag.glsl @@ -112,7 +112,7 @@ void main(void) { #endif #ifdef AMBIENT_LIGHT - outColor = vec4(diffuse*0.1f, 1); + outColor = vec4(ambient+diffuse*0.1f, 1); #else vec3 light = phongLighting(diffuse, specular, materialNs, lightColor, normal, lightDirInView, halfVecInView); outColor = vec4(light*shadow*(1+cos(1.57 + att*1.57)), 1); diff --git a/src/forwardmodule.cpp b/src/forwardmodule.cpp index 2f41af0..a1655c5 100644 --- a/src/forwardmodule.cpp +++ b/src/forwardmodule.cpp @@ -10,9 +10,6 @@ void ForwardModule::renderGL(Camera* myCamera, Scene* scene) { // bind target - renderTarget->bindFBO(); - if(clearBeforeDrawing) - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glViewport(0, 0, width, height); for(const Pass &p : passes) @@ -141,9 +138,3 @@ void ForwardModule::compileShaders(Scene* scene) } } } - -void ForwardModule::setRenderTarget(const FrameBuffer* target) -{ - if(target != NULL) - renderTarget = target; -} diff --git a/src/forwardmodule.h b/src/forwardmodule.h index 11544f8..8a9acd7 100644 --- a/src/forwardmodule.h +++ b/src/forwardmodule.h @@ -19,10 +19,7 @@ class PhongEntity; class ForwardModule : public Module { public: - ForwardModule() : - shaderSources(NULL), - renderTarget(FrameBuffer::screen), - clearBeforeDrawing(false) + ForwardModule() : shaderSources(NULL) { ambientLight.initAmbientLight(); } @@ -36,9 +33,6 @@ public: void setShaderSource(ShaderSource* source); void compileShaders(Scene* scene); - void setRenderTarget(const FrameBuffer* target); - void setClearBeforeDrawing(bool clear) {clearBeforeDrawing = clear;} - private: struct Pass { @@ -60,13 +54,9 @@ private: Light ambientLight; std::vector passes; ShaderSource* shaderSources; - - const FrameBuffer* renderTarget; int width; int height; - - bool clearBeforeDrawing; }; #endif // FORWARDMODULE_H diff --git a/src/material.h b/src/material.h index 87e92bb..c423b54 100644 --- a/src/material.h +++ b/src/material.h @@ -3,9 +3,8 @@ class Shader; -class Material +struct Material { -public: /** * @brief bindAttributes should send the material attribute to the specified shader as a uniform * if the shader is NULL, we can assume that modern opengl is not available and try to apply the material differently (glMaterial) diff --git a/src/mesh.cpp b/src/mesh.cpp index 9451a4f..720b17b 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -17,7 +17,7 @@ const char* const Mesh::flagStr[Mesh::NB_FLAGS] = "TANGENT_SPACE", "BILLBOARD", - "SHADOWED" + "SHADOWED", "COLOR_TEXTURE", "ALPHA_MASK", diff --git a/src/phongmaterial.h b/src/phongmaterial.h index 88c9b30..d8add73 100644 --- a/src/phongmaterial.h +++ b/src/phongmaterial.h @@ -6,22 +6,19 @@ class Texture; -class PhongMaterial : public Material +struct PhongMaterial : public Material { -public: // TODO add setters for this glm::vec3 ambient; glm::vec3 diffuse; glm::vec3 specular; float shininess; bool castShadow; -private: Texture* ambient_texture; Texture* diffuse_texture; Texture* specular_texture; Texture* normal_map; Texture* alpha_mask; -public: enum TextureSlots { DIFFUSE_SLOT, @@ -50,12 +47,6 @@ public: virtual void bindAttributes(Shader* myShader = NULL); virtual unsigned int getFlags(); - - void setAmbientTexture(Texture* myTexture) {ambient_texture = myTexture;} - void setDiffuseTexture(Texture* myTexture) {diffuse_texture = myTexture;} - void setSpecularTexture(Texture* myTexture) {specular_texture = myTexture;} - void setNormalMap(Texture* myNormalMap) {normal_map = myNormalMap;} - void setAlphaMask(Texture* myAlphaMask) {alpha_mask = myAlphaMask;} }; #endif // PHONGMATERIAL_H diff --git a/src/pipeline.cpp b/src/pipeline.cpp index 4693d62..490fb20 100644 --- a/src/pipeline.cpp +++ b/src/pipeline.cpp @@ -24,7 +24,6 @@ SimplePipeline::SimplePipeline(ShaderSource *forwardSource) { ForwardModule *forward = new ForwardModule(); forward->setShaderSource(forwardSource); - forward->setClearBeforeDrawing(false); modules.push_back(forward); } else @@ -36,19 +35,17 @@ void SimplePipeline::renderGL(Scene *scene) glClearColor(m_clearColor.r, m_clearColor.g, m_clearColor.b, 1); glClearDepth(1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - for(Module *m : modules) - { - glFinish(); - m->renderGL(m_camera, scene); - } + glViewport(0, 0, width, height); + modules[0]->renderGL(m_camera, scene); } void SimplePipeline::resizeGL(int w, int h) { + width = w; + height = h; if(m_camera != NULL) m_camera->resize(w, h); - for(Module *m : modules) - m->resize(w, h); + modules[0]->resize(w, h); } void SimplePipeline::refreshScene(Scene *scene) diff --git a/src/pipeline.h b/src/pipeline.h index 0251c8a..fd04b59 100644 --- a/src/pipeline.h +++ b/src/pipeline.h @@ -39,6 +39,9 @@ class SimplePipeline : public Pipeline Camera *m_camera; glm::vec3 m_clearColor; + int width; + int height; + public: SimplePipeline(ShaderSource *forwardSource = NULL); diff --git a/src/shadersource.cpp b/src/shadersource.cpp index 6a3c465..0f4b112 100644 --- a/src/shadersource.cpp +++ b/src/shadersource.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include "shader.h" #include "mesh.h" #include "light.h" @@ -52,11 +53,8 @@ Shader* ShaderSource::compile(const std::vector &defines) { std::string header = "#version 330 core"; - for(int i=0; i