Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
1.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Workfile: $
  6. // $Date: $
  7. //
  8. //-----------------------------------------------------------------------------
  9. // $Log: $
  10. //
  11. // $NoKeywords: $
  12. //=============================================================================//
  13. #if !defined(_STATIC_LINKED) || defined(_SHARED_LIB)
  14. #ifdef QUIVER
  15. #include "r_local.h"
  16. #endif
  17. #include "mathlib/bumpvects.h"
  18. #include "mathlib/vector.h"
  19. #include <assert.h>
  20. // memdbgon must be the last include file in a .cpp file!!!
  21. #include "tier0/memdbgon.h"
  22. // z is coming out of the face.
  23. void GetBumpNormals( const Vector& sVect, const Vector& tVect, const Vector& flatNormal,
  24. const Vector& phongNormal, Vector bumpNormals[NUM_BUMP_VECTS] )
  25. {
  26. Vector tmpNormal;
  27. bool leftHanded;
  28. int i;
  29. assert( NUM_BUMP_VECTS == 3 );
  30. // Are we left or right handed?
  31. CrossProduct( sVect, tVect, tmpNormal );
  32. if( DotProduct( flatNormal, tmpNormal ) < 0.0f )
  33. {
  34. leftHanded = true;
  35. }
  36. else
  37. {
  38. leftHanded = false;
  39. }
  40. // Build a basis for the face around the phong normal
  41. matrix3x4_t smoothBasis;
  42. CrossProduct( phongNormal.Base(), sVect.Base(), smoothBasis[1] );
  43. VectorNormalize( smoothBasis[1] );
  44. CrossProduct( smoothBasis[1], phongNormal.Base(), smoothBasis[0] );
  45. VectorNormalize( smoothBasis[0] );
  46. VectorCopy( phongNormal.Base(), smoothBasis[2] );
  47. if( leftHanded )
  48. {
  49. VectorNegate( smoothBasis[1] );
  50. }
  51. // move the g_localBumpBasis into world space to create bumpNormals
  52. for( i = 0; i < 3; i++ )
  53. {
  54. VectorIRotate( g_localBumpBasis[i], smoothBasis, bumpNormals[i] );
  55. }
  56. }
  57. #endif // !_STATIC_LINKED || _SHARED_LIB