That’s what I was looking for, thanks. I compared both methods - they yield the same results - and interestingly (but not intuitively), the mipmap solution is slower!?
Here is a code snippet for both functions (tex has dimensions of 512x512 pixels).
float GetPixelMean(Texture2D tex)
{
SW.Start();
int N = tex.Width * tex.Height;
float[] PixelValue = new float[N];
tex.GetData(PixelValue);
float Sum = 0;
for (int i = 0; i < PixelValue.Length; i++)
{
Sum += PixelValue[i];
}
long Time = SW.ElapsedTicks;
SW.Stop();
Console.WriteLine("Elapsed ticks: " + Time);
return Sum / N;
}
float GetPixelMeanMipMap(Texture2D tex)
{
SW.Start();
float[] PixelValue = new float[1];
tex.GetData(tex.LevelCount - 1, null, PixelValue, 0, 1);
long Time = SW.ElapsedTicks;
SW.Stop();
Console.WriteLine("Elapsed ticks: " + Time);
return PixelValue[0];
}
@mgulde sounds about right. Aside from a sampled solution always being off from an analytic one - a hemicube has higher density at the edges that’s going to skew things a great deal (more samples in a band of solid-angles around 45deg outward). Up close you end up with lots of samples in that band and at a distance your samples start to all pile together around the less dense center of the viewing direction.
Just to be sure, you’re only taking the appropriate half of each of the side faces of the cube right?