diff --git a/javascript/MaterialXView/index.ejs b/javascript/MaterialXView/index.ejs
index d832f03e42..8f278051af 100644
--- a/javascript/MaterialXView/index.ejs
+++ b/javascript/MaterialXView/index.ejs
@@ -10,6 +10,22 @@
margin: 0;
font-family: Arial
}
+
+ /* Property editor item color */
+ .peditoritem {
+ background-color: #334444;
+ }
+ /* Property editor folder color */
+ .peditorfolder {
+ background-color: #333333;
+ }
+
+ .peditor_material_assigned {
+ background-color: #006cb8;
+ }
+ .peditor_material_assigned:hover {
+ background-color: #32adff;
+ }
diff --git a/javascript/MaterialXView/public/shader_ball.svg b/javascript/MaterialXView/public/shader_ball.svg
new file mode 100644
index 0000000000..2b51705a42
--- /dev/null
+++ b/javascript/MaterialXView/public/shader_ball.svg
@@ -0,0 +1,5 @@
+
diff --git a/javascript/MaterialXView/public/shader_ball2.svg b/javascript/MaterialXView/public/shader_ball2.svg
new file mode 100644
index 0000000000..62907b5df8
--- /dev/null
+++ b/javascript/MaterialXView/public/shader_ball2.svg
@@ -0,0 +1,8 @@
+
diff --git a/javascript/MaterialXView/source/index.js b/javascript/MaterialXView/source/index.js
index ddd1ec8ffc..d11ba9691e 100644
--- a/javascript/MaterialXView/source/index.js
+++ b/javascript/MaterialXView/source/index.js
@@ -62,6 +62,13 @@ function init()
// Set up renderer
renderer = new THREE.WebGLRenderer({ canvas, context });
renderer.setSize(window.innerWidth, window.innerHeight);
+ // Disable introspection for shader debugging for deployment.
+ // - The code associated with getting program information can be very slow when
+ // dealing with shaders with lots of input uniforms (such as standard surface, openpbr shading models)
+ // as each call is blocking.
+ // - Adding this avoids the chess set scene from "hanging" the Chrome browser on Windows to a few second load.
+ // - Documentation for this flag: https://threejs.org/docs/index.html#api/en/renderers/WebGLRenderer.debug
+ renderer.debug.checkShaderErrors = false;
composer = new EffectComposer(renderer);
const renderPass = new RenderPass(scene.getScene(), scene.getCamera());
diff --git a/javascript/MaterialXView/source/viewer.js b/javascript/MaterialXView/source/viewer.js
index 3eff576be3..9992dd6985 100644
--- a/javascript/MaterialXView/source/viewer.js
+++ b/javascript/MaterialXView/source/viewer.js
@@ -111,7 +111,8 @@ export class Scene
console.log("Total geometry load time: ", performance.now() - startTime, " ms.");
- viewer.getMaterial().updateMaterialAssignments(viewer);
+ viewer.getMaterial().clearSoloMaterialUI();
+ viewer.getMaterial().updateMaterialAssignments(viewer, "");
this.setUpdateTransforms();
}
@@ -303,13 +304,16 @@ export class Scene
}
else
{
- const paths = geometry.split(',');
- for (let path of paths)
+ if (geometry != NO_GEOMETRY_SPECIFIER)
{
- if (dagPath.match(path))
+ const paths = geometry.split(',');
+ for (let path of paths)
{
- matches = true;
- break;
+ if (dagPath.match(path))
+ {
+ matches = true;
+ break;
+ }
}
}
}
@@ -460,6 +464,17 @@ class MaterialAssign
this._geometry = geometry;
this._collection = collection;
this._shader = null;
+ this._materialUI = null;
+ }
+
+ setMaterialUI(value)
+ {
+ this._materialUI = value;
+ }
+
+ getMaterialUI()
+ {
+ return this._materialUI;
}
setShader(shader)
@@ -482,6 +497,11 @@ class MaterialAssign
return this._geometry;
}
+ setGeometry(value)
+ {
+ this._geometry = value;
+ }
+
getCollection()
{
return this._collection;
@@ -506,19 +526,44 @@ export class Material
{
this._materials = [];
this._defaultMaterial = null;
+ this._soloMaterial = "";
+ }
+
+ clearMaterials()
+ {
+ this._materials.length = 0;
+ this._defaultMaterial = null;
+ this._soloMaterial = "";
+ }
+
+ setSoloMaterial(value)
+ {
+ this._soloMaterial = value;
+ }
+
+ getSoloMaterial()
+ {
+ return this._soloMaterial;
}
// If no material file is selected, we programmatically create a default material as a fallback
static createFallbackMaterial(doc)
{
- const ssName = 'SR_default';
- const ssNode = doc.addChildOfCategory('standard_surface', ssName);
+ let ssNode = doc.getChild('Generated_Default_Shader');
+ if (ssNode)
+ {
+ return ssNode;
+ }
+ const ssName = 'Generated_Default_Shader';
+ ssNode = doc.addChildOfCategory('standard_surface', ssName);
ssNode.setType('surfaceshader');
const smNode = doc.addChildOfCategory('surfacematerial', 'Default');
smNode.setType('material');
const shaderElement = smNode.addInput('surfaceshader');
shaderElement.setType('surfaceshader');
shaderElement.setNodeName(ssName);
+
+ return ssNode;
}
async loadMaterialFile(loader, materialFilename)
@@ -565,11 +610,10 @@ export class Material
// Check if there are any looks defined in the document
// If so then traverse the looks for all material assignments.
// Generate code and compile for any associated surface shader
- // and assign to the associatged geometry. If there are no looks
+ // and assign to the associated geometry. If there are no looks
// then the first material is found and assignment to all the
- // geometry.
- this._materials.length = 0;
- this._defaultMaterial = null;
+ // geometry.
+ this.clearMaterials();
var looks = doc.getLooks();
if (looks.length)
{
@@ -610,7 +654,7 @@ export class Material
}
else
{
- newAssignment = new MaterialAssign(shader, NO_GEOMETRY_SPECIFIER);
+ newAssignment = new MaterialAssign(shader, NO_GEOMETRY_SPECIFIER, null);
}
if (newAssignment)
@@ -623,35 +667,133 @@ export class Material
}
else
{
- // Search for any surface shader. It
+ // Search for any surface shaders. The first found
// is assumed to be assigned to the entire scene
// The identifier used is "*" to mean the entire scene.
- let elem = mx.findRenderableElement(doc);
- if (elem)
+ const materialNodes = doc.getMaterialNodes();
+ let shaderList = [];
+ let foundRenderable = false;
+ for (let i=0; i 0)
+ {
+ let shaderNodePath = shaderNodes[0].getNamePath()
+ if (!shaderList.includes(shaderNodePath))
+ {
+ let assignment = NO_GEOMETRY_SPECIFIER;
+ if (foundRenderable == false)
+ {
+ assignment = ALL_GEOMETRY_SPECIFIER;
+ foundRenderable = true;
+ }
+ console.log('-- add shader: ', shaderNodePath);
+ shaderList.push(shaderNodePath);
+ this._materials.push(new MaterialAssign(shaderNodes[0], assignment));
+ }
+ }
+ }
}
+ const nodeGraphs = doc.getNodeGraphs();
+ for (let i=0; i 0)
+ {
+ continue
+ }
+ let outputs = nodeGraph.getOutputs();
+ for (let j=0; j" + elem.getNamePath();
+ let img = matTitle.getElementsByTagName('img')[0];
+ if (img)
+ {
+ // Add event listener to icon to call updateSoloMaterial function
+ img.addEventListener('click', function(event)
+ {
+ Material.updateSoloMaterial(viewer, elemPath, materials,event);
+ });
+ }
+
+ if (closeUI)
+ {
+ matUI.close();
+ }
const uniformBlocks = Object.values(shader.getStage('pixel').getUniformBlocks());
var uniformToUpdate;
const ignoreList = ['u_envRadianceMips', 'u_envRadianceSamples', 'u_alphaThreshold'];
@@ -852,8 +1092,10 @@ export class Material
if (uifolderName && uifolderName.length) {
let newFolderName = currentNodePath + '/' + uifolderName;
currentFolder = folderList[newFolderName];
- if (!currentFolder) {
+ if (!currentFolder)
+ {
currentFolder = matUI.addFolder(uifolderName);
+ currentFolder.domElement.classList.add('peditorfolder');
folderList[newFolderName] = currentFolder;
}
}
@@ -929,7 +1171,8 @@ export class Material
{
step = (maxValue - minValue) / 1000.0;
}
- currentFolder.add(material.uniforms[name], 'value', minValue, maxValue, step).name(path);
+ const w = currentFolder.add(material.uniforms[name], 'value', minValue, maxValue, step).name(path);
+ w.domElement.classList.add('peditoritem');
}
break;
@@ -991,7 +1234,8 @@ export class Material
}
if (enumList.length == 0)
{
- currentFolder.add(material.uniforms[name], 'value', minValue, maxValue, step).name(path);
+ let w = currentFolder.add(material.uniforms[name], 'value', minValue, maxValue, step).name(path);
+ w.domElement.classList.add('peditoritem');
}
else
{
@@ -1017,8 +1261,9 @@ export class Material
}
}
const defaultOption = enumList[value]; // Set the default selected option
- const dropdownController = gui.add(enumeration, defaultOption, enumeration).name(path);
+ const dropdownController = currentFolder.add(enumeration, defaultOption, enumeration).name(path);
dropdownController.onChange(handleDropdownChange);
+ dropdownController.domElement.classList.add('peditoritem');
}
}
break;
@@ -1027,7 +1272,8 @@ export class Material
uniformToUpdate = material.uniforms[name];
if (uniformToUpdate && value != null)
{
- currentFolder.add(material.uniforms[name], 'value').name(path);
+ let w = currentFolder.add(material.uniforms[name], 'value').name(path);
+ w.domElement.classList.add('peditoritem');
}
break;
@@ -1069,6 +1315,7 @@ export class Material
Object.keys(material.uniforms[name].value).forEach((key) => {
let w = vecFolder.add(material.uniforms[name].value,
key, minValue[key], maxValue[key], step[key]).name(keyString[key]);
+ w.domElement.classList.add('peditoritem');
})
}
break;
@@ -1085,11 +1332,12 @@ export class Material
const color3 = new THREE.Color(dummy.color);
color3.fromArray(material.uniforms[name].value);
dummy.color = color3.getHex();
- currentFolder.addColor(dummy, 'color').name(path)
+ let w = currentFolder.addColor(dummy, 'color').name(path)
.onChange(function (value) {
const color3 = new THREE.Color(value);
material.uniforms[name].value.set(color3.toArray());
});
+ w.domElement.classList.add('peditoritem');
}
break;
@@ -1102,11 +1350,16 @@ export class Material
case 'filename':
break;
case 'string':
- uniformToUpdate = material.uniforms[name];
- if (uniformToUpdate && value != null) {
- item = currentFolder.add(material.uniforms[name], 'value');
+ console.log('String: ', name);
+ if (value != null) {
+ var dummy =
+ {
+ thevalue: value
+ }
+ let item = currentFolder.add(dummy, 'thevalue');
item.name(path);
- item.readonly(true);
+ item.disable(true);
+ item.domElement.classList.add('peditoritem');
}
break;
default:
diff --git a/libraries/stdlib/genglsl/mx_normalmap.glsl b/libraries/stdlib/genglsl/mx_normalmap.glsl
index 86d5610fea..19e0797c4f 100644
--- a/libraries/stdlib/genglsl/mx_normalmap.glsl
+++ b/libraries/stdlib/genglsl/mx_normalmap.glsl
@@ -1,4 +1,4 @@
-void mx_normalmap(vec3 value, int map_space, float normal_scale, vec3 N, vec3 T, out vec3 result)
+void mx_normalmap_vector2(vec3 value, int map_space, vec2 normal_scale, vec3 N, vec3 T, out vec3 result)
{
// Decode the normal map.
value = (value == vec3(0.0f)) ? vec3(0.0, 0.0, 1.0) : value * 2.0 - 1.0;
@@ -14,3 +14,8 @@ void mx_normalmap(vec3 value, int map_space, float normal_scale, vec3 N, vec3 T,
// Normalize the result.
result = normalize(value);
}
+
+void mx_normalmap_float(vec3 value, int map_space, float normal_scale, vec3 N, vec3 T, out vec3 result)
+{
+ mx_normalmap_vector2(value, map_space, vec2(normal_scale), N, T, result);
+}
diff --git a/libraries/stdlib/genglsl/stdlib_genglsl_impl.mtlx b/libraries/stdlib/genglsl/stdlib_genglsl_impl.mtlx
index 6f67b21d33..dc4f52e3b6 100644
--- a/libraries/stdlib/genglsl/stdlib_genglsl_impl.mtlx
+++ b/libraries/stdlib/genglsl/stdlib_genglsl_impl.mtlx
@@ -42,7 +42,9 @@
-
+
+
+
diff --git a/libraries/stdlib/genmdl/stdlib_genmdl_impl.mtlx b/libraries/stdlib/genmdl/stdlib_genmdl_impl.mtlx
index 6c550c92db..96fd768e25 100644
--- a/libraries/stdlib/genmdl/stdlib_genmdl_impl.mtlx
+++ b/libraries/stdlib/genmdl/stdlib_genmdl_impl.mtlx
@@ -44,7 +44,8 @@
-
+
+
diff --git a/libraries/stdlib/genmsl/mx_normalmap.metal b/libraries/stdlib/genmsl/mx_normalmap.metal
index c9c7bd5546..a3ffedaad5 100644
--- a/libraries/stdlib/genmsl/mx_normalmap.metal
+++ b/libraries/stdlib/genmsl/mx_normalmap.metal
@@ -1,4 +1,4 @@
-void mx_normalmap(vec3 value, int map_space, float normal_scale, vec3 N, vec3 T, out vec3 result)
+void mx_normalmap_vector2(vec3 value, int map_space, vec2 normal_scale, vec3 N, vec3 T, out vec3 result)
{
// Decode the normal map.
value = all(value == vec3(0.0f)) ? vec3(0.0, 0.0, 1.0) : value * 2.0 - 1.0;
@@ -14,3 +14,8 @@ void mx_normalmap(vec3 value, int map_space, float normal_scale, vec3 N, vec3 T,
// Normalize the result.
result = normalize(value);
}
+
+void mx_normalmap_float(vec3 value, int map_space, float normal_scale, vec3 N, vec3 T, out vec3 result)
+{
+ mx_normalmap_vector2(value, map_space, vec2(normal_scale), N, T, result);
+}
diff --git a/libraries/stdlib/genmsl/stdlib_genmsl_impl.mtlx b/libraries/stdlib/genmsl/stdlib_genmsl_impl.mtlx
index 40be6f8c46..1875c2b617 100644
--- a/libraries/stdlib/genmsl/stdlib_genmsl_impl.mtlx
+++ b/libraries/stdlib/genmsl/stdlib_genmsl_impl.mtlx
@@ -42,7 +42,8 @@
-
+
+
diff --git a/libraries/stdlib/genosl/mx_normalmap.osl b/libraries/stdlib/genosl/mx_normalmap.osl
index a1f276faf1..bf75781f51 100644
--- a/libraries/stdlib/genosl/mx_normalmap.osl
+++ b/libraries/stdlib/genosl/mx_normalmap.osl
@@ -1,4 +1,4 @@
-void mx_normalmap(vector value, string map_space, float normal_scale, vector N, vector U, output vector result)
+void mx_normalmap_vector2(vector value, string map_space, vector2 normal_scale, vector N, vector U, output vector result)
{
// Tangent space
if (map_space == "tangent")
@@ -6,7 +6,7 @@ void mx_normalmap(vector value, string map_space, float normal_scale, vector N,
vector v = value * 2.0 - 1.0;
vector T = normalize(U - dot(U, N) * N);
vector B = normalize(cross(N, T));
- result = normalize(T * v[0] * normal_scale + B * v[1] * normal_scale + N * v[2]);
+ result = normalize(T * v[0] * normal_scale[0] + B * v[1] * normal_scale[1] + N * v[2]);
}
// Object space
else
@@ -15,3 +15,8 @@ void mx_normalmap(vector value, string map_space, float normal_scale, vector N,
result = normalize(n);
}
}
+
+void mx_normalmap_float(vector value, string map_space, float normal_scale, vector N, vector U, output vector result)
+{
+ mx_normalmap_vector2(value, map_space, vector2(normal_scale, normal_scale), N, U, result);
+}
diff --git a/libraries/stdlib/genosl/stdlib_genosl_impl.mtlx b/libraries/stdlib/genosl/stdlib_genosl_impl.mtlx
index a984d912b8..ae3f6777cf 100644
--- a/libraries/stdlib/genosl/stdlib_genosl_impl.mtlx
+++ b/libraries/stdlib/genosl/stdlib_genosl_impl.mtlx
@@ -44,7 +44,8 @@
-
+
+
diff --git a/libraries/stdlib/stdlib_defs.mtlx b/libraries/stdlib/stdlib_defs.mtlx
index 90ccb57a98..051891cf83 100644
--- a/libraries/stdlib/stdlib_defs.mtlx
+++ b/libraries/stdlib/stdlib_defs.mtlx
@@ -2505,6 +2505,14 @@
+
+
+
+
+
+
+
+
- registerImplementation("IM_position_vector3_" + GlslShaderGenerator::TARGET, PositionNodeGlsl::create);
+ registerImplementation("IM_position_vector3_" + GlslShaderGenerator::TARGET, HwPositionNode::create);
//
- registerImplementation("IM_normal_vector3_" + GlslShaderGenerator::TARGET, NormalNodeGlsl::create);
+ registerImplementation("IM_normal_vector3_" + GlslShaderGenerator::TARGET, HwNormalNode::create);
//
- registerImplementation("IM_tangent_vector3_" + GlslShaderGenerator::TARGET, TangentNodeGlsl::create);
+ registerImplementation("IM_tangent_vector3_" + GlslShaderGenerator::TARGET, HwTangentNode::create);
//
- registerImplementation("IM_bitangent_vector3_" + GlslShaderGenerator::TARGET, BitangentNodeGlsl::create);
+ registerImplementation("IM_bitangent_vector3_" + GlslShaderGenerator::TARGET, HwBitangentNode::create);
//
registerImplementation("IM_texcoord_vector2_" + GlslShaderGenerator::TARGET, HwTexCoordNode::create);
registerImplementation("IM_texcoord_vector3_" + GlslShaderGenerator::TARGET, HwTexCoordNode::create);
@@ -194,11 +194,11 @@ GlslShaderGenerator::GlslShaderGenerator() :
registerImplementation("IM_geompropvalue_string_" + GlslShaderGenerator::TARGET, GeomPropValueNodeGlslAsUniform::create);
//
- registerImplementation("IM_frame_float_" + GlslShaderGenerator::TARGET, FrameNodeGlsl::create);
+ registerImplementation("IM_frame_float_" + GlslShaderGenerator::TARGET, HwFrameNode::create);
//
- registerImplementation("IM_time_float_" + GlslShaderGenerator::TARGET, TimeNodeGlsl::create);
+ registerImplementation("IM_time_float_" + GlslShaderGenerator::TARGET, HwTimeNode::create);
//
- registerImplementation("IM_viewdirection_vector3_" + GlslShaderGenerator::TARGET, ViewDirectionNodeGlsl::create);
+ registerImplementation("IM_viewdirection_vector3_" + GlslShaderGenerator::TARGET, HwViewDirectionNode::create);
//
registerImplementation("IM_surface_" + GlslShaderGenerator::TARGET, SurfaceNodeGlsl::create);
@@ -913,31 +913,9 @@ ShaderNodeImplPtr GlslShaderGenerator::getImplementation(const NodeDef& nodedef,
return impl;
}
-const string GlslImplementation::SPACE = "space";
-const string GlslImplementation::INDEX = "index";
-const string GlslImplementation::GEOMPROP = "geomprop";
-
-namespace
-{
-
-// List name of inputs that are not to be editable and
-// published as shader uniforms in GLSL.
-const std::set IMMUTABLE_INPUTS =
-{
- // Geometric node inputs are immutable since a shader needs regeneration if they change.
- "index", "space", "attrname"
-};
-
-} // anonymous namespace
-
const string& GlslImplementation::getTarget() const
{
return GlslShaderGenerator::TARGET;
}
-bool GlslImplementation::isEditable(const ShaderInput& input) const
-{
- return IMMUTABLE_INPUTS.count(input.getName()) == 0;
-}
-
MATERIALX_NAMESPACE_END
diff --git a/source/MaterialXGenGlsl/GlslShaderGenerator.h b/source/MaterialXGenGlsl/GlslShaderGenerator.h
index acc8b0d6ee..aafd665140 100644
--- a/source/MaterialXGenGlsl/GlslShaderGenerator.h
+++ b/source/MaterialXGenGlsl/GlslShaderGenerator.h
@@ -88,30 +88,13 @@ class MX_GENGLSL_API GlslShaderGenerator : public HwShaderGenerator
};
/// Base class for common GLSL node implementations
-class MX_GENGLSL_API GlslImplementation : public ShaderNodeImpl
+class MX_GENGLSL_API GlslImplementation : public HwImplementation
{
public:
const string& getTarget() const override;
- bool isEditable(const ShaderInput& input) const override;
-
protected:
GlslImplementation() { }
-
- // Integer identifiers for coordinate spaces.
- // The order must match the order given for
- // the space enum string in stdlib.
- enum Space
- {
- MODEL_SPACE = 0,
- OBJECT_SPACE = 1,
- WORLD_SPACE = 2
- };
-
- /// Internal string constants
- static const string SPACE;
- static const string INDEX;
- static const string GEOMPROP;
};
MATERIALX_NAMESPACE_END
diff --git a/source/MaterialXGenGlsl/Nodes/BitangentNodeGlsl.cpp b/source/MaterialXGenGlsl/Nodes/BitangentNodeGlsl.cpp
deleted file mode 100644
index 6f515824e7..0000000000
--- a/source/MaterialXGenGlsl/Nodes/BitangentNodeGlsl.cpp
+++ /dev/null
@@ -1,135 +0,0 @@
-//
-// Copyright Contributors to the MaterialX Project
-// SPDX-License-Identifier: Apache-2.0
-//
-
-#include
-
-#include
-
-MATERIALX_NAMESPACE_BEGIN
-
-ShaderNodeImplPtr BitangentNodeGlsl::create()
-{
- return std::make_shared();
-}
-
-void BitangentNodeGlsl::createVariables(const ShaderNode& node, GenContext& context, Shader& shader) const
-{
- const GenOptions& options = context.getOptions();
-
- ShaderStage& vs = shader.getStage(Stage::VERTEX);
- ShaderStage& ps = shader.getStage(Stage::PIXEL);
-
- if (options.hwImplicitBitangents)
- {
- addStageInput(HW::VERTEX_INPUTS, Type::VECTOR3, HW::T_IN_NORMAL, vs);
- addStageInput(HW::VERTEX_INPUTS, Type::VECTOR3, HW::T_IN_TANGENT, vs);
- }
- else
- {
- addStageInput(HW::VERTEX_INPUTS, Type::VECTOR3, HW::T_IN_BITANGENT, vs);
- }
-
- const ShaderInput* spaceInput = node.getInput(SPACE);
- const int space = spaceInput ? spaceInput->getValue()->asA() : OBJECT_SPACE;
- if (space == WORLD_SPACE)
- {
- addStageConnector(HW::VERTEX_DATA, Type::VECTOR3, HW::T_BITANGENT_WORLD, vs, ps);
- addStageUniform(HW::PRIVATE_UNIFORMS, Type::MATRIX44, HW::T_WORLD_MATRIX, vs);
-
- if (options.hwImplicitBitangents)
- {
- addStageConnector(HW::VERTEX_DATA, Type::VECTOR3, HW::T_NORMAL_WORLD, vs, ps);
- addStageConnector(HW::VERTEX_DATA, Type::VECTOR3, HW::T_TANGENT_WORLD, vs, ps);
- addStageUniform(HW::PRIVATE_UNIFORMS, Type::MATRIX44, HW::T_WORLD_INVERSE_TRANSPOSE_MATRIX, vs);
- }
- }
- else
- {
- addStageConnector(HW::VERTEX_DATA, Type::VECTOR3, HW::T_BITANGENT_OBJECT, vs, ps);
- }
-}
-
-void BitangentNodeGlsl::emitFunctionCall(const ShaderNode& node, GenContext& context, ShaderStage& stage) const
-{
- const GlslShaderGenerator& shadergen = static_cast(context.getShaderGenerator());
- const GenOptions& options = context.getOptions();
-
- const ShaderInput* spaceInput = node.getInput(SPACE);
- const int space = spaceInput ? spaceInput->getValue()->asA() : OBJECT_SPACE;
-
- DEFINE_SHADER_STAGE(stage, Stage::VERTEX)
- {
- VariableBlock& vertexData = stage.getOutputBlock(HW::VERTEX_DATA);
- const string prefix = shadergen.getVertexDataPrefix(vertexData);
- if (space == WORLD_SPACE)
- {
- ShaderPort* bitangent = vertexData[HW::T_BITANGENT_WORLD];
-
- if (!bitangent->isEmitted())
- {
- bitangent->setEmitted();
-
- if (options.hwImplicitBitangents)
- {
- ShaderPort* normal = vertexData[HW::T_NORMAL_WORLD];
- if (!normal->isEmitted())
- {
- normal->setEmitted();
- shadergen.emitLine(prefix + normal->getVariable() + " = normalize((" + HW::T_WORLD_INVERSE_TRANSPOSE_MATRIX + " * vec4(" + HW::T_IN_NORMAL + ", 0.0)).xyz)", stage);
- }
- ShaderPort* tangent = vertexData[HW::T_TANGENT_WORLD];
- if (!tangent->isEmitted())
- {
- tangent->setEmitted();
- shadergen.emitLine(prefix + tangent->getVariable() + " = normalize((" + HW::T_WORLD_MATRIX + " * vec4(" + HW::T_IN_TANGENT + ", 0.0)).xyz)", stage);
- }
- shadergen.emitLine(prefix + bitangent->getVariable() + " = cross(" + prefix + normal->getVariable() + ", " + prefix + tangent->getVariable() + ")", stage);
- }
- else
- {
- shadergen.emitLine(prefix + bitangent->getVariable() + " = normalize((" + HW::T_WORLD_MATRIX + " * vec4(" + HW::T_IN_BITANGENT + ", 0.0)).xyz)", stage);
- }
- }
- }
- else
- {
- ShaderPort* bitangent = vertexData[HW::T_BITANGENT_OBJECT];
- if (!bitangent->isEmitted())
- {
- bitangent->setEmitted();
-
- if (options.hwImplicitBitangents)
- {
- shadergen.emitLine(prefix + bitangent->getVariable() + " = cross(" + HW::T_IN_NORMAL + ", " + HW::T_IN_TANGENT + ")", stage);
- }
- else
- {
- shadergen.emitLine(prefix + bitangent->getVariable() + " = " + HW::T_IN_BITANGENT, stage);
- }
- }
- }
- }
-
- DEFINE_SHADER_STAGE(stage, Stage::PIXEL)
- {
- VariableBlock& vertexData = stage.getInputBlock(HW::VERTEX_DATA);
- const string prefix = shadergen.getVertexDataPrefix(vertexData);
- shadergen.emitLineBegin(stage);
- shadergen.emitOutput(node.getOutput(), true, false, context, stage);
- if (space == WORLD_SPACE)
- {
- const ShaderPort* bitangent = vertexData[HW::T_BITANGENT_WORLD];
- shadergen.emitString(" = normalize(" + prefix + bitangent->getVariable() + ")", stage);
- }
- else
- {
- const ShaderPort* bitangent = vertexData[HW::T_BITANGENT_OBJECT];
- shadergen.emitString(" = normalize(" + prefix + bitangent->getVariable() + ")", stage);
- }
- shadergen.emitLineEnd(stage);
- }
-}
-
-MATERIALX_NAMESPACE_END
diff --git a/source/MaterialXGenGlsl/Nodes/FrameNodeGlsl.cpp b/source/MaterialXGenGlsl/Nodes/FrameNodeGlsl.cpp
deleted file mode 100644
index b6dbb2002b..0000000000
--- a/source/MaterialXGenGlsl/Nodes/FrameNodeGlsl.cpp
+++ /dev/null
@@ -1,35 +0,0 @@
-//
-// Copyright Contributors to the MaterialX Project
-// SPDX-License-Identifier: Apache-2.0
-//
-
-#include
-
-#include
-
-MATERIALX_NAMESPACE_BEGIN
-
-ShaderNodeImplPtr FrameNodeGlsl::create()
-{
- return std::make_shared();
-}
-
-void FrameNodeGlsl::createVariables(const ShaderNode&, GenContext&, Shader& shader) const
-{
- ShaderStage& ps = shader.getStage(Stage::PIXEL);
- addStageUniform(HW::PRIVATE_UNIFORMS, Type::FLOAT, HW::T_FRAME, ps);
-}
-
-void FrameNodeGlsl::emitFunctionCall(const ShaderNode& node, GenContext& context, ShaderStage& stage) const
-{
- DEFINE_SHADER_STAGE(stage, Stage::PIXEL)
- {
- const ShaderGenerator& shadergen = context.getShaderGenerator();
- shadergen.emitLineBegin(stage);
- shadergen.emitOutput(node.getOutput(), true, false, context, stage);
- shadergen.emitString(" = " + HW::T_FRAME, stage);
- shadergen.emitLineEnd(stage);
- }
-}
-
-MATERIALX_NAMESPACE_END
diff --git a/source/MaterialXGenGlsl/Nodes/PositionNodeGlsl.cpp b/source/MaterialXGenGlsl/Nodes/PositionNodeGlsl.cpp
deleted file mode 100644
index d37af520b2..0000000000
--- a/source/MaterialXGenGlsl/Nodes/PositionNodeGlsl.cpp
+++ /dev/null
@@ -1,87 +0,0 @@
-//
-// Copyright Contributors to the MaterialX Project
-// SPDX-License-Identifier: Apache-2.0
-//
-
-#include
-
-#include
-
-MATERIALX_NAMESPACE_BEGIN
-
-ShaderNodeImplPtr PositionNodeGlsl::create()
-{
- return std::make_shared();
-}
-
-void PositionNodeGlsl::createVariables(const ShaderNode& node, 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);
-
- const ShaderInput* spaceInput = node.getInput(SPACE);
- const int space = spaceInput ? spaceInput->getValue()->asA() : OBJECT_SPACE;
- if (space == WORLD_SPACE)
- {
- addStageConnector(HW::VERTEX_DATA, Type::VECTOR3, HW::T_POSITION_WORLD, vs, ps);
- }
- else
- {
- addStageConnector(HW::VERTEX_DATA, Type::VECTOR3, HW::T_POSITION_OBJECT, vs, ps);
- }
-}
-
-void PositionNodeGlsl::emitFunctionCall(const ShaderNode& node, GenContext& context, ShaderStage& stage) const
-{
- const GlslShaderGenerator& shadergen = static_cast(context.getShaderGenerator());
-
- const ShaderInput* spaceInput = node.getInput(SPACE);
- const int space = spaceInput ? spaceInput->getValue()->asA() : OBJECT_SPACE;
-
- DEFINE_SHADER_STAGE(stage, Stage::VERTEX)
- {
- VariableBlock& vertexData = stage.getOutputBlock(HW::VERTEX_DATA);
- const string prefix = shadergen.getVertexDataPrefix(vertexData);
- if (space == WORLD_SPACE)
- {
- ShaderPort* position = vertexData[HW::T_POSITION_WORLD];
- if (!position->isEmitted())
- {
- position->setEmitted();
- shadergen.emitLine(prefix + position->getVariable() + " = hPositionWorld.xyz", stage);
- }
- }
- else
- {
- ShaderPort* position = vertexData[HW::T_POSITION_OBJECT];
- if (!position->isEmitted())
- {
- position->setEmitted();
- shadergen.emitLine(prefix + position->getVariable() + " = " + HW::T_IN_POSITION, stage);
- }
- }
- }
-
- DEFINE_SHADER_STAGE(stage, Stage::PIXEL)
- {
- VariableBlock& vertexData = stage.getInputBlock(HW::VERTEX_DATA);
- const string prefix = shadergen.getVertexDataPrefix(vertexData);
- shadergen.emitLineBegin(stage);
- shadergen.emitOutput(node.getOutput(), true, false, context, stage);
- if (space == WORLD_SPACE)
- {
- const ShaderPort* position = vertexData[HW::T_POSITION_WORLD];
- shadergen.emitString(" = " + prefix + position->getVariable(), stage);
- }
- else
- {
- const ShaderPort* position = vertexData[HW::T_POSITION_OBJECT];
- shadergen.emitString(" = " + prefix + position->getVariable(), stage);
- }
- shadergen.emitLineEnd(stage);
- }
-}
-
-MATERIALX_NAMESPACE_END
diff --git a/source/MaterialXGenGlsl/Nodes/SurfaceNodeGlsl.cpp b/source/MaterialXGenGlsl/Nodes/SurfaceNodeGlsl.cpp
index c83fbe1d78..2e222f6bcc 100644
--- a/source/MaterialXGenGlsl/Nodes/SurfaceNodeGlsl.cpp
+++ b/source/MaterialXGenGlsl/Nodes/SurfaceNodeGlsl.cpp
@@ -45,8 +45,8 @@ void SurfaceNodeGlsl::createVariables(const ShaderNode&, GenContext& context, Sh
{
// TODO:
// The surface shader needs position, normal, view position and light sources. We should solve this by adding some
- // dependency mechanism so this implementation can be set to depend on the PositionNodeGlsl, NormalNodeGlsl
- // ViewDirectionNodeGlsl and LightNodeGlsl nodes instead? This is where the MaterialX attribute "internalgeomprops"
+ // dependency mechanism so this implementation can be set to depend on the HwPositionNode, HwNormalNode
+ // HwViewDirectionNode and LightNodeGlsl nodes instead? This is where the MaterialX attribute "internalgeomprops"
// is needed.
//
ShaderStage& vs = shader.getStage(Stage::VERTEX);
diff --git a/source/MaterialXGenGlsl/Nodes/SurfaceShaderNodeGlsl.cpp b/source/MaterialXGenGlsl/Nodes/SurfaceShaderNodeGlsl.cpp
index 00362b1cab..5e97b8ffc6 100644
--- a/source/MaterialXGenGlsl/Nodes/SurfaceShaderNodeGlsl.cpp
+++ b/source/MaterialXGenGlsl/Nodes/SurfaceShaderNodeGlsl.cpp
@@ -24,8 +24,8 @@ void SurfaceShaderNodeGlsl::createVariables(const ShaderNode&, GenContext& conte
{
// TODO:
// The surface shader needs position, view position and light sources. We should solve this by adding some
- // dependency mechanism so this implementation can be set to depend on the PositionNodeGlsl,
- // ViewDirectionNodeGlsl and LightNodeGlsl nodes instead? This is where the MaterialX attribute "internalgeomprops"
+ // dependency mechanism so this implementation can be set to depend on the HwPositionNode,
+ // HwViewDirectionNode and LightNodeGlsl nodes instead? This is where the MaterialX attribute "internalgeomprops"
// is needed.
//
ShaderStage& vs = shader.getStage(Stage::VERTEX);
diff --git a/source/MaterialXGenGlsl/Nodes/TimeNodeGlsl.cpp b/source/MaterialXGenGlsl/Nodes/TimeNodeGlsl.cpp
deleted file mode 100644
index e508391141..0000000000
--- a/source/MaterialXGenGlsl/Nodes/TimeNodeGlsl.cpp
+++ /dev/null
@@ -1,38 +0,0 @@
-//
-// Copyright Contributors to the MaterialX Project
-// SPDX-License-Identifier: Apache-2.0
-//
-
-#include
-
-#include
-
-MATERIALX_NAMESPACE_BEGIN
-
-ShaderNodeImplPtr TimeNodeGlsl::create()
-{
- return std::make_shared();
-}
-
-void TimeNodeGlsl::createVariables(const ShaderNode&, GenContext&, Shader& shader) const
-{
- ShaderStage& ps = shader.getStage(Stage::PIXEL);
- addStageUniform(HW::PRIVATE_UNIFORMS, Type::FLOAT, HW::T_FRAME, ps);
-}
-
-void TimeNodeGlsl::emitFunctionCall(const ShaderNode& node, GenContext& context, ShaderStage& stage) const
-{
- DEFINE_SHADER_STAGE(stage, Stage::PIXEL)
- {
- const ShaderGenerator& shadergen = context.getShaderGenerator();
- shadergen.emitLineBegin(stage);
- shadergen.emitOutput(node.getOutput(), true, false, context, stage);
- shadergen.emitString(" = " + HW::T_FRAME + " / ", stage);
- const ShaderInput* fpsInput = node.getInput("fps");
- const string fps = fpsInput->getValue()->getValueString();
- shadergen.emitString(fps, stage);
- shadergen.emitLineEnd(stage);
- }
-}
-
-MATERIALX_NAMESPACE_END
diff --git a/source/MaterialXGenGlsl/Nodes/TimeNodeGlsl.h b/source/MaterialXGenGlsl/Nodes/TimeNodeGlsl.h
deleted file mode 100644
index c97f6b4741..0000000000
--- a/source/MaterialXGenGlsl/Nodes/TimeNodeGlsl.h
+++ /dev/null
@@ -1,26 +0,0 @@
-//
-// Copyright Contributors to the MaterialX Project
-// SPDX-License-Identifier: Apache-2.0
-//
-
-#ifndef MATERIALX_TIMENODEGLSL_H
-#define MATERIALX_TIMENODEGLSL_H
-
-#include
-
-MATERIALX_NAMESPACE_BEGIN
-
-/// Time node implementation for GLSL
-class MX_GENGLSL_API TimeNodeGlsl : 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/MaterialXGenGlsl/Nodes/ViewDirectionNodeGlsl.cpp b/source/MaterialXGenGlsl/Nodes/ViewDirectionNodeGlsl.cpp
deleted file mode 100644
index f9714b5d33..0000000000
--- a/source/MaterialXGenGlsl/Nodes/ViewDirectionNodeGlsl.cpp
+++ /dev/null
@@ -1,55 +0,0 @@
-//
-// 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
deleted file mode 100644
index 24cafe2f1d..0000000000
--- a/source/MaterialXGenGlsl/Nodes/ViewDirectionNodeGlsl.h
+++ /dev/null
@@ -1,26 +0,0 @@
-//
-// 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 81cd039af6..708ea15603 100644
--- a/source/MaterialXGenMdl/mdl/materialx/stdlib.mdl
+++ b/source/MaterialXGenMdl/mdl/materialx/stdlib.mdl
@@ -2060,13 +2060,13 @@ export float4 mx_transformmatrix_vector4(
return mxp_mat * mxp_in;
}
-export float3 mx_normalmap(
+export float3 mx_normalmap_vector2(
float3 mxp_in = float3(0.5, 0.5, 1.0),
uniform string mxp_space = string("tangent")
[[
anno::description("Enumeration {tangent, object}.")
]],
- float mxp_scale = float(1.0),
+ float2 mxp_scale = float2(1.0, 1.0),
float3 mxp_normal = float3(::state::transform_normal(::state::coordinate_internal,::state::coordinate_world,::state::normal())),
float3 mxp_tangent = float3(state::transform_vector(::state::coordinate_internal,::state::coordinate_world,::state::texture_tangent_u(0)))
)
@@ -2078,7 +2078,7 @@ export float3 mx_normalmap(
{
float3 v = mxp_in * 2.0 - 1.0;
float3 binormal = ::math::normalize(::math::cross(mxp_normal, mxp_tangent));
- return ::math::normalize(mxp_tangent * v.x * mxp_scale + binormal * v.y * mxp_scale + mxp_normal * v.z);
+ return ::math::normalize(mxp_tangent * v.x * mxp_scale.x + binormal * v.y * mxp_scale.y + mxp_normal * v.z);
}
else
{
@@ -2087,6 +2087,23 @@ export float3 mx_normalmap(
}
}
+export float3 mx_normalmap_float(
+ float3 mxp_in = float3(0.5, 0.5, 1.0),
+ uniform string mxp_space = string("tangent")
+ [[
+ anno::description("Enumeration {tangent, object}.")
+ ]],
+ float mxp_scale = float(1.0),
+ float3 mxp_normal = float3(::state::transform_normal(::state::coordinate_internal,::state::coordinate_world,::state::normal())),
+ float3 mxp_tangent = float3(state::transform_vector(::state::coordinate_internal,::state::coordinate_world,::state::texture_tangent_u(0)))
+)
+ [[
+ anno::description("Node Group: math")
+ ]]
+{
+ return mx_normalmap_vector2(mxp_in, mxp_space, float2(mxp_scale, mxp_scale), mxp_normal, mxp_tangent);
+}
+
export float3x3 mx_transpose_matrix33(
float3x3 mxp_in = float3x3(1.0,0.0,0.0, 0.0,1.0,0.0, 0.0,0.0,1.0)
)
diff --git a/source/MaterialXGenMsl/MslShaderGenerator.cpp b/source/MaterialXGenMsl/MslShaderGenerator.cpp
index 7a2461a5a8..e07c0fc6ad 100644
--- a/source/MaterialXGenMsl/MslShaderGenerator.cpp
+++ b/source/MaterialXGenMsl/MslShaderGenerator.cpp
@@ -6,15 +6,8 @@
#include
#include
-#include
-#include
-#include
-#include
#include
#include
-#include
-#include
-#include
#include
#include
#include
@@ -33,6 +26,13 @@
#include
#include
#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
#include
#include
#include
@@ -169,13 +169,13 @@ MslShaderGenerator::MslShaderGenerator() :
registerImplementation(elementNames, CombineNode::create);
//
- registerImplementation("IM_position_vector3_" + MslShaderGenerator::TARGET, PositionNodeMsl::create);
+ registerImplementation("IM_position_vector3_" + MslShaderGenerator::TARGET, HwPositionNode::create);
//
- registerImplementation("IM_normal_vector3_" + MslShaderGenerator::TARGET, NormalNodeMsl::create);
+ registerImplementation("IM_normal_vector3_" + MslShaderGenerator::TARGET, HwNormalNode::create);
//
- registerImplementation("IM_tangent_vector3_" + MslShaderGenerator::TARGET, TangentNodeMsl::create);
+ registerImplementation("IM_tangent_vector3_" + MslShaderGenerator::TARGET, HwTangentNode::create);
//
- registerImplementation("IM_bitangent_vector3_" + MslShaderGenerator::TARGET, BitangentNodeMsl::create);
+ registerImplementation("IM_bitangent_vector3_" + MslShaderGenerator::TARGET, HwBitangentNode::create);
//
registerImplementation("IM_texcoord_vector2_" + MslShaderGenerator::TARGET, HwTexCoordNode::create);
registerImplementation("IM_texcoord_vector3_" + MslShaderGenerator::TARGET, HwTexCoordNode::create);
@@ -198,11 +198,11 @@ MslShaderGenerator::MslShaderGenerator() :
registerImplementation("IM_geompropvalue_string_" + MslShaderGenerator::TARGET, GeomPropValueNodeMslAsUniform::create);
//
- registerImplementation("IM_frame_float_" + MslShaderGenerator::TARGET, FrameNodeMsl::create);
+ registerImplementation("IM_frame_float_" + MslShaderGenerator::TARGET, HwFrameNode::create);
//
- registerImplementation("IM_time_float_" + MslShaderGenerator::TARGET, TimeNodeMsl::create);
+ registerImplementation("IM_time_float_" + MslShaderGenerator::TARGET, HwTimeNode::create);
//
- registerImplementation("IM_viewdirection_vector3_" + MslShaderGenerator::TARGET, ViewDirectionNodeMsl::create);
+ registerImplementation("IM_viewdirection_vector3_" + MslShaderGenerator::TARGET, HwViewDirectionNode::create);
//
registerImplementation("IM_surface_" + MslShaderGenerator::TARGET, SurfaceNodeMsl::create);
@@ -1415,31 +1415,9 @@ ShaderNodeImplPtr MslShaderGenerator::getImplementation(const NodeDef& nodedef,
return impl;
}
-const string MslImplementation::SPACE = "space";
-const string MslImplementation::INDEX = "index";
-const string MslImplementation::GEOMPROP = "geomprop";
-
-namespace
-{
-
-// List name of inputs that are not to be editable and
-// published as shader uniforms in MSL.
-const std::set IMMUTABLE_INPUTS =
-{
- // Geometric node inputs are immutable since a shader needs regeneration if they change.
- "index", "space", "attrname"
-};
-
-} // namespace
-
const string& MslImplementation::getTarget() const
{
return MslShaderGenerator::TARGET;
}
-bool MslImplementation::isEditable(const ShaderInput& input) const
-{
- return IMMUTABLE_INPUTS.count(input.getName()) == 0;
-}
-
MATERIALX_NAMESPACE_END
diff --git a/source/MaterialXGenMsl/MslShaderGenerator.h b/source/MaterialXGenMsl/MslShaderGenerator.h
index 21817db735..e9f2981045 100644
--- a/source/MaterialXGenMsl/MslShaderGenerator.h
+++ b/source/MaterialXGenMsl/MslShaderGenerator.h
@@ -115,30 +115,13 @@ class MX_GENMSL_API MslShaderGenerator : public HwShaderGenerator
};
/// Base class for common MSL node implementations
-class MX_GENMSL_API MslImplementation : public ShaderNodeImpl
+class MX_GENMSL_API MslImplementation : public HwImplementation
{
public:
const string& getTarget() const override;
- bool isEditable(const ShaderInput& input) const override;
-
protected:
MslImplementation() { }
-
- // Integer identifiers for coordinate spaces.
- // The order must match the order given for
- // the space enum string in stdlib.
- enum Space
- {
- MODEL_SPACE = 0,
- OBJECT_SPACE = 1,
- WORLD_SPACE = 2
- };
-
- /// Internal string constants
- static const string SPACE;
- static const string INDEX;
- static const string GEOMPROP;
};
MATERIALX_NAMESPACE_END
diff --git a/source/MaterialXGenMsl/Nodes/BitangentNodeMsl.h b/source/MaterialXGenMsl/Nodes/BitangentNodeMsl.h
deleted file mode 100644
index 7239bb36d4..0000000000
--- a/source/MaterialXGenMsl/Nodes/BitangentNodeMsl.h
+++ /dev/null
@@ -1,26 +0,0 @@
-//
-// Copyright Contributors to the MaterialX Project
-// SPDX-License-Identifier: Apache-2.0
-//
-
-#ifndef MATERIALX_BITANGENTNODEMSL_H
-#define MATERIALX_BITANGENTNODEMSL_H
-
-#include
-
-MATERIALX_NAMESPACE_BEGIN
-
-/// Bitangent node implementation for MSL
-class MX_GENMSL_API BitangentNodeMsl : 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/MaterialXGenMsl/Nodes/FrameNodeMsl.h b/source/MaterialXGenMsl/Nodes/FrameNodeMsl.h
deleted file mode 100644
index 4ad554102b..0000000000
--- a/source/MaterialXGenMsl/Nodes/FrameNodeMsl.h
+++ /dev/null
@@ -1,26 +0,0 @@
-//
-// Copyright Contributors to the MaterialX Project
-// SPDX-License-Identifier: Apache-2.0
-//
-
-#ifndef MATERIALX_FRAMENODEMSL_H
-#define MATERIALX_FRAMENODEMSL_H
-
-#include
-
-MATERIALX_NAMESPACE_BEGIN
-
-/// Frame node implementation for MSL
-class MX_GENMSL_API FrameNodeMsl : 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/MaterialXGenMsl/Nodes/NormalNodeMsl.cpp b/source/MaterialXGenMsl/Nodes/NormalNodeMsl.cpp
deleted file mode 100644
index 6250290960..0000000000
--- a/source/MaterialXGenMsl/Nodes/NormalNodeMsl.cpp
+++ /dev/null
@@ -1,88 +0,0 @@
-//
-// Copyright Contributors to the MaterialX Project
-// SPDX-License-Identifier: Apache-2.0
-//
-
-#include
-
-#include
-
-MATERIALX_NAMESPACE_BEGIN
-
-ShaderNodeImplPtr NormalNodeMsl::create()
-{
- return std::make_shared();
-}
-
-void NormalNodeMsl::createVariables(const ShaderNode& node, 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_NORMAL, vs);
-
- const ShaderInput* spaceInput = node.getInput(SPACE);
- const int space = spaceInput ? spaceInput->getValue()->asA() : OBJECT_SPACE;
- if (space == WORLD_SPACE)
- {
- addStageUniform(HW::PRIVATE_UNIFORMS, Type::MATRIX44, HW::T_WORLD_INVERSE_TRANSPOSE_MATRIX, vs);
- addStageConnector(HW::VERTEX_DATA, Type::VECTOR3, HW::T_NORMAL_WORLD, vs, ps);
- }
- else
- {
- addStageConnector(HW::VERTEX_DATA, Type::VECTOR3, HW::T_NORMAL_OBJECT, vs, ps);
- }
-}
-
-void NormalNodeMsl::emitFunctionCall(const ShaderNode& node, GenContext& context, ShaderStage& stage) const
-{
- const MslShaderGenerator& shadergen = static_cast(context.getShaderGenerator());
-
- const ShaderInput* spaceInput = node.getInput(SPACE);
- const int space = spaceInput ? spaceInput->getValue()->asA() : OBJECT_SPACE;
-
- DEFINE_SHADER_STAGE(stage, Stage::VERTEX)
- {
- VariableBlock& vertexData = stage.getOutputBlock(HW::VERTEX_DATA);
- const string prefix = shadergen.getVertexDataPrefix(vertexData);
- if (space == WORLD_SPACE)
- {
- ShaderPort* normal = vertexData[HW::T_NORMAL_WORLD];
- if (!normal->isEmitted())
- {
- normal->setEmitted();
- shadergen.emitLine(prefix + normal->getVariable() + " = normalize((" + HW::T_WORLD_INVERSE_TRANSPOSE_MATRIX + " * float4(" + HW::T_IN_NORMAL + ", 0.0)).xyz)", stage);
- }
- }
- else
- {
- ShaderPort* normal = vertexData[HW::T_NORMAL_OBJECT];
- if (!normal->isEmitted())
- {
- normal->setEmitted();
- shadergen.emitLine(prefix + normal->getVariable() + " = " + HW::T_IN_NORMAL, stage);
- }
- }
- }
-
- DEFINE_SHADER_STAGE(stage, Stage::PIXEL)
- {
- VariableBlock& vertexData = stage.getInputBlock(HW::VERTEX_DATA);
- const string prefix = shadergen.getVertexDataPrefix(vertexData);
- shadergen.emitLineBegin(stage);
- shadergen.emitOutput(node.getOutput(), true, false, context, stage);
- if (space == WORLD_SPACE)
- {
- const ShaderPort* normal = vertexData[HW::T_NORMAL_WORLD];
- shadergen.emitString(" = normalize(" + prefix + normal->getVariable() + ")", stage);
- }
- else
- {
- const ShaderPort* normal = vertexData[HW::T_NORMAL_OBJECT];
- shadergen.emitString(" = normalize(" + prefix + normal->getVariable() + ")", stage);
- }
- shadergen.emitLineEnd(stage);
- }
-}
-
-MATERIALX_NAMESPACE_END
diff --git a/source/MaterialXGenMsl/Nodes/NormalNodeMsl.h b/source/MaterialXGenMsl/Nodes/NormalNodeMsl.h
deleted file mode 100644
index 7248613a74..0000000000
--- a/source/MaterialXGenMsl/Nodes/NormalNodeMsl.h
+++ /dev/null
@@ -1,26 +0,0 @@
-//
-// Copyright Contributors to the MaterialX Project
-// SPDX-License-Identifier: Apache-2.0
-//
-
-#ifndef MATERIALX_NORMALNODEMSL_H
-#define MATERIALX_NORMALNODEMSL_H
-
-#include
-
-MATERIALX_NAMESPACE_BEGIN
-
-/// Normal node implementation for MSL
-class MX_GENMSL_API NormalNodeMsl : 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/MaterialXGenMsl/Nodes/PositionNodeMsl.h b/source/MaterialXGenMsl/Nodes/PositionNodeMsl.h
deleted file mode 100644
index 1dada988be..0000000000
--- a/source/MaterialXGenMsl/Nodes/PositionNodeMsl.h
+++ /dev/null
@@ -1,26 +0,0 @@
-//
-// Copyright Contributors to the MaterialX Project
-// SPDX-License-Identifier: Apache-2.0
-//
-
-#ifndef MATERIALX_POSITIONNODEMSL_H
-#define MATERIALX_POSITIONNODEMSL_H
-
-#include
-
-MATERIALX_NAMESPACE_BEGIN
-
-/// Position node implementation for MSL
-class MX_GENMSL_API PositionNodeMsl : 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/MaterialXGenMsl/Nodes/SurfaceNodeMsl.cpp b/source/MaterialXGenMsl/Nodes/SurfaceNodeMsl.cpp
index c7fb7745b7..bd0cd91fb1 100644
--- a/source/MaterialXGenMsl/Nodes/SurfaceNodeMsl.cpp
+++ b/source/MaterialXGenMsl/Nodes/SurfaceNodeMsl.cpp
@@ -45,8 +45,8 @@ void SurfaceNodeMsl::createVariables(const ShaderNode&, GenContext& context, Sha
{
// TODO:
// The surface shader needs position, normal, view position and light sources. We should solve this by adding some
- // dependency mechanism so this implementation can be set to depend on the PositionNodeMsl, NormalNodeMsl
- // ViewDirectionNodeMsl and LightNodeMsl nodes instead? This is where the MaterialX attribute "internalgeomprops"
+ // dependency mechanism so this implementation can be set to depend on the HwPositionNode, HwNormalNode
+ // HwViewDirectionNode and LightNodeMsl nodes instead? This is where the MaterialX attribute "internalgeomprops"
// is needed.
//
ShaderStage& vs = shader.getStage(Stage::VERTEX);
diff --git a/source/MaterialXGenMsl/Nodes/SurfaceShaderNodeMsl.cpp b/source/MaterialXGenMsl/Nodes/SurfaceShaderNodeMsl.cpp
index a579c46f1b..a09796a557 100644
--- a/source/MaterialXGenMsl/Nodes/SurfaceShaderNodeMsl.cpp
+++ b/source/MaterialXGenMsl/Nodes/SurfaceShaderNodeMsl.cpp
@@ -24,8 +24,8 @@ void SurfaceShaderNodeMsl::createVariables(const ShaderNode&, GenContext& contex
{
// TODO:
// The surface shader needs position, view position and light sources. We should solve this by adding some
- // dependency mechanism so this implementation can be set to depend on the PositionNodeMsl,
- // ViewDirectionNodeMsl and LightNodeMsl nodes instead? This is where the MaterialX attribute "internalgeomprops"
+ // dependency mechanism so this implementation can be set to depend on the HwPositionNode,
+ // HwViewDirectionNode and LightNodeMsl nodes instead? This is where the MaterialX attribute "internalgeomprops"
// is needed.
//
ShaderStage& vs = shader.getStage(Stage::VERTEX);
diff --git a/source/MaterialXGenMsl/Nodes/TangentNodeMsl.cpp b/source/MaterialXGenMsl/Nodes/TangentNodeMsl.cpp
deleted file mode 100644
index 5e557e4e30..0000000000
--- a/source/MaterialXGenMsl/Nodes/TangentNodeMsl.cpp
+++ /dev/null
@@ -1,88 +0,0 @@
-//
-// Copyright Contributors to the MaterialX Project
-// SPDX-License-Identifier: Apache-2.0
-//
-
-#include
-
-#include
-
-MATERIALX_NAMESPACE_BEGIN
-
-ShaderNodeImplPtr TangentNodeMsl::create()
-{
- return std::make_shared();
-}
-
-void TangentNodeMsl::createVariables(const ShaderNode& node, 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_TANGENT, vs);
-
- const ShaderInput* spaceInput = node.getInput(SPACE);
- const int space = spaceInput ? spaceInput->getValue()->asA() : OBJECT_SPACE;
- if (space == WORLD_SPACE)
- {
- addStageUniform(HW::PRIVATE_UNIFORMS, Type::MATRIX44, HW::T_WORLD_MATRIX, vs);
- addStageConnector(HW::VERTEX_DATA, Type::VECTOR3, HW::T_TANGENT_WORLD, vs, ps);
- }
- else
- {
- addStageConnector(HW::VERTEX_DATA, Type::VECTOR3, HW::T_TANGENT_OBJECT, vs, ps);
- }
-}
-
-void TangentNodeMsl::emitFunctionCall(const ShaderNode& node, GenContext& context, ShaderStage& stage) const
-{
- const MslShaderGenerator& shadergen = static_cast(context.getShaderGenerator());
-
- const ShaderInput* spaceInput = node.getInput(SPACE);
- const int space = spaceInput ? spaceInput->getValue()->asA() : OBJECT_SPACE;
-
- DEFINE_SHADER_STAGE(stage, Stage::VERTEX)
- {
- VariableBlock& vertexData = stage.getOutputBlock(HW::VERTEX_DATA);
- const string prefix = shadergen.getVertexDataPrefix(vertexData);
- if (space == WORLD_SPACE)
- {
- ShaderPort* tangent = vertexData[HW::T_TANGENT_WORLD];
- if (!tangent->isEmitted())
- {
- tangent->setEmitted();
- shadergen.emitLine(prefix + tangent->getVariable() + " = normalize((" + HW::T_WORLD_MATRIX + " * float4(" + HW::T_IN_TANGENT + ", 0.0)).xyz)", stage);
- }
- }
- else
- {
- ShaderPort* tangent = vertexData[HW::T_TANGENT_OBJECT];
- if (!tangent->isEmitted())
- {
- tangent->setEmitted();
- shadergen.emitLine(prefix + tangent->getVariable() + " = " + HW::T_IN_TANGENT, stage);
- }
- }
- }
-
- DEFINE_SHADER_STAGE(stage, Stage::PIXEL)
- {
- VariableBlock& vertexData = stage.getInputBlock(HW::VERTEX_DATA);
- const string prefix = shadergen.getVertexDataPrefix(vertexData);
- shadergen.emitLineBegin(stage);
- shadergen.emitOutput(node.getOutput(), true, false, context, stage);
- if (space == WORLD_SPACE)
- {
- const ShaderPort* tangent = vertexData[HW::T_TANGENT_WORLD];
- shadergen.emitString(" = normalize(" + prefix + tangent->getVariable() + ")", stage);
- }
- else
- {
- const ShaderPort* tangent = vertexData[HW::T_TANGENT_OBJECT];
- shadergen.emitString(" = normalize(" + prefix + tangent->getVariable() + ")", stage);
- }
- shadergen.emitLineEnd(stage);
- }
-}
-
-MATERIALX_NAMESPACE_END
diff --git a/source/MaterialXGenMsl/Nodes/TangentNodeMsl.h b/source/MaterialXGenMsl/Nodes/TangentNodeMsl.h
deleted file mode 100644
index 42e2c7ef7c..0000000000
--- a/source/MaterialXGenMsl/Nodes/TangentNodeMsl.h
+++ /dev/null
@@ -1,26 +0,0 @@
-//
-// Copyright Contributors to the MaterialX Project
-// SPDX-License-Identifier: Apache-2.0
-//
-
-#ifndef MATERIALX_TANGENTNODEMSL_H
-#define MATERIALX_TANGENTNODEMSL_H
-
-#include
-
-MATERIALX_NAMESPACE_BEGIN
-
-/// Tangent node implementation for MSL
-class MX_GENMSL_API TangentNodeMsl : 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/MaterialXGenMsl/Nodes/TimeNodeMsl.h b/source/MaterialXGenMsl/Nodes/TimeNodeMsl.h
deleted file mode 100644
index 07c505a082..0000000000
--- a/source/MaterialXGenMsl/Nodes/TimeNodeMsl.h
+++ /dev/null
@@ -1,26 +0,0 @@
-//
-// Copyright Contributors to the MaterialX Project
-// SPDX-License-Identifier: Apache-2.0
-//
-
-#ifndef MATERIALX_TIMENODEMSL_H
-#define MATERIALX_TIMENODEMSL_H
-
-#include
-
-MATERIALX_NAMESPACE_BEGIN
-
-/// Time node implementation for MSL
-class MX_GENMSL_API TimeNodeMsl : 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/MaterialXGenMsl/Nodes/ViewDirectionNodeMsl.h b/source/MaterialXGenMsl/Nodes/ViewDirectionNodeMsl.h
deleted file mode 100644
index be7a40108a..0000000000
--- a/source/MaterialXGenMsl/Nodes/ViewDirectionNodeMsl.h
+++ /dev/null
@@ -1,26 +0,0 @@
-//
-// 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/MaterialXGenShader/HwShaderGenerator.cpp b/source/MaterialXGenShader/HwShaderGenerator.cpp
index 6ba94d1280..d0ca836416 100644
--- a/source/MaterialXGenShader/HwShaderGenerator.cpp
+++ b/source/MaterialXGenShader/HwShaderGenerator.cpp
@@ -12,6 +12,24 @@
MATERIALX_NAMESPACE_BEGIN
+const string HwImplementation::SPACE = "space";
+const string HwImplementation::INDEX = "index";
+const string HwImplementation::GEOMPROP = "geomprop";
+
+namespace
+{
+
+// When node inputs with these names are modified, we assume the
+// associated HW shader must be recompiled.
+const StringSet IMMUTABLE_INPUTS =
+{
+ "index",
+ "space",
+ "attrname"
+};
+
+} // anonymous namespace
+
namespace HW
{
@@ -619,4 +637,9 @@ void HwShaderGenerator::addStageLightingUniforms(GenContext& context, ShaderStag
}
}
+bool HwImplementation::isEditable(const ShaderInput& input) const
+{
+ return IMMUTABLE_INPUTS.count(input.getName()) == 0;
+}
+
MATERIALX_NAMESPACE_END
diff --git a/source/MaterialXGenShader/HwShaderGenerator.h b/source/MaterialXGenShader/HwShaderGenerator.h
index f839ac56bd..f93a8983ca 100644
--- a/source/MaterialXGenShader/HwShaderGenerator.h
+++ b/source/MaterialXGenShader/HwShaderGenerator.h
@@ -340,6 +340,31 @@ class MX_GENSHADER_API HwShaderGenerator : public ShaderGenerator
mutable ClosureContext _defEmission;
};
+/// @class HwShaderGenerator
+/// Base class for HW node implementations.
+class MX_GENSHADER_API HwImplementation : public ShaderNodeImpl
+{
+ public:
+ bool isEditable(const ShaderInput& input) const override;
+
+ protected:
+ HwImplementation() { }
+
+ // Integer identifiers for coordinate spaces.
+ // The order must match the order given for the space enum string in stdlib.
+ enum Space
+ {
+ MODEL_SPACE = 0,
+ OBJECT_SPACE = 1,
+ WORLD_SPACE = 2
+ };
+
+ /// Internal string constants
+ static const string SPACE;
+ static const string INDEX;
+ static const string GEOMPROP;
+};
+
/// @class HwResourceBindingContext
/// Class representing a context for resource binding for hardware resources.
class MX_GENSHADER_API HwResourceBindingContext : public GenUserData
diff --git a/source/MaterialXGenMsl/Nodes/BitangentNodeMsl.cpp b/source/MaterialXGenShader/Nodes/HwBitangentNode.cpp
similarity index 91%
rename from source/MaterialXGenMsl/Nodes/BitangentNodeMsl.cpp
rename to source/MaterialXGenShader/Nodes/HwBitangentNode.cpp
index 97ca079d35..83c43a3398 100644
--- a/source/MaterialXGenMsl/Nodes/BitangentNodeMsl.cpp
+++ b/source/MaterialXGenShader/Nodes/HwBitangentNode.cpp
@@ -3,18 +3,18 @@
// SPDX-License-Identifier: Apache-2.0
//
-#include
+#include
#include
MATERIALX_NAMESPACE_BEGIN
-ShaderNodeImplPtr BitangentNodeMsl::create()
+ShaderNodeImplPtr HwBitangentNode::create()
{
- return std::make_shared();
+ return std::make_shared();
}
-void BitangentNodeMsl::createVariables(const ShaderNode& node, GenContext& context, Shader& shader) const
+void HwBitangentNode::createVariables(const ShaderNode& node, GenContext& context, Shader& shader) const
{
const GenOptions& options = context.getOptions();
@@ -51,9 +51,9 @@ void BitangentNodeMsl::createVariables(const ShaderNode& node, GenContext& conte
}
}
-void BitangentNodeMsl::emitFunctionCall(const ShaderNode& node, GenContext& context, ShaderStage& stage) const
+void HwBitangentNode::emitFunctionCall(const ShaderNode& node, GenContext& context, ShaderStage& stage) const
{
- const MslShaderGenerator& shadergen = static_cast(context.getShaderGenerator());
+ const HwShaderGenerator& shadergen = static_cast(context.getShaderGenerator());
const GenOptions& options = context.getOptions();
const ShaderInput* spaceInput = node.getInput(SPACE);
diff --git a/source/MaterialXGenShader/Nodes/HwBitangentNode.h b/source/MaterialXGenShader/Nodes/HwBitangentNode.h
new file mode 100644
index 0000000000..a8bfa0bf11
--- /dev/null
+++ b/source/MaterialXGenShader/Nodes/HwBitangentNode.h
@@ -0,0 +1,26 @@
+//
+// Copyright Contributors to the MaterialX Project
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#ifndef MATERIALX_HWBITANGENTNODE_H
+#define MATERIALX_HWBITANGENTNODE_H
+
+#include
+
+MATERIALX_NAMESPACE_BEGIN
+
+/// Bitangent node implementation for hardware languages
+class MX_GENSHADER_API HwBitangentNode : public HwImplementation
+{
+ 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/MaterialXGenMsl/Nodes/FrameNodeMsl.cpp b/source/MaterialXGenShader/Nodes/HwFrameNode.cpp
similarity index 67%
rename from source/MaterialXGenMsl/Nodes/FrameNodeMsl.cpp
rename to source/MaterialXGenShader/Nodes/HwFrameNode.cpp
index faac05027a..cd6a3319a8 100644
--- a/source/MaterialXGenMsl/Nodes/FrameNodeMsl.cpp
+++ b/source/MaterialXGenShader/Nodes/HwFrameNode.cpp
@@ -3,24 +3,24 @@
// SPDX-License-Identifier: Apache-2.0
//
-#include
+#include
#include
MATERIALX_NAMESPACE_BEGIN
-ShaderNodeImplPtr FrameNodeMsl::create()
+ShaderNodeImplPtr HwFrameNode::create()
{
- return std::make_shared();
+ return std::make_shared();
}
-void FrameNodeMsl::createVariables(const ShaderNode&, GenContext&, Shader& shader) const
+void HwFrameNode::createVariables(const ShaderNode&, GenContext&, Shader& shader) const
{
ShaderStage& ps = shader.getStage(Stage::PIXEL);
addStageUniform(HW::PRIVATE_UNIFORMS, Type::FLOAT, HW::T_FRAME, ps);
}
-void FrameNodeMsl::emitFunctionCall(const ShaderNode& node, GenContext& context, ShaderStage& stage) const
+void HwFrameNode::emitFunctionCall(const ShaderNode& node, GenContext& context, ShaderStage& stage) const
{
DEFINE_SHADER_STAGE(stage, Stage::PIXEL)
{
diff --git a/source/MaterialXGenGlsl/Nodes/TangentNodeGlsl.h b/source/MaterialXGenShader/Nodes/HwFrameNode.h
similarity index 65%
rename from source/MaterialXGenGlsl/Nodes/TangentNodeGlsl.h
rename to source/MaterialXGenShader/Nodes/HwFrameNode.h
index 90a5b3aaad..4487a6a0b9 100644
--- a/source/MaterialXGenGlsl/Nodes/TangentNodeGlsl.h
+++ b/source/MaterialXGenShader/Nodes/HwFrameNode.h
@@ -3,15 +3,15 @@
// SPDX-License-Identifier: Apache-2.0
//
-#ifndef MATERIALX_TANGENTNODEGLSL_H
-#define MATERIALX_TANGENTNODEGLSL_H
+#ifndef MATERIALX_HWFRAMENODE_H
+#define MATERIALX_HWFRAMENODE_H
-#include
+#include
MATERIALX_NAMESPACE_BEGIN
-/// Tangent node implementation for GLSL
-class MX_GENGLSL_API TangentNodeGlsl : public GlslImplementation
+/// Frame node implementation for hardware languages
+class MX_GENSHADER_API HwFrameNode : public HwImplementation
{
public:
static ShaderNodeImplPtr create();
diff --git a/source/MaterialXGenGlsl/Nodes/NormalNodeGlsl.cpp b/source/MaterialXGenShader/Nodes/HwNormalNode.cpp
similarity index 85%
rename from source/MaterialXGenGlsl/Nodes/NormalNodeGlsl.cpp
rename to source/MaterialXGenShader/Nodes/HwNormalNode.cpp
index d9e27b87df..01234dcb46 100644
--- a/source/MaterialXGenGlsl/Nodes/NormalNodeGlsl.cpp
+++ b/source/MaterialXGenShader/Nodes/HwNormalNode.cpp
@@ -3,18 +3,18 @@
// SPDX-License-Identifier: Apache-2.0
//
-#include
+#include
#include
MATERIALX_NAMESPACE_BEGIN
-ShaderNodeImplPtr NormalNodeGlsl::create()
+ShaderNodeImplPtr HwNormalNode::create()
{
- return std::make_shared();
+ return std::make_shared();
}
-void NormalNodeGlsl::createVariables(const ShaderNode& node, GenContext&, Shader& shader) const
+void HwNormalNode::createVariables(const ShaderNode& node, GenContext&, Shader& shader) const
{
ShaderStage& vs = shader.getStage(Stage::VERTEX);
ShaderStage& ps = shader.getStage(Stage::PIXEL);
@@ -34,9 +34,9 @@ void NormalNodeGlsl::createVariables(const ShaderNode& node, GenContext&, Shader
}
}
-void NormalNodeGlsl::emitFunctionCall(const ShaderNode& node, GenContext& context, ShaderStage& stage) const
+void HwNormalNode::emitFunctionCall(const ShaderNode& node, GenContext& context, ShaderStage& stage) const
{
- const GlslShaderGenerator& shadergen = static_cast(context.getShaderGenerator());
+ const HwShaderGenerator& shadergen = static_cast(context.getShaderGenerator());
const ShaderInput* spaceInput = node.getInput(SPACE);
const int space = spaceInput ? spaceInput->getValue()->asA() : OBJECT_SPACE;
diff --git a/source/MaterialXGenGlsl/Nodes/PositionNodeGlsl.h b/source/MaterialXGenShader/Nodes/HwNormalNode.h
similarity index 64%
rename from source/MaterialXGenGlsl/Nodes/PositionNodeGlsl.h
rename to source/MaterialXGenShader/Nodes/HwNormalNode.h
index 95dddbce8e..fb19050600 100644
--- a/source/MaterialXGenGlsl/Nodes/PositionNodeGlsl.h
+++ b/source/MaterialXGenShader/Nodes/HwNormalNode.h
@@ -3,15 +3,15 @@
// SPDX-License-Identifier: Apache-2.0
//
-#ifndef MATERIALX_POSITIONNODEGLSL_H
-#define MATERIALX_POSITIONNODEGLSL_H
+#ifndef MATERIALX_HWNORMALNODE_H
+#define MATERIALX_HWNORMALNODE_H
-#include
+#include
MATERIALX_NAMESPACE_BEGIN
-/// Position node implementation for GLSL
-class MX_GENGLSL_API PositionNodeGlsl : public GlslImplementation
+/// Normal node implementation for hardware languages
+class MX_GENSHADER_API HwNormalNode : public HwImplementation
{
public:
static ShaderNodeImplPtr create();
diff --git a/source/MaterialXGenMsl/Nodes/PositionNodeMsl.cpp b/source/MaterialXGenShader/Nodes/HwPositionNode.cpp
similarity index 84%
rename from source/MaterialXGenMsl/Nodes/PositionNodeMsl.cpp
rename to source/MaterialXGenShader/Nodes/HwPositionNode.cpp
index 6f45f4364b..df7c11f4e6 100644
--- a/source/MaterialXGenMsl/Nodes/PositionNodeMsl.cpp
+++ b/source/MaterialXGenShader/Nodes/HwPositionNode.cpp
@@ -3,18 +3,18 @@
// SPDX-License-Identifier: Apache-2.0
//
-#include
+#include
#include
MATERIALX_NAMESPACE_BEGIN
-ShaderNodeImplPtr PositionNodeMsl::create()
+ShaderNodeImplPtr HwPositionNode::create()
{
- return std::make_shared();
+ return std::make_shared();
}
-void PositionNodeMsl::createVariables(const ShaderNode& node, GenContext&, Shader& shader) const
+void HwPositionNode::createVariables(const ShaderNode& node, GenContext&, Shader& shader) const
{
ShaderStage vs = shader.getStage(Stage::VERTEX);
ShaderStage ps = shader.getStage(Stage::PIXEL);
@@ -33,9 +33,9 @@ void PositionNodeMsl::createVariables(const ShaderNode& node, GenContext&, Shade
}
}
-void PositionNodeMsl::emitFunctionCall(const ShaderNode& node, GenContext& context, ShaderStage& stage) const
+void HwPositionNode::emitFunctionCall(const ShaderNode& node, GenContext& context, ShaderStage& stage) const
{
- const MslShaderGenerator& shadergen = static_cast(context.getShaderGenerator());
+ const HwShaderGenerator& shadergen = static_cast(context.getShaderGenerator());
const ShaderInput* spaceInput = node.getInput(SPACE);
const int space = spaceInput ? spaceInput->getValue()->asA() : OBJECT_SPACE;
diff --git a/source/MaterialXGenGlsl/Nodes/FrameNodeGlsl.h b/source/MaterialXGenShader/Nodes/HwPositionNode.h
similarity index 63%
rename from source/MaterialXGenGlsl/Nodes/FrameNodeGlsl.h
rename to source/MaterialXGenShader/Nodes/HwPositionNode.h
index f3a5197eae..ae2ce5c3f5 100644
--- a/source/MaterialXGenGlsl/Nodes/FrameNodeGlsl.h
+++ b/source/MaterialXGenShader/Nodes/HwPositionNode.h
@@ -3,15 +3,15 @@
// SPDX-License-Identifier: Apache-2.0
//
-#ifndef MATERIALX_FRAMENODEGLSL_H
-#define MATERIALX_FRAMENODEGLSL_H
+#ifndef MATERIALX_HWPOSITIONNODE_H
+#define MATERIALX_HWPOSITIONNODE_H
-#include
+#include
MATERIALX_NAMESPACE_BEGIN
-/// Frame node implementation for GLSL
-class MX_GENGLSL_API FrameNodeGlsl : public GlslImplementation
+/// Position node implementation for hardware languages
+class MX_GENSHADER_API HwPositionNode : public HwImplementation
{
public:
static ShaderNodeImplPtr create();
diff --git a/source/MaterialXGenGlsl/Nodes/TangentNodeGlsl.cpp b/source/MaterialXGenShader/Nodes/HwTangentNode.cpp
similarity index 85%
rename from source/MaterialXGenGlsl/Nodes/TangentNodeGlsl.cpp
rename to source/MaterialXGenShader/Nodes/HwTangentNode.cpp
index daffaf0e2c..6e80537932 100644
--- a/source/MaterialXGenGlsl/Nodes/TangentNodeGlsl.cpp
+++ b/source/MaterialXGenShader/Nodes/HwTangentNode.cpp
@@ -3,18 +3,18 @@
// SPDX-License-Identifier: Apache-2.0
//
-#include
+#include
#include
MATERIALX_NAMESPACE_BEGIN
-ShaderNodeImplPtr TangentNodeGlsl::create()
+ShaderNodeImplPtr HwTangentNode::create()
{
- return std::make_shared();
+ return std::make_shared();
}
-void TangentNodeGlsl::createVariables(const ShaderNode& node, GenContext&, Shader& shader) const
+void HwTangentNode::createVariables(const ShaderNode& node, GenContext&, Shader& shader) const
{
ShaderStage& vs = shader.getStage(Stage::VERTEX);
ShaderStage& ps = shader.getStage(Stage::PIXEL);
@@ -34,9 +34,9 @@ void TangentNodeGlsl::createVariables(const ShaderNode& node, GenContext&, Shade
}
}
-void TangentNodeGlsl::emitFunctionCall(const ShaderNode& node, GenContext& context, ShaderStage& stage) const
+void HwTangentNode::emitFunctionCall(const ShaderNode& node, GenContext& context, ShaderStage& stage) const
{
- const GlslShaderGenerator& shadergen = static_cast(context.getShaderGenerator());
+ const HwShaderGenerator& shadergen = static_cast(context.getShaderGenerator());
const ShaderInput* spaceInput = node.getInput(SPACE);
const int space = spaceInput ? spaceInput->getValue()->asA() : OBJECT_SPACE;
diff --git a/source/MaterialXGenGlsl/Nodes/BitangentNodeGlsl.h b/source/MaterialXGenShader/Nodes/HwTangentNode.h
similarity index 64%
rename from source/MaterialXGenGlsl/Nodes/BitangentNodeGlsl.h
rename to source/MaterialXGenShader/Nodes/HwTangentNode.h
index 905b2808e0..b36d7f3c56 100644
--- a/source/MaterialXGenGlsl/Nodes/BitangentNodeGlsl.h
+++ b/source/MaterialXGenShader/Nodes/HwTangentNode.h
@@ -3,15 +3,15 @@
// SPDX-License-Identifier: Apache-2.0
//
-#ifndef MATERIALX_BITANGENTNODEGLSL_H
-#define MATERIALX_BITANGENTNODEGLSL_H
+#ifndef MATERIALX_HWTANGENTNODE_H
+#define MATERIALX_HWTANGENTNODE_H
-#include
+#include
MATERIALX_NAMESPACE_BEGIN
-/// Bitangent node implementation for GLSL
-class MX_GENGLSL_API BitangentNodeGlsl : public GlslImplementation
+/// Tangent node implementation for hardware languages
+class MX_GENSHADER_API HwTangentNode : public HwImplementation
{
public:
static ShaderNodeImplPtr create();
diff --git a/source/MaterialXGenMsl/Nodes/TimeNodeMsl.cpp b/source/MaterialXGenShader/Nodes/HwTimeNode.cpp
similarity index 72%
rename from source/MaterialXGenMsl/Nodes/TimeNodeMsl.cpp
rename to source/MaterialXGenShader/Nodes/HwTimeNode.cpp
index 0c54861b40..8f802a0764 100644
--- a/source/MaterialXGenMsl/Nodes/TimeNodeMsl.cpp
+++ b/source/MaterialXGenShader/Nodes/HwTimeNode.cpp
@@ -3,24 +3,24 @@
// SPDX-License-Identifier: Apache-2.0
//
-#include
+#include
#include
MATERIALX_NAMESPACE_BEGIN
-ShaderNodeImplPtr TimeNodeMsl::create()
+ShaderNodeImplPtr HwTimeNode::create()
{
- return std::make_shared();
+ return std::make_shared();
}
-void TimeNodeMsl::createVariables(const ShaderNode&, GenContext&, Shader& shader) const
+void HwTimeNode::createVariables(const ShaderNode&, GenContext&, Shader& shader) const
{
ShaderStage& ps = shader.getStage(Stage::PIXEL);
addStageUniform(HW::PRIVATE_UNIFORMS, Type::FLOAT, HW::T_FRAME, ps);
}
-void TimeNodeMsl::emitFunctionCall(const ShaderNode& node, GenContext& context, ShaderStage& stage) const
+void HwTimeNode::emitFunctionCall(const ShaderNode& node, GenContext& context, ShaderStage& stage) const
{
DEFINE_SHADER_STAGE(stage, Stage::PIXEL)
{
diff --git a/source/MaterialXGenGlsl/Nodes/NormalNodeGlsl.h b/source/MaterialXGenShader/Nodes/HwTimeNode.h
similarity index 65%
rename from source/MaterialXGenGlsl/Nodes/NormalNodeGlsl.h
rename to source/MaterialXGenShader/Nodes/HwTimeNode.h
index acb4d5085d..e5e1a2fcd4 100644
--- a/source/MaterialXGenGlsl/Nodes/NormalNodeGlsl.h
+++ b/source/MaterialXGenShader/Nodes/HwTimeNode.h
@@ -3,15 +3,15 @@
// SPDX-License-Identifier: Apache-2.0
//
-#ifndef MATERIALX_NORMALNODEGLSL_H
-#define MATERIALX_NORMALNODEGLSL_H
+#ifndef MATERIALX_HWTIMENODE_H
+#define MATERIALX_HWTIMENODE_H
-#include
+#include
MATERIALX_NAMESPACE_BEGIN
-/// Normal node implementation for GLSL
-class MX_GENGLSL_API NormalNodeGlsl : public GlslImplementation
+/// Time node implementation for hardware languages
+class MX_GENSHADER_API HwTimeNode : public HwImplementation
{
public:
static ShaderNodeImplPtr create();
diff --git a/source/MaterialXGenMsl/Nodes/ViewDirectionNodeMsl.cpp b/source/MaterialXGenShader/Nodes/HwViewDirectionNode.cpp
similarity index 76%
rename from source/MaterialXGenMsl/Nodes/ViewDirectionNodeMsl.cpp
rename to source/MaterialXGenShader/Nodes/HwViewDirectionNode.cpp
index 1443b5c320..819ac93029 100644
--- a/source/MaterialXGenMsl/Nodes/ViewDirectionNodeMsl.cpp
+++ b/source/MaterialXGenShader/Nodes/HwViewDirectionNode.cpp
@@ -3,18 +3,18 @@
// SPDX-License-Identifier: Apache-2.0
//
-#include
+#include
#include
MATERIALX_NAMESPACE_BEGIN
-ShaderNodeImplPtr ViewDirectionNodeMsl::create()
+ShaderNodeImplPtr HwViewDirectionNode::create()
{
- return std::make_shared();
+ return std::make_shared();
}
-void ViewDirectionNodeMsl::createVariables(const ShaderNode&, GenContext&, Shader& shader) const
+void HwViewDirectionNode::createVariables(const ShaderNode&, GenContext&, Shader& shader) const
{
ShaderStage& vs = shader.getStage(Stage::VERTEX);
ShaderStage& ps = shader.getStage(Stage::PIXEL);
@@ -24,9 +24,9 @@ void ViewDirectionNodeMsl::createVariables(const ShaderNode&, GenContext&, Shade
addStageUniform(HW::PRIVATE_UNIFORMS, Type::VECTOR3, HW::T_VIEW_POSITION, ps);
}
-void ViewDirectionNodeMsl::emitFunctionCall(const ShaderNode& node, GenContext& context, ShaderStage& stage) const
+void HwViewDirectionNode::emitFunctionCall(const ShaderNode& node, GenContext& context, ShaderStage& stage) const
{
- const MslShaderGenerator& shadergen = static_cast(context.getShaderGenerator());
+ const HwShaderGenerator& shadergen = static_cast(context.getShaderGenerator());
DEFINE_SHADER_STAGE(stage, Stage::VERTEX)
{
diff --git a/source/MaterialXGenShader/Nodes/HwViewDirectionNode.h b/source/MaterialXGenShader/Nodes/HwViewDirectionNode.h
new file mode 100644
index 0000000000..143d89d437
--- /dev/null
+++ b/source/MaterialXGenShader/Nodes/HwViewDirectionNode.h
@@ -0,0 +1,26 @@
+//
+// Copyright Contributors to the MaterialX Project
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#ifndef MATERIALX_HWVIEWDIRECTIONNODE_H
+#define MATERIALX_HWVIEWDIRECTIONNODE_H
+
+#include
+
+MATERIALX_NAMESPACE_BEGIN
+
+/// ViewDirection node implementation for hardware languages
+class MX_GENSHADER_API HwViewDirectionNode : public HwImplementation
+{
+ 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/MaterialXView/Viewer.cpp b/source/MaterialXView/Viewer.cpp
index f6da076f17..c6a810c2d4 100644
--- a/source/MaterialXView/Viewer.cpp
+++ b/source/MaterialXView/Viewer.cpp
@@ -402,7 +402,7 @@ void Viewer::loadEnvironmentLight()
}
// Look for an irradiance map using an expected filename convention.
- mx::ImagePtr envIrradianceMap = _imageHandler->getZeroImage();
+ mx::ImagePtr envIrradianceMap;
if (!_normalizeEnvironment && !_splitDirectLight)
{
mx::FilePath envIrradiancePath = _envRadianceFilename.getParentPath() / IRRADIANCE_MAP_FOLDER / _envRadianceFilename.getBaseName();
@@ -410,7 +410,7 @@ void Viewer::loadEnvironmentLight()
}
// If not found, then generate an irradiance map via spherical harmonics.
- if (envIrradianceMap == _imageHandler->getZeroImage())
+ if (!envIrradianceMap || envIrradianceMap->getWidth() == 1)
{
if (_generateReferenceIrradiance)
{
diff --git a/source/PyMaterialX/PyMaterialXGenGlsl/PyGlslShaderGenerator.cpp b/source/PyMaterialX/PyMaterialXGenGlsl/PyGlslShaderGenerator.cpp
index ba4a9c981e..f26d4f2aee 100644
--- a/source/PyMaterialX/PyMaterialXGenGlsl/PyGlslShaderGenerator.cpp
+++ b/source/PyMaterialX/PyMaterialXGenGlsl/PyGlslShaderGenerator.cpp
@@ -12,8 +12,6 @@
#include
#include
-#include
-
namespace py = pybind11;
namespace mx = MaterialX;
diff --git a/source/PyMaterialX/PyMaterialXGenMdl/PyMdlShaderGenerator.cpp b/source/PyMaterialX/PyMaterialXGenMdl/PyMdlShaderGenerator.cpp
index d06e6f5ba7..d0702cfff0 100644
--- a/source/PyMaterialX/PyMaterialXGenMdl/PyMdlShaderGenerator.cpp
+++ b/source/PyMaterialX/PyMaterialXGenMdl/PyMdlShaderGenerator.cpp
@@ -8,12 +8,9 @@
#include
#include
-#include
-
namespace py = pybind11;
namespace mx = MaterialX;
-
void bindPyMdlShaderGenerator(py::module& mod)
{
py::class_(mod, "MdlShaderGenerator")
diff --git a/source/PyMaterialX/PyMaterialXGenMsl/PyMslShaderGenerator.cpp b/source/PyMaterialX/PyMaterialXGenMsl/PyMslShaderGenerator.cpp
index 870b9bc02c..48259cad07 100644
--- a/source/PyMaterialX/PyMaterialXGenMsl/PyMslShaderGenerator.cpp
+++ b/source/PyMaterialX/PyMaterialXGenMsl/PyMslShaderGenerator.cpp
@@ -10,8 +10,6 @@
#include
#include
-#include
-
namespace py = pybind11;
namespace mx = MaterialX;
diff --git a/source/PyMaterialX/PyMaterialXGenOsl/PyOslShaderGenerator.cpp b/source/PyMaterialX/PyMaterialXGenOsl/PyOslShaderGenerator.cpp
index 39082c28f5..7c53002669 100644
--- a/source/PyMaterialX/PyMaterialXGenOsl/PyOslShaderGenerator.cpp
+++ b/source/PyMaterialX/PyMaterialXGenOsl/PyOslShaderGenerator.cpp
@@ -9,8 +9,6 @@
#include
#include
-#include
-
namespace py = pybind11;
namespace mx = MaterialX;
diff --git a/source/PyMaterialX/PyMaterialXGenShader/PyHwShaderGenerator.cpp b/source/PyMaterialX/PyMaterialXGenShader/PyHwShaderGenerator.cpp
index d13b2ad133..286021cb90 100644
--- a/source/PyMaterialX/PyMaterialXGenShader/PyHwShaderGenerator.cpp
+++ b/source/PyMaterialX/PyMaterialXGenShader/PyHwShaderGenerator.cpp
@@ -9,8 +9,6 @@
#include
#include
-#include
-
namespace py = pybind11;
namespace mx = MaterialX;