2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2005 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2020-02-12 12:48:44 +01:00
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
|
* \ingroup gpu
|
2020-02-27 13:55:29 +01:00
|
|
|
*
|
|
|
|
|
* Intermediate node graph for generating GLSL shaders.
|
2020-02-12 12:48:44 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "DNA_listBase.h"
|
|
|
|
|
|
2022-04-14 18:47:58 +02:00
|
|
|
#include "BLI_ghash.h"
|
|
|
|
|
|
2024-02-01 10:40:24 -05:00
|
|
|
#include "GPU_material.hh"
|
2022-04-14 18:47:58 +02:00
|
|
|
|
2020-02-12 12:48:44 +01:00
|
|
|
struct GPUNode;
|
|
|
|
|
struct GPUOutput;
|
|
|
|
|
struct ListBase;
|
|
|
|
|
|
2024-03-23 01:24:18 +01:00
|
|
|
enum eGPUDataSource {
|
2020-02-12 12:48:44 +01:00
|
|
|
GPU_SOURCE_OUTPUT,
|
|
|
|
|
GPU_SOURCE_CONSTANT,
|
|
|
|
|
GPU_SOURCE_UNIFORM,
|
|
|
|
|
GPU_SOURCE_ATTR,
|
Materials: add custom object properties as uniform attributes.
This patch allows the user to type a property name into the
Attribute node, which will then output the value of the property
for each individual object, allowing to e.g. customize shaders
by object without duplicating the shader.
In order to make supporting this easier for Eevee, it is necessary
to explicitly choose whether the attribute is varying or uniform
via a dropdown option of the Attribute node. The dropdown also
allows choosing whether instancing should be taken into account.
The Cycles design treats all attributes as one common namespace,
so the Blender interface converts the enum to a name prefix that
can't be entered using keyboard.
In Eevee, the attributes are provided to the shader via a UBO indexed
with resource_id, similar to the existing Object Info data. Unlike it,
however, it is necessary to maintain a separate buffer for every
requested combination of attributes.
This is done using a hash table with the attribute set as the key,
as it is expected that technically different but similar materials
may use the same set of attributes. In addition, in order to minimize
wasted memory, a sparse UBO pool is implemented, so that chunks that
don't contain any data don't have to be allocated.
The back-end Cycles code is already refactored and committed by Brecht.
Differential Revision: https://developer.blender.org/D2057
2020-08-05 19:14:40 +03:00
|
|
|
GPU_SOURCE_UNIFORM_ATTR,
|
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_SOURCE_LAYER_ATTR,
|
2020-02-12 12:48:44 +01:00
|
|
|
GPU_SOURCE_STRUCT,
|
|
|
|
|
GPU_SOURCE_TEX,
|
2020-02-27 13:55:29 +01:00
|
|
|
GPU_SOURCE_TEX_TILED_MAPPING,
|
2022-04-14 18:47:58 +02:00
|
|
|
GPU_SOURCE_FUNCTION_CALL,
|
2022-09-13 11:07:30 +02:00
|
|
|
GPU_SOURCE_CRYPTOMATTE,
|
2024-03-23 01:24:18 +01:00
|
|
|
};
|
2020-02-12 12:48:44 +01:00
|
|
|
|
2024-03-23 01:24:18 +01:00
|
|
|
enum GPUNodeLinkType {
|
2020-02-12 12:48:44 +01:00
|
|
|
GPU_NODE_LINK_NONE = 0,
|
|
|
|
|
GPU_NODE_LINK_ATTR,
|
Materials: add custom object properties as uniform attributes.
This patch allows the user to type a property name into the
Attribute node, which will then output the value of the property
for each individual object, allowing to e.g. customize shaders
by object without duplicating the shader.
In order to make supporting this easier for Eevee, it is necessary
to explicitly choose whether the attribute is varying or uniform
via a dropdown option of the Attribute node. The dropdown also
allows choosing whether instancing should be taken into account.
The Cycles design treats all attributes as one common namespace,
so the Blender interface converts the enum to a name prefix that
can't be entered using keyboard.
In Eevee, the attributes are provided to the shader via a UBO indexed
with resource_id, similar to the existing Object Info data. Unlike it,
however, it is necessary to maintain a separate buffer for every
requested combination of attributes.
This is done using a hash table with the attribute set as the key,
as it is expected that technically different but similar materials
may use the same set of attributes. In addition, in order to minimize
wasted memory, a sparse UBO pool is implemented, so that chunks that
don't contain any data don't have to be allocated.
The back-end Cycles code is already refactored and committed by Brecht.
Differential Revision: https://developer.blender.org/D2057
2020-08-05 19:14:40 +03:00
|
|
|
GPU_NODE_LINK_UNIFORM_ATTR,
|
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_NODE_LINK_LAYER_ATTR,
|
2020-02-12 12:48:44 +01:00
|
|
|
GPU_NODE_LINK_COLORBAND,
|
|
|
|
|
GPU_NODE_LINK_CONSTANT,
|
2020-02-27 13:55:29 +01:00
|
|
|
GPU_NODE_LINK_IMAGE,
|
|
|
|
|
GPU_NODE_LINK_IMAGE_TILED,
|
|
|
|
|
GPU_NODE_LINK_IMAGE_TILED_MAPPING,
|
2022-09-16 15:04:47 +02:00
|
|
|
GPU_NODE_LINK_IMAGE_SKY,
|
2020-02-12 12:48:44 +01:00
|
|
|
GPU_NODE_LINK_OUTPUT,
|
|
|
|
|
GPU_NODE_LINK_UNIFORM,
|
2022-04-14 18:47:58 +02:00
|
|
|
GPU_NODE_LINK_DIFFERENTIATE_FLOAT_FN,
|
2024-03-23 01:24:18 +01:00
|
|
|
};
|
2020-02-12 12:48:44 +01:00
|
|
|
|
2024-03-23 01:24:18 +01:00
|
|
|
enum eGPUNodeTag {
|
2022-04-14 18:47:58 +02:00
|
|
|
GPU_NODE_TAG_NONE = 0,
|
|
|
|
|
GPU_NODE_TAG_SURFACE = (1 << 0),
|
|
|
|
|
GPU_NODE_TAG_VOLUME = (1 << 1),
|
|
|
|
|
GPU_NODE_TAG_DISPLACEMENT = (1 << 2),
|
|
|
|
|
GPU_NODE_TAG_THICKNESS = (1 << 3),
|
|
|
|
|
GPU_NODE_TAG_AOV = (1 << 4),
|
|
|
|
|
GPU_NODE_TAG_FUNCTION = (1 << 5),
|
2022-07-29 08:37:57 +02:00
|
|
|
GPU_NODE_TAG_COMPOSITOR = (1 << 6),
|
2024-03-23 01:24:18 +01:00
|
|
|
};
|
2022-04-14 18:47:58 +02:00
|
|
|
|
2022-11-14 12:21:37 +01:00
|
|
|
ENUM_OPERATORS(eGPUNodeTag, GPU_NODE_TAG_COMPOSITOR)
|
2022-04-14 18:47:58 +02:00
|
|
|
|
2020-02-12 12:48:44 +01:00
|
|
|
struct GPUNode {
|
2024-03-23 01:24:18 +01:00
|
|
|
GPUNode *next, *prev;
|
2020-02-12 12:48:44 +01:00
|
|
|
|
|
|
|
|
const char *name;
|
|
|
|
|
|
|
|
|
|
/* Internal flag to mark nodes during pruning */
|
2022-04-14 18:47:58 +02:00
|
|
|
eGPUNodeTag tag;
|
2020-02-12 12:48:44 +01:00
|
|
|
|
|
|
|
|
ListBase inputs;
|
|
|
|
|
ListBase outputs;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct GPUNodeLink {
|
|
|
|
|
GPUNodeStack *socket;
|
|
|
|
|
|
|
|
|
|
GPUNodeLinkType link_type;
|
|
|
|
|
int users; /* Refcount */
|
|
|
|
|
|
|
|
|
|
union {
|
|
|
|
|
/* GPU_NODE_LINK_CONSTANT | GPU_NODE_LINK_UNIFORM */
|
2020-02-27 13:55:29 +01:00
|
|
|
const float *data;
|
2020-02-12 12:48:44 +01:00
|
|
|
/* GPU_NODE_LINK_COLORBAND */
|
2024-03-23 01:24:18 +01:00
|
|
|
GPUTexture **colorband;
|
2020-02-12 12:48:44 +01:00
|
|
|
/* GPU_NODE_LINK_OUTPUT */
|
2024-03-23 01:24:18 +01:00
|
|
|
GPUOutput *output;
|
2020-02-12 12:48:44 +01:00
|
|
|
/* GPU_NODE_LINK_ATTR */
|
2024-03-23 01:24:18 +01:00
|
|
|
GPUMaterialAttribute *attr;
|
Materials: add custom object properties as uniform attributes.
This patch allows the user to type a property name into the
Attribute node, which will then output the value of the property
for each individual object, allowing to e.g. customize shaders
by object without duplicating the shader.
In order to make supporting this easier for Eevee, it is necessary
to explicitly choose whether the attribute is varying or uniform
via a dropdown option of the Attribute node. The dropdown also
allows choosing whether instancing should be taken into account.
The Cycles design treats all attributes as one common namespace,
so the Blender interface converts the enum to a name prefix that
can't be entered using keyboard.
In Eevee, the attributes are provided to the shader via a UBO indexed
with resource_id, similar to the existing Object Info data. Unlike it,
however, it is necessary to maintain a separate buffer for every
requested combination of attributes.
This is done using a hash table with the attribute set as the key,
as it is expected that technically different but similar materials
may use the same set of attributes. In addition, in order to minimize
wasted memory, a sparse UBO pool is implemented, so that chunks that
don't contain any data don't have to be allocated.
The back-end Cycles code is already refactored and committed by Brecht.
Differential Revision: https://developer.blender.org/D2057
2020-08-05 19:14:40 +03:00
|
|
|
/* GPU_NODE_LINK_UNIFORM_ATTR */
|
2024-03-23 01:24:18 +01:00
|
|
|
GPUUniformAttr *uniform_attr;
|
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_NODE_LINK_LAYER_ATTR */
|
2024-03-23 01:24:18 +01:00
|
|
|
GPULayerAttr *layer_attr;
|
2020-02-27 13:55:29 +01:00
|
|
|
/* GPU_NODE_LINK_IMAGE_BLENDER */
|
2024-03-23 01:24:18 +01:00
|
|
|
GPUMaterialTexture *texture;
|
2022-04-14 18:47:58 +02:00
|
|
|
/* GPU_NODE_LINK_DIFFERENTIATE_FLOAT_FN */
|
2025-03-24 15:53:35 +01:00
|
|
|
struct {
|
|
|
|
|
const char *function_name;
|
|
|
|
|
float filter_width;
|
|
|
|
|
} differentiate_float;
|
2020-02-12 12:48:44 +01:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2024-03-23 01:24:18 +01:00
|
|
|
struct GPUOutput {
|
|
|
|
|
GPUOutput *next, *prev;
|
2020-02-12 12:48:44 +01:00
|
|
|
|
|
|
|
|
GPUNode *node;
|
|
|
|
|
eGPUType type; /* data type = length of vector/matrix */
|
|
|
|
|
GPUNodeLink *link; /* output link */
|
|
|
|
|
int id; /* unique id as created by code generator */
|
2024-03-23 01:24:18 +01:00
|
|
|
};
|
2020-02-12 12:48:44 +01:00
|
|
|
|
2024-03-23 01:24:18 +01:00
|
|
|
struct GPUInput {
|
|
|
|
|
GPUInput *next, *prev;
|
2020-02-12 12:48:44 +01:00
|
|
|
|
|
|
|
|
GPUNode *node;
|
2020-07-19 17:12:48 +10:00
|
|
|
eGPUType type; /* data-type. */
|
2020-02-12 12:48:44 +01:00
|
|
|
GPUNodeLink *link;
|
|
|
|
|
int id; /* unique id as created by code generator */
|
|
|
|
|
|
|
|
|
|
eGPUDataSource source; /* data source */
|
|
|
|
|
|
|
|
|
|
/* Content based on eGPUDataSource */
|
|
|
|
|
union {
|
|
|
|
|
/* GPU_SOURCE_CONSTANT | GPU_SOURCE_UNIFORM */
|
|
|
|
|
float vec[16]; /* vector data */
|
2024-03-23 01:24:18 +01:00
|
|
|
/* GPU_SOURCE_TEX | GPU_SOURCE_TEX_TILED_MAPPING */
|
|
|
|
|
GPUMaterialTexture *texture;
|
2020-02-12 12:48:44 +01:00
|
|
|
/* GPU_SOURCE_ATTR */
|
2024-03-23 01:24:18 +01:00
|
|
|
GPUMaterialAttribute *attr;
|
Materials: add custom object properties as uniform attributes.
This patch allows the user to type a property name into the
Attribute node, which will then output the value of the property
for each individual object, allowing to e.g. customize shaders
by object without duplicating the shader.
In order to make supporting this easier for Eevee, it is necessary
to explicitly choose whether the attribute is varying or uniform
via a dropdown option of the Attribute node. The dropdown also
allows choosing whether instancing should be taken into account.
The Cycles design treats all attributes as one common namespace,
so the Blender interface converts the enum to a name prefix that
can't be entered using keyboard.
In Eevee, the attributes are provided to the shader via a UBO indexed
with resource_id, similar to the existing Object Info data. Unlike it,
however, it is necessary to maintain a separate buffer for every
requested combination of attributes.
This is done using a hash table with the attribute set as the key,
as it is expected that technically different but similar materials
may use the same set of attributes. In addition, in order to minimize
wasted memory, a sparse UBO pool is implemented, so that chunks that
don't contain any data don't have to be allocated.
The back-end Cycles code is already refactored and committed by Brecht.
Differential Revision: https://developer.blender.org/D2057
2020-08-05 19:14:40 +03:00
|
|
|
/* GPU_SOURCE_UNIFORM_ATTR */
|
2024-03-23 01:24:18 +01:00
|
|
|
GPUUniformAttr *uniform_attr;
|
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_SOURCE_LAYER_ATTR */
|
2024-03-23 01:24:18 +01:00
|
|
|
GPULayerAttr *layer_attr;
|
2022-04-14 18:47:58 +02:00
|
|
|
/* GPU_SOURCE_FUNCTION_CALL */
|
|
|
|
|
char function_call[64];
|
2020-02-12 12:48:44 +01:00
|
|
|
};
|
2024-03-23 01:24:18 +01:00
|
|
|
};
|
2020-02-12 12:48:44 +01:00
|
|
|
|
2024-03-23 01:24:18 +01:00
|
|
|
struct GPUNodeGraphOutputLink {
|
|
|
|
|
GPUNodeGraphOutputLink *next, *prev;
|
2020-12-04 08:13:54 +01:00
|
|
|
int hash;
|
|
|
|
|
GPUNodeLink *outlink;
|
2024-03-23 01:24:18 +01:00
|
|
|
};
|
2020-12-04 08:13:54 +01:00
|
|
|
|
2024-03-23 01:24:18 +01:00
|
|
|
struct GPUNodeGraphFunctionLink {
|
|
|
|
|
GPUNodeGraphFunctionLink *next, *prev;
|
2022-04-14 18:47:58 +02:00
|
|
|
char name[16];
|
|
|
|
|
GPUNodeLink *outlink;
|
2024-03-23 01:24:18 +01:00
|
|
|
};
|
2022-04-14 18:47:58 +02:00
|
|
|
|
2024-03-23 01:24:18 +01:00
|
|
|
struct GPUNodeGraph {
|
2020-02-12 12:48:44 +01:00
|
|
|
/* Nodes */
|
|
|
|
|
ListBase nodes;
|
|
|
|
|
|
2022-04-14 18:47:58 +02:00
|
|
|
/* Main Outputs. */
|
|
|
|
|
GPUNodeLink *outlink_surface;
|
|
|
|
|
GPUNodeLink *outlink_volume;
|
|
|
|
|
GPUNodeLink *outlink_displacement;
|
|
|
|
|
GPUNodeLink *outlink_thickness;
|
2020-12-04 08:13:54 +01:00
|
|
|
/* List of GPUNodeGraphOutputLink */
|
|
|
|
|
ListBase outlink_aovs;
|
2022-04-14 18:47:58 +02:00
|
|
|
/* List of GPUNodeGraphFunctionLink */
|
|
|
|
|
ListBase material_functions;
|
2022-07-29 08:37:57 +02:00
|
|
|
/* List of GPUNodeGraphOutputLink */
|
|
|
|
|
ListBase outlink_compositor;
|
2020-02-12 12:48:44 +01:00
|
|
|
|
2020-02-14 10:47:20 +01:00
|
|
|
/* Requested attributes and textures. */
|
|
|
|
|
ListBase attributes;
|
|
|
|
|
ListBase textures;
|
Materials: add custom object properties as uniform attributes.
This patch allows the user to type a property name into the
Attribute node, which will then output the value of the property
for each individual object, allowing to e.g. customize shaders
by object without duplicating the shader.
In order to make supporting this easier for Eevee, it is necessary
to explicitly choose whether the attribute is varying or uniform
via a dropdown option of the Attribute node. The dropdown also
allows choosing whether instancing should be taken into account.
The Cycles design treats all attributes as one common namespace,
so the Blender interface converts the enum to a name prefix that
can't be entered using keyboard.
In Eevee, the attributes are provided to the shader via a UBO indexed
with resource_id, similar to the existing Object Info data. Unlike it,
however, it is necessary to maintain a separate buffer for every
requested combination of attributes.
This is done using a hash table with the attribute set as the key,
as it is expected that technically different but similar materials
may use the same set of attributes. In addition, in order to minimize
wasted memory, a sparse UBO pool is implemented, so that chunks that
don't contain any data don't have to be allocated.
The back-end Cycles code is already refactored and committed by Brecht.
Differential Revision: https://developer.blender.org/D2057
2020-08-05 19:14:40 +03:00
|
|
|
|
|
|
|
|
/* The list of uniform attributes. */
|
|
|
|
|
GPUUniformAttrList uniform_attrs;
|
2022-04-14 18:47:58 +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
|
|
|
/* The list of layer attributes. */
|
|
|
|
|
ListBase layer_attrs;
|
|
|
|
|
|
2023-09-14 13:25:24 +10:00
|
|
|
/** Set of all the GLSL lib code blocks. */
|
2022-04-14 18:47:58 +02:00
|
|
|
GSet *used_libraries;
|
2024-03-23 01:24:18 +01:00
|
|
|
};
|
2020-02-12 12:48:44 +01:00
|
|
|
|
|
|
|
|
/* Node Graph */
|
|
|
|
|
|
2022-11-14 12:21:37 +01:00
|
|
|
void gpu_nodes_tag(GPUNodeLink *link, eGPUNodeTag tag);
|
2020-02-12 12:48:44 +01:00
|
|
|
void gpu_node_graph_prune_unused(GPUNodeGraph *graph);
|
Materials: add custom object properties as uniform attributes.
This patch allows the user to type a property name into the
Attribute node, which will then output the value of the property
for each individual object, allowing to e.g. customize shaders
by object without duplicating the shader.
In order to make supporting this easier for Eevee, it is necessary
to explicitly choose whether the attribute is varying or uniform
via a dropdown option of the Attribute node. The dropdown also
allows choosing whether instancing should be taken into account.
The Cycles design treats all attributes as one common namespace,
so the Blender interface converts the enum to a name prefix that
can't be entered using keyboard.
In Eevee, the attributes are provided to the shader via a UBO indexed
with resource_id, similar to the existing Object Info data. Unlike it,
however, it is necessary to maintain a separate buffer for every
requested combination of attributes.
This is done using a hash table with the attribute set as the key,
as it is expected that technically different but similar materials
may use the same set of attributes. In addition, in order to minimize
wasted memory, a sparse UBO pool is implemented, so that chunks that
don't contain any data don't have to be allocated.
The back-end Cycles code is already refactored and committed by Brecht.
Differential Revision: https://developer.blender.org/D2057
2020-08-05 19:14:40 +03:00
|
|
|
void gpu_node_graph_finalize_uniform_attrs(GPUNodeGraph *graph);
|
2022-09-22 17:27:51 +02:00
|
|
|
|
2023-02-14 21:51:03 +01:00
|
|
|
/**
|
|
|
|
|
* Optimize node graph for optimized material shader path.
|
|
|
|
|
* Once the base material has been generated, we can modify the shader
|
|
|
|
|
* node graph to create one which will produce an optimally performing shader.
|
|
|
|
|
* This currently involves baking uniform data into constant data to enable
|
|
|
|
|
* aggressive constant folding by the compiler in order to reduce complexity and
|
|
|
|
|
* shader core memory pressure.
|
|
|
|
|
*
|
|
|
|
|
* NOTE: Graph optimizations will produce a shader which needs to be re-compiled
|
|
|
|
|
* more frequently, however, the default material pass will always exist to fall
|
|
|
|
|
* back on. */
|
|
|
|
|
void gpu_node_graph_optimize(GPUNodeGraph *graph);
|
|
|
|
|
|
2021-12-09 20:01:47 +11:00
|
|
|
/**
|
|
|
|
|
* Free intermediate node graph.
|
|
|
|
|
*/
|
2020-02-14 10:47:20 +01:00
|
|
|
void gpu_node_graph_free_nodes(GPUNodeGraph *graph);
|
2021-12-09 20:01:47 +11:00
|
|
|
/**
|
|
|
|
|
* Free both node graph and requested attributes and textures.
|
|
|
|
|
*/
|
2020-02-12 12:48:44 +01:00
|
|
|
void gpu_node_graph_free(GPUNodeGraph *graph);
|
|
|
|
|
|
|
|
|
|
/* Material calls */
|
|
|
|
|
|
2024-03-23 01:24:18 +01:00
|
|
|
GPUNodeGraph *gpu_material_node_graph(GPUMaterial *material);
|
2021-12-09 20:01:47 +11:00
|
|
|
/**
|
|
|
|
|
* Returns the address of the future pointer to coba_tex.
|
|
|
|
|
*/
|
2024-03-23 01:24:18 +01:00
|
|
|
GPUTexture **gpu_material_ramp_texture_row_set(GPUMaterial *mat,
|
|
|
|
|
int size,
|
2024-07-29 13:01:12 +10:00
|
|
|
const float *pixels,
|
|
|
|
|
float *r_row);
|
2022-09-16 15:04:47 +02:00
|
|
|
/**
|
|
|
|
|
* Returns the address of the future pointer to sky_tex
|
|
|
|
|
*/
|
2024-03-23 01:24:18 +01:00
|
|
|
GPUTexture **gpu_material_sky_texture_layer_set(
|
|
|
|
|
GPUMaterial *mat, int width, int height, const float *pixels, float *row);
|