Blender V5.3
eevee_subsurface_shared.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#pragma once
12
14
15#ifndef GPU_SHADER
16namespace blender::eevee {
17#endif
18
19static constexpr int SSS_SAMPLE_MAX = 64;
20static constexpr float SSS_BURLEY_TRUNCATE = 16.0f;
21static constexpr float SSS_BURLEY_TRUNCATE_CDF = 0.9963790093708328;
22static constexpr float SSS_TRANSMIT_LUT_SIZE = 64.0f;
23static constexpr float SSS_TRANSMIT_LUT_RADIUS = 2.0f;
24static constexpr float SSS_TRANSMIT_LUT_SCALE = ((SSS_TRANSMIT_LUT_SIZE - 1.0f) /
26static constexpr float SSS_TRANSMIT_LUT_BIAS = (0.5f / float(SSS_TRANSMIT_LUT_SIZE));
27static constexpr float SSS_TRANSMIT_LUT_STEP_RES = 64.0f;
28
31 /* NOTE(fclem) Using float4 for alignment. */
41 int _pad1;
42 int _pad2;
43};
44
45static inline float3 burley_setup(float3 radius, float3 albedo)
46{
47 /* TODO(fclem): Avoid constant duplication. */
48 const float m_1_pi = 0.318309886183790671538f;
49
50 float3 A = albedo;
51 /* Diffuse surface transmission, equation (6). */
52 float3 s = 1.9f - A + 3.5f * ((A - 0.8f) * (A - 0.8f));
53 /* Mean free path length adapted to fit ancient Cubic and Gaussian models. */
54 float3 l = 0.25f * m_1_pi * radius;
55
56 return l / s;
57}
58
59static inline float3 burley_eval(float3 d, float r)
60{
61 /* Slide 33. */
62 float3 exp_r_3_d;
63 /* TODO(fclem): Vectorize. */
64 exp_r_3_d.x = expf(-r / (3.0f * d.x));
65 exp_r_3_d.y = expf(-r / (3.0f * d.y));
66 exp_r_3_d.z = expf(-r / (3.0f * d.z));
67 float3 exp_r_d = exp_r_3_d * exp_r_3_d * exp_r_3_d;
68 /* NOTE:
69 * - Surface albedo is applied at the end.
70 * - This is normalized diffuse model, so the equation is multiplied
71 * by 2*pi, which also matches `cdf()`.
72 */
73 return (exp_r_d + exp_r_3_d) / (4.0 * d);
74}
75
76#ifndef GPU_SHADER
77} // namespace blender::eevee
78#endif
#define host_shared
#define A
#define expf(x)
static constexpr float SSS_BURLEY_TRUNCATE
static constexpr float SSS_BURLEY_TRUNCATE_CDF
static constexpr float SSS_TRANSMIT_LUT_BIAS
static constexpr float SSS_TRANSMIT_LUT_SIZE
static constexpr int SSS_SAMPLE_MAX
static constexpr float SSS_TRANSMIT_LUT_SCALE
static constexpr float SSS_TRANSMIT_LUT_RADIUS
static float3 burley_setup(float3 radius, float3 albedo)
static float3 burley_eval(float3 d, float r)
static constexpr float SSS_TRANSMIT_LUT_STEP_RES
ATTR_WARN_UNUSED_RESULT const BMLoop * l
VecBase< float, 4 > float4
VecBase< float, 3 > float3
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float