Advertisement
Guest User

Untitled

a guest
Apr 10th, 2018
75
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. bool is_ring(vec2 point, vec2 center, vec2 radiuses) {
  29.       return !is_circle(point, center, radiuses[0]) && is_circle(point, center, radiuses[0] + radiuses[1]);
  30. }
  31.  
  32. vec2 getCirclePoint(vec2 center, float radius, float f) {
  33.     return vec2(radius * sin(f) + center.x, radius * cos(f) + center.y);
  34. }
  35.  
  36. int is_planet(float planetRadius, float orbitRadius, float speed) {
  37.     vec2 p = vPosition.xy;
  38.    
  39.     if(is_circle(p, getCirclePoint(vec2(0.0), orbitRadius, t / 900.0 * speed), planetRadius)) {
  40.         return 2;
  41.     }
  42.    
  43.     if(is_ring(p, vec2(0.0), vec2(orbitRadius, 0.01))) {
  44.         return 1;
  45.     }
  46.    
  47.     return 0;
  48. }
  49.  
  50. vec4 get_planet_color(float planetRadius, float orbitRadius, vec4 circleColor, float speed) {
  51.     int planetComponent = is_planet(planetRadius, orbitRadius, speed);
  52.     if(planetComponent == 2) {
  53.         return circleColor;
  54.     } else if(planetComponent == 1) {
  55.         return vec4(0.1,0.1,0.1,1.0);
  56.     }    
  57.    
  58.     return vec4(0.0);
  59. }
  60.  
  61.  
  62. vec4 getColor() {
  63.     vec2 p = vPosition.xy;
  64.    
  65.     if(is_circle(p, vec2(0.0), 0.05)) {
  66.         return vec4(1.0, 1.0, 0.0, 1.0);
  67.     }
  68.    
  69.     vec4 tmp;
  70.    
  71.     tmp = get_planet_color(0.03, 0.15, vec4(0.5, 0.5, 1.0, 1.0), 1.5);
  72.     if(tmp.a != 0.0) {
  73.         return tmp;
  74.     }
  75.  
  76.     tmp = get_planet_color(0.05, 0.65, vec4(1.0, 0.0, 0.0, 1.0), 0.5);
  77.     if(tmp.a != 0.0) {
  78.         return tmp;
  79.     }    
  80.  
  81.     return vec4(vec3(0.0), 1.0);
  82. }
  83.  
  84. void main(void) {
  85.     gl_FragColor = getColor();
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement