Intro04

From JReality Wiki
Jump to: navigation, search

Set material properties with shader interfaces and add a tool

Source file: Intro04

JavaDoc: DefaultPointShader

JavaDoc: DefaultLineShader

JavaDoc: DefaultPolygonShader


Run as Java webstart


We can achieve the same result as in Setting material properties with appearances a bit more cleanly by using shader interfaces instead of direct access to the Appearances. For more on shader interfaces, see article on jReality scene graph, particularly the section on "Shading", for details. Here's what the equivalent code looks like:


import java.awt.Color;
import de.jreality.scene.Appearance;
import de.jreality.shader.DefaultGeometryShader;
import de.jreality.shader.DefaultLineShader;
import de.jreality.shader.DefaultPointShader;
import de.jreality.shader.DefaultPolygonShader;
import de.jreality.shader.ShaderUtility;
import de.jreality.shader.RenderingHintsShader;
...
    Appearance ap = dodecSGC.getAppearance();
    DefaultGeometryShader dgs;
    DefaultLineShader dls;
    DefaultPointShader dpts;
    RenderingHintsShader rhs;
    DefaultPolygonShader dps;
 
    dgs = ShaderUtility.createDefaultGeometryShader(ap, true);
    dls = (DefaultLineShader) dgs.createLineShader("default");
    dls.setDiffuseColor(Color.yellow);
    dls.setTubeRadius(.05);
    dpts = (DefaultPointShader) dgs.createPointShader("default");
    dpts.setDiffuseColor(Color.red);
    dpts.setPointRadius(.1);
    dps = (DefaultPolygonShader) dgs.createPolygonShader("default");
    dps.setSmoothShading(false);
    rhs = ShaderUtility.createDefaultRenderingHintsShader(ap, true);
    rhs.setTransparencyEnabled(true);
    rhs.setOpaqueTubesAndSpheres(true);
    dps.setTransparency(.5);

The picture should be the same as in the previous tutorial.


Previous: Intro03 Developer Tutorial: Contents Next: Intro05