Author Topic: Strange blit behavior with black pixels  (Read 2709 times)

Offline MrFluff

  • byte
  • *
  • Posts: 11
    • View Profile
Strange blit behavior with black pixels
« on: June 09, 2011, 02:05:49 pm »

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]

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Strange blit behavior with black pixels
« Reply #1 on: June 09, 2011, 08:49:14 pm »
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.

Offline MrFluff

  • byte
  • *
  • Posts: 11
    • View Profile
Re: Strange blit behavior with black pixels
« Reply #2 on: June 15, 2011, 02:28:22 pm »

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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Strange blit behavior with black pixels
« Reply #3 on: June 16, 2011, 06:59:11 am »
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.

Offline MrFluff

  • byte
  • *
  • Posts: 11
    • View Profile
Re: Strange blit behavior with black pixels
« Reply #4 on: July 04, 2011, 12:32:54 pm »
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
« Last Edit: July 04, 2011, 12:34:56 pm by MrFluff »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Strange blit behavior with black pixels
« Reply #5 on: July 04, 2011, 06:49:02 pm »
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.

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Strange blit behavior with black pixels
« Reply #6 on: October 08, 2011, 02:59:02 pm »
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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Strange blit behavior with black pixels
« Reply #7 on: October 08, 2011, 11:25:28 pm »
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.

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Strange blit behavior with black pixels
« Reply #8 on: October 09, 2011, 12:33:42 pm »
but I use "Texture shade = new Texture(1, 1, new RGBColor(0, 0, 0, 0));" to get black texture...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Strange blit behavior with black pixels
« Reply #9 on: October 09, 2011, 01:53:15 pm »
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

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Strange blit behavior with black pixels
« Reply #10 on: October 09, 2011, 02:02:33 pm »
thanks, but could you implement this also into alpha? :)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Strange blit behavior with black pixels
« Reply #11 on: October 09, 2011, 02:03:27 pm »
Which alpha?

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Strange blit behavior with black pixels
« Reply #12 on: October 09, 2011, 02:06:07 pm »
the last with support OGES 2
edit: beta folder has something to do with version or it is just folder?
« Last Edit: October 09, 2011, 02:09:22 pm by Thomas. »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Strange blit behavior with black pixels
« Reply #13 on: October 09, 2011, 02:10:51 pm »
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.

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Strange blit behavior with black pixels
« Reply #14 on: October 09, 2011, 02:20:19 pm »
black pixel is now visible on screen, thanks :)