导航菜单

页面标题

页面副标题

Kreate v1.5.0 - MeshGradient.java 源代码

正在查看: Kreate v1.5.0 应用的 MeshGradient.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.mikepenz.hypnoticcanvas.shaders;

import androidx.compose.ui.graphics.Color;
import com.mikepenz.hypnoticcanvas.RuntimeEffect;
import com.mikepenz.hypnoticcanvas.shaders.Shader;
import java.util.ArrayList;
import kotlin.Metadata;
import kotlin.collections.ArraysKt;
import kotlin.collections.CollectionsKt;
import kotlin.jvm.internal.DefaultConstructorMarker;
import kotlin.jvm.internal.Intrinsics;

@Metadata(d1 = {"\u0000>\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u0011\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u0007\n\u0002\b\u0004\n\u0002\u0010\b\n\u0000\n\u0002\u0010\u0014\n\u0000\n\u0002\u0010\u000e\n\u0002\b\u000f\n\u0002\u0010\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0004\b\u0007\u0018\u00002\u00020\u0001B)\u0012\f\u0010\u0002\u001a\b\u0012\u0004\u0012\u00020\u00040\u0003\u0012\b\b\u0002\u0010\u0005\u001a\u00020\u0006\u0012\b\b\u0002\u0010\u0007\u001a\u00020\u0006¢\u0006\u0004\b\b\u0010\tJ(\u0010\u001e\u001a\u00020\u001f2\u0006\u0010 \u001a\u00020!2\u0006\u0010\"\u001a\u00020\u00062\u0006\u0010#\u001a\u00020\u00062\u0006\u0010$\u001a\u00020\u0006H\u0016R\u000e\u0010\n\u001a\u00020\u000bX\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\f\u001a\u00020\rX\u0082\u0004¢\u0006\u0002\n\u0000R\u0014\u0010\u000e\u001a\u00020\u000f8VX\u0096\u0004¢\u0006\u0006\u001a\u0004\b\u0010\u0010\u0011R\u0014\u0010\u0012\u001a\u00020\u000f8VX\u0096\u0004¢\u0006\u0006\u001a\u0004\b\u0013\u0010\u0011R\u0014\u0010\u0014\u001a\u00020\u000f8VX\u0096\u0004¢\u0006\u0006\u001a\u0004\b\u0015\u0010\u0011R\u0014\u0010\u0016\u001a\u00020\u000f8VX\u0096\u0004¢\u0006\u0006\u001a\u0004\b\u0017\u0010\u0011R\u0014\u0010\u0018\u001a\u00020\u000f8VX\u0096\u0004¢\u0006\u0006\u001a\u0004\b\u0019\u0010\u0011R\u0014\u0010\u001a\u001a\u00020\u000f8VX\u0096\u0004¢\u0006\u0006\u001a\u0004\b\u001b\u0010\u0011R\u0014\u0010\u001c\u001a\u00020\u000fX\u0096\u0004¢\u0006\b\n\u0000\u001a\u0004\b\u001d\u0010\u0011¨\u0006%"}, d2 = {"Lcom/mikepenz/hypnoticcanvas/shaders/MeshGradient;", "Lcom/mikepenz/hypnoticcanvas/shaders/Shader;", "colors", "", "Landroidx/compose/ui/graphics/Color;", "speed", "", "scale", "<init>", "([Landroidx/compose/ui/graphics/Color;FF)V", "colorCount", "", "colorUniforms", "", "name", "", "getName", "()Ljava/lang/String;", "authorName", "getAuthorName", "authorUrl", "getAuthorUrl", "credit", "getCredit", "license", "getLicense", "licenseUrl", "getLicenseUrl", "sksl", "getSksl", "applyUniforms", "", "runtimeEffect", "Lcom/mikepenz/hypnoticcanvas/RuntimeEffect;", "time", "width", "height", "hypnoticcanvas_release"}, k = 1, mv = {2, 0, 0}, xi = 48)
public final class MeshGradient implements Shader {
    public static final int $stable = 8;
    private final int colorCount;
    private final float[] colorUniforms;
    private final String sksl;

    public MeshGradient(Color[] colorArr, float f, float f2) {
        Intrinsics.checkNotNullParameter(colorArr, "colors");
        this.colorCount = colorArr.length;
        ArrayList arrayList = new ArrayList();
        for (Color color : colorArr) {
            long j = color.unbox-impl();
            CollectionsKt.addAll(arrayList, CollectionsKt.listOf(new Float[]{Float.valueOf(Color.getRed-impl(j)), Float.valueOf(Color.getGreen-impl(j)), Float.valueOf(Color.getBlue-impl(j))}));
        }
        this.colorUniforms = ArraysKt.toFloatArray((Float[]) arrayList.toArray(new Float[0]));
        this.sksl = "\nuniform float uTime;\nuniform vec3 uResolution;\n\nvec3 vColor;\nconst int MAX_COLORS = " + this.colorCount + ";\nuniform vec3 uColor[MAX_COLORS];\n\n//\tSimplex 3D Noise \n//\tby Ian McEwan, Ashima Arts\n//  https://gist.github.com/patriciogonzalezvivo/670c22f3966e662d2f83\n//\nvec4 permute(vec4 x) {\n    return mod(((x * 34.0) + 1.0) * x, 289.0);\n}\nvec4 taylorInvSqrt(vec4 r) {\n    return 1.79284291400159 - 0.85373472095314 * r;\n}\n\nfloat snoise(vec3 v) {\n    const vec2 C = vec2(1.0 / 6.0, 1.0 / 3.0);\n    const vec4 D = vec4(0.0, 0.5, 1.0, 2.0);\n\n    // First corner\n    vec3 i = floor(v + dot(v, C.yyy));\n    vec3 x0 = v - i + dot(i, C.xxx);\n\n    // Other corners\n    vec3 g = step(x0.yzx, x0.xyz);\n    vec3 l = 1.0 - g;\n    vec3 i1 = min(g.xyz, l.zxy);\n    vec3 i2 = max(g.xyz, l.zxy);\n\n    //  x0 = x0 - 0. + 0.0 * C \n    vec3 x1 = x0 - i1 + 1.0 * C.xxx;\n    vec3 x2 = x0 - i2 + 2.0 * C.xxx;\n    vec3 x3 = x0 - 1. + 3.0 * C.xxx;\n\n    // Permutations\n    i = mod(i, 289.0);\n    vec4 p = permute(permute(permute(i.z + vec4(0.0, i1.z, i2.z, 1.0)) + i.y + vec4(0.0, i1.y, i2.y, 1.0)) + i.x + vec4(0.0, i1.x, i2.x, 1.0));\n\n    // Gradients\n    // ( N*N points uniformly over a square, mapped onto an octahedron.)\n    float n_ = 1.0 / 7.0; // N=7\n    vec3 ns = n_ * D.wyz - D.xzx;\n\n    vec4 j = p - 49.0 * floor(p * ns.z * ns.z);  //  mod(p,N*N)\n\n    vec4 x_ = floor(j * ns.z);\n    vec4 y_ = floor(j - 7.0 * x_);    // mod(j,N)\n\n    vec4 x = x_ * ns.x + ns.yyyy;\n    vec4 y = y_ * ns.x + ns.yyyy;\n    vec4 h = 1.0 - abs(x) - abs(y);\n\n    vec4 b0 = vec4(x.xy, y.xy);\n    vec4 b1 = vec4(x.zw, y.zw);\n\n    vec4 s0 = floor(b0) * 2.0 + 1.0;\n    vec4 s1 = floor(b1) * 2.0 + 1.0;\n    vec4 sh = -step(h, vec4(0.0));\n\n    vec4 a0 = b0.xzyw + s0.xzyw * sh.xxyy;\n    vec4 a1 = b1.xzyw + s1.xzyw * sh.zzww;\n\n    vec3 p0 = vec3(a0.xy, h.x);\n    vec3 p1 = vec3(a0.zw, h.y);\n    vec3 p2 = vec3(a1.xy, h.z);\n    vec3 p3 = vec3(a1.zw, h.w);\n\n    //Normalise gradients\n    vec4 norm = taylorInvSqrt(vec4(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3)));\n    p0 *= norm.x;\n    p1 *= norm.y;\n    p2 *= norm.z;\n    p3 *= norm.w;\n\n    // Mix final noise value\n    vec4 m = max(0.6 - vec4(dot(x0, x0), dot(x1, x1), dot(x2, x2), dot(x3, x3)), 0.0);\n    m = m * m;\n    return 42.0 * dot(m * m, vec4(dot(p0, x0), dot(p1, x1), dot(p2, x2), dot(p3, x3)));\n}\n\n// Author       : Johnny Leek\n// https://github.com/JohnnyLeek1/React-Mesh-Gradient\n// Inspiration  : Yuri Artiukh\nvec4 main( vec2 fragCoord ) {\n    float mr = min(uResolution.x, uResolution.y);\n    vec2 uv = (fragCoord * " + f2 + " - uResolution.xy) / mr;\n\n    // Calculate base coordinate position\n    vec2 base = uv / 2;\n\n    // Apply slight tilt + incline\n    float tilt = -0.5 * uv.y;\n    float incline = uv.x * 0.1;\n\n    // Apply slight offset between -0.25 and 0.25 of the y position\n    float offset = incline * mix(-.25, 0.25, uv.y);\n\n    // Calculate noise based on base position\n    float noise = snoise(vec3(base.x + uTime * 0.2, base.y, uTime * 0.2));\n\n    // Ignore negative noise values\n    noise = max(0., noise);\n\n    // Calculate final position\n    vec3 pos = vec3(uResolution.x, uResolution.y, uResolution.z + noise * 0.1 + tilt + incline + offset);\n\n    // Set base color to the last color in our array\n    vColor = uColor[MAX_COLORS - 1];\n\n    // Iterate through the other colors in the array\n    for(int i = 0; i < MAX_COLORS - 1; i++) {\n        // Calculate some more noise values to use for the color\n        float flow = 5. + float(i) * 0.3;\n        float speed = 6. * " + f + " + float(i) * 0.3;\n        float seed = 1. + float(i) * 4.;\n\n        vec2 frequency = vec2(0.3, 0.7);\n\n        // Create min and max values for our noise (based on the current color index)\n        float noiseFloor = 0.00001;\n        float noiseCeil = 0.6 + float(i) * 0.07;\n\n        // Calculate noise\n        float noise = smoothstep(noiseFloor, noiseCeil, snoise(vec3(base.x * frequency.x + uTime * 0.005 * flow, base.y * frequency.y, uTime * 0.005 * speed + seed)));\n\n        // Mix the color with the base color based on our noise\n        vColor = mix(vColor, uColor[i], noise);\n    }\n\n    // Set the new uV and position of the vertex\n    return vec4(vColor, 1.0);\n}\n    ";
    }

    public MeshGradient(Color[] colorArr, float f, float f2, int i, DefaultConstructorMarker defaultConstructorMarker) {
        this(colorArr, (i & 2) != 0 ? 1.0f : f, (i & 4) != 0 ? 2.0f : f2);
    }

    @Override
    public float getSpeedModifier() {
        return Shader.DefaultImpls.getSpeedModifier(this);
    }

    @Override
    public String getName() {
        return "MeshGradient";
    }

    @Override
    public String getAuthorName() {
        return "Mike Penz";
    }

    @Override
    public String getAuthorUrl() {
        return "https://github.com/mikepenz/";
    }

    @Override
    public String getCredit() {
        return "";
    }

    @Override
    public String getLicense() {
        return "MIT License";
    }

    @Override
    public String getLicenseUrl() {
        return "https://opensource.org/license/mit";
    }

    @Override
    public String getSksl() {
        return this.sksl;
    }

    @Override
    public void applyUniforms(RuntimeEffect runtimeEffect, float time, float width, float height) {
        Intrinsics.checkNotNullParameter(runtimeEffect, "runtimeEffect");
        Shader.DefaultImpls.applyUniforms(this, runtimeEffect, time, width, height);
        runtimeEffect.setFloatUniform("uColor", this.colorUniforms);
    }
}