How to use Compute Shaders in Godot 4

  Рет қаралды 16,839

Crigz Vs Game Dev

Crigz Vs Game Dev

Күн бұрын

Here's a quick guide on how to set up Compute Shaders in Godot 4, using a practical example by converting the score calculation from my previous video, on Splatoon's ink gun, to be run as a compute shader.
Scripts:
Shader GLSL: pastebin.com/pbGGjrE8
Test Script: pastebin.com/92cvEagc
Final Score Calculator: pastebin.com/wXCqk1nQ
Resources:
github.com/godotengine/godot-...
docs.godotengine.org/en/lates...
Check out these Sebastian lague videos to see what compute shaders can do:
• Coding Adventure: Comp...
• I Spent a Week Making ...
Chapters:
0:00 Intro
0:18 Compute Shader Intro
0:37 Minimum Compute Shader
4:40 Score Calculation GLSL
6:44 Boilerplate
7:54 Texture Uniforms
11:23 Performance Comparison
12:13 Final Script
13:00 Outro

Пікірлер: 53
@Galomortalbr
@Galomortalbr Жыл бұрын
amazing video, i wish there was more content like this, Godot 4 is truly a step up from Godot 3
@wellhellotherekyle
@wellhellotherekyle Жыл бұрын
Wow, you’ve quickly become one of my favorite Godot resources!
@ZagrajmyzPszemkiem
@ZagrajmyzPszemkiem Жыл бұрын
A wonderfull tutorial! There is so little information about any of this online, it's great to see somebody taking their time to investigate what's possible.
@1cedragon
@1cedragon 5 ай бұрын
Excellent tutorial! Thank you for taking the time to explain compute shaders. I wish Godot had more documentation about them because they're such a powerful tool for advanced effects.
@leerpret3950
@leerpret3950 Жыл бұрын
This is great, thanks! Info on compute shaders are so rare, hopefully it becomes more mainstream.
@crigz
@crigz Жыл бұрын
I hope so too! You can do some incredible things with them, it's a tool everyone should have in their belt.
@planetbridging4249
@planetbridging4249 2 ай бұрын
I dont normaly give comments to youtube videos but this one actually got me to my solution i needed and to avoid using unity. Thank you so much for helping so i can make my idea using the godot 4 with compute shaders utlizing the cpu and the gpu for my ai architecture design :D
@Gredran
@Gredran Жыл бұрын
Godot 4 tutorials are comin in!! Great video! Its a cool thing to show off that the engine can do! You definitely earned a subscriber 😊
@binary_soup
@binary_soup Жыл бұрын
Turns out RGBA8 is required to use a texture in a sampler. If it doesn't have an alpha channel then the rendering device will throw an error. To fix this, you can use `image.convert(Image.FORMAT_RGBA8)` to convert its format first.
@mezzofortestudios7342
@mezzofortestudios7342 Жыл бұрын
this was helpful, thank you
@chriszymurgist
@chriszymurgist Ай бұрын
I have been banging my head on this issue until I came across your comment. As an addendum the PNG also can not have mipmaps.
@AslanSilva
@AslanSilva Жыл бұрын
Another vid so quick! Amazing stuff.
@RyanForresterDev
@RyanForresterDev Жыл бұрын
Great video, lots of stuff learned watching this! I'm hoping to have the time at some point to try a water shader using compute shaders and use the outputs for water physics.
@ViktorFerenczi
@ViktorFerenczi Жыл бұрын
Your video has been super useful and came at the exact right time for my project. Thanks! Subscribed.
@addmix
@addmix Жыл бұрын
Thank you. You actually cared to explain what each segment of code did. I was getting very frustrated trying to understand compute shaders, but this video helped me understand it better.
@Barnaclebeard
@Barnaclebeard Жыл бұрын
Beastly content, and appreciated
@RyanScottForReal
@RyanScottForReal Жыл бұрын
This is great, thank you. Would love to see what IS a more efficient way to do it. :)
@eigenman2571
@eigenman2571 Жыл бұрын
Super helpful! Thanks
@arez4906
@arez4906 Жыл бұрын
Very dope video! You definitely deserve more attention. It would be cool to see trails (particle trails or if there are other types of trails) explained, as i just cant get them working right!
@crigz
@crigz Жыл бұрын
Cool idea! What in particular did you struggle to get right with them?
@arez4906
@arez4906 Жыл бұрын
@@crigz Somehow whenever i tried particle trails i couldnt get them to render properly. They always were a random mess of stretched triangles or whatever. Also sometimes they became super large or the actual particles didnt even render (just the trails, but those buggy)
@crigz
@crigz Жыл бұрын
@@arez4906 is that in Godot 4.0? I had to scrap the splash particles I set up because they're currently so buggy in the beta.
@arez4906
@arez4906 Жыл бұрын
@@crigz Yep it is!
@marc.lepage
@marc.lepage Жыл бұрын
Thinking of doing some non-game stuff in Godot 4 and this will come in very handy!
@marc.lepage
@marc.lepage 3 ай бұрын
Just to say I have indeed been doing non-game stuff, now on Godot 4.2, and working on sharing my non-visual data (processed by compute shader) with a graphics shader without going through the CPU, so I can visualize the data but maintain framerate.
@indieology7336
@indieology7336 Жыл бұрын
Thank you!
@Greebli
@Greebli Жыл бұрын
This is great information thanks, but what about using the buffer in a shader to visualize the data? for example a for a fluid sim
@giantfrogstudios839
@giantfrogstudios839 Жыл бұрын
Nice video
@AgnisNeZvers
@AgnisNeZvers Жыл бұрын
Killer video! I'm having doubts that Splatoons is used compute shaders for Wii U (Splatoon 1 in 2015) & Switch. My guess is that it's just a collision system + some approximate area calculation based on collision position.
@farianderson168
@farianderson168 8 ай бұрын
Do we have to use external editor for writing compute shaders?
@nemene8585
@nemene8585 Жыл бұрын
How do you make the fancy operators, like merging >= and ==?
@question_mark
@question_mark Жыл бұрын
lezgooooooooooooooooooooooooooo thank u so much
@johanngambolputty5351
@johanngambolputty5351 Жыл бұрын
Ooh, do the compute shaders support doubles? I tried to do some fractal stuff in Godot before because of the ease of setting up ui and input, but you very quickly hit precision limits... Also, can it only do compute shaders through GL? How about OpenCL (would be nice since I've already written some OCL stuff now...)
@mezzofortestudios7342
@mezzofortestudios7342 Жыл бұрын
Currently the `RenderDevice` class uses only a Vulkan backend for compute
@thehattedhedgehog
@thehattedhedgehog 8 ай бұрын
I can't figure out how to clean after submitting. The memory is bulking (Godot 4.1.1.stable)
@AbeTheApe126
@AbeTheApe126 Жыл бұрын
Out of interest, in the performance comparison. Is the CPU version completely single threaded? E.g. no usage of threads on the system etc? Likely you would still not get close to the gpu perf but it would make for a slightly more 'fair' comparison potentially.
@prozacgodgamedev
@prozacgodgamedev Жыл бұрын
I was watching your previous splatoon tutorial and was thinking of a way to get rid of the seams. Regardless of the way the texture is unwrapped. This would only work on a compute shader because of the search space, but it should be massively parallel. I'm not 100% sure how to do this. In blender is there a way to generate a texture that matches the XYZ coordinates of a 3D surface using the same unwrap as the painting texture. This would give you a texture where paint can be splashed, and a lookup table for all splashable surfaces in 3D. In this way, we have a texture that matches the unwrapped texture, but we have XYZ coordinates for the entire level. Then when a splash happens you feed in this texture, the coordinate of the splash and the output is a texture of said splash. The way it works is ... if a 3D texture lookup triplet is inside the 3d radius of this splash sphere, it would fill in the output texture with the splash color. This should work quite flawlessly.
@crigz
@crigz Жыл бұрын
I'll have to look into this for sure!
@prozacgodgamedev
@prozacgodgamedev Жыл бұрын
@@crigz Thanks, I hope my explanation was ... adequate!
@prozacgodgamedev
@prozacgodgamedev Жыл бұрын
@@crigz I was looking into this myself and quickly realized you can easily paint through walls and backfaces, so there's a technical thing there to sort out. Seems similar issues would happen in your version too.
@crigz
@crigz Жыл бұрын
@@prozacgodgamedev Painting through walls and back-faces aren't an issue in this system, it's mostly painting over into other UV's if you don't leave enough margin, and there's not a proper wrap around on corners unless you perfectly place the UV map (not always possible). I've got a few ideas I'm experimenting with to fix this though.
@prozacgodgamedev
@prozacgodgamedev Жыл бұрын
@@crigz I'm setting up to attempt to build something akin to your splatoon level and a godot fps scene to attempt a real go at it. I'm not ... that well versed in ... well anything here, I'm winging it :D It'll be fun!
@leeuwarden20
@leeuwarden20 Жыл бұрын
Did you manage to draw a triangle with RenderingDevice?
@MACMAN2003
@MACMAN2003 Жыл бұрын
would it be possible to take in an image and change the colors around a bit? like if i wanted to change color1 to color2?
@crigz
@crigz Жыл бұрын
Yes, you can do something like that.
@MACMAN2003
@MACMAN2003 Жыл бұрын
@@crigz Do you have any idea on how to get started on doing that? Cause there's no documentation for compute shader stuff xd
@Galomortalbr
@Galomortalbr Жыл бұрын
hey, as much as i love the computer shader solution, i can't help but to feel it's over engineered, a simpler solution would had to been to use a viewport to downscale the 2048x2048 texture to 32x32 and then calculate based on that, could be done even in the main cpu thread without much of performance impact. it's obviously not fun solution but solves the issue without having to taxs the GPU or a entire thread, i still would like more content about computer shaders.
@savhasuvhe
@savhasuvhe Жыл бұрын
Can you do next anime shader?
@Chevifier
@Chevifier 6 ай бұрын
*Cuts off head to rub brain*😅
@brettfleeman6014
@brettfleeman6014 Жыл бұрын
First
Godot 4 Makes Multiplayer EASY!
5:42
Crigz Vs Game Dev
Рет қаралды 84 М.
Making a Raycaster using Godot 4 Compute Shaders!
29:20
Binary Soup
Рет қаралды 15 М.
🍟Best French Fries Homemade #cooking #shorts
00:42
BANKII
Рет қаралды 38 МЛН
La final estuvo difícil
00:34
Juan De Dios Pantoja
Рет қаралды 29 МЛН
1 класс vs 11 класс (неаккуратность)
01:00
Modern OpenGL Tutorial - Compute Shaders
11:27
Victor Gordan
Рет қаралды 53 М.
Learn GODOT 4 Compute Shaders with RAYTRACING!!
12:40
NekotoArts
Рет қаралды 26 М.
PROCEDURAL Terrain Generation (with Unloading) in Godot!
18:33
Overworld procedural generation in Godot, with compute shaders
1:33
Introduction to shaders: Learn the basics!
34:50
Barney Codes
Рет қаралды 275 М.
Intro to Godot 4's RenderingDevice (Compute Shaders)
5:10
DitzyNinja's Godojo
Рет қаралды 4,9 М.
GPU Compute Shader Work Groups
6:36
Arsiliath
Рет қаралды 5 М.
How To Render 2 Million Objects At 120 FPS
14:57
Tarodev
Рет қаралды 135 М.
The Power of Video Game HUDs
16:30
Game Maker's Toolkit
Рет қаралды 858 М.
САМЫЙ ГЛУПЫЙ БРАВЛЕР В БРАВЛ СТАРС
0:52
Baobab 4 Live
Рет қаралды 1,6 МЛН
Как он смог забить гол
0:59
Garga
Рет қаралды 1,8 МЛН
Kaiju Buzz absence 😔 | Brawl Stars #brawlstars #shorts
0:20
Ghostify Labs
Рет қаралды 7 МЛН