Revision 7cd24173
Added by Leszek Koltunski almost 7 years ago
src/main/java/org/distorted/library/effect/VertexEffectSwirl.java | ||
---|---|---|
76 | 76 |
|
77 | 77 |
return ret; |
78 | 78 |
} |
79 |
|
|
80 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
81 |
// Let d be the degree of the current vertex V with respect to center of the effect S and Region vRegion. |
|
82 |
// This effect rotates the current vertex V by vInterpolated.x radians clockwise around the circle dilated |
|
83 |
// by (1-d) around the center of the effect S. |
|
84 |
|
|
85 |
public static void enable() |
|
86 |
{ |
|
87 |
addEffect(EffectName.SWIRL, |
|
88 |
|
|
89 |
"vec2 center = vUniforms[effect+1].yz; \n" |
|
90 |
+ "vec2 PS = center-v.xy; \n" |
|
91 |
+ "vec4 SO = vUniforms[effect+2]; \n" |
|
92 |
+ "float d1_circle = degree_region(SO,PS); \n" |
|
93 |
+ "float d1_bitmap = degree_bitmap(center,PS); \n" |
|
94 |
|
|
95 |
+ "float alpha = vUniforms[effect].x; \n" |
|
96 |
+ "float sinA = sin(alpha); \n" |
|
97 |
+ "float cosA = cos(alpha); \n" |
|
98 |
|
|
99 |
+ "vec2 PS2 = vec2( PS.x*cosA+PS.y*sinA,-PS.x*sinA+PS.y*cosA ); \n" // vector PS rotated by A radians clockwise around center. |
|
100 |
+ "vec4 SG = (1.0-d1_circle)*SO; \n" // coordinates of the dilated circle P is going to get rotated around |
|
101 |
+ "float d2 = max(0.0,degree(SG,center,PS2)); \n" // make it a max(0,deg) because otherwise when center=left edge of the |
|
102 |
// bitmap some points end up with d2<0 and they disappear off view. |
|
103 |
+ "v.xy += min(d1_circle,d1_bitmap)*(PS - PS2/(1.0-d2)); \n" // if d2=1 (i.e P=center) we should have P unchanged. How to do it? |
|
104 |
); |
|
105 |
} |
|
79 | 106 |
} |
80 | 107 |
|
Also available in: Unified diff
Move all the knowledge about Vertex and Fragment effects to their respective classes.