How Shaders Work in OpenGL

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

КОМЕНТАРІ • 223

  • @ewanholmes4559
    @ewanholmes4559 5 років тому +857

    This better be the most beautiful triangle ive ever seen...

    • @carrapaz3645
      @carrapaz3645 4 роки тому +44

      it will be, every dumpling it's beautifull for his mum

    • @dualperception4296
      @dualperception4296 4 роки тому +39

      You havent tried vulkan yet have you?

    • @marcovalentinoalvarado3290
      @marcovalentinoalvarado3290 3 роки тому +24

      I drawn a rectangle cause im badass

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

      @@dualperception4296 No, he hasn't

    • @058w.
      @058w. 3 роки тому +6

      @Drake Lionel yea it works 100% guys. just give your social security bank account and credit card/paypal password.
      remember to sell your house and car or whatever else you have and deposit money to your bank account. it works better this way.
      only con is that you go bankrupt or homeless but hey you gotta compromise something too , right

  • @machine0man
    @machine0man 4 роки тому +241

    Other UA-camrs : Uses Drawings to Explain
    The Cherno : Just talk and Draws on Viewer's Mind

  • @arondejong6515
    @arondejong6515 7 років тому +534

    Best C++ and OpenGL tutorials EVER!

  • @spencerfreebairn9346
    @spencerfreebairn9346 6 років тому +130

    "... on the fly shader generation..." As if my mind weren't blown enough already.
    I'm loving these videos! You are an amazing teacher! You go in depth but always remain within the scope of the discussion. Excellent.

  • @goncalosoares8483
    @goncalosoares8483 7 років тому +150

    I'm having a college class on computer graphics and these videos are helping a lot! Please keep up the great work

  • @DridriLaBastos
    @DridriLaBastos 7 років тому +256

    OH YEAH TRIANGLE, THE NEXT TIME I WILL SEE YOU !!!

  • @eloquentlyemma
    @eloquentlyemma 7 років тому +45

    Thank you for this video. It has helped me clarify a few things in my mind. I'm going to go back and look at my own shader code now that you pointed out how many times the fragment shader is run in comparison to the vertex shader (I have a nasty feeling that my code will need a rewrite). It just those simple obvious pieces of information that can make such a difference. Also, I can't wait for when you show us more complex shaders.

  • @denic6861
    @denic6861 4 роки тому +7

    Beautifully explained. As somebody who has worked with shaders for the past 7 years, I am glad more light and accessible information is being tread on this amazing world of technology. I will be recommending this video to people for sure!

  • @TinoBurset
    @TinoBurset 5 років тому +69

    I'm 10 minutes in and just realized that there were no cuts in the video, with an spectacular and well paced explanation. Simply amazing content man!

    • @bumpsy
      @bumpsy 4 роки тому +16

      there are SO many cuts in Cherno videos xD he very often only says one sentence per cut but he cuts cleverly to not disturb the audio too much so it seems like he's talking in one stream

    • @TinoBurset
      @TinoBurset 4 роки тому +6

      @@bumpsy You are absolutely right! 😆 I guess that it _felt_ that way at the time.

    • @maugre316
      @maugre316 3 роки тому +2

      @@TinoBurset Just noticed one at 2:36, but there are more. I guess one way round it is to use multiple cameras and switch between them but the actual content is the important thing.

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

      there is one two seconds later at 10:02 lmao

  • @AmeshaSpentaArmaiti
    @AmeshaSpentaArmaiti 7 років тому +140

    I didn't know shaders were generated on the fly. That's pretty cool.

    • @deletevil
      @deletevil 4 роки тому +1

      what do you think happens when you go forward holding a flashlight/torch and the intensity of the light on the wall before you increases lol?

    • @AmeshaSpentaArmaiti
      @AmeshaSpentaArmaiti 4 роки тому +41

      @@deletevil That's not generating an entire System-specific shader during runtime. that's just a shader.

    • @deletevil
      @deletevil 4 роки тому +1

      @@AmeshaSpentaArmaiti , aah okay, thanks. I am a noob learning.

    • @generichuman_
      @generichuman_ 3 роки тому +42

      @@deletevil then why would you say that with such confidence if you're just learning? A little humility goes a long way

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

      @@generichuman_ and what are 'you' gaining from by replaying to a noob like that?

  • @Rasenganist
    @Rasenganist 4 роки тому +4

    @6:24 ;) The beautifull thing for me is to see people making great tutorials and videos, helping other to improve their own skills. Thank you for that man! It is a pleasure to listen to your videos.

  • @nm5paczek
    @nm5paczek 5 років тому +16

    Insane teaching skills, thank you

  • @apfelstrudlOfOA
    @apfelstrudlOfOA 2 роки тому +2

    I just stumbled upon this video by chanse, and I love your teaching style. You're extremely pedagogic in the way you teach. You repeat yourself with different wording and examples so we get different types of understandings for the same issue you're trying to teach, and it works tremendously! Great video!

  • @yinhao4085
    @yinhao4085 6 років тому +8

    This is the most detailed explaination! Helps so much on visualising the shader pipeline!

  • @mitcaro7310
    @mitcaro7310 2 роки тому +3

    I spent a semester on a GPU programming course at my university and didn't get a word of what our "experienced" professor said! Even until the end of the semester, I didn't know what shader or even OpenGL is. I hated that course. But now with only 6 short videos, BANG, everything makes sense and is easy to understand. Come to Switzerland and become a university professor Cherno. You're just fantastic.

  • @eliaspr8124
    @eliaspr8124 7 років тому +102

    I'd say you forgot a cut at 3:10

  • @RudolfCickoMusic
    @RudolfCickoMusic 11 місяців тому +3

    So in summary.
    - Vertex shader is called for each vertex. (used just for position)
    - Fragment shader (pixel shader) runs for each pixel that has to be rasterised.

    • @shashanktambe6341
      @shashanktambe6341 5 місяців тому

      What is rasterisation?

    • @RudolfCickoMusic
      @RudolfCickoMusic 5 місяців тому +1

      @@shashanktambe6341 Basically a vector function like you have in math. For example y = 2x where x = {1..10} all the pixels from (1,2) to (10, 20) will be rasterized.

    • @shashanktambe6341
      @shashanktambe6341 5 місяців тому

      @@RudolfCickoMusic thanks for coming back to comment

  • @timothyvandyke9511
    @timothyvandyke9511 4 роки тому +5

    "When it comes time to optimize and think about performance, which is really all the time" Thank you for making me feel less crazy.

  • @shunnie8482
    @shunnie8482 5 місяців тому

    Great explanation. I think its a great idea to give examples with modern game engines as well, in Unity or Unreal (in Unity->Shadergraph, in Unreal->Material Editor) you are actually making fragment shaders. There is also a part where you can also specify vertex positions as well, thats the vertex shader. In Unreal thats World Offset in the Material Editor.
    In Unity, if you are writing a shader completely in HLSL, you can also access the vertex shader, and you can see that all it does is get the world positions and then multiply them by the MVP matrix (model view projection matrix) to get the position it needs to have on the screen.
    For me it clicked when I saw these things in the programs I use everyday. I hope it helps someone trying to understand them as well.

  • @siddharthgpta
    @siddharthgpta 6 років тому +21

    In the beginning you were explaining that glDrawArrays draws the currently bound VertexBuffer, but just above the while loop you've bound it to 0. How is it still drawing the triangle in this case?

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

      That's also what I didn't get

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

      the glBindBuffer(0) unbinds the buffer. After this we can write to the buffer

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

      This got me thinking. I found this in the docs:
      Buffer object names are unsigned integers. The value zero is reserved, but there is no default buffer object for each buffer object target. Instead, buffer set to zero effectively unbinds any buffer object previously bound, and restores client memory usage for that buffer object target (if supported for that target). Buffer object names and the corresponding buffer object contents are local to the shared object space of the current GL rendering context; two rendering contexts share buffer object names only if they explicitly enable sharing between contexts through the appropriate GL windows interfaces functions.
      But don't exactly know what it means in the last part

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

    I have never found such a clear and thorough explanation of this anywhere else. Thank you for making this.

  • @kevingergely2462
    @kevingergely2462 4 роки тому +1

    I will soon start working with openGl and your videos are really good to refresh my memory with it. Thank you for the awesome tutorials.

  • @panaah30
    @panaah30 3 роки тому +6

    You explain so clearly ❤️
    Keep doing this ❤️🙂

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

    Man, the quality of your videos is just amazing. Keep up the good work!

  • @JayAnAm
    @JayAnAm 6 років тому +5

    Very good explanation, just subscribed!

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

      And I am your subscriber!!!! lol

  • @mukeshpareek5414
    @mukeshpareek5414 6 років тому +5

    Hi
    I have question here from opengl series video number 5
    glGenBuffers(1, &buffer);
    glBindBuffer(GL_ARRAY_BUFFER, buffer);
    glBufferData(GL_ARRAY_BUFFER, 6*sizeof(float),position,GL_STATIC_DRAW);
    glEnableVertexAttribArray(0);
    glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 2, 0);
    glBindBuffer(GL_ARRAY_BUFFER, 0); // Why still we see Triangle rendered even we are unbinding the buffer here? can anyone please help me to understand?

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

    I really love that this does not feels like someone reading a Wikipedia page to me. I really love how you explain the fundamentals and why we use them as well to make sense. Thanks a lot for these videos man!

  • @JimmyTheZombie115
    @JimmyTheZombie115 7 років тому +20

    When I was thinking of OpenGL... THIS came out! Nice!

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

      yep. same dude!

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

      sadly is not everyday

  • @greebly6011
    @greebly6011 7 місяців тому

    not even drawing or using animations and this still is one of the best explanations

  • @moichumoirunescape
    @moichumoirunescape Рік тому +1

    Your explanations are so clear and easy to understand! Thank you so much for this series, it's really awesome. :)

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

    The best explanation in the internet

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

    My man making an OpenGL Tutorial Series
    i would have gave up if you didn't make a series
    *keep up*

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

    I had a subject named computer graphics in my post graduate. My teacher didnt teach, but was strict in class, telling to write notes record note so on. Literally saying, you are teaching so good.

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

    You made me think now! And visualize without coding or learning anything!

  • @Damoygames
    @Damoygames 7 років тому +39

    Sunday: (TheCherno && ThinMatrix ) == Kreygasm

    • @KennyTutorials
      @KennyTutorials 5 років тому +2

      ​@@lufenmartofilia5804 Two best on my option teachers EVER! And also awesome guys! (TheChernoMatrix)

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

    Can't wait to create my first Shader. Thanks!

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

    I'm trying to get up to speed in OpenGL, and was looking for something on shaders. Found this video, and was so impressed I'm now working through the entire playlist. I'd originally avoided it because I'm actually working in Go -- but I figured, what the heck, apart from a few language-specific differences, it all works basically the same; sure, I can translate from C++ (which I've not used for literally decades) to Go (which I've only just begun tinkering with...) :-) Wrapping my head around three-four languages at once is about par for the course! ;-)

  • @spookier444
    @spookier444 4 роки тому +3

    he got Electronic Arts team perform every intro

  • @miteshsharma3106
    @miteshsharma3106 7 років тому +12

    Can you please make a video about unions in your c++ series

    • @Ahmed-wj5sd
      @Ahmed-wj5sd 7 років тому +1

      Mitesh Sharma he already did in the sparky engine series 5.5

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

    My possibilities are exploding right now. Thanks for the awesome tutorials! :D

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

    your hands are freaking me out but by purely listining to you it's excellent! thanks so much!

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

    These videos, excellent quality.

  • @SaravanaKumar-nl4sz
    @SaravanaKumar-nl4sz 7 років тому

    clean and clear intro for shader. Keep doing

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

    Thank you! Your explanation is very easy to understand.

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

    Thank you so much for the quality content!

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

    Thanks man, you are really good teacher.

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

    This is fantastic! love this explanation!

  • @ironichoneybadger5066
    @ironichoneybadger5066 2 місяці тому

    I'm coming to this series in 2024, and the comments all being in agreement that this tutorial is what we all needed to learn this skill is so entertaining to me

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

    I don't really think i can ever find such easy-understandable tutorial about OpenGL and Graphics Programming, which is really complicated by itself.
    Aah, and of course: drawing the best triangle in my life is priceless :)

  • @zaspanyflegmatyk2446
    @zaspanyflegmatyk2446 5 років тому +148

    when i hear "shaders" all that comes to my mind are Minecraft shaders

    • @xtdycxtfuv9353
      @xtdycxtfuv9353 4 роки тому +7

      kek same

    • @miles7267
      @miles7267 4 роки тому +5

      and they have to be written in code too

    • @andresvallelisboa5511
      @andresvallelisboa5511 4 роки тому +6

      That is because Minecraft uses them, they allow you to do amazing stuff.

  • @jellykisses9641
    @jellykisses9641 7 років тому +14

    Would it be practical to save compiled shaders (programs are saved as .exe) instead of compiling each time the program runs?

    • @ChrisHorner_WCC
      @ChrisHorner_WCC 7 років тому +9

      I don't think that's possible, as the result of the compilation may be driver-dependant. Plus I don't think OpenGL provides any way to actually copy those compiled shaders to the GPU memory.

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

      You could do that but this will bind the shader to your graphics card as it uses the compiler in the graphics driver to compile your code to the graphics card. And no the program gets only compiled once only if you add glCompileShader to the loop it would do that else you could use the program handle. Also there is a platform independent way to compile you shader the output is then called SpirV shader assembly.

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

    Sos crack, colorado. Gracias!

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

    You are doing something "good" for the society. Appreciate it.

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

    ah yes, an entire video (without coding) just explaining shaders. I love your explanations!!

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

    I love his hoodie

  • @cptray-steam
    @cptray-steam 3 роки тому

    I feel like I'm learning so much!

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

    Hii Cherno.. I need to render camera captured images using fragment shaders, the camera inputs and parameters come from a structure in another file, I need to pass them to my shader class and render them. There are 4 cameras. How do I do it please help me. I have seen many tutorials where they are using some functions to load the image, where we specify file path, but that is only for 1 file. I have 4 camera data's. I'm finding it difficult. Can you please help me?

  • @navegct8457
    @navegct8457 7 років тому +31

    #Notifacation Squad!!!!

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

    So I was reading this on learnopenLG and did try it that I cannot render the vertex budder object unless I have it binded to an vertex array object, idk if this is specific to a Mac or not. I'd really like to know if it is necessary to use a VAO before using any VBO to render anything at all??? Ahhh.... save me from this confusion.

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

    I have a difficult time expressing how much I enjoy these videos. That said it is meant in a strictly non-stocker way... Obviously...

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

    You have a gift for explaining things. Keep up the excellent work, we're tuned in :D

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

    Question: Do you only have one vertexshader and one fragment shader for all your mesh? Let say you have a 3D mesh shader. Do you need to make a new one for a 2D mesh? What about if you have a shader which handles lighting. Do you use the same shader to handle objects which you don't want to be lighted or do you create new shaders for all the different cases?

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

    Greatt, thanks. You should write the opengl documentation

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

    great video again

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

    Other tutorials just assume this will work -- so that I took it that the default shader was a universal hold-over from the pre-shader era.

  • @tuxmusicman
    @tuxmusicman 6 років тому +1

    Sooooooooo much information!

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

    i love cherno video thanks

  • @sleep3017
    @sleep3017 4 роки тому +1

    I always watch through all the ads so he can get his money

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

    One thing I wonder about current GPUs is why they are still reliant on the CPU performing draw calls. Wouldn't it be more efficient to be able to tell the GPU directly via some sort of programmable function when to draw stuff? With how busy the CPU already is it seems like alot of work added to the CPU to constantly have to perform draw calls to make the GPU do its job.
    Maybe I'm just too much of a newb but it just sounds like alot of work for the CPU that could just be done by a processor within the GPU itself

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

    yo i am eating a cadbury egg while watchin this. this is awesome

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

    Love your videos

  • @eliasf.fyksen5838
    @eliasf.fyksen5838 3 роки тому

    Watching that "glBindBuffer(GL_ARRAY_BUFFER, 0);" line is just killing me

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

      Consider that line as a function to unbind the buffer. You are just telling OpenGL that your bound buffer is 0, so nothing

  • @billy.n2813
    @billy.n2813 4 роки тому

    Thank you.

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

    The fragment shader only does one thing, decide what colour each pixel will be. That's all it does... That one simple task........

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

    I drew a quad on a screen without help... It means I understood your lessons well.

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

      ARE YOU SURE??? IT'S ACTUALLY NOT A TRIANGLE?

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

    Why is the Triangle Rendering? The buffer ist not bound because of the glBindBuffer(GL_ARRAY_BUFFER, 0);

  • @Chris-cs7nv
    @Chris-cs7nv Рік тому

    How come that's happening:
    Yes, but now shouldn't this fail because the buffer is unbound? Did I really hallucinate that in a previous video it was said that if we unbind the buffer then opengl will not draw anything?

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

    Is the fragment shader run for each pixel of the display, or for each pixel of a triangle/shape? As in, if I have a drawing area that is 1280x720 and 3 triangles all in the same exact spot that cover, say, 50 pixels worth of the display, will the fragment shader be called 921,600 times (1280 times 720), 150 times (because 3 triangles cover 50 pixels each), or just 50 times (because all 3 affect the same pixels)?

    • @__mk_km__
      @__mk_km__ 7 років тому +3

      150 times.
      EXCEPT if you have depth buffer enabled. In which case GPU may consider not to call fragment shader for the pixels which have their z-value less than in a buffer.
      What is z-buffer? Its a thing that OpenGL uses to prevent things behind other things to get drawn. (great explanation)

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

    I had a problem with OpenGL ES1.1 on my tablet. My app wouldn't draw anything.
    Which lets me to believe that compiling shaders is mandatory.
    But the shader functions arent in the opengles1.1 header!
    And my question is, how do I deal with this situation?
    I was trying to solve this program for around 2 yeras now
    (not really trying all that time, because I switched to developing the PC game)
    Any help?

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

      OpenGL 1.1 and OpenGL ES 1.1 don't support shaders. You need to use at least GL ES 2.0 I think

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

    Ahaa.
    So basically vertex shader = the outline
    fragment shader = what comes in.

  • @himanshupoddar1395
    @himanshupoddar1395 4 місяці тому

    In the plain old architecture we used to provide even the coordinates of vertex in the draw call, now it has been replaced by buffer and shaders. Why???

  • @gamereplayhq
    @gamereplayhq 6 років тому +1

    The quality is at par with the course I'm taking at edx (Computer Graphics), in fact way better as compared to that course. B-)

  • @NikhilKumar-ry7eg
    @NikhilKumar-ry7eg 4 роки тому

    where is your say thanks link?

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

    cherno reminds me of that city,chernobil

  • @ahaququq
    @ahaququq 5 місяців тому

    on NV works too

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

    So, at the simplest level, the vertex buffer details where vertices are in relation to each other, the vertex shaders determine where they are in relation to the screen?

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

      If position is the only data in the buffer, then yes, you could think of them as coordinates in local space. The shader then has transformations to change that to world space, screen space, etc.

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

    Your'e the best!

  • @Sl33pySt3rdust
    @Sl33pySt3rdust 4 місяці тому +1

    everytime i hear the word "shader" i instantly think of minecraft

  • @0xfrijolito
    @0xfrijolito 3 роки тому

    Whats shaders i need to mine with my gpu?

  • @Pdrum2
    @Pdrum2 4 місяці тому

    Yea the naming of shading is bit confusing

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

    THX

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

    How is it possible that it worked in the beginning although we have bound buffer 0 before start of the while loop? I thought (and I think he has even said it in the end of the episode before the previous episode) that it will not work like this because we have to bind the right buffer in order... I am confused, could you please explain it to me?

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

      think of binding the buffer as a rotating bridge. Once the data has been sent to GL_ARRAY_BUFFER(&buffername), the bridge to the &buffername is no longer needed and can be reset or set to another buffer. Setting it to 0 is one way to prevent accidental data transfer to the wrong place.

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

      @@TheKingoftheriff thanks for answer, but how does then opengl know which buffer to use if I uploaded more vertex buffers. I thought it always uses the bound vertex buffer.

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

      @@jakubhorak636 AFAIK, the draw function that outputs all the poly work, will put all the saved buffers on the screen. You only need &buffername while sending data. Currently all of it is stored in GL_ARRAY_BUFFER, which is like an area for all the buffers that belong to that type.

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

    3:09 you forgot to cut there, man

  • @gordonlim2322
    @gordonlim2322 4 роки тому +1

    program that runs on GPU

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

    what's intro music name?

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

    Is this projekt avaible on github?

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

    What's the language of a shader?

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

    Please make a series on directx

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

    Mine doesn't have a default shader then......

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

    I wrote exactly same code but it crashed.