bool D3D11EffectMaterial::SelectTechByName(const char* szName) { ID3DX11EffectTechnique* pTech = m_pEffect->GetTechniqueByName(szName); if(pTech == NULL) { return false; } if(FALSE == pTech->IsValid()) { return false; } m_pTech = pTech; return true; }
bool D3D11EffectMaterial::LoadFromFile(const char* szFile) { ID3D10Blob* pBlob = NULL; ID3D10Blob* pErrorBlob = NULL; if( FAILED( D3DX11CompileFromFileA( szFile, NULL, NULL, NULL, "fx_5_0", D3DCOMPILE_ENABLE_STRICTNESS, NULL, NULL, &pBlob, &pErrorBlob, NULL ) ) ) { OutputDebugInfo(pErrorBlob); return false; } OutputDebugInfo(pErrorBlob); HRESULT ret = D3DX11CreateEffectFromMemory(pBlob->GetBufferPointer(), pBlob->GetBufferSize(), 0, m_pDevice, &m_pEffect); if(FAILED(ret)) { return false; } if(m_pEffect->IsValid() == FALSE) { m_pEffect->Release(); m_pEffect = NULL; return false; } D3DX11_EFFECT_DESC desc; if(FAILED(m_pEffect->GetDesc(&desc))) { m_pEffect->Release(); m_pEffect = NULL; return false; } for(UINT i = 0; i < desc.Techniques; ++i) { ID3DX11EffectTechnique* pTech = m_pEffect->GetTechniqueByIndex(i); if(TRUE == pTech->IsValid()) { m_pTech = pTech; break; } } if(m_pTech == NULL) { m_pEffect->Release(); m_pEffect = NULL; m_pTech = NULL; return false; } D3DX11_TECHNIQUE_DESC tech; if(FAILED(m_pTech->GetDesc(&tech))) { m_pEffect->Release(); m_pEffect = NULL; m_pTech = NULL; } m_nPass = tech.Passes; m_semantics.m_pViewTM = (ID3DX11EffectMatrixVariable*)m_pEffect->GetVariableBySemantic("MATRIX_VIEW"); m_semantics.m_pWorldTM = (ID3DX11EffectMatrixVariable*)m_pEffect->GetVariableBySemantic("MATRIX_WORLD"); m_semantics.m_pProjTM = (ID3DX11EffectMatrixVariable*)m_pEffect->GetVariableBySemantic("MATRIX_PROJ"); m_semantics.m_pInvViewTM = (ID3DX11EffectMatrixVariable*)m_pEffect->GetVariableBySemantic("MATRIX_I_VIEW"); m_semantics.m_pInvWorldTM = (ID3DX11EffectMatrixVariable*)m_pEffect->GetVariableBySemantic("MATRIX_I_WORLD"); m_semantics.m_pInvProjTM = (ID3DX11EffectMatrixVariable*)m_pEffect->GetVariableBySemantic("MATRIX_I_PROJ"); m_semantics.m_pWVTM = (ID3DX11EffectMatrixVariable*)m_pEffect->GetVariableBySemantic("MATRIX_WV"); m_semantics.m_pWVPTM = (ID3DX11EffectMatrixVariable*)m_pEffect->GetVariableBySemantic("MATRIX_WVP"); m_semantics.m_pInvWVTM = (ID3DX11EffectMatrixVariable*)m_pEffect->GetVariableBySemantic("MATRIX_I_WV"); m_semantics.m_pInvWVPTM = (ID3DX11EffectMatrixVariable*)m_pEffect->GetVariableBySemantic("MATRIX_I_WVP"); m_semantics.m_pInvVPTM = (ID3DX11EffectMatrixVariable*)m_pEffect->GetVariableBySemantic("MATRIX_I_VP"); m_semantics.m_pGBuffer = (ID3DX11EffectShaderResourceVariable*)m_pEffect->GetVariableBySemantic("DR_GBUFFER"); m_semantics.m_pABuffer = (ID3DX11EffectShaderResourceVariable*)m_pEffect->GetVariableBySemantic("DR_ABUFFER"); return true; }