MAD values of disabled textures in DELTAGEN

Introduction to MAD values

DSPBR material texture's appearance can be adjusted with the so-called MAD (Multiplication and Addition) values, which modify each texel by multiplying it by a fixed scaling and then adding a constant.

Problem statement

The MAD values of disabled textures modified the appearance of materials until DELTAGEN 2022x. This behavior was confusing, because the properties of a disabled feature (in this case the texture) should not be taken into account. For this reason, starting from DELTAGEN 2023x, MAD values of disabled textures are discarded.

This behavior change could lead to visual inconsistencies for models, saved with previous DELTAGEN releases. The following images show the visual difference of the same material applied to a sphere in DELTAGEN 2022x and 2023x.

A pop-up message notifies the user when a model affected by this change is loaded.

 

 

 

Solution

In the above case, the material applied on Sphere has a disabled Sheen texture whose MAD properties are influencing the Sheen color. To achieve visual consistency, the user needs to multiply the Sheen color by the texture Multiplication value and then add the texture Addition value.

Manually changing the color values for different materials is a time-consuming task. A simple Python script can help.

Script

The script should consist of the following steps to modify material properties.

  • Read all materials from the material library.
libs = Materials.getAllMaterialLibraries()
if len(libs) > 0:
  library = libs[0]
  logger.logInfo("MaterialLibrary: " + library.name())
  # Access to all materials as a list of material
  materials = library.materials()
  • Iterate through all materials to obtain the stellar material description. The material description is provided as a JSON string. We can generate a dictionary from a string using Python's JSON package.
for mat in materials:
   stellarMat = mat.stellarMaterial()
   dict = json.loads(stellarMat.getMaterialDescription())
  • Read the current assigned Sheen color, texture Multiplication, and Addition values and perform the multiplication and addition operation on the sheen color, in the correct color space (linear RGB).
offset = getColor(dict["Sheen"]["sheenColor"]["texture"]["colorOffset"])
scale = getColor(dict["Sheen"]["sheenColor"]["texture"]["colorScale"])
color = getColor(dict["Sheen"]["sheenColor"]["color"])

# Transform to linear
offsetRGB = offset.getLinearRGBf()
scaleRGB = scale.getLinearRGBf()
colorRGB = color.getLinearRGBf()

# Apply MAD values
for i in range(0, 3):
   colorRGB[i] = colorRGB[i] * scaleRGB[i] + offsetRGB[i]
  • To update the Sheen color of the material, the calculated value needs to be assigned back to the material, in the correct output color space, which here is sRGB.
# Back to sRGB
color.setLinearRGBf(colorRGB[0], colorRGB[1], colorRGB[2])
colorSRGB = color.getSRGBf()

# Set the transformed color
dict["Sheen"]["sheenColor"]["color"]["spectrum"] = colorSRGB
dict["Sheen"]["sheenColor"]["color"]["encoding"]["CurrentValue"] = "RGB"

# Pass the changed parameters back to the material
updateStellarOutput = stellarMat.updateMaterialDescription(json.dumps(dict))
if not updateStellarOutput.success():
   logger.logError(updateStellarOutput.errorMessage())
else:
   logger.logInfo("Material update done.")

Similarly, we can change the color values for any other property; see for example the Albedo properties in the snippet below. The values for Albedo color, Multiplication, and Addition are as follows:

color = getColor(dict["Base"]["albedo"]["color"])
scale = getColor(dict["Base"]["albedo"]["texture"]["colorScale"])
offset = getColor(dict["Base"]["albedo"]["texture"]["colorOffset"])

The same is also easily done for float parameters, like the roughness:

#Get the inputs
dict = json.loads(stellarMat.getMaterialDescription())
offset = dict["Base"]["roughness"]["texture"]["valueOffset"]
scale = dict["Base"]["roughness"]["texture"]["valueScale"]
value = dict["Base"]["roughness"]["value"]
#Apply MAD values
value = value * scale + offset
#Set the transformed color
dict["Base"]["roughness"]["value"] = value
#Pass the changed parameters back to the material
updateStellarOutput = stellarMat.updateMaterialDescription(json.dumps(dict))
if not updateStellarOutput.success():
   logger.logError(updateStellarOutput.errorMessage())
else:
   logger.logInfo("Material update done.")

 

The complete script is attached below. The script can be directly executed in DELTAGEN 2023x.

The following script handles all the DSPBR types, including AxF.

 

​​​​​​​PYTHON ​​​​​​​SCRIPTING