Add snow to urban shader
This commit is contained in:
parent
1a986d8747
commit
64f351935b
2 changed files with 39 additions and 2 deletions
|
@ -3,6 +3,7 @@
|
|||
<name>Effects/urban</name>
|
||||
<inherits-from>Effects/terrain-default</inherits-from>
|
||||
<parameters>
|
||||
<snow-level><use>/sim/rendering/snow-level-m</use></snow-level>
|
||||
<depth-factor type="float">0.008</depth-factor>
|
||||
<night-color type="vec3d">0.75 0.59 0.05</night-color>
|
||||
<quality-level><use>/sim/rendering/quality-level</use></quality-level>
|
||||
|
@ -71,6 +72,10 @@
|
|||
<use>texture[2]/internal-format</use>
|
||||
</internal-format>
|
||||
</texture-unit>
|
||||
<texture-unit>
|
||||
<unit>2</unit>
|
||||
<type>noise</type>
|
||||
</texture-unit>
|
||||
<program>
|
||||
<vertex-shader>Shaders/urban.vert</vertex-shader>
|
||||
<fragment-shader>Shaders/urban.frag</fragment-shader>
|
||||
|
@ -97,6 +102,11 @@
|
|||
<type>sampler-2d</type>
|
||||
<value type="int">1</value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>NoiseTex</name>
|
||||
<type>sampler-3d</type>
|
||||
<value type="int">2</value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>depth_factor</name>
|
||||
<type>float</type>
|
||||
|
@ -117,6 +127,11 @@
|
|||
<type>float</type>
|
||||
<value><use>quality-level</use></value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>snowlevel</name>
|
||||
<type>float</type>
|
||||
<value><use>snow-level</use></value>
|
||||
</uniform>
|
||||
</pass>
|
||||
</technique>
|
||||
</PropertyList>
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in a new issue