private void Calculate(RenderTexture renderTexture, RenderTexture temporary, int scale) { var threshold32 = (byte)(threshold * 255.0f); var width = renderTexture.width; var height = renderTexture.height; var texture2D = P3dHelper.GetReadableCopy(renderTexture); var pixels32 = texture2D.GetPixels32(); P3dHelper.Destroy(texture2D); UpdateTotal(temporary, width, height, renderTexture.depth, renderTexture.format, scale); // Reset totals solidR = 0; solidG = 0; solidB = 0; solidA = 0; // Calculate totals for (var y = 0; y < height; y++) { var offset = y * width; for (var x = 0; x < height; x++) { var index = offset + x; if (baked == true && bakedPixels[index] == false) { continue; } var pixel32 = pixels32[index]; if (pixel32.r >= threshold32) { solidR++; } if (pixel32.g >= threshold32) { solidG++; } if (pixel32.b >= threshold32) { solidB++; } if (pixel32.a >= threshold32) { solidA++; } } } // Scale totals to account for downsampling solidR *= scale; solidG *= scale; solidB *= scale; solidA *= scale; }
private void Calculate(RenderTexture renderTexture, int scale) { var threshold32 = (int)(threshold * 255.0f); var width = renderTexture.width; var height = renderTexture.height; var texture2D = P3dHelper.GetReadableCopy(renderTexture); var pixels32 = texture2D.GetPixels32(); P3dHelper.Destroy(texture2D); UpdateTotal(renderTexture, width, height, scale); PrepareTemp(); for (var y = 0; y < height; y++) { var offset = y * width; for (var x = 0; x < height; x++) { var index = offset + x; if (baked == true && bakedPixels[index] == false) { continue; } var pixel32 = pixels32[index]; var bestIndex = -1; var bestDistance = threshold32; for (var i = 0; i < P3dColor.InstanceCount; i++) { var tempColor = tempColors[i]; var distance = 0; distance += System.Math.Abs(tempColor.R - pixel32.r); distance += System.Math.Abs(tempColor.G - pixel32.g); distance += System.Math.Abs(tempColor.B - pixel32.b); distance += System.Math.Abs(tempColor.A - pixel32.a); if (distance <= bestDistance) { bestIndex = i; bestDistance = distance; } } if (bestIndex >= 0) { tempColors[bestIndex].Solid++; } } } // Multiply totals to account for downsampling Contribute(scale); }