public MultiViewAccumulation() { ViewsPerFrame = SampleCount; SampleCount = 1; MaxIterations = TotalSampleCount; // TODO: support creating samples for a cropped aperture (hexagon etc.) unitDiskSamples = sampler.CreateLensSamplesFloat(SqrtMaxTotalSampleCount, true).ToArray(); Accumulate = true; }
private void GenerateLensSamplesTextures(int textureId, int totalSampleCount, int tileSize) { // size of a group of samples for a single pixel int bands = 2; int textureSize = bands * totalSampleCount * tileSize * tileSize; //IEnumerable<Vector2d> samples = GenerateLensSamples(tileSize, (int)Math.Sqrt(MaxTotalSampleCount)).GetEnumerator(); int sqrtTotalSampleCount = (int)Math.Sqrt(totalSampleCount); Vector2[, ,] samples = new Vector2[tileSize, tileSize, totalSampleCount]; Sampler sampler = new Sampler(); for (int y = 0; y < tileSize; y++) { for (int x = 0; x < tileSize; x++) { IEnumerable <Vector2> pixelSamples = sampler.CreateLensSamplesFloat(sqrtTotalSampleCount, ShuffleLensSamples); int z = 0; foreach (Vector2 sample in pixelSamples) { samples[x, y, z] = sample; z++; } } } GL.BindTexture(TextureTarget.Texture3D, textureId); IntPtr texturePtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(Half)) * textureSize); unsafe { int zStride = bands * tileSize * tileSize; for (int y = 0; y < tileSize; y++) { for (int x = 0; x < tileSize; x++) { Half *row = (Half *)texturePtr + bands * (y * tileSize + x); int index = 0; // Z dimension for (int sample = 0; sample < totalSampleCount; sample++) { Vector2 lensPos = samples[x, y, sample]; row[index] = (Half)lensPos.X; row[index + 1] = (Half)lensPos.Y; index += zStride; } } } } // TODO: could be an half float or unsigned byte instead of a float // TODO: two sample pair could be stored in one 4-channel value GL.TexImage3D(TextureTarget.Texture3D, 0, PixelInternalFormat.Rg16f, tileSize, tileSize, totalSampleCount, 0, PixelFormat.Rg, PixelType.HalfFloat, texturePtr); Marshal.FreeHGlobal(texturePtr); GL.TexParameter(TextureTarget.Texture3D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest); GL.TexParameter(TextureTarget.Texture3D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest); GL.TexParameter(TextureTarget.Texture3D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat); GL.TexParameter(TextureTarget.Texture3D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat); GL.TexParameter(TextureTarget.Texture3D, TextureParameterName.TextureWrapR, (int)TextureWrapMode.Clamp); }
private void GenerateLensSamplesTextures(int textureId, int totalSampleCount, int tileSize) { // size of a group of samples for a single pixel int bands = 2; int textureSize = bands * totalSampleCount * tileSize * tileSize; //IEnumerable<Vector2d> samples = GenerateLensSamples(tileSize, (int)Math.Sqrt(MaxTotalSampleCount)).GetEnumerator(); int sqrtTotalSampleCount = (int)Math.Sqrt(totalSampleCount); Vector2[, ,] samples = new Vector2[tileSize, tileSize, totalSampleCount]; Sampler sampler = new Sampler(); for (int y = 0; y < tileSize; y++) { for (int x = 0; x < tileSize; x++) { IEnumerable<Vector2> pixelSamples = sampler.CreateLensSamplesFloat(sqrtTotalSampleCount, ShuffleLensSamples); int z = 0; foreach (Vector2 sample in pixelSamples) { samples[x, y, z] = sample; z++; } } } GL.BindTexture(TextureTarget.Texture3D, textureId); IntPtr texturePtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(Half)) * textureSize); unsafe { int zStride = bands * tileSize * tileSize; for (int y = 0; y < tileSize; y++) { for (int x = 0; x < tileSize; x++) { Half* row = (Half*)texturePtr + bands * (y * tileSize + x); int index = 0; // Z dimension for (int sample = 0; sample < totalSampleCount; sample++) { Vector2 lensPos = samples[x, y, sample]; row[index] = (Half)lensPos.X; row[index + 1] = (Half)lensPos.Y; index += zStride; } } } } // TODO: could be an half float or unsigned byte instead of a float // TODO: two sample pair could be stored in one 4-channel value GL.TexImage3D(TextureTarget.Texture3D, 0, PixelInternalFormat.Rg16f, tileSize, tileSize, totalSampleCount, 0, PixelFormat.Rg, PixelType.HalfFloat, texturePtr); Marshal.FreeHGlobal(texturePtr); GL.TexParameter(TextureTarget.Texture3D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest); GL.TexParameter(TextureTarget.Texture3D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest); GL.TexParameter(TextureTarget.Texture3D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat); GL.TexParameter(TextureTarget.Texture3D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat); GL.TexParameter(TextureTarget.Texture3D, TextureParameterName.TextureWrapR, (int)TextureWrapMode.Clamp); }