Skip to content

Commit

Permalink
Patch updates for 1.38.8. Add xref to Khronos branch.
Browse files Browse the repository at this point in the history
  • Loading branch information
kwokcb committed Aug 21, 2023
1 parent f99f0f6 commit 8318f21
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 12 deletions.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: kwokcb
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,25 @@ The supported targets are:

Any future specification changes will go into MaterialX core as noted by issues logged [here](https://github.com/AcademySoftwareFoundation/MaterialX/issues)

A [Khronos branch](https://github.com/KhronosGroup/MaterialX/tree/gltf_mtlx_interop) using this library is available in a branch. This
currently includes integration in the MaterialXViewer and
MaterialX GraphEditor. Note that no pipeline tools are integrated there (such as baking) hence export expects the target nodegraph denoted in the next section.

<img src="docs/glTF_import_graphEditor.png" width=80%></img>
<br>
<img src="docs/gltf_import-graphEditor2.png" width=80%></img>
<br>
<sub>Figure: Snapshot of some sample assets imported into the MaterialX GraphEditor</sub>

Some of the documentation for this site will be migrating to the [MaterialX Learning Site](https://kwokcb.github.io/MaterialX_Learn/) (As of August, 2023).
**Stay Tuned**

## 2. Target MaterialX Representation

There is a specific target MaterialX node graph configuration which is the target for distillation / export as well as remixing / import.
There is a specific target MaterialX node graph configuration which is the target for distillation / export as well as remixing / import. These nodegraphs can be created in various editors including Maya, Houdini, etc and USD HDStorm integrations in general as long as the appropriate MaterialX library version is used.

<img src="docs/gltf_target_graph.png" width=80%></img>
<br><sub>Figure: Layout of "target" nodegraphs. Note that 0 or more upstream pattern graphs are supported for inputs to the root PBR shader</sub>

The definitions for these nodes can be found as part of the [core MaterialX library definitions](https://github.com/kwokcb/MaterialX/blob/main/libraries/bxdf/gltf_pbr.mtlx)

Expand Down Expand Up @@ -191,7 +202,7 @@ graph LR;
style IMPL_gltf_pbr_surfaceshader_alpha_cutoff fill:#0bb, color:#111
```

See [here](https://kwokcb.github.io/MaterialX_Learn/documents/definitions/gltf_pbr.html) for a description of the node.

<!-- <img src="./docs/gltf_pbr_graph.png" width=80%></img> -->

Expand Down
18 changes: 18 additions & 0 deletions build_no_update.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@echo off

mkdir build
cd build
cmake -DGLTF_MATERIALX_TEST_RENDER=ON -G "Visual Studio 16 2019" -A "x64" -DCMAKE_BUILD_TYPE=RelWithDebInfo ..
cmake --build . --target install --config RelWithDebInfo
ctest -VV --output-on-failure --build-config RelWithDebInfo -j1 -R glTF

REM cd ..
REM build\installed\bin\glTF2Mtlx --gltf ./resources/ABeautifulGame/glTF/ABeautifulGame.gltf --assignments
REM echo "-- Converstion to MTLTX from GLTF --" > conversion_log.txt
REM cat ./resources/ABeautifulGame/glTF/ABeautifulGame.gltf.mtlx >> conversion_log.txt

REM build\installed\bin\glTF2Mtlx --mtlx ./resources/ABeautifulGame/glTF/ABeautifulGame.gltf.mtlx
REM echo "-- Converstion to GLTF from MTLX --" >> conversion_log.txt
REM cat ./resources/ABeautifulGame/glTF/ABeautifulGame.gltf.mtlx._converted.gltf >> conversion_log.txt


Binary file added docs/glTF_import_graphEditor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/gltf_import-graphEditor2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 9 additions & 9 deletions source/MaterialXglTF/GltfMaterialHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <MaterialXCore/Library.h>
#include <MaterialXFormat/XmlIo.h>
#include <MaterialXFormat/Util.h>
#include <MaterialXGenShader/Util.h>
#include <MaterialXGenShader/ShaderTranslator.h>
#include <MaterialXRender/StbImageLoader.h>
#include <MaterialXglTF/GltfMaterialHandler.h>
Expand Down Expand Up @@ -280,9 +281,7 @@ void GltfMaterialHandler::translateShaders(DocumentPtr doc, std::ostream& logger
//
const string TARGET_GLTF = "gltf_pbr";
ShaderTranslatorPtr translator = ShaderTranslator::create();
vector<TypedElementPtr> materialNodes;
std::unordered_set<ElementPtr> shaderOutputs;
findRenderableMaterialNodes(doc, materialNodes, false, shaderOutputs);
vector<TypedElementPtr> materialNodes = findRenderableMaterialNodes(doc);
for (auto elem : materialNodes)
{
NodePtr materialNode = elem->asA<Node>();
Expand Down Expand Up @@ -384,7 +383,8 @@ bool GltfMaterialHandler::save(const FilePath& filePath, std::ostream& logger)
const string gltf_versionString = "2.0";
data->asset.generator = const_cast<char*>((new string("MaterialX " + mtlx_versionString + " to glTF " + gltf_versionString + " generator"))->c_str());;
data->asset.version = const_cast<char*>((new string(gltf_versionString))->c_str());
data->asset.copyright = "Created via glTF translation utilities found here: https://github.com/kwokcb/glTF_MaterialX";
std::string *copyright = new string("Created via glTF translation utilities found here : https://github.com/kwokcb/glTF_MaterialX");
data->asset.copyright = const_cast<char*>((copyright)->c_str());

// Scan for PBR shader nodes
const string PBR_CATEGORY_STRING("gltf_pbr");
Expand Down Expand Up @@ -626,8 +626,8 @@ bool GltfMaterialHandler::save(const FilePath& filePath, std::ostream& logger)
NodePtr ormNode= nullptr;
imageNode = nullptr;
const string extractCategory("extract");
bool fileNameMismatch = false;
bool separateOcclusion = false;
//bool fileNameMismatch = false;
//bool separateOcclusion = false;
for (size_t e = 0; e < 3; e++)
{
const string& inputName = extractInputs[e];
Expand Down Expand Up @@ -800,16 +800,16 @@ bool GltfMaterialHandler::save(const FilePath& filePath, std::ostream& logger)
}

ormFilename.removeExtension();
FilePath filePath = ormFilename.asString() + "_combined.png";
FilePath ormfilePath = ormFilename.asString() + "_combined.png";
bool saved = loader->saveImage(filePath, outputImage);
logger << " --> Write ORM image to disk: " << filePath.asString() << ". SUCCESS: " << std::to_string(saved) << std::endl;

cgltf_texture* texture = &(textureList[imageIndex]);
roughness.metallic_roughness_texture.texture = texture;
initialize_cgtlf_texture(*texture, imageNode->getNamePath(), filePath,
initialize_cgtlf_texture(*texture, imageNode->getNamePath(), ormfilePath,
&(imageList[imageIndex]));
imageIndex++;
logger << " --> Write cgltf image name: " << filePath.asString() << std::endl;
logger << " --> Write cgltf image name: " << ormfilePath.asString() << std::endl;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion source/MaterialXglTF/GltfMaterialHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class MX_GLTF_API MaterialHandler
/// to perform actions such as shader translation and baking.
/// </summary>
/// <param name="doc">Document to modify</param>
virtual void translateShaders(DocumentPtr doc, std::ostream& log) {};
virtual void translateShaders(DocumentPtr /*doc*/, std::ostream& /*log*/) {};

/// <summary>
/// Set document containing MaterialX definitions. This includes core library
Expand Down
3 changes: 3 additions & 0 deletions source/MaterialXglTF/GltfMaterialUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ bool GltfMaterialUtil::mtlx2glTF(MaterialHandlerPtr gltfMTLXLoader,

bool GltfMaterialUtil::haveSingleDocBake(const FilePath& errorFile)
{
#ifndef MTLX_TRANSLATE_SHADER
return false;
#endif
FilePath shaderTranslator(MTLX_TRANSLATE_SHADER);
if (shaderTranslator.isEmpty())
{
Expand Down

0 comments on commit 8318f21

Please sign in to comment.