Exemple #1
0
        /// <summary>
        /// <para>Attaches the element to the specified host. To overide Attach, please override <see cref="OnAttach(IRenderHost)"/> function.</para>
        /// <para>To set different render technique instead of using technique from host, override <see cref="OnCreateRenderTechnique"/></para>
        /// <para>Attach Flow: <see cref="OnCreateRenderTechnique(IRenderHost)"/> -> Set RenderHost -> Get Effect -> <see cref="OnAttach(IRenderHost)"/> -> <see cref="InvalidateSceneGraph"/></para>
        /// </summary>
        /// <param name="host">The host.</param>
        public void Attach(IRenderHost host)
        {
            if (IsAttached || host == null || host.EffectsManager == null)
            {
                return;
            }
            renderHost           = host;
            this.renderTechnique = OnSetRenderTechnique != null?OnSetRenderTechnique(host) : OnCreateRenderTechnique(host);

            if (renderTechnique == null)
            {
                var techniqueName = RenderHost.EffectsManager.RenderTechniques.FirstOrDefault();
                if (string.IsNullOrEmpty(techniqueName))
                {
                    return;
                }
                renderTechnique = RenderHost.EffectsManager[techniqueName];
            }
            IsAttached = OnAttach(host);
            if (IsAttached)
            {
                Attached();
                OnAttached?.Invoke(this, EventArgs.Empty);
            }
            InvalidateSceneGraph();
        }
 public override void Attach(IRenderHost host)
 {             
     foreach (var c in this.Children)
     {
         c.Attach(host);
     }
 }
Exemple #3
0
 /// <summary>
 /// Attaches the specified host.
 /// </summary>
 /// <param name="host">The host.</param>
 public void Attach(IRenderHost host)
 {
     Items.Attach(host);
     ViewCube.Attach(host);
     CoordinateSystem.Attach(host);
     Items2D.Attach(host);
 }
Exemple #4
0
 /// <summary>
 /// Used to override Detach
 /// </summary>
 protected virtual void OnDetach()
 {
     IsAttached      = false;
     renderTechnique = null;
     effect          = null;
     renderHost      = null;
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="host"></param>
        protected override bool OnAttach(IRenderHost host)
        {
            if (!base.OnAttach(host))
            {
                return(false);
            }

            if (renderHost.IsDeferredLighting)
            {
                return(false);
            }

            OnCreateGeometryBuffers();

            // --- set up const variables
            vPointParams = effect.GetVariableByName("vPointParams").AsVector();

            // --- set effect per object const vars
            var pointParams = new Vector4((float)Size.Width, (float)Size.Height, (float)Figure, (float)FigureRatio);

            vPointParams.Set(pointParams);

            // --- flush
            //Device.ImmediateContext.Flush();
            return(true);
        }
 public override void Attach(IRenderHost host)
 {
     foreach (var c in this.Children)
     {
         c.Attach(host);
     }
 }
        protected override bool OnAttach(IRenderHost host)
        {
            // --- attach
            if (!base.OnAttach(host))
            {
                return(false);
            }

            // --- shader variables
            vViewport          = effect.GetVariableByName("vViewport").AsVector();
            bFixedSizeVariable = effect.GetVariableByName("bBillboardFixedSize").AsScalar();
            // --- get geometry
            var geometry = geometryInternal as IBillboardText;

            if (geometry == null)
            {
                throw new System.Exception("Geometry must implement IBillboardText");
            }

            // --- material
            // this.AttachMaterial();
            this.bHasBillboardTexture          = effect.GetVariableByName("bHasTexture").AsScalar();
            this.billboardTextureVariable      = effect.GetVariableByName("billboardTexture").AsShaderResource();
            this.billboardAlphaTextureVariable = effect.GetVariableByName("billboardAlphaTexture").AsShaderResource();
            this.bHasBillboardAlphaTexture     = effect.GetVariableByName("bHasAlphaTexture").AsScalar();
            OnCreateGeometryBuffers();
            // --- set rasterstate
            OnRasterStateChanged();

            // --- flush
            //Device.ImmediateContext.Flush();
            return(true);
        }
Exemple #8
0
 /// <summary>
 /// Attaches the element to the specified host.
 /// </summary>
 /// <param name="host">The host.</param>
 public virtual void Attach(IRenderHost host)
 {
     this.renderTechnique = this.renderTechnique == null ? host.RenderTechnique : this.renderTechnique;
     this.effect          = EffectsManager.Instance.GetEffect(renderTechnique);
     this.renderHost      = host;
     this.InvalidateRender();
 }
        protected override bool OnAttach(IRenderHost host)
        {
            // --- attach
            if (base.OnAttach(host))
            {
                // --- light constant params
                this.vLightPos   = this.effect.GetVariableByName("vLightPos").AsVector();
                this.vLightDir   = this.effect.GetVariableByName("vLightDir").AsVector();
                this.vLightSpot  = this.effect.GetVariableByName("vLightSpot").AsVector();
                this.vLightColor = this.effect.GetVariableByName("vLightColor").AsVector();
                this.vLightAtt   = this.effect.GetVariableByName("vLightAtt").AsVector();
                this.iLightType  = this.effect.GetVariableByName("iLightType").AsScalar();

                // --- Set light type
                Light3DSceneShared.LightTypes[lightIndex] = (int)this.LightType;

                // --- flush
                // this.Device.ImmediateContext.Flush();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #10
0
 /// <summary>
 /// Attaches the element to the specified host.
 /// </summary>
 /// <param name="host">The host.</param>
 public virtual void Attach(IRenderHost host)
 {
     this.isAttached = true;
     this.device     = host.Device;
     this.effect     = host.Effects[effectName];
     this.renderHost = host;
 }
        protected override bool OnAttach(IRenderHost host)
        {
            if (!base.OnAttach(host))
            {
                return(false);
            }

            AttachMaterial();

            var geometry = Geometry as MeshGeometry3D;

            if (geometry == null)
            {
                throw new Exception("Geometry must not be null");
            }
            OnCreateGeometryBuffers();
            hasInstances  = (Instances != null) && (Instances.Any());
            bHasInstances = effect.GetVariableByName("bHasInstances").AsScalar();
            OnRasterStateChanged();
            if (hasInstances)
            {
                isInstanceChanged = true;
            }
            // Device.ImmediateContext.Flush();
            return(true);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="host"></param>
        /// <param name="format"></param>
        internal void CreateBuffers(IRenderHost host, Format format = Format.R32G32B32A32_Float)
        {
            /// set class variables
            this.renderHost   = host;
            this.device       = host.Device;
            this.targetWidth  = Math.Max((int)host.ActualWidth, 100);
            this.targetHeight = Math.Max((int)host.ActualHeight, 100);

            /// clear old buffers
            this.ClearGBuffer();
            this.screenQuad.Dispose();
            this.screenSphere.Dispose();
            this.screenCone.Dispose();

            /// create new buffers
            this.CreateQuadBuffer();
            this.CreateSphereBuffer();
            this.CreateConeBuffer();
            this.CreateGBuffer(format);



            /// flush
            this.device.ImmediateContext.Flush();
        }
        /// <summary>
        /// Override PointGeometryModel3D's Attach method to 
        /// provide a buffer of DynamoPointVertices
        /// </summary>
        public override void Attach(IRenderHost host)
        {
            var techManager = host.RenderTechniquesManager;

            renderTechnique = techManager.RenderTechniques[DefaultRenderTechniqueNames.Points];
            base.Attach(host);

            if (Geometry == null)
                return;

            if (renderHost.RenderTechnique == host.RenderTechniquesManager.RenderTechniques.Get(DeferredRenderTechniqueNames.Deferred) ||
                renderHost.RenderTechnique == host.RenderTechniquesManager.RenderTechniques.Get(DeferredRenderTechniqueNames.Deferred))
                return;

            vertexLayout = host.EffectsManager.GetLayout(renderTechnique);
            effectTechnique = effect.GetTechniqueByName(renderTechnique.Name);

            effectTransforms = new EffectTransformVariables(effect);

            var geometry = Geometry as PointGeometry3D;
            if (geometry != null)
            {          
                vertexBuffer = Device.CreateBuffer(BindFlags.VertexBuffer, VertexSizeInBytes, CreateVertexArray());
            }

            vViewport = effect.GetVariableByName("vViewport").AsVector();
            vPointParams = effect.GetVariableByName("vPointParams").AsVector();

            var pointParams = new Vector4((float)Size.Width, (float)Size.Height, (float)Figure, (float)FigureRatio);
            vPointParams.Set(pointParams);

            OnRasterStateChanged(DepthBias);

            Device.ImmediateContext.Flush();
        }
Exemple #14
0
 /// <summary>
 /// Attaches the element to the specified host.
 /// </summary>
 /// <param name="host">The host.</param>
 public virtual void Attach(IRenderHost host)
 {
     renderTechnique = this.renderTechnique == null ? host.RenderTechnique : this.renderTechnique;
     renderHost      = host;
     effect          = renderHost.EffectsManager.GetEffect(renderTechnique);
     InvalidateRender();
 }
Exemple #15
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="host"></param>
        protected override bool OnAttach(IRenderHost host)
        {
            // --- attach
            if (!base.OnAttach(host))
            {
                return(false);
            }

            // --- scale texcoords
            var texScale = TextureCoodScale;

            // --- get geometry
            var geometry = this.geometryInternal as MeshGeometry3D;

            // -- set geometry if given
            if (geometry != null)
            {
                //throw new HelixToolkitException("Geometry not found!");

                // --- init vertex buffer
                OnCreateGeometryBuffers();
            }
            else
            {
                throw new System.Exception("Geometry must not be null");
            }
            bInvertNormalVar = effect.GetVariableByName("bInvertNormal").AsScalar();
            // --- flush
            //this.Device.ImmediateContext.Flush();
            return(true);
        }
Exemple #16
0
 /// <summary>
 /// Attaches the element to the specified host.
 /// </summary>
 /// <param name="host">The host.</param>
 public virtual void Attach(IRenderHost host)
 {
     this.isAttached = true;
     this.device = host.Device;
     this.effect = host.Effects[effectName];
     this.renderHost = host;
 }
Exemple #17
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="host"></param>
        public override void Attach(IRenderHost host)
        {
            // --- attach
            this.renderTechnique = host.RenderTechnique;
            base.Attach(host);

            if (this.Geometry == null ||
                this.Geometry.Positions == null || this.Geometry.Positions.Count == 0 ||
                this.Geometry.Indices == null || this.Geometry.Indices.Count == 0)
            {
                return;
            }

            // --- get variables
            this.vertexLayout    = renderHost.EffectsManager.GetLayout(this.renderTechnique);
            this.effectTechnique = effect.GetTechniqueByName(this.renderTechnique.Name);

            // --- transformations
            this.effectTransforms = new EffectTransformVariables(this.effect);

            // --- material
            this.AttachMaterial();

            // --- scale texcoords
            var texScale = TextureCoodScale;

            // --- get geometry
            var geometry = this.Geometry as MeshGeometry3D;

            // -- set geometry if given
            if (geometry != null)
            {
                //throw new HelixToolkitException("Geometry not found!");

                /// --- init vertex buffer
                this.vertexBuffer = Device.CreateBuffer(BindFlags.VertexBuffer, VertexSizeInBytes, this.CreateDefaultVertexArray());

                /// --- init index buffer
                this.indexBuffer = Device.CreateBuffer(BindFlags.IndexBuffer, sizeof(int), this.Geometry.Indices.Array);
            }
            else
            {
                throw new System.Exception("Geometry must not be null");
            }

            /// --- init instances buffer
            this.hasInstances  = (this.Instances != null) && (this.Instances.Any());
            this.bHasInstances = this.effect.GetVariableByName("bHasInstances").AsScalar();
            if (this.hasInstances)
            {
                this.instanceBuffer = Buffer.Create(this.Device, this.instanceArray, new BufferDescription(Matrix.SizeInBytes * this.instanceArray.Length, ResourceUsage.Dynamic, BindFlags.VertexBuffer, CpuAccessFlags.Write, ResourceOptionFlags.None, 0));
            }

            /// --- set rasterstate
            this.OnRasterStateChanged();

            /// --- flush
            this.Device.ImmediateContext.Flush();
        }
        public override void Attach(IRenderHost host)
        {
            /// --- attach
            this.renderTechnique = Techniques.RenderCubeMap;
            base.Attach(host);

            /// --- get variables               
            this.vertexLayout = EffectsManager.Instance.GetLayout(this.renderTechnique);
            this.effectTechnique = effect.GetTechniqueByName(this.renderTechnique.Name);
            this.effectTransforms = new EffectTransformVariables(this.effect);

            /// -- attach cube map 
            if (this.Filename != null)
            {
                /// -- attach texture
                using (var texture = Texture2D.FromFile<Texture2D>(this.Device, this.Filename))
                {
                    this.texCubeMapView = new ShaderResourceView(this.Device, texture);
                }
                this.texCubeMap = effect.GetVariableByName("texCubeMap").AsShaderResource();
                this.texCubeMap.SetResource(this.texCubeMapView);
                this.bHasCubeMap = effect.GetVariableByName("bHasCubeMap").AsScalar();
                this.bHasCubeMap.Set(true);

                /// --- set up geometry
                var sphere = new MeshBuilder(false,true,false);
                sphere.AddSphere(new Vector3(0, 0, 0));
                this.geometry = sphere.ToMeshGeometry3D();

                /// --- set up vertex buffer
                this.vertexBuffer = Device.CreateBuffer(BindFlags.VertexBuffer, CubeVertex.SizeInBytes, this.geometry.Positions.Select((x, ii) => new CubeVertex() { Position = new Vector4(x, 1f) }).ToArray());

                /// --- set up index buffer
                this.indexBuffer = Device.CreateBuffer(BindFlags.IndexBuffer, sizeof(int), geometry.Indices.Array);

                /// --- set up rasterizer states
                var rasterStateDesc = new RasterizerStateDescription()
                {
                    FillMode = FillMode.Solid,
                    CullMode = CullMode.Back,
                    IsMultisampleEnabled = true,
                    IsAntialiasedLineEnabled = true,
                    IsFrontCounterClockwise = false,
                };
                this.rasterState = new RasterizerState(this.Device, rasterStateDesc);

                /// --- set up depth stencil state
                var depthStencilDesc = new DepthStencilStateDescription()
                {
                    DepthComparison = Comparison.LessEqual,
                    DepthWriteMask = global::SharpDX.Direct3D11.DepthWriteMask.All,
                    IsDepthEnabled = true,
                };
                this.depthStencilState = new DepthStencilState(this.Device, depthStencilDesc);
            }

            /// --- flush
            this.Device.ImmediateContext.Flush();
        }
 /// <summary>
 /// To override Attach routine, please override this.
 /// </summary>
 /// <param name="host"></param>
 /// <returns>
 /// Return true if attached
 /// </returns>
 protected override bool OnAttach(IRenderHost host)
 {
     base.OnAttach(host);
     shadowCore              = RenderCore as ShadowMapCore;
     host.SceneGraphUpdated += Host_SceneGraphUpdated;
     sceneChanged            = true;
     return(true);
 }
Exemple #20
0
 /// <summary>
 /// Called when [attach].
 /// </summary>
 /// <param name="target">The target.</param>
 /// <returns></returns>
 protected override bool OnAttach(IRenderHost target)
 {
     factory         = new Factory(FactoryType.Isolated);
     format          = new TextFormat(factory, "Arial", 12 * target.DpiScale);
     previousStr     = string.Empty;
     this.statistics = target.RenderStatistics;
     return(base.OnAttach(target));
 }
 public void Attach(IRenderHost host)
 {
     if (host.FeatureLevel >= global::SharpDX.Direct3D.FeatureLevel.Level_11_0)
     {
         transparentRenderCore.Attach(host.EffectsManager.GetTechnique(DefaultRenderTechniqueNames.MeshOITQuad));
         postFXAACore.Attach(host.EffectsManager.GetTechnique(DefaultRenderTechniqueNames.PostEffectFXAA));
     }
 }
Exemple #22
0
 /// <summary>
 /// Attaches the specified host.
 /// </summary>
 /// <param name="host">The host.</param>
 public void Attach(IRenderHost host)
 {
     if (IsAttached)
     {
         return;
     }
     IsAttached = OnAttach(host);
 }
Exemple #23
0
 /// <summary>
 /// Called when [attach].
 /// </summary>
 /// <param name="host">The host.</param>
 /// <returns></returns>
 protected override bool OnAttach(IRenderHost host)
 {
     for (int i = 0; i < Items.Count; ++i)
     {
         Items[i].Attach(host);
     }
     return(true);
 }
 /// <summary>
 /// Called when [attach].
 /// </summary>
 /// <param name="host">The host.</param>
 /// <returns></returns>
 protected override bool OnAttach(IRenderHost host)
 {
     base.OnAttach(host);
     InstanceBuffer.Initialize();
     InstanceBuffer.Elements     = Instances;
     particleCore.InstanceBuffer = InstanceBuffer;
     return(true);
 }
 /// <summary>
 /// Called when [attach].
 /// </summary>
 /// <param name="target">The target.</param>
 /// <returns></returns>
 protected override bool OnAttach(IRenderHost target)
 {
     factory         = Collect(new Factory(FactoryType.Isolated));
     format          = Collect(new TextFormat(factory, "Arial", 12));
     previousStr     = "";
     this.statistics = target.RenderStatistics;
     return(base.OnAttach(target));
 }
Exemple #26
0
        protected override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            hostPresenter = GetTemplateChild(ViewportPartNames.PART_HostPresenter) as ContentPresenter;
            if (hostPresenter != null)
            {
                hostPresenter.Content = new SwapChainRenderHost(EnableDeferredRendering);
                renderHostInternal    = (hostPresenter.Content as SwapChainRenderHost).RenderHost;
                if (renderHostInternal != null)
                {
                    renderHostInternal.Viewport            = this;
                    renderHostInternal.IsRendering         = Visibility == Visibility.Visible;
                    renderHostInternal.EffectsManager      = this.EffectsManager;
                    renderHostInternal.RenderTechnique     = this.RenderTechnique;
                    renderHostInternal.ClearColor          = this.BackgroundColor.ToColor4();
                    renderHostInternal.EnableRenderFrustum = this.EnableRenderFrustum;
                    renderHostInternal.IsShadowMapEnabled  = this.IsShadowMappingEnabled;
#if MSAA
                    renderHostInternal.MSAA = this.MSAA;
#endif
                    renderHostInternal.RenderConfiguration.AutoUpdateOctree = this.EnableAutoOctreeUpdate;
                    renderHostInternal.ExceptionOccurred += RenderHostInternal_ExceptionOccurred;
                }
            }
            if (viewCube == null)
            {
                viewCube = GetTemplateChild(ViewportPartNames.PART_ViewCube) as ViewBoxModel3D;
                if (viewCube != null)
                {
                    viewCube.ViewBoxClickedEvent += ViewCube_ViewBoxClickedEvent;
                }
            }

            if (viewCube == null)
            {
                throw new HelixToolkitException("{0} is missing from the template.", ViewportPartNames.PART_ViewCube);
            }
            else
            {
                viewCube.RelativeScreenLocationX = ViewCubeHorizontalPosition;
                viewCube.RelativeScreenLocationY = ViewCubeVerticalPosition;
                viewCube.UpDirection             = ModelUpDirection;
            }

            if (coordinateSystem == null)
            {
                coordinateSystem = GetTemplateChild(ViewportPartNames.PART_CoordinateView) as CoordinateSystemModel3D;
            }
            if (coordinateSystem == null)
            {
                throw new HelixToolkitException("{0} is missing from the template.", ViewportPartNames.PART_CoordinateView);
            }
            else
            {
                coordinateSystem.RelativeScreenLocationX = CoordinateSystemHorizontalPosition;
                coordinateSystem.RelativeScreenLocationY = CoordinateSystemVerticalPosition;
            }
        }
Exemple #27
0
 protected override bool OnAttach(IRenderHost host)
 {
     Light3DSceneShared = host.Light3DSceneShared;
     foreach (var c in this.Items)
     {
         c.Attach(host);
     }
     return(true);
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="host"></param>
        public override void Attach(IRenderHost host)
        {
            /// --- attach
            this.effectName = host.RenderTechnique.ToString();
            base.Attach(host);

            // --- get variables
            this.vertexLayout    = host.Effects.GetLayout(this.effectName);
            this.shaderTechnique = effect.GetTechniqueByName(this.effectName);

            // --- get the pass
            this.shaderPass = this.shaderTechnique.GetPassByName(this.Shading);

            // -- get geometry
            this.geometry = this.Geometry as MeshGeometry3D;


            if (this.geometry == null)
            {
                throw new HelixToolkitException("Geometry not found!");
            }

            /// --- model transformation
            this.effectTransforms = new EffectTransformVariables(this.effect);

            /// --- material
            this.AttachMaterial();

            /// --- init vertex buffer
            this.vertexBuffer = device.CreateBuffer(BindFlags.VertexBuffer, DefaultVertex.SizeInBytes, this.geometry.Positions.Select((x, ii) => new DefaultVertex()
            {
                Position  = new Vector4(x, 1f),
                Color     = this.geometry.Colors != null ? this.geometry.Colors[ii] : new Color4(1f, 0f, 0f, 1f),
                TexCoord  = this.geometry.TextureCoordinates != null ? this.geometry.TextureCoordinates[ii] : new Vector2(),
                Normal    = this.geometry.Normals != null ? this.geometry.Normals[ii] : new Vector3(),
                Tangent   = this.geometry.Tangents != null ? this.geometry.BiTangents[ii] : new Vector3(),
                BiTangent = this.geometry.BiTangents != null ? this.geometry.BiTangents[ii] : new Vector3(),
            }).ToArray());

            /// --- init index buffer
            this.indexBuffer = device.CreateBuffer(BindFlags.IndexBuffer, sizeof(int), this.geometry.Indices);

            ///// --- init instances buffer
            //this.hasInstances = this.Instances != null;
            //this.bHasInstances = this.effect.GetVariableByName("bHasInstances").AsScalar();
            //if (this.hasInstances)
            //{
            //    this.instanceBuffer = Buffer.Create(this.device, this.instanceArray, new BufferDescription(Matrix.SizeInBytes * this.instanceArray.Length, ResourceUsage.Dynamic, BindFlags.VertexBuffer, CpuAccessFlags.Write, ResourceOptionFlags.None, 0));
            //}

            /// --- init tessellation vars
            this.vTessellationVariables = effect.GetVariableByName("vTessellation").AsVector();
            this.vTessellationVariables.Set(new Vector4((float)this.TessellationFactor, 0, 0, 0));

            /// --- flush
            this.device.ImmediateContext.Flush();
        }
        /// <summary>
        /// Called when [attach].
        /// </summary>
        /// <param name="host">The host.</param>
        /// <returns></returns>
        protected override bool OnAttach(IRenderHost host)
        {
            RenderCore.Attach(renderTechnique);
            var screenSpaceCore = RenderCore as ScreenSpacedMeshRenderCore;

            screenSpaceCore.RelativeScreenLocationX = RelativeScreenLocationX;
            screenSpaceCore.RelativeScreenLocationY = RelativeScreenLocationY;
            screenSpaceCore.SizeScale = SizeScale;
            return(base.OnAttach(host));
        }
Exemple #30
0
 /// <summary>
 /// To override Attach routine, please override this.
 /// </summary>
 /// <param name="host"></param>
 /// <returns>
 /// Return true if attached
 /// </returns>
 protected override bool OnAttach(IRenderHost host)
 {
     // --- attach
     if (!base.OnAttach(host))
     {
         return(false);
     }
     instanceParamBuffer.Initialize();
     return(true);
 }
Exemple #31
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RenderContext"/> class.
 /// </summary>
 /// <param name="renderHost">The render host.</param>
 /// <param name="renderContext">The render context.</param>
 public RenderContext(IRenderHost renderHost, DeviceContext renderContext)
 {
     this.RenderHost     = renderHost;
     this.IsShadowPass   = false;
     this.IsDeferredPass = false;
     cbuffer             = renderHost.EffectsManager.ConstantBufferPool.Register(DefaultBufferNames.GlobalTransformCB, GlobalTransformStruct.SizeInBytes);
     DeviceContext       = renderContext;
     LightScene          = Collect(new Light3DSceneShared(renderHost.EffectsManager.ConstantBufferPool));
     SharedResource      = Collect(new ContextSharedResource());
 }
 public void Attach(IRenderHost host)
 {
     if (host.FeatureLevel >= global::SharpDX.Direct3D.FeatureLevel.Level_11_0)
     {
         oitWeightedCore.Attach(host.EffectsManager.GetTechnique(DefaultRenderTechniqueNames.MeshOITQuad));
         oitDepthPeelingCore.Attach(host.EffectsManager.GetTechnique(DefaultRenderTechniqueNames.MeshOITDepthPeeling));
         postFXAACore.Attach(host.EffectsManager.GetTechnique(DefaultRenderTechniqueNames.PostEffectFXAA));
         preSSAOCore.Attach(host.EffectsManager.GetTechnique(DefaultRenderTechniqueNames.SSAO));
     }
 }
 /// <summary>
 /// Attaches the specified host.
 /// </summary>
 /// <param name="host">The host.</param>
 public void Attach(IRenderHost host)
 {
     if (Interlocked.Increment(ref d3dCounter) == 1 && host.EffectsManager != null)
     {
         foreach (var renderable in Renderables)
         {
             renderable.Attach(host);
         }
     }
 }
Exemple #34
0
 /// <summary>
 /// Attaches the specified host.
 /// </summary>
 /// <param name="host">The host.</param>
 public void Attach(IRenderHost host)
 {
     Items.Attach(host.EffectsManager);
     Items.Invalidated += Items_Invalidated;
     ViewCube.Attach(host.EffectsManager);
     ViewCube.Invalidated += Items_Invalidated;
     CoordinateSystem.Attach(host.EffectsManager);
     CoordinateSystem.Invalidated += Items_Invalidated;
     Items2D.Attach(host);
 }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="host"></param>
        public override void Attach(IRenderHost host)
        {
            // --- attach
            this.renderTechnique = host.RenderTechnique;
            base.Attach(host);

            if (this.Geometry == null)
                return;

            // --- get variables
            this.vertexLayout = EffectsManager.Instance.GetLayout(this.renderTechnique);
            this.effectTechnique = effect.GetTechniqueByName(this.renderTechnique.Name);

            // --- transformations
            this.effectTransforms = new EffectTransformVariables(this.effect);

            // --- material
            this.AttachMaterial();

            // --- scale texcoords
            var texScale = TextureCoodScale;

            // --- get geometry
            var geometry = this.Geometry as MeshGeometry3D;

            // -- set geometry if given
            if (geometry != null)
            {
                //throw new HelixToolkitException("Geometry not found!");

                /// --- init vertex buffer
                this.vertexBuffer = Device.CreateBuffer(BindFlags.VertexBuffer, DefaultVertex.SizeInBytes, this.CreateDefaultVertexArray());

                /// --- init index buffer
                this.indexBuffer = Device.CreateBuffer(BindFlags.IndexBuffer, sizeof(int), this.Geometry.Indices.Array);
            }
            else
            {
                throw new System.Exception("Geometry must not be null");
            }

            /// --- init instances buffer
            this.hasInstances = (this.Instances != null) && (this.Instances.Any());
            this.bHasInstances = this.effect.GetVariableByName("bHasInstances").AsScalar();
            if (this.hasInstances)
            {
                this.instanceBuffer = Buffer.Create(this.Device, this.instanceArray, new BufferDescription(Matrix.SizeInBytes * this.instanceArray.Length, ResourceUsage.Dynamic, BindFlags.VertexBuffer, CpuAccessFlags.Write, ResourceOptionFlags.None, 0));
            }

            /// --- set rasterstate
            this.OnRasterStateChanged(this.DepthBias);

            /// --- flush
            this.Device.ImmediateContext.Flush();
        }
        public override void Attach(IRenderHost host)
        {
            foreach (var c in this.Children)
            {
                if (c.Parent == null)
                {
                    this.AddLogicalChild(c);
                }

                c.Attach(host);
            }
        }
        public RenderContext(IRenderHost canvas, Effect effect)
        {
            this.Canvas = canvas;
            this.IsShadowPass = false;
            this.IsDeferredPass = false;

            this.mView = effect.GetVariableByName("mView").AsMatrix();
            this.mProjection = effect.GetVariableByName("mProjection").AsMatrix();
            this.vViewport = effect.GetVariableByName("vViewport").AsVector();
            this.vFrustum = effect.GetVariableByName("vFrustum").AsVector();
            this.vEyePos = effect.GetVariableByName("vEyePos").AsVector();                     
        }
        public override void Attach(IRenderHost host)
        {
            /// --- attach
            base.Attach(host);

            /// --- light constant params              
            this.vLightAmbient = this.effect.GetVariableByName("vLightAmbient").AsVector();
            this.vLightAmbient.Set(this.Color);            

            /// --- flush
            this.Device.ImmediateContext.Flush();            
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="host"></param>
        public override void Attach(IRenderHost host)
        {
            /// --- attach
            this.effectName = host.RenderTechnique.ToString();
            base.Attach(host);

            // --- get variables
            this.vertexLayout = host.Effects.GetLayout(this.effectName);
            this.shaderTechnique = effect.GetTechniqueByName(this.effectName);
            this.geometry = this.Geometry as MeshGeometry3D;

            if (this.geometry == null)
            {
                throw new HelixToolkitException("Geometry not found!");
            }
                        
            /// --- transformations
            this.effectTransforms = new EffectTransformVariables(this.effect);

            /// --- material 
            this.AttachMaterial();

            /// scale texcoords
            var texScale = TextureCoodScale;

            /// --- init vertex buffer
            this.vertexBuffer = device.CreateBuffer(BindFlags.VertexBuffer, DefaultVertex.SizeInBytes, this.geometry.Positions.Select((x, ii) => new DefaultVertex()
            {
                Position   = new Vector4(x, 1f),
                Color      = this.geometry.Colors == null     ? new Color4(1f, 1f, 1f, 1f) : this.geometry.Colors[ii],
                TexCoord   = this.geometry.TextureCoordinates == null ? new Vector2() : texScale*this.geometry.TextureCoordinates[ii],
                Normal     = this.geometry.Normals == null    ? new Vector3() : this.geometry.Normals[ii],
                Tangent    = this.geometry.Tangents != null   ? this.geometry.BiTangents[ii] : new Vector3(),
                BiTangent  = this.geometry.BiTangents != null ? this.geometry.BiTangents[ii] : new Vector3(),
            }).ToArray());

            /// --- init index buffer
            this.indexBuffer = device.CreateBuffer(BindFlags.IndexBuffer, sizeof(int), this.geometry.Indices);

            /// --- init instances buffer            
            this.hasInstances = this.Instances != null;            
            this.bHasInstances = this.effect.GetVariableByName("bHasInstances").AsScalar();
            if (this.hasInstances)
            {                
                this.instanceBuffer = Buffer.Create(this.device, this.instanceArray, new BufferDescription(Matrix.SizeInBytes * this.instanceArray.Length, ResourceUsage.Dynamic, BindFlags.VertexBuffer, CpuAccessFlags.Write, ResourceOptionFlags.None, 0));                            
            }

            /// --- set rasterstate
            this.OnRasterStateChanged(this.DepthBias);

            /// --- flush
            this.device.ImmediateContext.Flush();
        }
        /// <summary>
        /// Attaches the specified host.
        /// </summary>
        /// <param name="host">
        /// The host.
        /// </param>
        public override void Attach(IRenderHost host)
        {
            base.Attach(host);
            foreach (var model in this.Children)
            {
                if (model.Parent == null)
                {
                    this.AddLogicalChild(model);
                }

                model.Attach(host);
            }
        }
        public override void Attach(IRenderHost host)
        {
            /// --- attach
            base.Attach(host);

            /// --- light constant params
            this.vLightDir = this.effect.GetVariableByName("vLightDir").AsVector();
            this.vLightColor = this.effect.GetVariableByName("vLightColor").AsVector();
            this.iLightType = this.effect.GetVariableByName("iLightType").AsScalar();

            /// --- Set light type
            lightTypes[lightIndex] = (int)Light3D.Type.Directional;

            /// --- flush
            this.Device.ImmediateContext.Flush();
        }
        public override void Attach(IRenderHost host)
        {
            renderTechnique = host.RenderTechniquesManager.RenderTechniques[DefaultRenderTechniqueNames.Lines];
            base.Attach(host);

            if (Geometry == null)
                return;

            if (host.SupportDeferredRender)
            {
                if (renderHost.RenderTechnique == host.RenderTechniquesManager.RenderTechniques[DeferredRenderTechniqueNames.Deferred] ||
                    renderHost.RenderTechnique == host.RenderTechniquesManager.RenderTechniques[DeferredRenderTechniqueNames.GBuffer])
                    return;
            }

            vertexLayout = renderHost.EffectsManager.GetLayout(renderTechnique);
            effectTechnique = effect.GetTechniqueByName(renderTechnique.Name);

            effectTransforms = new EffectTransformVariables(effect);

            var geometry = Geometry as LineGeometry3D;

            if (geometry != null)
            {
                vertexBuffer = Device.CreateBuffer(BindFlags.VertexBuffer, VertexSizeInBytes, CreateVertexArray());
                indexBuffer = Device.CreateBuffer(BindFlags.IndexBuffer, sizeof(int), geometry.Indices.ToArray());
            }

            hasInstances = (Instances != null) && (Instances.Any());
            bHasInstances = effect.GetVariableByName("bHasInstances").AsScalar();
            if (hasInstances)
            {
                instanceBuffer = Buffer.Create(Device, instanceArray, new BufferDescription(Matrix.SizeInBytes * instanceArray.Length, ResourceUsage.Dynamic, BindFlags.VertexBuffer, CpuAccessFlags.Write, ResourceOptionFlags.None, 0));
            }

            vViewport = effect.GetVariableByName("vViewport").AsVector();
            vLineParams = effect.GetVariableByName("vLineParams").AsVector();

            var lineParams = new Vector4((float)Thickness, (float)Smoothness, 0, 0);
            vLineParams.Set(lineParams);

            OnRasterStateChanged(DepthBias);

            Device.ImmediateContext.Flush();
        }
        public override void Attach(IRenderHost host)
        {
            // --- attach
            renderTechnique = host.RenderTechniquesManager.RenderTechniques[DefaultRenderTechniqueNames.BillboardText];
            effect = host.EffectsManager.GetEffect(renderTechnique);
            renderHost = host;

            // --- get variables
            vertexLayout = renderHost.EffectsManager.GetLayout(renderTechnique);
            effectTechnique = effect.GetTechniqueByName(renderTechnique.Name);

            // --- transformations
            effectTransforms = new EffectTransformVariables(effect);

            // --- shader variables
            vViewport = effect.GetVariableByName("vViewport").AsVector();

            // --- get geometry
            var geometry = Geometry as BillboardText3D;
            if (geometry == null)
            {
                return;
            }

            // --- material
            // this.AttachMaterial();
            billboardTextureVariable = effect.GetVariableByName("billboardTexture").AsShaderResource();

            var textureBytes = BillboardText3D.Texture.ToByteArray();
             //   billboardTextureView =new ShaderResourceView(Device, BillboardText3D.Texture);
            billboardTextureVariable.SetResource(billboardTextureView);

            // -- set geometry if given
            vertexBuffer = Device.CreateBuffer(BindFlags.VertexBuffer,
                VertexSizeInBytes, CreateBillboardVertexArray());

            /// --- set rasterstate
            OnRasterStateChanged(DepthBias);

            /// --- flush
            Device.ImmediateContext.Flush();
        }
        public override void Attach(IRenderHost host)
        {
            // --- attach
            this.renderTechnique = Techniques.RenderBillboard;
            this.effect = EffectsManager.Instance.GetEffect(renderTechnique);
            this.renderHost = host;

            // --- get variables
            this.vertexLayout = EffectsManager.Instance.GetLayout(this.renderTechnique);
            this.effectTechnique = effect.GetTechniqueByName(this.renderTechnique.Name);

            // --- transformations
            this.effectTransforms = new EffectTransformVariables(this.effect);

            // --- shader variables
            this.vViewport = effect.GetVariableByName("vViewport").AsVector();

            // --- get geometry
            var geometry = this.Geometry as BillboardText3D;
            if (geometry == null)
            {
                return;
            }

            // --- material
            // this.AttachMaterial();
            billboardTextureVariable = effect.GetVariableByName("billboardTexture").AsShaderResource();

            var textureBytes = geometry.Texture.ToByteArray();
            billboardTextureView = ShaderResourceView.FromMemory(Device, textureBytes);
            billboardTextureVariable.SetResource(billboardTextureView);

            // -- set geometry if given
            vertexBuffer = Device.CreateBuffer(BindFlags.VertexBuffer,
                DefaultVertex.SizeInBytes, CreateBillboardVertexArray());

            /// --- set rasterstate
            this.OnRasterStateChanged(this.DepthBias);

            /// --- flush
            this.Device.ImmediateContext.Flush();
        }
        /// <summary>
        /// By overriding Attach, we can provide our own vertex array.
        /// </summary>
        /// <param name="host">An object whose type implements IRenderHost.</param>
        public override void Attach(IRenderHost host)
        {
            renderTechnique = host.RenderTechniquesManager.RenderTechniques[DefaultRenderTechniqueNames.Points];
            base.Attach(host);

            if (Geometry == null)
                return;

            if (renderHost.RenderTechnique == renderHost.RenderTechniquesManager.RenderTechniques.Get(DeferredRenderTechniqueNames.Deferred) ||
                renderHost.RenderTechnique == renderHost.RenderTechniquesManager.RenderTechniques.Get(DeferredRenderTechniqueNames.GBuffer))
                return;

            vertexLayout = renderHost.EffectsManager.GetLayout(renderTechnique);
            effectTechnique = effect.GetTechniqueByName(renderTechnique.Name);

            effectTransforms = new EffectTransformVariables(effect);

            var geometry = Geometry as PointGeometry3D;

            if (geometry != null)
            {
                /// --- set up buffers            
                vertexBuffer = Device.CreateBuffer(BindFlags.VertexBuffer, VertexSizeInBytes, CreateVertexArray());
            }

            /// --- set up const variables
            vViewport = effect.GetVariableByName("vViewport").AsVector();
            //this.vFrustum = effect.GetVariableByName("vFrustum").AsVector();
            vPointParams = effect.GetVariableByName("vPointParams").AsVector();

            /// --- set effect per object const vars
            var pointParams = new Vector4((float)Size.Width, (float)Size.Height, (float)Figure, (float)FigureRatio);
            vPointParams.Set(pointParams);

            /// --- create raster state
            OnRasterStateChanged();

            /// --- flush
            Device.ImmediateContext.Flush();
        }
        /// <summary>
        /// Attaches the specified host.
        /// </summary>
        /// <param name="host">
        /// The host.
        /// </param>
        public virtual void Attach(IRenderHost host)
        {
            this.renderHost = host;
            this.IsAttached = true;

            foreach (var item in this.children)
            {
                var model = item as Element3D;
                if (model != null)
                {
                    model.Attach(host);
                }
            }
        }
Exemple #47
0
        public override void Attach(IRenderHost host)
        {
            this.effectName = host.RenderTechnique.ToString();
            base.Attach(host);
            
            if (this.LightType != LightType.Ambient)
            {
                this.lightIndex = lightCount++;
                lightCount = lightCount % maxLights;

                if (host.IsShadowMapEnabled)
                {
                this.mLightView = this.effect.GetVariableByName("mLightView").AsMatrix();
                this.mLightProj = this.effect.GetVariableByName("mLightProj").AsMatrix();
            }
        }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="host"></param>
        public override void Attach(IRenderHost host)
        {
            /// --- attach
            this.renderTechnique = Techniques.RenderLines;
            base.Attach(host);

            if (this.Geometry == null)
                return;

            #if DEFERRED
            if (renderHost.RenderTechnique == Techniques.RenderDeferred || renderHost.RenderTechnique == Techniques.RenderGBuffer)
                return;
            #endif

            // --- get device
            this.vertexLayout = EffectsManager.Instance.GetLayout(this.renderTechnique);
            this.effectTechnique = effect.GetTechniqueByName(this.renderTechnique.Name);

            this.effectTransforms = new EffectTransformVariables(this.effect);

            // --- get geometry
            var geometry = this.Geometry as LineGeometry3D;

            // -- set geometry if given
            if (geometry != null)
            {
                /// --- set up buffers
                this.vertexBuffer = Device.CreateBuffer(BindFlags.VertexBuffer, LinesVertex.SizeInBytes, this.CreateLinesVertexArray());

                /// --- set up indexbuffer
                this.indexBuffer = Device.CreateBuffer(BindFlags.IndexBuffer, sizeof(int), geometry.Indices.Array);
            }

            /// --- init instances buffer
            this.hasInstances = (this.Instances != null)&&(this.Instances.Any());
            this.bHasInstances = this.effect.GetVariableByName("bHasInstances").AsScalar();
            if (this.hasInstances)
            {
                this.instanceBuffer = Buffer.Create(this.Device, this.instanceArray, new BufferDescription(Matrix.SizeInBytes * this.instanceArray.Length, ResourceUsage.Dynamic, BindFlags.VertexBuffer, CpuAccessFlags.Write, ResourceOptionFlags.None, 0));
            }

            /// --- set up const variables
            this.vViewport = effect.GetVariableByName("vViewport").AsVector();
            //this.vFrustum = effect.GetVariableByName("vFrustum").AsVector();
            this.vLineParams = effect.GetVariableByName("vLineParams").AsVector();

            /// --- set effect per object const vars
            var lineParams = new Vector4((float)this.Thickness, (float)this.Smoothness, 0, 0);
            this.vLineParams.Set(lineParams);

            /// === debug hack
            //{
            //    var texDiffuseMapView = ShaderResourceView.FromFile(device, @"G:\Projects\Deformation Project\FrameworkWPF2012\Externals\HelixToolkit-SharpDX\Source\Examples\SharpDX.Wpf\LightingDemo\TextureCheckerboard2.jpg");
            //    var texDiffuseMap = effect.GetVariableByName("texDiffuseMap").AsShaderResource();
            //    texDiffuseMap.SetResource(texDiffuseMapView);
            //}

            /// --- create raster state
            this.OnRasterStateChanged(this.DepthBias);

            //this.rasterState = new RasterizerState(this.device, rasterStateDesc);

            /// --- set up depth stencil state
            //var depthStencilDesc = new DepthStencilStateDescription()
            //{
            //    DepthComparison = Comparison.Less,
            //    DepthWriteMask = global::SharpDX.Direct3D11.DepthWriteMask.All,
            //    IsDepthEnabled = true,
            //};
            //this.depthStencilState = new DepthStencilState(this.device, depthStencilDesc);

            /// --- flush
            this.Device.ImmediateContext.Flush();
        }
Exemple #49
0
        public override void Attach(IRenderHost host)
        {
            this.width = (int)(Resolution.X + 0.5f); //faktor* oneK;
            this.height = (int)(this.Resolution.Y + 0.5f); // faktor* oneK;

            base.effectName = Techniques.RenderColors;
            base.Attach(host);

            if (!host.IsShadowMapEnabled)
            {
                return;
            }

            // gen shadow map
            this.depthBufferSM = new Texture2D(device, new Texture2DDescription()
            {
                Format = Format.R32_Typeless, //!!!! because of depth and shader resource
                //Format = global::SharpDX.DXGI.Format.B8G8R8A8_UNorm,
                ArraySize = 1,
                MipLevels = 1,
                Width = width,
                Height = height,
                SampleDescription = new SampleDescription(1, 0),
                Usage = ResourceUsage.Default,
                BindFlags = BindFlags.DepthStencil | BindFlags.ShaderResource, //!!!!
                CpuAccessFlags = CpuAccessFlags.None,
                OptionFlags = ResourceOptionFlags.None,
            });

            this.colorBufferSM = new Texture2D(this.device, new Texture2DDescription
            {
                BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
                Format = Format.B8G8R8A8_UNorm,
                Width = width,
                Height = height,
                MipLevels = 1,
                SampleDescription = new SampleDescription(1, 0),
                Usage = ResourceUsage.Default,
                OptionFlags = ResourceOptionFlags.None,
                CpuAccessFlags = CpuAccessFlags.None,
                ArraySize = 1
            });

            this.renderTargetSM = new RenderTargetView(this.device, colorBufferSM)
            {
            };

            this.depthViewSM = new DepthStencilView(device, depthBufferSM, new DepthStencilViewDescription()
            {
                Format = Format.D32_Float,
                Dimension = DepthStencilViewDimension.Texture2D,
                Texture2D = new DepthStencilViewDescription.Texture2DResource()
                {
                    MipSlice = 0
                }
            });

            this.texShadowMapView = new ShaderResourceView(device, depthBufferSM, new ShaderResourceViewDescription()
            {
                Format = Format.R32_Float,
                Dimension = ShaderResourceViewDimension.Texture2D,
                Texture2D = new ShaderResourceViewDescription.Texture2DResource()
                {
                    MipLevels = 1,
                    MostDetailedMip = 0,
                }
            }); //!!!!

            this.texColorMapView = new ShaderResourceView(this.device, colorBufferSM, new ShaderResourceViewDescription()
            {
                Format = Format.B8G8R8A8_UNorm,
                Dimension = ShaderResourceViewDimension.Texture2D,
                Texture2D = new ShaderResourceViewDescription.Texture2DResource()
                {
                    MipLevels = 1,
                    MostDetailedMip = 0,
                }
            });

            this.texShadowMapVariable = effect.GetVariableByName("texShadowMap").AsShaderResource();
            this.vShadowMapInfoVariable = effect.GetVariableByName("vShadowMapInfo").AsVector();
            this.vShadowMapSizeVariable = effect.GetVariableByName("vShadowMapSize").AsVector();
            this.shadowPassContext = new RenderContext((DPFCanvas)host, this.effect);
        }
 public override void Attach(IRenderHost host)
 {
     this.renderTechnique = host.RenderTechnique;
     base.Attach(host);
 }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="host"></param>
        public override void Attach(IRenderHost host)
        {
            renderTechnique = Techniques.RenderPoints;
            base.Attach(host);

            if (Geometry == null)
                return;

            #if DEFERRED
            if (renderHost.RenderTechnique == Techniques.RenderDeferred || renderHost.RenderTechnique == Techniques.RenderGBuffer)
                return;
            #endif

            // --- get device
            vertexLayout = EffectsManager.Instance.GetLayout(renderTechnique);
            effectTechnique = effect.GetTechniqueByName(renderTechnique.Name);

            effectTransforms = new EffectTransformVariables(effect);

            // --- get geometry
            var geometry = Geometry as PointGeometry3D;

            // -- set geometry if given
            if (geometry != null)
            {
                /// --- set up buffers
                vertexBuffer = Device.CreateBuffer(BindFlags.VertexBuffer, Geometry3D.PointsVertex.SizeInBytes, CreatePointVertexArray());
            }

            /// --- set up const variables
            vViewport = effect.GetVariableByName("vViewport").AsVector();
            //this.vFrustum = effect.GetVariableByName("vFrustum").AsVector();
            vPointParams = effect.GetVariableByName("vPointParams").AsVector();

            /// --- set effect per object const vars
            var pointParams = new Vector4((float)Size.Width, (float)Size.Height, (float)Figure, (float)FigureRatio);
            vPointParams.Set(pointParams);

            /// --- create raster state
            OnRasterStateChanged(DepthBias);

            /// --- flush
            Device.ImmediateContext.Flush();
        }
Exemple #52
0
        /// <summary>
        /// Attaches the elements to the specified host.
        /// </summary>
        /// <param name="host">The host.</param>
        void IRenderable.Attach(IRenderHost host)
        {
            foreach (Element3D e in this.Items)
            {
                e.Attach(host);
            }

            StopWatch.Start();
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="host"></param>
        /// <param name="format"></param>
        internal void CreateBuffers(IRenderHost host, Format format = Format.R32G32B32A32_Float)
        {
            /// set class variables
            this.renderHost = host;
            this.device = host.Device;
            this.targetWidth = Math.Max((int)host.ActualWidth, 100);
            this.targetHeight = Math.Max((int)host.ActualHeight, 100);

            /// clear old buffers
            this.ClearGBuffer();
            this.screenQuad.Dispose();
            this.screenSphere.Dispose();
            this.screenCone.Dispose();

            /// create new buffers            
            this.CreateQuadBuffer();
            this.CreateSphereBuffer();
            this.CreateConeBuffer();
            this.CreateGBuffer(format);



            /// flush
            this.device.ImmediateContext.Flush();
        }
        public override void Attach(IRenderHost host)
        {
            base.Attach(host);

            renderTechnique = host.RenderTechniquesManager.RenderTechniques["RenderCustom"];

            if (Geometry == null)
                return;

            vertexLayout = renderHost.EffectsManager.GetLayout(renderTechnique);
            effectTechnique = effect.GetTechniqueByName(renderTechnique.Name);

            effectTransforms = new EffectTransformVariables(effect);

            AttachMaterial();

            var geometry = Geometry as MeshGeometry3D;

            if (geometry == null)
            {
                throw new Exception("Geometry must not be null");
            }

            vertexBuffer = Device.CreateBuffer(BindFlags.VertexBuffer, VertexSizeInBytes,
                CreateCustomVertexArray());
            indexBuffer = Device.CreateBuffer(BindFlags.IndexBuffer, sizeof(int),
                Geometry.Indices.ToArray());

            hasInstances = (Instances != null) && (Instances.Any());
            bHasInstances = effect.GetVariableByName("bHasInstances").AsScalar();
            if (hasInstances)
            {
                instanceBuffer = Buffer.Create(Device, instanceArray, new BufferDescription(Matrix.SizeInBytes * instanceArray.Length, ResourceUsage.Dynamic, BindFlags.VertexBuffer, CpuAccessFlags.Write, ResourceOptionFlags.None, 0));
            }

            OnRasterStateChanged();

            Device.ImmediateContext.Flush();
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="host"></param>
        public override void Attach(IRenderHost host)
        {
            /// --- attach
            this.effectName = host.RenderTechnique.ToString();
            base.Attach(host);

            // --- get variables
            this.vertexLayout = host.Effects.GetLayout(this.effectName);
            this.shaderTechnique = effect.GetTechniqueByName(this.effectName);

            // --- get the pass
            this.shaderPass = this.shaderTechnique.GetPassByName(this.Shading);

            // -- get geometry
            this.geometry = this.Geometry as MeshGeometry3D;


            if (this.geometry == null)
            {
                throw new HelixToolkitException("Geometry not found!");
            }

            /// --- model transformation
            this.effectTransforms = new EffectTransformVariables(this.effect);

            /// --- material 
            this.AttachMaterial();

            /// --- init vertex buffer
            this.vertexBuffer = device.CreateBuffer(BindFlags.VertexBuffer, DefaultVertex.SizeInBytes, this.geometry.Positions.Select((x, ii) => new DefaultVertex()
            {
                Position = new Vector4(x, 1f),
                Color = this.geometry.Colors != null ? this.geometry.Colors[ii] : new Color4(1f, 0f, 0f, 1f),
                TexCoord = this.geometry.TextureCoordinates != null ? this.geometry.TextureCoordinates[ii] : new Vector2(),
                Normal = this.geometry.Normals != null ? this.geometry.Normals[ii] : new Vector3(),
                Tangent = this.geometry.Tangents != null ? this.geometry.BiTangents[ii] : new Vector3(),
                BiTangent = this.geometry.BiTangents != null ? this.geometry.BiTangents[ii] : new Vector3(),
            }).ToArray());

            /// --- init index buffer
            this.indexBuffer = device.CreateBuffer(BindFlags.IndexBuffer, sizeof(int), this.geometry.Indices);

            ///// --- init instances buffer            
            //this.hasInstances = this.Instances != null;            
            //this.bHasInstances = this.effect.GetVariableByName("bHasInstances").AsScalar();
            //if (this.hasInstances)
            //{                
            //    this.instanceBuffer = Buffer.Create(this.device, this.instanceArray, new BufferDescription(Matrix.SizeInBytes * this.instanceArray.Length, ResourceUsage.Dynamic, BindFlags.VertexBuffer, CpuAccessFlags.Write, ResourceOptionFlags.None, 0));                            
            //}

            /// --- init tessellation vars
            this.vTessellationVariables = effect.GetVariableByName("vTessellation").AsVector();
            this.vTessellationVariables.Set(new Vector4((float)this.TessellationFactor, 0, 0, 0));

            /// --- flush
            this.device.ImmediateContext.Flush();
        }