Instead of fetching the texel from the cubemap using the refracted
vector R_{rf}, you find the point P where the refracted vector
intersects the bounding box and build a new vector R'_{rf} from
the center of the cubemap C to the intersection point P. Use this new vector to fetch
the texture color from the cubemap.
float eta=n2/n1;
float3R_{rf} =
refract(D,N,eta);
Find intersection point P
Find vector R'_{rf} =
CP;
Float4 col = texCube(Cubemap, R'_{rf});
The following figure shows a scene with a cubemap and the refraction vectors:
Figure 637 The local correction to refraction vector
The refraction produced by this technique is accurately physically based, because the direction
of the refraction vector is calculated using Snell’s Law.
There is also a builtin function that you can use in your shader to find
the refraction vector R
strictly according to the
Snell's law:
R = refract( I, N, eta);
Where:

I
is the normalized view or
incident vector.

N
is the normalized normal
vector.

eta
is the ratio of indices of refractions
n_{1}/n_{2}.
The following figure shows the flow of shaders that implement refraction based
on a local cubemap:
Figure 638 Shader implementations of refraction based on local
cubemap