ryanslikesocool / Mecanim2Texture

Bake skinned mesh animations to 2D textures
MIT License
52 stars 7 forks source link

Writing to EXR yields truncated negative values #4

Open transcendtient opened 3 years ago

transcendtient commented 3 years ago

For now I'm remapping the values to positive numbers. 255 is arbitrary and causes rounding errors similar to the vertex rounding you see in playstation games. The resulting textures are "white" but contain the animation data.

float Remap(float aValue) { float normal = Mathf.InverseLerp(-255, 255, aValue); return Mathf.Lerp(0, 255, normal); } And remapping the pixel. pixel.r = Remap(position.x); pixel.g = Remap(position.y); pixel.b = Remap(position.z);

I've rewritten the ShaderGraph as a standard surface shader, and to account for this 255 value I'm doing this. position -= float3(255/2, 255/2, 255/2);

transcendtient commented 3 years ago

I realize now this is a problem with the gamma color space. Do you have any other suggestions for how to remap the values in gamma color space? My solution works, but it has at best thousandths precision due to rounding errors if I use larger scale (65535).

transcendtient commented 3 years ago

Alright the REAL solution. Save it as an asset. Unity won't mess with the data this way. You have to remove the gamma correction if you do this.

transcendtient commented 3 years ago

image