2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2022-01-17 14:45:22 +01:00
|
|
|
|
2024-11-13 12:32:39 +01:00
|
|
|
#ifdef GPU_SHADER
|
|
|
|
|
# pragma once
|
2025-09-15 17:22:19 +02:00
|
|
|
# include "gpu_shader_compat.hh"
|
2024-11-13 12:32:39 +01:00
|
|
|
|
|
|
|
|
# include "draw_shader_shared.hh"
|
2025-04-16 20:26:48 +02:00
|
|
|
# include "gpencil_shader_shared.hh"
|
2024-11-13 12:32:39 +01:00
|
|
|
|
2025-09-25 10:57:02 +02:00
|
|
|
# include "draw_view_infos.hh"
|
2024-11-08 00:15:10 +01:00
|
|
|
|
2025-08-27 09:49:43 +02:00
|
|
|
# define CURVES_SHADER
|
2024-12-01 00:36:59 +01:00
|
|
|
# define DRW_GPENCIL_INFO
|
2024-11-13 12:32:39 +01:00
|
|
|
#endif
|
|
|
|
|
|
2024-03-22 23:51:35 -04:00
|
|
|
#include "draw_defines.hh"
|
2022-01-17 14:45:22 +01:00
|
|
|
#include "gpu_shader_create_info.hh"
|
|
|
|
|
|
2022-04-19 12:01:16 +02:00
|
|
|
GPU_SHADER_CREATE_INFO(draw_volume_infos)
|
2024-10-04 19:04:40 +02:00
|
|
|
TYPEDEF_SOURCE("draw_shader_shared.hh")
|
|
|
|
|
DEFINE("VOLUME_INFO_LIB")
|
|
|
|
|
UNIFORM_BUF_FREQ(DRW_OBJ_DATA_INFO_UBO_SLOT, VolumeInfos, drw_volume, BATCH)
|
|
|
|
|
GPU_SHADER_CREATE_END()
|
EEVEE: support Curves attributes rendering
This adds support to render Curves attributes in EEVEE.
Each attribute is stored in a texture derived from a VBO. As the
shading group needs the textures to be valid upon creation, the
attributes are created and setup during its very creation, instead
of doing it lazily via create_requested which we cannot rely on
anyway as contrary to the mesh batch, we do cannot really tell if
attributes need to be updated or else via some `DRW_batch_requested`.
Since point attributes need refinement, and since attributes are all
cast to vec4/float4 to account for differences in type conversions
between Blender and OpenGL, the refinement shader for points is
used as is. The point attributes are stored for each subdivision level
in CurvesEvalFinalCache. Each subdivision level also keeps track of the
attributes already in use so they are properly updated when needed.
Some basic garbage collection was added similar to what is done
for meshes: if the attributes used over time have been different
from the currently used attributes for too long, then the buffers
are freed, ensuring that stale attributesare removed.
This adds `CurvesInfos` to the shader creation info, which stores
the scope in which the attributes are defined. Scopes are stored
as booleans, in an array indexed by attribute loading order which
is also the order in which the attributes were added to the material.
A mapping is necessary between the indices used for the scoping, and
the ones used in the Curves cache, as this may contain stale
attributes which have not been garbage collected yet.
Common utilities with the mesh code for handling requested
attributes were moved to a separate file.
Differential Revision: https://developer.blender.org/D14916
2022-05-24 05:02:57 +02:00
|
|
|
|
|
|
|
|
GPU_SHADER_CREATE_INFO(draw_curves_infos)
|
2024-10-04 19:04:40 +02:00
|
|
|
TYPEDEF_SOURCE("draw_shader_shared.hh")
|
|
|
|
|
UNIFORM_BUF_FREQ(DRW_OBJ_DATA_INFO_UBO_SLOT, CurvesInfos, drw_curves, BATCH)
|
|
|
|
|
GPU_SHADER_CREATE_END()
|
2022-09-02 18:30:48 +02:00
|
|
|
|
Attribute Node: support accessing attributes of View Layer and Scene.
The attribute node already allows accessing attributes associated
with objects and meshes, which allows changing the behavior of the
same material between different objects or instances. The same idea
can be extended to an even more global level of layers and scenes.
Currently view layers provide an option to replace all materials
with a different one. However, since the same material will be applied
to all objects in the layer, varying the behavior between layers while
preserving distinct materials requires duplicating objects.
Providing access to properties of layers and scenes via the attribute
node enables making materials with built-in switches or settings that
can be controlled globally at the view layer level. This is probably
most useful for complex NPR shading and compositing. Like with objects,
the node can also access built-in scene properties, like render resolution
or FOV of the active camera. Lookup is also attempted in World, similar
to how the Object mode checks the Mesh datablock.
In Cycles this mode is implemented by replacing the attribute node with
the attribute value during sync, allowing constant folding to take the
values into account. This means however that materials that use this
feature have to be re-synced upon any changes to scene, world or camera.
The Eevee version uses a new uniform buffer containing a sorted array
mapping name hashes to values, with binary search lookup. The array
is limited to 512 entries, which is effectively limitless even
considering it is shared by all materials in the scene; it is also
just 16KB of memory so no point trying to optimize further.
The buffer has to be rebuilt when new attributes are detected in a
material, so the draw engine keeps a table of recently seen attribute
names to minimize the chance of extra rebuilds mid-draw.
Differential Revision: https://developer.blender.org/D15941
2022-09-12 00:30:58 +03:00
|
|
|
GPU_SHADER_CREATE_INFO(draw_layer_attributes)
|
2024-10-04 19:04:40 +02:00
|
|
|
TYPEDEF_SOURCE("draw_shader_shared.hh")
|
|
|
|
|
DEFINE("VLATTR_LIB")
|
|
|
|
|
UNIFORM_BUF_FREQ(DRW_LAYER_ATTR_UBO_SLOT,
|
|
|
|
|
LayerAttribute,
|
|
|
|
|
drw_layer_attrs[DRW_RESOURCE_CHUNK_LEN],
|
|
|
|
|
BATCH)
|
|
|
|
|
GPU_SHADER_CREATE_END()
|
Attribute Node: support accessing attributes of View Layer and Scene.
The attribute node already allows accessing attributes associated
with objects and meshes, which allows changing the behavior of the
same material between different objects or instances. The same idea
can be extended to an even more global level of layers and scenes.
Currently view layers provide an option to replace all materials
with a different one. However, since the same material will be applied
to all objects in the layer, varying the behavior between layers while
preserving distinct materials requires duplicating objects.
Providing access to properties of layers and scenes via the attribute
node enables making materials with built-in switches or settings that
can be controlled globally at the view layer level. This is probably
most useful for complex NPR shading and compositing. Like with objects,
the node can also access built-in scene properties, like render resolution
or FOV of the active camera. Lookup is also attempted in World, similar
to how the Object mode checks the Mesh datablock.
In Cycles this mode is implemented by replacing the attribute node with
the attribute value during sync, allowing constant folding to take the
values into account. This means however that materials that use this
feature have to be re-synced upon any changes to scene, world or camera.
The Eevee version uses a new uniform buffer containing a sorted array
mapping name hashes to values, with binary search lookup. The array
is limited to 512 entries, which is effectively limitless even
considering it is shared by all materials in the scene; it is also
just 16KB of memory so no point trying to optimize further.
The buffer has to be rebuilt when new attributes are detected in a
material, so the draw engine keeps a table of recently seen attribute
names to minimize the chance of extra rebuilds mid-draw.
Differential Revision: https://developer.blender.org/D15941
2022-09-12 00:30:58 +03:00
|
|
|
|
2025-02-25 18:41:51 +01:00
|
|
|
GPU_SHADER_CREATE_INFO(draw_object_infos)
|
2024-10-04 19:04:40 +02:00
|
|
|
TYPEDEF_SOURCE("draw_shader_shared.hh")
|
|
|
|
|
DEFINE("OBINFO_LIB")
|
2025-04-24 14:38:13 +02:00
|
|
|
STORAGE_BUF(DRW_OBJ_INFOS_SLOT, read, ObjectInfos, drw_infos[])
|
2024-10-04 19:04:40 +02:00
|
|
|
GPU_SHADER_CREATE_END()
|
2022-09-01 14:46:17 +02:00
|
|
|
|
2025-02-25 18:41:51 +01:00
|
|
|
/** \note Requires draw_object_infos. */
|
|
|
|
|
GPU_SHADER_CREATE_INFO(draw_object_attributes)
|
2024-10-04 19:04:40 +02:00
|
|
|
DEFINE("OBATTR_LIB")
|
2025-04-24 14:38:13 +02:00
|
|
|
STORAGE_BUF(DRW_OBJ_ATTR_SLOT, read, ObjectAttribute, drw_attrs[])
|
2025-02-25 18:41:51 +01:00
|
|
|
ADDITIONAL_INFO(draw_object_infos)
|
2024-10-04 19:04:40 +02:00
|
|
|
GPU_SHADER_CREATE_END()
|
2024-11-13 12:32:39 +01:00
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Geometry Type
|
|
|
|
|
* \{ */
|
|
|
|
|
|
|
|
|
|
GPU_SHADER_CREATE_INFO(draw_mesh)
|
2025-02-25 23:05:03 +01:00
|
|
|
ADDITIONAL_INFO(draw_modelmat)
|
2024-11-13 12:32:39 +01:00
|
|
|
GPU_SHADER_CREATE_END()
|
|
|
|
|
|
2025-08-27 09:49:43 +02:00
|
|
|
GPU_SHADER_CREATE_INFO(draw_curves)
|
|
|
|
|
DEFINE("CURVES_SHADER")
|
2024-11-13 12:32:39 +01:00
|
|
|
DEFINE("DRW_HAIR_INFO")
|
2025-08-27 09:49:43 +02:00
|
|
|
SAMPLER_FREQ(0, samplerBuffer, curves_pos_rad_buf, BATCH)
|
|
|
|
|
SAMPLER_FREQ(1, isamplerBuffer, curves_indirection_buf, BATCH)
|
2024-11-13 12:32:39 +01:00
|
|
|
GPU_SHADER_CREATE_END()
|
|
|
|
|
|
|
|
|
|
GPU_SHADER_CREATE_INFO(draw_pointcloud)
|
2025-04-24 14:38:13 +02:00
|
|
|
SAMPLER_FREQ(0, samplerBuffer, ptcloud_pos_rad_tx, BATCH)
|
2024-11-13 12:32:39 +01:00
|
|
|
DEFINE("POINTCLOUD_SHADER")
|
|
|
|
|
DEFINE("DRW_POINTCLOUD_INFO")
|
|
|
|
|
GPU_SHADER_CREATE_END()
|
|
|
|
|
|
|
|
|
|
GPU_SHADER_CREATE_INFO(draw_volume)
|
2025-02-25 23:05:03 +01:00
|
|
|
ADDITIONAL_INFO(draw_modelmat)
|
2024-11-13 12:32:39 +01:00
|
|
|
GPU_SHADER_CREATE_END()
|
|
|
|
|
|
|
|
|
|
GPU_SHADER_CREATE_INFO(draw_gpencil)
|
2025-04-16 20:26:48 +02:00
|
|
|
TYPEDEF_SOURCE("gpencil_shader_shared.hh")
|
2024-11-13 12:32:39 +01:00
|
|
|
DEFINE("DRW_GPENCIL_INFO")
|
2025-04-24 14:38:13 +02:00
|
|
|
SAMPLER(0, samplerBuffer, gp_pos_tx)
|
|
|
|
|
SAMPLER(1, samplerBuffer, gp_col_tx)
|
2024-11-13 12:32:39 +01:00
|
|
|
ADDITIONAL_INFO(draw_resource_id_varying)
|
|
|
|
|
ADDITIONAL_INFO(draw_view)
|
2025-02-25 18:41:51 +01:00
|
|
|
ADDITIONAL_INFO(draw_object_infos)
|
2024-11-13 12:32:39 +01:00
|
|
|
GPU_SHADER_CREATE_END()
|
|
|
|
|
|
|
|
|
|
/** \} */
|