Blender V5.3
eevee_thickness_lib.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
8
9/* Follow eMaterial_ThicknessMode. */
10enum class ThicknessMode : bool { Sphere = false, Slab = true };
11
13 /* Normal at the intersection point on the sphere. */
15 /* Position of the intersection point on the sphere. */
17};
18
19/* Storage for object thickness, which packs both thickness value and
20 * an associated model mode (slab, sphere) through the sign bit. */
21class Thickness {
22 float data;
23
24 public:
26 {
27 Thickness thickness;
28 thickness.data = (mode == ThicknessMode::Sphere) ? value : -value;
29 return thickness;
30 }
31
32 static Thickness zero()
33 {
34 Thickness thickness;
35 thickness.data = 0.0f;
36 return thickness;
37 }
38
39 float value() const
40 {
41 return abs(data);
42 }
43
45 {
46 return data > 0.0 ? ThicknessMode::Sphere : ThicknessMode::Slab;
47 }
48
50 {
51 if (mode() == ThicknessMode::Sphere) {
52 return sphere_intersect(value(), N, L);
53 }
54 return plane_intersect(value(), N, L);
55 }
56
57 private:
64 ThicknessIsect sphere_intersect(float diameter, float3 N, float3 L)
65 {
66 ThicknessIsect isect;
67 float cos_alpha = dot(L, -N);
68 isect.hit_N = normalize(N + L * (cos_alpha * 2.0f));
69 isect.hit_P = L * (cos_alpha * diameter);
70 return isect;
71 }
72
79 ThicknessIsect plane_intersect(float plane_distance, float3 N, float3 L)
80 {
81 ThicknessIsect isect;
82 float distance_from_shading_plane = dot(L, -N);
83 isect.hit_N = -N;
84 isect.hit_P = L * (plane_distance / distance_from_shading_plane);
85 return isect;
86 }
87};
ThicknessIsect shape_intersect(float3 N, float3 L)
static Thickness from(float value, ThicknessMode mode)
static Thickness zero()
float value() const
ThicknessMode mode() const
VecBase< float, D > normalize(VecOp< float, D >) RET
float dot(VecOp< float, D >, VecOp< float, D >) RET
#define abs
#define N
#define L
VecBase< float, 3 > float3