From: <Hex...@us...> - 2008-07-02 04:51:09
|
Revision: 2459 http://ogreaddons.svn.sourceforge.net/ogreaddons/?rev=2459&view=rev Author: HexiDave Date: 2008-07-01 21:51:10 -0700 (Tue, 01 Jul 2008) Log Message: ----------- Some new toys along with some updates. 50% done on the SceneObject system, which lets you automate a lot of game-object processes and adds the object to the scene with atmospheric scattering built in. Still working on documentation - lots to do still, so don't want to mess everything up now. Modified Paths: -------------- trunk/simplepagedterrain/trunk/bin/Release/SPT2_Demo.exe trunk/simplepagedterrain/trunk/bin/Release/resources.cfg trunk/simplepagedterrain/trunk/demo/include/SPT_Demo.h trunk/simplepagedterrain/trunk/library/include/Prerequisites.h trunk/simplepagedterrain/trunk/library/include/Terrain.h trunk/simplepagedterrain/trunk/library/scripts/SPTv2.vcproj trunk/simplepagedterrain/trunk/library/src/PNGHeightmapReader.cpp trunk/simplepagedterrain/trunk/library/src/Terrain.cpp trunk/simplepagedterrain/trunk/library/src/TerrainMesh.cpp trunk/simplepagedterrain/trunk/media/materials/Highlands.material Added Paths: ----------- trunk/simplepagedterrain/trunk/library/include/ObjectHandler.h trunk/simplepagedterrain/trunk/library/src/ObjectHandler.cpp trunk/simplepagedterrain/trunk/media/SPT2_Low.program trunk/simplepagedterrain/trunk/media/SPT2_Low.source trunk/simplepagedterrain/trunk/media/SPT2_Mat.material trunk/simplepagedterrain/trunk/media/SPT2_Medium.program trunk/simplepagedterrain/trunk/media/SPT2_Medium.source trunk/simplepagedterrain/trunk/media/SPT2_Shadow.program trunk/simplepagedterrain/trunk/media/SPT2_Shadow.source trunk/simplepagedterrain/trunk/media/materials/Ogre.material trunk/simplepagedterrain/trunk/media/materials/SPT2_Highlands.material trunk/simplepagedterrain/trunk/media/models/ trunk/simplepagedterrain/trunk/media/models/ogrehead.mesh trunk/simplepagedterrain/trunk/media/textures/Dirt.jpg trunk/simplepagedterrain/trunk/media/textures/GreenSkin.jpg trunk/simplepagedterrain/trunk/media/textures/WeirdEye.png trunk/simplepagedterrain/trunk/media/textures/spheremap.png Modified: trunk/simplepagedterrain/trunk/bin/Release/SPT2_Demo.exe =================================================================== (Binary files differ) Modified: trunk/simplepagedterrain/trunk/bin/Release/resources.cfg =================================================================== --- trunk/simplepagedterrain/trunk/bin/Release/resources.cfg 2008-07-01 15:10:10 UTC (rev 2458) +++ trunk/simplepagedterrain/trunk/bin/Release/resources.cfg 2008-07-02 04:51:10 UTC (rev 2459) @@ -8,6 +8,4 @@ FileSystem=../../media FileSystem=../../media/materials FileSystem=../../media/textures -FileSystem=../../PagedGeometry/media/grass -FileSystem=../../PagedGeometry/media/trees -FileSystem=../../PagedGeometry/media/trees2 \ No newline at end of file +FileSystem=../../media/models Modified: trunk/simplepagedterrain/trunk/demo/include/SPT_Demo.h =================================================================== --- trunk/simplepagedterrain/trunk/demo/include/SPT_Demo.h 2008-07-01 15:10:10 UTC (rev 2458) +++ trunk/simplepagedterrain/trunk/demo/include/SPT_Demo.h 2008-07-02 04:51:10 UTC (rev 2459) @@ -3,17 +3,21 @@ #include "AtmosphericCubeMap.h" #include "CircleDisplacement.h" #include "RectFlatten.h" +#include "ObjectHandler.h" #include <Ogre.h> +#include <fstream> + using namespace SPT; Terrain* gTerrain; Light* gSunLight; +// Kind of hacky, but can't use Camera as a Node +SceneNode* gFollowNode; - class MyFrameListener : public ExampleFrameListener { protected: @@ -56,6 +60,7 @@ vLightDir.normalise(); gTerrain->setLightDirection(vLightDir); + gSunLight->setDirection(vLightDir); mTimeUntilNextToggle = 0.2; @@ -80,6 +85,7 @@ pAtm->setMieCoef(0.1); gTerrain->setLightDirection(Vector3(0,0,1)); + gSunLight->setDirection(Vector3(0,0,1)); mTimeUntilNextToggle = 0.2; } @@ -106,7 +112,7 @@ // Randomly displaces the terrain as a big crater Vector3 pos = Vector3(Math::RangeRandom(-16000,16000),0.0f,Math::RangeRandom(-16000,16000)); - if (gTerrain->getHeightAt(pos,true,false)) + if (gTerrain->getHeightAt(pos,0.0f,true,false)) { Real radius = Math::RangeRandom(500,16000); Real power = Math::RangeRandom(-20000,20000); @@ -118,13 +124,14 @@ mTimeUntilNextToggle = 0.2; } + // Update our cheezy follow node + gFollowNode->setPosition(mCamera->getPosition()); + // Displays the current movement speed mDebugText = "Current speed: " + StringConverter::toString(mMoveSpeed) + " m/s"; - - return true; } @@ -171,7 +178,10 @@ // Set ambient light mSceneMgr->setAmbientLight(ColourValue(0.5,0.5,0.5)); + mCamera->getViewport()->setMaterialScheme("Medium"); + + gSunLight = mSceneMgr->createLight("Sun"); gSunLight->setType(Light::LT_DIRECTIONAL); gSunLight->setDirection(-0.808863, -0.488935, -0.326625); @@ -192,7 +202,7 @@ // Do a quick setup - gTerrain->quickSetup("Highlands_Height.png",2049,"SPT_Highlands",64000.0,6000.0); + gTerrain->quickSetup("Highlands_Height.png","SPT_Highlands",64000.0,6000.0); // All this handles the atmosphere @@ -232,6 +242,29 @@ // And you're done! + gFollowNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("ChaseNode"); + + const size_t iTotalOgreHeads = 50; + + SceneObject* pObj = 0; + Vector3 startPos = Vector3::ZERO; + + for (size_t i=0;i<iTotalOgreHeads;i++) + { + pObj = gTerrain->getObjectHandler()->createSceneObject("OgreHead" + StringConverter::toString(i),"ogrehead.mesh"); + pObj->setAutoClampState(Terrain::ACS_ALWAYS); + pObj->useBoundingBoxBase(); + pObj->biasHeightBonus(-2.0f); + pObj->setTargetNode(gFollowNode,(Math::RangeRandom(-50,50) > 0.0f) ? true : false); + startPos.x = Math::RangeRandom(-32000,32000); + startPos.z = Math::RangeRandom(-32000,32000); + pObj->moveObject(startPos); + pObj->setAutoClampTime(Math::RangeRandom(0.0f,5.0f)); + pObj->setAutoRotateTime(Math::RangeRandom(0.0f,2.0f)); + } + + + } void createFrameListener() Added: trunk/simplepagedterrain/trunk/library/include/ObjectHandler.h =================================================================== --- trunk/simplepagedterrain/trunk/library/include/ObjectHandler.h (rev 0) +++ trunk/simplepagedterrain/trunk/library/include/ObjectHandler.h 2008-07-02 04:51:10 UTC (rev 2459) @@ -0,0 +1,184 @@ +#pragma once + +#include <OgrePrerequisites.h> +#include <OgreMaterial.h> +#include <OgreVector3.h> +#include <OgreSceneNode.h> +#include "Prerequisites.h" +#include "Terrain.h" +#if (USE_SINGLETON == 1) +#include <OgreSingleton.h> +#endif + +namespace SPT +{ + class Terrain; + class ObjectHandler; + + class SceneObject + { + public: + + SceneObject( + ObjectHandler* objectHandler, + Ogre::MovableObject* movableObject, + Ogre::SceneNode* sceneNode, + Terrain::AutoClampState autoClampState, + Ogre::Real heightBonus); + + ~SceneObject(); + + void update(Ogre::Real fTime); + + Ogre::MovableObject* getObject() const { return mObject; } + + Ogre::SceneNode* getSceneNode() const { return mSceneNode; } + + ObjectHandler* getObjectHandler() const { return mObjectHandler; } + + Terrain::AutoClampState getAutoClampState() const { return mAutoClampState; } + void setAutoClampState(Terrain::AutoClampState val) { mAutoClampState = val; } + + Ogre::Real getAutoClampTime() const { return mAutoClampTime; } + void setAutoClampTime(Ogre::Real val) { mAutoClampTime = val; } + + Ogre::Real getHeightBonus() const { return mHeightBonus; } + void setHeightBonus(Ogre::Real val) { mHeightBonus = val; } + + void useBoundingBoxBase(); + + void biasHeightBonus(Ogre::Real val) {mHeightBonus += val;} + void biasHeightBonusPercent(Ogre::Real percent); + + void moveObject(const Ogre::Vector3& pos = Ogre::Vector3::ZERO); + void translateObject(const Ogre::Vector3& translation = Ogre::Vector3::ZERO); + + void setRotation(const Ogre::Quaternion& rotation = Ogre::Quaternion::IDENTITY); + + void rotateXZ(const Ogre::Degree rotation = Ogre::Degree() ); + + Ogre::Vector3 getOriginalDirection() const { return mOriginalDirection; } + void setOriginalDirection(const Ogre::Vector3& val = Ogre::Vector3::UNIT_Z) { mOriginalDirection = val; } + + void turnTowardsPoint(const Ogre::Vector3& target, bool useXZFirst = true); + + void turnTowardsPointXZ(const Ogre::Vector3& target); + + Ogre::Node* getTargetNode() const { return mTargetNode; } + void setTargetNode( Ogre::Node* val = 0, bool useXZRotationOnly = true) + { + mTargetNode = val; + mTargetXZRotationOnly = useXZRotationOnly; + } + + Ogre::Real getAutoRotateTime() const { return mAutoRotateTime; } + void setAutoRotateTime(Ogre::Real val) { mAutoRotateTime = val; } + + private: + Ogre::MovableObject* mObject; + + Ogre::SceneNode* mSceneNode; + Ogre::Vector3 mOriginalDirection; + Ogre::Node* mTargetNode; + bool mTargetXZRotationOnly; + + Ogre::Real mHeightBonus; + ObjectHandler* mObjectHandler; + + Ogre::Real mAutoClampTime; + + Ogre::Real mCurClampTime; + Ogre::Real mAutoRotateTime; + Ogre::Real mCurRotateTime; + + Terrain::AutoClampState mAutoClampState; + }; + +#if (USE_SINGLETON == 1) + class ObjectHandler : public Ogre::Singleton<ObjectHandler> +#else + class ObjectHandler +#endif + { + public: + ObjectHandler(); + ObjectHandler(Ogre::SceneManager* pSceneMgr, Terrain* pTerrain); + + ~ObjectHandler(); + +#if (USE_SINGLETON == 1) + static ObjectHandler& getSingleton(); + + static ObjectHandler* getSingletonPtr(); +#endif + + SceneObject* createSceneObject( + const Ogre::String& entityName, + const Ogre::String& meshName, + const Ogre::Vector3& position = Ogre::Vector3::ZERO, + const Ogre::Quaternion& rotation = Ogre::Quaternion::IDENTITY, + Terrain::AutoClampState autoClampState = Terrain::ACS_OFF, + bool useObjectBBFloor = false, + Ogre::Real heightBonus = 0.0f); + + SceneObject* createSceneObject( + const Ogre::String& entityName, + const Ogre::String& meshName, + const Ogre::String& sceneNodeName, + const Ogre::Vector3& position = Ogre::Vector3::ZERO, + const Ogre::Quaternion& rotation = Ogre::Quaternion::IDENTITY, + Terrain::AutoClampState autoClampState = Terrain::ACS_OFF, + bool useObjectBBFloor = false, + Ogre::Real heightBonus = 0.0f); + + SceneObject* createSceneObject( + Ogre::MovableObject* movableObject, + const Ogre::String& sceneNodeName, + const Ogre::Vector3& position = Ogre::Vector3::ZERO, + const Ogre::Quaternion& rotation = Ogre::Quaternion::IDENTITY, + Terrain::AutoClampState autoClampState = Terrain::ACS_OFF, + bool useObjectBBFloor = false, + Ogre::Real heightBonus = 0.0f); + + SceneObject* createSceneObject( + Ogre::MovableObject* movableObject, + const Ogre::Vector3& position = Ogre::Vector3::ZERO, + const Ogre::Quaternion& rotation = Ogre::Quaternion::IDENTITY, + Terrain::AutoClampState autoClampState = Terrain::ACS_OFF, + bool useObjectBBFloor = false, + Ogre::Real heightBonus = 0.0f); + + void _addSceneObjectToStorage(const Ogre::String& name, SceneObject* pObject); + + void destroySceneObject(SceneObject* pObject); + + void destroyAllSceneObjects(); + + void updateObjects(Ogre::Real fTime); + + + Ogre::SceneManager* getSceneMgr() const { return mSceneMgr; } + void setSceneMgr(Ogre::SceneManager* val) { mSceneMgr = val; } + + Terrain* getTerrain() const { return mTerrain; } + void setTerrain(Terrain* val) { mTerrain = val; } + + bool getUseRootTerrainHeight() const { return mUseRootTerrainHeight; } + void setUseRootTerrainHeight(bool val) { mUseRootTerrainHeight = val; } + + bool getUseGeoMorphTerrainHeight() const { return mUseGeoMorphTerrainHeight; } + void setUseGeoMorphTerrainHeight(bool val) { mUseGeoMorphTerrainHeight = val; } + + private: + typedef std::map<Ogre::String, SceneObject*> SceneObjectStorage; + SceneObjectStorage mStorage; + + Ogre::SceneManager* mSceneMgr; + Terrain* mTerrain; + + bool mUseRootTerrainHeight; + + bool mUseGeoMorphTerrainHeight; + + }; +} \ No newline at end of file Property changes on: trunk/simplepagedterrain/trunk/library/include/ObjectHandler.h ___________________________________________________________________ Name: svn:eol-style + native Modified: trunk/simplepagedterrain/trunk/library/include/Prerequisites.h =================================================================== --- trunk/simplepagedterrain/trunk/library/include/Prerequisites.h 2008-07-01 15:10:10 UTC (rev 2458) +++ trunk/simplepagedterrain/trunk/library/include/Prerequisites.h 2008-07-02 04:51:10 UTC (rev 2459) @@ -14,6 +14,8 @@ class Terrain; class TerrainMesh; class TerrainModifier; + class ObjectHandler; + class SceneObject; class QuadTree; class QNode; class Heightmap; Modified: trunk/simplepagedterrain/trunk/library/include/Terrain.h =================================================================== --- trunk/simplepagedterrain/trunk/library/include/Terrain.h 2008-07-01 15:10:10 UTC (rev 2458) +++ trunk/simplepagedterrain/trunk/library/include/Terrain.h 2008-07-02 04:51:10 UTC (rev 2459) @@ -12,6 +12,8 @@ namespace SPT { + class ObjectHandler; + class SceneObject; #if (USE_SINGLETON == 1) class Terrain : public Ogre::Singleton<Terrain> #else @@ -63,6 +65,15 @@ mClampUseGeoMorph = useMorph; } + enum AutoClampUpdateState + { + ACUS_MOVEMENT = 0, + ACUS_TIME, + ACUS_BOTH + }; + + + Ogre::Real getSkirtLength() const { return mSkirtLength; } void setSkirtLength(Ogre::Real val) { mSkirtLength = val; } void setSkirtLengthPercent(Ogre::Real val = 10.0f){ mSkirtLength = mTerrainHeight * (val / 100.0f);} @@ -70,6 +81,9 @@ Ogre::Real getMorphSpeed() const { return mMorphSpeed; } void setMorphSpeed(Ogre::Real val) { mMorphSpeed = val; } + Ogre::Real getLODCheckTime() const { return mLODCheckTime; } + void setLODCheckTime(Ogre::Real val) { mLODCheckTime = val; } + //void setTerrainNode(Ogre::SceneNode* pTerrainNode){mTerrainNode = pTerrainNode;} Ogre::SceneNode* getTerrainNode(){return mTerrainNode;} @@ -179,9 +193,20 @@ size_t iHeightmapWidth, const Ogre::String& strTerrainMaterialName, Ogre::Real fTerrainWidth, - Ogre::Real fTerrainHeight ); + Ogre::Real fTerrainHeight, + Ogre::Real fTerrainQuickLoadTime = 3.0f); + void quickSetup( + const Ogre::String& strHeightmapName, + const Ogre::String& strTerrainMaterialName, + Ogre::Real fTerrainWidth, + Ogre::Real fTerrainHeight, + Ogre::Real fTerrainQuickLoadTime = 3.0f ); + ObjectHandler* getObjectHandler() const { return mObjectHandler; } + void setObjectHandler(ObjectHandler* val) { mObjectHandler = val; } + + private: typedef std::map<size_t, Ogre::IndexData*> IndexStorage; IndexStorage mIndexStore; @@ -195,7 +220,13 @@ Ogre::Real mTerrainHeight; Ogre::Real mSkirtLength; Ogre::Real mMorphSpeed; + Ogre::Real mLODCheckTime; + Ogre::Real mPreMorphSpeed; + Ogre::Real mPreLODCheckTime; + bool mInitialized; + Ogre::Real mQuickLoadTime; + AutoClampState mClampState; Ogre::Real mClampBonusHeight; bool mClampUseRoot; @@ -216,6 +247,8 @@ HeightmapReader* mSingleton; + ObjectHandler* mObjectHandler; + Ogre::Vector3 mLightDirection; bool mAutoUpdateLightmap; Modified: trunk/simplepagedterrain/trunk/library/scripts/SPTv2.vcproj =================================================================== --- trunk/simplepagedterrain/trunk/library/scripts/SPTv2.vcproj 2008-07-01 15:10:10 UTC (rev 2458) +++ trunk/simplepagedterrain/trunk/library/scripts/SPTv2.vcproj 2008-07-02 04:51:10 UTC (rev 2459) @@ -376,6 +376,18 @@ </File> </Filter> </Filter> + <Filter + Name="ObjectHandler" + > + <File + RelativePath="..\src\ObjectHandler.cpp" + > + </File> + <File + RelativePath="..\include\ObjectHandler.h" + > + </File> + </Filter> </Filter> </Filter> </Files> Added: trunk/simplepagedterrain/trunk/library/src/ObjectHandler.cpp =================================================================== --- trunk/simplepagedterrain/trunk/library/src/ObjectHandler.cpp (rev 0) +++ trunk/simplepagedterrain/trunk/library/src/ObjectHandler.cpp 2008-07-02 04:51:10 UTC (rev 2459) @@ -0,0 +1,338 @@ +#include "ObjectHandler.h" + + + +#include <OgreSceneManager.h> +#include <OgreEntity.h> +#include <OgreMovableObject.h> + + +using namespace SPT; +using namespace Ogre; +using namespace std; + +#if (USE_SINGLETON == 1) +template<> SPT::ObjectHandler* Ogre::Singleton<SPT::ObjectHandler>::ms_Singleton = 0; +#endif + +namespace SPT +{ + + + SceneObject::SceneObject( + ObjectHandler* objectHandler, + Ogre::MovableObject* movableObject, + Ogre::SceneNode* sceneNode, + Terrain::AutoClampState autoClampState, + Ogre::Real heightBonus ) + : mObjectHandler(objectHandler), + mObject(movableObject), + mSceneNode(sceneNode), + mAutoClampState(autoClampState), + mHeightBonus(heightBonus), + mOriginalDirection(Ogre::Vector3::UNIT_Z), + mTargetNode(0), + mTargetXZRotationOnly(true), + mAutoClampTime(0.0f), + mAutoRotateTime(0.0f), + mCurClampTime(0.0f), + mCurRotateTime(0.0f) + { + + } + + SceneObject::~SceneObject() + { + if (mSceneNode) + { + mSceneNode->detachAllObjects(); + mSceneNode->getParentSceneNode()->removeAndDestroyChild(mSceneNode->getName()); + } + if (mObject) + { + mObjectHandler->getSceneMgr()->destroyMovableObject(mObject); + } + } + + void SceneObject::update( Ogre::Real fTime ) + { + Vector3 pos = mSceneNode->getPosition(); + switch(mAutoClampState) + { + case Terrain::ACS_ALWAYS: + mCurClampTime += fTime; + if (mCurClampTime >= mAutoClampTime) + { + mCurClampTime = 0.0f; + if (mObjectHandler->getTerrain()->getHeightAt( + pos,mHeightBonus, + mObjectHandler->getUseRootTerrainHeight(), + mObjectHandler->getUseGeoMorphTerrainHeight())) + { + mSceneNode->setPosition(pos); + } + } + break; + case Terrain::ACS_BELOW: + mCurClampTime += fTime; + if (mCurClampTime >= mAutoClampTime) + { + mCurClampTime = 0.0f; + if (mObjectHandler->getTerrain()->getHeightAt( + pos,mHeightBonus, + mObjectHandler->getUseRootTerrainHeight(), + mObjectHandler->getUseGeoMorphTerrainHeight())) + { + if (pos.y > mSceneNode->getPosition().y) + mSceneNode->setPosition(pos); + } + } + break; + default: + break; + } + + if (mTargetNode) + { + mCurRotateTime += fTime; + if (mCurRotateTime >= mAutoRotateTime) + { + mCurRotateTime = 0.0f; + if (mTargetXZRotationOnly) + turnTowardsPointXZ(mTargetNode->_getDerivedPosition()); + else + turnTowardsPoint(mTargetNode->_getDerivedPosition()); + } + } + } + + void SceneObject::useBoundingBoxBase() + { + const AxisAlignedBox& aabb = mObject->getBoundingBox(); + Real bottom = aabb.getMinimum().y; + Real center = aabb.getCenter().y; + mHeightBonus = center - bottom; + } + + void SceneObject::biasHeightBonusPercent( Ogre::Real percent ) + { + const AxisAlignedBox& aabb = mObject->getBoundingBox(); + Real bottom = aabb.getMinimum().y; + Real top = aabb.getMaximum().y; + Real total = top - bottom; + mHeightBonus += total * (percent / 100.0f); + } + + void SceneObject::moveObject( const Ogre::Vector3& pos /*= Ogre::Vector3::ZERO*/ ) + { + mSceneNode->setPosition(pos); + } + + void SceneObject::translateObject( const Ogre::Vector3& translation /*= Ogre::Vector3::ZERO*/ ) + { + mSceneNode->translate(translation); + } + + void SceneObject::setRotation( const Ogre::Quaternion& rotation /*= Ogre::Quaternion::IDENTITY*/ ) + { + mSceneNode->setOrientation(rotation); + } + + void SceneObject::rotateXZ( const Ogre::Degree rotation /*= Ogre::Degree() */ ) + { + Quaternion yRot(rotation, Vector3::UNIT_Y); + mSceneNode->rotate(yRot); + } + + void SceneObject::turnTowardsPoint( const Ogre::Vector3& target, bool useXZFirst /*= true*/ ) + { + Vector3 direction = target - mSceneNode->getPosition(); + Quaternion qRotXZ = mOriginalDirection.getRotationTo(Vector3(direction.x,mOriginalDirection.y,direction.z)); + Quaternion qRotY = Vector3(direction.x,0.0f,direction.z).normalisedCopy().getRotationTo(direction); + mSceneNode->setOrientation(qRotY * qRotXZ); + } + + void SceneObject::turnTowardsPointXZ( const Ogre::Vector3& target ) + { + Vector3 direction = target - mSceneNode->getPosition(); + Quaternion qRotXZ = mOriginalDirection.getRotationTo(Vector3(direction.x,mOriginalDirection.y,direction.z)); + //Quaternion qRotY = Vector3(direction.x,0.0f,direction.z).normalisedCopy().getRotationTo(direction); + mSceneNode->setOrientation(qRotXZ);// * qRotY); + } + ////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////// + +#if (USE_SINGLETON == 1) + ObjectHandler* ObjectHandler::getSingletonPtr(void) + { + return ms_Singleton; + } + ObjectHandler& ObjectHandler::getSingleton(void) + { + assert( ms_Singleton ); return ( *ms_Singleton ); + } +#endif + + ObjectHandler::ObjectHandler() + : mSceneMgr(0), + mTerrain(0), + mUseGeoMorphTerrainHeight(false), + mUseRootTerrainHeight(false) + { + + } + + ObjectHandler::ObjectHandler( Ogre::SceneManager* pSceneMgr, Terrain* pTerrain ) + : mSceneMgr(pSceneMgr), + mTerrain(pTerrain), + mUseGeoMorphTerrainHeight(false), + mUseRootTerrainHeight(false) + { + + } + + + ObjectHandler::~ObjectHandler() + { + destroyAllSceneObjects(); + } + + SceneObject* ObjectHandler::createSceneObject( + const Ogre::String& entityName, + const Ogre::String& meshName, + const Ogre::Vector3& position /*= Ogre::Vector3::ZERO*/, + const Ogre::Quaternion& rotation /*= Ogre::Quaternion::IDENTITY*/, + Terrain::AutoClampState autoClampState /*= Terrain::AutoClampState::ACS_OFF*/, + bool useObjectBBFloor /*= false*/, + Ogre::Real heightBonus /*= 0.0f*/ ) + { + assert(mSceneMgr); + + Entity* pEnt = mSceneMgr->createEntity(entityName,meshName); + SceneNode* pNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(position,rotation); + pNode->attachObject(pEnt); + + SceneObject* pObject = new SceneObject(this,pEnt,pNode,autoClampState,heightBonus); + if (useObjectBBFloor) + { + pObject->useBoundingBoxBase(); + } + + _addSceneObjectToStorage(entityName,pObject); + return pObject; + } + + SceneObject* ObjectHandler::createSceneObject( + const Ogre::String& entityName, + const Ogre::String& meshName, + const Ogre::String& sceneNodeName, + const Ogre::Vector3& position /*= Ogre::Vector3::ZERO*/, + const Ogre::Quaternion& rotation /*= Ogre::Quaternion::IDENTITY*/, + Terrain::AutoClampState autoClampState /*= Terrain::AutoClampState::ACS_OFF*/, + bool useObjectBBFloor /*= false*/, + Ogre::Real heightBonus /*= 0.0f*/ ) + { + assert(mSceneMgr); + + Entity* pEnt = mSceneMgr->createEntity(entityName,meshName); + SceneNode* pNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(sceneNodeName,position,rotation); + pNode->attachObject(pEnt); + + SceneObject* pObject = new SceneObject(this,pEnt,pNode,autoClampState,heightBonus); + if (useObjectBBFloor) + { + pObject->useBoundingBoxBase(); + } + + _addSceneObjectToStorage(entityName,pObject); + return pObject; + } + + SceneObject* ObjectHandler::createSceneObject( + Ogre::MovableObject* movableObject, + const Ogre::String& sceneNodeName, + const Ogre::Vector3& position /*= Ogre::Vector3::ZERO*/, + const Ogre::Quaternion& rotation /*= Ogre::Quaternion::IDENTITY*/, + Terrain::AutoClampState autoClampState /*= Terrain::AutoClampState::ACS_OFF*/, + bool useObjectBBFloor /*= false*/, + Ogre::Real heightBonus /*= 0.0f*/ ) + { + assert(mSceneMgr); + + SceneNode* pNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(sceneNodeName,position,rotation); + pNode->attachObject(movableObject); + + SceneObject* pObject = new SceneObject(this,movableObject,pNode,autoClampState,heightBonus); + if (useObjectBBFloor) + { + pObject->useBoundingBoxBase(); + } + + _addSceneObjectToStorage(movableObject->getName(),pObject); + return pObject; + } + + SceneObject* ObjectHandler::createSceneObject( + Ogre::MovableObject* movableObject, + const Ogre::Vector3& position /*= Ogre::Vector3::ZERO*/, + const Ogre::Quaternion& rotation /*= Ogre::Quaternion::IDENTITY*/, + Terrain::AutoClampState autoClampState /*= Terrain::AutoClampState::ACS_OFF*/, + bool useObjectBBFloor /*= false*/, + Ogre::Real heightBonus /*= 0.0f*/ ) + { + assert(mSceneMgr); + + SceneNode* pNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(position,rotation); + pNode->attachObject(movableObject); + + SceneObject* pObject = new SceneObject(this,movableObject,pNode,autoClampState,heightBonus); + if (useObjectBBFloor) + { + pObject->useBoundingBoxBase(); + } + + _addSceneObjectToStorage(movableObject->getName(),pObject); + return pObject; + } + + void ObjectHandler::_addSceneObjectToStorage( const Ogre::String& name, SceneObject* pObject ) + { + SceneObjectStorage::iterator it = mStorage.find(name); + if (it != mStorage.end()) + { + it = mStorage.erase(it); + } + + mStorage.insert(it,SceneObjectStorage::value_type(name,pObject)); + } + + void ObjectHandler::destroySceneObject( SceneObject* pObject ) + { + String name = pObject->getObject()->getName(); + SceneObjectStorage::iterator it = mStorage.find(name); + if (it != mStorage.end()) + { + mStorage.erase(it); + } + } + + void ObjectHandler::updateObjects( Ogre::Real fTime ) + { + SceneObjectStorage::iterator it = mStorage.begin(); + while (it != mStorage.end()) + { + it->second->update(fTime); + ++it; + } + } + + void ObjectHandler::destroyAllSceneObjects() + { + SceneObjectStorage::iterator it = mStorage.begin(); + while (it != mStorage.end()) + { + delete it->second; + ++it; + } + } +} \ No newline at end of file Property changes on: trunk/simplepagedterrain/trunk/library/src/ObjectHandler.cpp ___________________________________________________________________ Name: svn:eol-style + native Modified: trunk/simplepagedterrain/trunk/library/src/PNGHeightmapReader.cpp =================================================================== --- trunk/simplepagedterrain/trunk/library/src/PNGHeightmapReader.cpp 2008-07-01 15:10:10 UTC (rev 2458) +++ trunk/simplepagedterrain/trunk/library/src/PNGHeightmapReader.cpp 2008-07-02 04:51:10 UTC (rev 2459) @@ -23,19 +23,23 @@ size_t iSpacing /*= 1*/, bool bHasBorder /*= false*/ ) { - assert("Should have a width" && iWidth); + //assert("Should have a width" && iWidth); assert("Heightmap == 0" && pHeightmap); - pHeightmap->setWidth(iWidth); - pHeightmap->allocateData(); + Image img; img.load(strFileName,"General"); - size_t iMapWidth = img.getWidth(); + if (iWidth == 0) + iWidth = iMapWidth; + + pHeightmap->setWidth(iWidth); + pHeightmap->allocateData(); + HEIGHTMAPTYPE* pData = pHeightmap->getData(); size_t pos = 0; Modified: trunk/simplepagedterrain/trunk/library/src/Terrain.cpp =================================================================== --- trunk/simplepagedterrain/trunk/library/src/Terrain.cpp 2008-07-01 15:10:10 UTC (rev 2458) +++ trunk/simplepagedterrain/trunk/library/src/Terrain.cpp 2008-07-02 04:51:10 UTC (rev 2459) @@ -5,6 +5,7 @@ #include "HeightmapReader.h" #include "GPULightmapper.h" #include "AtmosphericCubeMap.h" +#include "ObjectHandler.h" #include <OgreMaterialManager.h> using namespace SPT; @@ -44,10 +45,16 @@ mClampUseGeoMorph(false), mSkirtLength(0.0f), mMorphSpeed(1.0f), + mLODCheckTime(1.0f), + mPreLODCheckTime(1.0f), + mPreMorphSpeed(1.0f), + mInitialized(false), mAutoUpdateLightmap(true) { mSingleton = new HeightmapReader(); + mObjectHandler = new ObjectHandler(0,this); + //mTerrainNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); } @@ -72,10 +79,16 @@ mClampUseGeoMorph(false), mSkirtLength(0.0f), mMorphSpeed(1.0f), + mLODCheckTime(1.0f), + mPreLODCheckTime(1.0f), + mPreMorphSpeed(1.0f), + mInitialized(false), mAutoUpdateLightmap(true) { mSingleton = new HeightmapReader(); + mObjectHandler = new ObjectHandler(mSceneMgr,this); + //mTerrainNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); } Terrain::~Terrain() @@ -160,6 +173,7 @@ void Terrain::destroy() { + mObjectHandler->destroyAllSceneObjects(); delete mSkyMap; mSkyMap = 0; @@ -172,6 +186,8 @@ delete mHeightmap; mHeightmap = 0; + + mInitialized = false; } bool Terrain::getHeightAt( Ogre::Vector3& vPos, Ogre::Real rBonus /*= 0.0f*/, bool bUseRoot /*= false*/, bool bUseGeoMorphing /*= false*/ ) @@ -251,8 +267,20 @@ break; } + if (mInitialized == false) + { + mQuickLoadTime -= fTime; + if (mQuickLoadTime <= 0.0f) + { + setLODCheckTime(mPreLODCheckTime); + setMorphSpeed(mPreMorphSpeed); + mInitialized = true; + } + } + + sTime += fTime; - if (sTime >= 1.0f) + if (sTime >= getLODCheckTime()) { mRootNode->runLODChecks(); sTime = 0.0f; @@ -262,6 +290,9 @@ if (mSkyMap) mSkyMap->updatePosition(); + + if (mObjectHandler) + mObjectHandler->updateObjects(fTime); } } @@ -418,16 +449,32 @@ size_t iHeightmapWidth, const Ogre::String& strTerrainMaterialName, Ogre::Real fTerrainWidth, - Ogre::Real fTerrainHeight ) + Ogre::Real fTerrainHeight, + Ogre::Real fTerrainQuickLoadTime /*= 1.0f*/ ) { setMaterial(strTerrainMaterialName); mWidth = fTerrainWidth; mTerrainHeight = fTerrainHeight; + mQuickLoadTime = fTerrainQuickLoadTime; + mPreLODCheckTime = mLODCheckTime; + mPreMorphSpeed = mMorphSpeed; + mMorphSpeed = 0.0f; + mLODCheckTime = 0.0f; + initialize(strHeightmapName,iHeightmapWidth); } + void Terrain::quickSetup( + const Ogre::String& strHeightmapName, + const Ogre::String& strTerrainMaterialName, + Ogre::Real fTerrainWidth, + Ogre::Real fTerrainHeight, + Ogre::Real fTerrainQuickLoadTime /*= 1.0f*/ ) + { + quickSetup(strHeightmapName,0,strTerrainMaterialName,fTerrainWidth,fTerrainHeight,fTerrainQuickLoadTime); + } void Terrain::setLightDirection( const Ogre::Vector3& vLightDir ) { mLightDirection = vLightDir; Modified: trunk/simplepagedterrain/trunk/library/src/TerrainMesh.cpp =================================================================== --- trunk/simplepagedterrain/trunk/library/src/TerrainMesh.cpp 2008-07-01 15:10:10 UTC (rev 2458) +++ trunk/simplepagedterrain/trunk/library/src/TerrainMesh.cpp 2008-07-02 04:51:10 UTC (rev 2459) @@ -820,10 +820,10 @@ mVertexData->vertexBufferBinding->setBinding(1,mDeltaBuffers[0]); - + mBuilt = true; - mBuilt = true; + destroyGeometryData(); } void TerrainMesh::getRenderOperation( Ogre::RenderOperation& op ) @@ -1321,12 +1321,16 @@ void TerrainMesh::destroyGeometryData() { - for (size_t i=0;i<mUVSets;i++) + if (mUVCoordinates) { - delete[] mUVCoordinates[i]; - mUVCoordinates[i] = 0; + for (size_t i=0;i<mUVSets;i++) + { + delete[] mUVCoordinates[i]; + mUVCoordinates[i] = 0; + } } + delete[] mUVCoordinates; mUVCoordinates = 0; Added: trunk/simplepagedterrain/trunk/media/SPT2_Low.program =================================================================== --- trunk/simplepagedterrain/trunk/media/SPT2_Low.program (rev 0) +++ trunk/simplepagedterrain/trunk/media/SPT2_Low.program 2008-07-02 04:51:10 UTC (rev 2459) @@ -0,0 +1,23 @@ +vertex_program SPT2_Low_VS hlsl +{ + source SPT2_Low.source + entry_point vs_main + target vs_2_0 + + default_params + { + param_named_auto matWorldViewProj worldviewproj_matrix + param_named_auto matWorld world_matrix + param_named_auto vViewPosition camera_position 0 + param_named_auto morphFactor custom 77 + //param_named_auto parentUVOffset custom 99 + } +} + + +fragment_program SPT2_Low_PS hlsl +{ + source SPT2_Low.source + entry_point ps_main + target ps_2_0 +} \ No newline at end of file Property changes on: trunk/simplepagedterrain/trunk/media/SPT2_Low.program ___________________________________________________________________ Name: svn:eol-style + native Added: trunk/simplepagedterrain/trunk/media/SPT2_Low.source =================================================================== --- trunk/simplepagedterrain/trunk/media/SPT2_Low.source (rev 0) +++ trunk/simplepagedterrain/trunk/media/SPT2_Low.source 2008-07-02 04:51:10 UTC (rev 2459) @@ -0,0 +1,127 @@ +#define USE_SCATTERING + +float4x4 matWorldViewProj; +float4x4 matWorld; +float4 vViewPosition; +float morphFactor; +//float3 parentUVOffset; + +float fMaxDistance; +//float fRoadScale; +float4 vSplatScales; +float4 vDetailScales; + +struct VS_INPUT +{ + float4 Pos : POSITION0; + float2 Tex : TEXCOORD0; + float2 Tex2: TEXCOORD1; + //float4 Color : COLOR0; + float delta: BLENDWEIGHT; +}; + +struct VS_OUTPUT +{ + float4 Pos : POSITION0; + float2 Tex : TEXCOORD0; + float4 Splat12 : TEXCOORD1; + float4 Splat34 : TEXCOORD2; + float2 Detail : TEXCOORD3; + float4 Depth : TEXCOORD4; +}; + +VS_OUTPUT vs_main( VS_INPUT Input ) +{ + VS_OUTPUT Output; + + Input.Pos.y += Input.delta * morphFactor; + + + Output.Pos = mul( matWorldViewProj, Input.Pos); + float3 vWorldPos = mul(matWorld, Input.Pos).xyz; + + //float3 EyeDir = vViewPosition.xyz - vWorldPos; + float3 EyeDir = vWorldPos - vViewPosition.xyz; + //EyeDir.z *= -1; + float Depth = length(EyeDir); + + Output.Depth.xyz = EyeDir / Depth; + Output.Depth.w = Depth / fMaxDistance; + + + Output.Tex = Input.Tex; + + Output.Splat12.xy = vWorldPos.xz / vSplatScales.x; + Output.Splat12.zw = vWorldPos.xz / vSplatScales.y; + Output.Splat34.xy = vWorldPos.xz / vSplatScales.z; + Output.Splat34.zw = vWorldPos.xz / vSplatScales.w; + + Output.Detail = Input.Tex * vDetailScales.x; + //Output.Details12.zw = Input.Tex * vDetailScales.y; + + //Output.Road = Input.Tex * fRoadScale; + + return Output; +} + +sampler2D Coverage; +sampler2D Splat; +sampler2D Lightmap; +sampler2D Splat1; +sampler2D Splat2; +sampler2D Splat3; +sampler2D Splat4; + +sampler2D Detail1; +//sampler2D Detail2; +sampler1D Extinction; +samplerCUBE SkyBox; + +struct PS_INPUT +{ + float2 texCoord: TEXCOORD0; + float4 Splat12 : TEXCOORD1; + float4 Splat34 : TEXCOORD2; + float2 Detail : TEXCOORD3; + float4 Depth : TEXCOORD4; +}; + +float4 ps_main( PS_INPUT Input ) : COLOR +{ + + float4 fLight = tex2D(Lightmap, Input.texCoord); + + float4 vCoverageColor = tex2D(Coverage, Input.texCoord); + + + float4 vSplatColor = tex2D(Splat, Input.texCoord); + vSplatColor /= vSplatColor.x + vSplatColor.y + vSplatColor.z + vSplatColor.w; + float4 vSplat1 = tex2D(Splat1, Input.Splat12.xy) * vSplatColor.x; + float4 vSplat2 = tex2D(Splat2, Input.Splat12.zw) * vSplatColor.y; + float4 vSplat3 = tex2D(Splat3, Input.Splat34.xy) * vSplatColor.z; + float4 vSplat4 = tex2D(Splat4, Input.Splat34.zw) * vSplatColor.w; + + + float4 oColor = vSplat1 + vSplat2 + vSplat3 + vSplat4; + + + float fDetail = tex2D(Detail1, Input.Detail).x; + + oColor *= fDetail; + + oColor.xyz *= vCoverageColor.xyz * 0.9f; + + oColor *= (fLight.w * 2.0 + 0.5); + +#ifdef USE_SCATTERING + float3 SkyColor = texCUBE(SkyBox, Input.Depth.xyz); + float ExtinctionVal = tex1D(Extinction, saturate(Input.Depth.w)); + + oColor.xyz = lerp(SkyColor, oColor.xyz , ExtinctionVal); +#endif + + return float4(oColor.xyz,1); +//return float4(oColor.x,0,0,1); + +} + Property changes on: trunk/simplepagedterrain/trunk/media/SPT2_Low.source ___________________________________________________________________ Name: svn:eol-style + native Added: trunk/simplepagedterrain/trunk/media/SPT2_Mat.material =================================================================== --- trunk/simplepagedterrain/trunk/media/SPT2_Mat.material (rev 0) +++ trunk/simplepagedterrain/trunk/media/SPT2_Mat.material 2008-07-02 04:51:10 UTC (rev 2459) @@ -0,0 +1,229 @@ +material SPT2_Medium +{ + technique Medium + { + pass + { + vertex_program_ref SPT2_Medium_VS + { + param_named fMaxDistance float 40000 + param_named vSplatScales float4 300 400 220 150 + param_named vDetailScales float4 1000 10000 1 1 + } + + fragment_program_ref SPT2_Medium_PS + { + + } + + texture_unit Coverage + { + texture_alias Coverage + filtering bilinear + tex_address_mode clamp + tex_coord_set 0 + } + texture_unit SplatMap + { + texture_alias SplatMap + filtering bilinear + tex_address_mode clamp + tex_coord_set 1 + } + texture_unit Lightmap + { + texture_alias Lightmap + filtering bilinear + tex_address_mode clamp + tex_coord_set 2 + } + texture_unit Splat1 + { + texture_alias Splat1 + filtering trilinear + tex_coord_set 3 + } + texture_unit Splat2 + { + texture_alias Splat2 + filtering trilinear + tex_coord_set 4 + } + texture_unit Splat3 + { + texture_alias Splat3 + filtering trilinear + tex_coord_set 5 + } + texture_unit Splat4 + { + texture_alias Splat4 + filtering trilinear + tex_coord_set 6 + } + + texture_unit Detail1 + { + texture_alias Detail1 + filtering trilinear + tex_coord_set 7 + } + + texture_unit Detail2 + { + texture_alias Detail2 + filtering trilinear + tex_coord_set 8 + } + texture_unit Extinction + { + texture_alias Extinction + filtering bilinear + tex_coord_set 9 + } + texture_unit SkyBox + { + texture_alias SkyBox + tex_coord_set 10 + } + + } + } +} + +material SPT2_Medium_Scheme : SPT2_Medium +{ + technique Medium + { + scheme Medium + + pass 0 + { + vertex_program_ref SPT2_Medium_VS + { + param_named fMaxDistance float 40000 + param_named vSplatScales float4 300 400 220 150 + param_named vDetailScales float4 1000 10000 1 1 + } + } + } +} + +material SPT2_Low : SPT2_Medium_Scheme +{ + technique Low + { + pass + { + vertex_program_ref SPT2_Low_VS + { + param_named fMaxDistance float 40000 + param_named vSplatScales float4 300 400 220 150 + param_named vDetailScales float4 1000 10000 1 1 + } + + fragment_program_ref SPT2_Low_PS + { + + } + + texture_unit Coverage + { + texture_alias Coverage + filtering bilinear + tex_address_mode clamp + tex_coord_set 0 + } + texture_unit SplatMap + { + texture_alias SplatMap + filtering bilinear + tex_address_mode clamp + tex_coord_set 1 + } + texture_unit Lightmap + { + texture_alias Lightmap + filtering bilinear + tex_address_mode clamp + tex_coord_set 2 + } + texture_unit Splat1 + { + texture_alias Splat1 + filtering trilinear + tex_coord_set 3 + } + texture_unit Splat2 + { + texture_alias Splat2 + filtering trilinear + tex_coord_set 4 + } + texture_unit Splat3 + { + texture_alias Splat3 + filtering trilinear + tex_coord_set 5 + } + texture_unit Splat4 + { + texture_alias Splat4 + filtering trilinear + tex_coord_set 6 + } + + texture_unit Detail1 + { + texture_alias Detail1 + filtering trilinear + tex_coord_set 7 + } + texture_unit Extinction + { + texture_alias Extinction + filtering bilinear + tex_coord_set 8 + } + texture_unit SkyBox + { + texture_alias SkyBox + tex_coord_set 9 + } + + } + } +} + +material SPT2_Low_Scheme : SPT2_Low +{ + technique Low + { + scheme Low + pass 0 + { + vertex_program_ref SPT2_Low_VS + { + param_named fMaxDistance float 40000 + param_named vSplatScales float4 300 400 220 150 + param_named vDetailScales float4 1000 10000 1 1 + } + } + } +} + +material SPT2_EarlyZ_Scheme : SPT2_Low_Scheme +{ + technique EarlyZ + { + scheme EarlyZ + pass 0 + { + colour_write off + vertex_program_ref SPT2_EarlyZ_VS + { + + } + } + } +} Property changes on: trunk/simplepagedterrain/trunk/media/SPT2_Mat.material ___________________________________________________________________ Name: svn:eol-style + native Added: trunk/simplepagedterrain/trunk/media/SPT2_Medium.program =================================================================== --- trunk/simplepagedterrain/trunk/media/SPT2_Medium.program (rev 0) +++ trunk/simplepagedterrain/trunk/media/SPT2_Medium.program 2008-07-02 04:51:10 UTC (rev 2459) @@ -0,0 +1,23 @@ +vertex_program SPT2_Medium_VS hlsl +{ + source SPT2_Medium.source + entry_point vs_main + target vs_3_0 + + default_params + { + param_named_auto matWorldViewProj worldviewproj_matrix + param_named_auto matWorld world_matrix + param_named_auto vViewPosition camera_position 0 + param_named_auto morphFactor custom 77 + //param_named_auto parentUVOffset custom 99 + } +} + + +fragment_program SPT2_Medium_PS hlsl +{ + source SPT2_Medium.source + entry_point ps_main + target ps_3_0 +} \ No newline at end of file Property changes on: trunk/simplepagedterrain/trunk/media/SPT2_Medium.program ___________________________________________________________________ Name: svn:eol-style + native Added: trunk/simplepagedterrain/trunk/media/SPT2_Medium.source =================================================================== --- trunk/simplepagedterrain/trunk/media/SPT2_Medium.source (rev 0) +++ trunk/simplepagedterrain/trunk/media/SPT2_Medium.source 2008-07-02 04:51:10 UTC (rev 2459) @@ -0,0 +1,212 @@ +#define USE_SCATTERING + +float4x4 matWorldViewProj; +float4x4 matWorld; +float4 vViewPosition; +float morphFactor; +//float3 parentUVOffset; + +float fMaxDistance; +//float fRoadScale; +float4 vSplatScales; +float4 vDetailScales; + +struct VS_INPUT +{ + float4 Pos : POSITION0; + float3 Norm: NORMAL0; + float2 Tex : TEXCOORD0; + float2 Tex2: TEXCOORD1; + //float4 Color : COLOR0; + float delta: BLENDWEIGHT; +}; + +struct VS_OUTPUT +{ + float4 Pos : POSITION0; + float2 Tex : TEXCOORD0; + float3 Splat1 : TEXCOORD1; + float3 Splat2 : TEXCOORD2; + float3 Splat3 : TEXCOORD3; + float3 Splat4 : TEXCOORD4; + float3 Normal : TEXCOORD5; + float4 Details12 : TEXCOORD6; + float4 Depth : TEXCOORD7; +}; + +VS_OUTPUT vs_main( VS_INPUT Input ) +{ + VS_OUTPUT Output; + + Input.Pos.y += Input.delta * morphFactor; + + + Output.Pos = mul( matWorldViewProj, Input.Pos); + float3 vWorldPos = mul(matWorld, Input.Pos).xyz; + Output.Normal = Input.Norm; + + //float3 EyeDir = vViewPosition.xyz - vWorldPos; + float3 EyeDir = vWorldPos - vViewPosition.xyz; + //EyeDir.z *= -1; + float Depth = length(EyeDir); + + Output.Depth.xyz = EyeDir / Depth; + Output.Depth.w = Depth / (fMaxDistance * 2.0f); + + + Output.Tex = Input.Tex; + + Output.Splat1 = vWorldPos / vSplatScales.x; + Output.Splat2 = vWorldPos / vSplatScales.y; + Output.Splat3 = vWorldPos / vSplatScales.z; + Output.Splat4 = vWorldPos / vSplatScales.w; + + + //float3 vSplat1 = vWorldPos / vSplatScales.x; + //float3 vSplat2 = vWorldPos / vSplatScales.y; + //float3 vSplat3 = vWorldPos / vSplatScales.z; + //float3 vSplat4 = vWorldPos / vSplatScales.w; + + //Output.Splat1 = float4(vSplat1,vSplat4.x); + //Output.Splat2 = float4(vSplat2,vSplat4.y); + //Output.Splat3 = float4(vSplat3,vSplat4.z); + + + Output.Details12.xy = Input.Tex * vDetailScales.x; + Output.Details12.zw = Input.Tex * vDetailScales.y; + + //Output.Road = Input.Tex * fRoadScale; + + return Output; +} + +sampler2D Coverage; +sampler2D Splat; +sampler2D Lightmap; +sampler2D Splat1; +sampler2D Splat2; +sampler2D Splat3; +sampler2D Splat4; + +sampler2D Detail1; +sampler2D Detail2; +sampler1D Extinction; +samplerCUBE SkyBox; + +struct PS_INPUT +{ + float2 texCoord : TEXCOORD0; + float3 Splat1 : TEXCOORD1; + float3 Splat2 : TEXCOORD2; + float3 Splat3 : TEXCOORD3; + float3 Splat4 : TEXCOORD4; + float3 Normal : TEXCOORD5; + float4 Details12 : TEXCOORD6; + float4 Depth : TEXCOORD7; +}; + +float4 ps_main( PS_INPUT Input ) : COLOR +{ + + + //float3 vNorm = normalize(Input.Normal); + + float4 fLight = tex2D(Lightmap, Input.texCoord); + float3 vNorm = (fLight.xyz * 2.0f) - 1.0f; + + float3 blendWeights = abs(vNorm)-0.2; + blendWeights *= 7.0; + blendWeights = pow(blendWeights, 3.0); + blendWeights = max(0.0, blendWeights); + + blendWeights /= dot(blendWeights,1.0); + + + + + float4 vCoverageColor = tex2D(Coverage, Input.texCoord); + + + float4 oColor = float4(0,0,0,0); + + float4 vSplatColor = tex2D(Splat, Input.texCoord); + vSplatColor /= vSplatColor.x + vSplatColor.y + vSplatColor.z + vSplatColor.w; + float4 vSplat1 = float4(0,0,0,1); + float4 vSplat2 = float4(0,0,0,1); + float4 vSplat3 = float4(0,0,0,1); + float4 vSplat4 = float4(0,0,0,1); + + // Tri-planar + + if (vSplatColor.x > 0.0f) + { + // Splat1 + + + vSplat1.xyz = tex2D(Splat1, Input.Splat1.yz).xyz * blendWeights.x + + tex2D(Splat1, Input.Splat1.xz).xyz * blendWeights.y + + tex2D(Splat1, Input.Splat1.xy).xyz * blendWeights.z; + vSplat1.xyz *= vSplatColor.x; + } + if (vSplatColor.y > 0.0f) + { + + + vSplat2.xyz = tex2D(Splat2, Input.Splat2.yz).xyz * blendWeights.x + + tex2D(Splat2, Input.Splat2.xz).xyz * blendWeights.y + + tex2D(Splat2, Input.Splat2.xy).xyz * blendWeights.z; + vSplat2.xyz *= vSplatColor.y; + } + + if (vSplatColor.z > 0.0f) + { + + vSplat3.xyz = tex2D(Splat3, Input.Splat3.yz).xyz * blendWeights.x + + tex2D(Splat3, Input.Splat3.xz).xyz * blendWeights.y + + tex2D(Splat3, Input.Splat3.xy).xyz * blendWeights.z; + vSplat3.xyz *= vSplatColor.z; + } + + if (vSplatColor.w > 0.0f) + { + // Splat4 + + + vSplat4.xyz = tex2D(Splat4, Input.Splat4.yz).xyz * blendWeights.x + + tex2D(Splat4, Input.Splat4.xz).xyz * blendWeights.y + + tex2D(Splat4, Input.Splat4.xy).xyz * blendWeights.z; + vSplat4.xyz *= vSplatColor.w; + } + + oColor = vSplat1 + vSplat2 + vSplat3 + vSplat4; + + + float fDetail1 = tex2D(Detail1, Input.Details12.xy).x; + float fDetail2 = tex2D(Detail2, Input.Details12.zw).x; + + oColor *= fDetail1 * fDetail2; + + //oColor *= (1 + vNoise); + + oColor.xyz *= vCoverageColor.xyz * 0.9f; + + //float4 vRoad = tex2D(Road, Input.Road) * vCoverageColor.w; + + //oColor *= (1.0f - vCoverageColor.w); + //oColor += vRoad; + + + + oColor *= (fLight.w * 2.0 + 0.5); + +#ifdef USE_SCATTERING + float3 SkyColor = texCUBE(SkyBox, Input.Depth.xyz); + float ExtinctionVal = tex1D(Extinction, saturate(Input.Depth.w)); + + oColor.xyz = lerp(SkyColor, oColor.xyz , ExtinctionVal); +#endif + + return float4(oColor.xyz,1); + +} + Property changes on: trunk/simplepagedterrain/trunk/media/SPT2_Medium.source ___________________________________________________________________ Name: svn:eol-style + native Added: trunk/simplepagedterrain/trunk/media/SPT2_Shadow.program =================================================================== --- trunk/simplepagedterrain/trunk/media/SPT2_Shadow.program (rev 0) +++ trunk/simplepagedterrain/trunk/media/SPT2_Shadow.program 2008-07-02 04:51:10 UTC (rev 2459) @@ -0,0 +1,14 @@ +vertex_program SPT2_Shadow hlsl +{ + source SPT2_Shadow.source + target vs_2_0 + entry_point vs_main + + default_params + { + param_named_auto matWorldViewProjection worldviewproj_matrix + param_named_auto matWorld world_matrix + param_named_auto matTexProjection texture_viewproj_matrix + param_named_auto morphFactor custom 77 + } +} \ No newline at end of file Property changes on: trunk/simplepagedterrain/trunk/media/SPT2_Shadow.program ___________________________________________________________________ Name: svn:eol-style + native Added: trunk/simplepagedterrain/trunk/media/SPT2_Shadow.source =================================================================== --- trunk/simplepagedterrain/trunk/media/SPT2_Shadow.source (rev 0) +++ trunk/simplepagedterrain/trunk/media/SPT2_Shadow.source 2008-07-02 04:51:10 UTC (rev 2459) @@ -0,0 +1,35 @@ +float4x4 matWorldViewProjection; +float4x4 matWorld; +float4x4 matTexProjection; +float morphFactor; + +struct VS_INPUT +{ + float4 Position : POSITION0; + float delta : BLENDWEIGHT; + +}; + +struct VS_OUTPUT +{ + float4 Position : POSITION0; + float4 ShadowTex: TEXCOORD0; + float4 ShadowTex2 : TEXCOORD1; + float4 Color : COLOR0; + +}; + +VS_OUTPUT vs_main( VS_INPUT Input ) +{ + VS_OUTPUT Output; + + Input.Position.y += (Input.delta * morphFactor); + + Output.Position = mul( matWorldViewProjection, Input.Position ); + Output.ShadowTex= mul(matTexProjection, mul(matWorld, Input.Position)); + Output.ShadowTex2=Output.ShadowTex; + Output.Color = float4(1,1,1,1); + + return( Output ); + +} \ No newline at end of file Property changes on: trunk/simplepagedterrain/trunk/media/SPT2_Shadow.source ___________________________________________________________________ Name: svn:eol-style + native Modified: trunk/simplepagedterrain/trunk/media/materials/Highlands.material =================================================================== --- trunk/simplepagedterrain/trunk/media/materials/Highlands.material 2008-07-01 15:10:10 UTC (rev 2458) +++ trunk/simplepagedterrain/trunk/media/materials/Highlands.material 2008-07-02 04:51:10 UTC (rev 2459) @@ -1,9 +1,23 @@ -material SPT_Highlands +material SPT_HighlandsOld { technique { + scheme SSDepth pass { + vertex_program_ref SSDepth_VS + { + } + fragment_program_ref SSDepth_PS + { + } + } + + } + technique + { + pass + { vertex_program_ref SPT2_Medium_VS { Added: trunk/simplepagedterrain/trunk/media/materials/Ogre.material =================================================================== --- trunk/simplepagedterrain/trunk/media/materials/Ogre.material (rev 0) +++ trunk/simplepagedterrain/trunk/media/materials/Ogre.material 2008-07-02 04:51:10 UTC (rev 2459) @@ -0,0 +1,68 @@ +material Ogre/Earring +{ + technique + { + pass + { + ambient 0.5 0.5 0 + diffuse 1 1 0 + + texture_unit + { + texture spheremap.png + colour_op_ex add src_texture src_current + colour_op_multipass_fallback one one + env_map spherical + } + } + } +} +material Ogre/Skin +{ + technique + { + pass + { + ambient 0.7 0.7 0.7 + cull_hardware none + + texture_unit + { + texture GreenSkin.jpg + tex_address_mode mirror + } + } + } +} +material Ogre/Tusks +{ + technique + { + pass + { + ambient 0.5 0.5 0.4 + diffuse 1 1 0.8 + + texture_unit + { + texture dirt01.jpg + colour_op_ex add src_texture src_current + colour_op_multipass_fallback one one + } + } + } +} +material Ogre/Eyes +{ + technique + { + pass + { + + texture_unit + { + texture WeirdEye.png + } + } + } +} \ No newline at end of file Property changes on: trunk/simplepagedterrain/trunk/media/materials/Ogre.material ___________________________________________________________________ Name: svn:eol-style + native Added: trunk/simplepagedterrain/trunk/media/materials/SPT2_Highlands.material =================================================================== --- trunk/simplepagedterrain/trunk/media/materials/SPT2_Highlands.material (rev 0) +++ trunk/simplepagedterrain/trunk/media/materials/SPT2_Highlands.material 2008-07-02 04:51:10 UTC (rev 2459) @@ -0,0 +1,11 @@ +material SPT_Highlands : SPT2_Low_Scheme +{ + set_texture_alias Coverage Highlands_Coverage.jpg + set_texture_alias SplatMap Highlands_Splat.dds + set_texture_alias Splat1 herbe_3.jpg + set_texture_alias Splat2 herbe_3.jpg + set_texture_alias Splat3 herbe_5.jpg + set_texture_alias Splat4 sand_025.jpg + set_texture_alias Detail1 detail_splat1.png + set_texture_alias Detail2 Detail3.jpg +} \ No newline at end of file Property changes on: trunk/simplepagedterrain/trunk/media/materials/SPT2_Highlands.material ___________________________________________________________________ Name: svn:eol-style + native Added: trunk/simplepagedterrain/trunk/media/models/ogrehead.mesh =================================================================== (Binary files differ) Property changes on: trunk/simplepagedterrain/trunk/media/models/ogrehead.mesh ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/simplepagedterrain/trunk/media/textures/Dirt.jpg =================================================================== (Binary files differ) Property changes on: trunk/simplepagedterrain/trunk/media/textures/Dirt.jpg ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/simplepagedterrain/trunk/media/textures/GreenSkin.jpg =================================================================== (Binary files differ) Property changes on: trunk/simplepagedterrain/trunk/media/textures/GreenSkin.jpg ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/simplepagedterrain/trunk/media/textures/WeirdEye.png =================================================================== (Binary files differ) Property changes on: trunk/simplepagedterrain/trunk/media/textures/WeirdEye.png ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/simplepagedterrain/trunk/media/textures/spheremap.png =================================================================== (Binary files differ) Property changes on: trunk/simplepagedterrain/trunk/media/textures/spheremap.png ___________________________________________________________________ Name: svn:mime-type + application/octet-stream This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |