还是先发DX的文档的记录:
Sets the state value for the currently assigned texture.
HRESULT SetTextureStageState( DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value );
If the method succeeds, the return value is D3D_OK. If the method fails, the return value can be D3DERR_INVALIDCALL.
Header: Declared in D3D9.h.
Library: Use D3D9.lib.
中英结合
三个参数:
1.指定当前设置的纹理层序号(Or ID)。貌似只能是0-7
2.设置纹理的渲染状态,是枚举值。可以是这些东西:
typedef enum D3DTEXTURESTAGESTATETYPE { D3DTSS_COLOROP = 1, D3DTSS_COLORARG1 = 2, D3DTSS_COLORARG2 = 3, D3DTSS_ALPHAOP = 4, D3DTSS_ALPHAARG1 = 5, D3DTSS_ALPHAARG2 = 6, D3DTSS_BUMPENVMAT00 = 7, D3DTSS_BUMPENVMAT01 = 8, D3DTSS_BUMPENVMAT10 = 9, D3DTSS_BUMPENVMAT11 = 10, D3DTSS_TEXCOORDINDEX = 11, D3DTSS_BUMPENVLSCALE = 22, D3DTSS_BUMPENVLOFFSET = 23, D3DTSS_TEXTURETRANSFORMFLAGS = 24, D3DTSS_COLORARG0 = 26, D3DTSS_ALPHAARG0 = 27, D3DTSS_RESULTARG = 28, D3DTSS_CONSTANT = 32, D3DTSS_FORCE_DWORD = 0x7fffffff, } D3DTEXTURESTAGESTATETYPE, *LPD3DTEXTURESTAGESTATETYPE;
DX文档上面有详细的解释。
3.设置的状态值,根据第二个参数的不同,第三个参数具有不同的取值方法和含义。
下面来看DX的Demo-Textures:
g_pd3dDevice->SetTexture( 0, g_pTexture );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_DISABLE );
都什么意思呢?
这5句分别是:
1.设置g_pTexture这个纹理对象的ID撒。
2.D3DTSS_COLOROP是设置纹理颜色的混合方法,Value值属于D3DTEXTUREOP这个枚举的成员:
typedef enum D3DTEXTUREOP { D3DTOP_DISABLE = 1, D3DTOP_SELECTARG1 = 2, D3DTOP_SELECTARG2 = 3, D3DTOP_MODULATE = 4, D3DTOP_MODULATE2X = 5, D3DTOP_MODULATE4X = 6, D3DTOP_ADD = 7, D3DTOP_ADDSIGNED = 8, D3DTOP_ADDSIGNED2X = 9, D3DTOP_SUBTRACT = 10, D3DTOP_ADDSMOOTH = 11, D3DTOP_BLENDDIFFUSEALPHA = 12, D3DTOP_BLENDTEXTUREALPHA = 13, D3DTOP_BLENDFACTORALPHA = 14, D3DTOP_BLENDTEXTUREALPHAPM = 15, D3DTOP_BLENDCURRENTALPHA = 16, D3DTOP_PREMODULATE = 17, D3DTOP_MODULATEALPHA_ADDCOLOR = 18, D3DTOP_MODULATECOLOR_ADDALPHA = 19, D3DTOP_MODULATEINVALPHA_ADDCOLOR = 20, D3DTOP_MODULATEINVCOLOR_ADDALPHA = 21, D3DTOP_BUMPENVMAP = 22, D3DTOP_BUMPENVMAPLUMINANCE = 23, D3DTOP_DOTPRODUCT3 = 24, D3DTOP_MULTIPLYADD = 25, D3DTOP_LERP = 26, D3DTOP_FORCE_DWORD = 0x7fffffff, } D3DTEXTUREOP, *LPD3DTEXTUREOP;
D3DTOP_MODULATE把第一个和第二个颜色相乘输出。这个第一个(Arg1)和(Arg2)到底是什么东西呢?继续往下看撒~~
3.D3DTSS_COLORARG1 第一个颜色撒~~ 这里设置为纹理颜色
4.D3DTSS_COLORARG2 第二个颜色是定点的漫反色颜色。
5.禁用Alpha操作
然后咱们看看DX的BasicHLSL的Shader:
PS_OUTPUT RenderScenePS( VS_OUTPUT In,
uniform bool bTexture )
{
PS_OUTPUT Output;
// Lookup mesh texture and modulate it with diffuse
if( bTexture )
Output.RGBColor = tex2D(MeshTextureSampler, In.TextureUV) * In.Diffuse;
else
Output.RGBColor = In.Diffuse;
return Output;
}
明白了吧~~笑~
详细的就不写了,自个儿翻DX的文档吧。
g_D3DDevice->SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, 0);//第一层纹理使用第一套纹理坐标