Blender V4.3
wave.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/* Wave */
10
12 NodeWaveBandsDirection bands_dir,
13 NodeWaveRingsDirection rings_dir,
14 NodeWaveProfile profile,
15 float3 p,
16 float distortion,
17 float detail,
18 float dscale,
19 float droughness,
20 float phase)
21{
22 /* Prevent precision issues on unit coordinates. */
23 p = (p + 0.000001f) * 0.999999f;
24
25 float n;
26
27 if (type == NODE_WAVE_BANDS) {
28 if (bands_dir == NODE_WAVE_BANDS_DIRECTION_X) {
29 n = p.x * 20.0f;
30 }
31 else if (bands_dir == NODE_WAVE_BANDS_DIRECTION_Y) {
32 n = p.y * 20.0f;
33 }
34 else if (bands_dir == NODE_WAVE_BANDS_DIRECTION_Z) {
35 n = p.z * 20.0f;
36 }
37 else { /* NODE_WAVE_BANDS_DIRECTION_DIAGONAL */
38 n = (p.x + p.y + p.z) * 10.0f;
39 }
40 }
41 else { /* NODE_WAVE_RINGS */
42 float3 rp = p;
43 if (rings_dir == NODE_WAVE_RINGS_DIRECTION_X) {
44 rp *= make_float3(0.0f, 1.0f, 1.0f);
45 }
46 else if (rings_dir == NODE_WAVE_RINGS_DIRECTION_Y) {
47 rp *= make_float3(1.0f, 0.0f, 1.0f);
48 }
49 else if (rings_dir == NODE_WAVE_RINGS_DIRECTION_Z) {
50 rp *= make_float3(1.0f, 1.0f, 0.0f);
51 }
52 /* else: NODE_WAVE_RINGS_DIRECTION_SPHERICAL */
53
54 n = len(rp) * 20.0f;
55 }
56
57 n += phase;
58
59 if (distortion != 0.0f) {
60 n += distortion * (noise_fbm(p * dscale, detail, droughness, 2.0f, true) * 2.0f - 1.0f);
61 }
62
63 if (profile == NODE_WAVE_PROFILE_SIN) {
64 return 0.5f + 0.5f * sinf(n - M_PI_2_F);
65 }
66 else if (profile == NODE_WAVE_PROFILE_SAW) {
67 n /= M_2PI_F;
68 return n - floorf(n);
69 }
70 else { /* NODE_WAVE_PROFILE_TRI */
71 n /= M_2PI_F;
72 return fabsf(n - floorf(n + 0.5f)) * 2.0f;
73 }
74}
75
77 KernelGlobals kg, ccl_private ShaderData *sd, ccl_private float *stack, uint4 node, int offset)
78{
79 uint4 node2 = read_node(kg, &offset);
80 uint4 node3 = read_node(kg, &offset);
81
82 /* RNA properties */
83 uint type_offset, bands_dir_offset, rings_dir_offset, profile_offset;
84 /* Inputs, Outputs */
85 uint co_offset, scale_offset, distortion_offset, detail_offset, dscale_offset, droughness_offset,
86 phase_offset;
87 uint color_offset, fac_offset;
88
90 node.y, &type_offset, &bands_dir_offset, &rings_dir_offset, &profile_offset);
91 svm_unpack_node_uchar3(node.z, &co_offset, &scale_offset, &distortion_offset);
93 node.w, &detail_offset, &dscale_offset, &droughness_offset, &phase_offset);
94 svm_unpack_node_uchar2(node2.x, &color_offset, &fac_offset);
95
96 float3 co = stack_load_float3(stack, co_offset);
97 float scale = stack_load_float_default(stack, scale_offset, node2.y);
98 float distortion = stack_load_float_default(stack, distortion_offset, node2.z);
99 float detail = stack_load_float_default(stack, detail_offset, node2.w);
100 float dscale = stack_load_float_default(stack, dscale_offset, node3.x);
101 float droughness = stack_load_float_default(stack, droughness_offset, node3.y);
102 float phase = stack_load_float_default(stack, phase_offset, node3.z);
103
104 float f = svm_wave((NodeWaveType)type_offset,
105 (NodeWaveBandsDirection)bands_dir_offset,
106 (NodeWaveRingsDirection)rings_dir_offset,
107 (NodeWaveProfile)profile_offset,
108 co * scale,
109 distortion,
110 detail,
111 dscale,
112 droughness,
113 phase);
114
115 if (stack_valid(fac_offset))
116 stack_store_float(stack, fac_offset, f);
117 if (stack_valid(color_offset))
118 stack_store_float3(stack, color_offset, make_float3(f, f, f));
119 return offset;
120}
121
unsigned int uint
const KernelGlobalsCPU *ccl_restrict KernelGlobals
#define sinf(x)
#define ccl_private
#define ccl_device_noinline_cpu
#define ccl_device_noinline
#define CCL_NAMESPACE_END
ccl_device_forceinline float3 make_float3(const float x, const float y, const float z)
#define floorf(x)
#define fabsf(x)
int len
CCL_NAMESPACE_BEGIN ccl_device_noinline float noise_fbm(float p, float detail, float roughness, float lacunarity, bool normalize)
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_inline uint4 read_node(KernelGlobals kg, ccl_private int *offset)
ccl_device_forceinline void svm_unpack_node_uchar3(uint i, ccl_private uint *x, ccl_private uint *y, ccl_private uint *z)
ccl_device_forceinline void svm_unpack_node_uchar2(uint i, ccl_private uint *x, ccl_private uint *y)
ccl_device_inline float stack_load_float_default(ccl_private float *stack, uint a, uint value)
ccl_device_inline void stack_store_float(ccl_private float *stack, uint a, float f)
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)
NodeWaveBandsDirection
@ NODE_WAVE_BANDS_DIRECTION_Z
@ NODE_WAVE_BANDS_DIRECTION_Y
@ NODE_WAVE_BANDS_DIRECTION_X
NodeWaveType
@ NODE_WAVE_BANDS
NodeWaveProfile
@ NODE_WAVE_PROFILE_SIN
@ NODE_WAVE_PROFILE_SAW
NodeWaveRingsDirection
@ NODE_WAVE_RINGS_DIRECTION_Y
@ NODE_WAVE_RINGS_DIRECTION_X
@ NODE_WAVE_RINGS_DIRECTION_Z
ShaderData
#define M_PI_2_F
Definition sky_float3.h:20
#define M_2PI_F
Definition sky_float3.h:23
float z
Definition sky_float3.h:27
float y
Definition sky_float3.h:27
float x
Definition sky_float3.h:27
uint x
Definition types_uint4.h:15
uint y
Definition types_uint4.h:15
uint z
Definition types_uint4.h:15
uint w
Definition types_uint4.h:15
ccl_device_noinline int svm_node_tex_wave(KernelGlobals kg, ccl_private ShaderData *sd, ccl_private float *stack, uint4 node, int offset)
Definition wave.h:76
CCL_NAMESPACE_BEGIN ccl_device_noinline_cpu float svm_wave(NodeWaveType type, NodeWaveBandsDirection bands_dir, NodeWaveRingsDirection rings_dir, NodeWaveProfile profile, float3 p, float distortion, float detail, float dscale, float droughness, float phase)
Definition wave.h:11