Board index FlightGear Development Effects and shaders

Volumetric grass (was 3D textures and volumetric data)

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

Re: 3D textures and volumetric data

Postby Icecode GL » Tue May 16, 2017 11:50 am

My first version actually used your noise functions to generate each layer. By applying a low pass filter to a randomly generated texture and a threshold decreasing with each consecutive layer (more density at the bottom and less at the top) you could get pretty good results. In fact, the Screenshot of the Month entry used that method.

Although there are advantages to using noise functions (mainly avoiding pattern repetition), most are disadvantages. As you said, Moire patterns appear and aliasing is hard to do. Distant grass just disappears since the texels are too small to be drawn and no mipmapping is available. I had no idea how to fix all of this so I just focused on the texture based approach and hoped that worked better.

if I do it explicitly, the hardware balks and refuses to generate so many vertices.


That's the main problem with geometry shaders (apart from being slow for tessellation which is what they were supposed to be used for) and why their use is so limited. But I'm sure we can get around those limitations with some kind of LOD system. At the end of the day no one cares about grass when flying.


I just tested your implementation and it looks amazing! I guess we should stick to the noise approach.
Icecode GL
 
Posts: 529
Joined: Thu Aug 12, 2010 12:17 pm
Location: Spain
Callsign: icecode
Version: GIT
OS: Arch Linux

Re: Volumetric grass (was 3D textures and volumetric data)

Postby Thorsten » Tue May 16, 2017 1:21 pm

Although there are advantages to using noise functions (mainly avoiding pattern repetition), most are disadvantages. As you said, Moire patterns appear and aliasing is hard to do. Distant grass just disappears since the texels are too small to be drawn and no mipmapping is available.


Mipmapping is just an averaging procedure, so for any procedural noise you do something roughly equivalent - you make the noise scale larger and the contrast lower.

In the event, we can just increase blade sizes a bit, decrease alpha to compensate and drop fragments when alpha has floored out.

I guess ideally we'd also run the geometry shader conditional on a distance cut (running the whole fur generator as a second pass on top of the default airfield effect actually leads to fairly non-tiling results here for all viewing distances).

I believe there's tons of advantages to noise functions - right now we can bend the blades dependent on wind direction and strength for instance. The noise function can be modulated to yield lower and higher density, and if the modulation is chosen to agree with the noise function of the base layer, we can draw high grass density on green patches and low grass density on brown patches.

But I do need a fragment distance somehow... I guess lighting can be flat and fogging faked by fading fragments to alpha, but... there needs to be a viable distance measure.
Thorsten
 
Posts: 10986
Joined: Mon Nov 02, 2009 8:33 am

Re: Volumetric grass (was 3D textures and volumetric data)

Postby Icecode GL » Tue May 16, 2017 1:53 pm

so for any procedural noise you do something roughly equivalent - you make the noise scale larger and the contrast lower.


True that. I'm just not familiar enough with noise functions to come up with those ideas, let alone implement them!


My opinion is that we should just pass the raw vertex position to the fragment shader, even if that means decreasing the max amount of layers. That would fix the tiling issues (we can use the vertex raw pos together with the texture coords) and the distance between the fragment and the eye would be available to you. 16 layers still gives good results, so we can play around with that value.

Apart from that, I thought of dynamically extruding more layers the nearer the camera is to the vertex. It would help decreasing the vertex count on screen.

right now we can bend the blades dependent on wind direction and strength for instance.


Talking about wind, this should work:
Code: Select all
#define WIND_WEIGHT 0.01
uniform float wind_x;
uniform float wind_y;

[...]

vec2 texCoord = gl_TexCoord[0].st;

float rndWindAngle = rand2D(floor(texCoord * 10.0)) * 6.2831853;
vec2 rndWindDir = vec2(cos(rndWindAngle), sin(rndWindAngle));
vec2 windDir = normalize(vec2(wind_x, wind_y) + rndWindDir * 0.2);

float windFunction = sin(time + rand2D(floor(texCoord * 50.0)) * 2.0);
float windDisplacement = windFunction * pow(g_layer/32.0, 2.0) * WIND_WEIGHT;

texCoord += windDir * windDisplacement;


Adding more erratic movement is just a matter of choosing a fancy function like overlapping different frequency sine waves instead of a plain simple sine wave.
Icecode GL
 
Posts: 529
Joined: Thu Aug 12, 2010 12:17 pm
Location: Spain
Callsign: icecode
Version: GIT
OS: Arch Linux

Re: Volumetric grass (was 3D textures and volumetric data)

Postby Thorsten » Tue May 16, 2017 3:02 pm

Okay, I think I have LOD, fog and lighting under control. One can get by with a lot of cheating... One factor is to choose consistent colors between grass texture sheet and base sheet, the other is to give the blades a decent amount of alpha to begin with. Still flickers a bit, but not much worse than trees rendered with alpha to coverage.

Image

That's kind of the worst case I've produced - you see the Moire and the LOD border a bit, but you need to know what you're looking for (base layer and overlay layer getting quite different color here...)

Image

See my latest files here - need to prepare dinner now... feel free to adapt and refine, it's sure not elegant right now...

Edit: Performance-wise, I didn't see much of a dent, but I threw a GeForce 1080 at it, so that may not mean it's not expensive...
Thorsten
 
Posts: 10986
Joined: Mon Nov 02, 2009 8:33 am

Re: Volumetric grass (was 3D textures and volumetric data)

Postby Icecode GL » Tue May 16, 2017 3:50 pm

Performance-wise, I didn't see much of a dent, but I threw a GeForce 1080 at it, so that may not mean it's not expensive...


My frames drop from 60 to 30 fps as soon as the grass covers the entire screen. No idea where the bottleneck is.
EDIT: I actually know where the bottleneck is: in my own testing code. :mrgreen: It runs a solid 60 fps on my machine, which isn't specially last-gen.
Icecode GL
 
Posts: 529
Joined: Thu Aug 12, 2010 12:17 pm
Location: Spain
Callsign: icecode
Version: GIT
OS: Arch Linux

Re: Volumetric grass (was 3D textures and volumetric data)

Postby Thorsten » Tue May 16, 2017 5:33 pm

Talking about wind, this should work(...)


I was actually thinking of biasing the bending part in the noise function - in zero wind, the direction into which blades lean would be random, but in steady wind they'd all be pushed into the same direction by the wind.
Thorsten
 
Posts: 10986
Joined: Mon Nov 02, 2009 8:33 am

Re: Volumetric grass (was 3D textures and volumetric data)

Postby wlbragg » Tue May 16, 2017 5:43 pm

Is this potentially a replacement for the current grass effect or in addition? If there is a choice I would prefer to continue to have access to the current implementation. I think they both have some useful features.
Kansas(2-27-15)/Ohio/Midwest scenery development.
KEQA (2-27-15), 3AU, KRCP Airport Layout
User avatar
wlbragg
 
Posts: 4891
Joined: Sat Aug 25, 2012 11:31 pm
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Debain/nVGT640

Re: Volumetric grass (was 3D textures and volumetric data)

Postby Thorsten » Tue May 16, 2017 6:30 pm

As I said, in the pic this is rendered on top of the current airfield.eff in a second pass.

Which we'll have optional.
Thorsten
 
Posts: 10986
Joined: Mon Nov 02, 2009 8:33 am

Re: Volumetric grass (was 3D textures and volumetric data)

Postby Catalanoic » Tue May 16, 2017 10:05 pm

"I think they both have some useful features."" +1
User avatar
Catalanoic
 
Posts: 1053
Joined: Mon Mar 05, 2012 12:33 am
Location: Barcelona (LEBL)
Callsign: Catalanoic
Version: 2017.3
OS: Lubuntu/Windows 7

Re: Volumetric grass (was 3D textures and volumetric data)

Postby Icecode GL » Wed May 17, 2017 3:15 pm

I was actually thinking of biasing the bending part in the noise function - in zero wind, the direction into which blades lean would be random, but in steady wind they'd all be pushed into the same direction by the wind.


Blade length varies when bending is done in the noise function. The blade gets cut laterally when it reaches the next blade bounding box. That's why I decided to do it in texture space before the noise function.
Icecode GL
 
Posts: 529
Joined: Thu Aug 12, 2010 12:17 pm
Location: Spain
Callsign: icecode
Version: GIT
OS: Arch Linux

Re: Volumetric grass (was 3D textures and volumetric data)

Postby Thorsten » Wed May 17, 2017 4:50 pm

Blade length varies when bending is done in the noise function. The blade gets cut laterally when it reaches the next blade bounding box.


True, but do we care (aka, is anyone actually going to see this when thousands of grass blades move)?
Thorsten
 
Posts: 10986
Joined: Mon Nov 02, 2009 8:33 am

Re: Volumetric grass (was 3D textures and volumetric data)

Postby Icecode GL » Wed May 17, 2017 6:00 pm

Actually yes! The whole terrain seems to move up and down when bending is applied. Try it yourself to see what I mean.
Icecode GL
 
Posts: 529
Joined: Thu Aug 12, 2010 12:17 pm
Location: Spain
Callsign: icecode
Version: GIT
OS: Arch Linux

Re: Volumetric grass (was 3D textures and volumetric data)

Postby wlbragg » Wed May 17, 2017 7:20 pm

Combined with the other grass effect.

Image
Kansas(2-27-15)/Ohio/Midwest scenery development.
KEQA (2-27-15), 3AU, KRCP Airport Layout
User avatar
wlbragg
 
Posts: 4891
Joined: Sat Aug 25, 2012 11:31 pm
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Debain/nVGT640

Re: Volumetric grass (was 3D textures and volumetric data)

Postby Thorsten » Thu May 18, 2017 9:23 am

... ain't this nice-looking?
Thorsten
 
Posts: 10986
Joined: Mon Nov 02, 2009 8:33 am

Re: Volumetric grass (was 3D textures and volumetric data)

Postby Catalanoic » Thu May 18, 2017 10:20 am

Really nice indeed, maybe fewer textured grass amount and change the same color like the grass shader effect to get an optimal result.
User avatar
Catalanoic
 
Posts: 1053
Joined: Mon Mar 05, 2012 12:33 am
Location: Barcelona (LEBL)
Callsign: Catalanoic
Version: 2017.3
OS: Lubuntu/Windows 7

PreviousNext

Return to Effects and shaders

Who is online

Users browsing this forum: themexicannon and 8 guests