Revision 81a0b906
Added by Leszek Koltunski over 8 years ago
| src/main/java/org/distorted/library/program/DistortedProgram.java | ||
|---|---|---|
| 230 | 230 |
{
|
| 231 | 231 |
String error = GLES30.glGetShaderInfoLog(shaderHandle); |
| 232 | 232 |
|
| 233 |
//android.util.Log.e("Program", "error compiling :"+error);
|
|
| 234 |
|
|
| 233 | 235 |
switch(shaderType) |
| 234 | 236 |
{
|
| 235 | 237 |
case GLES30.GL_VERTEX_SHADER : throw new VertexCompilationException(error); |
| src/main/res/raw/main_fragment_shader.glsl | ||
|---|---|---|
| 37 | 37 |
////////////////////////////////////////////////////////////////////////////////////////////// |
| 38 | 38 |
// CHROMA EFFECT |
| 39 | 39 |
|
| 40 |
#if defined(CHROMA) || defined(SMOOTH_CHROMA) |
|
| 40 | 41 |
void chroma(float degree, int effect, inout vec4 color) |
| 41 | 42 |
{
|
| 42 | 43 |
color.rgb = mix(color.rgb, fUniforms[effect].yzw, degree*fUniforms[effect].x); |
| 43 | 44 |
} |
| 45 |
#endif |
|
| 44 | 46 |
|
| 45 | 47 |
////////////////////////////////////////////////////////////////////////////////////////////// |
| 46 | 48 |
// ALPHA EFFECT (change transparency level) |
| 47 | 49 |
|
| 50 |
#if defined(ALPHA) || defined(SMOOTH_ALPHA) |
|
| 48 | 51 |
void alpha(float degree, int effect, inout vec4 color) |
| 49 | 52 |
{
|
| 50 | 53 |
color.a *= (degree*(fUniforms[effect].x-1.0)+1.0); |
| 51 | 54 |
} |
| 55 |
#endif |
|
| 52 | 56 |
|
| 53 | 57 |
////////////////////////////////////////////////////////////////////////////////////////////// |
| 54 | 58 |
// BRIGHTNESS EFFECT |
| 55 | 59 |
|
| 60 |
#if defined(BRIGHTNESS) || defined(SMOOTH_BRIGHTNESS) |
|
| 56 | 61 |
void brightness(float degree, int effect, inout vec4 color) |
| 57 | 62 |
{
|
| 58 | 63 |
color.rgb = mix(vec3(0.0,0.0,0.0), color.rgb, degree*(fUniforms[effect].x-1.0)+1.0 ); |
| 59 | 64 |
} |
| 60 |
|
|
| 65 |
#endif |
|
| 66 |
|
|
| 61 | 67 |
////////////////////////////////////////////////////////////////////////////////////////////// |
| 62 | 68 |
// CONTRAST EFFECT |
| 63 | 69 |
|
| 70 |
#if defined(CONTRAST) || defined(SMOOTH_CONTRAST) |
|
| 64 | 71 |
void contrast(float degree, int effect, inout vec4 color) |
| 65 | 72 |
{
|
| 66 | 73 |
color.rgb = mix(vec3(0.5,0.5,0.5), color.rgb, degree*(fUniforms[effect].x-1.0)+1.0 ); |
| 67 | 74 |
} |
| 75 |
#endif |
|
| 68 | 76 |
|
| 69 | 77 |
////////////////////////////////////////////////////////////////////////////////////////////// |
| 70 | 78 |
// SATURATION EFFECT |
| 71 | 79 |
|
| 80 |
#if defined(SATURATION) || defined(SMOOTH_SATURATION) |
|
| 72 | 81 |
void saturation(float degree, int effect, inout vec4 color) |
| 73 | 82 |
{
|
| 74 | 83 |
float luminance = dot(LUMI,color.rgb); |
| 75 | 84 |
color.rgb = mix(vec3(luminance,luminance,luminance), color.rgb, degree*(fUniforms[effect].x-1.0)+1.0 ); |
| 76 | 85 |
} |
| 86 |
#endif |
|
| 77 | 87 |
|
| 78 | 88 |
#endif |
| 79 | 89 |
|
| ... | ... | |
| 92 | 102 |
diff = (v_Position.xy - fUniforms[2*i+1].xy)/fUniforms[2*i+1].zw; |
| 93 | 103 |
pointDegree = max(0.0,1.0-dot(diff,diff)); |
| 94 | 104 |
|
| 95 |
if( fType[i]==CHROMA ) chroma (sign(pointDegree),2*i,pixel); |
|
| 96 |
else if( fType[i]==SMOOTH_CHROMA ) chroma ( pointDegree ,2*i,pixel); |
|
| 97 |
else if( fType[i]==ALPHA ) alpha (sign(pointDegree),2*i,pixel); |
|
| 98 |
else if( fType[i]==SMOOTH_ALPHA ) alpha ( pointDegree ,2*i,pixel); |
|
| 99 |
else if( fType[i]==BRIGHTNESS ) brightness(sign(pointDegree),2*i,pixel); |
|
| 100 |
else if( fType[i]==SMOOTH_BRIGHTNESS ) brightness( pointDegree ,2*i,pixel); |
|
| 101 |
else if( fType[i]==CONTRAST ) contrast (sign(pointDegree),2*i,pixel); |
|
| 102 |
else if( fType[i]==SMOOTH_CONTRAST ) contrast ( pointDegree ,2*i,pixel); |
|
| 103 |
else if( fType[i]==SATURATION ) saturation(sign(pointDegree),2*i,pixel); |
|
| 104 |
else if( fType[i]==SMOOTH_SATURATION ) saturation( pointDegree ,2*i,pixel); |
|
| 105 |
#ifdef CHROMA |
|
| 106 |
if( fType[i]==CHROMA ) chroma (sign(pointDegree),2*i,pixel); else |
|
| 107 |
#endif |
|
| 108 |
#ifdef SMOOTH_CHROMA |
|
| 109 |
if( fType[i]==SMOOTH_CHROMA ) chroma ( pointDegree ,2*i,pixel); else |
|
| 110 |
#endif |
|
| 111 |
#ifdef ALPHA |
|
| 112 |
if( fType[i]==ALPHA ) alpha (sign(pointDegree),2*i,pixel); else |
|
| 113 |
#endif |
|
| 114 |
#ifdef SMOOTH_ALPHA |
|
| 115 |
if( fType[i]==SMOOTH_ALPHA ) alpha ( pointDegree ,2*i,pixel); else |
|
| 116 |
#endif |
|
| 117 |
#ifdef BRIGHTNESS |
|
| 118 |
if( fType[i]==BRIGHTNESS ) brightness(sign(pointDegree),2*i,pixel); else |
|
| 119 |
#endif |
|
| 120 |
#ifdef SMOOTH_BRIGHTNESS |
|
| 121 |
if( fType[i]==SMOOTH_BRIGHTNESS ) brightness( pointDegree ,2*i,pixel); else |
|
| 122 |
#endif |
|
| 123 |
#ifdef CONTRAST |
|
| 124 |
if( fType[i]==CONTRAST ) contrast (sign(pointDegree),2*i,pixel); else |
|
| 125 |
#endif |
|
| 126 |
#ifdef SMOOTH_CONTRAST |
|
| 127 |
if( fType[i]==SMOOTH_CONTRAST ) contrast ( pointDegree ,2*i,pixel); else |
|
| 128 |
#endif |
|
| 129 |
#ifdef SATURATION |
|
| 130 |
if( fType[i]==SATURATION ) saturation(sign(pointDegree),2*i,pixel); else |
|
| 131 |
#endif |
|
| 132 |
#ifdef SMOOTH_SATURATION |
|
| 133 |
if( fType[i]==SMOOTH_SATURATION ) saturation( pointDegree ,2*i,pixel); else |
|
| 134 |
#endif |
|
| 135 |
{}
|
|
| 105 | 136 |
} |
| 106 | 137 |
#endif |
| 107 | 138 |
|
| src/main/res/raw/main_vertex_shader.glsl | ||
|---|---|---|
| 45 | 45 |
uniform vec4 vUniforms[3*NUM_VERTEX];// i-th effect is 3 consecutive vec4's: [3*i], [3*i+1], [3*i+2]. |
| 46 | 46 |
// The first vec4 is the Interpolated values, |
| 47 | 47 |
// next is half cache half Center, the third - the Region. |
| 48 |
#endif |
|
| 49 |
|
|
| 50 |
#if NUM_VERTEX>0 |
|
| 51 | 48 |
|
| 52 | 49 |
////////////////////////////////////////////////////////////////////////////////////////////// |
| 53 | 50 |
// HELPER FUNCTIONS |
| ... | ... | |
| 214 | 211 |
// along the force line is. |
| 215 | 212 |
// 0<=C<1 looks completely ridiculous and C<0 destroys the system. |
| 216 | 213 |
|
| 214 |
#ifdef DEFORM |
|
| 217 | 215 |
void deform(in int effect, inout vec3 v, inout vec3 n) |
| 218 | 216 |
{
|
| 219 | 217 |
const vec2 ONE = vec2(1.0,1.0); |
| ... | ... | |
| 253 | 251 |
|
| 254 | 252 |
n.xy += n.z*b*ps; |
| 255 | 253 |
} |
| 254 |
#endif |
|
| 256 | 255 |
|
| 257 | 256 |
////////////////////////////////////////////////////////////////////////////////////////////// |
| 258 | 257 |
// DISTORT EFFECT |
| ... | ... | |
| 309 | 308 |
// Thus we actually want to compute N(v.x,v.y) = a*(-(dx/|PS|)*f'(|PX|), -(dy/|PS|)*f'(|PX|), 1) and keep adding |
| 310 | 309 |
// the first two components. (a is the horizontal part) |
| 311 | 310 |
|
| 311 |
#ifdef DISTORT |
|
| 312 | 312 |
void distort(in int effect, inout vec3 v, inout vec3 n) |
| 313 | 313 |
{
|
| 314 | 314 |
vec2 center = vUniforms[effect+1].yz; |
| ... | ... | |
| 330 | 330 |
v.xy += d*force.xy; |
| 331 | 331 |
n.xy += n.z*b*ps; |
| 332 | 332 |
} |
| 333 |
#endif |
|
| 333 | 334 |
|
| 334 | 335 |
////////////////////////////////////////////////////////////////////////////////////////////// |
| 335 | 336 |
// SINK EFFECT |
| ... | ... | |
| 337 | 338 |
// Pull P=(v.x,v.y) towards center of the effect with P' = P + (1-h)*dist(S-P) |
| 338 | 339 |
// when h>1 we are pushing points away from S: P' = P + (1/h-1)*dist(S-P) |
| 339 | 340 |
|
| 341 |
#ifdef SINK |
|
| 340 | 342 |
void sink(in int effect,inout vec3 v) |
| 341 | 343 |
{
|
| 342 | 344 |
vec2 center = vUniforms[effect+1].yz; |
| ... | ... | |
| 346 | 348 |
|
| 347 | 349 |
v.xy += t*ps; |
| 348 | 350 |
} |
| 351 |
#endif |
|
| 349 | 352 |
|
| 350 | 353 |
////////////////////////////////////////////////////////////////////////////////////////////// |
| 351 | 354 |
// PINCH EFFECT |
| ... | ... | |
| 356 | 359 |
// with P' = P + (1-h)*dist(line to P) |
| 357 | 360 |
// when h>1 we are pushing points away from S: P' = P + (1/h-1)*dist(line to P) |
| 358 | 361 |
|
| 362 |
#ifdef PINCH |
|
| 359 | 363 |
void pinch(in int effect,inout vec3 v) |
| 360 | 364 |
{
|
| 361 | 365 |
vec2 center = vUniforms[effect+1].yz; |
| ... | ... | |
| 367 | 371 |
|
| 368 | 372 |
v.xy += t*dot(ps,dir)*dir; |
| 369 | 373 |
} |
| 374 |
#endif |
|
| 370 | 375 |
|
| 371 | 376 |
////////////////////////////////////////////////////////////////////////////////////////////// |
| 372 | 377 |
// SWIRL EFFECT |
| ... | ... | |
| 375 | 380 |
// This effect rotates the current vertex V by vInterpolated.x radians clockwise around the circle dilated |
| 376 | 381 |
// by (1-d) around the center of the effect S. |
| 377 | 382 |
|
| 383 |
#ifdef SWIRL |
|
| 378 | 384 |
void swirl(in int effect, inout vec3 v) |
| 379 | 385 |
{
|
| 380 | 386 |
vec2 center = vUniforms[effect+1].yz; |
| ... | ... | |
| 393 | 399 |
// bitmap some points end up with d2<0 and they disappear off view. |
| 394 | 400 |
v.xy += min(d1_circle,d1_bitmap)*(PS - PS2/(1.0-d2)); // if d2=1 (i.e P=center) we should have P unchanged. How to do it? |
| 395 | 401 |
} |
| 402 |
#endif |
|
| 396 | 403 |
|
| 397 | 404 |
////////////////////////////////////////////////////////////////////////////////////////////// |
| 398 | 405 |
// WAVE EFFECT |
| ... | ... | |
| 460 | 467 |
// |
| 461 | 468 |
// Generally speaking I'd keep to amplitude < length, as the opposite case has some other problems as well. |
| 462 | 469 |
|
| 470 |
#ifdef WAVE |
|
| 463 | 471 |
void wave(in int effect, inout vec3 v, inout vec3 n) |
| 464 | 472 |
{
|
| 465 | 473 |
vec2 center = vUniforms[effect+1].yz; |
| ... | ... | |
| 522 | 530 |
} |
| 523 | 531 |
} |
| 524 | 532 |
} |
| 525 |
|
|
| 526 | 533 |
#endif |
| 527 | 534 |
|
| 535 |
#endif // NUM_VERTEX>0 |
|
| 536 |
|
|
| 528 | 537 |
////////////////////////////////////////////////////////////////////////////////////////////// |
| 529 | 538 |
|
| 530 | 539 |
void main() |
| ... | ... | |
| 537 | 546 |
|
| 538 | 547 |
for(int i=0; i<vNumEffects; i++) |
| 539 | 548 |
{
|
| 540 |
if( vType[i]==DISTORT) distort(j,v,n); |
|
| 541 |
else if( vType[i]==DEFORM ) deform (j,v,n); |
|
| 542 |
else if( vType[i]==SINK ) sink (j,v); |
|
| 543 |
else if( vType[i]==PINCH ) pinch (j,v); |
|
| 544 |
else if( vType[i]==SWIRL ) swirl (j,v); |
|
| 545 |
else if( vType[i]==WAVE ) wave (j,v,n); |
|
| 549 |
#ifdef DISTORT |
|
| 550 |
if( vType[i]==DISTORT) distort(j,v,n); else |
|
| 551 |
#endif |
|
| 552 |
#ifdef DEFORM |
|
| 553 |
if( vType[i]==DEFORM ) deform (j,v,n); else |
|
| 554 |
#endif |
|
| 555 |
#ifdef SINK |
|
| 556 |
if( vType[i]==SINK ) sink (j,v); else |
|
| 557 |
#endif |
|
| 558 |
#ifdef PINCH |
|
| 559 |
if( vType[i]==PINCH ) pinch (j,v); else |
|
| 560 |
#endif |
|
| 561 |
#ifdef SWIRL |
|
| 562 |
if( vType[i]==SWIRL ) swirl (j,v); else |
|
| 563 |
#endif |
|
| 564 |
#ifdef WAVE |
|
| 565 |
if( vType[i]==WAVE ) wave (j,v,n); else |
|
| 566 |
#endif |
|
| 567 |
{}
|
|
| 546 | 568 |
|
| 547 | 569 |
j+=3; |
| 548 | 570 |
} |
Also available in: Unified diff
Preparation for shader optimization