merged branch
This commit is contained in:
commit
e95212468f
@ -14,7 +14,8 @@ endif(WIN32)
|
||||
set(LIB_SRC_LIST
|
||||
asciientity.cpp
|
||||
asciimodule.cpp
|
||||
framebuffer.cpp
|
||||
framebuffer.cpp
|
||||
gbuffer.cpp
|
||||
lights.cpp
|
||||
meshbuilder.cpp
|
||||
phongentity.cpp
|
||||
@ -25,8 +26,10 @@ set(LIB_SRC_LIST
|
||||
sparrowrenderer.cpp
|
||||
parametricmesh.cpp
|
||||
texture.cpp
|
||||
scene.cpp
|
||||
scene.cpp
|
||||
entityloader.cpp
|
||||
deferredmodule.cpp
|
||||
shadersource.cpp
|
||||
)
|
||||
|
||||
set(LIBRARY_NAME ${PROJECT_NAME})
|
||||
@ -38,8 +41,14 @@ set(LIB_ROOT ${DEPENDENCIES_ROOT}/lib/${SYSTEM_LIB_PATH})
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIB_ROOT}) #for SHARED
|
||||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIB_ROOT}) #for STATIC
|
||||
|
||||
add_library(${LIBRARY_NAME} STATIC ${LIB_SRC_LIST})
|
||||
add_definitions(-std=c++11)
|
||||
if(CMAKE_BUILD_TYPE MATCHES "Debug")
|
||||
set(CPP_DEFINES -DRENDER_DEBUG)
|
||||
endif()
|
||||
|
||||
file(GLOB LIBRARY_RES_FILES *.h *.frag *.vert)
|
||||
|
||||
add_library(${LIBRARY_NAME} STATIC ${LIB_SRC_LIST} ${LIBRARY_RES_FILES})
|
||||
add_definitions(-std=c++11 ${CPP_DEFINES})
|
||||
|
||||
include_directories(
|
||||
${INCLUDE_ROOT}
|
||||
|
1
deferredmodule.cpp
Normal file
1
deferredmodule.cpp
Normal file
@ -0,0 +1 @@
|
||||
#include "deferredmodule.h"
|
34
deferredmodule.h
Normal file
34
deferredmodule.h
Normal file
@ -0,0 +1,34 @@
|
||||
#ifndef DEFERREDMODULE_H
|
||||
#define DEFERREDMODULE_H
|
||||
|
||||
#include "module.h"
|
||||
#include <vector>
|
||||
#include <cstddef>
|
||||
#include <glew/glew.h>
|
||||
#include "lights.h"
|
||||
|
||||
class Shader;
|
||||
class PhongEntity;
|
||||
|
||||
class DeferredModule : public Module
|
||||
{
|
||||
public:
|
||||
DeferredModule(Lights::Light* myDirLight, Lights* myPointLights);
|
||||
|
||||
//void addEntity(PhongEntity* myEntity);
|
||||
//void clearEntities();
|
||||
|
||||
virtual void renderGL(Camera* myCamera) = 0;
|
||||
virtual bool requiresModernOpenGL() {return true;}
|
||||
private:
|
||||
/*Lights::Light* dirLight;
|
||||
Lights* pointLights;
|
||||
GLuint dirLightLocation;
|
||||
GLuint nbPointLightsLocation;
|
||||
GLuint pointLightsLocation;
|
||||
std::vector<PhongEntity*> entities;
|
||||
|
||||
static Shader* shaders[NB_SHADERS];*/
|
||||
};
|
||||
|
||||
#endif // DEFERREDMODULE_H
|
@ -1,7 +0,0 @@
|
||||
#include "entityloader.h"
|
||||
|
||||
EntityLoader::EntityLoader()
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -1,10 +0,0 @@
|
||||
#ifndef ENTITYLOADER_H
|
||||
#define ENTITYLOADER_H
|
||||
|
||||
class EntityLoader
|
||||
{
|
||||
public:
|
||||
EntityLoader();
|
||||
};
|
||||
|
||||
#endif // ENTITYLOADER_H
|
56
gbuffer.cpp
Normal file
56
gbuffer.cpp
Normal file
@ -0,0 +1,56 @@
|
||||
#include "gbuffer.h"
|
||||
#include "sparrowrenderer.h"
|
||||
#include "glassert.h"
|
||||
|
||||
GBuffer::GBuffer(int width, int height)
|
||||
{
|
||||
glAssert(glGenFramebuffers(1, &fbo));
|
||||
glAssert(glBindFramebuffer(GL_FRAMEBUFFER, fbo));
|
||||
|
||||
// - Normal buffer
|
||||
glAssert(glGenTextures(1, textures + NORMAL));
|
||||
glAssert(glBindTexture(GL_TEXTURE_2D, textures[NORMAL]));
|
||||
glAssert(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, width, height, 0, GL_RGB, GL_FLOAT, NULL));
|
||||
glAssert(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
|
||||
glAssert(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST));
|
||||
glAssert(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[NORMAL], 0));
|
||||
|
||||
// - Color + Specular exponent buffer
|
||||
glAssert(glGenTextures(1, textures + COLOR));
|
||||
glAssert(glBindTexture(GL_TEXTURE_2D, textures[COLOR]));
|
||||
glAssert(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL));
|
||||
glAssert(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
|
||||
glAssert(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST));
|
||||
glAssert(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, textures[COLOR], 0));
|
||||
|
||||
// - Specular color + objectId buffer
|
||||
glAssert(glGenTextures(1, textures + SPECULAR));
|
||||
glAssert(glBindTexture(GL_TEXTURE_2D, textures[SPECULAR]));
|
||||
glAssert(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL));
|
||||
glAssert(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
|
||||
glAssert(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST));
|
||||
glAssert(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_TEXTURE_2D, textures[SPECULAR], 0));
|
||||
|
||||
// - depth buffer
|
||||
glAssert(glGenTextures(1, textures + DEPTH));
|
||||
glAssert(glBindTexture(GL_TEXTURE_2D, textures[DEPTH]));
|
||||
glAssert(glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL));
|
||||
glAssert(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
|
||||
glAssert(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST));
|
||||
glAssert(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, textures[DEPTH], 0));
|
||||
|
||||
// - Tell OpenGL which color attachments we'll use (of this framebuffer) for rendering
|
||||
GLuint attachments[4] = {GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_DEPTH_ATTACHMENT};
|
||||
glAssert(glDrawBuffers(4, attachments));
|
||||
}
|
||||
|
||||
void GBuffer::bind()
|
||||
{
|
||||
glAssert(glBindFramebuffer(GL_FRAMEBUFFER, fbo));
|
||||
}
|
||||
|
||||
void GBuffer::bindTexture(TextureType type, int slot)
|
||||
{
|
||||
glAssert(glActiveTexture(GL_TEXTURE0 + slot));
|
||||
glAssert(glBindTexture(GL_TEXTURE_2D, textures[type]));
|
||||
}
|
26
gbuffer.h
Normal file
26
gbuffer.h
Normal file
@ -0,0 +1,26 @@
|
||||
#ifndef GBUFFER_H
|
||||
#define GBUFFER_H
|
||||
|
||||
#include <glew/glew.h>
|
||||
|
||||
class GBuffer
|
||||
{
|
||||
// fbo
|
||||
GLuint fbo;
|
||||
// textures
|
||||
enum TextureType
|
||||
{
|
||||
NORMAL,
|
||||
COLOR,
|
||||
SPECULAR,
|
||||
DEPTH,
|
||||
NB_TEXTURES
|
||||
};
|
||||
GLuint textures[NB_TEXTURES];
|
||||
public:
|
||||
GBuffer(int width, int height);
|
||||
void bind();
|
||||
void bindTexture(TextureType type, int slot);
|
||||
};
|
||||
|
||||
#endif // GBUFFER_H
|
@ -10,6 +10,7 @@
|
||||
#include <iostream>
|
||||
#include <cassert>
|
||||
|
||||
#ifdef RENDER_DEBUG
|
||||
#define STR(x) #x
|
||||
#define glAssert(code) \
|
||||
code; \
|
||||
@ -19,6 +20,9 @@
|
||||
std::cerr<<"Erreur OpenGL ("<<__FILE__<<":"<<__LINE__<<", "<<STR(code)<<") : "<<(const char*)gluErrorString (err)<<"("<<err<<")"<<std::endl; \
|
||||
} \
|
||||
}
|
||||
#else
|
||||
#define glAssert(code) code;
|
||||
#endif
|
||||
|
||||
#endif // GLASSERT
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "meshbuilder.h"
|
||||
#include <glm/ext.hpp>
|
||||
|
||||
void MeshBuilder::addPosition(float x, float y, float z)
|
||||
{
|
||||
@ -80,6 +81,24 @@ int MeshBuilder::getNbGroups()
|
||||
return indiceGroups.size();
|
||||
}
|
||||
|
||||
void MeshBuilder::computeNormals()
|
||||
{
|
||||
normals.resize(positions.size());
|
||||
for(const Group &g : indiceGroups)
|
||||
for (int i=0; i < g.indices.size(); i += 3)
|
||||
{
|
||||
int v0 = g.indices[i];
|
||||
int v1 = g.indices[i+1];
|
||||
int v2 = g.indices[i+2];
|
||||
glm::vec3 n = glm::cross(positions[v1] - positions[v0], positions[v2] - positions[v0]);
|
||||
normals[v0] += n;
|
||||
normals[v1] += n;
|
||||
normals[v2] += n;
|
||||
}
|
||||
for(glm::vec3 &n : normals)
|
||||
n = glm::normalize(n);
|
||||
}
|
||||
|
||||
void MeshBuilder::computeTangents()
|
||||
{
|
||||
if(!hasTexCoords())
|
||||
|
@ -26,6 +26,8 @@ public:
|
||||
void setCurrentGroupMaterial(Material* myMaterial);
|
||||
int getNbGroups();
|
||||
|
||||
// require positions and indices
|
||||
void computeNormals();
|
||||
// require normals and texCoord
|
||||
void computeTangents();
|
||||
};
|
||||
|
46
modules.todo
46
modules.todo
@ -1,14 +1,54 @@
|
||||
FBOs :
|
||||
image éclairée
|
||||
shadowmap
|
||||
g-buffer
|
||||
|
||||
Scene nodes :
|
||||
geometry : PHONG, NORMAL_MAP, DIFFUSE_TEXTURE, SPECULAR_TEXTURE, ALPHA_MASK
|
||||
light source : LIGHT, SHADOW_MAP, SHADOW_CUBEMAP
|
||||
|
||||
Modules :
|
||||
|
||||
- bump mapping module
|
||||
- forward (compatible crappy)
|
||||
IN :
|
||||
for sources
|
||||
for geometry
|
||||
OUT :
|
||||
image éclairée
|
||||
|
||||
- deferred
|
||||
IN :
|
||||
gbuffer
|
||||
for sources
|
||||
OUT :
|
||||
image éclairée
|
||||
|
||||
- gbuffer
|
||||
IN :
|
||||
for géométrie
|
||||
OUT :
|
||||
gbuffer
|
||||
|
||||
- shadowmap
|
||||
IN :
|
||||
for géométrie
|
||||
source
|
||||
OUT :
|
||||
shadowmap
|
||||
|
||||
- post effects
|
||||
IN :
|
||||
image éclairée
|
||||
OUT :
|
||||
image traitée
|
||||
|
||||
futres implémentations ?
|
||||
|
||||
- billboard module
|
||||
- particles module
|
||||
|
||||
- text/gui module
|
||||
|
||||
- shadowmap module
|
||||
|
||||
- heat wave module
|
||||
- mirror module
|
||||
- wave + mirror = water module
|
||||
|
@ -193,4 +193,5 @@ PhongEntity* PhongEntity::clone()
|
||||
myClone->nb_buffers = nb_buffers;
|
||||
myClone->vao = vao;
|
||||
myClone->vbo = vbo;
|
||||
return myClone;
|
||||
}
|
||||
|
80
shadersource.cpp
Normal file
80
shadersource.cpp
Normal file
@ -0,0 +1,80 @@
|
||||
#include "shadersource.h"
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include "shader.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
ShaderSource::ShaderSource()
|
||||
{
|
||||
for(int i=0; i<NB_TYPES; ++i)
|
||||
sources[i] = NULL;
|
||||
}
|
||||
|
||||
ShaderSource::~ShaderSource()
|
||||
{
|
||||
for(int i=0; i<NB_TYPES; ++i)
|
||||
if(sources[i] != NULL)
|
||||
delete(sources[i]);
|
||||
}
|
||||
|
||||
void ShaderSource::addSource(const char *source, SourceType type)
|
||||
{
|
||||
if(sources[type] != NULL)
|
||||
delete(sources[type]);
|
||||
sources[type] = new std::string(source);
|
||||
}
|
||||
|
||||
Shader* ShaderSource::compile(int nbDefines, const char** defines)
|
||||
{
|
||||
if(sources[VERTEX] == NULL || sources[FRAGMENT] == NULL)
|
||||
return NULL;
|
||||
std::string compiledSources[NB_TYPES];
|
||||
for(int i=0; i<NB_TYPES; ++i)
|
||||
{
|
||||
if(sources[i] == NULL)
|
||||
continue;
|
||||
compiledSources[i] = preprocess(*(sources[i]), nbDefines, defines);
|
||||
}
|
||||
if(sources[GEOMETRY] != NULL)
|
||||
return new Shader(compiledSources[VERTEX], compiledSources[GEOMETRY], compiledSources[FRAGMENT]);
|
||||
else
|
||||
return new Shader(compiledSources[VERTEX], compiledSources[FRAGMENT]);
|
||||
}
|
||||
|
||||
bool isDefined(const std::string &str, int nbDefines, const char** defines)
|
||||
{
|
||||
for(int i=0; i<nbDefines; ++i)
|
||||
{
|
||||
if(str.compare(defines[i]) == 0)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string ShaderSource::preprocess(std::string source, int nbDefines, const char** defines)
|
||||
{
|
||||
std::string compiled = "";
|
||||
std::istringstream ss(source);
|
||||
std::string line;
|
||||
bool allowed = true;
|
||||
while (std::getline(ss, line)) {
|
||||
if(line.size() > 0 && line.at(0) == '#')
|
||||
{
|
||||
if(line.compare(0, 8, "#version") == 0)
|
||||
compiled.append(line+'\n');
|
||||
else if(line.compare(0, 7, "#ifdef ") == 0)
|
||||
allowed = isDefined(line.substr(7), nbDefines, defines);
|
||||
else if(line.compare(0, 8, "#ifndef ") == 0)
|
||||
allowed = !isDefined(line.substr(8), nbDefines, defines);
|
||||
else if(line.compare("#endif") == 0)
|
||||
allowed = true;
|
||||
else if(line.compare("#else") == 0)
|
||||
allowed = !allowed;
|
||||
}
|
||||
else if(allowed)
|
||||
compiled.append(line+'\n');
|
||||
}
|
||||
std::cout << compiled << std::endl;
|
||||
return compiled;
|
||||
}
|
32
shadersource.h
Normal file
32
shadersource.h
Normal file
@ -0,0 +1,32 @@
|
||||
#ifndef SHADERSOURCE_H
|
||||
#define SHADERSOURCE_H
|
||||
|
||||
#include <string>
|
||||
|
||||
class Shader;
|
||||
|
||||
class ShaderSource
|
||||
{
|
||||
public:
|
||||
enum SourceType
|
||||
{
|
||||
VERTEX,
|
||||
GEOMETRY,
|
||||
FRAGMENT,
|
||||
NB_TYPES
|
||||
};
|
||||
|
||||
ShaderSource();
|
||||
~ShaderSource();
|
||||
|
||||
void addSource(const char *source, SourceType type);
|
||||
|
||||
Shader* compile(int nbDefines = 0, const char** defines = NULL);
|
||||
|
||||
private:
|
||||
std::string* sources[NB_TYPES];
|
||||
|
||||
std::string preprocess(std::string source, int nbDefines, const char** defines);
|
||||
};
|
||||
|
||||
#endif // SHADERSOURCE_H
|
62
togbuffer.frag
Normal file
62
togbuffer.frag
Normal file
@ -0,0 +1,62 @@
|
||||
#version 330 core
|
||||
layout (location = 0) out vec3 outNormal;
|
||||
layout (location = 1) out vec4 outColor;
|
||||
layout (location = 2) out vec4 outSpecular;
|
||||
|
||||
uniform float materialNs;
|
||||
uniform int objectId;
|
||||
|
||||
#ifdef ALPHA_MASK
|
||||
uniform sampler2D alphaMask;
|
||||
#endif
|
||||
|
||||
#ifdef DIFFUSE_TEXTURE
|
||||
uniform sampler2D diffuseTexture;
|
||||
#else
|
||||
uniform vec3 materialKd;
|
||||
#endif
|
||||
|
||||
#ifdef SPECULAR_TEXTURE
|
||||
uniform sampler2D specularTexture;
|
||||
#else
|
||||
uniform vec3 materialKs;
|
||||
#endif
|
||||
|
||||
#ifdef NORMAL_MAP
|
||||
uniform sampler2D normalMap;
|
||||
|
||||
in mat3 tangentSpace;
|
||||
#else
|
||||
in vec3 varNormal;
|
||||
#endif
|
||||
|
||||
in vec2 varTexCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
#ifdef ALPHA_MASK
|
||||
if(texture(alphaMask, varTexCoord).r < 0.5)
|
||||
discard;
|
||||
#endif
|
||||
|
||||
#ifdef NORMAL_MAP
|
||||
vec3 varNormal = texture(normalMap, varTexCoord).xyz * tangentSpace;
|
||||
#endif
|
||||
outNormal = normalize(varNormal);
|
||||
|
||||
#ifdef DIFFUSE_TEXTURE
|
||||
outColor.rgb = texture(diffuseTexture, varTexCoord).rgb;
|
||||
#else
|
||||
outColor.rgb = materialKd;
|
||||
#endif
|
||||
|
||||
outColor.a = materialNs;
|
||||
|
||||
#ifdef SPECULAR_TEXTURE
|
||||
outSpecular.rgb = texture(specularTexture, varTexCoord).rgb;
|
||||
#else
|
||||
outSpecular.rgb = materialKs;
|
||||
#endif
|
||||
|
||||
outSpecular.a = objectId;
|
||||
}
|
41
togbuffer.vert
Normal file
41
togbuffer.vert
Normal file
@ -0,0 +1,41 @@
|
||||
#version 330 core
|
||||
|
||||
#ifdef NORMAL_MAP
|
||||
out mat3 tangentSpace;
|
||||
#else
|
||||
out vec3 varNormal;
|
||||
#endif
|
||||
|
||||
out vec2 varTexCoord;
|
||||
|
||||
// Matrices
|
||||
uniform mat4 modelViewMatrix;
|
||||
uniform mat4 MVP;
|
||||
uniform mat4 viewMatrix;
|
||||
uniform mat3 normalMatrix;
|
||||
|
||||
layout(location = 0)in vec3 inPosition;
|
||||
layout(location = 1)in vec2 inTexCoord;
|
||||
layout(location = 2)in vec3 inNormal;
|
||||
#ifdef NORMAL_MAP
|
||||
layout(location = 3)in vec3 inTangent;
|
||||
layout(location = 4)in vec3 inBinormal;
|
||||
#endif
|
||||
|
||||
out vec3 varNormal;
|
||||
out vec2 varTexCoord;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
#ifdef NORMAL_MAP
|
||||
tangentSpace = mat3(normalize(normalMatrix*inNormal),
|
||||
normalize(normalMatrix*inTangent),
|
||||
normalize(normalMatrix*inBinormal));
|
||||
#else
|
||||
varNormal = normalize(normalMatrix*inNormal);
|
||||
#endif
|
||||
|
||||
varTexCoord = inTexCoord.xy;
|
||||
|
||||
gl_Position = MVP * vec4(inPosition, 1.0);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user