Skip to content

Commit 2f2b685

Browse files
committed
tracking 7.6; add missing text image
1 parent 5b29b39 commit 2f2b685

File tree

2 files changed

+27
-21
lines changed

2 files changed

+27
-21
lines changed
48.9 KB
Loading

articles/tutorials/advanced/2d_shaders/07_sprite_vertex_effect/index.md

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,21 @@ Follow along with the steps to set up the effect.
169169

170170
[!code-csharp[](./snippets/snippet-7-16.cs)]
171171

172-
9. When the game runs, the text will be missing. This is because we never created a projection matrix to assign to the `MatrixTransform` shader parameter. Add this code when loading the material:
172+
9. When the game runs, the text will be missing. This is because we never created a projection matrix to assign to the `MatrixTransform` shader parameter.
173+
174+
| ![Figure 7-4: The main menu title is missing](./images/missing-text.png) |
175+
| :----------------------------------------------------------------------------------------: |
176+
| **Figure 7-4: The main menu title is missing** |
177+
178+
Add this code when loading the material:
173179

174180
[!code-csharp[](./snippets/snippet-7-17.cs)]
175181

176182
10. And now you should see the text normally again.
177183

178-
| ![Figure 7-4: The main menu, but rendered with a custom vertex shader](./images/basic.png) |
184+
| ![Figure 7-5: The main menu, but rendered with a custom vertex shader](./images/basic.png) |
179185
| :----------------------------------------------------------------------------------------: |
180-
| **Figure 7-4: The main menu, but rendered with a custom vertex shader** |
186+
| **Figure 7-5: The main menu, but rendered with a custom vertex shader** |
181187

182188
### Making it Move
183189

@@ -191,19 +197,19 @@ And change the vertex shader to add the `DebugOffset` to the `output.Position` a
191197

192198
The sprites now move around as we adjust the shader parameter values.
193199

194-
| ![Figure 7-5: We can control the vertex positions](./gifs/basic.gif) |
200+
| ![Figure 7-6: We can control the vertex positions](./gifs/basic.gif) |
195201
| :------------------------------------------------------------------: |
196-
| **Figure 7-5: We can control the vertex positions** |
202+
| **Figure 7-6: We can control the vertex positions** |
197203

198204
It is important to build intuition for the different coordinate systems involved. Instead of adding the `DebugOffset` _after_ the clip-space conversion, if you try to add it _before_, like in the code below:
199205

200206
[!code-hlsl[](./snippets/snippet-7-20.hlsl?highlight=7)]
201207

202208
Then you will not see much movement at all. This is because the `DebugOffset` values only go from `0` to `1`, and in world space, this really only amounts to a single pixel. In fact, exactly how much an addition of _`1`_ happens to make is entirely defined _by_ the conversion to clip-space. The `projection` matrix we created treats world space coordinates with an origin around the screen's center, where 1 unit maps to 1 pixel. Sometimes this is exactly what you want, and sometimes it can be confusing.
203209

204-
| ![Figure 7-6: Changing coordinates before clip-space conversion](./gifs/basic-2.gif) |
210+
| ![Figure 7-7: Changing coordinates before clip-space conversion](./gifs/basic-2.gif) |
205211
| :----------------------------------------------------------------------------------: |
206-
| **Figure 7-6: Changing coordinates before clip-space conversion** |
212+
| **Figure 7-7: Changing coordinates before clip-space conversion** |
207213

208214
### Perspective Projection
209215

@@ -248,25 +254,25 @@ Moving the `z` value uniformly in the shader will not be visually stimulating. A
248254

249255
And now when the debug parameter is adjusted, the text spins in a way that was never possible with the default `SpriteBatch` vertex shader.
250256

251-
| ![Figure 7-7: A spinning text](./gifs/spin-1.gif) |
257+
| ![Figure 7-8: A spinning text](./gifs/spin-1.gif) |
252258
| :-----------------------------------------------: |
253-
| **Figure 7-7: A spinning text** |
259+
| **Figure 7-8: A spinning text** |
254260

255261
The text disappears for half of the rotation. That happens because as the vertices are rotated, the triangle itself started to point _away_ from the camera. By default, `SpriteBatch` will cull any faces that point away from the camera. Change the `rasterizerState` to `CullNone` when beginning the sprite batch:
256262

257263
[!code-csharp[](./snippets/snippet-7-26.cs?highlight=4)]
258264

259265
And voilà, the text no longer disappears on its flip side.
260266

261-
| ![Figure 7-8: A spinning text with reverse sides](./gifs/spin-2.gif) |
267+
| ![Figure 7-9: A spinning text with reverse sides](./gifs/spin-2.gif) |
262268
| :------------------------------------------------------------------: |
263-
| **Figure 7-8: A spinning text with reverse sides** |
269+
| **Figure 7-9: A spinning text with reverse sides** |
264270

265271
You may find that the field of view is too high for your taste. Try lowering the field of view to 60, and you'll see something similar to this,
266272

267-
| ![Figure 7-9: A spinning text with reverse sides with smaller fov](./gifs/spin-3.gif) |
273+
| ![Figure 7-10: A spinning text with reverse sides with smaller fov](./gifs/spin-3.gif) |
268274
| :-----------------------------------------------------------------------------------: |
269-
| **Figure 7-9: A spinning text with reverse sides with smaller fov** |
275+
| **Figure 7-10: A spinning text with reverse sides with smaller fov** |
270276

271277
As a final touch, we should remove the hard-coded `screenSize` variable from the shader, and extract it as a shader parameter. While we are at it, clean up and remove the debug parameters as well:
272278

@@ -280,9 +286,9 @@ And instead of manually controlling the spin angle, we can make the title spin g
280286

281287
[!code-csharp[](./snippets/snippet-7-29.cs?highlight=5-7)]
282288

283-
| ![Figure 7-10: Spin controlled by the mouse](./gifs/spin-4.gif) |
289+
| ![Figure 7-11: Spin controlled by the mouse](./gifs/spin-4.gif) |
284290
| :------------------------------------------------------------: |
285-
| **Figure 7-10: Spin controlled by the mouse** |
291+
| **Figure 7-11: Spin controlled by the mouse** |
286292

287293
## Applying it to the Game
288294

@@ -368,9 +374,9 @@ And then apply all of the parameters to the single material:
368374

369375
Any place where the old `_colorSwapMaterial` is being referenced should be changed to use the `_gameMaterial` instead. Now, if you run the game, the color swap controls are still visible, but we can also manually control the tilt of the map.
370376

371-
| ![Figure 7-11: All of the effects in one](./gifs/uber.gif) |
377+
| ![Figure 7-12: All of the effects in one](./gifs/uber.gif) |
372378
| :-------------------------------------------------------: |
373-
| **Figure 7-11: All of the effects in one** |
379+
| **Figure 7-12: All of the effects in one** |
374380

375381
### Adjusting the Game
376382

@@ -380,19 +386,19 @@ Add this snippet to the top of the `GameScene`'s `Update()` method:
380386

381387
[!code-csharp[](./snippets/snippet-7-43.cs)]
382388

383-
| ![Figure 7-12: Camera follows the slime](./gifs/cam-follow.gif) |
389+
| ![Figure 7-13: Camera follows the slime](./gifs/cam-follow.gif) |
384390
| :------------------------------------------------------------: |
385-
| **Figure 7-12: Camera follows the slime** |
391+
| **Figure 7-13: Camera follows the slime** |
386392

387393
The clear color of the scene can be seen in the corners (the `CornflowerBlue`). Pick whatever clear color you think looks good for the color swapping:
388394

389395
[!code-csharp[](./snippets/snippet-7-44.cs)]
390396

391397
And to finish this chapter, the game looks like this,
392398

393-
| ![Figure 7-13: vertex shaders make it pop](./gifs/final.gif) |
399+
| ![Figure 7-14: vertex shaders make it pop](./gifs/final.gif) |
394400
| :---------------------------------------------------------: |
395-
| **Figure 7-13: vertex shaders make it pop** |
401+
| **Figure 7-14: vertex shaders make it pop** |
396402

397403
## Conclusion
398404

0 commit comments

Comments
 (0)