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
>Themathtofullyexplainwhythisisrequiredisbeyondthescopeofthistutorialseries. Readabout [homogenouscoordinates](https://www.tomdalling.com/blog/modern-opengl/explaining-homogenous-coordinates-and-projective-geometry/) and the [perspective divide](https://www.scratchapixel.com/lessons/3d-basic-rendering/perspective-and-orthographic-projection-matrix/projection-matrix-GPU-rendering-pipeline-clipping.html)
@@ -356,9 +346,9 @@ It was helpful to use the `TitleScene` to build intuition for the vertex shader,
356
346
357
347
### Making One Big Shader
358
348
359
-
Aproblememergesrightaway. The `GameScene` isalreadyusingthecolorswappingeffecttodrawthesprites, and `SpriteBatch` canonlyuseasingleperbatch.
349
+
A problem emerges right away. The `GameScene` is already using the color swapping effect to draw the sprites, and `SpriteBatch` can only use a single shader per batch.
To solve this problem, we will collapse our shaders into a single shader that does it all, _both_ the color swapping _and_ the vertex manipulation. Writing code to be re-usable is a challenge for all programming languages, and shader languagess are no different.
362
352
363
353
> [!NOTE]
364
354
> The _Uber_ Shader
@@ -383,7 +373,12 @@ Follow the steps below to refactor the shader code, and to use the `#include` sy
Createafileinthe_MonoGameLibrary_'s `SharedContent/effects` folder called `common.fxh`. This file will contain utilities that can be shared for all effects, such as the `struct` types that define the inputs and outputs of the vertex and pixel shaders:
376
+
Createafileinthe_MonoGameLibrary_'s `SharedContent/effects` folder called `common.fxh`.
Thisfilewillcontainutilitiesthatcanbesharedfor all effects, such as the `struct` types that define the inputs and outputs of the vertex and pixel shaders:
387
382
388
383
[!code-hlsl[](./snippets/snippet-7-31.hlsl)]
389
384
@@ -401,9 +396,9 @@ Follow the steps below to refactor the shader code, and to use the `#include` sy
@@ -425,7 +420,10 @@ Follow the steps below to refactor the shader code, and to use the `#include` sy
425
420
426
421
Nowmostofthecomponentswewouldliketocombineintoasingleeffecthavebeensplitintovarious `.fxh` headerfiles, buttheirrelativelocationis**CRUCIAL** when refering to related functionality, to demonstrate this, we will "break" a shader and show how to fix it.
@@ -462,6 +460,8 @@ Follow the steps below to refactor the shader code, and to use the `#include` sy
462
460
463
461
[!code-csharp[](./snippets/snippet-7-42.cs)]
464
462
463
+
13. Somewhat optionally, remember to add the `rasterizerState: RasterizerState.CullNone` to the `SpriteBatch.Draw()` call if you do not want the game to vanish when the `SpinAmount` goes beyond half a rotation. In practice, we will not be be spinning the game world that much, so it does not really matter.
464
+
465
465
Any remaining places where the old `_colorSwapMaterial` is being referenced should be changed to use the `_gameMaterial` instead, including in the `Update` and `Draw` methods. (if you still have any old references to the `_grayscaleEffect` make sure to remove those as well as they are no longer used).
466
466
467
467
Now, if you run the game, the color swap controls are still visible, but we can also manually control the tilt of the map.
0 commit comments