Skip to content

Instantly share code, notes, and snippets.

@yoshimax
Last active March 10, 2018 15:05
Show Gist options
  • Save yoshimax/c8d32ef9f7263b51ec6f0224c8169de5 to your computer and use it in GitHub Desktop.
Save yoshimax/c8d32ef9f7263b51ec6f0224c8169de5 to your computer and use it in GitHub Desktop.
Circles.glsl
float circle(vec2 coord, vec2 offs)
{
float reso = 16.0;
float cw = iResolution.x / reso;
vec2 p = mod(coord, cw) + offs * cw;
float d = distance(p, vec2(cw / 2.0));
vec2 p2 = floor(coord / cw) - offs;
vec2 gr = vec2(0.443, 0.312);
float t = iGlobalTime * 2.0 + dot(p2, gr);
float l = cw * (sin(t) + 1.2) * 0.4;
float lw = 1.5;
return max(0.0, 1.0 - abs(l - d) / lw);
}
void main()
{
float c = 0.0;
for (int i = 0; i < 9; i++)
{
float dx = mod(float(i), 3.0) - 1.0;
float dy = float(i / 3) - 1.0;
c += circle(gl_FragCoord.xy, vec2(dx, dy));
}
gl_FragColor = vec4(vec3(min(1.0, c)), 1);
}
#version 150
uniform float time;
uniform vec2 resolution;
out vec4 fragColor;
float circle(vec2 coord, vec2 offs)
{
float reso = 16.0;
float cw = resolution.x / reso;
vec2 p = mod(coord, cw) + offs * cw;
float d = distance(p, vec2(cw / 2.0));
vec2 p2 = floor(coord / cw) - offs;
vec2 gr = vec2(0.443, 0.312);
float t = time * 2.0 + dot(p2, gr);
float l = cw * (sin(t) + 1.2) * 0.4;
float lw = 1.5;
return max(0.0, 1.0 - abs(l - d) / lw);
}
void main()
{
float c = 0.0;
for (int i = 0; i < 9; i++)
{
float dx = mod(float(i), 3.0) - 1.0;
float dy = float(i / 3) - 1.0;
c += circle(gl_FragCoord.xy, vec2(dx, dy));
}
fragColor = vec4(vec3(min(1.0, c)), 1);
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert_img
#pragma fragment frag
#include "UnityCG.cginc"
float circle(float2 coord, float2 offs)
{
float reso = 16.0;
float resolution = _ScreenParams;
float cw = resolution.x / reso;
float2 p = fmod(coord, cw) + offs * cw;
float d = distance(p, float2(cw / 2.0, cw / 2.0));
float2 p2 = floor(coord / cw) - offs;
float2 gr = float2(0.443, 0.312);
float time = _Time * 30;
float t = time * 2.0 + dot(p2, gr);
float l = cw * (sin(t) + 1.2) * 0.4;
float lw = 1.5;
return max(0.0, 1.0 - abs(l - d) / lw);
}
fixed4 frag (v2f_img i) : SV_Target
{
float c = 0.0;
for (int l = 0; l < 9; l++)
{
float dx = fmod(float(l), 3.0) - 1.0;
float dy = float(l / 3) - 1.0;
float resolution = _ScreenParams;
c += circle(i.uv*resolution , float2(dx, dy));
}
float a = min(1.0, c);
return fixed4(a,a,a,1.0);
}
ENDCG
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment