Material management
Keywords:
tutorial,
X3D,
world,
rendering
Author(s): Yvonne Jung
Date: 2007-04-26
Summary: This tutorial shows some advanced material management features.
Advanced material management
When looking at games or technical demonstrations of graphics card vendors and reviewing current literature dealing with rendering, one might think that most problems are solved and generalized solutions are standardized and readily available. But currently X3D still does not support advanced rendering methods. In order to overcome these limitations we present some nodes for advanced rendering techniques like render state control for allowing to create and author photo-realistic 3d worlds easily.
For complex rendering tasks the user sometimes needs control over the rendering order of different geometries as well as over low level rendering modes. So, because the Appearance node finally reveals how a rendered Shape node looks like, we extended the X3D shape component with some new nodes for setting different render states and therewith the Appearance node with the appropriate fields. This is necessary because those settings directly map to the GPU, so no PROTOs are possible here.
First we introduce the SFInt32 field "sortKey" for defining the rendering order, what is essential in combination with e.g. alpha blending and depth writing. Alternatively, one can think about a special ordering group, but this way usage is much more intuitive and is automatically correct for the whole scene graph. For rendering operations which belong closely together as it is the even for a simple toon shader for non-photorealistic rendering, we also introduce the MultiPassAppearance node as the generalized extension for the X3D TwoSidedMaterial node. The "appearance" field simply contains an ordered sequence of single-pass appearance nodes.
Additionally we propose an AppearanceGroup node which – as the name implies – extends the Group node with an "appearance" field. This is quite useful if a whole group of Shape nodes should share the same material properties. The field render (which b.t.w. is shared by all grouping nodes) simplifies the setting of visibility.
X3D bindings for multi-pass and group appearances
Code: Appearance settings for simple outlined comic material
AppearanceGroup {
children [
# all shape nodes etc
]
appearance MultiPassAppearance {
appearance [
DEF Pass1 Appearance {
faceMode FaceMode {
smooth FALSE
cullFace "back"
frontMode "fill"
}
material Material {
diffuseColor .7 .7 .7
}
}
DEF Pass2 Appearance {
lineProperties LineProperties {
linewidthScaleFactor 6
}
material Material {
diffuseColor 0 0 0
}
faceMode FaceMode {
smooth FALSE
cullFace "front"
backMode "line"
}
}
]
}
}
The left image shows an application of color masking in combination with using a defined rendering order for achieving the occlusion effects. The right image shows the usage of special materials for rendering the front and back faces beyond the simpe TwoSidedMaterial according to the above shown code fragment. In this context you also need the possibility to e.g. disable depth writing, to use different depth funcs, or to do arbitrary blending and discard operations for the compositing of object.

In the following, a few nodes for allowing finer control over the rendering modes are shown. If the corresponding fields in the Appearance node are not set by the user, the browser uses standard settings which fit best for the current material, texture or shader to ensure compatibility with the X3D standard. Otherwise the state modes override the default settings.
As the name implies, the BlendMode node allows access to blending and alpha test. The field values, for instance "src_alpha" and "one_minus_src_alpha" for standard alpha blending, map directly to the corresponding rendering state names of the API of the graphics board driver. The fields "alphaFunc" and "alphaFuncValue" specify the conditions under which a fragment is drawn or discarded. For example, with "alphaFunc" set to "lequal" and a given reference value c the fragment passes if the incoming alpha value is less than or equal to c. Concerning choice and naming conventions, a common subset of the OpenGL and DirectX graphics standards, which have already been very well documented, was chosen. For further information you may want to refer e.g. to the OpenGL Red Book.
The other four modes, StencilMode, ColorMaskMode, FaceMode and DepthMode, are likewise almost self-explanatory. The ColorMaskMode permits control over color masking – the color channel is written if the corresponding mask field is true. The FaceMode can be explained best as being a generalized extension of the "ccw" and "solid" fields of the X3DComposedGeometryNode, as is needed in combination with the "sortKey" field or the MultiPassAppearance.
With the DepthMode depth functions can be set as already explained above. The StencilMode permits fine grained control over stencil bit masks and functions. For all fields with default values equal to -1 or "none", implementation specific default values are used. This way, complex multi pass appearances as needed for advanced rendering can be created. Moreover, these extensions of the X3DAppearanceChildNode are also useful for other appliances, such as for instance image based CSG operations or augmented reality applications.
Comments
This tutorial has no comments.
Add a new comment
Due to excessive spamming we have disabled the comment functionality for tutorials. Please use our forum to post any questions.