Skip to content

Commit

Permalink
Add lots of new MaterialX 1.36 support
Browse files Browse the repository at this point in the history
Add sin, cos, tan, atan2, ceil, sqrt, exp, determinent, ln, and
transpose operators

Rename exponent operator to power

Rename pack to combine

add extract operator

Add conversion operators:
color2->vector2
color->vector
color4->vector4
vector2->color2
vector->color
vector4->color4

Matrix inversion operator.
  • Loading branch information
derekhaase authored and lgritz committed Jul 21, 2018
1 parent de63270 commit 4d3d0c4
Show file tree
Hide file tree
Showing 29 changed files with 485 additions and 60 deletions.
Binary file added src/shaders/.DS_Store
Binary file not shown.
34 changes: 20 additions & 14 deletions src/shaders/MaterialX/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,25 +100,26 @@ endmacro()

# MX shaders that come in flavors for all color/vector types, and float.
make_mx_flavors (
mx_absval.mx mx_add.mx mx_blur.mx mx_clamp.mx mx_compare.mx
mx_constant.mx mx_contrast.mx mx_divide.mx mx_dot.mx
mx_exponent.mx mx_floor.mx mx_fractal3d.mx mx_geomattrvalue.mx
mx_image.mx mx_invert.mx mx_max.mx mx_min.mx mx_mix.mx
mx_modulo.mx mx_multiply.mx mx_noise2d.mx mx_noise3d.mx
mx_absval.mx mx_acos.mx mx_add.mx mx_asin.mx mx_atan2.mx
mx_blur.mx mx_ceil.mx mx_clamp.mx mx_compare.mx
mx_constant.mx mx_contrast.mx mx_cos.mx mx_dot.mx
mx_exp.mx mx_power.mx mx_floor.mx mx_fractal3d.mx mx_geomattrvalue.mx
mx_image.mx mx_invert.mx mx_ln.mx mx_max.mx mx_min.mx mx_mix.mx
mx_modulo.mx mx_noise2d.mx mx_noise3d.mx
mx_ramp4.mx mx_ramplr.mx mx_ramptb.mx mx_remap.mx
mx_smoothstep.mx mx_splitlr.mx mx_splittb.mx mx_subtract.mx
mx_sin.mx mx_smoothstep.mx mx_splitlr.mx mx_splittb.mx mx_sqrt.mx mx_subtract.mx
mx_switch.mx mx_swizzle_color.mx mx_swizzle_color2.mx
mx_swizzle_color4.mx mx_swizzle_vector.mx mx_swizzle_vector2.mx
mx_swizzle_vector4.mx mx_triplanarprojection.mx
mx_swizzle_vector4.mx mx_tan.mx mx_triplanarprojection.mx
TYPES float color color2 color4 vector vector2 vector4)

# MX shaders that come in flavors for all color/vector types.
make_mx_flavors (
mx_add_float.mx mx_clamp_float.mx mx_contrast_float.mx
mx_divide_float.mx mx_exponent_float.mx mx_fractal3d_fa.mx
mx_add_float.mx mx_atan2_float.mx mx_clamp_float.mx mx_contrast_float.mx
mx_divide_float.mx mx_power_float.mx mx_fractal3d_fa.mx
mx_invert_float.mx mx_max_float.mx mx_min_float.mx
mx_modulo_float.mx mx_multiply_float.mx mx_noise2d_fa.mx
mx_noise3d_fa.mx mx_pack.mx mx_remap_float.mx
mx_noise3d_fa.mx mx_remap_float.mx
mx_smoothstep_float.mx mx_subtract_float.mx mx_swizzle_float.mx
TYPES color color2 color4 vector vector2 vector4)

Expand All @@ -136,6 +137,7 @@ make_mx_flavors (mx_cellnoise2d.mx TYPES float)
make_mx_flavors (mx_cellnoise3d.mx TYPES float)
make_mx_flavors (mx_constant.mx TYPES matrix44 matrix33 string filename bool int)
make_mx_flavors (mx_crossproduct.mx TYPES vector)
make_mx_flavors (mx_determinant.mx TYPES matrix44 matrix33)
make_mx_flavors (mx_disjointover.mx TYPES color2 color4)
make_mx_flavors (mx_dot.mx TYPES matrix44 matrix33 string filename bool int surfaceshader)
make_mx_flavors (mx_dotproduct.mx TYPES vector vector2 vector4)
Expand All @@ -154,10 +156,10 @@ make_mx_flavors (mx_normal.mx TYPES vector)
make_mx_flavors (mx_normalize.mx TYPES vector vector2 vector4)
make_mx_flavors (mx_out.mx TYPES color2 color4)
make_mx_flavors (mx_over.mx TYPES color2 color4)
make_mx_flavors (mx_pack_cc.mx TYPES color4)
make_mx_flavors (mx_pack_cf.mx TYPES color4)
make_mx_flavors (mx_pack_vf.mx TYPES vector4)
make_mx_flavors (mx_pack_vv.mx TYPES vector4)
make_mx_flavors (mx_combine_cc.mx TYPES color4)
make_mx_flavors (mx_combine_cf.mx TYPES color4)
make_mx_flavors (mx_combine_vf.mx TYPES vector4)
make_mx_flavors (mx_combine_vv.mx TYPES vector4)
make_mx_flavors (mx_position.mx TYPES vector)
make_mx_flavors (mx_premult.mx TYPES color color2 color4)
make_mx_flavors (mx_rotate2d.mx TYPES vector2)
Expand All @@ -166,7 +168,11 @@ make_mx_flavors (mx_scale.mx TYPES vector vector2)
make_mx_flavors (mx_tangent.mx TYPES vector)
make_mx_flavors (mx_texcoord.mx TYPES vector vector2)
make_mx_flavors (mx_time.mx TYPES float)
make_mx_flavors (mx_transpose.mx TYPES matrix44 matrix33)
make_mx_flavors (mx_unpremult.mx TYPES color color2 color4)
make_mx_flavors (mx_matrix_invert.mx TYPES matrix44 matrix33)
make_mx_flavors (mx_divide.mx TYPES float color color2 color4 vector vector2 vector4 matrix44 matrix33)
make_mx_flavors (mx_multiply.mx TYPES float color color2 color4 vector vector2 vector4 matrix44 matrix33)


add_custom_target (mxshaders ALL
Expand Down
34 changes: 24 additions & 10 deletions src/shaders/MaterialX/build_materialX_osl.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,29 +195,38 @@

BUILD_DICT = {
'mx_absval': ALL_TYPES,
'mx_acos' : ALL_TYPES,
'mx_add': ALL_TYPES + ['surfaceshader'],
'mx_add_float': ['color', 'color2', 'color4', 'vector', 'vector2', 'vector4'],
'mx_asin' : ALL_TYPES,
'mx_atan2' : ALL_TYPES,
'mx_atan2_float' : ALL_TYPES,
'mx_ambientocclusion': ['float'],
'mx_bitangent': ['vector'],
'mx_blur': ALL_TYPES,
'mx_burn': ['float', 'color', 'color2', 'color4'],
'mx_ceil' : ALL_TYPES,
'mx_cellnoise2d': ['float'],
'mx_cellnoise3d': ['float'],
'mx_clamp': ALL_TYPES,
'mx_clamp_float': ['color', 'color2', 'color4', 'vector', 'vector2', 'vector4'],
'mx_compare': ALL_TYPES,
'mx_constant': ALL_TYPES + ['matrix44', 'matrix33', 'string', 'filename', 'bool', 'int'],
'mx_cos': ALL_TYPES,
'mx_crossproduct': ['vector'],
'mx_determinant' : ['matrix44', 'matrix33'],
'mx_dodge': ['float', 'color', 'color2', 'color4'],
'mx_dotproduct': ['vector', 'vector2', 'vector4'],
'mx_dot': ALL_TYPES + ['matrix44', 'matrix33', 'string', 'filename', 'bool', 'int', 'surfaceshader'],
'mx_exp' : ALL_TYPES + ['int'],
'mx_floor': ALL_TYPES,
'mx_frame': ['float'],
'mx_geomattrvalue': ALL_TYPES + ['bool', 'string', 'int'],
'mx_geomcolor': ['float', 'color', 'color2', 'color4'],
'mx_heighttonormal': ['vector'],
'mx_hueshift': ['color', 'color4'],
'mx_image': ALL_TYPES,
'mx_ln' : ALL_TYPES + ['int'],
'mx_max': ALL_TYPES,
'mx_min': ALL_TYPES,
'mx_overlay': ['float', 'color', 'color2', 'color4'],
Expand All @@ -237,10 +246,10 @@
'mx_contrast_float': ['color', 'color2', 'color4', 'vector', 'vector2', 'vector4'],
'mx_smoothstep': ALL_TYPES,
'mx_smoothstep_float': ['color', 'color2', 'color4', 'vector', 'vector2', 'vector4'],
'mx_divide': ALL_TYPES,
'mx_divide': ALL_TYPES + ['matrix44', 'matrix33'],
'mx_divide_float': ['color', 'color2', 'color4', 'vector', 'vector2', 'vector4'],
'mx_exponent': ALL_TYPES,
'mx_exponent_float': ['color', 'color2', 'color4', 'vector', 'vector2', 'vector4'],
'mx_power': ALL_TYPES,
'mx_power_float': ['color', 'color2', 'color4', 'vector', 'vector2', 'vector4'],
'mx_invert': ALL_TYPES,
'mx_invert_float': ['color', 'color2', 'color4', 'vector', 'vector2', 'vector4'],
'mx_luminance': ['color', 'color4'],
Expand All @@ -251,19 +260,19 @@
'mx_min_float': ['color', 'color2', 'color4', 'vector', 'vector2', 'vector4'],
'mx_modulo': ALL_TYPES,
'mx_modulo_float': ['color', 'color2', 'color4', 'vector', 'vector2', 'vector4'],
'mx_multiply': ALL_TYPES,
'mx_multiply': ALL_TYPES + ['matrix44', 'matrix33'],
'mx_multiply_float':['color', 'color2', 'color4', 'vector', 'vector2', 'vector4'],
'mx_noise2d': ALL_TYPES,
'mx_noise2d_fa':['color', 'color2', 'color4', 'vector', 'vector2', 'vector4'],
'mx_noise3d': ALL_TYPES,
'mx_noise3d_fa':['color', 'color2', 'color4', 'vector', 'vector2', 'vector4'],
'mx_normal': ['vector'],
'mx_normalize': ['vector', 'vector2', 'vector4'],
'mx_pack': ['color', 'color2', 'color4', 'vector', 'vector2', 'vector4'],
'mx_pack_cf': ['color4'],
'mx_pack_cc': ['color4'],
'mx_pack_vf': ['vector4'],
'mx_pack_vv': ['vector4'],
'mx_combine': ['color', 'color2', 'color4', 'vector', 'vector2', 'vector4'],
'mx_combine_cf': ['color4'],
'mx_combine_cc': ['color4'],
'mx_combine_vf': ['vector4'],
'mx_combine_vv': ['vector4'],
'mx_position': ['vector'],
'mx_premult': ['color', 'color2', 'color4'],
'mx_ramp4': ALL_TYPES,
Expand All @@ -274,8 +283,10 @@
'mx_rotate2d': ['vector2'],
'mx_saturate': ['color', 'color4'],
'mx_scale': ['vector', 'vector2'],
'mx_sin': ALL_TYPES,
'mx_splitlr': ALL_TYPES,
'mx_splittb': ALL_TYPES,
'mx_sqrt' : ALL_TYPES,
'mx_subtract': ALL_TYPES,
'mx_subtract_float': ['color', 'color2', 'color4', 'vector', 'vector2', 'vector4'],
'mx_swizzle_float': ['color', 'color2', 'color4', 'vector', 'vector2', 'vector4'],
Expand All @@ -286,12 +297,15 @@
'mx_swizzle_vector2': ALL_TYPES,
'mx_swizzle_vector4': ALL_TYPES,
'mx_switch': ALL_TYPES,
'mx_tan': ALL_TYPES,
'mx_tangent': ['vector'],
'mx_texcoord': ['vector', 'vector2'],
'mx_time': ['float'],
'mx_transpose' : ['matrix44', 'matrix33'],
'mx_triplanarprojection': ALL_TYPES,
'mx_unpremult': ['color', 'color2', 'color4'],
'mx_mult_surfaceshader': ['color', 'float']
'mx_mult_surfaceshader': ['color', 'float'],
'mx_matrix_invert' : ['matrix44', 'matrix33'],
}

# open_mx_file: open a file on disk and return its contents
Expand Down
17 changes: 17 additions & 0 deletions src/shaders/MaterialX/mx_acos.mx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Open Shading Language : Copyright (c) 2009-2017 Sony Pictures Imageworks Inc., et al.
// https://github.com/imageworks/OpenShadingLanguage/blob/master/LICENSE
//
// MaterialX specification (c) 2017 Lucasfilm Ltd.
// http://www.materialx.org/

#include "mx_funcs.h"

shader mx_acos_TYPE_SUFFIX
[[ string help = TYPE_STR" acos(in)" ]]
(
TYPE in = TYPE_DEFAULT_IN,
output TYPE out = TYPE_DEFAULT_OUT
)
{
out = acos(in);
}
17 changes: 17 additions & 0 deletions src/shaders/MaterialX/mx_asin.mx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Open Shading Language : Copyright (c) 2009-2017 Sony Pictures Imageworks Inc., et al.
// https://github.com/imageworks/OpenShadingLanguage/blob/master/LICENSE
//
// MaterialX specification (c) 2017 Lucasfilm Ltd.
// http://www.materialx.org/

#include "mx_funcs.h"

shader mx_asin_TYPE_SUFFIX
[[ string help = TYPE_STR" asin(in)" ]]
(
TYPE in = TYPE_DEFAULT_IN,
output TYPE out = TYPE_DEFAULT_OUT
)
{
out = asin(in);
}
19 changes: 19 additions & 0 deletions src/shaders/MaterialX/mx_atan2.mx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Open Shading Language : Copyright (c) 2009-2017 Sony Pictures Imageworks Inc., et al.
// https://github.com/imageworks/OpenShadingLanguage/blob/master/LICENSE
//
// MaterialX specification (c) 2017 Lucasfilm Ltd.
// http://www.materialx.org/

#include "mx_funcs.h"

shader mx_atan2_TYPE_SUFFIX
[[ string help = TYPE_STR" atan2(in1, in2)" ]]
(
TYPE in1 = TYPE_DEFAULT_IN,
TYPE in2 = TYPE_DEFAULT_IN,

output TYPE out = TYPE_DEFAULT_OUT
)
{
out = atan2(in1, in2);
}
19 changes: 19 additions & 0 deletions src/shaders/MaterialX/mx_atan2_float.mx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Open Shading Language : Copyright (c) 2009-2017 Sony Pictures Imageworks Inc., et al.
// https://github.com/imageworks/OpenShadingLanguage/blob/master/LICENSE
//
// MaterialX specification (c) 2017 Lucasfilm Ltd.
// http://www.materialx.org/

#include "mx_funcs.h"

shader mx_atan2_float_TYPE_SUFFIX
[[ string help = TYPE_STR" atan2(in1, in2)" ]]
(
TYPE in1 = TYPE_DEFAULT_IN,
float in2 = 0.0,

output TYPE out = TYPE_DEFAULT_OUT
)
{
out = atan2(in1, in2);
}
17 changes: 17 additions & 0 deletions src/shaders/MaterialX/mx_ceil.mx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Open Shading Language : Copyright (c) 2009-2017 Sony Pictures Imageworks Inc., et al.
// https://github.com/imageworks/OpenShadingLanguage/blob/master/LICENSE
//
// MaterialX specification (c) 2017 Lucasfilm Ltd.
// http://www.materialx.org/

#include "mx_funcs.h"

shader mx_ceil_TYPE_SUFFIX
[[ string help = TYPE_STR" Find the smallest integer less than or equal to the parameter." ]]
(
TYPE in = TYPE_DEFAULT_IN,
output TYPE out = TYPE_DEFAULT_OUT
)
{
out = ceil(in);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "mx_funcs.h"

shader mx_pack_TYPE_SUFFIX
[[ string help = "Pack the channels from two, three or four streams into the same number of channels of a \
[[ string help = "Combine the channels from two, three or four streams into the same number of channels of a \
single stream of a specified compatible type;" ]]
(
float in1 = 0,
Expand All @@ -18,5 +18,5 @@ shader mx_pack_TYPE_SUFFIX
output TYPE out = TYPE_ZERO
)
{
out = pack (in1, in2, in3, in4);
out = combine (in1, in2, in3, in4);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

#include "mx_funcs.h"

shader mx_pack_cc_TYPE_SUFFIX
[[ string help = "Pack the channels from two, three or four streams into the same number of channels of a \
shader mx_combine_cc_TYPE_SUFFIX
[[ string help = "Combine the channels from two, three or four streams into the same number of channels of a \
single stream of a specified compatible type;" ]]
(
color2 in1 = {0,0},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

#include "mx_funcs.h"

shader mx_pack_cf_TYPE_SUFFIX
[[ string help = "Pack the channels from two, three or four streams into the same number of channels of a \
shader mx_combine_cf_TYPE_SUFFIX
[[ string help = "Combine the channels from two, three or four streams into the same number of channels of a \
single stream of a specified compatible type;" ]]
(
color in1 = 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

#include "mx_funcs.h"

shader mx_pack_vf_TYPE_SUFFIX
[[ string help = "Pack the channels from two, three or four streams into the same number of channels of a \
shader mx_combine_vf_TYPE_SUFFIX
[[ string help = "Combine the channels from two, three or four streams into the same number of channels of a \
single stream of a specified compatible type;" ]]
(
vector in1 = 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

#include "mx_funcs.h"

shader mx_pack_vv_TYPE_SUFFIX
[[ string help = "Pack the channels from two, three or four streams into the same number of channels of a \
shader mx_combine_vv_TYPE_SUFFIX
[[ string help = "Combine the channels from two, three or four streams into the same number of channels of a \
single stream of a specified compatible type;" ]]
(
vector2 in1 = {0,0},
Expand Down
17 changes: 17 additions & 0 deletions src/shaders/MaterialX/mx_cos.mx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Open Shading Language : Copyright (c) 2009-2017 Sony Pictures Imageworks Inc., et al.
// https://github.com/imageworks/OpenShadingLanguage/blob/master/LICENSE
//
// MaterialX specification (c) 2017 Lucasfilm Ltd.
// http://www.materialx.org/

#include "mx_funcs.h"

shader mx_cos_TYPE_SUFFIX
[[ string help = TYPE_STR" cos(in)" ]]
(
TYPE in = TYPE_DEFAULT_IN,
output TYPE out = TYPE_DEFAULT_OUT
)
{
out = cos(in);
}
17 changes: 17 additions & 0 deletions src/shaders/MaterialX/mx_determinant.mx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Open Shading Language : Copyright (c) 2009-2017 Sony Pictures Imageworks Inc., et al.
// https://github.com/imageworks/OpenShadingLanguage/blob/master/LICENSE
//
// MaterialX specification (c) 2017 Lucasfilm Ltd.
// http://www.materialx.org/

#include "mx_funcs.h"

shader mx_determinant_TYPE_SUFFIX
[[ string help = TYPE_STR" the determinant of matrix in" ]]
(
TYPE in = TYPE_DEFAULT_IN,
output float out = 0
)
{
out = determinant(in);
}
17 changes: 17 additions & 0 deletions src/shaders/MaterialX/mx_exp.mx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Open Shading Language : Copyright (c) 2009-2017 Sony Pictures Imageworks Inc., et al.
// https://github.com/imageworks/OpenShadingLanguage/blob/master/LICENSE
//
// MaterialX specification (c) 2017 Lucasfilm Ltd.
// http://www.materialx.org/

#include "mx_funcs.h"

shader exp_TYPE_SUFFIX
[[ string help = TYPE_STR" e(in)" ]]
(
TYPE in = TYPE_DEFAULT_IN,
output TYPE out = TYPE_DEFAULT_OUT
)
{
out = exp(in);
}
Loading

0 comments on commit 4d3d0c4

Please sign in to comment.