Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Bug Unity .FBX Vertex Color import error?

Discussion in 'Asset Importing & Exporting' started by Reed_Bird, Jul 27, 2022.

  1. Reed_Bird

    Reed_Bird

    Joined:
    Aug 9, 2020
    Posts:
    4
    Hi, I created a shader that takes a texture atlas and can render multiple textures from that atlas onto a single mesh in one pass. The way I do this is by setting the model's vertex colors so I can use the rgb values inside the shader and transform the model's uvs, using those values to make it loop on the specific part of the texture atlas I want that piece of geometry to have.

    However, there seems to be a very tiny error from importing the model, causing the vertex colors to be slightly different than as they were set. This causes other textures to bleed in. I am using Blender 2.79a, and exported the model as an .fbx (I imported into a Unity 2021.2.3f1 Personal project). Some of the vertex colors are the same as they were in blender (for example, rgba(0.5, 0.0, 0.5, 1.0)) but then others were off by 0.002 (for example rgba(0.502, 0.0, 0.502, 1.0)). This could happen on any value that was set greater than zero (in this case, the only values that were set were the rgb values and they were all set to 0.5 or 0.0 due to a 2x2 texture atlas)

    What can I do to prevent this error from occurring?

    I know it is not my shader that is wrong, as I was able to directly modify the mesh's vertex colors using a script, which made the level seamless. Here is a before and after of that script: before.PNG after.PNG
     
  2. Reed_Bird

    Reed_Bird

    Joined:
    Aug 9, 2020
    Posts:
    4
    This difference occurred on ~33 vertices out of 255 vertices
     
  3. Reed_Bird

    Reed_Bird

    Joined:
    Aug 9, 2020
    Posts:
    4
    I was able to make a workaround, but I would prefer to not to have to use it. The two attached scripts can update the vertex colors of the selected model in the editor. One of the scripts creates a window for the editor accessible from Windows>Clamp Vertex Colors. The variable "Default Value" is one of the values you set the vertex colors to (for example, I used the value 0.5 in the rgb channels of the vertex colors so I set "Default Value" to 0.5). The value "errorcheck" is how different the currently checked r/g/b value can be before it is considered the same value as "Default Value" (So for example, if I used an "errorcheck" value of 0.01, |0.5 - 0.504| = 0.004. 0.004 <= 0.01, which means the r/g/b value of 0.504 will be set to 0.5.). Press the button in the window to set the vertex colors. So you can do this to every single vertex color value that you have used or the ones that are incorrect. Be careful, however: the script does not allow undo-ing unfortunately.
     

    Attached Files:

  4. Reed_Bird

    Reed_Bird

    Joined:
    Aug 9, 2020
    Posts:
    4