From 33bc9a99eaac61ae38751fc78127859c66ef2e14 Mon Sep 17 00:00:00 2001
From: Alexander Gauggel <agauggel@uni-koblenz.de>
Date: Thu, 24 Jun 2021 21:00:10 +0200
Subject: [PATCH] [#82] Add small ambient light factor to volumetric lighting

---
 projects/voxelization/resources/shaders/lightInfo.inc | 9 +++++----
 projects/voxelization/resources/shaders/shader.frag   | 3 +++
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/projects/voxelization/resources/shaders/lightInfo.inc b/projects/voxelization/resources/shaders/lightInfo.inc
index 7cbf605e..a87f9ce7 100644
--- a/projects/voxelization/resources/shaders/lightInfo.inc
+++ b/projects/voxelization/resources/shaders/lightInfo.inc
@@ -2,10 +2,11 @@
 #define LIGHT_INFO_INC
 
 struct LightInfo{
-    vec3 L;             float padding;
-    vec3 sunColor;      
-    float sunStrength;
-    mat4 lightMatrix;
+    vec3    L;             
+    float   padding;
+    vec3    sunColor;      
+    float   sunStrength;
+    mat4    lightMatrix;
 };
 
 #endif // #ifndef LIGHT_INFO_INC
\ No newline at end of file
diff --git a/projects/voxelization/resources/shaders/shader.frag b/projects/voxelization/resources/shaders/shader.frag
index 0569abd1..ff8968ca 100644
--- a/projects/voxelization/resources/shaders/shader.frag
+++ b/projects/voxelization/resources/shaders/shader.frag
@@ -81,6 +81,7 @@ vec3 volumetricLighting(vec3 colorIn, vec3 V, vec3 pos, float d){
     vec3 scatteringCoefficient = vec3(0.005);
     vec3 absorptionCoefficient = vec3(0.01);
     vec3 extinctionCoefficient = scatteringCoefficient + absorptionCoefficient;
+    vec3 ambientLight          = vec3(0.2);
     
     float noiseScale    = 0.1;
     pos                 += V * noiseScale * interleavedGradientNoise(gl_FragCoord.xy);
@@ -91,6 +92,8 @@ vec3 volumetricLighting(vec3 colorIn, vec3 V, vec3 pos, float d){
         vec3    light       = lightInfo.sunColor * lightInfo.sunStrength;
         float   shadow      = shadowTest(samplePoint, lightInfo, shadowMap, shadowMapSampler, vec2(0));
         light               *= shadow;
+        light               += ambientLight;
+        
         color               += phase * light * scatteringCoefficient * stepSize;
         color               *= exp(-stepSize * extinctionCoefficient);
     }
-- 
GitLab