Project

General

Profile

« Previous | Next » 

Revision 5f76092f

Added by Leszek Koltunski over 5 years ago

Add (simplified, approximated) shading to the Sink effect, i.e. move the normal vectors.

View differences:

src/main/java/org/distorted/library/effect/VertexEffectDeform.java
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;"
src/main/java/org/distorted/library/effect/VertexEffectSink.java
60 60
    {
61 61
    addEffect(EffectName.SINK,
62 62

  
63
        "vec3 center = vUniforms[effect+1].yzw; \n"
64
      + "vec3 ps = center-v; \n"
65
      + "float h = vUniforms[effect].x; \n"
66
      + "float t = degree(vUniforms[effect+2],center,ps) * (1.0-h)/max(1.0,h); \n"
63
        "vec3 center = vUniforms[effect+1].yzw;            \n"
64
      + "vec3 ps = center-v;                               \n"
65
      + "float h = vUniforms[effect].x;                    \n"
66
      + "float deg = degree(vUniforms[effect+2],center,ps);\n"
67
      + "float t = deg * (1.0-h)/max(1.0,h);               \n"
68
      + "v += t*ps;                                        \n"
67 69

  
68
      + "v += t*ps;"
70
      + "const float A = 1.6;                              \n" // max amount of change in normal vector when pulling
71
      + "const float B = 10.0;                             \n" // when pushing
72
      + "vec3 nx = dot(ps,n)*ps;                           \n" // nx = (component of n that's parallel to ps) * |ps|^2 (=dot(ps,ps))
73
      + "float dot_ps = dot(ps,ps);                        \n"
74
      + "float sign_ps= sign(dot_ps);                      \n"
75
      + "nx = (sign_ps*nx)/(dot_ps-(sign_ps-1.0));         \n" // uff! now nx is the parallel to ps component of n, even if ps==0
76
      + "float move = deg*(h-1.0)/(h/B+1.0/A);             \n" // move(0)=-A*deg, move(1)=0, move(inf)=B*deg
77
      + "n += move*nx;                                     \n"
78
      + "n = normalize(n);"
69 79
      );
70 80
    }
71 81

  

Also available in: Unified diff