From c58728215f779fea111fcdca8fe17489659b92d1 Mon Sep 17 00:00:00 2001 From: schmelczerandras Date: Sat, 19 Sep 2020 17:30:04 +0200 Subject: [PATCH] Update shadows --- .../rendering/shaders/shading-fs.glsl | 43 +++++-------------- 1 file changed, 11 insertions(+), 32 deletions(-) diff --git a/src/graphics/rendering/shaders/shading-fs.glsl b/src/graphics/rendering/shaders/shading-fs.glsl index 7bc0728..fda718c 100644 --- a/src/graphics/rendering/shaders/shading-fs.glsl +++ b/src/graphics/rendering/shaders/shading-fs.glsl @@ -4,15 +4,13 @@ precision lowp float; #define INFINITY 1000.0 #define INTENSITY_INSIDE_RATIO 0.5 -#define SHADOW_HARDNESS 150.0 -#define HARD_SHADOW_TRACE_COUNT {hardShadowTraceCount} -#define SOFT_SHADOW_TRACE_COUNT {softShadowTraceCount} +#define SHADOW_TRACE_COUNT {shadowTraceCount} {macroDefinitions} -uniform bool softShadowsEnabled; uniform vec2 squareToAspectRatioTimes2; uniform float shadingNdcPixelSize; +uniform float shadowLength; uniform sampler2D distanceTexture; in vec2 position; @@ -34,41 +32,22 @@ float getDistance(in vec2 target) { return texture(distanceTexture, target)[0]; } -float softShadowTransparency(float startingDistance, float lightCenterDistance, vec2 direction) { - float rayLength = startingDistance; - float q = 1.0 / SHADOW_HARDNESS; - - for (int j = 0; j < SOFT_SHADOW_TRACE_COUNT; j++) { - float minDistance = getDistance(uvCoordinates + direction * rayLength); - - q = min(q, minDistance / rayLength); - rayLength += minDistance; - - if (rayLength >= lightCenterDistance) { - return q * SHADOW_HARDNESS; - } - } - - return 0.0; -} - -float hardShadowTransparency(float startingDistance, float lightCenterDistance, vec2 direction) { +float shadowTransparency(float startingDistance, float lightCenterDistance, vec2 direction) { float rayLength = startingDistance; - for (int j = 0; j < HARD_SHADOW_TRACE_COUNT; j++) { + for (int j = 0; j < SHADOW_TRACE_COUNT; j++) { rayLength += getDistance(uvCoordinates + direction * rayLength); } - return min(1.0, step(lightCenterDistance, rayLength) + rayLength / (150.0 * shadingNdcPixelSize)); + return min( + 1.0, + ( + step(lightCenterDistance, rayLength) + + rayLength / (shadowLength * shadingNdcPixelSize) + ) * 2.0 + ); } -float shadowTransparency(float startingDistance, float lightCenterDistance, vec2 direction) { - return softShadowsEnabled ? - softShadowTransparency(startingDistance, lightCenterDistance, direction) : - hardShadowTransparency(startingDistance, lightCenterDistance, direction); -} - - #ifdef CIRCLE_LIGHT_COUNT #if CIRCLE_LIGHT_COUNT > 0 uniform struct CircleLight {