Blender
V5.3
source
blender
draw
engines
eevee
shaders
eevee_bxdf_lut_lib.bsl.hh
Go to the documentation of this file.
1
/* SPDX-FileCopyrightText: 2017-2026 Blender Authors
2
*
3
* SPDX-License-Identifier: GPL-2.0-or-later */
4
9
10
#pragma once
11
12
#include "
eevee_defines.hh
"
13
#include "
eevee_utility_tx.bsl.hh
"
14
#include "
gpu_shader_compat.hh
"
15
#include "
gpu_shader_math_base.bsl.hh
"
16
17
namespace
eevee::lut
{
18
26
struct
GGXBrdfData
{
27
float
scale
;
28
float
bias
;
29
float
metal_bias
;
30
31
float4
pack
()
const
32
{
33
return
float4
(
scale
,
bias
,
metal_bias
, 0.0f);
34
}
35
36
static
GGXBrdfData
unpack
(
float4
data)
37
{
38
return
{.scale = data.x, .bias = data.y, .metal_bias = data.z};
39
}
40
41
static
float2
lut_coords_get
(
float
cos_theta
,
float
roughness)
42
{
43
return
float2
(roughness,
sqrt
(
saturate
(1.0f -
cos_theta
)));
44
}
45
46
static
GGXBrdfData
sample_utility_tx
(
const
UtilityTexture
&util_tx,
47
float
cos_theta
,
48
float
roughness)
49
{
50
const
float2
coords =
lut_coords_get
(
cos_theta
, roughness);
51
const
float4
data = util_tx.
sample_lut
(coords,
UTIL_BRDF_LAYER
);
52
return
unpack
(data);
53
}
54
};
55
63
struct
GGXBsdfData
{
64
float
scale
;
65
float
bias
;
66
float
transmission_factor
;
67
68
float4
pack
()
const
69
{
70
return
float4
(
scale
,
bias
,
transmission_factor
, 0.0f);
71
}
72
73
static
GGXBsdfData
unpack
(
float4
data)
74
{
75
return
{.scale = data.x, .bias = data.y, .transmission_factor = data.z};
76
}
77
78
static
float3
lut_coords_get
(
float
cos_theta
,
float
roughness,
float
ior)
79
{
80
/* IOR is the sine of the critical angle. */
81
float
critical_cos =
sqrt
(1.0f - ior * ior);
82
83
float3
coords;
84
coords.
x
=
square
(ior);
85
coords.
y
=
cos_theta
;
86
coords.
y
-= critical_cos;
87
coords.
y
/= (coords.
y
> 0.0f) ? (1.0f - critical_cos) : critical_cos;
88
coords.
y
= coords.
y
* 0.5f + 0.5f;
89
coords.
z
= roughness;
90
91
return
saturate
(coords);
92
}
93
94
static
GGXBsdfData
sample_utility_tx
(
const
UtilityTexture
&util_tx,
95
float
cos_theta
,
96
float
roughness,
97
float
ior)
98
{
99
const
float3
coords =
lut_coords_get
(
cos_theta
, roughness, ior);
100
const
float4
data = util_tx.
sample_bsdf_lut
(coords.xy, coords.
z
);
101
return
unpack
(data);
102
}
103
};
104
111
struct
GGXBtdfGt1Data
{
112
float
transmission_factor
;
113
114
float4
pack
()
const
115
{
116
return
float4
(
transmission_factor
, 0.0f, 0.0f, 0.0f);
117
}
118
119
static
GGXBtdfGt1Data
unpack
(
float4
data)
120
{
121
return
{.transmission_factor = data.x};
122
}
123
124
static
float3
lut_coords_get
(
float
cos_theta
,
float
roughness,
float
f0)
125
{
126
return
float3
(
sqrt
(f0),
sqrt
(1.0f -
cos_theta
), roughness);
127
}
128
129
static
GGXBtdfGt1Data
sample_utility_tx
(
const
UtilityTexture
&util_tx,
130
float
cos_theta
,
131
float
roughness,
132
float
f0)
133
{
134
const
float3
coords =
lut_coords_get
(
cos_theta
, roughness, f0);
135
const
float4
data = util_tx.
sample_bsdf_lut
(coords.xy, coords.
z
);
136
/* Shuffle to expect the same layout as the output of `pack`. */
137
return
unpack
(data.wxyz);
138
}
139
};
140
141
}
// namespace eevee::lut
cos_theta
ccl_device_inline float cos_theta(const float3 w)
Definition
bsdf_principled_hair_huang.h:86
eevee_defines.hh
UTIL_BRDF_LAYER
#define UTIL_BRDF_LAYER
Definition
eevee_defines.hh:215
eevee_utility_tx.bsl.hh
gpu_shader_compat.hh
sqrt
#define sqrt
Definition
gpu_shader_cxx_builtin.hh:118
gpu_shader_math_base.bsl.hh
square
float square(float v)
Definition
gpu_shader_math_base.bsl.hh:56
eevee::lut
Definition
eevee_bxdf_lut.bsl.hh:20
saturate
#define saturate(a)
Definition
smaa.cc:319
UtilityTexture
Definition
eevee_utility_tx.bsl.hh:10
UtilityTexture::sample_lut
float4 sample_lut(float2 uv, float layer) const
Definition
eevee_utility_tx.bsl.hh:26
UtilityTexture::sample_bsdf_lut
float4 sample_bsdf_lut(float2 uv, float layer) const
Definition
eevee_utility_tx.bsl.hh:34
eevee::lut::GGXBrdfData
Definition
eevee_bxdf_lut_lib.bsl.hh:26
eevee::lut::GGXBrdfData::scale
float scale
Definition
eevee_bxdf_lut_lib.bsl.hh:27
eevee::lut::GGXBrdfData::bias
float bias
Definition
eevee_bxdf_lut_lib.bsl.hh:28
eevee::lut::GGXBrdfData::unpack
static GGXBrdfData unpack(float4 data)
Definition
eevee_bxdf_lut_lib.bsl.hh:36
eevee::lut::GGXBrdfData::lut_coords_get
static float2 lut_coords_get(float cos_theta, float roughness)
Definition
eevee_bxdf_lut_lib.bsl.hh:41
eevee::lut::GGXBrdfData::metal_bias
float metal_bias
Definition
eevee_bxdf_lut_lib.bsl.hh:29
eevee::lut::GGXBrdfData::pack
float4 pack() const
Definition
eevee_bxdf_lut_lib.bsl.hh:31
eevee::lut::GGXBrdfData::sample_utility_tx
static GGXBrdfData sample_utility_tx(const UtilityTexture &util_tx, float cos_theta, float roughness)
Definition
eevee_bxdf_lut_lib.bsl.hh:46
eevee::lut::GGXBsdfData
Definition
eevee_bxdf_lut_lib.bsl.hh:63
eevee::lut::GGXBsdfData::pack
float4 pack() const
Definition
eevee_bxdf_lut_lib.bsl.hh:68
eevee::lut::GGXBsdfData::transmission_factor
float transmission_factor
Definition
eevee_bxdf_lut_lib.bsl.hh:66
eevee::lut::GGXBsdfData::scale
float scale
Definition
eevee_bxdf_lut_lib.bsl.hh:64
eevee::lut::GGXBsdfData::bias
float bias
Definition
eevee_bxdf_lut_lib.bsl.hh:65
eevee::lut::GGXBsdfData::lut_coords_get
static float3 lut_coords_get(float cos_theta, float roughness, float ior)
Definition
eevee_bxdf_lut_lib.bsl.hh:78
eevee::lut::GGXBsdfData::unpack
static GGXBsdfData unpack(float4 data)
Definition
eevee_bxdf_lut_lib.bsl.hh:73
eevee::lut::GGXBsdfData::sample_utility_tx
static GGXBsdfData sample_utility_tx(const UtilityTexture &util_tx, float cos_theta, float roughness, float ior)
Definition
eevee_bxdf_lut_lib.bsl.hh:94
eevee::lut::GGXBtdfGt1Data
Definition
eevee_bxdf_lut_lib.bsl.hh:111
eevee::lut::GGXBtdfGt1Data::transmission_factor
float transmission_factor
Definition
eevee_bxdf_lut_lib.bsl.hh:112
eevee::lut::GGXBtdfGt1Data::unpack
static GGXBtdfGt1Data unpack(float4 data)
Definition
eevee_bxdf_lut_lib.bsl.hh:119
eevee::lut::GGXBtdfGt1Data::pack
float4 pack() const
Definition
eevee_bxdf_lut_lib.bsl.hh:114
eevee::lut::GGXBtdfGt1Data::lut_coords_get
static float3 lut_coords_get(float cos_theta, float roughness, float f0)
Definition
eevee_bxdf_lut_lib.bsl.hh:124
eevee::lut::GGXBtdfGt1Data::sample_utility_tx
static GGXBtdfGt1Data sample_utility_tx(const UtilityTexture &util_tx, float cos_theta, float roughness, float f0)
Definition
eevee_bxdf_lut_lib.bsl.hh:129
float2
Definition
types_float2.h:13
float3
Definition
sky_math.h:135
float3::z
float z
Definition
sky_math.h:136
float3::y
float y
Definition
sky_math.h:136
float3::x
float x
Definition
sky_math.h:136
float4
Definition
sky_math.h:224
Generated on
for Blender by
doxygen
1.18.0