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:

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! :frowning:

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!

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.