Revision 5b1c0f47
Added by Leszek Koltunski about 9 years ago
| src/main/java/org/distorted/library/EffectQueueVertex.java | ||
|---|---|---|
| 157 | 157 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 158 | 158 |
// Do various post-processing on already computed effects. |
| 159 | 159 |
// 1) here unlike in the fragment queue, we don't have to multiply the points by ModelView matrix because that gets done in the shader. |
| 160 |
// 2) in case of swirl, pre-compute the sine and cosine of its rotation angle |
|
| 161 |
// 3) likewise in case of wave |
|
| 160 |
// 2) in case of SWIRL, switch the angle from degrees to radians |
|
| 161 |
// 3) likewise in case of WAVE |
|
| 162 |
// 4) In case of DISTORT, invert the Y-axis |
|
| 162 | 163 |
|
| 163 | 164 |
void postprocess(int effect) |
| 164 | 165 |
{
|
| 165 |
double d; |
|
| 166 |
|
|
| 167 | 166 |
if( mName[effect]==EffectNames.SWIRL.ordinal() ) |
| 168 | 167 |
{
|
| 169 |
d = Math.PI*mUniforms[NUM_UNIFORMS*effect]/180; |
|
| 170 |
mUniforms[NUM_UNIFORMS*effect ] = (float)Math.sin(d); |
|
| 171 |
mUniforms[NUM_UNIFORMS*effect+4] = (float)Math.cos(d); |
|
| 168 |
mUniforms[NUM_UNIFORMS*effect ] = (float)(Math.PI*mUniforms[NUM_UNIFORMS*effect ]/180); |
|
| 172 | 169 |
} |
| 173 | 170 |
if( mName[effect]==EffectNames.WAVE.ordinal() ) |
| 174 | 171 |
{
|
| 175 |
d = Math.PI*mUniforms[NUM_UNIFORMS*effect+1]/180; |
|
| 176 |
mUniforms[NUM_UNIFORMS*effect+1] = (float)Math.sin(d); |
|
| 177 |
mUniforms[NUM_UNIFORMS*effect+4] = (float)Math.cos(d); |
|
| 178 |
d = Math.PI*mUniforms[NUM_UNIFORMS*effect+3]/180; |
|
| 179 |
mUniforms[NUM_UNIFORMS*effect+3] = (float)Math.sin(d); |
|
| 180 |
mUniforms[NUM_UNIFORMS*effect+5] = (float)Math.cos(d); |
|
| 172 |
mUniforms[NUM_UNIFORMS*effect+1] = (float)(Math.PI*mUniforms[NUM_UNIFORMS*effect+1]/180); |
|
| 173 |
mUniforms[NUM_UNIFORMS*effect+3] = (float)(Math.PI*mUniforms[NUM_UNIFORMS*effect+3]/180); |
|
| 181 | 174 |
} |
| 182 | 175 |
if( mName[effect]==EffectNames.DISTORT.ordinal() ) |
| 183 | 176 |
{
|
| src/main/res/raw/main_vertex_shader.glsl | ||
|---|---|---|
| 336 | 336 |
vec4 SO = vUniforms[effect+2]; |
| 337 | 337 |
float d1_circle = degree_region(SO,PS); |
| 338 | 338 |
float d1_bitmap = degree_bitmap(center,PS); |
| 339 |
float sinA = vUniforms[effect ].x; // sin(A) precomputed in EffectListVertex.postprocess |
|
| 340 |
float cosA = vUniforms[effect+1].x; // cos(A) precomputed in EffectListVertex.postprocess |
|
| 339 |
|
|
| 340 |
float alpha = vUniforms[effect].x; |
|
| 341 |
float sinA = sin(alpha); |
|
| 342 |
float cosA = cos(alpha); |
|
| 343 |
|
|
| 341 | 344 |
vec2 PS2 = vec2( PS.x*cosA+PS.y*sinA,-PS.x*sinA+PS.y*cosA ); // vector PS rotated by A radians clockwise around center. |
| 342 | 345 |
vec4 SG = (1.0-d1_circle)*SO; // coordinates of the dilated circle P is going to get rotated around |
| 343 | 346 |
float d2 = max(0.0,degree(SG,center,PS2)); // make it a max(0,deg) because otherwise when center=left edge of the |
| ... | ... | |
| 401 | 404 |
// d) compute the above and see that this is equal precisely to SX from (**). |
| 402 | 405 |
// e) repeat points b,c,d in direction Y and come up with (***). |
| 403 | 406 |
// |
| 407 |
////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 404 | 408 |
// Note: we should avoid passing certain combinations of parameters to this function. One such known |
| 405 | 409 |
// combination is ( A: small but positive, B: any, amplitude >= length ). |
| 406 | 410 |
// In this case, certain 'unlucky' points have their normals almost horizontal (they got moved by (almost!) |
| ... | ... | |
| 421 | 425 |
|
| 422 | 426 |
if( deg != 0.0 && length != 0.0 ) |
| 423 | 427 |
{
|
| 424 |
float sinA = vUniforms[effect ].y; |
|
| 425 |
float cosA = vUniforms[effect+1].x; |
|
| 426 |
float sinB = vUniforms[effect ].w; |
|
| 427 |
float cosB = vUniforms[effect+1].y; |
|
| 428 |
float alpha = vUniforms[effect].y; |
|
| 429 |
float beta = vUniforms[effect].w; |
|
| 430 |
|
|
| 431 |
float sinA = sin(alpha); |
|
| 432 |
float cosA = cos(alpha); |
|
| 433 |
float sinB = sin(beta); |
|
| 434 |
float cosB = cos(beta); |
|
| 428 | 435 |
|
| 429 | 436 |
float angle= 1.578*(ps.x*cosB-ps.y*sinB) / length; |
| 430 | 437 |
|
Also available in: Unified diff
Switch off the pre-compulting of sin and cos in CPU as it turns out that those two are single-instruction functions on any modern GPU ( http://www.gamedev.net/topic/322422-number-of-gpu-cycles-for-cos-and-sin-functions/ - link form 2005 ! )