Godot: Shader: Assigning default values to uniforms causes crash when using single parameter constructors

Created on 29 Dec 2017  路  11Comments  路  Source: godotengine/godot

Godot version:

v3.0.beta.custom_build.2de7069

Issue description:

Godot crashes when using single parameter constructors for uniform default values. This happens for all non-scalar types, e.g. mat2, vec3, vec4..

Steps to reproduce:
Example - Write this in any shader: uniform vec2 v = vec2(1.0);

  • [x] I searched the existing GitHub issues for potential duplicates.
bug editor rendering

Most helpful comment

@11clock That's probably for assigning in the shader functions. Look further down in docs: "Uniforms can also be assigned default values:" 馃槂

Either way godot should not crash.

All 11 comments

Doesn't the guide to the new shader language say that you shouldn't assign uniform variables default values?

EDIT: http://docs.godotengine.org/en/latest/learning/features/shading/shading_language.html "Passing values to shaders is possible. These are global to the whole shader and called uniforms. When a shader is later assigned to a material, the uniforms will appear as editable parameters on it. Uniforms can鈥檛 be written from within the shader."

@11clock That's probably for assigning in the shader functions. Look further down in docs: "Uniforms can also be assigned default values:" 馃槂

Either way godot should not crash.

Got it. Uniform default values are not properly parsed. Memory is only allocated for the one parameter and the code expects memory to be allocated for all members of the type.

Areas of interest:

  • shader_language.cpp: _parse_shader() under case TK_UNIFORM
  • rasterizer_storage_gles3.cpp: _fill_std140_ubo_value()

Just as an exercise, I created a test for this.

This really should be a "milestone" for 3.0 and not 3.1.

Discussed it quickly with @reduz to see whether to merge #15985 before 3.0, but we prefer to wait for now:

\ \

Fair enough though I meant it shouldn't be a milestone for 3.1 if it can be fixed in the 3.0.x maintenance releases?

3.0 milestone means that it should be fixed before 3.0 is released, or once 3.0 is released, that it should be fixed only for 3.0. But this needs to be fixed for all future Godot versions, it's not a 3.0-specific issue.

Reopening as #15985 was reverted.

FYI, for those wondering how to use defaults, the workaround is:

uniform vec4 color: hint_color = vec4(1.0)

which crashes should be:

uniform vec4 color: hint_color = vec4(1.0, 1.0, 1.0, 1.0)

You cannot use the typical "exploding" constructors (so vec3 should have all 3, etc). This seems to work.

bumping, ran into this issue yesterday. Affects both 3.0.6 and current master

Was this page helpful?
0 / 5 - 0 ratings