Blender V4.3
vector_rotate.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
8
9/* Vector Rotate */
10
12 ccl_private float *stack,
13 uint input_stack_offsets,
14 uint axis_stack_offsets,
15 uint result_stack_offset)
16{
17 uint type, vector_stack_offset, rotation_stack_offset, center_stack_offset, axis_stack_offset,
18 angle_stack_offset, invert;
19
21 input_stack_offsets, &type, &vector_stack_offset, &rotation_stack_offset, &invert);
23 axis_stack_offsets, &center_stack_offset, &axis_stack_offset, &angle_stack_offset);
24
25 if (stack_valid(result_stack_offset)) {
26
27 float3 vector = stack_load_float3(stack, vector_stack_offset);
28 float3 center = stack_load_float3(stack, center_stack_offset);
29 float3 result = make_float3(0.0f, 0.0f, 0.0f);
30
32 float3 rotation = stack_load_float3(stack, rotation_stack_offset); // Default XYZ.
33 Transform rotationTransform = euler_to_transform(rotation);
34 if (invert) {
35 result = transform_direction_transposed(&rotationTransform, vector - center) + center;
36 }
37 else {
38 result = transform_direction(&rotationTransform, vector - center) + center;
39 }
40 }
41 else {
42 float3 axis;
43 float axis_length;
44 switch (type) {
46 axis = make_float3(1.0f, 0.0f, 0.0f);
47 axis_length = 1.0f;
48 break;
50 axis = make_float3(0.0f, 1.0f, 0.0f);
51 axis_length = 1.0f;
52 break;
54 axis = make_float3(0.0f, 0.0f, 1.0f);
55 axis_length = 1.0f;
56 break;
57 default:
58 axis = stack_load_float3(stack, axis_stack_offset);
59 axis_length = len(axis);
60 break;
61 }
62 float angle = stack_load_float(stack, angle_stack_offset);
63 angle = invert ? -angle : angle;
64 result = (axis_length != 0.0f) ?
65 rotate_around_axis(vector - center, axis / axis_length, angle) + center :
66 vector;
67 }
68
69 stack_store_float3(stack, result_stack_offset, result);
70 }
71}
72
unsigned int uint
@ NODE_VECTOR_ROTATE_TYPE_AXIS_Z
@ NODE_VECTOR_ROTATE_TYPE_AXIS_X
@ NODE_VECTOR_ROTATE_TYPE_EULER_XYZ
@ NODE_VECTOR_ROTATE_TYPE_AXIS_Y
static double angle(const Eigen::Vector3d &v1, const Eigen::Vector3d &v2)
Definition IK_Math.h:125
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Gabor Generate Gabor noise Gradient Generate interpolated color and intensity values based on the input vector Magic Generate a psychedelic color texture Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a vector
#define ccl_private
#define ccl_device_noinline
#define CCL_NAMESPACE_END
ccl_device_forceinline float3 make_float3(const float x, const float y, const float z)
int len
CCL_NAMESPACE_BEGIN ccl_device float invert(float color, float factor)
Definition invert.h:9
ccl_device_inline void stack_store_float3(ccl_private float *stack, uint a, float3 f)
CCL_NAMESPACE_BEGIN ccl_device_inline float3 stack_load_float3(ccl_private float *stack, uint a)
ccl_device_forceinline void svm_unpack_node_uchar3(uint i, ccl_private uint *x, ccl_private uint *y, ccl_private uint *z)
ccl_device_inline float stack_load_float(ccl_private float *stack, uint a)
ccl_device_forceinline void svm_unpack_node_uchar4(uint i, ccl_private uint *x, ccl_private uint *y, ccl_private uint *z, ccl_private uint *w)
ccl_device_inline bool stack_valid(uint a)
ShaderData
ccl_device_inline Transform euler_to_transform(const float3 euler)
Definition transform.h:175
ccl_device_inline float3 transform_direction(ccl_private const Transform *t, const float3 a)
Definition transform.h:94
ccl_device_inline float3 transform_direction_transposed(ccl_private const Transform *t, const float3 a)
Definition transform.h:123
ccl_device_inline float3 rotate_around_axis(float3 p, float3 axis, float angle)
Definition util/math.h:683
CCL_NAMESPACE_BEGIN ccl_device_noinline void svm_node_vector_rotate(ccl_private ShaderData *sd, ccl_private float *stack, uint input_stack_offsets, uint axis_stack_offsets, uint result_stack_offset)