Shaders 103 - Using Replacement Shaders

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

КОМЕНТАРІ • 121

  • @aFewBitsShort
    @aFewBitsShort 8 років тому +79

    You're da real MVP.

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

    I saw an article for adding SSR in Forward Rendering, and I was really confused when I saw them mention replacement shaders. Thank you so much for your help!

  • @PushyPixels
    @PushyPixels 8 років тому +77

    My goodness I am so jealous of your tutorials. How much time do you spend on the diagrams and editing? Your hard work has resulted in easily the best series on shaders available anywhere. And I am going to be bookmarking a link to 1:09 so I have it at the ready next time I need to explain MVP to a coworker.

  • @PawelStoleckiTechArt
    @PawelStoleckiTechArt 6 років тому +9

    ""You've watched 20min of shdaer tutorial so now you are basically an expert"made my day

  • @SheepUndefined
    @SheepUndefined 7 років тому

    Writing shaders to me has always been one of those things that perfectionists do when they aren't satisfied with having less control, but this video's the first one to actually show me the effects that they can handle. Which...pretty much every video in this channel's making me realize this, so...thanks for introducing me to the visual side of this program. ^^

  • @THE_G0AlAPAGOS
    @THE_G0AlAPAGOS 7 років тому +2

    Man Please , we need more .

  • @TayoTheT1000
    @TayoTheT1000 7 років тому +2

    I love your style of teaching. I really wish more people taught with as interesting and entertaining style as you do. Thanks :)

  • @WesaY07
    @WesaY07 8 років тому +4

    Ohh, so this explains Metroid Prime's thermal and x-ray vision! Brilliant video!
    Now I have to take some long ass time to learn the thing that I know about the least... creating shaders.

  • @Jazuhero
    @Jazuhero 8 років тому

    This is great! Shaders have always felt a bit like wizardry to me, so it's really amazing to see how even a few simple examples like these can create such cool effects! Thanks again for a great video!

  • @QckSGaming
    @QckSGaming 5 років тому

    After watching many of your shader videos I'm certain that I'm taking all the shader courses at my uni. Love your vids!

  • @SirNightmareFuel
    @SirNightmareFuel 8 років тому

    Wow, the editing quality is off the charts!

  • @yrekinger
    @yrekinger 8 років тому

    These are great ! I'm experimenting with shaders and find your content highly enlightening. I hope to see more, good job !

  • @blakeschreurs
    @blakeschreurs 7 років тому

    This solved a host of minor issues that'd been plaguing me for months (I had been using projectors). Thank you, thank you, thank you!

  • @jiratrello
    @jiratrello 8 років тому

    Loving your videos! Defs a much needed series.

  • @notsoren665
    @notsoren665 8 років тому +9

    Yay! Love the intro

  • @sma-mn5xe
    @sma-mn5xe 2 роки тому

    your videos are fantastic bro, excellent work :)
    I have started messing around with shaders in unity and your videos helped me a lot. thanks for that.

  •  4 роки тому

    Love how clear everythings sounds, thank you so much!

  • @adamwhitehurst
    @adamwhitehurst 8 років тому

    Another great video and I love the additional resources!

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

    @DanMoranGameDev In the fragment shader, ( 3:06 in the video ), how would you invert the scene so that white is far away and black is close up? And is there a way to get rid of the color component of this shader, such that it stays in grayscale without reading the models colors? Thanks for awesome tutorials!

  • @WonkyGames
    @WonkyGames 6 років тому +2

    Quick note for anyone trying this out for the first time, like myself. Make sure you're in forward rendering! I spent longer than I'd like to admit trying to figure out what was wrong before remembering I'd set my current project to use the deferred pipeline.
    While I'm here, how would I edit this to work with deferred?

  • @bobsmithy3103
    @bobsmithy3103 5 років тому

    Does anyone know why the camera is facing the negative z axis instead of the positive? 2:44

  • @rupeshmandke
    @rupeshmandke 8 років тому

    These are some neat tutorials!

  • @bulalaish
    @bulalaish 8 років тому

    greatgreat. I really like your tutorials. very good audio/video combination
    keep them shader tuts coming! :)

  • @rollizle
    @rollizle 4 роки тому

    Yo this seems awesome! Gotta play around with this.

  • @AlexTuduran
    @AlexTuduran 6 років тому

    Very nice presentation style and all is explained well. You got my sub.

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

    What's the type of shader you're using??? 0:55

  • @peiiiii5784
    @peiiiii5784 7 років тому +1

    This is so helpful! I hope i can press the like button for a hundred times.

  • @lehanru
    @lehanru 8 років тому

    This stuff makes me look good ! Thanks

  • @RUSOBPK
    @RUSOBPK 5 років тому

    Can i use this to avoid overdraw? Giving the camera a depth pass maybe can tell what objects are front and behind?... im working on a vr oculus go project and we have some lagging in a forest scene because of that (or at least thats what i think)

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

    The links got truncated in description and no longer work

  • @karanpratapsingh5022
    @karanpratapsingh5022 5 років тому +1

    Hi fellow Shaderers!
    For more clarity on the matrix transformations, the diagram on this page makes it crystal clear how the transformations affect the vertices.
    learnopengl.com/Getting-started/Coordinate-Systems

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

    I am trying to make a grass shader that will offset the vertices of a subdived plane in the Y-axis and X-axis,
    but instead of World X and Y direction, it offsets interms of my screen instead,
    how to offset them interms of world coordinate ?

  • @ThePatrvq
    @ThePatrvq 8 років тому +1

    what is teh diference in writing old style and PBR shaders ?
    Shall i learn the old way before i move to PBR? is it big deal anyways (in shader code) ?:)
    How would You recomend to start leraning shaders for Unity ? Do You know some good courses to start?
    I have 3 DVD`s about HLSL from CG Academy by Ben Cloward, is it worth to start there ?

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

    Can you do replacement shaders in URP?

  • @CL3NRcProductions
    @CL3NRcProductions 6 років тому

    I want to know how to remake the krasue's vision from eyes the horror game. i think its a shader, but i dont know where i can find it, or if i can find it. i tried to look in the game files, but most of the shaders didnt work on my GPU. or so it said. i have noticed that objects sway and wave, the colors are inverted, and theres some weird lights that look kinda like echolocation. ua-cam.com/video/8GuSvjvVEq8/v-deo.html

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

    Using something that renderers based on a ruleset is one thing, but how would I go around rendering 2 different texture sets, based on the shader being used?
    I know I can duplicate the object on another layer to get the same effect, but that can be costly.
    Any ideas?

  • @HariEdoTV
    @HariEdoTV 6 років тому

    It looks like the special shaders aren't ready as-is for the new Lightweight Render Pipeline in 2018.1. I can swap the materials to LWP equivalents, but the glow and overdraw effects are silently ignored. Would love to see an update if the pipeline supports it.

  • @createthisdotcom
    @createthisdotcom 7 років тому +2

    I love these videos. Also, you pronounce opaque as opeg. Kinda weird. But I still love these videos.

  • @Jorge-vv8cy
    @Jorge-vv8cy 4 роки тому

    Im trying to make a vertex lit replacement shader but when i set the tag "LightMode" = "Vertex" the shader stops showing. Not even pink. ¿What could be going wrong?

  • @xXBlackWorkXx
    @xXBlackWorkXx 7 років тому +4

    download of assets is broken :(

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

    The link to the assets in this videos description is broken for me. Anyone else? Tried opening in Chrome and internet explorer.

  • @countingdemonstudios7181
    @countingdemonstudios7181 5 років тому

    This was a little advanced for me but I still found it very interesting to watch, absentmindedly, as I took a bath :p

  • @chriswalch9359
    @chriswalch9359 5 років тому +1

    For those in Unity 2019... no more UNITY_MATRIX_MVP or UNITY_MATRIX_MV substitute these lines instead...
    o.vertex = UnityObjectToClipPos(v.vertex);
    o.depth = -UnityObjectToViewPos(v.vertex).z *_ProjectionParams.w;
    You're welcome :)

    • @frattapa
      @frattapa 5 років тому +3

      For anyone who needs it, I'll post the whole code here:
      Shader "Hidden/Replacement"
      {
      SubShader
      {
      Tags { "RenderType"="Opaque" }
      Pass
      {
      CGPROGRAM
      #pragma vertex vert
      #pragma fragment frag
      #include "UnityCG.cginc"
      struct appdata
      {
      float4 vertex : POSITION;
      };
      struct v2f
      {
      float4 vertex : SV_POSITION;
      float depth : DEPTH;
      };
      v2f vert (appdata v)
      {
      v2f o;
      o.vertex = UnityObjectToClipPos(v.vertex);
      o.depth = -UnityObjectToViewPos(v.vertex).z * _ProjectionParams.w;
      return o;
      }
      fixed4 frag (v2f i) : SV_Target
      {
      float invert = 1 - i.depth;
      return fixed4(invert,invert,invert,.5);
      }
      ENDCG
      }
      }
      }

  • @AdamX21198
    @AdamX21198 7 років тому

    Does this allow me to write shaders that change depending on the rendering path? I'm confused as to what the purpose of these kinds of shaders might be.

  • @MrMinebase
    @MrMinebase 5 років тому

    I know this video is a little bit old so I might not get a reaction but I have a question.
    For my project I am trying to create an infrared shader. I thaught it was smart to use replacement shaders for this but now I run into the problem that I want to have a color array and a float array. But I don't know how to give these arrays values. It doesn't seem you can just say: " Shader.SetGlobalFloatArray("_SpectrumValues", spectrumStartValues);".
    Can I use Shader.SetGlobalFloatArray for this or do I need use a different method?

  • @erfanroghani
    @erfanroghani 5 років тому

    When I start to use your shader on a material I get: Shader warning in 'ShowDepth': Shader is not supported on this GPU (none of subshaders/fallbacks are suitable). How can I fix it?

  • @notsoren665
    @notsoren665 8 років тому

    Hey, can you make a tutorial on changing colors perceived by the camera, both for sprites and ui. Like in the game downwell.

  • @Guitoon
    @Guitoon 5 років тому

    Hi ! I'm learning shaders step by step and your lessons help me a lot !
    But I have some questions in my mind like :
    In the final project, in the "QuickBlur" shader, in v2f structure, I saw it has a "HALFTEXEL" type but I found any references of it in any forum or documentation.
    Does it means you can specify any random type you want if you need or is it a real type name in shader lab ?

  • @roggincz
    @roggincz 8 років тому +7

    You are a wizzard!

  • @slimabob
    @slimabob 8 років тому +4

    Hey, could you make a video to serve as an extension of this one that shows how the creators of Shadow of Mordor achieved their Wraith Mode effect (Maybe a case study)? Here's a video if you're unfamiliar with the effect: ua-cam.com/video/isl18AP36PA/v-deo.html
    I was wondering not only how they achieved the important objects / enemies standing out through terrain, but also how they achieved the transformation effect between Talon and Celebrimbor.

  • @ChristopherSummer89
    @ChristopherSummer89 7 років тому

    Can you tell me whether it would be possible that an ImageEffect I am coding could interpret all transparent Textures as Alpha Cutout, even if they are not actually Cutout and I don't want them to be replaced either, I just wish my ImageEffect could interpret them as if they were Alpha Cutout, so they would be at Least approximately represented in the DepthTexture? That would be extremely helpful for a Volumetric Lighting Effect I am working on in Unity.

    • @DanMoranGameDev
      @DanMoranGameDev  7 років тому

      There's no good way to write depth values for transparent meshes that won't cause weird artifacts. If they wrote depth, they would draw incorrectly, as transparent geo typically draws back-to-front. Near objects would be z-culled by transparent objects behind them in a way that is probably not what you'd want.
      Now because Unity sometimes does the DepthTexture as a pre-pass instead of taking it directly from the Z buffer (I think PC is always pre-pass), you could make sure your transparent shaders have the proper depth writing pass. Unity shares the shadowcaster light mode- look at the built in shader "Normal-VertexLit" for an example.
      But depending on how you're using this depth texture and whether or not transparent stuff is partially see-thru, your image effect might look kind of broken.
      A last ditch effort that could work depending again on how you use the texture, you could do what Transparent shadow casters do. Shadow Casting is also just a depth texture, and to cast shadows from transparent objects, transparent meshes are dithered in the depth texture. This method relies on PCF or some other multi-tap soft shadow sampling to create the illusion of an accurate shadow for a transparent mesh. This is why transparent shadows have a screen-door/check-board effect when casting hard shadows.
      Hope this shines some light on your situation (hue hue hue)! I'd love to see your effect so feel free to share :)

  • @haydocc
    @haydocc 8 років тому

    So if I had a shader that I wanted to switch different materials onto it to change effects on the fly, would using a replacement shader script work? I've been trying to use an array of textures to apply to just one shader, can't get it working so I'm just looking at other possibilities.

    • @DanMoranGameDev
      @DanMoranGameDev  8 років тому

      Switching materials is not quite the same. Materials are just a reference to a shader with a set of keywords and values defined. If what you're trying to do is switch materials that use the same underlying shader, than replacement shaders might not be the correct solution.
      If what you need is a dynamic texture in your shader, than perhaps a rendertexture is what you're after?

  • @Biuret.
    @Biuret. 8 років тому

    Exelent tutorial, thank you for good quality videos. I have a question, how can I use a DX11 geomeyry replacement shader? Like for example a wireframe shader (UCLA for example)? Thank you.

  • @maksj-lewis4504
    @maksj-lewis4504 6 років тому +1

    hey dude can you do a video on stecils and depth buffer? much love

  • @animatorosoro9985
    @animatorosoro9985 5 років тому

    Does thsi replacement shader saves performance since texture is not rendered

  • @linusreimertz2850
    @linusreimertz2850 7 років тому +1

    could you make a video on water shaders?(:

  • @_D3adB0y_
    @_D3adB0y_ 8 років тому

    Awesome info! Is there a way to assign actual color to the zdepth so that I can change the start and end colors of the shader, essentially acting like a gradient map?

    • @_D3adB0y_
      @_D3adB0y_ 8 років тому

      This is the look I am trying to recreate: 66.media.tumblr.com/5d8bd286a99739858b4de0f3bac1854f/tumblr_o70ltkru8Z1rte5gyo4_500.gif

  • @DarekLosu
    @DarekLosu 7 років тому

    Extremely helpful, thank you!
    I'm making mobile games in Unity and I've noticed that in the Scene View when using Alpha Channel mode most objects are rendered as white (which means they are being rendered as transparent objects?), even when shaders are using "Opaque" queue with fragment shader setting alpha to 1, or even built-in ones like Mobile/Diffuse. Is it just a Unity quirk or are those objects really rendered as transparent objects? How to write a shader that would not be visible in the Alpha Channel view?
    The only way I've found so far is to use ColorMask RGB, but from what I've read it's actually slower (my tests show that it's true in some cases) and my main goal is to make those shaders as fast as possible and not treat opaque geometry as potentially transparent objects...

    • @DanMoranGameDev
      @DanMoranGameDev  7 років тому

      Actually Opaque objects will still write an alpha value if their fragment shader says to do so! You can use this to your advantage in many cases to pack in a hidden value, visible to image effects but that doesn't actually effect the look of an opaque objects. It's often used for masked bloom/emissive effects, but there are mobile games that pack in a depth value here to get cheaper depth field effects as well.

    • @DarekLosu
      @DarekLosu 7 років тому

      Thank you for quick answer!
      So what you're saying is that I should completely ignore the fact that those shader are writing an alpha channel value and that it doesn't affect performance, and they are not treated as potentially transparent objects?

    • @DanMoranGameDev
      @DanMoranGameDev  7 років тому

      DarekLosu correct, writing to the alpha channel is not what delineates something as transparent and doesn't cause performance issues.

  • @areebraza8262
    @areebraza8262 7 років тому

    can i possibly set certain objects a specific color? like give enemies a red color and the rest is blue?

    • @DanMoranGameDev
      @DanMoranGameDev  7 років тому

      Certainly. Just use a Color material property. Properties are inherited by the replacement shader remember.

  • @Ywinfull
    @Ywinfull 8 років тому

    Your tutorials are neat and useful thanks a lot BUT I have a question ! I played with it a little bit but when building a Stand-Alone it seems to stop working : the screen is filled with the camera background color. I looked into player settings, graphics settings, checked if the shader were in the build... I will look further into it and I might be missing something but if you have an idea ?

    • @DanMoranGameDev
      @DanMoranGameDev  8 років тому

      fabY definitely sounds like the shader is not on the build. Try referencing it with a public field in the inspector and also try putting the shader in to a Resource folder. I'll take a look when I can and correct the example files :)

    • @Ywinfull
      @Ywinfull 8 років тому

      I actually tried it yesterday the shader is in the build. What doesn't work it the Shader.SetGlobalColor() function !
      edit 5minutes later: of course how did I miss that haha, it is called in OnValidate() which... is called in the editor only :'D. Nevermind then x)

  • @barax9462
    @barax9462 7 років тому

    Please i need the book you are basing your knowledge on.

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

    Is this possible using URP shaders?

  • @subliminalman
    @subliminalman 8 років тому

    These shaders seem to only work in forward rendering mode on the camera. Am I wrong or do these not work with deferred?

    • @DanMoranGameDev
      @DanMoranGameDev  8 років тому +1

      +subliminalman Just tried them out: the OverDraw effect continues to work normally. For the ShowDepth effect, you have to specify a "Queue" tag that is greater than the skybox value of 2500. So "Geometry+501" would work.
      I ran into a lot of weirdness with the skybox and clear settings that I couldn't find documentation on while making this video. I guess I missed that it get's even weirder in deferred mode! Ahh well, that solution should work for you nevertheless.

  • @matthewbucher8098
    @matthewbucher8098 8 років тому

    Would you be able to throw the different shader scripts up on pastebin or something, and link them?

    • @DanMoranGameDev
      @DanMoranGameDev  8 років тому

      +Matthew Bucher They are linked in the description as a unitypackage file. Would you prefer a plain text as well?

    • @matthewbucher8098
      @matthewbucher8098 8 років тому

      +Makin' Stuff Look Good Ah didn't realize that was a direct download link xD Nope, this works just fine!

  • @stanislavkaliuk5659
    @stanislavkaliuk5659 8 років тому

    In QuickBlur.shader you use HALFTEXEL semantic, but in shaders and CG/HLSL manuals this semantic isn`t exist.
    Where you get information about this semantic?

    • @DanMoranGameDev
      @DanMoranGameDev  8 років тому +1

      I'm dumb. Just use "TEXCOORDX" where X is a number 0 through 7 for additional interpolators.

    • @stanislavkaliuk5659
      @stanislavkaliuk5659 8 років тому

      Thanks

  • @uchihai_a_h4871
    @uchihai_a_h4871 4 роки тому

    Didn't get that point saying replacement shader keeps the material properties. You just multiplied the the color of value (1,1,1,1) . so where is the other shader property(which got replaced). I am no expert its just a guess.

  • @paritoshvaidya9629
    @paritoshvaidya9629 4 роки тому

    nice work

  • @ReleeSquirrel
    @ReleeSquirrel 8 років тому

    So you seem like someone who knows a lot about Shaders and likes to share that knowledge. I'm trying to make a mask shader for a 2D game to hide things that would normally be displayed on screen. Any tips? If you want to make a full on tutorial for making one, I'm pretty sure I'm not the only one struggling with this.

    • @dex6596
      @dex6596 8 років тому

      Unity has experimental build for 2D where this is included

    • @ReleeSquirrel
      @ReleeSquirrel 8 років тому

      I've seen video of it but it seemed like they kept adding and removing that feature from the beta. Is it stable now?

  • @beamingxylophone
    @beamingxylophone 8 років тому

    Is it possible to create shaders like in "Fitness Evolved KINECT" in unity 3d??? If it is can you tell me how????

    • @purpleice2343
      @purpleice2343 7 років тому

      It has nothing to do with Unity, only with Shader language it uses and your brain.

    • @beamingxylophone
      @beamingxylophone 7 років тому

      So umm..do you have it?? I mean can can you do it?

    • @purpleice2343
      @purpleice2343 7 років тому +1

      Do I look like a developer of that game?

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

    haha the intro got me

  • @liangyue3325
    @liangyue3325 8 років тому

    good tutorial!

  • @AhsanUllah-yp1uu
    @AhsanUllah-yp1uu 6 років тому

    make complete video or link to this shade er download.................................

  • @crter
    @crter 7 років тому

    Super Great!

  • @rokolczuk
    @rokolczuk 5 років тому

    cool vid, thx bro

  • @wesley6442
    @wesley6442 11 місяців тому

    I am having issues with game if anyone can give advice or solutions, I've been fighting to get something to work and I have gotten nowhere. I feel there is a stupid easy solution and I am just not finding it, basically I want one of the camera's in my scene to view the same object differently. The idea is you use a device that shows a 3D holographic representation of a building, it's meant to be futuristic/sci fi themed and the operator can see the building as a 3D hologram to look around at, I have tried everything to get it work and I want to avoid duplicating objects, I just want one camera to see things differently while the main camera sees normally. I have used replacement shader scripts for cameras that refuse to work, nothing changes, I've tried prefab variants that kind of work but then anything that happens to my original object doesn't update on the variant, so if a door opens for example the duplicate/variant doesn't update and then it just gets too complicated with setting up for multiple animators and other things.. it would be so much simpler if I could just get my second camera to see the building/objects with a different texture, or shader or material swap but I can't get it to work for the life of me

  • @abdelrahmanmohammed9405
    @abdelrahmanmohammed9405 7 років тому +1

    Does this work on mobile?

    • @DanMoranGameDev
      @DanMoranGameDev  7 років тому +2

      The shader replacement feature in general? Yes that works on mobile.

    • @abdelrahmanmohammed9405
      @abdelrahmanmohammed9405 7 років тому

      Makin' Stuff Look Good Thanks for replying.
      No I mean the overdraw replacement shader. It worked well for me in the editor, but in the mobile nothing was rendered?

    • @DanMoranGameDev
      @DanMoranGameDev  7 років тому

      Oh I think when I put this project together I used Find.Shader which only works in the editor unless the shader you're attempting to find is included in the build by some other means (so in a Resources folder or listed in the Always Include list in the Graphics Settings).

    • @abdelrahmanmohammed9405
      @abdelrahmanmohammed9405 7 років тому

      Included it in both but again nothing is rendered!

    • @DanMoranGameDev
      @DanMoranGameDev  7 років тому

      Hmmm, if you're on Android, check adb; iOS, check the XCode output. See if you're getting any runtime errors when enabling the ReplacementShader. You could also check the build output logs to see if there were errors compiling the shader.

  • @outlaw1148
    @outlaw1148 8 років тому

    What is your twitch account?

  • @josh_swanson
    @josh_swanson 4 роки тому

    *in Unity

  • @sabrango
    @sabrango 5 років тому

    THX!

  • @dogmakeamove808
    @dogmakeamove808 8 років тому +1

    The background music mmmm.

    • @ImStimky
      @ImStimky 6 років тому

      Its from Paper Mario: The Thousand-Year Door
      its in an area where you save little puni's, the cute little mouse guys

  • @jimbeilaw4506
    @jimbeilaw4506 7 років тому

    Genius

  • @762
    @762 4 роки тому

    Doesn't work anymore.....

  • @scno0B1
    @scno0B1 8 років тому

    don't think bonus content would be a good idea if you want everyone to learn ALL THE THINGS"!

    • @DanMoranGameDev
      @DanMoranGameDev  8 років тому +2

      +scno0B1 haha yeah that's why it had the "???". If I do make bonus stuff, it will be outtakes, bloopers, behind the scenes sort of things. Educational resources/videos will always be accessible by all!

  • @elijahjns81
    @elijahjns81 6 років тому

    Dense material.

  • @mpixel2058
    @mpixel2058 4 роки тому

    I wish I understood this.

  • @bart02
    @bart02 7 років тому +1

    WWWOOOOOOOOOOOOOWWWWW