Game Development Reference
float2 ScreenUV = ScreenPosition.xy / ScreenPosition.w *
float2 (0.5f, -0.5f) + 0.5f;
float2 R = ScreenUV + TangentNormal.xy * DistortionStrenght;
return tex2Dlod(ReflectionTexture, float4 (R, 0.0f, ScaleBias.x *
Glossiness + ScaleBias.y)).rgb;
High-level shading language (HLSL) pseudocode to use a 2D reflection
improve the final quality in our case. Note that for performance reasons, we do not
transform the normal to view-space but keep it in tangent space, implying that
we could not distort in the correct direction. In practice the result is good enough
and the correct result would still be an approximation anyway (Figure 1.11).
We provide some performance measurements of our implementation with a 128
6 cubemap stored using DXT1 compression, 128
128 image proxies using
DXT5, and a 256
256 2D reflection texture. Image proxies use DXT5 to support
the alpha pixel border we add for antialiasing. We provide our performance
measurements as ranges since timings vary with the number of cubemaps, image
proxies and pixels clipped by the reflection plane. The typical case includes two
cubemaps and 10 to 15 image proxies. The whole process is in HDR format.
Figure 1.11. The influence of the distortion strength on the reflection.