16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-22 16:19:19 +02:00

shadow changes

This commit is contained in:
VB
2017-07-03 12:10:21 +02:00
parent 2b51d8229e
commit 689ad7206e
5 changed files with 91 additions and 24 deletions

View File

@@ -28,7 +28,7 @@ in vec4 f_light_pos;
out vec4 color;
uniform sampler2D tex;
uniform sampler2D shadowmap;
uniform sampler2DShadow shadowmap;
uniform vec3 ambient;
uniform vec3 emission;
@@ -39,13 +39,57 @@ uniform float specular;
uniform light_s lights[8];
uniform uint lights_count;
vec2 poissonDisk[16] = vec2[](
vec2( -0.94201624, -0.39906216 ),
vec2( 0.94558609, -0.76890725 ),
vec2( -0.094184101, -0.92938870 ),
vec2( 0.34495938, 0.29387760 ),
vec2( -0.91588581, 0.45771432 ),
vec2( -0.81544232, -0.87912464 ),
vec2( -0.38277543, 0.27676845 ),
vec2( 0.97484398, 0.75648379 ),
vec2( 0.44323325, -0.97511554 ),
vec2( 0.53742981, -0.47373420 ),
vec2( -0.26496911, -0.41893023 ),
vec2( 0.79197514, 0.19090188 ),
vec2( -0.24188840, 0.99706507 ),
vec2( -0.81409955, 0.91437590 ),
vec2( 0.19984126, 0.78641367 ),
vec2( 0.14383161, -0.14100790 )
);
float random(vec3 seed, int i)
{
vec4 seed4 = vec4(seed,i);
float dot_product = dot(seed4, vec4(12.9898,78.233,45.164,94.673));
return fract(sin(dot_product) * 43758.5453);
}
float calc_shadow()
{
vec3 coords = f_light_pos.xyz / f_light_pos.w;
vec3 coords = f_light_pos.xyz;// / f_light_pos.w;
coords = coords * 0.5 + 0.5;
float closest_depth = texture(shadowmap, coords.xy).r;
float current_depth = coords.z;
float shadow = (current_depth - 0.1) > closest_depth ? 0.0 : 1.0;
float bias = 0.005;
//PCF
//float shadow = texture(shadowmap, vec3(coords.xy, coords.z - bias));
//PCF + stratified poisson sampling
//float shadow = 1.0;
//for (int i=0;i<4;i++)
//{
// int index = int(16.0*random(gl_FragCoord.xyy, i))%16;
// shadow -= 0.25*(1.0-texture(shadowmap, vec3(coords.xy + poissonDisk[index]/5000.0, coords.z - bias)));
//}
//PCF + PCF
float shadow = 0.0;
vec2 texel = 1.0 / textureSize(shadowmap, 0);
for (float y = -1.5; y <= 1.5; y += 1.0)
for (float x = -1.5; x <= 1.5; x += 1.0)
shadow += texture(shadowmap, coords.xyz + vec3(vec2(x, y) * texel, -bias));
shadow /= 16.0;
return shadow;
}