1
0
Fork 0

Prepare ALS tree shader for filtering, add functionality for (optional) agressive optimization

This commit is contained in:
Thorsten Renk 2016-03-26 09:02:51 +02:00
parent c2ac3b8e13
commit 9afc904482
7 changed files with 145 additions and 19 deletions

10
Effects/tree-forest.eff Normal file
View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<PropertyList>
<name>Effects/tree-forest</name>
<inherits-from>Effects/tree</inherits-from>
<parameters>
<use_tree_shadows>true</use_tree_shadows>
<use_forest_effect>true</use_forest_effect>
<tree_patches>true</tree_patches>
</parameters>
</PropertyList>

View file

@ -57,6 +57,14 @@
<landing_light1_offset><use>/sim/rendering/als-secondary-lights/landing-light1-offset-deg</use></landing_light1_offset> <landing_light1_offset><use>/sim/rendering/als-secondary-lights/landing-light1-offset-deg</use></landing_light1_offset>
<landing_light2_offset><use>/sim/rendering/als-secondary-lights/landing-light2-offset-deg</use></landing_light2_offset> <landing_light2_offset><use>/sim/rendering/als-secondary-lights/landing-light2-offset-deg</use></landing_light2_offset>
<landing_light3_offset><use>/sim/rendering/als-secondary-lights/landing-light3-offset-deg</use></landing_light3_offset> <landing_light3_offset><use>/sim/rendering/als-secondary-lights/landing-light3-offset-deg</use></landing_light3_offset>
<use_filtering><use>/sim/rendering/als-filters/use-filtering</use></use_filtering>
<gamma><use>/sim/rendering/als-filters/gamma</use></gamma>
<brightness><use>/sim/rendering/als-filters/brightness</use></brightness>
<use_night_vision><use>/sim/rendering/als-filters/use-night-vision</use></use_night_vision>
<use_IR_vision><use>/sim/rendering/als-filters/use-IR-vision</use></use_IR_vision>
<delta_T><use>/environment/surface/delta-T-vegetation</use></delta_T>
<use_optimization><use>/sim/rendering/random-vegetation-optimize</use></use_optimization>
<tree_patches>false</tree_patches>
<cloudpos1_x><use>/local-weather/cloud-shadows/cloudpos-x[0]</use></cloudpos1_x> <cloudpos1_x><use>/local-weather/cloud-shadows/cloudpos-x[0]</use></cloudpos1_x>
<cloudpos1_y><use>/local-weather/cloud-shadows/cloudpos-y[0]</use></cloudpos1_y> <cloudpos1_y><use>/local-weather/cloud-shadows/cloudpos-y[0]</use></cloudpos1_y>
<cloudpos2_x><use>/local-weather/cloud-shadows/cloudpos-x[1]</use></cloudpos2_x> <cloudpos2_x><use>/local-weather/cloud-shadows/cloudpos-x[1]</use></cloudpos2_x>
@ -149,6 +157,7 @@
<fragment-shader>Shaders/tree-ALS-shadow.frag</fragment-shader> <fragment-shader>Shaders/tree-ALS-shadow.frag</fragment-shader>
<fragment-shader>Shaders/secondary_lights.frag</fragment-shader> <fragment-shader>Shaders/secondary_lights.frag</fragment-shader>
<fragment-shader>Shaders/hazes.frag</fragment-shader> <fragment-shader>Shaders/hazes.frag</fragment-shader>
<fragment-shader>Shaders/filters-ALS.frag</fragment-shader>
</program> </program>
<uniform> <uniform>
<name>visibility</name> <name>visibility</name>
@ -265,6 +274,38 @@
<type>float</type> <type>float</type>
<value><use>landing_light3_offset</use></value> <value><use>landing_light3_offset</use></value>
</uniform> </uniform>
<!-- filtering -->
<uniform>
<name>gamma</name>
<type>float</type>
<value><use>gamma</use></value>
</uniform>
<uniform>
<name>brightness</name>
<type>float</type>
<value><use>brightness</use></value>
</uniform>
<uniform>
<name>use_night_vision</name>
<type>bool</type>
<value><use>use_night_vision</use></value>
</uniform>
<uniform>
<name>use_IR_vision</name>
<type>bool</type>
<value><use>use_IR_vision</use></value>
</uniform>
<uniform>
<name>use_filtering</name>
<type>bool</type>
<value><use>use_filtering</use></value>
</uniform>
<uniform>
<name>delta_T</name>
<type>float</type>
<value><use>delta_T</use></value>
</uniform>
<!-- cloud shadows -->
<uniform> <uniform>
<name>cloudpos1_x</name> <name>cloudpos1_x</name>
<type>float</type> <type>float</type>
@ -510,6 +551,16 @@
<type>bool</type> <type>bool</type>
<value><use>use_tree_shadows</use></value> <value><use>use_tree_shadows</use></value>
</uniform> </uniform>
<uniform>
<name>use_optimization</name>
<type>bool</type>
<value><use>use_optimization</use></value>
</uniform>
<uniform>
<name>tree_patches</name>
<type>bool</type>
<value><use>tree_patches</use></value>
</uniform>
<uniform> <uniform>
<name>forest_effect_size</name> <name>forest_effect_size</name>
<type>float</type> <type>float</type>
@ -595,6 +646,7 @@
<fragment-shader>Shaders/tree-ALS.frag</fragment-shader> <fragment-shader>Shaders/tree-ALS.frag</fragment-shader>
<fragment-shader>Shaders/secondary_lights.frag</fragment-shader> <fragment-shader>Shaders/secondary_lights.frag</fragment-shader>
<fragment-shader>Shaders/hazes.frag</fragment-shader> <fragment-shader>Shaders/hazes.frag</fragment-shader>
<fragment-shader>Shaders/filters-ALS.frag</fragment-shader>
</program> </program>
<uniform> <uniform>
<name>visibility</name> <name>visibility</name>
@ -711,6 +763,38 @@
<type>float</type> <type>float</type>
<value><use>landing_light3_offset</use></value> <value><use>landing_light3_offset</use></value>
</uniform> </uniform>
<!-- filtering -->
<uniform>
<name>gamma</name>
<type>float</type>
<value><use>gamma</use></value>
</uniform>
<uniform>
<name>brightness</name>
<type>float</type>
<value><use>brightness</use></value>
</uniform>
<uniform>
<name>use_night_vision</name>
<type>bool</type>
<value><use>use_night_vision</use></value>
</uniform>
<uniform>
<name>use_IR_vision</name>
<type>bool</type>
<value><use>use_IR_vision</use></value>
</uniform>
<uniform>
<name>use_filtering</name>
<type>bool</type>
<value><use>use_filtering</use></value>
</uniform>
<uniform>
<name>delta_T</name>
<type>float</type>
<value><use>delta_T</use></value>
</uniform>
<!-- cloud shadows -->
<uniform> <uniform>
<name>cloudpos1_x</name> <name>cloudpos1_x</name>
<type>float</type> <type>float</type>

View file

@ -461,6 +461,7 @@
<wetness type="double" userarchive="n">0.0</wetness> <wetness type="double" userarchive="n">0.0</wetness>
<snow-thickness-factor type="double" userarchive="y">1.0</snow-thickness-factor> <snow-thickness-factor type="double" userarchive="y">1.0</snow-thickness-factor>
<delta-T-soil type="double" userarchive="n">0.0</delta-T-soil> <delta-T-soil type="double" userarchive="n">0.0</delta-T-soil>
<delta-T-vegetation type="double" userarchive="n">0.0</delta-T-vegetation>
<delta-T-rock type="double" userarchive="n">0.0</delta-T-rock> <delta-T-rock type="double" userarchive="n">0.0</delta-T-rock>
<delta-T-water type="double" userarchive="n">0.0</delta-T-water> <delta-T-water type="double" userarchive="n">0.0</delta-T-water>
<delta-T-cloud type="double" userarchive="n">0.0</delta-T-cloud> <delta-T-cloud type="double" userarchive="n">0.0</delta-T-cloud>

View file

@ -52,6 +52,7 @@ float rayleigh_in_func(in float dist, in float air_pollution, in float avisibili
vec3 searchlight(); vec3 searchlight();
vec3 landing_light(in float offset, in float offsetv); vec3 landing_light(in float offset, in float offsetv);
vec3 get_hazeColor(in float light_arg); vec3 get_hazeColor(in float light_arg);
vec3 filter_combined (in vec3 color) ;
float luminance(vec3 color) float luminance(vec3 color)
{ {
@ -378,15 +379,11 @@ hazeColor = intensity * normalize(mix(hazeColor, shadedFogColor, (1.0-smoothste
hazeColor = clamp(hazeColor,0.0,1.0); hazeColor = clamp(hazeColor,0.0,1.0);
fragColor.rgb = mix(eqColorFactor * hazeColor * eShade + secondary_light * fog_backscatter(avisibility), fragColor.rgb,transmission); fragColor.rgb = mix(eqColorFactor * hazeColor * eShade + secondary_light * fog_backscatter(avisibility), fragColor.rgb,transmission);
}
fragColor.rgb = filter_combined(fragColor.rgb);
gl_FragColor = fragColor; gl_FragColor = fragColor;
} }
else // if dist < 40.0 no fogging at all
{
gl_FragColor = fragColor;
}
//gl_FragColor.rgb = gl_SecondaryColor.rgb;
}

View file

@ -46,6 +46,8 @@ uniform float WindE;
uniform bool use_tree_shadows; uniform bool use_tree_shadows;
uniform bool use_forest_effect; uniform bool use_forest_effect;
uniform bool use_optimization;
uniform bool tree_patches;
uniform float osg_SimulationTime; uniform float osg_SimulationTime;
@ -92,9 +94,44 @@ void main()
vec3 lightFull = (gl_ModelViewMatrixInverse * gl_LightSource[0].position).xyz; vec3 lightFull = (gl_ModelViewMatrixInverse * gl_LightSource[0].position).xyz;
vec3 lightHorizon = normalize(vec3(lightFull.x,lightFull.y, 0.0)); vec3 lightHorizon = normalize(vec3(lightFull.x,lightFull.y, 0.0));
// this code is copied from tree.vert // eye position in model space
vec4 ep = gl_ModelViewMatrixInverse * vec4(0.0,0.0,0.0,1.0);
float rn_dist = length(gl_Color.xyz - ep.xyz) + 300.0 * mod(10.0 * gl_Color.x,1.0);
float rn = mod(100.0 * gl_Color.x + 100.0 * gl_Color.y,1.0);
float numVarieties = gl_Normal.z; float numVarieties = gl_Normal.z;
bool cull_flag = false;
float factor = 1.0;
float factor1 = 1.0;
if ((rn_dist > 2000.0) && (tree_patches == true) && (use_optimization == true))
{
if (rn > 0.15)
{cull_flag = true;}
else
{
numVarieties *=0.25;
factor = 5.2;
}
if (gl_FogCoord !=0.0) {cull_flag = true;}
}
if (cull_flag)
{
// move everything out of the view frustrum
gl_Position = vec4 (0.0,0.0,10.0,1.0);
gl_FrontColor.a = 0.0;
}
else
{
float texFract = floor(fract(gl_MultiTexCoord0.x) * numVarieties) / numVarieties; float texFract = floor(fract(gl_MultiTexCoord0.x) * numVarieties) / numVarieties;
// determine whether the tree changes color in autumn // determine whether the tree changes color in autumn
@ -127,7 +164,7 @@ void main()
vec3 position = gl_Vertex.xyz * gl_Normal.xxy; vec3 position = gl_Vertex.xyz * gl_Normal.xxy;
// Rotation of the generic quad to specific one for the tree. // Rotation of the generic quad to specific one for the tree.
position.xy = vec2(dot(position.xy, vec2(cr, sr)), dot(position.xy, vec2(-sr, cr))); position.xy = factor * vec2(dot(position.xy, vec2(cr, sr)), dot(position.xy, vec2(-sr, cr)));
// Shear by wind. Note that this only applies to the top vertices // Shear by wind. Note that this only applies to the top vertices
@ -192,10 +229,8 @@ void main()
// here start computations for the haze layer // here start computations for the haze layer
// we need several geometrical quantities // we need several geometrical quantities
// first current altitude of eye position in model space
vec4 ep = gl_ModelViewMatrixInverse * vec4(0.0,0.0,0.0,1.0);
// and relative position to vector
relPos = position - ep.xyz; relPos = position - ep.xyz;
// unfortunately, we need the distance in the vertex shader, although the more accurate version // unfortunately, we need the distance in the vertex shader, although the more accurate version
@ -317,13 +352,10 @@ if (cloud_shadow_flag == 1)
{light_ambient.rgb = light_ambient.rgb * (0.5 + 0.5 * shadow_func(relPos.x, relPos.y, 1.0, dist));} {light_ambient.rgb = light_ambient.rgb * (0.5 + 0.5 * shadow_func(relPos.x, relPos.y, 1.0, dist));}
//vec4 ambientColor = gl_FrontLightModelProduct.sceneColor +
//gl_FrontColor = ambientColor;
gl_FrontColor = light_ambient * gl_FrontMaterial.ambient; gl_FrontColor = light_ambient * gl_FrontMaterial.ambient;
gl_FrontColor.a = mie_angle; gl_BackColor.a = mie_angle; gl_FrontColor.a = mie_angle; gl_BackColor.a = mie_angle;
//gl_FrontSecondaryColor = vec4 (1.0,1.0,1.0,1.0) * 5.0*(1.0-dot(gl_SecondaryColor.rgb, vec3 (0.0,0.0,1.0))); }
//gl_BackSecondaryColor = vec4 (1.0,1.0,1.0,1.0) * 5.0 * (1.0-dot(gl_SecondaryColor.rgb, vec3 (0.0,0.0,1.0)));
} }

View file

@ -51,7 +51,7 @@ float rayleigh_in_func(in float dist, in float air_pollution, in float avisibili
vec3 searchlight(); vec3 searchlight();
vec3 landing_light(in float offset, in float offsetv); vec3 landing_light(in float offset, in float offsetv);
vec3 get_hazeColor(in float light_arg); vec3 get_hazeColor(in float light_arg);
vec3 filter_combined (in vec3 color) ;
@ -361,7 +361,8 @@ fragColor.rgb = mix( hazeColor + secondary_light * fog_backscatter(mvisibility)
} }
//if (autumn_flag > 0.0) {fragColor = vec4 (0.0,0.0,0.0,1.0);}
fragColor.rgb = filter_combined(fragColor.rgb);
gl_FragColor = fragColor; gl_FragColor = fragColor;
} }

View file

@ -177,6 +177,7 @@ Started September 2000 by David Megginson, david@megginson.com
<random-vegetation type="bool" userarchive="y">true</random-vegetation> <random-vegetation type="bool" userarchive="y">true</random-vegetation>
<random-vegetation-shadows type="bool" userarchive="y">false</random-vegetation-shadows> <random-vegetation-shadows type="bool" userarchive="y">false</random-vegetation-shadows>
<random-vegetation-normals type="bool" userarchive="y">false</random-vegetation-normals> <random-vegetation-normals type="bool" userarchive="y">false</random-vegetation-normals>
<random-vegetation-optimize type="bool" userarchive="y">false</random-vegetation-optimize>
<vegetation-density type="double" userarchive="y">1.0</vegetation-density> <vegetation-density type="double" userarchive="y">1.0</vegetation-density>
<random-buildings type="bool" userarchive="y">false</random-buildings> <random-buildings type="bool" userarchive="y">false</random-buildings>
<building-density type="double" userarchive="y">1.0</building-density> <building-density type="double" userarchive="y">1.0</building-density>