diff options
author | Jeroen Bakker <j.bakker@atmind.nl> | 2018-04-19 15:48:53 +0300 |
---|---|---|
committer | Jeroen Bakker <j.bakker@atmind.nl> | 2018-04-19 15:48:53 +0300 |
commit | a305652d87b7d14562e8e22aefe9073f34d2f06e (patch) | |
tree | 8adfa7f596c9f07fcdda1e84d2aebcd7b2b1a2e5 /source/blender/draw | |
parent | 0a679c6b685a4a046a9c4074cff8c508d6f91618 (diff) |
Workbench: Diffuse studio lighting
Diffstat (limited to 'source/blender/draw')
3 files changed, 42 insertions, 6 deletions
diff --git a/source/blender/draw/engines/workbench/shaders/solid_studio_frag.glsl b/source/blender/draw/engines/workbench/shaders/solid_studio_frag.glsl index 46f5409e4ca..96e65e2919e 100644 --- a/source/blender/draw/engines/workbench/shaders/solid_studio_frag.glsl +++ b/source/blender/draw/engines/workbench/shaders/solid_studio_frag.glsl @@ -1,11 +1,29 @@ uniform vec3 color; +uniform vec3 light_direction = vec3(0.0, 0.0, 1.0); -in vec3 normal; +uniform vec3 world_diffuse_light_xp = vec3(0.5, 0.5, 0.6); +uniform vec3 world_diffuse_light_xn = vec3(0.5, 0.5, 0.6); +uniform vec3 world_diffuse_light_yp = vec3(0.5, 0.5, 0.6); +uniform vec3 world_diffuse_light_yn = vec3(0.5, 0.5, 0.6); +uniform vec3 world_diffuse_light_zp = vec3(0.8, 0.8, 0.8); +uniform vec3 world_diffuse_light_zn = vec3(0.0, 0.0, 0.0); + +in vec3 normal_viewport; out vec4 fragColor; +#define USE_WORLD_DIFFUSE +#define AMBIENT_COLOR vec3(0.2, 0.2, 0.2) void main() { - float intensity = lambert_diffuse(vec3(0.0, 0.0, 1.0), normal); + +#ifdef USE_WORLD_DIFFUSE + vec3 diffuse_light_color = get_world_diffuse_light(normal_viewport, world_diffuse_light_xp, world_diffuse_light_xn, world_diffuse_light_yp, world_diffuse_light_yn, world_diffuse_light_zp, world_diffuse_light_zn); + vec3 shaded_color = (AMBIENT_COLOR + diffuse_light_color) * color; + +#else + float intensity = lambert_diffuse(light_direction, normal_viewport); vec3 shaded_color = color * intensity; + +#endif fragColor = vec4(shaded_color, 1.0); } diff --git a/source/blender/draw/engines/workbench/shaders/workbench_diffuse_lib.glsl b/source/blender/draw/engines/workbench/shaders/workbench_diffuse_lib.glsl index c4ac62c2cfc..22a55a386f7 100644 --- a/source/blender/draw/engines/workbench/shaders/workbench_diffuse_lib.glsl +++ b/source/blender/draw/engines/workbench/shaders/workbench_diffuse_lib.glsl @@ -1,3 +1,21 @@ -float lambert_diffuse(vec3 light_direction, vec3 surface_normal) { - return max(0.0, dot(light_direction, surface_normal)); +float normalized_dot(vec3 v1, vec3 v2) +{ + return max(0.0, dot(v1, v2)); } + +float lambert_diffuse(vec3 light_direction, vec3 surface_normal) +{ + return normalized_dot(light_direction, surface_normal); +} + +vec3 get_world_diffuse_light(vec3 N, vec3 xp, vec3 xn, vec3 yp, vec3 yn, vec3 zp, vec3 zn) +{ + vec3 result = vec3(0.0, 0.0, 0.0); + result = mix(result, xp, normalized_dot(vec3( 1.0, 0.0, 0.0), N)); + result = mix(result, xn, normalized_dot(vec3(-1.0, 0.0, 0.0), N)); + result = mix(result, yp, normalized_dot(vec3( 0.0, 1.0, 0.0), N)); + result = mix(result, yn, normalized_dot(vec3( 0.0, -1.0, 0.0), N)); + result = mix(result, zp, normalized_dot(vec3( 0.0, 0.0, 1.0), N)); + result = mix(result, zn, normalized_dot(vec3( 0.0, 0.0, -1.0), N)); + return result; +}
\ No newline at end of file diff --git a/source/blender/draw/engines/workbench/shaders/workbench_studio_vert.glsl b/source/blender/draw/engines/workbench/shaders/workbench_studio_vert.glsl index 819caa6e807..2da5deabfc2 100644 --- a/source/blender/draw/engines/workbench/shaders/workbench_studio_vert.glsl +++ b/source/blender/draw/engines/workbench/shaders/workbench_studio_vert.glsl @@ -4,10 +4,10 @@ uniform mat3 NormalMatrix; in vec3 pos; in vec3 nor; -out vec3 normal; +out vec3 normal_viewport; void main() { - normal = normalize(NormalMatrix * nor); + normal_viewport = normalize(NormalMatrix * nor); gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0); } |