MoonWorks-docs/content/Graphics/Resources/GraphicsPipeline/AttachmentInfo.md

36 lines
1.8 KiB
Markdown

---
title: "Attachment Info"
date: 2021-01-28T12:55:51-08:00
weight: 10
---
GraphicsPipelineAttachmentInfo tells the graphics pipeline what kinds of render passes will be used with the pipeline. These are *compatible* render passes. It also describes how the pipeline should blend colors. Blending does not affect compatibility, but the other properties do.
This structure is composed of a set of ColorAttachmentDescriptions, and an optional depth/stencil format.
Each ColorAttachmentDescription is composed of a texture format, a multisample count, and a ColorAttachmentBlendState.
Our color attachment always has color information stored in it - the blend state tells the renderer how to combine new pixel values with the original values to produce a new color.
`BlendEnable` is a bool. If we turn off blending entirely, the new pixel color will just overwrite any existing values. Simple!
`ColorWriteMask` tells the renderer which color channels it is allowed to write to.
Next we have `AlphaBlendOp` and `ColorBlendOp`, which are `BlendOp` values, and the rest of the fields are `BlendFactor` values. Rather than spend a bunch of time explaining the nuances of various blend modes, I will simply link you to a [very thorough explanation of graphics blending](https://learnopengl.com/Advanced-OpenGL/Blending).
Here is an example blend mode, which does something we call "additive blending". This kind of blending is very useful for lighting and particle effects.
```cs
var myColorTargetBlendState = new ColorTargetBlendState
{
BlendEnable = true,
ColorWriteMask = ColorComponentFlags.RGBA,
AlphaBlendOp = BlendOp.Add,
ColorBlendOp = BlendOp.Add,
SourceColorBlendFactor = BlendFactor.SourceAlpha,
SourceAlphaBlendFactor = BlendFactor.SourceAlpha,
DestinationColorBlendFactor = BlendFactor.One,
DestinationAlphaBlendFactor = BlendFactor.One
};
```