I had tons of fun making this effect! Are there any effects like this that you think I should cover? Comment down below and remember to subscribe! If you enjoyed this effect, consider becoming a Patreon supporter so you can vote on the next shader effect after Snow Layering: www.patreon.com/posts/feb-poll-next-or-47532797
"Are there any effects like this that you think I should cover?" Could you cover cutting a perfectly circular hole in the terrain using a cutout shader? I'm trying to simulate a putting green in golf and I need a way to simulate the golf cup but the terrain holes Unity provides are squares and not circles.
That's a very elegant implementation! In my case i kept an array of all the materials derived from this shader and set the cutoutPos vector foreach material in that array, so I avoid the constant raycast and copying materials while allowing for a smooth transition of the hole between different walls.
My two favourite Unity youtubers haven't posted in awhile (Brackey's quit and I don't know why Jason Wieman hasn't posted in a year). Your channel looks promising so I subbed :)
Hey Daniel, this is an awesome tutorial, I was looking for ways to do this and the stencil buffer methods caused me a lot of headaches in the past. Keep making amazing videos
Thanks! Personally, I really like the stencil buffer method too, but it's an extra thing you have to kind of know about to get it up and running. I'd say an advantage of the stencil method is that it's super easy to control the size of the cutout, but it'd be more difficult to pattern the cutout like in this video. Glad you like the videos, means a lot :)
@@danielilett I think using stencil buffer for see-through is really problematic. For example how do you ensure walls in front of the target object is stencilled away while the walls behind the target remains? A stencil buffer has no concept of depth
For anybody running into the following problem: If you maximize your play viewport the cutout is in the wrong position, but it is fine as long as the play window is not maximized. Switch your play window's (game window) aspect ratio to 16:9 or something other than Free Aspect, then it will be fine.
I love the video. The xray vision effect seems pretty cool. But I've got a question. Would it be possible to cut a whole in the shape of a mesh instead of a square or a circle? If so, how?
It doesn't seem to be working for me. I followed all of your steps. Does it only work on specific object. I'm trying it with a cube and its not working. Does the camera angle have to be something specific?
I think so? To be honest it's been a while since I made this video but I don't believe there is anything that wouldn't be supported by built-in's implementation of Shader Graph. If you encounter any problems then just reply and I'll try to help you out.
@@danielilett Oh thanks for the reply even though the video is quite old haha. So I made a material from built in Shader Graph and one thing I noticed is that it overwrites the wall's material when putting it on the wall object. Basically making it white. And if I try to add it in the mesh renderer array so there are 2 materials on the wall, when walking behind the wall, instead of making the whole wall transparent, it just shows the other material "underneath" the all-white wall. One option is to just take the texture from those wall materials and put it into shader graph MainTex and then it works, but then i'd need to create a new shadergraph material for each texture. But I can't think of any other way and maybe this is how it's supposed to work =/
Yeah, if you add two materials to the same mesh it doesn't always do what you think it'd do - it just renders the mesh twice. So in this case, it draws the normal material, then over it, it draws the cutout material (with a hole in it, so it looks like the first material inside the hole). Your best bet is having two materials for each thing, I think.
@@anttiv7109 i solved it my self, What ever you do in shader graph with camera position, if you want to make it stereo for each camera, use Costume function with two input vector (left and right camera position )and one output vector. This is just one node in the shader graph to alter the camera position node regarding if its left or right eye, and averithing else is the same. And I use script like this inside the costume function if (unity_CameraProjection[0][2] < 0) { OUT = Left;} else { OUT = Right;}
Hey Daniel, really helpful tutorial, can you please make a tutorial to add a door frame out (transparent) to the wall dynamically. I have tried multiple solution but none is working
Is there a way to do the same thing but changing the shape depending on the Object you wanna see through the wall?. For example, in the case of this video the shape of the hole in the wall would be a Cube instead of just a circle...
Hey, could you help with one scenario that I need to fix, lets say there is a house with four walls that is just one object and the player is standing in the middle while the camera is behind a wall. How can I make it so the shader would only apply to the walls only until the player is hit, because right now the hole is cutout in the front wall and the back because it is a single object so the same shader effect applies
@@m1glw97 You need to get the distance between CameraPosition and World Position and then the distance between Camera and Player position and compare these distances.
Hi! I know this is an old video, but I'm running into a dead end and need help. Despite following along and checking my work to the best of my ability, and despite my graph seeming identical, my materials appears completely pink with no shadows and doesn't actually function. Do you know what might be causing this?
Hey! Usually if a material looks pink/magenta and loses its shadows, it's a sign of a shader error. Do you get any errors logged in the console at all? Cos if not, I really have no idea what could be the issue! Also, what Unity version are you using? I don't imagine there's anything in this tutorial that would cause problems in any specific version of Unity or Shader Graph but it might be useful to help you debug the problem you're having.
Daniel - your cutoutsize goes into a 'tidy' node b4 the smoothstep - just an in and out - how go I do one of those / what's the node called? thx I also noticed if you were close to the wall the 'hole' was quite small but if the camera was quite away away it would eat the whole wall! So yes more code needed to work out cutoutsize depending on where you are in the scene.
The little node with just an in and out is the Redirect Node - you can make one by double-clicking any wire between two nodes and it'll pop up where you clicked.
Can this shader accept multiple holes on it? I'm wanting to use this along with a scrolling texture to make Fog of War on a plane that is above my map, which is also on a plane. I want to cut holes in the shader where the user has discovered. What do you think about that?
Can I add this as a second material to an object? I have a material with a specific shader for the overall visuals, I'd like to add this on top and still get the cut out effect. Is that possible? forgive my ignorance, I'm still a noob a shaders.
I don't think that would be possible using this specific shader unfortunately. My shader can't delete bits from other materials. What you could try (although it requires shader code) is stencils - Daniel Santalla has a very helpful and very short tutorial on this: ua-cam.com/video/0rEF8A3wF9U/v-deo.html. You would need to tweak your existing shader a bit (in his tutorial, that's step 3) and add a bit of scripting, but hopefully the video gives you enough to go on. Also you don't have to ask for forgiveness, that's what asking questions are for :D good luck on your shader journey!
@@danielilett Thank you for the response! This definitely helped, I was approaching it all wrong but I have much better direction now. Also, thanks for creating a welcoming environment for questions like mine!
Hi, great video as always! I'm trying to get kind of a "fog of war" effect, where depending on which level area we are at, only show that area to the player. I would like to have kind of a misty outline for the cutout that actually moves. How would you approach this kind of a problem?
I acknowledge you posted this comment 8 months ago, but if you still want to know why, that's because the shader hasn't rendered on the preview object (and therefore uses a light blue fallback texture instead). Although the preview turning blue is a unity bug, you can fix it by clicking and dragging off of the middle of the main preview window. This updates the shader's preview manually and should fix the light blue appearance bug. Hope this helps!
I know this video is old, but what material and object do I apply the cutout to? should i be applying the cutout to the walls, player, or other object? the cutout is either always on or always off and im at a bit of a loss for what to do
The cutout material should be applied to just the walls. If the cutout is always on or always off, then you might need to tweak the Cutout Size property. The Unity project I created for this video is on GitHub - I know it's a bit of a big download but that has everything set up exactly how I show in the video so maybe that will give you some pointers with how to proceed? :)
I use RaycastAll in the scripting section to get every wall in a line between the camera and the target object. However! If you have two walls adjacent, you're right, you'll need something different. You can probably use Physics.SphereCastAll, as it's sorta like a "raycast with thickness".
@@danielilett That's not exactly what I meant. You pass one Vector3 to the shader, which is the center of the hole. That means you can have only one hole per material (I didn't test it, but I'm quite sure that's how it works). What if I have 2 "CutoutObject" behind a single wall? I don't think you can pass an array of Vector3s. The only thing that I can think of is to have, let's say, three parameters (CutoutPos1, CutoutPos2, CutoutPos3), and edit the shader around that. Do you think it's possible to pass to the shader and array of parameters?
Ahh I see what you mean! Yeah, unfortunately you can't use vector arrays in Shader Graph, which is a shame, although you can with shader code. I don't know why there's that difference. You could use multiple properties as you've suggested - then you could stick the core behaviour of the graph in a Sub Graph and just repeat it three times, once for each cutout. Or you could do a workaround like encoding the cutout pos vectors inside a lookup texture. Shader Graph does support texture array properties, so I think you could encode the screen-space position vector inside the RGB components of a 1x1 texture per cutout. That's probably even more annoying and quite heavy-handed for this use case. Honestly I'd stick with multiple properties if you know exactly how many cutouts you'd need!
@@danielilett Thanks for the answer, I really appreciated it! Encoding the positions in a Texture is a fascinating solution, but since Shader Graph doesn't have a way to loop trough every slot, I'd say that gets complicated incredibly fast. Anyway, thanks again for the help!
No worries! I wonder if looping will ever become available in Shader Graph too, because that would be very powerful indeed. Hope you can get the effect you wanted either way :)
I had tons of fun making this effect! Are there any effects like this that you think I should cover? Comment down below and remember to subscribe!
If you enjoyed this effect, consider becoming a Patreon supporter so you can vote on the next shader effect after Snow Layering: www.patreon.com/posts/feb-poll-next-or-47532797
"Are there any effects like this that you think I should cover?" Could you cover cutting a perfectly circular hole in the terrain using a cutout shader? I'm trying to simulate a putting green in golf and I need a way to simulate the golf cup but the terrain holes Unity provides are squares and not circles.
That's a very elegant implementation! In my case i kept an array of all the materials derived from this shader and set the cutoutPos vector foreach material in that array, so I avoid the constant raycast and copying materials while allowing for a smooth transition of the hole between different walls.
Great video. I really like the effect, and the quality of the tutorial is top-tier. You're doing amazing work!
My two favourite Unity youtubers haven't posted in awhile (Brackey's quit and I don't know why Jason Wieman hasn't posted in a year). Your channel looks promising so I subbed :)
Just letting you know that jason weimann post every 2-3 days
Hey Daniel, this is an awesome tutorial, I was looking for ways to do this and the stencil buffer methods caused me a lot of headaches in the past. Keep making amazing videos
Thanks! Personally, I really like the stencil buffer method too, but it's an extra thing you have to kind of know about to get it up and running. I'd say an advantage of the stencil method is that it's super easy to control the size of the cutout, but it'd be more difficult to pattern the cutout like in this video. Glad you like the videos, means a lot :)
@@danielilett I think using stencil buffer for see-through is really problematic. For example how do you ensure walls in front of the target object is stencilled away while the walls behind the target remains? A stencil buffer has no concept of depth
How can I fix it if the cutout is in front of the player?
For anybody running into the following problem: If you maximize your play viewport the cutout is in the wrong position, but it is fine as long as the play window is not maximized. Switch your play window's (game window) aspect ratio to 16:9 or something other than Free Aspect, then it will be fine.
I love the video. The xray vision effect seems pretty cool. But I've got a question. Would it be possible to cut a whole in the shape of a mesh instead of a square or a circle? If so, how?
it still shows up when in front of the wall though.
It doesn't seem to be working for me. I followed all of your steps. Does it only work on specific object. I'm trying it with a cube and its not working. Does the camera angle have to be something specific?
Did you applied the material on the object?
how do i exclude the shadow?
I am also wondering this @Daniel Ilett
When I look through my objects shadow disappears too. Any suggestions?
Can I follow this tutorial whith a built-in shader graph?
I think so? To be honest it's been a while since I made this video but I don't believe there is anything that wouldn't be supported by built-in's implementation of Shader Graph. If you encounter any problems then just reply and I'll try to help you out.
@@danielilett Oh thanks for the reply even though the video is quite old haha. So I made a material from built in Shader Graph and one thing I noticed is that it overwrites the wall's material when putting it on the wall object. Basically making it white. And if I try to add it in the mesh renderer array so there are 2 materials on the wall, when walking behind the wall, instead of making the whole wall transparent, it just shows the other material "underneath" the all-white wall. One option is to just take the texture from those wall materials and put it into shader graph MainTex and then it works, but then i'd need to create a new shadergraph material for each texture. But I can't think of any other way and maybe this is how it's supposed to work =/
Yeah, if you add two materials to the same mesh it doesn't always do what you think it'd do - it just renders the mesh twice. So in this case, it draws the normal material, then over it, it draws the cutout material (with a hole in it, so it looks like the first material inside the hole). Your best bet is having two materials for each thing, I think.
How about stereo for VR? (SinglePass/MultyPass)
Did you ever get an answer to this?
@@anttiv7109
i solved it my self,
What ever you do in shader graph with camera position,
if you want to make it stereo for each camera, use Costume function with two input vector (left and right camera position )and one output vector.
This is just one node in the shader graph to alter the camera position node regarding if its left or right eye, and averithing else is the same.
And I use script like this inside the costume function
if (unity_CameraProjection[0][2] < 0) { OUT = Left;}
else { OUT = Right;}
weirdly enough the whole wall becomes transparent, even when I rotate the camera. any solution?
Hey Daniel, really helpful tutorial, can you please make a tutorial to add a door frame out (transparent) to the wall dynamically. I have tried multiple solution but none is working
Thx so much for your tutorial!!! could you please tell me how to do the taxicab distance? I'd like to have a square effect
is it possible to apply this shader and use the effect on other materials?
Is there a way to do the same thing but changing the shape depending on the Object you wanna see through the wall?. For example, in the case of this video the shape of the hole in the wall would be a Cube instead of just a circle...
Does this work in 2d too?
Hey, could you help with one scenario that I need to fix, lets say there is a house with four walls that is just one object and the player is standing in the middle while the camera is behind a wall. How can I make it so the shader would only apply to the walls only until the player is hit, because right now the hole is cutout in the front wall and the back because it is a single object so the same shader effect applies
Never mind, managed to accomplish that
@@liudasbaublys4542 I have the same problem. Can you tell me how you solved it?
@@liudasbaublys4542 And you might now, how to keep the shadows?
@@m1glw97 You need to get the distance between CameraPosition and World Position and then the distance between Camera and Player position and compare these distances.
@@liudasbaublys4542 Hi thanks for the reply. Im really shot in Shader Graph can you tell me jow i can do it or you maybe still have your solution?
Hi! I know this is an old video, but I'm running into a dead end and need help.
Despite following along and checking my work to the best of my ability, and despite my graph seeming identical, my materials appears completely pink with no shadows and doesn't actually function. Do you know what might be causing this?
Hey! Usually if a material looks pink/magenta and loses its shadows, it's a sign of a shader error. Do you get any errors logged in the console at all? Cos if not, I really have no idea what could be the issue! Also, what Unity version are you using? I don't imagine there's anything in this tutorial that would cause problems in any specific version of Unity or Shader Graph but it might be useful to help you debug the problem you're having.
Awesome tutorial! My only issue is that I have multiple cutouts overlapping if there's more than one object in the way.
Great tutorial, thank you very much.
Daniel - your cutoutsize goes into a 'tidy' node b4 the smoothstep - just an in and out - how go I do one of those / what's the node called? thx
I also noticed if you were close to the wall the 'hole' was quite small but if the camera was quite away away it would eat the whole wall! So yes more code needed to work out cutoutsize depending on where you are in the scene.
The little node with just an in and out is the Redirect Node - you can make one by double-clicking any wire between two nodes and it'll pop up where you clicked.
@@danielilett That's great Daniel - thanks😀
hey can you do it the cutout with texture?
Can this shader accept multiple holes on it? I'm wanting to use this along with a scrolling texture to make Fog of War on a plane that is above my map, which is also on a plane. I want to cut holes in the shader where the user has discovered. What do you think about that?
Can I add this as a second material to an object? I have a material with a specific shader for the overall visuals, I'd like to add this on top and still get the cut out effect. Is that possible?
forgive my ignorance, I'm still a noob a shaders.
I don't think that would be possible using this specific shader unfortunately. My shader can't delete bits from other materials.
What you could try (although it requires shader code) is stencils - Daniel Santalla has a very helpful and very short tutorial on this: ua-cam.com/video/0rEF8A3wF9U/v-deo.html. You would need to tweak your existing shader a bit (in his tutorial, that's step 3) and add a bit of scripting, but hopefully the video gives you enough to go on.
Also you don't have to ask for forgiveness, that's what asking questions are for :D good luck on your shader journey!
@@danielilett Thank you for the response! This definitely helped, I was approaching it all wrong but I have much better direction now.
Also, thanks for creating a welcoming environment for questions like mine!
Hi, great video as always! I'm trying to get kind of a "fog of war" effect, where depending on which level area we are at, only show that area to the player. I would like to have kind of a misty outline for the cutout that actually moves. How would you approach this kind of a problem?
hey you can mix this video with the "Fade Objects ..." video from @AETutsVids to have the fog effect.
my main preview is appearing light blue in shader graph. Why that may happen?
I acknowledge you posted this comment 8 months ago, but if you still want to know why, that's because the shader hasn't rendered on the preview object (and therefore uses a light blue fallback texture instead). Although the preview turning blue is a unity bug, you can fix it by clicking and dragging off of the middle of the main preview window. This updates the shader's preview manually and should fix the light blue appearance bug. Hope this helps!
@@timber4785 I have already swtich to unreal :D thx anyway
love the result but it working with only one object (player) is a real bummer
I know this video is old, but what material and object do I apply the cutout to?
should i be applying the cutout to the walls, player, or other object?
the cutout is either always on or always off and im at a bit of a loss for what to do
The cutout material should be applied to just the walls. If the cutout is always on or always off, then you might need to tweak the Cutout Size property. The Unity project I created for this video is on GitHub - I know it's a bit of a big download but that has everything set up exactly how I show in the video so maybe that will give you some pointers with how to proceed? :)
soemone is going ham on the piano 🔥🔥🔥🔥
It works only on editor view, not on camera
Doesn't that kill early z rejection?
Does anybody know how to make this toggle-able?
You can enable/disable the cutout object script
This tutorial is great, but what if I have multiple objects and I need multiple holes?
I use RaycastAll in the scripting section to get every wall in a line between the camera and the target object. However! If you have two walls adjacent, you're right, you'll need something different. You can probably use Physics.SphereCastAll, as it's sorta like a "raycast with thickness".
@@danielilett That's not exactly what I meant. You pass one Vector3 to the shader, which is the center of the hole. That means you can have only one hole per material (I didn't test it, but I'm quite sure that's how it works). What if I have 2 "CutoutObject" behind a single wall? I don't think you can pass an array of Vector3s. The only thing that I can think of is to have, let's say, three parameters (CutoutPos1, CutoutPos2, CutoutPos3), and edit the shader around that. Do you think it's possible to pass to the shader and array of parameters?
Ahh I see what you mean! Yeah, unfortunately you can't use vector arrays in Shader Graph, which is a shame, although you can with shader code. I don't know why there's that difference.
You could use multiple properties as you've suggested - then you could stick the core behaviour of the graph in a Sub Graph and just repeat it three times, once for each cutout.
Or you could do a workaround like encoding the cutout pos vectors inside a lookup texture. Shader Graph does support texture array properties, so I think you could encode the screen-space position vector inside the RGB components of a 1x1 texture per cutout. That's probably even more annoying and quite heavy-handed for this use case.
Honestly I'd stick with multiple properties if you know exactly how many cutouts you'd need!
@@danielilett Thanks for the answer, I really appreciated it! Encoding the positions in a Texture is a fascinating solution, but since Shader Graph doesn't have a way to loop trough every slot, I'd say that gets complicated incredibly fast. Anyway, thanks again for the help!
No worries! I wonder if looping will ever become available in Shader Graph too, because that would be very powerful indeed. Hope you can get the effect you wanted either way :)
THANKSSSSSS!!!!!!
Michael was Here
i want you to be in my family