bug fixes

This commit is contained in:
Anselme 2016-04-27 22:01:19 +02:00
parent 378806c0a0
commit 021ba006a0
9 changed files with 16 additions and 47 deletions

View File

@ -112,7 +112,7 @@ void main(void) {
#endif #endif
#ifdef AMBIENT_LIGHT #ifdef AMBIENT_LIGHT
outColor = vec4(diffuse*0.1f, 1); outColor = vec4(ambient+diffuse*0.1f, 1);
#else #else
vec3 light = phongLighting(diffuse, specular, materialNs, lightColor, normal, lightDirInView, halfVecInView); vec3 light = phongLighting(diffuse, specular, materialNs, lightColor, normal, lightDirInView, halfVecInView);
outColor = vec4(light*shadow*(1+cos(1.57 + att*1.57)), 1); outColor = vec4(light*shadow*(1+cos(1.57 + att*1.57)), 1);

View File

@ -10,9 +10,6 @@
void ForwardModule::renderGL(Camera* myCamera, Scene* scene) void ForwardModule::renderGL(Camera* myCamera, Scene* scene)
{ {
// bind target // bind target
renderTarget->bindFBO();
if(clearBeforeDrawing)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glViewport(0, 0, width, height); glViewport(0, 0, width, height);
for(const Pass &p : passes) 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;
}

View File

@ -19,10 +19,7 @@ class PhongEntity;
class ForwardModule : public Module class ForwardModule : public Module
{ {
public: public:
ForwardModule() : ForwardModule() : shaderSources(NULL)
shaderSources(NULL),
renderTarget(FrameBuffer::screen),
clearBeforeDrawing(false)
{ {
ambientLight.initAmbientLight(); ambientLight.initAmbientLight();
} }
@ -36,9 +33,6 @@ public:
void setShaderSource(ShaderSource* source); void setShaderSource(ShaderSource* source);
void compileShaders(Scene* scene); void compileShaders(Scene* scene);
void setRenderTarget(const FrameBuffer* target);
void setClearBeforeDrawing(bool clear) {clearBeforeDrawing = clear;}
private: private:
struct Pass struct Pass
{ {
@ -60,13 +54,9 @@ private:
Light ambientLight; Light ambientLight;
std::vector<Pass> passes; std::vector<Pass> passes;
ShaderSource* shaderSources; ShaderSource* shaderSources;
const FrameBuffer* renderTarget;
int width; int width;
int height; int height;
bool clearBeforeDrawing;
}; };
#endif // FORWARDMODULE_H #endif // FORWARDMODULE_H

View File

@ -3,9 +3,8 @@
class Shader; class Shader;
class Material struct Material
{ {
public:
/** /**
* @brief bindAttributes should send the material attribute to the specified shader as a uniform * @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) * if the shader is NULL, we can assume that modern opengl is not available and try to apply the material differently (glMaterial)

View File

@ -17,7 +17,7 @@ const char* const Mesh::flagStr[Mesh::NB_FLAGS] =
"TANGENT_SPACE", "TANGENT_SPACE",
"BILLBOARD", "BILLBOARD",
"SHADOWED" "SHADOWED",
"COLOR_TEXTURE", "COLOR_TEXTURE",
"ALPHA_MASK", "ALPHA_MASK",

View File

@ -6,22 +6,19 @@
class Texture; class Texture;
class PhongMaterial : public Material struct PhongMaterial : public Material
{ {
public: // TODO add setters for this
glm::vec3 ambient; glm::vec3 ambient;
glm::vec3 diffuse; glm::vec3 diffuse;
glm::vec3 specular; glm::vec3 specular;
float shininess; float shininess;
bool castShadow; bool castShadow;
private:
Texture* ambient_texture; Texture* ambient_texture;
Texture* diffuse_texture; Texture* diffuse_texture;
Texture* specular_texture; Texture* specular_texture;
Texture* normal_map; Texture* normal_map;
Texture* alpha_mask; Texture* alpha_mask;
public:
enum TextureSlots enum TextureSlots
{ {
DIFFUSE_SLOT, DIFFUSE_SLOT,
@ -50,12 +47,6 @@ public:
virtual void bindAttributes(Shader* myShader = NULL); virtual void bindAttributes(Shader* myShader = NULL);
virtual unsigned int getFlags(); 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 #endif // PHONGMATERIAL_H

View File

@ -24,7 +24,6 @@ SimplePipeline::SimplePipeline(ShaderSource *forwardSource)
{ {
ForwardModule *forward = new ForwardModule(); ForwardModule *forward = new ForwardModule();
forward->setShaderSource(forwardSource); forward->setShaderSource(forwardSource);
forward->setClearBeforeDrawing(false);
modules.push_back(forward); modules.push_back(forward);
} }
else else
@ -36,19 +35,17 @@ void SimplePipeline::renderGL(Scene *scene)
glClearColor(m_clearColor.r, m_clearColor.g, m_clearColor.b, 1); glClearColor(m_clearColor.r, m_clearColor.g, m_clearColor.b, 1);
glClearDepth(1.0); glClearDepth(1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
for(Module *m : modules) glViewport(0, 0, width, height);
{ modules[0]->renderGL(m_camera, scene);
glFinish();
m->renderGL(m_camera, scene);
}
} }
void SimplePipeline::resizeGL(int w, int h) void SimplePipeline::resizeGL(int w, int h)
{ {
width = w;
height = h;
if(m_camera != NULL) if(m_camera != NULL)
m_camera->resize(w, h); m_camera->resize(w, h);
for(Module *m : modules) modules[0]->resize(w, h);
m->resize(w, h);
} }
void SimplePipeline::refreshScene(Scene *scene) void SimplePipeline::refreshScene(Scene *scene)

View File

@ -39,6 +39,9 @@ class SimplePipeline : public Pipeline
Camera *m_camera; Camera *m_camera;
glm::vec3 m_clearColor; glm::vec3 m_clearColor;
int width;
int height;
public: public:
SimplePipeline(ShaderSource *forwardSource = NULL); SimplePipeline(ShaderSource *forwardSource = NULL);

View File

@ -2,6 +2,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <sstream> #include <sstream>
#include <iostream>
#include "shader.h" #include "shader.h"
#include "mesh.h" #include "mesh.h"
#include "light.h" #include "light.h"
@ -52,11 +53,8 @@ Shader* ShaderSource::compile(const std::vector<const char*> &defines)
{ {
std::string header = "#version 330 core"; std::string header = "#version 330 core";
for(int i=0; i<Light::NB_FLAGS; ++i) for(const char* def : defines)
{ header += "\n#define "+std::string(def);
for(const char* def : defines)
header += "\n#define "+std::string(def);
}
header += "\n#line 1\n"; header += "\n#line 1\n";