Monday, 18 November 2013

Transparency in JAVA3D

This lesson will show one way to use a Transparent texture in Java3D 

Since I wanted to use fire in my program, so I used a fire image, and made the background transparent in Photoshop. 
But if you applied the transparent texture the same way as regular textures, you will not get the effect you want. 

In order to get the Transparent effect, you must alter the polygon's Appearance
	Appearance fireApp = new Appearance ();
Create an instance of TransparencyAttributes
	TransparencyAttributes ta = new TransparencyAttributes();
Choose a Transparency Mode type (NONE, FASTEST, NICEST, SCREEN_DOOR, or BLENDED), in this case I use BLENDED
	ta.setTransparencyMode (ta.BLENDED);
Set the Transparency, from 0.0 to 1.0, where 0.0 is opaque , and 1.0 is transparent. I used 0.5 in this sample.
	ta.setTransparency (0.5f);
Then apply the TransparencyAttributes to the Appearance
	fireApp.setTransparencyAttributes (ta);


I placed a green polygon behind the fire polygon so the transparency effects would be evident. 
Without TransparencyAttributesWith TransparencyAttributes
Post a Comment