1/* 2 * Copyright (C) 2024 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 17uniform shader texture; 18uniform half thickness; 19 20/** 21 * Returns whether the current fragcoord lies on the outline, return range [0, 1]. 22 * 0 = no outline, 1 = outline 23 * This assumes that the given texture has a transparent background and evaluates whether it's an 24 * outline with finite differencing. 25 */ 26vec4 main(float2 fragCoord) { 27 float aN = texture.eval(fragCoord + vec2(0., thickness)).a; 28 float aS = texture.eval(fragCoord + vec2(0., -thickness)).a; 29 float dY = (aN - aS) * 0.5; 30 dY = max(dY, 0.0); 31 32 half outline = smoothstep(0.1, 1.8, dY * 5.0); 33 34 // Return the results in the R channel. 35 // Also return alpha 1 avoid visual artifacts when it is used standalone. 36 return vec4(outline, 0., 0., 1.); 37} 38