void ConverToLogLuminance(LPDIRECT3DTEXTURE9 pSource, sImageInfo *pInfo) { LPDIRECT3DDEVICE9 device = GutGetGraphicsDeviceDX9(); device->SetRenderTarget(0, g_pFrameSurface[DOWNSAMPLED_256x256]); device->SetDepthStencilSurface(NULL); D3DXHANDLE shader = g_pExposureEffect->GetTechniqueByName("LogLuminance"); g_pExposureEffect->SetTechnique(shader); D3DXHANDLE tablevar = g_pExposureEffect->GetParameterByName(NULL, "vLuminanceTable"); D3DXHANDLE imagevar = g_pExposureEffect->GetParameterByName(NULL, "Image"); Vector4 vTable(0.21f, 0.71f, 0.072f); g_pExposureEffect->SetVector(tablevar, (D3DXVECTOR4*)&vTable); g_pExposureEffect->SetTexture(imagevar, pSource); g_pExposureEffect->Begin(NULL, 0); g_pExposureEffect->BeginPass(0); DrawFullScreenQuad(pInfo); g_pExposureEffect->EndPass(); g_pExposureEffect->End(); }
HRESULT CD3DFont::InitDeviceObjects( LPDIRECT3DDEVICE9 pd3dDevice ) { HRESULT hr; // Keep a local copy of the device m_pd3dDevice = pd3dDevice; // Large fonts need larger textures //m_dwTexWidth = m_dwTexHeight = 256; xmlNode *node = XMLParseFile("textures/font.xml"); assert(node); int count = node->attribute("count").Asint(); m_dwSpacing = node->attribute("spacing").Asint() ; m_dwTexWidth = node->attribute("width").Asint(); m_dwTexHeight= node->attribute("height").Asint(); String imagefile = "textures/font.png"; StringIter p(node->body); for( int i=0;i<count;i++) { int c; p >> c; p >> m_fTexCoords[c-32][0] >> m_fTexCoords[c-32][1] >> m_fTexCoords[c-32][2] >> m_fTexCoords[c-32][3]; } hr=D3DXCreateTextureFromFile(m_pd3dDevice,(const char*)imagefile,&m_pTexture); LPD3DXBUFFER error; extern String effectpath; D3DXCreateEffectFromFile(m_pd3dDevice,effectpath + "/font.fx",NULL,NULL,0,NULL,&effect,&error) && VERIFY_RESULT; assert(effect); diffusemap = effect->GetParameterByName(NULL,"diffusemap"); assert(diffusemap); effect->SetTexture(diffusemap,m_pTexture) && VERIFY_RESULT; return S_OK; }
HRESULT KG3DSceneShadowMap::SetParametersForShader(LPD3DXEFFECT pShader) { KGLOG_PROCESS_ERROR(pShader); pShader->SetTexture("tShadowmap1",m_ShadowLevel[0].m_lpSMShadowMap); pShader->SetTexture("tShadowmap2",m_ShadowLevel[1].m_lpSMShadowMap); pShader->SetTexture("tShadowmap3",m_ShadowLevel[2].m_lpSMShadowMap); pShader->SetMatrix("matLightVP1",&m_ShadowLevel[0].m_matVP); pShader->SetMatrix("matLightVP2",&m_ShadowLevel[1].m_matVP); pShader->SetMatrix("matLightVP3",&m_ShadowLevel[2].m_matVP); /* D3DXVECTOR4 UV[9]; float x = 1.0F/m_ShadowLevel[0].m_dwShadowmapSize; float y = 1.0F/m_ShadowLevel[0].m_dwShadowmapSize; UV[0] = D3DXVECTOR4( 0, 0,0,0.3F); UV[1] = D3DXVECTOR4(-x, 0,0,0.3F); UV[2] = D3DXVECTOR4( x, 0,0,0.3F); UV[3] = D3DXVECTOR4( 0,-y,0,0.3F); UV[4] = D3DXVECTOR4( 0, y,0,0.3F); UV[5] = D3DXVECTOR4(-x, y,0,0.3F); UV[6] = D3DXVECTOR4( x, y,0,0.3F); UV[7] = D3DXVECTOR4( x,-y,0,0.3F); UV[8] = D3DXVECTOR4( x,-y,0,0.8F); pShader->SetVectorArray("g_avSampleOffsets",UV,9); */ return S_OK; Exit0: return E_FAIL; }
//--------------------------------------------------------------------------------------- // シェーダ終了 //--------------------------------------------------------------------------------------- void EndShader() { // パス終了 g_pFX->EndPass(); // テクニック終了 g_pFX->End(); }
void CShaderManager::Render( ) { if( m_pD3DDevice == NULL || m_pObject == NULL ) return; LPD3DXEFFECT fxShader = GetShader( m_pObject->m_hShader ); if( fxShader == NULL ) { m_pObject->Render(); return; } UINT uiNumPasses = 0; fxShader->Begin( &uiNumPasses, 0 ); for( UINT iPass = 0; iPass < uiNumPasses; ++iPass ) { fxShader->BeginPass( iPass ); m_pObject->Render(); fxShader->EndPass(); } fxShader->End(); }
void DXPointLight::DrawShadowMap(LPDIRECT3DDEVICE9 device, LPD3DXEFFECT effect, void (*drawcallback)(LPD3DXEFFECT)) { if( !shadowmap || !needsredraw ) return; LPDIRECT3DSURFACE9 surface = NULL; D3DXMATRIX vp; effect->SetVector("lightPos", (D3DXVECTOR4*)&position); for( int j = 0; j < 6; ++j ) { GetViewProjMatrix(vp, j); effect->SetMatrix("matViewProj", &vp); shadowmap->GetCubeMapSurface((D3DCUBEMAP_FACES)j, 0, &surface); device->SetRenderTarget(0, surface); device->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, 0xff000000, 1.0f, 0); drawcallback(effect); surface->Release(); } if( shadowtype == Static ) needsredraw = false; }
static void AddImpulse(void) { static Vector4 vPosition(0.0f, 0.0f, 0.0f, 0.0f); //Vector4 vDiff = vPosition - g_vPosition; Vector4 vDiff = g_vPosition - vPosition; Vector4 vLength = vDiff.Length(); if ( vLength[0]<2.0f ) return; Vector4 vDir = vDiff / vLength; Vector4 vVec0(vDir[1],-vDir[0], 0.0f, 0.0f); Vector4 vVec1(vDir[0], vDir[1], 0.0f, 0.0f); vPosition = g_vPosition; Vector4 vVec0_old = g_orient_matrix[0]; Vector4 vVec1_old = g_orient_matrix[1]; Vector4 vVec0_new = VectorLerp(vVec0_old, vVec0, 0.2f); Vector4 vVec1_new = VectorLerp(vVec1_old, vVec1, 0.2f); vVec0_new.Normalize(); vVec1_new.Normalize(); Vector4 vVec2_new = Vector3CrossProduct(vVec0_new, vVec1_new); g_orient_matrix.Identity(); g_orient_matrix[0] = vVec0_new; g_orient_matrix[1] = vVec1_new; g_orient_matrix[2] = vVec2_new; LPDIRECT3DDEVICE9 device = GutGetGraphicsDeviceDX9(); device->SetRenderTarget(0, g_pSurfaces[TEX_HEIGHT1]); device->SetDepthStencilSurface(NULL); Matrix4x4 view_matrix = g_Control.GetViewMatrix(); Matrix4x4 world_matrix; world_matrix.Scale_Replace(g_fRippleSize, g_fRippleSize, 1.0f); world_matrix[3] = g_vPosition; Matrix4x4 wvp_matrix = g_orient_matrix * world_matrix * view_matrix * g_proj_matrix; D3DXHANDLE shader = g_pWaterEffect->GetTechniqueByName("AddImpulse"); D3DXHANDLE wvp_matrix_var = g_pWaterEffect->GetParameterByName(NULL, "wvp_matrix"); D3DXHANDLE force_var = g_pWaterEffect->GetParameterByName(NULL, "fForce"); g_pWaterEffect->SetTechnique(shader); g_pWaterEffect->SetMatrix(wvp_matrix_var, (D3DXMATRIX *)&wvp_matrix); g_pWaterEffect->SetFloat(force_var, 0.05f); g_pWaterEffect->Begin(NULL, 0); g_pWaterEffect->BeginPass(0); g_Model_DX9.Render(0); g_pWaterEffect->EndPass(); g_pWaterEffect->End(); vPosition = g_vPosition; }
void CShaderManager::UnloadShader( HSHADER hShader ) { LPD3DXEFFECT fxShader = GetShader( hShader ); if( fxShader == NULL ) return; fxShader->Release(); m_vEffects[ hShader ] = NULL; }
//--------------------------------------------------------------------------------------- // ワールド変換行列設定(&シェーダへ設定) //--------------------------------------------------------------------------------------- void SetWorldMatrixShader(LPD3DXMATRIX pWorld) { g_pFX->SetMatrix(g_hMatWVP, &(*pWorld * g_mView * g_mProj)); g_pFX->SetMatrix(g_hMatW, pWorld); g_pFX->SetFloatArray(g_hLight, &g_vLight.x, 4); g_pFX->SetFloatArray(g_hCamera, &g_vCamera.x, 3); }
void SetupFX() { // 텍스처와 행렬값을 ID3DXEffect(여기서는 정점쉐이더)에 전달한다. g_pEffect->SetTexture( "tex0", g_pTexture ); g_pEffect->SetMatrix( "matW", &g_matWorld ); g_pEffect->SetMatrix( "matV", &g_matView ); g_pEffect->SetMatrix( "matP", &g_matProj ); }
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; }
//************************************************************************************************************* void DrawShadowVolume(const ShadowCaster& caster) { extrude->SetMatrix("matWorld", &caster.world); extrude->CommitChanges(); device->SetVertexDeclaration(shadowdecl); device->SetStreamSource(0, caster.vertices, 0, sizeof(D3DXVECTOR4)); device->SetIndices(caster.indices); device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, caster.numvertices, 0, caster.numfaces); }
void DXDirectionalLight::BlurShadowMap(LPDIRECT3DDEVICE9 device, LPD3DXEFFECT effect) { if( !shadowmap || !blur || !blurdeclforpointfordirectional || !needsblur ) return; float blurvertices[36] = { -0.5f, -0.5f, 0, 1, 0, 0, (float)shadowsize - 0.5f, -0.5f, 0, 1, 1, 0, -0.5f, (float)shadowsize - 0.5f, 0, 1, 0, 1, -0.5f, (float)shadowsize - 0.5f, 0, 1, 0, 1, (float)shadowsize - 0.5f, -0.5f, 0, 1, 1, 0, (float)shadowsize - 0.5f, (float)shadowsize - 0.5f, 0, 1, 1, 1 }; LPDIRECT3DSURFACE9 surface = NULL; D3DXVECTOR4 texelsize(1.0f / shadowsize, 0, 0, 0); UINT stride = 6 * sizeof(float); device->SetVertexDeclaration(blurdeclforpointfordirectional); // x blur->GetSurfaceLevel(0, &surface); effect->SetVector("texelSize", &texelsize); effect->CommitChanges(); device->SetRenderTarget(0, surface); device->Clear(0, NULL, D3DCLEAR_TARGET, 0xff000000, 1.0f, 0); device->SetTexture(0, shadowmap); device->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 2, blurvertices, stride); surface->Release(); std::swap(texelsize.x, texelsize.y); // y shadowmap->GetSurfaceLevel(0, &surface); effect->SetVector("texelSize", &texelsize); effect->CommitChanges(); device->SetRenderTarget(0, surface); device->Clear(0, NULL, D3DCLEAR_TARGET, 0xff000000, 1.0f, 0); device->SetTexture(0, blur); device->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 2, blurvertices, stride); surface->Release(); if( shadowtype == Static ) needsblur = false; }
//--------------------------------------------------------------------------------------- // シェーダ開始 //--------------------------------------------------------------------------------------- void BeginShader(int nTechnique) { if (nTechnique < 0 || nTechnique >= MAX_TECHNIQUE) { nTechnique = 0; } // テクニック設定 g_pFX->SetTechnique(g_hTech[nTechnique]); g_pFX->Begin(NULL, 0); // パス開始 g_pFX->BeginPass(0); }
void Destroy() { itLst _F = mpEft.begin(); itLst _L = mpEft.end(); for(; _F != _L; ++_F) { LPD3DXEFFECT pEft = _F->second; pEft->Release(); } mpEft.clear(); }
void VisualizeTextureLevel(LPDIRECT3DTEXTURE9 tex, int level, int x, int y, int w, int h, float gamma) { LPD3DXEFFECT effect = LoadEffect("utils.fx"); if (effect == NULL) return; CGame2D* g2d = Get2D(); effect->SetTexture("g_Image", tex); effect->SetFloat("g_Level", (float) level); effect->SetFloat("g_Gamma", gamma); effect->SetTechnique("TextureLevel"); DX_BEGIN_EFFECT(effect); g2d->DrawRect(x, y, w, h, 0xFFFFFFFF); DX_END_EFFECT(effect); }
// 3D 물체등을 그린다. void RenderScene() { // 뷰행렬 초기화. D3DXMATRIXA16 matView; // D3DXVECTOR3 vEyePt(0.0f, 0.0f, -200.0f); D3DXVECTOR3 vEyePt(gWorldCameraPosition.x, gWorldCameraPosition.y, gWorldCameraPosition.z); D3DXVECTOR3 vLookatPt(0.0f, 0.0f, 0.0f); D3DXVECTOR3 vUpVec(0.0f, 1.0f, 0.0f); D3DXMatrixLookAtLH(&matView, &vEyePt, &vLookatPt, &vUpVec); // 투영행렬 초기화. D3DXMATRIXA16 matProjection; D3DXMatrixPerspectiveFovLH(&matProjection, FOV, ASPECT_RATIO, NEAR_PLANE, FAR_PLANE); // 회전. gRotationY += ((0.4f * PI) / 180.0f); if (gRotationY > 2 * PI) gRotationY -= 2 * PI; // 월드행렬 초기화. D3DXMATRIXA16 matWorld; // D3DXMatrixIdentity(&matWorld); D3DXMatrixRotationY(&matWorld, gRotationY); // 쉐이더에 전달. gpTextureMappingShader->SetMatrix("gWorldMatrix", &matWorld); gpTextureMappingShader->SetMatrix("gViewMatrix", &matView); gpTextureMappingShader->SetMatrix("gProjectionMatrix", &matProjection); gpTextureMappingShader->SetVector("gWorldLightPosition", &gWorldLightPosition); gpTextureMappingShader->SetVector("gWorldCameraPosition", &gWorldCameraPosition); // gpTextureMappingShader->SetTexture("DiffuseMap_Tex", gpEarthDM); // 쉐이더 적용. UINT numPasses = 0; gpTextureMappingShader->Begin(&numPasses, NULL); for (UINT i = 0; i < numPasses; ++i) { gpTextureMappingShader->BeginPass(i); gpSphere->DrawSubset(0); gpTextureMappingShader->EndPass(); } gpTextureMappingShader->End(); }
INT ResetDevice() { itLst _F = mpEft.begin(); itLst _L = mpEft.end(); for(; _F != _L; ++_F) { LPD3DXEFFECT pEft = _F->second; if(FAILED(pEft->OnResetDevice())) return -1; } return 0; }
FXShader::FXShader(LPD3DXEFFECT FX,const char* name) : FXHandle(FX,name) { handle = FX->GetTechniqueByName(name); if(!handle) { Globals::console->Write("ERROR: cannot create D3DXHANDLE to shader '%s'\r\n",name); } Reset(); }
MString FxParameterGetUiLabel(LPD3DXEFFECT pEffect, DXCCEffectPath& parameter) { HRESULT hr= S_OK; CStringA UIName(parameter.End->Description.Name); if(parameter.Length == 1) { LPCSTR pName; D3DXHANDLE hUIName= DXCCFindEffectAnnotation(pEffect, parameter.Root->Handle, "SasUiLabel"); if(hUIName != NULL) { if(DXCC_SUCCEEDED(pEffect->GetString(hUIName, &pName))) UIName= pName; } } else { DXCCEffectElement* parent= ¶meter.Root[parameter.Length-2]; if(parent->Description.Elements != 0) UIName.Format( "[%d]", parameter.End->Index); } //e_Exit: return MString(UIName.GetString()); }
//************************************************************************************************************* void Render(float alpha, float elapsedtime) { static float time = 0; D3DXMATRIX viewproj; D3DXMatrixMultiply(&viewproj, &view, &proj); D3DXMatrixScaling(&world, 0.1f, 0.1f, 0.1f); time += elapsedtime; device->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, 0xff6694ed, 1.0f, 0); device->SetTransform(D3DTS_WORLD, &world); device->SetTransform(D3DTS_VIEW, &view); device->SetTransform(D3DTS_PROJECTION, &proj); mesh.Update(elapsedtime, &world); effect->SetMatrix("matViewProj", &viewproj); if( SUCCEEDED(device->BeginScene()) ) { mesh.Draw(); device->EndScene(); } device->Present(NULL, NULL, NULL, NULL); }
void RenderFrameDX9(void) { LPDIRECT3DDEVICE9 device = GutGetGraphicsDeviceDX9(); device->BeginScene(); AddImpulse(); WaterSimulation(); HeightmapToNormal(); device->SetRenderTarget(0, g_pMainFramebuffer); device->SetDepthStencilSurface(g_pMainDepthbuffer); device->Clear(0, NULL, D3DCLEAR_ZBUFFER, 0x0, 1.0f, 0); RenderWater(); DrawObject(); SwapHeightmaps(); float x = -1.0f; float y = -1.0f; float w = 0.4f; float h = 0.4f; if ( g_iMode & 0x01 ) { DrawImage(g_pTextures[TEX_HEIGHT2], x, y, w, h, &g_ImageInfo); x+=w; } if ( g_iMode & 0x02 ) { D3DXHANDLE shader = g_pWaterEffect->GetTechniqueByName("Heightmap"); D3DXHANDLE heightmap_var = g_pWaterEffect->GetTechniqueByName("heightmap_current"); g_pWaterEffect->SetTechnique(shader); g_pWaterEffect->SetTexture(heightmap_var, g_pTextures[TEX_HEIGHT2]); g_pWaterEffect->Begin(NULL, 0); g_pWaterEffect->BeginPass(0); GutDrawScreenQuad_DX9(x, y, w, h, &g_ImageInfo); g_pWaterEffect->EndPass(); g_pWaterEffect->End(); x+=w; } if ( g_iMode & 0x04 ) { DrawImage(g_pTextures[TEX_NORMAL], x, y, w, h, &g_ImageInfo); x+=w; } device->EndScene(); device->Present( NULL, NULL, NULL, NULL ); }
void CRenderTarget::Fill(CGame2D* g2d, int x, int y, int w, int h, float color[4]) { LPD3DXEFFECT effect = LoadEffect("utils.fx"); if (effect == NULL) return; BeginRenderTarget(0); if (SUCCEEDED(GetDevice()->BeginScene())) { CGame2D* g2d = Get2D(); effect->SetFloatArray("g_Fill", color, 4); effect->SetTechnique("FillTexture"); DX_BEGIN_EFFECT(effect); g2d->DrawRect(x, y, w, h, 0xFFFFFFFF); DX_END_EFFECT(effect); GetDevice()->EndScene(); } EndRenderTarget(); }
//************************************************************************************************************* void DownSample() { hdreffect->SetTechnique("downsample"); hdreffect->Begin(NULL, 0); hdreffect->BeginPass(0); for( int i = 1; i < 5; ++i ) { device->SetRenderTarget(0, dssurfaces[i]); device->SetTexture(0, dstargets[i - 1]); texelsize.x = (float)(2 << i) / (float)screenwidth; texelsize.y = (float)(2 << i) / (float)screenheight; tmpvert[6] = tmpvert[24] = tmpvert[30] = (float)screenwidth / ((float)(2 << i)) - 0.5f; tmpvert[13] = tmpvert[19] = tmpvert[31] = (float)screenheight / ((float)(2 << i)) - 0.5f; hdreffect->SetVector("texelsize", &texelsize); hdreffect->CommitChanges(); device->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 2, tmpvert, sizeof(D3DXVECTOR4) + sizeof(D3DXVECTOR2)); } hdreffect->EndPass(); hdreffect->End(); }
void VCND3D9_SelectionFX::SetSelectionState( LPD3DXEFFECT pShader, const VCNEffectParamSet& params ) { HRESULT hr; float f = params.GetFloat(VCNTXT("Selected")); hr = pShader->SetFloat( mSelected, f); VCN_ASSERT( SUCCEEDED(hr) ); }
void Cleanup() { // 폰트를 release 한다. if (gpFont) { gpFont->Release(); gpFont = NULL; } // 모델을 release 한다. if (gpSphere) { gpSphere->Release(); gpSphere = NULL; } // 쉐이더를 release 한다. if (gpNormalMappingShader) { gpNormalMappingShader->Release(); gpNormalMappingShader = NULL; } // 텍스처를 release 한다. if (gpStoneDM) { gpStoneDM->Release(); gpStoneDM = NULL; } if (gpStoneSM) { gpStoneSM->Release(); gpStoneSM = NULL; } if (gpStoneNM) { gpStoneNM->Release(); gpStoneNM = NULL; } // D3D를 release 한다. if (gpD3DDevice) { gpD3DDevice->Release(); gpD3DDevice = NULL; } if (gpD3D) { gpD3D->Release(); gpD3D = NULL; } }
void CGlowEffect::SetBlurEffectParameters(float dx,float dy,float blurAmount,CEffectFile* pEffect) { const int sampleCount = 9; float sampleWeights[sampleCount]; float sampleOffset[sampleCount * 2]; sampleWeights[0] = ComputeGaussian(0,blurAmount); sampleOffset[0] = 0; sampleOffset[1] = 0; float totalWeight = sampleWeights[0]; for (int i=0;i<sampleCount/2;i++) { float weight = ComputeGaussian( (float)(i+1),blurAmount); sampleWeights[i*2+1] = weight; sampleWeights[i*2+2] = weight; totalWeight += weight * 2; float offset = i * 2 + 1.5f; float offsetX = dx * offset; float offsetY = dy * offset; int index = (i * 2) * 2 + 2; sampleOffset[index] = offsetX; sampleOffset[index+1] = offsetY; sampleOffset[index+2] = -offsetX; sampleOffset[index+3] = -offsetY; } for(int i=0;i<sampleCount;i++) { sampleWeights[i] /= totalWeight; } //optimize code here!!! LPD3DXEFFECT fx = pEffect->GetDXEffect(); fx->SetFloatArray(fx->GetParameterByName(NULL,"sampleWeight"),sampleWeights,sampleCount); fx->SetFloatArray(fx->GetParameterByName(NULL,"sampleOffset"),sampleOffset,sampleCount * 2); }
//----------------------------------------------------------------------------- // Name: GetNextTechnique // Desc: //----------------------------------------------------------------------------- HRESULT CMyD3DApplication::GetNextTechnique(INT nDir, BOOL bBypassValidate) { D3DXEFFECT_DESC effect; UINT_PTR iTechnique = m_iTechnique; m_pEffect->GetDesc(&effect); for(;;) { iTechnique += nDir; if(((INT_PTR) iTechnique) < 0) iTechnique = effect.Techniques - 1; if(iTechnique >= effect.Techniques) iTechnique = 0; if(nDir && (iTechnique == m_iTechnique)) break; if(!nDir) nDir = 1; m_pEffect->SetTechnique((LPCSTR) iTechnique); if(bBypassValidate || (iTechnique == effect.Techniques - 1) || (m_bDrawCaustics || !m_pEffect->IsParameterUsed("tCAU")) && SUCCEEDED(m_pEffect->Validate())) { m_iTechnique = iTechnique; char szText[256]; sprintf(szText, "Water - Technique %d", m_iTechnique); SetWindowText(m_hWnd, szText); return S_OK; } } m_pEffect->SetTechnique((LPCSTR) m_iTechnique); return E_FAIL; }
/** * Sets the value currently stored in the parameter * * @date Created Apr 01, 2006 * @return Reference to the left parameter; Useful to assigning lines of * parameters at once. * @{ */ CShaderVariant& CShaderVariant::operator= (const CShaderVariant& oVal) { // Get description from both parameters. LPD3DXEFFECT pEffect = m_pParent->getD3DXEffect(); D3DXPARAMETER_DESC desc; HRESULT hRetval = pEffect->GetParameterDesc(m_hParam, &desc); HRESULT hRetOval = pEffect->GetParameterDesc(oVal.m_hParam, &desc); if(FAILED(hRetval) | FAILED(hRetOval)) return *this; // Copy parameter values unsigned char *pData = new unsigned char[desc.Bytes]; if (!pData) return *this; pEffect->GetValue(oVal.m_hParam, pData, desc.Bytes); pEffect->SetValue(m_hParam, pData, desc.Bytes); delete [] pData; return *this; }
//************************************************************************************************************* void BrightPass() { device->SetRenderTarget(0, dssurfaces[0]); device->SetTexture(0, scenetarget); tmpvert[6] = tmpvert[24] = tmpvert[30] = (float)screenwidth * 0.5f - 0.5f; tmpvert[13] = tmpvert[19] = tmpvert[31] = (float)screenheight * 0.5f - 0.5f; hdreffect->SetTechnique("brightpass"); hdreffect->Begin(NULL, 0); hdreffect->BeginPass(0); { device->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 2, tmpvert, sizeof(D3DXVECTOR4) + sizeof(D3DXVECTOR2)); } hdreffect->EndPass(); hdreffect->End(); // generate afterimage now device->SetRenderTarget(0, aftersurfaces[afterimagetex]); if( afterimage ) { device->SetTexture(0, afterimages[1 - afterimagetex]); device->SetTexture(1, dstargets[0]); hdreffect->SetTechnique("afterimage"); hdreffect->Begin(NULL, 0); hdreffect->BeginPass(0); { device->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 2, tmpvert, sizeof(D3DXVECTOR4) + sizeof(D3DXVECTOR2)); } hdreffect->EndPass(); hdreffect->End(); } else device->Clear(0, NULL, D3DCLEAR_TARGET, 0, 1, 0); afterimagetex = 1 - afterimagetex; }