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

Tangent error in shader #447

Open
agung098 opened this issue May 31, 2024 · 15 comments
Open

Tangent error in shader #447

agung098 opened this issue May 31, 2024 · 15 comments

Comments

@agung098
Copy link

If i add triplanar tangent script in shader its error in godot 4.2

@Zylann
Copy link
Owner

Zylann commented May 31, 2024

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.

@agung098
Copy link
Author

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)

@Zylann
Copy link
Owner

Zylann commented May 31, 2024

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.

@agung098
Copy link
Author

It's issues in godot but, issues closed:godotengine/godot#84875

@Zylann
Copy link
Owner

Zylann commented May 31, 2024

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...

@agung098
Copy link
Author

I try in different terrain plugin but its ok, no error message

@agung098
Copy link
Author

@Zylann
Copy link
Owner

Zylann commented May 31, 2024

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.

@agung098
Copy link
Author

@agung098
Copy link
Author

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;
}

@Zylann
Copy link
Owner

Zylann commented May 31, 2024

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

@Zylann
Copy link
Owner

Zylann commented May 31, 2024

Also, one of the shaders (Classic4) already has a triplanar slot (which also isn't using TANGENT):
image

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.

@agung098
Copy link
Author

agung098 commented Jun 1, 2024

Same error message if i input NORMAL_MAP in multisplat16 fragment shader

@agung098
Copy link
Author

agung098 commented Jun 1, 2024

	NORMAL_MAP = /*u_terrain_normal_basis **/ (
		w.r * normal0 +
		w.g * normal1 +
		w.b * normal2 +
		w.a * normal3) / w_sum;

@Zylann
Copy link
Owner

Zylann commented Jun 1, 2024

Well, that's even more annoying... again, this warning makes no sense here.

So here are your options:

  • Stop using TANGENT and NORMALMAP 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

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

No branches or pull requests

2 participants