ID3DXEffectStateManager::SetTextureStageState 这个函数有一大堆的参数:
HRESULT SetTextureStageState(
DWORD Stage,
D3DTEXTURESTAGESTATETYPE Type,
DWORD Value
);
Stage:这个参数是指第几层纹理,0.1.2.3..., 这个版本的dx9(Feb,2005)的SDK中说最多支持8层(Stage identifier of the texture for which the state value is set. Stage identifiers are zero-based. Devices can have up to eight set textures, so the maximum value allowed for Stage is 7. )
Type:定义对该纹理的哪个属进行设置,值很多。。。
Value: 指的是前面所选属性的值
Type:
typedef enum _D3DTEXTURESTAGESTATETYPE {
D3DTSS_COLOROP = 1, //颜色的运算这里的op 是operations,指对前面设置的颜色进行运算既后面的2个type:D3DTSS_COLORARG1,D3DTSS_COLORARG2或D3DTSS_ALPHAARG1,D3DTSS_ALPHAARG2 = 6
D3DTSS_COLORARG1 = 2,
D3DTSS_COLORARG2 = 3,
D3DTSS_ALPHAOP = 4, //alpha通道的运算
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;
Value又包括二个:D3DTEXTUREOF和D3DTA.( Can be either an operation (D3DTEXTUREOP) or an argument value (D3DTA), depending on what is chosen for Type.)
D3DTEXTUREOF:
D3DTOP_DISABLE = 1, //该纹理无效,既不显示
D3DTOP_SELECTARG1 = 2, //选择第1个颜色值(既D3DTSS_COLORARG1的值)作为纹理颜色输出
D3DTOP_SELECTARG2 = 3, //选择第2个颜色值(既D3DTSS_COLORARG2的值)作为纹理颜色输出
D3DTOP_MODULATE = 4, //将颜色1和颜色2相乘作为纹理颜色输出
D3DTOP_MODULATE2X = 5, //将颜色1和颜色2相乘后左移1bit(用于增亮)作为纹理颜色输出 ,
D3DTOP_MODULATE4X = 6, //将颜色1和颜色2相乘后左移2bit(用于增亮)作为纹理颜色输出
D3DTOP_ADD = 7, //将颜色1和颜色2相加作为纹理颜色输出
D3DTOP_ADDSIGNED = 8, ///////////后面的参见SDK 都是对2个颜色进行运算
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,
D3DTA:
这里的TA指的是texture arguments ,
D3DTA_CONSTANT //给当前纹理一个固定的值;
D3DTA_DIFFUSE; //diffuse的值作为参数 diffuse 可能有多个来源比如材质,vertex
D3DTA_SELECTMASK //Mask value for all arguments; not used when setting texture arguments 这句话不理解啊,为什么要伪装呢
D3DTA_SPECULAR //取spercular 的值作为参数 来源同diffuse
D3DTA_TEMP //待定
D3DTA_TEXTURE //用纹理的颜色值作为参数
D3DTA_TFACTOR //待定
参数太多,头都大了,晕呼呼的…
学习纹理:
要逆向思维,先学习HLSL,再回头看SetTextureStageState??
HRESULT SetTextureStageState( DWORD Stage,
D3DTEXTURESTAGESTATETYPE Type,
DWORD value
);
这个函数 的第二个参数和第三个参数 组合太多了...搞糊涂了..
第二个参数枚举类型
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;
第三个参数涉及到的枚举类型之一
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;
和D3DTA参数..
谁能详细的介绍下这个函数的功能和作用..以及参数的组合
下面的代码实现怎样的效果啊..看不懂
g_pd3dDevice->SetTexture( 0, g_pTexNormal );
g_pd3dDevice->SetTexture( 1, g_pTexDiffuse );
g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );
g_pd3dDevice->SetSamplerState( 1, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, 0 );
g_pd3dDevice->SetTextureStageState( 1, D3DTSS_TEXCOORDINDEX, 0 );
DWORD dwFactor = VectortoRGBA( &g_vLight, 0.0f );
g_pd3dDevice->SetRenderState( D3DRS_TEXTUREFACTOR, dwFactor );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_DOTPRODUCT3 );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_TFACTOR );
g_pd3dDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_MULTIPLYADD );
g_pd3dDevice->SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE );
g_pd3dDevice->SetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_CURRENT );
g_pd3dDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );
g_pd3dDevice->SetTextureStageState( 1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
///////////////////////////////////////////////////////
功能差不多就是用第一张做凸凹纹理,加上第2层纹理的颜色
//这个是法线贴图
g_pd3dDevice->SetTexture( 0, g_pTexNormal );
//这个是漫反射贴图
g_pd3dDevice->SetTexture( 1, g_pTexDiffuse );
//纹理采样方式
g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );
g_pd3dDevice->SetSamplerState( 1, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );
//两个纹理都使用0号纹理坐标
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, 0 );
g_pd3dDevice->SetTextureStageState( 1, D3DTSS_TEXCOORDINDEX, 0 );
//把光向量转成AGBA格式
DWORD dwFactor = VectortoRGBA( &g_vLight, 0.0f );
//你就这样理解下一句吧,这里设置一张纹理,纹理所有像素颜色读是上一句转换的RGBA颜色
g_pd3dDevice->SetRenderState( D3DRS_TEXTUREFACTOR, dwFactor );
//下面把纹理0设置为该阶段纹理混合第一个参数,操作方式为向量点乘,第2个参数为上面设置的factor"纹理“
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_DOTPRODUCT3 );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_TFACTOR );
//把第2层纹理和上面合成的纹理乘法叠加,然后再和上面合成的纹理相加
g_pd3dDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_MULTIPLYADD );
g_pd3dDevice->SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE );
g_pd3dDevice->SetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_CURRENT );
//透明处理,透明度以第2层纹理的alpha值为准
g_pd3dDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );
g_pd3dDevice->SetTextureStageState( 1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
//-------没时间了,要去做饭了。。可能还没说清楚哈
法线贴图产生凸凹纹理
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/zdl1016/archive/2007/05/24/1624276.aspx