Introduction to shaders: Learn the basics!

แชร์
ฝัง
  • เผยแพร่เมื่อ 27 เม.ย. 2024
  • 0:00 Intro
    1:24 What is a shader?
    3:37 Setting up shaders in P5js
    5:58 GLSL data types
    7:00 Vectors
    8:58 Attributes, Uniforms and Varying
    10:19 Barebones fragment shader
    11:00 Vertex shader
    14:57 Fragment shader revisited
    15:30 Gradients
    16:45 FragCoord tangent
    18:28 Mix function
    21:22 Setting uniforms
    22:43 Uniform images (sampler2D)
    24:58 p5.filterShader
    25:12 Uniform arrays
    27:05 Circles and SDFs
    31:47 Boolean logic
    33:25 Debugging shaders
    34:13 Conclusion
    Resources:
    Inigo Quilez TH-cam: / @inigoquilez
    Inigo Quilez shader: www.shadertoy.com/view/ldScDh
    Kishimisu TH-cam: / @kishimisu
    Kishimisu shader: www.shadertoy.com/view/mtyGWy
    Types of shaders: www.khronos.org/opengl/wiki/S...
    GLSL Data Types: www.khronos.org/opengl/wiki/D...)
    All available p5js shader attributes and uniforms: github.com/processing/p5.js/b...
    gl_FragCoord: registry.khronos.org/OpenGL-R...
    mix function: registry.khronos.org/OpenGL-R...
    p5.filterShader Library: github.com/BarneyWhiteman/p5....
    2D SDFs: iquilezles.org/articles/distf...
    Examples:
    All examples: editor.p5js.org/BarneyCodes/c...
    Vertex shader example: editor.p5js.org/BarneyCodes/s...
    Fragment shader gradient example: editor.p5js.org/BarneyCodes/s...
    Fragment shader position example: editor.p5js.org/BarneyCodes/s...
    Fragment shader image example: editor.p5js.org/BarneyCodes/s...
    Fragment shader array example: editor.p5js.org/BarneyCodes/s...
    Fragment shader SDF example: editor.p5js.org/BarneyCodes/s...
    Fragment shader logic example: editor.p5js.org/BarneyCodes/s...
    Shaders are an incredibly useful programming tool to have under your belt, especially for creative coding and generative art. They unlock a whole heap of potential, but they're a bit quirky to learn!
    This video covers a lot of the fundamentals and will hopefully set you up well for using shaders in the future!
    This is a bit of a long/dense video so be sure to take a break if you need, and you can always watch it more than once to help it all sink in!
    This video and its examples use P5js in WEBGL mode, however the concepts are transferable to pretty much any environment that you can use shaders in (some syntax may vary, especially in the CPU code).
    Follow me:
    Support the channel: www.youtube.com/@BarneyCodes/...
    Twitter: / barneycodes
    Reddit: / barneycodes
    #shaders #graphics #creativecoding

ความคิดเห็น • 270

  • @StarFury2
    @StarFury2 5 หลายเดือนก่อน +169

    It's very important to note that in modern versions of OpenGL (3.3+) qualifiers "attribute" and "varying" are deprecated and replaced with "in" and "out". And instead of gl_FragColor we are encouraged to use user-defined "out" variables.
    The logic of writing shaders is still the same, but none of this code will work in modern versions if allowance for the differences is not made.

    • @BarneyCodes
      @BarneyCodes  5 หลายเดือนก่อน +43

      Good call! I think WEBGL is a little behind, but I think that's about to change with WebGPU and WEBGL 2. Thanks for the comment!!

    • @nepp9574
      @nepp9574 5 หลายเดือนก่อน +7

      I was about to write exactly this. This is indeed pre glsl 1.3 syntax so very old. 1.3 and later uses above syntax and is incorporated into WebGL2 since 2017. This is coupled with OpenGL ES 3.0 which might be worth noting. For anyone interested in these facts, the above video of course still applies ❤

    • @BarneyCodes
      @BarneyCodes  5 หลายเดือนก่อน +11

      I didn't realise how long WebGL2 has been out! I think P5js only started supporting it recently.
      I've used the newer syntax in other projects, but everything web related I've been using the old syntax. Might be time to change that! Thanks for the comment!

    • @StarFury2
      @StarFury2 5 หลายเดือนก่อน +9

      I guess what I noted is quite obvious to an experienced user, but me being a noob with OpenGL, it was strange why compiler throws so many cryptic errors in my python+pyglet environment. I saw that built-in classes use default shaders with "in" and "out" qualifiers. Asked ChatGPT and it was like "Dude, you're using an ancient syntax!"😅
      Of course, all the love for the author, video is still relevant and definitely a must watch for anyone starting to mess with shaders!❤ @@BarneyCodes

    • @ecruz2317
      @ecruz2317 3 หลายเดือนก่อน

      if anyone wants traction for their channels, coding for marmoset will get you some traction, just a heads up, i only need to code 1 shader for myself and that is the "engine", i am using to get the results i want, it combines hlsl and glsl.

  • @tirins
    @tirins 8 หลายเดือนก่อน +108

    Does anybody else feel like going for a second helping of this... only a little bit later 😅 The info is dense! Awesome, man!

    • @BarneyCodes
      @BarneyCodes  8 หลายเดือนก่อน +17

      Hahaha yea sorry about that! There's just so much that I wanted to include in the video! I think shaders are just one of those things that take a few goes to sink in.
      Thanks for the comment!

    • @rmt3589
      @rmt3589 6 หลายเดือนก่อน +3

      Me!

    • @Seb001ean
      @Seb001ean 5 หลายเดือนก่อน +5

      I go back every week. Such a great starting place. Will there be a part 2 to this? Do you have ideas of what you’d want to include in it?

    • @BarneyCodes
      @BarneyCodes  5 หลายเดือนก่อน +8

      ​​@@Seb001eanGlad to hear you're finding it helpful! I'm thinking I'll do smaller videos that focus on one topic at a time instead of another video like this one. That'll hopefully mean they're more frequent but will also let me go into a little more depth each time.
      A few weeks ago I put out a video on how to use a noise texture in a shader if you want to check that out!
      I've got a few ideas such as using normal maps and creating very basic lighting, using vertex shaders to manipulate objects and a few others. Is there anything you would like to see cover?

    • @OctagonalSquare
      @OctagonalSquare 4 หลายเดือนก่อน +2

      I haven’t even gotten past the ads and yet know I’ll have to come back haha

  • @WarriorAlexOG
    @WarriorAlexOG 2 วันที่ผ่านมา +3

    This was just the video I needed to get started with shaders. I knew very little about them or what they even did or were capable of, but this video really showed me, on a beginner level, just how indepth this really goes.
    Thank you so much for all the effort you put into this video. You explained so much indepth, while also making it simplistic, while not watering anything down. The care and passion you put into making this really shows.

    • @BarneyCodes
      @BarneyCodes  2 วันที่ผ่านมา +2

      Thank you so much! I'm so glad you found it helpful, shaders can be an amazing tool so getting more people creating and playing around with them is exactly what my goal was!
      All the best on your shader journey ahead!

  • @maxenceveilleux
    @maxenceveilleux 26 วันที่ผ่านมา +10

    Only 3 minutes into the video and you answered so many of my questions. Thanks a ton already!

    • @BarneyCodes
      @BarneyCodes  26 วันที่ผ่านมา +2

      Glad you've already found it useful!

  • @BarneyCodes
    @BarneyCodes  9 หลายเดือนก่อน +31

    Finally finished! This video took ages to put together, so if you enjoyed it, it would be great if you could give it a like and share it with anyone you know who needs to learn about shaders!
    Also, I forgot to mention the amazing www.shadertoy.com which is another great resource and an easy way to get stuck into shader programming in your browser.
    If you'd like to see what else I'm working on, it would be great if you could wishlist my game Star Mining Co. on Steam! s.team/a/2584800/

    • @IDGs_space
      @IDGs_space 6 ชั่วโมงที่ผ่านมา

      oh yeah, don't forget graphtoy, it's a graphing calculator specifically with glsl in mind !!
      there's also a few websites in kishimisu's video on shader art coding but youtube tends to delete comments with links, they're still worth checking out though!!

  • @fr3ddyfr3sh
    @fr3ddyfr3sh 4 หลายเดือนก่อน +39

    seems a little shady to me 😅

    • @bloodaid
      @bloodaid 18 วันที่ผ่านมา +3

      Never trust shaders

  • @bynightcore4868
    @bynightcore4868 6 หลายเดือนก่อน +42

    Hi, normally I really don't comment on TH-cam videos. But man, this introduction was EXACTLY what I needed to get started with my university project. Thanks a lot man, keep up the good work :)

    • @BarneyCodes
      @BarneyCodes  6 หลายเดือนก่อน +9

      Thanks so much, glad it was helpful and I hope your project goes well!

  • @StevesMakerspace
    @StevesMakerspace 3 หลายเดือนก่อน +3

    Great job, Barney! Congrats on this video and your channel taking off! Well deserved.

    • @BarneyCodes
      @BarneyCodes  3 หลายเดือนก่อน +3

      Thank you so much Steve, I really appreciate all the support you've shown me! I still can't really believe how well this video has done!

  • @facr
    @facr 4 หลายเดือนก่อน +4

    Love the pace and the insight that gave us on shaders! Great!!!

    • @BarneyCodes
      @BarneyCodes  4 หลายเดือนก่อน +3

      Thanks so much, glad you enjoyed it!

  • @chbrules
    @chbrules หลายเดือนก่อน +7

    This is all new to me. I can see the potential for a lot of this stuff, and I can see you've barely scratching the surface of this powerful tool. Man... this is going to take a few watches just to even get started :|

    • @BarneyCodes
      @BarneyCodes  หลายเดือนก่อน +1

      It took me so many cracks at trying shaders before it started to stick! Not meant to discourage you, just letting you know you're not alone in feeling that way!
      I think it's just you have to approach it in a pretty different way from most programming so it can just take some time to get used to, I'm sure you'll get it though - if you have any questions or anything, just let me know :)

  • @nepp9574
    @nepp9574 5 หลายเดือนก่อน +9

    This is better than the official learn OpenGL tutorial (mix of c++ and glsl)❤Nice one! Exactly what I needed on my Vulkan adventures 😃

    • @BarneyCodes
      @BarneyCodes  5 หลายเดือนก่อน +4

      Wow, thank you so much! Hope your adventures go well!

  • @DeniseNepraunig
    @DeniseNepraunig 5 หลายเดือนก่อน +5

    Thank you so much for putting this video together! Fantastic explanation of the SDF and I also liked the part about the logic a lot! You touched so many topics with such a great presentation, really amazing man!!

    • @BarneyCodes
      @BarneyCodes  5 หลายเดือนก่อน +3

      Thanks so much, I'm glad you found it useful!

  • @RhogerAnacleto
    @RhogerAnacleto 3 หลายเดือนก่อน +6

    For the first time in my life, I understood what that Shader code was all about. Thank you for the quick explanation. I'll definitely need more couple of years to be able to write my first shader script to create a simple black circle on screen because is too hard, but this video is definitely one of the best to see about the topic.

    • @BarneyCodes
      @BarneyCodes  3 หลายเดือนก่อน +2

      Thank you so much! You've got this, it took a couple of tries before it started to sink in for me as well, I think that's very normal because it's definitely a different sort of programming from what most of us are exposed to, but I promise it does get easier!
      If you have any questions or need help, please feel free to reach out!

  • @alexeyl22
    @alexeyl22 4 หลายเดือนก่อน +1

    Great stuff. Looking forward for more.

  • @tristanjohn
    @tristanjohn 6 หลายเดือนก่อน +5

    Thanks loads for this! The comprehensive approach filled in literally all the gaps in my understanding of shaders.

    • @BarneyCodes
      @BarneyCodes  6 หลายเดือนก่อน +2

      No problem, glad you found it so useful!

  • @TechnicJelle
    @TechnicJelle 9 หลายเดือนก่อน +6

    What a great video! Thanks for making it :D

    • @BarneyCodes
      @BarneyCodes  9 หลายเดือนก่อน +5

      Thanks so much for the support! Glad you enjoyed it!

  • @user-gq3km7oe2f
    @user-gq3km7oe2f 5 หลายเดือนก่อน +4

    This is better than the official learn OpenGL tutorial (mix of c++ and glsl)Nice one! Exactly what I needed on my Vulkan adventures

  • @nouveu1
    @nouveu1 4 หลายเดือนก่อน +3

    I'm not really working in game dev but watched your video out of curiosity and it was a pleasure and nice relax for me. You have a great talent to explain things :)

    • @BarneyCodes
      @BarneyCodes  4 หลายเดือนก่อน +2

      Thanks so much!

  • @mis4vr877
    @mis4vr877 6 หลายเดือนก่อน +8

    I absolutely adore this video and your presentation. Shaders seemed like black magic before this but you really helped me understand

    • @BarneyCodes
      @BarneyCodes  6 หลายเดือนก่อน +3

      Thanks so much for the kind words! I'm really glad to hear this video helped!

  • @discotecc
    @discotecc 4 หลายเดือนก่อน +5

    Getting into graphics programming as a hobby thanks for the video, You're a great explainer. I wish I had gotten into this sooner instead of web development theres a lot of neat stuff to understand

  • @Phenylalanin1979
    @Phenylalanin1979 3 หลายเดือนก่อน +2

    Brilliant video, really a great way to visually teach complex topics. Very informative and I can appreciate how much work this video must have taken all in all. Also the two Edges was a nice touch :).

    • @BarneyCodes
      @BarneyCodes  3 หลายเดือนก่อน +1

      Thanks so much, I'm glad you enjoyed it! And I think you're just the second person to comment on the Edge joke, good to know there are a few cultured people out there hahaha

    • @Phenylalanin1979
      @Phenylalanin1979 3 หลายเดือนก่อน

      @@BarneyCodes Wait a minute ... is cultured code for old?

  • @atibyte
    @atibyte 4 หลายเดือนก่อน +2

    Nice intro to shaders, thank you!

    • @BarneyCodes
      @BarneyCodes  4 หลายเดือนก่อน +1

      Thanks, glad you liked it!

  • @Shamysoza92
    @Shamysoza92 4 หลายเดือนก่อน +4

    This is amazing! I am going through SimonDevs course but there is alot of clutter with threejs to make stuff happen, but using p5js is way simpler and really makes the javascript code as a secondary element and really focus on the glsl side of things. I hope this series keeps going.

    • @BarneyCodes
      @BarneyCodes  4 หลายเดือนก่อน +1

      I love Simon's videos, they're really great! But yea I think P5js is pretty much as straightforward as it gets for setting up shaders which is why I use it so much!
      There are some limitations with it though, like the ModelView matrix being combined in the vertex shader so that you can't do world space calculations.
      What topics would you like to see in the next video?

  • @boiimcfacto2364
    @boiimcfacto2364 4 หลายเดือนก่อน +3

    This is absolute fucking gold. I love you man. Crisp, clear and straight to the point. Your humour was never intrusive like with other tutorials and you even gave links for every checkpoint in the video. God bless you man, this was a fantastic video and I wish I could like it 10 times lol ♥

    • @BarneyCodes
      @BarneyCodes  4 หลายเดือนก่อน +1

      Thank you so much, that's so encouraging to hear and I'm glad you found it useful!

  • @akashdalvi5369
    @akashdalvi5369 2 หลายเดือนก่อน

    Thanks man.. this really helped a lot. Thank you for putting this much time and effort into this❤

  • @Jun127
    @Jun127 8 หลายเดือนก่อน +4

    This is a great resource. :)

    • @BarneyCodes
      @BarneyCodes  8 หลายเดือนก่อน +2

      Glad you found it useful!

  • @emmettdja
    @emmettdja 3 หลายเดือนก่อน +3

    it helps that p5js just recently made it much easier to use shaders with their library!

  • @accumulator4825
    @accumulator4825 4 หลายเดือนก่อน +1

    You're very good at explaining. Thank you for this video!

    • @BarneyCodes
      @BarneyCodes  4 หลายเดือนก่อน +1

      Thank you and no worries!

  • @mooshy5944
    @mooshy5944 5 หลายเดือนก่อน +1

    Thanks! this was exactly the sort of tutorial I’ve been looking for 🎉

    • @BarneyCodes
      @BarneyCodes  5 หลายเดือนก่อน +1

      No worries, glad it was helpful!

  • @AD-Dom
    @AD-Dom หลายเดือนก่อน +1

    Um, thank you. Wow. This is exactly the type of rundown I've been seeking.

    • @BarneyCodes
      @BarneyCodes  หลายเดือนก่อน

      No worries, glad it was helpful!

  • @wazawoo
    @wazawoo 3 หลายเดือนก่อน +1

    You are amazing at explaining and visualizing things

    • @BarneyCodes
      @BarneyCodes  3 หลายเดือนก่อน

      Thank you, that's very kind!

  • @Seb001ean
    @Seb001ean 7 หลายเดือนก่อน +18

    Fantastic introduction to shader programming! Thank you for this :)❤ I kept wanting to know more about everything you talked about, it really could have been an even more thorough introduction. Looking forward to a potential series or just more on this wondrous field of programming.

    • @BarneyCodes
      @BarneyCodes  7 หลายเดือนก่อน +5

      Thanks so much! It was pretty hard to decide what to keep in and what to leave out and it still ended up being a long video! I do plan on doing more videos with shaders in the future, is there any topic in particular you'd like to see in more depth?

    • @geelemo
      @geelemo 2 วันที่ผ่านมา

      ​@@BarneyCodes shaders in wgsl!

  • @reik2006
    @reik2006 3 หลายเดือนก่อน +1

    Really good introduction! Thank you

    • @BarneyCodes
      @BarneyCodes  3 หลายเดือนก่อน +1

      Thanks, glad you liked it!

  • @djneils100
    @djneils100 9 หลายเดือนก่อน +8

    this channel rocks - please keep going!

    • @BarneyCodes
      @BarneyCodes  9 หลายเดือนก่อน +5

      Thank you so much! Definitely more to come!

  • @pengain4
    @pengain4 7 หลายเดือนก่อน +1

    Awesome video. Very entertaining and educational

    • @BarneyCodes
      @BarneyCodes  7 หลายเดือนก่อน +1

      Thank you, glad you enjoyed it!

  • @wlgemini1991
    @wlgemini1991 6 หลายเดือนก่อน +2

    视频做的真棒, 每一步都介绍的很详细👍

    • @BarneyCodes
      @BarneyCodes  6 หลายเดือนก่อน +1

      Thank you!

  • @theobgshow
    @theobgshow 6 หลายเดือนก่อน +1

    Superb! Thank you 😊

    • @BarneyCodes
      @BarneyCodes  6 หลายเดือนก่อน +2

      No worries!

  • @doublemax77
    @doublemax77 4 หลายเดือนก่อน +1

    Excellent video, thank you so much!

    • @BarneyCodes
      @BarneyCodes  4 หลายเดือนก่อน +2

      No worries, glad you liked it!

  • @speckdratz
    @speckdratz 5 หลายเดือนก่อน +2

    Rating: 12/10 on all levels.
    This is YT-hall-of-fame material 🏆

    • @BarneyCodes
      @BarneyCodes  5 หลายเดือนก่อน +1

      Hahaha wow, thanks so much!

  • @BallardRobinett
    @BallardRobinett 5 หลายเดือนก่อน +1

    excellent video! really appreciate this

    • @BarneyCodes
      @BarneyCodes  5 หลายเดือนก่อน +1

      Glad it was helpful!

  • @syntaxerorr
    @syntaxerorr 4 หลายเดือนก่อน +2

    Great video.

  • @D.E.Nicolas.Goncalves
    @D.E.Nicolas.Goncalves 5 หลายเดือนก่อน +2

    Oh man! Greatfull by your content!

    • @BarneyCodes
      @BarneyCodes  5 หลายเดือนก่อน +1

      Glad you find it helpful!

  • @thatalbeeguy
    @thatalbeeguy 6 หลายเดือนก่อน +3

    thank you so much this is an incredible tutorial!

    • @BarneyCodes
      @BarneyCodes  6 หลายเดือนก่อน +1

      No worries, glad you found it useful!

  • @ttaylor7604
    @ttaylor7604 6 หลายเดือนก่อน +1

    I really needed a video like this about 2 years ago, when I studied this at university

    • @BarneyCodes
      @BarneyCodes  6 หลายเดือนก่อน +2

      Better late than never I guess?

  • @chaosordeal294
    @chaosordeal294 3 หลายเดือนก่อน +1

    The benefit of a strongly-typed language like C++ is that the developer is in control and well-informed. The advantages of loosely-typed languages are as many and varied as the reasons to be loose with variables in a computer program.

    • @chaosordeal294
      @chaosordeal294 3 หลายเดือนก่อน

      (none, there are none)

  • @jermaineallgood
    @jermaineallgood 7 หลายเดือนก่อน +1

    Thank you so much!!!! I appreciate this as it will help tremendously!

    • @BarneyCodes
      @BarneyCodes  7 หลายเดือนก่อน +1

      No worries!

  • @smooshymemes
    @smooshymemes หลายเดือนก่อน +2

    Better than my public education 11/10

  • @okie9025
    @okie9025 6 หลายเดือนก่อน +10

    26:50 you can also use the spread operator, which has the added bonus that it works with any number of arrays, i.e.:
    const colours = [...col1, ...col2, ...col3]

    • @BarneyCodes
      @BarneyCodes  6 หลายเดือนก่อน +3

      Oh that's really good! Thanks for the suggestion!

  • @zmf1425
    @zmf1425 6 หลายเดือนก่อน +2

    Very good. Thank you

    • @BarneyCodes
      @BarneyCodes  6 หลายเดือนก่อน +1

      No worries!

  • @theshoulderofgiants
    @theshoulderofgiants 9 หลายเดือนก่อน +9

    thank you ❤amazing work.... i hope you make this is a series..i would love to learn about vertex shaders..looking forward to ur next video 😁

    • @BarneyCodes
      @BarneyCodes  9 หลายเดือนก่อน +4

      Thanks! There will definitely be more shader videos! I'll have to think of something cool to do with the vertex shader!

  • @SeasonalMike
    @SeasonalMike 7 หลายเดือนก่อน +1

    Wow, I can't wait to learn how to draw a cube!

  • @onlylikenerd
    @onlylikenerd 5 หลายเดือนก่อน +2

    Hey nice video. Good stuff

    • @BarneyCodes
      @BarneyCodes  5 หลายเดือนก่อน +1

      Thanks, glad you liked it!

  • @bespokeprogramming
    @bespokeprogramming 7 หลายเดือนก่อน +1

    Mate! I love glsl, but your explanation is dope! Thank you!

    • @BarneyCodes
      @BarneyCodes  7 หลายเดือนก่อน +1

      Wow, thanks so much! Glad you liked it!

  • @jarrettonions3392
    @jarrettonions3392 7 หลายเดือนก่อน +2

    Todays the day bro!! :D been so long coming... finally got some bloom and reflective water up and running in unity... wow

    • @BarneyCodes
      @BarneyCodes  7 หลายเดือนก่อน +1

      That's great, nice work!

  • @simonnesvadba9757
    @simonnesvadba9757 หลายเดือนก่อน +1

    This gives my brain a nosebleed, but in a good way like in anime ❤

  • @mireymackey
    @mireymackey 4 หลายเดือนก่อน +2

    Top-tier video!

    • @BarneyCodes
      @BarneyCodes  4 หลายเดือนก่อน +1

      Thanks so much!

  • @Cypekeh
    @Cypekeh 7 หลายเดือนก่อน +4

    Great video, thanks
    I had some shaders in uni, but I didn't really get it
    Hopefully I'll start using them more often and learn them, but this video is a great introduction

    • @BarneyCodes
      @BarneyCodes  7 หลายเดือนก่อน +1

      Thanks! Hope the video is helpful, let me know if you have any questions!

  • @j_uice
    @j_uice 9 หลายเดือนก่อน +5

    yessssssss thanky ou for this!

    • @BarneyCodes
      @BarneyCodes  9 หลายเดือนก่อน +4

      No worries!

  • @TarousDT
    @TarousDT 4 หลายเดือนก่อน +2

    Small clarification, HLSL is the language used by DirectX, meaning it is windows only. Where as GLSL is multiplatform.

    • @BarneyCodes
      @BarneyCodes  4 หลายเดือนก่อน +2

      Thanks for clarifying!

  • @hk_labs
    @hk_labs 6 หลายเดือนก่อน +2

    Thank you!

    • @BarneyCodes
      @BarneyCodes  6 หลายเดือนก่อน +1

      No worries!

  • @adeidara9955
    @adeidara9955 8 หลายเดือนก่อน +3

    This is great, thank you! Ps. There is a low humming or noise in the background , I don’t mind it but some people could be sensitive to it ^^

    • @BarneyCodes
      @BarneyCodes  8 หลายเดือนก่อน +3

      Glad you found it useful, and thanks for the feedback, I'll look into eliminating it for future videos!

  • @hunam_
    @hunam_ 5 หลายเดือนก่อน +2

    thank you very much

    • @BarneyCodes
      @BarneyCodes  5 หลายเดือนก่อน +1

      No worries!

  • @JoeFly2009
    @JoeFly2009 4 หลายเดือนก่อน +2

    Great Video!
    I saw another comment talking about Minecraft's Vanilla Shaders (Vanilla means that it's the default version, without any API like OptiFine), and I think it would be interesting to make a video about it.
    Two great examples are bradleyq's shader-toolkit and VanillaPuddingTart.
    (The default files can be obtained by extracting Minecraft's jar file)

    • @BarneyCodes
      @BarneyCodes  4 หลายเดือนก่อน +2

      Thanks! I'm actually really interested in pursuing this idea so I'll definitely check out both of those!

  • @jackmalcolm
    @jackmalcolm 22 วันที่ผ่านมา +1

    Great video. Wish I understood it. I get the general concepts but a lot of the technical stuff flies over my head. Having a tough time learning basics of coding because I don’t have anything to code, a lot of tutorials/learning resources just feel like I’ve been given a list of a languages syntax.

    • @BarneyCodes
      @BarneyCodes  21 วันที่ผ่านมา +1

      It can definitely be that way when you're first getting started! Thankfully you'll start to notice that there are a lot of similarities between languages so once you get a bit more familiar with one, it'll be easier to pick up more. Keep at it and you'll get there!
      I highly recommend finding a tutorial for something that genuinely excites you, it makes it a lot easier to stick with it! (For me it was a really really basic game, I think it was a bit like space invaders or something!)

    • @jackmalcolm
      @jackmalcolm 20 วันที่ผ่านมา +1

      @@BarneyCodes I guess a follow up question would be where would/should I do something like that? Would you do that in a game engine like unity? Or just barebones? I feel like using a game engine might be a detriment to some of the learning process because the bells and whistles are already there, but I also don’t want to give myself an additional level of frustration for no reason.

    • @jackmalcolm
      @jackmalcolm 20 วันที่ผ่านมา +1

      @@BarneyCodes though, I guess it’s just personal preference and in finding a tutorial like that I’d get my (or an) answer.

    • @BarneyCodes
      @BarneyCodes  20 วันที่ผ่านมา +1

      @jackmalcolm I think if your aim is to learn to code, I'd probably recommend not using an engine. A really great starting point would be to check out "The Coding Train" here on TH-cam. Dan, the bloke that runs the channel, has hundreds of videos for all skill levels and his enthusiasm is infectious!
      In fact I think he may have pretty recently released a course on getting started programming, which could be perfect! EDIT: It's called "Creative Coding for Beginners - Full Course!" if you want to look it up :)

  • @FurryWrecker911
    @FurryWrecker911 4 หลายเดือนก่อน +1

    Im a 3d artist who has been wanting to get into technical art seeing that it's tight competition to get a job doing 3D stuff, but everyone and their mother needs like 5-10 tech artists. This is my gateway into securing my future. Did 3D stuff or 7 years under my last employer, but it's still tight as ever to get in anywhere else.

    • @BarneyCodes
      @BarneyCodes  4 หลายเดือนก่อน +1

      Best of luck! Hopefully this can get you started on your shader journey!

  • @chfr
    @chfr หลายเดือนก่อน +5

    Neat video! I went through the (current state of the) book of Shaders. I later saw people being critical on it in forums, saying it has some limitations, and your video helped me see one of it.
    The book of Shaders tackles pretty much only the contents of the .frag files, but thanks to the "circles array" example you made, I realize the importance of the "CPU" side of things, and passing custom variables.

    • @BarneyCodes
      @BarneyCodes  หลายเดือนก่อน +2

      Glad you found it useful! I had similar frustrations with a lot of shader tutorials, so happy to hear that my one has helped in that regard

  • @Dr.W.Krueger
    @Dr.W.Krueger 4 หลายเดือนก่อน +1

    I forgot more in 44 years of computer graphics development than others learned over the course of their entire lives

  • @elisthetic
    @elisthetic 4 หลายเดือนก่อน +2

    i would like you to know that this video is SO WELL MADE and beautifully explained, that me, a person with 0 prior experience to coding, no idea what the brackets even do, are able to understand the concepts perfectly well. Thank you so much, my journey of learning how to make games is looking a lot less dim now 😭

    • @BarneyCodes
      @BarneyCodes  4 หลายเดือนก่อน +1

      Wow, that's amazing! Glad you found it so useful and good luck on your journey! Feel free to reach out if you have any questions!

  • @__Rizzler__
    @__Rizzler__ 6 หลายเดือนก่อน +2

    thanks breh

    • @BarneyCodes
      @BarneyCodes  6 หลายเดือนก่อน +1

      No worries!

  • @CodeDisease
    @CodeDisease 4 หลายเดือนก่อน +1

    0:40 coffee time

  • @SirSnowman
    @SirSnowman 6 หลายเดือนก่อน +2

    If you delete "Chapters:" in the videodescription an start right with 00:00 ... you'll get the chapters also in the videotimebar as well

    • @BarneyCodes
      @BarneyCodes  6 หลายเดือนก่อน +3

      Thanks so much for that! I moved some things around in the description which must have screwed them up!

    • @SirSnowman
      @SirSnowman 6 หลายเดือนก่อน +1

      @@BarneyCodes no problem, I delete my comment tomorrow, to keep you tutorial clean :)

  • @Mtaalas
    @Mtaalas 4 หลายเดือนก่อน +1

    Draw a circle... then draw the rest of the fucking pantheon! :D
    Great video, straight to the point :)

    • @BarneyCodes
      @BarneyCodes  4 หลายเดือนก่อน

      Hahahaha thanks, glad you liked it!

  • @pentachronic
    @pentachronic 5 หลายเดือนก่อน +1

    The edge joke cracked me up!! Would be interested if Shaders are used for physics and engineering math calculations ? At the end of the day it’s just doing a load of parallel float (or other) ops.

    • @BarneyCodes
      @BarneyCodes  5 หลายเดือนก่อน +1

      I'm glad somebody got it, it's the first time someone mentioned it hahaha
      That's a really great question! There's a type of shader called a compute shader that is often used for exactly that! Compute shaders are basically a really flexible type of shader where the programmer gets to define most things about how it is run, and can read/write into "shader storage blocks" so you're not limited to just outputting to textures and you don't need to render geometry to trigger it to run.
      Before I learned about compute shaders, I did try to use textures to store particle positions but I couldn't get it to work too well. I'm sure that it's possible though!

  • @tommysanger6659
    @tommysanger6659 4 หลายเดือนก่อน +3

    Great video! A couple questions I have.
    If shaders are meant for the GPU, what happens when running on a system with only a CPU?
    For the background image, is there a difference in handling png, jpeg, etc? Or are they passed as just the pixel data?
    For video games, are shaders drawing everything? Or do they receive the frame (like the background image) and then apply additional changes to that?
    This is the first shader video I've come across, so I'm sorry if these are commonly answered questions.

    • @BarneyCodes
      @BarneyCodes  4 หลายเดือนก่อน +2

      Really great questions!
      Most mordern CPUs will have some sort of on-board graphics which is essentially like having a mini GPU built into it. A dedicated graphics card will be a lot faster and usually perform better too. You can get CPUs without graphics in built, but they're the exception not the norm.
      The CPU is where the work of opening/reading the files happens, and it then will just pass the pixel data to the CPU, so there shouldn't be any difference between different file types. If you're doing it yourself (ie not using an engine/framework), you'll have to set what form that pixel data takes using the graphics API you're using (this will be things like whether its RGBA or ARGB etc)
      In games, shaders will be drawing everything, but if you're using an engine or framework they will have shaders that do pretty much everything for you, you'll just tell it what models/textures/sprites to use and it will handle the rest. You'll almost always be able to write you own shaders though, if you need to do something a little obscure or want a custom effect.
      I hope that helps!

    • @tommysanger6659
      @tommysanger6659 4 หลายเดือนก่อน +1

      @@BarneyCodes Yes that helps a bunch! I did look some other stuff up and it seems there are more than just vertex and fragment shaders. Are the others just variants of these two that focus on specific aspects which could be combined into the base 2?
      Also, an additional question. I know NVIDIA applies their DLSS stuff that uses AI to make games look better. Are these just game specific shaders that are created using machine learning? Or does the regular image render from shaders, and then have another round in the GPU where DLSS polishes up the finished frame?

    • @BarneyCodes
      @BarneyCodes  4 หลายเดือนก่อน +1

      That's great to hear!
      Yea there are a bunch of types of shaders, and they are all their own unique thing and are used at different steps. You hear of vertex and fragment shaders the most though because they are required to draw stuff on the screen, where as the others are optional. The most common non-fragment or vertex shaders are probably geometry and compute shaders. Geometry shaders basically lets you turn a vertex into a group of vertices (eg you could turn a single point into a cube). Compute shaders are essentially just a way for you to use the parallel power of the GPU outside of the rendering process. It uses Shader Storage Buffer Objects (SSBOs) to transfer data between the CPU and GPU, so once the compute shader is finished you can read the SSBOs for the output and then use that information however you want.
      I don't know too much about DLSS but I had a quick look and it sounds like it's all done AFTER the rendering has finished. I think the idea is that you render to a lower resolution so that it's really fast, then DLSS upscales that smaller frame to a larger resolution. It uses special hardware on modern GPUs that is purpose built for running AI!

    • @AntonioNoack
      @AntonioNoack 4 หลายเดือนก่อน

      "For video games, are shaders drawing everything? Or do they receive the frame (like the background image) and then apply additional changes to that?"
      Yes, shaders are drawing everything, but at the same time, for things like transparency, you can enable blending (glEnable(GL_BLEND)), and then it will combine your calculated color with that of what you have drawn previously.
      Unfortunately, transparency in 3D is a complicated topic, so I'd recommend avoiding it when starting.

  • @ceruleansky6670
    @ceruleansky6670 6 หลายเดือนก่อน +1

    Instructions unclear about beverage choice grabbed vodka now I have to rewatch the video 11/10

    • @BarneyCodes
      @BarneyCodes  6 หลายเดือนก่อน +1

      Hahaha I'll be more specific next time

  • @zaftnotameni
    @zaftnotameni 7 หลายเดือนก่อน +2

    crazy that nowadays a 30 min video is referred to as "quite a long video"

    • @BarneyCodes
      @BarneyCodes  7 หลายเดือนก่อน +1

      As in 30 mins is a long video or it's not? 😂

    • @zaftnotameni
      @zaftnotameni 7 หลายเดือนก่อน +1

      hahaha, I meant it's not, specially if it is informative like this... : )

    • @BarneyCodes
      @BarneyCodes  7 หลายเดือนก่อน +1

      @@zaftnotameni Glad you found it informative! I think part of it being a "long video" in my mind is because it took a long time to make!

  • @miguelmyers8929
    @miguelmyers8929 8 หลายเดือนก่อน +1

    can you cover generating normals with the shaders? tangent space and world space?

    • @BarneyCodes
      @BarneyCodes  8 หลายเดือนก่อน +1

      We can definitely look at that in a future video, great idea!

  • @auditdb7433
    @auditdb7433 3 หลายเดือนก่อน +1

    Lost me at swizzling, but guess it helps to have 3d coding knowledge. Really hard to find a simple tutorial that goes deep on the basics. I really like the style of this vid and you had me for the first ten minutes. I will persevere.

    • @BarneyCodes
      @BarneyCodes  3 หลายเดือนก่อน +1

      Sorry to hear that! Honestly, you can get away with not using swizzling so I'd encourage you to just skip that part and keep going!
      All you need to know for swizzling is, if you see something like vec.xxy, it's the same as saying vec3(vec.x, vec.x, vec.y)
      Hope that helps!

    • @auditdb7433
      @auditdb7433 3 หลายเดือนก่อน +1

      @@BarneyCodes thanks 🙏

  • @marsovac
    @marsovac 4 หลายเดือนก่อน +2

    Nice video. Just one nitpick. The grayscale is incorrect, since human eyes don't treat colors equally. It depends on the use case and the color space but the general simple formula is: 0.2126 R + 0.7152 G + 0.0722 B. There are ones with square root and squaring of colors that aproximate it better, but are much more expensive in terms of performance.

    • @BarneyCodes
      @BarneyCodes  4 หลายเดือนก่อน +1

      Huh, that's really interesting! Thanks for the info!

  • @crab-cake
    @crab-cake 7 หลายเดือนก่อน +2

    not really familiar with shader languages but recently i've been looking into webgpu. in particular the wgpu rust crate. i think webgpu has a lot of potential. only downside is that there aren't many resources to learn outside of the spec since it's so new.

    • @BarneyCodes
      @BarneyCodes  7 หลายเดือนก่อน +1

      I did have a look into webgpu a little while ago, and like you said there aren't many resources. I'm not sure how many browsers support it at this point either? Looks really cool though, excited to see what it brings!

  • @roganjosh6220
    @roganjosh6220 4 หลายเดือนก่อน +1

    atleast now I know I need a new monitor

  • @davidcadavid7909
    @davidcadavid7909 2 หลายเดือนก่อน +1

    Hello. First of all great video. I am just getting started with this topic and learning more about how games work in general so this has been a great introduction to many concepts.
    I have a question: For the code shown at 31:49:
    float colour = 1.;
    for(int i = 0; i < num_circles; i ++) {
    float d = length(pos - circles[i].xy) - circles[i].z;
    d = step(0., d);
    colour *= d;
    }
    gl_FragColor = vec4(colour, colour, colour, 1.);
    I don't understand how the "colour" calculation works here, meaning, if it is 0 in the first iteration, it will already be 0 for all other circles in the loop since the initial value is outside the loop . Also the gl_FragColor is outside the loop, so we only paint once even though we calculate a value for all circles ? What am I missing?

    • @BarneyCodes
      @BarneyCodes  2 หลายเดือนก่อน +1

      Very good question! I think my variable name makes it not very clear, it probably should have been called something like "outsideCircles" or something similar.
      Basically, colour will stay as 1 only if it's not inside any of the circles. If it's inside any single circle, it will become 0, which will turn that pixel on the screen black (which is why I called it colour even though I probably shouldn't have!)
      You're right that if it turns to 0 in the first iteration, then it will always be 0 making the rest of the looping a bit redundant. However, because of the way GPUs parallelise things, you're only as fast as the slowest pixel, so if one pixel has to loop through all the circles, then there's no real speed to gain from breaking out of the loop early for other pixels.
      I hope that makes sense, please let me know if you've got any more questions!

    • @davidcadavid7909
      @davidcadavid7909 2 หลายเดือนก่อน

      @@BarneyCodes Wow thanks so much for the fast response. I think i understand what you are saying. At first i was seeing it as something sequential but I remembered that the code is executed in the context of a single pixel, and then it is executed for all pixels in parallel, so if I understand correctly we are basically checking if at least one circle is present in the pixel we are checking against and if it is, we paint that pixel black, otherwise we paint it white.
      Let me know if that is correct or if I am missing something (again 😅)
      Thanks again. Greetings from Colombia!

    • @BarneyCodes
      @BarneyCodes  2 หลายเดือนก่อน +1

      No worries at all, and yep, that is exactly what's happening! Each pixel is checking if it's inside any one of the circles and turning black if it is!
      It can definitely take some time to think about the code in this context and totally normal to find it confusing! But it gets easier the more you do it and it seems like you're picking it up really well!

  • @ruadeil_zabelin
    @ruadeil_zabelin 4 หลายเดือนก่อน +1

    More specifically HLSL is used by Direct3D, while GLSL is used by OpenGL and Vulkan. It is also worth noting that crosscompilation through for example spir-v is possible which means you really only need to write 1 language (typically hlsl) to support a wide variety of graphics apis.

    • @BarneyCodes
      @BarneyCodes  4 หลายเดือนก่อน +1

      I'll have to check the cross compilers out, didn't know that was a thing! Thanks!

    • @ruadeil_zabelin
      @ruadeil_zabelin 4 หลายเดือนก่อน +1

      ​@@BarneyCodes The way I do it in my game engine is write everything in HLSL. Then i use glslang to compile to Spir-V. From there i use spirv-cross to "decompile" to either GLSL that targets opengl or vulkan; at which point you can use the opengl commands to compile it or precompile back to target opengl spirv or vulkan spirv (yep.. they're not compatible with eachother; they have their own spirv flavour). You have to take this decompile step because the HLSL resulting spir-v is not compatible with opengl. Supposedly it works with Vulkan but i couldnt get it to work. But with this it works flawlessly across d3d11, 12, opengl 4.6 and vulkan 1.2. The decompiled GLSL isn't even half bad either.. it looks pretty clean.

    • @BarneyCodes
      @BarneyCodes  4 หลายเดือนก่อน +1

      ​@@ruadeil_zabelin Thanks for explaining! I'm guessing your engine allows people to choose which renderer they're using then? If so, that's impressive! The only other scenario I can think of where you might need to do something like this is if you're porting a game from one renderer to another. Are there other use cases for such a thing?

    • @ruadeil_zabelin
      @ruadeil_zabelin 4 หลายเดือนก่อน +1

      @@BarneyCodes You can pick a renderer yes, but I made it so it just suggests what I think is the "best" supported one for that platform. So on windows it always defaults to d3d11; on linux its Vulkan, on mac its opengl (though i might try metal someday). I basically studied how unreal engine handles their render api abstraction and found that its basically very similar to the d3d11 api. I wrote a similar interface and just implemented all the function calls for all the graphics api's. If you choose the abstraction well its not all that difficult to do. The only hurdle was the shaders so the possibility of crosscompiling was really nice.

    • @BarneyCodes
      @BarneyCodes  4 หลายเดือนก่อน +1

      @@ruadeil_zabelin Ahhh that makes a lot of sense! Sounds like a really cool project! Thanks for all the info :)

  • @MarekFajkus
    @MarekFajkus 6 หลายเดือนก่อน +3

    The only bad thing about this video is that it didn’t exist yet back when I was learning this the first time. From now on this will be the introduction I recommend. 👏👏👏

    • @BarneyCodes
      @BarneyCodes  6 หลายเดือนก่อน +1

      Wow! Thanks so much for that, very encouraging to hear!

  • @Phoeboi
    @Phoeboi 5 หลายเดือนก่อน +1

  • @alister_
    @alister_ 6 หลายเดือนก่อน +1

    Damn! If I had the chance to hug you I would surely do!

    • @BarneyCodes
      @BarneyCodes  6 หลายเดือนก่อน +1

      Glad it was helpful!

  • @KittenKatja
    @KittenKatja 6 หลายเดือนก่อน +2

    Can you do a video about changing Minecraft's Vanilla shaders? (it's also GLSL)
    To get started, you simply need to create a resource pack, and hit F3+T to reload resource packs in-game, from there, it would be like copy/pasting shader files into the resource pack, and modifying them there. (legally, you would need to create the modified file)

    • @BarneyCodes
      @BarneyCodes  6 หลายเดือนก่อน +4

      That sounds like a really fun idea! I've never made Minecraft shaders before so I'll have to play around with it a bit before making a video, but I really like that idea! Thanks for the comment!

  • @rmt3589
    @rmt3589 6 หลายเดือนก่อน +3

    For a videogame, is there any reason we would want more code in the pixel shader? (I already forgot what it's called)
    Seems like keeping it minimal would be the goal for performance.

    • @BarneyCodes
      @BarneyCodes  6 หลายเดือนก่อน +3

      It really depends on the use case, but in games the most common use is for visual effects (think shaders in Minecraft, it doesn't have an affect on gameplay but completely changes how it looks).
      It can have applications outside of just visuals as well though, for example I'm working on a game at the moment where I use shaders, and in particular the fragment/pixel shader, to calculate the damage to the terrain on a per-pixel level. If you want to learn more about that, I've got a playlist with my devlogs here: th-cam.com/play/PLlaA0JvEhcG_rFyz7oa7BR6GM02oQeo8b.html
      As with anything performance related though, it's worth using a profiler and finding out where the actual bottlenecks are, because generally the GPU is very fast, but only if you use it "properly" if that makes sense. Adding more effects and shaders won't necessarily have a negative affect on performance, but the best way to find out is to try it and see what happens!
      Hopefully that helps, let me know if you have any other questions!

    • @rmt3589
      @rmt3589 6 หลายเดือนก่อน +3

      @@BarneyCodes Thank you so much. I'm taking a swing at making my own engine after the Unity debacle, and finding out that many calculations were happening a frame shocked me. Glad it's not usually an issue.

    • @BarneyCodes
      @BarneyCodes  6 หลายเดือนก่อน +3

      It's pretty amazing how fast computers really are! Hope your engine project goes well!

  • @TsingYiTube
    @TsingYiTube 7 หลายเดือนก่อน +4

    0:36 I am an asshole!! 😂

  • @ecruz2317
    @ecruz2317 3 หลายเดือนก่อน +1

    How does one attach or combine vec to a slider bar that controls the intensities? i am close but don't know how to combine say 3 calls into 1 call in a slider format and not separated x, y, z, w, + thanks if anyone helps.

    • @BarneyCodes
      @BarneyCodes  3 หลายเดือนก่อน +1

      I think if you want to control each aspect of the vector individually you're going to have to use multiple sliders. You should be able to combine the values from each slider into a single vector though and set that in your shader.
      Pseudo code might look something like:
      shader.setUniform("mySliderValues", [slider1.value(), slider2.value(), slider3.value()]);
      Hope that helps

    • @ecruz2317
      @ecruz2317 3 หลายเดือนก่อน +1

      i'll give it a shot when i can and probably return with any progress, appreciate it, i do not do this, it is more like a new thing to learn, thank you.@@BarneyCodes

    • @BarneyCodes
      @BarneyCodes  3 หลายเดือนก่อน

      @@ecruz2317 Sounds good! I think the best way of learning is doing what you're doing and trying things a bit outside your comfort zone! Hope it goes well!

  • @tim_allen_jr
    @tim_allen_jr 4 หลายเดือนก่อน +1

    🧠⚡️📈

  • @Xphy
    @Xphy 5 วันที่ผ่านมา +1

    i just wanted how these shaders pass data and vars between them and between the environment , where the returned output value goes exactly

    • @BarneyCodes
      @BarneyCodes  5 วันที่ผ่านมา +1

      Data can be passed into the shader using by setting uniform values and, without doing extra setup, data is outputted from the shader in the form of textures/image data.
      If you want to be able to get other data out of the shader, then you should look into Shader Storage Buffer Objects (SSBOs) which can be manipulated inside the shader and then read out again by the CPU. They can be a little fiddly to set up, but they work very well!

    • @Xphy
      @Xphy 5 วันที่ผ่านมา +1

      @@BarneyCodes i appreciate your reply and i'll learn more abt it , thank you

    • @BarneyCodes
      @BarneyCodes  5 วันที่ผ่านมา +1

      No worries at all! I should also mention that there are "compute" shaders, which are seperate from the rendering pipeline and work only with SSBOs I think, so if you're only using the shader to run some simulation or something, they might be worth checking out too!

    • @Xphy
      @Xphy 5 วันที่ผ่านมา

      exactly i wanted to use gpu for training ai

  • @MuhammadRafay-gg6gi
    @MuhammadRafay-gg6gi 5 หลายเดือนก่อน +1

    I tried to follow along and wrote the code shown at 11:09 in p5.js web editor but could not get it to work. I went back to 5:20 to look at the previously shown code but somehow couldn't see how these two codes link together. Please help

    • @BarneyCodes
      @BarneyCodes  5 หลายเดือนก่อน +1

      In the code at 5:20 you can see on line 5 the call to the loadShader() function. This is how we load the code you're writing at 11:09 with the JavaScript code. You'll need to make sure the names you use in the loadShader() function exactly match the filenames you use for your vertex and fragment shaders!!
      What error message do you get when you run your code?
      There's also the example code linked in the description, so feel free to have a look at that, it might be easier to see what you're missing there!
      Hope that helps!

  • @benjaminatwood
    @benjaminatwood 2 หลายเดือนก่อน

    This video is swizzling!

  • @teamruddy611
    @teamruddy611 6 หลายเดือนก่อน +1

    What even is the language that you paid with javascript? I've never heard of it, likely less common.

    • @BarneyCodes
      @BarneyCodes  6 หลายเดือนก่อน +1

      If you mean P5js, it's just a javascript library that makes it really easy to draw on a canvas, but not necessary at all, it just makes the demos easier. And GLSL is a very common language for writing shaders! Hope that clears things up a bit!

  • @redfoxartist7548
    @redfoxartist7548 23 วันที่ผ่านมา +1

    p5.js says: Yikes! An error occurred compiling the vertex shader:ERROR: 0:3: 'gl_FragColor' : undeclared identifier
    ERROR: 0:3: 'assign' : l-value required (can't modify a const)
    ERROR: 0:3: '=' : dimension mismatch
    ERROR: 0:3: 'assign' : cannot convert from 'const 4-component vector of float' to 'const highp float'

    • @BarneyCodes
      @BarneyCodes  23 วันที่ผ่านมา

      From the error it looks like you're trying to use gl_FragColor inside the vertex shader, but I think it's only usable inside the fragment shader.
      It could be that you've accidentally got your vertex and fragment shaders the wrong way around in the loadShader function?
      Let me know if that helps!

  • @Draugo
    @Draugo 4 หลายเดือนก่อน +1

    Just out of interest. Would it be worth it to write the SDF for loop as a while loop instead to bail out early as soon as 0 is hit? How complex does the calculation need to be that this actually makes a difference? Or is it a form of branching and inherently slower than predefined number of loops.

    • @BarneyCodes
      @BarneyCodes  4 หลายเดือนก่อน

      Great question! It probably would be beneficial because in most cases a pixel won't only be inside the last circle, but it probably won't be a massive speed up, since in shaders you can only go as fast as the slowest case. The way GPUs work is all the fragments that are being calculated have to wait for the last fragment until they can move on to the next step. With GPU programming you're better off making the worst case scenario better, rather than making the most common scenario better, which is a bit strange!
      Hope that helps!

    • @Draugo
      @Draugo 4 หลายเดือนก่อน +1

      @@BarneyCodes Yeah, with that restriction it won't make a great difference unless well over 50% of the time you're certain that the pixel will be inside a circle in this case so there's a good chance that every pixel in the batch would complete early.
      I assume then that the while-loop in itself is not noticeable slower than a discreet number of loops from execution standpoint since for-loop in general is just a fancier while-loop?

    • @BarneyCodes
      @BarneyCodes  4 หลายเดือนก่อน

      @Draugo yea you would have to do some fairly major optimising I think. There's probably a way to do it though!
      And I'm not actually sure about while loops vs for loops, but my guess would be the same as yours, that they'd be basically the same

    • @Draugo
      @Draugo 4 หลายเดือนก่อน +1

      @@BarneyCodes Thanks for the great answers. The video was also a really good intro to shaders.

  • @zaftnotameni
    @zaftnotameni 7 หลายเดือนก่อน +2

    personally I'd prefer removing the p5 specific sections and making the video based on shadertoy or something like that, it gets a bit confusing if someone is new to both p5 and shaders

    • @BarneyCodes
      @BarneyCodes  7 หลายเดือนก่อน +1

      Good suggestion, thanks for the feedback!

    • @joningram
      @joningram 7 หลายเดือนก่อน +1

      @@BarneyCodes
      Whereas I'm very happy that you *did* include the p5 specific sections - there are plenty of more general introductions to shaders out there while this one shows you how they integrate with p5. Thank you.

    • @BarneyCodes
      @BarneyCodes  7 หลายเดือนก่อน +1

      That's good to hear, thanks for your feedback too! I had to use something, so no matter what language/framework there would have been people who aren't familiar with it. I think P5 is hopefully easy enough for people to pick up!
      Thanks again for your comment!

  • @scottlott3794
    @scottlott3794 7 หลายเดือนก่อน +2

    You spelled color wrong. :). Excellent video, thank you so much!

    • @BarneyCodes
      @BarneyCodes  6 หลายเดือนก่อน +2

      Glad you liked it! Colour is how we spell it in England/Australia!

  • @tombouie
    @tombouie 4 หลายเดือนก่อน +1

    Thks & over my head but;
    Pls take a look at FPGAs & Geometric Algebra and tell us what you think

    • @BarneyCodes
      @BarneyCodes  4 หลายเดือนก่อน +1

      I don't really have any experience with either of those topics but I can take a look!