10 shader tips you’d wish you knew sooner

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

КОМЕНТАРІ • 36

  • @GameDevBuddies
    @GameDevBuddies 2 дні тому +1

    Great video!
    Love the channel content, keep it up!
    Love the bitwise operator for storing booleans!

  • @perli216
    @perli216 24 дні тому +14

    Can u pls add chapters to your videos?

    • @oskar_schramm
      @oskar_schramm  23 дні тому +5

      Yes, added. thx will do in the future

    • @perli216
      @perli216 23 дні тому +2

      @@oskar_schramm thank uu

  • @vexedev
    @vexedev 16 днів тому

    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!

  • @MyChannelZs
    @MyChannelZs 22 дні тому +5

    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

    • @oskar_schramm
      @oskar_schramm  21 день тому

      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!

  • @NeZversSounds
    @NeZversSounds 21 день тому +1

    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?

    • @oskar_schramm
      @oskar_schramm  21 день тому

      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.

    • @njdewit
      @njdewit 19 днів тому

      Not necessarily. Do your homework.

    • @leonardotemperanza5824
      @leonardotemperanza5824 2 дні тому

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

  • @praveenb-xr
    @praveenb-xr 8 днів тому

    Can you make a detailed Video about Shader stripping in unity and How to do that Properly. No one does that properly

  • @MonsterJuiced
    @MonsterJuiced 23 дні тому +3

    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

    • @oskar_schramm
      @oskar_schramm  23 дні тому

      @@MonsterJuiced Shadertoy. There is also “GIGI EA”, a new tool for doing graphics/shader concepts quicker

    • @Gameslinx
      @Gameslinx 21 день тому

      That's Shadertoy, it's a website

    • @MonsterJuiced
      @MonsterJuiced 21 день тому

      @@Gameslinx Oh that's just GLSL then... No point

    • @oskar_schramm
      @oskar_schramm  21 день тому +1

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

    • @MonsterJuiced
      @MonsterJuiced 21 день тому +1

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

  • @sealsharp
    @sealsharp 24 дні тому

    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?

    • @oskar_schramm
      @oskar_schramm  21 день тому

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

  • @detdm
    @detdm 23 дні тому +1

    Yes, shaders are something

  • @mikhailhumphries
    @mikhailhumphries 22 дні тому +1

    Shader math insane

  • @mostrealtutu
    @mostrealtutu 23 дні тому +2

    just too bad that you make every video clickbaity like everyone else on yt. how about no bs, and just straight to the point.

    • @RexSacriticulus
      @RexSacriticulus 22 дні тому

      So many people are in hopes of escaping the wagie lifecycle, yet so few have a solid plan of doing so.

  • @AgentCryo
    @AgentCryo 23 дні тому +2

    Ive been stuck on shaders for while now lol.

    • @oskar_schramm
      @oskar_schramm  21 день тому

      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.

    • @AgentCryo
      @AgentCryo 21 день тому

      @@oskar_schramm ShaderToy what is that? I need to use unity since it's going to use the scene objects.

    • @AgentCryo
      @AgentCryo 21 день тому

      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.

  • @pleasantlygrim6712
    @pleasantlygrim6712 23 дні тому +1

    so glad I found this channel you sound like you really know what you're talking about

  • @gustbraga2736
    @gustbraga2736 22 дні тому +1

    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.

    • @oskar_schramm
      @oskar_schramm  21 день тому

      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.

  • @n0msayn
    @n0msayn 23 дні тому +1

    10/10 Content here. This channel's goin places

  • @X13-AA
    @X13-AA 23 дні тому +1

    Great video, most of these tips are often overlooked in tutorials