1 | #include "OgreCausticCubeMapRenderingRun.h"
|
---|
2 | //#include "OgreIlluminationManager.h"
|
---|
3 | #include "OgrePhotonMapRenderingRun.h"
|
---|
4 |
|
---|
5 |
|
---|
6 |
|
---|
7 | OgreCausticCubeMapRenderingRun::OgreCausticCubeMapRenderingRun(OgreSharedRuns* sharedRuns,
|
---|
8 | String name,
|
---|
9 | unsigned long startFrame,
|
---|
10 | unsigned long updateInterval,
|
---|
11 | unsigned int resolution,
|
---|
12 | String materialName,
|
---|
13 | unsigned char photonMapTexId,
|
---|
14 | bool updateAllFace,
|
---|
15 | float attenuation,
|
---|
16 | bool useTriangles,
|
---|
17 | bool blurMap)
|
---|
18 | :CausticCubeMapRenderingRun(startFrame, updateInterval, resolution, updateAllFace)
|
---|
19 | , OgreRenderingRun(startFrame, updateInterval)
|
---|
20 | , RenderingRun(startFrame, updateInterval)
|
---|
21 | {
|
---|
22 | this->attenuation = attenuation;
|
---|
23 | this->useTriangles = useTriangles;
|
---|
24 | this->sharedRuns = sharedRuns;
|
---|
25 | this->name = name;
|
---|
26 | this->materialName = materialName;
|
---|
27 | this->photonMapTexId = photonMapTexId;
|
---|
28 | this->blurMap = blurMap;
|
---|
29 |
|
---|
30 | spriteSetName = name + String("_pixelSpriteSet");
|
---|
31 |
|
---|
32 | createCausticCubeMap();
|
---|
33 | }
|
---|
34 |
|
---|
35 | void OgreCausticCubeMapRenderingRun::createCausticCubeMap()
|
---|
36 | {
|
---|
37 | causticCubemapTexture = createCubeRenderTexture(name,
|
---|
38 | Vector3(0,0,0),
|
---|
39 | resolution,
|
---|
40 | PF_FLOAT16_RGBA,
|
---|
41 | 0);
|
---|
42 |
|
---|
43 | if(blurMap)
|
---|
44 | bluredCausticCubemapTexture = createCubeRenderTexture(name + "_BLURED",
|
---|
45 | Vector3(0,0,0),
|
---|
46 | resolution,
|
---|
47 | PF_FLOAT16_RGBA,
|
---|
48 | 0);
|
---|
49 |
|
---|
50 | }
|
---|
51 |
|
---|
52 | void OgreCausticCubeMapRenderingRun::photonMapChanged(RenderingRun* run)
|
---|
53 | {
|
---|
54 | Material* mat = (Material*) MaterialManager::getSingleton().getByName(materialName).getPointer();
|
---|
55 | String photonMapName = ((OgrePhotonMapRenderingRun*) run->asOgreRenderingRun())->getPhotonMapTextureName();
|
---|
56 | mat->getTechnique(0)->getPass(0)->getTextureUnitState(photonMapTexId)->setTextureName(photonMapName);
|
---|
57 |
|
---|
58 | //rt = TextureManager::getSingleton().getByName(photonMapName);
|
---|
59 | LogManager::getSingleton().logMessage(LML_NORMAL, name + " map: " + photonMapName + " material: " + mat->getName());
|
---|
60 | }
|
---|
61 |
|
---|
62 | void OgreCausticCubeMapRenderingRun::updateCubeFace(int facenum)
|
---|
63 | {
|
---|
64 | RenderTarget* rt = causticCubemapTexture->getBuffer(facenum, 0).getPointer()
|
---|
65 | ->getRenderTarget();
|
---|
66 |
|
---|
67 | Camera* cam = rt->getViewport(0)->getCamera();
|
---|
68 | cam->setNearClipDistance(0.001);
|
---|
69 | cam->setFarClipDistance(2.0);
|
---|
70 | cam->setAspectRatio(1.0);
|
---|
71 | Radian r(Degree(90));
|
---|
72 | cam->setFOVy(r);
|
---|
73 |
|
---|
74 | RenderingRun* run = sharedRuns->getRun(ILLUMRUN_PHOTONMAP);
|
---|
75 | String photonMapName = ((OgrePhotonMapRenderingRun*) run->asOgreRenderingRun())->getPhotonMapTextureName();
|
---|
76 | TexturePtr tex = TextureManager::getSingleton().getByName(photonMapName);
|
---|
77 |
|
---|
78 | if(!useTriangles)
|
---|
79 | renderPixelSprites(materialName, rt, tex->getWidth(), tex->getHeight());
|
---|
80 | else
|
---|
81 | renderFullscreenGrid(materialName, rt, tex->getWidth(), tex->getHeight());
|
---|
82 |
|
---|
83 | if(blurMap)
|
---|
84 | {
|
---|
85 | rt = bluredCausticCubemapTexture->getBuffer(facenum, 0).getPointer()->getRenderTarget();
|
---|
86 | Material* mat = (Material*) MaterialManager::getSingleton().getByName("GameTools/BlurCubeFace").getPointer();
|
---|
87 | mat->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName(causticCubemapTexture->getName());
|
---|
88 | mat->getTechnique(0)->getPass(0)->getFragmentProgramParameters()->setNamedConstant("face", facenum);
|
---|
89 | renderFullscreenQuad("GameTools/BlurCubeFace", rt);
|
---|
90 | }
|
---|
91 |
|
---|
92 | //rt->writeContentsToFile("caucube" + this->name + StringConverter::toString(facenum) + ".dds");
|
---|
93 | }
|
---|
94 |
|
---|
95 | bool OgreCausticCubeMapRenderingRun::faceNeedsUpdate(int facenum)
|
---|
96 | {
|
---|
97 | return true;
|
---|
98 | }
|
---|