keywords:UE4, Lighting, 灯光, 光源距离裁剪, Volumetric Lightmaps

以下问题都是基于4.18,不排除后续新版本变动。

Fragments Notes

Static vs Stationary vs Moveable

In brief:

  • The main difference is that movable lights don’t produce GI!!
  • Static lights can’t change at all in gameplay.
  • Sationary can have small changes (like color)… Static lights are “free” (they are pre calculated maps), movable is the most “expensive”.

Static lights
Pros:

  • practically no limits; you can place as many as you want, they will not affect game performance- they will only affect light baking times, which is acceptable since that’s done during development
  • best lights to use for highest performance and frame rate of your game (so if you want 60 FPS online multiplayer, static lights are your friend)
  • very little to manage (i.e. no limit on cone angles overlapping, no stress about having too many of them casting shadows within player line of sight, etc.)
  • don’t need to worry about technical caveats, so a junior artist or lighter can go to town without a senior or lead having to worry about coming in a ripping the entire level’s light rig apart because there’s 1,000 dynamic lights in a hallway

Cons:

  • highest performance means lowest art quality; these are the worst quality lights you can use- BUT if you manage lightmap texel density well and have well laid out lightmap UV’s on static meshes, if CAN look really good)
  • baked shadow maps, so you don’t get the nice dynamic shadows from stationary or dynamic lights
  • since these are baked lights, you can’t change anything about them at run time (i.e. can’t change color, intensity, shadows, anything…)
  • this isn’t really a con to me, but I see a lot of people bring this up on the forums all the time: when working in UE4 editor, placing static lights doesn’t preview accurately to artists, so after you place them with the editor preview lighting and bake, you get completely different visual results. This isn’t a bug, but a limitation of the pipeline. Since static lights have to be prerendered before you can see what they look like in-game, the only way to get an accurate preview is to build your lighting all the time and see the results (while rendering at preview mode of course so it renders as fast as possible). However, as you place more and more static lights, your preview build times will slightly increase more and more. Once you’re really experienced at lighting in production with static lights (regardless of engine), you already know in your head how the lighting will most likely look when building your light rigs. Again, this is usually only a major con for new lighting artists or less experienced lighters.

Stationary Lights
Pros:

  • they look great because they cast dynamic shadow maps in the scene
  • they can be fitted with material functions and IES light profiles. these are special effects that can add a lot of artistic depth and realism to your scene
  • since they are dynamic, you can change their visual parameters at run time (i.e. you can change their color and intensity)
  • since they’re not solely dynamic, they can cast indirect illumination i.e. global illumination just like a static light, giving them the best of both worlds
  • cheaper to render than dully dynamic lights, making them better to use for performance

Cons:

  • can’t be moved at runtime like fully dynamic lights; you can’t move or rotate them!
  • hard limits; i.e. you can’t have more than 4 stationary lights overlap and touch the same mesh, if you do then the engine will automatically take the offending lights and convert them to fully dynamic lights- killing your performance!
  • lot more expensive to render than static lights
  • require more technical knowledge to use than static lights (inexperienced lighters may blow out a level’s performance by accident)

Dynamic lights
Pros:

  • fully dynamic lighting; meaning you can do anything at run time- move, rotate, change color, intensity, radius, etc. This makes them perfect for using as a player’s flashlight in a horror game, etc.
  • dynamic shadows
  • can use material functions, etc.
  • the preview you see in the editor is one to one with what the final lighting looks like, no need to bake and get different results like with static lights
  • not limited to 4 overlapping lights; place as many as you like if you’re planning on playing this on an IBM quantum super computer running 10x GTX 1080’s.

Cons:

  • most expensive lights to render in UE4; these will hurt performance and frame rate the most
  • again, easy for a junior lighter to accidentally kill performance by placing too many of these
  • no indirect lighting contribution, so you won’t get global illumination from these lights

Reference:
Difference between Static, Stationary, and Moveable skyights
Static or Stationary

LightMap

Volumetric Lightmaps: Volumetric lighting samples used for global illumination of dynamic objects and unbuild scene previews.
https://docs.unrealengine.com/4.26/en-US/RenderingAndGraphics/Lightmass/VolumetricLightmaps/

“Baked Lighting” and “Lightmaps” (Maya & Unreal Engine) (Recommended)
https://www.youtube.com/watch?v=-sJsR0y7R8U

Lightmap Creation for Unreal Engine 4 (unwrapping UV in 3ds Max) https://www.youtube.com/watch?v=joKnmShAdJE

Creating Custom and Auto-Generated Lightmaps | Live Training | Unreal Engine Livestream
https://www.youtube.com/watch?v=qZA_otJyZ1A

Lighting Channels

https://docs.unrealengine.com/en-us/Engine/Rendering/LightingAndShadows/LightingChannels

实际应用:
假设场景中只有一个平行光,且光照强度较大时,那么角色身上接收不到直接光照的部位(比如脖子),会明显发黑,如果增大 SkyBox 光照强度,那么会影响整个场景的亮度。有没办法只增加角色身上的光照亮度?让阴影区域变亮?解决办法是:Lighting Channels。
解决办法:
场景中添加两个平行光,A平行光的 Lighting Channels 只开启Channel 0,B平行光只开启Channel 1,然后角色的 Mesh 同时开启 Channel 0 和 Channel 1。

注意事项:

  • Lighting Channels是动态的,意思是:静态光(Static Lights)或者Mobility为Static的Static Mesh Actor不受Lighting Channels影响。要使用Lighting Channels,Static Mesh Actor和Lights的Mobility必须设置为Stationary或者Movable。
  • 材质类型影响:Lighting Channels只影响直接光照(direct lighting)下Opaque类型材质,Translucent或者Masked类型材质没有效果。
  • Lighting Channels对性能开销不大,可以忽略不计。

移动端的Lighting Channels:

  • 4.13版本开始,才支持移动端的Lighting Channel。
  • 移动端多个Directional Light支持不同Lighting Channels。
  • 一个Primitives只受一个Directional Light影响,如果primitves勾选了多个Lighting Channel,那么只会启用第一个。
  • CSM Shadows只会投射到与光源Lighting Channels相同的primitives上。
  • 动态点光源在移动端支持Lighting Channels的所有特性,与桌面级特性相同。

另外:Lighting Channels不支持运行时修改,就是说Lighting Channels在Actor创建时(比如BeginPlay)设置好以后,之后就无法再修改。

If Character is dark even give it dedicated Light Channel, the reason maybe is: there’re some objects casting shadows on the Character, you can disable Cast Shadow on these objects.

Occlusion Culling

Project Settings -》 Engine -》 Rendering -》 Culling -》 Min Screen Radius for Lights

Lights view distance
https://forums.unrealengine.com/unreal-engine/feedback-for-epic/54065-lights-view-distance

Ambient Occlusion

DFAO can be used with precomputed lighting, but SSAO can not. DFAO can save GPU cost but memory usage would increase.

Cheap Ambient Lighting System
https://forums.unrealengine.com/unreal-engine/marketplace/1511373-cheap-ambient-lighting-system

Ambient Occlusion quality command for mobile:
Engine\Source\Runtime\Renderer\Private\PostProcess\PostProcessAmbientOcclusionMobile.cpp

static TAutoConsoleVariable<int32> CVarMobileAmbientOcclusionQuality(
    TEXT("r.Mobile.AmbientOcclusionQuality"),
    1,
    TEXT("The quality of screen space ambient occlusion on mobile platform.\n")
    TEXT("0: Disabled.\n")
    TEXT("1: Low.(Default)\n")
    TEXT("2: Medium.\n")
    TEXT("3: High.\n"),
    ECVF_Scalability | ECVF_RenderThreadSafe
);
Screen Space Ambient Occlusion (SSAO)

Ambient Occlusion
https://docs.unrealengine.com/en-us/Engine/Rendering/LightingAndShadows/AmbientOcclusion

Distance Field Ambient Occlusion (DFAO)

How to enable DFAO

  1. Start by navigating to the Modes window, then in the Lights section, select and drag a Sky Light into the Level Viewport.
  2. With the Sky Light selected, navigate over to its Details panel and set its Mobility to Movable.
  3. Project Settings -> Engine -> Rendering -> Default Settings -> check Ambient Occlusion
    or
    Place a post process volume into your level, enable Unbound in it’s properties and then modify Intensity of AO intensity.
  4. Project Settings -> Engine -> Rendering -> Lighting -> check Generate Mesh Distance Fields

Distance Field Ambient Occlusion
https://docs.unrealengine.com/en-us/Engine/Rendering/LightingAndShadows/DistanceFieldAmbientOcclusion

Using Distance Field Ambient Occlusion
https://docs.unrealengine.com/en-US/Engine/Rendering/LightingAndShadows/MeshDistanceFields/HowTo/DFHT_2

Mesh Distance Fields
https://docs.unrealengine.com/en-US/Engine/Rendering/LightingAndShadows/MeshDistanceFields#EnablingDistanceFields

Screen Space Global Illumination (SSGI)

How to enable SSGI:
Project Settings > Engine > Rendering -> Lighting -> Check Screen Space Global Illumination.

An overview of dynamic global illumination using a screen space effect.
https://docs.unrealengine.com/en-US/Engine/Rendering/LightingAndShadows/ScreenSpaceGlobalIllumination/index.html

UE4 4.24 SSGI + AO Implementation
https://forums.unrealengine.com/development-discussion/rendering/1698726-ue4-4-24-ssgi-ao-implementation

Area Lights

Simulating Area Lights in UE4
https://www.unrealengine.com/en-US/blog/simulating-area-lights-in-ue4

Light Texture

LIGHT TEXTURE (UE4) Unreal Engine
https://www.youtube.com/watch?v=I1HsOtpBNpE

Reflections

Reflections (Part 1) Cube Map Reflections | Tips & Tricks | Unreal Engine
https://www.youtube.com/watch?v=AQ2jIgqLHPA

Reflections (Part 2) Planar Reflections & SSR | Tips & Tricks | Unreal Engine
https://www.youtube.com/watch?v=1Sx9qINRoIY

Light Map Compression

How to disable lightmaps compression:
Settings -> World Settings -> Lightmass -> Uncheck Compress Lightmaps.

Fragments Notes: Lighting on Mobile

Attentions on Mobile

1, Static and Stationary Spotlight support on Mobile, but Movable Spotlight not support on Mobile before v4.22;

2, Movable Pointlight support on Mobile always;

3, Testing in v4.21: Static and Stationary Point Light doesn't work on Android Vulkan without building lighting. Solution: Setting up your lighting in SM5, then building lighting, then switch to Android Vulkan, when start game, lighting would works right.

Reflection on Mobile

I did do some testing and was able to get the reflective environment to work on my end, but my results were not incredibly strong. Screen Space Reflections are unsupported on Mobile so that is expected no to work. You will want to make sure your ‘Skylight’ is set to ‘Static’ and ‘Cast Shadows’ is unchecked. Project Settings > Rendering > Mobile HDR is enabled. Then rebuild with Production quality lighting.

Reference:
https://answers.unrealengine.com/questions/387608/no-reflections-rendering-in-mobile-mode.html
https://answers.unrealengine.com/questions/381742/410-mobile-no-reflections-at-all.html

Lighting Issues

Fragments Issues

Issue 1:
Point Light intensity is very low event set Intensity to large value.
Solution:
Remove Point Light and add a new Point Light into scene and setting up it.

Issue 2:
There’re some strange block on lightmaps even building lighting again.
Solution:
Build -> Lighting Quality -> Production, then building lighting again. There’re some bug in Preview level of Lighting Quality.

Issue 3:
There’re some seams on the junction of two StaticMeshActor after lighting building.
Solution:
Rotating the StaticMesh 180 degrees, or up lightmap resolution to 128 rather than 64, or disable cascaded shadow maps and use either the Detail Lighting or Lighting Only view modes to see the baked result.

Issue 4:
There’re some strange gree block on meshes when Sky Light switch from Stationary to Movable (e.g. Turning DFAO on).

Solution:
Create a Level and enable Movable Sky Light at first, then copy meshes into the new Level.

Issue: shadows disappeared when the distance between Actor and Camera increased

This issue is affected by two factors:

  1. DirectionalLight’s perperty Dynamic Shadow Distance, if this value is less than the distance between Actor and Camera, shadows would disappeared.

  2. Engine’s parameter r.Shadow.RadiusThreshold,which means shadow visibility at camera distances, there’re two ways to change this parameter:

    • For Editor: Settings -> Engine Scalability Settings -> Shadow.
    • For Run-time: UKismetSystemLibrary::ExecuteConsoleCommand(GetWorld(), TEXT("r.Shadow.RadiusThreshold 0.06"));

参考:
https://answers.unrealengine.com/questions/707241/object-shadows-disappearing-too-early.html?sort=oldest

Troubleshooting Guide

LightingTroubleshootingGuide

Documents

Offical Documents

Lighting Content Examples
https://docs.unrealengine.com/en-us/Resources/ContentExamples/Lighting

Light Propagation Volumes
https://docs.unrealengine.com/en-us/Engine/Rendering/LightingAndShadows/LightPropagationVolumes

Lighting for Mobile Platforms
https://docs.unrealengine.com/en-us/Platforms/Mobile/Lighting

Blogs

Dynamic GI : Getting the Most out of LPV ( Light Propagation Volume )

Lighting Passes
https://unrealartoptimization.github.io/book/profiling/passes-lighting/

Unreal Engine 4 的 光和影
https://www.unrealengine.com/zh-CN/blog/chn-unreal-engine-4-light-and-shadow

[UE4] Let’s organize Light’s Mobility
https://qiita.com/EGJ-Nori_Shinoyama/items/caf3e83521b325770662

[UE4] Adjust Volumetric Lightmap by playing with lightmass.ini
https://qiita.com/EGJ-Nori_Shinoyama/items/ced1c91e2fd9de2c2ad4

[UE4] Create a lightmap for moving objects with Static Lighting
https://qiita.com/EGJ-Nori_Shinoyama/items/b9577608b4ac5a789c3e

Lighting Companion: Lightmass World Settings In UE4 (Recommended)
https://www.techarthub.com/lighting-companion-lightmass-world-settings-in-ue4/

Increasing frame rate using only lighting in Unreal Engine (Recommended)
https://dev.epicgames.com/community/learning/tutorials/DYVR/increasing-frame-rate-using-only-lighting-in-unreal-engine

Tutorials

Fragments Tutorials

Unreal 4: Lighting (Recommended)
https://i3dtutorials.gumroad.com/l/YjLxM

Tutorial | UE4 Lighting Overview
https://www.youtube.com/watch?v=kFaEf8V8XYY

Studying Lighting in Games
https://80.lv/articles/studying-lighting-in-games-2/

Lighting A Scene From Scratch - #19 Unreal Engine 4 Level Design Tutorial Series
https://www.youtube.com/watch?v=FsjqVIyr0O4

Create photoreal cinematics in UE4: Rebirth tutorial
https://www.youtube.com/watch?v=0iQJkSpOoOQ

How To Set Up A Realistic Post Process - UE4 Tutorial
https://www.youtube.com/watch?v=jYxgnSGybNU

Lighting with EMISSIVE Materials in UE4 - Unreal Engine Tutorial
https://www.youtube.com/watch?v=eVPuvCAEz4Q

UE4 Emissive Tutorial Example Files
https://gumroad.com/l/NrLQk

Lighting Detailed Interiors + Q&A [Unreal Engine 4]
https://www.youtube.com/watch?v=5t2nB75AdRA

80 Level Ratings: 10 Excellent Tutorials on Lighting in Unreal
https://80.lv/articles/80-level-ratings-10-excellent-tutorials-on-lighting-in-unreal/

Bake Lighting FASTER with GPU Lightmass - Unreal Engine 4.26
https://www.youtube.com/watch?v=hq1WFFF6iD0

Fog & Volumetric Tutorials

UE4 Lighting and Fog tutorial | ArtStation Challenge EP.006
https://www.youtube.com/watch?v=jsN0LBgrj14

Volumetric Fog and Lighting in Unreal Engine 4 | GDC 2018 | Unreal Engine
https://www.youtube.com/watch?v=Xd7-rTzfmCo

UE4 God Rays and Volumetric Fog Tutorial
https://www.youtube.com/watch?v=7w55FN2xBN0

Mix Volumetric Fog & Raytraced Shadows the RIGHT Way (Unreal Engine 4.26)
https://www.youtube.com/watch?v=UqMvd6UGBhE

Lighting Tricks

Hiding in Shadows (Stealth) - Unreal Engine 4 Tutorial
https://www.youtube.com/watch?v=th8feIg8BR4

[Unreal Engine 4] - Top 5 Light Tips And Tricks
https://www.youtube.com/watch?v=hlh7ncQQLlA

Exterior Lighting

How To Light Exteriors - Dynamic Lighting [Unreal Engine 4 Tutorial]
https://www.youtube.com/watch?v=58TxAz2Er0g

RTX GI

How To Improve Your Lighting w/ RTXGI
https://www.youtube.com/watch?v=hJohX8T5O-8


我只担心一件事,我怕我配不上自己所受的苦难。----陀思妥耶夫斯基