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:
Lukas Stockner
2015-12-29 14:42:49 +01:00
parent 1991ee1738
commit 5c682a901b
9 changed files with 66 additions and 10 deletions

View File

@@ -718,6 +718,7 @@ static ShaderNode *add_node(Scene *scene,
BL::ShaderNodeTexWave b_wave_node(b_node);
WaveTextureNode *wave = new WaveTextureNode();
wave->type = WaveTextureNode::type_enum[(int)b_wave_node.wave_type()];
wave->profile = WaveTextureNode::profile_enum[(int)b_wave_node.wave_profile()];
get_tex_mapping(&wave->tex_mapping, b_wave_node.texture_mapping());
node = wave;
}

View File

@@ -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;
}

View File

@@ -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

View File

@@ -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));

View File

@@ -1073,12 +1073,24 @@ static ShaderEnum wave_type_init()
return enm;
}
static ShaderEnum wave_profile_init()
{
ShaderEnum enm;
enm.insert("Sine", NODE_WAVE_PROFILE_SIN);
enm.insert("Saw", NODE_WAVE_PROFILE_SAW);
return enm;
}
ShaderEnum WaveTextureNode::type_enum = wave_type_init();
ShaderEnum WaveTextureNode::profile_enum = wave_profile_init();
WaveTextureNode::WaveTextureNode()
: TextureNode("wave_texture")
{
type = ustring("Bands");
profile = ustring("Sine");
add_input("Scale", SHADER_SOCKET_FLOAT, 1.0f);
add_input("Distortion", SHADER_SOCKET_FLOAT, 0.0f);
@@ -1120,7 +1132,8 @@ void WaveTextureNode::compile(SVMCompiler& compiler)
compiler.add_node(NODE_TEX_WAVE,
compiler.encode_uchar4(type_enum[type], color_out->stack_offset, fac_out->stack_offset, dscale_in->stack_offset),
compiler.encode_uchar4(vector_offset, scale_in->stack_offset, detail_in->stack_offset, distortion_in->stack_offset));
compiler.encode_uchar4(vector_offset, scale_in->stack_offset, detail_in->stack_offset, distortion_in->stack_offset),
profile_enum[profile]);
compiler.add_node(
__float_as_int(scale_in->value.x),
@@ -1137,6 +1150,7 @@ void WaveTextureNode::compile(OSLCompiler& compiler)
tex_mapping.compile(compiler);
compiler.parameter("Type", type);
compiler.parameter("Profile", profile);
compiler.add(this, "node_wave_texture");
}

View File

@@ -267,12 +267,15 @@ public:
virtual int get_group() { return NODE_GROUP_LEVEL_2; }
ustring type;
ustring profile;
static ShaderEnum type_enum;
static ShaderEnum profile_enum;
virtual bool equals(const ShaderNode *other) {
const WaveTextureNode *wave_node = (const WaveTextureNode*)other;
return TextureNode::equals(other) &&
type == wave_node->type;
type == wave_node->type &&
profile == wave_node->profile;
}
};

View File

@@ -939,6 +939,7 @@ static void node_shader_buts_tex_brick(uiLayout *layout, bContext *UNUSED(C), Po
static void node_shader_buts_tex_wave(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
{
uiItemR(layout, ptr, "wave_type", 0, "", ICON_NONE);
uiItemR(layout, ptr, "wave_profile", 0, "", ICON_NONE);
}
static void node_shader_buts_tex_musgrave(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)

View File

@@ -778,7 +778,7 @@ typedef struct NodeTexMusgrave {
typedef struct NodeTexWave {
NodeTexBase base;
int wave_type;
int pad;
int wave_profile;
} NodeTexWave;
typedef struct NodeTexMagic {
@@ -972,6 +972,9 @@ typedef struct NodeSunBeams {
#define SHD_WAVE_BANDS 0
#define SHD_WAVE_RINGS 1
#define SHD_WAVE_PROFILE_SIN 0
#define SHD_WAVE_PROFILE_SAW 1
/* sky texture */
#define SHD_SKY_OLD 0
#define SHD_SKY_NEW 1

View File

@@ -3858,6 +3858,12 @@ static void def_sh_tex_wave(StructRNA *srna)
{0, NULL, 0, NULL, NULL}
};
static EnumPropertyItem prop_wave_profile_items[] = {
{SHD_WAVE_PROFILE_SIN, "SIN", 0, "Sine", "Use a standard sine profile"},
{SHD_WAVE_PROFILE_SAW, "SAW", 0, "Saw", "Use a sawtooth profile"},
{0, NULL, 0, NULL, NULL}
};
PropertyRNA *prop;
RNA_def_struct_sdna_from(srna, "NodeTexWave", "storage");
@@ -3868,6 +3874,12 @@ static void def_sh_tex_wave(StructRNA *srna)
RNA_def_property_enum_items(prop, prop_wave_type_items);
RNA_def_property_ui_text(prop, "Wave Type", "");
RNA_def_property_update(prop, 0, "rna_Node_update");
prop = RNA_def_property(srna, "wave_profile", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "wave_profile");
RNA_def_property_enum_items(prop, prop_wave_profile_items);
RNA_def_property_ui_text(prop, "Wave Profile", "");
RNA_def_property_update(prop, 0, "rna_Node_update");
}
static void def_sh_tex_coord(StructRNA *srna)