示例#1
0
        public IPhoton GeneratePhoton()
        {
            float u = (float)RadiosityHelper.RandomDouble;
            float v = (float)RadiosityHelper.RandomDouble;
            float w = (float)RadiosityHelper.RandomDouble;

            float sum = u + v + w;

            u /= sum; v /= sum;

            Vector3 position = Vector3.BaryCentric(a.position, b.position, c.position, u, v);

            position += (Normal * 0.005f);

            #region Random Direction

            /*float x = ((float)RadiosityHelper.Random.NextDouble() * 2f) - 1f;
             * if (x == 0f)
             * RadiosityHelper.Random = new Random();
             * float y = ((float)RadiosityHelper.Random.NextDouble() * 2f) - 1f;
             * if (y == 0f)
             * RadiosityHelper.Random = new Random();
             * float z = ((float)RadiosityHelper.Random.NextDouble() * 2f)- 1f;
             * if (z == 0f)
             * RadiosityHelper.Random = new Random();
             * Vector3 direction = new Vector3(x, y, z);
             * direction.Normalize();*/
            #endregion

            double f = RadiosityHelper.RandomDoubleRange(2.0, -1.0); // get it within the range of -1 to +1

            Vector3 direction = Normal * (float)Math.Cos(f);

            return(new Photon(position, direction, color));
        }
示例#2
0
        public DiffuseLight(Vertex[] triangle, RealColor color, float power)
        {
            a = triangle[0]; b = triangle[1]; c = triangle[2];

            this.color = color.Copy();

            this.power = power;
            Normal     = RadiosityHelper.ComputeTriangleNormal(a, b, c);
            Center     = Vector3.BaryCentric(a.position, b.position, c.position, 0.333333f, 0.333333f);
        }