[Solved] Ray Scene Query

PatrickB3

05-09-2006 21:27:15

I got fresh from CVS to test the terrain painting and deformation at tile/page edges bug fix. Though those are fixed a new bug crept in. Ray Scene Queries are now way too expensive. Doing 90 per frame lowers the framerate from 25 to less than 2. It did not do this before.

tuan kuranes

06-09-2006 09:38:57

Which sort of Ray Scene Queries ?
Terrain height ? Entities ?

PatrickB3

06-09-2006 18:44:00

The ones I'm doing is for Terrain Height. Until I got fresh code they were really fast but now the frame rate is like 2fps. I hook them up to a key press and it is fine if I don't do them.

tuan kuranes

07-09-2006 09:43:47

I'll try to have a look, but I didn't make any real change in that part of code, so please double check if anything changed on your side (particularly query masks)

Dale_ee

07-09-2006 11:39:27

I can be wrong, but GOOFed is now working too slow in painting and deforming mode, though heightmap is 1k*1k and pc configuration is good.
AMD 3400+ 64, 1GB RAM, GeForce 6800GS 512ram.
I think it may happen because on circle-cursor which probably does some Ray Scene Queries.

PatrickB3

07-09-2006 19:56:44

Exactly. It does 90 queries every frame for the selection marking circle. I do the same thing so I'm having the same problem. Nothing changed in my code as all I did was get fresh PLSM2, recompile it, and run my app.

tuan kuranes

11-09-2006 12:02:31

Did you test with latest CVS ?
(beware of breaking changes, as it now uses Dagon real way to do this. check updated demo to see how it works, or cvs changelog)

PatrickB3

11-09-2006 22:29:01

Got fresh again. Still less than 2 fps. Same with GOOF.

I'm using:

mouseRay.setDirection(Ogre::Vector3::NEGATIVE_UNIT_Y);

for(Ogre::uint i = 0; i <= 90 && GameData.CurrentHandTool >= GAMETOOL_Raise; i++)
{
mouseRay.setOrigin(Ogre::Vector3(GameData.mBrushPos.x + GameData.mBrushPoints[i].x, 2500.0f, GameData.mBrushPos.z + GameData.mBrushPoints[i].z));
MouseRaySceneQuery->setRay(mouseRay);
// MouseRaySceneQuery->setQueryMask(1); //PLSM2 only RSQ_Height
MouseRaySceneQuery->setQueryTypeMask(Ogre::SceneManager::WORLD_GEOMETRY_TYPE_MASK );
MouseRaySceneQuery->setWorldFragmentType(SceneQuery::WFT_SINGLE_INTERSECTION);

// Perform the scene query
RaySceneQueryResult queryResult = MouseRaySceneQuery->execute();
itr = queryResult.begin();

if(itr != queryResult.end() && itr->worldFragment ) {
terrainHeight = itr->worldFragment->singleIntersection.y;
GameData.mBrushPoints[i].y = terrainHeight + 0.2f;
}
else {
GameData.mBrushPoints[i].y = 0.0f;
}
} // end for i


which used to give me like 25 fps with expensive shaders running now it is less than 2 with no shaders running except the terrain one.

PatrickB3

11-09-2006 22:50:31

k, here's the problem:


RaySceneQueryResult queryResult = MouseRaySceneQuery->execute();



Should be:


RaySceneQueryResult & queryResult = MouseRaySceneQuery->execute();


Otherwise it triggers one of the worst things you can do in C++ when making a game, triggering a copy constructor in a tight loop. Adding the '&' stops this. However what I don't understand is why suddenly this became so expensive as it is only returning one result anyways ( and I checked queryResult has a size of 1 ).

tuan kuranes

12-09-2006 07:41:55

Don't have a clue either why it suddenly appears... any ogre cvs update too at the same time ?

btw, you can/should also 'set' query option outside of the loop.

PatrickB3

12-09-2006 10:41:23

Nope, no new Ogre code. I guess the compiler just decided to compile it differently now.

Yeah, I should change that. The tool code isn't used by the game, just for making it so I wasn't too concerned about speed. Though when it went down to 2 fps the tool was useless so then I suddenly cared, lol.