- Home /
How to apply a bool[] to a texture?
For my fog of war system, I have an array of booleans that determines what color each pixel of the texture is How can I set the texture based on this array of booleans? Do I have to iterate through every bool to set the individual pixels of the texture?
Answer by Jessespike · Feb 23, 2015 at 07:12 AM
Yes, you'll have to iterate through the texture and bool array to determine result.
http://docs.unity3d.com/ScriptReference/Texture2D.SetPixel.html
Thanks for the answer. I did some more snooping around and found SetPixels nearby. I think this is the right choice for me to get a Texture2D but I'm still having trouble getting it onto a plane for the visualization.
Answer by hexagonius · Feb 23, 2015 at 07:13 AM
For per pixel coloring, you need a fragment shader. I'm not sure if it is possible to pass in arrays, but you could transform your bool array to s texture 2D and pass that in.
Oh and you could do a postprocess effect
Still, an iteration would be need to know what to shade and what not to shade.
ah, true. I looked into Texture2D and it has a neat SetPixel method. Ins$$anonymous$$d of a bool[], I'll use a byte[] which will work with it. Now I need to find a way to get it into a shader. Sorry I don't have much experience with them. Could you explain how to apply a Texture2D to a 'fragment shader'?
Your answer
Follow this Question
Related Questions
Get texture pixels under a plane 1 Answer
get pixel from a texture 1 Answer
Perfect 2d image 1 Answer
Texture Quality VS (Sprite 2D and UI) Quality 1 Answer
Analyse Textures first pixel 1 Answer