Valheim is pretty heavily GPU bound and the frame rates suck. Can't really blame them, typical of tiny indie teams and I'm enjoying the game, but I wonder if I can point a profiler at it and see what I can find...
Oops accidentally spoiled probably some endgame thing while looking at a Valheim frame capture 😂
Yikes! 101 VGPR procedural terrain shader with like 12 texture inputs. Good luck with that fam 😬
Reflection probes being rendered into a RGBA16F target (with overdraw) only to be immediately drawn into lighting buffer with no other use this frame. Could have been done directly or rolled into previous render pass. Builtin Unity system.
It's doing a cube shadowmap for campires, and it seems to render both a nearby terrain patch and a much larger scale terrain as well. Both through a geometry shader as well. I doubt campfires need such large scale terrain in their shadowmap.
This is possibly a mistake and only the nearby terrain geometry is needed. In my indoor campfire case, 2.2 million vertices were spent rendering the greater terrain and not a single pixel passed the depth test.
Dynamic lights are using depth tested geometry, one light per draw. Builtin Unity renderer, pretty outdated tech. At least there's just a few lights in this scene. If you had a bunch of torch wielding players around it would hurt tho.
It's rendering 4 shadow map cascades and again it seems both small and large terrain overlapping. Only in the last cascade did any pixels from the large terrain survived.
The builtin SSAO is kinda weird. It depth tests even though it's a fullscreen quad pass, and then spends an entire draw call copying a texture it just wrote. If you need 2 copies just write 2 render targets to begin with. Normal GBuffer filter is also weird.
From what I remember the default PostFX library is implemented poorly and ends up doing a lot of unnecessary render target shuffling about.
Fog is a separate fullscreen pass. Of course it didn't get rolled into any of the earlier passes :/
No idea what the sky shader is doing, but there's at least 3 copies of the mesh overlapping with alpha blending, and only the first one seems to do anything. Either broken or could be merged into 1 pass.
What is happening in this water domain shader?? Of course not a single pixel passed the depth test for this one :|
Cloud shader same issue as sky, 6 overlapping alpha blended meshes. Could probably merge into one and avoid the overdraw to a 64bpp target.
The custom particle shader draws each particle 5 times overlapped alpha blended. Whatever it's doing it can probably be merged down into 1 pass to avoid blending overhead at a minimum. Some particle effects are just 1 pass though.
These neat wind thingy particles are drawn 3 times over! Can probably merge it! Don't be afraid of for loops and if's inside your shader! They're not the cheapest but much better than drawing multiple times.
There's more low hanging fruit, including even the UI. Going to try profiling now.
The worst problem is with the terrain, in both the GBuffer and shadow pass. It has very poor occupancy for something texture heavy, or is just seemingly unnecessary in some depth passes.
Nothing is as bad at first sight after this, but there are performance gains to be had everywhere in a Valheim frame. I need to go to sleep now it's 3am. Fun game, looks great, wish it ran a bit better. Killed the first boss yesterday!
In the GBuffer pass there is way too much foliage/grass. You can do a depth prepass here first for the alphatested geometry, it will really help a lot with GBuffer overdraw.
They should also be ordered to be the last thing you draw in this pass!
Other than this, the graphics aren't too crazy. The entire Unity PostFX can be thrown into the trash bin performance-wise, there is heaps of time to be gained there too, but much more difficult to implement all of that.
Share this Scrolly Tale with your friends.
A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.
