Revision 30925500
Added by Leszek Koltunski over 9 years ago
| src/main/res/raw/main_vertex_shader.glsl | ||
|---|---|---|
| 236 | 236 |
// Solution: |
| 237 | 237 |
// 1. Decompose the V into two subcomponents, one parallel to SX and another perpendicular. |
| 238 | 238 |
// 2. Convince yourself (draw!) that the perpendicular component has no effect on normals. |
| 239 |
// 3. The parallel component changes the length of |SX| by the factor of a=(|SX|-|Vpar|)/|SX| (where the length can be negative depending on the direction) |
|
| 239 |
// 3. The parallel component changes the length of |SX| by the factor of a=(|SX|-|Vpar|)/|SX| (where the length |
|
| 240 |
// can be negative depending on the direction) |
|
| 240 | 241 |
// 4. that in turn leaves the x and y parts of the normal unchanged and multiplies the z component by a! |
| 241 | 242 |
// |
| 242 | 243 |
// |Vpar| = (u_dVx[i]*dx - u_dVy[i]*dy) / sqrt(ps_sq) = (Vx*dx-Vy*dy)/ sqrt(ps_sq) (-Vy because y is inverted) |
| ... | ... | |
| 258 | 259 |
// so finally -|PS|/f'(|PX|) = -ps_sq/ (6uz*d*(1-d)^2) |
| 259 | 260 |
// |
| 260 | 261 |
// Case 3: |
| 261 |
// f(t) = 3t^4-8t^3+6t^2 would be better as this safisfies f(0)=0, f'(0)=0, f'(1)=0, f(1)=1 and f(0.5)=0.7 and f'(t)= t(t-1)^2 >=0 for t>=0
|
|
| 262 |
// so this produces a fuller, thicker bubble! |
|
| 262 |
// f(t) = 3t^4-8t^3+6t^2 would be better as this safisfies f(0)=0, f'(0)=0, f'(1)=0, f(1)=1,
|
|
| 263 |
// f(0.5)=0.7 and f'(t)= t(t-1)^2 >=0 for t>=0 so this produces a fuller, thicker bubble!
|
|
| 263 | 264 |
// then -|PS|/f'(|PX|) = (-|PS|*|SX)) / (12uz*d*(d-1)^2) but |PS|*|SX| = ps_sq/(1-d) (see above!) |
| 264 | 265 |
// so finally -|PS|/f'(|PX|) = -ps_sq/ (12uz*d*(1-d)^3) |
| 265 | 266 |
// |
| ... | ... | |
| 269 | 270 |
// then the normal to g = f1+f2 is simply given by (f1x+f2x,f1y+f2y,1), i.e. if the third component is 1, then we can simply |
| 270 | 271 |
// add up the first and second components. |
| 271 | 272 |
// |
| 272 |
// Thus we actually want to compute N(v.x,v.y) = a*(-(dx/|PS|)*f'(|PX|), -(dy/|PS|)*f'(|PX|), 1) and keep adding the first two components.
|
|
| 273 |
// (a is the horizontal part) |
|
| 273 |
// Thus we actually want to compute N(v.x,v.y) = a*(-(dx/|PS|)*f'(|PX|), -(dy/|PS|)*f'(|PX|), 1) and keep adding |
|
| 274 |
// the first two components. (a is the horizontal part)
|
|
| 274 | 275 |
|
| 275 | 276 |
void distort(in int effect, inout vec4 v, inout vec4 n) |
| 276 | 277 |
{
|
| ... | ... | |
| 278 | 279 |
vec2 ps = point-v.xy; |
| 279 | 280 |
float d = degree(vUniforms[effect+1],point,ps); |
| 280 | 281 |
vec2 w = vec2(vUniforms[effect].x, -vUniforms[effect].y); |
| 281 |
float dt = dot(ps,ps); |
|
| 282 |
float uz = vUniforms[effect].z; // height of the bubble |
|
| 283 |
|
|
| 284 |
//v.z += uz*d; // cone |
|
| 285 |
//b = -(uz*(1.0-d)) / (dt + (1.0-d)*dot(w,ps) + (sign(dt)-1.0) ); // |
|
| 282 |
float uz = vUniforms[effect].z; // height of the bubble |
|
| 283 |
float denominator = dot(ps+(1.0-d)*w,ps); |
|
| 284 |
float one_over_denom = 1.0/(denominator+0.001*(1.0-sign(denominator))); // = denominator==0 ? 1000:1/denominator; |
|
| 285 |
|
|
| 286 |
//v.z += uz*d; // cone |
|
| 287 |
//b = -(uz*(1.0-d))*one_over_denom; // |
|
| 286 | 288 |
|
| 287 |
//v.z += uz*d*d*(3.0-2.0*d); // thin bubble
|
|
| 288 |
//b = -(6.0*uz*d*(1.0-d)*(1.0-d)) / (dt + (1.0-d)*dot(w,ps) + (sign(dt)-1.0) ); //
|
|
| 289 |
//v.z += uz*d*d*(3.0-2.0*d); // thin bubble |
|
| 290 |
//b = -(6.0*uz*d*(1.0-d)*(1.0-d))*one_over_denom; //
|
|
| 289 | 291 |
|
| 290 |
v.z += uz*d*d*(3.0*d*d -8.0*d +6.0); // thick bubble
|
|
| 291 |
float b = -(12.0*uz*d*(1.0-d)*(1.0-d)*(1.0-d)) / (dt + (1.0-d)*dot(w,ps) + (sign(dt)-1.0) ); // the last part - (sign-1) is to avoid b being a NaN when ps=(0,0)
|
|
| 292 |
v.z += uz*d*d*(3.0*d*d -8.0*d +6.0); // thick bubble |
|
| 293 |
float b = -(12.0*uz*d*(1.0-d)*(1.0-d)*(1.0-d))*one_over_denom; //
|
|
| 292 | 294 |
|
| 293 | 295 |
v.xy += d*w; |
| 294 | 296 |
n.xy += b*ps; |
Also available in: Unified diff
Fix for Bug #18: DISTORT effect: disappearing triangles