[SOLVED] How to rebuild a custom version of BasicEffect in Pipeline tool

Hello,

I have been stuck for multiple hours trying to rebuild a slightly custom version of BasicEffect.

I’m stuck on step#1, trying to rebuild the original unmodified BasicEffect.fx.

However when I try to compile this in the pipeline tool, I get an error “The effect must contain at least one technique and pass!”. I have another shader in the pipeline tool that compiles correctly, and the difference appears to be the technique declaration section. It seems the BasicEffect.fx does not use a traditional declaration syntax for the techniques/passes.

Also, as far as I understand, the old indexed technique from xna is not compatible in monogame (I couldn’t build the original XNA BasicEffect either)

Monogame BasicEffect.fx technique sections

    TECHNIQUE( BasicEffect,								VSBasic,			PSBasic );     
    TECHNIQUE( BasicEffect_NoFog,						VSBasicNoFog,		PSBasicNoFog );   
    TECHNIQUE( BasicEffect_VertexColor,					VSBasicVc,			PSBasic );   
    TECHNIQUE( BasicEffect_VertexColor_NoFog,			VSBasicVcNoFog,		PSBasicNoFog );
    TECHNIQUE( BasicEffect_Texture,						VSBasicTx,			PSBasicTx );
    TECHNIQUE( BasicEffect_Texture_NoFog,				VSBasicTxNoFog,		PSBasicTxNoFog );
    TECHNIQUE( BasicEffect_Texture_VertexColor,			VSBasicTxVc,		PSBasicTx );
    TECHNIQUE( BasicEffect_Texture_VertexColor_NoFog,	VSBasicTxVcNoFog,	PSBasicTxNoFog );
      
    TECHNIQUE( BasicEffect_VertexLighting,								VSBasicVertexLighting,		PSBasicVertexLighting );
    TECHNIQUE( BasicEffect_VertexLighting_NoFog,						VSBasicVertexLighting,		PSBasicVertexLightingNoFog );
    TECHNIQUE( BasicEffect_VertexLighting_VertexColor,					VSBasicVertexLightingVc,	PSBasicVertexLighting );
    TECHNIQUE( BasicEffect_VertexLighting_VertexColor_NoFog,			VSBasicVertexLightingVc,	PSBasicVertexLightingNoFog );
    TECHNIQUE( BasicEffect_VertexLighting_Texture,						VSBasicVertexLightingTx,	PSBasicVertexLightingTx );
    TECHNIQUE( BasicEffect_VertexLighting_Texture_NoFog,				VSBasicVertexLightingTx,	PSBasicVertexLightingTxNoFog );
    TECHNIQUE( BasicEffect_VertexLighting_Texture_VertexColor,			VSBasicVertexLightingTxVc,	PSBasicVertexLightingTx );
    TECHNIQUE( BasicEffect_VertexLighting_Texture_VertexColor_NoFog,	VSBasicVertexLightingTxVc,	PSBasicVertexLightingTxNoFog );
      

    TECHNIQUE( BasicEffect_OneLight,							VSBasicOneLight,		PSBasicVertexLighting );
    TECHNIQUE( BasicEffect_OneLight_NoFog,						VSBasicOneLight,		PSBasicVertexLightingNoFog );
    TECHNIQUE( BasicEffect_OneLight_VertexColor,				VSBasicOneLightVc,		PSBasicVertexLighting );
    TECHNIQUE( BasicEffect_OneLight_VertexColor_NoFog,			VSBasicOneLightVc,		PSBasicVertexLightingNoFog );
    TECHNIQUE( BasicEffect_OneLight_Texture,					VSBasicOneLightTx,		PSBasicVertexLightingTx );
    TECHNIQUE( BasicEffect_OneLight_Texture_NoFog,				VSBasicOneLightTx,		PSBasicVertexLightingTxNoFog );
    TECHNIQUE( BasicEffect_OneLight_Texture_VertexColor,		VSBasicOneLightTxVc,	PSBasicVertexLightingTx );
    TECHNIQUE( BasicEffect_OneLight_Texture_VertexColor_NoFog,	VSBasicOneLightTxVc,	PSBasicVertexLightingTxNoFog );
      

    TECHNIQUE( BasicEffect_PixelLighting,							VSBasicPixelLighting,		PSBasicPixelLighting );
    TECHNIQUE( BasicEffect_PixelLighting_NoFog,						VSBasicPixelLighting,		PSBasicPixelLighting );
    TECHNIQUE( BasicEffect_PixelLighting_VertexColor,				VSBasicPixelLightingVc,		PSBasicPixelLighting );
    TECHNIQUE( BasicEffect_PixelLighting_VertexColor_NoFog,			VSBasicPixelLightingVc,		PSBasicPixelLighting );
    TECHNIQUE( BasicEffect_PixelLighting_Texture,					VSBasicPixelLightingTx,		PSBasicPixelLightingTx );
    TECHNIQUE( BasicEffect_PixelLighting_Texture_NoFog,				VSBasicPixelLightingTx,		PSBasicPixelLightingTx );
    TECHNIQUE( BasicEffect_PixelLighting_Texture_VertexColor,		VSBasicPixelLightingTxVc,	PSBasicPixelLightingTx );
    TECHNIQUE( BasicEffect_PixelLighting_Texture_VertexColor_NoFog,	VSBasicPixelLightingTxVc,	PSBasicPixelLightingTx );

XNA BasicEffect.dx technique sections

    VertexShader VSArray[20] =
    {
        compile vs_2_0 VSBasic(),
        compile vs_2_0 VSBasicNoFog(),
        compile vs_2_0 VSBasicVc(),
        compile vs_2_0 VSBasicVcNoFog(),
        compile vs_2_0 VSBasicTx(),
        compile vs_2_0 VSBasicTxNoFog(),
        compile vs_2_0 VSBasicTxVc(),
        compile vs_2_0 VSBasicTxVcNoFog(),
        
        compile vs_2_0 VSBasicVertexLighting(),
        compile vs_2_0 VSBasicVertexLightingVc(),
        compile vs_2_0 VSBasicVertexLightingTx(),
        compile vs_2_0 VSBasicVertexLightingTxVc(),
        
        compile vs_2_0 VSBasicOneLight(),
        compile vs_2_0 VSBasicOneLightVc(),
        compile vs_2_0 VSBasicOneLightTx(),
        compile vs_2_0 VSBasicOneLightTxVc(),
        
        compile vs_2_0 VSBasicPixelLighting(),
        compile vs_2_0 VSBasicPixelLightingVc(),
        compile vs_2_0 VSBasicPixelLightingTx(),
        compile vs_2_0 VSBasicPixelLightingTxVc(),
    };


    int VSIndices[32] =
    {
        0,      // basic
        1,      // no fog
        2,      // vertex color
        3,      // vertex color, no fog
        4,      // texture
        5,      // texture, no fog
        6,      // texture + vertex color
        7,      // texture + vertex color, no fog
        
        8,      // vertex lighting
        8,      // vertex lighting, no fog
        9,      // vertex lighting + vertex color
        9,      // vertex lighting + vertex color, no fog
        10,     // vertex lighting + texture
        10,     // vertex lighting + texture, no fog
        11,     // vertex lighting + texture + vertex color
        11,     // vertex lighting + texture + vertex color, no fog
        
        12,     // one light
        12,     // one light, no fog
        13,     // one light + vertex color
        13,     // one light + vertex color, no fog
        14,     // one light + texture
        14,     // one light + texture, no fog
        15,     // one light + texture + vertex color
        15,     // one light + texture + vertex color, no fog
        
        16,     // pixel lighting
        16,     // pixel lighting, no fog
        17,     // pixel lighting + vertex color
        17,     // pixel lighting + vertex color, no fog
        18,     // pixel lighting + texture
        18,     // pixel lighting + texture, no fog
        19,     // pixel lighting + texture + vertex color
        19,     // pixel lighting + texture + vertex color, no fog
    };


    PixelShader PSArray[10] =
    {
        compile ps_2_0 PSBasic(),
        compile ps_2_0 PSBasicNoFog(),
        compile ps_2_0 PSBasicTx(),
        compile ps_2_0 PSBasicTxNoFog(),

        compile ps_2_0 PSBasicVertexLighting(),
        compile ps_2_0 PSBasicVertexLightingNoFog(),
        compile ps_2_0 PSBasicVertexLightingTx(),
        compile ps_2_0 PSBasicVertexLightingTxNoFog(),

        compile ps_2_0 PSBasicPixelLighting(),
        compile ps_2_0 PSBasicPixelLightingTx(),
    };


    int PSIndices[32] =
    {
        0,      // basic
        1,      // no fog
        0,      // vertex color
        1,      // vertex color, no fog
        2,      // texture
        3,      // texture, no fog
        2,      // texture + vertex color
        3,      // texture + vertex color, no fog
        
        4,      // vertex lighting
        5,      // vertex lighting, no fog
        4,      // vertex lighting + vertex color
        5,      // vertex lighting + vertex color, no fog
        6,      // vertex lighting + texture
        7,      // vertex lighting + texture, no fog
        6,      // vertex lighting + texture + vertex color
        7,      // vertex lighting + texture + vertex color, no fog
        
        4,      // one light
        5,      // one light, no fog
        4,      // one light + vertex color
        5,      // one light + vertex color, no fog
        6,      // one light + texture
        7,      // one light + texture, no fog
        6,      // one light + texture + vertex color
        7,      // one light + texture + vertex color, no fog
        
        8,      // pixel lighting
        8,      // pixel lighting, no fog
        8,      // pixel lighting + vertex color
        8,      // pixel lighting + vertex color, no fog
        9,      // pixel lighting + texture
        9,      // pixel lighting + texture, no fog
        9,      // pixel lighting + texture + vertex color
        9,      // pixel lighting + texture + vertex color, no fog
    };


    int ShaderIndex = 0;


    Technique BasicEffect
    {
        Pass
        {
            VertexShader = (VSArray[VSIndices[ShaderIndex]]);
            PixelShader  = (PSArray[PSIndices[ShaderIndex]]);
        }
    }

Sample shader that builds properly in pipeline tool

technique PointSprites
{
    pass Pass0
    {   
        VertexShader = compile VS_SHADERMODEL PointSpritesVS();
        PixelShader = compile PS_SHADERMODEL PointSpritesPS();
    }
}

Well, I tried some stuff but then I gave up when I noticed I only needed 2 of the 32 possible techniques in BasicEffect. So I made 2 separate effects, each supporting one of the 2 techniques I needed.

Moreso, I was not sure how I would port the CustomBasicEffect.cs because in XNA i was calling the constructor on it while the monogame version I think I would have to use contentManager.Load(“CustomBasicEffect”).

Then I took all my XNA code from CustomBasicEffect.cs and ported it into CustomBasicEffectWrapper.cs that modifies the loaded Effect instead of being a descendant of Effect itself.

Loads of code bug but in the end it worked :slight_smile: