private void CreateRender() { int screenWidth = MdxRender.Device.Viewport.Width; int screenHeight = MdxRender.Device.Viewport.Height; float dist2 = RadiosityHelper.GatherDistance * RadiosityHelper.GatherDistance; Bitmap renderBitm;// = new Bitmap(screenWidth, screenHeight); float[,,] hdr = new float[screenWidth, screenHeight, 3]; ChangeStage(RadiosityStage.TextureGeneration, screenWidth * screenHeight); SetOperation("Rendering..."); int tenPercent = screenWidth / 10; int left = screenWidth / 2 - tenPercent; int right = screenWidth / 2 + tenPercent; for (int y = 0; y < screenHeight; y++) { for (int x = 0; x < screenWidth; x++) { Vector3 direction, origin; MdxRender.CalculatePickRayWorld(x, y, out direction, out origin); //AddDebugRay(origin, direction); RadiosityIntersection intersect = m_bsp[0].RadiosityIntersect(origin, direction); //AddDebugPoint(intersect.Position); if (!intersect.NoIntersection) { Vector3 normal = m_bsp[0].GetFaceNormal(intersect.LightmapIndex, intersect.MaterialIndex, intersect.FaceIndex); List <CompressedPhoton> photons = photonMap.RetrieveNearestNeighbors((PhotonVector3)intersect.Position, dist2, 10000); RealColor sum = RealColor.Black.Copy();//new RealColor(photons.Count, photons.Count, photons.Count); if (photons.Count == 0) { System.Diagnostics.Debugger.Break(); } foreach (CompressedPhoton phot in photons) { float dotP = Vector3.Dot(-phot.Direction, normal); if (dotP < 0) { dotP = 0; } sum.Add(phot.Power.Copy().Multiply(dotP)); } if ((sum.G > sum.B) && (sum.G > sum.R)) { if (x >= left) { if (x <= right) { if (photons.Count > 100) { AddDebugRay(origin, direction); AddDebugPoint(origin); foreach (var photon in photons) { AddDebugPoint(photon.position.ToVector3()); } } } } //System.Diagnostics.Debugger.Break(); } //sum.Multiply(1 / (dist2 * (float)Math.PI)); //sum.Multiply(intersect.Material.AmbientLight); for (int c = 0; c < 3; c++) { hdr[x, y, c] = sum[c]; } } else { hdr[x, y, 0] = 0; hdr[x, y, 1] = 0; hdr[x, y, 2] = 0; } IncrementProgress(); } } //renderBitm = LinearTonemap(hdr); Bitmap tempBitmap = new Bitmap(screenWidth, screenHeight); //Graphics g = Graphics.FromImage(tempBitmap); //g.DrawImage(renderBitm, 0, 0); //g.Dispose(); //renderBitm.Dispose(); tempBitmap.Save(@"C:\Users\David\render.bmp"); return; }