From f2a71653840d9897a1bb79e0fd71a4180c8991e3 Mon Sep 17 00:00:00 2001 From: Chris Clyne Date: Wed, 5 Jun 2024 15:00:31 +0100 Subject: [PATCH] Half-lambert factor in Shader Info node --- .../eevee/shaders/closure_eval_surface_lib.glsl | 12 +++++++++--- .../draw/engines/eevee/shaders/closure_type_lib.glsl | 4 ++-- .../material/gpu_shader_material_shader_info.glsl | 8 ++++---- .../nodes/shader/nodes/node_shader_shader_info.cc | 1 + 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/source/blender/draw/engines/eevee/shaders/closure_eval_surface_lib.glsl b/source/blender/draw/engines/eevee/shaders/closure_eval_surface_lib.glsl index 25db86cd66b..277ae93ea34 100644 --- a/source/blender/draw/engines/eevee/shaders/closure_eval_surface_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/closure_eval_surface_lib.glsl @@ -404,7 +404,8 @@ void calc_shader_info(vec3 position, out vec4 half_light, out float shadows, out float self_shadows, - out vec4 ambient) + out vec4 ambient, + out float half_lambert) { calc_shader_info(position, normal, @@ -413,7 +414,8 @@ void calc_shader_info(vec3 position, half_light, shadows, self_shadows, - ambient); + ambient, + half_lambert); } /* Use custom (Per-Node) light groups */ @@ -424,7 +426,8 @@ void calc_shader_info(vec3 position, out vec4 half_light, out float shadows, out float self_shadows, - out vec4 ambient) + out vec4 ambient, + out float half_lambert) { ClosureEvalCommon cl_common = closure_Common_eval_init(CLOSURE_INPUT_COMMON_DEFAULT); cl_common.P = position; @@ -436,6 +439,7 @@ void calc_shader_info(vec3 position, float self_shadow_accum = 0.0; float light_accum = 0.0; half_light = vec4(0.0); + half_lambert = 0.0; for (int i = 0; i < laNumLight && i < MAX_LIGHT; i++) { ClosureLightData light = closure_light_eval_init(cl_common, i); @@ -459,6 +463,8 @@ void calc_shader_info(vec3 position, float radiance = light_diffuse(light.data, n_n, cl_common.V, light.L); half_light += vec4(light.data.l_color * light.data.l_diff * radiance, 0.0); + vec3 L = (ld.l_type == SUN) ? -ld.l_forward : (light.L.xyz / light.L.w); + half_lambert += 0.5 * dot(L, n_n) + 0.5; } shadows = (1.0 - (shadow_accum / max(light_accum, 1.0))); diff --git a/source/blender/draw/engines/eevee/shaders/closure_type_lib.glsl b/source/blender/draw/engines/eevee/shaders/closure_type_lib.glsl index bb95260f6fe..a9af7363c81 100644 --- a/source/blender/draw/engines/eevee/shaders/closure_type_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/closure_type_lib.glsl @@ -48,8 +48,8 @@ Closure nodetree_exec(); vec4 closure_to_rgba(Closure cl); /* Goo-engine node internals */ -void calc_shader_info(vec3 position, vec3 normal, ivec4 light_groups, ivec4 light_group_shadows, out vec4 half_light, out float shadows, out float self_shadows, out vec4 ambient); -void calc_shader_info(vec3 position, vec3 normal, out vec4 half_light, out float shadows, out float self_shadows, out vec4 ambient); +void calc_shader_info(vec3 position, vec3 normal, ivec4 light_groups, ivec4 light_group_shadows, out vec4 half_light, out float shadows, out float self_shadows, out vec4 ambient, out float half_lambert); +void calc_shader_info(vec3 position, vec3 normal, out vec4 half_light, out float shadows, out float self_shadows, out vec4 ambient, out float half_lambert); void screenspace_info(vec3 viewPos, out vec4 scene_col, out float scene_depth); void screenspace_curvature(float iiterations, float sample_scale, float clamp_dist, vec3 scale, out float scene_curvature, out float scene_rim); diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_shader_info.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_shader_info.glsl index f9ccfadf873..7d917ce7794 100644 --- a/source/blender/gpu/shaders/material/gpu_shader_material_shader_info.glsl +++ b/source/blender/gpu/shaders/material/gpu_shader_material_shader_info.glsl @@ -1,14 +1,14 @@ void node_shader_info(vec3 position, vec3 normal, -out vec4 half_light, out float shadows, out float self_shadows, out vec4 ambient) +out vec4 half_light, out float shadows, out float self_shadows, out vec4 ambient, out float half_lambert) { // Implicitly included by eevee shader linking. - calc_shader_info(position, normal, half_light, shadows, self_shadows, ambient); + calc_shader_info(position, normal, half_light, shadows, self_shadows, ambient, half_lambert); } void node_shader_info_light_groups(vec3 position, vec3 normal, vec4 light_groups, vec4 light_group_shadows, -out vec4 half_light, out float shadows, out float self_shadows, out vec4 ambient) +out vec4 half_light, out float shadows, out float self_shadows, out vec4 ambient, out float half_lambert) { // Implicitly included by eevee shader linking. - calc_shader_info(position, normal, floatBitsToInt(light_groups), floatBitsToInt(light_group_shadows), half_light, shadows, self_shadows, ambient); + calc_shader_info(position, normal, floatBitsToInt(light_groups), floatBitsToInt(light_group_shadows), half_light, shadows, self_shadows, ambient, half_lambert); } diff --git a/source/blender/nodes/shader/nodes/node_shader_shader_info.cc b/source/blender/nodes/shader/nodes/node_shader_shader_info.cc index f18af391421..34819fa48be 100644 --- a/source/blender/nodes/shader/nodes/node_shader_shader_info.cc +++ b/source/blender/nodes/shader/nodes/node_shader_shader_info.cc @@ -16,6 +16,7 @@ static void node_declare(NodeDeclarationBuilder &b) b.add_output(N_("Cast Shadows")); b.add_output(N_("Self Shadows")); b.add_output(N_("Ambient Lighting")); + b.add_output(N_("Half-lambert factor")); } static void node_shader_init_shader_info(bNodeTree* /*ntree*/, bNode *node)