1
0
Fork 0

3d noise based fog and deeper shadows for lower quality terrain, urban and water shaders

This commit is contained in:
Thorsten Renk 2013-04-22 10:02:14 +03:00
parent f1c16e1592
commit c877c8b4e5
7 changed files with 161 additions and 21 deletions

View file

@ -139,9 +139,15 @@
<fogtype>
<use>/sim/rendering/shaders/skydome</use>
</fogtype>
<fogstructure>
<use>/environment/fog-structure</use>
</fogstructure>
<ice_cover>
<use>/environment/sea/surface/ice-cover</use>
</ice_cover>
<quality_level>
<use>/sim/rendering/shaders/landmass</use>
</quality_level>
<!-- sea colors -->
<sea_r>
<use>/environment/sea/color_r</use>
@ -519,6 +525,11 @@
<type>float</type>
<value><use>cloud_self_shading</use></value>
</uniform>
<uniform>
<name>fogstructure</name>
<type>float</type>
<value><use>fogstructure</use></value>
</uniform>
<uniform>
<name>ice_cover</name>
<type>float</type>
@ -546,6 +557,11 @@
<use>sea_b</use>
</value>
</uniform>
<uniform>
<name>quality_level</name>
<type>int</type>
<value><use>quality_level</use></value>
</uniform>
<!-- END fog include -->
</pass>
</technique>

View file

@ -4,10 +4,10 @@
// Ambient term comes in gl_Color.rgb.
varying vec4 diffuse_term;
varying vec3 normal;
//varying vec2 nvec;
varying vec3 relPos;
varying vec2 rawPos;
//varying vec3 ecViewdir;
varying vec3 worldPos;
uniform sampler2D texture;
@ -56,6 +56,10 @@ float rand2D(in vec2 co){
return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
}
float rand3D(in vec3 co){
return fract(sin(dot(co.xyz ,vec3(12.9898,78.233,144.7272))) * 43758.5453);
}
float cosine_interpolate(in float a, in float b, in float x)
{
float ft = x * 3.1415927;
@ -90,12 +94,52 @@ float interpolatedNoise2D(in float x, in float y)
}
float interpolatedNoise3D(in float x, in float y, in float z)
{
float integer_x = x - fract(x);
float fractional_x = x - integer_x;
float integer_y = y - fract(y);
float fractional_y = y - integer_y;
float integer_z = z - fract(z);
float fractional_z = z - integer_z;
float v1 = rand3D(vec3(integer_x, integer_y, integer_z));
float v2 = rand3D(vec3(integer_x+1.0, integer_y, integer_z));
float v3 = rand3D(vec3(integer_x, integer_y+1.0, integer_z));
float v4 = rand3D(vec3(integer_x+1.0, integer_y +1.0, integer_z));
float v5 = rand3D(vec3(integer_x, integer_y, integer_z+1.0));
float v6 = rand3D(vec3(integer_x+1.0, integer_y, integer_z+1.0));
float v7 = rand3D(vec3(integer_x, integer_y+1.0, integer_z+1.0));
float v8 = rand3D(vec3(integer_x+1.0, integer_y +1.0, integer_z+1.0));
float i1 = simple_interpolate(v1,v5, fractional_z);
float i2 = simple_interpolate(v2,v6, fractional_z);
float i3 = simple_interpolate(v3,v7, fractional_z);
float i4 = simple_interpolate(v4,v8, fractional_z);
float ii1 = simple_interpolate(i1,i2,fractional_x);
float ii2 = simple_interpolate(i3,i4,fractional_x);
return simple_interpolate(ii1 , ii2 , fractional_y);
}
float Noise2D(in vec2 coord, in float wavelength)
{
return interpolatedNoise2D(coord.x/wavelength, coord.y/wavelength);
}
float Noise3D(in vec3 coord, in float wavelength)
{
return interpolatedNoise3D(coord.x/wavelength, coord.y/wavelength, coord.z/wavelength);
}
float light_func (in float x, in float a, in float b, in float c, in float d, in float e)
@ -190,12 +234,12 @@ float noisegrad_10m;
float noisegrad_5m;
float noise_50m = Noise2D(rawPos.xy, 50.0);;
float noise_250m;
float noise_500m = Noise2D(rawPos.xy, 500.0);
float noise_1500m = Noise2D(rawPos.xy, 1500.0);
float noise_2000m = Noise2D(rawPos.xy, 2000.0);
float noise_250m = Noise3D(worldPos.xyz,250.0);
float noise_500m = Noise3D(worldPos.xyz, 500.0);
float noise_1500m = Noise3D(worldPos.xyz, 1500.0);
float noise_2000m = Noise3D(worldPos.xyz, 2000.0);
@ -293,7 +337,7 @@ if (tquality_level > 3)
if (flag == 1)
{
//noise_50m = Noise2D(rawPos.xy, 50.0);
noise_250m = Noise2D(rawPos.xy, 250.0);
//noise_250m = Noise2D(rawPos.xy, 250.0);
dist_fact = 0.1 * smoothstep(15000.0,40000.0, dist) - 0.03 * (1.0 - smoothstep(500.0,5000.0, dist));
nSum = ((1.0 -noise_2000m) + noise_1500m + 2.0 * noise_250m +noise_50m)/5.0;
nSum = nSum - 0.08 * (1.0 -smoothstep(0.9,0.95, abs(steepness)));
@ -389,7 +433,7 @@ if ((dist < 5000.0)&& (quality_level > 3) && (wetness>0.0))
color += diffuse_term * NdotL;
NdotHV = max(dot(n, halfVector), 0.0);
if (gl_FrontMaterial.shininess > 0.0)
specular.rgb = ((gl_FrontMaterial.specular.rgb + (water_factor * vec3 (1.0, 1.0, 1.0)))
specular.rgb = ((gl_FrontMaterial.specular.rgb * 0.1 + (water_factor * vec3 (1.0, 1.0, 1.0)))
* light_specular.rgb
* pow(NdotHV, gl_FrontMaterial.shininess + (20.0 * water_factor)));
}

View file

@ -20,13 +20,11 @@
// bugs with gl_FrontFacing in the fragment shader.
varying vec4 diffuse_term;
varying vec3 normal;
//varying vec2 nvec;
varying vec3 relPos;
varying vec2 rawPos;
//varying vec3 ecViewdir;
varying vec3 worldPos;
//varying float earthShade;
//varying float yprime_alt;
varying float mie_angle;
varying float steepness;
@ -42,6 +40,8 @@ uniform float ground_scattering;
uniform float eye_alt;
uniform float moonlight;
uniform mat4 osg_ViewMatrixInverse;
float earthShade;
float yprime_alt;
//float mie_angle;
@ -78,6 +78,7 @@ void main()
float scattering;
rawPos = gl_Vertex.xy;
worldPos = (osg_ViewMatrixInverse *gl_ModelViewMatrix * gl_Vertex).xyz;
steepness = dot(normalize(gl_Normal), vec3 (0.0, 0.0, 1.0));
@ -260,6 +261,13 @@ else // the faster, full-day version without lightfields
light_ambient = light_ambient * ((1.0+steepness)/2.0 * 1.2 + (1.0-steepness)/2.0 * 0.2);
// deeper shadows when there is lots of direct light
float shade_depth = 1.0 * smoothstep (0.6,0.95,ground_scattering) * (1.0-smoothstep(0.1,0.5,overcast)) * smoothstep(0.4,1.5,earthShade);
light_ambient.rgb = light_ambient.rgb * (1.0 - shade_depth);
light_diffuse.rgb = light_diffuse.rgb * (1.0 + 1.2 * shade_depth);
// default lighting based on texture and material using the light we have just computed
diffuse_term = diffuse_color* light_diffuse;

View file

@ -529,7 +529,7 @@ if ((dist < 5000.0)&& (quality_level > 3) && (combined_wetness>0.0))
color += diffuse_term * NdotL;
NdotHV = max(dot(n, halfVector), 0.0);
if (gl_FrontMaterial.shininess > 0.0)
specular.rgb = ((gl_FrontMaterial.specular.rgb + (water_factor * vec3 (1.0, 1.0, 1.0)))
specular.rgb = ((gl_FrontMaterial.specular.rgb * 0.1 + (water_factor * vec3 (1.0, 1.0, 1.0)))
* light_specular.rgb
* pow(NdotHV, gl_FrontMaterial.shininess + (20.0 * water_factor)));
}

View file

@ -14,7 +14,7 @@
#define BINARY_SEARCH_COUNT 10
#define BILINEAR_SMOOTH_FACTOR 2.0
varying vec2 rawpos;
varying vec3 worldPos;
varying vec4 ecPosition;
varying vec3 VNormal;
varying vec3 VTangent;
@ -28,7 +28,7 @@ varying float yprime_alt;
varying float mie_angle;
//varying float steepness;
uniform sampler3D NoiseTex;
//uniform sampler3D NoiseTex;
uniform sampler2D BaseTex;
uniform sampler2D NormalTex;
uniform sampler2D QDMTex;
@ -66,6 +66,10 @@ float rand2D(in vec2 co){
return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
}
float rand3D(in vec3 co){
return fract(sin(dot(co.xyz ,vec3(12.9898,78.233,144.7272))) * 43758.5453);
}
float simple_interpolate(in float a, in float b, in float x)
{
@ -92,12 +96,50 @@ float interpolatedNoise2D(in float x, in float y)
}
float interpolatedNoise3D(in float x, in float y, in float z)
{
float integer_x = x - fract(x);
float fractional_x = x - integer_x;
float integer_y = y - fract(y);
float fractional_y = y - integer_y;
float integer_z = z - fract(z);
float fractional_z = z - integer_z;
float v1 = rand3D(vec3(integer_x, integer_y, integer_z));
float v2 = rand3D(vec3(integer_x+1.0, integer_y, integer_z));
float v3 = rand3D(vec3(integer_x, integer_y+1.0, integer_z));
float v4 = rand3D(vec3(integer_x+1.0, integer_y +1.0, integer_z));
float v5 = rand3D(vec3(integer_x, integer_y, integer_z+1.0));
float v6 = rand3D(vec3(integer_x+1.0, integer_y, integer_z+1.0));
float v7 = rand3D(vec3(integer_x, integer_y+1.0, integer_z+1.0));
float v8 = rand3D(vec3(integer_x+1.0, integer_y +1.0, integer_z+1.0));
float i1 = simple_interpolate(v1,v5, fractional_z);
float i2 = simple_interpolate(v2,v6, fractional_z);
float i3 = simple_interpolate(v3,v7, fractional_z);
float i4 = simple_interpolate(v4,v8, fractional_z);
float ii1 = simple_interpolate(i1,i2,fractional_x);
float ii2 = simple_interpolate(i3,i4,fractional_x);
return simple_interpolate(ii1 , ii2 , fractional_y);
}
float Noise2D(in vec2 coord, in float wavelength)
{
return interpolatedNoise2D(coord.x/wavelength, coord.y/wavelength);
}
float Noise3D(in vec3 coord, in float wavelength)
{
return interpolatedNoise3D(coord.x/wavelength, coord.y/wavelength, coord.z/wavelength);
}
float light_func (in float x, in float a, in float b, in float c, in float d, in float e)
@ -336,9 +378,8 @@ void main (void)
vec4 dust_color;
float noise_1500m = Noise2D(rawpos.xy, 1500.0);
float noise_2000m = Noise2D(rawpos.xy, 2000.0);
float noise_1500m = Noise3D(worldPos.xyz,1500.0);
float noise_2000m = Noise3D(worldPos.xyz,2000.0);
if (quality_level > 2)
{

View file

@ -21,7 +21,7 @@
varying vec3 relPos;
varying vec2 rawPos;
varying vec3 worldPos;
varying vec3 VNormal;
varying vec3 VTangent;
varying vec4 ecPosition;
@ -44,6 +44,7 @@ uniform float ground_scattering;
uniform float eye_alt;
uniform float moonlight;
uniform mat4 osg_ViewMatrixInverse;
attribute vec3 tangent;//, binormal;
@ -80,7 +81,8 @@ void main()
float vertex_alt;
float scattering;
rawPos = gl_Vertex.xy;
//rawPos = gl_Vertex.xy;
worldPos = (osg_ViewMatrixInverse *gl_ModelViewMatrix * gl_Vertex).xyz;
steepness = dot(normalize(gl_Normal), vec3 (0.0, 0.0, 1.0));
VNormal = normalize(gl_NormalMatrix * gl_Normal);
ecPosition = gl_ModelViewMatrix * gl_Vertex;

View file

@ -50,11 +50,13 @@ uniform float scattering;
uniform float ground_scattering;
uniform float cloud_self_shading;
uniform float eye_alt;
uniform float fogstructure;
uniform float ice_cover;
uniform float sea_r;
uniform float sea_g;
uniform float sea_b;
uniform int quality_level;
vec3 specular_light;
@ -614,7 +616,7 @@ transmission_arg = (dist-distance_in_layer)/avisibility;
float eqColorFactor;
/*
if (visibility < avisibility)
{
transmission_arg = transmission_arg + (distance_in_layer/visibility);
@ -628,6 +630,33 @@ else
// this combines the Weber-Fechner intensity
eqColorFactor = 1.0 - 0.1 * delta_zv/avisibility - (1.0 -effective_scattering);
}
*/
if (visibility < avisibility)
{
if (quality_level > 3)
{
transmission_arg = transmission_arg + (distance_in_layer/(1.0 * visibility + 1.0 * visibility * fogstructure * 0.06 * (noise_1500m + noise_2000m -1.0) ));
}
else
{
transmission_arg = transmission_arg + (distance_in_layer/visibility);
}
// this combines the Weber-Fechner intensity
eqColorFactor = 1.0 - 0.1 * delta_zv/visibility - (1.0 -effective_scattering);
}
else
{
if (quality_level > 3)
{
transmission_arg = transmission_arg + (distance_in_layer/(1.0 * avisibility + 1.0 * avisibility * fogstructure * 0.06 * (noise_1500m + noise_2000m - 1.0) ));
}
else
{
transmission_arg = transmission_arg + (distance_in_layer/avisibility);
}
// this combines the Weber-Fechner intensity
eqColorFactor = 1.0 - 0.1 * delta_zv/avisibility - (1.0 -effective_scattering);
}
transmission = fog_func(transmission_arg);