Former Insurgency Sandstorm dev here who did a bit of optic work, how we solved the problems of optics perspective when not using PiP, was similar to how you suggested it worked, except instead of not rendering certain portions of the optic, we just scale down the forward axis so it's "flat". We also smoothly interpolated it so it didn't go flat immediately.
Yo ! You are everywhere, man :3 Just to add on this: This was how non-magnified optics were done (most notable on Aimpoint M4) in Sandstorm. For magnified optics, a stencil mask was used (done by Robin M back in the day), still have PTSD from testing all the glove cosmetic mats that had to be flagged each time lol. And a bonus point: These methods could not be combined so flippable magnified sights suffer from perspective driven rendering when the magnifier was flipped off to a side.
@@BossKillRatio in the vast majority of games the first person weapon view is completely different from the third person renderings of seperate players. Pretty much the only game I can think of that's not like this is Tarkov, and I'm pretty sure Garbaj even made a video specifically talking about how this was the case in Insurgency.
I also noticed that you guys made the AI frequently instantly kill me specifically as opposed to other players. I suppose this was due to how well I did in coop in the first game, you guys wanted to ensure I didn't over dominate in coop.
For r6 siege atleast, if you go frame by frame you would notice the inside of the scope going transparent when transitioning to ADS. Around the frames of 1:04 and 1:05, you can see the full depth at the first frames when scoping in. Then when the screen zooms, the rest of the scope becomes transparent except the sides facing the character(with the 2 extrusion still being opaque and can be seen through the scope).
Yes! You can see the sides of the scope, but halfway, they just vanish! They definitely stop rendering the sides of the scope for the unobstructed view down the tube. Very observant!
That was my first thought too, and would probably be the first thing I'd try when tasked with implementing this. It's very cool that you can see it in action here.
I saw that too when I was going frame-by-frame at that timestamp, but when he showed the Apex ADS, there was no trickery that could be seen (as blatant as R6) in the scope. So I'm not sure about his question. Maybe it does the same thing, but cleaner? Not sure.
The inner walls could be transparent. Blender planes do this thing sometimes and they could use that along with a picture to simulate the appearance of the inner scope margins
No; if that were the case, the entire inner wall would be invisible. And in the games you can see the shortened inner walls. Do you know what you're sayin. or maybe you didn't word it correctly
@@slugintub I think he means the visible inner walls are an overlay not the actual scope but then it’s 3D and I think replacing the scope within a 3D overlay would result in some issues I’m just not very knowledgeable here so I don’t know
Something to keep in mind is that only magnified optics should work this way. In non-magnified optics such as a red dot or holographic sight, you *should* be able to see the inside walls of the tube, because that's all it is. A tube with flat glass panes on either side.
When you use red dots and holos properly (With both eyes open) you don't actually see the sight housing or "tube." Games only show the optic housing for balancing reasons.
And if the tube is long on a red dot it will still use 2 identical lenses inverted to eachother bending the light around the inside of the tube makeing it invisable to you and keeping the image the same size.
Hey Garbaj ! This has been a mystery for me for quite a long time too, but recently I was able to reproduce this effect by using an almost orthographic camera for the weapon. Basically everything but the weapon is rendered on one camera, and the weapon/arms etc. are rendered on a different camera, which, when aiming down sights, interpolates its projection to a near-orthographic one. It's like an ~90% interpolation between perspective and orthographic, because fully orthographic didn't look good imo. Idk if that's what all these games are doing, but it definitely works for me. Anyways, nice video as always, cheers !
@@marly1017 cameras and picture in picture are different, rendering on two cameras doesnt mean you have to render the entire scene twice, because each camera has different parts of the image on it
This very much sounds like the answer. Rendering the weapon in a different camera is done for other reasons as well, even though I don't quite remember what it was... 🤔
I've worked on a few games where we've actually used a similar concept to get better looking magnified scopes. The concept is basically having two models for the scope; one that is the entire thing and one that is essentially cut in half in different places. The latter model is swapped in at a moment when player's can barely notice it and as the front half of it doesn't exist anymore it gives the effect of the far side being the same size as the closer side. In your clips I believe this is seen in R6S & PUBG, while I'm fairly certain that SQUAD also uses a similar concept; when ADS-ing you can see a moment where the scope sort of "flickers". They also employ a simulated "eye relief" look, where there seems to be a dark ring that moves around in the scope to simulate you looking outside the magnified lens. One thing to note however is that I don't think AL uses this system because you can clearly see the inner side of the scope. What I suspect is that since AL renders the gun on a different layer they might actually have the gun having a significantly lower FOV than your main render layer, making the difference in the openings seem less significant. As going lower and lower FOV gives you a "half-orthographic" view I would assume that's their method. Finally, I should mention I'm only a 3D artist and not a coder. While I am learning coding in university and I do understand coding concepts, I don't know the code that goes behind this. This is just my best educated guess based on different games that I've worked on. I hope that this explanation gives you a basic understanding at least of how this all works, and I'd be happy to answer any more questions you might have :D
I was already wondering why nobody else mentioned it. Though, not the only possible answer, as a separate, smaller FOV for rendering only the gun also works sorta.
This might be surprisingly simple, you could just use the 3D scene rendered into a texture and re-render it on your first-person gun models. In Godot, you can access rendered screen with SCREEN_TEXTURE texture and SCREEN_UV texture coordinates in fragment shaders. You can write a custom shader that samples that texture and put that shader on the front lens so it appears as if you're looking though the scope. You can scale SCREEN_UV appropriately so that it samples from a smaller area and that way you get magnification, albeit with with blur. I suppose there are ways to fix the blur, for example by supersampling, but I have yet to experiment on that.
This is pretty much exactly what we did, albeit in Unity. We also make use of the stencil buffer to render a plane with a crosshair on it behind the scope to create a parallax effect for the crosshair when looking through the scope.
On the solution with making the tube shorter, no, you would never notice (if done correctly). I think it's actually a pretty good idea. Something else that could be the case has something to do with draw priority (if that's the correct word???). For example, if you clip inside a wall, you can see through the other side, that's because most games check if a polygon is facing you, and if it is, it is rendered, and if it isn't, it isn't, same with wether a polygon is obscured or not. This saves resources and is honestly not that expensive to implement. A gimmick you can introduce with this procedure is that certain objects can look bigger (or smaller if you'd really like) on the inside. When you look through the scope, a different scope model can be rendered that would realistically not fit as an inside of a scope, but due to forced perspective, you wouldn't be able to tell the difference. The inside scope could be slanted where the forward lens is bigger than the lens closest to your face, in such a way that it appears you are looking parallel to the walls of the tube.
These are called "Normals" as they are defined by the vectors vertically on the face of the polygons. Witch are called Normal Vector. And they define orientation and direction of the plane. And thus they are rather easy to implement. It is just a check wether or not you are more than 180° out of direction of the vector and thus look opposing to it. Then it will be rendered. This leads to 2 different scope models, where the only difference is the inner part of the scope. On one a cone with the tip on the camera. On the other a more or less straight Tube.
@@theonly5001 I think it just hides the inner walls of the scope when you use it (go frame by frame from 1:04 to see the moment the game makes hides those faces). As for the slight perspective of the walls, maybe it only makes the walls transparent except for a sliver at the front
4:01 look at the transition from scoped to no scope, it looks like the inside material of the scope becomes transparent on the inside because as it transitions from the narrow to wide, you start to see the inside, of the outside wall of the scope. There is one frame where it looks like part of the tube has transitioned from transparent to opaque
Yeah I think even the outside walls become mostly invisible when looked at from inside in this instance. So you can only see the scope from the outside, while it's transparent when looked at from inside.
Game dev here. -Some games just have 2 cameras, one of them renders the game, and the other renders the weapons of the user, so when you aim down sights, the camera that renders the weapons and arms of the character changes to cartographic while the other stays normal. I think you had visited before the 2 camera thing (not picture in picture but separated render for player body and environment) and talked about how the two could have a different FOV. -Others are using lerp between two meshes. When you start aiming, the front of the scope opens and becomes wider so that it has a conic shape instead of a cylindrical one (or whatever the scope's shape is) -Some games have chosen to throw in your face a flat sprite representing the whole gun with attachments and everything and zoom in without picture in picture (picture in picture/camera and render texture being the best possible way of making a scope)
There's another very common trick that is used to do picture in picture without performance hit, which is a neat shader that literally magnifies the image behind the lens without rendering another camera. It makes the image look worse as the zoom level increases, but for scopes up to like 4x zoom, the performance outweighs that for things like VR games.
My immediate thought was given that the weapon generally has it's own camera responsible for rendering it (so it doesn't clip through walls etc.), that all it does is widening the fov of that weapon cam, making it nearly orthographic. That's it. You don't actually need camera on the scope either, just take the image the main camera sees (since it can't see the weapon) and blow it up in the middle.
A weird but very cool effect to see is semi-transperancy on scopes. When you use an optic in real life you have two eyes, and only one of those is recieving a zoomed in perspective. With both eyes open, you effectively can swap your focus between them, which has the effect of making your scope (the perimeter of it, not the zoomed image) essentially transparent. Stalker anomaly does a decent job of replicating this (as well as you can on a 2d screen)
I love how in VR this i basically just the nature of having two eyes. I didn't even know that some flat games have this (or a version similar to the effect)
One of the best ways to achieve the effect is with a Stencil Mask. When you have your FP visuals rendered on their own layer, it's very easy to add a stencil mask in the scope to block anything on your FP layer from being rendered there. An added benefit to doing it this way instead of just hiding the back half of the scope mesh, is you also won't see anything through the scope that you shouldn't be able to see, such as the front of your gun, or your characters hands if the optic is really huge on screen. You'll only see the world through the scope. Plus, it means you don't have to build your meshes in a way that they can be partially toggled on / off.
I should add that with a stencil you can also do the opposite and make it so your scope reticle & effects are only visible through the lens of the scope. So you block your first person meshes from being seen through the lens, and allow your reticle to be seen through the lens simultaneously.
@Jordan Rodrigues culling the back faces doesn’t work for this. Scopes often have things on them like dials, as well as having a wider far end. Simply culling the back faces wouldn’t prevent you from seeing a bunch of the front faces further down the scope. Not to mention you would see the weapon itself through the scope. Using a stencil ensures you don’t see anything through the scope that you shouldn’t see, and doesn’t require manually toggling meshes on and off which creates visual pops.
Just a question.can i use stencil layers to separate the weapon mesh from the world and make it render above the world so i can avoid weapon clipping into the wall 🧱??
I feel like a scoped image should just render those pixels that are going to be visible scoped. But I believe the gun scopes are simply thinner at the close part that you poke you're character eye through, than the far end. So it isn't a tube, but rather a cone with 2 holes, smaller end closer to the camera.
It might be something closer to it rendering at area a bit bigger than the scope. If you only render an area the same size as the field of view the scope provides (pretty tiny), then unless your machine is super fast, you will get pop-in if you were to move too quickly. Speaking of pop-in, if your scope only renders the small field of view seen, how would you go about rendering a big model caught in the scope? Consider something like a large statue - if you scope it on it's head, you would have to render the whole model anyway. I think for these reasons it is quite complicated (and less practical) to design such a precise system for rending picture-in-picture scopes.
Some games, like Apex Legends use a separate model that swaps out when aiming. Older Call of Duty titles like infinite warfare and modern warfare remastered do this with magnified optics. Insurgency sandstorm uses a cull layer on the optic lens that removes the insides of magnified scopes when using the "Normal" scope setting.
In some older games like Call Of Duty: 4, the game completely took out everything apart from the area you can see with the scope, or they blurred it out which can be a very easy way of overcoming the problem.
This is only effective to an extent because at one point it starts affecting how the outside of the scope looks as well because you have to keep making it wider for longer scopes
@@andersonrobotics5608 well it could be that the front of the model de renders for the user and the cone may be alot steeper and not just a gradual expansion
I don't usually watch too many graphical-technical things like this, but it does interest me. Maybe its your cadence but i've watched two and genuinely enjoy and learn from this because it is clear that you are coming at it the same way we are: figuring it out as you go along and explaining to us the ins and outs so the layman and interested person could understand in depth. Subscribed.
I do know in my real closed-emitter 1x20mm red dot sights, like my Sig Romeo 5 and Bushnell TRS-25, you don't really see the inner walls of the sight. It's too short to really cause that effect, plus it helps to mount the sight as far forward on the AR's receiver as you can, so you get less vision obstruction. You mostly just see the back end of the sight's body. With games, you can totally just ignore it. For longer-tubed optics like an LPVO, it's a magnified sight that's just set to 1x zoom. So even though there's no magnification, you still don't see the inside of the tube. (The Trijicon MRO is a piece of garbage because of this effect going wrong, it screws with the focus of your eyes and it's actually slightly zoomed in, which distorts the image and looks wonky.)
Scope squashing up as it zooms in works really well. That's how we do it in the game we are making. Certain elements of the scope squash and flatten during the ADS. It is a bit of work, but is fairly convincing and works nicely. Benefit of using this technique is performance impact is minimal and you still get all the lighting and texture details showing on the scope body, even if it is squashed up.
Its really interesting how you make videos. Other game dev videos would just explain how they did it, whilst you explain the options and problems which gives me value even to the audiance even though you didn't kinda used it.
I'm a game dev with FPS experience (though we didn't use this approach). You could do it with two cameras. A Hip Camera which renders with perspective, and an ADS Camera renders only the optic in orthographic.
Usually the first person objects are being rendered separately from the rest of the screen. If they were not, then when you walk into a wall you'd see your weapon clip through the wall. So try walking into a wall, if the gun doesn't pass through the geometry, then the weapon is being rendered separately. With them being rendered separately, it is a small task to have the main camera change the FOV to zoom in while the gun's renderer instead warps to flatten out the image. also, if you are rendering the first person weapon separately it becomes easier to perform perspective and placement tricks so that a gun can be pointed a different way than you are actually aiming.
I think this is just a "side effect" of changing the camera's FOV itself... I noticed that when zooming too much the closer objects to the camera get significantly shorter, sometimes the FOV can even deform square tiles on the wall making them into rectangles, so I guess this is masking the scope's internal surface by distorting it shorter!!
@@MrBluelightzero It doesn't change perspective lines, it just shrinks things along them in order to fit on screen, making them appear shorter. When I change camera's FOV in Unity I get this kind of "linear" distortion, it's not like the dolly zoom effect or fisheye that distorts around in circular patterns, that's why squares become rectangulars and not "circles".
@@MrBluelightzero If it was just effectively shrinking the image down, then the squares would still be squares, but they deform into a rectangle when changing the FOV. I don't know what is under the hood of these game engines, maybe we are not setting only or directly the FOV, but my point is that changing the FOV is creating some kind of distorsion that I guess is somehow hidding the internal borders of the scopes. I don't deal with it in my game because I'm using a separate camera for the scope.
I think what's going on in Apex Legends is that the weapon viewmodel and the rest of the picture are rendered on separate cameras and the viewport camera is rendered on top of the other image. The two images and their field of view can be thus manipulated separately. When you aim down sights, the gameplay camera view is zoomed in a bit (FoV is made smaller) for the zoom effect and the scope effect is achieved by manipulating the fov of the viewport camera. It is zoomed in separately in order to get this flatter effect - kind of like changing the camera from perspective projection mode to isometric, but not quite. The point being that the more zoomed in the camera is, less perspective distortion is shown and thus the inside of the scope is not rendered. Honestly, I don't have any actual knowledge on this particular case and I have yet to test this theory in game engine, but this is what it looks like to me, it should be achievable technically without performance overhead and as far as I undestand, should result in something that we see here.
this is the most accurate solution for this problem, i use the same technique in my fps shooter game in Unity. this method is quite flexible and provides many options in terms of customizing the ADS View of the guns.
I think they are putting the camera way back and then zooming in. I tried doing this in blender using a single camera and the results do seem to indicate that being the case, but I don't know the nuance of how it might look with a background or how it might work in a game. Do try this though, if you read my comment. They also might be doing that just for the scope.
If you are far enough from the tube, you won't see the interior. I just tested it: Take a glass and put it parallel to your eyes. As it goes farther from you, it looks more like circle (at some point you don't see the interior, just the light at the end).
I think when you aim, the scope witches to 2 2d plaines on your screen with a hole in them that you look through. And since they're 2 2d plaines, you can simulate depth and perspective with them.
For Apex specifically there is a LOD for the scopes when aimed down sight that does "delete" part of the mesh to make the scope a little clearer. Though the part that remains is more than just the back ring of the scope, helping to provide the proper "perspective". Occasionally you can see the scope in apex de-render as you aim down sights which is how I stumbled across that specific information. It's an odd way of handling it but it does work.
I think they have a disk in the scope, like in the double camera system. However, it is a transparent disk. But it tells the rendering system to not render things in the gun which are behind it. I would expect that the disk is smoothly moved to the front of the sight when you de-scope, so that you get a smooth transition.
The inner moving scope parts when shooting in apex look like some kind of shader logic to me, I bet the front has a cut off shader or a cut off model and the inner part is just shader magic. It might also be possible to offset pixels to the front with shaders if I'm not mistaken.
What came to my mind (but is probably not the way anyone would do it), is that the diameter of the farther end of the scope increases, so it aligns with the new vision cone. But that seems super costly maybe not to implement but to build robustly
From an optical perspective, if you look down a scope, you don’t see the walls (you only do if the lens is not mounted in the right position for you which shows up as a black spot in your image), this is why there is a lens at the front and at the back, the lenses basically optically cut out the entire barrel of the scope and put your eyes’ natural focal point down range. In ascii art, this is what light does in a proper scope: >
If I'm not mistaken, apex still uses two camera's to render the gun and the environment separately to avoid clipping. If this is the case, then there's most likely a circular plane on the scope which is rendering a cut out portion of the environment camera to it (the size that the scope obscures). fun fact: this technique is also what Portals typically use to hide geometry that might fall between the second portals camera and the portal plane, Sebastian Lague covers this in his portal video. If they *don't* use two cameras, I'm clueless. I've never thought about the scope scaling thing but done right it would be unnoticeable, so you could be right there.
I've definitely seen some games introduce "cut off" planes when looking down the scope; mesh swap isn't uncommon either. Also, this might depend heavily on the renderer, but it should be possible in at least some to draw the scope image "focused at infinity" and thus make the walls parallel from the perspective of the player (kind of make it appear very far, but not alter the scale as you would normally do with perspective)
With the Vortex AMG UH-1 holographic sight, you don't get that tube effect. They accomplish this by making the objective lense larger than the optical lense. This makes the sight feel like a 2D plane instead of looking thru a tube.
I've noticed at least that in COD:MWR, the sniper scopes render an entirely different model which consists of mainly the rear ring of the scope, with some of the receiver and the adjustment dials also included. This is easily seen by entering the firing range, reloading, exiting right as you do and then re-entering the firing range and scoping in immediately
Insurgency sandstorm shrinks the model when aiming down unmagnified optics. You can see this most clearly when comparing the 1x and 2x red dot(unmagnified) where (when aiming) the unmagnified 2x red dot looks like you are looking through a toilet tube, whereas the 1x has a very nice field of view when aiming. This is due to the fact that the force perspective would not work on the 2x unmagnified optic. I'm not sure if this bug still exists but if you aim down sights with a 1x red dot and then push your rifle against a wall (so that your character points the gun upwards to avoid colliding with the wall) you can visibly see the deformed optic where the mesh has been shrunk.
There's a number of ways to get this to work: 1. Weapon and World are rendered separately, allowing the weapon to simply read from the texture containing the world and display it on the "lens". It's basically PIP, but only the gun has the extra cost attached. 2. In Deferred rendering with separate Z, you have the lens output an infinite depth as a solid/masked object in ADS mode. As the depth is behind what was previously on screen, you now have just the world where the lens used to be. Both of these date back to around 2012, and have been in use in some ways as far back as DirectX7.
3:42 Love how it shows the black part when shooting. With your simple method the scope always works different from real life where you only see well when looking from the right spot.
Some games they use textures that are viewable only in one direction, so from the outside you see the scope but when you zoom in the inside textures are invisible/see through
I saw you posted the solution to this in another video. Pulling the camera back and narrowing the field of view to effectively reach perspectiveless territory. Great work!
I also came across this problem, but one way that I think should work would be to move the camera far inside the scape just so you see a piece of the scope, downside is that you won't see the actual gun or the outside unzoomed view
One technique used for many games ils that all the character arms and weapons are rendered on a different layer, and then, added on top of the screen, kind of like the User Interface. Doing this allow you to change the camera perspective only for the character and weapons. So you can switch to a less perspective view for the weapons and ajust the player view at the same time but with less déformation. The 2 layer thing is also really usefull when you look at a wall and don't want your weapon to go through It.
The other BIG screw-up is that when using a red dot, you keep both eyes open and focus on the target (unlike when using iron sights). This effectively removes the entire red dot sight from your vision. Much like partially covering one eye with three fingers, your other eye fills in the blocked area. Red dot sights should appear as a faint, yet mostly transparent outline of the sight.
This is IRL. So one easy(?) fix would be to simply make the sight geometry transparent, and if anyone questions it you would know if they’ve ever shot a real gun before, and tell them to git gud scrub.
I believe the way Apex optics work is that it just makes the backfaces invisible. It looks pretty similar to Squad's optics where it hides the insides of the optics, but the zoom is just an increased FOV instead of a picture-in-picture. Another interesting thing that long-ranged optics have on Squad is that if you use the freelook key to look to the side while ADS'ing the scope, the scope picture shifts the further you look away until you can't see through the scope anymore. It's due to the parallax effect which is what also happens in real life scopes. You have to be directly looking through the scope to see through it.
Maybe there are 2 planes in the scope, one at the start, and one at the end. The game renders the view from the second plane, and projects it onto the first plane.
I've had this idea floating around my head for awhile, and it's this concept where you aim down your sight and all your surroundings all turn to black to better focus your aim essentially. You can see this machanic in CS:GO and TF2 and few other games I can't think of rights now, but this mechanic is mainly used for snipers.
That used to be the only way to do snipers on older games. Just zoom in the whole game and put a big black overlay so you could only see a circle. I remember being blown away by Crysis because I could aim down a telescopic sight and still have peripheral vision.
ADS works by making the ortho-graphic bi-lateral plane field trans-nodes renderer elves bend space time and compress the tri-angeloid vector expressions to make ADS sights zoom in. It’s that simple my dude!
I use shader projection in my games. Basically, using world position offset on vertices to achieve not only orthographic perspective on the gun, but to give the gun its entire own local fov. I then use pixel shader offsets to keep the guns from sticking through walls, but still exist physically infront of the players camera.
That’s really easy to explain; first person weapon models are almost always rendered in a separate overlay camera, specially because it solves the problem of having them digging through walls. In that context, you can freely adjust the overlay camera's field of view to be almost orthogonal regardless of the main camera's perspective, which would make anything the player is holding look shallow and depthless like they do when aiming down sights.
Playing Insurgency Sandstorm and while espectating (waiting for respawn), I found a guy aiming a rifle with a red dot sight who went too close to a wall, so weapon made the animation as holding the rifle up and I saw the red dot sight were shortened and looked warped, so I guess at least the technique used on Insurgency Sandstorm is warping the optics (I don't use picture in picture because of the performance lose).
one way to do it is to use clipping planes for the scope, an invisible plane which will limit what parts of the scope are rendered only for that single object, if its set up right you can also hide the front end of the gun when its seen through the same plane.
In some cases they just would use a depth cutout mask _(depth written invisible material at the same or lower render queue/order to cut out what's behind it, this is fiddly),_ or perhaps a stencil. I've made various scopes/optics in unity for vr. I always prefer the camera method, though optimally would be to build some kind of localized supersample & upscale method (extremely advanced) so you don't have to double render everything _(well sort of, in a lot of cases optimization methods by engines like unity and unreal should be able to instance things and re-render them in the other camera in the same pass preventing significant overhead)._
Blender has a feature where you can force the view of a model to be orthographic. Maybe they are somehow switching the scope models rendering to orthographic.
IRL scopes are tapered so that front lens is larger than the back (viewing) lens, thus minimizing the tunnel effect. They're not uniform diameter from front to back.
As an FPS developer, with lots of experience on this issue I can say you got it mostly right at 3:04 There are two versions of the weapon model, one for ADS and one for hipfire. The ADS version is a separate 3D model that mixes forced perspective + the back face of most of the polygons. That's why the front of the scope looks visible, there's still some polygons representing the front. They are just smaller and closer to the player's camera while ADS. I'd highly recommend looking at some of the 3D game files for Black Ops 3, which are easily accessible. They use the same method.
I suppose you could have a morphed view of the scope that exists only when aiming down sight. In a few it looked like there was a sudden change of how much of the inside of the scope was visible as you zoomed in.
Lowering the fov also helps a lot with the scope walls being visible from inside, just like you can see how in Apex it gets lowered a lot Also orthographic projection is basically just fov at 0°
Orthographic projection is not zero degree FOV, that would mean that you're zoomed into an infinitely small point (i.e. smaller FOV = more zoom). Orthographic projection is when the "camera" stops being a tiny plane through which the scene projects into a focal point, and it instead becomes a large plane that the scene is projected onto with one uniform vector. In raytracing this would be the screen as a plane floating around the scene and rays traced straight from each point on the plane into the scene in one uniform direction - the rays are parallel. In perspective projection the rays "converge" through a point behind the projection rectangle. The difference is very distinct.
I think a key aspect of it is that the weapon isn't drawn in the same render layer as the rest of the scene. What I think happens is the scene layer zooms in alot. Perhaps so much that the weapon itself would no longer fit on the screen. The camera is then also pulled back only in the weapons render layer to basically shrink the weapons screen size. The effect is that you get a much more ortogonal projection which makes the front and back of the scope more similar in size. Without blowing the weapon way out of proportion on the screen.
You forgot about the 3rd and cheapest way ever: CS 1.6 style, where you zoom in and put an overlay on top of you screen and stop rendering the gun... Or even the Black Mesa crowbar "sprite scope" that is not only cheap af as it looks awful. Anyway, ways that scope you showed could be done: almost orthographic camera rendering the gun; stop rendering the part of the interior of the tube and maybe add some flat surface with a paralax effect; refracting material shader (it might be possible, and maybe cheaper than Pic in Pic, depending on the engine you're using); and maybe changing the FOV of the viewmodel when you're aiming downsights. Also this is also a tricky thing: using pic in pic, you can make the scope camera with a slightly smaller FOV, so you zoom and looses some perspective feelings, getting an almost flat 2D image (like real-life scopes). Add this with some vignette and some dirty decals and call it Realism.
Feels like backface culling everything aside from a small section on the inner diameter of the scope would be a quick way to achieve the right effect there.
@Garbaj In Apex you can clearly see the camera changing focal length. (hence why the scope appears to shrink in length). You can see it in 2:44 where the part above the scope isn't visible (obscured) and then it suddenly transitions to becoming visible. Basically, The weapon camera zooms in and then zooms out while transitioning to a lower field of view (increasing focal length). You can search for the vertigo effect (dolly zoom). R6 simply makes the interior gone so that you can see through the backface culled outside.
As others have already commented, the solution is almost certainly to use a separate render layer for the weapon viewmodel. You could even render the scope and weapon in different passes. One thing that I noticed while watching the footage, is that, in the case of apex legends, the barrel of the gun would also intrude on the sight if it was rendered in worldspace, but it is obviously not visible through the scope. You could achieve this by changing the projection, or simply by using a layer mask in post-processing. There are always a variety of solutions to any given problem, and my guess is that different games use different solutions to achieve this same effect. As for performance impact, picture-in-picture has obvious drawbacks, and also looks bad if the sight takes up only a small part of the screen. As for the other techniques, the performance impact of having a separate render pass for the viewmodel should be minimal. Altering the mesh could maybe save a tiny bit of overhead, and could accomplished using the same transformations as altering the viewmodel camera's projection matrices, but at that point you have to contend with other limitations, either with in-place vertex manip with a compute shader (not fun) or moving meshes to and from video memory. I favour the separate render layer with a post-processing mask, because I think that's the easiest solution, but I like the elegance of the suggestion to change the projection of the viewmodel camera.
There's a few things that could be going on here (aside from some of the pointed out details by other comments about the geometry/material fade out). 1)Many first person shooters use a different camera matrix to render the weapon. This is why the gun doesn't distort or move with fov changes because it's actually being rendered at a different fov despite being geometrically represented within the scene (which is different from other common tricks like rendering a tiny gun close to the camera). In unity people often try to do this with layered cameras, but I think the effective way is to have a shader specific to the weapons that does reprojection on the other matrix. This being the case, you can actually flatten the weapon camera out towards an orthographic projection when ADSing, and I would argue Apex kinda has the look of doing that. 2)It actually is PiP, but they're using masking to save a bunch of extra drawing. This is similar to how Portal renders it's portals without incurring double the draw time. I'm kind of confused by games that have huge PiP framerate issues because it's relatively easy to make performant portals (in Unity in my case) using masking. 3)As others have pointed out, there's sometimes some kind of fade out happening, but I don't think they're necessarily hiding the geometry. It's possible that they have a shader with some kind of depth priority/fading that they ramp up when ADSing, and this can be smoothed by camera distance along a gradient.
I would make a screen partway down the scope, similar to the picture-in-picture solution. On that screen, I would apply some kind of shader that could warp or distort the geometry of the gun model behind the screen, but not anything else. Perhaps some kind of fish-eye-lens effect would work. I would include some kind of variable to change the refraction level of said shader, and tie that variable to the state the gun is in. If the player isn't using the sight, 0% refraction. If the player is using the scope, 100% refraction. Add a lerp between 0 and 100%, as the player moves the scope in front of their face, and back again. This would allow the inside of the scope to be visible when not in use, but shrink back when it is in use.
My theory for apex legends style zooming is this: when you put ur eye closer to a metal tube, there are is more obstructions other than the openings, but if you push it away from you and still look intk it, the obstructions shrink, so i think that apex does this same think except just zooms it in
The method you are looking for is a combination of things you noticed and another technique. You still zoom in/lower the FOV to get a better picture but to get that clear cutout image you also use a flat piece of Geo in the scope. Actually two of them with two different shaders. One to cut out the scope with a shader using Stencil buffer. The other to re-render what's behind that cutout with a scene_texture projection onto the other Geo. Then you enable/disable those mesh objects when you aim and go to hip. scene_texture Renders what's behind an object on the screen so that's why the cutout is necessary to clear the area it will render. Depending on how the renderer works and if you want to do other effects like blurring the background and keeping the scope area clear, you might have to use a separate render layer for the scopes/optics and the inner meshes as well. This is why if you look at those games when they aim in slow motion you can see when those mesh pieces get activated and deactivated. Someone pointed out the timestamps for R6: Siege clips but the game you can see this the clearest in is Warzone with the sniper scopes. Also since the scene_texture shader call is actually rendering to the same amount of pixels on your screen you can't zoom in inside the shader or else it will be pixelated. This is why you have to change the camera's FOV to get your zoom amount. This is how you can tell which method is picture in picture and which is the stencil buffer cutout/Scene_Texture method in different games.
I solved this in a game of mine by going with the multiple scope model route. When the player zooms I swap out the scope model to one that is more visually pleasing to look through. I had a technical limitation where I could not use a secondary camera to render the gun with a different projection. Worked quite well though. Users cant tell.
Elegant solution: outer circle just should be bigger. Like in weird optical illusions, where far placed greater object appears to be same size, as smaller object nearby.
literally as you ask the question you can see the aug scope doing what I guess. doing the exact same thing as picture in picture but with no zoom. just flat image of whats on the otherside but without different zoom levels.
I'm sure there's many ways to try and implement this, but one way would be: 1) render the gun in a second pass, 2) add a small circular mesh (could even be a quad with a circular texture) to the sight that you want to clear out, 3) use the depth buffer to block out the region from the mesh in (2) to not render the gun. This would allow you to open up the sights and not affect other rendered objects in the scene. It would also be fast, since it's all done in a shader using the depth buffer. Also the mesh/texture from (2) is animatable so it can grow and shrink as you bring the gun up and down, making the effect very smooth.
in many shooter games, they make a global render who everyone sees, but they make a local render that is separated from the model and displayed only for the main player, so when looking at the HUD and everything, you are seeing a bunch of "sprays" that give the look of 3D, so when you aim they stop rendering the gun and then transitions to use a separated spray of the sight that you are using, it's a world illumination-interactive png of a fake sight
The weapon is most likely being rendered with a different camera for First Person anyway, so they could just be grabbing the color from the camera without the weapon and putting in on a disk into the scope (like with the PiP mode), just a few cm inside the scope, so a little bit is still visible.
Gun layer rendered seperately to the 3rd person player model. Camera on gun moves back significantly and over to center and most importantly narrows the FOV as much as possible
There is 3 ways to do it that keeps the inside of the tube still visible, like in Apex or R6. 1) The FOV gets narrower when aiming, lessening the effect of seeing the other end of the scope that much smaller. This is the case in Apex. 2) The other end of the scopes internal tube is slightly wider inside of the far side. Not that common, though. 3) The inside of the scope is partially hidden. R6 does this and the FOV trick.
In Insurgency: Sandstorm the front of the scope is cut off while in ads, you can sometimes see it on the security red dot if you have a minor performance drop/stutter while exiting ads.
Even with all the research you do there are still some questions you may struggle to answer. That's why all the work you put into this channel is amazing. Your helping everyone else learn by giving them an easy source of useful information. This way the next "you" who comes along looking for answers has another place to find what they seek.
My solution to this would be having two cameras (one for everything except the gun, and the other rendering just the gun) as you said in the video on how to get rid of weapon clipping. In that way, you can lower the fov on the main camera and give the weapon camera an ortographic perspective (or you could just also lower the fov until you don't see the end of the scope). Love your vids btw :D
Former Insurgency Sandstorm dev here who did a bit of optic work, how we solved the problems of optics perspective when not using PiP, was similar to how you suggested it worked, except instead of not rendering certain portions of the optic, we just scale down the forward axis so it's "flat". We also smoothly interpolated it so it didn't go flat immediately.
Yo ! You are everywhere, man :3
Just to add on this:
This was how non-magnified optics were done (most notable on Aimpoint M4) in Sandstorm.
For magnified optics, a stencil mask was used (done by Robin M back in the day), still have PTSD from testing all the glove cosmetic mats that had to be flagged each time lol.
And a bonus point: These methods could not be combined so flippable magnified sights suffer from perspective driven rendering when the magnifier was flipped off to a side.
But.. what if another player sees ur gun being scaled down ?
@@BossKillRatio in the vast majority of games the first person weapon view is completely different from the third person renderings of seperate players. Pretty much the only game I can think of that's not like this is Tarkov, and I'm pretty sure Garbaj even made a video specifically talking about how this was the case in Insurgency.
@@BossKillRatio First person gun mesh and third person gun mesh are two different meshes.
I also noticed that you guys made the AI frequently instantly kill me specifically as opposed to other players. I suppose this was due to how well I did in coop in the first game, you guys wanted to ensure I didn't over dominate in coop.
For r6 siege atleast, if you go frame by frame you would notice the inside of the scope going transparent when transitioning to ADS. Around the frames of 1:04 and 1:05, you can see the full depth at the first frames when scoping in. Then when the screen zooms, the rest of the scope becomes transparent except the sides facing the character(with the 2 extrusion still being opaque and can be seen through the scope).
Good catch!
Yes! You can see the sides of the scope, but halfway, they just vanish! They definitely stop rendering the sides of the scope for the unobstructed view down the tube.
Very observant!
That was my first thought too, and would probably be the first thing I'd try when tasked with implementing this. It's very cool that you can see it in action here.
I hadn't noticed that, good eye!
I saw that too when I was going frame-by-frame at that timestamp, but when he showed the Apex ADS, there was no trickery that could be seen (as blatant as R6) in the scope. So I'm not sure about his question. Maybe it does the same thing, but cleaner? Not sure.
Never really thought about the depth of the scope, good point.
The inner walls could be transparent.
Blender planes do this thing sometimes and they could use that along with a picture to simulate the appearance of the inner scope margins
its called flipped normals btw :)
No; if that were the case, the entire inner wall would be invisible. And in the games you can see the shortened inner walls. Do you know what you're sayin. or maybe you didn't word it correctly
@@slugintub I think he means the visible inner walls are an overlay not the actual scope but then it’s 3D and I think replacing the scope within a 3D overlay would result in some issues I’m just not very knowledgeable here so I don’t know
@@HateHater2205 this. also the scope overlay could be made invisible when not seen so you don't get into as many problems
@@ceasnov oh alright then I think you have the best explanation
Something to keep in mind is that only magnified optics should work this way. In non-magnified optics such as a red dot or holographic sight, you *should* be able to see the inside walls of the tube, because that's all it is. A tube with flat glass panes on either side.
true though 1x optics generally don't have tubes that long to notice them shrinking due to perspective much
When you use red dots and holos properly (With both eyes open) you don't actually see the sight housing or "tube." Games only show the optic housing for balancing reasons.
ive used a tube red dot before, videogames are over the top. It looks just like apex legends
And if the tube is long on a red dot it will still use 2 identical lenses inverted to eachother bending the light around the inside of the tube makeing it invisable to you and keeping the image the same size.
@@themilkman8554 I've never seen a game that uses binocular vision so...
I am completely inept in coding. So all this info just goes over my head. I just watch because I like hearing your voice.
same here, glad i’m not the only one
Doesn't really have anything to do with coding but it's still very technical.
Kinda similar for me with Ahoy
Same bro
None of this was directly related to coding tho...?
Hey Garbaj !
This has been a mystery for me for quite a long time too, but recently I was able to reproduce this effect by using an almost orthographic camera for the weapon. Basically everything but the weapon is rendered on one camera, and the weapon/arms etc. are rendered on a different camera, which, when aiming down sights, interpolates its projection to a near-orthographic one. It's like an ~90% interpolation between perspective and orthographic, because fully orthographic didn't look good imo.
Idk if that's what all these games are doing, but it definitely works for me.
Anyways, nice video as always, cheers !
If you needed to use two cameras anyway games wouldnt warn you when switching to pic in pic mode
@@marly1017 no, rendering objects twice and rendering objects separately are completely different things.
@@marly1017 cameras and picture in picture are different, rendering on two cameras doesnt mean you have to render the entire scene twice, because each camera has different parts of the image on it
This very much sounds like the answer. Rendering the weapon in a different camera is done for other reasons as well, even though I don't quite remember what it was... 🤔
@@marly1017 what Froge said. PiP is slow because it renders the entire scene twice. This method renders nothing twice.
I've worked on a few games where we've actually used a similar concept to get better looking magnified scopes. The concept is basically having two models for the scope; one that is the entire thing and one that is essentially cut in half in different places. The latter model is swapped in at a moment when player's can barely notice it and as the front half of it doesn't exist anymore it gives the effect of the far side being the same size as the closer side. In your clips I believe this is seen in R6S & PUBG, while I'm fairly certain that SQUAD also uses a similar concept; when ADS-ing you can see a moment where the scope sort of "flickers". They also employ a simulated "eye relief" look, where there seems to be a dark ring that moves around in the scope to simulate you looking outside the magnified lens.
One thing to note however is that I don't think AL uses this system because you can clearly see the inner side of the scope. What I suspect is that since AL renders the gun on a different layer they might actually have the gun having a significantly lower FOV than your main render layer, making the difference in the openings seem less significant. As going lower and lower FOV gives you a "half-orthographic" view I would assume that's their method.
Finally, I should mention I'm only a 3D artist and not a coder. While I am learning coding in university and I do understand coding concepts, I don't know the code that goes behind this. This is just my best educated guess based on different games that I've worked on. I hope that this explanation gives you a basic understanding at least of how this all works, and I'd be happy to answer any more questions you might have :D
came looking for this comment. I was about to comment the same
@@mrtaufner yeah me too
The answer: stencil shaders. They can be used to mask certain parts of the weapon & scope when ADS. Greetings from Ireland 🇮🇪
I was already wondering why nobody else mentioned it. Though, not the only possible answer, as a separate, smaller FOV for rendering only the gun also works sorta.
@@lubbdaa True, but for performance reasons, I certainly wouldn't recommend using the render texture approach on mobile devices.
Top of the morning to ya!
@@mastershooter64 We don't say that here 😂
@@bioburden _damnnn youuu jacksepticeye!!!_ lol is it really that uncommon in ireland? was it more common in the past?
This might be surprisingly simple, you could just use the 3D scene rendered into a texture and re-render it on your first-person gun models. In Godot, you can access rendered screen with SCREEN_TEXTURE texture and SCREEN_UV texture coordinates in fragment shaders. You can write a custom shader that samples that texture and put that shader on the front lens so it appears as if you're looking though the scope. You can scale SCREEN_UV appropriately so that it samples from a smaller area and that way you get magnification, albeit with with blur. I suppose there are ways to fix the blur, for example by supersampling, but I have yet to experiment on that.
This is pretty much exactly what we did, albeit in Unity. We also make use of the stencil buffer to render a plane with a crosshair on it behind the scope to create a parallax effect for the crosshair when looking through the scope.
This effect is pretty easy to do using a render texture in Unity as well.
So this is basically described in the video PIP method
On the solution with making the tube shorter, no, you would never notice (if done correctly). I think it's actually a pretty good idea. Something else that could be the case has something to do with draw priority (if that's the correct word???). For example, if you clip inside a wall, you can see through the other side, that's because most games check if a polygon is facing you, and if it is, it is rendered, and if it isn't, it isn't, same with wether a polygon is obscured or not. This saves resources and is honestly not that expensive to implement. A gimmick you can introduce with this procedure is that certain objects can look bigger (or smaller if you'd really like) on the inside. When you look through the scope, a different scope model can be rendered that would realistically not fit as an inside of a scope, but due to forced perspective, you wouldn't be able to tell the difference. The inside scope could be slanted where the forward lens is bigger than the lens closest to your face, in such a way that it appears you are looking parallel to the walls of the tube.
This is what I thought too. Great minds think alike ^w^
These are called "Normals" as they are defined by the vectors vertically on the face of the polygons.
Witch are called Normal Vector.
And they define orientation and direction of the plane.
And thus they are rather easy to implement.
It is just a check wether or not you are more than 180° out of direction of the vector and thus look opposing to it. Then it will be rendered.
This leads to 2 different scope models, where the only difference is the inner part of the scope.
On one a cone with the tip on the camera.
On the other a more or less straight Tube.
@@theonly5001 huh, never thought about normal vectors. Pretty obvious actually
@@theonly5001 I think it just hides the inner walls of the scope when you use it (go frame by frame from 1:04 to see the moment the game makes hides those faces). As for the slight perspective of the walls, maybe it only makes the walls transparent except for a sliver at the front
@@vibaj16 that is certainly a option.
However you can do this option as well.
4:01 look at the transition from scoped to no scope, it looks like the inside material of the scope becomes transparent on the inside because as it transitions from the narrow to wide, you start to see the inside, of the outside wall of the scope. There is one frame where it looks like part of the tube has transitioned from transparent to opaque
Ironic for him to have put this clip over him saying "What am I missing?"
Yeah I think even the outside walls become mostly invisible when looked at from inside in this instance. So you can only see the scope from the outside, while it's transparent when looked at from inside.
Game dev here.
-Some games just have 2 cameras, one of them renders the game, and the other renders the weapons of the user, so when you aim down sights, the camera that renders the weapons and arms of the character changes to cartographic while the other stays normal. I think you had visited before the 2 camera thing (not picture in picture but separated render for player body and environment) and talked about how the two could have a different FOV.
-Others are using lerp between two meshes. When you start aiming, the front of the scope opens and becomes wider so that it has a conic shape instead of a cylindrical one (or whatever the scope's shape is)
-Some games have chosen to throw in your face a flat sprite representing the whole gun with attachments and everything and zoom in without picture in picture (picture in picture/camera and render texture being the best possible way of making a scope)
There's another very common trick that is used to do picture in picture without performance hit, which is a neat shader that literally magnifies the image behind the lens without rendering another camera. It makes the image look worse as the zoom level increases, but for scopes up to like 4x zoom, the performance outweighs that for things like VR games.
Smort
Cones
This is exactly what I was gonna say lol
it's ORTHOgraphic, not cartographic =D
but yeah
My immediate thought was given that the weapon generally has it's own camera responsible for rendering it (so it doesn't clip through walls etc.), that all it does is widening the fov of that weapon cam, making it nearly orthographic. That's it. You don't actually need camera on the scope either, just take the image the main camera sees (since it can't see the weapon) and blow it up in the middle.
A weird but very cool effect to see is semi-transperancy on scopes. When you use an optic in real life you have two eyes, and only one of those is recieving a zoomed in perspective. With both eyes open, you effectively can swap your focus between them, which has the effect of making your scope (the perimeter of it, not the zoomed image) essentially transparent. Stalker anomaly does a decent job of replicating this (as well as you can on a 2d screen)
I love how in VR this i basically just the nature of having two eyes. I didn't even know that some flat games have this (or a version similar to the effect)
One of the best ways to achieve the effect is with a Stencil Mask. When you have your FP visuals rendered on their own layer, it's very easy to add a stencil mask in the scope to block anything on your FP layer from being rendered there. An added benefit to doing it this way instead of just hiding the back half of the scope mesh, is you also won't see anything through the scope that you shouldn't be able to see, such as the front of your gun, or your characters hands if the optic is really huge on screen. You'll only see the world through the scope. Plus, it means you don't have to build your meshes in a way that they can be partially toggled on / off.
I should add that with a stencil you can also do the opposite and make it so your scope reticle & effects are only visible through the lens of the scope. So you block your first person meshes from being seen through the lens, and allow your reticle to be seen through the lens simultaneously.
@Jordan Rodrigues culling the back faces doesn’t work for this. Scopes often have things on them like dials, as well as having a wider far end. Simply culling the back faces wouldn’t prevent you from seeing a bunch of the front faces further down the scope. Not to mention you would see the weapon itself through the scope.
Using a stencil ensures you don’t see anything through the scope that you shouldn’t see, and doesn’t require manually toggling meshes on and off which creates visual pops.
Just a question.can i use stencil layers to separate the weapon mesh from the world and make it render above the world so i can avoid weapon clipping into the wall 🧱??
I feel like a scoped image should just render those pixels that are going to be visible scoped.
But I believe the gun scopes are simply thinner at the close part that you poke you're character eye through, than the far end. So it isn't a tube, but rather a cone with 2 holes, smaller end closer to the camera.
It might be something closer to it rendering at area a bit bigger than the scope. If you only render an area the same size as the field of view the scope provides (pretty tiny), then unless your machine is super fast, you will get pop-in if you were to move too quickly. Speaking of pop-in, if your scope only renders the small field of view seen, how would you go about rendering a big model caught in the scope? Consider something like a large statue - if you scope it on it's head, you would have to render the whole model anyway. I think for these reasons it is quite complicated (and less practical) to design such a precise system for rending picture-in-picture scopes.
Some games, like Apex Legends use a separate model that swaps out when aiming. Older Call of Duty titles like infinite warfare and modern warfare remastered do this with magnified optics. Insurgency sandstorm uses a cull layer on the optic lens that removes the insides of magnified scopes when using the "Normal" scope setting.
When you wrote older Call of Duty I imagined you meant Call of Duty 4 or something, not games from 5 years ago
@@Critical_Hit modern warfare teamstered is CoD4... But yeah I feel you
In some older games like Call Of Duty: 4, the game completely took out everything apart from the area you can see with the scope, or they blurred it out which can be a very easy way of overcoming the problem.
It could be that Inside the scope it's shaped like an opening cone, as if you cut the bottom off an ice-cream cone and looked through it
This is only effective to an extent because at one point it starts affecting how the outside of the scope looks as well because you have to keep making it wider for longer scopes
@@andersonrobotics5608 well it could be that the front of the model de renders for the user and the cone may be alot steeper and not just a gradual expansion
@@capofantasma97 then I'm not sure it was just a guess
I don't usually watch too many graphical-technical things like this, but it does interest me. Maybe its your cadence but i've watched two and genuinely enjoy and learn from this because it is clear that you are coming at it the same way we are: figuring it out as you go along and explaining to us the ins and outs so the layman and interested person could understand in depth. Subscribed.
I do know in my real closed-emitter 1x20mm red dot sights, like my Sig Romeo 5 and Bushnell TRS-25, you don't really see the inner walls of the sight. It's too short to really cause that effect, plus it helps to mount the sight as far forward on the AR's receiver as you can, so you get less vision obstruction. You mostly just see the back end of the sight's body. With games, you can totally just ignore it. For longer-tubed optics like an LPVO, it's a magnified sight that's just set to 1x zoom. So even though there's no magnification, you still don't see the inside of the tube. (The Trijicon MRO is a piece of garbage because of this effect going wrong, it screws with the focus of your eyes and it's actually slightly zoomed in, which distorts the image and looks wonky.)
Scope squashing up as it zooms in works really well. That's how we do it in the game we are making. Certain elements of the scope squash and flatten during the ADS. It is a bit of work, but is fairly convincing and works nicely. Benefit of using this technique is performance impact is minimal and you still get all the lighting and texture details showing on the scope body, even if it is squashed up.
maybe the inside of the tube is cone shaped.
Its really interesting how you make videos. Other game dev videos would just explain how they did it, whilst you explain the options and problems which gives me value even to the audiance even though you didn't kinda used it.
4:01 - Increment the frames slowly as he's scoping in- you can _see_ the rendering turn off for the parts of the scope not facing the back.
I'm a game dev with FPS experience (though we didn't use this approach). You could do it with two cameras. A Hip Camera which renders with perspective, and an ADS Camera renders only the optic in orthographic.
Usually the first person objects are being rendered separately from the rest of the screen. If they were not, then when you walk into a wall you'd see your weapon clip through the wall. So try walking into a wall, if the gun doesn't pass through the geometry, then the weapon is being rendered separately.
With them being rendered separately, it is a small task to have the main camera change the FOV to zoom in while the gun's renderer instead warps to flatten out the image.
also, if you are rendering the first person weapon separately it becomes easier to perform perspective and placement tricks so that a gun can be pointed a different way than you are actually aiming.
This is the answer
I think this is just a "side effect" of changing the camera's FOV itself... I noticed that when zooming too much the closer objects to the camera get significantly shorter, sometimes the FOV can even deform square tiles on the wall making them into rectangles, so I guess this is masking the scope's internal surface by distorting it shorter!!
@@MrBluelightzero It doesn't change perspective lines, it just shrinks things along them in order to fit on screen, making them appear shorter. When I change camera's FOV in Unity I get this kind of "linear" distortion, it's not like the dolly zoom effect or fisheye that distorts around in circular patterns, that's why squares become rectangulars and not "circles".
@@MrBluelightzero I replied before you edited it, but I still don't get you point though...
@@MrBluelightzero If it was just effectively shrinking the image down, then the squares would still be squares, but they deform into a rectangle when changing the FOV. I don't know what is under the hood of these game engines, maybe we are not setting only or directly the FOV, but my point is that changing the FOV is creating some kind of distorsion that I guess is somehow hidding the internal borders of the scopes. I don't deal with it in my game because I'm using a separate camera for the scope.
I think what's going on in Apex Legends is that the weapon viewmodel and the rest of the picture are rendered on separate cameras and the viewport camera is rendered on top of the other image. The two images and their field of view can be thus manipulated separately. When you aim down sights, the gameplay camera view is zoomed in a bit (FoV is made smaller) for the zoom effect and the scope effect is achieved by manipulating the fov of the viewport camera. It is zoomed in separately in order to get this flatter effect - kind of like changing the camera from perspective projection mode to isometric, but not quite. The point being that the more zoomed in the camera is, less perspective distortion is shown and thus the inside of the scope is not rendered.
Honestly, I don't have any actual knowledge on this particular case and I have yet to test this theory in game engine, but this is what it looks like to me, it should be achievable technically without performance overhead and as far as I undestand, should result in something that we see here.
this is the most accurate solution for this problem, i use the same technique in my fps shooter game in Unity. this method is quite flexible and provides many options in terms of customizing the ADS View of the guns.
@@purnabratakar7176 Cool to hear that you've actually put this in to practice! Thanks for your insight!
I think they are putting the camera way back and then zooming in. I tried doing this in blender using a single camera and the results do seem to indicate that being the case, but I don't know the nuance of how it might look with a background or how it might work in a game. Do try this though, if you read my comment.
They also might be doing that just for the scope.
If you are far enough from the tube, you won't see the interior. I just tested it: Take a glass and put it parallel to your eyes. As it goes farther from you, it looks more like circle (at some point you don't see the interior, just the light at the end).
I think when you aim, the scope witches to 2 2d plaines on your screen with a hole in them that you look through. And since they're 2 2d plaines, you can simulate depth and perspective with them.
Yeah, thats likely. But they're affected by light! I've never seen a game or engine where UI elements can be affected by light in the scene
@@SolaFideSolusChristus266 The scope elements could be in-scene sprites instead of UI elements with yet another layer on top for light-simulations
@@Ibuildstuff832 True
As someone who's been a shooter for 2/3 of his life, I can say videogame optics drive me insane on the regular
For Apex specifically there is a LOD for the scopes when aimed down sight that does "delete" part of the mesh to make the scope a little clearer. Though the part that remains is more than just the back ring of the scope, helping to provide the proper "perspective". Occasionally you can see the scope in apex de-render as you aim down sights which is how I stumbled across that specific information. It's an odd way of handling it but it does work.
I think they have a disk in the scope, like in the double camera system. However, it is a transparent disk. But it tells the rendering system to not render things in the gun which are behind it. I would expect that the disk is smoothly moved to the front of the sight when you de-scope, so that you get a smooth transition.
The inner moving scope parts when shooting in apex look like some kind of shader logic to me, I bet the front has a cut off shader or a cut off model and the inner part is just shader magic. It might also be possible to offset pixels to the front with shaders if I'm not mistaken.
What came to my mind (but is probably not the way anyone would do it), is that the diameter of the farther end of the scope increases, so it aligns with the new vision cone.
But that seems super costly maybe not to implement but to build robustly
From an optical perspective, if you look down a scope, you don’t see the walls (you only do if the lens is not mounted in the right position for you which shows up as a black spot in your image), this is why there is a lens at the front and at the back, the lenses basically optically cut out the entire barrel of the scope and put your eyes’ natural focal point down range. In ascii art, this is what light does in a proper scope: >
If I'm not mistaken, apex still uses two camera's to render the gun and the environment separately to avoid clipping. If this is the case, then there's most likely a circular plane on the scope which is rendering a cut out portion of the environment camera to it (the size that the scope obscures). fun fact: this technique is also what Portals typically use to hide geometry that might fall between the second portals camera and the portal plane, Sebastian Lague covers this in his portal video. If they *don't* use two cameras, I'm clueless. I've never thought about the scope scaling thing but done right it would be unnoticeable, so you could be right there.
bargy
I've definitely seen some games introduce "cut off" planes when looking down the scope; mesh swap isn't uncommon either.
Also, this might depend heavily on the renderer, but it should be possible in at least some to draw the scope image "focused at infinity" and thus make the walls parallel from the perspective of the player (kind of make it appear very far, but not alter the scale as you would normally do with perspective)
Lmao
Agreed
With the Vortex AMG UH-1 holographic sight, you don't get that tube effect. They accomplish this by making the objective lense larger than the optical lense. This makes the sight feel like a 2D plane instead of looking thru a tube.
I've noticed at least that in COD:MWR, the sniper scopes render an entirely different model which consists of mainly the rear ring of the scope, with some of the receiver and the adjustment dials also included. This is easily seen by entering the firing range, reloading, exiting right as you do and then re-entering the firing range and scoping in immediately
bydgoszcz
+1
I have no idea how I'm 1st
what makes no sense is that I’m second
@@ributoshithedragon9647 lol 🤣
Insurgency sandstorm shrinks the model when aiming down unmagnified optics.
You can see this most clearly when comparing the 1x and 2x red dot(unmagnified) where (when aiming) the unmagnified 2x red dot looks like you are looking through a toilet tube, whereas the 1x has a very nice field of view when aiming. This is due to the fact that the force perspective would not work on the 2x unmagnified optic.
I'm not sure if this bug still exists but if you aim down sights with a 1x red dot and then push your rifle against a wall (so that your character points the gun upwards to avoid colliding with the wall) you can visibly see the deformed optic where the mesh has been shrunk.
There's a number of ways to get this to work:
1. Weapon and World are rendered separately, allowing the weapon to simply read from the texture containing the world and display it on the "lens". It's basically PIP, but only the gun has the extra cost attached.
2. In Deferred rendering with separate Z, you have the lens output an infinite depth as a solid/masked object in ADS mode. As the depth is behind what was previously on screen, you now have just the world where the lens used to be.
Both of these date back to around 2012, and have been in use in some ways as far back as DirectX7.
3:42 Love how it shows the black part when shooting. With your simple method the scope always works different from real life where you only see well when looking from the right spot.
what game is the one u tagged?
@@theXeNoNxX I dont know. Based on the map it might be pubg. Havent played for a while though.
Some games they use textures that are viewable only in one direction, so from the outside you see the scope but when you zoom in the inside textures are invisible/see through
They may just not render the inner wall of the scope so your vision just goes through it
I saw you posted the solution to this in another video. Pulling the camera back and narrowing the field of view to effectively reach perspectiveless territory. Great work!
Upon ADS-ing the farther end of the scope might be expand to account for the problem
I also came across this problem, but one way that I think should work would be to move the camera far inside the scape just so you see a piece of the scope, downside is that you won't see the actual gun or the outside unzoomed view
One technique used for many games ils that all the character arms and weapons are rendered on a different layer, and then, added on top of the screen, kind of like the User Interface. Doing this allow you to change the camera perspective only for the character and weapons. So you can switch to a less perspective view for the weapons and ajust the player view at the same time but with less déformation.
The 2 layer thing is also really usefull when you look at a wall and don't want your weapon to go through It.
The other BIG screw-up is that when using a red dot, you keep both eyes open and focus on the target (unlike when using iron sights). This effectively removes the entire red dot sight from your vision.
Much like partially covering one eye with three fingers, your other eye fills in the blocked area.
Red dot sights should appear as a faint, yet mostly transparent outline of the sight.
This is IRL. So one easy(?) fix would be to simply make the sight geometry transparent, and if anyone questions it you would know if they’ve ever shot a real gun before, and tell them to git gud scrub.
I believe the way Apex optics work is that it just makes the backfaces invisible. It looks pretty similar to Squad's optics where it hides the insides of the optics, but the zoom is just an increased FOV instead of a picture-in-picture.
Another interesting thing that long-ranged optics have on Squad is that if you use the freelook key to look to the side while ADS'ing the scope, the scope picture shifts the further you look away until you can't see through the scope anymore. It's due to the parallax effect which is what also happens in real life scopes. You have to be directly looking through the scope to see through it.
Maybe there are 2 planes in the scope, one at the start, and one at the end. The game renders the view from the second plane, and projects it onto the first plane.
I've had this idea floating around my head for awhile, and it's this concept where you aim down your sight and all your surroundings all turn to black to better focus your aim essentially. You can see this machanic in CS:GO and TF2 and few other games I can't think of rights now, but this mechanic is mainly used for snipers.
That used to be the only way to do snipers on older games. Just zoom in the whole game and put a big black overlay so you could only see a circle.
I remember being blown away by Crysis because I could aim down a telescopic sight and still have peripheral vision.
ADS works by making the ortho-graphic bi-lateral plane field trans-nodes renderer elves bend space time and compress the tri-angeloid vector expressions to make ADS sights zoom in. It’s that simple my dude!
I use shader projection in my games. Basically, using world position offset on vertices to achieve not only orthographic perspective on the gun, but to give the gun its entire own local fov.
I then use pixel shader offsets to keep the guns from sticking through walls, but still exist physically infront of the players camera.
That’s really easy to explain; first person weapon models are almost always rendered in a separate overlay camera, specially because it solves the problem of having them digging through walls. In that context, you can freely adjust the overlay camera's field of view to be almost orthogonal regardless of the main camera's perspective, which would make anything the player is holding look shallow and depthless like they do when aiming down sights.
Playing Insurgency Sandstorm and while espectating (waiting for respawn), I found a guy aiming a rifle with a red dot sight who went too close to a wall, so weapon made the animation as holding the rifle up and I saw the red dot sight were shortened and looked warped, so I guess at least the technique used on Insurgency Sandstorm is warping the optics (I don't use picture in picture because of the performance lose).
one way to do it is to use clipping planes for the scope, an invisible plane which will limit what parts of the scope are rendered only for that single object, if its set up right you can also hide the front end of the gun when its seen through the same plane.
The picture-in-picture idea explains Halo's sniper rifle scope very well as a side effect!
They might have a another camera that's renders over the scope and is pushed forward to pass the actual site
In some cases they just would use a depth cutout mask _(depth written invisible material at the same or lower render queue/order to cut out what's behind it, this is fiddly),_ or perhaps a stencil. I've made various scopes/optics in unity for vr. I always prefer the camera method, though optimally would be to build some kind of localized supersample & upscale method (extremely advanced) so you don't have to double render everything _(well sort of, in a lot of cases optimization methods by engines like unity and unreal should be able to instance things and re-render them in the other camera in the same pass preventing significant overhead)._
Blender has a feature where you can force the view of a model to be orthographic. Maybe they are somehow switching the scope models rendering to orthographic.
you can make the material one sided, the inside of the tube will be transparent but the outside will still be rendered
IRL scopes are tapered so that front lens is larger than the back (viewing) lens, thus minimizing the tunnel effect. They're not uniform diameter from front to back.
As an FPS developer, with lots of experience on this issue I can say you got it mostly right at 3:04
There are two versions of the weapon model, one for ADS and one for hipfire.
The ADS version is a separate 3D model that mixes forced perspective + the back face of most of the polygons. That's why the front of the scope looks visible, there's still some polygons representing the front. They are just smaller and closer to the player's camera while ADS.
I'd highly recommend looking at some of the 3D game files for Black Ops 3, which are easily accessible. They use the same method.
I suppose you could have a morphed view of the scope that exists only when aiming down sight. In a few it looked like there was a sudden change of how much of the inside of the scope was visible as you zoomed in.
Lowering the fov also helps a lot with the scope walls being visible from inside, just like you can see how in Apex it gets lowered a lot
Also orthographic projection is basically just fov at 0°
Orthographic projection is not zero degree FOV, that would mean that you're zoomed into an infinitely small point (i.e. smaller FOV = more zoom). Orthographic projection is when the "camera" stops being a tiny plane through which the scene projects into a focal point, and it instead becomes a large plane that the scene is projected onto with one uniform vector. In raytracing this would be the screen as a plane floating around the scene and rays traced straight from each point on the plane into the scene in one uniform direction - the rays are parallel. In perspective projection the rays "converge" through a point behind the projection rectangle. The difference is very distinct.
Let's say it's 0° fov with the camera not acting as a point but a plane. I mean yeah you're right.
it could be rendered as if it's focused at infinity
I think a key aspect of it is that the weapon isn't drawn in the same render layer as the rest of the scene.
What I think happens is the scene layer zooms in alot. Perhaps so much that the weapon itself would no longer fit on the screen.
The camera is then also pulled back only in the weapons render layer to basically shrink the weapons screen size.
The effect is that you get a much more ortogonal projection which makes the front and back of the scope more similar in size. Without blowing the weapon way out of proportion on the screen.
A really simple way of achieving this look is to have the inside of the tube more of a inverse cone, then an actual tube.
absolute banger apex clip at 4:04
You forgot about the 3rd and cheapest way ever: CS 1.6 style, where you zoom in and put an overlay on top of you screen and stop rendering the gun... Or even the Black Mesa crowbar "sprite scope" that is not only cheap af as it looks awful.
Anyway, ways that scope you showed could be done: almost orthographic camera rendering the gun; stop rendering the part of the interior of the tube and maybe add some flat surface with a paralax effect; refracting material shader (it might be possible, and maybe cheaper than Pic in Pic, depending on the engine you're using); and maybe changing the FOV of the viewmodel when you're aiming downsights.
Also this is also a tricky thing: using pic in pic, you can make the scope camera with a slightly smaller FOV, so you zoom and looses some perspective feelings, getting an almost flat 2D image (like real-life scopes). Add this with some vignette and some dirty decals and call it Realism.
Feels like backface culling everything aside from a small section on the inner diameter of the scope would be a quick way to achieve the right effect there.
I think they widen the front of the scope so its like a funnel and thats why you only see a bit of it
In Insurgency, they go transparent. Its more noticable when using guns without flipdown front site as they'll only render in a pool of blood.
@Garbaj
In Apex you can clearly see the camera changing focal length. (hence why the scope appears to shrink in length).
You can see it in 2:44 where the part above the scope isn't visible (obscured) and then it suddenly transitions to becoming visible.
Basically, The weapon camera zooms in and then zooms out while transitioning to a lower field of view (increasing focal length).
You can search for the vertigo effect (dolly zoom).
R6 simply makes the interior gone so that you can see through the backface culled outside.
As others have already commented, the solution is almost certainly to use a separate render layer for the weapon viewmodel. You could even render the scope and weapon in different passes. One thing that I noticed while watching the footage, is that, in the case of apex legends, the barrel of the gun would also intrude on the sight if it was rendered in worldspace, but it is obviously not visible through the scope. You could achieve this by changing the projection, or simply by using a layer mask in post-processing. There are always a variety of solutions to any given problem, and my guess is that different games use different solutions to achieve this same effect. As for performance impact, picture-in-picture has obvious drawbacks, and also looks bad if the sight takes up only a small part of the screen. As for the other techniques, the performance impact of having a separate render pass for the viewmodel should be minimal. Altering the mesh could maybe save a tiny bit of overhead, and could accomplished using the same transformations as altering the viewmodel camera's projection matrices, but at that point you have to contend with other limitations, either with in-place vertex manip with a compute shader (not fun) or moving meshes to and from video memory. I favour the separate render layer with a post-processing mask, because I think that's the easiest solution, but I like the elegance of the suggestion to change the projection of the viewmodel camera.
There's a few things that could be going on here (aside from some of the pointed out details by other comments about the geometry/material fade out).
1)Many first person shooters use a different camera matrix to render the weapon. This is why the gun doesn't distort or move with fov changes because it's actually being rendered at a different fov despite being geometrically represented within the scene (which is different from other common tricks like rendering a tiny gun close to the camera). In unity people often try to do this with layered cameras, but I think the effective way is to have a shader specific to the weapons that does reprojection on the other matrix. This being the case, you can actually flatten the weapon camera out towards an orthographic projection when ADSing, and I would argue Apex kinda has the look of doing that.
2)It actually is PiP, but they're using masking to save a bunch of extra drawing. This is similar to how Portal renders it's portals without incurring double the draw time. I'm kind of confused by games that have huge PiP framerate issues because it's relatively easy to make performant portals (in Unity in my case) using masking.
3)As others have pointed out, there's sometimes some kind of fade out happening, but I don't think they're necessarily hiding the geometry. It's possible that they have a shader with some kind of depth priority/fading that they ramp up when ADSing, and this can be smoothed by camera distance along a gradient.
I would make a screen partway down the scope, similar to the picture-in-picture solution. On that screen, I would apply some kind of shader that could warp or distort the geometry of the gun model behind the screen, but not anything else. Perhaps some kind of fish-eye-lens effect would work.
I would include some kind of variable to change the refraction level of said shader, and tie that variable to the state the gun is in. If the player isn't using the sight, 0% refraction. If the player is using the scope, 100% refraction. Add a lerp between 0 and 100%, as the player moves the scope in front of their face, and back again. This would allow the inside of the scope to be visible when not in use, but shrink back when it is in use.
My theory for apex legends style zooming is this: when you put ur eye closer to a metal tube, there are is more obstructions other than the openings, but if you push it away from you and still look intk it, the obstructions shrink, so i think that apex does this same think except just zooms it in
The method you are looking for is a combination of things you noticed and another technique.
You still zoom in/lower the FOV to get a better picture but to get that clear cutout image you also use a flat piece of Geo in the scope. Actually two of them with two different shaders.
One to cut out the scope with a shader using Stencil buffer.
The other to re-render what's behind that cutout with a scene_texture projection onto the other Geo. Then you enable/disable those mesh objects when you aim and go to hip.
scene_texture Renders what's behind an object on the screen so that's why the cutout is necessary to clear the area it will render.
Depending on how the renderer works and if you want to do other effects like blurring the background and keeping the scope area clear, you might have to use a separate render layer for the scopes/optics and the inner meshes as well.
This is why if you look at those games when they aim in slow motion you can see when those mesh pieces get activated and deactivated. Someone pointed out the timestamps for R6: Siege clips but the game you can see this the clearest in is Warzone with the sniper scopes.
Also since the scene_texture shader call is actually rendering to the same amount of pixels on your screen you can't zoom in inside the shader or else it will be pixelated. This is why you have to change the camera's FOV to get your zoom amount. This is how you can tell which method is picture in picture and which is the stencil buffer cutout/Scene_Texture method in different games.
I solved this in a game of mine by going with the multiple scope model route. When the player zooms I swap out the scope model to one that is more visually pleasing to look through. I had a technical limitation where I could not use a secondary camera to render the gun with a different projection. Worked quite well though. Users cant tell.
Elegant solution: outer circle just should be bigger. Like in weird optical illusions, where far placed greater object appears to be same size, as smaller object nearby.
literally as you ask the question you can see the aug scope doing what I guess. doing the exact same thing as picture in picture but with no zoom. just flat image of whats on the otherside but without different zoom levels.
The scope might be a seperate object that gets shortened/replaced separately. But I'm just spitballing.
I'm sure there's many ways to try and implement this, but one way would be: 1) render the gun in a second pass, 2) add a small circular mesh (could even be a quad with a circular texture) to the sight that you want to clear out, 3) use the depth buffer to block out the region from the mesh in (2) to not render the gun.
This would allow you to open up the sights and not affect other rendered objects in the scene. It would also be fast, since it's all done in a shader using the depth buffer. Also the mesh/texture from (2) is animatable so it can grow and shrink as you bring the gun up and down, making the effect very smooth.
in many shooter games, they make a global render who everyone sees, but they make a local render that is separated from the model and displayed only for the main player, so when looking at the HUD and everything, you are seeing a bunch of "sprays" that give the look of 3D, so when you aim they stop rendering the gun and then transitions to use a separated spray of the sight that you are using, it's a world illumination-interactive png of a fake sight
The weapon is most likely being rendered with a different camera for First Person anyway, so they could just be grabbing the color from the camera without the weapon and putting in on a disk into the scope (like with the PiP mode), just a few cm inside the scope, so a little bit is still visible.
So happy you are gaining traction. Found you 4 or 5 months ago & I love the stuff you put out. Can't wait to try your game someday!
Gun layer rendered seperately to the 3rd person player model. Camera on gun moves back significantly and over to center and most importantly narrows the FOV as much as possible
There is 3 ways to do it that keeps the inside of the tube still visible, like in Apex or R6.
1) The FOV gets narrower when aiming, lessening the effect of seeing the other end of the scope that much smaller. This is the case in Apex.
2) The other end of the scopes internal tube is slightly wider inside of the far side. Not that common, though.
3) The inside of the scope is partially hidden. R6 does this and the FOV trick.
In Insurgency: Sandstorm the front of the scope is cut off while in ads, you can sometimes see it on the security red dot if you have a minor performance drop/stutter while exiting ads.
Even with all the research you do there are still some questions you may struggle to answer.
That's why all the work you put into this channel is amazing. Your helping everyone else learn by giving them an easy source of useful information.
This way the next "you" who comes along looking for answers has another place to find what they seek.
My solution to this would be having two cameras (one for everything except the gun, and the other rendering just the gun) as you said in the video on how to get rid of weapon clipping. In that way, you can lower the fov on the main camera and give the weapon camera an ortographic perspective (or you could just also lower the fov until you don't see the end of the scope). Love your vids btw :D