diff --git a/javascript/MaterialXView/source/viewer.js b/javascript/MaterialXView/source/viewer.js
index b0bcd98fbf..3eff576be3 100644
--- a/javascript/MaterialXView/source/viewer.js
+++ b/javascript/MaterialXView/source/viewer.js
@@ -949,11 +949,17 @@ export class Material
}
var step = 0;
var enumList = []
+ var enumValues = []
if (nodeDefInput)
{
if (nodeDefInput.hasAttribute('enum'))
{
+ // Get enum and enum values attributes (if present)
enumList = nodeDefInput.getAttribute('enum').split(',');
+ if (nodeDefInput.hasAttribute('enumvalues'))
+ {
+ enumValues = nodeDefInput.getAttribute('enumvalues').split(',').map(Number);
+ }
}
else
{
@@ -989,8 +995,30 @@ export class Material
}
else
{
- // TODO: Add enum support
- currentFolder.add(material.uniforms[name], 'value' ).name(path);
+ // Map enumList strings to values
+ // Map to 0..N if no values are specified via enumvalues attribute
+ if (enumValues.length == 0)
+ {
+ for (let i = 0; i < enumList.length; ++i)
+ {
+ enumValues.push(i);
+ }
+ }
+ const enumeration = {};
+ enumList.forEach((str, index) => {
+ enumeration[str] = enumValues[index];
+ });
+
+ // Function to handle enum drop-down
+ function handleDropdownChange(value) {
+ if (material.uniforms[name])
+ {
+ material.uniforms[name].value = value;
+ }
+ }
+ const defaultOption = enumList[value]; // Set the default selected option
+ const dropdownController = gui.add(enumeration, defaultOption, enumeration).name(path);
+ dropdownController.onChange(handleDropdownChange);
}
}
break;
@@ -1046,7 +1074,7 @@ export class Material
break;
case 'color3':
- // Irksome way to mape arrays to colors and back
+ // Irksome way to map arrays to colors and back
uniformToUpdate = material.uniforms[name];
if (uniformToUpdate && value != null)
{
diff --git a/libraries/nprlib/genglsl/nprlib_genglsl_impl.mtlx b/libraries/nprlib/genglsl/nprlib_genglsl_impl.mtlx
new file mode 100644
index 0000000000..7ddc4cee83
--- /dev/null
+++ b/libraries/nprlib/genglsl/nprlib_genglsl_impl.mtlx
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/libraries/nprlib/genmdl/nprlib_genmdl_impl.mtlx b/libraries/nprlib/genmdl/nprlib_genmdl_impl.mtlx
new file mode 100644
index 0000000000..b6472e0c51
--- /dev/null
+++ b/libraries/nprlib/genmdl/nprlib_genmdl_impl.mtlx
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/libraries/nprlib/genmsl/nprlib_genmsl_impl.mtlx b/libraries/nprlib/genmsl/nprlib_genmsl_impl.mtlx
new file mode 100644
index 0000000000..b8f9a4e3aa
--- /dev/null
+++ b/libraries/nprlib/genmsl/nprlib_genmsl_impl.mtlx
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/libraries/nprlib/genosl/nprlib_genosl_impl.mtlx b/libraries/nprlib/genosl/nprlib_genosl_impl.mtlx
new file mode 100644
index 0000000000..0b077b6406
--- /dev/null
+++ b/libraries/nprlib/genosl/nprlib_genosl_impl.mtlx
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/libraries/nprlib/nprlib_defs.mtlx b/libraries/nprlib/nprlib_defs.mtlx
new file mode 100644
index 0000000000..e724658ae5
--- /dev/null
+++ b/libraries/nprlib/nprlib_defs.mtlx
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/libraries/stdlib/genglsl/mx_creatematrix_vector3_matrix33.glsl b/libraries/stdlib/genglsl/mx_creatematrix_vector3_matrix33.glsl
new file mode 100644
index 0000000000..aa10ef5b98
--- /dev/null
+++ b/libraries/stdlib/genglsl/mx_creatematrix_vector3_matrix33.glsl
@@ -0,0 +1,6 @@
+void mx_creatematrix_vector3_matrix33(vec3 in1, vec3 in2, vec3 in3, out mat3 result)
+{
+ result = mat3(in1.x, in1.y, in1.z,
+ in2.x, in2.y, in2.z,
+ in3.x, in3.y, in3.z);
+}
diff --git a/libraries/stdlib/genglsl/mx_creatematrix_vector3_matrix44.glsl b/libraries/stdlib/genglsl/mx_creatematrix_vector3_matrix44.glsl
new file mode 100644
index 0000000000..194fad421a
--- /dev/null
+++ b/libraries/stdlib/genglsl/mx_creatematrix_vector3_matrix44.glsl
@@ -0,0 +1,7 @@
+void mx_creatematrix_vector3_matrix44(vec3 in1, vec3 in2, vec3 in3, vec3 in4, out mat4 result)
+{
+ result = mat4(in1.x, in1.y, in1.z, 0.0,
+ in2.x, in2.y, in2.z, 0.0,
+ in3.x, in3.y, in3.z, 0.0,
+ in4.x, in4.y, in4.z, 1.0);
+}
diff --git a/libraries/stdlib/genglsl/mx_creatematrix_vector4_matrix44.glsl b/libraries/stdlib/genglsl/mx_creatematrix_vector4_matrix44.glsl
new file mode 100644
index 0000000000..665a22212b
--- /dev/null
+++ b/libraries/stdlib/genglsl/mx_creatematrix_vector4_matrix44.glsl
@@ -0,0 +1,7 @@
+void mx_creatematrix_vector4_matrix44(vec4 in1, vec4 in2, vec4 in3, vec4 in4, out mat4 result)
+{
+ result = mat4(in1.x, in1.y, in1.z, in1.w,
+ in2.x, in2.y, in2.z, in2.w,
+ in3.x, in3.y, in3.z, in3.w,
+ in4.x, in4.y, in4.z, in4.w);
+}
diff --git a/libraries/stdlib/genglsl/stdlib_genglsl_impl.mtlx b/libraries/stdlib/genglsl/stdlib_genglsl_impl.mtlx
index 07aae6ce66..6f67b21d33 100644
--- a/libraries/stdlib/genglsl/stdlib_genglsl_impl.mtlx
+++ b/libraries/stdlib/genglsl/stdlib_genglsl_impl.mtlx
@@ -748,6 +748,11 @@
+
+
+
+
+
diff --git a/libraries/stdlib/genmdl/stdlib_genmdl_impl.mtlx b/libraries/stdlib/genmdl/stdlib_genmdl_impl.mtlx
index 022f0896f1..6c550c92db 100644
--- a/libraries/stdlib/genmdl/stdlib_genmdl_impl.mtlx
+++ b/libraries/stdlib/genmdl/stdlib_genmdl_impl.mtlx
@@ -754,6 +754,11 @@
+
+
+
+
+
diff --git a/libraries/stdlib/genmsl/stdlib_genmsl_impl.mtlx b/libraries/stdlib/genmsl/stdlib_genmsl_impl.mtlx
index dea1c49636..40be6f8c46 100644
--- a/libraries/stdlib/genmsl/stdlib_genmsl_impl.mtlx
+++ b/libraries/stdlib/genmsl/stdlib_genmsl_impl.mtlx
@@ -748,6 +748,11 @@
+
+
+
+
+
diff --git a/libraries/stdlib/genosl/mx_creatematrix.osl b/libraries/stdlib/genosl/mx_creatematrix.osl
new file mode 100644
index 0000000000..933dce00ba
--- /dev/null
+++ b/libraries/stdlib/genosl/mx_creatematrix.osl
@@ -0,0 +1,23 @@
+void mx_creatematrix_vector3_matrix33(vector in1, vector in2, vector in3, out matrix result)
+{
+ result = matrix(in1.x, in1.y, in1.z, 0.0,
+ in2.x, in2.y, in2.z, 0.0,
+ in3.x, in3.y, in3.z, 0.0,
+ 0.0, 0.0, 0.0, 1.0);
+}
+
+void mx_creatematrix_vector3_matrix44(vector3 in1, vector3 in2, vector3 in3, vector3 in4, out matrix result)
+{
+ result = matrix(in1.x, in1.y, in1.z, 0.0,
+ in2.x, in2.y, in2.z, 0.0,
+ in3.x, in3.y, in3.z, 0.0,
+ in4.x, in4.y, in4.z, 1.0);
+}
+
+void mx_creatematrix_vector4_matrix44(vector4 in1, vector4 in2, vector4 in3, vector4 in4, out matrix result)
+{
+ result = matrix(in1.x, in1.y, in1.z, in1.w,
+ in2.x, in2.y, in2.z, in2.w,
+ in3.x, in3.y, in3.z, in3.w,
+ in4.x, in4.y, in4.z, in4.w);
+}
diff --git a/libraries/stdlib/genosl/stdlib_genosl_impl.mtlx b/libraries/stdlib/genosl/stdlib_genosl_impl.mtlx
index 42828ce641..a984d912b8 100644
--- a/libraries/stdlib/genosl/stdlib_genosl_impl.mtlx
+++ b/libraries/stdlib/genosl/stdlib_genosl_impl.mtlx
@@ -751,6 +751,11 @@
+
+
+
+
+
diff --git a/libraries/stdlib/stdlib_defs.mtlx b/libraries/stdlib/stdlib_defs.mtlx
index 3f187e2be1..90ccb57a98 100644
--- a/libraries/stdlib/stdlib_defs.mtlx
+++ b/libraries/stdlib/stdlib_defs.mtlx
@@ -4359,6 +4359,33 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
-
+
@@ -46,11 +39,11 @@
-
+
-
-
-
+
+
+
diff --git a/resources/Materials/TestSuite/_options.mtlx b/resources/Materials/TestSuite/_options.mtlx
index bb29fbd7c1..1da00394e6 100644
--- a/resources/Materials/TestSuite/_options.mtlx
+++ b/resources/Materials/TestSuite/_options.mtlx
@@ -91,7 +91,7 @@
-
+
diff --git a/resources/Materials/TestSuite/nprlib/edge_brighten.mtlx b/resources/Materials/TestSuite/nprlib/edge_brighten.mtlx
new file mode 100644
index 0000000000..7e9aca7f22
--- /dev/null
+++ b/resources/Materials/TestSuite/nprlib/edge_brighten.mtlx
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/resources/Materials/TestSuite/nprlib/starfield.mtlx b/resources/Materials/TestSuite/nprlib/starfield.mtlx
new file mode 100644
index 0000000000..6898054a6d
--- /dev/null
+++ b/resources/Materials/TestSuite/nprlib/starfield.mtlx
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/resources/Materials/TestSuite/stdlib/math/matrix.mtlx b/resources/Materials/TestSuite/stdlib/math/matrix.mtlx
new file mode 100644
index 0000000000..4bcb555739
--- /dev/null
+++ b/resources/Materials/TestSuite/stdlib/math/matrix.mtlx
@@ -0,0 +1,29 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/source/MaterialXGenGlsl/GlslShaderGenerator.cpp b/source/MaterialXGenGlsl/GlslShaderGenerator.cpp
index e506c700c7..5b20ee1b03 100644
--- a/source/MaterialXGenGlsl/GlslShaderGenerator.cpp
+++ b/source/MaterialXGenGlsl/GlslShaderGenerator.cpp
@@ -14,6 +14,7 @@
#include
#include
#include
+#include
#include
#include
#include
@@ -196,6 +197,8 @@ GlslShaderGenerator::GlslShaderGenerator() :
registerImplementation("IM_frame_float_" + GlslShaderGenerator::TARGET, FrameNodeGlsl::create);
//
registerImplementation("IM_time_float_" + GlslShaderGenerator::TARGET, TimeNodeGlsl::create);
+ //
+ registerImplementation("IM_viewdirection_vector3_" + GlslShaderGenerator::TARGET, ViewDirectionNodeGlsl::create);
//
registerImplementation("IM_surface_" + GlslShaderGenerator::TARGET, SurfaceNodeGlsl::create);
diff --git a/source/MaterialXGenGlsl/Nodes/ViewDirectionNodeGlsl.cpp b/source/MaterialXGenGlsl/Nodes/ViewDirectionNodeGlsl.cpp
new file mode 100644
index 0000000000..f9714b5d33
--- /dev/null
+++ b/source/MaterialXGenGlsl/Nodes/ViewDirectionNodeGlsl.cpp
@@ -0,0 +1,55 @@
+//
+// Copyright Contributors to the MaterialX Project
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include
+
+#include
+
+MATERIALX_NAMESPACE_BEGIN
+
+ShaderNodeImplPtr ViewDirectionNodeGlsl::create()
+{
+ return std::make_shared();
+}
+
+void ViewDirectionNodeGlsl::createVariables(const ShaderNode&, GenContext&, Shader& shader) const
+{
+ ShaderStage& vs = shader.getStage(Stage::VERTEX);
+ ShaderStage& ps = shader.getStage(Stage::PIXEL);
+
+ addStageInput(HW::VERTEX_INPUTS, Type::VECTOR3, HW::T_IN_POSITION, vs);
+ addStageConnector(HW::VERTEX_DATA, Type::VECTOR3, HW::T_POSITION_WORLD, vs, ps);
+ addStageUniform(HW::PRIVATE_UNIFORMS, Type::VECTOR3, HW::T_VIEW_POSITION, ps);
+}
+
+void ViewDirectionNodeGlsl::emitFunctionCall(const ShaderNode& node, GenContext& context, ShaderStage& stage) const
+{
+ const GlslShaderGenerator& shadergen = static_cast(context.getShaderGenerator());
+
+ DEFINE_SHADER_STAGE(stage, Stage::VERTEX)
+ {
+ VariableBlock& vertexData = stage.getOutputBlock(HW::VERTEX_DATA);
+ const string prefix = shadergen.getVertexDataPrefix(vertexData);
+ ShaderPort* position = vertexData[HW::T_POSITION_WORLD];
+ if (!position->isEmitted())
+ {
+ position->setEmitted();
+ shadergen.emitLine(prefix + position->getVariable() + " = hPositionWorld.xyz", stage);
+ }
+ }
+
+ DEFINE_SHADER_STAGE(stage, Stage::PIXEL)
+ {
+ VariableBlock& vertexData = stage.getInputBlock(HW::VERTEX_DATA);
+ const string prefix = shadergen.getVertexDataPrefix(vertexData);
+ ShaderPort* position = vertexData[HW::T_POSITION_WORLD];
+ shadergen.emitLineBegin(stage);
+ shadergen.emitOutput(node.getOutput(), true, false, context, stage);
+ shadergen.emitString(" = normalize(" + prefix + position->getVariable() + " - " + HW::T_VIEW_POSITION + ")", stage);
+ shadergen.emitLineEnd(stage);
+ }
+}
+
+MATERIALX_NAMESPACE_END
diff --git a/source/MaterialXGenGlsl/Nodes/ViewDirectionNodeGlsl.h b/source/MaterialXGenGlsl/Nodes/ViewDirectionNodeGlsl.h
new file mode 100644
index 0000000000..24cafe2f1d
--- /dev/null
+++ b/source/MaterialXGenGlsl/Nodes/ViewDirectionNodeGlsl.h
@@ -0,0 +1,26 @@
+//
+// Copyright Contributors to the MaterialX Project
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#ifndef MATERIALX_VIEWDIRECTIONNODEGLSL_H
+#define MATERIALX_VIEWDIRECTIONNODEGLSL_H
+
+#include
+
+MATERIALX_NAMESPACE_BEGIN
+
+/// ViewDirection node implementation for GLSL
+class MX_GENGLSL_API ViewDirectionNodeGlsl : public GlslImplementation
+{
+ public:
+ static ShaderNodeImplPtr create();
+
+ void createVariables(const ShaderNode& node, GenContext& context, Shader& shader) const override;
+
+ void emitFunctionCall(const ShaderNode& node, GenContext& context, ShaderStage& stage) const override;
+};
+
+MATERIALX_NAMESPACE_END
+
+#endif
diff --git a/source/MaterialXGenMdl/mdl/materialx/stdlib.mdl b/source/MaterialXGenMdl/mdl/materialx/stdlib.mdl
index 4ba4f0875a..81cd039af6 100644
--- a/source/MaterialXGenMdl/mdl/materialx/stdlib.mdl
+++ b/source/MaterialXGenMdl/mdl/materialx/stdlib.mdl
@@ -1366,6 +1366,22 @@ export float mx_time_float(
return ::state::animation_time();
}
+export float3 mx_viewdirection_vector3(
+ uniform mx_coordinatespace_type mxp_space = mx_coordinatespace_type(mx_coordinatespace_type_world)
+ [[
+ anno::description("Enumeration {model,object,world}."),
+ anno::unused()
+ ]]
+)
+ [[
+ anno::description("Node Group: nprlib")
+ ]]
+{
+ // Not implemented: mx_viewdirection_vector3
+ float3 defaultValue = float3(0.0, 0.0, 1.0);
+ return defaultValue;
+}
+
export color mx_modulo_color3(
color mxp_in1 = color(0.0, 0.0, 0.0),
color mxp_in2 = color(1.0, 1.0, 1.0)
@@ -4131,6 +4147,46 @@ export float4 mx_combine4_vector4(
return float4(mxp_in1, mxp_in2, mxp_in3, mxp_in4);
}
+export float3x3 mx_creatematrix_vector3_matrix33(
+ float3 mxp_in1 = float3(1.0, 0.0, 0.0),
+ float3 mxp_in2 = float3(0.0, 1.0, 0.0),
+ float3 mxp_in3 = float3(0.0, 0.0, 1.0)
+)
+ [[
+ anno::description("Node Group: math")
+ ]]
+{
+ return float3x3(mxp_in1[0],mxp_in1[1],mxp_in1[2],mxp_in2[0],mxp_in2[1],mxp_in2[2],mxp_in3[0],mxp_in3[1],mxp_in3[2]);
+}
+
+
+export float4x4 mx_creatematrix_vector3_matrix44(
+ float3 mxp_in1 = float3(1.0, 0.0, 0.0),
+ float3 mxp_in2 = float3(0.0, 1.0, 0.0),
+ float3 mxp_in3 = float3(0.0, 0.0, 1.0)
+ float3 mxp_in4 = float3(0.0, 0.0, 0.0)
+)
+ [[
+ anno::description("Node Group: math")
+ ]]
+{
+ return float4x4(mxp_in1[0],mxp_in1[1],mxp_in1[2],0.0, mxp_in2[0],mxp_in2[1],mxp_in2[2],0.0, mxp_in3[0],mxp_in3[1],mxp_in3[2]0.0, mxp_in4[0],mxp_in4[1],mxp_in4[2],1.0);
+}
+
+
+export float4x4 mx_creatematrix_vector4_matrix44(
+ float4 mxp_in1 = float4(1.0, 0.0, 0.0, 0.0),
+ float4 mxp_in2 = float4(0.0, 1.0, 0.0, 0.0),
+ float4 mxp_in3 = float4(0.0, 0.0, 1.0, 0.0)
+ float4 mxp_in4 = float4(0.0, 0.0, 0.0, 1.0)
+)
+ [[
+ anno::description("Node Group: math")
+ ]]
+{
+ return float4x4(mxp_in1[0],mxp_in1[1],mxp_in1[2],mxp_in1[3],mxp_in2[0],mxp_in2[1],mxp_in2[2],mxp_in2[3],mxp_in3[0],mxp_in3[1],mxp_in3[2],mxp_in3[3],mxp_in4[0],mxp_in4[1],mxp_in4[2],mxp_in4[3]);
+}
+
// Nodedef: ND_extract_color3 is represented by a nodegraph: NG_extract_color3
// Nodedef: ND_extract_color4 is represented by a nodegraph: NG_extract_color4
// Nodedef: ND_extract_vector2 is represented by a nodegraph: NG_extract_vector2
diff --git a/source/MaterialXGenMsl/MslShaderGenerator.cpp b/source/MaterialXGenMsl/MslShaderGenerator.cpp
index 10c368177c..7a2461a5a8 100644
--- a/source/MaterialXGenMsl/MslShaderGenerator.cpp
+++ b/source/MaterialXGenMsl/MslShaderGenerator.cpp
@@ -14,6 +14,7 @@
#include
#include
#include
+#include
#include
#include
#include
@@ -200,6 +201,8 @@ MslShaderGenerator::MslShaderGenerator() :
registerImplementation("IM_frame_float_" + MslShaderGenerator::TARGET, FrameNodeMsl::create);
//
registerImplementation("IM_time_float_" + MslShaderGenerator::TARGET, TimeNodeMsl::create);
+ //
+ registerImplementation("IM_viewdirection_vector3_" + MslShaderGenerator::TARGET, ViewDirectionNodeMsl::create);
//
registerImplementation("IM_surface_" + MslShaderGenerator::TARGET, SurfaceNodeMsl::create);
diff --git a/source/MaterialXGenMsl/Nodes/ViewDirectionNodeMsl.cpp b/source/MaterialXGenMsl/Nodes/ViewDirectionNodeMsl.cpp
new file mode 100644
index 0000000000..1443b5c320
--- /dev/null
+++ b/source/MaterialXGenMsl/Nodes/ViewDirectionNodeMsl.cpp
@@ -0,0 +1,55 @@
+//
+// Copyright Contributors to the MaterialX Project
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include
+
+#include
+
+MATERIALX_NAMESPACE_BEGIN
+
+ShaderNodeImplPtr ViewDirectionNodeMsl::create()
+{
+ return std::make_shared();
+}
+
+void ViewDirectionNodeMsl::createVariables(const ShaderNode&, GenContext&, Shader& shader) const
+{
+ ShaderStage& vs = shader.getStage(Stage::VERTEX);
+ ShaderStage& ps = shader.getStage(Stage::PIXEL);
+
+ addStageInput(HW::VERTEX_INPUTS, Type::VECTOR3, HW::T_IN_POSITION, vs);
+ addStageConnector(HW::VERTEX_DATA, Type::VECTOR3, HW::T_POSITION_WORLD, vs, ps);
+ addStageUniform(HW::PRIVATE_UNIFORMS, Type::VECTOR3, HW::T_VIEW_POSITION, ps);
+}
+
+void ViewDirectionNodeMsl::emitFunctionCall(const ShaderNode& node, GenContext& context, ShaderStage& stage) const
+{
+ const MslShaderGenerator& shadergen = static_cast(context.getShaderGenerator());
+
+ DEFINE_SHADER_STAGE(stage, Stage::VERTEX)
+ {
+ VariableBlock& vertexData = stage.getOutputBlock(HW::VERTEX_DATA);
+ const string prefix = shadergen.getVertexDataPrefix(vertexData);
+ ShaderPort* position = vertexData[HW::T_POSITION_WORLD];
+ if (!position->isEmitted())
+ {
+ position->setEmitted();
+ shadergen.emitLine(prefix + position->getVariable() + " = hPositionWorld.xyz", stage);
+ }
+ }
+
+ DEFINE_SHADER_STAGE(stage, Stage::PIXEL)
+ {
+ VariableBlock& vertexData = stage.getInputBlock(HW::VERTEX_DATA);
+ const string prefix = shadergen.getVertexDataPrefix(vertexData);
+ ShaderPort* position = vertexData[HW::T_POSITION_WORLD];
+ shadergen.emitLineBegin(stage);
+ shadergen.emitOutput(node.getOutput(), true, false, context, stage);
+ shadergen.emitString(" = normalize(" + prefix + position->getVariable() + " - " + HW::T_VIEW_POSITION + ")", stage);
+ shadergen.emitLineEnd(stage);
+ }
+}
+
+MATERIALX_NAMESPACE_END
diff --git a/source/MaterialXGenMsl/Nodes/ViewDirectionNodeMsl.h b/source/MaterialXGenMsl/Nodes/ViewDirectionNodeMsl.h
new file mode 100644
index 0000000000..be7a40108a
--- /dev/null
+++ b/source/MaterialXGenMsl/Nodes/ViewDirectionNodeMsl.h
@@ -0,0 +1,26 @@
+//
+// Copyright Contributors to the MaterialX Project
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#ifndef MATERIALX_VIEWDIRECTIONNODEMSL_H
+#define MATERIALX_VIEWDIRECTIONNODEMSL_H
+
+#include
+
+MATERIALX_NAMESPACE_BEGIN
+
+/// ViewDirection node implementation for MSL
+class MX_GENMSL_API ViewDirectionNodeMsl : public MslImplementation
+{
+ public:
+ static ShaderNodeImplPtr create();
+
+ void createVariables(const ShaderNode& node, GenContext& context, Shader& shader) const override;
+
+ void emitFunctionCall(const ShaderNode& node, GenContext& context, ShaderStage& stage) const override;
+};
+
+MATERIALX_NAMESPACE_END
+
+#endif
diff --git a/source/MaterialXRender/ShaderMaterial.cpp b/source/MaterialXRender/ShaderMaterial.cpp
index 4e8ccc491f..c61c6d3c04 100644
--- a/source/MaterialXRender/ShaderMaterial.cpp
+++ b/source/MaterialXRender/ShaderMaterial.cpp
@@ -73,7 +73,7 @@ bool ShaderMaterial::generateEnvironmentShader(GenContext& context,
readFromXmlFile(envDoc, filename);
doc->importLibrary(envDoc);
- NodeGraphPtr envGraph = doc->getNodeGraph("environmentDraw");
+ NodeGraphPtr envGraph = doc->getNodeGraph("envMap");
if (!envGraph)
{
return false;
diff --git a/source/MaterialXView/Viewer.cpp b/source/MaterialXView/Viewer.cpp
index 3119424a0c..928deb9b7d 100644
--- a/source/MaterialXView/Viewer.cpp
+++ b/source/MaterialXView/Viewer.cpp
@@ -137,55 +137,6 @@ void applyModifiers(mx::DocumentPtr doc, const DocumentModifiers& modifiers)
}
}
-// ViewDir implementation for GLSL
-// as needed for the environment shader.
-template
-class ViewDir : public NodeGraphImpl
-{
-public:
- static mx::ShaderNodeImplPtr create()
- {
- return std::make_shared();
- }
-
- void createVariables(const mx::ShaderNode&, mx::GenContext&, mx::Shader& shader) const override
- {
- mx::ShaderStage& vs = shader.getStage(mx::Stage::VERTEX);
- mx::ShaderStage& ps = shader.getStage(mx::Stage::PIXEL);
- addStageInput(mx::HW::VERTEX_INPUTS, mx::Type::VECTOR3, mx::HW::T_IN_POSITION, vs);
- addStageConnector(mx::HW::VERTEX_DATA, mx::Type::VECTOR3, mx::HW::T_POSITION_WORLD, vs, ps);
- addStageUniform(mx::HW::PRIVATE_UNIFORMS, mx::Type::VECTOR3, mx::HW::T_VIEW_POSITION, ps);
- }
-
- void emitFunctionCall(const mx::ShaderNode& node, mx::GenContext& context, mx::ShaderStage& stage) const override
- {
- const mx::ShaderGenerator& shadergen = context.getShaderGenerator();
-
- DEFINE_SHADER_STAGE(stage, mx::Stage::VERTEX)
- {
- mx::VariableBlock& vertexData = stage.getOutputBlock(mx::HW::VERTEX_DATA);
- const mx::string prefix = vertexData.getInstance() + ".";
- mx::ShaderPort* position = vertexData[mx::HW::T_POSITION_WORLD];
- if (!position->isEmitted())
- {
- position->setEmitted();
- shadergen.emitLine(prefix + position->getVariable() + " = hPositionWorld.xyz", stage);
- }
- }
-
- DEFINE_SHADER_STAGE(stage, mx::Stage::PIXEL)
- {
- mx::VariableBlock& vertexData = stage.getInputBlock(mx::HW::VERTEX_DATA);
- const mx::string prefix = vertexData.getInstance() + ".";
- mx::ShaderPort* position = vertexData[mx::HW::T_POSITION_WORLD];
- shadergen.emitLineBegin(stage);
- shadergen.emitOutput(node.getOutput(), true, false, context, stage);
- shadergen.emitString(" = normalize(" + prefix + position->getVariable() + " - " + mx::HW::T_VIEW_POSITION + ")", stage);
- shadergen.emitLineEnd(stage);
- }
- }
-};
-
} // anonymous namespace
//
@@ -299,10 +250,8 @@ Viewer::Viewer(const std::string& materialFilename,
_renderPipeline = MetalRenderPipeline::create(this);
_renderPipeline->initialize(ng::metal_device(),
ng::metal_command_queue());
- _genContext.getShaderGenerator().registerImplementation("IM_viewdir_vector3_" + _genContext.getShaderGenerator().getTarget(), ViewDir::create);
#else
_renderPipeline = GLRenderPipeline::create(this);
- _genContext.getShaderGenerator().registerImplementation("IM_viewdir_vector3_" + _genContext.getShaderGenerator().getTarget(), ViewDir::create);
// Set Essl generator options
_genContextEssl.getOptions().targetColorSpaceOverride = "lin_rec709";
@@ -319,7 +268,6 @@ Viewer::Viewer(const std::string& materialFilename,
_genContextMdl.getOptions().targetColorSpaceOverride = "lin_rec709";
_genContextMdl.getOptions().fileTextureVerticalFlip = false;
#endif
- // Register the API Spcefic implementation for used by the environment shader.
}
void Viewer::initialize()
@@ -2468,7 +2416,7 @@ mx::MaterialPtr Viewer::getEnvironmentMaterial()
{
if (!_envMaterial)
{
- mx::FilePath envFilename = _searchPath.find(mx::FilePath("resources/Lights/envmap_shader.mtlx"));
+ mx::FilePath envFilename = _searchPath.find(mx::FilePath("resources/Lights/environment_map.mtlx"));
try
{
_envMaterial = _renderPipeline->createMaterial();