MDL Volume

Issue #1125 resolved
Alessandro Padovani created an issue

Again credits go to Midnight for getting into the mdl code, I'd never be able to do this without his insights. I had to fix the setup in #1075 here and there, but the log idea is good. Converting into log we also get the same odd behavior when a color channel goes to 0, because log(0) doesn't exist and it's returned as zero both in daz and blender. This is the "iray volume bug" we never were able to deal with.

Below there's the setup and the equations. The volume custom group doesn't change. This works both for uber and pbrskin.

# daz volume
if thin walled == on
    there's no volume
if transmitted measurement distance == 0 or transmitted color == black/white
    there's no absorption
if scattering measurement distance == 0 or sss color == black/white or sss amount == 0
    there's no scatter
if there's no absorption and there's no scatter
    there's no volume

absorption color = transmitted color
absorption density = 100 / transmitted measurement distance

if sss mode == mono
    scatter color = sss amount
# chromatic works fine for color components from .001 to .999
# log(0) doesn't exist and we get log(0) = 0
# log(1) is approximated with log(.999)
if sss mode == chromatic
    scatter color = daz_color_log(sss color)
scatter density = 100 / scattering measurement distance
scatter anisotropy = sss direction

Below there's the DAZ Color Log group. We could also do it with python, in this case we have to be sure that python does log(0) = 0, because this is what iray does for the "iray volume bug". Please note that it is also necessary to clamp the color channels from 0 to .999 to mimic iray.

Finally below there's a comparison with iray, I also include the original setup by Midnight in #1075 to show the fix.

Comments (9)

  1. Thomas Larsson repo owner

    Implemented in last commit. I use the node group approach because it is simpler if there are textures involved. The setup is much cleaner now. In particular, before the sss color was inverted in chromatic mode, but that seems to be gone now.

    I didn’t find a min-max setting for the math nodes, so instead I use the wrap settings which seems to do the same thing. If the setting has change name we will have a problem in older Blenders, but I didn’t have time to check that right now.

  2. Alessandro Padovani reporter

    Commit 588d884 works fine.

    Wrap is not exactly the same, though in this case should do. The clamp node is add > converter > clamp.

    edit. Nope, wrap is not the same. Consider when value = 1, wrap will do .001 while clamp will do .999. Please fix.

    edit. The daz color log is not available in “make shader groups“.

  3. Alessandro Padovani reporter

    Commit 0ece8be doesn’t work.

    I get an error when I try to import the test scene volume.duf.

    And below it’s how the color log comes from “make shader groups“

    edit. note. As a side note in daz studio it is not possible to use a texture for the sss color, not in uber nor in pbrskin, so we may go with python instead. But using the color log is perhaps more friendly if the user wants to edit the sss color.

    edit. Or below there’s a possible optimization of the color log using some vector math, please note that the group input and output are colors. We can use minimum instead of clamp because in daz studio it is not possible to insert negative values for the sss color. The original color log above is more “readable” though.

  4. Thomas Larsson repo owner

    Ouch. Everything worked until I chose to explicitly set the clamp type. I must have skipped the final test. After the import failed, Blender’s data contained a corrupt node group that was added later.

    I didn’t notice that the SSS color couldn’t have a texture. It is probably more efficient to transform the color at load time then.

  5. Alessandro Padovani reporter

    Commit fd56374 works fine.

    Feel free to use python or the optimization if you wish. Personally I'd keep the color log if the user wants to change the sss color easily, but it's minor.

  6. Log in to comment