MaterialX export from Blender shader nodes #112864

Open
opened 2023-09-25 18:45:51 +02:00 by Brecht Van Lommel · 8 comments

As part of Hydra render engine support (#110765 ), we want to be able to render Cycles and EEVEE shaders in Hydra render engines. For this a conversion from Blender shader nodes to MaterialX nodes was implemented in #111765.

This implementation is incomplete, not all nodes are currently supported. This tasks is meant to keep track of the progress. Some nodes may not be possible to export. For this we should add some indicator in the user interface.

Native support for editing MaterialX nodes in Blender is important functionality as well, but not part of the initial implementation.

Tasks

  •  Show which nodes are unsupported when Hydra render engine is selected
  •  Implement Script node (#113341)
  •  Implement White Noise node (#113495)
  • Implement steps, clamp, smooth step inputs for Map Range node (#114635)
  • Integrate as part of USD export for
    • Hydra
    • USD file export

Nodes

Legend

🟢 Implemented
🟡 Partially implemented
🟠 Default value
🔴 Not implemented

Input

Node Status Comment
Ambient Occlusion 🟠 MatX node exists but not implemented internally
Attribute 🟠 TODO: could be partially implemented
Bevel 🟠 This node isn't supported by MaterialX
Camera Data 🟠 Returning socket default value
Color Attribute 🟠 TODO: could be partially implemented
Curves Info 🟠 MatX doesn't have an implementation for this node
Fresnel 🟠 TODO: could be partially implemented
Geometry 🟡 Some outputs aren't supported by MaterialX
Layer Weight 🔴
Light Path 🟠 This node isn't supported by MaterialX. Only default values returned.
Object Info 🟡 Some outputs isn't supported by MaterialX
Particle Info 🔴 No correspondent node in MatX
Point Info 🔴 No correspondent node in MatX
RGB 🟢
Tangent 🔴 MatX doesn't have an implementation for this node
Tеxture Coordinate 🟡 Some outputs aren't supported by MaterialX
UV Map 🟡 """UV"" selection and ""From Instances"" not implemented"
Value 🟢
Volume Info 🔴
Wireframe 🔴 No correspondent node in MatX

Output

Node Status Comment
Material Output 🟡 Only Surface input implemented (Volume and Displacement aren't)
Light Output 🔴
AOV Output 🔴

Color

Node Status Comment
Brightness/Contrast 🟢
Gamma 🟢
Hue/Saturation/Value 🟢
Invert Color 🟢
Light Falloff 🟢 No correspondent node in MatX. Used formula from OSL shader code in Cycles
Mix Color 🟡 TODO: Apply blend type
RGB Curves 🟠 TODO: could be implemented

Converter

Node Status Comment
Blackbody 🟢
Clamp 🟢
Color Ramp 🔴
Combine Color 🟢
Combine XYZ 🟢
Float Curve 🟠 TODO: could be implemented
Map Range 🟢 Smootherstep not supported
Math 🟢
Mix 🟢
RGB to BW 🟢
Separate Color 🟢 MatX doesn't support HSL color model
Separate XYZ 🟢
Vector Math 🟢
Wavelength 🔴

Shader

Node Status Comment
Add Shader 🟢
Diffuse BSDF 🟢
Emission 🟢
Glass BSDF 🟢
Glossy BSDF 🟢
Hair BSDF 🔴 No correspondent node in MatX
Holdout 🔴 No correspondent node in MatX
Mix Shader 🟢
Principled BSDF 🟢
Principled Hair BSDF 🔴 No correspondent node in MatX
Principled Volume 🔴 TODO: could be implemented(anisotropic_vdf)
Refraction BSDF 🟢
Sheen BSDF 🟢
Subsurface Scattering 🟢
Toon BSDF 🔴 No correspondent node in MatX
Translucent BSDF 🟢
Transparent BSDF 🟢 "No correspondent node in MatX. It uses ""surface"" node for this purpose but its output is ""surfaceshader""."
Volume Absorption 🔴 TODO: could be implemented (absorption_vdf)
Volume Scatter 🔴 TODO: could be implemented (anisotropic_vdf)

Texture

Node Status Comment
Brick Texture 🔴
Checker Texture 🟢
Environment Texture 🟡 texcoords should be translated to spherical coordinates
Gabor Texture 🔴
Gradient Texture 🟢
IES Texture 🔴
Image Texture 🟢 TODO: projection doesn't used
Magic Texture 🔴
Noise Texture 🟡 Some inputs and modes not supported by MaterialX. Noise output may yield different results than expected as well.
Point Density 🔴
Sky Texture 🔴
Voronoi Texture 🔴
Wave Texture 🟢
White Noise Texture 🟢

Vector

Node Status Comment
Bump 🟢
Displacement 🟢 Normal input and Space feature don't have an implementation in MatX
Mapping 🟢
Normal 🟢
Normal Map 🟢
Vector Curves 🟡 Returning default value. TODO: could be implemented
Vector Displacement 🔴
Vector Rotate 🟢
Vector Transform 🟢

Other

Node Status Comment
Script 🔴 TODO: can be implemented to pass mtlx files
NodeGroup 🟢
Frame 🟢
Reroute 🟢
As part of Hydra render engine support (#110765 ), we want to be able to render Cycles and EEVEE shaders in Hydra render engines. For this a conversion from Blender shader nodes to MaterialX nodes was implemented in #111765. This implementation is incomplete, not all nodes are currently supported. This tasks is meant to keep track of the progress. Some nodes may not be possible to export. For this we should add some indicator in the user interface. Native support for editing MaterialX nodes in Blender is important functionality as well, but not part of the initial implementation. ## Tasks * [ ] Show which nodes are unsupported when Hydra render engine is selected * [ ] Implement Script node (https://projects.blender.org/blender/blender/pulls/113341) * [x] Implement White Noise node (https://projects.blender.org/blender/blender/pulls/113495) * [x]Implement `steps`, `clamp`, `smooth step` inputs for Map Range node (https://projects.blender.org/blender/blender/pulls/114635) * [x] Integrate as part of USD export for * [x] Hydra * [x] USD file export ## Nodes ### Legend 🟢 Implemented 🟡 Partially implemented 🟠 Default value 🔴 Not implemented ### Input |Node|Status|Comment| |-|-|-| |Ambient Occlusion|🟠|<ambientocclusion> MatX node exists but not implemented internally| |Attribute|🟠|TODO: could be partially implemented| |Bevel|🟠|This node isn't supported by MaterialX| |Camera Data|🟠|Returning socket default value | |Color Attribute|🟠|TODO: could be partially implemented| |Curves Info|🟠|MatX doesn't have an implementation for this node| |Fresnel|🟠|TODO: could be partially implemented| |Geometry|🟡|Some outputs aren't supported by MaterialX| |Layer Weight|🔴|| |Light Path|🟠|This node isn't supported by MaterialX. Only default values returned.| |Object Info|🟡|Some outputs isn't supported by MaterialX| |Particle Info|🔴|No correspondent node in MatX| |Point Info|🔴|No correspondent node in MatX| |RGB|🟢|| |Tangent|🔴|MatX doesn't have an implementation for this node| |Tеxture Coordinate|🟡|Some outputs aren't supported by MaterialX| |UV Map|🟡|"""UV"" selection and ""From Instances"" not implemented"| |Value|🟢|| |Volume Info|🔴|| |Wireframe|🔴|No correspondent node in MatX| ### Output |Node|Status|Comment| |-|-|-| |Material Output|🟡|Only Surface input implemented (Volume and Displacement aren't)| |Light Output|🔴|| |AOV Output|🔴|| ### Color |Node|Status|Comment| |-|-|-| |Brightness/Contrast|🟢|| |Gamma|🟢|| |Hue/Saturation/Value|🟢|| |Invert Color|🟢|| |Light Falloff|🟢|No correspondent node in MatX. Used formula from OSL shader code in Cycles| |Mix Color|🟡|TODO: Apply blend type| |RGB Curves|🟠|TODO: could be implemented| ### Converter |Node|Status|Comment| |-|-|-| |Blackbody|🟢|| |Clamp|🟢|| |Color Ramp|🔴|| |Combine Color|🟢|| |Combine XYZ|🟢|| |Float Curve|🟠|TODO: could be implemented| |Map Range|🟢|Smootherstep not supported| |Math|🟢|| |Mix|🟢|| |RGB to BW|🟢|| |Separate Color|🟢|MatX doesn't support HSL color model| |Separate XYZ|🟢|| |Vector Math|🟢|| |Wavelength|🔴|| ### Shader |Node|Status|Comment| |-|-|-| |Add Shader|🟢|| |Diffuse BSDF|🟢|| |Emission|🟢|| |Glass BSDF|🟢|| |Glossy BSDF|🟢|| |Hair BSDF|🔴|No correspondent node in MatX| |Holdout|🔴|No correspondent node in MatX| |Mix Shader|🟢|| |Principled BSDF|🟢|| |Principled Hair BSDF|🔴|No correspondent node in MatX| |Principled Volume|🔴|TODO: could be implemented(anisotropic_vdf)| |Refraction BSDF|🟢|| |Sheen BSDF|🟢|| |Subsurface Scattering|🟢|| |Toon BSDF|🔴|No correspondent node in MatX| |Translucent BSDF|🟢|| |Transparent BSDF|🟢|"No correspondent node in MatX. It uses ""surface"" node for this purpose but its output is ""surfaceshader""."| |Volume Absorption|🔴|TODO: could be implemented (absorption_vdf)| |Volume Scatter|🔴|TODO: could be implemented (anisotropic_vdf)| ### Texture |Node|Status|Comment| |-|-|-| |Brick Texture|🔴|| |Checker Texture|🟢|| |Environment Texture|🟡|texcoords should be translated to spherical coordinates| |Gabor Texture|🔴|| |Gradient Texture|🟢|| |IES Texture|🔴|| |Image Texture|🟢|TODO: projection doesn't used| |Magic Texture|🔴|| |Noise Texture|🟡|Some inputs and modes not supported by MaterialX. Noise output may yield different results than expected as well. | |Point Density|🔴|| |Sky Texture|🔴|| |Voronoi Texture|🔴|| |Wave Texture|🟢|| |White Noise Texture|🟢|| ### Vector |Node|Status|Comment| |-|-|-| |Bump|🟢|| |Displacement|🟢|Normal input and Space feature don't have an implementation in MatX| |Mapping|🟢|| |Normal|🟢|| |Normal Map|🟢|| |Vector Curves|🟡|Returning default value. TODO: could be implemented| |Vector Displacement|🔴|| |Vector Rotate|🟢|| |Vector Transform|🟢|| ### Other |Node|Status|Comment| |-|-|-| |Script|🔴|TODO: can be implemented to pass mtlx files| |NodeGroup|🟢|| |Frame|🟢|| |Reroute|🟢||
Brecht Van Lommel added the
Module
Render & Cycles
Type
To Do
labels 2023-09-25 18:45:51 +02:00
Contributor

Re:#111765 (comment), I had a go at trying to add a function to the Python API that allows for writing MaterialX materials to disk and came up with this: https://projects.blender.org/blender/blender/compare/main...expenses:export-materialx. It works pretty well for my needs. Further improvements would be to return a proper MaterialX Python structure instead.

Re:https://projects.blender.org/blender/blender/pulls/111765#issuecomment-1029617, I had a go at trying to add a function to the Python API that allows for writing MaterialX materials to disk and came up with this: https://projects.blender.org/blender/blender/compare/main...expenses:export-materialx. It works pretty well for my needs. Further improvements would be to return a proper MaterialX Python structure instead.
Author
Owner

@expenses that seems useful, could be made into a PR. It should not use hydra::cache_or_get_image_file though since that will write image files to a Hydra cache directory, rather than next to the mtlx files. Probably also would want an option not to write any image files at all.

@expenses that seems useful, could be made into a PR. It should not use `hydra::cache_or_get_image_file` though since that will write image files to a Hydra cache directory, rather than next to the mtlx files. Probably also would want an option not to write any image files at all.
Brecht Van Lommel added this to the Render & Cycles project 2023-10-04 21:24:27 +02:00

I reviewed https://projects.blender.org/blender/blender/compare/main...expenses:export-materialx and didn't see the usage of hydra::cache_or_get_image_file, what are the next steps to contribute?

I reviewed https://projects.blender.org/blender/blender/compare/main...expenses:export-materialx and didn't see the usage of `hydra::cache_or_get_image_file`, what are the next steps to contribute?

@expenses do you know if it's possible to write a mtlx without external images if they are using them? That seems a feature enhancement to truncate the nodes that uses images.

@expenses do you know if it's possible to write a mtlx without external images if they are using them? That seems a feature enhancement to truncate the nodes that uses images.

Unless its expected that we will be able to export all current and future Eevee/Cycles nodes, it would be neat if we could get some kind of indicator in Blenders UI as to which nodes are supported and not.

It could be either:
a little icon in the nodes "titlebar" (the colored area at the top of each node)
or
some text indicating support status (like "MaterialX: Supported"/"MaterialX: Partial Support"/"MaterialX: Unsupported") when you hover the node).

Unless its expected that we will be able to export all current and future Eevee/Cycles nodes, it would be neat if we could get some kind of indicator in Blenders UI as to which nodes are supported and not. It could be either: a little icon in the nodes "titlebar" (the colored area at the top of each node) or some text indicating support status (like "MaterialX: Supported"/"MaterialX: Partial Support"/"MaterialX: Unsupported") when you hover the node).
Contributor

@ernest.lee hey, sorry I don't know MaterialX so well. What I've written works for my use cases but I'm not in a position to polish it to a mergeable state, sorry.

@ernest.lee hey, sorry I don't know MaterialX so well. What I've written works for my use cases but I'm not in a position to polish it to a mergeable state, sorry.

Hello,
The noise texture outputs a colored noise at the factro node.

blender/blender-addons#105266

Hello, The noise texture outputs a colored noise at the factro node. blender/blender-addons#105266

It would be great to have some way to support the "time" and "frame" Application Nodes from MaterialX.
(https://github.com/AcademySoftwareFoundation/MaterialX/blob/main/documents/Specification/MaterialX.Specification.md#application-nodes)

My understanding is that currently, people have to type "#frame" into a Value node in Blender to get "frame", and "#frame/60" to get "time". Not sure if that would be a good heuristic to export them in this way, or have special nodes instead.

Currently, I believe what happens is that this graph:
image

results in Blender exporting the MaterialX graph every frame with the new settings, leading to really low frame rates in Hydra viewport.

It would be great to have some way to support the "time" and "frame" Application Nodes from MaterialX. (https://github.com/AcademySoftwareFoundation/MaterialX/blob/main/documents/Specification/MaterialX.Specification.md#application-nodes) My understanding is that currently, people have to type "#frame" into a Value node in Blender to get "frame", and "#frame/60" to get "time". Not sure if that would be a good heuristic to export them in this way, or have special nodes instead. Currently, I believe what happens is that this graph: <img width="1240" alt="image" src="attachments/52515963-6fb5-4eb8-b11f-17ea4931a982"> results in Blender exporting the MaterialX graph _every frame_ with the new settings, leading to really low frame rates in Hydra viewport.
2.4 MiB
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No Assignees
6 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#112864
No description provided.