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:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,7 +216,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);
|
||||
fillText(scene.TextJobs, world);
|
||||
m_RenderFrame->Add(scene);
|
||||
|
||||
|
||||
@@ -102,9 +102,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);
|
||||
@@ -155,6 +154,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);
|
||||
@@ -173,21 +179,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);
|
||||
}
|
||||
Reference in New Issue
Block a user