2023-11-22 15:25:36 +01:00
|
|
|
//Shard noise
|
|
|
|
//By ENDESGA
|
|
|
|
|
|
|
|
varying vec2 v_vTexcoord;
|
|
|
|
varying vec4 v_vColour;
|
|
|
|
|
|
|
|
uniform float seed;
|
2023-12-23 12:59:21 +01:00
|
|
|
|
|
|
|
uniform vec2 progress;
|
|
|
|
uniform int progressUseSurf;
|
|
|
|
uniform sampler2D progressSurf;
|
|
|
|
float prog;
|
|
|
|
|
|
|
|
uniform vec2 sharpness;
|
|
|
|
uniform int sharpnessUseSurf;
|
|
|
|
uniform sampler2D sharpnessSurf;
|
|
|
|
float sharp;
|
|
|
|
|
|
|
|
uniform vec2 scale;
|
|
|
|
uniform int scaleUseSurf;
|
|
|
|
uniform sampler2D scaleSurf;
|
|
|
|
|
2023-11-22 15:25:36 +01:00
|
|
|
uniform vec2 u_resolution;
|
|
|
|
uniform vec2 position;
|
2024-03-31 05:36:11 +02:00
|
|
|
uniform float rotation;
|
2023-11-22 15:25:36 +01:00
|
|
|
|
|
|
|
#define tau 6.283185307179586
|
|
|
|
|
|
|
|
vec3 hash(vec3 p) { return fract(sin(vec3(
|
|
|
|
dot(p, vec3(127.1324, 311.7874, 829.3683)) * (152.6178612 + seed / 10000.),
|
|
|
|
dot(p, vec3(269.8355, 183.3961, 614.5965)) * (437.5453123 + seed / 10000.),
|
|
|
|
dot(p, vec3(615.2689, 264.1657, 278.1687)) * (962.6718165 + seed / 10000.)
|
|
|
|
)) * 43758.5453); }
|
|
|
|
|
2023-12-23 12:59:21 +01:00
|
|
|
float shard_noise(in vec3 p, in float _sharp) {
|
2023-11-22 15:25:36 +01:00
|
|
|
vec3 ip = floor(p);
|
|
|
|
vec3 fp = fract(p);
|
|
|
|
|
|
|
|
float v = 0., t = 0.;
|
|
|
|
|
|
|
|
for (int z = -1; z <= 1; z++)
|
|
|
|
for (int y = -1; y <= 1; y++)
|
|
|
|
for (int x = -1; x <= 1; x++) {
|
2023-12-23 12:59:21 +01:00
|
|
|
vec3 o = vec3(x, y, z);
|
2023-11-22 15:25:36 +01:00
|
|
|
vec3 io = ip + o;
|
2023-12-23 12:59:21 +01:00
|
|
|
vec3 h = hash(io);
|
|
|
|
vec3 r = fp - (o + h);
|
2023-11-22 15:25:36 +01:00
|
|
|
float w = exp2(-tau*dot(r, r));
|
|
|
|
|
|
|
|
// tanh deconstruction and optimization by @Xor
|
2023-12-23 12:59:21 +01:00
|
|
|
float s = _sharp * dot(r, hash(io + vec3(11, 31, 47)) - 0.5);
|
2023-11-22 15:25:36 +01:00
|
|
|
v += w * s * inversesqrt(1.0 + s * s);
|
|
|
|
t += w;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ((v / t) * .5) + .5;
|
|
|
|
}
|
|
|
|
|
|
|
|
void main() {
|
2023-12-23 12:59:21 +01:00
|
|
|
#region params
|
|
|
|
vec2 sca = scale;
|
|
|
|
if(scaleUseSurf == 1) {
|
|
|
|
vec4 _vMap = texture2D( scaleSurf, v_vTexcoord );
|
|
|
|
sca = vec2(mix(scale.x, scale.y, (_vMap.r + _vMap.g + _vMap.b) / 3.));
|
|
|
|
}
|
|
|
|
|
|
|
|
prog = progress.x;
|
|
|
|
if(progressUseSurf == 1) {
|
|
|
|
vec4 _vMap = texture2D( progressSurf, v_vTexcoord );
|
|
|
|
prog = mix(progress.x, progress.y, (_vMap.r + _vMap.g + _vMap.b) / 3.);
|
|
|
|
}
|
|
|
|
|
|
|
|
sharp = sharpness.x;
|
|
|
|
if(sharpnessUseSurf == 1) {
|
|
|
|
vec4 _vMap = texture2D( sharpnessSurf, v_vTexcoord );
|
|
|
|
sharp = mix(sharpness.x, sharpness.y, (_vMap.r + _vMap.g + _vMap.b) / 3.);
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
2024-03-31 05:36:11 +02:00
|
|
|
float ang = radians(rotation);
|
|
|
|
vec2 pos = (v_vTexcoord - position / u_resolution) * mat2(cos(ang), -sin(ang), sin(ang), cos(ang)) * sca / 16.;
|
|
|
|
|
2023-12-23 12:59:21 +01:00
|
|
|
prog /= 100.;
|
2023-11-22 15:25:36 +01:00
|
|
|
vec3 uv = vec3( pos + prog, prog * .5 );
|
|
|
|
|
2023-12-23 12:59:21 +01:00
|
|
|
gl_FragColor = vec4( vec3(shard_noise(16.0 * uv, pow(sharp, 2.) * 20.)), 1. );
|
2023-11-22 15:25:36 +01:00
|
|
|
}
|