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 |
|
|
private Data3D mShear;
|
33 |
|
|
private Data3D mCenter;
|
34 |
00be51f0
|
Leszek Koltunski
|
|
35 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
36 |
|
|
/**
|
37 |
|
|
* Only for use by the library itself.
|
38 |
|
|
*
|
39 |
|
|
* @y.exclude
|
40 |
|
|
*/
|
41 |
|
|
public boolean compute(float[] uniforms, int index, long currentDuration, long step )
|
42 |
|
|
{
|
43 |
|
|
mCenter.get(uniforms,index+CENTER_OFFSET,currentDuration,step);
|
44 |
f046b159
|
Leszek Koltunski
|
return mShear.get(uniforms,index+VALUES_OFFSET,currentDuration,step);
|
45 |
00be51f0
|
Leszek Koltunski
|
}
|
46 |
|
|
|
47 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
48 |
|
|
|
49 |
f046b159
|
Leszek Koltunski
|
static String code()
|
50 |
|
|
{
|
51 |
|
|
return
|
52 |
|
|
|
53 |
|
|
"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 |
00be51f0
|
Leszek Koltunski
|
|
58 |
f046b159
|
Leszek Koltunski
|
+ "v -= center; \n"
|
59 |
00be51f0
|
Leszek Koltunski
|
|
60 |
f046b159
|
Leszek Koltunski
|
+ "float new_vx = (1.0+sx*sy)*v.x + sx*v.y; \n"
|
61 |
|
|
+ "float new_vy = sy*v.x + v.y; \n"
|
62 |
|
|
+ "float new_vz = sz*v.y + v.z; \n"
|
63 |
00be51f0
|
Leszek Koltunski
|
|
64 |
f046b159
|
Leszek Koltunski
|
+ "v.x = new_vx; \n"
|
65 |
|
|
+ "v.y = new_vy; \n"
|
66 |
|
|
+ "v.z = new_vz; \n"
|
67 |
00be51f0
|
Leszek Koltunski
|
|
68 |
f046b159
|
Leszek Koltunski
|
+ "v += center; \n"
|
69 |
00be51f0
|
Leszek Koltunski
|
|
70 |
f046b159
|
Leszek Koltunski
|
+ "float new_nx = (1.0+sx*sy)*n.x + sx*n.y; \n"
|
71 |
|
|
+ "float new_ny = sy*n.x + n.y; \n"
|
72 |
|
|
+ "float new_nz = sz*n.y + n.z; \n"
|
73 |
00be51f0
|
Leszek Koltunski
|
|
74 |
f046b159
|
Leszek Koltunski
|
+ "n.x = new_nx; \n"
|
75 |
|
|
+ "n.y = new_ny; \n"
|
76 |
e54bfada
|
Leszek Koltunski
|
+ "n.z = new_nz; \n"
|
77 |
|
|
|
78 |
|
|
+ "#ifdef PREAPPLY \n"
|
79 |
|
|
|
80 |
|
|
+ "float new_ix = (1.0+sx*sy)*inf.x + sx*inf.y; \n"
|
81 |
|
|
+ "float new_iy = sy*inf.x + inf.y; \n"
|
82 |
|
|
+ "float new_iz = sz*inf.y + inf.z; \n"
|
83 |
|
|
|
84 |
|
|
+ "inf.x = new_ix; \n"
|
85 |
|
|
+ "inf.y = new_iy; \n"
|
86 |
|
|
+ "inf.z = new_iz; \n"
|
87 |
|
|
|
88 |
|
|
+ "#endif \n";
|
89 |
f046b159
|
Leszek Koltunski
|
}
|
90 |
|
|
|
91 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
92 |
|
|
// PUBLIC API
|
93 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
94 |
00be51f0
|
Leszek Koltunski
|
/**
|
95 |
|
|
* Have to call this before the shaders get compiled (i.e before DistortedLibrary.onCreate()) for the Effect to work.
|
96 |
|
|
*/
|
97 |
|
|
public static void enable()
|
98 |
|
|
{
|
99 |
f046b159
|
Leszek Koltunski
|
addEffect( NAME, code() );
|
100 |
00be51f0
|
Leszek Koltunski
|
}
|
101 |
|
|
|
102 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
103 |
|
|
/**
|
104 |
|
|
* Shear the Mesh.
|
105 |
|
|
*
|
106 |
|
|
* @param shear The 3-tuple of shear factors. The first controls level
|
107 |
|
|
* of shearing in the X-axis, second - Y-axis and the third -
|
108 |
|
|
* Z-axis. Each is the tangent of the shear angle, i.e 0 -
|
109 |
|
|
* no shear, 1 - shear by 45 degrees (tan(45deg)=1) etc.
|
110 |
|
|
* @param center Center of shearing, i.e. the point which stays unmoved.
|
111 |
|
|
*/
|
112 |
|
|
public VertexEffectShear(Data3D shear, Data3D center)
|
113 |
|
|
{
|
114 |
f046b159
|
Leszek Koltunski
|
super(NAME);
|
115 |
00be51f0
|
Leszek Koltunski
|
mShear = shear;
|
116 |
|
|
mCenter = center;
|
117 |
|
|
}
|
118 |
|
|
}
|