Cycles: Add Saw option to the wave texture
This commit adds "Bands Saw" and "Rings Saw" to the options for the Wave texture node in Cycles, behaving similar to the Saw option in BI textures. Requested by @cekuhnen on BA. Reviewers: dingto, sergey Subscribers: cekuhnen Differential Revision: https://developer.blender.org/D1699
This commit is contained in:
@@ -19,7 +19,7 @@
|
||||
|
||||
/* Wave */
|
||||
|
||||
float wave(point p, string type, float detail, float distortion, float dscale)
|
||||
float wave(point p, string type, string profile, float detail, float distortion, float dscale)
|
||||
{
|
||||
float n = 0.0;
|
||||
|
||||
@@ -33,13 +33,23 @@ float wave(point p, string type, float detail, float distortion, float dscale)
|
||||
if (distortion != 0.0) {
|
||||
n = n + (distortion * noise_turbulence(p * dscale, detail, 0));
|
||||
}
|
||||
return 0.5 + 0.5 * sin(n);
|
||||
|
||||
if (profile == "Sine") {
|
||||
return 0.5 + 0.5 * sin(n);
|
||||
}
|
||||
else {
|
||||
/* Saw profile */
|
||||
n /= M_2PI;
|
||||
n -= (int) n;
|
||||
return (n < 0.0)? n + 1.0: n;
|
||||
}
|
||||
}
|
||||
|
||||
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 Profile = "Sine",
|
||||
float Scale = 5.0,
|
||||
float Distortion = 0.0,
|
||||
float Detail = 2.0,
|
||||
@@ -53,7 +63,7 @@ shader node_wave_texture(
|
||||
if (use_mapping)
|
||||
p = transform(mapping, p);
|
||||
|
||||
Fac = wave(p * Scale, Type, Detail, Distortion, DetailScale);
|
||||
Fac = wave(p * Scale, Type, Profile, Detail, Distortion, DetailScale);
|
||||
Color = Fac;
|
||||
}
|
||||
|
||||
|
@@ -293,6 +293,11 @@ typedef enum NodeWaveType {
|
||||
NODE_WAVE_RINGS
|
||||
} NodeWaveType;
|
||||
|
||||
typedef enum NodeWaveProfiles {
|
||||
NODE_WAVE_PROFILE_SIN,
|
||||
NODE_WAVE_PROFILE_SAW,
|
||||
} NodeWaveProfile;
|
||||
|
||||
typedef enum NodeSkyType {
|
||||
NODE_SKY_OLD,
|
||||
NODE_SKY_NEW
|
||||
|
@@ -18,7 +18,7 @@ CCL_NAMESPACE_BEGIN
|
||||
|
||||
/* Wave */
|
||||
|
||||
ccl_device_noinline float svm_wave(NodeWaveType type, float3 p, float detail, float distortion, float dscale)
|
||||
ccl_device_noinline float svm_wave(NodeWaveType type, NodeWaveProfile profile, float3 p, float detail, float distortion, float dscale)
|
||||
{
|
||||
float n;
|
||||
|
||||
@@ -26,11 +26,18 @@ ccl_device_noinline float svm_wave(NodeWaveType type, float3 p, float detail, fl
|
||||
n = (p.x + p.y + p.z) * 10.0f;
|
||||
else /* NODE_WAVE_RINGS */
|
||||
n = len(p) * 20.0f;
|
||||
|
||||
|
||||
if(distortion != 0.0f)
|
||||
n += distortion * noise_turbulence(p*dscale, detail, 0);
|
||||
|
||||
return 0.5f + 0.5f * sinf(n);
|
||||
if(profile == NODE_WAVE_PROFILE_SIN) {
|
||||
return 0.5f + 0.5f * sinf(n);
|
||||
}
|
||||
else { /* NODE_WAVE_PROFILE_SAW */
|
||||
n /= M_2PI_F;
|
||||
n -= (int) n;
|
||||
return (n < 0.0f)? n + 1.0f: n;
|
||||
}
|
||||
}
|
||||
|
||||
ccl_device void svm_node_tex_wave(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node, int *offset)
|
||||
@@ -49,7 +56,7 @@ ccl_device void svm_node_tex_wave(KernelGlobals *kg, ShaderData *sd, float *stac
|
||||
float distortion = stack_load_float_default(stack, distortion_offset, node2.z);
|
||||
float dscale = stack_load_float_default(stack, dscale_offset, node2.w);
|
||||
|
||||
float f = svm_wave((NodeWaveType)type, co*scale, detail, distortion, dscale);
|
||||
float f = svm_wave((NodeWaveType)type, (NodeWaveProfile)node.w, co*scale, detail, distortion, dscale);
|
||||
|
||||
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));
|
||||
|
Reference in New Issue
Block a user