Modern OpenGL Tutorial - Compute Shaders

  Рет қаралды 52,773

Victor Gordan

Victor Gordan

Күн бұрын

In this tutorial I'll show you how to use Compute Shaders in your OpenGL projects.
Source Code
github.com/VictorGordan/openg...
OpenGL Documentation
www.khronos.org/registry/Open...
Discord Server
/ discord
Patreon
/ victorgordan
Timestamps
00:00 Intro
00:10 What are they used for
00:45 How they work
01:22 Compute Shader Example
01:32 Creating Compute Shaders
01:42 Dispatching Compute Shaders
02:28 "Rendering" Compute Shaders
02:45 Compute Shaders Source Code
03:27 Inputs
05:03 Ray Tracer Code
05:35 Warps/Wavefronts
05:59 Improving Performance
06:53 Shared Variables
08:40 Atomic Operations
09:43 Group Voting
11:01 Outro
References
antongerdelan.net/opengl/comp...
www.khronos.org/opengl/wiki/C...
• Coding Adventure: Comp... (comment)
stackoverflow.com/questions/6...
stackoverflow.com/questions/3...
developer.download.nvidia.com...
#opengl #opengltutorial #computergraphics #cpp #visualstudio #3dgraphics #computeshaders #modernopengl

Пікірлер: 90
@BoyBaykiller
@BoyBaykiller 2 жыл бұрын
Feels good seeing high quality content on modern (not the 3.x modern) OpenGL. Thanks! One thing about the shader group vote: It's 4.6 core functionality so you dont have to append the "ARB" suffix. Otherwise it would be using the ARB extension instead of core and somtimes their specification is different. You can then even remove the requiring of the extensions.
@VictorGordan
@VictorGordan 2 жыл бұрын
Thank you! :) My GLSL highlighter extension was throwing some errors about including it, so that's why I did it. Good to know it's not required!
@georgiyx9561
@georgiyx9561 2 жыл бұрын
Thank you so much, i've struggled getting my compute shaders to work and with the help of you, they now work :)
@VictorGordan
@VictorGordan 2 жыл бұрын
Good to hear! :)
@rose95524
@rose95524 Жыл бұрын
Thank you soo much for these compute shader videos!! They are absolutely amazing and by far the best resource I've found for making compute shaders :D
@VictorGordan
@VictorGordan Жыл бұрын
Awww, thank you! Also, cute profile pic :)
@jakestein8516
@jakestein8516 2 жыл бұрын
Perfect timing. I was just starting to play around with compute shaders this week.
@VictorGordan
@VictorGordan 2 жыл бұрын
Hopefully you learnt some new stuff ;)
@krakacats7532
@krakacats7532 Жыл бұрын
i hit the 1k like, haha. Also very great video! I really couldnt find anything useful online for learning compute shader, but this really helped me understand it. Thanks
@mitchellkelly241
@mitchellkelly241 2 жыл бұрын
Every time I come back to the channel the production just keeps getting better and better! I have always wondered how to do animation within OpenGL. Would animation or something along those lines be possible as a tutorial in the future? Thank you for your hard work!
@VictorGordan
@VictorGordan 2 жыл бұрын
Yeah, I'll for sure do an animation series at one point, but right now it's not on my priority list :c
@jeffcummings3842
@jeffcummings3842 Жыл бұрын
Great explanation, thanks! I decided that maybe I was ready for compute shaders, but now I know that's still a bit of a ways away, but within reach, and this helps with understanding when I may actually need them, however experimentation is warranted! Thanks again.
@VictorGordan
@VictorGordan Жыл бұрын
You're welcome! Ray-marching or ray-tracing could be a good start for compute shaders ;) Alternatively, for a non-render use, check out my "planes" video from the procedural generation series. I make use of compute shaders there to vastly improve the generation of planes with high triangle counts!
@jeffcummings3842
@jeffcummings3842 Жыл бұрын
@@VictorGordan nice, i'll have to check that out!
@Trandunz
@Trandunz 2 жыл бұрын
Love your work Victor, i can still hear your voice when im doing my opengl :)
@kylevondra
@kylevondra 2 жыл бұрын
As usual, another banger video. Love to see it, keep up the great work!!
@VictorGordan
@VictorGordan 2 жыл бұрын
Thank you for your continuous support! :)
@jawadch8723
@jawadch8723 2 жыл бұрын
Amazing video! Covered everything I needed!
@VictorGordan
@VictorGordan 2 жыл бұрын
Glad to hear that! If u made smth cool feel free to share it on my Discord server, I like to see what u guys make using my tuts :)
@jawadch8723
@jawadch8723 2 жыл бұрын
@@VictorGordan Sure!
@codeblend5225
@codeblend5225 2 жыл бұрын
You are simply amazing. Even a person like me gets everything (when explained by you).
@codeblend5225
@codeblend5225 2 жыл бұрын
btw, I like using Visual Studio Code more. Is there any way to do OpenGL dev in Visual Studio Code.
@VictorGordan
@VictorGordan 2 жыл бұрын
Yeah, for sure. But I don't know how to link C++ libraries in VS Code, you'll have to look that up. But it is possible!
@chrisburrowssucks
@chrisburrowssucks 2 жыл бұрын
Epic. Thank you Victor.
@VictorGordan
@VictorGordan 2 жыл бұрын
You're welcome :)
@alwinjoshy5888
@alwinjoshy5888 2 жыл бұрын
Thanks for the content.
@VictorGordan
@VictorGordan 2 жыл бұрын
You are welcome! :)
@hamimmahmud5777
@hamimmahmud5777 Жыл бұрын
Keep up the good work
@VictorGordan
@VictorGordan Жыл бұрын
Thx :,)
@hamimmahmud5777
@hamimmahmud5777 Жыл бұрын
Welcome
@TheRoy714
@TheRoy714 2 жыл бұрын
Awesome tutorial
@VictorGordan
@VictorGordan 2 жыл бұрын
Thank you! :)
@codeblend5225
@codeblend5225 2 жыл бұрын
Thanks! I will.
@dimitrisspiridonidis3284
@dimitrisspiridonidis3284 2 жыл бұрын
very good job 👍
@VictorGordan
@VictorGordan 2 жыл бұрын
Thank you! :d
@MrDimakoles
@MrDimakoles 2 жыл бұрын
good visuals i am enjoying it
@VictorGordan
@VictorGordan 2 жыл бұрын
Thanks!
@kalebbruwer
@kalebbruwer 2 жыл бұрын
Thanks. I was missing one line: glUseProgram() and a small eternity later I figured that out thanks to this video
@VictorGordan
@VictorGordan 2 жыл бұрын
U're welcome :)
@clemdemort9613
@clemdemort9613 Жыл бұрын
Very nice of you to put a like counter in the description of your video! :)
@VictorGordan
@VictorGordan Жыл бұрын
Someone has to do it since KZbin gave up on it haha
@alexandru-cristiansandu1016
@alexandru-cristiansandu1016 2 жыл бұрын
Interesting tutorial for some of the more modern capabilities of OpenGL, you definitely become better at making such videos!
@VictorGordan
@VictorGordan 2 жыл бұрын
Mersi! :)
@darkarchon89
@darkarchon89 Жыл бұрын
Great video. This clarified a lot of things that mystified me the past couple of days. Question about 5:08 where you normalize the range from [0,1] to [-1,1]. Is this to match OpenGL clip space, or is there another purpose?
@VictorGordan
@VictorGordan Жыл бұрын
Good to hear :) And yes, it is because of OpenGL's clip space!
@bithigh8301
@bithigh8301 2 жыл бұрын
I've just subscribe!! Awesome video! btw, which video editor do you use? thanks for sharing
@VictorGordan
@VictorGordan 2 жыл бұрын
Thx for the sub! :) I'm using Adobe Premiere for editing and Adobe After Effects for animating
@TristanPopken
@TristanPopken 2 жыл бұрын
Hey, thank you for the great tutorial. I finnaly got to make a working compute shader. One question though, it seems like the more invocations and the less work groups, the better the performace is. For example, i get the best performance with x=32 y=32. Why exactly is that?
@VictorGordan
@VictorGordan 2 жыл бұрын
Good to hear that, I'm glad u found it helpful! Tbh I don't fully understand it myself, but as far as I know it will depend from project to project. So even though 32x32 might seem to give the best performance in this case, it might not in other cases. Basically work groups aren't rly done in parallel at the exact same time, but invocations sort of are, so that's a very rough idea as to why more invocations result in better performance. But it will likely differ as I said. Plus that sometimes you simply want certain sizes for the invocations to deal with non-visual stuff, so more invocations does not mean better performance ;)
@arlynwalker9901
@arlynwalker9901 2 жыл бұрын
s/o to you from china bro, working absolutely well
@VictorGordan
@VictorGordan 2 жыл бұрын
Greetings from the Netherlands! :)
@SirCobraXI
@SirCobraXI Ай бұрын
7:55 Hey, so this caused quite a bit confusion to me. So i did some research and it seems barrier() has implicit shared memory synchronization, so the other call is not needed. However, this seems to not apply for other types of memory, for which you may still need an extra sync call. Also sadly it is not possible to sync a global memory between all thread groups because they are not always executed at the same time.
@gergelybertalan5181
@gergelybertalan5181 2 жыл бұрын
@Victor this is awesome! Where do you learn these things from?
@VictorGordan
@VictorGordan 2 жыл бұрын
Tutorials hidden throughout the internet, stackoverflow, and very imporant, the official documentation ;)
@blaarkies
@blaarkies 2 жыл бұрын
A good example where this is extremely useful is if you have to do n-body gravity simulations, that is, calculate a value between every object and every other object in the game world, and in the end add up all the values for each object (to find the force applied to each object by gravity). Where normal CPUs can handle a few 100 objects before losing framerate, i bet compute shaders can handle thousands of these
@VictorGordan
@VictorGordan 2 жыл бұрын
Yeah, 100%. If written smartly I bet it can go up to tens of thousands or more (just a guess tho)
@floriansteinmann7270
@floriansteinmann7270 2 жыл бұрын
Hey can you please show us how to make a galaxy shader Should worl similar to endportal shader in minecraft if possiblr
@spookyghostking608
@spookyghostking608 2 жыл бұрын
God bless!
@VictorGordan
@VictorGordan 2 жыл бұрын
Amen!
@myth0genesis
@myth0genesis Жыл бұрын
Will there be a step-by-step video about how to make one of these from scratch in, say, VS 2022 and C++ (in keeping with your earlier shader programming series)?
@VictorGordan
@VictorGordan Жыл бұрын
It should be pretty much the same thing, no? Or did VS 2022 change that many things?
@myth0genesis
@myth0genesis Жыл бұрын
@@VictorGordan No, VS 2022 didn't really change much as far as I can tell. I meant will you have a tutorial to make a compute shader from the beginning in general? VS 2022 and C++ were just used as examples for illustrative purposes. I don't really know where any of the code goes (I always use IDEs like shadertoy and SHADERed or Unreal Engine to do shader programming, so I've largely been able to get away with not having to hook it into a C++ program from scratch).
@VictorGordan
@VictorGordan Жыл бұрын
Ah, I already have tutorials for that. My OpenGL tutorials go through that process ;) specifically the first 3/4 tutorials!
@myth0genesis
@myth0genesis Жыл бұрын
@@VictorGordan Okay. Thanks for that. Sorry for the seemingly needless question, then. I'm already working alongside the tutorials as I suspected this might have been the case. Everything up to episode 3 is working out (even with VS 2022 and Glad for OpenGL 4.6 instead of 3.3, with the appropriate changes to the major and minor version numbers in the code, of course). Great job making things clear and easy to understand! I'm hoping to be able to remake some popular statistical tests for 128-bit hash functions so they can run on GPUs (to test some of my own out). It seems like all existing batteries of tests I came across are CPU-bound and would take forever to test a good sample size (in the 128-bit cases), so I'm hoping to leverage the parallelism of the GPU compute pipeline to speed things up a bit (or at least it'd be fun to try).
@VictorGordan
@VictorGordan Жыл бұрын
Don't worry about the question haha Good luck with the GPU porting ;)
@floriansteinmann7270
@floriansteinmann7270 2 жыл бұрын
Could you please do a tutorial on how to make a grass shader which doesnt only repeat the texture but brings in variation with multiple textures I think the key is noise maps
@VictorGordan
@VictorGordan 2 жыл бұрын
Yeah, I'll make a tutorial on that at some point! It will be part of my procedural generation series which will actually get it's second episode in a week or so ;)
@floriansteinmann7270
@floriansteinmann7270 2 жыл бұрын
@@VictorGordan thats cool ty
@KangJangkrik
@KangJangkrik 2 жыл бұрын
Will it support ARM devices like raspberry pi and cheap SoC like Allwinner h6?
@VictorGordan
@VictorGordan 2 жыл бұрын
I don't think so since they don't have a GPU as far as I know, and I doubt the CPU supports OpenGL 4 or higher :(
@KangJangkrik
@KangJangkrik 2 жыл бұрын
@@VictorGordan raspberry pi 4 has two GPUs actually, VC6 and V3D. Currently supports Vulkan but experimental. I don't know about latest supported OpenGL version, too much mixed information.
@sonuaryan5287
@sonuaryan5287 Жыл бұрын
How to provide input as nxn matrix and n size vector and multiply then output
@VictorGordan
@VictorGordan Жыл бұрын
For matrices up to 4x4 you should be able to just use uniforms. For matrices over that size I think you'll have to send the matrix as an array and then make some custom functions that interpret the array as an matrix. But who knows, there might be an easier way out there, not sure :(
@featherless656
@featherless656 2 жыл бұрын
@VictorGordan , I'm stuck on the 5th tutorial, the only way I could get you to see is to comment on your latest video, whenever I run the program the triangle is white, could you help me with this?(The shader files and code is perfect)
@VictorGordan
@VictorGordan 2 жыл бұрын
I've seen your comment before, but I wasn't sure what to answer. The most common problem when this happens, is a typo. Lots of people have told me they followed perfectly, but 90% of the time they do find a typo. Another problem might be that you said you changed some directories. Since the triangle is displayed in the first place, it's likely a problem with the fragment shader. Or it might have to do with the vertex attributes. Not sure what else it could be :(
@featherless656
@featherless656 2 жыл бұрын
@@VictorGordan It might be my driver for my graphics card, not sure.
@VictorGordan
@VictorGordan 2 жыл бұрын
I also thought of that, but then I think the vertex shader would also not work...
@featherless656
@featherless656 2 жыл бұрын
@@VictorGordan another thing I thought of was the #330 core, I thought that maybe because I had gotten glfw 3.3.6 it wasn’t working
@VictorGordan
@VictorGordan 2 жыл бұрын
It shouldn't matter
@nickgennady
@nickgennady 2 жыл бұрын
So how does OpenGL compare to Vulkin? Also OpenGL does not run on Apple products right? Must be annoying to a certain extent.
@VictorGordan
@VictorGordan 2 жыл бұрын
I think anything up to OpenGL 4.1 runs on Mac, but not the newer versions. But if u're going to make games for example, u wouldn't rly care about Mac since almost nobody games on a Mac. As for how it compares to Vulkan? Vulkan is a lot more syntax heavy. U have to write a lot more boilerplate code and take care of a lot more GPU details to render stuff. OpenGL is simpler in that regards, but because you have less control over the miniscule parts of your GPU it can also be less performant in some situations. If you are a beginner, 100% go for OpenGL. It will teach you all the basics and make it much easier to transition to Vulkan. Keep in mind tho that in terms of graphics, both can look "better" than the other. It really depends on the code you write. OpenGL just dosen't have some of the bleeding edge stuff like RTX support and other things. U're unlikely to use those as a noob.
@shinystick241
@shinystick241 2 жыл бұрын
When 3d physics?
@VictorGordan
@VictorGordan 2 жыл бұрын
I don't know tbh. It's not a priority right now, but it will come for sure!
@webgpu
@webgpu 7 ай бұрын
GUYS. IF YOU WANT TO BE UP TO DATE ON COMPUTE SHADERS: INVEST YOUR TIME LEARNING WGSL (WebGPU's Compute Shader). one of the advantages is that the text (ascii file) with the shader code can be run instantly (with an html helper) in anyone's browser without needing any compiler. -- if you were wondering, the "native" code you're writing now (c++ + opengl) can be already ported "in full" to typescript + webgpu (ie, a web app
@Jkauppa
@Jkauppa Жыл бұрын
why webgl 1.0 has to be so stupid formatted
@Jkauppa
@Jkauppa Жыл бұрын
languages are not made to get things done, they are only for a show
@Jkauppa
@Jkauppa Жыл бұрын
pride kills languages and anything good
@arkadiymel5987
@arkadiymel5987 2 жыл бұрын
5:04 it seems that gl_LocalInvocationID should actually be gl_GlobalInvocationID.
@VictorGordan
@VictorGordan 2 жыл бұрын
Yup, I think you're correct... oops :/
Introduction to shaders: Learn the basics!
34:50
Barney Codes
Рет қаралды 261 М.
I made a better Ray-Tracing engine
17:38
NamePointer
Рет қаралды 240 М.
Which one will take more 😉
00:27
Polar
Рет қаралды 79 МЛН
How did CatNap end up in Luca cartoon?🙀
00:16
LOL
Рет қаралды 6 МЛН
Mini Jelly Cake 🎂
00:50
Mr. Clabik
Рет қаралды 16 МЛН
How Bad Apple was played inside Super Mario Bros.
31:35
100th Coin
Рет қаралды 151
Ray Tracing: How NVIDIA Solved the Impossible!
16:11
Two Minute Papers
Рет қаралды 784 М.
Modern OpenGL Tutorial - Tessellation Shaders
7:59
Victor Gordan
Рет қаралды 16 М.
An introduction to Shader Art Coding
22:40
kishimisu
Рет қаралды 888 М.
How Do Games Render So Much Grass?
15:52
Acerola
Рет қаралды 311 М.
Getting Started with Compute Shaders in Unity
14:03
Game Dev Guide
Рет қаралды 189 М.
Introduction to Vulkan Compute Shaders
21:39
İlker
Рет қаралды 8 М.
Compute shader 101
1:22:52
Raph Levien
Рет қаралды 24 М.
How to use Compute Shaders in Godot 4
13:25
Crigz Vs Game Dev
Рет қаралды 16 М.
How Big Budget AAA Games Render Clouds
10:45
SimonDev
Рет қаралды 251 М.
Which one will take more 😉
00:27
Polar
Рет қаралды 79 МЛН