Chapter 1. Overview

X3D [X3D] is an open standard for representing interactive 3D models, with many advanced graphic features. Chapter 2, What is X3D? describes X3D in more detail.

Programmable shaders component [X3D Shaders] (part of the X3D standard) defines how shaders can be assigned to visible shapes. Shaders are programs usually executed on the graphic processor unit (GPU). They control the per-vertex and per-pixel processing, for example summing the lights contribution and mixing the texture colors. The authors can create and assign shaders to shapes, which makes a myriad of interesting graphic effects possible in X3D models. Chapter 3, Shaders and X3D describes shaders and the standard way to use them with X3D.

The shaders designed using the standard nodes replace the normal rendering functionality, not enhance it. This reflects the underlying API, like OpenGL or Direct3D. The 3D libraries, in turn, follow the hardware idea that shader code should be a complete and optimized program designed for rendering a particular shape.

We argue that a different approach is needed in many situations. Authors usually would like to keep the normal rendering features working and only add their own effects. The 3D renderer already has an extensive internal shaders system and the authors want to depend on these internal shaders to do the common job.

As an example, consider this simplified lighting equation:

Different effects want to change various parts of this equation, without touching the others. For example, the shadow function may check a shadow map pixel, or (when shadow map is not available) always return 1. The normal function may take the vector straight from the geometry description, or calculate it using a texture value (classic bump mapping). See Figure 1.1, “Japanese shrine model with more and more effects applied ”. The light_color function may use different lighting models (Phong, Ward, Cook-Torrance and so on). Sometimes it makes sense to change these functions for all the light sources and sometimes only a specific light source should behave differently. Our approach allows you to do everything mentioned here.

We present a system for creating effects by essentially compositing pieces of a shader code. All the effects defined this way effortlessly cooperate and can be combined with each other and with application internal shaders. This makes shader programs:

  1. Much easier to create. We can jump straight into the implementation of our imagined algorithm in the shader. We are only interested in modifying the relevant shader calculation parameter. We do not need to care about the rest of the shader.

  2. Much more powerful. Our effect immediately cooperates with absolutely every normal feature of X3D rendering. This makes the implemented effect useful for a wide range of real uses, not only for a particular situation or a particular model (as it often happens with specialized shader code). All X3D light sources, textures, even other shader effects, are correctly applied.

It is important to note that we keep the full power of a chosen GPU shading language. We deliberately do not try to invent here a new language, or wrap existing language in some cumbersome limitations. This is most flexible for authors, and it also allows an easy implementation — there is no need for any complex shading language processing inside the application.

Figure 1.1. Japanese shrine model with more and more effects applied. The model is based on http://opengameart.org/content/shrine-shinto-japan.

Japanese shrine model with more and more effects applied. The model is based on http://opengameart.org/content/shrine-shinto-japan.
No effects.
Japanese shrine model with more and more effects applied. The model is based on http://opengameart.org/content/shrine-shinto-japan.
Phong shading (per-pixel lighting).
Japanese shrine model with more and more effects applied. The model is based on http://opengameart.org/content/shrine-shinto-japan.
Bump mapping.
Japanese shrine model with more and more effects applied. The model is based on http://opengameart.org/content/shrine-shinto-japan.
1st shadow map.
Japanese shrine model with more and more effects applied. The model is based on http://opengameart.org/content/shrine-shinto-japan.
2nd shadow map.
Japanese shrine model with more and more effects applied. The model is based on http://opengameart.org/content/shrine-shinto-japan.
Both shadow maps.