Blender V5.3
eevee_closure.bsl.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
5#pragma once
6
7#include "eevee_bxdf.bsl.hh"
8#include "gpu_shader_codegen_lib.glsl"
9
10/* Return the apparent roughness of a closure compared to a GGX reflection lobe. */
11float closure_apparent_roughness_get(ClosureUndetermined cl)
12{
13 switch (cl.type) {
19 case CLOSURE_BSDF_MICROFACET_GGX_REFLECTION_ID:
20 return bxdf_ggx_perceived_roughness_reflection(to_closure_reflection(cl).roughness);
22 return bxdf_ggx_perceived_roughness_reflection(to_closure_thin_refraction(cl).roughness);
24 return bxdf_ggx_perceived_roughness_transmission(to_closure_refraction(cl).roughness,
25 to_closure_refraction(cl).ior);
26 case CLOSURE_NONE_ID:
27 return 0.0f;
28 }
29 return 0.0f;
30}
31
32float closure_evaluate_pdf(ClosureUndetermined cl, float3 L, float3 V, Thickness thickness)
33{
34 switch (cl.type) {
36 return bxdf_translucent_eval(cl.N, L, thickness).pdf;
38 /* TODO(fclem): Sampled BSSDF. */
39 return bxdf_diffuse_eval(cl.N, L).pdf;
41 return bxdf_diffuse_eval(cl.N, L).pdf;
42 case CLOSURE_BSDF_MICROFACET_GGX_REFLECTION_ID: {
43 ClosureReflection cl_ = to_closure_reflection(cl);
44 float roughness_sq = square(cl_.roughness);
45 return bxdf_ggx_eval_reflection(cl.N, L, V, roughness_sq, true).pdf;
46 }
48 ClosureRefraction cl_ = to_closure_refraction(cl);
49 float roughness_sq = square(cl_.roughness);
50 return bxdf_ggx_eval_refraction(cl.N, L, V, roughness_sq, cl_.ior, thickness, true).pdf;
51 }
53 ClosureThinRefraction cl_ = to_closure_thin_refraction(cl);
54 float roughness_sq = square(cl_.roughness);
55 return bxdf_ggx_eval_reflection(-cl.N, L, reflect(V, cl.N), roughness_sq, true).pdf;
56 }
57 case CLOSURE_NONE_ID:
58 break;
59 }
60 assert(false);
61 return 0.0f;
62}
63
64LightProbeRay bxdf_lightprobe_ray(ClosureUndetermined cl,
65 float3 /*P*/,
66 float3 V,
67 Thickness thickness)
68{
69 switch (cl.type) {
72 break;
73 case CLOSURE_NONE_ID:
77 case CLOSURE_BSDF_MICROFACET_GGX_REFLECTION_ID:
79 break;
80 }
81
82 switch (cl.type) {
84 return bxdf_translucent_lightprobe(cl.N, thickness);
85 case CLOSURE_NONE_ID:
88 return bxdf_diffuse_lightprobe(cl.N);
89 case CLOSURE_BSDF_MICROFACET_GGX_REFLECTION_ID:
90 return bxdf_ggx_lightprobe_reflection(to_closure_reflection(cl), V);
92 return bxdf_ggx_lightprobe_transmission(to_closure_refraction(cl), V, thickness);
94 return bxdf_ggx_lightprobe_thin_glass_transmission(to_closure_thin_refraction(cl), V);
95 }
96
97 assert(false);
98 return {};
99}
100
102 ClosureUndetermined cl,
103 float3 V,
104 Thickness thickness,
105 const bool is_transmission)
106{
107 ClosureLight cl_light;
108 if (is_transmission) {
109 /* Transmission. */
110 switch (cl.type) {
112 /* If the `thickness / sss_radius` ratio is near 0, this transmission term should converge
113 * to a uniform term like the translucent BSDF. But we need to find what to do in other
114 * cases. For now, approximate the transmission term as just back-facing. */
115 cl_light = bxdf_translucent_light(cl, V, Thickness::zero());
116 break;
118 cl_light = bxdf_ggx_light_transmission(util_tx, to_closure_refraction(cl), V, thickness);
119 break;
122 util_tx, to_closure_thin_refraction(cl), V);
123 break;
125 /* Defaults to avoid UB. */
126 case CLOSURE_BSDF_MICROFACET_GGX_REFLECTION_ID:
128 case CLOSURE_NONE_ID:
129 cl_light = bxdf_translucent_light(cl, V, thickness);
130 break;
131 }
132 }
133 else {
134 /* Reflection. */
135 switch (cl.type) {
136 case CLOSURE_BSDF_MICROFACET_GGX_REFLECTION_ID:
137 cl_light = bxdf_ggx_light_reflection(util_tx, to_closure_reflection(cl), V);
138 break;
141 /* Defaults to avoid UB. */
145 case CLOSURE_NONE_ID:
146 cl_light = bxdf_diffuse_light(cl, V);
147 break;
148 }
149 }
150 cl_light.light_shadowed = float3(0.0f);
151 cl_light.light_unshadowed = float3(0.0f);
152 return cl_light;
153}
154
156 ClosureUndetermined cl,
157 float3 V,
158 Thickness thickness)
159{
160 return closure_light_new_ex(util_tx, cl, V, thickness, true);
161}
162
163ClosureLight closure_light_new(const UtilityTexture &util_tx, ClosureUndetermined cl, float3 V)
164{
165 return closure_light_new_ex(util_tx, cl, V, Thickness::zero(), false);
166}
static Thickness zero()
LightProbeRay bxdf_diffuse_lightprobe(float3 N)
float bxdf_translucent_perceived_roughness()
ClosureLight bxdf_diffuse_light(ClosureUndetermined cl, float3 V)
BsdfEval bxdf_translucent_eval(float3 N, float3 L, Thickness thickness)
float bxdf_diffuse_perceived_roughness()
BsdfEval bxdf_diffuse_eval(float3 N, float3 L)
LightProbeRay bxdf_translucent_lightprobe(float3 N, Thickness thickness)
ClosureLight bxdf_translucent_light(ClosureUndetermined cl, float3 V, Thickness thickness)
float bxdf_ggx_perceived_roughness_reflection(float roughness)
LightProbeRay bxdf_ggx_lightprobe_reflection(ClosureReflection cl, float3 V)
LightProbeRay bxdf_ggx_lightprobe_thin_glass_transmission(ClosureThinRefraction cl, float3 V)
LightProbeRay bxdf_ggx_lightprobe_transmission(ClosureRefraction cl, float3 V, Thickness thickness)
ClosureLight bxdf_ggx_light_reflection(const UtilityTexture &util_tx, ClosureReflection cl, float3 V)
void bxdf_ggx_context_amend_transmission(ClosureUndetermined &cl, float3 &V, Thickness thickness)
BsdfEval bxdf_ggx_eval_refraction(float3 N, float3 L, float3 V, float alpha, float ior, Thickness thickness, const bool do_clamp)
BsdfEval bxdf_ggx_eval_reflection(float3 N, float3 L, float3 V, float alpha, bool do_clamp)
ClosureLight bxdf_ggx_light_thin_glass_transmission(const UtilityTexture &util_tx, ClosureThinRefraction cl, float3 V)
ClosureLight bxdf_ggx_light_transmission(const UtilityTexture &util_tx, ClosureRefraction cl, float3 V, Thickness thickness)
float bxdf_ggx_perceived_roughness_transmission(float roughness, float ior)
ClosureLight closure_light_new(const UtilityTexture &util_tx, ClosureUndetermined cl, float3 V, Thickness thickness)
ClosureLight closure_light_new_ex(const UtilityTexture &util_tx, ClosureUndetermined cl, float3 V, Thickness thickness, const bool is_transmission)
float closure_apparent_roughness_get(ClosureUndetermined cl)
LightProbeRay bxdf_lightprobe_ray(ClosureUndetermined cl, float3, float3 V, Thickness thickness)
float closure_evaluate_pdf(ClosureUndetermined cl, float3 L, float3 V, Thickness thickness)
#define assert(assertion)
VecBase< T, D > reflect(VecOp< T, D >, VecOp< T, D >) RET
float square(float v)
@ CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID
@ CLOSURE_BSDF_DIFFUSE_ID
@ CLOSURE_BSSRDF_BURLEY_ID
@ CLOSURE_NONE_ID
@ CLOSURE_BSDF_THIN_GLASS_TRANSMISSION_ID
@ CLOSURE_BSDF_TRANSLUCENT_ID
#define L
packed_float3 light_shadowed
packed_float3 light_unshadowed
CCL_NAMESPACE_BEGIN struct Window V