Revision ffbf279e
Added by Leszek Koltunski over 9 years ago
| src/main/java/org/distorted/library/DistortedBitmap.java | ||
|---|---|---|
| 51 | 51 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 52 | 52 |
/** |
| 53 | 53 |
* Default constructor: creates a DistortedBitmap (width,height) pixels in size, with the distortion |
| 54 |
* grid of size 'size' and does not fill it up with any Bitmap data just yet.
|
|
| 54 |
* grid of 'cols' and does not fill it up with any Bitmap data just yet.
|
|
| 55 | 55 |
* <p> |
| 56 | 56 |
* Distortion grid is a grid of rectangles the Bitmap is split to. The vertices of this grid are then |
| 57 | 57 |
* moved around by the Vertex Shader to create various Vertex Effects. |
| ... | ... | |
| 65 | 65 |
* |
| 66 | 66 |
* @param width width of the DistortedBitmap, in pixels. |
| 67 | 67 |
* @param height height of the DistortedBitmap, in pixels. |
| 68 |
* @param gridSize Horizontal size of the distortion grid. 2<=size<256. |
|
| 68 |
* @param cols Number of columns in the distortion grid. 2<=size<256. |
|
| 69 |
* Number of rows gets calculated with 'rows = cols*height/width'. |
|
| 69 | 70 |
*/ |
| 70 |
public DistortedBitmap(int width, int height, int gridSize)
|
|
| 71 |
public DistortedBitmap(int width, int height, int cols)
|
|
| 71 | 72 |
{
|
| 72 |
int xsize = gridSize;
|
|
| 73 |
int ysize = xsize*height/width;
|
|
| 73 |
int xsize = cols;
|
|
| 74 |
int ysize = cols*height/width;
|
|
| 74 | 75 |
|
| 75 | 76 |
if( xsize<2 ) xsize= 2; |
| 76 | 77 |
if( xsize>256 ) xsize=256; |
| ... | ... | |
| 79 | 80 |
|
| 80 | 81 |
mSizeX= width; |
| 81 | 82 |
mSizeY= height; |
| 82 |
mSizeZ= 1;
|
|
| 83 |
mSizeZ= 1; |
|
| 83 | 84 |
mGrid = new DistortedBitmapGrid(xsize,ysize); |
| 84 |
initializeData(gridSize);
|
|
| 85 |
initializeData(); |
|
| 85 | 86 |
} |
| 86 | 87 |
|
| 87 | 88 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| src/main/java/org/distorted/library/DistortedCubes.java | ||
|---|---|---|
| 67 | 67 |
* |
| 68 | 68 |
* X |
| 69 | 69 |
* </p> |
| 70 |
* @param gridSize size, in pixels, of the single 1x1x1 cube our cuboid is built from
|
|
| 70 |
* @param cubeSize size, in pixels, of the single 1x1x1 cube our cuboid is built from
|
|
| 71 | 71 |
* @param frontOnly Only create the front wall or side and back as well? |
| 72 | 72 |
*/ |
| 73 |
public DistortedCubes(int cols, String desc, int gridSize, boolean frontOnly)
|
|
| 73 |
public DistortedCubes(int cols, String desc, int cubeSize, boolean frontOnly)
|
|
| 74 | 74 |
{
|
| 75 | 75 |
int Rs = 0; |
| 76 | 76 |
int Cs = 0; |
| ... | ... | |
| 93 | 93 |
} |
| 94 | 94 |
} |
| 95 | 95 |
|
| 96 |
mSizeX= gridSize*Cs;
|
|
| 97 |
mSizeY= gridSize*Rs;
|
|
| 98 |
mSizeZ= frontOnly ? 0 : gridSize;
|
|
| 96 |
mSizeX= cubeSize*Cs;
|
|
| 97 |
mSizeY= cubeSize*Rs;
|
|
| 98 |
mSizeZ= frontOnly ? 1 : cubeSize;
|
|
| 99 | 99 |
mGrid = new DistortedCubesGrid(cols,desc, frontOnly); |
| 100 |
initializeData(gridSize);
|
|
| 100 |
initializeData(); |
|
| 101 | 101 |
} |
| 102 | 102 |
|
| 103 | 103 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| src/main/java/org/distorted/library/DistortedObject.java | ||
|---|---|---|
| 46 | 46 |
|
| 47 | 47 |
protected DistortedObjectGrid mGrid = null; |
| 48 | 48 |
protected long mID; |
| 49 |
protected int mSizeX, mSizeY, mSizeZ, mSize; // in screen space
|
|
| 49 |
protected int mSizeX, mSizeY, mSizeZ; // in screen space |
|
| 50 | 50 |
|
| 51 | 51 |
protected Bitmap[] mBmp= null; // |
| 52 | 52 |
int[] mTextureDataH; // have to be shared among all the cloned Objects |
| ... | ... | |
| 58 | 58 |
|
| 59 | 59 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 60 | 60 |
|
| 61 |
protected void initializeData(int size)
|
|
| 61 |
protected void initializeData() |
|
| 62 | 62 |
{
|
| 63 | 63 |
mID = DistortedObjectList.add(this); |
| 64 |
mSize = size; |
|
| 65 | 64 |
mTextureDataH = new int[1]; |
| 66 | 65 |
mTextureDataH[0]= 0; |
| 67 | 66 |
mBmp = new Bitmap[1]; |
| ... | ... | |
| 220 | 219 |
mSizeX = dc.mSizeX; |
| 221 | 220 |
mSizeY = dc.mSizeY; |
| 222 | 221 |
mSizeZ = dc.mSizeZ; |
| 223 |
mSize = dc.mSize; |
|
| 224 | 222 |
mGrid = dc.mGrid; |
| 225 | 223 |
|
| 226 | 224 |
if( (flags & Distorted.CLONE_BITMAP) != 0 ) |
| src/main/java/org/distorted/library/DistortedObjectGrid.java | ||
|---|---|---|
| 34 | 34 |
|
| 35 | 35 |
protected int dataLength; |
| 36 | 36 |
|
| 37 |
protected FloatBuffer mGridPositions,mGridColors,mGridNormals,mGridTexture;
|
|
| 37 |
protected FloatBuffer mGridPositions,mGridNormals,mGridTexture; |
|
| 38 | 38 |
|
| 39 | 39 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 40 | 40 |
|
| src/main/res/raw/main_fragment_shader.glsl | ||
|---|---|---|
| 32 | 32 |
uniform vec4 fUniforms[2*NUM_FRAGMENT]; // i-th effect is 2 consecutive vec4's: [2*i], [2*i+1]. First vec4 is the Interpolated values, |
| 33 | 33 |
// next describes the Region, i.e. area over which the effect is active. |
| 34 | 34 |
|
| 35 |
const vec3 LUMI3= vec3( 0.2125, 0.7154, 0.0721 ); |
|
| 36 |
const vec3 ZERO3= vec3(0.0,0.0,0.0); |
|
| 37 |
const vec3 HALF3= vec3(0.5,0.5,0.5); |
|
| 38 |
const vec2 ONE2 = vec2(1.0,1.0); |
|
| 39 |
const vec2 HALF2= vec2(0.5,0.5); |
|
| 40 |
|
|
| 35 |
const vec3 LUMI = vec3( 0.2125, 0.7154, 0.0721 ); |
|
| 36 |
|
|
| 41 | 37 |
////////////////////////////////////////////////////////////////////////////////////////////// |
| 42 | 38 |
// MACROBLOCK EFFECT |
| 43 | 39 |
|
| 44 |
void macroblock(float degree, int effect, inout vec4 pixel)
|
|
| 40 |
void macroblock(float degree, int effect, inout vec2 tex)
|
|
| 45 | 41 |
{
|
| 46 |
vec2 a = degree*(fUniforms[effect].yz-ONE2)+ONE2; |
|
| 47 |
vec2 tex = ( max((1.0-degree)*v_TexCoordinate,floor(v_TexCoordinate*a)) + degree*HALF2 ) / a; |
|
| 48 |
|
|
| 49 |
pixel = texture2D(u_Texture, tex); |
|
| 42 |
vec2 one = vec2(1.0,1.0); |
|
| 43 |
vec2 a = degree*(fUniforms[effect].yz-one)+one; |
|
| 44 |
tex = ( max((1.0-degree)*tex,floor(tex*a)) + degree*vec2(0.5,0.5) ) / a; |
|
| 50 | 45 |
} |
| 51 | 46 |
|
| 52 | 47 |
////////////////////////////////////////////////////////////////////////////////////////////// |
| 53 | 48 |
// CHROMA EFFECT |
| 54 | 49 |
|
| 55 |
void chroma(float degree, int effect, inout vec4 pixel)
|
|
| 50 |
void chroma(float degree, int effect, inout vec4 color)
|
|
| 56 | 51 |
{
|
| 57 |
pixel.rgb = mix( pixel.rgb, fUniforms[effect].yzw, degree*fUniforms[effect].x);
|
|
| 52 |
color.rgb = mix(color.rgb, fUniforms[effect].yzw, degree*fUniforms[effect].x);
|
|
| 58 | 53 |
} |
| 59 | 54 |
|
| 60 | 55 |
////////////////////////////////////////////////////////////////////////////////////////////// |
| 61 | 56 |
// ALPHA EFFECT (change transparency level) |
| 62 | 57 |
|
| 63 |
void alpha(float degree, int effect, inout vec4 pixel)
|
|
| 58 |
void alpha(float degree, int effect, inout vec4 color)
|
|
| 64 | 59 |
{
|
| 65 |
pixel.a *= (degree*(fUniforms[effect].x-1.0)+1.0);
|
|
| 60 |
color.a *= (degree*(fUniforms[effect].x-1.0)+1.0);
|
|
| 66 | 61 |
} |
| 67 | 62 |
|
| 68 | 63 |
////////////////////////////////////////////////////////////////////////////////////////////// |
| 69 | 64 |
// BRIGHTNESS EFFECT |
| 70 | 65 |
|
| 71 |
void brightness(float degree, int effect, inout vec4 pixel)
|
|
| 66 |
void brightness(float degree, int effect, inout vec4 color)
|
|
| 72 | 67 |
{
|
| 73 |
pixel.rgb = mix(ZERO3, pixel.rgb, degree*(fUniforms[effect].x-1.0)+1.0 );
|
|
| 68 |
color.rgb = mix(vec3(0.0,0.0,0.0), color.rgb, degree*(fUniforms[effect].x-1.0)+1.0 );
|
|
| 74 | 69 |
} |
| 75 |
|
|
| 70 |
|
|
| 76 | 71 |
////////////////////////////////////////////////////////////////////////////////////////////// |
| 77 | 72 |
// CONTRAST EFFECT |
| 78 | 73 |
|
| 79 |
void contrast(float degree, int effect, inout vec4 pixel)
|
|
| 74 |
void contrast(float degree, int effect, inout vec4 color)
|
|
| 80 | 75 |
{
|
| 81 |
pixel.rgb = mix(HALF3, pixel.rgb, degree*(fUniforms[effect].x-1.0)+1.0 );
|
|
| 76 |
color.rgb = mix(vec3(0.5,0.5,0.5), color.rgb, degree*(fUniforms[effect].x-1.0)+1.0 );
|
|
| 82 | 77 |
} |
| 83 | 78 |
|
| 84 | 79 |
////////////////////////////////////////////////////////////////////////////////////////////// |
| 85 | 80 |
// SATURATION EFFECT |
| 86 | 81 |
|
| 87 |
void saturation(float degree, int effect, inout vec4 pixel)
|
|
| 82 |
void saturation(float degree, int effect, inout vec4 color)
|
|
| 88 | 83 |
{
|
| 89 |
float luminance = dot(LUMI3,pixel.rgb);
|
|
| 90 |
pixel.rgb = mix(vec3(luminance,luminance,luminance), pixel.rgb, degree*(fUniforms[effect].x-1.0)+1.0 );
|
|
| 84 |
float luminance = dot(LUMI,color.rgb);
|
|
| 85 |
color.rgb = mix(vec3(luminance,luminance,luminance), color.rgb, degree*(fUniforms[effect].x-1.0)+1.0 );
|
|
| 91 | 86 |
} |
| 92 | 87 |
|
| 93 | 88 |
#endif |
| ... | ... | |
| 96 | 91 |
|
| 97 | 92 |
void main() |
| 98 | 93 |
{
|
| 99 |
vec4 pixel = texture2D(u_Texture, v_TexCoordinate); |
|
| 94 |
vec2 tex = v_TexCoordinate; |
|
| 95 |
vec4 col = vec4(1.0,1.0,1.0,1.0); |
|
| 100 | 96 |
|
| 101 | 97 |
#if NUM_FRAGMENT>0 |
| 102 | 98 |
vec2 diff; |
| 103 | 99 |
float pointDegree; |
| 104 |
|
|
| 100 |
|
|
| 105 | 101 |
for(int i=0; i<fNumEffects; i++) |
| 106 | 102 |
{
|
| 107 | 103 |
diff = (v_Position.xy - fUniforms[2*i+1].xy)/fUniforms[2*i+1].zw; |
| 108 | 104 |
pointDegree = max(0.0,1.0-dot(diff,diff)); |
| 109 | 105 |
|
| 110 |
if( fType[i]==MACROBLOCK ) macroblock(sign(pointDegree),2*i, pixel);
|
|
| 111 |
else if( fType[i]==CHROMA ) chroma (sign(pointDegree),2*i, pixel);
|
|
| 112 |
else if( fType[i]==SMOOTH_CHROMA ) chroma ( pointDegree ,2*i, pixel);
|
|
| 113 |
else if( fType[i]==ALPHA ) alpha (sign(pointDegree),2*i, pixel);
|
|
| 114 |
else if( fType[i]==SMOOTH_ALPHA ) alpha ( pointDegree ,2*i, pixel);
|
|
| 115 |
else if( fType[i]==BRIGHTNESS ) brightness(sign(pointDegree),2*i, pixel);
|
|
| 116 |
else if( fType[i]==SMOOTH_BRIGHTNESS ) brightness( pointDegree ,2*i, pixel);
|
|
| 117 |
else if( fType[i]==CONTRAST ) contrast (sign(pointDegree),2*i, pixel);
|
|
| 118 |
else if( fType[i]==SMOOTH_CONTRAST ) contrast ( pointDegree ,2*i, pixel);
|
|
| 119 |
else if( fType[i]==SATURATION ) saturation(sign(pointDegree),2*i, pixel);
|
|
| 120 |
else if( fType[i]==SMOOTH_SATURATION ) saturation( pointDegree ,2*i, pixel);
|
|
| 106 |
if( fType[i]==MACROBLOCK ) macroblock(sign(pointDegree),2*i,tex);
|
|
| 107 |
else if( fType[i]==CHROMA ) chroma (sign(pointDegree),2*i,col);
|
|
| 108 |
else if( fType[i]==SMOOTH_CHROMA ) chroma ( pointDegree ,2*i,col);
|
|
| 109 |
else if( fType[i]==ALPHA ) alpha (sign(pointDegree),2*i,col);
|
|
| 110 |
else if( fType[i]==SMOOTH_ALPHA ) alpha ( pointDegree ,2*i,col);
|
|
| 111 |
else if( fType[i]==BRIGHTNESS ) brightness(sign(pointDegree),2*i,col);
|
|
| 112 |
else if( fType[i]==SMOOTH_BRIGHTNESS ) brightness( pointDegree ,2*i,col);
|
|
| 113 |
else if( fType[i]==CONTRAST ) contrast (sign(pointDegree),2*i,col);
|
|
| 114 |
else if( fType[i]==SMOOTH_CONTRAST ) contrast ( pointDegree ,2*i,col);
|
|
| 115 |
else if( fType[i]==SATURATION ) saturation(sign(pointDegree),2*i,col);
|
|
| 116 |
else if( fType[i]==SMOOTH_SATURATION ) saturation( pointDegree ,2*i,col);
|
|
| 121 | 117 |
} |
| 122 | 118 |
#endif |
| 123 | 119 |
|
| 124 |
gl_FragColor = pixel*0.5*(v_Normal.z+1.0);
|
|
| 120 |
gl_FragColor = (col * 0.5 * (v_Normal.z+1.0) * texture2D(u_Texture, tex));
|
|
| 125 | 121 |
} |
Also available in: Unified diff
revert latest changes to the fragment shader.
small things in DistortedObjects.