Blender
V5.3
source
blender
draw
engines
eevee
shaders
eevee_utility_tx.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_defines.hh
"
8
#include "
gpu_shader_compat.hh
"
9
10
struct
UtilityTexture
{
11
[[
sampler
(
RBUFS_UTILITY_TEX_SLOT
)]]
sampler2DArray
utility_tx
;
12
13
/* Fetch texel. Repeat extend mode if above range. */
14
float4
fetch
(
float2
texel,
float
layer
)
const
15
{
16
return
texelFetch
(
utility_tx
,
int3
(
int2
(texel) %
UTIL_TEX_SIZE
,
int
(
layer
)), 0);
17
}
18
19
/* Sample at uv position. Filtered & extend mode enabled. */
20
float4
sample_extend
(
float2
uv,
float
layer
)
const
21
{
22
return
textureLod
(
utility_tx
,
float3
(uv,
layer
), 0.0f);
23
}
24
25
/* Sample at uv position but with scale and bias so that uv space bounds lie on texel centers. */
26
float4
sample_lut
(
float2
uv,
float
layer
)
const
27
{
28
/* Scale and bias coordinates, for correct filtered lookup. */
29
uv = uv *
UTIL_TEX_UV_SCALE
+
UTIL_TEX_UV_BIAS
;
30
return
textureLod
(
utility_tx
,
float3
(uv,
layer
), 0.0f);
31
}
32
33
/* Sample GGX BSDF LUT. */
34
float4
sample_bsdf_lut
(
float2
uv,
float
layer
)
const
35
{
36
/* Scale and bias coordinates, for correct filtered lookup. */
37
uv = uv *
UTIL_TEX_UV_SCALE
+
UTIL_TEX_UV_BIAS
;
38
layer
=
layer
*
UTIL_BSDF_LAYER_COUNT
+
UTIL_BSDF_LAYER
;
39
40
float
layer_floored;
41
float
interp
=
modf
(
layer
, layer_floored);
42
43
float4
tex_low =
textureLod
(
utility_tx
,
float3
(uv, layer_floored), 0.0f);
44
float4
tex_high =
textureLod
(
utility_tx
,
float3
(uv, layer_floored + 1.0f), 0.0f);
45
46
/* Manual trilinear interpolation. */
47
return
mix
(tex_low, tex_high,
interp
);
48
}
49
};
eevee_defines.hh
RBUFS_UTILITY_TEX_SLOT
#define RBUFS_UTILITY_TEX_SLOT
Definition
eevee_defines.hh:229
UTIL_BSDF_LAYER
#define UTIL_BSDF_LAYER
Definition
eevee_defines.hh:216
UTIL_TEX_UV_BIAS
#define UTIL_TEX_UV_BIAS
Definition
eevee_defines.hh:210
UTIL_TEX_UV_SCALE
#define UTIL_TEX_UV_SCALE
Definition
eevee_defines.hh:209
UTIL_BSDF_LAYER_COUNT
#define UTIL_BSDF_LAYER_COUNT
Definition
eevee_defines.hh:206
UTIL_TEX_SIZE
#define UTIL_TEX_SIZE
Definition
eevee_defines.hh:205
gpu_shader_compat.hh
sampler
#define sampler(slot)
Definition
gpu_shader_cxx_attribute.hh:115
layer
#define layer
Definition
gpu_shader_cxx_attribute.hh:69
modf
#define modf
Definition
gpu_shader_cxx_builtin.hh:115
texelFetch
TEX_TEMPLATE DataVec texelFetch(T, IntCoord, int) RET
textureLod
TEX_TEMPLATE DataVec textureLod(T, FltCoord, float) RET
sampler2DArray
SamplerBase< float, 2, false, true > sampler2DArray
Definition
gpu_shader_cxx_sampler.hh:76
interp
ccl_device_inline float interp(const float a, const float b, const float t)
Definition
math_base.h:549
blender::float4
VecBase< float, 4 > float4
Definition
BLI_math_vector_types.hh:800
blender::int2
VecBase< int32_t, 2 > int2
Definition
BLI_math_vector_types.hh:781
blender::float2
VecBase< float, 2 > float2
Definition
BLI_math_vector_types.hh:798
blender::int3
VecBase< int32_t, 3 > int3
Definition
BLI_math_vector_types.hh:782
blender::float3
VecBase< float, 3 > float3
Definition
BLI_math_vector_types.hh:799
mix
#define mix
Definition
radial_tiling_shared.hh:83
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_extend
float4 sample_extend(float2 uv, float layer) const
Definition
eevee_utility_tx.bsl.hh:20
UtilityTexture::sample_bsdf_lut
float4 sample_bsdf_lut(float2 uv, float layer) const
Definition
eevee_utility_tx.bsl.hh:34
UtilityTexture::utility_tx
sampler2DArray utility_tx
Definition
eevee_utility_tx.bsl.hh:11
UtilityTexture::fetch
float4 fetch(float2 texel, float layer) const
Definition
eevee_utility_tx.bsl.hh:14
Generated on
for Blender by
doxygen
1.18.0