Pointlights are now using the pointlight component and the Light renderqueue to draw.

This commit is contained in:
Tleety
2016-01-08 14:12:09 +01:00
parent 25a99a04c5
commit dab4ba2164
5 changed files with 67 additions and 19 deletions
+2 -3
View File
@@ -17,6 +17,7 @@ public:
void GenerateNewFrustum();
void CullLights();
void FillLightList(RenderQueueCollection& rq);
GLuint FrustumSSBO() const { return m_FrustumSSBO; }
GLuint LightSSBO() const { return m_LightSSBO; }
@@ -49,8 +50,6 @@ private:
};
Frustum m_Frustums[80*45]; //TODO: Renderer: Make this change with resolution
void TEMPCreateLights();
//This should be a component
struct PointLight {
glm::vec4 Position = glm::vec4(0.f);
@@ -60,7 +59,7 @@ private:
float Falloff = 0.3f;
float Padding = 1337;
};
PointLight m_PointLights[NUM_LIGHTS];
std::vector<PointLight> m_PointLights;
struct LightGrid {
float Start;
+6 -5
View File
@@ -82,11 +82,12 @@ struct SpriteJob : RenderJob
struct PointLightJob : RenderJob
{
glm::vec3 Position;
glm::vec3 SpecularColor = glm::vec3(1, 1, 1);
glm::vec3 DiffuseColor = glm::vec3(1, 1, 1);
float Radius = 1.f;
float Intensity = 0.8f;
glm::vec4 Position;
glm::vec4 Color;
float Radius;
float Intensity;
float Falloff;
float padding = 123;
void CalculateHash() override
{
+30 -11
View File
@@ -3,7 +3,6 @@
LightCullingPass::LightCullingPass(IRenderer* renderer)
{
m_Renderer = renderer;
TEMPCreateLights();
InitializeSSBOs();
InitializeShaderPrograms();
GenerateNewFrustum();
@@ -35,6 +34,14 @@ void LightCullingPass::CullLights()
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);
} else {
GLfloat zero = 0.f;
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(GLfloat), &zero , GL_DYNAMIC_COPY);
}
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
m_LightCullProgram->Bind();
@@ -49,6 +56,25 @@ void LightCullingPass::CullLights()
GLERROR("CullLights Error: End");
}
void LightCullingPass::FillLightList(RenderQueueCollection& rq)
{
m_PointLights.clear();
for(auto &job : rq.Lights) {
auto pointLightjob = std::dynamic_pointer_cast<PointLightJob>(job);
if (pointLightjob) {
PointLight 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;
}
}
}
void LightCullingPass::InitializeSSBOs()
{
glGenBuffers(1, &m_FrustumSSBO);
@@ -59,7 +85,9 @@ void LightCullingPass::InitializeSSBOs()
glGenBuffers(1, &m_LightSSBO);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, m_LightSSBO);
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(m_PointLights), &m_PointLights, GL_DYNAMIC_COPY);
if(m_PointLights.size() > 0) {
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(PointLight) * m_PointLights.size(), &(m_PointLights[0]), GL_DYNAMIC_COPY);
}
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
GLERROR("m_LightSSBO");
@@ -96,12 +124,3 @@ void LightCullingPass::InitializeShaderPrograms()
m_LightCullProgram->Link();
}
void LightCullingPass::TEMPCreateLights()
{
for (int i = 0; i < NUM_LIGHTS; i++) {
glm::vec3 pos = glm::vec3(cos(i) * i/10.f, 0.5f, sin(i) * i/10.f);
m_PointLights[i].Position = glm::vec4(pos, 1.f);
m_PointLights[i].Color = glm::vec4(rand()%255 / 255.f, rand()%255 / 255.f, rand()%255 / 255.f, 1.f);
m_PointLights[i].Radius = glm::length(pos) / 5.f;
}
}
@@ -111,6 +111,34 @@ void RenderQueueFactory::FillModels(World* world, RenderQueue* renderQueue)
void RenderQueueFactory::FillLights(World* world, RenderQueue* renderQueue)
{
auto pointLights = world->GetComponents("PointLight");
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) {
return;
}
glm::vec4 color = pointlightC["Color"];
float radius = (double)pointlightC["Radius"];
float intensity = (double)pointlightC["Intensity"];
float falloff = (double)pointlightC["Falloff"];
PointLightJob job;
job.Position = transformC["Position"];
job.Color = color;
job.Radius = radius;
job.Intensity = intensity;
job.Falloff = falloff;
renderQueue->Add(job);
}
}
+1
View File
@@ -92,6 +92,7 @@ void Renderer::Draw(RenderQueueCollection& rq)
{
m_PickingPass->Draw(rq);
//DrawScreenQuad(m_PickingPass->PickingTexture());
m_LightCullingPass->FillLightList(rq);
m_LightCullingPass->CullLights();
//m_DrawScenePass->Draw(rq);