Je dessine des choses sur un FBO dans libgdx. Que je veux juste dessiner ce fbo avec un fond TRANSPARENT à mon écran. Mais c'est toujours noir.Libgdx fbo transparence d'arrière-plan
Est-il possible d'utiliser un arrière-plan transparent sur le spriteBatch? J'ai essayé beaucoup de choses, mais il semble que je ne peux pas supporter cette tâche simple.
J'ai créé un shader personnalisé et:
vec4 orig = texture2D(u_texture, tc);
if (orig.a==0.0) discard;
ths OIR créer un code:
fbo = new FrameBuffer(Format.RGB565, width, height, hasDepth);
que:
public void begin() {
fbo.begin();
Gdx.gl.glClearColor(1.0f, 0.0f, 0.0f, 0f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
}
public void render() {
renderIt();
}
private void renderIt() {
spriteBatch.begin();
spriteBatch.setShader(shader);
spriteBatch.draw(fboRegion, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
spriteBatch.end();
}
public void end() {
Gdx.gl.glDisable(GLES20.GL_BLEND);
fbo.end();
}
On dirait que le shader ne peut pas d'une durée déterminée des valeurs alpha du FBO . Pourquoi? J'ai juste besoin d'effacer les alpha = 0.0 pixels.
Donc, dans mon shaders l'arrière-plan découpé:
if (orig.r==1.0) discard;
ce travaille
if (orig.a==0.0) discard;
if (orig.a<0.2) discard;
if (orig.a<0.9) discard;
CECI EST PAS
mon shaders ressemble à ce
void main() {
vec4 sum = vec4(0.0);
vec2 tc = v_texCoord0;
//the amount to blur, i.e. how far off center to sample from
//1.0 -> blur by one pixel
//2.0 -> blur by two pixels, etc.
float blur = radius/resolution;
//the direction of our blur
//(1.0, 0.0) -> x-axis blur
//(0.0, 1.0) -> y-axis blur
float hstep = dir.x;
float vstep = dir.y;
sum += texture2D(u_texture, vec2(tc.x - 4.0*blur*hstep, tc.y - 4.0*blur*vstep)) * 0.0162162162;
sum += texture2D(u_texture, vec2(tc.x - 3.0*blur*hstep, tc.y - 3.0*blur*vstep)) * 0.0540540541;
sum += texture2D(u_texture, vec2(tc.x - 2.0*blur*hstep, tc.y - 2.0*blur*vstep)) * 0.1216216216;
sum += texture2D(u_texture, vec2(tc.x - 1.0*blur*hstep, tc.y - 1.0*blur*vstep)) * 0.1945945946;
sum += texture2D(u_texture, vec2(tc.x, tc.y)) * 0.2270270270;
sum += texture2D(u_texture, vec2(tc.x + 1.0*blur*hstep, tc.y + 1.0*blur*vstep)) * 0.1945945946;
sum += texture2D(u_texture, vec2(tc.x + 2.0*blur*hstep, tc.y + 2.0*blur*vstep)) * 0.1216216216;
sum += texture2D(u_texture, vec2(tc.x + 3.0*blur*hstep, tc.y + 3.0*blur*vstep)) * 0.0540540541;
sum += texture2D(u_texture, vec2(tc.x + 4.0*blur*hstep, tc.y + 4.0*blur*vstep)) * 0.0162162162;
vec4 all = v_color * vec4(sum.rgb, 1.0);
if (all.a < 0.9) discard;
else gl_FragColor = all;
}
Peut-être assurez-vous que l'alpha est vraiment 0 en testant 'orig .a <0.1' ou quelque chose. Cela pourrait être très proche de 0 pour une raison quelconque. – Charanor
vec4 orig = texture2D (u_texture, tc); si (orig.a <0.2) rejeter; essayé mais aussi pas de travail ... l'arrière-plan est juste ROUGE. Il semble que ne peut pas voir l'alpha de GL clearcolor ce qui est défini à 0.0 – lacas