1 | #include "OgreReducedCubeMapRenderingRun.h"
|
---|
2 | #include "OgreIlluminationManager.h"
|
---|
3 |
|
---|
4 |
|
---|
5 |
|
---|
6 | OgreReducedCubeMapRenderingRun::OgreReducedCubeMapRenderingRun(OgreSharedRuns* sharedRuns,
|
---|
7 | String name,
|
---|
8 | unsigned long startFrame,
|
---|
9 | unsigned long updateInterval,
|
---|
10 | unsigned int resolution,
|
---|
11 | bool useDistCalc,
|
---|
12 | bool useFaceAngleCalc,
|
---|
13 | float distTolerance,
|
---|
14 | float angleTolerance,
|
---|
15 | bool updateAllFace)
|
---|
16 | :ReducedCubeMapRenderingRun(startFrame, updateInterval, resolution, useDistCalc, useFaceAngleCalc, distTolerance, angleTolerance, updateAllFace)
|
---|
17 | , OgreRenderingRun(startFrame, updateInterval)
|
---|
18 | , RenderingRun(startFrame, updateInterval)
|
---|
19 | {
|
---|
20 | this->sharedRuns = sharedRuns;
|
---|
21 | this->name = name;
|
---|
22 |
|
---|
23 | createReducedCubeMap();
|
---|
24 | }
|
---|
25 |
|
---|
26 | void OgreReducedCubeMapRenderingRun::createReducedCubeMap()
|
---|
27 | {
|
---|
28 | reducedCubemapTexture = createCubeRenderTexture(name,
|
---|
29 | sharedRuns->getRootPosition(),
|
---|
30 | resolution,
|
---|
31 | PF_FLOAT16_RGBA);
|
---|
32 | }
|
---|
33 |
|
---|
34 | void OgreReducedCubeMapRenderingRun::updateCubeFace(int facenum)
|
---|
35 | {
|
---|
36 | RenderTarget* rt = reducedCubemapTexture->getBuffer(facenum, 0).getPointer()
|
---|
37 | ->getRenderTarget();
|
---|
38 |
|
---|
39 | Material* mat = (Material*) MaterialManager::getSingleton().getByName("GameTools/CubeMap/Reduce").getPointer();
|
---|
40 | GpuProgramParametersSharedPtr fpParams = mat->getTechnique(0)->getPass(0)->getFragmentProgramParameters();
|
---|
41 | fpParams->setNamedConstant("nFace",facenum);
|
---|
42 | // mat->getTechnique(0)->getPass(0)->setFragmentProgramParameters(fpParams);
|
---|
43 |
|
---|
44 | renderFullscreenQuad("GameTools/CubeMap/Reduce", rt);
|
---|
45 |
|
---|
46 | //rt->writeContentsToFile("cubbereduce" + StringConverter::toString(facenum) + ".dds");
|
---|
47 | }
|
---|
48 |
|
---|
49 | bool OgreReducedCubeMapRenderingRun::faceNeedsUpdate(int facenum)
|
---|
50 | {
|
---|
51 | if(useDistCalc || useFaceAngleCalc)
|
---|
52 | {
|
---|
53 | float chance1 = 1.0;
|
---|
54 | float chance2 = 1.0;
|
---|
55 |
|
---|
56 | Camera* mainCamera = OgreIlluminationManager::getSingleton().getMainCamera();
|
---|
57 |
|
---|
58 | if(useDistCalc)
|
---|
59 | {
|
---|
60 | Vector3 cubemapPosition = sharedRuns->getRootPosition(ILLUMRUN_REDUCED_CUBEMAP);
|
---|
61 | float objradius = sharedRuns->getRootBoundingSphere(ILLUMRUN_REDUCED_CUBEMAP).getRadius();
|
---|
62 | float fov = mainCamera->getFOVy().valueRadians() / 2.0;
|
---|
63 | float dist = (cubemapPosition - mainCamera->getPosition()).length();
|
---|
64 | float vangle = Math::ASin( objradius / dist).valueRadians();
|
---|
65 | float angleratio = vangle / fov;
|
---|
66 | chance1 = Math::Pow(angleratio, 1.0 / distTolerance);
|
---|
67 | }
|
---|
68 |
|
---|
69 | if(useFaceAngleCalc)
|
---|
70 | {
|
---|
71 | Vector3 faceDir = getCubeMapFaceDirection(facenum);
|
---|
72 | Vector3 cameraDir = mainCamera->getDirection();
|
---|
73 | float angle = faceDir.dotProduct(-1 * cameraDir);
|
---|
74 | float facingforward = (angle + 1) / 2.0;
|
---|
75 | chance2 = Math::Pow(facingforward, 1.0 / angleTolerance);
|
---|
76 | }
|
---|
77 |
|
---|
78 | float dice = Math::UnitRandom();
|
---|
79 | float chance = chance1 * chance2;
|
---|
80 |
|
---|
81 | if(dice < chance)
|
---|
82 | {
|
---|
83 | return true;
|
---|
84 | }
|
---|
85 | else
|
---|
86 | {
|
---|
87 | return false;
|
---|
88 | }
|
---|
89 | }
|
---|
90 |
|
---|
91 | return true;
|
---|
92 | }
|
---|
93 |
|
---|
94 | void OgreReducedCubeMapRenderingRun::colorCubeMapChanged(String& newMapName)
|
---|
95 | {
|
---|
96 | Material* mat = (Material*) MaterialManager::getSingleton().getByName("GameTools/CubeMap/Reduce").getPointer();
|
---|
97 | mat->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName(newMapName);
|
---|
98 | /*
|
---|
99 | Texture* tex = (Texture*) TextureManager::getSingleton().getByName(newMapName).getPointer();
|
---|
100 | int resolution = tex->getWidth();
|
---|
101 |
|
---|
102 | GpuProgramParametersSharedPtr fpParams = mat->getTechnique(0)->getPass(0)->getFragmentProgramParameters();
|
---|
103 | fpParams->setNamedConstant("CUBEMAP_SIZE", resolution );
|
---|
104 | mat->getTechnique(0)->getPass(0)->setFragmentProgramParameters(fpParams); */
|
---|
105 |
|
---|
106 | }
|
---|