diff --git a/CMakeLists.txt b/CMakeLists.txt index f320646..028baba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,8 +14,7 @@ endif(WIN32) set(LIB_SRC_LIST asciientity.cpp asciimodule.cpp - framebuffer.cpp - gbuffermodule.cpp + framebuffer.cpp lights.cpp meshbuilder.cpp phongentity.cpp @@ -26,6 +25,7 @@ set(LIB_SRC_LIST sparrowrenderer.cpp parametricmesh.cpp texture.cpp + scene.cpp entityloader.cpp ) diff --git a/camera.h b/camera.h index 06e03c0..075f5ad 100644 --- a/camera.h +++ b/camera.h @@ -2,8 +2,6 @@ #define CAMERA_H #include -#include -#include class Camera{ public: diff --git a/gbuffermodule.cpp b/gbuffermodule.cpp deleted file mode 100644 index 68e7c92..0000000 --- a/gbuffermodule.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "gbuffermodule.h" -#include "camera.h" -#include "mesh.h" - -void GBufferModule::addMesh(Mesh* myMesh) -{ - -} - -void GBufferModule::renderGL(Camera* myCamera) -{ - -} diff --git a/gbuffermodule.h b/gbuffermodule.h deleted file mode 100644 index e9b2b55..0000000 --- a/gbuffermodule.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef GBUFFERMODULE_H -#define GBUFFERMODULE_H - -#include "module.h" -#include -#include - -class Shader; -class Mesh; - -class GBufferModule : public Module -{ -public: - Shader* shader; - std::vector meshes; - - GBufferModule(Shader* myShader = NULL) : shader(myShader) {} - - void addMesh(Mesh* myMesh); - void virtual renderGL(Camera* myCamera); -}; - -#endif // GBUFFERMODULE_H diff --git a/phongbump.frag b/phongbump.frag new file mode 100644 index 0000000..8390db7 --- /dev/null +++ b/phongbump.frag @@ -0,0 +1,50 @@ +#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; +uniform sampler2D bumpMap; + +// 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 +#include "camera.h" + +// Scene Node flags : + +#define CAMERA_NODE 1 +#define DIRECTIONNAL_LIGHT_NODE 2 +#define POINT_LIGHT_NODE 4 +#define PHONG_NODE 8 +#define PHONG_DIFFUSE_TEXTURED_NODE 16 +#define PHONG_SPECULAR_TEXTURED_NODE 32 +#define PHONG_NORMAL_TEXTURED_NODE 64 +#define PARTICLES_NODE 128 +// up to 24 more nodes can be added here... + +// Scene interface : + +class Scene +{ + // the scene is supposed to contain Scene Nodes +public: + // this should draw all nodes matching the specified flags. + virtual draw(unsigned int flags) = 0; +}; + +// Some basic implementations : + +class Mesh; + +class LeafNode : public SceneNode +{ + glm::mat4 transform; + std::vector children; +public: + virtual void drawChildren(glm::mat4 m, unsigned int flags) + { + for(LeafNode* node : children) + node->drawChildren(m*transform, flags); + } +}; + +class MeshNode : public LeafNode +{ + Mesh* mesh; +public: + virtual void drawChildren(glm::mat4 m, unsigned int flags) + { + // TODO : draw VAOs matching the flags + for(LeafNode* node : children) + node->drawChildren(m*transform, flags); + } +}; + +class TreeScene +{ + LeafNode* root; +public: + virtual draw(unsigned int flags) + { + root->drawChildren(glm::mat4(), flags); + } +}; + +class CameraNode : public LeafNode +{ +public: + virtual glm::mat4 getProjectionMatrix() = 0; + virtual glm::mat4 getViewMatrix() = 0; + + virtual void resize(int width, int height) = 0; +}; + +#endif // SCENE_H