Deeper shadows and fog/snow continuity across terrain tiles for highest quality level terrain shader of Atmospheric Light Scattering
This commit is contained in:
parent
f9da4387e6
commit
402d75a602
2 changed files with 62 additions and 29 deletions
|
@ -4,12 +4,11 @@
|
|||
// Ambient term comes in gl_Color.rgb.
|
||||
varying vec4 diffuse_term;
|
||||
varying vec3 normal;
|
||||
//varying vec2 nvec;
|
||||
varying vec3 relPos;
|
||||
varying vec2 rawPos;
|
||||
//varying vec2 worldPos;
|
||||
varying vec3 worldPos;
|
||||
varying vec3 ecViewdir;
|
||||
varying vec3 ecNormal;
|
||||
|
||||
|
||||
|
||||
uniform sampler2D texture;
|
||||
|
@ -20,7 +19,7 @@ uniform sampler2D mix_texture;
|
|||
uniform sampler2D grain_texture;
|
||||
uniform sampler2D dot_texture;
|
||||
uniform sampler2D gradient_texture;
|
||||
//uniform sampler2D foam_texture;
|
||||
|
||||
|
||||
|
||||
//varying float yprime_alt;
|
||||
|
@ -71,6 +70,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;
|
||||
|
@ -103,6 +106,39 @@ float interpolatedNoise2D(in float x, in float y)
|
|||
return simple_interpolate(i1 , i2 , fractional_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)
|
||||
|
@ -111,6 +147,11 @@ 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 dotNoise2D(in float x, in float y, in float fractionalMaxDotSize)
|
||||
{
|
||||
float integer_x = x - fract(x);
|
||||
|
@ -259,10 +300,10 @@ float noise_25m = Noise2D(rawPos.xy, 25.0);
|
|||
float noise_50m = Noise2D(rawPos.xy, 50.0);
|
||||
|
||||
|
||||
float noise_250m = Noise2D(rawPos.xy,250.0);
|
||||
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);
|
||||
|
||||
// dot noise
|
||||
|
||||
|
|
|
@ -20,14 +20,12 @@
|
|||
// 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 vec2 worldPos;
|
||||
varying vec3 worldPos;
|
||||
varying vec3 ecViewdir;
|
||||
|
||||
//varying float earthShade;
|
||||
//varying float yprime_alt;
|
||||
|
||||
varying float mie_angle;
|
||||
varying float steepness;
|
||||
varying float grad_dir;
|
||||
|
@ -42,15 +40,13 @@ uniform float visibility;
|
|||
uniform float overcast;
|
||||
uniform float ground_scattering;
|
||||
uniform float eye_alt;
|
||||
//uniform float eye_lat;
|
||||
//uniform float eye_lon;
|
||||
uniform float moonlight;
|
||||
|
||||
uniform mat4 osg_ViewMatrixInverse;
|
||||
|
||||
float earthShade;
|
||||
float yprime_alt;
|
||||
//float mie_angle;
|
||||
|
||||
|
||||
|
||||
// This is the value used in the skydome scattering shader - use the same here for consistency?
|
||||
|
@ -85,17 +81,8 @@ void main()
|
|||
float scattering;
|
||||
|
||||
rawPos = gl_Vertex.xy;
|
||||
worldPos = (osg_ViewMatrixInverse *gl_ModelViewMatrix * gl_Vertex).xyz;
|
||||
|
||||
// try making a continuous coordinate system
|
||||
//vec4 worldPos3D = (osg_ViewMatrixInverse *gl_ModelViewMatrix * gl_Vertex);
|
||||
|
||||
//rawPos = worldPos3d.yz;
|
||||
//float x1 = sin(eye_lon) * worldPos3D.y + cos(eye_lon) * worldPos3D.z;
|
||||
//float y1 = cos(eye_lon) * worldPos3D.y - sin(eye_lon) * worldPos3D.z;
|
||||
|
||||
//y1 = cos(eye_lat) * y1 + sin(eye_lat) * worldPos3D.x;
|
||||
|
||||
//worldPos = vec2 (x1, y1);
|
||||
|
||||
steepness = dot(normalize(gl_Normal), vec3 (0.0, 0.0, 1.0));
|
||||
grad_dir = dot(normalize(gl_Normal.xy), vec2 (1.0, 0.0));
|
||||
|
@ -277,7 +264,12 @@ 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);
|
||||
|
||||
//light_ambient.rgb = 0.1 * light_ambient.rgb;
|
||||
// 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
|
||||
|
||||
|
|
Loading…
Reference in a new issue