hotgloupi
10-10-2007 00:31:35
Hi all !
I found how to get dynamic lighting in plsm, but I'm trying for many hours to get lightImage, that is the var used to contain dynamic shadow texture.
I'm trying to get it with SceneManager->getOption() process.
I added this code :
if (strKey == "getLightMap")
{
Ogre::Image *i = static_cast < Ogre::Image * > (pDestValue);
i = mTextureManager->getLightMap();
return true;
}
and of course add one getLightMap() function in PagingLandScapeTextureManager and one in PagingLandScapeTexture that finally return *mLightImage.
but it always do nothing, like an infinite loop, when I call that :
Ogre::Image lightMapImage;
mSceneMgr->getOption("getLightMap", &lightMapImage);
// Create dynamic texture
mNatureColorMap = Ogre::TextureManager::getSingleton().loadImage("NatureColorMap",
"World",
lightMapImage,
Ogre::TEX_TYPE_2D );
i get my infinite loop just after terrain.Light.x,y.jpg loading...
so, do you think that the way is good?
Is there another (proper) way?
Something I can try?
thanks !
hotgloupi
12-10-2007 12:40:32
Ok without community help ...
this is changes I do to plsm2 lib :
to PagingLandscapeTexture class : uchar* PagingLandScapeTexture::getLightMapData()
{
lightUpdate();
return mLightImage.getData();
}
to PagingLandscapeTextureManager class :uchar* PagingLandScapeTextureManager::getLightMapDataPage(const unsigned int x, const unsigned int z,
const bool alwaysReturn)
{
if (x < mWidth && z < mHeight)
{
PagingLandScapeTextureList::iterator l, lend = mActiveTextures.end();
for (l = mActiveTextures.begin(); l != lend; ++l)
{
if ((*l)->isCoord(x, z))
return (*l)->getLightMapData();
}
if (alwaysReturn)
return getNewTexture(x, z)->getLightMapData();
}
assert (!alwaysReturn);
return 0;
}
to PagingLandscapeSceneManager::getOption(..) member : if (strKey == "getLightMapDataPage")
{
Ogre::Vector2 **page = static_cast < Ogre::Vector2 ** > (pDestValue);
// get shadow data page
uchar* data = mTextureManager->getLightMapDataPage((*page)->x, (*page)->y, false);
// convert void pointer to a uchar**
uchar** target_ptr = static_cast<uchar**>(pDestValue);
*target_ptr = data;
return true;
}
and this is the code I use to retrieve LightMap : int width=0, height=0, pageSize=0;
Ogre::Real scaleX, scaleZ;
mSceneMgr->getOption("Width", &width);
mSceneMgr->getOption("Height", &height);
mSceneMgr->getOption("PageSize", &pageSize);
mSceneMgr->getOption("ScaleX", &scaleX);
mSceneMgr->getOption("ScaleZ", &scaleZ);
int numPages = width*height;
/*LOG(Ogre::String("width = ") + Ogre::StringConverter::toString(width));
LOG(Ogre::String("height = ") + Ogre::StringConverter::toString(height));
LOG(Ogre::String("ScaleX = ") + Ogre::StringConverter::toString(scaleX));
LOG(Ogre::String("pageSize = ") + Ogre::StringConverter::toString(pageSize));
LOG(Ogre::String("ScaleZ = ") + Ogre::StringConverter::toString(scaleZ));*/
mNatureColorMaps = new Ogre::TexturePtr[numPages];
mLightImages = new Ogre::Image[numPages];
Ogre::Vector2 currentPage;
Ogre::uchar* currentData;
void* myOptionPtr;
for (int i=0 ; i<width ; i++)
for (int j=0 ; j<height ; j++)
{
currentPage = Ogre::Vector2(i, j);
myOptionPtr = ¤tPage;
if (mSceneMgr->getOption("getLightMapDataPage", &myOptionPtr))
{
currentData = (Ogre::uchar*)myOptionPtr;
// load image page
mLightImages[i + width*j].loadDynamicImage(currentData, pageSize-1, pageSize-1, Ogre::PF_A8);
// Create dynamic texture page
mNatureColorMaps[i + width*j] =
Ogre::TextureManager::getSingleton().createManual( "NATURE_COLOR_MAP." +
Ogre::StringConverter::toString(i) + "." +
Ogre::StringConverter::toString(j),
"World",
Ogre::TEX_TYPE_2D,
pageSize-1, pageSize-1, 0,
Ogre::PF_A8,
Ogre::TU_DYNAMIC);
mNatureColorMaps[i + width*j].get()->loadImage(mLightImages[i + width*j]);
/*mLightImages[i + width*j].save(Ogre::String("/home/hotgloupi/DynamicLightning.") +
Ogre::StringConverter::toString(i) + "." +
Ogre::StringConverter::toString(j) + ".jpg");*/
}
}
hotgloupi
29-10-2007 15:17:28
This is the patch :
Index: include/OgrePagingLandScapeTexture.h
===================================================================
RCS file: /cvsroot/ogre/ogreaddons/paginglandscape/PlugIns/PagingLandScape2/include/OgrePagingLandScapeTexture.h,v
retrieving revision 1.33
diff -r1.33 OgrePagingLandScapeTexture.h
103a104
> uchar* getLightMapData() ;
Index: include/OgrePagingLandScapeTextureManager.h
===================================================================
RCS file: /cvsroot/ogre/ogreaddons/paginglandscape/PlugIns/PagingLandScape2/include/OgrePagingLandScapeTextureManager.h,v
retrieving revision 1.28
diff -r1.28 OgrePagingLandScapeTextureManager.h
93a94,95
>
> uchar* getLightMapDataPage(const unsigned int x, const unsigned int z,const bool alwaysReturn) ;
Index: src/OgrePagingLandScapeSceneManager.cpp
===================================================================
RCS file: /cvsroot/ogre/ogreaddons/paginglandscape/PlugIns/PagingLandScape2/src/OgrePagingLandScapeSceneManager.cpp,v
retrieving revision 1.99
diff -r1.99 OgrePagingLandScapeSceneManager.cpp
1138a1139,1153
> if (strKey == "getLightMapDataPage")
> {
> Ogre::Vector2 **page = static_cast < Ogre::Vector2 ** > (pDestValue);
>
> // get shadow data page
> uchar* data = mTextureManager->getLightMapDataPage((*page)->x, (*page)->y, false);
>
> // convert void pointer to a uchar**
> uchar** target_ptr = static_cast<uchar**>(pDestValue);
>
> *target_ptr = data;
>
> return true;
> }
>
Index: src/OgrePagingLandScapeTexture.cpp
===================================================================
RCS file: /cvsroot/ogre/ogreaddons/paginglandscape/PlugIns/PagingLandScape2/src/OgrePagingLandScapeTexture.cpp,v
retrieving revision 1.54
diff -r1.54 OgrePagingLandScapeTexture.cpp
1382a1383,1388
>
> uchar* PagingLandScapeTexture::getLightMapData()
> {
> lightUpdate();
> return mLightImage.getData();
> }
1383a1390,1392
>
>
>
Index: src/OgrePagingLandScapeTextureManager.cpp
===================================================================
RCS file: /cvsroot/ogre/ogreaddons/paginglandscape/PlugIns/PagingLandScape2/src/OgrePagingLandScapeTextureManager.cpp,v
retrieving revision 1.61
diff -r1.61 OgrePagingLandScapeTextureManager.cpp
692a693,710
> uchar* PagingLandScapeTextureManager::getLightMapDataPage(const unsigned int x, const unsigned int z,
> const bool alwaysReturn)
> {
> if (x < mWidth && z < mHeight)
> {
> PagingLandScapeTextureList::iterator l, lend = mActiveTextures.end();
> for (l = mActiveTextures.begin(); l != lend; ++l)
> {
> if ((*l)->isCoord(x, z))
> return (*l)->getLightMapData();
> }
> if (alwaysReturn)
> return getNewTexture(x, z)->getLightMapData();
> }
> assert (!alwaysReturn);
> return 0;
> }
>
hotgloupi
12-11-2007 20:51:35
I think I'm the owner of this post
this is my conclusion :
For retrieve shadow data, i use this code :
mSceneMgr->getOption("Width", &mWidth);
mSceneMgr->getOption("Height", &mHeight);
mSceneMgr->getOption("PageSize", &mPageSize);
mSceneMgr->getOption("ScaleX", &mScaleX);
mSceneMgr->getOption("ScaleY", &mScaleY);
mSceneMgr->getOption("ScaleZ", &mScaleZ);
mNumPages = mWidth * mHeight;
mLightMaps = new Ogre::uchar*[mNumPages];
Ogre::Vector2 currentPage;
void* myOptionPtr;
for (int i=0 ; i<mWidth ; i++)
for (int j=0 ; j<mHeight ; j++)
{
currentPage = Ogre::Vector2(i, j);
myOptionPtr = ¤tPage;
mSceneMgr->getOption("getLightMapDataPage", &myOptionPtr);
mLightMaps[i + j*mWidth] = (Ogre::uchar*)myOptionPtr;
}
after that, you can easily transform those uchar* tab to Ogre::Image.
I change a little part of paged geometry (and i posted changes in dedicated forum) to apply directly like a color map.
I'll come back when i will feel alone
bye