为什么球体贴图实际上无法匹配 [英] why the sphere texture map can not actually match

查看:98
本文介绍了为什么球体贴图实际上无法匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的3d项目中有一个球体,并且有一个地球纹理,我使用的算法是 Wiki 来计算纹理坐标。
我的效果文件中的代码如下:

i have a sphere in my 3d project, and i have an earth texture, i use the algorithm from wiki to calculate the texture coordinate. the code in my effect file look like this:

float pi = 3.14159265359f;
output.uvCoords.x = 0.5 + atan2(input.normal.z, input.normal.x) / (2 * pi);
output.uvCoords.y = 0.5f - asin(input.normal.y) / pi;

结果如下图所示:


  1. 从左边看(有一条线,这是我的问题)

  1. look from left( there is a line, this is my question)

从正面看

3。从右看

推荐答案

最后我自己弄清楚了,问题出在事实上,我正在计算纹理坐标在顶点着色器中。问题在于,一个顶点在纹理的最右边,而三角形的其他两个顶点在纹理的最左边,这导致几乎整个纹理在这样的三角形上可见。因此存在一堆混乱的纹理坐标。解决方案是我应该将法线发送到像素着色器,并在像素着色器中计算纹理坐标

finally i figure it out by myself, The problem lies in the fact, that i'am calculating the texture coordinates in the vertex shader. The problem is that one vertex is on the far right of the texture, while the other 2 vertices of a triangle are on the far left of the texture, which results in almost the whole texture being visible on such a triangle. so there is a line of jumbled texture coords. the solution is i should send the normal to pixel shader and calculate the texture coord in the pixel shader

这篇关于为什么球体贴图实际上无法匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆