Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static Texture2D MakeAttenuationTexture(int w, float pow, float scale) {
- var bd = new Color[w * w];
- for (int i = 0; i < bd.Length; i++)
- {
- bd[i] = new Color(0,0,0,0);
- }
- /// 1.0 / (1.0 + 25.0*r*r)
- for (int x = 1; x < w - 1; x++)
- {
- for (int y = 1; y < w - 1; y++)
- {
- float actualX = 2.0f * ((float)x - ((float)w) / 2.0f) / (float)w;
- float actualY = 2.0f * ((float)y - ((float)w) / 2.0f) / (float)w;
- Vector2 vec = new Vector2(actualX, actualY);
- float distance = vec.magnitude;
- float attenuation = 1.0f / (1.0f + 25.0f * Mathf.Pow(distance, pow) * scale);
- Color c = new Color(attenuation, attenuation, attenuation, attenuation);
- bd[x + y * w] = c;
- }
- }
- Texture2D newtex = new Texture2D(w, w);
- newtex.SetPixels(bd);
- newtex.wrapMode = TextureWrapMode.Clamp;
- newtex.Apply();
- return newtex;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement