Files
uarep-ctl/shaders/tools.gdshaderinc

42 lines
1.2 KiB
Plaintext

const float DS = 0.004; /* Относительное расстояние на котором выполняется сглаживание краёв */
global uniform float random_value;
float random_timed(vec2 uv)
{
return fract(sin(dot(uv + TIME * random_value, vec2(12.9898, 78.233))) * 43758.5453);
}
float smooth_px(float r, float R, float ds)
{
return smoothstep(R + ds, R - ds, r);
}
void circle_thin(inout vec3 color, vec2 uv, vec2 p, float r, float w, vec3 c, float a)
{
float d = distance(uv, p);
float v0 = r - w;
float v1 = r + w;
color += a * sqrt(smoothstep(v1, v0, d) * smoothstep(v0, v1, d) * c);
}
void line_r(inout vec4 color, vec2 uv, vec2 center, float theta0, float radius, vec4 c)
{
vec2 d = uv - center;
vec2 p = radius * vec2(cos(theta0 * PI / 180.0), - sin(theta0 * PI / 180.0));
float l = length(d - p * clamp(dot(d, p) / dot(p, p), 0.0, 1.0));
color.rgb += c.rgb * smooth_px(l, 1.0, DS) * c.a;
}
void rotate_vec2(inout vec2 vert, float a, vec2 pos)
{
vert -= pos;
float sin_a = sin(a);
float cos_a = cos(a);
vert *= mat2(vec2(cos_a, sin_a), vec2(-sin_a, cos_a));
vert += pos;
}