We picked up all hobbies this year. And although I’m sure my life has been enriched by running marathons The crown Matthew Wilde had astral projections from my body on the weekends and had a somewhat more extensive lockdown project: he made drunk bottle shaders for Half-life: Alyx.
The shaders were added to the game in a May patchand they started right away Getting love on the internet. It’s easy to see why: you look really, really good. The shader makes bottles appear transparent, with liquid that reacts when the bottle is shaken. Before the patch, the bottles made a sloshing sound when shaken, but otherwise looked opaque.
I wanted to find out how the shader worked and there was no better person than Wilde.
I spent a fair amount of lock-down on this important work. Boozy Liquid Shader, now available in the latest update for Half-Life: Alyx pic.twitter.com/Iw9h98pmEg
– Matthew Wilde (@skilful) May 28, 2020
Wilde is a VFX developer who worked at Valve when Alyx was in development – but further Dota Underlords. He made a wine glass shader for the Dota character Jull, which caught Scott Dalton’s attention on the Half a life: Alyx Team. There are lots of bottles in AlyxHowever, a certain level takes place in a distillery and requires the player to interact with bottles a lot of.
Developing a shader that would make the bottles look full of liquid would make the level even more impressive. And Wilde wouldn’t be starting from scratch either: the game was basically done, with detailed assets and a powerful lighting system.
“All of the bottles existed as models, and they were all beautifully textured and they look great,” said Wilde. “And so we could immediately see that it was really promising.”
But with AlyxWith the release date looming, there was simply no time to implement the new shader without causing performance issues.
“If there was only an occasional bottle … it probably wouldn’t have been a problem,” Wilde said to me. “But it was that distillery again that had thousands of props and thousands of bottles.”
The shader was postponed for release, and although Wilde was disappointed, he accepted it. Half-life: Alyx came out on March 23, 2020. The same day, Jay Inslee, the governor of Washington state, an order issued for a stay at home that would close Valve’s Bellevue offices.
“And so we suddenly had time,” said Wilde. “Lockdown gave us the opportunity to look back at things we hadn’t done before.”
Make the shader
Shaders are programs that tell 3D objects how they should look. This special shader is a pixel shader that uses the lighting to tell each pixel what color it should have. Everything that is rendered in a game has a shader.
“It’s just that some shaders are a little more involved than others,” Wilde told me.
Shaders explain a lot of the details at the end that we see. Rendering 3D elements – for example, all grooves and knots in tree bark – would be time-consuming and labor-intensive. However, a shader can create the illusion of tree bark, armor, skin, or beer froth in a bottle, even if the object it is applied to is just smooth, smooth igamesnewss.
Now lost at home, Wilde returned to the shader. Alyx already had a lighting system so the shader had to figure out which values to be used when lighting has been calculated. The shader takes into account inputs such as basic colors, textures and reflections for both the liquid and the bottle itself and then combines them all with one another.
“And what you then output is a different color,” said Wilde. “You do it for every pixel and you get a result in the end.”
The shader is primarily the result of obsessive observation. Wilde was literally sitting in his basement, picking up and playing with bottles to see how liquids behave.
“You look at a shader and see all the work that went into it, and it’s pages and pages of things, but that has never flown out of anyone’s mind, you know, straight into the file,” said Wilde to me . “It was always about building it up slowly … and then brainstorming over time and kind of sketching it out.”
Wilde would make observations of the real bottle – the foam that develops on beeror the way in which liquid captures the light – and then adjust these inputs in the shader so that its creation reflects reality. It was like creating a pointillist painting, pixel by pixel. In particular, there is no liquid simulation here.
“It’s really made to behave the way I intended it to be, nothing more realistic than that,” said Wilde. “There is no simulation, it is just observed.”
Hence the formulation in Alyx‘s Sticky Notes is very intentional: “Bottles now appear
Reflection and refraction
Cube mapping has long been a game’s handling of reflections, and even if ray tracing looms in the future, that won’t change overnight. A dice card consists of six views that are burned into a cube. Depending on where the player’s camera is pointing, the game will draw an approximate view of the cube to create a reflection. This is why mirrors don’t really work in games – dice cards don’t create Perfect Reflections, and they really don’t have to.
There’s a great example of that Marvel’s Spider-Man on PS4 where reflections might show on buildings something up close, but not necessarily the most accurate thing. We are usually quite capable of suspending disbelief because the reflection is there good enough.
This alcohol shader uses a dice card to create reflections but also to create the illusion of refraction – that is light that goes through an object instead of bouncing off it.
The bottles are not transparent. But she appearance transparent because Alyx draws the dice card for your approximate coordinates and projects the pre-baked image onto the side of the bottle you are looking at. It shows you a distorted view of the room, but it’s a wild illusion that absolutely works.
“Use it on a bottle where things are already a little skewed, everything is a little dirty … that’s actually a really good option,” said Wilde. “I think it helps too, when you look at glass and liquid, nobody knows what it should look like, just as an instinctive thing. You just accept when you start looking through glass and things get a little strange. “
The cube map image is doubly distorted when the shader indicates there is liquid. Wilde combines reflections upon reflections to create the impression that there are two surfaces: the glass bottle and the liquid “inside”.
And so the illusion of liquid is created Within a transparent glass bottle – in fact the bottle is empty and opaque.
Fake physics
What I love most about this shader is that it is detailed enough to cross our mental threshold of realism – even if it doesn’t require simulation.
“Everything is fake, everything is deceived. Everything is just kind of observed and optimized and the values are changed until it feels almost right, ”said Wilde. “When I shake a bottle [the liquid] Art wobbles around a bit. So let’s wiggle it a bit insofar as the wiggle looks about right. “
It is this wobble that initially delayed the shader as there was no efficient way to get the information into play. In the end, the performance cost was negligible as Wilde’s colleagues at Valve realized they could store data in the shader’s vertex color.
The vertex color is “a relic from an earlier time before realistic lighting and texture,” Wilde told me in an email. “In this case it was just one color that was applied to the whole. And we didn’t use that color for anything. “
And so the stirring (or professionally sloshing) of the liquid, the direction of gravity, and foam or bubbles are stored in these unused RGB channels. When I wag a bottle wildly, the speed of the bottle is used to drive the movement, causing the liquid to slosh around. Bubbles or foam are also speed-tied and gradually break up when movement stops. However, the most intense calculations – lighting, reflections, shadows – are already carried out for every object in the game, regardless of whether the player is going crazy with bottles or not.
Why it works
While working on a lockdown project with plenty of alcohol may sound isolating, Wilde wasn’t alone in implementing the shader and fixing the performance issue – AlyxThe visual effects are a team effort.
“The success rests first and foremost on the fact that the assets themselves are so good from the start,” said Wilde. “If you’re writing a shader, certainly this type of shader … piggybacking you on an existing pipeline and lighting configuration. So it’s just about making the best use of what is there. “
Shaking a bottle may be easy in real life, but making a virtual bottle respond in kind isn’t that easy. With time and frankly impressive powers of observation, Half-life: AlyxThe juicy bottles felt like this Law that we don’t have to suspend disbelief when we see them. It’s the kind of clever, creative thinking that game development will always benefit from, no matter how advanced the technology is.
Table of Contents