Skip to content

Commit

Permalink
Chromatic aberration
Browse files Browse the repository at this point in the history
  • Loading branch information
MEEPofFaith committed Feb 8, 2024
1 parent fa421dd commit 5b790a1
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 58 deletions.
29 changes: 29 additions & 0 deletions assets/shaders/chromaticAberration.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#define HIGHP

uniform sampler2D u_texture;

uniform vec2 u_campos;
uniform vec2 u_resolution;
uniform float u_time;

varying vec2 v_texCoords;

void main() {
vec2 c = v_texCoords.xy;

float sTime = u_time / 60.0;
float amount = sin(sTime * 2.1);
amount += sin(sTime * 3.5);
amount += cos(sTime * 4.67);
amount += sin(sTime * 1.2);
amount *= 2.0;
amount /= u_resolution.x;

vec3 col = vec3(
texture2D(u_texture, vec2(c.x + amount, c.y)).r,
texture2D(u_texture, c).g,
texture2D(u_texture, vec2(c.x - amount, c.y)).b
);

gl_FragColor = vec4(col, 1.0);
}
4 changes: 1 addition & 3 deletions src/drunkustry/Drunkdustry.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import mindustry.game.EventType.*;
import mindustry.mod.*;

import static arc.Core.*;
import static mindustry.Vars.*;

public class Drunkdustry extends Mod{
Expand All @@ -22,8 +21,7 @@ public Drunkdustry(){
public void init(){
DrunkSound.init();
DrunkShaders.init();
DrunkColors.init();
DrunkWaves.init();
DrunkRendering.init();
}

private void loadSettings(){
Expand Down
28 changes: 0 additions & 28 deletions src/drunkustry/graphics/DrunkColors.java

This file was deleted.

48 changes: 48 additions & 0 deletions src/drunkustry/graphics/DrunkRendering.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package drunkustry.graphics;

import arc.*;
import arc.graphics.*;
import arc.graphics.g2d.*;
import arc.graphics.gl.*;
import mindustry.game.EventType.*;
import mindustry.graphics.*;

import static arc.Core.*;

public class DrunkRendering{
public static FrameBuffer colorBuffer;
public static FrameBuffer aberrationBuffer;
private static FrameBuffer distortionBuffer;

public static void init(){
colorBuffer = new FrameBuffer();
aberrationBuffer = new FrameBuffer();
distortionBuffer = new FrameBuffer();

Events.run(Trigger.draw, () -> {
colorBuffer.resize(graphics.getWidth(), graphics.getHeight());
aberrationBuffer.resize(graphics.getWidth(), graphics.getHeight());
distortionBuffer.resize(graphics.getWidth(), graphics.getHeight());

Draw.draw(Layer.background - 0.02f, () -> {
distortionBuffer.begin(Color.clear);
});
Draw.draw(Layer.background - 0.01f, () -> {
aberrationBuffer.begin(Color.clear);
});

Draw.draw(Layer.endPixeled + 1, () -> {
aberrationBuffer.end();
aberrationBuffer.blit(DrunkShaders.chromaticAberration);

colorBuffer.begin(Color.clear);
Draw.rect();
colorBuffer.end();
colorBuffer.blit(DrunkShaders.colorHallucination);

distortionBuffer.end();
distortionBuffer.blit(DrunkShaders.distortion);
});
});
}
}
2 changes: 2 additions & 0 deletions src/drunkustry/graphics/DrunkShaders.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@

public class DrunkShaders{
public static DrunkShader colorHallucination;
public static DrunkShader chromaticAberration;
public static DrunkShader distortion;

public static void init(){
colorHallucination = new DrunkShader("colorHallucination");
chromaticAberration = new DrunkShader("chromaticAberration");
distortion = new DrunkShader("distortion");
}

Expand Down
27 changes: 0 additions & 27 deletions src/drunkustry/graphics/DrunkWaves.java

This file was deleted.

0 comments on commit 5b790a1

Please sign in to comment.