2015-05-21 08:28:21 +00:00
|
|
|
// -*-C++-*-
|
|
|
|
|
2015-05-22 07:51:54 +00:00
|
|
|
#version 120
|
2015-05-21 08:28:21 +00:00
|
|
|
|
|
|
|
varying vec3 vertex;
|
|
|
|
varying vec3 viewDir;
|
|
|
|
|
|
|
|
uniform float osg_SimulationTime;
|
|
|
|
uniform float thrust_collimation;
|
|
|
|
uniform float thrust_density;
|
2015-05-22 07:51:54 +00:00
|
|
|
uniform float base_flame_density;
|
2015-05-21 08:28:21 +00:00
|
|
|
uniform float shock_frequency;
|
|
|
|
uniform float noise_strength;
|
|
|
|
uniform float noise_scale;
|
|
|
|
|
|
|
|
uniform float flame_color_low_r;
|
|
|
|
uniform float flame_color_low_g;
|
|
|
|
uniform float flame_color_low_b;
|
|
|
|
|
|
|
|
uniform float flame_color_high_r;
|
|
|
|
uniform float flame_color_high_g;
|
|
|
|
uniform float flame_color_high_b;
|
|
|
|
|
2015-05-22 07:51:54 +00:00
|
|
|
uniform float base_flame_r;
|
|
|
|
uniform float base_flame_g;
|
|
|
|
uniform float base_flame_b;
|
|
|
|
|
2015-05-21 08:28:21 +00:00
|
|
|
uniform int use_shocks;
|
|
|
|
uniform int use_noise;
|
|
|
|
|
|
|
|
float Noise3D(in vec3 coord, in float wavelength);
|
|
|
|
float Noise2D(in vec2 coord, in float wavelength);
|
|
|
|
|
2015-05-22 07:51:54 +00:00
|
|
|
const int n_steps = 15;
|
2015-05-21 08:28:21 +00:00
|
|
|
|
|
|
|
float spherical_smoothstep (in vec3 pos)
|
|
|
|
{
|
|
|
|
|
2015-05-22 07:51:54 +00:00
|
|
|
float l = length(vec3 (pos.x/2.0, pos.y,pos.z) );
|
2015-05-21 08:28:21 +00:00
|
|
|
|
2015-05-22 07:51:54 +00:00
|
|
|
return 10.0 * thrust_density * base_flame_density * (1.0 - smoothstep(0.1, 0.2, l));
|
2015-05-21 08:28:21 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float thrust_flame (in vec3 pos)
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
//float noise = Noise3D(vec3(pos.x - osg_SimulationTime * 20.0 , pos.y, pos.z), 0.3);
|
2015-05-22 07:51:54 +00:00
|
|
|
float noise = 0.0;
|
|
|
|
|
|
|
|
float d_rad = length(pos.yz);
|
|
|
|
//float longFade = smoothstep(0.0, 5.0, pos.x) ;
|
|
|
|
float longFade = pos.x/5.0;
|
2015-05-21 08:28:21 +00:00
|
|
|
|
2015-05-22 07:51:54 +00:00
|
|
|
float density = 1.0 - longFade;
|
|
|
|
float radius = 0.2 + thrust_collimation * 1.2 * pow((pos.x+0.1),0.5);
|
2015-05-21 08:28:21 +00:00
|
|
|
|
2015-05-22 07:51:54 +00:00
|
|
|
if (d_rad > radius) {return 0.0;}
|
|
|
|
|
|
|
|
|
|
|
|
if (use_noise ==1)
|
|
|
|
{
|
|
|
|
noise = Noise2D(vec2(pos.x - osg_SimulationTime * 30.0 , d_rad), noise_scale);
|
|
|
|
}
|
|
|
|
|
|
|
|
density *= (1.0 - smoothstep(0.125, radius, d_rad)) * (1.0 - noise_strength + noise_strength* noise);
|
2015-05-21 08:28:21 +00:00
|
|
|
|
|
|
|
if (use_shocks == 1)
|
|
|
|
{
|
2015-05-22 07:51:54 +00:00
|
|
|
float shock = sin(pos.x * 10.0 * shock_frequency);
|
|
|
|
density += shock * shock * shock * shock * (1.0 - longFade) * (1.0 - smoothstep(0.05, 0.1, d_rad)) * (1.0 - smoothstep(0.0, 1.0, thrust_collimation));
|
2015-05-21 08:28:21 +00:00
|
|
|
}
|
|
|
|
|
2015-05-22 07:51:54 +00:00
|
|
|
|
|
|
|
return 10.0 * thrust_density * density / (radius/0.2);
|
2015-05-21 08:28:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
|
|
|
|
2015-05-22 07:51:54 +00:00
|
|
|
vec3 vDir = normalize(viewDir);
|
|
|
|
|
|
|
|
float x_E, y_E, z_E;
|
|
|
|
|
|
|
|
if (vDir.x > 0.0) {x_E = 5.0;} else {x_E = 0.0;}
|
|
|
|
if (vDir.y > 0.0) {y_E = 1.0;} else {y_E = -1.0;}
|
|
|
|
if (vDir.z > 0.0) {z_E = 1.0;} else {z_E = -1.0;}
|
|
|
|
|
|
|
|
float t_x = (x_E - vertex.x) / vDir.x;
|
|
|
|
float t_y = (y_E - vertex.y) / vDir.y;
|
|
|
|
float t_z = (z_E - vertex.z) / vDir.z;
|
2015-05-21 08:28:21 +00:00
|
|
|
|
|
|
|
float t_min = min(t_x, t_y);
|
|
|
|
t_min = min(t_min, t_z);
|
|
|
|
|
|
|
|
|
|
|
|
float dt = t_min / float(n_steps);
|
|
|
|
|
|
|
|
vec3 step = viewDir * dt;
|
|
|
|
vec3 pos = vertex;
|
|
|
|
|
|
|
|
float density1 = 0.0;
|
|
|
|
float density2 = 0.0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < n_steps; i++)
|
|
|
|
{
|
|
|
|
pos = pos + step;
|
2015-05-22 07:51:54 +00:00
|
|
|
density1 += spherical_smoothstep(pos) * dt;
|
2015-05-21 08:28:21 +00:00
|
|
|
density2 += thrust_flame(pos) * dt;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float density = density1 + density2;
|
2015-05-22 07:51:54 +00:00
|
|
|
//density = clamp(density,0.0,1.0);
|
|
|
|
density = 1.0 - exp(-density);
|
|
|
|
|
|
|
|
density1 = 1.0 - exp(-density1);
|
|
|
|
density2 = 1.0 - exp(-density2);
|
2015-05-21 08:28:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
vec3 flame_color_low = vec3 (flame_color_low_r, flame_color_low_g, flame_color_low_b);
|
|
|
|
vec3 flame_color_high = vec3 (flame_color_high_r, flame_color_high_g, flame_color_high_b);
|
|
|
|
|
2015-05-22 07:51:54 +00:00
|
|
|
vec3 color = mix(flame_color_low, flame_color_high, density2);
|
|
|
|
color = mix(color, vec3(0.8, 1.0, 1.0), density1);
|
2015-05-21 08:28:21 +00:00
|
|
|
|
|
|
|
vec4 finalColor = vec4 (color.rgb, density);
|
|
|
|
|
|
|
|
gl_FragColor = finalColor;
|
|
|
|
}
|