bool c_gbuffer::SetEffectVar(LPD3DXEFFECT& effect, bool& variable_used, cstring texture_semantic, Render::s_render_target& target, cstring x_handle_semantic, const int x_index, cstring y_handle_semantic, const int y_index, cstring z_handle_semantic, const int z_index, cstring w_handle_semantic, const int w_index) { variable_used = false; if(!effect) return false; //find the intended texture handle D3DXHANDLE tex_handle = effect->GetParameterBySemantic(NULL, texture_semantic); variable_used = (tex_handle != NULL) ? true : false; if(!tex_handle) return true; else if(tex_handle && !target.IsEnabled()) return false; // set the texture variable effect->SetTexture(tex_handle, target.texture); // search for the index variables handles // then set them to the indices for the intended data D3DXHANDLE index_handle = NULL; if(x_handle_semantic) { index_handle = effect->GetParameterBySemantic(NULL, x_handle_semantic); if(!index_handle) return false; effect->SetInt(index_handle, x_index); } if(y_handle_semantic) { index_handle = effect->GetParameterBySemantic(NULL, y_handle_semantic); if(!index_handle) return false; effect->SetInt(index_handle, y_index); } if(z_handle_semantic) { index_handle = effect->GetParameterBySemantic(NULL, z_handle_semantic); if(!index_handle) return false; effect->SetInt(index_handle, z_index); } if(w_handle_semantic) { index_handle = effect->GetParameterBySemantic(NULL, w_handle_semantic); if(!index_handle) return false; effect->SetInt(index_handle, w_index); } return true; }
//--------------------------------------------------------------------------------------- // シェーダ初期化 //--------------------------------------------------------------------------------------- HRESULT InitShader() { // シェーダ読み込み HRESULT hr = D3DXCreateEffectFromFile(g_pD3DDevice, PATH_FXTEST, NULL, NULL, 0, NULL, &g_pFX, NULL); if (FAILED(hr)) { TCHAR szMsg[1024]; _stprintf(szMsg, _T("シェーダ(%s)読み込みエラー"), PATH_FXTEST); MessageBox(g_hWnd, szMsg, _T("error"), MB_OK); return hr; } // ハンドル取得 struct _param { LPCSTR pszName; D3DXHANDLE* pHandle; } param[] = { {"WORLDVIEWPROJECTION", &g_hMatWVP}, {"WORLD", &g_hMatW}, {"CAMERAPOSITION", &g_hCamera}, {"MATERIALDIFFUSE", &g_hDiffuse}, {"MATERIALSPECULAR", &g_hSpecular}, {"MATERIALPOWER", &g_hPower}, {"MATERIALAMBIENT", &g_hAmbient}, {"MATERIALTEXTURE", &g_hTexture}, {"MATERIALTEXTUREVALID", &g_hTexEnable}, }; for (int i = 0; i < _countof(param); i++) { *param[i].pHandle = g_pFX->GetParameterBySemantic(NULL, param[i].pszName); } g_hLight = g_pFX->GetParameterByName(NULL, "light"); for (int i = 0; i < MAX_TECHNIQUE; ++i) { g_hTech[i] = g_pFX->GetTechnique(i); } return hr; }