Skip to content

Commit bbbd075

Browse files
committed
Support WebGL1, rearrange
1 parent c5f70be commit bbbd075

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl.js

+24-20
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,20 @@ vec3 ACESFilmicToneMapping( vec3 color ) {
7373
7474
}
7575
76+
// Matrices for rec 2020 <> rec 709 color space conversion
77+
// matrix provided in row-major order so it has been transposed
78+
// https://www.itu.int/pub/R-REP-BT.2407-2017
79+
const mat3 LINEAR_REC2020_TO_LINEAR_SRGB = mat3(
80+
vec3( 1.6605, - 0.1246, - 0.0182 ),
81+
vec3( - 0.5876, 1.1329, - 0.1006 ),
82+
vec3( - 0.0728, - 0.0083, 1.1187 )
83+
);
84+
85+
const mat3 LINEAR_SRGB_TO_LINEAR_REC2020 = mat3(
86+
vec3( 0.6274, 0.0691, 0.0164 ),
87+
vec3( 0.3293, 0.9195, 0.0880 ),
88+
vec3( 0.0433, 0.0113, 0.8956 )
89+
);
7690
7791
// https://iolite-engine.com/blog_posts/minimal_agx_implementation
7892
//
@@ -95,36 +109,26 @@ vec3 agxDefaultContrastApprox( vec3 x ) {
95109
// Input and output encoded as Linear-sRGB.
96110
vec3 AgXToneMapping( vec3 color ) {
97111
98-
// Matrices for rec 2020 <> rec 709 color space conversion
99-
// matrix provided in row-major order so it has been transposed
100-
// https://www.itu.int/pub/R-REP-BT.2407-2017
101-
const mat3 LINEAR_REC2020_TO_LINEAR_SRGB = mat3(
102-
vec3( 1.6605, - 0.1246, - 0.0182 ),
103-
vec3( - 0.5876, 1.1329, - 0.1006 ),
104-
vec3( - 0.0728, - 0.0083, 1.1187 )
105-
);
106-
107-
// TODO: add implementation
108-
const mat3 LINEAR_SRGB_TO_LINEAR_REC2020 = inverse( LINEAR_REC2020_TO_LINEAR_SRGB );
109-
110-
// AGX Tone Mapping implementation based on Filament, which is in turn based
111-
// on Blender's implementation for rec 2020 colors:
112-
// https://github.com/google/filament/pull/7236
112+
// AgX constants
113113
const mat3 AgXInsetMatrix = mat3(
114114
vec3( 0.856627153315983, 0.137318972929847, 0.11189821299995 ),
115115
vec3( 0.0951212405381588, 0.761241990602591, 0.0767994186031903 ),
116116
vec3( 0.0482516061458583, 0.101439036467562, 0.811302368396859 )
117117
);
118-
const mat3 AgXOutsetMatrixInv = mat3(
119-
vec3( 0.899796955911611, 0.11142098895748, 0.11142098895748 ),
120-
vec3( 0.0871996192028351, 0.875575586156966, 0.0871996192028349 ),
121-
vec3( 0.013003424885555, 0.0130034248855548, 0.801379391839686 )
118+
119+
// explicit AgXOutsetMatrix generated from Filaments AgXOutsetMatixInv
120+
const mat3 AgXOutsetMatrix = mat3(
121+
vec3( 1.1271005818144368, - 0.1413297634984383, - 0.14132976349843826 ),
122+
vec3( - 0.11060664309660323, 1.157823702216272, - 0.11060664309660294 ),
123+
vec3( - 0.016493938717834573, - 0.016493938717834257, 1.2519364065950405 )
122124
);
123-
const mat3 AgXOutsetMatrix = inverse( AgXOutsetMatrixInv );
124125
125126
const float AgxMinEv = - 12.47393; // log2(pow(2, LOG2_MIN) * MIDDLE_GRAY)
126127
const float AgxMaxEv = 4.026069; // log2(pow(2, LOG2_MAX) * MIDDLE_GRAY)
127128
129+
// AGX Tone Mapping implementation based on Filament, which is in turn based
130+
// on Blender's implementation for rec 2020 colors:
131+
// https://github.com/google/filament/pull/7236
128132
color = LINEAR_SRGB_TO_LINEAR_REC2020 * color;
129133
130134
color = max( vec3( 0.0 ), color );

0 commit comments

Comments
 (0)