source: GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgrePMWeightComputeRenderingRun.cpp @ 2189

Revision 2189, 3.9 KB checked in by szirmay, 17 years ago (diff)
Line 
1#include "OgrePMWeightComputeRenderingRun.h"
2#include "OgreIlluminationManager.h"
3#include "OgrePMEntryPointMapRenderingRun.h"
4
5OgrePMWeightComputeRenderingRun::OgrePMWeightComputeRenderingRun(String name, String LightName)
6                                                                                                                   : OgreRenderingRun(1, 1)
7                                                                                                                   , RenderingRun(1, 1)
8{
9        this->name = name;
10        weights = 0;
11       
12        this->light = Root::getSingleton()._getCurrentSceneManager()->getLight(LightName);
13        createWeightMap();
14
15        OgreIlluminationManager::getSingleton().createGlobalRun(ILLUMRUN_PM_ENTRYPOINTMAP);
16}
17
18void OgrePMWeightComputeRenderingRun::createWeightMap()
19{
20       
21        unsigned int entryPointCnt = OgreIlluminationManager::getSingleton().getPathMapEntryPoints().size();
22        int width = entryPointCnt / 4096;
23        int height = 4096;
24        TexturePtr texPtr = Ogre::TextureManager::getSingleton().createManual(name,
25                                                                                                                                                "default",
26                                                                                                                                                TEX_TYPE_2D,
27                                                                                                                                                width,
28                                                                                                                                                height,
29                                                                                                                                                0,
30                                                                                                                                                0,
31                                                                                                                                                PF_FLOAT32_R,
32                                                                                                                                                TU_RENDERTARGET);
33         weightTexture = texPtr.getPointer();
34         //add viewport to rendertarget
35         HardwarePixelBuffer* hpb = (weightTexture->getBuffer()).getPointer();
36         RenderTarget* rt = hpb->getRenderTarget();
37         Camera* wc = Root::getSingleton()._getCurrentSceneManager()->createCamera(name + "_CAMERA");
38         Viewport* v = rt->addViewport(wc);
39         v->setOverlaysEnabled(false);
40         rt->setAutoUpdated(false);
41}
42
43
44
45void OgrePMWeightComputeRenderingRun::updateFrame(unsigned long frameNum)
46{
47        switch(light->getType())
48        {
49                case Light::LT_SPOTLIGHT:
50
51                        MaterialPtr mat = MaterialManager::getSingleton().getByName("GTP/PathMap_ComputeWeights");
52
53                        GpuProgramParameters* Fparams = mat->getTechnique(0)->getPass(0)->getFragmentProgramParameters().getPointer();
54                       
55                        Vector3 lightPos = light->getPosition();
56                        Vector3 lightDir = light->getDirection();
57                //      Radian lightAngle = light->getSpotlightOuterAngle();
58                        unsigned int entryPointCnt = OgreIlluminationManager::getSingleton().getPathMapEntryPoints().size();
59                        int col = entryPointCnt / 4096;
60
61                        //Fparams->setNamedConstant("lightTransform", lightMatrix);
62                        Fparams->setNamedConstant("nRadionColumns", col);
63                        Fparams->setNamedConstant("lightPos", lightPos);
64                        Fparams->setNamedConstant("lightDir", lightDir);
65
66                        OgrePMEntryPointMapRenderingRun* PMEPrun = (OgrePMEntryPointMapRenderingRun*)
67                                        OgreIlluminationManager::getSingleton().getGlobalRun(ILLUMRUN_PM_ENTRYPOINTMAP)->asOgreRenderingRun();
68                        mat->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName(
69                                                PMEPrun->getEntryPointTextureName());
70                               
71                        RenderTarget* rt = weightTexture->getBuffer().getPointer()->getRenderTarget();
72                        renderFullscreenQuad(mat->getName(), rt);
73
74                        //rt->writeContentsToFile("focusingmap.dds");
75               
76               
77                        break;         
78        }
79
80        unsigned int clustercount = OgreIlluminationManager::getSingleton().getPathMapClusterLengthsSize();
81        if(weights == 0)
82                weights = new float[clustercount];
83       
84        unsigned int entryPointCnt = OgreIlluminationManager::getSingleton().getPathMapEntryPoints().size();
85        int width = entryPointCnt / 4096;
86        int height = 4096;
87        unsigned int buffersize = width * height;
88        float* allEntryWeights = new float[buffersize];
89        PixelBox lockBox(width, height, 1, PF_FLOAT32_R, allEntryWeights);
90        weightTexture->getBuffer()->blitToMemory(lockBox);     
91
92        int iRadion = 0;
93        for(int iCluster=0; iCluster < clustercount; iCluster++)
94        {
95                weights[iCluster] = 0.0;
96                for(int clusterSummer=0;
97                        clusterSummer < OgreIlluminationManager::getSingleton().getPathMapClusterLength(iCluster);
98                        clusterSummer++, iRadion++)
99                {
100                        weights[iCluster] += allEntryWeights[iRadion];                 
101                }
102                if(weights[iCluster] <= 0)
103                        weights[iCluster] /= OgreIlluminationManager::getSingleton().getPathMapClusterLength(iCluster); //(double)clusterLenghts[iCluster];
104                else
105                        weights[iCluster] = 0.0f;               
106        }
107}
108
109
Note: See TracBrowser for help on using the repository browser.