i
i
i
i
i
i
i
i
3. Shader-Based Water Effects 313
4. Avoid using discard to perform clipping. Although using the discard key-
word works for clipping techniques, its use decreases the efficiency of early
order-independent depth rejection performance advantages that the POW-
ERVR architecture offers (See Section 3.3.1 for more information).
3.2.4 Refraction Render Pass
In a case where the rendered water should appear to be fairly deep, adding refrac-
tion to the simulation can vastly improve the quality of the effect. To do this, an
approach similar to that taken during the reflection render pass should be used,
in which all objects below the water are rendered out to a texture (Figure 3.6).
Clipping (using the inverse of the water plane) can be assisted by rough culling
on the CPU beforehand. This reduces the GPU workload [PowerVR 10].
If the effect should produce very clear water, all elements of the scene below
the water should be rendered, including the skybox (or similar object) (Fig-
ure 3.7). If a murky water effect is required, a fogging effect can be used to fade
out objects at lower depths (discussed later in this section).
Once the scene has been rendered to a texture, it can then be utilized by
the water’s fragment shader. The screen-space texture coordinates (as used in
Section 3.2.3) are also used to sample the refraction texture. The refraction
sample is then combined with the reflection sample, either at a constant ratio
(e.g., 50/50), or using an equation such as the Fresnel term to provide a dynamic
Figure 3.6. Refraction stored as a texture.