示例#1
0
文件: Matrix.cs 项目: Tilps/Stash
 public Vector Apply(Vector other)
 {
     Vector v;
     v.Dx = other.Dx * values[0, 0] + other.Dy * values[0, 1] + other.Dz * values[0, 2];
     v.Dy = other.Dx * values[1, 0] + other.Dy * values[1, 1] + other.Dz * values[1, 2];
     v.Dz = other.Dx * values[2, 0] + other.Dy * values[2, 1] + other.Dz * values[2, 2];
     return v;
 }
示例#2
0
文件: ToyTracer.cs 项目: Tilps/Stash
 private double lambert2(Vector light, Vector normal, double brilliance)
 {
     return Math.Pow(Math.Abs(light.Dot(normal) / light.Length), brilliance);
 }
示例#3
0
文件: ToyTracer.cs 项目: Tilps/Stash
 private void GetPerp(Vector vector, out Vector a, out Vector b)
 {
     Vector basis;
     if (Math.Abs(vector.Dz) < 0.9)
     {
         basis = new Vector(0, 0, 1);
     }
     else
     {
         basis = new Vector(1, 0, 0);
     }
     a = vector.Cross(basis);
     b = a.Cross(vector);
 }
示例#4
0
文件: ToyTracer.cs 项目: Tilps/Stash
        private void CalculateLightContrib(Vector normal, ColorIntensity lightColor, Material surf, ColorIntensity pigment, ref double rI, ref double gI, ref double bI, Vector lightdir, Vector eye)
        {
            double diffusivity = 1.0-surf.Specularity;
            if (surf.Phong > 0.0)
            {
                Vector reflection = eye;
                reflection.Add(normal.Scale(-2.0 * eye.Dot(normal)));
                double phong = -lightdir.Scale(1.0 / lightdir.Length).Dot(reflection);
                if (phong > 0.0)
                {
                    double phongpowd = Math.Pow(phong, surf.Exponent);
                    rI += surf.Phong * phongpowd * lightColor.R*diffusivity;
                    gI += surf.Phong * phongpowd * lightColor.G * diffusivity;
                    bI += surf.Phong * phongpowd * lightColor.B * diffusivity;
                }
            }
            if (surf.Specular > 0.0)
            {
                Vector half = lightdir.Scale(1.0 / lightdir.Length);
                half.Add(eye);
                half.ScaleSelf(0.5);
                double spec = half.Dot(normal) / half.Length;

                if (spec > 0.0)
                {
                    double specpowd = Math.Pow(spec, 1.0 / surf.Roughness);
                    rI += surf.Specular * specpowd * lightColor.R * diffusivity;
                    gI += surf.Specular * specpowd * lightColor.G * diffusivity;
                    bI += surf.Specular * specpowd * lightColor.B * diffusivity;
                }
            }
            if (surf.Iridescence > 0.0)
            {
                double cosaoi = lightdir.Dot(normal)/lightdir.Length;
                double interference = 4.0 * Math.PI * surf.FilmThickness * cosaoi;

                double intensity = cosaoi * surf.Iridescence;
                double rwl = 0.25;
                double gwl = 0.18;
                double bwl = 0.14;
                /* Modify color by phase offset for each wavelength. */

                rI += surf.Iridescence * (intensity * (1.0 - 0.5 * Math.Cos(interference / rwl))) * diffusivity;
                gI += surf.Iridescence * (intensity * (1.0 - 0.5 * Math.Cos(interference / gwl))) * diffusivity;
                bI += surf.Iridescence * (intensity * (1.0 - 0.5 * Math.Cos(interference / bwl))) * diffusivity;

            }
            double lam = lambert2(lightdir, normal, surf.Brilliance);
            rI += surf.Diffuse * pigment.R * lam * lightColor.R * diffusivity;
            gI += surf.Diffuse * pigment.G * lam * lightColor.G * diffusivity;
            bI += surf.Diffuse * pigment.B * lam * lightColor.B * diffusivity;
        }
示例#5
0
文件: Vector.cs 项目: Tilps/Stash
 public double Dot(Vector other)
 {
     return Dx * other.Dx + Dy * other.Dy + Dz * other.Dz;
 }
示例#6
0
文件: Vector.cs 项目: Tilps/Stash
 public Vector Cross(Vector other)
 {
     return new Vector(Dy * other.Dz - Dz * other.Dy, Dz * other.Dx - Dx * other.Dz, Dx * other.Dy - Dy * other.Dx);
 }
示例#7
0
文件: Vector.cs 项目: Tilps/Stash
 public void Add(Vector other)
 {
     Dx += other.Dx;
     Dy += other.Dy;
     Dz += other.Dz;
 }
示例#8
0
文件: Point.cs 项目: Tilps/Stash
 public Point MoveBy(Vector shift)
 {
     return new Point(X + shift.Dx, Y + shift.Dy, Z + shift.Dz);
 }
示例#9
0
文件: View.cs 项目: Tilps/Stash
 public void Upward(Point place)
 {
     Vector upnot = look.Start.LineTo(place);
     up = look.Direct.Cross(upnot).Cross(look.Direct);
 }