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 natehirsch · Mar 11, 2015 at 05:14 PM · shadermaterialgraphicsrendertexturealphamap

Set dynamic generated alpha mask on shader at runtime

Here is my end goal: to generate an alpha mask texture at runtime and be able to keep updating it and sending it to a texture's shader. Performance is a concern for me. I want to be able to take touch input and 'erase' the texture by setting the alpha to 0 in that section.

So I already have a shader and material that renders a texture with an alpha mask, and I think I just need to do myMaterial.SetTexture("_AlphaTex",myRenderTexture);

But how can I generate the RenderTexture and manually set each pixel. Will changing the texture and sending it to the shader every frame there is touch input be a performance issue? Is there a better way to achieve this effect? (I've read that Texture2D.SetPixels is super slow)

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 AlwaysSunny · Mar 11, 2015 at 05:26 PM 1
Share

So, your alpha mask is a render texture? Or are you playing fast and loose with the ter$$anonymous$$ology? ;)

In whatever case, I see you have two sensible options:

$$anonymous$$anipulate an alpha texture's Color[] array with touches or manipulate the mesh's vertex colors with touches and use a shader which respects vertex alpha.

It's my understanding that the vertex method would be somewhat more performant, simply because it's less expensive than SetPixels. Even so, frankly I'd just go with what you've got unless you find that it's a bottleneck.

$$anonymous$$eep in $$anonymous$$d that your alpha mask's resolution (or vertex density with the vertex color method) can-and-should be as sparse as possible. Writing 32x32 pixels or vertex colors is (literally!) exponentially cheaper than 256x256 or whatever.

avatar image natehirsch · Mar 11, 2015 at 05:49 PM 0
Share

Yeah I don't know all my ter$$anonymous$$ology :) this is the first time I've tried messing with anything graphics related in Unity. So how would I go about doing the mesh vertex method? Can you show me where I can access a mesh's vertex colors in code?

avatar image AlwaysSunny · Mar 11, 2015 at 06:22 PM 1
Share

Because you've already got your texture method all set up and ready to roll, you might as well stick with it. I imagine the performance discrepancy between the two methods will be negligible if your expectations (resolutions) are reasonable.

Your biggest optimizations will be keeping the operation as svelte as possible by reducing resolution, maybe even spreading your change requests over several frames.

Here's the $$anonymous$$esh API link in the docs. You can do some cool stuff so it's worth digging into, but then you'll still need to write a shader to respect vertex colors. Gotta pace yourself! ;)

http://docs.unity3d.com/ScriptReference/$$anonymous$$esh.html

avatar image natehirsch · Mar 11, 2015 at 09:23 PM 0
Share

Thanks, I'll take a look at that later and let you know how it goes!

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

RenderTexture and DrawTexture using material is not working 0 Answers

Creating a Material from shader string 2 Answers

Postprocessing effect in Oculus GO 0 Answers

Standard material shader ignoring SetFloat property "_Mode"? 1 Answer

use RenderTexture on a sphere correctly? 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