-
-
Save Grace-pc/8a052054bb0fd838e1788b80ff616b6b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Author: Jeremy | |
//Editor: Ziqi | |
// Course: ShaderArt (DIGF-3011, Winter 2022) | |
// Title: LiveCode_Grid | |
#ifdef GL_ES | |
precision mediump float; | |
#endif | |
uniform vec2 u_resolution; | |
uniform vec2 u_mouse; | |
uniform float u_time; | |
float sdSegment( in vec2 p, in vec2 a, in vec2 b ) | |
{ | |
vec2 pa = p-a, ba = b-a; | |
float h = clamp( dot(pa,ba)/dot(ba,ba), -0.192, 1.536 ); | |
return length( pa - ba*h ); | |
} | |
vec3 hsb2rgb( in vec3 c ){ | |
vec3 rgb = clamp(abs(mod(c.x*6.0+vec3(0.0,4.0,2.0), | |
6.0)-3.0)-1.0, | |
0.0, | |
1.0 ); | |
rgb = rgb*rgb*(3.0-2.0*rgb); | |
return c.z * mix( vec3(1.000,0.975,0.955), rgb, c.y); | |
} | |
void main() { | |
float change = abs(sin(u_time));//the change is from thebookofshaders | |
// normalized coordinates | |
vec2 st = gl_FragCoord.xy/u_resolution.xy; | |
st.x *= u_resolution.x/u_resolution.y; | |
vec2 st0 = st; | |
float circ2 = distance( st, vec2(0.790,0.470)); | |
circ2 = step( 0.256, circ2); | |
st *= 10.0; // 0...10 | |
vec2 cellIndex = floor(st); | |
st = fract( st); // 1.3 => 0.3 | |
if( mod(cellIndex.y, 2.) == 0.0){ | |
st = st0; | |
st.x -= -0.134; | |
st *= 10.*change; | |
cellIndex = floor(st); | |
st = fract( st); // 1.3 => 0.3 | |
} | |
vec3 color = vec3( st, 0); | |
float circ1 = distance( st, vec2(0.5, 0.5)); | |
circ1 = 1.0-step(.624, circ1); | |
// remainder after a division operation | |
// 1 % 2 => 1 | |
// 2 % 2 => 0 | |
// 3 % 2 => 1 | |
// 4 % 2 => 0 | |
// 5 % 2 => 1 | |
// 6 % 2 => 0 | |
if( mod(cellIndex.x, 2.) == 0.){ | |
if( mod(cellIndex.y, 2.) == 0.){ | |
color = vec3( change, change, change )*circ1; | |
} else { | |
color = vec3(1.000,0.784,0.002)*circ1; | |
} | |
} else { | |
if( mod(cellIndex.y, 2.) == 0.){ | |
color = vec3(0.420,0.565,1.000)*circ1; | |
} else { | |
color = vec3( 0.0, 1.0, 1. )*circ1; | |
} | |
} | |
// calculate the color in HSB space | |
vec3 hsb = vec3( st.y - u_time*1.168, 0.824, 0.632); | |
float line = sdSegment( st, vec2(change,0.810), vec2(0.480,change)); | |
color = mix( color, hsb2rgb(hsb), line ); | |
// display the color for the pixel | |
gl_FragColor = vec4(color, 1.0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment