[SOLVED] Fog and PLSM2

Lshink

17-02-2006 04:18:30

Hello:

I'm sort of confused about how to add fog into PLSM2. I've tried to edit the demo to have fog in it -- but to no avail. Here is the only code sniplet I've added:

virtual void chooseSceneManager(void)
{
// Get the SceneManager, in this case the Paging LandScape specialization
mSceneMgr = mRoot->getSceneManager( ST_EXTERIOR_REAL_FAR );

unsigned short target = mWindow->getNumViewports();

for(int i = 0; i < target; i++)
{
//ColourValue fadeColour( 0.1, 0.1, 0.1 );
//mSceneMgr->setFog( FOG_EXP, g_DayColor, 0.005 );
mWindow->getViewport(0)->setBackgroundColour( g_DayColor );
}

mSceneMgr->setFog( FOG_LINEAR, g_DayColor, 0.0, 0, 130 );

mSceneMgr->setWorldGeometry( Ogre::String("paginglandscape2.cfg") );
}


But I still see no fog. I don't have any skyboxes/domes created either that are possibly blocking it out. Any idea on what I'm doing wrong?

tuan kuranes

17-02-2006 08:17:33

It works here by uncommenting fog code in plsm2 demo. (Paginglandscape.h:167 - 169)

Make sure fog is not disabled afterwards in your code.

Lshink

17-02-2006 18:36:10

Ok, I uncommented the code and also check to see if its disabled anywhere else, but I didn't see anything. The only thing I changed to the demo was uncommenting the fog and recompiling, these are the results:



I can't see any fogging on the terrain. I'm still a bit confused -- is there more I need to do to get fogging in PLSM2? I put the exact same code in the TSM and got the fog effect.

All I did was uncomment the fog code in the demo, but here is my PagingLandScape.h:

/*
-----------------------------------------------------------------------------
This source file is part of OGRE
(Object-oriented Graphics Rendering Engine)
For the latest info, see http://ogre.sourceforge.net/

Copyright © 2000-2002 The OGRE Team
Also see acknowledgements in Readme.html

This program is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.

This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place - Suite 330, Boston, MA 02111-1307, USA, or go to
http://www.gnu.org/copyleft/lesser.txt.
-----------------------------------------------------------------------------
*/

/**
@file
LandScape.h
@brief
Specialisation of OGRE's framework application to show the
LandScape rendering plugin
*/
#include "ExampleApplication.h"
#include "OgreStringConverter.h"
#include "OgreSphere.h"
#include "OgrePanelOverlayElement.h"

using namespace Ogre;

#include "OgrePagingLandScapeRaySceneQuery.h"
#include "OgrePagingLandScapeListenerManager.h"

ColourValue g_DayColor;



#include "Terrainlistener.h"
#include "Overlay.h"
#include "FrameListener.h"


class PagingLandScapeApplication : public ExampleApplication
{
public:
//-----------------------------------------------------------------------
PagingLandScapeApplication()
{
g_DayColor = ColourValue(0.57421875, 0.640625, 0.9921875);
mPagingFrameListener = 0;
}
//-----------------------------------------------------------------------
~PagingLandScapeApplication()
{
if (mPagingFrameListener)
delete mPagingFrameListener;
}
protected:
Light* mLight;
SceneNode* mLightNode;
Ogre::uint mNumScreenShots;
PagingLandScapeFrameListener* mPagingFrameListener;


//-----------------------------------------------------------------------
virtual void createFrameListener(void)
{
mPagingFrameListener= new PagingLandScapeFrameListener(mWindow,
mCamera, mLight, mLightNode,
false, true);
mRoot->addFrameListener(mPagingFrameListener);
}
//-----------------------------------------------------------------------
virtual void chooseSceneManager(void)
{
// Get the SceneManager, in this case the Paging LandScape specialization
mSceneMgr = mRoot->getSceneManager( ST_EXTERIOR_REAL_FAR );
mSceneMgr->setWorldGeometry( Ogre::String("paginglandscape2.cfg") );
}
//-----------------------------------------------------------------------
virtual void createCamera(void)
{
// Create the camera
mCamera = mSceneMgr->createCamera( "PlayerCam" );

Vector3 pos(128,25,128);
//Vector3 pos(3085, 0, 3085);

mCamera->lookAt( pos );
// Place the camera a little over the terrain
pos.y += 38700;
// Position it at 500 in Z direction
mCamera->setPosition( pos );
float tmp;
mSceneMgr->getOption( "VisibleDistance", &tmp);
mCamera->setNearClipDistance( 1 );
// Infinite far plane?
if (mRoot->getRenderSystem()->getCapabilities()->hasCapability(RSC_INFINITE_FAR_PLANE))
{
mCamera->setFarClipDistance(0);
}
else
{
mCamera->setFarClipDistance( tmp );
}
}
//-----------------------------------------------------------------------
virtual void createViewports(void)
{
// Create one viewport, entire window
Viewport* vp = mWindow->addViewport(mCamera);
//vp->setBackgroundColour(ColourValue::Black);
//vp->setBackgroundColour( ColourValue(0.35, 0.43, 0.5) );
vp->setBackgroundColour( g_DayColor );
}
//-----------------------------------------------------------------------
// Just override the mandatory create scene method
void createScene(void)
{
srand (0);
// Set ambient light
mSceneMgr->setAmbientLight( ColourValue (0.7f, 0.7f, 0.7f));//g_DayColor );

{
//lights
Vector3 LightPos(0.0f, 0.0f, 0.0f);

mLight = mSceneMgr->createLight("MainLight");

mLight->setPosition(LightPos);

mLight->setDiffuseColour(0.93f, 0.93f, 0.93f);
mLight->setAttenuation(10000.0f, 1.0f, 1.0f, 0.0f);

mLight->setType (Light::LT_DIRECTIONAL);
mLight->setDirection (Vector3 (0.0f, -1.0f, 0.0f));

SceneNode *BaseNode = mSceneMgr->getRootSceneNode()->createChildSceneNode ("LightHandler");
BaseNode->setPosition (-3500.0f, 0.0f, -2600.0f);
mLightNode = BaseNode->createChildSceneNode ("LightHandlerSon");
mLightNode->setPosition (0.0f, 15000.0f, 0.0f);
mLightNode->attachObject (mLight);

BillboardSet* LightSet = mSceneMgr->createBillboardSet("RedYellowLights");
LightSet->setMaterialName("Examples/Flare");
mLightNode->attachObject(LightSet);

Billboard* LightBoard = LightSet->createBillboard(LightPos);
//LightBoard->setDimensions(10.0f, 10.0f);
LightBoard->setColour(ColourValue(1.0f, 1.0f, 0.2f, 1.0f));
}

/* Plane plane;
plane.d = 100;
plane.normal = Vector3::NEGATIVE_UNIT_Y;

mSceneMgr->setSkyPlane( true, plane, "Examples/CloudySky", 500, 20, true, 0.5, 150, 150 );*/

float tmp, tmp2;

mSceneMgr->getOption( "VisibleDistance", &tmp);
mSceneMgr->getOption( "DistanceLOD", &tmp2);
mSceneMgr->setFog( FOG_LINEAR , g_DayColor, 0.0, tmp2, tmp);


//// Define the required curve sky plane
//Plane plane;
//// 3000 world units from the camera
//plane.d = 300;
//// Above the camera, facing down
//plane.normal = -Vector3::UNIT_Y;
//// Create a curved sky plane 10000 units wide, tile the texture 3
//// times, and curve height is 0.5 of the sky plane's width.
//mSceneMgr->setSkyPlane( true, plane, "Examples/CloudySky", 300, 27, true, 0.35f);
//mSceneMgr->getMaterial("Examples/CloudySky")->setFog( true, FOG_EXP, g_DayColor, 0.00005 );

//showDebugOverlay( true );

// Add the water

// Entity *ent;
//
// Plane p;
// p.normal = Vector3::UNIT_Y;
// p.d = 50.0;
// MeshManager::getSingleton().createPlane("WaterPlane",p,400,400,20,20,true,1,50,50,Vector3::UNIT_Z);
//
// // Create an entity (the floor)
// ent = mSceneMgr->createEntity("water", "WaterPlane");
// ent->setMaterialName("Examples/TransparentTest");

// static_cast<SceneNode*>(mSceneMgr->getRootSceneNode()->createChild())->attachObject(ent);

createGrassMesh ();

}

void createGrassMesh()
{

#define GRASS_HEIGHT 300
#define GRASS_WIDTH 250
#define GRASS_MESH_NAME "grassblades"
#define GRASS_MATERIAL "Examples/GrassBlades"
#define OFFSET_PARAM 999

// Each grass section is 3 planes at 60 degrees to each other
// Normals point straight up to simulate correct lighting
MeshPtr msh = MeshManager::getSingleton().createManual(GRASS_MESH_NAME,
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
SubMesh* sm = msh->createSubMesh();
sm->useSharedVertices = false;
sm->vertexData = new VertexData();
sm->vertexData->vertexStart = 0;
sm->vertexData->vertexCount = 12;
VertexDeclaration* dcl = sm->vertexData->vertexDeclaration;
size_t offset = 0;
dcl->addElement(0, offset, VET_FLOAT3, VES_POSITION);
offset += VertexElement::getTypeSize(VET_FLOAT3);
dcl->addElement(0, offset, VET_FLOAT3, VES_NORMAL);
offset += VertexElement::getTypeSize(VET_FLOAT3);
dcl->addElement(0, offset, VET_FLOAT2, VES_TEXTURE_COORDINATES);
offset += VertexElement::getTypeSize(VET_FLOAT2);

HardwareVertexBufferSharedPtr vbuf = HardwareBufferManager::getSingleton()
.createVertexBuffer(
offset, 12, HardwareBuffer::HBU_STATIC_WRITE_ONLY);
float* pReal = static_cast<float*>(vbuf->lock(HardwareBuffer::HBL_DISCARD));
Vector3 baseVec(GRASS_WIDTH/2, 0, 0);
Vector3 vec = baseVec;
Quaternion rot;
rot.FromAngleAxis(Degree(60), Vector3::UNIT_Y);
int i;
for (i = 0; i < 3; ++i)
{
// position
*pReal++ = -vec.x;
*pReal++ = GRASS_HEIGHT;
*pReal++ = -vec.z;
// normal
*pReal++ = 0;
*pReal++ = 1;
*pReal++ = 0;
// uv
*pReal++ = 0;
*pReal++ = 0;

// position
*pReal++ = vec.x;
*pReal++ = GRASS_HEIGHT;
*pReal++ = vec.z;
// normal
*pReal++ = 0;
*pReal++ = 1;
*pReal++ = 0;
// uv
*pReal++ = 1;
*pReal++ = 0;

// position
*pReal++ = -vec.x;
*pReal++ = 0;
*pReal++ = -vec.z;
// normal
*pReal++ = 0;
*pReal++ = 1;
*pReal++ = 0;
// uv
*pReal++ = 0;
*pReal++ = 1;

// position
*pReal++ = vec.x;
*pReal++ = 0;
*pReal++ = vec.z;
// normal
*pReal++ = 0;
*pReal++ = 1;
*pReal++ = 0;
// uv
*pReal++ = 1;
*pReal++ = 1;

vec = rot * vec;
}
vbuf->unlock();
sm->vertexData->vertexBufferBinding->setBinding(0, vbuf);
sm->indexData->indexCount = 6*3;
sm->indexData->indexBuffer = HardwareBufferManager::getSingleton()
.createIndexBuffer(HardwareIndexBuffer::IT_16BIT, 6*3,
HardwareBuffer::HBU_STATIC_WRITE_ONLY);
uint16* pI = static_cast<uint16*>(
sm->indexData->indexBuffer->lock(HardwareBuffer::HBL_DISCARD));
for (i = 0; i < 3; ++i)
{
int off = i*4;
*pI++ = 0 + off;
*pI++ = 3 + off;
*pI++ = 1 + off;

*pI++ = 0 + off;
*pI++ = 2 + off;
*pI++ = 3 + off;
}

sm->indexData->indexBuffer->unlock();

sm->setMaterialName(GRASS_MATERIAL);
msh->load();

}
};




Thanks for the help so far!

tuan kuranes

17-02-2006 18:48:12

here my fog line says
mSceneMgr->setFog( FOG_LINEAR , g_DayColor, 0.0003, tmp2, tmp);
make sure you did not make any other change.
I've tried it using terragen_terrain and splatting2.

Lshink

17-02-2006 20:01:49

Ah! ok, I see it now. Sorry, I didn't go through all of them to see if the fog worked.

Why does the fog only work with that one? Is there any way to get it to work with others? perhaps the grand_canyon?

tuan kuranes

18-02-2006 08:03:19

it must be matter of either "VisibleDistance" or "DistanceLOD" being too far or terrain material not supporting fog.

Lshink

18-02-2006 20:56:54

I got it!

I just had to turn off VertexCompression and VertexProgramMorph and then the fogging showed up! :)

Falagard

18-02-2006 21:47:42

Fog support probably has to be added to the terrain morphing vertex shader. It wouldn't be hard to add.