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/advanced/2d_shaders/07_sprite_vertex_effect/index.md
+27-21Lines changed: 27 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -169,15 +169,21 @@ Follow along with the steps to set up the effect.
169
169
170
170
[!code-csharp[](./snippets/snippet-7-16.cs)]
171
171
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-5: We can control the vertex positions**|
202
+
|**Figure 7-6: We can control the vertex positions**|
197
203
198
204
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:
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.
203
209
204
-
||
210
+
||
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:
|**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**|
270
276
271
277
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:
272
278
@@ -280,9 +286,9 @@ And instead of manually controlling the spin angle, we can make the title spin g
@@ -368,9 +374,9 @@ And then apply all of the parameters to the single material:
368
374
369
375
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.
370
376
371
-
||
377
+
||
0 commit comments