From bbf73c2766f37269252c1705d517f45c0ee2224b Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Wed, 4 Oct 2023 00:46:29 +0200 Subject: [PATCH] Apply surface angle to sun light --- wadsrc/static/shaders/lightmap/frag_raytrace.glsl | 2 +- wadsrc/static/shaders/lightmap/trace_sunlight.glsl | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/wadsrc/static/shaders/lightmap/frag_raytrace.glsl b/wadsrc/static/shaders/lightmap/frag_raytrace.glsl index 307412414..d492fb035 100644 --- a/wadsrc/static/shaders/lightmap/frag_raytrace.glsl +++ b/wadsrc/static/shaders/lightmap/frag_raytrace.glsl @@ -29,7 +29,7 @@ void main() vec3 origin = worldpos + normal * 0.1; #if defined(USE_SUNLIGHT) - vec3 incoming = TraceSunLight(origin); + vec3 incoming = TraceSunLight(origin, normal, SurfaceIndex); #else vec3 incoming = vec3(0.0); #endif diff --git a/wadsrc/static/shaders/lightmap/trace_sunlight.glsl b/wadsrc/static/shaders/lightmap/trace_sunlight.glsl index 6340f3e19..b0821a9db 100644 --- a/wadsrc/static/shaders/lightmap/trace_sunlight.glsl +++ b/wadsrc/static/shaders/lightmap/trace_sunlight.glsl @@ -1,8 +1,16 @@ vec2 getVogelDiskSample(int sampleIndex, int sampleCount, float phi); -vec3 TraceSunLight(vec3 origin) +vec3 TraceSunLight(vec3 origin, vec3 normal, int surfaceIndex) { + float angleAttenuation = 1.0f; + if (surfaceIndex >= 0) + { + angleAttenuation = max(dot(normal, SunDir), 0.0); + if (angleAttenuation == 0.0) + return vec3(0.0); + } + const float minDistance = 0.01; vec3 incoming = vec3(0.0); const float dist = 32768.0; @@ -45,5 +53,5 @@ vec3 TraceSunLight(vec3 origin) #endif - return incoming; + return incoming * angleAttenuation; }