Revision 0f10a0b6
Added by Leszek Koltunski about 4 years ago
src/main/java/org/distorted/library/effectqueue/EffectQueueMatrix.java | ||
---|---|---|
37 | 37 |
private static float[] mMVPMatrix = new float[16]; |
38 | 38 |
private static float[] mModelViewMatrix = new float[16]; |
39 | 39 |
|
40 |
private static int[] mBoundingH = new int[MAIN_VARIANTS]; |
|
41 | 40 |
private static int[] mStretchH = new int[MAIN_VARIANTS]; |
42 | 41 |
private static int[] mMVPMatrixH = new int[MAIN_VARIANTS]; |
43 | 42 |
private static int[] mMVMatrixH = new int[MAIN_VARIANTS]; |
44 | 43 |
|
45 |
private static float[] mTmpMatrix = new float[16]; |
|
46 |
private static float[] mTmpResult = new float[4]; |
|
47 |
private static float[] mTmpPoint = new float[4]; |
|
48 |
private static float mMinX,mMaxX,mMinY,mMaxY; |
|
49 |
|
|
50 | 44 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
51 | 45 |
|
52 | 46 |
EffectQueueMatrix() |
... | ... | |
58 | 52 |
|
59 | 53 |
static void uniforms(int mProgramH, int variant) |
60 | 54 |
{ |
61 |
mBoundingH[variant] = GLES30.glGetUniformLocation(mProgramH, "u_Bounding"); |
|
62 | 55 |
mStretchH[variant] = GLES30.glGetUniformLocation(mProgramH, "u_Stretch"); |
63 | 56 |
mMVPMatrixH[variant]= GLES30.glGetUniformLocation(mProgramH, "u_MVPMatrix"); |
64 | 57 |
mMVMatrixH[variant] = GLES30.glGetUniformLocation(mProgramH, "u_MVMatrix"); |
65 | 58 |
} |
66 | 59 |
|
67 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
68 |
|
|
69 |
private void magnifyDir() |
|
70 |
{ |
|
71 |
Matrix.multiplyMV(mTmpResult,0,mTmpMatrix,0,mTmpPoint,0); |
|
72 |
float nx = mTmpResult[0]/mTmpResult[3]; |
|
73 |
float ny = mTmpResult[1]/mTmpResult[3]; |
|
74 |
|
|
75 |
if( nx<mMinX ) mMinX = nx; |
|
76 |
if( nx>mMaxX ) mMaxX = nx; |
|
77 |
if( ny<mMinY ) mMinY = ny; |
|
78 |
if( ny>mMaxY ) mMaxY = ny; |
|
79 |
} |
|
80 |
|
|
81 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
82 |
// return a float which describes how much larger an object must be so that it appears to be (about) |
|
83 |
// 'marginInPixels' pixels larger in each direction. Used in Postprocessing. |
|
84 |
|
|
85 |
float magnify(float[] projection, int width, int height, float mipmap, MeshBase mesh, float marginInPixels) |
|
86 |
{ |
|
87 |
mMinX = Integer.MAX_VALUE; |
|
88 |
mMaxX = Integer.MIN_VALUE; |
|
89 |
mMinY = Integer.MAX_VALUE; |
|
90 |
mMaxY = Integer.MIN_VALUE; |
|
91 |
|
|
92 |
mTmpPoint[3] = 1.0f; |
|
93 |
|
|
94 |
Matrix.multiplyMM(mTmpMatrix, 0, projection, 0, mModelViewMatrix, 0); |
|
95 |
|
|
96 |
float halfX = mesh.getBoundingX(); |
|
97 |
float halfY = mesh.getBoundingY(); |
|
98 |
float halfZ = mesh.getBoundingZ(); |
|
99 |
|
|
100 |
mTmpPoint[0] = +halfX; mTmpPoint[1] = +halfY; mTmpPoint[2] = +halfZ; magnifyDir(); |
|
101 |
mTmpPoint[0] = +halfX; mTmpPoint[1] = +halfY; mTmpPoint[2] = -halfZ; magnifyDir(); |
|
102 |
mTmpPoint[0] = +halfX; mTmpPoint[1] = -halfY; mTmpPoint[2] = +halfZ; magnifyDir(); |
|
103 |
mTmpPoint[0] = +halfX; mTmpPoint[1] = -halfY; mTmpPoint[2] = -halfZ; magnifyDir(); |
|
104 |
mTmpPoint[0] = -halfX; mTmpPoint[1] = +halfY; mTmpPoint[2] = +halfZ; magnifyDir(); |
|
105 |
mTmpPoint[0] = -halfX; mTmpPoint[1] = +halfY; mTmpPoint[2] = -halfZ; magnifyDir(); |
|
106 |
mTmpPoint[0] = -halfX; mTmpPoint[1] = -halfY; mTmpPoint[2] = +halfZ; magnifyDir(); |
|
107 |
mTmpPoint[0] = -halfX; mTmpPoint[1] = -halfY; mTmpPoint[2] = -halfZ; magnifyDir(); |
|
108 |
|
|
109 |
float xLenInPixels = width *(mMaxX-mMinX)/2; |
|
110 |
float yLenInPixels = height*(mMaxY-mMinY)/2; |
|
111 |
|
|
112 |
// already margin / avg(xLen,yLen) is the size of the halo. |
|
113 |
// Here we need a bit more because we are marking not only the halo, but a little bit around |
|
114 |
// it as well so that the (blur for example) will be smooth on the edges. Thus the 2.0f. |
|
115 |
// ( 4.0 because there is an extra 2.0 from the avg(xLen,yLen) ) |
|
116 |
// |
|
117 |
// mMipmap ( 1.0, 0.5, 0.25, 0.125 ) - we need to make the size of the halo independent |
|
118 |
// of postprocessing effect quality. |
|
119 |
|
|
120 |
return mipmap*4.0f*marginInPixels/( xLenInPixels+yLenInPixels ); |
|
121 |
} |
|
122 |
|
|
123 | 60 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
124 | 61 |
|
125 | 62 |
void compute(long currTime) |
... | ... | |
164 | 101 |
// combined Model-View-Projection matrix |
165 | 102 |
Matrix.multiplyMM(mMVPMatrix, 0, projection, 0, mModelViewMatrix, 0); |
166 | 103 |
|
167 |
GLES30.glUniform3f( mBoundingH[variant] , mesh.getBoundingX(), mesh.getBoundingY(), mesh.getBoundingZ()); |
|
168 | 104 |
GLES30.glUniform3f( mStretchH[variant] , mesh.getStretchX() , mesh.getStretchY() , mesh.getStretchZ() ); |
169 | 105 |
GLES30.glUniformMatrix4fv(mMVMatrixH[variant] , 1, false, mModelViewMatrix, 0); |
170 | 106 |
GLES30.glUniformMatrix4fv(mMVPMatrixH[variant], 1, false, mMVPMatrix , 0); |
Also available in: Unified diff
A lot of changes.
1) main vertex shader: remove support for degree_object. This functionality will hopefully come back when we introduce other than circular regions.
2) MeshBase: remove the need to set a Bounding box (this is the point of the whole thing - we wanted to get rid of this so that the advances in MeshJoined will be easier)
3) Set ground for removing the MeshBase.setStretch / getStretch (another thing needed to advance MeshJoined )
4) since we removed the Bounding box, we need to change the DEFORN effect to have 1 additional parameter, the 'radius' which takes over the function of the bounding box in the vertex shader.
5) since the'res no bounding box, simplify the postprocessing Halo (remove EffectQueueMatrix.magnify() )
6) adjust applications.
After this we will hopefully be ready to introduce MeshBase.preApply(VertexEffect), i.e. bending several simple Meshes with any VertexEffect - including the freshly-introduced PseudoMatrix-Vertex effects like VertexEffectScale - and then combining them into one MeshJoined.