diff options
Diffstat (limited to 'weathereffects/assets/shaders/utils.agsl')
-rw-r--r-- | weathereffects/assets/shaders/utils.agsl | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/weathereffects/assets/shaders/utils.agsl b/weathereffects/assets/shaders/utils.agsl new file mode 100644 index 0000000..ffc651a --- /dev/null +++ b/weathereffects/assets/shaders/utils.agsl @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +highp float idGenerator(vec2 point) { + vec2 p = fract(point * vec2(723.123, 236.209)); + p += dot(p, p + 17.1512); + return fract(p.x * p.y); +} + +highp float idGenerator(float value) { + return idGenerator(vec2(value, 1.412)); +} + +mat2 rotationMat(float angleRad) { + float c=cos(angleRad); + float s=sin(angleRad); + // | c -s | + // | s c | + return mat2( + c, s, // First column. + -s, c // second column. + ); +} + +vec2 rotateAroundPoint(vec2 point, vec2 centerPoint, float angleRad) { + return (point - centerPoint) * rotationMat(angleRad) + centerPoint; +} + +// function created on Grapher (equation decided by testing in Grapher). +float wiggle(float time, float wiggleSpeed) { + return sin(wiggleSpeed * time + 0.5 * sin(wiggleSpeed * 5. * time)) + * sin(wiggleSpeed * time) - 0.5; +} + +// Noise range of [-1.0, 1.0[ with triangle distribution. +float triangleNoise(vec2 n) { + n = fract(n * vec2(5.3987, 5.4421)); + n += dot(n.yx, n.xy + vec2(21.5351, 14.3137)); + float xy = n.x * n.y; + // compute in [0..2[ and remap to [-1.0..1.0[ + return fract(xy * 95.4307) + fract(xy * 75.04961) - 1.0; +} + +/* + * This is the normal blend mode in which the foreground is painted on top of the background based + * on the foreground opacity. + * + * @param b the background color. + * @param f the foreground color. + * @param o the mask or the foreground alpha. + * + * Note: this blending function expects the foreground to have premultiplied alpha. + */ +vec3 normalBlend(vec3 b, vec3 f, float o) { + return b * (1. - o) + f; +} + +vec3 normalBlendWithWhiteSrc(vec3 b, float o) { + return b * (1. - o) + o; +} |