Itâs actually not done, but this may be enough. Uses only sample content. No render targets, just masks the material.
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
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?
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.
This looks great! Can you post your material so we can see what changes you made? Trying it out but its doing strange things
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.
So hereâs how it works:
The original idea was to trace the entry & exit lenses of the scope:
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):
The parameters are updated by just getting the location and radius of the lenses:
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.
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
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âŚ
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â:
How do you mean a âzoomedâ version of the mesh?? How have you done this?? Its really cool by the way great job
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.
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.
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.
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)
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
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
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.