Deus Ex – Alpha Terrain

Three years in the past, whereas enjoying Deus Ex: Mankind Divided, I seen a pleasant little trick and tweeted about it – in the present day is the day once I lastly launch it as an article. Do you guess, what’s this about?
Right reply: The terrain blends properly with the stone! Let me clarify it in additional element: Often when objects and terrain intersect with each-other, one can see a harsh intersection. In Deus Ex alternatively, there’s a pleasant clean transition between terrain and object:
Now, mixing objects with the terrain is not a spectacular new concept. An inventory:
- I personally described a enjoyable method for bushes in Torchlight [Link]
- There’s an incredible method to mix the colours and even normals of the terrain with the mesh (recognized from Battlefront 2) [Link]
- TigSource Thread about Terrain Blending in Zelda: BotW & Farcry 5 [Link]
- Terrain mixing with Unreal Realtime Digital Texturing (RVT) [Link]
- There’s this enjoyable experiment to make use of Pixel Depth Offset & Dithering to mix terrain and object [Link]
What I like in regards to the Deus Ex strategy: it’s a easy hack (and you recognize me, I LOVE methods like that!).
Let’s have a look at some examples, and possibly you possibly can guess already what’s occurring right here:
The terrain makes use of a translucent materials!
As such, it may possibly make use of a easy depth fade (the nearer a pixel is to an opaque floor, the extra clear it will get) it may possibly now mix easily with the (opaque) objects.
As a substitute of doing a easy depth fade, EmilMeiton describes an improved method: “utilizing the depth buffer “uncooked” to mix my objects works, however the result’s closely depending on the angle of the digicam to the bottom. […] I spotted we may merely reverse this impact by calculating the tangent of the angle between the terrain regular and the view path (digicam vector) and use this to divide the sooner used distance (between terrain and object beneath). It’s not excellent however it’s manner higher than the consequence earlier than,”
Enable me to say a number of phrases why seeing a translucent materials shocked me:
- Overdraw. We all the time hear: Watch out with overdraw! Keep away from enormous particles!! It kills your efficiency!!!!111 So, seeing a terrain (which fills not less than half the display screen more often than not) utilizing a translucent materials appeared counterintuitive to me.
- Sorting. Translucent objects normally have sorting points. Within the video under, you possibly can see these within the type of polygons being seen by means of different polygons in entrance:
Notice: Unreal simply added Order Independent Translucency, and this may be a recreation changer!
The rationale why all of this was a shock to me was, that normally terrain rendering works like proven under.
As you possibly can see, the terrain is opaque and drawn very early. This is sensible as a result of now you don’t must render something which is hidden behind the already rendered pixels. Adrian ship me one other example of Metal Gear Solid V the place they render the terrain first to keep away from rendering something behind it – this benefit could be misplaced within the case of Deus Ex the place the terrain is rendered final.
After I noticed the Deus Ex strategy the primary time, I requested on Twitter and Ben Golus answered and defined a bit here and here (simply in case you need extra particulars).
Let’s now check out the talked about issues (overdraw & sorting):
Right here’s my guess why overdraw is not an enormous downside on this case:
It’s solely one layer. Often when artists get warned about overdraw, it’s to keep away from that too many translucent layers overlap one another in order that 1 pixel is touched 50x throughout rendering as a result of 50 particles cowl its space.
It helps, that the terrain could be very flat in order that we by no means see it overlapping itself (one thing like my sorting-example from above, the place the hills overlap one another, by no means happens in Deus Ex):
Only one sentence above I wrote, that the sorting in Deus Ex shouldn’t be an issue due to the flatness of the terrain. Nonetheless, I’d like to point out you the rendering course of in Deus Ex and present an instance how potential sorting points might be solved (e.g. if the terrain has overlapping hills).
Like normally in real-time rendering, all opaque objects come first. Often the terrain is a part of that (see GTA V instance above), however not a lot in Deus Ex! There are some patches of orange sand, however these shall be occluded quickly:
Now, the terrain is drawn on prime. It has a translucent materials which permits for the graceful mix with the opaque geometry. Notice that it additionally will get rendered into the depth buffer! That is particular! Often that is not the case for translucent objects (more details here) however right here it’s OK as a result of we all know, that nothing must be rendered behind the terrain pixels.
The subsequent steps could be shadows, lighting, different translucent parts like particles and naturally the UI. However these issues should not attention-grabbing for us proper now.
I’d like to emphasise how vital it’s, that the (translucent) terrain will get written into the depth buffer as a result of it serves two functions:
1. Avoiding sorting points. By evaluating newly drawn pixels to the already current depth data, we will discard these pixels, that are behind already rendered ones:
I made a tutorial how to set up the example above to avoid sorting issues.
As talked about earlier than: My instance could be very mountainous, however the terrain in Deus Ex is sort of flat! So in idea, on this particular case, rendering the (translucent) terrain into the depth buffer wouldn’t have been crucial since there aren’t any sorting points to be anticipated. However we will use the depth data for one thing else:
2. Depth Fade for particles. Within the instance under, you possibly can see, typical sorting points (left), a “repair” by forcing the particle to be drawn on prime (middle) and the nicest manner of getting the particle “reacting” to the terrain by doing a pleasant depth fade (proper):
Once more: Doing such a depth fade could be very regular after we’re speaking a few particle being near an opaque object as a result of they all the time render into the depth buffer whereas translucent object like our terrain normally don’t!
And right here you possibly can see it in motion within the recreation. The mud impact has a delicate transition with the terrain:
Zelda: BotW makes use of an identical method, and here’s a thread where flogelz re-creates the terrain blending. They don’t use a translucent materials for the terrain however mix all the things within the GBuffer, however the render order is identical: First all the things else, then the terrain.
Deus Ex makes use of a pleasant hack to mix terrain and objects. Three issues are particular about its terrain rendering:
- The terrain renders after all opaque objects
- The terrain makes use of a translucent materials
- The terrain renders into the depth buffer (normally solely opaque objects do)
This stuff are achieved to:
- Keep away from sorting points
- Mix terrain softly with objects
- Mix different translucent parts like particles softly with the (translucent) terrain
Ensuing issues might be:
- Probably waste of rendering opaque objects as a result of they’re utterly occluded by the terrain (not the case in Deus Ex)
- When wanting carefully, the hack is sort of seen because it will depend on the angle between of digicam and terrain
I hope you preferred the article and be happy to go away a remark!
Simon ♥