Hello Guest

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - lvictorino

Pages: [1]
1
Support / Re: Extract only sprite pixels of an Atlas
« on: February 22, 2014, 11:50:11 pm »
Sorry for my broken english, workaround wasn't the wisest word to use.
Anyway thank you very much for you help!

2
Support / Re: Extract only sprite pixels of an Atlas
« on: February 22, 2014, 06:08:28 pm »
Thanks for the answer.
I've tried the uvs workaround before seeing your post... however the results I had in sprite definitions were "weird". My atlas is 1024x1024, my sprite is 27x27 and uvs given are :
  • (0.0, 0.9)
  • [1] (0.0, 0.9)
    [2] (0.0, 1.0)
    [3] (0.0, 1.0)

    That's why I didn't work too hard on that.
    Anyway, do you plan to have that kind of feature in the next release? It could be super-handy to have that.

3
Support / Extract only sprite pixels of an Atlas
« on: February 21, 2014, 01:16:51 pm »
Hi,

I'd like to extract only the pixel informations used by the current sprite.
The idea would be to analyze colors used by a sprite, and loop through its pixels.
Unfortunately renderer.material.mainTexture returns only the atlas (1024x1024) for my 27x27 texture. GetPixels an iterating through all pixels of the atlas could be overkill. Is there a bettre way?

Thank you.

4
Support / Re: Color replacement in animations
« on: February 06, 2014, 09:14:21 am »
Just to be sure... I'll have to modify the current tk2d shader and add what I want to it in order to keep the functionalities... right? (I'm so scared by shaders)

5
Support / Re: Color replacement in animations
« on: February 06, 2014, 08:51:03 am »
A question came to me...

Wouldn't be more efficient to do the color replacement via shaders?
Do you think it could be possible / easy to work on shaders while using tk2d?

Thanks,

6
Support / Re: Color replacement in animations
« on: November 13, 2013, 02:08:34 pm »
Thanks for this quick answer.
If I understand your suggestion about sharedMaterial correctly it means that if I change the pixel value for the shareMaterial.texture it will change the pixel color for EVERY shirt of every player in the game. Am I right ?

As every player should have a different shirt color it's not what I need.

I'll go with this :
Code: [Select]
public class ColorReplace : MonoBehaviour
{
    Texture2D _modified_tex = null;

    private void RandomizeColor()
    {
        Texture2D tex = Instantiate(renderer.material.mainTexture) as Texture2D;
        renderer.material.mainTexture = tex;
        Color search = new Color(1.0f, 0.0f, 1.0f);
        Color replace = new Color(Random.value, Random.value, Random.value);
        Color[] pix = tex.GetPixels();
        for (int y = 0; y < tex.height; ++y)
        {
            for (int x = 0; x < tex.width; ++x)
            {
                if (pix[ y * tex.width + x ] == search)
                {
                    pix[ y * tex.width + x ] = replace;
                }
            }
        }
        tex.SetPixels(pix);
        tex.Apply();
        _modified_tex = tex;
    }

    private void Awake()
    {
        RandomizeColor();
        GetComponent<tk2dBaseSprite>().SpriteChanged += ColorReplace_SpriteChanged;
    }

    void ColorReplace_SpriteChanged(tk2dBaseSprite obj)
    {
        renderer.material.mainTexture = _modified_tex;
    }
}

Then, the pixel change will be compute only once and saved for every player. And as you suggested it I swap the texture every time the animator change the material.
What do you think? Does it look correct to you?

Thanks again for your answer.

7
Support / Color replacement in animations
« on: November 13, 2013, 07:21:22 am »
Hi,

I'm trying to do some color replacement for player customization purpose.
I want the player to be able to choose the color of his avatar. Imagine a sprite of a football player, I want to change the shirt color only.
I've been looking at some "green screen" technique, where the initial shirt color would be of a color I don't use (full green, or full pink), and then use Unity3D GetPixels / SetPixels to replace only pixels of this specific color with the one chosen by players.

It works fine with static sprites. But I wonder how to perform such replacement with sprite animation?

Also, if you have any better idea on how to perform such color replacement, please share it :)

Here is the code I use so far :

Code: [Select]
    private void Awake()
    {
        Texture2D tex = Instantiate(renderer.material.mainTexture) as Texture2D; // I guess it's because animator doesn't use mainTexture.
        renderer.material.mainTexture = tex;
        Color search = new Color(1.0f, 0.0f, 1.0f); // looking for pink color
        Color replace = new Color(Random.value, Random.value, Random.value); // changing it by a random color
        for (int y = 0; y < tex.height; ++y)
        {
            for (int x = 0; x < tex.width; ++x)
            {
                if (tex.GetPixel(x, y) == search)
                {
                    tex.SetPixel(x, y, replace);
                }
            }
        }
        tex.Apply();
    }

Thanks for your help

Pages: [1]