Porta tots els shaders a Vulkan i Metal

This commit is contained in:
2026-05-04 12:35:58 +02:00
parent 8d42d5741f
commit ef37a7a2e6
38 changed files with 2942 additions and 8 deletions

View File

@@ -0,0 +1,64 @@
#include <metal_stdlib>
using namespace metal;
// Remember — diatribes
// MSL port of remember.vk.glsl.
struct ShadertoyUBO {
float iTime;
float2 iResolution;
};
struct PassthroughVOut {
float4 pos [[position]];
float2 uv;
};
static float hash12(float2 p) {
float3 p3 = fract(float3(p.xyx) * 0.1031);
p3 += dot(p3, p3.yzx + 33.33);
return fract((p3.x + p3.y) * p3.z);
}
fragment float4 remember_fs(PassthroughVOut in [[stage_in]],
constant ShadertoyUBO& U [[buffer(0)]]) {
float2 fragCoord = in.uv * U.iResolution;
float2 u = fragCoord;
float3 q, p = float3(U.iResolution, U.iResolution.x / U.iResolution.y);
float i = 0.0, s = 0.0;
float d = 0.125 * hash12(u);
float t = U.iTime * 0.1;
u = (u + u - p.xy) / p.y;
if (abs(u.y) > 0.8) { return float4(0); }
float4 o = float4(0.0);
for (; i < 64.0; i++) {
q = p = float3(u * d, d + t * 5.0);
// mat2(cos(.1*p.z+.1*t+vec4(0,33,11,0))) — column-major: (m00,m10,m01,m11)
float4 cs = cos(0.1 * p.z + 0.1 * t + float4(0, 33, 11, 0));
float2x2 m = float2x2(cs.x, cs.y, cs.z, cs.w);
p.xy = p.xy * m;
q.xz = cos(q.xz);
p.z = cos(p.z);
for (s = 1.0; s++ < 6.0;) {
q += sin(0.6 * t + p.zxy * 0.6);
p += sin(t + t + p.yzx * s) * 0.6;
}
s = 0.02 + abs(min(length(p + 3.0 * sin(p.z * 0.5)) - 4.0, length(q - 2.0 * sin(p.z * 0.4)) - 6.0)) * 0.2;
d += s;
float4 brightTerm = min(0.01 * float4(6, 2, 1, 0) / max(length(u * sin(t + t + t)), 0.001), float4(50.0));
o += brightTerm + 1.0 / s * length(u);
}
o = tanh(max(o / 6e2 + dot(u, u) * 0.35, 0.0));
return o;
}

Binary file not shown.

View File

@@ -0,0 +1,61 @@
#version 450
// Name: Remember
// Author: diatribes
// URL: https://www.shadertoy.com/view/tXSBDK
layout(location = 0) in vec2 vUV;
layout(location = 0) out vec4 FragColor;
layout(set = 3, binding = 0) uniform ShadertoyUBO {
float iTime;
vec2 iResolution;
};
// fuzzy brain — Hash function to replace iChannel0 texture noise
float hash12(vec2 p) {
vec3 p3 = fract(vec3(p.xyx) * .1031);
p3 += dot(p3, p3.yzx + 33.33);
return fract((p3.x + p3.y) * p3.z);
}
void mainImage(out vec4 o, vec2 u) {
vec3 q, p = vec3(iResolution.xy, iResolution.x / iResolution.y);
float i = 0.0, s,
d = .125 * hash12(u),
t = iTime * .1;
u = (u + u - p.xy) / p.y;
if (abs(u.y) > .8) { o = vec4(0); return; }
o = vec4(0.0);
for (; i < 64.; i++) {
q = p = vec3(u * d, d + t * 5.);
p.xy *= mat2(cos(.1 * p.z + .1 * t + vec4(0, 33, 11, 0)));
q.xz = cos(q.xz);
p.z = cos(p.z);
for (s = 1.; s++ < 6.;
q += sin(.6 * t + p.zxy * .6),
p += sin(t + t + p.yzx * s) * .6);
d += s = .02 + abs(min(length(p + 3. * sin(p.z * .5)) - 4., length(q - 2. * sin(p.z * .4)) - 6.)) * .2;
vec4 brightTerm = min(.01 * vec4(6, 2, 1, 0) / max(length(u * sin(t + t + t)), 0.001), vec4(50.0));
o += brightTerm + 1. / s * length(u);
}
o = tanh(max(o / 6e2 + dot(u, u) * .35, 0.));
}
void main() {
vec2 fragCoordPixels = vUV * iResolution;
vec4 outColor;
mainImage(outColor, fragCoordPixels);
FragColor = outColor;
}