Vertex Textures in vs_3_0 (DirectX HLSL)
The vertex shader 3.0 model supports texture lookup in the vertex shader using the texldl - vs texture load statement. The vertex engine contains four texture sampler stages, named D3DVERTEXTEXTURESAMPLER0, D3DVERTEXTEXTURESAMPLER1, D3DVERTEXTEXTURESAMPLER2, and D3DVERTEXTEXTURESAMPLER3. These are distinct from the displacement map sampler and texture samplers in the pixel engine.
To sample textures set at those four stages, you can use the vertex engine and program the stages with the CheckDeviceFormat method. Set textures at those stages using SetTexture, with the stage index D3DVERTEXTEXTURESAMPLER0 through D3DVERTEXTEXTURESAMPLER3. A new register has been introduced in the vertex shader, the sampler register (like in ps_2_0), which represents the vertex texture sampler. This register needs to be defined in the shader before using it.
The functionality is identical to the pixel textures, except for the following:
- Anisotropic texture filtering is not supported, hence D3DSAMP_MAXANISOTROPY is ignored and D3DTEXF_ANISOTROPIC cannot be set for magnify, or minify for these stages.
- Rate of change information is not available, hence the application has to compute the level of detail and provide that information as a parameter to texldl - vs.
- As in pixel shaders, if multielement textures are supported, D3DSAMP_ELEMENTINDEX is used to figure out which element to sample from.
- The state D3DSAMP_DMAPOFFSET is ignored for these stages.
- Use CheckDeviceFormat with D3DUSAGE_QUERY_VERTEXTEXTURE" to query a texture to see if it can be used as a vertex texture.
- VertexTextureFilterCaps indicates what kind of filters are allowed at the vertex texture samplers. D3DPTFILTERCAPS_MINFANISOTROPIC and D3DPTFILTERCAPS_MAGFANISOTROPIC are disallowed.
A sampling stage register identifies a sampling unit that can be used in texture load statements. A sampling unit corresponds to the texture sampling stage, encapsulating the sampling-specific state provided in SetSamplerState.
Each sampler uniquely identifies a single texture surface that is set to the corresponding sampler using SetTexture. However, the same texture surface can be set at multiple samplers.
At draw time, a texture cannot be simultaneously set as a render target and a texture at a stage.
Because vs_3_0 supports four samplers, up to four texture surfaces can be read from in a single shader pass. A sampler register might appear only as an argument in the texture load statement: texldl - vs.
In vs_3_0, if you use a sampler, it must be declared at the beginning of the shader program, using the dcl_samplerType (sm3 - vs asm) (as in ps_2_0).
This feature will be supported in software vertex processing. The specific filter types supported can be checked by calling GetDeviceCaps and checking VertexTextureFilterCaps. All published texture formats will be supported as vertex textures in software vertex processing.
Applications can check if a particular texture format is supported in the software vertex processing mode by calling CheckDeviceFormat and providing (D3DVERTEXTEXTURESAMPLER | D3DUSAGE_SOFTWAREPROCESSING) as usage. All formats are supported for software vertex processing. The scratch pool is required for software vertex processing.
// New define #define D3DVERTEXTEXTURESAMPLER0 (D3DDMAPSAMPLER+1) #define D3DVERTEXTEXTURESAMPLER1 (D3DDMAPSAMPLER+2) #define D3DVERTEXTEXTURESAMPLER2 (D3DDMAPSAMPLER+3) #define D3DVERTEXTEXTURESAMPLER3 (D3DDMAPSAMPLER+4) #define D3DVERTEXTEXTURESAMPLER (0x00100000L) // New caps field in D3DCAPS9 DWORD VertexTextureFilterCaps;