Code refactor: add separate RGB to BW node and rename some sockets.

This commit is contained in:
Brecht Van Lommel
2016-05-29 12:24:47 +02:00
parent eac7ed8d04
commit 9bd2820aaf
23 changed files with 199 additions and 148 deletions

View File

@@ -339,7 +339,7 @@ static ShaderNode *add_node(Scene *scene,
node = new HSVNode(); node = new HSVNode();
} }
else if(b_node.is_a(&RNA_ShaderNodeRGBToBW)) { else if(b_node.is_a(&RNA_ShaderNodeRGBToBW)) {
node = new ConvertNode(SocketType::COLOR, SocketType::FLOAT); node = new RGBToBWNode();
} }
else if(b_node.is_a(&RNA_ShaderNodeMath)) { else if(b_node.is_a(&RNA_ShaderNodeMath)) {
BL::ShaderNodeMath b_math_node(b_node); BL::ShaderNodeMath b_math_node(b_node);

View File

@@ -59,10 +59,10 @@ float brick(point p, float mortar_size, float bias,
shader node_brick_texture( shader node_brick_texture(
int use_mapping = 0, int use_mapping = 0,
matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
float Offset = 0.5, float offset = 0.5,
int OffsetFrequency = 2, int offset_frequency = 2,
float Squash = 1.0, float squash = 1.0,
int SquashFrequency = 1, int squash_frequency = 1,
point Vector = P, point Vector = P,
color Color1 = 0.2, color Color1 = 0.2,
color Color2 = 0.8, color Color2 = 0.8,
@@ -84,7 +84,7 @@ shader node_brick_texture(
color Col = Color1; color Col = Color1;
Fac = brick(p * Scale, MortarSize, Bias, BrickWidth, RowHeight, Fac = brick(p * Scale, MortarSize, Bias, BrickWidth, RowHeight,
Offset, OffsetFrequency, Squash, SquashFrequency, tint); offset, offset_frequency, squash, squash_frequency, tint);
if (Fac != 1.0) { if (Fac != 1.0) {
float facm = 1.0 - tint; float facm = 1.0 - tint;

View File

@@ -17,18 +17,18 @@
#include "stdosl.h" #include "stdosl.h"
shader node_convert_from_color( shader node_convert_from_color(
color Color = 0.0, color value_color = 0.0,
output string String = "", output string value_string = "",
output float Val = 0.0, output float value_float = 0.0,
output int ValInt = 0, output int value_int = 0,
output vector Vector = vector(0.0, 0.0, 0.0), output vector value_vector = vector(0.0, 0.0, 0.0),
output point Point = point(0.0, 0.0, 0.0), output point value_point = point(0.0, 0.0, 0.0),
output normal Normal = normal(0.0, 0.0, 0.0)) output normal value_normal = normal(0.0, 0.0, 0.0))
{ {
Val = Color[0] * 0.2126 + Color[1] * 0.7152 + Color[2] * 0.0722; value_float = value_color[0] * 0.2126 + value_color[1] * 0.7152 + value_color[2] * 0.0722;
ValInt = (int)(Color[0] * 0.2126 + Color[1] * 0.7152 + Color[2] * 0.0722); value_int = (int)(value_color[0] * 0.2126 + value_color[1] * 0.7152 + value_color[2] * 0.0722);
Vector = vector(Color[0], Color[1], Color[2]); value_vector = vector(value_color[0], value_color[1], value_color[2]);
Point = point(Color[0], Color[1], Color[2]); value_point = point(value_color[0], value_color[1], value_color[2]);
Normal = normal(Color[0], Color[1], Color[2]); value_normal = normal(value_color[0], value_color[1], value_color[2]);
} }

View File

@@ -17,18 +17,18 @@
#include "stdosl.h" #include "stdosl.h"
shader node_convert_from_float( shader node_convert_from_float(
float Val = 0.0, float value_float = 0.0,
output string String = "", output string value_string = "",
output int ValInt = 0, output int value_int = 0,
output color Color = 0.0, output color value_color = 0.0,
output vector Vector = vector(0.0, 0.0, 0.0), output vector value_vector = vector(0.0, 0.0, 0.0),
output point Point = point(0.0, 0.0, 0.0), output point value_point = point(0.0, 0.0, 0.0),
output normal Normal = normal(0.0, 0.0, 0.0)) output normal value_normal = normal(0.0, 0.0, 0.0))
{ {
ValInt = (int)Val; value_int = (int)value_float;
Color = color(Val, Val, Val); value_color = color(value_float, value_float, value_float);
Vector = vector(Val, Val, Val); value_vector = vector(value_float, value_float, value_float);
Point = point(Val, Val, Val); value_point = point(value_float, value_float, value_float);
Normal = normal(Val, Val, Val); value_normal = normal(value_float, value_float, value_float);
} }

View File

@@ -17,19 +17,19 @@
#include "stdosl.h" #include "stdosl.h"
shader node_convert_from_int( shader node_convert_from_int(
int ValInt = 0, int value_int = 0,
output string String = "", output string value_string = "",
output float Val = 0.0, output float value_float = 0.0,
output color Color = 0.0, output color value_color = 0.0,
output vector Vector = vector(0.0, 0.0, 0.0), output vector value_vector = vector(0.0, 0.0, 0.0),
output point Point = point(0.0, 0.0, 0.0), output point value_point = point(0.0, 0.0, 0.0),
output normal Normal = normal(0.0, 0.0, 0.0)) output normal value_normal = normal(0.0, 0.0, 0.0))
{ {
float f = (float)ValInt; float f = (float)value_int;
Val = f; value_float = f;
Color = color(f, f, f); value_color = color(f, f, f);
Vector = vector(f, f, f); value_vector = vector(f, f, f);
Point = point(f, f, f); value_point = point(f, f, f);
Normal = normal(f, f, f); value_normal = normal(f, f, f);
} }

View File

@@ -17,18 +17,18 @@
#include "stdosl.h" #include "stdosl.h"
shader node_convert_from_normal( shader node_convert_from_normal(
normal Normal = normal(0.0, 0.0, 0.0), normal value_normal = normal(0.0, 0.0, 0.0),
output string String = "", output string value_string = "",
output float Val = 0.0, output float value_float = 0.0,
output int ValInt = 0, output int value_int = 0,
output vector Vector = vector(0.0, 0.0, 0.0), output vector value_vector = vector(0.0, 0.0, 0.0),
output color Color = 0.0, output color value_color = 0.0,
output point Point = point(0.0, 0.0, 0.0)) output point value_point = point(0.0, 0.0, 0.0))
{ {
Val = (Normal[0] + Normal[1] + Normal[2]) * (1.0 / 3.0); value_float = (value_normal[0] + value_normal[1] + value_normal[2]) * (1.0 / 3.0);
ValInt = (int)((Normal[0] + Normal[1] + Normal[2]) * (1.0 / 3.0)); value_int = (int)((value_normal[0] + value_normal[1] + value_normal[2]) * (1.0 / 3.0));
Vector = vector(Normal[0], Normal[1], Normal[2]); value_vector = vector(value_normal[0], value_normal[1], value_normal[2]);
Color = color(Normal[0], Normal[1], Normal[2]); value_color = color(value_normal[0], value_normal[1], value_normal[2]);
Point = point(Normal[0], Normal[1], Normal[2]); value_point = point(value_normal[0], value_normal[1], value_normal[2]);
} }

View File

@@ -17,18 +17,18 @@
#include "stdosl.h" #include "stdosl.h"
shader node_convert_from_point( shader node_convert_from_point(
point Point = point(0.0, 0.0, 0.0), point value_point = point(0.0, 0.0, 0.0),
output string String = "", output string value_string = "",
output float Val = 0.0, output float value_float = 0.0,
output int ValInt = 0, output int value_int = 0,
output vector Vector = vector(0.0, 0.0, 0.0), output vector value_vector = vector(0.0, 0.0, 0.0),
output color Color = 0.0, output color value_color = 0.0,
output normal Normal = normal(0.0, 0.0, 0.0)) output normal value_normal = normal(0.0, 0.0, 0.0))
{ {
Val = (Point[0] + Point[1] + Point[2]) * (1.0 / 3.0); value_float = (value_point[0] + value_point[1] + value_point[2]) * (1.0 / 3.0);
ValInt = (int)((Normal[0] + Normal[1] + Normal[2]) * (1.0 / 3.0)); value_int = (int)((value_normal[0] + value_normal[1] + value_normal[2]) * (1.0 / 3.0));
Vector = vector(Point[0], Point[1], Point[2]); value_vector = vector(value_point[0], value_point[1], value_point[2]);
Color = color(Point[0], Point[1], Point[2]); value_color = color(value_point[0], value_point[1], value_point[2]);
Normal = normal(Point[0], Point[1], Point[2]); value_normal = normal(value_point[0], value_point[1], value_point[2]);
} }

View File

@@ -17,13 +17,13 @@
#include "stdosl.h" #include "stdosl.h"
shader node_convert_from_string( shader node_convert_from_string(
string String = "", string value_string = "",
output color Color = color(0.0, 0.0, 0.0), output color value_color = color(0.0, 0.0, 0.0),
output float Val = 0.0, output float value_float = 0.0,
output int ValInt = 0, output int value_int = 0,
output vector Vector = vector(0.0, 0.0, 0.0), output vector value_vector = vector(0.0, 0.0, 0.0),
output point Point = point(0.0, 0.0, 0.0), output point value_point = point(0.0, 0.0, 0.0),
output normal Normal = normal(0.0, 0.0, 0.0)) output normal value_normal = normal(0.0, 0.0, 0.0))
{ {
} }

View File

@@ -17,18 +17,18 @@
#include "stdosl.h" #include "stdosl.h"
shader node_convert_from_vector( shader node_convert_from_vector(
vector Vector = vector(0.0, 0.0, 0.0), vector value_vector = vector(0.0, 0.0, 0.0),
output string String = "", output string value_string = "",
output float Val = 0.0, output float value_float = 0.0,
output int ValInt = 0, output int value_int = 0,
output color Color = color(0.0, 0.0, 0.0), output color value_color = color(0.0, 0.0, 0.0),
output point Point = point(0.0, 0.0, 0.0), output point value_point = point(0.0, 0.0, 0.0),
output normal Normal = normal(0.0, 0.0, 0.0)) output normal value_normal = normal(0.0, 0.0, 0.0))
{ {
Val = (Vector[0] + Vector[1] + Vector[2]) * (1.0 / 3.0); value_float = (value_vector[0] + value_vector[1] + value_vector[2]) * (1.0 / 3.0);
ValInt = (int)((Normal[0] + Normal[1] + Normal[2]) * (1.0 / 3.0)); value_int = (int)((value_normal[0] + value_normal[1] + value_normal[2]) * (1.0 / 3.0));
Color = color(Vector[0], Vector[1], Vector[2]); value_color = color(value_vector[0], value_vector[1], value_vector[2]);
Point = point(Vector[0], Vector[1], Vector[2]); value_point = point(value_vector[0], value_vector[1], value_vector[2]);
Normal = normal(Vector[0], Vector[1], Vector[2]); value_normal = normal(value_vector[0], value_vector[1], value_vector[2]);
} }

View File

@@ -63,7 +63,7 @@ float gradient(point p, string type)
shader node_gradient_texture( shader node_gradient_texture(
int use_mapping = 0, int use_mapping = 0,
matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
string Type = "Linear", string type = "Linear",
point Vector = P, point Vector = P,
output float Fac = 0.0, output float Fac = 0.0,
output color Color = 0.0) output color Color = 0.0)
@@ -73,7 +73,7 @@ shader node_gradient_texture(
if (use_mapping) if (use_mapping)
p = transform(mapping, p); p = transform(mapping, p);
Fac = gradient(p, Type); Fac = gradient(p, type);
Color = color(Fac, Fac, Fac); Color = color(Fac, Fac, Fac);
} }

View File

@@ -62,9 +62,9 @@ color image_texture_lookup(string filename,
int use_alpha, int use_alpha,
int is_float, int is_float,
string interpolation, string interpolation,
string wrap) string extension)
{ {
color rgb = (color)texture(filename, u, 1.0 - v, "wrap", wrap, "interp", interpolation, "alpha", Alpha); color rgb = (color)texture(filename, u, 1.0 - v, "wrap", extension, "interp", interpolation, "alpha", Alpha);
if (use_alpha) { if (use_alpha) {
rgb = color_unpremultiply(rgb, Alpha); rgb = color_unpremultiply(rgb, Alpha);

View File

@@ -93,7 +93,7 @@ color magic(point p, int n, float distortion)
shader node_magic_texture( shader node_magic_texture(
int use_mapping = 0, int use_mapping = 0,
matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
int Depth = 2, int depth = 2,
float Distortion = 5.0, float Distortion = 5.0,
float Scale = 5.0, float Scale = 5.0,
point Vector = P, point Vector = P,
@@ -105,7 +105,7 @@ shader node_magic_texture(
if (use_mapping) if (use_mapping)
p = transform(mapping, p); p = transform(mapping, p);
Color = magic(p * Scale, Depth, Distortion); Color = magic(p * Scale, depth, Distortion);
Fac = (Color[0] + Color[1] + Color[2]) * (1.0 / 3.0); Fac = (Color[0] + Color[1] + Color[2]) * (1.0 / 3.0);
} }

View File

@@ -50,7 +50,7 @@ float safe_log(float a, float b)
shader node_math( shader node_math(
string type = "Add", string type = "Add",
int Clamp = 0, int use_clamp = 0,
float Value1 = 0.0, float Value1 = 0.0,
float Value2 = 0.0, float Value2 = 0.0,
output float Value = 0.0) output float Value = 0.0)
@@ -96,7 +96,7 @@ shader node_math(
else if (type == "Absolute") else if (type == "Absolute")
Value = fabs(Value1); Value = fabs(Value1);
if (Clamp) if (use_clamp)
Value = clamp(Value, 0.0, 1.0); Value = clamp(Value, 0.0, 1.0);
} }

View File

@@ -278,7 +278,7 @@ color node_mix_clamp(color col)
shader node_mix( shader node_mix(
string type = "Mix", string type = "Mix",
int Clamp = 0, int use_clamp = 0,
float Fac = 0.5, float Fac = 0.5,
color Color1 = 0.0, color Color1 = 0.0,
color Color2 = 0.0, color Color2 = 0.0,
@@ -323,7 +323,7 @@ shader node_mix(
if (type == "Linear Light") if (type == "Linear Light")
Color = node_mix_linear(t, Color1, Color2); Color = node_mix_linear(t, Color1, Color2);
if (Clamp) if (use_clamp)
Color = node_mix_clamp(Color); Color = node_mix_clamp(Color);
} }

View File

@@ -187,7 +187,7 @@ float noise_musgrave_ridged_multi_fractal(point p, float H, float lacunarity,
shader node_musgrave_texture( shader node_musgrave_texture(
int use_mapping = 0, int use_mapping = 0,
matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
string Type = "fBM", string type = "fBM",
float Dimension = 2.0, float Dimension = 2.0,
float Lacunarity = 1.0, float Lacunarity = 1.0,
float Detail = 2.0, float Detail = 2.0,
@@ -210,15 +210,15 @@ shader node_musgrave_texture(
p = p * Scale; p = p * Scale;
if (Type == "Multifractal") if (type == "Multifractal")
Fac = intensity * noise_musgrave_multi_fractal(p, dimension, lacunarity, octaves); Fac = intensity * noise_musgrave_multi_fractal(p, dimension, lacunarity, octaves);
else if (Type == "fBM") else if (type == "fBM")
Fac = intensity * noise_musgrave_fBm(p, dimension, lacunarity, octaves); Fac = intensity * noise_musgrave_fBm(p, dimension, lacunarity, octaves);
else if (Type == "Hybrid Multifractal") else if (type == "Hybrid Multifractal")
Fac = intensity * noise_musgrave_hybrid_multi_fractal(p, dimension, lacunarity, octaves, Offset, Gain); Fac = intensity * noise_musgrave_hybrid_multi_fractal(p, dimension, lacunarity, octaves, Offset, Gain);
else if (Type == "Ridged Multifractal") else if (type == "Ridged Multifractal")
Fac = intensity * noise_musgrave_ridged_multi_fractal(p, dimension, lacunarity, octaves, Offset, Gain); Fac = intensity * noise_musgrave_ridged_multi_fractal(p, dimension, lacunarity, octaves, Offset, Gain);
else if (Type == "Hetero Terrain") else if (type == "Hetero Terrain")
Fac = intensity * noise_musgrave_hetero_terrain(p, dimension, lacunarity, octaves, Offset); Fac = intensity * noise_musgrave_hetero_terrain(p, dimension, lacunarity, octaves, Offset);
Color = color(Fac, Fac, Fac); Color = color(Fac, Fac, Fac);

View File

@@ -17,12 +17,12 @@
#include "stdosl.h" #include "stdosl.h"
shader node_normal( shader node_normal(
normal Direction = normal(0.0, 0.0, 0.0), normal direction = normal(0.0, 0.0, 0.0),
normal NormalIn = normal(0.0, 0.0, 0.0), normal NormalIn = normal(0.0, 0.0, 0.0),
output normal NormalOut = normal(0.0, 0.0, 0.0), output normal NormalOut = normal(0.0, 0.0, 0.0),
output float Dot = 1.0) output float Dot = 1.0)
{ {
NormalOut = normalize(Direction); NormalOut = normalize(direction);
Dot = dot(NormalOut, normalize(NormalIn)); Dot = dot(NormalOut, normalize(NormalIn));
} }

View File

@@ -20,7 +20,7 @@
shader node_rgb_ramp( shader node_rgb_ramp(
color ramp_color[] = {0.0}, color ramp_color[] = {0.0},
float ramp_alpha[] = {0.0}, float ramp_alpha[] = {0.0},
int ramp_interpolate = 1, int interpolate = 1,
float Fac = 0.0, float Fac = 0.0,
output color Color = 0.0, output color Color = 0.0,
@@ -38,7 +38,7 @@ shader node_rgb_ramp(
Color = ramp_color[i]; Color = ramp_color[i];
Alpha = ramp_alpha[i]; Alpha = ramp_alpha[i];
if (ramp_interpolate && t > 0.0) { if (interpolate && t > 0.0) {
Color = (1.0 - t) * Color + t * ramp_color[i + 1]; Color = (1.0 - t) * Color + t * ramp_color[i + 1];
Alpha = (1.0 - t) * Alpha + t * ramp_alpha[i + 1]; Alpha = (1.0 - t) * Alpha + t * ramp_alpha[i + 1];
} }

View File

@@ -22,13 +22,13 @@ shader node_subsurface_scattering(
vector Radius = vector(0.1, 0.1, 0.1), vector Radius = vector(0.1, 0.1, 0.1),
float TextureBlur = 0.0, float TextureBlur = 0.0,
float Sharpness = 0.0, float Sharpness = 0.0,
string Falloff = "Cubic", string falloff = "Cubic",
normal Normal = N, normal Normal = N,
output closure color BSSRDF = 0) output closure color BSSRDF = 0)
{ {
if (Falloff == "Gaussian") if (falloff == "Gaussian")
BSSRDF = Color * bssrdf_gaussian(Normal, Scale * Radius, TextureBlur); BSSRDF = Color * bssrdf_gaussian(Normal, Scale * Radius, TextureBlur);
else if (Falloff == "Cubic") else if (falloff == "Cubic")
BSSRDF = Color * bssrdf_cubic(Normal, Scale * Radius, TextureBlur, Sharpness); BSSRDF = Color * bssrdf_cubic(Normal, Scale * Radius, TextureBlur, Sharpness);
else else
BSSRDF = Color * bssrdf_burley(Normal, Scale * Radius, TextureBlur, Color); BSSRDF = Color * bssrdf_burley(Normal, Scale * Radius, TextureBlur, Color);

View File

@@ -22,7 +22,7 @@
shader node_voronoi_texture( shader node_voronoi_texture(
int use_mapping = 0, int use_mapping = 0,
matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
string Coloring = "Intensity", string coloring = "Intensity",
float Scale = 5.0, float Scale = 5.0,
point Vector = P, point Vector = P,
output float Fac = 0.0, output float Fac = 0.0,
@@ -40,7 +40,7 @@ shader node_voronoi_texture(
voronoi(p * Scale, 1.0, da, pa); voronoi(p * Scale, 1.0, da, pa);
/* Colored output */ /* Colored output */
if (Coloring == "Intensity") { if (coloring == "Intensity") {
Fac = fabs(da[0]); Fac = fabs(da[0]);
Color = color(Fac); Color = color(Fac);
} }

View File

@@ -48,8 +48,8 @@ float wave(point p, string type, string profile, float detail, float distortion,
shader node_wave_texture( shader node_wave_texture(
int use_mapping = 0, int use_mapping = 0,
matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
string Type = "Bands", string type = "Bands",
string Profile = "Sine", string profile = "Sine",
float Scale = 5.0, float Scale = 5.0,
float Distortion = 0.0, float Distortion = 0.0,
float Detail = 2.0, float Detail = 2.0,
@@ -63,7 +63,7 @@ shader node_wave_texture(
if (use_mapping) if (use_mapping)
p = transform(mapping, p); p = transform(mapping, p);
Fac = wave(p * Scale, Type, Profile, Detail, Distortion, DetailScale); Fac = wave(p * Scale, type, profile, Detail, Distortion, DetailScale);
Color = Fac; Color = Fac;
} }

View File

@@ -343,6 +343,11 @@ typedef enum NodeNormalMapSpace {
NODE_NORMAL_MAP_BLENDER_WORLD, NODE_NORMAL_MAP_BLENDER_WORLD,
} NodeNormalMapSpace; } NodeNormalMapSpace;
typedef enum NodeImageColorSpace {
NODE_COLOR_SPACE_NONE = 0,
NODE_COLOR_SPACE_COLOR = 1,
} NodeImageColorSpace;
typedef enum NodeImageProjection { typedef enum NodeImageProjection {
NODE_IMAGE_PROJ_FLAT = 0, NODE_IMAGE_PROJ_FLAT = 0,
NODE_IMAGE_PROJ_BOX = 1, NODE_IMAGE_PROJ_BOX = 1,
@@ -350,6 +355,11 @@ typedef enum NodeImageProjection {
NODE_IMAGE_PROJ_TUBE = 3, NODE_IMAGE_PROJ_TUBE = 3,
} NodeImageProjection; } NodeImageProjection;
typedef enum NodeEnvironmentProjection {
NODE_ENVIRONMENT_EQUIRECTANGULAR = 0,
NODE_ENVIRONMENT_MIRROR_BALL = 1,
} NodeEnvironmentProjection;
typedef enum NodeBumpOffset { typedef enum NodeBumpOffset {
NODE_BUMP_OFFSET_CENTER, NODE_BUMP_OFFSET_CENTER,
NODE_BUMP_OFFSET_DX, NODE_BUMP_OFFSET_DX,

View File

@@ -433,14 +433,14 @@ void ImageTextureNode::compile(OSLCompiler& compiler)
switch(extension) { switch(extension) {
case EXTENSION_EXTEND: case EXTENSION_EXTEND:
compiler.parameter("wrap", "clamp"); compiler.parameter("extension", "clamp");
break; break;
case EXTENSION_CLIP: case EXTENSION_CLIP:
compiler.parameter("wrap", "black"); compiler.parameter("extension", "black");
break; break;
case EXTENSION_REPEAT: case EXTENSION_REPEAT:
default: default:
compiler.parameter("wrap", "periodic"); compiler.parameter("extension", "periodic");
break; break;
} }
@@ -867,7 +867,7 @@ void GradientTextureNode::compile(OSLCompiler& compiler)
{ {
tex_mapping.compile(compiler); tex_mapping.compile(compiler);
compiler.parameter("Type", type); compiler.parameter("type", type);
compiler.add(this, "node_gradient_texture"); compiler.add(this, "node_gradient_texture");
} }
@@ -971,7 +971,7 @@ void VoronoiTextureNode::compile(OSLCompiler& compiler)
{ {
tex_mapping.compile(compiler); tex_mapping.compile(compiler);
compiler.parameter("Coloring", coloring); compiler.parameter("coloring", coloring);
compiler.add(this, "node_voronoi_texture"); compiler.add(this, "node_voronoi_texture");
} }
@@ -1051,7 +1051,7 @@ void MusgraveTextureNode::compile(OSLCompiler& compiler)
{ {
tex_mapping.compile(compiler); tex_mapping.compile(compiler);
compiler.parameter("Type", type); compiler.parameter("type", type);
compiler.add(this, "node_musgrave_texture"); compiler.add(this, "node_musgrave_texture");
} }
@@ -1135,8 +1135,8 @@ void WaveTextureNode::compile(OSLCompiler& compiler)
{ {
tex_mapping.compile(compiler); tex_mapping.compile(compiler);
compiler.parameter("Type", type); compiler.parameter("type", type);
compiler.parameter("Profile", profile); compiler.parameter("profile", profile);
compiler.add(this, "node_wave_texture"); compiler.add(this, "node_wave_texture");
} }
@@ -1186,7 +1186,7 @@ void MagicTextureNode::compile(OSLCompiler& compiler)
{ {
tex_mapping.compile(compiler); tex_mapping.compile(compiler);
compiler.parameter("Depth", depth); compiler.parameter("depth", depth);
compiler.add(this, "node_magic_texture"); compiler.add(this, "node_magic_texture");
} }
@@ -1311,10 +1311,10 @@ void BrickTextureNode::compile(OSLCompiler& compiler)
{ {
tex_mapping.compile(compiler); tex_mapping.compile(compiler);
compiler.parameter("Offset", offset); compiler.parameter("offset", offset);
compiler.parameter("OffsetFrequency", offset_frequency); compiler.parameter("offset_frequency", offset_frequency);
compiler.parameter("Squash", squash); compiler.parameter("squash", squash);
compiler.parameter("SquashFrequency", squash_frequency); compiler.parameter("squash_frequency", squash_frequency);
compiler.add(this, "node_brick_texture"); compiler.add(this, "node_brick_texture");
} }
@@ -1504,7 +1504,7 @@ void NormalNode::compile(SVMCompiler& compiler)
void NormalNode::compile(OSLCompiler& compiler) void NormalNode::compile(OSLCompiler& compiler)
{ {
compiler.parameter_normal("Direction", direction); compiler.parameter_normal("direction", direction);
compiler.add(this, "node_normal"); compiler.add(this, "node_normal");
} }
@@ -1536,6 +1536,40 @@ void MappingNode::compile(OSLCompiler& compiler)
compiler.add(this, "node_mapping"); compiler.add(this, "node_mapping");
} }
/* RGBToBW */
RGBToBWNode::RGBToBWNode()
: ShaderNode("rgb_to_bw")
{
add_input("Color", SocketType::COLOR);
add_output("Val", SocketType::FLOAT);
}
bool RGBToBWNode::constant_fold(ShaderGraph * /*graph*/,
ShaderOutput * /*socket*/,
float3 *optimized_value)
{
if(inputs[0]->link == NULL) {
optimized_value->x = linear_rgb_to_gray(inputs[0]->value());
return true;
}
return false;
}
void RGBToBWNode::compile(SVMCompiler& compiler)
{
compiler.add_node(NODE_CONVERT,
NODE_CONVERT_CF,
compiler.stack_assign(inputs[0]),
compiler.stack_assign(outputs[0]));
}
void RGBToBWNode::compile(OSLCompiler& compiler)
{
compiler.add(this, "node_convert_from_color");
}
/* Convert */ /* Convert */
ConvertNode::ConvertNode(SocketType::Type from_, SocketType::Type to_, bool autoconvert) ConvertNode::ConvertNode(SocketType::Type from_, SocketType::Type to_, bool autoconvert)
@@ -1552,40 +1586,40 @@ ConvertNode::ConvertNode(SocketType::Type from_, SocketType::Type to_, bool auto
} }
if(from == SocketType::FLOAT) if(from == SocketType::FLOAT)
add_input("Val", SocketType::FLOAT); add_input("value_float", SocketType::FLOAT);
else if(from == SocketType::INT) else if(from == SocketType::INT)
add_input("ValInt", SocketType::INT); add_input("value_int", SocketType::INT);
else if(from == SocketType::COLOR) else if(from == SocketType::COLOR)
add_input("Color", SocketType::COLOR); add_input("value_color", SocketType::COLOR);
else if(from == SocketType::VECTOR) else if(from == SocketType::VECTOR)
add_input("Vector", SocketType::VECTOR); add_input("value_vector", SocketType::VECTOR);
else if(from == SocketType::POINT) else if(from == SocketType::POINT)
add_input("Point", SocketType::POINT); add_input("value_point", SocketType::POINT);
else if(from == SocketType::NORMAL) else if(from == SocketType::NORMAL)
add_input("Normal", SocketType::NORMAL); add_input("value_normal", SocketType::NORMAL);
else if(from == SocketType::STRING) else if(from == SocketType::STRING)
add_input("String", SocketType::STRING); add_input("value_string", SocketType::STRING);
else if(from == SocketType::CLOSURE) else if(from == SocketType::CLOSURE)
add_input("Closure", SocketType::CLOSURE); add_input("value_closure", SocketType::CLOSURE);
else else
assert(0); assert(0);
if(to == SocketType::FLOAT) if(to == SocketType::FLOAT)
add_output("Val", SocketType::FLOAT); add_output("value_float", SocketType::FLOAT);
else if(to == SocketType::INT) else if(to == SocketType::INT)
add_output("ValInt", SocketType::INT); add_output("value_int", SocketType::INT);
else if(to == SocketType::COLOR) else if(to == SocketType::COLOR)
add_output("Color", SocketType::COLOR); add_output("value_color", SocketType::COLOR);
else if(to == SocketType::VECTOR) else if(to == SocketType::VECTOR)
add_output("Vector", SocketType::VECTOR); add_output("value_vector", SocketType::VECTOR);
else if(to == SocketType::POINT) else if(to == SocketType::POINT)
add_output("Point", SocketType::POINT); add_output("value_point", SocketType::POINT);
else if(to == SocketType::NORMAL) else if(to == SocketType::NORMAL)
add_output("Normal", SocketType::NORMAL); add_output("value_normal", SocketType::NORMAL);
else if(to == SocketType::STRING) else if(to == SocketType::STRING)
add_output("String", SocketType::STRING); add_output("value_string", SocketType::STRING);
else if(to == SocketType::CLOSURE) else if(to == SocketType::CLOSURE)
add_output("Closure", SocketType::CLOSURE); add_output("value_closure", SocketType::CLOSURE);
else else
assert(0); assert(0);
} }
@@ -2176,7 +2210,7 @@ void SubsurfaceScatteringNode::compile(SVMCompiler& compiler)
void SubsurfaceScatteringNode::compile(OSLCompiler& compiler) void SubsurfaceScatteringNode::compile(OSLCompiler& compiler)
{ {
compiler.parameter("Falloff", falloff_enum[closure]); compiler.parameter("falloff", falloff_enum[closure]);
compiler.add(this, "node_subsurface_scattering"); compiler.add(this, "node_subsurface_scattering");
} }
@@ -3366,7 +3400,7 @@ void MixNode::compile(SVMCompiler& compiler)
void MixNode::compile(OSLCompiler& compiler) void MixNode::compile(OSLCompiler& compiler)
{ {
compiler.parameter("type", type); compiler.parameter("type", type);
compiler.parameter("Clamp", use_clamp); compiler.parameter("use_clamp", use_clamp);
compiler.add(this, "node_mix"); compiler.add(this, "node_mix");
} }
@@ -4128,7 +4162,7 @@ void MathNode::compile(SVMCompiler& compiler)
void MathNode::compile(OSLCompiler& compiler) void MathNode::compile(OSLCompiler& compiler)
{ {
compiler.parameter("type", type); compiler.parameter("type", type);
compiler.parameter("Clamp", use_clamp); compiler.parameter("use_clamp", use_clamp);
compiler.add(this, "node_math"); compiler.add(this, "node_math");
} }
@@ -4477,7 +4511,7 @@ void RGBRampNode::compile(OSLCompiler& compiler)
compiler.parameter_color_array("ramp_color", ramp); compiler.parameter_color_array("ramp_color", ramp);
compiler.parameter_array("ramp_alpha", ramp_alpha.data(), ramp_alpha.size()); compiler.parameter_array("ramp_alpha", ramp_alpha.data(), ramp_alpha.size());
compiler.parameter("ramp_interpolate", interpolate); compiler.parameter("interpolate", interpolate);
compiler.add(this, "node_rgb_ramp"); compiler.add(this, "node_rgb_ramp");
} }

View File

@@ -362,6 +362,13 @@ public:
} }
}; };
class RGBToBWNode : public ShaderNode {
public:
SHADER_NODE_CLASS(RGBToBWNode)
bool constant_fold(ShaderGraph *graph, ShaderOutput *socket, float3 *optimized_value);
};
class ConvertNode : public ShaderNode { class ConvertNode : public ShaderNode {
public: public:
ConvertNode(SocketType::Type from, SocketType::Type to, bool autoconvert = false); ConvertNode(SocketType::Type from, SocketType::Type to, bool autoconvert = false);