![]() |
![]() |
BasicHLSL Sample
Path
Sample Overview
How does the sample work? Note that the D3DXCreateEffectFromFile() call takes flags which are needed to debug shaders with the Microsoft Visual Studio .NET shader debugger. Debugging vertex shaders requires either REF or software vertex processing, and debugging pixel shaders requires REF. The D3DXSHADER_FORCE_*_SOFTWARE_NOOPT flag improves the debug experience in the shader debugger. It enables source level debugging, prevents instruction reordering, prevents dead code elimination, and forces the compiler to compile against the next higher available software target, which ensures that the unoptimized shaders do not exceed the shader model limitations. Setting these flags will cause slower rendering since the shaders will be unoptimized and forced into software. All that is needed to turn these flags on with the sample code is to uncomment the #define DEBUG_VS or #define DEBUG_PS line from near the top of the file. This will also force the device into software processing by adding some code to CMyD3DApplication::ConfirmDevices(). See the DirectX documentation for more information about using the shader debugger. In CMyD3DApplication::Render() it sets the technique to use with a call to m_pEffect->SetTechnique(). It passes a D3DXHANDLE to the technique that was obtained upon init with a call to m_pEffect->GetTechniqueByName(). It is possible to pass a string name instead of a handle, but using a handle improves performance since this high frequency call does not have to spend time on a string compare. It then sets variables used by the technique such as the World*View*Projection matrix and the time variable with various ID3DXEffect::Set*() calls. To render it calls m_pEffect->Begin() which returns the number of passes required by the technique, then it loops through each pass calling m_pEffect->Pass(iPass) and rendering the mesh with m_pMesh->DrawSubset(). When all the passes are done, it calls m_pEffect->End().
|