Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Takkun · Dec 13, 2012 at 05:29 PM · shadermaterialvertexcolorvertex-lit

Creating models with color only, from script

Hello, this is my first question on unity answers.

I am trying to create a model from script using the Mesh class, and represent each face with a separate color. I have a mesh filter, and a renderer attached to the game object. At the moment, it is a simple cube.

My problem is that I can not find out how to properly set these colors I desire. I have read about Mesh.colors and colors32, but none of the shaders will show these colors. Only the GUI/Text shader has been successful in getting close to what I'm looking for. The cube, upon creation turns grey, such as when you have an object without a material.

When I import a model as normal, Unity automatically creates as many materials as needed by the file, a unique material for each color. This would be great, if I was importing models, but I'm making procedural meshes. And even if I create several materials from code, applying them to the Cube does nothing to tell it which faces I want colored, and it only shows one of the materials anyway.

This troubles me, because I may want non-textured models to be loaded from an outside source (for example, user generated content, or a storage cache outside the unity folder), but it seems that even with a custom loader written, Unity does not expose the methods of applying these colors properly, and mostly gives support for skinned/uv models imported into the editor. This seems backwards to me, because with raw opengl, I can support solid colors easier than a texturing/uv system. However, I really enjoy Unity, and for all other aspects love it's rendering engine, so I'd like to be able to use it for my projects instead of deploying my own engine.

Let me note, I do not want to use textures at all, I'm purposely attempting to use vertex colored models. An example of the art style would be Mario 64, or the old runescape models. In those games, the characters and some world geometry used simple vertex colors, and any texturing was solely for detail effects.

Is there any way to accomplish what I want? It may be a product of me missing a critical documentation piece, and if so, would you please point me in the right direction? Thank you in advance for reading this question.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Eric5h5 · Dec 13, 2012 at 06:43 PM

You need a shader that uses vertex colors in order to use Mesh.colors. Most of the built-in shaders do not, so you can either find and download one that does, or make your own (see here for shader source).

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Takkun · Dec 13, 2012 at 06:52 PM 0
Share

If that is the case, how does Unity internally apply several material colors when you import a model from an external app? Is this feature not exposed to the scripting library? Thanks again

avatar image Eric5h5 · Dec 13, 2012 at 08:02 PM 0
Share

Not really sure what you mean. Vertex colors in an imported model will not show up unless you use a shader that has vertex color support. $$anonymous$$aterials and shaders are two different things.

avatar image Takkun · Dec 13, 2012 at 08:11 PM 0
Share

$$anonymous$$y apologies, I believe I am confusing the term material between blender and unity. When I assign two separate "materials" in blender, all I'm actually doing is setting it to vertex lit, with two separate colors being assigned to whichever verts I specify. Checking the model file, it is storing this. In unity, it somehow converts these to Unity materials, which appear to be different in nature, but in the conversion process, it is retaining my selection of verts to color. However, this seems to be a oneway process, and I can not modify these colors after the fact, doing so breaks the linkage and just colors the entire mesh with the last applied unity material. I was asking is there anyway to access this behind the scenes process that unity does, so that I can modify these imported "blender materials" in Unity, but after your answers, and more googling on the subject, I think that there may not actually be an easy way. Of course, I could always just remodel and reimport back into unity to fix these, but this only works if I'm using the assets in the project folder, not if I am dynamically loading assets from a folder cache or the web.

Thank you for your interest in helping me understand.

avatar image Takkun · Dec 13, 2012 at 08:47 PM 0
Share

After stewing on my thoughts for a moment, and re-reading what you posted, I went and played around with what is called a "submesh". This achieved exactly what I was looking for in combination with Unity materials and vertex colors. Thanks for your help!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Material doesn't have a color property '_Color' 4 Answers

Blending 2 textures using vertex COLOR 0 Answers

How to catch Material doesn't have a texture property exception 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

How to get Vertex Color in a cg shader? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges