Revision 9829a8fd
Added by Leszek Koltunski 6 months ago
| src/main/java/org/distorted/library/effect/Effect.kt | ||
|---|---|---|
| 18 | 18 |
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // |
| 19 | 19 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 20 | 20 |
|
| 21 |
package org.distorted.library.effect;
|
|
| 21 |
package org.distorted.library.effect |
|
| 22 | 22 |
|
| 23 |
import org.distorted.library.effectqueue.EffectQueue; |
|
| 24 |
import org.distorted.library.main.DistortedLibrary; |
|
| 25 |
import org.distorted.library.main.InternalStackFrameList; |
|
| 26 |
import org.distorted.library.message.EffectListener; |
|
| 27 |
|
|
| 28 |
import java.lang.reflect.Method; |
|
| 29 |
import java.util.ArrayList; |
|
| 23 |
import org.distorted.library.effectqueue.EffectQueue |
|
| 24 |
import org.distorted.library.main.DistortedLibrary |
|
| 25 |
import org.distorted.library.main.InternalStackFrameList |
|
| 26 |
import org.distorted.library.message.EffectListener |
|
| 27 |
import java.lang.reflect.Method |
|
| 30 | 28 |
|
| 31 | 29 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 32 | 30 |
/** |
| 33 | 31 |
* Abstract Effect of any type. |
| 34 | 32 |
*/ |
| 35 |
public abstract class Effect |
|
| 36 |
{
|
|
| 37 |
private final static int MAX_UNITY_DIM = 4; |
|
| 38 |
private final static int NUM_EFFECTS = EffectName.LENGTH; |
|
| 39 |
|
|
| 40 |
private final long mID; |
|
| 41 |
private final EffectType mType; |
|
| 42 |
private final EffectName mName; |
|
| 43 |
private final int mDimension; |
|
| 44 |
private final int mRegionDim; |
|
| 45 |
private final int mCenterDim; |
|
| 46 |
|
|
| 47 |
private ArrayList<EffectListener> mListeners =null; |
|
| 48 |
private int mNumListeners=0; // ==mListeners.length(), but we only create mListeners if the first one gets added |
|
| 49 |
|
|
| 50 |
private final static float[] mUnity= new float[MAX_UNITY_DIM*NUM_EFFECTS]; |
|
| 51 |
private final static int[] mUnityDim = new int[NUM_EFFECTS]; |
|
| 52 |
|
|
| 53 |
int mAndAssociation; |
|
| 54 |
int mEquAssociation; |
|
| 55 |
|
|
| 56 |
static boolean[] mEnabled = new boolean[NUM_EFFECTS]; |
|
| 57 |
|
|
| 58 |
static |
|
| 59 |
{
|
|
| 60 |
for(int i=0; i<NUM_EFFECTS; i++) mEnabled[i] = false; |
|
| 61 |
} |
|
| 62 |
|
|
| 63 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 64 |
|
|
| 65 |
public abstract void addQueue(EffectQueue queue); |
|
| 66 |
public abstract void remQueue(EffectQueue queue); |
|
| 67 |
|
|
| 68 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 69 |
|
|
| 70 |
Effect(EffectName name) |
|
| 71 |
{
|
|
| 72 |
mName = name; |
|
| 73 |
mType = name.getType(); |
|
| 74 |
mDimension = name.getEffectDimension(); |
|
| 75 |
mCenterDim = name.getCenterDimension(); |
|
| 76 |
mRegionDim = name.getRegionDimension(); |
|
| 77 |
|
|
| 78 |
mAndAssociation = 0xffffffff; |
|
| 79 |
mEquAssociation = 0; |
|
| 80 |
|
|
| 81 |
int n = name.ordinal(); |
|
| 82 |
float[] u = name.getUnity(); |
|
| 83 |
int l = u.length; |
|
| 84 |
|
|
| 85 |
System.arraycopy(u, 0, mUnity, MAX_UNITY_DIM*n, l); |
|
| 86 |
|
|
| 87 |
mUnityDim[n] = l; |
|
| 88 |
|
|
| 89 |
mID = (InternalStackFrameList.getNextEffectID()<<EffectType.LENGTH) + mType.ordinal(); |
|
| 90 |
} |
|
| 91 |
|
|
| 92 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 93 |
/** |
|
| 94 |
* Only for use by the library itself. |
|
| 95 |
* |
|
| 96 |
* @y.exclude |
|
| 97 |
*/ |
|
| 98 |
public static void onPause() |
|
| 99 |
{
|
|
| 100 |
for(int i=0; i<NUM_EFFECTS; i++) mEnabled[i] = false; |
|
| 101 |
|
|
| 102 |
MatrixEffect.destroyStatics(); |
|
| 103 |
VertexEffect.destroyStatics(); |
|
| 104 |
FragmentEffect.destroyStatics(); |
|
| 105 |
PostprocessEffect.destroyStatics(); |
|
| 106 |
} |
|
| 107 |
|
|
| 108 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 109 |
/** |
|
| 110 |
* Only for use by the library itself. |
|
| 111 |
* |
|
| 112 |
* @y.exclude |
|
| 113 |
*/ |
|
| 114 |
public abstract boolean compute(float[] uniforms, int index, long currentDuration, long step ); |
|
| 115 |
|
|
| 116 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 117 |
/** |
|
| 118 |
* Only for use by the library itself. |
|
| 119 |
* |
|
| 120 |
* @y.exclude |
|
| 121 |
*/ |
|
| 122 |
public int getNumListeners() |
|
| 123 |
{
|
|
| 124 |
return mNumListeners; |
|
| 125 |
} |
|
| 126 |
|
|
| 127 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 128 |
/** |
|
| 129 |
* Only for use by the library itself. |
|
| 130 |
* |
|
| 131 |
* @y.exclude |
|
| 132 |
*/ |
|
| 133 |
public EffectListener removeFirstListener() |
|
| 134 |
{
|
|
| 135 |
if( mNumListeners>0 ) |
|
| 136 |
{
|
|
| 137 |
mNumListeners--; |
|
| 138 |
return mListeners.remove(0); |
|
| 139 |
} |
|
| 140 |
|
|
| 141 |
return null; |
|
| 142 |
} |
|
| 143 |
|
|
| 144 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 145 |
/** |
|
| 146 |
* Only for use by the library itself. |
|
| 147 |
* |
|
| 148 |
* @y.exclude |
|
| 149 |
*/ |
|
| 150 |
public void writeAssociations(int[] intUniforms, int index1, int index2) |
|
| 151 |
{
|
|
| 152 |
intUniforms[index1] = mAndAssociation; |
|
| 153 |
intUniforms[index2] = mEquAssociation; |
|
| 154 |
} |
|
| 155 |
|
|
| 156 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 157 |
// PUBLIC API |
|
| 158 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 159 |
/** |
|
| 160 |
* Do the set of Uniforms written in buffer[index], buffer[index+1], etc represent a Unity, i.e a |
|
| 161 |
* null Effect? |
|
| 162 |
*/ |
|
| 163 |
public boolean isUnity(float[] buffer, int index) |
|
| 164 |
{
|
|
| 165 |
int name = mName.ordinal(); |
|
| 166 |
|
|
| 167 |
switch(mUnityDim[name]) |
|
| 168 |
{
|
|
| 169 |
case 0: return true; |
|
| 170 |
case 1: return buffer[index ]==mUnity[MAX_UNITY_DIM*name ]; |
|
| 171 |
case 2: return buffer[index ]==mUnity[MAX_UNITY_DIM*name ] && |
|
| 172 |
buffer[index+1]==mUnity[MAX_UNITY_DIM*name+1]; |
|
| 173 |
case 3: return buffer[index ]==mUnity[MAX_UNITY_DIM*name ] && |
|
| 174 |
buffer[index+1]==mUnity[MAX_UNITY_DIM*name+1] && |
|
| 175 |
buffer[index+2]==mUnity[MAX_UNITY_DIM*name+2]; |
|
| 176 |
case 4: return buffer[index ]==mUnity[MAX_UNITY_DIM*name ] && |
|
| 177 |
buffer[index+1]==mUnity[MAX_UNITY_DIM*name+1] && |
|
| 178 |
buffer[index+2]==mUnity[MAX_UNITY_DIM*name+2] && |
|
| 179 |
buffer[index+3]==mUnity[MAX_UNITY_DIM*name+3]; |
|
| 180 |
} |
|
| 181 |
|
|
| 182 |
return false; |
|
| 183 |
} |
|
| 184 |
|
|
| 185 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 186 |
// this will enable() all Fragment Effects twice (once for smooth variant, once for non-smooth) |
|
| 187 |
// but this shouldn't matter. |
|
| 188 |
/** |
|
| 189 |
* Enable all effects of a given type. |
|
| 190 |
* |
|
| 191 |
* @param type EffectType to enable. |
|
| 192 |
*/ |
|
| 193 |
public static void enableEffects(EffectType type) |
|
| 194 |
{
|
|
| 195 |
Method method; |
|
| 33 |
abstract class Effect internal constructor (val name: EffectName) |
|
| 34 |
{
|
|
| 35 |
val iD: Long // unique ID of this Effect. |
|
| 36 |
val type: EffectType = name.type // EffectType enum corresponding to this Effect. |
|
| 37 |
val effectDimension: Int = name.effectDimension // number of Uniforms needed to describe this effect. |
|
| 38 |
val regionDimension: Int = name.regionDimension // dimension of the Region supported by this effect (0- no region supported at all). |
|
| 39 |
val centerDimension: Int = name.centerDimension // dimension of the Center supported by this effect (0- no center supported at all). |
|
| 40 |
var numListeners: Int = 0 // ==mListeners.length(), but we only create mListeners if the first one gets added |
|
| 41 |
private set |
|
| 42 |
val string: String get() = name.name // printable name of this Effect. |
|
| 43 |
|
|
| 44 |
var mAndAssociation: Int = -0x1 |
|
| 45 |
var mEquAssociation: Int = 0 |
|
| 46 |
private var mListeners: ArrayList<EffectListener>? = null |
|
| 47 |
|
|
| 48 |
companion object |
|
| 49 |
{
|
|
| 50 |
private const val MAX_UNITY_DIM = 4 |
|
| 51 |
private val NUM_EFFECTS: Int = EffectName.LENGTH |
|
| 52 |
private val mUnity = FloatArray(MAX_UNITY_DIM*NUM_EFFECTS) |
|
| 53 |
private val mUnityDim = IntArray(NUM_EFFECTS) |
|
| 54 |
var mEnabled: BooleanArray = BooleanArray(NUM_EFFECTS) |
|
| 55 |
|
|
| 56 |
init |
|
| 57 |
{
|
|
| 58 |
for (i in 0 until NUM_EFFECTS) mEnabled[i] = false |
|
| 59 |
} |
|
| 196 | 60 |
|
| 197 |
for(EffectName name: EffectName.values()) |
|
| 198 |
{
|
|
| 199 |
if( name.getType() == type ) |
|
| 61 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 62 |
/** |
|
| 63 |
* Only for use by the library itself. |
|
| 64 |
* |
|
| 65 |
* @y.exclude |
|
| 66 |
*/ |
|
| 67 |
@JvmStatic |
|
| 68 |
fun onPause() |
|
| 200 | 69 |
{
|
| 201 |
Class<? extends Effect> cls = name.getEffectClass();
|
|
| 70 |
for (i in 0 until NUM_EFFECTS) mEnabled[i] = false
|
|
| 202 | 71 |
|
| 203 |
try |
|
| 204 |
{
|
|
| 205 |
method = cls.getMethod("enable"); // getMethod and NOT getDeclaredMethod because enable()
|
|
| 206 |
// is public |
|
| 207 |
} |
|
| 208 |
catch(NoSuchMethodException ex) |
|
| 209 |
{
|
|
| 210 |
DistortedLibrary.logMessage("Effect: exception getting method: "+ex.getMessage());
|
|
| 211 |
method = null; |
|
| 212 |
} |
|
| 72 |
MatrixEffect.destroyStatics() |
|
| 73 |
VertexEffect.destroyStatics() |
|
| 74 |
FragmentEffect.destroyStatics() |
|
| 75 |
PostprocessEffect.destroyStatics() |
|
| 76 |
} |
|
| 213 | 77 |
|
| 214 |
try |
|
| 215 |
{
|
|
| 216 |
if( method!=null ) method.invoke(null); |
|
| 217 |
} |
|
| 218 |
catch(Exception ex) |
|
| 219 |
{
|
|
| 220 |
DistortedLibrary.logMessage("Effect: exception invoking method: "+ex.getMessage());
|
|
| 221 |
} |
|
| 78 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 79 |
// this will enable() all Fragment Effects twice (once for smooth variant, once for non-smooth) |
|
| 80 |
// but this shouldn't matter. |
|
| 81 |
/** |
|
| 82 |
* Enable all effects of a given type. |
|
| 83 |
* |
|
| 84 |
* @param type EffectType to enable. |
|
| 85 |
*/ |
|
| 86 |
@JvmStatic |
|
| 87 |
fun enableEffects(type: EffectType) |
|
| 88 |
{
|
|
| 89 |
var method: Method? |
|
| 90 |
|
|
| 91 |
for (name in EffectName.entries) |
|
| 92 |
{
|
|
| 93 |
if (name.type==type) |
|
| 94 |
{
|
|
| 95 |
val cls = name.effectClass |
|
| 96 |
|
|
| 97 |
try |
|
| 98 |
{
|
|
| 99 |
method = cls.getMethod("enable") // getMethod and NOT getDeclaredMethod because enable() is public
|
|
| 100 |
} |
|
| 101 |
catch (ex: NoSuchMethodException) |
|
| 102 |
{
|
|
| 103 |
DistortedLibrary.logMessage("Effect: exception getting method: "+ex.message)
|
|
| 104 |
method = null |
|
| 105 |
} |
|
| 106 |
|
|
| 107 |
try |
|
| 108 |
{
|
|
| 109 |
method?.invoke(null) |
|
| 110 |
} |
|
| 111 |
catch (ex: Exception) |
|
| 112 |
{
|
|
| 113 |
DistortedLibrary.logMessage("Effect: exception invoking method: "+ex.message)
|
|
| 114 |
} |
|
| 115 |
} |
|
| 116 |
} |
|
| 222 | 117 |
} |
| 223 |
} |
|
| 224 | 118 |
} |
| 225 | 119 |
|
| 226 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 227 |
/** |
|
| 228 |
* Return the EffectType enum corresponding to this Effect. |
|
| 229 |
* |
|
| 230 |
* @see EffectType |
|
| 231 |
*/ |
|
| 232 |
public EffectType getType() |
|
| 233 |
{
|
|
| 234 |
return mType; |
|
| 235 |
} |
|
| 120 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 121 |
abstract fun addQueue(queue: EffectQueue) |
|
| 122 |
abstract fun remQueue(queue: EffectQueue) |
|
| 123 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 124 |
init |
|
| 125 |
{
|
|
| 126 |
val n = name.ordinal |
|
| 127 |
val u = name.unity |
|
| 128 |
val l = u.size |
|
| 129 |
System.arraycopy(u, 0, mUnity, MAX_UNITY_DIM*n, l) |
|
| 130 |
mUnityDim[n] = l |
|
| 131 |
iD = (InternalStackFrameList.getNextEffectID() shl EffectType.LENGTH)+type.ordinal |
|
| 132 |
} |
|
| 133 |
|
|
| 134 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 135 |
/** |
|
| 136 |
* Only for use by the library itself. |
|
| 137 |
* |
|
| 138 |
* @y.exclude |
|
| 139 |
*/ |
|
| 140 |
abstract fun compute(uniforms: FloatArray, index: Int, currentDuration: Long, step: Long): Boolean |
|
| 141 |
|
|
| 142 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 143 |
/** |
|
| 144 |
* Only for use by the library itself. |
|
| 145 |
* |
|
| 146 |
* @y.exclude |
|
| 147 |
*/ |
|
| 148 |
fun removeFirstListener(): EffectListener? |
|
| 149 |
{
|
|
| 150 |
if (numListeners>0) |
|
| 151 |
{
|
|
| 152 |
numListeners-- |
|
| 153 |
return mListeners!!.removeAt(0) |
|
| 154 |
} |
|
| 236 | 155 |
|
| 237 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 238 |
/** |
|
| 239 |
* Return the EffectName enum corresponding to this Effect. |
|
| 240 |
* |
|
| 241 |
* @see EffectName |
|
| 242 |
*/ |
|
| 243 |
public EffectName getName() |
|
| 244 |
{
|
|
| 245 |
return mName; |
|
| 156 |
return null |
|
| 246 | 157 |
} |
| 247 | 158 |
|
| 248 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 249 |
/** |
|
| 250 |
* Return the unique ID of this Effect. |
|
| 251 |
*/ |
|
| 252 |
public long getID() |
|
| 253 |
{
|
|
| 254 |
return mID; |
|
| 255 |
} |
|
| 256 |
|
|
| 257 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 258 |
/** |
|
| 259 |
* Return a printable name of this Effect. |
|
| 260 |
*/ |
|
| 261 |
public String getString() |
|
| 159 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 160 |
/** |
|
| 161 |
* Only for use by the library itself. |
|
| 162 |
* |
|
| 163 |
* @y.exclude |
|
| 164 |
*/ |
|
| 165 |
fun writeAssociations(intUniforms: IntArray, index1: Int, index2: Int) |
|
| 262 | 166 |
{
|
| 263 |
return mName.name(); |
|
| 167 |
intUniforms[index1] = mAndAssociation |
|
| 168 |
intUniforms[index2] = mEquAssociation |
|
| 264 | 169 |
} |
| 265 | 170 |
|
| 266 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 267 |
/** |
|
| 268 |
* Return the dimension of the Center supported by this effect (0- no center supported at all). |
|
| 269 |
*/ |
|
| 270 |
public int getCenterDimension() |
|
| 171 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 172 |
// PUBLIC API |
|
| 173 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 174 |
/** |
|
| 175 |
* Do the set of Uniforms written in buffer[i+(0..dim)] represent a Unity, i.e a null Effect? |
|
| 176 |
*/ |
|
| 177 |
fun isUnity(buffer: FloatArray, i: Int): Boolean |
|
| 271 | 178 |
{
|
| 272 |
return mCenterDim;
|
|
| 273 |
}
|
|
| 179 |
val n = name.ordinal
|
|
| 180 |
val d = MAX_UNITY_DIM*n
|
|
| 274 | 181 |
|
| 275 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
| 276 |
/**
|
|
| 277 |
* Return the dimension of the Region supported by this effect (0- no region supported at all).
|
|
| 278 |
*/
|
|
| 279 |
public int getRegionDimension()
|
|
| 280 |
{
|
|
| 281 |
return mRegionDim;
|
|
| 282 |
} |
|
| 182 |
when (mUnityDim[n])
|
|
| 183 |
{
|
|
| 184 |
0 -> return true
|
|
| 185 |
1 -> return buffer[i]==mUnity[d]
|
|
| 186 |
2 -> return buffer[i]==mUnity[d] && buffer[i+1]==mUnity[d+1]
|
|
| 187 |
3 -> return buffer[i]==mUnity[d] && buffer[i+1]==mUnity[d+1] && buffer[i+2]==mUnity[d+2]
|
|
| 188 |
4 -> return buffer[i]==mUnity[d] && buffer[i+1]==mUnity[d+1] && buffer[i+2]==mUnity[d+2] && buffer[i+3]==mUnity[d+3]
|
|
| 189 |
}
|
|
| 283 | 190 |
|
| 284 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 285 |
/** |
|
| 286 |
* Return the number of Uniforms needed to describe this effect. |
|
| 287 |
*/ |
|
| 288 |
public int getEffectDimension() |
|
| 289 |
{
|
|
| 290 |
return mDimension; |
|
| 191 |
return false |
|
| 291 | 192 |
} |
| 292 | 193 |
|
| 293 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 294 |
/** |
|
| 295 |
* Adds the calling class to the list of Listeners that get notified when this Effect gets 'finished' |
|
| 296 |
* i.e. when the Dynamic inside this Effect reaches its final point and stops moving. This will be sent |
|
| 297 |
* only once, on the first time the Dynamic reaches its final point. |
|
| 298 |
* |
|
| 299 |
* If there's no Dynamic, ths message will never be sent. |
|
| 300 |
* |
|
| 301 |
* @param el A class implementing the EffectListener interface that wants to get notifications. |
|
| 302 |
*/ |
|
| 303 |
public void notifyWhenFinished(EffectListener el)
|
|
| 194 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
| 195 |
/**
|
|
| 196 |
* Adds the calling class to the list of Listeners that get notified when this Effect gets 'finished'
|
|
| 197 |
* i.e. when the Dynamic inside this Effect reaches its final point and stops moving. This will be sent
|
|
| 198 |
* only once, on the first time the Dynamic reaches its final point.
|
|
| 199 |
*
|
|
| 200 |
* If there's no Dynamic, ths message will never be sent.
|
|
| 201 |
*
|
|
| 202 |
* @param el A class implementing the EffectListener interface that wants to get notifications.
|
|
| 203 |
*/
|
|
| 204 |
fun notifyWhenFinished(el: EffectListener)
|
|
| 304 | 205 |
{
|
| 305 |
if( mListeners==null ) mListeners = new ArrayList<>();
|
|
| 206 |
if (mListeners==null) mListeners = ArrayList()
|
|
| 306 | 207 |
|
| 307 |
if( !mListeners.contains(el) )
|
|
| 308 |
{
|
|
| 309 |
mListeners.add(el);
|
|
| 310 |
mNumListeners++;
|
|
| 311 |
} |
|
| 208 |
if (!mListeners!!.contains(el))
|
|
| 209 |
{
|
|
| 210 |
mListeners!!.add(el)
|
|
| 211 |
numListeners++
|
|
| 212 |
}
|
|
| 312 | 213 |
} |
| 313 |
} |
|
| 214 |
} |
|
| src/main/java/org/distorted/library/effect/EffectName.kt | ||
|---|---|---|
| 18 | 18 |
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // |
| 19 | 19 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 20 | 20 |
|
| 21 |
package org.distorted.library.effect;
|
|
| 21 |
package org.distorted.library.effect |
|
| 22 | 22 |
|
| 23 | 23 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 24 | 24 |
/** |
| 25 | 25 |
* Names of Effects one can add to the DistortedEffects queues. |
| 26 |
* <p> |
|
| 27 |
* Effect's 'Type' is one of the constants defined in {@link EffectType}.
|
|
| 28 |
* </p> |
|
| 29 |
* <p> |
|
| 26 |
* |
|
| 27 |
* Effect's 'Type' is one of the constants defined in [EffectType]. |
|
| 28 |
* |
|
| 30 | 29 |
* Effect's 'Uniforms' are a vector of 7 (matrix effects) 12 (vertex) or 8 (fragment) floats, which |
| 31 | 30 |
* together form full information how to compute a given effect. |
| 32 | 31 |
* Typically, some of those values will be Interpolated in CPU (by one of the 'EffectQueueX.compute()' |
| 33 | 32 |
* methods) and the effect of such Interpolation sent to the Shaders. |
| 34 |
* </p> |
|
| 35 |
* <p> |
|
| 33 |
* |
|
| 36 | 34 |
* Effect's 'Unity' is such a particular vector of its 'interpolated values' which makes the |
| 37 | 35 |
* effect NULL. For example, if the effect is 'MOVE' by a 3-dimensional vector, then a 'NULL |
| 38 | 36 |
* MOVE' is a MOVE by vector (0,0,0), thus (0,0,0) is the unity of the MOVE effect. |
| 39 | 37 |
* This is used by the EffectQueue classes to decide if the final form of the Effect is NULL - and |
| 40 | 38 |
* thus if it can safely be removed from Effect Queues without affecting the visual in any way. |
| 41 |
* </p> |
|
| 42 | 39 |
*/ |
| 43 |
|
|
| 44 |
public enum EffectName |
|
| 45 |
{
|
|
| 46 |
// EFFECT NAME /////// EFFECT TYPE ////////// EFFECT UNITY //////////// DIM REGION CENTER // CLASS |
|
| 47 |
ROTATE ( EffectType.MATRIX , new float[] {0.0f} , 4, 0, 3 , MatrixEffectRotate.class ),
|
|
| 48 |
QUATERNION ( EffectType.MATRIX , new float[] {0.0f,0.0f,0.0f} , 4, 0, 3 , MatrixEffectQuaternion.class ),
|
|
| 49 |
MOVE ( EffectType.MATRIX , new float[] {0.0f,0.0f,0.0f} , 3, 0, 0 , MatrixEffectMove.class ),
|
|
| 50 |
SCALE ( EffectType.MATRIX , new float[] {1.0f,1.0f,1.0f} , 3, 0, 0 , MatrixEffectScale.class ),
|
|
| 51 |
SHEAR ( EffectType.MATRIX , new float[] {0.0f,0.0f,0.0f} , 3, 0, 3 , MatrixEffectShear.class ),
|
|
| 52 |
|
|
| 53 |
DISTORT ( EffectType.VERTEX , new float[] {0.0f,0.0f,0.0f} , 3, 4, 3 , VertexEffectDistort.class ),
|
|
| 54 |
DEFORM ( EffectType.VERTEX , new float[] {0.0f,0.0f,0.0f} , 4, 4, 3 , VertexEffectDeform.class ),
|
|
| 55 |
SINK ( EffectType.VERTEX , new float[] {1.0f} , 1, 4, 3 , VertexEffectSink.class ),
|
|
| 56 |
PINCH ( EffectType.VERTEX , new float[] {1.0f} , 3, 4, 3 , VertexEffectPinch.class ),
|
|
| 57 |
SWIRL ( EffectType.VERTEX , new float[] {0.0f} , 1, 4, 3 , VertexEffectSwirl.class ),
|
|
| 58 |
WAVE ( EffectType.VERTEX , new float[] {0.0f} , 5, 4, 3 , VertexEffectWave.class ),
|
|
| 59 |
DISAPPEAR ( EffectType.VERTEX , new float[] {} , 0, 0, 0 , VertexEffectDisappear.class ),
|
|
| 60 |
PIPE ( EffectType.VERTEX , new float[] {1,0f} , 5, 0, 3 , VertexEffectPipe.class ),
|
|
| 61 |
|
|
| 62 |
VERTEX_MOVE ( EffectType.VERTEX , new float[] {0.0f,0.0f,0.0f} , 3, 0, 0 , VertexEffectMove.class ),
|
|
| 63 |
VERTEX_QUATERNION( EffectType.VERTEX , new float[] {0.0f,0.0f,0.0f} , 4, 0, 3 , VertexEffectQuaternion.class ),
|
|
| 64 |
VERTEX_ROTATE ( EffectType.VERTEX , new float[] {0.0f} , 4, 0, 3 , VertexEffectRotate.class ),
|
|
| 65 |
VERTEX_SCALE ( EffectType.VERTEX , new float[] {1.0f,1.0f,1.0f} , 3, 0, 0 , VertexEffectScale.class ),
|
|
| 66 |
VERTEX_SHEAR ( EffectType.VERTEX , new float[] {0.0f,0.0f,0.0f} , 3, 0, 3 , VertexEffectShear.class ),
|
|
| 67 |
|
|
| 68 |
ALPHA ( EffectType.FRAGMENT, new float[] {1.0f} , 1, 3, 3 , FragmentEffectAlpha.class ),
|
|
| 69 |
SMOOTH_ALPHA ( EffectType.FRAGMENT, new float[] {1.0f} , 1, 3, 3 , FragmentEffectAlpha.class ),
|
|
| 70 |
CHROMA ( EffectType.FRAGMENT, new float[] {0.0f} , 4, 3, 3 , FragmentEffectChroma.class ),
|
|
| 71 |
SMOOTH_CHROMA ( EffectType.FRAGMENT, new float[] {0.0f} , 4, 3, 3 , FragmentEffectChroma.class ),
|
|
| 72 |
BRIGHTNESS ( EffectType.FRAGMENT, new float[] {1.0f} , 1, 3, 3 , FragmentEffectBrightness.class ),
|
|
| 73 |
SMOOTH_BRIGHTNESS( EffectType.FRAGMENT, new float[] {1.0f} , 1, 3, 3 , FragmentEffectBrightness.class ),
|
|
| 74 |
SATURATION ( EffectType.FRAGMENT, new float[] {1.0f} , 1, 3, 3 , FragmentEffectSaturation.class ),
|
|
| 75 |
SMOOTH_SATURATION( EffectType.FRAGMENT, new float[] {1.0f} , 1, 3, 3 , FragmentEffectSaturation.class ),
|
|
| 76 |
CONTRAST ( EffectType.FRAGMENT, new float[] {1.0f} , 1, 3, 3 , FragmentEffectContrast.class ),
|
|
| 77 |
SMOOTH_CONTRAST ( EffectType.FRAGMENT, new float[] {1.0f} , 1, 3, 3 , FragmentEffectContrast.class ),
|
|
| 78 |
|
|
| 79 |
BLUR ( EffectType.POSTPROCESS,new float[] {0.0f} , 2, 0, 0 , PostprocessEffectBlur.class ),
|
|
| 80 |
GLOW ( EffectType.POSTPROCESS,new float[] {0.0f} , 6, 0, 0 , PostprocessEffectGlow.class ),
|
|
| 81 |
BORDER ( EffectType.POSTPROCESS,new float[] {0.0f} , 5, 0, 0 , PostprocessEffectBorder.class ),
|
|
| 82 |
; |
|
| 83 |
|
|
| 84 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 85 |
|
|
| 86 |
public static final int LENGTH = values().length; |
|
| 87 |
|
|
| 88 |
private final EffectType type; |
|
| 89 |
private final float[] unity; |
|
| 90 |
private final int dimension; |
|
| 91 |
private final int regionDim; |
|
| 92 |
private final int centerDim; |
|
| 93 |
private final Class<? extends Effect> effectClass; |
|
| 94 |
|
|
| 95 |
private static final int[] dimensions; |
|
| 96 |
private static final int[] regionDimension; |
|
| 97 |
private static final int[] centerDimension; |
|
| 98 |
private static final EffectName[] names; // copy the values() to a local variable so that we |
|
| 99 |
// don't have to keep recreating the array every time |
|
| 100 |
static |
|
| 40 |
enum class EffectName( type: EffectType, unity: FloatArray, dim: Int, regionDim: Int, centerDim: Int, effectClass: Class<out Effect?>) |
|
| 41 |
{
|
|
| 42 |
// EFFECT NAME /////// EFFECT TYPE ////////// EFFECT UNITY //////////// DIM REGION CENTER // CLASS |
|
| 43 |
ROTATE (EffectType.MATRIX, floatArrayOf(0.0f), 4, 0, 3, MatrixEffectRotate::class.java), |
|
| 44 |
QUATERNION (EffectType.MATRIX, floatArrayOf(0.0f, 0.0f, 0.0f), 4, 0, 3, MatrixEffectQuaternion::class.java), |
|
| 45 |
MOVE (EffectType.MATRIX, floatArrayOf(0.0f, 0.0f, 0.0f), 3, 0, 0, MatrixEffectMove::class.java), |
|
| 46 |
SCALE (EffectType.MATRIX, floatArrayOf(1.0f, 1.0f, 1.0f), 3, 0, 0, MatrixEffectScale::class.java), |
|
| 47 |
SHEAR (EffectType.MATRIX, floatArrayOf(0.0f, 0.0f, 0.0f), 3, 0, 3, MatrixEffectShear::class.java), |
|
| 48 |
|
|
| 49 |
DISTORT (EffectType.VERTEX, floatArrayOf(0.0f, 0.0f, 0.0f), 3, 4, 3, VertexEffectDistort::class.java), |
|
| 50 |
DEFORM (EffectType.VERTEX, floatArrayOf(0.0f, 0.0f, 0.0f), 4, 4, 3, VertexEffectDeform::class.java), |
|
| 51 |
SINK (EffectType.VERTEX, floatArrayOf(1.0f), 1, 4, 3, VertexEffectSink::class.java), |
|
| 52 |
PINCH (EffectType.VERTEX, floatArrayOf(1.0f), 3, 4, 3, VertexEffectPinch::class.java), |
|
| 53 |
SWIRL (EffectType.VERTEX, floatArrayOf(0.0f), 1, 4, 3, VertexEffectSwirl::class.java), |
|
| 54 |
WAVE (EffectType.VERTEX, floatArrayOf(0.0f), 5, 4, 3, VertexEffectWave::class.java), |
|
| 55 |
DISAPPEAR (EffectType.VERTEX, floatArrayOf(), 0, 0, 0, VertexEffectDisappear::class.java), |
|
| 56 |
PIPE (EffectType.VERTEX, floatArrayOf(1f, 0f), 5, 0, 3, VertexEffectPipe::class.java), |
|
| 57 |
|
|
| 58 |
VERTEX_MOVE (EffectType.VERTEX, floatArrayOf(0.0f, 0.0f, 0.0f), 3, 0, 0, VertexEffectMove::class.java), |
|
| 59 |
VERTEX_QUATERNION(EffectType.VERTEX, floatArrayOf(0.0f, 0.0f, 0.0f), 4, 0, 3, VertexEffectQuaternion::class.java), |
|
| 60 |
VERTEX_ROTATE (EffectType.VERTEX, floatArrayOf(0.0f), 4, 0, 3, VertexEffectRotate::class.java), |
|
| 61 |
VERTEX_SCALE (EffectType.VERTEX, floatArrayOf(1.0f, 1.0f, 1.0f), 3, 0, 0, VertexEffectScale::class.java), |
|
| 62 |
VERTEX_SHEAR (EffectType.VERTEX, floatArrayOf(0.0f, 0.0f, 0.0f), 3, 0, 3, VertexEffectShear::class.java), |
|
| 63 |
|
|
| 64 |
ALPHA (EffectType.FRAGMENT, floatArrayOf(1.0f), 1, 3, 3, FragmentEffectAlpha::class.java), |
|
| 65 |
SMOOTH_ALPHA (EffectType.FRAGMENT, floatArrayOf(1.0f), 1, 3, 3, FragmentEffectAlpha::class.java), |
|
| 66 |
CHROMA (EffectType.FRAGMENT, floatArrayOf(0.0f), 4, 3, 3, FragmentEffectChroma::class.java), |
|
| 67 |
SMOOTH_CHROMA (EffectType.FRAGMENT, floatArrayOf(0.0f), 4, 3, 3, FragmentEffectChroma::class.java), |
|
| 68 |
BRIGHTNESS (EffectType.FRAGMENT, floatArrayOf(1.0f), 1, 3, 3, FragmentEffectBrightness::class.java), |
|
| 69 |
SMOOTH_BRIGHTNESS(EffectType.FRAGMENT, floatArrayOf(1.0f), 1, 3, 3, FragmentEffectBrightness::class.java), |
|
| 70 |
SATURATION (EffectType.FRAGMENT, floatArrayOf(1.0f), 1, 3, 3, FragmentEffectSaturation::class.java), |
|
| 71 |
SMOOTH_SATURATION(EffectType.FRAGMENT, floatArrayOf(1.0f), 1, 3, 3, FragmentEffectSaturation::class.java), |
|
| 72 |
CONTRAST (EffectType.FRAGMENT, floatArrayOf(1.0f), 1, 3, 3, FragmentEffectContrast::class.java), |
|
| 73 |
SMOOTH_CONTRAST (EffectType.FRAGMENT, floatArrayOf(1.0f), 1, 3, 3, FragmentEffectContrast::class.java), |
|
| 74 |
|
|
| 75 |
BLUR (EffectType.POSTPROCESS, floatArrayOf(0.0f), 2, 0, 0, PostprocessEffectBlur::class.java), |
|
| 76 |
GLOW (EffectType.POSTPROCESS, floatArrayOf(0.0f), 6, 0, 0, PostprocessEffectGlow::class.java), |
|
| 77 |
BORDER (EffectType.POSTPROCESS, floatArrayOf(0.0f), 5, 0, 0, PostprocessEffectBorder::class.java), |
|
| 78 |
; |
|
| 79 |
/////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 80 |
|
|
| 81 |
val type: EffectType |
|
| 82 |
val unity: FloatArray |
|
| 83 |
private val dimension: Int |
|
| 84 |
private val regionDim: Int |
|
| 85 |
private val centerDim: Int |
|
| 86 |
val effectClass: Class<out Effect?> |
|
| 87 |
|
|
| 88 |
val effectDimension: Int get() = dimensions[ordinal] |
|
| 89 |
val regionDimension: Int get() = Companion.regionDimension[ordinal] |
|
| 90 |
val centerDimension: Int get() = Companion.centerDimension[ordinal] |
|
| 91 |
|
|
| 92 |
companion object |
|
| 101 | 93 |
{
|
| 102 |
int i=0; |
|
| 103 |
|
|
| 104 |
dimensions = new int[LENGTH]; |
|
| 105 |
regionDimension = new int[LENGTH]; |
|
| 106 |
centerDimension = new int[LENGTH]; |
|
| 107 |
names = new EffectName[LENGTH]; |
|
| 108 |
|
|
| 109 |
for(EffectName name: EffectName.values()) |
|
| 110 |
{
|
|
| 111 |
dimensions[i] = name.dimension; |
|
| 112 |
regionDimension[i] = name.regionDim; |
|
| 113 |
centerDimension[i] = name.centerDim; |
|
| 114 |
names[i] = name; |
|
| 115 |
|
|
| 116 |
i++; |
|
| 117 |
} |
|
| 94 |
val LENGTH: Int = entries.size |
|
| 95 |
private val dimensions: IntArray |
|
| 96 |
private val regionDimension: IntArray |
|
| 97 |
private val centerDimension: IntArray |
|
| 98 |
private val names: Array<EffectName?> // copy the values() to a local variable so that we |
|
| 99 |
// don't have to keep recreating the array every time |
|
| 100 |
init |
|
| 101 |
{
|
|
| 102 |
dimensions = IntArray(LENGTH) |
|
| 103 |
regionDimension = IntArray(LENGTH) |
|
| 104 |
centerDimension = IntArray(LENGTH) |
|
| 105 |
names = arrayOfNulls(LENGTH) |
|
| 106 |
|
|
| 107 |
for ( (i,name) in entries.withIndex() ) |
|
| 108 |
{
|
|
| 109 |
dimensions[i] = name.dimension |
|
| 110 |
regionDimension[i] = name.regionDim |
|
| 111 |
centerDimension[i] = name.centerDim |
|
| 112 |
names[i] = name |
|
| 113 |
} |
|
| 114 |
} |
|
| 118 | 115 |
} |
| 119 |
|
|
| 120 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 121 |
|
|
| 122 |
float[] getUnity() |
|
| 123 |
{
|
|
| 124 |
return unity; |
|
| 125 |
} |
|
| 126 |
|
|
| 127 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 128 |
|
|
| 129 |
EffectName(EffectType type, float[] unity, int dimension, int regionDim, |
|
| 130 |
int centerDim, Class<? extends Effect> effectClass ) |
|
| 116 |
/////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 117 |
init |
|
| 131 | 118 |
{
|
| 132 |
this.type = type;
|
|
| 133 |
this.unity = unity;
|
|
| 134 |
this.dimension = dimension;
|
|
| 135 |
this.regionDim = regionDim;
|
|
| 136 |
this.centerDim = centerDim;
|
|
| 137 |
this.effectClass = effectClass;
|
|
| 119 |
this.type = type
|
|
| 120 |
this.unity = unity
|
|
| 121 |
this.dimension = dim
|
|
| 122 |
this.regionDim = regionDim
|
|
| 123 |
this.centerDim = centerDim
|
|
| 124 |
this.effectClass = effectClass
|
|
| 138 | 125 |
} |
| 139 |
|
|
| 140 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 141 |
// PUBLIC API |
|
| 142 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 143 |
/** |
|
| 144 |
* Returns the Type of an individual Effect. For example, EffectName.ROTATE.getType() will |
|
| 145 |
* return EffectType.MATRIX. |
|
| 146 |
* @return type of the effect. |
|
| 147 |
*/ |
|
| 148 |
public EffectType getType() |
|
| 149 |
{
|
|
| 150 |
return type; |
|
| 151 |
} |
|
| 152 |
|
|
| 153 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 154 |
/** |
|
| 155 |
* Returns the Class of an individual Effect. For example, EffectName.ROTATE.getEffectClass() |
|
| 156 |
* returns MatrixEffectRotate.class. |
|
| 157 |
* @return effect class. |
|
| 158 |
*/ |
|
| 159 |
public Class<? extends Effect> getEffectClass() |
|
| 160 |
{
|
|
| 161 |
return effectClass; |
|
| 162 |
} |
|
| 163 |
|
|
| 164 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 165 |
/** |
|
| 166 |
* Returns the i-th EffectName. |
|
| 167 |
* <p> |
|
| 168 |
* If you want to loop over all possible Effects, you need this. |
|
| 169 |
*/ |
|
| 170 |
public static EffectName getName(int ordinal) |
|
| 171 |
{
|
|
| 172 |
return names[ordinal]; |
|
| 173 |
} |
|
| 174 |
|
|
| 175 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 176 |
/** |
|
| 177 |
* Returns the dimension of an Effect (in other words, the number of interpolated values). |
|
| 178 |
* @return dimension of the Effect. |
|
| 179 |
*/ |
|
| 180 |
public int getEffectDimension() { return dimensions[ordinal()]; }
|
|
| 181 |
|
|
| 182 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 183 |
/** |
|
| 184 |
* What is the dimension of the Region supported by this effect? |
|
| 185 |
* @return Dimension of the Region supported (0-region not supported at all). |
|
| 186 |
*/ |
|
| 187 |
public int getRegionDimension() { return regionDimension[ordinal()]; }
|
|
| 188 |
|
|
| 189 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 190 |
/** |
|
| 191 |
* What is the dimension of the Center supported by this effect? |
|
| 192 |
* @return Dimension of the Center supported (0-center not supported at all). |
|
| 193 |
*/ |
|
| 194 |
public int getCenterDimension() { return centerDimension[ordinal()]; }
|
|
| 195 |
} |
|
| 196 |
|
|
| 126 |
/////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 127 |
fun getName(ordinal: Int): EffectName? = names[ordinal] |
|
| 128 |
} |
|
| src/main/java/org/distorted/library/effect/EffectQuality.kt | ||
|---|---|---|
| 18 | 18 |
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // |
| 19 | 19 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 20 | 20 |
|
| 21 |
package org.distorted.library.effect;
|
|
| 21 |
package org.distorted.library.effect |
|
| 22 | 22 |
|
| 23 | 23 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 24 |
|
|
| 25 |
import org.distorted.library.main.DistortedEffects; |
|
| 26 |
|
|
| 27 | 24 |
/** |
| 28 | 25 |
* A list of quality levels. |
| 29 |
* <p>
|
|
| 26 |
* |
|
| 30 | 27 |
* One can set quality of a Postprocessing Effect to one of those. The lower the quality, the faster |
| 31 | 28 |
* the rendering will be. |
| 32 | 29 |
* |
| 33 | 30 |
* @see DistortedEffects |
| 34 | 31 |
*/ |
| 35 |
public enum EffectQuality |
|
| 36 |
{
|
|
| 37 |
HIGHEST ( 0, 1.000f ), // has to start from 0 |
|
| 38 |
HIGH ( 1, 0.500f ), |
|
| 39 |
MEDIUM ( 2, 0.250f ), |
|
| 40 |
LOW ( 3, 0.125f ); |
|
| 41 |
|
|
| 42 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 43 |
/** |
|
| 44 |
* Numof of possible qualities. |
|
| 45 |
*/ |
|
| 46 |
public static final int LENGTH = values().length; |
|
| 47 |
|
|
| 48 |
private final int level; |
|
| 49 |
private final float mipmap; |
|
| 50 |
|
|
| 51 |
private static final EffectQuality[] qualities; |
|
| 52 |
|
|
| 53 |
static |
|
| 32 |
enum class EffectQuality(val level: Int, private val mipmap: Float) |
|
| 33 |
{
|
|
| 34 |
HIGHEST(0, 1.000f), // has to start from 0 |
|
| 35 |
HIGH (1, 0.500f), |
|
| 36 |
MEDIUM (2, 0.250f), |
|
| 37 |
LOW (3, 0.125f); |
|
| 38 |
|
|
| 39 |
companion object |
|
| 54 | 40 |
{
|
| 55 |
int i=0; |
|
| 56 |
qualities= new EffectQuality[LENGTH]; |
|
| 57 |
for(EffectQuality q: EffectQuality.values()) qualities[i++] = q; |
|
| 58 |
} |
|
| 41 |
@JvmField val LENGTH: Int = entries.size |
|
| 42 |
private val qualities: Array<EffectQuality?> |
|
| 59 | 43 |
|
| 60 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 44 |
init |
|
| 45 |
{
|
|
| 46 |
var i=0 |
|
| 47 |
qualities = arrayOfNulls(LENGTH) |
|
| 48 |
for (q in entries) qualities[i++] = q |
|
| 49 |
} |
|
| 61 | 50 |
|
| 62 |
EffectQuality(int level, float mipmap) |
|
| 63 |
{
|
|
| 64 |
this.level = level; |
|
| 65 |
this.mipmap= mipmap; |
|
| 66 |
} |
|
| 67 |
|
|
| 68 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 69 |
/** |
|
| 70 |
* Only for use by the library itself. |
|
| 71 |
* |
|
| 72 |
* @y.exclude |
|
| 73 |
*/ |
|
| 74 |
public int getLevel() |
|
| 75 |
{
|
|
| 76 |
return level; |
|
| 77 |
} |
|
| 78 |
|
|
| 79 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 80 |
/** |
|
| 81 |
* Only for use by the library itself. |
|
| 82 |
* |
|
| 83 |
* @y.exclude |
|
| 84 |
*/ |
|
| 85 |
public static float getMipmap(int quality) |
|
| 86 |
{
|
|
| 87 |
return qualities[quality].mipmap; |
|
| 51 |
@JvmStatic fun getMipmap(quality: Int): Float = qualities[quality]!!.mipmap |
|
| 88 | 52 |
} |
| 89 |
}
|
|
| 53 |
} |
|
| 90 | 54 |
|
| src/main/java/org/distorted/library/effect/EffectType.kt | ||
|---|---|---|
| 18 | 18 |
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // |
| 19 | 19 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 20 | 20 |
|
| 21 |
package org.distorted.library.effect;
|
|
| 21 |
package org.distorted.library.effect |
|
| 22 | 22 |
|
| 23 | 23 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 24 |
|
|
| 25 | 24 |
/** |
| 26 | 25 |
* Types of Effects one can add to the DistortedEffects queues. |
| 27 |
* <p>
|
|
| 26 |
* |
|
| 28 | 27 |
* Each effect type goes to an independent queue; the queues get executed one-by-one |
| 29 | 28 |
* and are each a class descendant from EffectQueue. |
| 30 | 29 |
*/ |
| 31 |
|
|
| 32 |
public enum EffectType |
|
| 33 |
{
|
|
| 34 |
/** |
|
| 35 |
* Effects that change the ModelView matrix: Rotations, Moves, Shears, Scales. |
|
| 36 |
*/ |
|
| 37 |
MATRIX, |
|
| 38 |
/** |
|
| 39 |
* Effects that get executed in the Vertex shader: various distortions of the vertices. |
|
| 40 |
*/ |
|
| 41 |
VERTEX, |
|
| 42 |
/** |
|
| 43 |
* Effects executed in the Fragment shader: changes of color, hue, transparency levels, etc. |
|
| 44 |
*/ |
|
| 45 |
FRAGMENT, |
|
| 46 |
/** |
|
| 47 |
* Postprocessing effects done to the texture the first stage fragment shader created |
|
| 48 |
*/ |
|
| 49 |
POSTPROCESS; |
|
| 50 |
|
|
| 51 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 52 |
/** |
|
| 53 |
* Number of effect types. |
|
| 54 |
* Only for use by the library itself. |
|
| 55 |
* |
|
| 56 |
* @y.exclude |
|
| 57 |
*/ |
|
| 58 |
public static final int LENGTH = values().length; |
|
| 59 |
/** |
|
| 60 |
* Needed when we do bitwise operations on Effect Types. |
|
| 61 |
* Only for use by the library itself. |
|
| 62 |
* |
|
| 63 |
* @y.exclude |
|
| 64 |
*/ |
|
| 65 |
public static final int MASK= (1<<LENGTH)-1; |
|
| 66 |
|
|
| 67 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 68 |
/** |
|
| 69 |
* Only for use by the library itself. |
|
| 70 |
* |
|
| 71 |
* @y.exclude |
|
| 72 |
*/ |
|
| 73 |
public static void reset(int[] maxtable) |
|
| 30 |
enum class EffectType |
|
| 31 |
{
|
|
| 32 |
MATRIX, // Effects that change the ModelView matrix: Rotations, Moves, Shears, Scales. |
|
| 33 |
VERTEX, // Effects that get executed in the Vertex shader: various distortions of the vertices. |
|
| 34 |
FRAGMENT, // Effects executed in the Fragment shader: changes of color, hue, transparency levels, etc. |
|
| 35 |
POSTPROCESS; // Postprocessing effects done to the texture the first stage fragment shader created |
|
| 36 |
|
|
| 37 |
companion object |
|
| 74 | 38 |
{
|
| 75 |
maxtable[0] =100; // By default, there can be a maximum 100 MATRIX effects in a single |
|
| 76 |
// EffectQueueMatrix at any given time. This can be changed with a call |
|
| 77 |
// to EffectQueueMatrix.setMax(int) |
|
| 78 |
maxtable[1] = 30; // Max 30 VERTEX Effects |
|
| 79 |
maxtable[2] = 5; // Max 5 FRAGMENT Effects |
|
| 80 |
maxtable[3] = 3; // Max 3 POSTPROCESSING Effects |
|
| 39 |
@JvmField val LENGTH: Int = entries.size |
|
| 40 |
@JvmField val MASK: Int = (1 shl LENGTH)-1 |
|
| 41 |
@JvmStatic fun reset(maxtable: IntArray) |
|
| 42 |
{
|
|
| 43 |
maxtable[0] = 100 // By default, there can be a maximum 100 MATRIX effects in a single |
|
| 44 |
// EffectQueueMatrix at any given time. This can be changed with a call |
|
| 45 |
// to EffectQueueMatrix.setMax(int) |
|
| 46 |
maxtable[1] = 30 // Max 30 VERTEX Effects |
|
| 47 |
maxtable[2] = 5 // Max 5 FRAGMENT Effects |
|
| 48 |
maxtable[3] = 3 // Max 3 POSTPROCESSING Effects |
|
| 49 |
} |
|
| 50 |
|
|
| 51 |
fun getType(ordinal: Int): EffectType = entries[ordinal] |
|
| 81 | 52 |
} |
| 82 |
|
|
| 83 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 84 |
/** |
|
| 85 |
* Returns the i-th EffectType. |
|
| 86 |
* <p> |
|
| 87 |
* If you want to loop over all possible effect types, you need this. |
|
| 88 |
*/ |
|
| 89 |
public static EffectType getType(int ordinal) |
|
| 90 |
{
|
|
| 91 |
return values()[ordinal]; |
|
| 92 |
} |
|
| 93 |
|
|
| 94 |
} |
|
| 53 |
} |
|
| src/main/java/org/distorted/library/effect/FragmentEffect.kt | ||
|---|---|---|
| 18 | 18 |
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // |
| 19 | 19 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 20 | 20 |
|
| 21 |
package org.distorted.library.effect;
|
|
| 21 |
package org.distorted.library.effect |
|
| 22 | 22 |
|
| 23 |
import org.distorted.library.effectqueue.EffectQueue;
|
|
| 24 |
import org.distorted.library.type.Static3D;
|
|
| 23 |
import org.distorted.library.effectqueue.EffectQueue |
|
| 24 |
import org.distorted.library.type.Static3D |
|
| 25 | 25 |
|
| 26 | 26 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 27 | 27 |
/** |
| 28 | 28 |
* Abstract class that represents an Effect that works by injecting certain code into the main Fragment shader. |
| 29 | 29 |
*/ |
| 30 |
public abstract class FragmentEffect extends Effect |
|
| 31 |
{
|
|
| 32 |
/** |
|
| 33 |
* 12: 4-per effect interpolated values, 3 dimensional Center (+padding), 3 dimensional Region (+padding). |
|
| 34 |
*/ |
|
| 35 |
public static final int NUM_FLOAT_UNIFORMS = 12; |
|
| 36 |
/** |
|
| 37 |
* 4: the name, unused, unused, unused |
|
| 38 |
*/ |
|
| 39 |
public static final int NUM_INT_UNIFORMS = 4; |
|
| 30 |
abstract class FragmentEffect internal constructor(name: EffectName) : Effect(name) |
|
| 31 |
{
|
|
| 32 |
override fun addQueue(queue: EffectQueue) { /* NO OP */ }
|
|
| 33 |
override fun remQueue(queue: EffectQueue) { /* NO OP */ }
|
|
| 40 | 34 |
|
| 41 |
static final int CENTER_OFFSET = 5; |
|
| 42 |
static final int REGION_OFFSET = 8; |
|
| 43 |
private static String mGLSL = ""; |
|
| 44 |
private static int mNumEnabled = 0; |
|
| 45 |
|
|
| 46 |
final static Static3D MAX_REGION = new Static3D(1000000,1000000,1000000); |
|
| 47 |
|
|
| 48 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 49 |
|
|
| 50 |
FragmentEffect(EffectName name) |
|
| 51 |
{
|
|
| 52 |
super(name); |
|
| 53 |
} |
|
| 54 |
|
|
| 55 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 56 |
// prepare code to be injected into the 'main_fragment_shader' main() function. |
|
| 57 |
|
|
| 58 |
static void addEffect(EffectName not_smooth, EffectName yes_smooth, String code) |
|
| 59 |
{
|
|
| 60 |
int effect1 = not_smooth.ordinal(); |
|
| 61 |
int effect2 = yes_smooth.ordinal(); |
|
| 62 |
|
|
| 63 |
if( mEnabled[effect1] ) return; |
|
| 64 |
|
|
| 65 |
mEnabled[effect1] = true; |
|
| 66 |
mNumEnabled ++; |
|
| 67 |
|
|
| 68 |
mGLSL += |
|
| 69 |
|
|
| 70 |
"if( fProperties[i].x =="+effect1+")\n" |
|
| 71 |
+ "{\n"
|
|
| 72 |
+ "degree = sign(degree); \n" |
|
| 73 |
+ code +"\n" |
|
| 74 |
+ "}\n" |
|
| 75 |
+"else\n" |
|
| 76 |
+"if( fProperties[i].x =="+effect2+")\n" |
|
| 77 |
+ "{\n"
|
|
| 78 |
+ code +"\n" |
|
| 79 |
+ "}\n" |
|
| 80 |
+"else\n"; |
|
| 81 |
} |
|
| 82 |
|
|
| 83 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 84 |
/** |
|
| 85 |
* Only for use by the library itself. |
|
| 86 |
* |
|
| 87 |
* @y.exclude |
|
| 88 |
*/ |
|
| 89 |
public static String getGLSL() |
|
| 90 |
{
|
|
| 91 |
return mGLSL + "{}";
|
|
| 92 |
} |
|
| 93 |
|
|
| 94 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 95 |
|
|
| 96 |
static void destroyStatics() |
|
| 97 |
{
|
|
| 98 |
mNumEnabled = 0; |
|
| 99 |
mGLSL = ""; |
|
| 100 |
} |
|
| 101 |
|
|
| 102 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 103 |
/** |
|
| 104 |
* Only for use by the library itself. |
|
| 105 |
* |
|
| 106 |
* @y.exclude |
|
| 107 |
*/ |
|
| 108 |
public void addQueue(EffectQueue queue) |
|
| 109 |
{
|
|
| 110 |
// NO OP |
|
| 111 |
} |
|
| 112 |
|
|
| 113 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 114 |
/** |
|
| 115 |
* Only for use by the library itself. |
|
| 116 |
* |
|
| 117 |
* @y.exclude |
|
| 118 |
*/ |
|
| 119 |
public void remQueue(EffectQueue queue) |
|
| 120 |
{
|
|
| 121 |
// NO OP |
|
| 122 |
} |
|
| 123 |
|
|
| 124 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 125 |
// PUBLIC API |
|
| 126 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 127 |
/** |
|
| 128 |
* Return the number of Fragment effects enabled. |
|
| 129 |
*/ |
|
| 130 |
public static int getNumEnabled() |
|
| 35 |
companion object |
|
| 131 | 36 |
{
|
| 132 |
return mNumEnabled; |
|
| 37 |
const val NUM_FLOAT_UNIFORMS: Int = 12 // 4-per effect interpolated values, 3 dimensional Center (+padding), 3 dimensional Region (+padding). |
|
| 38 |
const val NUM_INT_UNIFORMS : Int = 4 // the name, unused, unused, unused |
|
| 39 |
const val CENTER_OFFSET: Int = 5 |
|
| 40 |
const val REGION_OFFSET: Int = 8 |
|
| 41 |
private var mGLSL = "" |
|
| 42 |
private var numEnabled: Int = 0 // number of Fragment effects enabled. |
|
| 43 |
val MAX_REGION: Static3D = Static3D(1000000f, 1000000f, 1000000f) |
|
| 44 |
@JvmStatic val gLSL: String get() = mGLSL+"{}"
|
|
| 45 |
|
|
| 46 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 47 |
// prepare code to be injected into the 'main_fragment_shader' main() function. |
|
| 48 |
fun addEffect(notSmooth: EffectName, yesSmooth: EffectName, code: String) |
|
| 49 |
{
|
|
| 50 |
val effect1 = notSmooth.ordinal |
|
| 51 |
val effect2 = yesSmooth.ordinal |
|
| 52 |
|
|
| 53 |
if (mEnabled[effect1]) return |
|
| 54 |
|
|
| 55 |
mEnabled[effect1] = true |
|
| 56 |
numEnabled++ |
|
| 57 |
|
|
| 58 |
mGLSL += |
|
| 59 |
("""
|
|
| 60 |
if( fProperties[i].x ==$effect1) |
|
| 61 |
{
|
|
| 62 |
degree = sign(degree); |
|
| 63 |
$code |
|
| 64 |
} |
|
| 65 |
else |
|
| 66 |
if( fProperties[i].x ==$effect2) |
|
| 67 |
{
|
|
| 68 |
$code |
|
| 69 |
} |
|
| 70 |
else |
|
| 71 |
|
|
| 72 |
""".trimIndent()) |
|
| 73 |
} |
|
| 74 |
|
|
| 75 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 76 |
fun destroyStatics() |
|
| 77 |
{
|
|
| 78 |
numEnabled = 0 |
|
| 79 |
mGLSL = "" |
|
| 80 |
} |
|
| 133 | 81 |
} |
| 134 |
} |
|
| 82 |
} |
|
| src/main/java/org/distorted/library/effect/FragmentEffectAlpha.kt | ||
|---|---|---|
| 18 | 18 |
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // |
| 19 | 19 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 20 | 20 |
|
| 21 |
package org.distorted.library.effect;
|
|
| 21 |
package org.distorted.library.effect |
|
| 22 | 22 |
|
| 23 |
import org.distorted.library.type.Data1D;
|
|
| 24 |
import org.distorted.library.type.Data3D;
|
|
| 25 |
import org.distorted.library.type.Static3D;
|
|
| 23 |
import org.distorted.library.type.Data1D |
|
| 24 |
import org.distorted.library.type.Data3D |
|
| 25 |
import org.distorted.library.type.Static3D |
|
| 26 | 26 |
|
| 27 | 27 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 28 | 28 |
/** |
| 29 | 29 |
* Make a certain Region change its transparency level. |
| 30 | 30 |
*/ |
| 31 |
public class FragmentEffectAlpha extends FragmentEffect
|
|
| 32 |
{
|
|
| 33 |
private final Data1D mAlpha;
|
|
| 34 |
private final Data3D mCenter;
|
|
| 35 |
private final Data3D mRegion;
|
|
| 31 |
class FragmentEffectAlpha : FragmentEffect
|
|
| 32 |
{
|
|
| 33 |
private val mAlpha: Data1D
|
|
| 34 |
private val mCenter: Data3D
|
|
| 35 |
private val mRegion: Data3D
|
|
| 36 | 36 |
|
| 37 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 38 |
/** |
|
| 39 |
* Only for use by the library itself. |
|
| 40 |
* |
|
| 41 |
* @y.exclude |
|
| 42 |
*/ |
|
| 43 |
public boolean compute(float[] uniforms, int index, long currentDuration, long step ) |
|
| 37 |
companion object |
|
| 44 | 38 |
{
|
| 45 |
mCenter.get(uniforms, index+CENTER_OFFSET, currentDuration, step); |
|
| 46 |
mRegion.get(uniforms, index+REGION_OFFSET, currentDuration, step); |
|
| 47 |
return mAlpha.get(uniforms,index, currentDuration, step); |
|
| 39 |
/** |
|
| 40 |
* Have to call this before the shaders get compiled (i.e before DistortedLibrary.onCreate()) for the Effect to work. |
|
| 41 |
*/ |
|
| 42 |
@JvmStatic |
|
| 43 |
fun enable() |
|
| 44 |
{
|
|
| 45 |
addEffect(EffectName.ALPHA, EffectName.SMOOTH_ALPHA, |
|
| 46 |
"color.a *= (degree*(fUniforms[effect].x-1.0)+1.0);") |
|
| 47 |
} |
|
| 48 | 48 |
} |
| 49 |
|
|
| 50 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 51 |
// PUBLIC API |
|
| 52 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 53 |
/** |
|
| 54 |
* Makes a certain sub-region of the Object smoothly change its transparency level. |
|
| 55 |
* |
|
| 56 |
* @param alpha level of transparency we want to have at any given moment: pixel.a *= alpha. |
|
| 57 |
* Valid range: <0,1> |
|
| 58 |
* @param center center of the Effect (point in 3D). |
|
| 59 |
* @param region Region this Effect is limited to (3 radii defining an ellipsoid). |
|
| 60 |
* @param smooth If true, the level of 'alpha' will smoothly fade out towards the edges of the region. |
|
| 61 |
*/ |
|
| 62 |
public FragmentEffectAlpha(Data1D alpha, Data3D center, Data3D region, boolean smooth) |
|
| 49 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 50 |
/** |
|
| 51 |
* Only for use by the library itself. |
|
| 52 |
* |
|
| 53 |
* @y.exclude |
|
| 54 |
*/ |
|
| 55 |
override fun compute(uniforms: FloatArray, index: Int, currentDuration: Long, step: Long): Boolean |
|
| 63 | 56 |
{
|
| 64 |
super(smooth? EffectName.SMOOTH_ALPHA:EffectName.ALPHA); |
|
| 65 |
mAlpha = alpha; |
|
| 66 |
mCenter = center; |
|
| 67 |
mRegion = (region==null ? MAX_REGION : region); |
|
| 57 |
mCenter.get(uniforms, index+CENTER_OFFSET, currentDuration, step) |
|
| 58 |
mRegion.get(uniforms, index+REGION_OFFSET, currentDuration, step) |
|
| 59 |
return mAlpha.get(uniforms, index, currentDuration, step) |
|
| 68 | 60 |
} |
| 69 | 61 |
|
| 70 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 71 |
/** |
|
| 72 |
* Makes the whole Object smoothly change its transparency level. |
|
| 73 |
* |
|
| 74 |
* @param alpha level of transparency we want to have at any given moment: pixel.a *= alpha. |
|
| 75 |
* Valid range: <0,1> |
|
| 76 |
*/ |
|
| 77 |
public FragmentEffectAlpha(Data1D alpha) |
|
| 62 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 63 |
// PUBLIC API |
|
| 64 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 65 |
/** |
|
| 66 |
* Makes a certain sub-region of the Object smoothly change its transparency level. |
|
| 67 |
* |
|
| 68 |
* @param alpha level of transparency we want to have at any given moment: pixel.a *= alpha. |
|
| 69 |
* Valid range: <0,1> |
|
| 70 |
* @param center center of the Effect (point in 3D). |
|
| 71 |
* @param region Region this Effect is limited to (3 radii defining an ellipsoid). |
|
| 72 |
* @param smooth If true, the level of 'alpha' will smoothly fade out towards the edges of the region. |
|
| 73 |
*/ |
|
| 74 |
constructor(alpha: Data1D, center: Data3D, region: Data3D?, smooth: Boolean) : super(if (smooth) EffectName.SMOOTH_ALPHA else EffectName.ALPHA) |
|
| 78 | 75 |
{
|
| 79 |
super(EffectName.ALPHA); |
|
| 80 |
mAlpha = alpha; |
|
| 81 |
mCenter = new Static3D(0,0,0); |
|
| 82 |
mRegion = MAX_REGION; |
|
| 76 |
mAlpha = alpha |
|
| 77 |
mCenter = center |
|
| 78 |
mRegion = (region ?: MAX_REGION) |
|
| 83 | 79 |
} |
| 84 | 80 |
|
| 85 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 86 |
/** |
|
| 87 |
* Have to call this before the shaders get compiled (i.e before DistortedLibrary.onCreate()) for the Effect to work. |
|
| 88 |
*/ |
|
| 89 |
public static void enable() |
|
| 81 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 82 |
/** |
|
| 83 |
* Makes the whole Object smoothly change its transparency level. |
|
| 84 |
* |
|
| 85 |
* @param alpha level of transparency we want to have at any given moment: pixel.a *= alpha. |
|
| 86 |
* Valid range: <0,1> |
|
| 87 |
*/ |
|
| 88 |
constructor(alpha: Data1D) : super(EffectName.ALPHA) |
|
| 90 | 89 |
{
|
| 91 |
addEffect( EffectName.ALPHA,EffectName.SMOOTH_ALPHA, |
|
| 92 |
"color.a *= (degree*(fUniforms[effect].x-1.0)+1.0);" ); |
|
| 90 |
mAlpha = alpha |
|
| 91 |
mCenter = Static3D(0f,0f,0f) |
|
| 92 |
mRegion = MAX_REGION |
|
| 93 | 93 |
} |
| 94 |
} |
|
| 94 |
} |
|
| src/main/java/org/distorted/library/effect/FragmentEffectBrightness.kt | ||
|---|---|---|
| 18 | 18 |
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // |
| 19 | 19 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 20 | 20 |
|
| 21 |
package org.distorted.library.effect;
|
|
| 21 |
package org.distorted.library.effect |
|
| 22 | 22 |
|
| 23 |
import org.distorted.library.type.Data1D;
|
|
| 24 |
import org.distorted.library.type.Data3D;
|
|
| 25 |
import org.distorted.library.type.Static3D;
|
|
| 23 |
import org.distorted.library.type.Data1D |
|
| 24 |
import org.distorted.library.type.Data3D |
|
| 25 |
import org.distorted.library.type.Static3D |
|
| 26 | 26 |
|
| 27 | 27 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 28 | 28 |
/** |
| 29 | 29 |
* Make a certain Region change its brightness level. |
| 30 | 30 |
*/ |
| 31 |
public class FragmentEffectBrightness extends FragmentEffect
|
|
| 32 |
{
|
|
| 33 |
private final Data1D mBrightness;
|
|
| 34 |
private final Data3D mCenter;
|
|
| 35 |
private final Data3D mRegion;
|
|
| 31 |
class FragmentEffectBrightness : FragmentEffect
|
|
| 32 |
{
|
|
| 33 |
private val mBrightness: Data1D
|
|
| 34 |
private val mCenter: Data3D
|
|
| 35 |
private val mRegion: Data3D
|
|
| 36 | 36 |
|
| 37 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 38 |
/** |
|
| 39 |
* Only for use by the library itself. |
|
| 40 |
* |
|
| 41 |
* @y.exclude |
|
| 42 |
*/ |
|
| 43 |
public boolean compute(float[] uniforms, int index, long currentDuration, long step ) |
|
| 37 |
companion object |
|
| 44 | 38 |
{
|
| 45 |
mCenter.get(uniforms, index+CENTER_OFFSET, currentDuration, step); |
|
| 46 |
mRegion.get(uniforms, index+REGION_OFFSET, currentDuration, step); |
|
| 47 |
return mBrightness.get(uniforms,index,currentDuration,step); |
|
| 39 |
/** |
|
| 40 |
* Have to call this before the shaders get compiled (i.e before DistortedLibrary.onCreate()) for the Effect to work. |
|
| 41 |
*/ |
|
| 42 |
@JvmStatic |
|
| 43 |
fun enable() |
|
| 44 |
{
|
|
| 45 |
addEffect(EffectName.BRIGHTNESS, EffectName.SMOOTH_BRIGHTNESS, |
|
| 46 |
"color.rgb = mix(vec3(0.0,0.0,0.0), color.rgb, degree*(fUniforms[effect].x-1.0)+1.0 );") |
|
| 47 |
} |
|
| 48 | 48 |
} |
| 49 |
|
|
| 50 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 51 |
// PUBLIC API |
|
| 52 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 53 |
/** |
|
| 54 |
* Makes a certain sub-region of the Object smoothly change its brightness level. |
|
| 55 |
* |
|
| 56 |
* @param brightness level of brightness we want to have at any given moment. Valid range: <0,infinity) |
|
| 57 |
* @param center center of the Effect (point in 3D). |
|
| 58 |
* @param region Region this Effect is limited to (3 radii defining an ellipsoid). |
|
| 59 |
* @param smooth If true, the level of 'brightness' will smoothly fade out towards the edges of the region. |
|
| 60 |
*/ |
|
| 61 |
public FragmentEffectBrightness(Data1D brightness, Data3D center, Data3D region, boolean smooth) |
|
| 49 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 50 |
/** |
|
| 51 |
* Only for use by the library itself. |
|
| 52 |
* |
|
| 53 |
* @y.exclude |
|
| 54 |
*/ |
|
| 55 |
override fun compute(uniforms: FloatArray, index: Int, currentDuration: Long, step: Long): Boolean |
|
| 62 | 56 |
{
|
| 63 |
super(smooth?EffectName.SMOOTH_BRIGHTNESS:EffectName.BRIGHTNESS); |
|
| 64 |
mBrightness = brightness; |
|
| 65 |
mCenter = center; |
|
| 66 |
mRegion = (region==null ? MAX_REGION : region); |
|
| 57 |
mCenter.get(uniforms, index+CENTER_OFFSET, currentDuration, step) |
|
| 58 |
mRegion.get(uniforms, index+REGION_OFFSET, currentDuration, step) |
|
| 59 |
return mBrightness.get(uniforms, index, currentDuration, step) |
|
| 67 | 60 |
} |
| 68 | 61 |
|
| 69 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 70 |
/** |
|
| 71 |
* Makes the whole Object smoothly change its brightness level. |
|
| 72 |
* |
|
| 73 |
* @param brightness level of brightness we want to have at any given moment. Valid range: <0,infinity) |
|
| 74 |
*/ |
|
| 75 |
public FragmentEffectBrightness(Data1D brightness) |
|
| 62 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 63 |
// PUBLIC API |
|
| 64 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 65 |
/** |
|
| 66 |
* Makes a certain sub-region of the Object smoothly change its brightness level. |
|
| 67 |
* |
|
| 68 |
* @param brightness level of brightness we want to have at any given moment. Valid range: <0,infinity) |
|
| 69 |
* @param center center of the Effect (point in 3D). |
|
| 70 |
* @param region Region this Effect is limited to (3 radii defining an ellipsoid). |
|
| 71 |
* @param smooth If true, the level of 'brightness' will smoothly fade out towards the edges of the region. |
|
| 72 |
*/ |
|
| 73 |
constructor(brightness: Data1D, center: Data3D, region: Data3D?, smooth: Boolean) : super(if (smooth) EffectName.SMOOTH_BRIGHTNESS else EffectName.BRIGHTNESS) |
|
| 76 | 74 |
{
|
| 77 |
super(EffectName.BRIGHTNESS); |
|
| 78 |
mBrightness = brightness; |
|
| 79 |
mCenter = new Static3D(0,0,0); |
|
| 80 |
mRegion = MAX_REGION; |
|
| 75 |
mBrightness = brightness |
|
| 76 |
mCenter = center |
|
| 77 |
mRegion = (region ?: MAX_REGION) |
|
| 81 | 78 |
} |
| 82 | 79 |
|
| 83 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 84 |
/** |
|
| 85 |
* Have to call this before the shaders get compiled (i.e before DistortedLibrary.onCreate()) for the Effect to work. |
|
| 86 |
*/ |
|
| 87 |
public static void enable() |
|
| 80 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 81 |
/** |
|
| 82 |
* Makes the whole Object smoothly change its brightness level. |
|
| 83 |
* |
|
| 84 |
* @param brightness level of brightness we want to have at any given moment. Valid range: <0,infinity) |
|
| 85 |
*/ |
|
| 86 |
constructor(brightness: Data1D) : super(EffectName.BRIGHTNESS) |
|
| 88 | 87 |
{
|
| 89 |
addEffect( EffectName.BRIGHTNESS,EffectName.SMOOTH_BRIGHTNESS, |
|
| 90 |
"color.rgb = mix(vec3(0.0,0.0,0.0), color.rgb, degree*(fUniforms[effect].x-1.0)+1.0 );" ); |
|
| 88 |
mBrightness = brightness |
|
| 89 |
mCenter = Static3D(0f,0f,0f) |
|
| 90 |
mRegion = MAX_REGION |
|
| 91 | 91 |
} |
| 92 |
} |
|
| 92 |
} |
|
| src/main/java/org/distorted/library/effect/FragmentEffectChroma.kt | ||
|---|---|---|
| 18 | 18 |
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // |
| 19 | 19 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 20 | 20 |
|
| 21 |
package org.distorted.library.effect;
|
|
| 21 |
package org.distorted.library.effect |
|
| 22 | 22 |
|
| 23 |
import org.distorted.library.type.Data1D;
|
|
| 24 |
import org.distorted.library.type.Data3D;
|
|
| 25 |
import org.distorted.library.type.Static3D;
|
|
| 23 |
import org.distorted.library.type.Data1D |
|
| 24 |
import org.distorted.library.type.Data3D |
|
| 25 |
import org.distorted.library.type.Static3D |
|
| 26 | 26 |
|
| 27 | 27 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 28 | 28 |
/** |
| 29 | 29 |
* Make a certain Region change its color. |
| 30 | 30 |
*/ |
| 31 |
public class FragmentEffectChroma extends FragmentEffect
|
|
| 32 |
{
|
|
| 33 |
private final Data1D mBlend;
|
|
| 34 |
private final Data3D mColor;
|
|
| 35 |
private final Data3D mCenter;
|
|
| 36 |
private final Data3D mRegion;
|
|
| 31 |
class FragmentEffectChroma : FragmentEffect
|
|
| 32 |
{
|
|
| 33 |
private val mBlend: Data1D
|
|
| 34 |
private val mColor: Data3D
|
|
| 35 |
private val mCenter: Data3D
|
|
| 36 |
private val mRegion: Data3D
|
|
| 37 | 37 |
|
| 38 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 39 |
/** |
|
| 40 |
* Only for use by the library itself. |
|
| 41 |
* |
|
| 42 |
* @y.exclude |
|
| 43 |
*/ |
|
| 44 |
public boolean compute(float[] uniforms, int index, long currentDuration, long step ) |
|
| 38 |
companion object |
|
| 45 | 39 |
{
|
| 46 |
mColor.get(uniforms,index+1,currentDuration,step); |
|
| 47 |
mCenter.get(uniforms,index+CENTER_OFFSET,currentDuration,step); |
|
| 48 |
mRegion.get(uniforms,index+REGION_OFFSET,currentDuration,step); |
|
| 49 |
return mBlend.get(uniforms,index,currentDuration,step); |
|
| 40 |
/** |
|
| 41 |
* Have to call this before the shaders get compiled (i.e before DistortedLibrary.onCreate()) for the Effect to work. |
|
| 42 |
*/ |
|
| 43 |
fun enable() |
|
| 44 |
{
|
|
| 45 |
addEffect(EffectName.CHROMA, EffectName.SMOOTH_CHROMA, |
|
| 46 |
"color.rgb = mix(color.rgb, fUniforms[effect].yzw, degree*fUniforms[effect].x);") |
|
| 47 |
} |
|
| 50 | 48 |
} |
| 51 |
|
|
| 52 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 53 |
// PUBLIC API |
|
| 54 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 55 |
/** |
|
| 56 |
* Makes a certain sub-region of the Object smoothly change all three of its RGB components. |
|
| 57 |
* |
|
| 58 |
* @param blend level of blend a given pixel will be mixed with the next parameter 'color': |
|
| 59 |
* pixel = (1-level)*pixel + level*color. |
|
| 60 |
* Valid range: <0,1> |
|
| 61 |
* @param color Color to mix. (1,0,0) is RED. |
|
| 62 |
* @param center center of the Effect (point in 3D). |
|
| 63 |
* @param region Region this Effect is limited to (3 radii defining an ellipsoid). |
|
| 64 |
* @param smooth If true, the level of 'blend' will smoothly fade out towards the edges of the region. |
|
| 65 |
*/ |
|
| 66 |
public FragmentEffectChroma(Data1D blend, Data3D color, Data3D center, Data3D region, boolean smooth) |
|
| 49 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 50 |
/** |
|
| 51 |
* Only for use by the library itself. |
|
| 52 |
* |
|
| 53 |
* @y.exclude |
|
| 54 |
*/ |
|
| 55 |
override fun compute(uniforms: FloatArray, index: Int, currentDuration: Long, step: Long): Boolean |
|
| 67 | 56 |
{
|
| 68 |
super(smooth?EffectName.SMOOTH_CHROMA:EffectName.CHROMA); |
|
| 69 |
mBlend = blend; |
|
| 70 |
mColor = color; |
|
| 71 |
mCenter = center; |
|
| 72 |
mRegion = (region==null ? MAX_REGION : region); |
|
| 57 |
mColor.get(uniforms, index+1, currentDuration, step) |
|
| 58 |
mCenter.get(uniforms, index+CENTER_OFFSET, currentDuration, step) |
|
| 59 |
mRegion.get(uniforms, index+REGION_OFFSET, currentDuration, step) |
|
| 60 |
return mBlend.get(uniforms, index, currentDuration, step) |
|
| 73 | 61 |
} |
| 74 | 62 |
|
| 75 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 76 |
/** |
|
| 77 |
* Makes the whole Object smoothly change all three of its RGB components. |
|
| 78 |
* |
|
| 79 |
* @param blend level of blend a given pixel will be mixed with the next parameter 'color': |
|
Also available in: Unified diff
migrate the 'effect' package.