1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2019 Leszek Koltunski leszek@koltunski.pl //
|
3
|
// //
|
4
|
// This file is part of Distorted. //
|
5
|
// //
|
6
|
// 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
|
// //
|
11
|
// This library 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 GNU //
|
14
|
// Lesser General Public License for more details. //
|
15
|
// //
|
16
|
// 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
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
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
|
private static final EffectName NAME = EffectName.VERTEX_SCALE;
|
33
|
|
34
|
private final Data3D mScale;
|
35
|
|
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
|
return mScale.get(uniforms,index+VALUES_OFFSET,currentDuration,step);
|
45
|
}
|
46
|
|
47
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
48
|
|
49
|
static String code()
|
50
|
{
|
51
|
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
|
"n *= vec3(X,Y,Z); \n" +
|
58
|
"n = normalize(n); \n";
|
59
|
}
|
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
|
addEffect( NAME, code() );
|
70
|
}
|
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
|
super(NAME);
|
81
|
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
|
super(NAME);
|
93
|
mScale = new Static3D(scale,scale,scale);
|
94
|
}
|
95
|
}
|