From 4b199cf04af83f59895d4d1e9a2d8443c1ec8e06 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Tue, 3 Apr 2012 09:36:14 -0700 Subject: started the flag material --- assets/images/us_flag.png | Bin 0 -> 9946 bytes assets/shaders/Flag.frag.glsl | 13 +++++++++++++ assets/shaders/Flag.vert.glsl | 29 +++++++++++++++++++++-------- 3 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 assets/images/us_flag.png create mode 100644 assets/shaders/Flag.frag.glsl (limited to 'assets') diff --git a/assets/images/us_flag.png b/assets/images/us_flag.png new file mode 100644 index 00000000..1545edc2 Binary files /dev/null and b/assets/images/us_flag.png differ diff --git a/assets/shaders/Flag.frag.glsl b/assets/shaders/Flag.frag.glsl new file mode 100644 index 00000000..79d4bec3 --- /dev/null +++ b/assets/shaders/Flag.frag.glsl @@ -0,0 +1,13 @@ +#ifdef GL_ES +precision highp float; +#endif + +uniform sampler2D u_tex0; + +varying vec2 v_uv; + +void main(void) +{ + vec3 col = texture2D(u_tex0, v_uv).xyz; + gl_FragColor = vec4(col,1.0); +} \ No newline at end of file diff --git a/assets/shaders/Flag.vert.glsl b/assets/shaders/Flag.vert.glsl index 7dc932a7..9da0ee1c 100644 --- a/assets/shaders/Flag.vert.glsl +++ b/assets/shaders/Flag.vert.glsl @@ -16,20 +16,33 @@ attribute vec2 texcoord; // scalar uniforms uniform float u_time; +uniform float u_waveWidth; +uniform float u_waveHeight; // matrix uniforms uniform mat4 u_mvMatrix; uniform mat4 u_projMatrix; uniform mat4 u_worldMatrix; +// varying variables +varying vec2 v_uv; + void main() { - float angle = (u_time%360)*2; - - a_pos.z = sin( a_pos.x + angle); - a_pos.z += sin( a_pos.y/2 + angle); - a_pos.z *= a_pos.x * 0.09; - gl_Position = u_projMatrix * u_mvMatrix * vec4(a_pos,1.0) ; - - gl_FragColor = v_color; + float pi = 3.14159; + float angle = mod(u_time, pi)*2.0; + + vec3 v = a_pos; + v_uv = texcoord; + + vec2 pos = texcoord; + float tmp = pos.x; pos.x = pos.y; pos.y = tmp; + pos.x = pos.x * 1.0*pi * u_waveWidth; + pos.y = pos.y * 1.0*pi * u_waveWidth; + + v.z = sin( pos.x + angle); + v.z += sin( pos.y/2.0 + angle); + v.z *= v.y * 0.09 * u_waveHeight; + + gl_Position = u_projMatrix * u_mvMatrix * vec4(v,1.0) ; } -- cgit v1.2.3