Example #1
0
        public MainViewModel()
        {
            // ----------------------------------------------
            // titles
            this.Title = "Screen Space Ambient Occlusion Demo";
            this.SubTitle = "WPF & SharpDX";

            // camera setup
            this.Camera = new PerspectiveCamera { Position = new Point3D(1.5, 2.5, 2.5), LookDirection = new Vector3D(-1.5, -2.5, -2.5), UpDirection = new Vector3D(0, 1, 0) };

            // default render technique
            RenderTechniquesManager = new DeferredTechniquesManager();
            RenderTechnique = RenderTechniquesManager.RenderTechniques[DeferredRenderTechniqueNames.Deferred];
            EffectsManager = new DeferredEffectsManager(RenderTechniquesManager);
            SupportDeferredRender = true;

            // background
            this.BackgroundColor = (Color4)Color.White;

            // setup lighting
            this.AmbientLightColor = new Color4(0.1f, 0.1f, 0.1f, 1.0f);
            this.DirectionalLightColor = Color.White;
            this.DirectionalLightDirection1 = new Vector3(-2, -5, -2);
            this.DirectionalLightDirection2 = new Vector3(+2, +5, +5);

            // model materials
            this.DefaultMaterial = PhongMaterials.DefaultVRML;

            //load model
            var reader = new ObjReader();
            var objModel = reader.Read(@"./Media/CornellBox-Glossy.obj");

            this.ModelGeometry = new Element3DCollection();
            this.ModelGeometry.AddRange(objModel.Select(x => new MeshGeometryModel3D() { Geometry = x.Geometry as MeshGeometry3D, Material = x.Material, }));

            // model trafos
            this.ModelTransform = new Media3D.TranslateTransform3D(0, 0, 0);
        }
Example #2
0
        /// <summary>
        /// Constructor of the MainViewModel
        /// </summary>
        public MainViewModel()
        {
            // titles
            this.Title = "Deferred Shading Demo";
            this.SubTitle = "WPF & SharpDX";

            // camera setup
            this.Camera = new PerspectiveCamera { Position = new Point3D(18, 64, 30), LookDirection = new Vector3D(-18, -64, -30), UpDirection = new Vector3D(0, 1, 0) };

            // deferred render technique
            RenderTechniquesManager = new DeferredTechniquesManager();
            RenderTechnique = RenderTechniquesManager.RenderTechniques[DeferredRenderTechniqueNames.Deferred];
            EffectsManager = new DeferredEffectsManager(RenderTechniquesManager);
            SupportDeferredRender = true;

            //load model
            var reader = new ObjReader();
            var objModel = reader.Read(@"./Media/bunny.obj");
            this.Model = objModel[0].Geometry as MeshGeometry3D;
            var scale = 2.0;

            // model trafos
            var transf1 = new Transform3DGroup();
            transf1.Children.Add(new ScaleTransform3D(scale, scale, scale));
            transf1.Children.Add(new RotateTransform3D(new Media3D.AxisAngleRotation3D(new Vector3D(0, 1, 0), 40), 0.0, 0.0, 0.0));
            transf1.Children.Add(new TranslateTransform3D(0, -2, 3));
            this.Model1Transform = transf1;

            var transf2 = new Transform3DGroup();
            transf2.Children.Add(new ScaleTransform3D(scale, scale, scale));
            transf2.Children.Add(new Media3D.RotateTransform3D(new Media3D.AxisAngleRotation3D(new Vector3D(0, 1, 0), 66), 0.0, 0.0, 0.0));
            transf2.Children.Add(new Media3D.TranslateTransform3D(-3.0, -2, -2.5));
            this.Model2Transform = transf2;

            var transf3 = new Transform3DGroup();
            transf3.Children.Add(new ScaleTransform3D(scale, scale, scale));
            transf3.Children.Add(new TranslateTransform3D(+3.5, -2, -1.0));
            this.Model3Transform = transf3;

            // floor plane
            var meshBuilder = new MeshBuilder();
            meshBuilder.AddBox(new Vector3(0, 0, 0), 100, 0.0, 100, BoxFaces.PositiveY);
            this.Plane = meshBuilder.ToMeshGeometry3D();
            this.PlaneTransform = new TranslateTransform3D(0, -1.05, 0);

            // model materials
            this.RedMaterial = PhongMaterials.Red;
            this.GreenMaterial = PhongMaterials.Green;
            this.BlueMaterial = PhongMaterials.Blue;
            this.PlaneMaterial = PhongMaterials.DefaultVRML;
            this.PlaneMaterial.DiffuseMap = new BitmapImage(new System.Uri(@"./Media/TextureCheckerboard2.jpg", System.UriKind.RelativeOrAbsolute));
            this.PlaneMaterial.NormalMap = new BitmapImage(new System.Uri(@"./Media/TextureCheckerboard2_dot3.jpg", System.UriKind.RelativeOrAbsolute));

            // setup lighting
            this.AmbientLightColor = new Color4(0.3f, 0.3f, 0.3f, 1.0f);
            this.DirectionalLightColor = new Color4(0.2f, 0.2f, 0.2f, 1.0f);
            this.DirectionalLightDirection = new Vector3(-2, -5, -2);

            this.PointLightColor = (Color4)Color.White;
            this.PointLightAttenuation = new Vector3(0.0f, 0.0f, 0.18f); //1/0/0 ; 0.1, 0.2, 0.3
            this.PointLightTransform1 = new TranslateTransform3D(new Vector3D(0, 1, 0));
            this.PointLightTransform2 = new TranslateTransform3D(new Vector3D(6, 1, 3));
            this.PointLightTransform3 = new TranslateTransform3D(new Vector3D(-3, 1, -6));

            this.SpotLightColor = (Color4)Color.AntiqueWhite;
            this.SpotLightAttenuation = new Vector3(1.0f, 0.1f, 0.01f);

            // light collection
            this.PointLightCollection = new Element3DCollection();
            this.PointLightCount = 7;
            this.PointLightSpread = 100;

            // spotlight collection
            this.SpotLightCollection = new Element3DCollection();
            this.SpotLightCount = 7;
            this.SpotLightSpread = 100;
        }