Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shader with instance uniforms fails in compatibility #100080

Closed
mooflu opened this issue Dec 6, 2024 · 2 comments · Fixed by #100125
Closed

Shader with instance uniforms fails in compatibility #100080

mooflu opened this issue Dec 6, 2024 · 2 comments · Fixed by #100125

Comments

@mooflu
Copy link
Contributor

mooflu commented Dec 6, 2024

Tested versions

v4.4.dev4.official [36e6207]

System information

Godot v4.4.dev4 - Windows 10.0.22631 - Multi-window, 2 monitors - OpenGL 3 (Compatibility) - NVIDIA GeForce RTX 2070 SUPER (NVIDIA; 32.0.15.6094) - 13th Gen Intel(R) Core(TM) i7-13700KF (24 threads)

Issue description

Attached project uses both a global and 2 instance uniforms.

Actual error is:

E 0:00:01:0046   _display_error_with_code: SceneShaderGLES3: Fragment shader compilation failed:
0(445) : error C1503: undefined variable "instance_offset"

Looks like definition is after use.
From the output log (filtered by instance_offset):

445: 		vec2 m_d=vec2((((global_shader_uniforms[m_iTime].x) * 0.00050000002375) + (global_shader_uniforms[(instance_offset+1u)].x)), 0.0);
672: uniform highp uint instance_offset;

Steps to reproduce

Run attached project.

Minimal reproduction project (MRP)

instance-test.zip

@peterdang1502
Copy link
Contributor

looked into this a little bit and correct me if i'm wrong but i believe the error is coming from one of these function calls

glShaderSource(spec.frag_id, 1, &cstr, nullptr);
glCompileShader(spec.frag_id);
glGetShaderiv(spec.frag_id, GL_COMPILE_STATUS, &status);

which are OpenGL functions. not too sure how to proceed from here

@mooflu
Copy link
Contributor Author

mooflu commented Dec 6, 2024

It's a shader source compile error. Godot generates the shader code from a template. See https://github.com/godotengine/godot/blob/master/drivers/gles3/shaders/scene.glsl

If I move the declaration for instance_offset up, it works.
I can make a PR for the diff below, but I'm not sure if I moved it to a "good" place (right after scene_data) and/or if the other variables in that block should maybe be moved, too.

diff --git a/drivers/gles3/shaders/scene.glsl b/drivers/gles3/shaders/scene.glsl
index 2022c8ee43..778c4f953d 100644
--- a/drivers/gles3/shaders/scene.glsl
+++ b/drivers/gles3/shaders/scene.glsl
@@ -206,6 +206,8 @@ layout(std140) uniform SceneData { // ubo:2
 }
 scene_data;
 
+uniform highp uint instance_offset;
+
 #ifdef USE_ADDITIVE_LIGHTING
 
 #if defined(ADDITIVE_OMNI) || defined(ADDITIVE_SPOT)
@@ -430,7 +432,6 @@ uniform highp mat4 world_transform;
 uniform highp vec3 compressed_aabb_position;
 uniform highp vec3 compressed_aabb_size;
 uniform highp vec4 uv_scale;
-uniform highp uint instance_offset;
 
 uniform highp uint model_flags;
 
@@ -965,6 +966,8 @@ layout(std140) uniform SceneData { // ubo:2
 }
 scene_data;
 
+uniform highp uint instance_offset;
+
 #ifdef USE_MULTIVIEW
 layout(std140) uniform MultiviewData { // ubo:8
        highp mat4 projection_matrix_view[MAX_VIEWS];
@@ -1202,7 +1205,6 @@ ivec2 multiview_uv(ivec2 uv) {
 uniform highp mat4 world_transform;
 uniform mediump float opaque_prepass_threshold;
 uniform highp uint model_flags;
-uniform highp uint instance_offset;
 
 #if defined(RENDER_MATERIAL)
 layout(location = 0) out vec4 albedo_output_buffer;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants