Use the root appearance

From JReality Wiki
Revision as of 09:22, 6 August 2012 by Gunn (Talk | contribs)

(diff) ←Older revision | view current revision (diff) | Newer revision→ (diff)
Jump to: navigation, search

JavaDoc: RootAppearance


The Appearance attached to the root SceneGraphComponent of a Viewer has a special significance. Certain global settings are expected to be found there. Here's how to create an instance of RootAppearance for writing:


import de.jreality.shader.ShaderUtility;
import de.jreality.shader.RootAppearance;
Appearance ap = viewer.getSceneRoot().getAppearance();
RootAppearance rootAp = ShaderUtility.createRootAppearance(ap);


Fog

The following parameters control the fog:


  • "fogEnabled" When true, then fog parameters are applied to the scene.
  • "fogDensity" This is an exponent describing the falloff rate of light passing through the fog. Default = .1
  • "fogColor" The color of the fog, which is blended with the result of attenuating the material color with the fog density above.
    • If this is not set, then it inherits its value from the value of backgroundColor (see below).


For example:


rootAp.setFogEnabled(true);
rootAp.setFogDensity(.5);  // thick fog
rootAp.setFogColor(Color.white);


Background

There are also attributes controlling the background coloring:


  • "backgroundColor" Expected to be an instance of java.awt.Color, specifies an RGBA color for the background.
  • "backgroundColors" Expected to be of type java.awt.Color[4]. If present, overrides "backgroundColor" by specifying colors for the four corners, in the order UR, UL, LL, and LR. The corner colors are bilinearly interpolated to make the background.
  • "skyBox" Expected type is de.jreality.shader.ImageData[6]. Overrides the previous two attributes if it's present.


For more on skyboxes and reflection maps, see Use a skybox and reflection map.


Metric

jReality supports rendering in non-euclidean spaces. One can set the metric as follows:


 import de.jreality.math.Pn;
Appearance ap = viewer.getSceneRoot().getAppearance();
int metric = Pn.ELLIPTIC;   // HYPERBOLIC and EUCLIDEAN also possible
app.setAttribute(CommonAttributes.METRIC, metric);

Note that the metric can be set in any part of the scene graph, so this doesn't belong to the root appearance per se. However, the following related feature does:


Rendering in the 3-sphere

By default, using Pn.ELLIPTIC to set the metric will result in rendering of elliptic space. If you desire rendering of spherical space (a double-covering of elliptic space), set the following value in the root appearance:

import de.jreality.shader.ShaderUtility;
import de.jreality.shader.RootAppearance;
Appearance ap = viewer.getSceneRoot().getAppearance();
RootAppearance rootAp = ShaderUtility.createRootAppearance(ap);
rootAp.setRenderS3(true);


Note that this will only have an effect if the value of the metric attribute is Pn.ELLIPTIC.


Previous: Use vertex arrays in JOGL backend Developer Tutorial: Contents Next: Use vertex colors an a point set