diff options
author | Juan Linietsky <reduzio@gmail.com> | 2019-10-31 21:27:42 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2020-02-11 12:05:03 +0100 |
commit | 8deb977551b58f814f1dcdbc6692b143b871a82c (patch) | |
tree | d198b05179112be6e57992a13849b0035038f381 | |
parent | da0457fa29e1ea63f89b1e1d73e72c4dc80a9966 (diff) |
Changed SDF processing to smooth out shadows.
-rw-r--r-- | servers/visual/rasterizer_rd/shaders/giprobe.glsl | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/servers/visual/rasterizer_rd/shaders/giprobe.glsl b/servers/visual/rasterizer_rd/shaders/giprobe.glsl index d756058356..0bec71b3df 100644 --- a/servers/visual/rasterizer_rd/shaders/giprobe.glsl +++ b/servers/visual/rasterizer_rd/shaders/giprobe.glsl @@ -202,20 +202,23 @@ float raymarch(float distance,float distance_adv,vec3 from,vec3 direction) { vec3 cell_size = 1.0 / vec3(params.limits); - - while (distance > 0.0) { //use this to avoid precision errors + float occlusion = 1.0; + while (distance > 0.5) { //use this to avoid precision errors float advance = texture(sampler3D(texture_sdf,texture_sampler),from * cell_size).r * 255.0 - 1.0; if (advance<0.0) { + occlusion = 0.0; break; } + occlusion=min(advance,occlusion); + advance = max(distance_adv, advance - mod(advance, distance_adv)); //should always advance in multiples of distance_adv from += direction * advance; distance -= advance; } - return max(0.0,distance); + return occlusion;//max(0.0,distance); } @@ -320,7 +323,11 @@ bool compute_light_at_pos(uint index, vec3 pos, vec3 normal, inout vec3 light, i vec3 to = pos; - to-= sign(light_dir)*0.45; //go near the edge towards the light direction to avoid self occlusion + if (length(normal) > 0.2) { + to += normal * distance_adv * 0.51; + } else { + to -= sign(light_dir)*0.45; //go near the edge towards the light direction to avoid self occlusion + } //clip clip_segment(mix(vec4(-1.0,0.0,0.0,0.0),vec4(1.0,0.0,0.0,float(params.limits.x-1)),bvec4(light_dir.x < 0.0)),to,light_pos); @@ -337,12 +344,23 @@ bool compute_light_at_pos(uint index, vec3 pos, vec3 normal, inout vec3 light, i light_pos = to - light_dir * distance; //from -= sign(light_dir)*0.45; //go near the edge towards the light direction to avoid self occlusion - float dist = raymarch(distance,distance_adv,light_pos,light_dir); + + /*float dist = raymarch(distance,distance_adv,light_pos,light_dir); if (dist > distance_adv) { return false; } + attenuation *= 1.0 - smoothstep(0.1*distance_adv,distance_adv,dist); + */ + + float occlusion = raymarch(distance,distance_adv,light_pos,light_dir); + + if (occlusion==0.0) { + return false; + } + + attenuation *= occlusion;//1.0 - smoothstep(0.1*distance_adv,distance_adv,dist); } |