Ivan Belyavtsev
22.01.2022
The renderer doesn’t take into account which the triangle is closer to the camera and renders the triangle on top of the previous one [1]
For rasterization we are using \(x\) and \(y\) only. Let’s store \(z\) coordinate of pixel to separated buffer. This buffer is called depth buffer (or z-buffer) [2]
bool DepthTest(unsigned short x, unsigned short y, float z)
{
return z < depth_buffer(x, y)]; //Depends on Z-axis directions
}
void SetPixel(unsigned short x, unsigned short y, float z,)
{
auto color = pixel_shader(attributes);
if (DepthTest(x, y, z))
{
frame_buffer(x, y) = color;
depth_buffer(x, y) = z;
}
}
[2]
auto color = pixel_shader(attributes);
if (DepthTest(x, y, z))
{
frame_buffer(x, y) = color;
depth_buffer(x, y) = z;
}
[3]
[3]
set_render_target
, and clear_render_target
methods of cg::renderer::rasterizer
class to consume a depth buffercg::renderer::rasterization_renderer
depth_test
function of cg::renderer::rasterizer
classDepth test
stage to draw
method of cg::renderer::rasterizer
rasterization
tagrasterization
tagDue date: Friday, 4 February 2022, 12:00 AM