Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LOOKDEVX-2124 - MaterialX Topo Handler #3445

Merged
merged 3 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/mayaUsd/render/MaterialXGenOgsXml/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ target_sources(${PROJECT_NAME}
GlslOcioNodeImpl.cpp
OgsFragment.cpp
OgsXmlGenerator.cpp
ShaderGenUtil.cpp
Nodes/SurfaceNodeMaya.cpp
Nodes/TexcoordNodeMaya.cpp
PugiXML/pugixml.cpp
Expand All @@ -18,6 +19,7 @@ set(HEADERS
GlslOcioNodeImpl.h
OgsFragment.h
OgsXmlGenerator.h
ShaderGenUtil.h
)

# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -65,6 +67,10 @@ mayaUsd_promoteHeaderList(HEADERS ${HEADERS} SUBDIR render/MaterialXGenOgsXml)
# install
# -----------------------------------------------------------------------------

install(FILES ${HEADERS}
DESTINATION ${CMAKE_INSTALL_PREFIX}/include/${PROJECT_NAME}/render/MaterialXGenOgsXml
)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allows LookdevX to used the shadergen code.


install(FILES ${NODE_DECLARATIONS}
DESTINATION ${CMAKE_INSTALL_PREFIX}/libraries/adsk/maya
)
Expand Down
17 changes: 12 additions & 5 deletions lib/mayaUsd/render/MaterialXGenOgsXml/GlslFragmentGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@ void fixupVertexDataInstance(ShaderStage& stage)

static const std::string primvarParamSource
= "vec([23]) [$](" + d(HW::T_IN_GEOMPROP) + "_[A-Za-z0-9_]+)";

static const std::regex primvarParamRegex(primvarParamSource.c_str());
static const std::regex primvarParamRegex(primvarParamSource.c_str());
static const std::string texcoordParamSource
= "vec([23]) [$](" + d(HW::T_TEXCOORD) + "_[0-9]+)";
static const std::regex texcoordParamRegex(texcoordParamSource.c_str());
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you can see above, we already had code that cleaned up shader stream variable names that were generated for "geompropvalue" nodes. We need to do the same for variable names generated for the "texcoor"nodes used in LookdevX.


// Find keywords: (as text)
//
Expand All @@ -94,16 +96,21 @@ void fixupVertexDataInstance(ShaderStage& stage)
// PIX_IN.(NAME) PIX_IN.st
//

static const std::string vdCleanupSource = "[$]" + d(HW::T_VERTEX_DATA_INSTANCE) + "[.][$]"
static const std::string vdCleanGeoSource = "[$]" + d(HW::T_VERTEX_DATA_INSTANCE) + "[.][$]"
+ d(HW::T_IN_GEOMPROP) + "_([A-Za-z0-9_]+)";
static const std::regex vdCleanGeoRegex(vdCleanGeoSource.c_str());

static const std::regex vdCleanupRegex(vdCleanupSource.c_str());
static const std::string vdCleanTexSource
= "[$]" + d(HW::T_VERTEX_DATA_INSTANCE) + "[.][$](" + d(HW::T_TEXCOORD) + "_[0-9]+)";
static const std::regex vdCleanTexRegex(vdCleanTexSource.c_str());

std::string code = stage.getSourceCode();
code = std::regex_replace(code, paramRegex, "vec3 unused_$1");
code = std::regex_replace(code, vtxRegex, "$$$1( PIX_IN.$$$1 )");
code = std::regex_replace(code, primvarParamRegex, "vec$1 unused_$2");
code = std::regex_replace(code, vdCleanupRegex, "PIX_IN.$1");
code = std::regex_replace(code, texcoordParamRegex, "vec$1 unused_$2");
code = std::regex_replace(code, vdCleanGeoRegex, "PIX_IN.$1");
code = std::regex_replace(code, vdCleanTexRegex, "PIX_IN.$1");

#if MX_COMBINED_VERSION >= 13804
stage.setSourceCode(code);
Expand Down
2 changes: 1 addition & 1 deletion lib/mayaUsd/render/MaterialXGenOgsXml/OgsFragment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ bool OgsFragment::isElementAShader() const

bool OgsFragment::isTransparent() const
{
return _glslShader && _glslShader->hasAttribute(mx::HW::ATTR_TRANSPARENT);
return isTransparentSurface(_element, mx::GlslShaderGenerator::TARGET);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using native MaterialX call.

}

mx::ImageSamplingProperties
Expand Down
4 changes: 3 additions & 1 deletion lib/mayaUsd/render/MaterialXGenOgsXml/OgsFragment.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
/// @file
/// OGS fragment wrapper.

#include <mayaUsd/base/api.h>

#include <MaterialXCore/Document.h>
#include <MaterialXGenShader/Shader.h>
#include <MaterialXRender/ImageHandler.h>
Expand All @@ -16,7 +18,7 @@ namespace MaterialXMaya {
/// and outputs and embedding source code in one or potentially multiple target
/// shading languages (GLSL is the only such language currently supported).
///
class OgsFragment
class MAYAUSD_CORE_PUBLIC OgsFragment
{
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allow these classes to be used in LookdevX.

public:
/// Creates a local GLSL fragment generator
Expand Down
4 changes: 3 additions & 1 deletion lib/mayaUsd/render/MaterialXGenOgsXml/OgsXmlGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@

/// @file
/// OGS XML fragments generator
#include <mayaUsd/base/api.h>

#include <MaterialXGenShader/ShaderGenerator.h>

MATERIALX_NAMESPACE_BEGIN

class OgsXmlGenerator
class MAYAUSD_CORE_PUBLIC OgsXmlGenerator
{
public:
/// Generate OSG XML for the given shader fragments, output to the given stream.
Expand Down
Loading