x


is this a mipmap problem?

Hi, I have this function where I add a alpha channel to a texture - and then use the shader downbelow on the texture. This works fine until I scale the object to a smaller size, why is this? - When I down scale the texture then the alpha I just add'd is not working and the start texture is displayed without the alpha.

thanks,

/Joe

Add alpha to texture

enter code here
Texture2D addAlphaToTexture(Texture2D texture, Texture2D alphaTexture){

    Color[] textureColorArray = new Color[texture.width*texture.height];
    textureColorArray = texture.GetPixels(0);

    Color[] alphaArray = new Color[alphaTexture.width*alphaTexture.height];
    alphaArray = alphaTexture.GetPixels();

    Color[] mixedColorArray = new Color[texture.width*texture.height];

    for(int joe = 0; joe < textureColorArray.Length; joe++){

       if(alphaArray[joe].a != 0){
         mixedColorArray[joe] = textureColorArray[joe];
       }
    }

    texture.SetPixels( mixedColorArray, 0);    
    texture.Apply(false);
    return texture;
}

AlphaSelfIllum Shader

enter code here
Shader "AlphaSelfIllum" {
Properties {
    _Color ("Color Tint", Color) = (1,1,1,1)
    _MainTex ("SelfIllum Color (RGB) Alpha (A)", 2D) = "white"
}
Category {
   Lighting On
   ZWrite Off
   Cull Back
   Blend SrcAlpha OneMinusSrcAlpha
   Tags {Queue=Transparent}
   SubShader {
        Material {
           Emission [_Color]
        }
        Pass {
           SetTexture [_MainTex] {
                  Combine Texture * Primary, Texture * Primary
            }
        }
    } 
}

}

more ▼

asked Feb 01 '12 at 08:29 PM

TenCommander gravatar image

TenCommander
38 4 5 10

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Solution

I found a solution, it was just to use a texture without mipmaps on the function like this

enter code here
Texture2D texture = new Texture2D(x, y, TextureFormat.ARGB32, false); 

Thanks to me self.

more ▼

answered Feb 02 '12 at 12:08 PM

TenCommander gravatar image

TenCommander
38 4 5 10

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x353
x286
x22

asked: Feb 01 '12 at 08:29 PM

Seen: 485 times

Last Updated: Feb 02 '12 at 12:08 PM