- Home /
Blurring a generated alpha mask
I tried all day to get this work.
So instead of using tilemaps, I want to generate a layer mask for every texture layer which then gets put onto the ground. I managed to generate those layer masks based on the state of a tileGrid (which can change any moment in the game, therefore I want to generate the ground texture on demand)
Problem is, that I can't manage to blur the layermasks. I tried different approaches. I put all my alpha values (8bit) in a 2d-byte field and tried applying various blur algorithms myself, but apparently I lack the skills to implement/copypaste box or gaussian blur myself, because the layermasks always turned black or didn't change at all.
Next, I tried to save the layermasks into a Texture2D. I red somewhere that you can use the mip map technique to blur a texture. But that didn't work either. All attempts to resize and scale back up a layermask turned it to a black texture with 50% alpha channel and I can't track down the error.
Is there any cheap way I didn't find yet which can generate me a blurred version of a heightmap/alphachannel?
You may want to pastebin and link some code. Easier to help.
That was the problem, thanks. I reordered the code and it works with box blur. I had to implement it myself, blurring a Texture2D Source into a Texture2D target. Sad that there is no out-of-the-box mechanism available because it seems rather slow the way I did it :(
slow the way I did it :(
Hmm, do you need to recompute it every time? Perhaps you could generate a dozen or so alpha textures, at startup only, and randomly select one of those when needed.
Answer by Glurth · Mar 14, 2015 at 03:39 PM
I put all my alpha values (8bit) in a 2d-byte field and tried applying various blur algorithms...copypaste ... the layermasks always turned black or didn't change at all.
regarding copy/pasting the code for the blur: I suspect/guess the algorithm uses a float value between 0 and 1 to represent the alpha. If you are using 0-255 (8bit), this is going to yield incorrect results. You will need to scale the 8bit number down to 0-1: float alpha= ((float)Alpha8bit)/255.0f;
Your answer
![](https://koobas.hobune.stream/wayback/20220613190048im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How to procedurally generate a super simple terrain 1 Answer
Renderer on object disabled after level reload 1 Answer
MipMapBias alternative for Android? 1 Answer