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

52 lines
2.2 KiB
Markdown
Raw Permalink Normal View History

2022-03-02 08:20:53 +00:00
---
title: "Attachment Info"
date: 2021-01-28T12:55:51-08:00
2022-03-04 18:40:39 +00:00
weight: 1
2022-03-02 08:20:53 +00:00
---
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
};
2022-03-04 18:34:23 +00:00
var myColorAttachmentDescription = new ColorAttachmentDescriptions
{
Format = TextureFormat.R8G8B8A8,
SampleCount = SampleCount.One,
BlendState = myColorTargetBlendState,
};
2022-03-02 08:20:53 +00:00
```
2022-03-04 18:40:39 +00:00
There's a convenient constructor for putting this all together.
```cs
var myAttachmentInfo = new GraphicsPipelineAttachmentInfo(
TextureFormat.D16,
myColorAttachmentDescription
);
```