理解D3D—(2)最多混合几层texture

先提出问题

Q:要是模型有很多层贴图,再加上shadow map,还有ssao,岂不是会不够用了?

A:

参考资料

IDirect3DDevice9::SetTexture

Assigns a texture to a stage for a device.

HRESULT SetTexture(
DWORD Sampler,
IDirect3DBaseTexture9 * pTexture
);

Parameters

Sampler

Zero based sampler number. Textures are bound to samplers; samplers define sampling state such as the filtering mode and the address wrapping mode. Textures are referenced differently by the programmable and the fixed function pipeline【可编程着色器和固定管线,这两种情况下,textures不同】:

  1. Programmable shaders reference textures using the sampler number. The number of samplers available to a programmable shader is dependent on the shader version【可编程着色器的有效采样器的数目取决于着色器的版本】. For vertex shaders, see Sampler (Direct3D 9 asm-vs). For pixel shaders see Sampler (Direct3D 9 asm-ps).
  2. The fixed function pipeline on the other hand, references textures by texture stage number【另一方面,固定管线取决于texture stage的数目】. The maximum number of samplers is determined from two caps: MaxSimultaneousTextures and MaxTextureBlendStages of the D3DCAPS9 structure.

[in] There are two other special cases for stage/sampler numbers.

  1. A special number called D3DDMAPSAMPLER is used for Displacement Mapping (Direct3D 9).
  2. A programmable vertex shader uses a special number defined by a D3DVERTEXTEXTURESAMPLER when accessing Vertex Textures in vs_3_0 (DirectX HLSL).
Remarks

IDirect3DDevice9::SetTexture is not allowed if the texture is created with a pool type of D3DPOOL_SCRATCH. IDirect3DDevice9::SetTexture is not allowed with a pool type of D3DPOOL_SYSTEMMEM texture unless DevCaps is set with D3DDEVCAPS_TEXTURESYSTEMMEMORY.

 

IDirect3DDevice9::SetTextureStageState

Sets the state value for the currently assigned texture.

HRESULT SetTextureStageState(
DWORD Stage,
D3DTEXTURESTAGESTATETYPE Type,
DWORD Value
);
Parameters
Stage
[in] 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【Stage标识符从0开始。设备可以有8组textures,所以Stage的最大值为7】. 【Q:eight set textures == 8组textures?啥意思?】
Type
[in] Texture state to set. This parameter can be any member of the D3DTEXTURESTAGESTATETYPE enumerated type.
Value
[in] State value to set. The meaning of this value is determined by the Type parameter.

Gamebryo里面

nid3dpass.h

    //  Max number of blending stages supported.
//  Should correspond to the number of pixel shader instructions allowed.
    static unsigned int ms_uiMaxTextureBlendStages;
//  Max number of textures that can be bound to the blending stages.
//  Should correspond to the number of texture registers supported by the
//  pixel shaders.
    static unsigned int ms_uiMaxSimultaneousTextures;
//  Max number of samplers supported.
//  Can only be greater than ms_uiMaxTextureBlendStages under DX9 when
//  PS2.0 (or greater) hardware is supported.
    static unsigned int ms_uiMaxSamplers;

内网跟踪了下LightSpeed的版本蜗牛的例子StandardMaterial,ms_uiMaxTextureBlendStages == 8.

  1. Bump maps

  2. Dark maps

  3. Decal maps (up to 3)

  4. Detail maps

  5. Gloss maps

  6. Glow maps

  7. Normal maps
  8. Parallax maps

  9. Environment maps

Q:已经9个了,那Base maps呢?

A:ms_uiMaxSamplers可以比ms_uiMaxTextureBlendStages大了,呵呵,加上Base maps一共10个,还有shadow,猜想ms_uiMaxSamplers至少==11.

2009-9-30 经跟踪代码,Pixel Shader版本大于2,就是16个。就是device capabilities嘛,一初始化程序就能确定。device::GetDeviceCaps(…)

nidx9renderer.cpp

NiDX9Renderer::InitializeDeviceCaps

NiD3DPass::SetMaxTextureBlendStages(m_kD3DCaps9.MaxTextureBlendStages);
NiD3DPass::SetMaxSimultaneousTextures(m_kD3DCaps9.MaxSimultaneousTextures);
if (m_uiMaxPixelShaderVersion >= D3DPS_VERSION(20))
    NiD3DPass::SetMaxSamplers(16);
else
    NiD3DPass::SetMaxSamplers(m_kD3DCaps9.MaxTextureBlendStages);

 再加上ssao,也肯定是是够用的了。

 IDirect3DDevice9::GetDeviceCaps

Retrieves the capabilities of the rendering device.【取得渲染设备的能力

HRESULT GetDeviceCaps(
D3DCAPS9 * pCaps
);
Parameters
pCaps
[out] Pointer to a D3DCAPS9 structure, describing the returned device.
Return Values

If the method succeeds, the return value is D3D_OK. If the method fails, the return value can be D3DERR_INVALIDCALL.

Remarks

IDirect3DDevice9::GetDeviceCaps retrieves the software vertex pipeline capabilities when the device is being used in software vertex processing mode.

原文地址:https://www.cnblogs.com/lai3d/p/1575355.html