java - LibGDX shader not working for FBO texture -
i have shader , want run shader on whole rendered image @ end instead of each individual sprite render on screen. purpose created fbo, render images fbo , render colorbuffertexture generated fbo. there 1 problem, shader not work when render fbo texture. withoutfbo() method render image shader working fine, withfbo() method renders image without shader. know shader in withfbo() working because if try render other colorbuffertexture fbo shader work. why isn't shader working texture generated fbo?
note: shader working code, problem doesn't work when use fbotexture. if call batch.draw(sprite, ...) shader work in both withfbo() , withoutfbo() methods, call batch.draw(fbotexture, ...) render fbo texture without applying shader.
public class application3 extends applicationadapter { float time; sprite sprite; framebuffer fbo; spritebatch batch; texture noisetexture; textureregion fbotexture; shaderprogram shaderprogram; @override public void create() { shaderprogram.pedantic = false; batch = new spritebatch(); sprite = new sprite(new texture("game.png")); sprite.setsize(gdx.graphics.getwidth(), gdx.graphics.getheight()); shaderprogram = new shaderprogram(gdx.files.internal(shader.glitch2.getvertex()), gdx.files.internal(shader.glitch2.getfragment())); noisetexture = new texture(gdx.files.internal(shader.glitch2.getpath() + "noise.png")); noisetexture.bind(0); fbo = new framebuffer(pixmap.format.rgba8888, gdx.graphics.getwidth(), gdx.graphics.getheight(), false); fbotexture = new textureregion(fbo.getcolorbuffertexture()); fbotexture.flip(false, true); } @override public void render() { //withfbo(); withoutfbo(); } void withoutfbo() { gdx.gl.glclearcolor(0, 0, 0, 1); gdx.gl.glclear(gl20.gl_color_buffer_bit); time += gdx.graphics.getdeltatime(); shaderprogram.setuniformi("u_noise", 0); shaderprogram.setuniformf("u_time", time); batch.setshader(shaderprogram); batch.begin(); batch.draw(sprite, sprite.getx(), sprite.gety(), sprite.getwidth(), sprite.getheight()); batch.setshader(null); batch.end(); } void withfbo() { gdx.gl.glclearcolor(0, 0, 0, 1); gdx.gl.glclear(gl20.gl_color_buffer_bit); time += gdx.graphics.getdeltatime(); fbo.begin(); batch.begin(); batch.draw(sprite, sprite.getx(), sprite.gety(), sprite.getwidth(), sprite.getheight()); batch.end(); fbo.end(); shaderprogram.setuniformi("u_noise", 0); shaderprogram.setuniformf("u_time", time); batch.setshader(shaderprogram); batch.begin(); batch.draw(fbotexture, sprite.getx(), sprite.gety(), sprite.getwidth(), sprite.getheight()); batch.setshader(null); batch.end(); } }
Comments
Post a Comment