Wall Cutout in Unity Shader Graph

Поділитися
Вставка
  • Опубліковано 10 гру 2024

КОМЕНТАРІ • 77

  • @danielilett
    @danielilett  3 роки тому +3

    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

    • @johnnilson9039
      @johnnilson9039 2 місяці тому

      "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.

  • @_g_r_m_
    @_g_r_m_ 2 роки тому +4

    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.

  • @Masoniscool9
    @Masoniscool9 3 роки тому +2

    Great video. I really like the effect, and the quality of the tutorial is top-tier. You're doing amazing work!

  • @justinwhite2725
    @justinwhite2725 3 роки тому +6

    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 :)

  • @FTWRahul
    @FTWRahul 3 роки тому +3

    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

    • @danielilett
      @danielilett  3 роки тому +2

      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 :)

    • @garen591
      @garen591 2 роки тому

      @@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

  • @andrewo7369
    @andrewo7369 2 роки тому +6

    How can I fix it if the cutout is in front of the player?

  • @ruhanpotgieter5807
    @ruhanpotgieter5807 3 роки тому +1

    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.

  • @xroadabro
    @xroadabro Рік тому +3

    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?

  • @viva-la-baz1458
    @viva-la-baz1458 Рік тому +1

    it still shows up when in front of the wall though.

  • @TheHungryLemur
    @TheHungryLemur 3 роки тому +3

    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?

    • @Sohneg
      @Sohneg 8 місяців тому

      Did you applied the material on the object?

  • @jovendeligos9539
    @jovendeligos9539 2 роки тому +3

    how do i exclude the shadow?

    • @livelively3845
      @livelively3845 2 роки тому +1

      I am also wondering this @Daniel Ilett
      When I look through my objects shadow disappears too. Any suggestions?

  • @Luka-vb3no
    @Luka-vb3no Рік тому +1

    Can I follow this tutorial whith a built-in shader graph?

    • @danielilett
      @danielilett  Рік тому

      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.

    • @Luka-vb3no
      @Luka-vb3no Рік тому

      @@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 =/

    • @danielilett
      @danielilett  Рік тому

      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.

  • @miloradtanevski9786
    @miloradtanevski9786 3 роки тому +3

    How about stereo for VR? (SinglePass/MultyPass)

    • @anttiv7109
      @anttiv7109 3 місяці тому

      Did you ever get an answer to this?

    • @miloradtanevski9786
      @miloradtanevski9786 2 місяці тому

      ​@@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;}

  • @ymedomri7897
    @ymedomri7897 3 роки тому +1

    weirdly enough the whole wall becomes transparent, even when I rotate the camera. any solution?

  • @harshwardhanjethania
    @harshwardhanjethania 3 роки тому +1

    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

  • @changruizhu7923
    @changruizhu7923 2 роки тому

    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

  • @derBalu
    @derBalu 6 місяців тому

    is it possible to apply this shader and use the effect on other materials?

  • @m4gmar
    @m4gmar 3 роки тому +1

    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...

  • @tomschwrs
    @tomschwrs 2 роки тому +1

    Does this work in 2d too?

  • @liudasbaublys4542
    @liudasbaublys4542 4 місяці тому

    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

    • @liudasbaublys4542
      @liudasbaublys4542 4 місяці тому

      Never mind, managed to accomplish that

    • @m1glw97
      @m1glw97 3 місяці тому

      @@liudasbaublys4542 I have the same problem. Can you tell me how you solved it?

    • @m1glw97
      @m1glw97 3 місяці тому

      @@liudasbaublys4542 And you might now, how to keep the shadows?

    • @liudasbaublys4542
      @liudasbaublys4542 3 місяці тому

      @@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.

    • @m1glw97
      @m1glw97 3 місяці тому

      ​@@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?

  • @nota3xcombo196
    @nota3xcombo196 8 місяців тому

    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?

    • @danielilett
      @danielilett  8 місяців тому

      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.

  • @Spencer_Hill
    @Spencer_Hill 3 роки тому

    Awesome tutorial! My only issue is that I have multiple cutouts overlapping if there's more than one object in the way.

  • @ruhanpotgieter5807
    @ruhanpotgieter5807 3 роки тому

    Great tutorial, thank you very much.

  • @eddierocksuk
    @eddierocksuk 2 роки тому

    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.

    • @danielilett
      @danielilett  2 роки тому

      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.

    • @eddierocksuk
      @eddierocksuk 2 роки тому

      @@danielilett That's great Daniel - thanks😀

  • @Matt-qr7sy
    @Matt-qr7sy 2 роки тому

    hey can you do it the cutout with texture?

  • @michaelcollins47
    @michaelcollins47 Рік тому

    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?

  • @anthonymelo4810
    @anthonymelo4810 3 роки тому +1

    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.

    • @danielilett
      @danielilett  3 роки тому +2

      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!

    • @anthonymelo4810
      @anthonymelo4810 3 роки тому +2

      @@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!

  • @torppe2226
    @torppe2226 2 роки тому

    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?

    • @shiroinoshinigami
      @shiroinoshinigami 2 роки тому

      hey you can mix this video with the "Fade Objects ..." video from @AETutsVids to have the fog effect.

  • @Elmarath
    @Elmarath 2 роки тому

    my main preview is appearing light blue in shader graph. Why that may happen?

    • @timber4785
      @timber4785 Рік тому

      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!

    • @Elmarath
      @Elmarath Рік тому

      @@timber4785 I have already swtich to unreal :D thx anyway

  • @ZZaGGrrUzz
    @ZZaGGrrUzz 2 роки тому

    love the result but it working with only one object (player) is a real bummer

  • @carriganreilly
    @carriganreilly 2 роки тому

    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

    • @danielilett
      @danielilett  2 роки тому

      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? :)

  • @LowLevelLemmy
    @LowLevelLemmy Рік тому

    soemone is going ham on the piano 🔥🔥🔥🔥

  • @moleculedevelopment8909
    @moleculedevelopment8909 2 роки тому

    It works only on editor view, not on camera

  • @daslolo
    @daslolo 3 роки тому

    Doesn't that kill early z rejection?

  • @thesinghzingkid
    @thesinghzingkid 2 роки тому

    Does anybody know how to make this toggle-able?

    • @mateuszpk5511
      @mateuszpk5511 2 роки тому

      You can enable/disable the cutout object script

  • @emagiannu
    @emagiannu 3 роки тому

    This tutorial is great, but what if I have multiple objects and I need multiple holes?

    • @danielilett
      @danielilett  3 роки тому

      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".

    • @emagiannu
      @emagiannu 3 роки тому

      @@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?

    • @danielilett
      @danielilett  3 роки тому +1

      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!

    • @emagiannu
      @emagiannu 3 роки тому

      @@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!

    • @danielilett
      @danielilett  3 роки тому

      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 :)

  • @twobrackets
    @twobrackets 3 роки тому

    THANKSSSSSS!!!!!!

  • @plantedcircle9321
    @plantedcircle9321 Рік тому

    Michael was Here

  • @dude2542
    @dude2542 2 роки тому

    i want you to be in my family