Revision a2878a67
Added by Leszek Koltunski about 4 years ago
src/main/java/org/distorted/library/effect/VertexEffectQuaternion.java | ||
---|---|---|
78 | 78 |
|
79 | 79 |
+ "n.x = qw*nx + qz*ny - qy*nz - qx*nw; \n" |
80 | 80 |
+ "n.y = qw*ny - qz*nx - qy*nw + qx*nz; \n" |
81 |
+ "n.z = qw*nz - qz*nw + qy*nx - qx*ny; \n" |
|
82 |
|
|
83 |
+ "#ifdef PREAPPLY \n" |
|
84 |
|
|
85 |
+ "float ix = - inf.z*qy + inf.y*qz + inf.x*qw; \n" |
|
86 |
+ "float iy = + inf.z*qx + inf.y*qw - inf.x*qz; \n" |
|
87 |
+ "float iz = + inf.z*qw - inf.y*qx + inf.x*qy; \n" |
|
88 |
+ "float iw = - inf.z*qz - inf.y*qy - inf.x*qx; \n" |
|
89 |
|
|
90 |
+ "inf.x = qw*ix + qz*iy - qy*iz - qx*iw; \n" |
|
91 |
+ "inf.y = qw*iy - qz*ix - qy*iw + qx*iz; \n" |
|
92 |
+ "inf.z = qw*iz - qz*iw + qy*ix - qx*iy; \n" |
|
93 |
|
|
94 |
+ "#endif \n"; |
|
81 |
+ "n.z = qw*nz - qz*nw + qy*nx - qx*ny; \n"; |
|
95 | 82 |
} |
96 | 83 |
|
97 | 84 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/library/effect/VertexEffectRotate.java | ||
---|---|---|
95 | 95 |
|
96 | 96 |
+ "n.x = qw*nx + qz*ny - qy*nz - qx*nw; \n" |
97 | 97 |
+ "n.y = qw*ny - qz*nx - qy*nw + qx*nz; \n" |
98 |
+ "n.z = qw*nz - qz*nw + qy*nx - qx*ny; \n" |
|
99 |
|
|
100 |
+ "#ifdef PREAPPLY \n" |
|
101 |
|
|
102 |
+ "float ix = - inf.z*qy + inf.y*qz + inf.x*qw; \n" |
|
103 |
+ "float iy = + inf.z*qx + inf.y*qw - inf.x*qz; \n" |
|
104 |
+ "float iz = + inf.z*qw - inf.y*qx + inf.x*qy; \n" |
|
105 |
+ "float iw = - inf.z*qz - inf.y*qy - inf.x*qx; \n" |
|
106 |
|
|
107 |
+ "inf.x = qw*ix + qz*iy - qy*iz - qx*iw; \n" |
|
108 |
+ "inf.y = qw*iy - qz*ix - qy*iw + qx*iz; \n" |
|
109 |
+ "inf.z = qw*iz - qz*iw + qy*ix - qx*iy; \n" |
|
110 |
|
|
111 |
+ "#endif \n"; |
|
98 |
+ "n.z = qw*nz - qz*nw + qy*nx - qx*ny; \n"; |
|
112 | 99 |
} |
113 | 100 |
|
114 | 101 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/library/effect/VertexEffectShear.java | ||
---|---|---|
72 | 72 |
+ "float new_nx = n.x - sy*n.y + sy*sz*n.z; \n" |
73 | 73 |
+ "float new_ny =-sx*n.x + tmp*(n.y - sz*n.z); \n" |
74 | 74 |
+ "n.x = new_nx; \n" |
75 |
+ "n.y = new_ny; \n" |
|
76 |
|
|
77 |
+ "#ifdef PREAPPLY \n" |
|
78 |
|
|
79 |
+ "float new_ix = inf.x - sy*inf.y + sy*sz*inf.z; \n" |
|
80 |
+ "float new_iy =-sx*inf.x + tmp*(inf.y - sz*inf.z);\n" |
|
81 |
+ "inf.x = new_ix; \n" |
|
82 |
+ "inf.y = new_iy; \n" |
|
83 |
|
|
84 |
+ "#endif \n"; |
|
75 |
+ "n.y = new_ny; \n"; |
|
85 | 76 |
} |
86 | 77 |
|
87 | 78 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/library/main/DistortedLibrary.java | ||
---|---|---|
347 | 347 |
|
348 | 348 |
fullVertHeader += "#define PREAPPLY\n"; |
349 | 349 |
|
350 |
String[] feedback = { "v_Position", "v_endPosition", "v_Inflate" };
|
|
350 |
String[] feedback = { "v_Position", "v_endPosition" }; |
|
351 | 351 |
|
352 | 352 |
try |
353 | 353 |
{ |
src/main/java/org/distorted/library/mesh/AssociationUniformBlock.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.mesh; |
|
21 |
|
|
22 |
import android.opengl.GLES30; |
|
23 |
|
|
24 |
import org.distorted.library.main.InternalBuffer; |
|
25 |
|
|
26 |
import static org.distorted.library.mesh.MeshBase.MAX_EFFECT_COMPONENTS; |
|
27 |
|
|
28 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
29 |
|
|
30 |
class AssociationUniformBlock |
|
31 |
{ |
|
32 |
private static final int ASSOCIATION_SIZE = 16*MAX_EFFECT_COMPONENTS; |
|
33 |
private static final int DEFAULT_ASSOCIATION = 0xffffffff; |
|
34 |
|
|
35 |
private InternalBuffer mUBO; |
|
36 |
private int[] mAssociations; |
|
37 |
|
|
38 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
39 |
|
|
40 |
AssociationUniformBlock() |
|
41 |
{ |
|
42 |
mAssociations= new int[ASSOCIATION_SIZE/4]; |
|
43 |
|
|
44 |
for(int i=0; i<MAX_EFFECT_COMPONENTS; i++) |
|
45 |
{ |
|
46 |
mAssociations[4*i ] = DEFAULT_ASSOCIATION; |
|
47 |
mAssociations[4*i+2] = i; |
|
48 |
} |
|
49 |
|
|
50 |
mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ); |
|
51 |
} |
|
52 |
|
|
53 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
54 |
|
|
55 |
AssociationUniformBlock( AssociationUniformBlock original) |
|
56 |
{ |
|
57 |
int size = original.mAssociations.length; |
|
58 |
mAssociations= new int[size]; |
|
59 |
System.arraycopy(original.mAssociations, 0, mAssociations, 0, size); |
|
60 |
|
|
61 |
mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ); |
|
62 |
} |
|
63 |
|
|
64 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
65 |
|
|
66 |
boolean matchesAssociation( int comp, int andAssoc, int equAssoc) |
|
67 |
{ |
|
68 |
return (andAssoc & mAssociations[4*comp]) != 0 || (equAssoc == mAssociations[4*comp+2]); |
|
69 |
} |
|
70 |
|
|
71 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
72 |
|
|
73 |
void setEffectAssociationNow(int comp, int andAssociation, int equAssociation) |
|
74 |
{ |
|
75 |
mAssociations[4*comp ] = andAssociation; |
|
76 |
mAssociations[4*comp+2] = equAssociation; |
|
77 |
|
|
78 |
mUBO.invalidate(); |
|
79 |
} |
|
80 |
|
|
81 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
82 |
|
|
83 |
int getIndex() |
|
84 |
{ |
|
85 |
return mUBO.createImmediatelyInt( ASSOCIATION_SIZE, mAssociations); |
|
86 |
} |
|
87 |
|
|
88 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
89 |
|
|
90 |
void copy( int compTo, AssociationUniformBlock assocFrom, int compFrom) |
|
91 |
{ |
|
92 |
mAssociations[4*compTo ] = assocFrom.mAssociations[4*compFrom ]; |
|
93 |
mAssociations[4*compTo+2] = assocFrom.mAssociations[4*compFrom+2]; |
|
94 |
} |
|
95 |
} |
src/main/java/org/distorted/library/mesh/MeshBase.java | ||
---|---|---|
46 | 46 |
*/ |
47 | 47 |
public abstract class MeshBase |
48 | 48 |
{ |
49 |
private static final int UBO_BINDING = 3; |
|
49 |
private static final int ASSOC_UBO_BINDING = 3; |
|
50 |
private static final int CENTER_UBO_BINDING = 4; |
|
50 | 51 |
static final int MAX_EFFECT_COMPONENTS= 100; |
51 | 52 |
|
52 | 53 |
// sizes of attributes of an individual vertex. |
53 | 54 |
private static final int POS_DATA_SIZE= 3; // vertex coordinates: x,y,z |
54 | 55 |
private static final int NOR_DATA_SIZE= 3; // normal vector: x,y,z |
55 |
private static final int INF_DATA_SIZE= 3; // 'inflate' vector: x,y,z |
|
56 | 56 |
private static final int TEX_DATA_SIZE= 2; // texture coordinates: s,t |
57 | 57 |
private static final int COM_DATA_SIZE= 1; // component number, a single float |
58 | 58 |
|
59 | 59 |
static final int POS_ATTRIB = 0; |
60 | 60 |
static final int NOR_ATTRIB = POS_DATA_SIZE; |
61 |
static final int INF_ATTRIB = POS_DATA_SIZE + NOR_DATA_SIZE; |
|
62 | 61 |
static final int TEX_ATTRIB = 0; |
63 | 62 |
static final int COM_ATTRIB = TEX_DATA_SIZE; |
64 | 63 |
|
65 |
static final int VERT1_ATTRIBS= POS_DATA_SIZE + NOR_DATA_SIZE + INF_DATA_SIZE; // number of attributes of a vertex (the part changed by preapply)
|
|
66 |
static final int VERT2_ATTRIBS= TEX_DATA_SIZE + COM_DATA_SIZE; // number of attributes of a vertex (the 'preapply invariant' part)
|
|
67 |
static final int TRAN_ATTRIBS = POS_DATA_SIZE + NOR_DATA_SIZE + INF_DATA_SIZE; // number of attributes of a transform feedback vertex
|
|
64 |
static final int VERT1_ATTRIBS= POS_DATA_SIZE + NOR_DATA_SIZE; // number of attributes of a vertex (the part changed by preapply) |
|
65 |
static final int VERT2_ATTRIBS= TEX_DATA_SIZE + COM_DATA_SIZE; // number of attributes of a vertex (the 'preapply invariant' part) |
|
66 |
static final int TRAN_ATTRIBS = POS_DATA_SIZE + NOR_DATA_SIZE; // number of attributes of a transform feedback vertex |
|
68 | 67 |
|
69 | 68 |
private static final int BYTES_PER_FLOAT = 4; |
70 | 69 |
|
71 | 70 |
private static final int OFFSET_POS = POS_ATTRIB*BYTES_PER_FLOAT; |
72 | 71 |
private static final int OFFSET_NOR = NOR_ATTRIB*BYTES_PER_FLOAT; |
73 |
private static final int OFFSET_INF = INF_ATTRIB*BYTES_PER_FLOAT; |
|
74 | 72 |
private static final int OFFSET_TEX = TEX_ATTRIB*BYTES_PER_FLOAT; |
75 | 73 |
private static final int OFFSET_COM = COM_ATTRIB*BYTES_PER_FLOAT; |
76 | 74 |
|
... | ... | |
81 | 79 |
private boolean mShowNormals; // when rendering this mesh, draw normal vectors? |
82 | 80 |
private InternalBuffer mVBO1, mVBO2, mTFO; // main vertex buffer and transform feedback buffer |
83 | 81 |
private int mNumVertices; |
84 |
private float[] mVertAttribs1; // packed: PosX,PosY,PosZ, NorX,NorY,NorZ, InfX,InfY,InfZ
|
|
82 |
private float[] mVertAttribs1; // packed: PosX,PosY,PosZ, NorX,NorY,NorZ |
|
85 | 83 |
private float[] mVertAttribs2; // packed: TexS,TexT, Component |
86 | 84 |
private float mInflate; |
87 |
private AssociationUniformBlock mAUB; |
|
85 |
private UniformBlockAssociation mUBA; |
|
86 |
private UniformBlockCenter mUBC; |
|
88 | 87 |
|
89 | 88 |
DeferredJobs.JobNode[] mJobNode; |
90 | 89 |
|
91 |
private static final int TEX_COMP_SIZE = 5; // 5 four-bytes entities inside the component
|
|
90 |
private static final int TEX_COMP_SIZE = 5; // 5 four-byte entities inside the component |
|
92 | 91 |
|
93 | 92 |
private static class TexComponent |
94 | 93 |
{ |
... | ... | |
131 | 130 |
|
132 | 131 |
mJobNode = new DeferredJobs.JobNode[1]; |
133 | 132 |
|
134 |
mAUB = new AssociationUniformBlock(); |
|
133 |
mUBA = new UniformBlockAssociation(); |
|
134 |
mUBC = new UniformBlockCenter(); |
|
135 | 135 |
|
136 | 136 |
mVBO1= new InternalBuffer(GLES30.GL_ARRAY_BUFFER , GLES30.GL_STATIC_READ); |
137 | 137 |
mVBO2= new InternalBuffer(GLES30.GL_ARRAY_BUFFER , GLES30.GL_STATIC_READ); |
... | ... | |
147 | 147 |
mInflate = original.mInflate; |
148 | 148 |
mNumVertices= original.mNumVertices; |
149 | 149 |
|
150 |
mAUB = new AssociationUniformBlock(original.mAUB); |
|
150 |
mUBA = new UniformBlockAssociation(original.mUBA); |
|
151 |
mUBC = new UniformBlockCenter(original.mUBC); |
|
151 | 152 |
|
152 | 153 |
if( deep ) |
153 | 154 |
{ |
... | ... | |
254 | 255 |
start = end+1; |
255 | 256 |
end = mEffComponent.get(comp); |
256 | 257 |
|
257 |
if( mAUB.matchesAssociation(comp, andAssoc, equAssoc) )
|
|
258 |
if( mUBA.matchesAssociation(comp, andAssoc, equAssoc) )
|
|
258 | 259 |
{ |
259 | 260 |
applyMatrixToComponent(matrixP, matrixV, start, end); |
260 | 261 |
} |
... | ... | |
299 | 300 |
mVertAttribs1[index+NOR_ATTRIB+1] /= len1; |
300 | 301 |
mVertAttribs1[index+NOR_ATTRIB+2] /= len1; |
301 | 302 |
} |
302 |
|
|
303 |
x = mVertAttribs1[index+INF_ATTRIB ]; |
|
304 |
y = mVertAttribs1[index+INF_ATTRIB+1]; |
|
305 |
z = mVertAttribs1[index+INF_ATTRIB+2]; |
|
306 |
|
|
307 |
mVertAttribs1[index+INF_ATTRIB ] = matrixV[0]*x + matrixV[4]*y + matrixV[ 8]*z; |
|
308 |
mVertAttribs1[index+INF_ATTRIB+1] = matrixV[1]*x + matrixV[5]*y + matrixV[ 9]*z; |
|
309 |
mVertAttribs1[index+INF_ATTRIB+2] = matrixV[2]*x + matrixV[6]*y + matrixV[10]*z; |
|
310 |
|
|
311 |
x = mVertAttribs1[index+INF_ATTRIB ]; |
|
312 |
y = mVertAttribs1[index+INF_ATTRIB+1]; |
|
313 |
z = mVertAttribs1[index+INF_ATTRIB+2]; |
|
314 |
|
|
315 |
float len2 = (float)Math.sqrt(x*x + y*y + z*z); |
|
316 |
|
|
317 |
if( len2>0.0f ) |
|
318 |
{ |
|
319 |
mVertAttribs1[index+INF_ATTRIB ] /= len2; |
|
320 |
mVertAttribs1[index+INF_ATTRIB+1] /= len2; |
|
321 |
mVertAttribs1[index+INF_ATTRIB+2] /= len2; |
|
322 |
} |
|
323 | 303 |
} |
324 | 304 |
} |
325 | 305 |
|
... | ... | |
327 | 307 |
|
328 | 308 |
void setEffectAssociationNow(int component, int andAssociation, int equAssociation) |
329 | 309 |
{ |
330 |
mAUB.setEffectAssociationNow(component, andAssociation, equAssociation); |
|
310 |
mUBA.setEffectAssociationNow(component, andAssociation, equAssociation); |
|
311 |
} |
|
312 |
|
|
313 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
314 |
|
|
315 |
void setEffectCenterNow(int component, float x, float y, float z) |
|
316 |
{ |
|
317 |
mUBC.setEffectCenterNow(component, x, y, z); |
|
331 | 318 |
} |
332 | 319 |
|
333 | 320 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
393 | 380 |
|
394 | 381 |
if( origEffComponents<MAX_EFFECT_COMPONENTS ) |
395 | 382 |
{ |
396 |
mAUB.copy(origEffComponents, mesh.mAUB, j); |
|
383 |
mUBA.copy(origEffComponents, mesh.mUBA, j); |
|
384 |
mUBC.copy(origEffComponents, mesh.mUBC, j); |
|
397 | 385 |
origEffComponents++; |
398 | 386 |
} |
399 | 387 |
} |
... | ... | |
690 | 678 |
*/ |
691 | 679 |
public void send(int programH) |
692 | 680 |
{ |
693 |
int index = mAUB.getIndex(); |
|
694 |
GLES30.glBindBufferBase(GLES30.GL_UNIFORM_BUFFER, UBO_BINDING, index); |
|
695 |
GLES30.glUniformBlockBinding(programH, UBO_BINDING, index); |
|
681 |
int indexA = mUBA.getIndex(); |
|
682 |
GLES30.glBindBufferBase(GLES30.GL_UNIFORM_BUFFER, ASSOC_UBO_BINDING, indexA); |
|
683 |
GLES30.glUniformBlockBinding(programH, ASSOC_UBO_BINDING, indexA); |
|
684 |
|
|
685 |
int indexC = mUBC.getIndex(); |
|
686 |
GLES30.glBindBufferBase(GLES30.GL_UNIFORM_BUFFER, CENTER_UBO_BINDING, indexC); |
|
687 |
GLES30.glUniformBlockBinding(programH, CENTER_UBO_BINDING, indexC); |
|
696 | 688 |
} |
697 | 689 |
|
698 | 690 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
727 | 719 |
GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, index1 ); |
728 | 720 |
GLES30.glVertexAttribPointer(program.mAttribute[0], POS_DATA_SIZE, GLES30.GL_FLOAT, false, VERT1_SIZE, OFFSET_POS); |
729 | 721 |
GLES30.glVertexAttribPointer(program.mAttribute[1], NOR_DATA_SIZE, GLES30.GL_FLOAT, false, VERT1_SIZE, OFFSET_NOR); |
730 |
GLES30.glVertexAttribPointer(program.mAttribute[2], INF_DATA_SIZE, GLES30.GL_FLOAT, false, VERT1_SIZE, OFFSET_INF); |
|
731 | 722 |
GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, index2 ); |
732 |
GLES30.glVertexAttribPointer(program.mAttribute[3], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, VERT2_SIZE, OFFSET_TEX);
|
|
733 |
GLES30.glVertexAttribPointer(program.mAttribute[4], COM_DATA_SIZE, GLES30.GL_FLOAT, false, VERT2_SIZE, OFFSET_COM);
|
|
723 |
GLES30.glVertexAttribPointer(program.mAttribute[2], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, VERT2_SIZE, OFFSET_TEX);
|
|
724 |
GLES30.glVertexAttribPointer(program.mAttribute[3], COM_DATA_SIZE, GLES30.GL_FLOAT, false, VERT2_SIZE, OFFSET_COM);
|
|
734 | 725 |
GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, 0); |
735 | 726 |
} |
736 | 727 |
|
... | ... | |
786 | 777 |
|
787 | 778 |
version = byteBuf.getInt(0); |
788 | 779 |
|
789 |
if( version==1 ) |
|
780 |
if( version==1 || version==2 )
|
|
790 | 781 |
{ |
791 | 782 |
mNumVertices= byteBuf.getInt(4); |
792 | 783 |
numTex = byteBuf.getInt(8); |
... | ... | |
811 | 802 |
mVertAttribs1 = new float[VERT1_ATTRIBS*mNumVertices]; |
812 | 803 |
mVertAttribs2 = new float[VERT2_ATTRIBS*mNumVertices]; |
813 | 804 |
|
814 |
buffer = new byte[BYTES_PER_FLOAT*(size + mNumVertices*(VERT1_ATTRIBS+VERT2_ATTRIBS))]; |
|
805 |
// version 1 had extra 3 floats (the 'inflate' vector) in its vert1 array |
|
806 |
int vert1InFile = version==1 ? VERT1_ATTRIBS+3 : VERT1_ATTRIBS; |
|
807 |
|
|
808 |
buffer = new byte[BYTES_PER_FLOAT*(size + mNumVertices*(vert1InFile+VERT2_ATTRIBS))]; |
|
815 | 809 |
|
816 | 810 |
try |
817 | 811 |
{ |
... | ... | |
827 | 821 |
FloatBuffer floatBuf = byteBuf.asFloatBuffer(); |
828 | 822 |
|
829 | 823 |
floatBuf.get(tmp,0,size); |
830 |
floatBuf.get(mVertAttribs1, 0, VERT1_ATTRIBS*mNumVertices); |
|
824 |
|
|
825 |
switch(version) |
|
826 |
{ |
|
827 |
case 1 : int index = floatBuf.position(); |
|
828 |
|
|
829 |
for(int vert=0; vert<mNumVertices; vert++) |
|
830 |
{ |
|
831 |
mVertAttribs1[VERT1_ATTRIBS*vert+POS_ATTRIB ] = floatBuf.get(index+POS_ATTRIB ); |
|
832 |
mVertAttribs1[VERT1_ATTRIBS*vert+POS_ATTRIB+1] = floatBuf.get(index+POS_ATTRIB+1); |
|
833 |
mVertAttribs1[VERT1_ATTRIBS*vert+POS_ATTRIB+2] = floatBuf.get(index+POS_ATTRIB+2); |
|
834 |
mVertAttribs1[VERT1_ATTRIBS*vert+NOR_ATTRIB ] = floatBuf.get(index+NOR_ATTRIB ); |
|
835 |
mVertAttribs1[VERT1_ATTRIBS*vert+NOR_ATTRIB+1] = floatBuf.get(index+NOR_ATTRIB+1); |
|
836 |
mVertAttribs1[VERT1_ATTRIBS*vert+NOR_ATTRIB+2] = floatBuf.get(index+NOR_ATTRIB+2); |
|
837 |
index+=vert1InFile; |
|
838 |
} |
|
839 |
floatBuf.position(index); |
|
840 |
break; |
|
841 |
case 2 : floatBuf.get(mVertAttribs1, 0, VERT1_ATTRIBS*mNumVertices); |
|
842 |
break; |
|
843 |
default: android.util.Log.e("mesh", "Error: unknown mesh file version "+String.format("0x%08X", version)); |
|
844 |
return 0; |
|
845 |
} |
|
846 |
|
|
831 | 847 |
floatBuf.get(mVertAttribs2, 0, VERT2_ATTRIBS*mNumVertices); |
832 | 848 |
|
833 | 849 |
TexComponent tex; |
... | ... | |
902 | 918 |
|
903 | 919 |
try |
904 | 920 |
{ |
905 |
stream.writeInt(1); // version
|
|
921 |
stream.writeInt(2); // version
|
|
906 | 922 |
stream.writeInt(mNumVertices); |
907 | 923 |
stream.writeInt(numTex); |
908 | 924 |
stream.writeInt(numEff); |
... | ... | |
1152 | 1168 |
* Copy the Mesh. |
1153 | 1169 |
* |
1154 | 1170 |
* @param deep If to be a deep or shallow copy of mVertAttribs1, i.e. the array holding vertices, |
1155 |
* normals and inflates (the rest, in particular the mVertAttribs2 containing texture
|
|
1171 |
* and normals (the rest, in particular the mVertAttribs2 containing texture
|
|
1156 | 1172 |
* coordinates and effect associations, is always deep copied) |
1157 | 1173 |
*/ |
1158 | 1174 |
public abstract MeshBase copy(boolean deep); |
src/main/java/org/distorted/library/mesh/MeshCubes.java | ||
---|---|---|
628 | 628 |
attribs1[VERT1_ATTRIBS*currVert + NOR_ATTRIB+1] = mNormalY[index]; |
629 | 629 |
attribs1[VERT1_ATTRIBS*currVert + NOR_ATTRIB+2] = mNormalZ[index]; |
630 | 630 |
|
631 |
attribs1[VERT1_ATTRIBS*currVert + INF_ATTRIB ] = mInflateX[row][col]/2.0f; |
|
632 |
attribs1[VERT1_ATTRIBS*currVert + INF_ATTRIB+1] = mInflateY[row][col]/2.0f; |
|
633 |
attribs1[VERT1_ATTRIBS*currVert + INF_ATTRIB+2] = vectZ; |
|
634 |
|
|
635 | 631 |
if( vectZ>0 ) |
636 | 632 |
{ |
637 | 633 |
attribs2[VERT2_ATTRIBS*currVert + TEX_ATTRIB ] = mTexMappingX[FRONT] + x * mTexMappingW[FRONT]; |
... | ... | |
669 | 665 |
attribs1[VERT1_ATTRIBS*currVert + NOR_ATTRIB+1] = 1.0f; |
670 | 666 |
attribs1[VERT1_ATTRIBS*currVert + NOR_ATTRIB+2] = (slice==0 ? R : (slice==mSlices ? -R:0) ); |
671 | 667 |
|
672 |
attribs1[VERT1_ATTRIBS*currVert + INF_ATTRIB ] = mInflateX[row][col]/2.0f; |
|
673 |
attribs1[VERT1_ATTRIBS*currVert + INF_ATTRIB+1] = mInflateY[row][col]/2.0f; |
|
674 |
attribs1[VERT1_ATTRIBS*currVert + INF_ATTRIB+2] = z; |
|
675 |
|
|
676 | 668 |
attribs2[VERT2_ATTRIBS*currVert + TEX_ATTRIB ] = mTexMappingX[TOP] + x * mTexMappingW[TOP]; |
677 | 669 |
attribs2[VERT2_ATTRIBS*currVert + TEX_ATTRIB+1] = mTexMappingY[TOP] + (0.5f-z) * mTexMappingH[TOP]; |
678 | 670 |
|
... | ... | |
691 | 683 |
attribs1[VERT1_ATTRIBS*currVert + NOR_ATTRIB+1] =-1.0f; |
692 | 684 |
attribs1[VERT1_ATTRIBS*currVert + NOR_ATTRIB+2] = (slice==0 ? R : (slice==mSlices ? -R:0) ); |
693 | 685 |
|
694 |
attribs1[VERT1_ATTRIBS*currVert + INF_ATTRIB ] = mInflateX[row][col]/2.0f; |
|
695 |
attribs1[VERT1_ATTRIBS*currVert + INF_ATTRIB+1] = mInflateY[row][col]/2.0f; |
|
696 |
attribs1[VERT1_ATTRIBS*currVert + INF_ATTRIB+2] = z; |
|
697 |
|
|
698 | 686 |
attribs2[VERT2_ATTRIBS*currVert + TEX_ATTRIB ] = mTexMappingX[BOTTOM] + x * mTexMappingW[BOTTOM]; |
699 | 687 |
attribs2[VERT2_ATTRIBS*currVert + TEX_ATTRIB+1] = mTexMappingY[BOTTOM] + (0.5f-z) * mTexMappingH[BOTTOM]; |
700 | 688 |
|
... | ... | |
713 | 701 |
attribs1[VERT1_ATTRIBS*currVert + NOR_ATTRIB+1] = side==WEST ? 0.0f : (side==NORTH?-R:R); |
714 | 702 |
attribs1[VERT1_ATTRIBS*currVert + NOR_ATTRIB+2] = (slice==0 ? R : (slice==mSlices ? -R:0) ); |
715 | 703 |
|
716 |
attribs1[VERT1_ATTRIBS*currVert + INF_ATTRIB ] = mInflateX[row][col]/2.0f; |
|
717 |
attribs1[VERT1_ATTRIBS*currVert + INF_ATTRIB+1] = mInflateY[row][col]/2.0f; |
|
718 |
attribs1[VERT1_ATTRIBS*currVert + INF_ATTRIB+2] = z; |
|
719 |
|
|
720 | 704 |
attribs2[VERT2_ATTRIBS*currVert + TEX_ATTRIB ] = mTexMappingX[LEFT] + (0.5f-z) * mTexMappingW[LEFT]; |
721 | 705 |
attribs2[VERT2_ATTRIBS*currVert + TEX_ATTRIB+1] = mTexMappingY[LEFT] + (1.0f-y) * mTexMappingH[LEFT]; |
722 | 706 |
|
... | ... | |
735 | 719 |
attribs1[VERT1_ATTRIBS*currVert + NOR_ATTRIB+1] = side==EAST ? 0.0f : (side==SOUTH?-R:R); |
736 | 720 |
attribs1[VERT1_ATTRIBS*currVert + NOR_ATTRIB+2] = (slice==0 ? R : (slice==mSlices ? -R:0) ); |
737 | 721 |
|
738 |
attribs1[VERT1_ATTRIBS*currVert + INF_ATTRIB ] = mInflateX[row][col]/2.0f; |
|
739 |
attribs1[VERT1_ATTRIBS*currVert + INF_ATTRIB+1] = mInflateY[row][col]/2.0f; |
|
740 |
attribs1[VERT1_ATTRIBS*currVert + INF_ATTRIB+2] = z; |
|
741 |
|
|
742 | 722 |
attribs2[VERT2_ATTRIBS*currVert + TEX_ATTRIB ] = mTexMappingX[RIGHT] + (0.5f-z) * mTexMappingW[RIGHT]; |
743 | 723 |
attribs2[VERT2_ATTRIBS*currVert + TEX_ATTRIB+1] = mTexMappingY[RIGHT] + (1.0f-y) * mTexMappingH[RIGHT]; |
744 | 724 |
|
... | ... | |
760 | 740 |
attribs1[VERT1_ATTRIBS*currVert + NOR_ATTRIB+1] = attribs1[VERT1_ATTRIBS*(currVert-1) + NOR_ATTRIB+1]; |
761 | 741 |
attribs1[VERT1_ATTRIBS*currVert + NOR_ATTRIB+2] = attribs1[VERT1_ATTRIBS*(currVert-1) + NOR_ATTRIB+2]; |
762 | 742 |
|
763 |
attribs1[VERT1_ATTRIBS*currVert + INF_ATTRIB ] = attribs1[VERT1_ATTRIBS*(currVert-1) + INF_ATTRIB ]; |
|
764 |
attribs1[VERT1_ATTRIBS*currVert + INF_ATTRIB+1] = attribs1[VERT1_ATTRIBS*(currVert-1) + INF_ATTRIB+1]; |
|
765 |
attribs1[VERT1_ATTRIBS*currVert + INF_ATTRIB+2] = attribs1[VERT1_ATTRIBS*(currVert-1) + INF_ATTRIB+2]; |
|
766 |
|
|
767 | 743 |
attribs2[VERT2_ATTRIBS*currVert + TEX_ATTRIB ] = attribs2[VERT2_ATTRIBS*(currVert-1) + TEX_ATTRIB ]; |
768 | 744 |
attribs2[VERT2_ATTRIBS*currVert + TEX_ATTRIB+1] = attribs2[VERT2_ATTRIBS*(currVert-1) + TEX_ATTRIB+1]; |
769 | 745 |
|
src/main/java/org/distorted/library/mesh/MeshQuad.java | ||
---|---|---|
40 | 40 |
attribs1[VERT1_ATTRIBS*index + NOR_ATTRIB+1] = 0.0f; |
41 | 41 |
attribs1[VERT1_ATTRIBS*index + NOR_ATTRIB+2] = 1.0f; |
42 | 42 |
|
43 |
attribs1[VERT1_ATTRIBS*index + INF_ATTRIB ] = (x-0.5f); |
|
44 |
attribs1[VERT1_ATTRIBS*index + INF_ATTRIB+1] = (0.5f-y); |
|
45 |
attribs1[VERT1_ATTRIBS*index + INF_ATTRIB+2] = 0.01f ; // Inflated surface needs to be slightly in front |
|
46 |
|
|
47 | 43 |
attribs2[VERT2_ATTRIBS*index + TEX_ATTRIB ] = x; |
48 | 44 |
attribs2[VERT2_ATTRIBS*index + TEX_ATTRIB+1] = 1.0f-y; |
49 | 45 |
} |
src/main/java/org/distorted/library/mesh/MeshRectangles.java | ||
---|---|---|
67 | 67 |
attribs1[VERT1_ATTRIBS*vertex + NOR_ATTRIB+1] = 0.0f; |
68 | 68 |
attribs1[VERT1_ATTRIBS*vertex + NOR_ATTRIB+2] = 1.0f; |
69 | 69 |
|
70 |
attribs1[VERT1_ATTRIBS*vertex + INF_ATTRIB ] = x; |
|
71 |
attribs1[VERT1_ATTRIBS*vertex + INF_ATTRIB+1] = -y; |
|
72 |
attribs1[VERT1_ATTRIBS*vertex + INF_ATTRIB+2] = 0.01f; // Inflated surface needs to be slightly in front |
|
73 |
|
|
74 | 70 |
attribs2[VERT2_ATTRIBS*vertex + TEX_ATTRIB ] = x+0.5f; |
75 | 71 |
attribs2[VERT2_ATTRIBS*vertex + TEX_ATTRIB+1] = 0.5f-y; |
76 | 72 |
|
... | ... | |
93 | 89 |
attribs1[VERT1_ATTRIBS*vertex + NOR_ATTRIB+1] = attribs1[VERT1_ATTRIBS*(vertex-1) + NOR_ATTRIB+1]; |
94 | 90 |
attribs1[VERT1_ATTRIBS*vertex + NOR_ATTRIB+2] = attribs1[VERT1_ATTRIBS*(vertex-1) + NOR_ATTRIB+2]; |
95 | 91 |
|
96 |
attribs1[VERT1_ATTRIBS*vertex + INF_ATTRIB ] = attribs1[VERT1_ATTRIBS*(vertex-1) + INF_ATTRIB ]; |
|
97 |
attribs1[VERT1_ATTRIBS*vertex + INF_ATTRIB+1] = attribs1[VERT1_ATTRIBS*(vertex-1) + INF_ATTRIB+1]; |
|
98 |
attribs1[VERT1_ATTRIBS*vertex + INF_ATTRIB+2] = attribs1[VERT1_ATTRIBS*(vertex-1) + INF_ATTRIB+2]; |
|
99 |
|
|
100 | 92 |
attribs2[VERT2_ATTRIBS*vertex + TEX_ATTRIB ] = attribs2[VERT2_ATTRIBS*(vertex-1) + TEX_ATTRIB ]; |
101 | 93 |
attribs2[VERT2_ATTRIBS*vertex + TEX_ATTRIB+1] = attribs2[VERT2_ATTRIBS*(vertex-1) + TEX_ATTRIB+1]; |
102 | 94 |
|
src/main/java/org/distorted/library/mesh/MeshSphere.java | ||
---|---|---|
89 | 89 |
attribs1[VERT1_ATTRIBS*currentVert + NOR_ATTRIB+1] = attribs1[VERT1_ATTRIBS*(currentVert-1) + NOR_ATTRIB+1]; |
90 | 90 |
attribs1[VERT1_ATTRIBS*currentVert + NOR_ATTRIB+2] = attribs1[VERT1_ATTRIBS*(currentVert-1) + NOR_ATTRIB+2]; |
91 | 91 |
|
92 |
attribs1[VERT1_ATTRIBS*currentVert + INF_ATTRIB ] = attribs1[VERT1_ATTRIBS*(currentVert-1) + INF_ATTRIB ]; |
|
93 |
attribs1[VERT1_ATTRIBS*currentVert + INF_ATTRIB+1] = attribs1[VERT1_ATTRIBS*(currentVert-1) + INF_ATTRIB+1]; |
|
94 |
attribs1[VERT1_ATTRIBS*currentVert + INF_ATTRIB+2] = attribs1[VERT1_ATTRIBS*(currentVert-1) + INF_ATTRIB+2]; |
|
95 |
|
|
96 | 92 |
attribs2[VERT2_ATTRIBS*currentVert + TEX_ATTRIB ] = attribs2[VERT2_ATTRIBS*(currentVert-1) + TEX_ATTRIB ]; |
97 | 93 |
attribs2[VERT2_ATTRIBS*currentVert + TEX_ATTRIB+1] = attribs2[VERT2_ATTRIBS*(currentVert-1) + TEX_ATTRIB+1]; |
98 | 94 |
|
... | ... | |
191 | 187 |
attribs1[VERT1_ATTRIBS*currentVert + NOR_ATTRIB ] = 2*x;// the vertex coords, normal vector, and |
192 | 188 |
attribs1[VERT1_ATTRIBS*currentVert + NOR_ATTRIB+1] = 2*y;// inflate vector have identical (x,y,z). |
193 | 189 |
attribs1[VERT1_ATTRIBS*currentVert + NOR_ATTRIB+2] = 2*z;// |
194 |
// TODO: think about some more efficient |
|
195 |
attribs1[VERT1_ATTRIBS*currentVert + INF_ATTRIB ] = x; // representation. |
|
196 |
attribs1[VERT1_ATTRIBS*currentVert + INF_ATTRIB+1] = y; // |
|
197 |
attribs1[VERT1_ATTRIBS*currentVert + INF_ATTRIB+2] = z; // |
|
198 | 190 |
|
199 | 191 |
attribs2[VERT2_ATTRIBS*currentVert + TEX_ATTRIB ] = (float)texX; |
200 | 192 |
attribs2[VERT2_ATTRIBS*currentVert + TEX_ATTRIB+1] = (float)texY; |
src/main/java/org/distorted/library/mesh/MeshTriangles.java | ||
---|---|---|
42 | 42 |
attribs1[VERT1_ATTRIBS*vertex + NOR_ATTRIB+1] = 0.0f; |
43 | 43 |
attribs1[VERT1_ATTRIBS*vertex + NOR_ATTRIB+2] = 1.0f; |
44 | 44 |
|
45 |
attribs1[VERT1_ATTRIBS*vertex + INF_ATTRIB ] = (x-0.5f); |
|
46 |
attribs1[VERT1_ATTRIBS*vertex + INF_ATTRIB+1] = (y-0.33f); |
|
47 |
attribs1[VERT1_ATTRIBS*vertex + INF_ATTRIB+2] = 0.01f ; // Inflated surface needs to be slightly in front |
|
48 |
|
|
49 | 45 |
attribs2[VERT2_ATTRIBS*vertex + TEX_ATTRIB ] = x; |
50 | 46 |
attribs2[VERT2_ATTRIBS*vertex + TEX_ATTRIB+1] = y; |
51 | 47 |
|
src/main/java/org/distorted/library/mesh/UniformBlockAssociation.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.mesh; |
|
21 |
|
|
22 |
import android.opengl.GLES30; |
|
23 |
|
|
24 |
import org.distorted.library.main.InternalBuffer; |
|
25 |
|
|
26 |
import static org.distorted.library.mesh.MeshBase.MAX_EFFECT_COMPONENTS; |
|
27 |
|
|
28 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
29 |
|
|
30 |
class UniformBlockAssociation |
|
31 |
{ |
|
32 |
private static final int BLOCK_SIZE = 16*MAX_EFFECT_COMPONENTS; |
|
33 |
private static final int DEFAULT_ASSOCIATION = 0xffffffff; |
|
34 |
|
|
35 |
private InternalBuffer mUBO; |
|
36 |
private int[] mAssociations; |
|
37 |
|
|
38 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
39 |
|
|
40 |
UniformBlockAssociation() |
|
41 |
{ |
|
42 |
mAssociations= new int[BLOCK_SIZE/4]; |
|
43 |
|
|
44 |
for(int i=0; i<MAX_EFFECT_COMPONENTS; i++) |
|
45 |
{ |
|
46 |
mAssociations[4*i ] = DEFAULT_ASSOCIATION; |
|
47 |
mAssociations[4*i+2] = i; |
|
48 |
} |
|
49 |
|
|
50 |
mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ); |
|
51 |
} |
|
52 |
|
|
53 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
54 |
|
|
55 |
UniformBlockAssociation(UniformBlockAssociation original) |
|
56 |
{ |
|
57 |
int size = original.mAssociations.length; |
|
58 |
mAssociations= new int[size]; |
|
59 |
System.arraycopy(original.mAssociations, 0, mAssociations, 0, size); |
|
60 |
|
|
61 |
mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ); |
|
62 |
} |
|
63 |
|
|
64 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
65 |
|
|
66 |
boolean matchesAssociation( int comp, int andAssoc, int equAssoc) |
|
67 |
{ |
|
68 |
return (andAssoc & mAssociations[4*comp]) != 0 || (equAssoc == mAssociations[4*comp+2]); |
|
69 |
} |
|
70 |
|
|
71 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
72 |
|
|
73 |
void setEffectAssociationNow(int comp, int andAssociation, int equAssociation) |
|
74 |
{ |
|
75 |
mAssociations[4*comp ] = andAssociation; |
|
76 |
mAssociations[4*comp+2] = equAssociation; |
|
77 |
|
|
78 |
mUBO.invalidate(); |
|
79 |
} |
|
80 |
|
|
81 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
82 |
|
|
83 |
int getIndex() |
|
84 |
{ |
|
85 |
return mUBO.createImmediatelyInt( BLOCK_SIZE, mAssociations); |
|
86 |
} |
|
87 |
|
|
88 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
89 |
|
|
90 |
void copy(int compTo, UniformBlockAssociation assocFrom, int compFrom) |
|
91 |
{ |
|
92 |
mAssociations[4*compTo ] = assocFrom.mAssociations[4*compFrom ]; |
|
93 |
mAssociations[4*compTo+2] = assocFrom.mAssociations[4*compFrom+2]; |
|
94 |
} |
|
95 |
} |
src/main/java/org/distorted/library/mesh/UniformBlockCenter.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.mesh; |
|
21 |
|
|
22 |
import android.opengl.GLES30; |
|
23 |
|
|
24 |
import org.distorted.library.main.InternalBuffer; |
|
25 |
|
|
26 |
import static org.distorted.library.mesh.MeshBase.MAX_EFFECT_COMPONENTS; |
|
27 |
|
|
28 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
29 |
|
|
30 |
class UniformBlockCenter |
|
31 |
{ |
|
32 |
private static final int BLOCK_SIZE = 16*MAX_EFFECT_COMPONENTS; |
|
33 |
|
|
34 |
private InternalBuffer mUBO; |
|
35 |
private float[] mCenter; |
|
36 |
|
|
37 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
38 |
|
|
39 |
UniformBlockCenter() |
|
40 |
{ |
|
41 |
mCenter= new float[BLOCK_SIZE/4]; |
|
42 |
mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ); |
|
43 |
} |
|
44 |
|
|
45 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
46 |
|
|
47 |
UniformBlockCenter(UniformBlockCenter original) |
|
48 |
{ |
|
49 |
int size = original.mCenter.length; |
|
50 |
mCenter= new float[size]; |
|
51 |
System.arraycopy(original.mCenter, 0, mCenter, 0, size); |
|
52 |
|
|
53 |
mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ); |
|
54 |
} |
|
55 |
|
|
56 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
57 |
|
|
58 |
void setEffectCenterNow(int comp, float x, float y, float z) |
|
59 |
{ |
|
60 |
mCenter[4*comp ] = x; |
|
61 |
mCenter[4*comp+1] = y; |
|
62 |
mCenter[4*comp+2] = z; |
|
63 |
|
|
64 |
mUBO.invalidate(); |
|
65 |
} |
|
66 |
|
|
67 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
68 |
|
|
69 |
int getIndex() |
|
70 |
{ |
|
71 |
return mUBO.createImmediatelyFloat( BLOCK_SIZE, mCenter); |
|
72 |
} |
|
73 |
|
|
74 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
75 |
|
|
76 |
void copy(int compTo, UniformBlockCenter blockFrom, int compFrom) |
|
77 |
{ |
|
78 |
mCenter[4*compTo ] = blockFrom.mCenter[4*compFrom ]; |
|
79 |
mCenter[4*compTo+1] = blockFrom.mCenter[4*compFrom+1]; |
|
80 |
mCenter[4*compTo+2] = blockFrom.mCenter[4*compFrom+2]; |
|
81 |
} |
|
82 |
} |
src/main/res/raw/main_vertex_shader.glsl | ||
---|---|---|
22 | 22 |
|
23 | 23 |
in vec3 a_Position; // Per-vertex position. |
24 | 24 |
in vec3 a_Normal; // Per-vertex normal vector. |
25 |
in vec3 a_Inflate; // This vector describes the direction this vertex needs to go when we 'inflate' the whole mesh. |
|
26 |
// If the mesh is locally smooth, this is equal to the normal vector. Otherwise (on sharp edges) - no. |
|
27 | 25 |
in vec2 a_TexCoordinate; // Per-vertex texture coordinate. |
28 | 26 |
in float a_Component; // The component a vertex belongs to. |
29 | 27 |
// to a vertex effect. An effect will only be active on a vertex iff (a_Association & vAssociation[effect]) != 0. |
30 | 28 |
// ( see VertexEffect.retSection() ) |
31 | 29 |
|
32 |
out vec3 v_Position; // |
|
30 |
out vec3 v_Position; // for Transform Feedback only
|
|
33 | 31 |
out vec3 v_endPosition; // for Transform Feedback only |
34 |
|
|
35 |
#ifdef PREAPPLY |
|
36 |
out vec3 v_Inflate; // Transform Feedback for preapply effects |
|
37 |
#endif |
|
38 |
|
|
39 | 32 |
out vec3 v_Normal; // |
40 | 33 |
out vec2 v_TexCoordinate; // |
41 | 34 |
|
... | ... | |
46 | 39 |
uniform float u_Inflate; // how much should we inflate (>0.0) or deflate (<0.0) the mesh. |
47 | 40 |
uniform int u_TransformFeedback; // are we doing the transform feedback now? |
48 | 41 |
|
42 |
layout (std140, binding=4) uniform componentCenter |
|
43 |
{ |
|
44 |
vec4 vComCenter[MAX_COMPON]; // centers of earch mesh component. 4 floats: |
|
45 |
// (x,y,z,unused) |
|
46 |
}; |
|
47 |
|
|
49 | 48 |
#if NUM_VERTEX>0 |
50 | 49 |
uniform int vNumEffects; // total number of vertex effects |
51 | 50 |
uniform ivec4 vProperties[NUM_VERTEX];// their properties, 4 ints: |
... | ... | |
58 | 57 |
// The first vec4 is the Interpolated values, |
59 | 58 |
// second vec4: first float - cache, next 3: Center, the third - the Region. |
60 | 59 |
|
61 |
layout (std140, binding=3) uniform meshAssociation
|
|
60 |
layout (std140, binding=3) uniform componentAssociation
|
|
62 | 61 |
{ |
63 | 62 |
ivec4 vComAssoc[MAX_COMPON]; // component Associations, 4 ints: |
64 | 63 |
// 1: component's AND association |
... | ... | |
111 | 110 |
|
112 | 111 |
void main() |
113 | 112 |
{ |
114 |
vec3 v = a_Position + u_Inflate*a_Inflate; |
|
113 |
int component = int(a_Component); |
|
114 |
vec3 v = a_Position + u_Inflate*(a_Position - vComCenter[component].xyz); |
|
115 | 115 |
vec3 n = a_Normal; |
116 | 116 |
|
117 |
#ifdef PREAPPLY |
|
118 |
vec3 inf = a_Inflate; |
|
119 |
#endif |
|
120 |
|
|
121 | 117 |
#if NUM_VERTEX>0 |
122 | 118 |
int effect=0; |
123 |
int component = int(a_Component); |
|
124 | 119 |
|
125 | 120 |
for(int i=0; i<vNumEffects; i++) |
126 | 121 |
{ |
... | ... | |
136 | 131 |
#ifdef PREAPPLY |
137 | 132 |
v_Position = v; |
138 | 133 |
v_endPosition= n; |
139 |
v_Inflate = inf; |
|
140 | 134 |
#else |
141 | 135 |
if( u_TransformFeedback == 1 ) |
142 | 136 |
{ |
Also available in: Unified diff
Remove the 'inflate' vertex attributs from the Mesh and file format, and replace that with a per-component 'inflate centers' (which are as of yet untested)