PCZSM patch

klumhru

04-12-2008 18:59:41

This fixes the Impostor rendering in the PCZSM, where every entity and camera has to have a parent scenenode.

Index: ImpostorPage.cpp
===================================================================
--- ImpostorPage.cpp (revision 2528)
+++ ImpostorPage.cpp (working copy)
@@ -49,6 +49,7 @@
if (++selfInstances == 1){
//Set up a single instance of a scene node which will be used when rendering impostor textures
geom->getSceneNode()->createChildSceneNode("ImpostorPage::renderNode");
+ geom->getSceneNode()->createChildSceneNode("ImpostorPage::cameraNode");
}
}

@@ -445,6 +446,7 @@
RenderTexture *renderTarget;
Camera *renderCamera;
Viewport *renderViewport;
+ SceneNode *camNode;

//Set up RTT texture
uint32 textureSize = ImpostorPage::impostorResolution;
@@ -459,7 +461,9 @@
renderTarget->setAutoUpdated(false);

//Set up camera
+ camNode = sceneMgr->getSceneNode("ImpostorPage::cameraNode");
renderCamera = sceneMgr->createCamera(getUniqueID("ImpostorCam"));
+ camNode->attachObject(renderCamera);
renderCamera->setLodBias(1000.0f);
renderViewport = renderTarget->addViewport(renderCamera);
renderViewport->setOverlaysEnabled(false);

Fish

05-12-2008 00:56:20

Sweet! Thanks for the patch klumhru!

JohnJ

05-12-2008 04:43:27

Thanks, that's very helpful! I'll merge this soon.

Fish

10-12-2008 04:34:33

I'm seeing some odd behavior with this patch. It appears that not all mesh entities are getting an impostor and sometimes an impostor will fade-in at a location where there is no mesh present.

I'm using the PCZSM, the latest Ogre trunk 8207, and the "LOAD TREES" code from example 5.

Also, I had to put the line:
[Impostors]
FileSystem=../Standard Resources/trees

in my resources.cfg file in order to make PagedGeometry stop throwing an exception, "Cannot find a group named Impostors in ResourceGroupManager::isResourceGroupInitialised OgreResourceGroupManager.cpp (line 1704).

JohnJ

10-12-2008 22:21:08

Is this behavior related to the patch (in other words, if you un-patch it, does it work normally)? It seems strange that these modifications would do anything like that. I'll do some testing later today, but if I can't reproduce the problem, it would help if you could send me some code that does.

Fish

11-12-2008 05:01:20

Is this behavior related to the patch (in other words, if you un-patch it, does it work normally)?

I didn't mean to say that the 'exception' is due to this patch. If I unpatch it I still get the exception when I try to use impostors. If I remove impostors as a detail level then the exception is not thrown, as expected.

What I meant to say is that this patch does not seem to completely support impostors with the PCZSM. I have yet to dig into the PG code. And in all honesty there is a good chance that we won't use impostors at all. But it would be nice to have them for folks with less powerful hardware.


It seems strange that these modifications would do anything like that. I'll do some testing later today, but if I can't reproduce the problem, it would help if you could send me some code that does.


Great, I'm interested to know the results. :D

JohnJ

11-12-2008 23:57:12

Ok, that makes sense. I tested it and couldn't find anything wrong, which isn't surprising now because I wasn't using PCZSM.

Regarding PCZSM/PLSM/etc. compatibility issues, keep in mind that since PagedGeometry works with "official" Ogre scene managers, anything that's broken under an addon scene manager might not be "patchable" on PagedGeometry's end, depending on the nature of the problem.

Technically, if a third-party scene manager is causing weird things to happen in PagedGeometry, it should be fixed in the scene manager, not in PagedGeometry. Patches like this one are OK since they don't make the code messy or incompatible with other scene managers at the expense of another, but generally your best bet at getting your problem fixed is in the PCZSM code I think.

Either way though, if you keep running into trouble getting PagedGeometry working correctly with your scene manager, let me know and I can try to debug it for you (and hopefully find what's causing the problem, at least).

Fish

12-12-2008 00:42:32

Ok, that makes sense. I tested it and couldn't find anything wrong, which isn't surprising now because I wasn't using PCZSM.

Regarding PCZSM/PLSM/etc. compatibility issues, keep in mind that since PagedGeometry works with "official" Ogre scene managers, anything that's broken under an addon scene manager might not be "patchable" on PagedGeometry's end, depending on the nature of the problem.


Actually, I think the PCZSM is an official scene manager as of Ogre 1.6.0. I think what you meant is that PG was designed with the OctreeSceneManager and an earlier version of Ogre in mind, no?

The 'Exception' may actually be related to some changes made in 1.6.0. As far as the odd impostor behavior there may still be some loose ends in this patch.

When I have time and if the calls (complaints) warrant it I'll dig into the source and see if I can locate the problems and, of course, post the patch here (unless klumhru beats me to it). :)

-Fish

JohnJ

12-12-2008 00:49:43

Hmm... I didn't even know that PCZSM was a part of Ogre 1.6 :). I'll take a look at it then, and see if I can reproduce the problem. Still, "in theory" there shouldn't be compatibility issues like this between scene managers. In any case, something's not right, and I'll do my best to find the problem.

I might not get any time until the weekend though, since I'll be working late today and probably tomorrow.

klumhru

12-12-2008 02:41:10

The problem as far as PCZSM is concerned - at least what I can see - is that everything needs to have a parent scene node, including cameras in this case. It might be that the entities have to have a scene node as well, which would defeat the purpose of PG. The feature is integral to PCZSM though so it's not really a bug as such.

I only posted the patch as PCZSM is now an integral SM in Ogre as of 1.6 as Fish mentioned. It seemed pretty simple and clean as a fix for a bug that bugged me and might others when they start using the PCZSM with PG ;)

Chaster

14-12-2008 00:01:01

JohnJ, I am actually using PG with PCZSM, although I had to generate the tree impostor texture offline because of the incompatibility that this Patch is supposed to fix.

I had to make a couple different changes within PG for my own stuff, but I can't remember exactly... I should go take a look.

I'll try this patch and see what happens in my code.

Chaster

p.s. let me know if you need any assistance JohnJ.

Chaster

14-12-2008 19:26:37

Update: This patch does not work. Only one impostor view is being generated (if you look in the generated texture, it only contains one view instead of the many different views PG needs).

I think I know where the problem (roughly) is, but need to delve in more.

What I *think* is happening is that when all the views of the tree are generated, the camera manipulations which are supposed to point at the tree are not working correctly. I suspect this is because the camera view is being manipulated directly, instead of the scene node it is now attached to.

I'll see what I can do to fix this.

Chaster

Chaster

14-12-2008 20:27:03

Update:

I still haven't been able to get the impostor texture to generate correctly yet. it gives me a very odd texture (only one view, and it's rendered entirely in black).

I decided to go back to the PG examples and modify them to use PCZSM. However, when I just tried to compile & run them as they are (straight from SVN), I get the same error as fish:


PagedGeometry stop throwing an exception, "Cannot find a group named Impostors in ResourceGroupManager::isResourceGroupInitialised OgreResourceGroupManager.cpp (line 1704).


Since the examples don't even use a resources.cfg file, I'm a little bit at a loss why this is happening.. Any clues?

Chaster

Chaster

14-12-2008 21:05:01

Update:

To fix the exception being thrown, the samples need the following added:

ResourceGroupManager::getSingleton().createResourceGroup("Impostors");


This should be inserted before the call to initializeAllResourceGroups() is called.

Still trying working on the PCZSM problem... Help is welcome...


Chaster

Chaster

14-12-2008 22:19:42

Well, no joy so far. I am wondering if the camera and entity nodes need to have their zone explicitly set before rendering out the impostor texture (which would be a problem since not everyone is using the PCZSM with PG). I can't work on this anymore for now. I have some other more important pressing deadlines.

I will say, for my project, what I did was just generate the necessary impostor textures using the example code (just replacing meshes for the trees) and then putting those impostors into my application (which uses PCZSM). PagedGeometry seems to work fine with PCZSM in all other aspects besides the generation of the impostor textures.

Chaster

JohnJ

15-12-2008 15:45:39

Chaster: Thanks for the help! Hmm... maybe this problem will be more difficult than I thought, if there are issues with portals, zones, etc. I don't know why you can't simply add an entity and render it, but I have a feeling patching this could be messy.

Anyway, thanks for the resource group patch - I'll be sure to merge that soon (although I'll probably add the createResourceGroup() into the impostor system since it is it's responsibility to keep itself from crashing, not the examples).

JohnJ

18-12-2008 00:51:33

(Sorry this took so long, I haven't been able to spend much time on this lately)

The crash caused by the impostor resource group should hopefully be fixed now (no need to create any impostor group yourself - it's automatic).

I also modified the impostor generator to use scene node translations rather than camera translations, so maybe that will help (unless you already tried that). Let me know how it goes (keep in mind it won't regenerate the impostors unless you delete their generated image files).

Chaster

18-12-2008 08:49:43

Thanks JohnJ,

I am unsure as to what is causing the problem generating the impostor textures in PCZSM. You should be able to just put an entity in and a camera, and have it render fine (as long as both have nodes). If you don't explicitly assign a node to a zone, it should automatically get assigned to the default zone.

I gave it a shot at fixing, but couldn't get it to work, and I'm kinda swamped (eternally) so I just put it off for now. I'll try again with your changes and see if they make a difference. I also changed a small bit of code in PCZSM which might make a difference (doubt it) so maybe we can get it working...

Chaster

Chaster

19-12-2008 20:07:54

Update: Well, the latest code still doesn't generate all of the impostors when used with PCZSM. However, at least it generates ONE of them correctly. Previously, it would just generate a single impostor view which was black (like a silhouette). Now it generates the right rendering, but still only one view (instead of 32).

Still not sure why it doesn't work. It *should* work. It might be that I am testing in my full game project (rather than a simple scene setup specifically to test PCZSM with PG)...

Chaster

JohnJ

20-12-2008 02:36:52

Ok, thanks for the update. Strange that the PCZSM is being so problematic for some reason, even when patching PagedGeometry to use PCZSM-compatible techniques. Well, let me know if you learn anything new. I can't think of much else I can do other than debug PCZSM, which I don't know anything about really.