Difference between revisions of "3D Fundamentals Tutorial 11"

From Chilipedia
Jump to: navigation, search
(Downloads)
(Video)
 
(One intermediate revision by the same user not shown)
Line 4: Line 4:
  
 
The tutorial video is on YouTube [https://youtu.be/HyVc0X9JKpg here].
 
The tutorial video is on YouTube [https://youtu.be/HyVc0X9JKpg here].
 +
 +
<div class="mw-collapsible mw-collapsed"><br />
 +
* The need for occlusion in scenes with multiple objects [https://youtu.be/HyVc0X9JKpg?t=0m24s 0:24]
 +
<div class="mw-collapsible-content">
 +
:* We used culling of triangles when drawing convex shapes
 +
:* But this doen't solve our problem with occlusion (e.g. multiple meshes in the same scene)
 +
:* One could considers the painter's algorithm, but that's inefficient and of limited use
 +
</div>
 +
* Solution: the z-buffer: simple, elegant & performant [https://youtu.be/HyVc0X9JKpg?t=2m27s 2:27]
 +
<div class="mw-collapsible-content">
 +
:* Essentially sorts triangles based on their depth at the pixel level
 +
:* Uses two 2D-arrays (for x,y coordinates): a back-buffer (of colors, in <code>gfx</code> in our case) as a render target, and a z-buffer (of floats) to store depth
 +
:* We initialize the z-buffer with infinity
 +
:* Whenever we want to write to the back-buffer, we check to see if z-value of the pixel we are drawing is smaller (and set the z-buffer in that case)
 +
:* This is a special sorting case [https://youtu.be/HyVc0X9JKpg?t=6m26s 6:26]
 +
</div>
 +
* Implementation in code [https://youtu.be/HyVc0X9JKpg?t=7m06s 7:06]
 +
<div class="mw-collapsible-content">
 +
:* The <code>ZBuffer</code> class
 +
:* Changes to the <code>Pipeline</code> class, <code>if (zb.TestAndSet(x,y,z))</code> before the <code>PutPixel</code> call
 +
</div>
 +
* If done well, Z-testing can reduce rendering time [https://youtu.be/HyVc0X9JKpg?t=9m54s 9:54]
 +
<div class="mw-collapsible-content">
 +
:* Works best if geometries are sorted and drawn from front to back (more Z-test rejections)
 +
:* This is contrary to intuition and old/other techniques (e.g. in 2D: drawing sprites and tilemaps)
 +
</div>
 +
* Scene definitions and demo [https://youtu.be/HyVc0X9JKpg?t=10m58s 10:58]
 +
* Differences with Hardware APIs [https://youtu.be/HyVc0X9JKpg?t=11m50s 11:50]
 +
<div class="mw-collapsible-content">
 +
:* These provide more options for configuring the z-buffer, such as depth comparison operators, choice of formats/types
 +
:* These typically store 1/z in the buffer, requiring corrections for depth precision (high in the near plane, low in the far plane)
 +
</div>
 +
* Dealing with translucent pixels and depth [https://youtu.be/HyVc0X9JKpg?t=13m58s 13:58]
 +
<div class="mw-collapsible-content">
 +
:* You will need to store the order of all the translucent pixels up until the first opaque one
 +
</div>
 +
* Stencil Buffers [https://youtu.be/HyVc0X9JKpg?t=14m28s 14:28]
 +
<div class="mw-collapsible-content">
 +
:* Provide more flexibility to reject pixels & have more control (general purpose bufffers)
 +
:* E.g. for UIs, HUDs, mirrors, shadow effects etc.
 +
</div>
 +
* Next up: vertex shaders and working towards dynamic lighting effects [https://youtu.be/HyVc0X9JKpg?t=15m00s 15:00]
 +
</div>
  
 
== Downloads ==
 
== Downloads ==

Latest revision as of 03:31, 15 June 2020

Things that are behind get covered up by things that are in front.

Video

The tutorial video is on YouTube here.


  • The need for occlusion in scenes with multiple objects 0:24
  • We used culling of triangles when drawing convex shapes
  • But this doen't solve our problem with occlusion (e.g. multiple meshes in the same scene)
  • One could considers the painter's algorithm, but that's inefficient and of limited use
  • Solution: the z-buffer: simple, elegant & performant 2:27
  • Essentially sorts triangles based on their depth at the pixel level
  • Uses two 2D-arrays (for x,y coordinates): a back-buffer (of colors, in gfx in our case) as a render target, and a z-buffer (of floats) to store depth
  • We initialize the z-buffer with infinity
  • Whenever we want to write to the back-buffer, we check to see if z-value of the pixel we are drawing is smaller (and set the z-buffer in that case)
  • This is a special sorting case 6:26
  • Implementation in code 7:06
  • The ZBuffer class
  • Changes to the Pipeline class, if (zb.TestAndSet(x,y,z)) before the PutPixel call
  • If done well, Z-testing can reduce rendering time 9:54
  • Works best if geometries are sorted and drawn from front to back (more Z-test rejections)
  • This is contrary to intuition and old/other techniques (e.g. in 2D: drawing sprites and tilemaps)
  • Scene definitions and demo 10:58
  • Differences with Hardware APIs 11:50
  • These provide more options for configuring the z-buffer, such as depth comparison operators, choice of formats/types
  • These typically store 1/z in the buffer, requiring corrections for depth precision (high in the near plane, low in the far plane)
  • Dealing with translucent pixels and depth 13:58
  • You will need to store the order of all the translucent pixels up until the first opaque one
  • Provide more flexibility to reject pixels & have more control (general purpose bufffers)
  • E.g. for UIs, HUDs, mirrors, shadow effects etc.
  • Next up: vertex shaders and working towards dynamic lighting effects 15:00

Downloads

The GitHub repository for the tutorial code is here.

Paper on depth precision

See also