Open HaruYou27 opened 2 weeks ago
If I recall correctly, the allowed syntax within a shader include file comes from the type of file in which it is included. Have you tried including the shaderinclude file from a canvas item shader?
Yeah, it seems like the actual shader will compile fine, but the shader include will show a compile error if it is open.
test_inc.gdshaderinc
varying vec2 v;
void vertex()
{
v = VERTEX; // VERTEX should be a vec2 in a CanvasItem shader.
}
canvas_test.gdshader
:
shader_type canvas_item;
#include "res://test_inc.gdshaderinc"
// Includes this:
//varying vec2 v;
//void vertex()
//{
//v = VERTEX; // VERTEX should be a vec2 in a CanvasItem shader.
//}
void fragment() {
COLOR = vec4(v, 0.0, 1.0);
}
The sprite shows up fine, and the canvas item shader compiles fine with no errors. However, the shader include file has a compile error when the file is open.
There is probably some documentation improvement that could be made in the #include section.
There are probably also some improvements that could be made to the either the preprocessor or the way shader include files are compiled and displayed in the shader editor.
But it seems like the basic functionality here is fine, it just has some compile errors (in the editor) that can be safely ignored.
This is one of similar issues I had when using shader includes in a project where I had to implement shader variants, kept getting pointless errors which made development annoying, which led me to pass everything via functions https://github.com/Zylann/godot_atmosphere_shader/blob/330cfe9da1f579dab0677027def9ac3e2563a847/addons/zylann.atmosphere/shaders/include/planet_atmosphere_main.gdshaderinc#L5
If I recall correctly, the allowed syntax within a shader include file comes from the type of file in which it is included. Have you tried including the shaderinclude file from a canvas item shader?
No complie error, the shader works correctly. But the editor thinks otherwise.
Tested versions
v4.3.stable.arch_linux v.4.0.stable
System information
Godot v4.3.stable unknown - Arch Linux ZEN SMP PREEMPT_DYNAMIC Fri, 01 Nov 2024 03:30:35 +0000 - Wayland - GLES3 (Compatibility) - Mesa Intel(R) HD Graphics 3000 (SNB GT2) - Intel(R) Core(TM) i7-2670QM CPU @ 2.20GHz (8 Threads)
Issue description
By default, shader include type is spatial, which change the type of built-ins However, it is not possible to change the shader_type of shader include file.
The shader does complie with no error and works correctly. But still show as an error in the editor:
Steps to reproduce
Create a shader include file. Try to use some canvas-item built-in.
Minimal reproduction project (MRP)
shaderincludeissue.zip