forked from man-o-valor/as-the-body-falls
-
Notifications
You must be signed in to change notification settings - Fork 0
Collapse file tree
Files
Search this repository
/
Copy pathstar.glsl
More file actions
More file actions
Latest commit
125 lines (90 loc) · 3.42 KB
/
star.glsl
File metadata and controls
125 lines (90 loc) · 3.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
bool renderGravityPoints = false;
bool closeToGravityPoint = false;
int maxSteps = 30000;
vec2 screenSize = iResolution.xy;
float longerSide = max(screenSize.x, screenSize.y);
float drag = 0.0005;
float minDistance = 5.0;
float gravity = 5.0;
vec2 pixelCoords = fragCoord.xy;
vec3 color = vec3(1.0, 1.0, 1.0);
float xCenter = screenSize.x / 2.0;
float yCenter = screenSize.y / 2.0;
vec2 points[10] = vec2[](
vec2(xCenter + cos(0.0) * 200.0, yCenter + sin(0.0) * 200.0),
vec2(xCenter + cos(0.628) * 200.0, yCenter + sin(0.628) * 200.0),
vec2(xCenter + cos(1.257) * 200.0, yCenter + sin(1.257) * 200.0),
vec2(xCenter + cos(1.885) * 200.0, yCenter + sin(1.885) * 200.0),
vec2(xCenter + cos(2.513) * 200.0, yCenter + sin(2.513) * 200.0),
vec2(xCenter + cos(3.142) * 200.0, yCenter + sin(3.142) * 200.0),
vec2(xCenter + cos(3.770) * 200.0, yCenter + sin(3.770) * 200.0),
vec2(xCenter + cos(4.398) * 200.0, yCenter + sin(4.398) * 200.0),
vec2(xCenter + cos(5.027) * 200.0, yCenter + sin(5.027) * 200.0),
vec2(xCenter + cos(5.655) * 200.0, yCenter + sin(5.655) * 200.0)
);
vec3 colors[10] = vec3[](
vec3(0.0, 0.0, 0.0),
vec3(0.05, 0.0, 0.1),
vec3(0.2, 0.0, 0.3),
vec3(0.4, 0.0, 0.2),
vec3(0.6, 0.1, 0.0),
vec3(0.8, 0.3, 0.0),
vec3(1.0, 0.6, 0.0),
vec3(1.0, 0.8, 0.3),
vec3(0.9, 0.95, 1.0),
vec3(1.0, 1.0, 1.0)
);
for (int i = 0; i 10; i++) {
if (length(fragCoord - points[i]) minDistance) {
if (renderGravityPoints) {
color = vec3(0.0, 0.0, 0.0);
} else {
color = vec3(colors[i]);
}
closeToGravityPoint = true;
}
}
float particleX = pixelCoords.x;
float particleY = pixelCoords.y;
float velocityX = 0.0;
float velocityY = 0.0;
int collidedPointIndex = -1;
int stepCount = 0;
fragColor = vec4(color, 1.0);
while (stepCount maxSteps) {
if (closeToGravityPoint) break;
stepCount++;
float accelerationX = 0.0;
float accelerationY = 0.0;
for (int i = 0; i 10; i++) {
float pointX = points[i].x;
float pointY = points[i].y;
float dx = (pointX - particleX) * (512.0 / longerSide);
float dy = (pointY - particleY) * (512.0 / longerSide);
float distanceSquared = dx * dx + dy * dy;
float minDistance = minDistance * (512.0 / longerSide);
if (distanceSquared (minDistance * minDistance)) {
collidedPointIndex = i;
break;
}
float gravityForce = gravity / distanceSquared;
float distance = sqrt(distanceSquared);
accelerationX += gravityForce * (dx / distance);
accelerationY += gravityForce * (dy / distance);
}
if (collidedPointIndex >=t;= 0) break;
velocityX += accelerationX;
velocityY += accelerationY;
velocityX *= (1.0 - drag);
velocityY *= (1.0 - drag);
particleX += velocityX;
particleY += velocityY;
}
if (collidedPointIndex == -1) {
fragColor = vec4(color, 1.0);
} else {
fragColor = vec4(colors[collidedPointIndex], 1.0);
}
}