Revision f046b159
Added by Leszek Koltunski almost 4 years ago
src/main/java/org/distorted/library/effect/VertexEffectSink.java | ||
---|---|---|
30 | 30 |
*/ |
31 | 31 |
public class VertexEffectSink extends VertexEffect |
32 | 32 |
{ |
33 |
private static final EffectName NAME = EffectName.SINK; |
|
34 |
|
|
33 | 35 |
private Data1D mSink; |
34 | 36 |
private Data3D mCenter; |
35 | 37 |
private Data4D mRegion; |
... | ... | |
44 | 46 |
{ |
45 | 47 |
mCenter.get(uniforms,index+CENTER_OFFSET,currentDuration,step); |
46 | 48 |
mRegion.get(uniforms,index+REGION_OFFSET,currentDuration,step); |
47 |
return mSink.get(uniforms,index,currentDuration,step); |
|
49 |
return mSink.get(uniforms,index+VALUES_OFFSET,currentDuration,step);
|
|
48 | 50 |
} |
49 | 51 |
|
50 | 52 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
51 |
// PUBLIC API |
|
52 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
53 |
// Pull P=(v.x,v.y) towards center of the effect with P' = P + (1-h)*dist(S-P) |
|
54 |
// when h>1 we are pushing points away from S: P' = P + (1/h-1)*dist(S-P) |
|
55 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
56 |
/** |
|
57 |
* Have to call this before the shaders get compiled (i.e before DistortedLibrary.onCreate()) for the Effect to work. |
|
58 |
*/ |
|
59 |
public static void enable() |
|
53 |
|
|
54 |
static String code() |
|
60 | 55 |
{ |
61 |
addEffect(EffectName.SINK,
|
|
56 |
return
|
|
62 | 57 |
|
63 | 58 |
"vec3 ps = vUniforms[effect+1].yzw - v; \n" |
64 | 59 |
+ "float h = vUniforms[effect].x; \n" |
... | ... | |
74 | 69 |
+ "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 |
75 | 70 |
+ "float move = deg*(h-1.0)/(h/B+1.0/A); \n" // move(0)=-A*deg, move(1)=0, move(inf)=B*deg |
76 | 71 |
+ "n += move*n_ps; \n" |
77 |
+ "n = normalize(n);" |
|
78 |
); |
|
72 |
+ "n = normalize(n);"; |
|
73 |
} |
|
74 |
|
|
75 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
76 |
// PUBLIC API |
|
77 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
78 |
// Pull P=(v.x,v.y) towards center of the effect with P' = P + (1-h)*dist(S-P) |
|
79 |
// when h>1 we are pushing points away from S: P' = P + (1/h-1)*dist(S-P) |
|
80 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
81 |
/** |
|
82 |
* Have to call this before the shaders get compiled (i.e before DistortedLibrary.onCreate()) for the Effect to work. |
|
83 |
*/ |
|
84 |
public static void enable() |
|
85 |
{ |
|
86 |
addEffect(NAME, code() ); |
|
79 | 87 |
} |
80 | 88 |
|
81 | 89 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
89 | 97 |
*/ |
90 | 98 |
public VertexEffectSink(Data1D sink, Data3D center, Data4D region) |
91 | 99 |
{ |
92 |
super(EffectName.SINK);
|
|
100 |
super(NAME);
|
|
93 | 101 |
mSink = sink; |
94 | 102 |
mCenter = center; |
95 | 103 |
mRegion = (region==null ? MAX_REGION : region); |
... | ... | |
105 | 113 |
*/ |
106 | 114 |
public VertexEffectSink(Data1D sink, Data3D center) |
107 | 115 |
{ |
108 |
super(EffectName.SINK);
|
|
116 |
super(NAME);
|
|
109 | 117 |
mSink = sink; |
110 | 118 |
mCenter = center; |
111 | 119 |
mRegion = MAX_REGION; |
Also available in: Unified diff
First attempt at the MeshBase.apply(VertexEffect) API.