From 28a9b5e03e8061e3a4002e653d521fb34c44c11b Mon Sep 17 00:00:00 2001 From: austin Date: Wed, 16 Feb 2022 18:55:39 -0500 Subject: [PATCH] fix self shadows --- assets/Shaders/FragmentShader.fs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/assets/Shaders/FragmentShader.fs b/assets/Shaders/FragmentShader.fs index fd597772..72fb448f 100644 --- a/assets/Shaders/FragmentShader.fs +++ b/assets/Shaders/FragmentShader.fs @@ -185,6 +185,14 @@ float ShadowCalculation(vec4 fragPosLightSpace, vec3 lightDir, vec3 normal){ shadow = 0.0; } + //calculate dot product, if it is >0 we know they're parallel-ish therefore should disregard the shadow mapping + //ie the fragment is already facing away from the light source + float dotprod = dot(normalize(lightDir),normalize(normal)); + + if(dotprod > 0.0){ + shadow = 0.0; + } + // shadow = currentDepth; return shadow;