Project

General

Profile

« Previous | Next » 

Revision 4aa38649

Added by Leszek Koltunski over 5 years ago

Redefine the Vertex Region from (x,y,r,unused) to (x,y,z,r). This takes into account the 'Z', which makes it possible to warp only one side of a 3D Mesh like Sphere.

Also corresponding changes in applications.

View differences:

src/main/java/org/distorted/library/effect/VertexEffectDeform.java
110 110
    {
111 111
    addEffect( EffectName.DEFORM,
112 112

  
113
        "const vec2 ONE = vec2(1.0,1.0);  \n"
113
        "const vec3 ONE = vec3(1.0,1.0,1.0);  \n"
114 114
      + "const float A = 0.5; \n"
115 115
      + "const float B = 0.2; \n"
116 116
      + "const float C = 5.0; \n"
117 117

  
118
      + "vec2 center = vUniforms[effect+1].yz; \n"
119
      + "vec2 ps     = center-v.xy; \n"
120
      + "vec2 aPS    = abs(ps); \n"
121
      + "vec2 maxps  = u_objD.xy + abs(center); \n"
118
      + "vec3 center = vUniforms[effect+1].yzw; \n"
119
      + "vec3 ps     = center-v.xyz; \n"
120
      + "vec3 aPS    = abs(ps); \n"
121
      + "vec3 maxps  = u_objD + abs(center); \n"
122 122
      + "float d     = degree_region(vUniforms[effect+2],ps); \n"
123 123
      + "vec3 force  = vUniforms[effect].xyz * d; \n"
124
      + "vec2 aForce = abs(force.xy); \n"
125
      + "float denom = dot(ps+(1.0-d)*force.xy,ps); \n"
124
      + "vec3 aForce = abs(force); \n"
125
      + "float denom = dot(ps+(1.0-d)*force,ps); \n"
126 126
      + "float one_over_denom = 1.0/(denom-0.001*(sign(denom)-1.0)); \n"
127
      + "vec2 Aw = A*maxps; \n"
128
      + "vec2 quot = ps / maxps; \n"
127
      + "vec3 Aw = A*maxps; \n"
128
      + "vec3 quot = ps / maxps; \n"
129 129
      + "quot = quot*quot; \n"                                                 // ( (x/W)^2 , (y/H)^2 ) where x,y are distances from V to center
130 130

  
131 131
      + "float denomV = 1.0 / (aForce.y + Aw.x); \n"
132 132
      + "float denomH = 1.0 / (aForce.x + Aw.y); \n"
133 133

  
134
      + "vec2 vertCorr= ONE - aPS / ( aForce+C*aPS + (ONE-sign(aForce)) ); \n" // avoid division by 0 when force and PS both are 0
134
      + "vec3 vertCorr= ONE - aPS / ( aForce+C*aPS + (ONE-sign(aForce)) ); \n" // avoid division by 0 when force and PS both are 0
135 135

  
136 136
      + "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
137 137
      + "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
......
144 144
      + "v.z += force.z*d*d*(3.0*d*d -8.0*d +6.0); \n"                         // thick bubble
145 145
      + "float b = -(12.0*force.z*d*(1.0-d)*(1.0-d)*(1.0-d))*one_over_denom; \n"
146 146

  
147
      + "n.xy += n.z*b*ps;"
147
      + "n.xy += n.z*b*ps.xy;"
148 148
      );
149 149
    }
150 150

  
......
178 178
    super(EffectName.DEFORM);
179 179
    mVector = vector;
180 180
    mCenter = center;
181
    mRegion = new Static4D(0,0,Float.MAX_VALUE, Float.MAX_VALUE);
181
    mRegion = new Static4D(0,0,0, Float.MAX_VALUE);
182 182
    }
183 183
  }

Also available in: Unified diff