private void MainDxViewportViewOnDxSceneDeviceCreated(object sender, EventArgs e)
        {
            // Create a SolidColorEffect that will be used to render each objects with a color from object's id
            _solidColorEffect = new SolidColorEffect();
            _solidColorEffect.OverrideModelColor = true; // We will overwrite the object's color with color specified in SolidColorEffect.Color

            _disposables.Add(_solidColorEffect);

            MainDXViewportView.DXScene.DXDevice.EffectsManager.RegisterEffect(_solidColorEffect);


            // Create a custom rendering step that will be used instead of standard rendering step
            _objectIdRenderingStep = new CustomActionRenderingStep("ObjectIdRenderingStep")
            {
                CustomAction = ObjectIdRenderingAction,
                IsEnabled    = false
            };

            MainDXViewportView.DXScene.RenderingSteps.AddAfter(MainDXViewportView.DXScene.DefaultRenderObjectsRenderingStep, _objectIdRenderingStep);

            // In this sample we render Object ids to a custom bitmap,
            // so for standard rendering, we disable our custom rendering.
            // But if you went you can enable it and disabled the standard rendering - this will always render objects ids:
            //_objectIdRenderingStep.IsEnabled = true;
            //MainDXViewportView.DXScene.DefaultRenderObjectsRenderingStep.IsEnabled = false;
        }
        public CustomRenderingStep1()
        {
            InitializeComponent();

            MainDXViewportView.DXSceneInitialized += delegate(object sender, EventArgs args)
            {
                if (MainDXViewportView.DXScene == null) // When DXEngine falls back to WPF 3D rendering, the DXScene is null; we could also check for MainDXViewportView.UsedGraphicsProfile.DriverType != GraphicsProfile.DriverTypes.Wpf3D
                {
                    return;
                }

                InitializeSharpDXRendering(MainDXViewportView.DXScene);

                var customActionRenderingStep = new CustomActionRenderingStep("Custom DXScene rendering step");
                customActionRenderingStep.CustomAction = SharpDXRenderingAction;

                MainDXViewportView.DXScene.RenderingSteps.AddBefore(MainDXViewportView.DXScene.DefaultRenderObjectsRenderingStep, customActionRenderingStep);
            };

            CompositionTarget.Rendering += OnCompositionTargetOnRendering;

            this.Unloaded += delegate { Dispose(); };
        }
Exemple #3
0
        private void OnDxSceneDeviceCreated(object sender, EventArgs e)
        {
            //
            // !!! IMPORTANT !!!
            //
            // Some rendering queues are being sorted by material.
            // This improves performance by rendering objects with similar material one after another and
            // this reduces number of DirectX state changes.
            // But when using ObjectId map, we need to disable rendering queues by material.
            // If this is not done, the objects rendered in the standard rendering pass and
            // objects rendered for object id map will be rendered in different order.
            // Because of this we would not be able to get the original object id from the back.
            //
            // Therefore go through all MaterialSortedRenderingQueue and disable sorting.
            //
            // Note the we do not need to disable sorting by camera distance (TransparentRenderingQueue)
            // because the object order does not change when rendering object id map.

            foreach (var materialSortedRenderingQueue in MainDXViewportView.DXScene.RenderingQueues.OfType <MaterialSortedRenderingQueue>())
            {
                materialSortedRenderingQueue.IsSortingEnabled = false;
            }



            // Create a SolidColorEffect that will be used to render each objects with a color from object's id
            _solidColorEffect = new SolidColorEffect
            {
                // We will overwrite the object's color with color specified in SolidColorEffect.Color
                OverrideModelColor = true,

                // Always use Opaque blend state even if alpha is less then 1 (usually PremultipliedAlphaBlend is used in this case).
                // This will allow us to also use alpha component for the object id (in our case RenderingQueue id)
                OverrideBlendState = MainDXViewportView.DXScene.DXDevice.CommonStates.Opaque,

                // By default for alpha values less then 1, the color components are multiplied with alpha value to produce pre-multiplied colors.
                // This will allow us to also use alpha component for the object id (in our case RenderingQueue id)
                PremultiplyAlphaColors = false
            };


            _disposables.Add(_solidColorEffect);

            MainDXViewportView.DXScene.DXDevice.EffectsManager.RegisterEffect(_solidColorEffect);


            // Create a custom rendering step that will be used instead of standard rendering step.
            // It will be used in the CreateObjectIdBitmapButton_OnClick method below
            _objectIdRenderingStep = new CustomActionRenderingStep("ObjectIdRenderingStep")
            {
                CustomAction = ObjectIdRenderingAction,
                IsEnabled    = false                    // IMPORTANT: disable this custom rendering step - it will be enabled when rendering to bitmap
            };

            MainDXViewportView.DXScene.RenderingSteps.AddAfter(MainDXViewportView.DXScene.DefaultRenderObjectsRenderingStep, _objectIdRenderingStep);

            // In this sample we render Object ids to a custom bitmap,
            // so for standard rendering, we disable our custom rendering.
            // But if you went you can enable it and disabled the standard rendering - this will always render objects ids:
            //
            //_objectIdRenderingStep.IsEnabled = true;
            //MainDXViewportView.DXScene.DefaultRenderObjectsRenderingStep.IsEnabled = false;
        }