Blender V5.3
eevee_defines.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2021 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
11
12#pragma once
13
14/* Look Up Tables. */
15#define LUT_WORKGROUP_SIZE 16
16
17/* Hierarchical Z down-sampling. */
18[[maybe_unused]] static constexpr int HIZ_MIP_COUNT = 7;
19/* NOTE: The shader is written to update 5 mipmaps using LDS.
20 * Each thread actually update 4 LOD_0 pixels, which means the number of MIPLVL we cover is:
21 * `(log2(HIZ_GROUP_SIZE) + 1) + LOD_0 + LAST_GROUP_LVL = HIZ_MIP_COUNT` */
22[[maybe_unused]] static constexpr int HIZ_GROUP_SIZE = 16;
23
24/* Avoid too much overhead caused by resizing the light buffers too many time. */
25#define LIGHT_CHUNK 256
26
27[[maybe_unused]] static constexpr int CULLING_SELECT_GROUP_SIZE = 256;
28[[maybe_unused]] static constexpr int CULLING_SORT_GROUP_SIZE = 256;
29[[maybe_unused]] static constexpr int CULLING_ZBIN_GROUP_SIZE = 1024;
30[[maybe_unused]] static constexpr int CULLING_TILE_GROUP_SIZE = 256;
31
32/* Reflection Probes. */
33/* When changed update parallel sum loop in `eevee_lightprobe_sphere_remap_comp.glsl`. */
34[[maybe_unused]] static constexpr int SPHERE_PROBE_REMAP_GROUP_SIZE = 32;
35[[maybe_unused]] static constexpr int SPHERE_PROBE_GROUP_SIZE = 16;
36[[maybe_unused]] static constexpr int SPHERE_PROBE_SELECT_GROUP_SIZE = 64;
37[[maybe_unused]] static constexpr int SPHERE_PROBE_MIPMAP_LEVELS = 5;
38[[maybe_unused]] static constexpr int SPHERE_PROBE_SH_GROUP_SIZE = 256;
39[[maybe_unused]] static constexpr int SPHERE_PROBE_SH_SAMPLES_PER_GROUP = 64;
40/* Must be power of two for correct partitioning. */
41[[maybe_unused]] static constexpr int SPHERE_PROBE_ATLAS_MAX_SUBDIV = 12;
42[[maybe_unused]] static constexpr int SPHERE_PROBE_ATLAS_RES = (1
44/* Maximum number of thread-groups dispatched for remapping a probe to octahedral mapping. */
45[[maybe_unused]] static constexpr int SPHERE_PROBE_MAX_HARMONIC =
48/* Start and end value for mixing sphere probe and volume probes. */
49[[maybe_unused]] static constexpr float SPHERE_PROBE_MIX_START_ROUGHNESS = 0.7f;
50[[maybe_unused]] static constexpr float SPHERE_PROBE_MIX_END_ROUGHNESS = 0.9f;
51/* Roughness of the last mip map for sphere probes. */
52[[maybe_unused]] static constexpr float SPHERE_PROBE_MIP_MAX_ROUGHNESS = 0.7f;
53#define SPHERE_PROBE_FORMAT SFLOAT_16_16_16_16
57[[maybe_unused]] static constexpr int SPHERE_PROBE_MAX = 128;
58
60#define VOLUME_PROBE_FORMAT SFLOAT_16_16_16_16
61
67[[maybe_unused]] static constexpr int PLANAR_PROBE_MAX = 16;
68
75#if 0
76/* Useful for debugging the tile-copy version of the shadow rendering without making debugging
77 * tools unresponsive. */
78[[maybe_unused]] static constexpr int SHADOW_TILEMAP_RES = 4;
79[[maybe_unused]] static constexpr int SHADOW_TILEMAP_LOD = 2; /* LOG2(SHADOW_TILEMAP_RES) */
80#else
81[[maybe_unused]] static constexpr int SHADOW_TILEMAP_RES = 32;
82[[maybe_unused]] static constexpr int SHADOW_TILEMAP_LOD = 5; /* LOG2(SHADOW_TILEMAP_RES) */
83#endif
84[[maybe_unused]] static constexpr int SHADOW_TILEMAP_LOD0_LEN = ((SHADOW_TILEMAP_RES / 1) *
85 (SHADOW_TILEMAP_RES / 1));
86[[maybe_unused]] static constexpr int SHADOW_TILEMAP_LOD1_LEN = ((SHADOW_TILEMAP_RES / 2) *
87 (SHADOW_TILEMAP_RES / 2));
88[[maybe_unused]] static constexpr int SHADOW_TILEMAP_LOD2_LEN = ((SHADOW_TILEMAP_RES / 4) *
89 (SHADOW_TILEMAP_RES / 4));
90[[maybe_unused]] static constexpr int SHADOW_TILEMAP_LOD3_LEN = ((SHADOW_TILEMAP_RES / 8) *
91 (SHADOW_TILEMAP_RES / 8));
92[[maybe_unused]] static constexpr int SHADOW_TILEMAP_LOD4_LEN = ((SHADOW_TILEMAP_RES / 16) *
93 (SHADOW_TILEMAP_RES / 16));
94[[maybe_unused]] static constexpr int SHADOW_TILEMAP_LOD5_LEN = ((SHADOW_TILEMAP_RES / 32) *
95 (SHADOW_TILEMAP_RES / 32));
96[[maybe_unused]] static constexpr int SHADOW_TILEMAP_PER_ROW = 64;
97[[maybe_unused]] static constexpr int SHADOW_TILEDATA_PER_TILEMAP =
100/* Maximum number of relative LOD distance we can store. */
101[[maybe_unused]] static constexpr int SHADOW_TILEMAP_MAX_CLIPMAP_LOD = 8;
102#if 0
103/* Useful for debugging the tile-copy version of the shadow rendering without making debugging
104 * tools unresponsive. */
105[[maybe_unused]] static constexpr int SHADOW_PAGE_CLEAR_GROUP_SIZE= 8;
106[[maybe_unused]] static constexpr int SHADOW_PAGE_RES= 8;
107[[maybe_unused]] static constexpr int SHADOW_PAGE_LOD= 3; /* LOG2(SHADOW_PAGE_RES) */
108#else
109[[maybe_unused]] static constexpr int SHADOW_PAGE_CLEAR_GROUP_SIZE = 32;
110[[maybe_unused]] static constexpr int SHADOW_PAGE_RES = 256;
111[[maybe_unused]] static constexpr int SHADOW_PAGE_LOD = 8; /* LOG2(SHADOW_PAGE_RES) */
112#endif
113/* For testing only. */
114// #define SHADOW_FORCE_LOD0
115[[maybe_unused]] static constexpr int SHADOW_MAP_MAX_RES = (SHADOW_PAGE_RES * SHADOW_TILEMAP_RES);
116[[maybe_unused]] static constexpr int SHADOW_DEPTH_SCAN_GROUP_SIZE = 8;
117[[maybe_unused]] static constexpr int SHADOW_AABB_TAG_GROUP_SIZE = 64;
118[[maybe_unused]] static constexpr int SHADOW_MAX_TILEMAP = 4096;
119[[maybe_unused]] static constexpr int SHADOW_MAX_TILE = (SHADOW_MAX_TILEMAP *
121[[maybe_unused]] static constexpr int SHADOW_MAX_PAGE = 8192;
122[[maybe_unused]] static constexpr int SHADOW_BOUNDS_GROUP_SIZE = 64;
123[[maybe_unused]] static constexpr int SHADOW_CLIPMAP_GROUP_SIZE = 64;
124[[maybe_unused]] static constexpr int SHADOW_VIEW_MAX = 64 /* Must match DRW_VIEW_MAX. */;
125[[maybe_unused]] static constexpr int SHADOW_RENDER_MAP_SIZE = (SHADOW_VIEW_MAX *
127[[maybe_unused]] static constexpr int SHADOW_ATOMIC = 1;
128[[maybe_unused]] static constexpr int SHADOW_PAGE_PER_ROW = 8;
129[[maybe_unused]] static constexpr int SHADOW_PAGE_PER_COL = 8;
130[[maybe_unused]] static constexpr int SHADOW_PAGE_MAX_LAYER = 128;
131[[maybe_unused]] static constexpr int SHADOW_PAGE_PER_LAYER = (SHADOW_PAGE_PER_ROW *
133[[maybe_unused]] static constexpr int SHADOW_MAX_STEP = 16;
134[[maybe_unused]] static constexpr int SHADOW_MAX_RAY = 4;
135[[maybe_unused]] static constexpr int SHADOW_ROG_ID = 0;
136
137/* Gbuffer. */
139#define GBUF_HEADER_FB_LAYER_COUNT 1
140#define GBUF_CLOSURE_FB_LAYER_COUNT 2
141#define GBUF_NORMAL_FB_LAYER_COUNT 1
142
143/* Deferred Lighting. */
144#define DEFERRED_RADIANCE_FORMAT UINT_32
145#define DEFERRED_GBUFFER_ROG_ID 0
146
147/* Ray-tracing. */
148[[maybe_unused]] static constexpr int RAYTRACE_GROUP_SIZE = 8;
149/* Keep this as a define to avoid shader variations. */
150#define RAYTRACE_RADIANCE_FORMAT UFLOAT_11_11_10
151#define RAYTRACE_RAYTIME_FORMAT SFLOAT_32
152#define RAYTRACE_VARIANCE_FORMAT SFLOAT_16
153#define RAYTRACE_TILEMASK_FORMAT UINT_8
154
155/* Sub-Surface Scattering. */
156[[maybe_unused]] static constexpr int SUBSURFACE_GROUP_SIZE = RAYTRACE_GROUP_SIZE;
157#define SUBSURFACE_RADIANCE_FORMAT UFLOAT_11_11_10
158#define SUBSURFACE_OBJECT_ID_FORMAT UINT_16
159
160/* Film. */
161#define FILM_GROUP_SIZE 16
162
163/* Motion Blur. */
164#define MOTION_BLUR_GROUP_SIZE 32
165#define MOTION_BLUR_DILATE_GROUP_SIZE 512
166
167/* Irradiance Cache. */
169[[maybe_unused]] static constexpr int IRRADIANCE_GRID_MAX = 64;
170
171/* Depth Of Field. */
172[[maybe_unused]] static constexpr int DOF_TILES_SIZE = 8;
173[[maybe_unused]] static constexpr int DOF_TILES_FLATTEN_GROUP_SIZE = DOF_TILES_SIZE;
174[[maybe_unused]] static constexpr int DOF_TILES_DILATE_GROUP_SIZE = 8;
175[[maybe_unused]] static constexpr int DOF_BOKEH_LUT_SIZE = 32;
176[[maybe_unused]] static constexpr int DOF_MAX_SLIGHT_FOCUS_RADIUS = 5;
177[[maybe_unused]] static constexpr int DOF_SLIGHT_FOCUS_SAMPLE_MAX = 16;
178[[maybe_unused]] static constexpr int DOF_MIP_COUNT = 4;
179[[maybe_unused]] static constexpr int DOF_REDUCE_GROUP_SIZE = (1 << (DOF_MIP_COUNT - 1));
180[[maybe_unused]] static constexpr int DOF_DEFAULT_GROUP_SIZE = 32;
181[[maybe_unused]] static constexpr int DOF_STABILIZE_GROUP_SIZE = 16;
182[[maybe_unused]] static constexpr int DOF_FILTER_GROUP_SIZE = 8;
183[[maybe_unused]] static constexpr int DOF_GATHER_GROUP_SIZE = DOF_TILES_SIZE;
184[[maybe_unused]] static constexpr int DOF_RESOLVE_GROUP_SIZE = (DOF_TILES_SIZE * 2);
185
186/* Ambient Occlusion. */
187#define AMBIENT_OCCLUSION_PASS_TILE_SIZE 16
188
189/* IrradianceBake. */
190#define SURFEL_GROUP_SIZE 256
191#define SURFEL_LIST_GROUP_SIZE 256
192#define IRRADIANCE_GRID_GROUP_SIZE 4 /* In each dimension, so 4x4x4 workgroup size. */
193#define IRRADIANCE_GRID_BRICK_SIZE 4 /* In each dimension, so 4x4x4 brick size. */
194#define IRRADIANCE_BOUNDS_GROUP_SIZE 64
195
196/* Volumes. */
197#define VOLUME_GROUP_SIZE 4
198#define VOLUME_INTEGRATION_GROUP_SIZE 8
199[[maybe_unused]] static constexpr int VOLUME_HIT_DEPTH_MAX = 16;
200
201/* Velocity. */
202#define VERTEX_COPY_GROUP_SIZE 64
203
204/* Utility Texture. */
205#define UTIL_TEX_SIZE 64
206#define UTIL_BSDF_LAYER_COUNT 16
207/* Scale and bias to avoid interpolation of the border pixel.
208 * Remap UVs to the border pixels centers. */
209#define UTIL_TEX_UV_SCALE ((UTIL_TEX_SIZE - 1.0f) / UTIL_TEX_SIZE)
210#define UTIL_TEX_UV_BIAS (0.5f / UTIL_TEX_SIZE)
211
212#define UTIL_BLUE_NOISE_LAYER 0
213#define UTIL_SSS_TRANSMITTANCE_PROFILE_LAYER 1
214#define UTIL_LTC_MAT_LAYER 2
215#define UTIL_BRDF_LAYER 3
216#define UTIL_BSDF_LAYER 4
217#define UTIL_DISK_INTEGRAL_LAYER UTIL_SSS_TRANSMITTANCE_PROFILE_LAYER
218#define UTIL_DISK_INTEGRAL_COMP 3
219
220#define PREPASS_FRAG_OUT_NORMAL 0
221#define PREPASS_FRAG_OUT_OB_ID 1
222#define PREPASS_FRAG_OUT_VELOCITY 2
223
224/* Resource bindings. */
225
226/* Textures. */
228/* Used anywhere. (Starts at index 2, since 0 and 1 are used by draw_gpencil) */
229#define RBUFS_UTILITY_TEX_SLOT 2
230#define HIZ_TEX_SLOT 3
231/* Only during surface shading (forward and deferred eval). */
232#define SHADOW_TILEMAPS_TEX_SLOT 4
233#define SHADOW_ATLAS_TEX_SLOT 5
234#define VOLUME_PROBE_TEX_SLOT 6
235#define SPHERE_PROBE_TEX_SLOT 7
236#define VOLUME_SCATTERING_TEX_SLOT 8
237#define VOLUME_TRANSMITTANCE_TEX_SLOT 9
238#define HIZ_PREVIOUS_LAYER_TEX_SLOT 10
239#define RADIANCE_PREVIOUS_LAYER_TEX_SLOT 11
240#define RAYCAST_DEPTH_TEX_SLOT 12
241#define OBJECT_ID_TEX_SLOT 13
242#define PREPASS_NORMAL_TEX_SLOT 14
243/* Currently only used by ray-tracing, but might become used by forward too. */
244#define PLANAR_PROBE_DEPTH_TEX_SLOT 15
245#define PLANAR_PROBE_RADIANCE_TEX_SLOT 16
246
247#define GBUF_CLOSURE_TEX_SLOT 17
248#define GBUF_NORMAL_TEX_SLOT 18
249#define GBUF_HEADER_TEX_SLOT 19
250
251/* Images. */
252#define RBUFS_COLOR_SLOT 0
253#define RBUFS_VALUE_SLOT 1
254#define RBUFS_CRYPTOMATTE_SLOT 2
255#define GBUF_CLOSURE_SLOT 3
256#define GBUF_NORMAL_SLOT 4
257#define GBUF_HEADER_SLOT 5
258/* Volume properties pass do not write to `rbufs`. Reuse the same bind points. */
259#define VOLUME_PROP_SCATTERING_IMG_SLOT 0
260#define VOLUME_PROP_EXTINCTION_IMG_SLOT 1
261#define VOLUME_PROP_EMISSION_IMG_SLOT 2
262#define VOLUME_PROP_PHASE_IMG_SLOT 3
263#define VOLUME_PROP_PHASE_WEIGHT_IMG_SLOT 4
264#define VOLUME_OCCUPANCY_SLOT 5
265/* Only during volume pre-pass. */
266#define VOLUME_HIT_DEPTH_SLOT 0
267#define VOLUME_HIT_COUNT_SLOT 1
268/* Only during shadow rendering. */
269#define SHADOW_ATLAS_IMG_SLOT 4
270
271/* Uniform Buffers. */
272/* Slot 0 is GPU_NODE_TREE_UBO_SLOT. */
273#define UNIFORM_BUF_SLOT 1
274/* Split from the main uniform buffer since they're updated multiple times per frame. */
275#define PIPELINE_BUF_SLOT 2
276#define RAYTRACE_BUF_SLOT 3
277/* Only during surface shading (forward and deferred eval). */
278#define IRRADIANCE_GRID_BUF_SLOT 4
279#define SPHERE_PROBE_BUF_SLOT 5
280#define PLANAR_PROBE_BUF_SLOT 6
281/* Only during pre-pass. */
282#define VELOCITY_CAMERA_PREV_BUF 4
283#define VELOCITY_CAMERA_CURR_BUF 5
284#define VELOCITY_CAMERA_NEXT_BUF 6
285/* Overlap with Draw module reserved slot for volume.
286 * But this is used only for the prepass which doesn't bind volume data. */
287#define CLIP_PLANE_BUF 7
288/* Only during subsurface scattering */
289#define SUBSURFACE_BUF_SLOT 4
290
291/* Storage Buffers. */
292#define LIGHT_CULL_BUF_SLOT 0
293#define LIGHT_BUF_SLOT 1
294#define LIGHT_ZBIN_BUF_SLOT 2
295#define LIGHT_TILE_BUF_SLOT 3
296#define IRRADIANCE_BRICK_BUF_SLOT 4
297#define SAMPLING_BUF_SLOT 6
298#define CRYPTOMATTE_BUF_SLOT 7
299/* Only during surface capture. */
300#define SURFEL_BUF_SLOT 4
301/* Only during surface capture. */
302#define CAPTURE_BUF_SLOT 5
303/* Only during shadow rendering. */
304#define SHADOW_RENDER_MAP_BUF_SLOT 3
305#define SHADOW_PAGE_INFO_SLOT 4
306#define SHADOW_RENDER_VIEW_BUF_SLOT 5
307
308/* Only during pre-pass. */
309#define VELOCITY_OBJ_PREV_BUF_SLOT 0
310#define VELOCITY_OBJ_NEXT_BUF_SLOT 1
311#define VELOCITY_GEO_PREV_BUF_SLOT 2
312#define VELOCITY_GEO_NEXT_BUF_SLOT 3
313#define VELOCITY_INDIRECTION_BUF_SLOT 4
314
315#define CLOSURE_WEIGHT_CUTOFF 1e-5f
316/* Treat closure as singular if the roughness is below this threshold. */
317#define BSDF_ROUGHNESS_THRESHOLD 2e-2f
318
319/* Cannot use math libraries in shared headers yet. */
320#define EEVEE_PI 3.14159265358979323846f /* pi */
static constexpr int SHADOW_TILEMAP_LOD5_LEN
static constexpr int SHADOW_DEPTH_SCAN_GROUP_SIZE
static constexpr int SPHERE_PROBE_SH_GROUP_SIZE
static constexpr int SHADOW_PAGE_PER_LAYER
static constexpr int SHADOW_PAGE_CLEAR_GROUP_SIZE
static constexpr int SHADOW_MAX_PAGE
static constexpr int VOLUME_HIT_DEPTH_MAX
static constexpr int SHADOW_AABB_TAG_GROUP_SIZE
static constexpr int DOF_TILES_SIZE
static constexpr int SPHERE_PROBE_REMAP_GROUP_SIZE
static constexpr int SHADOW_MAX_STEP
static constexpr int SHADOW_TILEMAP_LOD3_LEN
static constexpr int SHADOW_TILEMAP_PER_ROW
static constexpr int CULLING_ZBIN_GROUP_SIZE
static constexpr float SPHERE_PROBE_MIX_END_ROUGHNESS
static constexpr int CULLING_TILE_GROUP_SIZE
static constexpr int DOF_DEFAULT_GROUP_SIZE
static constexpr int SHADOW_ATOMIC
static constexpr int DOF_RESOLVE_GROUP_SIZE
static constexpr int IRRADIANCE_GRID_MAX
static constexpr int PLANAR_PROBE_MAX
static constexpr int SHADOW_TILEMAP_LOD2_LEN
static constexpr int SHADOW_TILEMAP_LOD0_LEN
static constexpr int DOF_SLIGHT_FOCUS_SAMPLE_MAX
static constexpr int SHADOW_MAX_TILE
static constexpr int DOF_STABILIZE_GROUP_SIZE
static constexpr int SUBSURFACE_GROUP_SIZE
static constexpr int DOF_TILES_DILATE_GROUP_SIZE
static constexpr int SHADOW_TILEMAP_MAX_CLIPMAP_LOD
static constexpr int SHADOW_VIEW_MAX
static constexpr int SPHERE_PROBE_ATLAS_RES
static constexpr int SPHERE_PROBE_MIPMAP_LEVELS
static constexpr int SHADOW_TILEMAP_RES
static constexpr int SHADOW_TILEMAP_LOD
static constexpr int SPHERE_PROBE_GROUP_SIZE
static constexpr int DOF_GATHER_GROUP_SIZE
static constexpr float SPHERE_PROBE_MIP_MAX_ROUGHNESS
static constexpr int SHADOW_PAGE_MAX_LAYER
static constexpr int SHADOW_PAGE_PER_ROW
static constexpr int SHADOW_MAP_MAX_RES
static constexpr int RAYTRACE_GROUP_SIZE
static constexpr int CULLING_SORT_GROUP_SIZE
static constexpr int HIZ_MIP_COUNT
static constexpr float SPHERE_PROBE_MIX_START_ROUGHNESS
static constexpr int SHADOW_TILEMAP_LOD4_LEN
static constexpr int SPHERE_PROBE_MAX
static constexpr int CULLING_SELECT_GROUP_SIZE
static constexpr int SHADOW_MAX_TILEMAP
static constexpr int SHADOW_TILEMAP_LOD1_LEN
static constexpr int SHADOW_PAGE_LOD
static constexpr int SHADOW_RENDER_MAP_SIZE
static constexpr int SPHERE_PROBE_MAX_HARMONIC
static constexpr int SHADOW_CLIPMAP_GROUP_SIZE
static constexpr int DOF_MAX_SLIGHT_FOCUS_RADIUS
static constexpr int DOF_TILES_FLATTEN_GROUP_SIZE
static constexpr int SPHERE_PROBE_SELECT_GROUP_SIZE
static constexpr int SHADOW_BOUNDS_GROUP_SIZE
static constexpr int SPHERE_PROBE_ATLAS_MAX_SUBDIV
static constexpr int SHADOW_PAGE_PER_COL
static constexpr int HIZ_GROUP_SIZE
static constexpr int SHADOW_TILEDATA_PER_TILEMAP
static constexpr int DOF_FILTER_GROUP_SIZE
static constexpr int DOF_BOKEH_LUT_SIZE
static constexpr int DOF_MIP_COUNT
static constexpr int SHADOW_ROG_ID
static constexpr int DOF_REDUCE_GROUP_SIZE
static constexpr int SHADOW_PAGE_RES
static constexpr int SPHERE_PROBE_SH_SAMPLES_PER_GROUP
static constexpr int SHADOW_MAX_RAY