Blender
V5.3
source
blender
draw
engines
eevee
shaders
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
7
#include "
gpu_shader_compat.hh
"
8
9
/* Follow eMaterial_ThicknessMode. */
10
enum class
ThicknessMode
:
bool
{
Sphere
=
false
,
Slab
=
true
};
11
12
struct
ThicknessIsect
{
13
/* Normal at the intersection point on the sphere. */
14
float3
hit_N
;
15
/* Position of the intersection point on the sphere. */
16
float3
hit_P
;
17
};
18
19
/* Storage for object thickness, which packs both thickness value and
20
* an associated model mode (slab, sphere) through the sign bit. */
21
class
Thickness
{
22
float
data;
23
24
public
:
25
static
Thickness
from
(
float
value
,
ThicknessMode
mode
)
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
44
ThicknessMode
mode
()
const
45
{
46
return
data > 0.0 ?
ThicknessMode::Sphere
:
ThicknessMode::Slab
;
47
}
48
49
ThicknessIsect
shape_intersect
(
float3
N
,
float3
L
)
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
};
Thickness
Definition
eevee_thickness_lib.bsl.hh:21
Thickness::shape_intersect
ThicknessIsect shape_intersect(float3 N, float3 L)
Definition
eevee_thickness_lib.bsl.hh:49
Thickness::from
static Thickness from(float value, ThicknessMode mode)
Definition
eevee_thickness_lib.bsl.hh:25
Thickness::zero
static Thickness zero()
Definition
eevee_thickness_lib.bsl.hh:32
Thickness::value
float value() const
Definition
eevee_thickness_lib.bsl.hh:39
Thickness::mode
ThicknessMode mode() const
Definition
eevee_thickness_lib.bsl.hh:44
ThicknessMode
ThicknessMode
Definition
eevee_thickness_lib.bsl.hh:10
ThicknessMode::Slab
@ Slab
Definition
eevee_thickness_lib.bsl.hh:10
ThicknessMode::Sphere
@ Sphere
Definition
eevee_thickness_lib.bsl.hh:10
gpu_shader_compat.hh
normalize
VecBase< float, D > normalize(VecOp< float, D >) RET
dot
float dot(VecOp< float, D >, VecOp< float, D >) RET
abs
#define abs
Definition
gpu_shader_cxx_builtin.hh:104
N
#define N
Definition
mball_tessellate.cc:278
L
#define L
Definition
mball_tessellate.cc:274
blender::float3
VecBase< float, 3 > float3
Definition
BLI_math_vector_types.hh:799
Sphere
Definition
draw_shape.bsl.hh:42
ThicknessIsect
Definition
eevee_thickness_lib.bsl.hh:12
ThicknessIsect::hit_N
float3 hit_N
Definition
eevee_thickness_lib.bsl.hh:14
ThicknessIsect::hit_P
float3 hit_P
Definition
eevee_thickness_lib.bsl.hh:16
float3
Definition
sky_math.h:135
Generated on
for Blender by
doxygen
1.18.0