Strange blit behavior with black pixels

Started by MrFluff, June 09, 2011, 02:05:49 PM

Previous topic - Next topic

MrFluff


I am facing a strange blit behavior when drawing textures on the screen:

When drawing an image that contains (nearly) black pixels, they get drawn transparent. This is what someone might expect when reading the docs about
FrameBuffer.blit(Texture src,
                 int srcX,
                 int srcY,
                 int destX,
                 int destY,
                 int width,
                 int height,
                 boolean transparent)

using TRANSPARENT_BLITTING.

Unfortunately, the drawing does not work correctly, and even if it would work with OPAQUE_BLITTING (which had the same behavior) I cannot use it as these images interfere with other transparent textures that are attached to 3d models (when a plane with a glow texture intersects my drawing image, no pixels of the 3d scene are drawn and the camera image in the background is fully visible on these intersecting pixels).

I thought that using the method
FrameBuffer.blit(Texture src,
                 int srcX,
                 int srcY,
                 int destX,
                 int destY,
                 int sourceWidth,
                 int sourceHeight,
                 int destWidth,
                 int destHeight,
                 int transValue,
                 boolean additive,
                 RGBColor addColor)


might help but I failed in getting another outcome than the one shown in the image.

Is there any possibility in preventing this filtering of (nearly) black pixels?

[attachment deleted by admin]

EgonOlsen

By default, jPCT generates an alpha channel based on the black pixels in the texture. If you don't want that behaviour, use a texture with it's own alpha channel (png is good format for that) and load it using one of the useAlpha-constructors of Texture.

The other problem (OPAQUE_BLITTING) being transparent comes from the fact that your framebuffer uses alpha too and the alpha of the blitted texture will simply be copied into the framebuffer, which looks like as if it were a transparent blit which it actually isn't. What i don't get from your post is, if that overdraw problem, where the blit overdraws the rendered scene also happens when using a transparent blit. In that case, please let me know and i'll add an option to suppress this.

MrFluff


Hi EgonOlsen,

Thx for reply - setting useOpaque of the texture solved the problem.

I am not sure if I understand your penultimate sentence but i'll try to explain what happened.

My problem was as follows:

I have a 3d scene which is placed over the camera image (the pixelformat of the GLSurfaceView.SurfaceHolder is set to PixelFormat.TRANSLUCENT).

When I blit an image on the framebuffer that intersects with a 3d object that has a (semi-)transparent texture on it, they seam to clear all the pixels of the 3D Scene where they intersect, letting the camera image totally shine through.
This only seamed to appear when i use  OPAQUE_BLITTING.

EgonOlsen

An opaque blit simply copies the pixels from the texture into the framebuffer. This includes the alpha values even if the have no influence on the blit itself. However, in your case, the framebuffer is translucent, i.e. it gets the alpha values from the blitted texture and considers the black areas of the texture as translucent for the framebuffer. While this is perfectly fine, it might not always be what one wants....hence the question. But if everthing is fine now, don't care about this.

MrFluff

#4
here's one more problem I am facing :)

I searched the forum but there does not seem to be someone else having this problem.

Usually someone might to suspect the transValue of the blit method to be a number between 0 and 255.

According to the docs the value is like this:

transValue - the transparency value, -1 is none, 0 is highest transparency. Higher values mean less transparency.

I've made some tests and 15 seams to be pretty close to 0% transparency, but this is quite odd as there is no possibility to have a 50% transparent draw (the value 8 doesn't seam to be any near to 50% anyway).

Then again, I wanted to just use the RGBColors alpha value, but this didn't work either.

Whats the best way to blit (semi) transparent images onto the framebuffer? (the best way I can think of is to not use any values of the blit method at all but make the image itself transparent in Photoshop)

Thx in advance

EgonOlsen

You can adjust the parameters of the transparency formula by playing around with the glTransparenyXXX-setting s in Config. The default values are from desktop jPCT and try to mimic the behaviour of the software renderer.

Thomas.

Can be somehow disabled generating an alpha with using black pixel? Blitted texture, with using new RGBColor(0,0,0,0) like texture, is invisible.

EgonOlsen

Just use one of the useAlpha-constructors of Texture with useAlpha=true. Even if the source image doesn't contain an alpha channel, this will avoid the creation of the default alpha mask.

Thomas.

but I use "Texture shade = new Texture(1, 1, new RGBColor(0, 0, 0, 0));" to get black texture...

EgonOlsen

I see...i've modified this constructors behaviour to take the RGBColor's alpha into account. Simple create your black color with opaque alpha and you should get what you want, if you use this version: http://jpct.de/download/beta/jpct-ae.jar

Thomas.

thanks, but could you implement this also into alpha? :)

EgonOlsen


Thomas.

#12
the last with support OGES 2
edit: beta folder has something to do with version or it is just folder?

EgonOlsen

It's more or less just a folder name. They differ mainly because i moved some stuff between servers and somehow lost track of the names. You can simply take that jar instead of the one from the alpha...it's the same thing, just newer. It contains all the ES2.0 stuff that the alpha did plus some fixes.

Thomas.

black pixel is now visible on screen, thanks :)