text2D at uv(0,0) get wrong result[Unity]

Case:

When use ramp textures,maybe you will get strange results when sample texture at uv(0,0)

alt text

like using the texture above, when you tex2D at uv(0,0),

float3 ramp = text2D(_RampTex,float2(0,0));

instead of getting black color you will get a white color.

And if you change the 0 to .001, you can get the correct color-black.


Reason:

Because the default wrap mode of the texture in unity is "repeat", So when sample the texture(assume the magniffication is use Bilinear Interpolation).like this



so when you texture's wrap mode setted to repeat, the sample is like this(Becuase with our ramp texture,the the color of v orientation are the same, so we just take the u orientation for example ):


so you will get the wrong result.it's the same result as sample at uv(1,0)(and the sample at uv(1,0) is wrong too)


Solution:

Just set the wrap mode of texture to "Clamp".

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页