Friday, June 24, 2022

TONE MAPPING

This post is requested by Midnight Arrow at bitbucket to explain tone mapping in relation to material conversion. Below there's some reference.

http://www.digitaldog.net/

https://docs.omniverse.nvidia.com/app_create/prod_materials-and-rendering/render-settings_post-processing.html

https://docs.blender.org/manual/en/latest/render/color_management.html

https://bitbucket.org/Diffeomorphic/import_daz/issues/22/basic-tone-mapping


One feature of the diffeomorphic importer is that it converts materials from iray to cycles and eevee. This means that you can reasonably expect that your blender materials will be similar to daz studio. Then lights and cameras are converted as well, together with the notorious ghost lights. So your daz scenes will mosttly retain in blender the same look they have in daz studio.

What is not converted is tone mapping. Because there's no easy way to do it, and also because tone mapping is application specific and usually the tone mapping features are decided at render time depending on the project.

Q1. So what it is tone mapping and how does it affect materials and rendering ?

A1. Well tone mapping is how the rendered image is mapped on the output device. That is, a rendered image is defined in a linear color space that can store all the possible physics colors. Then your monitor can't reproduce all those colors so the rendered image is "shrinked" to fit the monitor palette. Technically this is called a linear to srgb transfer function that's what tone mapping does.


Below there's an example of tone mapping in daz studio with the default settings. We can see that the sphere and the background hdri are partially overexposed. This means that the tone mapping in iray doesn't map those colors in the output space of your monitor and they're all white.

You can find the daz test scene in the bitbucked link above. This scene needs the standard genesis package to be installed, plus it uses the standard srgb reference at digital dog, where you can also find lots of good articles.



Below there's the same scene imported via diffeomorphic and rendered in cycles. Here we use the default filmic view transform that's the blender tone mapping. We can see that the filmic view maps more colors to the monitor and the image is less overexposed.



We can get in blender a tone mapping similar to the iray default by using the standard view instead of the filmic view, with a medium low contrast look. Below there's the scene and the settings. We can see that now the colors and lights are more similar to iray.



Q2. Then why diffeomorphic doesn't force the standard view to mimic iray ?

A2. Because the iray tone mapping is not "fixed", it has many parameters that the user can fiddle with depending on the final look he wishes to get. And the standard view only mimics the default iray parameters that will mostly change. Unfortunately there's no easy way to convert the iray tone mapping parameters into the blender tone mapping parameters.


edit. note. As noted by William Hurst at bitbucket, tone mapping is usually done in post production. Both in daz studio and blender to avoid tone mapping it is possible to render to exr, that's hdri images without tone mapping. Then the tone mapping can be done in the post production application, as gimp or the blender compositor for example, or any application that can handle hdri images.

Saturday, June 18, 2022

Converting Morphs to Shapekeys and Morph Presets

A morph in DAZ Studio is either a driven pose or a shapekey, or a combination of both. Driven poses are application-specific, so if you want to export morphs to a game engine you need to convert the driven poses to shapekeys first. This is done with the Convert Morph To Shapekey button in the Advanced Panel > Morphs panel. However, if your character has many morphs, it takes a very long time to convert them all. Let us estimate how long.

Each facial morph typically affects all faces bones, so the time needed to evaluate the final location of a face bone is proportional to the number of loaded morphs. Hence the time needed to evaluate a single morph grows linearly with the number of loaded morphs, and the time needed to evaluate all morphs grows quadratically. To reduce the conversion time, we can divide the morphs into manageable batches, which are loaded, converted and saved in temporary files. The conversion time will then be proportional to the total number of morphs times the batch size, which is much smaller if we keep the batch size down. When all files have been written, they can be loaded with the Import Custom Morphs tool and exported to the game engine.

The shapekeys are stored in morph preset files, which should be readable by DAZ Studio. Unfortunately, I have not yet managed to load the presets in DAZ Studio, but the files can be read by the Import Custom Morphs tool which is what we need for this application.

The tools that we are going to use are located in the Advanced Setup > Morphs Panel.
Load some morphs, e.g. the expressions. Press Convert Morphs To Shapekeys are select the morphs that you want to convert.
Here is the original angry morphs, using the driven face bones.
And here is the converted shapekey.
Morph presets are save as individual files, one for each shapekey, in the directory specified below the Save Morph Preset button.
In the popup dialog, we specify which shapekeys we want to save a morph presets. We can also change the directory, but here there is no folder button that opens a file selector.
The duf files are saved in the specified directory.
Once all batches have been converted and saved as morph presets, we reload all the shapekeys with the Import Custom Morphs button. Since we are going to export the shapekeys to a game engine afterwards, using rig property drivers is unnecessary.

Friday, June 3, 2022

Combo Materials

DAZ characters have many materials for the skin: face, torso, arms, legs, lips, nails etc. If we want to edit the materials once they have been imported into Blender we hence have to make the same changes in many places, which is inconvenient and error-prone. Until now, there have been two tools that facilitate editing multiple materials: the material editor and UDIM materials. However, both approaches have significant drawbacks.

The material editor has a clumsy interface, and is limited to changing existing parameters. It cannot change the topology of the node trees, e.g. by adding or removing nodes or editing links.

UDIM materials renames textures and saves them locally, and you must make sure that the UVs lie in the right tile (wrong for G81F arms and legs). Moreover, there is a problem with the bump distance, which depends on the pixel density and the mesh area covered by the texture in Iray. Hence the bump distance in Blender is different for the various skin materials. To keep the correct values, UDIM materials with different bump values must remain different, which defeats the purpose of editing all of them at once.

Some time ago Aszrael suggested a better approach: replace most of the node tree with a single node group, and only keep the textures. This node group is called a combo group and the materials that use it combo materials. We can then edit the combo group in a single place, and all combo materials are changed consistently.

To create a combo material, we use the Make Combo Material button at the bottom of the Material section. The active material is used as a blueprint for the combo group, so it is important that one of the skin materials is active.
The popup dialog lets us select the combo materials. By default the skin, lips and nails materials are selected. The active material is displayed at the bottom of the dialog.
Here is the original torso node tree.
And here is the node tree after most of the node tree has been replaced by the combo group. Apart from the output node, only the texture nodes remain, since they differ between the combo materials. The combo group is the same. Note that the combo group has a Bump:Distance input. This is the bump distance which differs between materials depending on the covered mesh area.
Here is the inside of the combo group. The input sockets are named after the nodes and sockets they are connected to, ignoring any math or mix-rgb nodes inbetween. The output sockets, called Cycles, Eevee, Volume and Displacement, are connected to the corresponding sockets of the output node.
Shell nodes are not included in the combo group. The reason is that a shell typically only affect some of the skin materials (usually the torso) and not the others.
Textures and texture-like nodes are left outside the combo group. Here we have a node group that corresponds to a layered image in DAZ Studio. In the other skin materials this node is a standard image texture node.
After converting to combo materials, the layered image node group stays outside the combo group.
It sometimes happens that some skin materials have extra nodes. E.g., the face and lips materials can have node groups that correspond to the diffuse overlay or makeup channels in DAZ Studio. In that case it is important to select the right active material to start from.
Here we have a character with eye makeup and glossy lipstick, and the result if we make combo materials starting from the torso, face and lips materials, respectively. The torso material doesn't have the overlay group, so the makeup is ignored altogether. The face material keeps the eye makeup, but the lips material doesn't have a lipstick texture so the color is replaced by black. Also the lips are glossier (have less roughness) than the rest of the skin. So when we start from the face, the lips lose gloss, and when we start from the lips, the rest of the skin becomes too glossy.
The solution is to make the combo materials with the face as the active material, and exclude the lips material from the conversion. The reason why the overlay group does not affect the other materials is that missing textures are replaced by pure black, cf. the lip color above. In the torso material, the Fac input of the diffuse overlay node is black i.e. zero, so the overlay node has no influence.

Combo materials are easier to use and more powerful than the old material editor. The latter is therefore deprecated and will probably be removed in the future, perhaps by the eventual release of version 1.6.2. The only drawback with making combo materials is that they are destructive; once converted to combo materials there is no going back. It can therefore be a good idea to backup the original materials, e.g. with the Make Palette tool.