What is the difference between forward and deferred rendering?

If you are a game developer, you have heard about forward rendering and deferred rendering more or less in the graphics engine you use. Usually you have to choose one of your games. But what are they, what are the differences between them, and how should we choose?

Modern Graphics Pipelines

Before we start, we must know a little about modern programmable graphics pipelines. Earlier, we were limited by the function of the graphics card. We couldn't change the way each pixel was drawn. In addition to sending some different textures, we could not modify the data of the vertices. Now that the times have changed, we can program based on the graphics pipeline of the graphics card. We can send code to the graphics card to change the appearance (color) of the pixels, use normal maps to change their appearance to make them appear, or add reflections (and a lot of realism).

This code takes the form of geometry, vertex and fragment shaders, essentially controlling how the graphics card renders the object.

Simplified view of a programmable graphics pipeline

Forward Rendering (forward rendering / forward rendering)

Forward Rendering is the rendering technique used by most rendering engines. You provide the geometry object to the graphics card, which breaks the geometry into vertex shaders, then interpolates the vertex data into the fragment/pixel shader, and then performs the final rendering before they are sent to the screen. (template testing, mixing, etc.).

Forward rendering: geometry shader to vertex shader to split shader

This is a linear process where each geometry object is processed step by step through the rendering pipeline and produces the final image.

Deferred Rendering

Deferred rendering, by this name, means that the rendering is delayed until all geometry objects have been processed through the rendering pipeline, and finally the shading is applied (by lighting to determine the final pixel color) and the final image is produced.

So why do you want to deal with this?

Deferred rendering: geometry to vertex to fragment shader. Pass to multiple render targets and then shade with light.

Delayed illumination is a modification of deferred rendering by reducing the size of the G buffer by using more passes in the scene.

Lighting Performance

The performance of standard forward rendering lighting is also the main reason why you should choose another rendering method. In the standard Forward Rendering pipeline flow, each light performs a lighting calculation on each vertex/slice, which is often referred to as per-vertex lighting and per-chip/pixel lighting.

If you have 100 geometric objects in the scene, and each geometric object has 1000 vertices, you have about 100,000 deformations (very rough calculations). Graphics cards can also be handled very easily, but when these polygons are sent to the fragment shader, expensive lighting consumption can drastically degrade performance. Developers can try to place lighting calculations into vertex shaders to reduce the calculation of lighting by the fragment shader.

Whether it is the topmost tile on this pixel or the occluded tile, expensive lighting calculations are performed on each visible tile of each polygon. If the resolution of the screen is 1024x768, you have nearly 800,000 pixels that need to be rendered. You can easily achieve a million-level chip operations per frame. And most of the chips will be rejected (deep testing phase), then the lighting for this film is in vain.

If you want to render every light of such a scene that reaches a million-level movie, then you will jump on the number of lights in each frame by x1000000 pieces! Imagine you have a small town with a light source on the street! ! ! ! !

For the formula for calculating the forward rendering complexity, see: big O notatio, complexity formula: O(num_geometry_fragments * num_lights). You can see that the complexity here is directly related to the number of geometric objects and the number of lights.

A tile is a "pending pixel" that may eventually become a pixel on the screen. If it is not culled during the depth test phase, it will become the final pixel of the screen on the screen. Some engines now optimize lighting calculations in other ways, such as removing very far lights, combining lights or using Light maps (very popular, but only static objects). If you have a lot of lighting that requires dynamic lighting, we need a better solution.

Deferred Rendering to the Rescue (forward rendering of the savior – delayed rendering)

Deferred Rendering is an interesting way to reduce the number of light-colored objects. Especially for the total fragment object, the number of slices that perform illumination is directly determined by the resolution of the screen.

The complexity of Deferred Rendering is O(screen_resolution * num_lights) in big O notation.

Now you can understand how much light you have is determined by your use of the number of lights. So you can be happy to increase the amount of your lights. (This doesn't mean you can have unlimited geometric objects, they still have to go through the pipeline and other processing to get to the G-Buffer.)

The Guts of Deferred Rendering

Each geometry object is rendered, but without the use of lighting, multiple render targets are used to draw Buffers of multiple screen space sizes. The depth, normal and color are written to the respective buffers (images). These Buffers are then combined with the prime color of each light image to produce the final image.

Color, depth and normal buffer. (Image by astrofa, via Wikimedia Commons.)

The final illumination (shadow) uses three buffers to generate the result. (Image by astrofa, via Wikimedia Commons.)

Which one to choose?

One of the shortest answers is: If you use a lot of lights then you should use Deferred Rendering. But Deferred Rendering also has some obvious drawbacks:

• This process requires the graphics card to support multi-target rendering. The old graphics card is not supported. All can't work on it. There is no workaround for this, unless the customer service is forced to change the video card.

• It requires a high-bandwidth graphics card. You have to send large Buffer data, and the boss's graphics card may not be able to handle it. For this, there is no workaround, unless the customer service is forced to change the video card.

• You cannot use transparent objects. (unless you use deferred rendering and Forward Rendering together).

• No anti-aliasing.

• Only one type of material is allowed unless you use a delayed rendering modification called Deferred Lighting.

• Shadows depend on the amount of lighting, and delayed rendering does not solve any shadow problems.

If you don't have a lot of lights or you want to be able to allow them on older graphics cards, you should choose to use Forward Rendering and replace your lights with static lightmaps. This result still looks surprising.

to sum up

I hope to get rid of some of the lighting themes. Your choice here is to solve the rendering problem, but it is very important to make the right choice before the game starts, because you can avoid future modifications.

Coaxial Cable

Rf Coaxial Cable,Digital Coaxial Cable,Coaxial Cable For Internet,Coaxial Cable Types

Zhejiang Wanma Tianyi Communication Wire & Cable Co., Ltd. , https://www.zjwmty.com