KAR98S

BouncingSun.frag

May 30th, 2020 (edited)
273
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.     This is a fragment shader file, if you don't know anything about it
  3.     you can run it here online -> http://editor.thebookofshaders.com/
  4.     just copy and paste the code
  5. */
  6.  
  7. precision mediump float;
  8.  
  9. uniform vec2 u_resolution;
  10. uniform vec2 u_mouse;
  11. uniform float u_time;
  12.  
  13. float diatance(vec2 p1, vec2 p2){   //distance function
  14.     return
  15.         (sqrt(
  16.             (pow( (p2.y - p1.y) , 2.0) + pow( (p2.x - p1.x), 2.0))
  17.         ));
  18. }
  19.  
  20. void main() {
  21.     vec2 centre = vec2(u_resolution.x/2.0,u_resolution.y/2.0);
  22.     float R,G,B,A, dist, size1, size2, tmp;
  23.     vec3 color;
  24.    
  25.    
  26.     size1 = 100.0;
  27.     size1 *= ((abs(sin(u_time / 3.0))) + 0.5);          //--comment this line to stop growth
  28.                                                         //  animation
  29.     centre.y *= (abs(sin(u_time*2.0)));                 //--comment to stop position animation
  30.     size2 = (size1 * 4.0);
  31.     size2 *= (abs( sin( u_time / 2.0 )) / 5.0 ) + 0.8;  //--animating warmth | comment to stop
  32.    
  33.     dist = distance(gl_FragCoord.xy, centre);           //--distance of each pixel from centre
  34.     if( dist <= size1){         //--sun color
  35.         tmp = dist/size1;
  36.         R = 1.0;
  37.         G = (1.0 - pow((dist/size1)*0.9,8.0));
  38.         B = (1.0 - pow(tmp,0.5));
  39.     }
  40.     else if(dist <= size2){     //--set shine/warmth color
  41.         tmp = dist/size2;
  42.         R = (1.0 - clamp(pow(tmp,5.0),0.0,0.7));
  43.         G = (1.0 - clamp(pow(tmp,3.0),0.0,0.2));
  44.         B = (pow (tmp,1.0));
  45.     }
  46.     else{                       //--set sky color
  47.         R = 0.3;
  48.         B = 1.0;
  49.         G = 0.8;
  50.     }
  51.  
  52.     color = vec3(R,G,B);
  53.     A = 1.0;
  54.     gl_FragColor = vec4(color,A);
  55. }
RAW Paste Data