From 64f351935b50e1d329445dc34c12902162c10de6 Mon Sep 17 00:00:00 2001 From: fredb Date: Sat, 10 Apr 2010 17:32:07 +0000 Subject: [PATCH] Add snow to urban shader --- Effects/urban.eff | 15 +++++++++++++++ Shaders/urban.frag | 26 ++++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/Effects/urban.eff b/Effects/urban.eff index ab95140dd..f8eecd141 100644 --- a/Effects/urban.eff +++ b/Effects/urban.eff @@ -3,6 +3,7 @@ Effects/urban Effects/terrain-default + /sim/rendering/snow-level-m 0.008 0.75 0.59 0.05 /sim/rendering/quality-level @@ -71,6 +72,10 @@ texture[2]/internal-format + + 2 + noise + Shaders/urban.vert Shaders/urban.frag @@ -97,6 +102,11 @@ sampler-2d 1 + + NoiseTex + sampler-3d + 2 + depth_factor float @@ -117,6 +127,11 @@ float quality-level + + snowlevel + float + snow-level + diff --git a/Shaders/urban.frag b/Shaders/urban.frag index 33f9f3c7f..d991acc1c 100644 --- a/Shaders/urban.frag +++ b/Shaders/urban.frag @@ -13,13 +13,16 @@ varying vec3 VBinormal; varying vec3 Normal; varying vec4 constantColor; +uniform sampler3D NoiseTex; uniform sampler2D BaseTex; uniform sampler2D NormalTex; uniform float depth_factor; uniform float tile_size; uniform float quality_level; // From /sim/rendering/quality-level +uniform float snowlevel; // From /sim/rendering/snow-level-m uniform vec3 night_color; +const float scale = 1.0; int linear_search_steps = 10; float ray_intersect(sampler2D reliefMap, vec2 dp, vec2 ds) @@ -73,6 +76,7 @@ void main (void) float emis = N.z; N.z = sqrt(1.0 - min(1.0,dot(N.xy, N.xy))); + float Nz = N.z; N = normalize(N.x * VTangent + N.y * VBinormal + N.z * VNormal); vec3 l = gl_LightSource[0].position.xyz; @@ -100,14 +104,32 @@ void main (void) emission_factor *= 0.5*pow(tc.r+0.8*tc.g+0.2*tc.b, 2) -0.2; ambient_light += (emission_factor * vec4(night_color, 0.0)); - vec4 finalColor = texture2D(BaseTex, uv) * ambient_light; - float fogFactor; float fogCoord = ecPos3.z / (1.0 + smoothstep(0.3, 0.7, emission_factor)); const float LOG2 = 1.442695; fogFactor = exp2(-gl_Fog.density * gl_Fog.density * fogCoord * fogCoord * LOG2); fogFactor = clamp(fogFactor, 0.0, 1.0); + vec4 noisevec = texture3D(NoiseTex, (rawpos.xyz)*0.01*scale); + vec4 nvL = texture3D(NoiseTex, (rawpos.xyz)*0.00066*scale); + + float n=0.06; + n += nvL[0]*0.4; + n += nvL[1]*0.6; + n += nvL[2]*2.0; + n += nvL[3]*4.0; + n += noisevec[0]*0.1; + n += noisevec[1]*0.4; + + n += noisevec[2]*0.8; + n += noisevec[3]*2.1; + n = mix(0.6, n, fogFactor); + + vec4 finalColor = texture2D(BaseTex, uv); + finalColor = mix(finalColor, clamp(n+nvL[2]*4.1+vec4(0.1, 0.1, nvL[2]*2.2, 1.0), 0.7, 1.0), + step(0.8,Nz)*smoothstep(snowlevel+300.0, snowlevel+360.0, (rawpos.z)+nvL[1]*3000.0)); + finalColor *= ambient_light; + if (gl_Fog.density == 1.0) fogFactor=1.0;