godotengine / godot

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

Functions from shader includes can't have arguments when included with relative path #72108

Closed winston-yallow closed 1 year ago

winston-yallow commented 1 year ago

Godot version

v4.0.beta15.official [4fa6edc88]

System information

Windows 10 (10.0.19045 Build 19045) | Forward+ | Vulkan API 1.3.206 | AMD Radeon RX 6800 XT

Issue description

If there is a function with arguments within a .gdshaderinc file, then this function can not be used in other shaders that include this via a relative include. The error in the other shaders is "Too many arguments for "example()" call. Expected at most 0 but received 1". Using an absolute path for the include resolves the error.

Note: The relative include does work in the special case of both files being in the project root.

Steps to reproduce

  1. Put a shader and a shader-include file into a subdirectory
  2. Write a function with arguments in the shader-include file
  3. Include that file in the shader
  4. Try to use the function

Minimal reproduction project

shader-include-bug.zip

winston-yallow commented 1 year ago

On further investigation, it seems like relative includes aren't supported. At least the debug console output says "Can't open file from path 'res://common.gdshaderinc'" when trying to use a relative path, suggesting that it tries to find the file at the project root.

I'm not sure if it's intended that paths need to be absolute. If yes, then the error in the shader editor tab should be clearer. Instead of saying that the method expected no arguments, it would be good to say that the include didn't work and therefore the function is not available.

Zylann commented 1 year ago

I have the same problem, except I'm not using relative paths... I have shaders like

#include "smooth_terrain/shaders/transvoxel.gdshaderinc"

Producing such errors:

ERROR: Can't open file from path 'res://smooth_terrain/smooth_terrain/shaders/transvoxel.gdshaderinc'.
   at: (core\io\file_access.cpp:699)

Where smooth_terrain IS a folder under res://. This shader worked fine during alphas and betas, until recently it broke with that error where functions can't have arguments.

smooth_terrain appears twice in the path though, Godot tried to make the path relative. Still, the error is wrong, because the including shader did not mention the problem at the #include line, rather complaining about a confusing error on a function call.

akien-mga commented 1 year ago

Please open a new issue with a reproduction project.