Use a skybox and reflection map

From JReality Wiki
Jump to: navigation, search

Source file: SkyboxAndReflMapExample

JavaDoc: TextureUtility

JavaDoc: CubeMap

Run as Java webstart

Creating a skybox and a matching reflection map is as easy as reading in six images representing the sides of the world cube. The method TextureUtility.createReflectionMap(...)takes as arguments a string representing the location where the files are located (directory plus the file name stem), the suffixes used to represent the six walls, as well as the file suffix (.jpg, .png).

Deriving a skybox from a reflection map is handled by the method TextureUtility.createSkyBox(...).

Note that to get a reflection map on the tubes generated by a line shader, you have to create a separate reflection map. Similar (but not shown) for spheres generated by point shader.

The method createReflectionMap(...) used in this example uses shader interfaces to write appropriate values into the Appearance instance it is handed. See How to use shader interfaces for details.

public class SkyboxAndReflMapExample {
  public static void main(String[] args)  {
    SceneGraphComponent worldSGC =   SceneGraphUtility.createFullSceneGraphComponent("SkyboxExample");
    worldSGC.setGeometry(new CatenoidHelicoid(40));
    Appearance ap = worldSGC.getAppearance();
    DefaultGeometryShader dgs = ShaderUtility.createDefaultGeometryShader(ap, true);
    // basic class needed for both reflection maps and skyboxes is a CubeMap
    CubeMap rm = null;
    try {
      rm = TextureUtility.createReflectionMap(ap,"polygonShader",
           new String[]{"rt","lf","up", "dn","bk","ft"},
    } catch (IOException e) {
   Viewer v = JRViewer.display(worldSGC);
    ImageData[] sides = TextureUtility.getCubeMapImages(rm);
    // attach a skybox to the scene root
     v.getSceneRoot().getAppearance(), sides);

The result should look something like this:


Previous: Use an animated 2d texture Developer Tutorial: Contents Next: Use a GLSL Shader

How to create your own sky box with a digital camera:

You can create your own sky box with a digital camera.

See for detailed instructions.

(you're welcome to add the instructions directly to this Wiki)