Fix shadowing for specular reflections.

This commit is contained in:
Joshua Yanovski 2020-04-23 00:01:20 +02:00
parent ddd4a67a97
commit f2953087f6
6 changed files with 26 additions and 17 deletions

View File

@ -67,7 +67,8 @@ void main() {
// vec3 point_light = light_at(f_pos, f_norm);
// vec3 light, diffuse_light, ambient_light;
//get_sun_diffuse(f_norm, time_of_day.x, view_dir, k_a * point_shadow * (shade_frac * 0.5 + light_frac * 0.5), k_d * point_shadow * shade_frac, k_s * point_shadow * shade_frac, alpha, emitted_light, reflected_light);
get_sun_diffuse2(f_norm, sun_dir, moon_dir, view_dir, k_a * (shade_frac * 0.5 + light_frac * 0.5), k_d * point_shadow * shade_frac, k_s * point_shadow * shade_frac, alpha, emitted_light, reflected_light);
get_sun_diffuse2(f_norm, sun_dir, moon_dir, view_dir, k_a * (shade_frac * 0.5 + light_frac * 0.5), k_d, k_s, alpha, emitted_light, reflected_light);
reflected_light *= point_shadow * shade_frac;
emitted_light *= point_shadow;
lights_at(f_pos, f_norm, view_dir, k_a, k_d, k_s, alpha, emitted_light, reflected_light);

View File

@ -51,8 +51,8 @@ void main() {
const float R_s = pow((1.0 - n2) / (1.0 + n2), 2);
vec3 k_a = vec3(1.0);
vec3 k_d = vec3(1.0) * water_color;
vec3 k_s = vec3(R_s) * water_color;
vec3 k_d = vec3(1.0);
vec3 k_s = vec3(R_s);
vec3 emitted_light, reflected_light;
@ -65,7 +65,8 @@ void main() {
vec3 light_frac = /*vec3(1.0);*/light_reflection_factor(f_norm/*vec3(0, 0, 1.0)*/, view_dir, vec3(0, 0, -1.0), vec3(1.0), vec3(R_s), alpha);
// vec3 surf_color = /*srgb_to_linear*/(vec3(0.4, 0.7, 2.0));
get_sun_diffuse2(f_norm, /*time_of_day.x*/sun_dir, moon_dir, /*-cam_to_frag*/view_dir, k_a * (shade_frac * 0.5 + light_frac * 0.5), vec3(0.0), k_s * f_light * point_shadow * shade_frac, alpha, emitted_light, reflected_light);
get_sun_diffuse2(f_norm, /*time_of_day.x*/sun_dir, moon_dir, /*-cam_to_frag*/view_dir, k_a * (shade_frac * 0.5 + light_frac * 0.5), vec3(0.0), k_s, alpha, emitted_light, reflected_light);
reflected_light *= f_light * point_shadow * shade_frac;
emitted_light *= f_light * point_shadow;
// get_sun_diffuse(f_norm, time_of_day.x, light, diffuse_light, ambient_light, 0.0);
// diffuse_light *= f_light * point_shadow;
@ -82,14 +83,15 @@ void main() {
reflected_light += point_light; */
vec3 diffuse_light_point = vec3(0.0);
lights_at(f_pos, f_norm, view_dir, k_a, vec3(1.0), vec3(0.0), alpha, emitted_light, diffuse_light_point);
lights_at(f_pos, f_norm, view_dir, k_a, vec3(1.0), vec3(k_s), alpha, emitted_light, diffuse_light_point);
vec3 dump_light = vec3(0.0);
vec3 specular_light_point = vec3(0.0);
lights_at(f_pos, f_norm, view_dir, vec3(0.0), vec3(0.0), vec3(1.0), alpha, dump_light, specular_light_point);
lights_at(f_pos, f_norm, view_dir, vec3(0.0), vec3(0.0), /*vec3(1.0)*/k_s, alpha, dump_light, specular_light_point);
diffuse_light_point -= specular_light_point;
float reflected_light_point = length(diffuse_light_point) + f_light * point_shadow;
reflected_light += k_d * (diffuse_light_point + f_light * point_shadow * shade_frac) + k_s * specular_light_point;
reflected_light += water_color * k_d * (diffuse_light_point + f_light * point_shadow * shade_frac) + k_s * specular_light_point;
float fog_level = fog(f_pos.xyz, focus_pos.xyz, medium.x);
vec4 clouds;

View File

@ -114,13 +114,13 @@ void main() {
float moon_shade_frac = horizon_at(/*f_shadow, f_pos.z, */f_pos, moon_dir);
float shade_frac = /*1.0;*/sun_shade_frac + moon_shade_frac;
const float alpha = 0.255/* / 4.0 / sqrt(2.0)*/;
const float alpha = 0.255 / 4.0/* / 4.0 / sqrt(2.0)*/;
const float n2 = 1.3325;
const float R_s = pow((1.0 - n2) / (1.0 + n2), 2);
vec3 k_a = vec3(1.0);
vec3 k_d = 1.0 * water_color;
vec3 k_s = R_s * reflect_color;//2.0 * reflect_color;
vec3 k_d = vec3(1.0);
vec3 k_s = vec3(R_s);//2.0 * reflect_color;
vec3 emitted_light, reflected_light;
// vec3 light, diffuse_light, ambient_light;
@ -129,7 +129,8 @@ void main() {
// 0 = 100% reflection, 1 = translucent water
float passthrough = pow(dot(faceforward(f_norm, f_norm, cam_to_frag/*view_dir*/), -cam_to_frag/*view_dir*/), 0.5);
get_sun_diffuse2(norm, /*time_of_day.x*/sun_dir, moon_dir, view_dir, k_a * (shade_frac * 0.5 + light_frac * 0.5), vec3(0.0), /*vec3(f_light * point_shadow)*//*reflect_color*/k_s * f_light * point_shadow * shade_frac, alpha, emitted_light, reflected_light);
get_sun_diffuse2(norm, /*time_of_day.x*/sun_dir, moon_dir, view_dir, k_a * (shade_frac * 0.5 + light_frac * 0.5), vec3(0.0), /*vec3(f_light * point_shadow)*//*reflect_color*/k_s, alpha, emitted_light, reflected_light);
reflected_light *= reflect_color * f_light * point_shadow * shade_frac;
emitted_light *= f_light * point_shadow;
vec3 diffuse_light_point = vec3(0.0);
@ -137,10 +138,11 @@ void main() {
vec3 dump_light = vec3(0.0);
vec3 specular_light_point = vec3(0.0);
lights_at(f_pos, norm, view_dir, vec3(0.0), vec3(0.0), vec3(1.0), alpha, dump_light, specular_light_point);
lights_at(f_pos, norm, view_dir, vec3(0.0), vec3(0.0), /*vec3(1.0)*/k_s, alpha, dump_light, specular_light_point);
diffuse_light_point -= specular_light_point;
float reflected_light_point = length(diffuse_light_point/*.r*/) + f_light * point_shadow;
reflected_light += k_d * (diffuse_light_point + f_light * point_shadow * shade_frac) + k_s * specular_light_point;
reflected_light += water_color * k_d * (diffuse_light_point + f_light * point_shadow * shade_frac) + reflect_color * specular_light_point;
/* vec3 point_light = light_at(f_pos, norm);
emitted_light += point_light;
reflected_light += point_light; */
@ -153,7 +155,7 @@ void main() {
// diffuse_light += point_light;
// reflected_light += point_light;
// vec3 surf_color = srgb_to_linear(vec3(0.2, 0.5, 1.0)) * light * diffuse_light * ambient_light;
vec3 surf_color = illuminate(water_color * emitted_light, reflected_light);
vec3 surf_color = illuminate(/*water_color * */emitted_light, reflected_light);
float fog_level = fog(f_pos.xyz, focus_pos.xyz, medium.x);
vec4 clouds;
@ -172,6 +174,7 @@ void main() {
// vec4 color = mix(vec4(reflect_color * 2.0, 1.0), vec4(surf_color, 1.0 / (1.0 + /*diffuse_light*/(/*f_light * point_shadow*/f_light * point_shadow + reflected_light_point/* + point_light*//*reflected_light*/) * 0.25)), passthrough);
// vec4 color = mix(vec4(surf_color, 1.0), vec4(surf_color, 0.0), passthrough);
//vec4 color = vec4(surf_color, 1.0);
// vec4 color = mix(vec4(reflect_color, 1.0), vec4(surf_color, 1.0 / (1.0 + /*diffuse_light*/(/*f_light * point_shadow*/reflected_light_point/* + point_light*//*reflected_light*/))), passthrough);
vec4 color = vec4(surf_color, mix(1.0, 1.0 / (1.0 + /*0.25 * *//*diffuse_light*/(/*f_light * point_shadow*/reflected_light_point)), passthrough));
tgt_color = mix(mix(color, vec4(fog_color, 0.0), fog_level), vec4(clouds.rgb, 0.0), clouds.a);

View File

@ -77,8 +77,9 @@ void main() {
// vec3 light, diffuse_light, ambient_light;
// get_sun_diffuse(f_norm, time_of_day.x, cam_to_frag, (0.25 * shade_frac + 0.25 * light_frac) * f_col, 0.5 * shade_frac * f_col, 0.5 * shade_frac * /*vec3(1.0)*/f_col, 2.0, emitted_light, reflected_light);
get_sun_diffuse2(f_norm/*l_norm*/, sun_dir, moon_dir, view_dir, 1.0 * (0.5 * light_frac + vec3(0.5 * shade_frac)), vec3(shade_frac * 1.0), /*0.5 * shade_frac * *//*vec3(1.0)*//*f_col*/vec3(shade_frac * R_s), alpha, emitted_light, reflected_light);
get_sun_diffuse2(f_norm/*l_norm*/, sun_dir, moon_dir, view_dir, 1.0 * (0.5 * light_frac + vec3(0.5 * shade_frac)), vec3(1.0), /*0.5 * shade_frac * *//*vec3(1.0)*//*f_col*/vec3(R_s), alpha, emitted_light, reflected_light);
// emitted_light = vec3(1.0);
reflected_light *= shade_frac;
// reflected_light = vec3(0.0);
// emitted_light += 0.5 * vec3(SUN_AMBIANCE * sun_shade_frac * sun_light + moon_shade_frac * moon_light) * f_col * (ambient_sides + 1.0);

View File

@ -61,7 +61,8 @@ void main() {
// vec3 point_light = light_at(f_pos, f_norm);
// vec3 surf_color = srgb_to_linear(vec3(0.2, 0.5, 1.0));
// vec3 cam_to_frag = normalize(f_pos - cam_pos.xyz);
get_sun_diffuse2(f_norm, /*time_of_day.x, */sun_dir, moon_dir, /*cam_to_frag*/view_dir, k_a * (shade_frac * 0.5 + light_frac * 0.5), k_d * vert_light * point_shadow * shade_frac, k_s * vert_light * point_shadow * shade_frac, 2.0, emitted_light, reflected_light);
get_sun_diffuse2(f_norm, /*time_of_day.x, */sun_dir, moon_dir, /*cam_to_frag*/view_dir, k_a * (shade_frac * 0.5 + light_frac * 0.5), k_d, k_s, alpha, emitted_light, reflected_light);
reflected_light *= vert_light * point_shadow * shade_frac;
emitted_light *= vert_light * point_shadow;
// get_sun_diffuse(f_norm, time_of_day.x, light, diffuse_light, ambient_light, 1.0);
// float point_shadow = shadow_at(f_pos, f_norm);

View File

@ -61,9 +61,10 @@ void main() {
float point_shadow = shadow_at(f_pos, f_norm);
vec3 light_frac = /*vec3(1.0)*/light_reflection_factor(f_norm, view_dir, vec3(0, 0, -1.0), vec3(1.0), vec3(R_s), alpha);
max_light += get_sun_diffuse2(f_norm, /*time_of_day.x, */sun_dir, moon_dir, view_dir, k_a * (shade_frac * 0.5 + light_frac * 0.5), k_d * f_light * point_shadow * shade_frac, k_s * f_light * point_shadow * shade_frac, alpha, emitted_light, reflected_light);
max_light += get_sun_diffuse2(f_norm, /*time_of_day.x, */sun_dir, moon_dir, view_dir, k_a * (shade_frac * 0.5 + light_frac * 0.5), k_d, k_s, alpha, emitted_light, reflected_light);
emitted_light *= f_light * point_shadow;
reflected_light *= f_light * point_shadow * shade_frac;
max_light += lights_at(f_pos, f_norm, view_dir, k_a, k_d, k_s, alpha, emitted_light, reflected_light);
/* vec3 point_light = light_at(f_pos, f_norm);