public void CreateBabylonMaterial(BabylonScene scene)
        {
            var babylonMaterial = new BabylonMaterial();

            scene.MaterialsList.Add(babylonMaterial);

            // Guid
            babylonMaterial.id = ID.ToString();

            // Name
            babylonMaterial.name = Name;

            // Data
            babylonMaterial.backFaceCulling = BackFaceCulling;
            babylonMaterial.diffuse         = Diffuse.ToArray();
            babylonMaterial.emissive        = Emissive.ToArray();
            babylonMaterial.specular        = Specular.ToArray();
            babylonMaterial.specularPower   = SpecularPower;
            babylonMaterial.alpha           = Alpha;

            if (string.IsNullOrEmpty(DiffuseTexture))
            {
                babylonMaterial.diffuseTexture = null;
                return;
            }

            babylonMaterial.diffuseTexture      = new BabylonTexture();
            babylonMaterial.diffuseTexture.name = Path.GetFileName(DiffuseTexture);

            scene.AddTexture(DiffuseTexture);
        }
Exemple #2
0
        /// <summary>
        /// Determines whether the specified <see cref="MaterialPalette"/> is equal to the current <see cref="UFLT.Records.MaterialPalette"/>.
        /// </summary>
        /// <param name='other'>
        /// The <see cref="MaterialPalette"/> to compare with the current <see cref="UFLT.Records.MaterialPalette"/>.
        /// </param>
        /// <returns>
        /// <c>true</c> if the specified <see cref="MaterialPalette"/> is equal to the current
        /// <see cref="UFLT.Records.MaterialPalette"/>; otherwise, <c>false</c>.
        /// </returns>
        public bool Equals(MaterialPalette other)
        {
            // Check color fields
            if (!Ambient.Equals(other.Ambient))
            {
                return(false);
            }
            if (!Diffuse.Equals(other.Diffuse))
            {
                return(false);
            }
            if (!Specular.Equals(other.Specular))
            {
                return(false);
            }
            if (!Emissive.Equals(other.Emissive))
            {
                return(false);
            }

            if (Mathf.Approximately(Shininess, other.Shininess))
            {
                return(false);
            }
            if (Mathf.Approximately(Alpha, other.Alpha))
            {
                return(false);
            }

            return(true);
        }
Exemple #3
0
    public void build()
    {
        DestroyRenderAreaTexture();

        texture = new Texture2D(200, 200);
        GameObject.Find("ViewRectangle").GetComponent <MeshRenderer> ().material.mainTexture = texture;
        vp = new ViewPlane(texture.width, texture.height, 1.0f, 100);
        background_color = Constants.black;

        tracer_ptr = new AreaLightTracer(this);

        Ambient ambLight = new Ambient();

        ambLight.set_color(new Color(1, 1, 1, 1));
        ambLight.scale_radiance(1.0f);
        set_ambient_light(ambLight);

        PerspectiveCamera pinhole_ptr1 = new PerspectiveCamera();

        set_camera(pinhole_ptr1);

        Emissive ems = new Emissive();

        ems.scale_radiance(40.0f);
        ems.set_ce(new Color(1, 0, 0, 1));

        //Create Sky Object
        Sky sky = new Sky();

        sky.sphereCenter = new Vector3(0, 0, 0);
        sky.sphereRad    = 20000.0f;
        sky.set_material(ems);
        add_object(sky);

        //Create Environment Light
        Environment envLight = new Environment();

        envLight.set_material(ems);
        envLight.SetSampler(new Regular(100));
        add_light(envLight);


        Matte mat_ptr = new Matte();

        mat_ptr.set_ka(0.25f);
        mat_ptr.set_kd(0.65f);
        mat_ptr.set_cd(new Color(1, 1, 0, 1));

        Sphere sphere = new Sphere();

        sphere.sphereCenter = new Vector3(-20, 0, 0);
        sphere.sphereRad    = 30.0f;
        sphere.set_material(mat_ptr);


        add_object(sphere);

        render_scene();
    }
        private void Spherical()
        {
            Emissive e = new Emissive(ColorUtils.WHITE, 28);

            Sphere        s1  = new Sphere(new Vec3(972, 756, 108), 120);
            SphericalLamp sl1 = new SphericalLamp(s1, e);

            sl1.Shadows = false;
            sl1.Sampler = new MultiJittered(vp.NumSamples);

            Sphere        s2  = new Sphere(new Vec3(972, 756, -1296), 120);
            SphericalLamp sl2 = new SphericalLamp(s2, e);

            sl2.Shadows = false;
            sl2.Sampler = new MultiJittered(vp.NumSamples);

            Sphere        s3  = new Sphere(new Vec3(-1188, 756, 108), 120);
            SphericalLamp sl3 = new SphericalLamp(s3, e);

            sl3.Shadows = false;
            sl3.Sampler = new MultiJittered(vp.NumSamples);

            Sphere        s4  = new Sphere(new Vec3(-1188, 756, -1296), 120);
            SphericalLamp sl4 = new SphericalLamp(s4, e);

            sl4.Shadows = false;
            sl4.Sampler = new MultiJittered(vp.NumSamples);

            AddObject(sl1);
            AddObject(sl2);
            AddObject(sl3);
            AddObject(sl4);

            AreaLight l1 = new AreaLight();

            l1.Object  = sl1;
            l1.Shadows = true;

            AreaLight l2 = new AreaLight();

            l2.Object  = sl2;
            l2.Shadows = true;

            AreaLight l3 = new AreaLight();

            l3.Object  = sl3;
            l3.Shadows = true;

            AreaLight l4 = new AreaLight();

            l4.Object  = sl4;
            l4.Shadows = true;

            AddLight(l1);
            AddLight(l2);
            AddLight(l3);
            AddLight(l4);
        }
Exemple #5
0
 public RectangularLamp(Rectangle rectangle,
                        Emissive emissive) :
     base()
 {
     this.rectangle = rectangle;
     material       = emissive;
     this.emissive  = emissive;
     shadows        = false;
 }
Exemple #6
0
 public SphericalLamp(Sphere sphere, Emissive emissive) :
     base()
 {
     this.sphere     = sphere;
     material        = emissive;
     sphere.Material = emissive;
     this.emissive   = emissive;
     shadows         = false;
 }
Exemple #7
0
 public override int GetHashCode()
 {
     return((int)(
                (Name.GetHashCode() * 3) +
                (Ambient.GetHashCode() * 5) +
                (Diffuse.GetHashCode() * 7) +
                (Specular.GetHashCode() * 11) +
                (Emissive.GetHashCode() * 13) +
                (Reflectivity * 17) +
                (Opacity * 19)));
 }
Exemple #8
0
 public DiskLamp(Disk disk, Emissive emissive) :
     base()
 {
     this.disk = disk;
     up        = new Vec3(0, 1, 0);
     ComputeUVW();
     area          = MathUtils.PI * disk.Radius * disk.Radius;
     material      = disk.Material = emissive;
     this.emissive = emissive;
     shadows       = false;
 }
Exemple #9
0
        protected override void RefreshUniforms()
        {
            base.RefreshUniforms();

            Program.SetUniformData("ambient", Renderer.GammaInput ? Ambient.GammaToLinear() : Ambient);
            Program.SetUniformData("emissive", Renderer.GammaInput ?  Emissive.GammaToLinear() : Emissive);
            if (ShouldWrapAround)
            {
                Program.SetUniformData("wrapRGB", WrapRGB);
            }
        }
Exemple #10
0
        public odfMaterialPropertySet Clone()
        {
            odfMaterialPropertySet prop = new odfMaterialPropertySet();

            prop.Unknown1      = Unknown1;
            prop.Diffuse       = new Color4(Diffuse.ToVector4());
            prop.Ambient       = new Color4(Ambient.ToVector4());
            prop.Specular      = new Color4(Specular.ToVector4());
            prop.Emissive      = new Color4(Emissive.ToVector4());
            prop.SpecularPower = SpecularPower;
            return(prop);
        }
Exemple #11
0
        public void SetMaterial(IDeviceContextHolder contextHolder, IAcDynamicMaterial material)
        {
            if (material == null)
            {
                return;
            }
            Emissive.SetMaterial(contextHolder, material);

            if (RadialSpeedBlur != 0f)
            {
                material.SetRadialSpeedBlurNext(RadialSpeedBlur);
            }
        }
        protected override void RefreshUniforms()
        {
            base.RefreshUniforms();

            Program.SetUniformData("ambient", Renderer.GammaInput ? Ambient.GammaToLinear() : Ambient);
            Program.SetUniformData("emissive", Renderer.GammaInput ? Emissive.GammaToLinear() : Emissive);
            Program.SetUniformData("specular", Specular);
            Program.SetUniformData("shininess", Shininess);
            Program.SetUniformData("hardness", Hardness);
            Program.SetUniformData("normalScale", new Vector2(1, 1));
            if (ShouldWrapAround)
            {
                Program.SetUniformData("wrapRGB", WrapRGB);
            }
        }
 /// <summary>
 /// Test to see if this material is equal to another.
 /// </summary>
 /// <param name="other">The material to test against.</param>
 /// <returns>True if the object is equal to this one. False, otherwise.</returns>
 public bool Equals(MeshStandardMaterial other)
 {
     if (other == null)
     {
         return(false);
     }
     return(Roughness.Equals(other.Roughness) &&
            Metalness.Equals(other.Metalness) &&
            Ambient.Equals(other.Ambient) &&
            Color.Equals(other.Color) &&
            Emissive.Equals(other.Emissive) &&
            Map == other.Map &&
            BumpMap == other.BumpMap &&
            AlphaMap == other.AlphaMap &&
            EnvironmentMap == other.EnvironmentMap);
 }
        public override void Build()
        {
            vp            = ViewPlane.Create(1920, 1080, SystemOfCoordinates.SSC_INT);
            vp.NumSamples = 100;
            vp.MaxDepth   = 5;

            backgroundColor = ColorUtils.BLACK;
            tracer          = new PathTrace(this);

            Ambient a = new Ambient();

            a.ScaleRadiance = 0.0f;
            AmbientLight    = a;

            Pinhole pinhole = new Pinhole(new Vec3(100, 45, 100),
                                          new Vec3(-10, 40, 0),
                                          new Vec3(0.0, 1.0, 0.0),
                                          800, 1.5f);

            Camera = pinhole;

            Emissive emissive = new Emissive(ColorUtils.WHITE, 1.5f);

            ConcaveSphere sphere = new ConcaveSphere();

            sphere.Radius   = 1000000;
            sphere.Shadows  = false;
            sphere.Material = emissive;
            AddObject(sphere);

            float ka = 0.2f;

            Matte m1 = new Matte();

            m1.SetKa(ka);
            m1.SetKd(0.60f);
            m1.SetColor(ColorUtils.WHITE);
            m1.SetSampler(new MultiJittered(vp.NumSamples));

            Sphere largeSphere = new Sphere(new Vec3(38, 20, -24), 20);

            largeSphere.Material = m1;
            AddObject(largeSphere);

            Matte m2 = new Matte();

            m2.SetKa(ka);
            m2.SetKd(0.5f);
            m2.SetColor(0.85f);
            m2.SetSampler(new MultiJittered(vp.NumSamples));

            Sphere smallSphere = new Sphere(new Vec3(34, 12, 13), 12);

            smallSphere.Material = m2;
            AddObject(smallSphere);

            Matte m3 = new Matte();

            m3.SetKa(ka);
            m3.SetKd(0.75f);
            m3.SetColor(0.73f, 0.22f, 0.0f);
            m3.SetSampler(new MultiJittered(vp.NumSamples));

            Sphere mediumSphere = new Sphere(new Vec3(-7, 15, 42), 16);

            mediumSphere.Material = m3;
            AddObject(mediumSphere);

            Matte m4 = new Matte();

            m4.SetKa(ka);
            m4.SetKd(0.75f);
            m4.SetColor(0.60f);
            m4.SetSampler(new MultiJittered(vp.NumSamples));

            float b = 0;
            float t = 85;
            float r = 22;

            SolidCylinder cylinder = new SolidCylinder(b, t, r, m4);

            AddObject(cylinder);

            Matte m5 = new Matte();

            m5.SetKa(ka);
            m5.SetKd(0.75f);
            m5.SetColor(0.95f);
            m5.SetSampler(new MultiJittered(vp.NumSamples));

            Box box = new Box(new Vec3(-55, 0, -110),
                              new Vec3(-25, 60, 65),
                              m5);

            AddObject(box);

            Matte m6 = new Matte();

            m6.SetKa(0.15f);
            m6.SetKd(0.95f);
            m6.SetColor(0.37f, 0.43f, 0.08f);
            m6.SetSampler(new MultiJittered(vp.NumSamples));

            Plane plane = new Plane(new Vec3(0, 0.01, 0),
                                    new Vec3(0, 1, 0),
                                    m6);

            AddObject(plane);
        }
        public override void Build()
        {
            vp = ViewPlane.Create(1024, 768, SystemOfCoordinates.SSC_INT);
            //vp.NumSamples = 4096;
            vp.NumSamples = 400;
            vp.MaxDepth   = 10;

            backgroundColor = ColorUtils.BLACK;

            tracer = new GlobalTrace(this);
            //tracer = new PathTrace(this);

            Ambient ambient = new Ambient();

            ambient.ScaleRadiance = 0;
            AmbientLight          = ambient;

            Pinhole camera = new Pinhole();

            camera.SetEye(27.6, 27.4, -80);
            camera.SetLookat(27.6, 27.4, 0.0);
            camera.ViewPlaneDistance = 1200;
            Camera = camera;

            Vec3 p0;
            Vec3 a, b;
            Vec3 normal;

            // box dimensions

            double width  = 55.28;     // x direction
            double height = 54.88;     // y direction
            double depth  = 55.92;     // z direction


            Emissive emissive = new Emissive(new Vec3(1.0, 0.73, 0.4), 100);

            p0     = new Vec3(21.3, height - 0.001, 22.7);
            a      = new Vec3(0.0, 0.0, 10.5);
            b      = new Vec3(13.0, 0.0, 0.0);
            normal = new Vec3(0.0, -1.0, 0.0);

            RectangularLamp lamp = new RectangularLamp(new Rectangle(p0, a, b, normal), emissive);

            lamp.Sampler = new MultiJittered(vp.NumSamples);
            AddObject(lamp);

            AreaLight ceilingLight = new AreaLight();

            ceilingLight.Object = lamp;
            AddLight(ceilingLight);


            // left wall

            Matte matte1 = new Matte();

            matte1.SetKa(0.0f);
            matte1.SetKd(0.6f);
            matte1.SetColor(0.57f, 0.025f, 0.025f);     // red
            matte1.SetSampler(new MultiJittered(vp.NumSamples));

            p0     = new Vec3(width, 0.0, 0.0);
            a      = new Vec3(0.0, 0.0, depth);
            b      = new Vec3(0.0, height, 0.0);
            normal = new Vec3(-1.0, 0.0, 0.0);
            Rectangle leftWall = new Rectangle(p0, a, b, normal);

            leftWall.Material = matte1;
            AddObject(leftWall);


            // right wall

            Matte matte2 = new Matte();

            matte2.SetKa(0.0f);
            matte2.SetKd(0.6f);
            matte2.SetColor(0.37f, 0.59f, 0.2f);    // green
            matte2.SetSampler(new MultiJittered(vp.NumSamples));

            p0     = new Vec3(0.0, 0.0, 0.0);
            a      = new Vec3(0.0, 0.0, depth);
            b      = new Vec3(0.0, height, 0.0);
            normal = new Vec3(1.0, 0.0, 0.0);
            Rectangle rightWall = new Rectangle(p0, a, b, normal);

            rightWall.Material = matte2;
            AddObject(rightWall);


            // back wall

            Matte matte3 = new Matte();

            matte3.SetKa(0.0f);
            matte3.SetKd(0.6f);
            matte3.SetColor(ColorUtils.WHITE);
            matte3.SetSampler(new MultiJittered(vp.NumSamples));

            p0     = new Vec3(0.0, 0.0, depth);
            a      = new Vec3(width, 0.0, 0.0);
            b      = new Vec3(0.0, height, 0.0);
            normal = new Vec3(0.0, 0.0, -1.0);
            Rectangle backWall = new Rectangle(p0, a, b, normal);

            backWall.Material = matte3;
            AddObject(backWall);


            // floor

            p0     = new Vec3(0.0, 0.0, 0.0);
            a      = new Vec3(0.0, 0.0, depth);
            b      = new Vec3(width, 0.0, 0.0);
            normal = new Vec3(0.0, 1.0, 0.0);
            Rectangle floor = new Rectangle(p0, a, b, normal);

            floor.Material = matte3;
            AddObject(floor);


            // ceiling

            p0     = new Vec3(0.0, height, 0.0);
            a      = new Vec3(0.0, 0.0, depth);
            b      = new Vec3(width, 0.0, 0.0);
            normal = new Vec3(0.0, -1.0, 0.0);
            Rectangle ceiling = new Rectangle(p0, a, b, normal);

            ceiling.Material = matte3;
            AddObject(ceiling);


            // the two boxes defined as 5 rectangles each

            // short box

            // top

            p0     = new Vec3(13.0, 16.5, 6.5);
            a      = new Vec3(-4.8, 0.0, 16.0);
            b      = new Vec3(16.0, 0.0, 4.9);
            normal = new Vec3(0.0, 1.0, 0.0);
            Rectangle shortTop = new Rectangle(p0, a, b, normal);

            shortTop.Material = matte3;
            AddObject(shortTop);


            // side 1

            p0 = new Vec3(13.0, 0.0, 6.5);
            a  = new Vec3(-4.8, 0.0, 16.0);
            b  = new Vec3(0.0, 16.5, 0.0);
            Rectangle shortSide1 = new Rectangle(p0, a, b);

            shortSide1.Material = matte3;
            AddObject(shortSide1);


            // side 2

            p0 = new Vec3(8.2, 0.0, 22.5);
            a  = new Vec3(15.8, 0.0, 4.7);
            Rectangle shortSide2 = new Rectangle(p0, a, b);

            shortSide2.Material = matte3;
            AddObject(shortSide2);


            // side 3

            p0 = new Vec3(24.2, 0.0, 27.4);
            a  = new Vec3(4.8, 0.0, -16.0);
            Rectangle shortSide3 = new Rectangle(p0, a, b);

            shortSide3.Material = matte3;
            AddObject(shortSide3);


            // side 4

            p0 = new Vec3(29.0, 0.0, 11.4);
            a  = new Vec3(-16.0, 0.0, -4.9);
            Rectangle shortSide4 = new Rectangle(p0, a, b);

            shortSide4.Material = matte3;
            AddObject(shortSide4);



            // tall box

            // top

            p0     = new Vec3(42.3, 33.0, 24.7);
            a      = new Vec3(-15.8, 0.0, 4.9);
            b      = new Vec3(4.9, 0.0, 15.9);
            normal = new Vec3(0.0, 1.0, 0.0);
            Rectangle tallTop = new Rectangle(p0, a, b, normal);

            tallTop.Material = matte3;
            AddObject(tallTop);


            // side 1

            p0 = new Vec3(42.3, 0.0, 24.7);
            a  = new Vec3(-15.8, 0.0, 4.9);
            b  = new Vec3(0.0, 33.0, 0.0);
            Rectangle tallSide1 = new Rectangle(p0, a, b);

            tallSide1.Material = matte3;
            AddObject(tallSide1);


            // side 2

            p0 = new Vec3(26.5, 0.0, 29.6);
            a  = new Vec3(4.9, 0.0, 15.9);
            Rectangle tallSide2 = new Rectangle(p0, a, b);

            tallSide2.Material = matte3;
            AddObject(tallSide2);


            // side 3

            p0 = new Vec3(31.4, 0.0, 45.5);
            a  = new Vec3(15.8, 0.0, -4.9);
            Rectangle tallSide3 = new Rectangle(p0, a, b);

            tallSide3.Material = matte3;
            AddObject(tallSide3);


            // side 4

            p0 = new Vec3(47.2, 0.0, 40.6);
            a  = new Vec3(-4.9, 0.0, -15.9);
            Rectangle tallSide4 = new Rectangle(p0, a, b);

            tallSide4.Material = matte3;
            AddObject(tallSide4);
        }
        public override void Build()
        {
            vp            = ViewPlane.Create(1024, 768, SystemOfCoordinates.SSC_INT);
            vp.NumSamples = 100;
            vp.MaxDepth   = 10;

            backgroundColor = new Vec3(0.0, 0.3, 0.25);
            tracer          = new Whitted(this);

            //AmbientOccluder a = new AmbientOccluder(ColorUtils.WHITE,
            //                                        0.25, 1.0);
            //a.Sampler = new MultiJittered(vp.NumSamples);
            Ambient a = new Ambient();

            a.ScaleRadiance = 0.25f;
            AmbientLight    = a;

            Pinhole pinhole = new Pinhole(new Vec3(1, 7.5, 20),
                                          new Vec3(0.0, -0.35, 0.0),
                                          new Vec3(0.0, 1.0, 0.0),
                                          5250);

            Camera = pinhole;

            Emissive e = new Emissive();

            e.ScaleRadiance = 3.0f;
            e.Ce            = ColorUtils.WHITE;

            RectangularLamp lamp = new RectangularLamp(
                new Rectangle(new Vec3(0, 20, 0),
                              new Vec3(1, 0, 0),
                              new Vec3(0, 0, 1),
                              new Vec3(0, -1, 0)),
                e);

            lamp.Sampler = new MultiJittered(vp.NumSamples);
            AddObject(lamp);

            AreaLight areaLight = new AreaLight();

            areaLight.Object  = lamp;
            areaLight.Shadows = true;
            AddLight(areaLight);

            //PointLight l = new PointLight();
            //l.SetLocation(20, 20, 15);
            //l.ScaleRadiance = 3.0f;
            //AddLight(l);

            Transparent glass = new Transparent();

            glass.SetKs(0.5f);
            glass.SetExp(2000);
            glass.SetIor(1.5f);
            glass.SetKr(0.1f);
            glass.SetKt(1.53f);
            //glass.SetCd(0.4f);

            float ir = 0.9f;
            float or = 1;

            //Bowl b = Bowl.CreateFlatRimmedBowl(ir, or);
            Bowl b = Bowl.CreateRoundRimmedBowl(ir, or);

            b.Material = glass;
            AddObject(b);

            Reflective reflective = new Reflective();

            reflective.SetKa(0.6f);
            reflective.SetKd(0.4f);
            reflective.SetCd(ColorUtils.RED);
            reflective.SetKs(0.5f);
            reflective.SetExp(2000);
            reflective.SetKr(0.25f);

            double r = 0.4;
            double t = 55;

            t = MathUtils.PI * t / 180;
            double x = -(0.9 - r) * Math.Cos(t);
            double y = -(0.9 - r) * Math.Sin(t);

            Sphere s = new Sphere(new Vec3(x, y, 0), r, reflective);

            AddObject(s);

            Reflective reflective2 = new Reflective();

            reflective2.SetKa(0.6f);
            reflective2.SetKd(0.4f);
            reflective2.SetCd(ColorUtils.YELLOW);
            reflective2.SetKs(0.5f);
            reflective2.SetExp(2000);
            reflective2.SetKr(0.5f);

            r = 0.35;
            t = 35;
            t = MathUtils.PI * t / 180;
            x = (0.9 - r) * Math.Cos(t);
            y = -(0.9 - r) * Math.Sin(t);

            Sphere s2 = new Sphere(new Vec3(x, y, 0), r, reflective2);

            AddObject(s2);

            Matte rm = new Matte();

            rm.SetColor(ColorUtils.WHITE);
            rm.SetKa(0.8f);
            rm.SetKd(0.85f);

            Rectangle rectangle = new Rectangle(new Vec3(-2, -1, -5),
                                                new Vec3(0, 0, 9),
                                                new Vec3(4, 0, 0));

            rectangle.Material = rm;
            AddObject(rectangle);
        }
        public override void Build()
        {
            vp            = ViewPlane.Create(1920, 1080, SystemOfCoordinates.SSC_INT);
            vp.NumSamples = 144;
            vp.MaxDepth   = 10;

            backgroundColor = new Vec3(0.15);
            tracer          = new AreaLighting(this);

            AmbientOccluder a = new AmbientOccluder();

            a.ScaleRadiance = 0.5;
            a.MinAmount     = 0.05;
            a.Sampler       = new MultiJittered(vp.NumSamples);
            AmbientLight    = a;

            Pinhole pinhole = new Pinhole(new Vec3(75, 40, 100),
                                          new Vec3(-10, 39, 0),
                                          new Vec3(0.0, 1.0, 0.0),
                                          360, 3.0f);

            Camera = pinhole;

            Rectangle rectangle = new Rectangle(new Vec3(75, 40, 100),
                                                new Vec3(0, 50, 0),
                                                new Vec3(50, 0, -50));
            Emissive        e    = new Emissive(ColorUtils.WHITE, 20);
            RectangularLamp lamp = new RectangularLamp(rectangle, e);

            lamp.Sampler = new MultiJittered(vp.NumSamples);
            lamp.Shadows = false;

            AddObject(lamp);

            AreaLight light = new AreaLight();

            light.Object = lamp;

            AddLight(light);

            Reflective reflective1 = new Reflective();

            reflective1.SetKa(0.25f);
            reflective1.SetKd(0.5f);
            reflective1.SetColor(0.75f, 0.75f, 0.0f);
            reflective1.SetSpecularColor(ColorUtils.WHITE);
            reflective1.SetKs(0.15f);
            reflective1.SetExp(100.0f);
            reflective1.SetKr(0.75f);
            reflective1.SetReflectiveColor(ColorUtils.WHITE);

            double radius = 23.0;
            Sphere s1     = new Sphere(new Vec3(38, radius, -25), radius);

            s1.Material = reflective1;
            AddObject(s1);

            Matte matte1 = new Matte();

            matte1.SetKa(0.45f);
            matte1.SetKd(0.75f);
            matte1.SetColor(0.75f, 0.25f, 0.0f);

            Sphere s2 = new Sphere(new Vec3(-7, 10, 42), 20);

            s2.Material = matte1;
            AddObject(s2);

            Reflective reflective2 = new Reflective();

            reflective2.SetKa(0.35f);
            reflective2.SetKd(0.75f);
            reflective2.SetColor(ColorUtils.BLACK);
            reflective2.SetSpecularColor(ColorUtils.WHITE);
            reflective2.SetKs(0.0f);
            reflective2.SetExp(1.0f);
            reflective2.SetKr(0.75f);
            reflective2.SetReflectiveColor(ColorUtils.WHITE);

            Sphere s3 = new Sphere(new Vec3(-30, 59, 35), 20);

            s3.Material = reflective2;
            AddObject(s3);

            //cylinder
            Reflective reflective3 = new Reflective();

            reflective3.SetKa(0.35f);
            reflective3.SetKd(0.5f);
            reflective3.SetColor(0.0f, 0.5f, 0.75f);
            reflective3.SetSpecularColor(ColorUtils.WHITE);
            reflective3.SetKs(0.2f);
            reflective3.SetExp(100.0f);
            reflective3.SetKr(0.75f);
            reflective3.SetReflectiveColor(ColorUtils.WHITE);

            float b  = 0.0f;
            float t  = 85f;
            float cr = 22f;

            SolidCylinder cylinder = new SolidCylinder(b, t, cr);

            cylinder.Material = reflective3;
            AddObject(cylinder);

            //box
            Matte matte2 = new Matte();

            matte2.SetKa(0.15f);
            matte2.SetKd(0.5f);
            matte2.SetColor(0.75f, 1.0f, 0.75f);

            Box box = new Box(new Vec3(-35, 0, -110),
                              new Vec3(-25, 60, 65));

            box.Material = matte2;
            AddObject(box);

            //plane
            Matte matte3 = new Matte();

            matte3.SetKa(0.30f);
            matte3.SetKd(0.9f);
            matte3.SetColor(ColorUtils.WHITE);

            Plane plane = new Plane(new Vec3(),
                                    new Vec3(0, 1, 0));

            plane.Material = matte3;

            AddObject(plane);
        }
        public override void Build()
        {
            vp            = ViewPlane.Create(1024, 768, SystemOfCoordinates.SSC_INT);
            vp.NumSamples = 4;

            backgroundColor = ColorUtils.BLACK;
            tracer          = new AreaLighting(this);

            MultiJittered sampler = new MultiJittered(vp.NumSamples);

            sampler.Generate();

            AmbientOccluder occluder = new AmbientOccluder(ColorUtils.WHITE, 0.0);

            occluder.Sampler = sampler;
            //occluder.ScaleRadiance = 1.0;
            //occluder.Color = ColorUtils.WHITE;
            //occluder.SetMinAmount(0.0f);
            AmbientLight = occluder;

            Pinhole pinhole = new Pinhole(new Vec3(0.0, 0.0, 500.0),
                                          new Vec3(0.0, 0.0, 0.0),
                                          new Vec3(0.0, 1.0, 0.0),
                                          2000.0f);

            Camera = pinhole;

            Emissive emissive = new Emissive(ColorUtils.WHITE, 20.0f);

            //emissive.ScaleRadiance = 1.0f;
            //emissive.Ce = new Vec3(1.0, 1.0, 1.0);

            sampler = new MultiJittered(256);
            sampler.Generate();

            ConcaveSphere sphere = new ConcaveSphere(new Vec3(), 10000.0);

            //sphere.Radius = 10000.0;
            sphere.Sampler          = sampler;
            sphere.Material         = emissive;
            sphere.EmissiveMaterial = emissive;
            sphere.Shadows          = false;
            AddObject(sphere);

            sampler = new MultiJittered(256);
            sampler.Generate();

            EnvironmentLight l = new EnvironmentLight();

            l.Material = emissive;
            l.Sampler  = sampler;
            l.Sampler.MapSamplesToHemisphere(10);
            l.Shadows = true;
            AddLight(l);

            //Rectangle rectangle = new Rectangle(new Vec3(0.0, 100.0, 0.0),
            //                                    new Vec3(216.0, 0.0, 0.0),
            //                                    new Vec3(0.0, 0.0, 216.0));
            //emissive = new Emissive();
            //emissive.ScaleRadiance = 1.0f;
            //emissive.Ce = ColorUtils.WHITE;

            //rectangle.Material = emissive;
            //rectangle.Sampler = sampler;
            //rectangle.Shadows = false;
            //AddObject(rectangle);

            AreaLight areaLight = new AreaLight();

            areaLight.Object  = sphere;
            areaLight.Shadows = true;
            AddLight(areaLight);

            Vec3 lightGreen = new Vec3(0.65f, 1.0f, 0.30f);
            Vec3 green      = new Vec3(0.0f, 0.6f, 0.3f);
            Vec3 darkGreen  = new Vec3(0.0f, 0.41f, 0.41f);

            Vec3 yellow     = new Vec3(1.0f, 1.0f, 0.0f);
            Vec3 darkYellow = new Vec3(0.61f, 0.61f, 0.0f);

            Vec3 lightPurple = new Vec3(0.65f, 0.3f, 1.0f);
            Vec3 darkPurple  = new Vec3(0.5f, 0.0f, 1.0f);

            Vec3 brown  = new Vec3(0.71f, 0.40f, 0.16f);
            Vec3 orange = new Vec3(1.0f, 0.75f, 0.0f);

            Matte matte = new Matte();

            matte.SetKa(0.2f);
            matte.SetKd(0.5f);
            matte.SetColor(ColorUtils.WHITE);

            Plane p = new Plane(new Vec3(0, -85, 0), new Vec3(0, 1, 0));

            p.Material = matte;
            AddObject(p);

            Phong m = new Phong();

            m.SetKa(0.2f);
            m.SetKd(0.65f);
            m.SetKs(0.1f);
            m.SetExp(8.0f);
            m.SetColor(ColorUtils.WHITE);

            Sphere s = new Sphere(new Vec3(5, 3, 0), 30);

            s.Material = m;

            AddObject((Sphere)s.Clone());

            s.SetCenter(45, -7, -60);
            s.Radius = 20;
            m.SetColor(brown);
            AddObject((Sphere)s.Clone());

            s.SetCenter(40, 43, -100);
            s.Radius = 17;
            m.SetColor(darkGreen);
            AddObject((Sphere)s.Clone());

            s.SetCenter(-20, 28, -15);
            s.Radius = 20;
            m.SetColor(orange);
            AddObject((Sphere)s.Clone());

            s.SetCenter(-25, -7, -35);
            s.Radius = 27;
            m.SetColor(green);
            AddObject((Sphere)s.Clone());

            s.SetCenter(20, -27, -35);
            s.Radius = 25;
            m.SetColor(lightGreen);
            AddObject((Sphere)s.Clone());

            s.SetCenter(35, 18, -35);
            s.Radius = 22;
            m.SetColor(green);
            AddObject((Sphere)s.Clone());

            s.SetCenter(-57, -17, -50);
            s.Radius = 15;
            m.SetColor(brown);
            AddObject((Sphere)s.Clone());

            s.SetCenter(-47, 16, -80);
            s.Radius = 23;
            m.SetColor(lightGreen);
            AddObject((Sphere)s.Clone());

            s.SetCenter(-15, -32, -60);
            s.Radius = 22;
            m.SetColor(darkGreen);
            AddObject((Sphere)s.Clone());

            s.SetCenter(-35, -37, -80);
            s.Radius = 22;
            m.SetColor(darkYellow);
            AddObject((Sphere)s.Clone());

            s.SetCenter(10, 43, -80);
            s.Radius = 22;
            m.SetColor(darkYellow);
            AddObject((Sphere)s.Clone());

            s.SetCenter(30, -7, -80);
            s.Radius = 10;
            m.SetColor(darkYellow);
            AddObject((Sphere)s.Clone());

            s.SetCenter(-40, 48, -110);
            s.Radius = 18;
            m.SetColor(darkGreen);
            AddObject((Sphere)s.Clone());

            s.SetCenter(-10, 53, -120);
            s.Radius = 18;
            m.SetColor(brown);
            AddObject((Sphere)s.Clone());

            s.SetCenter(-55, -52, -100);
            s.Radius = 10;
            m.SetColor(lightPurple);
            AddObject((Sphere)s.Clone());

            s.SetCenter(5, -52, -100);
            s.Radius = 15;
            m.SetColor(brown);
            AddObject((Sphere)s.Clone());

            s.SetCenter(-20, -57, -120);
            s.Radius = 15;
            m.SetColor(darkPurple);
            AddObject((Sphere)s.Clone());

            s.SetCenter(55, -27, -100);
            s.Radius = 17;
            m.SetColor(darkGreen);
            AddObject((Sphere)s.Clone());

            s.SetCenter(50, -47, -120);
            s.Radius = 15;
            m.SetColor(brown);
            AddObject((Sphere)s.Clone());

            s.SetCenter(70, -42, -150);
            s.Radius = 10;
            m.SetColor(lightPurple);
            AddObject((Sphere)s.Clone());

            s.SetCenter(5, 73, -130);
            s.Radius = 12;
            m.SetColor(lightPurple);
            AddObject((Sphere)s.Clone());

            s.SetCenter(66, 21, -130);
            s.Radius = 13;
            m.SetColor(darkPurple);
            AddObject((Sphere)s.Clone());

            s.SetCenter(72, -12, -140);
            s.Radius = 12;
            m.SetColor(lightPurple);
            AddObject((Sphere)s.Clone());

            s.SetCenter(64, 5, -160);
            s.Radius = 11;
            m.SetColor(green);
            AddObject((Sphere)s.Clone());

            s.SetCenter(55, 38, -160);
            s.Radius = 12;
            m.SetColor(lightPurple);
            AddObject((Sphere)s.Clone());

            s.SetCenter(-73, -2, -160);
            s.Radius = 12;
            m.SetColor(lightPurple);
            AddObject((Sphere)s.Clone());

            s.SetCenter(30, -62, -140);
            s.Radius = 15;
            m.SetColor(darkPurple);
            AddObject((Sphere)s.Clone());

            s.SetCenter(25, 63, -140);
            s.Radius = 15;
            m.SetColor(darkPurple);
            AddObject((Sphere)s.Clone());

            s.SetCenter(-60, 46, -140);
            s.Radius = 15;
            m.SetColor(darkPurple);
            AddObject((Sphere)s.Clone());

            s.SetCenter(-30, 68, -130);
            s.Radius = 12;
            m.SetColor(lightPurple);
            AddObject((Sphere)s.Clone());

            s.SetCenter(58, 56, -180);
            s.Radius = 11;
            m.SetColor(green);
            AddObject((Sphere)s.Clone());

            s.SetCenter(-63, -39, -180);
            s.Radius = 11;
            m.SetColor(green);
            AddObject((Sphere)s.Clone());

            s.SetCenter(46, 68, -200);
            s.Radius = 10;
            m.SetColor(lightPurple);
            AddObject((Sphere)s.Clone());

            s.SetCenter(-3, -72, -130);
            s.Radius = 12;
            m.SetColor(lightPurple);
            AddObject(s);
        }
        public override void Build()
        {
            vp            = ViewPlane.Create(1024, 768, SystemOfCoordinates.SSC_INT);
            vp.NumSamples = 64;

            backgroundColor = ColorUtils.BLACK;
            tracer          = new RayCast(this);

            AmbientOccluder a = new AmbientOccluder(ColorUtils.WHITE,
                                                    0.25, 1.0);

            a.Sampler    = new MultiJittered(vp.NumSamples);
            AmbientLight = a;

            Pinhole pinhole = new Pinhole(new Vec3(0.0, 80.0, 210),
                                          new Vec3(0.0, 0.0, 0.0),
                                          new Vec3(0.0, 1.0, 0.0),
                                          500);

            Camera = pinhole;

            Emissive e = new Emissive();

            e.ScaleRadiance = 8.0f;
            e.Ce            = ColorUtils.WHITE;

            Rectangle rectangle = new Rectangle(new Vec3(0.0, 200.0, 100.0),
                                                new Vec3(216.0, 0.0, 0.0),
                                                new Vec3(0.0, 0.0, 216.0));

            rectangle.Shadows = false;

            RectangularLamp lamp = new RectangularLamp(rectangle, e);

            lamp.Sampler = new MultiJittered(vp.NumSamples);
            AddObject(lamp);

            AreaLight areaLight = new AreaLight();

            areaLight.Object  = lamp;
            areaLight.Shadows = true;
            AddLight(areaLight);

            //PointLight l = new PointLight();
            //l.Color = ColorUtils.WHITE;
            //l.SetLocation(100, 100, 200);
            //l.ScaleRadiance = 3.0f;
            //l.Shadows = true;
            //AddLight(l);

            Phong m = new Phong();

            m.SetColor(new Vec3(0.6, 0.2, 0.02));
            m.SetKa(0.2f);
            m.SetKd(0.65f);
            m.SetKs(0.4f);
            m.SetExp(64.0f);

            Phong i = new Phong();

            i.SetColor(new Vec3(0.8, 0.4, 0.02));
            i.SetKa(0.2f);
            i.SetKd(0.65f);
            i.SetKs(0.4f);
            i.SetExp(64.0f);

            //Bowl b = Bowl.CreateFlatRimmedBowl(75, 80);
            //Bowl b = Bowl.CreateRoundRimmedBowl(75, 80);
            Bowl b = Bowl.Create(75, 80, true);

            b.SetExternalMaterial(m);
            b.SetInternalMaterial(i);
            b.SetBorderMaterial(i);

            AddObject(b);

            Plane p  = new Plane(new Vec3(0, -80, 0), new Vec3(0, 1, 0));
            Matte pm = new Matte();

            pm.SetColor(new Vec3(0.2, 0.2, 0.2));
            pm.SetKa(0.2f);
            pm.SetKd(0.6f);
            p.Material = pm;

            AddObject(p);
        }
Exemple #20
0
        public static void buildCornelBox(Construction primitives, IIllumination lights, double diffuse,
                                          Tracer tracer, IRandomFactory randomFactory, IHemispherecalSamplerFactory hemiSamplerFactory)
        {
            IMaterial matte         = new Matte(diffuse, Constant.WHITE, primitives, lights, tracer, randomFactory, hemiSamplerFactory);
            IMaterial emitter       = new Emissive(Constant.WHITE, 1.0, 50.0);
            var       rightMaterial = new Matte(diffuse, Constant.GREEN, primitives, lights, tracer, randomFactory, hemiSamplerFactory);
            var       leftMaterial  = new Matte(diffuse, Constant.RED, primitives, lights, tracer, randomFactory, hemiSamplerFactory);

            // 下面
#if true
            #region Floor
            //white
            //552.8 0.0   0.0
            //  0.0 0.0   0.0
            //  0.0 0.0 559.2
            //549.6 0.0 559.2
            primitives.add(new Triangle(
                               new Vector3D(552.8, 0.0, 0.0),
                               new Vector3D(0.0, 0.0, -559.2),
                               new Vector3D(0.0, 0.0, 0.0),
                               matte));
            primitives.add(new Triangle(
                               new Vector3D(552.8, 0.0, 0.0),
                               new Vector3D(549.6, 0.0, -559.2),
                               new Vector3D(0.0, 0.0, -559.2),
                               matte));
            #endregion Floor
#endif

            // 照明
            #region Light
            //343.0 548.8 227.0
            //343.0 548.8 332.0
            //213.0 548.8 332.0
            //213.0 548.8 227.0
            var light1 = new Triangle(
                new Vector3D(343.0, 548, -227.0),
                new Vector3D(213.0, 548, -332.0),
                new Vector3D(343.0, 548, -332.0),
                emitter);
            primitives.add(light1);
            lights.addLight(light1);
            var light2 = new Triangle(
                new Vector3D(343.0, 548, -227.0),
                new Vector3D(213.0, 548, -227.0),
                new Vector3D(213.0, 548, -332.0),
                emitter);
            primitives.add(light2);
            lights.addLight(light2);
            #endregion Light

            // 上面
#if true
            #region Ceiling
            //556.0 548.8   0.0
            //556.0 548.8 559.2
            //0.0 548.8 559.2
            //0.0 548.8   0.0
            primitives.add(new Triangle(
                               new Vector3D(556.0, 548.8, 0.0),
                               new Vector3D(0.0, 548.8, -559.2),
                               new Vector3D(556.0, 548.8, -559.2),
                               matte));
            primitives.add(new Triangle(
                               new Vector3D(556.0, 548.8, 0.0),
                               new Vector3D(0.0, 548.8, 0.0),
                               new Vector3D(0.0, 548.8, -559.2),
                               matte));
            #endregion Ceiling
#endif

            // 背面
#if true
            #region Backward
            //549.6   0.0 559.2
            //0.0   0.0 559.2
            //0.0 548.8 559.2
            //556.0 548.8 559.2
            primitives.add(new Triangle(
                               new Vector3D(549.6, 0.0, -559.2),
                               new Vector3D(0.0, 548.8, -559.2),
                               new Vector3D(0.0, 0.0, -559.2),
                               matte));
            primitives.add(new Triangle(
                               new Vector3D(549.6, 0.0, -559.2),
                               new Vector3D(556.0, 548.8, -559.2),
                               new Vector3D(0.0, 548.8, -559.2),
                               matte));
            #endregion Backward
#endif

#if true
            // 左面
            #region Left
            //0.0   0.0 559.2
            //0.0   0.0   0.0
            //0.0 548.8   0.0
            //0.0 548.8 559.2
            primitives.add(new Triangle(
                               new Vector3D(0.0, 0.0, -559.2),
                               new Vector3D(0.0, 548.8, 0.0),
                               new Vector3D(0.0, 0.0, 0.0),
                               leftMaterial));
            primitives.add(new Triangle(
                               new Vector3D(0.0, 0.0, -559.2),
                               new Vector3D(0.0, 548.8, -559.2),
                               new Vector3D(0.0, 548.8, 0.0),
                               leftMaterial));
            #endregion Left
#endif

#if true
            // 右面
            #region Right
            //552.8   0.0   0.0
            //549.6   0.0 559.2
            //556.0 548.8 559.2
            //556.0 548.8   0.0
            primitives.add(new Triangle(
                               new Vector3D(552.8, 0.0, 0.0),
                               new Vector3D(556.0, 548.8, -559.2),
                               new Vector3D(549.6, 0.0, -559.2),
                               rightMaterial));
            primitives.add(new Triangle(
                               new Vector3D(552.8, 0.0, 0.0),
                               new Vector3D(556.0, 548.8, 0.0),
                               new Vector3D(556.0, 548.8, -559.2),
                               rightMaterial));
            #endregion Right
#endif

            // 小さい箱
#if true
            #region SmallBox
            //130.0 165.0  65.0
            // 82.0 165.0 225.0
            //240.0 165.0 272.0
            //290.0 165.0 114.0
            primitives.add(new Triangle(
                               new Vector3D(130.0, 165.0, -65.0),
                               new Vector3D(240.0, 165.0, -272.0),
                               new Vector3D(82.0, 165.0, -225.0),
                               matte));
            primitives.add(new Triangle(
                               new Vector3D(130.0, 165.0, -65.0),
                               new Vector3D(290.0, 165.0, -114.0),
                               new Vector3D(240.0, 165.0, -272.0),
                               matte));

            //290.0   0.0 114.0
            //290.0 165.0 114.0
            //240.0 165.0 272.0
            //240.0   0.0 272.0
            primitives.add(new Triangle(
                               new Vector3D(290.0, 0.0, -114.0),
                               new Vector3D(240.0, 165.0, -272.0),
                               new Vector3D(290.0, 165.0, -114.0),
                               matte));
            primitives.add(new Triangle(
                               new Vector3D(290.0, 0.0, -114.0),
                               new Vector3D(240.0, 0.0, -272.0),
                               new Vector3D(240.0, 165.0, -272.0),
                               matte));

            //130.0   0.0  65.0
            //130.0 165.0  65.0
            //290.0 165.0 114.0
            //290.0   0.0 114.0
            primitives.add(new Triangle(
                               new Vector3D(130.0, 0.0, -65.0),
                               new Vector3D(290.0, 165.0, -114.0),
                               new Vector3D(130.0, 165.0, -65.0),
                               matte));
            primitives.add(new Triangle(
                               new Vector3D(130.0, 0.0, -65.0),
                               new Vector3D(290.0, 0.0, -114),
                               new Vector3D(290.0, 165.0, -114.0),
                               matte));

            // 82.0   0.0 225.0
            // 82.0 165.0 225.0
            //130.0 165.0  65.0
            //130.0   0.0  65.0
            primitives.add(new Triangle(
                               new Vector3D(82.0, 0.0, -225.0),
                               new Vector3D(130.0, 165.0, -65.0),
                               new Vector3D(82.0, 165.0, -225.0),
                               matte));
            primitives.add(new Triangle(
                               new Vector3D(82.0, 0.0, -225.0),
                               new Vector3D(130.0, 0.0, -65.0),
                               new Vector3D(130.0, 165.0, -65.0),
                               matte));

            //240.0   0.0 272.0
            //240.0 165.0 272.0
            // 82.0 165.0 225.0
            // 82.0   0.0 225.0
            primitives.add(new Triangle(
                               new Vector3D(240.0, 0.0, -272.0),
                               new Vector3D(82.0, 165.0, -225.0),
                               new Vector3D(240.0, 165.0, -272.0),
                               matte));
            primitives.add(new Triangle(
                               new Vector3D(240.0, 0.0, -272.0),
                               new Vector3D(82.0, 0.0, -225.0),
                               new Vector3D(82.0, 165.0, -225.0),
                               matte));
            #endregion SmallBox
#endif

            // 大きい箱
#if true
            #region BigBox
            //423.0 330.0 247.0
            //265.0 330.0 296.0
            //314.0 330.0 456.0
            //472.0 330.0 406.0
            primitives.add(new Triangle(
                               new Vector3D(423.0, 330.0, -247.0),
                               new Vector3D(314.0, 330.0, -456.0),
                               new Vector3D(265.0, 330.0, -296.0),
                               matte));
            primitives.add(new Triangle(
                               new Vector3D(423.0, 330.0, -247.0),
                               new Vector3D(472.0, 330.0, -406.0),
                               new Vector3D(314.0, 330.0, -456.0),
                               matte));

            //423.0   0.0 247.0
            //423.0 330.0 247.0
            //472.0 330.0 406.0
            //472.0   0.0 406.0
            primitives.add(new Triangle(
                               new Vector3D(423.0, 0.0, -247.0),
                               new Vector3D(472.0, 330.0, -406.0),
                               new Vector3D(423.0, 330.0, -247.0),
                               matte));
            primitives.add(new Triangle(
                               new Vector3D(423.0, 0.0, -247.0),
                               new Vector3D(472.0, 0.0, -406.0),
                               new Vector3D(472.0, 330.0, -406.0),
                               matte));

            //472.0   0.0 406.0
            //472.0 330.0 406.0
            //314.0 330.0 456.0
            //314.0   0.0 456.0
            primitives.add(new Triangle(
                               new Vector3D(472.0, 0.0, -406.0),
                               new Vector3D(314.0, 330.0, -456.0),
                               new Vector3D(472.0, 330.0, -406.0),
                               matte));
            primitives.add(new Triangle(
                               new Vector3D(472.0, 0.0, -406.0),
                               new Vector3D(314.0, 0.0, -456.0),
                               new Vector3D(314.0, 330.0, -456.0),
                               matte));

            //314.0   0.0 456.0
            //314.0 330.0 456.0
            //265.0 330.0 296.0
            //265.0   0.0 296.0
            primitives.add(new Triangle(
                               new Vector3D(314.0, 0.0, -456.0),
                               new Vector3D(265.0, 330.0, -296.0),
                               new Vector3D(314.0, 330.0, -456.0),
                               matte));
            primitives.add(new Triangle(
                               new Vector3D(314.0, 0.0, -456.0),
                               new Vector3D(265.0, 0.0, -296.0),
                               new Vector3D(265.0, 330.0, -296.0),
                               matte));

            //265.0   0.0 296.0
            //265.0 330.0 296.0
            //423.0 330.0 247.0
            //423.0   0.0 247.0
            primitives.add(new Triangle(
                               new Vector3D(265.0, 0.0, -296.0),
                               new Vector3D(423.0, 330.0, -247.0),
                               new Vector3D(265.0, 330.0, -296.0),
                               matte));
            primitives.add(new Triangle(
                               new Vector3D(265.0, 0.0, -296.0),
                               new Vector3D(423.0, 0.0, -247.0),
                               new Vector3D(423.0, 330.0, -247.0),
                               matte));
            #endregion BigBox
#endif
        }
        public override void Build()
        {
            vp                = ViewPlane.Create(1024, 768, SystemOfCoordinates.SSC_INT);
            vp.NumSamples     = 64;
            vp.ShowOutOfGamut = 2;

            backgroundColor = ColorUtils.BLACK;
            tracer          = new AreaLighting(this);

            Ambient a = new Ambient();

            a.ScaleRadiance = 1.0f;
            AmbientLight    = a;

            Pinhole pinhole = new Pinhole(new Vec3(0.0, 0.0, 500.0),
                                          new Vec3(0.0, 0.0, 0.0),
                                          new Vec3(0.0, 1.0, 0.0),
                                          2000.0f);

            Camera = pinhole;

            Emissive emissive = new Emissive();

            emissive.ScaleRadiance = 40.0f;
            emissive.Ce            = ColorUtils.WHITE;

            MultiJittered sampler = new MultiJittered(256);

            sampler.Generate();

            Rectangle rectangle = new Rectangle(new Vec3(100.0, 100.0, 200.0),
                                                new Vec3(216.0, 0.0, 0.0),
                                                new Vec3(0.0, 0.0, 216.0));

            rectangle.Shadows = false;

            RectangularLamp lamp = new RectangularLamp(rectangle, emissive);

            lamp.Sampler = sampler;
            AddObject(lamp);

            AreaLight areaLight = new AreaLight();

            areaLight.Object  = lamp;
            areaLight.Shadows = true;
            AddLight(areaLight);

            Vec3 lightGreen = new Vec3(0.65f, 1.0f, 0.30f);
            Vec3 green      = new Vec3(0.0f, 0.6f, 0.3f);
            Vec3 darkGreen  = new Vec3(0.0f, 0.41f, 0.41f);

            Vec3 yellow     = new Vec3(1.0f, 1.0f, 0.0f);
            Vec3 darkYellow = new Vec3(0.61f, 0.61f, 0.0f);

            Vec3 lightPurple = new Vec3(0.65f, 0.3f, 1.0f);
            Vec3 darkPurple  = new Vec3(0.5f, 0.0f, 1.0f);

            Vec3 brown  = new Vec3(0.71f, 0.40f, 0.16f);
            Vec3 orange = new Vec3(1.0f, 0.75f, 0.0f);

            Matte matte = new Matte();

            matte.SetKa(0.2f);
            matte.SetKd(0.5f);
            matte.SetColor(ColorUtils.WHITE);

            Plane p = new Plane(new Vec3(0, -85, 0), new Vec3(0, 1, 0));

            p.Material = matte;
            AddObject(p);

            Matte m = new Matte();

            //Plastic *m = new Plastic();
            m.SetKa(0.2f);
            m.SetKd(0.65f);
            //m.SetKs(0.1f);
            //m.SetExp(8.0f);
            m.SetColor(ColorUtils.WHITE);

            Sphere s = new Sphere(new Vec3(5, 3, 0), 30);

            s.Material = m;

            AddObject((Sphere)s.Clone());

            s.SetCenter(45, -7, -60);
            s.Radius = 20;
            m.SetColor(brown);
            AddObject((Sphere)s.Clone());

            s.SetCenter(40, 43, -100);
            s.Radius = 17;
            m.SetColor(darkGreen);
            AddObject((Sphere)s.Clone());

            s.SetCenter(-20, 28, -15);
            s.Radius = 20;
            m.SetColor(orange);
            AddObject((Sphere)s.Clone());

            s.SetCenter(-25, -7, -35);
            s.Radius = 27;
            m.SetColor(green);
            AddObject((Sphere)s.Clone());

            s.SetCenter(20, -27, -35);
            s.Radius = 25;
            m.SetColor(lightGreen);
            AddObject((Sphere)s.Clone());

            s.SetCenter(35, 18, -35);
            s.Radius = 22;
            m.SetColor(green);
            AddObject((Sphere)s.Clone());

            s.SetCenter(-57, -17, -50);
            s.Radius = 15;
            m.SetColor(brown);
            AddObject((Sphere)s.Clone());

            s.SetCenter(-47, 16, -80);
            s.Radius = 23;
            m.SetColor(lightGreen);
            AddObject((Sphere)s.Clone());

            s.SetCenter(-15, -32, -60);
            s.Radius = 22;
            m.SetColor(darkGreen);
            AddObject((Sphere)s.Clone());

            s.SetCenter(-35, -37, -80);
            s.Radius = 22;
            m.SetColor(darkYellow);
            AddObject((Sphere)s.Clone());

            s.SetCenter(10, 43, -80);
            s.Radius = 22;
            m.SetColor(darkYellow);
            AddObject((Sphere)s.Clone());

            s.SetCenter(30, -7, -80);
            s.Radius = 10;
            m.SetColor(darkYellow);
            AddObject((Sphere)s.Clone());

            s.SetCenter(-40, 48, -110);
            s.Radius = 18;
            m.SetColor(darkGreen);
            AddObject((Sphere)s.Clone());

            s.SetCenter(-10, 53, -120);
            s.Radius = 18;
            m.SetColor(brown);
            AddObject((Sphere)s.Clone());

            s.SetCenter(-55, -52, -100);
            s.Radius = 10;
            m.SetColor(lightPurple);
            AddObject((Sphere)s.Clone());

            s.SetCenter(5, -52, -100);
            s.Radius = 15;
            m.SetColor(brown);
            AddObject((Sphere)s.Clone());

            s.SetCenter(-20, -57, -120);
            s.Radius = 15;
            m.SetColor(darkPurple);
            AddObject((Sphere)s.Clone());

            s.SetCenter(55, -27, -100);
            s.Radius = 17;
            m.SetColor(darkGreen);
            AddObject((Sphere)s.Clone());

            s.SetCenter(50, -47, -120);
            s.Radius = 15;
            m.SetColor(brown);
            AddObject((Sphere)s.Clone());

            s.SetCenter(70, -42, -150);
            s.Radius = 10;
            m.SetColor(lightPurple);
            AddObject((Sphere)s.Clone());

            s.SetCenter(5, 73, -130);
            s.Radius = 12;
            m.SetColor(lightPurple);
            AddObject((Sphere)s.Clone());

            s.SetCenter(66, 21, -130);
            s.Radius = 13;
            m.SetColor(darkPurple);
            AddObject((Sphere)s.Clone());

            s.SetCenter(72, -12, -140);
            s.Radius = 12;
            m.SetColor(lightPurple);
            AddObject((Sphere)s.Clone());

            s.SetCenter(64, 5, -160);
            s.Radius = 11;
            m.SetColor(green);
            AddObject((Sphere)s.Clone());

            s.SetCenter(55, 38, -160);
            s.Radius = 12;
            m.SetColor(lightPurple);
            AddObject((Sphere)s.Clone());

            s.SetCenter(-73, -2, -160);
            s.Radius = 12;
            m.SetColor(lightPurple);
            AddObject((Sphere)s.Clone());

            s.SetCenter(30, -62, -140);
            s.Radius = 15;
            m.SetColor(darkPurple);
            AddObject((Sphere)s.Clone());

            s.SetCenter(25, 63, -140);
            s.Radius = 15;
            m.SetColor(darkPurple);
            AddObject((Sphere)s.Clone());

            s.SetCenter(-60, 46, -140);
            s.Radius = 15;
            m.SetColor(darkPurple);
            AddObject((Sphere)s.Clone());

            s.SetCenter(-30, 68, -130);
            s.Radius = 12;
            m.SetColor(lightPurple);
            AddObject((Sphere)s.Clone());

            s.SetCenter(58, 56, -180);
            s.Radius = 11;
            m.SetColor(green);
            AddObject((Sphere)s.Clone());

            s.SetCenter(-63, -39, -180);
            s.Radius = 11;
            m.SetColor(green);
            AddObject((Sphere)s.Clone());

            s.SetCenter(46, 68, -200);
            s.Radius = 10;
            m.SetColor(lightPurple);
            AddObject((Sphere)s.Clone());

            s.SetCenter(-3, -72, -130);
            s.Radius = 12;
            m.SetColor(lightPurple);
            AddObject(s);
        }
Exemple #22
0
    public void build()
    {
        DestroyRenderAreaTexture();

        texture = new Texture2D(200, 200);
        GameObject.Find("ViewRectangle").GetComponent <MeshRenderer> ().material.mainTexture = texture;
        vp           = new ViewPlane(texture.width, texture.height, 1.0f, 1);
        vp.max_depth = 5;

        tracer_ptr = new GlobalTracer(this);

        Ambient amblight = new Ambient();

        amblight.scale_radiance(1.0f);
        amblight.set_color(new Color(1, 1, 1, 1));
        set_ambient_light(amblight);


        PerspectiveCamera pinhole_ptr1 = new PerspectiveCamera();

        pinhole_ptr1.set_eye(new Vector3(0, 0, 500));
        pinhole_ptr1.set_lookat(Vector3.zero);
        pinhole_ptr1.set_view_distance(600.0f);
        pinhole_ptr1.compute_uvw();
        set_camera(pinhole_ptr1);

        Directional directional = new Directional();

        directional.set_color(new Color(1, 1, 1, 1));
        directional.set_direction(new Vector3(-1, -1, 0));
        directional.cast_shadows = false;
        directional.scale_radiance(3.0f);
        add_light(directional);

        Reflective mat_ptr = new Reflective();

        mat_ptr.set_kr(1.0f);
        mat_ptr.set_exp(1.0f);
        mat_ptr.set_cr(sphere_1_col);

        Sphere sphere = new Sphere();

        sphere.sphereCenter = new Vector3(0, 0, 0);
        sphere.sphereRad    = 1.0f;
        sphere.set_material(mat_ptr);

        Instance sphereInst = new Instance(sphere);

        sphereInst.set_material(mat_ptr);
        add_object(sphereInst);

        sphereInst.set_identity();
        sphereInst.Scale(20, 20, 20);
        sphereInst.Translate(60.0f, 20.0f, 0);

        Matte mat_ptr1 = new Matte();

        mat_ptr1.ambient_brdf.Set_Sampler(100, 0.5f);
        mat_ptr1.diffuse_brdf.Set_Sampler(100, 0.5f);
        mat_ptr1.set_ka(1.0f);
        mat_ptr1.set_kd(1);
        mat_ptr1.set_cd(plane_col);


        Plane p = new Plane();

        p.planeNormal       = new Vector3(0, 1, 0);
        p.planePassThrghPnt = new Vector3(0, -20, 0);
        p.set_material(mat_ptr1);
        add_object(p);

        Emissive mat_ptr2 = new Emissive();

        mat_ptr2.scale_radiance(1);
        mat_ptr2.set_ce(sphere_2_col);

        Sphere sphere1 = new Sphere();

        sphere1.sphereCenter = new Vector3(0, 0, 0);
        sphere1.sphereRad    = 1.0f;
        sphere1.set_material(mat_ptr2);

        Instance sphereInst1 = new Instance(sphere1);

        sphereInst1.set_material(mat_ptr2);
        add_object(sphereInst1);

        sphereInst1.set_identity();
        sphereInst1.Scale(20, 20, 20);
        sphereInst1.Translate(-60.0f, 20.0f, 0);

        render_scene();
    }