Graphics Reference
In-Depth Information
struct VS_INPUT
{ float3 position : POSITION;
float3 normal
: NORMAL;
};
struct PS_INPUT
{ float4 position : SV_Position;
float3 normal
: TEXCOORD0;
float3 eye
: TEXC00RD1;
};
struct pixel
{
float4 color : COLOR;
};
PS_INPUT VSMAIN( VSJENPUT IN )
{
PS_INPUT OUT;
// Find the world space position of the vertex.
float4 WorldPos = mul( float4( Imposition, 1 ), WorldMatrix );
// Output the clip space position for the rasterizer.
OUT. position = mul( float4( IN. position, 1 ), WorldViewProjMatrix );
// Find world space normal and eye vectors.
OUT.normal = normalize( mul( IN. normal, (Aoat3x3)WorldMatrix ) );
OUT.eye
= normalize ( WorldPos.xyz - ViewPosition.xyz );
return OUT;
};
Listing 13.4. The vertex shader for rendering a reflective object that will sample a paraboloid map.
After the reflective object's geometry has been rasterized, the pixel shader is invoked
to determine what color should appear at each fragment location. This is done by first
normalizing the world-space surface normal vector and the view-direction vector. Next,
we calculate the reflection of the eye vector about the surface normal. This essentially
indicates where in world space will be visible from that particular fragment for the given
viewing angle. We then convert this reflected vector to be relative to the paraboloid's basis,
so that it will be in the same coordinate frame as our paraboloid maps.
This new reflected vector is used to determine where in the paraboloid maps to look
up. In essence, we perform the exact same process that we have seen before. The vector's z
component is added to 1 to find the z-coordinate of the summed vector in Equation (13.7).
This is then used to project the x and y reflection vector components by dividing by this
Search WWH ::




Custom Search