source: GTP/branches/IllumWPdeliver2008dec/IlluminationWP/source/OgreIllumModule/src/RenderingRuns/OgrePMEntryPointMapRenderingRun.cpp @ 3255

Revision 3255, 3.9 KB checked in by szirmay, 15 years ago (diff)
Line 
1#include "OgrePMEntryPointMapRenderingRun.h"
2#include "OgreIlluminationManager.h"
3
4OgrePMEntryPointMapRenderingRun::OgrePMEntryPointMapRenderingRun(String name)
5                                                                                                                   : OgreRenderingRun(1, 1)
6                                                                                                                   , RenderingRun(1, 1)
7{
8        this->name = name;
9       
10        createEntryPointMap(); 
11}
12
13void OgrePMEntryPointMapRenderingRun::createEntryPointMap()
14{
15        unsigned int entryPointCnt = OgreIlluminationManager::getSingleton().getPathMapEntryPoints().size();
16        int width = entryPointCnt / 4096 * 2;
17        int height = 4096;
18        TexturePtr texPtr = Ogre::TextureManager::getSingleton().createManual(name,
19                                                                                                                                                "default",
20                                                                                                                                                TEX_TYPE_2D,
21                                                                                                                                                width,
22                                                                                                                                                height,
23                                                                                                                                                0,
24                                                                                                                                                0,
25                                                                                                                                                PF_FLOAT32_RGBA,
26                                                                                                                                                TU_DEFAULT);
27        entryPointTexture = texPtr.getPointer();
28       
29        struct TMR
30        {
31                float pos[4];
32                float dir[4];
33        };
34        TMR* tm = new TMR[entryPointCnt];
35        for(int i=0; i<entryPointCnt; i++)
36        {
37                PathMapEntryPoint* EP = &OgreIlluminationManager::getSingleton().getPathMapEntryPoints().at(i);
38                tm[i].pos[0] = EP->position.x;
39                tm[i].pos[1] = EP->position.y;
40                tm[i].pos[2] = EP->position.z;
41                tm[i].pos[3] = 1.0;
42                tm[i].dir[0] = EP->normal.x;
43                tm[i].dir[1] = EP->normal.y;
44                tm[i].dir[2] = EP->normal.z;
45                tm[i].dir[3] = EP->prob;
46        }       
47
48        PixelBox lockBox(width, height, 1, PF_FLOAT32_RGBA, tm);
49        entryPointTexture->getBuffer()->blitFromMemory(lockBox);
50
51        delete[] tm;
52
53        int clusterCount = OgreIlluminationManager::getSingleton().getPathMapClusterLengthsSize();
54        width = clusterCount;
55        height = 2;
56        texPtr = Ogre::TextureManager::getSingleton().createManual(name + "_CL",
57                                                                                                                                                "default",
58                                                                                                                                                TEX_TYPE_2D,
59                                                                                                                                                width,
60                                                                                                                                                height,
61                                                                                                                                                0,
62                                                                                                                                                0,
63                                                                                                                                                PF_FLOAT32_R,
64                                                                                                                                                TU_RENDERTARGET);
65        clusterLengthTexture = texPtr.getPointer();
66
67        float* data = new float[clusterCount * 2];
68        unsigned int clusterStartEntryPoint = 0;
69        for(int i = 0; i < clusterCount; i++)
70        {
71                unsigned int clusterSize = OgreIlluminationManager::getSingleton().getPathMapClusterLength(i);
72                data[i] = clusterSize;//clustercount
73                data[clusterCount + i] = clusterStartEntryPoint;
74                for(int j = 0; j < clusterSize; j++)
75                {
76                        PathMapEntryPoint* EP = &OgreIlluminationManager::getSingleton().getPathMapEntryPoints().at(clusterStartEntryPoint + j);
77                        EP->clusterID = i;
78                }
79                clusterStartEntryPoint += clusterSize;
80        }
81
82        PixelBox lockBox2(width, height, 1, PF_FLOAT32_R, data);
83        clusterLengthTexture->getBuffer()->blitFromMemory(lockBox2);
84
85        delete[] data;
86
87        if(false)
88        {
89                SceneManager* sm = Root::getSingleton()._getCurrentSceneManager();
90                BillboardSet* bbs = sm->createBillboardSet("WEIGHT_DEBUG", 4096);
91                bbs->setDefaultDimensions(0.1, 0.1);
92                for(int i= 0; i < entryPointCnt;i++)
93                {
94                  PathMapEntryPoint* EP = &OgreIlluminationManager::getSingleton().getPathMapEntryPoints().at(i);
95                  int r = i / 256;
96                  int g = i - r * 256;
97                  float rr = (float) r / 256.0;
98                  float gg = (float) g / 256.0;
99                 
100                  ColourValue c;                 
101                  c = ColourValue(rr, gg, 0);
102                  /*c = ColourValue(
103                          Math::Ceil(Math::Floor(EP->position.x)),
104                          Math::Ceil(Math::Floor(EP->position.y)),
105                          Math::Ceil(Math::Floor(EP->position.z)));*/
106                  //c = ColourValue(0,0,1,0);
107                  bbs->createBillboard(Vector3(EP->position.x, i, EP->position.z), c);
108                }
109                bbs->setPointRenderingEnabled(true);
110                bbs->setMaterialName("GTP/PM/EPBillboards");
111                sm->getRootSceneNode()->createChildSceneNode("WEIGHT_DEBUG_SN")->attachObject(bbs);
112        }
113}
114
115void OgrePMEntryPointMapRenderingRun::updateFrame(unsigned long frameNum)
116{       
117       
118}
119
120void OgrePMEntryPointMapRenderingRun::freeAllResources()
121{
122        this->entryPointTexture = 0;
123        this->clusterLengthTexture = 0;
124        TextureManager::getSingleton().remove(name);
125        TextureManager::getSingleton().remove(name + "_CL");   
126}
127
128
129
Note: See TracBrowser for help on using the repository browser.