diff --git a/assets b/assets index 6cbf2365..2fca9181 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 6cbf2365d49e6280750ea3bcd0f9c271779e6f15 +Subproject commit 2fca918162535c859c6adbe433e69fad8ea931b6 diff --git a/include/Engine/Rendering/LightCullingPass.h b/include/Engine/Rendering/LightCullingPass.h index 2fc1cbfc..954444da 100644 --- a/include/Engine/Rendering/LightCullingPass.h +++ b/include/Engine/Rendering/LightCullingPass.h @@ -56,15 +56,16 @@ 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(0.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 { Point, Directional, Spot } Type; }; - std::vector m_PointLights; + std::vector m_LightSources; struct LightGrid { float Start; diff --git a/resources/Shaders/CullLights.comp.glsl b/resources/Shaders/CullLights.comp.glsl index c2675f20..f2908ecc 100644 --- a/resources/Shaders/CullLights.comp.glsl +++ b/resources/Shaders/CullLights.comp.glsl @@ -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 == 0) { + 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 == 1) { + AppendLight( i ); + } } diff --git a/resources/Shaders/ForwardPlus.frag.glsl b/resources/Shaders/ForwardPlus.frag.glsl index 3d5b9bfd..713e3621 100644 --- a/resources/Shaders/ForwardPlus.frag.glsl +++ b/resources/Shaders/ForwardPlus.frag.glsl @@ -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 CalcLightSource(vec4 lightPos, float lightRadius, vec4 lightColor, float intensity, vec4 viewVec, vec4 position, vec4 normal, float falloff) { vec4 L = lightPos - position; float dist = length(L); @@ -108,15 +109,15 @@ void main() { int l = int(LightIndex[i]); - 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 = CalcLightSource(V * LightSources.List[l].Position, LightSources.List[l].Radius, LightSources.List[l].Color, LightSources.List[l].Intensity, viewVec, position, normal, LightSources.List[i].Falloff); totalLighting.Diffuse += result.Diffuse; totalLighting.Specular += result.Specular; } - 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 += vec4(0.0, LightGrids.Data[currentTile].Amount/3.0, 0, 1); + fragmentColor += Input.DiffuseColor + vec4(0.0, LightGrids.Data[currentTile].Amount/3.0, 0, 1); //fragmentColor = texel * Input.DiffuseColor * Color; if(int(gl_FragCoord.x)%16 == 0 || int(gl_FragCoord.y)%16 == 0 ) { diff --git a/src/Engine/Rendering/LightCullingPass.cpp b/src/Engine/Rendering/LightCullingPass.cpp index e59a50c0..d9cc8249 100644 --- a/src/Engine/Rendering/LightCullingPass.cpp +++ b/src/Engine/Rendering/LightCullingPass.cpp @@ -59,8 +59,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); @@ -82,19 +82,20 @@ void LightCullingPass::CullLights(RenderScene& scene) void LightCullingPass::FillLightList(RenderScene& scene) { - m_PointLights.clear(); + m_LightSources.clear(); for(auto &job : scene.PointLightJobs) { auto pointLightjob = std::dynamic_pointer_cast(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); + //p.Padding = 123.f; + p.Type = LightSource::Point; + m_LightSources.push_back(p); continue; } } @@ -110,8 +111,8 @@ void LightCullingPass::InitializeSSBOs() 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); + if(m_LightSources.size() > 0) { + glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(LightSource) * m_LightSources.size(), &(m_LightSources[0]), GL_DYNAMIC_COPY); } glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0); GLERROR("m_LightSSBO");