Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Title: HW4
- // Author: Iris
- // Course: ShaderArt (DIGF-3011, Winter 2022)
- #ifdef GL_ES
- precision mediump float;
- #endif
- uniform vec2 u_mouse;
- uniform vec2 u_resolution;
- uniform float u_time;
- // calculateHue()
- // select a color from a collection of 6 based on a percentage
- // returns a RGB color
- // random()
- // by Patricio Gonzalez-Vivo
- float random (vec2 st) {
- return fract(sin(dot(st.xy,
- vec2(12.9898,78.233)))*
- 43758.5453123);
- }
- float map(float value, float min1, float max1, float min2, float max2) {
- return min2 + (value - min1) * (max2 - min2) / (max1 - min1);
- }
- vec3 calculateHue(vec3 colors[3], float pct){
- pct = fract(pct);
- vec3 result = vec3(0.0); // Define the result so that we don't return nothing by accident
- float numberOfSections = 3.; // Number of sections (maximum of 12)
- for (int position = 0; position <= 3; position ++){ // Loops through the following code 12 times
- float leftPosition = float(position) / numberOfSections; // Defines the left most position of the current section you're in
- float rightPosition = float(position) + 1. / numberOfSections; // Defines the right most position of the current section you're in
- if (pct > leftPosition && pct <= rightPosition){ // Checks what section of the screen you are in (divided into numberOfSections)
- result = colors[position]; // Colors your section with the appropriate colour
- }
- }
- return result;
- }
- vec3 rgb_normalize( int r, int g, int b){
- return vec3(float(r)/255., float(g)/255., float(b)/255.);
- }
- void main (void) {
- vec2 st = gl_FragCoord.xy/u_resolution.xy;
- vec3 colors[3];
- // DEFINE YOUR COLOURS FOR THE TOP ROW HERE
- colors[0] = rgb_normalize(128, 0, 32);
- colors[1] = rgb_normalize(125, 112, 152);
- colors[2] = rgb_normalize(255, 0, 0);
- vec3 color = vec3(0);
- float row = 1.0 - st.y;
- row = floor( row * 3.0); // Split the screen into 4 rows
- // calculate the brightness based on the cell index using map()
- // this creates steps for brightness: 0., 0.25, 0.5, 0.75, 1.0
- float minBri = 0.3;
- float brightness = map(abs(row), 0., 4., 1., minBri );
- brightness *= map(abs(row), 0., 4., 1., minBri );
- if( row == 0.0){
- // SHOW THE TOP ROW
- color = calculateHue(colors, st.x*-1.);
- } else if( row == 1.0 ){
- // SHOW THE FIRST MIDDLE ROW
- color = calculateHue(colors, st.x-1.*tan(u_time)/3.);
- } else if( row == 2.0 ){
- // SHOW THE SECOND MIDDLE ROW
- color = calculateHue(colors, random(st*u_time/8.));
- }
- gl_FragColor = vec4(color,1.0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement