Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
jstone-lucasfilm authored Oct 13, 2023
2 parents 011f6f3 + eb52ec2 commit 9d1cc79
Show file tree
Hide file tree
Showing 15 changed files with 334 additions and 312 deletions.
25 changes: 25 additions & 0 deletions resources/Materials/TestSuite/stdlib/texture/texcoord.mtlx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0"?>
<materialx version="1.38" colorspace="lin_rec709">
<!--
Test for texture coordinates. This test makes sure that two texture coordinate nodes with various
widths can coexist.
-->
<standard_surface name="standard_surface" type="surfaceshader" xpos="6.152174" ypos="-0.560345">
<input name="base" type="float" value="1" />
<input name="base_color" type="color3" nodename="swizzle_vector2_color3" />
<input name="specular_roughness" type="float" value="0.1" />
<input name="subsurface" type="float" value="0.4" />
<input name="subsurface_color" type="color3" nodename="swizzle_vector3_color3" />
</standard_surface>
<surfacematerial name="surfacematerial" type="material" xpos="8.695652" ypos="0.000000">
<input name="surfaceshader" type="surfaceshader" nodename="standard_surface" />
</surfacematerial>
<texcoord name="texcoord_vector2" type="vector2" xpos="1.666667" ypos="-1.405172" />
<texcoord name="texcoord_vector3" type="vector3" xpos="0.268116" ypos="1.068966" />
<swizzle name="swizzle_vector3_color3" type="color3" xpos="3.101449" ypos="0.698276">
<input name="in" type="vector3" nodename="texcoord_vector3" />
</swizzle>
<swizzle name="swizzle_vector2_color3" type="color3" xpos="4.260870" ypos="-2.896552">
<input name="in" type="vector2" nodename="texcoord_vector2" />
</swizzle>
</materialx>
6 changes: 3 additions & 3 deletions source/MaterialXGenGlsl/GlslShaderGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <MaterialXGenGlsl/Nodes/NormalNodeGlsl.h>
#include <MaterialXGenGlsl/Nodes/TangentNodeGlsl.h>
#include <MaterialXGenGlsl/Nodes/BitangentNodeGlsl.h>
#include <MaterialXGenGlsl/Nodes/TexCoordNodeGlsl.h>
#include <MaterialXGenGlsl/Nodes/GeomColorNodeGlsl.h>
#include <MaterialXGenGlsl/Nodes/GeomPropValueNodeGlsl.h>
#include <MaterialXGenGlsl/Nodes/FrameNodeGlsl.h>
Expand All @@ -34,6 +33,7 @@
#include <MaterialXGenShader/Nodes/CombineNode.h>
#include <MaterialXGenShader/Nodes/SwitchNode.h>
#include <MaterialXGenShader/Nodes/HwImageNode.h>
#include <MaterialXGenShader/Nodes/HwTexCoordNode.h>
#include <MaterialXGenShader/Nodes/ClosureSourceCodeNode.h>
#include <MaterialXGenShader/Nodes/ClosureCompoundNode.h>
#include <MaterialXGenShader/Nodes/ClosureLayerNode.h>
Expand Down Expand Up @@ -174,8 +174,8 @@ GlslShaderGenerator::GlslShaderGenerator() :
// <!-- <bitangent> -->
registerImplementation("IM_bitangent_vector3_" + GlslShaderGenerator::TARGET, BitangentNodeGlsl::create);
// <!-- <texcoord> -->
registerImplementation("IM_texcoord_vector2_" + GlslShaderGenerator::TARGET, TexCoordNodeGlsl::create);
registerImplementation("IM_texcoord_vector3_" + GlslShaderGenerator::TARGET, TexCoordNodeGlsl::create);
registerImplementation("IM_texcoord_vector2_" + GlslShaderGenerator::TARGET, HwTexCoordNode::create);
registerImplementation("IM_texcoord_vector3_" + GlslShaderGenerator::TARGET, HwTexCoordNode::create);
// <!-- <geomcolor> -->
registerImplementation("IM_geomcolor_float_" + GlslShaderGenerator::TARGET, GeomColorNodeGlsl::create);
registerImplementation("IM_geomcolor_color3_" + GlslShaderGenerator::TARGET, GeomColorNodeGlsl::create);
Expand Down
2 changes: 1 addition & 1 deletion source/MaterialXGenGlsl/GlslShaderGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class MX_GENGLSL_API GlslShaderGenerator : public HwShaderGenerator
ShaderNodeImplPtr getImplementation(const NodeDef& nodedef, GenContext& context) const override;

/// Determine the prefix of vertex data variables.
virtual string getVertexDataPrefix(const VariableBlock& vertexData) const;
string getVertexDataPrefix(const VariableBlock& vertexData) const override;

public:
/// Unique identifier for this generator target
Expand Down
62 changes: 0 additions & 62 deletions source/MaterialXGenGlsl/Nodes/TexCoordNodeGlsl.cpp

This file was deleted.

6 changes: 3 additions & 3 deletions source/MaterialXGenMsl/MslShaderGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <MaterialXGenMsl/Nodes/NormalNodeMsl.h>
#include <MaterialXGenMsl/Nodes/TangentNodeMsl.h>
#include <MaterialXGenMsl/Nodes/BitangentNodeMsl.h>
#include <MaterialXGenMsl/Nodes/TexCoordNodeMsl.h>
#include <MaterialXGenMsl/Nodes/GeomColorNodeMsl.h>
#include <MaterialXGenMsl/Nodes/GeomPropValueNodeMsl.h>
#include <MaterialXGenMsl/Nodes/FrameNodeMsl.h>
Expand All @@ -34,6 +33,7 @@
#include <MaterialXGenShader/Nodes/CombineNode.h>
#include <MaterialXGenShader/Nodes/SwitchNode.h>
#include <MaterialXGenShader/Nodes/HwImageNode.h>
#include <MaterialXGenShader/Nodes/HwTexCoordNode.h>
#include <MaterialXGenShader/Nodes/ClosureSourceCodeNode.h>
#include <MaterialXGenShader/Nodes/ClosureCompoundNode.h>
#include <MaterialXGenShader/Nodes/ClosureLayerNode.h>
Expand Down Expand Up @@ -178,8 +178,8 @@ MslShaderGenerator::MslShaderGenerator() :
// <!-- <bitangent> -->
registerImplementation("IM_bitangent_vector3_" + MslShaderGenerator::TARGET, BitangentNodeMsl::create);
// <!-- <texcoord> -->
registerImplementation("IM_texcoord_vector2_" + MslShaderGenerator::TARGET, TexCoordNodeMsl::create);
registerImplementation("IM_texcoord_vector3_" + MslShaderGenerator::TARGET, TexCoordNodeMsl::create);
registerImplementation("IM_texcoord_vector2_" + MslShaderGenerator::TARGET, HwTexCoordNode::create);
registerImplementation("IM_texcoord_vector3_" + MslShaderGenerator::TARGET, HwTexCoordNode::create);
// <!-- <geomcolor> -->
registerImplementation("IM_geomcolor_float_" + MslShaderGenerator::TARGET, GeomColorNodeMsl::create);
registerImplementation("IM_geomcolor_color3_" + MslShaderGenerator::TARGET, GeomColorNodeMsl::create);
Expand Down
2 changes: 1 addition & 1 deletion source/MaterialXGenMsl/MslShaderGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class MX_GENMSL_API MslShaderGenerator : public HwShaderGenerator
ShaderNodeImplPtr getImplementation(const NodeDef& nodedef, GenContext& context) const override;

/// Determine the prefix of vertex data variables.
virtual string getVertexDataPrefix(const VariableBlock& vertexData) const;
string getVertexDataPrefix(const VariableBlock& vertexData) const override;

public:
/// Unique identifier for this generator target
Expand Down
62 changes: 0 additions & 62 deletions source/MaterialXGenMsl/Nodes/TexCoordNodeMsl.cpp

This file was deleted.

26 changes: 0 additions & 26 deletions source/MaterialXGenMsl/Nodes/TexCoordNodeMsl.h

This file was deleted.

3 changes: 3 additions & 0 deletions source/MaterialXGenShader/HwShaderGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,9 @@ class MX_GENSHADER_API HwShaderGenerator : public ShaderGenerator
/// Unbind all light shaders previously bound.
static void unbindLightShaders(GenContext& context);

/// Determine the prefix of vertex data variables.
virtual string getVertexDataPrefix(const VariableBlock& vertexData) const = 0;

/// Types of closure contexts for HW.
enum ClosureContextType
{
Expand Down
83 changes: 83 additions & 0 deletions source/MaterialXGenShader/Nodes/HwTexCoordNode.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
//
// Copyright Contributors to the MaterialX Project
// SPDX-License-Identifier: Apache-2.0
//

#include <MaterialXGenShader/Nodes/HwTexCoordNode.h>
#include <MaterialXGenShader/HwShaderGenerator.h>
#include <MaterialXGenShader/Shader.h>

MATERIALX_NAMESPACE_BEGIN

string HwTexCoordNode::INDEX = "index";

ShaderNodeImplPtr HwTexCoordNode::create()
{
return std::make_shared<HwTexCoordNode>();
}

void HwTexCoordNode::createVariables(const ShaderNode& node, GenContext&, Shader& shader) const
{
const ShaderOutput* output = node.getOutput();
const string index = getIndex(node);

ShaderStage& vs = shader.getStage(Stage::VERTEX);
ShaderStage& ps = shader.getStage(Stage::PIXEL);

addStageInput(HW::VERTEX_INPUTS, output->getType(), HW::T_IN_TEXCOORD + "_" + index, vs, true);
addStageConnector(HW::VERTEX_DATA, output->getType(), HW::T_TEXCOORD + "_" + index, vs, ps, true);
}

void HwTexCoordNode::emitFunctionCall(const ShaderNode& node, GenContext& context, ShaderStage& stage) const
{
const HwShaderGenerator& shadergen = static_cast<const HwShaderGenerator&>(context.getShaderGenerator());

const string index = getIndex(node);
const string variable = HW::T_TEXCOORD + "_" + index;
const ShaderOutput* output = node.getOutput();

DEFINE_SHADER_STAGE(stage, Stage::VERTEX)
{
VariableBlock& vertexData = stage.getOutputBlock(HW::VERTEX_DATA);
const string prefix = shadergen.getVertexDataPrefix(vertexData);
ShaderPort* texcoord = vertexData[variable];
if (!texcoord->isEmitted())
{
shadergen.emitLine(prefix + texcoord->getVariable() + " = " + HW::T_IN_TEXCOORD + "_" + index, stage);
texcoord->setEmitted();
}
}

DEFINE_SHADER_STAGE(stage, Stage::PIXEL)
{
VariableBlock& vertexData = stage.getInputBlock(HW::VERTEX_DATA);
const string prefix = shadergen.getVertexDataPrefix(vertexData);
ShaderPort* texcoord = vertexData[variable];
shadergen.emitLineBegin(stage);
shadergen.emitOutput(output, true, false, context, stage);

// Extract the requested number of components from the texture coordinates (which may be a
// larger datatype than the requested number of texture coordinates, if several texture
// coordinate nodes with different width coexist).
string suffix = EMPTY_STRING;
if (output->getType() == Type::VECTOR2)
{
suffix = ".xy";
}
else if (output->getType() == Type::VECTOR3)
{
suffix = ".xyz";
}

shadergen.emitString(" = " + prefix + texcoord->getVariable() + suffix, stage);
shadergen.emitLineEnd(stage);
}
}

string HwTexCoordNode::getIndex(const ShaderNode& node) const
{
const ShaderInput* input = node.getInput(INDEX);
return input ? input->getValue()->getValueString() : "0";
}

MATERIALX_NAMESPACE_END
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,27 @@
// SPDX-License-Identifier: Apache-2.0
//

#ifndef MATERIALX_TEXCOORDNODEGLSL_H
#define MATERIALX_TEXCOORDNODEGLSL_H
#ifndef MATERIALX_HWTEXCOORDNODE_H
#define MATERIALX_HWTEXCOORDNODE_H

#include <MaterialXGenGlsl/GlslShaderGenerator.h>
#include <MaterialXGenShader/Nodes/SourceCodeNode.h>

MATERIALX_NAMESPACE_BEGIN

/// TexCoord node implementation for GLSL
class MX_GENGLSL_API TexCoordNodeGlsl : public GlslImplementation
/// Generic texture coordinate node for hardware languages
class MX_GENSHADER_API HwTexCoordNode : public ShaderNodeImpl
{
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;

protected:
virtual string getIndex(const ShaderNode& node) const;

static string INDEX;
};

MATERIALX_NAMESPACE_END
Expand Down
Loading

0 comments on commit 9d1cc79

Please sign in to comment.