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

КОМЕНТАРІ • 46

  • @DigitalImpostor1
    @DigitalImpostor1 Рік тому +16

    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"

  • @warrenpaul9858
    @warrenpaul9858 11 місяців тому +3

    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.

  • @lukostello
    @lukostello 2 роки тому +2

    Would never have guessed to use the vertex data to feed into the color input, thank you so much

  • @mch43856
    @mch43856 Рік тому +1

    Amazing tutorial really well explained ty!

  • @phoboss950
    @phoboss950 2 роки тому +7

    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

    • @AgeOfAsparagus
      @AgeOfAsparagus  2 роки тому

      Can that be done without code?

    • @phoboss950
      @phoboss950 2 роки тому +2

      @@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

  • @AdredenGaming
    @AdredenGaming 3 роки тому +3

    Oh man this was 90% of what I needed. Perfect Thank you so much sub

    • @AgeOfAsparagus
      @AgeOfAsparagus  3 роки тому +2

      Thanks! I'm interested in doing more stuff like this. Please let me know if you have any ideas!

    • @AdredenGaming
      @AdredenGaming 3 роки тому

      @@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.

  • @chrisfritz7545
    @chrisfritz7545 Рік тому +2

    Holy #$@#! Please make more like this. You explained this so well.

  • @SULTANVIDEOGAMES
    @SULTANVIDEOGAMES Рік тому +1

    this is the best lesson on visual shaders

  • @EeVeE3D
    @EeVeE3D 2 роки тому +1

    Great tutorial.. Very well explained.. Thank you...

  • @alvinmrobles
    @alvinmrobles 3 роки тому +1

    Great explanation. Thx for the help.

  • @tomgrimard8075
    @tomgrimard8075 8 місяців тому

    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 :)

  • @jeffg4686
    @jeffg4686 3 роки тому +1

    really good explanation.

  • @NOPerative
    @NOPerative 3 роки тому +1

    Neato!

  • @GaryParkin
    @GaryParkin 8 місяців тому

    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.

  • @gustavols6699
    @gustavols6699 3 роки тому +1

    very good tutorial, please go further into this topic

  • @OLIV3R_YT
    @OLIV3R_YT Рік тому

    Thanks❤

  • @dueddel
    @dueddel 3 роки тому +2

    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.

    • @AgeOfAsparagus
      @AgeOfAsparagus  3 роки тому +1

      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!

    • @AgeOfAsparagus
      @AgeOfAsparagus  3 роки тому +1

      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.

    • @dueddel
      @dueddel 3 роки тому +1

      @@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

    • @dueddel
      @dueddel 3 роки тому

      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. ;-)

  • @davidmurphy563
    @davidmurphy563 3 роки тому +2

    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?

    • @AgeOfAsparagus
      @AgeOfAsparagus  3 роки тому +1

      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.

    • @NeZversSounds
      @NeZversSounds 3 роки тому +2

      @@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.

  • @MikelMonleon
    @MikelMonleon 6 місяців тому

    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?

  • @b3daz
    @b3daz 3 роки тому +1

    Great one. I still wish for having a plugin that will copy the blender shaders workflow.

    • @AgeOfAsparagus
      @AgeOfAsparagus  3 роки тому

      That's an amazing idea and I'm surprised that doesn't exist yet?

    • @b3daz
      @b3daz 3 роки тому

      @@AgeOfAsparagus Dont know.

    • @alvinmrobles
      @alvinmrobles 3 роки тому

      Your wish may come true soon

    • @b3daz
      @b3daz 3 роки тому

      @@alvinmrobles Nice.

  • @QqQq-bf8bd
    @QqQq-bf8bd Рік тому +1

    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

    • @AgeOfAsparagus
      @AgeOfAsparagus  Рік тому

      See the suggested video card at the end of this one, that's where I use this material in a project.

  • @Speed-TV
    @Speed-TV Рік тому

    PLEASE... DESELECT THE CUBE 😭

  • @martirexanimation2217
    @martirexanimation2217 3 роки тому +1

    Can you make a AI friend for the player

    • @AgeOfAsparagus
      @AgeOfAsparagus  3 роки тому

      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

    • @martirexanimation2217
      @martirexanimation2217 3 роки тому

      yeah you can make a AI friend that protects you