Graphics Reference
In-Depth Information
summed vector z-component. After this division, the resulting x and
y
coordinates indicate
the paraboloid location to look up, but are scaled to the [-1,1] range. Since the paraboloid is
stored in a texture, we must convert these coordinates to the appropriate texture coordinates.
This is done with a scaling factor and a biasing factor to remap the coordinates. Finally, we
choose which paraboloid map to sample based on the sign of the reflection vector's z-compo-
nent.
5
A small scaling is also applied to the resulting sampled value to serve as an attenuation
factor. This will help to discern the difference between multiple reflections later on.
float4
PSMAIN(
PS_INPUT
IN ) :
SV_Target
{
float4 OUT;
// Normalize the input normal and eye vectors
float3
N =
normalize(
IN.normal
);
float3
E
=
normalize(
IN.eye );
// Calculate the world space reflection vector,
and
then transform it
to
// the paraboloid
basis.
float3
R
=
reflect(
E,
N );
R =
mul(
R,
(Aoat3x3)ParaboloidBasis );
//
Calculate the
forward paraboloid map texture coordinates,
with z
//
determining which paraboloid map to
sample
(front or back).
float3 front;
front.x
= (R.x / (2*(1 + R.z))) + 0.5;
front.
y = 1-((R.y / (2*(1 + R.z))) + 0.5);
front.z
= 0.0f;
// Calculate the backward paraboloid map texture coordinates, with z
// determining which paraboloid
map
to sample (front or back).
float3
back;
back.x = (R.x / (2*(1 - R.z))) + 0.5;
back.y = 1-((R.y / (2*(1 - R.z))) + 0.5);
back.z
= 1.0f;
//
Sample
the
appropriate paraboloid
map based
on which direction
//
the
reflection
vector is
pointing,
if
(
R.z
> 0 )
OUT
= ParaboloidTexture.Sample(
ParaboloidSampler, front
);
else
OUT
= ParaboloidTexture.Sample( ParaboloidSampler,
back
);
OUT
*= 0.8f;
return
OUT;
}
Listing
1
3.5.
The pixel shader for rendering a reflective object that will sample a paraboloid map.
5
The 2D texture array element is selected by setting the z-component of the texture coordinates being used for
sampling. In our example, we use either a 0 or a 1 to select the front and back paraboloid maps, respectively.
Search WWH ::
Custom Search