Merge pull request #39 from teamfisk/Forward+

Forward+
This commit is contained in:
Joachim Pettersson
2016-01-19 16:53:07 +01:00
19 changed files with 260 additions and 106 deletions
+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
+9 -8
View File
@@ -46,8 +46,8 @@ private:
int m_NumberOfTiles = 0;
struct Plane {
glm::vec3 Normal;
float d;
glm::vec3 Normal = glm::vec3(0.f);
float d = 0;
};
struct Frustum {
@@ -56,20 +56,21 @@ private:
Frustum* m_Frustums;
//This should be a component
struct PointLight {
struct LightSource {
glm::vec4 Position = glm::vec4(0.f);
glm::vec4 Direction = glm::vec4(10.f);
glm::vec4 Color = glm::vec4(1.f);
float Radius = 5.f;
float Intensity = 0.8f;
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 {
float Start;
float Amount;
glm::vec2 Padding;
float Start = 0;
float Amount = 0;
glm::vec2 Padding = glm::vec2(1.f, 2.f);
};
LightGrid* m_LightGrid;
+4
View File
@@ -12,6 +12,7 @@
#include "../Core/ResourceManager.h"
#include "Camera.h"
#include "../Core/World.h"
#include "../Core/Transform.h"
struct ModelJob : RenderJob
{
@@ -28,6 +29,9 @@ struct ModelJob : RenderJob
Matrix = matrix;
Color = modelComponent["Color"];
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;
};
+3
View File
@@ -12,6 +12,7 @@
#include "RenderJob.h"
#include "ModelJob.h"
#include "PointLightJob.h"
#include "DirectionalLightJob.h"
/*
@@ -53,12 +54,14 @@ struct RenderScene
::Camera* Camera;
std::list<std::shared_ptr<RenderJob>> ForwardJobs;
std::list<std::shared_ptr<RenderJob>> PointLightJobs;
std::list<std::shared_ptr<RenderJob>> DirectionalLightJobs;
Rectangle Viewport;
void Clear()
{
ForwardJobs.clear();
PointLightJobs.clear();
DirectionalLightJobs.clear();
}
};
+2 -1
View File
@@ -46,7 +46,8 @@ private:
void updateProjectionMatrix(ComponentWrapper& cameraComponent);
void fillModels(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;
bool OnInputCommand(const Events::InputCommand& e);
+2 -4
View File
@@ -22,9 +22,8 @@
class Renderer : public IRenderer
{
public:
Renderer(EventBroker* eventBroker, World* world)
Renderer(EventBroker* eventBroker)
: m_EventBroker(eventBroker)
, m_World(world)
{ }
virtual void Initialize() override;
@@ -36,7 +35,6 @@ public:
private:
//----------------------Variables----------------------//
EventBroker* m_EventBroker;
World* m_World;
Texture* m_ErrorTexture;
Texture* m_WhiteTexture;
@@ -62,7 +60,7 @@ private:
void DrawScreenQuad(GLuint textureToDraw);
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);
//--------------------ShaderPrograms-------------------//
ShaderProgram* m_BasicForwardProgram;
+1
View File
@@ -9,6 +9,7 @@
<xs:include schemaLocation="Components/Camera.xsd"/>
<xs:include schemaLocation="Components/AABB.xsd"/>
<xs:include schemaLocation="Components/PointLight.xsd"/>
<xs:include schemaLocation="Components/DirectionalLight.xsd"/>
<xs:include schemaLocation="Components/Trigger.xsd"/>
<xs:include schemaLocation="Components/Health.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>
+52 -2
View File
@@ -13,6 +13,7 @@
</c:Model>
<c:Transform>
<Scale X="100" Y="1" Z="100"/>
<Orientation X="0" Y="2.59200001" Z="0"/>
</c:Transform>
</Components>
<Children/>
@@ -45,9 +46,58 @@
<Entity>
<Components>
<c:Camera/>
<c:Listener/>
<c:Transform>
<Position X="5.85247707" Y="3.8454349" Z="-1.14486957"/>
<Orientation X="2.51327395" Y="1.23916209" Z="-3.1415925"/>
<Position X="1.36896265" Y="4.4259491" Z="10.6640663"/>
<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>
</Components>
<Children/>
+1
View File
@@ -27,6 +27,7 @@
<xs:element ref="c:SpawnPoint" minOccurs="0"/>
<xs:element ref="c:PlayerSpawn" minOccurs="0"/>
<xs:element ref="c:Team" minOccurs="0"/>
<xs:element ref="c:DirectionalLight" minOccurs="0"/>
</xs:all>
</xs:complexType>
</xs:element>
+16 -13
View File
@@ -27,19 +27,20 @@ layout (std430, binding = 0) buffer FrustumBuffer
Frustum Data[];
} Frustums;
struct PointLight {
struct LightSource {
vec4 Position;
vec4 Direction;
vec4 Color;
float Radius;
float Intensity;
float Falloff;
float Padding;
int Type;
};
layout (std430, binding = 1) buffer LightBuffer
{
PointLight List[];
} PointLights;
LightSource List[];
} LightSources;
struct LightGrid {
float Start;
@@ -106,8 +107,7 @@ layout (local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
void main ()
{
GroupIndex = int(gl_WorkGroupID.x + (gl_WorkGroupID.y * int(ScreenDimensions.x/TILE_SIZE)));
if(gl_LocalInvocationIndex == 0)
{
if(gl_LocalInvocationIndex == 0) {
GroupLightCount = 0;
GroupFrustum = Frustums.Data[GroupIndex];
}
@@ -115,22 +115,25 @@ void main ()
barrier();
memoryBarrierShared();
for(int i = int(gl_LocalInvocationIndex); i < PointLights.List.length(); i += TILE_SIZE*TILE_SIZE)
{
PointLight light = PointLights.List[i];
for(int i = int(gl_LocalInvocationIndex); i < LightSources.List.length(); i += TILE_SIZE*TILE_SIZE) {
LightSource light = LightSources.List[i];
//if pointlight
//Pos i view antagligen
if(SphereInsideFrustrum( vec3(V * light.Position), light.Radius, GroupFrustum))
{
//TODO: Fix transparent and opaque list, and depth test.
AppendLight( i );
if(light.Type == 1) {
if(SphereInsideFrustrum( vec3(V * light.Position), light.Radius, GroupFrustum)) {
//TODO: Fix transparent and opaque list, and depth test.
AppendLight( i );
}
}
//if conelight
//if directional
if(light.Type == 2) {
AppendLight( i );
}
}
+39 -20
View File
@@ -9,19 +9,20 @@ uniform sampler2D texture0;
#define TILE_SIZE 16
struct PointLight {
struct LightSource {
vec4 Position;
vec4 Direction;
vec4 Color;
float Radius;
float Intensity;
float Falloff;
float Padding;
int Type;
};
layout (std430, binding = 1) buffer LightBuffer
{
PointLight List[];
} PointLights;
LightSource List[];
} LightSources;
struct LightGrid {
float Start;
@@ -71,7 +72,7 @@ vec4 CalcDiffuse(vec4 lightColor, vec4 lightVec, vec4 normal) {
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;
float dist = length(L);
@@ -85,6 +86,16 @@ LightResult CalcPointLight(vec4 lightPos, float lightRadius, vec4 lightColor, fl
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()
{
@@ -94,8 +105,8 @@ void main()
vec4 viewVec = normalize(-position);
vec2 tilePos;
tilePos.x = int(gl_FragCoord.x/16);
tilePos.y = int(gl_FragCoord.y/16);
tilePos.x = int(gl_FragCoord.x/TILE_SIZE);
tilePos.y = int(gl_FragCoord.y/TILE_SIZE);
LightResult totalLighting;
totalLighting.Diffuse = scene_ambient;
@@ -103,30 +114,38 @@ void main()
int start = int(LightGrids.Data[currentTile].Start);
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]);
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.Specular += result.Specular;
}
//fragmentColor += Input.DiffuseColor;
fragmentColor += Input.DiffuseColor * (totalLighting.Diffuse + totalLighting.Specular) * 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;
if(int(gl_FragCoord.x)%16 == 0 || int(gl_FragCoord.y)%16 == 0 )
{
//fragmentColor += vec4(0.5, 0, 0, 0);
//fragmentColor += vec4(currentTile/3600.f, 0, 0, 1);
//Tiled Debug Code
/*
if(int(gl_FragCoord.x)%16 == 0 || int(gl_FragCoord.y)%16 == 0 ) {
fragmentColor += vec4(0.5, 0, 0, 0);
} 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);
}
*/
}
+1 -1
View File
@@ -29,6 +29,6 @@ void main()
Output.Position = Position;
Output.TextureCoordinate = TextureCoords;
Output.Normal = Normal;
Output.Normal = vec3(M * vec4(Normal, 0.0));
Output.DiffuseColor = DiffuseVertexColor;
}
+26 -19
View File
@@ -40,15 +40,14 @@ void LightCullingPass::OnResolutionChange()
void LightCullingPass::SetSSBOSizes()
{
m_NumberOfTiles = (int)(m_Renderer->Resolution().Width*m_Renderer->Resolution().Height)/TILE_SIZE;
//m_Frustums = new Frustum[s];
//m_LightGrid = new LightGrid[s];
//m_LightIndex = new float[s*200];
m_NumberOfTiles = (int)(m_Renderer->Resolution().Width/TILE_SIZE) * (int)(m_Renderer->Resolution().Height/TILE_SIZE);
m_Frustums = new Frustum[m_NumberOfTiles];
m_LightGrid = new LightGrid[m_NumberOfTiles];
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)
@@ -59,8 +58,8 @@ void LightCullingPass::CullLights(RenderScene& scene)
glBindBuffer(GL_SHADER_STORAGE_BUFFER, m_LightOffsetSSBO);
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(m_LightOffset), &m_LightOffset, GL_DYNAMIC_COPY);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, m_LightSSBO);
if (m_PointLights.size() > 0) {
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(PointLight) * m_PointLights.size(), &(m_PointLights[0]), GL_DYNAMIC_COPY);
if (m_LightSources.size() > 0) {
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(LightSource) * m_LightSources.size(), &(m_LightSources[0]), GL_DYNAMIC_COPY);
} else {
GLfloat zero = 0.f;
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, 3, m_LightOffsetSSBO);
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");
}
void LightCullingPass::FillLightList(RenderScene& scene)
{
m_PointLights.clear();
m_LightSources.clear();
for(auto &job : scene.PointLightJobs) {
auto pointLightjob = std::dynamic_pointer_cast<PointLightJob>(job);
if (pointLightjob) {
PointLight p;
LightSource p;
p.Color = pointLightjob->Color;
p.Falloff = pointLightjob->Falloff;
p.Intensity = pointLightjob->Intensity;
p.Position = glm::vec4(glm::vec3(pointLightjob->Position), 1.f);
p.Radius = pointLightjob->Radius;
p.Padding = 123.f;
m_PointLights.push_back(p);
continue;
//p.Padding = 123.f;
p.Type = LightSource::Point;
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);
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);
GLERROR("m_FrustumSSBO");
glGenBuffers(1, &m_LightSSBO);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, m_LightSSBO);
if(m_PointLights.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) * 200, nullptr, GL_DYNAMIC_COPY);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
GLERROR("m_LightSSBO");
glGenBuffers(1, &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);
GLERROR("m_LightGridSSBO");
glGenBuffers(1, &m_LightOffsetSSBO);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, m_LightOffsetSSBO);
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(m_LightOffset), &m_LightOffset, GL_DYNAMIC_COPY);
+36 -15
View File
@@ -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");
if (pointLights == nullptr) {
return;
if (pointLights != nullptr) {
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));
jobs.push_back(pointLightJob);
void RenderSystem::fillDirectionalLights(std::list<std::shared_ptr<RenderJob>>& jobs, World* world)
{
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);
}
}
}
@@ -160,7 +180,8 @@ void RenderSystem::Update(World* world, double dt)
scene.Camera = m_Camera;
scene.Viewport = Rectangle(1280, 720);
fillModels(scene.ForwardJobs, world);
fillLight(scene.PointLightJobs, world);
fillPointLights(scene.PointLightJobs, world);
fillDirectionalLights(scene.DirectionalLightJobs, world);
m_RenderFrame->Add(scene);
}
+8 -19
View File
@@ -98,9 +98,8 @@ void Renderer::Draw(RenderFrame& frame)
m_PickingPass->ClearPicking();
for (auto scene : frame.RenderScenes){
m_Camera = scene->Camera; // remove renderer camera when Editor uses the render scene cameras.
FillDepth(*scene);
SortRenderJobsByDepth(*scene);
m_PickingPass->Draw(*scene);
m_LightCullingPass->GenerateNewFrustum(*scene);
m_LightCullingPass->FillLightList(*scene);
@@ -147,6 +146,13 @@ void Renderer::InitializeTextures()
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)
{
glGenTextures(1, texture);
@@ -165,21 +171,4 @@ void Renderer::InitializeRenderPasses()
m_PickingPass = new PickingPass(this, m_EventBroker);
m_LightCullingPass = new LightCullingPass(this);
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
View File
@@ -29,7 +29,7 @@ Game::Game(int argc, char* argv[])
// 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->SetVSYNC(m_Config->Get<bool>("Video.VSYNC", false));
m_Renderer->SetResolution(Rectangle::Rectangle(
@@ -64,8 +64,7 @@ Game::Game(int argc, char* argv[])
EntityFileParser fp(file);
fp.MergeEntities(m_World);
}
//SO MUCH TEMP PLEASE REMOVE ME OMFG VIKTOR HELP
m_Renderer->m_World = m_World;
// Create Octrees
m_OctreeCollision = new Octree(AABB(glm::vec3(-100), glm::vec3(100)), 4);