Тёмный

Modern OpenGL Tutorial - Compute Shaders 

Victor Gordan
Подписаться 12 тыс.
Просмотров 56 тыс.
50% 1

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

Опубликовано:

 

23 июл 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 92   
@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 2 года назад
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 2 года назад
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 ;)
@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! :)
@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 :)
@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!
@chris_burrows
@chris_burrows 2 года назад
Epic. Thank you Victor.
@VictorGordan
@VictorGordan 2 года назад
You're welcome :)
@alwinjoshy5888
@alwinjoshy5888 2 года назад
Thanks for the content.
@VictorGordan
@VictorGordan 2 года назад
You are 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
@hamimmahmud5777
@hamimmahmud5777 Год назад
Keep up the good work
@VictorGordan
@VictorGordan Год назад
Thx :,)
@hamimmahmud5777
@hamimmahmud5777 Год назад
Welcome
@MrDimakoles
@MrDimakoles 2 года назад
good visuals i am enjoying it
@VictorGordan
@VictorGordan 2 года назад
Thanks!
@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 RU-vid 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! :)
@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
@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 :)
@darkarchon89
@darkarchon89 2 года назад
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 2 года назад
Good to hear :) And yes, it is because of OpenGL's clip space!
@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
@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 ;)
@SirCobraXI
@SirCobraXI 4 месяца назад
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.
@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)
@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 ;)
@arlynwalker9901
@arlynwalker9901 2 года назад
s/o to you from china bro, working absolutely well
@VictorGordan
@VictorGordan 2 года назад
Greetings from the Netherlands! :)
@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 :(
@spookyghostking608
@spookyghostking608 2 года назад
God bless!
@VictorGordan
@VictorGordan 2 года назад
Amen!
@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
@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
@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 ;)
@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.
@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 10 месяцев назад
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
@mccrackhead1832
@mccrackhead1832 28 дней назад
I don't like you
@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
Просмотров 304 тыс.
Я читаю переписки сына
00:18
Просмотров 518 тыс.
Телеграмм-Колян Карелия #юмор
00:10
I made a better Ray-Tracing engine
17:38
Просмотров 248 тыс.
Modern OpenGL Tutorial - Tessellation Shaders
7:59
Просмотров 18 тыс.
Compute shader 101
1:22:52
Просмотров 25 тыс.
Compilers, How They Work, And Writing Them From Scratch
23:53
What Are Shaders?
6:24
Просмотров 199 тыс.
7 Examples Proving Shaders are Amazing
8:09
Просмотров 34 тыс.
Ray Tracing: How NVIDIA Solved the Impossible!
16:11
Просмотров 790 тыс.
How To Write Fast Shaders
10:33
Просмотров 18 тыс.
An introduction to Shader Art Coding
22:40
Просмотров 944 тыс.