- Home /
Transparency from grayscale while in game
Is there a way to add transparency to an object while playing, from grayscale? I'm trying to use a heightmap generated from a perlin script to create a cloud effect, and i'd like to create transparency from the dark areas on the texture while in runtime.
Answer by Negagames · Jan 05, 2014 at 02:49 AM
texG.Apply();
That notoriously forgotten command... That's what I missed. Thank you for the help guys!
Answer by HappyMoo · Jan 04, 2014 at 11:20 AM
Check out the Particle Shaders like "Additive" etc.
have you tried this? Additive Shaders makes black pixel transparent and white fully visible
Answer by sparkzbarca · Jan 04, 2014 at 01:15 PM
yea easy, just use a transparency shader and then in gimp or photoshop or whatever set an alpha layer.
to change the transparency of an object in general code wise.
void ChangeAlpha(GameObject Piece, float Alpha)
{
Color TempColor = Piece.renderer.material.color;
TempColor.a = Alpha;
Piece.renderer.material.SetColor("_Color", TempColor);
}
that will take a gameobject and a value from 0 to 1 (where 0 is invisible, 1 is fully visibly and .5 is partly see through) and set a gameobject WITH a transparency shader to render transparent.
@sprkzbarca Not really what the I was asking. What I need to do is change the alpha of a texture pixel by pixel while in game. This is what I had, and it wasn't working, but it should give a better idea as to what i'm trying to accomplish:
if(modify3){
for(int x = 0; x < texG.width; x ++){
for(int y = 0; y < texG.height; y ++){
UnityEngine.Color col = new UnityEngine.Color(texG.GetPixel(x, y).r, texG.GetPixel(x, y).g, texG.GetPixel(x, y).b, texG.GetPixel(x, y).grayscale*255);
texG.SetPixel(x, y, col);
}
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613125509im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Set shader's AlphaCutoff programmatically in HDRP 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers