vs_assao_gbuffer.sc 807 B

123456789101112131415161718192021222324252627
  1. $input a_position, a_normal, a_texcoord0
  2. $output v_normal, v_texcoord0
  3. /*
  4. * Copyright 2018 Attila Kocsis. All rights reserved.
  5. * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE
  6. */
  7. #include "../common/common.sh"
  8. void main()
  9. {
  10. // Calculate vertex position
  11. vec3 pos = a_position.xyz;
  12. gl_Position = mul(u_modelViewProj, vec4(pos, 1.0) );
  13. // Calculate normal. Note that compressed normal is stored in the vertices
  14. vec3 normalObjectSpace = a_normal.xyz*2.0+-1.0; // Normal is stored in [0,1], remap to [-1,1].
  15. // Transform normal into world space.
  16. vec3 normalWorldSpace = mul(u_model[0], vec4(normalObjectSpace, 0.0) ).xyz;
  17. // Normalize to remove (uniform...) scaling, however, recompress
  18. v_normal.xyz = normalize(normalWorldSpace)*0.5+0.5;
  19. v_texcoord0 = a_texcoord0 * 16.0;
  20. }