source: GTP/branches/IllumWPdeliver2008dec/IlluminationWP/demos/Standalone/PathMap [DirectX]/FinalCompositionRenderStrategy.cpp @ 3255

Revision 3255, 4.7 KB checked in by szirmay, 16 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, -pathMapEffect->parameters->Get(fTorchDistance), -pathMapEffect->parameters->Get(fTorchDistance), 0.0);
56//      D3DXMatrixTranslation(&torchMatrix, 0.0, 0.0, pathMapEffect->parameters->Get(fTorchDistance));
57
58        effect->SetFloatArray("occProjToTexMatrix", opttme, 9);
59        effect->SetMatrix("occWorldToProjMatrix", &(*pathMapEffect->lightCamera->GetViewMatrix() * *pathMapEffect->lightCamera->GetProjMatrix()));
60       
61
62        effect->SetTexture("depthMap", pathMapEffect->depthMapTexture);
63
64        effect->SetFloatArray("lightPower", (float*)&lightPower, 3);
65        effect->SetFloatArray("lightPos", (float*)&lightPos, 3);
66        effect->SetFloatArray("lightDir", (float*)&lightDir, 3);
67
68        if(pathMapEffect->parameters->Get(bLookFromLight))
69        {
70                if(pathMapEffect->parameters->Get(bCruise))
71                                                effect->SetMatrix("modelToProjMatrix",
72                                &( entity->modelWorldTransform * pathMapEffect->shipPosInverse * torchMatrix * *pathMapEffect->lightCamera->GetProjMatrix() ) );
73                else
74                        effect->SetMatrix("modelToProjMatrix",
75                                &( entity->modelWorldTransform * *pathMapEffect->lightCamera->GetViewMatrix() * torchMatrix * *pathMapEffect->lightCamera->GetProjMatrix() ) );
76        }
77        else
78                effect->SetMatrix("modelToProjMatrix",
79                        &( entity->modelWorldTransform * *pathMapEffect->camera->GetViewMatrix() * *pathMapEffect->camera->GetProjMatrix() ) );
80
81        effect->SetMatrix("modelToWorldMatrix", &entity->modelWorldTransform);
82        effect->SetMatrix("inverseTransposedModelToWorldMatrix", &entity->inverseTransposedModelWorldTransform);
83}
84
85void FinalCompositionRenderStrategy::applyTextures(SubEntity* subEntity) const
86{
87        LPD3DXEFFECT effect = pathMapEffect->effect;
88
89        // nearestIdx -> bushId
90        static float weightsa[256]; // = new float[entityIterator->nNearClusters];
91        for(unsigned int y=0; y<subEntity->nNearClusters; y++)
92        {
93//              Entity e = *entityIterator;
94                weightsa[y] = pathMapEffect->weights[subEntity->nearClusterIndices[y]];
95        }
96        HRESULT hr = effect->SetFloatArray("weightsa", weightsa, subEntity->nNearClusters);
97       
98        effect->SetTexture("filteredAtlas", subEntity->prmTexture);
99        if(subEntity->subMesh->bumpTexture)
100                effect->SetTexture("bumpMap", subEntity->subMesh->bumpTexture);
101        if(subEntity->subMesh->normalTexture)
102                effect->SetTexture("normalMap", subEntity->subMesh->normalTexture);
103
104        int prmAtlasSize = subEntity->subMesh->parent->prmAtlasSize;
105        int prmnt[2] = {subEntity->prmxres / prmAtlasSize, subEntity->prmyres / prmAtlasSize};
106
107        effect->SetIntArray("prmAtlasTiles", prmnt, 2);
108        effect->SetFloatArray("atlasHalfPixel", (float*)&Vector(
109                0.5 / subEntity->prmxres, 0.5 / subEntity->prmyres, 0.0), 2);
110
111        if(subEntity->subMesh->lambertTexture)
112                effect->SetTexture("brdfMap", subEntity->subMesh->lambertTexture);
113        else
114                effect->SetTexture("brdfMap", pathMapEffect->emptyTexture);
115
116        effect->CommitChanges();
117}
118
119void FinalCompositionRenderStrategy::resetRenderState() const
120{
121        LPDIRECT3DDEVICE9 device = pathMapEffect->device;
122        device->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);
123        device->SetRenderState(D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE | D3DCOLORWRITEENABLE_ALPHA);
124}
125
Note: See TracBrowser for help on using the repository browser.