Implement Uniformbuffer objects for nodetree parameters

For users that means you can tweak shaders in the nodetree and things
are way faster. This is a huge improvement, particularly in
systems that have no shader cache.

From the code perspective it means we are no longer re-compiling the
shader every time a value is tweaked in the UI. We are using uniforms
for those values.

It would be slow to add that many uniforms for all the shaders. So
instead we are using UBO (Uniform Buffer Objects).

This fixes the main issue of T51467. However GWN_shaderinterface_create() still
needs to be improvedi. When opening a .blend all shaders are compiled once, so
optimizing it will bring a measurable impact.

========================================================================
NOTE: This breaks update of Cycles material upon nodetree nodes
tweaking. It will be fixed separately by depsgraph, once tackling T51925
(Animated Eevee values slowdown).

The idea is to make Depsgraph update more granular. The XXX TODO in
rna_nodetree.c will be tackled at that time as well.
========================================================================

Reviewers: sergey, brecht, fclem

Differential Revision: https://developer.blender.org/D2739
This commit is contained in:
Dalai Felinto 2017-07-14 17:40:54 +02:00
parent 73b1425297
commit 2a489273d7
Notes: blender-bot 2023-02-14 06:59:09 +01:00
Referenced by issue #52061, Cant change environmental texture with thumbnail view enabled while browsing
Referenced by issue #51467, Eevee: Shader recompilation issue
79 changed files with 579 additions and 168 deletions

View File

@ -2025,7 +2025,7 @@ bNodeTree *ntreeLocalize(bNodeTree *ntree)
for (node = ntree->nodes.first; node; node = node->next) {
/* store new_node pointer to original */
node->new_node->new_node = node;
node->new_node->original = node;
}
if (ntree->typeinfo->localize)

View File

@ -779,6 +779,11 @@ DRWShadingGroup *DRW_shgroup_material_create(struct GPUMaterial *material, DRWPa
}
}
GPUUniformBuffer *ubo = GPU_material_get_uniform_buffer(material);
if (ubo != NULL) {
DRW_shgroup_uniform_block(grp, GPU_UBO_BLOCK_NAME, ubo);
}
return grp;
}

View File

@ -43,6 +43,7 @@ extern "C" {
struct Image;
struct ImageUser;
struct ListBase;
struct Material;
struct Object;
struct Scene;
@ -53,9 +54,11 @@ struct GPUNodeLink;
struct GPUNodeStack;
struct GPUMaterial;
struct GPUTexture;
struct GPUUniformBuffer;
struct GPULamp;
struct PreviewImage;
struct World;
struct bNode;
struct bNodeTree;
typedef struct GPUNode GPUNode;
@ -143,6 +146,7 @@ typedef struct GPUNodeStack {
#define GPU_DYNAMIC_GROUP_MIST 0x00050000
#define GPU_DYNAMIC_GROUP_WORLD 0x00060000
#define GPU_DYNAMIC_GROUP_MAT 0x00070000
#define GPU_DYNAMIC_UBO 0x00080000
typedef enum GPUDynamicType {
@ -202,6 +206,7 @@ typedef enum GPUDynamicType {
GPUNodeLink *GPU_attribute(CustomDataType type, const char *name);
GPUNodeLink *GPU_uniform(float *num);
GPUNodeLink *GPU_dynamic_uniform(float *num, GPUDynamicType dynamictype, void *data);
GPUNodeLink *GPU_uniform_buffer(float *num, GPUType gputype);
GPUNodeLink *GPU_image(struct Image *ima, struct ImageUser *iuser, bool is_data);
GPUNodeLink *GPU_cube_map(struct Image *ima, struct ImageUser *iuser, bool is_data);
GPUNodeLink *GPU_image_preview(struct PreviewImage *prv);
@ -212,7 +217,10 @@ GPUNodeLink *GPU_opengl_builtin(GPUOpenGLBuiltin builtin);
void GPU_node_link_set_type(GPUNodeLink *link, GPUType type);
bool GPU_link(GPUMaterial *mat, const char *name, ...);
bool GPU_stack_link(GPUMaterial *mat, const char *name, GPUNodeStack *in, GPUNodeStack *out, ...);
bool GPU_stack_link(GPUMaterial *mat, struct bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out, ...);
GPUNodeLink *GPU_uniformbuffer_link_out(
struct GPUMaterial *mat, struct bNode *node,
struct GPUNodeStack *stack, const int index);
void GPU_material_output_link(GPUMaterial *material, GPUNodeLink *link);
void GPU_material_enable_alpha(GPUMaterial *material);
@ -244,6 +252,10 @@ struct Scene *GPU_material_scene(GPUMaterial *material);
GPUMatType GPU_Material_get_type(GPUMaterial *material);
struct GPUPass *GPU_material_get_pass(GPUMaterial *material);
struct GPUUniformBuffer *GPU_material_get_uniform_buffer(GPUMaterial *material);
void GPU_material_create_uniform_buffer(GPUMaterial *material, struct ListBase *inputs);
void GPU_material_uniform_buffer_tag_dirty(struct ListBase *gpumaterials);
void GPU_material_vertex_attributes(GPUMaterial *material,
struct GPUVertexAttribs *attrib);

View File

@ -32,12 +32,19 @@
#ifndef __GPU_UNIFORMBUFFER_H__
#define __GPU_UNIFORMBUFFER_H__
typedef enum GPUType GPUType;
struct ListBase;
typedef struct GPUUniformBuffer GPUUniformBuffer;
typedef struct GPUUniformBufferDynamicItem GPUUniformBufferDynamicItem;
GPUUniformBuffer *GPU_uniformbuffer_create(int size, const void *data, char err_out[256]);
GPUUniformBuffer *GPU_uniformbuffer_dynamic_create(struct ListBase *inputs, char err_out[256]);
void GPU_uniformbuffer_free(GPUUniformBuffer *ubo);
void GPU_uniformbuffer_update(GPUUniformBuffer *ubo, const void *data);
void GPU_uniformbuffer_dynamic_update(GPUUniformBuffer *ubo_);
void GPU_uniformbuffer_bind(GPUUniformBuffer *ubo, int number);
#if 0
@ -46,4 +53,10 @@ void GPU_uniformbuffer_unbind(GPUUniformBuffer *ubo);
int GPU_uniformbuffer_bindpoint(GPUUniformBuffer *ubo);
bool GPU_uniformbuffer_is_empty(GPUUniformBuffer *ubo);
bool GPU_uniformbuffer_is_dirty(GPUUniformBuffer *ubo);
void GPU_uniformbuffer_tag_dirty(GPUUniformBuffer *ubo);
#define GPU_UBO_BLOCK_NAME "nodeTree"
#endif /* __GPU_UNIFORMBUFFER_H__ */

View File

@ -36,6 +36,7 @@
#include "DNA_customdata_types.h"
#include "DNA_image_types.h"
#include "DNA_material_types.h"
#include "DNA_node_types.h"
#include "BLI_blenlib.h"
#include "BLI_utildefines.h"
@ -47,6 +48,7 @@
#include "GPU_material.h"
#include "GPU_shader.h"
#include "GPU_texture.h"
#include "GPU_uniformbuffer.h"
#include "BLI_sys_types.h" /* for intptr_t support */
@ -508,12 +510,16 @@ static void codegen_set_unique_ids(ListBase *nodes)
BLI_ghash_free(definehash, NULL, NULL);
}
static int codegen_print_uniforms_functions(DynStr *ds, ListBase *nodes)
/**
* It will create an UBO for GPUMaterial if there is any GPU_DYNAMIC_UBO.
*/
static int codegen_process_uniforms_functions(GPUMaterial *material, DynStr *ds, ListBase *nodes)
{
GPUNode *node;
GPUInput *input;
const char *name;
int builtins = 0;
ListBase ubo_inputs = {NULL, NULL};
/* print uniforms */
for (node = nodes->first; node; node = node->next) {
@ -545,7 +551,13 @@ static int codegen_print_uniforms_functions(DynStr *ds, ListBase *nodes)
}
}
else if (input->source == GPU_SOURCE_VEC_UNIFORM) {
if (input->dynamicvec) {
if (input->dynamictype == GPU_DYNAMIC_UBO) {
if (!input->link) {
/* We handle the UBOuniforms separately. */
BLI_addtail(&ubo_inputs, BLI_genericNodeN(input));
}
}
else if (input->dynamicvec) {
/* only create uniforms for dynamic vectors */
BLI_dynstr_appendf(ds, "uniform %s unf%d;\n",
GPU_DATATYPE_STR[input->type], input->id);
@ -584,6 +596,22 @@ static int codegen_print_uniforms_functions(DynStr *ds, ListBase *nodes)
}
}
/* Handle the UBO block separately. */
if ((material != NULL) && !BLI_listbase_is_empty(&ubo_inputs)) {
GPU_material_create_uniform_buffer(material, &ubo_inputs);
/* Inputs are sorted */
BLI_dynstr_appendf(ds, "\nlayout (std140) uniform %s {\n", GPU_UBO_BLOCK_NAME);
for (LinkData *link = ubo_inputs.first; link; link = link->next) {
input = link->data;
BLI_dynstr_appendf(ds, "\t%s unf%d;\n",
GPU_DATATYPE_STR[input->type], input->id);
}
BLI_dynstr_append(ds, "};\n");
BLI_freelistN(&ubo_inputs);
}
BLI_dynstr_append(ds, "\n");
return builtins;
@ -686,7 +714,7 @@ static void codegen_call_functions(DynStr *ds, ListBase *nodes, GPUOutput *final
BLI_dynstr_append(ds, ";\n");
}
static char *code_generate_fragment(ListBase *nodes, GPUOutput *output, bool use_new_shading)
static char *code_generate_fragment(GPUMaterial *material, ListBase *nodes, GPUOutput *output, bool use_new_shading)
{
DynStr *ds = BLI_dynstr_new();
char *code;
@ -703,7 +731,7 @@ static char *code_generate_fragment(ListBase *nodes, GPUOutput *output, bool use
#endif
codegen_set_unique_ids(nodes);
builtins = codegen_print_uniforms_functions(ds, nodes);
builtins = codegen_process_uniforms_functions(material, ds, nodes);
#if 0
if (G.debug & G_DEBUG)
@ -1397,7 +1425,7 @@ static void gpu_node_input_link(GPUNode *node, GPUNodeLink *link, const GPUType
name = outnode->name;
input = outnode->inputs.first;
if ((STREQ(name, "set_value") || STREQ(name, "set_rgb")) &&
if ((STREQ(name, "set_value") || STREQ(name, "set_rgb") || STREQ(name, "set_rgba")) &&
(input->type == type))
{
input = MEM_dupallocN(outnode->inputs.first);
@ -1514,15 +1542,84 @@ static void gpu_node_input_link(GPUNode *node, GPUNodeLink *link, const GPUType
BLI_addtail(&node->inputs, input);
}
static void gpu_node_input_socket(GPUNode *node, GPUNodeStack *sock)
{
GPUNodeLink *link;
static const char *gpu_uniform_set_function_from_type(eNodeSocketDatatype type)
{
switch (type) {
case SOCK_FLOAT:
return "set_value";
case SOCK_VECTOR:
return "set_rgb";
case SOCK_RGBA:
return "set_rgba";
default:
BLI_assert(!"No gpu function for non-supported eNodeSocketDatatype");
return NULL;
}
}
/**
* Link stack uniform buffer.
* This is called for the input/output sockets that are note connected.
*/
static GPUNodeLink *gpu_uniformbuffer_link(
GPUMaterial *mat, bNode *node, GPUNodeStack *stack, const int index, const eNodeSocketInOut in_out)
{
bNodeSocket *socket;
if (in_out == SOCK_IN) {
socket = BLI_findlink(&node->original->inputs, index);
}
else {
socket = BLI_findlink(&node->original->outputs, index);
}
BLI_assert(socket != NULL);
BLI_assert(socket->in_out == in_out);
if ((socket->flag & SOCK_HIDE_VALUE) == 0) {
GPUNodeLink *link;
switch (socket->type) {
case SOCK_FLOAT:
{
bNodeSocketValueFloat *socket_data = socket->default_value;
link = GPU_uniform_buffer(&socket_data->value, GPU_FLOAT);
break;
}
case SOCK_VECTOR:
{
bNodeSocketValueRGBA *socket_data = socket->default_value;
link = GPU_uniform_buffer(socket_data->value, GPU_VEC3);
break;
}
case SOCK_RGBA:
{
bNodeSocketValueRGBA *socket_data = socket->default_value;
link = GPU_uniform_buffer(socket_data->value, GPU_VEC4);
break;
}
default:
return NULL;
break;
}
if (in_out == SOCK_IN) {
GPU_link(mat, gpu_uniform_set_function_from_type(socket->type), link, &stack->link);
}
return link;
}
return NULL;
}
static void gpu_node_input_socket(GPUMaterial *material, bNode *bnode, GPUNode *node, GPUNodeStack *sock, const int index)
{
if (sock->link) {
gpu_node_input_link(node, sock->link, sock->type);
}
else if ((material != NULL) && (gpu_uniformbuffer_link(material, bnode, sock, index, SOCK_IN) != NULL)) {
gpu_node_input_link(node, sock->link, sock->type);
}
else {
link = GPU_node_link_create();
GPUNodeLink *link = GPU_node_link_create();
link->ptr1 = sock->vec;
gpu_node_input_link(node, link, sock->type);
}
@ -1685,6 +1782,21 @@ GPUNodeLink *GPU_dynamic_uniform(float *num, GPUDynamicType dynamictype, void *d
return link;
}
/**
* Add uniform to UBO struct of GPUMaterial.
*/
GPUNodeLink *GPU_uniform_buffer(float *num, GPUType gputype)
{
GPUNodeLink *link = GPU_node_link_create();
link->ptr1 = num;
link->ptr2 = NULL;
link->dynamic = true;
link->dynamictype = GPU_DYNAMIC_UBO;
link->type = gputype;
return link;
}
GPUNodeLink *GPU_image(Image *ima, ImageUser *iuser, bool is_data)
{
GPUNodeLink *link = GPU_node_link_create();
@ -1795,7 +1907,7 @@ bool GPU_link(GPUMaterial *mat, const char *name, ...)
return true;
}
bool GPU_stack_link(GPUMaterial *mat, const char *name, GPUNodeStack *in, GPUNodeStack *out, ...)
bool GPU_stack_link(GPUMaterial *material, bNode *bnode, const char *name, GPUNodeStack *in, GPUNodeStack *out, ...)
{
GPUNode *node;
GPUFunction *function;
@ -1815,11 +1927,11 @@ bool GPU_stack_link(GPUMaterial *mat, const char *name, GPUNodeStack *in, GPUNod
if (in) {
for (i = 0; in[i].type != GPU_NONE; i++) {
gpu_node_input_socket(node, &in[i]);
gpu_node_input_socket(material, bnode, node, &in[i], i);
totin++;
}
}
if (out) {
for (i = 0; out[i].type != GPU_NONE; i++) {
gpu_node_output(node, out[i].type, &out[i].link);
@ -1841,7 +1953,7 @@ bool GPU_stack_link(GPUMaterial *mat, const char *name, GPUNodeStack *in, GPUNod
if (totin == 0) {
link = va_arg(params, GPUNodeLink *);
if (link->socket)
gpu_node_input_socket(node, link->socket);
gpu_node_input_socket(NULL, NULL, node, link->socket, -1);
else
gpu_node_input_link(node, link, function->paramtype[i]);
}
@ -1851,8 +1963,8 @@ bool GPU_stack_link(GPUMaterial *mat, const char *name, GPUNodeStack *in, GPUNod
}
va_end(params);
gpu_material_add_node(mat, node);
gpu_material_add_node(material, node);
return true;
}
@ -1877,6 +1989,11 @@ int GPU_link_changed(GPUNodeLink *link)
return 0;
}
GPUNodeLink *GPU_uniformbuffer_link_out(GPUMaterial *mat, bNode *node, GPUNodeStack *stack, const int index)
{
return gpu_uniformbuffer_link(mat, node, stack, index, SOCK_OUT);
}
/* Pass create/free */
static void gpu_nodes_tag(GPUNodeLink *link)
@ -1917,6 +2034,7 @@ static void gpu_nodes_prune(ListBase *nodes, GPUNodeLink *outlink)
}
GPUPass *GPU_generate_pass_new(
struct GPUMaterial *material,
ListBase *nodes, struct GPUNodeLink *frag_outlink,
GPUVertexAttribs *attribs,
const char *vert_code, const char *geom_code,
@ -1933,7 +2051,7 @@ GPUPass *GPU_generate_pass_new(
gpu_nodes_get_vertex_attributes(nodes, attribs);
/* generate code and compile with opengl */
fragmentgen = code_generate_fragment(nodes, frag_outlink->output, true);
fragmentgen = code_generate_fragment(material, nodes, frag_outlink->output, true);
vertexgen = code_generate_vertex_new(nodes, vert_code, (geom_code != NULL));
tmp = BLI_strdupcat(frag_lib, glsl_material_library);
@ -2012,7 +2130,7 @@ GPUPass *GPU_generate_pass(
gpu_nodes_get_builtin_flag(nodes, builtins);
/* generate code and compile with opengl */
fragmentcode = code_generate_fragment(nodes, outlink->output, false);
fragmentcode = code_generate_fragment(NULL, nodes, outlink->output, false);
vertexcode = code_generate_vertex(nodes, type);
geometrycode = code_generate_geometry(nodes, use_opensubdiv);

View File

@ -168,6 +168,7 @@ struct GPUPass {
typedef struct GPUPass GPUPass;
GPUPass *GPU_generate_pass_new(
struct GPUMaterial *material,
ListBase *nodes, struct GPUNodeLink *frag_outlink,
struct GPUVertexAttribs *attribs,
const char *vert_code, const char *geom_code,

View File

@ -64,6 +64,7 @@
#include "GPU_material.h"
#include "GPU_shader.h"
#include "GPU_texture.h"
#include "GPU_uniformbuffer.h"
#include "gpu_codegen.h"
#include "gpu_lamp_private.h"
@ -133,6 +134,7 @@ struct GPUMaterial {
bool bound;
bool is_opensubdiv;
GPUUniformBuffer *ubo; /* UBOs for shader uniforms. */
};
/* Forward declaration so shade_light_textures() can use this, while still keeping the code somewhat organized */
@ -250,6 +252,10 @@ void GPU_material_free(ListBase *gpumaterial)
if (material->pass)
GPU_pass_free(material->pass);
if (material->ubo != NULL) {
GPU_uniformbuffer_free(material->ubo);
}
BLI_freelistN(&material->lamps);
MEM_freeN(material);
@ -429,6 +435,30 @@ GPUPass *GPU_material_get_pass(GPUMaterial *material)
return material->pass;
}
GPUUniformBuffer *GPU_material_get_uniform_buffer(GPUMaterial *material)
{
return material->ubo;
}
/**
* Create dynamic UBO from parameters
* \param ListBase of BLI_genericNodeN(GPUInput)
*/
void GPU_material_create_uniform_buffer(GPUMaterial *material, ListBase *inputs)
{
material->ubo = GPU_uniformbuffer_dynamic_create(inputs, NULL);
}
void GPU_material_uniform_buffer_tag_dirty(ListBase *gpumaterials)
{
for (LinkData *link = gpumaterials->first; link; link = link->next) {
GPUMaterial *material = link->data;
if (material->ubo != NULL) {
GPU_uniformbuffer_tag_dirty(material->ubo);
}
}
}
void GPU_material_vertex_attributes(GPUMaterial *material, GPUVertexAttribs *attribs)
{
*attribs = material->attribs;
@ -2130,7 +2160,7 @@ GPUMaterial *GPU_material_from_nodetree(
if (mat->outlink) {
outlink = mat->outlink;
mat->pass = GPU_generate_pass_new(
&mat->nodes, outlink, &mat->attribs, vert_code, geom_code, frag_lib, defines);
mat, &mat->nodes, outlink, &mat->attribs, vert_code, geom_code, frag_lib, defines);
}
/* note that even if building the shader fails in some way, we still keep

View File

@ -29,23 +29,68 @@
* \ingroup gpu
*/
#include <string.h>
#include "MEM_guardedalloc.h"
#include "BLI_blenlib.h"
#include "gpu_codegen.h"
#include "GPU_extensions.h"
#include "GPU_glew.h"
#include "GPU_material.h"
#include "GPU_uniformbuffer.h"
struct GPUUniformBuffer {
typedef enum GPUUniformBufferFlag {
GPU_UBO_FLAG_INITIALIZED = (1 << 0),
GPU_UBO_FLAG_DIRTY = (1 << 1),
} GPUUniformBufferFlag;
typedef enum GPUUniformBufferType {
GPU_UBO_STATIC = 0,
GPU_UBO_DYNAMIC = 1,
} GPUUniformBufferType;
typedef struct GPUUniformBuffer {
int size; /* in bytes */
GLuint bindcode; /* opengl identifier for UBO */
int bindpoint; /* current binding point */
};
GPUUniformBufferType type;
} GPUUniformBuffer;
#define GPUUniformBufferStatic GPUUniformBuffer
typedef struct GPUUniformBufferDynamic {
GPUUniformBuffer buffer;
ListBase items; /* GPUUniformBufferDynamicItem */
void *data;
char flag;
} GPUUniformBufferDynamic;
typedef struct GPUUniformBufferDynamicItem {
struct GPUUniformBufferDynamicItem *next, *prev;
GPUType gputype;
float *data;
int size;
} GPUUniformBufferDynamicItem;
/* Prototypes */
static void gpu_uniformbuffer_inputs_sort(struct ListBase *inputs);
static GPUUniformBufferDynamicItem *gpu_uniformbuffer_populate(
GPUUniformBufferDynamic *ubo, const GPUType gputype, float *num);
static void gpu_uniformbuffer_initialize(GPUUniformBuffer *ubo, const void *data)
{
glBindBuffer(GL_UNIFORM_BUFFER, ubo->bindcode);
glBufferData(GL_UNIFORM_BUFFER, ubo->size, data, GL_DYNAMIC_DRAW);
glBindBuffer(GL_UNIFORM_BUFFER, 0);
}
GPUUniformBuffer *GPU_uniformbuffer_create(int size, const void *data, char err_out[256])
{
GPUUniformBuffer *ubo = MEM_callocN(sizeof(GPUUniformBuffer), "GPUUniformBuffer");
GPUUniformBuffer *ubo = MEM_callocN(sizeof(GPUUniformBufferStatic), "GPUUniformBufferStatic");
ubo->size = size;
/* Generate Buffer object */
@ -65,26 +110,164 @@ GPUUniformBuffer *GPU_uniformbuffer_create(int size, const void *data, char err_
return NULL;
}
glBindBuffer(GL_UNIFORM_BUFFER, ubo->bindcode);
glBufferData(GL_UNIFORM_BUFFER, ubo->size, data, GL_DYNAMIC_DRAW);
glBindBuffer(GL_UNIFORM_BUFFER, 0);
gpu_uniformbuffer_initialize(ubo, data);
return ubo;
}
/**
* Create dynamic UBO from parameters
* Return NULL if failed to create or if \param inputs is empty.
*
* \param inputs ListBase of BLI_genericNodeN(GPUInput)
*/
GPUUniformBuffer *GPU_uniformbuffer_dynamic_create(ListBase *inputs, char err_out[256])
{
/* There is no point on creating an UBO if there is no arguments. */
if (BLI_listbase_is_empty(inputs)) {
return NULL;
}
GPUUniformBufferDynamic *ubo = MEM_callocN(sizeof(GPUUniformBufferDynamic), "GPUUniformBufferDynamic");
ubo->buffer.type = GPU_UBO_DYNAMIC;
ubo->flag = GPU_UBO_FLAG_DIRTY;
/* Generate Buffer object. */
glGenBuffers(1, &ubo->buffer.bindcode);
if (!ubo->buffer.bindcode) {
if (err_out)
BLI_snprintf(err_out, 256, "GPUUniformBuffer: UBO create failed");
GPU_uniformbuffer_free(&ubo->buffer);
return NULL;
}
if (ubo->buffer.size > GPU_max_ubo_size()) {
if (err_out)
BLI_snprintf(err_out, 256, "GPUUniformBuffer: UBO too big");
GPU_uniformbuffer_free(&ubo->buffer);
return NULL;
}
/* Make sure we comply to the ubo alignment requirements. */
gpu_uniformbuffer_inputs_sort(inputs);
for (LinkData *link = inputs->first; link; link = link->next) {
GPUInput *input = link->data;
gpu_uniformbuffer_populate(ubo, input->type, input->dynamicvec);
}
ubo->data = MEM_mallocN(ubo->buffer.size, __func__);
/* Initialize buffer data. */
GPU_uniformbuffer_dynamic_update(&ubo->buffer);
return &ubo->buffer;
}
/**
* Free the data, and clean the items list.
*/
static void gpu_uniformbuffer_dynamic_reset(GPUUniformBufferDynamic *ubo)
{
ubo->buffer.size = 0;
if (ubo->data) {
MEM_freeN(ubo->data);
}
BLI_freelistN(&ubo->items);
}
void GPU_uniformbuffer_free(GPUUniformBuffer *ubo)
{
if (ubo->type == GPU_UBO_DYNAMIC) {
gpu_uniformbuffer_dynamic_reset((GPUUniformBufferDynamic *)ubo);
}
glDeleteBuffers(1, &ubo->bindcode);
MEM_freeN(ubo);
}
void GPU_uniformbuffer_update(GPUUniformBuffer *ubo, const void *data)
static void gpu_uniformbuffer_update(GPUUniformBuffer *ubo, const void *data)
{
glBindBuffer(GL_UNIFORM_BUFFER, ubo->bindcode);
glBufferSubData(GL_UNIFORM_BUFFER, 0, ubo->size, data);
glBindBuffer(GL_UNIFORM_BUFFER, 0);
}
void GPU_uniformbuffer_update(GPUUniformBuffer *ubo, const void *data)
{
BLI_assert(ubo->type == GPU_UBO_STATIC);
gpu_uniformbuffer_update(ubo, data);
}
/**
* We need to recalculate the internal data, and re-generate it
* from its populated items.
*/
void GPU_uniformbuffer_dynamic_update(GPUUniformBuffer *ubo_)
{
BLI_assert(ubo_->type == GPU_UBO_DYNAMIC);
GPUUniformBufferDynamic *ubo = (GPUUniformBufferDynamic *)ubo_;
float *offset = ubo->data;
for (GPUUniformBufferDynamicItem *item = ubo->items.first; item; item = item->next) {
memcpy(offset, item->data, item->size);
offset += item->gputype;
}
if (ubo->flag & GPU_UBO_FLAG_INITIALIZED) {
gpu_uniformbuffer_update(ubo_, ubo->data);
}
else {
ubo->flag |= GPU_UBO_FLAG_INITIALIZED;
gpu_uniformbuffer_initialize(ubo_, ubo->data);
}
ubo->flag &= ~GPU_UBO_FLAG_DIRTY;
}
/**
* Returns 1 if the first item shold be after second item.
* We make sure the vec4 uniforms come first.
*/
static int inputs_cmp(const void *a, const void *b)
{
const LinkData *link_a = a, *link_b = b;
const GPUInput *input_a = link_a->data, *input_b = link_b->data;
return input_a->type < input_b->type ? 1 : 0;
}
/**
* Make sure we respect the expected alignment of UBOs.
* vec4, pad vec3 as vec4, then vec2, then floats.
*/
static void gpu_uniformbuffer_inputs_sort(ListBase *inputs)
{
BLI_listbase_sort(inputs, inputs_cmp);
}
/**
* This may now happen from the main thread, so we can't update the UBO
* We simply flag it as dirty
*/
static GPUUniformBufferDynamicItem *gpu_uniformbuffer_populate(
GPUUniformBufferDynamic *ubo, const GPUType gputype, float *num)
{
BLI_assert(gputype <= GPU_VEC4);
GPUUniformBufferDynamicItem *item = MEM_callocN(sizeof(GPUUniformBufferDynamicItem), __func__);
/* Treat VEC3 as VEC4 because of UBO struct alignment requirements. */
GPUType type = gputype == GPU_VEC3 ? GPU_VEC4 : gputype;
item->gputype = type;
item->data = num;
item->size = type * sizeof(float);
ubo->buffer.size += item->size;
ubo->flag |= GPU_UBO_FLAG_DIRTY;
BLI_addtail(&ubo->items, item);
return item;
}
void GPU_uniformbuffer_bind(GPUUniformBuffer *ubo, int number)
{
if (number >= GPU_max_ubo_binds()) {
@ -92,6 +275,13 @@ void GPU_uniformbuffer_bind(GPUUniformBuffer *ubo, int number)
return;
}
if (ubo->type == GPU_UBO_DYNAMIC) {
GPUUniformBufferDynamic *ubo_dynamic = (GPUUniformBufferDynamic *)ubo;
if (ubo_dynamic->flag & GPU_UBO_FLAG_DIRTY) {
GPU_uniformbuffer_dynamic_update(ubo);
}
}
if (ubo->bindcode != 0) {
glBindBufferBase(GL_UNIFORM_BUFFER, number, ubo->bindcode);
}
@ -102,4 +292,10 @@ void GPU_uniformbuffer_bind(GPUUniformBuffer *ubo, int number)
int GPU_uniformbuffer_bindpoint(GPUUniformBuffer *ubo)
{
return ubo->bindpoint;
}
}
void GPU_uniformbuffer_tag_dirty(GPUUniformBuffer *ubo_) {
BLI_assert(ubo_->type == GPU_UBO_DYNAMIC);
GPUUniformBufferDynamic *ubo = (GPUUniformBufferDynamic *)ubo_;
ubo->flag |= GPU_UBO_FLAG_DIRTY;
}

View File

@ -180,6 +180,8 @@ static EnumPropertyItem node_sampler_type_items[] = {
#include "ED_node.h"
#include "ED_render.h"
#include "GPU_material.h"
#include "NOD_common.h"
#include "NOD_socket.h"
@ -2273,13 +2275,45 @@ static void rna_NodeSocketStandard_vector_range(PointerRNA *ptr, float *min, flo
*softmax = dval->max;
}
static void rna_NodeSocket_value_update(Main *bmain, Scene *scene, PointerRNA *ptr)
{
/* XXX: TODO (sergey/dalai) move this to depsgraph. */
bNodeTree *ntree = (bNodeTree *)ptr->id.data;
if (ntree->type == NTREE_SHADER) {
FOREACH_NODETREE(bmain, tntree, id) {
if (GS(id->name) == ID_WO) {
World *wo = (World *)id;
if ((BLI_listbase_is_empty(&wo->gpumaterial) == false) &&
ntreeHasTree(tntree, ntree))
{
wo->update_flag = 1;
GPU_material_uniform_buffer_tag_dirty(&wo->gpumaterial);
WM_main_add_notifier(NC_MATERIAL | ND_SHADING, NULL);
}
}
else if (GS(id->name) == ID_MA) {
Material *ma = (Material *)id;
if ((BLI_listbase_is_empty(&ma->gpumaterial) == false) &&
ntreeHasTree(tntree, ntree))
{
GPU_material_uniform_buffer_tag_dirty(&ma->gpumaterial);
WM_main_add_notifier(NC_MATERIAL | ND_SHADING, ma);
}
}
} FOREACH_NODETREE_END
}
else {
rna_NodeSocket_update(bmain, scene, ptr);
}
}
/* using a context update function here, to avoid searching the node if possible */
static void rna_NodeSocketStandard_value_update(struct bContext *C, PointerRNA *ptr)
{
bNode *node;
/* default update */
rna_NodeSocket_update(CTX_data_main(C), CTX_data_scene(C), ptr);
rna_NodeSocket_value_update(CTX_data_main(C), CTX_data_scene(C), ptr);
/* try to use node from context, faster */
node = CTX_data_pointer_get(C, "node").data;

View File

@ -78,6 +78,7 @@
#include "GPU_lamp.h"
#include "GPU_material.h"
#include "GPU_uniformbuffer.h"
int sh_node_poll_default(struct bNodeType *ntype, struct bNodeTree *ntree);

View File

@ -40,9 +40,9 @@ static bNodeSocketTemplate sh_node_add_shader_out[] = {
{ -1, 0, "" }
};
static int node_shader_gpu_add_shader(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static int node_shader_gpu_add_shader(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
return GPU_stack_link(mat, "node_add_shader", in, out);
return GPU_stack_link(mat, node, "node_add_shader", in, out);
}
/* node type definition */

View File

@ -39,9 +39,9 @@ static bNodeSocketTemplate sh_node_ambient_occlusion_out[] = {
{ -1, 0, "" }
};
static int node_shader_gpu_ambient_occlusion(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static int node_shader_gpu_ambient_occlusion(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
return GPU_stack_link(mat, "node_ambient_occlusion", in, out, GPU_builtin(GPU_VIEW_NORMAL));
return GPU_stack_link(mat, node, "node_ambient_occlusion", in, out, GPU_builtin(GPU_VIEW_NORMAL));
}
/* node type definition */

View File

@ -47,7 +47,7 @@ static int node_shader_gpu_attribute(GPUMaterial *mat, bNode *node, bNodeExecDat
NodeShaderAttribute *attr = node->storage;
GPUNodeLink *cd_attr = GPU_attribute(CD_AUTO_FROM_NAME, attr->name);
return GPU_stack_link(mat, "node_attribute", in, out, cd_attr);
return GPU_stack_link(mat, node, "node_attribute", in, out, cd_attr);
}
/* node type definition */

View File

@ -40,9 +40,9 @@ static bNodeSocketTemplate sh_node_background_out[] = {
{ -1, 0, "" }
};
static int node_shader_gpu_background(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static int node_shader_gpu_background(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
return GPU_stack_link(mat, "node_background", in, out);
return GPU_stack_link(mat, node, "node_background", in, out);
}
/* node type definition */

View File

@ -42,9 +42,9 @@ static bNodeSocketTemplate sh_node_brightcontrast_out[] = {
{ -1, 0, "" }
};
static int gpu_shader_brightcontrast(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static int gpu_shader_brightcontrast(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
return GPU_stack_link(mat, "brightness_contrast", in, out);
return GPU_stack_link(mat, node, "brightness_contrast", in, out);
}
void register_node_type_sh_brightcontrast(void)

View File

@ -49,12 +49,12 @@ static void node_shader_init_anisotropic(bNodeTree *UNUSED(ntree), bNode *node)
node->custom1 = SHD_GLOSSY_GGX;
}
static int node_shader_gpu_bsdf_anisotropic(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static int node_shader_gpu_bsdf_anisotropic(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
if (!in[4].link)
GPU_link(mat, "world_normals_get", &in[4].link);
return GPU_stack_link(mat, "node_bsdf_anisotropic", in, out);
return GPU_stack_link(mat, node, "node_bsdf_anisotropic", in, out);
}
/* node type definition */

View File

@ -41,12 +41,12 @@ static bNodeSocketTemplate sh_node_bsdf_diffuse_out[] = {
{ -1, 0, "" }
};
static int node_shader_gpu_bsdf_diffuse(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static int node_shader_gpu_bsdf_diffuse(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
if (!in[2].link)
GPU_link(mat, "world_normals_get", &in[2].link);
return GPU_stack_link(mat, "node_bsdf_diffuse", in, out);
return GPU_stack_link(mat, node, "node_bsdf_diffuse", in, out);
}
/* node type definition */

View File

@ -47,12 +47,12 @@ static void node_shader_init_glass(bNodeTree *UNUSED(ntree), bNode *node)
node->custom1 = SHD_GLOSSY_BECKMANN;
}
static int node_shader_gpu_bsdf_glass(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static int node_shader_gpu_bsdf_glass(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
if (!in[3].link)
GPU_link(mat, "world_normals_get", &in[3].link);
return GPU_stack_link(mat, "node_bsdf_glass", in, out);
return GPU_stack_link(mat, node, "node_bsdf_glass", in, out);
}
/* node type definition */

View File

@ -46,12 +46,12 @@ static void node_shader_init_glossy(bNodeTree *UNUSED(ntree), bNode *node)
node->custom1 = SHD_GLOSSY_GGX;
}
static int node_shader_gpu_bsdf_glossy(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static int node_shader_gpu_bsdf_glossy(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
if (!in[2].link)
GPU_link(mat, "world_normals_get", &in[2].link);
return GPU_stack_link(mat, "node_bsdf_glossy", in, out);
return GPU_stack_link(mat, node, "node_bsdf_glossy", in, out);
}
/* node type definition */

View File

@ -43,9 +43,9 @@ static bNodeSocketTemplate sh_node_bsdf_hair_out[] = {
{ -1, 0, "" }
};
static int node_shader_gpu_bsdf_hair(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static int node_shader_gpu_bsdf_hair(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
return GPU_stack_link(mat, "node_bsdf_hair", in, out);
return GPU_stack_link(mat, node, "node_bsdf_hair", in, out);
}
/* node type definition */

View File

@ -63,7 +63,7 @@ static void node_shader_init_principled(bNodeTree *UNUSED(ntree), bNode *node)
node->custom1 = SHD_GLOSSY_MULTI_GGX;
}
static int node_shader_gpu_bsdf_principled(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static int node_shader_gpu_bsdf_principled(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
#if 0 /* Old 2.7 glsl viewport */
// normal
@ -100,10 +100,10 @@ static int node_shader_gpu_bsdf_principled(GPUMaterial *mat, bNode *UNUSED(node)
/* Only use complex versions when needed. */
if (!in[12].link && (in[12].vec[0] == 0.0f)) {
return GPU_stack_link(mat, "node_bsdf_principled_simple", in, out, GPU_builtin(GPU_VIEW_POSITION));
return GPU_stack_link(mat, node, "node_bsdf_principled_simple", in, out, GPU_builtin(GPU_VIEW_POSITION));
}
else {
return GPU_stack_link(mat, "node_bsdf_principled_clearcoat", in, out, GPU_builtin(GPU_VIEW_POSITION));
return GPU_stack_link(mat, node, "node_bsdf_principled_clearcoat", in, out, GPU_builtin(GPU_VIEW_POSITION));
}
}

View File

@ -47,12 +47,12 @@ static void node_shader_init_refraction(bNodeTree *UNUSED(ntree), bNode *node)
node->custom1 = SHD_GLOSSY_BECKMANN;
}
static int node_shader_gpu_bsdf_refraction(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static int node_shader_gpu_bsdf_refraction(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
if (!in[3].link)
GPU_link(mat, "world_normals_get", &in[3].link);
return GPU_stack_link(mat, "node_bsdf_refraction", in, out);
return GPU_stack_link(mat, node, "node_bsdf_refraction", in, out);
}
/* node type definition */

View File

@ -42,14 +42,14 @@ static bNodeSocketTemplate sh_node_bsdf_toon_out[] = {
{ -1, 0, "" }
};
static int node_shader_gpu_bsdf_toon(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static int node_shader_gpu_bsdf_toon(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
if (!in[3].link)
in[3].link = GPU_builtin(GPU_VIEW_NORMAL);
else
GPU_link(mat, "direction_transform_m4v3", in[3].link, GPU_builtin(GPU_VIEW_MATRIX), &in[3].link);
return GPU_stack_link(mat, "node_bsdf_toon", in, out);
return GPU_stack_link(mat, node, "node_bsdf_toon", in, out);
}
/* node type definition */

View File

@ -40,12 +40,12 @@ static bNodeSocketTemplate sh_node_bsdf_translucent_out[] = {
{ -1, 0, "" }
};
static int node_shader_gpu_bsdf_translucent(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static int node_shader_gpu_bsdf_translucent(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
if (!in[1].link)
GPU_link(mat, "world_normals_get", &in[1].link);
return GPU_stack_link(mat, "node_bsdf_translucent", in, out);
return GPU_stack_link(mat, node, "node_bsdf_translucent", in, out);
}
/* node type definition */

View File

@ -39,9 +39,9 @@ static bNodeSocketTemplate sh_node_bsdf_transparent_out[] = {
{ -1, 0, "" }
};
static int node_shader_gpu_bsdf_transparent(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static int node_shader_gpu_bsdf_transparent(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
return GPU_stack_link(mat, "node_bsdf_transparent", in, out);
return GPU_stack_link(mat, node, "node_bsdf_transparent", in, out);
}
/* node type definition */

View File

@ -41,12 +41,12 @@ static bNodeSocketTemplate sh_node_bsdf_velvet_out[] = {
{ -1, 0, "" }
};
static int node_shader_gpu_bsdf_velvet(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static int node_shader_gpu_bsdf_velvet(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
if (!in[2].link)
GPU_link(mat, "world_normals_get", &in[2].link);
return GPU_stack_link(mat, "node_bsdf_velvet", in, out);
return GPU_stack_link(mat, node, "node_bsdf_velvet", in, out);
}
/* node type definition */

View File

@ -52,7 +52,7 @@ static int gpu_shader_bump(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(
else
GPU_link(mat, "direction_transform_m4v3", in[3].link, GPU_builtin(GPU_VIEW_MATRIX), &in[3].link);
float invert = node->custom1;
GPU_stack_link(mat, "node_bump", in, out, GPU_builtin(GPU_VIEW_POSITION), GPU_uniform(&invert));
GPU_stack_link(mat, node, "node_bump", in, out, GPU_builtin(GPU_VIEW_POSITION), GPU_uniform(&invert));
/* Other nodes are applying view matrix if the input Normal has a link.
* We don't want normal to have view matrix applied twice, so we cancel it here.
*

View File

@ -52,7 +52,7 @@ static void node_shader_exec_camera(void *data, int UNUSED(thread), bNode *UNUSE
}
}
static int gpu_shader_camera(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static int gpu_shader_camera(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
GPUNodeLink *viewvec;
@ -62,7 +62,7 @@ static int gpu_shader_camera(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecDat
if (GPU_material_use_new_shading_nodes(mat))
GPU_link(mat, "invert_z", viewvec, &viewvec);
return GPU_stack_link(mat, "camera", in, out, viewvec);
return GPU_stack_link(mat, node, "camera", in, out, viewvec);
}
void register_node_type_sh_camera(void)

View File

@ -66,7 +66,7 @@ static int gpu_shader_curve_vec(GPUMaterial *mat, bNode *node, bNodeExecData *UN
int size;
curvemapping_table_RGBA(node->storage, &array, &size);
return GPU_stack_link(mat, "curves_vec", in, out, GPU_texture(size, array));
return GPU_stack_link(mat, node, "curves_vec", in, out, GPU_texture(size, array));
}
void register_node_type_sh_curve_vec(void)
@ -125,7 +125,7 @@ static int gpu_shader_curve_rgb(GPUMaterial *mat, bNode *node, bNodeExecData *UN
curvemapping_initialize(node->storage);
curvemapping_table_RGBA(node->storage, &array, &size);
return GPU_stack_link(mat, "curves_rgb", in, out, GPU_texture(size, array));
return GPU_stack_link(mat, node, "curves_rgb", in, out, GPU_texture(size, array));
}
void register_node_type_sh_curve_rgb(void)

View File

@ -49,7 +49,7 @@ static bNodeSocketTemplate sh_node_eevee_metallic_out[] = {
{ -1, 0, "" }
};
static int node_shader_gpu_eevee_metallic(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static int node_shader_gpu_eevee_metallic(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
static float one = 1.0f;
@ -68,7 +68,7 @@ static int node_shader_gpu_eevee_metallic(GPUMaterial *mat, bNode *UNUSED(node),
GPU_link(mat, "set_value", GPU_uniform(&one), &in[10].link);
}
return GPU_stack_link(mat, "node_eevee_metallic", in, out);
return GPU_stack_link(mat, node, "node_eevee_metallic", in, out);
}

View File

@ -48,7 +48,7 @@ static bNodeSocketTemplate sh_node_eevee_specular_out[] = {
{ -1, 0, "" }
};
static int node_shader_gpu_eevee_specular(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static int node_shader_gpu_eevee_specular(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
static float one = 1.0f;
@ -67,7 +67,7 @@ static int node_shader_gpu_eevee_specular(GPUMaterial *mat, bNode *UNUSED(node),
GPU_link(mat, "set_value", GPU_uniform(&one), &in[9].link);
}
return GPU_stack_link(mat, "node_eevee_specular", in, out);
return GPU_stack_link(mat, node, "node_eevee_specular", in, out);
}

View File

@ -40,9 +40,9 @@ static bNodeSocketTemplate sh_node_emission_out[] = {
{ -1, 0, "" }
};
static int node_shader_gpu_emission(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static int node_shader_gpu_emission(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
return GPU_stack_link(mat, "node_emission", in, out, GPU_builtin(GPU_VIEW_NORMAL));
return GPU_stack_link(mat, node, "node_emission", in, out, GPU_builtin(GPU_VIEW_NORMAL));
}
/* node type definition */

View File

@ -39,7 +39,7 @@ static bNodeSocketTemplate sh_node_fresnel_out[] = {
{ -1, 0, "" }
};
static int node_shader_gpu_fresnel(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static int node_shader_gpu_fresnel(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
if (!in[1].link) {
in[1].link = GPU_builtin(GPU_VIEW_NORMAL);
@ -48,7 +48,7 @@ static int node_shader_gpu_fresnel(GPUMaterial *mat, bNode *UNUSED(node), bNodeE
GPU_link(mat, "direction_transform_m4v3", in[1].link, GPU_builtin(GPU_VIEW_MATRIX), &in[1].link);
}
return GPU_stack_link(mat, "node_fresnel", in, out, GPU_builtin(GPU_VIEW_POSITION));
return GPU_stack_link(mat, node, "node_fresnel", in, out, GPU_builtin(GPU_VIEW_POSITION));
}
static void node_shader_exec_fresnel(void *data, int UNUSED(thread), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), bNodeStack **in, bNodeStack **out)

View File

@ -52,9 +52,9 @@ static void node_shader_exec_gamma(void *UNUSED(data), int UNUSED(thread), bNode
out[0]->vec[2] = col[2] > 0.0f ? powf(col[2], gamma) : col[2];
}
static int node_shader_gpu_gamma(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static int node_shader_gpu_gamma(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
return GPU_stack_link(mat, "node_gamma", in, out);
return GPU_stack_link(mat, node, "node_gamma", in, out);
}
void register_node_type_sh_gamma(void)

View File

@ -136,7 +136,7 @@ static int gpu_shader_geom(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(
GPUNodeLink *mtface = GPU_attribute(CD_MTFACE, ngeo->uvname);
GPUNodeLink *mcol = GPU_attribute(CD_MCOL, ngeo->colname);
bool ret = GPU_stack_link(mat, "geom", in, out,
bool ret = GPU_stack_link(mat, node, "geom", in, out,
GPU_builtin(GPU_VIEW_POSITION), GPU_builtin(GPU_VIEW_NORMAL),
GPU_builtin(GPU_INVERSE_VIEW_MATRIX), orco, mtface, mcol);
if (GPU_material_use_world_space_shading(mat)) {

View File

@ -41,9 +41,9 @@ static bNodeSocketTemplate sh_node_geometry_out[] = {
{ -1, 0, "" }
};
static int node_shader_gpu_geometry(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static int node_shader_gpu_geometry(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
return GPU_stack_link(mat, "node_geometry", in, out,
return GPU_stack_link(mat, node, "node_geometry", in, out,
GPU_builtin(GPU_VIEW_POSITION), GPU_builtin(GPU_VIEW_NORMAL),
GPU_attribute(CD_ORCO, ""), GPU_builtin(GPU_OBJECT_MATRIX),
GPU_builtin(GPU_INVERSE_VIEW_MATRIX));

View File

@ -82,9 +82,9 @@ static void node_shader_exec_hue_sat(void *UNUSED(data), int UNUSED(thread), bNo
}
static int gpu_shader_hue_sat(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static int gpu_shader_hue_sat(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
return GPU_stack_link(mat, "hue_sat", in, out);
return GPU_stack_link(mat, node, "hue_sat", in, out);
}
void register_node_type_sh_hue_sat(void)

View File

@ -65,9 +65,9 @@ static void node_shader_exec_invert(void *UNUSED(data), int UNUSED(thread), bNod
copy_v3_v3(out[0]->vec, icol);
}
static int gpu_shader_invert(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static int gpu_shader_invert(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
return GPU_stack_link(mat, "invert", in, out);
return GPU_stack_link(mat, node, "invert", in, out);
}
void register_node_type_sh_invert(void)

View File

@ -68,7 +68,7 @@ static int gpu_shader_lamp(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(
visifac = GPU_lamp_get_data(mat, lamp, &col, &lv, &dist, &shadow, &energy);
bool ret = GPU_stack_link(mat, "lamp", in, out, col, energy, lv, dist, shadow, visifac);
bool ret = GPU_stack_link(mat, node, "lamp", in, out, col, energy, lv, dist, shadow, visifac);
if (GPU_material_use_world_space_shading(mat))
ret &= GPU_link(mat, "direction_transform_m4v3", out[1].link, GPU_builtin(GPU_INVERSE_VIEW_MATRIX), &out[1].link);
return ret;

View File

@ -41,7 +41,7 @@ static bNodeSocketTemplate sh_node_layer_weight_out[] = {
{ -1, 0, "" }
};
static int node_shader_gpu_layer_weight(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static int node_shader_gpu_layer_weight(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
if (!in[1].link)
in[1].link = GPU_builtin(GPU_VIEW_NORMAL);
@ -49,7 +49,7 @@ static int node_shader_gpu_layer_weight(GPUMaterial *mat, bNode *UNUSED(node), b
GPU_link(mat, "direction_transform_m4v3", in[1].link, GPU_builtin(GPU_VIEW_MATRIX), &in[1].link);
}
return GPU_stack_link(mat, "node_layer_weight", in, out, GPU_builtin(GPU_VIEW_POSITION));
return GPU_stack_link(mat, node, "node_layer_weight", in, out, GPU_builtin(GPU_VIEW_POSITION));
}
static void node_shader_exec_layer_weight(void *data, int UNUSED(thread), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), bNodeStack **in, bNodeStack **out)

View File

@ -44,9 +44,9 @@ static bNodeSocketTemplate sh_node_light_falloff_out[] = {
{ -1, 0, "" }
};
static int node_shader_gpu_light_falloff(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static int node_shader_gpu_light_falloff(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
return GPU_stack_link(mat, "node_light_falloff", in, out);
return GPU_stack_link(mat, node, "node_light_falloff", in, out);
}
/* node type definition */

View File

@ -46,9 +46,9 @@ static bNodeSocketTemplate sh_node_light_path_out[] = {
{ -1, 0, "" }
};
static int node_shader_gpu_light_path(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static int node_shader_gpu_light_path(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
return GPU_stack_link(mat, "node_light_path", in, out);
return GPU_stack_link(mat, node, "node_light_path", in, out);
}
/* node type definition */

View File

@ -94,7 +94,7 @@ static int gpu_shader_mapping(GPUMaterial *mat, bNode *node, bNodeExecData *UNUS
GPUNodeLink *tdomin = GPU_uniform(&domin);
GPUNodeLink *tdomax = GPU_uniform(&domax);
GPU_stack_link(mat, "mapping", in, out, tmat, tmin, tmax, tdomin, tdomax);
GPU_stack_link(mat, node, "mapping", in, out, tmat, tmin, tmax, tdomin, tdomax);
if (texmap->type == TEXMAP_TYPE_NORMAL)
GPU_link(mat, "texco_norm", out[0].link, &out[0].link);

View File

@ -249,7 +249,7 @@ static int gpu_shader_math(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(
case NODE_MATH_LESS:
case NODE_MATH_GREATER:
case NODE_MATH_MOD:
GPU_stack_link(mat, names[node->custom1], in, out);
GPU_stack_link(mat, node, names[node->custom1], in, out);
break;
case NODE_MATH_SIN:
case NODE_MATH_COS:
@ -264,14 +264,14 @@ static int gpu_shader_math(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(
GPUNodeStack tmp_in[2];
memcpy(&tmp_in[0], &in[0], sizeof(GPUNodeStack));
memcpy(&tmp_in[1], &in[2], sizeof(GPUNodeStack));
GPU_stack_link(mat, names[node->custom1], tmp_in, out);
GPU_stack_link(mat, node, names[node->custom1], tmp_in, out);
}
else {
/* use only second item and terminator */
GPUNodeStack tmp_in[2];
memcpy(&tmp_in[0], &in[1], sizeof(GPUNodeStack));
memcpy(&tmp_in[1], &in[2], sizeof(GPUNodeStack));
GPU_stack_link(mat, names[node->custom1], tmp_in, out);
GPU_stack_link(mat, node, names[node->custom1], tmp_in, out);
}
break;
default:

View File

@ -71,7 +71,8 @@ static int gpu_shader_mix_rgb(GPUMaterial *mat, bNode *node, bNodeExecData *UNUS
"mix_screen", "mix_div", "mix_diff", "mix_dark", "mix_light",
"mix_overlay", "mix_dodge", "mix_burn", "mix_hue", "mix_sat",
"mix_val", "mix_color", "mix_soft", "mix_linear"};
int ret = GPU_stack_link(mat, names[node->custom1], in, out);
int ret = GPU_stack_link(mat, node, names[node->custom1], in, out);
if (ret && node->custom2 & SHD_MIXRGB_CLAMP) {
float min[3] = {0.0f, 0.0f, 0.0f};
float max[3] = {1.0f, 1.0f, 1.0f};

View File

@ -41,9 +41,9 @@ static bNodeSocketTemplate sh_node_mix_shader_out[] = {
{ -1, 0, "" }
};
static int node_shader_gpu_mix_shader(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static int node_shader_gpu_mix_shader(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
return GPU_stack_link(mat, "node_mix_shader", in, out);
return GPU_stack_link(mat, node, "node_mix_shader", in, out);
}
/* node type definition */

View File

@ -58,14 +58,14 @@ static void node_shader_exec_normal(void *UNUSED(data), int UNUSED(thread), bNod
out[1]->vec[0] = -dot_v3v3(vec, out[0]->vec);
}
static int gpu_shader_normal(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static int gpu_shader_normal(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
GPUNodeLink *vec = GPU_uniform(out[0].vec);
if (GPU_material_use_new_shading_nodes(mat)) {
return GPU_stack_link(mat, "normal_new_shading", in, out, vec);
return GPU_stack_link(mat, node, "normal_new_shading", in, out, vec);
}
else {
return GPU_stack_link(mat, "normal", in, out, vec);
return GPU_stack_link(mat, node, "normal", in, out, vec);
}
}

View File

@ -37,9 +37,9 @@ static bNodeSocketTemplate sh_node_object_info_out[] = {
{ -1, 0, "" }
};
static int node_shader_gpu_object_info(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static int node_shader_gpu_object_info(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
return GPU_stack_link(mat, "node_object_info", in, out, GPU_builtin(GPU_OBJECT_MATRIX), GPU_builtin(GPU_OBJECT_INFO));
return GPU_stack_link(mat, node, "node_object_info", in, out, GPU_builtin(GPU_OBJECT_MATRIX), GPU_builtin(GPU_OBJECT_INFO));
}
static void node_shader_exec_object_info(void *data, int UNUSED(thread), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), bNodeStack **UNUSED(in), bNodeStack **out)

View File

@ -67,7 +67,7 @@ static void node_shader_exec_output(void *data, int UNUSED(thread), bNode *node,
}
}
static int gpu_shader_output(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static int gpu_shader_output(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
GPUNodeLink *outlink;
@ -80,7 +80,7 @@ static int gpu_shader_output(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecDat
return false;
}
GPU_stack_link(mat, "output_node", in, out, &outlink);
GPU_stack_link(mat, node, "output_node", in, out, &outlink);
GPU_material_output_link(mat, outlink);
return 1;

View File

@ -36,11 +36,11 @@ static bNodeSocketTemplate sh_node_output_eevee_material_in[] = {
{ -1, 0, "" }
};
static int node_shader_gpu_output_eevee_material(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static int node_shader_gpu_output_eevee_material(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
GPUNodeLink *outlink;
GPU_stack_link(mat, "node_output_eevee_material", in, out, &outlink);
GPU_stack_link(mat, node, "node_output_eevee_material", in, out, &outlink);
GPU_material_output_link(mat, outlink);
return true;

View File

@ -38,7 +38,7 @@ static bNodeSocketTemplate sh_node_output_material_in[] = {
{ -1, 0, "" }
};
static int node_shader_gpu_output_material(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static int node_shader_gpu_output_material(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
GPUNodeLink *outlink;
@ -46,7 +46,7 @@ static int node_shader_gpu_output_material(GPUMaterial *mat, bNode *UNUSED(node)
return false;
}
GPU_stack_link(mat, "node_output_material", in, out, &outlink);
GPU_stack_link(mat, node, "node_output_material", in, out, &outlink);
GPU_material_output_link(mat, outlink);
return true;

View File

@ -35,11 +35,11 @@ static bNodeSocketTemplate sh_node_output_world_in[] = {
{ -1, 0, "" }
};
static int node_shader_gpu_output_world(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static int node_shader_gpu_output_world(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
GPUNodeLink *outlink;
GPU_stack_link(mat, "node_output_world", in, out, &outlink);
GPU_stack_link(mat, node, "node_output_world", in, out, &outlink);
GPU_material_output_link(mat, outlink);
return true;

View File

@ -48,10 +48,10 @@ static void node_shader_exec_particle_info(void *data, int UNUSED(thread), bNode
RE_instance_get_particle_info(shi->obi, out[0]->vec, out[1]->vec, out[2]->vec, out[3]->vec, out[4]->vec, out[5]->vec, out[6]->vec);
}
static int gpu_shader_particle_info(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static int gpu_shader_particle_info(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
return GPU_stack_link(mat, "particle_info", in, out,
return GPU_stack_link(mat, node, "particle_info", in, out,
GPU_builtin(GPU_PARTICLE_SCALAR_PROPS),
GPU_builtin(GPU_PARTICLE_LOCATION),
GPU_builtin(GPU_PARTICLE_VELOCITY),

View File

@ -38,10 +38,10 @@ static bNodeSocketTemplate sh_node_rgb_out[] = {
{ -1, 0, "" }
};
static int gpu_shader_rgb(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static int gpu_shader_rgb(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
GPUNodeLink *vec = GPU_uniform(out[0].vec);
return GPU_stack_link(mat, "set_rgba", in, out, vec);
GPUNodeLink *link = GPU_uniformbuffer_link_out(mat, node, out, 0);
return GPU_stack_link(mat, node, "set_rgba", in, out, link);
}
void register_node_type_sh_rgb(void)

View File

@ -53,9 +53,9 @@ static void node_shader_exec_sephsv(void *UNUSED(data), int UNUSED(thread), bNod
&out[0]->vec[0], &out[1]->vec[0], &out[2]->vec[0]);
}
static int gpu_shader_sephsv(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static int gpu_shader_sephsv(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
return GPU_stack_link(mat, "separate_hsv", in, out);
return GPU_stack_link(mat, node, "separate_hsv", in, out);
}
void register_node_type_sh_sephsv(void)
@ -94,9 +94,9 @@ static void node_shader_exec_combhsv(void *UNUSED(data), int UNUSED(thread), bNo
hsv_to_rgb(h, s, v, &out[0]->vec[0], &out[0]->vec[1], &out[0]->vec[2]);
}
static int gpu_shader_combhsv(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static int gpu_shader_combhsv(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
return GPU_stack_link(mat, "combine_hsv", in, out);
return GPU_stack_link(mat, node, "combine_hsv", in, out);
}
void register_node_type_sh_combhsv(void)

View File

@ -54,9 +54,9 @@ static void node_shader_exec_seprgb(void *UNUSED(data), int UNUSED(thread), bNod
out[2]->vec[0] = col[2];
}
static int gpu_shader_seprgb(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static int gpu_shader_seprgb(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
return GPU_stack_link(mat, "separate_rgb", in, out);
return GPU_stack_link(mat, node, "separate_rgb", in, out);
}
void register_node_type_sh_seprgb(void)
@ -98,9 +98,9 @@ static void node_shader_exec_combrgb(void *UNUSED(data), int UNUSED(thread), bNo
out[0]->vec[2] = b;
}
static int gpu_shader_combrgb(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static int gpu_shader_combrgb(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
return GPU_stack_link(mat, "combine_rgb", in, out);
return GPU_stack_link(mat, node, "combine_rgb", in, out);
}
void register_node_type_sh_combrgb(void)

View File

@ -44,9 +44,9 @@ static bNodeSocketTemplate sh_node_sepxyz_out[] = {
{ -1, 0, "" }
};
static int gpu_shader_sepxyz(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static int gpu_shader_sepxyz(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
return GPU_stack_link(mat, "separate_xyz", in, out);
return GPU_stack_link(mat, node, "separate_xyz", in, out);
}
void register_node_type_sh_sepxyz(void)
@ -75,9 +75,9 @@ static bNodeSocketTemplate sh_node_combxyz_out[] = {
{ -1, 0, "" }
};
static int gpu_shader_combxyz(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static int gpu_shader_combxyz(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
return GPU_stack_link(mat, "combine_xyz", in, out);
return GPU_stack_link(mat, node, "combine_xyz", in, out);
}
void register_node_type_sh_combxyz(void)

View File

@ -56,9 +56,9 @@ static void node_shader_exec_squeeze(void *UNUSED(data), int UNUSED(thread), bNo
out[0]->vec[0] = 1.0f / (1.0f + powf(M_E, -((vec[0] - vec[2]) * vec[1])));
}
static int gpu_shader_squeeze(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static int gpu_shader_squeeze(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
return GPU_stack_link(mat, "squeeze", in, out);
return GPU_stack_link(mat, node, "squeeze", in, out);
}
void register_node_type_sh_squeeze(void)

View File

@ -49,12 +49,12 @@ static void node_shader_init_subsurface_scattering(bNodeTree *UNUSED(ntree), bNo
node->custom1 = SHD_SUBSURFACE_BURLEY;
}
static int node_shader_gpu_subsurface_scattering(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static int node_shader_gpu_subsurface_scattering(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
if (!in[5].link)
GPU_link(mat, "world_normals_get", &in[5].link);
return GPU_stack_link(mat, "node_subsurface_scattering", in, out);
return GPU_stack_link(mat, node, "node_subsurface_scattering", in, out);
}
static void node_shader_update_subsurface_scattering(bNodeTree *UNUSED(ntree), bNode *node)

View File

@ -46,7 +46,7 @@ static int node_shader_gpu_tangent(GPUMaterial *mat, bNode *node, bNodeExecData
NodeShaderTangent *attr = node->storage;
if (attr->direction_type == SHD_TANGENT_UVMAP) {
return GPU_stack_link(mat, "node_tangentmap", in, out, GPU_attribute(CD_TANGENT, ""), GPU_builtin(GPU_INVERSE_VIEW_MATRIX));
return GPU_stack_link(mat, node, "node_tangentmap", in, out, GPU_attribute(CD_TANGENT, ""), GPU_builtin(GPU_INVERSE_VIEW_MATRIX));
}
else {
GPUNodeLink *orco = GPU_attribute(CD_ORCO, "");
@ -58,7 +58,7 @@ static int node_shader_gpu_tangent(GPUMaterial *mat, bNode *node, bNodeExecData
else
GPU_link(mat, "tangent_orco_z", orco, &orco);
return GPU_stack_link(mat, "node_tangent", in, out, GPU_builtin(GPU_VIEW_NORMAL), orco,
return GPU_stack_link(mat, node, "node_tangent", in, out, GPU_builtin(GPU_VIEW_NORMAL), orco,
GPU_builtin(GPU_OBJECT_MATRIX), GPU_builtin(GPU_INVERSE_VIEW_MATRIX));
}
}

View File

@ -80,7 +80,7 @@ static int node_shader_gpu_tex_brick(GPUMaterial *mat, bNode *node, bNodeExecDat
NodeTexBrick *tex = (NodeTexBrick *)node->storage;
float offset_freq = tex->offset_freq;
float squash_freq = tex->squash_freq;
return GPU_stack_link(mat, "node_tex_brick",
return GPU_stack_link(mat, node, "node_tex_brick",
in, out,
GPU_uniform(&tex->offset), GPU_uniform(&offset_freq),
GPU_uniform(&tex->squash), GPU_uniform(&squash_freq));

View File

@ -61,7 +61,7 @@ static int node_shader_gpu_tex_checker(GPUMaterial *mat, bNode *node, bNodeExecD
node_shader_gpu_tex_mapping(mat, node, in, out);
return GPU_stack_link(mat, "node_tex_checker", in, out);
return GPU_stack_link(mat, node, "node_tex_checker", in, out);
}
/* node type definition */

View File

@ -42,20 +42,20 @@ static bNodeSocketTemplate sh_node_tex_coord_out[] = {
{ -1, 0, "" }
};
static int node_shader_gpu_tex_coord(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static int node_shader_gpu_tex_coord(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
GPUNodeLink *orco = GPU_attribute(CD_ORCO, "");
GPUNodeLink *mtface = GPU_attribute(CD_MTFACE, "");
GPUMatType type = GPU_Material_get_type(mat);
if (type == GPU_MATERIAL_TYPE_WORLD) {
return GPU_stack_link(mat, "node_tex_coord_background", in, out,
return GPU_stack_link(mat, node, "node_tex_coord_background", in, out,
GPU_builtin(GPU_VIEW_POSITION), GPU_builtin(GPU_VIEW_NORMAL),
GPU_builtin(GPU_INVERSE_VIEW_MATRIX), GPU_builtin(GPU_INVERSE_OBJECT_MATRIX),
GPU_builtin(GPU_CAMERA_TEXCO_FACTORS), orco, mtface);
}
else {
return GPU_stack_link(mat, "node_tex_coord", in, out,
return GPU_stack_link(mat, node, "node_tex_coord", in, out,
GPU_builtin(GPU_VIEW_POSITION), GPU_builtin(GPU_VIEW_NORMAL),
GPU_builtin(GPU_INVERSE_VIEW_MATRIX), GPU_builtin(GPU_INVERSE_OBJECT_MATRIX),
GPU_builtin(GPU_CAMERA_TEXCO_FACTORS), orco, mtface);

View File

@ -62,7 +62,7 @@ static int node_shader_gpu_tex_environment(GPUMaterial *mat, bNode *node, bNodeE
int isdata = tex->color_space == SHD_COLORSPACE_NONE;
if (!ima)
return GPU_stack_link(mat, "node_tex_environment_empty", in, out);
return GPU_stack_link(mat, node, "node_tex_environment_empty", in, out);
if (!in[0].link) {
GPUMatType type = GPU_Material_get_type(mat);
@ -76,9 +76,9 @@ static int node_shader_gpu_tex_environment(GPUMaterial *mat, bNode *node, bNodeE
node_shader_gpu_tex_mapping(mat, node, in, out);
if (tex->projection == SHD_PROJ_EQUIRECTANGULAR)
GPU_stack_link(mat, "node_tex_environment_equirectangular", in, out, GPU_image(ima, iuser, isdata));
GPU_stack_link(mat, node, "node_tex_environment_equirectangular", in, out, GPU_image(ima, iuser, isdata));
else
GPU_stack_link(mat, "node_tex_environment_mirror_ball", in, out, GPU_image(ima, iuser, isdata));
GPU_stack_link(mat, node, "node_tex_environment_mirror_ball", in, out, GPU_image(ima, iuser, isdata));
ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, NULL);
if (ibuf && (ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA) == 0 &&

View File

@ -61,7 +61,7 @@ static int node_shader_gpu_tex_gradient(GPUMaterial *mat, bNode *node, bNodeExec
NodeTexGradient *tex = (NodeTexGradient *)node->storage;
float gradient_type = tex->gradient_type;
return GPU_stack_link(mat, "node_tex_gradient", in, out, GPU_uniform(&gradient_type));
return GPU_stack_link(mat, node, "node_tex_gradient", in, out, GPU_uniform(&gradient_type));
}
/* node type definition */

View File

@ -66,7 +66,7 @@ static int node_shader_gpu_tex_image(GPUMaterial *mat, bNode *node, bNodeExecDat
float blend = tex->projection_blend;
if (!ima)
return GPU_stack_link(mat, "node_tex_image_empty", in, out);
return GPU_stack_link(mat, node, "node_tex_image_empty", in, out);
if (!in[0].link)
in[0].link = GPU_attribute(CD_MTFACE, "");
@ -75,7 +75,7 @@ static int node_shader_gpu_tex_image(GPUMaterial *mat, bNode *node, bNodeExecDat
switch (tex->projection) {
case SHD_PROJ_FLAT:
GPU_stack_link(mat, "node_tex_image", in, out, GPU_image(ima, iuser, isdata));
GPU_stack_link(mat, node, "node_tex_image", in, out, GPU_image(ima, iuser, isdata));
break;
case SHD_PROJ_BOX:
GPU_link(mat, "direction_transform_m4v3", GPU_builtin(GPU_VIEW_NORMAL),
@ -94,12 +94,12 @@ static int node_shader_gpu_tex_image(GPUMaterial *mat, bNode *node, bNodeExecDat
case SHD_PROJ_SPHERE:
GPU_link(mat, "point_texco_remap_square", in[0].link, &in[0].link);
GPU_link(mat, "point_map_to_sphere", in[0].link, &in[0].link);
GPU_stack_link(mat, "node_tex_image", in, out, GPU_image(ima, iuser, isdata));
GPU_stack_link(mat, node, "node_tex_image", in, out, GPU_image(ima, iuser, isdata));
break;
case SHD_PROJ_TUBE:
GPU_link(mat, "point_texco_remap_square", in[0].link, &in[0].link);
GPU_link(mat, "point_map_to_tube", in[0].link, &in[0].link);
GPU_stack_link(mat, "node_tex_image", in, out, GPU_image(ima, iuser, isdata));
GPU_stack_link(mat, node, "node_tex_image", in, out, GPU_image(ima, iuser, isdata));
break;
}

View File

@ -64,7 +64,7 @@ static int node_shader_gpu_tex_magic(GPUMaterial *mat, bNode *node, bNodeExecDat
node_shader_gpu_tex_mapping(mat, node, in, out);
return GPU_stack_link(mat, "node_tex_magic", in, out, GPU_uniform(&depth));
return GPU_stack_link(mat, node, "node_tex_magic", in, out, GPU_uniform(&depth));
}
/* node type definition */

View File

@ -68,7 +68,7 @@ static int node_shader_gpu_tex_musgrave(GPUMaterial *mat, bNode *node, bNodeExec
NodeTexMusgrave *tex = (NodeTexMusgrave *)node->storage;
float type = tex->musgrave_type;
return GPU_stack_link(mat, "node_tex_musgrave", in, out, GPU_uniform(&type));
return GPU_stack_link(mat, node, "node_tex_musgrave", in, out, GPU_uniform(&type));
}
/* node type definition */

View File

@ -61,7 +61,7 @@ static int node_shader_gpu_tex_noise(GPUMaterial *mat, bNode *node, bNodeExecDat
node_shader_gpu_tex_mapping(mat, node, in, out);
return GPU_stack_link(mat, "node_tex_noise", in, out);
return GPU_stack_link(mat, node, "node_tex_noise", in, out);
}
/* node type definition */

View File

@ -61,7 +61,7 @@ static int node_shader_gpu_tex_sky(GPUMaterial *mat, bNode *node, bNodeExecData
node_shader_gpu_tex_mapping(mat, node, in, out);
return GPU_stack_link(mat, "node_tex_sky", in, out);
return GPU_stack_link(mat, node, "node_tex_sky", in, out);
}
/* node type definition */

View File

@ -63,7 +63,7 @@ static int node_shader_gpu_tex_voronoi(GPUMaterial *mat, bNode *node, bNodeExecD
NodeTexVoronoi *tex = (NodeTexVoronoi *)node->storage;
float coloring = tex->coloring;
return GPU_stack_link(mat, "node_tex_voronoi", in, out, GPU_uniform(&coloring));
return GPU_stack_link(mat, node, "node_tex_voronoi", in, out, GPU_uniform(&coloring));
}
/* node type definition */

View File

@ -67,7 +67,7 @@ static int node_shader_gpu_tex_wave(GPUMaterial *mat, bNode *node, bNodeExecData
float wave_type = tex->wave_type;
float wave_profile = tex->wave_profile;
return GPU_stack_link(mat, "node_tex_wave", in, out, GPU_uniform(&wave_type), GPU_uniform(&wave_profile));
return GPU_stack_link(mat, node, "node_tex_wave", in, out, GPU_uniform(&wave_type), GPU_uniform(&wave_profile));
}
/* node type definition */

View File

@ -126,7 +126,7 @@ static int gpu_shader_texture(GPUMaterial *mat, bNode *node, bNodeExecData *UNUS
if (tex && tex->ima && (tex->type == TEX_IMAGE || tex->type == TEX_ENVMAP)) {
if (tex->type == TEX_IMAGE) {
GPUNodeLink *texlink = GPU_image(tex->ima, &tex->iuser, false);
GPU_stack_link(mat, "texture_image", in, out, texlink);
GPU_stack_link(mat, node, "texture_image", in, out, texlink);
}
else { /* TEX_ENVMAP */
if (!in[0].link)

View File

@ -47,7 +47,7 @@ static int node_shader_gpu_uvmap(GPUMaterial *mat, bNode *node, bNodeExecData *U
NodeShaderUVMap *attr = node->storage;
GPUNodeLink *mtface = GPU_attribute(CD_MTFACE, attr->uv_map);
return GPU_stack_link(mat, "node_uvmap", in, out, mtface);
return GPU_stack_link(mat, node, "node_uvmap", in, out, mtface);
}
/* node type definition */

View File

@ -69,7 +69,7 @@ static int gpu_shader_valtorgb(GPUMaterial *mat, bNode *node, bNodeExecData *UNU
int size;
colorband_table_RGBA(node->storage, &array, &size);
return GPU_stack_link(mat, "valtorgb", in, out, GPU_texture(size, array));
return GPU_stack_link(mat, node, "valtorgb", in, out, GPU_texture(size, array));
}
void register_node_type_sh_valtorgb(void)
@ -110,9 +110,9 @@ static void node_shader_exec_rgbtobw(void *UNUSED(data), int UNUSED(thread), bNo
out[0]->vec[0] = IMB_colormanagement_get_luminance(col);
}
static int gpu_shader_rgbtobw(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static int gpu_shader_rgbtobw(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
return GPU_stack_link(mat, "rgbtobw", in, out);
return GPU_stack_link(mat, node, "rgbtobw", in, out);
}
void register_node_type_sh_rgbtobw(void)

View File

@ -38,10 +38,10 @@ static bNodeSocketTemplate sh_node_value_out[] = {
{ -1, 0, "" }
};
static int gpu_shader_value(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static int gpu_shader_value(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
GPUNodeLink *vec = GPU_uniform(out[0].vec);
return GPU_stack_link(mat, "set_value", in, out, vec);
GPUNodeLink *link = GPU_uniformbuffer_link_out(mat, node, out, 0);
return GPU_stack_link(mat, node, "set_value", in, out, link);
}
void register_node_type_sh_value(void)

View File

@ -111,7 +111,7 @@ static int gpu_shader_vect_math(GPUMaterial *mat, bNode *node, bNodeExecData *UN
case 2:
case 3:
case 4:
GPU_stack_link(mat, names[node->custom1], in, out);
GPU_stack_link(mat, node, names[node->custom1], in, out);
break;
case 5:
if (in[0].hasinput || !in[1].hasinput) {
@ -119,14 +119,14 @@ static int gpu_shader_vect_math(GPUMaterial *mat, bNode *node, bNodeExecData *UN
GPUNodeStack tmp_in[2];
memcpy(&tmp_in[0], &in[0], sizeof(GPUNodeStack));
memcpy(&tmp_in[1], &in[2], sizeof(GPUNodeStack));
GPU_stack_link(mat, names[node->custom1], tmp_in, out);
GPU_stack_link(mat, node, names[node->custom1], tmp_in, out);
}
else {
/* use only second item and terminator */
GPUNodeStack tmp_in[2];
memcpy(&tmp_in[0], &in[1], sizeof(GPUNodeStack));
memcpy(&tmp_in[1], &in[2], sizeof(GPUNodeStack));
GPU_stack_link(mat, names[node->custom1], tmp_in, out);
GPU_stack_link(mat, node, names[node->custom1], tmp_in, out);
}
break;
default:

View File

@ -40,9 +40,9 @@ static bNodeSocketTemplate sh_node_volume_absorption_out[] = {
{ -1, 0, "" }
};
static int node_shader_gpu_volume_absorption(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static int node_shader_gpu_volume_absorption(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
return GPU_stack_link(mat, "node_volume_absorption", in, out);
return GPU_stack_link(mat, node, "node_volume_absorption", in, out);
}
/* node type definition */

View File

@ -41,9 +41,9 @@ static bNodeSocketTemplate sh_node_volume_scatter_out[] = {
{ -1, 0, "" }
};
static int node_shader_gpu_volume_scatter(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static int node_shader_gpu_volume_scatter(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
return GPU_stack_link(mat, "node_volume_scatter", in, out);
return GPU_stack_link(mat, node, "node_volume_scatter", in, out);
}
/* node type definition */