Example #1
0
        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, NeighborsCount, true);

            WMath.Vector[] Directions = null;
            if (radioButtonHammersley.Checked)
            {
                double[,]               Samples = m_Hammersley.BuildSequence(NeighborsCount, 2);
                Directions = m_Hammersley.MapSequenceToSphere(Samples);
            }
            else
            {
                Random TempRNG = new Random();
                Directions = new WMath.Vector[NeighborsCount];
                for (int i = 0; i < NeighborsCount; i++)
                {
                    Directions[i] = new WMath.Vector(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
        }
Example #2
0
        private void    GenerateRays(int _RaysCount, float _MaxConeAngle, RendererManaged.StructuredBuffer <RendererManaged.float3> _Target)
        {
            _RaysCount = Math.Min(MAX_THREADS, _RaysCount);

            WMath.Hammersley hammersley = new WMath.Hammersley();
            double[,]                       sequence = hammersley.BuildSequence(_RaysCount, 2);
            WMath.Vector[] rays = hammersley.MapSequenceToSphere(sequence, 0.5f * _MaxConeAngle);
            for (int RayIndex = 0; RayIndex < _RaysCount; RayIndex++)
            {
                WMath.Vector ray = rays[RayIndex];

//              // Scale the ray so we ensure to always walk at least a texel in the texture
//              float	SinTheta = (float) Math.Sqrt( 1.0 - ray.y * ray.y );
//              float	LengthFactor = 1.0f / SinTheta;
//              ray *= LengthFactor;

                _Target.m[RayIndex].Set(ray.x, -ray.z, ray.y);
            }

            _Target.Write();
        }