Convert "Shader Brick" materials from Daz

Issue #7 closed
Jessub Kim created an issue

Background

In Daz, some materials have a type of “Shader Brick”.

“Shader Brick” materials are shaders that were built using Shader Mixer in Daz.

Currently, the diffeomorphic plugin doesn’t perform any conversion for “Shader Brick” materials.

What is Shader Mixer?

Shader Mixer is a node-based system that is very similar to Blender’s Material Node-system.

There are a few categories:

  • Functions: These nodes perform operations for material output based on input parameters

    • MDL nodes

      • It seems these nodes come from functions in MDL files in C:\Program Files\DAZ 3D\DAZStudio4\shaders\iray\
      • Other ones
    • Geometric nodes

      • these nodes also seem to be MDL specific nodes. I might be wrong on this. But looks generic enough to be hand replicable if not.
    • Mathmatics nodes

      • Quite standard mathmatical operators like Sine, XOR, etc.. should be replicable
  • Root:

    • MDL Surface: This node represents the final material output

Proposal

My proposal is two things:

  • Parse the “shader brick” data from Daz material file and reconstruct the nodes somehow.
  • Modify Cycles render engine code so that it can render MDL materials

The following tasks would be required:

  1. Create a custom Blender build that

    1. allows MDL material as Cycles kernel input
    2. contains custom Blender material nodes to represent the fore-mentioned nodes from Shader Mixer
  2. In Blender’s Daz import script, if the material is “Shader Brick”, hook up the Shader brick nodes with the equivalent Blender nodes from above.

I’ve read that the latest Reality render plugin for Daz also has functionality to convert Iray (to some degree). And the code for it will soon be open source according to this http://preta3d.com/forums/viewtopic.php?f=20&t=1128&start=30

This means that the development could be made easier by referencing the Reality source code.

Who’s going to do it?

I’m happy to take on this work but wanted to communicate with contributors here so that I don’t step on anyone’s toe while trying to push this change into the plugin

Comments (14)

  1. Thomas Larsson repo owner

    This is an interesting proposal, because I don’t know anything about the brick material myself. There have been a few times that people contributed to this add-on, e.g. with support for case-sensitive file systems.. In those cases they cloned the repo and made a pull request when the addition was ready. If you are happy with that arrangement its ok with me.

    You probably want to override the CyclesMaterial and/or CyclesTree classes in cycles.py. The best thing is if you keep the bulk of your code in a separate file (brick.py perhaps) and only make small changes in the rest of the code to hook on.

  2. Alessandro Padovani

    Adding MDL support to cycles would be a revolution because this way it is possible to compile a uber shader node and the iray materials will transfer right out of the box without any need for conversion. I’m still doubtful that this could be done since afaik cycles is OSL based. Unfortunately I have very little free time lately but for sure I’d be glad to contribute with tests as far as I can.

    Thank you so much for this nice idea and proposal.

  3. Alessandro Padovani

    just for information the iray uber base source is irayubermaterial.mdl in C:\Program Files\DAZ 3D\DAZStudio4\shaders\iray\daz_3d

  4. Alessandro Padovani

    One different and probably easier approach to the issue could be to translate the irayubermaterial.mdl into an equivalent irayubermaterial.osl source. This would require someone who knows both the mdl and osl languages. Actually the principled shader is part of the kernel but since there’s a template_osl folder in the blender distribution I wonder if this could fit there. Below the principled source just for information.

    https://github.com/dfelinto/blender/blob/master/intern/cycles/kernel/shaders/node_principled_bsdf.osl

  5. Jessub Kim reporter

    @Alessandro Padovani Thanks for your input. Much appreciated.

    To clarify, my current integration approach is the following:

    • Use the compiler provided by Nvidia’s MDL SDK to generate executable CUDA/CPU bytecode from MDL scripts (such as Iray uber material)
    • Modify the Blender codebase so that Cycles' material evalution code so that it uses the bytecode generated above.

    This requires creating a custom build (fork) of Blender. I created a private github repo atm for this.

    Also, while this fork is going to be 2.82 version, I won’t have time to keep it up to date with future Blender releases. I’m wondering if that’s okay with you and others? (But the fork will be open source so anyone can contribute with maintenance)

    Another thing, the MDL integration will be implemented in 2 phases:

    1. Iray uber MDL material is used without conversion to Blender nodes, when rendered using Blender Cycles
    2. Shader Brick materials are also used directly without conversion to Blender nodes.

    #2 is expected to take months to implement because it involves a number of extra tasks over #1, such as manually inspecting hundreds of Shader brick nodes in Daz3d and matching them with equivalent MDL functions that already exist.

    To better communicate and collaborate ideas, I am documenting my technical design in this page https://www.notion.so/nprlab/MDL-Integration-to-Blender-Cycles-65a8e0523c59410caa8db9dd919980df

    If anyone would like to discuss this integration over chat, you can join my discord server https://discord.gg/PNrkk5P

  6. Alessandro Padovani

    @Jessub Kim That’s why I was proposing to translate the uber shader instead, since it wouldn’t need a blender/cycles fork to be maintained. Also almost every daz asset uses either 3delight shaders or the iray uber shader. Then 3delight shaders can be easily converted to the uber shader inside daz studio. So I feel the uber shader is everything we really need.

    Anyway, whatever decision you make your project will be awesome for iray integration.

  7. Alessandro Padovani

    @Jessub Kim Just another note about cycles. In some articles they say that cycles becomes slower the more features they add. So if adding shader bricks will make cycles much slower you may consider adding the uber shader alone, that’s enough for daz conversions.

  8. Jessub Kim reporter

    @Alessandro Padovani

    From what I heard, OSL support in Cycles is actually not first class. (heard of bugs, incomplete features, etc..) Also, OSL is CPU only. So to me, that rules out OSL translation as a sound option

    Another way is translating MDL to Blender material nodes.

    Again, if no modification is to be made to Blender, ability to replicate MDL functions will be very limited because Blender nodes work differently and also not all MDL functions are implemented in Blender.

    You don’t have to worry about Shader Brick translation slowing down Cycles. Shader Bricks material will be translated to a MDL script first and processed the same way as how Iray uber shader will be interpreted by Cycles.

    I will note that Uber shader integration alone could be sufficient for many users and hold off any work on shader brick integration until there is more indication that this is very much desired.

  9. Alessandro Padovani

    There are news from Jessub Kim on the daz forum. Personally I believe his work is amazing. Once he gets a first working version it should be possible to import any uber shader material exactly as it is in iray, that would be a major enhacement for materials. Though the actual conversion would be needed for amd cards since if I understand correctly the project by Jessub only supports nvidia cards.

    https://www.daz3d.com/forums/discussion/comment/5806421/#Comment_5806421

  10. Log in to comment