Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 rhrao · Aug 06, 2014 at 06:37 PM · shadertexturematerialgraphicseffect

Tracing in Unity3D

Hello all!

Let me preface this by saying that I'm no expert in game development or graphic programming.

Now that that's settled; we've made a 2D game in Unity(4.5) free version. We've a feature, wherein you can trace a specific shape.

The shape is provided in the form of an image (a black shape on a transparent background), like this: sample image

Then I've imported this image as a Texture2D, and applied it on a Gameobject (a fixed size plane, saved as a prefab) using the default Sprites Shader. Basically, I want the black area of the shape to be replaced by white (or any other color). Only the black area is traceable. The idea is that the user can move on to the next step, once he/she traces the entire shape. The user has an on-screen cursor that he/she uses to trace the shape. The tracing can only be done in a specific direction.

I've currently achieved this by using GetPixels and SetPixels method of Texture2D, and checking whether all the pixels no longer black. To enforce direction, and also to not have jitter (and prevent redundantly checking every frame whether each pixel is no longer black, for the entire image), I've divided the shape into sectors, so that only pixels of one sector get checked before moving on to the next sector.

Now, although this "does" what I want, it's not as good looking! :(

Also all the sectors are square/rectangular in shape, so all curves look weird while tracing.

Is there some other way I can do this/a better way to do this? I had heard about using custom shaders, but wasn't sure if that's the right path.

Anyways, any help will be greatly appreciated. Thanks all!

exampleshape.jpg (478.9 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 vvyrone · Jan 18, 2016 at 02:21 PM 0
Share

@rhrao can u $$anonymous$$ch me what did u do to create a trace. in my case i am creating a trace the number can u share your knowledge tnx ..

1 Reply

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

Answer by robertbu · Aug 06, 2014 at 06:58 PM

What comes to mind is using a shader with an alpha cutoff mask. For example take a look at this answer:

  [http://answers.unity3d.com/questions/14770/creating-a-circular-progressbar-timer.html][1]

They are using the shader for a circle, but it can be used for any shape. You just need to define the mask. You would need to keep track of how far along the shape the user is. This could be done by an array of waypoints. You would set the blend of the shader to that fraction.

[1]: http://answers.unity3d.com/questions/14770/creating-a-circular-progressbar-timer.html

Comment
Add comment · Show 2 · 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 rhrao · Aug 06, 2014 at 09:18 PM 0
Share

Thanks! Hmm - so basically, I'd have to have an alpha gradient version of my shape with the gradient following the direction of tracing (so as to unveil it appropriately). And under the alpha gradient shape, I'd need the actual, "untraced" version of the shape.

Cool, I'll be trying this out tomorrow, and will mark your answer as correct if that works! :) Thanks again!

avatar image rhrao · Aug 07, 2014 at 07:03 PM 0
Share

Oh this was perfect! Thanks a bunch! I just tried it out and I have the exact effect that I'm looking for. I'm using an array of invisible gameObjects as triggers to enforce direction and detect completion, but all in all, this is perfect!

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How can I prevent lights overlapping in intensity? 1 Answer

How to blend colors from two texture maps in VFX graph 1 Answer

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

use RenderTexture on a sphere correctly? 1 Answer

How can I pan a texture to specific location on a sheet? 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