effect: use constants for error colors in shaders

PiperOrigin-RevId: 630194321
This commit is contained in:
tofunmi 2024-05-02 15:19:41 -07:00 committed by Copybara-Service
parent d59f1cb6e3
commit 620cb32667
7 changed files with 45 additions and 46 deletions

View File

@ -31,8 +31,8 @@ uniform int uOutputColorTransfer;
uniform mat3 uColorTransform;
uniform mat4 uRgbMatrix;
// TODO(b/227624622): Consider using mediump to save precision, if it won't lead
// to noticeable quantization.
// Output color for an obviously visible error.
const vec3 ERROR_COLOR_RED = vec3(1.0, 0.0, 0.0);
// HLG OETF for one channel.
highp float hlgOetfSingleChannel(highp float linearChannel) {
@ -83,8 +83,7 @@ highp vec3 applyOetf(highp vec3 linearColor) {
} else if (uOutputColorTransfer == COLOR_TRANSFER_HLG) {
return hlgOetf(linearColor);
} else {
// Output red as an obviously visible error.
return vec3(1.0, 0.0, 0.0);
return ERROR_COLOR_RED;
}
}

View File

@ -64,8 +64,10 @@ const mat3 XYZ_TO_RGB_BT709 =
mat3(3.24096994f, -0.96924364f, 0.05563008f, -1.53738318f, 1.87596750f,
-0.20397696f, -0.49861076f, 0.04155506f, 1.05697151f);
// TODO(b/227624622): Consider using mediump to save precision, if it won't lead
// to noticeable quantization errors.
// Output colors for an obviously visible error.
const vec3 ERROR_COLOR_RED = vec3(1.0, 0.0, 0.0);
const vec3 ERROR_COLOR_GREEN = vec3(0.0, 1.0, 0.0);
const vec3 ERROR_COLOR_BLUE = vec3(0.0, 0.0, 1.0);
// BT.2100 / BT.2020 HLG EOTF for one channel.
highp float hlgEotfSingleChannel(highp float hlgChannel) {
@ -112,8 +114,7 @@ highp vec3 applyEotf(highp vec3 electricalColor) {
} else if (uInputColorTransfer == COLOR_TRANSFER_HLG) {
return hlgEotf(electricalColor);
} else {
// Output red as an obviously visible error.
return vec3(1.0, 0.0, 0.0);
return ERROR_COLOR_RED;
}
}
@ -206,8 +207,7 @@ highp vec3 applyBt2020ToBt709Ootf(highp vec3 linearRgbBt2020) {
} else if (uInputColorTransfer == COLOR_TRANSFER_HLG) {
return applyHlgBt2020ToBt709Ootf(linearRgbBt2020);
} else {
// Output green as an obviously visible error.
return vec3(0.0, 1.0, 0.0);
return ERROR_COLOR_GREEN;
}
}
@ -275,8 +275,7 @@ highp vec3 applyOetf(highp vec3 linearColor) {
} else if (uOutputColorTransfer == COLOR_TRANSFER_LINEAR) {
return linearColor;
} else {
// Output blue as an obviously visible error.
return vec3(0.0, 0.0, 1.0);
return ERROR_COLOR_BLUE;
}
}

View File

@ -56,8 +56,10 @@ const mat3 XYZ_TO_RGB_BT709 =
mat3(3.24096994f, -0.96924364f, 0.05563008f, -1.53738318f, 1.87596750f,
-0.20397696f, -0.49861076f, 0.04155506f, 1.05697151f);
// TODO(b/227624622): Consider using mediump to save precision, if it won't lead
// to noticeable quantization errors.
// Output colors for an obviously visible error.
const vec3 ERROR_COLOR_RED = vec3(1.0, 0.0, 0.0);
const vec3 ERROR_COLOR_GREEN = vec3(0.0, 1.0, 0.0);
const vec3 ERROR_COLOR_BLUE = vec3(0.0, 0.0, 1.0);
// BT.2100 / BT.2020 HLG EOTF for one channel.
highp float hlgEotfSingleChannel(highp float hlgChannel) {
@ -104,8 +106,7 @@ highp vec3 applyEotf(highp vec3 electricalColor) {
} else if (uInputColorTransfer == COLOR_TRANSFER_HLG) {
return hlgEotf(electricalColor);
} else {
// Output red as an obviously visible error.
return vec3(1.0, 0.0, 0.0);
return ERROR_COLOR_RED;
}
}
@ -198,8 +199,7 @@ highp vec3 applyBt2020ToBt709Ootf(highp vec3 linearRgbBt2020) {
} else if (uInputColorTransfer == COLOR_TRANSFER_HLG) {
return applyHlgBt2020ToBt709Ootf(linearRgbBt2020);
} else {
// Output green as an obviously visible error.
return vec3(0.0, 1.0, 0.0);
return ERROR_COLOR_GREEN;
}
}
@ -267,8 +267,7 @@ highp vec3 applyOetf(highp vec3 linearColor) {
} else if (uOutputColorTransfer == COLOR_TRANSFER_LINEAR) {
return linearColor;
} else {
// Output blue as an obviously visible error.
return vec3(0.0, 0.0, 1.0);
return ERROR_COLOR_BLUE;
}
}

View File

@ -41,6 +41,10 @@ const int WORKING_COLOR_SPACE_DEFAULT = 0;
const int WORKING_COLOR_SPACE_ORIGINAL = 1;
const int WORKING_COLOR_SPACE_LINEAR = 2;
// Output colors for an obviously visible error.
const vec3 ERROR_COLOR_BLUE = vec3(0.0, 0.0, 1.0);
const vec3 ERROR_COLOR_RED = vec3(1.0, 0.0, 0.0);
// Transforms a single channel from electrical to optical SDR using the SMPTE
// 170M OETF.
float smpte170mEotfSingleChannel(float electricalChannel) {
@ -84,8 +88,7 @@ vec3 convertToWorkingColors(vec3 inputColor) {
} else if (uSdrWorkingColorSpace == WORKING_COLOR_SPACE_LINEAR) {
return smpte170mEotf(inputColor);
} else {
// Output blue as an obviously visible error.
return vec3(0.0, 0.0, 1.0);
return ERROR_COLOR_BLUE;
}
}
@ -101,8 +104,7 @@ highp vec3 convertToOutputColors(highp vec3 workingColors) {
} else if (uOutputColorTransfer == COLOR_TRANSFER_SDR_VIDEO) {
return workingColors;
} else {
// Output red as an obviously visible error.
return vec3(1.0, 0.0, 0.0);
return ERROR_COLOR_RED;
}
} else if (uSdrWorkingColorSpace == WORKING_COLOR_SPACE_ORIGINAL) {
return workingColors;
@ -112,12 +114,10 @@ highp vec3 convertToOutputColors(highp vec3 workingColors) {
} else if (uOutputColorTransfer == COLOR_TRANSFER_SDR_VIDEO) {
return smpte170mOetf(workingColors);
} else {
// Output red as an obviously visible error.
return vec3(1.0, 0.0, 0.0);
return ERROR_COLOR_RED;
}
} else {
// Output red as an obviously visible error.
return vec3(1.0, 0.0, 0.0);
return ERROR_COLOR_RED;
}
}

View File

@ -48,6 +48,10 @@ const int WORKING_COLOR_SPACE_DEFAULT = 0;
const int WORKING_COLOR_SPACE_ORIGINAL = 1;
const int WORKING_COLOR_SPACE_LINEAR = 2;
// Output colors for an obviously visible error.
const vec3 ERROR_COLOR_RED = vec3(1.0, 0.0, 0.0);
const vec3 ERROR_COLOR_BLUE = vec3(0.0, 0.0, 1.0);
// Transforms a single channel from electrical to optical SDR using the sRGB
// EOTF.
float srgbEotfSingleChannel(float electricalChannel) {
@ -108,8 +112,7 @@ vec3 convertToWorkingColors(vec3 inputColor) {
} else if (uInputColorTransfer == COLOR_TRANSFER_SDR_VIDEO) {
return inputColor;
} else {
// Output blue as an obviously visible error.
return vec3(0.0, 0.0, 1.0);
return ERROR_COLOR_BLUE;
}
} else if (uSdrWorkingColorSpace == WORKING_COLOR_SPACE_ORIGINAL) {
return inputColor;
@ -119,12 +122,10 @@ vec3 convertToWorkingColors(vec3 inputColor) {
} else if (uInputColorTransfer == COLOR_TRANSFER_SDR_VIDEO) {
return smpte170mEotf(inputColor);
} else {
// Output blue as an obviously visible error.
return vec3(0.0, 0.0, 1.0);
return ERROR_COLOR_BLUE;
}
} else {
// Output blue as an obviously visible error.
return vec3(0.0, 0.0, 1.0);
return ERROR_COLOR_BLUE;
}
}
@ -137,8 +138,7 @@ highp vec3 convertToOutputColors(highp vec3 workingColors) {
} else if (uOutputColorTransfer == COLOR_TRANSFER_SDR_VIDEO) {
return workingColors;
} else {
// Output red as an obviously visible error.
return vec3(1.0, 0.0, 0.0);
return ERROR_COLOR_RED;
}
} else if (uSdrWorkingColorSpace == WORKING_COLOR_SPACE_ORIGINAL) {
return workingColors;
@ -148,12 +148,10 @@ highp vec3 convertToOutputColors(highp vec3 workingColors) {
} else if (uOutputColorTransfer == COLOR_TRANSFER_SDR_VIDEO) {
return smpte170mOetf(workingColors);
} else {
// Output red as an obviously visible error.
return vec3(1.0, 0.0, 0.0);
return ERROR_COLOR_RED;
}
} else {
// Output red as an obviously visible error.
return vec3(1.0, 0.0, 0.0);
return ERROR_COLOR_RED;
}
}

View File

@ -28,6 +28,9 @@ varying vec2 vTexSamplingCoord;
// Only COLOR_TRANSFER_SDR and COLOR_TRANSFER_GAMMA_2_2 are allowed.
uniform int uOutputColorTransfer;
// Output color for an obviously visible error.
const vec3 ERROR_COLOR_RED = vec3(1.0, 0.0, 0.0);
const float inverseGamma = 0.4500;
// Transforms a single channel from optical to electrical SDR using the SMPTE
@ -72,8 +75,7 @@ highp vec3 applyOetf(highp vec3 linearColor) {
} else if (uOutputColorTransfer == COLOR_TRANSFER_GAMMA_2_2) {
return gamma22Oetf(linearColor);
} else {
// Output red as an obviously visible error.
return vec3(1.0, 0.0, 0.0);
return ERROR_COLOR_RED;
}
}

View File

@ -30,8 +30,8 @@ uniform sampler2D uTexSampler;
uniform sampler2D uGainmapTexSampler;
uniform mat4 uRgbMatrix;
// C.java#ColorTransfer value.
// Only COLOR_TRANSFER_LINEAR, COLOR_TRANSFER_GAMMA_2_2, COLOR_TRANSFER_ST2084,
// and COLOR_TRANSFER_HLG are allowed.
// Only COLOR_TRANSFER_LINEAR, COLOR_TRANSFER_HLG, COLOR_TRANSFER_ST2084,
// are allowed.
uniform int uOutputColorTransfer;
// Uniforms for applying gainmap to base.
@ -63,6 +63,9 @@ const int COLOR_TRANSFER_GAMMA_2_2 = 10;
const int COLOR_TRANSFER_ST2084 = 6;
const int COLOR_TRANSFER_HLG = 7;
// Output color for an obviously visible error.
const vec3 ERROR_COLOR_BLUE = vec3(0.0, 0.0, 1.0);
// Matrix values based on computeXYZMatrix(BT2020Primaries, BT2020WhitePoint)
// https://cs.android.com/android/platform/superproject/main/+/main:frameworks/native/libs/ui/ColorSpace.cpp;l=199-231;drc=ea6c713503b283eef9e6cd1d6674228f6a81d762
const mat3 RGB_BT2020_TO_XYZ =
@ -171,8 +174,7 @@ highp vec3 applyOetf(highp vec3 linearColor) {
} else if (uOutputColorTransfer == COLOR_TRANSFER_LINEAR) {
return linearColor;
} else {
// Output blue as an obviously visible error.
return vec3(0.0, 0.0, 1.0);
return ERROR_COLOR_BLUE;
}
}