Ads keep us online. Without them, we wouldn't exist. We don't have paywalls or sell mods - we never will. But every month we have large bills and running ads is our only way to cover them. Please consider unblocking us. Thank you from GameBanana <3

Real-time moss in Half-Life - A Blog Post for Half-Life.

It's real!

A couple of weeks ago, I thought to myself, "Wouldn't it be funny if I actually implemented real-time moss growth into HL?", and now we're here.



Here's the story behind it:

In 1997, Gabe Newell was interviewed about Half-Life and what it brings to the table. At some point, he mentioned that moss would grow on Black Mesa's walls. Realistically speaking though, this was absolutely not feasible considering late 90s hardware and the rendering APIs of the time.

The only way it could've been possible was on a much smaller scale in the software renderer, but the only person or two who could work with it had much more important things to do. So, moss never got into Half-Life.

Fast-forward to 2003, Gabe is interviewed again during Half-Life 2's development. He mentions trying to get someone from the team to work on it, but we all know nobody's willing to do that. It's an overkill of a feature, and everyone would rather work on something interesting or just to get the game done already. In fact, this may explain how Judith Mossman got her surname, hmm...

So yeah, nobody wants to work on such an ambitious feature that is merely a detail which most players wouldn't even perceive. Right?

Well, I do.
Sometime around 2020, I was showing off some cool features in my mod base, and a friend of mine asked "Hey Admer, when are you gonna add real-time moss growth?", which was essentially a joke. It's one of those inside jokes from the cut content/alpha/beta fandom. And then, one day, I thought it'd be funny if I did it for real.

So I did. On the 21st of March 2022, I laid the foundations for the rendering code, drew a basic diagram representing how the system would work, and posted a screenshot of that on Twitter. Considering how small the HL1 community is, the tweet went viral.

I, for a moment, became a meme.


(original tweet)

Me being me though, I didn't work on it again until more than a week later. I did some more groundwork for the renderer, and I finally got to render a textured triangle.



Yay! What about making it 3D though? That involved some... stuff. Be warned, for technical talk is ahead.

You see, in order to project something 2D into a 3D kinda space, you need to transform it in a number of ways. You first need to transform it in world space (moving it around by some XYZ coordinates and whatnot, like, where the object is actually at), then you need to transform it relative to the camera (because the camera is static, and the world revolves around it), and then you use a projection matrix (e.g. perspective with a 90° FOV) to do the actual, fancy 3D-to-2D stuff.

The projection matrix was a huge issue because I couldn't just get it from the engine. I technically could, via some OpenGL functions, buuuut I couldn't always rely on it, and it seemed rather hacky. So I decided to reverse-engineer that tiny bit of the rendering code.

I looked into Half-Life through apitrace - and the Quake source code - to find that the near Z value is 4, and the far Z value depends the level designer, but it's 4096 by default.



Here we can see I was playing at 1600x900, and bounce.bsp had a render distance of 7200 units.

This means anything that is less than 4 units away from your face simply won't get rendered. I had an initial assumption of 0.01 and 4096 respectively, which is something that modern engines would typically do!

But yeah, in practice, this difference meant I was seeing moss through walls.



But, finding the right near Z value fixed that, so yay!
I also had to convert from the engine's horizontal FOV into vertical FOV, so I could have a proper, correct-looking perspective that is consistent with the engine's own perspective. I did that thanks to a friend of mine, even though I could've googled it. Yeah, I'm very lazy to google things sometimes.

The rest is really just shader magic. The source code for everything in the video is available and you can find it here, although there are no actual downloads/releases yet. (also note: this won't work in software mode for obvious reasons)

This is just the first part of the plan though, and that was getting the thing to render. The rest will be more about moss multiplication, i.e. the actual growth and spread logic. We will see how that one works out by the end of the month, I hope. I'll likely post another blog once that happens.

Thanks for reading.
Login or Sign up to access this!
Login or Sign up to access this!

Comments

No comments yet!

Embed

Share banner
Image URL
HTML embed code
BB embed code
Markdown embed code

Blogger

Login or Sign up to access this!
Login or Sign up to access this!
Login or Sign up to access this!

Game

Login or Sign up to access this!

Category

Details

Initiative
None

Share

  • 30
  • 8.4k
  • 11
Login or Sign up to access this!

More from Submitter

More WiPs from Submitter

More Other/Misc Blogs

arrow_back