here is a part of my shader which i alter vertex heights in world space.
float4 CosWaveHeights = Cos * _Amplitudes - _SpaceFreq; // just a constant up and down motion for waves
for the sake of simplicity, the above ampituldes vector is just pointing up.
and i calculate tangents binormals and normals as follows(wavedirx and y are just a vector pointting to a side for simplicty):
float3 T = float3(0, 1, dot(CosWaveHeights, _WaveDirY));
float3 B = float3(1, 0, dot(CosWaveHeights, _WaveDirX));
float3 N = cross(T, B);
But normals look messed up with above calculation, what might be wrong here?
Your calculation doesn´t seem to make sense:
float3 T = float3(0, 1, dot(CosWaveHeights, _WaveDirY));
Will point up and forward.
float3 B = float3(1, 0, dot(CosWaveHeights, _WaveDirX));
Will point to the right and forward.
float3 N = cross(T, B);
Is the normal of the plane streched between those two vectors above which is something kinda messed up.
You should just calculate the normal from sourrounding heights which you will have to calculate and from there you can also go on calculating the tangent and bitangent.
Tangents don´t have to be based on UV coordinates, this depends on what you want to do with them. And depending on the mesh you can make some assumptions about the UV layout which then allows you to calculate them as if they where based on it. And the tangents do depend on the vertex positions. The tangent as well as the bitangent are orthogonal to the normal and orthogonal to each other.
This is for waves approaching the shore, and they are stretched on those vectors.
Anyways, i found out what the problem is. i replaced the wave mesh and it kinda works now.
If you want to use tangents for tangent space normal mapping, then they depend very much on the UV coordinates. Mapping your UVs directly to vertex position makes tangent calculation easier, but it does not change the fact that tangents depend on the UVs as well as vertex positions.