vs_rsm_gbuffer.sc 764 B

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