sugi-cho / Animation-Texture-Baker

頂点の位置と法線を、Texture2Dに保存しておく。ARGBFloatとか、HDR Textureを使用したバージョン
MIT License
786 stars 110 forks source link

Why vid + 0.5 #1

Closed litefeel closed 6 years ago

litefeel commented 6 years ago

https://github.com/sugi-cho/Animation-Texture-Baker/blob/cec8861d88f757f9b9f21ee300f823e76b78cec7/Assets/AnimationBaker/Shaders/TextureAnimPlayer.shader#L52

Hello. thanks for your code. I read your code and it works perfectly. now. I don’t understand a bit.

float x = (vid + 0.5) * ts.x;

vid(SV_VertexID) is the index of vertex. it's 0, 1, 2, 3 .... (vertexCount - 1) ts.x is 1 / textureWidth

my question: why vid + 0.5?

Please give me a hint. thanks.

sugi-cho commented 6 years ago

hi, good question.

using texture.filterMode = Bilinear for interpolation of each frames. The y direction may be interpolated, but the x direction needs to be the center of the texel.

uv.x = (vid + 0.5) / textureWidth is center value of texel, which is position of vertex.