diff --git a/Effects/birdswarm.eff b/Effects/birdswarm.eff new file mode 100644 index 000000000..21d329039 --- /dev/null +++ b/Effects/birdswarm.eff @@ -0,0 +1,166 @@ + + + + Effects/birdswarm + + + + Models/Effects/birds_in_flight.png + 2d + linear-mipmap-linear + repeat + repeat + normalized + + + 0.9 + 0.8 + 0.82 + 0.7 + 0.3 + 0.25 + /environment/ground-visibility-m + /environment/visibility-m + /environment/ground-haze-thickness-m + /environment/mean-terrain-elevation-m + /sim/rendering/eye-altitude-m + /environment/terminator-relative-position-m + /rendering/scene/scattering + + + + + + /sim/rendering/shaders/skydome + + + 2.0 + + + + GL_ARB_shader_objects + GL_ARB_shading_language_100 + GL_ARB_vertex_shader + GL_ARB_fragment_shader + + + + + + true + + material/active + material/ambient + material/diffuse + material/specular + material/emissive + material/shininess + material/color-mode + + + blend/active + blend/source + blend/destination + + shade-model + cull-face + rendering-hint + + 111 + DepthSortedBin + + + 0 + texture[0]/image + texture[0]/type + texture[0]/filter + texture[0]/wrap-s + texture[0]/wrap-t + texture[0]/internal-format + + + false + + false + + Shaders/birds-ALS.vert + Shaders/birds-ALS.frag + Shaders/noise.frag + Shaders/hazes.frag + + + + + color_base_r + float + color_base_r + + + color_base_g + float + color_base_g + + + color_base_b + float + color_base_b + + + color_alt_r + float + color_alt_r + + + color_alt_g + float + color_alt_g + + + color_alt_b + float + color_alt_b + + + visibility + float + visibility + + + avisibility + float + avisibility + + + hazeLayerAltitude + float + lthickness + + + scattering + float + scattering + + + eye_alt + float + eye_alt + + + terminator + float + terminator + + + texture + sampler-2d + 0 + + + texture + sampler-2d + 0 + + + + + diff --git a/Models/Effects/Birds/birds.ac b/Models/Effects/Birds/birds.ac new file mode 100644 index 000000000..566004b12 --- /dev/null +++ b/Models/Effects/Birds/birds.ac @@ -0,0 +1,22 @@ +AC3Db +MATERIAL "DefaultWhite" rgb 1.0000 1.0000 1.0000 amb 0.2000 0.2000 0.2000 emis 0.0000 0.0000 0.0000 spec 0.5000 0.5000 0.5000 shi 10 trans 0.0000 +MATERIAL "DefaultWhite" rgb 1.0000 1.0000 1.0000 amb 0.2000 0.2000 0.2000 emis 0.0000 0.0000 0.0000 spec 0.0250 0.0250 0.0250 shi 50 trans 0.1000 +OBJECT world +name "Blender_export__birds1.ac" +kids 1 +OBJECT poly +name "birds1" +numvert 4 +-0.0000019 -1.0000000 -1.0000000 +-0.0000005 1.0000000 -1.0000000 +0.0000005 -1.0000000 1.0000000 +0.0000019 1.0000000 1.0000000 +numsurf 1 +SURF 0X20 +mat 1 +refs 4 +1 0 0 +0 0 0 +2 0 0 +3 0 0 +kids 0 diff --git a/Models/Effects/Birds/birds_in_flight.png b/Models/Effects/Birds/birds_in_flight.png new file mode 100644 index 000000000..aaa96c691 Binary files /dev/null and b/Models/Effects/Birds/birds_in_flight.png differ diff --git a/Models/Effects/Birds/birdswarm.ac b/Models/Effects/Birds/birdswarm.ac new file mode 100644 index 000000000..f3c6798e8 --- /dev/null +++ b/Models/Effects/Birds/birdswarm.ac @@ -0,0 +1,22 @@ +AC3Db +MATERIAL "DefaultWhite" rgb 1.0000 1.0000 1.0000 amb 0.2000 0.2000 0.2000 emis 0.0000 0.0000 0.0000 spec 0.5000 0.5000 0.5000 shi 10 trans 1.0000 +MATERIAL "DefaultWhite" rgb 1.0000 1.0000 1.0000 amb 0.2000 0.2000 0.2000 emis 0.0000 0.0000 0.0000 spec 0.0250 0.0250 0.0250 shi 50 trans 1.0000 +OBJECT world +name "Blender_export__procedural_light.ac" +kids 1 +OBJECT poly +name "birdswarm" +numvert 4 +-0.0000019 -1.0000000 -1.0000000 +-0.0000005 1.0000000 -1.0000000 +0.0000005 -1.0000000 1.0000000 +0.0000019 1.0000000 1.0000000 +numsurf 1 +SURF 0X20 +mat 1 +refs 4 +1 0 0 +0 0 0 +2 0 0 +3 0 0 +kids 0 diff --git a/Models/Effects/Birds/birdswarm.xml b/Models/Effects/Birds/birdswarm.xml new file mode 100644 index 000000000..75f3de4db --- /dev/null +++ b/Models/Effects/Birds/birdswarm.xml @@ -0,0 +1,22 @@ + + + + + birdswarm1.xml + + + + birdswarm2.xml + + + + birdswarm3.xml + + + + birdswarm4.xml + + + + + diff --git a/Models/Effects/Birds/birdswarm1.xml b/Models/Effects/Birds/birdswarm1.xml new file mode 100644 index 000000000..c2f28d4b3 --- /dev/null +++ b/Models/Effects/Birds/birdswarm1.xml @@ -0,0 +1,25 @@ + + + + birds.ac + + + 0 + 0 + 200.0 + + + birds1 + scale + 50.0 + 50.0 + 50.0 + + + + Effects/birdswarm + birds1 + + + + diff --git a/Models/Effects/Birds/birdswarm2.xml b/Models/Effects/Birds/birdswarm2.xml new file mode 100644 index 000000000..d142ea917 --- /dev/null +++ b/Models/Effects/Birds/birdswarm2.xml @@ -0,0 +1,28 @@ + + + + birds.ac + + + 40 + 20 + 200.0 + + + birds1 + scale + 50.0 + 50.0 + 50.0 + + + + Effects/birdswarm + birds1 + + + + + + + diff --git a/Models/Effects/Birds/birdswarm3.xml b/Models/Effects/Birds/birdswarm3.xml new file mode 100644 index 000000000..79092d689 --- /dev/null +++ b/Models/Effects/Birds/birdswarm3.xml @@ -0,0 +1,25 @@ + + + + birds.ac + + + 60 + 5 + 190.0 + + + birds1 + scale + 50.0 + 50.0 + 50.0 + + + + Effects/birdswarm + birds1 + + + + diff --git a/Models/Effects/Birds/birdswarm4.xml b/Models/Effects/Birds/birdswarm4.xml new file mode 100644 index 000000000..fb16eed76 --- /dev/null +++ b/Models/Effects/Birds/birdswarm4.xml @@ -0,0 +1,25 @@ + + + + birds.ac + + + 85 + -30 + 210.0 + + + birds1 + scale + 50.0 + 50.0 + 50.0 + + + + Effects/birdswarm + birds1 + + + + diff --git a/Shaders/birds-ALS.frag b/Shaders/birds-ALS.frag new file mode 100644 index 000000000..0e0f43d21 --- /dev/null +++ b/Shaders/birds-ALS.frag @@ -0,0 +1,206 @@ +// -*-C++-*- + +uniform sampler2D texture; + +uniform float color_base_r; +uniform float color_base_g; +uniform float color_base_b; + +uniform float color_alt_r; +uniform float color_alt_g; +uniform float color_alt_b; + +uniform float visibility; +uniform float avisibility; +uniform float hazeLayerAltitude; +uniform float eye_alt; +uniform float terminator; +uniform float scattering; + +uniform float osg_SimulationTime; + + +varying vec3 vertex; +varying vec3 relPos; +varying vec3 normal; + +const float terminator_width = 200000.0; + +float Noise2D(in vec2 coord, in float wavelength); +float VoronoiNoise2D(in vec2 coord, in float wavelength, in float xrand, in float yrand); +float fog_func (in float targ, in float alt); + +float light_func (in float x, in float a, in float b, in float c, in float d, in float e) +{ +//x = x - 0.5; + +// use the asymptotics to shorten computations +if (x < -15.0) {return 0.0;} + +return e / pow((1.0 + a * exp(-b * (x-c)) ),(1.0/d)); +} + + +void main() +{ + +float noise = 0.0; + + +vec3 color_base = vec3 (color_base_r, color_base_g, color_base_b); +vec3 color_alt = vec3 (color_alt_r, color_alt_g, color_alt_b); +vec3 shadedFogColor = vec3(0.55, 0.67, 0.88); + + +vec3 viewDir = normalize(relPos); + + +vec2 lookup_coords = vertex.yz; +lookup_coords.x += 0.03* osg_SimulationTime; + +float domain_size = 0.05; +float r = length(vertex); + +float domain_noise = VoronoiNoise2D(lookup_coords, domain_size, 0.0, 0.0); +domain_noise = domain_noise * (1.0- smoothstep(0.5, 1.0, r)); + +if (domain_noise < 0.9) {discard;} + + + +// fogging + +float dist = length(relPos); +float delta_z = hazeLayerAltitude - eye_alt; +float transmission; +float vAltitude; +float delta_zv; +float H; +float distance_in_layer; +float transmission_arg; + + // angle with horizon + float ct = dot(vec3(0.0, 0.0, 1.0), relPos)/dist; + + + if (delta_z > 0.0) // we're inside the layer + { + if (ct < 0.0) // we look down + { + distance_in_layer = dist; + vAltitude = min(distance_in_layer,min(visibility, avisibility)) * ct; + delta_zv = delta_z - vAltitude; + } + else // we may look through upper layer edge + { + H = dist * ct; + if (H > delta_z) {distance_in_layer = dist/H * delta_z;} + else {distance_in_layer = dist;} + vAltitude = min(distance_in_layer,visibility) * ct; + delta_zv = delta_z - vAltitude; + } + } + else // we see the layer from above, delta_z < 0.0 + { + H = dist * -ct; + if (H < (-delta_z)) + { + distance_in_layer = 0.0; + delta_zv = 0.0; + } + else + { + vAltitude = H + delta_z; + distance_in_layer = vAltitude/H * dist; + vAltitude = min(distance_in_layer,visibility) * (-ct); + delta_zv = vAltitude; + } + } + + + + transmission_arg = (dist-distance_in_layer)/avisibility; + if (visibility < avisibility) + { + transmission_arg = transmission_arg + (distance_in_layer/visibility); + } + else + { + transmission_arg = transmission_arg + (distance_in_layer/avisibility); + } + + + + transmission = fog_func(transmission_arg, 0.0); + float lightArg = terminator/100000.0; + float earthShade = 0.6 * (1.0 - smoothstep(-terminator_width+ terminator, terminator_width + terminator, 0.0)) + 0.4; + + vec4 light_diffuse; + + + light_diffuse.b = light_func(lightArg , 1.330e-05, 0.264, 2.227, 1.08e-05, 1.0); + light_diffuse.g = light_func(lightArg , 3.931e-06, 0.264, 3.827, 7.93e-06, 1.0); + light_diffuse.r = light_func(lightArg, 8.305e-06, 0.161, 3.827, 3.04e-05, 1.0); + light_diffuse.a = 1.0; + + light_diffuse *=scattering; + + + float intensity = length(light_diffuse.rgb); + light_diffuse.rgb = intensity * normalize(mix(light_diffuse.rgb, shadedFogColor, 1.0 -smoothstep(0.4, 0.7,earthShade) )); + + +vec4 domainTexel; + + +if (domain_noise > 0.9) {domainTexel = vec4 (1.0, 1.0, 1.0, 1.0);} +else {domainTexel = vec4 (0.0, 0.0, 0.0, 0.0);} + + + +vec2 coords_raw = lookup_coords/domain_size; +coords_raw += vec2(0.5,0.5); +float coord_int_x = coords_raw.x - fract(coords_raw.x) ; +float coord_int_y = coords_raw.y - fract(coords_raw.y) ; + +vec2 domain_coords = vec2 (coords_raw.x - coord_int_x, coords_raw.y - coord_int_y); + +float domain_x = coords_raw.x - coord_int_x; + +domain_coords.y = clamp(domain_coords.y, 0.05, 0.95); + +domain_coords.x *=0.25; + +float shape_select = 0.0; + +if (domain_noise > 0.975) {shape_select = 0.25;} +else if (domain_noise > 0.95) {shape_select = 0.5;} +else if (domain_noise > 0.925) {shape_select = 0.75;} + +float t_fact = fract(osg_SimulationTime); + +if (t_fact > 0.75) {shape_select +=0.75;} +else if (t_fact > 0.5) {shape_select +=0.5;} +else if (t_fact > 0.25) {shape_select +=0.25;} + + +domain_coords.x += shape_select; + +vec4 shapeTexel = texture2D(texture, domain_coords); + +color_base.rgb = mix(color_alt.rgb, color_base.rgb, length(shapeTexel.rgb)/1.73); + +if ((domain_coords.y < 0.1) || (domain_coords.y > 0.9)) {shapeTexel.a = 0.0;} +if ((domain_x < 0.1) || (domain_x > 0.9)) {shapeTexel.a = 0.0;} + +domainTexel.rgb *= color_base.rgb; + +vec4 birdTexel; +birdTexel.rgb = domainTexel.rgb * light_diffuse; +birdTexel.a = domainTexel.a * shapeTexel.a * transmission; + + +gl_FragColor = birdTexel; + + +} diff --git a/Shaders/birds-ALS.vert b/Shaders/birds-ALS.vert new file mode 100644 index 000000000..f5c764eba --- /dev/null +++ b/Shaders/birds-ALS.vert @@ -0,0 +1,48 @@ +// -*-C++-*- + +#version 120 + + + + +varying vec3 vertex; +varying vec3 relPos; +varying vec3 normal; + +uniform float osg_SimulationTime; + +void main() +{ + +vec4 ep = gl_ModelViewMatrixInverse * vec4(0.0,0.0,0.0,1.0); + + vec4 l = gl_ModelViewMatrixInverse * vec4(0.0,0.0,1.0,1.0); + vec3 u = normalize(ep.xyz - l.xyz); + + vec3 absu = abs(u); + vec3 r = normalize(vec3(-u.y, u.x, 0.0)); + vec3 w = cross(u, r); + +vertex = gl_Vertex.xyz; +relPos = vertex - ep.xyz; +normal = gl_NormalMatrix * gl_Normal; + + gl_Position = vec4(0.0, 0.0, 0.0, 1.0); + gl_Position.xyz = gl_Vertex.x * u; + gl_Position.xyz += gl_Vertex.y * r; + gl_Position.xyz += gl_Vertex.z * w; + + gl_Position = gl_ModelViewProjectionMatrix * gl_Position; + +//vec4 offset = gl_ModelViewProjectionMatrix * vec4 (0.05* osg_SimulationTime, 0.0, 0.0, 1.0); + +//gl_Position +=offset; + +//gl_Position = ftransform(); +gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0; + +gl_FrontColor = vec4 (1.0,1.0,1.0,1.0); +gl_BackColor = gl_FrontColor; +} + +