diff --git a/Effects/flutter.eff b/Effects/flutter.eff new file mode 100644 index 000000000..404eda994 --- /dev/null +++ b/Effects/flutter.eff @@ -0,0 +1,161 @@ + + + Effects/flutter + Effects/model-default + + true + + 1 + + + smooth + + + /environment/config/boundary/entry[0]/wind-speed-kt + + 0.0 + 0.08 + + + + + /sim/rendering/shader-effects + + + 2.0 + + + + GL_ARB_shader_objects + GL_ARB_shading_language_100 + GL_ARB_vertex_shader + GL_ARB_fragment_shader + + + + + + true + + + material/active + + + material/ambient + + + material/diffuse + + + material/specular + + + material/emissive + + + material/shininess + + + material/color-mode + + + + + blend/active + + + blend/source + + + blend/destination + + + + shade-model + + + cull-face + + + rendering-hint + + + + 0 + + + texture[0]/type + + + texture[0]/image + + + texture[0]/filter + + + texture[0]/wrap-s + + + texture[0]/wrap-t + + + + + 9 + noise + + + vertex-program-two-side + + + Shaders/flutter.vert + Shaders/default.frag + + + + colorMode + int + + material/color-mode-uniform + + + + WindSpeed + float + + wind-speed + + + + Offset + float + + offset + + + + AmpFactor + float + + amplitude-factor + + + + Noise + sampler-3d + 9 + + + + + diff --git a/Shaders/flutter.vert b/Shaders/flutter.vert new file mode 100644 index 000000000..640edd885 --- /dev/null +++ b/Shaders/flutter.vert @@ -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); + +}