Board index FlightGear Development Effects and shaders

Plantation effect

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

Plantation effect

Postby frtps » Thu Oct 17, 2019 8:53 am

Rather than use random vegetation I'd like to simulate tree plantations by generating regularly-spaced, almost uniform-height trees, but perhaps with variations in the row directions. Is there any such effect already in the shader directory, or a way to produce it with pre-existing shader variables?
frtps
 
Posts: 49
Joined: Sun Aug 05, 2018 9:58 am

Re: Plantation effect

Postby Thorsten » Thu Oct 17, 2019 8:57 am

I don't think it exists, but it should be significantly easier to do than the random size patches of trees we have now - essentially just use 1-dim noise.
Thorsten
 
Posts: 11189
Joined: Mon Nov 02, 2009 8:33 am

Re: Plantation effect

Postby vnts » Fri Oct 18, 2019 2:42 pm

Reminds me :) . I wondered about generic instancing effect(s) support when I was tinkering a bit with shaders a while ago. It seemed conceptually useful for many things (?). One that accepts a generic model - which could be 2 quads for trees. It would create an arbitrary 2d grid of objects. A line of trees or windmills would be just a subset. It would also have some random variation in spacing and rotation, as well as object slots that are randomly empty.

The thought came from noticing airports have things like car parks full of simple car models that can hit frame rate disproportionately (maybe needs project3000 to show up?). Airports also tend to have manually placed trees, or various objects. Not sure if manually placed trees miss out on special lighting done by tree shader (season effects too).

Something conceptually along the lines of:

Input to shaders by engine might include: 1. some instance ID, 2. something to distinguish it from other of the effect in view, 3. # rows&columns, 4. location of two diagonally opposite corners of grid, 5. bounding radius/dimensions, 6. min&max spacing variation in both directions, 7. min&max rotation angles & variation, 8. a parameter 0-1 that tweaks the distribution in variation (how common the extremes are), 9. probability of an object slot being empty like , 10. some parameters for random color or texture variation for cars&similar.

1&2 - give a random PRNG seed for each object.
4-9 - supplied by the scenery maker in an XML(?) file distributed via terrasync. 9. can be done by shaders by if convenient (fragment discard statement or maybe collapsing vertices into a point?).
10 - may need variants of shaders unless there's a convenient way to specify masks for colour changes for everything without slow down - via spare mask channels, texture colour lookup tables, texture swaps, or something.

Edit: Random spacing away from airports in uneven terrain is harder, unless the general slope around each object position was also given by the engine, and variation in spacing (or slope) was small.

Grids with varying objects like objects like different vehicle models would be harder, and might be faked with 2-3 uses with different spacing.

Instancing support for manually specified position & rotation might also improve performance since airports often have duplicated objects(?).

Just a thought. Not sure if that's workable, fast, or easy to implement.

(Engine functionality to instance specified models without changing c++ may also be useful for objects bordering straight streets, like rows of streetlamps&road barriers&hedges.)

Kind regards
vnts
 
Posts: 101
Joined: Thu Apr 02, 2015 12:29 am

Re: Plantation effect

Postby frtps » Thu Nov 14, 2019 8:55 am

So I've developed some code to produce a "plantation" effect. I expect this could be used for orchards and agroforestry. Not for vineyards unfortunately as the vegetation system instantiates a tree as two planes at right angles.

Image

The code places trees at integer spacings on the x,y coordinate grid in which the triangles are expressed (so I guess on a N-S E-W grid). I've done it this way so that neighbouring triangles and tiles will not have problems with trees getting too close together at the boundaries, as they'll all be on the same underlying grid. The spacing is simply based on the usual wood coverage material property. Things like tree height variation and masks can all be managed through the currently available material properties.

In order to switch on this effect, I think there would have to be a new "plantation" material property. Note that the tree positions (random or regular) are calculated outside the shader system (i.e. the positions are only generated CPU-side once when the tile is loaded).

Does adding a <plantation> boolean material property sound reasonable? Is the N-S E-W grid layout too limiting?
frtps
 
Posts: 49
Joined: Sun Aug 05, 2018 9:58 am

Re: Plantation effect

Postby Thorsten » Thu Nov 14, 2019 9:15 am

Sweet :D

For a C++ side change and how to interface it, best contact the mailing list for opinions - too few developers check the forum for those things.

(Note that since we position trees in the vertex shader, we could just force them to integer positions there - which might be a less intrusive change).
Thorsten
 
Posts: 11189
Joined: Mon Nov 02, 2009 8:33 am

Re: Plantation effect

Postby Icecode GL » Thu Nov 14, 2019 11:20 am

Looking nice!

In order to switch on this effect, I think there would have to be a new "plantation" material property.


In my opinion that sounds like a good option. It's an artificial forest but it's still a forest, so a boolean property makes sense to me. It's also very backwards compatible as you could just assume it's false by default.
Icecode GL
 
Posts: 569
Joined: Thu Aug 12, 2010 12:17 pm
Location: Spain
Callsign: icecode
Version: GIT
OS: Arch Linux

Re: Plantation effect

Postby Thorsten » Thu Nov 14, 2019 12:03 pm

Actually it could be a more general integer encoding - that could accomodate more complicated future shapes (trees preferably bunched together in groups, ...)
Thorsten
 
Posts: 11189
Joined: Mon Nov 02, 2009 8:33 am

Re: Plantation effect

Postby GinGin » Thu Nov 14, 2019 12:40 pm

That is a very nice piece of work.
GinGin
 
Posts: 802
Joined: Wed Jul 05, 2017 10:41 am
Location: Paris
Callsign: Gingin

Re: Plantation effect

Postby wlbragg » Thu Nov 14, 2019 3:26 pm

Looks good, could it also be adapted as row crops?
Kansas(2-27-15)/Ohio/Midwest scenery development.
KEQA (2-27-15), 3AU, KRCP Airport Layout
Intel i5 3570K AMDRX480
User avatar
wlbragg
 
Posts: 4988
Joined: Sat Aug 25, 2012 11:31 pm
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Linux/AMDRX480

Re: Plantation effect

Postby frtps » Thu Nov 14, 2019 10:07 pm

wlbragg wrote in Thu Nov 14, 2019 3:26 pm:Looks good, could it also be adapted as row crops?


No reason you couldn't, all you would do in the material definition is to supply the e.g. corn stalk "tree" texture swatch and other vegetation parameters as per usual. Not sure about the hit on the graphics/CPU from instantiating vegetation at typical crop densities though.
frtps
 
Posts: 49
Joined: Sun Aug 05, 2018 9:58 am

Re: Plantation effect

Postby frtps » Thu Nov 14, 2019 10:10 pm

Thorsten wrote in Thu Nov 14, 2019 9:15 am:Sweet :D

For a C++ side change and how to interface it, best contact the mailing list for opinions - too few developers check the forum for those things.

(Note that since we position trees in the vertex shader, we could just force them to integer positions there - which might be a less intrusive change).


Roger that. I'll switch my attention to the mailing list.
frtps
 
Posts: 49
Joined: Sun Aug 05, 2018 9:58 am


Return to Effects and shaders

Who is online

Users browsing this forum: No registered users and 2 guests