The nice feature of our system is that effects can be attached to various
types of objects, not just shapes. For example a particular light source
may have a shader effect assigned.
This allows to modify the contribution of a given light.
For example the spot light shape can be modified, possibly
based on some texture information (see Figure 5.3, “Textured spot light with shadow”).
Or a different lighting model may be implemented, like anisotropic Ward
or Cook-Torrance.
To make this possible, the effects
field is added to every light node:
X3DLightNode MFNode [] effects [] # Effect
An example below demonstrates how light effects are specified inside an X3D. The code makes a spot light with an exponential drop-off, similar to traditional OpenGL fixed-function spot lights. Such code can replace (or multiply with) the standard X3D concept of the linear drop-off for spot lights.
The customization is done by overriding the PLUG_light_scale
.
Remember that all plugs available in our implementation
are documented in Appendix A, Reference of available plugs.
SpotLight {
effects Effect { language "GLSL"
parts EffectPart { type "FRAGMENT"
url "data:text/plain,
uniform vec3 castle_LightSource0SpotDirection;
void PLUG_light_scale(inout float light_scale,
const in vec3 normal_eye,
const in vec3 light_dir)
{
light_scale *= pow(dot(normalize(
castle_LightSource0SpotDirection), -light_dir), 10.0) * 2.0;
}"
} } }