Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Antor | |
Old Version | Published before Godot 3 was released. |
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.
- You have to first specify the
shader_type
(spatial, canvas_item or particles). - Write the uniforms or any other variable.
- Define the shaders functions
void vertex()
andvoid 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) ):
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: but 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:
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!
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
Zylann | 2017-08-29 12:57
Hello Zylann.
Thank you very much for the fast reply.
-
About the color, I tried it (also with
vect4
), but thecolor
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 ofCOLOR
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
Antor | 2017-08-29 13:56