Hacks to make a nice demo.
This commit is contained in:
+37
-11
@@ -9,8 +9,8 @@ void GameWorld::Initialize()
|
|||||||
{
|
{
|
||||||
auto camera = CreateEntity();
|
auto camera = CreateEntity();
|
||||||
auto transform = AddComponent<Components::Transform>(camera, "Transform");
|
auto transform = AddComponent<Components::Transform>(camera, "Transform");
|
||||||
transform->Position.z = 20.f;
|
transform->Position.z = 70.f;
|
||||||
transform->Position.y = 20.f;
|
transform->Position.y = 25.f;
|
||||||
transform->Orientation = glm::quat(glm::vec3(glm::pi<float>() / 8.f, 0.f, 0.f));
|
transform->Orientation = glm::quat(glm::vec3(glm::pi<float>() / 8.f, 0.f, 0.f));
|
||||||
auto cameraComp = AddComponent<Components::Camera>(camera, "Camera");
|
auto cameraComp = AddComponent<Components::Camera>(camera, "Camera");
|
||||||
cameraComp->FarClip = 2000.f;
|
cameraComp->FarClip = 2000.f;
|
||||||
@@ -56,22 +56,48 @@ void GameWorld::Initialize()
|
|||||||
AddComponent<Components::Input>(car, "Input");
|
AddComponent<Components::Input>(car, "Input");
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 0; i < 50; i++)
|
/*for(int i = 0; i < 83; i++)
|
||||||
|
{
|
||||||
|
auto light = CreateEntity();
|
||||||
|
auto transform = AddComponent<Components::Transform>(light, "Transform");
|
||||||
|
transform->Position = glm::vec3((float)(2*i)*glm::sin((float)i), 3, (float)(2*i)*glm::cos((float)i));
|
||||||
|
|
||||||
|
auto pointLight = AddComponent<Components::PointLight>(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<Components::Model>(light, "Model");
|
||||||
|
model->ModelFile = "Models/Placeholders/PhysicsTest/PointLight.obj";
|
||||||
|
}*/
|
||||||
|
|
||||||
|
for(int i = 0; i < 100; i++)
|
||||||
{
|
{
|
||||||
auto ball = CreateEntity();
|
auto ball = CreateEntity();
|
||||||
auto transform = AddComponent<Components::Transform>(ball, "Transform");
|
auto transform = AddComponent<Components::Transform>(ball, "Transform");
|
||||||
transform->Position = glm::vec3(243, 10 + i*10, 0);
|
transform->Position = glm::vec3(i/5.f, 5 + i*2, i/5.f);
|
||||||
transform->Scale = glm::vec3(10);
|
transform->Scale = glm::vec3(1.0f, 1.0f, 1.0f);
|
||||||
transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f));
|
transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f));
|
||||||
auto model = AddComponent<Components::Model>(ball, "Model");
|
auto model = AddComponent<Components::Model>(ball, "Model");
|
||||||
model->ModelFile = "Models/Placeholders/PhysicsTest/Cube2.obj";
|
model->ModelFile = "Models/Placeholders/PhysicsTest/Sphere.obj";
|
||||||
|
auto sphere = AddComponent<Components::Sphere>(ball, "Sphere");
|
||||||
|
sphere->Radius = 0.5;
|
||||||
auto physics = AddComponent<Components::Physics>(ball, "Physics");
|
auto physics = AddComponent<Components::Physics>(ball, "Physics");
|
||||||
physics->Mass = 100;
|
physics->Mass = 1;
|
||||||
auto box = AddComponent<Components::Box>(ball, "Box");
|
|
||||||
box->Width = 5.f;
|
|
||||||
box->Height = 5.f;
|
|
||||||
box->Depth = 5.f;
|
|
||||||
|
|
||||||
|
auto pointLight = AddComponent<Components::PointLight>(ball, "PointLight");
|
||||||
|
pointLight->Specular = glm::vec3(0.1f, 0.1f, 0.1f);
|
||||||
|
pointLight->Diffuse = glm::vec3(0.05f, 0.36f, 1.f);
|
||||||
|
/*pointLight->constantAttenuation = 0.13f;
|
||||||
|
pointLight->linearAttenuation = 0.009f;
|
||||||
|
pointLight->quadraticAttenuation = 0.007f;*/
|
||||||
|
pointLight->constantAttenuation = 0.03f;
|
||||||
|
pointLight->linearAttenuation = 0.119f;
|
||||||
|
pointLight->quadraticAttenuation = 0.07f;
|
||||||
|
pointLight->spotExponent = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*{
|
/*{
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -42,7 +42,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
|
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
|
// 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);
|
m_PhysicsWorld = new hkpWorld(worldInfo);
|
||||||
}
|
}
|
||||||
// Register all collision agents, even though only box - box will be used in this particular example.
|
// Register all collision agents, even though only box - box will be used in this particular example.
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
#ifndef gBuffer_h__
|
||||||
|
#define gBuffer_h__
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
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__
|
||||||
Reference in New Issue
Block a user