Time for action – semitransparent texture

The previous material was opaque, but materials can also be semitransparent. Applying a semitransparent material makes the geometry partially see-through and blends the geometry's color with what is visible behind it. For this, you need an image file with an alpha channel that has grayscale in it.

Let's try to create a fancy window:

  1. Copy the assets/Textures/mucha-window.png image to your project's assets/Textures/ directory.
  2. Back in TexturesOpaqueTransparent.java, add the following code in the simpleInitApp() method:
    Box windowMesh = new Box(new Vector3f(0f, 0f, 0f), 1f, 1.4f, 0.01f); Geometry windowGeo = new Geometry("stained glass window", windowMesh); Material windowMat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); ...

Get jMonkeyEngine 3.0 Beginner's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.