XNA Deferred Shading, Replace BasicEffect

Posted by Alex on Game Development See other posts from Game Development or by Alex
Published on 2012-11-06T22:34:14Z Indexed on 2012/11/06 23:20 UTC
Read the original article Hit count: 430

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);
       }
    }

© Game Development or respective owner

Related posts about XNA

Related posts about c#