Blender V4.5
eevee_material_info.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#ifdef GPU_SHADER
6# pragma once
8
9# include "gpu_glsl_cpp_stubs.hh"
10
12# include "draw_view_info.hh"
13# include "eevee_shader_shared.hh"
14
15# include "eevee_common_info.hh"
16# include "eevee_volume_info.hh"
17
18# define HAIR_SHADER
19# define DRW_HAIR_INFO
20
21# define POINTCLOUD_SHADER
22# define DRW_POINTCLOUD_INFO
23
24# define SHADOW_UPDATE_ATOMIC_RASTER
25# define MAT_TRANSPARENT
26
27# define thickness_mode 1.0f
28#endif
29
30#include "eevee_defines.hh"
32
33/* -------------------------------------------------------------------- */
36
37/* Common interface */
39/* World Position. */
41/* World Normal. */
44
45GPU_SHADER_CREATE_INFO(eevee_geom_mesh)
46ADDITIONAL_INFO(eevee_shared)
47DEFINE("MAT_GEOM_MESH")
50VERTEX_SOURCE("eevee_geom_mesh_vert.glsl")
51VERTEX_OUT(eevee_surf_iface)
52ADDITIONAL_INFO(draw_modelmat)
53ADDITIONAL_INFO(draw_object_infos)
54ADDITIONAL_INFO(draw_resource_id_varying)
55ADDITIONAL_INFO(draw_view)
57
58GPU_SHADER_NAMED_INTERFACE_INFO(eevee_surf_pointcloud_iface, pointcloud_interp)
59SMOOTH(float, radius)
60SMOOTH(float3, position)
61GPU_SHADER_NAMED_INTERFACE_END(pointcloud_interp)
62GPU_SHADER_NAMED_INTERFACE_INFO(eevee_surf_pointcloud_flat_iface, pointcloud_interp_flat)
63FLAT(int, id)
64GPU_SHADER_NAMED_INTERFACE_END(pointcloud_interp_flat)
65
66GPU_SHADER_CREATE_INFO(eevee_geom_pointcloud)
67ADDITIONAL_INFO(eevee_shared)
68DEFINE("MAT_GEOM_POINTCLOUD")
69VERTEX_SOURCE("eevee_geom_pointcloud_vert.glsl")
70VERTEX_OUT(eevee_surf_iface)
71VERTEX_OUT(eevee_surf_pointcloud_iface)
72VERTEX_OUT(eevee_surf_pointcloud_flat_iface)
73ADDITIONAL_INFO(draw_pointcloud)
74ADDITIONAL_INFO(draw_modelmat)
75ADDITIONAL_INFO(draw_object_infos)
76ADDITIONAL_INFO(draw_resource_id_varying)
77ADDITIONAL_INFO(draw_view)
79
80GPU_SHADER_CREATE_INFO(eevee_geom_volume)
81ADDITIONAL_INFO(eevee_shared)
82DEFINE("MAT_GEOM_VOLUME")
84VERTEX_OUT(eevee_surf_iface)
85VERTEX_SOURCE("eevee_geom_volume_vert.glsl")
86ADDITIONAL_INFO(draw_modelmat)
87ADDITIONAL_INFO(draw_object_infos)
88ADDITIONAL_INFO(draw_resource_id_varying)
89ADDITIONAL_INFO(draw_volume_infos)
90ADDITIONAL_INFO(draw_view)
92
93GPU_SHADER_CREATE_INFO(eevee_geom_gpencil)
94ADDITIONAL_INFO(eevee_shared)
95DEFINE("MAT_GEOM_GPENCIL")
96VERTEX_SOURCE("eevee_geom_gpencil_vert.glsl")
97VERTEX_OUT(eevee_surf_iface)
98ADDITIONAL_INFO(draw_gpencil)
99ADDITIONAL_INFO(draw_modelmat)
100ADDITIONAL_INFO(draw_object_infos)
101ADDITIONAL_INFO(draw_resource_id_varying)
102ADDITIONAL_INFO(draw_resource_id)
104
105GPU_SHADER_NAMED_INTERFACE_INFO(eevee_surf_curve_iface, curve_interp)
106SMOOTH(float2, barycentric_coords)
107SMOOTH(float3, tangent)
108SMOOTH(float3, binormal)
109SMOOTH(float, time)
110SMOOTH(float, time_width)
111SMOOTH(float, thickness)
113GPU_SHADER_NAMED_INTERFACE_INFO(eevee_surf_curve_flat_iface, curve_interp_flat)
114FLAT(int, strand_id)
115GPU_SHADER_NAMED_INTERFACE_END(curve_interp_flat)
116
117GPU_SHADER_CREATE_INFO(eevee_geom_curves)
118ADDITIONAL_INFO(eevee_shared)
119DEFINE("MAT_GEOM_CURVES")
120VERTEX_SOURCE("eevee_geom_curves_vert.glsl")
121VERTEX_OUT(eevee_surf_iface)
122VERTEX_OUT(eevee_surf_curve_iface)
123VERTEX_OUT(eevee_surf_curve_flat_iface)
124ADDITIONAL_INFO(draw_modelmat)
125ADDITIONAL_INFO(draw_object_infos)
126ADDITIONAL_INFO(draw_resource_id_varying)
127ADDITIONAL_INFO(draw_view)
128ADDITIONAL_INFO(draw_hair)
129ADDITIONAL_INFO(draw_curves_infos)
131
132GPU_SHADER_CREATE_INFO(eevee_geom_world)
133ADDITIONAL_INFO(eevee_shared)
134DEFINE("MAT_GEOM_WORLD")
135BUILTINS(BuiltinBits::VERTEX_ID)
136VERTEX_SOURCE("eevee_geom_world_vert.glsl")
137VERTEX_OUT(eevee_surf_iface)
138ADDITIONAL_INFO(draw_modelmat)
139ADDITIONAL_INFO(draw_object_infos) /* Unused, but allow debug compilation. */
140ADDITIONAL_INFO(draw_resource_id_varying)
141ADDITIONAL_INFO(draw_view)
143
145
146/* -------------------------------------------------------------------- */
149
150#define image_out(slot, qualifier, format, name) \
151 image(slot, format, qualifier, ImageType::Float2D, name, Frequency::PASS)
152#define image_array_out(slot, qualifier, format, name) \
153 image(slot, format, qualifier, ImageType::Float2DArray, name, Frequency::PASS)
154
155GPU_SHADER_CREATE_INFO(eevee_surf_deferred_base)
156DEFINE("MAT_DEFERRED")
157DEFINE("GBUFFER_WRITE")
158/* NOTE: This removes the possibility of using gl_FragDepth. */
160/* Direct output. (Emissive, Holdout) */
161FRAGMENT_OUT(0, float4, out_radiance)
163FRAGMENT_OUT(2, float2, out_gbuf_normal)
164FRAGMENT_OUT(3, float4, out_gbuf_closure1)
165FRAGMENT_OUT(4, float4, out_gbuf_closure2)
166/* Everything is stored inside a two layered target, one for each format. This is to fit the
167 * limitation of the number of images we can bind on a single shader. */
168IMAGE_FREQ(GBUF_CLOSURE_SLOT, GPU_RGB10_A2, write, image2DArray, out_gbuf_closure_img, PASS)
169IMAGE_FREQ(GBUF_NORMAL_SLOT, GPU_RG16, write, image2DArray, out_gbuf_normal_img, PASS)
170/* Storage for additional infos that are shared across closures. */
171IMAGE_FREQ(GBUF_HEADER_SLOT, GPU_R32UI, write, uimage2DArray, out_gbuf_header_img, PASS)
172/* Added at runtime because of test shaders not having `node_tree`. */
173// ADDITIONAL_INFO(eevee_render_pass_out)
174// ADDITIONAL_INFO(eevee_cryptomatte_out)
175ADDITIONAL_INFO(eevee_global_ubo)
176ADDITIONAL_INFO(eevee_utility_texture)
177ADDITIONAL_INFO(eevee_sampling_data)
178ADDITIONAL_INFO(eevee_hiz_data)
180
181GPU_SHADER_CREATE_INFO(eevee_surf_deferred)
182FRAGMENT_SOURCE("eevee_surf_deferred_frag.glsl")
183ADDITIONAL_INFO(eevee_surf_deferred_base)
185
186GPU_SHADER_CREATE_INFO(eevee_surf_deferred_hybrid)
187FRAGMENT_SOURCE("eevee_surf_hybrid_frag.glsl")
188ADDITIONAL_INFO(eevee_surf_deferred_base)
189ADDITIONAL_INFO(eevee_light_data)
190ADDITIONAL_INFO(eevee_lightprobe_data)
191ADDITIONAL_INFO(eevee_shadow_data)
193
194GPU_SHADER_CREATE_INFO(eevee_surf_forward)
195DEFINE("MAT_FORWARD")
196/* Early fragment test is needed for render passes support for forward surfaces. */
197/* NOTE: This removes the possibility of using gl_FragDepth. */
199FRAGMENT_OUT_DUAL(0, float4, out_radiance, SRC_0)
200FRAGMENT_OUT_DUAL(0, float4, out_transmittance, SRC_1)
201FRAGMENT_SOURCE("eevee_surf_forward_frag.glsl")
202/* Optionally added depending on the material. */
203// ADDITIONAL_INFO(eevee_render_pass_out)
204// ADDITIONAL_INFO(eevee_cryptomatte_out)
205ADDITIONAL_INFO(eevee_global_ubo)
206ADDITIONAL_INFO(eevee_light_data)
207ADDITIONAL_INFO(eevee_lightprobe_data)
208ADDITIONAL_INFO(eevee_utility_texture)
209ADDITIONAL_INFO(eevee_sampling_data)
210ADDITIONAL_INFO(eevee_shadow_data)
211ADDITIONAL_INFO(eevee_hiz_data)
212ADDITIONAL_INFO(eevee_volume_lib)
214
215GPU_SHADER_CREATE_INFO(eevee_surf_capture)
216DEFINE("MAT_CAPTURE")
217STORAGE_BUF(SURFEL_BUF_SLOT, write, Surfel, surfel_buf[])
218STORAGE_BUF(CAPTURE_BUF_SLOT, read_write, CaptureInfoData, capture_info_buf)
219PUSH_CONSTANT(bool, is_double_sided)
220FRAGMENT_SOURCE("eevee_surf_capture_frag.glsl")
221ADDITIONAL_INFO(eevee_global_ubo)
222ADDITIONAL_INFO(eevee_utility_texture)
224
225GPU_SHADER_CREATE_INFO(eevee_surf_depth)
226DEFINE("MAT_DEPTH")
227FRAGMENT_SOURCE("eevee_surf_depth_frag.glsl")
228ADDITIONAL_INFO(eevee_global_ubo)
229ADDITIONAL_INFO(eevee_sampling_data)
230ADDITIONAL_INFO(eevee_utility_texture)
232
233GPU_SHADER_CREATE_INFO(eevee_surf_world)
234PUSH_CONSTANT(float, world_opacity_fade)
235PUSH_CONSTANT(float, world_background_blur)
236PUSH_CONSTANT(int4, world_coord_packed)
238FRAGMENT_OUT(0, float4, out_background)
239FRAGMENT_SOURCE("eevee_surf_world_frag.glsl")
240ADDITIONAL_INFO(eevee_global_ubo)
241ADDITIONAL_INFO(eevee_lightprobe_sphere_data)
242ADDITIONAL_INFO(eevee_volume_probe_data)
243ADDITIONAL_INFO(eevee_sampling_data)
244/* Optionally added depending on the material. */
245// ADDITIONAL_INFO(eevee_render_pass_out)
246// ADDITIONAL_INFO(eevee_cryptomatte_out)
247ADDITIONAL_INFO(eevee_utility_texture)
249
250GPU_SHADER_CREATE_INFO(eevee_renderpass_clear)
251FRAGMENT_OUT(0, float4, out_background)
252FRAGMENT_SOURCE("eevee_renderpass_clear_frag.glsl")
253ADDITIONAL_INFO(gpu_fullscreen)
254ADDITIONAL_INFO(eevee_global_ubo)
255ADDITIONAL_INFO(eevee_render_pass_out)
256ADDITIONAL_INFO(eevee_cryptomatte_out)
257ADDITIONAL_INFO(eevee_shared)
260
261GPU_SHADER_NAMED_INTERFACE_INFO(eevee_surf_shadow_atomic_iface, shadow_iface)
262FLAT(int, shadow_view_id)
264
265GPU_SHADER_NAMED_INTERFACE_INFO(eevee_surf_shadow_clipping_iface, shadow_clip)
266SMOOTH(float3, position)
269
270GPU_SHADER_CREATE_INFO(eevee_surf_shadow)
271DEFINE_VALUE("DRW_VIEW_LEN", STRINGIFY(SHADOW_VIEW_MAX))
272DEFINE("MAT_SHADOW")
273BUILTINS(BuiltinBits::VIEWPORT_INDEX)
274VERTEX_OUT(eevee_surf_shadow_clipping_iface)
275STORAGE_BUF(SHADOW_RENDER_VIEW_BUF_SLOT, read, ShadowRenderView, render_view_buf[SHADOW_VIEW_MAX])
276FRAGMENT_SOURCE("eevee_surf_shadow_frag.glsl")
277ADDITIONAL_INFO(eevee_global_ubo)
278ADDITIONAL_INFO(eevee_utility_texture)
279ADDITIONAL_INFO(eevee_sampling_data)
281
282GPU_SHADER_CREATE_INFO(eevee_surf_shadow_atomic)
283ADDITIONAL_INFO(eevee_surf_shadow)
284DEFINE("SHADOW_UPDATE_ATOMIC_RASTER")
285BUILTINS(BuiltinBits::TEXTURE_ATOMIC)
286VERTEX_OUT(eevee_surf_shadow_atomic_iface)
288IMAGE(SHADOW_ATLAS_IMG_SLOT, GPU_R32UI, read_write, uimage2DArrayAtomic, shadow_atlas_img)
290
291GPU_SHADER_CREATE_INFO(eevee_surf_shadow_tbdr)
292ADDITIONAL_INFO(eevee_surf_shadow)
293DEFINE("SHADOW_UPDATE_TBDR")
294BUILTINS(BuiltinBits::LAYER)
295/* Use greater depth write to avoid loosing the early Z depth test but ensure correct fragment
296 * ordering after slope bias. */
297DEPTH_WRITE(DepthWrite::GREATER)
298/* F32 color attachment for on-tile depth accumulation without atomics. */
299FRAGMENT_OUT_ROG(0, float, out_depth, SHADOW_ROG_ID)
301
302#undef image_out
303#undef image_array_out
304
306
307/* -------------------------------------------------------------------- */
310
311GPU_SHADER_CREATE_INFO(eevee_surf_volume)
312DEFINE("MAT_VOLUME")
313/* Only the front fragments have to be invoked. */
315IMAGE(VOLUME_PROP_SCATTERING_IMG_SLOT, GPU_R11F_G11F_B10F, read_write, image3D, out_scattering_img)
316IMAGE(VOLUME_PROP_EXTINCTION_IMG_SLOT, GPU_R11F_G11F_B10F, read_write, image3D, out_extinction_img)
317IMAGE(VOLUME_PROP_EMISSION_IMG_SLOT, GPU_R11F_G11F_B10F, read_write, image3D, out_emissive_img)
318IMAGE(VOLUME_PROP_PHASE_IMG_SLOT, GPU_R16F, read_write, image3D, out_phase_img)
319IMAGE(VOLUME_PROP_PHASE_WEIGHT_IMG_SLOT, GPU_R16F, read_write, image3D, out_phase_weight_img)
321FRAGMENT_SOURCE("eevee_surf_volume_frag.glsl")
322ADDITIONAL_INFO(draw_modelmat_common)
323ADDITIONAL_INFO(draw_view)
324ADDITIONAL_INFO(eevee_shared)
325ADDITIONAL_INFO(eevee_global_ubo)
326ADDITIONAL_INFO(eevee_sampling_data)
327ADDITIONAL_INFO(eevee_utility_texture)
329
330GPU_SHADER_CREATE_INFO(eevee_surf_occupancy)
331DEFINE("MAT_OCCUPANCY")
332/* All fragments need to be invoked even if we write to the depth buffer. */
334BUILTINS(BuiltinBits::TEXTURE_ATOMIC)
335PUSH_CONSTANT(bool, use_fast_method)
336IMAGE(VOLUME_HIT_DEPTH_SLOT, GPU_R32F, write, image3D, hit_depth_img)
337IMAGE(VOLUME_HIT_COUNT_SLOT, GPU_R32UI, read_write, uimage2DAtomic, hit_count_img)
338IMAGE(VOLUME_OCCUPANCY_SLOT, GPU_R32UI, read_write, uimage3DAtomic, occupancy_img)
339FRAGMENT_SOURCE("eevee_surf_occupancy_frag.glsl")
340ADDITIONAL_INFO(eevee_global_ubo)
341ADDITIONAL_INFO(eevee_sampling_data)
343
345
346/* -------------------------------------------------------------------- */
351
352#ifndef NDEBUG
353
354/* Stub functions defined by the material evaluation. */
355GPU_SHADER_CREATE_INFO(eevee_material_stub)
356DEFINE("EEVEE_MATERIAL_STUBS")
357/* Dummy uniform buffer to detect overlap with material node-tree. */
358UNIFORM_BUF(0, int, node_tree)
360
361# define EEVEE_MAT_GEOM_VARIATIONS(prefix, ...) \
362 CREATE_INFO_VARIANT(prefix##_world, eevee_geom_world, __VA_ARGS__) \
363 /* Turned off until dependency on common_view/math_lib are sorted out. */ \
364 /* CREATE_INFO_VARIANT(prefix##_gpencil, eevee_geom_gpencil, __VA_ARGS__) */ \
365 CREATE_INFO_VARIANT(prefix##_curves, eevee_geom_curves, __VA_ARGS__) \
366 CREATE_INFO_VARIANT(prefix##_mesh, eevee_geom_mesh, __VA_ARGS__) \
367 CREATE_INFO_VARIANT(prefix##_pointcloud, eevee_geom_pointcloud, __VA_ARGS__) \
368 CREATE_INFO_VARIANT(prefix##_volume, eevee_geom_volume, __VA_ARGS__)
369
370# define EEVEE_MAT_PIPE_VARIATIONS(name, ...) \
371 EEVEE_MAT_GEOM_VARIATIONS(name##_world, eevee_surf_world, __VA_ARGS__) \
372 EEVEE_MAT_GEOM_VARIATIONS(name##_depth, eevee_surf_depth, __VA_ARGS__) \
373 EEVEE_MAT_GEOM_VARIATIONS(name##_deferred, eevee_surf_deferred, __VA_ARGS__) \
374 EEVEE_MAT_GEOM_VARIATIONS(name##_forward, eevee_surf_forward, __VA_ARGS__) \
375 EEVEE_MAT_GEOM_VARIATIONS(name##_capture, eevee_surf_capture, __VA_ARGS__) \
376 EEVEE_MAT_GEOM_VARIATIONS(name##_volume, eevee_surf_volume, __VA_ARGS__) \
377 EEVEE_MAT_GEOM_VARIATIONS(name##_occupancy, eevee_surf_occupancy, __VA_ARGS__) \
378 EEVEE_MAT_GEOM_VARIATIONS(name##_shadow_atomic, eevee_surf_shadow_atomic, __VA_ARGS__) \
379 EEVEE_MAT_GEOM_VARIATIONS(name##_shadow_tbdr, eevee_surf_shadow_tbdr, __VA_ARGS__)
380
381EEVEE_MAT_PIPE_VARIATIONS(eevee_surface, eevee_material_stub)
382
383#endif
384
unsigned int uint
#define STRINGIFY(x)
@ GPU_R32F
@ GPU_RGB10_A2
@ GPU_R16F
@ GPU_RG16
@ GPU_R32UI
@ GPU_R11F_G11F_B10F
return true
#define VOLUME_PROP_SCATTERING_IMG_SLOT
#define DEFERRED_GBUFFER_ROG_ID
#define SHADOW_VIEW_MAX
#define VOLUME_HIT_DEPTH_SLOT
#define CAPTURE_BUF_SLOT
#define VOLUME_PROP_PHASE_WEIGHT_IMG_SLOT
#define VOLUME_HIT_COUNT_SLOT
#define VOLUME_OCCUPANCY_SLOT
#define GBUF_CLOSURE_SLOT
#define SHADOW_ATLAS_IMG_SLOT
#define SHADOW_RENDER_MAP_BUF_SLOT
#define GBUF_HEADER_SLOT
#define VOLUME_PROP_EXTINCTION_IMG_SLOT
#define SHADOW_RENDER_VIEW_BUF_SLOT
#define VOLUME_PROP_PHASE_IMG_SLOT
#define GBUF_NORMAL_SLOT
#define VOLUME_PROP_EMISSION_IMG_SLOT
#define SHADOW_RENDER_MAP_SIZE
#define SHADOW_ROG_ID
#define SURFEL_BUF_SLOT
#define EEVEE_MAT_PIPE_VARIATIONS(name,...)
uint pos
uint nor
ImageBase< uint, 2, true, true > uimage2DArrayAtomic
ImageBase< uint, 2, false, true > uimage2DAtomic
ImageBase< uint, 3, false, true > uimage3DAtomic
ImageBase< uint, 2, true > uimage2DArray
ImageBase< float, 2, true > image2DArray
VecBase< float, 4 > float4
ImageBase< float, 3 > image3D
#define VERTEX_OUT(stage_interface)
#define FRAGMENT_OUT_DUAL(slot, type, name, blend)
#define SMOOTH(type, name)
#define UNIFORM_BUF(slot, type_name, name)
#define FRAGMENT_SOURCE(filename)
#define IMAGE_FREQ(slot, format, qualifiers, type, name, freq)
#define ADDITIONAL_INFO(info_name)
#define PUSH_CONSTANT(type, name)
#define DEFINE(name)
#define GPU_SHADER_NAMED_INTERFACE_INFO(_interface, _inst_name)
#define FLAT(type, name)
#define GPU_SHADER_NAMED_INTERFACE_END(_inst_name)
#define FRAGMENT_OUT(slot, type, name)
#define BUILTINS(builtin)
#define STORAGE_BUF(slot, qualifiers, type_name, name)
#define GPU_SHADER_CREATE_INFO(_info)
#define VERTEX_SOURCE(filename)
#define VERTEX_IN(slot, type, name)
#define IMAGE(slot, format, qualifiers, type, name)
#define GPU_SHADER_CREATE_END()
#define DO_STATIC_COMPILATION()
#define DEPTH_WRITE(value)
#define EARLY_FRAGMENT_TEST(enable)
#define DEFINE_VALUE(name, value)
#define FRAGMENT_OUT_ROG(slot, type, name, rog)
ccl_device_inline float interp(const float a, const float b, const float t)
Definition math_base.h:502
#define N
read