3
\$\begingroup\$

So am trying to create a make-up game and i need to have a basic drawing solution, and so far i have made a good progress with the help of the DepthMask solution
My approach was like this : suppose we want to edit the eyelash color (texture)

1-in the beginning there is an eyelash object at a layer named old 2-after choosing the new color that we will draw with, a new game object is created under the first eyelash, which mean it's invisible for the moment 3-then when we start drawing, we are actually creating little circles above the old eye lash, these circles contain the depthMask shader which effect the old eyeLash and give the impression that we are drawing with the new color

So far, everything is going great, my problem is that i cannot use this approach to use a 3rd color, suppose the player want to create an eyelash with mixed color, how can i do that with the previous solution ? or is it impossible to do ?

EDIT: I already thought about adding new layers with each new color, and it works, but since unity is limited to 31 layers, this solution can never be a good one.

I really hope someone can answer this, and if you know a better way to do it then please don't hesitate to tell me.

EDIT2: After a couple of hours, i've reached a pretty cool result, and i think that this can be the good way to reach my goal, this script allow to replace a specific pixel in a material texture with another chosen texture (target texture must be in the same size, and readable)

// the texture that i will paint with 
public Texture2D targetTexture ;
//temporary texture
Texture2D tmpTexture;


void Start ()
{
        //setting temp texture width and height 
        tmpTexture = new Texture2D (targetTexture.width, targetTexture.height);

        for (int y =0; y<tmpTexture.height; y++) {
                for (int x = 0; x<tmpTexture.width; x++) {
                        //filling the temporary texture with the target texture
                        tmpTexture.SetPixel (x, y, targetTexture.GetPixel (x, y));
                }
        }
        //Apply 
        tmpTexture.Apply ();
        //change the object main texture 
        renderer.material.mainTexture = tmpTexture;


}

Now i think that the problem will only be, "how to know which pixel i should replace based on mouse position over the object ?"

Thank you very much and have a great day.

\$\endgroup\$
  • \$\begingroup\$ Is it a 2D or 3D game? \$\endgroup\$ – dsilva.vinicius Jan 22 '14 at 18:12
  • \$\begingroup\$ 2D, it's a clone of this game i thought the eyebrow cutting would be the hardest part so i started with it, i finish it yesterday and now am stacked with the painting thing... \$\endgroup\$ – alaslipknot Jan 22 '14 at 18:52
  • \$\begingroup\$ The approach used in edit 2 has very poor performance. You are doing n accesses to the texture, each one changing just one pixel (n being the number of pixels). You have better changing the pixels in a fragment shader (which have all accesses parallel). To verify which pixels to change, check my answer about the spline brush and use the post processing effect described. \$\endgroup\$ – dsilva.vinicius Jan 23 '14 at 11:36
1
\$\begingroup\$

To achieve this effect you just have to verify which pixels are affected by a brush stroke and play a little with them in a post processing fragment shader with alpha blending enabled.

Brush stroke:

For smoothness, the brush strokes can be simulated by a spline generated using the mouse positions reported while doing the stroke.

Rendering

After updating the brush stroke, do the usual rendering of the scene using the current person face state.

Post processing

  • Acquire the sampled points in the spline and use them as centers for circles. You can as well get other points in the spline with better displacement to ensure a good distribution.
  • For each pixel verify if it is inside the radius of any circle.
  • If this is true, assign an alpha value for that pixel and use usual alpha blending with the current scene texture generated before post processing. This step will mix the colours of the brush and the face.
\$\endgroup\$
  • \$\begingroup\$ Hi, thank you for your help, please check 2nd update \$\endgroup\$ – alaslipknot Jan 22 '14 at 23:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.