Drawing a gradient triangle with depth in mind

by ca1ek   Last Updated April 03, 2016 08:05 AM - source

I'm writing a software 3D rasterizer.

I managed to get a gradient triangle to work in it:

gradient triangle img

And a triangle with z-depth shown on it:

depth triangle img

But, how do I blend these two? So that I draw a gradient triangle in a way that the top vertice color is smaller as it's more far away while the others take up more space because they are closer?



Answers 1


What you probably need is usually called "fog".

Define fog color (e.g. grey) and its min/max depths. Then, depending on the depth you have on your triangles fragments (pixels) mix in the fog color.

if depth < fog_min then
  color
else
if depth < fog_max then
  color = mix(color, fog_color, (depth - fog_min) / (fog_max - fog_min))
else
  color = fog_color;
Krom Stern
Krom Stern
April 03, 2016 09:58 AM

Related Questions





Isometric painter's algorithm problem

Updated October 13, 2016 09:05 AM