3D Fundamentals Tutorial 10

From Chilipedia
Revision as of 02:37, 10 June 2020 by R vdw (Talk | contribs) (Video)

Jump to: navigation, search

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
  • Demo 11:57
  • How perspective correction was (not) handled in early 3d games 12:16
  • To fully correct, you need an expensive reciprocal operation 1/z for every pixel drawn
  • Some awful examples of badly handled perspective drawing 13:45
  • Solution used in hardware pipelines / GPUs 14:11
  • Control how each vertex attribute is interpolated independently (interpolation modifiers)
  • References to full math derivations 14:50
  • Side effect of our solution: we now have the correct z-values for each pixel 16:20

Downloads

The GitHub repository for the tutorial code is here.

Mathematical Derivations

See also