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

Revision 2249, 7.1 KB checked in by szirmay, 18 years ago (diff)
Line 
1#include "OgrePMWeightComputeRenderingRun.h"
2#include "OgreIlluminationManager.h"
3#include "OgrePMEntryPointMapRenderingRun.h"
4#include "OgreDepthShadowMapRenderingRun.h"
5
6OgrePMWeightComputeRenderingRun::OgrePMWeightComputeRenderingRun(String name, String LightName)
7                                                                                                                   : OgreRenderingRun(1, 1)
8                                                                                                                   , RenderingRun(1, 1)
9{
10        this->name = name;
11        weights = 0;
12       
13        this->light = Root::getSingleton()._getCurrentSceneManager()->getLight(LightName);
14        createWeightMap();
15
16        OgreIlluminationManager::getSingleton().createGlobalRun(ILLUMRUN_PM_ENTRYPOINTMAP);
17}
18
19void OgrePMWeightComputeRenderingRun::createWeightMap()
20{
21       
22        unsigned int entryPointCnt = OgreIlluminationManager::getSingleton().getPathMapEntryPoints().size();
23        int width = entryPointCnt / 4096;
24        int height = 4096;
25        TexturePtr texPtr = Ogre::TextureManager::getSingleton().createManual(name + "_ALL",
26                                                                                                                                                "default",
27                                                                                                                                                TEX_TYPE_2D,
28                                                                                                                                                width,
29                                                                                                                                                height,
30                                                                                                                                                0,
31                                                                                                                                                0,
32                                                                                                                                                PF_FLOAT32_R,
33                                                                                                                                                TU_RENDERTARGET);
34         allWeightsTexture = texPtr.getPointer();
35         //add viewport to rendertarget
36         HardwarePixelBuffer* hpb = (allWeightsTexture->getBuffer()).getPointer();
37         RenderTarget* rt = hpb->getRenderTarget();
38         Camera* wc = Root::getSingleton()._getCurrentSceneManager()->createCamera(name + "_ALL_CAMERA");
39         Viewport* v = rt->addViewport(wc);
40         v->setOverlaysEnabled(false);
41         rt->setAutoUpdated(false);
42
43        unsigned int clustercount = OgreIlluminationManager::getSingleton().getPathMapClusterLengthsSize();
44        width = clustercount;
45        height = 1;
46        texPtr = Ogre::TextureManager::getSingleton().createManual(name,
47                                                                                                                                "default",
48                                                                                                                                TEX_TYPE_2D,
49                                                                                                                                width,
50                                                                                                                                height,
51                                                                                                                                0,
52                                                                                                                                0,
53                                                                                                                                PF_FLOAT32_R,
54                                                                                                                                TU_RENDERTARGET);
55         weightTexture = texPtr.getPointer();
56         //add viewport to rendertarget
57         hpb = (weightTexture->getBuffer()).getPointer();
58         rt = hpb->getRenderTarget();
59         wc = Root::getSingleton()._getCurrentSceneManager()->createCamera(name + "_CAMERA");
60         v = rt->addViewport(wc);
61         v->setOverlaysEnabled(false);
62         rt->setAutoUpdated(false);
63}
64
65
66
67void OgrePMWeightComputeRenderingRun::updateFrame(unsigned long frameNum)
68{
69        OgreIlluminationManager::getSingleton().updateGlobalRun(ILLUMRUN_PM_ENTRYPOINTMAP, frameNum);
70        OgrePMEntryPointMapRenderingRun* PMEPrun = (OgrePMEntryPointMapRenderingRun*)
71                OgreIlluminationManager::getSingleton().getGlobalRun(ILLUMRUN_PM_ENTRYPOINTMAP)->asOgreRenderingRun();
72        unsigned int entryPointCnt = OgreIlluminationManager::getSingleton().getPathMapEntryPoints().size();
73        int col = entryPointCnt / 4096;
74               
75        if(light->getType() == Light::LT_SPOTLIGHT)
76        {
77                OgreIlluminationManager::getSingleton().createPerLightRun(light->getName(), ILLUMRUN_DEPTH_SHADOWMAP);
78                OgreIlluminationManager::getSingleton().updatePerLightRun(light->getName(), ILLUMRUN_DEPTH_SHADOWMAP, frameNum);
79                OgreDepthShadowMapRenderingRun* SMrun = (OgreDepthShadowMapRenderingRun*) OgreIlluminationManager::getSingleton()
80                        .getPerLightRun(light->getName(), ILLUMRUN_DEPTH_SHADOWMAP)->asOgreRenderingRun();
81               
82                MaterialPtr mat = MaterialManager::getSingleton().getByName("GTP/PathMap_ComputeWeights");
83                GpuProgramParameters* Fparams = mat->getTechnique(0)->getPass(0)->getFragmentProgramParameters().getPointer();
84                       
85                        Vector3 lightPos = light->getPosition();
86                        Vector3 lightDir = light->getDirection();
87                //      Radian lightAngle = light->getSpotlightOuterAngle();
88                       
89                        Fparams->setNamedConstant("nRadionColumns", col);
90                        Fparams->setNamedConstant("lightPos", lightPos);
91                        Fparams->setNamedConstant("lightDir", lightDir);
92                        Fparams->setNamedConstant("lightPower", light->getPowerScale());
93                        Fparams->setNamedConstant("lightViewProj", SMrun->getLightViewProjMatrix());
94                        Fparams->setNamedConstant("lightFarPlane", SMrun->getLightFarPlane());
95                       
96                        mat->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName(
97                                                PMEPrun->getEntryPointTextureName());
98                        mat->getTechnique(0)->getPass(0)->getTextureUnitState(1)->setTextureName(
99                                                SMrun->getDepthMapTextureName());
100                               
101                        RenderTarget* rt = allWeightsTexture->getBuffer().getPointer()->getRenderTarget();
102                        renderFullscreenQuad(mat->getName(), rt);
103
104                //      rt->writeContentsToFile("allweights.bmp");
105                //      rt->writeContentsToFile("allweights.dds");
106                       
107                /*      float* allweights = new float[entryPointCnt / 4096 * 4096];
108                        PixelBox lockBox(entryPointCnt / 4096, 4096, 1, PF_FLOAT32_R, allweights);
109                        allWeightsTexture->getBuffer()->blitToMemory(lockBox);
110
111                        ///////////////////DEBUG
112                        static BillboardSet* entryPointBBSet = 0;
113                        if(entryPointBBSet == 0)
114                        {
115                                SceneManager* sm = Root::getSingleton()._getCurrentSceneManager();
116                                entryPointBBSet = sm->createBillboardSet("PATHMAP_ENTRYPOINTS", entryPointCnt);
117                                entryPointBBSet->setBillboardType(BBT_POINT);
118                                entryPointBBSet->setBillboardsInWorldSpace(true);
119                                entryPointBBSet->setPointRenderingEnabled(true);
120                                for(unsigned int i = 0; i < entryPointCnt; i++)
121                                {
122                                        PathMapEntryPoint EP = OgreIlluminationManager::getSingleton().getPathMapEntryPoints().at(i);
123                                        Vector3 billboardPosition = EP.position;
124                                       
125                                        float uCoord = allweights[i];
126                                        float  vCoord = 0;
127                                        //float uCoord = ((float) (i % col) + 0.5f) / (float) col;
128                                        //float vCoord = ((float)(i / col) + 0.5f) / 4096.0f;
129                                        entryPointBBSet->createBillboard(billboardPosition, ColourValue(uCoord, vCoord, 0, 0));
130                                }
131                                entryPointBBSet->setMaterialName("GTP/PM/EPBillboards");
132                                MaterialPtr mater = MaterialManager::getSingleton().getByName("GTP/PM/EPBillboards");
133                                mater->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName(allWeightsTexture->getName());
134                                sm->getRootSceneNode()->createChildSceneNode()->attachObject(entryPointBBSet);
135                        }
136
137                        delete[] allweights;*/
138
139/////////////////
140        }
141        else
142        {
143                ///not implemented
144        }
145
146        unsigned int clustercount = OgreIlluminationManager::getSingleton().getPathMapClusterLengthsSize();
147
148        MaterialPtr mat = MaterialManager::getSingleton().getByName("GTP/PathMap_SumWeights");
149        GpuProgramParameters* Fparams = mat->getTechnique(0)->getPass(0)->getFragmentProgramParameters().getPointer();
150        Fparams->setNamedConstant("nRadionColumns", col);
151        Fparams->setNamedConstant("clusterCount", (float) clustercount);
152        mat->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName(
153                                                PMEPrun->getEntryPointTextureName());
154        mat->getTechnique(0)->getPass(0)->getTextureUnitState(1)->setTextureName(
155                                                PMEPrun->getClusterLengthTextureName());
156        mat->getTechnique(0)->getPass(0)->getTextureUnitState(2)->setTextureName(
157                                                allWeightsTexture->getName());
158       
159        RenderTarget* rt = weightTexture->getBuffer().getPointer()->getRenderTarget();
160        renderFullscreenQuad(mat->getName(), rt);
161
162        //rt->writeContentsToFile("weights.bmp");       
163        //rt->writeContentsToFile("weights.dds");
164/*
165        float* weights = new float[clustercount];
166        PixelBox lockBox(clustercount, 1, 1, PF_FLOAT32_R, weights);
167        weightTexture->getBuffer()->blitToMemory(lockBox);
168
169        delete[] weights;*/
170}
171
172
Note: See TracBrowser for help on using the repository browser.