Skip to content

Commit 6e248a9

Browse files
committed
Glow around the rim
1 parent eed29bd commit 6e248a9

File tree

4 files changed

+116
-12
lines changed

4 files changed

+116
-12
lines changed

assets/shaders/accretiondisk.frag

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#define HIGHP
2+
3+
#define MUL 4.0
4+
5+
uniform sampler2D u_texture;
6+
7+
uniform vec2 u_campos;
8+
uniform vec2 u_resolution;
9+
10+
uniform int u_blackholecount;
11+
uniform vec4 u_blackholes[MAX_COUNT];
12+
uniform vec4 u_colors[MAX_COUNT];
13+
14+
varying vec2 v_texCoords;
15+
16+
//https://stackoverflow.com/a/72973369
17+
vec4 blendOver(float4 a, float4 b) {
18+
float newAlpha = mix(b.w, 1.0, a.w);
19+
vec3 newColor = mix(b.w * b.xyz, a.xyz, a.w);
20+
float divideFactor = (newAlpha > 0.001 ? (1.0 / newAlpha) : 1.0);
21+
return float4(newColor * divideFactor, newAlpha);
22+
}
23+
24+
void main() {
25+
vec2 c = v_texCoords.xy;
26+
vec2 coords = (c * u_resolution) + u_campos;
27+
vec4 col = vec4(0.0);
28+
29+
for(int i = 0; i < u_blackholecount; ++i){
30+
vec4 blackhole = u_blackholes[i];
31+
float cX = blackhole.r;
32+
float cY = blackhole.g;
33+
float iR = blackhole.b;
34+
35+
float dst = distance(blackhole.xy, coords);
36+
if(dst < iR){ //Inside, clear
37+
gl_FragColor = vec4(0.0);
38+
return;
39+
}else if(dst > iR * MUL){ //Outside, skip
40+
continue;
41+
}else{ //Add
42+
float p = 1.0 - (dst - iR) / (iR * MUL - iR);
43+
vec4 c1 = u_colors[i];
44+
c1.a = p;
45+
46+
col = blendOver(col, c1);
47+
}
48+
}
49+
50+
gl_FragColor = col;
51+
}

src/progressed/graphics/Draw3D.java

+13-7
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,24 @@ public class Draw3D{
2525

2626
public static void init(){
2727
Events.run(Trigger.drawOver, () -> {
28-
Bloom bloom = renderer.bloom;
29-
if(bloom != null && bloomQueue.any()){
28+
if(bloomQueue.any()){
3029
bloomQueue.sort(q -> q.layer);
31-
Draw.draw(PMLayer.skyBloom, () -> {
32-
bloom.capture();
30+
Bloom bloom = renderer.bloom;
31+
if(bloom != null){
32+
Draw.draw(PMLayer.skyBloom, () -> {
33+
bloom.capture();
34+
for(QueuedBloom b : bloomQueue){
35+
b.draw.run();
36+
}
37+
bloom.render();
38+
});
39+
}else{
3340
for(QueuedBloom b : bloomQueue){
3441
b.draw.run();
3542
}
36-
bloom.render();
37-
});
43+
}
44+
bloomQueue.clear();
3845
}
39-
bloomQueue.clear();
4046
});
4147
}
4248

src/progressed/graphics/PMShaders.java

+28-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class PMShaders{
1717
public static AlphaShader alphaShader;
1818
public static DimShader dimShader;
1919
public static GravitationalLensingShader blackHole;
20+
public static AccretionDiskShader accretionDisk;
2021
public static PassThroughShader passThrough;
2122

2223
public static void init(){
@@ -32,10 +33,15 @@ public static void init(){
3233
}
3334

3435
public static void createBlackholeShader(){
35-
GravitationalLensingShader.len *= 2;
36+
if(blackHole != null){
37+
GravitationalLensingShader.len *= 2;
38+
blackHole.dispose();
39+
accretionDisk.dispose();
40+
}
41+
3642
Shader.prependFragmentCode = "#define MAX_COUNT " + GravitationalLensingShader.len + "\n";
37-
if(blackHole != null) blackHole.dispose();
3843
blackHole = new GravitationalLensingShader();
44+
accretionDisk = new AccretionDiskShader();
3945
Shader.prependFragmentCode = "";
4046
}
4147

@@ -158,7 +164,7 @@ public void apply(){
158164
}
159165

160166
public static class GravitationalLensingShader extends PMLoadShader{
161-
public static int len = 16 / 2;
167+
public static int len = 4;
162168
public float[] blackholes;
163169

164170
GravitationalLensingShader(){
@@ -175,6 +181,25 @@ public void apply(){
175181
}
176182
}
177183

184+
public static class AccretionDiskShader extends PMLoadShader{
185+
public float[] blackholes;
186+
public float[] colors;
187+
188+
AccretionDiskShader(){
189+
super("screenspace", "accretiondisk");
190+
}
191+
192+
@Override
193+
public void apply(){
194+
setUniformf("u_campos", Core.camera.position.x - Core.camera.width / 2, Core.camera.position.y - Core.camera.height / 2);
195+
setUniformf("u_resolution", Core.camera.width, Core.camera.height);
196+
197+
setUniformi("u_blackholecount", blackholes.length / 4);
198+
setUniform4fv("u_blackholes", blackholes, 0, blackholes.length);
199+
setUniform4fv("u_colors", colors, 0, colors.length);
200+
}
201+
}
202+
178203
static class PassThroughShader extends PMLoadShader{
179204
public PassThroughShader(){
180205
super("screenspace", "passThrough");

src/progressed/graphics/renders/BlackHoleRenderer.java

+24-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
import arc.graphics.g2d.*;
66
import arc.graphics.gl.*;
77
import arc.struct.*;
8+
import arc.util.*;
89
import mindustry.game.EventType.*;
910
import mindustry.graphics.*;
1011
import progressed.graphics.*;
1112
import progressed.graphics.PMShaders.*;
1213

1314
import static arc.Core.*;
15+
import static mindustry.Vars.renderer;
1416

1517
/** Renders the glowing area around black holes. (Do I even need this?) */
1618
public class BlackHoleRenderer{
@@ -40,19 +42,39 @@ public BlackHoleRenderer(){ //TODO setting
4042
if(zones.size >= GravitationalLensingShader.len) PMShaders.createBlackholeShader();
4143

4244
float[] blackholes = new float[zones.size * 4];
45+
float[] colors = new float[zones.size * 4];
4346
for(int i = 0; i < zones.size; i++){
4447
BlackHoleZone zone = zones.get(i);
4548
blackholes[i * 4] = zone.x;
4649
blackholes[i * 4 + 1] = zone.y;
4750
blackholes[i * 4 + 2] = zone.inRadius;
4851
blackholes[i * 4 + 3] = zone.outRadius;
52+
53+
Tmp.c1.abgr8888(zone.color);
54+
colors[i * 4] = Tmp.c1.r;
55+
colors[i * 4 + 1] = Tmp.c1.g;
56+
colors[i * 4 + 2] = Tmp.c1.b;
57+
colors[i * 4 + 3] = Tmp.c1.a;
4958
}
5059
PMShaders.blackHole.blackholes = blackholes;
5160
buffer.blit(PMShaders.blackHole);
5261

53-
zones.clear();
62+
PMShaders.accretionDisk.blackholes = blackholes;
63+
PMShaders.accretionDisk.colors = colors;
64+
buffer.begin();
65+
Draw.rect();
66+
buffer.end();
5467

55-
//TODO accretion disk
68+
Bloom bloom = renderer.bloom;
69+
if(bloom != null){
70+
bloom.capture();
71+
buffer.blit(PMShaders.accretionDisk);
72+
bloom.render();
73+
}else{
74+
buffer.blit(PMShaders.accretionDisk);
75+
}
76+
77+
zones.clear();
5678
});
5779
});
5880
}

0 commit comments

Comments
 (0)