-
Notifications
You must be signed in to change notification settings - Fork 69
2d shader tutorial #171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
2d shader tutorial #171
Changes from 4 commits
Commits
Show all changes
118 commits
Select commit
Hold shift + click to select a range
33381d6
update action to allow deploying other branches
cdhanna 20f2bf8
2dshader tutorial
cdhanna 827d325
Merge branch 'main-monogame'
cdhanna 8499c83
edits to toc
cdhanna dbfe09a
restore missing chapter 4.
cdhanna a84df78
pass to remove all contractions
cdhanna 9c4143d
tracking: 2.1
cdhanna eb08554
tracking 3.1
cdhanna cb91fd0
tracking 3.2
cdhanna d623455
tracking 3.3
cdhanna 2b1b856
tracking 3.4
cdhanna c27012b
tracking 3.5
cdhanna 8093200
tracking 3.6
cdhanna 9dfa203
tacking 3.7
cdhanna 00a7f5e
tracking 3.8
cdhanna 1398f3f
update submodules
cdhanna aaebb02
struggling with submodules
cdhanna 3fc677a
restore inside submodule
cdhanna 414f8a3
copying premake step from main repo
cdhanna 0c9437d
restore mg stuff
cdhanna b59721e
Merge branch 'main' into main
SimonDarksideJ 9be7a65
Merge branch 'main' into main
SimonDarksideJ dafd0fc
Merge branch 'main' into main
SimonDarksideJ 60d7a86
Fixed SpriteBatch xref, no such item in the MonoGame API called "Spri…
SimonDarksideJ 463baec
Merge branch 'main-monogame'
cdhanna ff17275
adding gif support to docfx file
cdhanna 7cdb033
submodules up to dev
cdhanna 287c92d
build
cdhanna 1068ddf
steal more build stuff from main repo
cdhanna baf71f0
add public folder to resources
cdhanna ff26e43
playing around with sitemap
cdhanna 10ef1b4
use rel link
cdhanna 71d61e9
fix toc; add hot reload at runtime message
cdhanna 1336eb4
standardizing media link formatting
cdhanna 7f3045c
extracted snippets and highlighted 02
cdhanna 8ef191c
highlighting 03
cdhanna a9a0fa8
highlight 04
cdhanna eaba03a
tracking 4.1
cdhanna 99142e6
tracking 5.1; overview gif
cdhanna c8a7cca
tracking 5.2; removed restatement of intro
cdhanna b4faa2c
tracking 5.3; mgcb pic, admonishments, minor typos
cdhanna f3003f8
tracking 5.4; some highlighting
cdhanna 4d83827
tracking 5.5; note about auto shader parameter
cdhanna 3bf0f4b
tracking 5.6
cdhanna bc7032d
tracking 5.7; smoothstep admonishment and top bold
cdhanna a12bc08
more code snippet updates in chapter 5
cdhanna aeee225
tracking 5.8; gradient textures in horizontal table
cdhanna 215a3bc
more chapter 5 highlighting
cdhanna dc5e7c7
more code highlights for chapter 5
cdhanna 8570b10
tracking 5.9
cdhanna 76973fd
tracking 6-1; add overview graphic
cdhanna ee55ad9
tracking 6.2; mgcb screenshot and reword
cdhanna 3bcb3a4
tracking 5.10; update to list
cdhanna ac84ea0
tracking 6.3
cdhanna 1019fb5
tracking 6.4; bigger image previews
cdhanna 017e2cb
tracking 6.5; table for colors
cdhanna 58f4c8e
tracking 6.6
cdhanna 48d4ddd
tracking 6.7; sources for luts
cdhanna d3c8191
highlighting snippets for 06
cdhanna c7331e3
fix css issues
cdhanna c31440d
tracking 7.1; overview gifs
cdhanna 352e8e8
tracking 7.2; clarification around SV_Position
cdhanna c20b94e
fix admonishment typo
cdhanna e1a4fb4
tracking 7.3
cdhanna aac4d2d
tracking 7.4
cdhanna efc1869
tracking 7.5; number steps and mgcb screenshot
cdhanna 6154cdb
some 07 snippets
cdhanna 5b29b39
07 highlighting
cdhanna 2f2b685
tracking 7.6; add missing text image
cdhanna 44e228d
tracking 7.7; culling note
cdhanna 113c0fa
tracking 7.8 ; walk back uber shader into admonish
cdhanna 6e814c5
tracking 7.9 numbered steps
cdhanna d91ee41
tracking 8.1; dry and add overview gif
cdhanna 1beda0a
tracking 8.2; add definitions
cdhanna c5ec5a9
tracking 8.3; render target null
cdhanna 9a9929b
tracking 8.4; numbering steps and adding mgcb shots
cdhanna 27c111c
tracking 8.5; add normal map link
cdhanna 20a8d36
tracking 8.6; figures and workarounds
cdhanna f772f42
tracking 8.7; add another visual demo
cdhanna 6478fd7
tracking 8.8
cdhanna 0517ea0
some 08 highlights
cdhanna 6c0c989
highlights for 08
cdhanna 0ea6c63
add overview gif for chapter 9
cdhanna 168f4aa
figure update
cdhanna 3cfce22
adding mgcb
cdhanna a1f0ebf
tracking 9.1; numbering
cdhanna 74f22b4
tracking 9.2; bit packing links
cdhanna e66e148
highlighitng and snippet context for 09
cdhanna 265bc10
shadow visual improvements
cdhanna 4748199
use overview gif
cdhanna 7e802ba
tracking 10.1
cdhanna c94437a
format sig
cdhanna dc05dd9
minor clerical errors
cdhanna 6ddec86
Review fixes
SimonDarksideJ a0214b6
Revert code block fixes
SimonDarksideJ 4e4975e
tracking b2-1
cdhanna df41d18
tracking b2-2
cdhanna 81306e6
Review/simon (#2)
SimonDarksideJ a6acacf
update hot reload for auto-start, net9, and support dotnet-run
cdhanna 31c7a84
Rename snippet
SimonDarksideJ bac8e9f
Chapter 6 changes
SimonDarksideJ 611fbbc
Feature/review continues (#3)
SimonDarksideJ b2baf7b
Further review and clean-up - CH6 / 7 (#4)
SimonDarksideJ f6094a5
updates for chapter 2
cdhanna a7d3c48
chapter 3 updates
cdhanna f8530ae
chapter 4 edits
cdhanna f5d039f
chapter 5 edits
cdhanna 7039e08
chapter 6 notes
cdhanna 056a034
some chapter 7 edits
cdhanna d95ce15
more chap7 notes
cdhanna 014a349
some chap 8 comments
cdhanna 9288f99
more chap 8 comments
cdhanna 2c76f1a
fix chap 6 content dir, and fix chap 8 w confusion
cdhanna 1b446d1
very minor changes
cdhanna a087b1d
figure 9-7
cdhanna b7e5362
fix fig numbers in 09
cdhanna 56a9926
some chap 9 comments
cdhanna d71cd17
more chap 9 comments
cdhanna File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
articles/tutorials/advanced/2d_shaders/01_introduction/index.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| --- | ||
| title: "Chapter 01: Getting Started" | ||
| description: "Prepare your project and get ready" | ||
| --- | ||
|
|
||
| Welcome to the advanced 2D shaders tutorial! Before we dive into writing complex effects, this first chapter will make sure you're ready to go. We will get the starting project set up and take a quick look at the technical foundation of how shaders work with MonoGame's `SpriteBatch`. | ||
|
|
||
| ## The Starting Code | ||
|
|
||
| This tutorial series builds directly on top of the final code from the "Building 2D Games" tutorial. It is essential that you start with this project. | ||
|
|
||
| > [!note] | ||
| > You can get the complete starting source code for this tutorial here: | ||
| > [The final chapter's source code](https://github.com/MonoGame/MonoGame.Samples/tree/3.8.4/Tutorials/learn-monogame-2d/src/24-Shaders/) | ||
|
|
||
| Once you have the code downloaded, open it in your IDE and run the `DungeonSlime` project to make sure everything is working correctly. You should see the title screen from the previous tutorial. | ||
|
|
||
| ## Project Structure | ||
|
|
||
| The solution is organized into two main projects: | ||
|
|
||
| - **`DungeonSlime`**: The main game project. This contains our game logic and game-specific content. | ||
| - **`MonoGameLibrary`**: Our reusable class library. We will be adding new, generic helper classes here that could be used in any of your future MonoGame projects. | ||
|
|
||
| Most of our shader files (`.fx`) will be created in the `Content/effects` folder within the `DungeonSlime` project to start, and later within the `MonoGameLibrary` for shared effects. | ||
|
|
||
| ## What's Next | ||
|
|
||
| Now that our project is set up, we can get to work. The focus for the first several chapters will be to create a workflow for developing shaders in MonoGame. Once we have a hot-reload system, a class to manage the effects, and a debug UI ready, we will carry on and build up 5 effects. The effects will range from simple pixel shaders and vertex shaders up to rendering techniques. As we develop these shaders together, we will build an intuition for how to tackle shader development. | ||
|
|
||
| Continue to the next chapter, [Chapter 02: Hot Reload](../02_hot_reload/index.md) | ||
|
|
||
|
|
||
458 changes: 458 additions & 0 deletions
458
articles/tutorials/advanced/2d_shaders/02_hot_reload/index.md
Large diffs are not rendered by default.
Oops, something went wrong.
5 changes: 5 additions & 0 deletions
5
articles/tutorials/advanced/2d_shaders/02_hot_reload/snippets/DungeonSlime.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| <ItemGroup> | ||
| <PackageReference Include="Gum.MonoGame" Version="2025.5.1.1" /> | ||
| <PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.*" /> | ||
| <PackageReference Include="MonoGame.Content.Builder.Task" Version="3.8.*" /> | ||
| </ItemGroup> |
42 changes: 42 additions & 0 deletions
42
articles/tutorials/advanced/2d_shaders/02_hot_reload/snippets/WatchedAsset.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| #region declaration | ||
| using System; | ||
| using Microsoft.Xna.Framework.Content; | ||
|
|
||
| namespace MonoGameLibrary.Content; | ||
|
|
||
| public class WatchedAsset<T> | ||
| { | ||
|
|
||
| } | ||
|
|
||
| #endregion | ||
| { | ||
| #region members | ||
| /// <summary> | ||
| /// The latest version of the asset. | ||
| /// </summary> | ||
| public T Asset { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// The last time the <see cref="Asset"/> was loaded into memory. | ||
| /// </summary> | ||
| public DateTimeOffset UpdatedAt { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// The name of the <see cref="Asset"/>. This is the name used to load the asset from disk. | ||
| /// </summary> | ||
| public string AssetName { get; init; } | ||
|
|
||
| /// <summary> | ||
| /// The <see cref="ContentManager"/> instance that loaded the asset. | ||
| /// </summary> | ||
| public ContentManager Owner { get; init; } | ||
| #endregion | ||
|
|
||
| #region methods | ||
| public bool TryRefresh(out T oldAsset) | ||
| { | ||
| return Owner.TryRefresh(this, out oldAsset); | ||
| } | ||
| #endregion | ||
| } |
36 changes: 36 additions & 0 deletions
36
articles/tutorials/advanced/2d_shaders/02_hot_reload/snippets/dotnet-tools.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| { | ||
| "version": 1, | ||
| "isRoot": true, | ||
| "tools": { | ||
| "dotnet-mgcb": { | ||
| "version": "3.8.3", | ||
| "commands": [ | ||
| "mgcb" | ||
| ] | ||
| }, | ||
| "dotnet-mgcb-editor": { | ||
| "version": "3.8.3", | ||
| "commands": [ | ||
| "mgcb-editor" | ||
| ] | ||
| }, | ||
| "dotnet-mgcb-editor-linux": { | ||
| "version": "3.8.3", | ||
| "commands": [ | ||
| "mgcb-editor-linux" | ||
| ] | ||
| }, | ||
| "dotnet-mgcb-editor-windows": { | ||
| "version": "3.8.3", | ||
| "commands": [ | ||
| "mgcb-editor-windows" | ||
| ] | ||
| }, | ||
| "dotnet-mgcb-editor-mac": { | ||
| "version": "3.8.3", | ||
| "commands": [ | ||
| "mgcb-editor-mac" | ||
| ] | ||
| } | ||
| } | ||
| } |
Binary file added
BIN
+593 KB
articles/tutorials/advanced/2d_shaders/02_hot_reload/videos/shader-reload.mp4
Binary file not shown.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.