Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBartosz Moniewski <monio>2020-02-17 14:31:38 +0300
committerBrecht Van Lommel <brecht@blender.org>2020-02-17 15:24:07 +0300
commit67d12bb5192d04a596e216f63cff2875fdd8cfbf (patch)
treec4d866f343ec9b87f713ebd004a8f343ab6f5307 /intern/cycles/kernel
parentae9bbb4d0360aea694b46ee698d24dbc1476ebf3 (diff)
Shading: add direction modes and phase offset to wave texture node
* Direction mode X, Y and Z to align with axes rather than diagonal or spherical as previously. X is the new default, existing files will use diagonal or spherical for compatibility. * Phase offset to offset the wave along its direction, for purposes like animation and distortion. https://developer.blender.org/D6382
Diffstat (limited to 'intern/cycles/kernel')
-rw-r--r--intern/cycles/kernel/shaders/node_wave_texture.osl67
-rw-r--r--intern/cycles/kernel/svm/svm_types.h17
-rw-r--r--intern/cycles/kernel/svm/svm_wave.h91
3 files changed, 144 insertions, 31 deletions
diff --git a/intern/cycles/kernel/shaders/node_wave_texture.osl b/intern/cycles/kernel/shaders/node_wave_texture.osl
index 5b27c570e42..5f97976e582 100644
--- a/intern/cycles/kernel/shaders/node_wave_texture.osl
+++ b/intern/cycles/kernel/shaders/node_wave_texture.osl
@@ -19,40 +19,81 @@
/* Wave */
-float wave(point p, string type, string profile, float detail, float distortion, float dscale)
+float wave(point p,
+ string type,
+ string bands_direction,
+ string rings_direction,
+ string profile,
+ float detail,
+ float distortion,
+ float dscale,
+ float phase)
{
+ /* Prevent precision issues on unit coordinates. */
+ p = (p + 0.000001) * 0.999999;
+
float n = 0.0;
if (type == "bands") {
- n = (p[0] + p[1] + p[2]) * 10.0;
+ if (bands_direction == "x") {
+ n = p[0] * 20.0;
+ }
+ else if (bands_direction == "y") {
+ n = p[1] * 20.0;
+ }
+ else if (bands_direction == "z") {
+ n = p[2] * 20.0;
+ }
+ else { /* diagonal */
+ n = (p[0] + p[1] + p[2]) * 10.0;
+ }
}
else if (type == "rings") {
- n = length(p) * 20.0;
+ point rp = p;
+ if (rings_direction == "x") {
+ rp *= point(0.0, 1.0, 1.0);
+ }
+ else if (rings_direction == "y") {
+ rp *= point(1.0, 0.0, 1.0);
+ }
+ else if (rings_direction == "z") {
+ rp *= point(1.0, 1.0, 0.0);
+ }
+ /* else: "spherical" */
+
+ n = length(rp) * 20.0;
}
+ n += phase;
+
if (distortion != 0.0) {
n = n + (distortion * (fractal_noise(p * dscale, detail) * 2.0 - 1.0));
}
if (profile == "sine") {
- return 0.5 + 0.5 * sin(n);
+ return 0.5 + 0.5 * sin(n - M_PI_2);
+ }
+ else if (profile == "saw") {
+ n /= M_2PI;
+ return n - floor(n);
}
- else {
- /* Saw profile */
+ else { /* profile tri */
n /= M_2PI;
- n -= (int)n;
- return (n < 0.0) ? n + 1.0 : n;
+ return abs(n - floor(n + 0.5)) * 2.0;
}
}
shader node_wave_texture(int use_mapping = 0,
matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
string type = "bands",
+ string bands_direction = "x",
+ string rings_direction = "x",
string profile = "sine",
float Scale = 5.0,
float Distortion = 0.0,
float Detail = 2.0,
float DetailScale = 1.0,
+ float PhaseOffset = 0.0,
point Vector = P,
output float Fac = 0.0,
output color Color = 0.0)
@@ -62,6 +103,14 @@ shader node_wave_texture(int use_mapping = 0,
if (use_mapping)
p = transform(mapping, p);
- Fac = wave(p * Scale, type, profile, Detail, Distortion, DetailScale);
+ Fac = wave(p * Scale,
+ type,
+ bands_direction,
+ rings_direction,
+ profile,
+ Detail,
+ Distortion,
+ DetailScale,
+ PhaseOffset);
Color = Fac;
}
diff --git a/intern/cycles/kernel/svm/svm_types.h b/intern/cycles/kernel/svm/svm_types.h
index 828b43eb8e4..45c299e0acb 100644
--- a/intern/cycles/kernel/svm/svm_types.h
+++ b/intern/cycles/kernel/svm/svm_types.h
@@ -384,9 +384,24 @@ typedef enum NodeMusgraveType {
typedef enum NodeWaveType { NODE_WAVE_BANDS, NODE_WAVE_RINGS } NodeWaveType;
-typedef enum NodeWaveProfiles {
+typedef enum NodeWaveBandsDirection {
+ NODE_WAVE_BANDS_DIRECTION_X,
+ NODE_WAVE_BANDS_DIRECTION_Y,
+ NODE_WAVE_BANDS_DIRECTION_Z,
+ NODE_WAVE_BANDS_DIRECTION_DIAGONAL
+} NodeWaveBandsDirection;
+
+typedef enum NodeWaveRingsDirection {
+ NODE_WAVE_RINGS_DIRECTION_X,
+ NODE_WAVE_RINGS_DIRECTION_Y,
+ NODE_WAVE_RINGS_DIRECTION_Z,
+ NODE_WAVE_RINGS_DIRECTION_SPHERICAL
+} NodeWaveRingsDirection;
+
+typedef enum NodeWaveProfile {
NODE_WAVE_PROFILE_SIN,
NODE_WAVE_PROFILE_SAW,
+ NODE_WAVE_PROFILE_TRI,
} NodeWaveProfile;
typedef enum NodeSkyType { NODE_SKY_OLD, NODE_SKY_NEW } NodeSkyType;
diff --git a/intern/cycles/kernel/svm/svm_wave.h b/intern/cycles/kernel/svm/svm_wave.h
index 50c868c0f82..64102535f7d 100644
--- a/intern/cycles/kernel/svm/svm_wave.h
+++ b/intern/cycles/kernel/svm/svm_wave.h
@@ -19,52 +19,101 @@ CCL_NAMESPACE_BEGIN
/* Wave */
ccl_device_noinline_cpu float svm_wave(NodeWaveType type,
+ NodeWaveBandsDirection bands_dir,
+ NodeWaveRingsDirection rings_dir,
NodeWaveProfile profile,
float3 p,
float detail,
float distortion,
- float dscale)
+ float dscale,
+ float phase)
{
+ /* Prevent precision issues on unit coordinates. */
+ p = (p + 0.000001f) * 0.999999f;
+
float n;
- if (type == NODE_WAVE_BANDS)
- n = (p.x + p.y + p.z) * 10.0f;
- else /* NODE_WAVE_RINGS */
- n = len(p) * 20.0f;
+ 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;
if (distortion != 0.0f)
n += distortion * (fractal_noise_3d(p * dscale, detail) * 2.0f - 1.0f);
if (profile == NODE_WAVE_PROFILE_SIN) {
- return 0.5f + 0.5f * sinf(n);
+ 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);
}
- else { /* NODE_WAVE_PROFILE_SAW */
+ else { /* NODE_WAVE_PROFILE_TRI */
n /= M_2PI_F;
- n -= (int)n;
- return (n < 0.0f) ? n + 1.0f : n;
+ return fabsf(n - floorf(n + 0.5f)) * 2.0f;
}
}
ccl_device void svm_node_tex_wave(
KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node, int *offset)
{
- uint4 node2 = read_node(kg, offset);
+ uint4 defaults1 = read_node(kg, offset);
+ uint4 defaults2 = read_node(kg, offset);
- uint type;
- uint co_offset, scale_offset, detail_offset, dscale_offset, distortion_offset, color_offset,
- fac_offset;
+ /* 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;
- svm_unpack_node_uchar4(node.y, &type, &color_offset, &fac_offset, &dscale_offset);
- svm_unpack_node_uchar4(node.z, &co_offset, &scale_offset, &detail_offset, &distortion_offset);
+ 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);
float3 co = stack_load_float3(stack, co_offset);
- float scale = stack_load_float_default(stack, scale_offset, node2.x);
- float detail = stack_load_float_default(stack, detail_offset, node2.y);
- float distortion = stack_load_float_default(stack, distortion_offset, node2.z);
- float dscale = stack_load_float_default(stack, dscale_offset, node2.w);
+ 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);
- float f = svm_wave(
- (NodeWaveType)type, (NodeWaveProfile)node.w, co * scale, detail, distortion, dscale);
+ float f = svm_wave((NodeWaveType)type_offset,
+ (NodeWaveBandsDirection)bands_dir_offset,
+ (NodeWaveRingsDirection)rings_dir_offset,
+ (NodeWaveProfile)profile_offset,
+ co * scale,
+ detail,
+ distortion,
+ dscale,
+ phase);
if (stack_valid(fac_offset))
stack_store_float(stack, fac_offset, f);