From 6ef32c6dac1c7ce76e5b03fdfa1854c388f6f4aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Garc=C3=ADa=20Li=C3=B1=C3=A1n?= Date: Mon, 30 Mar 2020 18:43:25 +0200 Subject: [PATCH 1/4] Compositor: Use depth partitioning in the low spec pipeline. --- Compositor/low-spec.xml | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/Compositor/low-spec.xml b/Compositor/low-spec.xml index a4bfe5be9..8a22a859b 100644 --- a/Compositor/low-spec.xml +++ b/Compositor/low-spec.xml @@ -1,9 +1,27 @@ + low-spec - - display + + far scene + 100.0 + + + near + scene + 0xfff7ff + + depth + 100.0 From f0ee8f23d26632dfcf49f0647c5894893ae1538c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Garc=C3=ADa=20Li=C3=B1=C3=A1n?= Date: Thu, 2 Apr 2020 21:32:05 +0200 Subject: [PATCH 2/4] Compositor: Use #version 140 for clustered shading This fixes compatibility issues with AMD graphics cards that support a OpenGL 3.1 compatibility profile. Integrated Intel GPUs using the Mesa drivers should set the environment variable: MESA_GL_VERSION_OVERRIDE="3.1COMPAT" --- Compositor/Shaders/ALS/clustered-include.frag | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Compositor/Shaders/ALS/clustered-include.frag b/Compositor/Shaders/ALS/clustered-include.frag index c5b3bbdaa..c94084bda 100644 --- a/Compositor/Shaders/ALS/clustered-include.frag +++ b/Compositor/Shaders/ALS/clustered-include.frag @@ -1,4 +1,4 @@ -#version 150 +#version 140 uniform usampler3D fg_ClusteredLightGrid; uniform usamplerBuffer fg_ClusteredLightIndices; From e1e0cf5997bb4b35a40818788f8bbf6422dd7a9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Garc=C3=ADa=20Li=C3=B1=C3=A1n?= Date: Sat, 4 Apr 2020 17:57:33 +0200 Subject: [PATCH 3/4] Compositor: Port remaining ALS Effects to use a logarithmic depth buffer --- Compositor/Effects/airfield.eff | 4 +- Compositor/Effects/grass.eff | 4 +- Compositor/Effects/model-default.eff | 2 +- Compositor/Effects/model-interior-display.eff | 2 +- Compositor/Effects/model-interior.eff | 2 +- Compositor/Effects/model-transparent.eff | 39 ++- Compositor/Effects/terrain-default.eff | 2 +- Compositor/Shaders/ALS/3dcloud-detailed.frag | 6 + Compositor/Shaders/ALS/3dcloud-detailed.vert | 6 +- Compositor/Shaders/ALS/3dcloud.frag | 6 + Compositor/Shaders/ALS/3dcloud.vert | 6 +- Compositor/Shaders/ALS/agriculture.frag | 1 + Compositor/Shaders/ALS/airfield.frag | 1 + Compositor/Shaders/ALS/birds.frag | 7 +- Compositor/Shaders/ALS/birds.vert | 4 + Compositor/Shaders/ALS/bowwave.frag | 7 +- Compositor/Shaders/ALS/chute.vert | 5 +- Compositor/Shaders/ALS/cliffs.frag | 1 + Compositor/Shaders/ALS/cloud-impostor.vert | 4 + Compositor/Shaders/ALS/cloud-noctilucent.vert | 4 + .../Shaders/ALS/cloud-static-detailed.frag | 6 + .../Shaders/ALS/cloud-static-detailed.vert | 4 + Compositor/Shaders/ALS/cloud-static.frag | 6 + Compositor/Shaders/ALS/cloud-static.vert | 4 + Compositor/Shaders/ALS/drunway.frag | 1 + Compositor/Shaders/ALS/flutter.vert | 3 + .../{terrain-base.vert => generic-base.vert} | 0 Compositor/Shaders/ALS/glass.frag | 7 +- Compositor/Shaders/ALS/glass.vert | 5 +- Compositor/Shaders/ALS/grass.frag | 7 +- Compositor/Shaders/ALS/grass.geom | 8 +- Compositor/Shaders/ALS/hud.frag | 7 +- Compositor/Shaders/ALS/hud.vert | 4 + Compositor/Shaders/ALS/light.frag | 7 +- Compositor/Shaders/ALS/light.vert | 3 + Compositor/Shaders/ALS/model-base.frag | 7 +- Compositor/Shaders/ALS/model-base.vert | 254 ------------------ .../Shaders/ALS/model-interior-base.frag | 6 +- .../Shaders/ALS/model-interior-detailed.frag | 7 +- .../Shaders/ALS/model-interior-detailed.vert | 6 +- .../Shaders/ALS/model-interior-display.frag | 7 +- Compositor/Shaders/ALS/model-transparent.frag | 51 ++++ Compositor/Shaders/ALS/model-transparent.vert | 65 +++++ Compositor/Shaders/ALS/model-ultra.frag | 6 + Compositor/Shaders/ALS/model-ultra.vert | 6 +- .../Shaders/ALS/model-wingflex-organic.vert | 4 + Compositor/Shaders/ALS/planet-aurora.vert | 4 + Compositor/Shaders/ALS/planet.vert | 4 + Compositor/Shaders/ALS/rain-layer.frag | 7 +- Compositor/Shaders/ALS/rain-layer.vert | 5 +- Compositor/Shaders/ALS/road-ultra.frag | 7 +- Compositor/Shaders/ALS/rock.frag | 1 + Compositor/Shaders/ALS/runway.frag | 1 + Compositor/Shaders/ALS/space-base.frag | 7 +- Compositor/Shaders/ALS/space-base.vert | 4 + Compositor/Shaders/ALS/space-ultra.frag | 7 +- Compositor/Shaders/ALS/space-ultra.vert | 4 + Compositor/Shaders/ALS/surface-light.frag | 7 +- Compositor/Shaders/ALS/surface-light.vert | 4 + Compositor/Shaders/ALS/terrain-base.frag | 1 + Compositor/Shaders/ALS/terrain-detailed.frag | 1 + Compositor/Shaders/ALS/terrain-overlay.frag | 7 +- Compositor/Shaders/ALS/terrain-overlay.geom | 4 + Compositor/Shaders/ALS/terrain-ultra.frag | 1 + .../Shaders/ALS/terrain-writedepth.frag | 12 + .../Shaders/ALS/terrain-writedepth.vert | 10 + Compositor/Shaders/ALS/thrustflame.frag | 6 + Compositor/Shaders/ALS/thrustflame.vert | 4 + Compositor/Shaders/ALS/wake.vert | 4 + Compositor/Shaders/ALS/water-base.frag | 1 + Compositor/Shaders/ALS/water-high.frag | 1 + 71 files changed, 403 insertions(+), 315 deletions(-) rename Compositor/Shaders/ALS/{terrain-base.vert => generic-base.vert} (100%) delete mode 100644 Compositor/Shaders/ALS/model-base.vert create mode 100644 Compositor/Shaders/ALS/model-transparent.frag create mode 100644 Compositor/Shaders/ALS/model-transparent.vert create mode 100644 Compositor/Shaders/ALS/terrain-writedepth.frag create mode 100644 Compositor/Shaders/ALS/terrain-writedepth.vert diff --git a/Compositor/Effects/airfield.eff b/Compositor/Effects/airfield.eff index 9094d5357..1ea18f283 100644 --- a/Compositor/Effects/airfield.eff +++ b/Compositor/Effects/airfield.eff @@ -91,8 +91,8 @@ RenderBin - Shaders/Default/trivial.vert - Shaders/Default/trivial.frag + Shaders/ALS/terrain-writedepth.vert + Shaders/ALS/terrain-writedepth.frag 0 0 0 0 diff --git a/Compositor/Effects/grass.eff b/Compositor/Effects/grass.eff index cdf137959..ba97f835d 100644 --- a/Compositor/Effects/grass.eff +++ b/Compositor/Effects/grass.eff @@ -94,8 +94,8 @@ RenderBin - Shaders/Default/trivial.vert - Shaders/Default/trivial.frag + Shaders/ALS/terrain-writedepth.vert + Shaders/ALS/terrain-writedepth.frag 0 0 0 0 diff --git a/Compositor/Effects/model-default.eff b/Compositor/Effects/model-default.eff index 6cb77c73f..72e1c2abc 100644 --- a/Compositor/Effects/model-default.eff +++ b/Compositor/Effects/model-default.eff @@ -473,7 +473,7 @@ vertex-program-two-side - Shaders/ALS/model-base.vert + Shaders/ALS/generic-base.vert Shaders/ALS/shadows-include.vert Shaders/ALS/model-base.frag Shaders/ALS/hazes.frag diff --git a/Compositor/Effects/model-interior-display.eff b/Compositor/Effects/model-interior-display.eff index f87b158b9..5c993b362 100644 --- a/Compositor/Effects/model-interior-display.eff +++ b/Compositor/Effects/model-interior-display.eff @@ -69,7 +69,7 @@ vertex-program-two-side - Shaders/ALS/model-base.vert + Shaders/ALS/generic-base.vert Shaders/ALS/model-interior-base.frag Shaders/ALS/hazes.frag Shaders/ALS/secondary_lights.frag diff --git a/Compositor/Effects/model-interior.eff b/Compositor/Effects/model-interior.eff index 57395eac8..225fc2e80 100644 --- a/Compositor/Effects/model-interior.eff +++ b/Compositor/Effects/model-interior.eff @@ -742,7 +742,7 @@ vertex-program-two-side - Shaders/ALS/model-base.vert + Shaders/ALS/generic-base.vert Shaders/ALS/model-interior-base.frag Shaders/ALS/hazes.frag Shaders/ALS/secondary_lights.frag diff --git a/Compositor/Effects/model-transparent.eff b/Compositor/Effects/model-transparent.eff index 560c1e9c0..21784e500 100644 --- a/Compositor/Effects/model-transparent.eff +++ b/Compositor/Effects/model-transparent.eff @@ -11,26 +11,6 @@ 1 - - - /environment/ground-visibility-m - - - /environment/visibility-m - - - /environment/ground-haze-thickness-m - - - /rendering/scene/scattering - - - /environment/terminator-relative-position-m - - - /sim/rendering/shaders/skydome - - @@ -192,6 +172,25 @@ modulate + + vertex-program-two-side + + + Shaders/ALS/model-transparent.vert + Shaders/ALS/model-transparent.frag + + + texture + sampler-2d + 0 + + + colorMode + int + + material/color-mode-uniform + + diff --git a/Compositor/Effects/terrain-default.eff b/Compositor/Effects/terrain-default.eff index 8ef3168bb..95b9db10b 100644 --- a/Compositor/Effects/terrain-default.eff +++ b/Compositor/Effects/terrain-default.eff @@ -2108,7 +2108,7 @@ - Shaders/ALS/terrain-base.vert + Shaders/ALS/generic-base.vert Shaders/ALS/shadows-include.vert Shaders/ALS/terrain-base.frag Shaders/ALS/hazes.frag diff --git a/Compositor/Shaders/ALS/3dcloud-detailed.frag b/Compositor/Shaders/ALS/3dcloud-detailed.frag index 61c627d7f..cd5acc42a 100644 --- a/Compositor/Shaders/ALS/3dcloud-detailed.frag +++ b/Compositor/Shaders/ALS/3dcloud-detailed.frag @@ -1,5 +1,7 @@ #version 120 +uniform float fg_Fcoef; + uniform sampler2D baseTexture; uniform float scattering; @@ -12,6 +14,8 @@ varying float bottom_shade; varying vec3 internal_pos; varying vec3 hazeColor; +varying float flogz; + vec3 filter_combined (in vec3 color) ; void main(void) @@ -81,4 +85,6 @@ void main(void) gl_FragColor.rgb = finalColor.rgb; gl_FragColor.a = mix(0.0, finalColor.a, 1.0 - 0.5 * (1.0 - fogFactor)); + // logarithmic depth + gl_FragDepth = log2(flogz) * fg_Fcoef * 0.5; } diff --git a/Compositor/Shaders/ALS/3dcloud-detailed.vert b/Compositor/Shaders/ALS/3dcloud-detailed.vert index fa9b69959..4bb01c4ad 100644 --- a/Compositor/Shaders/ALS/3dcloud-detailed.vert +++ b/Compositor/Shaders/ALS/3dcloud-detailed.vert @@ -1,8 +1,6 @@ // -*-C++-*- #version 120 -uniform float fg_Fcoef; - varying float fogFactor; varying vec3 hazeColor; varying float mie_frag; @@ -11,6 +9,8 @@ varying vec3 internal_pos; varying float bottom_shade; varying float z_pos; +varying float flogz; + uniform float range; // From /sim/rendering/clouds3d-vis-range uniform float detail_range; // From /sim/rendering/clouds3d_detail-range uniform float scattering; @@ -154,7 +154,7 @@ void main(void) vec3 relVector = gl_Position.xyz - ep.xyz; gl_Position = gl_ModelViewProjectionMatrix * gl_Position; // logarithmic depth - gl_Position.z = (log2(max(1e-6, 1.0 + gl_Position.w)) * fg_Fcoef - 1.0) * gl_Position.w; + flogz = 1.0 + gl_Position.w; // Light at the final position diff --git a/Compositor/Shaders/ALS/3dcloud.frag b/Compositor/Shaders/ALS/3dcloud.frag index c1076788a..ca3ff1e01 100644 --- a/Compositor/Shaders/ALS/3dcloud.frag +++ b/Compositor/Shaders/ALS/3dcloud.frag @@ -1,10 +1,14 @@ #version 120 +uniform float fg_Fcoef; + uniform sampler2D baseTexture; varying float fogFactor; varying vec3 hazeColor; +varying float flogz; + vec3 filter_combined (in vec3 color) ; void main(void) @@ -20,5 +24,7 @@ void main(void) gl_FragColor.rgb = finalColor.rgb; gl_FragColor.a = mix(0.0, finalColor.a, 1.0 - 0.5 * (1.0 - fogFactor)); + // logarithmic depth + gl_FragDepth = log2(flogz) * fg_Fcoef * 0.5; } diff --git a/Compositor/Shaders/ALS/3dcloud.vert b/Compositor/Shaders/ALS/3dcloud.vert index a56b4b7fb..1a7829f19 100644 --- a/Compositor/Shaders/ALS/3dcloud.vert +++ b/Compositor/Shaders/ALS/3dcloud.vert @@ -1,11 +1,11 @@ // -*-C++-*- #version 120 -uniform float fg_Fcoef; - varying float fogFactor; varying vec3 hazeColor; +varying float flogz; + uniform float range; // From /sim/rendering/clouds3d-vis-range uniform float detail_range; // From /sim/rendering/clouds3d_detail-range uniform float scattering; @@ -137,7 +137,7 @@ void main(void) vec3 relVector = gl_Position.xyz - ep.xyz; gl_Position = gl_ModelViewProjectionMatrix * gl_Position; // logarithmic depth - gl_Position.z = (log2(max(1e-6, 1.0 + gl_Position.w)) * fg_Fcoef - 1.0) * gl_Position.w; + flogz = 1.0 + gl_Position.w; // Light at the final position diff --git a/Compositor/Shaders/ALS/agriculture.frag b/Compositor/Shaders/ALS/agriculture.frag index 552dca805..f73a235e8 100644 --- a/Compositor/Shaders/ALS/agriculture.frag +++ b/Compositor/Shaders/ALS/agriculture.frag @@ -661,6 +661,7 @@ fragColor.rgb = mix(hazeColor + secondary_light * fog_backscatter(mvisibility), fragColor.rgb = filter_combined(fragColor.rgb); gl_FragColor = fragColor; +// logarithmic depth gl_FragDepth = log2(flogz) * fg_Fcoef * 0.5; } diff --git a/Compositor/Shaders/ALS/airfield.frag b/Compositor/Shaders/ALS/airfield.frag index b51dacc8d..168524b01 100644 --- a/Compositor/Shaders/ALS/airfield.frag +++ b/Compositor/Shaders/ALS/airfield.frag @@ -524,6 +524,7 @@ fragColor.rgb = mix(hazeColor+secondary_light * fog_backscatter(mvisibility), fr fragColor.rgb = filter_combined(fragColor.rgb); gl_FragColor = fragColor; +// logarithmic depth gl_FragDepth = log2(flogz) * fg_Fcoef * 0.5; } diff --git a/Compositor/Shaders/ALS/birds.frag b/Compositor/Shaders/ALS/birds.frag index e470cee7c..4e1154e28 100644 --- a/Compositor/Shaders/ALS/birds.frag +++ b/Compositor/Shaders/ALS/birds.frag @@ -1,6 +1,8 @@ // -*-C++-*- #version 120 +uniform float fg_Fcoef; + uniform sampler2D texture; uniform float color_base_r; @@ -25,6 +27,8 @@ varying vec3 vertex; varying vec3 relPos; varying vec3 normal; +varying float flogz; + const float terminator_width = 200000.0; float Noise2D(in vec2 coord, in float wavelength); @@ -202,6 +206,7 @@ birdTexel.a = domainTexel.a * shapeTexel.a * transmission; gl_FragColor = birdTexel; - +// logarithmic depth +gl_FragDepth = log2(flogz) * fg_Fcoef * 0.5; } diff --git a/Compositor/Shaders/ALS/birds.vert b/Compositor/Shaders/ALS/birds.vert index f5c764eba..e63c31ea5 100644 --- a/Compositor/Shaders/ALS/birds.vert +++ b/Compositor/Shaders/ALS/birds.vert @@ -9,6 +9,8 @@ varying vec3 vertex; varying vec3 relPos; varying vec3 normal; +varying float flogz; + uniform float osg_SimulationTime; void main() @@ -33,6 +35,8 @@ normal = gl_NormalMatrix * gl_Normal; gl_Position.xyz += gl_Vertex.z * w; gl_Position = gl_ModelViewProjectionMatrix * gl_Position; + // logarithmic depth + flogz = 1.0 + gl_Position.w; //vec4 offset = gl_ModelViewProjectionMatrix * vec4 (0.05* osg_SimulationTime, 0.0, 0.0, 1.0); diff --git a/Compositor/Shaders/ALS/bowwave.frag b/Compositor/Shaders/ALS/bowwave.frag index 47cc48361..97f2e8b4f 100644 --- a/Compositor/Shaders/ALS/bowwave.frag +++ b/Compositor/Shaders/ALS/bowwave.frag @@ -12,6 +12,8 @@ #version 120 #define fps2kts 0.5925 +uniform float fg_Fcoef; + uniform sampler2D water_normalmap; uniform sampler2D water_reflection; uniform sampler2D water_dudvmap; @@ -54,6 +56,8 @@ varying float yprime_alt; varying float mie_angle; varying float steepness; +varying float flogz; + vec3 specular_light; float fog_func (in float targ, in float alt); @@ -439,6 +443,7 @@ if (intensity > 0.0) // this needs to be a condition, because otherwise hazeColo finalColor.rgb = filter_combined(finalColor.rgb); gl_FragColor = vec4(finalColor.rgb, alpha0.a * 1.35); - + // logarithmic depth + gl_FragDepth = log2(flogz) * fg_Fcoef * 0.5; } diff --git a/Compositor/Shaders/ALS/chute.vert b/Compositor/Shaders/ALS/chute.vert index a46a3087e..84857f6f1 100644 --- a/Compositor/Shaders/ALS/chute.vert +++ b/Compositor/Shaders/ALS/chute.vert @@ -26,6 +26,8 @@ varying vec3 relPos; varying float yprime_alt; varying float mie_angle; +varying float flogz; + uniform int colorMode; uniform float hazeLayerAltitude; uniform float terminator; @@ -285,7 +287,8 @@ else // the faster, full-day version without lightfields gl_FrontColor.rgb = constant_term.rgb; gl_FrontColor.a = 1.0; gl_BackColor.rgb = constant_term.rgb; gl_BackColor.a = 0.0; gl_Position = gl_ModelViewProjectionMatrix * vertex; - + // logarithmic depth + flogz = 1.0 + gl_Position.w; } diff --git a/Compositor/Shaders/ALS/cliffs.frag b/Compositor/Shaders/ALS/cliffs.frag index f1a892648..977a68619 100644 --- a/Compositor/Shaders/ALS/cliffs.frag +++ b/Compositor/Shaders/ALS/cliffs.frag @@ -618,6 +618,7 @@ fragColor.rgb = mix(hazeColor + secondary_light * fog_backscatter(mvisibility), fragColor.rgb = filter_combined(fragColor.rgb); gl_FragColor = fragColor; +// logarithmic depth gl_FragDepth = log2(flogz) * fg_Fcoef * 0.5; } diff --git a/Compositor/Shaders/ALS/cloud-impostor.vert b/Compositor/Shaders/ALS/cloud-impostor.vert index 0fbfc2236..72ac337dc 100644 --- a/Compositor/Shaders/ALS/cloud-impostor.vert +++ b/Compositor/Shaders/ALS/cloud-impostor.vert @@ -4,6 +4,8 @@ varying float fogFactor; varying vec3 hazeColor; +varying float flogz; + uniform float terminator; uniform float altitude; uniform float cloud_self_shading; @@ -65,6 +67,8 @@ void main(void) vec3 relVector = gl_Position.xyz - ep.xyz; gl_Position = gl_ModelViewProjectionMatrix * gl_Position; + // logarithmic depth + flogz = 1.0 + gl_Position.w; // Light at the final position diff --git a/Compositor/Shaders/ALS/cloud-noctilucent.vert b/Compositor/Shaders/ALS/cloud-noctilucent.vert index 2b1f0617b..4441e69ba 100644 --- a/Compositor/Shaders/ALS/cloud-noctilucent.vert +++ b/Compositor/Shaders/ALS/cloud-noctilucent.vert @@ -4,6 +4,8 @@ varying float fogFactor; varying vec3 hazeColor; +varying float flogz; + uniform float terminator; uniform float altitude; uniform float cloud_self_shading; @@ -62,6 +64,8 @@ void main(void) vec3 relVector = gl_Position.xyz - ep.xyz; gl_Position = gl_ModelViewProjectionMatrix * gl_Position; + // logarithmic depth + flogz = 1.0 + gl_Position.w; // Light at the final position diff --git a/Compositor/Shaders/ALS/cloud-static-detailed.frag b/Compositor/Shaders/ALS/cloud-static-detailed.frag index d362694d5..f8c023822 100644 --- a/Compositor/Shaders/ALS/cloud-static-detailed.frag +++ b/Compositor/Shaders/ALS/cloud-static-detailed.frag @@ -1,6 +1,8 @@ // -*-C++-*- #version 120 +uniform float fg_Fcoef; + uniform sampler2D baseTexture; uniform float ring_factor; @@ -12,6 +14,8 @@ varying float eShade; varying vec3 hazeColor; +varying float flogz; + vec3 filter_combined (in vec3 color) ; void main(void) @@ -56,4 +60,6 @@ void main(void) fragColor.rgb = filter_combined(fragColor.rgb); //fragColor.rgb = vec3 (1.0, 0.0, 0.0); gl_FragColor = fragColor; + // logarithmic depth + gl_FragDepth = log2(flogz) * fg_Fcoef * 0.5; } diff --git a/Compositor/Shaders/ALS/cloud-static-detailed.vert b/Compositor/Shaders/ALS/cloud-static-detailed.vert index 2ea5d7c28..78693204d 100644 --- a/Compositor/Shaders/ALS/cloud-static-detailed.vert +++ b/Compositor/Shaders/ALS/cloud-static-detailed.vert @@ -6,6 +6,8 @@ varying float mie_frag; varying float eShade; varying vec3 hazeColor; +varying float flogz; + uniform float terminator; uniform float altitude; uniform float cloud_self_shading; @@ -61,6 +63,8 @@ void main(void) vec3 relVector = gl_Position.xyz - ep.xyz; gl_Position = gl_ModelViewProjectionMatrix * gl_Position; + // logarithmic depth + flogz = 1.0 + gl_Position.w; // Light at the final position diff --git a/Compositor/Shaders/ALS/cloud-static.frag b/Compositor/Shaders/ALS/cloud-static.frag index 0edbbbee2..23994cf72 100644 --- a/Compositor/Shaders/ALS/cloud-static.frag +++ b/Compositor/Shaders/ALS/cloud-static.frag @@ -1,10 +1,14 @@ #version 120 +uniform float fg_Fcoef; + uniform sampler2D baseTexture; varying float fogFactor; varying vec3 hazeColor; +varying float flogz; + vec3 filter_combined (in vec3 color) ; void main(void) @@ -17,4 +21,6 @@ void main(void) fragColor.rgb = filter_combined(fragColor.rgb); gl_FragColor = fragColor; + // logarithmic depth + gl_FragDepth = log2(flogz) * fg_Fcoef * 0.5; } diff --git a/Compositor/Shaders/ALS/cloud-static.vert b/Compositor/Shaders/ALS/cloud-static.vert index 150357fb5..453b7bbfd 100644 --- a/Compositor/Shaders/ALS/cloud-static.vert +++ b/Compositor/Shaders/ALS/cloud-static.vert @@ -4,6 +4,8 @@ varying float fogFactor; varying vec3 hazeColor; +varying float flogz; + uniform float terminator; uniform float altitude; uniform float cloud_self_shading; @@ -62,6 +64,8 @@ void main(void) vec3 relVector = gl_Position.xyz - ep.xyz; gl_Position = gl_ModelViewProjectionMatrix * gl_Position; + // logarithmic depth + flogz = 1.0 + gl_Position.w; // Light at the final position diff --git a/Compositor/Shaders/ALS/drunway.frag b/Compositor/Shaders/ALS/drunway.frag index 07ae0033f..f855cbe35 100644 --- a/Compositor/Shaders/ALS/drunway.frag +++ b/Compositor/Shaders/ALS/drunway.frag @@ -503,6 +503,7 @@ fragColor.rgb = mix(hazeColor +secondary_light * fog_backscatter(mvisibility) , fragColor.rgb = filter_combined(fragColor.rgb); gl_FragColor = fragColor; +// logarithmic depth gl_FragDepth = log2(flogz) * fg_Fcoef * 0.5; } diff --git a/Compositor/Shaders/ALS/flutter.vert b/Compositor/Shaders/ALS/flutter.vert index 500fcdcca..1708a9357 100644 --- a/Compositor/Shaders/ALS/flutter.vert +++ b/Compositor/Shaders/ALS/flutter.vert @@ -28,6 +28,7 @@ varying vec3 relPos; varying float yprime_alt; varying float mie_angle; +varying float flogz; uniform int colorMode; uniform float osg_SimulationTime; @@ -138,6 +139,8 @@ void main() rotationmatrix(-relWinddir, RotationMatrix); pos *= RotationMatrix; gl_Position = gl_ModelViewProjectionMatrix * pos; + // logarithmic depth + flogz = 1.0 + gl_Position.w; //do the colour and fog vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex; diff --git a/Compositor/Shaders/ALS/terrain-base.vert b/Compositor/Shaders/ALS/generic-base.vert similarity index 100% rename from Compositor/Shaders/ALS/terrain-base.vert rename to Compositor/Shaders/ALS/generic-base.vert diff --git a/Compositor/Shaders/ALS/glass.frag b/Compositor/Shaders/ALS/glass.frag index cf73cd629..1d8110896 100644 --- a/Compositor/Shaders/ALS/glass.frag +++ b/Compositor/Shaders/ALS/glass.frag @@ -11,6 +11,10 @@ varying float splash_angle; varying float Mie; varying float ambient_fraction; +varying float flogz; + +uniform float fg_Fcoef; + uniform sampler2D texture; uniform sampler2D frost_texture; uniform sampler2D func_texture; @@ -250,6 +254,7 @@ fragColor.a = max(outerColor.a, fog_texel.a); fragColor.rgb = filter_combined(fragColor.rgb); gl_FragColor = clamp(fragColor,0.0,1.0); - +// logarithmic depth +gl_FragDepth = log2(flogz) * fg_Fcoef * 0.5; } diff --git a/Compositor/Shaders/ALS/glass.vert b/Compositor/Shaders/ALS/glass.vert index 39ec90f57..886677eab 100644 --- a/Compositor/Shaders/ALS/glass.vert +++ b/Compositor/Shaders/ALS/glass.vert @@ -11,6 +11,8 @@ varying float splash_angle; varying float Mie; varying float ambient_fraction; +varying float flogz; + uniform float ground_scattering; uniform float hazeLayerAltitude; uniform float moonlight; @@ -126,7 +128,8 @@ ambient_fraction = length(light_ambient.rgb)/(length(light_diffuse.rgb +light_am gl_Position = ftransform(); -gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0; +// logarithmic depth +flogz = 1.0 + gl_Position.w; vec4 diffuse_color = gl_FrontMaterial.diffuse; vec4 ambient_color = gl_FrontMaterial.ambient; diff --git a/Compositor/Shaders/ALS/grass.frag b/Compositor/Shaders/ALS/grass.frag index ad22c1116..2767e7afb 100755 --- a/Compositor/Shaders/ALS/grass.frag +++ b/Compositor/Shaders/ALS/grass.frag @@ -2,9 +2,10 @@ #version 120 #define BLADE_FRACTION 0.1 -#define MAX_LAYERS 30 #define MAX_DISTANCE 1000.0 +uniform float fg_Fcoef; + uniform float visibility; uniform float scattering; uniform float overlay_bias; @@ -33,6 +34,8 @@ varying vec2 g_rawpos; // Horizontal position in model space varying float g_distance_to_eye; // Distance to the camera. Layers were disregarded varying float g_layer; // The layer where the fragment lives (0-1 range) +varying float flogz; + float rand2D(in vec2 co); float Noise2D(in vec2 co, in float wavelength); vec3 filter_combined (in vec3 color) ; @@ -172,4 +175,6 @@ void main() fragColor.rgb = filter_combined(fragColor.rgb); gl_FragColor = fragColor; + // logarithmic depth + gl_FragDepth = log2(flogz) * fg_Fcoef * 0.5; } diff --git a/Compositor/Shaders/ALS/grass.geom b/Compositor/Shaders/ALS/grass.geom index ba5f7531f..2384a0901 100755 --- a/Compositor/Shaders/ALS/grass.geom +++ b/Compositor/Shaders/ALS/grass.geom @@ -2,9 +2,9 @@ #version 120 #extension GL_EXT_geometry_shader4 : enable -#define MAX_LAYERS 30 +#define MAX_LAYERS 20 #define MIN_LAYERS 8 -#define MAX_MINUS_MIN_LAYERS 22 +#define MAX_MINUS_MIN_LAYERS 12 uniform float max_height; @@ -14,6 +14,8 @@ varying out vec2 g_rawpos; varying out float g_distance_to_eye; varying out float g_layer; +varying out float flogz; + uniform mat4 fg_LightMatrix_csm0; uniform mat4 fg_LightMatrix_csm1; @@ -60,6 +62,8 @@ void main() setupShadows(gl_ModelViewMatrix * pos); gl_Position = gl_ModelViewProjectionMatrix * pos; + // logarithmic depth + flogz = 1.0 + gl_Position.w; gl_TexCoord[0] = gl_TexCoordIn[i][0]; EmitVertex(); } diff --git a/Compositor/Shaders/ALS/hud.frag b/Compositor/Shaders/ALS/hud.frag index 9377be735..e3b856ddf 100644 --- a/Compositor/Shaders/ALS/hud.frag +++ b/Compositor/Shaders/ALS/hud.frag @@ -11,6 +11,10 @@ varying float splash_angle; varying float Mie; varying float ambient_fraction; +varying float flogz; + +uniform float fg_Fcoef; + uniform sampler2D texture; uniform sampler2D frost_texture; uniform sampler2D func_texture; @@ -284,6 +288,7 @@ fragColor.rgb = filter_combined(fragColor.rgb); gl_FragColor = clamp(fragColor,0.0,1.0); - +// logarithmic depth +gl_FragDepth = log2(flogz) * fg_Fcoef * 0.5; } diff --git a/Compositor/Shaders/ALS/hud.vert b/Compositor/Shaders/ALS/hud.vert index aa8a23527..6e41507a2 100644 --- a/Compositor/Shaders/ALS/hud.vert +++ b/Compositor/Shaders/ALS/hud.vert @@ -11,6 +11,8 @@ varying float splash_angle; varying float Mie; varying float ambient_fraction; +varying float flogz; + uniform float ground_scattering; uniform float hazeLayerAltitude; uniform float moonlight; @@ -126,6 +128,8 @@ ambient_fraction = length(light_ambient.rgb)/(length(light_diffuse.rgb +light_am gl_Position = ftransform(); +// logarithmic depth +flogz = 1.0 + gl_Position.w; gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0; vec4 diffuse_color = gl_FrontMaterial.diffuse; diff --git a/Compositor/Shaders/ALS/light.frag b/Compositor/Shaders/ALS/light.frag index 4b49c7585..d90b2f0bc 100644 --- a/Compositor/Shaders/ALS/light.frag +++ b/Compositor/Shaders/ALS/light.frag @@ -1,6 +1,8 @@ // -*-C++-*- #version 120 +uniform float fg_Fcoef; + uniform sampler2D texture; uniform float light_color_base_r; @@ -37,6 +39,8 @@ varying vec3 vertex; varying vec3 relPos; varying vec3 normal; +varying float flogz; + float Noise2D(in vec2 coord, in float wavelength); float fog_func (in float targ, in float alt); @@ -227,6 +231,7 @@ vec3 light_color = mix(light_color_base, light_color_center, intensity*intensity gl_FragColor = vec4 (light_color.rgb, intensity * transmission ); - +// logarithmic depth +gl_FragDepth = log2(flogz) * fg_Fcoef * 0.5; } diff --git a/Compositor/Shaders/ALS/light.vert b/Compositor/Shaders/ALS/light.vert index da585c7d7..f6c0710c0 100644 --- a/Compositor/Shaders/ALS/light.vert +++ b/Compositor/Shaders/ALS/light.vert @@ -16,6 +16,7 @@ varying vec3 vertex; varying vec3 relPos; varying vec3 normal; +varying float flogz; void main() @@ -39,6 +40,8 @@ normal = gl_NormalMatrix * gl_Normal; gl_Position.xyz += gl_Vertex.y * r; gl_Position.xyz += gl_Vertex.z * w; gl_Position = gl_ModelViewProjectionMatrix * gl_Position; + // logarithmic depth + flogz = 1.0 + gl_Position.w; //gl_Position = ftransform(); gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0; diff --git a/Compositor/Shaders/ALS/model-base.frag b/Compositor/Shaders/ALS/model-base.frag index 437b924fe..14a28e390 100644 --- a/Compositor/Shaders/ALS/model-base.frag +++ b/Compositor/Shaders/ALS/model-base.frag @@ -8,12 +8,16 @@ varying vec3 normal; varying vec3 relPos; varying vec4 ecPosition; +uniform float fg_Fcoef; + uniform sampler2D texture; varying float yprime_alt; varying float mie_angle; +varying float flogz; + uniform float visibility; uniform float avisibility; @@ -323,6 +327,7 @@ fragColor.rgb = addClusteredLightsContribution(fragColor.rgb, ecPosition.xyz, no fragColor.rgb = filter_combined(fragColor.rgb); gl_FragColor = fragColor; - +// logarithmic depth +gl_FragDepth = log2(flogz) * fg_Fcoef * 0.5; } diff --git a/Compositor/Shaders/ALS/model-base.vert b/Compositor/Shaders/ALS/model-base.vert deleted file mode 100644 index 963c4ca87..000000000 --- a/Compositor/Shaders/ALS/model-base.vert +++ /dev/null @@ -1,254 +0,0 @@ -// -*-C++-*- -#version 120 - -// Shader that uses OpenGL state values to do per-pixel lighting -// -// The only light used is gl_LightSource[0], which is assumed to be -// directional. -// -// Diffuse colors come from the gl_Color, ambient from the material. This is -// equivalent to osg::Material::DIFFUSE. -// Haze part added by Thorsten Renk, Oct. 2011 - - -#define MODE_OFF 0 -#define MODE_DIFFUSE 1 -#define MODE_AMBIENT_AND_DIFFUSE 2 - -uniform float fg_Fcoef; - -// The constant term of the lighting equation that doesn't depend on -// the surface normal is passed in gl_{Front,Back}Color. The alpha -// component is set to 1 for front, 0 for back in order to work around -// bugs with gl_FrontFacing in the fragment shader. -varying vec4 diffuse_term; -varying vec3 normal; -varying vec3 relPos; -varying vec4 ecPosition; - -varying float yprime_alt; -varying float mie_angle; - -uniform int colorMode; -uniform float hazeLayerAltitude; -uniform float terminator; -uniform float terrain_alt; -uniform float avisibility; -uniform float visibility; -uniform float overcast; -uniform float ground_scattering; -uniform float moonlight; - - -void setupShadows(vec4 eyeSpacePos); - -// This is the value used in the skydome scattering shader - use the same here for consistency? -const float EarthRadius = 5800000.0; -const float terminator_width = 200000.0; - - -float earthShade; - -float light_func (in float x, in float a, in float b, in float c, in float d, in float e) -{ -//x = x - 0.5; - -// use the asymptotics to shorten computations -if (x < -15.0) {return 0.0;} - -return e / pow((1.0 + a * exp(-b * (x-c)) ),(1.0/d)); -} - - -void main() -{ - - vec4 light_diffuse; - vec4 light_ambient; - vec3 shadedFogColor = vec3(0.55, 0.67, 0.88); - vec3 moonLightColor = vec3 (0.095, 0.095, 0.15) * moonlight; - - - //float yprime_alt; - float yprime; - float lightArg; - float intensity; - float vertex_alt; - float scattering; - -// this code is copied from default.vert - - ecPosition = gl_ModelViewMatrix * gl_Vertex; - gl_Position = ftransform(); - // logarithmic depth - gl_Position.z = (log2(max(1e-6, 1.0 + gl_Position.w)) * fg_Fcoef - 1.0) * gl_Position.w; - gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0; - normal = gl_NormalMatrix * gl_Normal; - vec4 ambient_color, diffuse_color; - if (colorMode == MODE_DIFFUSE) { - diffuse_color = gl_Color; - ambient_color = gl_FrontMaterial.ambient; - } else if (colorMode == MODE_AMBIENT_AND_DIFFUSE) { - diffuse_color = gl_Color; - ambient_color = gl_Color; - } else { - diffuse_color = gl_FrontMaterial.diffuse; - ambient_color = gl_FrontMaterial.ambient; - } - - - - // 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 = gl_Vertex.xyz - ep.xyz; - - // unfortunately, we need the distance in the vertex shader, although the more accurate version - // is later computed in the fragment shader again - float dist = length(relPos); - - // altitude of the vertex in question, somehow zero leads to artefacts, so ensure it is at least 100m - vertex_alt = max(gl_Vertex.z,100.0); - scattering = ground_scattering + (1.0 - ground_scattering) * smoothstep(hazeLayerAltitude -100.0, hazeLayerAltitude + 100.0, vertex_alt); - - - // branch dependent on daytime - -if (terminator < 1000000.0) // the full, sunrise and sunset computation -{ - - - // establish coordinates relative to sun position - - vec3 lightFull = (gl_ModelViewMatrixInverse * gl_LightSource[0].position).xyz; - vec3 lightHorizon = normalize(vec3(lightFull.x,lightFull.y, 0.0)); - - - - // yprime is the distance of the vertex into sun direction - yprime = -dot(relPos, lightHorizon); - - // this gets an altitude correction, higher terrain gets to see the sun earlier - yprime_alt = yprime - sqrt(2.0 * EarthRadius * vertex_alt); - - // two times terminator width governs how quickly light fades into shadow - // now the light-dimming factor - earthShade = 0.6 * (1.0 - smoothstep(-terminator_width+ terminator, terminator_width + terminator, yprime_alt)) + 0.4; - - // parametrized version of the Flightgear ground lighting function - lightArg = (terminator-yprime_alt)/100000.0; - - // directional scattering for low sun - if (lightArg < 10.0) - {mie_angle = (0.5 * dot(normalize(relPos), normalize(lightFull)) ) + 0.5;} - else - {mie_angle = 1.0;} - - - - - light_diffuse.b = light_func(lightArg, 1.330e-05, 0.264, 3.827, 1.08e-05, 1.0); - light_diffuse.g = light_func(lightArg, 3.931e-06, 0.264, 3.827, 7.93e-06, 1.0); - light_diffuse.r = light_func(lightArg, 8.305e-06, 0.161, 3.827, 3.04e-05, 1.0); - light_diffuse.a = 1.0; - light_diffuse = light_diffuse * scattering; - - - light_ambient.r = light_func(lightArg, 0.236, 0.253, 1.073, 0.572, 0.33); - light_ambient.g = light_ambient.r * 0.4/0.33; - light_ambient.b = light_ambient.r * 0.5/0.33; - light_ambient.a = 1.0; - - - - -// correct ambient light intensity and hue before sunrise -if (earthShade < 0.5) - { - //light_ambient = light_ambient * (0.7 + 0.3 * smoothstep(0.2, 0.5, earthShade)); - intensity = length(light_ambient.xyz); - - light_ambient.rgb = intensity * normalize(mix(light_ambient.rgb, shadedFogColor, 1.0 -smoothstep(0.4, 0.8,earthShade) )); - light_ambient.rgb = light_ambient.rgb + moonLightColor * (1.0 - smoothstep(0.4, 0.5, earthShade)); - - intensity = length(light_diffuse.xyz); - light_diffuse.rgb = intensity * normalize(mix(light_diffuse.rgb, shadedFogColor, 1.0 -smoothstep(0.4, 0.7,earthShade) )); - } - - -// the haze gets the light at the altitude of the haze top if the vertex in view is below -// but the light at the vertex if the vertex is above - -vertex_alt = max(vertex_alt,hazeLayerAltitude); - -if (vertex_alt > hazeLayerAltitude) - { - if (dist > 0.8 * avisibility) - { - vertex_alt = mix(vertex_alt, hazeLayerAltitude, smoothstep(0.8*avisibility, avisibility, dist)); - yprime_alt = yprime -sqrt(2.0 * EarthRadius * vertex_alt); - } - } -else - { - vertex_alt = hazeLayerAltitude; - yprime_alt = yprime -sqrt(2.0 * EarthRadius * vertex_alt); - } - -} -else // the faster, full-day version without lightfields -{ - //vertex_alt = max(gl_Vertex.z,100.0); - - earthShade = 1.0; - mie_angle = 1.0; - - if (terminator > 3000000.0) - {light_diffuse = vec4 (1.0, 1.0, 1.0, 0.0); - light_ambient = vec4 (0.33, 0.4, 0.5, 0.0); } - else - { - - lightArg = (terminator/100000.0 - 10.0)/20.0; - light_diffuse.b = 0.78 + lightArg * 0.21; - light_diffuse.g = 0.907 + lightArg * 0.091; - light_diffuse.r = 0.904 + lightArg * 0.092; - light_diffuse.a = 1.0; - - light_ambient.r = 0.316 + lightArg * 0.016; - light_ambient.g = light_ambient.r * 0.4/0.33; - light_ambient.b = light_ambient.r * 0.5/0.33; - light_ambient.a = 1.0; - } - - light_diffuse = light_diffuse * scattering; - yprime_alt = -sqrt(2.0 * EarthRadius * hazeLayerAltitude); -} - - -// default lighting based on texture and material using the light we have just computed - - diffuse_term = diffuse_color* light_diffuse; - vec4 constant_term = gl_FrontMaterial.emission + ambient_color * - (gl_LightModel.ambient + light_ambient); - // Super hack: if diffuse material alpha is less than 1, assume a - // transparency animation is at work - if (gl_FrontMaterial.diffuse.a < 1.0) - diffuse_term.a = gl_FrontMaterial.diffuse.a; - else - diffuse_term.a = gl_Color.a; - // Another hack for supporting two-sided lighting without using - // gl_FrontFacing in the fragment shader. - gl_FrontColor.rgb = constant_term.rgb; gl_FrontColor.a = 1.0; - gl_BackColor.rgb = constant_term.rgb; gl_BackColor.a = 0.0; - - setupShadows(gl_ModelViewMatrix * gl_Vertex); -} - - - - diff --git a/Compositor/Shaders/ALS/model-interior-base.frag b/Compositor/Shaders/ALS/model-interior-base.frag index 96d890aff..03052f1c0 100644 --- a/Compositor/Shaders/ALS/model-interior-base.frag +++ b/Compositor/Shaders/ALS/model-interior-base.frag @@ -7,6 +7,7 @@ varying vec4 diffuse_term; varying vec3 normal; varying vec3 relPos; +uniform float fg_Fcoef; uniform sampler2D texture; uniform samplerCube cube_texture; @@ -14,6 +15,8 @@ uniform samplerCube cube_texture; varying float yprime_alt; varying float mie_angle; +varying float flogz; + uniform float visibility; uniform float avisibility; @@ -179,6 +182,7 @@ void main() fragColor.rgb = filter_combined(fragColor.rgb); gl_FragColor = fragColor; - +// logarithmic depth +gl_FragDepth = log2(flogz) * fg_Fcoef * 0.5; } diff --git a/Compositor/Shaders/ALS/model-interior-detailed.frag b/Compositor/Shaders/ALS/model-interior-detailed.frag index 35075a47b..fda1d5bbf 100644 --- a/Compositor/Shaders/ALS/model-interior-detailed.frag +++ b/Compositor/Shaders/ALS/model-interior-detailed.frag @@ -9,6 +9,8 @@ varying vec3 relPos; varying vec3 rawpos; +uniform float fg_Fcoef; + uniform sampler2D texture; uniform sampler2D lightmap_texture; uniform sampler2D grain_texture; @@ -18,6 +20,8 @@ uniform samplerCube cube_texture; varying float yprime_alt; varying float mie_angle; +varying float flogz; + uniform float visibility; uniform float avisibility; @@ -237,7 +241,8 @@ void main() fragColor.rgb = filter_combined(fragColor.rgb); gl_FragColor = fragColor; - +// logarithmic depth +gl_FragDepth = log2(flogz) * fg_Fcoef * 0.5; } diff --git a/Compositor/Shaders/ALS/model-interior-detailed.vert b/Compositor/Shaders/ALS/model-interior-detailed.vert index e7ae64eb5..8b40fe0e7 100644 --- a/Compositor/Shaders/ALS/model-interior-detailed.vert +++ b/Compositor/Shaders/ALS/model-interior-detailed.vert @@ -15,8 +15,6 @@ #define MODE_DIFFUSE 1 #define MODE_AMBIENT_AND_DIFFUSE 2 -uniform float fg_Fcoef; - // The constant term of the lighting equation that doesn't depend on // the surface normal is passed in gl_{Front,Back}Color. The alpha // component is set to 1 for front, 0 for back in order to work around @@ -29,6 +27,8 @@ varying vec3 rawpos; varying float yprime_alt; varying float mie_angle; +varying float flogz; + uniform int colorMode; uniform int irradiance_map_type; uniform int ra_irradiance_map_type; @@ -88,7 +88,7 @@ void main() //vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex; gl_Position = ftransform(); // logarithmic depth - gl_Position.z = (log2(max(1e-6, 1.0 + gl_Position.w)) * fg_Fcoef - 1.0) * gl_Position.w; + flogz = 1.0 + gl_Position.w; gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0; normal = gl_NormalMatrix * gl_Normal; vec4 ambient_color, diffuse_color; diff --git a/Compositor/Shaders/ALS/model-interior-display.frag b/Compositor/Shaders/ALS/model-interior-display.frag index 4251f57de..3582ad5ca 100644 --- a/Compositor/Shaders/ALS/model-interior-display.frag +++ b/Compositor/Shaders/ALS/model-interior-display.frag @@ -8,6 +8,8 @@ varying vec3 normal; varying vec3 relPos; +uniform float fg_Fcoef; + uniform sampler2D texture; uniform sampler2D dust_texture; uniform sampler2D lightmap_texture; @@ -18,6 +20,8 @@ uniform samplerCube cube_texture; varying float yprime_alt; varying float mie_angle; +varying float flogz; + uniform float visibility; uniform float avisibility; @@ -356,7 +360,8 @@ void main() fragColor.rgb = filter_combined(fragColor.rgb); gl_FragColor = fragColor; - +// logarithmic depth +gl_FragDepth = log2(flogz) * fg_Fcoef * 0.5; } diff --git a/Compositor/Shaders/ALS/model-transparent.frag b/Compositor/Shaders/ALS/model-transparent.frag new file mode 100644 index 000000000..6aa49a409 --- /dev/null +++ b/Compositor/Shaders/ALS/model-transparent.frag @@ -0,0 +1,51 @@ +// -*-C++-*- + +// Ambient term comes in gl_Color.rgb. +#version 120 + +varying vec4 diffuse_term; +varying vec3 normal; + +varying float flogz; + +uniform float fg_Fcoef; + +uniform sampler2D texture; + +void main() +{ + vec3 n; + float NdotL, NdotHV; + vec4 color = gl_Color; + vec3 lightDir = gl_LightSource[0].position.xyz; + vec3 halfVector = gl_LightSource[0].halfVector.xyz; + vec4 texel; + vec4 fragColor; + vec4 specular = vec4(0.0); + + // If gl_Color.a == 0, this is a back-facing polygon and the + // normal should be reversed. + n = (2.0 * gl_Color.a - 1.0) * normal; + n = normalize(n); + + NdotL = dot(n, lightDir); + if (NdotL > 0.0) { + color += diffuse_term * NdotL; + NdotHV = max(dot(n, halfVector), 0.0); + if (gl_FrontMaterial.shininess > 0.0) + specular.rgb = (gl_FrontMaterial.specular.rgb + * gl_LightSource[0].specular.rgb + * pow(NdotHV, gl_FrontMaterial.shininess)); + } + color.a = diffuse_term.a; + // This shouldn't be necessary, but our lighting becomes very + // saturated. Clamping the color before modulating by the texture + // is closer to what the OpenGL fixed function pipeline does. + color = clamp(color, 0.0, 1.0); + texel = texture2D(texture, gl_TexCoord[0].st); + fragColor = color * texel + specular; + + gl_FragColor = fragColor; + // logarithmic depth + gl_FragDepth = log2(flogz) * fg_Fcoef * 0.5; +} diff --git a/Compositor/Shaders/ALS/model-transparent.vert b/Compositor/Shaders/ALS/model-transparent.vert new file mode 100644 index 000000000..fc69445af --- /dev/null +++ b/Compositor/Shaders/ALS/model-transparent.vert @@ -0,0 +1,65 @@ +// -*-C++-*- + +// Shader that uses OpenGL state values to do per-pixel lighting +// +// The only light used is gl_LightSource[0], which is assumed to be +// directional. +// +// Diffuse colors come from the gl_Color, ambient from the material. This is +// equivalent to osg::Material::DIFFUSE. +#version 120 +#define MODE_OFF 0 +#define MODE_DIFFUSE 1 +#define MODE_AMBIENT_AND_DIFFUSE 2 + +// The constant term of the lighting equation that doesn't depend on +// the surface normal is passed in gl_{Front,Back}Color. The alpha +// component is set to 1 for front, 0 for back in order to work around +// bugs with gl_FrontFacing in the fragment shader. +varying vec4 diffuse_term; +varying vec3 normal; + +varying float flogz; + +uniform int colorMode; + +////fog "include"//////// +//uniform int fogType; +// +//void fog_Func(int type); +///////////////////////// + +void main() +{ + gl_Position = ftransform(); + // logarithmic depth + flogz = 1.0 + gl_Position.w; + gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0; + normal = gl_NormalMatrix * gl_Normal; + vec4 ambient_color, diffuse_color; + if (colorMode == MODE_DIFFUSE) { + diffuse_color = gl_Color; + ambient_color = gl_FrontMaterial.ambient; + } else if (colorMode == MODE_AMBIENT_AND_DIFFUSE) { + diffuse_color = gl_Color; + ambient_color = gl_Color; + } else { + diffuse_color = gl_FrontMaterial.diffuse; + ambient_color = gl_FrontMaterial.ambient; + } + diffuse_term = diffuse_color * gl_LightSource[0].diffuse; + vec4 constant_term = gl_FrontMaterial.emission + ambient_color * + (gl_LightModel.ambient + gl_LightSource[0].ambient); + // Super hack: if diffuse material alpha is less than 1, assume a + // transparency animation is at work + if (gl_FrontMaterial.diffuse.a < 1.0) + diffuse_term.a = gl_FrontMaterial.diffuse.a; + else + diffuse_term.a = gl_Color.a; + // Another hack for supporting two-sided lighting without using + // gl_FrontFacing in the fragment shader. + gl_FrontColor.rgb = constant_term.rgb; gl_FrontColor.a = 1.0; + gl_BackColor.rgb = constant_term.rgb; gl_BackColor.a = 0.0; + //fogCoord = abs(ecPosition.z / ecPosition.w); + //fog_Func(fogType); +} diff --git a/Compositor/Shaders/ALS/model-ultra.frag b/Compositor/Shaders/ALS/model-ultra.frag index c60154d52..fc9915f07 100644 --- a/Compositor/Shaders/ALS/model-ultra.frag +++ b/Compositor/Shaders/ALS/model-ultra.frag @@ -17,6 +17,10 @@ varying vec3 vertVec; varying float alpha; +varying float flogz; + +uniform float fg_Fcoef; + uniform sampler2D BaseTex; uniform sampler2D LightMapTex; uniform sampler2D NormalTex; @@ -682,4 +686,6 @@ void main (void) fragColor.rgb = filter_combined(fragColor.rgb); gl_FragColor = fragColor; + // logarithmic depth + gl_FragDepth = log2(flogz) * fg_Fcoef * 0.5; } diff --git a/Compositor/Shaders/ALS/model-ultra.vert b/Compositor/Shaders/ALS/model-ultra.vert index fd313c77a..096522889 100644 --- a/Compositor/Shaders/ALS/model-ultra.vert +++ b/Compositor/Shaders/ALS/model-ultra.vert @@ -13,11 +13,11 @@ varying vec3 vertVec; varying float alpha; +varying float flogz; + attribute vec3 tangent; attribute vec3 binormal; -uniform float fg_Fcoef; - uniform float pitch; uniform float roll; uniform float hdg; @@ -116,7 +116,7 @@ void main(void) gl_Position = ftransform(); // logarithmic depth - gl_Position.z = (log2(max(1e-6, 1.0 + gl_Position.w)) * fg_Fcoef - 1.0) * gl_Position.w; + flogz = 1.0 + gl_Position.w; gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0; setupShadows(ecPosition); diff --git a/Compositor/Shaders/ALS/model-wingflex-organic.vert b/Compositor/Shaders/ALS/model-wingflex-organic.vert index db847ddef..b15d3d9a3 100644 --- a/Compositor/Shaders/ALS/model-wingflex-organic.vert +++ b/Compositor/Shaders/ALS/model-wingflex-organic.vert @@ -16,6 +16,8 @@ varying vec3 vertVec; varying float alpha; +varying float flogz; + attribute vec3 tangent; attribute vec3 binormal; @@ -163,6 +165,8 @@ void main(void) gl_FrontColor = gl_Color; } gl_Position = gl_ModelViewProjectionMatrix * vertex; + // logarithmic depth + flogz = 1.0 + gl_Position.w; //gl_Position = ftransform(); gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0; } diff --git a/Compositor/Shaders/ALS/planet-aurora.vert b/Compositor/Shaders/ALS/planet-aurora.vert index d976311fd..d9ef71973 100644 --- a/Compositor/Shaders/ALS/planet-aurora.vert +++ b/Compositor/Shaders/ALS/planet-aurora.vert @@ -4,6 +4,8 @@ varying vec3 vertex; varying vec3 normal; varying vec3 relVec; +uniform float fg_Fcoef; + uniform float osg_SimulationTime; uniform float arc_id; @@ -25,4 +27,6 @@ void main() gl_Position = gl_ModelViewProjectionMatrix * vert_out; + // logarithmic depth + gl_Position.z = (log2(max(1e-6, 1.0 + gl_Position.w)) * fg_Fcoef - 1.0) * gl_Position.w; } diff --git a/Compositor/Shaders/ALS/planet.vert b/Compositor/Shaders/ALS/planet.vert index 40befcbf7..4d07fdb34 100644 --- a/Compositor/Shaders/ALS/planet.vert +++ b/Compositor/Shaders/ALS/planet.vert @@ -21,6 +21,8 @@ varying vec3 normal; varying vec3 ecViewDir; varying vec3 VTangent; +uniform float fg_Fcoef; + uniform int colorMode; attribute vec3 tangent;//, binormal; @@ -34,6 +36,8 @@ void main() ecViewDir = (gl_ModelViewMatrix * (ep - gl_Vertex)).xyz; gl_Position = ftransform(); + // logarithmic depth + gl_Position.z = (log2(max(1e-6, 1.0 + gl_Position.w)) * fg_Fcoef - 1.0) * gl_Position.w; gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0; normal = gl_NormalMatrix * gl_Normal; VTangent = gl_NormalMatrix * tangent; diff --git a/Compositor/Shaders/ALS/rain-layer.frag b/Compositor/Shaders/ALS/rain-layer.frag index d4189db31..2f33354b8 100644 --- a/Compositor/Shaders/ALS/rain-layer.frag +++ b/Compositor/Shaders/ALS/rain-layer.frag @@ -1,10 +1,14 @@ #version 120 +uniform float fg_Fcoef; + uniform sampler2D baseTexture; varying float fogFactor; varying vec3 hazeColor; varying vec3 relVector; +varying float flogz; + vec3 filter_combined (in vec3 color) ; uniform bool is_lightning; @@ -62,5 +66,6 @@ void main(void) fragColor.rgb = filter_combined(fragColor.rgb); gl_FragColor = fragColor; - + // logarithmic depth + gl_FragDepth = log2(flogz) * fg_Fcoef * 0.5; } diff --git a/Compositor/Shaders/ALS/rain-layer.vert b/Compositor/Shaders/ALS/rain-layer.vert index 8b2fa2961..6d1ab5dc8 100644 --- a/Compositor/Shaders/ALS/rain-layer.vert +++ b/Compositor/Shaders/ALS/rain-layer.vert @@ -5,6 +5,8 @@ varying float fogFactor; varying vec3 hazeColor; varying vec3 relVector; +varying float flogz; + uniform float range; // From /sim/rendering/clouds3d-vis-range uniform float scattering; uniform float terminator; @@ -57,7 +59,8 @@ void main(void) relVector = gl_Position.xyz - ep.xyz; gl_Position = gl_ModelViewProjectionMatrix * gl_Position; - + // logarithmic depth + flogz = 1.0 + gl_Position.w; // Light at the final position diff --git a/Compositor/Shaders/ALS/road-ultra.frag b/Compositor/Shaders/ALS/road-ultra.frag index 615102498..c67d8490f 100644 --- a/Compositor/Shaders/ALS/road-ultra.frag +++ b/Compositor/Shaders/ALS/road-ultra.frag @@ -19,6 +19,10 @@ varying vec3 vertVec; varying float alpha; +varying float flogz; + +uniform float fg_Fcoef; + uniform sampler2D BaseTex; uniform sampler2D NormalTex; uniform sampler2D ReflMapTex; @@ -864,5 +868,6 @@ void main (void) fragColor.rgb = filter_combined(fragColor.rgb); gl_FragColor = fragColor; - + // logarithmic depth + gl_FragDepth = log2(flogz) * fg_Fcoef * 0.5; } diff --git a/Compositor/Shaders/ALS/rock.frag b/Compositor/Shaders/ALS/rock.frag index 026c97559..d8613cb84 100644 --- a/Compositor/Shaders/ALS/rock.frag +++ b/Compositor/Shaders/ALS/rock.frag @@ -677,6 +677,7 @@ fragColor.rgb = mix(hazeColor + secondary_light * fog_backscatter(mvisibility), fragColor.rgb = filter_combined(fragColor.rgb); gl_FragColor = fragColor; +// logarithmic depth gl_FragDepth = log2(flogz) * fg_Fcoef * 0.5; } diff --git a/Compositor/Shaders/ALS/runway.frag b/Compositor/Shaders/ALS/runway.frag index b6656ccb4..c91239e8b 100644 --- a/Compositor/Shaders/ALS/runway.frag +++ b/Compositor/Shaders/ALS/runway.frag @@ -530,6 +530,7 @@ fragColor.rgb = mix(hazeColor +secondary_light * fog_backscatter(mvisibility), f fragColor.rgb = filter_combined(fragColor.rgb); gl_FragColor = fragColor; +// logarithmic depth gl_FragDepth = log2(flogz) * fg_Fcoef * 0.5; } diff --git a/Compositor/Shaders/ALS/space-base.frag b/Compositor/Shaders/ALS/space-base.frag index c11df1f43..065c88285 100644 --- a/Compositor/Shaders/ALS/space-base.frag +++ b/Compositor/Shaders/ALS/space-base.frag @@ -8,12 +8,16 @@ varying vec3 normal; varying vec3 relPos; +uniform float fg_Fcoef; + uniform sampler2D texture; varying float yprime_alt; varying float mie_angle; +varying float flogz; + uniform float visibility; uniform float avisibility; @@ -355,6 +359,7 @@ fragColor.rgb = mix(hazeColor + secondary_light * fog_backscatter(mvisibility), gl_FragColor = fragColor; - +// logarithmic depth +gl_FragDepth = log2(flogz) * fg_Fcoef * 0.5; } diff --git a/Compositor/Shaders/ALS/space-base.vert b/Compositor/Shaders/ALS/space-base.vert index 3e72723ce..7351aca74 100644 --- a/Compositor/Shaders/ALS/space-base.vert +++ b/Compositor/Shaders/ALS/space-base.vert @@ -27,6 +27,8 @@ varying float yprime_alt; varying float mie_angle; varying float alt_factor; +varying float flogz; + uniform int colorMode; uniform float hazeLayerAltitude; uniform float terminator; @@ -77,6 +79,8 @@ void main() //vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex; gl_Position = ftransform(); + // logarithmic depth + flogz = 1.0 + gl_Position.w; gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0; normal = gl_NormalMatrix * gl_Normal; vec4 ambient_color, diffuse_color; diff --git a/Compositor/Shaders/ALS/space-ultra.frag b/Compositor/Shaders/ALS/space-ultra.frag index 34dcf708d..143f17f3d 100644 --- a/Compositor/Shaders/ALS/space-ultra.frag +++ b/Compositor/Shaders/ALS/space-ultra.frag @@ -17,6 +17,10 @@ varying vec3 vertVec; varying float alpha; +varying float flogz; + +uniform float fg_Fcoef; + uniform sampler2D BaseTex; uniform sampler2D LightMapTex; uniform sampler2D NormalTex; @@ -673,6 +677,7 @@ void main (void) gl_FragColor = fragColor; - + // logarithmic depth + gl_FragDepth = log2(flogz) * fg_Fcoef * 0.5; } diff --git a/Compositor/Shaders/ALS/space-ultra.vert b/Compositor/Shaders/ALS/space-ultra.vert index 5275593f3..eee877d09 100644 --- a/Compositor/Shaders/ALS/space-ultra.vert +++ b/Compositor/Shaders/ALS/space-ultra.vert @@ -13,6 +13,8 @@ varying vec3 vertVec; varying float alpha; +varying float flogz; + attribute vec3 tangent; attribute vec3 binormal; @@ -110,5 +112,7 @@ void main(void) gl_FrontColor = gl_Color; gl_Position = ftransform(); + // logarithmic depth + flogz = 1.0 + gl_Position.w; gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0; } diff --git a/Compositor/Shaders/ALS/surface-light.frag b/Compositor/Shaders/ALS/surface-light.frag index 9349a62da..812e23c70 100644 --- a/Compositor/Shaders/ALS/surface-light.frag +++ b/Compositor/Shaders/ALS/surface-light.frag @@ -1,6 +1,8 @@ // -*-C++-*- #version 120 +uniform float fg_Fcoef; + uniform sampler2D texture; uniform float visibility; @@ -17,6 +19,8 @@ varying vec3 relPos; varying vec2 rawPos; varying float pixelSize; +varying float flogz; + float alt; float Noise2D(in vec2 coord, in float wavelength); @@ -173,6 +177,7 @@ void main() light_color = mix(light_color, vec3 (1.0, 1.0, 1.0), 0.5 * intensity * intensity); gl_FragColor = vec4 (clamp(light_color.rgb,0.0,1.0), intensity * transmission * dist_att); - + // logarithmic depth + gl_FragDepth = log2(flogz) * fg_Fcoef * 0.5; } diff --git a/Compositor/Shaders/ALS/surface-light.vert b/Compositor/Shaders/ALS/surface-light.vert index d3a39d7b3..5172fc04a 100644 --- a/Compositor/Shaders/ALS/surface-light.vert +++ b/Compositor/Shaders/ALS/surface-light.vert @@ -13,12 +13,16 @@ varying vec3 relPos; varying vec2 rawPos; varying float pixelSize; +varying float flogz; + bool light_directional = true; void main() { gl_FrontColor= gl_Color; gl_Position = ftransform(); + // logarithmic depth + flogz = 1.0 + gl_Position.w; vec4 ep = gl_ModelViewMatrixInverse * vec4(0.0,0.0,0.0,1.0); relPos = gl_Vertex.xyz - ep.xyz; diff --git a/Compositor/Shaders/ALS/terrain-base.frag b/Compositor/Shaders/ALS/terrain-base.frag index cdfcd1e00..6e84cdd19 100644 --- a/Compositor/Shaders/ALS/terrain-base.frag +++ b/Compositor/Shaders/ALS/terrain-base.frag @@ -249,6 +249,7 @@ fragColor.rgb = mix(hazeColor, fragColor.rgb,transmission); fragColor.rgb = filter_combined(fragColor.rgb); gl_FragColor = fragColor; +// logarithmic depth gl_FragDepth = log2(flogz) * fg_Fcoef * 0.5; } diff --git a/Compositor/Shaders/ALS/terrain-detailed.frag b/Compositor/Shaders/ALS/terrain-detailed.frag index 4176531f8..3a057d23b 100644 --- a/Compositor/Shaders/ALS/terrain-detailed.frag +++ b/Compositor/Shaders/ALS/terrain-detailed.frag @@ -504,6 +504,7 @@ fragColor.rgb = mix(clamp(hazeColor,0.0,1.0) , clamp(fragColor.rgb,0.0,1.0),tran fragColor.rgb = filter_combined(fragColor.rgb); gl_FragColor = fragColor; +// logarithmic depth gl_FragDepth = log2(flogz) * fg_Fcoef * 0.5; } diff --git a/Compositor/Shaders/ALS/terrain-overlay.frag b/Compositor/Shaders/ALS/terrain-overlay.frag index 9a87f2002..ce546cd0c 100644 --- a/Compositor/Shaders/ALS/terrain-overlay.frag +++ b/Compositor/Shaders/ALS/terrain-overlay.frag @@ -1,9 +1,10 @@ // -*-C++-*- #version 120 -#define MAX_LAYERS 8 #define MAX_DISTANCE 3000.0 +uniform float fg_Fcoef; + uniform float visibility; uniform float avisibility; uniform float scattering; @@ -39,6 +40,8 @@ varying vec3 g_normal; varying float g_altitude; varying float g_layer; // The layer where the fragment lives (0-1 range) +varying float flogz; + float rand2D(in vec2 co); float Noise2D(in vec2 co, in float wavelength); @@ -168,4 +171,6 @@ void main() fragColor = clamp(fragColor, 0.0, 1.0); gl_FragColor = fragColor; + // logarithmic depth + gl_FragDepth = log2(flogz) * fg_Fcoef * 0.5; } diff --git a/Compositor/Shaders/ALS/terrain-overlay.geom b/Compositor/Shaders/ALS/terrain-overlay.geom index 2e412b74e..0e12357b4 100644 --- a/Compositor/Shaders/ALS/terrain-overlay.geom +++ b/Compositor/Shaders/ALS/terrain-overlay.geom @@ -16,6 +16,8 @@ varying out vec3 g_normal; varying out float g_altitude; varying out float g_layer; +varying out float flogz; + float min3(in float a, in float b, in float c) @@ -50,6 +52,8 @@ void main() g_altitude = gl_PositionIn[i].z; gl_Position = gl_ModelViewProjectionMatrix * pos; + // logarithmic depth + flogz = 1.0 + gl_Position.w; gl_TexCoord[0] = gl_TexCoordIn[i][0]; EmitVertex(); } diff --git a/Compositor/Shaders/ALS/terrain-ultra.frag b/Compositor/Shaders/ALS/terrain-ultra.frag index 136c2168b..b206f27fc 100644 --- a/Compositor/Shaders/ALS/terrain-ultra.frag +++ b/Compositor/Shaders/ALS/terrain-ultra.frag @@ -666,6 +666,7 @@ fragColor.rgb = mix(hazeColor+secondary_light * fog_backscatter(mvisibility) , f fragColor.rgb = filter_combined(fragColor.rgb); gl_FragColor = fragColor; +// logarithmic depth gl_FragDepth = log2(flogz) * fg_Fcoef * 0.5; } diff --git a/Compositor/Shaders/ALS/terrain-writedepth.frag b/Compositor/Shaders/ALS/terrain-writedepth.frag new file mode 100644 index 000000000..209a1afce --- /dev/null +++ b/Compositor/Shaders/ALS/terrain-writedepth.frag @@ -0,0 +1,12 @@ +#version 120 + +uniform float fg_Fcoef; + +varying float flogz; + +void main() +{ + gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0); + // logarithmic depth + gl_FragDepth = log2(flogz) * fg_Fcoef * 0.5; +} diff --git a/Compositor/Shaders/ALS/terrain-writedepth.vert b/Compositor/Shaders/ALS/terrain-writedepth.vert new file mode 100644 index 000000000..d213937b4 --- /dev/null +++ b/Compositor/Shaders/ALS/terrain-writedepth.vert @@ -0,0 +1,10 @@ +#version 120 + +varying float flogz; + +void main() +{ + gl_Position = ftransform(); + // logarithmic depth + flogz = 1.0 + gl_Position.w; +} diff --git a/Compositor/Shaders/ALS/thrustflame.frag b/Compositor/Shaders/ALS/thrustflame.frag index 9fedd6921..f22d87817 100644 --- a/Compositor/Shaders/ALS/thrustflame.frag +++ b/Compositor/Shaders/ALS/thrustflame.frag @@ -5,6 +5,10 @@ varying vec3 vertex; varying vec3 viewDir; +varying float flogz; + +uniform float fg_Fcoef; + uniform float osg_SimulationTime; uniform float thrust_collimation; uniform float flame_radius_fraction; @@ -139,4 +143,6 @@ color = mix(color, vec3(base_flame_r, base_flame_g, base_flame_b), density1); vec4 finalColor = vec4 (color.rgb, density); gl_FragColor = finalColor; +// logarithmic depth +gl_FragDepth = log2(flogz) * fg_Fcoef * 0.5; } diff --git a/Compositor/Shaders/ALS/thrustflame.vert b/Compositor/Shaders/ALS/thrustflame.vert index 0d2e38e4a..d40a75b09 100644 --- a/Compositor/Shaders/ALS/thrustflame.vert +++ b/Compositor/Shaders/ALS/thrustflame.vert @@ -5,6 +5,8 @@ varying vec3 vertex; varying vec3 viewDir; +varying float flogz; + void main() { @@ -14,6 +16,8 @@ vertex = gl_Vertex.xyz; viewDir = normalize(vertex - ep.xyz); gl_Position = ftransform(); +// logarithmic depth +flogz = 1.0 + gl_Position.w; gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0; gl_FrontColor = vec4 (1.0,1.0,1.0,1.0); diff --git a/Compositor/Shaders/ALS/wake.vert b/Compositor/Shaders/ALS/wake.vert index 974a6cb0f..dee6ee2a4 100644 --- a/Compositor/Shaders/ALS/wake.vert +++ b/Compositor/Shaders/ALS/wake.vert @@ -25,6 +25,8 @@ varying float earthShade; varying float yprime_alt; varying float mie_angle; +varying float flogz; + uniform float osg_SimulationTime; uniform float WindE, WindN, spd, hdg; uniform float hazeLayerAltitude; @@ -105,6 +107,8 @@ void main(void) gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0; gl_Position = ftransform(); + // logarithmic depth + flogz = 1.0 + gl_Position.w; // here start computations for the haze layer diff --git a/Compositor/Shaders/ALS/water-base.frag b/Compositor/Shaders/ALS/water-base.frag index 2dcb975b8..1c118ef0c 100644 --- a/Compositor/Shaders/ALS/water-base.frag +++ b/Compositor/Shaders/ALS/water-base.frag @@ -560,5 +560,6 @@ if (intensity > 0.0) // this needs to be a condition, because otherwise hazeColo finalColor.rgb = filter_combined(finalColor.rgb); gl_FragColor = finalColor; + // logarithmic depth gl_FragDepth = log2(flogz) * fg_Fcoef * 0.5; } diff --git a/Compositor/Shaders/ALS/water-high.frag b/Compositor/Shaders/ALS/water-high.frag index d7150d9c7..d850d7c96 100644 --- a/Compositor/Shaders/ALS/water-high.frag +++ b/Compositor/Shaders/ALS/water-high.frag @@ -742,6 +742,7 @@ finalColor.rgb = filter_combined(finalColor.rgb); gl_FragColor = finalColor; +// logarithmic depth gl_FragDepth = log2(flogz) * fg_Fcoef * 0.5; } From c0e2b243f68bc1323106db3f86f22255c4bd3112 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Garc=C3=ADa=20Li=C3=B1=C3=A1n?= Date: Sat, 4 Apr 2020 18:12:20 +0200 Subject: [PATCH 4/4] Compositor: Fix EarthView with ALS pipeline --- Compositor/Effects/model-combined.eff | 4 +- Compositor/Effects/planet-cloudlayer.eff | 159 +++---- Compositor/Effects/planet.eff | 578 ++++++++++++----------- Compositor/Effects/space-combined.eff | 2 + Compositor/Effects/space.eff | 3 +- 5 files changed, 376 insertions(+), 370 deletions(-) diff --git a/Compositor/Effects/model-combined.eff b/Compositor/Effects/model-combined.eff index aed99f782..5562e23b5 100644 --- a/Compositor/Effects/model-combined.eff +++ b/Compositor/Effects/model-combined.eff @@ -305,7 +305,7 @@ please see Docs/README.model-combined.eff for documentation 7 --> - + /sim/rendering/shaders/quality-level @@ -843,7 +843,7 @@ please see Docs/README.model-combined.eff for documentation - + als-lighting diff --git a/Compositor/Effects/planet-cloudlayer.eff b/Compositor/Effects/planet-cloudlayer.eff index 1f303c732..fc98be6db 100644 --- a/Compositor/Effects/planet-cloudlayer.eff +++ b/Compositor/Effects/planet-cloudlayer.eff @@ -86,7 +86,86 @@ 15 6 - + + + true + + + material/active + + + material/ambient + + + material/diffuse + + + material/specular + + + material/emissive + + + material/shininess + + + material/color-mode + + + + + blend/active + + + blend/source + + + blend/destination + + + + shade-model + + + cull-face + + + rendering-hint + + + + texture[0]/active + + 0 + + texture[0]/image + + + texture[0]/filter + + + texture[0]/wrap-s + + + texture[0]/wrap-t + + + + modulate + + + + + + + als-lighting @@ -360,82 +439,4 @@ - - - true - - - material/active - - - material/ambient - - - material/diffuse - - - material/specular - - - material/emissive - - - material/shininess - - - material/color-mode - - - - - blend/active - - - blend/source - - - blend/destination - - - - shade-model - - - cull-face - - - rendering-hint - - - - texture[0]/active - - 0 - - texture[0]/image - - - texture[0]/filter - - - texture[0]/wrap-s - - - texture[0]/wrap-t - - - - modulate - - - - - diff --git a/Compositor/Effects/planet.eff b/Compositor/Effects/planet.eff index 0dbf670a8..c983ce20b 100644 --- a/Compositor/Effects/planet.eff +++ b/Compositor/Effects/planet.eff @@ -90,293 +90,7 @@ 15 6 - - - - - 2.0 - - - - GL_ARB_shader_objects - GL_ARB_shading_language_100 - GL_ARB_vertex_shader - GL_ARB_fragment_shader - - - - - true - - - material/active - - - material/ambient - - - material/diffuse - - - material/specular - - - material/emissive - - - material/shininess - - - material/color-mode - - - - transparent - - - false - - - shade-model - - - cull-face - - - rendering-hint - - - 0 - - texture[0]/type - - - texture[0]/image - - - texture[0]/filter - - - texture[0]/wrap-s - - - texture[0]/wrap-t - - - - 1 - - texture[1]/image - - - texture[1]/type - - - texture[1]/filter - - - texture[1]/wrap-s - - - texture[1]/wrap-t - - - texture[1]/internal-format - - - - 2 - - texture[2]/image - - - texture[2]/type - - - texture[2]/filter - - - texture[2]/wrap-s - - - texture[2]/wrap-t - - - texture[2]/internal-format - - - - 3 - - texture[3]/image - - - texture[3]/type - - - texture[3]/filter - - - texture[3]/wrap-s - - - texture[3]/wrap-t - - - texture[3]/internal-format - - - - Shaders/ALS/planet.vert - Shaders/ALS/planet.frag - Shaders/ALS/noise.frag - Shaders/ALS/filters.frag - - tangent - 6 - - - normal - 15 - - - - texture - sampler-2d - 0 - - - shadowtex - sampler-2d - 1 - - - grain_texture - sampler-2d - 2 - - - colorMode - int - - material/color-mode-uniform - - - - visibility - float - - visibility - - - - air_pollution - float - - air_pollution - - - - sun_angle - float - - sun-angle - - - - use_clouds - bool - - use-clouds - - - - use_overlay - bool - - use-overlay-textures - - - - use_cloud_shadows - bool - - use-cloud-shadows - - - - gamma - float - - gamma - - - - brightness - float - - brightness - - - - use_filtering - bool - - use_filtering - - - - use_night_vision - bool - - use_night_vision - - - - use_IR_vision - bool - - use_IR_vision - - - - delta_T - float - - delta_T - - - - fact_grey - float - - fact_grey - - - - fact_black - float - - fact_black - - - - display_xsize - int - - display_xsize - - - - display_ysize - int - - display_ysize - - - - - + true @@ -454,7 +168,8 @@ --> - + + als-lighting @@ -755,4 +470,291 @@ + + als-lighting + + + + 2.0 + + + + GL_ARB_shader_objects + GL_ARB_shading_language_100 + GL_ARB_vertex_shader + GL_ARB_fragment_shader + + + + + true + + + material/active + + + material/ambient + + + material/diffuse + + + material/specular + + + material/emissive + + + material/shininess + + + material/color-mode + + + + transparent + + + false + + + shade-model + + + cull-face + + + rendering-hint + + + 0 + + texture[0]/type + + + texture[0]/image + + + texture[0]/filter + + + texture[0]/wrap-s + + + texture[0]/wrap-t + + + + 1 + + texture[1]/image + + + texture[1]/type + + + texture[1]/filter + + + texture[1]/wrap-s + + + texture[1]/wrap-t + + + texture[1]/internal-format + + + + 2 + + texture[2]/image + + + texture[2]/type + + + texture[2]/filter + + + texture[2]/wrap-s + + + texture[2]/wrap-t + + + texture[2]/internal-format + + + + 3 + + texture[3]/image + + + texture[3]/type + + + texture[3]/filter + + + texture[3]/wrap-s + + + texture[3]/wrap-t + + + texture[3]/internal-format + + + + Shaders/ALS/planet.vert + Shaders/ALS/planet.frag + Shaders/ALS/noise.frag + Shaders/ALS/filters.frag + + tangent + 6 + + + normal + 15 + + + + texture + sampler-2d + 0 + + + shadowtex + sampler-2d + 1 + + + grain_texture + sampler-2d + 2 + + + colorMode + int + + material/color-mode-uniform + + + + visibility + float + + visibility + + + + air_pollution + float + + air_pollution + + + + sun_angle + float + + sun-angle + + + + use_clouds + bool + + use-clouds + + + + use_overlay + bool + + use-overlay-textures + + + + use_cloud_shadows + bool + + use-cloud-shadows + + + + gamma + float + + gamma + + + + brightness + float + + brightness + + + + use_filtering + bool + + use_filtering + + + + use_night_vision + bool + + use_night_vision + + + + use_IR_vision + bool + + use_IR_vision + + + + delta_T + float + + delta_T + + + + fact_grey + float + + fact_grey + + + + fact_black + float + + fact_black + + + + display_xsize + int + + display_xsize + + + + display_ysize + int + + display_ysize + + + + diff --git a/Compositor/Effects/space-combined.eff b/Compositor/Effects/space-combined.eff index bd3058a2f..39a7cde81 100644 --- a/Compositor/Effects/space-combined.eff +++ b/Compositor/Effects/space-combined.eff @@ -15,6 +15,7 @@ 0 + als-lighting Shaders/ALS/space-ultra.vert @@ -951,6 +952,7 @@ + als-lighting Shaders/ALS/space-base.vert diff --git a/Compositor/Effects/space.eff b/Compositor/Effects/space.eff index 82bc863ae..14130c699 100644 --- a/Compositor/Effects/space.eff +++ b/Compositor/Effects/space.eff @@ -3,7 +3,8 @@ Effects/space Effects/model-default - + + als-lighting Shaders/ALS/space-base.vert