@@calccalccalc You can't solve everything, no, but linear algebra generally has the most efficient solution when it comes to almost anything vector related, including transforms, 3d rendering pipelines, and shaders, which are all very computationally intensive.
For the solution with the second camera you'll probably want to transform the view camera based on object (Node3D) space. For example, have a Node3D for the player side of the mirror and transform the global position and rotation of the view camera to its local space. Then you set the mirror camera to the local space of Node3D that's rotated and scaled to have the mirror camera on the mirror side. You could do this by multiplying Transform3D in a script without putting Node3Ds in the hierarchy, but do whatever is more intuitive to you.
Only work on raytracing setup, you can however use Ray marching but because of how the traditional setup work you can only receive what's on the screen hence screenspace reflection/ssr. Because of that it doesn't really work for mirror, but it does work on something like water where you don't need all the reflection
yeah, is it posible to calculate the exact pixel where the light of the object would come out of hit the screen (it's exactly how the first mirror works). the problem would be how to place the camera. technically the second method with the second camera always looking towards the player would be the best solution, but i don't have enought knowlegde about 3d to know why it doesn't work properly :(
For the second camera. You want to use linear algebra. Transform the player camera's coordinates and rotation to the mirror's object space. And then apply the mirror's rotation to the camera. This allows you to move the mirror wherever you deaire without need of editing the script or locking it to Cartesian coordinates
This is pretty cool, and I think that mirror and portal shaders have quite a bit in common. Sebastian Lague (an excellent youtuber with some of the best videos I've seen) has a video about portals on his channel, which also briefly discusses mirros and camera alignment called "Coding Adventure: Portals". Even aside from that, a lot of Sebastian's other videos are extremely interesting to watch, sometimes I even go back and rewatch them!
this is why the mirrors in all the games are broken or dirty beyond use. I really think the mirrored geometry, used in the right spots, gives the best bang for the buck performance-wise, and it was used as far back as Mario 64, Metal Gear Solid 2 (maybe MGS1). I really think for a spooky game, being able to see ghosts/monsters behind you in the mirror, would be spoopy.
You can do this with a second camera too, by drawing certain objects during the mirror pass only. Duplicating geometry might be harder to automate and maintain, culling may become an issue, and the "twin room" geometry takes actual space in your level... If older games could get away with using a Render-To-Texture approach, I'm pretty sure they would have done it that way. But that was a major bottleneck (or simply not possible) with older hardware.
@@tzimmermann is the camera technique what they do in portal? because it looks flawless in portal. I know i've seen a geometry version where the fake geometry is only visible through the mirror's material, meaning it doesn't take space in the level. it's present, overlapping the room on the other side, but it has no collision and is not visible unless viewed through the mirror texture. i saw a tutorial for that in like 2016.
@@westingtyler1 Yes. This camera technique for mirrors is the same idea used for portals in Portal. When used to create reflections, it's called a planar reflection. It's flawless in terms of looks, but is the most expensive method besides ray tracing. Certain small objects are often removed from the reflections to improve performance. Pay close attention to water reflections in games like Half-Life 2 and you might notice some of those missing objects.
@@westingtyler1 As far as I know, they did use a virtual camera in Portal, but dropped using RTT after prototyping. Instead, they use a stencil buffer trick (and a lot of clipping plane magic), so everything can be drawn to the same render target (single pass). They do have to duplicate models that are mid-way through portals though, because you potentially need to see them in two places at once. It gets hairy when you need to solve the recursion problem (blue portal sees orange portal), and you need to render both opaque and transparent geometry. Look for a video called "Valve developers discuss Portal problems" where they talk about it in more detail! I don't know about the tutorial you're referring to, but if you're duplicating geometry, the twin room *has* to be somewhere, just maybe not directly on the other side...
I think the mirror code could be similar to Sebastian Lague's portal code. A mirror is basically just a portal that leads to itself that you also can't go through
This would definitely get a nice result at first, but just remember, the graphics in the game portal (it uses a similar approach to lague) are optimised especially for this effect, as it is quite computationally expensive.
Several people already talked about transformation spaces and portals which I recommend to look at. I also want to point out about "stencil buffer" which makes copying object local to some portion of the scene (like a plane for a mirror or a portal)
a camera solution can be taking the normal and basis of the mirror, multiply the difference between player and camera by the negative of the normal and add to the position of the camera, and then add a 90deg rotation relative to its local Y basis. that could work i think, and then you wouldn't have to hardcode the position calculation
another funny way is, for simple shaded games, you can use a second pass that stores the location of a mirror and simply moves every vertex across the mirror plane. you'd need 1 more pass per mirror, and it would be a pain to handle depth but i did it for some tests at one point
In Duke Nukem 3d (the one from the last century ~1996), they had a wide empty space behind every mirror and would use that space to replicate every vertex/sprite you would see in the opposite direction. Worked basically like your first attempt, (and was just as stationary), but automated. Minds were blown back in the day :)
Also you could use a geometry shader to fake reflections by duplicating the scene to the other side of the mirror. Don’t know how to do that in Godot though
4:12 you can solve the camera spin using inverse quaternions. you take the quaternions of the player rotation and the mirror, multiply by the transposed player camera rotation, then multiply by both quaternions for player cam and mirror rotation.
My favourite in my surreal game was a parallaxed cubemap (low resolution and nearest for a pixel effect). It looked like a mirror from afar but on closer inspection, it's so odd and distorted, i love it
“copying” is the optimal solution, and is what most games use for functional mirrors. This is because it gives you the freedom to optimise the reflection in various ways. Everything else requires rendering the visible world to a texture, which is compute intensive, and is generally used for reflective effects that can be turned off in quality settings. Of course, it does depend on the platform, as an optimised copy would be great for performance and therefore better for mobile devices/VR, and you could get away with using render textures with a single-camera game that is running on a PS5 or on a PC with a strong GPU. Also, it depends on the game. Is this the only mirror in the game? Is this one of a few mirrors in the game? How important are mirrors to the gameplay? How big is/are the mirror/mirrors? An additional optimisation to “copying” is to make sure everything that is mirrored is only simulated on the player’s side, and to copy the effects to the mirror world. This way, you’re only bottlenecked by memory, rather than compute.
@1:58 "A mirror is basically reflecting light particles" * assumes hes going to go into physics about replicating light particle behavior * "So we can use a camera" Me : Oh.. yeah
2:54 I heard about plane cameras. Maybe they would work if you mirror it right and add the perspective thing so you can look at the mirror from different angles.
So, what you can do for the for making a mirror with viewports and cameras is convert the global player camera position into a local position. I do not know much about godot, so you'll have to check how to do it, but generally it involves a bunch of matrix multiplication. If you want to work with modifying positions and rotations it is good to have an understanding about matrix multiplication. Then, you just flip the normal of the mirror, and calculate a new global camera position based on your recorded local position (but with the flipped normal). Another issue you may come into: Let's say there is a box behind the mirror. If you use the method you described, your camera will record that box. you essentially need to align the near view clip plane to the mirror position. That way, everything that is behind the mirror is not recorded. Advantages of this: Since you are using local positions, and decoding them using another transform, you can actually separate the transforms instead of having them in the same place fixed. This means, portals Just remember that if you make portals, the near clip plane should point to the target view plane (the side of the mirror with flipped positions). There also come a lot of issues like view recursion, Actually travelling through the portal, collisions, and collisions of objects through the portal.
Portal and Portal 2 use the moving camera method with a shader that cuts the portal part out of the screen and slaps it on the portal texture, the only difference is that the other camera is the same offset you have from the portal and portals facing other directions are corrected
The camera mirror I tried to setup too and had the same issue (and the corner problem, I'd love to see a commented version of your script to see how you solved that, I'm still utterly stuck with it myself) On my end for the camera and rotation issue, what I did is add a Transform (called Copycat in my case XD) that's a child of the mirror plane, and make it mimic the player global transform. Then I make the camera (which is also child of the plane, since subviewport already require that) mimic the local transform of the copycat with the reversed axis.
Wondering whether it's possible to do the copying method, take a snapshot of it, remove the extra objects and use just a texture of that snapshot, and then somehow render copies of any moving objects on top of that texture (despite the fact they'd be behind it).
It's not for the same end effect, but take a look at how they did the 3d projection for The Amazing Adventures of Spider-Man The Ride. They called the technique "squinching" to get the sort of 'portal' effect.
I'd just render to an image (with the inverse camera rotation as the player's and at the mirror's position) and render that as the mirror texture. It's worked for me. Edit: Just watched the video and you did mention this method.
The Sims 2 has a great dynamic reflection system, with objects and characters reflecting in mirrors. In "Castaway Stories", all the objects are reflected in the sea, creating a fascinating effect. These are probably the remains of ancient civilizations' forgotten technologies. Can anyone tell us more about them?
For vehicles the camera is the way to go, probably the most realistic. I use three of them in my buses and trucks in Unity, they are fine. I miss a better way to use on huge buildings. Screen space solutions are garbage when the player is inside the vehicle, since there is no outside view to render.
Generally all of these have their uses however I see ray traced reflections eventually becoming the standard as hardware RT gets more performant and more prominent in game rendering. I tend to see render to texture as the most common method for rendering mirrors in games. Older games tend to mirror geometry but that's not great for most modern games because it's too expensive. Super cool to see this kinda stuff. Also are planar reflections possible to be used as reflections in Godot?
This is an example when a person does not understand anything about a topic, but trying to teach others something. A single mirror in a room is an elementary task, which can be solved without any shaders at all, even on the most old versions of graphics API. The universal and fastest way to do this: 1) When you render your mirror surface, set enabling value to the allowing mask (for example, using stencil buffer in OpenGL). 2) Move your camera after rendering to its reflected position and direction vectors. All reflected coordinates are calculated as P'=P-N*2*dot(N,P-M), and all reflected vectors as V'=V-N*2*dot(N,V). Where N is the normal to the mirror surface |N|=1, and M is any point on the mirror surface. 3) Render second pass directly into screen space, using the allowing mask. Don't render any polygons or objects which will not visible from mirror. It will be better if you will also check before the second render pass, is any of pixels of the mirror was really rendered on the screen. And don't render second pass if it wasn't. If you want to render many mirrors in the room, you need to use the same method, but using unique value of the mask for each mirror. And process this like a tree, going deeper and render next reflected pass for each other mirror, if that mirror was visible in the current render pass. You also need to use stack of camera's positions, to correctly calculate its reflected positions after reflected positions and to revert reflecting, when returning from the processed leaf of the tree. And use level limitation of the tree to prevent major lags in the scenes with possibility of multiple reflections (for example, if a mirror opposite a mirror).
@@Code_It_All I think it will be better to make a really informative video for your viewers, on how to make a mirror in Godot, instead of the 8-minute overview of methods that don't work or are difficult to implement in practice (such as with the second room, because of collision in space and manual objects duplication). I don't know Godot and I'm not even a game developer, so if Godot doesn't have the ability to do the second render pass with using mask for it, then my apologies. I am just a random viewer who came across this video. And my last advice will be - read articles on computer graphics issues, starting from the very basics, which were back in the 80-90s. And necessarily study linear algebra, without it it is impossible to write anything even in 2D graphics. Over time, gaining more knowledge, you will become the awesome specialist in gamedev, good luck.
I always though that setting a material of an object as metallic and smooth is enough to make a mirror, but somehow I don't see any games use that technique
You can definitely do mirrors with raymarching/pathtracing (both of which would often be called ray tracing). Generally you need to have custom rendering code tho.
@@jlewwis1995 Sometimes. Depending on how you do it ray tracing can be faster than rasterization. My one example is Psycho SSR reflections in Cyberpunk 2077. If you have a RT capable card, at resolutions like 1080p and above Psycho reflections are actually more expensive to render than ray traced reflections
@@jlewwis1995 depends. If you have a really detailed graphics and an easy way to represent them in an SDF or as voxels or smth then it might be faster on a well optimised compute shader. Still a lot more work though to only pay off in very specific circumstances anyway.
I think you forgot rotate check. I mean that 360 or 180 angle you need to it not over 360 or under 0. You can think of the turret. When the aim turret turret aim at the player the turret will rotate but when there 0 or 360 it will either turn change direction opposite turn. Just a guess. You need a pointer and rotate for mirror (face direction) and player (face direction) to know when to inverse camera render target. the angle can be positive and negative when rotate and inverse. Since you inverse you need do some with the inverse rotate check. I guess you missing that variable. Just think of 2D plane.
You could increase your fps with shadow maps, that actually are shadows drawn in the textures of objects. The only issue is the player's shadow that moves with the player and isn't a texture so... Well, i think this could be an option, but if you want to have more realism, better use real time lighting.
@@Code_It_All Yeah, i know haha. I'm studying programming and some stuff is difficult to remember if you dont read it before. I actually use unity and gms2 to do games and sometimes i need the documentation just because i can't remember some things.
2:10 This would not work as a realistic mirror. I don't know how to explain why it wouldn't, but it has to do with how the visual of the mirror changes when you move around. Try comparing a real life mirror to your mirror.
Where in this video did I say specifically this is a complete tutorial and flawless ? Also if you actually listen to what I say I didn't even watch it fully, It just helped me a bit, if you want more you can watch that video ( link in desc ), Also that is only one of the methods I used. this video is so that beginner get some idea and overview about mirrors.
this is why linear algebra and matrix math are important for gamedev
r u serious
@@nudtanunwarnnissornr u?
@@nudtanunwarnnissorn Oh yes. It's a field called computational linear algebra.
…and then realise that you can’t solve *everything* with linear algebra, and come up with a simple and practical solution 😅
@@calccalccalc You can't solve everything, no, but linear algebra generally has the most efficient solution when it comes to almost anything vector related, including transforms, 3d rendering pipelines, and shaders, which are all very computationally intensive.
For the solution with the second camera you'll probably want to transform the view camera based on object (Node3D) space. For example, have a Node3D for the player side of the mirror and transform the global position and rotation of the view camera to its local space. Then you set the mirror camera to the local space of Node3D that's rotated and scaled to have the mirror camera on the mirror side. You could do this by multiplying Transform3D in a script without putting Node3Ds in the hierarchy, but do whatever is more intuitive to you.
The viewport camera thing seems the best solution
Not to mention you can lower the resolution of the viewport if your game is already too intensive
Mirror maths are surprisingly simple. You just take the surface normal and have the vector bounce off from it. Simple calculus
That's how light particles work, My issue was the placement of the second camera though...
@@Code_It_All yes Ik this isn't ray tracing or vector math. You wanted a tricky way to make mirrors
Only work on raytracing setup, you can however use Ray marching but because of how the traditional setup work you can only receive what's on the screen hence screenspace reflection/ssr. Because of that it doesn't really work for mirror, but it does work on something like water where you don't need all the reflection
yeah, is it posible to calculate the exact pixel where the light of the object would come out of hit the screen (it's exactly how the first mirror works). the problem would be how to place the camera.
technically the second method with the second camera always looking towards the player would be the best solution, but i don't have enought knowlegde about 3d to know why it doesn't work properly :(
For the second camera. You want to use linear algebra.
Transform the player camera's coordinates and rotation to the mirror's object space. And then apply the mirror's rotation to the camera.
This allows you to move the mirror wherever you deaire without need of editing the script or locking it to Cartesian coordinates
This is pretty cool, and I think that mirror and portal shaders have quite a bit in common. Sebastian Lague (an excellent youtuber with some of the best videos I've seen) has a video about portals on his channel, which also briefly discusses mirros and camera alignment called "Coding Adventure: Portals". Even aside from that, a lot of Sebastian's other videos are extremely interesting to watch, sometimes I even go back and rewatch them!
mirrors are just portals that you can't enter because you're in the way!
@@johnywuijts917 lmaooo
this is why the mirrors in all the games are broken or dirty beyond use. I really think the mirrored geometry, used in the right spots, gives the best bang for the buck performance-wise, and it was used as far back as Mario 64, Metal Gear Solid 2 (maybe MGS1). I really think for a spooky game, being able to see ghosts/monsters behind you in the mirror, would be spoopy.
You can do this with a second camera too, by drawing certain objects during the mirror pass only.
Duplicating geometry might be harder to automate and maintain, culling may become an issue, and the "twin room" geometry takes actual space in your level... If older games could get away with using a Render-To-Texture approach, I'm pretty sure they would have done it that way. But that was a major bottleneck (or simply not possible) with older hardware.
@@tzimmermann is the camera technique what they do in portal? because it looks flawless in portal.
I know i've seen a geometry version where the fake geometry is only visible through the mirror's material, meaning it doesn't take space in the level. it's present, overlapping the room on the other side, but it has no collision and is not visible unless viewed through the mirror texture. i saw a tutorial for that in like 2016.
@@westingtyler1 Yes. This camera technique for mirrors is the same idea used for portals in Portal. When used to create reflections, it's called a planar reflection. It's flawless in terms of looks, but is the most expensive method besides ray tracing. Certain small objects are often removed from the reflections to improve performance. Pay close attention to water reflections in games like Half-Life 2 and you might notice some of those missing objects.
@@westingtyler1 As far as I know, they did use a virtual camera in Portal, but dropped using RTT after prototyping. Instead, they use a stencil buffer trick (and a lot of clipping plane magic), so everything can be drawn to the same render target (single pass). They do have to duplicate models that are mid-way through portals though, because you potentially need to see them in two places at once.
It gets hairy when you need to solve the recursion problem (blue portal sees orange portal), and you need to render both opaque and transparent geometry. Look for a video called "Valve developers discuss Portal problems" where they talk about it in more detail!
I don't know about the tutorial you're referring to, but if you're duplicating geometry, the twin room *has* to be somewhere, just maybe not directly on the other side...
Tony Hawk is my personal favorite example, as the airport level achieves it's shininess by just doing method 1
The rookie method: take a photo of a mirror and use it as a diffuse texture
bro singlehandedly solved a problem that existed for like the last 8 hours, thanks
I think the mirror code could be similar to Sebastian Lague's portal code. A mirror is basically just a portal that leads to itself that you also can't go through
This would definitely get a nice result at first, but just remember, the graphics in the game portal (it uses a similar approach to lague) are optimised especially for this effect, as it is quite computationally expensive.
Which is actually addressed here, the place-a-second-camera-wait-fuck-i-cant-algebra part
Several people already talked about transformation spaces and portals which I recommend to look at. I also want to point out about "stencil buffer" which makes copying object local to some portion of the scene (like a plane for a mirror or a portal)
Godot doesn't currently have stencil buffer access unless you add it in yourself, unfortunately
a camera solution can be taking the normal and basis of the mirror, multiply the difference between player and camera by the negative of the normal and add to the position of the camera, and then add a 90deg rotation relative to its local Y basis. that could work i think, and then you wouldn't have to hardcode the position calculation
another funny way is, for simple shaded games, you can use a second pass that stores the location of a mirror and simply moves every vertex across the mirror plane. you'd need 1 more pass per mirror, and it would be a pain to handle depth but i did it for some tests at one point
In Duke Nukem 3d (the one from the last century ~1996), they had a wide empty space behind every mirror and would use that space to replicate every vertex/sprite you would see in the opposite direction. Worked basically like your first attempt, (and was just as stationary), but automated. Minds were blown back in the day :)
Also you could use a geometry shader to fake reflections by duplicating the scene to the other side of the mirror. Don’t know how to do that in Godot though
4:12 you can solve the camera spin using inverse quaternions. you take the quaternions of the player rotation and the mirror, multiply by the transposed player camera rotation, then multiply by both quaternions for player cam and mirror rotation.
My favourite in my surreal game was a parallaxed cubemap (low resolution and nearest for a pixel effect). It looked like a mirror from afar but on closer inspection, it's so odd and distorted, i love it
Lol, did we forget how to draw planar reflections?
Laughs in Unreal Engine 5's Nanite Ray Traced Reflections
but nice tutorial Man! I like the video
“copying” is the optimal solution, and is what most games use for functional mirrors. This is because it gives you the freedom to optimise the reflection in various ways. Everything else requires rendering the visible world to a texture, which is compute intensive, and is generally used for reflective effects that can be turned off in quality settings.
Of course, it does depend on the platform, as an optimised copy would be great for performance and therefore better for mobile devices/VR, and you could get away with using render textures with a single-camera game that is running on a PS5 or on a PC with a strong GPU.
Also, it depends on the game.
Is this the only mirror in the game?
Is this one of a few mirrors in the game?
How important are mirrors to the gameplay?
How big is/are the mirror/mirrors?
An additional optimisation to “copying” is to make sure everything that is mirrored is only simulated on the player’s side, and to copy the effects to the mirror world.
This way, you’re only bottlenecked by memory, rather than compute.
Measuring performance in how many extra ms it takes is going to give you more usable results than measuring in fps, especially when it's that high.
reflection probes, ssr and raycasting all have the benefit of working on curved surfaces.
Goes to show just how genius Insomniac devs are 😮
Those aren't the only ways to make a mirror
Enjoyed your video!
Unsolicited tip: pass your audio through a de-esser?
@1:58
"A mirror is basically reflecting light particles"
* assumes hes going to go into physics about replicating light particle behavior *
"So we can use a camera"
Me : Oh.. yeah
2:54 I heard about plane cameras. Maybe they would work if you mirror it right and add the perspective thing so you can look at the mirror from different angles.
So, what you can do for the for making a mirror with viewports and cameras is convert the global player camera position into a local position. I do not know much about godot, so you'll have to check how to do it, but generally it involves a bunch of matrix multiplication.
If you want to work with modifying positions and rotations it is good to have an understanding about matrix multiplication.
Then, you just flip the normal of the mirror, and calculate a new global camera position based on your recorded local position (but with the flipped normal).
Another issue you may come into:
Let's say there is a box behind the mirror. If you use the method you described, your camera will record that box. you essentially need to align the near view clip plane to the mirror position. That way, everything that is behind the mirror is not recorded.
Advantages of this:
Since you are using local positions, and decoding them using another transform, you can actually separate the transforms instead of having them in the same place fixed. This means, portals
Just remember that if you make portals, the near clip plane should point to the target view plane (the side of the mirror with flipped positions).
There also come a lot of issues like view recursion, Actually travelling through the portal, collisions, and collisions of objects through the portal.
Portal and Portal 2 use the moving camera method with a shader that cuts the portal part out of the screen and slaps it on the portal texture, the only difference is that the other camera is the same offset you have from the portal and portals facing other directions are corrected
The camera mirror I tried to setup too and had the same issue (and the corner problem, I'd love to see a commented version of your script to see how you solved that, I'm still utterly stuck with it myself)
On my end for the camera and rotation issue, what I did is add a Transform (called Copycat in my case XD) that's a child of the mirror plane, and make it mimic the player global transform.
Then I make the camera (which is also child of the plane, since subviewport already require that) mimic the local transform of the copycat with the reversed axis.
Wondering whether it's possible to do the copying method, take a snapshot of it, remove the extra objects and use just a texture of that snapshot, and then somehow render copies of any moving objects on top of that texture (despite the fact they'd be behind it).
It's not for the same end effect, but take a look at how they did the 3d projection for The Amazing Adventures of Spider-Man The Ride. They called the technique "squinching" to get the sort of 'portal' effect.
Fascinating subject mate keep it up 💪🔥
Can you please make an fps swimming tutorial in godot. Not so many tutorials out there about swimming :(
Perhaps if you parent the camera to the mirror object and using it's local position will fix the camera's positioning.
I'd just render to an image (with the inverse camera rotation as the player's and at the mirror's position) and render that as the mirror texture. It's worked for me.
Edit: Just watched the video and you did mention this method.
The Sims 2 has a great dynamic reflection system, with objects and characters reflecting in mirrors. In "Castaway Stories", all the objects are reflected in the sea, creating a fascinating effect. These are probably the remains of ancient civilizations' forgotten technologies. Can anyone tell us more about them?
For vehicles the camera is the way to go, probably the most realistic. I use three of them in my buses and trucks in Unity, they are fine.
I miss a better way to use on huge buildings. Screen space solutions are garbage when the player is inside the vehicle, since there is no outside view to render.
I like that Godot is getting more attention nowadays
For the camera mirror, you can just use an orthographic camera I'm pretty sure.
Generally all of these have their uses however I see ray traced reflections eventually becoming the standard as hardware RT gets more performant and more prominent in game rendering. I tend to see render to texture as the most common method for rendering mirrors in games. Older games tend to mirror geometry but that's not great for most modern games because it's too expensive. Super cool to see this kinda stuff.
Also are planar reflections possible to be used as reflections in Godot?
if planar reflections are not a default option, it can still be done with code, as shown in the video
Cool vid. How do you see your FPS in Godot?
Thanks! You can use debugging tools in Godot itself to see fps, but here I'm using Mangohud in linux
Bro you responded so quickly . You earned a subscriber as a Godot enthusiast!!
@SleepyLeviathan6 lol, you commented at the right time 😂
Why am I watching this at 4am. I am not even a game developer.
Gotta start somewhere right ?
Lmao the schizophrenic “subscribe” appearing and disappearing
Try using dot products instead of sin/cos (subtracting dot products, multiplying etc. look at the vector math a lil)
This is an example when a person does not understand anything about a topic, but trying to teach others something. A single mirror in a room is an elementary task, which can be solved without any shaders at all, even on the most old versions of graphics API.
The universal and fastest way to do this:
1) When you render your mirror surface, set enabling value to the allowing mask (for example, using stencil buffer in OpenGL).
2) Move your camera after rendering to its reflected position and direction vectors. All reflected coordinates are calculated as P'=P-N*2*dot(N,P-M), and all reflected vectors as V'=V-N*2*dot(N,V). Where N is the normal to the mirror surface |N|=1, and M is any point on the mirror surface.
3) Render second pass directly into screen space, using the allowing mask. Don't render any polygons or objects which will not visible from mirror.
It will be better if you will also check before the second render pass, is any of pixels of the mirror was really rendered on the screen. And don't render second pass if it wasn't.
If you want to render many mirrors in the room, you need to use the same method, but using unique value of the mask for each mirror. And process this like a tree, going deeper and render next reflected pass for each other mirror, if that mirror was visible in the current render pass. You also need to use stack of camera's positions, to correctly calculate its reflected positions after reflected positions and to revert reflecting, when returning from the processed leaf of the tree. And use level limitation of the tree to prevent major lags in the scenes with possibility of multiple reflections (for example, if a mirror opposite a mirror).
Thanks for your thorough tutorial on how to make a perfect mirror, something which I never claimed to be doing in this video.
Also this is not really a tutorial, it's more of an overview
@@Code_It_All I think it will be better to make a really informative video for your viewers, on how to make a mirror in Godot, instead of the 8-minute overview of methods that don't work or are difficult to implement in practice (such as with the second room, because of collision in space and manual objects duplication).
I don't know Godot and I'm not even a game developer, so if Godot doesn't have the ability to do the second render pass with using mask for it, then my apologies. I am just a random viewer who came across this video. And my last advice will be - read articles on computer graphics issues, starting from the very basics, which were back in the 80-90s. And necessarily study linear algebra, without it it is impossible to write anything even in 2D graphics. Over time, gaining more knowledge, you will become the awesome specialist in gamedev, good luck.
I always though that setting a material of an object as metallic and smooth is enough to make a mirror, but somehow I don't see any games use that technique
You can definitely do mirrors with raymarching/pathtracing (both of which would often be called ray tracing). Generally you need to have custom rendering code tho.
It would be cool to see it implemented in godot !
Not to mention it would take a newer gpu and would have far worse performance than the duplication or viewport methods
@@jlewwis1995 Sometimes. Depending on how you do it ray tracing can be faster than rasterization. My one example is Psycho SSR reflections in Cyberpunk 2077. If you have a RT capable card, at resolutions like 1080p and above Psycho reflections are actually more expensive to render than ray traced reflections
@@jlewwis1995 depends. If you have a really detailed graphics and an easy way to represent them in an SDF or as voxels or smth then it might be faster on a well optimised compute shader. Still a lot more work though to only pay off in very specific circumstances anyway.
❤
I think you forgot rotate check. I mean that 360 or 180 angle you need to it not over 360 or under 0. You can think of the turret. When the aim turret turret aim at the player the turret will rotate but when there 0 or 360 it will either turn change direction opposite turn. Just a guess. You need a pointer and rotate for mirror (face direction) and player (face direction) to know when to inverse camera render target. the angle can be positive and negative when rotate and inverse. Since you inverse you need do some with the inverse rotate check. I guess you missing that variable. Just think of 2D plane.
You could try Ray marching
raymarching would require remaking your entire scene in shader code
@@coppertones7093 Not necessarily, all the scene data is already on the GPU
@@mariovelez578 you’d need to use SDFs instead of triangles
@@coppertones7093 You could use the SDF of a triangle with an acceleration structure
You really gotta learn to use quaternions. It basically makes any rotation-based issues go away.
Reflection probe needs to follow your camera origin
You could use similar code to make the visuals of a portal
Haydee 2 has a really good mirror idk how expensive it is but in scenes with and without it i get the same fps 80 -100
How the hell did the first method reduce your fps by so much?
I believe it was the two OmniLights and it's shadows
1:09 ok demon words. Only cause you said so.
How about a Complicated Solution!, Cube Mapping as Mirrors! LUL
You could increase your fps with shadow maps, that actually are shadows drawn in the textures of objects. The only issue is the player's shadow that moves with the player and isn't a texture so... Well, i think this could be an option, but if you want to have more realism, better use real time lighting.
You mean bake shadows ?
,You could also get more fps by changing some stuff on WorldEnv and decreasing the shadow quality in project setting
@@Code_It_All Yeah, i know haha. I'm studying programming and some stuff is difficult to remember if you dont read it before. I actually use unity and gms2 to do games and sometimes i need the documentation just because i can't remember some things.
And many game also have very immersion brake mirror when in VR, it instantly looks like a screen with no depth.
yep, this is why copying is the optimal method here, at least out of these options
You shouldn't use FPS as your performance measurement because it's non-linear. You should use the frame time instead.
Or just put a real mirror next to the computer screen. Heaps easier.
2:10 This would not work as a realistic mirror. I don't know how to explain why it wouldn't, but it has to do with how the visual of the mirror changes when you move around.
Try comparing a real life mirror to your mirror.
Did you watch the whole video before commenting?
@@miklhnsn692 yes
just make an object and make its rouphness: 10000000 and metalic: 100000
are you using laptop or PC?
I'm on PC
7:00 SDGFI❌ SDFGI✅
Rtx fixes that problem
If u r lazy like me
Neat
first method is the roblox method lol
0:41 that's called mirroring lol
lol, who would've thought!
I dont know why i watched this i am not even a developer i dont even know coding i dont even have godot
Get rid of those random forced subtitles.
Unreal
Ikr ?
A tutorial watching a tutorial is crazy
Where in this video did I say specifically this is a complete tutorial and flawless ?
Also if you actually listen to what I say I didn't even watch it fully, It just helped me a bit, if you want more you can watch that video ( link in desc ), Also that is only one of the methods I used. this video is so that beginner get some idea and overview about mirrors.