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

Adding a uniform starting by '_' in a shader breaks rendering #12880

Closed
Zylann opened this issue Nov 13, 2017 · 8 comments
Closed

Adding a uniform starting by '_' in a shader breaks rendering #12880

Zylann opened this issue Nov 13, 2017 · 8 comments
Assignees
Milestone

Comments

@Zylann
Copy link
Contributor

Zylann commented Nov 13, 2017

Godot 3.0 alpha2
Windows 10 64 bits
nVidia 940M

Repro:

  1. Create a scene with a sprite in it and a texture on it (the default icon will do)
  2. Create a ShaderMaterial, save it to a file
  3. Cretae a Shader, save it to a file
  4. Write this code into the shader:
shader_type canvas_item;

uniform sampler2D _indices;

void fragment() {
	COLOR = vec4(1,0,0,1);
}
  1. Assign the material on the Sprite
  2. Notice rendering is broken:
    image

The log is spammed by this:

ERROR: _display_error_with_code: CanvasShaderGLES3: Vertex Program Compilation Failed:
0(107) : error C7528: OpenGL reserves names containing '__'

   At: drivers\gles3\shader_gles3.cpp:167
ERROR: ShaderGLES3::get_current_version: Method/Function Failed, returning: 0
   At: drivers\gles3\shader_gles3.cpp:368
ERROR: ShaderGLES3::bind: Condition ' !version ' is true. returned: false
   At: drivers\gles3\shader_gles3.cpp:122
ERROR: ShaderGLES3::_get_uniform: Condition ' !version ' is true. returned: -1
   At: .\drivers/gles3/shader_gles3.h:376
ERROR: ShaderGLES3::_get_uniform: Condition ' !version ' is true. returned: -1
   At: .\drivers/gles3/shader_gles3.h:376
ERROR: ShaderGLES3::_get_uniform: Condition ' !version ' is true. returned: -1
   At: .\drivers/gles3/shader_gles3.h:376
ERROR: ShaderGLES3::_get_uniform: Condition ' !version ' is true. returned: -1
   At: .\drivers/gles3/shader_gles3.h:376
ERROR: ShaderGLES3::_get_uniform: Condition ' !version ' is true. returned: -1
   At: .\drivers/gles3/shader_gles3.h:376
ERROR: ShaderGLES3::_get_uniform: Condition ' !version ' is true. returned: -1
   At: .\drivers/gles3/shader_gles3.h:376
ERROR: ShaderGLES3::_get_uniform: Condition ' !version ' is true. returned: -1
   At: .\drivers/gles3/shader_gles3.h:376
ERROR: ShaderGLES3::_get_uniform: Condition ' !version ' is true. returned: -1
   At: .\drivers/gles3/shader_gles3.h:376
ERROR: ShaderGLES3::_get_uniform: Condition ' !version ' is true. returned: -1
   At: .\drivers/gles3/shader_gles3.h:376
ERROR: _gl_debug_print: GL ERROR: Source: OpenGL        Type: Error     ID: 1282        Severity: High  Message: GL_INVALID_OPERATION error generated. No active program.
   At: drivers\gles3\rasterizer_gles3.cpp:122
ERROR: _gl_debug_print: GL ERROR: Source: OpenGL        Type: Error     ID: 1282        Severity: High  Message: GL_INVALID_OPERATION error generated. No active program.
   At: drivers\gles3\rasterizer_gles3.cpp:122
ERROR: _gl_debug_print: GL ERROR: Source: OpenGL        Type: Error     ID: 1282        Severity: High  Message: GL_INVALID_OPERATION error generated. No active program.
   At: drivers\gles3\rasterizer_gles3.cpp:122
ERROR: _gl_debug_print: GL ERROR: Source: OpenGL        Type: Error     ID: 1282        Severity: High  Message: GL_INVALID_OPERATION error generated. No active program.
   At: drivers\gles3\rasterizer_gles3.cpp:122

It took me some lucky scrolling to find out that the issue was only caused by the '_' at the beginning of my uniform.

@eon-s
Copy link
Contributor

eon-s commented Nov 13, 2017

If _ is so problematic (even in 2.x) the shader variables should be renamed in other way, like v_.

@BastiaanOlij
Copy link
Contributor

Looks to me your problem start here:
error C7528: OpenGL reserves names containing '__'

Thats hardly a Godot issue, seems OpenGL itself doesn't like you starting variable names with an underscore. I guess Godot could automatically rename things that are reserved or maybe detect them in editor an already highlight that you can't use that name...

@eon-s
Copy link
Contributor

eon-s commented Nov 13, 2017

Is because Godot adds a _ to the names, that was affecting some variable names (on android) on 2.1 and here adds a second _ making it use the reserved characters.

@Zylann
Copy link
Contributor Author

Zylann commented Nov 13, 2017

My shader is valid GLSL, Godot made it wrong, and didn't highlight it to me anyways, so I think it's either a bug or at least bad UX :p

@BastiaanOlij
Copy link
Contributor

Ah, now the double _ makes sense. So the first _ is your code and the second is added by Godot.

Yeah its not something people will grasp. I never used snake case before I started working in Godot so I never ran into this :)

@648trindade
Copy link

648trindade commented Jan 30, 2018

Still reproducible in 3.0 stable version

Apparently Godot renames variables adding m_ prefix, making variable names that contain one underscore at beggining contain two underscores

Godot uses 3.3 GLSL version. This citation is from GLSL 3.3 specification (page 13):

All macro names containing two consecutive underscores ( __ ) are reserved for future use as predefined macro names.

And from 4.4 (page 22) it stop being treated as an error:

[...] In addition, all identifiers containing two consecutive underscores ( __ ) are reserved for use by underlying software layers. Defining such a name in a shader does not itself result in an error, but may result in unintended behaviors that stem from having multiple definitions of the same name.

I think that godot should add just m as prefix, or replace underscore at beggining of variable names with other character, but this is a problematic aproach, since there can possible be another variable with such name.
Godot should correct variable with two underscores at the middle of variable name too. It's a terrible practice to add two underscores at the middle of name, i know, but always there someone that do this.

However, apparently the error only happened on Windows to me. Linux version is fine. (why?)

@DavidSichma
Copy link
Contributor

This issue also affects VisualShaders as some variables in the auto-generated code have a leading underscore.

@akien-mga
Copy link
Member

Cherry-picked for 3.0.7.

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

Successfully merging a pull request may close this issue.

7 participants