Design: DrawEngine Color Management #72420

Closed
opened 2019-12-13 13:03:22 +01:00 by Jeroen Bakker · 17 comments
Member

After the overlay engine refactoring landed we are one step closer to do better color management in the 3d viewport. This design task describes the steps that needs to happen and the reasoning behind it.

Current Limitation

  • Colors in the viewport and after rendering are different when using overlay engine. The reason is that color transfer is done as one of the last steps of the first render engine (EEVEE, Workbench). The overlay engine ignores the color space it is compositing into.
  • Colors in the viewport and after rendering are different when using grease pencil. The reason is that color transfer is done as one of the last steps of the first render engine (EEVEE, Workbench). The render engine can set the output buffer already to sRGB or linear REC709. Grease Pencil (the second render engine) converts its input color to match this behavior, but does the blending in the color space of the buffer.

DrawManager

One benefit of the overlay unification project is that the overlays are rendered in a separate GPU texture. 20181213_engine.png 20181213_overlay.png 20181213_combined.png. This was a first step of implementing a better drawing color management pipeline.

This proposal consist of several some rules.

  1. The Draw manager will be responsible for the view transform, pending on the active draw mode and draw engines.
  2. The Draw Manager will be responsible to perform the display transform as a last step in the drawing pipeline.
  3. The compositing between engines must be performed in scene reference space.
  • Image empties and camera background images are currently composited directly in the engine output. That is a hack and has to be removed.

Conceptually the pipeline would look like:
image.png
Note: that the Z Combine could also be any compositing trick. It is controlled by the draw engine. The Z Combine shows when it is being used in the pipeline, not what is being done.
Note: Due to upcoming implementation the view transform will happen after the grease pencil engine

WARNING! as this seems conceptually a good idea, OCIO is limiting this. The best we can do is to apply color management after the grease pencil. But the line renderings will always be drawn in display space. The other option is that the line renderings will also be color managed with the settings that the scene and draw mode requests.

Next Steps

  1. Get input from GPU Viewport, Render & Cycles and Grease Pencil.
After the overlay engine refactoring landed we are one step closer to do better color management in the 3d viewport. This design task describes the steps that needs to happen and the reasoning behind it. **Current Limitation** * Colors in the viewport and after rendering are different when using overlay engine. The reason is that color transfer is done as one of the last steps of the first render engine (EEVEE, Workbench). The overlay engine ignores the color space it is compositing into. * Colors in the viewport and after rendering are different when using grease pencil. The reason is that color transfer is done as one of the last steps of the first render engine (EEVEE, Workbench). The render engine can set the output buffer already to sRGB or linear REC709. Grease Pencil (the second render engine) converts its input color to match this behavior, but does the blending in the color space of the buffer. **DrawManager** One benefit of the overlay unification project is that the overlays are rendered in a separate GPU texture. ![20181213_engine.png](https://archive.blender.org/developer/F8216336/20181213_engine.png) ![20181213_overlay.png](https://archive.blender.org/developer/F8216337/20181213_overlay.png) ![20181213_combined.png](https://archive.blender.org/developer/F8216339/20181213_combined.png). This was a first step of implementing a better drawing color management pipeline. This proposal consist of several some rules. 1. The Draw manager will be responsible for the view transform, pending on the active draw mode and draw engines. 2. The Draw Manager will be responsible to perform the display transform as a last step in the drawing pipeline. 3. The compositing between engines must be performed in scene reference space. - Image empties and camera background images are currently composited directly in the engine output. That is a hack and has to be removed. Conceptually the pipeline would look like: ![image.png](https://archive.blender.org/developer/F8216489/image.png) Note: that the Z Combine could also be any compositing trick. It is controlled by the draw engine. The Z Combine shows when it is being used in the pipeline, not what is being done. Note: Due to upcoming implementation the view transform will happen after the grease pencil engine WARNING! as this seems conceptually a good idea, OCIO is limiting this. The best we can do is to apply color management after the grease pencil. But the line renderings will always be drawn in display space. The other option is that the line renderings will also be color managed with the settings that the scene and draw mode requests. **Next Steps** 1. Get input from `GPU Viewport`, `Render & Cycles` and `Grease Pencil`.
Jeroen Bakker self-assigned this 2019-12-13 13:03:22 +01:00
Author
Member

Added subscriber: @Jeroen-Bakker

Added subscriber: @Jeroen-Bakker
Jeroen Bakker changed title from [WIP] Design: DrawEngine Colormanagement to [WIP] Design: DrawEngine Color Management 2019-12-13 13:57:31 +01:00
Jeroen Bakker changed title from [WIP] Design: DrawEngine Color Management to Design: DrawEngine Color Management 2019-12-13 14:25:03 +01:00

Added subscriber: @item412

Added subscriber: @item412

Added subscriber: @Pipeliner

Added subscriber: @Pipeliner
Member

Added subscriber: @EAW

Added subscriber: @EAW

Added subscriber: @frameshift

Added subscriber: @frameshift

Great to see this being tackled! One small note:

The compositing between engines must be performed in linear REC709.

I believe you mean the scene linear reference space.

Great to see this being tackled! One small note: > The compositing between engines must be performed in linear REC709. I believe you mean *the scene linear reference space*.

Added subscribers: @fclem, @antoniov

Added subscribers: @fclem, @antoniov

@Jeroen-Bakker Actually @fclem is doing a big refactor of the grease pencil drawing engine and he is already thinking in color management.

@Jeroen-Bakker Actually @fclem is doing a big refactor of the grease pencil drawing engine and he is already thinking in color management.

Side note: I recently found that the sRGB texture format was allowed to be used in framebuffers (but was listed under texture only fomat in GPU module). This texture format if use used correctly should give us linear blending an decoding of srgb textures for free. (note: i do know we already use that for image textures).

Side note: I recently found that the sRGB texture format was allowed to be used in framebuffers (but was listed under texture only fomat in GPU module). This texture format if use used correctly should give us linear blending an decoding of srgb textures for free. (note: i do know we already use that for image textures).

Ok I've managed to do a proof of concept implementation of the sRGB framebuffer handling and it gives a lot of benefits... but changes some things that we may want to take into account.

Here is the paste with the diff: P1213

New (linear color space blending)*
Capture d’écran du 2020-01-14 22-46-44.png
Old (display space color space blending)
Capture d’écran du 2020-01-14 22-47-09.png

*Note: This is technically true only if the display space is sRGB. If not, opengl will still assume it is and do the sRGB - Linear conversions instead of Display Space - Linear.

We can see that the blending of bright color is more noticeable (i.e: the grid) and the darker ones are less prominent than before (i.e.:the lights' ground line. barely noticeable below selected orange lights).
This gives much more pleasant anti-aliasing which was my motivation for this.

The technical bits:

  • We need sRGB texture for viewport and overlay render targets.
  • We need to convert all colors used in overlays to linear colors. Most of them are in draw_common.c but some are still hardcoded (i.e: bone drawing IIRC)
  • We need to ENABLE GL_FRAMEBUFFER_SRGB when we render to these framebuffers. This way opengl does the Linear to sRGB conversion AFTER blending when doing the writes.
  • We need to DISABLE GL_FRAMEBUFFER_SRGB inside DRW_transform_to_display because the display transform is already done by the OCIO shader.
  • We have to convert to sRGB when drawing the viewport area texture since the texture is now sampled and converted to linear space. In my patch I just enabled GL_FRAMEBUFFER_SRGB for this step. As it turns out the default framebuffer render target is sRGB for some reason (this might be implementation dependent so I would not rely on this to be always true).

I tried to always enable GL_FRAMEBUFFER_SRGB (which is supposed to only modify writes to sRGB textures/rendertargets) but now everything in blender's UI need to be in linear space since it is transformed back to sRGB by opengl's fixed pipeline.
You can such missing color correction on the view gizmos in the top right corner of the viewport.

So we can decide to only do the viewport management .

BTW this also mean doing proper color management for the Image editor since it also uses GPUViewport.

I think this is a nice step into a better color managed UI. We could use sRGB for area framebuffer everywhere to hold data in a compressed manner (in GL_SRGB8_A8 format) and use OCIO to do the Linear > display space conversion at blitting time. This way we can make an exception for the viewport by using a floating point format to easily support HDR displays and wide gammuts.

We could also use GL_RGB10_A2format for areas buffers but this means having less alpha precision.

Ok I've managed to do a proof of concept implementation of the sRGB framebuffer handling and it gives a lot of benefits... but changes some things that we may want to take into account. Here is the paste with the diff: [P1213](https://archive.blender.org/developer/P1213.txt) New (linear color space blending)* ![Capture d’écran du 2020-01-14 22-46-44.png](https://archive.blender.org/developer/F8278467/Capture_d_écran_du_2020-01-14_22-46-44.png) Old (display space color space blending) ![Capture d’écran du 2020-01-14 22-47-09.png](https://archive.blender.org/developer/F8278465/Capture_d_écran_du_2020-01-14_22-47-09.png) *Note: This is technically true only if the display space is sRGB. If not, opengl will still assume it is and do the sRGB - Linear conversions instead of Display Space - Linear. We can see that the blending of bright color is more noticeable (i.e: the grid) and the darker ones are less prominent than before (i.e.:the lights' ground line. barely noticeable below selected orange lights). This gives much more pleasant anti-aliasing which was my motivation for this. The technical bits: - We need sRGB texture for viewport and overlay render targets. - We need to convert all colors used in overlays to linear colors. Most of them are in `draw_common.c` but some are still hardcoded (i.e: bone drawing IIRC) - We need to ENABLE `GL_FRAMEBUFFER_SRGB` when we render to these framebuffers. This way opengl does the Linear to sRGB conversion AFTER blending when doing the writes. - We need to DISABLE `GL_FRAMEBUFFER_SRGB` inside `DRW_transform_to_display` because the display transform is already done by the OCIO shader. - We have to convert to sRGB when drawing the viewport area texture since the texture is now sampled and converted to linear space. In my patch I just enabled GL_FRAMEBUFFER_SRGB for this step. As it turns out the default framebuffer render target is sRGB for some reason (this might be implementation dependent so I would not rely on this to be always true). I tried to always enable GL_FRAMEBUFFER_SRGB (which is supposed to only modify writes to sRGB textures/rendertargets) but now everything in blender's UI need to be in linear space since it is transformed back to sRGB by opengl's fixed pipeline. You can such missing color correction on the view gizmos in the top right corner of the viewport. So we can decide to only do the viewport management . BTW this also mean doing proper color management for the Image editor since it also uses GPUViewport. I think this is a nice step into a better color managed UI. We could use sRGB for area framebuffer everywhere to hold data in a compressed manner (in `GL_SRGB8_A8` format) and use OCIO to do the Linear > display space conversion at blitting time. This way we can make an exception for the viewport by using a floating point format to easily support HDR displays and wide gammuts. We could also use `GL_RGB10_A2`format for areas buffers but this means having less alpha precision.

Added subscriber: @troy_s

Added subscriber: @troy_s

After talking with @troy_s I've come to realize that the terminology is a bit messed up here.

When I was referring to sRGB textures and framebuffers, I was just referring to the transfer function that does not alter the primaries and just remap the input for better perceptual storage. The input color would still be linear.

Also when we say we will render overlays in display space, we mean Linear Display Space.

After talking with @troy_s I've come to realize that the terminology is a bit messed up here. When I was referring to sRGB textures and framebuffers, I was just referring to the transfer function that does not alter the primaries and just remap the input for better perceptual storage. The input color would still be linear. Also when we say we will render overlays in display space, we mean Linear Display Space.
Member

It is difficult to read white text over a light grey alpha background like Firefox default
image.png

so I remade it over a solid black background in case anyone else was having the same difficulty.

Pipeline_as_Nodes_over_Black.png

It is difficult to read white text over a light grey alpha background like Firefox default ![image.png](https://archive.blender.org/developer/F8216489/image.png) so I remade it over a solid black background in case anyone else was having the same difficulty. ![Pipeline_as_Nodes_over_Black.png](https://archive.blender.org/developer/F8280604/Pipeline_as_Nodes_over_Black.png)

I've included the relevant colourimetric transforms required in the chain, given three two different layers of transparency in the viewport. Hope someone finds this informative.

Blender Pixel Merge Overview.png

I've included the relevant colourimetric transforms required in the chain, given three two different layers of transparency in the viewport. Hope someone finds this informative. ![Blender Pixel Merge Overview.png](https://archive.blender.org/developer/F8280670/Blender_Pixel_Merge_Overview.png)

Added subscriber: @BSannholm

Added subscriber: @BSannholm
Author
Member

Changed status from 'Confirmed' to: 'Resolved'

Changed status from 'Confirmed' to: 'Resolved'

Added subscriber: @pauanyu_blender

Added subscriber: @pauanyu_blender
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
10 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#72420
No description provided.