Graphics Reference
In-Depth Information
winding order is flipped. This effectively reverses the prior situation, and clips or culls the
positive half-space geometry. In this way, we only apply the appropriate sets of geometry
to each of the paraboloid maps.
[maxvertexcount(3)
]
[instance(2)]
void
GSMAIN(
triangle
GS_INPUT
input[3],
uint
id
:
SV_GSInstanceID,
inout
TriangleStream<PS_INPUT> OutputStream
)
{
PS_INPUT
output;
// Initialize the vertex order
and
the direction of the paraboloid.
uint3
order
=
uint3(
0, 1, 2 );
float
direction
= 1.0f;
//
Check to see which copy of the primitive this is. If it is 0, then it
// is considered the front facing paraboloid. If it
is
1, then it is
// considered the back facing paraboloid. For back facing, we reverse
// the output vertex winding order,
if
(
id
== 1 )
{
order.
xyz
=
order.xzy;
direction
=
-1.0f;
}
//
Emit three vertices for one complete triangle,
for
(
int
i
= 6;
i
< 3; i++ )
{
// Create
a
projection factor, which determines which half space
// will be considered positive and also adds the viewing vector
// which is (0,0,1) and
hence
can only be added to
the
z-component.
float
projFactor
= input[order[i]]
.z_value
*
direction
+ 1.0f;
output.
position.x
=
input[order[i]].position.x
/
projFactor;
output.
position.y
= input[order[i]]
.position.
y
/ projFactor;
output.position.
z
=
input[order[i]]
.position.
z;
output.position.
w
= 1.0f;
// Simply use the geometry shader instance
as
the render target
// index for this primitive,
output.rtindex
=
id;
// Pass through the texture coordinates to the pixel shader
output.tex
=
input[order[i]
]
.tex;
output.
z_value
= input[order[i]
]
.z_value
*
direction;
//
Write the vertex
to
the output stream.
OutputStream.
Append(output);
}
OutputStream.
RestartStrip(
);
}
Listing 13.2.
The geometry shader for rendering a textured object into dual paraboloid maps.
Search WWH ::
Custom Search