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

Enabling Albedo Texture MSDF and UV1 Triplanar at the same time results in a shader compilation error #89463

Closed
Calinou opened this issue Mar 13, 2024 · 0 comments · Fixed by #89470

Comments

@Calinou
Copy link
Member

Calinou commented Mar 13, 2024

Tested versions

  • Reproducible in: 4.0.3.stable, 4.1.3.stable, 4.2.1.stable, 4.3.dev da945ce

System information

Godot v4.3.dev (da945ce) - Fedora Linux 39 (KDE Plasma) - Wayland - GLES3 (Compatibility) - NVIDIA GeForce RTX 4090 (nvidia; 545.29.06) - 13th Gen Intel(R) Core(TM) i9-13900K (32 Threads)

Issue description

Enabling Albedo Texture MSDF and UV1 Triplanar at the same time results in a shader compilation error:

--Main Shader--
    1 | // NOTE: Shader automatically converted from Godot Engine 4.3.dev's StandardMaterial3D.
    2 | 
    3 | shader_type spatial;
    4 | render_mode blend_mix,depth_draw_opaque,cull_back,diffuse_burley,specular_schlick_ggx;
    5 | uniform vec4 albedo : source_color;
    6 | uniform sampler2D texture_albedo : source_color,filter_linear_mipmap,repeat_enable;
    7 | uniform float msdf_pixel_range;
    8 | uniform float msdf_outline_size;
    9 | uniform float point_size : hint_range(0,128);
   10 | uniform float roughness : hint_range(0,1);
   11 | uniform sampler2D texture_metallic : hint_default_white,filter_linear_mipmap,repeat_enable;
   12 | uniform vec4 metallic_texture_channel;
   13 | uniform sampler2D texture_roughness : hint_roughness_r,filter_linear_mipmap,repeat_enable;
   14 | uniform float specular;
   15 | uniform float metallic;
   16 | varying vec3 uv1_triplanar_pos;
   17 | uniform float uv1_blend_sharpness;
   18 | varying vec3 uv1_power_normal;
   19 | uniform vec3 uv1_scale;
   20 | uniform vec3 uv1_offset;
   21 | uniform vec3 uv2_scale;
   22 | uniform vec3 uv2_offset;
   23 | 
   24 | 
   25 | void vertex() {
   26 |         vec3 normal = NORMAL;
   27 |         TANGENT = vec3(0.0,0.0,-1.0) * abs(normal.x);
   28 |         TANGENT+= vec3(1.0,0.0,0.0) * abs(normal.y);
   29 |         TANGENT+= vec3(1.0,0.0,0.0) * abs(normal.z);
   30 |         TANGENT = normalize(TANGENT);
   31 |         BINORMAL = vec3(0.0,1.0,0.0) * abs(normal.x);
   32 |         BINORMAL+= vec3(0.0,0.0,-1.0) * abs(normal.y);
   33 |         BINORMAL+= vec3(0.0,1.0,0.0) * abs(normal.z);
   34 |         BINORMAL = normalize(BINORMAL);
   35 |         uv1_power_normal=pow(abs(NORMAL),vec3(uv1_blend_sharpness));
   36 |         uv1_triplanar_pos = VERTEX * uv1_scale + uv1_offset;
   37 |         uv1_power_normal/=dot(uv1_power_normal,vec3(1.0));
   38 |         uv1_triplanar_pos *= vec3(1.0,-1.0, 1.0);
   39 | }
   40 | 
   41 | 
   42 | float msdf_median(float r, float g, float b, float a) {
   43 |         return min(max(min(r, g), min(max(r, g), b)), a);
   44 | }
   45 | 
   46 | 
   47 | vec4 triplanar_texture(sampler2D p_sampler,vec3 p_weights,vec3 p_triplanar_pos) {
   48 |         vec4 samp=vec4(0.0);
   49 |         samp+= texture(p_sampler,p_triplanar_pos.xy) * p_weights.z;
   50 |         samp+= texture(p_sampler,p_triplanar_pos.xz) * p_weights.y;
   51 |         samp+= texture(p_sampler,p_triplanar_pos.zy * vec2(-1.0,1.0)) * p_weights.x;
   52 |         return samp;
   53 | }
   54 | 
   55 | 
   56 | void fragment() {
   57 |         vec4 albedo_tex = triplanar_texture(texture_albedo,uv1_power_normal,uv1_triplanar_pos);
   58 |         {
   59 |                 albedo_tex.rgb = mix(vec3(1.0 + 0.055) * pow(albedo_tex.rgb, vec3(1.0 / 2.4)) - vec3(0.055), vec3(12.92) * albedo_tex.rgb.rgb, lessThan(albedo_tex.rgb, vec3(0.0031308)));
   60 |                 vec2 msdf_size = vec2(msdf_pixel_range) / vec2(textureSize(texture_albedo, 0));
E  61->                 vec2 dest_size = vec2(1.0) / fwidth(uv1_triplanar_pos);
   62 |                 float px_size = max(0.5 * dot(msdf_size, dest_size), 1.0);
   63 |                 float d = msdf_median(albedo_tex.r, albedo_tex.g, albedo_tex.b, albedo_tex.a) - 0.5;
   64 |                 if (msdf_outline_size > 0.0) {
   65 |                         float cr = clamp(msdf_outline_size, 0.0, msdf_pixel_range / 2.0) / msdf_pixel_range;
   66 |                         albedo_tex.a = clamp((d + cr) * px_size, 0.0, 1.0);
   67 |                 } else {
   68 |                         albedo_tex.a = clamp(d * px_size + 0.5, 0.0, 1.0);
   69 |                 }
   70 |                 albedo_tex.rgb = vec3(1.0);
   71 |         }
   72 |         ALBEDO = albedo.rgb * albedo_tex.rgb;
   73 |         float metallic_tex = dot(triplanar_texture(texture_metallic,uv1_power_normal,uv1_triplanar_pos),metallic_texture_channel);
   74 |         METALLIC = metallic_tex * metallic;
   75 |         vec4 roughness_texture_channel = vec4(1.0,0.0,0.0,0.0);
   76 |         float roughness_tex = dot(triplanar_texture(texture_roughness,uv1_power_normal,uv1_triplanar_pos),roughness_texture_channel);
   77 |         ROUGHNESS = roughness_tex * roughness;
   78 |         SPECULAR = specular;
   79 | }
   80 | 
SHADER ERROR: Invalid arguments to operator '/': 'vec2, vec3'.
          at: (null) (:61)
ERROR: Shader compilation failed.
   at: set_code (servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.cpp:145)
ERROR: Parameter "version" is null.
   at: version_get_shader (./servers/rendering/renderer_rd/shader_rd.h:166)

Enabling UV2 Triplanar doesn't have this issue. I found this out while working on #89267 🙂

It probably doesn't make sense to have both triplanar and MSDF enabled at the same time, so triplanar should probably "win" here like we do for height mapping (where height mapping is ignored when triplanar is enabled):

if (features[FEATURE_HEIGHT_MAPPING] && flags[FLAG_UV1_USE_TRIPLANAR]) {
// Display both resource name and albedo texture name.
// Materials are often built-in to scenes, so displaying the resource name alone may not be meaningful.
// On the other hand, albedo textures are almost always external to the scene.
if (textures[TEXTURE_ALBEDO].is_valid()) {
WARN_PRINT(vformat("%s (albedo %s): Height mapping is not supported on triplanar materials. Ignoring height mapping in favor of triplanar mapping.", get_path(), textures[TEXTURE_ALBEDO]->get_path()));
} else if (!get_path().is_empty()) {
WARN_PRINT(vformat("%s: Height mapping is not supported on triplanar materials. Ignoring height mapping in favor of triplanar mapping.", get_path()));
} else {
// Resource wasn't saved yet.
WARN_PRINT("Height mapping is not supported on triplanar materials. Ignoring height mapping in favor of triplanar mapping.");
}
}

Steps to reproduce

  • Create a StandardMaterial3D and assign it to a MeshInstance.
  • Enable Albedo > Texture MSDF and UV1 > Triplanar.
  • Notice the material turning gray and look at the Output panel.

Minimal reproduction project (MRP)

test_triplanar_msdf.zip

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