2022-01-13 05:24:03 +01:00
|
|
|
//
|
|
|
|
// Simple passthrough fragment shader
|
|
|
|
//
|
|
|
|
varying vec2 v_vTexcoord;
|
|
|
|
varying vec4 v_vColour;
|
|
|
|
|
2022-09-21 06:09:40 +02:00
|
|
|
uniform vec2 dimension;
|
2022-01-13 05:24:03 +01:00
|
|
|
uniform vec2 position;
|
|
|
|
uniform vec2 scale;
|
|
|
|
uniform float seed;
|
|
|
|
uniform float shift;
|
2023-01-01 02:06:02 +01:00
|
|
|
uniform int shiftAxis;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-09-21 06:09:40 +02:00
|
|
|
uniform int useSampler;
|
|
|
|
|
2023-01-09 03:14:20 +01:00
|
|
|
float randomSeed (in vec2 st, float _seed) {
|
|
|
|
return fract(sin(dot(st.xy, vec2(12.9898, 78.233))) * (43758.5453123 + _seed));
|
|
|
|
}
|
|
|
|
|
2022-01-13 05:24:03 +01:00
|
|
|
float random (in vec2 st) {
|
2023-01-09 03:14:20 +01:00
|
|
|
return mix(randomSeed(st, floor(seed)), randomSeed(st, floor(seed) + 1.), fract(seed));
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void main() {
|
2022-09-21 06:09:40 +02:00
|
|
|
vec2 st = v_vTexcoord - position / dimension;
|
2022-01-13 05:24:03 +01:00
|
|
|
vec2 pos = vec2(st * scale);
|
2023-01-01 02:06:02 +01:00
|
|
|
|
|
|
|
if(shiftAxis == 0)
|
|
|
|
pos.x += random(vec2(0., floor(pos.y))) * shift;
|
|
|
|
else if(shiftAxis == 1)
|
|
|
|
pos.y += random(vec2(0., floor(pos.x))) * shift;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-01-09 03:14:20 +01:00
|
|
|
if(useSampler == 0) {
|
|
|
|
vec2 i = floor(pos);
|
|
|
|
float n = random(i);
|
2022-09-21 06:09:40 +02:00
|
|
|
gl_FragColor = vec4(vec3(n), 1.0);
|
2023-01-09 03:14:20 +01:00
|
|
|
} else {
|
2022-09-21 06:09:40 +02:00
|
|
|
vec2 samPos = floor(pos) / scale + 0.5 / scale;
|
|
|
|
gl_FragColor = texture2D( gm_BaseTexture, samPos );
|
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|