Blender  V2.93
svm_wave.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2013 Blender Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
19 /* Wave */
20 
22  NodeWaveBandsDirection bands_dir,
23  NodeWaveRingsDirection rings_dir,
24  NodeWaveProfile profile,
25  float3 p,
26  float distortion,
27  float detail,
28  float dscale,
29  float droughness,
30  float phase)
31 {
32  /* Prevent precision issues on unit coordinates. */
33  p = (p + 0.000001f) * 0.999999f;
34 
35  float n;
36 
37  if (type == NODE_WAVE_BANDS) {
38  if (bands_dir == NODE_WAVE_BANDS_DIRECTION_X) {
39  n = p.x * 20.0f;
40  }
41  else if (bands_dir == NODE_WAVE_BANDS_DIRECTION_Y) {
42  n = p.y * 20.0f;
43  }
44  else if (bands_dir == NODE_WAVE_BANDS_DIRECTION_Z) {
45  n = p.z * 20.0f;
46  }
47  else { /* NODE_WAVE_BANDS_DIRECTION_DIAGONAL */
48  n = (p.x + p.y + p.z) * 10.0f;
49  }
50  }
51  else { /* NODE_WAVE_RINGS */
52  float3 rp = p;
53  if (rings_dir == NODE_WAVE_RINGS_DIRECTION_X) {
54  rp *= make_float3(0.0f, 1.0f, 1.0f);
55  }
56  else if (rings_dir == NODE_WAVE_RINGS_DIRECTION_Y) {
57  rp *= make_float3(1.0f, 0.0f, 1.0f);
58  }
59  else if (rings_dir == NODE_WAVE_RINGS_DIRECTION_Z) {
60  rp *= make_float3(1.0f, 1.0f, 0.0f);
61  }
62  /* else: NODE_WAVE_RINGS_DIRECTION_SPHERICAL */
63 
64  n = len(rp) * 20.0f;
65  }
66 
67  n += phase;
68 
69  if (distortion != 0.0f)
70  n += distortion * (fractal_noise_3d(p * dscale, detail, droughness) * 2.0f - 1.0f);
71 
72  if (profile == NODE_WAVE_PROFILE_SIN) {
73  return 0.5f + 0.5f * sinf(n - M_PI_2_F);
74  }
75  else if (profile == NODE_WAVE_PROFILE_SAW) {
76  n /= M_2PI_F;
77  return n - floorf(n);
78  }
79  else { /* NODE_WAVE_PROFILE_TRI */
80  n /= M_2PI_F;
81  return fabsf(n - floorf(n + 0.5f)) * 2.0f;
82  }
83 }
84 
86  KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node, int *offset)
87 {
88  uint4 node2 = read_node(kg, offset);
89  uint4 node3 = read_node(kg, offset);
90 
91  /* RNA properties */
92  uint type_offset, bands_dir_offset, rings_dir_offset, profile_offset;
93  /* Inputs, Outputs */
94  uint co_offset, scale_offset, distortion_offset, detail_offset, dscale_offset, droughness_offset,
95  phase_offset;
96  uint color_offset, fac_offset;
97 
99  node.y, &type_offset, &bands_dir_offset, &rings_dir_offset, &profile_offset);
100  svm_unpack_node_uchar3(node.z, &co_offset, &scale_offset, &distortion_offset);
102  node.w, &detail_offset, &dscale_offset, &droughness_offset, &phase_offset);
103  svm_unpack_node_uchar2(node2.x, &color_offset, &fac_offset);
104 
105  float3 co = stack_load_float3(stack, co_offset);
106  float scale = stack_load_float_default(stack, scale_offset, node2.y);
107  float distortion = stack_load_float_default(stack, distortion_offset, node2.z);
108  float detail = stack_load_float_default(stack, detail_offset, node2.w);
109  float dscale = stack_load_float_default(stack, dscale_offset, node3.x);
110  float droughness = stack_load_float_default(stack, droughness_offset, node3.y);
111  float phase = stack_load_float_default(stack, phase_offset, node3.z);
112 
113  float f = svm_wave((NodeWaveType)type_offset,
114  (NodeWaveBandsDirection)bands_dir_offset,
115  (NodeWaveRingsDirection)rings_dir_offset,
116  (NodeWaveProfile)profile_offset,
117  co * scale,
118  distortion,
119  detail,
120  dscale,
121  droughness,
122  phase);
123 
124  if (stack_valid(fac_offset))
125  stack_store_float(stack, fac_offset, f);
126  if (stack_valid(color_offset))
127  stack_store_float3(stack, color_offset, make_float3(f, f, f));
128 }
129 
unsigned int uint
Definition: BLI_sys_types.h:83
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
OperationNode * node
CCL_NAMESPACE_BEGIN ccl_device_inline float3 stack_load_float3(float *stack, uint a)
ccl_device_inline uint4 read_node(KernelGlobals *kg, int *offset)
ccl_device_inline float stack_load_float_default(float *stack, uint a, uint value)
ccl_device_forceinline void svm_unpack_node_uchar3(uint i, uint *x, uint *y, uint *z)
ccl_device_inline void stack_store_float3(float *stack, uint a, float3 f)
ccl_device_forceinline void svm_unpack_node_uchar4(uint i, uint *x, uint *y, uint *z, uint *w)
ccl_device_inline void stack_store_float(float *stack, uint a, float f)
ccl_device_forceinline void svm_unpack_node_uchar2(uint i, uint *x, uint *y)
ccl_device_inline bool stack_valid(uint a)
#define sinf(x)
#define ccl_device
#define ccl_device_noinline_cpu
#define CCL_NAMESPACE_END
#define floorf(x)
#define fabsf(x)
#define make_float3(x, y, z)
ShaderData
float z
Definition: sky_float3.h:35
float y
Definition: sky_float3.h:35
float x
Definition: sky_float3.h:35
ccl_device_noinline float fractal_noise_3d(float3 p, float octaves, float roughness)
NodeWaveBandsDirection
Definition: svm_types.h:406
@ NODE_WAVE_BANDS_DIRECTION_Z
Definition: svm_types.h:409
@ NODE_WAVE_BANDS_DIRECTION_Y
Definition: svm_types.h:408
@ NODE_WAVE_BANDS_DIRECTION_X
Definition: svm_types.h:407
NodeWaveType
Definition: svm_types.h:404
@ NODE_WAVE_BANDS
Definition: svm_types.h:404
NodeWaveProfile
Definition: svm_types.h:420
@ NODE_WAVE_PROFILE_SIN
Definition: svm_types.h:421
@ NODE_WAVE_PROFILE_SAW
Definition: svm_types.h:422
NodeWaveRingsDirection
Definition: svm_types.h:413
@ NODE_WAVE_RINGS_DIRECTION_Y
Definition: svm_types.h:415
@ NODE_WAVE_RINGS_DIRECTION_X
Definition: svm_types.h:414
@ NODE_WAVE_RINGS_DIRECTION_Z
Definition: svm_types.h:416
ccl_device void svm_node_tex_wave(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node, int *offset)
Definition: svm_wave.h:85
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: svm_wave.h:21
#define M_PI_2_F
Definition: util_math.h:46
#define M_2PI_F
Definition: util_math.h:69
uint len