primitive types and rasterizer
continuous-integration/drone/push Build is passing Details

main
cosmonaut 2021-01-27 15:45:15 -08:00
parent 6ae0fef808
commit 9f38535a3d
2 changed files with 51 additions and 0 deletions

View File

@ -0,0 +1,19 @@
---
title: "PrimitiveType"
date: 2021-01-27T15:32:11-08:00
weight: 5
---
`PrimitiveType` determines how a stream of vertex information will be interpreted as shapes by the pipeline. There are 5 types of primitives that MoonWorks supports.
`PointList` will interpret the data as a list of points.
`LineList` will interpret the data as a list of lines.
`LineStrip` will interpet the data as a strip of lines.
`TriangleList` will interpret the data as a list of triangles.
`TriangleStrip` will interpret the data as a strip of triangles.
The primitive type you will use the most by far is `TriangleList` - the vast majority of 3D model exporters will give you vertex data in the form of a list of triangles. The others are mostly niche cases.

View File

@ -0,0 +1,32 @@
---
title: "Rasterizer State"
date: 2021-01-27T15:30:01-08:00
weight: 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.
```cs
var myRasterizerState = new RasterizerState
{
FrontFace = FrontFace.Clockwise,
CullMode = CullMode.Back,
FillMode = FillMode.Fill,
LineWidth = 1f,
DepthBiasEnable = false
};
```