1.9 KiB
title | date | weight |
---|---|---|
Rasterizer State | 2021-01-27T15:30:01-08:00 | 6 |
Rasterization is, essentially, the process of converting 3D vertex information into pixels on a surface. There are many different ways that we may wish to control rasterization.
Note that I am mostly going to discuss triangles here. Many of these options will be ignored unless you are using triangle primitives, for soon to be obvious reasons.
FrontFace
specifies which triangles we will designate as "front-facing", using what we call "winding order". If we use FrontFace.CounterClockwise
, then triangles listed in counter-clockwise order will be designated as front faces. Likewise, if we use FrontFace.Clockwise
, clockwise triangles will be designated as front faces. Which order you choose depends on the format of your vertex data.
Why is this important? The answer is "primitive culling". A lot of the time we have no need to render triangles that are facing away from the camera, so we can save a lot of processing time by not rasterizing those triangles.
CullMode
has four options: None
, Front
, Back
, and FrontAndBack
.
FillMode
tells the rasterizer how to fill in the triangles. Fill
completely fills the triangle. Line
only renders the edges of the face. Point
only renders the input points. Line
mode is also referred to as "wireframe rendering" which is useful for debugging.
LineWidth
describes lines in terms of pixel width. Maximum line width above 1f is hardware-specific so be careful with this one.
Finally, the rasterizer can alter depth values by adding a constant factor or biasing them based on slope. This can sometimes be useful for shadow mapping. Most of the time you won't be needing this and you can just set DepthBiasEnable
to false.
var myRasterizerState = new RasterizerState
{
FrontFace = FrontFace.Clockwise,
CullMode = CullMode.Back,
FillMode = FillMode.Fill,
LineWidth = 1f,
DepthBiasEnable = false
};