예제 #1
0
파일: Objects.cs 프로젝트: Ukolnir/MMCS_332
 public Sphere(Vector3 center, float radius, ColorT color, double spec, double refl, double refr = 0)
 {
     Center = center;
     Radius = radius;
     Color  = color;
     //Зеркальность
     Specular = spec;
     //Отражение
     Reflective = refl;
     //Прозрачность
     Refraction = refr;
 }
예제 #2
0
        private void render()
        {
            ViewPort Port   = new ViewPort(1, 1, 1, Cw, Ch);
            Camera   camera = new Camera(new Vector3(-1.0f, 0.0f, -11.0f));

            InitScene();

            //Отрисовка
            for (int x = -Cw / 2; x < Cw / 2; ++x)
            {
                for (int y = -Ch / 2 + 1; y < Ch / 2; ++y)
                {
                    Vector3 D = camera.Rotation * Port.PictureToViewPort(x, y);
                    ColorT  c = TraceRay(camera.Position, D, 1, float.MaxValue, 3);
                    PutPixel(x, y, c.Trunc());
                }
            }
            pictureBox1.Image = bmp;
        }
예제 #3
0
        public ColorT TraceRay(Vector3 O, Vector3 D, float t_min, float t_max, int Depth)
        {
            var ResultIntersect = ClosestIntersection(O, D, t_min, t_max);

            if (ResultIntersect.Item1 == null)
            {
                return(background);
            }

            Vector3 P = O + D * ResultIntersect.Item2;
            Vector3 N = P - ResultIntersect.Item1.Center;

            N = N / (float)N.Length();

            ColorT local_color = ResultIntersect.Item1.Color * ComputeLight(P, N, -D, ResultIntersect.Item1.Specular);

            double r = ResultIntersect.Item1.Reflective;

            if (Depth < 0 || r < 0)
            {
                return(local_color);
            }

            Vector3 R = ReflectRay(-D, N);

            ColorT reflected_color = TraceRay(P, R, t_min, t_max, Depth - 1);

            ColorT refracted_color = new ColorT();

            if (ResultIntersect.Item1.Refraction != 0)
            {
                refracted_color = TraceRay(P, D, 0.1f, t_max, 0);
            }

            return(local_color * (1 - r) + reflected_color * r + refracted_color * ResultIntersect.Item1.Refraction);
        }