+#if defined(IS_REQUIRED_YUV_TO_RGB) || defined(IS_REQUIRED_UNIFIED_YUV_AND_RGB)
+lowp vec4 ConvertYuvToRgba(mediump vec2 texCoord)
+{
+#ifdef IS_REQUIRED_UNIFIED_YUV_AND_RGB
+ // Special case when shader use YUV but actual textures are not YUV format.
+ // In this case, just resturn sTexture.
+ if(textureSize(sTextureU, 0) != textureSize(sTextureV, 0))
+ {
+ return texture(sTexture, texCoord);
+ }
+#endif
+
+ lowp float y = texture(sTexture, texCoord).r;
+ lowp float u = texture(sTextureU, texCoord).r - 0.5;
+ lowp float v = texture(sTextureV, texCoord).r - 0.5;
+ lowp vec4 rgba;
+ rgba.r = y + (1.403 * v);
+ rgba.g = y - (0.344 * u) - (0.714 * v);
+ rgba.b = y + (1.770 * u);
+ rgba.a = 1.0;
+ return rgba;
+}
+#endif
+
+#ifdef IS_REQUIRED_DEBUG_VISUAL_SHADER
+
+// Predefined values whether some macro defined or not.
+// Since we make debug codes replace by macro,
+// sharp if keyword cannot be used.
+// Instead, let we use bool values so we can use define checked in script
+#ifdef IS_REQUIRED_ROUNDED_CORNER
+const bool IS_REQUIRED_ROUNDED_CORNER_BOOL = true;
+#else
+const bool IS_REQUIRED_ROUNDED_CORNER_BOOL = false;
+#endif
+#ifdef IS_REQUIRED_BORDERLINE
+const bool IS_REQUIRED_BORDERLINE_BOOL = true;
+#else
+const bool IS_REQUIRED_BORDERLINE_BOOL = false;
+#endif
+#ifdef IS_REQUIRED_YUV_TO_RGB
+const bool IS_REQUIRED_YUV_TO_RGB_BOOL = true;
+#else
+const bool IS_REQUIRED_YUV_TO_RGB_BOOL = false;
+#endif
+#ifdef IS_REQUIRED_UNIFIED_YUV_AND_RGB
+const bool IS_REQUIRED_UNIFIED_YUV_AND_RGB_BOOL = true;
+#else
+const bool IS_REQUIRED_UNIFIED_YUV_AND_RGB_BOOL = false;
+#endif
+#ifdef IS_REQUIRED_ALPHA_MASKING
+const bool IS_REQUIRED_ALPHA_MASKING_BOOL = true;
+#else
+const bool IS_REQUIRED_ALPHA_MASKING_BOOL = false;
+#endif
+#ifdef ATLAS_DEFAULT_WARP
+const bool ATLAS_DEFAULT_WARP_BOOL = true;
+#else
+const bool ATLAS_DEFAULT_WARP_BOOL = false;
+#endif
+#ifdef ATLAS_CUSTOM_WARP
+const bool ATLAS_CUSTOM_WARP_BOOL = true;
+#else
+const bool ATLAS_CUSTOM_WARP_BOOL = false;
+#endif
+
+// These lines in the shader may be replaced with actual definitions by the debug-image-visual-shader-script.json.
+// DEBUG_TRIGGER_CODE return bool type, and DEBUG_RATIO_CODE return float value which will be clamped between 0.0 and 1.0
+// If DEBUG_TRIGGER_CODE return true, it mean we will change final color's channel value.
+// If ratio is 0.0, debug color rate become MINIMUM_DEBUG_COLOR_RATE, and 1.0 than MAXIMUM_DEBUG_COLOR_RATE.
+#define MINIMUM_DEBUG_COLOR_RATE
+#define MAXIMUM_DEBUG_COLOR_RATE
+#define DEBUG_TRIGGER_RED_CODE
+#define DEBUG_TRIGGER_GREEN_CODE
+#define DEBUG_TRIGGER_BLUE_CODE
+#define DEBUG_RATIO_RED_CODE
+#define DEBUG_RATIO_GREEN_CODE
+#define DEBUG_RATIO_BLUE_CODE
+#define DEBUG_EXTRA_UNIFORMS
+
+DEBUG_EXTRA_UNIFORMS
+
+const mediump float gMinDebugColorRate = MINIMUM_DEBUG_COLOR_RATE;
+const mediump float gMaxDebugColorRate = MAXIMUM_DEBUG_COLOR_RATE;
+
+bool DebugTriggerRed(mediump vec4 originColor)
+{
+ DEBUG_TRIGGER_RED_CODE
+}
+
+bool DebugTriggerGreen(mediump vec4 originColor)
+{
+ DEBUG_TRIGGER_GREEN_CODE
+}
+
+bool DebugTriggerBlue(mediump vec4 originColor)
+{
+ DEBUG_TRIGGER_BLUE_CODE
+}
+
+mediump float DebugRatioRed(mediump vec4 originColor)
+{
+ DEBUG_RATIO_RED_CODE
+}
+
+mediump float DebugRatioGreen(mediump vec4 originColor)
+{
+ DEBUG_RATIO_GREEN_CODE
+}
+
+mediump float DebugRatioBlue(mediump vec4 originColor)
+{
+ DEBUG_RATIO_BLUE_CODE
+}
+
+mediump vec3 ApplyDebugMixColor(mediump vec4 originColor)
+{
+ mediump float debugColorRateRed = 0.0;
+ mediump float debugColorRateGreen = 0.0;
+ mediump float debugColorRateBlue = 0.0;
+
+ if(DebugTriggerRed(originColor))
+ {
+ debugColorRateRed = mix(gMinDebugColorRate, gMaxDebugColorRate, smoothstep(0.0, 1.0, DebugRatioRed(originColor)));
+ }
+ if(DebugTriggerGreen(originColor))
+ {
+ debugColorRateGreen = mix(gMinDebugColorRate, gMaxDebugColorRate, smoothstep(0.0, 1.0, DebugRatioGreen(originColor)));
+ }
+ if(DebugTriggerBlue(originColor))
+ {
+ debugColorRateBlue = mix(gMinDebugColorRate, gMaxDebugColorRate, smoothstep(0.0, 1.0, DebugRatioBlue(originColor)));
+ }
+
+ mediump float colorRate = max(debugColorRateRed, max(debugColorRateGreen, debugColorRateBlue));
+ mediump vec3 debugColor = vec3(debugColorRateRed, debugColorRateGreen, debugColorRateBlue);
+
+ debugColor *= mix(1.0, originColor.a, preMultipliedAlpha);
+
+ return originColor.rgb * (1.0 - colorRate) + debugColor;
+}
+#endif
+