Blender V5.0
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) {
27 const float4 vertex_color = primitive_surface_attribute<float4>(kg, sd, descriptor).val;
28 stack_store_float3(stack, color_offset, make_float3(vertex_color));
29 stack_store_float(stack, alpha_offset, vertex_color.w);
30 }
31 else {
32 const float3 vertex_color = primitive_surface_attribute<float3>(kg, sd, descriptor).val;
33 stack_store_float3(stack, color_offset, vertex_color);
34 stack_store_float(stack, alpha_offset, 1.0f);
35 }
36 }
37 else {
38 stack_store_float3(stack, color_offset, make_float3(0.0f, 0.0f, 0.0f));
39 stack_store_float(stack, alpha_offset, 0.0f);
40 }
41}
42
44 ccl_private ShaderData *sd,
45 ccl_private float *stack,
46 const uint4 node)
47{
48 uint layer_id;
49 uint color_offset;
50 uint alpha_offset;
51 svm_unpack_node_uchar3(node.y, &layer_id, &color_offset, &alpha_offset);
52 const float bump_filter_width = __uint_as_float(node.z);
53
54 const AttributeDescriptor descriptor = find_attribute(kg, sd, layer_id);
55 if (descriptor.offset != ATTR_STD_NOT_FOUND) {
57 dual4 vertex_color = primitive_surface_attribute<float4>(kg, sd, descriptor, true, false);
58 vertex_color.val += vertex_color.dx * bump_filter_width;
59 stack_store_float3(stack, color_offset, make_float3(vertex_color.val));
60 stack_store_float(stack, alpha_offset, vertex_color.val.w);
61 }
62 else {
63 dual3 vertex_color = primitive_surface_attribute<float3>(kg, sd, descriptor, true, false);
64 vertex_color.val += vertex_color.dx * bump_filter_width;
65 stack_store_float3(stack, color_offset, vertex_color.val);
66 stack_store_float(stack, alpha_offset, 1.0f);
67 }
68 }
69 else {
70 stack_store_float3(stack, color_offset, make_float3(0.0f, 0.0f, 0.0f));
71 stack_store_float(stack, alpha_offset, 0.0f);
72 }
73}
74
76 ccl_private ShaderData *sd,
77 ccl_private float *stack,
78 const uint4 node)
79{
80 uint layer_id;
81 uint color_offset;
82 uint alpha_offset;
83 svm_unpack_node_uchar3(node.y, &layer_id, &color_offset, &alpha_offset);
84 const float bump_filter_width = __uint_as_float(node.z);
85
86 const AttributeDescriptor descriptor = find_attribute(kg, sd, layer_id);
87 if (descriptor.offset != ATTR_STD_NOT_FOUND) {
89 dual4 vertex_color = primitive_surface_attribute<float4>(kg, sd, descriptor, false, true);
90 vertex_color.val += vertex_color.dy * bump_filter_width;
91 stack_store_float3(stack, color_offset, make_float3(vertex_color.val));
92 stack_store_float(stack, alpha_offset, vertex_color.val.w);
93 }
94 else {
95 dual3 vertex_color = primitive_surface_attribute<float3>(kg, sd, descriptor, false, true);
96 vertex_color.val += vertex_color.dy * bump_filter_width;
97 stack_store_float3(stack, color_offset, vertex_color.val);
98 stack_store_float(stack, alpha_offset, 1.0f);
99 }
100 }
101 else {
102 stack_store_float3(stack, color_offset, make_float3(0.0f, 0.0f, 0.0f));
103 stack_store_float(stack, alpha_offset, 0.0f);
104 }
105}
106
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)
@ NODE_ATTR_RGBA
@ NODE_ATTR_FLOAT4
@ ATTR_STD_NOT_FOUND
descriptor
CCL_NAMESPACE_BEGIN ccl_device_forceinline dual< T > primitive_surface_attribute(KernelGlobals kg, const ccl_private ShaderData *sd, const AttributeDescriptor desc, const bool dx=false, const bool dy=false)
Definition primitive.h:32
static bool find_attribute(const std::string &attributes, const char *search_attribute)
float w
Definition sky_math.h:225
uint y
Definition types_uint4.h:13
uint z
Definition types_uint4.h:13
dual< float4 > dual4
Definition types_dual.h:59
dual< float3 > dual3
Definition types_dual.h:58
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)