Tangent error in shader
Opened this issue ยท 15 comments
If i add triplanar tangent script in shader its error in godot 4.2
What are you talking about? Which script? Which code? What are you doing? Which plugin version? You're not providing enough information. Please don't delete the issue template if it's to write a single line with no details. Also if all you did is to modify one of the plugin shaders, this is likely not an issue with the plugin but more a Godot shaders question, which you can ask in different places.
I put this code in vertex, for make triplanar :
TANGENT = cross(NORMAL, vec3(0,0,1));
BINORMAL = cross(NORMAL, TANGENT);
This is error message:
servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp:3725 - Attempting to use a shader that requires tangents with a mesh that doesn't contain tangents. Ensure that meshes are imported with the 'ensure_tangents' option. If creating your own meshes, add an ARRAY_TANGENTarray (when using ArrayMesh) or callgenerate_tangents() (when using SurfaceTool). (User)
Well, first, this warning is bogus because the mesh used for rendering does not need tangents, especially if you make them up in the shader anyways. So at the very least, it looks like an oversight from Godot.
But one thing you could do is to not put this code in the vertex shader, or create a varying
to pass it to the vertex shader instead of using Godot's built-in TANGENT.
It's issues in godot but, issues closed:godotengine/godot#84875
It's been closed without the present case being raised. So maybe it should be re-opened, but if having this warning is desired to handle the other cases, I'm not sure how the devs should make Godot realize when tangents are generated in the shader...
I try in different terrain plugin but its ok, no error message
This is simple terrain for try: https://github.com/majikayogames/SimpleTerrain/tree/main/addons/SimpleTerrain
Why are you linking this? It's not even using this plugin.
But should be noted that this plugin does not assign TANGENT anywhere in its shader, from what I can see. It's also working differently so obviously some things dont happen the same way.
vec3 get_normal(vec2 uv, out vec3 tangent, out vec3 binormal) {
float u, v, height;
vec3 normal;
// Use vertex normals within radius of vertex_normals_distance, and along region borders.
if (v_region_border_mask > 0.5 || v_vertex_xz_dist < vertex_normals_distance) {
normal = normalize(v_normal);
} else {
height = get_height(uv);
u = height - get_height(uv + vec2(_region_texel_size, 0));
v = height - get_height(uv + vec2(0, _region_texel_size));
normal = normalize(vec3(u, _mesh_vertex_spacing, v));
}
tangent = cross(normal, vec3(0, 0, 1));
binormal = cross(normal, tangent);
return normal;
}
That's yet another plugin where they don't even precalculate normals. I think they also added tangents to their mesh (which is also different, it uses clipmap instead of quad tree) just to silence the warning, even though they are not even used by the shader.
As I said, you can still make your tangent in the shader if you want to, by not using Godot's builtin variable in the vertex shader or doing it in the vertex shader, no need to refactor how this plugin works
Also, one of the shaders (Classic4
) already has a triplanar slot (which also isn't using TANGENT
):
The reason it works without TANGENT
is because for a very long time this plugin just factored all normalmapping (ground and textures) into NORMAL
, and doesn't use NORMALMAP
. I don't exactly recall why (the plugin has been around since Godot 2) It's not how it's normally done nowadays I guess, but if the latter is desired, shaders need to be modified a bit more extensively. I have no plan to do this, but PRs are welcome.
Same error message if i input NORMAL_MAP in multisplat16 fragment shader
NORMAL_MAP = /*u_terrain_normal_basis **/ (
w.r * normal0 +
w.g * normal1 +
w.b * normal2 +
w.a * normal3) / w_sum;
Well, that's even more annoying... again, this warning makes no sense here.
So here are your options:
- Stop using
TANGENT
andNORMALMAP
in shader because Godot made it way too annoying to use them in this case due to this pesky warning. You can look how Classic4 is doing to not use either of these. - Modify
hterrain_mesher.gd
so that it inserts a tangents array into the mesh, which is annoying because that's unnecessary data just to silence a warning that should not even exist in this situation - Wait until Godot fixes this somehow (or do a PR), though at the moment I'm not sure how it's going to be fixed