A solution to this problem involves binding to the local geometry in the procedure to calculate the reflection.
This solution is described in GPU Gems: Programming
Techniques, Tips, and Tricks for Real-time Graphics by Randima Fernando
The following figure shows a local correction using a bounding
Figure 6-14 Local correction using a bounding sphere
A bounding sphere is used as a proxy volume that delimits the scene to be
reflected. Instead of using the reflected vector
fetch the texture from the cubemap a new vector
used. To build this new vector you find the intersection point
P in the bounding sphere of the ray from the local point
V in the direction of the reflected vector
R. Create a new vector
R’ from the center of the cubemap
where the cubemap was generated, to the intersection point
P. Use this vector to fetch the texture from the cubemap.
float3 R = reflect(D, N);
Find intersection point P
Find vector R’ = CP
float4 col = texCUBE(_Cubemap, R’);
This approach produces good results in the surfaces of objects with a
near spherical shape but reflections in plane reflective surfaces are deformed. Another
drawback of this method is that the algorithm to calculate the intersection point with
the bounding sphere solves a second degree equation and this is relatively complex.
The following figure shows a local correction using a bounding box:
Figure 6-15 Local correction using a bounding box
A more recent work in 2012 by Sebastien Lagarde uses this new approach to
simulate more complex ambient specular lighting using several cubemaps and uses an
algorithm to evaluate the contribution of each cubemap and efficiently blend on the GPU.
Table 6-3 Differences between infinite and local cubemaps
- Mainly used outdoors to represent the lighting
from a distant environment.
- Cubemap position is not relevant.
- Represents the lighting from a finite local
- Cubemap position is relevant.
- The lighting from these cubemaps is right only
at the location where the cubemap was created.
- Local correction must be applied to adapt the
intrinsic infinite nature of cubemaps to local environment.
The following figure shows the scene with correct reflections generated with
Figure 6-16 Correct reflections