Search code examples
javaopengljava-3d

Creating a Glowing Sphere in Java3D


I'm looking for a way to reproduce this foggy-sphere-glowing effect using Java3D.

http://bzflag.org/screenshots/bzfi0021.jpg http://bzflag.org/screenshots/bzfi0019.jpg http://bzflag.org/screenshots/bzfi0022.jpg

I'm creating a transform group with a point light source and an emissive-material-sphere, but I can't reproduce the foggyness.

Ideas?

Thanks!

============ SOLUTION (Thanks to Ricket) ===========

    try
    {
        TextureLoader myLoader = new TextureLoader( new File("./data/grad.png").toURI().toURL(), this );

        ImageComponent2D myImage = myLoader.getImage( );

        Raster raster = new Raster( );
        raster.setPosition( new Point3f( 0.0f, 0.0f, 0.0f ) );
        raster.setType( Raster.RASTER_COLOR );
        raster.setSize( 50, 50);
        raster.setImage( myImage );

        TransparencyAttributes ta =  new TransparencyAttributes( TransparencyAttributes.BLENDED, 0.0f );
        Appearance app = new Appearance();
        app.setTransparencyAttributes( ta );

        objScale.addChild( new OrientedShape3D(raster, app, OrientedShape3D.ROTATE_ABOUT_POINT, new Point3f( 0.0f, 0.0f, 0.0f )));


    }
    catch (MalformedURLException e) { throw new RuntimeException(); }

Solution

  • I'm pretty sure the "sphere" is actually a 2D sprite drawn in 3D space as a billboard, and then a matching color light also 'drawn' at its position. The fogginess is just a 2D gradient of the image.

    This is just my best guess from having played the game though, I haven't looked at the source.