Lecture 05: Culling. Depth buffer

Computer graphics in Game development

Ivan Belyavtsev

24.10.2020

Backface culling

From: https://www.scratchapixel.com/lessons/3d-basic-rendering/rasterization-practical-implementation/rasterization-stage [1]

“Backface culling” experiment

Deduction phase

  • Check it out on the Cornell box obj
  • What about performance?

“Backface culling” experiment

Experiment

Let’s implement it together

“Backface culling” experiment

What is the new knowledge?

  • Triangle strips ordering

Order of rendering

Idea: sort all triangles from farthest to nearest from camera [2]

“Order of rendering” experiment

Deduction phase

  • After transformations Z-coordinate is still exist
  • Is it possible to sort triangle by Z to nearest triangles will cover farthest one’s?
  • What about performance?

“Order of rendering” experiment

Experiment

Let’s implement it together

“Order of rendering” experiment

What is the new knowledge?

  • Solves the ordering issue
  • Requires preliminary sorting of triangles
  • Exists more complex cases

Mixed-triangle case

Kliment Redko. Suprematism

Kliment Redko. Suprematism

Depth buffer

vector<color> frame_buffer;
vector<float> depth_buffer; //+Infs, for instance

void SetPixel(unsigned short x, unsigned short y, float z, color color)
{
    frame_buffer[y * width + x] = color;
    depth_buffer[y * width + x] = z;
}

[2]

Z-buffer culling

bool DepthTest(unsigned short x, unsigned short y, float z)
{
    return z < depth_buffer[y * width + x]; //Depends on Z-axis directions
}

void SetPixel(unsigned short x, unsigned short y, float z, color color)
{
    if (DepthTest(x, y, z))
    {
        frame_buffer[y * width + x] = color;
        depth_buffer[y * width + x] = z;
    }
}

[2]

“Z-buffer culling” experiment

Deduction phase

  • Possible to skip SetPixel if depth test fails
  • What about performance?

“Z-buffer culling” experiment

Experiment

Let’s implement it together

“Z-buffer culling” experiment

Reference

From: https://github.com/djbelyak/basic-of-rasterization/blob/main/references/depth_buffer.png

“Z-buffer culling” experiment

What is the new knowledge?

  • Z-buffer culling solves hard cases

References

1.
Rasterization: A practical implementation [Electronic resource]. 2015. URL: https://www.scratchapixel.com/lessons/3d-basic-rendering/rasterization-practical-implementation/rasterization-stage.
2.
Marschner S., Shirley P. Fundamentals of computer graphics, fourth edition. 4th ed. Natick, MA, USA: A. K. Peters, Ltd., 2016.
// reveal.js plugins