Pixel-Composer/shaders/sh_noise_wavelet/sh_noise_wavelet.fsh

76 lines
3 KiB
Text
Raw Normal View History

2023-11-22 15:25:36 +01:00
// "Wavelet Noise"
// The MIT License
// Copyright © 2020 Martijn Steinrucken
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// Email: countfrolic@gmail.com
// Twitter: @The_ArtOfCode
// YouTube: youtube.com/TheArtOfCodeIsCool
// Facebook: https://www.facebook.com/groups/theartofcode/
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
uniform float seed;
uniform vec2 u_resolution;
uniform vec2 position;
2023-12-23 12:59:21 +01:00
uniform vec2 progress;
uniform int progressUseSurf;
uniform sampler2D progressSurf;
uniform vec2 detail;
uniform int detailUseSurf;
uniform sampler2D detailSurf;
uniform vec2 scale;
uniform int scaleUseSurf;
uniform sampler2D scaleSurf;
2023-11-22 15:25:36 +01:00
float WaveletNoise(vec2 p, float z, float k) {
float d = 0., s = 1., m = 0., a;
for(float i = 0.; i < 4.; i++) {
vec2 q = p * s;
vec2 g = fract(floor(q) * vec2(123.34 + seed, 233.53 + seed));
g += dot(g, g + 23.234);
a = fract(g.x * g.y) * 0.0001 + z * (mod(g.x + g.y, 2.) - 1.); // add vorticity
q = (fract(q) - .5) * mat2(cos(a), -sin(a), sin(a), cos(a));
d += sin(q.x * 10. + z) * smoothstep(.25, .0, dot(q, q)) / s;
p = p * mat2(.54, -.84, .84, .54) + i;
m += 1. / s;
s *= k;
}
return d / m;
}
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.));
}
float 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.);
}
float detl = detail.x;
if(detailUseSurf == 1) {
vec4 _vMap = texture2D( detailSurf, v_vTexcoord );
detl = mix(detail.x, detail.y, (_vMap.r + _vMap.g + _vMap.b) / 3.);
}
#endregion
2023-11-22 15:25:36 +01:00
vec2 pos = v_vTexcoord - .5;
pos.x *= (u_resolution.x / u_resolution.y);
2023-12-23 12:59:21 +01:00
pos = (pos + position) * sca / 16.;
2023-11-22 15:25:36 +01:00
vec3 col = vec3(0.);
2023-12-23 12:59:21 +01:00
col += WaveletNoise(pos * 5., (2.9864 + prog), detl) * .5 + .5;
2023-11-22 15:25:36 +01:00
gl_FragColor = vec4(col, 1.0);
}