5.3. Effects for a group of nodes

The Effect node is a descendant of the abstract X3DChildNode. As such it can be placed directly within X3D grouping nodes like Group, Transform and at the top level of the X3D file. Such effect will apply to all the shapes within the given group. The scope rules follow the X3D conventions for other nodes, like pointing device sensor nodes and LocalFog.

The LocalFog example is worth emphasizing. Using our system, an X3D viewer can implement the LocalFog node as a prototype that expands to our Effect node. This results in a 100% correct and easy implementation of the standard LocalFog node.

As one of the demos, we have implemented a realistic animated volumetric fog, where the fog density is stored in a 3D smooth noise texture (idea from [Volumetric Fog]). In a fragment shader, the 3D texture is sampled along the line between the camera and pixel position in the 3D space. This makes a very convincing effect of a dense fog. The Effect node with appropriate shader code is placed at the top level of the X3D file, so it simply works for all shapes. See Figure 5.2, “Volumetric fog with animated density”.

Figure 5.2. Volumetric fog with animated density

Volumetric fog with animated density
No fog.
Volumetric fog with animated density
No lighting. Note that the fog is assumed to have its own ambient lighting, so it colors the image even in this case.
Volumetric fog with animated density
Lights and fog.