Commit Graph

37 Commits

Author SHA1 Message Date
Brecht Van Lommel 3cd27374ee Color management: add Filmic view transform to Blender configuration.
* "Filmic" and "False Color" view transforms added (sRGB display device only).
* "Very Low/Low/Base/High/Very High Contrast" looks added.
* Added filtering so that Filmic only shows look names prefixed with "Filmic - ".

Filmic Dynamic Range LUT configuration created by Troy James Sobotka with
special thanks and feedback from Guillermo, Claudio Rocha, Bassam Kurdali,
Eugenio Pignataro, Henri Hebeisen, Jason Clarke, Haarm-Peter Duiker, Thomas
Mansencal, and Timothy Lottes.

Differential Revision: https://developer.blender.org/D2659
2017-05-07 16:41:38 +02:00
Sergey Sharybin ce629c5dd9 Color management: Add utility function to convert byte to float with processor applied 2017-02-07 17:49:54 +01:00
Sergey Sharybin 5d6177111d Color management: Implement threaded byte buffer conversion
The title says it all actually: now we can convert byte buffer
directly, without need of temporary float buffer.
2017-02-07 17:49:54 +01:00
Sergey Sharybin 8cc4f3f52a Implement threaded partial display buffer update
This speeds up update of display buffer when affected area is big enough.

Mainly helpful for cases when doing long fast strokes when painting.
2016-05-06 10:04:29 +02:00
Sergey Sharybin e3e23f7746 ImBuf: Make luminance calculation inlined
Title actually tells it all, it is rather simple function which totally makes
sense to be inlined.

This gives up to 5% of speedup when updating scopes for a large image.

Reviewers: campbellbarton

Differential Revision: https://developer.blender.org/D1310
2016-01-25 14:13:52 +01:00
Campbell Barton b1d758ae6b Cleanup: redundant struct declarations 2015-03-29 03:56:39 +11:00
Antony Riakiotakis dd38dce7f0 Part 2 of D1082 by Troy Sobotka, remove our functions that do luma
calculations and use the OCIO one instead.
2015-03-17 15:20:33 +01:00
Sergey Sharybin 71f689843d Fix deadlock happening when using Save Buffers for render
Summary:
Issue was caused by the same tile being written twice to
the EXR file. This was happening because of partial update
of work-in-progress tiles was merging result to the final
render result in order to make color management pipeline
happy.

We need to avoid such a merges and keep memory usage as
low as possible when Save Buffers is enabled.

Now render pipeline will allocate special display buffer
in render layer which will contain combined pass in the
display space. This keeps memory usage as low as we can
do at this moment.

There's one weak thing which is changing color management
settings during rendering would lead to lossy conversion.
This is because render result's display buffer uses color
space from the time when rendering was invoked.

This is actually what was happening in previous release
already actually so not a big issue.

Reviewers: brecht

Reviewed By: brecht

Differential Revision: https://developer.blender.org/D162
2014-01-01 22:32:47 +06:00
Sergey Sharybin 2249d71e26 Color management: added utility function to apply processor on a pixel
It applies color management on a pixel in a way, based on number of
channels of this pixel.

Simplifies partial update code a bit.
2013-12-18 15:51:09 +06:00
Sergey Sharybin 6e77dfeb1a Color management: get rid of original byte buffer partial update
It was only used by opengl render and in fact it needed just to
set DISPLAY_BUFFER_INVALID flag for the image buffer.

In theory it wouldn't make any change to opengl render speed
(because this change just moved rect_from_float from color
management code to image save code). And could not see any speed
changes on my laptop.
2013-12-18 15:25:46 +06:00
Sergey Sharybin 5a91df3271 Implement GPU-side dither
Summary:
Uses some magic pseudo-random which is actually a
texture coordinate hashing function.

TODOs:
- Dither noise is the same for all the frames.
- It's different from Floyd's dither we've been
  using before.
- Currently CPU and GPU dithering used different
  implementation. Ideally we need to use the same
  dither in CPU.

Reviewers: brecht

Reviewed By: brecht

Differential Revision: http://developer.blender.org/D58
2013-12-13 12:36:45 +06:00
Sergey Sharybin a698709d95 Code cleanup: remove unused color management functions 2013-12-04 15:57:54 +06:00
Sergey Sharybin 6e1fe4ddd9 Implementation of curve mapping in GLSL
The title says it all, now having curve mapping
enabled in color management settings wouldn't
force fallback from GLSL to CPU based color space
conversion.
2013-10-09 15:57:32 +00:00
Campbell Barton 8beb565c59 code cleanup: headers - doxy comments. 2013-09-12 03:02:50 +00:00
Sergey Sharybin cf8cddf07a Film response curves implemented as a looks
This commit implement's OCIO's Looks idea which
is about applying some color correction on the
buffer before it get's affected by a display
transform.

This is mainly used to modify images in an
artistics way.

Currently we've got looks generated from film
response curves for all sorts of cameras.

Patch by both of me and Brecht.
2013-09-09 09:48:26 +00:00
Sergey Sharybin d4b8a6cb85 Code cleanup: use boolean instead of int for colormanagement 2013-09-05 17:13:43 +00:00
Sergey Sharybin 529c6d0eeb Fix #36124: VSE - Input Color option does not work for video files
Byte images and movies will now fully follow input color space.
Before this non-sRGB input colorspace for byte images and movies
behave really doggy (results in preview and final render were
totally different).

To prevent data loss, if byte image is set not stored in sequencer's
space it'll be internally converted to float buffer.

In theory some setups might be rendering a bit different now, but
new behavior is totally expected and someone used non-sRGB input
space for byte images/movies had Convert Float enabled anyway.
2013-09-02 13:54:12 +00:00
Brecht Van Lommel 60ff60dcdc RenderEngine API: add viewport draw utility functions to bind a GLSL fragment
shader for converting colors from linear to display space, based on the scene
color management settings.

if engine.support_display_space_shader(scene): # test graphics card support
	engine.bind_display_space_shader(scene)
	# draw pixels ..
	engine.unbind_display_space_shader()
2013-08-30 23:49:35 +00:00
Sergey Sharybin df74639002 Speedup for rendered viewport for blender internal
Display code was a bottleneck here, so made it so render
result draw follows Image Draw settings.
2013-05-12 19:01:23 +00:00
Sergey Sharybin c1b704a11a Use GLSL display for compositor backdrop and sequencer preview
Now only background images remained to be ported. Plus implement
GLSL for dithering and RGB curves.
2013-04-04 12:20:13 +00:00
Campbell Barton 7bbaf4853a code cleanup: use bools in UI and WM code, quiet some shadow warnings, remove unused function uiEmboss() 2013-04-04 02:05:11 +00:00
Sergey Sharybin 9c49e71216 Bunch of fixes for GLSL display transform
- GLSL shader wasn't aware of alpha predivide option,
  always assuming alpha is straight. Gave wrong results
  when displaying transparent float buffers.

- GLSL display wasn't aware of float buffers with number
  of channels different from 4, crashing when trying to
  display image with different number of channels.

  This required a bit larger changes, namely now it's
  possible to pass format (GL_RGB, GL_RGBAm GL_LUMINANCE)
  to glaDrawPixelsTex, This also implied adding format to
  glaDrawPixelsAuto and modifying all places where this
  functions are called.

  Now GLSL will handle both 3 and 4 channels buffers,
  single channel images are handled by CPU.

- Replaced hack for render result displaying with a bit
  different hack.

  Namely CPU conversion will happen only during render,
  once render is done GLSL would be used for displaying
  render result on a screen.

  This is so because of the way renderer updates parts
  of the image -- it happens without respect to active
  render layer in image user. This is harmless because
  only display buffer is modifying, but this is tricky
  because we don't have original buffer opened during
  rendering.

  One more related fix here was about when rendering
  multiple layers, wrong image would be displaying when
  rendering is done. Added a signal to invalidate
  display buffer once rendering is done (only happens
  when using multiple layers). This solves issue with
  wrong buffer stuck on the display when using regular
  CPU display space transform and if GLSL is available
  it'll make image displayed with a GLSL shader.

- As an additional change, byte buffers now also uses
  GLSL display transform.

  So now only dutehr and RGB curves are stoppers for
  using GLSL for all kind of display transforms.
2013-04-03 15:59:54 +00:00
Sergey Sharybin 752ad1bc37 More usage of GLSL for color managed image drawing
Uses GLSL for drawing image in Image Editor space.

This requires change in image_buffer_rect_update, so
original float buffer is being updated as well. This
is unlikely be something bad, but will keep an eye
on this change.

Also no byte buffer allocation happens there, this
is so because byte buffer used for display only
and in case of GLSL display such allocation and
partial update is just waste of time.

Also switched OpenGL render from using CPU color
space linearization to GLSL color space transform.
Makes OpenGL rendering pretty much faster (but
still slower than in 2.60).

internal changes:

- Added functions to setup GLSL shader for color
  space conversion in colormanagement.c. Currently
  conversion form a colorspace defined by a role to
  linear space is implemented. Easy to extend to
  other cases.

- Added helper functions to glutil.c which does
  smarter image buffer draw (calling all needed OCIO
  stuff, editors now could draw image buffer with a
  single function call -- all the checks are done in
  glutil.c).

- Also added helper function for buffer linearization
  from a given role to glutil.c. Everyone now able to
  linearize buffer with a single call.

  This function will do nothing is GLSL routines fails
  or not supported.

  And one last this: this function uses offscreen
  drawing, could potentially give issues on some
  cards, also will keep an eye on this.
2013-04-02 17:28:37 +00:00
Sergey Sharybin 2dff7c01ad Implement GPU-side display transform for clip editor
Implemented using GLSL API from OpenColorIO library and
some general functions were added to it's c-api:

- OCIO_setupGLSLDraw prepares OpenGL context for GPU-based
  transformation for a giver processor.

  This function compiles and links shader, sets  up it's
  argument. After this transformation would be applied
  on an image displaying as a 2D texture.

  So, glaDrawPixelsTex called after OCIO_setupGLSLDraw will
  do a proper color space transform.

- OCIO_finishGLSLDraw restores OpenGL context after all
  color-managed display is over.

- OCIO_freeOGLState frees allocated state structure used
  for cacheing some GLSL-related stuff.

There're some utility functions in IMB_colormanagent which
are basically proxies to lower level OCIO functions but
which could be used from any place in blender.

Chacheing of movie clip frame on GPU is also removed now,
and either glaDrawPixelsTex or glaDrawPixelsAuto are used
for display now. This is so no code duplication happens
now and no large textures are lurking around in GPU memory.

Known issues:
- Texture buffer and GLSL are no longer checking for
  video card capabilities, possibly could lead to some
  artifacts on crappy drivers/cards.

- Only float buffers are displaying using GLSL, byte
  buffers will still use fallback display method.

  This is to be addressed later.

- If RGB curves are used as a part of display transform,
  GLSL display will also be disabled. This is also thing
  to be solved later.

Additional changes:

- glaDrawPixelsTexScaled will now use RGBA16F as an
  internal format of storing textures when it's used
  to draw float buffer. This is needed so LUT are
  applied without precision loss.
2013-03-29 16:02:27 +00:00
Sergey Sharybin b19155e76c Fix #34672: Image sampling line didn't use color management for byte buffers
This makes it so sample line (for all image editor, sequencer and compositor)
displaying managed color for byte buffers as well. It was simply not implemented
before.
2013-03-18 11:34:05 +00:00
Sergey Sharybin 7fcc1ac48b Implemented delayed partial rect update for image buffers
Used by image painting mode, so every brush step would mark area
if affected on, but actual color space conversion would happen
later when actually displaying image.

Implemented as a rcti stored in ImBuf which is getting merged with
partial rect passed to IMB_partial_display_buffer_update_delayed.

This makes painting as fast as it currently possible and finally
solves #33935: Texture painting slow down with mouse, but not with tablet
2013-02-11 13:24:35 +00:00
Sergey Sharybin 08cea96ab0 Alpha premul pipeline cleanup
This assumptions are now made:
- Internally float buffers are always linear alpha-premul colors
- Readers should worry about delivering float buffers with that
  assumptions.
- There's an input image setting to say whether it's stored with
  straight/premul alpha on the disk.
- Byte buffers are now assumed have straight alpha, readers should
  deliver straight alpha.

Some implementation details:

- Removed scene's color unpremultiply setting, which was very
  much confusing and was wrong for default settings.
  Now all renderers assumes to deliver premultiplied alpha.

- IMB_buffer_byte_from_float will now linearize alpha when
  converting from buffer.

- Sequencer's effects were changed to assume bytes have got
  straight alpha. Most of effects will work with bytes still,
  however for glow it was more tricky to avoid data loss, so
  there's a commented out glow implementation which converts
  byte buffer to floats first, operates on floats and returns
  bytes back. It's slower and not sure if it should actually
  be used -- who're using glow on alpha anyway?

- Sequencer modifiers should also be working nice with straight
  bytes now.

- GLSL preview will predivide float textures to make nice shading,
  shading with byte textures worked nice (GLSL was assuming straight
  alpha).

- Blender Internal will set alpha=1 to the whole sky. The same
  happens in Cycles and there's no way to avoid this -- sky is
  neither straight nor premul and doesn't fit color pipeline well.

- Straight alpha mode for render result was also eliminated.

- Conversion to correct alpha need to be done before linearizing
  float buffer.

- TIFF will now load and save files with proper alpha mode setting
  in file meta data header.

- Remove Use Alpha from texture mapping and replaced with image
  datablock setting.

  Behaves much more predictable and clear from code point of view
  and solves possible regressions when non-premultiplied images were
  used as textures with ignoring alpha channel.
2012-12-31 13:52:13 +00:00
Sergey Sharybin b518197db7 Correction to recent fix for shader nodes -- image could be not loaded yet
when tree is being executed. This could lead to nor initialized color space
for the image.

Solved by insuring image buffer is loaded before checking for whether color
conversion is needed.
2012-10-23 11:44:47 +00:00
Sergey Sharybin 3285d47842 Fix #32930: texture colors in material nodes (blender internal) are brighter than normal
There was a missing byte buffer linearization for shader nodes.

Also fixed incorrect image input color space refresh when image is packed.
2012-10-22 17:34:06 +00:00
Sergey Sharybin 3b88a29abf Cycles: progressive refine option
Just makes progressive refine :)

This means the whole image would be refined gradually using as much
threads as it's set in performance settings. Having enough tiles is
required to have this option working as it's expected.

Technically it's implemented by repeatedly computing next sample for
all the tiles before switching to next sample.

This works around 7-12% slower than regular tile-based rendering, so
use this option only if you really need it.

This commit also fixes progressive update of image when Save Buffers
option is enabled.

And one more thing this commit fixes is handling display buffer with
Save Buffers option enabled. If this option is enabled image buffer
wouldn't have neither byte nor float buffer until image is fully
rendered which could backfire in missing image while rendering in
cases color management cache became full.

This issue solved by allocating byte buffer for image buffer from
tile update callback.

Patch was reviewed by Brecht. He also made some minor edits to
original version to patch. Thanks, man!
2012-10-13 12:38:32 +00:00
Sergey Sharybin fae7dd22c7 Color Management: resolve warnings when OCIO configuration file misses None display 2012-09-26 13:17:47 +00:00
Sergey Sharybin 456a78961c code cleanup: make naming more consistent 2012-09-25 10:21:51 +00:00
Sergey Sharybin 90a5e8593c Color Management: float generated images had is_data flag set incorrect 2012-09-25 08:42:24 +00:00
Sergey Sharybin 2953b6ab5c Fix #32644: ctrl+F11 internal animation player crash
Crash was caused by missed color management initialization -- it was
happening too late.

Move it to generic ImBuf init/exit functions, so now color management
is properly initializing when animation player is launched.
2012-09-24 13:48:37 +00:00
Sergey Sharybin 9e3e12fa4e Proper fix for #32626: TIFF renders are limited to 8 bit even when we choose 16.
Color management would be applied on both of float and byte buffers on image
save in cases if file format doesn't require linear float buffer and if image
is saving as render result.

This solves both initial report issue and TODO marked in previous fix.

Also de-duplicated image buffer color managing code and gave some more
meaningful names for few functions. Also wrote documentation around this
function, so current assumptions about spaces should be clear enough.

Made regression tests by saving EXR/PNG images to all supported format and
rendering OpenGL/Normal animation, in all cases seems everything is fine,
but more tests for sure would be welcome.
2012-09-24 11:56:07 +00:00
Sergey Sharybin f61ef65adb Color Management: different fixes for byte buffers
- Color space of byte buffer for generated images haven't been
  updated properly on change

- Byte buffers weren't handling data color spaces on display transform
  properly
2012-09-21 20:44:41 +00:00
Sergey Sharybin a73dd3476e Color Management, Stage 2: Switch color pipeline to use OpenColorIO
Replace old color pipeline which was supporting linear/sRGB color spaces
only with OpenColorIO-based pipeline.

This introduces two configurable color spaces:

- Input color space for images and movie clips. This space is used to convert
  images/movies from color space in which file is saved to Blender's linear
  space (for float images, byte images are not internally converted, only input
  space is stored for such images and used later).

  This setting could be found in image/clip data block settings.

- Display color space which defines space in which particular display is working.

  This settings could be found in scene's Color Management panel.

When render result is being displayed on the screen, apart from converting image
to display space, some additional conversions could happen.

This conversions are:

- View, which defines tone curve applying before display transformation.
  These are different ways to view the image on the same display device.
  For example it could be used to emulate film view on sRGB display.

- Exposure affects on image exposure before tone map is applied.

- Gamma is post-display gamma correction, could be used to match particular
  display gamma.

- RGB curves are user-defined curves which are applying before display
  transformation, could be used for different purposes.

All this settings by default are only applying on render result and does not
affect on other images. If some particular image needs to be affected by this
transformation, "View as Render" setting of image data block should be set to
truth. Movie clips are always affected by all display transformations.

This commit also introduces configurable color space in which sequencer is
working. This setting could be found in scene's Color Management panel and
it should be used if such stuff as grading needs to be done in color space
different from sRGB (i.e. when Film view on sRGB display is use, using VD16
space as sequencer's internal space would make grading working in space
which is close to the space using for display).

Some technical notes:

- Image buffer's float buffer is now always in linear space, even if it was
  created from 16bit byte images.

- Space of byte buffer is stored in image buffer's rect_colorspace property.

- Profile of image buffer was removed since it's not longer meaningful.

- OpenGL and GLSL is supposed to always work in sRGB space. It is possible
  to support other spaces, but it's quite large project which isn't so
  much important.

- Legacy Color Management option disabled is emulated by using None display.
  It could have some regressions, but there's no clear way to avoid them.

- If OpenColorIO is disabled on build time, it should make blender behaving
  in the same way as previous release with color management enabled.

More details could be found at this page (more details would be added soon):
http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.64/Color_Management

--
Thanks to Xavier Thomas, Lukas Toene for initial work on OpenColorIO
integration and to Brecht van Lommel for some further development and code/
usecase review!
2012-09-15 10:05:07 +00:00