Skip to content

Instantly share code, notes, and snippets.

@mrange
Created August 10, 2019 18:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrange/0f564eb77515c7f7fada3d3d4a9f597e to your computer and use it in GitHub Desktop.
Save mrange/0f564eb77515c7f7fada3d3d4a9f597e to your computer and use it in GitHub Desktop.
rounded_box
#version 150
uniform float time;
uniform vec2 resolution;
uniform vec2 mouse;
uniform vec3 spectrum;
uniform sampler2D texture0;
uniform sampler2D texture1;
uniform sampler2D texture2;
uniform sampler2D texture3;
uniform sampler2D prevFrame;
uniform sampler2D prevPass;
in VertexData
{
vec4 v_position;
vec3 v_normal;
vec2 v_texcoord;
} inData;
out vec4 fragColor;
float roundedBox(vec2 p, vec3 d)
{
float r = d.z;
d *= 0.5;
p = abs(p);
float oxy = length(vec2(d.x - d.z, d.y - d.z));
float dx = p.x - d.x;
float dy = p.y - d.y;
float dxy = sqrt(0.5)*(p.x + p.y) - oxy;
float ds = length(p - sqrt(0.5)*oxy + d.z) - r;
float db = max(max(dx, dy), dxy);
return min(ds, db);
}
float df(vec2 p)
{
return length(p) - 1.0;
}
void main(void)
{
vec2 uv = -1. + 2. * inData.v_texcoord;
uv.x *= resolution.x/resolution.y;
float d = roundedBox(uv, vec3(1.0, 1.0, 0.1));
vec3 col = vec3(0.0);
float md = mod(d, 0.1);
if (abs(md) < 0.01)
{
float h = 1.0/(abs(d) / 0.1);
if (d < 0)
{
col = vec3(h, 0.25, 0.25);
}
else
{
col = vec3(0.25, 0.25, h);
}
}
if (abs(d) < 0.01)
{
col = vec3(1.0);
}
fragColor = vec4(col, 1.0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment