sceneData.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _SCENEDATA_H_
  23. #define _SCENEDATA_H_
  24. #ifndef _SCENERENDERSTATE_H_
  25. #include "scene/sceneRenderState.h"
  26. #endif
  27. #ifndef _LIGHTMANAGER_H_
  28. #include "lighting/lightManager.h"
  29. #endif
  30. #ifndef _GFXDEVICE_H_
  31. #include "gfx/gfxDevice.h"
  32. #endif
  33. class GFXTexHandle;
  34. class GFXCubemap;
  35. struct CustomShaderBindingData;
  36. struct SceneData
  37. {
  38. /// The special bin types.
  39. enum BinType
  40. {
  41. /// A normal render bin that isn't one of
  42. /// the special bins we care about.
  43. RegularBin = 0,
  44. /// The deferred render bin.
  45. /// @RenderDeferredMgr
  46. DeferredBin,
  47. /// The selection-highlight render bin.
  48. /// @afxRenderHighlightMgr
  49. HighlightBin,
  50. };
  51. enum
  52. {
  53. MAX_LIGHTS = 8
  54. };
  55. /// This defines when we're rendering a special bin
  56. /// type that the material or lighting system needs
  57. /// to know about.
  58. BinType binType;
  59. // textures
  60. GFXTextureObject *lightmap;
  61. GFXTextureObject *backBuffTex;
  62. GFXTextureObject *reflectTex;
  63. GFXTextureObject *miscTex;
  64. GFXTextureObject *accuTex;
  65. /// The current lights to use in rendering
  66. /// in order of the light importance.
  67. LightInfo* lights[MAX_LIGHTS];
  68. ///
  69. LinearColorF ambientLightColor;
  70. // fog
  71. F32 fogDensity;
  72. F32 fogDensityOffset;
  73. F32 fogHeightFalloff;
  74. LinearColorF fogColor;
  75. // misc
  76. const MatrixF *objTrans;
  77. GFXCubemap *cubemap;
  78. F32 visibility;
  79. /// Enables wireframe rendering for the object.
  80. bool wireframe;
  81. /// A generic hint value passed from the game
  82. /// code down to the material for use by shader
  83. /// features.
  84. void *materialHint;
  85. Vector<CustomShaderBindingData*> customShaderData;
  86. /// Constructor.
  87. SceneData()
  88. {
  89. accuTex = NULL;
  90. backBuffTex = NULL;
  91. binType = RegularBin;
  92. cubemap = NULL;
  93. fogDensity = 0.0f;
  94. fogDensityOffset = 0.0f;
  95. fogHeightFalloff = 0.0f;
  96. lightmap = NULL;
  97. for (U32 i = 0; i < MAX_LIGHTS; i++)
  98. {
  99. lights[i] = NULL;
  100. }
  101. materialHint = NULL;
  102. miscTex = NULL;
  103. reflectTex = NULL;
  104. wireframe = false;
  105. objTrans = &MatrixF::Identity;
  106. visibility = 1.0f;
  107. }
  108. /// Initializes the data with the scene state setting
  109. /// common scene wide parameters.
  110. inline void init( const SceneRenderState *state, BinType type = RegularBin )
  111. {
  112. dMemset( this, 0, sizeof( SceneData ) );
  113. setFogParams( state->getSceneManager()->getFogData() );
  114. wireframe = GFXDevice::getWireframe();
  115. binType = type;
  116. objTrans = &MatrixF::Identity;
  117. visibility = 1.0f;
  118. ambientLightColor = state->getAmbientLightColor();
  119. }
  120. inline void setFogParams( const FogData &data )
  121. {
  122. fogDensity = data.density;
  123. fogDensityOffset = data.densityOffset;
  124. if ( !mIsZero( data.atmosphereHeight ) )
  125. fogHeightFalloff = 1.0f / data.atmosphereHeight;
  126. else
  127. fogHeightFalloff = 0.0f;
  128. fogColor = data.color;
  129. }
  130. };
  131. #endif // _SCENEDATA_H_