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.

87 lines
3.6 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. // Set stride pointers for non-strided case
  17. extern void SetupStrides(D3DFE_PROCESSVERTICES* pv, UINT stride);
  18. // We use power of 2 because it preserves the mantissa when we multiply
  19. const D3DVALUE __HUGE_PWR2 = 1024.0f*1024.0f*2.0f;
  20. //--------------------------------------------------------------------------
  21. #define D3DFE_SET_ALPHA(color, a) ((char*)&color)[3] = (unsigned char)a;
  22. //--------------------------------------------------------------------------
  23. inline void ComputeFogFactor(LPD3DFE_PROCESSVERTICES pv, D3DVALUE dist, DWORD *pOutput)
  24. {
  25. if (pv->lighting.fog_mode == D3DFOG_LINEAR)
  26. {
  27. if (dist < pv->lighting.fog_start)
  28. D3DFE_SET_ALPHA((*pOutput), 255)
  29. else
  30. if (dist >= pv->lighting.fog_end)
  31. D3DFE_SET_ALPHA((*pOutput), 0)
  32. else
  33. {
  34. D3DVALUE v = (pv->lighting.fog_end - dist) * pv->lighting.fog_factor;
  35. int f = FTOI(v);
  36. D3DFE_SET_ALPHA((*pOutput), f)
  37. }
  38. }
  39. else
  40. {
  41. D3DVALUE tmp = dist*pv->lighting.fog_density;
  42. if (pv->lighting.fog_mode == D3DFOG_EXP2)
  43. {
  44. tmp *= tmp;
  45. }
  46. tmp = (D3DVALUE)exp(-tmp) * 255.0f;
  47. int f = FTOI(tmp);
  48. D3DFE_SET_ALPHA((*pOutput), f)
  49. }
  50. }
  51. //--------------------------------------------------------------------------
  52. // Input:
  53. // v - input vertex in the model space
  54. // pCoord - vertex, transformed to the camera space
  55. // pWeights - pointer to the vertex weights
  56. // Output:
  57. // Alpha component of pv->lighting.outSpecular is set
  58. //
  59. void ComputeFog(LPD3DFE_PROCESSVERTICES pv, D3DVECTOR &v, D3DVECTOR* pCoord,
  60. D3DVALUE* pWeights, BYTE* pMatrixIndices);
  61. //---------------------------------------------------------------------
  62. typedef void (*PFN_TEXTURETRANSFORM)(D3DVALUE *pIn, D3DVALUE *pOut, D3DMATRIXI *m);
  63. typedef void (*PFN_TEXTURETRANSFORMLOOP)(D3DVALUE *pIn, D3DVALUE *pOut, D3DMATRIXI *m,
  64. DWORD dwCount, DWORD dwInpStride, DWORD dwOutStride);
  65. extern PFN_TEXTURETRANSFORM g_pfnTextureTransform[16];
  66. extern PFN_TEXTURETRANSFORMLOOP g_pfnTextureTransformLoop[16];
  67. //---------------------------------------------------------------------
  68. inline void ComputeReflectionVector(D3DVECTOR *vertexPosition, D3DVECTOR *normal, D3DVECTOR *reflectionVector)
  69. {
  70. D3DVECTOR vertex = *vertexPosition;
  71. VecNormalizeFast(vertex);
  72. D3DVALUE dot = 2*(vertex.x * normal->x + vertex.y * normal->y + vertex.z * normal->z);
  73. reflectionVector->x = vertex.x - dot*normal->x;
  74. reflectionVector->y = vertex.y - dot*normal->y;
  75. reflectionVector->z = vertex.z - dot*normal->z;
  76. }
  77. //---------------------------------------------------------------------
  78. inline void ComputeReflectionVectorInfiniteViewer(D3DVECTOR *normal, D3DVECTOR *reflectionVector)
  79. {
  80. D3DVALUE dot = 2*normal->z;
  81. reflectionVector->x = - dot*normal->x;
  82. reflectionVector->y = - dot*normal->y;
  83. reflectionVector->z = 1.0f - dot*normal->z;
  84. }
  85. #endif // _PVVID_H