Hello! I would like to take advantage of Unreal Engine’s deferred lighting systems and achieve some light rays, but the thing is that it is only available for the sun in the level. Does anyone know how such thing can be achieved? A great example of what I mean is in the game Viscera Cleanup Detail.
Correct me if I’m wrong, but I believe volumetric lighting (the effect you’re describing) is actually harder to do thanks to deferred lighting, not easier, as per what you’re implying? Deferred lighting is a more efficient way of calculating lighting in terms of surfaces for lots of lights, though you lose a lot of the access to lighting information in deferred lighting when it comes to materials and shaders outside of the lighting passes.
Volumetric lighting, or calculating lighting volumetrically and using that to calculate light shafts within 3D space, is unfortunately something that Unreal Engine 4 doesn’t do well, the current methods are mostly screen-space methods and are limited to directional lights (IIRC I did hear that the code in theory could work for point lights, but it’s just got some major bugs which means point light support isn’t good). The light either has to be on-screen (for the bloom method) or there needs to be depth information near the light source (for the occlusion method, in other words the light needs to be practically on-screen as well though it has a larger “range” than the bloom method). The bloom method is physically inaccurate but highly controllable, whereas the occlusion method is physically accurate but you have less control over it and it’s more of a subtle effect rather than the blatantly obvious bloom method, unless you drop in either an atmospheric fog actor or an exponential height fog actor.
Currently you have four options that I know of if you must have volumetric lighting. The first is to fake the effect by having a mesh with a transparent emissive material applied, you can use a cone with the top cut off to add shafts of light coming from spotlights, this is the easiest and least costly of the three, however it is static: the shaft cannot move unless you want to get into some scripting to move and rotate the mesh as say the sun moves in the sky. The second is to use translucent particles to locally apply volumetric lighting. A particle system with a small number of large, translucent particles with a sphere mask and a cloud texture blended together (you can get the cloud texture from Photoshop) can make a terrific volume of fog, this has a decent quality but can be quite costly thanks to overdraw (one of the problems with deferred lighting): more particles means a denser volume, but it also means a lot more overdraw. The third is to use very small GPU particles using two-sided foliage lighting to act as little specks of dust to give the feeling of lighting being volumetric: I used this for some simple snow and got ~130k particles with next to no hit on performance, over a large area. This is a great method for giving the feeling of volumetric lighting without the hit of volumetric lighting. The fourth is to take a look at this other thread for how they faked it. This is basically the second method but following the player: it’s a “visor”-esque mesh with a translucent material applied and some careful tweaking of the material graph can get some nice shafts. This IMO looks the nicest if you can get it right, but it can be very costly and can drive shader complexity into the 50%+ range if you’re not careful.
Getting light shafts / light rays is a few click challenge.
Set a directional light and atmospheric fog into your scene.
In Directional Light settings mark Light Shafts and adjust settings to your liking.
In atmospheric fog there will be an option saying Use Sun as… something. Sorry I don’t recall, but this removes the light shafts coming only from the Sun. That’s all, to adjust Sun’s height, rotate directional light, or atmospheric fog, can’t remember.
Hey there, you can actually use my system with a more subdivided mesh and the new per-vertex directional translucency shader model in 4.11 and the performance is pretty decent. I’m working on an update to my system to take better advantage of this model and hopefully yield better quality and better performance.
Ah, nice, completely forgot about that shading model!