mirror of
https://github.com/blender/blender
synced 2026-11-22 03:45:13 +03:00
Caused by 4d6c7718c5.
Under certain conditions it is possible that the offset logic in the
AttributeTableBuilder::add() assigns offset of -1. This value just
happens to match ATTR_STD_NOT_FOUND, leading to false-positive check
that attribute is not found (for example, svm_node_attr_init() that
checks desc.offset != ATTR_STD_NOT_FOUND.
The simplest solution is to tweak the value of the ATTR_STD_NOT_FOUND
to make it very big negative value.
There is now an utility function to check whether AttributeDescriptor
points to an attribute that is found, to help possibly tweaking this
check in the future, and to make code a bit more semantically clear.
Pull Request: https://projects.blender.org/blender/blender/pulls/157410
63 lines
2 KiB
C
63 lines
2 KiB
C
/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0 */
|
|
|
|
#pragma once
|
|
|
|
#include "kernel/globals.h"
|
|
|
|
#include "kernel/geom/attribute.h"
|
|
#include "kernel/geom/object.h"
|
|
#include "kernel/geom/primitive.h"
|
|
|
|
#include "kernel/svm/node_types.h"
|
|
#include "kernel/svm/util.h"
|
|
|
|
#include "kernel/util/differential.h"
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
/* Bump Eval Nodes */
|
|
|
|
ccl_device_noinline void svm_node_enter_bump_eval(KernelGlobals kg,
|
|
ccl_private ShaderData *sd,
|
|
ccl_private float *stack,
|
|
const ccl_global SVMNodeEnterBumpEval &node)
|
|
{
|
|
const uint offset = node.state_offset;
|
|
|
|
/* save state */
|
|
stack_store_float3(stack, offset + 0, sd->P);
|
|
stack_store_float(stack, offset + 3, sd->dP);
|
|
|
|
/* Set position as if undisplaced. */
|
|
const AttributeDescriptor desc = find_attribute(kg, sd, ATTR_STD_POSITION_UNDISPLACED);
|
|
if (is_attribute_found(desc)) {
|
|
dual3 attr = primitive_surface_attribute<dual3>(kg, sd, desc);
|
|
object_position_transform(kg, sd, &attr);
|
|
|
|
sd->P = attr.val;
|
|
sd->dP = differential_make_compact(attr);
|
|
|
|
/* Save the full differential, the compact form isn't enough for svm_node_set_bump. */
|
|
stack_store_float3(stack, offset + 4, attr.dx);
|
|
stack_store_float3(stack, offset + 7, attr.dy);
|
|
|
|
/* Set normal as if undisplaced. Note this does not need to be restored,
|
|
* because the bump evaluation will write to sd->N. */
|
|
primitive_normal_set_undisplaced(kg, sd, desc.offset);
|
|
}
|
|
}
|
|
|
|
ccl_device_noinline void svm_node_leave_bump_eval(ccl_private ShaderData *sd,
|
|
ccl_private float *stack,
|
|
const ccl_global SVMNodeLeaveBumpEval &node)
|
|
{
|
|
const uint offset = node.state_offset;
|
|
|
|
/* restore state */
|
|
sd->P = stack_load_float3(stack, offset + 0);
|
|
sd->dP = stack_load_float(stack, offset + 3);
|
|
}
|
|
|
|
CCL_NAMESPACE_END
|