3
\$\begingroup\$

I have implemented deferred shading in my XNA 4.0 project, meaning that I need all objects to start out with the same shader "RenderGBuffer.fx". How can I use a custom Content Processor to:

  1. Not load any textures by default (I want to manually do this)
  2. Use "RenderGBuffer.fx" as the default shader instead of BasicEffect

Below is the progress so far

   public class DeferredModelProcessor : ModelProcessor
    {
       EffectMaterialContent deferredShader;

       public DeferredModelProcessor()
       {

       }

       protected override MaterialContent ConvertMaterial(MaterialContent material, ContentProcessorContext context)
       {
           deferredShader = new EffectMaterialContent();
           deferredShader.Effect = new ExternalReference<EffectContent>("DeferredShading/RenderGBuffer.fx");         

           return context.Convert<MaterialContent, MaterialContent>(deferredShader, typeof(MaterialProcessor).Name);
       }
    }
\$\endgroup\$
1
\$\begingroup\$

After a day of a lot research, this is how you do it:

using Microsoft.Xna.Framework.Content.Pipeline;
using Microsoft.Xna.Framework.Content.Pipeline.Graphics;
using Microsoft.Xna.Framework.Content.Pipeline.Processors;

namespace Deferred_Pipeline
{
    [ContentProcessor(DisplayName = "Deferred Model - Archon")]
    public class DeferredModelProcessor : ModelProcessor
    {
        public DeferredModelProcessor()
        {

        }

        protected override MaterialContent ConvertMaterial(MaterialContent material, ContentProcessorContext context)
        {
            EffectMaterialContent deferredShader = new EffectMaterialContent();
            deferredShader.Effect = new ExternalReference<EffectContent>("../ArchonContent/DeferredShading/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;

            return context.Convert<MaterialContent, MaterialContent>(deferredShader, typeof(MaterialProcessor).Name, processorParameters);
        }
    }
}
| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.