Blender V5.0
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
8
9#pragma once
10
12
13#ifndef GPU_SHADER
14namespace blender::eevee {
15#endif
16
17#define SSS_SAMPLE_MAX 64
18#define SSS_BURLEY_TRUNCATE 16.0
19#define SSS_BURLEY_TRUNCATE_CDF 0.9963790093708328
20#define SSS_TRANSMIT_LUT_SIZE 64.0
21#define SSS_TRANSMIT_LUT_RADIUS 2.0
22#define SSS_TRANSMIT_LUT_SCALE ((SSS_TRANSMIT_LUT_SIZE - 1.0) / float(SSS_TRANSMIT_LUT_SIZE))
23#define SSS_TRANSMIT_LUT_BIAS (0.5 / float(SSS_TRANSMIT_LUT_SIZE))
24#define SSS_TRANSMIT_LUT_STEP_RES 64.0
25
28 /* NOTE(fclem) Using float4 for alignment. */
36 int _pad1;
37 int _pad2;
38};
40
41static inline float3 burley_setup(float3 radius, float3 albedo)
42{
43 /* TODO(fclem): Avoid constant duplication. */
44 const float m_1_pi = 0.318309886183790671538;
45
46 float3 A = albedo;
47 /* Diffuse surface transmission, equation (6). */
48 float3 s = 1.9 - A + 3.5 * ((A - 0.8) * (A - 0.8));
49 /* Mean free path length adapted to fit ancient Cubic and Gaussian models. */
50 float3 l = 0.25 * m_1_pi * radius;
51
52 return l / s;
53}
54
55static inline float3 burley_eval(float3 d, float r)
56{
57 /* Slide 33. */
58 float3 exp_r_3_d;
59 /* TODO(fclem): Vectorize. */
60 exp_r_3_d.x = expf(-r / (3.0 * d.x));
61 exp_r_3_d.y = expf(-r / (3.0 * d.y));
62 exp_r_3_d.z = expf(-r / (3.0 * d.z));
63 float3 exp_r_d = exp_r_3_d * exp_r_3_d * exp_r_3_d;
64 /* NOTE:
65 * - Surface albedo is applied at the end.
66 * - This is normalized diffuse model, so the equation is multiplied
67 * by 2*pi, which also matches `cdf()`.
68 */
69 return (exp_r_d + exp_r_3_d) / (4.0 * d);
70}
71
72#ifndef GPU_SHADER
73} // namespace blender::eevee
74#endif
#define BLI_STATIC_ASSERT_ALIGN(st, align)
Definition BLI_assert.h:86
ATTR_WARN_UNUSED_RESULT const BMLoop * l
#define A
#define expf(x)
#define SSS_SAMPLE_MAX
static float3 burley_setup(float3 radius, float3 albedo)
static float3 burley_eval(float3 d, float r)
VecBase< float, 4 > float4
VecBase< float, 3 > float3