Shape component - extensions

Contents:

1. Toggle shape rendering (Shape.render)

Shape {
  ...
  SFBool     [in,out]      render      TRUE      
}

The field render allows to easily hide and show the given Shape. A hidden shape is not rendered, but otherwise it's still processed (for example, it is used for collision detection).

If you want to hide a particular shape, sometimes this may be a simpler method than using standard X3D Switch node. It doesn't require to wrap the Shape in a Switch node.

This is compatible with InstantReality Shape extension.

2. Specify shading, e.g. to force Phong shading or wireframe for a shape (Shape.shading)

We add a shading field to the Shape node (more precisely, to the abstract X3DShapeNode):

X3DShapeNode (e.g. Shape) {
  ... all normal X3DShapeNode fields ...
  SFString   [in,out]      shading     "DEFAULT"   # ["DEFAULT"|"GOURAUD"|"PHONG"|"WIREFRAME"]
}

The allowed values for the shading field:

  • DEFAULT: use the default shading. In view3dscene you control this using the "View -> Phong Shading on Everything" checkbox. In your own games you control this using the Scene.Attributes.PhongShading property in Pascal code.

  • GOURAUD: fast per-vertex lighting calculation. It is the default shading for now.

    Explicitly specifying the "GOURAUD" indicates that this shape wants to use Gouraud shading, even if the default scene shading is Phong. Note that some features (like bump mapping and shadow maps) will override this and require Phong shading anyway, since it's impossible to realize them with Gouraud shading.

    Note that the "GOURAUD" shading performs only one-sided lighting in the shader pipeline. This means that only one face side receives lighting. By default (when ccw="TRUE") this is the side oriented in a counter-clockwise fashion, but you can switch this by setting the ccw="FALSE". The other face will be always black (or invisible, if the backface-culling if used, by solid="TRUE", which is actually default).

  • PHONG: pretty per-pixel lighting calculation. This also means always using shader pipeline to render this shape. This also performs two-sided lighting.

  • WIREFFRAME: render as a wireframe. The rendering model matches the IndexedLineSet specification, in particular: the shape is not lit.

    For now this is only honored by the Box, Sphere nodes. It will be extended to all geometry nodes when necessary in the future.

These shading names are consistent with "Browser options" in X3D spec (with DEFAULT added by us).

3. Specify alpha channel treatment (field alphaChannel for Appearance)

Demo of alphaChannel override

We add a new field to the Appearance node to request a specific alpha treatment when rendering.

Appearance {
  ... all normal Appearance fields ...
  SFString   []            alphaChannel  "AUTO"      # "AUTO", "NONE", "TEST" or "BLENDING"
}

Test file of this feature.

Value AUTO (the default) means that we auto-detect the correct alpha treatment, looking at various things.

  • Material properties (whether the material uses Material.transparency > 0),

  • texture properties (whether some texture defines some alpha channel, and whether it's a yes-or-no alpha channel or smooth).

  • The interpretation of each texture may also be affected by it's ImageTexture.alphaChannel field.

Other Appearance.alphaChannel values force a specific alpha channel treatment at rendering. Using them means that our auto-detection (discussed above) is not used at all. There are three possible values:

  1. NONE: Ignore any alpha channel, render as opaque.
  2. TEST: Use alpha-testing, which is good for textures having a sharp (yes-or-no) alpha channel contents.
  3. BLENDING: Use blending, which allows to show partial transparency of textures and/or materials.