Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#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;
#define MAX_ITR 64
in VertexData
{
vec4 v_position;
vec3 v_normal;
vec2 v_texcoord;
} inData;
out vec4 fragColor;
// http://iquilezles.org/www/articles/distfunctions2d/distfunctions2d.htm
float equiTri(vec2 p){
float side = sqrt(3.0);
p.x = abs(p.x) - 1.0;
p.y = p.y +1.0/side;
if(p.x + side*p.y > 0.0){
p = vec2(p.x - side*p.y, -side*p.x - p.y)/2.0;
}
p.x -= clamp(p.x,-2.0,0.0);
return -length(p)*sign(p.y);
}
// http://www.iquilezles.org/www/articles/palettes/palettes.htm
// As t runs from 0 to 1 (our normalized palette index or domain),
//the cosine oscilates c times with a phase of d.
//The result is scaled and biased by a and b to meet the desired constrast and brightness.
vec3 cosPalette( float t, vec3 a, vec3 b, vec3 c, vec3 d )
{
return a + b*cos( 6.28318*(c*t+d) );
}
void main(void)
{
vec2 fragCoord = inData.v_texcoord * resolution.xy;
vec2 p = (-resolution.xy + 2.0*fragCoord)/resolution.y;
// distance metric
float shape = equiTri(p*vec2(spectrum.x * 20));
vec3 col = cosPalette(0.5,vec3(0.5),vec3(0.5),vec3(1),vec3(time*0.01,time*0.1,time*.2));
// lighting: darken at the center
col = vec3(shape) * col;
// output: pixel color
fragColor = vec4( col.bgr, 1.0 );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.