diff --git a/Effects/landmass.eff b/Effects/landmass.eff
index 3486081e8..cf2fd86a5 100644
--- a/Effects/landmass.eff
+++ b/Effects/landmass.eff
@@ -3,8 +3,19 @@
Effects/landmass
Effects/terrain-default
+
+ Textures.high/Terrain/forest-relief.png
+ linear-mipmap-linear
+ repeat
+ repeat
+ normalized
+
+
+ 6
+ 7
+
@@ -46,17 +57,35 @@
1
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+ 2
+
+
+
+
+
+
+
Shaders/landmass.vert
Shaders/landmass.frag
+
+ tangent
+ 6
+
+
+ binormal
+ 7
+
NoiseTex
@@ -68,11 +97,21 @@
sampler-2d
1
+
+ NormalTex
+ sampler-2d
+ 2
+
+
+ depth_factor
+ float
+ 0.01
+
snowlevel
float
-
+
diff --git a/Shaders/landmass.frag b/Shaders/landmass.frag
index 1e088d4b6..6ec32af84 100644
--- a/Shaders/landmass.frag
+++ b/Shaders/landmass.frag
@@ -3,18 +3,68 @@
varying vec4 rawpos;
varying vec4 ecPosition;
varying vec3 VNormal;
+varying vec3 VTangent;
+varying vec3 VBinormal;
varying vec3 Normal;
-varying vec4 constantColor;
+varying vec4 constantColor;
uniform sampler3D NoiseTex;
uniform sampler2D BaseTex;
-uniform float snowlevel;
+uniform sampler2D NormalTex;
+uniform float depth_factor;
+uniform float snowlevel; // From /sim/rendering/snow-level-m
-// From /sim/rendering/snow-level-m
const float scale = 1.0;
+float ray_intersect(sampler2D reliefMap, vec2 dp, vec2 ds)
+{
+ const int linear_search_steps = 20;
+
+ float size = 1.0 / float(linear_search_steps);
+ float depth = 0.0;
+ float best_depth = 1.0;
+
+ for(int i = 0; i < linear_search_steps - 1; ++i)
+ {
+ depth += size;
+ float t = texture2D(reliefMap, dp + ds * depth).a;
+ if(best_depth > 0.996)
+ if(depth >= t)
+ best_depth = depth;
+ }
+ depth = best_depth;
+
+ const int binary_search_steps = 5;
+
+ for(int i = 0; i < binary_search_steps; ++i)
+ {
+ size *= 0.5;
+ float t = texture2D(reliefMap, dp + ds * depth).a;
+ if(depth >= t)
+ {
+ best_depth = depth;
+ depth -= 2.0 * size;
+ }
+ depth += size;
+ }
+
+ return(best_depth);
+}
+
void main (void)
{
+ vec3 V = normalize(ecPosition.xyz);
+ float a = dot(VNormal, -V);
+ vec2 s = vec2(dot(V, VTangent), dot(V, VBinormal));
+ s *= depth_factor / a;
+ vec2 ds = s;
+ vec2 dp = gl_TexCoord[0].st;
+ float d = ray_intersect(NormalTex, dp, ds);
+
+ vec2 uv = dp + ds * d;
+ vec3 N = texture2D(NormalTex, uv).xyz * 2.0 - 1.0;
+
+
vec4 noisevec = texture3D(NoiseTex, (rawpos.xyz)*0.01*scale);
vec4 nvL = texture3D(NoiseTex, (rawpos.xyz)*0.00066*scale);
@@ -22,7 +72,6 @@ void main (void)
float fogCoord = ecPosition.z;
const float LOG2 = 1.442695;
fogFactor = exp2(-gl_Fog.density * gl_Fog.density * fogCoord * fogCoord * LOG2);
-// float biasFactor = exp2(-0.00000002 * fogCoord * fogCoord * LOG2);
float biasFactor = fogFactor = clamp(fogFactor, 0.0, 1.0);
float n=0.06;
@@ -37,7 +86,7 @@ void main (void)
n += noisevec[3]*2.1;
n = mix(0.6, n, biasFactor);
// good
- vec4 c1 = texture2D(BaseTex, gl_TexCoord[0].st);
+ vec4 c1 = texture2D(BaseTex, uv);
//brown
//c1 = mix(c1, vec4(n-0.46, n-0.45, n-0.53, 1.0), smoothstep(0.50, 0.55, nvL[2]*6.6));
//"steep = gray"
@@ -45,8 +94,22 @@ void main (void)
//"snow"
c1 = mix(c1, clamp(n+nvL[2]*4.1+vec4(0.1, 0.1, nvL[2]*2.2, 1.0), 0.7, 1.0), smoothstep(snowlevel+300.0, snowlevel+360.0, (rawpos.z)+nvL[1]*3000.0));
- vec3 diffuse = gl_Color.rgb * max(0.0, dot(normalize(VNormal), gl_LightSource[0].position.xyz));
- vec4 ambient_light = constantColor + gl_LightSource[0].diffuse * vec4(diffuse, 1.0);
+ N = normalize(N.x * VTangent + N.y * VBinormal + N.z * VNormal);
+ vec3 l = gl_LightSource[0].position.xyz;
+ vec3 diffuse = gl_Color.rgb * max(0.0, dot(N, l));
+
+// Shadow
+ dp += ds * d;
+ vec3 sl = normalize( vec3( dot( l, VTangent ), dot( l, VBinormal ), dot( -l, VNormal ) ) );
+ ds = sl.xy * depth_factor / sl.z;
+ dp -= ds * d;
+ float dl = ray_intersect(NormalTex, dp, ds);
+ float shadow_factor = 1.0;
+ if ( dl < d - 0.05 )
+ shadow_factor = dot( constantColor.xyz, vec3( 1.0, 1.0, 1.0 ) ) * 0.25;
+// end shadow
+
+ vec4 ambient_light = constantColor + gl_LightSource[0].diffuse * shadow_factor * vec4(diffuse, 1.0);
c1 *= ambient_light;
vec4 finalColor = c1;
diff --git a/Shaders/landmass.vert b/Shaders/landmass.vert
index 1076cdafc..0c717001e 100644
--- a/Shaders/landmass.vert
+++ b/Shaders/landmass.vert
@@ -1,19 +1,26 @@
varying vec4 rawpos;
varying vec4 ecPosition;
varying vec3 VNormal;
+varying vec3 VTangent;
+varying vec3 VBinormal;
varying vec3 Normal;
-varying vec4 constantColor;
+varying vec4 constantColor;
+
+attribute vec3 tangent;
+attribute vec3 binormal;
void main(void)
{
- rawpos = gl_Vertex;
- ecPosition = gl_ModelViewMatrix * gl_Vertex;
- VNormal = normalize(gl_NormalMatrix * gl_Normal);
- Normal = normalize(gl_Normal);
+ rawpos = gl_Vertex;
+ ecPosition = gl_ModelViewMatrix * rawpos;
+ Normal = normalize(gl_Normal);
+ VNormal = gl_NormalMatrix * gl_Normal;
+ VTangent = gl_NormalMatrix * tangent;
+ VBinormal = gl_NormalMatrix * binormal;
- gl_FrontColor = gl_Color;
- constantColor = gl_FrontMaterial.emission
- + gl_Color * (gl_LightModel.ambient + gl_LightSource[0].ambient);
- gl_Position = ftransform();
- gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
+ gl_FrontColor = gl_Color;
+ constantColor = gl_FrontMaterial.emission
+ + gl_FrontColor * (gl_LightModel.ambient + gl_LightSource[0].ambient);
+ gl_Position = ftransform();
+ gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
}