From 9afc9044827a35f3542c6186b8e24a55889d5a9d Mon Sep 17 00:00:00 2001 From: Thorsten Renk Date: Sat, 26 Mar 2016 09:02:51 +0200 Subject: [PATCH] Prepare ALS tree shader for filtering, add functionality for (optional) agressive optimization --- Effects/tree-forest.eff | 10 +++++ Effects/tree.eff | 84 ++++++++++++++++++++++++++++++++++++ Environment/environment.xml | 1 + Shaders/tree-ALS-shadow.frag | 13 +++--- Shaders/tree-ALS-shadow.vert | 50 +++++++++++++++++---- Shaders/tree-ALS.frag | 5 ++- preferences.xml | 1 + 7 files changed, 145 insertions(+), 19 deletions(-) create mode 100644 Effects/tree-forest.eff diff --git a/Effects/tree-forest.eff b/Effects/tree-forest.eff new file mode 100644 index 000000000..fa5e6f996 --- /dev/null +++ b/Effects/tree-forest.eff @@ -0,0 +1,10 @@ + + + Effects/tree-forest + Effects/tree + + true + true + true + + diff --git a/Effects/tree.eff b/Effects/tree.eff index 631e72681..0996666a2 100644 --- a/Effects/tree.eff +++ b/Effects/tree.eff @@ -57,6 +57,14 @@ /sim/rendering/als-secondary-lights/landing-light1-offset-deg /sim/rendering/als-secondary-lights/landing-light2-offset-deg /sim/rendering/als-secondary-lights/landing-light3-offset-deg + /sim/rendering/als-filters/use-filtering + /sim/rendering/als-filters/gamma + /sim/rendering/als-filters/brightness + /sim/rendering/als-filters/use-night-vision + /sim/rendering/als-filters/use-IR-vision + /environment/surface/delta-T-vegetation + /sim/rendering/random-vegetation-optimize + false /local-weather/cloud-shadows/cloudpos-x[0] /local-weather/cloud-shadows/cloudpos-y[0] /local-weather/cloud-shadows/cloudpos-x[1] @@ -149,6 +157,7 @@ Shaders/tree-ALS-shadow.frag Shaders/secondary_lights.frag Shaders/hazes.frag + Shaders/filters-ALS.frag visibility @@ -265,6 +274,38 @@ float landing_light3_offset + + + gamma + float + gamma + + + brightness + float + brightness + + + use_night_vision + bool + use_night_vision + + + use_IR_vision + bool + use_IR_vision + + + use_filtering + bool + use_filtering + + + delta_T + float + delta_T + + cloudpos1_x float @@ -510,6 +551,16 @@ bool use_tree_shadows + + use_optimization + bool + use_optimization + + + tree_patches + bool + tree_patches + forest_effect_size float @@ -595,6 +646,7 @@ Shaders/tree-ALS.frag Shaders/secondary_lights.frag Shaders/hazes.frag + Shaders/filters-ALS.frag visibility @@ -711,6 +763,38 @@ float landing_light3_offset + + + gamma + float + gamma + + + brightness + float + brightness + + + use_night_vision + bool + use_night_vision + + + use_IR_vision + bool + use_IR_vision + + + use_filtering + bool + use_filtering + + + delta_T + float + delta_T + + cloudpos1_x float diff --git a/Environment/environment.xml b/Environment/environment.xml index 161544e63..0fc20349e 100644 --- a/Environment/environment.xml +++ b/Environment/environment.xml @@ -461,6 +461,7 @@ 0.0 1.0 0.0 + 0.0 0.0 0.0 0.0 diff --git a/Shaders/tree-ALS-shadow.frag b/Shaders/tree-ALS-shadow.frag index 5975379f0..65a1dad26 100644 --- a/Shaders/tree-ALS-shadow.frag +++ b/Shaders/tree-ALS-shadow.frag @@ -52,6 +52,7 @@ float rayleigh_in_func(in float dist, in float air_pollution, in float avisibili vec3 searchlight(); vec3 landing_light(in float offset, in float offsetv); vec3 get_hazeColor(in float light_arg); +vec3 filter_combined (in 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); fragColor.rgb = mix(eqColorFactor * hazeColor * eShade + secondary_light * fog_backscatter(avisibility), fragColor.rgb,transmission); +} + +fragColor.rgb = filter_combined(fragColor.rgb); + gl_FragColor = fragColor; } -else // if dist < 40.0 no fogging at all -{ - -gl_FragColor = fragColor; -} - -//gl_FragColor.rgb = gl_SecondaryColor.rgb; -} diff --git a/Shaders/tree-ALS-shadow.vert b/Shaders/tree-ALS-shadow.vert index d8b5307e6..21808f843 100644 --- a/Shaders/tree-ALS-shadow.vert +++ b/Shaders/tree-ALS-shadow.vert @@ -46,6 +46,8 @@ uniform float WindE; uniform bool use_tree_shadows; uniform bool use_forest_effect; +uniform bool use_optimization; +uniform bool tree_patches; uniform float osg_SimulationTime; @@ -92,9 +94,44 @@ void main() vec3 lightFull = (gl_ModelViewMatrixInverse * gl_LightSource[0].position).xyz; 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; + + 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; // determine whether the tree changes color in autumn @@ -127,7 +164,7 @@ void main() vec3 position = gl_Vertex.xyz * gl_Normal.xxy; // 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 @@ -192,10 +229,8 @@ void main() // here start computations for the haze layer // 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; // 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));} - //vec4 ambientColor = gl_FrontLightModelProduct.sceneColor + - //gl_FrontColor = ambientColor; gl_FrontColor = light_ambient * gl_FrontMaterial.ambient; 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))); + } } diff --git a/Shaders/tree-ALS.frag b/Shaders/tree-ALS.frag index 5f713c3a4..219889b9a 100644 --- a/Shaders/tree-ALS.frag +++ b/Shaders/tree-ALS.frag @@ -51,7 +51,7 @@ float rayleigh_in_func(in float dist, in float air_pollution, in float avisibili vec3 searchlight(); vec3 landing_light(in float offset, in float offsetv); 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; } diff --git a/preferences.xml b/preferences.xml index 1dbbfaa34..6ca17a016 100644 --- a/preferences.xml +++ b/preferences.xml @@ -177,6 +177,7 @@ Started September 2000 by David Megginson, david@megginson.com true false false + false 1.0 false 1.0