Skip to content

Commit

Permalink
Bind distortion to noise instead of time
Browse files Browse the repository at this point in the history
WHY IS IT DESTROYING THE UI
  • Loading branch information
MEEPofFaith committed Feb 7, 2024
1 parent de7dc11 commit 51abc10
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 30 deletions.
2 changes: 1 addition & 1 deletion assets/shaders/drunk.frag
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ vec3 hsv2rgb(vec3 c)

void main(){
vec2 c = v_texCoords.xy;
vec2 coords = vec2(c.x * u_resolution.x + u_campos.x, c.y * u_resolution.y + u_campos.y);
vec2 coords = (c * u_resolution) + u_campos;

float btime = u_time / 3000.0;
float noise = (texture2D(u_noise, (coords) / NSCALE + vec2(btime) * vec2(-0.9, 0.8)).r +
Expand Down
25 changes: 17 additions & 8 deletions assets/shaders/drunkWaves.frag
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#define HIGHP

#define PI 3.1415926535897932384626433832795
#define NSCALE 600.0 / 2.0

uniform sampler2D u_texture;
uniform sampler2D u_noise;

uniform vec2 u_campos;
uniform vec2 u_resolution;
Expand All @@ -11,14 +13,21 @@ uniform float u_time;
varying vec2 v_texCoords;

void main() {
vec2 T = v_texCoords.xy;
vec2 coords = (T * u_resolution) + u_campos;
float btime = u_time / 20.0;
T += vec2(sin(coords.y / 5.0 + btime), sin(coords.x / 5.0 + btime)) / u_resolution * 2;
vec2 c = v_texCoords.xy;
vec2 coords = (c * u_resolution) + u_campos;

//float btime = u_time / 50.0;
//vec2 pos = v_texCoords + u_campos / u_resolution;
//vec2 c = vec2(pos.x + sin(btime + pos.y * 2.0 * PI) * mag, pos.y);
float wTime = u_time / 3000.0;
vec2 sNoise = (vec2(
texture2D(u_noise, (coords) / NSCALE + vec2(wTime) * vec2(-0.4, 1.2)).r +
texture2D(u_noise, (coords) / NSCALE + vec2(wTime * 1.3) * vec2(0.9, -0.7)).r,
texture2D(u_noise, (coords) / NSCALE + vec2(wTime) * vec2(0.7, 0.3)).r +
texture2D(u_noise, (coords) / NSCALE + vec2(wTime * 1.2) * vec2(-0.5, -0.4)).r
) - 1) * 2.0 * 2.0 * PI;
float oNoise = (texture2D(u_noise, (coords) / NSCALE + vec2(wTime * 1.5) * vec2(-0.8, -0.7)).r +
texture2D(u_noise, (coords) / NSCALE + vec2(wTime * 1.1) * vec2(1.3, 0.3)).r - 0.5) * 2.0;

gl_FragColor = texture2D(u_texture, T);
vec2 off = vec2(sin(coords.y / 5.0 + sNoise.x), sin(coords.x / 5.0 + sNoise.y)) / u_resolution * 2.0 * oNoise;
c += off;

gl_FragColor = texture2D(u_texture, c);
}
2 changes: 1 addition & 1 deletion src/drunkustry/graphics/DrunkColors.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static void init(){

Events.run(Trigger.drawOver, () -> {
drunkBuffer.resize(graphics.getWidth(), graphics.getHeight());
Draw.draw(Layer.max, () -> {
Draw.draw(Layer.endPixeled + 2, () -> {
drunkBuffer.begin(Color.clear);
Draw.rect();
drunkBuffer.end();
Expand Down
19 changes: 2 additions & 17 deletions src/drunkustry/graphics/DrunkShaders.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,11 @@

public class DrunkShaders{
public static DrunkShader drunkShader;
public static DrunkWaves drunkWaves;
public static DrunkShader drunkWaves;

public static void init(){
drunkShader = new DrunkShader("drunk");
drunkWaves = new DrunkWaves();
}

public static class DrunkWaves extends Shader{
public DrunkWaves(){
super(getShaderFi("screenspace.vert"), getShaderFi("drunkWaves.frag"));
}

@Override
public void apply(){
setUniformf("u_campos", Core.camera.position.x - Core.camera.width / 2, Core.camera.position.y - Core.camera.height / 2);
setUniformf("u_resolution", Core.camera.width, Core.camera.height);
setUniformf("u_time", Time.time);
}
drunkWaves = new DrunkShader("drunkWaves");
}

/** Copy of {@link SurfaceShader} that's able to get my shader. */
Expand Down Expand Up @@ -71,8 +58,6 @@ public void apply(){
}

noiseTex.bind(1);
renderer.effectBuffer.getTexture().bind(0);

setUniformi("u_noise", 1);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/drunkustry/graphics/DrunkWaves.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ public class DrunkWaves{
public static void init(){
wavesBuffer = new FrameBuffer();

Events.run(Trigger.draw, () -> wavesBuffer.resize(graphics.getWidth(), graphics.getHeight()));
Events.run(Trigger.drawOver, () -> {
Draw.draw(Layer.min, () -> wavesBuffer.begin(Color.clear));
Draw.draw(Layer.max, () -> {
wavesBuffer.resize(graphics.getWidth(), graphics.getHeight());
Draw.draw(Layer.background - 0.01f, () -> wavesBuffer.begin(Color.clear));
Draw.draw(Layer.endPixeled + 4, () -> {
wavesBuffer.end();
wavesBuffer.blit(DrunkShaders.drunkWaves);
});
Expand Down

0 comments on commit 51abc10

Please sign in to comment.