1
0
Fork 0

ALS road shader: add procedural snow, make lighting switchable

This commit is contained in:
Thorsten Renk 2017-03-09 14:00:09 +02:00
parent 549bf4dd04
commit bfc6a014bb
2 changed files with 60 additions and 10 deletions

View file

@ -17,8 +17,11 @@
<grain-texture-enabled type="int">0</grain-texture-enabled> <grain-texture-enabled type="int">0</grain-texture-enabled>
<grain-magnification type="float">50</grain-magnification> <grain-magnification type="float">50</grain-magnification>
<lightmap-color type="vec3d" n="0"> 0.8 0.8 1.0 </lightmap-color> <lightmap-color type="vec3d" n="0"> 0.8 0.8 1.0 </lightmap-color>
<snow_level><use>/environment/snow-level-m</use></snow_level>
<snow_thickness_factor><use>/environment/surface/snow-thickness-factor</use></snow_thickness_factor>
<road-traffic-enabled><use>/sim/rendering/osm/road-traffic-enabled</use></road-traffic-enabled> <road-traffic-enabled><use>/sim/rendering/osm/road-traffic-enabled</use></road-traffic-enabled>
<road-traffic-density><use>/sim/rendering/osm/road-traffic-density</use></road-traffic-density> <road-traffic-density><use>/sim/rendering/osm/road-traffic-density</use></road-traffic-density>
<road-light-factor><use>/environment/lightmap-factor</use></road-light-factor>
</parameters> </parameters>
<technique n="3"> <technique n="3">
@ -493,6 +496,14 @@
</value> </value>
</uniform> </uniform>
<uniform>
<name>streetlight_factor</name>
<type>float</type>
<value>
<use>road-light-factor</use>
</value>
</uniform>
<!-- use a grain texture map--> <!-- use a grain texture map-->
<uniform> <uniform>
@ -511,7 +522,7 @@
</value> </value>
</uniform> </uniform>
<!-- simulate wetness and rain--> <!-- simulate wetness, snow and rain-->
<uniform> <uniform>
<name>rain_enabled</name> <name>rain_enabled</name>
<type>int</type> <type>int</type>
@ -520,6 +531,18 @@
</value> </value>
</uniform> </uniform>
<uniform>
<name>snowlevel</name>
<type>float</type>
<value><use>snow_level</use></value>
</uniform>
<uniform>
<name>snow_thickness_factor</name>
<type>float</type>
<value><use>snow_thickness_factor</use></value>
</uniform>
<!-- set the amount of ambient light correction 0.0 - 1.0 --> <!-- set the amount of ambient light correction 0.0 - 1.0 -->
<uniform> <uniform>
<name>amb_correction</name> <name>amb_correction</name>

View file

@ -56,6 +56,7 @@ uniform float grain_magnification;
uniform float wetness; uniform float wetness;
uniform float rain_norm; uniform float rain_norm;
uniform float road_traffic_density; uniform float road_traffic_density;
uniform float streetlight_factor;
uniform float avisibility; uniform float avisibility;
uniform float cloud_self_shading; uniform float cloud_self_shading;
@ -69,6 +70,8 @@ uniform float terminator;
uniform float terrain_alt; uniform float terrain_alt;
uniform float visibility; uniform float visibility;
uniform float air_pollution; uniform float air_pollution;
uniform float snowlevel;
uniform float snow_thickness_factor;
uniform float osg_SimulationTime; uniform float osg_SimulationTime;
@ -98,6 +101,7 @@ float alt_factor(in float eye_alt, in float vertex_alt);
float light_distance_fading(in float dist); float light_distance_fading(in float dist);
float fog_backscatter(in float avisibility); float fog_backscatter(in float avisibility);
float rand2D(in vec2 co); float rand2D(in vec2 co);
float Noise2D(in vec2 coord, in float wavelength);
vec3 rayleigh_out_shift(in vec3 color, in float outscatter); vec3 rayleigh_out_shift(in vec3 color, in float outscatter);
vec3 get_hazeColor(in float lightArg); vec3 get_hazeColor(in float lightArg);
@ -183,6 +187,11 @@ void main (void)
vec3 mixedcolor; vec3 mixedcolor;
vec3 N = vec3(0.0,0.0,1.0); vec3 N = vec3(0.0,0.0,1.0);
// noise
float noise_1m = Noise2D(rawpos.xy, 1.0);
float noise_5m = Noise2D(rawpos.xy, 5.0);
// road type characteristics // road type characteristics
float rtype_traffic_density = 0.0; float rtype_traffic_density = 0.0;
@ -242,6 +251,8 @@ void main (void)
float ct = dot(normalize(up), normalize(vertVec)); float ct = dot(normalize(up), normalize(vertVec));
vec3 relPos = (gl_ModelViewMatrixInverse * vec4 (vertVec,0.0)).xyz;
/// END geometry for light /// END geometry for light
@ -292,15 +303,32 @@ void main (void)
/// END grain overlay /// END grain overlay
/// BEGIN procedural cars /// BEGIN procedural textures - cars and snow
float cTag = 0.0;
float cPresent = 0.0;
vec2 roadCoords = gl_TexCoord[0].st; vec2 roadCoords = gl_TexCoord[0].st;
roadCoords.s *=8.0; roadCoords.s *=8.0;
roadCoords.s = fract(roadCoords.s); roadCoords.s = fract(roadCoords.s);
vec4 snow_texel = vec4 (0.95, 0.95, 0.95, 1.0);
float noise_term = 0.5 * (noise_5m - 0.5);
noise_term += 0.5 * (noise_1m - 0.5);
snow_texel.a = snow_texel.a * 0.2+0.8* smoothstep(0.2,0.8, 0.3 +noise_term + 0.5*snow_thickness_factor +0.0001*(relPos.z +eye_alt -snowlevel) );
float noise_2000m = 0.0;
float noise_10m = 0.0;
float snowLaneShape = smoothstep(0.20, 0.28, roadCoords.s) * (1.0-smoothstep(0.42, 0.5, roadCoords.s));
snowLaneShape += smoothstep(0.6, 0.68, roadCoords.s) * (1.0-smoothstep(0.82, 0.9, roadCoords.s));
snow_texel.a *= (1.0 - 0.3* snowLaneShape * rtype_traffic_density);
texel.rgb = mix(texel.rgb, snow_texel.rgb, snow_texel.a* smoothstep(snowlevel, snowlevel+200.0, 1.0 * (relPos.z + eye_alt)+ (noise_2000m + 0.1 * noise_10m -0.55) *400.0));
float cTag = 0.0;
float cPresent = 0.0;
if (road_traffic_enabled == 1) if (road_traffic_enabled == 1)
{ {
float cSign = 1.0; float cSign = 1.0;
@ -329,9 +357,9 @@ void main (void)
float cPos = cTag; float cPos = cTag;
if (cSign > 0.0) {cPos = 1.0 - cPos;} if (cSign > 0.0) {cPos = 1.0 - cPos;}
float cShape = smoothstep(0.0, 0.05, cPos) * (1.0-smoothstep(0.35, 0.4, cPos)); float cShape = smoothstep(0.0, 0.05, cPos) * (1.0-smoothstep(0.35, 0.4, cPos));
float laneShape = smoothstep(0.25, 0.28, roadCoords.s) * (1.0-smoothstep(0.42, 0.45, roadCoords.s)); float laneShape = smoothstep(0.25, 0.28, roadCoords.s) * (1.0-smoothstep(0.42, 0.45, roadCoords.s));
laneShape += smoothstep(0.65, 0.68, roadCoords.s) * (1.0-smoothstep(0.82, 0.85, roadCoords.s)); laneShape += smoothstep(0.65, 0.68, roadCoords.s) * (1.0-smoothstep(0.82, 0.85, roadCoords.s));
cShape *= laneShape; cShape *= laneShape;
texel.rgb = mix(texel.rgb, cColor, cPresent * cShape); texel.rgb = mix(texel.rgb, cColor, cPresent * cShape);
@ -395,7 +423,7 @@ void main (void)
{pf1 = pow(nDotHV1, 0.5*gl_FrontMaterial.shininess);} {pf1 = pow(nDotHV1, 0.5*gl_FrontMaterial.shininess);}
vec3 relPos = (gl_ModelViewMatrixInverse * vec4 (vertVec,0.0)).xyz;
if (cloud_shadow_flag == 1) if (cloud_shadow_flag == 1)
{ {
light_diffuse = light_diffuse * shadow_func(relPos.x, relPos.y, 1.0, dist); light_diffuse = light_diffuse * shadow_func(relPos.x, relPos.y, 1.0, dist);
@ -427,7 +455,7 @@ void main (void)
Specular+= gl_FrontMaterial.specular * pow(max(0.0,-dot(N,normalize(vertVec))),gl_FrontMaterial.shininess) * vec4(secondary_light,1.0); Specular+= gl_FrontMaterial.specular * pow(max(0.0,-dot(N,normalize(vertVec))),gl_FrontMaterial.shininess) * vec4(secondary_light,1.0);
//vec4 color = gl_Color + Diffuse * gl_FrontMaterial.diffuse; //vec4 color = gl_Color + Diffuse * gl_FrontMaterial.diffuse;
vec4 color = Diffuse * gl_FrontMaterial.diffuse; vec4 color = Diffuse * gl_FrontMaterial.diffuse;
color = clamp( color, 0.0, 1.0 ); color = clamp( color, 0.0, 1.0 );
@ -531,7 +559,6 @@ void main (void)
// set ambient adjustment to remove bluiness with user input // set ambient adjustment to remove bluiness with user input
float ambient_offset = clamp(amb_correction, -1.0, 1.0); float ambient_offset = clamp(amb_correction, -1.0, 1.0);
//vec4 ambient = gl_LightModel.ambient + gl_LightSource[0].ambient;
vec4 ambient = gl_LightModel.ambient + light_ambient; vec4 ambient = gl_LightModel.ambient + light_ambient;
vec4 ambient_Correction = vec4(ambient.rg, ambient.b * 0.6, 1.0) vec4 ambient_Correction = vec4(ambient.rg, ambient.b * 0.6, 1.0)
* ambient_offset ; * ambient_offset ;
@ -558,7 +585,7 @@ void main (void)
vec3 pLMColor = streetlight_color;//vec3 (0.941, 0.682, 0.086); vec3 pLMColor = streetlight_color;//vec3 (0.941, 0.682, 0.086);
float pLMIntensity = smoothstep(0.0, 0.4, roadCoords.s) * (1.0 - smoothstep(0.6, 1.0, roadCoords.s)); float pLMIntensity = smoothstep(0.0, 0.4, roadCoords.s) * (1.0 - smoothstep(0.6, 1.0, roadCoords.s));
pLMIntensity = 0.5 * rtype_base_illumination + 0.1 * max(0.0,sin(4.0 * roadCoords.t)); pLMIntensity = 0.5 * rtype_base_illumination + 0.1 * max(0.0,sin(4.0 * roadCoords.t)) * streetlight_factor;
pLMColor *= pLMIntensity; pLMColor *= pLMIntensity;