What is the meaning of Z-buffering, as I imagine that scene with a couple of thousand polygons it for 10 years, won't draw?

I read about z-buffer, and these samples with 2 cubes, or 4 lines, just a question, what if there's, well, the usual gaming scene from Skyrim or any other game of the 21st century, there are several millions of faces, that is, 100 trees standing one after another, and that 99 trees will be outlined, and then blocked 100.
Or I something do not understand, or not using it for 30 years, so.
April 19th 20 at 12:16
4 answers
April 19th 20 at 12:18
Solution
Z-buffering is needed to correctly traverse complex objects.
In a modern graphics more difficult, but z-buffering is not going anywhere ever. It's just another technique to achieve some specific goals.
Generally draw 2K polygons is a trifling occupation for modern video cards. It is important that through the interstices of the foliage of this your hundredth tree looked through the trees or any other objects behind.
Polygons are sorted by the distance to the camera. First are drawn the most remote, then those that are closer.
Z-buffer and it is used not only for determining overlap of objects, but for fast search of objects under the beam.
suppose there is a file, which is painted the vertices, edges, faces, textures for faces. I need from all of these objects to represent in a raster format. And store it(if enough memory), and when to draw, to take
and fill in array of z-buffer color. And apply if their z is less.
And do I understand correctly that the depth is the z coordinate of the point to the camera from the point (0,0,z). - henri.Bergstr commented on April 19th 20 at 12:21
@henri.Bergstr,
I have from all of these objects to represent in a raster format

What do you mean?
fill in array of z-buffer color

the z buffer is a two - dimensional array, the size of the screen (or rather with the area you rendered) and each element of this array stores the distance from the camera to nearest to the camera point of intersection of the ray with the object. There is not stored the color. Color in another buffer.
Technically it can be implemented in very different ways. Nothing prevents you to store the depth in a separate channel of a four channel image.
And do I understand correctly that the depth is the z coordinate of the point to the camera from the point (0,0,z).

Not correct. for each pixel of the image depth is the distance (or squared distance) from the camera to nearest to the camera point of intersection of the ray from the camera through the pixel with some object. - delmer_Casper commented on April 19th 20 at 12:24
(moved back) - Gloria_Konopelski commented on April 19th 20 at 12:27
@Gloria_Konopelski:
just by the fact that there are no other options

Well, strictly speaking, there is. There are always options. Just the z-buffer is quite efficient and accurate solution. You can only use the painter's algorithm, but it will cause a chain of problems, which like dominoes avalanche will complicate the code or leave blemishes in the image. If everything consists of triangles, it is possible to accurately cross them solving the equation for finding the intersection of the planes and breaking up the triangles on the lines of intersection, to continue to work painter's algorithm. Here is the same problem as above. Breed new polygons, increasing the complexity of the code.
And that's not including semi-transparent textures, no shaders, no refractions, and other pieces. z-buffer is a concept, not a silver bullet. Real its use is part of a large and complex process of rendering the scene. - delmer_Casper commented on April 19th 20 at 12:30
@delmer_Casperabout like! ))
- thank you for the info the painter's Algorithm
z-buffer is a concept, not a silver bullet
and no one claimed )) .. it is a question of erudition in the subject, which, in turn, depends on demand on the passed prof path ))
..
Real its use is part of a large and complex process of rendering the scene
if neither of which I knew nothing about it, and would not be here ))
but once learned something else - I will remember, thank you! )) - Gloria_Konopelski commented on April 19th 20 at 12:33
@Gloria_Konopelski, Yes my answer even though you addressed, but actually meant the default.
And you for General knowledge, probably, will be interested to learn of such a thing as Ray Marching.
Is now repetitive and boring elegant and fascinating concept. Something more elegant even raytracing (with ratnasingam I, by the way, here's an example of not the short code from a very old experiments, sorry, I'm far from a frontend development=). - delmer_Casper commented on April 19th 20 at 12:36
@delmer_Casper, uh.. sensitive.. breaks between "where zanykat?" and "should I?".. ))
he was sick a long time 3D och )).. (I mean VERY long ))
and (apparently) as distant from frontend )))..

.. uh.. watch a movie.. but with the go - Mata (distances on the space of functions and their metrics) this is the "Mat.analysis" (or as it was called in my school ))) - Gloria_Konopelski commented on April 19th 20 at 12:39
@Gloria_Konopelski, well in fact everything is simple. I'm here about this
but with the go - Mata

If you do not go in the way he there draws fractals, the concept is simple as an axe:
Measure the distance from the camera to the surface of an object, move it the distance of the point along the ray through the pixel. And so the circle until you reach zero. - delmer_Casper commented on April 19th 20 at 12:42
@delmer_Casper,
If you do not go into that .. the concept is simple as an axe
it's so - Gloria_Konopelski commented on April 19th 20 at 12:45
April 19th 20 at 12:20
Usually for wood, use technology, billboard, i.e. flat rectangle that is rotated to face the camera. I.e., 100 trees, 100 squares, 200 triangles to draw - a piece of cake (textures themselves may not be very much, but every tree you can change the size and color).
Z-buffer is needed, if too lazy to sort objects by distance from camera. Sometimes even this cannot be done for overlapping volume bodies.
billboard For trees no longer applied. For the leaves, maybe, but not for trees. - eric97 commented on April 19th 20 at 12:23
April 19th 20 at 12:22
All modern games use the z-buffer. Including any GTA V.
And if you draw first near objects, then rendering is blocked z-buffer slice of the hardware to be clipped by the video card, and it is very fast. Fully drawn, they often will not.
Plus, the game will never be a situation with 99 polopoloonline trees on one line, except for z-buffer use and other technologies.
For example, thanks to LOD, the total number of polygons will be only very near objects, and the farther the object, the more low-poly version will be substituted instead. Instead of the most distant objects will generally be a flat image.
Thanks to the trees the visibility of the frame will get some of the objects that shouldn't be visible to the camera, they just will not be drawn, because the engine will understand that they are blocked from view.
etc...

There are ways to do without z-buffer. For example, for indoor use binary trees to draw walls in order from the near to the far.
Plus, for objects with transparency z-buffer to be used is generally impossible, we have to sort the faces and draw them in order from far to the middle, so that the transparency is correctly applied.
In short, the nuances of the car and small truck.

Suggest habré to read a series of posts "as rendered frame in the game n" https://habr.com/ru/company/ua-hosting/blog/271931/ there's quite a good show all the steps, including the z-buffer.
April 19th 20 at 12:24
@henri.Bergstr,
suppose there is a file, which is painted the vertices, edges, faces, textures for faces
good start..
I need from all of these objects to represent in a raster format. And store it..
with a hangover?
and when to draw, to take
and fill in array of z-buffer color
all that is built on the principles of z-buffer, first projects your model to the clipboard, and then harshly cuts off all at once (color, meth, and other crap) do not render. and only then, render things like a fragment of the rear wing of the Audi, which is visible from the corner of the house in the foreground

.. something like this

upd and here in this part, z-buffer taxis, taxied, and will steer

just by the fact that there are no other options

Find more questions by tags GraphicsAlgorithms3D