Blender V5.3
eevee_bxdf_diffuse.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
11#include "gpu_shader_codegen_lib.glsl"
14#include "gpu_shader_ray.bsl.hh"
15
16/* -------------------------------------------------------------------- */
19
28{
29 BsdfSample samp;
30 samp.direction = sample_cos_hemisphere(rand_cylinder);
31 samp.pdf = samp.direction.z * M_1_PI;
32 return samp;
33}
34
36{
37 BsdfEval eval;
38 eval.throughput = eval.pdf = saturate(dot(N, L)) * M_1_PI;
39 return eval;
40}
41
43{
44 return 1.0f;
45}
46
54
55ClosureLight bxdf_diffuse_light(ClosureUndetermined cl, float3 V)
56{
57 ClosureLight light;
58 light.N = cl.N;
59 light.type = LIGHT_DIFFUSE;
60 eevee::LTCData::pack_identity(light, light.N, V);
61 return light;
62}
63
65
66/* -------------------------------------------------------------------- */
69
79{
80 if (thickness.mode() == ThicknessMode::Sphere && thickness.value() != 0.0f) {
81 /* Two transmission events inside a sphere is a uniform sphere distribution. */
82 float cos_theta = rand.x * 2.0f - 1.0f;
83 BsdfSample samp;
84 samp.direction = float3(rand.yz * sin_from_cos(cos_theta), -cos_theta);
85 samp.pdf = 0.25f * M_1_PI;
86 return samp;
87 }
88
89 /* Inverted cosine distribution. */
91 samp.direction = -samp.direction;
92 return samp;
93}
94
96{
97 if (thickness.mode() == ThicknessMode::Sphere && thickness.value() != 0.0f) {
98 /* Two transmission events inside a sphere is a uniform sphere distribution. */
99 BsdfEval eval;
100 eval.throughput = eval.pdf = 0.25f * M_1_PI;
101 return eval;
102 }
103
104 BsdfEval eval;
105 eval.throughput = eval.pdf = saturate(dot(-N, L));
106 return eval;
107}
108
110{
111 return 1.0f;
112}
113
115{
116 LightProbeRay probe;
118 /* If using the spherical assumption, discard any directionality from the lighting. */
119 const bool sphere_with_thickness = thickness.mode() == ThicknessMode::Sphere &&
120 thickness.value() != 0.0f;
121 probe.dominant_direction = sphere_with_thickness ? float3(0.0f) : -N;
122 return probe;
123}
124
125Ray bxdf_translucent_ray_amend(ClosureUndetermined cl, float3 /*V*/, Ray ray, Thickness thickness)
126{
127 if (thickness.mode() == ThicknessMode::Sphere) {
128 /* Ray direction is distributed on the whole sphere.
129 * Move the ray origin to the sphere surface (with bias to avoid self-intersection). */
130 ray.origin += (ray.direction - cl.N) * thickness.value() * 0.505f;
131 }
132 return ray;
133}
134
135ClosureLight bxdf_translucent_light(ClosureUndetermined cl, float3 V, Thickness thickness)
136{
137 /* A translucent sphere lit by a light outside the sphere transmits the
138 * light uniformly over the sphere. To mimic this phenomenon, the LTC evaluation
139 * does not horizon-clip lights if we set `LTCFormFactorType::TwoSidedCosineSphere`.
140 *
141 * For slab model, the approximation has little to no impact on the lighting in practice,
142 * only focusing the light a tiny bit. Using the flipped normal is good enough approximation.
143 */
144 const bool sphere_with_thickness = thickness.mode() == ThicknessMode::Sphere &&
145 thickness.value() != 0.0f;
146
147 ClosureLight light;
148 light.N = -cl.N;
149 light.type = sphere_with_thickness ? LIGHT_TRANSLUCENT_WITH_THICKNESS : LIGHT_DIFFUSE;
150
151 eevee::LTCData ltc_data = eevee::LTCData::identity(light.N, V);
152 if (sphere_with_thickness) {
154 }
155 ltc_data.pack_to(light);
156
157 return light;
158}
159
#define M_1_PI
ccl_device_inline float cos_theta(const float3 w)
float value() const
ThicknessMode mode() const
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)
BsdfSample bxdf_translucent_sample(float3 rand, Thickness thickness)
BsdfSample bxdf_diffuse_sample(const float3 rand_cylinder)
Ray bxdf_translucent_ray_amend(ClosureUndetermined cl, float3, Ray ray, Thickness thickness)
ClosureLight bxdf_translucent_light(ClosureUndetermined cl, float3 V, Thickness thickness)
float3 sample_cos_hemisphere(const float2 rand)
float dot(VecOp< float, D >, VecOp< float, D >) RET
float sin_from_cos(float c)
#define N
#define L
#define saturate(a)
Definition smaa.cc:319
packed_float3 direction
packed_float3 dominant_direction
packed_float3 direction
packed_float3 origin
LTCFormFactorType form_factor_type
static LTCData identity(float3 N, float3 V)
void pack_to(ClosureLight &cl) const
static void pack_identity(ClosureLight &cl, float3 N, float3 V)
float x
Definition sky_math.h:136
CCL_NAMESPACE_BEGIN struct Window V