MrLixm / AgXc

Fork of Troy.S AgX, a display rendering transform available via OCIO and more
92 stars 8 forks source link

[OCIO] increase compatibility with Redshift. #2

Closed MrLixm closed 1 year ago

MrLixm commented 1 year ago

Update

A thread has been opened on the Redshift forum

https://redshift.maxon.net/topic/44651/ocio-colorspace-discovering-process-is-too-obscure

Original issue

(Info initally provided by Saul Espinoza) When parsing config, Redshift will be looking for the "sRGB EOTF" colorspace to perform some transformations when needed. The discovery process is hardcoded and not very clear yet but seems you need a colorspace named with at least "sRGB" in the name and then a specific transform. (probably does a regex on values or on transform name ?) Saul recommended to try first the true EOTF with

- !<ExponentWithLinearTransform> {gamma: 2.4, offset: 0.055, direction: inverse}

But let's also try the power function to see if its looking for the ExponentTransform or for the "2.4" value.

-!<ExponentTransform> { value: [ 2.2, 2.2, 2.2, 1 ], direction: inverse }
MrLixm commented 1 year ago

Trying to reproduce the error in katana. Even with the proper color space setup[ on the RedshiftRenderSetting I got some errors.

image

Error message related seems to be :

[INFO plugins.Redshift]: Loading OCIO config using .\ocio\config.ocio
[INFO plugins.Redshift]:    OCIO env var defined. Using it instead
[INFO plugins.Redshift]:    Full path: .\ocio\config.ocio
[INFO plugins.Redshift]:    Ok
[INFO plugins.Redshift]: Creating OCIO processors between rendering and view/srgb spaces
[INFO plugins.Redshift]:    Rendering space: Linear sRGB
[INFO plugins.Redshift]:    Display: sRGB
[INFO plugins.Redshift]:    View: AgX Punchy
[WARN plugins.Redshift]:    Failed to find a suitable sRGB color space in config!
[INFO plugins.Redshift]:        Proxies with textures in 'sRGB' color space may not render correctly.
[INFO plugins.Redshift]:        Physical sun/sky, black-body and hair shaders may not render correctly.
[WARN plugins.Redshift]:    Failed to create rendering to sRGB processor
[INFO plugins.Redshift]: Loading OCIO color space transforms for texture sampling
[INFO plugins.Redshift]:    Unable to find a suitable sRGB-linear color space. Common texture linear color space will be: "Linear sRGB"
[INFO plugins.Redshift]: Render command finished. Returning to Katana a non-zero render result.

But not sure it's the error message mentioned by Saul, seems like something else.

MrLixm commented 1 year ago

Manage to reproduce the issue in C4D 2023 :

Steps

First fix

By adding the colorspace mentioned by Saul the error disappears:

But this fix is only for v2 config and I must maintain v1 compatibility

MrLixm commented 1 year ago

How Redshift detects the "sRGB" colorspace : RnD process

test-1

An interesting point is that the built-in RS config doesn't expose a colorspace with this transform. The sRGB colorspace is defined using a BuiltinTransform in a display_colorspace.

So here is what I added to AgXc:

view_transforms:

# needed to validate the config
- !<ViewTransform>
    name: Un-tone-mapped
    description: |
      Convert the scene colorimetry directly to display-referred with no tone-mapping.
      This is often described as a "linear workflow." It is intended only for diagnostic purposes.
    from_scene_reference: !<BuiltinTransform> {style: "UTILITY - ACES-AP0_to_CIE-XYZ-D65_BFD"}

display_colorspaces:

  - !<ColorSpace>
    name: sRGB
    family:
    description: |
      sRGB monitor (piecewise EOTF)
    isdata: false
    categories: [ file-io ]
    encoding: sdr-video
    from_display_reference: !<GroupTransform>
      children:
        - !<BuiltinTransform> {style: "DISPLAY - CIE-XYZ-D65_to_sRGB"}
        - !<RangeTransform> {min_in_value: 0., min_out_value: 0., max_in_value: 1., max_out_value: 1.}

But still not working tried to :

Nothing works, I don't understand how is the redshift config picked.

test-2

Another weird point, I tried the Substance Painter default config, and this one works fine, it's a v1 config where the sRGB colorspace use a simple FileTransform.

So I did tried to just copy their sRGB colorspace into AgXc and now it works!

  - !<ColorSpace>
    name: sRGB
    family: ""
    equalitygroup: ""
    bitdepth: 32f
    description: |
      Standard RGB display color space
    isdata: false
    allocation: uniform
    allocationvars: [0, 1.125]
    to_reference: !<FileTransform> {src: srgb.spi1d, interpolation: linear}

So further test to determine why this is now working (tests in order) :

Minimal working config

Upon testing this is the configs with the most basic setup that doesn't raise errors :

OCIO v1

OCIO: Reference ColorSpaces: LinearSRGB:'mango' SRGB:'pineapple' Raw:'coco'

ocio_profile_version: 1
environment: { }
search_path: LUTs
strictparsing: true

roles:
  color_picking: pineapple
  data: coco
  default: pineapple
  scene_linear: mango

displays:
  sRGB:
  - !<View> {name: Default, colorspace: pineapple}
  - !<View> {name: Disabled, colorspace: coco}

colorspaces:

  - !<ColorSpace>
    name: pineapple
    family: ""
    equalitygroup: ""
    bitdepth: 32f
    description: sRGB
    isdata: false
    allocation: uniform
    allocationvars: [0, 1.125]
    to_reference: !<FileTransform> {src: baba.spi1d, interpolation: linear}

  - !<ColorSpace>
    name: mango
    family: Colorspaces
    equalitygroup: ""
    bitdepth: 32f
    description: Open Domain Linear BT.709 Tristimulus
    isdata: false
    allocation: lg2
    allocationvars: [ -10, 7, 0.0056065625 ]

  - !<ColorSpace>
    name: coco
    family: Colorspaces
    equalitygroup: scalar
    bitdepth: 32f
    description: Passthrough means no transformations. Also know as "raw".
    isdata: true
    allocation: uniform
    allocationvars: [0, 1]

OCIO v2:

ocio_profile_version: 2

search_path:

environment: {}

roles:
  color_picking: scene-linear Rec.709-sRGB
  data: coco
  default: sRGB
  scene_linear: scene-linear Rec.709-sRGB

shared_views:
  - !<View> {name: DefaultCoco, colorspace: coco}

displays:
  sRGB:
    - !<Views> [ DefaultCoco ]

view_transforms:

- !<ViewTransform>
    name: ROCK
    description: skip
    from_scene_reference: !<BuiltinTransform> {style: "UTILITY - ACES-AP0_to_CIE-XYZ-D65_BFD"}

display_colorspaces:

  - !<ColorSpace>
    name: sRGB
    family:
    description: |
      sRGB monitor (piecewise EOTF)
    isdata: false
    categories: [ file-io ]
    encoding: sdr-video
    from_display_reference: !<GroupTransform>
      children:
        - !<BuiltinTransform> {style: "DISPLAY - CIE-XYZ-D65_to_sRGB"}
        - !<RangeTransform> {min_in_value: 0., min_out_value: 0., max_in_value: 1., max_out_value: 1.}

colorspaces:

  - !<ColorSpace>
    name: scene-linear Rec.709-sRGB
    family:
    equalitygroup: ""
    bitdepth: 32f
    description: |
      Scene-linear Rec.709 or sRGB primaries
    isdata: false
    categories: [ file-io, working-space ]
    encoding: scene-linear
    to_scene_reference: !<MatrixTransform> {matrix: [ 0.439632981919, 0.382988698152, 0.177378319929, 0, 0.089776442959, 0.813439428749, 0.096784128292, 0, 0.017541170383, 0.111546553302, 0.870912276314, 0, 0, 0, 0, 1 ]}

  - !<ColorSpace>
    name: coco
    family:
    equalitygroup: ""
    bitdepth: 32f
    description: |
      Raw (no color processing)
    isdata: true
    categories: [ file-io ]
    encoding: data
MrLixm commented 1 year ago

How Redshift detects the "sRGB" colorspace : Results

Redshift need 3 colorspaces to work : "LinearSRGB", "SRGB", "Raw"

pbrt4bounty commented 1 year ago

Try you to make a look into the shipped OCIO files for Blender addon to see how a custom config is adapted to use in RS.

MrLixm commented 1 year ago

Nice tip thanks ! Seems to be using the !<FileTransform> {src: srgb.spi1d, interpolation: linear} as in the substance config for the sRGB colorspace. So that make it clear why this transform is being used to identify the sRGB colorspace, because the Blender config has it.