MLRPrimitiveLighting.hpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. Verify(colors.GetLength() == litColors.GetLength());
  31. Verify(normals.GetLength() == colors.GetLength());
  32. Verify(coords.GetLength() == colors.GetLength());
  33. int i, k, len = colors.GetLength();
  34. MLRVertexData vertexData;
  35. #if COLOR_AS_DWORD
  36. TO_DO;
  37. #else
  38. RGBAColor *color = &colors[0];
  39. #endif
  40. //
  41. //--------------------------------
  42. // Now light the array of vertices
  43. //--------------------------------
  44. //
  45. vertexData.point = &coords[0];
  46. vertexData.color = &litColors[0];
  47. vertexData.normal = &normals[0];
  48. for(k=0;k<len;k++)
  49. {
  50. if(visibleIndexedVertices[k] != 0)
  51. {
  52. vertexData.color->red = 0.0f;
  53. vertexData.color->green = 0.0f;
  54. vertexData.color->blue = 0.0f;
  55. vertexData.color->alpha = color->alpha;
  56. for (i=0;i<nrLights;i++)
  57. {
  58. MLRLight *light = lights[i];
  59. Check_Object(light);
  60. int mask = state_mask & light->GetLightMask();
  61. if (!mask)
  62. continue;
  63. if (mask&MLRState::VertexLightingMode)
  64. {
  65. if (
  66. GetCurrentState().GetBackFaceMode() != MLRState::BackFaceOffMode
  67. || light->GetLightType() == MLRLight::AmbientLight
  68. )
  69. {
  70. light->LightVertex(vertexData);
  71. Set_Statistic(LitVertices, LitVertices+1);
  72. }
  73. }
  74. }
  75. }
  76. vertexData.point++;
  77. vertexData.color++;
  78. vertexData.normal++;
  79. color++;
  80. }
  81. actualColors = &litColors;
  82. }
  83. }