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 Piesk · Sep 23, 2013 at 03:01 PM · pixel-lighting

I want to change the alpha of individual pixels on a texture based on a particle effect

So I have a texture, to be able to visualise the problem a bit more let's say it is a solid vertical blue rectangle.

What i want to do is have it start off invisible (0 alpha), then i'd like it to start becoming visible from the top and crawl downwards, imagine nannites crawling down it and eating a layer of dirt off the top as they go so it becomes visible where they are... that kind of thing.

My first thought was to try and use a particle effect, setting the alpha of any pixel that has a particle over it to 1.

So i guess what i'm really asking is, is it possible to edit alpha levels of a texture pixel by pixel. And can you tell it to detect if there is a particle there and react to that?

Many thanks

Comment
Add comment · Show 11
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 Piesk · Sep 24, 2013 at 09:14 AM 0
Share

After doing a fair bit of research into different methods i discovered how to use a clipping mask by writing a fairly basic shader. I can use that to do a simplified version if it comes to it but i would really like to have more of a random effect.

In order to do that i'm intending to use get pixel and set pixel in order to change alpha levels based on those of pixels around that pixel in question. However documentation on get and set pixel is 1) only in US rather than c# and 2) not commented/explained very well.

Could any one help me understand how to use them? Just to clarify:

I want to check the alpha of a pixel adjacent to current pixel, and then set current pixel's alpha dependent on that.

avatar image Hoeloe · Sep 24, 2013 at 09:16 AM 0
Share

If possible, avoid using get/set pixel. It's fine if you're using it once or twice, but it's very, very expensive, so using it continuously like you're planning could be extremely slow. You can probably achieve this entire effect within a shader, though it would be a little more complex than what you have at the moment.

avatar image Piesk · Sep 24, 2013 at 11:32 AM 0
Share

yeah i was a little concerned about that, i'm intending to try and make it cheaper by only checking the "next" row of pixels as it were ins$$anonymous$$d of all pixels on each pass, and using getpixels to check all adjacent pixels at once rather than doing each individually... do you think this would be enough?

$$anonymous$$y problem is that I have absolutely no idea where to start with shaders, I haven't looked at them before now. And the last one i tried looked pretty much like nonsense, I didn't really understand what it was doing.

avatar image Hoeloe · Sep 24, 2013 at 11:46 AM 0
Share

It depends. If you're ai$$anonymous$$g for mobile, then no. Low-end PCs, maybe not, but you're probably fine if you're ai$$anonymous$$g for a decent PC. Shaders aren't too tricky to learn, though. I managed to learn most of the basics of vertex and surface shaders in about a week, it just takes a bit of trial and error, and internet tutorials. Generally, when working with pixel data as a texture, shaders are the way to go.

avatar image Piesk · Sep 24, 2013 at 11:51 AM 0
Share

I am experimenting a little at the moment trying to use get and set pixels to accomplish what is needed. But for some reason the following code seems to be doing absolutely nothing, the material is still completely visible:

 // Use this for initialization
     void Start () {
         
         //store texture being used
         texture = (Texture2D)renderer.material.mainTexture;
         
         //store color data for all pixels in texture
         Color [] textureColors = texture.GetPixels(0,0,texture.width,texture.height);
         
         //set all pixel's alpha channel to 0
         for(int index = 0; index< textureColors.Length; index++)
         {
             textureColors[index].a = 0;    
         }
         
         //set textures pixels using new colors
         texture.SetPixels(0,0,texture.width,texture.height,textureColors);
         
         //update renderer's material to edited texture
         renderer.material.mainTexture = texture;
         
     }

can any one help me with this? Why is this not setting the alpha to 0? thanks guys.

ps. Thanks hoeloe i may well look into shaders then.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by inewland · Nov 16, 2013 at 10:24 PM

You need to do texture.Apply() after SetPixel()!

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

18 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

Related Questions

Switch default diffuse light to vertex-light 0 Answers

Unity changes pixel colors 2 Answers

Does pixel shaders behave like vertex shaders when pixel light count is set to 0 from quality settings ? 1 Answer

Point Lights and fullforwardshadows 0 Answers

Can I change tile colours depending on proximity to the player? 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