D3D9学习笔记(五) State

一个state就是对(固定)渲染管线的某个特性或参数的一次设置

state block 记录了一个序列很多的state,可以保存相似的一连串对管线的设置

4.0.1创建state block

1.创建一个State Block并将当前state加入

IDirect3DDevice9::CreateStateBlock()

2.自动的捕捉一短时间的state变化

IDirect3DStateBlock9* pStateBlock = NULL;

pd3dDevice->BeginStateBlock();

。。。

pd3dDevice->EndStateBlock( &pStateBlock );

3.stateblock的操作

Aply 它可以将这段state作用于当前的设备,(注意当前设备中的这段state里没有捕捉的值不会被改变)

capture:捕捉当前设备中那些存在域这个stateblock里的值的state

GetDevice:获取设备

 

4.1 state的种类

Vertex state

Pixel state

Each texture assigned to a sampler

Each vertex texture

Each displacement map texture

The current texture palette

A pointer to the index buffer

The viewport

The scissors rectangle

The world, view, and projection matrices

The texture transforms

The clipping planes

The current material

 

IDirect3DDevice9::BeginStateBlock后记录的操作

IDirect3DDevice9::LightEnable

IDirect3DDevice9::SetClipPlane

IDirect3DDevice9::SetCurrentTexturePalette

IDirect3DDevice9::SetFVF

IDirect3DDevice9::SetIndices

IDirect3DDevice9::SetLight

IDirect3DDevice9::SetMaterial

IDirect3DDevice9::SetNPatchMode

IDirect3DDevice9::SetPixelShader

IDirect3DDevice9::SetPixelShaderConstantB

IDirect3DDevice9::SetPixelShaderConstantF

IDirect3DDevice9::SetPixelShaderConstantI

IDirect3DDevice9::SetRenderState

IDirect3DDevice9::SetSamplerState

IDirect3DDevice9::SetScissorRect

IDirect3DDevice9::SetStreamSource

IDirect3DDevice9::SetStreamSourceFreq

IDirect3DDevice9::SetTexture

IDirect3DDevice9::SetTextureStageState

IDirect3DDevice9::SetTransform

IDirect3DDevice9::SetViewport

IDirect3DDevice9::SetVertexDeclaration

IDirect3DDevice9::SetVertexShader

IDirect3DDevice9::SetVertexShaderConstantB

IDirect3DDevice9::SetVertexShaderConstantF

IDirect3DDevice9::SetVertexShaderConstantI

4.2设置state

vertex 管线的

IDirect3DDevice9::SetRenderState.渲染状态

        

 

 

 

 

 

state名称

默认值

备注

D3DRS_CULLMODE

D3DCULL_CCW

Backface cull

D3DRS_FOGCOLOR

0

雾颜色

D3DRS_FOGTABLEMODE

D3DFOG_NONE

pixel雾的计算方法(线性 一次两次)

D3DRS_FOGSTART

0

雾参数

D3DRS_FOGEND

1

 

D3DRS_FOGDENSITY

1

 

D3DRS_RANGEFOGENABLE

FALSE

 

D3DRS_AMBIENT

0

环境光颜色

D3DRS_COLORVERTEX

TRUE

是否允许指定每个顶点颜色(默认的)

D3DRS_FOGVERTEXMODE

D3DFOG_NONE

vertex雾的计算方法

D3DRS_CLIPPING

TRUE

允许剪裁

D3DRS_LIGHTING

TRUE

开启光照

D3DRS_LOCALVIEWER

TRUE

摄像机相关的光照,如果用正交投影 那么要false

D3DRS_EMISSIVEMATERIALSOURCE

D3DMCS_MATERIAL

自发光体的光源材质

D3DRS_AMBIENTMATERIALSOURCE

D3DMCS_MATERIAL

环境光的。。

D3DRS_DIFFUSEMATERIALSOURCE

D3DMCS_COLOR1

漫反射光的的。。

D3DRS_SPECULARMATERIALSOURCE

D3DMCS_COLOR2

高光的。。。

D3DRS_VERTEXBLEND

D3DVBF_DISABLE

顶点混合(几何变形使用)的矩阵树龄

D3DRS_CLIPPLANEENABLE

0

自定义剪裁平面开启

D3DRS_POINTSIZE

Driver dependent

A float value that specifies the size to use for point size computation in cases where point size is not specified for each vertex

D3DRS_POINTSIZE_MIN

1

精灵点参数

D3DRS_POINTSPRITEENABLE

FALSE

 

D3DRS_POINTSCALEENABLE

FALSE

 

D3DRS_POINTSCALE_A

1

 

D3DRS_POINTSCALE_B

0

 

D3DRS_POINTSCALE_C

0

 

D3DRS_MULTISAMPLEANTIALIAS

TRUE

多采样采用反走样

D3DRS_MULTISAMPLEMASK

0xffffffff

 

D3DRS_PATCHEDGESTYLE

D3DPATCHEDGE_DISCRETE

在面片边缘处的tesselation采用什么方法(比如是否是浮点数,这将使边缘平滑),默认整数

D3DRS_POINTSIZE_MAX

1

 

D3DRS_INDEXEDVERTEXBLENDENABLE

FALSE

 

D3DRS_TWEENFACTOR

0

 

D3DRS_POSITIONDEGREE

D3DDEGREE_CUBIC

 

D3DRS_NORMALDEGREE

D3DDEGREE_LINEAR

 

D3DRS_MINTESSELLATIONLEVEL

1

Tesselation参数

D3DRS_MAXTESSELLATIONLEVEL

1

 

D3DRS_ADAPTIVETESS_X

0

 

D3DRS_ADAPTIVETESS_Y

0

 

D3DRS_ADAPTIVETESS_Z

1

 

D3DRS_ADAPTIVETESS_W

0

 

 

IDirect3DDevice9::SetSamplerState纹理采样状态

只有这一个可设D3DSAMP_DMAPOFFSET

IDirect3DDevice9::SetTexture把一个纹理绑定到管线的设置

IDirect3DDevice9::SetTextureStageState设置当前绑定纹理的状态值

 

 

 

pixel 管线的

IDirect3DDevice9::SetRenderState.渲染状态

D3DRS_ZENABLE

D3DZB_FALSE

 

使用zbuffer

D3DRS_SPECULARENABLE

FALSE

 

使用高光反射

D3DFILLMODE

D3DFILL_SOLID

 

面的填充模式

D3DSHADEMODE

D3DSHADE_GOURAUD

 

渲染模式(目前只有flat和gouraud)

D3DRS_ZWRITEENABLE

TRUE

 

Depth buffer是否可写,注意这个不影响depthbuffer的比较操作

D3DRS_ALPHATESTENABLE

FALSE

 

Alpha 测试(镂空)

D3DRS_LASTPIXEL

TRUE

 

画最后一个pixel为一条线

D3DRS_SRCBLEND

D3DBLEND_ONE

 

两个混合参数的来源

D3DRS_DESTBLEND

D3DBLEND_ZERO

 

 

D3DRS_ZFUNC

D3DCMP_LESSEQUAL

 

深度测试的比较函数

D3DRS_ALPHAREF

0

 

Alpha测试的基准参数

D3DRS_ALPHAFUNC

D3DCMP_ALWAYS

 

Alpha测试的比较函数

D3DRS_DITHERENABLE

FALSE

 

是否开启dithering

D3DRS_FOGSTART

0

 

Fog参数

D3DRS_FOGEND

1

 

 

D3DRS_FOGDENSITY

1

 

 

D3DRS_ALPHABLENDENABLE

FALSE

 

开启Alpha混合

D3DRS_DEPTHBIAS

0

 

深度偏移值,用于区分在一个平面的两个物体的前后

D3DRS_STENCILENABLE

FALSE

 

开启stencil 缓存

D3DRS_STENCILFAIL

D3DSTENCILOP_KEEP

 

Stencil参数(常用于溶解 贴花 描边)

D3DRS_STENCILZFAIL

D3DSTENCILOP_KEEP

 

 

D3DRS_STENCILPASS

D3DSTENCILOP_KEEP

 

 

D3DRS_STENCILFUNC

D3DCMP_ALWAYS

 

 

D3DRS_STENCILREF

0

 

 

D3DRS_STENCILMASK

0xffffffff

 

 

D3DRS_STENCILWRITEMASK

0xffffffff

 

 

D3DRS_TEXTUREFACTOR

0xffffffff

 

 

D3DRS_WRAP0

0

 

 

D3DRS_WRAP1

0

 

 

D3DRS_WRAP2

0

 

 

D3DRS_WRAP3

0

 

 

D3DRS_WRAP4

0

 

 

D3DRS_WRAP5

0

 

 

D3DRS_WRAP6

0

 

 

D3DRS_WRAP7

0

 

 

D3DRS_WRAP8

0

 

 

D3DRS_WRAP9

0

 

 

D3DRS_WRAP10

0

 

 

D3DRS_WRAP11

0

 

 

D3DRS_WRAP12

0

 

 

D3DRS_WRAP13

0

 

 

D3DRS_WRAP14

0

 

 

D3DRS_WRAP15

0

 

 

D3DRS_LOCALVIEWER

TRUE

 

 

D3DRS_EMISSIVEMATERIALSOURCE

D3DMCS_MATERIAL

 

材质指令

D3DRS_AMBIENTMATERIALSOURCE

D3DMCS_MATERIAL

 

 

D3DRS_DIFFUSEMATERIALSOURCE

D3DMCS_COLOR1

 

 

D3DRS_SPECULARMATERIALSOURCE

D3DMCS_COLOR2

 

 

D3DRS_COLORWRITEENABLE

0x0000000f

 

 

D3DBLENDOP

D3DBLENDOP_ADD

 

混合方式

D3DRS_SCISSORTESTENABLE

FALSE

 

开启SCISSORTEST

D3DRS_SLOPESCALEDEPTHBIAS

0

 

深度偏移的一个参数

D3DRS_ANTIALIASEDLINEENABLE

FALSE

 

开启对线的反走样

D3DRS_TWOSIDEDSTENCILMODE

FALSE

 

双面的stencil模式

D3DRS_CCW_STENCILFAIL

D3DSTENCILOP_KEEP

 

 

D3DRS_CCW_STENCILZFAIL

D3DSTENCILOP_KEEP

 

 

D3DRS_CCW_STENCILPASS

D3DSTENCILOP_KEEP

 

 

D3DRS_CCW_STENCILFUNC

D3DCMP_ALWAYS

 

 

D3DRS_COLORWRITEENABLE1

0x0000000f

 

 

D3DRS_COLORWRITEENABLE2

0x0000000f

 

 

D3DRS_COLORWRITEENABLE3

0x0000000f

 

 

D3DRS_BLENDFACTOR

0xffffffff

 

 

D3DRS_SRGBWRITEENABLE

0

 

 

D3DRS_SEPARATEALPHABLENDENABLE

FALSE

 

为alpha通道做独立的混合操作

D3DRS_SRCBLENDALPHA

D3DBLEND_ONE

 

Alpha混合的相关操作

D3DRS_DESTBLENDALPHA

D3DBLEND_ZERO

 

 

D3DRS_BLENDOPALPHA

D3DBLENDOP_ADD

 

 

IDirect3DDevice9::SetSamplerState纹理采样设置

D3DSAMP_ADDRESSU

 

D3DTADDRESS_WRAP

D3DSAMP_ADDRESSV

 

D3DTADDRESS_WRAP

D3DSAMP_ADDRESSW

 

D3DTADDRESS_WRAP

D3DSAMP_BORDERCOLOR

 

0x00000000

D3DSAMP_MAGFILTER

 

D3DTEXF_POINT

D3DSAMP_MINFILTER

 

D3DTEXF_POINT

D3DSAMP_MIPFILTER

 

D3DTEXF_NONE

D3DSAMP_MIPMAPLODBIAS

 

0

D3DSAMP_MAXMIPLEVEL

 

0

D3DSAMP_MAXANISOTROPY

 

1

D3DSAMP_SRGBTEXTURE

 

0

D3DSAMP_ELEMENTINDEX

 

0

 

IDirect3DDevice9::SetTexture把一个纹理绑定到管线的设置

IDirect3DDevice9::SetTextureStageState设置当前绑定纹理的状态值

D3DTSS_COLOROP

D3DTOP_DISABLE

纹理颜色的操纵方式

D3DTSS_COLORARG1

D3DTA_TEXTURE

 

D3DTSS_COLORARG2

D3DTA_CURRENT

 

D3DTSS_ALPHAOP

D3DTOP_DISABLE

 

D3DTSS_ALPHAARG1

D3DTA_TEXTURE

 

D3DTSS_ALPHAARG2

D3DTA_CURRENT

 

D3DTSS_BUMPENVMAT00

0

 

D3DTSS_BUMPENVMAT01

0

 

D3DTSS_BUMPENVMAT10

0

 

D3DTSS_BUMPENVMAT11

0

 

D3DTSS_TEXCOORDINDEX

0

 

D3DTSS_BUMPENVLSCALE

0

 

D3DTSS_BUMPENVLOFFSET

0

 

D3DTSS_TEXTURETRANSFORMFLAGS

D3DTTFF_DISABLE

 

D3DTSS_COLORARG0

D3DTA_CURRENT

 

D3DTSS_ALPHAARG0

D3DTA_CURRENT

 

D3DTSS_RESULTARG

D3DTA_CURRENT

 

 

你可能感兴趣的:(D3D9学习笔记(五) State)