1
0
Fork 0

ALS: rotor wash effect for volumetric grass and water shaders

This commit is contained in:
Thorsten Renk 2017-06-27 11:01:23 +03:00
parent 530fc065fc
commit 7c72687ed7
6 changed files with 122 additions and 10 deletions

View file

@ -21,6 +21,9 @@
<grass_modulate_height_min>0.0</grass_modulate_height_min>
<windE><use>/environment/sea/surface/wind-from-east-fps</use></windE>
<windN><use>/environment/sea/surface/wind-from-north-fps</use></windN>
<wash-x><use>/environment/aircraft-effects/wash-x</use></wash-x>
<wash-y><use>/environment/aircraft-effects/wash-y</use></wash-y>
<wash-strength><use>/environment/aircraft-effects/wash-strength</use></wash-strength>
</parameters>
@ -689,6 +692,27 @@
<use>windN</use>
</value>
</uniform>
<uniform>
<name>wash_x</name>
<type>float</type>
<value>
<use>wash-x</use>
</value>
</uniform>
<uniform>
<name>wash_y</name>
<type>float</type>
<value>
<use>wash-y</use>
</value>
</uniform>
<uniform>
<name>wash_strength</name>
<type>float</type>
<value>
<use>wash-strength</use>
</value>
</uniform>
<uniform>
<name>overlay_bias</name>
<type>float</type>

View file

@ -134,6 +134,11 @@
<air_pollution><use>/environment/air-pollution-norm</use></air_pollution>
<ice_cover><use>/environment/sea/surface/ice-cover</use></ice_cover>
<quality_level><use>/sim/rendering/shaders/landmass</use></quality_level>
<!-- rotor wash -->
<wash-x><use>/environment/aircraft-effects/wash-x</use></wash-x>
<wash-y><use>/environment/aircraft-effects/wash-y</use></wash-y>
<wash-strength><use>/environment/aircraft-effects/wash-strength</use></wash-strength>
<!-- filtering -->
<use_filtering><use>/sim/rendering/als-filters/use-filtering</use></use_filtering>
@ -478,6 +483,27 @@
<use>windN</use>
</value>
</uniform>
<uniform>
<name>wash_x</name>
<type>float</type>
<value>
<use>wash-x</use>
</value>
</uniform>
<uniform>
<name>wash_y</name>
<type>float</type>
<value>
<use>wash-y</use>
</value>
</uniform>
<uniform>
<name>wash_strength</name>
<type>float</type>
<value>
<use>wash-strength</use>
</value>
</uniform>
<uniform>
<name>WaveFreq</name>
<type>float</type>

View file

@ -138,6 +138,10 @@
<sea_r><use>/environment/sea/color_r</use></sea_r>
<sea_g><use>/environment/sea/color_g</use></sea_g>
<sea_b><use>/environment/sea/color_b</use></sea_b>
<!-- rotor wash -->
<wash-x><use>/environment/aircraft-effects/wash-x</use></wash-x>
<wash-y><use>/environment/aircraft-effects/wash-y</use></wash-y>
<wash-strength><use>/environment/aircraft-effects/wash-strength</use></wash-strength>
<!-- filtering -->
<use_filtering><use>/sim/rendering/als-filters/use-filtering</use></use_filtering>
<gamma><use>/sim/rendering/als-filters/gamma</use></gamma>
@ -451,6 +455,27 @@
<use>windN</use>
</value>
</uniform>
<uniform>
<name>wash_x</name>
<type>float</type>
<value>
<use>wash-x</use>
</value>
</uniform>
<uniform>
<name>wash_y</name>
<type>float</type>
<value>
<use>wash-y</use>
</value>
</uniform>
<uniform>
<name>wash_strength</name>
<type>float</type>
<value>
<use>wash-strength</use>
</value>
</uniform>
<uniform>
<name>WaveFreq</name>
<type>float</type>

View file

@ -497,6 +497,9 @@
<use-wipers type="int" userarchive="n">0</use-wipers>
<use-overlay type="int" userarchive="n">0</use-overlay>
<overlay-alpha type="float" userarchive="n">1.0</overlay-alpha>
<wash-x type="float" userarchive="n">0.0</wash-x>
<wash-y type="float" userarchive="n">0.0</wash-y>
<wash-strength type="float" userarchive="n">0.0</wash-strength>
</aircraft-effects>

View file

@ -16,6 +16,10 @@ uniform float grass_modulate_height_min;
uniform float wind_x;
uniform float wind_y;
uniform float wash_x;
uniform float wash_y;
uniform float wash_strength;
uniform int grass_modulate_by_overlay;
uniform int grass_groups;
uniform int wind_effects;
@ -89,11 +93,19 @@ void main()
if (g_distance_to_eye > MAX_DISTANCE) {discard;}
vec2 texCoord = gl_TexCoord[0].st;
if (wind_effects > 1)
{
vec2 windDir = normalize(vec2 (max(wind_x, 0.1), wind_y) );
float windStrength = 0.5 * length(vec2 (wind_x, wind_y));
vec2 eyePos = (gl_ModelViewMatrixInverse * vec4 (0.0, 0.0, 0.0, 1.0)).xy;
vec2 washDir = vec2 (wash_x, wash_y) - (g_rawpos - eyePos);
float washStrength = 20.0 * min(14.0 * wash_strength/(length(washDir) + 1.0), 1.0);
washStrength *= (1.0 - 0.8 * sin(20.0 * osg_SimulationTime + length(washDir) + dot(normalize(washDir), vec2(1.0, 0.0))));
vec2 windDir = normalize(vec2 (max(wind_x, 0.1), wind_y) + washStrength * vec2 (-washDir.y, washDir.x));
float windStrength = 0.5 * length(vec2 (wind_x, wind_y)) + washStrength;
float windAmplitude = 1.0 + 0.3 * windStrength;
float sineTerm = sin(0.7 * windStrength * osg_SimulationTime + 0.05 * (g_rawpos.x + g_rawpos.y));
sineTerm = sineTerm + sin(0.6 * windStrength * osg_SimulationTime + 0.04 * (g_rawpos.x + g_rawpos.y));
@ -101,9 +113,7 @@ void main()
sineTerm = sineTerm/3.0;
sineTerm = 5.0 * sineTerm * sineTerm;
float windDisplacement = pow(g_layer/32.0, 2.0) * clamp((windStrength + windAmplitude * sineTerm), -30.0, 30.0);
float windDisplacement = pow(g_layer/32.0, 2.0) * clamp((windStrength + windAmplitude * sineTerm), -35.0, 35.0);
texCoord += (windDisplacement * windDir);
}

View file

@ -63,6 +63,10 @@ uniform float landing_light1_offset;
uniform float landing_light2_offset;
uniform float landing_light3_offset;
uniform float wash_x;
uniform float wash_y;
uniform float wash_strength;
uniform int quality_level;
uniform int tquality_level;
uniform int ocean_flag;
@ -489,22 +493,42 @@ void main(void)
//add foam
vec4 foam_texel = texture2D(sea_foam, vec2(waterTex2 * tscale) * 25.0);
if (dist < 10000.0)
{
float foamSlope = 0.10 + 0.1 * windScale;
// rotor wash
vec2 washDir = vec2 (wash_x, wash_y) - relPos.xy;
float washDist = length(washDir);
float washStrength = 3.0 * min(14.0 * wash_strength/(washDist + 1.0), 1.0);
float timeFact = sin(-30.0 * osg_SimulationTime + 1.5 * washDist + dot(normalize(washDir), vec2(1.0, 0.0)));
float noiseFact = 0.5 * Noise2D(vec2 (relPos.x + 30.0 * osg_SimulationTime, relPos.y), 1.1);
noiseFact+= 0.5 * Noise2D(vec2 (relPos.x - 31.0 *osg_SimulationTime, relPos.y ), 1.0);
washStrength *= (0.5 + (0.3 * noiseFact) + (0.2 * noiseFact * clamp(timeFact, -0.2, 1.0)));
//washStrength *= (0.5 + (0.3 * noiseFact * clamp(timeFact, -0.2, 1.0)));
float waveSlope = N.g;
float surfFact = 0.0;
if ((windEffect >= 8.0) || (steepness < 0.999) || (topoTexel.a > 0.98))
surfFact += washStrength;
if ((windEffect >= 8.0) || (steepness < 0.999) || (topoTexel.a > 0.98) || (washStrength > 0.5))
{
if ((waveSlope > 0.0) && (ocean_flag ==1))
{
surfFact = surfFact +(1.0 -smoothstep(0.97,1.0,steepness));
surfFact += 0.5 * smoothstep(0.98,1.0,topoTexel.a);
waveSlope = waveSlope + 2.0 * surfFact;
}
waveSlope = waveSlope + 2.0 * surfFact;
if (waveSlope >= foamSlope){
finalColor = mix(finalColor, max(finalColor, finalColor + foam_texel), smoothstep(0.01, 0.50, N.g+0.2 * surfFact));
}