better color values

Issue #19 resolved
Alessandro Padovani created an issue

tested with daz studio 4.12.0.86, blender 2.82, plugin commit 8285adc

The plugin seems to import color values that don't match with daz studio. We'll see why and how to eventually fix it. Below an example. The (0.8,1,1) iray color is imported as (0.794446,1,1) in cycles. If we open the duf file we can see that the color is even different, that's (0.9035454,1,1). So what's the matter ?

"id" : "diffuse",
"type" : "float_color",
"name" : "Diffuse Color",
"label" : "Base Color",
"value" : [ 0.7529412, 0.7529412, 0.7529412 ],
"current_value" : [ 0.9035454, 1, 1 ],

Well we know that both iray and cycles are pbr engines so they both use linear color values. The difference is how they store linear values. That is, while cycles uses the correct linear function, iray seems to use the gamma 2.2 approximation. Plus the values in the duf files are gamma corrected. Now gamma 2.2 is a very good approximation of the linear function, that's why luckily the difference between iray and cycles is always very low. So the exact equation to get the iray values is below.

cycles color = duf color ** 2.2
0.9035454 ** 2.2 = 0.7999999..

While at this time the plugin uses the linear equation

cycles color = ((duf color + 0.055) / 1.055) ** 2.4
((0.9035454 + 0.055) / 1.055) ** 2.4 = 0.794446

In this case it is also important to limit the math precision since cycles color values get 6 digits. Otherwise we may get mismatching values again. Below an example in the blender python console.

cycles color = round(duf color ** 2.2, 6)
round(0.9035454 ** 2.2, 6) = 0.8

Comments (5)

  1. Alessandro Padovani reporter

    EDIT: It’s my fault. I had a reflectance tint and forgot that it gets multiplied with the base color. That explains the “odd” values below. So everything is ok, apart the srgbToLinear function that needs to be corrected.

    Unfortunately commit 663ec5f doesn't seem to work fine. Below an example, first the duf file then iray then cycles. For some reason (1, 0.8470591, 0.6666669) in the duf file gets converted into (0.788235, 0.694081, 0.392147) in cycles. Now the green component is right but the red and blue components get odd values.

    "id" : "diffuse",
    "type" : "float_color",
    "name" : "Diffuse Color",
    "label" : "Base Color",
    "value" : [ 0.7529412, 0.7529412, 0.7529412 ],
    "current_value" : [ 1, 0.8470591, 0.6666669 ],
    

    Also the srgbToLinear function as defined in commit 663ec5f is wrong. Below the correct function.

    def srgbToLinear(self, srgb):
        lin = []
        for s in srgb:
        #   this is the correct linear function used by cycles
        #   if s < 0.04045:
        #      l = s/12.92
        #   else:
        #      l = ((s+0.055)/1.055)**2.4
        #   this is the gamma 2.2 approximation used by iray
            l = round(s**2.2, 6)
            lin.append(l)
        return Vector(lin)
    

  2. Alessandro Padovani reporter

    NOTE. Negative colors from iray are not supported see #134. Also see #349 point 3 for “color“ vs “float color“. See #1235 for AGX ACES support.

  3. Log in to comment