Pixel-Composer/shaders/sh_ani_noise/sh_ani_noise.fsh

35 lines
942 B
Text
Raw Normal View History

2022-01-13 05:24:03 +01:00
//
// Simple passthrough fragment shader
//
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
uniform vec2 noiseAmount;
uniform vec2 position;
2022-12-13 09:20:36 +01:00
uniform float angle;
2022-01-13 05:24:03 +01:00
uniform float seed;
2023-01-09 03:14:20 +01:00
float random1D (in vec2 st, float _seed) {
return fract(sin(dot(st.xy, vec2(12.9898, 78.233)) * mod(_seed, 32.156) * 12.588) * 43758.5453123);
}
2022-01-13 05:24:03 +01:00
float random (in vec2 st) {
2023-01-09 03:14:20 +01:00
return mix(random1D(st, floor(seed)), random1D(st, floor(seed) + 1.), fract(seed));
2022-01-13 05:24:03 +01:00
}
void main() {
2022-12-13 09:20:36 +01:00
vec2 pos = v_vTexcoord - position, _pos;
_pos.x = pos.x * cos(angle) - pos.y * sin(angle);
_pos.y = pos.x * sin(angle) + pos.y * cos(angle);
2022-01-13 05:24:03 +01:00
float yy = floor(_pos.y * noiseAmount.y);
2023-01-09 03:14:20 +01:00
float xx = (_pos.x + random1D(vec2(yy), floor(seed))) * noiseAmount.x;
2022-01-13 05:24:03 +01:00
float x0 = floor(xx);
float x1 = floor(xx) + 1.;
float noise0 = random(vec2(x0, yy));
float noise1 = random(vec2(x1, yy));
gl_FragColor = vec4(vec3(mix(noise0, noise1, (xx - x0) / (x1 - x0))), 1.);
}