Wall Cutout in Unity Shader Graph

Поделиться
HTML-код
  • Опубликовано: 7 ноя 2024

Комментарии • 76

  • @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 Месяц назад

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

  • @andrewo7369
    @andrewo7369 2 года назад +6

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

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

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

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

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

  • @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 7 месяцев назад

      Did you applied the material on the object?

  • @derBalu
    @derBalu 5 месяцев назад

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

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

  • @LowLevelLemmy
    @LowLevelLemmy Год назад

    soemone is going ham on the piano 🔥🔥🔥🔥

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

  • @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 Год назад

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

  • @viva-la-baz1458
    @viva-la-baz1458 Год назад +1

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

  • @ymedomri7897
    @ymedomri7897 3 года назад +1

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

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

  • @Luka-vb3no
    @Luka-vb3no 11 месяцев назад +1

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

    • @danielilett
      @danielilett  11 месяцев назад

      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 11 месяцев назад

      @@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  11 месяцев назад

      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.

  • @nota3xcombo196
    @nota3xcombo196 7 месяцев назад

    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  7 месяцев назад

      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.

  • @miloradtanevski9786
    @miloradtanevski9786 3 года назад +3

    How about stereo for VR? (SinglePass/MultyPass)

    • @anttiv7109
      @anttiv7109 Месяц назад

      Did you ever get an answer to this?

    • @miloradtanevski9786
      @miloradtanevski9786 Месяц назад

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

  • @tomschwrs
    @tomschwrs 2 года назад +1

    Does this work in 2d too?

  • @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: ruclips.net/video/0rEF8A3wF9U/видео.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!

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

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

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

  • @liudasbaublys4542
    @liudasbaublys4542 3 месяца назад

    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 3 месяца назад

      Never mind, managed to accomplish that

    • @m1glw97
      @m1glw97 2 месяца назад

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

    • @m1glw97
      @m1glw97 2 месяца назад

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

    • @liudasbaublys4542
      @liudasbaublys4542 2 месяца назад

      @@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 2 месяца назад

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

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

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

  • @moleculedevelopment8909
    @moleculedevelopment8909 2 года назад

    It works only on editor view, not on camera

  • @ZZaGGrrUzz
    @ZZaGGrrUzz 2 года назад

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

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

  • @daslolo
    @daslolo 3 года назад

    Doesn't that kill early z rejection?

  • @Matt-qr7sy
    @Matt-qr7sy 2 года назад

    hey can you do it the cutout with texture?

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

  • @thesinghzingkid
    @thesinghzingkid 2 года назад

    Does anybody know how to make this toggle-able?

    • @mateuszpk5511
      @mateuszpk5511 2 года назад

      You can enable/disable the cutout object script

  • @dude2542
    @dude2542 2 года назад

    i want you to be in my family

  • @plantedcircle9321
    @plantedcircle9321 Год назад

    Michael was Here