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
This commit is contained in:
committed by
Brecht Van Lommel
parent
ae9bbb4d03
commit
67d12bb519
@@ -27,7 +27,7 @@
|
||||
* \note Use #STRINGIFY() rather than defining with quotes.
|
||||
*/
|
||||
#define BLENDER_VERSION 283
|
||||
#define BLENDER_SUBVERSION 3
|
||||
#define BLENDER_SUBVERSION 4
|
||||
/** Several breakages with 280, e.g. collections vs layers. */
|
||||
#define BLENDER_MINVERSION 280
|
||||
#define BLENDER_MINSUBVERSION 0
|
||||
|
||||
@@ -1250,6 +1250,31 @@ static void update_noise_and_wave_distortion(bNodeTree *ntree)
|
||||
}
|
||||
}
|
||||
|
||||
/* Wave Texture node: Restore previous texture directions and offset.
|
||||
* 1. In 2.81, Wave texture had fixed diagonal direction (Bands) or
|
||||
* mapping along distance (Rings). Now, directions are customizable
|
||||
* properties, with X axis being new default. To fix this we set new
|
||||
* direction options to Diagonal and Spherical.
|
||||
* 2. Sine profile is now negatively offseted by PI/2 to better match
|
||||
* other profiles. To fix this we set new Phase Offset input to PI/2
|
||||
* in nodes with Sine profile.
|
||||
*/
|
||||
static void update_wave_node_directions_and_offset(bNodeTree *ntree)
|
||||
{
|
||||
for (bNode *node = ntree->nodes.first; node; node = node->next) {
|
||||
if (node->type == SH_NODE_TEX_WAVE) {
|
||||
NodeTexWave *tex = (NodeTexWave *)node->storage;
|
||||
tex->bands_direction = SHD_WAVE_BANDS_DIRECTION_DIAGONAL;
|
||||
tex->rings_direction = SHD_WAVE_RINGS_DIRECTION_SPHERICAL;
|
||||
|
||||
if (tex->wave_profile == SHD_WAVE_PROFILE_SIN) {
|
||||
bNodeSocket *sockPhaseOffset = nodeFindSocket(node, SOCK_IN, "Phase Offset");
|
||||
*cycles_node_socket_float_value(sockPhaseOffset) = M_PI_2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void blo_do_versions_cycles(FileData *UNUSED(fd), Library *UNUSED(lib), Main *bmain)
|
||||
{
|
||||
/* Particle shape shared with Eevee. */
|
||||
@@ -1489,4 +1514,13 @@ void do_versions_after_linking_cycles(Main *bmain)
|
||||
}
|
||||
FOREACH_NODETREE_END;
|
||||
}
|
||||
|
||||
if (!MAIN_VERSION_ATLEAST(bmain, 283, 4)) {
|
||||
FOREACH_NODETREE_BEGIN (bmain, ntree, id) {
|
||||
if (ntree->type == NTREE_SHADER) {
|
||||
update_wave_node_directions_and_offset(ntree);
|
||||
}
|
||||
}
|
||||
FOREACH_NODETREE_END;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -873,6 +873,14 @@ 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);
|
||||
int type = RNA_enum_get(ptr, "wave_type");
|
||||
if (type == SHD_WAVE_BANDS) {
|
||||
uiItemR(layout, ptr, "bands_direction", 0, "", ICON_NONE);
|
||||
}
|
||||
else { /* SHD_WAVE_RINGS */
|
||||
uiItemR(layout, ptr, "rings_direction", 0, "", ICON_NONE);
|
||||
}
|
||||
|
||||
uiItemR(layout, ptr, "wave_profile", 0, "", ICON_NONE);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,26 +1,64 @@
|
||||
float calc_wave(
|
||||
vec3 p, float distortion, float detail, float detail_scale, int wave_type, int wave_profile)
|
||||
float calc_wave(vec3 p,
|
||||
float distortion,
|
||||
float detail,
|
||||
float detail_scale,
|
||||
float phase,
|
||||
int wave_type,
|
||||
int bands_dir,
|
||||
int rings_dir,
|
||||
int wave_profile)
|
||||
{
|
||||
/* Prevent precision issues on unit coordinates. */
|
||||
p = (p + 0.000001) * 0.999999;
|
||||
|
||||
float n;
|
||||
|
||||
if (wave_type == 0) { /* type bands */
|
||||
n = (p.x + p.y + p.z) * 10.0;
|
||||
if (wave_type == 0) { /* type bands */
|
||||
if (bands_dir == 0) { /* X axis */
|
||||
n = p.x * 20.0;
|
||||
}
|
||||
else if (bands_dir == 1) { /* Y axis */
|
||||
n = p.y * 20.0;
|
||||
}
|
||||
else if (bands_dir == 2) { /* Z axis */
|
||||
n = p.z * 20.0;
|
||||
}
|
||||
else { /* Diagonal axis */
|
||||
n = (p.x + p.y + p.z) * 10.0;
|
||||
}
|
||||
}
|
||||
else { /* type rings */
|
||||
n = length(p) * 20.0;
|
||||
vec3 rp = p;
|
||||
if (rings_dir == 0) { /* X axis */
|
||||
rp *= vec3(0.0, 1.0, 1.0);
|
||||
}
|
||||
else if (rings_dir == 1) { /* Y axis */
|
||||
rp *= vec3(1.0, 0.0, 1.0);
|
||||
}
|
||||
else if (rings_dir == 2) { /* Z axis */
|
||||
rp *= vec3(1.0, 1.0, 0.0);
|
||||
}
|
||||
/* else: Spherical */
|
||||
|
||||
n = length(rp) * 20.0;
|
||||
}
|
||||
|
||||
n += phase;
|
||||
|
||||
if (distortion != 0.0) {
|
||||
n += distortion * (fractal_noise(p * detail_scale, detail) * 2.0 - 1.0);
|
||||
}
|
||||
|
||||
if (wave_profile == 0) { /* profile sin */
|
||||
return 0.5 + 0.5 * sin(n);
|
||||
return 0.5 + 0.5 * sin(n - M_PI_2);
|
||||
}
|
||||
else { /* profile saw */
|
||||
else if (wave_profile == 1) { /* profile saw */
|
||||
n /= 2.0 * M_PI;
|
||||
n -= int(n);
|
||||
return (n < 0.0) ? n + 1.0 : n;
|
||||
return n - floor(n);
|
||||
}
|
||||
else { /* profile tri */
|
||||
n /= 2.0 * M_PI;
|
||||
return abs(n - floor(n + 0.5)) * 2.0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,13 +67,24 @@ void node_tex_wave(vec3 co,
|
||||
float distortion,
|
||||
float detail,
|
||||
float detail_scale,
|
||||
float phase,
|
||||
float wave_type,
|
||||
float bands_dir,
|
||||
float rings_dir,
|
||||
float wave_profile,
|
||||
out vec4 color,
|
||||
out float fac)
|
||||
{
|
||||
float f;
|
||||
f = calc_wave(co * scale, distortion, detail, detail_scale, int(wave_type), int(wave_profile));
|
||||
f = calc_wave(co * scale,
|
||||
distortion,
|
||||
detail,
|
||||
detail_scale,
|
||||
phase,
|
||||
int(wave_type),
|
||||
int(bands_dir),
|
||||
int(rings_dir),
|
||||
int(wave_profile));
|
||||
|
||||
color = vec4(f, f, f, 1.0);
|
||||
fac = f;
|
||||
|
||||
@@ -896,6 +896,8 @@ typedef struct NodeTexMusgrave {
|
||||
typedef struct NodeTexWave {
|
||||
NodeTexBase base;
|
||||
int wave_type;
|
||||
int bands_direction;
|
||||
int rings_direction;
|
||||
int wave_profile;
|
||||
} NodeTexWave;
|
||||
|
||||
@@ -1139,8 +1141,25 @@ enum {
|
||||
#define SHD_WAVE_BANDS 0
|
||||
#define SHD_WAVE_RINGS 1
|
||||
|
||||
#define SHD_WAVE_PROFILE_SIN 0
|
||||
#define SHD_WAVE_PROFILE_SAW 1
|
||||
enum {
|
||||
SHD_WAVE_BANDS_DIRECTION_X = 0,
|
||||
SHD_WAVE_BANDS_DIRECTION_Y = 1,
|
||||
SHD_WAVE_BANDS_DIRECTION_Z = 2,
|
||||
SHD_WAVE_BANDS_DIRECTION_DIAGONAL = 3,
|
||||
};
|
||||
|
||||
enum {
|
||||
SHD_WAVE_RINGS_DIRECTION_X = 0,
|
||||
SHD_WAVE_RINGS_DIRECTION_Y = 1,
|
||||
SHD_WAVE_RINGS_DIRECTION_Z = 2,
|
||||
SHD_WAVE_RINGS_DIRECTION_SPHERICAL = 3,
|
||||
};
|
||||
|
||||
enum {
|
||||
SHD_WAVE_PROFILE_SIN = 0,
|
||||
SHD_WAVE_PROFILE_SAW = 1,
|
||||
SHD_WAVE_PROFILE_TRI = 2,
|
||||
};
|
||||
|
||||
/* sky texture */
|
||||
#define SHD_SKY_OLD 0
|
||||
|
||||
@@ -4556,9 +4556,30 @@ static void def_sh_tex_wave(StructRNA *srna)
|
||||
{0, NULL, 0, NULL, NULL},
|
||||
};
|
||||
|
||||
static EnumPropertyItem prop_wave_bands_direction_items[] = {
|
||||
{SHD_WAVE_BANDS_DIRECTION_X, "X", 0, "X", "Bands across X axis"},
|
||||
{SHD_WAVE_BANDS_DIRECTION_Y, "Y", 0, "Y", "Bands across Y axis"},
|
||||
{SHD_WAVE_BANDS_DIRECTION_Z, "Z", 0, "Z", "Bands across Z axis"},
|
||||
{SHD_WAVE_BANDS_DIRECTION_DIAGONAL, "DIAGONAL", 0, "Diagonal", "Bands across diagonal axis"},
|
||||
{0, NULL, 0, NULL, NULL},
|
||||
};
|
||||
|
||||
static EnumPropertyItem prop_wave_rings_direction_items[] = {
|
||||
{SHD_WAVE_RINGS_DIRECTION_X, "X", 0, "X", "Rings along X axis"},
|
||||
{SHD_WAVE_RINGS_DIRECTION_Y, "Y", 0, "Y", "Rings along Y axis"},
|
||||
{SHD_WAVE_RINGS_DIRECTION_Z, "Z", 0, "Z", "Rings along Z axis"},
|
||||
{SHD_WAVE_RINGS_DIRECTION_SPHERICAL,
|
||||
"SPHERICAL",
|
||||
0,
|
||||
"Spherical",
|
||||
"Rings along spherical distance"},
|
||||
{0, NULL, 0, NULL, NULL},
|
||||
};
|
||||
|
||||
static const 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"},
|
||||
{SHD_WAVE_PROFILE_TRI, "TRI", 0, "Triangle", "Use a triangle profile"},
|
||||
{0, NULL, 0, NULL, NULL},
|
||||
};
|
||||
|
||||
@@ -4573,6 +4594,18 @@ static void def_sh_tex_wave(StructRNA *srna)
|
||||
RNA_def_property_ui_text(prop, "Wave Type", "");
|
||||
RNA_def_property_update(prop, 0, "rna_Node_update");
|
||||
|
||||
prop = RNA_def_property(srna, "bands_direction", PROP_ENUM, PROP_NONE);
|
||||
RNA_def_property_enum_sdna(prop, NULL, "bands_direction");
|
||||
RNA_def_property_enum_items(prop, prop_wave_bands_direction_items);
|
||||
RNA_def_property_ui_text(prop, "Bands Direction", "");
|
||||
RNA_def_property_update(prop, 0, "rna_Node_update");
|
||||
|
||||
prop = RNA_def_property(srna, "rings_direction", PROP_ENUM, PROP_NONE);
|
||||
RNA_def_property_enum_sdna(prop, NULL, "rings_direction");
|
||||
RNA_def_property_enum_items(prop, prop_wave_rings_direction_items);
|
||||
RNA_def_property_ui_text(prop, "Rings Direction", "");
|
||||
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);
|
||||
|
||||
@@ -27,6 +27,7 @@ static bNodeSocketTemplate sh_node_tex_wave_in[] = {
|
||||
{SOCK_FLOAT, 1, N_("Distortion"), 0.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f},
|
||||
{SOCK_FLOAT, 1, N_("Detail"), 2.0f, 0.0f, 0.0f, 0.0f, 0.0f, 16.0f},
|
||||
{SOCK_FLOAT, 1, N_("Detail Scale"), 1.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f},
|
||||
{SOCK_FLOAT, 1, N_("Phase Offset"), 0.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f},
|
||||
{-1, 0, ""},
|
||||
};
|
||||
|
||||
@@ -62,7 +63,9 @@ static void node_shader_init_tex_wave(bNodeTree *UNUSED(ntree), bNode *node)
|
||||
BKE_texture_mapping_default(&tex->base.tex_mapping, TEXMAP_TYPE_POINT);
|
||||
BKE_texture_colormapping_default(&tex->base.color_mapping);
|
||||
tex->wave_type = SHD_WAVE_BANDS;
|
||||
|
||||
tex->bands_direction = SHD_WAVE_BANDS_DIRECTION_X;
|
||||
tex->rings_direction = SHD_WAVE_RINGS_DIRECTION_X;
|
||||
tex->wave_profile = SHD_WAVE_PROFILE_SIN;
|
||||
node->storage = tex;
|
||||
}
|
||||
|
||||
@@ -77,10 +80,19 @@ static int node_shader_gpu_tex_wave(GPUMaterial *mat,
|
||||
|
||||
NodeTexWave *tex = (NodeTexWave *)node->storage;
|
||||
float wave_type = tex->wave_type;
|
||||
float bands_direction = tex->bands_direction;
|
||||
float rings_direction = tex->rings_direction;
|
||||
float wave_profile = tex->wave_profile;
|
||||
|
||||
return GPU_stack_link(
|
||||
mat, node, "node_tex_wave", in, out, GPU_constant(&wave_type), GPU_constant(&wave_profile));
|
||||
return GPU_stack_link(mat,
|
||||
node,
|
||||
"node_tex_wave",
|
||||
in,
|
||||
out,
|
||||
GPU_constant(&wave_type),
|
||||
GPU_constant(&bands_direction),
|
||||
GPU_constant(&rings_direction),
|
||||
GPU_constant(&wave_profile));
|
||||
}
|
||||
|
||||
/* node type definition */
|
||||
|
||||
Reference in New Issue
Block a user