Skip to content

Commit edeebe7

Browse files
committed
Added TV noise effect.
1 parent 6232cd9 commit edeebe7

9 files changed

Lines changed: 78 additions & 13 deletions

File tree

api/src/main/java/oxy/bascenario/api/effects/ScreenEffect.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ public enum ScreenEffect {
1111
FILM_GRAIN("Film Grain"),
1212
FILM_GRAIN_NO_TONE("Film Grain No Tone"),
1313
BLACK_AND_WHITE("Black And White"),
14-
NIGHT_VISION("Night Vision");
14+
NIGHT_VISION("Night Vision"),
15+
TV_NOISE("Tv Noise")
16+
;
1517

1618
private final String name;
1719

core/src/main/java/oxy/bascenario/screens/ScreenEffectScreen.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import oxy.bascenario.screens.renderer.effects.FilmGrainEffectRenderer;
99
import oxy.bascenario.screens.renderer.effects.ShiningEffectRenderer;
1010
import oxy.bascenario.screens.renderer.effects.SmokeEffectRenderer;
11+
import oxy.bascenario.screens.renderer.effects.TvNoiseEffectRenderer;
1112
import oxy.bascenario.utils.ExtendableScreen;
1213

1314
import java.util.HashSet;
@@ -22,11 +23,13 @@ public class ScreenEffectScreen extends ExtendableScreen {
2223
private final SmokeEffectRenderer smokeEffectRenderer = new SmokeEffectRenderer();
2324
private final ShiningEffectRenderer shiningEffectRenderer = new ShiningEffectRenderer();
2425
private final FilmGrainEffectRenderer filmGrainEffectRenderer = new FilmGrainEffectRenderer();
26+
private final TvNoiseEffectRenderer tvNoiseEffectRenderer = new TvNoiseEffectRenderer();
2527

2628
@Override
2729
public void show() {
2830
this.smokeEffectRenderer.init();
2931
this.filmGrainEffectRenderer.init();
32+
this.tvNoiseEffectRenderer.init();
3033
}
3134

3235
@Override
@@ -44,5 +47,9 @@ public void render(float delta) {
4447
if (effects.contains(ScreenEffect.FILM_GRAIN) || effects.contains(ScreenEffect.FILM_GRAIN_NO_TONE)) {
4548
filmGrainEffectRenderer.render(effects.contains(ScreenEffect.FILM_GRAIN));
4649
}
50+
51+
if (effects.contains(ScreenEffect.TV_NOISE)) {
52+
tvNoiseEffectRenderer.render();
53+
}
4754
}
4855
}

core/src/main/java/oxy/bascenario/screens/renderer/effects/FilmGrainEffectRenderer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ public void render(boolean tone) {
3232
time = System.currentTimeMillis();
3333
}
3434

35-
this.noise2.render(0, 0);
36-
this.noise1.render(0, 0);
35+
this.noise2.thisrendermethodsomehowworksandIdontknowwhy(0, 0);
36+
this.noise1.thisrendermethodsomehowworksandIdontknowwhy(0, 0);
3737

3838
if (tone) {
3939
ThinGL.renderer2D().filledRectangle(GLOBAL_RENDER_STACK, 0, 0, 1920, 1080, Color.fromRGB(255, 247, 167).withAlphaF(0.15f));

core/src/main/java/oxy/bascenario/screens/renderer/effects/SmokeEffectRenderer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ public void render(boolean add) {
4545
}
4646

4747
if (add) {
48-
sprite1.render(-400, 1080 - 100 * 1.6f);
48+
sprite1.thisrendermethodsomehowworksandIdontknowwhy(-400, 1080 - 100 * 1.6f);
4949
sprite1.addTileOffset(1, 0);
5050

51-
sprite.render(0, 1080 - 512 * 1.6f);
51+
sprite.thisrendermethodsomehowworksandIdontknowwhy(0, 1080 - 512 * 1.6f);
5252
sprite.addTileOffset(1, 0);
5353
}
5454

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package oxy.bascenario.screens.renderer.effects;
2+
3+
import net.lenni0451.commons.RandomUtils;
4+
import net.lenni0451.commons.color.Color;
5+
import net.raphimc.thingl.ThinGL;
6+
import oxy.bascenario.Base;
7+
import oxy.bascenario.utils.thingl.other.TilingSprite;
8+
9+
import static oxy.bascenario.utils.thingl.ThinGLUtils.GLOBAL_RENDER_STACK;
10+
11+
public class TvNoiseEffectRenderer {
12+
private long time;
13+
14+
private TilingSprite noise;
15+
16+
public void init() {
17+
this.noise = new TilingSprite(Base.instance().assetsManager().texture("assets/base/uis/effects/FX_TEX_Noise_42.png"));
18+
this.noise.width = 1920;
19+
this.noise.height = 1080;
20+
}
21+
22+
public void render() {
23+
if (System.currentTimeMillis() - time > 90) {
24+
this.noise.setTilePosition(RandomUtils.randomInt(0, 512), RandomUtils.randomInt(0, 512));
25+
time = System.currentTimeMillis();
26+
}
27+
28+
this.noise.thecorrectone(0, 0);
29+
ThinGL.renderer2D().coloredTexture(GLOBAL_RENDER_STACK, Base.instance().assetsManager().texture("assets/base/uis/effects/FX_TEX_GT_Circle_Blur_inv.png"), 0, 0, 1920, 1080, Color.BLACK.withAlphaF(0.4f));
30+
}
31+
}

core/src/main/java/oxy/bascenario/utils/thingl/other/TilingSprite.java

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,36 @@ public class TilingSprite {
1919
public int color = Color.WHITE.toRGB();
2020
public float rotation = 0;
2121

22-
public void render(float x, float y) {
22+
public void thecorrectone(float x, float y) {
23+
final float textureWidth = texture2D.getWidth(), textureHeight = texture2D.getHeight();
24+
25+
int totalTimesX = MathUtils.ceilInt(width / textureWidth);
26+
int totalTimesY = MathUtils.ceilInt(height / textureHeight);
27+
28+
for (int i = 0; i < totalTimesX; i++) {
29+
for (int n = 0; n < totalTimesY; n++) {
30+
GLOBAL_RENDER_STACK.pushMatrix();
31+
GLOBAL_RENDER_STACK.rotateZ(rotation);
32+
float tileX = x + i * textureWidth, tileY = y + n * textureHeight;
33+
GLOBAL_RENDER_STACK.translate(tileX, tileY, 0);
34+
GLOBAL_RENDER_STACK.scale(scale);
35+
36+
ThinGL.renderer2D().coloredTextureWithRawTexCoord(GLOBAL_RENDER_STACK,
37+
texture2D, 0, 0, textureWidth - tilePosition.x(), textureHeight,
38+
tilePosition.x() / textureWidth, tilePosition.y() / textureHeight,
39+
(textureWidth - tilePosition.x()) / textureWidth, 1, Color.fromRGB(color));
40+
41+
ThinGL.renderer2D().coloredTextureWithRawTexCoord(GLOBAL_RENDER_STACK,
42+
texture2D, (textureWidth - tilePosition.x()), 0, tilePosition.x(), textureHeight,
43+
0, tilePosition.y() / textureHeight,
44+
tilePosition.x() / textureWidth, 1, Color.fromRGB(color));
45+
46+
GLOBAL_RENDER_STACK.popMatrix();
47+
}
48+
}
49+
}
50+
51+
public void thisrendermethodsomehowworksandIdontknowwhy(float x, float y) {
2352
final float textureWidth = texture2D.getWidth(), textureHeight = texture2D.getHeight();
2453

2554
int totalTimesX = MathUtils.ceilInt(width / textureWidth);
@@ -58,7 +87,6 @@ public void setTilePosition(float x, float y) {
5887
while (newX > texture2D.getWidth()) {
5988
newX -= texture2D.getWidth();
6089
}
61-
System.out.println(newX);
6290
x = newX * Math.signum(x);
6391
}
6492

202 KB
Loading

core/src/test/java/DummyTest.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import imgui.ImGui;
2-
import net.lenni0451.commons.color.Color;
31
import oxy.bascenario.Base;
4-
import oxy.bascenario.api.utils.FileInfo;
52
import oxy.bascenario.utils.ExtendableScreen;
63
import oxy.bascenario.utils.Launcher;
74
import oxy.bascenario.utils.thingl.ThinGLUtils;
@@ -37,10 +34,10 @@ public void show() {
3734
public void render(float delta) {
3835
ThinGLUtils.start();
3936

40-
sprite1.render(-400, 1080 - 100 * 1.6f);
37+
sprite1.thisrendermethodsomehowworksandIdontknowwhy(-400, 1080 - 100 * 1.6f);
4138
sprite1.addTileOffset(1, 0);
4239

43-
sprite.render(0, 1080 - 512 * 1.6f);
40+
sprite.thisrendermethodsomehowworksandIdontknowwhy(0, 1080 - 512 * 1.6f);
4441
sprite.addTileOffset(1, 0);
4542

4643
ThinGLUtils.end();

core/src/test/java/scenario/ScreenEffectTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public static void main(String[] args) {
1515
final Scenario.Builder scenario = new Scenario.Builder();
1616

1717
scenario.add(0, new SetBackgroundEvent(FileInfo.internal("BG_BlackMarket.jpg"), 0));
18-
scenario.add(0, new ScreenEffectEvent(ScreenEffectEvent.Type.ADD, ScreenEffect.FILM_GRAIN));
18+
scenario.add(0, new ScreenEffectEvent(ScreenEffectEvent.Type.ADD, ScreenEffect.TV_NOISE));
1919

2020
Launcher.launch(new ScenarioScreen(scenario.build()), false);
2121
}

0 commit comments

Comments
 (0)