1
0
Fork 0

ALS bird shader

This commit is contained in:
Thorsten Renk 2016-04-30 21:27:28 +03:00
parent fc868d5d0b
commit 94c96a29c7
11 changed files with 589 additions and 0 deletions

166
Effects/birdswarm.eff Normal file
View file

@ -0,0 +1,166 @@
<?xml version="1.0" encoding="utf-8"?>
<PropertyList>
<name>Effects/birdswarm</name>
<parameters>
<texture n="0">
<image>Models/Effects/birds_in_flight.png</image>
<type>2d</type>
<filter>linear-mipmap-linear</filter>
<wrap-s>repeat</wrap-s>
<wrap-t>repeat</wrap-t>
<internal-format>normalized</internal-format>
</texture>
<color_base_r type="float">0.9</color_base_r>
<color_base_g type="float">0.8</color_base_g>
<color_base_b type="float">0.82</color_base_b>
<color_alt_r type="float">0.7</color_alt_r>
<color_alt_g type="float">0.3</color_alt_g>
<color_alt_b type="float">0.25</color_alt_b>
<visibility><use>/environment/ground-visibility-m</use></visibility>
<avisibility><use>/environment/visibility-m</use></avisibility>
<lthickness><use>/environment/ground-haze-thickness-m</use></lthickness>
<terrain_alt><use>/environment/mean-terrain-elevation-m</use></terrain_alt>
<eye_alt><use>/sim/rendering/eye-altitude-m</use></eye_alt>
<terminator><use>/environment/terminator-relative-position-m</use></terminator>
<scattering><use>/rendering/scene/scattering</use></scattering>
</parameters>
<technique n="4">
<predicate>
<and>
<property>/sim/rendering/shaders/skydome</property>
<or>
<less-equal>
<value type="float">2.0</value>
<glversion/>
</less-equal>
<and>
<extension-supported>GL_ARB_shader_objects</extension-supported>
<extension-supported>GL_ARB_shading_language_100</extension-supported>
<extension-supported>GL_ARB_vertex_shader</extension-supported>
<extension-supported>GL_ARB_fragment_shader</extension-supported>
</and>
</or>
</and>
</predicate>
<pass>
<lighting>true</lighting>
<material>
<active><use>material/active</use></active>
<ambient><use>material/ambient</use></ambient>
<diffuse><use>material/diffuse</use></diffuse>
<specular><use>material/specular</use></specular>
<emissive><use>material/emissive</use></emissive>
<shininess><use>material/shininess</use></shininess>
<color-mode><use>material/color-mode</use></color-mode>
</material>
<blend>
<active><use>blend/active</use></active>
<source><use>blend/source</use></source>
<destination><use>blend/destination</use></destination>
</blend>
<shade-model><use>shade-model</use></shade-model>
<cull-face><use>cull-face</use></cull-face>
<rendering-hint><use>rendering-hint</use></rendering-hint>
<render-bin>
<bin-number>111</bin-number>
<bin-name>DepthSortedBin</bin-name>
</render-bin>
<texture-unit>
<unit>0</unit>
<image><use>texture[0]/image</use></image>
<type><use>texture[0]/type</use></type>
<filter><use>texture[0]/filter</use></filter>
<wrap-s><use>texture[0]/wrap-s</use></wrap-s>
<wrap-t><use>texture[0]/wrap-t</use></wrap-t>
<internal-format><use>texture[0]/internal-format</use></internal-format>
</texture-unit>
<depth>
<write-mask>false</write-mask>
</depth>
<vertex-program-two-side>false</vertex-program-two-side>
<program>
<vertex-shader>Shaders/birds-ALS.vert</vertex-shader>
<fragment-shader>Shaders/birds-ALS.frag</fragment-shader>
<fragment-shader>Shaders/noise.frag</fragment-shader>
<fragment-shader>Shaders/hazes.frag</fragment-shader>
</program>
<uniform>
<name>color_base_r</name>
<type>float</type>
<value><use>color_base_r</use></value>
</uniform>
<uniform>
<name>color_base_g</name>
<type>float</type>
<value><use>color_base_g</use></value>
</uniform>
<uniform>
<name>color_base_b</name>
<type>float</type>
<value><use>color_base_b</use></value>
</uniform>
<uniform>
<name>color_alt_r</name>
<type>float</type>
<value><use>color_alt_r</use></value>
</uniform>
<uniform>
<name>color_alt_g</name>
<type>float</type>
<value><use>color_alt_g</use></value>
</uniform>
<uniform>
<name>color_alt_b</name>
<type>float</type>
<value><use>color_alt_b</use></value>
</uniform>
<uniform>
<name>visibility</name>
<type>float</type>
<value><use>visibility</use></value>
</uniform>
<uniform>
<name>avisibility</name>
<type>float</type>
<value><use>avisibility</use></value>
</uniform>
<uniform>
<name>hazeLayerAltitude</name>
<type>float</type>
<value><use>lthickness</use></value>
</uniform>
<uniform>
<name>scattering</name>
<type>float</type>
<value><use>scattering</use></value>
</uniform>
<uniform>
<name>eye_alt</name>
<type>float</type>
<value><use>eye_alt</use></value>
</uniform>
<uniform>
<name>terminator</name>
<type>float</type>
<value><use>terminator</use></value>
</uniform>
<uniform>
<name>texture</name>
<type>sampler-2d</type>
<value type="int">0</value>
</uniform>
<uniform>
<name>texture</name>
<type>sampler-2d</type>
<value type="int">0</value>
</uniform>
</pass>
</technique>
</PropertyList>

View file

@ -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

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

View file

@ -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

View file

@ -0,0 +1,22 @@
<?xml version="1.0"?>
<PropertyList>
<model>
<path>birdswarm1.xml</path>
</model>
<model>
<path>birdswarm2.xml</path>
</model>
<model>
<path>birdswarm3.xml</path>
</model>
<model>
<path>birdswarm4.xml</path>
</model>
</PropertyList>

View file

@ -0,0 +1,25 @@
<?xml version="1.0"?>
<PropertyList>
<path>birds.ac</path>
<offsets>
<x-m> 0 </x-m>
<y-m> 0 </y-m>
<z-m> 200.0 </z-m>
</offsets>
<animation>
<object-name>birds1</object-name>
<type>scale</type>
<x-offset>50.0</x-offset>
<y-offset>50.0</y-offset>
<z-offset>50.0</z-offset>
</animation>
<effect>
<inherits-from>Effects/birdswarm</inherits-from>
<object-name>birds1</object-name>
</effect>
</PropertyList>

View file

@ -0,0 +1,28 @@
<?xml version="1.0"?>
<PropertyList>
<path>birds.ac</path>
<offsets>
<x-m> 40 </x-m>
<y-m> 20 </y-m>
<z-m> 200.0 </z-m>
</offsets>
<animation>
<object-name>birds1</object-name>
<type>scale</type>
<x-offset>50.0</x-offset>
<y-offset>50.0</y-offset>
<z-offset>50.0</z-offset>
</animation>
<effect>
<inherits-from>Effects/birdswarm</inherits-from>
<object-name>birds1</object-name>
</effect>
</PropertyList>

View file

@ -0,0 +1,25 @@
<?xml version="1.0"?>
<PropertyList>
<path>birds.ac</path>
<offsets>
<x-m> 60 </x-m>
<y-m> 5 </y-m>
<z-m> 190.0 </z-m>
</offsets>
<animation>
<object-name>birds1</object-name>
<type>scale</type>
<x-offset>50.0</x-offset>
<y-offset>50.0</y-offset>
<z-offset>50.0</z-offset>
</animation>
<effect>
<inherits-from>Effects/birdswarm</inherits-from>
<object-name>birds1</object-name>
</effect>
</PropertyList>

View file

@ -0,0 +1,25 @@
<?xml version="1.0"?>
<PropertyList>
<path>birds.ac</path>
<offsets>
<x-m> 85 </x-m>
<y-m> -30 </y-m>
<z-m> 210.0 </z-m>
</offsets>
<animation>
<object-name>birds1</object-name>
<type>scale</type>
<x-offset>50.0</x-offset>
<y-offset>50.0</y-offset>
<z-offset>50.0</z-offset>
</animation>
<effect>
<inherits-from>Effects/birdswarm</inherits-from>
<object-name>birds1</object-name>
</effect>
</PropertyList>

206
Shaders/birds-ALS.frag Normal file
View file

@ -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;
}

48
Shaders/birds-ALS.vert Normal file
View file

@ -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;
}