Board index FlightGear Development Effects and shaders

optimizing random trees: strong effect on performance ?

An exciting "new" option in FlightGear, that includes reflections, lightmaps, the particle system etc.. A lot is yet to be discovered/implemented!

Re: optimizing random trees: strong effect on performance ?

Postby erik » Sat Nov 21, 2015 10:15 am

That would be good news, I might take a stab at it. But that part of the code is all new to me, so I might come back with a question or two.

Erik
Current: Parachutist, Paraglider, Pterosaur, Pilatus PC-9M and variants, ERCO Ercoupe, Fokker Dr.1, Fokker 50, Fokker 100
Less active: Cessna T-37, T-38, Santa Claus. Previous: General Dynamics F-16. Worked on: Wright Flyer
erik
 
Posts: 2245
Joined: Thu Nov 01, 2007 2:41 pm

Re: optimizing random trees: strong effect on performance ?

Postby Thorsten » Sat Nov 21, 2015 10:36 am

With the ability to run a specific forest effect per landclass we have now, I think it's worth looking into the idea of shader-based LOD again. I had code to change four single trees drawn with two quads against four trees shown on the single quad beyond some distance at some point, but the pitfall was that this sucked for isolated trees (you'd see isolated trees being replaced by a group of trees in the distance).

For dense forests, it gave quite some performance boost. I could go from tree density 2 to tree density 5-6 with equal performance impact if I remember correctly.
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: optimizing random trees: strong effect on performance ?

Postby erik » Sat Nov 21, 2015 12:00 pm

Sounds like a neat trick!

Erik
Current: Parachutist, Paraglider, Pterosaur, Pilatus PC-9M and variants, ERCO Ercoupe, Fokker Dr.1, Fokker 50, Fokker 100
Less active: Cessna T-37, T-38, Santa Claus. Previous: General Dynamics F-16. Worked on: Wright Flyer
erik
 
Posts: 2245
Joined: Thu Nov 01, 2007 2:41 pm

Re: optimizing random trees: strong effect on performance ?

Postby erik » Mon Nov 23, 2015 11:49 am

I don't seem to be able to let the billboards show up in the scene. Looks like an incorrect rotation or a double rotation or something, quite frustrating as it took me half an hour to get the billboards code in and three full days to ultimately give up on it.

I guess someone who actually knows how this code is supposed to work should better take a look.

Erik
Current: Parachutist, Paraglider, Pterosaur, Pilatus PC-9M and variants, ERCO Ercoupe, Fokker Dr.1, Fokker 50, Fokker 100
Less active: Cessna T-37, T-38, Santa Claus. Previous: General Dynamics F-16. Worked on: Wright Flyer
erik
 
Posts: 2245
Joined: Thu Nov 01, 2007 2:41 pm

Re: optimizing random trees: strong effect on performance ?

Postby erik » Mon Nov 23, 2015 12:48 pm

Interesting find, after replacing osg::Billboard with osg::Geode I still do not see any trees further back.
But I did not add Effects again: Are the trees only written to the quad using shaders perhaps?

Erik
Current: Parachutist, Paraglider, Pterosaur, Pilatus PC-9M and variants, ERCO Ercoupe, Fokker Dr.1, Fokker 50, Fokker 100
Less active: Cessna T-37, T-38, Santa Claus. Previous: General Dynamics F-16. Worked on: Wright Flyer
erik
 
Posts: 2245
Joined: Thu Nov 01, 2007 2:41 pm

Re: optimizing random trees: strong effect on performance ?

Postby Thorsten » Mon Nov 23, 2015 1:00 pm

Yes, trees won't work without running the effect.
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: optimizing random trees: strong effect on performance ?

Postby erik » Mon Nov 23, 2015 1:05 pm

Ok thanks, something to look at then.

Erik
Current: Parachutist, Paraglider, Pterosaur, Pilatus PC-9M and variants, ERCO Ercoupe, Fokker Dr.1, Fokker 50, Fokker 100
Less active: Cessna T-37, T-38, Santa Claus. Previous: General Dynamics F-16. Worked on: Wright Flyer
erik
 
Posts: 2245
Joined: Thu Nov 01, 2007 2:41 pm

Re: optimizing random trees: strong effect on performance ?

Postby Thorsten » Mon Nov 23, 2015 1:14 pm

I *suspect* billboarding inside the shader might also be faster than letting the CPU do it - at least that's how it worked for clouds. But I don't know for sure.
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: optimizing random trees: strong effect on performance ?

Postby erik » Mon Nov 23, 2015 1:23 pm

Well, using shaders for tree rendering renders the use of Billboards useless since the shader makes assumptions that they are crosses (omitting the second quad causes a crash) and may have shadows (ye another quad).
So it is essentially useless to go after billboards without a major overhaul of the shaders.

Erik
Current: Parachutist, Paraglider, Pterosaur, Pilatus PC-9M and variants, ERCO Ercoupe, Fokker Dr.1, Fokker 50, Fokker 100
Less active: Cessna T-37, T-38, Santa Claus. Previous: General Dynamics F-16. Worked on: Wright Flyer
erik
 
Posts: 2245
Joined: Thu Nov 01, 2007 2:41 pm

Re: optimizing random trees: strong effect on performance ?

Postby Thorsten » Mon Nov 23, 2015 1:31 pm

I'm not sure what you have in mind.

Currently on the C++ side trees are just created as three quads (cross + shadow) and the position and orientation data is dumped to the generic attributes gl_Color and gl_FogCoord etc.

The shader then uses that information to position, scale and rotate the trees and (if so desired) to generate the shadow.

Within this scheme, position of the quad or orientation doesn't really have any meaning before the vertex shader runs.

I believe we use this instancing scheme because it turned out to be faster than anything else.

Now, dropping quads as well as billboarding quads beyond a certain distance are operations that can also be done inside the vertex shader (see the cloud vertex shader for instance). So, either you have to implement these operations inside the shader, or you need to use a different effect for the billboarded trees (basically model-default.eff) since you want just light and fog, but none of the positioning/re-scaling operations we currently do inside tree.eff.
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: optimizing random trees: strong effect on performance ?

Postby erik » Mon Nov 23, 2015 1:33 pm

Nice if I had known all this in advance I could have spent my time more usefully.

Erik
Current: Parachutist, Paraglider, Pterosaur, Pilatus PC-9M and variants, ERCO Ercoupe, Fokker Dr.1, Fokker 50, Fokker 100
Less active: Cessna T-37, T-38, Santa Claus. Previous: General Dynamics F-16. Worked on: Wright Flyer
erik
 
Posts: 2245
Joined: Thu Nov 01, 2007 2:41 pm

Re: optimizing random trees: strong effect on performance ?

Postby Thorsten » Mon Nov 23, 2015 1:39 pm

Sorry - I was enjoying 47 hours of power outage during the last days and didn't even realize until now that you'd be working on it. I think Stuart is the person to talk to for the C++ side of things (though I know some from the shadow work) - I'm most familiar with the GLSL side.
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: optimizing random trees: strong effect on performance ?

Postby erik » Mon Nov 23, 2015 1:42 pm

If you want to take it over using shaders, my idea was the following:

up to 2km use the current scheme
beyond that use single textured quads always facing the camera, no effects like moving and shadows.

Erik
Current: Parachutist, Paraglider, Pterosaur, Pilatus PC-9M and variants, ERCO Ercoupe, Fokker Dr.1, Fokker 50, Fokker 100
Less active: Cessna T-37, T-38, Santa Claus. Previous: General Dynamics F-16. Worked on: Wright Flyer
erik
 
Posts: 2245
Joined: Thu Nov 01, 2007 2:41 pm

Re: optimizing random trees: strong effect on performance ?

Postby stuart » Mon Nov 23, 2015 1:47 pm

Hi Erik,

Sorry you ended up on a bit of a wild goose-chase on this. I had (foolishly on my part) assumed you were already familiar with how the trees worked.

osg::Billboard is almost certainly the wrong direction to look for performance improvement. The reason Tim and I implemented the trees the way we did was to avoid having to use it as it was a complete performance drain. I suspect the problem is that it's doing a bunch of transformations in the CPU, and then pushing each object individually to the GPU, rather than the shader approach which streams a bunch of instantiations and uses GPU code to wort them out.

I'd suggest starting with modifying the existing trees so that only a single quad it generated. That should give you an idea of what perf improvement to expect and whether there is mileage in it. The shader code to do the billboarding shouldn't be too difficult - there's examples in the cloud shader code already.

-Stuart
G-MWLX
User avatar
stuart
Moderator
 
Posts: 1629
Joined: Wed Nov 29, 2006 10:56 am
Location: Edinburgh
Callsign: G-MWLX

Re: optimizing random trees: strong effect on performance ?

Postby erik » Mon Nov 23, 2015 1:50 pm

Problem is, a single quad doesn't work since the shader expects more than one (up tot three), causing a crash in my video driver. I guess it's best to let the shader decide not to render the other two.

Erik
Current: Parachutist, Paraglider, Pterosaur, Pilatus PC-9M and variants, ERCO Ercoupe, Fokker Dr.1, Fokker 50, Fokker 100
Less active: Cessna T-37, T-38, Santa Claus. Previous: General Dynamics F-16. Worked on: Wright Flyer
erik
 
Posts: 2245
Joined: Thu Nov 01, 2007 2:41 pm

PreviousNext

Return to Effects and shaders

Who is online

Users browsing this forum: No registered users and 2 guests