/// <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("Effects\\PreEffects\\TexturingEffect.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("DefaultTexture", 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); }
/// <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( "InstancedSkinnedModelProcessor 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("SkinnedModelInstancing.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); }
/// <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); }
protected override MaterialContent ConvertMaterial(MaterialContent material, ContentProcessorContext context) { MaterialData mat = incomingMaterials.Single(m => m.Name == material.Name); EffectMaterialContent emc = new EffectMaterialContent(); emc.Effect = new ExternalReference<EffectContent>(Path.Combine(contentPath, mat.CustomEffect)); emc.Name = material.Name; emc.Identity = material.Identity; foreach (KeyValuePair<String, ExternalReference<TextureContent>> texture in material.Textures) { if (texture.Key == "Texture") { emc.Textures.Add(texture.Key, texture.Value); } else { context.Logger.LogWarning(null, material.Identity, "There were some other textures referenced by the model, but we can't properly assign them to the correct effect parameter."); } } foreach (EffectParam ep in mat.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))); } } return base.ConvertMaterial(emc, context); }
protected override MaterialContent ConvertMaterial(MaterialContent material, ContentProcessorContext context) { var customMaterial = new EffectMaterialContent(); customMaterial.Effect = new ExternalReference<EffectContent>(effectPath); //var basicMaterial = (BasicMaterialContent) material; //if (basicMaterial.Texture != null) //{ // customMaterial.Textures.Add(skyMapKey, basicMaterial.Texture); //} foreach (var texture in material.Textures) { customMaterial.Textures.Add(texture.Key, texture.Value); } var parameters = new OpaqueDataDictionary(); parameters["ColorKeyColor"] = ColorKeyColor; parameters["ColorKeyEnabled"] = ColorKeyEnabled; parameters["TextureFormat"] = TextureFormat; parameters["GenerateMipmaps"] = GenerateMipmaps; parameters["ResizeTexturesToPowerOfTwo"] = ResizeTexturesToPowerOfTwo; return context.Convert<MaterialContent, MaterialContent>( customMaterial, typeof(MaterialProcessor).Name, parameters); }
protected override MaterialContent ConvertMaterial(MaterialContent material, ContentProcessorContext context) { var myMaterial = new EffectMaterialContent(); var effectPath = Path.GetFullPath("Effect/Phong.fx"); myMaterial.Effect = new ExternalReference<EffectContent>(effectPath); // マテリアル名をエフェクトに渡す(TODO: これ渡せてないなあ・・・) Console.WriteLine("Material name : " + material.Name); myMaterial.Effect.Name = material.Name; if (material is BasicMaterialContent) { var basicMaterial = (BasicMaterialContent)material; myMaterial.OpaqueData.Add("DiffuseColor", basicMaterial.DiffuseColor); myMaterial.OpaqueData.Add("Alpha", basicMaterial.Alpha); myMaterial.OpaqueData.Add("EmissiveColor", basicMaterial.EmissiveColor); myMaterial.OpaqueData.Add("SpecularColor", basicMaterial.SpecularColor); myMaterial.OpaqueData.Add("SpecularPower", 4.0f); } else if (material is EffectMaterialContent) { var effectMaterial = (EffectMaterialContent)material; } else { throw new Exception("unknown material"); } return base.ConvertMaterial(myMaterial, context); }
/// <summary> /// Override the ConvertMaterial method to apply our custom InstancedModel.fx shader. /// </summary> protected override MaterialContent ConvertMaterial(MaterialContent material, ContentProcessorContext context) { EffectMaterialContent newMaterial = new EffectMaterialContent(); newMaterial.Effect = new ExternalReference<EffectContent>("SKraftShader.fx", rootIdentity); BasicMaterialContent basicMaterial = material as BasicMaterialContent; if ((basicMaterial != null) && (basicMaterial.Texture != null)) { newMaterial.Textures.Add("Texture", basicMaterial.Texture); } return base.ConvertMaterial(newMaterial, context); }
protected override MaterialContent ConvertMaterial(MaterialContent material, ContentProcessorContext context) { var customMaterial = new EffectMaterialContent(); var effectPath = Path.GetFullPath(effectFilename); customMaterial.Effect = new ExternalReference<EffectContent>(effectPath); var parameters = new OpaqueDataDictionary(); parameters["ColorKeyColor"] = ColorKeyColor; parameters["ColorKeyEnabled"] = ColorKeyEnabled; parameters["TextureFormat"] = TextureFormat; parameters["GenerateMipmaps"] = GenerateMipmaps; parameters["ResizeTexturesToPowerOfTwo"] = ResizeTexturesToPowerOfTwo; return context.Convert<MaterialContent, MaterialContent>( customMaterial, typeof(MaterialProcessor).Name, parameters); }
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; }
protected override MaterialContent ConvertMaterial(MaterialContent material, ContentProcessorContext context) { BasicMaterialContent basicMaterialContent = material as BasicMaterialContent; bool texture = basicMaterialContent != null; if (texture) { EffectMaterialContent effectMaterialContent = new EffectMaterialContent(); string fullPath = Path.GetFullPath("SkinnedModel.fx"); effectMaterialContent.Effect = new ExternalReference<EffectContent>(fullPath); texture = basicMaterialContent.Texture == null; if (!texture) { effectMaterialContent.Textures.Add("Texture", basicMaterialContent.Texture); } MaterialContent materialContent = base.ConvertMaterial(effectMaterialContent, context); return materialContent; } else { throw new InvalidContentException(string.Format("SkinnedModelProcessor only supports BasicMaterialContent, but input mesh uses {0}.", material.GetType())); } }
public override MaterialContent Process(MaterialContent input, ContentProcessorContext context) { // Create a new material effect EffectMaterialContent customMaterial = new EffectMaterialContent(); // Access the input as a basic material BasicMaterialContent basicMaterial = (BasicMaterialContent)input; // If Texture is null, we are not using texture mapping. Otherwise, we are if (skinned) { string effectFile = Path.GetFullPath("SkinnedEffect.fx"); customMaterial.Effect = new ExternalReference<EffectContent>(effectFile); customMaterial.Textures.Add("Texture", basicMaterial.Texture); section = 1; } else if (basicMaterial.Texture == null) { // I don't know why, but sometimes you get an invalid material. So, // I just let the base processor handle it. if (basicMaterial.DiffuseColor == null) return base.Process(input, context); string effectFile = Path.GetFullPath("PhibesEffect1.fx"); customMaterial.Effect = new ExternalReference<EffectContent>(effectFile); customMaterial.OpaqueData.Add("DiffuseColor", basicMaterial.DiffuseColor); } else { string effectFile = Path.GetFullPath("PhibesEffect2.fx"); customMaterial.Effect = new ExternalReference<EffectContent>(effectFile); customMaterial.Textures.Add("Texture", basicMaterial.Texture); } customMaterial.OpaqueData.Add("Light1Location", LightInfo(section, 0)); customMaterial.OpaqueData.Add("Light1Color", LightInfo(section, 1)); customMaterial.OpaqueData.Add("Light2Location", LightInfo(section, 2)); customMaterial.OpaqueData.Add("Light2Color", LightInfo(section, 3)); customMaterial.OpaqueData.Add("Light3Location", LightInfo(section, 4)); customMaterial.OpaqueData.Add("Light3Color", LightInfo(section, 5)); // Chain to the base material processor. return base.Process(customMaterial, context); }
protected override MaterialContent ConvertMaterial(MaterialContent material, ContentProcessorContext context) { EffectMaterialContent lppMaterial = new EffectMaterialContent(); OpaqueDataDictionary processorParameters = new OpaqueDataDictionary(); processorParameters["ColorKeyColor"] = this.ColorKeyColor; processorParameters["ColorKeyEnabled"] = this.ColorKeyEnabled; processorParameters["TextureFormat"] = this.TextureFormat; processorParameters["GenerateMipmaps"] = this.GenerateMipmaps; processorParameters["ResizeTexturesToPowerOfTwo"] = this.ResizeTexturesToPowerOfTwo; processorParameters["PremultiplyTextureAlpha"] = false; processorParameters["ColorKeyEnabled"] = false; lppMaterial.Effect = new ExternalReference<EffectContent>("shaders/LPPMainEffect.fx"); lppMaterial.CompiledEffect = context.BuildAsset<EffectContent, CompiledEffectContent>(lppMaterial.Effect, "EffectProcessor"); //extract the extra parameters ExtractDefines(lppMaterial, material, context); // 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) { lppMaterial.Textures.Add(texture.Key, texture.Value); } try { lppMaterial.OpaqueData.Add("DiffuseColor", new Vector4((Vector3)material.OpaqueData["DiffuseColor"], (float)material.OpaqueData["Alpha"])); lppMaterial.OpaqueData.Add("SpecularColor", material.OpaqueData["SpecularColor"]); lppMaterial.OpaqueData.Add("SpecularPower", material.OpaqueData["SpecularPower"]); } catch (Exception ex) { Console.WriteLine(ex); } // 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); }
protected override MaterialContent ConvertMaterial(MaterialContent material, ContentProcessorContext context) { EffectMaterialContent normalMappingMaterial = new EffectMaterialContent(); normalMappingMaterial.Effect = new ExternalReference<EffectContent> ("shaders/NormalMapping.fx"); // 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); } return context.Convert<MaterialContent, MaterialContent> (normalMappingMaterial, typeof(MaterialProcessor).Name); }
/// <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>("InstancedModel.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); }
protected override MaterialContent ConvertMaterial(MaterialContent material, ContentProcessorContext context) { var basicMaterial = new EffectMaterialContent { Effect = new ExternalReference<EffectContent>("../HMEngineContent/Shaders/BasicShader.fx") }; var processorParameters = new OpaqueDataDictionary(); processorParameters["ColorKeyColor"] = ColorKeyColor; processorParameters["ColorKeyEnabled"] = ColorKeyEnabled; processorParameters["TextureFormat"] = TextureFormat; processorParameters["GenerateMipmaps"] = GenerateMipmaps; processorParameters["ResizeTexturesToPowerOfTwo"] = ResizeTexturesToPowerOfTwo; // Copy any textures already added to the built in material to our custom basicMaterial foreach (KeyValuePair<String, ExternalReference<TextureContent>> texture in material.Textures) { basicMaterial.Textures.Add(texture.Key, texture.Value); } // Convert the material using the HMMaterialProcessor. This will perform any special texture processing we need return context.Convert<MaterialContent, MaterialContent>(basicMaterial, typeof (HMMaterialProcessor).Name, processorParameters); }
/// <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("tankshader.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); } // Chain to the base material processor. return base.Process(customMaterial, context); }
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 }
/// <summary> /// 全てのマテリアルがスキンモデル用のエフェクトを使うように変更する /// </summary> protected override MaterialContent ConvertMaterial(MaterialContent material, ContentProcessorContext context) { BasicMaterialContent basicMaterial = material as BasicMaterialContent; if (basicMaterial == null) { throw new InvalidContentException(string.Format( "SkinnedModelProcessorはBasicMaterialContentのみをサポートします"+ "入力メッシュは{0}を使用しています。",material.GetType())); } EffectMaterialContent effectMaterial = new EffectMaterialContent(); // スキンメッシュエフェクトを参照する string effectPath = Path.GetFullPath(@"Effect\SkinnedModel.fx"); effectMaterial.Effect = new ExternalReference<EffectContent>(effectPath); bool useTexture = UseTexture; // BasicMaterialContentのテクスチャを新しいマテリアルに設定する if (basicMaterial.Texture != null) { effectMaterial.Textures.Add("Texture", basicMaterial.Texture); } else { useTexture = false; } // マテリアルパラメータをエフェクトに設定 if (basicMaterial.DiffuseColor != null) effectMaterial.OpaqueData.Add("DiffuseColor", basicMaterial.DiffuseColor); if (basicMaterial.EmissiveColor != null) effectMaterial.OpaqueData.Add("EmissiveColor", basicMaterial.EmissiveColor); if (basicMaterial.SpecularColor != null) effectMaterial.OpaqueData.Add("SpecularColor", basicMaterial.SpecularColor); if (basicMaterial.SpecularPower != null) effectMaterial.OpaqueData.Add("SpecularPower", basicMaterial.SpecularPower); if (UseMaterial && useTexture) { effectMaterial.OpaqueData.Add("TechniqueName", "MaterialTextureTechnique"); } else if (UseMaterial) { effectMaterial.OpaqueData.Add("TechniqueName", "MaterialTechnique"); } else if (useTexture) { effectMaterial.OpaqueData.Add("TechniqueName", "TextureTechnique"); } else { effectMaterial.OpaqueData.Add("TechniqueName", "BasicTechnique"); } // ModelProcessorのConvertMaterialを呼ぶ return base.ConvertMaterial(effectMaterial, context); }
protected override MaterialContent ConvertMaterial(MaterialContent material, ContentProcessorContext context) { EffectMaterialContent deferredShadingMaterial = new EffectMaterialContent(); deferredShadingMaterial.Effect = new ExternalReference<EffectContent>("../../GraphicsLibrary/GraphicsContent/Shaders/Deferred Rendering/RenderGBuffer.fx"); deferredShadingMaterial.CompiledEffect = context.BuildAsset<EffectContent, CompiledEffectContent>(deferredShadingMaterial.Effect, "EffectProcessor"); // 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.Contains("DiffuseMap") || texture.Key.Contains("Texture")) deferredShadingMaterial.Textures.Add(texture.Key, texture.Value); if (texture.Key.Contains("NormalMap")) deferredShadingMaterial.Textures.Add(texture.Key, texture.Value); if (texture.Key.Contains("SpecularMap")) deferredShadingMaterial.Textures.Add(texture.Key, texture.Value); if (texture.Key.Contains("EmissiveMap")) deferredShadingMaterial.Textures.Add(texture.Key, texture.Value); } //extract the extra parameters ExtractDefines(deferredShadingMaterial, material, context); // Return material return context.Convert<MaterialContent, MaterialContent>(deferredShadingMaterial, typeof(DeferredRendererMaterialProcessor).Name); }
/// <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="deferredMaterial"></param> /// <param name="material"></param> /// <param name="context"></param> private void ExtractDefines(EffectMaterialContent deferredMaterial, 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 (m_IsSkinned) { context.Logger.LogMessage("Skinned mesh found"); defines += "SKINNED_MESH;"; } if (!String.IsNullOrEmpty(defines)) deferredMaterial.OpaqueData.Add("Defines", defines); }
protected override MaterialContent ConvertMaterial(MaterialContent material, ContentProcessorContext context) { EffectMaterialContent Material = new EffectMaterialContent(); Material.Effect = new ExternalReference<EffectContent>(effect); foreach (KeyValuePair<String, ExternalReference<TextureContent>> texture in material.Textures) { if ((texture.Key == "Texture")) { Material.Textures.Add(diffuseMapKey, texture.Value); Material.Textures.Add(normalMapKey, new ExternalReference<TextureContent>(texture.Value.Filename.Substring(0, texture.Value.Filename.Length - 4) + "_N.jpg")); Material.Textures.Add(heightMapKey, new ExternalReference<TextureContent>(texture.Value.Filename.Substring(0, texture.Value.Filename.Length - 4) + "_H.jpg")); } } return context.Convert<MaterialContent, MaterialContent>(Material, typeof(MaterialProcessor).Name); }
/// <summary> /// Loads the specified effect into the material. /// </summary> protected override MaterialContent ConvertMaterial(MaterialContent material, ContentProcessorContext context) { EffectMaterialContent newMaterial = new EffectMaterialContent(); if (string.IsNullOrWhiteSpace(mEffectName)) { throw new ArgumentNullException("Effect asset undefined."); } newMaterial.Effect = new ExternalReference<EffectContent>(mEffectName); foreach (KeyValuePair<string, ExternalReference<TextureContent>> pair in material.Textures) { newMaterial.Textures.Add(pair.Key, pair.Value); } return context.Convert<MaterialContent, MaterialContent>(newMaterial, typeof(MaterialProcessor).Name); }
protected override MaterialContent ConvertMaterial(MaterialContent material, ContentProcessorContext context) { EffectMaterialContent deferredShadingMaterial = new EffectMaterialContent(); deferredShadingMaterial.Effect = new ExternalReference<EffectContent>("System/Effects/GBuffer.fx"); foreach (KeyValuePair<string, ExternalReference<TextureContent>> texture in material.Textures) { // MonoGame has a bug where texture names must be named after the texture sampler in the shader // // Example: // texture Texture; // sampler AlbedoSampler = sampler_state // { // texture = <Texture>; // MINFILTER = LINEAR; // MAGFILTER = LINEAR; // MIPFILTER = LINEAR; // ADDRESSU = WRAP; // ADDRESSV = WRAP; // }; if (texture.Key == "Texture") { deferredShadingMaterial.Textures.Add("Texture", texture.Value); } if (texture.Key == "NormalMap") { deferredShadingMaterial.Textures.Add("NormalMap", texture.Value); } if (texture.Key == "SpecularMap") { deferredShadingMaterial.Textures.Add("SpecularMap", texture.Value); } } return context.Convert<MaterialContent, MaterialContent>(deferredShadingMaterial, "MGMaterialProcessor"); }
/// <summary> /// プロセッサ処理 /// </summary> public override MaterialContent Process(MaterialContent input, ContentProcessorContext context) { MaterialContent finalinput; if (context.TargetPlatform == TargetPlatform.WindowsPhone) { finalinput = input; } else { BasicMaterialContent basicinput = input as BasicMaterialContent; if (basicinput == null) throw new InvalidContentException(string.Format( "MMDProcessorはEffectMaterialContentのみをサポートします" + "入力メッシュは{0}を使用しています。", input.GetType())); ExternalReference<EffectContent> effect; //リソースからファイルを作成して読み込むという超セコイ方法…… if (!Directory.Exists("ext")) Directory.CreateDirectory("ext"); FileStream fs; fs = new FileStream(Path.Combine("ext", "MMDAccessoryEffect.fx"), FileMode.Create); BinaryWriter bw = new BinaryWriter(fs); bw.Write(MMDXResource.AccessoryEffect); bw.Close(); effect = new ExternalReference<EffectContent>(Path.Combine("ext", "MMDAccessoryEffect.fx")); EffectMaterialContent effectcontent = new EffectMaterialContent(); effectcontent.Effect = effect; //パラメータコピー foreach (var data in basicinput.OpaqueData) { effectcontent.OpaqueData.Add(data.Key, data.Value); } //テクスチャのコピー if (basicinput.Textures.Count > 0) { foreach (var it in basicinput.Textures) { if (string.IsNullOrEmpty(it.Value.Filename)) continue; if (it.Value.Filename.IndexOf('*') != -1) { string[] files = it.Value.Filename.Split('*'); foreach(var file in files){ if (Path.GetExtension(file) == ".sph" || Path.GetExtension(file) == ".spa") { effectcontent.Textures.Add("Sphere", new ExternalReference<TextureContent>(CreateSpherePath(file))); } else { effectcontent.Textures.Add(it.Key, new ExternalReference<TextureContent>(file)); } } } else if (Path.GetExtension(it.Value.Filename) == ".sph" || Path.GetExtension(it.Value.Filename) == ".spa") { it.Value.Filename = CreateSpherePath(it.Value.Filename); effectcontent.Textures.Add("Sphere", it.Value); } else effectcontent.Textures.Add(it.Key, it.Value); } } //パラメータ設定 effectcontent.OpaqueData.Add("ShaderIndex", ShaderIndex); //データの渡し finalinput = effectcontent; } //事前アルファOff this.PremultiplyTextureAlpha = false; return base.Process(finalinput, context); }
/// <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; }
protected override MaterialContent ConvertMaterial(MaterialContent material, ContentProcessorContext context) { EffectMaterialContent normalMappingMaterial = new EffectMaterialContent(); string effectDirectory = Path.Combine(directory, "../../Effects/"); normalMappingMaterial.Effect = new ExternalReference<EffectContent> (Path.Combine(effectDirectory, "NormalMapping.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(NormalMappingMaterialProcessor).Name, processorParameters); }
//Convert the Material Content protected override MaterialContent ConvertMaterial(MaterialContent material, ContentProcessorContext context) { //Initialize Effect Material Content EffectMaterialContent deferredShadingMaterial = new EffectMaterialContent(); //Set Effect to the Effect Material Content deferredShadingMaterial.Effect = new ExternalReference<EffectContent>("Effects/GBuffer.fx"); //Set the Textures to the Effect 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 Converted Material return context.Convert<MaterialContent, MaterialContent>(deferredShadingMaterial, typeof(MaterialProcessor).Name); }
protected override MaterialContent ConvertMaterial(MaterialContent material, ContentProcessorContext context) { EffectMaterialContent deferredShadingMaterial = new EffectMaterialContent(); deferredShadingMaterial.Effect = new ExternalReference<EffectContent>("System/Effects/GBuffer.fx"); 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); }
protected override MaterialContent ConvertMaterial(MaterialContent material, ContentProcessorContext context) { EffectMaterialContent myMaterial = new EffectMaterialContent(); // material.Name = "gownooooooooo"; material.OpaqueData.Add("duupsko",15); Log(context,"KEYSY: "+material.OpaqueData.Keys.ToString()); if (material is EffectMaterialContent) { EffectMaterialContent effectMaterialContent = (EffectMaterialContent)material; Log(context, "Material is EffectMaterial! Using shader"); Log(context, effectMaterialContent.Effect.Filename.ToString()); // 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]); Log(context, "Set texture ‘{0}’ = {1}", textureKey, textureContent.Filename); } else { Log(context, "Failed! ‘{0}’ = {1}", textureKey, textureContent.Filename); } } MaterialContent cm = base.ConvertMaterial(myMaterial, context); cm.OpaqueData.Add("ble",""); return cm; } else if (material is BasicMaterialContent) { // create a BasicMaterialContent and use that to convert instead BasicMaterialContent basicMaterial = (BasicMaterialContent)material; Log(context, basicMaterial.OpaqueData.ToString() + "Licznosc:" + basicMaterial.OpaqueData.Count.ToString() + " nazwa materialu " + basicMaterial.Name); foreach (KeyValuePair<string, object> data in basicMaterial.OpaqueData) { Log(context,"DUPSKO: "+data.Key.ToString()+" __ " ); } // Log(context,basicMaterial.); // You can set textures for the effect to use if (basicMaterial.Textures.Count > 0) { Log(context, "Basic Material has a texture: {0}, name: {1}", basicMaterial.Name, basicMaterial.Texture.Name); myMaterial.Textures.Add("DiffuseTexture", basicMaterial.Texture); } else { Log(context, "No textures on {0}", basicMaterial.Name); } basicMaterial.OpaqueData.Add("dupsko",15); MaterialContent cm = base.ConvertMaterial(basicMaterial, context); return cm; } else throw new Exception("huh? this is very odd"); }
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); }