@Override public void render () { frameBuffer.begin(); Gdx.gl20.glViewport(0, 0, frameBuffer.getWidth(), frameBuffer.getHeight()); Gdx.gl20.glClearColor(0f, 1f, 0f, 1); Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT); mesh.render(meshShader, GL20.GL_TRIANGLES); meshShader.end(); frameBuffer.end(); stencilFrameBuffer.begin(); Gdx.gl20.glViewport(0, 0, frameBuffer.getWidth(), frameBuffer.getHeight()); Gdx.gl20.glClearColor(1f, 1f, 0f, 1); Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_STENCIL_BUFFER_BIT); stencilFrameBuffer.end(); spriteBatch.draw(frameBuffer.getColorBufferTexture(), 0, 0, 256, 256, 0, 0, frameBuffer.getColorBufferTexture().getWidth(), frameBuffer.getColorBufferTexture().getHeight(), false, true); spriteBatch.draw(stencilFrameBuffer.getColorBufferTexture(), 256, 256, 256, 256, 0, 0, frameBuffer.getColorBufferTexture() .getWidth(), frameBuffer.getColorBufferTexture().getHeight(), false, true); spriteBatch.end();
@Override public FrameBuffer build () { return new FrameBuffer(this); } }
@Override public void dispose () { if (fbo != null) fbo.dispose(); fbo = null; } }
public void begin () { final int w = fbo.getWidth(); final int h = fbo.getHeight(); fbo.begin(); Gdx.gl.glViewport(0, 0, w, h); Gdx.gl.glClearColor(1, 1, 1, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT); Gdx.gl.glEnable(GL20.GL_SCISSOR_TEST); Gdx.gl.glScissor(1, 1, w - 2, h - 2); }
m_fboRegion = new TextureRegion(m_fbo.getColorBufferTexture()); m_fboRegion.flip(false, true); m_fbo.begin(); m_fbo.end();
public void render () { angle += 45 * Gdx.graphics.getDeltaTime(); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT); cam.update(); matrix.setToRotation(0, 1, 0, angle); cam.combined.mul(matrix); fbo.begin(); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT); Gdx.gl.glEnable(GL20.GL_DEPTH_TEST); modelBatch.begin(cam); modelBatch.render(sceneInstance); modelBatch.end(); fbo.end(); batch.begin(); batch.disableBlending(); batchShader.setUniformi("u_filterSize", filter.length); batchShader.setUniform1fv("u_filter", filter, 0, filter.length); batchShader.setUniform2fv("u_offsets", offsets, 0, offsets.length); batch.draw(fboRegion, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); batch.end(); logger.log(); } }
@Override public void render (FrameBuffer src, FrameBuffer dest) { restoreViewport(dest); if (dest != null) { motionFilter.setInput(src).setOutput(dest).render(); fbo = dest; } else { if (fbo == null) { // Init frame buffer fbo = new FrameBuffer(Format.RGBA8888, src.getWidth(), src.getHeight(), false); } motionFilter.setInput(src).setOutput(fbo).render(); // Copy fbo to screen copyFilter.setInput(fbo).setOutput(dest).render(); } // Set last frame motionFilter.setLastFrameTexture(fbo.getColorBufferTexture()); }
@Override public TextureDescriptor getDepthMap () { textureDesc.texture = fbo.getColorBufferTexture(); return textureDesc; }
frameBuffer.begin(); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT); frameBuffer.end(); renderContext.textureBinder.bind(frameBuffer.getTextureAttachments().get(DIFFUSE_ATTACHMENT))); mrtSceneShader.setUniformi("u_normalTexture", renderContext.textureBinder.bind(frameBuffer.getTextureAttachments().get(NORMAL_ATTACHMENT))); mrtSceneShader.setUniformi("u_positionTexture", renderContext.textureBinder.bind(frameBuffer.getTextureAttachments().get(POSITION_ATTACHMENT))); mrtSceneShader.setUniformi("u_depthTexture", renderContext.textureBinder.bind(frameBuffer.getTextureAttachments().get(DEPTH_ATTACHMENT))); for (int i = 0; i < lights.size; i++) { Light light = lights.get(i); batch.draw(frameBuffer.getTextureAttachments().get(DIFFUSE_ATTACHMENT), 0, 0, Gdx.graphics.getWidth() / 4f, Gdx.graphics.getHeight() / 4f, 0f, 0f, 1f, 1f); batch.draw(frameBuffer.getTextureAttachments().get(NORMAL_ATTACHMENT), Gdx.graphics.getWidth() / 4f, 0, Gdx.graphics.getWidth() / 4f, Gdx.graphics.getHeight() / 4f, 0f, 0f, 1f, 1f); batch.draw(frameBuffer.getTextureAttachments().get(POSITION_ATTACHMENT), 2 * Gdx.graphics.getWidth() / 4f, 0, Gdx.graphics.getWidth() / 4f, Gdx.graphics.getHeight() / 4f, 0f, 0f, 1f, 1f); batch.draw(frameBuffer.getTextureAttachments().get(DEPTH_ATTACHMENT), 3 * Gdx.graphics.getWidth() / 4f, 0, Gdx.graphics.getWidth() / 4f, Gdx.graphics.getHeight() / 4f, 0f, 0f, 1f, 1f); batch.end();
/** End pass n. * @param n Pass number */ protected void endPass (int n) { frameBuffers[n].end(); }
@Override public void resize(int width, int height) { this.width = width; this.height = height; if (frameBuffer != null) frameBuffer.dispose(); frameBuffer = new FrameBuffer(Pixmap.Format.RGB565, width, height, false); bufferTexture = new TextureRegion(frameBuffer.getColorBufferTexture()); bufferTexture.flip(false, true); }
public void create () { ShaderProgram.pedantic = false; /* * shader = new ShaderProgram(Gdx.files.internal("data/shaders/default.vert").readString(), Gdx.files.internal( * "data/shaders/depthtocolor.frag").readString()); if (!shader.isCompiled()) { Gdx.app.log("EdgeDetectionTest", * "couldn't compile scene shader: " + shader.getLog()); } */ batchShader = new ShaderProgram(Gdx.files.internal("data/shaders/batch.vert").readString(), Gdx.files.internal( "data/shaders/convolution.frag").readString()); if (!batchShader.isCompiled()) { Gdx.app.log("EdgeDetectionTest", "couldn't compile post-processing shader: " + batchShader.getLog()); } ObjLoader objLoader = new ObjLoader(); scene = objLoader.loadModel(Gdx.files.internal("data/scene.obj")); sceneInstance = new ModelInstance(scene); modelBatch = new ModelBatch(); fbo = new FrameBuffer(Format.RGB565, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true); cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); cam.position.set(0, 0, 10); cam.lookAt(0, 0, 0); cam.far = 30; batch = new SpriteBatch(); batch.setShader(batchShader); fboRegion = new TextureRegion(fbo.getColorBufferTexture()); fboRegion.flip(false, true); logger = new FPSLogger(); calculateOffsets(); }
/** Begin pass n. * @param n Pass number */ protected void beginPass (int n) { frameBuffers[n].begin(); };
private void applyBlur(float blur) { // Horizontal blur from FBO A to FBO B fboB.begin(); batch.setShader(shader); shader.setUniformf("dir", 1.0f, 0.0f); shader.setUniformf("radius", blur); Gdx.gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); drawTexture(fboA.getColorBufferTexture(), 0.0f, 0.0f); batch.flush(); fboB.end(); // Vertical blur from FBO B to the screen shader.setUniformf("dir", 0.0f, 1.0f); shader.setUniformf("radius", blur); drawTexture(fboB.getColorBufferTexture(), 0.0f, 0.0f); batch.flush(); }
@Override public void render (FrameBuffer src, FrameBuffer dest) { restoreViewport(dest); if (dest != null) { motionFilter.setInput(src).setOutput(dest).render(); fbo = dest; } else { if (fbo == null) { // Init frame buffer fbo = new FrameBuffer(Format.RGBA8888, src.getWidth(), src.getHeight(), false); } motionFilter.setInput(src).setOutput(fbo).render(); // Copy fbo to screen copyFilter.setInput(fbo).setOutput(dest).render(); } // Set last frame motionFilter.setLastFrameTexture(fbo.getColorBufferTexture()); }
public void begin () { final int w = fbo.getWidth(); final int h = fbo.getHeight(); fbo.begin(); Gdx.gl.glViewport(0, 0, w, h); Gdx.gl.glClearColor(1, 1, 1, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT); Gdx.gl.glEnable(GL20.GL_SCISSOR_TEST); Gdx.gl.glScissor(1, 1, w - 2, h - 2); }
@Override public TextureDescriptor getDepthMap () { textureDesc.texture = fbo.getColorBufferTexture(); return textureDesc; }
public void end () { Gdx.gl.glDisable(GL20.GL_SCISSOR_TEST); fbo.end(); }