Skip to content

Commit

Permalink
Better ACES tonemapping function
Browse files Browse the repository at this point in the history
Also, use it in the oklch example as this allows for regression testing 
of the visual output, but also because the example just looks better 
with ACES tonemapping.
  • Loading branch information
jonathanhogg committed Aug 31, 2024
1 parent 3ed4ad9 commit f6c0ee6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
6 changes: 3 additions & 3 deletions docs/windows.md
Original file line number Diff line number Diff line change
Expand Up @@ -641,11 +641,11 @@ of each pixel. Default is `0`.
adjustments, Values less than 1 will lighten the output image and values
greater than 1 will darken it.

`tonemap=` [ `:aces` | `:reinhard` ]
`tonemap=` [ `:reinhard` | `:aces` ]
: If specified, then a tone-mapping function will be applied to map high
dynamic range images into the $[0,1]$ range. The supported tone-mapping
functions are: (an approximation of) the ACES filmic curve, and the Reinhard
curve. Default is no tone-mapping.
functions are: the Reinhard curve function, and a (close approximation of) the
ACES filmic function. Default is no tone-mapping.

If `tonemap=:reinhard` then an additional attribute is supported:

Expand Down
17 changes: 9 additions & 8 deletions examples/oklch.fl
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ let M=50

!window size=1080
!record filename=OUTPUT
!canvas3d
!light color=0.5 direction=0;0;-1
!transform rotate_x=t/30 rotate_z=-t/12 scale=2.5
for c in ..M
!transform translate=0;0;200*c/M-100
for h in ..N
!transform rotate_z=-h/N translate=0;50;0
!sphere size=25 color=oklch(1;0.4*c/M;h/N)
!adjust tonemap=:aces
!canvas3d
!light color=1 direction=0;0;-1
!transform rotate_x=t/30 rotate_z=-t/12 scale=2.5
for c in ..M
!transform translate=0;0;200*c/M-100
for h in ..N
!transform rotate_z=-h/N translate=0;50;0
!sphere size=25 color=oklch(1;0.4*c/M;h/N)
Binary file modified examples/oklch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 7 additions & 2 deletions src/flitter/render/window/glsl/color_functions.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ vec3 tonemap_reinhard(vec3 c, float whitepoint) {
return cd;
}

vec3 tonemap_aces(vec3 c) {
return c * (2.51 * c + 0.03) / (c * (2.43 * c + 0.59) + 0.14);
vec3 tonemap_aces(vec3 color)
{
// This function based on https://github.com/TheRealMJP/BakingLab/blob/master/BakingLab/ACES.hlsl
//
color = mat3(0.59719, 0.076, 0.0284, 0.35458, 0.90834, 0.13383, 0.04823, 0.01566, 0.83777) * color;
color = (color * (color + 0.0245786) - 0.000090537) / (color * (0.983729 * color + 0.4329510) + 0.238081);
return mat3(1.60475, -0.10208, -0.00327, -0.53108, 1.10813, -0.07276, -0.07367, -0.00605, 1.07602) * color;
}

0 comments on commit f6c0ee6

Please sign in to comment.