Effect States (Direct3D 9)

Effect states are used to initialize pipeline states in preparation for vertex and pixel processing.



effect state [ [index] ] = expression;


Where:

  • effect state - Similar to the traditional fixed function pipeline states. A complete list of states is provided below.
  • [ [index] ] - Optional integer index. The index identifies a particular state within an array of effect states. The outer brackets indicate that an index is optional. If an index is used, be sure to use the inner brackets.
  • expression - State assignment expression. See Expressions (Direct3D 9).

Each state has a native data type. This is the data type that the state expects values to be in when the effect assigns them. The data types that each state expects are listed below.

Note that the effect interface will attempt to cast values to the appropriate type as early as possible. Literal values can be cast at compile time. Non-literals (i.e. regular variables) need to be cast when the appropriate Set methods are called. For example, the effect interface will cast values set using SetBool, SetValue, and other similar functions if necessary. For better performance ensure that the values passed to the effect interface are already the correct type and will not need casting. If the runtime is unable to cast a value, an error is returned.

Effect states can be broken up into the following categories:

Light States

To enable the best performance for applying an effect, all components of a light or a material should be specified in the effect file. States that you fail to declare are set to some default value because there is no way for Direct3D to set light states individually.

Light StateTypeValues
LightAmbient[n]float4See the Ambient member of D3DLIGHT9.
LightAttenuation0[n]floatSee the Attenuation0 member of D3DLIGHT9.
LightAttenuation1[n]floatSee the Attenuation1 member of D3DLIGHT9.
LightAttenuation2[n]floatSee the Attenuation2 member of D3DLIGHT9.
LightDiffuse[n]float4See the Diffuse member of D3DLIGHT9.
LightDirection[n]float3See the Direction member of D3DLIGHT9.
LightEnable[n]boolTRUE or FALSE. See the bEnable argument in LightEnable.
LightFalloff[n]float D3DCOLORVALUE. See the Falloff member of D3DLIGHT9.
LightPhi[n]floatSee the Phi member of D3DLIGHT9.
LightPosition[n]float3See the Position member of D3DLIGHT9.
LightRange[n]floatSee the Range member of D3DLIGHT9.
LightSpecular[n]float4See the Specular member of D3DLIGHT9.
LightTheta[n]floatSee the Theta member of D3DLIGHT9.
LightType[n]dwordSame value as the array of up to n D3DLIGHTTYPE values without the D3DLIGHT_ prefix.

 

Example:



LightEnable[0] = TRUE;
LightType[0] = POINT;
LightPosition[0] = float3<10.0f, 1.0f, 23.0f>;
LightAmbient[0] = float4<0.7f, 0.0f, 0.0f, 1.0f>;


This will enable lighting, make point lighting the type, set the light position to float3<10.0f, 1.0f, 23.0f>, and set the ambient color to float4<0.7f, 0.0f, 0.0f, 1.0f>.

Material States

States that you fail to declare are set to some default value because there is no way for Direct3D to set material states individually.

Material StateTypeValues
MaterialAmbientfloat4Same value as Ambient
MaterialDiffusefloat4Same value as Diffuse
MaterialEmissivefloat4Same value as Emissive
MaterialPowerfloatSame value as Power
MaterialSpecularfloat4Same value as Specular

 

Example:



MaterialDiffuse = float4<0.7f, 0.0f, 0.0f, 1.0f>;
MaterialPower = 3.0f;


This will set the diffuse color to float4<0.7f, 0.0f, 0.0f, 1.0f> and make the power of the material 3.0f.

Render States

There are two types of render states:

Pixel Pipe Render States

Effect file render states have names similar to the fixed function pipeline states, often with the prefix removed.

Render StateTypeValues
AlphaBlendEnableboolTrue or False. Same values as D3DRS_ALPHABLENDENABLE in D3DRENDERSTATETYPE.
AlphaFuncdwordSame values as D3DCMPFUNC without the D3DCMP_ prefix. See D3DRS_ALPHAFUNC.
AlphaRefdwordSame values as D3DRS_ALPHAREF.
AlphaTestEnabledwordTrue or False. See D3DRS_ALPHATESTENABLE.
BlendOpdwordSame values as D3DBLENDOP without the D3DBLENDOP_ prefix.
ColorWriteEnabledwordBitwise combination of RED|GREEN|BLUE|ALPHA. See D3DRS_COLORWRITEENABLE.
DepthBiasfloatSame values as D3DRS_DEPTHBIAS.
DestBlenddwordSame values as D3DBLEND without the D3DBLEND_ prefix.
DitherEnableboolTrue or False. Same values as D3DRS_DITHERENABLE.
FillModedwordSame values as D3DFILLMODE without the D3DFILL_ prefix.
LastPixeldwordTrue or False. See D3DRS_LASTPIXEL.
ShadeModedwordSame values as D3DSHADEMODE without the D3DSHADE_ prefix.
SlopeScaleDepthBiasfloatSame values as D3DRS_SLOPESCALEDEPTHBIAS.
SrcBlenddwordSame values as D3DBLEND without the D3DBLEND_ prefix.
StencilEnableboolTrue or False. Same values as D3DRS_STENCILENABLE.
StencilFaildwordSame values as D3DSTENCILCAPS without the D3DSTENCILCAP_ prefix. See D3DRS_STENCILFAIL.
StencilFuncdwordSame values as D3DCMPFUNC without the D3DCMP_ prefix. See D3DRS_STENCILFUNC.
StencilMaskdwordSame values as D3DRS_STENCILMASK.
StencilPassdwordSame values as D3DSTENCILCAPS without the D3DSTENCILCAP_ prefix. See D3DRS_STENCILPASS.
StencilRefintSame values as D3DRS_STENCILREF.
StencilWriteMaskdwordSame values as D3DRS_STENCILWRITEMASK.
StencilZFaildwordSame values as D3DSTENCILCAPS without the D3DSTENCILCAP_ prefix. See D3DRS_STENCILZFAIL.
TextureFactordwordSame values as D3DCOLOR. Same values as D3DRS_TEXTUREFACTOR.
Wrap0 - Wrap15dword Values are the same as the values used by D3DRS_WRAP0. Valid values are:
  • COORD0 (which corresponds to D3DWRAPCOORD_0)
  • COORD1 (which corresponds to D3DWRAPCOORD_1)
  • COORD2 (which corresponds to D3DWRAPCOORD_2)
  • COORD3 (which corresponds to D3DWRAPCOORD_3)
  • U (which corresponds to D3DWRAP_U)
  • V (which corresponds to D3DWRAP_V)
  • W (which corresponds to D3DWRAP_W)
ZEnabledwordSame values as D3DZBUFFERTYPE without the D3DZB_ prefix.
ZFuncdwordSame values as D3DCMPFUNC without the D3DCMP_ prefix. See D3DRS_ZFUNC.
ZWriteEnableboolTrue or False. See D3DRS_ZWRITEENABLE.

 

Example:



AlphaBlendEnable = TRUE;
FillMode = WIREFRAME;


This will enable alpha blending and make all geometries render in wireframe.

Vertex Pipe Render States

Effect file render states have names similar to the fixed function pipeline states, often with the prefix removed.

Render StateTypeValues
Ambientfloat4Same values as D3DRS_AMBIENT.
AmbientMaterialSourcedwordSame values as D3DMATERIALCOLORSOURCE without the D3DMCS_ prefix. See D3DRS_AMBIENTMATERIALSOURCE.
ClippingboolTrue or False. Same values as D3DRS_CLIPPING.
ClipPlaneEnabledwordBitwise combination of D3DCLIPPLANE0 - D3DCLIPPLANE5 macros. See D3DCLIPPLANEn and D3DRS_CLIPPLANEENABLE.
ColorVertexboolTrue or False. Same values as D3DRS_COLORVERTEX.
CullModedwordSame values as D3DCULL without the D3DCULL_ prefix.
DiffuseMaterialSourcedwordSame values as D3DMATERIALCOLORSOURCE without the D3DMCS_ prefix. See D3DRS_DIFFUSEMATERIALSOURCE.
EmissiveMaterialSourcedwordSame values as D3DMATERIALCOLORSOURCE without the D3DMCS_ prefix. See D3DRS_EMISSIVEMATERIALSOURCE.
FogColordwordSame values as D3DCOLOR. See D3DRS_FOGCOLOR.
FogDensityfloatSame values as D3DRS_FOGDENSITY.
FogEnableboolTrue or False. Same values as D3DRS_FOGENABLE.
FogEndfloatSame values as D3DRS_FOGEND.
FogStartfloatSame values as D3DRS_FOGSTART.
FogTableModedwordSame values as D3DFOGMODE. See D3DRS_FOGTABLEMODE in D3DRENDERSTATETYPE.
FogVertexModedwordSame values as D3DFOGMODE without the D3DFOG_ prefix.
IndexedVertexBlendEnableboolTrue or False. Same values as D3DRS_INDEXEDVERTEXBLENDENABLE.
LightingboolTrue or False. Same values as D3DRS_LIGHTING.
LocalViewerboolTrue or False. Same values as D3DRS_LOCALVIEWER.
MultiSampleAntialiasboolSame values as D3DRS_MULTISAMPLEANTIALIAS.
MultiSampleMaskdwordSame values as D3DRS_MULTISAMPLEMASK.
NormalizeNormalsboolTrue or False. Same values as D3DRS_NORMALIZENORMALS.
PatchSegmentsfloat Same values as nSegments in SetNPatchMode.
PointScale_AfloatSame values as D3DRS_POINTSCALE_A.
PointScale_BfloatSame values as D3DRS_POINTSCALE_B.
PointScale_CfloatSame values as D3DRS_POINTSCALE_C.
PointScaleEnableboolSame values as D3DRS_POINTSCALEENABLE.
PointSizefloatSame values as D3DRS_POINTSIZE.
PointSize_MinfloatSame values as D3DRS_POINTSIZE_MIN.
PointSize_MaxfloatSame values as D3DRS_POINTSIZE_MAX without the D3DRS_ prefix.
PointSpriteEnableboolTrue or False. Same values as D3DRS_POINTSPRITEENABLE.
RangeFogEnableboolTrue or False. Same values as D3DRS_RANGEFOGENABLE.
SpecularEnableboolTrue or False. Same values as D3DRS_SPECULARENABLE.
SpecularMaterialSourcedwordSame values as D3DMATERIALCOLORSOURCE without the D3DMCS_ prefix. See D3DRS_SPECULARMATERIALSOURCE.
TweenFactorfloatSame values as D3DRS_TWEENFACTOR.
VertexBlenddwordSame values as D3DVERTEXBLENDFLAGS without the D3DVBF_ prefix. See D3DRS_VERTEXBLEND.

 

Example:



Ambient = float4<0.7f, 0.0f, 0.0f, 1.0f>;
CullMode = CCW;
FogColor = 0xff0000;


This will make the ambient color float4<0.7f, 0.0f, 0.0f, 1.0f>, set the backface culling mode to counter-clockwise, and set the fog color to red.

Sampler States

A sampler state represents a sampler object.

StateTypeValues
SamplersamplerNULL, or a sampler state block.

 

Sampler Stage States

Sampler stage states are used to sample textures. Sampler state determines filtering types and texture addressing modes.

Sampler StateTypeValues
AddressU[16]dwordSame values as D3DTEXTUREADDRESS without the D3DTADDRESS_ prefix. See D3DSAMP_ADDRESSU.
AddressV[16]dwordSame values as D3DTEXTUREADDRESS without the D3DTADDRESS_ prefix. See D3DSAMP_ADDRESSV.
AddressW[16]dwordSame values as D3DTEXTUREADDRESS without the D3DTADDRESS_ prefix. See D3DSAMP_ADDRESSW.
BorderColor[16] D3DCOLOR Same values as D3DTEXTUREFILTERTYPE without the D3DTEXF_ prefix. See D3DSAMP_BORDERCOLOR.
MagFilter[16]dwordSame values as D3DTEXTUREFILTERTYPE without the D3DTEXF_ prefix. See D3DSAMP_MAGFILTER.
MaxAnisotropy[16]dwordSame values as D3DSAMP_MAXANISOTROPY without the D3DSAMP_ prefix.
MaxMipLevel[16]intSame values as D3DSAMP_MAXMIPLEVEL without the D3DSAMP_ prefix.
MinFilter[16]dwordSame values as D3DSAMP_MINFILTER without the D3DSAMP_ prefix.
MipFilter[16]dwordSame values as D3DSAMP_MIPFILTER without the D3DSAMP_ prefix.
MipMapLodBias[16]floatSame values as D3DSAMP_MIPMAPLODBIAS without the D3DSAMP_ prefix.
SRGBTexturefloatSame value as D3DSAMP_SRGBTEXTURE without the D3DSAMP_ prefix.

 

Example:



AddressU[0] = CLAMP;
AddressV[0] = CLAMP;
AddressW[0] = CLAMP;


This clamps UVW values to be in between 0 and 1.

Shader States

There are only two effect shader states: one associated with a vertex shader object and the other associated with a pixel shader object.

Shader StateTypeValues
PixelShaderpixelshaderNULL, an assembly block, a compile target, or a pixel shader parameter.
VertexShadervertexshaderNULL, an assembly block, a compile target, or a pixel shader parameter.

 

Example:



VertexShader = compile vs_1_1 VSTexture();
PixelShader  = NULL;


This will compile VSTexture, a vertex shader defined earlier in the .fx file, to the vertex shader version 1.1, and then set that compiled shader as the vertex shader. The pixel shader is assigned to NULL.

Shader Constant States

Shader constant states are used to access shader constant parameters.

Shader Constant StateTypeValues
PixelShaderConstantfloat[m[n]]m x n array of floats; m and n are optional.
PixelShaderConstant1float4One 4D float.
PixelShaderConstant2float4x2Two 4D floats.
PixelShaderConstant3float4x3Three 4D floats.
PixelShaderConstant4float4x4Four 4D floats.
PixelShaderConstantBbool[m[n]]m x n array of bools; m and n are optional.
PixelShaderConstantIint[m[n]]m x n array of ints. m and n are optional.
PixelShaderConstantFfloat[m[n]]m x n array of floats. m and n are optional.
VertexShaderConstantfloat[m[n]]m x n array of floats. m and n are optional.
VertexShaderConstant1float4One 4D float.
VertexShaderConstant2float4x2Two 4D floats.
VertexShaderConstant3float4x3Three 4D floats.
VertexShaderConstant4float4x4Four 4D floats.
VertexShaderConstantBbool[m[n]]m x n array of bools. m and n are optional.
VertexShaderConstantIint[m[n]]m x n array of ints. m and n are optional.
VertexShaderConstantFfloat[m[n]]m x n array of floats. m and n are optional.

 

Texture States

Texture states initialize textures used by the multitexture blender.

Texture StateTypeValues
Texture[8]textureNULL, or a texture parameter.

 

Texture Stage States

Texture stage states set up textures and the texture stages in the multitexture blender.

Texture Stage StateTypeValues
AlphaOp[8]dwordSame as D3DTEXTUREOP without the D3DTOP_ prefix. See D3DTSS_ALPHAOP.
AlphaArg0[8]dwordSame as D3DTA without the D3DTA_ prefix. See D3DTSS_ALPHAARG0.
AlphaArg1[8]dwordSame as D3DTA without the D3DTA_ prefix. See D3DTSS_ALPHAARG1.
AlphaArg2[8]dwordSame as D3DTA without the D3DTA_ prefix. See D3DTSS_ALPHAARG2.
ColorArg0[8]dwordSame as D3DTA without the D3DTA_ prefix. See D3DTSS_COLORARG0.
ColorArg1[8]dwordSame as D3DTA without the D3DTA_ prefix. See D3DTSS_COLORARG1.
ColorArg2[8]dwordSame as D3DTA without the D3DTA_ prefix. See D3DTSS_COLORARG2.
ColorOp[8]dwordSame as D3DTEXTUREOP without the D3DTOP_ prefix. See D3DTSS_COLOROP.
BumpEnvLScale[8]floatSame values as D3DTSS_BUMPENVLSCALE without the D3DTSS_TCI prefix.
BumpEnvLOffset[8]floatSame values as D3DTSS_BUMPENVLOFFSET without the D3DTSS_TCI prefix.
BumpEnvMat00[8]floatSame values as D3DTSS_BUMPENVMAT00.
BumpEnvMat01[8]floatSame values as D3DTSS_BUMPENVMAT01.
BumpEnvMat10[8]floatSame values as D3DTSS_BUMPENVMAT10.
BumpEnvMat11[8]floatSame values as D3DTSS_BUMPENVMAT11.
ResultArg[8]dwordSame as D3DTA without the D3DTA_ prefix. See D3DTSS_RESULTARG.
TexCoordIndex[8]dwordSame values as D3DTSS_TEXCOORDINDEX without the D3DTSS_TCI prefix.
TextureTransformFlags[8]dwordSame values as D3DTEXTURETRANSFORMFLAGS values without the D3DTTFF_ prefix. See D3DTSS_TEXTURETRANSFORMFLAGS.

 

Transform States

Set transform states to initialize transformation matrices. Effects use transposed matrices for efficiency. You can provide transposed matrices to an effect, or an effect will automatically transpose the matrices before using them.

Transform StateTypeValues
ProjectionTransformfloat4x4A 4x4 matrix of floats. Same values as D3DTS_PROJECTION without the D3DTS_ prefix.
TextureTransform[8]float4x4A 4x4 matrix of floats. Same values as D3DTRANSFORMSTATETYPE without the D3DTS_ prefix.
ViewTransformfloat4x4A 4x4 matrix of floats. Same values as D3DTS_VIEW without the D3DTS_ prefix.
WorldTransformfloat4x4A 4x4 matrix of floats.

 

Related topics

Effect Format

 

 

Show: