Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifdef GL_ES
- precision highp float;
- #endif
- varying vec4 vColor;
- varying vec3 vPosition;
- uniform float f; // this is incremented every frame
- uniform float t; // this is time in milliseconds since init
- float plasma(vec2 pos) {
- return sin(pos.x) * cos(pos.y) * 0.5 + 0.5;
- }
- float radius(vec2 point, vec2 center) {
- return distance(point, center);
- }
- bool is_circle(vec2 point, vec2 center, float fradius) {
- float r = radius(point, center);
- if(r <= fradius) {
- return true;
- } else {
- return false;
- }
- }
- bool is_ring(vec2 point, vec2 center, vec2 radiuses) {
- return !is_circle(point, center, radiuses[0]) && is_circle(point, center, radiuses[0] + radiuses[1]);
- }
- vec2 getCirclePoint(vec2 center, float radius, float f) {
- return vec2(radius * sin(f) + center.x, radius * cos(f) + center.y);
- }
- int is_planet(float planetRadius, float orbitRadius, float speed) {
- vec2 p = vPosition.xy;
- if(is_circle(p, getCirclePoint(vec2(0.0), orbitRadius, t / 900.0 * speed), planetRadius)) {
- return 2;
- }
- if(is_ring(p, vec2(0.0), vec2(orbitRadius, 0.01))) {
- return 1;
- }
- return 0;
- }
- vec4 get_planet_color(float planetRadius, float orbitRadius, vec4 circleColor, float speed) {
- int planetComponent = is_planet(planetRadius, orbitRadius, speed);
- if(planetComponent == 2) {
- return circleColor;
- } else if(planetComponent == 1) {
- return vec4(0.1,0.1,0.1,1.0);
- }
- return vec4(0.0);
- }
- vec4 getColor() {
- vec2 p = vPosition.xy;
- if(is_circle(p, vec2(0.0), 0.05)) {
- return vec4(1.0, 1.0, 0.0, 1.0);
- }
- vec4 tmp;
- tmp = get_planet_color(0.03, 0.15, vec4(0.5, 0.5, 1.0, 1.0), 1.5);
- if(tmp.a != 0.0) {
- return tmp;
- }
- tmp = get_planet_color(0.05, 0.65, vec4(1.0, 0.0, 0.0, 1.0), 0.5);
- if(tmp.a != 0.0) {
- return tmp;
- }
- return vec4(vec3(0.0), 1.0);
- }
- void main(void) {
- gl_FragColor = getColor();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement