2022-01-13 05:24:03 +01:00
|
|
|
//
|
|
|
|
// Simple passthrough fragment shader
|
|
|
|
//
|
|
|
|
varying vec2 v_vTexcoord;
|
|
|
|
varying vec4 v_vColour;
|
|
|
|
|
|
|
|
uniform vec2 position;
|
|
|
|
uniform vec2 u_resolution;
|
2023-12-23 09:39:55 +01:00
|
|
|
|
|
|
|
uniform vec2 scale;
|
|
|
|
uniform int scaleUseSurf;
|
|
|
|
uniform sampler2D scaleSurf;
|
|
|
|
|
2022-01-13 05:24:03 +01:00
|
|
|
uniform int iteration;
|
2022-12-27 04:00:50 +01:00
|
|
|
uniform float seed;
|
2023-02-28 09:43:01 +01:00
|
|
|
uniform int tile;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-04-07 21:25:27 +02:00
|
|
|
uniform int colored;
|
|
|
|
uniform vec2 colorRanR;
|
|
|
|
uniform vec2 colorRanG;
|
|
|
|
uniform vec2 colorRanB;
|
|
|
|
|
2023-12-23 09:39:55 +01:00
|
|
|
vec2 sca;
|
|
|
|
|
2023-11-15 14:42:53 +01:00
|
|
|
vec3 hsv2rgb(vec3 c) { #region
|
2023-04-07 21:25:27 +02:00
|
|
|
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
|
|
|
|
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
|
|
|
|
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
|
2023-11-15 14:42:53 +01:00
|
|
|
} #endregion
|
2023-04-07 21:25:27 +02:00
|
|
|
|
2023-12-18 04:40:21 +01:00
|
|
|
float random (in vec2 st, float seed) { return fract(sin(dot(st.xy + vec2(21.456, 46.856), vec2(12.989, 78.233))) * (43758.545 + seed)); }
|
|
|
|
|
2023-11-15 14:42:53 +01:00
|
|
|
float randomFloat (in vec2 st, float seed) { #region
|
2023-02-28 09:43:01 +01:00
|
|
|
float sedSt = floor(seed);
|
|
|
|
float sedFr = fract(seed);
|
|
|
|
|
2023-11-15 14:42:53 +01:00
|
|
|
return mix(random(st, sedSt), random(st, sedSt + 1.), sedFr);
|
|
|
|
} #endregion
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-12-18 04:40:21 +01:00
|
|
|
vec2 random2 (in vec2 st, float seed) { return vec2(random(st, seed), random(st, seed + 1.864)); }
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-11-15 14:42:53 +01:00
|
|
|
float noise (in vec2 st, in vec2 scale) { #region
|
|
|
|
vec2 cellMin = floor(st);
|
|
|
|
vec2 cellMax = floor(st) + vec2(1., 1.);
|
|
|
|
|
|
|
|
if(tile == 1) {
|
|
|
|
cellMin = mod(cellMin, scale);
|
|
|
|
cellMax = mod(cellMax, scale);
|
|
|
|
}
|
|
|
|
|
|
|
|
vec2 f = fract(st);
|
|
|
|
vec2 u = f * f * (3.0 - 2.0 * f);
|
|
|
|
|
|
|
|
float a = randomFloat(vec2(cellMin.x, cellMin.y), seed);
|
|
|
|
float b = randomFloat(vec2(cellMax.x, cellMin.y), seed);
|
|
|
|
float c = randomFloat(vec2(cellMin.x, cellMax.y), seed);
|
|
|
|
float d = randomFloat(vec2(cellMax.x, cellMax.y), seed);
|
|
|
|
|
|
|
|
return abs(mix(mix(a, b, u.x), mix(c, d, u.x), u.y));
|
|
|
|
} #endregion
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-11-15 14:42:53 +01:00
|
|
|
float perlin(in vec2 st) { #region
|
2023-02-28 09:43:01 +01:00
|
|
|
float amp = pow(2., float(iteration) - 1.) / (pow(2., float(iteration)) - 1.);
|
2023-04-07 21:25:27 +02:00
|
|
|
float n = 0.;
|
|
|
|
vec2 pos = st;
|
2023-12-23 09:39:55 +01:00
|
|
|
vec2 sc = sca;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
for(int i = 0; i < iteration; i++) {
|
2023-02-28 09:43:01 +01:00
|
|
|
n += noise(pos, sc) * amp;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-12-12 06:40:29 +01:00
|
|
|
pos += random2(vec2(float(i), float(i)), seed + 1.574186) * sc;
|
2023-11-15 14:42:53 +01:00
|
|
|
|
2023-02-28 09:43:01 +01:00
|
|
|
sc *= 2.;
|
2022-01-13 05:24:03 +01:00
|
|
|
amp *= .5;
|
|
|
|
pos *= 2.;
|
|
|
|
}
|
|
|
|
|
2023-04-07 21:25:27 +02:00
|
|
|
return n;
|
2023-11-15 14:42:53 +01:00
|
|
|
} #endregion
|
2023-04-07 21:25:27 +02:00
|
|
|
|
2023-11-15 14:42:53 +01:00
|
|
|
void main() { #region
|
2023-12-23 09:39:55 +01:00
|
|
|
#region params
|
|
|
|
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.));
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
2023-04-07 21:25:27 +02:00
|
|
|
if(colored == 0) {
|
2023-12-23 09:39:55 +01:00
|
|
|
vec2 pos = (v_vTexcoord + position) * sca;
|
2023-04-07 21:25:27 +02:00
|
|
|
gl_FragColor = vec4(vec3(perlin(pos)), 1.0);
|
|
|
|
} else if(colored == 1) {
|
2023-12-23 09:39:55 +01:00
|
|
|
float randR = colorRanR[0] + perlin((v_vTexcoord + position) * sca) * (colorRanR[1] - colorRanR[0]);
|
|
|
|
float randG = colorRanG[0] + perlin((v_vTexcoord + position + vec2(1.7227, 4.55529)) * sca) * (colorRanG[1] - colorRanG[0]);
|
|
|
|
float randB = colorRanB[0] + perlin((v_vTexcoord + position + vec2(6.9950, 6.82063)) * sca) * (colorRanB[1] - colorRanB[0]);
|
2023-04-07 21:25:27 +02:00
|
|
|
|
|
|
|
gl_FragColor = vec4(randR, randG, randB, 1.0);
|
|
|
|
} else if(colored == 2) {
|
2023-12-23 09:39:55 +01:00
|
|
|
float randH = colorRanR[0] + perlin((v_vTexcoord + position) * sca) * (colorRanR[1] - colorRanR[0]);
|
|
|
|
float randS = colorRanG[0] + perlin((v_vTexcoord + position + vec2(1.7227, 4.55529)) * sca) * (colorRanG[1] - colorRanG[0]);
|
|
|
|
float randV = colorRanB[0] + perlin((v_vTexcoord + position + vec2(6.9950, 6.82063)) * sca) * (colorRanB[1] - colorRanB[0]);
|
2023-04-07 21:25:27 +02:00
|
|
|
|
|
|
|
gl_FragColor = vec4(hsv2rgb(vec3(randH, randS, randV)), 1.0);
|
|
|
|
}
|
2023-11-15 14:42:53 +01:00
|
|
|
} #endregion
|