protected override MaterialContent ConvertMaterial(MaterialContent material, ContentProcessorContext context) { EffectMaterialContent normalMappingMaterial = new EffectMaterialContent(); normalMappingMaterial.Effect = new ExternalReference <EffectContent> (Path.Combine("Effects/renderGBuffer.fx")); OpaqueDataDictionary processorParameters = new OpaqueDataDictionary(); processorParameters["ColorKeyColor"] = this.ColorKeyColor; processorParameters["ColorKeyEnabled"] = this.ColorKeyEnabled; processorParameters["TextureFormat"] = this.TextureFormat; processorParameters["GenerateMipmaps"] = this.GenerateMipmaps; processorParameters["ResizeTexturesToPowerOfTwo"] = this.ResizeTexturesToPowerOfTwo; // copy the textures in the original material to the new normal mapping // material. this way the diffuse texture is preserved. The // PreprocessSceneHierarchy function has already added the normal map // texture to the Textures collection, so that will be copied as well. foreach (KeyValuePair <String, ExternalReference <TextureContent> > texture in material.Textures) { normalMappingMaterial.Textures.Add(texture.Key, texture.Value); } // and convert the material using the NormalMappingMaterialProcessor, // who has something special in store for the normal map. return(context.Convert <MaterialContent, MaterialContent> (normalMappingMaterial, typeof(DeferredMaterialProcessor).Name, processorParameters)); }
/// <summary> /// Changes all the materials to use our skinned model effect. /// </summary> protected override MaterialContent ConvertMaterial(MaterialContent material, ContentProcessorContext context) { BasicMaterialContent basicMaterial = material as BasicMaterialContent; if (basicMaterial == null) { throw new InvalidContentException(string.Format( "SkinnedModelProcessor only supports BasicMaterialContent, " + "but input mesh uses {0}.", material.GetType())); } EffectMaterialContent effectMaterial = new EffectMaterialContent(); // Store a reference to our skinned mesh effect. string effectPath = Path.GetFullPath("SkinnedModel.fx"); effectMaterial.Effect = new ExternalReference <EffectContent>(effectPath); // Copy texture settings from the input // BasicMaterialContent over to our new material. if (basicMaterial.Texture != null) { effectMaterial.Textures.Add("Texture", basicMaterial.Texture); } // Chain to the base ModelProcessor converter. return(base.ConvertMaterial(effectMaterial, context)); }
protected override MaterialContent ConvertMaterial( MaterialContent material, ContentProcessorContext context) { EffectMaterialContent deferredShadingMaterial = new EffectMaterialContent(); deferredShadingMaterial.Effect = new ExternalReference <EffectContent> (effectDirectory + "RenderGBuffer.fx"); // copy the textures in the original material to the new normal mapping // material, if they are relevant to our renderer. The // LookUpTextures function has added the normal map and specular map // textures to the Textures collection, so that will be copied as well. foreach (KeyValuePair <String, ExternalReference <TextureContent> > texture in material.Textures) { if ((texture.Key == "Texture") || (texture.Key == "NormalMap") || (texture.Key == "SpecularMap")) { deferredShadingMaterial.Textures.Add(texture.Key, texture.Value); } } return(context.Convert <MaterialContent, MaterialContent>(deferredShadingMaterial, typeof(MaterialProcessor).Name)); }
private void ExtractTextures(EffectMaterialContent lppMaterial, MaterialContent material) { foreach (KeyValuePair <String, ExternalReference <TextureContent> > texture in material.Textures) { if (texture.Key.ToLower().Equals("diffusemap") || texture.Key.ToLower().Equals("texture")) { lppMaterial.Textures.Add(DiffuseMapKey, texture.Value); } if (texture.Key.ToLower().Equals("normalmap")) { lppMaterial.Textures.Add(NormalMapKey, texture.Value); } if (texture.Key.ToLower().Equals("specularmap")) { lppMaterial.Textures.Add(SpecularMapKey, texture.Value); } if (texture.Key.ToLower().Equals("emissivemap") || texture.Key.ToLower().Equals("emissive")) { lppMaterial.Textures.Add(EmissiveMapKey, texture.Value); } if (texture.Key.ToLower().Equals("seconddiffusemap")) { lppMaterial.Textures.Add(SecondDiffuseMapKey, texture.Value); } if (texture.Key.ToLower().Equals("secondnormalmap")) { lppMaterial.Textures.Add(SecondNormalMapKey, texture.Value); } if (texture.Key.ToLower().Equals("secondspecularmap")) { lppMaterial.Textures.Add(SecondSpecularMapKey, texture.Value); } if (texture.Key.ToLower().Equals("reflectionmap")) { lppMaterial.Textures.Add(ReflectionMapKey, texture.Value); } } ExternalReference <TextureContent> externalRef; if (!lppMaterial.Textures.TryGetValue(DiffuseMapKey, out externalRef)) { lppMaterial.Textures[DiffuseMapKey] = new ExternalReference <TextureContent>("textures/default_diffuse.tga"); } if (!lppMaterial.Textures.TryGetValue(NormalMapKey, out externalRef)) { lppMaterial.Textures[NormalMapKey] = new ExternalReference <TextureContent>("textures/default_normal.tga"); } if (!lppMaterial.Textures.TryGetValue(SpecularMapKey, out externalRef)) { lppMaterial.Textures[SpecularMapKey] = new ExternalReference <TextureContent>("textures/default_specular.tga"); } if (!lppMaterial.Textures.TryGetValue(EmissiveMapKey, out externalRef)) { lppMaterial.Textures[EmissiveMapKey] = new ExternalReference <TextureContent>("textures/default_emissive.tga"); } }
/// <summary> /// Creates new material with the new effect file. /// </summary> public override MaterialContent Process(MaterialContent input, ContentProcessorContext context) { if (string.IsNullOrEmpty(customEffect)) { throw new ArgumentException("Custom Effect not set to an effect file"); } // Create a new effect material. EffectMaterialContent customMaterial = new EffectMaterialContent(); // Point the new material at the custom effect file. string effectFile = Path.GetFullPath(customEffect); customMaterial.Effect = new ExternalReference <EffectContent>(effectFile); // Loop over the textures in the current material adding them to // the new material. foreach (KeyValuePair <string, ExternalReference <TextureContent> > textureContent in input.Textures) { customMaterial.Textures.Add(textureContent.Key, textureContent.Value); } // Loop over the opaque data in the current material adding them to // the new material. foreach (KeyValuePair <string, Object> opaqueData in input.OpaqueData) { customMaterial.OpaqueData.Add(opaqueData.Key, opaqueData.Value); } // Call the base material processor to continue the rest of the processing. return(base.Process(customMaterial, context)); }
/// <summary> /// Stores the current selected technique and if the texture uses alpha /// into the mesh name for each mesh part. /// </summary> private void StoreEffectTechniqueInMeshName( NodeContent input, ContentProcessorContext context) { MeshContent mesh = input as MeshContent; if (mesh != null) { foreach (GeometryContent geom in mesh.Geometry) { EffectMaterialContent effectMaterial = geom.Material as EffectMaterialContent; if (effectMaterial != null) { if (effectMaterial.OpaqueData.ContainsKey("technique")) { // Store technique here! (OpaqueData["technique"] is an // int32) If we have multiple mesh parts in our mesh object, // there will be multiple techniques listed at the end of // our mesh name. input.Name = input.Name + effectMaterial.OpaqueData["technique"]; } } } } // Go through all childs foreach (NodeContent child in input.Children) { StoreEffectTechniqueInMeshName(child, context); } }
/// <summary> /// Extract any defines we need from the original material, like alphaMasked, fresnel, reflection, etc, and pass it into /// the opaque data /// </summary> /// <param name="lppMaterial"></param> /// <param name="material"></param> /// <param name="context"></param> private void ExtractDefines(EffectMaterialContent lppMaterial, MaterialContent material, ContentProcessorContext context) { string defines = ""; if (material.OpaqueData.ContainsKey("alphaMasked") && material.OpaqueData["alphaMasked"].ToString() == "True") { context.Logger.LogMessage("Alpha masked material found"); lppMaterial.OpaqueData.Add("AlphaReference", (float)material.OpaqueData["AlphaReference"]); defines += "ALPHA_MASKED;"; } if (material.OpaqueData.ContainsKey("reflectionEnabled") && material.OpaqueData["reflectionEnabled"].ToString() == "True") { context.Logger.LogMessage("Reflection enabled"); defines += "REFLECTION_ENABLED;"; } if (_isSkinned) { context.Logger.LogMessage("Skinned mesh found"); defines += "SKINNED_MESH;"; } if (material.OpaqueData.ContainsKey("dualLayerEnabled") && material.OpaqueData["dualLayerEnabled"].ToString() == "True") { context.Logger.LogMessage("Dual layer material found"); defines += "DUAL_LAYER;"; } if (!String.IsNullOrEmpty(defines)) { lppMaterial.OpaqueData.Add("Defines", defines); } }
/// <summary> /// Converts an input material to use our custom InstancedModel effect. /// </summary> MaterialContent ProcessMaterial(MaterialContent material) { // Have we already processed this material? if (!processedMaterials.ContainsKey(material)) { // If not, process it now. EffectMaterialContent instancedMaterial = new EffectMaterialContent(); // Set the material to use our custom instancing effect. instancedMaterial.Effect = new ExternalReference <EffectContent>( "InstancedModel.fx", rootNode.Identity); // Copy across the texture setting from the input material. if (!material.Textures.ContainsKey("Texture")) { throw new InvalidContentException( "Material has no texture, but the InstancedModel " + "effect does not support untextured materials."); } instancedMaterial.Textures.Add("Texture", material.Textures["Texture"]); // Chain to the built-in MaterialProcessor, which will // build the effect and texture referenced by this material. processedMaterials[material] = context.Convert <MaterialContent, MaterialContent>(instancedMaterial, "MaterialProcessor"); } return(processedMaterials[material]); }
protected override MaterialContent ConvertMaterial(MaterialContent material, ContentProcessorContext context) { EffectMaterialContent lppMaterial = new EffectMaterialContent(); OpaqueDataDictionary processorParameters = new OpaqueDataDictionary(); processorParameters["ColorKeyColor"] = this.ColorKeyColor; processorParameters["ColorKeyEnabled"] = false; processorParameters["TextureFormat"] = this.TextureFormat; processorParameters["GenerateMipmaps"] = this.GenerateMipmaps; processorParameters["ResizeTexturesToPowerOfTwo"] = this.ResizeTexturesToPowerOfTwo; processorParameters["PremultiplyTextureAlpha"] = false; processorParameters["ColorKeyEnabled"] = false; lppMaterial.Effect = new ExternalReference <EffectContent>(_customFx.Length == 0 ? "shaders/LPPMainEffect.fx" : _customFx); lppMaterial.CompiledEffect = context.BuildAsset <EffectContent, CompiledEffectContent>(lppMaterial.Effect, "EffectProcessor"); // copy the textures in the original material to the new lpp // material ExtractTextures(lppMaterial, material); //extract the extra parameters ExtractDefines(lppMaterial, material, context); // and convert the material using the NormalMappingMaterialProcessor, // who has something special in store for the normal map. return(context.Convert <MaterialContent, MaterialContent> (lppMaterial, typeof(LightPrePassMaterialProcessor).Name, processorParameters)); }
private void CreateMaterial() { using (XmlReader reader = XmlReader.Create(MaterialDataFilePath)) { mTerrainMaterial = IntermediateSerializer.Deserialize <List <MaterialData> >(reader, null); } MaterialData tmSingle = mTerrainMaterial.Single(); EffectMaterialContent emc = new EffectMaterialContent(); emc.Effect = new ExternalReference <EffectContent>(Path.Combine(Environment.CurrentDirectory, tmSingle.CustomEffect)); emc.Name = tmSingle.Name; foreach (EffectParam ep in tmSingle.EffectParams) { if (ep.Category == EffectParamCategory.OpaqueData) { emc.OpaqueData.Add(ep.Name, ep.Value); } else if (ep.Category == EffectParamCategory.Texture) { emc.Textures.Add(ep.Name, new ExternalReference <TextureContent>((string)(ep.Value))); } } mOutputTC.Tag = tmSingle.HandlingFlags; #if XBOX outputTC.MaterialContent = context.Convert <MaterialContent, MaterialContent>(emc, "MaterialProcessor"); #else mOutputTC.MaterialContent = mContext.Convert <MaterialContent, MaterialContent>(emc, "FxcMaterialProcessor"); #endif }
protected override MaterialContent ConvertMaterial(MaterialContent material, ContentProcessorContext context) { EffectMaterialContent myMaterial = new EffectMaterialContent(); if (material is BasicMaterialContent) { return(base.ConvertMaterial(material, context)); } else if (material is EffectMaterialContent) { EffectMaterialContent effectMaterialContent = (EffectMaterialContent)material; // // remap effect // myMaterial.Effect = new ExternalReference <EffectContent>(effectMaterialContent.Effect.Filename); // textures foreach (KeyValuePair <string, ExternalReference <TextureContent> > pair in effectMaterialContent.Textures) { string textureKey = pair.Key; ExternalReference <TextureContent> textureContent = pair.Value; if (!string.IsNullOrEmpty(textureContent.Filename)) { myMaterial.Textures.Add(textureKey, material.Textures[textureKey]); } } } return(base.ConvertMaterial(myMaterial, context)); }
protected override MaterialContent ConvertMaterial(MaterialContent material, ContentProcessorContext context) { BasicMaterialContent basicMaterial = material as BasicMaterialContent; if (basicMaterial == null) { context.Logger.LogImportantMessage("This mesh doesn't have a valid basic material."); } // Only process meshs with basic material // Otherwise the mesh must be using the correct shader (AnimatedModel.fx) if (basicMaterial != null) { EffectMaterialContent effectMaterial = new EffectMaterialContent(); effectMaterial.Effect = new ExternalReference <EffectContent>(EFFECTS_PATH + EFFECT_FILENAME); // Correct the texture path if (basicMaterial.Texture != null) { string textureFileName = Path.GetFileName(basicMaterial.Texture.Filename); effectMaterial.Textures.Add("diffuseTexture1", new ExternalReference <TextureContent>(TEXTURES_PATH + textureFileName)); } return(base.ConvertMaterial(effectMaterial, context)); } else { return(base.ConvertMaterial(material, context)); } }
public override MyreMaterialContent Process(MyreMaterialData input, ContentProcessorContext context) { MyreMaterialContent output = new MyreMaterialContent(); output.Technique = input.Technique; EffectMaterialContent material = new EffectMaterialContent(); material.Effect = new ExternalReference <EffectContent>(input.EffectName); foreach (var texture in input.Textures) { material.Textures.Add(texture.Key, new ExternalReference <TextureContent>(texture.Value)); } foreach (var item in input.OpaqueData) { material.OpaqueData.Add(item.Key, item.Value); } var processorParameters = new OpaqueDataDictionary(); processorParameters.Add("PremultiplyTextureAlpha", false); output.Material = context.Convert <MaterialContent, MaterialContent>(material, "MaterialProcessor", processorParameters); return(output); }
} // UseParentBoneNameIfMeshNameIsNotSet(input) #endregion #region StoreEffectMaterialsAndTechniques /// <summary> /// Stores the current selected technique and if the texture uses alpha /// into the mesh name for each mesh part. /// </summary> private void StoreEffectTechniqueInMeshName( NodeContent input, ContentProcessorContext context) { MeshContent mesh = input as MeshContent; if (mesh != null) { foreach (GeometryContent geom in mesh.Geometry) { EffectMaterialContent effectMaterial = geom.Material as EffectMaterialContent; if (effectMaterial != null) { if (effectMaterial.OpaqueData.ContainsKey("technique")) { // Store technique here! (OpaqueData["technique"] is an int32) input.Name = input.Name + effectMaterial.OpaqueData["technique"]; } // if (effectMaterial.OpaqueData.ContainsKey) } // if (effectMaterial) } // foreach (geom) } // if (mesh) // Go through all childs foreach (NodeContent child in input.Children) { StoreEffectTechniqueInMeshName(child, context); } // foreach (child) } // StoreEffectTechniqueInMeshName(input, context)
/// <summary> /// Converts a material. /// </summary> public override MaterialContent Process(MaterialContent input, ContentProcessorContext context) { // Create a new effect material. EffectMaterialContent customMaterial = new EffectMaterialContent(); // Point the new material at our custom effect file. string effectFile = Path.GetFullPath("Shaders/ShipEffect.fx"); customMaterial.Effect = new ExternalReference <EffectContent>(effectFile); // Copy texture data across from the original material. BasicMaterialContent basicMaterial = (BasicMaterialContent)input; if (basicMaterial.Texture != null) { customMaterial.Textures.Add("DiffuseTexture", basicMaterial.Texture); customMaterial.OpaqueData.Add("TextureEnabled", true); } // Add in the Normal and Specular maps string normalTexture = basicMaterial.Texture.Filename.Replace("_c", "_n"); string specularTexture = basicMaterial.Texture.Filename.Replace("_c", "_s"); string emissiveTexture = basicMaterial.Texture.Filename.Replace("_c", "_i"); customMaterial.Textures.Add("SpecularTexture", new ExternalReference <TextureContent>(specularTexture)); customMaterial.Textures.Add("NormalTexture", new ExternalReference <TextureContent>(normalTexture)); customMaterial.Textures.Add("EmissiveTexture", new ExternalReference <TextureContent>(emissiveTexture)); // Chain to the base material processor. return(base.Process(customMaterial, context)); }
/// <summary> /// Converts a material. /// </summary> public override MaterialContent Process(MaterialContent input, ContentProcessorContext context) { // Create a new effect material. EffectMaterialContent customMaterial = new EffectMaterialContent(); // Point the new material at our custom effect file. string effectFile = Path.GetFullPath("EnvironmentMap.fx"); customMaterial.Effect = new ExternalReference <EffectContent>(effectFile); // Copy texture data across from the original material. BasicMaterialContent basicMaterial = (BasicMaterialContent)input; if (basicMaterial.Texture != null) { customMaterial.Textures.Add("Texture", basicMaterial.Texture); customMaterial.OpaqueData.Add("TextureEnabled", true); } // Add the reflection texture. string envmap = Path.GetFullPath(EnvironmentMap); customMaterial.Textures.Add("EnvironmentMap", new ExternalReference <TextureContent>(envmap)); // Chain to the base material processor. return(base.Process(customMaterial, context)); }
protected override MaterialContent ConvertMaterial(MaterialContent material, ContentProcessorContext context) { OpaqueDataDictionary pparams = new OpaqueDataDictionary( ); pparams["ColorKeyEnabled"] = false; pparams["GenerateMipmaps"] = this.GenerateMipmaps; pparams["TextureFormat"] = this.TextureFormat; pparams["ResizeTexturesToPowerOfTwo"] = this.ResizeTexturesToPowerOfTwo; pparams["PremultiplyTextureAlpha"] = false; string exePath = Application.ExecutablePath; string appDir = exePath.Replace(Path.GetFileName(exePath), string.Empty); string shaderPath = Path.Combine(appDir, DATA_DIR + @"\game.fx"); EffectMaterialContent vixenMaterial = new EffectMaterialContent( ); vixenMaterial.Effect = new ExternalReference <EffectContent>(shaderPath); vixenMaterial.CompiledEffect = context.BuildAsset <EffectContent, CompiledEffectContent>(vixenMaterial.Effect, "EffectProcessor"); foreach (KeyValuePair <string, ExternalReference <TextureContent> > texture in material.Textures) { switch (texture.Key) { case C4D_DMAP: vixenMaterial.Textures.Add(KEY_DMAP, texture.Value); break; case C4D_NMAP: vixenMaterial.Textures.Add(KEY_NMAP, texture.Value); break; case C4D_SMAP: vixenMaterial.Textures.Add(KEY_SMAP, texture.Value); break; case C4D_EMAP: vixenMaterial.Textures.Add(KEY_EMAP, texture.Value); break; } } if (!vixenMaterial.Textures.ContainsKey(KEY_DMAP)) { vixenMaterial.Textures[KEY_DMAP] = new ExternalReference <TextureContent>(Path.Combine(appDir, DATA_DIR + @"\dmap.tga")); } if (!vixenMaterial.Textures.ContainsKey(KEY_NMAP)) { vixenMaterial.Textures[KEY_DMAP] = new ExternalReference <TextureContent>(Path.Combine(appDir, DATA_DIR + @"\nmap.tga")); } if (!vixenMaterial.Textures.ContainsKey(KEY_SMAP)) { vixenMaterial.Textures[KEY_DMAP] = new ExternalReference <TextureContent>(Path.Combine(appDir, DATA_DIR + @"\smap.tga")); } if (!vixenMaterial.Textures.ContainsKey(KEY_EMAP)) { vixenMaterial.Textures[KEY_DMAP] = new ExternalReference <TextureContent>(Path.Combine(appDir, DATA_DIR + @"\emap.tga")); } return(context.Convert <MaterialContent, MaterialContent>(vixenMaterial, typeof(MaterialProcessor).Name, pparams)); }
protected override MaterialContent ConvertMaterial(MaterialContent material, ContentProcessorContext context) { string effectFile = this.effectFileName; if (string.IsNullOrEmpty(effectFile)) { if (string.IsNullOrEmpty(this.normalMapTexture)) { if (string.IsNullOrEmpty(this.diffuseTexture)) { effectFile = "Effects\\DefaultSolidColor.fx"; } else { effectFile = "Effects\\Default.fx"; } } else { effectFile = "Effects\\DefaultNormalMap.fx"; } } EffectMaterialContent normalMappingMaterial = new EffectMaterialContent(); normalMappingMaterial.Effect = new ExternalReference <EffectContent>(Path.Combine(directory, effectFile)); OpaqueDataDictionary processorParameters = new OpaqueDataDictionary(); processorParameters["ColorKeyColor"] = this.ColorKeyColor; processorParameters["ColorKeyEnabled"] = this.ColorKeyEnabled; processorParameters["TextureFormat"] = this.TextureFormat; processorParameters["PremultiplyTextureAlpha"] = this.PremultiplyTextureAlpha; processorParameters["PremultiplyVertexColors"] = this.PremultiplyVertexColors; processorParameters["GenerateMipmaps"] = this.GenerateMipmaps; processorParameters["ResizeTexturesToPowerOfTwo"] = this.ResizeTexturesToPowerOfTwo; // copy the textures in the original material to the new normal mapping // material. this way the diffuse texture is preserved. The // PreprocessSceneHierarchy function has already added the normal map // texture to the Textures collection, so that will be copied as well. foreach (KeyValuePair <String, ExternalReference <TextureContent> > texture in material.Textures) { normalMappingMaterial.Textures.Add(texture.Key, texture.Value); } if (!string.IsNullOrEmpty(diffuseTexture)) { normalMappingMaterial.Textures.Add("DiffuseTexture", new ExternalReference <TextureContent>(Path.Combine(directory, diffuseTexture))); } // and convert the material using the NormalMappingMaterialProcessor, // who has something special in store for the normal map. #if MONOGAME return(context.Convert <MaterialContent, MaterialContent>(normalMappingMaterial, typeof(MGMaterialProcessor).Name, processorParameters)); #else return(context.Convert <MaterialContent, MaterialContent>(normalMappingMaterial, typeof(MaterialProcessor).Name, processorParameters)); #endif }
public override ParticleSettingsContent Process(ParticleSettingsContent input, ContentProcessorContext context) { // Create an effect material describing how we want to draw these particles. EffectMaterialContent effect = new EffectMaterialContent(); // Set the effect to be used by this material. effect.Effect = new ExternalReference <EffectContent>( "Particles\\ParticleEffect.fx"); // Set the texture to be used by this material. effect.Textures["ParticleTexture"] = new ExternalReference <TextureContent>( input.TextureName + ".png"); // Set parameters describing how the material should be rendered. effect.OpaqueData.Add("Duration", (float)input.Duration.TotalSeconds); effect.OpaqueData.Add("DurationRandomness", input.DurationRandomness); effect.OpaqueData.Add("Gravity", input.Gravity); effect.OpaqueData.Add("EndVelocity", input.EndVelocity); effect.OpaqueData.Add("MinColor", input.MinColor.ToVector4()); effect.OpaqueData.Add("MaxColor", input.MaxColor.ToVector4()); effect.OpaqueData.Add("RotateSpeed", new Vector2(input.MinRotateSpeed, input.MaxRotateSpeed)); effect.OpaqueData.Add("StartSize", new Vector2(input.MinStartSize, input.MaxStartSize)); effect.OpaqueData.Add("EndSize", new Vector2(input.MinEndSize, input.MaxEndSize)); // Choose the appropriate effect technique. If these particles will never // rotate, we can use a simpler pixel shader that requires less GPU power. if ((input.MinRotateSpeed == 0) && (input.MaxRotateSpeed == 0)) { input.TechniqueName = "NonRotatingParticles"; } else { input.TechniqueName = "RotatingParticles"; } // Chain to the built-in MaterialProcessor, telling it to convert the // EffectMaterialContent that we just created. This will automatically // compile the .fx file and texture that the material is referencing, // and fill in the returned material with references to where the compiled // effect and texture have been stored. Because of this, there is no longer // any need to explicitly add the particle effect or textures to the // project: they will now automatically be built and loaded any time they // are referenced by one of our particle description XML files. input.ParticleEffect = context.Convert <MaterialContent, MaterialContent>(effect, "MaterialProcessor"); return(input); }
/// <summary> /// Loads a custom material. That is, loads a material with a custom effect. /// </summary> /// <returns>The custom material</returns> private MaterialContent ImportCustomMaterial() { EffectMaterialContent content = new EffectMaterialContent(); tokens.SkipName(); string effectName = GetAbsolutePath(tokens.NextString()); content.Effect = new ExternalReference <EffectContent>(effectName); // Find value initializers for the effect parameters and set the values // as indicated for (string token = tokens.NextToken(); token != "}"; token = tokens.NextToken()) { if (token == "EffectParamFloats") { tokens.SkipName(); string floatsParamName = tokens.NextString(); int numFloats = tokens.NextInt(); float[] floats = new float[numFloats]; for (int i = 0; i < numFloats; i++) { floats[i] = tokens.NextFloat(); } tokens.SkipToken(); content.OpaqueData.Add(floatsParamName, floats); } else if (token == "EffectParamDWord") { tokens.SkipName(); string dwordParamName = tokens.NextString(); float dword = tokens.NextFloat(); tokens.SkipToken(); content.OpaqueData.Add(dwordParamName, dword); } else if (token == "EffectParamString") { tokens.SkipName(); string stringParamName = tokens.NextString(); string paramValue = tokens.NextString(); tokens.SkipToken(); content.OpaqueData.Add(stringParamName, paramValue); } if (token == "{") { tokens.SkipNode(); } } return(content); }
protected override MaterialContent ConvertMaterial(MaterialContent material, ContentProcessorContext context) { EffectMaterialContent lppMat = new EffectMaterialContent(); lppMat.Effect = new ExternalReference <EffectContent>("Aeon/Shaders/Lpp.fx"); foreach (KeyValuePair <string, ExternalReference <TextureContent> > tex in material.Textures) { if ((tex.Key == "Texture") || (tex.Key == "NormalMap") || (tex.Key == "SpecularMap")) { lppMat.Textures.Add(tex.Key, tex.Value); } } return(context.Convert <MaterialContent, MaterialContent>(lppMat, typeof(MaterialProcessor).Name)); }
/// <summary> /// If the replacement shader string is not empty, replace the shader of the /// given material with the given replacement shader. Copy all shader parameters across. /// </summary> /// <param name="gc">The geometry content to replace the shader in.</param> /// <param name="context">For generating errors.</param> /// <param name="shader">The shader to replace to (or empty string, to do nothing).</param> protected virtual void MaybeReplaceMaterial(GeometryContent gc, ContentProcessorContext context, string shader, ContentIdentity identity) { if (shader.Equals("")) { return; } EffectMaterialContent emc = new EffectMaterialContent(); string prevEffect = ""; foreach (KeyValuePair <string, object> kvp in gc.Material.OpaqueData) { #if DEBUG context.Logger.LogMessage("param {0}: value {1}", kvp.Key, kvp.Value); #endif if (kvp.Key.Equals("Effect")) { prevEffect = (kvp.Value as ExternalReference <EffectContent>).Filename; } else if (kvp.Key.Equals("CompiledEffect")) { throw new System.ArgumentException("Dxt5ModelProcessor cannot do effect substitution of already compiled effects."); } else { emc.OpaqueData.Add(kvp.Key, kvp.Value); } } foreach (KeyValuePair <string, ExternalReference <TextureContent> > tr in gc.Material.Textures) { emc.Textures.Add(tr.Key, tr.Value); } string path = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(identity.SourceFilename), shader); if (shader[0] == '+') { path = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(prevEffect), System.IO.Path.GetFileNameWithoutExtension(prevEffect) + shader.Substring(1) + ".fx"); if (!System.IO.File.Exists(path)) { path = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(identity.SourceFilename), System.IO.Path.GetFileNameWithoutExtension(prevEffect) + shader.Substring(1) + ".fx"); } } context.Logger.LogImportantMessage("{2}: Replacing shader {0} to {1} for {3}", prevEffect, path, identity.SourceFilename, gc.Name); emc.OpaqueData.Add("Effect", new ExternalReference <EffectContent>(path)); gc.Material = emc; }
/// <summary> /// Helper function creates a new geometry object, /// and sets it to use our billboard effect. /// </summary> static GeometryContent CreateVegetationGeometry(string textureFilename, float width, float height, float windAmount, ContentIdentity identity) { GeometryContent geometry = new GeometryContent(); // Add the vertex channels needed for our billboard geometry. VertexChannelCollection channels = geometry.Vertices.Channels; // Add a vertex channel holding normal vectors. channels.Add <Vector3>(VertexChannelNames.Normal(), null); // Add a vertex channel holding texture coordinates. channels.Add <Vector2>(VertexChannelNames.TextureCoordinate(0), null); // Add a second texture coordinate channel, holding a per-billboard // random number. This is used to make each billboard come out a // slightly different size, and to animate at different speeds. channels.Add <float>(VertexChannelNames.TextureCoordinate(1), null); // Create a material for rendering the billboards. EffectMaterialContent material = new EffectMaterialContent(); // Point the material at our custom billboard effect. string directory = Path.GetDirectoryName(identity.SourceFilename); string effectFilename = Path.Combine(directory, "Billboard.fx"); material.Effect = new ExternalReference <EffectContent>(effectFilename); // Set the texture to be used by these billboards. textureFilename = Path.Combine(directory, textureFilename); material.Textures.Add("Texture", new ExternalReference <TextureContent>(textureFilename)); // Set effect parameters describing the size and // wind sensitivity of these billboards. material.OpaqueData.Add("BillboardWidth", width); material.OpaqueData.Add("BillboardHeight", height); material.OpaqueData.Add("WindAmount", windAmount); geometry.Material = material; return(geometry); }
/// <summary> ///Overriding the ConvertMaterial function of ModelProcessor so that we can ///replace the BasicEffect with our own ShatterEffect. /// </summary> /// <param name="material">input Material</param> /// <param name="context">Content processor context</param> /// <returns></returns> protected override MaterialContent ConvertMaterial(MaterialContent material, ContentProcessorContext context) { EffectMaterialContent effect = new EffectMaterialContent(); // Use our own ShatterEffect.fx instead of BasicEffect. effect.Effect = new ExternalReference <EffectContent>("..\\Content\\Shaders\\skinned.fx"); foreach (ExternalReference <TextureContent> texture in material.Textures.Values) { // Add the textures in the source Material to our effect. effect.Textures.Add("diffuseTexture", texture); } return(base.ConvertMaterial(effect, context)); }
/// <summary> /// Changes all the materials to use our skinned model effect. /// </summary> /// <param name="material"> /// The material. /// </param> /// <param name="context"> /// The context. /// </param> protected override MaterialContent ConvertMaterial(MaterialContent material, ContentProcessorContext context) { var basicMaterial = material as BasicMaterialContent; if (basicMaterial == null) { throw new InvalidContentException( string.Format( "SkinnedModelProcessor only supports BasicMaterialContent, " + "but input mesh uses {0}.", material.GetType())); } var effectMaterial = new EffectMaterialContent(); // Store a reference to our skinned mesh effect. string effectPath = string.Empty; if (animationXML != null) { // get all animations XmlNodeList shaderList = animationXML.GetElementsByTagName("shader"); foreach (XmlNode shadernode in shaderList) { effectPath = Path.GetFullPath(shadernode.InnerText.Trim()); } } if (String.IsNullOrEmpty(effectPath)) { // Store a reference to our skinned mesh effect. effectPath = Path.GetFullPath("Effects\\ShadowMap.fx"); } effectMaterial.Effect = new ExternalReference <EffectContent>(effectPath); // Copy texture settings from the input // BasicMaterialContent over to our new material. if (basicMaterial.Texture != null) { effectMaterial.Textures.Add("Texture", basicMaterial.Texture); } // Chain to the base ModelProcessor converter. return(base.ConvertMaterial(effectMaterial, context)); }
protected override MaterialContent ConvertMaterial(MaterialContent material, ContentProcessorContext context) { EffectMaterialContent deferredShadingMaterial = new EffectMaterialContent(); deferredShadingMaterial.Effect = new ExternalReference <EffectContent>("Shaders\\RenderGBuffer.fx"); //Copy textures in the original material to the new normal mapping material if they are relevant to our renderer. //The LookUpTextures function has added the normal map and specular map textures to the Textures colletion so that will be copied as well foreach (var kvp in material.Textures) { if ((kvp.Key == "Texture") || (kvp.Key == "NormalMap") || (kvp.Key == "SpecularMap")) { deferredShadingMaterial.Textures.Add(kvp.Key, kvp.Value); } } return(context.Convert <MaterialContent, MaterialContent>(deferredShadingMaterial, typeof(MaterialProcessor).Name)); }
protected override MaterialContent ConvertMaterial(MaterialContent material, ContentProcessorContext context) { if (string.IsNullOrEmpty(StitchedEffect)) { throw new Exception("Stitched Effect property must be set for StitchUp Model Processor."); } string fullPath = Path.GetFullPath(Path.Combine(new FileInfo(material.Identity.SourceFilename).DirectoryName, StitchedEffect)); context.AddDependency(fullPath); EffectMaterialContent effectMaterial = new EffectMaterialContent { CompiledEffect = context.BuildAsset <StitchedEffectContent, CompiledEffectContent>(new ExternalReference <StitchedEffectContent>(fullPath), typeof(StitchedEffectProcessor).Name), Identity = material.Identity, Name = material.Name }; return(effectMaterial); }
/// <summary> /// Override the ConvertMaterial method to apply our custom InstancedModel.fx shader. /// </summary> protected override MaterialContent ConvertMaterial(MaterialContent material, ContentProcessorContext context) { // Create a new material. EffectMaterialContent newMaterial = new EffectMaterialContent(); // Tell it to use our custom InstancedModel.fx shader. newMaterial.Effect = new ExternalReference <EffectContent>("../shaders/modelrenderer/default.fx", rootIdentity); // Copy the texture setting across from the original material. BasicMaterialContent basicMaterial = material as BasicMaterialContent; if ((basicMaterial != null) && (basicMaterial.Texture != null)) { newMaterial.Textures.Add("Texture", basicMaterial.Texture); } // Chain to the base ModelProcessor, so it can build our new material. return(base.ConvertMaterial(newMaterial, context)); }
/// <summary> /// /// </summary> public override MaterialContent Process(MaterialContent input, ContentProcessorContext context) { // Reference the Distorters effect file EffectMaterialContent effect = new EffectMaterialContent(); effect.Effect = new ExternalReference <EffectContent>("Distorters.fx"); // If the model specifies a displacement map, carry it over ExternalReference <TextureContent> displacementMap; if (input.Textures.TryGetValue(DisplacementMapKey, out displacementMap)) { effect.Textures.Add(DisplacementMapKey, displacementMap); } // Continue processing the distorter effect with the default effect behavior return(base.Process(effect, context)); }
/// <summary> /// Changes all the materials to use our skinned model effect. /// </summary> protected override MaterialContent ConvertMaterial(MaterialContent material, ContentProcessorContext context) { BasicMaterialContent basicMaterial = material as BasicMaterialContent; string effectPath = ""; if (basicMaterial == null) { throw new InvalidContentException(string.Format( "SkinnedModelProcessor only supports BasicMaterialContent, " + "but input mesh uses {0}.", material.GetType())); } EffectMaterialContent effectMaterial = new EffectMaterialContent(); // StoreEffectMaterialContent effectMaterial = new EffectMaterialContent(); a reference to our skinned mesh effect. /* * StreamWriter w = new StreamWriter("test.txt"); * w.WriteLine(); * w.Close(); */ if (File.Exists("Models\\SkinnedModel.fx")) { effectPath = Path.GetFullPath("Models\\SkinnedModel.fx"); } if (effectPath == "") { return(base.ConvertMaterial(material, context)); } effectMaterial.Effect = new ExternalReference <EffectContent>(effectPath); // Copy texture settings from the input // BasicMaterialContent over to our new material. if (basicMaterial.Texture != null) { effectMaterial.Textures.Add("Texture", basicMaterial.Texture); } // Chain to the base ModelProcessor converter. return(base.ConvertMaterial(effectMaterial, context)); }