2011-11-06 21:05:58 +00:00
|
|
|
/*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Copyright 2011-2013 Blender Foundation
|
2011-11-06 21:05:58 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2011-11-06 21:05:58 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-11-06 21:05:58 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
2014-12-25 02:50:24 +01:00
|
|
|
* limitations under the License.
|
2011-11-06 21:05:58 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
2012-06-08 19:57:25 +00:00
|
|
|
/* Wave */
|
2011-11-06 21:05:58 +00:00
|
|
|
|
2019-08-22 17:36:54 +02:00
|
|
|
ccl_device_noinline_cpu float svm_wave(NodeWaveType type,
|
2020-02-17 12:31:38 +01:00
|
|
|
NodeWaveBandsDirection bands_dir,
|
|
|
|
NodeWaveRingsDirection rings_dir,
|
2019-08-22 17:36:54 +02:00
|
|
|
NodeWaveProfile profile,
|
|
|
|
float3 p,
|
|
|
|
float detail,
|
|
|
|
float distortion,
|
2020-02-17 12:31:38 +01:00
|
|
|
float dscale,
|
|
|
|
float phase)
|
2011-11-06 21:05:58 +00:00
|
|
|
{
|
2020-02-17 12:31:38 +01:00
|
|
|
/* Prevent precision issues on unit coordinates. */
|
|
|
|
p = (p + 0.000001f) * 0.999999f;
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
float n;
|
2011-11-06 21:05:58 +00:00
|
|
|
|
2020-02-17 12:31:38 +01:00
|
|
|
if (type == NODE_WAVE_BANDS) {
|
|
|
|
if (bands_dir == NODE_WAVE_BANDS_DIRECTION_X) {
|
|
|
|
n = p.x * 20.0f;
|
|
|
|
}
|
|
|
|
else if (bands_dir == NODE_WAVE_BANDS_DIRECTION_Y) {
|
|
|
|
n = p.y * 20.0f;
|
|
|
|
}
|
|
|
|
else if (bands_dir == NODE_WAVE_BANDS_DIRECTION_Z) {
|
|
|
|
n = p.z * 20.0f;
|
|
|
|
}
|
|
|
|
else { /* NODE_WAVE_BANDS_DIRECTION_DIAGONAL */
|
|
|
|
n = (p.x + p.y + p.z) * 10.0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { /* NODE_WAVE_RINGS */
|
|
|
|
float3 rp = p;
|
|
|
|
if (rings_dir == NODE_WAVE_RINGS_DIRECTION_X) {
|
|
|
|
rp *= make_float3(0.0f, 1.0f, 1.0f);
|
|
|
|
}
|
|
|
|
else if (rings_dir == NODE_WAVE_RINGS_DIRECTION_Y) {
|
|
|
|
rp *= make_float3(1.0f, 0.0f, 1.0f);
|
|
|
|
}
|
|
|
|
else if (rings_dir == NODE_WAVE_RINGS_DIRECTION_Z) {
|
|
|
|
rp *= make_float3(1.0f, 1.0f, 0.0f);
|
|
|
|
}
|
|
|
|
/* else: NODE_WAVE_RINGS_DIRECTION_SPHERICAL */
|
|
|
|
|
|
|
|
n = len(rp) * 20.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
n += phase;
|
2015-12-29 14:42:49 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (distortion != 0.0f)
|
2019-12-05 22:07:43 +01:00
|
|
|
n += distortion * (fractal_noise_3d(p * dscale, detail) * 2.0f - 1.0f);
|
2011-11-06 21:05:58 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (profile == NODE_WAVE_PROFILE_SIN) {
|
2020-02-17 12:31:38 +01:00
|
|
|
return 0.5f + 0.5f * sinf(n - M_PI_2_F);
|
|
|
|
}
|
|
|
|
else if (profile == NODE_WAVE_PROFILE_SAW) {
|
|
|
|
n /= M_2PI_F;
|
|
|
|
return n - floorf(n);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2020-02-17 12:31:38 +01:00
|
|
|
else { /* NODE_WAVE_PROFILE_TRI */
|
2019-04-17 06:17:24 +02:00
|
|
|
n /= M_2PI_F;
|
2020-02-17 12:31:38 +01:00
|
|
|
return fabsf(n - floorf(n + 0.5f)) * 2.0f;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2011-11-06 21:05:58 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ccl_device void svm_node_tex_wave(
|
|
|
|
KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node, int *offset)
|
2011-11-06 21:05:58 +00:00
|
|
|
{
|
2020-02-17 12:31:38 +01:00
|
|
|
uint4 defaults1 = read_node(kg, offset);
|
|
|
|
uint4 defaults2 = read_node(kg, offset);
|
2011-11-06 21:05:58 +00:00
|
|
|
|
2020-02-17 12:31:38 +01:00
|
|
|
/* RNA properties */
|
|
|
|
uint type_offset, bands_dir_offset, rings_dir_offset, profile_offset;
|
|
|
|
/* Inputs, Outputs */
|
|
|
|
uint co_offset, scale_offset, distortion_offset, detail_offset, dscale_offset, phase_offset;
|
|
|
|
uint color_offset, fac_offset;
|
2011-11-06 21:05:58 +00:00
|
|
|
|
2020-02-17 12:31:38 +01:00
|
|
|
svm_unpack_node_uchar4(
|
|
|
|
node.y, &type_offset, &bands_dir_offset, &rings_dir_offset, &profile_offset);
|
|
|
|
svm_unpack_node_uchar4(node.z, &co_offset, &scale_offset, &distortion_offset, &detail_offset);
|
|
|
|
svm_unpack_node_uchar4(node.w, &dscale_offset, &phase_offset, &color_offset, &fac_offset);
|
2011-11-06 21:05:58 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
float3 co = stack_load_float3(stack, co_offset);
|
2020-02-17 12:31:38 +01:00
|
|
|
float scale = stack_load_float_default(stack, scale_offset, defaults1.x);
|
|
|
|
float detail = stack_load_float_default(stack, detail_offset, defaults1.y);
|
|
|
|
float distortion = stack_load_float_default(stack, distortion_offset, defaults1.z);
|
|
|
|
float dscale = stack_load_float_default(stack, dscale_offset, defaults1.w);
|
|
|
|
float phase = stack_load_float_default(stack, phase_offset, defaults2.x);
|
2011-11-06 21:05:58 +00:00
|
|
|
|
2020-02-17 12:31:38 +01:00
|
|
|
float f = svm_wave((NodeWaveType)type_offset,
|
|
|
|
(NodeWaveBandsDirection)bands_dir_offset,
|
|
|
|
(NodeWaveRingsDirection)rings_dir_offset,
|
|
|
|
(NodeWaveProfile)profile_offset,
|
|
|
|
co * scale,
|
|
|
|
detail,
|
|
|
|
distortion,
|
|
|
|
dscale,
|
|
|
|
phase);
|
2011-11-06 21:05:58 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (stack_valid(fac_offset))
|
|
|
|
stack_store_float(stack, fac_offset, f);
|
|
|
|
if (stack_valid(color_offset))
|
|
|
|
stack_store_float3(stack, color_offset, make_float3(f, f, f));
|
2011-11-06 21:05:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|