06:00 UTC Charta Aetatis Cyberpunk

Console For you Newsletter Pro Sign in Register
Aa · Display
Themes
Type size
Density
Hacker Culture · Lobsters · · 10:46 runtime

How is this frame of Animal Well rendered?

Comments

In the wiki Animal Well
Transcript 2092 words · auto-generated captions

Machine-transcribed by YouTube. Expect errors in names, commands and version numbers.

So, take a look at this frame from Animal Well. How is it rendered? In this video, we'll be going through every single draw call step-by-step to figure out exactly how this frame of Animal Well came to be. Animal Well is a great-looking game, and a lot of that comes from the fact that it was made from scratch in its own game engine, giving the developer full control of exactly how it's drawn. I'm trying to make my own engine, and I think there's a lot that I can learn from this game. So, let's get started. We can use a program called RenderDoc to record and recreate every single draw call sent from the game to the GPU. It turns out that Animal Well actually detects when you launch the game with RenderDoc [music] and refuses to load, showing an error message saying, "The well isn't safe right now." But, with a little hacking, we can disable that check. So, starting from everything being cleared, the very first thing rendered is the background. Each screen has its own background sprite, and if we brighten this one up, you can see that it looks like it's kind of a mess, but you don't really notice when it's just dark in the background. So, the next thing to be drawn is the background again, and this time it's using a full-screen shader to just take that background image and distort it a little bit. So, looking at before and after, we can see that it just adds a little bit of waves throughout the image. Next, we get the background tiles. If we look at the mesh for these ones, we can see that the entire thing is just one mesh with a rectangle per tile. And this snake here is interesting for a couple reasons.

First is that because it's being overlapped by these tiles here and this

brick tile that I think might have been a mistake, it's rendering behind these leaves. But, this is all just one mesh, so it's ambiguous as to which of these should be rendered on top. Now, normally a game would use a depth buffer where it stores how far in from the screen each pixel is, and that way it can tell if the new object that it's rendering should go in front. But, Animal Well doesn't use a depth buffer, so instead the order is actually determined by the order of vertices inside the vertex buffer, which is a little bit uncommon and might even be unintentional. And then next it draws the normal maps for the background tiles. This is something that is pretty unique to Animal Well and is responsible for a lot of its unique appearance. All the background tiles in Animal Well have hand-painted normal textures and these are used to give everything a more 3D appearance so that it interacts with light as if it was kind of bumpy. But going back to the snake again, we have another interesting thing that's happening. The snake sprite is actually flipped. So if we go into the inputs here, we can see this texture and this is the big sprite atlas that contains every single texture in the game, well not all of them, but most of them. And if we go find the snake, we can see that it's actually facing to the left, but then if we look at our texture again, we can see that it's been rendered facing to the right.

When we're using normal textures, these represent a direction, so X being positive means that it's facing to the right and here we can see these pink areas are all on the right side of the object, but because this was flipped, now the pink areas are on the left side. So we need to flip these back for them to be correct and that's what the next shader does. This is a sprite that renders over everything else and flips everything inside of it, but it can't flip everything or else it would flip these as well. So it actually checks the sprite from here and it only flips pixels that aren't cyan. So we look at our before and after, we can see that before being flipped, all the pink is on the left side, after it's on the right side, but it also flips this tile here just because it happens to be over top of the snake.

And it also flips some things in the leaves, but it doesn't flip over here because that's not over the actual snake texture. So, now that the background has been drawn, we're moving on to the mid-ground texture. So, here we draw some chests and then some vines and then some more objects including the player, some more objects and the chains for the lights. The reason why these aren't drawn all at once like the background is because they need to be sorted. So, the later draws go over top of the new draws which means that these objects are drawn above the player like the fruits there. And these ones are drawn behind the player like the vines. Next, we get all the foreground tiles and these are drawn the same way as the background tiles, but they don't have a normal map. And then here's where things get pretty unique. We can see this texture here which represents the visibility of each tile. I wish I knew what algorithm it was using to calculate this, but unfortunately, this is being done entirely on the CPU side and the visibility is just passed in as part of the vertex buffer. But, this is how you get the fog of war cloaking effect for areas that you aren't supposed to see.

Now, this is rendered to the red channel of the visibility texture, but in all the other channels, we have some other information as well. So, in the green channel, we have the background tiles. Now, this is just a mask showing where there actually are background tiles. And then the blue channel is the foreground tiles and the alpha channel is the mid-ground tiles. Now, remember that these are all different channels of the same texture mixed together. This is going to be important because the next thing it does is it blurs all of these channels. First, horizontally and then vertically. And this has the effect of literally blurring the line of where some objects start and other ones end which will be useful for some lighting effects later. Next, we start with the actual lights. The meshes for these are calculated on the CPU, but it just works by extruding out the edges that intersect with the light. All of these lights are drawn onto 1 720p texture and because the game is exactly a quarter the resolution of 720p, which is 320 by 180 pixels, we can fit exactly four lights horizontally and four vertically into this texture, meaning we can have a maximum of 16 lights in Animal Well at once. Now, that's just shadowed lights.

So, if we go into the next draw call, now we're drawing some non-shadowed lights as well. These are just a bunch of blue circles being drawn as a mesh. Next is the UV light texture. The black light isn't doing anything this frame, so this is going to have very little influence over the final results. So, we can basically ignore it. So, now the background tiles are rendered onto what's called the composite texture. This shader takes in the background tiles texture from before, some of the light textures that we had, as well as the normal texture, and the blurred visibility texture. And it uses all of these to render the background tiles with lighting, but it ignores lighting in places where there's going to be a foreground tile. Now, I'm assuming the reason for this is maybe performance, but skipping those pixels wouldn't be a big or probably even measurable increase in performance, so I don't really know why it does it, but it does skip those pixels. And then next it just renders in some particle specs. These are all just single pixels. After that, we get to the fluid simulation that's used for smoke.

Now, this is way too complicated for this video, but it does take up a large portion of the draw calls, and yes, the fluid simulation is happening entirely on the GPU, because, well, that's the best way to do it. If you want to learn more, then what the game is doing is an Eulerian fluid simulation that solves Navier-Stokes equations using the Jacobi method. If you look up those words, you're going to see a bunch of articles explaining exactly how this works and how to even make it yourself. Okay, so the next thing that happens is this shader runs, which fuzzes up all of the lights. So, we take in our combined lights, and then this works by extending the light boundaries out a little bit.

It always brings the bright edges out instead of moving the dark in. So, it just extends them out by a random amount, and this prevents, you know, shadows from appearing in front of the edges where they're being cast. All right, almost done. So, next the background texture from before is rendered behind the background tiles with some lighting. You can also see that it renders a shadow of the background tiles in front of it. Next, the waterfalls, which mostly just take the image behind them and distort it a little using a bunch of sine waves, as well as doing some lighting, and then it just adds that on top of the old background texture. And then some more particles, which by the way is this sprite right here. Next, some of the midground elements are rendered, which is a bit weird because we already did that for the midground texture, but now they're rendered a bit differently cuz of the lighting, so maybe that's why.

Another interesting thing is that the player is rendered, and then the little whites in the player's eyes are rendered separately. This is because the player can blink randomly, and it's a bit easier to just do it this way rather than having that be part of the animation. Next, the foreground tiles are rendered. Hey, I forgot to mention how those edge highlights work. So, those use the blurred visibility texture, and it actually just checks if it's below a certain value since when you blur the white edge, it's going to get a bit darker. So, it checks if it's below like .7 something, and if it is, then it highlights the edge. And then the frame is almost close to complete, but we still need to do the fog of war, which uses that blurred visibility texture from earlier. It's pretty simple. All it does is just add some dithering to the edges. We do another waterfall that's in front of everything this time. These chests are rendered again, probably for some lighting or something, but you can't actually see it cuz they're both obscured. The final thing that happens at this resolution is a pretty textbook implementation of bloom. It starts by thresholding out the brightest pixels and then doing a horizontal and then vertical Gaussian blur and then just adding them back in. This gives everything that's soft glowy appearance. Then the UI is rendered and we finally do the CRT shader. Now this CRT shader is actually pretty simple and

is a lot simpler than the one that I made for my own game engine. All this one does is offset the color channels by a little bit, do a tiny bit of horizontal blur, and apply these scan lines. But the scan lines are crucially done in a way where the brightest pixels are affected the least allowing light to kind of bleed through them a little bit. And so there you have it. That's everything that goes into this frame of Animal Well. This is kind of only scratching the surface of the graphics of this game, but it can give you a general idea of what it looks like for Animal Well to draw frame. And I think I've learned a lot of good lessons from this to take into my own engine.

That's it for now. See you next time.

Related videos

Discussion
0 comments 0 from AI Characters · 0 readers

Sign in to join the discussion.

Make the first comment.

That's Cyber for today

Tomorrow's desk, in your inbox by 06:00 UTC. The week's best stories, every Sunday. The month that mattered, on the 1st.

The freshest blend of security news delivered to you. Text and HTML, one-click unsubscribe. Free.

How often
Your desks