//----------------------------------------------------------------------- void CEnvironmentMap::modelShaderApply(OwnMatrix4x4 *pModelMtx /*= NULL*/, bool bRenderEnvMappedMesh) { LPD3DXCONSTANTTABLE constable = mVtxConstTable; OwnMatrix4x4 modelMtx, viewProjMtx, modelViewProjMtx; if (NULL == pModelMtx) modelMtx.setIdentity(); else modelMtx = *pModelMtx; viewProjMtx.setMultiply(mCamera->mViewTrans, mCamera->mProjectionTrans); modelViewProjMtx.setMultiply(modelMtx, viewProjMtx); HRESULT hr; D3DXHANDLE handle; D3DXHANDLE modelViewProj = mVtxConstTable->GetConstantByName(0, "u_ModelViewProjMatrix"); hr = mVtxConstTable->SetMatrix(mD3DDevice, modelViewProj, (D3DXMATRIX*)&modelViewProjMtx); D3DXHANDLE u_ModelMatrix = constable->GetConstantByName(0, "u_ModelToWorld"); hr = constable->SetMatrix(mD3DDevice, u_ModelMatrix, (D3DXMATRIX*)&modelMtx); LPD3DXCONSTANTTABLE pixConstable = mPxlConstTable; float value = bRenderEnvMappedMesh ? 0.5f : 0; D3DXHANDLE reflectivity = pixConstable->GetConstantByName(0, "$reflectivity"); hr = pixConstable->SetFloat(mD3DDevice, reflectivity, value); }
bool CD3D9HLSLMaterialRenderer::setVariable(bool vertexShader, const c8* name, const f32* floats, int count) { LPD3DXCONSTANTTABLE tbl = vertexShader ? VSConstantsTable : PSConstantsTable; if (!tbl) return false; // currently we only support top level parameters. // Should be enough for the beginning. (TODO) D3DXHANDLE hndl = tbl->GetConstantByName(NULL, name); if (!hndl) { core::stringc s = "HLSL Variable to set not found: '"; s += name; s += "'. Available variables are:"; os::Printer::log(s.c_str(), ELL_WARNING); printHLSLVariables(tbl); return false; } HRESULT hr = tbl->SetFloatArray(pID3DDevice, hndl, floats, count); if (FAILED(hr)) { os::Printer::log("Error setting float array for HLSL variable", ELL_WARNING); return false; } return true; }
//----------------------------------------------------------------------- void CEnvironmentMap::lightShaderConfig() { HRESULT hr; D3DXHANDLE handle; Material material; material.Ke = D3DXVECTOR3(0, 0, 0); material.Ka = D3DXVECTOR3(0, 0, 0); material.Kd = D3DXVECTOR3(1, 1, 1); material.Ks = D3DXVECTOR3(1, 1, 1); material.shininess = 5; Light light; light.position = D3DXVECTOR3(-10, 0, -10); light.color = D3DXVECTOR3(0, 1, 0); LPD3DXCONSTANTTABLE constable = mVtxConstTable; D3DXHANDLE u_Material = constable->GetConstantByName(0, "u_Material"); hr = constable->SetValue(mD3DDevice, u_Material, &material, sizeof(material)); D3DXHANDLE u_Light = constable->GetConstantByName(0, "u_Light"); hr = constable->SetValue(mD3DDevice, u_Light, &light, sizeof(light)); }