Merge remote-tracking branch 'origin/master' into TextRendering
# Conflicts: # include/Engine/Rendering/RenderQueue.h # include/Engine/Rendering/RenderSystem.h # include/Engine/Rendering/Renderer.h # src/Engine/Rendering/RenderSystem.cpp
This commit is contained in:
+1
-1
Submodule assets updated: a3c92ac876...6ffb46e155
@@ -0,0 +1,35 @@
|
|||||||
|
#ifndef DirectionalLightJob_h__
|
||||||
|
#define DirectionalLightJob_h__
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
#include "../Common.h"
|
||||||
|
#include "../GLM.h"
|
||||||
|
#include "../Core/ComponentWrapper.h"
|
||||||
|
#include "RenderJob.h"
|
||||||
|
#include "../Core/Transform.h"
|
||||||
|
#include "../Core/World.h"
|
||||||
|
|
||||||
|
struct DirectionalLightJob : RenderJob
|
||||||
|
{
|
||||||
|
DirectionalLightJob(ComponentWrapper transformComponent, ComponentWrapper directionalLightComponent, World* m_World)
|
||||||
|
: RenderJob()
|
||||||
|
{
|
||||||
|
|
||||||
|
Direction = glm::vec4(0,0,-1,0) * glm::inverse(Transform::AbsoluteOrientation(m_World, transformComponent.EntityID));
|
||||||
|
//Direction = glm::vec4((glm::vec3)directionalLightComponent["Direction"], 0.f);
|
||||||
|
Color = (glm::vec4)directionalLightComponent["Color"];
|
||||||
|
Intensity = (double)directionalLightComponent["Intensity"];
|
||||||
|
};
|
||||||
|
|
||||||
|
glm::vec4 Direction;
|
||||||
|
glm::vec4 Color;
|
||||||
|
float Intensity;
|
||||||
|
|
||||||
|
void CalculateHash() override
|
||||||
|
{
|
||||||
|
Hash = 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -46,8 +46,8 @@ private:
|
|||||||
int m_NumberOfTiles = 0;
|
int m_NumberOfTiles = 0;
|
||||||
|
|
||||||
struct Plane {
|
struct Plane {
|
||||||
glm::vec3 Normal;
|
glm::vec3 Normal = glm::vec3(0.f);
|
||||||
float d;
|
float d = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Frustum {
|
struct Frustum {
|
||||||
@@ -56,20 +56,21 @@ private:
|
|||||||
Frustum* m_Frustums;
|
Frustum* m_Frustums;
|
||||||
|
|
||||||
//This should be a component
|
//This should be a component
|
||||||
struct PointLight {
|
struct LightSource {
|
||||||
glm::vec4 Position = glm::vec4(0.f);
|
glm::vec4 Position = glm::vec4(0.f);
|
||||||
|
glm::vec4 Direction = glm::vec4(10.f);
|
||||||
glm::vec4 Color = glm::vec4(1.f);
|
glm::vec4 Color = glm::vec4(1.f);
|
||||||
float Radius = 5.f;
|
float Radius = 5.f;
|
||||||
float Intensity = 0.8f;
|
float Intensity = 0.8f;
|
||||||
float Falloff = 0.3f;
|
float Falloff = 0.3f;
|
||||||
float Padding = 1337;
|
enum Type_t { Zero, Point, Directional, Spot } Type;
|
||||||
};
|
};
|
||||||
std::vector<PointLight> m_PointLights;
|
std::vector<LightSource> m_LightSources;
|
||||||
|
|
||||||
struct LightGrid {
|
struct LightGrid {
|
||||||
float Start;
|
float Start = 0;
|
||||||
float Amount;
|
float Amount = 0;
|
||||||
glm::vec2 Padding;
|
glm::vec2 Padding = glm::vec2(1.f, 2.f);
|
||||||
};
|
};
|
||||||
|
|
||||||
LightGrid* m_LightGrid;
|
LightGrid* m_LightGrid;
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
#include "../Core/ResourceManager.h"
|
#include "../Core/ResourceManager.h"
|
||||||
#include "Camera.h"
|
#include "Camera.h"
|
||||||
#include "../Core/World.h"
|
#include "../Core/World.h"
|
||||||
|
#include "../Core/Transform.h"
|
||||||
|
|
||||||
struct ModelJob : RenderJob
|
struct ModelJob : RenderJob
|
||||||
{
|
{
|
||||||
@@ -28,6 +29,9 @@ struct ModelJob : RenderJob
|
|||||||
Matrix = matrix;
|
Matrix = matrix;
|
||||||
Color = modelComponent["Color"];
|
Color = modelComponent["Color"];
|
||||||
Entity = modelComponent.EntityID;
|
Entity = modelComponent.EntityID;
|
||||||
|
glm::vec3 abspos = Transform::AbsolutePosition(world, modelComponent.EntityID);
|
||||||
|
glm::vec3 worldpos = glm::vec3(camera->ViewMatrix() * glm::vec4(abspos, 1));
|
||||||
|
Depth = worldpos.z;
|
||||||
World = world;
|
World = world;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
#include "ModelJob.h"
|
#include "ModelJob.h"
|
||||||
#include "TextJob.h"
|
#include "TextJob.h"
|
||||||
#include "PointLightJob.h"
|
#include "PointLightJob.h"
|
||||||
|
#include "DirectionalLightJob.h"
|
||||||
|
|
||||||
struct RenderScene
|
struct RenderScene
|
||||||
{
|
{
|
||||||
@@ -20,6 +21,7 @@ struct RenderScene
|
|||||||
std::list<std::shared_ptr<RenderJob>> ForwardJobs;
|
std::list<std::shared_ptr<RenderJob>> ForwardJobs;
|
||||||
std::list<std::shared_ptr<RenderJob>> PointLightJobs;
|
std::list<std::shared_ptr<RenderJob>> PointLightJobs;
|
||||||
std::list<std::shared_ptr<RenderJob>> TextJobs;
|
std::list<std::shared_ptr<RenderJob>> TextJobs;
|
||||||
|
std::list<std::shared_ptr<RenderJob>> DirectionalLightJobs;
|
||||||
Rectangle Viewport;
|
Rectangle Viewport;
|
||||||
|
|
||||||
void Clear()
|
void Clear()
|
||||||
@@ -27,6 +29,7 @@ struct RenderScene
|
|||||||
ForwardJobs.clear();
|
ForwardJobs.clear();
|
||||||
PointLightJobs.clear();
|
PointLightJobs.clear();
|
||||||
TextJobs.clear();
|
TextJobs.clear();
|
||||||
|
DirectionalLightJobs.clear();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -47,7 +47,8 @@ private:
|
|||||||
|
|
||||||
void fillModels(std::list<std::shared_ptr<RenderJob>>& jobs, World* world);
|
void fillModels(std::list<std::shared_ptr<RenderJob>>& jobs, World* world);
|
||||||
void fillText(std::list<std::shared_ptr<RenderJob>>& jobs, World* world);
|
void fillText(std::list<std::shared_ptr<RenderJob>>& jobs, World* world);
|
||||||
void fillLight(std::list<std::shared_ptr<RenderJob>>& jobs, World* world);
|
void fillPointLights(std::list<std::shared_ptr<RenderJob>>& jobs, World* world);
|
||||||
|
void fillDirectionalLights(std::list<std::shared_ptr<RenderJob>>& jobs, World* world);
|
||||||
|
|
||||||
EventRelay<RenderSystem, Events::InputCommand> m_EInputCommand;
|
EventRelay<RenderSystem, Events::InputCommand> m_EInputCommand;
|
||||||
bool OnInputCommand(const Events::InputCommand& e);
|
bool OnInputCommand(const Events::InputCommand& e);
|
||||||
|
|||||||
@@ -24,9 +24,8 @@
|
|||||||
class Renderer : public IRenderer
|
class Renderer : public IRenderer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Renderer(EventBroker* eventBroker, World* world)
|
Renderer(EventBroker* eventBroker)
|
||||||
: m_EventBroker(eventBroker)
|
: m_EventBroker(eventBroker)
|
||||||
, m_World(world)
|
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
virtual void Initialize() override;
|
virtual void Initialize() override;
|
||||||
@@ -38,7 +37,6 @@ public:
|
|||||||
private:
|
private:
|
||||||
//----------------------Variables----------------------//
|
//----------------------Variables----------------------//
|
||||||
EventBroker* m_EventBroker;
|
EventBroker* m_EventBroker;
|
||||||
World* m_World;
|
|
||||||
TextRenderer* m_TextRenderer;
|
TextRenderer* m_TextRenderer;
|
||||||
|
|
||||||
Texture* m_ErrorTexture;
|
Texture* m_ErrorTexture;
|
||||||
@@ -65,7 +63,7 @@ private:
|
|||||||
void DrawScreenQuad(GLuint textureToDraw);
|
void DrawScreenQuad(GLuint textureToDraw);
|
||||||
|
|
||||||
static bool DepthSort(const std::shared_ptr<RenderJob> &i, const std::shared_ptr<RenderJob> &j) { return (i->Depth < j->Depth); }
|
static bool DepthSort(const std::shared_ptr<RenderJob> &i, const std::shared_ptr<RenderJob> &j) { return (i->Depth < j->Depth); }
|
||||||
void FillDepth(RenderScene& scene);
|
void SortRenderJobsByDepth(RenderScene &scene);
|
||||||
void GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type);
|
void GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type);
|
||||||
//--------------------ShaderPrograms-------------------//
|
//--------------------ShaderPrograms-------------------//
|
||||||
ShaderProgram* m_BasicForwardProgram;
|
ShaderProgram* m_BasicForwardProgram;
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
<xs:include schemaLocation="Components/Camera.xsd"/>
|
<xs:include schemaLocation="Components/Camera.xsd"/>
|
||||||
<xs:include schemaLocation="Components/AABB.xsd"/>
|
<xs:include schemaLocation="Components/AABB.xsd"/>
|
||||||
<xs:include schemaLocation="Components/PointLight.xsd"/>
|
<xs:include schemaLocation="Components/PointLight.xsd"/>
|
||||||
|
<xs:include schemaLocation="Components/DirectionalLight.xsd"/>
|
||||||
<xs:include schemaLocation="Components/Trigger.xsd"/>
|
<xs:include schemaLocation="Components/Trigger.xsd"/>
|
||||||
<xs:include schemaLocation="Components/Health.xsd"/>
|
<xs:include schemaLocation="Components/Health.xsd"/>
|
||||||
<xs:include schemaLocation="Components/Listener.xsd"/>
|
<xs:include schemaLocation="Components/Listener.xsd"/>
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
|
||||||
|
<DirectionalLight xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="DirectionalLight.xsd">
|
||||||
|
<Color R="1" G="1" B="1" A="1"/>
|
||||||
|
<Intensity>0.8</Intensity>
|
||||||
|
<Visible>true</Visible>
|
||||||
|
</DirectionalLight>
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<?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="DirectionalLight">
|
||||||
|
<xs:annotation>
|
||||||
|
<xs:documentation>A directional light that shines bright like the future.</xs:documentation>
|
||||||
|
</xs:annotation>
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:all>
|
||||||
|
<xs:element name="Color" type="t:Color" minOccurs="0"/>
|
||||||
|
<xs:element name="Intensity" type="t:double" minOccurs="0"/>
|
||||||
|
<xs:element name="Visible" type="t:bool" minOccurs="0"/>
|
||||||
|
</xs:all>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
</xs:schema>
|
||||||
@@ -13,6 +13,7 @@
|
|||||||
</c:Model>
|
</c:Model>
|
||||||
<c:Transform>
|
<c:Transform>
|
||||||
<Scale X="100" Y="1" Z="100"/>
|
<Scale X="100" Y="1" Z="100"/>
|
||||||
|
<Orientation X="0" Y="2.59200001" Z="0"/>
|
||||||
</c:Transform>
|
</c:Transform>
|
||||||
</Components>
|
</Components>
|
||||||
<Children/>
|
<Children/>
|
||||||
@@ -45,9 +46,58 @@
|
|||||||
<Entity>
|
<Entity>
|
||||||
<Components>
|
<Components>
|
||||||
<c:Camera/>
|
<c:Camera/>
|
||||||
|
<c:Listener/>
|
||||||
<c:Transform>
|
<c:Transform>
|
||||||
<Position X="5.85247707" Y="3.8454349" Z="-1.14486957"/>
|
<Position X="1.36896265" Y="4.4259491" Z="10.6640663"/>
|
||||||
<Orientation X="2.51327395" Y="1.23916209" Z="-3.1415925"/>
|
<Orientation X="-0.0349078141" Y="0.157154545" Z="-2.60252193e-07"/>
|
||||||
|
</c:Transform>
|
||||||
|
</Components>
|
||||||
|
<Children/>
|
||||||
|
</Entity>
|
||||||
|
<Entity>
|
||||||
|
<Components>
|
||||||
|
<c:DirectionalLight/>
|
||||||
|
<c:Model>
|
||||||
|
<Resource>Models/DirectionalLightWidget.obj</Resource>
|
||||||
|
</c:Model>
|
||||||
|
<c:Transform>
|
||||||
|
<Position X="2.1529963" Y="6.59221172" Z="0.169116676"/>
|
||||||
|
<Orientation X="4.32000017" Y="4.6340003" Z="0"/>
|
||||||
|
</c:Transform>
|
||||||
|
</Components>
|
||||||
|
<Children/>
|
||||||
|
</Entity>
|
||||||
|
<Entity>
|
||||||
|
<Components>
|
||||||
|
<c:Model>
|
||||||
|
<Resource>Models/Assault.obj</Resource>
|
||||||
|
</c:Model>
|
||||||
|
<c:Transform>
|
||||||
|
<Position X="-2.00568962" Y="0.527161121" Z="0"/>
|
||||||
|
</c:Transform>
|
||||||
|
</Components>
|
||||||
|
<Children>
|
||||||
|
<Entity>
|
||||||
|
<Components>
|
||||||
|
<c:Model>
|
||||||
|
<Resource>Models/SecondaryWeapon.fbx</Resource>
|
||||||
|
</c:Model>
|
||||||
|
<c:Transform>
|
||||||
|
<Position X="-0.546139359" Y="0.853016734" Z="0.177482292"/>
|
||||||
|
<Orientation X="1.47266471" Y="0.524984181" Z="1.243698"/>
|
||||||
|
</c:Transform>
|
||||||
|
</Components>
|
||||||
|
<Children/>
|
||||||
|
</Entity>
|
||||||
|
</Children>
|
||||||
|
</Entity>
|
||||||
|
<Entity>
|
||||||
|
<Components>
|
||||||
|
<c:Model>
|
||||||
|
<Resource>Models/Core/UnitSphere.obj</Resource>
|
||||||
|
</c:Model>
|
||||||
|
<c:Transform>
|
||||||
|
<Position X="0" Y="3.70000029" Z="0"/>
|
||||||
</c:Transform>
|
</c:Transform>
|
||||||
</Components>
|
</Components>
|
||||||
<Children/>
|
<Children/>
|
||||||
|
|||||||
@@ -11,12 +11,14 @@
|
|||||||
<c:Camera>
|
<c:Camera>
|
||||||
<Name>ActionCamera</Name>
|
<Name>ActionCamera</Name>
|
||||||
</c:Camera>
|
</c:Camera>
|
||||||
|
<c:Listener/>
|
||||||
<c:Model>
|
<c:Model>
|
||||||
<Resource>Models/Camera.obj</Resource>
|
<Resource>Models/Camera.obj</Resource>
|
||||||
|
<Visible>false</Visible>
|
||||||
</c:Model>
|
</c:Model>
|
||||||
<c:Transform>
|
<c:Transform>
|
||||||
<Position X="-7.05254316" Y="2.96810508" Z="10.5229216"/>
|
<Position X="-1.04501271" Y="2.65480638" Z="9.08133221"/>
|
||||||
<Orientation X="-0.24434644" Y="-0.680581629" Z="4.69731361e-07"/>
|
<Orientation X="-0.488691956" Y="-0.261693299" Z="4.35807976e-07"/>
|
||||||
</c:Transform>
|
</c:Transform>
|
||||||
</Components>
|
</Components>
|
||||||
<Children>
|
<Children>
|
||||||
@@ -79,7 +81,7 @@
|
|||||||
</c:RaptorCopter>
|
</c:RaptorCopter>
|
||||||
<c:Transform>
|
<c:Transform>
|
||||||
<Position X="0" Y="2.37320328" Z="0"/>
|
<Position X="0" Y="2.37320328" Z="0"/>
|
||||||
<Orientation X="0" Y="6311.2666" Z="0"/>
|
<Orientation X="0" Y="6858.01416" Z="0"/>
|
||||||
</c:Transform>
|
</c:Transform>
|
||||||
</Components>
|
</Components>
|
||||||
<Children>
|
<Children>
|
||||||
@@ -88,6 +90,7 @@
|
|||||||
<c:PointLight>
|
<c:PointLight>
|
||||||
<Color A="1" B="1" G="0" R="1"/>
|
<Color A="1" B="1" G="0" R="1"/>
|
||||||
<Radius>6</Radius>
|
<Radius>6</Radius>
|
||||||
|
<Intensity>0.5</Intensity>
|
||||||
</c:PointLight>
|
</c:PointLight>
|
||||||
<c:Transform>
|
<c:Transform>
|
||||||
<Position X="-2.5" Y="0" Z="0"/>
|
<Position X="-2.5" Y="0" Z="0"/>
|
||||||
@@ -100,6 +103,7 @@
|
|||||||
<c:PointLight>
|
<c:PointLight>
|
||||||
<Color A="1" B="0" G="1" R="1"/>
|
<Color A="1" B="0" G="1" R="1"/>
|
||||||
<Radius>6</Radius>
|
<Radius>6</Radius>
|
||||||
|
<Intensity>0.5</Intensity>
|
||||||
</c:PointLight>
|
</c:PointLight>
|
||||||
<c:Transform>
|
<c:Transform>
|
||||||
<Position X="0" Y="0" Z="-2.5"/>
|
<Position X="0" Y="0" Z="-2.5"/>
|
||||||
@@ -112,6 +116,7 @@
|
|||||||
<c:PointLight>
|
<c:PointLight>
|
||||||
<Color A="1" B="1" G="1" R="0"/>
|
<Color A="1" B="1" G="1" R="0"/>
|
||||||
<Radius>6</Radius>
|
<Radius>6</Radius>
|
||||||
|
<Intensity>0.5</Intensity>
|
||||||
</c:PointLight>
|
</c:PointLight>
|
||||||
<c:Transform>
|
<c:Transform>
|
||||||
<Position X="0" Y="0" Z="2.5"/>
|
<Position X="0" Y="0" Z="2.5"/>
|
||||||
@@ -123,6 +128,7 @@
|
|||||||
<Components>
|
<Components>
|
||||||
<c:PointLight>
|
<c:PointLight>
|
||||||
<Radius>6</Radius>
|
<Radius>6</Radius>
|
||||||
|
<Intensity>0.5</Intensity>
|
||||||
</c:PointLight>
|
</c:PointLight>
|
||||||
<c:Transform>
|
<c:Transform>
|
||||||
<Position X="2.5" Y="0" Z="0"/>
|
<Position X="2.5" Y="0" Z="0"/>
|
||||||
@@ -132,18 +138,6 @@
|
|||||||
</Entity>
|
</Entity>
|
||||||
</Children>
|
</Children>
|
||||||
</Entity>
|
</Entity>
|
||||||
<Entity>
|
|
||||||
<Components>
|
|
||||||
<c:PointLight>
|
|
||||||
<Radius>51</Radius>
|
|
||||||
<Intensity>0.4999997615814209</Intensity>
|
|
||||||
</c:PointLight>
|
|
||||||
<c:Transform>
|
|
||||||
<Position X="0" Y="10" Z="0"/>
|
|
||||||
</c:Transform>
|
|
||||||
</Components>
|
|
||||||
<Children/>
|
|
||||||
</Entity>
|
|
||||||
<Entity>
|
<Entity>
|
||||||
<Components>
|
<Components>
|
||||||
<c:Model>
|
<c:Model>
|
||||||
@@ -187,6 +181,22 @@
|
|||||||
</Entity>
|
</Entity>
|
||||||
</Children>
|
</Children>
|
||||||
</Entity>
|
</Entity>
|
||||||
|
<Entity>
|
||||||
|
<Components>
|
||||||
|
<c:DirectionalLight>
|
||||||
|
<Color A="1" B="0.996078432" G="1" R="1"/>
|
||||||
|
<Intensity>0.80000001192092896</Intensity>
|
||||||
|
</c:DirectionalLight>
|
||||||
|
<c:Model>
|
||||||
|
<Resource>Models/DirectionalLightWidget.obj</Resource>
|
||||||
|
</c:Model>
|
||||||
|
<c:Transform>
|
||||||
|
<Position X="-0.0013256073" Y="1.89540339" Z="6.53467274"/>
|
||||||
|
<Orientation X="-1.06251872" Y="0.0644905791" Z="-0.639524579"/>
|
||||||
|
</c:Transform>
|
||||||
|
</Components>
|
||||||
|
<Children/>
|
||||||
|
</Entity>
|
||||||
</Children>
|
</Children>
|
||||||
|
|
||||||
</Entity>
|
</Entity>
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
<xs:element ref="c:SpawnPoint" minOccurs="0"/>
|
<xs:element ref="c:SpawnPoint" minOccurs="0"/>
|
||||||
<xs:element ref="c:PlayerSpawn" minOccurs="0"/>
|
<xs:element ref="c:PlayerSpawn" minOccurs="0"/>
|
||||||
<xs:element ref="c:Team" minOccurs="0"/>
|
<xs:element ref="c:Team" minOccurs="0"/>
|
||||||
|
<xs:element ref="c:DirectionalLight" minOccurs="0"/>
|
||||||
</xs:all>
|
</xs:all>
|
||||||
</xs:complexType>
|
</xs:complexType>
|
||||||
</xs:element>
|
</xs:element>
|
||||||
|
|||||||
@@ -27,19 +27,20 @@ layout (std430, binding = 0) buffer FrustumBuffer
|
|||||||
Frustum Data[];
|
Frustum Data[];
|
||||||
} Frustums;
|
} Frustums;
|
||||||
|
|
||||||
struct PointLight {
|
struct LightSource {
|
||||||
vec4 Position;
|
vec4 Position;
|
||||||
|
vec4 Direction;
|
||||||
vec4 Color;
|
vec4 Color;
|
||||||
float Radius;
|
float Radius;
|
||||||
float Intensity;
|
float Intensity;
|
||||||
float Falloff;
|
float Falloff;
|
||||||
float Padding;
|
int Type;
|
||||||
};
|
};
|
||||||
|
|
||||||
layout (std430, binding = 1) buffer LightBuffer
|
layout (std430, binding = 1) buffer LightBuffer
|
||||||
{
|
{
|
||||||
PointLight List[];
|
LightSource List[];
|
||||||
} PointLights;
|
} LightSources;
|
||||||
|
|
||||||
struct LightGrid {
|
struct LightGrid {
|
||||||
float Start;
|
float Start;
|
||||||
@@ -106,8 +107,7 @@ layout (local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
|
|||||||
void main ()
|
void main ()
|
||||||
{
|
{
|
||||||
GroupIndex = int(gl_WorkGroupID.x + (gl_WorkGroupID.y * int(ScreenDimensions.x/TILE_SIZE)));
|
GroupIndex = int(gl_WorkGroupID.x + (gl_WorkGroupID.y * int(ScreenDimensions.x/TILE_SIZE)));
|
||||||
if(gl_LocalInvocationIndex == 0)
|
if(gl_LocalInvocationIndex == 0) {
|
||||||
{
|
|
||||||
GroupLightCount = 0;
|
GroupLightCount = 0;
|
||||||
GroupFrustum = Frustums.Data[GroupIndex];
|
GroupFrustum = Frustums.Data[GroupIndex];
|
||||||
}
|
}
|
||||||
@@ -115,22 +115,25 @@ void main ()
|
|||||||
barrier();
|
barrier();
|
||||||
memoryBarrierShared();
|
memoryBarrierShared();
|
||||||
|
|
||||||
for(int i = int(gl_LocalInvocationIndex); i < PointLights.List.length(); i += TILE_SIZE*TILE_SIZE)
|
for(int i = int(gl_LocalInvocationIndex); i < LightSources.List.length(); i += TILE_SIZE*TILE_SIZE) {
|
||||||
{
|
LightSource light = LightSources.List[i];
|
||||||
PointLight light = PointLights.List[i];
|
|
||||||
|
|
||||||
//if pointlight
|
//if pointlight
|
||||||
//Pos i view antagligen
|
//Pos i view antagligen
|
||||||
if(SphereInsideFrustrum( vec3(V * light.Position), light.Radius, GroupFrustum))
|
if(light.Type == 1) {
|
||||||
{
|
if(SphereInsideFrustrum( vec3(V * light.Position), light.Radius, GroupFrustum)) {
|
||||||
//TODO: Fix transparent and opaque list, and depth test.
|
//TODO: Fix transparent and opaque list, and depth test.
|
||||||
AppendLight( i );
|
AppendLight( i );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//if conelight
|
//if conelight
|
||||||
|
|
||||||
//if directional
|
//if directional
|
||||||
|
if(light.Type == 2) {
|
||||||
|
AppendLight( i );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,19 +9,20 @@ uniform sampler2D texture0;
|
|||||||
|
|
||||||
#define TILE_SIZE 16
|
#define TILE_SIZE 16
|
||||||
|
|
||||||
struct PointLight {
|
struct LightSource {
|
||||||
vec4 Position;
|
vec4 Position;
|
||||||
|
vec4 Direction;
|
||||||
vec4 Color;
|
vec4 Color;
|
||||||
float Radius;
|
float Radius;
|
||||||
float Intensity;
|
float Intensity;
|
||||||
float Falloff;
|
float Falloff;
|
||||||
float Padding;
|
int Type;
|
||||||
};
|
};
|
||||||
|
|
||||||
layout (std430, binding = 1) buffer LightBuffer
|
layout (std430, binding = 1) buffer LightBuffer
|
||||||
{
|
{
|
||||||
PointLight List[];
|
LightSource List[];
|
||||||
} PointLights;
|
} LightSources;
|
||||||
|
|
||||||
struct LightGrid {
|
struct LightGrid {
|
||||||
float Start;
|
float Start;
|
||||||
@@ -71,7 +72,7 @@ vec4 CalcDiffuse(vec4 lightColor, vec4 lightVec, vec4 normal) {
|
|||||||
return lightColor * power;
|
return lightColor * power;
|
||||||
}
|
}
|
||||||
|
|
||||||
LightResult CalcPointLight(vec4 lightPos, float lightRadius, vec4 lightColor, float intensity, vec4 viewVec, vec4 position, vec4 normal, float falloff)
|
LightResult CalcPointLightSource(vec4 lightPos, float lightRadius, vec4 lightColor, float intensity, vec4 viewVec, vec4 position, vec4 normal, float falloff)
|
||||||
{
|
{
|
||||||
vec4 L = lightPos - position;
|
vec4 L = lightPos - position;
|
||||||
float dist = length(L);
|
float dist = length(L);
|
||||||
@@ -85,6 +86,16 @@ LightResult CalcPointLight(vec4 lightPos, float lightRadius, vec4 lightColor, fl
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LightResult CalcDirectionalLightSource(vec4 direction, vec4 color, float intensity, vec4 viewVec, vec4 vertNormal)
|
||||||
|
{
|
||||||
|
vec4 L = normalize( -vec4(direction.xyz, 0) );
|
||||||
|
|
||||||
|
LightResult result;
|
||||||
|
result.Diffuse = CalcDiffuse(color, L, vertNormal) * intensity;
|
||||||
|
result.Specular = CalcSpecular(color, viewVec, L, vertNormal) * intensity;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
@@ -94,8 +105,8 @@ void main()
|
|||||||
vec4 viewVec = normalize(-position);
|
vec4 viewVec = normalize(-position);
|
||||||
|
|
||||||
vec2 tilePos;
|
vec2 tilePos;
|
||||||
tilePos.x = int(gl_FragCoord.x/16);
|
tilePos.x = int(gl_FragCoord.x/TILE_SIZE);
|
||||||
tilePos.y = int(gl_FragCoord.y/16);
|
tilePos.y = int(gl_FragCoord.y/TILE_SIZE);
|
||||||
|
|
||||||
LightResult totalLighting;
|
LightResult totalLighting;
|
||||||
totalLighting.Diffuse = scene_ambient;
|
totalLighting.Diffuse = scene_ambient;
|
||||||
@@ -103,30 +114,38 @@ void main()
|
|||||||
|
|
||||||
int start = int(LightGrids.Data[currentTile].Start);
|
int start = int(LightGrids.Data[currentTile].Start);
|
||||||
int amount = int(LightGrids.Data[currentTile].Amount);
|
int amount = int(LightGrids.Data[currentTile].Amount);
|
||||||
//for(int i = 0; i < 3; i++)
|
|
||||||
for(int i = start; i < start + amount; i++)
|
for(int i = start; i < start + amount; i++) {
|
||||||
{
|
|
||||||
int l = int(LightIndex[i]);
|
int l = int(LightIndex[i]);
|
||||||
|
LightSource light = LightSources.List[l];
|
||||||
|
|
||||||
LightResult result = CalcPointLight(V * PointLights.List[l].Position, PointLights.List[l].Radius, PointLights.List[l].Color, PointLights.List[l].Intensity, viewVec, position, normal, PointLights.List[i].Falloff);
|
LightResult result;
|
||||||
|
if(light.Type == 1) { // point
|
||||||
|
result = CalcPointLightSource(V * light.Position, light.Radius, light.Color, light.Intensity, viewVec, position, normal, light.Falloff);
|
||||||
|
} else if (light.Type == 2) { //Directional
|
||||||
|
result = CalcDirectionalLightSource(V * light.Direction, light.Color, light.Intensity, viewVec, normal);
|
||||||
|
}
|
||||||
totalLighting.Diffuse += result.Diffuse;
|
totalLighting.Diffuse += result.Diffuse;
|
||||||
totalLighting.Specular += result.Specular;
|
totalLighting.Specular += result.Specular;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//fragmentColor += Input.DiffuseColor;
|
||||||
fragmentColor += Input.DiffuseColor * (totalLighting.Diffuse + totalLighting.Specular) * texel * Color;
|
fragmentColor += Input.DiffuseColor * (totalLighting.Diffuse + totalLighting.Specular) * texel * Color;
|
||||||
//fragmentColor += Input.DiffuseColor * (totalLighting.Diffuse) * texel * Color;
|
//fragmentColor += Input.DiffuseColor * (totalLighting.Diffuse) * texel * Color;
|
||||||
//fragmentColor += vec4(0.0, LightGrids.Data[currentTile].Amount/3.0, 0, 1);
|
//fragmentColor += Input.DiffuseColor + vec4(0.0, LightGrids.Data[currentTile].Amount/3, 0, 1);
|
||||||
//fragmentColor = texel * Input.DiffuseColor * Color;
|
//fragmentColor = texel * Input.DiffuseColor * Color;
|
||||||
if(int(gl_FragCoord.x)%16 == 0 || int(gl_FragCoord.y)%16 == 0 )
|
//fragmentColor += vec4(currentTile/3600.f, 0, 0, 1);
|
||||||
{
|
|
||||||
//fragmentColor += vec4(0.5, 0, 0, 0);
|
//Tiled Debug Code
|
||||||
|
/*
|
||||||
|
if(int(gl_FragCoord.x)%16 == 0 || int(gl_FragCoord.y)%16 == 0 ) {
|
||||||
|
fragmentColor += vec4(0.5, 0, 0, 0);
|
||||||
} else {
|
} else {
|
||||||
//fragmentColor += vec4(LightGrids.Data[int(tilePos.x + tilePos.y*80)].Amount/3.0, 0, 0, 1);
|
fragmentColor += vec4(LightGrids.Data[int(tilePos.x + tilePos.y*80)].Amount/LightSources.List.length(), 0, 0, 1);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,6 @@ void main()
|
|||||||
|
|
||||||
Output.Position = Position;
|
Output.Position = Position;
|
||||||
Output.TextureCoordinate = TextureCoords;
|
Output.TextureCoordinate = TextureCoords;
|
||||||
Output.Normal = Normal;
|
Output.Normal = vec3(M * vec4(Normal, 0.0));
|
||||||
Output.DiffuseColor = DiffuseVertexColor;
|
Output.DiffuseColor = DiffuseVertexColor;
|
||||||
}
|
}
|
||||||
@@ -40,15 +40,14 @@ void LightCullingPass::OnResolutionChange()
|
|||||||
|
|
||||||
void LightCullingPass::SetSSBOSizes()
|
void LightCullingPass::SetSSBOSizes()
|
||||||
{
|
{
|
||||||
m_NumberOfTiles = (int)(m_Renderer->Resolution().Width*m_Renderer->Resolution().Height)/TILE_SIZE;
|
m_NumberOfTiles = (int)(m_Renderer->Resolution().Width/TILE_SIZE) * (int)(m_Renderer->Resolution().Height/TILE_SIZE);
|
||||||
|
|
||||||
//m_Frustums = new Frustum[s];
|
|
||||||
//m_LightGrid = new LightGrid[s];
|
|
||||||
//m_LightIndex = new float[s*200];
|
|
||||||
|
|
||||||
m_Frustums = new Frustum[m_NumberOfTiles];
|
m_Frustums = new Frustum[m_NumberOfTiles];
|
||||||
m_LightGrid = new LightGrid[m_NumberOfTiles];
|
m_LightGrid = new LightGrid[m_NumberOfTiles];
|
||||||
m_LightIndex = new float[m_NumberOfTiles*MAX_LIGHTS_PER_TILE];
|
m_LightIndex = new float[m_NumberOfTiles*MAX_LIGHTS_PER_TILE];
|
||||||
|
for (int i = 0; i < m_NumberOfTiles*MAX_LIGHTS_PER_TILE; i++) {
|
||||||
|
m_LightIndex[i] = -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LightCullingPass::CullLights(RenderScene& scene)
|
void LightCullingPass::CullLights(RenderScene& scene)
|
||||||
@@ -59,8 +58,8 @@ void LightCullingPass::CullLights(RenderScene& scene)
|
|||||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, m_LightOffsetSSBO);
|
glBindBuffer(GL_SHADER_STORAGE_BUFFER, m_LightOffsetSSBO);
|
||||||
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(m_LightOffset), &m_LightOffset, GL_DYNAMIC_COPY);
|
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(m_LightOffset), &m_LightOffset, GL_DYNAMIC_COPY);
|
||||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, m_LightSSBO);
|
glBindBuffer(GL_SHADER_STORAGE_BUFFER, m_LightSSBO);
|
||||||
if (m_PointLights.size() > 0) {
|
if (m_LightSources.size() > 0) {
|
||||||
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(PointLight) * m_PointLights.size(), &(m_PointLights[0]), GL_DYNAMIC_COPY);
|
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(LightSource) * m_LightSources.size(), &(m_LightSources[0]), GL_DYNAMIC_COPY);
|
||||||
} else {
|
} else {
|
||||||
GLfloat zero = 0.f;
|
GLfloat zero = 0.f;
|
||||||
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(GLfloat), &zero , GL_DYNAMIC_COPY);
|
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(GLfloat), &zero , GL_DYNAMIC_COPY);
|
||||||
@@ -75,27 +74,38 @@ void LightCullingPass::CullLights(RenderScene& scene)
|
|||||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, m_LightGridSSBO);
|
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, m_LightGridSSBO);
|
||||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, m_LightOffsetSSBO);
|
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, m_LightOffsetSSBO);
|
||||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 4, m_LightIndexSSBO);
|
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 4, m_LightIndexSSBO);
|
||||||
glDispatchCompute(m_Renderer->Resolution().Width / TILE_SIZE, m_Renderer->Resolution().Height / TILE_SIZE, 1);
|
glDispatchCompute(glm::ceil(m_Renderer->Resolution().Width / TILE_SIZE), glm::ceil(m_Renderer->Resolution().Height / TILE_SIZE), 1);
|
||||||
|
|
||||||
GLERROR("CullLights Error: End");
|
GLERROR("CullLights Error: End");
|
||||||
}
|
}
|
||||||
|
|
||||||
void LightCullingPass::FillLightList(RenderScene& scene)
|
void LightCullingPass::FillLightList(RenderScene& scene)
|
||||||
{
|
{
|
||||||
m_PointLights.clear();
|
m_LightSources.clear();
|
||||||
|
|
||||||
for(auto &job : scene.PointLightJobs) {
|
for(auto &job : scene.PointLightJobs) {
|
||||||
auto pointLightjob = std::dynamic_pointer_cast<PointLightJob>(job);
|
auto pointLightjob = std::dynamic_pointer_cast<PointLightJob>(job);
|
||||||
if (pointLightjob) {
|
if (pointLightjob) {
|
||||||
PointLight p;
|
LightSource p;
|
||||||
p.Color = pointLightjob->Color;
|
p.Color = pointLightjob->Color;
|
||||||
p.Falloff = pointLightjob->Falloff;
|
p.Falloff = pointLightjob->Falloff;
|
||||||
p.Intensity = pointLightjob->Intensity;
|
p.Intensity = pointLightjob->Intensity;
|
||||||
p.Position = glm::vec4(glm::vec3(pointLightjob->Position), 1.f);
|
p.Position = glm::vec4(glm::vec3(pointLightjob->Position), 1.f);
|
||||||
p.Radius = pointLightjob->Radius;
|
p.Radius = pointLightjob->Radius;
|
||||||
p.Padding = 123.f;
|
//p.Padding = 123.f;
|
||||||
m_PointLights.push_back(p);
|
p.Type = LightSource::Point;
|
||||||
continue;
|
m_LightSources.push_back(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(auto &job : scene.DirectionalLightJobs) {
|
||||||
|
auto directionalLightJob = std::dynamic_pointer_cast<DirectionalLightJob>(job);
|
||||||
|
if(directionalLightJob) {
|
||||||
|
LightSource p;
|
||||||
|
p.Direction = directionalLightJob->Direction;
|
||||||
|
p.Color = directionalLightJob->Color;
|
||||||
|
p.Intensity = directionalLightJob->Intensity;
|
||||||
|
p.Type = LightSource::Directional;
|
||||||
|
m_LightSources.push_back(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -104,25 +114,22 @@ void LightCullingPass::InitializeSSBOs()
|
|||||||
{
|
{
|
||||||
glGenBuffers(1, &m_FrustumSSBO);
|
glGenBuffers(1, &m_FrustumSSBO);
|
||||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, m_FrustumSSBO);
|
glBindBuffer(GL_SHADER_STORAGE_BUFFER, m_FrustumSSBO);
|
||||||
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(Frustum)*m_NumberOfTiles, m_Frustums, GL_DYNAMIC_COPY);
|
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(Frustum)*m_NumberOfTiles, nullptr, GL_DYNAMIC_COPY);
|
||||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
|
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
|
||||||
GLERROR("m_FrustumSSBO");
|
GLERROR("m_FrustumSSBO");
|
||||||
|
|
||||||
glGenBuffers(1, &m_LightSSBO);
|
glGenBuffers(1, &m_LightSSBO);
|
||||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, m_LightSSBO);
|
glBindBuffer(GL_SHADER_STORAGE_BUFFER, m_LightSSBO);
|
||||||
if(m_PointLights.size() > 0) {
|
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(LightSource) * 200, nullptr, GL_DYNAMIC_COPY);
|
||||||
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(PointLight) * m_PointLights.size(), &(m_PointLights[0]), GL_DYNAMIC_COPY);
|
|
||||||
}
|
|
||||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
|
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
|
||||||
GLERROR("m_LightSSBO");
|
GLERROR("m_LightSSBO");
|
||||||
|
|
||||||
glGenBuffers(1, &m_LightGridSSBO);
|
glGenBuffers(1, &m_LightGridSSBO);
|
||||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, m_LightGridSSBO);
|
glBindBuffer(GL_SHADER_STORAGE_BUFFER, m_LightGridSSBO);
|
||||||
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(LightGrid)*m_NumberOfTiles, m_LightGrid, GL_DYNAMIC_COPY);
|
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(LightGrid)*m_NumberOfTiles, nullptr, GL_DYNAMIC_COPY);
|
||||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
|
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
|
||||||
GLERROR("m_LightGridSSBO");
|
GLERROR("m_LightGridSSBO");
|
||||||
|
|
||||||
|
|
||||||
glGenBuffers(1, &m_LightOffsetSSBO);
|
glGenBuffers(1, &m_LightOffsetSSBO);
|
||||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, m_LightOffsetSSBO);
|
glBindBuffer(GL_SHADER_STORAGE_BUFFER, m_LightOffsetSSBO);
|
||||||
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(m_LightOffset), &m_LightOffset, GL_DYNAMIC_COPY);
|
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(m_LightOffset), &m_LightOffset, GL_DYNAMIC_COPY);
|
||||||
|
|||||||
@@ -114,25 +114,45 @@ void RenderSystem::fillModels(std::list<std::shared_ptr<RenderJob>>& jobs, World
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void RenderSystem::fillLight(std::list<std::shared_ptr<RenderJob>>& jobs, World* world)
|
void RenderSystem::fillPointLights(std::list<std::shared_ptr<RenderJob>>& jobs, World* world)
|
||||||
{
|
{
|
||||||
auto pointLights = world->GetComponents("PointLight");
|
auto pointLights = world->GetComponents("PointLight");
|
||||||
if (pointLights == nullptr) {
|
if (pointLights != nullptr) {
|
||||||
return;
|
for (auto& pointlightC : *pointLights) {
|
||||||
|
bool visible = pointlightC["Visible"];
|
||||||
|
if (!visible) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
auto transformC = world->GetComponent(pointlightC.EntityID, "Transform");
|
||||||
|
if (&transformC == nullptr) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<PointLightJob> pointLightJob = std::shared_ptr<PointLightJob>(new PointLightJob(transformC, pointlightC, m_World));
|
||||||
|
jobs.push_back(pointLightJob);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (auto& pointlightC : *pointLights) {
|
|
||||||
bool visible = pointlightC["Visible"];
|
|
||||||
if (!visible) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
auto transformC = world->GetComponent(pointlightC.EntityID, "Transform");
|
|
||||||
if (&transformC == nullptr) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<PointLightJob> pointLightJob = std::shared_ptr<PointLightJob>(new PointLightJob(transformC, pointlightC, m_World));
|
void RenderSystem::fillDirectionalLights(std::list<std::shared_ptr<RenderJob>>& jobs, World* world)
|
||||||
jobs.push_back(pointLightJob);
|
{
|
||||||
|
auto directionalLights = world->GetComponents("DirectionalLight");
|
||||||
|
if (directionalLights != nullptr) {
|
||||||
|
for (auto& directionalLightC : *directionalLights) {
|
||||||
|
bool visable = directionalLightC["Visible"];
|
||||||
|
if (!visable) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto transformC = world->GetComponent(directionalLightC.EntityID, "Transform");
|
||||||
|
if (&transformC == nullptr) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<DirectionalLightJob> directionalLightJob = std::shared_ptr<DirectionalLightJob>(new DirectionalLightJob(transformC, directionalLightC, m_World));
|
||||||
|
jobs.push_back(directionalLightJob);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,7 +216,8 @@ void RenderSystem::Update(World* world, double dt)
|
|||||||
scene.Camera = m_Camera;
|
scene.Camera = m_Camera;
|
||||||
scene.Viewport = Rectangle(1280, 720);
|
scene.Viewport = Rectangle(1280, 720);
|
||||||
fillModels(scene.ForwardJobs, world);
|
fillModels(scene.ForwardJobs, world);
|
||||||
fillLight(scene.PointLightJobs, world);
|
fillPointLights(scene.PointLightJobs, world);
|
||||||
|
fillDirectionalLights(scene.DirectionalLightJobs, world);
|
||||||
fillText(scene.TextJobs, world);
|
fillText(scene.TextJobs, world);
|
||||||
m_RenderFrame->Add(scene);
|
m_RenderFrame->Add(scene);
|
||||||
|
|
||||||
|
|||||||
@@ -102,9 +102,8 @@ void Renderer::Draw(RenderFrame& frame)
|
|||||||
|
|
||||||
m_PickingPass->ClearPicking();
|
m_PickingPass->ClearPicking();
|
||||||
for (auto scene : frame.RenderScenes){
|
for (auto scene : frame.RenderScenes){
|
||||||
|
|
||||||
m_Camera = scene->Camera; // remove renderer camera when Editor uses the render scene cameras.
|
m_Camera = scene->Camera; // remove renderer camera when Editor uses the render scene cameras.
|
||||||
FillDepth(*scene);
|
SortRenderJobsByDepth(*scene);
|
||||||
m_PickingPass->Draw(*scene);
|
m_PickingPass->Draw(*scene);
|
||||||
m_LightCullingPass->GenerateNewFrustum(*scene);
|
m_LightCullingPass->GenerateNewFrustum(*scene);
|
||||||
m_LightCullingPass->FillLightList(*scene);
|
m_LightCullingPass->FillLightList(*scene);
|
||||||
@@ -155,6 +154,13 @@ void Renderer::InitializeTextures()
|
|||||||
m_WhiteTexture = ResourceManager::Load<Texture>("Textures/Core/Blank.png");
|
m_WhiteTexture = ResourceManager::Load<Texture>("Textures/Core/Blank.png");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Renderer::SortRenderJobsByDepth(RenderScene &scene)
|
||||||
|
{
|
||||||
|
//Sort all forward jobs so transparency is good.
|
||||||
|
scene.ForwardJobs.sort(Renderer::DepthSort);
|
||||||
|
}
|
||||||
|
|
||||||
void Renderer::GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type)
|
void Renderer::GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type)
|
||||||
{
|
{
|
||||||
glGenTextures(1, texture);
|
glGenTextures(1, texture);
|
||||||
@@ -173,21 +179,4 @@ void Renderer::InitializeRenderPasses()
|
|||||||
m_PickingPass = new PickingPass(this, m_EventBroker);
|
m_PickingPass = new PickingPass(this, m_EventBroker);
|
||||||
m_LightCullingPass = new LightCullingPass(this);
|
m_LightCullingPass = new LightCullingPass(this);
|
||||||
m_DrawFinalPass = new DrawFinalPass(this, m_LightCullingPass);
|
m_DrawFinalPass = new DrawFinalPass(this, m_LightCullingPass);
|
||||||
}
|
|
||||||
|
|
||||||
//Temp func
|
|
||||||
void Renderer::FillDepth(RenderScene& scene)
|
|
||||||
{
|
|
||||||
for (auto job : scene.ForwardJobs) {
|
|
||||||
auto modelJob = std::dynamic_pointer_cast<ModelJob>(job);
|
|
||||||
if(! modelJob) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
glm::vec3 abspos = Transform::AbsolutePosition(modelJob->World, modelJob->Entity);
|
|
||||||
glm::vec3 worldpos = glm::vec3(scene.Camera->ViewMatrix() * glm::vec4(abspos, 1));
|
|
||||||
modelJob->Depth = worldpos.z;
|
|
||||||
}
|
|
||||||
scene.ForwardJobs.sort(Renderer::DepthSort);
|
|
||||||
}
|
}
|
||||||
+2
-3
@@ -30,7 +30,7 @@ Game::Game(int argc, char* argv[])
|
|||||||
|
|
||||||
|
|
||||||
// Create the renderer
|
// Create the renderer
|
||||||
m_Renderer = new Renderer(m_EventBroker, m_World);
|
m_Renderer = new Renderer(m_EventBroker);
|
||||||
m_Renderer->SetFullscreen(m_Config->Get<bool>("Video.Fullscreen", false));
|
m_Renderer->SetFullscreen(m_Config->Get<bool>("Video.Fullscreen", false));
|
||||||
m_Renderer->SetVSYNC(m_Config->Get<bool>("Video.VSYNC", false));
|
m_Renderer->SetVSYNC(m_Config->Get<bool>("Video.VSYNC", false));
|
||||||
m_Renderer->SetResolution(Rectangle::Rectangle(
|
m_Renderer->SetResolution(Rectangle::Rectangle(
|
||||||
@@ -65,8 +65,7 @@ Game::Game(int argc, char* argv[])
|
|||||||
EntityFileParser fp(file);
|
EntityFileParser fp(file);
|
||||||
fp.MergeEntities(m_World);
|
fp.MergeEntities(m_World);
|
||||||
}
|
}
|
||||||
//SO MUCH TEMP PLEASE REMOVE ME OMFG VIKTOR HELP
|
|
||||||
m_Renderer->m_World = m_World;
|
|
||||||
|
|
||||||
// Create Octrees
|
// Create Octrees
|
||||||
m_OctreeCollision = new Octree(AABB(glm::vec3(-100), glm::vec3(100)), 4);
|
m_OctreeCollision = new Octree(AABB(glm::vec3(-100), glm::vec3(100)), 4);
|
||||||
|
|||||||
Reference in New Issue
Block a user