1
0
Fork 0

Procedural thruster flames, work in progress

This commit is contained in:
Thorsten Renk 2015-05-21 11:28:21 +03:00
parent 5b6a913b80
commit 44f8e5f672
4 changed files with 375 additions and 0 deletions

View file

@ -0,0 +1,61 @@
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.5000
MATERIAL "Material" rgb 0.8000 0.8000 0.8000 amb 1.0000 1.0000 1.0000 emis 0.0000 0.0000 0.0000 spec 0.5000 0.5000 0.5000 shi 50 trans 0.5000
OBJECT world
name "Blender_export__cube.ac"
kids 1
OBJECT poly
name "Bounding_box"
numvert 8
5.0 -1.0 -1.0
5.0 -1.0 1.0
0.0 -1.0 1.0
0.0 -1.0 -1.0
5.0 1.0 -1.0
5.0 1.0 1.0
0.0 1.0 1.0
0.0 1.0 -1.0
numsurf 6
SURF 0X20
mat 1
refs 4
0 0 0
1 0 0
2 0 0
3 0 0
SURF 0X20
mat 1
refs 4
4 0 0
7 0 0
6 0 0
5 0 0
SURF 0X20
mat 1
refs 4
0 0 0
4 0 0
5 0 0
1 0 0
SURF 0X20
mat 1
refs 4
1 0 0
5 0 0
6 0 0
2 0 0
SURF 0X20
mat 1
refs 4
2 0 0
6 0 0
7 0 0
3 0 0
SURF 0X20
mat 1
refs 4
4 0 0
0 0 0
3 0 0
7 0 0
kids 0

171
Effects/thrust-flame.eff Normal file
View file

@ -0,0 +1,171 @@
<?xml version="1.0" encoding="utf-8"?>
<PropertyList>
<name>Effects/thrust-flame</name>
<parameters>
<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>
<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>
<use_shocks type="int">1</use_shocks>
<use_noise type="int">1</use_noise>
</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>
<!-- The texture unit is always active because the shaders expect
that. -->
<unit>0</unit>
<active><use>texture[0]/active</use></active>
<type><use>texture[0]/type</use></type>
<image><use>texture[0]/image</use></image>
<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/thrustflame-ALS.vert</vertex-shader>
<fragment-shader>Shaders/thrustflame-ALS.frag</fragment-shader>
<fragment-shader>Shaders/noise.frag</fragment-shader>
</program>
<uniform>
<name>thrust_collimation</name>
<type>float</type>
<value><use>thrust_collimation</use></value>
</uniform>
<uniform>
<name>thrust_density</name>
<type>float</type>
<value><use>thrust_density</use></value>
</uniform>
<uniform>
<name>shock_frequency</name>
<type>float</type>
<value><use>shock_frequency</use></value>
</uniform>
<uniform>
<name>noise_strength</name>
<type>float</type>
<value><use>noise_strength</use></value>
</uniform>
<uniform>
<name>noise_scale</name>
<type>float</type>
<value><use>noise_scale</use></value>
</uniform>
<uniform>
<name>flame_color_low_r</name>
<type>float</type>
<value><use>flame_color_low_r</use></value>
</uniform>
<uniform>
<name>flame_color_low_g</name>
<type>float</type>
<value><use>flame_color_low_g</use></value>
</uniform>
<uniform>
<name>flame_color_low_b</name>
<type>float</type>
<value><use>flame_color_low_b</use></value>
</uniform>
<uniform>
<name>flame_color_high_r</name>
<type>float</type>
<value><use>flame_color_high_r</use></value>
</uniform>
<uniform>
<name>flame_color_high_g</name>
<type>float</type>
<value><use>flame_color_high_g</use></value>
</uniform>
<uniform>
<name>flame_color_high_b</name>
<type>float</type>
<value><use>flame_color_high_b</use></value>
</uniform>
<uniform>
<name>use_shocks</name>
<type>int</type>
<value><use>use_shocks</use></value>
</uniform>
<uniform>
<name>use_noise</name>
<type>int</type>
<value><use>use_noise</use></value>
</uniform>
<uniform>
<name>texture</name>
<type>sampler-2d</type>
<value type="int">0</value>
</uniform>
<uniform>
<name>colorMode</name>
<type>int</type>
<value><use>material/color-mode-uniform</use></value>
</uniform>
</pass>
</technique>
</PropertyList>

View file

@ -0,0 +1,124 @@
// -*-C++-*-
varying vec3 vertex;
varying vec3 viewDir;
uniform float osg_SimulationTime;
uniform float thrust_collimation;
uniform float thrust_density;
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;
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;
float spherical_smoothstep (in vec3 pos)
{
float noise = Noise3D(vec3(pos.x - osg_SimulationTime * 5.0 , pos.y, pos.z), 0.3);
pos *=4.0;
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 d = 1.0 - pos.x/2.5 ;
float radius = 0.2 + thrust_collimation * 1.4 * pow((pos.x+0.1),0.5);
d *= (1.0 - smoothstep(0.125, radius, length(pos.yz))) * (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));
}
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);
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);
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;
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);
density2 += thrust_flame(pos) * dt;
}
float density = density1 + density2;
density = clamp(density,0.0,1.0);
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);
vec4 finalColor = vec4 (color.rgb, density);
gl_FragColor = finalColor;
}

View file

@ -0,0 +1,19 @@
// -*-C++-*-
varying vec3 vertex;
varying vec3 viewDir;
void main()
{
vec4 ep = gl_ModelViewMatrixInverse * vec4(0.0,0.0,0.0,1.0);
vertex = gl_Vertex.xyz;
viewDir = normalize(vertex - ep.xyz);
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;
}