Revision 8376b7d1
Added by Leszek Koltunski over 4 years ago
src/main/java/org/distorted/library/effect/VertexEffectDistort.java | ||
---|---|---|
131 | 131 |
+ "vec4 region= vUniforms[effect+2]; \n" |
132 | 132 |
+ "float d = degree(region,ps); \n" |
133 | 133 |
|
134 |
+ "v += d*force; \n" |
|
134 |
+ "if( d>0.0 ) \n" |
|
135 |
+ " { \n" |
|
136 |
+ " v += d*force; \n" |
|
135 | 137 |
|
136 |
+ "float tp = 1.0+n.z; \n"
|
|
137 |
+ "float tr = 1.0 / (tp - (sign(tp)-1.0)); \n" // proper way to compute 1/x is
|
|
138 |
+ " float tp = 1.0+n.z; \n"
|
|
139 |
+ " float tr = 1.0 / (tp - (sign(tp)-1.0)); \n" // proper way to compute 1/x is
|
|
138 | 140 |
// 1/(x-(sign(x)-1)) and NOT 1/(x+1-sign(x)) |
139 | 141 |
|
140 |
+ "float ap = ps.x*n.z - ps.z*n.x; \n" // rotate the ps vector
|
|
141 |
+ "float bp = ps.y*n.z - ps.z*n.y; \n" //
|
|
142 |
+ "float cp =(ps.x*n.y - ps.y*n.x)*tr; \n" //
|
|
143 |
+ "vec3 psRot = vec3( ap+n.y*cp , bp-n.x*cp , dot(ps,n) ); \n" //
|
|
142 |
+ " float ap = ps.x*n.z - ps.z*n.x; \n" // rotate the ps vector
|
|
143 |
+ " float bp = ps.y*n.z - ps.z*n.y; \n" //
|
|
144 |
+ " float cp =(ps.x*n.y - ps.y*n.x)*tr; \n" //
|
|
145 |
+ " vec3 psRot = vec3( ap+n.y*cp , bp-n.x*cp , dot(ps,n) ); \n" //
|
|
144 | 146 |
|
145 |
+ "float len = length(psRot); \n"
|
|
146 |
+ "float corr= sign(len)-1.0; \n" // make N (0,0,1) if ps=(0,0,0)
|
|
147 |
+ "vec3 N = vec3( -dot(force,n)*psRot.xy, region.w*len-corr ); \n" // modified rotated normal
|
|
147 |
+ " float len = length(psRot); \n"
|
|
148 |
+ " float corr= sign(len)-1.0; \n" // make N (0,0,1) if ps=(0,0,0)
|
|
149 |
+ " vec3 N = vec3( -dot(force,n)*psRot.xy, region.w*len-corr ); \n" // modified rotated normal
|
|
148 | 150 |
// dot(force,n) is rotated force.z |
149 |
+ "float an = N.x*n.z + N.z*n.x; \n" // now create the normal vector
|
|
150 |
+ "float bn = N.y*n.z + N.z*n.y; \n" // back from our modified normal
|
|
151 |
+ "float cn =(N.x*n.y - N.y*n.x)*tr; \n" // rotated back
|
|
152 |
+ "n = vec3( an+n.y*cn , bn-n.x*cn , -N.x*n.x-N.y*n.y+N.z*n.z); \n" // notice 4 signs change!
|
|
151 |
+ " float an = N.x*n.z + N.z*n.x; \n" // now create the normal vector
|
|
152 |
+ " float bn = N.y*n.z + N.z*n.y; \n" // back from our modified normal
|
|
153 |
+ " float cn =(N.x*n.y - N.y*n.x)*tr; \n" // rotated back
|
|
154 |
+ " n = vec3( an+n.y*cn , bn-n.x*cn , -N.x*n.x-N.y*n.y+N.z*n.z);\n" // notice 4 signs change!
|
|
153 | 155 |
|
154 |
+ " n = normalize(n); \n"; |
|
156 |
+ " n = normalize(n); \n" |
|
157 |
+ " }"; |
|
155 | 158 |
|
156 | 159 |
} |
157 | 160 |
|
Also available in: Unified diff
Fix the fact that Distort was rotating normals outside of its region!