Пример #1
0
        public ReflectionMapSample()
        {
            InitializeComponent();

            //Ab3d.DirectX.DXDiagnostics.CreateDebugDirectXDevice = true;

            MainDXViewportView.DXSceneInitialized += delegate(object sender, EventArgs args)
            {
                if (MainDXViewportView.UsedGraphicsProfile.DriverType != GraphicsProfile.DriverTypes.Wpf3D)
                {
                    // We create the CubeMap from 6 bitmap images
                    string packUriPrefix = string.Format("pack://application:,,,/{0};component/Resources/SkyboxTextures/", this.GetType().Assembly.GetName().Name);

                    // Create DXCubeMap with specifying 6 bitmaps for all sides of the cube
                    _dxCubeMap = new DXCubeMap(packUriPrefix,
                                               "CloudyLightRaysRight512.png",
                                               "CloudyLightRaysLeft512.png",
                                               "CloudyLightRaysUp512.png",
                                               "CloudyLightRaysDown512.png",
                                               "CloudyLightRaysFront512.png",
                                               "CloudyLightRaysBack512.png");

                    // To show the environment map correctly for our bitmaps we need to flip bottom bitmap horizontally and vertically
                    _dxCubeMap.FlipBitmaps(flipRightBitmapType: DXCubeMap.FlipBitmapType.None,
                                           flipLeftBitmapType: DXCubeMap.FlipBitmapType.None,
                                           flipUpBitmapType: DXCubeMap.FlipBitmapType.None,
                                           flipDownBitmapType: DXCubeMap.FlipBitmapType.FlipXY,
                                           flipFrontBitmapType: DXCubeMap.FlipBitmapType.None,
                                           flipBackBitmapType: DXCubeMap.FlipBitmapType.None);

                    SetupCubeMapMaterial();
                }
            };

            this.Unloaded += delegate(object sender, RoutedEventArgs args)
            {
                // We need to dispose all the DirectX resources created here:
                if (_dxCubeMap != null)
                {
                    _dxCubeMap.Dispose();
                    _dxCubeMap = null;
                }

                // Then dispose the MainDXViewportView
                MainDXViewportView.Dispose();
            };
        }
        public EnvironmentReflectionsTest()
        {
            InitializeComponent();

            string packUriPrefix = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources\\SkyboxTextures\\");

            //string packUriPrefix = "pack://*****:*****@"Resources\SkyboxTextures\sunsetcube1024.dds");


            // This sample is showing 4 teapot models. We set different reflectionFactors to each of them.
            // Front left Teapot:
            // full reflection (reflectionFactor = 1.0f)
            SetEnvironmentMap(TeapotVisual1.Content, _dxCubeMap, reflectionFactor: 1.0f);

            // Front right Teapot:
            // half reflection and half diffuse color (reflectionFactor = 0.5f)
            SetEnvironmentMap(TeapotVisual2.Content, _dxCubeMap, reflectionFactor: 0.5f);

            // Back left Teapot:
            // full reflection on blue color and half reflection of green and blue (reflectionFactor = new SharpDX.Color3(0.5f, 0.5f, 1.0f))
            SetEnvironmentMap(TeapotVisual3.Content, _dxCubeMap, reflectionFactor: new SharpDX.Color3(0.5f, 0.5f, 1.0f));

            // Back right Teapot:
            // no reflection and full diffuse color (reflectionFactor = 0.0f)
            SetEnvironmentMap(TeapotVisual4.Content, _dxCubeMap, reflectionFactor: 0.0f);


            this.Unloaded += delegate(object sender, RoutedEventArgs args)
            {
                // We need to dispose all the DirectX resources created here:
                if (_dxCubeMap != null)
                {
                    _dxCubeMap.Dispose();
                    _dxCubeMap = null;
                }

                // Then dispose the MainDXViewportView
                MainDXViewportView.Dispose();
            };
        }