• 9
• 11
• 9
• 20
• 12

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.

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
{

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

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

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 on other sites

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 on other sites
You could introduce a state manager, something like this:
http://www.gamedev.net/topic/647102-state-manager-code-review-suggestions/

Regarding storing and resetting of states, I believe in your Begin() call you can set if you want states to be restored when your cycle is done.