Add flutter effect for flags etc.
Signed-off-by: Vivian Meazza <vivian.meazza@lineone.net>
This commit is contained in:
parent
759c8ded5a
commit
b7960ee919
2 changed files with 240 additions and 0 deletions
161
Effects/flutter.eff
Normal file
161
Effects/flutter.eff
Normal file
|
@ -0,0 +1,161 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PropertyList>
|
||||
<name>Effects/flutter</name>
|
||||
<inherits-from>Effects/model-default</inherits-from>
|
||||
<parameters>
|
||||
<vertex-program-two-side type="bool">true</vertex-program-two-side>
|
||||
<material>
|
||||
<color-mode-uniform>1</color-mode-uniform>
|
||||
<!-- DIFFUSE -->
|
||||
</material>
|
||||
<shade-model>smooth</shade-model>
|
||||
<wind-speed>
|
||||
<!--<use>/environment/Vinson/rel-wind-speed-kts</use>-->
|
||||
<use>/environment/config/boundary/entry[0]/wind-speed-kt</use>
|
||||
</wind-speed>
|
||||
<offset>0.0</offset>
|
||||
<amplitude-factor>0.08</amplitude-factor>
|
||||
</parameters>
|
||||
<technique n="9">
|
||||
<predicate>
|
||||
<and>
|
||||
<property>/sim/rendering/shader-effects</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>
|
||||
<texture-unit>
|
||||
<!-- The texture unit is always active because the shaders expect
|
||||
that. -->
|
||||
<unit>0</unit>
|
||||
<!-- If there is a texture, the type in the derived effect
|
||||
will be "2d". -->
|
||||
<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>
|
||||
<texture-unit>
|
||||
<unit>9</unit>
|
||||
<type>noise</type>
|
||||
</texture-unit>
|
||||
<vertex-program-two-side>
|
||||
<use>vertex-program-two-side</use>
|
||||
</vertex-program-two-side>
|
||||
<program>
|
||||
<vertex-shader>Shaders/flutter.vert</vertex-shader>
|
||||
<fragment-shader>Shaders/default.frag</fragment-shader>
|
||||
</program>
|
||||
<!--<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>
|
||||
<uniform>
|
||||
<name>WindSpeed</name>
|
||||
<type>float</type>
|
||||
<value>
|
||||
<use>wind-speed</use>
|
||||
</value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>Offset</name>
|
||||
<type>float</type>
|
||||
<value>
|
||||
<use>offset</use>
|
||||
</value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>AmpFactor</name>
|
||||
<type>float</type>
|
||||
<value>
|
||||
<use>amplitude-factor</use>
|
||||
</value>
|
||||
</uniform>
|
||||
<uniform>
|
||||
<name>Noise</name>
|
||||
<type>sampler-3d</type>
|
||||
<value type="int">9</value>
|
||||
</uniform>
|
||||
</pass>
|
||||
</technique>
|
||||
|
||||
</PropertyList>
|
79
Shaders/flutter.vert
Normal file
79
Shaders/flutter.vert
Normal file
|
@ -0,0 +1,79 @@
|
|||
// -*-C++-*-
|
||||
|
||||
// Shader that uses OpenGL state values to do per-pixel lighting
|
||||
//
|
||||
// The only light used is gl_LightSource[0], which is assumed to be
|
||||
// directional.
|
||||
//
|
||||
// Diffuse colors come from the gl_Color, ambient from the material. This is
|
||||
// equivalent to osg::Material::DIFFUSE.
|
||||
|
||||
#define MODE_OFF 0
|
||||
#define MODE_DIFFUSE 1
|
||||
#define MODE_AMBIENT_AND_DIFFUSE 2
|
||||
|
||||
// The ambient term of the lighting equation that doesn't depend on
|
||||
// the surface normal is passed in gl_{Front,Back}Color. The alpha
|
||||
// component is set to 1 for front, 0 for back in order to work around
|
||||
// bugs with gl_FrontFacing in the fragment shader.
|
||||
varying vec4 diffuse_term;
|
||||
varying vec3 normal;
|
||||
varying float fogCoord;
|
||||
|
||||
uniform int colorMode;
|
||||
uniform float osg_SimulationTime;
|
||||
uniform float WindSpeed, Offset, AmpFactor;
|
||||
uniform sampler3D Noise;
|
||||
|
||||
void main()
|
||||
{
|
||||
// map noise vector
|
||||
vec4 noisevec = texture3D(Noise, gl_Vertex.xyz);
|
||||
|
||||
//waving effect
|
||||
float tsec = osg_SimulationTime;
|
||||
vec4 pos = gl_Vertex;
|
||||
vec4 oldpos = gl_Vertex;
|
||||
|
||||
float freq = (10 * WindSpeed) + 10;
|
||||
pos.y = sin((pos.x * 5.0 + tsec * freq )/5.0) * 0.5 ;
|
||||
pos.y += sin((pos.z * 5.0 + tsec * freq/2)/5.0) * 0.125 ;
|
||||
|
||||
pos.y *= pow(pos.x - Offset, 2.0) * AmpFactor;
|
||||
|
||||
gl_Position = gl_ModelViewProjectionMatrix * pos;
|
||||
|
||||
vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex;
|
||||
|
||||
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
|
||||
normal = gl_NormalMatrix * gl_Normal;
|
||||
vec4 ambient_color, diffuse_color;
|
||||
|
||||
if (colorMode == MODE_DIFFUSE) {
|
||||
diffuse_color = gl_Color;
|
||||
ambient_color = gl_FrontMaterial.ambient;
|
||||
} else if (colorMode == MODE_AMBIENT_AND_DIFFUSE) {
|
||||
diffuse_color = gl_Color;
|
||||
ambient_color = gl_Color;
|
||||
} else {
|
||||
diffuse_color = gl_FrontMaterial.diffuse;
|
||||
ambient_color = gl_FrontMaterial.ambient;
|
||||
}
|
||||
|
||||
diffuse_term = diffuse_color * gl_LightSource[0].diffuse;
|
||||
vec4 ambient_term = ambient_color * gl_LightSource[0].ambient;
|
||||
|
||||
// Super hack: if diffuse material alpha is less than 1, assume a
|
||||
// transparency animation is at work
|
||||
if (gl_FrontMaterial.diffuse.a < 1.0)
|
||||
diffuse_term.a = gl_FrontMaterial.diffuse.a;
|
||||
else
|
||||
diffuse_term.a = gl_Color.a;
|
||||
|
||||
// Another hack for supporting two-sided lighting without using
|
||||
// gl_FrontFacing in the fragment shader.
|
||||
gl_FrontColor.rgb = ambient_term.rgb; gl_FrontColor.a = 0.0;
|
||||
gl_BackColor.rgb = ambient_term.rgb; gl_FrontColor.a = 1.0;
|
||||
fogCoord = abs(ecPosition.z / ecPosition.w);
|
||||
|
||||
}
|
Loading…
Reference in a new issue