public static void ApplyStains(this ColorData baseData, string part, bool flipH, bool flipV, float px = -1f, float py = -1f) { var stainData = GraphicsDatabase.GetColorData(part, null); var baseRect = baseData.rect; var stainWidth = stainData.width; var stainHeight = stainData.height; var x = (int)(baseRect.x + (baseRect.width - stainWidth) * (px != -1f ? px : Rand.Value)); var y = (int)(baseRect.y + (baseRect.height - stainHeight) * (py != -1f ? py : Rand.Value)); var oPixels = baseData.GetRawPixels(x, y, stainWidth, stainHeight); var pPixels = stainData.pixels; for (int sx = 0; sx < stainWidth; sx++) { for (int sy = 0; sy < stainHeight; sy++) { var pIdx = (flipH ? (stainWidth - sx - 1) : sx) + (flipV ? (stainHeight - sy - 1) : sy) * stainWidth; var oIdx = sx + sy * stainWidth; var oa = oPixels[oIdx].a; var a = pPixels[pIdx].a * oa; if (oa * (oPixels[oIdx].r + oPixels[oIdx].g + oPixels[oIdx].b) > 0.05f) { oPixels[oIdx].r = oPixels[oIdx].r * (1 - a) + pPixels[pIdx].r * a; oPixels[oIdx].g = oPixels[oIdx].g * (1 - a) + pPixels[pIdx].g * a; oPixels[oIdx].b = oPixels[oIdx].b * (1 - a) + pPixels[pIdx].b * a; } } } baseData.SetPixels(x, y, new ColorData(stainWidth, stainHeight, oPixels)); }
public IEnumerator InitIterativ(GraphicRequest req, int n, int points) { var data = GraphicsDatabase.GetColorData(req.path + directions[n], bodyColor, true); yield return(null); while (points > 0) { var stain = ZombieStains.GetRandom(points, req.path.Contains("Naked")); var it = data.ApplyStainsIterativ(stain.Key, Rand.Bool, Rand.Bool); while (it.MoveNext()) { yield return(null); } points -= stain.Value; hash = Gen.HashCombine(hash, stain); yield return(null); } var request = new MaterialRequest { mainTex = null, // will be calculated lazy from 'data' shader = req.shader, color = color, colorTwo = colorTwo, maskTex = null }; mats[n] = new VariableMaterial(request, data); }
public static Texture2D GetZombieButtonBackground() { if (ZombieButtonBackground == null) { ZombieButtonBackground = GraphicsDatabase.LoadTexture("ZombieButtonBackground", 170, 45); } return(ZombieButtonBackground); }
public static Texture2D GetMenuIcon() { if (MenuIcon == null) { MenuIcon = GraphicsDatabase.LoadTexture("PatreonIcon", 60, 45); } return(MenuIcon); }
public override void Init(GraphicRequest req) { data = req.graphicData; path = req.path; color = req.color; colorTwo = req.colorTwo; drawSize = req.drawSize; hash = Gen.HashCombine(hash, path); hash = Gen.HashCombineStruct(hash, color); hash = Gen.HashCombineStruct(hash, colorTwo); var bodyColor = GraphicToolbox.RandomSkinColorString(); mats = new ColorData[] { GraphicsDatabase.GetColorData(req.path + "_back", bodyColor, true), GraphicsDatabase.GetColorData(req.path + "_side", bodyColor, true), GraphicsDatabase.GetColorData(req.path + "_front", bodyColor, true) } .Select(data => { var points = ZombieStains.maxStainPoints; while (points > 0) { var stain = ZombieStains.GetRandom(points, req.path.Contains("Naked")); data.ApplyStains(stain.Key, Rand.Bool, Rand.Bool); points -= stain.Value; hash = Gen.HashCombine(hash, stain); } var request = new MaterialRequest { mainTex = null, // will be calculated lazy from 'data' shader = req.shader, color = color, colorTwo = colorTwo, maskTex = null }; return(new PreparedMaterial(request, data)); }) .ToArray(); }