Godot Spatial Shaders - A Gentle Introduction
Вставка
- Опубліковано 26 чер 2024
- We’ll be using Godot’s node-based visual shaders to create a very simple material that causes an object's color to be connected to it’s position in 3D space, and specifically it’s depth on the z-axis.
I wanted to create a very simple shader for my 3D Top Down Shooter series, and found it way more difficult than I was expecting it to be, so I created this very gentle introduction to spatial shaders for anyone else out there who might have hit the same difficulty that I did.
I do my best to explain every step along the way, and I’m hoping this will be useful to anyone who has never touched 3D (spatial) shaders before. I’m new to shaders myself, so I'm probably be oversimplifying a lot of concepts, but we can learn more about those later when we want to to more complicated stuff, right?
Timestamps:
0:00 - Intro
0:45 - New scene
1:34 - Fragment processor
3:37 - Vertex processor
6:45 - From vertex to color
12:30 - Global vertex positions
16:50 - Vector Decompose to use only Z position
18:21 - Uniform (export) variables
20:01 - Mixing colors
21:38 - Top Down Shooter plans
22:08 - Saving the material
*******************************
Make a 3D Top Down Shooter in Godot: • Make a 3D Top Down Sho...
Credits
-----------
Get Godot: godotengine.org/
Editing: nuby nub ( / @nubynub2712 )
Tools
---------
Video Editing: Blender
Overlays: Krita, GIMP, Inkscape, Draw on your Screen (Gnome shell extension)
Recording: SimpleScreenRecorder & Audacity3fgdfg
For those who fallow 3D Top Down Shooter Series and want recreate this in Godot 4.0.
1* 13:26
Now world vector is called "model_matrix"
2* 18:53
Now color uniform is called "ColorParameter"
For those struggling in 4.0 to actually find the visual shader option. It wasn't an initial option. i had to add shader, then in the tooltip to save the file, there is an option of "type" select visual shader from there.
Would never have guessed to use the vertex data to feed into the color input, thank you so much
Amazing tutorial really well explained ty!
14:01 Pro tip: instead of using transform multiplication you can enable ShaderMaterial>Shader>Flags>world_vertex_coords to directly have the vertex input show the global vertex position.
EDIT: if you want to do it by code:
add "world_vertex_coords" to "render_mode":
render_mode world_vertex_coords;
heard it's suppose to save computation or something
Can that be done without code?
@@AgeOfAsparagus yes, using the inspector go and enable MeshInstance>Material/0>ShaderMaterial>Shader>Flags>world_vertex_coords
EDIT: and just use the Vertex_Input as usual
Oh man this was 90% of what I needed. Perfect Thank you so much sub
Thanks! I'm interested in doing more stuff like this. Please let me know if you have any ideas!
@@AgeOfAsparagus right on. my goal is a water column shader so like the deeper you go into the ocean the darker it gets. Haven't quite got a shader from this working yet. but it helped immensely. the alpha is a bit wired so not sure atm how to deal with that.
Holy #$@#! Please make more like this. You explained this so well.
Thank you!
this is the best lesson on visual shaders
Thank you!
Great tutorial.. Very well explained.. Thank you...
You're welcome!
Great explanation. Thx for the help.
You're welcome!
Thanks a lot for the video! At first I had a bit of trouble because some of the nodes in visualshader changed their name and looks but I was able to do everything lol. I'm just starting using it but I want to do some insane blocks before doing some programmation (because I know C# kind of correctly already) hope to see more can't wait to see everything you did already :)
really good explanation.
Thank you!
Neato!
Holy crap this was cool. Thank you and please do more. In my head I was thinking of a 3d printer where you'd use the alpha value to make the cube appear when a node was moved up over it. I'm going to see if I can make this while it's fresh in my head. I'd assume the moving node could be just that LERP with the value changing over time from 0 to 1.
In Godot 4.101 there's s little arrow in the Input so you can break out the red,green, and blue.
very good tutorial, please go further into this topic
Thanks!
Thanks❤
Haven't even seen 4 minutes of this video as of writing this, but enough to instantly subscribe to your channel. :) Thanks for sharing. I'd love to see more about spacial shaders (using the visual shader tool).
Everytime I stumble upon shaders in general (as long as it's about using them in Godot) I notice that most people use the scripted shaders and I'm asking myself why don't they use the visual shaders? They're so much easier…
I once played with visual shaders in Unity and it's a great tool. I wished more people would go that way in Godot as well. I get the impressen they go for the scripted shaders for some reason I don't understand, like is the visual shader buggy or something? … It seems to be one of the reasons I personally didn't start to finally learn more about shaders in Godot. Because there are (almost) only tutorial videos out there where scripted shaders are used, but I just don't want to use'em (for whatever strange reason, I'm a programmer for a living for about 18 years, I know I CAN learn shaderscript but I don't WANT to ;)).
Furthermore, most shader tutorials are related to 2D, but I am interested in 3D. I think that kind of information is rare.
That being said, I'd be happy to see more of videos like this one where someone can learn how to implement visual effects like wobbly vanishing objects and distorted portals and such stuff using visual spatial shaders in Godot.
Thank you! I was curious if there would be interest in this, which is why I pulled it out from the main series I'm doing at the moment. If there's enough interest, I'll do more for sure! If you have any examples of scripted tutorials you think would be interesting to recreate as visual shaders, drop me the links!
Funny that you mention a resistance to scripting shaders, I felt the exact same way! I dont know why, I think I felt dirty going back to a C style syntax, lol.
@@AgeOfAsparagus There's tons of videos I love to watch but never dare to implement myself in shader script (not even thinking of that :D). Have a look here, for example (look out for the "shader" and "effect" keywords on that video listing):
ua-cam.com/users/arleyutivideos
Other than that:
ua-cam.com/users/results?search_query=shader+godot
Just found that one on the above search result page (which is kinda exctly what I meant by vanishing objects effects, I could also imagine a few other effects of how appearing and vanishing could look like, but this is a good one already):
ua-cam.com/video/sf_Dc4ew3eM/v-deo.html
To have that said, you can access the code for all shaders made by that "きのもと結衣" (however that's being pronounced) user here:
bitbucket.org/arlez80/workspace/projects/GE
…or just see the video descriptions of whatever shader video you find in the listing (ua-cam.com/users/arleyutivideos). As far as I can see the shader scripts are all published under the terms of MIT license.
Nevertheless I didn't download any of them… It's still shader script. ;-)
You know, I've been scripting in godot's shader language but the visual language looks very convenient. I should give it a whirl.
Does the visual shader come with an overhead compared to just scripting do you know?
If you click the right most icon in the visual shader panel, you can see that it's just writing the shader code for you.
@@AgeOfAsparagus Not only that but also ANY shader gets compiled on GPU no matter how or where you write it. The only overhead visual shader has is that it is put together not manually and not use some optimal code you could write yourself.
what if you then want the mesh to maintain the color generated after moving? There a way to parent the shader to a node's position?
Great one. I still wish for having a plugin that will copy the blender shaders workflow.
That's an amazing idea and I'm surprised that doesn't exist yet?
@@AgeOfAsparagus Dont know.
Your wish may come true soon
@@alvinmrobles Nice.
my version is godot 3.5.1 stable mono, i know some shaders code but how to connect any shaders script (2d or 3d) to gdscript, some suggestions is "set_shader_param()" or "set_uniform()" use gdscript, but i didn't know this proper code please help, i can not use any shaders
See the suggested video card at the end of this one, that's where I use this material in a project.
PLEASE... DESELECT THE CUBE 😭
Can you make a AI friend for the player
Woah, cool idea!! What should it do? Should it be like a pick-up/power-up? I'm adding this to my list of possible future tutorial ideas! =D
yeah you can make a AI friend that protects you