MLRTriangleLighting.hpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. //===========================================================================//
  2. // Copyright (C) Microsoft Corporation. All rights reserved. //
  3. //===========================================================================//
  4. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  5. //
  6. void
  7. CLASSNAME::Lighting (
  8. MLRLight* const* lights,
  9. int nrLights
  10. )
  11. {
  12. Check_Object(this);
  13. //
  14. //----------------------------------------------------------------------
  15. // If no lights or normals are specified, use the original vertex colors
  16. //----------------------------------------------------------------------
  17. //
  18. actualColors = &colors;
  19. int state_mask = GetCurrentState().GetLightingMode();
  20. if (nrLights == 0 || normals.GetLength() == 0 || state_mask == MLRState::LightingOffMode)
  21. return;
  22. Check_Pointer(lights);
  23. //
  24. //-------------------------------
  25. // See if we need vertex lighting
  26. //-------------------------------
  27. //
  28. if (state_mask & MLRState::VertexLightingMode)
  29. {
  30. Start_Timer(Vertex_Light_Time);
  31. Verify(colors.GetLength() == litColors.GetLength());
  32. Verify(normals.GetLength() == colors.GetLength());
  33. Verify(coords.GetLength() == colors.GetLength());
  34. int i, k, len = colors.GetLength();
  35. MLRVertexData vertexData;
  36. #if COLOR_AS_DWORD
  37. TO_DO;
  38. #else
  39. RGBAColor *color = &colors[0];
  40. #endif
  41. //
  42. //--------------------------------
  43. // Now light the array of vertices
  44. //--------------------------------
  45. //
  46. vertexData.point = &coords[0];
  47. vertexData.color = &litColors[0];
  48. vertexData.normal = &normals[0];
  49. for(k=0;k<len;k++)
  50. {
  51. if(visibleIndexedVertices[k] != 0)
  52. {
  53. vertexData.color->red = 0.0f;
  54. vertexData.color->green = 0.0f;
  55. vertexData.color->blue = 0.0f;
  56. vertexData.color->alpha = color->alpha;
  57. for (i=0;i<nrLights;i++)
  58. {
  59. MLRLight *light = lights[i];
  60. Check_Object(light);
  61. int mask = state_mask & light->GetLightMask();
  62. if (!mask)
  63. continue;
  64. if (mask&MLRState::VertexLightingMode)
  65. {
  66. if (
  67. GetCurrentState().GetBackFaceMode() != MLRState::BackFaceOffMode
  68. || light->GetLightType() == MLRLight::AmbientLight
  69. )
  70. {
  71. light->LightVertex(vertexData);
  72. Set_Statistic(LitVertices, LitVertices+1);
  73. }
  74. }
  75. }
  76. vertexData.color->red *= color->red;
  77. vertexData.color->green *= color->green;
  78. vertexData.color->blue *= color->blue;
  79. vertexData.color->alpha *= color->alpha;
  80. }
  81. vertexData.point++;
  82. vertexData.color++;
  83. vertexData.normal++;
  84. color++;
  85. }
  86. actualColors = &litColors;
  87. Stop_Timer(Vertex_Light_Time);
  88. }
  89. if (state_mask & MLRState::LightMapLightingMode)
  90. {
  91. Start_Timer(LightMap_Light_Time);
  92. int i;
  93. for (i=0;i<nrLights;i++)
  94. {
  95. MLRLight *light = lights[i];
  96. Check_Object(light);
  97. MLRLightMap *lm = light->GetLightMap();
  98. if(lm==NULL)
  99. {
  100. continue;
  101. }
  102. // Verify(state.GetAlphaMode() == MLRState::OneZeroMode);
  103. int mask = state_mask & light->GetLightMask();
  104. if (!mask)
  105. continue;
  106. if (mask & MLRState::LightMapLightingMode)
  107. {
  108. LightMapLighting(lights[i]);
  109. }
  110. }
  111. Stop_Timer(LightMap_Light_Time);
  112. }
  113. }