Revision 569ea22c
Added by Leszek Koltunski over 6 years ago
| src/main/java/org/distorted/library/effect/VertexEffectPinch.java | ||
|---|---|---|
| 73 | 73 |
|
| 74 | 74 |
"vec3 center = vUniforms[effect+1].yzw; \n" |
| 75 | 75 |
+ "vec3 ps = center-v; \n" |
| 76 |
+ "float h = vUniforms[effect].x; \n" |
|
| 76 |
+ "float h = vUniforms[effect].x; \n" |
|
| 77 |
+ "float latitude = vUniforms[effect].y; \n" |
|
| 78 |
+ "float longitude = vUniforms[effect].z; \n" |
|
| 77 | 79 |
+ "float deg = degree(vUniforms[effect+2],center,ps); \n" |
| 78 | 80 |
+ "float t = deg * (1.0-h)/max(1.0,h); \n" |
| 79 |
+ "float latitude = vUniforms[effect].y; \n" |
|
| 80 |
+ "float longitude = vUniforms[effect].z; \n" |
|
| 81 | 81 |
+ "float sinLAT = sin(latitude); \n" |
| 82 | 82 |
+ "float cosLAT = cos(latitude); \n" |
| 83 | 83 |
+ "float sinLON = sin(longitude); \n" |
| 84 | 84 |
+ "float cosLON = cos(longitude); \n" |
| 85 | 85 |
+ "vec3 dir = vec3(sinLON*cosLAT,sinLAT,cosLON*cosLAT);\n" |
| 86 |
+ "v += t*dot(ps,dir)*dir;" |
|
| 86 |
+ "float dot_dir_ps = dot(dir,ps); \n" |
|
| 87 |
+ "v += t*dot_dir_ps*dir; \n" |
|
| 88 |
|
|
| 89 |
+ "const float A = 1.6; \n" // max amount of change in normal vector when pulling |
|
| 90 |
+ "const float B = 10.0; \n" // when pushing |
|
| 91 |
+ "vec3 n_ps = dot(ps,n)*ps; \n" // n_ps = (component of n that's parallel to ps) * |ps|^2 (=dot(ps,ps)) |
|
| 92 |
+ "float dot_ps = dot(ps,ps); \n" |
|
| 93 |
+ "float sign_ps= sign(dot_ps); \n" |
|
| 94 |
+ "n_ps = sign_ps*n_ps/(dot_ps-(sign_ps-1.0)); \n" // uff! now n_ps is the parallel to ps component of n, even if ps==0 |
|
| 95 |
+ "float move = deg*(h-1.0)/(h/B+1.0/A); \n" // move(0)=-A*deg, move(1)=0, move(inf)=B*deg |
|
| 96 |
+ "n += move * abs(dot(n,dir)) * n_ps; \n" |
|
| 97 |
+ "n = normalize(n);" |
|
| 87 | 98 |
); |
| 88 | 99 |
} |
| 89 | 100 |
|
| src/main/java/org/distorted/library/effect/VertexEffectSink.java | ||
|---|---|---|
| 69 | 69 |
|
| 70 | 70 |
+ "const float A = 1.6; \n" // max amount of change in normal vector when pulling |
| 71 | 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))
|
|
| 72 |
+ "vec3 n_ps = dot(ps,n)*ps; \n" // n_ps = (component of n that's parallel to ps) * |ps|^2 (=dot(ps,ps))
|
|
| 73 | 73 |
+ "float dot_ps = dot(ps,ps); \n" |
| 74 | 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
|
|
| 75 |
+ "n_ps = (sign_ps*n_ps)/(dot_ps-(sign_ps-1.0)); \n" // uff! now n_ps is the parallel to ps component of n, even if ps==0
|
|
| 76 | 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"
|
|
| 77 |
+ "n += move*n_ps; \n"
|
|
| 78 | 78 |
+ "n = normalize(n);" |
| 79 | 79 |
); |
| 80 | 80 |
} |
Also available in: Unified diff
Add correct normal vectors to the PINCH effect. The effect is now fully 3D.