sceneData.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. class 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 glow render bin.
  45. /// @see RenderGlowMgr
  46. GlowBin,
  47. /// The deferred render bin.
  48. /// @RenderDeferredMgr
  49. DeferredBin,
  50. /// The selection-highlight render bin.
  51. /// @afxRenderHighlightMgr
  52. HighlightBin,
  53. };
  54. enum
  55. {
  56. MAX_LIGHTS = 8
  57. };
  58. /// This defines when we're rendering a special bin
  59. /// type that the material or lighting system needs
  60. /// to know about.
  61. BinType binType;
  62. // textures
  63. GFXTextureObject *lightmap;
  64. GFXTextureObject *backBuffTex;
  65. GFXTextureObject *reflectTex;
  66. GFXTextureObject *miscTex;
  67. GFXTextureObject *accuTex;
  68. /// The current lights to use in rendering
  69. /// in order of the light importance.
  70. LightInfo* lights[MAX_LIGHTS];
  71. ///
  72. LinearColorF ambientLightColor;
  73. // fog
  74. F32 fogDensity;
  75. F32 fogDensityOffset;
  76. F32 fogHeightFalloff;
  77. LinearColorF fogColor;
  78. // misc
  79. const MatrixF *objTrans;
  80. GFXCubemap *cubemap;
  81. F32 visibility;
  82. /// Enables wireframe rendering for the object.
  83. bool wireframe;
  84. /// A generic hint value passed from the game
  85. /// code down to the material for use by shader
  86. /// features.
  87. void *materialHint;
  88. Vector<CustomShaderBindingData*> customShaderData;
  89. /// Constructor.
  90. SceneData()
  91. {
  92. accuTex = NULL;
  93. backBuffTex = NULL;
  94. binType = RegularBin;
  95. cubemap = NULL;
  96. fogDensity = 0.0f;
  97. fogDensityOffset = 0.0f;
  98. fogHeightFalloff = 0.0f;
  99. lightmap = NULL;
  100. for (U32 i = 0; i < MAX_LIGHTS; i++)
  101. {
  102. lights[i] = NULL;
  103. }
  104. materialHint = NULL;
  105. miscTex = NULL;
  106. reflectTex = NULL;
  107. wireframe = false;
  108. objTrans = &MatrixF::Identity;
  109. visibility = 1.0f;
  110. }
  111. /// Initializes the data with the scene state setting
  112. /// common scene wide parameters.
  113. inline void init( const SceneRenderState *state, BinType type = RegularBin )
  114. {
  115. dMemset( this, 0, sizeof( SceneData ) );
  116. setFogParams( state->getSceneManager()->getFogData() );
  117. wireframe = GFXDevice::getWireframe();
  118. binType = type;
  119. objTrans = &MatrixF::Identity;
  120. visibility = 1.0f;
  121. ambientLightColor = state->getAmbientLightColor();
  122. }
  123. inline void setFogParams( const FogData &data )
  124. {
  125. fogDensity = data.density;
  126. fogDensityOffset = data.densityOffset;
  127. if ( !mIsZero( data.atmosphereHeight ) )
  128. fogHeightFalloff = 1.0f / data.atmosphereHeight;
  129. else
  130. fogHeightFalloff = 0.0f;
  131. fogColor = data.color;
  132. }
  133. };
  134. #endif // _SCENEDATA_H_