Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 martygrof3708 · Jun 03, 2019 at 02:53 PM · shadercoloreffectgradient

How can I make an animated color gradient?

I do not know how to create a shader script, but I can learn. I want to create an effect on the surface of a quad. When this effect is activated, I want 2 white gradient to start in the middle of the cube and expand outwards until it reaches the edges of the quad.

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 highpockets · Jun 03, 2019 at 09:46 PM 0
Share

Did the last attempt fail?? We’re you able to make a texture and scale it up??

avatar image martygrof3708 highpockets · Jun 03, 2019 at 09:51 PM 0
Share

Oh hi! No it didn't fail. I got it to work. The issue using a texture and scaling it up is that I don't get the full effect I want. Because I want the white fade to expand outwards, but clip at the edges. Right now it scales up and stops at the edges, but it doesn't look like it fades out, it just stops. I am looking for the white gradient to expand outwards and look like it fades out at the edges.

To be clear, the texture I made is a hollow square with an inwards alpha fade. So it looks good until it hits the edges and stops, because when it stop I can clearly see its a square and not a gradient.

Essentially, I want it to look like the gradient disappears into the edges, not just stop at them.

avatar image highpockets martygrof3708 · Jun 04, 2019 at 05:58 AM 0
Share

You can fade it out at the end. Use Color.Lerp and fade to Color.clear. Additionally, you can adjust the UV positions when you get near to where you want it to fade out, if the UVs slowly change to the middle , which is hollow space, you will not see the gradient texture anymore. Sprite.uv

Show more comments

1 Reply

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

Answer by highpockets · Jun 04, 2019 at 09:41 PM

Take a look at the Scripting API:


https://docs.unity3d.com/ScriptReference/Sprite-uv.html


Get a reference to your sprite:


 [SerializeField] Sprite sprite;
 [SerializedField] SpriteRenderer rend;

Place that in your class and assign the sprite and sprite renderer in the inspector (click on the circle beside the field to see the options of what sprites/sprite renderers you can choose)


Once you scale up the image, you can start modifying the uvs (Vector2 pixel coordinates) of the sprite with a coroutine like the below for example.


 IEnumerator ManipulateUV()
 {
 
 Vector2[] originalUV = sprite.uv;
 float timer = 0.0f;
 float speed = 0.5f;
 
 while(timer < 1.0f)
 {
 foreach(Vector2 pos in sprite.uv)
 {
 pos = Vector2.Lerp(pos, sprite.pivot, timer);
 }
 timer += Time.deltaTime * speed;
 yield return new WaitForEndOfFrame();
 }
 rend.enabled = false;
 sprite.uv = originalUV;
 }


Now just call the above with StartCoroutine(ManipulateUV()); when you want to fade out after or while you are scaling up. It is untested code, so let me know if there is an issue, but I hope you get the idea. The above will move the sprite's texture coordinates towards the center of the sprite on the texture over the period of 2 seconds and when its finished, the sprite renderer will disable and the uv coordinates will go back to normal for your next effect. One issue with this approach is that you won't be able to have 2 effects happening at once, but fading out at different times as this is changing the base texture coordinates and will affect all instances of the sprite

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 martygrof3708 · Jun 05, 2019 at 12:09 AM 0
Share

Excellent answer thank you very much.

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

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

Related Questions

How can I create a gradient color background for my game, without using skybox? 2 Answers

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

,I am Trying to make A Colored Vignette Effect and I don't know how 0 Answers

Creating this light effect 1 Answer

Rendering problem with opaque objects with the same Mat rendering through each other (Grouped to the same empty object) 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