Fiddling around with lighting and a Rendermanager

This commit is contained in:
steffen 2017-11-22 20:40:45 +01:00
parent 1995d2734e
commit b5ec100c9c
2 changed files with 8 additions and 5 deletions

View file

@ -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:

View file

@ -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);