C# 使用网格UV在世界纹理中匹配覆盖图像
在过去的几天里,我一直在为我在一个名为。要测试我创建此演示的效果,请执行以下操作:C# 使用网格UV在世界纹理中匹配覆盖图像,c#,unity3d,textures,rendering,C#,Unity3d,Textures,Rendering,在过去的几天里,我一直在为我在一个名为。要测试我创建此演示的效果,请执行以下操作: 此图像叠加在屏幕上:(缩放以匹配分辨率) 按下空格键,游戏中网格顶点的屏幕坐标将转换为UV,并应用于具有相同纹理的网格 当摄影机以垂直角度面向四边形时,效果如下: 以另一种方式解释,如果四边形的左上角坐标水平穿过屏幕30%,垂直穿过屏幕40%,我希望使顶点的UV(0.3,0.4)纹理与覆盖完美匹配(如图所示) 现在,仅当摄影机也可以从其他角度观看时,效果才起作用,因此,以下是更新纹理后摄影机轻微旋转(围绕Y轴)的
void UpdateTexture() {
// test is the rainbow Texture2D
// r is the Renderer
r.material.mainTexture = test;
// m is the Quad mesh
Vector3[] vert = m.vertices;
Vector2[] uv = m.uv;
// We will go through each vertex of the mesh
for(int i = 0; i < uv.Length; i++) {
// Find where the world position of that vertex is
Vector3 worldPosition = transform.TransformPoint(vert[i]);
// Convert that into a screen position based on our camera
Vector2 screenPosition = CameraToTexture.cam.WorldToScreenPoint(worldPosition);
// Put that within the range 0...1 as a UV
Vector2 uvPosition = new Vector2(screenPosition.x / CameraToTexture.cam.pixelWidth, screenPosition.y / CameraToTexture.cam.pixelHeight);
// Save that UV into our temp array
uv[i] = uvPosition;
}
// Apply to the UV array of the mesh
m.uv = uv;
}
void UpdateTexture(){
//测试是彩虹纹理2d
//r是渲染器
r、 material.main纹理=测试;
//m是四边形网格
向量3[]顶点=m个顶点;
向量2[]uv=m.uv;
//我们将遍历网格的每个顶点
对于(int i=0;i
我的问题是:
如果需要更多的信息,我很可能会提供。这是由于视角扭曲造成的,但我对主题了解不够,无法提供答案。我已经读了一些书。好像我在这里陷得有点深了。