Difference between revisions of "3D Fundamentals Tutorial 10"
From Chilipedia
(Created page with "In this tutorial we get the butt wiggling texture to respect our authoritae! In other words, we upgrade our affine texture mapping to perspective-correct texture mapping. ==...") |
(→Video) |
||
(4 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
− | In this tutorial we get the butt wiggling texture to respect our authoritae! In other words, we upgrade our affine texture mapping to perspective-correct texture mapping. | + | In this tutorial we get the butt wiggling texture to respect our authoritae! In other words, we upgrade our affine texture mapping to perspective-correct texture mapping, putting the kibosh on the fucked-up texture distortion. |
== Video == | == Video == | ||
− | The tutorial video is on YouTube [https://youtu.be/ | + | The tutorial video is on YouTube [https://youtu.be/1Dv2-cLAJXw here]. |
+ | |||
+ | You can see a video that really exaggerates what affine (warpy) textures look like [https://youtu.be/8IRT3SdRz8c?t=1260 here]. | ||
+ | |||
+ | <div class="mw-collapsible mw-collapsed"><br /> | ||
+ | * The need for perspective correction: texture warping [https://youtu.be/1Dv2-cLAJXw?t=0m47s 0:47] | ||
+ | * Explanation & visualization of the problem [https://youtu.be/1Dv2-cLAJXw?t=1m57s 1:57] | ||
+ | <div class="mw-collapsible-content"> | ||
+ | :* Linear mapping of screen coordinates to texture coordinates is not correct | ||
+ | :* Reason: interpolation in screenspace is different from interpolation in object space (and all attributes of the object) | ||
+ | :* We need "foreshortening": far things get compressed, close things get expanded | ||
+ | </div> | ||
+ | * The math: the z divide makes mapping nonlinear [https://youtu.be/1Dv2-cLAJXw?t=4m28s 4:28] | ||
+ | * Solution: interpolate between the z-divided texture coordinates [https://youtu.be/1Dv2-cLAJXw?t=5m00s 5:00] | ||
+ | * Implementing this into code [https://youtu.be/1Dv2-cLAJXw?t=8m40s 8:40] | ||
+ | <div class="mw-collapsible-content"> | ||
+ | :* In <code>PubeScreenTransformer.h</code> (where the projection / z-divide is applied) | ||
+ | :* In <code>Pipeline.h</code> (where the interpolation is done) [https://youtu.be/1Dv2-cLAJXw?t=10m57s 10:57] | ||
+ | </div> | ||
+ | * Demo [https://youtu.be/1Dv2-cLAJXw?t=11m57s 11:57] | ||
+ | * How perspective correction was (not) handled in early 3d games [https://youtu.be/1Dv2-cLAJXw?t=12m16s 12:16] | ||
+ | <div class="mw-collapsible-content"> | ||
+ | :* To fully correct, you need an expensive reciprocal operation 1/z for every pixel drawn | ||
+ | :* PS1 just didn't give a shit [https://youtu.be/1Dv2-cLAJXw?t=13m45s 13:45] | ||
+ | </div> | ||
+ | * Solution used in hardware pipelines / GPUs [https://youtu.be/1Dv2-cLAJXw?t=14m11s 14:11] | ||
+ | <div class="mw-collapsible-content"> | ||
+ | :* Control how each vertex attribute is interpolated independently (interpolation modifiers) | ||
+ | </div> | ||
+ | * References to full math derivations [https://youtu.be/1Dv2-cLAJXw?t=14m50s 14:50] | ||
+ | * Side effect of our solution: we now have the correct z-values for each pixel [https://youtu.be/1Dv2-cLAJXw?t=16m20s 16:20] | ||
+ | </div> | ||
== Downloads == | == Downloads == |
Latest revision as of 02:41, 10 June 2020
In this tutorial we get the butt wiggling texture to respect our authoritae! In other words, we upgrade our affine texture mapping to perspective-correct texture mapping, putting the kibosh on the fucked-up texture distortion.
Video
The tutorial video is on YouTube here.
You can see a video that really exaggerates what affine (warpy) textures look like here.
- The need for perspective correction: texture warping 0:47
- Explanation & visualization of the problem 1:57
- Linear mapping of screen coordinates to texture coordinates is not correct
- Reason: interpolation in screenspace is different from interpolation in object space (and all attributes of the object)
- We need "foreshortening": far things get compressed, close things get expanded
- The math: the z divide makes mapping nonlinear 4:28
- Solution: interpolate between the z-divided texture coordinates 5:00
- Implementing this into code 8:40
- In
PubeScreenTransformer.h
(where the projection / z-divide is applied) - In
Pipeline.h
(where the interpolation is done) 10:57
- In
- To fully correct, you need an expensive reciprocal operation 1/z for every pixel drawn
- PS1 just didn't give a shit 13:45
- Solution used in hardware pipelines / GPUs 14:11
- Control how each vertex attribute is interpolated independently (interpolation modifiers)
Downloads
The GitHub repository for the tutorial code is here.