Created
September 24, 2019 13:15
-
-
Save metaphore/bfdc18ecf6c5155a19d88d14222dd83b to your computer and use it in GitHub Desktop.
GDX VFX transparency rendering test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.badlogic.gdx.ApplicationAdapter; | |
import com.badlogic.gdx.Gdx; | |
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application; | |
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration; | |
import com.badlogic.gdx.graphics.Color; | |
import com.badlogic.gdx.graphics.GL20; | |
import com.badlogic.gdx.graphics.OrthographicCamera; | |
import com.badlogic.gdx.graphics.Pixmap; | |
import com.badlogic.gdx.graphics.glutils.ShapeRenderer; | |
import com.badlogic.gdx.math.MathUtils; | |
import com.crashinvaders.vfx.VfxEffect; | |
import com.crashinvaders.vfx.VfxManager; | |
import com.crashinvaders.vfx.effects.MotionBlurEffect; | |
import com.crashinvaders.vfx.filters.MotionBlurFilter; | |
public class ShaderAlphaTest extends ApplicationAdapter { | |
private final Color clearColor = new Color(0xffffff00); | |
private ShapeRenderer shapeRenderer; | |
private OrthographicCamera camera; | |
private VfxManager vfxManager; | |
private VfxEffect vfxEffect; | |
private float time = 0f; | |
public static void main(String[] args) { | |
Lwjgl3ApplicationConfiguration config = new Lwjgl3ApplicationConfiguration(); | |
config.useVsync(true); | |
new Lwjgl3Application(new ShaderAlphaTest(), config); | |
} | |
@Override | |
public void create() { | |
super.create(); | |
camera = new OrthographicCamera(); | |
camera.setToOrtho(true); | |
shapeRenderer = new ShapeRenderer(); | |
vfxManager = new VfxManager(Pixmap.Format.RGBA8888); | |
vfxEffect = new MotionBlurEffect(Pixmap.Format.RGBA8888, MotionBlurFilter.BlurFunction.MAX, .75f); | |
vfxManager.addEffect(vfxEffect); | |
vfxManager.setBlendingEnabled(true); | |
} | |
@Override | |
public void render() { | |
Gdx.gl.glClearColor(0.392f, 0.584f, 0.929f, 1f); //cornflower blue | |
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); | |
time += Gdx.graphics.getRawDeltaTime() * 2f; | |
vfxManager.cleanUpBuffers(clearColor); | |
vfxManager.beginCapture(); | |
shapeRenderer.begin(ShapeRenderer.ShapeType.Filled); | |
shapeRenderer.setColor(Color.RED); | |
float halfWidth = Gdx.graphics.getWidth() / 2f; | |
float halfHeight = Gdx.graphics.getHeight() / 2f; | |
shapeRenderer.circle( | |
halfWidth + halfWidth * MathUtils.sin(time) * .8f, | |
halfHeight + halfHeight * MathUtils.sin(-time) * .8f, | |
40f * MathUtils.sin(time * .5f), | |
60 | |
); | |
shapeRenderer.setColor(Color.YELLOW); | |
shapeRenderer.circle( | |
halfWidth + halfWidth * MathUtils.sin(-time) * .8f, | |
halfHeight + halfHeight * MathUtils.sin(-time) * .8f, | |
40f * MathUtils.sin(time * .5f), | |
60 | |
); | |
shapeRenderer.end(); | |
vfxManager.endCapture(); | |
vfxManager.applyEffects(); | |
Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); | |
vfxManager.renderToScreen(); | |
} | |
public void resize(int width, int height) { | |
super.resize(width, height); | |
vfxManager.resize(width, height); | |
camera.setToOrtho(true); | |
shapeRenderer.setProjectionMatrix(camera.combined); | |
} | |
public void dispose() { | |
vfxManager.dispose(); | |
vfxEffect.dispose(); | |
shapeRenderer.dispose(); | |
super.dispose(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The code is written for GDX-VFX
0.4.3