Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeroen Bakker <j.bakker@atmind.nl>2018-06-18 16:17:46 +0300
committerJeroen Bakker <j.bakker@atmind.nl>2018-06-18 16:32:53 +0300
commit7747d4cecf078589f614813d0e5e0a753d4e10b5 (patch)
tree099fe569b48e44f1406d8420ea618ad27f00ee84 /source/blender/draw/engines/workbench/shaders/workbench_world_light_lib.glsl
parentfec97ec94939ab32b43e3221e4c611e1e873a563 (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.glsl34
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. */