Andy Robbins Profile picture
Mar 26, 2021 • 22 tweets • 5 min read
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 😬 Image
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. Image
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. Image
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. Image
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. Image
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 :| Image
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. Image
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. Image
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. Image
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. Image
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.

• • •

Missing some Tweet in this thread? You can try to force a refresh

Keep Current with Andy Robbins

Andy Robbins Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!


Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

Did Thread Reader help you today?

Support us! We are indie developers!

This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!


0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy


3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!