0 votes

Greetings!

I made this post because I want to learn the new shader language used in Godot 3.0 and help others to learn or fixing possible issues. Don't misunderstand me, I don't pretend to complain about it, just learn and help improving the engine ;) With hat said, let's start.

I know it's mostly GLSL, which I like and I'm familiar with it, but I'm having a lot of trouble to make the simplest shaders. Is there any documentation available? I've been looking in every place I could, but I found almost no documentation about it, so with a few posts from Juan, my knowledge about GLSL and digging in the source code, I managed to more or less understand the language.

  1. You have to first specify the shader_type (spatial, canvas_item or particles).
  2. Write the uniforms or any other variable.
  3. Define the shaders functions void vertex() and void fragment().

I'm mostly doing spatial shaders, which I assume are for 3D. So my questions are for that type.

I did the simplest shader for make a sphere in red color (the uniform vector equals to (1, 0, 0) ):enter image description here

I have few questions:

  • How can I make the uniform variable to be a color picker? With that code I simply get a window to introduce vector values. In Godot 2.x you introduce uniform color pick_color; and you get a color picker. I've seen Juan doing this: enter image description herebut that doesn't work for me. Is it a feature still in development or can I do it in some way?
  • How can I get the light information ( director vector, specular, diffusse light, etc.) in a spatial shader type? I digged in the source code and the only thing I could find was, for example, a variable called LIGHT_VEC like in Godot 2.x, but is only defined for canvas_shader type!

Finally, I would like to point out some issue. If you try to use COLOR instead of ALBEDO, this is what happens:
enter image description here

I know it's in alpha development, and there are still missing features and lot of work to do, but I just wanted to make sure if it's my poor knowledge about it or not ;).

Thank you very much for your time!

asked Aug 29 in Engine by Antor (15 points)

For your color, try to write uniform color Color;?

Also about the last issue, do you have any error printed in the console? I don't see anything wrong with the code besides it doesn't set the albedo, which should have resulted at least in a black sphere, but it shouldn't also break the vertex pass like your screenshot shows. Maybe the vec4 construction is wrongly parsed (I think GLSL usually supports this as a "swizzle constructor"). You can search issues on Github or write one with your example, there are multiples issues already recorded about shaders.

Finally, just for contribution, here is a shader I wrote for heightmap displacement: https://github.com/Zylann/godot_heightmap_module/blob/master/default_shader.txt

Hello Zylann.

Thank you very much for the fast reply.

  • About the color, I tried it (also withvect4), but the color type doesn't seem to exist, although I've seen it in action in some screenshots from Juan (I downloaded the source code 2 days ago).

  • About the issue, it happens every time you try to declare the diffuse color with COLOR. In the example above I chose one of many forms that I tried: COLOR.rgb = ALBEDO, COLOR.rgb = Color, COLOR = vec4(ALBEDO, ALPHA), etc.
    All of them lead to the same strange white and black thing. The console doesn't give any problem. Maybe it's something wrong in the source code declaration of COLOR

And thank you very much for your shader, I'll look onto it ;)

And about the light vectors, do you know anything about it?

Thank you again for your help :D

2 Answers

0 votes
Best answer

There is a reference for the shader language here.

To edit a color uniform in the editor you need to do uniform vec4 color : hint_color;.

You also might want to look at the screen shaders demo.

Not sure about light shaders. According to this issue some of the light data is not accessible right now.

answered Sep 13 by Smellyhobo101 (54 points)
selected Sep 18 by Antor

Hey!, sorry for being late.
Thank you very much, I haven't tried yer, but I'm sure It'll work. When I can, I'll test it.

Thank you for the shaders demo also! :D

0 votes

Your issue stems from the fact that 'Color' is not an actual shading parameter here, but a value that you can assign to parameters like 'Albedo' (it allows the use of vertex color data).

I too am starting to learn the new shader API and I found this will work for a simple shader where a color is set using the picker (in part thanks to the first answer above).

shader_type spatial;
uniform vec4 color : hint_color;

void fragment(){
    ALBEDO = vec3(color[0],color[1],color[2]);
    }

To note, there's a few things the reference does not make all that clear right now (hopefully, we will soon get more extensive documentation on actual usage).

answered Sep 18 by Ace-Dragon (141 points)

Hello!
Thank you for your help! I'll try it as soon as I can :)

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.