From 4b29d48f27ecfef71d8f34510e3789b0132f568c Mon Sep 17 00:00:00 2001 From: Tleety Date: Mon, 18 Jan 2016 17:57:45 +0100 Subject: [PATCH] WIP --- .../Engine/Rendering/DirectionalLightJob.h | 2 +- include/Engine/Rendering/LightCullingPass.h | 2 +- resources/Shaders/CullLights.comp.glsl | 4 +-- resources/Shaders/ForwardPlus.frag.glsl | 25 ++++++------------- 4 files changed, 11 insertions(+), 22 deletions(-) diff --git a/include/Engine/Rendering/DirectionalLightJob.h b/include/Engine/Rendering/DirectionalLightJob.h index 83787833..92cd195a 100644 --- a/include/Engine/Rendering/DirectionalLightJob.h +++ b/include/Engine/Rendering/DirectionalLightJob.h @@ -15,7 +15,7 @@ struct DirectionalLightJob : RenderJob DirectionalLightJob(ComponentWrapper transformComponent, ComponentWrapper directionalLightComponent, World* m_World) : RenderJob() { - Direction = glm::vec4((glm::vec3)directionalLightComponent["Direction"], 1.f); + Direction = glm::vec4((glm::vec3)directionalLightComponent["Direction"], 0.f); Color = (glm::vec4)directionalLightComponent["Color"]; Intensity = (double)directionalLightComponent["Intensity"]; }; diff --git a/include/Engine/Rendering/LightCullingPass.h b/include/Engine/Rendering/LightCullingPass.h index ab50f650..7eb2c62d 100644 --- a/include/Engine/Rendering/LightCullingPass.h +++ b/include/Engine/Rendering/LightCullingPass.h @@ -63,7 +63,7 @@ private: float Radius = 5.f; float Intensity = 0.8f; float Falloff = 0.3f; - enum Type_t { Point, Directional, Spot } Type; + enum Type_t { Zero, Point, Directional, Spot } Type; }; std::vector m_LightSources; diff --git a/resources/Shaders/CullLights.comp.glsl b/resources/Shaders/CullLights.comp.glsl index f2908ecc..c32c6479 100644 --- a/resources/Shaders/CullLights.comp.glsl +++ b/resources/Shaders/CullLights.comp.glsl @@ -120,7 +120,7 @@ void main () //if pointlight //Pos i view antagligen - if(light.Type == 0) { + if(light.Type == 1) { if(SphereInsideFrustrum( vec3(V * light.Position), light.Radius, GroupFrustum)) { //TODO: Fix transparent and opaque list, and depth test. AppendLight( i ); @@ -131,7 +131,7 @@ void main () //if conelight //if directional - if(light.Type == 1) { + if(light.Type == 2) { AppendLight( i ); } diff --git a/resources/Shaders/ForwardPlus.frag.glsl b/resources/Shaders/ForwardPlus.frag.glsl index 087c594c..9f9140fb 100644 --- a/resources/Shaders/ForwardPlus.frag.glsl +++ b/resources/Shaders/ForwardPlus.frag.glsl @@ -88,7 +88,7 @@ LightResult CalcPointLightSource(vec4 lightPos, float lightRadius, vec4 lightCol LightResult CalcDirectionalLightSource(vec4 direction, vec4 color, float intensity, vec4 viewVec, vec4 vertPosition, vec4 vertNormal) { - vec4 L = normalize( -direction ); + vec4 L = normalize( vec4(direction.xyz, 1) ); LightResult result; result.Diffuse = CalcDiffuse(color, L, vertNormal) * intensity; @@ -119,9 +119,9 @@ void main() int l = int(LightIndex[i]); LightResult result; - if(LightSources.List[i].Type == 0) { // point - //result = CalcPointLightSource(V * LightSources.List[l].Position, LightSources.List[l].Radius, LightSources.List[l].Color, LightSources.List[l].Intensity, viewVec, position, normal, LightSources.List[i].Falloff); - } else if (LightSources.List[i].Type == 1) { //Directional + if(LightSources.List[i].Type == 1) { // point + result = CalcPointLightSource(V * LightSources.List[l].Position, LightSources.List[l].Radius, LightSources.List[l].Color, LightSources.List[l].Intensity, viewVec, position, normal, LightSources.List[i].Falloff); + } else if (LightSources.List[i].Type == 2) { //Directional result = CalcDirectionalLightSource(V * LightSources.List[l].Direction, LightSources.List[i].Color, LightSources.List[i].Intensity, viewVec, position, normal); } totalLighting.Diffuse += result.Diffuse; @@ -129,26 +129,15 @@ void main() } - fragmentColor += Input.DiffuseColor; - //fragmentColor += Input.DiffuseColor * (totalLighting.Diffuse + totalLighting.Specular) * texel * Color; + //fragmentColor += Input.DiffuseColor; + fragmentColor += Input.DiffuseColor * (totalLighting.Diffuse + totalLighting.Specular) * texel * Color; //fragmentColor += Input.DiffuseColor * (totalLighting.Diffuse) * texel * Color; - //fragmentColor += Input.DiffuseColor + vec4(0.0, LightGrids.Data[currentTile].Amount/3.0, 0, 1); - if(LightSources.List[0].Type == 0) { - fragmentColor += vec4(1,0,0,1); - } - if(LightSources.List[0].Type == 1) { - fragmentColor += vec4(0,1,0,1); - } - if(LightSources.List[0].Type == 2) { - fragmentColor += vec4(0,0,1,1); - } + //fragmentColor += Input.DiffuseColor + vec4(0.0, LightGrids.Data[currentTile].Start/.0, 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); } else { //fragmentColor += vec4(LightGrids.Data[int(tilePos.x + tilePos.y*80)].Amount/3.0, 0, 0, 1); - - } }