Commits

Anonymous committed 41a1911

Removed deferred rendering files

Comments (0)

Files changed (26)

PolyMain/PolyMain.vcxproj

     <ClInclude Include="include\Poly.h" />
     <ClInclude Include="include\PolyEnvironment.h" />
     <ClInclude Include="include\PolyPrerequisites.h" />
-    <ClInclude Include="include\render\PolyAmbientLight.h" />
-    <ClInclude Include="include\render\PolyDeferredLightCP.h" />
-    <ClInclude Include="include\render\PolyDeferredShading.h" />
-    <ClInclude Include="include\render\PolyDLight.h" />
-    <ClInclude Include="include\render\PolyGBufferMaterialGenerator.h" />
-    <ClInclude Include="include\render\PolyGBufferSchemeHandler.h" />
-    <ClInclude Include="include\render\PolyGeomUtils.h" />
-    <ClInclude Include="include\render\PolyLightMaterialGenerator.h" />
-    <ClInclude Include="include\render\PolyListenerFactoryLogic.h" />
-    <ClInclude Include="include\render\PolyMaterialGenerator.h" />
-    <ClInclude Include="include\render\PolyNullSchemeHandler.h" />
     <ClInclude Include="include\render\PolyRender.h" />
     <ClInclude Include="include\render\PolyRenderComponent.h" />
     <ClInclude Include="include\render\PolyRenderDrawUtil.h" />
     <ClInclude Include="include\render\PolyRenderSubScene.h" />
     <ClInclude Include="include\render\PolyRenderSystem.h" />
     <ClInclude Include="include\render\PolyRenderUtil.h" />
-    <ClInclude Include="include\render\PolySharedData.h" />
     <ClInclude Include="include\script\PolyScript.h" />
     <ClInclude Include="include\script\PolyScriptBindings.h" />
     <ClInclude Include="include\script\PolyScriptConstructor.h" />
       <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
       <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
     </ClCompile>
-    <ClCompile Include="include\render\PolyAmbientLight.cpp" />
-    <ClCompile Include="include\render\PolyDeferredLightCP.cpp" />
-    <ClCompile Include="include\render\PolyDeferredShading.cpp" />
-    <ClCompile Include="include\render\PolyDLight.cpp" />
-    <ClCompile Include="include\render\PolyGBufferMaterialGenerator.cpp" />
-    <ClCompile Include="include\render\PolyGBufferSchemeHandler.cpp" />
-    <ClCompile Include="include\render\PolyGeomUtils.cpp" />
-    <ClCompile Include="include\render\PolyLightMaterialGenerator.cpp" />
-    <ClCompile Include="include\render\PolyMaterialGenerator.cpp" />
     <ClCompile Include="include\render\PolyRenderDrawUtil.cpp" />
     <ClCompile Include="include\render\PolyRenderIcoSphere.cpp" />
     <ClCompile Include="include\render\PolyRenderSubScene.cpp" />

PolyMain/PolyMain.vcxproj.filters

       <Filter>script</Filter>
     </ClInclude>
     <ClInclude Include="include\PolyEnvironment.h" />
-    <ClInclude Include="include\render\PolyAmbientLight.h">
-      <Filter>render</Filter>
-    </ClInclude>
-    <ClInclude Include="include\render\PolyDeferredLightCP.h">
-      <Filter>render</Filter>
-    </ClInclude>
-    <ClInclude Include="include\render\PolyDeferredShading.h">
-      <Filter>render</Filter>
-    </ClInclude>
-    <ClInclude Include="include\render\PolyDLight.h">
-      <Filter>render</Filter>
-    </ClInclude>
-    <ClInclude Include="include\render\PolyGBufferMaterialGenerator.h">
-      <Filter>render</Filter>
-    </ClInclude>
-    <ClInclude Include="include\render\PolyGBufferSchemeHandler.h">
-      <Filter>render</Filter>
-    </ClInclude>
-    <ClInclude Include="include\render\PolyGeomUtils.h">
-      <Filter>render</Filter>
-    </ClInclude>
-    <ClInclude Include="include\render\PolyLightMaterialGenerator.h">
-      <Filter>render</Filter>
-    </ClInclude>
-    <ClInclude Include="include\render\PolyListenerFactoryLogic.h">
-      <Filter>render</Filter>
-    </ClInclude>
-    <ClInclude Include="include\render\PolyMaterialGenerator.h">
-      <Filter>render</Filter>
-    </ClInclude>
-    <ClInclude Include="include\render\PolyNullSchemeHandler.h">
-      <Filter>render</Filter>
-    </ClInclude>
     <ClInclude Include="include\render\PolyRender.h">
       <Filter>render</Filter>
     </ClInclude>
     <ClInclude Include="include\render\PolyRenderUtil.h">
       <Filter>render</Filter>
     </ClInclude>
-    <ClInclude Include="include\render\PolySharedData.h">
-      <Filter>render</Filter>
-    </ClInclude>
     <ClInclude Include="include\game\PolyAudioListenerComponent.h">
       <Filter>game\audio</Filter>
     </ClInclude>
     <ClCompile Include="include\util\PolyReflection.cpp">
       <Filter>util</Filter>
     </ClCompile>
-    <ClCompile Include="include\render\PolyAmbientLight.cpp">
-      <Filter>render</Filter>
-    </ClCompile>
-    <ClCompile Include="include\render\PolyDeferredLightCP.cpp">
-      <Filter>render</Filter>
-    </ClCompile>
-    <ClCompile Include="include\render\PolyDeferredShading.cpp">
-      <Filter>render</Filter>
-    </ClCompile>
-    <ClCompile Include="include\render\PolyDLight.cpp">
-      <Filter>render</Filter>
-    </ClCompile>
-    <ClCompile Include="include\render\PolyGBufferMaterialGenerator.cpp">
-      <Filter>render</Filter>
-    </ClCompile>
-    <ClCompile Include="include\render\PolyGBufferSchemeHandler.cpp">
-      <Filter>render</Filter>
-    </ClCompile>
-    <ClCompile Include="include\render\PolyGeomUtils.cpp">
-      <Filter>render</Filter>
-    </ClCompile>
-    <ClCompile Include="include\render\PolyLightMaterialGenerator.cpp">
-      <Filter>render</Filter>
-    </ClCompile>
-    <ClCompile Include="include\render\PolyMaterialGenerator.cpp">
-      <Filter>render</Filter>
-    </ClCompile>
     <ClCompile Include="include\render\PolyRenderDrawUtil.cpp">
       <Filter>render</Filter>
     </ClCompile>

PolyMain/include/audio/PolyAudioSound.h

 		virtual void	setMinDistance(float dist) = 0;
 		virtual void	setPlaybackSpeed(float speed) = 0;
 
+		virtual void	setVolume(float val) = 0;
+		virtual float	getVolume() const = 0;
+
 		virtual void	setIsPaused(bool paused) = 0;
-		virtual bool	getIsPaused() = 0;
+		virtual bool	isPaused() const = 0;
+
+		virtual bool	isFinished() const = 0;
 
 		virtual void	stop() = 0;
-
 		virtual void	drop() = 0;
 	};
 }

PolyMain/include/game/PolyCameraComponent.cpp

 #include "core/PolyEngine.h"
 #include "render/PolyRenderSubScene.h"
 #include "render/PolyRenderSystem.h"
-#include "render/PolyDeferredShading.h"
 #include "game/PolyTransformComponent.h"
 
 #include "game/PolyCameraComponent.h"

PolyMain/include/render/PolyAmbientLight.cpp

-/*
------------------------------------------------------------------------------
-This source file is part of OGRE
-(Object-oriented Graphics Rendering Engine)
-For the latest info, see http://www.ogre3d.org/
-
-Copyright (c) 2000-2012 Torus Knot Software Ltd
-Also see acknowledgements in Readme.html
-
-You may use this sample code for anything you like, it is not covered by the
-same license as the rest of the engine.
------------------------------------------------------------------------------
-*/
-
-#include "PolyPrerequisites.h"
-#include "OgreMaterialManager.h"
-#include "OgreRoot.h"
-#include "OgreRenderSystem.h"
-
-#include "render/PolyAmbientLight.h"
-#include "render/PolyGeomUtils.h"
-
-
-using namespace Ogre;
-
-AmbientLight::AmbientLight() {
-	setRenderQueueGroup(RENDER_QUEUE_2);
-
-	mRenderOp.vertexData = new VertexData();
-	mRenderOp.indexData = 0;
-
-	GeomUtils::createQuad(mRenderOp.vertexData);
-
-	mRenderOp.operationType = RenderOperation::OT_TRIANGLE_STRIP; 
-	mRenderOp.useIndexes = false; 
-
-	// Set bounding
-	setBoundingBox(AxisAlignedBox(-10000,-10000,-10000,10000,10000,10000));
-	mRadius = 15000;
-
-	mMatPtr = MaterialManager::getSingleton().getByName("DeferredShading/AmbientLight");
-	POLY_ASSERT(mMatPtr.isNull()==false);
-	mMatPtr->load();
-
-    //This shader needs to be aware if its running under OpenGL or DirectX.
-    //Real depthFactor = (Root::getSingleton().getRenderSystem()->getName() ==
-    //    "OpenGL Rendering Subsystem") ? 2.0 : 1.0;
-    //mMatPtr->getTechnique(0)->getPass(0)->getFragmentProgramParameters()->setNamedConstant(
-    //        "depthFactor", depthFactor);
-}
-
-AmbientLight::~AmbientLight() {
-	// need to release IndexData and vertexData created for renderable
-	delete mRenderOp.indexData;
-	delete mRenderOp.vertexData;
-}
-
-/** @copydoc MovableObject::getBoundingRadius */
-Real AmbientLight::getBoundingRadius(void) const {
-	return mRadius;
-
-}
-/** @copydoc Renderable::getSquaredViewDepth */
-Real AmbientLight::getSquaredViewDepth(const Camera*) const {
-	return 0.0;
-}
-
-const MaterialPtr& AmbientLight::getMaterial(void) const {
-	return mMatPtr;
-}
-
-void AmbientLight::getWorldTransforms(Ogre::Matrix4* xform) const {
-	*xform = Matrix4::IDENTITY;
-}
-
-void AmbientLight::updateFromCamera(Ogre::Camera* camera) {
-	Ogre::Technique* tech = getMaterial()->getBestTechnique();
-	Ogre::Vector3 farCorner = camera->getViewMatrix(true) * camera->getWorldSpaceCorners()[4];
-
-	for (unsigned short i=0; i<tech->getNumPasses(); i++) {
-		Ogre::Pass* pass = tech->getPass(i);
-		// get the vertex shader parameters
-		Ogre::GpuProgramParametersSharedPtr params = pass->getVertexProgramParameters();
-		// set the camera's far-top-right corner
-		if (params->_findNamedConstantDefinition("farCorner"))
-			params->setNamedConstant("farCorner", farCorner);
-	    
-		params = pass->getFragmentProgramParameters();
-		if (params->_findNamedConstantDefinition("farCorner"))
-			params->setNamedConstant("farCorner", farCorner);
-	}
-}

PolyMain/include/render/PolyAmbientLight.h

-/*
------------------------------------------------------------------------------
-This source file is part of OGRE
-(Object-oriented Graphics Rendering Engine)
-For the latest info, see http://www.ogre3d.org/
-
-Copyright (c) 2000-2012 Torus Knot Software Ltd
-Also see acknowledgements in Readme.html
-
-You may use this sample code for anything you like, it is not covered by the
-same license as the rest of the engine.
------------------------------------------------------------------------------
-*/
-
-#ifndef _AMBIENTLIGHT_H
-#define _AMBIENTLIGHT_H
-
-#include "OgreSimpleRenderable.h"
-
-// Renderable for rendering Ambient component and also to
-// establish the depths
-
-// Just instantiation is sufficient
-// Note that instantiation is necessary to at least establish the depths
-// even if the current ambient colour is 0
-
-// its ambient colour is same as the scene's ambient colour
-
-// XXX Could make this a singleton/make it private to the DeferredShadingSystem e.g.
-
-class AmbientLight : public Ogre::SimpleRenderable
-
-{
-public:
-	AmbientLight();
-	~AmbientLight();
-
-	/** @copydoc MovableObject::getBoundingRadius */
-	virtual Ogre::Real getBoundingRadius(void) const;
-	/** @copydoc Renderable::getSquaredViewDepth */
-	virtual Ogre::Real getSquaredViewDepth(const Ogre::Camera*) const;
-	/** @copydoc Renderable::getMaterial */
-	virtual const Ogre::MaterialPtr& getMaterial(void) const;
-
-	virtual void getWorldTransforms(Ogre::Matrix4* xform) const;
-
-	void updateFromCamera(Ogre::Camera* camera);
-protected:
-	Ogre::Real mRadius;
-	Ogre::MaterialPtr mMatPtr;
-};
- 
-#endif

PolyMain/include/render/PolyDLight.cpp

-/*
------------------------------------------------------------------------------
-This source file is part of OGRE
-(Object-oriented Graphics Rendering Engine)
-For the latest info, see http://www.ogre3d.org/
-
-Copyright (c) 2000-2012 Torus Knot Software Ltd
-Also see acknowledgements in Readme.html
-
-You may use this sample code for anything you like, it is not covered by the
-same license as the rest of the engine.
------------------------------------------------------------------------------
-*/
-
-#include "PolyPrerequisites.h"
-#include "OgreHardwareBufferManager.h"
-#include "OgreCamera.h"
-#include "OgreSceneNode.h"
-#include "OgreLight.h"
-#include "OgreTechnique.h"
-#include "OgreSceneManager.h"
-#include "render/PolyGeomUtils.h"
-#include "render/PolyLightMaterialGenerator.h"
-
-#include "render/PolyDLight.h"
-
-
-#define ENABLE_BIT(mask, flag) (mask) |= (flag)
-#define DISABLE_BIT(mask, flag) (mask) &= ~(flag)
-
-using namespace Ogre;
-//-----------------------------------------------------------------------
-DLight::DLight(MaterialGenerator *sys, Ogre::Light* parentLight):
-    mParentLight(parentLight), bIgnoreWorld(false), mGenerator(sys), mPermutation(0) {
-	// Set up geometry
-	// Allocate render operation
-	mRenderOp.operationType = RenderOperation::OT_TRIANGLE_LIST;
-	mRenderOp.indexData = 0;
-	mRenderOp.vertexData = 0;
-	mRenderOp.useIndexes = true;
-
-	updateFromParent();
-}
-//-----------------------------------------------------------------------
-DLight::~DLight() {
-	// need to release IndexData and vertexData created for renderable
-    delete mRenderOp.indexData;
-    delete mRenderOp.vertexData;
-}
-//-----------------------------------------------------------------------
-void DLight::setAttenuation(float c, float b, float a) {
-	// Set Attenuation parameter to shader
-	//setCustomParameter(3, Vector4(c, b, a, 0));
-	float outerRadius = mParentLight->getAttenuationRange();
-	/// There is attenuation? Set material accordingly
-	if(c != 1.0f || b != 0.0f || a != 0.0f)
-	{
-		ENABLE_BIT(mPermutation, LightMaterialGenerator::MI_ATTENUATED);
-		if (mParentLight->getType() == Light::LT_POINT) {
-			//// Calculate radius from Attenuation
-			int threshold_level = 10;// difference of 10-15 levels deemed unnoticeable
-			float threshold = 1.0f/((float)threshold_level/256.0f); 
-
-			//// Use quadratic formula to determine outer radius
-			c = c-threshold;
-			float d=sqrt(b*b-4*a*c);
-			outerRadius = (-2*c)/(b+d);
-			outerRadius *= 1.2f;
-		}
-	}
-	else
-	{
-		DISABLE_BIT(mPermutation,LightMaterialGenerator::MI_ATTENUATED);
-	}
-    
-	rebuildGeometry(outerRadius);
-}
-//-----------------------------------------------------------------------
-void DLight::setSpecularColour(const ColourValue &col) {
-	//setCustomParameter(2, Vector4(col.r, col.g, col.b, col.a));
-	/// There is a specular component? Set material accordingly
-	
-	if(col.r != 0.0f || col.g != 0.0f || col.b != 0.0f)
-		ENABLE_BIT(mPermutation,LightMaterialGenerator::MI_SPECULAR);
-	else
-		DISABLE_BIT(mPermutation,LightMaterialGenerator::MI_SPECULAR);
-		
-}
-//-----------------------------------------------------------------------
-void DLight::rebuildGeometry(float radius) {
-	//Disable all 3 bits
-	DISABLE_BIT(mPermutation, LightMaterialGenerator::MI_POINT);
-	DISABLE_BIT(mPermutation, LightMaterialGenerator::MI_SPOTLIGHT);
-	DISABLE_BIT(mPermutation, LightMaterialGenerator::MI_DIRECTIONAL);
-
-	switch (mParentLight->getType())
-	{
-	case Light::LT_DIRECTIONAL:
-		createRectangle2D();
-        ENABLE_BIT(mPermutation,LightMaterialGenerator::MI_DIRECTIONAL);
-		break;
-	case Light::LT_POINT:
-		/// XXX some more intelligent expression for rings and segments
-		createSphere(radius, 10, 10);
-		ENABLE_BIT(mPermutation,LightMaterialGenerator::MI_POINT);
-		break;
-	case Light::LT_SPOTLIGHT:
-		Real height = mParentLight->getAttenuationRange();
-		Radian coneRadiusAngle = mParentLight->getSpotlightOuterAngle() / 2;
-        Real rad = Math::Tan(coneRadiusAngle) * height;
-		createCone(rad, height, 20);
-		ENABLE_BIT(mPermutation,LightMaterialGenerator::MI_SPOTLIGHT);
-		break;
-	}	
-}
-//-----------------------------------------------------------------------
-void DLight::createRectangle2D() {
-	/// XXX this RenderOp should really be re-used between DLight objects,
-	/// not generated every time
-	delete mRenderOp.vertexData; 
-	delete mRenderOp.indexData; 
-
-	mRenderOp.vertexData = new VertexData();
-    mRenderOp.indexData = 0;
-
-	GeomUtils::createQuad(mRenderOp.vertexData);
-
-    mRenderOp.operationType = RenderOperation::OT_TRIANGLE_STRIP; 
-    mRenderOp.useIndexes = false; 
-
-	// Set bounding
-    setBoundingBox(AxisAlignedBox(-10000,-10000,-10000,10000,10000,10000));
-	mRadius = 15000;
-	bIgnoreWorld = true;
-}
-//-----------------------------------------------------------------------
-void DLight::createSphere(float radius, int nRings, int nSegments) {
-	delete mRenderOp.vertexData; 
-	delete mRenderOp.indexData;
-	mRenderOp.operationType = RenderOperation::OT_TRIANGLE_LIST;
-	mRenderOp.indexData = new IndexData();
-	mRenderOp.vertexData = new VertexData();
-	mRenderOp.useIndexes = true;
-
-	GeomUtils::createSphere(mRenderOp.vertexData, mRenderOp.indexData
-		, radius
-		, nRings, nSegments
-		, false // no normals
-		, false // no texture coordinates
-		);
-
-	// Set bounding box and sphere
-	setBoundingBox( AxisAlignedBox( Vector3(-radius, -radius, -radius), Vector3(radius, radius, radius) ) );
-	mRadius = radius;
-	bIgnoreWorld = false;
-}
-//-----------------------------------------------------------------------
-void DLight::createCone(float radius, float height, int nVerticesInBase) {
-	delete mRenderOp.vertexData;
-	delete mRenderOp.indexData;
-	mRenderOp.operationType = RenderOperation::OT_TRIANGLE_LIST;
-	mRenderOp.indexData = new IndexData();
-	mRenderOp.vertexData = new VertexData();
-	mRenderOp.useIndexes = true;
-
-	GeomUtils::createCone(mRenderOp.vertexData, mRenderOp.indexData
-		, radius
-		, height, nVerticesInBase);
-
-	// Set bounding box and sphere
-	setBoundingBox( AxisAlignedBox( 
-			Vector3(-radius, 0, -radius), 
-			Vector3(radius, height, radius) ) );
-
-	mRadius = radius;
-	bIgnoreWorld = false;
-}
-//-----------------------------------------------------------------------
-Real DLight::getBoundingRadius(void) const {
-	return mRadius;
-}
-//-----------------------------------------------------------------------
-Real DLight::getSquaredViewDepth(const Camera* cam) const {
-	if(bIgnoreWorld) {
-		return 0.0f;
-	}
-	else {
-		Vector3 dist = cam->getDerivedPosition() - getParentSceneNode()->_getDerivedPosition();
-		return dist.squaredLength();
-	}
-}
-//-----------------------------------------------------------------------
-const MaterialPtr& DLight::getMaterial(void) const {
-	return mGenerator->getMaterial(mPermutation);
-}
-//-----------------------------------------------------------------------
-void DLight::getWorldTransforms(Matrix4* xform) const {
-	if (mParentLight->getType() == Light::LT_SPOTLIGHT)
-	{
-		Quaternion quat = Vector3::UNIT_Y.getRotationTo(mParentLight->getDerivedDirection());
-		xform->makeTransform(mParentLight->getDerivedPosition(),
-			Vector3::UNIT_SCALE, quat);
-	}
-	else
-	{
-		xform->makeTransform(mParentLight->getDerivedPosition(),
-			Vector3::UNIT_SCALE, Quaternion::IDENTITY);
-	}
-	
-}
-//-----------------------------------------------------------------------
-void DLight::updateFromParent() {
-	//TODO : Don't do this unless something changed
-	setAttenuation(mParentLight->getAttenuationConstant(), 
-		mParentLight->getAttenuationLinear(), mParentLight->getAttenuationQuadric());	
-	setSpecularColour(mParentLight->getSpecularColour());
-
-	if (getCastChadows())
-	{
-		ENABLE_BIT(mPermutation,LightMaterialGenerator::MI_SHADOW_CASTER);
-	}
-	else
-	{
-		DISABLE_BIT(mPermutation, LightMaterialGenerator::MI_SHADOW_CASTER);
-	}
-}
-//-----------------------------------------------------------------------
-bool DLight::isCameraInsideLight(Ogre::Camera* camera) {
-	switch (mParentLight->getType())
-	{
-	case Ogre::Light::LT_DIRECTIONAL:
-		return false;
-	case Ogre::Light::LT_POINT:
-		{
-		Ogre::Real distanceFromLight = camera->getDerivedPosition()
-			.distance(mParentLight->getDerivedPosition());
-		//Small epsilon fix to account for the fact that we aren't a true sphere.
-		return distanceFromLight <= mRadius + camera->getNearClipDistance() + 0.1; 
-		}
-	case Ogre::Light::LT_SPOTLIGHT:
-		{
-		Ogre::Vector3 lightPos = mParentLight->getDerivedPosition();
-		Ogre::Vector3 lightDir = mParentLight->getDerivedDirection();
-		Ogre::Radian attAngle = mParentLight->getSpotlightOuterAngle();
-		
-		//Extend the analytic cone's radius by the near clip range by moving its tip accordingly.
-		//Some trigonometry needed here.
-		Ogre::Vector3 clipRangeFix = -lightDir * (camera->getNearClipDistance() / Ogre::Math::Tan(attAngle/2));
-		lightPos = lightPos + clipRangeFix;
-    
-		Ogre::Vector3 lightToCamDir = camera->getDerivedPosition() - lightPos;
-		Ogre::Real distanceFromLight = lightToCamDir.normalise();
-
-		Ogre::Real cosAngle = lightToCamDir.dotProduct(lightDir);
-		Ogre::Radian angle = Ogre::Math::ACos(cosAngle);
-		//Check whether we will see the cone from our current POV.
-		return (distanceFromLight <= (mParentLight->getAttenuationRange() + clipRangeFix.length()))
-			&& (angle <= attAngle);
-		}
-	default:
-		//Please the compiler
-		return false;
-	}
-}
-//-----------------------------------------------------------------------
-bool DLight::getCastChadows() const {
-	return 
-		mParentLight->_getManager()->isShadowTechniqueInUse() &&
-		mParentLight->getCastShadows() && 
-		(mParentLight->getType() == Light::LT_DIRECTIONAL || mParentLight->getType() == Light::LT_SPOTLIGHT);
-}
-//-----------------------------------------------------------------------
-void DLight::updateFromCamera(Ogre::Camera* camera) {
-	//Set shader params
-	const Ogre::MaterialPtr& mat = getMaterial();
-	if (!mat->isLoaded()) {
-		mat->load();
-	}
-	Ogre::Technique* tech = mat->getBestTechnique();
-	Ogre::Vector3 farCorner = camera->getViewMatrix(true) * camera->getWorldSpaceCorners()[4];
-
-	for (unsigned short i=0; i<tech->getNumPasses(); i++) {
-		Ogre::Pass* pass = tech->getPass(i);
-		// get the vertex shader parameters
-		Ogre::GpuProgramParametersSharedPtr params = pass->getVertexProgramParameters();
-		// set the camera's far-top-right corner
-		if (params->_findNamedConstantDefinition("farCorner"))
-			params->setNamedConstant("farCorner", farCorner);
-	    
-		params = pass->getFragmentProgramParameters();
-		if (params->_findNamedConstantDefinition("farCorner"))
-			params->setNamedConstant("farCorner", farCorner);
-
-		//If inside light geometry, render back faces with CMPF_GREATER, otherwise normally
-		if (mParentLight->getType() == Ogre::Light::LT_DIRECTIONAL)
-		{
-			pass->setCullingMode(Ogre::CULL_CLOCKWISE);
-			pass->setDepthCheckEnabled(false);
-		}
-		else
-		{
-			pass->setDepthCheckEnabled(true);
-			if (isCameraInsideLight(camera))
-			{
-				pass->setCullingMode(Ogre::CULL_ANTICLOCKWISE);
-				pass->setDepthFunction(Ogre::CMPF_GREATER_EQUAL);
-			}
-			else
-			{
-				pass->setCullingMode(Ogre::CULL_CLOCKWISE);
-				pass->setDepthFunction(Ogre::CMPF_LESS_EQUAL);
-			}
-		}
-
-		Camera shadowCam("ShadowCameraSetupCam", 0);
-		shadowCam._notifyViewport(camera->getViewport());
-		SceneManager* sm = mParentLight->_getManager();
-		sm->getShadowCameraSetup()->getShadowCamera(sm, 
-			camera, camera->getViewport(), mParentLight, &shadowCam, 0);
-			
-		//Get the shadow camera position
-		if (params->_findNamedConstantDefinition("shadowCamPos")) {
-			params->setNamedConstant("shadowCamPos", shadowCam.getPosition());
-		}
-		if (params->_findNamedConstantDefinition("shadowFarClip")) {
-			params->setNamedConstant("shadowFarClip", shadowCam.getFarClipDistance());
-		}
-
-	}
-}

PolyMain/include/render/PolyDLight.h

-/*
------------------------------------------------------------------------------
-This source file is part of OGRE
-(Object-oriented Graphics Rendering Engine)
-For the latest info, see http://www.ogre3d.org/
-
-Copyright (c) 2000-2012 Torus Knot Software Ltd
-Also see acknowledgements in Readme.html
-
-You may use this sample code for anything you like, it is not covered by the
-same license as the rest of the engine.
------------------------------------------------------------------------------
-*/
-
-#ifndef H_WJ_DLight
-#define H_WJ_DLight
-
-#include "OgreSimpleRenderable.h"
-#include "render/PolyMaterialGenerator.h"
-
-/** Deferred light geometry. Each instance matches a normal light.
-	Should not be created by the user.
-	XXX support other types of light other than point lights.
- */
-class DLight: public Ogre::SimpleRenderable
-{
-public:
-	DLight(MaterialGenerator *gen, Ogre::Light* parentLight);
-	~DLight();
-
-	/** Update the information from the light that matches this one 
-	 */
-	void updateFromParent();
-
-	/** Update the information that is related to the camera
-	 */
-	void updateFromCamera(Ogre::Camera* camera);
-
-	/** Does this light cast shadows?
-	*/
-	virtual bool getCastChadows() const;
-
-	/** @copydoc MovableObject::getBoundingRadius */
-	virtual Ogre::Real getBoundingRadius(void) const;
-	/** @copydoc Renderable::getSquaredViewDepth */
-	virtual Ogre::Real getSquaredViewDepth(const Ogre::Camera*) const;
-	/** @copydoc Renderable::getMaterial */
-	virtual const Ogre::MaterialPtr& getMaterial(void) const;
-	/** @copydoc Renderable::getBoundingRadius */
-	virtual void getWorldTransforms(Ogre::Matrix4* xform) const;
-protected:
-
-	/** Check if the camera is inside a light
-	*/
-	bool isCameraInsideLight(Ogre::Camera* camera);
-
-	/** Create geometry for this light.
-	*/
-	void rebuildGeometry(float radius);
-
-	/** Create a sphere geometry.
-	*/
-	void createSphere(float radius, int nRings, int nSegments);
-
-	/** Create a rectangle.
-	*/
-	void createRectangle2D();
-	
-	/** Create a cone.
-	*/
-	void createCone(float radius, float height, int nVerticesInBase);
-
-	/** Set constant, linear, quadratic Attenuation terms 
-	 */
-	void setAttenuation(float c, float b, float a);
-
-	/** Set the specular colour
-	 */
-	void setSpecularColour(const Ogre::ColourValue &col);
-
-	/// The light that this DLight renders
-	Ogre::Light* mParentLight;
-	/// Mode to ignore world orientation/position
-	bool bIgnoreWorld;
-	/// Bounding sphere radius
-	float mRadius;
-	/// Deferred shading system this minilight is part of
-	MaterialGenerator *mGenerator;
-	/// Material permutation
-	Ogre::uint32 mPermutation;
-};
-
-#endif

PolyMain/include/render/PolyDeferredLightCP.cpp

-/*
------------------------------------------------------------------------------
-This source file is part of OGRE
-(Object-oriented Graphics Rendering Engine)
-For the latest info, see http://www.ogre3d.org/
-
-Copyright (c) 2000-2012 Torus Knot Software Ltd
-Also see acknowledgements in Readme.html
-
-You may use this sample code for anything you like, it is not covered by the
-same license as the rest of the engine.
------------------------------------------------------------------------------
-*/
-
-#include "PolyPrerequisites.h"
-#include "render/PolyLightMaterialGenerator.h"
-
-#include "render/PolyDeferredLightCP.h"
-
-
-using namespace Ogre;
-
-DeferredLightRenderOperation::DeferredLightRenderOperation(
-	CompositorInstance* instance, const CompositionPass* pass) {
-	mViewport = instance->getChain()->getViewport();
-	
-	//Get the names of the GBuffer textures
-	const CompositionPass::InputTex& input0 = pass->getInput(0);
-	mTexName0 = instance->getTextureInstanceName(input0.name, input0.mrtIndex);
-	const CompositionPass::InputTex& input1 = pass->getInput(1);
-	mTexName1 = instance->getTextureInstanceName(input1.name, input1.mrtIndex);
-
-	// Create lights material generator
-	mLightMaterialGenerator = new LightMaterialGenerator();
-	
-	// Create the ambient light
-	mAmbientLight = new AmbientLight();
-	const MaterialPtr& mat = mAmbientLight->getMaterial();
-	mat->load();
-}
-
-DLight* DeferredLightRenderOperation::createDLight(Ogre::Light* light) {
-	DLight *rv = new DLight(mLightMaterialGenerator,light);
-	mLights[light] = rv;
-	return rv;
-}
-
-void injectTechnique(SceneManager* sm, Technique* tech, Renderable* rend, const Ogre::LightList* lightList) {
-    for(unsigned short i=0; i<tech->getNumPasses(); ++i) {
-		Ogre::Pass* pass = tech->getPass(i);
-        if (lightList != 0)
-			sm->_injectRenderWithPass(pass, rend, false, false, lightList);
-		else
-			sm->_injectRenderWithPass(pass, rend, false);
-	}
-}
-
-void DeferredLightRenderOperation::execute(SceneManager *sm, RenderSystem *rs) {
-    Ogre::Camera* cam = mViewport->getCamera();
-
-	mAmbientLight->updateFromCamera(cam);
-    Technique* tech = mAmbientLight->getMaterial()->getBestTechnique();
-	injectTechnique(sm, tech, mAmbientLight, 0);
-
-	const LightList& lightList = sm->_getLightsAffectingFrustum();
-    for (LightList::const_iterator it = lightList.begin(); it != lightList.end(); it++) {
-        Light* light = *it;
-		Ogre::LightList ll;
-		ll.push_back(light);
-
-		//if (++i != 2) continue;
-        //if (light->getType() != Light::LT_DIRECTIONAL) continue;
-		//if (light->getDiffuseColour() != ColourValue::Red) continue;
-
-		LightsMap::iterator dLightIt = mLights.find(light);
-		DLight* dLight = 0;
-		if (dLightIt == mLights.end()) {
-			dLight = createDLight(light);
-		}
-		else {
-			dLight = dLightIt->second;
-			dLight->updateFromParent();
-		}
-		dLight->updateFromCamera(cam);
-		tech = dLight->getMaterial()->getBestTechnique();
-
-		//Update shadow texture
-		if (dLight->getCastChadows()) {
-			SceneManager::RenderContext* context = sm->_pauseRendering();
-
-			sm->prepareShadowTextures(cam, mViewport, &ll);
-			sm->_resumeRendering(context);
-			
-			Pass* pass = tech->getPass(0);
-			TextureUnitState* tus = pass->getTextureUnitState("ShadowMap");
-			POLY_ASSERT(tus);
-			const TexturePtr& shadowTex = sm->getShadowTexture(0);
-			if (tus->_getTexturePtr() != shadowTex) {
-				tus->_setTexturePtr(shadowTex);
-			}
-			
-		}
-		
-        injectTechnique(sm, tech, dLight, &ll);
-	}
-}
-
-DeferredLightRenderOperation::~DeferredLightRenderOperation() {
-	for (LightsMap::iterator it = mLights.begin(); it != mLights.end(); ++it) {
-		POLY_DELETE(it->second);
-	}
-	mLights.clear();
-	
-	POLY_DELETE(mAmbientLight);
-	POLY_DELETE(mLightMaterialGenerator);
-}

PolyMain/include/render/PolyDeferredLightCP.h

-/*
------------------------------------------------------------------------------
-This source file is part of OGRE
-(Object-oriented Graphics Rendering Engine)
-For the latest info, see http://www.ogre3d.org/
-
-Copyright (c) 2000-2012 Torus Knot Software Ltd
-Also see acknowledgements in Readme.html
-
-You may use this sample code for anything you like, it is not covered by the
-same license as the rest of the engine.
------------------------------------------------------------------------------
-*/
-
-#ifndef _DEFERRED_LIGHT_CP_H
-#define _DEFERRED_LIGHT_CP_H
-
-#include "OgreCompositorInstance.h"
-#include "OgreCustomCompositionPass.h"
-
-#include "render/PolyDLight.h"
-#include "render/PolyMaterialGenerator.h"
-#include "render/PolyAmbientLight.h"
-
-//The render operation that will be called each frame in the custom composition pass
-//This is the class that will send the actual render calls of the spheres (point lights),
-//cones (spotlights) and quads (directional lights) after the GBuffer has been constructed
-class DeferredLightRenderOperation : public Ogre::CompositorInstance::RenderSystemOperation
-{
-public:
-	DeferredLightRenderOperation(Ogre::CompositorInstance* instance, const Ogre::CompositionPass* pass);
-	
-	/** @copydoc CompositorInstance::RenderSystemOperation::execute */
-	virtual void execute(Ogre::SceneManager *sm, Ogre::RenderSystem *rs);
-
-	virtual ~DeferredLightRenderOperation();
-private:
-
-	/** Create a new deferred light
-	 */
-	DLight *createDLight(Ogre::Light* light);
-	
-	//The texture names of the GBuffer components
-	Ogre::String mTexName0;
-	Ogre::String mTexName1;
-
-	//The material generator for the light geometry
-	MaterialGenerator* mLightMaterialGenerator;
-
-	//The map of deferred light geometries already constructed
-	typedef std::map<Ogre::Light*, DLight*> LightsMap;
-	LightsMap mLights;
-
-	//The ambient light used to render the scene
-	AmbientLight* mAmbientLight;
-
-	//The viewport that we are rendering to
-	Ogre::Viewport* mViewport;
-};
-
-//The custom composition pass that is used for rendering the light geometry
-//This class needs to be registered with the CompositorManager
-class DeferredLightCompositionPass : public Ogre::CustomCompositionPass
-{
-public:
-
-	/** @copydoc CustomCompositionPass::createOperation */
-	virtual Ogre::CompositorInstance::RenderSystemOperation* createOperation(
-		Ogre::CompositorInstance* instance, const Ogre::CompositionPass* pass)
-	{
-		return OGRE_NEW DeferredLightRenderOperation(instance, pass);
-	}
-
-protected:
-	virtual ~DeferredLightCompositionPass() {}
-};
-
-#endif

PolyMain/include/render/PolyDeferredShading.cpp

-/*
------------------------------------------------------------------------------
-This source file is part of OGRE
-(Object-oriented Graphics Rendering Engine)
-For the latest info, see http://www.ogre3d.org/
-
-Copyright (c) 2000-2012 Torus Knot Software Ltd
-Also see acknowledgements in Readme.html
-
-You may use this sample code for anything you like, it is not covered by the
-same license as the rest of the engine.
------------------------------------------------------------------------------
-*/
-
-#include "PolyPrerequisites.h"
-
-#include "render/PolyDeferredShading.h"
-
-#include "OgreConfigFile.h"
-#include "OgreStringConverter.h"
-#include "OgreException.h"
-
-#include "OgreRoot.h"
-#include "OgreRenderSystem.h"
-
-#include "OgreEntity.h"
-#include "OgreSubEntity.h"
-#include "OgreRoot.h"
-
-#include <OgreCompositor.h>
-#include <OgreCompositorManager.h>
-#include <OgreCompositorChain.h>
-#include <OgreCompositorInstance.h>
-#include <OgreCompositorLogic.h>
-
-#include <OgreLogManager.h>
-
-#include "render/PolyDeferredLightCP.h"
-#include "render/PolyGBufferSchemeHandler.h"
-#include "render/PolyNullSchemeHandler.h"
-
-#include "render/PolySharedData.h"
-
-namespace Ogre {
-    template<> SharedData* Singleton<SharedData>::msSingleton = 0;
-}
-
-using namespace Ogre;
-
-const Ogre::uint8 DeferredShadingSystem::PRE_GBUFFER_RENDER_QUEUE = Ogre::RENDER_QUEUE_1;
-const Ogre::uint8 DeferredShadingSystem::POST_GBUFFER_RENDER_QUEUE = Ogre::RENDER_QUEUE_8;
-
-DeferredShadingSystem::DeferredShadingSystem(Viewport *vp, SceneManager *sm,  Camera *cam)
-:	mViewport(vp),
-	mSceneMgr(sm),
-	mCamera(cam) {
-	sm->setShadowTechnique(SHADOWTYPE_TEXTURE_ADDITIVE);
-	sm->setShadowTextureCasterMaterial("DeferredShading/Shadows/Caster");
-	mSceneMgr->setShadowTextureCount(1);
-	mSceneMgr->setShadowFarDistance(150);
-	mSceneMgr->setShadowTextureConfig(0, 1024, 1024, PF_FLOAT16_R, 2);
-	mSceneMgr->setShadowDirectionalLightExtrusionDistance(75);
-}
-
-void DeferredShadingSystem::initialize() {
-	for(int i=0; i<DSM_COUNT; ++i)
-		mInstance[i]=0;
-
-	createResources();
-	
-	mActive = false;
-	
-	mCurrentMode = DSM_SHOWLIT;
-	setActive(true);
-}
-
-DeferredShadingSystem::~DeferredShadingSystem() {
-	CompositorChain *chain = CompositorManager::getSingleton().getCompositorChain(mViewport);
-	for(int i=0; i<DSM_COUNT; ++i)
-		chain->_removeInstance(mInstance[i]);
-	CompositorManager::getSingleton().removeCompositorChain(mViewport);
-
-	Ogre::CompositorManager& compMgr = Ogre::CompositorManager::getSingleton();
-	CompositorLogicMap::const_iterator itor = mCompositorLogics.begin();
-	CompositorLogicMap::const_iterator end  = mCompositorLogics.end();
-	while( itor != end ) {
-		compMgr.unregisterCompositorLogic( itor->first );
-		delete itor->second;
-		++itor;
-	}
-	mCompositorLogics.clear();
-}
-
-void DeferredShadingSystem::setMode(DSMode mode) {
-	POLY_ASSERT( 0 <= mode && mode < DSM_COUNT);
-
-	// prevent duplicate setups
-	if (mCurrentMode == mode && mInstance[mode]->getEnabled()==mActive)
-		return;
-
-	for(int i=0; i<DSM_COUNT; ++i) {
-		if(i == mode) {
-			mInstance[i]->setEnabled(mActive);
-		}
-		else {
-			mInstance[i]->setEnabled(false);
-		}
-	}
-
-	mCurrentMode = mode;
-}
-
-void DeferredShadingSystem::setActive(bool active) {
-	if (mActive != active) {
-		mActive = active;
-		mGBufferInstance->setEnabled(active);
-
-		// mCurrentMode could have changed with a prior call to setMode, so iterate all
-		setMode(mCurrentMode);
-	}
-}
-
-DeferredShadingSystem::DSMode DeferredShadingSystem::getMode() const {
-	return mCurrentMode;
-}
-
-void DeferredShadingSystem::createResources() {
-	CompositorManager &compMan = CompositorManager::getSingleton();
-
-	//Hook up the compositor logic and scheme handlers.
-	//This can theoretically happen in a loaded plugin, but in this case the demo contains the code.
-	static bool firstTime = true;
-	if (firstTime)
-	{
-		MaterialManager::getSingleton().addListener(new GBufferSchemeHandler, "GBuffer");
-		MaterialManager::getSingleton().addListener(new NullSchemeHandler, "NoGBuffer");
-
-		compMan.registerCustomCompositionPass("DeferredLight", new DeferredLightCompositionPass);
-
-		firstTime = false;
-	}
-
-	// Create the main GBuffer compositor
-	mGBufferInstance = compMan.addCompositor(mViewport, "DeferredShading/GBuffer");
-	
-	// Create filters
-	mInstance[DSM_SHOWLIT] = compMan.addCompositor(mViewport, "DeferredShading/ShowLit");
-	mInstance[DSM_SHOWNORMALS] = compMan.addCompositor(mViewport, "DeferredShading/ShowNormals");
-	mInstance[DSM_SHOWDSP] = compMan.addCompositor(mViewport, "DeferredShading/ShowDepthSpecular");
-	mInstance[DSM_SHOWCOLOUR] = compMan.addCompositor(mViewport, "DeferredShading/ShowColour");
-}
-
-
-void DeferredShadingSystem::logCurrentMode() {
-	if (mActive==false) {
-		LogManager::getSingleton().logMessage("No Compositor Enabled!");
-		return;
-	}
-
-	CompositorInstance* ci = mInstance[mCurrentMode];
-	POLY_ASSERT(!ci->getEnabled());
-
-	LogManager::getSingleton().logMessage("Current Mode: ");
-	LogManager::getSingleton().logMessage(ci->getCompositor()->getName());
-}

PolyMain/include/render/PolyDeferredShading.h

-/*
------------------------------------------------------------------------------
-This source file is part of OGRE
-(Object-oriented Graphics Rendering Engine)
-For the latest info, see http://www.ogre3d.org/
-
-Copyright (c) 2000-2012 Torus Knot Software Ltd
-Also see acknowledgements in Readme.html
-
-You may use this sample code for anything you like, it is not covered by the
-same license as the rest of the engine.
------------------------------------------------------------------------------
-*/
-
-/**
-Implementation of a Deferred Shading engine in OGRE, using Multiple Render Targets and
-CG high level language shaders.
-	// W.J. :wumpus: van der Laan 2005 / Noam Gat 2009 //
-
-Deferred shading renders the scene to a 'fat' texture format, using a shader that outputs colour, 
-normal, depth, and possible other attributes per fragment. Multi Render Target is required as we 
-are dealing with many outputs which get written into multiple render textures in the same pass.
-
-After rendering the scene in this format, the shading (lighting) can be done as a post process. 
-This means that lighting is done in screen space, using light-representing geometry (sphere for
-point light, cone for spot light and quad for directional) to render their contribution.
-
-The wiki article explaining this demo can be found here :
-  http://www.ogre3d.org/wiki/index.php/Deferred_Shading
-*/
-
-#ifndef H_DeferredShadingSystem
-#define H_DeferredShadingSystem
-
-#include "Ogre.h"
-
-#include "OgreCompositorInstance.h"
-#include "OgreSceneManager.h"
-#include "OgreSceneNode.h"
-#include "OgreMaterial.h"
-#include "OgreRenderTargetListener.h"
-#include "PolyGeomUtils.h"
-
-using namespace Ogre;
-
-/** System to manage Deferred Shading for a camera/render target.
- *  @note With the changes to the compositor framework, this class just
- *		selects which compositors to enable.
- */
-class DeferredShadingSystem : public Ogre::RenderTargetListener {
-public:
-	enum DSMode {
-		DSM_SHOWLIT = 0,     // The deferred shading mode
-		DSM_SHOWCOLOUR = 1,  // Show diffuse (for debugging)
-		DSM_SHOWNORMALS = 2, // Show normals (for debugging)
-		DSM_SHOWDSP = 3,	 // Show depth and specular channel (for debugging)
-		DSM_COUNT = 4
-	};
-
-	//The first render queue that does get rendered into the GBuffer
-	//place objects (like skies) that should be before gbuffer before this one.
-	static const Ogre::uint8 PRE_GBUFFER_RENDER_QUEUE;
-
-	//The first render queue that does not get rendered into the GBuffer
-	//place transparent (or other non gbuffer) objects after this one
-	static const Ogre::uint8 POST_GBUFFER_RENDER_QUEUE;
-
-					DeferredShadingSystem(Ogre::Viewport *vp, Ogre::SceneManager *sm, Ogre::Camera *cam);
-					~DeferredShadingSystem();
-
-	void			initialize();
-
-	/** Set rendering mode (one of DSMode)
-	 */
-	void			setMode(DSMode mode);
-	DSMode			getMode(void) const;
-
-	/** Activate or deactivate system
-	 */
-	void			setActive(bool active);
-	
-protected:
-	Ogre::Viewport* mViewport;
-	Ogre::SceneManager* mSceneMgr;
-	Ogre::Camera*	mCamera;
-	
-	Ogre::CompositorInstance* mGBufferInstance;
-
-	// Filters
-	Ogre::CompositorInstance* mInstance[DSM_COUNT];
-
-	// Active/inactive
-	bool			mActive;
-	DSMode			mCurrentMode;
-
-	//Used to unregister compositor logics and free memory
-	typedef Poly::map<String, CompositorLogic*>::type CompositorLogicMap;
-	CompositorLogicMap mCompositorLogics;
-
-	void			createResources();
-	
-	void			logCurrentMode();
-};
-
-const ColourValue SAMPLE_COLORS[] = 
-{   ColourValue::Red, ColourValue::Green, ColourValue::Blue, 
-    ColourValue::White, ColourValue(1,1,0,1), ColourValue(1,0,1,1)
-};
-
-#endif

PolyMain/include/render/PolyGBufferMaterialGenerator.cpp

-/*
------------------------------------------------------------------------------
-This source file is part of OGRE
-(Object-oriented Graphics Rendering Engine)
-For the latest info, see http://www.ogre3d.org/
-
-Copyright (c) 2000-2012 Torus Knot Software Ltd
-Also see acknowledgements in Readme.html
-
-You may use this sample code for anything you like, it is not covered by the
-same license as the rest of the engine.
------------------------------------------------------------------------------
-*/
-
-#include "PolyPrerequisites.h"
-#include "OgreMaterialManager.h"
-#include "OgreGpuProgramManager.h"
-#include "OgreStringConverter.h"
-#include "OgreHighLevelGpuProgramManager.h"
-#include "OgreTechnique.h"
-
-#include "render/PolyGBufferMaterialGenerator.h"
-
-
-//Use this directive to control whether you are writing projective (regular) or linear depth.
-#define WRITE_LINEAR_DEPTH
-
-//This is the concrete implementation of the material generator.
-class GBufferMaterialGeneratorImpl : public MaterialGenerator::Impl {
-public:
-	GBufferMaterialGeneratorImpl(const Ogre::String& baseName) : mBaseName(baseName) {}
-	
-protected:
-	Ogre::String mBaseName;
-	virtual Ogre::GpuProgramPtr generateVertexShader(MaterialGenerator::Perm permutation);
-	virtual Ogre::GpuProgramPtr generateFragmentShader(MaterialGenerator::Perm permutation);
-	virtual Ogre::MaterialPtr generateTemplateMaterial(MaterialGenerator::Perm permutation);
-
-};
-
-GBufferMaterialGenerator::GBufferMaterialGenerator() {
-	vsMask = VS_MASK;
-	fsMask = FS_MASK;
-	matMask = MAT_MASK;
-	materialBaseName = "DeferredShading/GBuffer/";
-	mImpl = new GBufferMaterialGeneratorImpl(materialBaseName);
-}
-
-Ogre::GpuProgramPtr GBufferMaterialGeneratorImpl::generateVertexShader(MaterialGenerator::Perm permutation) {
-	Ogre::StringStream ss;
-	
-	ss << "void ToGBufferVP(" << std::endl;
-	ss << "	float4 iPosition : POSITION," << std::endl;
-	ss << "	float3 iNormal   : NORMAL," << std::endl;
-
-	Ogre::uint32 numTexCoords = (permutation & GBufferMaterialGenerator::GBP_TEXCOORD_MASK) >> 8;
-	for (Ogre::uint32 i=0; i<numTexCoords; i++) {
-		ss << "	float2 iUV" << i << " : TEXCOORD" << i << ',' << std::endl;
-	}
-
-	if (permutation & GBufferMaterialGenerator::GBP_NORMAL_MAP) {
-		ss << "	float3 iTangent : TANGENT0," << std::endl;
-	}
-
-	//TODO : Skinning inputs
-	ss << std::endl;
-	
-
-
-	ss << "	out float4 oPosition : POSITION," << std::endl;
-#ifdef WRITE_LINEAR_DEPTH
-    ss << "	out float3 oViewPos : TEXCOORD0," << std::endl;
-#else
-	ss << "	out float oDepth : TEXCOORD0," << std::endl;
-#endif
-	ss << "	out float3 oNormal : TEXCOORD1," << std::endl;
-	int texCoordNum = 2;
-	if (permutation & GBufferMaterialGenerator::GBP_NORMAL_MAP) {
-		ss << "	out float3 oTangent : TEXCOORD" << texCoordNum++ << ',' << std::endl;
-		ss << "	out float3 oBiNormal : TEXCOORD" << texCoordNum++ << ',' << std::endl;
-	}
-	for (Ogre::uint32 i=0; i<numTexCoords; i++) {
-		ss << "	out float2 oUV" << i << " : TEXCOORD" << texCoordNum++ << ',' << std::endl;
-	}
-
-	ss << std::endl;
-
-	ss << "	uniform float4x4 cWorldViewProj," << std::endl;
-	ss << "	uniform float4x4 cWorldView" << std::endl;
-
-	ss << "	)" << std::endl;
-	
-	
-	ss << "{" << std::endl;
-	ss << "	oPosition = mul(cWorldViewProj, iPosition);" << std::endl;
-	ss << "	oNormal = mul(cWorldView, float4(iNormal,0)).xyz;" << std::endl;
-	if (permutation & GBufferMaterialGenerator::GBP_NORMAL_MAP) {
-		ss << "	oTangent = mul(cWorldView, float4(iTangent,0)).xyz;" << std::endl;
-		ss << "	oBiNormal = cross(oNormal, oTangent);" << std::endl;
-	}
-
-#ifdef WRITE_LINEAR_DEPTH
-    ss << "	oViewPos = mul(cWorldView, iPosition).xyz;" << std::endl;
-#else
-	ss << "	oDepth = oPosition.w;" << std::endl;
-#endif
-
-	for (Ogre::uint32 i=0; i<numTexCoords; i++) {
-		ss << "	oUV" << i << " = iUV" << i << ';' << std::endl;
-	}
-
-	ss << "}" << std::endl;
-	
-	Ogre::String programSource = ss.str();
-	Ogre::String programName = mBaseName + "VP_" + Ogre::StringConverter::toString(permutation);
-
-#if OGRE_DEBUG_MODE
-	Ogre::LogManager::getSingleton().getDefaultLog()->logMessage(programSource);
-#endif
-
-	// Create shader object
-	Ogre::HighLevelGpuProgramPtr ptrProgram = Ogre::HighLevelGpuProgramManager::getSingleton().createProgram(
-		programName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
-		"cg", Ogre::GPT_VERTEX_PROGRAM);
-	ptrProgram->setSource(programSource);
-	ptrProgram->setParameter("entry_point","ToGBufferVP");
-	ptrProgram->setParameter("profiles","vs_1_1 arbvp1");
-
-	const Ogre::GpuProgramParametersSharedPtr& params = ptrProgram->getDefaultParameters();
-	params->setNamedAutoConstant("cWorldViewProj", Ogre::GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX);
-	params->setNamedAutoConstant("cWorldView", Ogre::GpuProgramParameters::ACT_WORLDVIEW_MATRIX);
-	ptrProgram->load();
-
-	return Ogre::GpuProgramPtr(ptrProgram);
-}
-
-Ogre::GpuProgramPtr GBufferMaterialGeneratorImpl::generateFragmentShader(MaterialGenerator::Perm permutation) {
-	Ogre::StringStream ss;
-	
-	ss << "void ToGBufferFP(" << std::endl;
-#ifdef WRITE_LINEAR_DEPTH
-    ss << "	float3 iViewPos : TEXCOORD0," << std::endl;
-#else
-    ss << "	float1 iDepth : TEXCOORD0," << std::endl;
-#endif
-	ss << "	float3 iNormal   : TEXCOORD1," << std::endl;
-
-	int texCoordNum = 2;
-	if (permutation & GBufferMaterialGenerator::GBP_NORMAL_MAP) {
-		ss << "	float3 iTangent : TEXCOORD" << texCoordNum++ << ',' << std::endl;
-		ss << "	float3 iBiNormal : TEXCOORD" << texCoordNum++ << ',' << std::endl;
-	}
-
-	Ogre::uint32 numTexCoords = (permutation & GBufferMaterialGenerator::GBP_TEXCOORD_MASK) >> 8;
-	for (Ogre::uint32 i=0; i<numTexCoords; i++) {
-		ss << "	float2 iUV" << i << " : TEXCOORD" << texCoordNum++ << ',' << std::endl;
-	}
-
-	ss << std::endl;
-
-	ss << "	out float4 oColor0 : COLOR0," << std::endl;
-	ss << "	out float4 oColor1 : COLOR1," << std::endl;
-
-	ss << std::endl;
-
-	int samplerNum = 0;
-	if (permutation & GBufferMaterialGenerator::GBP_NORMAL_MAP) {
-		ss << "	uniform sampler sNormalMap : register(s" << samplerNum++ << ")," << std::endl;
-	}
-	Ogre::uint32 numTextures = permutation & GBufferMaterialGenerator::GBP_TEXTURE_MASK;
-	for (Ogre::uint32 i=0; i<numTextures; i++) {
-		ss << "	uniform sampler sTex" << i << " : register(s" << samplerNum++ << ")," << std::endl;
-	}
-    if (numTextures == 0 || permutation & GBufferMaterialGenerator::GBP_HAS_DIFFUSE_COLOUR) {
-		ss << "	uniform float4 cDiffuseColour," << std::endl;
-	}
-
-#ifdef WRITE_LINEAR_DEPTH
-    ss << "	uniform float cFarDistance," << std::endl;
-#endif
-	
-	ss << "	uniform float cSpecularity" << std::endl;
-
-	ss << "	)" << std::endl;
-	
-	
-	ss << "{" << std::endl;
-
-	if (numTexCoords > 0 && numTextures > 0) {
-		ss << "	oColor0.rgb = tex2D(sTex0, iUV0);" << std::endl;
-        if (permutation & GBufferMaterialGenerator::GBP_HAS_DIFFUSE_COLOUR) {
-            ss << "	oColor0.rgb *= cDiffuseColour.rgb;" << std::endl;
-        }
-	}
-    else {
-		ss << "	oColor0.rgb = cDiffuseColour.rgb;" << std::endl;
-	}
-    
-	
-	ss << "	oColor0.a = cSpecularity;" << std::endl;
-	if (permutation & GBufferMaterialGenerator::GBP_NORMAL_MAP) {
-		ss << "	float3 texNormal = (tex2D(sNormalMap, iUV0)-0.5)*2;" << std::endl;
-		ss << "	float3x3 normalRotation = float3x3(iTangent, iBiNormal, iNormal);" << std::endl;
-		ss << "	oColor1.rgb = normalize(mul(texNormal, normalRotation));" << std::endl;
-	} else {
-		ss << "	oColor1.rgb = normalize(iNormal);" << std::endl;
-	}
-#ifdef WRITE_LINEAR_DEPTH
-    ss << "	oColor1.a = length(iViewPos) / cFarDistance;" << std::endl;
-#else
-    ss << "	oColor1.a = iDepth;" << std::endl;
-#endif
-
-	ss << "}" << std::endl;
-	
-	Ogre::String programSource = ss.str();
-	Ogre::String programName = mBaseName + "FP_" + Ogre::StringConverter::toString(permutation);
-
-#if OGRE_DEBUG_MODE
-	Ogre::LogManager::getSingleton().getDefaultLog()->logMessage(programSource);
-#endif
-
-	// Create shader object
-	Ogre::HighLevelGpuProgramPtr ptrProgram = Ogre::HighLevelGpuProgramManager::getSingleton().createProgram(
-		programName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
-		"cg", Ogre::GPT_FRAGMENT_PROGRAM);
-	ptrProgram->setSource(programSource);
-	ptrProgram->setParameter("entry_point","ToGBufferFP");
-	ptrProgram->setParameter("profiles","ps_2_0 arbfp1");
-
-	const Ogre::GpuProgramParametersSharedPtr& params = ptrProgram->getDefaultParameters();
-	params->setNamedAutoConstant("cSpecularity", Ogre::GpuProgramParameters::ACT_SURFACE_SHININESS);
-	if (numTextures == 0 || permutation & GBufferMaterialGenerator::GBP_HAS_DIFFUSE_COLOUR) {
-		params->setNamedAutoConstant("cDiffuseColour", Ogre::GpuProgramParameters::ACT_SURFACE_DIFFUSE_COLOUR);
-	}
-
-#ifdef WRITE_LINEAR_DEPTH
-    //TODO : Should this be the distance to the far corner, not the far clip distance?
-    params->setNamedAutoConstant("cFarDistance", Ogre::GpuProgramParameters::ACT_FAR_CLIP_DISTANCE);
-#endif
-
-	ptrProgram->load();
-	return Ogre::GpuProgramPtr(ptrProgram);
-}
-
-Ogre::MaterialPtr GBufferMaterialGeneratorImpl::generateTemplateMaterial(MaterialGenerator::Perm permutation) {
-	Ogre::String matName = mBaseName + "Mat_" + Ogre::StringConverter::toString(permutation);
-
-	Ogre::MaterialPtr matPtr = Ogre::MaterialManager::getSingleton().create
-		(matName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
-	Ogre::Pass* pass = matPtr->getTechnique(0)->getPass(0);
-	pass->setName(mBaseName + "Pass_" + Ogre::StringConverter::toString(permutation));
-	pass->setLightingEnabled(false);
-	if (permutation & GBufferMaterialGenerator::GBP_NORMAL_MAP) {
-		pass->createTextureUnitState();
-	}
-
-	Ogre::uint32 numTextures = permutation & GBufferMaterialGenerator::GBP_TEXTURE_MASK;
-	for (Ogre::uint32 i=0; i<numTextures; i++) {
-		pass->createTextureUnitState();
-	}
-
-	return matPtr;
-}

PolyMain/include/render/PolyGBufferMaterialGenerator.h

-/*
------------------------------------------------------------------------------
-This source file is part of OGRE
-(Object-oriented Graphics Rendering Engine)
-For the latest info, see http://www.ogre3d.org/
-
-Copyright (c) 2000-2012 Torus Knot Software Ltd
-Also see acknowledgements in Readme.html
-
-You may use this sample code for anything you like, it is not covered by the
-same license as the rest of the engine.
------------------------------------------------------------------------------
-*/
-
-
-#ifndef _GBUFFER_MATERIAL_GENERATOR_H_
-#define _GBUFFER_MATERIAL_GENERATOR_H_
-
-#include "PolyMaterialGenerator.h"
-
-/** Class for generating materials for objects to render themselves to the GBuffer
- *  @note This does not support all the possible rendering techniques out there.
- *  in order to support more, either expand this class or make sure that objects
- *  that will not get treated correctly will not have materials generated for them.
- */
-class GBufferMaterialGenerator : public MaterialGenerator {
-public:
-	
-	//Constructor
-	GBufferMaterialGenerator();
-
-	//The relevant options for objects that are rendered to the GBuffer
-	enum GBufferPermutations {
-		//(Regular) Textures
-		GBP_NO_TEXTURES =			0x00000000,
-		GBP_ONE_TEXTURE =			0x00000001,
-		GBP_TWO_TEXTURES =			0x00000002,
-		GBP_THREE_TEXTURES =		0x00000003,
-		GBP_TEXTURE_MASK =			0x0000000F,
-		
-        //Material properties
-        GBP_HAS_DIFFUSE_COLOUR =     0x00000010,
-
-		//The number of texture coordinate sets
-		GBP_NO_TEXCOORDS =			0x00000000,
-		GBP_ONE_TEXCOORD =			0x00000100,
-		GBP_TWO_TEXCOORDS =			0x00000200,
-		GBP_TEXCOORD_MASK =			0x00000700,
-
-		//Do we have a normal map
-		GBP_NORMAL_MAP =			0x00000800,
-
-		//Are we skinned?
-		GBP_SKINNED =				0x00010000
-	};
-	
-	//The mask of the flags that matter for generating the fragment shader
-	static const Ogre::uint32 FS_MASK =		0x0000FFFF;
-	
-	//The mask of the flags that matter for generating the vertex shader
-	static const Ogre::uint32 VS_MASK =		0x00FFFF00;
-	
-	//The mask of the flags that matter for generating the material
-	static const Ogre::uint32 MAT_MASK =	0xFF00FFFF;
-};
-
-#endif

PolyMain/include/render/PolyGBufferSchemeHandler.cpp

-/*
------------------------------------------------------------------------------
-This source file is part of OGRE
-(Object-oriented Graphics Rendering Engine)
-For the latest info, see http://www.ogre3d.org/
-
-Copyright (c) 2000-2012 Torus Knot Software Ltd
-Also see acknowledgements in Readme.html
-
-You may use this sample code for anything you like, it is not covered by the
-same license as the rest of the engine.
------------------------------------------------------------------------------
-*/
-
-#include "PolyPrerequisites.h"
-#include <OgreMaterialManager.h>
-#include <OgreTechnique.h>
-
-#include "render/PolyGBufferSchemeHandler.h"
-
-
-using namespace Ogre;
-
-const String GBufferSchemeHandler::NORMAL_MAP_PATTERN = "normal";
-
-Technique* GBufferSchemeHandler::handleSchemeNotFound(unsigned short schemeIndex, 
-		const String& schemeName, Material* originalMaterial, unsigned short lodIndex, 
-		const Renderable* rend)
-{
-	Ogre::MaterialManager& matMgr = Ogre::MaterialManager::getSingleton();
-	String curSchemeName = matMgr.getActiveScheme();
-	matMgr.setActiveScheme(MaterialManager::DEFAULT_SCHEME_NAME);
-	Technique* originalTechnique = originalMaterial->getBestTechnique(lodIndex, rend);
-	matMgr.setActiveScheme(curSchemeName);
-
-	Technique* gBufferTech = originalMaterial->createTechnique();
-	gBufferTech->removeAllPasses();
-	gBufferTech->setSchemeName(schemeName);
-
-	Technique* noGBufferTech = originalMaterial->createTechnique();
-	noGBufferTech->removeAllPasses();
-	noGBufferTech->setSchemeName("NoGBuffer");
-
-	for (unsigned short i=0; i<originalTechnique->getNumPasses(); i++)
-	{
-		Pass* originalPass = originalTechnique->getPass(i);
-		PassProperties props = inspectPass(originalPass, lodIndex, rend);
-		
-		if (!props.isDeferred)
-		{
-			//Just copy the technique so it gets rendered regularly
-			Pass* clonePass = noGBufferTech->createPass();
-			*clonePass = *originalPass;
-			continue;
-		}
-
-		Pass* newPass = gBufferTech->createPass();
-		MaterialGenerator::Perm perm = getPermutation(props);
-
-		const Ogre::MaterialPtr& templateMat = mMaterialGenerator.getMaterial(perm);
-    	
-		//We assume that the GBuffer technique contains only one pass. But its true.
-		*newPass = *(templateMat->getTechnique(0)->getPass(0));
-		fillPass(newPass, originalPass, props);    
-	}
-    
-	return gBufferTech;
-}
-
-bool GBufferSchemeHandler::checkNormalMap(
-	TextureUnitState* tus, GBufferSchemeHandler::PassProperties& props)
-{
-	bool isNormal = false;
-	Ogre::String lowerCaseAlias = tus->getTextureNameAlias();
-	Ogre::StringUtil::toLowerCase(lowerCaseAlias);
-	if (lowerCaseAlias.find(NORMAL_MAP_PATTERN) != Ogre::String::npos)
-	{
-		isNormal = true;
-	}
-	else 
-	{
-		Ogre::String lowerCaseName = tus->getTextureName();
-		Ogre::StringUtil::toLowerCase(lowerCaseName);
-		if (lowerCaseName.find(NORMAL_MAP_PATTERN) != Ogre::String::npos)
-		{
-			isNormal = true;
-		}
-	}
-
-	if (isNormal)
-	{
-		if (props.normalMap == 0)
-		{
-			props.normalMap = tus;
-		}
-		else
-		{
-			OGRE_EXCEPT(Exception::ERR_DUPLICATE_ITEM,
-				"Multiple normal map patterns matches",
-				"GBufferSchemeHandler::inspectPass");
-		}
-	}
-	return isNormal;
-}
-
-GBufferSchemeHandler::PassProperties GBufferSchemeHandler::inspectPass(
-	Pass* pass, unsigned short lodIndex, const Renderable* rend)
-{
-	PassProperties props;
-	
-	//TODO : Use renderable to indicate wether this has skinning.
-	//Probably use same const cast that renderSingleObject uses.
-	if (pass->hasVertexProgram())
-	{
-		props.isSkinned = pass->getVertexProgram()->isSkeletalAnimationIncluded();
-	}
-	else 
-	{
-		props.isSkinned = false;
-	}
-
-	for (unsigned short i=0; i<pass->getNumTextureUnitStates(); i++) 
-	{
-		TextureUnitState* tus = pass->getTextureUnitState(i);
-		if (!checkNormalMap(tus, props))
-		{
-			props.regularTextures.push_back(tus);
-		}
-		if (tus->getEffects().size() > 0)
-		{
-			props.isDeferred = false;
-		}
-		
-	}
-
-    if (pass->getDiffuse() != ColourValue::White)
-    {
-        props.hasDiffuseColour = true;
-    }
-
-    //Check transparency
-    if (pass->getDestBlendFactor() != Ogre::SBF_ZERO)
-    {
-        //TODO : Better ways to do this
-        props.isDeferred = false;
-    }
-	return props;
-}
-
-MaterialGenerator::Perm GBufferSchemeHandler::getPermutation(const PassProperties& props)
-{
-	MaterialGenerator::Perm perm = 0;
-	switch (props.regularTextures.size())
-	{
-	case 0:
-		perm |= GBufferMaterialGenerator::GBP_NO_TEXTURES;
-		
-		if (props.normalMap != 0)
-		{
-			perm |= GBufferMaterialGenerator::GBP_ONE_TEXCOORD;
-		}
-		else
-		{
-			perm |= GBufferMaterialGenerator::GBP_NO_TEXCOORDS;
-		}
-		break;
-	case 1:
-		perm |= GBufferMaterialGenerator::GBP_ONE_TEXTURE;
-		perm |= GBufferMaterialGenerator::GBP_ONE_TEXCOORD;
-		break;
-	case 2:
-		perm |= GBufferMaterialGenerator::GBP_TWO_TEXTURES;
-		//TODO : When do we use two texcoords?
-		perm |= GBufferMaterialGenerator::GBP_ONE_TEXCOORD;
-		break;
-	case 3:
-		perm |= GBufferMaterialGenerator::GBP_THREE_TEXTURES;
-		perm |= GBufferMaterialGenerator::GBP_ONE_TEXCOORD;
-		break;
-	default:
-		OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED,
-			"Can not generate G-Buffer materials for '>3 regular-texture' objects",
-			"GBufferSchemeHandler::inspectPass");
-	}
-
-	if (props.isSkinned)
-	{
-		perm |= GBufferMaterialGenerator::GBP_SKINNED;
-	}
-
-	if (props.normalMap != 0)
-	{
-		perm |= GBufferMaterialGenerator::GBP_NORMAL_MAP;
-	}
-
-    if (props.hasDiffuseColour)
-    {
-        perm |= GBufferMaterialGenerator::GBP_HAS_DIFFUSE_COLOUR;
-    }
-	return perm;
-}
-
-void GBufferSchemeHandler::fillPass(
-	Pass* gBufferPass, Pass* originalPass, const PassProperties& props)
-{
-	//Reference the correct textures. Normal map first!
-	int texUnitIndex = 0;
-	if (props.normalMap != 0)
-	{
-		*(gBufferPass->getTextureUnitState(texUnitIndex)) = *(props.normalMap);
-		texUnitIndex++;
-	}
-	for (size_t i=0; i<props.regularTextures.size(); i++)
-	{
-		*(gBufferPass->getTextureUnitState(texUnitIndex)) = *(props.regularTextures[i]);
-		texUnitIndex++;
-	}
-	gBufferPass->setAmbient(originalPass->getAmbient());
-	gBufferPass->setDiffuse(originalPass->getDiffuse());
-	gBufferPass->setSpecular(originalPass->getSpecular());
-	gBufferPass->setShininess(originalPass->getShininess());
-    gBufferPass->setCullingMode(originalPass->getCullingMode());
-    gBufferPass->setLightingEnabled(false);
-}

PolyMain/include/render/PolyGBufferSchemeHandler.h

-/*
------------------------------------------------------------------------------
-This source file is part of OGRE
-(Object-oriented Graphics Rendering Engine)
-For the latest info, see http://www.ogre3d.org/
-
-Copyright (c) 2000-2012 Torus Knot Software Ltd
-Also see acknowledgements in Readme.html
-
-You may use this sample code for anything you like, it is not covered by the
-same license as the rest of the engine.
------------------------------------------------------------------------------
-*/
-
-
-#ifndef _GBUFFERSCHEMEHANDLER_H
-#define _GBUFFERSCHEMEHANDLER_H
-
-#include <OgreMaterialManager.h>
-#include "PolyGBufferMaterialGenerator.h"
-
-/** Class for handling materials who did not specify techniques for rendering
- *  themselves into the GBuffer. This class allows deferred shading to be used,
- *  without having to specify new techniques for all the objects in the scene.
- *  @note This does not support all the possible rendering techniques out there.
- *  in order to support more, either expand this class or specify the techniques
- *  in the materials.
- */
-class GBufferSchemeHandler : public Ogre::MaterialManager::Listener {
-public:
-	/** @copydoc MaterialManager::Listener::handleSchemeNotFound */
-	virtual Ogre::Technique* handleSchemeNotFound(unsigned short schemeIndex, 
-		const Ogre::String& schemeName, Ogre::Material* originalMaterial, unsigned short lodIndex, 
-		const Ogre::Renderable* rend);
-protected:
-	//The material generator
-	GBufferMaterialGenerator mMaterialGenerator;
-	
-	//The string that will be checked in textures to determine whether they are normal maps
-	static const Ogre::String NORMAL_MAP_PATTERN;
-
-	//A structure for containing the properties of a material, relevant to GBuffer rendering
-	//You might need to expand this class to support more options
-	struct PassProperties {
-		PassProperties() : isDeferred(true), normalMap(0), isSkinned(false) {}
-
-		bool isDeferred;
-		Ogre::vector<Ogre::TextureUnitState*>::type regularTextures;
-		Ogre::TextureUnitState* normalMap;
-		bool isSkinned;
-        bool hasDiffuseColour;
-		
-		//Example of possible extension : vertex colours
-		//Ogre::TrackVertexColourType vertexColourType;
-	};
-
-	//Inspect a technique and return its relevant properties
-	PassProperties inspectPass(Ogre::Pass* pass, 
-		unsigned short lodIndex, const Ogre::Renderable* rend);
-
-	//Get the permutation of material flags that fit a certain property sheet
-	MaterialGenerator::Perm getPermutation(const PassProperties& props);
-
-	//Fill a pass with the specific data from the pass it is based on
-	void fillPass(Ogre::Pass* gBufferPass, Ogre::Pass* originalPass, const PassProperties& props);
-
-	//Check if a texture is a normal map, and fill property sheet accordingly
-	bool checkNormalMap(Ogre::TextureUnitState* tus, PassProperties& props);
-};
-
-#endif

PolyMain/include/render/PolyGeomUtils.cpp

-/*
------------------------------------------------------------------------------
-This source file is part of OGRE
-(Object-oriented Graphics Rendering Engine)
-For the latest info, see http://www.ogre3d.org/
-
-Copyright (c) 2000-2012 Torus Knot Software Ltd
-Also see acknowledgements in Readme.html
-
-You may use this sample code for anything you like, it is not covered by the
-same license as the rest of the engine.
------------------------------------------------------------------------------
-*/
-
-
-#include "PolyPrerequisites.h"
-#include "OgreMeshManager.h"
-#include "OgreSubMesh.h"
-#include "OgreHardwareBufferManager.h"
-
-#include "render/PolyGeomUtils.h"
-
-
-using namespace Ogre;
-
-void GeomUtils::createSphere(  const String& strName
-							 , float radius
-							 , int nRings, int nSegments
-							 , bool bNormals
-							 , bool bTexCoords)
-{
-	MeshPtr pSphere = MeshManager::getSingleton().createManual(strName, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
-	SubMesh *pSphereVertex = pSphere->createSubMesh();
-	pSphere->sharedVertexData = new VertexData();
-
-	createSphere(pSphere->sharedVertexData, pSphereVertex->indexData
-		, radius
-		, nRings, nSegments
-		, bNormals // need normals
-		, bTexCoords // need texture co-ordinates
-		);
-
-	// Generate face list
-	pSphereVertex->useSharedVertices = true;
-
-	// the original code was missing this line:
-	pSphere->_setBounds( AxisAlignedBox( Vector3(-radius, -radius, -radius), Vector3(radius, radius, radius) ), false );
-	pSphere->_setBoundingSphereRadius(radius);
-	// this line makes clear the mesh is loaded (avoids memory leaks)
-	pSphere->load();
-}
-
-void GeomUtils::createSphere(VertexData*& vertexData, IndexData*& indexData
-						 , float radius
-						 , int nRings, int nSegments
-						 , bool bNormals
-						 , bool bTexCoords)
-{
-	POLY_ASSERT(vertexData && indexData);
-
-	// define the vertex format
-	VertexDeclaration* vertexDecl = vertexData->vertexDeclaration;
-	size_t currOffset = 0;
-	// positions