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.

79 lines
2.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. #include "tier0/platform.h"
  3. #include "mathlib/mathlib.h"
  4. #include "mathlib/spherical_geometry.h"
  5. #include "tier2/tier2.h"
  6. #include "mathlib/halton.h"
  7. #include "bitmap/float_bm.h"
  8. #include "tier0/memdbgon.h"
  9. void main(int argc,char **argv)
  10. {
  11. InitCommandLineProgram( argc, argv );
  12. // 1/8th of the sphere
  13. float a1=UnitSphereTriangleArea( Vector( 1, 0, 0 ), Vector( 0, 0, -1 ), Vector( 0, 1, 0 ) );
  14. printf( "right spherical triangle projected percentage=%2.4f\n", a1 / ( 4 * M_PI ));
  15. // a small one
  16. Vector v1 = Vector( 1, 0, 0 );
  17. Vector v2 = v1 + Vector( 0, 0.2, 0 );
  18. Vector v3 = v1 + Vector( 0, 0, 0.2 );
  19. v2.NormalizeInPlace();
  20. v3.NormalizeInPlace();
  21. float a2=UnitSphereTriangleArea( v1, v2, v3 );
  22. printf( "small spherical triangle projected percentage=%2.5f\n", a2 / ( 4* M_PI ) );
  23. // now, create a cubemap and sum the area of each of its cells
  24. FloatCubeMap_t envMap( 10, 10 );
  25. float flAreaSum = 0.;
  26. for( int nFace = 0 ; nFace < 6; nFace ++ )
  27. {
  28. for( int nY = 0 ; nY < 9; nY++ )
  29. for( int nX = 0 ; nX < 9; nX++ )
  30. {
  31. Vector v00 = envMap.PixelDirection( nFace, nX, nY );
  32. Vector v01 = envMap.PixelDirection( nFace, nX, nY + 1 );
  33. Vector v10 = envMap.PixelDirection( nFace, nX + 1, nY );
  34. Vector v11 = envMap.PixelDirection( nFace, nX + 1 , nY + 1 );
  35. v00.NormalizeInPlace();
  36. v01.NormalizeInPlace();
  37. v10.NormalizeInPlace();
  38. v11.NormalizeInPlace();
  39. flAreaSum += UnitSphereTriangleArea( v00, v01, v10 );
  40. flAreaSum += UnitSphereTriangleArea( v10, v11, v01 );
  41. }
  42. }
  43. printf( "sum of areas of cubemap cells = %2.2f\n", flAreaSum / ( 4.0 * M_PI ) );
  44. #if 0 // visual spherical harmonics as (confusing) point sets
  45. // spherical harmonics
  46. DirectionalSampler_t sampler;
  47. for(int i = 0 ; i < 50000; i++ )
  48. {
  49. Vector dir=sampler.NextValue();
  50. float SH = SphericalHarmonic( 4, 3, dir );
  51. float r=0;
  52. float g=1; //0.5+0.5*DotProduct( dir, Vector( 0, 0, 1 ) );
  53. float b=0;
  54. if ( SH < 0 )
  55. {
  56. SH = -SH;
  57. r=g;
  58. g=0;
  59. }
  60. r *= SH;
  61. g *= SH;
  62. b *= SH;
  63. float rad= SH * 4.0; //4.0; //SH *= 8.0;
  64. printf( "2\n" );
  65. printf( "%f %f %f %f %f %f\n",
  66. dir.x * rad, dir.y * rad, dir.z * rad, r, g, b );
  67. rad += 0.03;
  68. printf( "%f %f %f %f %f %f\n",
  69. dir.x * rad, dir.y * rad, dir.z * rad, r, g, b );
  70. }
  71. #endif
  72. }