Commit 82af7f1d by andrewlewis Committed by Tofunmi Adigun-Hameed

Run `clang-format` on GLSL

PiperOrigin-RevId: 534015933
(cherry picked from commit 65c33e69709f34ef94f8831b290eb30df2a4306b)
parent 9066652b
...@@ -34,12 +34,9 @@ varying vec2 vTexSamplingCoord; ...@@ -34,12 +34,9 @@ varying vec2 vTexSamplingCoord;
const float epsilon = 1e-10; const float epsilon = 1e-10;
vec3 rgbToHcv(vec3 rgb) { vec3 rgbToHcv(vec3 rgb) {
vec4 p = (rgb.g < rgb.b) vec4 p = (rgb.g < rgb.b) ? vec4(rgb.bg, -1.0, 2.0 / 3.0)
? vec4(rgb.bg, -1.0, 2.0 / 3.0)
: vec4(rgb.gb, 0.0, -1.0 / 3.0); : vec4(rgb.gb, 0.0, -1.0 / 3.0);
vec4 q = (rgb.r < p.x) vec4 q = (rgb.r < p.x) ? vec4(p.xyw, rgb.r) : vec4(rgb.r, p.yzx);
? vec4(p.xyw, rgb.r)
: vec4(rgb.r, p.yzx);
float c = q.x - min(q.w, q.y); float c = q.x - min(q.w, q.y);
float h = abs((q.w - q.y) / (6.0 * c + epsilon) + q.z); float h = abs((q.w - q.y) / (6.0 * c + epsilon) + q.z);
return vec3(h, c, q.x); return vec3(h, c, q.x);
......
...@@ -72,11 +72,9 @@ vec3 applyLookup(vec3 color) { ...@@ -72,11 +72,9 @@ vec3 applyLookup(vec3 color) {
// by N gives us the final formula for y: // by N gives us the final formula for y:
// y = ((0.5 + N * redCoord + g * (N - 1)) / N) / N // y = ((0.5 + N * redCoord + g * (N - 1)) / N) / N
// y = (0.5 + redCoord * N + g * (N - 1)) / (N * N) // y = (0.5 + redCoord * N + g * (N - 1)) / (N * N)
float lowerY = float lowerY = (0.5 + redCoordLow * uColorLutLength +
(0.5 color.g * (uColorLutLength - 1.0)) /
+ redCoordLow * uColorLutLength (uColorLutLength * uColorLutLength);
+ color.g * (uColorLutLength - 1.0))
/ (uColorLutLength * uColorLutLength);
// The upperY is the same position moved up by one LUT plane. // The upperY is the same position moved up by one LUT plane.
float upperY = lowerY + 1.0 / uColorLutLength; float upperY = lowerY + 1.0 / uColorLutLength;
......
...@@ -44,17 +44,15 @@ highp float hlgOetfSingleChannel(highp float linearChannel) { ...@@ -44,17 +44,15 @@ highp float hlgOetfSingleChannel(highp float linearChannel) {
const highp float b = 0.28466892; const highp float b = 0.28466892;
const highp float c = 0.55991073; const highp float c = 0.55991073;
return linearChannel <= 1.0 / 12.0 ? sqrt(3.0 * linearChannel) : return linearChannel <= 1.0 / 12.0 ? sqrt(3.0 * linearChannel)
a * log(12.0 * linearChannel - b) + c; : a * log(12.0 * linearChannel - b) + c;
} }
// BT.2100 / BT.2020 HLG OETF. // BT.2100 / BT.2020 HLG OETF.
highp vec3 hlgOetf(highp vec3 linearColor) { highp vec3 hlgOetf(highp vec3 linearColor) {
return vec3( return vec3(hlgOetfSingleChannel(linearColor.r),
hlgOetfSingleChannel(linearColor.r),
hlgOetfSingleChannel(linearColor.g), hlgOetfSingleChannel(linearColor.g),
hlgOetfSingleChannel(linearColor.b) hlgOetfSingleChannel(linearColor.b));
);
} }
// BT.2100 / BT.2020, PQ / ST2084 OETF. // BT.2100 / BT.2020, PQ / ST2084 OETF.
......
...@@ -66,17 +66,15 @@ highp float hlgEotfSingleChannel(highp float hlgChannel) { ...@@ -66,17 +66,15 @@ highp float hlgEotfSingleChannel(highp float hlgChannel) {
const highp float a = 0.17883277; const highp float a = 0.17883277;
const highp float b = 0.28466892; const highp float b = 0.28466892;
const highp float c = 0.55991073; const highp float c = 0.55991073;
return hlgChannel <= 0.5 ? hlgChannel * hlgChannel / 3.0 : return hlgChannel <= 0.5 ? hlgChannel * hlgChannel / 3.0
(b + exp((hlgChannel - c) / a)) / 12.0; : (b + exp((hlgChannel - c) / a)) / 12.0;
} }
// BT.2100 / BT.2020 HLG EOTF. // BT.2100 / BT.2020 HLG EOTF.
highp vec3 hlgEotf(highp vec3 hlgColor) { highp vec3 hlgEotf(highp vec3 hlgColor) {
return vec3( return vec3(hlgEotfSingleChannel(hlgColor.r),
hlgEotfSingleChannel(hlgColor.r),
hlgEotfSingleChannel(hlgColor.g), hlgEotfSingleChannel(hlgColor.g),
hlgEotfSingleChannel(hlgColor.b) hlgEotfSingleChannel(hlgColor.b));
);
} }
// BT.2100 / BT.2020 PQ EOTF. // BT.2100 / BT.2020 PQ EOTF.
...@@ -115,18 +113,17 @@ highp vec3 applyHlgBt2020ToBt709Ootf(highp vec3 linearRgbBt2020) { ...@@ -115,18 +113,17 @@ highp vec3 applyHlgBt2020ToBt709Ootf(highp vec3 linearRgbBt2020) {
// https://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.2100-2-201807-I!!PDF-E.pdf // https://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.2100-2-201807-I!!PDF-E.pdf
// Matrix values based on computeXYZMatrix(BT2020Primaries, BT2020WhitePoint) // Matrix values based on computeXYZMatrix(BT2020Primaries, BT2020WhitePoint)
// https://cs.android.com/android/platform/superproject/+/master:frameworks/base/libs/hwui/utils/HostColorSpace.cpp;l=200-232;drc=86bd214059cd6150304888a285941bf74af5b687 // https://cs.android.com/android/platform/superproject/+/master:frameworks/base/libs/hwui/utils/HostColorSpace.cpp;l=200-232;drc=86bd214059cd6150304888a285941bf74af5b687
const mat3 RGB_TO_XYZ_BT2020 = mat3( const mat3 RGB_TO_XYZ_BT2020 =
0.63695805f, 0.26270021f, 0.00000000f, mat3(0.63695805f, 0.26270021f, 0.00000000f, 0.14461690f, 0.67799807f,
0.14461690f, 0.67799807f, 0.02807269f, 0.02807269f, 0.16888098f, 0.05930172f, 1.06098506f);
0.16888098f, 0.05930172f, 1.06098506f);
// Matrix values based on computeXYZMatrix(BT709Primaries, BT709WhitePoint) // Matrix values based on computeXYZMatrix(BT709Primaries, BT709WhitePoint)
const mat3 XYZ_TO_RGB_BT709 = mat3( const mat3 XYZ_TO_RGB_BT709 =
3.24096994f, -0.96924364f, 0.05563008f, mat3(3.24096994f, -0.96924364f, 0.05563008f, -1.53738318f, 1.87596750f,
-1.53738318f, 1.87596750f, -0.20397696f, -0.20397696f, -0.49861076f, 0.04155506f, 1.05697151f);
-0.49861076f, 0.04155506f, 1.05697151f);
// hlgGamma is 1.2 + 0.42 * log10(nominalPeakLuminance/1000); // hlgGamma is 1.2 + 0.42 * log10(nominalPeakLuminance/1000);
// nominalPeakLuminance was selected to use a 500 as a typical value, used // nominalPeakLuminance was selected to use a 500 as a typical value, used
// in https://cs.android.com/android/platform/superproject/+/master:frameworks/native/libs/tonemap/tonemap.cpp;drc=7a577450e536aa1e99f229a0cb3d3531c82e8a8d;l=62, // in
// https://cs.android.com/android/platform/superproject/+/master:frameworks/native/libs/tonemap/tonemap.cpp;drc=7a577450e536aa1e99f229a0cb3d3531c82e8a8d;l=62,
// b/199162498#comment35, and // b/199162498#comment35, and
// https://www.microsoft.com/applied-sciences/uploads/projects/investigation-of-hdr-vs-tone-mapped-sdr/investigation-of-hdr-vs-tone-mapped-sdr.pdf. // https://www.microsoft.com/applied-sciences/uploads/projects/investigation-of-hdr-vs-tone-mapped-sdr/investigation-of-hdr-vs-tone-mapped-sdr.pdf.
const float hlgGamma = 1.0735674018211279; const float hlgGamma = 1.0735674018211279;
...@@ -167,17 +164,15 @@ highp float hlgOetfSingleChannel(highp float linearChannel) { ...@@ -167,17 +164,15 @@ highp float hlgOetfSingleChannel(highp float linearChannel) {
const highp float b = 0.28466892; const highp float b = 0.28466892;
const highp float c = 0.55991073; const highp float c = 0.55991073;
return linearChannel <= 1.0 / 12.0 ? sqrt(3.0 * linearChannel) : return linearChannel <= 1.0 / 12.0 ? sqrt(3.0 * linearChannel)
a * log(12.0 * linearChannel - b) + c; : a * log(12.0 * linearChannel - b) + c;
} }
// BT.2100 / BT.2020 HLG OETF. // BT.2100 / BT.2020 HLG OETF.
highp vec3 hlgOetf(highp vec3 linearColor) { highp vec3 hlgOetf(highp vec3 linearColor) {
return vec3( return vec3(hlgOetfSingleChannel(linearColor.r),
hlgOetfSingleChannel(linearColor.r),
hlgOetfSingleChannel(linearColor.g), hlgOetfSingleChannel(linearColor.g),
hlgOetfSingleChannel(linearColor.b) hlgOetfSingleChannel(linearColor.b));
);
} }
// BT.2100 / BT.2020, PQ / ST2084 OETF. // BT.2100 / BT.2020, PQ / ST2084 OETF.
...@@ -206,8 +201,7 @@ float gamma22OetfSingleChannel(highp float linearChannel) { ...@@ -206,8 +201,7 @@ float gamma22OetfSingleChannel(highp float linearChannel) {
// BT.709 gamma 2.2 OETF. // BT.709 gamma 2.2 OETF.
vec3 gamma22Oetf(highp vec3 linearColor) { vec3 gamma22Oetf(highp vec3 linearColor) {
return vec3( return vec3(gamma22OetfSingleChannel(linearColor.r),
gamma22OetfSingleChannel(linearColor.r),
gamma22OetfSingleChannel(linearColor.g), gamma22OetfSingleChannel(linearColor.g),
gamma22OetfSingleChannel(linearColor.b)); gamma22OetfSingleChannel(linearColor.b));
} }
...@@ -237,7 +231,8 @@ vec3 yuvToRgb(vec3 yuv) { ...@@ -237,7 +231,8 @@ vec3 yuvToRgb(vec3 yuv) {
void main() { void main() {
vec3 srcYuv = texture(uTexSampler, vTexSamplingCoord).xyz; vec3 srcYuv = texture(uTexSampler, vTexSamplingCoord).xyz;
vec3 opticalColorBt2020 = applyEotf(yuvToRgb(srcYuv)); vec3 opticalColorBt2020 = applyEotf(yuvToRgb(srcYuv));
vec4 opticalColor = (uApplyHdrToSdrToneMapping == 1) vec4 opticalColor =
(uApplyHdrToSdrToneMapping == 1)
? vec4(applyBt2020ToBt709Ootf(opticalColorBt2020), 1.0) ? vec4(applyBt2020ToBt709Ootf(opticalColorBt2020), 1.0)
: vec4(opticalColorBt2020, 1.0); : vec4(opticalColorBt2020, 1.0);
vec4 transformedColors = uRgbMatrix * opticalColor; vec4 transformedColors = uRgbMatrix * opticalColor;
......
...@@ -58,17 +58,15 @@ highp float hlgEotfSingleChannel(highp float hlgChannel) { ...@@ -58,17 +58,15 @@ highp float hlgEotfSingleChannel(highp float hlgChannel) {
const highp float a = 0.17883277; const highp float a = 0.17883277;
const highp float b = 0.28466892; const highp float b = 0.28466892;
const highp float c = 0.55991073; const highp float c = 0.55991073;
return hlgChannel <= 0.5 ? hlgChannel * hlgChannel / 3.0 : return hlgChannel <= 0.5 ? hlgChannel * hlgChannel / 3.0
(b + exp((hlgChannel - c) / a)) / 12.0; : (b + exp((hlgChannel - c) / a)) / 12.0;
} }
// BT.2100 / BT.2020 HLG EOTF. // BT.2100 / BT.2020 HLG EOTF.
highp vec3 hlgEotf(highp vec3 hlgColor) { highp vec3 hlgEotf(highp vec3 hlgColor) {
return vec3( return vec3(hlgEotfSingleChannel(hlgColor.r),
hlgEotfSingleChannel(hlgColor.r),
hlgEotfSingleChannel(hlgColor.g), hlgEotfSingleChannel(hlgColor.g),
hlgEotfSingleChannel(hlgColor.b) hlgEotfSingleChannel(hlgColor.b));
);
} }
// BT.2100 / BT.2020 PQ EOTF. // BT.2100 / BT.2020 PQ EOTF.
...@@ -107,18 +105,17 @@ highp vec3 applyHlgBt2020ToBt709Ootf(highp vec3 linearRgbBt2020) { ...@@ -107,18 +105,17 @@ highp vec3 applyHlgBt2020ToBt709Ootf(highp vec3 linearRgbBt2020) {
// https://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.2100-2-201807-I!!PDF-E.pdf // https://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.2100-2-201807-I!!PDF-E.pdf
// Matrix values based on computeXYZMatrix(BT2020Primaries, BT2020WhitePoint) // Matrix values based on computeXYZMatrix(BT2020Primaries, BT2020WhitePoint)
// https://cs.android.com/android/platform/superproject/+/master:frameworks/base/libs/hwui/utils/HostColorSpace.cpp;l=200-232;drc=86bd214059cd6150304888a285941bf74af5b687 // https://cs.android.com/android/platform/superproject/+/master:frameworks/base/libs/hwui/utils/HostColorSpace.cpp;l=200-232;drc=86bd214059cd6150304888a285941bf74af5b687
const mat3 RGB_TO_XYZ_BT2020 = mat3( const mat3 RGB_TO_XYZ_BT2020 =
0.63695805f, 0.26270021f, 0.00000000f, mat3(0.63695805f, 0.26270021f, 0.00000000f, 0.14461690f, 0.67799807f,
0.14461690f, 0.67799807f, 0.02807269f, 0.02807269f, 0.16888098f, 0.05930172f, 1.06098506f);
0.16888098f, 0.05930172f, 1.06098506f);
// Matrix values based on computeXYZMatrix(BT709Primaries, BT709WhitePoint) // Matrix values based on computeXYZMatrix(BT709Primaries, BT709WhitePoint)
const mat3 XYZ_TO_RGB_BT709 = mat3( const mat3 XYZ_TO_RGB_BT709 =
3.24096994f, -0.96924364f, 0.05563008f, mat3(3.24096994f, -0.96924364f, 0.05563008f, -1.53738318f, 1.87596750f,
-1.53738318f, 1.87596750f, -0.20397696f, -0.20397696f, -0.49861076f, 0.04155506f, 1.05697151f);
-0.49861076f, 0.04155506f, 1.05697151f);
// hlgGamma is 1.2 + 0.42 * log10(nominalPeakLuminance/1000); // hlgGamma is 1.2 + 0.42 * log10(nominalPeakLuminance/1000);
// nominalPeakLuminance was selected to use a 500 as a typical value, used // nominalPeakLuminance was selected to use a 500 as a typical value, used
// in https://cs.android.com/android/platform/superproject/+/master:frameworks/native/libs/tonemap/tonemap.cpp;drc=7a577450e536aa1e99f229a0cb3d3531c82e8a8d;l=62, // in
// https://cs.android.com/android/platform/superproject/+/master:frameworks/native/libs/tonemap/tonemap.cpp;drc=7a577450e536aa1e99f229a0cb3d3531c82e8a8d;l=62,
// b/199162498#comment35, and // b/199162498#comment35, and
// https://www.microsoft.com/applied-sciences/uploads/projects/investigation-of-hdr-vs-tone-mapped-sdr/investigation-of-hdr-vs-tone-mapped-sdr.pdf. // https://www.microsoft.com/applied-sciences/uploads/projects/investigation-of-hdr-vs-tone-mapped-sdr/investigation-of-hdr-vs-tone-mapped-sdr.pdf.
const float hlgGamma = 1.0735674018211279; const float hlgGamma = 1.0735674018211279;
...@@ -159,17 +156,15 @@ highp float hlgOetfSingleChannel(highp float linearChannel) { ...@@ -159,17 +156,15 @@ highp float hlgOetfSingleChannel(highp float linearChannel) {
const highp float b = 0.28466892; const highp float b = 0.28466892;
const highp float c = 0.55991073; const highp float c = 0.55991073;
return linearChannel <= 1.0 / 12.0 ? sqrt(3.0 * linearChannel) : return linearChannel <= 1.0 / 12.0 ? sqrt(3.0 * linearChannel)
a * log(12.0 * linearChannel - b) + c; : a * log(12.0 * linearChannel - b) + c;
} }
// BT.2100 / BT.2020 HLG OETF. // BT.2100 / BT.2020 HLG OETF.
highp vec3 hlgOetf(highp vec3 linearColor) { highp vec3 hlgOetf(highp vec3 linearColor) {
return vec3( return vec3(hlgOetfSingleChannel(linearColor.r),
hlgOetfSingleChannel(linearColor.r),
hlgOetfSingleChannel(linearColor.g), hlgOetfSingleChannel(linearColor.g),
hlgOetfSingleChannel(linearColor.b) hlgOetfSingleChannel(linearColor.b));
);
} }
// BT.2100 / BT.2020, PQ / ST2084 OETF. // BT.2100 / BT.2020, PQ / ST2084 OETF.
...@@ -198,8 +193,7 @@ float gamma22OetfSingleChannel(highp float linearChannel) { ...@@ -198,8 +193,7 @@ float gamma22OetfSingleChannel(highp float linearChannel) {
// BT.709 gamma 2.2 OETF. // BT.709 gamma 2.2 OETF.
vec3 gamma22Oetf(highp vec3 linearColor) { vec3 gamma22Oetf(highp vec3 linearColor) {
return vec3( return vec3(gamma22OetfSingleChannel(linearColor.r),
gamma22OetfSingleChannel(linearColor.r),
gamma22OetfSingleChannel(linearColor.g), gamma22OetfSingleChannel(linearColor.g),
gamma22OetfSingleChannel(linearColor.b)); gamma22OetfSingleChannel(linearColor.b));
} }
...@@ -222,9 +216,10 @@ highp vec3 applyOetf(highp vec3 linearColor) { ...@@ -222,9 +216,10 @@ highp vec3 applyOetf(highp vec3 linearColor) {
} }
void main() { void main() {
vec3 opticalColorBt2020 = applyEotf( vec3 opticalColorBt2020 =
texture(uTexSampler, vTexSamplingCoord).xyz); applyEotf(texture(uTexSampler, vTexSamplingCoord).xyz);
vec4 opticalColor = (uApplyHdrToSdrToneMapping == 1) vec4 opticalColor =
(uApplyHdrToSdrToneMapping == 1)
? vec4(applyBt2020ToBt709Ootf(opticalColorBt2020), 1.0) ? vec4(applyBt2020ToBt709Ootf(opticalColorBt2020), 1.0)
: vec4(opticalColorBt2020, 1.0); : vec4(opticalColorBt2020, 1.0);
vec4 transformedColors = uRgbMatrix * opticalColor; vec4 transformedColors = uRgbMatrix * opticalColor;
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
// ES 2 fragment shader that: // ES 2 fragment shader that:
// 1. Samples from an external texture with uTexSampler copying from this // 1. Samples from an external texture with uTexSampler copying from this
// texture to the current output. // texture to the current output.
...@@ -51,8 +50,7 @@ float smpte170mEotfSingleChannel(float electricalChannel) { ...@@ -51,8 +50,7 @@ float smpte170mEotfSingleChannel(float electricalChannel) {
// Transforms electrical to optical SDR using the SMPTE 170M EOTF. // Transforms electrical to optical SDR using the SMPTE 170M EOTF.
vec3 smpte170mEotf(vec3 electricalColor) { vec3 smpte170mEotf(vec3 electricalColor) {
return vec3( return vec3(smpte170mEotfSingleChannel(electricalColor.r),
smpte170mEotfSingleChannel(electricalColor.r),
smpte170mEotfSingleChannel(electricalColor.g), smpte170mEotfSingleChannel(electricalColor.g),
smpte170mEotfSingleChannel(electricalColor.b)); smpte170mEotfSingleChannel(electricalColor.b));
} }
...@@ -68,8 +66,7 @@ float smpte170mOetfSingleChannel(float opticalChannel) { ...@@ -68,8 +66,7 @@ float smpte170mOetfSingleChannel(float opticalChannel) {
// Transforms optical SDR colors to electrical SDR using the SMPTE 170M OETF. // Transforms optical SDR colors to electrical SDR using the SMPTE 170M OETF.
vec3 smpte170mOetf(vec3 opticalColor) { vec3 smpte170mOetf(vec3 opticalColor) {
return vec3( return vec3(smpte170mOetfSingleChannel(opticalColor.r),
smpte170mOetfSingleChannel(opticalColor.r),
smpte170mOetfSingleChannel(opticalColor.g), smpte170mOetfSingleChannel(opticalColor.g),
smpte170mOetfSingleChannel(opticalColor.b)); smpte170mOetfSingleChannel(opticalColor.b));
} }
...@@ -80,8 +77,8 @@ highp vec3 applyOetf(highp vec3 linearColor) { ...@@ -80,8 +77,8 @@ highp vec3 applyOetf(highp vec3 linearColor) {
// LINT.IfChange(color_transfer) // LINT.IfChange(color_transfer)
const int COLOR_TRANSFER_LINEAR = 1; const int COLOR_TRANSFER_LINEAR = 1;
const int COLOR_TRANSFER_SDR_VIDEO = 3; const int COLOR_TRANSFER_SDR_VIDEO = 3;
if (uOutputColorTransfer == COLOR_TRANSFER_LINEAR if (uOutputColorTransfer == COLOR_TRANSFER_LINEAR ||
|| uEnableColorTransfer == GL_FALSE) { uEnableColorTransfer == GL_FALSE) {
return linearColor; return linearColor;
} else if (uOutputColorTransfer == COLOR_TRANSFER_SDR_VIDEO) { } else if (uOutputColorTransfer == COLOR_TRANSFER_SDR_VIDEO) {
return smpte170mOetf(linearColor); return smpte170mOetf(linearColor);
...@@ -91,8 +88,8 @@ highp vec3 applyOetf(highp vec3 linearColor) { ...@@ -91,8 +88,8 @@ highp vec3 applyOetf(highp vec3 linearColor) {
} }
} }
vec3 applyEotf(vec3 electricalColor){ vec3 applyEotf(vec3 electricalColor) {
if (uEnableColorTransfer == GL_TRUE){ if (uEnableColorTransfer == GL_TRUE) {
return smpte170mEotf(electricalColor); return smpte170mEotf(electricalColor);
} else if (uEnableColorTransfer == GL_FALSE) { } else if (uEnableColorTransfer == GL_FALSE) {
return electricalColor; return electricalColor;
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
// ES 2 fragment shader that: // ES 2 fragment shader that:
// 1. Samples from an input texture created from an internal texture (e.g. a // 1. Samples from an input texture created from an internal texture (e.g. a
// texture created from a bitmap), with uTexSampler copying from this texture // texture created from a bitmap), with uTexSampler copying from this texture
...@@ -56,11 +55,9 @@ float srgbEotfSingleChannel(float electricalChannel) { ...@@ -56,11 +55,9 @@ float srgbEotfSingleChannel(float electricalChannel) {
// Transforms electrical to optical SDR using the sRGB EOTF. // Transforms electrical to optical SDR using the sRGB EOTF.
vec3 srgbEotf(const vec3 electricalColor) { vec3 srgbEotf(const vec3 electricalColor) {
return vec3( return vec3(srgbEotfSingleChannel(electricalColor.r),
srgbEotfSingleChannel(electricalColor.r),
srgbEotfSingleChannel(electricalColor.g), srgbEotfSingleChannel(electricalColor.g),
srgbEotfSingleChannel(electricalColor.b) srgbEotfSingleChannel(electricalColor.b));
);
} }
// Transforms a single channel from electrical to optical SDR using the SMPTE // Transforms a single channel from electrical to optical SDR using the SMPTE
...@@ -75,8 +72,7 @@ float smpte170mEotfSingleChannel(float electricalChannel) { ...@@ -75,8 +72,7 @@ float smpte170mEotfSingleChannel(float electricalChannel) {
// Transforms electrical to optical SDR using the SMPTE 170M EOTF. // Transforms electrical to optical SDR using the SMPTE 170M EOTF.
vec3 smpte170mEotf(vec3 electricalColor) { vec3 smpte170mEotf(vec3 electricalColor) {
return vec3( return vec3(smpte170mEotfSingleChannel(electricalColor.r),
smpte170mEotfSingleChannel(electricalColor.r),
smpte170mEotfSingleChannel(electricalColor.g), smpte170mEotfSingleChannel(electricalColor.g),
smpte170mEotfSingleChannel(electricalColor.b)); smpte170mEotfSingleChannel(electricalColor.b));
} }
...@@ -92,17 +88,16 @@ float smpte170mOetfSingleChannel(float opticalChannel) { ...@@ -92,17 +88,16 @@ float smpte170mOetfSingleChannel(float opticalChannel) {
// Transforms optical SDR colors to electrical SDR using the SMPTE 170M OETF. // Transforms optical SDR colors to electrical SDR using the SMPTE 170M OETF.
vec3 smpte170mOetf(vec3 opticalColor) { vec3 smpte170mOetf(vec3 opticalColor) {
return vec3( return vec3(smpte170mOetfSingleChannel(opticalColor.r),
smpte170mOetfSingleChannel(opticalColor.r),
smpte170mOetfSingleChannel(opticalColor.g), smpte170mOetfSingleChannel(opticalColor.g),
smpte170mOetfSingleChannel(opticalColor.b)); smpte170mOetfSingleChannel(opticalColor.b));
} }
// Applies the appropriate EOTF to convert nonlinear electrical signals to linear // Applies the appropriate EOTF to convert nonlinear electrical signals to
// optical signals. Input and output are both normalized to [0, 1]. // linear optical signals. Input and output are both normalized to [0, 1].
vec3 applyEotf(vec3 electricalColor){ vec3 applyEotf(vec3 electricalColor) {
if (uEnableColorTransfer == GL_TRUE){ if (uEnableColorTransfer == GL_TRUE) {
if (uInputColorTransfer == COLOR_TRANSFER_SRGB){ if (uInputColorTransfer == COLOR_TRANSFER_SRGB) {
return srgbEotf(electricalColor) ; return srgbEotf(electricalColor);
} else if (uInputColorTransfer == COLOR_TRANSFER_SDR_VIDEO) { } else if (uInputColorTransfer == COLOR_TRANSFER_SDR_VIDEO) {
return smpte170mEotf(electricalColor); return smpte170mEotf(electricalColor);
} else { } else {
...@@ -120,8 +115,8 @@ vec3 applyEotf(vec3 electricalColor){ ...@@ -120,8 +115,8 @@ vec3 applyEotf(vec3 electricalColor){
// Applies the appropriate OETF to convert linear optical signals to nonlinear // Applies the appropriate OETF to convert linear optical signals to nonlinear
// electrical signals. Input and output are both normalized to [0, 1]. // electrical signals. Input and output are both normalized to [0, 1].
highp vec3 applyOetf(highp vec3 linearColor) { highp vec3 applyOetf(highp vec3 linearColor) {
if (uOutputColorTransfer == COLOR_TRANSFER_LINEAR if (uOutputColorTransfer == COLOR_TRANSFER_LINEAR ||
|| uEnableColorTransfer == GL_FALSE) { uEnableColorTransfer == GL_FALSE) {
return linearColor; return linearColor;
} else if (uOutputColorTransfer == COLOR_TRANSFER_SDR_VIDEO) { } else if (uOutputColorTransfer == COLOR_TRANSFER_SDR_VIDEO) {
return smpte170mOetf(linearColor); return smpte170mOetf(linearColor);
...@@ -131,8 +126,8 @@ highp vec3 applyOetf(highp vec3 linearColor) { ...@@ -131,8 +126,8 @@ highp vec3 applyOetf(highp vec3 linearColor) {
} }
} }
vec2 getAdjustedTexSamplingCoord(vec2 originalTexSamplingCoord){ vec2 getAdjustedTexSamplingCoord(vec2 originalTexSamplingCoord) {
if (uInputColorTransfer == COLOR_TRANSFER_SRGB){ if (uInputColorTransfer == COLOR_TRANSFER_SRGB) {
// Whereas the Android system uses the top-left corner as (0,0) of the // Whereas the Android system uses the top-left corner as (0,0) of the
// coordinate system, OpenGL uses the bottom-left corner as (0,0), so the // coordinate system, OpenGL uses the bottom-left corner as (0,0), so the
// texture gets flipped. We flip the texture vertically to ensure the // texture gets flipped. We flip the texture vertically to ensure the
...@@ -144,8 +139,8 @@ vec2 getAdjustedTexSamplingCoord(vec2 originalTexSamplingCoord){ ...@@ -144,8 +139,8 @@ vec2 getAdjustedTexSamplingCoord(vec2 originalTexSamplingCoord){
} }
void main() { void main() {
vec4 inputColor = texture2D( vec4 inputColor =
uTexSampler, getAdjustedTexSamplingCoord(vTexSamplingCoord)); texture2D(uTexSampler, getAdjustedTexSamplingCoord(vTexSamplingCoord));
vec3 linearInputColor = applyEotf(inputColor.rgb); vec3 linearInputColor = applyEotf(inputColor.rgb);
vec4 transformedColors = uRgbMatrix * vec4(linearInputColor, 1); vec4 transformedColors = uRgbMatrix * vec4(linearInputColor, 1);
......
...@@ -42,8 +42,7 @@ float smpte170mOetfSingleChannel(float opticalChannel) { ...@@ -42,8 +42,7 @@ float smpte170mOetfSingleChannel(float opticalChannel) {
// Transforms optical SDR colors to electrical SDR using the SMPTE 170M OETF. // Transforms optical SDR colors to electrical SDR using the SMPTE 170M OETF.
vec3 smpte170mOetf(vec3 opticalColor) { vec3 smpte170mOetf(vec3 opticalColor) {
return vec3( return vec3(smpte170mOetfSingleChannel(opticalColor.r),
smpte170mOetfSingleChannel(opticalColor.r),
smpte170mOetfSingleChannel(opticalColor.g), smpte170mOetfSingleChannel(opticalColor.g),
smpte170mOetfSingleChannel(opticalColor.b)); smpte170mOetfSingleChannel(opticalColor.b));
} }
...@@ -57,8 +56,7 @@ float gamma22OetfSingleChannel(highp float linearChannel) { ...@@ -57,8 +56,7 @@ float gamma22OetfSingleChannel(highp float linearChannel) {
// BT.709 gamma 2.2 OETF. // BT.709 gamma 2.2 OETF.
vec3 gamma22Oetf(highp vec3 linearColor) { vec3 gamma22Oetf(highp vec3 linearColor) {
return vec3( return vec3(gamma22OetfSingleChannel(linearColor.r),
gamma22OetfSingleChannel(linearColor.r),
gamma22OetfSingleChannel(linearColor.g), gamma22OetfSingleChannel(linearColor.g),
gamma22OetfSingleChannel(linearColor.b)); gamma22OetfSingleChannel(linearColor.b));
} }
......
...@@ -22,6 +22,7 @@ uniform mat4 uTexTransformationMatrix; ...@@ -22,6 +22,7 @@ uniform mat4 uTexTransformationMatrix;
varying vec2 vTexSamplingCoord; varying vec2 vTexSamplingCoord;
void main() { void main() {
gl_Position = uTransformationMatrix * aFramePosition; gl_Position = uTransformationMatrix * aFramePosition;
vec4 texturePosition = vec4(aFramePosition.x * 0.5 + 0.5, aFramePosition.y * 0.5 + 0.5, 0.0, 1.0); vec4 texturePosition = vec4(aFramePosition.x * 0.5 + 0.5,
aFramePosition.y * 0.5 + 0.5, 0.0, 1.0);
vTexSamplingCoord = (uTexTransformationMatrix * texturePosition).xy; vTexSamplingCoord = (uTexTransformationMatrix * texturePosition).xy;
} }
...@@ -22,6 +22,7 @@ uniform mat4 uTexTransformationMatrix; ...@@ -22,6 +22,7 @@ uniform mat4 uTexTransformationMatrix;
out vec2 vTexSamplingCoord; out vec2 vTexSamplingCoord;
void main() { void main() {
gl_Position = uTransformationMatrix * aFramePosition; gl_Position = uTransformationMatrix * aFramePosition;
vec4 texturePosition = vec4(aFramePosition.x * 0.5 + 0.5, aFramePosition.y * 0.5 + 0.5, 0.0, 1.0); vec4 texturePosition = vec4(aFramePosition.x * 0.5 + 0.5,
aFramePosition.y * 0.5 + 0.5, 0.0, 1.0);
vTexSamplingCoord = (uTexTransformationMatrix * texturePosition).xy; vTexSamplingCoord = (uTexTransformationMatrix * texturePosition).xy;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment