SO3Engine
SO3DeferredLightAmbient.cpp
Go to the documentation of this file.
1/*
2-----------------------------------------------------------------------------
3This source file is part of OpenSpace3D
4For the latest info, see http://www.openspace3d.com
5
6Copyright (c) 2012 I-maginer
7
8This program is free software; you can redistribute it and/or modify it under
9the terms of the GNU Lesser General Public License as published by the Free Software
10Foundation; either version 2 of the License, or (at your option) any later
11version.
12
13This program is distributed in the hope that it will be useful, but WITHOUT
14ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public License along with
18this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19Place - Suite 330, Boston, MA 02111-1307, USA, or go to
20http://www.gnu.org/copyleft/lesser.txt
21
22-----------------------------------------------------------------------------
23*/
24
28#include "OgreMaterialManager.h"
29#include "OgreRoot.h"
30#include "OgreRenderSystem.h"
31
32namespace SO3
33{
34
35SDeferredLightAmbient::SDeferredLightAmbient(SDeferredLightMaterialGenerator* typeLightMaterialGenerator)
36{
37 ambientLightMaterialGenerator = typeLightMaterialGenerator;
38 setRenderQueueGroup(Ogre::RENDER_QUEUE_2);
39
40 mRenderOp.vertexData = new Ogre::VertexData();
41 mRenderOp.indexData = 0;
42
43 SBaseMeshsTools::CreateQuad(mRenderOp.vertexData);
44 mRenderOp.operationType = Ogre::RenderOperation::OT_TRIANGLE_STRIP;
45 mRenderOp.useIndexes = false;
46
47 // Set bounding
48 setBoundingBox(Ogre::AxisAlignedBox(-10000,-10000,-10000,10000,10000,10000));
49 radius = 15000;
50
51 //TODO This shader needs to be aware if its running under OpenGL or DirectX.
52 //Real depthFactor = (Root::getSingleton().getRenderSystem()->getName() ==
53 // "OpenGL Rendering Subsystem") ? 2.0 : 1.0;
54 //mMatPtr->getTechnique(0)->getPass(0)->getFragmentProgramParameters()->setNamedConstant(
55 // "depthFactor", depthFactor);
56}
57
59{
60 // need to release IndexData and vertexData created for renderable
61 delete mRenderOp.indexData;
62 delete mRenderOp.vertexData;
63}
64
66{
67 return radius;
68}
69
70Ogre::Real SDeferredLightAmbient::getSquaredViewDepth(const Ogre::Camera*) const
71{
72 return 0.0;
73}
74
75const Ogre::MaterialPtr& SDeferredLightAmbient::getMaterial() const
76{
77 // No permutation needed for ambient light!
78 SDeferredLightPermutation noPermutation;
79 return ambientLightMaterialGenerator->GetMaterial(SDeferredShading::getSingleton().GetGBuffer(), noPermutation);
80}
81
82void SDeferredLightAmbient::getWorldTransforms(Ogre::Matrix4* xform) const
83{
84 *xform = Ogre::Matrix4::IDENTITY;
85}
86
88{
89 Ogre::Technique* tech = getMaterial()->getBestTechnique();
90 Ogre::Vector3 farCorner = camera->getViewMatrix(true) * camera->getWorldSpaceCorners()[4];
91
92 // get the vertex shader parameters
93 // set the camera's far-top-right corner
94 Ogre::GpuProgramParametersSharedPtr params = tech->getPass(0)->getVertexProgramParameters();
95 if (params->_findNamedConstantDefinition("farCorner"))
96 params->setNamedConstant("farCorner", farCorner);
97}
98
99}
static void CreateQuad(Ogre::VertexData *&vertexData)
virtual void getWorldTransforms(Ogre::Matrix4 *xform) const
virtual const Ogre::MaterialPtr & getMaterial() const
virtual Ogre::Real getSquaredViewDepth(const Ogre::Camera *) const
virtual Ogre::Real getBoundingRadius() const
void UpdateFromCamera(Ogre::Camera *camera)
static SDeferredShading & getSingleton()
const Ogre::MaterialPtr & GetMaterial(SGBuffer *gbuffer, PERMUTATION_CLASS permutation)