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(); } }
public void CopyFromSkinnedEffect(SkinnedEffect cloneSource) { CacheEffectParameters(cloneSource); preferPerPixelLighting = cloneSource.PreferPerPixelLighting; fogEnabled = cloneSource.FogEnabled; world = cloneSource.World; view = cloneSource.View; projection = cloneSource.Projection; diffuseColor = cloneSource.DiffuseColor; emissiveColor = cloneSource.EmissiveColor; ambientLightColor = cloneSource.AmbientLightColor; alpha = cloneSource.Alpha; fogStart = cloneSource.FogStart; fogEnd = cloneSource.FogEnd; weightsPerVertex = cloneSource.WeightsPerVertex; Texture = cloneSource.Texture; SpecularColor = cloneSource.SpecularColor; SpecularPower = cloneSource.SpecularPower; eyePositionParam.SetValue(cloneSource.Parameters["EyePosition"].GetValueVector3()); fogVectorParam.SetValue(cloneSource.Parameters["FogVector"].GetValueVector4()); worldInverseTransposeParam.SetValue(cloneSource.Parameters["WorldInverseTranspose"].GetValueMatrix()); bonesParam.SetValue(cloneSource.Parameters["Bones"].GetValueMatrixArray(MaxBones)); }
protected override void Draw(GameTime gameTime) { graphics.GraphicsDevice.Clear(Color.BurlyWood); // Update the bone transforms if skinned material effect issupported foreach (ModelMesh mesh in model.Meshes) { foreach (var material in mesh.Materials) { SkinnedEffect effect = material.Effect as SkinnedEffect; if (effect == null) { continue; } effect.SetBoneTransforms(skinnedAnimation.SkinTransforms); } } // Draw model model.Draw(modelTransform, camera.View, camera.Projection); base.Draw(gameTime); }
internal static void SetTexture(this Effect effect, Texture2D texture) { if (effect is BasicEffect) { BasicEffect source = effect as BasicEffect; source.Texture = texture; source.TextureEnabled = texture != null; } else if (effect is SkinnedEffect) { SkinnedEffect source = effect as SkinnedEffect; source.Texture = texture; } else if (effect is EnvironmentMapEffect) { EnvironmentMapEffect source = effect as EnvironmentMapEffect; source.Texture = texture; } else if (effect is DualTextureEffect) { DualTextureEffect source = effect as DualTextureEffect; source.Texture = texture; } else if (effect is AlphaTestEffect) { AlphaTestEffect source = effect as AlphaTestEffect; source.Texture = texture; } }
/// <summary> /// Create the material from another material instance. /// </summary> /// <param name="other">Other material to clone.</param> public SkinnedMaterial(SkinnedMaterial other) { _effect = other._effect.Clone() as SkinnedEffect; MaterialAPI asBase = this; other.CloneBasics(ref asBase); }
internal static Texture2D GetTexture(this Effect sourceEffect) { Texture2D texture = null; if (sourceEffect is BasicEffect) { BasicEffect source = sourceEffect as BasicEffect; texture = source.Texture; } else if (sourceEffect is SkinnedEffect) { SkinnedEffect source = sourceEffect as SkinnedEffect; texture = source.Texture; } else if (sourceEffect is EnvironmentMapEffect) { EnvironmentMapEffect source = sourceEffect as EnvironmentMapEffect; texture = source.Texture; } else if (sourceEffect is DualTextureEffect) { DualTextureEffect source = sourceEffect as DualTextureEffect; texture = source.Texture; } else if (sourceEffect is AlphaTestEffect) { AlphaTestEffect source = sourceEffect as AlphaTestEffect; texture = source.Texture; } return(texture); }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); // AETHER.ANIMATION EXAMPLE CODE foreach (ModelMesh mesh in testModel.Meshes) { foreach (var part in mesh.MeshParts) { // for GPU animations SkinnedEffect effect = (SkinnedEffect)part.Effect; // for CPU animations // BasicEffect effect = (BasicEffect)part.Effect; // for GPU animations effect.SetBoneTransforms(testAnimations.AnimationTransforms); // for CPU animations // part.UpdateVertices(testAnimations.AnimationTransforms); effect.World = testWorld; effect.View = testView; effect.Projection = testProjection; effect.SpecularColor = Vector3.Zero; ApplyLighting(effect); } mesh.Draw(); } // TODO: Add your drawing code here base.Draw(gameTime); }
protected override void LoadContent() { this.colorStream = new ColorStreamRenderer(Game, new Vector2(GraphicsDevice.Viewport.Width - 5 - 160, 5), new Vector2(160, 100)); this.currentModel = Game.Content.Load <Model>("MODELS/ninja2/ninja/ninja2"); if (null == this.currentModel) { throw new InvalidOperationException("Cannot load 3D avatar model"); } effect = new SkinnedEffect(GraphicsDevice); effect.Texture = Game.Content.Load <Texture2D>("MODELS/ninja2/ninja/texture"); foreach (ModelMesh mesh in currentModel.Meshes) { foreach (ModelMeshPart part in mesh.MeshParts) { part.Effect = effect; } } this.animator.AvatarModel = this.currentModel; this.animator.AvatarHipCenterHeight = this.avatarHipCenterDrawHeight; this.BuildJointHierarchy(); base.LoadContent(); }
protected override void Draw(GameTime gt, IObject obj, RenderHelper render, ICamera cam, IList <Light.ILight> lights) { AnimatedModel modelo = obj.Modelo as AnimatedModel; for (int i = 0; i < modelo.GetAnimatedModel().Meshes.Count; i++) { ModelMesh modelMesh = modelo.GetAnimatedModel().Meshes[i]; for (int j = 0; j < modelMesh.MeshParts.Count; j++) { SkinnedEffect basicEffect = (SkinnedEffect)modelMesh.MeshParts[j].Effect; if (EnableTexture) { basicEffect.Texture = modelo.getTexture(TextureType.DIFFUSE, i, j); } if (followBone) { basicEffect.World = Followed.GetBoneAbsoluteTransform(boneName) * Followobj.WorldMatrix; basicEffect.SetBoneTransforms(modelo.getBonesTransformation()); } else { basicEffect.World = WorldMatrix; basicEffect.SetBoneTransforms(ac.GetBoneTransformations()); } basicEffect.View = cam.View; basicEffect.Projection = cam.Projection; } modelMesh.Draw(); } }
/// <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; }
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 }
public void Render(ref Matrix worldMatrix, string techniqueName, RenderHandler renderDelegate) { SkinnedEffect effect = (internalEffect != null) ? internalEffect : skinnedEffect; effect.View = State.ViewMatrix; effect.Projection = State.ProjectionMatrix; effect.World = worldMatrix; foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Apply(); renderDelegate(); } }
/// <summary> /// Creates a simple shader to render 3D meshes using the BasicEffect class. /// </summary> /// <exception cref="GoblinException"></exception> public SkinnedModelShader() { if (!State.Initialized) { throw new GoblinException("Goblin XNA needs to be initialized first using State.InitGoblin(..)"); } skinnedEffect = new SkinnedEffect(State.Device); lightSources = new List <LightSource>(); ambientLight = Vector3.Zero; originalSet = false; alphaIndexer = 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); }
public void SetParameters(Material material) { if (material.InternalEffect != null) { if (material.InternalEffect is SkinnedEffect) { internalEffect = (SkinnedEffect)material.InternalEffect; internalEffect.Alpha = originalAlphas[alphaIndexer] * material.Diffuse.W; internalEffect.PreferPerPixelLighting = skinnedEffect.PreferPerPixelLighting; internalEffect.AmbientLightColor = skinnedEffect.AmbientLightColor; if (lightsChanged) { if (lightSources.Count > 0) { DirectionalLight[] lights = { internalEffect.DirectionalLight0, internalEffect.DirectionalLight1, internalEffect.DirectionalLight2 }; int numLightSource = lightSources.Count; for (int i = 0; i < numLightSource; i++) { lights[i].Enabled = true; lights[i].DiffuseColor = Vector3Helper.GetVector3(lightSources[i].Diffuse); lights[i].Direction = lightSources[i].Direction; lights[i].SpecularColor = Vector3Helper.GetVector3(lightSources[i].Specular); } } } alphaIndexer = (alphaIndexer + 1) % originalAlphas.Length; } else { Log.Write("Passed internal effect is not BasicEffect, so we can not apply the " + "effect to this shader", Log.LogLevel.Warning); } } else { skinnedEffect.Alpha = material.Diffuse.W; skinnedEffect.DiffuseColor = Vector3Helper.GetVector3(material.Diffuse); skinnedEffect.SpecularColor = Vector3Helper.GetVector3(material.Specular); skinnedEffect.EmissiveColor = Vector3Helper.GetVector3(material.Emissive); skinnedEffect.SpecularPower = material.SpecularPower; skinnedEffect.Texture = material.Texture; } }
private void ApplySkinnedEffect() { foreach (var mesh in Model.Meshes) { foreach (var part in mesh.MeshParts) { SkinnedEffect seffect = new SkinnedEffect(GameUtilities.GraphicsDevice); BasicEffect originalEffect = part.Effect as BasicEffect; seffect.Texture = originalEffect.Texture; seffect.SpecularColor = originalEffect.SpecularColor; seffect.DiffuseColor = originalEffect.DiffuseColor; part.Effect = seffect; } } }
public ExampleModelClass(AnimationModelContent model, SkinnedEffect effect) { this.model = model; this.effect = effect; skeleton = model.GetSkeleton(); animationStates = new List <AnimationState>(); for (int i = 0; i < model.GetAnimationCount(); i++) { Animation animation = model.GetAnimation(i); AnimationState state = new AnimationState(animation); animationStates.Add(state); } animationTransforms = new Matrix[skeleton.GetBoneCount()]; }
public Effect UseSkinnedEffect(Schema2.Material srcMaterial) { if (_Device == null) { throw new InvalidOperationException(); } if (srcMaterial == null) { if (_DefaultSkinned == null) { _DefaultSkinned = new SkinnedEffect(_Device); _Disposables.AddDisposable(_DefaultRigid); } return(_DefaultSkinned); } if (_SkinnedEffects.TryGetValue(srcMaterial, out SkinnedEffect dstMaterial)) { return(dstMaterial); } dstMaterial = new SkinnedEffect(_Device); _SkinnedEffects[srcMaterial] = dstMaterial; _Disposables.AddDisposable(dstMaterial); dstMaterial.Name = srcMaterial.Name; dstMaterial.Alpha = GetAlphaLevel(srcMaterial); dstMaterial.DiffuseColor = GetDiffuseColor(srcMaterial); dstMaterial.SpecularColor = GetSpecularColor(srcMaterial); dstMaterial.SpecularPower = GetSpecularPower(srcMaterial); dstMaterial.EmissiveColor = GeEmissiveColor(srcMaterial); dstMaterial.Texture = GetDiffuseTexture(srcMaterial); dstMaterial.WeightsPerVertex = 4; dstMaterial.PreferPerPixelLighting = true; // apparently, SkinnedEffect does not support disabling textures, so we set a white texture here. if (dstMaterial.Texture == null) { dstMaterial.Texture = _TexFactory.UseWhiteImage(); } return(dstMaterial); }
public GenericEffect(Effect effectToAssimilate) : this() { /* * DefaultShaderType type = DetermineEffect( false, effectToAssimilate ); * if( type == DefaultShaderType.Basic ) * { * mBasicEffect = (BasicEffect)effectToAssimilate; * } * else if( type == DefaultShaderType.DualTexture ) * { * mDualTextureEffect = (DualTextureEffect)effectToAssimilate; * } * else if( type == DefaultShaderType.EnvironmentMapped ) * { * mEnvironmentMapEffect = (EnvironmentMapEffect)effectToAssimilate; * } * else if( type == DefaultShaderType.Skinned ) * { * mSkinnedEffect = (SkinnedEffect)effectToAssimilate; * } */ if (effectToAssimilate is BasicEffect) { mBasicEffect = effectToAssimilate as BasicEffect; } else if (effectToAssimilate is AlphaTestEffect) { mAlphaTestEffect = effectToAssimilate as AlphaTestEffect; } #if !MONOGAME else if (effectToAssimilate is DualTextureEffect) { mDualTextureEffect = effectToAssimilate as DualTextureEffect; } else if (effectToAssimilate is EnvironmentMapEffect) { mEnvironmentMapEffect = effectToAssimilate as EnvironmentMapEffect; } else if (effectToAssimilate is SkinnedEffect) { mSkinnedEffect = effectToAssimilate as SkinnedEffect; } #endif }
/// <summary> /// Looks up shortcut references to our effect parameters. /// </summary> void CacheEffectParameters(SkinnedEffect cloneSource) { textureParam = Parameters["Texture"]; diffuseColorParam = Parameters["DiffuseColor"]; emissiveColorParam = Parameters["EmissiveColor"]; specularColorParam = Parameters["SpecularColor"]; specularPowerParam = Parameters["SpecularPower"]; eyePositionParam = Parameters["EyePosition"]; fogColorParam = Parameters["FogColor"]; fogVectorParam = Parameters["FogVector"]; worldParam = Parameters["World"]; worldInverseTransposeParam = Parameters["WorldInverseTranspose"]; worldViewProjParam = Parameters["WorldViewProj"]; bonesParam = Parameters["Bones"]; shaderIndexParam = Parameters["ShaderIndex"]; lightPositionsParam = Parameters["lightPositions"]; lightColorsParam = Parameters["lightColors"]; }
public void LoadAnimatedModel(out Model model, string filePath) { model = Game.Content.Load <Model>(filePath); foreach (ModelMesh mesh in model.Meshes) { foreach (ModelMeshPart part in mesh.MeshParts) { SkinnedEffect skinnedEffect = part.Effect as SkinnedEffect; if (skinnedEffect != null) { CustomSkinnedEffect newEffect = new CustomSkinnedEffect(toonAnimatedEffect); newEffect.CopyFromSkinnedEffect(skinnedEffect); newEffect.LightPositions = camera.lightPositions; part.Effect = newEffect; } } } }
public RendererXNA(GraphicsDevice device) { this.modelMatrixStack.Push(Matrix.Identity); this.projMat = Matrix.Identity; this.viewMat = Matrix.Identity; this.basicEffect = new BasicEffect(device); this.multiTexture = new DualTextureEffect(device); this.skinnedEffect = new SkinnedEffect(device); this.skinnedEffect.WeightsPerVertex = 4; this.alphaTestEffect = new AlphaTestEffect(device); this.device = device; this.numTex = 0; this.m_cachedFog = (Fog)null; this.initBlendStates(); this.initRasterStates(); this.initDepthStates(); this.initSamplerStates(); }
public GenericEffect(DefaultShaderType type) : this() { if (type != DefaultShaderType.Determine) { if (type == DefaultShaderType.Basic) { mBasicEffect = new BasicEffect(FlatRedBallServices.GraphicsDevice); } else if (type == DefaultShaderType.AlphaTest) { mAlphaTestEffect = new AlphaTestEffect(FlatRedBallServices.GraphicsDevice); } else if (type == DefaultShaderType.DualTexture) { #if MONOGAME throw new NotImplementedException(); #else mDualTextureEffect = new DualTextureEffect(FlatRedBallServices.GraphicsDevice); #endif } else if (type == DefaultShaderType.EnvironmentMapped) { #if MONOGAME throw new NotImplementedException(); #else mEnvironmentMapEffect = new EnvironmentMapEffect(FlatRedBallServices.GraphicsDevice); #endif } else if (type == DefaultShaderType.Skinned) { #if MONOGAME throw new NotImplementedException(); #else mSkinnedEffect = new SkinnedEffect(FlatRedBallServices.GraphicsDevice); #endif } } }
} // GetBoneMatrices() #endregion #region SetBoneMatrices internal void SetBoneMatrices(Matrix[] matrices, SkinnedEffect skinnedEffect)//, HVertexShader vertexShader) { Vector4[] values = new Vector4[matrices.Length * 3]; for (int i = 0; i < matrices.Length; i++) { // Note: We use the transpose matrix here. // This has to be reconstructed in the shader, but this is not // slower than directly using matrices and this is the only way // we can store 80 matrices with ps2.0. values[i * 3 + 0] = new Vector4( matrices[i].M11, matrices[i].M21, matrices[i].M31, matrices[i].M41); values[i * 3 + 1] = new Vector4( matrices[i].M12, matrices[i].M22, matrices[i].M32, matrices[i].M42); values[i * 3 + 2] = new Vector4( matrices[i].M13, matrices[i].M23, matrices[i].M33, matrices[i].M43); } // for //vertexShader.SetValue("skinnedMatricesVS20", values); skinnedEffect.SetBoneTransforms(matrices); }
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; } } }
/// <summary> /// Render the animated model (will call UpdateAnimation internally, /// but if you do that yourself before calling this method, it gets /// optimized out). Rendering always uses the skinnedNormalMapping shader /// with the DiffuseSpecular20 technique. /// </summary> /// <param name="renderMatrix">Render matrix</param> internal void Render(SkinnedEffect effect, Matrix renderMatrix, GameTime gameTime) { if (IsValid == false) { return; } // Make sure we use the correct vertex declaration for our shader. /*AlkaronCoreGame.Core.GraphicsDevice.VertexDeclaration = * SkinnedTangentVertex.VertexDecl;*/ Matrix[] boneMats = GetBoneMatrices(renderMatrix); // Set custom skinnedMatrices SetBoneMatrices(boneMats, effect); // Render the mesh RenderVertices(); }
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; } } }
/// <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(); } }
/// <summary> /// Creates a new SkinnedEffect by cloning parameter settings from an existing instance. /// </summary> protected CustomSkinnedEffect(SkinnedEffect cloneSource) : base(cloneSource) { CacheEffectParameters(cloneSource); preferPerPixelLighting = cloneSource.PreferPerPixelLighting; fogEnabled = cloneSource.FogEnabled; world = cloneSource.World; view = cloneSource.View; projection = cloneSource.Projection; diffuseColor = cloneSource.DiffuseColor; emissiveColor = cloneSource.EmissiveColor; ambientLightColor = cloneSource.AmbientLightColor; alpha = cloneSource.Alpha; fogStart = cloneSource.FogStart; fogEnd = cloneSource.FogEnd; weightsPerVertex = cloneSource.WeightsPerVertex; }
/// <summary> /// Constructor of the <c>AnimatedModel</c> class. /// </summary> /// <param name="model">Reference to the model.</param> /// <param name="position">Initial position of the model.</param> /// <param name="rotation">Initial rotation of the model.</param> /// <param name="scale">Initial scale of the model.</param> /// <param name="modelID">Id to identify the model.</param> /// <param name="meshesToDraw">List of meshes to draw.</param> public AnimatedModel(GameModel model, Vector3 position, Vector3 rotation, Vector3 scale, int modelID, bool meshesToDraw = false) : base(model, position, rotation, scale, modelID) { _modelSkinningData = Model.Model.Tag as SkinningData; _animation = new AnimationPlayer(_modelSkinningData); SkinnedEffect effect = (SkinnedEffect)base.Model.Model.Meshes[0].MeshParts[0].Effect; _damageColor = Color.Red.ToVector3(); _naturalDiffuseColor = effect.DiffuseColor; _naturalAmbientColor = effect.AmbientLightColor; if (meshesToDraw) { _meshesToDraw = new List <string>(); _meshesToDraw.Add("Model"); } else { _meshesToDraw = null; } }
/// <summary> /// Looks up shortcut references to our effect parameters. /// </summary> void CacheEffectParameters(SkinnedEffect cloneSource) { textureParam = Parameters["Texture"]; diffuseColorParam = Parameters["DiffuseColor"]; emissiveColorParam = Parameters["EmissiveColor"]; specularColorParam = Parameters["SpecularColor"]; specularPowerParam = Parameters["SpecularPower"]; eyePositionParam = Parameters["EyePosition"]; fogColorParam = Parameters["FogColor"]; fogVectorParam = Parameters["FogVector"]; worldParam = Parameters["World"]; worldInverseTransposeParam = Parameters["WorldInverseTranspose"]; worldViewProjParam = Parameters["WorldViewProj"]; bonesParam = Parameters["Bones"]; shaderIndexParam = Parameters["ShaderIndex"]; light0 = new DirectionalLight(Parameters["DirLight0Direction"], Parameters["DirLight0DiffuseColor"], Parameters["DirLight0SpecularColor"], (cloneSource != null) ? cloneSource.light0 : null); light1 = new DirectionalLight(Parameters["DirLight1Direction"], Parameters["DirLight1DiffuseColor"], Parameters["DirLight1SpecularColor"], (cloneSource != null) ? cloneSource.light1 : null); light2 = new DirectionalLight(Parameters["DirLight2Direction"], Parameters["DirLight2DiffuseColor"], Parameters["DirLight2SpecularColor"], (cloneSource != null) ? cloneSource.light2 : null); }
/// <summary> /// Creates a new SkinnedEffect by cloning parameter settings from an existing instance. /// </summary> protected SkinnedEffect(SkinnedEffect cloneSource) : base(cloneSource) { CacheEffectParameters(cloneSource); preferPerPixelLighting = cloneSource.preferPerPixelLighting; fogEnabled = cloneSource.fogEnabled; world = cloneSource.world; view = cloneSource.view; projection = cloneSource.projection; diffuseColor = cloneSource.diffuseColor; emissiveColor = cloneSource.emissiveColor; ambientLightColor = cloneSource.ambientLightColor; alpha = cloneSource.alpha; fogStart = cloneSource.fogStart; fogEnd = cloneSource.fogEnd; weightsPerVertex = cloneSource.weightsPerVertex; }
public void SetLightViewProjection(ref SkinnedEffect effect) { effect.LightViewProjection = this.lightViewProjectionMatrix; }
public void SetLights(ref SkinnedEffect effect) { effect.LightColor = lightColor; effect.AmbientLightColor = ambientLightColor; effect.LightDirection = directionToSun; effect.ShadowMap = shadowMap; effect.TexelSize = TexelSize; effect.LightViewProjections = this.LightViewProjectionMatrices; effect.ClipPlanes = this.LightClipPlanes; #if TUNE_DEPTH_BIAS effect.Parameters["DepthBias"].SetValue(DepthBias); #endif }
public override void LoadContent(Microsoft.Xna.Framework.Content.ContentManager content, ParameterSet parm, Stage stage) { if (contentLoaded) return; bool initialized = false; model = BasicModelLoad(parm, out initialized); this.modelExtra = model.Tag as ModelExtra; System.Diagnostics.Debug.Assert(modelExtra != null); if (!initialized) { foreach (ModelMesh mesh in Model.Meshes) { foreach (ModelMeshPart part in mesh.MeshParts) { if (IsBumpMapped && IsSpecularMapped) { SkinnedBumpedSpecularEffect effect = new SkinnedBumpedSpecularEffect(content.Load<Effect>("Effects/v2/SkinnedWithSpecular")); effect.Shininess = Shininess; effect.SpecularPower = SpecularPower; part.Effect = effect; } else if (IsBumpMapped && !IsSpecularMapped) { SkinnedBumpedEffect effect = new SkinnedBumpedEffect(content.Load<Effect>("Effects/v2/SkinnedBumped")); effect.Shininess = Shininess; effect.SpecularPower = SpecularPower; part.Effect = effect; } else if (!IsBumpMapped && !IsSpecularMapped) { SkinnedEffect effect = new SkinnedEffect(content.Load<Effect>("Effects/v2/Skinned")); effect.Shininess = Shininess; effect.SpecularPower = SpecularPower; part.Effect = effect; } } } } base.LoadContent(content, parm, stage); }