godot
godot copied to clipboard
Using Bent Normal Map and Triplanar on UV1 gives a shader compilation error
Tested versions
- Reproducible on v4.5.dev5.official [64b09905c]
- N/A on earlier versions
System information
Godot v4.5.dev5 - Arch Linux #1 ZEN SMP PREEMPT_DYNAMIC Sat, 07 Jun 2025 14:36:09 +0000 on Wayland - X11 display driver, Multi-window, 1 monitor - Vulkan (Forward+) - dedicated AMD Radeon RX 570 Series (RADV POLARIS10) - AMD Ryzen 7 5700X 8-Core Processor (16 threads)
Issue description
StandardMaterial3Ds that have both a bent normal map and a triplanar UV1 fail to compile and give an error to the console:
--Main Shader--
1 | // NOTE: Shader automatically converted from Godot Engine 4.5.dev5'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 | uniform ivec2 albedo_texture_size;
9 | uniform float point_size : hint_range(0.1, 128.0, 0.1);
10 |
11 | uniform float roughness : hint_range(0.0, 1.0);
12 | uniform sampler2D texture_metallic : hint_default_white, filter_linear_mipmap, repeat_enable;
13 | uniform vec4 metallic_texture_channel;
14 | uniform sampler2D texture_roughness : hint_roughness_r, filter_linear_mipmap, repeat_enable;
15 |
16 | uniform float specular : hint_range(0.0, 1.0, 0.01);
17 | uniform float metallic : hint_range(0.0, 1.0, 0.01);
18 |
19 | uniform sampler2D texture_bent_normal : hint_roughness_normal, filter_linear_mipmap, repeat_enable;
20 | varying vec3 uv1_triplanar_pos;
21 |
22 | uniform float uv1_blend_sharpness : hint_range(0.0, 150.0, 0.001);
23 | varying vec3 uv1_power_normal;
24 |
25 | uniform vec3 uv1_scale;
26 | uniform vec3 uv1_offset;
27 | uniform vec3 uv2_scale;
28 | uniform vec3 uv2_offset;
29 |
30 | void vertex() {
31 | vec3 normal = NORMAL;
32 |
33 | TANGENT = vec3(0.0, 0.0, -1.0) * abs(normal.x);
34 | TANGENT += vec3(1.0, 0.0, 0.0) * abs(normal.y);
35 | TANGENT += vec3(1.0, 0.0, 0.0) * abs(normal.z);
36 | TANGENT = normalize(TANGENT);
37 |
38 | BINORMAL = vec3(0.0, 1.0, 0.0) * abs(normal.x);
39 | BINORMAL += vec3(0.0, 0.0, -1.0) * abs(normal.y);
40 | BINORMAL += vec3(0.0, 1.0, 0.0) * abs(normal.z);
41 | BINORMAL = normalize(BINORMAL);
42 |
43 | // UV1 Triplanar: Enabled
44 | uv1_power_normal = pow(abs(NORMAL), vec3(uv1_blend_sharpness));
45 | uv1_triplanar_pos = VERTEX * uv1_scale + uv1_offset;
46 | uv1_power_normal /= dot(uv1_power_normal, vec3(1.0));
47 | uv1_triplanar_pos *= vec3(1.0, -1.0, 1.0);
48 | }
49 |
50 | vec4 triplanar_texture(sampler2D p_sampler, vec3 p_weights, vec3 p_triplanar_pos) {
51 | vec4 samp = vec4(0.0);
52 | samp += texture(p_sampler, p_triplanar_pos.xy) * p_weights.z;
53 | samp += texture(p_sampler, p_triplanar_pos.xz) * p_weights.y;
54 | samp += texture(p_sampler, p_triplanar_pos.zy * vec2(-1.0, 1.0)) * p_weights.x;
55 | return samp;
56 | }
57 |
58 | void fragment() {
59 | vec4 albedo_tex = triplanar_texture(texture_albedo, uv1_power_normal, uv1_triplanar_pos);
60 | ALBEDO = albedo.rgb * albedo_tex.rgb;
61 |
62 | float metallic_tex = dot(triplanar_texture(texture_metallic, uv1_power_normal, uv1_triplanar_pos), metallic_texture_channel);
63 | METALLIC = metallic_tex * metallic;
64 | SPECULAR = specular;
65 |
66 | vec4 roughness_texture_channel = vec4(1.0, 0.0, 0.0, 0.0);
67 | float roughness_tex = dot(triplanar_texture(texture_roughness, uv1_power_normal, uv1_triplanar_pos), roughness_texture_channel);
68 | ROUGHNESS = roughness_tex * roughness;
69 |
70 | // Bent Normal Map: Enabled
E 71-> BENT_NORMAL_MAP = texture(texture_bent_normal, base_uv).rgb;
72 | }
73 |
ERROR: :71 - Unknown identifier in expression: 'base_uv'.
ERROR: Shader compilation failed.
I'm not sure if it makes sense to have both enabled at the same time, so this can probably be solved by not allowing BNM to be set when Triplanar on UV1 is enabled, or vice versa.
Steps to reproduce
- Open MRP
- Select MeshInstance3D
- Select the mesh and its material (for clarity, the material was also colored red)
- Enable Triplanar on UV1
Minimal reproduction project (MRP)
@LunaCapra should bent normals work with triplanar?