Revision f046b159
Added by Leszek Koltunski over 5 years ago
| src/main/java/org/distorted/library/effect/Effect.java | ||
|---|---|---|
| 69 | 69 |
float[] u = name.getUnity(); |
| 70 | 70 |
int l = u.length; |
| 71 | 71 |
|
| 72 |
for(int i=0; i<l; i++) |
|
| 73 |
{
|
|
| 74 |
mUnity[n*MAX_UNITY_DIM+i] = u[i]; |
|
| 75 |
} |
|
| 72 |
System.arraycopy(u, 0, mUnity, MAX_UNITY_DIM*n, l); |
|
| 76 | 73 |
|
| 77 | 74 |
mUnityDim[n] = l; |
| 78 | 75 |
|
| src/main/java/org/distorted/library/effect/VertexEffect.java | ||
|---|---|---|
| 21 | 21 |
|
| 22 | 22 |
import org.distorted.library.type.Static4D; |
| 23 | 23 |
|
| 24 |
import java.lang.reflect.Method; |
|
| 25 |
|
|
| 24 | 26 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 25 | 27 |
/** |
| 26 | 28 |
* Abstract class that represents an Effect that works by injecting certain code into the main Vertex shader. |
| ... | ... | |
| 37 | 39 |
private static String mGLSL = ""; |
| 38 | 40 |
private static int mNumEnabled = 0; |
| 39 | 41 |
|
| 42 |
private static String mFullGLSL = ""; |
|
| 43 |
private static int mFullEnabled = 0; |
|
| 44 |
private static boolean mFullPrepared = false; |
|
| 45 |
|
|
| 40 | 46 |
final static Static4D MAX_REGION = new Static4D(0,0,0,1000000); |
| 41 | 47 |
|
| 42 | 48 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 47 | 53 |
} |
| 48 | 54 |
|
| 49 | 55 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 50 |
// prepare code to be injected into the 'main_vertex_shader' main() function. |
|
| 51 | 56 |
|
| 52 |
static void addEffect(EffectName name, String code)
|
|
| 57 |
private static String retSection(int effect, String code)
|
|
| 53 | 58 |
{
|
| 54 |
int effect = name.ordinal(); |
|
| 55 |
|
|
| 56 |
if( mEnabled[effect] ) return; |
|
| 57 |
|
|
| 58 |
mEnabled[effect] = true; |
|
| 59 |
mNumEnabled ++; |
|
| 60 |
|
|
| 61 |
mGLSL += |
|
| 59 |
return |
|
| 62 | 60 |
|
| 63 | 61 |
"if( vName[i]=="+effect+")\n" + |
| 64 | 62 |
"{\n" +
|
| ... | ... | |
| 67 | 65 |
"else\n"; |
| 68 | 66 |
} |
| 69 | 67 |
|
| 68 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 69 |
// prepare the code to be injected into the Full program, i.e. code of ALL vertex effects. |
|
| 70 |
|
|
| 71 |
private static void prepareFull() |
|
| 72 |
{
|
|
| 73 |
Method method; |
|
| 74 |
|
|
| 75 |
for(EffectName name: EffectName.values()) |
|
| 76 |
{
|
|
| 77 |
if( name.getType() == EffectType.VERTEX ) |
|
| 78 |
{
|
|
| 79 |
Class<? extends Effect> cls = name.getEffectClass(); |
|
| 80 |
|
|
| 81 |
try |
|
| 82 |
{
|
|
| 83 |
method = cls.getDeclaredMethod("code");
|
|
| 84 |
} |
|
| 85 |
catch(NoSuchMethodException ex) |
|
| 86 |
{
|
|
| 87 |
android.util.Log.e("Effect", "exception getting method: "+ex.getMessage());
|
|
| 88 |
method = null; |
|
| 89 |
} |
|
| 90 |
|
|
| 91 |
try |
|
| 92 |
{
|
|
| 93 |
if( method!=null ) |
|
| 94 |
{
|
|
| 95 |
Object value = method.invoke(null); |
|
| 96 |
String code = (String)value; |
|
| 97 |
mFullGLSL += retSection(name.ordinal(),code); |
|
| 98 |
mFullEnabled++; |
|
| 99 |
} |
|
| 100 |
} |
|
| 101 |
catch(Exception ex) |
|
| 102 |
{
|
|
| 103 |
android.util.Log.e("Effect", "exception invoking method: "+ex.getMessage());
|
|
| 104 |
} |
|
| 105 |
} |
|
| 106 |
} |
|
| 107 |
} |
|
| 108 |
|
|
| 109 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 110 |
// prepare code to be injected into the 'main_vertex_shader' main() function. |
|
| 111 |
|
|
| 112 |
static void addEffect(EffectName name, String code) |
|
| 113 |
{
|
|
| 114 |
int effect = name.ordinal(); |
|
| 115 |
|
|
| 116 |
if( !mEnabled[effect] ) |
|
| 117 |
{
|
|
| 118 |
mEnabled[effect] = true; |
|
| 119 |
mNumEnabled ++; |
|
| 120 |
mGLSL += retSection(effect,code); |
|
| 121 |
} |
|
| 122 |
} |
|
| 123 |
|
|
| 70 | 124 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 71 | 125 |
/** |
| 72 | 126 |
* Only for use by the library itself. |
| ... | ... | |
| 78 | 132 |
return mGLSL + "{}";
|
| 79 | 133 |
} |
| 80 | 134 |
|
| 135 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 136 |
/** |
|
| 137 |
* Only for use by the library itself. |
|
| 138 |
* |
|
| 139 |
* @y.exclude |
|
| 140 |
*/ |
|
| 141 |
public static String getAllGLSL() |
|
| 142 |
{
|
|
| 143 |
if( !mFullPrepared ) |
|
| 144 |
{
|
|
| 145 |
prepareFull(); |
|
| 146 |
mFullPrepared = true; |
|
| 147 |
} |
|
| 148 |
|
|
| 149 |
return mFullGLSL + "{}";
|
|
| 150 |
} |
|
| 151 |
|
|
| 152 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 153 |
/** |
|
| 154 |
* Only for use by the library itself. |
|
| 155 |
* |
|
| 156 |
* @y.exclude |
|
| 157 |
*/ |
|
| 158 |
public static int getAllEnabled() |
|
| 159 |
{
|
|
| 160 |
if( !mFullPrepared ) |
|
| 161 |
{
|
|
| 162 |
prepareFull(); |
|
| 163 |
mFullPrepared = true; |
|
| 164 |
} |
|
| 165 |
|
|
| 166 |
return mFullEnabled; |
|
| 167 |
} |
|
| 168 |
|
|
| 81 | 169 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 82 | 170 |
|
| 83 | 171 |
static void destroyStatics() |
| 84 | 172 |
{
|
| 85 | 173 |
mNumEnabled = 0; |
| 86 | 174 |
mGLSL = ""; |
| 175 |
mFullEnabled= 0; |
|
| 176 |
mFullGLSL = ""; |
|
| 177 |
mFullPrepared = false; |
|
| 87 | 178 |
} |
| 88 | 179 |
|
| 89 | 180 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| src/main/java/org/distorted/library/effect/VertexEffectDeform.java | ||
|---|---|---|
| 29 | 29 |
*/ |
| 30 | 30 |
public class VertexEffectDeform extends VertexEffect |
| 31 | 31 |
{
|
| 32 |
private static final EffectName NAME = EffectName.DEFORM; |
|
| 33 |
|
|
| 32 | 34 |
private Data3D mVector, mCenter; |
| 33 | 35 |
private Data1D mRadius; |
| 34 | 36 |
private Data4D mRegion; |
| ... | ... | |
| 41 | 43 |
*/ |
| 42 | 44 |
public boolean compute(float[] uniforms, int index, long currentDuration, long step ) |
| 43 | 45 |
{
|
| 44 |
mCenter.get(uniforms,index+CENTER_OFFSET,currentDuration,step); |
|
| 45 |
mRegion.get(uniforms,index+REGION_OFFSET,currentDuration,step); |
|
| 46 |
mRadius.get(uniforms,index+3,currentDuration,step); |
|
| 47 |
return mVector.get(uniforms,index,currentDuration,step); |
|
| 46 |
mCenter.get(uniforms,index+CENTER_OFFSET ,currentDuration,step); |
|
| 47 |
mRegion.get(uniforms,index+REGION_OFFSET ,currentDuration,step); |
|
| 48 |
mRadius.get(uniforms,index+VALUES_OFFSET+3,currentDuration,step); |
|
| 49 |
|
|
| 50 |
return mVector.get(uniforms,index+VALUES_OFFSET,currentDuration,step); |
|
| 48 | 51 |
} |
| 49 | 52 |
|
| 50 | 53 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 103 | 106 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 104 | 107 |
// 2020-05-03: replaced vec3 'u_Bounding' with a uniform 'vUniforms[effect].w' (i.e. mRadius) |
| 105 | 108 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 106 |
/** |
|
| 107 |
* Have to call this before the shaders get compiled (i.e before DistortedLibrary.onCreate()) for the Effect to work. |
|
| 108 |
*/ |
|
| 109 |
public static void enable() |
|
| 109 |
|
|
| 110 |
static String code() |
|
| 110 | 111 |
{
|
| 111 |
addEffect( EffectName.DEFORM,
|
|
| 112 |
return
|
|
| 112 | 113 |
|
| 113 | 114 |
"const vec3 ONE = vec3(1.0,1.0,1.0); \n" |
| 114 | 115 |
+ "const float A = 0.5; \n" |
| ... | ... | |
| 144 | 145 |
+ "v.z += force.z*d*d*(3.0*d*d -8.0*d +6.0); \n" // thick bubble |
| 145 | 146 |
+ "float b = -(12.0*force.z*d*(1.0-d)*(1.0-d)*(1.0-d))*one_over_denom; \n" |
| 146 | 147 |
|
| 147 |
+ "n.xy += n.z*b*ps.xy;" |
|
| 148 |
); |
|
| 148 |
+ "n.xy += n.z*b*ps.xy;"; |
|
| 149 |
} |
|
| 150 |
|
|
| 151 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 152 |
/** |
|
| 153 |
* Have to call this before the shaders get compiled (i.e before DistortedLibrary.onCreate()) for the Effect to work. |
|
| 154 |
*/ |
|
| 155 |
public static void enable() |
|
| 156 |
{
|
|
| 157 |
addEffect( NAME, code() ); |
|
| 149 | 158 |
} |
| 150 | 159 |
|
| 151 | 160 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 161 | 170 |
*/ |
| 162 | 171 |
public VertexEffectDeform(Data3D vector, Data1D radius, Data3D center, Data4D region) |
| 163 | 172 |
{
|
| 164 |
super(EffectName.DEFORM);
|
|
| 173 |
super(NAME);
|
|
| 165 | 174 |
mVector = vector; |
| 166 | 175 |
mRadius = radius; |
| 167 | 176 |
mCenter = center; |
| ... | ... | |
| 180 | 189 |
*/ |
| 181 | 190 |
public VertexEffectDeform(Data3D vector, Data1D radius, Data3D center) |
| 182 | 191 |
{
|
| 183 |
super(EffectName.DEFORM);
|
|
| 192 |
super(NAME);
|
|
| 184 | 193 |
mVector = vector; |
| 185 | 194 |
mRadius = radius; |
| 186 | 195 |
mCenter = center; |
| src/main/java/org/distorted/library/effect/VertexEffectDistort.java | ||
|---|---|---|
| 28 | 28 |
*/ |
| 29 | 29 |
public class VertexEffectDistort extends VertexEffect |
| 30 | 30 |
{
|
| 31 |
private static final EffectName NAME = EffectName.DISTORT; |
|
| 32 |
|
|
| 31 | 33 |
private Data3D mVector, mCenter; |
| 32 | 34 |
private Data4D mRegion; |
| 33 | 35 |
|
| ... | ... | |
| 41 | 43 |
{
|
| 42 | 44 |
mCenter.get(uniforms,index+CENTER_OFFSET,currentDuration,step); |
| 43 | 45 |
mRegion.get(uniforms,index+REGION_OFFSET,currentDuration,step); |
| 44 |
return mVector.get(uniforms,index,currentDuration,step); |
|
| 46 |
|
|
| 47 |
return mVector.get(uniforms,index+VALUES_OFFSET,currentDuration,step); |
|
| 45 | 48 |
} |
| 46 | 49 |
|
| 47 | 50 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 118 | 121 |
// which makes Vrot = (a+n.y*c , b-n.y*c , v*n) where |
| 119 | 122 |
// a = vx*nz-vz*nx , b = vy*nz-vz*ny , c = (vx*ny-vy*nx)/(1+nz) (unless n=(0,0,-1)) |
| 120 | 123 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 121 |
/** |
|
| 122 |
* Have to call this before the shaders get compiled (i.e before DistortedLibrary.onCreate()) for the Effect to work. |
|
| 123 |
*/ |
|
| 124 |
public static void enable() |
|
| 124 |
|
|
| 125 |
static String code() |
|
| 125 | 126 |
{
|
| 126 |
addEffect(EffectName.DISTORT,
|
|
| 127 |
return
|
|
| 127 | 128 |
|
| 128 | 129 |
"vec3 ps = vUniforms[effect+1].yzw - v; \n" |
| 129 | 130 |
+ "vec3 force = vUniforms[effect].xyz; \n" |
| ... | ... | |
| 152 | 153 |
+ " n = vec3( an+n.y*cn , bn-n.x*cn , -N.x*n.x-N.y*n.y+N.z*n.z);\n" // notice 4 signs change! |
| 153 | 154 |
|
| 154 | 155 |
+ " n = normalize(n); \n" |
| 155 |
+ " } \n" |
|
| 156 |
); |
|
| 156 |
+ " } \n"; |
|
| 157 |
} |
|
| 158 |
|
|
| 159 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 160 |
/** |
|
| 161 |
* Have to call this before the shaders get compiled (i.e before DistortedLibrary.onCreate()) for the Effect to work. |
|
| 162 |
*/ |
|
| 163 |
public static void enable() |
|
| 164 |
{
|
|
| 165 |
addEffect( NAME, code() ); |
|
| 157 | 166 |
} |
| 158 | 167 |
|
| 159 | 168 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 166 | 175 |
*/ |
| 167 | 176 |
public VertexEffectDistort(Data3D vector, Data3D center, Data4D region) |
| 168 | 177 |
{
|
| 169 |
super(EffectName.DISTORT);
|
|
| 178 |
super(NAME);
|
|
| 170 | 179 |
mVector = vector; |
| 171 | 180 |
mCenter = center; |
| 172 | 181 |
mRegion = (region==null ? MAX_REGION : region); |
| ... | ... | |
| 181 | 190 |
*/ |
| 182 | 191 |
public VertexEffectDistort(Data3D vector, Data3D center) |
| 183 | 192 |
{
|
| 184 |
super(EffectName.DISTORT);
|
|
| 193 |
super(NAME);
|
|
| 185 | 194 |
mVector = vector; |
| 186 | 195 |
mCenter = center; |
| 187 | 196 |
mRegion = MAX_REGION; |
| src/main/java/org/distorted/library/effect/VertexEffectMove.java | ||
|---|---|---|
| 28 | 28 |
*/ |
| 29 | 29 |
public class VertexEffectMove extends VertexEffect |
| 30 | 30 |
{
|
| 31 |
private static final EffectName NAME = EffectName.VERTEX_MOVE; |
|
| 32 |
|
|
| 31 | 33 |
private Data3D mVector; |
| 32 | 34 |
|
| 33 | 35 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 38 | 40 |
*/ |
| 39 | 41 |
public boolean compute(float[] uniforms, int index, long currentDuration, long step ) |
| 40 | 42 |
{
|
| 41 |
return mVector.get(uniforms,index,currentDuration,step); |
|
| 43 |
return mVector.get(uniforms,index+VALUES_OFFSET,currentDuration,step); |
|
| 44 |
} |
|
| 45 |
|
|
| 46 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 47 |
|
|
| 48 |
static String code() |
|
| 49 |
{
|
|
| 50 |
return "v += vUniforms[effect].xyz;"; |
|
| 42 | 51 |
} |
| 43 | 52 |
|
| 44 | 53 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 49 | 58 |
*/ |
| 50 | 59 |
public static void enable() |
| 51 | 60 |
{
|
| 52 |
addEffect( EffectName.VERTEX_MOVE, "v += vUniforms[effect].xyz;" );
|
|
| 61 |
addEffect( NAME, code() );
|
|
| 53 | 62 |
} |
| 54 | 63 |
|
| 55 | 64 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 60 | 69 |
*/ |
| 61 | 70 |
public VertexEffectMove(Data3D vector) |
| 62 | 71 |
{
|
| 63 |
super(EffectName.VERTEX_MOVE);
|
|
| 72 |
super(NAME);
|
|
| 64 | 73 |
mVector = vector; |
| 65 | 74 |
} |
| 66 | 75 |
} |
| src/main/java/org/distorted/library/effect/VertexEffectPinch.java | ||
|---|---|---|
| 34 | 34 |
*/ |
| 35 | 35 |
public class VertexEffectPinch extends VertexEffect |
| 36 | 36 |
{
|
| 37 |
private static final EffectName NAME = EffectName.PINCH; |
|
| 38 |
|
|
| 37 | 39 |
private Data3D mPinch; |
| 38 | 40 |
private Data3D mCenter; |
| 39 | 41 |
private Data4D mRegion; |
| ... | ... | |
| 48 | 50 |
{
|
| 49 | 51 |
mCenter.get(uniforms,index+CENTER_OFFSET,currentDuration,step); |
| 50 | 52 |
mRegion.get(uniforms,index+REGION_OFFSET,currentDuration,step); |
| 51 |
boolean ret = mPinch.get(uniforms,index,currentDuration,step); |
|
| 53 |
boolean ret = mPinch.get(uniforms,index+VALUES_OFFSET,currentDuration,step);
|
|
| 52 | 54 |
|
| 53 |
uniforms[index+1] = (float)(Math.PI*uniforms[index+1]/180); |
|
| 54 |
uniforms[index+2] = (float)(Math.PI*uniforms[index+2]/180); |
|
| 55 |
uniforms[index+VALUES_OFFSET+1] = (float)(Math.PI*uniforms[index+1]/180);
|
|
| 56 |
uniforms[index+VALUES_OFFSET+2] = (float)(Math.PI*uniforms[index+2]/180);
|
|
| 55 | 57 |
|
| 56 | 58 |
return ret; |
| 57 | 59 |
} |
| 58 | 60 |
|
| 59 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 60 |
// PUBLIC API |
|
| 61 | 61 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 62 | 62 |
// Pull P=(v.x,v.y) along a vector from the center of region sphere to a point on it defined by |
| 63 | 63 |
// the (latitude,longitude) pair of angles with P' = P + (1-h)*dist(line to P) |
| 64 | 64 |
// when h>1 we are pushing points away from S: P' = P + (1/h-1)*dist(line to P) |
| 65 | 65 |
// (where 'line' above passes through the center point and goes along the vector) |
| 66 | 66 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 67 |
/** |
|
| 68 |
* Have to call this before the shaders get compiled (i.e before DistortedLibrary.onCreate()) for the Effect to work. |
|
| 69 |
*/ |
|
| 70 |
public static void enable() |
|
| 67 |
|
|
| 68 |
static String code() |
|
| 71 | 69 |
{
|
| 72 |
addEffect(EffectName.PINCH,
|
|
| 70 |
return
|
|
| 73 | 71 |
|
| 74 | 72 |
"vec3 ps = vUniforms[effect+1].yzw -v; \n" |
| 75 | 73 |
+ "float h = vUniforms[effect].x; \n" |
| ... | ... | |
| 93 | 91 |
+ "n_ps = sign_ps*n_ps/(dot_ps-(sign_ps-1.0)); \n" // uff! now n_ps is the parallel to ps component of n, even if ps==0 |
| 94 | 92 |
+ "float move = deg*(h-1.0)/(h/B+1.0/A); \n" // move(0)=-A*deg, move(1)=0, move(inf)=B*deg |
| 95 | 93 |
+ "n += move * abs(dot(n,dir)) * n_ps; \n" |
| 96 |
+ "n = normalize(n);" |
|
| 97 |
); |
|
| 94 |
+ "n = normalize(n);"; |
|
| 95 |
} |
|
| 96 |
|
|
| 97 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 98 |
// PUBLIC API |
|
| 99 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 100 |
/** |
|
| 101 |
* Have to call this before the shaders get compiled (i.e before DistortedLibrary.onCreate()) for the Effect to work. |
|
| 102 |
*/ |
|
| 103 |
public static void enable() |
|
| 104 |
{
|
|
| 105 |
addEffect( NAME, code() ); |
|
| 98 | 106 |
} |
| 99 | 107 |
|
| 100 | 108 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 109 | 117 |
*/ |
| 110 | 118 |
public VertexEffectPinch(Data3D pinch, Data3D center, Data4D region) |
| 111 | 119 |
{
|
| 112 |
super(EffectName.PINCH);
|
|
| 120 |
super(NAME);
|
|
| 113 | 121 |
mPinch = pinch; |
| 114 | 122 |
mCenter = center; |
| 115 | 123 |
mRegion = (region==null ? MAX_REGION : region); |
| ... | ... | |
| 126 | 134 |
*/ |
| 127 | 135 |
public VertexEffectPinch(Data3D pinch, Data3D center) |
| 128 | 136 |
{
|
| 129 |
super(EffectName.PINCH);
|
|
| 137 |
super(NAME);
|
|
| 130 | 138 |
mPinch = pinch; |
| 131 | 139 |
mCenter = center; |
| 132 | 140 |
mRegion = MAX_REGION; |
| src/main/java/org/distorted/library/effect/VertexEffectQuaternion.java | ||
|---|---|---|
| 29 | 29 |
*/ |
| 30 | 30 |
public class VertexEffectQuaternion extends VertexEffect |
| 31 | 31 |
{
|
| 32 |
private static final EffectName NAME = EffectName.VERTEX_QUATERNION; |
|
| 33 |
|
|
| 32 | 34 |
private Data4D mQuaternion; |
| 33 | 35 |
private Data3D mCenter; |
| 34 | 36 |
|
| ... | ... | |
| 41 | 43 |
public boolean compute(float[] uniforms, int index, long currentDuration, long step ) |
| 42 | 44 |
{
|
| 43 | 45 |
mCenter.get(uniforms,index+CENTER_OFFSET,currentDuration,step); |
| 44 |
return mQuaternion.get(uniforms,index,currentDuration,step); |
|
| 46 |
return mQuaternion.get(uniforms,index+VALUES_OFFSET,currentDuration,step); |
|
| 47 |
} |
|
| 48 |
|
|
| 49 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 50 |
|
|
| 51 |
static String code() |
|
| 52 |
{
|
|
| 53 |
return |
|
| 54 |
|
|
| 55 |
"float qx = vUniforms[effect].x; \n" |
|
| 56 |
+ "float qy = vUniforms[effect].y; \n" |
|
| 57 |
+ "float qz = vUniforms[effect].z; \n" |
|
| 58 |
+ "float qw = vUniforms[effect].w; \n" |
|
| 59 |
+ "vec3 center = vUniforms[effect+1].yzw; \n" |
|
| 60 |
|
|
| 61 |
+ "v -= center; \n" |
|
| 62 |
|
|
| 63 |
+ "float tx = qx - v.z*qy + v.y*qz + v.x*qw; \n" |
|
| 64 |
+ "float ty = qy + v.z*qx + v.y*qw - v.x*qz; \n" |
|
| 65 |
+ "float tz = qz + v.z*qw - v.y*qx + v.x*qy; \n" |
|
| 66 |
+ "float tw = qw - v.z*qz - v.y*qy - v.x*qx; \n" |
|
| 67 |
|
|
| 68 |
+ "v.x = qw*tx + qz*ty - qy*tz - qx*tw; \n" |
|
| 69 |
+ "v.y = qw*ty - qz*tx - qy*tw + qx*tz; \n" |
|
| 70 |
+ "v.z = qw*tz - qz*tw + qy*tx - qx*ty; \n" |
|
| 71 |
|
|
| 72 |
+ "v += center; \n" |
|
| 73 |
|
|
| 74 |
+ "float nx = - n.z*qy + n.y*qz + n.x*qw; \n" |
|
| 75 |
+ "float ny = + n.z*qx + n.y*qw - n.x*qz; \n" |
|
| 76 |
+ "float nz = + n.z*qw - n.y*qx + n.x*qy; \n" |
|
| 77 |
+ "float nw = - n.z*qz - n.y*qy - n.x*qx; \n" |
|
| 78 |
|
|
| 79 |
+ "n.x = qw*nx + qz*ny - qy*nz - qx*nw; \n" |
|
| 80 |
+ "n.y = qw*ny - qz*nx - qy*nw + qx*nz; \n" |
|
| 81 |
+ "n.z = qw*nz - qz*nw + qy*nx - qx*ny; \n"; |
|
| 45 | 82 |
} |
| 46 | 83 |
|
| 47 | 84 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 52 | 89 |
*/ |
| 53 | 90 |
public static void enable() |
| 54 | 91 |
{
|
| 55 |
addEffect( EffectName.VERTEX_QUATERNION, |
|
| 56 |
"float qx = vUniforms[effect].x; \n" |
|
| 57 |
+ "float qy = vUniforms[effect].y; \n" |
|
| 58 |
+ "float qz = vUniforms[effect].z; \n" |
|
| 59 |
+ "float qw = vUniforms[effect].w; \n" |
|
| 60 |
+ "vec3 center = vUniforms[effect+1].yzw; \n" |
|
| 61 |
|
|
| 62 |
+ "v -= center; \n" |
|
| 63 |
|
|
| 64 |
+ "float tx = qx - v.z*qy + v.y*qz + v.x*qw; \n" |
|
| 65 |
+ "float ty = qy + v.z*qx + v.y*qw - v.x*qz; \n" |
|
| 66 |
+ "float tz = qz + v.z*qw - v.y*qx + v.x*qy; \n" |
|
| 67 |
+ "float tw = qw - v.z*qz - v.y*qy - v.x*qx; \n" |
|
| 68 |
|
|
| 69 |
+ "v.x = qw*tx + qz*ty - qy*tz - qx*tw; \n" |
|
| 70 |
+ "v.y = qw*ty - qz*tx - qy*tw + qx*tz; \n" |
|
| 71 |
+ "v.z = qw*tz - qz*tw + qy*tx - qx*ty; \n" |
|
| 72 |
|
|
| 73 |
+ "v += center; \n" |
|
| 74 |
|
|
| 75 |
+ "float nx = - n.z*qy + n.y*qz + n.x*qw; \n" |
|
| 76 |
+ "float ny = + n.z*qx + n.y*qw - n.x*qz; \n" |
|
| 77 |
+ "float nz = + n.z*qw - n.y*qx + n.x*qy; \n" |
|
| 78 |
+ "float nw = - n.z*qz - n.y*qy - n.x*qx; \n" |
|
| 79 |
|
|
| 80 |
+ "n.x = qw*nx + qz*ny - qy*nz - qx*nw; \n" |
|
| 81 |
+ "n.y = qw*ny - qz*nx - qy*nw + qx*nz; \n" |
|
| 82 |
+ "n.z = qw*nz - qz*nw + qy*nx - qx*ny; \n" |
|
| 83 |
); |
|
| 92 |
addEffect( NAME, code() ); |
|
| 84 | 93 |
} |
| 85 | 94 |
|
| 86 | 95 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 92 | 101 |
*/ |
| 93 | 102 |
public VertexEffectQuaternion(Data4D quaternion, Data3D center ) |
| 94 | 103 |
{
|
| 95 |
super(EffectName.VERTEX_QUATERNION);
|
|
| 104 |
super(NAME);
|
|
| 96 | 105 |
mQuaternion = quaternion; |
| 97 | 106 |
mCenter = center; |
| 98 | 107 |
} |
| src/main/java/org/distorted/library/effect/VertexEffectRotate.java | ||
|---|---|---|
| 30 | 30 |
*/ |
| 31 | 31 |
public class VertexEffectRotate extends VertexEffect |
| 32 | 32 |
{
|
| 33 |
private static final EffectName NAME = EffectName.VERTEX_ROTATE; |
|
| 34 |
|
|
| 33 | 35 |
private Data1D mAngle; |
| 34 | 36 |
private Data3D mAxis, mCenter; |
| 35 | 37 |
|
| ... | ... | |
| 42 | 44 |
public boolean compute(float[] uniforms, int index, long currentDuration, long step ) |
| 43 | 45 |
{
|
| 44 | 46 |
mCenter.get(uniforms,index+CENTER_OFFSET,currentDuration,step); |
| 45 |
mAxis.get(uniforms,index+1,currentDuration,step); |
|
| 47 |
mAxis.get(uniforms,index+VALUES_OFFSET+1,currentDuration,step);
|
|
| 46 | 48 |
|
| 47 | 49 |
float len = uniforms[index+1]*uniforms[index+1] + uniforms[index+2]*uniforms[index+2] + uniforms[index+3]*uniforms[index+3]; |
| 48 | 50 |
len = (float)Math.sqrt(len); |
| 49 | 51 |
|
| 50 | 52 |
if( len!=0 ) |
| 51 | 53 |
{
|
| 52 |
uniforms[index+1] /= len; |
|
| 53 |
uniforms[index+2] /= len; |
|
| 54 |
uniforms[index+3] /= len; |
|
| 54 |
uniforms[index+VALUES_OFFSET+1] /= len;
|
|
| 55 |
uniforms[index+VALUES_OFFSET+2] /= len;
|
|
| 56 |
uniforms[index+VALUES_OFFSET+3] /= len;
|
|
| 55 | 57 |
} |
| 56 | 58 |
|
| 57 |
return mAngle.get(uniforms,index,currentDuration,step); |
|
| 59 |
return mAngle.get(uniforms,index+VALUES_OFFSET,currentDuration,step);
|
|
| 58 | 60 |
} |
| 59 | 61 |
|
| 60 | 62 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 61 |
// PUBLIC API |
|
| 62 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 63 |
/** |
|
| 64 |
* Have to call this before the shaders get compiled (i.e before DistortedLibrary.onCreate()) for the Effect to work. |
|
| 65 |
*/ |
|
| 66 |
public static void enable() |
|
| 63 |
|
|
| 64 |
static String code() |
|
| 67 | 65 |
{
|
| 68 |
addEffect( EffectName.VERTEX_ROTATE, |
|
| 66 |
return |
|
| 67 |
|
|
| 68 |
"float angle = vUniforms[effect].x*3.1415/360.0;\n" |
|
| 69 |
+ "vec3 center = vUniforms[effect+1].yzw; \n" |
|
| 70 |
+ "float sinHalf = sin(angle); \n" |
|
| 71 |
+ "float cosHalf = cos(angle); \n" |
|
| 69 | 72 |
|
| 70 |
"float angle = vUniforms[effect].x*3.1415/360.0;\n"
|
|
| 71 |
+ "vec3 center = vUniforms[effect+1].yzw; \n"
|
|
| 72 |
+ "float sinHalf = sin(angle); \n"
|
|
| 73 |
+ "float cosHalf = cos(angle); \n"
|
|
| 73 |
+ "float qx = vUniforms[effect].y * sinHalf; \n"
|
|
| 74 |
+ "float qy = vUniforms[effect].z * sinHalf; \n"
|
|
| 75 |
+ "float qz = vUniforms[effect].w * sinHalf; \n"
|
|
| 76 |
+ "float qw = cosHalf; \n"
|
|
| 74 | 77 |
|
| 75 |
+ "float qx = vUniforms[effect].y * sinHalf; \n" |
|
| 76 |
+ "float qy = vUniforms[effect].z * sinHalf; \n" |
|
| 77 |
+ "float qz = vUniforms[effect].w * sinHalf; \n" |
|
| 78 |
+ "float qw = cosHalf; \n" |
|
| 78 |
+ "v -= center; \n" |
|
| 79 | 79 |
|
| 80 |
+ "v -= center; \n" |
|
| 80 |
+ "float tx = qx - v.z*qy + v.y*qz + v.x*qw; \n" |
|
| 81 |
+ "float ty = qy + v.z*qx + v.y*qw - v.x*qz; \n" |
|
| 82 |
+ "float tz = qz + v.z*qw - v.y*qx + v.x*qy; \n" |
|
| 83 |
+ "float tw = qw - v.z*qz - v.y*qy - v.x*qx; \n" |
|
| 81 | 84 |
|
| 82 |
+ "float tx = qx - v.z*qy + v.y*qz + v.x*qw; \n" |
|
| 83 |
+ "float ty = qy + v.z*qx + v.y*qw - v.x*qz; \n" |
|
| 84 |
+ "float tz = qz + v.z*qw - v.y*qx + v.x*qy; \n" |
|
| 85 |
+ "float tw = qw - v.z*qz - v.y*qy - v.x*qx; \n" |
|
| 85 |
+ "v.x = qw*tx + qz*ty - qy*tz - qx*tw; \n" |
|
| 86 |
+ "v.y = qw*ty - qz*tx - qy*tw + qx*tz; \n" |
|
| 87 |
+ "v.z = qw*tz - qz*tw + qy*tx - qx*ty; \n" |
|
| 86 | 88 |
|
| 87 |
+ "v.x = qw*tx + qz*ty - qy*tz - qx*tw; \n" |
|
| 88 |
+ "v.y = qw*ty - qz*tx - qy*tw + qx*tz; \n" |
|
| 89 |
+ "v.z = qw*tz - qz*tw + qy*tx - qx*ty; \n" |
|
| 89 |
+ "v += center; \n" |
|
| 90 | 90 |
|
| 91 |
+ "v += center; \n" |
|
| 91 |
+ "float nx = - n.z*qy + n.y*qz + n.x*qw; \n" |
|
| 92 |
+ "float ny = + n.z*qx + n.y*qw - n.x*qz; \n" |
|
| 93 |
+ "float nz = + n.z*qw - n.y*qx + n.x*qy; \n" |
|
| 94 |
+ "float nw = - n.z*qz - n.y*qy - n.x*qx; \n" |
|
| 92 | 95 |
|
| 93 |
+ "float nx = - n.z*qy + n.y*qz + n.x*qw; \n"
|
|
| 94 |
+ "float ny = + n.z*qx + n.y*qw - n.x*qz; \n"
|
|
| 95 |
+ "float nz = + n.z*qw - n.y*qx + n.x*qy; \n"
|
|
| 96 |
+ "float nw = - n.z*qz - n.y*qy - n.x*qx; \n"
|
|
| 96 |
+ "n.x = qw*nx + qz*ny - qy*nz - qx*nw; \n"
|
|
| 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 |
}
|
|
| 97 | 100 |
|
| 98 |
+ "n.x = qw*nx + qz*ny - qy*nz - qx*nw; \n" |
|
| 99 |
+ "n.y = qw*ny - qz*nx - qy*nw + qx*nz; \n" |
|
| 100 |
+ "n.z = qw*nz - qz*nw + qy*nx - qx*ny; \n" |
|
| 101 |
); |
|
| 101 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 102 |
// PUBLIC API |
|
| 103 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 104 |
/** |
|
| 105 |
* Have to call this before the shaders get compiled (i.e before DistortedLibrary.onCreate()) for the Effect to work. |
|
| 106 |
*/ |
|
| 107 |
public static void enable() |
|
| 108 |
{
|
|
| 109 |
addEffect( NAME, code() ); |
|
| 102 | 110 |
} |
| 103 | 111 |
|
| 104 | 112 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 111 | 119 |
*/ |
| 112 | 120 |
public VertexEffectRotate(Data1D angle, Data3D axis, Data3D center) |
| 113 | 121 |
{
|
| 114 |
super(EffectName.VERTEX_ROTATE);
|
|
| 122 |
super(NAME);
|
|
| 115 | 123 |
mAngle = angle; |
| 116 | 124 |
mAxis = axis; |
| 117 | 125 |
mCenter = center; |
| src/main/java/org/distorted/library/effect/VertexEffectScale.java | ||
|---|---|---|
| 28 | 28 |
*/ |
| 29 | 29 |
public class VertexEffectScale extends VertexEffect |
| 30 | 30 |
{
|
| 31 |
private static final EffectName NAME = EffectName.VERTEX_SCALE; |
|
| 32 |
|
|
| 31 | 33 |
private Data3D mScale; |
| 32 | 34 |
|
| 33 | 35 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 38 | 40 |
*/ |
| 39 | 41 |
public boolean compute(float[] uniforms, int index, long currentDuration, long step ) |
| 40 | 42 |
{
|
| 41 |
return mScale.get(uniforms,index,currentDuration,step); |
|
| 43 |
return mScale.get(uniforms,index+VALUES_OFFSET,currentDuration,step); |
|
| 44 |
} |
|
| 45 |
|
|
| 46 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 47 |
|
|
| 48 |
static String code() |
|
| 49 |
{
|
|
| 50 |
return "v *= vUniforms[effect].xyz;"; |
|
| 42 | 51 |
} |
| 43 | 52 |
|
| 44 | 53 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 49 | 58 |
*/ |
| 50 | 59 |
public static void enable() |
| 51 | 60 |
{
|
| 52 |
addEffect( EffectName.VERTEX_SCALE, "v *= vUniforms[effect].xyz;" );
|
|
| 61 |
addEffect( NAME, code() );
|
|
| 53 | 62 |
} |
| 54 | 63 |
|
| 55 | 64 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 60 | 69 |
*/ |
| 61 | 70 |
public VertexEffectScale(Data3D scale) |
| 62 | 71 |
{
|
| 63 |
super(EffectName.VERTEX_SCALE);
|
|
| 72 |
super(NAME);
|
|
| 64 | 73 |
mScale = scale; |
| 65 | 74 |
} |
| 66 | 75 |
|
| ... | ... | |
| 72 | 81 |
*/ |
| 73 | 82 |
public VertexEffectScale(float scale) |
| 74 | 83 |
{
|
| 75 |
super(EffectName.VERTEX_SCALE);
|
|
| 84 |
super(NAME);
|
|
| 76 | 85 |
mScale = new Static3D(scale,scale,scale); |
| 77 | 86 |
} |
| 78 | 87 |
} |
| src/main/java/org/distorted/library/effect/VertexEffectShear.java | ||
|---|---|---|
| 27 | 27 |
*/ |
| 28 | 28 |
public class VertexEffectShear extends VertexEffect |
| 29 | 29 |
{
|
| 30 |
private Data3D mShear, mCenter; |
|
| 30 |
private static final EffectName NAME = EffectName.VERTEX_SHEAR; |
|
| 31 |
|
|
| 32 |
private Data3D mShear; |
|
| 33 |
private Data3D mCenter; |
|
| 31 | 34 |
|
| 32 | 35 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 33 | 36 |
/** |
| ... | ... | |
| 38 | 41 |
public boolean compute(float[] uniforms, int index, long currentDuration, long step ) |
| 39 | 42 |
{
|
| 40 | 43 |
mCenter.get(uniforms,index+CENTER_OFFSET,currentDuration,step); |
| 41 |
return mShear.get(uniforms,index,currentDuration,step); |
|
| 44 |
return mShear.get(uniforms,index+VALUES_OFFSET,currentDuration,step);
|
|
| 42 | 45 |
} |
| 43 | 46 |
|
| 44 | 47 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 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 | 48 |
|
| 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]; |
|
| 49 |
static String code() |
|
| 50 |
{
|
|
| 51 |
return |
|
| 52 |
|
|
| 53 |
"float sx = vUniforms[effect].x; \n" |
|
| 54 |
+ "float sy = vUniforms[effect].y; \n" |
|
| 55 |
+ "float sz = vUniforms[effect].z; \n" |
|
| 56 |
+ "vec3 center = vUniforms[effect+1].yzw; \n" |
|
| 55 | 57 |
|
| 56 |
Matrix.translateM(matrix, 0, x, y, z);
|
|
| 58 |
+ "v -= center; \n"
|
|
| 57 | 59 |
|
| 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 |
|
| 60 |
+ "float new_vx = (1.0+sx*sy)*v.x + sx*v.y; \n" |
|
| 61 |
+ "float new_vy = sy*v.x + v.y; \n" |
|
| 62 |
+ "float new_vz = sz*v.y + v.z; \n" |
|
| 62 | 63 |
|
| 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 |
|
| 64 |
+ "v.x = new_vx; \n" |
|
| 65 |
+ "v.y = new_vy; \n" |
|
| 66 |
+ "v.z = new_vz; \n" |
|
| 67 | 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 |
|
| 68 |
+ "v += center; \n" |
|
| 72 | 69 |
|
| 73 |
Matrix.translateM(matrix, 0,-x,-y,-z); |
|
| 74 |
*/ |
|
| 70 |
+ "float new_nx = (1.0+sx*sy)*n.x + sx*n.y; \n" |
|
| 71 |
+ "float new_ny = sy*n.x + n.y; \n" |
|
| 72 |
+ "float new_nz = sz*n.y + n.z; \n" |
|
| 75 | 73 |
|
| 74 |
+ "n.x = new_nx; \n" |
|
| 75 |
+ "n.y = new_ny; \n" |
|
| 76 |
+ "n.z = new_nz; \n"; |
|
| 77 |
} |
|
| 78 |
|
|
| 79 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 80 |
// PUBLIC API |
|
| 81 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 76 | 82 |
/** |
| 77 | 83 |
* Have to call this before the shaders get compiled (i.e before DistortedLibrary.onCreate()) for the Effect to work. |
| 78 | 84 |
*/ |
| 79 | 85 |
public static void enable() |
| 80 | 86 |
{
|
| 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 |
); |
|
| 87 |
addEffect( NAME, code() ); |
|
| 108 | 88 |
} |
| 109 | 89 |
|
| 110 | 90 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 119 | 99 |
*/ |
| 120 | 100 |
public VertexEffectShear(Data3D shear, Data3D center) |
| 121 | 101 |
{
|
| 122 |
super(EffectName.VERTEX_SHEAR);
|
|
| 102 |
super(NAME);
|
|
| 123 | 103 |
mShear = shear; |
| 124 | 104 |
mCenter = center; |
| 125 | 105 |
} |
| src/main/java/org/distorted/library/effect/VertexEffectSink.java | ||
|---|---|---|
| 30 | 30 |
*/ |
| 31 | 31 |
public class VertexEffectSink extends VertexEffect |
| 32 | 32 |
{
|
| 33 |
private static final EffectName NAME = EffectName.SINK; |
|
| 34 |
|
|
| 33 | 35 |
private Data1D mSink; |
| 34 | 36 |
private Data3D mCenter; |
| 35 | 37 |
private Data4D mRegion; |
| ... | ... | |
| 44 | 46 |
{
|
| 45 | 47 |
mCenter.get(uniforms,index+CENTER_OFFSET,currentDuration,step); |
| 46 | 48 |
mRegion.get(uniforms,index+REGION_OFFSET,currentDuration,step); |
| 47 |
return mSink.get(uniforms,index,currentDuration,step); |
|
| 49 |
return mSink.get(uniforms,index+VALUES_OFFSET,currentDuration,step);
|
|
| 48 | 50 |
} |
| 49 | 51 |
|
| 50 | 52 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 51 |
// PUBLIC API |
|
| 52 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 53 |
// Pull P=(v.x,v.y) towards center of the effect with P' = P + (1-h)*dist(S-P) |
|
| 54 |
// when h>1 we are pushing points away from S: P' = P + (1/h-1)*dist(S-P) |
|
| 55 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 56 |
/** |
|
| 57 |
* Have to call this before the shaders get compiled (i.e before DistortedLibrary.onCreate()) for the Effect to work. |
|
| 58 |
*/ |
|
| 59 |
public static void enable() |
|
| 53 |
|
|
| 54 |
static String code() |
|
| 60 | 55 |
{
|
| 61 |
addEffect(EffectName.SINK,
|
|
| 56 |
return
|
|
| 62 | 57 |
|
| 63 | 58 |
"vec3 ps = vUniforms[effect+1].yzw - v; \n" |
| 64 | 59 |
+ "float h = vUniforms[effect].x; \n" |
| ... | ... | |
| 74 | 69 |
+ "n_ps = (sign_ps*n_ps)/(dot_ps-(sign_ps-1.0)); \n" // uff! now n_ps is the parallel to ps component of n, even if ps==0 |
| 75 | 70 |
+ "float move = deg*(h-1.0)/(h/B+1.0/A); \n" // move(0)=-A*deg, move(1)=0, move(inf)=B*deg |
| 76 | 71 |
+ "n += move*n_ps; \n" |
| 77 |
+ "n = normalize(n);" |
|
| 78 |
); |
|
| 72 |
+ "n = normalize(n);"; |
|
| 73 |
} |
|
| 74 |
|
|
| 75 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 76 |
// PUBLIC API |
|
| 77 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 78 |
// Pull P=(v.x,v.y) towards center of the effect with P' = P + (1-h)*dist(S-P) |
|
| 79 |
// when h>1 we are pushing points away from S: P' = P + (1/h-1)*dist(S-P) |
|
| 80 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 81 |
/** |
|
| 82 |
* Have to call this before the shaders get compiled (i.e before DistortedLibrary.onCreate()) for the Effect to work. |
|
| 83 |
*/ |
|
| 84 |
public static void enable() |
|
| 85 |
{
|
|
| 86 |
addEffect(NAME, code() ); |
|
| 79 | 87 |
} |
| 80 | 88 |
|
| 81 | 89 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 89 | 97 |
*/ |
| 90 | 98 |
public VertexEffectSink(Data1D sink, Data3D center, Data4D region) |
| 91 | 99 |
{
|
| 92 |
super(EffectName.SINK);
|
|
| 100 |
super(NAME);
|
|
| 93 | 101 |
mSink = sink; |
| 94 | 102 |
mCenter = center; |
| 95 | 103 |
mRegion = (region==null ? MAX_REGION : region); |
| ... | ... | |
| 105 | 113 |
*/ |
| 106 | 114 |
public VertexEffectSink(Data1D sink, Data3D center) |
| 107 | 115 |
{
|
| 108 |
super(EffectName.SINK);
|
|
| 116 |
super(NAME);
|
|
| 109 | 117 |
mSink = sink; |
| 110 | 118 |
mCenter = center; |
| 111 | 119 |
mRegion = MAX_REGION; |
| src/main/java/org/distorted/library/effect/VertexEffectSwirl.java | ||
|---|---|---|
| 34 | 34 |
*/ |
| 35 | 35 |
public class VertexEffectSwirl extends VertexEffect |
| 36 | 36 |
{
|
| 37 |
private static final EffectName NAME = EffectName.SWIRL; |
|
| 38 |
|
|
| 37 | 39 |
private Data1D mSwirl; |
| 38 | 40 |
private Data3D mCenter; |
| 39 | 41 |
private Data4D mRegion; |
| ... | ... | |
| 48 | 50 |
{
|
| 49 | 51 |
mCenter.get(uniforms,index+CENTER_OFFSET,currentDuration,step); |
| 50 | 52 |
mRegion.get(uniforms,index+REGION_OFFSET,currentDuration,step); |
| 51 |
boolean ret = mSwirl.get(uniforms,index,currentDuration,step); |
|
| 53 |
boolean ret = mSwirl.get(uniforms,index+VALUES_OFFSET,currentDuration,step);
|
|
| 52 | 54 |
|
| 53 |
uniforms[index] = (float)(Math.PI*uniforms[index]/180); |
|
| 55 |
uniforms[index+VALUES_OFFSET] = (float)(Math.PI*uniforms[index]/180);
|
|
| 54 | 56 |
|
| 55 | 57 |
return ret; |
| 56 | 58 |
} |
| 57 | 59 |
|
| 58 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 59 |
// PUBLIC API |
|
| 60 | 60 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 61 | 61 |
// Let d be the degree of the current vertex V with respect to center of the effect S and Region vRegion. |
| 62 | 62 |
// This effect rotates the current vertex V by vInterpolated.x radians clockwise around the circle dilated |
| 63 | 63 |
// by (1-d) around the center of the effect S. |
| 64 | 64 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 65 |
/** |
|
| 66 |
* Have to call this before the shaders get compiled (i.e before DistortedLibrary.onCreate()) for the Effect to work. |
|
| 67 |
*/ |
|
| 68 |
public static void enable() |
|
| 65 |
|
|
| 66 |
static String code() |
|
| 69 | 67 |
{
|
| 70 |
addEffect(EffectName.SWIRL,
|
|
| 68 |
return
|
|
| 71 | 69 |
|
| 72 | 70 |
"vec3 center = vUniforms[effect+1].yzw; \n" |
| 73 | 71 |
+ "vec3 PS = center-v.xyz; \n" |
| ... | ... | |
| 81 | 79 |
+ "vec4 SG = (1.0-deg1)*SO; \n" // coordinates of the dilated circle P is going to get rotated around |
| 82 | 80 |
+ "float d2 = max(0.0,degree(SG,PS2)); \n" // make it a max(0,deg) because otherwise when center=left edge of the |
| 83 | 81 |
// object some points end up with d2<0 and they disappear off view. |
| 84 |
+ "v.xy += deg1 * (PS.xy - PS2.xy/(1.0-d2)); \n" // if d2=1 (i.e P=center) we should have P unchanged. How to do it? |
|
| 85 |
); |
|
| 82 |
+ "v.xy += deg1 * (PS.xy - PS2.xy/(1.0-d2)); \n";// if d2=1 (i.e P=center) we should have P unchanged. How to do it? |
|
| 83 |
} |
|
| 84 |
|
|
| 85 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 86 |
// PUBLIC API |
|
| 87 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 88 |
/** |
|
| 89 |
* Have to call this before the shaders get compiled (i.e before DistortedLibrary.onCreate()) for the Effect to work. |
|
| 90 |
*/ |
|
| 91 |
public static void enable() |
|
| 92 |
{
|
|
| 93 |
addEffect( NAME, code() ); |
|
| 86 | 94 |
} |
| 87 | 95 |
|
| 88 | 96 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 95 | 103 |
*/ |
| 96 | 104 |
public VertexEffectSwirl(Data1D swirl, Data3D center, Data4D region) |
| 97 | 105 |
{
|
| 98 |
super(EffectName.SWIRL);
|
|
| 106 |
super(NAME);
|
|
| 99 | 107 |
mSwirl = swirl; |
| 100 | 108 |
mCenter = center; |
| 101 | 109 |
mRegion = (region==null ? MAX_REGION : region); |
| ... | ... | |
| 110 | 118 |
*/ |
| 111 | 119 |
public VertexEffectSwirl(Data1D swirl, Data3D center) |
| 112 | 120 |
{
|
| 113 |
super(EffectName.SWIRL);
|
|
| 121 |
super(NAME);
|
|
| 114 | 122 |
mSwirl = swirl; |
| 115 | 123 |
mCenter = center; |
| 116 | 124 |
mRegion = MAX_REGION; |
| src/main/java/org/distorted/library/effect/VertexEffectWave.java | ||
|---|---|---|
| 33 | 33 |
*/ |
| 34 | 34 |
public class VertexEffectWave extends VertexEffect |
| 35 | 35 |
{
|
| 36 |
private static final EffectName NAME = EffectName.WAVE; |
|
| 37 |
|
|
| 36 | 38 |
private Data5D mWave; |
| 37 | 39 |
private Data3D mCenter; |
| 38 | 40 |
private Data4D mRegion; |
| ... | ... | |
| 47 | 49 |
{
|
| 48 | 50 |
mCenter.get(uniforms,index+CENTER_OFFSET,currentDuration,step); |
| 49 | 51 |
mRegion.get(uniforms,index+REGION_OFFSET,currentDuration,step); |
| 50 |
boolean ret = mWave.get(uniforms,index,currentDuration,step); |
|
| 52 |
boolean ret = mWave.get(uniforms,index+VALUES_OFFSET,currentDuration,step);
|
|
| 51 | 53 |
|
| 52 |
uniforms[index+2] = (float)(Math.PI*uniforms[index+2]/180); |
|
| 53 |
uniforms[index+3] = (float)(Math.PI*uniforms[index+3]/180); |
|
| 54 |
uniforms[index+4] = (float)(Math.PI*uniforms[index+4]/180); |
|
| 54 |
uniforms[index+VALUES_OFFSET+2] = (float)(Math.PI*uniforms[index+2]/180);
|
|
| 55 |
uniforms[index+VALUES_OFFSET+3] = (float)(Math.PI*uniforms[index+3]/180);
|
|
| 56 |
uniforms[index+VALUES_OFFSET+4] = (float)(Math.PI*uniforms[index+4]/180);
|
|
| 55 | 57 |
|
| 56 | 58 |
return ret; |
| 57 | 59 |
} |
| 58 | 60 |
|
| 59 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 60 |
// PUBLIC API |
|
| 61 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 61 |
////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 62 | 62 |
// Directional sinusoidal wave effect. |
| 63 | 63 |
// |
| 64 | 64 |
// This is an effect from a (hopefully!) generic family of effects of the form (vec3 V: |V|=1 , f(x,y) ) (*) |
| ... | ... | |
| 122 | 122 |
// |
| 123 | 123 |
// Generally speaking I'd keep to amplitude < length, as the opposite case has some other problems as well. |
| 124 | 124 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 125 |
/** |
|
| 126 |
* Have to call this before the shaders get compiled (i.e before DistortedLibrary.onCreate()) for the Effect to work. |
|
| 127 |
*/ |
|
| 128 |
public static void enable() |
|
| 125 |
|
|
| 126 |
static String code() |
|
| 129 | 127 |
{
|
| 130 |
addEffect(EffectName.WAVE,
|
|
| 128 |
return
|
|
| 131 | 129 |
|
| 132 | 130 |
"vec3 center = vUniforms[effect+1].yzw; \n" |
| 133 | 131 |
+ "float amplitude = vUniforms[effect ].x; \n" |
| ... | ... | |
| 184 | 182 |
+ "n.y = (n.y*normal.z + n.z*normal.y); \n" // ? Because if we do the above, my Nexus4 crashes |
| 185 | 183 |
+ "n.z = (n.z*normal.z); \n" // during shader compilation! |
| 186 | 184 |
+ "} \n" |
| 187 |
+ "}" |
|
| 188 |
); |
|
| 185 |
+ "}"; |
|
| 186 |
} |
|
| 187 |
|
|
| 188 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 189 |
// PUBLIC API |
|
| 190 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 191 |
/** |
|
| 192 |
* Have to call this before the shaders get compiled (i.e before DistortedLibrary.onCreate()) for the Effect to work. |
|
| 193 |
*/ |
|
| 194 |
public static void enable() |
|
| 195 |
{
|
|
| 196 |
addEffect( NAME, code() ); |
|
| 189 | 197 |
} |
| 190 | 198 |
|
| 191 | 199 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 219 | 227 |
*/ |
| 220 | 228 |
public VertexEffectWave(Data5D wave, Data3D center, Data4D region) |
| 221 | 229 |
{
|
| 222 |
super(EffectName.WAVE);
|
|
| 230 |
super(NAME);
|
|
| 223 | 231 |
mWave = wave; |
| 224 | 232 |
mCenter = center; |
| 225 | 233 |
mRegion = (region==null ? MAX_REGION : region); |
| ... | ... | |
| 229 | 237 |
/** |
| 230 | 238 |
* Directional, sinusoidal wave effect. |
| 231 | 239 |
* |
| 232 |
* @param wave see {@link #VertexEffectWave(Data5D,Data3D)}
|
|
| 240 |
* @param wave see {@link #VertexEffectWave(Data5D,Data3D,Data4D)}
|
|
| 233 | 241 |
* @param center 3-dimensional Data that, at any given time, returns the Center of the Effect. |
| 234 | 242 |
*/ |
| 235 | 243 |
public VertexEffectWave(Data5D wave, Data3D center) |
| 236 | 244 |
{
|
| 237 |
super(EffectName.WAVE);
|
|
| 245 |
super(NAME);
|
|
| 238 | 246 |
mWave = wave; |
| 239 | 247 |
mCenter = center; |
| 240 | 248 |
mRegion = MAX_REGION; |
| src/main/java/org/distorted/library/effectqueue/EffectQueue.java | ||
|---|---|---|
| 37 | 37 |
*/ |
| 38 | 38 |
public abstract class EffectQueue implements InternalMaster.Slave |
| 39 | 39 |
{
|
| 40 |
static final int MAIN_VARIANTS = 3; // Number of Main program variants (ATM 3: MAIN, MAIN OIT, PREPROCESS)
|
|
| 40 |
static final int MAIN_VARIANTS = 4; // Number of Main program variants (ATM 4: MAIN, MAIN OIT, PREPROCESS, FULL)
|
|
| 41 | 41 |
|
| 42 | 42 |
private static final int CREATE = 0; |
| 43 | 43 |
private static final int ATTACH = 1; |
| ... | ... | |
| 47 | 47 |
int mNumEffects; // 'ToBe' will be more than mNumEffects if doWork() hasn't |
| 48 | 48 |
private int mNumEffectsToBe; // added them yet (or less if it hasn't removed some yet) |
| 49 | 49 |
float[] mUniforms; |
| 50 |
private int mNumUniforms; |
|
| 50 | 51 |
long[] mCurrentDuration; |
| 51 | 52 |
Effect[] mEffects; |
| 52 | 53 |
int[] mName; |
| 53 |
long mTime=0;
|
|
| 54 |
long mTime; |
|
| 54 | 55 |
|
| 55 | 56 |
private static int[] mMax = new int[EffectType.LENGTH]; |
| 56 | 57 |
private static long mNextID; |
| ... | ... | |
| 60 | 61 |
private int mIndex; |
| 61 | 62 |
private boolean mCreated; |
| 62 | 63 |
|
| 63 |
private class Job |
|
| 64 |
private static class Job
|
|
| 64 | 65 |
{
|
| 65 | 66 |
int type; |
| 66 | 67 |
int num; |
| ... | ... | |
| 88 | 89 |
EffectQueue(int numUniforms, int index) |
| 89 | 90 |
{
|
| 90 | 91 |
mCreated = false; |
| 92 |
mTime = 0; |
|
| 91 | 93 |
mID = 0; |
| 92 | 94 |
mNumEffects = 0; |
| 93 | 95 |
mNumEffectsToBe = 0; |
| 94 | 96 |
mIndex = index; |
| 97 |
mNumUniforms = numUniforms; |
|
| 95 | 98 |
|
| 96 |
mJobs.add(new Job(CREATE,numUniforms,false,null)); // create the stuff that depends on max number
|
|
| 99 |
mJobs.add(new Job(CREATE,numUniforms,false,null)); // create the stuff that depends on max number |
|
| 97 | 100 |
InternalMaster.newSlave(this); // of uniforms later, on first render. |
| 98 | 101 |
} |
| 99 | 102 |
|
| 103 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 104 |
|
|
| 105 |
EffectQueue(EffectQueue source) |
|
| 106 |
{
|
|
| 107 |
if( !source.mCreated ) |
|
| 108 |
{
|
|
| 109 |
mCreated = false; |
|
| 110 |
mTime = 0; |
|
| 111 |
mID = 0; |
|
| 112 |
mNumEffects = 0; |
|
| 113 |
mNumEffectsToBe = 0; |
|
| 114 |
mIndex = source.mIndex; |
|
| 115 |
mNumUniforms = source.mNumUniforms; |
|
| 116 |
|
|
| 117 |
int numJobs = source.mJobs.size(); |
|
| 118 |
|
|
| 119 |
for(int i=0; i<numJobs; i++) |
|
| 120 |
{
|
|
| 121 |
Job job = source.mJobs.get(i); |
|
| 122 |
mJobs.add(job); |
|
| 123 |
} |
|
| 124 |
|
|
| 125 |
InternalMaster.newSlave(this); |
|
| 126 |
} |
|
| 127 |
else |
|
| 128 |
{
|
|
| 129 |
mCreated = true; |
|
| 130 |
mTime = source.mTime; |
|
| 131 |
mID = source.mID; |
|
| 132 |
mNumEffects = source.mNumEffects; |
|
| 133 |
mNumEffectsToBe = source.mNumEffectsToBe; |
|
| 134 |
mIndex = source.mIndex; |
|
| 135 |
mNumUniforms = source.mNumUniforms; |
|
| 136 |
|
|
| 137 |
int max = mMax[mIndex]; |
|
| 138 |
if( max>0 ) |
|
| 139 |
{
|
|
| 140 |
mUniforms = new float[max*source.mNumUniforms]; |
|
| 141 |
mCurrentDuration = new long[max]; |
|
| 142 |
mEffects = new Effect[max]; |
|
| 143 |
mName = new int[max]; |
|
| 144 |
} |
|
| 145 |
|
|
| 146 |
for(int i=0; i<mNumEffects; i++ ) |
|
| 147 |
{
|
|
| 148 |
mEffects[i] = source.mEffects[i]; |
|
| 149 |
mCurrentDuration[i] = source.mCurrentDuration[i]; |
|
| 150 |
mName[i] = source.mName[i]; |
|
| 151 |
} |
|
| 152 |
} |
|
| 153 |
} |
|
| 154 |
|
|
| 100 | 155 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 101 | 156 |
|
| 102 | 157 |
public static void allocateQueues(EffectQueue[] queues, EffectQueue[] from, int flags) |
| ... | ... | |
| 135 | 190 |
} |
| 136 | 191 |
|
| 137 | 192 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 193 |
// variant: 0 --> MAIN 1 --> OIT 2 --> prePOST 3 --> FULL |
|
| 138 | 194 |
|
| 139 | 195 |
public static void getUniforms(int programH, int variant) |
| 140 | 196 |
{
|
| src/main/java/org/distorted/library/effectqueue/EffectQueueFragment.java | ||
|---|---|---|
| 43 | 43 |
super(NUM_UNIFORMS,INDEX); |
| 44 | 44 |
} |
| 45 | 45 |
|
| 46 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 47 |
|
|
| 48 |
EffectQueueFragment(EffectQueueFragment source) |
|
| 49 |
{
|
|
| 50 |
super(source); |
|
| 51 |
} |
|
| 52 |
|
|
| 46 | 53 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 47 | 54 |
|
| 48 | 55 |
static void uniforms(int mProgramH, int variant) |
| src/main/java/org/distorted/library/effectqueue/EffectQueueMatrix.java | ||
|---|---|---|
| 47 | 47 |
super(NUM_UNIFORMS,INDEX ); |
| 48 | 48 |
} |
| 49 | 49 |
|
| 50 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 51 |
|
|
| 52 |
EffectQueueMatrix(EffectQueueMatrix source) |
|
| 53 |
{
|
|
| 54 |
super(source); |
|
| 55 |
} |
|
| 56 |
|
|
| 50 | 57 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 51 | 58 |
|
| 52 | 59 |
static void uniforms(int mProgramH, int variant) |
| src/main/java/org/distorted/library/effectqueue/EffectQueuePostprocess.java | ||
|---|---|---|
| 64 | 64 |
super(NUM_UNIFORMS,INDEX ); |
| 65 | 65 |
} |
| 66 | 66 |
|
| 67 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 68 |
|
|
| 69 |
EffectQueuePostprocess(EffectQueuePostprocess source) |
|
| 70 |
{
|
|
| 71 |
super(source); |
|
| 72 |
} |
|
| 73 |
|
|
| 67 | 74 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 68 | 75 |
|
| 69 | 76 |
void compute(long currTime) |
| src/main/java/org/distorted/library/effectqueue/EffectQueueVertex.java | ||
|---|---|---|
| 26 | 26 |
import org.distorted.library.message.EffectMessageSender; |
| 27 | 27 |
|
| 28 | 28 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 29 |
|
|
| 30 |
class EffectQueueVertex extends EffectQueue |
|
| 29 |
/** |
|
| 30 |
* Not part of public API, do not document (public only because has to be used in Meshes) |
|
| 31 |
* |
|
| 32 |
* @y.exclude |
|
| 33 |
*/ |
|
| 34 |
public class EffectQueueVertex extends EffectQueue |
|
| 31 | 35 |
{
|
| 32 | 36 |
private static final int NUM_UNIFORMS = VertexEffect.NUM_UNIFORMS; |
| 33 | 37 |
private static final int INDEX = EffectType.VERTEX.ordinal(); |
| ... | ... | |
| 39 | 43 |
|
| 40 | 44 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 41 | 45 |
|
| 42 |
EffectQueueVertex() |
|
| 46 |
public EffectQueueVertex()
|
|
| 43 | 47 |
{
|
| 44 | 48 |
super(NUM_UNIFORMS,INDEX); |
| 45 | 49 |
} |
| 46 | 50 |
|
| 51 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 52 |
|
|
| 53 |
public EffectQueueVertex(EffectQueueVertex source) |
|
| 54 |
{
|
|
| 55 |
super(source); |
|
| 56 |
} |
|
| 57 |
|
|
| 47 | 58 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 48 | 59 |
|
| 49 | 60 |
static void uniforms(int mProgramH, int variant) |
| ... | ... | |
| 55 | 66 |
} |
| 56 | 67 |
|
| 57 | 68 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 58 |
|
|
| 59 |
void compute(long currTime) |
|
| 69 |
/** |
|
| 70 |
* Not part of public API, do not document (public only because has to be used in Meshes) |
|
| 71 |
* |
|
| 72 |
* @y.exclude |
|
| 73 |
*/ |
|
| 74 |
public void compute(long currTime) |
|
| 60 | 75 |
{
|
| 61 | 76 |
if( currTime==mTime ) return; |
| 62 | 77 |
if( mTime==0 ) mTime = currTime; |
| ... | ... | |
| 76 | 91 |
} |
| 77 | 92 |
|
| 78 | 93 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 79 |
|
|
| 80 |
void send(float inflate, int variant) |
|
| 94 |
/** |
|
| 95 |
* Not part of public API, do not document (public only because has to be used in Meshes) |
|
| 96 |
* |
|
| 97 |
* @y.exclude |
|
| 98 |
*/ |
|
| 99 |
public void send(float inflate, int variant) |
|
| 81 | 100 |
{
|
| 82 | 101 |
GLES30.glUniform1i( mNumEffectsH[variant], mNumEffects); |
| 83 | 102 |
GLES30.glUniform1f( mInflateH[variant] , inflate ); |
| src/main/java/org/distorted/library/main/DistortedLibrary.java | ||
|---|---|---|
| 129 | 129 |
private static int mBlitDepthH; |
| 130 | 130 |
private static final FloatBuffer mQuadPositions; |
| 131 | 131 |
|
| 132 |
/// FULL PROGRAM /// |
|
| 133 |
private static DistortedProgram mFullProgram; |
|
| 134 |
|
|
| 132 | 135 |
static |
| 133 | 136 |
{
|
| 134 | 137 |
float[] positionData= { -0.5f, -0.5f, -0.5f, 0.5f, 0.5f,-0.5f, 0.5f, 0.5f };
|
| ... | ... | |
| 288 | 291 |
mNormalMVPMatrixH = GLES30.glGetUniformLocation( normalProgramH, "u_MVPMatrix"); |
| 289 | 292 |
} |
| 290 | 293 |
|
| 294 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 295 |
|
|
| 296 |
private static void createFullProgram(Resources resources) |
|
| 297 |
{
|
|
| 298 |
final InputStream fullVertStream = resources.openRawResource(R.raw.main_vertex_shader); |
|
| 299 |
final InputStream fullFragStream = resources.openRawResource(R.raw.main_fragment_shader); |
|
| 300 |
|
|
| 301 |
int numV = VertexEffect.getAllEnabled(); |
|
| 302 |
|
|
| 303 |
String fullVertHeader= mGLSL_VERSION + ("#define NUM_VERTEX " + ( numV>0 ? getMax(EffectType.VERTEX ) : 0 ) + "\n");
|
|
| 304 |
String fullFragHeader= mGLSL_VERSION + ("#define NUM_FRAGMENT " + 0 + "\n");
|
|
| 305 |
String enabledEffectV= VertexEffect.getAllGLSL(); |
|
| 306 |
String enabledEffectF= "{}";
|
|
| 307 |
|
|
| 308 |
String[] feedback = { "v_Position", "v_endPosition" };
|
|
| 309 |
|
|
| 310 |
try |
|
| 311 |
{
|
|
| 312 |
mFullProgram = new DistortedProgram(fullVertStream, fullFragStream, fullVertHeader, fullFragHeader, |
|
| 313 |
enabledEffectV, enabledEffectF, mGLSL, feedback); |
|
| 314 |
} |
|
| 315 |
catch(Exception e) |
|
| 316 |
{
|
|
| 317 |
Log.e("EFFECTS", e.getClass().getSimpleName()+" trying to compile FULL program: "+e.getMessage());
|
|
| 318 |
throw new RuntimeException(e.getMessage()); |
|
| 319 |
} |
|
| 320 |
|
|
| 321 |
int fullProgramH = mFullProgram.getProgramHandle(); |
|
| 322 |
EffectQueue.getUniforms(fullProgramH,3); |
|
| 323 |
} |
|
| 324 |
|
|
| 291 | 325 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 292 | 326 |
|
| 293 | 327 |
private static void createProgramsOIT(Resources resources) |
| ... | ... | |
| 418 | 452 |
GLES30.glEndTransformFeedback(); |
| 419 | 453 |
GLES30.glBindBufferBase(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, 0, 0); |
| 420 | 454 |
|
| 421 |
DistortedLibrary.mNormalProgram.useProgram();
|
|
| 422 |
GLES30.glUniformMatrix4fv(DistortedLibrary.mNormalMVPMatrixH, 1, false, EffectQueue.getMVP(queues) , 0);
|
|
| 423 |
mesh.bindTransformAttribs(DistortedLibrary.mNormalProgram);
|
|
| 455 |
mNormalProgram.useProgram(); |
|
| 456 |
GLES30.glUniformMatrix4fv(mNormalMVPMatrixH, 1, false, EffectQueue.getMVP(queues) , 0); |
|
| 457 |
mesh.bindTransformAttribs(mNormalProgram); |
|
| 424 | 458 |
GLES30.glLineWidth(8.0f); |
| 425 | 459 |
GLES30.glDrawArrays(GLES30.GL_LINES, 0, 2*num); |
| 426 | 460 |
} |
| 427 | 461 |
|
| 462 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 463 |
// execute all VertexEffects and adjust all vertices |
|
| 464 |
|
|
| 465 |
public static void adjustVertices(MeshBase mesh) |
|
| 466 |
{
|
|
| 467 |
if( mFullProgram!=null ) |
|
| 468 |
{
|
|
| 469 |
GLES30.glViewport(0, 0, 500, 500 ); // TODO ??? |
|
| 470 |
|
|
| 471 |
int num = mesh.getNumVertices(); |
|
| 472 |
int tfo = mesh.getTFO(); |
|
| 473 |
|
|
| 474 |
mFullProgram.useProgram(); |
|
| 475 |
mesh.bindVertexAttribs(mFullProgram); |
|
| 476 |
mesh.computeQueue(); |
|
| 477 |
mesh.sendQueue(); |
|
| 478 |
|
|
| 479 |
GLES30.glBindBufferBase(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, 0, tfo ); |
|
| 480 |
GLES30.glBeginTransformFeedback( GLES30.GL_POINTS); |
|
| 481 |
InternalRenderState.switchOffDrawing(); |
|
| 482 |
GLES30.glDrawArrays( GLES30.GL_POINTS, 0, num ); |
|
| 483 |
InternalRenderState.restoreDrawing(); |
|
| 484 |
GLES30.glEndTransformFeedback(); |
|
| 485 |
GLES30.glBindBufferBase(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, 0, 0); |
|
| 486 |
|
|
| 487 |
mesh.copyTransformToVertex(); |
|
| 488 |
} |
|
| 489 |
} |
|
| 490 |
|
|
| 428 | 491 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 429 | 492 |
|
| 430 | 493 |
static void drawPrivOIT(DistortedEffects effects, MeshBase mesh, InternalOutputSurface surface, long currTime) |
| ... | ... | |
| 460 | 523 |
|
| 461 | 524 |
static void drawPriv(DistortedEffects effects, MeshBase mesh, InternalOutputSurface surface, long currTime) |
| 462 | 525 |
{
|
| 463 |
if( mMainOITProgram!=null )
|
|
| 526 |
if( mMainProgram!=null ) |
|
| 464 | 527 |
{
|
| 465 | 528 |
EffectQueue[] queues = effects.getQueues(); |
| 466 | 529 |
|
| ... | ... | |
| 824 | 887 |
exception = ex; |
| 825 | 888 |
} |
| 826 | 889 |
|
| 890 |
try |
|
| 891 |
{
|
|
Also available in: Unified diff
First attempt at the MeshBase.apply(VertexEffect) API.