Project

General

Profile

« Previous | Next » 

Revision 00be51f0

Added by Leszek Koltunski over 4 years ago

new VertexEffectShear

View differences:

src/main/java/org/distorted/library/effect/EffectName.java
59 59
  VERTEX_QUATERNION( EffectType.VERTEX  ,   new float[] {0.0f,0.0f,0.0f} , 4, 0,     3    , VertexEffectQuaternion.class   ),
60 60
  VERTEX_ROTATE    ( EffectType.VERTEX  ,   new float[] {0.0f}           , 4, 0,     3    , VertexEffectRotate.class       ),
61 61
  VERTEX_SCALE     ( EffectType.VERTEX  ,   new float[] {1.0f,1.0f,1.0f} , 3, 0,     0    , VertexEffectScale.class        ),
62
  VERTEX_SHEAR     ( EffectType.VERTEX  ,   new float[] {0.0f,0.0f,0.0f} , 3, 0,     3    , VertexEffectShear.class        ),
62 63

  
63 64
  ALPHA            ( EffectType.FRAGMENT,   new float[] {1.0f}           , 1, 3,     3    , FragmentEffectAlpha.class      ),
64 65
  SMOOTH_ALPHA     ( EffectType.FRAGMENT,   new float[] {1.0f}           , 1, 3,     3    , FragmentEffectAlpha.class      ),
src/main/java/org/distorted/library/effect/VertexEffectQuaternion.java
57 57
             + "float qy = vUniforms[effect].y;               \n"
58 58
             + "float qz = vUniforms[effect].z;               \n"
59 59
             + "float qw = vUniforms[effect].w;               \n"
60
             + "vec3 center = vUniforms[effect+1].yzw;        \n"
61

  
62
             + "v -= center;                                  \n"
60 63

  
61 64
             + "float tx = qx - v.z*qy + v.y*qz + v.x*qw;     \n"
62 65
             + "float ty = qy + v.z*qx + v.y*qw - v.x*qz;     \n"
......
67 70
             + "v.y = qw*ty - qz*tx - qy*tw + qx*tz;          \n"
68 71
             + "v.z = qw*tz - qz*tw + qy*tx - qx*ty;          \n"
69 72

  
73
             + "v += center;                                  \n"
74

  
70 75
             + "float nx =  - n.z*qy + n.y*qz + n.x*qw;       \n"
71 76
             + "float ny =  + n.z*qx + n.y*qw - n.x*qz;       \n"
72 77
             + "float nz =  + n.z*qw - n.y*qx + n.x*qy;       \n"
src/main/java/org/distorted/library/effect/VertexEffectShear.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
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
  private Data3D mShear, mCenter;
31

  
32
///////////////////////////////////////////////////////////////////////////////////////////////////
33
/**
34
 * Only for use by the library itself.
35
 *
36
 * @y.exclude
37
 */
38
  public boolean compute(float[] uniforms, int index, long currentDuration, long step )
39
    {
40
    mCenter.get(uniforms,index+CENTER_OFFSET,currentDuration,step);
41
    return mShear.get(uniforms,index,currentDuration,step);
42
    }
43

  
44
///////////////////////////////////////////////////////////////////////////////////////////////////
45
// PUBLIC API
46
///////////////////////////////////////////////////////////////////////////////////////////////////
47
/*
48
  float sx = uniforms[NUM_UNIFORMS*index  ];
49
    float sy = uniforms[NUM_UNIFORMS*index+1];
50
    float sz = uniforms[NUM_UNIFORMS*index+2];
51

  
52
    float x  = uniforms[NUM_UNIFORMS*index+CENTER_OFFSET  ];
53
    float y  = uniforms[NUM_UNIFORMS*index+CENTER_OFFSET+1];
54
    float z  = uniforms[NUM_UNIFORMS*index+CENTER_OFFSET+2];
55

  
56
    Matrix.translateM(matrix, 0, x, y, z);
57

  
58
    matrix[4] += sx*matrix[0]; // Multiply viewMatrix by 1 x 0 0 , i.e. X-shear.
59
    matrix[5] += sx*matrix[1]; //                        0 1 0 0
60
    matrix[6] += sx*matrix[2]; //                        0 0 1 0
61
    matrix[7] += sx*matrix[3]; //                        0 0 0 1
62

  
63
    matrix[0] += sy*matrix[4]; // Multiply viewMatrix by 1 0 0 0 , i.e. Y-shear.
64
    matrix[1] += sy*matrix[5]; //                        y 1 0 0
65
    matrix[2] += sy*matrix[6]; //                        0 0 1 0
66
    matrix[3] += sy*matrix[7]; //                        0 0 0 1
67

  
68
    matrix[4] += sz*matrix[8]; // Multiply viewMatrix by 1 0 0 0 , i.e. Z-shear.
69
    matrix[5] += sz*matrix[9]; //                        0 1 0 0
70
    matrix[6] += sz*matrix[10];//                        0 z 1 0
71
    matrix[7] += sz*matrix[11];//                        0 0 0 1
72

  
73
    Matrix.translateM(matrix, 0,-x,-y,-z);
74
*/
75

  
76
/**
77
 * Have to call this before the shaders get compiled (i.e before DistortedLibrary.onCreate()) for the Effect to work.
78
 */
79
  public static void enable()
80
    {
81
    addEffect( EffectName.VERTEX_SHEAR,
82

  
83
               "float sx = vUniforms[effect].x;               \n"
84
             + "float sy = vUniforms[effect].y;               \n"
85
             + "float sz = vUniforms[effect].z;               \n"
86
             + "vec3 center = vUniforms[effect+1].yzw;        \n"
87

  
88
             + "v -= center;                                  \n"
89

  
90
             + "float new_vx = (1.0+sx*sy)*v.x + sx*v.y;      \n"
91
             + "float new_vy = sy*v.x + v.y;                  \n"
92
             + "float new_vz = sz*v.y + v.z;                  \n"
93

  
94
             + "v.x = new_vx;                                 \n"
95
             + "v.y = new_vy;                                 \n"
96
             + "v.z = new_vz;                                 \n"
97

  
98
             + "v += center;                                  \n"
99

  
100
             + "float new_nx = (1.0+sx*sy)*n.x + sx*n.y;      \n"
101
             + "float new_ny = sy*n.x + n.y;                  \n"
102
             + "float new_nz = sz*n.y + n.z;                  \n"
103

  
104
             + "n.x = new_nx;                                 \n"
105
             + "n.y = new_ny;                                 \n"
106
             + "n.z = new_nz;                                 \n"
107
             );
108
    }
109

  
110
///////////////////////////////////////////////////////////////////////////////////////////////////
111
/**
112
 * Shear the Mesh.
113
 *
114
 * @param shear   The 3-tuple of shear factors. The first controls level
115
 *                of shearing in the X-axis, second - Y-axis and the third -
116
 *                Z-axis. Each is the tangent of the shear angle, i.e 0 -
117
 *                no shear, 1 - shear by 45 degrees (tan(45deg)=1) etc.
118
 * @param center  Center of shearing, i.e. the point which stays unmoved.
119
 */
120
  public VertexEffectShear(Data3D shear, Data3D center)
121
    {
122
    super(EffectName.VERTEX_SHEAR);
123
    mShear = shear;
124
    mCenter = center;
125
    }
126
  }

Also available in: Unified diff