diff options
author | Jeroen Bakker <j.bakker@atmind.nl> | 2018-06-18 16:17:46 +0300 |
---|---|---|
committer | Jeroen Bakker <j.bakker@atmind.nl> | 2018-06-18 16:32:53 +0300 |
commit | 7747d4cecf078589f614813d0e5e0a753d4e10b5 (patch) | |
tree | 099fe569b48e44f1406d8420ea618ad27f00ee84 /source/blender/draw/engines/workbench/shaders/workbench_world_light_lib.glsl | |
parent | fec97ec94939ab32b43e3221e4c611e1e873a563 (diff) |
Workbench: increased Quality of the diffuse lighting model
- implemented Spherical Harmonics L2 for diffuse shading.
TODO: caching the precalculated harmonics so it won't take soo long to
open the popover
Diffstat (limited to 'source/blender/draw/engines/workbench/shaders/workbench_world_light_lib.glsl')
-rw-r--r-- | source/blender/draw/engines/workbench/shaders/workbench_world_light_lib.glsl | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/source/blender/draw/engines/workbench/shaders/workbench_world_light_lib.glsl b/source/blender/draw/engines/workbench/shaders/workbench_world_light_lib.glsl index 9d256e5350a..71adc751f0a 100644 --- a/source/blender/draw/engines/workbench/shaders/workbench_world_light_lib.glsl +++ b/source/blender/draw/engines/workbench/shaders/workbench_world_light_lib.glsl @@ -1,24 +1,32 @@ #define BLINN +vec3 spherical_harmonics_L2(vec3 N, vec3 spherical_harmonics_coefs[9]) +{ + vec3 sh = vec3(0.0); + + sh += 0.282095 * spherical_harmonics_coefs[0]; + + sh += -0.488603 * N.z * spherical_harmonics_coefs[1]; + sh += 0.488603 * N.y * spherical_harmonics_coefs[2]; + sh += -0.488603 * N.x * spherical_harmonics_coefs[3]; + + sh += 1.092548 * N.x * N.z * spherical_harmonics_coefs[4]; + sh += -1.092548 * N.z * N.y * spherical_harmonics_coefs[5]; + sh += 0.315392 * (3.0 * N.y * N.y - 1.0) * spherical_harmonics_coefs[6]; + sh += -1.092548 * N.x * N.y * spherical_harmonics_coefs[7]; + sh += 0.546274 * (N.x * N.x - N.z * N.z) * spherical_harmonics_coefs[8]; + + return sh; +} + vec3 get_world_diffuse_light(WorldData world_data, vec3 N) { - vec4 result = world_data.diffuse_light_x_pos * clamp(N.x, 0.0, 1.0); - result = mix(result, world_data.diffuse_light_x_neg, clamp(-N.x, 0.0, 1.0)); - result = mix(result, world_data.diffuse_light_y_pos, clamp(-N.y, 0.0, 1.0)); - result = mix(result, world_data.diffuse_light_y_neg, clamp(N.y, 0.0, 1.0)); - result = mix(result, world_data.diffuse_light_z_pos, clamp(N.z, 0.0, 1.0)); - return mix(result, world_data.diffuse_light_z_neg, clamp(-N.z, 0.0, 1.0)).xyz; + return (spherical_harmonics_L2(vec3(N.x, N.y, -N.z), world_data.spherical_harmonics_coefs)); } vec3 get_camera_diffuse_light(WorldData world_data, vec3 N) { - vec4 result = world_data.diffuse_light_x_pos * clamp(N.x, 0.0, 1.0); - result = mix(result, world_data.diffuse_light_x_neg, clamp(-N.x, 0.0, 1.0)); - result = mix(result, world_data.diffuse_light_z_pos, clamp( N.y, 0.0, 1.0)); - result = mix(result, world_data.diffuse_light_z_neg, clamp(-N.y, 0.0, 1.0)); - result = mix(result, world_data.diffuse_light_y_pos, clamp( N.z, 0.0, 1.0)); - result = mix(result, world_data.diffuse_light_y_neg, clamp(-N.z, 0.0, 1.0)); - return result.rgb; + return (spherical_harmonics_L2(vec3(N.x, -N.z, -N.y), world_data.spherical_harmonics_coefs)); } /* N And I are in View Space. */ |