source: GTP/trunk/App/Demos/Illum/pathmap/FinalCompositionRenderStrategy.cpp @ 2197

Revision 2197, 4.3 KB checked in by szirmay, 17 years ago (diff)
Line 
1#include "dxstdafx.h"
2#include ".\finalcompositionrenderstrategy.h"
3
4#include "PathMapEffect.h"
5#include "Entity.h"
6#include "SubEntity.h"
7#include "SubMesh.h"
8#include "Mesh.h"
9
10FinalCompositionRenderStrategy::FinalCompositionRenderStrategy(PathMapEffect* pathMapEffect)
11:RenderStrategy(pathMapEffect)
12{
13}
14
15void FinalCompositionRenderStrategy::applyTargets() const
16{
17        LPDIRECT3DDEVICE9 device = pathMapEffect->device;
18        device->SetRenderTarget(0, pathMapEffect->frameColorBuffer);
19        device->SetDepthStencilSurface(pathMapEffect->frameDepthStencilBuffer);
20
21}
22
23void FinalCompositionRenderStrategy::applyRenderState() const
24{
25        LPDIRECT3DDEVICE9 device = pathMapEffect->device;
26       
27        device->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,     D3DCOLOR_XRGB(0,0,0), 1.0f, 0 );
28}
29
30void FinalCompositionRenderStrategy::applyTechnique() const
31{
32        LPD3DXEFFECT effect = pathMapEffect->effect;
33        int lmode = pathMapEffect->parameters->GetInt(fIndirectLightingMode);
34        if(lmode == 3)
35                effect->SetTechnique("walkIndirect");
36        if(lmode == 2)
37                effect->SetTechnique("walk");
38        if(lmode == 1)
39                effect->SetTechnique("walkAmbient");
40        if(lmode == 0)
41                effect->SetTechnique("walkDirect");
42
43}
44
45void FinalCompositionRenderStrategy::applyTransforms(Entity* entity) const
46{
47        LPD3DXEFFECT effect = pathMapEffect->effect;
48
49                //set global params
50        static float opttme[9] = {0.5f, 0.0f, 0.0f,
51                                                        0.0f, -0.5f, 0.0f,
52                                                        0.5f + (0.5f / pathMapEffect->DEPTHMAPRES), 0.5f + (0.5f / pathMapEffect->DEPTHMAPRES), 1.0f};
53
54        D3DXMATRIX torchMatrix;
55        D3DXMatrixTranslation(&torchMatrix, 0.0, -pathMapEffect->parameters->Get(fTorchDistance), 0.0);
56
57        effect->SetFloatArray("occProjToTexMatrix", opttme, 9);
58        effect->SetMatrix("occWorldToProjMatrix", &(*pathMapEffect->lightCamera->GetViewMatrix() * *pathMapEffect->lightCamera->GetProjMatrix()));
59
60        effect->SetTexture("depthMap", pathMapEffect->depthMapTexture);
61
62        effect->SetFloatArray("lightPower", (float*)&lightPower, 3);
63        effect->SetFloatArray("lightPos", (float*)&lightPos, 3);
64        effect->SetFloatArray("lightDir", (float*)&lightDir, 3);
65
66        if(pathMapEffect->parameters->Get(bLookFromLight))
67                effect->SetMatrix("modelToProjMatrix",
68                        &( entity->modelWorldTransform * *pathMapEffect->lightCamera->GetViewMatrix() * torchMatrix * *pathMapEffect->lightCamera->GetProjMatrix() ) );
69        else
70                effect->SetMatrix("modelToProjMatrix",
71                        &( entity->modelWorldTransform * *pathMapEffect->camera->GetViewMatrix() * *pathMapEffect->camera->GetProjMatrix() ) );
72
73        effect->SetMatrix("modelToWorldMatrix", &entity->modelWorldTransform);
74        effect->SetMatrix("inverseTransposedModelToWorldMatrix", &entity->inverseTransposedModelWorldTransform);
75}
76
77void FinalCompositionRenderStrategy::applyTextures(SubEntity* subEntity) const
78{
79        LPD3DXEFFECT effect = pathMapEffect->effect;
80
81        // nearestIdx -> bushId
82        static float weightsa[256]; // = new float[entityIterator->nNearClusters];
83        for(unsigned int y=0; y<subEntity->nNearClusters; y++)
84        {
85//              Entity e = *entityIterator;
86                weightsa[y] = pathMapEffect->weights[subEntity->nearClusterIndices[y]];
87        }
88        HRESULT hr = effect->SetFloatArray("weightsa", weightsa, subEntity->nNearClusters);
89       
90        effect->SetTexture("filteredAtlas", subEntity->prmTexture);
91        if(subEntity->subMesh->bumpTexture)
92                effect->SetTexture("bumpMap", subEntity->subMesh->bumpTexture);
93        if(subEntity->subMesh->normalTexture)
94                effect->SetTexture("normalMap", subEntity->subMesh->normalTexture);
95
96        int prmAtlasSize = subEntity->subMesh->parent->prmAtlasSize;
97        int prmnt[2] = {subEntity->prmxres / prmAtlasSize, subEntity->prmyres / prmAtlasSize};
98
99        effect->SetIntArray("prmAtlasTiles", prmnt, 2);
100        effect->SetFloatArray("atlasHalfPixel", (float*)&Vector(
101                0.5 / subEntity->prmxres, 0.5 / subEntity->prmyres, 0.0), 2);
102
103        if(subEntity->subMesh->lambertTexture)
104                effect->SetTexture("brdfMap", subEntity->subMesh->lambertTexture);
105        else
106                effect->SetTexture("brdfMap", pathMapEffect->emptyTexture);
107
108        effect->CommitChanges();
109}
110
111void FinalCompositionRenderStrategy::resetRenderState() const
112{
113        LPDIRECT3DDEVICE9 device = pathMapEffect->device;
114        device->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);
115        device->SetRenderState(D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE | D3DCOLORWRITEENABLE_ALPHA);
116}
117
Note: See TracBrowser for help on using the repository browser.