1
0
Fork 0

Improvements to flame effect

This commit is contained in:
Thorsten Renk 2015-05-22 10:51:54 +03:00
parent 44f8e5f672
commit b17cd267ef
3 changed files with 87 additions and 40 deletions

View file

@ -7,19 +7,29 @@
<texture n="0">
<type>white</type>
</texture>
<thrust_collimation>0.1</thrust_collimation>
<thrust_density>0.5</thrust_density>
<shock_frequency>0.5</shock_frequency>
<noise_strength>0.2</noise_strength>
<noise_scale>0.1</noise_scale>
<thrust_collimation type="float">0.1</thrust_collimation>
<thrust_density type="float">0.5</thrust_density>
<base_flame_density type="float">1.0</base_flame_density>
<shock_frequency type="float">0.5</shock_frequency>
<noise_strength type="float">0.2</noise_strength>
<noise_scale type="float">0.1</noise_scale>
<flame_color_low_r type="float">0.95</flame_color_low_r>
<flame_color_low_g type="float">0.55</flame_color_low_g>
<flame_color_low_b type="float">0.0</flame_color_low_b>
<flame_color_high_r type="float">1.0</flame_color_high_r>
<flame_color_high_g type="float">0.8</flame_color_high_g>
<flame_color_high_b type="float">0.3</flame_color_high_b>
<base_flame_r type="float">1.0</base_flame_r>
<base_flame_g type="float">0.8</base_flame_g>
<base_flame_b type="float">0.3</base_flame_b>
<use_shocks type="int">1</use_shocks>
<use_noise type="int">1</use_noise>
<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>
</parameters>
<technique n="4">
@ -95,6 +105,11 @@
<type>float</type>
<value><use>thrust_density</use></value>
</uniform>
<uniform>
<name>base_flame_density</name>
<type>float</type>
<value><use>base_flame_density</use></value>
</uniform>
<uniform>
<name>shock_frequency</name>
<type>float</type>
@ -140,6 +155,21 @@
<type>float</type>
<value><use>flame_color_high_b</use></value>
</uniform>
<uniform>
<name>base_flame_r</name>
<type>float</type>
<value><use>base_flame_r</use></value>
</uniform>
<uniform>
<name>base_flame_g</name>
<type>float</type>
<value><use>base_flame_g</use></value>
</uniform>
<uniform>
<name>base_flame_b</name>
<type>float</type>
<value><use>base_flame_b</use></value>
</uniform>
<uniform>

View file

@ -1,5 +1,6 @@
// -*-C++-*-
#version 120
varying vec3 vertex;
varying vec3 viewDir;
@ -7,6 +8,7 @@ varying vec3 viewDir;
uniform float osg_SimulationTime;
uniform float thrust_collimation;
uniform float thrust_density;
uniform float base_flame_density;
uniform float shock_frequency;
uniform float noise_strength;
uniform float noise_scale;
@ -19,56 +21,61 @@ uniform float flame_color_high_r;
uniform float flame_color_high_g;
uniform float flame_color_high_b;
uniform float base_flame_r;
uniform float base_flame_g;
uniform float base_flame_b;
uniform int use_shocks;
uniform int use_noise;
float Noise3D(in vec3 coord, in float wavelength);
float Noise2D(in vec2 coord, in float wavelength);
const int n_steps = 100;
const int n_steps = 15;
float spherical_smoothstep (in vec3 pos)
{
float noise = Noise3D(vec3(pos.x - osg_SimulationTime * 5.0 , pos.y, pos.z), 0.3);
float l = length(vec3 (pos.x/2.0, pos.y,pos.z) );
pos *=4.0;
return 10.0 * thrust_density * base_flame_density * (1.0 - smoothstep(0.1, 0.2, l));
pos.x *=0.5;
float d = length(pos);
return 3.0 * (1.0 - smoothstep(0.3, 0.7, d)) /float(n_steps)* (0.5 + 0.5 * noise);
}
float spherical_smoothstep1 (in vec3 pos)
{
pos.x *=0.2;
float d = length(pos);
return 1.0 * (1.0 - smoothstep(0.3, 0.7, d)) /float(n_steps);
}
float thrust_flame (in vec3 pos)
{
//float noise = Noise3D(vec3(pos.x - osg_SimulationTime * 20.0 , pos.y, pos.z), 0.3);
float noise = Noise2D(vec2(pos.x - osg_SimulationTime * 30.0 , length(pos.yz)), noise_scale);
float noise = 0.0;
float d = 1.0 - pos.x/2.5 ;
float radius = 0.2 + thrust_collimation * 1.4 * pow((pos.x+0.1),0.5);
float d_rad = length(pos.yz);
//float longFade = smoothstep(0.0, 5.0, pos.x) ;
float longFade = pos.x/5.0;
d *= (1.0 - smoothstep(0.125, radius, length(pos.yz))) * (1.0 - noise_strength + noise_strength* noise);
float density = 1.0 - longFade;
float radius = 0.2 + thrust_collimation * 1.2 * pow((pos.x+0.1),0.5);
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);
if (use_shocks == 1)
{
float shock = sin(pos.x * 20.0 * shock_frequency);
d += shock * shock * shock * shock * (1.0 - pos.x/2.5) * (1.0 - smoothstep(0.05, 0.1, length(pos.yz))) * (1.0 - smoothstep(0.0, 1.0, thrust_collimation));
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));
}
return 10.0 * thrust_density * d / (radius/0.2);
return 10.0 * thrust_density * density / (radius/0.2);
}
@ -76,14 +83,21 @@ return 10.0 * thrust_density * d / (radius/0.2);
void main()
{
float t_x = 2.0 * abs(vertex.x) / max(viewDir.x, 0.0001);
float t_y = 2.0 * abs(vertex.y) / max(viewDir.y, 0.0001);
float t_z = 2.0 * abs(vertex.z) / max(viewDir.z, 0.0001);
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;
float t_min = min(t_x, t_y);
t_min = min(t_min, t_z);
t_min = 5.0;
float dt = t_min / float(n_steps);
@ -98,11 +112,7 @@ float density2 = 0.0;
for (int i = 0; i < n_steps; i++)
{
pos = pos + step;
if ((pos.x > 5.0) || (pos.x <0.0)) {break;}
if ((pos.y > 1.0) || (pos.y <-1.0)) {break;}
if ((pos.z > 1.0) || (pos.z <-1.0)) {break;}
//density1 += spherical_smoothstep(pos);
//density2 += spherical_smoothstep1(pos);
density1 += spherical_smoothstep(pos) * dt;
density2 += thrust_flame(pos) * dt;
}
@ -110,13 +120,18 @@ for (int i = 0; i < n_steps; i++)
float density = density1 + density2;
density = clamp(density,0.0,1.0);
//density = clamp(density,0.0,1.0);
density = 1.0 - exp(-density);
density1 = 1.0 - exp(-density1);
density2 = 1.0 - exp(-density2);
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);
vec3 color = mix(flame_color_low, flame_color_high, density2+density1);
vec3 color = mix(flame_color_low, flame_color_high, density2);
color = mix(color, vec3(0.8, 1.0, 1.0), density1);
vec4 finalColor = vec4 (color.rgb, density);

View file

@ -1,5 +1,7 @@
// -*-C++-*-
#version 120
varying vec3 vertex;
varying vec3 viewDir;