I initially thought of a Script/Module that SolarLune once made, though my second Thought is this one, and I would probably prefer it...
Code:
# Blender Game Engine 2.55 Resource Kit: Energy Wave
# Shader by Martins Uptitis and Mike Pan
#
# The GLSL vertex shader is responsible for
# animated displacement of the wave
# The GLSL fragment shader is responsible for
# the coloring
# Run the game,
# then click anywhere on the screen :)
from bge import logic
cont = logic.getCurrentController()
own = cont.owner
VertexShader = """
uniform sampler2D noiseMap;
uniform float timer;
varying vec3 normal, lightDir, eyeVec;
#define amplitude 0.01
#define speed 1.0
void main()
{
//get the first UV layout
gl_TexCoord[0] = gl_MultiTexCoord0;
// pass lighting information to fragment shader
normal = gl_NormalMatrix * gl_Normal;
vec3 vVertex = vec3(gl_ModelViewMatrix * gl_Vertex);
eyeVec = -vVertex;
// deform
vec4 v = gl_Vertex;
v.z = sin(timer*speed+v.x*0.5+v.y*1.0)*0.3+v.z*amplitude;
v.z += texture2D(noiseMap, gl_TexCoord[0].st+timer*(0.01*speed)).r*0.3;
gl_Position = gl_ModelViewProjectionMatrix * v;
}
"""
FragmentShader = """
uniform sampler2D noiseMap;
uniform float timer;
varying vec3 normal, eyeVec;
void main(void)
{
vec3 N = normalize(normal);
vec3 E = normalize(eyeVec);
float fresnelTerm = pow( max(1.0-dot(N,E), 0.0), 2.0);
vec3 color1 = gl_FrontMaterial.diffuse.rgb;
vec3 color2 = gl_FrontMaterial.specular.rgb;
gl_FragColor.rgb = mix(color1 ,color2 ,fresnelTerm);
gl_FragColor.a = fresnelTerm*2.0;
}
"""
mesh = own.meshes[0]
for mat in mesh.materials:
shader = mat.getShader()
if shader != None:
if not shader.isValid():
shader.setSource(VertexShader, FragmentShader, 1)
shader.setSampler('noiseMap',0)
shader.setUniform1f('timer',own["timer"])
Apply this to an Object like you would apply a Python Script. It will deform your Mesh into a moving Wave Function.
Look at the bold-italic Line: It is the Function itself. Play around with that Function, maybe you get an adequate Breakin' Wave?
Bookmarks