[osg-users] help required on saving transparent images with antialiased lines

Gianluca Natale natale at europe.altair.com
Wed Jan 27 06:43:52 PST 2016


Hi all,
I'm trying to take a snapshot of my scene, by rendering it in a hidden pixel buffer, then saving the content as a .png.

The idea is to save the alpha channel too, in order to have transparent images (actually transparent background).
So, I've allocated a RGBA pixel buffer, rendered the scene inside, then copied the content into a osg::image and saved it to disk.
It works fine for opaque surfaces (whose alpha is set to 1.0 in the color assigned to the primitive), but I have some issues when rendering anti-aliased lines, though their color is completely opaque (alpha = 1.0).

As I render lines by enabling anti-aliasing in OpenGL, the color of every pixel is proportional to the coverage of that pixel by the primitive.
So, while computing the fragment color, I guess OpenGL also updates its alpha value, in the pixel buffer where it renders the lines. And that alpha value is finally written in the image I save on disk.
In consequence, pixels related to lines appear to be transparent, even if I have set their color completely opaque (alpha = 1.0).

To be clearer, I've attached some pictures with different settings.

1)      "image RGB" has been taken by allocating a RGB pixel buffer, so discarding the alpha channel. Background color is set to RGBA = (0.8, 0.2, 0.2, 1.0).

2)      "image RGBA 100" has been taken by allocating a RGBA pixel buffer, with opaque background color, as in case 1: RGBA = (0.8, 0.2, 0.2, 1.0).

3)      "image RGBA 50" has been taken by allocating a RGBA pixel buffer, with transparent background color: RGBA = (0.8, 0.2, 0.2, 0.5).

First image looks good, with no transparent background.
Third image has a transparent background, but also, as you can see, noticeable jaggies appearing on the edges of the parts, either those which join adjacent opaque surfaces. It looks like those jaggies are due to the alpha values stored for those
pixels, which are not 1.0.
Second image is the worst: though the background is completely opaque (because of the alpha value set in the clear color, 1.0), still I see the jaggies on the borders of the parts.

Is there a way to avoid that? I mean, I'd like to render anti-aliased lines in my transparent image, but keeping them opaque when saved to disk.

Thanks,
Gianluca

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20160127/e782c9e7/attachment-0002.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image RGB.png
Type: image/png
Size: 59669 bytes
Desc: image RGB.png
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20160127/e782c9e7/attachment-0006.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image RGBA 100.png
Type: image/png
Size: 81922 bytes
Desc: image RGBA 100.png
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20160127/e782c9e7/attachment-0007.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image RGBA 50.png
Type: image/png
Size: 84405 bytes
Desc: image RGBA 50.png
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20160127/e782c9e7/attachment-0008.png>


More information about the osg-users mailing list