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
1
Question by dissidently · Mar 09, 2011 at 01:13 PM · shadertexturematerialproceduralgradient

is there a way to make a gradient material, white to black, in Unity3D?

Assuming a model has UV's already setup, is there a way to "create" procedurally or otherwise, in Unity3d, a gradient material without using a texture?

Here's an example of a gradient ramp: http://www.secondpicture.com/tutorials/3d/gradient_ramp_parameters.png

Or do I need to create a texture, import it and apply it to the model?

Comment
Add comment · Show 2
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 Jessy · Mar 09, 2011 at 01:51 PM 2
Share

Statement is pointing you in the right direction, but I don't see why you can't just model the vert colors.

avatar image Statement · Mar 09, 2011 at 02:03 PM 0
Share

That's right. One overlooks the easiest solutions easily. :)

2 Replies

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

Answer by Statement · Mar 09, 2011 at 01:24 PM

You can create a material procedurally without textures by writing your own shaders. That way, you'll be working primarily with vertex positions, normals, uvs, colors and calling different arithmetic functions that are interpolated across the surface.

For example, you could do the ramp along your uv.x or uv.y. Just interpolate a color using the value from the uv map.

Or even more simple, depending on your needs, just set the Mesh.colors to the colors instead and use a shader that makes use of colors (I think the built in ones do, but I am not 100% sure - try it out!). Otherwise you can check out this shader.

  • Edit: The link I provided actually says:

    (Note that most builtin shaders don't display vertex colors, you can use eg. a particle shader to see vertex colors)

Here, each color represents a vertex in your mesh. This color is interpolated across the surface of the neighboring triangles automatically, just like texture coordinates or normals.

Editing the example from Mesh.colors could yield:

 // Unityscript converted to C#
 void Start ()
 {
     var mesh = GetComponent<MeshFilter>().mesh;
     var uv = mesh.uv;
     var colors = new Color[uv.Length];
     
     // Instead if vertex.y we use uv.x
     for (var i = 0; i < uv.Length;i++)
         colors[i] = Color.Lerp(Color.red, Color.green, uv[i].x); 
     
     mesh.colors = colors;
 }

I tested this with a particle material and it seems to work fine.

Comment
Add comment · Show 1 · 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 Chris12345 · Jul 21, 2015 at 07:28 PM 0
Share

Can you convert this to C# I am having troubles?

avatar image
-2

Answer by Clonus · Nov 15, 2017 at 12:31 PM

void Start () {

     var mesh = GetComponent<MeshFilter>().mesh;

    Vector2[] uv = mesh.uv;

     Color[] colors = new Color[uv.Length];

     for (var i = 0; i< uv.Length; i++)
         colors[i] = Color.Lerp(Color.red, Color.green, uv[i].x);

     mesh.colors = colors;

 }
Comment
Add comment · 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

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

1 Person is following this question.

avatar image

Related Questions

procedurally generated gradient 2 Answers

How to avoid Texture.Apply() 1 Answer

Cutout Material is not showing texture transparency? 0 Answers

2 materials/shaders 1 texture? 2 Answers

Textures not showing up 0 Answers


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