When I constructed the arraymesh, I assigned a value to the TANGENT of each vertex, and it was a normalized value. But the TANGENT I get in the shader is totally different from what I pass. What does godot do to the TANGENT I pass in, and how can I get the original value I pass in?
TANGENT in shader is different from what I passed in
See this page:
https://docs.godotengine.org/en/stable/tutorials/shaders/shader_reference/spatial_shader.html
What you likely need to do is set skip_vertex_transform
on the render_mode
. Like this:
shader_type spatial;
render_mode skip_vertex_transform;
void vertex() {
VERTEX = (MODELVIEW_MATRIX * vec4(VERTEX, 1.0)).xyz;
NORMAL = normalize((MODELVIEW_MATRIX * vec4(NORMAL, 0.0)).xyz);
}
cybereality skip_vertex_transform
has been added, but I still can't get the correct TANGENT value, but the NORMAL value is correct.
So something else must be off. If you use that mode, then it disables the default calculation. Where are you taking the TANGENT. If it is in the vertex shader than it should be correct. But if you sample in the fragment, then there will be default interpolation. It may also just be a bug with how you are setting the tangent. It's hard to say without seeing the code.
var normal = new Vector3[realVertexNum];
var tangent = new double[realVertexNum * 4];
for (int i = 0; i < realVertexNum; i++)
{
int q = i / 10;
int m = i % 10;
Vector3 curNormal = (OriginVertexs[q + 1] - OriginVertexs[q]).Normalized();
Vector3 curTangent = (OriginVertexs[q + 1] - OriginVertexs[q]).Normalized();
normal[i] = curNormal;
tangent[i * 4] = curTangent.x;
tangent[i * 4 + 1] = curTangent.y;
tangent[i * 4 + 2] = curTangent.z;
tangent[i * 4 + 3] = 1.0;
}
I am using TANGENT in the vertex shader. The above code is the code where I set the NORMAL and TANGENT of each vertex. I think there should be no problem because the obtained NORMAL value is correct. In theory, TANGENT should be the same value as NORMAL, but it is not.
I know where the problem is. TANGENT must use float type, but I use double type.