Do you have any recommendations for shader code intellisense/highlight in Unity? I use an extension in VS but it doesn't work great and gets in your way, and doesn't navigate to built-in unity headers. I always have to search for them and find them to browse the code... it would be really nice if there was something that did that for me and made F12 goto definition work!
Good initiative. However not a fan of this hand wavy style thats not explaining much. It's a common to say to avoid branching, though branching is fine when the lanes are coherent in a warp, as the lanes are executed in SIMD lockstep fashion. Also avoiding discard is more because that disables early-z optimization
Good addition. Just wanted to give an example of why it's not good practice to have branching due to the nature SIMD instructions, but maybe should have picked a better example. With "Hand wavy style", do you mean that the explanation vague or incomplete? Trying to understand and get better. Thanks for letting me know!
Yes you are correct, that would need branching. A ternary if is the same instructions as a normal if. But lerping or multiplying by a bool isn't the same, it won't issue a comparison. And the bool doesn't need to be calculated on the GPU, it could be sent up as a flag and multiplied with for example.
@@oskar_schrammWhat they wrote isn't a ternary if, it's just a "greater than" instruction. No branching needed in that case. A ternary if could also be optimized into branchless code depending on the compiler
for the love of god can you or someone tell me which program I can use to write hlsl and preview my code in real-time please? What's that program at 10:31? I can't even find anywhere on the internet where to even begin and which program to use for composing HLSL and previewing my work. It's all GLSL sandboxes. I don't want that. How do I begin, from absolute step 1? Which software do I get to start typing and previewing? Please help Oskar
@@MonsterJuiced Most research papers are still written in OpenGL/GLSL so it's a great skill to be able to translate between them. Also they are not so different, and as a graphics programmer you will most likely never be stuck with one API or one shader language. With that said, if you really want HLSL, try out GIGI by EA or use a library that sets up your engine, and then play around with the HLSL code.
@@oskar_schramm currently I'm using unreal engine so to live test hlsl I'm using custom nodes but it still requires extra faffing about setting up the inputs to the custom node. (The custom node lets you type hlsl script). I just wanted a software specifically for live previewing raw hlsl or glsl (both or just hlsl) because I'm trying to see exactly as I input the code, what's happening to the screen itself. Not necessarily what's happening to the preview sphere in unreal engine. It's just extra steps in UE that I don't want to have to keep doing when I'm just trying to test ideas. I understand it's a great skill to be able to translate between both shader languages but I feel like I'd be wasting valuable time learning glsl when unreal engine requires hlsl and I have to learn hlsl anyway to be able to translate it.
08:40 The part that we can't sample the depth buffer: You are referring to the depth buffer that currently gets read/updated during depth testing of the fragment stage, while when people say "sample the depth buffer" what they mean is sample a copy of the depth buffer created either in a depth prepass or copied after opague. Do i get that right?
No not necessarily. If you create your depthbuffer as a resource and render target, or if you create a read only depthbuffer, you can sample from it in the shader, no copy or z-prepass needed. But what can't be done with any resrouce is reading and writing to it at the same time. So if you want to write to your depth buffer, which you normaly want in a deferred pipeline, if you also want the depth in the shader, you would need to reconstruct the depth from the screen space (SV_Position).
Keep doing a lot of what challenges you, and eventually, a door will open. Use tools like Shadertoy or GIGI by EA, to use shader code quickly without the setup needed.
Great video, adding a bit to the subject of conditionals. Beware of the argument that branches should be avoided at all costs in shaders, as it depends a lot on the occasion. For example: - If (global_variable) is totally acceptable, since this variable won't change between threads - If () { early loop break / heavy computation avoidance } is also acceptable Basically, conditionals that don't change between “waves” or blocks of therads that share a memory won't be problematic. Another important point: Your if() in the code may not be a conditional once compiled! If we try to be clever and do something like: lerp(0, 1, step(cond, 0.5)); or even lerp(0, 1, cond > 0.5); the program will generate more lines of code than a simple if (step is a conditional). I'd say it's good practice to avoid using it where you can, since it's the market standard, but not that it's strictly forbidden, especially on today's boards.
Absolutely, great addition. I think most of the things I mention in my videos are never black or white, but should be taken with a grain of salt, since there are always exceptions to the rules.
Great video!
Love the channel content, keep it up!
Love the bitwise operator for storing booleans!
Can u pls add chapters to your videos?
Yes, added. thx will do in the future
@@oskar_schramm thank uu
Do you have any recommendations for shader code intellisense/highlight in Unity? I use an extension in VS but it doesn't work great and gets in your way, and doesn't navigate to built-in unity headers. I always have to search for them and find them to browse the code... it would be really nice if there was something that did that for me and made F12 goto definition work!
Good initiative. However not a fan of this hand wavy style thats not explaining much.
It's a common to say to avoid branching, though branching is fine when the lanes are coherent in a warp, as the lanes are executed in SIMD lockstep fashion. Also avoiding discard is more because that disables early-z optimization
Good addition. Just wanted to give an example of why it's not good practice to have branching due to the nature SIMD instructions, but maybe should have picked a better example.
With "Hand wavy style", do you mean that the explanation vague or incomplete? Trying to understand and get better. Thanks for letting me know!
Calculating a bool requires comparison. If there's a comparison, then there's a branching.
bool a = b > c; is a branching, isn't it?
Yes you are correct, that would need branching. A ternary if is the same instructions as a normal if. But lerping or multiplying by a bool isn't the same, it won't issue a comparison. And the bool doesn't need to be calculated on the GPU, it could be sent up as a flag and multiplied with for example.
Not necessarily. Do your homework.
@@oskar_schrammWhat they wrote isn't a ternary if, it's just a "greater than" instruction. No branching needed in that case. A ternary if could also be optimized into branchless code depending on the compiler
Can you make a detailed Video about Shader stripping in unity and How to do that Properly. No one does that properly
for the love of god can you or someone tell me which program I can use to write hlsl and preview my code in real-time please? What's that program at 10:31? I can't even find anywhere on the internet where to even begin and which program to use for composing HLSL and previewing my work. It's all GLSL sandboxes. I don't want that. How do I begin, from absolute step 1? Which software do I get to start typing and previewing? Please help Oskar
@@MonsterJuiced Shadertoy. There is also “GIGI EA”, a new tool for doing graphics/shader concepts quicker
That's Shadertoy, it's a website
@@Gameslinx Oh that's just GLSL then... No point
@@MonsterJuiced Most research papers are still written in OpenGL/GLSL so it's a great skill to be able to translate between them. Also they are not so different, and as a graphics programmer you will most likely never be stuck with one API or one shader language. With that said, if you really want HLSL, try out GIGI by EA or use a library that sets up your engine, and then play around with the HLSL code.
@@oskar_schramm currently I'm using unreal engine so to live test hlsl I'm using custom nodes but it still requires extra faffing about setting up the inputs to the custom node. (The custom node lets you type hlsl script). I just wanted a software specifically for live previewing raw hlsl or glsl (both or just hlsl) because I'm trying to see exactly as I input the code, what's happening to the screen itself. Not necessarily what's happening to the preview sphere in unreal engine.
It's just extra steps in UE that I don't want to have to keep doing when I'm just trying to test ideas.
I understand it's a great skill to be able to translate between both shader languages but I feel like I'd be wasting valuable time learning glsl when unreal engine requires hlsl and I have to learn hlsl anyway to be able to translate it.
08:40 The part that we can't sample the depth buffer:
You are referring to the depth buffer that currently gets read/updated during depth testing of the fragment stage, while when people say "sample the depth buffer" what they mean is sample a copy of the depth buffer created either in a depth prepass or copied after opague. Do i get that right?
No not necessarily. If you create your depthbuffer as a resource and render target, or if you create a read only depthbuffer, you can sample from it in the shader, no copy or z-prepass needed. But what can't be done with any resrouce is reading and writing to it at the same time.
So if you want to write to your depth buffer, which you normaly want in a deferred pipeline, if you also want the depth in the shader, you would need to reconstruct the depth from the screen space (SV_Position).
Yes, shaders are something
Shader math insane
just too bad that you make every video clickbaity like everyone else on yt. how about no bs, and just straight to the point.
So many people are in hopes of escaping the wagie lifecycle, yet so few have a solid plan of doing so.
Ive been stuck on shaders for while now lol.
Keep doing a lot of what challenges you, and eventually, a door will open.
Use tools like Shadertoy or GIGI by EA, to use shader code quickly without the setup needed.
@@oskar_schramm ShaderToy what is that? I need to use unity since it's going to use the scene objects.
Oh the shader is a raytracing shader btw
also might need to know how to do raymarching if I want to do stuff like clouds, water, and atmosphere.
so glad I found this channel you sound like you really know what you're talking about
Great video, adding a bit to the subject of conditionals. Beware of the argument that branches should be avoided at all costs in shaders, as it depends a lot on the occasion.
For example:
- If (global_variable) is totally acceptable, since this variable won't change between threads
- If () { early loop break / heavy computation avoidance } is also acceptable
Basically, conditionals that don't change between “waves” or blocks of therads that share a memory won't be problematic.
Another important point: Your if() in the code may not be a conditional once compiled!
If we try to be clever and do something like:
lerp(0, 1, step(cond, 0.5)); or even lerp(0, 1, cond > 0.5); the program will generate more lines of code than a simple if (step is a conditional).
I'd say it's good practice to avoid using it where you can, since it's the market standard, but not that it's strictly forbidden, especially on today's boards.
Absolutely, great addition. I think most of the things I mention in my videos are never black or white, but should be taken with a grain of salt, since there are always exceptions to the rules.
10/10 Content here. This channel's goin places
Great video, most of these tips are often overlooked in tutorials