Project Description

Effect Custom Tool for Visual Studio is a visual studio extension that helps you generate c# classes from effect (*.fx) files for use with Xna projects.

This project is inspired by Xna Effect Generator made by SnprBoB86, which was for Xna 1.0 and was not updated for quite a long while.

Screenshot

Features
  • Generate .cs file from .fx file right inside Visual Studio.
  • Generate classes that extends Microsoft.Xna.Framework.Graphics.Effect, automatically generate c# properties that access effect variables.
  • Use your custom effect just like Microsoft.Xna.Framework.Graphics.BasicEffect, no more string garbages.
  • Compiled effect embed into the assembly, no more coping the *.xnb around.
  • PascalCasing variables produce public properties, while camelCasing variables are internal.
  • Generate property documentation from .fx "SasUiDescription" annotation.
  • Generated classes are partial, so you can easily extending the functionality.
  • Support Xna 4.0.

Change Log

v1.2
  • Added support for Xna 4.0.
  • Added support for Visual Studio 2010, Visual C# Express 2010, Visual Studio Express 2010 for Windows Phone.
  • Fixed renaming issues in previous versions.

An Example

Given your MyEffect.fx

texture Texture;
float4x4 World;
float alpha <string SasUiDescription =  "Gets or sets the transparency.";> = 1.0;

float4 PixelShader(float2 texCoord : TEXCOORD0) : COLOR0
{
    return float4(0, 0, 0, 0);
}

technique Default
{
    pass Pass1
    {
        PixelShader = compile ps_2_0 PixelShader();
    }
}


We will generate two files, MyEffect.cs

// -----------------------------------------------------------------------------
// Changes to this file will not be modified by the code generator.
// -----------------------------------------------------------------------------
namespace YourNamespace
{
    using Microsoft.Xna.Framework;
    using Microsoft.Xna.Framework.Graphics;
        
    public partial class MyEffect
    {        
        public MyEffect(GraphicsDevice graphicsDevice) : 
                this(graphicsDevice)
        {
            InitializeComponent();
        }    }
}


And MyEffect.Designer.cs (The following code is just an outline of the generated file)

namespace YourNameSpace {

    using Microsoft.Xna.Framework;
    using Microsoft.Xna.Framework.Graphics;    
    
    partial class MyEffect : Microsoft.Xna.Framework.Graphics.Effect {       

        public Microsoft.Xna.Framework.Graphics.Texture2D Texture { get; set; }        
        public Microsoft.Xna.Framework.Matrix World { get; set; }     
        
        /// <summary>
        /// Gets or sets the transparency.
        /// </summary>
        internal float Alpha { get; set; }     
    }
}



How To Use
  • Download and install EffectCustomTool installer.
  • Restart Visual Studio, open or create your Xna game project.
  • Add an Effect (.fx) file to your Xna project, NOT content project.
Screenshot
  • Right click on the .fx file, select Properties.
  • Set Custom Tool to EffectCustomTool.
  • Set Build Action to "None".
Screenshot
  • Right click on the .fx file, select Run Custom Tool.
Screenshot
  • If your effect file is correct and are supported by our tool, a .Designer.cs file will be created under .fx file.
Screenshot

Last edited Aug 12, 2010 at 2:20 PM by Nightin, version 35