• Advertisement
Sign in to follow this  

transformation of fixed function pipeline into states in effect file

This topic is 781 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi

If someone is familair with effect file and states could You look and check if below transformation of states from fixed function pipeline is OK? I would be grateful.

 

Original code:

void Goalnet::draw()
{
    //culling mode turn off
    d3d::pDev->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);   
    //alfa test - skip drawing pixel which alpha is 0
    d3d::pDev->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE);
    d3d::pDev->SetRenderState(D3DRS_ALPHAREF, 1);
    d3d::pDev->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL);

    //alfa blending
    d3d::pDev->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
    d3d::pDev->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
    d3d::pDev->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
    d3d::pDev->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
    d3d::pDev->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
    d3d::pDev->SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
    d3d::pDev->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);

    mNet.drawMesh(mMatOrientation); //here I know how to transform into shader, I only have problem with states in pass

    //Restore
    d3d::pDev->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);
    d3d::pDev->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
    d3d::pDev->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);
}

effect file:

...
technique Medium
{
    pass P0
    {
        vertexShader = compile vs_2_0 BlendMediumVS();
        pixelShader  = compile ps_2_0 BlendMediumPS();


         CullMode = None;
        AlphaRef = 1;
        AlphaFunc = GreaterEqual;
        AlphaTestEnable = true;


       AlphaBlendEnable = true;
       SrcBlend = SrcAlpha;
       DestBlend = InvSrcAplha;
       BlendOp = Add;


       ColorOp[0] = SelectArg1;
       ColorArg1[0] = Texture;
       AlphaOp[0] = SelectArg1;
       AlphaArg1[0] = Texture;


        AlphaOp[1] = Disable;
        ColorOp[1] = Disable;
    }
}

After drawing should I still keep in the code:

   //Restore
    d3d::pDev->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);
    d3d::pDev->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
    d3d::pDev->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);

in order to restore states for fixed function pipeline needs? Or I don't have to restore settings because they back by default to CCW and alphablendable=false, alphatestenable=false? So in general if I for example change cullmode to NONE in shader "A" is this none value still kept in graphic card after effect endpass/end or this value back to previous one before effect file was started?

Edited by anders211

Share this post


Link to post
Share on other sites
Advertisement

What I do is using middleman functions to set such things (states, textures, shaders), which allows me to keep a reference of last state and skip if it's set to what it already is :)

I don't know wether D3D9 effects uses such methods or always sets whatever you tell it to, and what happens after effect call..

Share this post


Link to post
Share on other sites

OK, thanks, this is a good approach for fixed function pipeline.

As far as effect files are concerned and definition of states in pass body, after finishing work with effect file device states back to values used before, so no need to restore. I did some tests and this is a result.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement