unity quaternion vector

make footprints

Do two kinds of surface subdivision and decal

First generate a height map with an orthogonal camera 

Sampling uv is generated by pos from world to camera space

 

Unity's support for tessellation is still relatively large, only surfacesshader can be used 

And the surfaceshader with tesse does not support the transfer of custom data from its own vs to ps

 

If it does not match the lighting (normal), the newly added vertices cannot be seen clearly

If unity's surfacesshader can't support tessellation-generated vertices and pass normal to ps, this function doesn't make much sense

 

To generate footprints in the direction of the character's movement requires generating a set of vertex data 

This direction is calculated by me using quaternions 

temp = rot * new Vector3(-1f * scale, 0, 1f * scale);//Use quaternionXvector3 at the origin to get the orientation 
va[x++] = pos + temp; //Then apply to the position of the point, which is equivalent to moving to world space after localspace rotation

                        //If you don't do this directly, rotationXpos will get ((0, 0, 0)-point) the vector after this vector is rotated along the quarternion

                          //Debug.DrawLine(start, dir, Color.green); can be used to debug
temp = rot * new Vector3(-1f * scale, 0, -1f * scale);
va[x++] = pos + temp;

temp = rot * new Vector3(1f * scale, 0, -1f * scale);
va[x++] = pos + temp;
temp = rot * new Vector3(1f * scale, 0, 1f * scale);
va[x++] = pos + temp;

{
mesh = new Mesh();
mesh.hideFlags = HideFlags.DontSave;
mesh.vertices = va;
mesh.uv = ta;
mesh.SetIndices(ia, MeshTopology.Triangles, 0);
}

Graphics.DrawMesh(mesh, Matrix4x4.identity, markMat, 16, camHeight);//16 layer decal

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324973765&siteId=291194637