You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/tutorials/building_2d_games/24_shaders/index.md
+20Lines changed: 20 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -61,6 +61,26 @@ For our Dungeon Slime game, we'll focus primarily on pixel shaders since we want
61
61
> [!NOTE]
62
62
> There are other types of shaders beyond vertex and pixel shaders, such as compute shaders, geometry shaders, and hull/domain shaders. These more advanced shader types enabled powerful features like physics simulations, procedural geometry, and complex post-processing effects. However, they are not currently supported in the standard MonoGame implementation and are beyond the scope of this beginner tutorial. As the MonoGame graphics pipeline evolves, support for these advanced shader types may be added in future versions.
63
63
64
+
### The Shader Pipeline
65
+
66
+
To understand how shaders work, it helps to visualize how data flow through the rendering pipeline.
67
+
68
+
||
|**Figure 24-1: Basic shader pipeline showing how data flows through the rendering process**|
71
+
72
+
This diagram illustrates the fundamental steps of the shader pipeline:
73
+
74
+
1.**Input Data**: The process begins with input data that is sent to the GPU to render:
75
+
1.**Vertex Data**: The vertex data (positions, colors, etc.) that define the geometry of what is being drawn.
76
+
2.**Texture**: The image data that will be applied to the geometry.
77
+
2.**Vertex Shader**: Processes each vertex, calculating its final position on the screen and passing the data to the next stage.
78
+
3.**Sampler**: Controls how texture data is accessed, applying [filtering](../18_texture_sampling/index.md#filtering-modes) (how pixels blend when scaled) and [addressing](../18_texture_sampling/index.md#addressing-modes) (what happens at texture edges).
79
+
4.**Pixel Shader**: Takes the transformed vertices and sampled texture data to calculate the final color of each pixel.
80
+
5.**Output**: The final rendered image that appears on your screen.
81
+
82
+
When working with [**SpriteBatch**](xref:Microsoft.Xna.Framework.Graphics.SpriteBatch) (2D) in MonoGame, the framework handles most of the vertex shader work automatically, which is why we will focus primarily on writing pixel shaders for visual effects.
83
+
64
84
### Shader Languages and Cross-Platform Considerations
65
85
66
86
MonoGame uses the [High-Level Shader Language (HLSL)](https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl) for writing shader effects. HLSL is a C-like programming language developed by Microsoft for DirectX. As MonoGame also supports OpenGL which uses the [OpenGL Shading Language (GLSL)](https://www.khronos.org/opengl/wiki/OpenGL_Shading_Language) instead of DirectX, it needs a way to make shaders work everywhere.
0 commit comments