Revision 24804c15
Added by Leszek Koltunski about 5 years ago
| src/main/java/org/distorted/library/effect/VertexEffect.java | ||
|---|---|---|
| 34 | 34 |
*/ |
| 35 | 35 |
public static final int NUM_FLOAT_UNIFORMS = 12; |
| 36 | 36 |
/** |
| 37 |
* 3: name, AND association, equ Association
|
|
| 37 |
* 4: name, AND association, reserved, EQU Association
|
|
| 38 | 38 |
*/ |
| 39 |
public static final int NUM_INT_UNIFORMS = 3;
|
|
| 39 |
public static final int NUM_INT_UNIFORMS = 4;
|
|
| 40 | 40 |
|
| 41 | 41 |
static final int VALUES_OFFSET = 0; |
| 42 | 42 |
static final int CENTER_OFFSET = 5; |
| ... | ... | |
| 63 | 63 |
{
|
| 64 | 64 |
return |
| 65 | 65 |
|
| 66 |
"if( vName[i]=="+effect+" )\n" +
|
|
| 66 |
"if( vProperties[i].x =="+effect+" )\n" +
|
|
| 67 | 67 |
"{\n" +
|
| 68 | 68 |
code +"\n" + |
| 69 | 69 |
"}\n" + |
| src/main/java/org/distorted/library/effectqueue/EffectQueue.java | ||
|---|---|---|
| 265 | 265 |
} |
| 266 | 266 |
|
| 267 | 267 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 268 |
// this assumes 0<=effect<mNumEffects
|
|
| 268 |
// this assumes 0<=effect |
|
| 269 | 269 |
|
| 270 | 270 |
protected void remove(int effect) |
| 271 | 271 |
{
|
| 272 |
mNumEffects--; |
|
| 273 |
|
|
| 274 |
int max = mMax[mIndex]; |
|
| 275 |
|
|
| 276 |
for(int i=effect; i<mNumEffects; i++ ) |
|
| 272 |
if( mNumEffects>effect ) |
|
| 277 | 273 |
{
|
| 278 |
mEffects[i]= mEffects[i+1]; |
|
| 279 |
|
|
| 280 |
for(int j=0; j<mNumIntUniforms; j++) |
|
| 281 |
{
|
|
| 282 |
mIntUniforms[j*max + i] = mIntUniforms[j*max + i+1]; |
|
| 283 |
} |
|
| 274 |
mNumEffects--; |
|
| 275 |
System.arraycopy(mEffects, effect+1, mEffects, effect, mNumEffects-effect); |
|
| 276 |
System.arraycopy(mIntUniforms, mNumIntUniforms*(effect+1), mIntUniforms, mNumIntUniforms*effect, mNumIntUniforms*(mNumEffects-effect) ); |
|
| 277 |
mEffects[mNumEffects] = null; |
|
| 284 | 278 |
} |
| 285 |
|
|
| 286 |
mEffects[mNumEffects] = null; |
|
| 287 | 279 |
} |
| 288 | 280 |
|
| 289 | 281 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 447 | 439 |
|
| 448 | 440 |
if( position==-1 ) |
| 449 | 441 |
{
|
| 450 |
mEffects[mNumEffects] = job.effect; |
|
| 451 |
mIntUniforms[mNumEffects] = job.effect.getName().ordinal(); |
|
| 442 |
mEffects[mNumEffects] = job.effect;
|
|
| 443 |
mIntUniforms[mNumIntUniforms*mNumEffects] = job.effect.getName().ordinal();
|
|
| 452 | 444 |
|
| 453 | 445 |
mNumEffects++; |
| 454 | 446 |
changed = true; |
| 455 | 447 |
} |
| 456 | 448 |
else if( position>=0 && position<=mNumEffects ) |
| 457 | 449 |
{
|
| 458 |
for(int j=mNumEffects; j>position; j--) |
|
| 459 |
{
|
|
| 460 |
mEffects[j] = mEffects[j-1]; |
|
| 461 |
mIntUniforms[j] = mIntUniforms[j-1]; |
|
| 462 |
} |
|
| 463 |
|
|
| 464 |
mEffects[position] = job.effect; |
|
| 465 |
mIntUniforms[position] = job.effect.getName().ordinal(); |
|
| 450 |
System.arraycopy(mEffects , position, mEffects , position+1, mNumEffects-position); |
|
| 451 |
System.arraycopy(mIntUniforms, mNumIntUniforms*position, mIntUniforms, mNumIntUniforms*(position+1), mNumIntUniforms*(mNumEffects-position) ); |
|
| 452 |
|
|
| 453 |
mEffects[position] = job.effect; |
|
| 454 |
mIntUniforms[mNumIntUniforms*position] = job.effect.getName().ordinal(); |
|
| 466 | 455 |
|
| 467 | 456 |
mNumEffects++; |
| 468 | 457 |
changed = true; |
| src/main/java/org/distorted/library/effectqueue/EffectQueueVertex.java | ||
|---|---|---|
| 38 | 38 |
|
| 39 | 39 |
private static final int INDEX = EffectType.VERTEX.ordinal(); |
| 40 | 40 |
|
| 41 |
private static int[] mNumEffectsH = new int[MAIN_VARIANTS]; |
|
| 42 |
private static int[] mNameH = new int[MAIN_VARIANTS]; |
|
| 43 |
private static int[] mUniformsH = new int[MAIN_VARIANTS]; |
|
| 44 |
private static int[] mAndAssociationH= new int[MAIN_VARIANTS]; |
|
| 45 |
private static int[] mEquAssociationH= new int[MAIN_VARIANTS]; |
|
| 46 |
private static int[] mInflateH = new int[MAIN_VARIANTS]; |
|
| 41 |
private static int[] mNumEffectsH = new int[MAIN_VARIANTS]; |
|
| 42 |
private static int[] mInflateH = new int[MAIN_VARIANTS]; |
|
| 43 |
private static int[] mPropertiesH = new int[MAIN_VARIANTS]; |
|
| 44 |
private static int[] mUniformsH = new int[MAIN_VARIANTS]; |
|
| 47 | 45 |
|
| 48 | 46 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 49 | 47 |
|
| ... | ... | |
| 63 | 61 |
|
| 64 | 62 |
static void uniforms(int mProgramH, int variant) |
| 65 | 63 |
{
|
| 66 |
mNumEffectsH[variant] = GLES30.glGetUniformLocation( mProgramH, "vNumEffects"); |
|
| 67 |
mNameH[variant] = GLES30.glGetUniformLocation( mProgramH, "vName"); |
|
| 68 |
mUniformsH[variant] = GLES30.glGetUniformLocation( mProgramH, "vUniforms"); |
|
| 69 |
mAndAssociationH[variant]= GLES30.glGetUniformLocation( mProgramH, "vEffAndAssoc"); |
|
| 70 |
mEquAssociationH[variant]= GLES30.glGetUniformLocation( mProgramH, "vEffEquAssoc"); |
|
| 71 |
mInflateH[variant] = GLES30.glGetUniformLocation( mProgramH, "u_Inflate"); |
|
| 64 |
mNumEffectsH[variant]= GLES30.glGetUniformLocation( mProgramH, "vNumEffects"); |
|
| 65 |
mInflateH[variant] = GLES30.glGetUniformLocation( mProgramH, "u_Inflate"); |
|
| 66 |
mPropertiesH[variant]= GLES30.glGetUniformLocation( mProgramH, "vProperties"); |
|
| 67 |
mUniformsH[variant] = GLES30.glGetUniformLocation( mProgramH, "vUniforms"); |
|
| 72 | 68 |
} |
| 73 | 69 |
|
| 74 | 70 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 85 | 81 |
|
| 86 | 82 |
for(int i=0; i<mNumEffects; i++) |
| 87 | 83 |
{
|
| 88 |
mEffects[i].writeAssociations(mIntUniforms, mMax[INDEX]+i, 2*mMax[INDEX]+i);
|
|
| 84 |
mEffects[i].writeAssociations(mIntUniforms, NUM_INT_UNIFORMS*i+1, NUM_INT_UNIFORMS*i+3);
|
|
| 89 | 85 |
|
| 90 | 86 |
if( mEffects[i].compute(mFloatUniforms, NUM_FLOAT_UNIFORMS*i, currTime, step) ) |
| 91 | 87 |
{
|
| ... | ... | |
| 109 | 105 |
|
| 110 | 106 |
if( mNumEffects>0 ) |
| 111 | 107 |
{
|
| 112 |
GLES30.glUniform1iv( mNameH[variant] , mNumEffects, mIntUniforms , 0 ); |
|
| 113 |
GLES30.glUniform1iv( mAndAssociationH[variant], mNumEffects, mIntUniforms , mMax[INDEX]); |
|
| 114 |
GLES30.glUniform1iv( mEquAssociationH[variant], mNumEffects, mIntUniforms , 2*mMax[INDEX]); |
|
| 115 |
GLES30.glUniform4fv( mUniformsH[variant] ,(NUM_FLOAT_UNIFORMS/4)*mNumEffects, mFloatUniforms , 0 ); |
|
| 108 |
GLES30.glUniform4iv( mPropertiesH[variant], mNumEffects, mIntUniforms , 0); |
|
| 109 |
GLES30.glUniform4fv( mUniformsH[variant] ,(NUM_FLOAT_UNIFORMS/4)*mNumEffects, mFloatUniforms , 0); |
|
| 116 | 110 |
} |
| 117 | 111 |
} |
| 118 | 112 |
} |
| src/main/res/raw/main_vertex_shader.glsl | ||
|---|---|---|
| 20 | 20 |
precision highp float; |
| 21 | 21 |
precision highp int; |
| 22 | 22 |
|
| 23 |
in vec3 a_Position; // Per-vertex position. |
|
| 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 |
in vec2 a_TexCoordinate; // Per-vertex texture coordinate. |
|
| 28 |
in float a_Component; // The component a vertex belongs to. |
|
| 29 |
// to a vertex effect. An effect will only be active on a vertex iff (a_Association & vAssociation[effect]) != 0. |
|
| 30 |
// ( see VertexEffect.retSection() ) |
|
| 31 |
|
|
| 32 |
out vec3 v_Position; // |
|
| 33 |
out vec3 v_endPosition; // for Transform Feedback only |
|
| 23 |
in vec3 a_Position; // Per-vertex position.
|
|
| 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 |
in vec2 a_TexCoordinate; // Per-vertex texture coordinate.
|
|
| 28 |
in float a_Component; // The component a vertex belongs to.
|
|
| 29 |
// to a vertex effect. An effect will only be active on a vertex iff (a_Association & vAssociation[effect]) != 0.
|
|
| 30 |
// ( see VertexEffect.retSection() )
|
|
| 31 |
|
|
| 32 |
out vec3 v_Position; //
|
|
| 33 |
out vec3 v_endPosition; // for Transform Feedback only
|
|
| 34 | 34 |
|
| 35 | 35 |
#ifdef PREAPPLY |
| 36 |
out vec3 v_Inflate; // Transform Feedback for preapply effects |
|
| 36 |
out vec3 v_Inflate; // Transform Feedback for preapply effects
|
|
| 37 | 37 |
#endif |
| 38 | 38 |
|
| 39 |
out vec3 v_Normal; // |
|
| 40 |
out vec2 v_TexCoordinate; // |
|
| 39 |
out vec3 v_Normal; //
|
|
| 40 |
out vec2 v_TexCoordinate; //
|
|
| 41 | 41 |
|
| 42 |
uniform mat4 u_MVPMatrix; // u_MVMatrixP * projection. |
|
| 43 |
uniform mat4 u_MVMatrixP; // the combined model/view matrix. (for points) |
|
| 44 |
uniform mat4 u_MVMatrixV; // the combined model/view matrix. (for vectors) |
|
| 45 |
// which need to work differently on points and vectors |
|
| 46 |
uniform float u_Inflate; // how much should we inflate (>0.0) or deflate (<0.0) the mesh. |
|
| 47 |
uniform int u_TransformFeedback; // are we doing the transform feedback now? |
|
| 42 |
uniform mat4 u_MVPMatrix; // u_MVMatrixP * projection.
|
|
| 43 |
uniform mat4 u_MVMatrixP; // the combined model/view matrix. (for points)
|
|
| 44 |
uniform mat4 u_MVMatrixV; // the combined model/view matrix. (for vectors)
|
|
| 45 |
// which need to work differently on points and vectors
|
|
| 46 |
uniform float u_Inflate; // how much should we inflate (>0.0) or deflate (<0.0) the mesh.
|
|
| 47 |
uniform int u_TransformFeedback; // are we doing the transform feedback now?
|
|
| 48 | 48 |
|
| 49 | 49 |
#if NUM_VERTEX>0 |
| 50 |
uniform int vNumEffects; // total number of vertex effects |
|
| 51 |
uniform int vName[NUM_VERTEX]; // their names. |
|
| 52 |
uniform int vEffAndAssoc[NUM_VERTEX];// Associations of the vertex effects. Those are used to connect an effect to a Mesh component. |
|
| 53 |
uniform int vEffEquAssoc[NUM_VERTEX];// Components the vertex effects work on. Likewise used to connect an effect to a Mesh component. |
|
| 50 |
uniform int vNumEffects; // total number of vertex effects |
|
| 51 |
uniform ivec4 vProperties[NUM_VERTEX];// their properties, 4 ints: |
|
| 52 |
// 1: name of the effect |
|
| 53 |
// 2: effect's AND association |
|
| 54 |
// 3: reserved int (probably another AND assoc in the future) |
|
| 55 |
// 4: effect's EQU association |
|
| 54 | 56 |
|
| 55 |
uniform vec4 vUniforms[3*NUM_VERTEX];// i-th effect is 3 consecutive vec4's: [3*i], [3*i+1], [3*i+2]. |
|
| 56 |
// The first vec4 is the Interpolated values, |
|
| 57 |
// second vec4: first float - cache, next 3: Center, the third - the Region. |
|
| 57 |
uniform vec4 vUniforms[3*NUM_VERTEX]; // i-th effect is 3 consecutive vec4's: [3*i], [3*i+1], [3*i+2].
|
|
| 58 |
// The first vec4 is the Interpolated values,
|
|
| 59 |
// second vec4: first float - cache, next 3: Center, the third - the Region.
|
|
| 58 | 60 |
|
| 59 | 61 |
layout (std140, binding=3) uniform meshAssociation |
| 60 | 62 |
{
|
| 61 |
ivec4 vComAssoc[MAX_COMPON]; // component Associations |
|
| 63 |
ivec4 vComAssoc[MAX_COMPON]; // component Associations, 4 ints: |
|
| 64 |
// 1: component's AND association |
|
| 65 |
// 2: reserved. Probably another AND assoc in the future. |
|
| 66 |
// 3: component's EQU association |
|
| 67 |
// 4: reserved |
|
| 62 | 68 |
}; |
| 63 | 69 |
|
| 64 | 70 |
////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 118 | 124 |
|
| 119 | 125 |
for(int i=0; i<vNumEffects; i++) |
| 120 | 126 |
{
|
| 121 |
if( ((vComAssoc[component].x & vEffAndAssoc[i]) != 0) || (vComAssoc[component].z == vEffEquAssoc[i]) )
|
|
| 127 |
if( ((vComAssoc[component].x & vProperties[i].y) != 0) || (vComAssoc[component].z == vProperties[i].w) )
|
|
| 122 | 128 |
{
|
| 123 | 129 |
// ENABLED EFFECTS WILL BE INSERTED HERE |
| 124 | 130 |
|
Also available in: Unified diff
Turn the vName, vEffAnd and vEffEqu integer array uniforms into a one ivec4.
The point: ivec4s are always packed tightly in UBOs (which is going to be the next step)