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 post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Hamlet-Archer · Jun 05, 2015 at 01:56 PM · shadertexture2d

scratchcard type blend between two textures

we are building a scratchcard lottery type effect like in this image:

alt text

at this point, we start with a mesh with the unscratched texture (backTexture), and then we use a raycast to find the input hit point (pixelX, pixelY), and blend the scratched texture (frontTexture) in based on the distance from the hit point using Texture2D.SetPixels. i.e. something like this:

             for (int x = Mathf.Max (0, pixelX - radius); x < Mathf.Min (backTexture.width, pixelX + radius); x++) {
                 for (int y = Mathf.Max (0, pixelY - radius); y < Mathf.Min (backTexture.height, pixelY + radius); y++) {
                     float discount = (new Vector2 (pixelX - x, pixelY - y)).magnitude / (float)radius;
                     if (discount < 1f) {
                         int index = x + y * backTexture.width;
                         backPixels [index] = Color.Lerp (backPixels [index], frontPixels [index], Time.deltaTime * strength * (1f - discount));
                     } 
                 }
             }
         backTexture.SetPixels32 (backPixels);
         backTexture.Apply ();

the problem is that the performance of Texture2D.SetPixels32() and Texture2D.Apply() are too low.

we have done some research to find people suggesting a shader-based solution, where a shader with 2 materials will draw the corresponding blend of textures. unfortunately i'm afraid we know very little about shaders, and in particular, we'd appreciate help on:

  1. how to tell the shader to draw something based on pixel position, and

  2. how to set the array parameter of the shader from script.

many thanks!

maxresdefault.jpg (78.3 kB)
Comment
Add comment · Show 1
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 Hamlet-Archer · Jun 08, 2015 at 01:46 AM 0
Share

bump... any taker? would much appreciate help on this.

2 Replies

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

Answer by clever · Jun 08, 2015 at 03:43 AM

There's a shader the does a mask which can be found here: http://wiki.unity3d.com/index.php/TextureMask

Sadly you'll still have to use SetPixels to "scratch" the mask texture. One way you can limit the performance hit is to make the "scratch surface" texture rather small (like use a 256x256 or 512x512)

There's also a dissolve shader on the wiki but I haven't played around with it to see if it could help you: http://wiki.unity3d.com/index.php/Dissolve_With_Texture

Hope this helps

Comment
Add comment · Show 3 · 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 Hamlet-Archer · Jun 08, 2015 at 05:03 AM 0
Share

thanks! this is helpful. let me try a low resolution mask and see how it works. :-)

avatar image Bhargav5530 · Jul 11, 2015 at 12:12 PM 0
Share

Hey Hamlet Arche can you give me your code I am facing same problem I don't have used setPixels I have tried evertying on internet and finally I am here. can can you give me your code so that I can scratch the image. deeply thanks if you give me you code.

avatar image Hamlet-Archer · Jul 13, 2015 at 01:08 AM 0
Share

hi @bhargav, i ended up just reducing the resolution and using more or less the same codes in my original question.

avatar image
0

Answer by Patel-Sagar · Jul 13, 2015 at 11:47 AM

Hello,

Here is what you can use.

http://studio.openxcell.com/remove-dustfog-object-unity-swipe.html

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

22 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

Related Questions

Combining 2 black-white textures 2 Answers

Why is Unity generating grayscale normal maps? 0 Answers

textureQueryLod/CalculateLevelOfDetail in Fragment Shader 2 Answers

Change the color of a black sprite?,How can i change the color of a black sprite? 1 Answer

Converting a RenderTexture to a Texture2D for use in a shader 2 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