Reduce point lamp noise
This commit is contained in:
parent
900f2b77c7
commit
c3bdf0efda
|
@ -66,7 +66,7 @@ uniform mat4 LWVP;
|
|||
uniform vec3 lightColor;
|
||||
uniform vec3 lightDir;
|
||||
uniform vec3 lightPos;
|
||||
uniform vec2 lightPlane;
|
||||
uniform vec2 lightProj;
|
||||
uniform int lightType;
|
||||
uniform int lightShadow;
|
||||
uniform float shadowsBias;
|
||||
|
@ -145,7 +145,7 @@ void main() {
|
|||
}
|
||||
}
|
||||
else if (lightShadow == 2) { // Cube
|
||||
visibility = PCFCube(lp, -l, shadowsBias, lightPlane);
|
||||
visibility = PCFCube(lp, -l, shadowsBias, lightProj, n);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -22,8 +22,8 @@
|
|||
"link": "_lampPosition"
|
||||
},
|
||||
{
|
||||
"name": "lightPlane",
|
||||
"link": "_lampPlane"
|
||||
"name": "lightProj",
|
||||
"link": "_lampPlaneProj"
|
||||
},
|
||||
{
|
||||
"name": "lightDir",
|
||||
|
|
|
@ -52,22 +52,20 @@ float PCF(const vec2 uv, const float compare) {
|
|||
return result / 9.0;
|
||||
}
|
||||
|
||||
float lpToDepth(vec3 lp, const vec2 lightPlane) {
|
||||
// TODO: pass uniforms
|
||||
float a = lightPlane.y + lightPlane.x;
|
||||
float b = lightPlane.y - lightPlane.x;
|
||||
float c = 2.0 * lightPlane.y * lightPlane.x;
|
||||
float lpToDepth(vec3 lp, const vec2 lightProj) {
|
||||
lp = abs(lp);
|
||||
float zcomp = max(lp.x, max(lp.y, lp.z));
|
||||
zcomp = a / b - c / b / zcomp;
|
||||
zcomp = lightProj.x - lightProj.y / zcomp;
|
||||
return zcomp * 0.5 + 0.5;
|
||||
}
|
||||
|
||||
float PCFCube(const vec3 lp, const vec3 ml, const float bias, const vec2 lightPlane) {
|
||||
// return float(texture(shadowMapCube, ml).r + bias > lpToDepth(lp, lightPlane));
|
||||
float compare = lpToDepth(lp, lightPlane) - bias;
|
||||
float result = step(compare, texture(shadowMapCube, ml).r);
|
||||
float PCFCube(const vec3 lp, vec3 ml, const float bias, const vec2 lightProj, const vec3 n) {
|
||||
// return float(texture(shadowMapCube, ml).r + bias > lpToDepth(lp, lightProj));
|
||||
const float s = shadowmapCubePcfSize; // 0.001 TODO: incorrect...
|
||||
// float compare = lpToDepth(lp, lightProj) - bias;
|
||||
float compare = lpToDepth(lp - n * 0.003, lightProj) - bias * 0.4;
|
||||
ml = ml + n * 0.003;
|
||||
float result = step(compare, texture(shadowMapCube, ml).r);
|
||||
result += step(compare, texture(shadowMapCube, ml + vec3(s, s, s)).r);
|
||||
result += step(compare, texture(shadowMapCube, ml + vec3(-s, s, s)).r);
|
||||
result += step(compare, texture(shadowMapCube, ml + vec3(s, -s, s)).r);
|
||||
|
@ -80,8 +78,6 @@ float PCFCube(const vec3 lp, const vec3 ml, const float bias, const vec2 lightPl
|
|||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
float shadowTest(const vec3 lPos, const float shadowsBias) {
|
||||
|
||||
// float cosAngle = max(1.0 - dotNL, 0.0);
|
||||
|
|
|
@ -603,7 +603,7 @@ def make_forward_base(con_mesh, parse_opacity=False):
|
|||
frag.add_uniform('bool receiveShadow')
|
||||
frag.add_uniform('float shadowsBias', '_lampShadowsBias')
|
||||
frag.add_uniform('int lightShadow', '_lampCastShadow')
|
||||
frag.add_uniform('vec2 lightPlane', '_lampPlane')
|
||||
frag.add_uniform('vec2 lightProj', '_lampPlaneProj')
|
||||
|
||||
frag.write('if (receiveShadow) {')
|
||||
frag.write(' if (lightShadow == 1) {')
|
||||
|
@ -622,7 +622,7 @@ def make_forward_base(con_mesh, parse_opacity=False):
|
|||
else:
|
||||
frag.write(' visibility *= PCF(lpos.xy, lpos.z - shadowsBias);')
|
||||
frag.write(' }')
|
||||
frag.write(' else if (lightShadow == 2) visibility *= PCFCube(lp, -l, shadowsBias, lightPlane);')
|
||||
frag.write(' else if (lightShadow == 2) visibility *= PCFCube(lp, -l, shadowsBias, lightProj, n);')
|
||||
frag.write('}')
|
||||
|
||||
frag.write('if (lightType == 2) {')
|
||||
|
|
|
@ -61,7 +61,7 @@ def make_rect(con_rect):
|
|||
frag.add_uniform('vec3 lightPos', link='_lampPosition')
|
||||
frag.add_uniform('vec3 lightColor', link='_lampColor')
|
||||
frag.add_uniform('int lightShadow', link='_lampCastShadow')
|
||||
frag.add_uniform('vec2 lightPlane', link='_lampPlane')
|
||||
frag.add_uniform('vec2 lightProj', link='_lampPlaneProj')
|
||||
frag.add_uniform('float shadowsBias', link='_lampShadowsBias')
|
||||
# TODO: ifdef
|
||||
frag.add_uniform('float envmapStrength', link='_envmapStrength')
|
||||
|
@ -114,7 +114,7 @@ def make_rect(con_rect):
|
|||
frag.write(' if (lPos.x > 0.0 && lPos.y > 0.0 && lPos.x < 1.0 && lPos.y < 1.0) visibility = PCF(lPos.xy, lPos.z - shadowsBias);;')
|
||||
frag.write('}')
|
||||
frag.write('else if (lightShadow == 2) {')
|
||||
frag.write(' visibility = PCFCube(lp, -l, shadowsBias, lightPlane);')
|
||||
frag.write(' visibility = PCFCube(lp, -l, shadowsBias, lightProj, n);')
|
||||
frag.write('}')
|
||||
|
||||
frag.write('visibility *= attenuate(distance(wposition, lightPos));')
|
||||
|
|
|
@ -64,7 +64,7 @@ def make_gi(context_id):
|
|||
frag.add_uniform('sampler2D shadowMap', included=True)
|
||||
frag.add_uniform('samplerCube shadowMapCube', included=True)
|
||||
frag.add_uniform('int lightShadow', '_lampCastShadow')
|
||||
frag.add_uniform('vec2 lightPlane', '_lampPlane')
|
||||
frag.add_uniform('vec2 lightProj', '_lampPlaneProj')
|
||||
frag.add_uniform('float shadowsBias', '_lampShadowsBias')
|
||||
frag.write('if (lightShadow == 1 && lampPos.w > 0.0) {')
|
||||
frag.write(' vec3 lpos = lampPos.xyz / lampPos.w;')
|
||||
|
@ -73,7 +73,7 @@ def make_gi(context_id):
|
|||
frag.write(' if (texture(shadowMap, lpos.xy).r < lpos.z - shadowsBias) visibility = 0.0;')
|
||||
# frag.write(' visibility = PCF(lpos.xy, lpos.z - shadowsBias);')
|
||||
frag.write('}')
|
||||
frag.write('else if (lightShadow == 2) visibility *= float(texture(shadowMapCube, -l).r + shadowsBias > lpToDepth(lp, lightPlane));')
|
||||
frag.write('else if (lightShadow == 2) visibility *= float(texture(shadowMapCube, -l).r + shadowsBias > lpToDepth(lp, lightProj));')
|
||||
|
||||
# frag.write('if (lightType == 2) {')
|
||||
# frag.write(' float spotEffect = dot(lightDir, l);')
|
||||
|
|
Loading…
Reference in a new issue