2023-06-14 16:52:36 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0 */
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2021-10-24 14:19:19 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
2024-12-26 17:53:57 +01:00
|
|
|
#include "kernel/svm/math_util.h"
|
|
|
|
|
#include "kernel/svm/util.h"
|
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
2025-05-27 21:30:45 +02:00
|
|
|
ccl_device_noinline void svm_node_math(ccl_private float *stack,
|
2025-01-01 18:15:54 +01:00
|
|
|
const uint type,
|
|
|
|
|
const uint inputs_stack_offsets,
|
|
|
|
|
const uint result_stack_offset)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2024-12-29 17:32:00 +01:00
|
|
|
uint a_stack_offset;
|
|
|
|
|
uint b_stack_offset;
|
|
|
|
|
uint c_stack_offset;
|
Maths Node: Additional functions
When creating shaders and using maths functions it is expected that Blender should match functions in other DCC applications, game engines and shading languages such as GLSL and OSL.
This patch adds missing functions to the Blender maths node.
Ideally, it would be nice to have these functions available to vectors too but that is not part of this patch.
This patch adds the following functions trunc, snap, wrap, compare, pingpong, sign, radians, degrees, cosh, sinh, tanh, exp, smoothmin and inversesqrt.
Sign function is based on GLSL and OSL functions and returns zero when x == 0.
Differential Revision: https://developer.blender.org/D5957
2019-12-05 23:02:05 +00:00
|
|
|
svm_unpack_node_uchar3(inputs_stack_offsets, &a_stack_offset, &b_stack_offset, &c_stack_offset);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2024-12-29 17:32:00 +01:00
|
|
|
const float a = stack_load_float(stack, a_stack_offset);
|
|
|
|
|
const float b = stack_load_float(stack, b_stack_offset);
|
|
|
|
|
const float c = stack_load_float(stack, c_stack_offset);
|
|
|
|
|
const float result = svm_math((NodeMathType)type, a, b, c);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2024-10-08 00:33:56 +02:00
|
|
|
stack_store_float(stack, result_stack_offset, result);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-08 00:33:56 +02:00
|
|
|
ccl_device_noinline int svm_node_vector_math(KernelGlobals kg,
|
|
|
|
|
ccl_private float *stack,
|
2025-01-01 18:15:54 +01:00
|
|
|
const uint type,
|
|
|
|
|
const uint inputs_stack_offsets,
|
|
|
|
|
const uint outputs_stack_offsets,
|
2024-10-08 00:33:56 +02:00
|
|
|
int offset)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2024-12-29 17:32:00 +01:00
|
|
|
uint value_stack_offset;
|
|
|
|
|
uint vector_stack_offset;
|
|
|
|
|
uint a_stack_offset;
|
|
|
|
|
uint b_stack_offset;
|
|
|
|
|
uint param1_stack_offset;
|
2019-08-21 11:59:57 +02:00
|
|
|
svm_unpack_node_uchar3(
|
2021-03-23 09:21:56 +00:00
|
|
|
inputs_stack_offsets, &a_stack_offset, &b_stack_offset, ¶m1_stack_offset);
|
2019-08-21 11:59:57 +02:00
|
|
|
svm_unpack_node_uchar2(outputs_stack_offsets, &value_stack_offset, &vector_stack_offset);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2024-12-29 17:32:00 +01:00
|
|
|
const float3 a = stack_load_float3(stack, a_stack_offset);
|
|
|
|
|
const float3 b = stack_load_float3(stack, b_stack_offset);
|
2020-03-27 14:24:13 +01:00
|
|
|
float3 c = make_float3(0.0f, 0.0f, 0.0f);
|
2024-12-29 17:32:00 +01:00
|
|
|
const float param1 = stack_load_float(stack, param1_stack_offset);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
Shading: Add more operators to Vector Math node.
Add Multiply, Divide, Project, Reflect, Distance, Length, Scale, Snap,
Floor, Ceil, Modulo, Fraction, Absolute, Minimum, and Maximum operators
to the Vector Math node. The Value output has been removed from operators
whose output is a vector, and the other way around. All of those removals
has been handled properly in versioning code.
The patch doesn't include tests for the new operators. Tests will be added
in a later patch.
Reviewers: brecht, JacquesLucke
Differential Revision: https://developer.blender.org/D5523
2019-08-21 19:36:33 +02:00
|
|
|
float value;
|
|
|
|
|
float3 vector;
|
2020-02-14 21:46:10 +00:00
|
|
|
|
|
|
|
|
/* 3 Vector Operators */
|
2021-06-04 16:53:50 +01:00
|
|
|
if (type == NODE_VECTOR_MATH_WRAP || type == NODE_VECTOR_MATH_FACEFORWARD ||
|
|
|
|
|
type == NODE_VECTOR_MATH_MULTIPLY_ADD)
|
|
|
|
|
{
|
2024-12-29 17:32:00 +01:00
|
|
|
const uint4 extra_node = read_node(kg, &offset);
|
2024-10-08 00:33:56 +02:00
|
|
|
c = stack_load_float3(stack, extra_node.x);
|
2020-02-14 21:46:10 +00:00
|
|
|
}
|
|
|
|
|
|
2021-03-23 09:21:56 +00:00
|
|
|
svm_vector_math(&value, &vector, (NodeVectorMathType)type, a, b, c, param1);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2024-12-26 17:53:59 +01:00
|
|
|
if (stack_valid(value_stack_offset)) {
|
2024-10-08 00:33:56 +02:00
|
|
|
stack_store_float(stack, value_stack_offset, value);
|
2024-12-26 17:53:59 +01:00
|
|
|
}
|
|
|
|
|
if (stack_valid(vector_stack_offset)) {
|
2024-10-08 00:33:56 +02:00
|
|
|
stack_store_float3(stack, vector_stack_offset, vector);
|
2024-12-26 17:53:59 +01:00
|
|
|
}
|
2024-10-08 00:33:56 +02:00
|
|
|
return offset;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|