Blender V4.5
vertex_color.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#pragma once
6
9#include "kernel/svm/util.h"
10#include "util/math_base.h"
11
13
15 ccl_private ShaderData *sd,
16 ccl_private float *stack,
17 const uint4 node)
18{
19 uint layer_id;
20 uint color_offset;
21 uint alpha_offset;
22 svm_unpack_node_uchar3(node.y, &layer_id, &color_offset, &alpha_offset);
23
24 const AttributeDescriptor descriptor = find_attribute(kg, sd, layer_id);
25 if (descriptor.offset != ATTR_STD_NOT_FOUND) {
28 kg, sd, descriptor, nullptr, nullptr);
29 stack_store_float3(stack, color_offset, make_float3(vertex_color));
30 stack_store_float(stack, alpha_offset, vertex_color.w);
31 }
32 else {
34 kg, sd, descriptor, nullptr, nullptr);
35 stack_store_float3(stack, color_offset, vertex_color);
36 stack_store_float(stack, alpha_offset, 1.0f);
37 }
38 }
39 else {
40 stack_store_float3(stack, color_offset, make_float3(0.0f, 0.0f, 0.0f));
41 stack_store_float(stack, alpha_offset, 0.0f);
42 }
43}
44
46 ccl_private ShaderData *sd,
47 ccl_private float *stack,
48 const uint4 node)
49{
50 uint layer_id;
51 uint color_offset;
52 uint alpha_offset;
53 svm_unpack_node_uchar3(node.y, &layer_id, &color_offset, &alpha_offset);
54 const float bump_filter_width = __uint_as_float(node.z);
55
56 const AttributeDescriptor descriptor = find_attribute(kg, sd, layer_id);
57 if (descriptor.offset != ATTR_STD_NOT_FOUND) {
59 float4 dfdx;
61 kg, sd, descriptor, &dfdx, nullptr);
62 vertex_color += dfdx * bump_filter_width;
63 stack_store_float3(stack, color_offset, make_float3(vertex_color));
64 stack_store_float(stack, alpha_offset, vertex_color.w);
65 }
66 else {
67 float3 dfdx;
69 kg, sd, descriptor, &dfdx, nullptr);
70 vertex_color += dfdx * bump_filter_width;
71 stack_store_float3(stack, color_offset, vertex_color);
72 stack_store_float(stack, alpha_offset, 1.0f);
73 }
74 }
75 else {
76 stack_store_float3(stack, color_offset, make_float3(0.0f, 0.0f, 0.0f));
77 stack_store_float(stack, alpha_offset, 0.0f);
78 }
79}
80
82 ccl_private ShaderData *sd,
83 ccl_private float *stack,
84 const uint4 node)
85{
86 uint layer_id;
87 uint color_offset;
88 uint alpha_offset;
89 svm_unpack_node_uchar3(node.y, &layer_id, &color_offset, &alpha_offset);
90 const float bump_filter_width = __uint_as_float(node.z);
91
92 const AttributeDescriptor descriptor = find_attribute(kg, sd, layer_id);
93 if (descriptor.offset != ATTR_STD_NOT_FOUND) {
95 float4 dfdy;
97 kg, sd, descriptor, nullptr, &dfdy);
98 vertex_color += dfdy * bump_filter_width;
99 stack_store_float3(stack, color_offset, make_float3(vertex_color));
100 stack_store_float(stack, alpha_offset, vertex_color.w);
101 }
102 else {
103 float3 dfdy;
105 kg, sd, descriptor, nullptr, &dfdy);
106 vertex_color += dfdy * bump_filter_width;
107 stack_store_float3(stack, color_offset, vertex_color);
108 stack_store_float(stack, alpha_offset, 1.0f);
109 }
110 }
111 else {
112 stack_store_float3(stack, color_offset, make_float3(0.0f, 0.0f, 0.0f));
113 stack_store_float(stack, alpha_offset, 0.0f);
114 }
115}
116
unsigned int uint
ccl_device_inline void stack_store_float(ccl_private float *stack, const uint a, const float f)
ccl_device_inline void stack_store_float3(ccl_private float *stack, const uint a, const float3 f)
ccl_device_forceinline void svm_unpack_node_uchar3(const uint i, ccl_private uint *x, ccl_private uint *y, ccl_private uint *z)
#define ccl_private
const ThreadKernelGlobalsCPU * KernelGlobals
#define ccl_device_noinline
#define CCL_NAMESPACE_END
ccl_device_forceinline float3 make_float3(const float x, const float y, const float z)
#define __uint_as_float(x)
VecBase< float, 4 > float4
@ NODE_ATTR_RGBA
@ NODE_ATTR_FLOAT4
@ ATTR_STD_NOT_FOUND
descriptor
CCL_NAMESPACE_BEGIN ccl_device_forceinline T primitive_surface_attribute(KernelGlobals kg, const ccl_private ShaderData *sd, const AttributeDescriptor desc, ccl_private T *dfdx, ccl_private T *dfdy)
Definition primitive.h:32
static bool find_attribute(const std::string &attributes, const char *search_attribute)
uint y
Definition types_uint4.h:13
uint z
Definition types_uint4.h:13
ccl_device_noinline void svm_node_vertex_color_bump_dx(KernelGlobals kg, ccl_private ShaderData *sd, ccl_private float *stack, const uint4 node)
ccl_device_noinline void svm_node_vertex_color_bump_dy(KernelGlobals kg, ccl_private ShaderData *sd, ccl_private float *stack, const uint4 node)
CCL_NAMESPACE_BEGIN ccl_device_noinline void svm_node_vertex_color(KernelGlobals kg, ccl_private ShaderData *sd, ccl_private float *stack, const uint4 node)