vs_bump.sc 1000 B

1234567891011121314151617181920212223242526272829303132333435
  1. $input a_position, a_normal, a_tangent, a_texcoord0
  2. $output v_wpos, v_view, v_normal, v_tangent, v_bitangent, v_texcoord0
  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. void main()
  9. {
  10. vec3 wpos = mul(u_model[0], vec4(a_position, 1.0) ).xyz;
  11. v_wpos = wpos;
  12. gl_Position = mul(u_viewProj, vec4(wpos, 1.0) );
  13. vec4 normal = a_normal * 2.0 - 1.0;
  14. vec4 tangent = a_tangent * 2.0 - 1.0;
  15. vec3 wnormal = mul(u_model[0], vec4(normal.xyz, 0.0) ).xyz;
  16. vec3 wtangent = mul(u_model[0], vec4(tangent.xyz, 0.0) ).xyz;
  17. v_normal = normalize(wnormal);
  18. v_tangent = normalize(wtangent);
  19. v_bitangent = cross(v_normal, v_tangent) * tangent.w;
  20. mat3 tbn = mtxFromCols(v_tangent, v_bitangent, v_normal);
  21. // eye position in world space
  22. vec3 weyepos = mul(vec4(0.0, 0.0, 0.0, 1.0), u_view).xyz;
  23. // tangent space view dir
  24. v_view = mul(weyepos - wpos, tbn);
  25. v_texcoord0 = a_texcoord0;
  26. }