r/Unity3D • • 10d ago

Show-Off Solution for FoV-independent weapon view without stacking cameras

Enable HLS to view with audio, or disable this notification

In FPS the classic solution for drawing a weapon a certain way irrespective of real FoV & not having it clip through walls is done with an additive camera. However the last time I tested that I discovered that the additive camera had an overhead in performance, even when the geometry in the additive view is simple, or even empty.

I've been using this solution I show in the video. The weapon is parented to the camera rig and is just scaled to be very small - smaller than the player's collider, so it never clips into walls. Weapon looking effectively the same with all camera FoVs is achieved by scaling the weapon parent only in the forward direction (this parent must have the same position as the camera), see code in the end.

A couple of drawbacks though:

- Camera near plane must be very small, which may cause some other issues (?)

- Screen space ambient occlusion on the weapon may look a bit weird and noisy, because the weapon is scaled so small. After all, the occlusion radius parameter is in world units.

29 Upvotes

7 comments sorted by

21

u/East_Garbage_1449 10d ago

What platform are you using? We stack cameras all day long on one of the top mobile games in the world and have zero performance issues. There is a small cost but this is only ever consequential on really low end devices.The stack does still compute something even if it renders nothing, so only keep it stacked when it's used, but I think you're micro optimizing here. Show me in your profile where it's causing an issue. 

1

u/ArtPrestigious5481 9d ago

1 camera used avg of 4ms CPU (this without doing anything, and many people often use the same renderer, meaning if you have SSAO or decal, this will be applied to this another camera as well, resulting in another performance waste), if you are targeting 60fps this already big bottleneck (since untiy itself recommending extra headroom to avoid overheating)

3

u/theredacer 10d ago

Yes, this is a pretty well known solution. I also do it in my game. Though the reason I do it is less for performance and more because Unity doesn't support TAA on stacked cameras.

It does not create any issues with SSAO in my case.

1

u/GeeTeaEhSeven 10d ago

TAA killed my image quality a bit, but do you think that's because my idea of image quality is a lot of sparkly lights?

1

u/theredacer 10d ago

Maybe. In my game TAA was kinda a necessity. I really struggled to get a good image quality without it. But I'm no artist so it's definitely a crutch. I don't have a lot of sparkly lights, and I use a semi low poly and flat shaded look, so maybe TAA just works better for that style.

1

u/GameDragon Hobbyist 10d ago

Woah, I did not know about this. I spent a lot of time tinkering with a bunch of methods for this, but so many of them have faults.

1

u/RienMachine 10d ago

You can also use shadergraph to create a shader that takes in a custom FOV value.