[Source Code] Where are shader builtins exposed?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Void

I’m making a game with an NPR art style, but not enough information is exposed to the shaders to do what I want to do. I’m looking to extend the builtins to include things like shadow color for my game, but I can’t find where in the source code this is defined.

EDIT: I’ve tried a few more things since posting this; I’ve found that builtins are defined in servers/visual/shader_types.cpp, and there’s something called a remap defined in drivers/gles2/shader_compiler_gles2.cpp, but I can’t find where the value for a builtin comes from, and I can’t find anything that explains what the remaps are.

Hi,
are you looking for this?

Spatial shaders — Godot Engine (stable) documentation in English

or do you want to extend godot and do a custom build?

Well then you want to have a look here, wich shows most of the places where those things happen:
https://github.com/godotengine/godot/search?q=DEPTH_TEXTURE

klaas | 2021-07-11 11:51

I want to extend Godot with a custom build. Unfortunately, github search only seems to be able to search the master 4.0 branch, which changed up a lot of the renderer code, so that link doesn’t help at all.

Void | 2021-07-12 03:50

well then … the rendering happens here in the driver …
https://github.com/godotengine/godot/tree/3.3/drivers/gles3

klaas | 2021-07-12 08:02

Edited my main post to explain more of where I am right now.

Void | 2021-07-12 16:37

The shader compiler is used to convert the godot-shading language into real GLSL Shaders. Where the remapping is to realize if (eg) a DEPTH_TEXTURE is needed, then in the actual shader the DEPTH_TEXTURE keyword is replaced with depth_buffer and that is connected to a actual depth path buffer.

its a non trival thing to extend the rasterizer.

I dont know what “NPR art style” is, maybe you want to descripe this in more detailed way or link/post a screenshot of what you want and what informations your shaders needs to archive this.

klaas | 2021-07-12 16:49

Right now I’m trying to do something similar to Wind Waker’s art style; like I said in the original post, the only thing I need right now is to expose shadow color to the 3D renderer.

Void | 2021-07-12 21:56

my guess is …

in “shader_compiler_gles3.cpp”
after

actions[VS::SHADER_SPATIAL].renames["LIGHT_COLOR"] = "light_color";

add this line

actions[VS::SHADER_SPATIAL].renames["SHADOW_COLOR"] = "shadow_color_contact";

this may result in that the “SHADOW_COLOR” exposes the “shadow_color_contact” what is used in the scene shader
(https://github.com/godotengine/godot/blob/3.3/drivers/gles3/shaders/scene.glsl)

klaas | 2021-07-13 11:39

Thanks so much! Finally found it and now it works. Can you post this as a full answer so I can mark it as the correct one?

Void | 2021-07-13 18:35

:bust_in_silhouette: Reply From: klaas

The comments combined:

the rendering happens here in the driver …

The shader compiler is used to convert the godot-shading language into real GLSL Shaders. Where the remapping is to realize if (eg) a DEPTHTEXTURE is needed, then in the actual shader the DEPTHTEXTURE keyword is replaced with depth_buffer and that is connected to a actual depth path buffer.

To expose the shadow_color in the shader … try this

in “shadercompilergles3.cpp”
after

actions[VS::SHADER_SPATIAL].renames["LIGHT_COLOR"] = "light_color";

add this line

actions[VS::SHADER_SPATIAL].renames["SHADOW_COLOR"] = "shadow_color_contact";

this may result in that the “SHADOWCOLOR” exposes the “shadowcolor_contact” what is used in the scene shader
(https://github.com/godotengine/godot/blob/3.3/drivers/gles3/shaders/scene.glsl)