Made bias variable to get smaller bias for smaller shadow maps.
This commit is contained in:
parent
0d8256abe5
commit
6fe51809a0
@ -60,11 +60,11 @@ vec2 poissonDisk[16] = vec2[](
|
|||||||
vec2( 0.14383161, -0.14100790 )
|
vec2( 0.14383161, -0.14100790 )
|
||||||
);
|
);
|
||||||
|
|
||||||
float sampleDirectionalShadow(sampler2DShadow shadowMap, vec4 shadowCoord) {
|
float sampleDirectionalShadow(sampler2DShadow shadowMap, vec4 shadowCoord, float maxBias ) {
|
||||||
float visibility = 1.0;
|
float visibility = 1.0;
|
||||||
const float stretching = 650.0;
|
const float stretching = 650.0;
|
||||||
float bias = 0.001*tan(acos(clamp(dot(vNormal, -directionalLightVector), 0.0, 1.0)));
|
float bias = 0.001*tan(acos(clamp(dot(vNormal, -directionalLightVector), 0.0, 1.0)));
|
||||||
bias = clamp(bias, 0.0, 0.01);
|
bias = clamp(bias, 0.0, maxBias);
|
||||||
for (int i=0; i<4; i++) {
|
for (int i=0; i<4; i++) {
|
||||||
visibility -= directionalIntensity/16*(1.0-texture(shadowMap, vec3(shadowCoord.xy + poissonDisk[i]/stretching, shadowCoord.z - bias)));
|
visibility -= directionalIntensity/16*(1.0-texture(shadowMap, vec3(shadowCoord.xy + poissonDisk[i]/stretching, shadowCoord.z - bias)));
|
||||||
}
|
}
|
||||||
@ -109,24 +109,24 @@ void main()
|
|||||||
float directionalVisibility = 1.0f;
|
float directionalVisibility = 1.0f;
|
||||||
if (distanceToBorder(shadowCoord1.xy) <= 0.5 && distanceToBorder(shadowCoord1.xy) > 0.2) {
|
if (distanceToBorder(shadowCoord1.xy) <= 0.5 && distanceToBorder(shadowCoord1.xy) > 0.2) {
|
||||||
if (distanceToBorder(shadowCoord0.xy) <= 0.5 && distanceToBorder(shadowCoord0.xy) > 0.2) {
|
if (distanceToBorder(shadowCoord0.xy) <= 0.5 && distanceToBorder(shadowCoord0.xy) > 0.2) {
|
||||||
directionalVisibility = sampleDirectionalShadow(shadowMap_directional0, shadowCoord0);
|
directionalVisibility = sampleDirectionalShadow(shadowMap_directional0, shadowCoord0, 0.001);
|
||||||
}
|
}
|
||||||
else if (distanceToBorder(shadowCoord0.xy) <= 0.5 && distanceToBorder(shadowCoord0.xy) > 0.0) {
|
else if (distanceToBorder(shadowCoord0.xy) <= 0.5 && distanceToBorder(shadowCoord0.xy) > 0.0) {
|
||||||
float directionalVisibility0 = sampleDirectionalShadow(shadowMap_directional0, shadowCoord0);
|
float directionalVisibility0 = sampleDirectionalShadow(shadowMap_directional0, shadowCoord0, 0.001);
|
||||||
float directionalVisibility1 = sampleDirectionalShadow(shadowMap_directional1, shadowCoord1);
|
float directionalVisibility1 = sampleDirectionalShadow(shadowMap_directional1, shadowCoord1, 0.002);
|
||||||
directionalVisibility = mix(directionalVisibility0, directionalVisibility1, distanceToBorder(shadowCoord0.xy) * 5);
|
directionalVisibility = mix(directionalVisibility0, directionalVisibility1, distanceToBorder(shadowCoord0.xy) * 5);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
directionalVisibility = sampleDirectionalShadow(shadowMap_directional1, shadowCoord1);
|
directionalVisibility = sampleDirectionalShadow(shadowMap_directional1, shadowCoord1, 0.002);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (distanceToBorder(shadowCoord1.xy) <= 0.5 && distanceToBorder(shadowCoord1.xy) > 0.0) {
|
else if (distanceToBorder(shadowCoord1.xy) <= 0.5 && distanceToBorder(shadowCoord1.xy) > 0.0) {
|
||||||
float directionalVisibility1 = sampleDirectionalShadow(shadowMap_directional1, shadowCoord1);
|
float directionalVisibility1 = sampleDirectionalShadow(shadowMap_directional1, shadowCoord1, 0.01);
|
||||||
float directionalVisibility2 = sampleDirectionalShadow(shadowMap_directional2, shadowCoord2);
|
float directionalVisibility2 = sampleDirectionalShadow(shadowMap_directional2, shadowCoord2, 0.01);
|
||||||
directionalVisibility = mix(directionalVisibility1, directionalVisibility2, distanceToBorder(shadowCoord1.xy) * 5);
|
directionalVisibility = mix(directionalVisibility1, directionalVisibility2, distanceToBorder(shadowCoord1.xy) * 5);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
directionalVisibility = sampleDirectionalShadow(shadowMap_directional2, shadowCoord2);
|
directionalVisibility = sampleDirectionalShadow(shadowMap_directional2, shadowCoord2, 0.01);
|
||||||
}
|
}
|
||||||
diffuseColor += clamp(dot(normalize(vNormal), directionalVector)
|
diffuseColor += clamp(dot(normalize(vNormal), directionalVector)
|
||||||
*diffuseFactor*directionalIntensity*directionalColor, 0.0, 1.0)*directionalVisibility;
|
*diffuseFactor*directionalIntensity*directionalColor, 0.0, 1.0)*directionalVisibility;
|
||||||
|
Loading…
Reference in New Issue
Block a user