/docs/configurations/allocation_vars.rst

http://github.com/imageworks/OpenColorIO · ReStructuredText · 123 lines · 93 code · 30 blank · 0 comment · 0 complexity · 6f18b266c0f982e7b6b987d43d7f9e56 MD5 · raw file

  1. ..
  2. SPDX-License-Identifier: CC-BY-4.0
  3. Copyright Contributors to the OpenColorIO Project.
  4. .. _allocationvars:
  5. How to Configure ColorSpace Allocation
  6. ======================================
  7. The allocation / allocation vars are utilized using during GPU 3dlut / shader
  8. text generation. (Processor::getGpuShaderText, Processor::getGpuLut3D).
  9. If, in the course of GPU processing, a 3D lut is required, the "allocation /
  10. allocation vars" direct how OCIO should sample the colorspace, with the intent
  11. being to maintain maximum fidelity and minimize clamping.
  12. Currently support allocations / variables:
  13. ALLOCATION_UNIFORM::
  14. 2 vars: [min, max]
  15. ALLOCATION_LG2::
  16. 2 vars: [lg2min, lg2max]
  17. 3 vars: [lg2min, lg2max, linear_offset]
  18. So say you have an srgb image (such as an 8-bit tif), where you know the data
  19. ranges between 0.0 - 1.0 (after converting to float). If you wanted to apply
  20. a 3d lut to this data, there is no danger in sampling that space uniformly and
  21. clamping data outside (0,1). So for this colorspace we would tag it:
  22. .. code-block:: yaml
  23. allocation: uniform
  24. allocationvars: [0.0, 1.0]
  25. These are the defaults, so the tagging could also be skipped.
  26. But what if you were actually first processing the data, where occasionally
  27. small undershoot and overshoot values were encountered? If you wanted OCIO to
  28. preserve this overshoot / undershoot pixel information, you would do so by
  29. modifying the allocation vars.
  30. .. code-block:: yaml
  31. allocation: uniform
  32. allocationvars: [-0.125, 1.125]
  33. This would mean that any image data originally within [-0.125, 1.125] will be
  34. preserved during GPU processing. (Protip: Data outside this range *may*
  35. actually be preserved in some circumstances - such as if a 3d lut is not needed
  36. - but it's not required to be preserved).
  37. So why not leave this at huge values (such as [-1000.0, 1000.0]) all the time?
  38. Well, there's a cost to supporting this larger dynamic range, and that cost is
  39. reduced precision within the 3D luts sample space. So in general you're best
  40. served by using sensible allocations (the smallest you can get away with, but
  41. no smaller).
  42. Now in the case of high-dynamic range color spaces (such as float linear), a
  43. uniform sampling is not sufficient because the max value we need to preserve is
  44. so high.
  45. Say you were using a 32x32x32 3d lookup table (a common size). Middle gray is
  46. at 0.18, and specular values are very much above that. Say the max value we
  47. wanted to preserve in our coding space is 256.0, each 3d lut lattice coordinates
  48. would represent 8.0 units of linear light! That means the vast majority of the
  49. perceptually significant portions of the space wouldn't be sampled at all!
  50. unform allocation from 0-256\:
  51. 0
  52. 8.0
  53. 16.0
  54. ...
  55. 240.0
  56. 256.0
  57. So another allocation is defined, lg2
  58. .. code-block:: yaml
  59. - !<ColorSpace>
  60. name: linear
  61. description: |
  62. Scene-linear, high dynamic range. Used for rendering and compositing.
  63. allocation: lg2
  64. allocationvars: [-8, 8]
  65. In this case, we're saying that the appropriate ways to sample the 3d lut are
  66. logarithmically, from 2^-8 stops to 2^8 stops.
  67. Sample locations:
  68. 2^-8\: 0.0039
  69. 2^-7\: 0.0078
  70. 2^-6\: 0.0156
  71. ...
  72. 2^0\: 1.0
  73. ...
  74. 2^6\: 64.0
  75. 2^7\: 128.0
  76. 2^8\: 256.0
  77. Which gives us a much better perceptual sampling of the space.
  78. The one downside of this approach is that it can't represent 0.0,
  79. which is why we optionally allow a 3d allocation var, a black point
  80. offset. If you need to preserve 0.0 values, and you have a high
  81. dynamic range space, you can specify a small offset.
  82. Example:
  83. .. code-block:: yaml
  84. allocation: lg2
  85. allocationvars: [-8, 8, 0.00390625]
  86. The [-15.0, 6.0] values in spi-vfx come from the fact that all of the
  87. linearizations provided in that profile span the region from 2^-15
  88. stops, to 2^6 stops. One could probably change that black point to a
  89. higher number (such as -8), but if you raised it too much you would
  90. start seeing black values be clipped. Conversely, on the high end
  91. one could raise it a bit but if you raised it too far the precision
  92. would suffer around gray, and if you lowered it further you'd start to
  93. see highlight clipping.