No video

Fade Objects with C# and the Standard URP Shaders | Unity Tutorial

  Рет қаралды 16,490

LlamAcademy

LlamAcademy

Күн бұрын

Пікірлер: 89
@miguelbr8567
@miguelbr8567 Жыл бұрын
THANK YOU MAN, YOU SAVED MY PROJECT. I spent all along last day trying to figure out something, trying to compute shaders to do this, THANK YOU VERY MUCH
@LlamAcademy
@LlamAcademy Жыл бұрын
You’re very welcome! I’m glad it could save your project!
@poobagification
@poobagification 2 жыл бұрын
Great video as always. Congrats to you and Andrew Bowen on that phenomenal support!
@renman3000
@renman3000 Жыл бұрын
Wow! Thanks. Crazy that such a simple task would be so complex!
@LlamAcademy
@LlamAcademy Жыл бұрын
Yeah it was a little tricky to figure out 😅
@stylie473joker5
@stylie473joker5 Жыл бұрын
@@LlamAcademy Thanks for the hard work, just wanted to ask if this also works with details that are painted with unity's detail paint brush like trees and such
@LlamAcademy
@LlamAcademy Жыл бұрын
I don’t think this will work out of the box with Unity Terrain with trees, grass, and other details placed.
@NatadTech
@NatadTech 7 ай бұрын
Thank you so much bro for hosting it at github and not like some other who host it on their patreon
@ray691108
@ray691108 Жыл бұрын
Omg, you are awesome! super thanks for your example! you deserve more followers and attention indeed!
@LlamAcademy
@LlamAcademy Жыл бұрын
Thank you 🙏 I appreciate that
@chrisb6079
@chrisb6079 2 ай бұрын
Thanks for doing this tutorial
@LlamAcademy
@LlamAcademy 2 ай бұрын
Glad it could help you!
@Romored
@Romored 7 ай бұрын
I rarely comment on videos but this time I will ! Really nice video and awesome tutorial 🔥 Have a nice day ! ✌
@infernumex
@infernumex 2 жыл бұрын
I can't pretend I completely understand this script, but I was able to tweak it for my game, so thank you!
@LlamAcademy
@LlamAcademy 2 жыл бұрын
Great! 🙌 I don't fully understand what all of the things we're toggling do either so 🤷‍♂️sometimes just have to just accept some magic :)
@dreamisover9813
@dreamisover9813 2 жыл бұрын
This channel covers interesting topics, thx
@eyadmohamed-vt7gl
@eyadmohamed-vt7gl 7 ай бұрын
You are the Smartest man on the earth you solved the problem that i could not solve for 5 month Thank you very much
@LlamAcademy
@LlamAcademy 6 ай бұрын
😅 I don’t know about that, but thank you! I’m glad it helped you!
@LuqmanHidayat00
@LuqmanHidayat00 2 жыл бұрын
awesome, great tutorial! i can see myself using this in the future. i'm gonna save it to my playlist
@LlamAcademy
@LlamAcademy 2 жыл бұрын
🙌
@dimitardimitrov7950
@dimitardimitrov7950 4 ай бұрын
LoL, thanks for the tutorial, I followed it to the tee, it worked for me, no errors, but at one point the material wouldn't fade back in, I'm not a programmer, so I shamelessly copied your script from , git, thanks man, amazing tutorial :D
@dimitardimitrov7950
@dimitardimitrov7950 4 ай бұрын
did change it to SphereCastNonAlloc with a radius of 1 for my game
@LlamAcademy
@LlamAcademy 3 ай бұрын
That's why it's available :) Glad it helps you
@oldbelt2578
@oldbelt2578 Жыл бұрын
Thank you! this works perfectly!
@Equisdeification
@Equisdeification 2 жыл бұрын
Hey! I love your channel, you are always giving excellent info
@LlamAcademy
@LlamAcademy 2 жыл бұрын
Awesome to hear! 🙏 I appreciate that
@rickzhang9158
@rickzhang9158 2 жыл бұрын
Great work and I've learned a lot from your video! Unfortuantely when I tried using your code in my project, it appeared to have a bug when encountered with more than one object in the way. When there are 2 objects between player and camera, the fading process worked fine, but when the player walked out of the objects, only the object near the camera returned to opaque, and the other one (blocked by the object near the camera) stayed transparent. That's how I conclude the problem here. Bad at code, I can't fix the issue by myself. Guess this methond only works well in open area. But still, this method is fantastic!
@LlamAcademy
@LlamAcademy 2 жыл бұрын
Hmm……. I will check that out maybe I pushed some incorrect code after doing the editing on the video. Let me get back to you. The idea is this supports as many objects blocking view as you allow RaycastHit array size to be.
@hamzakontaz6066
@hamzakontaz6066 Жыл бұрын
Thank you so much for this effort
@rqbh
@rqbh 6 ай бұрын
Raycast can not detect object
@alexleonardkrea
@alexleonardkrea 2 жыл бұрын
Very clever sir!
@LlamAcademy
@LlamAcademy 2 жыл бұрын
Glad you think so! Thanks!
@DioTravel
@DioTravel 4 ай бұрын
This isn't working for me yet. I feel like I'm really close though. Nothing is showing up in the Objects Blocking View array. I have two objects with colliders and the Fading Object script. I thought it might be the Target Position Offset because I'm not seeing anything change when I change the X,Y,Z values. Either that or the Raycast is not hitting the objects. What would you recommend I do to debug this?
@LlamAcademy
@LlamAcademy 4 ай бұрын
To debug this I like to make an editor script that draws the raycast for me with Handles.DrawLine() based on the direction and start position of the camera. Somehow a lot of times I mess up the raycast and it's not hitting what I expect. If you see the line going through all the objects, double check the layer mask you're raycasting on and the layers of the objects you expect to be hitting to see if there's something wonky going on there.
@DioTravel
@DioTravel 4 ай бұрын
@@LlamAcademy Thanks so much, I got to work! Looks like it was the layers of the objects and the layermask that was making everything wonky!
@antlermind
@antlermind Жыл бұрын
Awesome tutorial here, what an amazing wealth of knowledge your channel has! That being said.. I am having some difficulties getting this working. Currently, there is one spot on my mesh that does turn transparent when blocking the player, but the rest of the mesh stays opaque. Is there any special magic that needs to be done within the URP shader to make this work correctly?
@LlamAcademy
@LlamAcademy Жыл бұрын
Hi! Sorry for the delay in response, it's been a crazy few weeks for me lately. For your issue... I'm not sure how you could have that happen. Because the FadingObject script finds all child renderers and we iterate over all materials, I can't imagine a scenario where you could run into that if FadingObject just pulls all children. There's no magic material properties on the Standard Lit Shader in URP that would prevent it from fading out. Some ways I could imagine that would result in what you described would be: 1. If there are overlapping objects, some without colliders, that are not parented under the object that has a collider + FadingObject. The secondary object would not be considered and not fade out 2. If FadingObject has Renderers assigned in the inspector that are not the full set of Renderers to consider. If you can send a video of your scene setup and the issue maybe I could spot something funny? Or if you have a small reproducible repository I could check it out as well
@rqbh
@rqbh 6 ай бұрын
Not work anymore in Unity2022.3 , is there any other steps to do except add two scripts ?
@LlamAcademy
@LlamAcademy 6 ай бұрын
The objects that can obstruct the camera need a reasonable collider or it won’t work! Do you have colliders on your objects?
@rqbh
@rqbh 6 ай бұрын
​@@LlamAcademy Yes, i use the same sense , the starter 3th person
@lawrence9713
@lawrence9713 4 ай бұрын
Do you need a fix player for it? Could it be done in a game like Age of Empires/ City Skylines, just fading out objects because the cam is zoomed in or something
@LlamAcademy
@LlamAcademy 4 ай бұрын
Works with any target
@steve-banbury-creative-xr
@steve-banbury-creative-xr Жыл бұрын
Thanks for putting this together - just what I need for a project I'm working on and I will be following it in detail. BUT... can I just ask... is it absolutely necessary to put music in the background, particularly on a repetitive loop? I find it hinders following the tutorial, which is kinda counter productive. I've had to remove my headphones and take a break so many times purely due to the background music. It will eventually drive me to distraction! Can we just have the education without the background elevator music, please? Otherwise, keep up the fantastic work!!
@LlamAcademy
@LlamAcademy Жыл бұрын
Thanks for the feedback! When I go back in time and review my older videos I see a lot of room for improvement. One of those (many areas 😅) is the too loud background music that obviously loops. I hope in more recent videos you find the music choice and volume less distracting.
@steve-banbury-creative-xr
@steve-banbury-creative-xr Жыл бұрын
@@LlamAcademy Thanks for the response! Unfortunately, once you've focussed on the music it's really hard to just ignore it - I have tried :). The content of the tutorial was very helpful though. I only really wanted the bit about fading a 3D object with URP, but I found much more than that, which I am sure will be very useful in the future.
@falricthesleeping9717
@falricthesleeping9717 Жыл бұрын
Hey nice video, at the first of the video you said you can use shaders, well where can I find any source for how to do it? thanks
@brianparkhurst5352
@brianparkhurst5352 Ай бұрын
This works great, until I add a ridgedbody component to my object. I need objects to fade, but also need collision detection. I cant seem to figure out what I'm overlooking here. UPDATE:: My children object had the Fade Object component added to them which worked great, Until I added a ridged body component to the Empty parent object for box collision. To fix the issue I added the Fade Object to the parent object, and it worked again. Problem Solved!
@LlamAcademy
@LlamAcademy Ай бұрын
Thank you for sharing your update 🧡! I'm sure someone else will run into the same issue and appreciate that
@brianparkhurst5352
@brianparkhurst5352 Ай бұрын
@@LlamAcademy So I did a build and run test on my project and the fade function doesn't work. Works great in the editor but fails to implement in the build. Any thoughts where to begin debugging this issue?
@LlamAcademy
@LlamAcademy Ай бұрын
Sometimes in the build Unity will strip shader variants that are not used. That’s configured in your project settings / graphic settings. If you aren’t using any transparent materials sometimes this variant doesn’t get included in the build. You can add that variant as a preloaded shader to ensure it’s always included.
@calvinms7503
@calvinms7503 Жыл бұрын
thank you!
@LlamAcademy
@LlamAcademy Жыл бұрын
You’re very welcome! ☺️
@jameslafritz2867
@jameslafritz2867 Жыл бұрын
Hey, Great Video. Is there a reason you chose to go this route instead of using the "Render Feature" of the Rendering->URP Render Pipeline, you may have a video on this already. I use 2 "Render Objects" One for when the character is behind an object and one for when the character is in front using the depth test. if a character is behind an object it use a dither material that I have set up to make it appear as the object is sim-transparent. But there is always the ability to create your own custom render feature that could fade the object out instead.
@LlamAcademy
@LlamAcademy Жыл бұрын
Honestly, I haven't looked into Render Features. When I implemented this effect, URP and Render Features were not out yet. This video was a direct URP translation from what I implemented in the Built-In Render Pipeline.
@jmprsh153
@jmprsh153 2 жыл бұрын
Hey so im guessing i have to import the universal render pipeline for this to work? I was wondering what i would need to do to just use the normal 'standard' shader thats with the normal one. Also if i have to use the universal render pipeline do i have to do anything specific with the project as i try the shader but it makes all the textures pink
@LlamAcademy
@LlamAcademy 2 жыл бұрын
Hi! Yes this is specifically for URP. In the description of the video I have a link to the video showing how to do it with the Built-in render pipeline. The process is the same, but I give you the specific properties and values over there.
@watercat1248
@watercat1248 2 жыл бұрын
Wen I have create therd person player controller in past I have use one system that makes the camera to get closer wean the hit in collisions The problem with that system is the fact block even if the are something small like columns fences ECT but I think if someone make acception for the spefic object I will perfectly fine
@maxg5196
@maxg5196 Жыл бұрын
I'm currently implementing this into my game. I got it working like a charm like in the video. However, I want it to check an list of targets, not just one player target. Currently I am doing the foreach loop for each target in the list in the CheckForObjects coroutine. However, it is still only working for one target at a time. Maybe you would have a better understanding of why that is and how to implement this? Thanks
@LlamAcademy
@LlamAcademy Жыл бұрын
If you have a static list of items that need to be checked, I think the simplest solution is to attach multiple of the same script with different targets. If it's dynamic, then I would expect you're doing it conceptually correct on the CheckForObjects. Could you send me a gist or something with the code? Maybe it's just a small tweak that needs to be made to what you already did.
@maxg5196
@maxg5196 Жыл бұрын
@@LlamAcademy yeah it'll be a dynamic list: I have a script on the targets that adds them to the list when they enter camera view and removes them when they exit camera. What would be the best way for me to share my code with you? Discord?
@maxg5196
@maxg5196 Жыл бұрын
Actually I believe I solved it myself. For other people's reference: essentially when doing the raycast check for each consecutive target, it overrides the array of the previous. And since the function which fades back in objects that are no longer being hit uses this Hits array, it only takes into consideration the last target checked. You need to save all the objects hit in a new array/list and use that in the FadeObjectsNoLongerBeingHit function
@LlamAcademy
@LlamAcademy Жыл бұрын
Oh! Great to hear. I like to use GitHub Gists to share individual scripts: gist.github.com/starred
@danielhasi6974
@danielhasi6974 Жыл бұрын
nice work, but its not possible if i using terrain and try to hide trees right?
@LlamAcademy
@LlamAcademy Жыл бұрын
That’s right. The terrain uses a different shader and does not use the standard rendering with a MeshRenderer
@jjanor7745
@jjanor7745 Жыл бұрын
is there any way to fix the SSAO popping in and out? looks pretty terrible
@LlamAcademy
@LlamAcademy Жыл бұрын
Hmm...I am not 100% sure you can achieve that very easily. Transparent objects usually are not included in the SSAO pass. Maybe you can tweak the settings of SSAO to go after opaque and change the render queue to something like Opaque + 1 to see if that works? Otherwise it might require custom implementation of SSAO to consider these objects.
@jjanor7745
@jjanor7745 Жыл бұрын
@@LlamAcademy Thank you for the answer! I'll see what I can do!
@phantomosteam3727
@phantomosteam3727 Жыл бұрын
Hello i have a different stile of my game that consist of cubes. I think this method is good for big objects instead but actually in my case only 2 cubes disappear and the rest remain opaque so i still can't see my player behind that cubes. Is there a method to give raycast more radius to area??
@LlamAcademy
@LlamAcademy Жыл бұрын
Yes! A Raycast is an “infinitely thin” line. You can use a boxcast or spherecast if you need a wider area. You can check out this video to see how all types of “casts” work: kzfaq.info/get/bejne/nLCpnJqdl9q7e6M.html
@phantomosteam3727
@phantomosteam3727 Жыл бұрын
@@LlamAcademy Thank you very much for answer! But in your case you are actually using RaycastNonAlloc and i don't know how to feet it exactly to your script because each Raycast have different settings allocation and i think using non alloc is better isn't that?
@LlamAcademy
@LlamAcademy Жыл бұрын
Yes, the NonAlloc is the most performant option since it doesn’t generate garbage. You can feed the BoxCastNonAlloc very similarly to RaycastNonAlloc. The video linked above has examples of how to feed each “cast” along with links to the documentation pages!
@phantomosteam3727
@phantomosteam3727 Жыл бұрын
@@LlamAcademy Yes i already watched these video before
@LlamAcademy
@LlamAcademy Жыл бұрын
I will review this in the morning and get back to you
@adamzadorski7764
@adamzadorski7764 2 жыл бұрын
Great!
@LlamAcademy
@LlamAcademy 2 жыл бұрын
😎
@qqqwwwwq
@qqqwwwwq 9 ай бұрын
Hi, I used your tutorial but for HDRP with a shader graph. On the line: " private IEnumerator FadeObjectOut(FadingObject FadingObject) { foreach (Material material in FadingObject.Materials) { material.SetFloat("_Alpha", 0.6f); // Here I pass the value of the variable } yield return null; if (RunningCoroutines.ContainsKey(FadingObject)) { StopCoroutine(RunningCoroutines[FadingObject]); RunningCoroutines.Remove(FadingObject); } } " I used my float variable. But I can't achieve a smooth fade out, because... "alphaFloat = Mathf.Lerp(alphaFloat, 0.6f, Time.deltaTime*1.1f);" triggers only in one frame. Tell me how to modify your code. Thank you!
@qqqwwwwq
@qqqwwwwq 9 ай бұрын
Thank you, I figured it out myself))
@chuozt
@chuozt 2 ай бұрын
Could you explain your solutions for this? I got the same issues.
@qqqwwwwq
@qqqwwwwq 2 ай бұрын
@@chuozt I'll answer you a little later!
@qqqwwwwq
@qqqwwwwq 2 ай бұрын
@@chuozt it was so long ago that I don’t remember what was there, here is the entire coroutine: private IEnumerator FadeObjectOut(FadingObject FadingObject) { float time = 0; while (FadingObject.Materials[0].color.a > FadedAlpha) { foreach (Material material in FadingObject.Materials) { if (material.HasProperty("_Color")) { material.SetFloat("_FloatAlph", 1f); AlphaStep = FadingObject.InitialAlpha; // AlphaFloat = Mathf.Lerp(FadingObject.InitialAlpha, 0.4f, time * FadeSpeed); for (int i = 0; i < 3; i++) { AlphaStep = AlphaStep - 0.2f; material.color = new Color( material.color.r, material.color.g, material.color.b, AlphaStep ); yield return new WaitForSeconds(FadeSpeedOn); Debug.Log(AlphaStep); } } } time += Time.deltaTime; yield return null; } if (RunningCoroutines.ContainsKey(FadingObject)) { StopCoroutine(RunningCoroutines[FadingObject]); RunningCoroutines.Remove(FadingObject); } }
@chuozt
@chuozt 2 ай бұрын
@@qqqwwwwq Your objects' surface types are set to Transparent initially right?
@cyco3oy
@cyco3oy 2 жыл бұрын
+1
@LlamAcademy
@LlamAcademy 2 жыл бұрын
@michaelvicente5365
@michaelvicente5365 Жыл бұрын
looks promising, sadly I get an error "Assets\urp-fading-standard-shaders-main\Assets\StarterAssets\TutorialInfo\Scripts\Editor\ReadmeEditor.cs(79,23): error CS0115: 'ReadmeEditor.OnInspectorGUI()': no suitable method found to override"
@LlamAcademy
@LlamAcademy Жыл бұрын
Hmm..... you can safely delete that file. It was just carried over from the Third Person Starter Assets from Unity. Which version of Unity are you on?
I Made the Same Game in 8 Engines
12:34
Emeral
Рет қаралды 4 МЛН
A new way to generate worlds (stitched WFC)
10:51
Watt Designs
Рет қаралды 525 М.
❌Разве такое возможно? #story
01:00
Кэри Найс
Рет қаралды 3,6 МЛН
هذه الحلوى قد تقتلني 😱🍬
00:22
Cool Tool SHORTS Arabic
Рет қаралды 48 МЛН
The Joker kisses Harley Quinn underwater!#Harley Quinn #joker
00:49
Harley Quinn with the Joker
Рет қаралды 14 МЛН
Why Devs NEED TO know about Render Matrices!
11:31
Kaze Emanuar
Рет қаралды 68 М.
EVERY Post-Processing effect in Unity | What you NEED to know
8:47
Sasquatch B Studios
Рет қаралды 11 М.
The Right Way to Spawn Objects in Unreal Engine | UE5
18:03
Ali Elzoheiry
Рет қаралды 18 М.
I Wish I Had Known This Before I Started Unity Game Development...
11:11
Outline Post Process in Unity Shader Graph (URP)
8:24
Daniel Ilett
Рет қаралды 42 М.
How to ACTUALLY get into Gamedev
14:01
DaFluffyPotato
Рет қаралды 718 М.
Can AI code Flappy Bird? Watch ChatGPT try
7:26
candlesan
Рет қаралды 9 МЛН
❌Разве такое возможно? #story
01:00
Кэри Найс
Рет қаралды 3,6 МЛН