Project

General

Profile

« Previous | Next » 

Revision f6cac1f6

Added by Leszek Koltunski over 7 years ago

rearrange comments

View differences:

src/main/res/raw/main_vertex_shader.glsl
17 17
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                       //
18 18
//////////////////////////////////////////////////////////////////////////////////////////////
19 19

  
20
uniform vec3 u_objD;                      // half of object width x half of object height X half the depth;
21
                                          // point (0,0,0) is the center of the object
20
uniform vec3 u_objD;                 // half of object width x half of object height X half the depth;
21
                                     // point (0,0,0) is the center of the object
22 22

  
23
uniform float u_Depth;                    // max absolute value of v.z ; beyond that the vertex would be culled by the near or far planes.
24
                                          // I read OpenGL ES has a built-in uniform variable gl_DepthRange.near = n, 
25
                                          // .far = f, .diff = f-n so maybe u_Depth is redundant
26
                                          // Update: this struct is only available in fragment shaders
23
uniform float u_Depth;               // max absolute value of v.z ; beyond that the vertex would be culled by the near or far planes.
24
                                     // I read OpenGL ES has a built-in uniform variable gl_DepthRange.near = n,
25
                                     // .far = f, .diff = f-n so maybe u_Depth is redundant
26
                                     // Update: this struct is only available in fragment shaders
27 27
                                
28
uniform mat4 u_MVPMatrix;                 // A constant representing the combined model/view/projection matrix.      		       
29
uniform mat4 u_MVMatrix;                  // A constant representing the combined model/view matrix.       		
28
uniform mat4 u_MVPMatrix;            // A constant representing the combined model/view/projection matrix.
29
uniform mat4 u_MVMatrix;             // A constant representing the combined model/view matrix.
30 30
		 
31
attribute vec3 a_Position;                // Per-vertex position information we will pass in.   				
32
attribute vec3 a_Normal;                  // Per-vertex normal information we will pass in.
33
attribute vec2 a_TexCoordinate;           // Per-vertex texture coordinate information we will pass in. 		
31
attribute vec3 a_Position;           // Per-vertex position information we will pass in.
32
attribute vec3 a_Normal;             // Per-vertex normal information we will pass in.
33
attribute vec2 a_TexCoordinate;      // Per-vertex texture coordinate information we will pass in.
34 34
		  
35
varying vec3 v_Position;                  //      		
36
varying vec3 v_Normal;                    //
37
varying vec2 v_TexCoordinate;             //  		
35
varying vec3 v_Position;             //
36
varying vec3 v_Normal;               //
37
varying vec2 v_TexCoordinate;        //
38 38

  
39
uniform int vNumEffects;                  // total number of vertex effects
39
uniform int vNumEffects;             // total number of vertex effects
40 40

  
41 41
#if NUM_VERTEX>0
42
uniform int vType[NUM_VERTEX];            // their types.
43
uniform vec4 vUniforms[3*NUM_VERTEX];     // i-th effect is 3 consecutive vec4's: [3*i], [3*i+1], [3*i+2].
44
                                          // The first vec4 is the Interpolated values,
45
                                          // next is half cache half Center, the third -  the Region.
42
uniform int vType[NUM_VERTEX];       // their types.
43
uniform vec4 vUniforms[3*NUM_VERTEX];// i-th effect is 3 consecutive vec4's: [3*i], [3*i+1], [3*i+2].
44
                                     // The first vec4 is the Interpolated values,
45
                                     // next is half cache half Center, the third -  the Region.
46 46
#endif
47 47

  
48 48
#if NUM_VERTEX>0
......
163 163
//
164 164
// Deform the whole shape of the Object by force V
165 165
// 
166
// If the point of application (Sx,Sy) is on the edge of the Object, then:
166
// If the point of application (Sx,Sy) is on the upper edge of the Object, then:
167 167
// a) ignore Vz
168 168
// b) change shape of the whole Object in the following way:
169
//    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,
170
//    width of the Object = w, height = h, |LM| = Wl, |MR| = Wr, force vector V=(Vx,Vy). Also let H = h/(h+Vy)
169
//    Suppose the upper-left corner of the Object rectangle is point L, upper-right - R, force vector V
170
//    is applied to point M on the upper edge, width of the Object = w, height = h, |LM| = Wl, |MR| = Wr,
171
//    force vector V=(Vx,Vy). Also let H = h/(h+Vy)
171 172
//
172 173
//    Let now L' and R' be points such that vec(LL') = Wr/w * vec(V) and vec(RR') = Wl/w * vec(V)
173 174
//    now let Vl be a point on the line segment L --> M+vec(V) such that Vl(y) = L'(y)
174 175
//    and let Vr be a point on the line segment R --> M+vec(V) such that Vr(y) = R'(y)
175 176
//    
176
//    Now define points Fl and Fr, the points L and R will be moved to under force V, with Fl(y)=L'(y) and Fr(y)=R'(y) and |VrFr|/|VrR'| = |VlFl|/|VlL'| = H
177
//    Now define points Fl and Fr, the points L and R will be moved to under force V, with Fl(y)=L'(y)
178
//    and Fr(y)=R'(y) and |VrFr|/|VrR'| = |VlFl|/|VlL'| = H
177 179
//    Now notice that |VrR'| = |VlL'| = Wl*Wr / w   ( a little geometric puzzle! )
178 180
//
179 181
//    Then points L,R under force V move by vectors vec(Fl), vec(Fr) where
180 182
//    vec(Fl) = (Wr/w) * [ (Vx+Wl)-Wl*H, Vy ] = (Wr/w) * [ Wl*Vy / (h+Vy) + Vx, Vy ]
181 183
//    vec(Fr) = (Wl/w) * [ (Vx-Wr)+Wr*H, Vy ] = (Wl/w) * [-Wr*Vy / (h+Vy) + Vx, Vy ]
182 184
//
183
//    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:
185
//    Lets now denote M+vec(V) = M'. The line segment LMR gets distorted to the curve Fl-M'-Fr. Let's
186
//    now arbitrarilly decide that:
184 187
//    a) at point Fl the curve has to be parallel to line LM'
185 188
//    b) at point M' - to line LR
186 189
//    c) at point Fr - to line M'R
187 190
//
188
//    Now if Fl=(flx,fly) , M'=(mx,my) , Fr=(frx,fry); direction vector at Fl is (vx,vy) and at M' is (+c,0) where +c is some positive constant, then 
189
//    the parametric equations of the Fl--->M' section of the curve (which has to satisfy (X(0),Y(0)) = Fl, (X(1),Y(1))=M', (X'(0),Y'(0)) = (vx,vy), (X'(1),Y'(1)) = (+c,0)) is
191
//    Now if Fl=(flx,fly) , M'=(mx,my) , Fr=(frx,fry); direction vector at Fl is (vx,vy) and at M'
192
//    is (+c,0) where +c is some positive constant, then  the parametric equations of the Fl--->M'
193
//    section of the curve (which has to satisfy (X(0),Y(0)) = Fl, (X(1),Y(1))=M',
194
//    (X'(0),Y'(0)) = (vx,vy), (X'(1),Y'(1)) = (+c,0) ) is
190 195
//
191 196
//    X(t) = ( (mx-flx)-vx )t^2 + vx*t + flx                                  (*)
192 197
//    Y(t) = ( vy - 2(my-fly) )t^3 + ( 3(my-fly) -2vy )t^2 + vy*t + fly
193 198
//
194
//    Here we have to have X'(1) = 2(mx-flx)-vx which is positive <==> vx<2(mx-flx). We also have to have vy<2(my-fly) so that Y'(t)>0 (this is a must otherwise we have local loops!) 
195
//    Similarly for the Fr--->M' part of the curve we have the same equation except for the fact that this time we have to have X'(1)<0 so now we have to have vx>2(mx-flx).
199
//    Here we have to have X'(1) = 2(mx-flx)-vx which is positive <==> vx<2(mx-flx). We also have to
200
//    have vy<2(my-fly) so that Y'(t)>0 (this is a must otherwise we have local loops!)
201
//    Similarly for the Fr--->M' part of the curve we have the same equation except for the fact that
202
//    this time we have to have X'(1)<0 so now we have to have vx>2(mx-flx).
196 203
//
197
//    If we are stretching the left or right edge of the bitmap then the only difference is that we have to have (X'(1),Y'(1)) = (0,+-c) with + or - c depending on which part of the curve
204
//    If we are stretching the left or right edge of the bitmap then the only difference is that we
205
//    have to have (X'(1),Y'(1)) = (0,+-c) with + or - c depending on which part of the curve
198 206
//    we are tracing. Then the parametric equation is
199 207
//
200 208
//    X(t) = ( vx - 2(mx-flx) )t^3 + ( 3(mx-flx) -2vx )t^2 + vx*t + flx
......
202 210
//
203 211
//    If we are dragging the top edge:    
204 212
//
205
//    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
206
//    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)
213
//    Now point (x,u_objD.x) on the top edge will move by vector (X(t),Y(t)) where those functions
214
//    are given by (*) and t =  x < dSx ? (u_objD.x+x)/(u_objD.x+dSx) : (u_objD.x-x)/(u_objD.x-dSx)
215
//    (this is 'vec2 time' below in the code).
207 216
//    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)
208 217
  
209 218
void deform(in int effect, inout vec4 v)

Also available in: Unified diff