Volumetric fog что это
Volumetric Fog
В этой статье я опишу создание простейшего волюметрического тумана (Volumetric fog) с помощью программы Render Monkey от компании ATI.
Волюметрический туман – это туман, который может принимать любую форму, например, чайника. В принципе форма тумана зависит от формы используемого меша (Mesh). Этот туман можно использовать для различных эффектов, например, создание лайт шафтов (Light Shaft), создание облаков, призраков и др.
Немного теории.
Начнем с первой части шейдера, которая будет рендерить в текстуру глубину передних полигонов. Она будет выглядеть так:
В вертекстном шейдере нужно вернуть глубину трансформированной вершины. Для этого нужно координату Z разделить на большое число, чтобы получить число в пределах от 0 до 1. И передать ее как текстурную координату в пиксельный шейдер. Который в свою очередь просто возвращает ее в качестве цвета.
Второй шейдер идентичный первому, за исключением того, что обход вершин происходит против часовой стрелки, поэтому вычисляется глубина задних полигонов.
Если вы делаете эффект не в Render Monkey, то стейты нужно менять в проходах, вот так:
После того, как у нас готовы две текстуры с отрендеренеми в них глубинами меша необходимо найти толщину тумана. Для этого создаем третий проход.
Вертексный шейдер будет выглядеть вот так:
Немного о текстурных координатах. Здесь я установил координаты таким образом, чтобы туман растягивался по всей поверхности квадрата, на который выводится результат программы.
Как видно, это обычный вертексный шейдер, который возвращает позицию вершины и текстурные координаты. В пиксельном же шейдере находится разница полученных глубин и умножается на коэффициент туманности:
В итоге получается такого вида туман:
Volumetric Fog
An overview of the Volumetric Fog features available when using Exponential Height Fog.
With Unreal Engine, version 4.16, we now have support for Volumetric Fog. This method computes participating media density and lighting at every point in the camera frustum, so that we can support varying densities and any number of lights affecting the fog.
In this scene, Volumetric Fog is coming from the directional light source off screen through the arch and surrounding area to create shadowed fog.
Volumetric Fog Controls
When setting up and adjusting Volumetric Fog, you can control it globally or locally in your scene. The global controls enable you to use the Exponential Height Fog component to control fog for the the entire scene. The local controls enable you to control fog by way of a particle system in areas where the particles can spawn.
Global Controls
To control Volumetric Fog, you can adjust the properties in your Exponential Height Fog and on each Light to control the Light’s contribution amount.
Exponential Height Fog
Volumetric Fog controls can be found in the Exponential Height Fog component under the Volumetric Fog section. The exponential height distribution provides a global density for Volumetric Fog.
Scattering Distribution
This determines how directional the volumetric scattering is; a value of 0, means light scatters equally in all directions, while a value close to 1 causes scattering, predominantly in the direction of the light (you have to be looking at the light to see its scattering).
Albedo
This is the overall reflectiveness of the participating media. Clouds, fog, and mist, which are based on water particles, have an Albedo close to 1.
Extinction Scale
Controls how much the participating media blocks light.
View Distance
This is the distance from the camera over which Volumetric Fog will be computed. In the created volume texture for the fog there are a limited number of Z slices depending on this distance. Increasing the distance will result in under-sampling that can cause artifacts to appear. The number of Z slices can be adjusted by using r.VolumetricFog.GridSizeZ, where higher is better quality, but will be more expensive.
Override Light Colors with Fog Inscattering Colors
When enabled, uses the Fog Inscattering Color, Directional Inscattering Color, and Inscattering Texture properties to override the light color with Volumetric Fog.
Lights
Each Light’s contribution amount to the scene (and whether it shadows the fog) can be controlled by adjusting the following properties on each Light’s Details panel under the Light section.
Volumetric Scattering Intensity
Controls how much this light will contribute to the Volumetric Fog. When set to 0, there is no contribution.
Cast Volumetric Shadow
Toggles whether or not to cast a volumetric shadow for lights contributing to Volumetric Fog. When shadow casting is enabled, Point and Spot Lights are approximately three times more expensive because they contribute to the volume textures shadowing, where as non-shadow casting lights only contribute to the fog but do not shadow.
In this example, the Spot Light’s contribution to the Volumetric Fog has been disabled by setting the Volumetric Scattering Intensity to 0.
Local Controls
Materials using the Volume domain describe Albedo, Emissive, and Extinction for a given point in space. Albedo is in the range 1, while Emissive and Extinction are world space densities with any value greater than 0.
This is an example of the simplest Volume Material for a Particle System.
Volume materials currently only work on particles and positions inside of the particle radius will be valid, which is usually handled by a SphereMask.
Placing a single Particle System with the material causes a sphere of density to be added to the Volumetric Fog. The effect is fully three dimensional (3D) with no billboards involved.
Taking this approach a step further, you could use multiple spherical fog particles with noise from textures to limit fog to a certain area of your scene.
In this scene, the fog particles have populated these low-lying areas to create a localized fog effect that is shadowed using Voluemtric Fog.
Temporal Reprojection
The volume textures (voxels) used by Volumetric Fog are relatively low-resolution and aligned to the camera frustum. Volumetric Fog uses a heavy temporal reprojection filter with a different sub-voxel jitter per frame to smooth out the aliasing. As a side-effect, fast-changing lights, like flashlights and muzzle flashes, leave lighting trails. To disable the contribution of these lights, set Volumetric Scattering Intensity to 0.
Precomputed Lighting on Volumetric Fog
Volumetric Lightmaps support static lighting application for Volumetric fog by having each fog voxel interpolate precomputed lighting to its position in space.
Stationary Lights have their indirect lighting stored in lightmaps, which now affects fog.
Skylights are shadowed properly, preventing indoor areas from becoming over-fogged.
Static and Emissive for Static lights affect fog without costing anything since they’re all merged into the Volumetric Lightmap.
Performance
Particles using Volume domain can add a significant GPU cost, depending on their 3D overdraw and instruction count. Use the console command profilegpu to inspect this cost.
Point and Spot Lights that have Cast Volumetric Shadow enabled, cost approximately three times more than unshadowed Point and Spot Lights.
Currently Supported Features
This list comprises the currently supported features of Volumetric Fog:
A single Directional Light, with shadowing from Cascaded Shadow Maps or static shadowing, with a Light Function.
Any number of Point and Spot Lights, with dynamic or static shadowing (if Cast Volumetric Shadowing is enabled).
Shadowing of Stationary Sky Lights.
Precomputed Lighting through Volumetric Lightmaps (Direct Lighting of Static Lights, Indirect Lighting of Stationary Lights).
A single Skylight, with shadowing from Distance Field Ambient Occlusion (if enabled).
Particle Lights (if Volumetric Scattering Intensity is greater than 0).
Also, translucency is properly affected by Volumetric Fog, depending on its position in the scene. By default, translucency computes fog at vertices, so water planes with low tessellation can introduce artifacts. These materials can be set to compute fogging per-pixel to solve this with Compute Fog Per-Pixel enabled in the Material Details.
Known Issues
The following features are not yet supported while using Volumetric Fog:
IES profiles and Light Functions on Point and Spot Lights.
Shadowing from Ray Traced Distance Field Shadows.
Shadowing from Volumetric Fog (itself).
Source Radius on Point and Spot Lights.
Some settings in the Exponential Height Fog, like Fog Cutoff Distance, Start Distance, and Fog Max Opacity.
Common Questions
Below are some common questions or issues that may arise when using Volumetric Fog.
How can one achieve stronger light shafts without heavy global fog?
When the global density of fog is increased, you get denser fog, so you only notice light shafts (shadows of light) if the fog is dense enough to have everything heavily fogged. There are two ways to go about having stronger light shafts without heavy fog:
Keep the global fog density low, but use a higher Volumetric Scattering Intensity for the Directional Light. Also, adjust the Scattering Distritbution to nearly 0.9 in your Exponential Height Fog Actor.
Keep the global fog density low, but increase it in certain areas with Volume particles.
Can Exponential Height Fog and Volumetric Fog be used at the same time?
At this time, Volumetric Fog replaces Fog Inscattering Color within the Volumetric Fog View Distance. Because Volumetric Fog is physically-based and Exponetial Fog is not, it’s impossible to blend the two systems in the distance for them to precisely match. This also means that some settings in the Exponential Height Fog component will have no effect on Volumetric Fog.
Can the Volumetric Fog’s center be decoupled from the camera? This would be ideal for top-down games.
Not currently, though, a standalone volume would be ideal for this. However, it’s hard to integrate them with translucency efficiently.
Training Stream
Объемный туман
Обзор возможностей Volumetric Fog доступных когда используется Exponential Height Fog.
Регуляторы для Volumetric Fog
Глобальный контроль
Exponential Height Fog
Scattering Distribution
Albedo
Extinction Scale
View Distance
Override Light Colors with Fog Inscattering Colors
Когда это включено, для определения цвета освещения с помощью Volumetric Fog используется Fog Inscattering Color, Directional Inscattering Color и Inscattering Texture.
Lights
Volumetric Scattering Intensity
Cast Volumetric Shadow
Локальные элементы управления
Это пример простейшего Volume Material для системы частиц.
Volume materials currently only work on particles and positions inside of the particle radius will be valid, which is usually handled by a SphereMask.
Временное репроектирование
Предварительное вычисление света на Volumetric Fog
У Stationary Lights есть их косвенное освещение, хранящееся в световых картах, которые теперь влияют на туман.
Производительность
Поддерживаемые функции
Этот список содержит поддерживаемые в настоящее время функции Volumetric Fog :
Известные трудности
Следующие функции пока не поддерживаются при использовании Volumetric Fog :
Общие вопросы
Как можно добиться более сильных световых валов без тяжелого глобального тумана?
Когда глобальная плотность тумана увеличивается, вы получаете более плотный туман, поэтому вы видите только светлые валы (тени света), если туман достаточно плотный, чтобы все сильно затуманилось. Есть два способа добиться более сильных световых валов без сильного тумана :
Можно ли одновременно использовать Exponential Height Fog и Volumetric Fog?
Учебные стримы
Volumetric Fog
An overview of the Volumetric Fog features available when using Exponential Height Fog.
With Unreal Engine, version 4.16, we now have support for Volumetric Fog. This method computes participating media density and lighting at every point in the camera frustum, so that we can support varying densities and any number of lights affecting the fog.
In this scene, Volumetric Fog is coming from the directional light source off screen through the arch and surrounding area to create shadowed fog.
Volumetric Fog Controls
When setting up and adjusting Volumetric Fog, you can control it globally or locally in your scene. The global controls enable you to use the Exponential Height Fog component to control fog for the the entire scene. The local controls enable you to control fog by way of a particle system in areas where the particles can spawn.
Global Controls
To control Volumetric Fog, you can adjust the properties in your Exponential Height Fog and on each Light to control the Light’s contribution amount.
Exponential Height Fog
Volumetric Fog controls can be found in the Exponential Height Fog component under the Volumetric Fog section. The exponential height distribution provides a global density for Volumetric Fog.
Scattering Distribution
This determines how directional the volumetric scattering is; a value of 0, means light scatters equally in all directions, while a value close to 1 causes scattering, predominantly in the direction of the light (you have to be looking at the light to see its scattering).
Albedo
This is the overall reflectiveness of the participating media. Clouds, fog, and mist, which are based on water particles, have an Albedo close to 1.
Extinction Scale
Controls how much the participating media blocks light.
View Distance
This is the distance from the camera over which Volumetric Fog will be computed. In the created volume texture for the fog there are a limited number of Z slices depending on this distance. Increasing the distance will result in under-sampling that can cause artifacts to appear. The number of Z slices can be adjusted by using r.VolumetricFog.GridSizeZ, where higher is better quality, but will be more expensive.
Override Light Colors with Fog Inscattering Colors
When enabled, uses the Fog Inscattering Color, Directional Inscattering Color, and Inscattering Texture properties to override the light color with Volumetric Fog.
Lights
Each Light’s contribution amount to the scene (and whether it shadows the fog) can be controlled by adjusting the following properties on each Light’s Details panel under the Light section.
Volumetric Scattering Intensity
Controls how much this light will contribute to the Volumetric Fog. When set to 0, there is no contribution.
Cast Volumetric Shadow
Toggles whether or not to cast a volumetric shadow for lights contributing to Volumetric Fog. When shadow casting is enabled, Point and Spot Lights are approximately three times more expensive because they contribute to the volume textures shadowing, where as non-shadow casting lights only contribute to the fog but do not shadow.
In this example, the Spot Light’s contribution to the Volumetric Fog has been disabled by setting the Volumetric Scattering Intensity to 0.
Local Controls
Materials using the Volume domain describe Albedo, Emissive, and Extinction for a given point in space. Albedo is in the range 1, while Emissive and Extinction are world space densities with any value greater than 0.
This is an example of the simplest Volume Material for a Particle System.
Volume materials currently only work on particles and positions inside of the particle radius will be valid, which is usually handled by a SphereMask.
Placing a single Particle System with the material causes a sphere of density to be added to the Volumetric Fog. The effect is fully three dimensional (3D) with no billboards involved.
Taking this approach a step further, you could use multiple spherical fog particles with noise from textures to limit fog to a certain area of your scene.
In this scene, the fog particles have populated these low-lying areas to create a localized fog effect that is shadowed using Voluemtric Fog.
Temporal Reprojection
The volume textures (voxels) used by Volumetric Fog are relatively low-resolution and aligned to the camera frustum. Volumetric Fog uses a heavy temporal reprojection filter with a different sub-voxel jitter per frame to smooth out the aliasing. As a side-effect, fast-changing lights, like flashlights and muzzle flashes, leave lighting trails. To disable the contribution of these lights, set Volumetric Scattering Intensity to 0.
Precomputed Lighting on Volumetric Fog
Volumetric Lightmaps support static lighting application for Volumetric fog by having each fog voxel interpolate precomputed lighting to its position in space.
Stationary Lights have their indirect lighting stored in lightmaps, which now affects fog.
Skylights are shadowed properly, preventing indoor areas from becoming over-fogged.
Static and Emissive for Static lights affect fog without costing anything since they’re all merged into the Volumetric Lightmap.
Performance
Particles using Volume domain can add a significant GPU cost, depending on their 3D overdraw and instruction count. Use the console command profilegpu to inspect this cost.
Point and Spot Lights that have Cast Volumetric Shadow enabled, cost approximately three times more than unshadowed Point and Spot Lights.
Currently Supported Features
This list comprises the currently supported features of Volumetric Fog:
A single Directional Light, with shadowing from Cascaded Shadow Maps or static shadowing, with a Light Function.
Any number of Point and Spot Lights, with dynamic or static shadowing (if Cast Volumetric Shadowing is enabled).
Shadowing of Stationary Sky Lights.
Precomputed Lighting through Volumetric Lightmaps (Direct Lighting of Static Lights, Indirect Lighting of Stationary Lights).
A single Skylight, with shadowing from Distance Field Ambient Occlusion (if enabled).
Particle Lights (if Volumetric Scattering Intensity is greater than 0).
Also, translucency is properly affected by Volumetric Fog, depending on its position in the scene. By default, translucency computes fog at vertices, so water planes with low tessellation can introduce artifacts. These materials can be set to compute fogging per-pixel to solve this with Compute Fog Per-Pixel enabled in the Material Details.
Known Issues
The following features are not yet supported while using Volumetric Fog:
IES profiles and Light Functions on Point and Spot Lights.
Shadowing from Ray Traced Distance Field Shadows.
Shadowing from Volumetric Fog (itself).
Source Radius on Point and Spot Lights.
Some settings in the Exponential Height Fog, like Fog Cutoff Distance, Start Distance, and Fog Max Opacity.
Common Questions
Below are some common questions or issues that may arise when using Volumetric Fog.
How can one achieve stronger light shafts without heavy global fog?
When the global density of fog is increased, you get denser fog, so you only notice light shafts (shadows of light) if the fog is dense enough to have everything heavily fogged. There are two ways to go about having stronger light shafts without heavy fog:
Keep the global fog density low, but use a higher Volumetric Scattering Intensity for the Directional Light. Also, adjust the Scattering Distritbution to nearly 0.9 in your Exponential Height Fog Actor.
Keep the global fog density low, but increase it in certain areas with Volume particles.
Can Exponential Height Fog and Volumetric Fog be used at the same time?
At this time, Volumetric Fog replaces Fog Inscattering Color within the Volumetric Fog View Distance. Because Volumetric Fog is physically-based and Exponetial Fog is not, it’s impossible to blend the two systems in the distance for them to precisely match. This also means that some settings in the Exponential Height Fog component will have no effect on Volumetric Fog.
Can the Volumetric Fog’s center be decoupled from the camera? This would be ideal for top-down games.
Not currently, though, a standalone volume would be ideal for this. However, it’s hard to integrate them with translucency efficiently.