Generate a Mesh Asset Using Compute Shaders in the Unity Editor! ✔️ 2020.3 | Game Dev Tutorial

preview_player
Показать описание
✔️ Works in 2020.2 ➕ 2020.3

Compute shaders are scripts than run on the GPU and are specialized at solving problems that can be broken into many parts. If this describes a mesh you want to generate, they can do it super fast! In this video, I'll show you how to procedurally generate a mesh in the Unity Editor - using compute shaders - and save it as a mesh asset file.

👋 Subscribe for weekly game development videos!

👑 Join my Patreon for extra influence over topics, early access to videos, and downloadable project files!

🔗 Check out my website for a searchable list of tutorials!

🎬 Previous videos

✨ Follow up videos

💬 Video transcript

📚 Reference scripts

⏲️ Timestamps:
0:00 Intro
1:09 Project setup
1:41 The ScriptableObject
3:00 The inspector button
4:05 The compute shader
8:10 The dispatcher
12:35 The finished inspector
14:34 Testing
15:09 Wrap up and credits

🎖️ Credits and references:

#GameDev #IndieDev #Unity
Рекомендации по теме
Комментарии
Автор

Thank you for this tutorial. It's clear from watching other tutorials on the subject when someone has only a high level understanding vs a low level understanding. Too many of the tutorials out there when you search for compute shaders just gloss over stuff without explaining why they use them. Cheers!

CannabisTechLife
Автор

I'm literally nerding out over how high quality this was. I'm pretty picky when it comes to tutorials since I'm a snob when it comes to clean code and I usually stop watching after a little bit if people accidentally or intentionally leave it out to shorten video times. Having said that, you did excellent and I learned a lot.

You definitely earned a like and a subscribe, thank you!

peterwilliams
Автор

Love it! Looking forward to grass and other stuff that you can do with it!
BTW, I'm really impressed by how many high-quality videos you are able to produce.

ThomasChen-urgt
Автор

This is super helpful. I am looking into passing an octree structure to the compute shader and have it generate a voxelized mesh. Your videos are exactly what I have been looking for.

Timtowtdi-oop
Автор

I'm a new subscriber, enjoying the quality, depth, and complexity of the content you deliver. It can be hard to find good resources on this, specifically in relation to Unity.

ChipboardDev
Автор

The best compute shader tutorial I have ever seen👍Thank you!

brianxu
Автор

Enjoyed this quite a bit. Liked, subscribed and leaving a comment for the algorithm!

mrjamerific
Автор

This video is great :) Got here from Jendrik Illner's computer graphics newsletter, will check out some of your other videos as well

tombuben
Автор

I think this runs slowly because you generate more vertices than needed. You generate 9 vertices, 3 for each triangle, when you only need 4: a, b, c and center.

florinf
Автор

This is great. by using this method you shown, I can do mesh generation and tesselation in GPU. Also i can write the generated data as mesh asset. Thanks!

sammtanX
Автор

As always, a nice tutorial.
You should look for making a volumetric light tutorial or things like that, as far as I keep searching on youtube, there's no tutorial about how to code them just how to use URP or Aura. It may help you get more subs (or you can use the community tabs to improve your visibility, youtube's algorithm is broken anyway).
I hope to see more content anyway, keep up the good work!

IkikaeruRaimei
Автор

You should do a more in depth video or videos on custom editors. I would love to see that.

Other ideas:
ui
procedural generation (ex: tile based like townscaper - game by Oskar stalberg)
Coding patterns
Wave function collapse
Multithreading
Sdfs
Water (shaders, waterfalls, ripple effect around objects in water, etc)

I am just suggesting these ideas because your videos are really in depth and helpful (unlike other channels that just scratch the surface)

anonymoussloth
Автор

what about procedurally generated meshes like minecraft chunks?

manofapocalypse
Автор

I have an error at 13:13 with the PyramidBaker. The inspector can't acces the baker for some reason.

wzukay
Автор

I followed this tutorial exactly, and receive the following console error:

IndexOutOfRangeException: Invalid kernelIndex (0) passed, must be non-negative less than 1.

PyramidBaker.Run (UnityEngine.ComputeShader shader, PyramidBakeSettings settings, UnityEngine.Mesh& generatedMesh) (at

I've tried to debug myself, but can't seem to find a solution due to my very limited shader/HLSL knowledge.

Any ideas that might be causing this?
Thanks!

steffelix
Автор

Hey! thanks for the great video! quick question though! When I go to create a pyramid, the loading bar will come up but nothing happens, not sure what my issue is but any tips or pointers are greatly appreciated!

dechin
Автор

Very informative tutorial, well done. I'm hitting an issue however on mac, I'm running a fairly new mac from 2019, it's Intel based not Apple Silicon, either way they both use Metal rendering api and I'm getting this error "Metal: Vertex or Fragment Shader "MyCompute" requires a ComputeBuffer at index 1 to be bound, but none provided. Skipping draw calls to avoid crashing." any ideas, googling this hasn't turned up many suggestions.

jrdatak
Автор

If we create meshes using compute shaders, how do we give them mesh colliders and other things like materials?

anonymoussloth
Автор

Thanks a lot for this amazing tutorial!
Right now, I'm trying to procedually generate terrains and therefore wanted to learn how to use compute shader in Unity...
it is hard to get into this stuff cause there are quite a few steps to go until it works ._.
You explained everything very well and in a nice pace, keep up the good work! <3

Would be very interested in a video on how to use compute shaders in the unity editor for procedual mesh generation!
Especially on how to parametrize some noise funtions in the compute shaders and make them configurable from the inspector...
any thoughts on how to do this? o.o

kapadork
Автор

I suppose you could make this a create convex hull from a list of vertices.... interesting. Have you done this?

AtmosMr