105 |
105 |
{
|
106 |
106 |
addEffect( EffectName.DEFORM,
|
107 |
107 |
|
108 |
|
"const vec3 ONE = vec3(1.0,1.0,1.0); \n"
|
109 |
|
+ "const float A = 0.5; \n"
|
110 |
|
+ "const float B = 0.2; \n"
|
111 |
|
+ "const float C = 5.0; \n"
|
|
108 |
"const vec3 ONE = vec3(1.0,1.0,1.0); \n"
|
|
109 |
+ "const float A = 0.5; \n"
|
|
110 |
+ "const float B = 0.2; \n"
|
|
111 |
+ "const float C = 5.0; \n"
|
112 |
112 |
|
113 |
|
+ "vec3 center = vUniforms[effect+1].yzw; \n"
|
114 |
|
+ "vec3 ps = center-v; \n"
|
115 |
|
+ "vec3 aPS = abs(ps); \n"
|
116 |
|
+ "vec3 maxps = u_objD + abs(center); \n"
|
117 |
|
+ "float d = degree_region(vUniforms[effect+2],ps); \n"
|
118 |
|
+ "vec3 force = vUniforms[effect].xyz * d; \n"
|
119 |
|
+ "vec3 aForce = abs(force); \n"
|
120 |
|
+ "float denom = dot(ps+(1.0-d)*force,ps); \n"
|
121 |
|
+ "float one_over_denom = 1.0/(denom-0.001*(sign(denom)-1.0)); \n"
|
122 |
|
+ "vec3 Aw = A*maxps; \n"
|
123 |
|
+ "vec3 quot = ps / maxps; \n"
|
124 |
|
+ "quot = quot*quot; \n" // ( (x/W)^2 , (y/H)^2 ) where x,y are distances from V to center
|
|
113 |
+ "vec3 center = vUniforms[effect+1].yzw; \n"
|
|
114 |
+ "vec3 ps = center-v; \n"
|
|
115 |
+ "vec3 aPS = abs(ps); \n"
|
|
116 |
+ "vec3 maxps = u_objD + abs(center); \n"
|
|
117 |
+ "float d = degree_region(vUniforms[effect+2],ps); \n"
|
|
118 |
+ "vec3 force = vUniforms[effect].xyz * d; \n"
|
|
119 |
+ "vec3 aForce = abs(force); \n"
|
|
120 |
+ "float denom = dot(ps+(1.0-d)*force,ps); \n"
|
|
121 |
+ "float one_over_denom = 1.0/(denom-0.001*(sign(denom)-1.0)); \n"
|
|
122 |
+ "vec3 Aw = A*maxps; \n"
|
|
123 |
+ "vec3 quot = ps / maxps; \n"
|
|
124 |
+ "quot = quot*quot; \n" // ( (x/W)^2 , (y/H)^2 ) where x,y are distances from V to center
|
125 |
125 |
|
126 |
|
+ "float denomV = 1.0 / (aForce.y + Aw.x); \n"
|
127 |
|
+ "float denomH = 1.0 / (aForce.x + Aw.y); \n"
|
|
126 |
+ "float denomV = 1.0 / (aForce.y + Aw.x); \n"
|
|
127 |
+ "float denomH = 1.0 / (aForce.x + Aw.y); \n"
|
128 |
128 |
|
129 |
|
+ "vec3 vertCorr= ONE - aPS / ( aForce+C*aPS + (ONE-sign(aForce)) ); \n" // avoid division by 0 when force and PS both are 0
|
|
129 |
+ "vec3 vertCorr= ONE - aPS / ( aForce+C*aPS + (ONE-sign(aForce)) ); \n" // avoid division by 0 when force and PS both are 0
|
130 |
130 |
|
131 |
|
+ "float mvXvert = -B * ps.x * aForce.y * (1.0-quot.y) * denomV; \n" // impact the vertical component of the force vector has on horizontal movement
|
132 |
|
+ "float mvYhorz = -B * ps.y * aForce.x * (1.0-quot.x) * denomH; \n" // impact the horizontal component of the force vector has on vertical movement
|
133 |
|
+ "float mvYvert = force.y * (1.0-quot.x*Aw.x*denomV) * vertCorr.y; \n" // impact the vertical component of the force vector has on vertical movement
|
134 |
|
+ "float mvXhorz = force.x * (1.0-quot.y*Aw.y*denomH) * vertCorr.x; \n" // impact the horizontal component of the force vector has on horizontal movement
|
|
131 |
+ "float mvXvert = -B * ps.x * aForce.y * (1.0-quot.y) * denomV; \n" // impact the vertical component of the force vector has on horizontal movement
|
|
132 |
+ "float mvYhorz = -B * ps.y * aForce.x * (1.0-quot.x) * denomH; \n" // impact the horizontal component of the force vector has on vertical movement
|
|
133 |
+ "float mvYvert = force.y * (1.0-quot.x*Aw.x*denomV) * vertCorr.y; \n" // impact the vertical component of the force vector has on vertical movement
|
|
134 |
+ "float mvXhorz = force.x * (1.0-quot.y*Aw.y*denomH) * vertCorr.x; \n" // impact the horizontal component of the force vector has on horizontal movement
|
135 |
135 |
|
136 |
|
+ "v.x += (mvXvert+mvXhorz); \n"
|
137 |
|
+ "v.y += (mvYvert+mvYhorz); \n"
|
|
136 |
+ "v.x += (mvXvert+mvXhorz); \n"
|
|
137 |
+ "v.y += (mvYvert+mvYhorz); \n"
|
138 |
138 |
|
139 |
|
+ "v.z += force.z*d*d*(3.0*d*d -8.0*d +6.0); \n" // thick bubble
|
|
139 |
+ "v.z += force.z*d*d*(3.0*d*d -8.0*d +6.0); \n" // thick bubble
|
140 |
140 |
+ "float b = -(12.0*force.z*d*(1.0-d)*(1.0-d)*(1.0-d))*one_over_denom; \n"
|
141 |
141 |
|
142 |
142 |
+ "n.xy += n.z*b*ps.xy;"
|
Add (simplified, approximated) shading to the Sink effect, i.e. move the normal vectors.