Revision cd174a64
Added by Leszek Koltunski over 8 years ago
src/main/res/raw/main_vertex_shader.glsl | ||
---|---|---|
146 | 146 |
////////////////////////////////////////////////////////////////////////////////////////////// |
147 | 147 |
// DEFORM EFFECT |
148 | 148 |
// |
149 |
// Deform the whole shape of the bitmap by force V
|
|
149 |
// Deform the whole shape of the Object by force V
|
|
150 | 150 |
// |
151 |
// If the point of application (Sx,Sy) is on the edge of the bitmap, then:
|
|
151 |
// If the point of application (Sx,Sy) is on the edge of the Object, then:
|
|
152 | 152 |
// a) ignore Vz |
153 |
// b) change shape of the whole bitmap in the following way:
|
|
154 |
// Suppose the upper-left corner of the bitmap rectangle is point L, upper-right - R, force vector V is applied to point M on the upper edge,
|
|
155 |
// length of the bitmap = w, height = h, |LM| = Wl, |MR| = Wr, force vector V=(Vx,Vy). Also let H = h/(h+Vy)
|
|
153 |
// b) change shape of the whole Object in the following way:
|
|
154 |
// Suppose the upper-left corner of the Object rectangle is point L, upper-right - R, force vector V is applied to point M on the upper edge,
|
|
155 |
// width of the Object = w, height = h, |LM| = Wl, |MR| = Wr, force vector V=(Vx,Vy). Also let H = h/(h+Vy)
|
|
156 | 156 |
// |
157 | 157 |
// Let now L' and R' be points such that vec(LL') = Wr/w * vec(V) and vec(RR') = Wl/w * vec(V) |
158 | 158 |
// now let Vl be a point on the line segment L --> M+vec(V) such that Vl(y) = L'(y) |
... | ... | |
165 | 165 |
// vec(Fl) = (Wr/w) * [ (Vx+Wl)-Wl*H, Vy ] = (Wr/w) * [ Wl*Vy / (h+Vy) + Vx, Vy ] |
166 | 166 |
// vec(Fr) = (Wl/w) * [ (Vx-Wr)+Wr*H, Vy ] = (Wl/w) * [-Wr*Vy / (h+Vy) + Vx, Vy ] |
167 | 167 |
// |
168 |
// Lets now denote M+vec(v) = M'. The line segment LMR gets distorted to the curve Fl-M'-Fr. Let's now arbitrarilly decide that:
|
|
168 |
// Lets now denote M+vec(V) = M'. The line segment LMR gets distorted to the curve Fl-M'-Fr. Let's now arbitrarilly decide that:
|
|
169 | 169 |
// a) at point Fl the curve has to be parallel to line LM' |
170 | 170 |
// b) at point M' - to line LR |
171 | 171 |
// c) at point Fr - to line M'R |
... | ... | |
188 | 188 |
// If we are dragging the top edge: |
189 | 189 |
// |
190 | 190 |
// Now point (x,u_objD.x) on the top edge will move by vector (X(t),Y(t)) where those functions are given by (*) and |
191 |
// t = x < dSx ? (u_objD.x+x)/(u_objD.x+dSx) : (u_objD.x-x)/(u_objD.x-dSx) |
|
191 |
// t = x < dSx ? (u_objD.x+x)/(u_objD.x+dSx) : (u_objD.x-x)/(u_objD.x-dSx) (this is 'vec2 time' below in the code)
|
|
192 | 192 |
// Any point (x,y) will move by vector (a*X(t),a*Y(t)) where a is (y+u_objD.y)/(2*u_objD.y) |
193 | 193 |
|
194 | 194 |
void deform(in int effect, inout vec4 v) |
195 | 195 |
{ |
196 |
vec2 p = vUniforms[effect+2].yz;
|
|
197 |
vec2 w = vUniforms[effect].xy; // w = vec(MM')
|
|
196 |
vec2 center = vUniforms[effect+2].yz;
|
|
197 |
vec2 force = vUniforms[effect].xy; // force = vec(MM')
|
|
198 | 198 |
vec2 vert_vec, horz_vec; |
199 |
vec2 signXY = sign(p-v.xy); |
|
200 |
vec2 time = (u_objD.xy+signXY*v.xy)/(u_objD.xy+signXY*p); |
|
201 |
vec2 factorV = vec2(0.5,0.5) + sign(p)*v.xy/(4.0*u_objD.xy); |
|
202 |
vec2 factorD = (u_objD.xy-signXY*p)/(2.0*u_objD.xy); |
|
203 |
vec2 vert_d = factorD.x*w; |
|
204 |
vec2 horz_d = factorD.y*w; |
|
205 |
vec2 corr = 0.33 / ( 1.0 + (4.0*u_objD.x*u_objD.x)/dot(w,w) ) * (p+w+signXY*u_objD.xy); // .x = the vector tangent to X(t) at Fl = 0.3*vec(LM') (or vec(RM') if signXY.x=-1). |
|
206 |
// .y = the vector tangent to X(t) at Fb = 0.3*vec(BM') (or vec(TM') if signXY.y=-1) |
|
207 |
// the scalar: make the length of the speed vectors at Fl and Fr be 0 when force vector 'w' is zero |
|
208 |
vert_vec.x = ( w.x-vert_d.x-corr.x )*time.x*time.x + corr.x*time.x + vert_d.x; |
|
209 |
horz_vec.y = (-w.y+horz_d.y+corr.y )*time.y*time.y - corr.y*time.y - horz_d.y; |
|
210 |
vert_vec.y = (-3.0*vert_d.y+2.0*w.y )*time.x*time.x*time.x + (-3.0*w.y+5.0*vert_d.y )*time.x*time.x - vert_d.y*time.x - vert_d.y; |
|
211 |
horz_vec.x = ( 3.0*horz_d.x-2.0*w.x )*time.y*time.y*time.y + ( 3.0*w.x-5.0*horz_d.x )*time.y*time.y + horz_d.x*time.y + horz_d.x; |
|
199 |
vec2 signXY = sign(center-v.xy); |
|
200 |
vec2 time = (u_objD.xy+signXY*v.xy)/(u_objD.xy+signXY*center); |
|
201 |
vec2 factorV = vec2(0.5,0.5) + (center*v.xy)/(4.0*u_objD.xy*u_objD.xy); |
|
202 |
vec2 factorD = (u_objD.xy-signXY*center)/(2.0*u_objD.xy); |
|
203 |
vec2 vert_d = factorD.x*force; |
|
204 |
vec2 horz_d = factorD.y*force; |
|
205 |
float dot = dot(force,force); |
|
206 |
vec2 corr = 0.33 * (center+force+signXY*u_objD.xy) * dot / ( dot + (4.0*u_objD.x*u_objD.x) ); // .x = the vector tangent to X(t) at Fl = 0.3*vec(LM') (or vec(RM') if signXY.x=-1). |
|
207 |
// .y = the vector tangent to X(t) at Fb = 0.3*vec(BM') (or vec(TM') if signXY.y=-1) |
|
208 |
// the scalar: make the length of the speed vectors at Fl and Fr be 0 when force vector 'force' is zero |
|
209 |
vert_vec.x = ( force.x-vert_d.x-corr.x )*time.x*time.x + corr.x*time.x + vert_d.x; |
|
210 |
horz_vec.y = (-force.y+horz_d.y+corr.y )*time.y*time.y - corr.y*time.y - horz_d.y; |
|
211 |
vert_vec.y = (-3.0*vert_d.y+2.0*force.y )*time.x*time.x*time.x + (-3.0*force.y+5.0*vert_d.y )*time.x*time.x - vert_d.y*time.x - vert_d.y; |
|
212 |
horz_vec.x = ( 3.0*horz_d.x-2.0*force.x )*time.y*time.y*time.y + ( 3.0*force.x-5.0*horz_d.x )*time.y*time.y + horz_d.x*time.y + horz_d.x; |
|
212 | 213 |
|
213 |
v.xy += (factorV.y*vert_vec + factorV.x*horz_vec);
|
|
214 |
v.xy += (factorV.y*vert_vec + factorV.x*horz_vec); |
|
214 | 215 |
} |
215 | 216 |
|
216 | 217 |
////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
Make the 'deform' effect continuous when 'center' point passes through (0,0) i.e. middle of the Object.