Gamasutra Article on Imposters...

Discussion area about developing or extending OGRE, adding plugins for it or building applications on it. No newbie questions please, use the Help forum for that.
User avatar
Falagard
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 2060
Joined: Thu Feb 26, 2004 12:11 am
Location: Toronto, Canada
x 3
Contact:

Gamasutra Article on Imposters...

Post by Falagard »

Someone really needs to implement this in Ogre.

If they do, they'll be my hero.

http://www.gamasutra.com/features/20060 ... s_01.shtml

I took a quick stab at implementing imposters in Ogre more than a year ago, but didn't follow through. At the time, render targets in Ogre didn't support alpha, and I had some problem setting up the matrices properly.

The code that I was basing my implementation on was this older imposter article.

http://www.gamasutra.com/features/20020712/oneil_03.htm

Anyhow, the new gamasutra article has some great stuff (on cursory glance) for how to set it up and how to use one render texture to store multiple imposters.

The old article probably has some useful stuff too.

So... anyone feel like tackling it? My hands are full already, but I'm sure many many people would benefit from imposters in Ogre, and it would add to the growing list of Ogre's features.

Clay
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Post by jacmoe »

I totally agree. :)

Posted about Billboard Clouds a while ago, but the general concensus was that it was a great idea, but it would probably eat up texture memory, so ...

Here is the thread:
http://www.ogre3d.org/phpBB2/viewtopic. ... ght=clouds


I believe that Zadeck is Xavier Decorety - so the Billboard Clouds guy is already introduced to Ogre. :wink:
User avatar
tuan kuranes
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 2653
Joined: Wed Sep 24, 2003 8:07 am
Location: Haute Garonne, France
x 4
Contact:

Post by tuan kuranes »

I'm already doing it.

here's the classes:

UniqueImpostorSet (handling the BillboardSet of impostor and the RenderTexture.)
UniqueImpostorhandler (handling the impostor, handle a MovableObject.)
TextureSpace (sort of quadtree handling free and used parts of the rtt, only power of 2 texturespace possible, so it's big space waste, but fast.)

Thing is that it need a special version of billboardset, as stated here.

It's a WIP for implementing LOD-Sprite Technique for Accelerated Terrain Renderingng in PLSM2.
It still some work to do before releasing it, but I can release the impostor classes before finishing the other parts.

Perhaps it could be a plugin ImpostorFX, as particleFX... and then have some contribution like NonUniqueImpostorSet, ShaderInstancingNonUniqueImpostorSet, and an MakeImpostor that would create NormalMap texture as well. (sort of DefferedUniqueImpostorSet).
User avatar
Falagard
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 2060
Joined: Thu Feb 26, 2004 12:11 am
Location: Toronto, Canada
x 3
Contact:

Post by Falagard »

Sweet!

Personally, here's a few things I would want and not sure fit into your current design:

Instead of just MovableObject, would it be possible to add a Scene node and all its children?

For example, I may have a Tree that is made from multiple different entities that are attached together. Or a house that is made the same way, and I'd want the whole thing to be rendered into a single imposter.

I'm not sure what Unique versus NonUnique impostor sets are in your description. Do I have to read the whitepaper to understand?

Anyhow, that's great news :-)
User avatar
tuan kuranes
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 2653
Joined: Wed Sep 24, 2003 8:07 am
Location: Haute Garonne, France
x 4
Contact:

Post by tuan kuranes »

Actually movableObject as target is mainly to suit my needs.

What I need is to be able to act on the target to be impostored, here's the list of thing I have to do with it :

- ability to set target visible or invisible.
- change its renderQueue (render only the target)
- access to material(s) to change the alpha blending between target and impostor.
- get target WorldBoundingBox and target WorldPosition

Perhaps we can get all from a SceneNode pointer ?

It sure would be even more powerful... could "impostor" a would world page and everything attached to...

About distinction :
-Non-Unique is about rendering the exact same tree using the same "texturespace" several times (distant trees, grass blades, etc...).
-Unique make each impostor uses its own texture. (most 3d objects, which angle to camera and placement make it unique in a scene)
User avatar
Xadeck
Halfling
Posts: 77
Joined: Tue Jul 05, 2005 11:16 am
Location: France
Contact:

Post by Xadeck »

jacmoe wrote:I totally agree. :)

I believe that Zadeck is Xavier Decorety - so the Billboard Clouds guy is already introduced to Ogre. :wink:
It spells Xadeck ;-( Contraction of Xavier and Deck of card, a reminder of old times where I was practising card tricks). And my family name is Decoret ;-)

CU soon about Ogre
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Post by jacmoe »

Oops. :oops: (Got the Decorety from Gamasutra).

Looking forward to hearing from you Xadeck. :)
User avatar
tuan kuranes
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 2653
Joined: Wed Sep 24, 2003 8:07 am
Location: Haute Garonne, France
x 4
Contact:

Post by tuan kuranes »

Billboard Patch is here :
http://sourceforge.net/tracker/index.ph ... tid=302997

The Alpha Impostor source code to follow tomorrow...
User avatar
Falagard
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 2060
Joined: Thu Feb 26, 2004 12:11 am
Location: Toronto, Canada
x 3
Contact:

Post by Falagard »

You're my hero :-)
User avatar
tuan kuranes
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 2653
Joined: Wed Sep 24, 2003 8:07 am
Location: Haute Garonne, France
x 4
Contact:

Post by tuan kuranes »

Here's the alpha version (source only) :

http://tuan.kuranes.free.fr/Ogre.html#Impostor


It's using the SceneNode suggestion from Falagard.

Todo :
- Do Heavy lobbying on Ogre Team so that above patch (per billboard texture coordinates) is applied before Dagon release ;) Surely Need a nicely packed binary Demo.
- Create an "UniqueImpostorManager" singleton class that will handle different sets, and if a RenderTexture is full, create a new Set and mode The uniqueImpostorHandler in It. (and destroy the set when it's empty)
- Update the RTT once instead of per Texture Space, but that means one camera and viewport by TextureSpace (could be huge fps boost whe updating lots of impostors, but at large memory price. or not...)
- Comment the code...
- Find a way to make the alpha transition works in all case (including on Movable Objects with shaders) and make use of alpha_rejection to prevent gray borders ?
- Better handles of camera updates (detect roll and yaw)
- handles non-square impostors (need to change texturespace quadtree to something else.) or even support for arbitrary texture resolutions for impostors.
- does not account for changes in orientation of the 3D object, for now user has to manually call 'uniqueimpostorhandler->makeimpostor().' Same for Lighting and object animation changes.
- Load Balancing Imposter Regeneration
- Use max render texture size and max texture unit (and make billoardset supports multitexture)

[edit]Todo list additions.[/edit]
Last edited by tuan kuranes on Thu Jan 12, 2006 10:28 am, edited 9 times in total.
User avatar
Lee04
Minaton
Posts: 945
Joined: Mon Jul 05, 2004 4:06 pm
Location: Sweden
x 1

Billboards 4 Dagon

Post by Lee04 »

You have my support.
We really think this is worth while.

<edit>
Which version of Ogre are this patches for?
</edit>

cheers

Lee04

------------------------------------------------------------------------
Impostors 4 Dagon - Impostors 4 Dagon - Impostors 4 Dagon -
Impostors 4 Dagon - Impostors 4 Dagon - Impostors 4 Dagon -
Impostors 4 Dagon - Impostors 4 Dagon - Impostors 4 Dagon -
------------------------------------------------------------------------
Last edited by Lee04 on Wed Jan 11, 2006 3:19 pm, edited 1 time in total.
User avatar
celic
Gnome
Posts: 363
Joined: Wed Mar 23, 2005 11:05 am
Location: Chisinau/Moldova
Contact:

Post by celic »

Tuan, could you remove the .ncb file from the scripts folder, cause it takes 6 Megs and it's unuseful? This way I hope the zip will be faster to download :)
User avatar
tuan kuranes
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 2653
Joined: Wed Sep 24, 2003 8:07 am
Location: Haute Garonne, France
x 4
Contact:

Post by tuan kuranes »

Good spot, celic, fixed that and it's now 32ko zip !
User avatar
BenO
Goblin
Posts: 241
Joined: Mon Apr 18, 2005 5:03 pm

Post by BenO »

too small ^^

how much time did u spend developping this ?
Benjamin RIGAUD
Software Engineer
User avatar
tuan kuranes
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 2653
Joined: Wed Sep 24, 2003 8:07 am
Location: Haute Garonne, France
x 4
Contact:

Post by tuan kuranes »

@Lee04 : Per Billboard Texture Coordinate patch is for Dagon.

@BenO : It still needs much work. And you'll note many part comes from already done old code (texturespace is adapted from old terrain quadtree/octree code, getscreensize() is mostly from forum posts, etc.). All in all, didn't take much time, cannot say as it's amongst real world tasks, perhaps a few real hours. As stated above it's part of implementing that in plsm2, which is taking me much more time to get visual results acceptable.

Hint : "Google Desktop Search" is a must to easily find old piece of code on your hd just when you need it. It really speed up productivity. (finding articles, code and documents is really easier with it.)
User avatar
tuan kuranes
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 2653
Joined: Wed Sep 24, 2003 8:07 am
Location: Haute Garonne, France
x 4
Contact:

Post by tuan kuranes »

User avatar
Falagard
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 2060
Joined: Thu Feb 26, 2004 12:11 am
Location: Toronto, Canada
x 3
Contact:

Post by Falagard »

That's uber cool!

I personally see this as a major help for trees. Basically I see the LOD for thousands of trees in an outdoor setting looking something like this (distances and polys made up on the spot):

Close up: Highest res trees with mesh trunk (400 polys) + 600 poly billboarded leaves using alpha masking / rejection for leaves.

20 meters: Cross fade to medium res tree with mesh trunk (150 polys) + 200 poly billboarded leaves

60 meters: cross fade to impostor, 2 polys

90 meters: cross fade to billboard, 2 polys, shared by all distant trees of this type. Impostor no longer has to update, texture can be freed.

128 meters: billboard uses static geometry and vertex shader for orientation - so thousands of trees of this type can sit in single buffer.

By the way, I implemented cross fading into the GOOF framework for entities with both regular materials and shaders, but had to make it a mandate that all vertex shaders required a parameter called "opacity".

Also, I had to create a copy of the material during the cross fade and turn on alpha blending, then reset the original material after the fade was finished.

Personally I don't think you necessarily have to implement cross fading into the impostor code, although I can definitely see it as a benefit.

I'm very very impressed by this impostor stuff, nice work. Love it! LOVE IT!

Patch up Dagon for Impostors! Sign the petition!!!
Last edited by Falagard on Wed Jan 11, 2006 8:26 pm, edited 1 time in total.
Shadow007
Gremlin
Posts: 185
Joined: Sat May 07, 2005 3:27 pm

Problems with the code ...

Post by Shadow007 »

First, I'd like to say that I am no active Ogre3d user, just a regular lurker. I'm really impressed by what was done by the Ogre community. That being said, I've seen two potential problems with the code ...

First, the UniqueImpostorManager is not used, thus the two files are superfluous.

Secondly, in the UniqueImpostorHandler::getMinMaxEdgesOfAABBIn2D, there is an error :
In the "for (uint i = 0; i < 8; i++)" part, the first corner could be in the Positive side of the plane, with the result being that A and B will still be initialised to 0 for the next corners. I guess a Bool should used to check if a fisrt corner was found in the Negative side, instead of a if(i == 0).

I hope I made myself understand..

Thanks for all the work !!
User avatar
tuan kuranes
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 2653
Joined: Wed Sep 24, 2003 8:07 am
Location: Haute Garonne, France
x 4
Contact:

Post by tuan kuranes »

@Falagard : I'd like to find an elegant way to do "generic" cross fading, but without contraints like "opacity" shader constants. What would be the best would be to find a way to make "user" have the hand on that by some "callback" system, that will give him the current opacity he should set himself on his object.

@Shadow007: UniqueImpostorManager is not used now, but will be soon. For now, there's no falling back when an impostor didn't find a free "textureSpace" to render in (try allocation a 1024 maxTextureSize for handlers and you'll segfault !).
Manager is the solution. If there is no more room in a Set, it will create a new Set and move the handler in...
Thanks for the bug report on getMinMaxEdgesOfAABBIn2D, i'll fix that in next version (the one with the manager.).

Suggestions are welcome !
User avatar
SunSailor
Gnoll
Posts: 699
Joined: Sun Jan 02, 2005 5:45 pm
Location: Velbert, Germany
x 2
Contact:

Post by SunSailor »

Think this should be at least in the post dagon version if not in dagon itself...
Regarding the demo, it complains about a d3dx9_25.dll missing. Where can I get this? Is there a newer DX-Version, is it something .net related or in which context is it?
User avatar
tuan kuranes
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 2653
Joined: Wed Sep 24, 2003 8:07 am
Location: Haute Garonne, France
x 4
Contact:

Post by tuan kuranes »

look here for link to missing dx dll :
http://www.toymaker.info/Games/html/directx_9_0c.html
(strange has I directly installed december 2005 dxsdk and _25 is stated as coming from april SDK)
User avatar
Falagard
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 2060
Joined: Thu Feb 26, 2004 12:11 am
Location: Toronto, Canada
x 3
Contact:

Post by Falagard »

... make "user" have the hand on that by some "callback" system, that will give him the current opacity he should set himself on his object.
Yup, I agree, that is of course the most generic and flexible way to do it. However, it might end up being painful for the user to use a system like that - having to register a callback mechanism to set the opacity per material.

There are other possibilities though - allow the user to specify a param name or index, and type (float, float4) and/or swizzle (x, y, z, or w) and have it set the parameter into the shader automatically.

Just a thought ;-)

You'll likely still have to create a copy of the material though, especially since materials are shared - you don't want to fade in/out all meshes using that material, just the current one, and you may need to enable scene blending on a material that is normally opaque.

Clay
User avatar
tuan kuranes
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 2653
Joined: Wed Sep 24, 2003 8:07 am
Location: Haute Garonne, France
x 4
Contact:

Post by tuan kuranes »

having to register a callback mechanism to set the opacity per material
But that would by user object types so it should reduce the amount of code needed.
There are other possibilities though ...
yes but they'll all quickly make me write huge amounts of code in order to handle all possible case... (not only shader based material but all materials...)
you may need to enable scene blending on a material that is normally opaque.
same here, what if user object is already using scene blending ? this can lead to a lot of particular case...

I'm thinking about making user have to make a virtual method

Code: Select all

UniqueImpostorHandler::notifyOpacity(const float alpha)
that user will have to overwrite if he wants to handle alpha transition depending on it.
So user will make a class by its scene node impostored type.
suggestions, thoughts ?
User avatar
DrPain
Gnome
Posts: 349
Joined: Tue Jul 05, 2005 2:51 pm
Location: Connecticut, USA

Post by DrPain »

First I want to say that it's fantastic that you're working on this! Much appreciated!
tuan kuranes wrote:I'm thinking about making user have to make a virtual method

Code: Select all

UniqueImpostorHandler::notifyOpacity(const float alpha)
that user will have to overwrite if he wants to handle alpha transition depending on it.
So user will make a class by its scene node impostored type.
suggestions, thoughts ?
Are you saying the user will need a different class for every object type that uses imposters?
A class for every tree type and every building type?
Hopefully the coffee hasn't kicked in yet and I'm misunderstanding you. :)
User avatar
tuan kuranes
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 2653
Joined: Wed Sep 24, 2003 8:07 am
Location: Haute Garonne, France
x 4
Contact:

Post by tuan kuranes »

Are you saying the user will need a different class for every object type that uses imposters?
I would say that it's more application oriented than that.

If user uses only shaders, then he would just have to enable alpha blending and change its opacity shader constant. So one would have only user class to build for all its objects.

It mostly can be one class for all user object, but depending on movable object name and movable object type (user tests), he should easily handles its "material" category (shaders, transparent objects, no shader and no transparency objects, multitexture, diffuse colors only, etc...).
Or he can make one class per category, provided they're not mixed under the same scene node hierarchy given to uniqueImpostorHandler.
Post Reply