Basic articles | Ray tracing 01 | Techniques and optimization of ray tracing in UE

1. What is ray tracing

  • basic concept

    • Each pixel of the screen sends a ray to the scene. After colliding with the scene object, it will display different colors, and then adjust the color performance of the pixel accordingly.

    • BVH algorithm greatly enhances the efficiency of light tracing; (detection of collision triangle → detection of collision model bounding box)

  • The difference between ray tracing and rasterization

light chasing rasterization
Start with pixels and rays; Start with objects and triangles;
Rendering is slow, but realistic; Render blocks, but not realistic enough;
Real physical lighting; Use some tricks to simulate light behavior;
Easy to open; Requires some development attempts to achieve real results;

2. Hybrid rendering

  • basic concept

    • Because ray tracing is expensive, we use ray tracing where we need it.
  • application

    • Diffuse light: we will use rasterization to achieve;

    • Reflection: Reflections on blurred surfaces use rasterization, and reflections on smooth surfaces use light tracing;

    • Ambient Occlusion (AO): Choose SSAO or Light Tracing depending on the situation;

    • Shadow: The shadow selection of the core light uses light tracing;

    • Global Light (GI): The consumption is very high, when using it, consider turning off other light tracing;

      insert image description here

3. The use of ray tracing

1) Scene basic settings

  • project settings

    • Turn on light tracing and texture LOD;

      insert image description here

    • The platform is set to DirectX 12;

      insert image description here

  • Restart the engine after the setting is successful

    • You will see that the graphics calculation has been switched to DirectX 12 in the upper right corner;

      insert image description here

    • In the display, there is an extra column for ray chasing Dug;

      insert image description here

2) Ambient Occlusion - AO

  • concept

    • An algorithm to calculate whether ambient light is blocked by surrounding objects;
  • two options

    • Light chase AO

      • When the screen ray collides with the model surface, the real occlusion relationship can be calculated;
    • Rasterized AO: SSAO

      • Based on the ready-made depth data, the operation is fast;

      • The biggest disadvantage is that it is impossible to distinguish between the foreground and the background. When the object is occluded, the background object will be removed, and this part of the AO will be ignored;

        insert image description here

  • AO opening and setting

    • When the red frame is enabled, use ray tracing AO. When not enabled, use SSAO;

    • Pixel-by-pixel is the accuracy of AO; radius is the length of the light tracing ray; both values ​​directly affect performance;

      insert image description here

3) Reflection

  • three options

    • light reflection

      • The rougher the surface, the larger the reflective horn and the greater the consumption;

        insert image description here

    • Screen Space Reflection: Post-processing of images

      • Objects outside the screen cannot be recognized, so the borders of the screen and some special places will be distorted;

      • The reflection distance will also be affected by the screen distance, which has a large limitation;

    • reflection probe

      • Environment capture or HDR textures;

      insert image description here

      insert image description here

  • Turning on and setting reflection

    • Select type in reflection;

    • Maximum roughness: SSR is used for surfaces exceeding the value. This threshold has a great impact on performance, and the recommended value is 0.2;

    • Maximum number of bounces: Reflected reflections, the more times, the greater the performance consumption;

    • Pixel-by-pixel: control accuracy and affect performance;

    • Shadow settings and semi-transparent object settings also affect performance and can be turned on as needed;

      insert image description here

4) Shadow-Shadow

  • two options

    • Light chasing shadow: it will match the radius of the light source, and a real virtual shadow will appear;

      insert image description here

    • Rasterized shadows: using waterfall shadow maps (Shadow map)

      insert image description here

  • Turn on and set

    • Turn on light tracing shadows for the main light source

      insert image description here

    • Sampling accuracy of light tracing shadows
      insert image description here

5) Global Light - GI

  • two options

    • Light Chasing GI: Environmental objects scatter real secondary light;

      insert image description here

    • Rasterization GI: use construction + light map method;

  • Turn on and set

    • Choose whether to enable it in the type;

    • The number of bounces and pixel-by-pixel have a great impact on the accuracy;

      insert image description here

6) Translucent-Translucent

  • two options

    • Light chasing translucency: produce real reflection and refraction;

      insert image description here

    • Rasterized translucency: used with SSR or reflection probes;

  • Turn on and set

    • When the scene has no transmission, choose rasterization, which can save a few frames of performance

      insert image description here

  • Translucent Material

    • When using rasterization, there are usually sorted textures, it is best to turn off double sided;

      insert image description here

    • Calculation of the refractive index (approximate value): from air to glass, the refractive index of the two is divided;

      insert image description here

    • Material instance

      insert image description here

4. Performance optimization

1) Material optimization

  • Principle: When ray tracing, turn off some material calculations in reflection to increase running performance;

  • Core node: RayTracingQualitySwitchReplace

    • Normal: the data called by the shader during normal rendering;

    • RayTraced: the data called by the shader in light tracing reflection;

      insert image description here

      insert image description here

2) Global instruction optimization

  • 指令1:r.RayTracing.Reflections.TestPathRoughness 1

    • Principle: The reflectance threshold of the light-tracking test, when the threshold is 1, the test uses SSR;

      insert image description here

  • Command 2: r.RayTracing.Reflections.MaxRayDistance 100

    • Principle: The farthest distance of the ray, the default is -1 (infinity). When lowered, the performance improves, and the reflection will be incomplete;

      insert image description here

  • 指令3:r.RayTracing.Reflections.ScreenPercentage 50

    • Principle: Set the resolution percentage of the reflection. When it is lowered, the performance is improved, and the reflection will cause jitter;

      insert image description here

  • Command 4: r.RayTracing.Reflections.Hybrid 1

    • Principle: Turn on the reflection hybrid algorithm. When it is turned on, the performance is improved, and SSR will be used instead of light tracing reflection at the beginning of the second reflection;

      insert image description here

  • 指令5:r.RayTracing.Reflections.ReflectionCaptures 1

    • Principle: Probe reflection is superimposed on the basis of light tracing reflection. When turned on, all reflections can be set to 1 time, and the dark areas with more than 2 times will be replaced by probe reflections.

      insert image description here

      insert image description here

3) Global light GI optimization

  • Mode changed from "Brute Force" to "Final Gathering"

    insert image description here

  • Reduced sampling accuracy of skylight

    insert image description here

  • 指令:r.RayTracing.GlobalIllumination.NextEventEstimationSamples 1

    • Principle: The number of samples is reduced
      insert image description here

4) GPU viewer-visualizer

  • Shortcut key: Ctrl+Shift+

  • official page

  • Interface and Operation

    insert image description here

  • When clicked, the consumption of this block will be located

    insert image description here

Guess you like

Origin blog.csdn.net/u011637323/article/details/125849257