1 |
00be51f0
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2020 Leszek Koltunski //
|
3 |
|
|
// //
|
4 |
|
|
// This file is part of Distorted. //
|
5 |
|
|
// //
|
6 |
|
|
// Distorted is free software: you can redistribute it and/or modify //
|
7 |
|
|
// it under the terms of the GNU General Public License as published by //
|
8 |
|
|
// the Free Software Foundation, either version 2 of the License, or //
|
9 |
|
|
// (at your option) any later version. //
|
10 |
|
|
// //
|
11 |
|
|
// Distorted is distributed in the hope that it will be useful, //
|
12 |
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
13 |
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
14 |
|
|
// GNU General Public License for more details. //
|
15 |
|
|
// //
|
16 |
|
|
// You should have received a copy of the GNU General Public License //
|
17 |
|
|
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. //
|
18 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19 |
|
|
|
20 |
|
|
package org.distorted.library.effect;
|
21 |
|
|
|
22 |
|
|
import org.distorted.library.type.Data3D;
|
23 |
|
|
|
24 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
25 |
|
|
/**
|
26 |
|
|
* Shear the Mesh.
|
27 |
|
|
*/
|
28 |
|
|
public class VertexEffectShear extends VertexEffect
|
29 |
|
|
{
|
30 |
f046b159
|
Leszek Koltunski
|
private static final EffectName NAME = EffectName.VERTEX_SHEAR;
|
31 |
|
|
|
32 |
78ff6ea9
|
Leszek Koltunski
|
private final Data3D mShear, mCenter;
|
33 |
00be51f0
|
Leszek Koltunski
|
|
34 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
35 |
|
|
/**
|
36 |
|
|
* Only for use by the library itself.
|
37 |
|
|
*
|
38 |
|
|
* @y.exclude
|
39 |
|
|
*/
|
40 |
|
|
public boolean compute(float[] uniforms, int index, long currentDuration, long step )
|
41 |
|
|
{
|
42 |
|
|
mCenter.get(uniforms,index+CENTER_OFFSET,currentDuration,step);
|
43 |
f046b159
|
Leszek Koltunski
|
return mShear.get(uniforms,index+VALUES_OFFSET,currentDuration,step);
|
44 |
00be51f0
|
Leszek Koltunski
|
}
|
45 |
|
|
|
46 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
47 |
be42e989
|
Leszek Koltunski
|
// For explanation (esp. about the way we modify vectors n and i) see MatrixEffectShear.
|
48 |
00be51f0
|
Leszek Koltunski
|
|
49 |
f046b159
|
Leszek Koltunski
|
static String code()
|
50 |
|
|
{
|
51 |
|
|
return
|
52 |
|
|
|
53 |
be42e989
|
Leszek Koltunski
|
"float sx = vUniforms[effect].x; \n"
|
54 |
|
|
+ "float sy = vUniforms[effect].y; \n"
|
55 |
|
|
+ "float sz = vUniforms[effect].z; \n"
|
56 |
|
|
+ "vec3 center = vUniforms[effect+1].yzw; \n"
|
57 |
|
|
+ "float tmp = sx*sy + 1.0; \n"
|
58 |
00be51f0
|
Leszek Koltunski
|
|
59 |
be42e989
|
Leszek Koltunski
|
+ "v -= center; \n"
|
60 |
00be51f0
|
Leszek Koltunski
|
|
61 |
be42e989
|
Leszek Koltunski
|
+ "float new_vx = tmp*v.x + sx*v.y; \n"
|
62 |
|
|
+ "float new_vy = sy*v.x + v.y; \n"
|
63 |
|
|
+ "float new_vz = sz*v.y + v.z; \n"
|
64 |
00be51f0
|
Leszek Koltunski
|
|
65 |
be42e989
|
Leszek Koltunski
|
+ "v.x = new_vx; \n"
|
66 |
|
|
+ "v.y = new_vy; \n"
|
67 |
|
|
+ "v.z = new_vz; \n"
|
68 |
00be51f0
|
Leszek Koltunski
|
|
69 |
be42e989
|
Leszek Koltunski
|
+ "v += center; \n"
|
70 |
00be51f0
|
Leszek Koltunski
|
|
71 |
be42e989
|
Leszek Koltunski
|
+ "float new_nx = n.x - sy*n.y + sy*sz*n.z; \n"
|
72 |
|
|
+ "float new_ny =-sx*n.x + tmp*(n.y - sz*n.z); \n"
|
73 |
|
|
+ "n.x = new_nx; \n"
|
74 |
457bd08e
|
Leszek Koltunski
|
+ "n.y = new_ny; \n"
|
75 |
|
|
|
76 |
|
|
+ "n = normalize(n);";
|
77 |
f046b159
|
Leszek Koltunski
|
}
|
78 |
|
|
|
79 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
80 |
|
|
// PUBLIC API
|
81 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
82 |
00be51f0
|
Leszek Koltunski
|
/**
|
83 |
|
|
* Have to call this before the shaders get compiled (i.e before DistortedLibrary.onCreate()) for the Effect to work.
|
84 |
|
|
*/
|
85 |
|
|
public static void enable()
|
86 |
|
|
{
|
87 |
f046b159
|
Leszek Koltunski
|
addEffect( NAME, code() );
|
88 |
00be51f0
|
Leszek Koltunski
|
}
|
89 |
|
|
|
90 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
91 |
|
|
/**
|
92 |
|
|
* Shear the Mesh.
|
93 |
|
|
*
|
94 |
|
|
* @param shear The 3-tuple of shear factors. The first controls level
|
95 |
|
|
* of shearing in the X-axis, second - Y-axis and the third -
|
96 |
|
|
* Z-axis. Each is the tangent of the shear angle, i.e 0 -
|
97 |
|
|
* no shear, 1 - shear by 45 degrees (tan(45deg)=1) etc.
|
98 |
|
|
* @param center Center of shearing, i.e. the point which stays unmoved.
|
99 |
|
|
*/
|
100 |
|
|
public VertexEffectShear(Data3D shear, Data3D center)
|
101 |
|
|
{
|
102 |
f046b159
|
Leszek Koltunski
|
super(NAME);
|
103 |
00be51f0
|
Leszek Koltunski
|
mShear = shear;
|
104 |
|
|
mCenter = center;
|
105 |
|
|
}
|
106 |
|
|
}
|