diff --git a/Effects/transition.eff b/Effects/transition.eff
index bf54a358f..382258afc 100644
--- a/Effects/transition.eff
+++ b/Effects/transition.eff
@@ -89,6 +89,306 @@ parameters :
6
7
-->
+
+
+
+ /sim/rendering/shaders/transition
+ /sim/rendering/rembrandt/enabled
+
+ 4.0
+ /sim/rendering/shaders/water
+
+
+
+ 2.0
+
+
+
+ GL_ARB_shader_objects
+ GL_ARB_shading_language_100
+ GL_ARB_vertex_shader
+ GL_ARB_fragment_shader
+
+
+ GL_EXT_gpu_shader4
+
+
+
+
+ true
+
+
+
+
+
+
+
+
+
+
+
+ ambient-and-diffuse
+
+
+
+
+
+
+
+
+
+
+ smooth
+ back
+
+
+
+
+
+
+
+
+
+
+
+ 0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 3
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 4
+ noise
+
+
+
+
+ Shaders/transition-gbuffer.vert
+ Shaders/transition-gbuffer.frag
+ Shaders/gbuffer-functions.frag
+ Shaders/gbuffer-encode.frag
+
+
+
+ BaseTex
+ sampler-2d
+ 0
+
+
+
+ SecondTex
+ sampler-2d
+ 1
+
+
+
+ ThirdTex
+ sampler-2d
+ 2
+
+
+
+ SnowTex
+ sampler-2d
+ 3
+
+
+
+ NoiseTex
+ sampler-3d
+ 4
+
+
+
+ RainNorm
+ float
+
+
+
+
+
+
+ SnowLevel
+ float
+
+
+
+
+
+
+ Transitions
+ float
+
+
+
+
+
+
+ InverseSlope
+ float
+
+
+
+
+
+
+ CloudCover0
+ float
+
+
+
+
+
+
+ CloudCover1
+ float
+
+
+
+
+
+
+ CloudCover2
+ float
+
+
+
+
+
+
+ CloudCover3
+ float
+
+
+
+
+
+
+ CloudCover4
+ float
+
+
+
+
+
+
+
+ visibility
+ float
+
+
+
+
+
+ avisibility
+ float
+
+
+
+
+
+ hazeLayerAltitude
+ float
+
+
+
+
+
+ scattering
+ float
+
+
+
+
+
+ terminator
+ float
+
+
+
+
+
+ fogType
+ int
+
+
+
+
+
+
+
diff --git a/Shaders/transition-gbuffer.frag b/Shaders/transition-gbuffer.frag
new file mode 100644
index 000000000..be2ecd8f4
--- /dev/null
+++ b/Shaders/transition-gbuffer.frag
@@ -0,0 +1,160 @@
+// -*-C++-*-
+// Texture switching based on face slope and snow level
+// based on earlier work by Frederic Bouvier, Tim Moore, and Yves Sablonier.
+// � Emilian Huminiuc 2011
+
+
+varying vec4 RawPos;
+varying vec3 normal;
+varying vec3 Vnormal;
+
+uniform float SnowLevel;
+uniform float Transitions;
+uniform float InverseSlope;
+uniform float RainNorm;
+
+uniform float CloudCover0;
+uniform float CloudCover1;
+uniform float CloudCover2;
+uniform float CloudCover3;
+uniform float CloudCover4;
+
+uniform sampler2D BaseTex;
+uniform sampler2D SecondTex;
+uniform sampler2D ThirdTex;
+uniform sampler2D SnowTex;
+
+uniform sampler3D NoiseTex;
+
+// gbuffer function
+void encode_gbuffer(vec3 normal, vec3 color, int mId, float specular, float shininess, float emission, float depth);
+///////////////////
+
+void main()
+ {
+ float MixFactor;
+ float NdotL;
+ float NdotHV;
+ float fogFactor;
+ float cover;
+ float slope;
+ float L1;
+ float L2;
+ float wetness;
+ float pf;
+
+ vec3 n;
+ vec3 lightDir;
+ vec3 halfVector;
+
+ vec4 texel;
+ vec4 fragColor;
+ vec4 color;
+ vec4 Noise;
+
+ cover = min(min(min(min(CloudCover0, CloudCover1),CloudCover2),CloudCover3),CloudCover4);
+
+ Noise = texture3D(NoiseTex, RawPos.xyz*0.0011);
+ MixFactor = Noise.r * Noise.g * Noise.b; //Mixing Factor to create a more organic looking boundary
+ MixFactor *= 300.0;
+ MixFactor = clamp(MixFactor, 0.0, 1.0);
+ L1 = 0.90 - 0.02 * MixFactor; //first transition slope
+ L2 = 0.78 + 0.04 * MixFactor; //Second transition slope
+
+ // If gl_Color.a == 0, this is a back-facing polygon and the
+ // Vnormal should be reversed.
+ n = (2.0 * gl_Color.a - 1.0) * Vnormal;
+ n = normalize(n);
+
+ color = vec4(1.0);
+
+ //Select texture based on slope
+ slope = normalize(normal).z;
+
+ //pull the texture fetch outside flow control to fix aliasing artefacts :(
+ vec4 baseTexel = texture2D(BaseTex, gl_TexCoord[0].st);
+ vec4 secondTexel = texture2D(SecondTex, gl_TexCoord[0].st);
+ vec4 thirdTexel = texture2D(ThirdTex, gl_TexCoord[0].st);
+ vec4 snowTexel = texture2D(SnowTex, gl_TexCoord[0].st);
+
+ //Normal transition. For more abrupt faces apply another texture (or 2).
+ if (InverseSlope == 0.0) {
+ //Do we do an intermediate transition
+ if (Transitions >= 1.5) {
+ if (slope >= L1) {
+ texel = baseTexel;
+ }
+ if (slope >= L2 && slope < L1){
+ texel = mix(secondTexel, baseTexel, smoothstep(L2, L1 - 0.06 * MixFactor, slope));
+ }
+ if (slope < L2){
+ texel = mix(thirdTexel, secondTexel, smoothstep(L2 - 0.13 * MixFactor, L2, slope));
+ }
+ // Just one transition
+ } else if (Transitions < 1.5) {
+ if (slope >= L1) {
+ texel = baseTexel;
+ }
+ if (slope < L1) {
+ texel = mix(thirdTexel, baseTexel, smoothstep(L2 - 0.13 * MixFactor, L1, slope));
+ }
+ }
+
+ //Invert the transition: keep original texture on abrupt slopes and switch to another on flatter terrain
+ } else if (InverseSlope > 0.0) {
+ //Interemdiate transition ?
+ if (Transitions >= 1.5) {
+ if (slope >= L1 + 0.1) {
+ texel = thirdTexel;
+ }
+ if (slope >= L2 && slope < L1 + 0.1){
+ texel = mix(secondTexel, thirdTexel, smoothstep(L2 + 0.06 * MixFactor, L1 + 0.1, slope));
+ }
+ if (slope <= L2){
+ texel = mix(baseTexel, secondTexel, smoothstep(L2 - 0.06 * MixFactor, L2, slope));
+ }
+ //just one
+ } else if (Transitions < 1.5) {
+ if (slope > L1 + 0.1) {
+ texel = thirdTexel;
+ }
+ if (slope <= L1 + 0.1){
+ texel = mix(baseTexel, thirdTexel, smoothstep(L2 - 0.06 * MixFactor, L1 + 0.1, slope));
+ }
+ }
+ }
+
+ //darken textures with wetness
+ wetness = 1.0 - 0.3 * RainNorm;
+ texel.rgb = texel.rgb * wetness;
+
+ float altitude = RawPos.z;
+ //Snow texture for areas higher than SnowLevel
+ if (altitude >= SnowLevel - (1000.0 * slope + 300.0 * MixFactor) && slope > L2 - 0.12) {
+ texel = mix( texel,
+ mix( texel, snowTexel, smoothstep(L2 - 0.09 * MixFactor, L2, slope) ),
+ smoothstep(SnowLevel - (1000.0 * slope + 300.0 * MixFactor),
+ SnowLevel - (1000.0 * slope - 150.0 * MixFactor),
+ altitude)
+ );
+ }
+
+ fragColor = color * texel;
+
+ if(cover >= 2.5){
+ fragColor.rgb = fragColor.rgb * 1.2;
+ } else {
+ fragColor.rg = fragColor.rg * (0.6 + 0.2 * cover);
+ fragColor.b = fragColor.b * (0.5 + 0.25 * cover);
+ }
+
+
+ fragColor.rgb *= 1.2 - 0.4 * MixFactor;
+
+ float specular = dot( gl_FrontMaterial.specular.rgb, vec3( 0.3, 0.59, 0.11 ) );
+ float emission = dot( gl_FrontLightModelProduct.sceneColor.rgb + gl_FrontMaterial.emission.rgb,
+ vec3( 0.3, 0.59, 0.11 )
+ );
+
+ encode_gbuffer( n, fragColor.rgb, 1, specular, gl_FrontMaterial.shininess, emission, gl_FragCoord.z );
+ }
diff --git a/Shaders/transition-gbuffer.vert b/Shaders/transition-gbuffer.vert
new file mode 100644
index 000000000..b63c0f2ee
--- /dev/null
+++ b/Shaders/transition-gbuffer.vert
@@ -0,0 +1,17 @@
+// -*- mode: C; -*-
+// Licence: GPL v2
+// Authors: Frederic Bouvier, Emilian Huminiuc
+//
+
+varying vec4 RawPos;
+
+varying vec3 normal;
+varying vec3 Vnormal;
+
+void main() {
+ RawPos = gl_Vertex;
+ gl_Position = ftransform();
+ gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
+ normal = normalize(gl_Normal);
+ Vnormal = gl_NormalMatrix * gl_Normal;
+}