diff --git a/Lights/Lights.py b/Lights/Lights.py index b47c0de..568acf1 100644 --- a/Lights/Lights.py +++ b/Lights/Lights.py @@ -50,7 +50,7 @@ class Light: new = True glClearColor(1.0,1.0,1.0,1.0) glBindFramebuffer(GL_FRAMEBUFFER,self.FramebufferId) - glCullFace(GL_FRONT) + #glCullFace(GL_FRONT) glViewport(0, 0, 512, 512) if new: if self.DepthBuffer == -1: diff --git a/fragment.glsl b/fragment.glsl index 60655ba..0192d0c 100644 --- a/fragment.glsl +++ b/fragment.glsl @@ -23,9 +23,11 @@ const float screenGamma = 2.2; const float pitl = 2*3.14159265359 / 16.0; const float circlelength = 700.0; -bool isVisible(int i, vec2 offs) +bool isVisible(int i, vec2 offs, float lambertian) { - return !(texture(ShadowMaps[i],lightviewpos[i].xy + offs).x <= (lightviewpos[i].z - 0.0005*tan(acos(dot(normal,-normalize(lightpos[i] - pos.xyz)))))); + float bias = 0.005*tan(acos(lambertian)); + bias = clamp(bias,0.0,0.01);//*tan(acos(dot(normal,-normalize(lightpos[i] - pos.xyz)))); + return !(texture(ShadowMaps[i],lightviewpos[i].xy + offs).x < (lightviewpos[i].z - bias)); } void main() @@ -35,6 +37,7 @@ void main() for(int i = 0; i < numLights; i++){ vec3 lightDir = -normalize(lightpos[i] - pos.xyz); float lambertian = max(dot(normalize(normal),lightDir),0.0); + float cosTheta = clamp(dot(normalize(normal),-lightDir), 0.0, 1.0); float specular = 0; vec3 viewDir = normalize(-pos.xyz); vec3 halfDir = normalize(lightDir + viewDir); @@ -44,7 +47,7 @@ void main() float visible = 0; for(int j = 0; j < 4; j++){ vec2 offs = vec2(cos(j*4*pitl),sin(j*4*pitl)) / circlelength; - visible += float(isVisible(i, offs)) * 1.0/16.0; + visible += float(isVisible(i, offs,cosTheta)) * 1.0/16.0; } if(visible == 0.25) visible = 1.0; @@ -52,7 +55,7 @@ void main() visible = 0; for(int j = 0; j < 16; j++){ vec2 offs = vec2(cos(j*pitl),sin(j*pitl)) / circlelength; - visible += float(isVisible(i, offs)) * 1.0/16.0; + visible += float(isVisible(i, offs,cosTheta)) * 1.0/16.0; } colorLinear += (visible * 0.5 + 0.5) *(lambertian * diffuseFactor * colorin * lightColor[i] + specular * specFactor*colorin);