Project

General

Profile

« Previous | Next » 

Revision 57297c51

Added by Leszek Koltunski over 7 years ago

Correct one more issue with computation of WAVE.

View differences:

src/main/res/raw/main_vertex_shader.glsl
361 361
//
362 362
// Also, in this case f(x,y) = amplitude*sin(x/length), with those 2 parameters passed in uniforms.
363 363
//
364
////////////////////////////////////////////////////////
364
//////////////////////////////////////////////////////////////////////////////////////////////
365 365
// How to compute any generic effect of type (*)
366
////////////////////////////////////////////////////////
366
//////////////////////////////////////////////////////////////////////////////////////////////
367 367
//
368 368
// By definition, the vertices move by f(x,y)*V.
369 369
//
370 370
// Normals are much more complicated.
371
// Let angle X be the angle (0,Vy,Vz)((0,Vy,0)(Vx,Vy,Vz).
372
// Let angle Y be the angle (Vx,0,Vz)((Vx,0,0)(Vx,Vy,Vz).
371
// Let angle X be the angle (0,Vy,Vz)(0,Vy,0)(Vx,Vy,Vz).
372
// Let angle Y be the angle (Vx,0,Vz)(Vx,0,0)(Vx,Vy,Vz).
373 373
//
374 374
// Then it can be shown that the resulting surface, at point to which point (x0,y0,0) got moved to,
375 375
// has 2 tangent vectors given by
......
417 417
    float sinB = vUniforms[effect  ].w;
418 418
    float cosB = vUniforms[effect+1].y;
419 419

  
420
    float angle= 1.578*(-ps.x*cosB-ps.y*sinB) / length;  // -ps.x and -ps.y because the 'ps=center-v.xy' inverts the XY axis!
420
    float angle= 1.578*(ps.x*cosB-ps.y*sinB) / length;
421

  
421 422
    vec3 dir   = vec3(sinB*cosA,cosB*cosA,sinA);
422 423

  
423 424
    v.xyz += sin(angle)*deg*dir;
......
432 433
      float sinY = ( sqrtX==0.0 ? 0.0 : dir.z / sqrtX);
433 434
      float cosY = ( sqrtX==0.0 ? 1.0 : dir.y / sqrtX);
434 435

  
435
      float absSinX = sinX<0.0 ? -sinX:sinX;
436
      float absSinY = sinY<0.0 ? -sinY:sinY;
436
      float abs_z = dir.z <0.0 ? -(sinX*sinY) : (sinX*sinY);
437 437

  
438 438
      float tmp = 1.578*cos(angle)*deg/length;
439 439

  
440
      float fx = cosB*tmp;
440
      float fx =-cosB*tmp;
441 441
      float fy = sinB*tmp;
442 442

  
443
      vec3 sx = vec3 (1.0+cosX*fx,cosY*sinX*fx,absSinY*sinX*fx);
444
      vec3 sy = vec3 (cosX*sinY*fy,1.0+cosY*fy,absSinX*sinY*fy);
443
      vec3 sx = vec3 (1.0+cosX*fx,cosY*sinX*fx,abs_z*fx);
444
      vec3 sy = vec3 (cosX*sinY*fy,1.0+cosY*fy,abs_z*fy);
445 445

  
446 446
      vec3 normal = cross(sx,sy);
447 447

  
448 448
      if( normal.z > 0.0 )
449 449
        {
450
        n.xy += (n.z/normal.z)*vec2(normal.x,normal.y);
450
        n.x = (n.x*normal.z + n.z*normal.x);
451
        n.y = (n.y*normal.z + n.z*normal.y);
452
        n.z = (n.z*normal.z);
451 453
        }
452 454
      }
453 455
    }

Also available in: Unified diff