1 |
a918bba1
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
cc62b34a
|
Leszek Koltunski
|
// Copyright 2019 Leszek Koltunski leszek@koltunski.pl //
|
3 |
a918bba1
|
Leszek Koltunski
|
// //
|
4 |
|
|
// This file is part of Distorted. //
|
5 |
|
|
// //
|
6 |
cc62b34a
|
Leszek Koltunski
|
// This library is free software; you can redistribute it and/or //
|
7 |
|
|
// modify it under the terms of the GNU Lesser General Public //
|
8 |
|
|
// License as published by the Free Software Foundation; either //
|
9 |
|
|
// version 2.1 of the License, or (at your option) any later version. //
|
10 |
a918bba1
|
Leszek Koltunski
|
// //
|
11 |
cc62b34a
|
Leszek Koltunski
|
// This library is distributed in the hope that it will be useful, //
|
12 |
a918bba1
|
Leszek Koltunski
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
13 |
cc62b34a
|
Leszek Koltunski
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU //
|
14 |
|
|
// Lesser General Public License for more details. //
|
15 |
a918bba1
|
Leszek Koltunski
|
// //
|
16 |
cc62b34a
|
Leszek Koltunski
|
// You should have received a copy of the GNU Lesser General Public //
|
17 |
|
|
// License along with this library; if not, write to the Free Software //
|
18 |
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA //
|
19 |
a918bba1
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
20 |
|
|
|
21 |
|
|
package org.distorted.library.effect;
|
22 |
|
|
|
23 |
|
|
import org.distorted.library.type.Data3D;
|
24 |
|
|
import org.distorted.library.type.Static3D;
|
25 |
|
|
|
26 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
27 |
|
|
/**
|
28 |
|
|
* Scale the Mesh by 3D scale factors.
|
29 |
|
|
*/
|
30 |
|
|
public class VertexEffectScale extends VertexEffect
|
31 |
|
|
{
|
32 |
f046b159
|
Leszek Koltunski
|
private static final EffectName NAME = EffectName.VERTEX_SCALE;
|
33 |
|
|
|
34 |
0e1d3d2e
|
Leszek Koltunski
|
private final Data3D mScale;
|
35 |
a918bba1
|
Leszek Koltunski
|
|
36 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
37 |
|
|
/**
|
38 |
|
|
* Only for use by the library itself.
|
39 |
|
|
*
|
40 |
|
|
* @y.exclude
|
41 |
|
|
*/
|
42 |
|
|
public boolean compute(float[] uniforms, int index, long currentDuration, long step )
|
43 |
|
|
{
|
44 |
f046b159
|
Leszek Koltunski
|
return mScale.get(uniforms,index+VALUES_OFFSET,currentDuration,step);
|
45 |
|
|
}
|
46 |
|
|
|
47 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
48 |
|
|
|
49 |
|
|
static String code()
|
50 |
|
|
{
|
51 |
be42e989
|
Leszek Koltunski
|
return
|
52 |
|
|
|
53 |
|
|
"v *= vUniforms[effect].xyz; \n" +
|
54 |
|
|
"float X = vUniforms[effect].y*vUniforms[effect].z; \n" +
|
55 |
|
|
"float Y = vUniforms[effect].x*vUniforms[effect].z; \n" +
|
56 |
|
|
"float Z = vUniforms[effect].x*vUniforms[effect].y; \n" +
|
57 |
457bd08e
|
Leszek Koltunski
|
"n *= vec3(X,Y,Z); \n" +
|
58 |
|
|
"n = normalize(n); \n";
|
59 |
a918bba1
|
Leszek Koltunski
|
}
|
60 |
|
|
|
61 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
62 |
|
|
// PUBLIC API
|
63 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
64 |
|
|
/**
|
65 |
|
|
* Have to call this before the shaders get compiled (i.e before DistortedLibrary.onCreate()) for the Effect to work.
|
66 |
|
|
*/
|
67 |
|
|
public static void enable()
|
68 |
|
|
{
|
69 |
f046b159
|
Leszek Koltunski
|
addEffect( NAME, code() );
|
70 |
a918bba1
|
Leszek Koltunski
|
}
|
71 |
|
|
|
72 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
73 |
|
|
/**
|
74 |
|
|
* Scale the Mesh by 3D scale factors.
|
75 |
|
|
*
|
76 |
|
|
* @param scale current x- , y- and z- scale factors.
|
77 |
|
|
*/
|
78 |
|
|
public VertexEffectScale(Data3D scale)
|
79 |
|
|
{
|
80 |
f046b159
|
Leszek Koltunski
|
super(NAME);
|
81 |
a918bba1
|
Leszek Koltunski
|
mScale = scale;
|
82 |
|
|
}
|
83 |
|
|
|
84 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
85 |
|
|
/**
|
86 |
|
|
* Scale the Mesh by 3D scale factors.
|
87 |
|
|
*
|
88 |
|
|
* @param scale Common x,y, and z scale factor.
|
89 |
|
|
*/
|
90 |
|
|
public VertexEffectScale(float scale)
|
91 |
|
|
{
|
92 |
f046b159
|
Leszek Koltunski
|
super(NAME);
|
93 |
a918bba1
|
Leszek Koltunski
|
mScale = new Static3D(scale,scale,scale);
|
94 |
|
|
}
|
95 |
|
|
}
|