1 | #include "OgreDepthShadowRecieverRenderTechnique.h"
|
---|
2 | #include "OgreTechniqueGroup.h"
|
---|
3 | #include "OgreIlluminationManager.h"
|
---|
4 | #include "OgreDepthShadowMapRenderingRun.h"
|
---|
5 |
|
---|
6 | OgreDepthShadowRecieverRenderTechnique::OgreDepthShadowRecieverRenderTechnique(
|
---|
7 | int maxlights,
|
---|
8 | String shadowVertexProgram,
|
---|
9 | String shadowFragmentProgram,
|
---|
10 | Pass* pass,
|
---|
11 | OgreRenderable* parentRenderable,
|
---|
12 | OgreTechniqueGroup* parentTechniqueGroup)
|
---|
13 | :RenderTechnique( parentRenderable, parentTechniqueGroup),
|
---|
14 | OgreRenderTechnique(pass, parentRenderable, parentTechniqueGroup),
|
---|
15 | DepthShadowRecieverRenderTechnique(parentRenderable, parentTechniqueGroup)
|
---|
16 | {
|
---|
17 | this->maxlights = maxlights;
|
---|
18 | this->shadowVertexProgram = shadowVertexProgram ;
|
---|
19 | this->shadowFragmentProgram = shadowFragmentProgram;
|
---|
20 |
|
---|
21 |
|
---|
22 | //insert new passes
|
---|
23 | Ogre::Technique* techn = pass->getParent();
|
---|
24 | Technique::PassIterator it = techn->getPassIterator();
|
---|
25 |
|
---|
26 | int index = 0;
|
---|
27 | while(it.hasMoreElements())
|
---|
28 | {
|
---|
29 | if( it.getNext() == pass)
|
---|
30 | break;
|
---|
31 | index++;
|
---|
32 | it.moveNext();
|
---|
33 | }
|
---|
34 |
|
---|
35 | index++;
|
---|
36 | for(int i = 0; i < maxlights; i++)
|
---|
37 | {
|
---|
38 | int lastpass = techn->getNumPasses();
|
---|
39 | Pass* newpass = techn->createPass();
|
---|
40 | passes.push_back(newpass);
|
---|
41 |
|
---|
42 | newpass->setVertexProgram(shadowVertexProgram);
|
---|
43 | newpass->setFragmentProgram(shadowFragmentProgram);
|
---|
44 |
|
---|
45 | GpuProgramParameters* Vparams = newpass->getVertexProgramParameters().getPointer();
|
---|
46 | Vparams->setNamedAutoConstant("worldViewProj",
|
---|
47 | GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX);
|
---|
48 | Vparams->setNamedAutoConstant("world",
|
---|
49 | GpuProgramParameters::ACT_WORLD_MATRIX);
|
---|
50 | GpuProgramParameters* Fparams = newpass->getFragmentProgramParameters().getPointer();
|
---|
51 |
|
---|
52 | TextureUnitState* st = newpass->createTextureUnitState();
|
---|
53 | st->setTextureFiltering(TFO_BILINEAR);
|
---|
54 |
|
---|
55 | newpass->setSceneBlending(SBT_MODULATE);
|
---|
56 |
|
---|
57 | techn->movePass(lastpass, index);
|
---|
58 | }
|
---|
59 |
|
---|
60 | }
|
---|
61 |
|
---|
62 | OgreDepthShadowRecieverRenderTechnique::~OgreDepthShadowRecieverRenderTechnique()
|
---|
63 | {
|
---|
64 |
|
---|
65 | }
|
---|
66 |
|
---|
67 | void OgreDepthShadowRecieverRenderTechnique::update(unsigned long frameNum)
|
---|
68 | {
|
---|
69 | LightList lights;
|
---|
70 | Root::getSingleton()._getCurrentSceneManager()->_populateLightList(
|
---|
71 | ((OgreSharedRuns*) sharedRuns)->getRootPosition(),
|
---|
72 | 100000.0,
|
---|
73 | lights);
|
---|
74 |
|
---|
75 | //fill passes
|
---|
76 | for(unsigned int i = 0; i < passes.size(); i++)
|
---|
77 | {
|
---|
78 | if(lights.size() > i)
|
---|
79 | {
|
---|
80 | //create run if not exists
|
---|
81 | OgreIlluminationManager::getSingleton().createPerLightRun(lights.at(i)->getName(),
|
---|
82 | ILLUMRUN_DEPTH_SHADOWMAP);
|
---|
83 | //update light depth map
|
---|
84 | OgreIlluminationManager::getSingleton().updatePerLightRun(lights.at(i)->getName(),
|
---|
85 | ILLUMRUN_DEPTH_SHADOWMAP,
|
---|
86 | frameNum);
|
---|
87 |
|
---|
88 | //set texture to pass
|
---|
89 | OgreDepthShadowMapRenderingRun* depthRun =
|
---|
90 | (OgreDepthShadowMapRenderingRun*) OgreIlluminationManager::getSingleton()
|
---|
91 | .getPerLightRun(lights.at(i)->getName(),
|
---|
92 | ILLUMRUN_DEPTH_SHADOWMAP)->asOgreRenderingRun();
|
---|
93 |
|
---|
94 | passes.at(i)->getTextureUnitState(0)->setTextureName(
|
---|
95 | depthRun->getDepthMapTextureName());
|
---|
96 |
|
---|
97 | //TODO: set matrices
|
---|
98 | GpuProgramParametersSharedPtr fpParams = passes.at(i)->getFragmentProgramParameters();
|
---|
99 | fpParams->setNamedConstant("lightView", depthRun->getLightViewMatrix());
|
---|
100 | fpParams->setNamedConstant("lightViewProj", depthRun->getLightViewProjMatrix());
|
---|
101 |
|
---|
102 | passes.at(i)->setActive(true);
|
---|
103 | }
|
---|
104 | else
|
---|
105 | passes.at(i)->setActive(false);
|
---|
106 |
|
---|
107 | }
|
---|
108 | }
|
---|
109 |
|
---|