1#version 300 es 2// Copyright 2022 The Android Open Source Project 3// 4// Licensed under the Apache License, Version 2.0 (the "License"); 5// you may not use this file except in compliance with the License. 6// You may obtain a copy of the License at 7// 8// http://www.apache.org/licenses/LICENSE-2.0 9// 10// Unless required by applicable law or agreed to in writing, software 11// distributed under the License is distributed on an "AS IS" BASIS, 12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13// See the License for the specific language governing permissions and 14// limitations under the License. 15 16// ES 3 fragment shader that samples from an external texture with uTexSampler, 17// copying from this texture to the current output while applying the specified 18// color transform uColorTransform, which should be a YUV to RGB conversion 19// matrix. The sampler uses the using the EXT_YUV_target extension: 20// https://www.khronos.org/registry/OpenGL/extensions/EXT/EXT_YUV_target.txt. 21 22#extension GL_OES_EGL_image_external : require 23#extension GL_EXT_YUV_target : require 24precision mediump float; 25uniform __samplerExternal2DY2YEXT uTexSampler; 26uniform mat3 uColorTransform; 27in vec2 vTexSamplingCoord; 28out vec4 outColor; 29void main() { 30 vec3 srcYuv = texture(uTexSampler, vTexSamplingCoord).xyz; 31 vec3 yuvOffset; 32 yuvOffset.x = srcYuv.r - 0.0625; 33 yuvOffset.y = srcYuv.g - 0.5; 34 yuvOffset.z = srcYuv.b - 0.5; 35 outColor = vec4(uColorTransform * yuvOffset, 1.0); 36} 37