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

Revision 2218, 7.1 KB checked in by szirmay, 17 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("lightViewProj", SMrun->getLightViewProjMatrix());
93                        Fparams->setNamedConstant("lightFarPlane", SMrun->getLightFarPlane());
94                       
95                        mat->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName(
96                                                PMEPrun->getEntryPointTextureName());
97                        mat->getTechnique(0)->getPass(0)->getTextureUnitState(1)->setTextureName(
98                                                SMrun->getDepthMapTextureName());
99                               
100                        RenderTarget* rt = allWeightsTexture->getBuffer().getPointer()->getRenderTarget();
101                        renderFullscreenQuad(mat->getName(), rt);
102
103                //      rt->writeContentsToFile("allweights.bmp");
104                //      rt->writeContentsToFile("allweights.dds");
105                       
106                /*      float* allweights = new float[entryPointCnt / 4096 * 4096];
107                        PixelBox lockBox(entryPointCnt / 4096, 4096, 1, PF_FLOAT32_R, allweights);
108                        allWeightsTexture->getBuffer()->blitToMemory(lockBox);
109
110                        ///////////////////DEBUG
111                        static BillboardSet* entryPointBBSet = 0;
112                        if(entryPointBBSet == 0)
113                        {
114                                SceneManager* sm = Root::getSingleton()._getCurrentSceneManager();
115                                entryPointBBSet = sm->createBillboardSet("PATHMAP_ENTRYPOINTS", entryPointCnt);
116                                entryPointBBSet->setBillboardType(BBT_POINT);
117                                entryPointBBSet->setBillboardsInWorldSpace(true);
118                                entryPointBBSet->setPointRenderingEnabled(true);
119                                for(unsigned int i = 0; i < entryPointCnt; i++)
120                                {
121                                        PathMapEntryPoint EP = OgreIlluminationManager::getSingleton().getPathMapEntryPoints().at(i);
122                                        Vector3 billboardPosition = EP.position;
123                                       
124                                        float uCoord = allweights[i];
125                                        float  vCoord = 0;
126                                        //float uCoord = ((float) (i % col) + 0.5f) / (float) col;
127                                        //float vCoord = ((float)(i / col) + 0.5f) / 4096.0f;
128                                        entryPointBBSet->createBillboard(billboardPosition, ColourValue(uCoord, vCoord, 0, 0));
129                                }
130                                entryPointBBSet->setMaterialName("GTP/PM/EPBillboards");
131                                MaterialPtr mater = MaterialManager::getSingleton().getByName("GTP/PM/EPBillboards");
132                                mater->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName(allWeightsTexture->getName());
133                                sm->getRootSceneNode()->createChildSceneNode()->attachObject(entryPointBBSet);
134                        }
135
136                        delete[] allweights;*/
137
138/////////////////
139        }
140        else
141        {
142                ///not implemented
143        }
144
145        unsigned int clustercount = OgreIlluminationManager::getSingleton().getPathMapClusterLengthsSize();
146
147        MaterialPtr mat = MaterialManager::getSingleton().getByName("GTP/PathMap_SumWeights");
148        GpuProgramParameters* Fparams = mat->getTechnique(0)->getPass(0)->getFragmentProgramParameters().getPointer();
149        Fparams->setNamedConstant("nRadionColumns", col);
150        Fparams->setNamedConstant("clusterCount", (float) clustercount);
151        mat->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName(
152                                                PMEPrun->getEntryPointTextureName());
153        mat->getTechnique(0)->getPass(0)->getTextureUnitState(1)->setTextureName(
154                                                PMEPrun->getClusterLengthTextureName());
155        mat->getTechnique(0)->getPass(0)->getTextureUnitState(2)->setTextureName(
156                                                allWeightsTexture->getName());
157       
158        RenderTarget* rt = weightTexture->getBuffer().getPointer()->getRenderTarget();
159        renderFullscreenQuad(mat->getName(), rt);
160
161        //rt->writeContentsToFile("weights.bmp");       
162        //rt->writeContentsToFile("weights.dds");
163/*
164        float* weights = new float[clustercount];
165        PixelBox lockBox(clustercount, 1, 1, PF_FLOAT32_R, weights);
166        weightTexture->getBuffer()->blitToMemory(lockBox);
167
168        delete[] weights;*/
169}
170
171
Note: See TracBrowser for help on using the repository browser.