godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.08k stars 69 forks source link

Import MaterialX for procedural materials #714

Open fire opened 4 years ago

fire commented 4 years ago

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 commented 2 years ago

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

The design is to turn MaterialX into StandardMaterial3D.

What works:

What doesn't work:

Calinou commented 2 years ago

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 commented 2 years ago

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

  1. https://github.com/godotengine/godot/pull/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 commented 2 years ago

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 https://github.com/godotengine/godot-proposals/issues/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 commented 2 years ago

To fully implement MaterialX import, I'll need to propose adding GLTF Specular and GLTF Volumetric shaders to Godot Engine.

unknown

Volumetric

References

fire commented 2 years ago

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 commented 10 months ago

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

fire commented 10 months ago

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

expenses commented 10 months ago

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 commented 10 months ago

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 commented 10 months ago

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 commented 7 months ago

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.