godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91.33k stars 21.24k forks source link

Editor Shader Include Debugger: Incorrect type error when using Canvas Item built-ins #98885

Open HaruYou27 opened 2 weeks ago

HaruYou27 commented 2 weeks ago

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 Screenshot_20241106_133627 However, it is not possible to change the shader_type of shader include file. Screenshot_20241106_133604

The shader does complie with no error and works correctly. But still show as an error in the editor: Screenshot_20241106_190958

Steps to reproduce

Create a shader include file. Try to use some canvas-item built-in.

Minimal reproduction project (MRP)

shaderincludeissue.zip

clayjohn commented 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?

tetrapod00 commented 2 weeks ago

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. Godot_v4 3-stable_win64_fWisSCpdHL However, the shader include file has a compile error when the file is open. Godot_v4 3-stable_win64_B5CGt5LL2a

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.

MGilleronFJ commented 2 weeks ago

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

HaruYou27 commented 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?

Screenshot_20241106_190958 No complie error, the shader works correctly. But the editor thinks otherwise.