Mixed Reality Shadow - Unity Tutorial - Quest 3

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome back to another mix rity tutorial and in this video I'm going to show you how to add shadows in mix R for your virtual object as always if you'd like to support my work you can join us on patreon to get access to exclusive tutorials and the source code of all of my project but without further Ado let's get started okay so let me show you the first technique to add an nice shadow in mix righty so as you can see I'm inside a very simple mix ready project this is the setup that I shown in this tutorial on how to make a meta 3 game but of course this mix rity Shadow can work for any mix rity project not just on the meta 3 okay so for this first technique I'm going to right click in the AR key go to 3D object and search for Quad so as the name suggest this will create a quad in our scene we can then rotate it scale it down there you go and now what I'm going to do is get our cube right click go to copy and copy the position we can then select back the quad right click and select paste position position there you go now this will place the quad at the position of our Cube but now we can just press on W and place it a bit down below there you go okay so now that we've added a quad under this Cube the technique to add a shadow for this cube is actually to just simply create a blop texture that will just follow this Cube now in my case as you can see I have imported in my game this white circle fade texture that you will be able to download in the description below now make sure to go on the texture properties and select Alpha is transparency then we can go down below and click on apply there you go now the texture appears correctly over there okay so now how to use this texture to create a shadow effect under this Cube we can right click go to create material this will of course create a new material that we can call blop Shadow beautiful and in my case I'm using the standard pipeline so I'm simply going to go to unlit press transparent texture and as you can see this is a nonl transparent Shader that use both a texture and a base color so what we can do is drag the Wide Circle fade over there beautiful now we can drag the blop Shadow under here the quad that we made and there it is we can see the beautiful Shadow appearing now but of course you can use now the base color to kind of thin the color to Black you can also reduce here the transparency by changing the alpha value of the color but I think a value of 205 will be perfect okay beautiful now in the case that you are not using the standar pipeline but the universal rendering pipeline you can of course do a similar setup by going to urp unlit then settings the materials to transparent and just drag the texture over there in the same way okay here we go now let's try to see what this looks like okay and here you go as you can see we can see here the blood Shadow just under the cube but right now we have a problem of course is that if we move the cube well the shadow doesn't follow so let me show you how we can fix this so okay so to fix this we are going to make this sad follow the cube position but always be projected on the ground so let me click on ADD component and I'm going to write a script C place on ground there you go okay so on the script we are going to need five variable so be ready first we need of course a reference to the object that we want to follow so the cube in our case then we want a reference to a raycast distance there you go which will be the distance of the rast to find the ground so for the rast we need as well a layer mask that we can call layer mask and finally I'm going to add a public fold called radius because I actually lie to you it's not a rast that we are going to use it is a sphere cast which which compar to rast needs a certain radius there you go finally the last parameter will be a vertical offset which will help us to better place vertically the object so let's maybe set it at first to 0.02 CM beautiful and now I'm going to remove the start function but in the update let's do rast hit rast hit and then create a sphere CS that will be projected just down below the target object that we are trying to follow so let's do bull has it equals physics. sphere cast transform. position radius Vector 3 do down out recast it and the last parameters will be the layer mask beautiful now if we have it something then we can use what we it to place here this sad by doing transform. position equals new Vector 3 we can give on the x value the target position. X on the Z value we can do the same but with the Z position of the Target and here we are just missing the Y component of uh the transform. position Vector 3 and which will be our recast hit. point. y value and which we can increment with our vertical offset this way we'll be able to better place using the vertical offset the quad above or below something thing oh and just before going back to Unity I think I just made a mistake here we want to start casting the sphere cast from the target position not the transform position so let's simply write Target that position here instead oh and of course I did another mistake in this Spar cast no don't blame me this function takes a lot of parameters but anyway I forgot to add here the rast distance of course and we can add it just before here the layer Mass so let's simply write Rick cast distance and now everything should work fine we can now save our script and go back to Unity there you go after waiting for the script to compile as you can see we can now set this component by dragging first the cube for the Target because this is the thing that we want to follow for the RAS distance we can leave it to two and for the layer Mass this means the thing that we want to collide with now in my case I'm going to go at the top click on layer add layer and add a layer which I will call round because I of course want to place the object on the ground so let's say layer mask now to be only ground beautiful now for the radius basically what we want is to give for the radius half of the real size of this Cube now the size of this cube is 0.08 so maybe we can do F the radius 0.04 there you go and now everything is set up use these beautiful blub shadows and to make it follow our Cube of course the last thing we need to do is to just have something in our real world that we can collide with now in my case under the OVR scene manager if you remember on my tutorial series on how to make a mix right meta 3 game I use here this prefab so Global mesh collider that actually maps to the real world around me so what I'm going to do is Select here this Global mesh collider click on global mesh collider there you go and set its layer to ground this way the quad will be able to find it with the ray cast as it has the layer Mass ground and we will be able to place here this blop Shadows on top so only one way to find out and it is to build our game to test it and there you go as you can see we can see our beautiful quad now under our Cube but most of all if I move the cube well as you can see vertically the shadow stays in place but I can move it around and it is correctly placed under at all time this is awesome and there you have it so this was one of the two technique to create a nice shadows in mix right now of course let me show you how to do the Su technique which will be a bit more precise now if I go to Unity then I right click go to 3D object and then plane as you can see this create a white plane that we can recenter at 0000 0 and if we place it a bit down below Watch What Happens of of course we have shadows that are drawn from the controller or the cube in this plane but the issue is that the plane is still showing of course so how cool would it be if it was possible to actually hide the plane material but only show the color and of course it is possible using a custom Shader so the Shader that we are going to use is this one so the shadow receiver that you will be able to find in the description below now I believe that this Shadow receiver Shader works for both a standard Pipeline and urp but if you want a more advanced Shadow receiver for Universal rendering pipeline I highly recommend this asset there is also a paid version that works with more than one directional light that you will be able also to find with an affiliate Link in the description down below now anyway let me show you how to use it to only show the shadow over there but first a little side note some of you might have some blurred Shadow over there uh you can actually increase the quality of the Shadow by going for standard pipeline to edit project settings and then here click on quality you can then remove all of the different settings but keep Ultra and then if you go down below you can set the shadow projection to close fit and reduce the shadow distance and this should improve here the quality of your light and by the way if you are not using the standard pipeline but the universal rendering pipeline I highly recommend this tutorial which will also show show you how to improve the look of your Shadow now anyway if we go back to our shadow receiver I'm going to right click on the shadow receiver go to create and then select material this will create a material with the custom Shadow receiver Shader and now if we drag this material onto the plane as you can see it is already working only here the shadow on the plane are appearing not the material of the plane now with this Shader you can change here the color of the Shadows and you can also change the opacity now in my case I will just leave it to this value which I think are nice but if I go to my directional light I think I will probably just set the rotation to be 90 so that the shadow will appears directly under here each element there you go next to better test everything I'm going to duplicate here the cube that we have and place it over there right and the first Cube I'm going to go in is mesh renderer and make the C C Shadow set to off this way we will be able to compare the two Shadow one using the blop Shadow quad that we made and the other using here the shadow receiver plane and there you go basically that is it for the setup but I think it should be better to actually use it not on any plane but on the plane that is placed on our ground so to do this I'm going to select here this plane press on delete to remove it and then if I go to the OVR scene manager that I have on my project if I click on the plus button here I can select here the floor there you go this way if now I click on the plane prefab I can override here the plane prefab that will be used for the floor so let's simply select the plane press on contrl D rename it plane shadow receiver we can double click on this plane to open it because I'm going to select here the Z XY object and remove it I don't want to show here uh the little Gizmo I only want to have here displ mesh renderer and next we are going to go to our custom Shadow receiver material and drag it over there and there we go we can now go back here select the OVR scene manager select the invisible plane but drag now the plain Shadow receiver for the floor prefab there you go now this way the floor that will be used for scene model will have the plain Shadow receiver to display the shadow of our game that is awesome oh and by the way something that is very important but that should be default if we go to our plane shadow receiver by double clicking on it then that you go on the mesh renderer make sure here that the lighting receive Shadow is enabled this will of course make it so that well this plane receive the shadows of your game which is exactly what we want now let's go back and build our game to find out if this is working and there you go guys we can have a look at the two Shadow system that we made for mix rity game on the right side the blop Shadow technique which works great and on the left side the shadow receiver technique which project a shadow on the floor now this is looking awesome and as you can see we can even have the shadow of our controller showing now so everything is looking great and this conclude of course this tutorial which I hope that you enjoyed and of course big shout out to my patreon for supporting my work and which are the one making it possible for me to make this video now anyway if like them you want to get access to exclusive tutorials and the source code of all of my projects join us the link is in the description below thank you for watching and see you soon [Music] bye-bye
Info
Channel: Valem Tutorials
Views: 7,824
Rating: undefined out of 5
Keywords: valem, vr keyboard unity, valem vr, valem tutorials, virtual reality, vr, VR, xr, valem tutorials vr, vr tutorial, vr tutorial for beginners, vr tutorial unity, unity, unity vr, unity vr tutorial, beginner, basic, learn, vr programming, easy, how, to, howto, gamedev, vr dev, vr development, indie gamedev, beginner xr tutorial, how to make a vr game, unity xr toolkit, vr basics tutorial, vr tutorial beginner, vr unity beginner, xr toolkit unity
Id: m4APdFMQIgg
Channel Id: undefined
Length: 13min 54sec (834 seconds)
Published: Mon Nov 13 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.