Revision 39b80df0
Added by Leszek Koltunski over 7 years ago
src/main/res/raw/main_vertex_shader.glsl | ||
---|---|---|
350 | 350 |
void wave(in int effect, inout vec4 v, inout vec4 n) |
351 | 351 |
{ |
352 | 352 |
vec2 center = vUniforms[effect+1].zw; |
353 |
float sinA = vUniforms[effect ].y; |
|
354 |
float cosA = vUniforms[effect+1].x; |
|
355 |
float sinB = vUniforms[effect ].w; |
|
356 |
float cosB = vUniforms[effect+1].y; |
|
357 | 353 |
float amplitude = vUniforms[effect ].x; |
358 | 354 |
float length = vUniforms[effect ].z; |
359 | 355 |
|
360 | 356 |
vec2 ps = center-v.xy; |
361 | 357 |
float deg = amplitude*degree_region(vUniforms[effect+2],ps); |
362 | 358 |
|
363 |
if( deg != 0.0 ) |
|
359 |
if( deg != 0.0 && length != 0.0 )
|
|
364 | 360 |
{ |
365 |
float angle = length==0.0 ? 0.0 : 1.578*(ps.x*cosB+ps.y*sinB) / length; |
|
366 |
v.xyz += sin(angle)*deg*vec3(sinB*cosA,cosB*cosA,sinA); |
|
361 |
float sinA = vUniforms[effect ].y; |
|
362 |
float cosA = vUniforms[effect+1].x; |
|
363 |
float sinB = vUniforms[effect ].w; |
|
364 |
float cosB = vUniforms[effect+1].y; |
|
365 |
|
|
366 |
float angle = 1.578*(ps.x*cosB+ps.y*sinB) / length; |
|
367 |
vec3 dir = vec3(sinB*cosA,cosB*cosA,sinA); |
|
368 |
|
|
369 |
v.xyz += sin(angle)*deg*dir; |
|
370 |
|
|
371 |
float sqrtX = sqrt(dir.y*dir.y + dir.z*dir.z); |
|
372 |
float sqrtY = sqrt(dir.x*dir.x + dir.z*dir.z); |
|
373 |
|
|
374 |
float sinX = ( sqrtX==0.0 ? 0.0 : dir.z / sqrtX); |
|
375 |
float cosX = ( sqrtX==0.0 ? 1.0 : dir.y / sqrtX); |
|
376 |
float sinY = ( sqrtY==0.0 ? 0.0 : dir.z / sqrtY); |
|
377 |
float cosY = ( sqrtY==0.0 ? 1.0 : dir.y / sqrtY); |
|
378 |
|
|
379 |
float tmp = 1.578*cos(angle)*deg/length; |
|
380 |
|
|
381 |
float fx = cosB*tmp; |
|
382 |
float fy = sinB*tmp; |
|
383 |
|
|
384 |
vec3 sx = vec3 (1.0+cosX*fx,cosY*sinX*fx,sinY*sinX*fx); |
|
385 |
vec3 sy = vec3 (cosX*sinY*fy,1.0+cosY*fy,sinX*sinY*fy); |
|
386 |
|
|
387 |
vec3 normal = cross(sx,sy); |
|
388 |
|
|
389 |
if( n.z != 0.0 ) |
|
390 |
{ |
|
391 |
n.xyz = n.z*normal; |
|
392 |
} |
|
367 | 393 |
} |
368 | 394 |
} |
369 | 395 |
|
Also available in: Unified diff
Shades of the WAVE effect (almost!) working.