Blender V5.0
bump.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
7#include "kernel/globals.h"
8
10#include "kernel/geom/object.h"
12
13#include "kernel/svm/util.h"
14
16
18
19/* Bump Eval Nodes */
20
22 ccl_private ShaderData *sd,
23 ccl_private float *stack,
24 const uint offset)
25{
26 /* save state */
27 stack_store_float3(stack, offset + 0, sd->P);
28 stack_store_float(stack, offset + 3, sd->dP);
29
30 /* This is a loop to work around a Metal compiler issue, this way we can have
31 * a single find_attribute and primitive_surface_attribute call. */
33 for (int i = 0; i < 2; i++) {
34 const AttributeDescriptor desc = find_attribute(kg, sd, std[i]);
35 if (desc.offset == ATTR_STD_NOT_FOUND) {
36 continue;
37 }
38
39 dual3 attr = primitive_surface_attribute<float3>(kg, sd, desc, true, true);
40
41 if (std[i] == ATTR_STD_NORMAL_UNDISPLACED) {
42 /* Set normal as if undisplaced.
43 * Note this does not need to be restored, because the bump evaluation will
44 * write to sd->N. */
45 float3 N = safe_normalize(attr.val);
46 object_normal_transform(kg, sd, &N);
47 sd->N = (sd->flag & SD_BACKFACING) ? -N : N;
48 }
49 else {
50 /* Set position as if undisplaced. */
51 object_position_transform(kg, sd, &attr);
52
53 sd->P = attr.val;
54 sd->dP = differential_make_compact(attr);
55
56 /* Save the full differential, the compact form isn't enough for svm_node_set_bump. */
57 stack_store_float3(stack, offset + 4, attr.dx);
58 stack_store_float3(stack, offset + 7, attr.dy);
59 }
60 }
61}
62
64 ccl_private float *stack,
65 const uint offset)
66{
67 /* restore state */
68 sd->P = stack_load_float3(stack, offset + 0);
69 sd->dP = stack_load_float(stack, offset + 3);
70}
71
unsigned int uint
ccl_device_noinline void svm_node_leave_bump_eval(ccl_private ShaderData *sd, ccl_private float *stack, const uint offset)
Definition bump.h:63
CCL_NAMESPACE_BEGIN ccl_device_noinline void svm_node_enter_bump_eval(KernelGlobals kg, ccl_private ShaderData *sd, ccl_private float *stack, const uint offset)
Definition bump.h:21
ccl_device_inline float stack_load_float(const ccl_private float *stack, const uint a)
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_NAMESPACE_BEGIN ccl_device_inline float3 stack_load_float3(const ccl_private float *stack, const uint a)
#define ccl_private
const ThreadKernelGlobalsCPU * KernelGlobals
#define ccl_device_noinline
#define CCL_NAMESPACE_END
ccl_device_forceinline float differential_make_compact(const float dD)
ccl_device_inline void object_normal_transform(KernelGlobals kg, const ccl_private ShaderData *sd, ccl_private float3 *N)
ccl_device_inline void object_position_transform(KernelGlobals kg, const ccl_private ShaderData *sd, ccl_private T *P)
@ SD_BACKFACING
AttributeStandard
@ ATTR_STD_NOT_FOUND
@ ATTR_STD_POSITION_UNDISPLACED
@ ATTR_STD_NORMAL_UNDISPLACED
ccl_device_inline float2 safe_normalize(const float2 a)
#define N
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)
i
Definition text_draw.cc:230
dual< float3 > dual3
Definition types_dual.h:58