Leaked source code of windows server 2003
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.

83 lines
3.4 KiB

  1. /*============================ ==============================================;
  2. *
  3. * Copyright (C) 1998 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: pvvid.h
  6. * Content: Common defines for the geometry inner loop
  7. *
  8. ***************************************************************************/
  9. #ifndef _PVVID_H
  10. #define _PVVID_H
  11. #include "clipper.h"
  12. // This function should be called every time FVF ID is changed
  13. // All pv flags, input and output FVF id should be set before calling the
  14. // function.
  15. extern void UpdateGeometryLoopData(LPD3DFE_PROCESSVERTICES pv);
  16. // We use power of 2 because it preserves the mantissa when we multiply
  17. const D3DVALUE __HUGE_PWR2 = 1024.0f*1024.0f*2.0f;
  18. //--------------------------------------------------------------------------
  19. #define D3DFE_SET_ALPHA(color, a) ((char*)&color)[3] = (unsigned char)a;
  20. //--------------------------------------------------------------------------
  21. inline void ComputeFogFactor(LPD3DFE_PROCESSVERTICES pv, D3DVALUE dist, DWORD *pOutput)
  22. {
  23. if (pv->lighting.fog_mode == D3DFOG_LINEAR)
  24. {
  25. if (dist < pv->lighting.fog_start)
  26. D3DFE_SET_ALPHA((*pOutput), 255)
  27. else
  28. if (dist >= pv->lighting.fog_end)
  29. D3DFE_SET_ALPHA((*pOutput), 0)
  30. else
  31. {
  32. D3DVALUE v = (pv->lighting.fog_end - dist) * pv->lighting.fog_factor;
  33. int f = FTOI(v);
  34. D3DFE_SET_ALPHA((*pOutput), f)
  35. }
  36. }
  37. else
  38. {
  39. D3DVALUE tmp = dist*pv->lighting.fog_density;
  40. if (pv->lighting.fog_mode == D3DFOG_EXP2)
  41. {
  42. tmp *= tmp;
  43. }
  44. tmp = (D3DVALUE)exp(-tmp) * 255.0f;
  45. int f = FTOI(tmp);
  46. D3DFE_SET_ALPHA((*pOutput), f)
  47. }
  48. }
  49. //--------------------------------------------------------------------------
  50. // Input:
  51. // v - input vertex in the model space
  52. // le - vertex, transformed to the camera space
  53. // Output:
  54. // Alpha component of pv->lighting.outSpecular is set
  55. //
  56. void ComputeFog(LPD3DFE_PROCESSVERTICES pv, D3DVECTOR &v, D3DLIGHTINGELEMENT *le);
  57. //---------------------------------------------------------------------
  58. typedef void (*PFN_TEXTURETRANSFORM)(D3DVALUE *pIn, D3DVALUE *pOut, D3DMATRIXI *m);
  59. typedef void (*PFN_TEXTURETRANSFORMLOOP)(D3DVALUE *pIn, D3DVALUE *pOut, D3DMATRIXI *m,
  60. DWORD dwCount, DWORD dwInpStride, DWORD dwOutStride);
  61. extern PFN_TEXTURETRANSFORM g_pfnTextureTransform[16];
  62. extern PFN_TEXTURETRANSFORMLOOP g_pfnTextureTransformLoop[16];
  63. //---------------------------------------------------------------------
  64. inline void ComputeReflectionVector(D3DVECTOR *vertexPosition, D3DVECTOR *normal, D3DVECTOR *reflectionVector)
  65. {
  66. D3DVECTOR vertex = *vertexPosition;
  67. VecNormalizeFast(vertex);
  68. D3DVALUE dot = 2*(vertex.x * normal->x + vertex.y * normal->y + vertex.z * normal->z);
  69. reflectionVector->x = vertex.x - dot*normal->x;
  70. reflectionVector->y = vertex.y - dot*normal->y;
  71. reflectionVector->z = vertex.z - dot*normal->z;
  72. }
  73. //---------------------------------------------------------------------
  74. inline void ComputeReflectionVectorInfiniteViewer(D3DVECTOR *normal, D3DVECTOR *reflectionVector)
  75. {
  76. D3DVALUE dot = 2*normal->z;
  77. reflectionVector->x = - dot*normal->x;
  78. reflectionVector->y = - dot*normal->y;
  79. reflectionVector->z = 1.0f - dot*normal->z;
  80. }
  81. #endif // _PVVID_H