- Home /
Importing .obj files with RGB data
I want to import and render a .obj file in Unity. The vertices in the .obj file also have RGB data associated with them. I know how to import and render the .obj, but I don't know how to texture it with the correct RGB data. Can anyone help?
Thanks!
To "see" vertex colors, you'll need to use a shader which respects vertex color. I don't believe any of the stock legacy shaders do this, though I could be mistaken. This is not called "texture"-ing the model with vertex colors. You should avoid referring to making use of vertex colors in this way using the word "texture", since the two are unrelated.
To make use of this data in some other way, the $$anonymous$$esh class API exposes vertex colors.
If you are not referring to vertex colors, please refine your question.
Answer by tanoshimi · Mar 12, 2015 at 06:49 AM
@AlwaysSunny is correct; to render vertex colours assigned to a mesh, you need to assign a shader to the material that makes use of them. The built-in "VertexLit" shader will do just fine (in Unity 5 you'll find it under Legacy Shaders/VertexLit)
Thanks for the suggestion! I have created a new GameObject, added a $$anonymous$$eshFilter with my mesh, and added a $$anonymous$$eshRenderer with a new $$anonymous$$aterial that has a VertexLit shader. Can you help me figure out the next step? Do I need to add a script to my GameObject that sets the colors of every vertex in my mesh to the values in my .obj file? Do I need to do this in the actual shader?
Thanks!
I don't remember VertexLit respecting vertex colors, but @Tanoshimi's word is law 'round these parts, so I may be misremembering.
If you are entirely confident that your vertex colors were properly edited in your 3D program, perhaps there's some other factor at work I am not considering. No additional steps need to be taken - if your imported model has vertex colors, and your shader respects vertex colors, you'll see the result immediately.
Oh dear, I'm beginning to doubt myself now, but am not near a computer to be able to test...! Try creating a new shader and assigning it to the material as follows:
Shader "VertexLit Coloured" {
Properties { _Color ("$$anonymous$$ain Colour", Color) = (1,1,1,1) }
SubShader {
CGPROGRA$$anonymous$$
#pragma surface surf Lambert
struct Input { float4 color : COLOR; };
uniform fixed4 _Color;
void surf(Input IN, inout SurfaceOutput o) {
o.Albedo = IN.color.rgb;
o.Alpha = 1;
}
ENDCG
}
}
Was someone able to get this to work? Is there a way do make Unity use .obj files with Vertex Colors, like $$anonymous$$eshLab exports them?
Your answer
![](https://koobas.hobune.stream/wayback/20220613185851im_/https://answers.unity.com/themes/thub/images/avi.jpg)