Pixel-Composer/shaders/sh_mirror/sh_mirror.fsh

31 lines
754 B
Text
Raw Normal View History

2022-01-13 05:24:03 +01:00
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
2023-02-23 07:02:19 +01:00
#define TAU 6.283185307179586
2024-12-30 09:37:33 +01:00
#define PI 3.141592653589793
2022-01-13 05:24:03 +01:00
2024-01-20 05:06:56 +01:00
uniform vec2 dimension;
uniform vec2 position;
2022-01-13 05:24:03 +01:00
uniform float angle;
void main() {
2024-12-30 09:37:33 +01:00
vec2 ps = v_vTexcoord;
vec2 px = v_vTexcoord * dimension - position;
2022-01-13 05:24:03 +01:00
float _angle;
2024-12-30 09:37:33 +01:00
_angle = atan(px.y, px.x) + angle;
2022-01-13 05:24:03 +01:00
_angle = TAU - (_angle - floor(_angle / TAU) * TAU);
2024-12-30 09:37:33 +01:00
if(_angle < PI) {
float _alpha = (angle + PI) - (_angle + angle);
float inv_angle = (angle + PI) + _alpha;
float dist = length(px);
2022-01-13 05:24:03 +01:00
2024-12-30 09:37:33 +01:00
ps = (position + vec2(cos(inv_angle) * dist, -sin(inv_angle) * dist )) / dimension;
2024-01-20 05:06:56 +01:00
}
2022-01-13 05:24:03 +01:00
2024-01-20 05:06:56 +01:00
gl_FragColor = vec4(0.);
2024-12-30 09:37:33 +01:00
if(ps.x > 0. && ps.x < 1. && ps.y > 0. && ps.y < 1.)
gl_FragColor = texture2D( gm_BaseTexture, ps );
2022-01-13 05:24:03 +01:00
}