From 9f38535a3de0f42af189b602a97ac0239bb0a531 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Wed, 27 Jan 2021 15:45:15 -0800 Subject: [PATCH] primitive types and rasterizer --- .../GraphicsPipeline/PrimitiveType.md | 19 +++++++++++ .../GraphicsPipeline/RasterizerState.md | 32 +++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 content/Graphics/Resources/GraphicsPipeline/PrimitiveType.md create mode 100644 content/Graphics/Resources/GraphicsPipeline/RasterizerState.md diff --git a/content/Graphics/Resources/GraphicsPipeline/PrimitiveType.md b/content/Graphics/Resources/GraphicsPipeline/PrimitiveType.md new file mode 100644 index 0000000..b9f94aa --- /dev/null +++ b/content/Graphics/Resources/GraphicsPipeline/PrimitiveType.md @@ -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. diff --git a/content/Graphics/Resources/GraphicsPipeline/RasterizerState.md b/content/Graphics/Resources/GraphicsPipeline/RasterizerState.md new file mode 100644 index 0000000..cb2a1ed --- /dev/null +++ b/content/Graphics/Resources/GraphicsPipeline/RasterizerState.md @@ -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 +}; +```