SIMONE: We're all taking up hobbies this year.
A lot of people are baking bread.
Some people are learning how to paint or to skateboard.
Matt Wilde decided to make beer.
Virtual reality beer. In Half-Life: Alyx.
Let me explain.
Matt is a VFX developer at Valve
and he is the reason that these bottles of alcohol...
...look so dang good.
When Half-Life: Alyx patched in these boozy bottles,
people got PUMPED! Because it looks like
there's a baller physics simulation running here.
Like the perfectly rendered gamer liquid of the future. (soft chorus singing in background)
But it's not.
It's one big cheat.
You see, liquids are tricky.
In a video game world
where everything is a bunch of shapes stuck together,
liquid has no shape.
And not all liquids are created equal.
A foaming golden beer is different from a viscous oil slick.
There are different ways developers can make liquids.
Shadow of the Tomb Raider
runs a real-time fluid simulation,
but only in the square around Lara.
The edges of the simulated square are blended into
the non simulated liquid around it.
Liquid can also be created through particle effects.
In this BioShock scene,
an airplane crashes into the tunnel
and water starts flooding in, oh noooo!
But this isn't a physics simulation.
The level of water is never going to rise.
The particles keep generating
and then dying away for infinity.
(water rushing)
And there's another way
of making that sweet, sweet liquid.
Matt's way.
His passion is shaders.
MATT: Everything that's rendered has got a shader.
It's just that some shaders
are a bit more involved than others.
They're kind of magic though.
They are magic.
SIMONE: Okay, so shaders are programs that tell 3D objects
how to look.
There are a few different kinds of shaders,
but I'm talking about pixel shaders.
At its most basic,
a pixel shader tells every single pixel what color to be.
It sounds simple,
but pixel shaders account for a lot of what we actually see
in video games.
The easiest way to see the power of shaders
is to look at what modders can do
with Minecraft shader packs.
Neither the texture nor the geometry
of this wall is changing.
But it can look dramatically different
depending on what shader is applied.
When it comes to liquids,
Minecraft water shaders can include reflections
or even caustics,
which are those cool curvy patterns you get
when light is distorted,
like in a swimming pool, or Dakota Johnson's living room.
DAKOTA JOHNSON: I think is the coolest.
SIMONE: All of those liquid examples I was talking about earlier,
they also use shaders.
Everything does.
But the liquid in these bottles in Half-Life: Alyx
is only shader.
The bottle is a 3D object,
and friends, there is nothing inside of it.
The shader is like a sticker that's stamped on the side
playing tricks with our minds.
And it's exactly the reason that Matt was brought on board
the Alyx team.
MATT: We've got an entire level based around a distillery.
And currently the the bottles, they're really static.
You can't see through them, they don't do anything.
SIMONE: When Matt joined, Alyx was almost a finished game.
The other developers had made these beautiful bottle assets
covered in dust and grime.
There was a powerful lighting system in place.
But what Matt didn't have was a lot of time.
Alyx needed to ship,
and optimizing a distillery chock full of reactive liquids
was a lot to deal with.
So the shader got shelved,
and Alyx shipped with opaque bottles on March 23rd, 2020.
The same day that Washington State went into lockdown.
MATT: And so we had time suddenly.
(eerie music) (bottle whooshing)
SIMONE: Matt resumed work in his basement
with a lot of booze on hand.
MATT: So yeah, I mean, it starts from just picking up a bottle
and looking at it and just seeing what happens.
SIMONE: So, when I hold this bottle of whiskey up,
I notice that it's darker amber on the bottom
and lighter in the neck of the bottle.
I also notice the bottle has a lot of dust on it,
and that's gross.
MATT: Oh yeah, here's a meniscus.
And here's like... the edge here,
it catches the light in a certain way.
SIMONE: This is what Matt did for hours and hours:
observe the behavior of liquid in the bottle,
and then adjust that value in the shader.
Functions that compute the lighting
exist in the Alyx engine already.
What the shader needs to figure out
is what values to use when the lighting is calculated.
It takes into account things like the base color
of an object,
how reflective it might be,
the shape of its surface.
Matt was working with two sets of these values,
one set for the glass bottle and another for the liquid.
Let's talk just about base colors.
With red wine and a green bottle,
you end up with, I guess it's black.
But that same wine in a crystal glass looks red.
Or maybe still black.
It's red.
You get the point is the point.
And that's just one input.
MATT: You have inputs for textures,
the glass color and the dirt,
lumpiness of the glass and metallic bits of the labels.
All of those are inputs.
And then you combine them together just using maths.
And then what you output is another color.
You do it for every pixel and you get a result at the end.
SIMONE: It's like he's creating a pointillist painting.
He adds a single brush stroke
and looks at it from 20 feet away in VR
to decide if it looks like beer yet.
Even though there are two sets of values to start with,
what we end up with is just one shader.
But there's basically a horizontal line
programmed into the bottle that says
anything below here is rendered
to look like it has liquid in it.
Anything above here, isn't.
That line changes relative to the bottle.
So if it turns over or, God forbid, gravity changes,
it looks like the amount of liquid stays the same.
A bottle that's half-full will always look half-full.
Or half-empty.
(brisk electronic music)
If you break a bottle,
the shader swaps to a version that ignores the liquid.
You get a particle effect for the splash,
and a wet decal on the ground that says you're a sloppy boy.
The tricky part is nailing reflection,
light bouncing off an object,
and refraction, light passing through an object.
Matt was able to check his work by just popping into VR.
MATT: I would generally hang out in the lobby of the hotel,
the Northern Star.
And that's because
there's a load of different bottles there, so it's great.
It's a great place to test it,
but also the lighting is absolutely perfect for it
because there's big windows on the side.
Do you hold up a bottle to the windows,
you see the light coming in through the windows.
We hit upon the idea of using the cube maps
which are used for reflections.
Also using those same cube maps for refraction.
SIMONE: Cube mapping is how most games handle reflections.
You've got six views baked into a cube,
and depending on where the player's camera is pointing,
the game will pull an approximate view from the cube
for the reflection.
It's why mirrors don't really work in games.
Cube mapping doesn't create a perfect reflection.
There's a great example of that in Spider-Man for PS4,
where reflections on buildings
will show something from nearby,
but not necessarily the right thing.
The thing that makes cube maps so unreliable for reflection
makes them perfect for refraction.
MATT: Using them for a bottle
where things are already a bit distorted,
where everything's a bit dirty,
it's actually really a good way of doing it, it turns out.
And you get away with a lot more than you might imagine.
SIMONE: The cube map image is distorted,
and then doubly distorted where the shader says
there is liquid.
Reflection and refraction are also what Matt uses
to make it look like there's two surfaces here:
the bottle and the liquid inside of it.
MATT: The only extra thing, I suppose for the liquid,
is that I do the reflections.
I do them twice and kind of combine them
so that it does look like there's two actual surfaces.
So you get reflection on top of another reflection.
SIMONE: And those double reflections are on top of a bottle
that is not actually transparent
and has nothing inside it at all.
MATT: It's not really clever solutions to things,
it's more like stupid solutions to things.
It is magical.
And it's why I really enjoy doing them.
The shaders can create something visually
that is completely unique.
But yeah, it's all kind of maths in the end.
SIMONE: One of the things that I find so cool about this shader
is that it basically passes our mental threshold for realism
even though it's not actually based on any physics
of how liquid behaves or looks.
It's just based on Matt's obsessive observation
of how liquid behaves and looks.
MATT: And I think it also helps that
when you're looking at glass and liquid,
no one knows how it should look
just as an instinctive thing.
You just accept that when you start looking through glass
and things go a bit weird.
SIMONE: We bring so much suspension of disbelief to video games.
Sometimes I clip through walls and that's okay.
When I talk to an NPC and they start to repeat dialogue,
I'm not mad.
That's how I know our conversation is over.
But with these bottles,
there's no suspension of disbelief required.
They hit our brains right in the sweet spot
that makes us say, "Holy shit, that looks real!!"
MATT: So yeah, everything is faked.
Everything is cheated.
Everything is just kind of observed and tweaked
and values are modified until it just about feels right.
SIMONE: No matter how realistic video games end up looking,
developers are always going to need creative solutions
like this shader.
To me it perfectly represents
how something that's so simple in real life
could turn into a creative challenge for a game,
could turn into art.
(brisk electronic music)
MATT: I spent so long picking up bottles and looking at them,
I can't stop doing it.
But I see things like little bubbles
that gather around the edge.
I don't do that, you know.
I kind of wish I'd done that.
This is port and it's a little bit thicker,
and if you do that quickly,
you see that it starts to come down the sides a bit as well.
You know, I'm not doing that.
Maybe I should have done that.
You could go on forever.