vs_mesh.sc 809 B

1234567891011121314151617181920212223242526272829303132
  1. $input a_position, a_normal
  2. $output v_pos, v_view, v_normal, v_color0
  3. /*
  4. * Copyright 2011-2025 Branimir Karadzic. All rights reserved.
  5. * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE
  6. */
  7. #include "../common/common.sh"
  8. uniform vec4 u_time;
  9. void main()
  10. {
  11. vec3 pos = a_position;
  12. float sx = sin(pos.x*32.0+u_time.x*4.0)*0.5+0.5;
  13. float cy = cos(pos.y*32.0+u_time.x*4.0)*0.5+0.5;
  14. vec3 displacement = vec3(sx, cy, sx*cy);
  15. vec3 normal = a_normal.xyz*2.0 - 1.0;
  16. pos = pos + normal*displacement*vec3(0.06, 0.06, 0.06);
  17. gl_Position = mul(u_modelViewProj, vec4(pos, 1.0) );
  18. v_pos = gl_Position.xyz;
  19. v_view = mul(u_modelView, vec4(pos, 1.0) ).xyz;
  20. v_normal = mul(u_modelView, vec4(normal, 0.0) ).xyz;
  21. float len = length(displacement)*0.4+0.6;
  22. v_color0 = vec4(len, len, len, 1.0);
  23. }