improved bloom system
This commit is contained in:
@@ -86,7 +86,6 @@ public class CircularVisualizer implements Disposable {
|
||||
((OrthographicCamera) camera).setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||
|
||||
shader.begin();
|
||||
shader.setUniformMatrix("u_projTrans", camera.combined);
|
||||
mesh.render(shader, GL20.GL_LINE_STRIP, 0, vertexCount);
|
||||
shader.end();
|
||||
|
||||
|
@@ -34,17 +34,17 @@ public class BloomShader implements Disposable {
|
||||
Gdx.app.debug("Shader", "using glow shader");
|
||||
brightFilterShader = new ShaderProgram(Gdx.files.internal("shaders/basic.vsh"), Gdx.files.internal("shaders/bright_filter.fsh"));
|
||||
if (!brightFilterShader.isCompiled()) {
|
||||
Gdx.app.error("Shader failed to compile", brightFilterShader.getLog());
|
||||
System.exit(0);
|
||||
Gdx.app.error("Shader failed to compile bright filter shader", brightFilterShader.getLog());
|
||||
System.exit(1);
|
||||
}
|
||||
if (brightFilterShader.getLog().length() != 0) {
|
||||
Gdx.app.error("Shader", brightFilterShader.getLog());
|
||||
}
|
||||
|
||||
gaussianBlurShader = new ShaderProgram(Gdx.files.internal("shaders/basic.vsh"), Gdx.files.internal("shaders/gaussian_blur.fsh"));
|
||||
gaussianBlurShader = new ShaderProgram(Gdx.files.internal("shaders/gaussian_blur.vsh"), Gdx.files.internal("shaders/gaussian_blur.fsh"));
|
||||
if (!gaussianBlurShader.isCompiled()) {
|
||||
Gdx.app.error("Shader failed to compile", gaussianBlurShader.getLog());
|
||||
System.exit(0);
|
||||
Gdx.app.error("Shader failed to compile gaussian blur shader", gaussianBlurShader.getLog());
|
||||
System.exit(1);
|
||||
}
|
||||
if (gaussianBlurShader.getLog().length() != 0) {
|
||||
Gdx.app.error("Shader", gaussianBlurShader.getLog());
|
||||
@@ -52,8 +52,8 @@ public class BloomShader implements Disposable {
|
||||
|
||||
combineShader = new ShaderProgram(Gdx.files.internal("shaders/basic.vsh"), Gdx.files.internal("shaders/combine.fsh"));
|
||||
if (!combineShader.isCompiled()) {
|
||||
Gdx.app.error("Shader failed to compile", combineShader.getLog());
|
||||
System.exit(0);
|
||||
Gdx.app.error("Shader failed to compile combination shader", combineShader.getLog());
|
||||
System.exit(1);
|
||||
}
|
||||
if (combineShader.getLog().length() != 0) {
|
||||
Gdx.app.error("Shader", combineShader.getLog());
|
||||
@@ -71,10 +71,13 @@ public class BloomShader implements Disposable {
|
||||
combineShader.setUniformi("u_texture1", 1);
|
||||
combineShader.end();
|
||||
|
||||
gaussianBlurShader.begin();
|
||||
gaussianBlurShader.setUniformf("resolution", hBlur.getWidth(), vBlur.getHeight());
|
||||
gaussianBlurShader.end();
|
||||
|
||||
vBlur.getColorBufferTexture().bind(1);
|
||||
|
||||
Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0);
|
||||
ShaderProgram.pedantic = false;
|
||||
}
|
||||
|
||||
public void begin() {
|
||||
@@ -102,31 +105,46 @@ public class BloomShader implements Disposable {
|
||||
screenBatch.flush();
|
||||
lightFilterBuffer.end();
|
||||
|
||||
for (int i = 0; i <= bloomLevel; i++) {
|
||||
// Horizontal gaussian blur
|
||||
fboRegion.setTexture(lightFilterBuffer.getColorBufferTexture());
|
||||
hBlur.begin();
|
||||
screenBatch.setShader(gaussianBlurShader);
|
||||
gaussianBlurShader.setUniformf("radius", 1f + 0.2f*bloomLevel);
|
||||
gaussianBlurShader.setUniformi("pass", 0);
|
||||
screenBatch.draw(fboRegion, 0f, 0f, width, height);
|
||||
screenBatch.flush();
|
||||
hBlur.end();
|
||||
|
||||
|
||||
// //Vertical gaussian blur
|
||||
fboRegion.setTexture(hBlur.getColorBufferTexture());
|
||||
vBlur.begin();
|
||||
gaussianBlurShader.setUniformi("pass", 1);
|
||||
screenBatch.draw(fboRegion, 0f, 0f, width, height);
|
||||
screenBatch.flush();
|
||||
vBlur.end();
|
||||
|
||||
if (bloomLevel > 2) {
|
||||
// Horizontal gaussian blur
|
||||
if (i > 0) {
|
||||
fboRegion.setTexture(vBlur.getColorBufferTexture());
|
||||
} else {
|
||||
fboRegion.setTexture(lightFilterBuffer.getColorBufferTexture());
|
||||
}
|
||||
fboRegion.setTexture(vBlur.getColorBufferTexture());
|
||||
hBlur.begin();
|
||||
screenBatch.setShader(gaussianBlurShader);
|
||||
gaussianBlurShader.setUniformi("horizontal", 1);
|
||||
gaussianBlurShader.setUniformf("radius", 1.1f);
|
||||
gaussianBlurShader.setUniformi("pass", 0);
|
||||
screenBatch.draw(fboRegion, 0f, 0f, width, height);
|
||||
screenBatch.flush();
|
||||
hBlur.end();
|
||||
|
||||
|
||||
// //Vertical gaussian blur
|
||||
vBlur.begin();
|
||||
fboRegion.setTexture(hBlur.getColorBufferTexture());
|
||||
screenBatch.setShader(gaussianBlurShader);
|
||||
gaussianBlurShader.setUniformi("horizontal", 0);
|
||||
vBlur.begin();
|
||||
gaussianBlurShader.setUniformi("pass", 1);
|
||||
screenBatch.draw(fboRegion, 0f, 0f, width, height);
|
||||
screenBatch.flush();
|
||||
vBlur.end();
|
||||
}
|
||||
|
||||
Gdx.gl.glClearColor(0f, 0f, 0f, 0f);
|
||||
Gdx.gl.glClearColor(0f, 0f, 0f, 1f);
|
||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||
screenBatch.setShader(combineShader);
|
||||
fboRegion.setTexture(normalBuffer.getColorBufferTexture());
|
||||
|
Reference in New Issue
Block a user