Blender V5.3
eevee_light_eval.bsl.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2022-2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
10#include "eevee_ltc_lib.bsl.hh"
11#include "eevee_shadow.bsl.hh"
14
15namespace eevee {
16
24
31
32namespace light {
33
34template<bool is_transmission> struct ClosureStack {};
35
36template<> struct ClosureStack<false> {
37 [[capacity(light_closure_count_reflect)]] ClosureLight cl[3];
38};
39
40template<> struct ClosureStack<true> {
41 [[capacity(light_closure_count_transmit)]] ClosureLight cl[3];
42};
43
45 LightData light,
46 LightVector lv,
47 LightShape shape,
48 ClosureLight &cl,
49 float attenuation,
50 float shadow)
51{
52 attenuation *= power_get(light, cl.type);
53 if (attenuation < 1e-30f) {
54 return;
55 }
56
57 LTCData ltc_data = LTCData::unpack_from(cl);
58 float ltc_result = ltc::evaluate(util_tx, light, shape, lv, ltc_data);
59
60 float3 out_radiance = light.color * ltc_result;
61 float visibility = shadow * attenuation;
62 cl.light_shadowed += visibility * out_radiance;
63 cl.light_unshadowed += attenuation * out_radiance;
64}
65
66template<bool is_transmission> struct EvalCtx {
68
78
79 void light_eval_single(LightEvalData &srt, LightData light, const bool is_directional)
80 {
81 if (!light_linking_affects_receiver(light.light_set_membership, receiver_light_set)) {
82 return;
83 }
84
85 LightVector lv = LightVector::get(light, is_directional, P);
86
87 /* TODO(fclem): Get rid of this special case. */
88 bool is_translucent_with_thickness = is_transmission &&
89 (stack.cl[0].type == LIGHT_TRANSLUCENT_WITH_THICKNESS);
90
91 float attenuation = light_attenuation_surface(light, is_directional, lv);
92 if (attenuation < LIGHT_ATTENUATION_THRESHOLD) {
93 return;
94 }
95
96 float shadow = 1.0f;
97 if (light.tilemap_index != LIGHT_NO_SHADOW) {
99 light,
100 is_directional,
101 is_transmission,
102 is_translucent_with_thickness,
103 texel,
104 thickness,
105 P,
106 Ng,
107 stack.cl[0].N,
110 1.0f,
111 ray_count,
113 }
114
115 LightShape shape = LightShape::get(light, lv);
116
117 const UtilityTexture &util = srt.utility_tx;
118 const auto &util_tx = util.utility_tx;
119
120 for (uint i = 0u; i < 3; i++) [[unroll]] {
121 if constexpr (is_transmission) {
123 eval_single_closure(util_tx, light, lv, shape, stack.cl[i], attenuation, shadow);
124 }
125 }
126 else {
128 eval_single_closure(util_tx, light, lv, shape, stack.cl[i], attenuation, shadow);
129 }
130 }
131 }
132 }
133
134 void eval_directional(LightEvalData &srt, uint /*l_idx*/, LightData light)
135 {
136 light_eval_single(srt, light, true);
137 }
138
139 void eval_local(LightEvalData &srt, uint /*l_idx*/, LightData light)
140 {
141 light_eval_single(srt, light, false);
142 }
143};
144
145template struct EvalCtx<true>;
146template struct EvalCtx<false>;
147
152
153/* NOTE: Doesn't init the closure stack. */
155{
156 EvalCtx<true> ctx_tr;
157 ctx_tr.P = ctx.P;
158 ctx_tr.Ng = ctx.Ng;
159 ctx_tr.texel = ctx.texel;
160 ctx_tr.thickness = ctx.thickness;
164 ctx_tr.ray_count = ctx.ray_count;
165 ctx_tr.ray_step_count = ctx.ray_step_count;
166 return ctx_tr;
167}
168
169} // namespace light
170
189
190} // namespace eevee
#define LIGHT_ATTENUATION_THRESHOLD
float light_attenuation_surface(LightData light, const bool is_directional, LightVector lv)
#define LIGHT_NO_SHADOW
#define capacity(const)
#define compilation_constant
#define resource_table
#define static_branch
#define unroll
SamplerBase< float, 2, false, true > sampler2DArray
unsigned int uchar
void eval_single_closure(sampler2DArray util_tx, LightData light, LightVector lv, LightShape shape, ClosureLight &cl, float attenuation, float shadow)
float power_get(LightData light, LightingType type)
void foreach_visible(const LightRenderData &srt, float2 pixel, float linear_view_z, CallbackT &cb, ResourceT &res)
EvalCtx< true > init_from_reflect_ctx(EvalCtx< false > ctx)
bool light_linking_affects_receiver(uint2 light_set_membership, uchar receiver_light_set)
float evaluate(sampler2DArray util_tx, LightData light, LightShape shape, LightVector lv, LTCData ltc_data)
float shadow_eval(ShadowRenderData &srd, LightData light, const bool is_directional, const bool is_transmission, bool is_translucent_with_thickness, float2 frag_co, Thickness thickness, float3 P, float3 Ng, float3 N, float terminator_normal_offset, float terminator_geometry_offset, float soft_shadow_scale, int ray_count, int ray_step_count)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
packed_float3 light_shadowed
packed_float3 light_unshadowed
static LightShape get(LightData light, LightVector lv)
static LightVector get(LightData light, const bool is_directional, float3 P)
sampler2DArray utility_tx
static LTCData unpack_from(ClosureLight cl)
LightEvalConstants constants
void eval_transmission(light::EvalCtx< true > &ctx, float vPz)
void eval_reflection(light::EvalCtx< false > &ctx, float vPz)
void eval_local(LightEvalData &srt, uint, LightData light)
ClosureStack< is_transmission > stack
void light_eval_single(LightEvalData &srt, LightData light, const bool is_directional)
void eval_directional(LightEvalData &srt, uint, LightData light)