Is it possible to render the first person completely seperately. Not panini related

:grin:


It’s actually not done, but this may be enough. Uses only sample content. No render targets, just masks the material.

1 Like

MostHost_LA: you can’t blame the guy for wanting a -proper- system really. sure UE4 doesn’t support a more straightforward way out of the box (while other engines do, and even UE4 can be modified to do it) does not mean we must be locked to a mindset of hacks and workarounds.

so, scope classes.

look at 7:17, there’s 21 different scope optics models. they are just optics, so no they are not tied to a specific weapon (sure you won’t use a snipe scope on a gun, but each of these scopes can go with any of the different rifles). vertex paint really does not scale up

sniper scopes (x36 or whatever) usually obscure the outside of the scope (see that same video at 18:50). you just scale the FOV, easy, no render targets.

with the solution I proposed in my previous post, it really is a “cure all” solution. I’ve seen it in action, it’s pixel-perfect removal of the gun geometry based on the scope lens, whatever position or rotation the animation might cause it to do. and of course you can control it. you can still filter what you want to clip however you wish, be it by distance from the scope or by vertex paint or whatever else you want to muster in your material. the important part (the position and shape of the scope lens to clip through, per-pixel) is there.

lacking the good solution (simply because Epic has no interest in spending effort making CustomDepth sampleable in the base pass), maybe at least we could spend the time here contributing to a more robust solution (one still doable without engine changes). personally I find that more stimulating than questioning his (quite reasonable) motives :slight_smile:

and I don’t see how multiplayer is involved in any way. in most games first person arms and guns are rendered detached from the 3rd person mesh (what other players see), which is in turn not rendered in the eyes of the player (except a cutout of the waist and legs). this is FPS basics.

_

midgunner66: that’s a good effort! though, how would it behave when the gun moves from animation, and how would it work if the scope was a rectangle rather than a circle?

1 Like

Those are models not “types”.
The types I see in the video are only acog and red dot.

They can all occlude the gun the same way. That is red dot does not.
Acog can if above x2

Re multiplayer. It does matter if you just render the gun with the same material.
It will disappear when the enemy aims down sight unless you use different weapons.

Re the rest.
Maybe editing the engine for a specific purpose is not such a bad idea if the scope of the project requires it.

I don’t blame him at all for wanting a better solution, but I think the focus is in the wrong place.

A “better” solution is not going to make the gameplay any better is it?
A proper solution (like your pass sampling) would…

Thanks! The way it works, animation doesn’t affect it (both skinned and if the gun is moving & rotating), and I’m about to change something that I think will make the scope shape (lens) not matter.

1 Like

This looks great! Can you post your material so we can see what changes you made? Trying it out but its doing strange things

1 Like

Would also like to see how you made this, handling self-occlusion is turning out to be more challenging than I expected for my approach.

1 Like

So here’s how it works:

The original idea was to trace the entry & exit lenses of the scope:


If the ray hit both lenses, then that means it’s passing through the scope. So the original idea was to ray trace two disks, and if the ray hit both, then mask the material. The only problem with this is that the shape of the lenses have to match the scope lenses.

But after making it, I realized (1) the position of the entry & exit points don’t matter as long as they’re inside the scope, and (2) you don’t need two lenses (intersections), you only need one.

So the new idea is simply: if the ray hits a lens placed inside the scope, then it is passing through the scope, so mask the material:

The only necessary things is that (1) it must touch all inside walls of the scope, and (2) it must not go outside the scope (though, I think there is some lenience on these, so they may not be 100% musts).


So the material is simple (note: the parameters are still named from the old idea):


It’s a single material applied to whatever you want to mask (meaning the gun, but not the scope). The material works by intersecting the disk of the entry point; the disk is formed by intersecting the plane and then the distance of that intersection to the entry point and seeing if it is within the radius of the sphere. If it is, then mask the material.

The parameters are updated by just getting the location and radius of the lenses:

2 Likes

The only part I’m really curious about is the magnification you are getting - seemingly with no artifacts. At least viewed on mobile…
You did say you weren’t using a render target, so how are you filtering it?

Lol, there is no zoom; it’s just masking out the material. That’s what I was mentioning way earlier:

The reason the barrel disappears in the scope in COD, etc., is because of the scope’s zoom; when the scope is not zoomed, you can see the barrel, like the reference videos I posted. In my video, it’s simply masking out the barrel, so it is “emulating” a zoom.

I’ll chalk it off to a cardboard tube illusion then.
It looked like the head was closer when seen thorough the scope.

1 Like

Thanks for posting (and explaining) it, that’s a really clever approach

I don’t care about scopes, I just like interesting materials so in my view this thread was a success lol

3 Likes

Appreciate you seeing my viewpoint.

I had originally thought about using the custom depth/stencils to create my mask for the lens, then using that to mask the gun, exactly as you said. I looked at videos of COD and slowed them down frame by frame and you can clearly see the gun is masked out real time through the lens where it should be visible. And obviously I knew that some games render FP seperately to do this sort of thing. Its a real shame an engine as good as UE cant do this, and I fail to understand why they wouldnt be interested in making it work by default.

Do you know of any games/projects that have gone to the lengths of making engine changes to make it work? How much effort is this for someone experienced in that sort of field, do you know?

And yes hopefully we can come up with the next best solution that works in Unreal Engine for others to learn from and use to achieve similarly AAA results…

1 Like

So I got scope zoom to work, though I hacked it in a quick idea I had; the way it is now is not “correct”:


It just switches to a “zoomed” version of the mesh, no render targets.

3 Likes

How do you mean a ‘zoomed’ version of the mesh?? How have you done this?? Its really cool by the way great job :slight_smile:

1 Like

There’s two meshes, one that’s normal sized, and one that’s scaled up. When you look through the scope, it masks the normal sized one and shows the scaled up one.

Obviously this has problems, so it’s very hacky, but it’s a start.

2 Likes

yea but artifacts… that’s why usually render targets.
Though it’s probably more performant since at a minimum you are looking at double the MS cost to render the scope scene well enough.

IDK. maybe can you specifically run a different anti alias onto the zoomed lense material?
There’s an anitaliased mask node that I never played with before that could become useful for this perhaps…
Takes the route of a render target though, so not sure.

Say you were to save out the lense material to a RT and re-use it in the antialiased texture for instance. ( Draw Material to Render Target)
The cost of that doesn’t involve rendering - but it does write to memory/disk so still not cheap.

1 Like

Yeah, there are artifacts, but good for an experiment. I think render targets are better suited for this.


I got a better zoom working. Video shows zooming, moving, and rotation, and artifacts.

It does it using world offset. I know you need to scale the vertices along the plane of the scope, but what I did just managed to move the vertices forward & back. Eh, good enough. I’m done with this. :joy:

1 Like

Lol that’s nuts.
Make a scify game our of it and submit it for the jam.
(It’s probably already better than the “theme” they picked! Yet again)

1 Like

my bad those are attachments with optics, not the optics themselves. but the point is still that each of these are differently positioned and sized (even shaped) so each of these will ‘clip through’ the weapon body in a different way, hence the need for a more robust system than vertex paint.

for multiplayer: this system is only relevant for the 1st person view meshes (the whole functionality should be disabled -except- for the currently controlled/viewed meshes from 1st person of the local client), so of course nothing the enemy does should have any impact on your own weapons, and of course you shouldn’t see clipping on the enemy weapons when you or the enemy does ADS. I thought that was immediately obvious but maybe I’m misunderstanding what makes it a problem in your eyes

a better solution won’t make the gameplay any better per se, but it would save time of setup and tweaking the positioning/sizing/aligning of the clip-through params in the material per-weapon per-attachment. you can focus more on gameplay if you save time on tedious/finnicky things :wink:

1 Like

throughout the years it’s become clear that Epic will only be interested in things that will either: benefit their ongoing projects, seem beneficial for a majority of the users, and/or make a significant progress to keep up with the state of the art. sampling CustomDepth in the base pass is a feature that doesn’t seem to meet any of this criteria :slight_smile:

in a previous company I worked at the feature was added by a generalist programmer (experienced, but not a rendering specialist), and took him a handful of days if memory serves me right.

without engine changes the idea of a virtual plane seems like a fair alternative.
with enough work in the material it could be made to behave fixed at a specific point in the weapon regardless of animation (using transform from local to world) without passing coordinates from BP every frame. and you’d be able to feed the ‘local position’ numerically (get the position from your 3d modelling software) and not have to deal with repositioning all the time.
you could also map a texture to it (instead of a parametric disc shape) with the shape of the scope ‘baked’, and it would allow you to have various scope shapes like rectangle etc.