| 5 | class Program |
| 6 | { |
| 7 | static void Main(string[] args) |
| 8 | { |
| 9 | int width = 1280; |
| 10 | int height = 720; |
| 11 | float[] backbuffer = new float[width * height * 4]; |
| 12 | Stopwatch stopwatch = new Stopwatch(); |
| 13 | long totalRayCount = 0; |
| 14 | |
| 15 | Test test = new Test(); |
| 16 | const int kFrameCount = 30; |
| 17 | stopwatch.Start(); |
| 18 | float s = 0.0f; |
| 19 | for (int i = 0; i < kFrameCount; ++i) |
| 20 | { |
| 21 | int rayCount; |
| 22 | test.DrawTest(s, i, width, height, backbuffer, out rayCount); |
| 23 | totalRayCount += rayCount; |
| 24 | |
| 25 | s = (float)((double)stopwatch.ElapsedTicks / (double)Stopwatch.Frequency); |
| 26 | int frames = i + 1; |
| 27 | |
| 28 | float ms = s / frames * 1000.0f; |
| 29 | float mrayS = (float)(totalRayCount / s * 1.0e-6f); |
| 30 | float mrayFr = rayCount * 1.0e-6f; |
| 31 | System.Console.WriteLine($"{ms:F2}ms {mrayS:F1}Mrays/s {mrayFr:F2}Mrays/frame frames {frames}"); |
| 32 | } |
| 33 | |
| 34 | byte[] bytes = new byte[backbuffer.Length]; |
| 35 | for (int i = 0; i < backbuffer.Length; i += 4) |
| 36 | { |
| 37 | bytes[i + 0] = (byte)(LinearToSRGB(backbuffer[i + 2])); |
| 38 | bytes[i + 1] = (byte)(LinearToSRGB(backbuffer[i + 1])); |
| 39 | bytes[i + 2] = (byte)(LinearToSRGB(backbuffer[i + 0])); |
| 40 | bytes[i + 3] = 255; |
| 41 | } |
| 42 | byte[] header = { |
| 43 | 0, // ID length |
| 44 | 0, // no color map |
| 45 | 2, // uncompressed, true color |
| 46 | 0, 0, 0, 0, |
| 47 | 0, |
| 48 | 0, 0, 0, 0, // x and y origin |
| 49 | (byte)(width & 0x00FF), |
| 50 | (byte)((width & 0xFF00) >> 8), |
| 51 | (byte)(height & 0x00FF), |
| 52 | (byte)((height & 0xFF00) >> 8), |
| 53 | 32, // 32 bit |
| 54 | 0 }; |
| 55 | using (BinaryWriter writer = new BinaryWriter(new FileStream("output.tga", FileMode.Create))) |
| 56 | { |
| 57 | writer.Write(header); |
| 58 | writer.Write(bytes); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | static uint LinearToSRGB(float x) |
| 63 | { |