Computer graphics in Game development

Ivan Belyavtsev

24.10.2020

[1]

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

Let’s implement it together

- Triangle strips ordering

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

- 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?

Let’s implement it together

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

```
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]

```
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]

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

Let’s implement it together

- Z-buffer culling solves hard cases

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.