diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index 7a5a543..62e3980 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -40,11 +40,38 @@ void GameWorld::Initialize() physics->Mass = 10; } - for(int i = 0; i < 10; i++) + { + auto TankTest = CreateEntity(); + auto transform = AddComponent(TankTest, "Transform"); + transform->Position = glm::vec3(1.5f, 0.7f, 5.f); + + auto model = AddComponent(TankTest, "Model"); + model->ModelFile = "Models/Placeholders/tank/Chassi.obj"; + } + + for(int i = 0; i < 83; i++) + { + auto light = CreateEntity(); + auto transform = AddComponent(light, "Transform"); + transform->Position = glm::vec3((float)(2*i)*glm::sin((float)i), 3, (float)(2*i)*glm::cos((float)i)); + + auto pointLight = AddComponent(light, "PointLight"); + pointLight->Specular = glm::vec3(0.1f, 0.1f, 0.1f); + pointLight->Diffuse = glm::vec3(0.05f, 0.36f, 1.f); + pointLight->constantAttenuation = 0.03f; + pointLight->linearAttenuation = 0.009f; + pointLight->quadraticAttenuation = 0.07f; + pointLight->spotExponent = 0.0f; + + auto model = AddComponent(light, "Model"); + model->ModelFile = "Models/Placeholders/PhysicsTest/PointLight.obj"; + } + + for(int i = 0; i < 500; i++) { auto ball = CreateEntity(); auto transform = AddComponent(ball, "Transform"); - transform->Position = glm::vec3(0, 5 + i*2, 0); + transform->Position = glm::vec3(i/5.f, 5 + i*2, i/5.f); transform->Scale = glm::vec3(1.0f, 1.0f, 1.0f); transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f)); auto model = AddComponent(ball, "Model"); diff --git a/src/Shaders/geometry_pass.frag.glsl b/src/Shaders/geometry_pass.frag.glsl new file mode 100644 index 0000000..4fe34ba --- /dev/null +++ b/src/Shaders/geometry_pass.frag.glsl @@ -0,0 +1,20 @@ +#version 430 + +in vec2 TexCoord0; +in vec3 Normal0; +in vec3 WorldPos0; + +layout (location = 0) out vec3 WorldPosOut; +layout (location = 1) out vec3 DiffuseOut; +layout (location = 2) out vec3 NormalOut; +layout (location = 3) out vec3 TexCoordOut; + +uniform sampler2D gColorMap; + +void main() +{ + WorldPosOut = WorldPos0; + DiffuseOut = texture(gColorMap, TexCoord0).xyz; + NormalOut = normalize(Normal0); + TexCoordOut = vec3(TexCoord0, 0.0); +} \ No newline at end of file diff --git a/src/Shaders/geometry_pass.vert.glsl b/src/Shaders/geometry_pass.vert.glsl new file mode 100644 index 0000000..c431ba9 --- /dev/null +++ b/src/Shaders/geometry_pass.vert.glsl @@ -0,0 +1,20 @@ +#version 430 + +layout (location = 0) in vec3 Position; +layout (location = 1) in vec2 TexCoord; +layout (location = 2) in vec3 Normal; + +uniform mat4 gWVP; +uniform mat4 gWorld; + +out vec2 TexCoord0; +out vec3 Normal0; +out vec3 WorldPos0; + +void main() +{ + gl_Position = gWVP * vec4(Position, 1.0); + TexCoord0 = TexCoord; + Normal0 = (gWorld * vec4(Normal, 0.0)).xyz; + WorldPos0 = (gWorld * vec4(Position, 1.0)).xyz; +} \ No newline at end of file diff --git a/src/Systems/PhysicsSystem.cpp b/src/Systems/PhysicsSystem.cpp index 98ee002..6ec3b45 100644 --- a/src/Systems/PhysicsSystem.cpp +++ b/src/Systems/PhysicsSystem.cpp @@ -41,7 +41,7 @@ Systems::PhysicsSystem::PhysicsSystem(World* world) : System(world) worldInfo.m_broadPhaseBorderBehaviour = hkpWorldCinfo::BROADPHASE_BORDER_FIX_ENTITY; // just fix the entity if the object falls off too far // You must specify the size of the broad phase - objects should not be simulated outside this region - worldInfo.setBroadPhaseWorldSize(1000.0f); + worldInfo.setBroadPhaseWorldSize(10000.0f); m_PhysicsWorld = new hkpWorld(worldInfo); } // Register all collision agents, even though only box - box will be used in this particular example. diff --git a/src/gBuffer.cpp b/src/gBuffer.cpp new file mode 100644 index 0000000..5acf690 --- /dev/null +++ b/src/gBuffer.cpp @@ -0,0 +1,40 @@ +#include "PrecompiledHeader.h" +#include "gBuffer.h" + +bool GBuffer::Init(unsigned int WindowWidth, unsigned int WindowHeight) +{ + // Create the FBO + glGenFramebuffers(1, &m_fbo); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbo); + + // Create the gbuffer textures + glGenTextures(ARRAY_SIZE_IN_ELEMENTS(m_textures), m_textures); + glGenTextures(1, &m_depthTexture); + + for (unsigned int i = 0 ; i < ARRAY_SIZE_IN_ELEMENTS(m_textures) ; i++) { + glBindTexture(GL_TEXTURE_2D, m_textures[i]); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, WindowWidth, WindowHeight, 0, GL_RGB, GL_FLOAT, NULL); + glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, m_textures[i], 0); + } + + // depth + glBindTexture(GL_TEXTURE_2D, m_depthTexture); + glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, WindowWidth, WindowHeight, 0, GL_DEPTH_COMPONENT, GL_FLOAT, + NULL); + glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, m_depthTexture, 0); + + GLenum DrawBuffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3 }; + glDrawBuffers(ARRAY_SIZE_IN_ELEMENTS(DrawBuffers), DrawBuffers); + + GLenum Status = glCheckFramebufferStatus(GL_FRAMEBUFFER); + + if (Status != GL_FRAMEBUFFER_COMPLETE) { + printf("FB error, status: 0x%x\n", Status); + return false; + } + + // restore default FBO + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); + + return true; +} \ No newline at end of file diff --git a/src/gBuffer.h b/src/gBuffer.h new file mode 100644 index 0000000..721eb15 --- /dev/null +++ b/src/gBuffer.h @@ -0,0 +1,35 @@ +#ifndef gBuffer_h__ +#define gBuffer_h__ + +#include + +class GBuffer +{ +public: + + enum GBUFFER_TEXTURE_TYPE { + GBUFFER_TEXTURE_TYPE_POSITION, + GBUFFER_TEXTURE_TYPE_DIFFUSE, + GBUFFER_TEXTURE_TYPE_NORMAL, + GBUFFER_TEXTURE_TYPE_TEXCOORD, + GBUFFER_NUM_TEXTURES + }; + + GBuffer(); + + ~GBuffer(); + + bool Init(unsigned int WindowWidth, unsigned int WindowHeight); + + void BindForWriting(); + + void BindForReading(); + +private: + + GLuint m_fbo; + GLuint m_textures[GBUFFER_NUM_TEXTURES]; + GLuint m_depthTexture; +}; + +#endif //gBuffer_h__ \ No newline at end of file diff --git a/vs11/Returngeance/Returngeance.vcxproj.filters b/vs11/Returngeance/Returngeance.vcxproj.filters index 26bcf35..672e8dd 100755 --- a/vs11/Returngeance/Returngeance.vcxproj.filters +++ b/vs11/Returngeance/Returngeance.vcxproj.filters @@ -157,36 +157,6 @@ Rendering - - Physics\Components - - - Physics\Components - - - Physics\Components - - - Physics\Components - - - Physics\Components - - - Physics\Components - - - Physics\Components - - - Physics\Components - - - Physics\Components - - - Physics\Components - Physics\Components @@ -242,6 +212,8 @@ Audio + +