added bloom shader
This commit is contained in:
@@ -9,9 +9,9 @@ import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
|
||||
import zero1hd.rhythmbullet.RhythmBullet;
|
||||
import zero1hd.rhythmbullet.stages.CreativeHUD;
|
||||
import zero1hd.rhythmbullet.stages.GameHUD;
|
||||
import zero1hd.rhythmbullet.stages.GamePlayArea;
|
||||
import zero1hd.rhythmbullet.stages.ui.CreativeHUD;
|
||||
import zero1hd.rhythmbullet.stages.ui.GameHUD;
|
||||
|
||||
public class CreativeScreen extends ScreenAdapter {
|
||||
CreativeHUD chud;
|
||||
@@ -19,9 +19,6 @@ public class CreativeScreen extends ScreenAdapter {
|
||||
GamePlayArea gamePlayArea;
|
||||
InputMultiplexer inputs;
|
||||
|
||||
SpriteBatch bgBatch;
|
||||
private Texture background;
|
||||
|
||||
Preferences prefs;
|
||||
|
||||
public CreativeScreen(RhythmBullet core, MainMenu mainMenu) {
|
||||
@@ -31,10 +28,6 @@ public class CreativeScreen extends ScreenAdapter {
|
||||
inputs = new InputMultiplexer(chud, ghud, gamePlayArea);
|
||||
|
||||
this.prefs = core.getPrefs();
|
||||
|
||||
background = core.getAssetManager().get("star_bg.png");
|
||||
bgBatch = new SpriteBatch(1);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -49,10 +42,6 @@ public class CreativeScreen extends ScreenAdapter {
|
||||
Gdx.gl.glClearColor(0.2f, 0.2f, 0.2f, 1f);
|
||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||
|
||||
bgBatch.begin();
|
||||
bgBatch.draw(background, 0f, 0f);
|
||||
bgBatch.end();
|
||||
|
||||
gamePlayArea.getViewport().apply();
|
||||
gamePlayArea.act();
|
||||
gamePlayArea.draw();
|
||||
|
@@ -5,9 +5,6 @@ import com.badlogic.gdx.InputMultiplexer;
|
||||
import com.badlogic.gdx.Screen;
|
||||
import com.badlogic.gdx.ScreenAdapter;
|
||||
import com.badlogic.gdx.graphics.GL20;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
|
||||
@@ -15,8 +12,8 @@ import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
|
||||
import zero1hd.rhythmbullet.RhythmBullet;
|
||||
import zero1hd.rhythmbullet.audio.CoreMusicInfo;
|
||||
import zero1hd.rhythmbullet.audio.map.GamePlayMap;
|
||||
import zero1hd.rhythmbullet.stages.GameHUD;
|
||||
import zero1hd.rhythmbullet.stages.GamePlayArea;
|
||||
import zero1hd.rhythmbullet.stages.ui.GameHUD;
|
||||
|
||||
public class GameScreen extends ScreenAdapter {
|
||||
private GamePlayArea gameArea;
|
||||
@@ -28,10 +25,6 @@ public class GameScreen extends ScreenAdapter {
|
||||
|
||||
private CoreMusicInfo music;
|
||||
|
||||
SpriteBatch bgBatch;
|
||||
private ShaderProgram bgShader;
|
||||
private Texture background;
|
||||
|
||||
public GameScreen(RhythmBullet core, Screen screen) {
|
||||
this.core = core;
|
||||
|
||||
@@ -53,25 +46,6 @@ public class GameScreen extends ScreenAdapter {
|
||||
inputs.addProcessor(gameHUD);
|
||||
inputs.addProcessor(gameArea);
|
||||
|
||||
background = core.getAssetManager().get("star_bg.png");
|
||||
|
||||
if (core.getPrefs().getBoolean("bg shader")) {
|
||||
Gdx.app.debug("Shader", "using background shader");
|
||||
|
||||
bgShader = new ShaderProgram(Gdx.files.internal("shaders/bg.vsh"), Gdx.files.internal("shaders/bg.fsh"));
|
||||
|
||||
if (!bgShader.isCompiled()) {
|
||||
System.err.println(bgShader.getLog());
|
||||
System.exit(0);
|
||||
}
|
||||
if (bgShader.getLog().length()!=0) {
|
||||
System.out.println(bgShader.getLog());
|
||||
}
|
||||
|
||||
bgBatch = new SpriteBatch(2, bgShader);
|
||||
} else {
|
||||
bgBatch = new SpriteBatch(2);
|
||||
}
|
||||
}
|
||||
|
||||
public void setGamePlayMap(GamePlayMap gpm) {
|
||||
@@ -97,20 +71,6 @@ public class GameScreen extends ScreenAdapter {
|
||||
public void render(float delta) {
|
||||
Gdx.gl.glClearColor(0f, 0f, 0f, 0f);
|
||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||
//Background stuff should literally span the whole screen so no matrice stuff
|
||||
bgBatch.begin();
|
||||
if (bgShader != null) {
|
||||
bgBatch.setShader(bgShader);
|
||||
bgShader.setUniformf("resolution", Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||
|
||||
if (music != null) {
|
||||
bgShader.setUniformf("time", music.getPlaybackMusic().getPosition());
|
||||
}
|
||||
}
|
||||
bgBatch.draw(background, 0f, 0f);
|
||||
bgBatch.end();
|
||||
|
||||
|
||||
//actual game and hud
|
||||
if (!gameHUD.isPaused()) {
|
||||
gameArea.act(delta);
|
||||
|
@@ -1,4 +1,4 @@
|
||||
package zero1hd.rhythmbullet.stages.ui;
|
||||
package zero1hd.rhythmbullet.stages;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Input.Keys;
|
||||
@@ -18,7 +18,6 @@ import zero1hd.rhythmbullet.audio.AudioAnalyzer;
|
||||
import zero1hd.rhythmbullet.audio.AudioDataPackage;
|
||||
import zero1hd.rhythmbullet.audio.map.RhythmMapAlgorithm;
|
||||
import zero1hd.rhythmbullet.screens.MainMenu;
|
||||
import zero1hd.rhythmbullet.stages.GamePlayArea;
|
||||
import zero1hd.rhythmbullet.ui.windows.BassUMGraphWindow;
|
||||
import zero1hd.rhythmbullet.ui.windows.BeatViewer;
|
||||
import zero1hd.rhythmbullet.ui.windows.DifficultyWindow;
|
||||
@@ -249,6 +248,8 @@ public class CreativeHUD extends Stage implements MiniListener {
|
||||
musicPlayBackControls.setAudiofile(null);
|
||||
analyzer = new AudioAnalyzer(musicSelector.getSelectedMusic());
|
||||
analyzer.sender.addListener(this);
|
||||
ghud.setMusic(null);
|
||||
|
||||
break;
|
||||
case SPECTRAL_FLUX_DONE:
|
||||
analyzer.runThresholdCleaning();
|
||||
@@ -265,7 +266,6 @@ public class CreativeHUD extends Stage implements MiniListener {
|
||||
musicPlayBackControls.setAudiofile(adp.getMusicInfo());
|
||||
volumeWindow.setMusic(adp.getMusicInfo());
|
||||
beatViewer.setMusic(adp.getMusicInfo(), analyzer.getAudioDataPackage());
|
||||
ghud.setMusic(null);
|
||||
|
||||
bassUMgraphWindow.setData(analyzer.getAudioDataPackage().getBassPeaks(), analyzer.getAudioDataPackage().getuMPeaks(), adp.getMusicInfo());
|
||||
bassUMgraphWindow.getGraph().avgG1 = adp.getBassAvg();
|
@@ -1,4 +1,4 @@
|
||||
package zero1hd.rhythmbullet.stages.ui;
|
||||
package zero1hd.rhythmbullet.stages;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Input.Keys;
|
||||
@@ -19,7 +19,6 @@ import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
|
||||
|
||||
import zero1hd.rhythmbullet.RhythmBullet;
|
||||
import zero1hd.rhythmbullet.stages.GamePlayArea;
|
||||
import zero1hd.rhythmbullet.ui.builders.HealthBar;
|
||||
import zero1hd.rhythmbullet.ui.windows.FPSWindow;
|
||||
import zero1hd.rhythmbullet.ui.windows.PauseMenu;
|
||||
@@ -142,7 +141,6 @@ public class GameHUD extends Stage {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
super.act(delta);
|
||||
}
|
||||
|
@@ -35,9 +35,13 @@ public class GamePlayArea extends Stage {
|
||||
|
||||
public ScoreManager score = new ScoreManager();
|
||||
|
||||
private ShaderProgram glowShader;
|
||||
private FrameBuffer blurTarget;
|
||||
TextureRegion fboRegion;
|
||||
private ShaderProgram gaussianBlurShader;
|
||||
private ShaderProgram brightFilterShader;
|
||||
private ShaderProgram combineShader;
|
||||
private FrameBuffer lightFilterBuffer;
|
||||
private FrameBuffer normalBuffer;
|
||||
private FrameBuffer hBlur, vBlur;
|
||||
private TextureRegion fboRegion;
|
||||
private int fboSize;
|
||||
|
||||
public GamePlayArea(AssetManager assetManager, Preferences prefs) {
|
||||
@@ -63,32 +67,62 @@ public class GamePlayArea extends Stage {
|
||||
|
||||
/**
|
||||
* needs to be called right after set as screen (should be called in show method).
|
||||
* This is due to the saving preference being done once the screen is hidden.
|
||||
* @param prefs
|
||||
*/
|
||||
public void loadShaders(Preferences prefs) {
|
||||
if (prefs.getBoolean("glow shader")) {
|
||||
Gdx.app.debug("Shader", "using glow shader");
|
||||
glowShader = new ShaderProgram(Gdx.files.internal("shaders/glow.vsh"), Gdx.files.internal("shaders/glow.fsh"));
|
||||
if (!glowShader.isCompiled()) {
|
||||
System.err.println(glowShader.getLog());
|
||||
brightFilterShader = new ShaderProgram(Gdx.files.internal("shaders/basic.vsh"), Gdx.files.internal("shaders/bright_filter.fsh"));
|
||||
if (!brightFilterShader.isCompiled()) {
|
||||
System.err.println(brightFilterShader.getLog());
|
||||
System.exit(0);
|
||||
}
|
||||
if (glowShader.getLog().length() != 0) {
|
||||
System.out.println(glowShader.getLog());
|
||||
if (brightFilterShader.getLog().length() != 0) {
|
||||
System.out.println(brightFilterShader.getLog());
|
||||
}
|
||||
|
||||
gaussianBlurShader = new ShaderProgram(Gdx.files.internal("shaders/basic.vsh"), Gdx.files.internal("shaders/gaussian_blur.fsh"));
|
||||
if (!gaussianBlurShader.isCompiled()) {
|
||||
System.err.println(gaussianBlurShader.getLog());
|
||||
System.exit(0);
|
||||
}
|
||||
if (gaussianBlurShader.getLog().length() != 0) {
|
||||
System.out.println(gaussianBlurShader.getLog());
|
||||
}
|
||||
|
||||
combineShader = new ShaderProgram(Gdx.files.internal("shaders/basic.vsh"), Gdx.files.internal("shaders/combine.fsh"));
|
||||
if (!combineShader.isCompiled()) {
|
||||
System.err.println(combineShader.getLog());
|
||||
System.exit(0);
|
||||
}
|
||||
if (combineShader.getLog().length() != 0) {
|
||||
System.out.println(combineShader.getLog());
|
||||
}
|
||||
|
||||
|
||||
if (Gdx.graphics.getWidth() < 1024) {
|
||||
fboSize = 1024;
|
||||
} else if (Gdx.graphics.getWidth() < 2048) {
|
||||
fboSize = 2048;
|
||||
} else if (Gdx.graphics.getWidth() < 2048) {
|
||||
fboSize = 4096;
|
||||
} else {
|
||||
fboSize = 4096;
|
||||
}
|
||||
|
||||
blurTarget = new FrameBuffer(Format.RGBA8888, fboSize, fboSize, false);
|
||||
|
||||
fboRegion = new TextureRegion(blurTarget.getColorBufferTexture());
|
||||
fboRegion.flip(false, true);
|
||||
lightFilterBuffer = new FrameBuffer(Format.RGBA8888, fboSize/4, fboSize/4, false);
|
||||
normalBuffer = new FrameBuffer(Format.RGBA8888, fboSize, fboSize, false);
|
||||
hBlur = new FrameBuffer(Format.RGBA8888, fboSize, fboSize, false);
|
||||
vBlur = new FrameBuffer(Format.RGBA8888, fboSize, fboSize, false);
|
||||
|
||||
fboRegion = new TextureRegion();
|
||||
|
||||
combineShader.begin();
|
||||
combineShader.setUniformi("u_texture1", 1);
|
||||
combineShader.end();
|
||||
|
||||
vBlur.getColorBufferTexture().bind(1);
|
||||
|
||||
Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0);
|
||||
}
|
||||
|
||||
ShaderProgram.pedantic = false;
|
||||
@@ -96,27 +130,52 @@ public class GamePlayArea extends Stage {
|
||||
|
||||
@Override
|
||||
public void draw() {
|
||||
//TODO batch draw background
|
||||
if (glowShader != null) {
|
||||
blurTarget.begin();
|
||||
|
||||
if (gaussianBlurShader != null) {
|
||||
//Begin drawing a normal version of screen
|
||||
normalBuffer.begin();
|
||||
Gdx.gl.glClearColor(0f, 0f, 0f, 0f);
|
||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||
getBatch().setBlendFunction(-1, -1);
|
||||
Gdx.gl20.glBlendFuncSeparate(GL20.GL_ONE, GL20.GL_ONE_MINUS_SRC_ALPHA,GL20.GL_ONE, GL20.GL_DST_ALPHA);
|
||||
super.draw();
|
||||
collisionDetector.renderParticles(getBatch(), Gdx.graphics.getDeltaTime(), true);
|
||||
blurTarget.end(getViewport().getScreenX(), getViewport().getScreenY(), getViewport().getScreenWidth(), getViewport().getScreenHeight());
|
||||
getBatch().setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
|
||||
normalBuffer.end(getViewport().getScreenX(), getViewport().getScreenY(), getViewport().getScreenWidth(), getViewport().getScreenHeight());
|
||||
//END
|
||||
|
||||
getBatch().setBlendFunction(GL20.GL_ONE, GL20.GL_ONE_MINUS_SRC_ALPHA);
|
||||
getBatch().begin();
|
||||
getBatch().setShader(glowShader);
|
||||
//Begin light filtering
|
||||
lightFilterBuffer.begin();
|
||||
Gdx.gl.glClearColor(0f, 0f, 0f, 0f);
|
||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||
getBatch().setShader(brightFilterShader);
|
||||
getBatch().begin(); //BATCH STARTS HERE
|
||||
getRoot().draw(getBatch(), 1f);
|
||||
getBatch().flush();
|
||||
lightFilterBuffer.end(getViewport().getScreenX(), getViewport().getScreenY(), getViewport().getScreenWidth(), getViewport().getScreenHeight());
|
||||
|
||||
//Horizontal gaussian blur
|
||||
hBlur.begin();
|
||||
fboRegion.setTexture(lightFilterBuffer.getColorBufferTexture());
|
||||
getBatch().setShader(gaussianBlurShader);
|
||||
gaussianBlurShader.setUniformf("horizontal", 1);
|
||||
getBatch().draw(fboRegion, 0f, 0f, RhythmBullet.GAME_AREA_WIDTH, RhythmBullet.GAME_AREA_HEIGHT);
|
||||
getBatch().flush();
|
||||
hBlur.end(getViewport().getScreenX(), getViewport().getScreenY(), getViewport().getScreenWidth(), getViewport().getScreenHeight());
|
||||
|
||||
//Vertical gaussian blur
|
||||
vBlur.begin();
|
||||
fboRegion.setTexture(hBlur.getColorBufferTexture());
|
||||
getBatch().setShader(gaussianBlurShader);
|
||||
gaussianBlurShader.setUniformf("horizontal", 0);
|
||||
getBatch().draw(fboRegion, 0f, 0f, RhythmBullet.GAME_AREA_WIDTH, RhythmBullet.GAME_AREA_HEIGHT);
|
||||
getBatch().flush();
|
||||
vBlur.end(getViewport().getScreenX(), getViewport().getScreenY(), getViewport().getScreenWidth(), getViewport().getScreenHeight());
|
||||
|
||||
//Draw everything to screen
|
||||
getBatch().setShader(combineShader);
|
||||
fboRegion.setRegion(normalBuffer.getColorBufferTexture());
|
||||
fboRegion.flip(false, true);
|
||||
getBatch().draw(fboRegion, 0f, 0f, RhythmBullet.GAME_AREA_WIDTH, RhythmBullet.GAME_AREA_HEIGHT);
|
||||
getBatch().setShader(null);
|
||||
getBatch().end(); //BATCH ENDS HERE
|
||||
|
||||
getBatch().end();
|
||||
|
||||
} else {
|
||||
super.draw();
|
||||
}
|
||||
@@ -162,7 +221,7 @@ public class GamePlayArea extends Stage {
|
||||
polyjet.moveUp = true;
|
||||
}
|
||||
|
||||
if (keycode == KeyMap.down) {
|
||||
if (keycode == KeyMap.down) {
|
||||
polyjet.moveDown = true;
|
||||
}
|
||||
|
||||
@@ -205,11 +264,10 @@ public class GamePlayArea extends Stage {
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
if (glowShader != null) {
|
||||
blurTarget.dispose();
|
||||
glowShader.dispose();
|
||||
if (gaussianBlurShader != null) {
|
||||
normalBuffer.dispose();
|
||||
gaussianBlurShader.dispose();
|
||||
}
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user