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 Aladine · Jan 12, 2014 at 02:52 PM · 2dshadertexturecolormask

is it possible to make 2d real time coloring with masks (paint app)

Hello everyone,

So it comes up that i need to make a make-up game for girls, and one of the thing that am really stacked with is how to color a certain part of an object without effecting other objects, before explaining a little bit more, please watch 10 seconds of this video from the given time, as you can see when he is applying the blue color to the eyelashes, it appears like he is coloring it "step by step" for now the only solution that i can think about in unity is to break the eyelashes to more than one object and each time a user touch an object it get colored. But i want to know if there is a better solution for this ? if i have to make this in flash for example, i would add a mask in the eyelash layer that only make the eyelash shape visible and simply draw over it, any chance to make such a thing in unity ? thank you

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

1 Reply

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

Answer by robertbu · Jan 12, 2014 at 05:58 PM

You could use Texture2D.GetPixels32() and Texture2D.SetPixels32() to get and set pixels of the texture. You could also use some sort of a second texture to define one or more masks for the setting of color. Note that modifying the pixels of a texture requires the texture to be marked as read/write which doubles the amount of texture memory required for a specific texture. In addition, the operation to set pixels requires that you copy all the pixels for the texture making the operation slower than native texture setting methods. I think you would be okay for most platforms, but you'll have to do a performance test on your target platform. Note there are various examples of painting using Unity around, so I'd Google a bit and take a look at some example code.

Comment
Add comment · Show 8 · 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 Aladine · Jan 12, 2014 at 06:03 PM 0
Share

thank you for revealing get and set Pixels32(), i hope they are not over-complicated to use otherwise i'll stick to my first approach since am not making a real paint application, about that, i looked for unity paint examples and unfortunately i wasn't lucky enough to find a good example, would you please post a link for that ? thank you

avatar image robertbu · Jan 12, 2014 at 06:26 PM 1
Share

Here is one project I took a look at the when I was researching painting:

http://www.arongranberg.com/unity/unitypaint/

This is an older project, so I don't know if it will compile for the latest version of Unity. Figuring out Get and Set pixels will take a bit of work. You have a few challenges.

  • Figuring out what pixels to change. You can use the Raycast.textureCoord to figure out the center of where the person is dragging and clicking, but you will still have figure out which pixels beyond the center get changed. This could be based on distance and/or based on the mask.

  • The array's returned by Get/Set Pixels32 are 1D, so you have to calculate the 2D coordinates yourself.

avatar image Aladine · Jan 12, 2014 at 06:32 PM 0
Share

Yes i found that project and i thought it's a little bit old too, i'll give it a try anyway,thanx.

And the pixels manipulation seems more expensive than expected (in term of performance, and coding) specially for this project so i'll keep to working with my first method hoping that i have a decent "drawing" effect. thanx again.

avatar image Aladine · Jan 22, 2014 at 07:49 PM 0
Share

hey @robertbu i think it comes down to use one of setPixel solution, cause as i explained it here the masking approach seems to be a very bad solution, my question to you is, is it possible to draw with texture ?? for example, suppose you have 2 exact same size circles that have the exact same size texture but with different motifs, is it possible to draw on the first texture using pixel with the same coordinate from the 2nd texture ? if yes, can you please explain it more and show some examples (in c#) i will REALLY appreciate that, thank you

avatar image robertbu · Jan 22, 2014 at 07:57 PM 0
Share

I don't have any special knowledge here, but I could work it out. It looks straight forward. Unfortunately I won't be back at my desk for a week. You can either open this as a new question, or you bump this question in a week and I'll take a look.

Show more comments

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

20 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

Related Questions

Rewrite simple alphamask fixed function shader to surface or cg shader 2 Answers

Materials are colored differently on rotated objects 1 Answer

Sprite masking 3 Answers

Texture Takes Main Color of Material 1 Answer

Shader to apply Alpha to other images 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