Fixed some transparency bugs and started on component based camera

This commit is contained in:
viktorljung
2015-12-14 19:10:00 +01:00
parent 6723e71fee
commit 05b78265be
17 changed files with 160 additions and 72 deletions
+1 -1
Submodule assets updated: b37468222e...c5f674349a
+6
View File
@@ -25,12 +25,18 @@ public:
private:
void GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type) const;
static bool DepthSort(const std::shared_ptr<RenderJob> &i, const std::shared_ptr<RenderJob> &j)
{
return (i->Depth < j->Depth);
};
Texture* m_WhiteTexture;
const IRenderer* m_Renderer;
ShaderProgram* m_BasicForwardProgram;
};
#endif
+23
View File
@@ -0,0 +1,23 @@
#ifndef Events_SetCamera_h__
#define Events_SetCamera_h__
#include "../Core/EventBroker.h"
#include "../Core/Entity.h"
namespace Events
{
/** Thrown Every frame, use functions to pick*/
struct SetCamera : Event
{
public:
SetCamera() { };
EntityID Entity;
private:
};
}
#endif
+1
View File
@@ -46,6 +46,7 @@ public:
struct MaterialGroup
{
float Shininess;
float Transparency;
std::shared_ptr<::Texture> Texture;
std::shared_ptr<::Texture> NormalMap;
std::shared_ptr<::Texture> SpecularMap;
+31
View File
@@ -63,6 +63,37 @@ struct ModelJob : RenderJob
}
};
struct TransparentModelJob : RenderJob
{
unsigned int ShaderID = 0;
unsigned int TextureID = 0;
//TODO: RENDERER: Not sure if the best solution for pickingColor to entity link is this
EntityID Entity;
glm::mat4 ModelMatrix;
const Texture* DiffuseTexture;
const Texture* NormalTexture;
const Texture* SpecularTexture;
float Shininess = 0.f;
glm::vec4 Color;
const Model* Model = nullptr;
unsigned int StartIndex = 0;
unsigned int EndIndex = 0;
// Animation
Skeleton* Skeleton = nullptr;
bool NoRootMotion = true;
std::string AnimationName;
double AnimationTime = 0;
void CalculateHash() override
{
Hash = TextureID;
}
};
struct SpriteJob : RenderJob
{
unsigned int ShaderID = 0;
@@ -6,16 +6,19 @@
#include "../Core/ResourceManager.h"
#include "Model.h"
#include "../GLM.h"
#include "../Core/EventBroker.h"
#include "ESetCamera.h"
class RenderQueueFactory
{
public:
RenderQueueFactory();
RenderQueueFactory(EventBroker* eventBroker);
void Update(World* world);
RenderQueueCollection RenderQueues() const { return m_RenderQueues; }
private:
EventBroker* m_EventBroker;
RenderQueueCollection m_RenderQueues;
void FillModels(World* world, RenderQueue* renderQueue);
@@ -26,6 +29,9 @@ private:
glm::vec3 AbsolutePosition(World* world, EntityID entity);
glm::quat AbsoluteOrientation(World* world, EntityID entity);
glm::vec3 AbsoluteScale(World* world, EntityID entity);
EntityID m_CurrentCamera;
};
#endif
+3 -1
View File
@@ -32,8 +32,9 @@ enum lightType
class Renderer : public IRenderer
{
public:
Renderer(EventBroker* eventBroker)
Renderer(EventBroker* eventBroker, World* world)
: m_EventBroker(eventBroker)
, m_World(world)
{ }
virtual void Initialize() override;
@@ -43,6 +44,7 @@ public:
private:
//----------------------Variables----------------------//
EventBroker* m_EventBroker;
World* m_World;
Texture* m_ErrorTexture;
Texture* m_WhiteTexture;
+1
View File
@@ -6,4 +6,5 @@
<xs:include schemaLocation="Components/Test.xsd"/>
<xs:include schemaLocation="Components/RaptorCopter.xsd"/>
<xs:include schemaLocation="Components/Player.xsd"/>
<xs:include schemaLocation="Components/Camera.xsd"/>
</xs:schema>
+6
View File
@@ -0,0 +1,6 @@
<c:Camera>
<AspectRatio>1.77</AspectRatio>
<FOV>90</FOV>
<NearClip>0.01</NearClip>
<FarClip>5000</FarClip>
</c:Camera>
+19
View File
@@ -0,0 +1,19 @@
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:t="types">
<xs:import schemaLocation="../Types.xsd" namespace="types"/>
<xs:element name="Camera">
<xs:annotation>
<xs:documentation>It's a camera thingy!</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:all>
<xs:element name="AspectRatio" type="t:double" minOccurs="0"/>
<xs:element name="FOV" type="t:double" minOccurs="0"/>
<xs:element name="NearClip" type="t:double" minOccurs="0"/>
<xs:element name="FarClip" type="t:double" minOccurs="0"/>
</xs:all>
</xs:complexType>
</xs:element>
</xs:schema>
+2 -14
View File
@@ -13,22 +13,10 @@
<Entity>
<Components>
<c:Transform>
<Position X="-1.5"/>
<Scale X="1" Y="1" Z="1"/>
</c:Transform>
<c:Model>
<Resource>Models/ScaleWidget.obj</Resource>
</c:Model>
</Components>
</Entity>
<Entity>
<Components>
<c:Transform>
<Position X="1.5"/>
</c:Transform>
<c:Model>
<Resource>Models/RotationWidget.obj</Resource>
</c:Model>
<c:Camera>
</c:Camera>
</Components>
</Entity>
<Entity>
+1
View File
@@ -32,6 +32,7 @@ void DrawScenePass::Draw(RenderQueueCollection& rq)
DrawScenePassState state;
rq.Forward.Jobs.sort(DrawScenePass::DepthSort);
//TODO: Render: Add code for more jobs than modeljobs.
for (auto &job : rq.Forward) {
@@ -8,6 +8,8 @@ DrawScenePassState::DrawScenePassState()
GLERROR("---");
Enable(GL_DEPTH_TEST);
Enable(GL_CULL_FACE);
Enable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
ClearColor(glm::vec4(255.f / 255, 163.f / 255, 176.f / 255, 0.f));
Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
+7 -1
View File
@@ -78,7 +78,12 @@ RawModel::RawModel(std::string fileName)
// Material diffuse color
aiColor4D diffuse;
material->Get(AI_MATKEY_COLOR_DIFFUSE, diffuse);
desc.DiffuseVertexColor = glm::vec4(diffuse.r, diffuse.g, diffuse.b, diffuse.a);
float opacity;
material->Get(AI_MATKEY_OPACITY, opacity);
desc.DiffuseVertexColor = glm::vec4(diffuse.r, diffuse.g, diffuse.b, opacity);
// Material specular color
aiColor4D specular;
material->Get(AI_MATKEY_COLOR_SPECULAR, specular);
@@ -132,6 +137,7 @@ RawModel::RawModel(std::string fileName)
matGroup.EndIndex = m_Indices.size() - 1;
// Material shininess
material->Get(AI_MATKEY_SHININESS, matGroup.Shininess);
material->Get(AI_MATKEY_OPACITY, matGroup.Transparency);
//LOG_DEBUG("Shininess: %f", matGroup.Shininess);
// Diffuse texture
//LOG_DEBUG("%i diffuse textures found", material->GetTextureCount(aiTextureType_DIFFUSE));
+38 -14
View File
@@ -1,9 +1,10 @@
#include "Rendering/RenderQueueFactory.h"
RenderQueueFactory::RenderQueueFactory()
RenderQueueFactory::RenderQueueFactory(EventBroker* eventBroker)
{
m_RenderQueues = RenderQueueCollection();
m_EventBroker = eventBroker;
}
void RenderQueueFactory::Update(World* world)
@@ -79,21 +80,44 @@ void RenderQueueFactory::FillModels(World* world, RenderQueue* renderQueue)
Model* model = ResourceManager::Load<Model>(resource);
for (auto texGroup : model->TextureGroups) {
ModelJob job;
job.TextureID = (texGroup.Texture) ? texGroup.Texture->ResourceID : 0;
job.DiffuseTexture = texGroup.Texture.get();
job.NormalTexture = texGroup.NormalMap.get();
job.SpecularTexture = texGroup.SpecularMap.get();
job.Model = model;
job.StartIndex = texGroup.StartIndex;
job.EndIndex = texGroup.EndIndex;
job.ModelMatrix = model->m_Matrix * ModelMatrix(world, modelC.EntityID);
job.Color = color;
//TODO: RENDERER: Not sure if the best solution for pickingColor to entity link is this
job.Entity = modelC.EntityID;
if (color.a < 1.0f || texGroup.Transparency < 1.0f) {
//transparent stuffs
TransparentModelJob job;
job.TextureID = (texGroup.Texture) ? texGroup.Texture->ResourceID : 0;
job.DiffuseTexture = texGroup.Texture.get();
job.NormalTexture = texGroup.NormalMap.get();
job.SpecularTexture = texGroup.SpecularMap.get();
job.Model = model;
job.StartIndex = texGroup.StartIndex;
job.EndIndex = texGroup.EndIndex;
job.ModelMatrix = model->m_Matrix * ModelMatrix(world, modelC.EntityID);
job.Color = color;
renderQueue->Add(job);
job.Entity = modelC.EntityID;
job.Depth = 10.f; //insert real viewspace depth here
renderQueue->Add(job);
} else {
ModelJob job;
job.TextureID = (texGroup.Texture) ? texGroup.Texture->ResourceID : 0;
job.DiffuseTexture = texGroup.Texture.get();
job.NormalTexture = texGroup.NormalMap.get();
job.SpecularTexture = texGroup.SpecularMap.get();
job.Model = model;
job.StartIndex = texGroup.StartIndex;
job.EndIndex = texGroup.EndIndex;
job.ModelMatrix = model->m_Matrix * ModelMatrix(world, modelC.EntityID);
job.Color = color;
//TODO: RENDERER: Not sure if the best solution for pickingColor to entity link is this
job.Entity = modelC.EntityID;
renderQueue->Add(job);
}
}
}
}
+1 -31
View File
@@ -10,6 +10,7 @@ void Renderer::Initialize()
if (m_Camera == nullptr) {
m_Camera = m_DefaultCamera;
}
TEMPCreateLights();
InitializeRenderPasses();
@@ -88,36 +89,6 @@ void Renderer::InitializeShaders()
void Renderer::InputUpdate(double dt)
{
static DebugCameraInputController<Renderer> firstPersonInputController(m_EventBroker, -1);
glm::vec3 m_Position = m_Camera->Position();
if (glfwGetKey(m_Window, GLFW_KEY_O) == GLFW_PRESS)
{
m_Position = glm::vec3(0.f, 0.f, 5.f);
}
if (glfwGetKey(m_Window, GLFW_KEY_W) == GLFW_PRESS)
{
m_Position += m_Camera->Forward() * m_CameraMoveSpeed * (float)dt;
}
if (glfwGetKey(m_Window, GLFW_KEY_S) == GLFW_PRESS)
{
m_Position -= m_Camera->Forward() * m_CameraMoveSpeed * (float)dt;
}
if (glfwGetKey(m_Window, GLFW_KEY_D) == GLFW_PRESS)
{
m_Position += m_Camera->Right() * m_CameraMoveSpeed * (float)dt;
}
if (glfwGetKey(m_Window, GLFW_KEY_A) == GLFW_PRESS)
{
m_Position -= m_Camera->Right() * m_CameraMoveSpeed * (float)dt;
}
if (glfwGetKey(m_Window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS)
{
m_CameraMoveSpeed = 5.f;
}
else {
m_CameraMoveSpeed = 0.5f;
}
firstPersonInputController.Update(dt);
m_Camera->SetOrientation(firstPersonInputController.Orientation());
m_Camera->SetPosition(firstPersonInputController.Position());
@@ -237,7 +208,6 @@ void Renderer::CalculateFrustum()
{
GLERROR("CalculateFrustum Error-1");
m_CalculateFrustumProgram->Bind();
GLERROR("CalculateFrustum Error1");
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, m_FrustumSSBO);
GLERROR("CalculateFrustum Error2");
+11 -9
View File
@@ -14,10 +14,17 @@ Game::Game(int argc, char* argv[])
// Create the core event broker
m_EventBroker = new EventBroker();
m_RenderQueueFactory = new RenderQueueFactory();
m_RenderQueueFactory = new RenderQueueFactory(m_EventBroker);
// Create a world
m_World = new World();
std::string mapToLoad = m_Config->Get<std::string>("Debug.LoadMap", "");
if (!mapToLoad.empty()) {
ResourceManager::Load<EntityXMLFile>(mapToLoad)->PopulateWorld(m_World);
}
// Create the renderer
m_Renderer = new Renderer(m_EventBroker);
m_Renderer = new Renderer(m_EventBroker, m_World);
m_Renderer->SetFullscreen(m_Config->Get<bool>("Video.Fullscreen", false));
m_Renderer->SetVSYNC(m_Config->Get<bool>("Video.VSYNC", false));
m_Renderer->SetResolution(Rectangle(
@@ -27,7 +34,7 @@ Game::Game(int argc, char* argv[])
m_Config->Get<int>("Video.Height", 720)
));
m_Renderer->Initialize();
m_Renderer->Camera()->SetFOV(glm::radians(m_Config->Get<float>("Video.FOV", 90.f)));
//m_Renderer->Camera()->SetFOV(glm::radians(m_Config->Get<float>("Video.FOV", 90.f)));
// Create input manager
m_InputManager = new InputManager(m_Renderer->Window(), m_EventBroker);
@@ -41,12 +48,7 @@ Game::Game(int argc, char* argv[])
m_FrameStack->Width = m_Renderer->Resolution().Width;
m_FrameStack->Height = m_Renderer->Resolution().Height;
// Create a world
m_World = new World();
std::string mapToLoad = m_Config->Get<std::string>("Debug.LoadMap", "");
if (!mapToLoad.empty()) {
ResourceManager::Load<EntityXMLFile>(mapToLoad)->PopulateWorld(m_World);
}
// Create system pipeline
m_SystemPipeline = new SystemPipeline(m_EventBroker);