texture永远是图形学最精华细节最多的地方,所以我也花了最多的时间阅读和写这个章节。
d3dDevice->SetTexture
(n,tex)设置当前在n通道的texture,n的数量硬件在0-7.多个通道的texture可以进行blending
一个pixel在光照计算后得到一个颜色值c1,它纹理采样有一个颜色值c2,最终这个pixel的颜色值为
Color = c1 x DestBlend+c2 x SourceBlend
可以通过
IDirect3DDevice9::SetRenderState(D3DRS_BLENDXXX)来控制这个混合策略
默认是
SourceBlend = D3DBLEND_SRCALPHA
DestBlend = D3DBLEND_INVSRCALPHA
也就是贴图的颜色权重就是alpha值。
可以通过这个设定,设置贴图的透明度,SourceBlend = D3DBLEND_ZERO
DestBlend = D3DBLEND_ONE就会变成贴图完全消失
7.1 address mode
纹理坐标通常在0-1之间,当处理那些不在这个范围内的纹理坐标时的策略就是address mode
IDirect3DDevice9::SetSamplerState(D3DSAMP_ADDRESSU/D3DSAMP_ADDRESSV/D3DSAMP_ADDRESSW,)
D3DTADDRESS_WRAP 重复纹理u=2与u=1相同
D3DTADDRESS_MIRROR 于上类似,但是01正向 12镜像23正向...
D3DTADDRESS_CLAMP
小于0设为0 大于1设为1
D3DTADDRESS_BORDER 超范围的设为设定的border color
(设定这个值通过IDirect3DDevice9::SetSamplerState(D3DSAMP_BORDERCOLOR))
D3DTADDRESS_MIRRORONCE 只镜像一次然后 clamp
虽然允许使用任意数值的纹理坐标,但是往往这个值也是被硬件限制的,D3DCAPS9中的MaxTextureRepeat代表纹理坐标的范围在-MaxTextureRepeat到MaxTextureRepeat之间。
The interpretation of MaxTextureRepeat is also affected by the D3DPTEXTURECAPS_TEXREPEATNOTSCALEDBYSIZE capability bit. When this bit is set, the value in the MaxTextureRepeat member is used precisely as described. However, when D3DPTEXTURECAPS_TEXREPEATNOTSCALEDBYSIZE is not set, texture repeating limitations depend on the size of the texture indexed by the texture coordinates. In this case, MaxTextureRepeat must be scaled by the current texture size at the largest level of detail to compute the valid texture coordinate range. For example, given a texture dimension of 32 and MaxTextureRepeat of 512, the actual valid texture coordinate range is 512/32 = 16, so the texture coordinates for this device must be within the range of -16.0 to +16.0.
7.2 texture filtering
filtering是使用具体的0-1内的纹理坐标获取纹理上颜色值的策略。
IDirect3DDevice9::SetSamplerState(0-7),场合参数,filter参数)
场合参数
D3DSAMP_MAGFILTER,一个纹理点(texel)需要被映射到很多pixel的时候放大
D3DSAMP_MINFILTER,一个pixel采样到很多纹理点的时候,放小
D3DSAMP_MIPFILTER mipmap