/// <summary>
        ///
        /// </summary>
        protected void AttachMaterial()
        {
            this.phongMaterial = Material as PhongMaterial;
            if (phongMaterial != null)
            {
                this.effectMaterial = new EffectMaterialVariables(this.effect);

                /// --- has texture
                if (phongMaterial.DiffuseMap != null)
                {
                    this.texDiffuseMapView = ShaderResourceView.FromMemory(Device, phongMaterial.DiffuseMap.ToByteArray());
                    this.effectMaterial.texDiffuseMapVariable.SetResource(this.texDiffuseMapView);
                    this.effectMaterial.bHasDiffuseMapVariable.Set(true);
                }
                else
                {
                    this.effectMaterial.bHasDiffuseMapVariable.Set(false);
                }

                // --- has bumpmap
                if (phongMaterial.NormalMap != null)
                {
                    var geometry = this.Geometry as MeshGeometry3D;
                    if (geometry != null)
                    {
                        if (geometry.Tangents == null)
                        {
                            //System.Windows.MessageBox.Show(string.Format("No Tangent-Space found. NormalMap will be omitted."), "Warrning", MessageBoxButton.OK);
                            phongMaterial.NormalMap = null;
                        }
                        else
                        {
                            this.texNormalMapView = ShaderResourceView.FromMemory(Device, phongMaterial.NormalMap.ToByteArray());
                            this.effectMaterial.texNormalMapVariable.SetResource(this.texNormalMapView);
                            this.effectMaterial.bHasNormalMapVariable.Set(true);
                        }
                    }
                }
                else
                {
                    this.effectMaterial.bHasNormalMapVariable.Set(false);
                }

                // --- has displacement map
                if (phongMaterial.DisplacementMap != null)
                {
                    this.texDisplacementMapView = ShaderResourceView.FromMemory(Device, phongMaterial.DisplacementMap.ToByteArray());
                    this.effectMaterial.texDisplacementMapVariable.SetResource(this.texDisplacementMapView);
                    this.effectMaterial.bHasDisplacementMapVariable.Set(true);
                }
                else
                {
                    this.effectMaterial.bHasDisplacementMapVariable.Set(false);
                }
            }
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        protected virtual void AttachMaterial()
        {
            var phongMaterial = Material as CustomPhongMaterial;

            if (phongMaterial != null)
            {
                this.effectMaterial = new EffectMaterialVariables(this.effect, phongMaterial);
                this.effectMaterial.CreateTextureViews(Device, this);
            }
        }
 /// <summary>
 ///
 /// </summary>
 protected virtual void AttachMaterial()
 {
     Disposer.RemoveAndDispose(ref this.effectMaterial);
     if (materialInternal != null)
     {
         this.effectMaterial = new EffectMaterialVariables(this.effect, materialInternal);
         this.effectMaterial.CreateTextureViews(Device, this);
         this.effectMaterial.RenderDiffuseMap      = this.RenderDiffuseMap;
         this.effectMaterial.RenderDiffuseAlphaMap = this.RenderDiffuseAlphaMap;
         this.effectMaterial.RenderNormalMap       = this.RenderNormalMap;
         this.effectMaterial.RenderDisplacementMap = this.RenderDisplacementMap;
         this.effectMaterial.OnInvalidateRenderer += (s, e) => { InvalidateRender(); };
     }
 }
        /// <summary>
        /// 
        /// </summary>
        protected virtual void AttachMaterial()
        {
            this.phongMaterial = Material as PhongMaterial;
            if (phongMaterial != null)
            {
                this.effectMaterial = new EffectMaterialVariables(this.effect);

                /// --- has texture
                if (phongMaterial.DiffuseMap != null)
                {
                    this.texDiffuseMapView = new ShaderResourceView(Device,TextureLoader.CreateTexture2DFromMediaBitamp(this.Device, phongMaterial.DiffuseMap));// ShaderResourceView.FromMemory(Device, phongMaterial.DiffuseMap.ToByteArray());
                    this.effectMaterial.texDiffuseMapVariable.SetResource(this.texDiffuseMapView);
                    this.effectMaterial.bHasDiffuseMapVariable.Set(true);
                }
                else
                {
                    this.effectMaterial.bHasDiffuseMapVariable.Set(false);
                }

                // --- has bumpmap
                if (phongMaterial.NormalMap != null)
                {
                    var geometry = this.Geometry as MeshGeometry3D;
                    if (geometry != null)
                    {
                        if (geometry.Tangents == null)
                        {
                            //System.Windows.MessageBox.Show(string.Format("No Tangent-Space found. NormalMap will be omitted."), "Warrning", MessageBoxButton.OK);
                            phongMaterial.NormalMap = null;
                        }
                        else
                        {
                            this.texNormalMapView = new ShaderResourceView(Device, TextureLoader.CreateTexture2DFromMediaBitamp(this.Device, phongMaterial.NormalMap));
                            this.effectMaterial.texNormalMapVariable.SetResource(this.texNormalMapView);
                            this.effectMaterial.bHasNormalMapVariable.Set(true);
                        }
                    }
                }
                else
                {
                    this.effectMaterial.bHasNormalMapVariable.Set(false);
                }

                // --- has displacement map
                if (phongMaterial.DisplacementMap != null)
                {
                    this.texDisplacementMapView = new ShaderResourceView(Device, TextureLoader.CreateTexture2DFromMediaBitamp(this.Device, phongMaterial.DisplacementMap));
                    this.effectMaterial.texDisplacementMapVariable.SetResource(this.texDisplacementMapView);
                    this.effectMaterial.bHasDisplacementMapVariable.Set(true);
                }
                else
                {
                    this.effectMaterial.bHasDisplacementMapVariable.Set(false);
                }
            }
        }
        /// <summary>
        /// 
        /// </summary>
        protected void AttachMaterial()
        {
            this.phongMaterial = Material as PhongMaterial;
            if (phongMaterial != null)
            {
                this.effectMaterial = new EffectMaterialVariables(this.effect);

                /// --- has texture
                if (phongMaterial.DiffuseMap != null)
                {
                    this.texDiffuseMapView = ShaderResourceView.FromMemory(device, phongMaterial.DiffuseMap.ToByteArray());
                    this.effectMaterial.texDiffuseMapVariable.SetResource(this.texDiffuseMapView);
                    this.effectMaterial.bHasDiffuseMapVariable.Set(true);                    
                }
                else
                {
                    this.effectMaterial.bHasDiffuseMapVariable.Set(false);
                }

                // --- has bumpmap
                if (phongMaterial.NormalMap != null)
                {
                    if (this.geometry.Tangents == null)
                    {
                        System.Windows.MessageBox.Show(string.Format("No Tangent-Space found. NormalMap will be omitted."), "Warning");
                        phongMaterial.NormalMap = null;
                    }
                    else
                    {
                        this.texNormalMapView = ShaderResourceView.FromMemory(device, phongMaterial.NormalMap.ToByteArray());
                        this.effectMaterial.texNormalMapVariable.SetResource(this.texNormalMapView);
                        this.effectMaterial.bHasNormalMapVariable.Set(true);
                    }
                }
                else
                {
                    this.effectMaterial.bHasNormalMapVariable.Set(false);
                }

                // --- has displacement map
                if (phongMaterial.DisplacementMap != null)
                {
                    this.texDisplacementMapView = ShaderResourceView.FromMemory(device, phongMaterial.DisplacementMap.ToByteArray());
                    this.effectMaterial.texDisplacementMapVariable.SetResource(this.texDisplacementMapView);
                    this.effectMaterial.bHasDisplacementMapVariable.Set(true);
                }
                else
                {
                    this.effectMaterial.bHasDisplacementMapVariable.Set(false);
                }
            }
        }