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
- Material States
- Render States
- Sampler States
- Sampler Stage States
- Shader States
- Shader Constant States
- Texture States
- Texture Stage States
- Transform States
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 State | Type | Values |
---|---|---|
LightAmbient[n] | float4 | See the Ambient member of D3DLIGHT9. |
LightAttenuation0[n] | float | See the Attenuation0 member of D3DLIGHT9. |
LightAttenuation1[n] | float | See the Attenuation1 member of D3DLIGHT9. |
LightAttenuation2[n] | float | See the Attenuation2 member of D3DLIGHT9. |
LightDiffuse[n] | float4 | See the Diffuse member of D3DLIGHT9. |
LightDirection[n] | float3 | See the Direction member of D3DLIGHT9. |
LightEnable[n] | bool | TRUE or FALSE. See the bEnable argument in LightEnable. |
LightFalloff[n] | float | D3DCOLORVALUE. See the Falloff member of D3DLIGHT9. |
LightPhi[n] | float | See the Phi member of D3DLIGHT9. |
LightPosition[n] | float3 | See the Position member of D3DLIGHT9. |
LightRange[n] | float | See the Range member of D3DLIGHT9. |
LightSpecular[n] | float4 | See the Specular member of D3DLIGHT9. |
LightTheta[n] | float | See the Theta member of D3DLIGHT9. |
LightType[n] | dword | Same 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 State | Type | Values |
---|---|---|
MaterialAmbient | float4 | Same value as Ambient |
MaterialDiffuse | float4 | Same value as Diffuse |
MaterialEmissive | float4 | Same value as Emissive |
MaterialPower | float | Same value as Power |
MaterialSpecular | float4 | Same 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 State | Type | Values |
---|---|---|
AlphaBlendEnable | bool | True or False. Same values as D3DRS_ALPHABLENDENABLE in D3DRENDERSTATETYPE. |
AlphaFunc | dword | Same values as D3DCMPFUNC without the D3DCMP_ prefix. See D3DRS_ALPHAFUNC. |
AlphaRef | dword | Same values as D3DRS_ALPHAREF. |
AlphaTestEnable | dword | True or False. See D3DRS_ALPHATESTENABLE. |
BlendOp | dword | Same values as D3DBLENDOP without the D3DBLENDOP_ prefix. |
ColorWriteEnable | dword | Bitwise combination of RED, GREEN, BLUE, and ALPHA. See D3DRS_COLORWRITEENABLE. |
DepthBias | float | Same values as D3DRS_DEPTHBIAS. |
DestBlend | dword | Same values as D3DBLEND without the D3DBLEND_ prefix. |
DitherEnable | bool | True or False. Same values as D3DRS_DITHERENABLE. |
FillMode | dword | Same values as D3DFILLMODE without the D3DFILL_ prefix. |
LastPixel | dword | True or False. See D3DRS_LASTPIXEL. |
ShadeMode | dword | Same values as D3DSHADEMODE without the D3DSHADE_ prefix. |
SlopeScaleDepthBias | float | Same values as D3DRS_SLOPESCALEDEPTHBIAS. |
SrcBlend | dword | Same values as D3DBLEND without the D3DBLEND_ prefix. |
SRGBWriteEnable | bool | True or False. Same values as D3DRS_SRGBWRITEENABLE. |
StencilEnable | bool | True or False. Same values as D3DRS_STENCILENABLE. |
StencilFail | dword | Same values as D3DSTENCILCAPS without the D3DSTENCILCAP_ prefix. See D3DRS_STENCILFAIL. |
StencilFunc | dword | Same values as D3DCMPFUNC without the D3DCMP_ prefix. See D3DRS_STENCILFUNC. |
StencilMask | dword | Same values as D3DRS_STENCILMASK. |
StencilPass | dword | Same values as D3DSTENCILCAPS without the D3DSTENCILCAP_ prefix. See D3DRS_STENCILPASS. |
StencilRef | int | Same values as D3DRS_STENCILREF. |
StencilWriteMask | dword | Same values as D3DRS_STENCILWRITEMASK. |
StencilZFail | dword | Same values as D3DSTENCILCAPS without the D3DSTENCILCAP_ prefix. See D3DRS_STENCILZFAIL. |
TextureFactor | dword | Same values as D3DCOLOR. Same values as D3DRS_TEXTUREFACTOR. |
Wrap0 - Wrap15 | dword | Values are the same as the values used by D3DRS_WRAP0. Valid values are:
|
ZEnable | dword | Same values as D3DZBUFFERTYPE without the D3DZB_ prefix. |
ZFunc | dword | Same values as D3DCMPFUNC without the D3DCMP_ prefix. See D3DRS_ZFUNC. |
ZWriteEnable | bool | True 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 State | Type | Values |
---|---|---|
Ambient | float4 | Same values as D3DRS_AMBIENT. |
AmbientMaterialSource | dword | Same values as D3DMATERIALCOLORSOURCE without the D3DMCS_ prefix. See D3DRS_AMBIENTMATERIALSOURCE. |
Clipping | bool | True or False. Same values as D3DRS_CLIPPING. |
ClipPlaneEnable | dword | Bitwise combination of D3DCLIPPLANE0 - D3DCLIPPLANE5 macros. See D3DCLIPPLANEn and D3DRS_CLIPPLANEENABLE. |
ColorVertex | bool | True or False. Same values as D3DRS_COLORVERTEX. |
CullMode | dword | Same values as D3DCULL without the D3DCULL_ prefix. |
DiffuseMaterialSource | dword | Same values as D3DMATERIALCOLORSOURCE without the D3DMCS_ prefix. See D3DRS_DIFFUSEMATERIALSOURCE. |
EmissiveMaterialSource | dword | Same values as D3DMATERIALCOLORSOURCE without the D3DMCS_ prefix. See D3DRS_EMISSIVEMATERIALSOURCE. |
FogColor | dword | Same values as D3DCOLOR. See D3DRS_FOGCOLOR. |
FogDensity | float | Same values as D3DRS_FOGDENSITY. |
FogEnable | bool | True or False. Same values as D3DRS_FOGENABLE. |
FogEnd | float | Same values as D3DRS_FOGEND. |
FogStart | float | Same values as D3DRS_FOGSTART. |
FogTableMode | dword | Same values as D3DFOGMODE. See D3DRS_FOGTABLEMODE in D3DRENDERSTATETYPE. |
FogVertexMode | dword | Same values as D3DFOGMODE without the D3DFOG_ prefix. |
IndexedVertexBlendEnable | bool | True or False. Same values as D3DRS_INDEXEDVERTEXBLENDENABLE. |
Lighting | bool | True or False. Same values as D3DRS_LIGHTING. |
LocalViewer | bool | True or False. Same values as D3DRS_LOCALVIEWER. |
MultiSampleAntialias | bool | Same values as D3DRS_MULTISAMPLEANTIALIAS. |
MultiSampleMask | dword | Same values as D3DRS_MULTISAMPLEMASK. |
NormalizeNormals | bool | True or False. Same values as D3DRS_NORMALIZENORMALS. |
PatchSegments | float | Same values as nSegments in SetNPatchMode. |
PointScale_A | float | Same values as D3DRS_POINTSCALE_A. |
PointScale_B | float | Same values as D3DRS_POINTSCALE_B. |
PointScale_C | float | Same values as D3DRS_POINTSCALE_C. |
PointScaleEnable | bool | Same values as D3DRS_POINTSCALEENABLE. |
PointSize | float | Same values as D3DRS_POINTSIZE. |
PointSize_Min | float | Same values as D3DRS_POINTSIZE_MIN. |
PointSize_Max | float | Same values as D3DRS_POINTSIZE_MAX without the D3DRS_ prefix. |
PointSpriteEnable | bool | True or False. Same values as D3DRS_POINTSPRITEENABLE. |
RangeFogEnable | bool | True or False. Same values as D3DRS_RANGEFOGENABLE. |
SpecularEnable | bool | True or False. Same values as D3DRS_SPECULARENABLE. |
SpecularMaterialSource | dword | Same values as D3DMATERIALCOLORSOURCE without the D3DMCS_ prefix. See D3DRS_SPECULARMATERIALSOURCE. |
TweenFactor | float | Same values as D3DRS_TWEENFACTOR. |
VertexBlend | dword | Same 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.
State | Type | Values |
---|---|---|
Sampler | sampler | NULL, 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 State | Type | Values |
---|---|---|
AddressU[16] | dword | Same values as D3DTEXTUREADDRESS without the D3DTADDRESS_ prefix. See D3DSAMP_ADDRESSU. |
AddressV[16] | dword | Same values as D3DTEXTUREADDRESS without the D3DTADDRESS_ prefix. See D3DSAMP_ADDRESSV. |
AddressW[16] | dword | Same 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] | dword | Same values as D3DTEXTUREFILTERTYPE without the D3DTEXF_ prefix. See D3DSAMP_MAGFILTER. |
MaxAnisotropy[16] | dword | Same values as D3DSAMP_MAXANISOTROPY without the D3DSAMP_ prefix. |
MaxMipLevel[16] | int | Same values as D3DSAMP_MAXMIPLEVEL without the D3DSAMP_ prefix. |
MinFilter[16] | dword | Same values as D3DSAMP_MINFILTER without the D3DSAMP_ prefix. |
MipFilter[16] | dword | Same values as D3DSAMP_MIPFILTER without the D3DSAMP_ prefix. |
MipMapLodBias[16] | float | Same values as D3DSAMP_MIPMAPLODBIAS without the D3DSAMP_ prefix. |
SRGBTexture | bool | Same 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 State | Type | Values |
---|---|---|
PixelShader | pixelshader | NULL, an assembly block, a compile target, or a pixel shader parameter. |
VertexShader | vertexshader | NULL, 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 State | Type | Values |
---|---|---|
PixelShaderConstant | float[m[n]] | m x n array of floats; m and n are optional. |
PixelShaderConstant1 | float4 | One 4D float. |
PixelShaderConstant2 | float4x2 | Two 4D floats. |
PixelShaderConstant3 | float4x3 | Three 4D floats. |
PixelShaderConstant4 | float4x4 | Four 4D floats. |
PixelShaderConstantB | bool[m[n]] | m x n array of bools; m and n are optional. |
PixelShaderConstantI | int[m[n]] | m x n array of ints. m and n are optional. |
PixelShaderConstantF | float[m[n]] | m x n array of floats. m and n are optional. |
VertexShaderConstant | float[m[n]] | m x n array of floats. m and n are optional. |
VertexShaderConstant1 | float4 | One 4D float. |
VertexShaderConstant2 | float4x2 | Two 4D floats. |
VertexShaderConstant3 | float4x3 | Three 4D floats. |
VertexShaderConstant4 | float4x4 | Four 4D floats. |
VertexShaderConstantB | bool[m[n]] | m x n array of bools. m and n are optional. |
VertexShaderConstantI | int[m[n]] | m x n array of ints. m and n are optional. |
VertexShaderConstantF | float[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 State | Type | Values |
---|---|---|
Texture[8] | texture | NULL, or a texture parameter. |
Texture Stage States
Texture stage states set up textures and the texture stages in the multitexture blender.
Texture Stage State | Type | Values |
---|---|---|
AlphaOp[8] | dword | Same as D3DTEXTUREOP without the D3DTOP_ prefix. See D3DTSS_ALPHAOP. |
AlphaArg0[8] | dword | Same as D3DTA without the D3DTA_ prefix. See D3DTSS_ALPHAARG0. |
AlphaArg1[8] | dword | Same as D3DTA without the D3DTA_ prefix. See D3DTSS_ALPHAARG1. |
AlphaArg2[8] | dword | Same as D3DTA without the D3DTA_ prefix. See D3DTSS_ALPHAARG2. |
ColorArg0[8] | dword | Same as D3DTA without the D3DTA_ prefix. See D3DTSS_COLORARG0. |
ColorArg1[8] | dword | Same as D3DTA without the D3DTA_ prefix. See D3DTSS_COLORARG1. |
ColorArg2[8] | dword | Same as D3DTA without the D3DTA_ prefix. See D3DTSS_COLORARG2. |
ColorOp[8] | dword | Same as D3DTEXTUREOP without the D3DTOP_ prefix. See D3DTSS_COLOROP. |
BumpEnvLScale[8] | float | Same values as D3DTSS_BUMPENVLSCALE without the D3DTSS_TCI prefix. |
BumpEnvLOffset[8] | float | Same values as D3DTSS_BUMPENVLOFFSET without the D3DTSS_TCI prefix. |
BumpEnvMat00[8] | float | Same values as D3DTSS_BUMPENVMAT00. |
BumpEnvMat01[8] | float | Same values as D3DTSS_BUMPENVMAT01. |
BumpEnvMat10[8] | float | Same values as D3DTSS_BUMPENVMAT10. |
BumpEnvMat11[8] | float | Same values as D3DTSS_BUMPENVMAT11. |
ResultArg[8] | dword | Same as D3DTA without the D3DTA_ prefix. See D3DTSS_RESULTARG. |
TexCoordIndex[8] | dword | Same values as D3DTSS_TEXCOORDINDEX without the D3DTSS_TCI prefix. |
TextureTransformFlags[8] | dword | Same 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 State | Type | Values |
---|---|---|
ProjectionTransform | float4x4 | A 4x4 matrix of floats. Same values as D3DTS_PROJECTION without the D3DTS_ prefix. |
TextureTransform[8] | float4x4 | A 4x4 matrix of floats. Same values as D3DTRANSFORMSTATETYPE without the D3DTS_ prefix. |
ViewTransform | float4x4 | A 4x4 matrix of floats. Same values as D3DTS_VIEW without the D3DTS_ prefix. |
WorldTransform | float4x4 | A 4x4 matrix of floats. |