transparency in software GL mode

Started by Ben, December 12, 2008, 11:34:24 PM

Previous topic - Next topic

Ben

Hi,

I am wondering if it is possible to get smooth transparency transitions for objects in the software GL renderer.
This would be mostly for particle effects, for example, I would like to render a simple quad polygon with a smoke cloud texture, initially rendered fully opaque and have it gradually become more and more transparent until it disappears (in other words, a smooth fade out).

I am currently using Object3D.setTransparency(int x), but it does not have a great range of transparency values, and the highest transparency value = 0, is not very transparent at all.

With the hardware GL renderer, altering Config.glTransparencyOffset seems to work. But as stated in the docs this is not supported in software mode.

Is there another approach to achieve this, or is this not supported in software mode? If not currently supported, are there any plans to do so in the future?  Particle effects, such as fire, explosions, smoke etc.. do not look good without this functionality.

Thanks in advance,

Ben.

paulscode

I'm writing this off the top of my head, so you might have to play around with it a little to make it work, but I think something like this might do the trick.

First, use Photoshop or other editor to create your smoke texture with an alpha chanel for simi-transparency (.png format works well for this).

In your program, define a "maximum intensity" color for your smoke.  For example, for "firefly green" smoke you'd use something like this:
    Color smokeColor = new Color( 152, 247, 23 );

Next, create a method for returning an "intensity" of this color:
    // intensity range: 0.0f - 1.0f
    public Color intensity( Color color, float intensity )
    {
        float r = color.getRed();
        float g = color.getGreen();
        float b = color.getBlue();
        r *= intensity;
        g *= intensity;
        b *= intensity;
        return new Color( (int) r, (int) g, (int) b );
    }


Then set up your smoke cloud Object3D properties like this:
    obj.setTransparency( 0 );
    obj.setTransparencyMode( Object3D.TRANSPARENCY_MODE_ADD );
    obj.setLighting( Object3D.LIGHTING_NO_LIGHTS );


Now you should be able to adjust the fade on your smoke cloud as needed like this:
    float fade = 0.5f;
    obj.setAdditionalColor( intensityColor( smokeColor, fade ) );


I did something similar to this in my glowing firefly demo applet.  In that case, I only called an "intensityColor" method once rather than using it to dynamically fade the texture, but the concept seems to me like it should work.  For reference, the source code for my applet can be download from the How to make things glow thread.

EgonOlsen

Quote from: Ben on December 12, 2008, 11:34:24 PM
Is there another approach to achieve this, or is this not supported in software mode? If not currently supported, are there any plans to do so in the future?  Particle effects, such as fire, explosions, smoke etc.. do not look good without this functionality.
As paulscode mentioned, just use a texture with an alpha channel (see my comment on your post about version 1.17). That should do the trick.