Ejemplo n.º 1
0
        public void Draw(Camera camera, Matrix world, bool drawAmbient, bool isEnlightend, float lightPower)
        {
            if (model == null)
            {
                return;
            }
            //
            // Compute all of the bone absolute transforms
            //
            Matrix[] boneTransforms = new Matrix[bones.Count];
            for (int i = 0; i < bones.Count; i++)
            {
                Bone bone = bones[i];
                bone.ComputeAbsoluteTransform();

                boneTransforms[i] = bone.AbsoluteTransform;
            }

            Matrix[] skeleton = new Matrix[modelExtra.Skeleton.Count];
            for (int s = 0; s < modelExtra.Skeleton.Count; s++)
            {
                Bone bone = bones[modelExtra.Skeleton[s]];
                skeleton[s] = bone.SkinTransform * bone.AbsoluteTransform;
            }

            // Draw the model.
            foreach (ModelMesh modelMesh in model.Meshes)
            {
                foreach (Effect effect in modelMesh.Effects)
                {
                    if (effect is BasicEffect)
                    {
                        BasicEffect basicEffect = effect as BasicEffect;
                        basicEffect.World      = boneTransforms[modelMesh.ParentBone.Index] * world;
                        basicEffect.View       = camera.View;
                        basicEffect.Projection = camera.Projection;
                        basicEffect.GraphicsDevice.DepthStencilState = DepthStencilState.Default;
                        basicEffect.GraphicsDevice.BlendState        = BlendState.AlphaBlend;

                        this.SetBasicEffects(basicEffect, drawAmbient, isEnlightend, lightPower);
                        if (this.modelTexture != null)
                        {
                            basicEffect.Texture = this.modelTexture;
                        }
                    }

                    if (effect is SkinnedEffect)
                    {
                        SkinnedEffect skinndedEffect = effect as SkinnedEffect;
                        skinndedEffect.World      = boneTransforms[modelMesh.ParentBone.Index] * world;
                        skinndedEffect.View       = camera.View;
                        skinndedEffect.Projection = camera.Projection;
                        skinndedEffect.EnableDefaultLighting();
                        skinndedEffect.PreferPerPixelLighting = true;
                        skinndedEffect.SetBoneTransforms(skeleton);
                    }
                }
                modelMesh.Draw();
            }
        }
Ejemplo n.º 2
0
        public override void Initialize(PloobsEngine.Engine.GraphicInfo ginfo, PloobsEngine.Engine.GraphicFactory factory, PloobsEngine.SceneControl.IObject obj)
        {
            base.Initialize(ginfo, factory, obj);

#if WINDOWS_PHONE || REACH
            SkinnedEffect = factory.GetSkinnedEffect();
            SkinnedEffect.EnableDefaultLighting();
#endif
        }
Ejemplo n.º 3
0
        /// <summary>
        /// The sunlight.
        /// </summary>
        /// <param name="effect">
        /// The effect.
        /// </param>
        /// <param name="specularColor">
        /// The specular color.
        /// </param>
        public static void Sunlight(SkinnedEffect effect, Vector3 specularColor)
        {
            effect.EnableDefaultLighting();

            effect.DirectionalLight0.Enabled       = true;
            effect.DirectionalLight0.Direction     = SunDirection;
            effect.DirectionalLight0.DiffuseColor  = SunColor;
            effect.DirectionalLight0.SpecularColor = specularColor;
        }
Ejemplo n.º 4
0
        protected override void LoadContent()
        {
            ResourceLibrary.Load(content, device);

            spritebatch = new SpriteBatch(device);

            skinnedeffect = new SkinnedEffect(device);
            skinnedeffect.EnableDefaultLighting();
            skinnedeffect.FogEnabled             = false;
            skinnedeffect.PreferPerPixelLighting = true;

            dude = new ExampleModelClass(ResourceLibrary.dude, skinnedeffect);
            dude.SetWorld(Matrix.CreateScale(0.05f));
            dude.PlayAnimation(0, -1.0f, true);
        }
Ejemplo n.º 5
0
        private void SetNewEffect()
        {
            foreach (ModelMesh mesh in _model.Model.Model.Meshes)
            {
                foreach (ModelMeshPart part in mesh.MeshParts)
                {
                    SkinnedEffect newEffect = new SkinnedEffect(EngineManager.GameGraphicsDevice);
                    BasicEffect   oldEffect = ((BasicEffect)part.Effect);

                    newEffect.EnableDefaultLighting();

                    newEffect.SpecularColor     = Color.Black.ToVector3();
                    newEffect.AmbientLightColor = oldEffect.AmbientLightColor;
                    newEffect.DiffuseColor      = oldEffect.DiffuseColor;
                    newEffect.Texture           = oldEffect.Texture;

                    part.Effect = newEffect;
                }
            }
        }
Ejemplo n.º 6
0
        private void SetSkinnedEffect()
        {
            foreach (ModelMesh mesh in _character.Meshes)
            {
                foreach (ModelMeshPart meshPart in mesh.MeshParts)
                {
                    SkinnedEffect skinnedEffect = new SkinnedEffect(Game.GraphicsDevice);
                    BasicEffect   basicEffect   = (BasicEffect)meshPart.Effect;

                    skinnedEffect.EnableDefaultLighting();
                    skinnedEffect.SpecularColor = Color.White.ToVector3();


                    skinnedEffect.AmbientLightColor = basicEffect.AmbientLightColor;
                    skinnedEffect.DiffuseColor      = basicEffect.DiffuseColor;
                    skinnedEffect.Texture           = basicEffect.Texture;

                    meshPart.Effect = skinnedEffect;
                }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Create the material.
        /// </summary>
        /// <param name="fromEffect">Effect to create material from.</param>
        /// <param name="copyEffectProperties">If true, will copy initial properties from effect.</param>
        public SkinnedMaterial(SkinnedEffect fromEffect, bool copyEffectProperties = true)
        {
            // store effect and set default properties
            _effect = fromEffect.Clone() as SkinnedEffect;
            SetDefaults();

            // copy properties from effect itself
            if (copyEffectProperties)
            {
                // set effect defaults
                Texture        = fromEffect.Texture;
                TextureEnabled = fromEffect.Texture != null;
                Alpha          = fromEffect.Alpha;
                AmbientLight   = new Color(fromEffect.AmbientLightColor.X, fromEffect.AmbientLightColor.Y, fromEffect.AmbientLightColor.Z);
                DiffuseColor   = new Color(fromEffect.DiffuseColor.X, fromEffect.DiffuseColor.Y, fromEffect.DiffuseColor.Z);
                SpecularColor  = new Color(fromEffect.SpecularColor.X, fromEffect.SpecularColor.Y, fromEffect.SpecularColor.Z);
                SpecularPower  = fromEffect.SpecularPower;

                // enable lightings by default
                _effect.EnableDefaultLighting();
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Draw the model
        /// </summary>
        /// <param name="graphics">The graphics device to draw on</param>
        /// <param name="camera">A camera to determine the view</param>
        /// <param name="world">A world matrix to place the model</param>
        public override void  Draw(GameTime gameTime)
        {
            if (model == null)
            {
                return;
            }

            Game1 _game = (Game1)base.Game;

            //
            // Compute all of the bone absolute transforms
            //

            Matrix[] boneTransforms = new Matrix[bones.Count];

            for (int i = 0; i < bones.Count; i++)
            {
                Bone _bone = bones[i];
                _bone.ComputeAbsoluteTransform();

                boneTransforms[i] = _bone.AbsoluteTransform;
            }

            //
            // Determine the skin transforms from the skeleton
            //

            Matrix[] skeleton = new Matrix[modelExtra.Skeleton.Count];
            for (int s = 0; s < modelExtra.Skeleton.Count; s++)
            {
                Bone bone = bones[modelExtra.Skeleton[s]];
                skeleton[s] = bone.SkinTransform * bone.AbsoluteTransform;
            }

            // Draw the model.
            foreach (ModelMesh modelMesh in model.Meshes)
            {
                foreach (Effect effect in modelMesh.Effects)
                {
                    if (effect is BasicEffect)
                    {
                        BasicEffect beffect = effect as BasicEffect;
                        beffect.World      = boneTransforms[modelMesh.ParentBone.Index] * GetWorld();
                        beffect.View       = _game.camera.view;
                        beffect.Projection = _game.camera.projection;
                        beffect.EnableDefaultLighting();
                        beffect.PreferPerPixelLighting = true;
                    }

                    if (effect is SkinnedEffect)
                    {
                        SkinnedEffect seffect = effect as SkinnedEffect;
                        seffect.World      = boneTransforms[modelMesh.ParentBone.Index] * GetWorld();
                        seffect.View       = ((Game1)base.Game).camera.view;
                        seffect.Projection = ((Game1)base.Game).camera.projection;
                        seffect.EnableDefaultLighting();
                        seffect.PreferPerPixelLighting = true;
                        seffect.SetBoneTransforms(skeleton);
                    }
                }

                modelMesh.Draw();
            }
        }
        /// <summary>
        /// Draw the current state of the <c>AnimatedModel</c>.
        /// </summary>
        /// <param name="view">View matrix of the active camera.</param>
        /// <param name="projection">Projection matrix of the active camera.</param>
        /// <param name="method">Method to draw the model (no instancing, hardware instancing).</param>
        /// <param name="individualTransformations">Individual transforms of the meshes.</param>
        /// <param name="customEffect">Custom effect to be applied to the model.</param>
        public override void Draw(Matrix view, Matrix projection, DrawingMethod method,
                                  Dictionary <string, Matrix> individualTransformations, Effect customEffect)
        {
            Matrix baseWorld = GetWorldMatrix();

            if (customEffect != null)
            {
                customEffect.CurrentTechnique = customEffect.Techniques["MultipleTargets"];
                customEffect.Parameters["xView"].SetValue(view);
                customEffect.Parameters["xProjection"].SetValue(projection);
            }

            foreach (ModelMesh mesh in base.Model.Model.Meshes)
            {
                if (_meshesToDraw != null && !_meshesToDraw.Contains(mesh.Name))
                {
                    continue;
                }

                foreach (ModelMeshPart meshPart in mesh.MeshParts)
                {
                    if (customEffect != null)
                    {
                        customEffect.Parameters["xTexture"].SetValue(Model.Texture);
                        if (individualTransformations.ContainsKey(mesh.Name))
                        {
                            customEffect.Parameters["xWorld"].SetValue(
                                individualTransformations[mesh.Name] *
                                GetParentTransform(Model.Model, mesh.ParentBone) *
                                baseWorld);
                        }
                        else
                        {
                            customEffect.Parameters["xWorld"].SetValue(
                                GetParentTransform(Model.Model, mesh.ParentBone) * baseWorld);
                        }

                        customEffect.CurrentTechnique.Passes[0].Apply();
                    }
                    else if (meshPart.Effect is SkinnedEffect)
                    {
                        SkinnedEffect effect = (SkinnedEffect)meshPart.Effect;

                        if (_animation != null)
                        {
                            effect.SetBoneTransforms(_animation.SkinTransforms);
                        }

                        if (individualTransformations.ContainsKey(mesh.Name))
                        {
                            effect.World = individualTransformations[mesh.Name] *
                                           GetParentTransform(Model.Model, mesh.ParentBone) *
                                           baseWorld;
                        }
                        else
                        {
                            effect.World = GetParentTransform(Model.Model, mesh.ParentBone) *
                                           baseWorld;
                        }

                        effect.View       = view;
                        effect.Projection = projection;

                        if (_damaged == true)
                        {
                            effect.DiffuseColor      = _damageColor;
                            effect.AmbientLightColor = _damageColor;
                        }
                        else
                        {
                            effect.DiffuseColor      = _naturalDiffuseColor;
                            effect.AmbientLightColor = _naturalAmbientColor;
                        }

                        effect.SpecularColor = Color.CadetBlue.ToVector3();
                        effect.SpecularPower = 256;

                        effect.EnableDefaultLighting();
                        effect.CurrentTechnique.Passes[0].Apply();
                    }

                    EngineManager.GameGraphicsDevice.SetVertexBuffer(meshPart.VertexBuffer, meshPart.VertexOffset);
                    EngineManager.GameGraphicsDevice.Indices = meshPart.IndexBuffer;

                    EngineManager.GameGraphicsDevice.DrawIndexedPrimitives(
                        PrimitiveType.TriangleList,
                        0, 0,
                        meshPart.NumVertices,
                        meshPart.StartIndex,
                        meshPart.PrimitiveCount);
                }
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Draw the model
        /// </summary>
        /// <param name="graphics">The graphics device to draw on</param>
        /// <param name="camera">A camera to determine the view</param>
        /// <param name="world">A world matrix to place the model</param>
        public void Draw(GraphicsDevice graphics, Camera camera, float modelRotation, Vector3 modelPosition)
        {
            if (model == null)
            {
                return;
            }

            //
            // Compute all of the bone absolute transforms
            //

            Matrix[] boneTransforms = new Matrix[bones.Count];

            for (int i = 0; i < bones.Count; i++)
            {
                Bone bone = bones[i];
                bone.ComputeAbsoluteTransform();

                boneTransforms[i] = bone.AbsoluteTransform;
            }

            //
            // Determine the skin transforms from the skeleton
            //

            Matrix[] skeleton = new Matrix[modelExtra.Skeleton.Count];
            for (int s = 0; s < modelExtra.Skeleton.Count; s++)
            {
                Bone bone = bones[modelExtra.Skeleton[s]];
                skeleton[s] = bone.SkinTransform * bone.AbsoluteTransform;
            }

            // Draw the model.
            foreach (ModelMesh modelMesh in model.Meshes)
            {
                foreach (Effect effect in modelMesh.Effects)
                {
                    if (effect is BasicEffect)
                    {
                        BasicEffect beffect = effect as BasicEffect;
                        beffect.World      = boneTransforms[modelMesh.ParentBone.Index] * Matrix.CreateRotationY(modelRotation) * Matrix.CreateTranslation(modelPosition);
                        beffect.View       = camera.View;
                        beffect.Projection = camera.Projection;
                        beffect.EnableDefaultLighting();
                        beffect.PreferPerPixelLighting = true;
                    }

                    if (effect is SkinnedEffect)
                    {
                        SkinnedEffect seffect = effect as SkinnedEffect;
                        seffect.World      = boneTransforms[modelMesh.ParentBone.Index] * Matrix.CreateRotationY(modelRotation) * Matrix.CreateTranslation(modelPosition);
                        seffect.View       = camera.View;
                        seffect.Projection = camera.Projection;
                        seffect.EnableDefaultLighting();
                        seffect.PreferPerPixelLighting = true;
                        seffect.SetBoneTransforms(skeleton);
                    }
                }

                modelMesh.Draw();
            }
        }
Ejemplo n.º 11
0
        private void DrawModelHardwareInstancing(Matrix view, Matrix projection,
                                                 Dictionary <string, Matrix> individualTransformations, Effect customEffect, AnimationPlayer player)
        {
            Matrix baseWorld = GetWorldMatrix();

            if (customEffect != null)
            {
                customEffect.CurrentTechnique = customEffect.Techniques["MultipleTargets"];
                customEffect.Parameters["xView"].SetValue(view);
                customEffect.Parameters["xProjection"].SetValue(projection);
            }

            foreach (ModelMesh mesh in _model.Model.Meshes)
            {
                foreach (ModelMeshPart meshPart in mesh.MeshParts)
                {
                    if (customEffect != null)
                    {
                        customEffect.Parameters["xTexture"].SetValue(_model.Texture);
                        if (individualTransformations.ContainsKey(mesh.Name))
                        {
                            customEffect.Parameters["xWorld"].SetValue(
                                individualTransformations[mesh.Name] *
                                GetParentTransform(_model.Model, mesh.ParentBone) *
                                baseWorld);
                        }
                        else
                        {
                            customEffect.Parameters["xWorld"].SetValue(
                                GetParentTransform(_model.Model, mesh.ParentBone) * baseWorld);
                        }

                        customEffect.CurrentTechnique.Passes[0].Apply();
                    }
                    else if (meshPart.Effect is BasicEffect)
                    {
                        BasicEffect effect = (BasicEffect)meshPart.Effect;

                        if (individualTransformations.ContainsKey(mesh.Name))
                        {
                            effect.World = individualTransformations[mesh.Name] *
                                           GetParentTransform(_model.Model, mesh.ParentBone) *
                                           baseWorld;
                        }
                        else
                        {
                            effect.World = GetParentTransform(_model.Model, mesh.ParentBone) *
                                           baseWorld;
                        }

                        effect.View       = view;
                        effect.Projection = projection;

                        effect.EnableDefaultLighting();
                        effect.CurrentTechnique.Passes[0].Apply();
                    }
                    else if (meshPart.Effect is SkinnedEffect)
                    {
                        SkinnedEffect effect = (SkinnedEffect)meshPart.Effect;

                        if (player != null)
                        {
                            effect.SetBoneTransforms(player.GetSkinTransforms());
                        }

                        if (individualTransformations.ContainsKey(mesh.Name))
                        {
                            effect.World = individualTransformations[mesh.Name] *
                                           GetParentTransform(_model.Model, mesh.ParentBone) *
                                           baseWorld;
                        }
                        else
                        {
                            effect.World = GetParentTransform(_model.Model, mesh.ParentBone) *
                                           baseWorld;
                        }

                        effect.View       = view;
                        effect.Projection = projection;

                        effect.EnableDefaultLighting();
                        effect.CurrentTechnique.Passes[0].Apply();
                    }

                    EngineManager.GameGraphicsDevice.SetVertexBuffer(meshPart.VertexBuffer,
                                                                     meshPart.VertexOffset);
                    EngineManager.GameGraphicsDevice.Indices = meshPart.IndexBuffer;

                    EngineManager.GameGraphicsDevice.DrawIndexedPrimitives(
                        PrimitiveType.TriangleList,
                        0, 0,
                        meshPart.NumVertices,
                        meshPart.StartIndex,
                        meshPart.PrimitiveCount);
                }
            }
        }
Ejemplo n.º 12
0
        public virtual void AssignParamsInitialize()
        {
            if (MyEffect == null)
            {
                throw new NullReferenceException("MyEffect iz null and you tryin' to extract params from it, n***a?");
            }

            etMain           = null;
            etSkinned        = null;
            etMainShadows    = null;
            etSkinnedShadows = null;

            epWorld = null;
            epWorldInverseTranspose = null;
            epWorldViewProj         = null;
            epDiffuseMap            = null;
            epNormalMap             = null;
            epCubeMap           = null;
            epDiffuseColor      = null;
            epSpecularColor     = null;
            epGlossiness        = null;
            epReflectivityColor = null;
            epReflectivityBias  = null;
            epTransparency      = null;
            epPerPixelLighting  = null;

            epBones = null;

            epAmbientLightColor       = null;
            epDirLight0Direction      = null;
            epDirLight0DiffuseColor   = null;
            epDirLight0SpecularColor  = null;
            epDirLight0ShadowMap0     = null;
            epDirLight0WorldViewProj1 = null;
            epDirLight0WorldViewProj2 = null;
            epDirLight1Direction      = null;
            epDirLight1DiffuseColor   = null;
            epDirLight1SpecularColor  = null;
            epDirLight2Direction      = null;
            epDirLight2DiffuseColor   = null;
            epDirLight2SpecularColor  = null;

            epPointLightDiffuseColors  = null;
            epPointLightSpecularColors = null;
            epPointLightPositions      = null;
            epPointLightAttenuations   = null;
            epPointLightCount          = null;
            epPoint0ShadowMap          = null;
            epSSA = null;

            epEyePosition         = null;
            epBoundingFrustum     = null;
            epCustomClippingPlane = null;

            int pNameHash;

            int hWorld          = ("World").GetHashCode();
            int hWIT            = ("WorldInverseTranspose").GetHashCode();
            int hWVP            = ("WorldViewProj").GetHashCode();
            int hDiff           = ("DiffuseMap").GetHashCode();
            int hDiff2          = ("Texture").GetHashCode();
            int hNorm           = ("NormalMap").GetHashCode();
            int hCube           = ("CubeMap").GetHashCode();
            int hDiffCol        = ("DiffuseColor").GetHashCode();
            int hSpecCol        = ("SpecularColor").GetHashCode();
            int hGloss          = ("Glossiness").GetHashCode();
            int hRefl           = ("ReflectivityColor").GetHashCode();
            int hReflB          = ("ReflectivityBias").GetHashCode();
            int hTransp         = ("Transparency").GetHashCode();
            int hBones          = ("Bones").GetHashCode();
            int hAmbLCol        = ("AmbientLightColor").GetHashCode();
            int hEmiss          = ("EmissiveColor").GetHashCode();
            int l0dir           = ("DirLight0Direction").GetHashCode();
            int l0dif           = ("DirLight0DiffuseColor").GetHashCode();
            int l0spec          = ("DirLight0SpecularColor").GetHashCode();
            int l0sm            = ("DirLight0ShadowMap").GetHashCode();
            int l0WVP           = ("DirLight0WorldViewProj").GetHashCode();
            int l0VP1           = ("DirLight0WorldViewProj1").GetHashCode();
            int l0VP2           = ("DirLight0WorldViewProj2").GetHashCode();
            int l1dir           = ("DirLight1Direction").GetHashCode();
            int l1dif           = ("DirLight1DiffuseColor").GetHashCode();
            int l1spec          = ("DirLight1SpecularColor").GetHashCode();
            int l2dir           = ("DirLight2Direction").GetHashCode();
            int l2dif           = ("DirLight2DiffuseColor").GetHashCode();
            int l2spec          = ("DirLight2SpecularColor").GetHashCode();
            int pDiffs          = ("PointLightDiffuseColors").GetHashCode();
            int pSpecs          = ("PointLightSpecularColors").GetHashCode();
            int jebactowszystko = ("ShadowSampleAddition").GetHashCode();
            int pPos            = ("PointLightPositions").GetHashCode();
            int pAtts           = ("PointLightAttenuations").GetHashCode();
            int pCnt            = ("PointLightCount").GetHashCode();
            int p0sm            = ("Point0ShadowMap").GetHashCode();
            int p0WVP           = ("Point0WorldViewProj").GetHashCode();
            int eyeP            = ("EyePosition").GetHashCode();
            int bs  = ("BoundingFrustum").GetHashCode();
            int cCP = ("CustomClippingPlane").GetHashCode();

            etUnlit                 = MyEffect.Techniques["Unlit"];
            etMain                  = MyEffect.Techniques["Main"];
            etSkinned               = MyEffect.Techniques["Skinned"];
            etMainShadows           = MyEffect.Techniques["MainShadows"];
            etSkinnedShadows        = MyEffect.Techniques["SkinnedShadows"];
            etMainBlurredShadows    = MyEffect.Techniques["MainBlurredShadows"];
            etSkinnedBlurredShadows = MyEffect.Techniques["SkinnedBlurredShadows"];

            foreach (EffectParameter p in MyEffect.Parameters)
            {
                pNameHash = p.Name.GetHashCode();

                if (pNameHash == hWorld)
                {
                    epWorld = p;
                }
                else if (pNameHash == hWIT)
                {
                    epWorldInverseTranspose = p;
                }
                else if (pNameHash == hWVP)
                {
                    epWorldViewProj = p;
                }
                else if (pNameHash == hDiff)
                {
                    epDiffuseMap = p;
                }
                else if (pNameHash == hDiff2)
                {
                    epDiffuseMap = p;
                }
                else if (pNameHash == hNorm)
                {
                    epNormalMap = p;
                }
                else if (pNameHash == hCube)
                {
                    epCubeMap = p;
                }
                else if (pNameHash == hDiffCol)
                {
                    epDiffuseColor = p;
                }
                else if (pNameHash == hSpecCol)
                {
                    epSpecularColor = p;
                }
                else if (pNameHash == hGloss)
                {
                    epGlossiness = p;
                }
                else if (pNameHash == hRefl)
                {
                    epReflectivityColor = p;
                }
                else if (pNameHash == hReflB)
                {
                    epReflectivityBias = p;
                }
                else if (pNameHash == hTransp)
                {
                    epTransparency = p;
                }
                else if (pNameHash == hBones)
                {
                    epBones = p;
                }
                else if (pNameHash == hAmbLCol)
                {
                    epAmbientLightColor = p;
                }
                else if (pNameHash == hEmiss)
                {
                    epAmbientLightColor = p;
                }
                else if (pNameHash == l0dir)
                {
                    epDirLight0Direction = p;
                }
                else if (pNameHash == l0dif)
                {
                    epDirLight0DiffuseColor = p;
                }
                else if (pNameHash == l0spec)
                {
                    epDirLight0SpecularColor = p;
                }
                else if (pNameHash == l0sm)
                {
                    epDirLight0ShadowMap0 = p;
                }
                else if (pNameHash == l0WVP)
                {
                    epDirLight0WorldViewProj = p;
                }
                else if (pNameHash == l0VP1)
                {
                    epDirLight0WorldViewProj1 = p;
                }
                else if (pNameHash == l0VP2)
                {
                    epDirLight0WorldViewProj2 = p;
                }
                else if (pNameHash == l1dir)
                {
                    epDirLight1Direction = p;
                }
                else if (pNameHash == l1dif)
                {
                    epDirLight1DiffuseColor = p;
                }
                else if (pNameHash == l1spec)
                {
                    epDirLight1SpecularColor = p;
                }
                else if (pNameHash == l2dir)
                {
                    epDirLight2Direction = p;
                }
                else if (pNameHash == l2dif)
                {
                    epDirLight2DiffuseColor = p;
                }
                else if (pNameHash == l2spec)
                {
                    epDirLight2SpecularColor = p;
                }
                else if (pNameHash == pDiffs)
                {
                    epPointLightDiffuseColors = p;
                }
                else if (pNameHash == pSpecs)
                {
                    epPointLightSpecularColors = p;
                }
                else if (pNameHash == pPos)
                {
                    epPointLightPositions = p;
                }
                else if (pNameHash == pAtts)
                {
                    epPointLightAttenuations = p;
                }
                else if (pNameHash == pCnt)
                {
                    epPointLightCount = p;
                }
                else if (pNameHash == p0sm)
                {
                    epPoint0ShadowMap = p;
                }
                else if (pNameHash == jebactowszystko)
                {
                    epSSA = p;
                }
                else if (pNameHash == eyeP)
                {
                    epEyePosition = p;
                }
                else if (pNameHash == bs)
                {
                    epBoundingFrustum = p;
                }
                else if (pNameHash == cCP)
                {
                    epCustomClippingPlane = p;
                }
            }

            if (MyEffect is BasicEffect)
            {
                tempBEref = (BasicEffect)MyEffect;

                tempBEref.LightingEnabled                 = true;
                tempBEref.DirectionalLight0.Enabled       = true;
                tempBEref.DirectionalLight0.DiffuseColor  = new Vector3(0.0f, 0.0f, 0.0f);
                tempBEref.DirectionalLight0.SpecularColor = new Vector3(0.0f, 0.0f, 0.0f);
                tempBEref.DirectionalLight0.Direction     = new Vector3(0.0f, 1.0f, 0.0f);
                tempBEref.DirectionalLight1.Enabled       = true;
                tempBEref.DirectionalLight1.DiffuseColor  = new Vector3(0.0f, 0.0f, 0.0f);
                tempBEref.DirectionalLight1.SpecularColor = new Vector3(0.0f, 0.0f, 0.0f);
                tempBEref.DirectionalLight1.Direction     = new Vector3(0.0f, 1.0f, 0.0f);
                tempBEref.DirectionalLight2.Enabled       = true;
                tempBEref.DirectionalLight2.DiffuseColor  = new Vector3(0.0f, 0.0f, 0.0f);
                tempBEref.DirectionalLight2.SpecularColor = new Vector3(0.0f, 0.0f, 0.0f);
                tempBEref.DirectionalLight2.Direction     = new Vector3(0.0f, 1.0f, 0.0f);
                tempBEref.TextureEnabled = true;
            }
            else if (MyEffect is SkinnedEffect)
            {
                tempSEref = (SkinnedEffect)MyEffect;

                tempSEref.EnableDefaultLighting();
                tempSEref.DirectionalLight0.Enabled       = true;
                tempSEref.DirectionalLight1.Enabled       = true;
                tempSEref.DirectionalLight2.Enabled       = true;
                tempSEref.DirectionalLight0.DiffuseColor  = new Vector3(0.0f, 0.0f, 0.0f);
                tempSEref.DirectionalLight0.SpecularColor = new Vector3(0.0f, 0.0f, 0.0f);
                tempSEref.DirectionalLight0.Direction     = new Vector3(0.0f, 1.0f, 0.0f);
                tempSEref.DirectionalLight1.DiffuseColor  = new Vector3(0.0f, 0.0f, 0.0f);
                tempSEref.DirectionalLight1.SpecularColor = new Vector3(0.0f, 0.0f, 0.0f);
                tempSEref.DirectionalLight1.Direction     = new Vector3(0.0f, 1.0f, 0.0f);
                tempSEref.DirectionalLight2.DiffuseColor  = new Vector3(0.0f, 0.0f, 0.0f);
                tempSEref.DirectionalLight2.SpecularColor = new Vector3(0.0f, 0.0f, 0.0f);
                tempSEref.DirectionalLight2.Direction     = new Vector3(0.0f, 1.0f, 0.0f);
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Draw the model
        /// </summary>
        /// <param name="gameTime">The snapshot of time during drawing.</param>
        public void Draw(GameTime gameTime, GameObject owner, Vector3 offset)
        {
            if (model == null)
            {
                return;
            }

            Camera camera = owner.Scene.Camera.GetComponent <Camera>();

            if (model.Tag == null)
            {
                model.Draw(Matrix.CreateTranslation(offset) * owner.LocalToWorldMatrix, camera.ViewMatrix, camera.ProjectionMatrix);
                return;
            }

            //
            // Compute all of the bone absolute transforms
            //

            Matrix[] boneTransforms = new Matrix[bones.Count];

            for (int i = 0; i < bones.Count; i++)
            {
                Bone bone = bones[i];
                bone.ComputeAbsoluteTransform();

                boneTransforms[i] = bone.AbsoluteTransform;
            }

            //
            // Determine the skin transforms from the skeleton
            //

            Matrix[] skeleton = null;
            if (modelExtra != null)
            {
                skeleton = new Matrix[modelExtra.Skeleton.Count];
                for (int s = 0; s < modelExtra.Skeleton.Count; s++)
                {
                    Bone bone = bones[modelExtra.Skeleton[s]];
                    skeleton[s] = bone.SkinTransform * bone.AbsoluteTransform;
                }
            }

            if (skeleton != null)
            {
                foreach (Effect effect in PreCustomSkinnedShaders)
                {
                    if (effect.Name.Contains("HighlightSkinnedColor"))
                    {
                        if (owner.Name.Equals("HologramPreview"))
                        {
                            effect.Parameters["LineColor"].SetValue(new Color(0.6f, 0.75f, 0.85f, 0.1f).ToVector4());
                        }
                        if (owner.Name.Equals("HologramPlayback"))
                        {
                            effect.Parameters["LineColor"].SetValue(new Color(0.6f, 0.75f, 0.85f, 0.5f).ToVector4());
                        }
                        if (owner.Name.StartsWith("Enemy"))
                        {
                            effect.Parameters["LineColor"].SetValue(Color.Red.ToVector4());
                        }
                    }
                    effect.Parameters["View"].SetValue(camera.ViewMatrix);
                    effect.Parameters["Projection"].SetValue(camera.ProjectionMatrix);
                    foreach (ModelMesh modelMesh in model.Meshes)
                    {
                        List <Effect> effects = new List <Effect>();
                        effect.Parameters["World"].SetValue(Matrix.CreateTranslation(offset) * boneTransforms[modelMesh.ParentBone.Index] * owner.LocalToWorldMatrix);
                        effect.Parameters["Bones"].SetValue(skeleton);
                        foreach (ModelMeshPart meshPart in modelMesh.MeshParts)
                        {
                            effects.Add(meshPart.Effect);
                            meshPart.Effect = effect;
                        }
                        modelMesh.Draw();
                        for (int i = 0; i < effects.Count; ++i)
                        {
                            modelMesh.MeshParts[i].Effect = effects[i];
                        }
                    }
                }

                model.Meshes[0].Effects[0].GraphicsDevice.DepthStencilState = DepthStencilState.Default;
                RasterizerState rast = new RasterizerState();
                rast.CullMode = CullMode.CullCounterClockwiseFace;
                model.Meshes[0].Effects[0].GraphicsDevice.RasterizerState = rast;
            }

            // Draw the model.
            foreach (ModelMesh modelMesh in model.Meshes)
            {
                foreach (Effect effect in modelMesh.Effects)
                {
                    if (effect is BasicEffect)
                    {
                        BasicEffect beffect = effect as BasicEffect;
                        beffect.World      = Matrix.CreateTranslation(offset) * boneTransforms[modelMesh.ParentBone.Index] * owner.LocalToWorldMatrix;
                        beffect.View       = camera.ViewMatrix;
                        beffect.Projection = camera.ProjectionMatrix;
                        beffect.EnableDefaultLighting();
                        beffect.PreferPerPixelLighting = true;
                    }
                    else if (effect is SkinnedEffect)
                    {
                        SkinnedEffect seffect = effect as SkinnedEffect;
                        seffect.World      = Matrix.CreateTranslation(offset) * boneTransforms[modelMesh.ParentBone.Index] * owner.LocalToWorldMatrix;
                        seffect.View       = camera.ViewMatrix;
                        seffect.Projection = camera.ProjectionMatrix;
                        seffect.EnableDefaultLighting();
                        seffect.PreferPerPixelLighting = true;
                        if (skeleton != null)
                        {
                            seffect.SetBoneTransforms(skeleton);
                        }
                    }
                    else
                    {
                        effect.Parameters["World"].SetValue(Matrix.CreateTranslation(offset) * boneTransforms[modelMesh.ParentBone.Index] * owner.LocalToWorldMatrix);
                        effect.Parameters["View"].SetValue(camera.ViewMatrix);
                        effect.Parameters["Projection"].SetValue(camera.ProjectionMatrix);
                    }
                }

                modelMesh.Draw();
            }
        }