added SceneGraph
This commit is contained in:
parent
837fe1cd39
commit
50631ee113
@ -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
|
||||
)
|
||||
|
||||
|
2
camera.h
2
camera.h
@ -2,8 +2,6 @@
|
||||
#define CAMERA_H
|
||||
|
||||
#include <glm/mat4x4.hpp>
|
||||
#include <glm/vec3.hpp>
|
||||
#include <glm/vec2.hpp>
|
||||
|
||||
class Camera{
|
||||
public:
|
||||
|
@ -1,13 +0,0 @@
|
||||
#include "gbuffermodule.h"
|
||||
#include "camera.h"
|
||||
#include "mesh.h"
|
||||
|
||||
void GBufferModule::addMesh(Mesh* myMesh)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void GBufferModule::renderGL(Camera* myCamera)
|
||||
{
|
||||
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
#ifndef GBUFFERMODULE_H
|
||||
#define GBUFFERMODULE_H
|
||||
|
||||
#include "module.h"
|
||||
#include <vector>
|
||||
#include <cstddef>
|
||||
|
||||
class Shader;
|
||||
class Mesh;
|
||||
|
||||
class GBufferModule : public Module
|
||||
{
|
||||
public:
|
||||
Shader* shader;
|
||||
std::vector<Mesh*> meshes;
|
||||
|
||||
GBufferModule(Shader* myShader = NULL) : shader(myShader) {}
|
||||
|
||||
void addMesh(Mesh* myMesh);
|
||||
void virtual renderGL(Camera* myCamera);
|
||||
};
|
||||
|
||||
#endif // GBUFFERMODULE_H
|
50
phongbump.frag
Normal file
50
phongbump.frag
Normal file
@ -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<nbPointLights+1; ++i)
|
||||
light += computeLight(kd, materialKs, materialNs, pointLights[i*2 -1], varNormal, lightDirInView[i], halfVecInView[i]);
|
||||
|
||||
outColor = vec4(materialAmbient + light, 1);
|
||||
}
|
||||
|
57
phongbump.vert
Normal file
57
phongbump.vert
Normal file
@ -0,0 +1,57 @@
|
||||
#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 vec2 inTexCoord;
|
||||
layout(location = 2)in vec3 inTangent[2];
|
||||
|
||||
out vec3 lightDirInView[5];
|
||||
out vec3 halfVecInView[5];
|
||||
|
||||
out vec3 varNormal;
|
||||
out vec2 varTexCoord;
|
||||
out vec3 varTangent;
|
||||
out vec3 varBinormal;
|
||||
|
||||
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; i<nbPointLights+1; ++i)
|
||||
computePointLightingVectorsInView(vec3(modelViewMatrix*vec4(inPosition, 1.0)),
|
||||
pointLights[i*2 - 2],
|
||||
lightDirInView[i],
|
||||
halfVecInView[i]);
|
||||
|
||||
// normales corrigees (en fonction de la vue)
|
||||
varNormal = normalize(vec3(normalMatrix*vec4(inNormal,0)));
|
||||
|
||||
// coordonnees de texture
|
||||
varTexCoord = inTexCoord.xy;
|
||||
varTangent = inTangent[0];
|
||||
varBinormal = inTangent[1];
|
||||
|
||||
// position du vertex
|
||||
gl_Position = MVP * vec4(inPosition, 1.0);
|
||||
}
|
76
scene.h
Normal file
76
scene.h
Normal file
@ -0,0 +1,76 @@
|
||||
#ifndef SCENE_H
|
||||
#define SCENE_H
|
||||
|
||||
#include <glm/mat4x4.hpp>
|
||||
#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<LeafNode*> 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
|
Loading…
x
Reference in New Issue
Block a user