forked from google/ExoPlayer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add OETF and EOTF ES2 fragment shaders for non-HDR frames.
* Transform the intermediate color space to linear SDR by applying the SMPTE 170M EOTF and OETF. * Use linear colors for the color filter pixel tests and update all golden bitmaps. PiperOrigin-RevId: 476124592
- Loading branch information
1 parent
331d4d6
commit afd829e
Showing
58 changed files
with
201 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 0 additions & 30 deletions
30
...libraries/effect/src/main/assets/shaders/fragment_shader_transformation_external_es2.glsl
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
...aries/effect/src/main/assets/shaders/fragment_shader_transformation_sdr_external_es2.glsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#version 100 | ||
// Copyright 2021 The Android Open Source Project | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
|
||
// ES 2 fragment shader that: | ||
// 1. Samples from an external texture with uTexSampler copying from this | ||
// texture to the current output. | ||
// 2. Transforms the electrical colors to optical colors using the SMPTE 170M | ||
// EOTF. | ||
// 3. Applies a 4x4 RGB color matrix to change the pixel colors. | ||
// 4. Transforms the optical colors back to electrical ones if uApplyOetf == 1 | ||
// using the SMPTE 170M OETF. | ||
|
||
#extension GL_OES_EGL_image_external : require | ||
precision mediump float; | ||
uniform samplerExternalOES uTexSampler; | ||
uniform mat4 uRgbMatrix; | ||
varying vec2 vTexSamplingCoord; | ||
uniform int uApplyOetf; | ||
|
||
const float inverseGamma = 0.4500; | ||
const float gamma = 1.0 / inverseGamma; | ||
|
||
// Transforms a single channel from electrical to optical SDR. | ||
float sdrEotfSingleChannel(float electricalChannel) { | ||
// Specification: | ||
// https://www.itu.int/rec/R-REC-BT.1700-0-200502-I/en | ||
return electricalChannel < 0.0812 | ||
? electricalChannel / 4.500 | ||
: pow((electricalChannel + 0.099) / 1.099, gamma); | ||
} | ||
|
||
// Transforms electronical to optical SDR using the SMPTE 170M EOTF. | ||
vec3 sdrEotf(vec3 electricalColor) { | ||
return vec3( | ||
sdrEotfSingleChannel(electricalColor.r), | ||
sdrEotfSingleChannel(electricalColor.g), | ||
sdrEotfSingleChannel(electricalColor.b)); | ||
} | ||
|
||
// Transforms a single channel from optical to electrical SDR. | ||
float sdrOetfSingleChannel(float opticalChannel) { | ||
// Specification: | ||
// https://www.itu.int/rec/R-REC-BT.1700-0-200502-I/en | ||
return opticalChannel < 0.018 | ||
? opticalChannel * 4.500 | ||
: 1.099 * pow(opticalChannel, inverseGamma) - 0.099; | ||
} | ||
|
||
// Transforms optical SDR colors to electrical SDR using the SMPTE 170M OETF. | ||
vec3 sdrOetf(vec3 opticalColor) { | ||
return uApplyOetf == 1 | ||
? vec3( | ||
sdrOetfSingleChannel(opticalColor.r), | ||
sdrOetfSingleChannel(opticalColor.g), | ||
sdrOetfSingleChannel(opticalColor.b)) | ||
: opticalColor; | ||
} | ||
|
||
void main() { | ||
vec4 inputColor = texture2D(uTexSampler, vTexSamplingCoord); | ||
vec3 linearInputColor = sdrEotf(inputColor.rgb); | ||
|
||
vec4 transformedColors = uRgbMatrix * vec4(linearInputColor, 1); | ||
|
||
gl_FragColor = vec4(sdrOetf(transformedColors.rgb), inputColor.a); | ||
} |
52 changes: 52 additions & 0 deletions
52
...libraries/effect/src/main/assets/shaders/fragment_shader_transformation_sdr_oetf_es2.glsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#version 100 | ||
// Copyright 2022 The Android Open Source Project | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// ES 2 fragment shader that: | ||
// 1. Samples from uTexSampler, copying from this texture to the current | ||
// output. | ||
// 2. Applies a 4x4 RGB color matrix to change the pixel colors. | ||
// 3. Transforms the optical colors to electrical colors using the SMPTE | ||
// 170M OETF. | ||
|
||
precision mediump float; | ||
uniform sampler2D uTexSampler; | ||
uniform mat4 uRgbMatrix; | ||
varying vec2 vTexSamplingCoord; | ||
|
||
const float inverseGamma = 0.4500; | ||
|
||
// Transforms a single channel from optical to electrical SDR. | ||
float sdrOetfSingleChannel(float opticalChannel) { | ||
// Specification: | ||
// https://www.itu.int/rec/R-REC-BT.1700-0-200502-I/en | ||
return opticalChannel < 0.018 | ||
? opticalChannel * 4.500 | ||
: 1.099 * pow(opticalChannel, inverseGamma) - 0.099; | ||
} | ||
|
||
// Transforms optical SDR colors to electrical SDR using the SMPTE 170M OETF. | ||
vec3 sdrOetf(vec3 opticalColor) { | ||
return vec3( | ||
sdrOetfSingleChannel(opticalColor.r), | ||
sdrOetfSingleChannel(opticalColor.g), | ||
sdrOetfSingleChannel(opticalColor.b)); | ||
} | ||
|
||
void main() { | ||
vec4 inputColor = texture2D(uTexSampler, vTexSamplingCoord); | ||
vec4 transformedColors = uRgbMatrix * vec4(inputColor.rgb, 1); | ||
|
||
gl_FragColor = vec4(sdrOetf(transformedColors.rgb), inputColor.a); | ||
} |
Oops, something went wrong.