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 /
This question was closed Nov 02, 2013 at 06:38 AM by Fornoreason1000 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Fornoreason1000 · Apr 27, 2013 at 04:43 PM · c#guitexture

How to gradient-wise fill a bitmap programmatically

I'll be using this for GUI purposes, to allow the user customization of colors of the GUI, the HP bars and other gauges are Gradients. using Set pixels a millions times in a loop is far too slow. I want the Player to define two colors using RGB sliders, with normal GUI i can just tint the color setting but this will not work with gradients.

is there any efficient way i could achieve this? Its similar to the FFVII window background color customization but an overlay of what already there.

Comment
Add comment · Show 4
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 Eric5h5 · Apr 27, 2013 at 10:06 PM 0
Share

Why would you use SetPixel millions of times in a loop? A gradient texture is just 2 pixels.

avatar image Fornoreason1000 · Apr 28, 2013 at 04:02 AM 0
Share

I tried using 2 pixels, but when I stretched to about 180x16 pixels you'd have two separate rectangles of solid color.

@Fattie So using an overlay of two gradients? that seems logical. so all i need is two black/gray to blank gradients, and adjust there color.

avatar image Eric5h5 · Apr 28, 2013 at 04:11 AM 3
Share

No, you just use bilinear filtering, and 2 pixels can be stretched to anything and will result in a smooth gradient.

avatar image Fattie · Apr 28, 2013 at 05:36 AM 0
Share

What a great tip !!!!!!!!!!!

1 Reply

  • Sort: 
avatar image
2
Best Answer

Answer by Fornoreason1000 · Apr 28, 2013 at 05:00 AM

This seems to do the trick.

  Texture2D a = new Texture2D(2,1);
                 a.SetPixel(1, 1, color1);
                 a.SetPixel(2, 1, color2);
                 a.filterMode = FilterMode.Bilinear;
                 a.wrapMode = TextureWrapMode.Clamp;
                 a.Apply();
                 GUI.DrawTexture(new Rect(x, gague_y, width, 16), a);
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

Follow this Question

Answers Answers and Comments

15 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

Texture2D not showing in build, but shows up in editor 1 Answer

How can i show number of lives as image during gameplay 1 Answer

Equivelant of GUI.DrawSprite() ? 0 Answers

null texture passed to GUI.DrawTexture 0 Answers

how to display the damage value from a mob 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