#Preventing FPS gun clipping

1 messages · Page 1 of 1 (latest)

umbral yarrow
#

looking for a way to do that, preferably without my gun model constantly flickering

drowsy charm
#

So instead of the second camera all you will be doing is forcing the gun to render last meaning it will render on top of everything

#

To do that you want to make a layer called Gun and any gameobject that's supposed to render on top should be that layer

#

Next you see at Render there. That asset you want to open up in the inspector from your directory

#

In the renderer asset you should have something like this. For the Opaque Layer Mask make sure you remove Gun layer from it

#

After that scroll down to RendererFeatures -> Add RenderFeature -> Render Object

#

Now, since this only uses a single camera, you do want to make it a child to the player as it moves in the same physical space

#

I'm also assuming the gun materials you are using are Opaque (which they should be)

thin pollen
#

Overlay cameras or forced render order will not play nice if the first person model needs to receive cast shadows from the environment

#

If the weapon is shrunk relative to the camera's transform, it'll move closer and less likely clip with other objects, no change in appearance from the camera's point of view

drowsy charm
#

Lighting should be fine but yeah shadows would be a problem if the gun is inside of the wall and you want the shadow to project onto the wall it's in, but even if you shrunk that down I feel like that would be hard to portray correctly, no?

#

Can always just make a secondary rendering of the character that's rendered a few units back that only project shadows

#

Ah, yeah but if it's in the wall it does become darken unfortunately

thin pollen
#

I heard someone mention that you can do some type of matrix math to fix that, but it went over my head and I can't find it unfortunately

#

So shrinking the mesh would be my first option each time
Simple to do by parenting an empty to the camera with zero transforms, parenting the gun to that and then uniformly scaling down the empty

#

As a bonus scaling only in depth axis precisely emulates changing FoV

umbral yarrow
#

one small issue

#

you can see the insides of the gun now

drowsy charm
#

Ah so it's more than one material eh

#

Let me think, there's a few ways about this

umbral yarrow
#

the problem with that is that both the insides and the top parts are the same material

drowsy charm
#

Oh, yeah I see what you're talking about

umbral yarrow
#

so if you do that you end up with this

drowsy charm
#

Right, that's a little tricky then. Well, I think Spazi's idea is probably best, but as a bandaid I'd turn event ordering to 'After Rendering' and unchecking the depth box there.

#

Really the more materials you have to sort against becomes a problem with this idea. For a single drawcall it should work fine but yeah I see what you're talking about running into sorting issues with inner geometry

#

Meaning the secondary camera idea does become more workable as you set up an environment to sort, or do as Spazi said and shrink everything and lower the near-clipping plane enough that it looks promising.

#

After Rendering point does work though to sort against everything on its own layer.

umbral yarrow
#

i got it to work!

#

basically, you have the two cameras with different priorities, the gun camera's render type being set to "overlay". then i added it to the main camera's stack

drowsy charm
#

Problem with that way is you can see the shadowing doesnt work

#

Only the scene lighting would apply in that case

#

Generally just a hard issue to resolve without some tricks unfortunately

#

But really I'd worry about that another time as you can always come back to this later on. Good job for getting it working though ;p

thin pollen
#

If the limitations of these techniques aren't a bother, that means they're perfect for this case

#

I didn't expect opaque sorting to be a problem between meshes all included in the same Render Objects though

umbral yarrow
#

the shadow of a floating gun would break the immersion faster than looking down and seeing no legs

thin pollen