Skip to content

Instantly share code, notes, and snippets.

@Grace-pc
Last active March 12, 2022 08:04
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 Grace-pc/2c4409a8b2f603ca16a9e9b6f9588270 to your computer and use it in GitHub Desktop.
Save Grace-pc/2c4409a8b2f603ca16a9e9b6f9588270 to your computer and use it in GitHub Desktop.
// Author: Jeremy Rotsztain
//Editor: Ziqi Guo
// Title: Week3 HW1
// Course: ShaderArt (DIGF-3011, Winter 2022)
#ifdef GL_ES
precision mediump float;
#endif
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
// calculate a circle:
// 1.0 is inside of circle (true); 0.0 is outside of circle (false)
float drawCircle(vec2 st, vec2 pos, float size){
float d = distance(st, pos);
// step shows values > argument 1, and we want the opposite
// so we invert the results by subtraction 1.0 - the value
return 1.0-smoothstep(size-(size*0.858),
size+(size*-0.142),
dot(d,d)*3.984);
}
void main() {
vec2 st = gl_FragCoord.xy/u_resolution.xy;
st.x *= u_resolution.x/u_resolution.y;
float change = abs(sin(u_time));//the change is from thebookofshaders
vec2 mouseXY = u_mouse / u_resolution;
// calculate layers as circles
float layer1 = drawCircle( st, vec2(0.190,0.740-mouseXY.x), 0.260);
float layer2 = drawCircle( st, vec2(0.5-mouseXY.x, 0.5), 0.3);
float layer3 = drawCircle( st, vec2(0.75-mouseXY.y, 0.5), 0.3);
// is is our fragment color/background color
vec3 color = vec3(0.030,0.023,0.030);
// draw 3 circles on top of one another
color = mix( color, vec3(1.0-st.x, 0.576, change), layer1);
color = mix( color, vec3(1.000,change,1.746-st.x), layer2);
color = mix( color, vec3(0.0, 1.120-st.y, change), layer3);
// color = mix( color, vec3(0.0, 0.0, 2.0), layer4);
// debug: look at the raw data
// disable the code below to view
// color = vec3(layer1);
// try multiplying circle2 & circle3 to create a transparent overlay
gl_FragColor = vec4(color,1.0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment