#include "dxstdafx.h" #include ".\finalcompositionrenderstrategy.h" #include "PathMapEffect.h" #include "Entity.h" #include "SubEntity.h" #include "SubMesh.h" #include "Mesh.h" FinalCompositionRenderStrategy::FinalCompositionRenderStrategy(PathMapEffect* pathMapEffect) :RenderStrategy(pathMapEffect) { } void FinalCompositionRenderStrategy::applyTargets() const { LPDIRECT3DDEVICE9 device = pathMapEffect->device; device->SetRenderTarget(0, pathMapEffect->frameColorBuffer); device->SetDepthStencilSurface(pathMapEffect->frameDepthStencilBuffer); } void FinalCompositionRenderStrategy::applyRenderState() const { LPDIRECT3DDEVICE9 device = pathMapEffect->device; device->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,0), 1.0f, 0 ); } void FinalCompositionRenderStrategy::applyTechnique() const { LPD3DXEFFECT effect = pathMapEffect->effect; int lmode = pathMapEffect->parameters->GetInt(fIndirectLightingMode); if(lmode == 3) effect->SetTechnique("walkIndirect"); if(lmode == 2) effect->SetTechnique("walk"); if(lmode == 1) effect->SetTechnique("walkAmbient"); if(lmode == 0) effect->SetTechnique("walkDirect"); } void FinalCompositionRenderStrategy::applyTransforms(Entity* entity) const { LPD3DXEFFECT effect = pathMapEffect->effect; //set global params static float opttme[9] = {0.5f, 0.0f, 0.0f, 0.0f, -0.5f, 0.0f, 0.5f + (0.5f / pathMapEffect->DEPTHMAPRES), 0.5f + (0.5f / pathMapEffect->DEPTHMAPRES), 1.0f}; D3DXMATRIX torchMatrix; D3DXMatrixTranslation(&torchMatrix, 0.0, -pathMapEffect->parameters->Get(fTorchDistance), 0.0); effect->SetFloatArray("occProjToTexMatrix", opttme, 9); effect->SetMatrix("occWorldToProjMatrix", &(*pathMapEffect->lightCamera->GetViewMatrix() * *pathMapEffect->lightCamera->GetProjMatrix())); effect->SetTexture("depthMap", pathMapEffect->depthMapTexture); effect->SetFloatArray("lightPower", (float*)&lightPower, 3); effect->SetFloatArray("lightPos", (float*)&lightPos, 3); effect->SetFloatArray("lightDir", (float*)&lightDir, 3); if(pathMapEffect->parameters->Get(bLookFromLight)) effect->SetMatrix("modelToProjMatrix", &( entity->modelWorldTransform * *pathMapEffect->lightCamera->GetViewMatrix() * torchMatrix * *pathMapEffect->lightCamera->GetProjMatrix() ) ); else effect->SetMatrix("modelToProjMatrix", &( entity->modelWorldTransform * *pathMapEffect->camera->GetViewMatrix() * *pathMapEffect->camera->GetProjMatrix() ) ); effect->SetMatrix("modelToWorldMatrix", &entity->modelWorldTransform); effect->SetMatrix("inverseTransposedModelToWorldMatrix", &entity->inverseTransposedModelWorldTransform); } void FinalCompositionRenderStrategy::applyTextures(SubEntity* subEntity) const { LPD3DXEFFECT effect = pathMapEffect->effect; // nearestIdx -> bushId static float weightsa[256]; // = new float[entityIterator->nNearClusters]; for(unsigned int y=0; ynNearClusters; y++) { // Entity e = *entityIterator; weightsa[y] = pathMapEffect->weights[subEntity->nearClusterIndices[y]]; } HRESULT hr = effect->SetFloatArray("weightsa", weightsa, subEntity->nNearClusters); effect->SetTexture("filteredAtlas", subEntity->prmTexture); if(subEntity->subMesh->bumpTexture) effect->SetTexture("bumpMap", subEntity->subMesh->bumpTexture); if(subEntity->subMesh->normalTexture) effect->SetTexture("normalMap", subEntity->subMesh->normalTexture); int prmAtlasSize = subEntity->subMesh->parent->prmAtlasSize; int prmnt[2] = {subEntity->prmxres / prmAtlasSize, subEntity->prmyres / prmAtlasSize}; effect->SetIntArray("prmAtlasTiles", prmnt, 2); effect->SetFloatArray("atlasHalfPixel", (float*)&Vector( 0.5 / subEntity->prmxres, 0.5 / subEntity->prmyres, 0.0), 2); if(subEntity->subMesh->lambertTexture) effect->SetTexture("brdfMap", subEntity->subMesh->lambertTexture); else effect->SetTexture("brdfMap", pathMapEffect->emptyTexture); effect->CommitChanges(); } void FinalCompositionRenderStrategy::resetRenderState() const { LPDIRECT3DDEVICE9 device = pathMapEffect->device; device->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW); device->SetRenderState(D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE | D3DCOLORWRITEENABLE_ALPHA); }