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

Label3D rendering solid color instead of text #100669

Closed
Wiechciu opened this issue Dec 20, 2024 · 6 comments · Fixed by #100678
Closed

Label3D rendering solid color instead of text #100669

Wiechciu opened this issue Dec 20, 2024 · 6 comments · Fixed by #100678

Comments

@Wiechciu
Copy link

Tested versions

  • Reproducible in 4.4 dev 7
  • Not reproducible in 4.4 dev 6 and any previous

System information

Windows 10, GeForce GTX 1660 Super, AMD Ryzen 5 2600

Issue description

After the dev 7 release, all of the Label3Ds in my project got broken, rendering just a solid gray color instead of any text. See attached screenshot of the same scene from dev 6 (with correctly rendered text) and dev 7 (with a solid color instead of text).
Image
Image

When I create a new project, the Label3Ds render text correctly without any issues, so I cannot reproduce it on an empty project.
In my project, I additionally have these errors on start up, related to shaders. I unfortunately don't know much about shaders, so can't tell what it means exactly, but I don't have this error when I create a new project, so this might be related to this issue with Label3D

Godot Engine v4.4.dev7.official (c) 2007-present Juan Linietsky, Ariel Manzur & Godot Contributors.
  ERROR: :68 - Unknown identifier in expression: 'albedo_texture_size'.
  ERROR: Shader compilation failed.
  ERROR: :53 - Unknown identifier in expression: 'albedo_texture_size'.
  ERROR: Shader compilation failed.
  ERROR: :53 - Unknown identifier in expression: 'albedo_texture_size'.
  ERROR: Shader compilation failed.
--Main Shader--
    1 | // NOTE: Shader automatically converted from Godot Engine 4.4.dev7's StandardMaterial3D.
    2 | 
    3 | shader_type spatial;
    4 | render_mode blend_mix, depth_draw_opaque, cull_disabled, diffuse_burley, specular_schlick_ggx, unshaded, depth_test_disabled;
    5 | 
    6 | uniform vec4 albedo : source_color;
    7 | uniform sampler2D texture_albedo : source_color, filter_linear_mipmap, repeat_enable;
    8 | 
    9 | uniform float msdf_pixel_range : hint_range(1.0, 100.0, 1.0);
   10 | uniform float msdf_outline_size : hint_range(0.0, 250.0, 1.0);
   11 | uniform float point_size : hint_range(0.1, 128.0, 0.1);
   12 | 
   13 | uniform float roughness : hint_range(0.0, 1.0);
   14 | uniform sampler2D texture_metallic : hint_default_white, filter_linear_mipmap, repeat_enable;
   15 | uniform vec4 metallic_texture_channel;
   16 | uniform sampler2D texture_roughness : hint_roughness_r, filter_linear_mipmap, repeat_enable;
   17 | 
   18 | uniform float specular : hint_range(0.0, 1.0, 0.01);
   19 | uniform float metallic : hint_range(0.0, 1.0, 0.01);
   20 | 
   21 | uniform vec3 uv1_scale;
   22 | uniform vec3 uv1_offset;
   23 | uniform vec3 uv2_scale;
   24 | uniform vec3 uv2_offset;
   25 | 
   26 | void vertex() {
   27 | 	// Vertex Color is sRGB: Enabled
   28 | 	if (!OUTPUT_IS_SRGB) {
   29 | 		COLOR.rgb = mix(
   30 | 				pow((COLOR.rgb + vec3(0.055)) * (1.0 / (1.0 + 0.055)), vec3(2.4)),
   31 | 				COLOR.rgb * (1.0 / 12.92),
   32 | 				lessThan(COLOR.rgb, vec3(0.04045)));
   33 | 	}
   34 | 
   35 | 	UV = UV * uv1_scale.xy + uv1_offset.xy;
   36 | 
   37 | 	// Billboard Mode: Enabled
   38 | 	MODELVIEW_MATRIX = VIEW_MATRIX * mat4(
   39 | 			MAIN_CAM_INV_VIEW_MATRIX[0],
   40 | 			MAIN_CAM_INV_VIEW_MATRIX[1],
   41 | 			MAIN_CAM_INV_VIEW_MATRIX[2],
   42 | 			MODEL_MATRIX[3]);
   43 | 
   44 | 	// Billboard Keep Scale: Enabled
   45 | 	MODELVIEW_MATRIX = MODELVIEW_MATRIX * mat4(
   46 | 			vec4(length(MODEL_MATRIX[0].xyz), 0.0, 0.0, 0.0),
   47 | 			vec4(0.0, length(MODEL_MATRIX[1].xyz), 0.0, 0.0),
   48 | 			vec4(0.0, 0.0, length(MODEL_MATRIX[2].xyz), 0.0),
   49 | 			vec4(0.0, 0.0, 0.0, 1.0));
   50 | 	MODELVIEW_NORMAL_MATRIX = mat3(MODELVIEW_MATRIX);
   51 | }
   52 | 
   53 | float msdf_median(float r, float g, float b, float a) {
   54 | 	return min(max(min(r, g), min(max(r, g), b)), a);
   55 | }
   56 | 
   57 | void fragment() {
   58 | 	vec2 base_uv = UV;
   59 | 
   60 | 	vec4 albedo_tex = texture(texture_albedo, base_uv);
   61 | 
   62 | 	{
   63 | 		// Albedo Texture MSDF: Enabled
   64 | 		albedo_tex.rgb = mix(
   65 | 				vec3(1.0 + 0.055) * pow(albedo_tex.rgb, vec3(1.0 / 2.4)) - vec3(0.055),
   66 | 				vec3(12.92) * albedo_tex.rgb,
   67 | 				lessThan(albedo_tex.rgb, vec3(0.0031308)));
E  68-> 		vec2 msdf_size = vec2(msdf_pixel_range) / vec2(albedo_texture_size));
   69 | 		vec2 dest_size = vec2(1.0) / fwidth(base_uv);
   70 | 
   71 | 		float px_size = max(0.5 * dot(msdf_size, dest_size), 1.0);
   72 | 		float d = msdf_median(albedo_tex.r, albedo_tex.g, albedo_tex.b, albedo_tex.a) - 0.5;
   73 | 		if (msdf_outline_size > 0.0) {
   74 | 			float cr = clamp(msdf_outline_size, 0.0, msdf_pixel_range / 2.0) / msdf_pixel_range;
   75 | 			albedo_tex.a = clamp((d + cr) * px_size, 0.0, 1.0);
   76 | 		} else {
   77 | 			albedo_tex.a = clamp(d * px_size + 0.5, 0.0, 1.0);
   78 | 		}
   79 | 		albedo_tex.rgb = vec3(1.0);
   80 | 	}
   81 | 
   82 | 	// Vertex Color Use as Albedo: Enabled
   83 | 	albedo_tex *= COLOR;
   84 | 
   85 | 	ALBEDO = albedo.rgb * albedo_tex.rgb;
   86 | 
   87 | 	float metallic_tex = dot(texture(texture_metallic, base_uv), metallic_texture_channel);
   88 | 	METALLIC = metallic_tex * metallic;
   89 | 	SPECULAR = specular;
   90 | 
   91 | 	vec4 roughness_texture_channel = vec4(1.0, 0.0, 0.0, 0.0);
   92 | 	float roughness_tex = dot(texture(texture_roughness, base_uv), roughness_texture_channel);
   93 | 	ROUGHNESS = roughness_tex * roughness;
   94 | 	ALPHA *= albedo.a * albedo_tex.a;
   95 | }
   96 | 
--Main Shader--
    1 | // NOTE: Shader automatically converted from Godot Engine 4.4.dev7's StandardMaterial3D.
    2 | 
    3 | shader_type spatial;
    4 | render_mode blend_mix, depth_draw_opaque, cull_back, diffuse_burley, specular_schlick_ggx;
    5 | 
    6 | uniform vec4 albedo : source_color;
    7 | uniform sampler2D texture_albedo : source_color, filter_linear_mipmap, repeat_enable;
    8 | 
    9 | uniform float msdf_pixel_range : hint_range(1.0, 100.0, 1.0);
   10 | uniform float msdf_outline_size : hint_range(0.0, 250.0, 1.0);
   11 | uniform float point_size : hint_range(0.1, 128.0, 0.1);
   12 | 
   13 | uniform float roughness : hint_range(0.0, 1.0);
   14 | uniform sampler2D texture_metallic : hint_default_white, filter_linear_mipmap, repeat_enable;
   15 | uniform vec4 metallic_texture_channel;
   16 | uniform sampler2D texture_roughness : hint_roughness_r, filter_linear_mipmap, repeat_enable;
   17 | 
   18 | uniform float specular : hint_range(0.0, 1.0, 0.01);
   19 | uniform float metallic : hint_range(0.0, 1.0, 0.01);
   20 | 
   21 | uniform vec3 uv1_scale;
   22 | uniform vec3 uv1_offset;
   23 | uniform vec3 uv2_scale;
   24 | uniform vec3 uv2_offset;
   25 | 
   26 | void vertex() {
   27 | 	// Vertex Color is sRGB: Enabled
   28 | 	if (!OUTPUT_IS_SRGB) {
   29 | 		COLOR.rgb = mix(
   30 | 				pow((COLOR.rgb + vec3(0.055)) * (1.0 / (1.0 + 0.055)), vec3(2.4)),
   31 | 				COLOR.rgb * (1.0 / 12.92),
   32 | 				lessThan(COLOR.rgb, vec3(0.04045)));
   33 | 	}
   34 | 
   35 | 	UV = UV * uv1_scale.xy + uv1_offset.xy;
   36 | }
   37 | 
   38 | float msdf_median(float r, float g, float b, float a) {
   39 | 	return min(max(min(r, g), min(max(r, g), b)), a);
   40 | }
   41 | 
   42 | void fragment() {
   43 | 	vec2 base_uv = UV;
   44 | 
   45 | 	vec4 albedo_tex = texture(texture_albedo, base_uv);
   46 | 
   47 | 	{
   48 | 		// Albedo Texture MSDF: Enabled
   49 | 		albedo_tex.rgb = mix(
   50 | 				vec3(1.0 + 0.055) * pow(albedo_tex.rgb, vec3(1.0 / 2.4)) - vec3(0.055),
   51 | 				vec3(12.92) * albedo_tex.rgb,
   52 | 				lessThan(albedo_tex.rgb, vec3(0.0031308)));
E  53-> 		vec2 msdf_size = vec2(msdf_pixel_range) / vec2(albedo_texture_size));
   54 | 		vec2 dest_size = vec2(1.0) / fwidth(base_uv);
   55 | 
   56 | 		float px_size = max(0.5 * dot(msdf_size, dest_size), 1.0);
   57 | 		float d = msdf_median(albedo_tex.r, albedo_tex.g, albedo_tex.b, albedo_tex.a) - 0.5;
   58 | 		if (msdf_outline_size > 0.0) {
   59 | 			float cr = clamp(msdf_outline_size, 0.0, msdf_pixel_range / 2.0) / msdf_pixel_range;
   60 | 			albedo_tex.a = clamp((d + cr) * px_size, 0.0, 1.0);
   61 | 		} else {
   62 | 			albedo_tex.a = clamp(d * px_size + 0.5, 0.0, 1.0);
   63 | 		}
   64 | 		albedo_tex.rgb = vec3(1.0);
   65 | 	}
   66 | 
   67 | 	// Vertex Color Use as Albedo: Enabled
   68 | 	albedo_tex *= COLOR;
   69 | 
   70 | 	ALBEDO = albedo.rgb * albedo_tex.rgb;
   71 | 
   72 | 	float metallic_tex = dot(texture(texture_metallic, base_uv), metallic_texture_channel);
   73 | 	METALLIC = metallic_tex * metallic;
   74 | 	SPECULAR = specular;
   75 | 
   76 | 	vec4 roughness_texture_channel = vec4(1.0, 0.0, 0.0, 0.0);
   77 | 	float roughness_tex = dot(texture(texture_roughness, base_uv), roughness_texture_channel);
   78 | 	ROUGHNESS = roughness_tex * roughness;
   79 | 	ALPHA *= albedo.a * albedo_tex.a;
   80 | }
   81 | 
--Main Shader--
    1 | // NOTE: Shader automatically converted from Godot Engine 4.4.dev7's StandardMaterial3D.
    2 | 
    3 | shader_type spatial;
    4 | render_mode blend_mix, depth_draw_opaque, cull_disabled, diffuse_burley, specular_schlick_ggx, unshaded;
    5 | 
    6 | uniform vec4 albedo : source_color;
    7 | uniform sampler2D texture_albedo : source_color, filter_linear_mipmap, repeat_enable;
    8 | 
    9 | uniform float msdf_pixel_range : hint_range(1.0, 100.0, 1.0);
   10 | uniform float msdf_outline_size : hint_range(0.0, 250.0, 1.0);
   11 | uniform float point_size : hint_range(0.1, 128.0, 0.1);
   12 | 
   13 | uniform float roughness : hint_range(0.0, 1.0);
   14 | uniform sampler2D texture_metallic : hint_default_white, filter_linear_mipmap, repeat_enable;
   15 | uniform vec4 metallic_texture_channel;
   16 | uniform sampler2D texture_roughness : hint_roughness_r, filter_linear_mipmap, repeat_enable;
   17 | 
   18 | uniform float specular : hint_range(0.0, 1.0, 0.01);
   19 | uniform float metallic : hint_range(0.0, 1.0, 0.01);
   20 | 
   21 | uniform vec3 uv1_scale;
   22 | uniform vec3 uv1_offset;
   23 | uniform vec3 uv2_scale;
   24 | uniform vec3 uv2_offset;
   25 | 
   26 | void vertex() {
   27 | 	// Vertex Color is sRGB: Enabled
   28 | 	if (!OUTPUT_IS_SRGB) {
   29 | 		COLOR.rgb = mix(
   30 | 				pow((COLOR.rgb + vec3(0.055)) * (1.0 / (1.0 + 0.055)), vec3(2.4)),
   31 | 				COLOR.rgb * (1.0 / 12.92),
   32 | 				lessThan(COLOR.rgb, vec3(0.04045)));
   33 | 	}
   34 | 
   35 | 	UV = UV * uv1_scale.xy + uv1_offset.xy;
   36 | }
   37 | 
   38 | float msdf_median(float r, float g, float b, float a) {
   39 | 	return min(max(min(r, g), min(max(r, g), b)), a);
   40 | }
   41 | 
   42 | void fragment() {
   43 | 	vec2 base_uv = UV;
   44 | 
   45 | 	vec4 albedo_tex = texture(texture_albedo, base_uv);
   46 | 
   47 | 	{
   48 | 		// Albedo Texture MSDF: Enabled
   49 | 		albedo_tex.rgb = mix(
   50 | 				vec3(1.0 + 0.055) * pow(albedo_tex.rgb, vec3(1.0 / 2.4)) - vec3(0.055),
   51 | 				vec3(12.92) * albedo_tex.rgb,
   52 | 				lessThan(albedo_tex.rgb, vec3(0.0031308)));
E  53-> 		vec2 msdf_size = vec2(msdf_pixel_range) / vec2(albedo_texture_size));
   54 | 		vec2 dest_size = vec2(1.0) / fwidth(base_uv);
   55 | 
   56 | 		float px_size = max(0.5 * dot(msdf_size, dest_size), 1.0);
   57 | 		float d = msdf_median(albedo_tex.r, albedo_tex.g, albedo_tex.b, albedo_tex.a) - 0.5;
   58 | 		if (msdf_outline_size > 0.0) {
   59 | 			float cr = clamp(msdf_outline_size, 0.0, msdf_pixel_range / 2.0) / msdf_pixel_range;
   60 | 			albedo_tex.a = clamp((d + cr) * px_size, 0.0, 1.0);
   61 | 		} else {
   62 | 			albedo_tex.a = clamp(d * px_size + 0.5, 0.0, 1.0);
   63 | 		}
   64 | 		albedo_tex.rgb = vec3(1.0);
   65 | 	}
   66 | 
   67 | 	// Vertex Color Use as Albedo: Enabled
   68 | 	albedo_tex *= COLOR;
   69 | 
   70 | 	ALBEDO = albedo.rgb * albedo_tex.rgb;
   71 | 
   72 | 	float metallic_tex = dot(texture(texture_metallic, base_uv), metallic_texture_channel);
   73 | 	METALLIC = metallic_tex * metallic;
   74 | 	SPECULAR = specular;
   75 | 
   76 | 	vec4 roughness_texture_channel = vec4(1.0, 0.0, 0.0, 0.0);
   77 | 	float roughness_tex = dot(texture(texture_roughness, base_uv), roughness_texture_channel);
   78 | 	ROUGHNESS = roughness_tex * roughness;
   79 | 	ALPHA *= albedo.a * albedo_tex.a;
   80 | }
   81 | 

And these errors when I run the project:

E 0:00:06:0680   Unknown identifier in expression: 'albedo_texture_size'.
  <C++ Source>   :68
E 0:00:06:0736   set_code: Shader compilation failed.
  <C++ Error>    Method/function failed.
  <C++ Source>   servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.cpp:152 @ set_code()

Steps to reproduce

Create a Label3D node, then add some text to it - it will render a solid gray color instead of text.
When I create a new project, the Label3Ds render text correctly without any issues, so I cannot reproduce it on an empty project.

Minimal reproduction project (MRP)

When I create a new project, the Label3Ds render text correctly without any issues, so I cannot reproduce it on an empty project.

@akien-mga
Copy link
Member

Regression from #100280 - sounds like nobody tested this 🙃

@akien-mga
Copy link
Member

To be clear I see two issues in #100280:

  • There's an extra closing parentheses so the shader should actually have a parse error.
  • albedo_texture_size is only defined if (alpha_antialiasing_mode != ALPHA_ANTIALIASING_OFF && (transparency == TRANSPARENCY_ALPHA_SCISSOR || transparency == TRANSPARENCY_ALPHA_HASH)) and apparently this isn't the condition we have here.

@akien-mga akien-mga moved this from For team assessment to In progress / Assigned in Rendering Issue Triage Dec 20, 2024
@clayjohn
Copy link
Member

clayjohn commented Dec 21, 2024

Any chance you can share what combination of settings triggers this? It doesn't reproduce with a default Label3D.

Edit: I think I might be able to work backwards from the shader actually. But in the future, it would save us a lot of time if you could share how to reproduce the issue

@Wiechciu
Copy link
Author

Any chance you can share what combination of settings triggers this? It doesn't reproduce with a default Label3D.

Edit: I think I might be able to work backwards from the shader actually. But in the future, it would save us a lot of time if you could share how to reproduce the issue

I upgraded my Godot from dev 6 to dev 7, opened my project and that's what I saw, there were no specific steps I took to break it.
I tested the same scenes in the newly created project, and they worked fine, so sharing the scenes with you would bring no benefit.
If you have any suggestions what settings I can test on my end - let me know.
If you want, I can also share the whole project with you, if you feel like it will help you.

@clayjohn
Copy link
Member

I was able to work backwards from the shader. The bug requires using a font with MSDF enabled. The default font doesn't have MSDF, so it doesn't trigger this bug.

Ideally your reproduction steps would have included that information to save me time. But in this case the error in the shader code had everything I needed to figure it out quickly, so it was no problem! I've already made a PR to fix this issue :) #100678

@Wiechciu
Copy link
Author

Wiechciu commented Dec 21, 2024

I was able to work backwards from the shader. The bug requires using a font with MSDF enabled. The default font doesn't have MSDF, so it doesn't trigger this bug.

Ideally your reproduction steps would have included that information to save me time. But in this case the error in the shader code had everything I needed to figure it out quickly, so it was no problem! I've already made a PR to fix this issue :) #100678

Hi @clayjohn, thanks for the fix, but I actually don't use any custom font in my project, only the default ones. Is there any way I can test your fix to see if it actually was the rootcause?
Or if I can provide you with any specific screenshot, settings, etc, let me know.

Edit:
I just remembered that I used this setting to change the default font to msdf:
https://docs.godotengine.org/en/stable/classes/class_projectsettings.html#class-projectsettings-property-gui-theme-default-font-multichannel-signed-distance-field

@github-project-automation github-project-automation bot moved this from In progress / Assigned to Done in Rendering Issue Triage Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Release Blocker
Status: Done
Development

Successfully merging a pull request may close this issue.

4 participants