opengl es - 2D topdown Water Ripple Effect (Fragment Shader) -


so here's code found: ripplesprite.cpp

void rippleeffectsprite::update(float delta) { //called per frame updaterippleparams(); // todo: improve float ripplespeed = 0.25f; float maxrippledistance = 1; m_rippledistance += ripplespeed * delta; m_ripplerange = (1 - m_rippledistance / maxrippledistance) * 0.02f;  if (m_rippledistance > maxrippledistance) {     updaterippleparams();     unscheduleupdate(); //stop updating     } }  void rippleeffectsprite::updaterippleparams() { getglprogramstate()->setuniformfloat("u_rippledistance", m_rippledistance); getglprogramstate()->setuniformfloat("u_ripplerange", m_ripplerange); } 

fragment shader

varying vec4 v_fragmentcolor;  varying vec2 v_texcoord;  uniform float u_rippledistance; uniform float u_ripplerange;  float waveheight(vec2 p) {     float ampfactor = 2;     float distfactor = 2;     float dist = length(p);     float delta = abs(u_rippledistance - dist);     if (delta <= u_ripplerange) {         return cos((u_rippledistance - dist) * distfactor) * (u_ripplerange - delta) * ampfactor;     }     else {         return 0;     } }  void main() {     vec2 p = v_texcoord - vec2(0.5, 0.5);     vec2 normal = normalize(p);     // offset texcoord along dist direction     vec2 v_texcoord2 = v_texcoord + normal * waveheight(p);      gl_fragcolor = texture2d(cc_texture0, v_texcoord2) * v_fragmentcolor; } 

now i'll try best describe in english, when run creates small circle (well not circle, more oval) @ middle of sprite, expands outward, textures below distorted bit, wave. i've been reading stuff shaders week , understand how work, don't understand algorithm, can explain me how created oval , made 'evenly',slowly expand?

here's link of tutorial: http://www.cocos.com/doc/tutorial/show?id=2121


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -