www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: aZen on March 04, 2014, 12:48:02 am

Title: Drawing with true alpha
Post by: aZen on March 04, 2014, 12:48:02 am
I've tried:

Code: [Select]
        Config.useFramebufferWithAlpha = true;
        FrameBuffer fb = new FrameBuffer(getWidth(), getHeight(), FrameBuffer.SAMPLINGMODE_OGSS);
        fb.clear(new Color(255,255,255,0));
        world.renderScene(fb);
        world.draw(fb);
        fb.update();
        BufferedImage result = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
        fb.display(result.getGraphics());
        Config.useFramebufferWithAlpha = false;
        return result;

But the alpha value is only "1" or "0", so the edges don't appear smooth. Is there an easy way to fix this?
Title: Re: Drawing with true alpha
Post by: EgonOlsen on March 04, 2014, 08:19:15 pm
It should work already if your textures have a real alpha channel, i.e. have been created by using the Texture constructor with the useAlpha flag (and out of a file format that actually supports alpha like png).
Title: Re: Drawing with true alpha
Post by: aZen on March 04, 2014, 08:32:16 pm
I should have clarified: I'm using oversampling (FrameBuffer.SAMPLINGMODE_OGSS). So I'm expecting the edges where the background and the object are anti-aliased to blend smoothly. At the moment the transparency is either 1 or 0. I was hoping it would blend as 0 to 255.
Title: Re: Drawing with true alpha
Post by: EgonOlsen on March 04, 2014, 08:55:20 pm
I see...that's something completely different. I'll have a look...
Title: Re: Drawing with true alpha
Post by: EgonOlsen on March 04, 2014, 09:06:15 pm
Try this jar: http://jpct.de/download/beta/jpct.jar (http://jpct.de/download/beta/jpct.jar)

The current behaviour is by design, so i'm not going to change it. But i added a config switch, Config.blendAlphaIfOversampling. Set it to true and see if that helps.
Title: Re: Drawing with true alpha
Post by: aZen on March 04, 2014, 09:42:07 pm
Thank you! Unfortunately it's still not correct. It appears that the pixels are first blended with the background and then the alpha transparency is applied.

If this is problematic to implement on your end I can always do two render passes with black and white and calculate the correct transparency and color myself.

(http://i.imgur.com/6xXfCdb.png)
(left with black background and right with white background, you can see the white pixels in the right image)
Title: Re: Drawing with true alpha
Post by: EgonOlsen on March 04, 2014, 10:03:09 pm
Opps...yes, you are right. I've updated the jar, but i've no idea if that version works better or colors everything like a rainbow. If it still doesn't work, maybe you can provide me with a simple test case?
Title: Re: Drawing with true alpha
Post by: aZen on March 04, 2014, 10:12:02 pm
[...] no idea if that version works better or colors everything like a rainbow [...]

Haha, those are great alternatives =)
Everything seems to work fine now! Thank you very much!