Blender V5.3
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"
14#include "gpu_shader_compat.hh"
16
17namespace eevee::lut {
18
27 float scale;
28 float bias;
30
31 float4 pack() const
32 {
33 return float4(scale, bias, metal_bias, 0.0f);
34 }
35
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
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
64 float scale;
65 float bias;
67
68 float4 pack() const
69 {
70 return float4(scale, bias, transmission_factor, 0.0f);
71 }
72
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
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
113
114 float4 pack() const
115 {
116 return float4(transmission_factor, 0.0f, 0.0f, 0.0f);
117 }
118
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
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
ccl_device_inline float cos_theta(const float3 w)
#define UTIL_BRDF_LAYER
#define sqrt
float square(float v)
#define saturate(a)
Definition smaa.cc:319
float4 sample_lut(float2 uv, float layer) const
float4 sample_bsdf_lut(float2 uv, float layer) const
static GGXBrdfData unpack(float4 data)
static float2 lut_coords_get(float cos_theta, float roughness)
static GGXBrdfData sample_utility_tx(const UtilityTexture &util_tx, float cos_theta, float roughness)
static float3 lut_coords_get(float cos_theta, float roughness, float ior)
static GGXBsdfData unpack(float4 data)
static GGXBsdfData sample_utility_tx(const UtilityTexture &util_tx, float cos_theta, float roughness, float ior)
static GGXBtdfGt1Data unpack(float4 data)
static float3 lut_coords_get(float cos_theta, float roughness, float f0)
static GGXBtdfGt1Data sample_utility_tx(const UtilityTexture &util_tx, float cos_theta, float roughness, float f0)
float z
Definition sky_math.h:136
float y
Definition sky_math.h:136
float x
Definition sky_math.h:136