Advertisement
Guest User

Untitled

a guest
Apr 10th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #ifdef GL_ES
  2. precision highp float;
  3. #endif
  4.  
  5. varying vec4 vColor;
  6. varying vec3 vPosition;
  7.  
  8. uniform float f; // this is incremented every frame
  9. uniform float t; // this is time in milliseconds since init
  10.  
  11. float plasma(vec2 pos) {
  12.  return sin(pos.x) * cos(pos.y) * 0.5 + 0.5;
  13. }
  14.  
  15. float radius(vec2 point, vec2 center) {
  16.     return distance(point, center);
  17. }
  18.  
  19. bool is_circle(vec2 point, vec2 center, float fradius) {
  20.        float r = radius(point, center);
  21.        if(r <= fradius) {
  22.             return true;
  23.        } else {
  24.                 return false;
  25.        }
  26. }
  27.  
  28.  
  29. bool is_ring(vec2 point, vec2 center, vec2 radiuses) {
  30.       return !is_circle(point, center, radiuses[0]) && is_circle(point, center, radiuses[0] + radiuses[1]);
  31. }
  32.  
  33. vec2 getCirclePoint(vec2 center, float radius, float f) {
  34.     return vec2(radius * sin(f) + center.x, radius * cos(f) + center.y);
  35. }
  36.  
  37. int is_planet(float planetRadius, float orbitRadius, float speed) {
  38.     vec2 p = vPosition.xy;
  39.    
  40.     if(is_circle(p, getCirclePoint(vec2(0.0), orbitRadius, t / 900.0 * speed), planetRadius)) {
  41.         return 2;
  42.     }
  43.    
  44.     if(is_ring(p, vec2(0.0), vec2(orbitRadius, 0.01))) {
  45.         return 1;
  46.     }
  47.    
  48.     return 0;
  49. }
  50.  
  51. vec4 get_planet_color(float planetRadius, float orbitRadius, vec4 circleColor, float speed) {
  52.     int planetComponent = is_planet(planetRadius, orbitRadius, speed);
  53.     if(planetComponent == 2) {
  54.         return circleColor;
  55.     } else if(planetComponent == 1) {
  56.         return vec4(0.1,0.1,0.1,1.0);
  57.     }    
  58.    
  59.     return vec4(0.0);
  60. }
  61.  
  62.  
  63. vec4 getColor() {
  64.     vec2 p = vPosition.xy;
  65.    
  66.     if(is_circle(p, vec2(0.0), 0.05)) {
  67.         return vec4(1.0, 1.0, 0.0, 1.0);
  68.     }
  69.    
  70.     vec4 tmp;
  71.    
  72.     tmp = get_planet_color(0.03, 0.15, vec4(0.5, 0.5, 1.0, 1.0), 1.5);
  73.     if(tmp.a != 0.0) {
  74.         return tmp;
  75.     }
  76.  
  77.     tmp = get_planet_color(0.05, 0.65, vec4(1.0, 0.0, 0.0, 1.0), 0.5);
  78.     if(tmp.a != 0.0) {
  79.         return tmp;
  80.     }    
  81.  
  82.     return vec4(vec3(0.0), 1.0);
  83. }
  84.  
  85. void main(void) {
  86.     gl_FragColor = getColor();
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement