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

Import MaterialX for procedural materials #714

Open
fire opened this issue Apr 15, 2020 · 12 comments
Open

Import MaterialX for procedural materials #714

fire opened this issue Apr 15, 2020 · 12 comments

Comments

@fire
Copy link
Member

fire commented Apr 15, 2020

Describe the project you are working on:

Not for my project.

Describe the problem or limitation you are having in your project:

@StraToN asked if there were plans to support Material Definition Language at some point for importing shaders (https://docs.substance3d.com/sddoc/mdl-material-definition-language-145653991.html)

MDL (Nvidia), Arnold(Autodesk), Open Shader Language(Sony?) and Principled BSDF (Blender Foundation) make bad candidates for use as a material library. MDL is not vendor neutral. Arnold is proprietary. OSL is not an interactive format. Principled BSDF is not exportable outside of Blender.

MaterialX avoids those problems. https://www.materialx.org/Specification.html

Instead of using texture sheets, we can trade runtime performance for procedural material definitions. The procedural materials can also be baked.

Existing proprietary tooling can be used for material artists to create a catalog of opensource materials. https://share.substance3d.com/libraries/6111

Blender can be convinced to make a MaterialX exporter.

Describe the feature / enhancement and how it helps to overcome the problem or limitation:
Write a MaterialX to glsl rendering importer.

Notes: https://github.com/materialx/MaterialX/blob/master/documents/DeveloperGuide/ShaderGeneration.md

Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:

  1. Import the MaterialX shader generator
  2. Investigate the shadergen to glsl code.
  3. Convert shadergen to Godot Shader
  4. Associate dependent resources
  5. Output Godot Engine shader as an imported shader or texture (procedurally baked) or baked at runtime in a loading stage

This is a picture of a green base color in Substance Designer opened in the MaterialX viewer.

Screen Shot 2020-04-15 at 12 06 04 PM

This is a picture of Godot icon image as a resource in Substance Designer opened in the MaterialX viewer.

Screen Shot 2020-04-15 at 12 24 56 PM

If this enhancement will not be used often, can it be worked around with a few lines of script?:

Generating shader graphs is non-trivial. Both ux and rendering materials require work.

Is there a reason why this should be core and not an add-on in the asset library?:

I think this can be a GDNative addon in theory. MaterialX is a native code library. Wanted to post the proposal here for review.

Other

I am not working on Import MaterialX for procedural materials, feel free to take on the task.

@fire
Copy link
Member Author

fire commented Mar 10, 2022

Started work on this https://github.com/fire/MaterialX/tree/godot-gltf.

The design is to turn MaterialX into StandardMaterial3D.

What works:

  • linking
  • xml parsing

What doesn't work:

  • using materialx default nodes
  • baking to texture

@Calinou
Copy link
Member

Calinou commented Mar 10, 2022

This is not strictly related, but what's your opinion on the USD material format? Many PBR material websites such as AmbientCG now provide ZIP archives with USDA and USDC files inside (example).

@fire
Copy link
Member Author

fire commented Mar 10, 2022

@Calinou We can support USD this through our Blender integration pull request.

  1. Add Blend Import godot#54886
  2. https://github.com/V-Sekai/godot-usd

I do not think it's a good use of time / effort to implement a skeleton animation level capable USD gdextension plugin in the near future. The addon will get you most of the way to "USD" import.

@Calinou
Copy link
Member

Calinou commented Mar 10, 2022

I do not think it's a good use of time / effort to implement a skeleton animation level capable USD gdextension plugin in the near future. The addon will get you most of the way to "USD" import.

I think we could have standalone USD material importing, even if we don't implement the full USD specification. It makes setting up PBR materials much faster, and could possibly obsolete #2316 (although converting textures to ORM is still more efficient).

That said, this can likely be implemented by a GDScript add-on already (using a custom importer).

@fire
Copy link
Member Author

fire commented Mar 10, 2022

@fire
Copy link
Member Author

fire commented Mar 10, 2022

To be clear, USD material support is in MaterialX and I've requested GLTF support too.

image

https://github.com/fire/MaterialX/tree/main/resources/Materials/Examples/UsdPreviewSurface

@NicTanghe
Copy link

In order for godot to become the "metaverse" browser it is supposed to become, it needs to support materialx.

@fire
Copy link
Member Author

fire commented Sep 18, 2023

There’s missing vulkan support, but I can try looking.

@expenses
Copy link

I've been working on a MaterialX to VisualShader converter recently at https://github.com/expenses/godot-materialx/. Progress has been going smoothly and it can handle some pretty complex materials fairly well.

20230927_14h55m24s_grim

I have a couple of questions for people more knowledgeable about Godot's shading system than I am:

@ywmaa
Copy link

ywmaa commented Sep 27, 2023

Now that's a great work,

How well supported and stable are VisualShaders compared to the shading language? Are things moving more towards the node-based system or away from it?

Not sure, but I don't think visual shaders are going any way soon, personally I use them a lot, also at core they just translate to Godot Shading Language, and from what I have seen, the shader community cares about the Visual Shaders and even makes an addons for it : https://godotengine.org/asset-library/asset/1745
also if you look at the godot shaders website : https://godotshaders.com/ you will find a mix of both, some use visual shaders, and some use shader language, but I guess the domninant is shader language.

I think you should keep converting to Visual shaders, and any one who wants to use shader language can convert easily using Godot built-in converter.

for the rest, sorry my shader knowledge is weak to know the answers ;p

@Calinou
Copy link
Member

Calinou commented Sep 27, 2023

What kind of support does Godot have for transmissive surfaces (KhronosGroup/glTF@main/extensions/2.0/Khronos/KHR_materials_transmission)? Is this something that can be added to VisualShaders without shading lang/system changes?

BaseMaterial3D has backlighting properties, which can be replicated in a custom shader by setting BACKLIGHT in fragment(): https://github.com/godotengine/godot/blob/ec62b8a3ee1d731387a440b4d2abb7961aa28322/scene/resources/material.cpp#L1459-L1467

Subsurface scattering also has a transmittance property you can enable. This is more realistic but slower to render.

@fire
Copy link
Member Author

fire commented Dec 4, 2023

https://github.com/expenses/usd-mtx-scripts/blob/main/mtlx-to-godot.py has an implementation of materialx to visual shaders as a proof of concept.

https://github.com/blender/blender/tree/universal-scene-description need to ask Blender to support conversion of Blender material to usd material as a python function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants