public OutputPanelHammersley(IContainer container) { container.Add(this); InitializeComponent(); Hammersley QRNG = new Hammersley(); double[,] Sequence = QRNG.BuildSequence(SAMPLES_COUNT, 2); for (int SampleIndex = 0; SampleIndex < SAMPLES_COUNT; SampleIndex++) { float Angle = 2.0f * (float)Math.PI * (float)Sequence[SampleIndex, 0]; float Radius = (float)Math.Sqrt(Sequence[SampleIndex, 1]); // Uniform // float Radius = (float) Sequence[SampleIndex,1]; m_Samples[SampleIndex] = new float2(Radius * (float)Math.Cos(Angle), Radius * (float)Math.Sin(Angle)); } string Format = "const uint SHADOW_SAMPLES_COUNT = "+ SAMPLES_COUNT + ";\r\n" + "const float2 SamplesOffset[SHADOW_SAMPLES_COUNT] = {\r\n"; for (int SampleIndex = 0; SampleIndex < SAMPLES_COUNT; SampleIndex++) { Format += " float2( " + m_Samples[SampleIndex].x + ", " + m_Samples[SampleIndex].y + " ),\r\n"; } Format += "};\r\n\r\n"; OnSizeChanged(EventArgs.Empty); }
private void integerTrackbarControlNeighborsCount_ValueChanged(IntegerTrackbarControl _Sender, int _FormerValue) { int NeighborsCount = integerTrackbarControlNeighborsCount.Value; if (m_SB_Neighbors != null) { m_SB_Neighbors.Dispose(); } m_SB_Neighbors = new StructuredBuffer <SB_Neighbor>(m_Device, (uint)NeighborsCount, true, false); float3[] directions = null; if (radioButtonHammersley.Checked) { double[,] samples = m_hammersley.BuildSequence(NeighborsCount, 2); directions = m_hammersley.MapSequenceToSphere(samples); } else { Random TempRNG = new Random(); directions = new float3[NeighborsCount]; for (int i = 0; i < NeighborsCount; i++) { directions[i] = new float3(2.0f * (float)TempRNG.NextDouble() - 1.0f, 2.0f * (float)TempRNG.NextDouble() - 1.0f, 2.0f * (float)TempRNG.NextDouble() - 1.0f); directions[i].Normalize(); } } Random RNG = new Random(1); m_neighborPositions = new float3[NeighborsCount]; m_NeighborColors = new float3[NeighborsCount]; for (int NeighborIndex = 0; NeighborIndex < NeighborsCount; NeighborIndex++) { float Radius = 2.0f; // Make that random! m_neighborPositions[NeighborIndex] = Radius * new float3(directions[NeighborIndex].x, directions[NeighborIndex].y, directions[NeighborIndex].z); float R = (float)RNG.NextDouble(); float G = (float)RNG.NextDouble(); float B = (float)RNG.NextDouble(); m_NeighborColors[NeighborIndex] = new float3(R, G, B); m_SB_Neighbors.m[NeighborIndex].m_Position = m_neighborPositions[NeighborIndex]; m_SB_Neighbors.m[NeighborIndex].m_Color = m_NeighborColors[NeighborIndex]; } m_SB_Neighbors.Write(); // Upload // Build initial cell buttonBuildCell_Click(this, EventArgs.Empty); }