boxEnvironmentProbe.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. #include "T3D/lighting/boxEnvironmentProbe.h"
  23. #include "math/mathIO.h"
  24. #include "scene/sceneRenderState.h"
  25. #include "console/consoleTypes.h"
  26. #include "core/stream/bitStream.h"
  27. #include "materials/baseMatInstance.h"
  28. #include "console/engineAPI.h"
  29. #include "gfx/gfxDrawUtil.h"
  30. #include "gfx/gfxDebugEvent.h"
  31. #include "gfx/gfxTransformSaver.h"
  32. #include "math/mathUtils.h"
  33. #include "gfx/bitmap/gBitmap.h"
  34. #include "core/stream/fileStream.h"
  35. #include "core/fileObject.h"
  36. #include "core/resourceManager.h"
  37. #include "console/simPersistID.h"
  38. #include "T3D/gameFunctions.h"
  39. #include "postFx/postEffect.h"
  40. #include "renderInstance/renderProbeMgr.h"
  41. #include "renderInstance/renderProbeMgr.h"
  42. #include "math/util/sphereMesh.h"
  43. #include "materials/materialManager.h"
  44. #include "math/util/matrixSet.h"
  45. #include "gfx/bitmap/cubemapSaver.h"
  46. #include "materials/materialFeatureTypes.h"
  47. #include "materials/shaderData.h"
  48. #include "gfx/gfxTextureManager.h"
  49. #include "gfx/bitmap/imageUtils.h"
  50. #include "T3D/lighting/IBLUtilities.h"
  51. extern bool gEditingMission;
  52. extern ColorI gCanvasClearColor;
  53. IMPLEMENT_CO_NETOBJECT_V1(BoxEnvironmentProbe);
  54. ConsoleDocClass(BoxEnvironmentProbe,
  55. "@brief An example scene object which renders a mesh.\n\n"
  56. "This class implements a basic SceneObject that can exist in the world at a "
  57. "3D position and render itself. There are several valid ways to render an "
  58. "object in Torque. This class implements the preferred rendering method which "
  59. "is to submit a MeshRenderInst along with a Material, vertex buffer, "
  60. "primitive buffer, and transform and allow the RenderMeshMgr handle the "
  61. "actual setup and rendering for you.\n\n"
  62. "See the C++ code for implementation details.\n\n"
  63. "@ingroup Examples\n");
  64. //-----------------------------------------------------------------------------
  65. // Object setup and teardown
  66. //-----------------------------------------------------------------------------
  67. BoxEnvironmentProbe::BoxEnvironmentProbe() : ReflectionProbe()
  68. {
  69. mCaptureMask = REFLECTION_PROBE_CAPTURE_TYPEMASK;
  70. mProbeShapeType = ProbeInfo::Box;
  71. mAtten = 0.0;
  72. }
  73. BoxEnvironmentProbe::~BoxEnvironmentProbe()
  74. {
  75. }
  76. //-----------------------------------------------------------------------------
  77. // Object Editing
  78. //-----------------------------------------------------------------------------
  79. void BoxEnvironmentProbe::initPersistFields()
  80. {
  81. // SceneObject already handles exposing the transform
  82. Parent::initPersistFields();
  83. addField("attenuation", TypeF32, Offset(mAtten, BoxEnvironmentProbe), "falloff percent");
  84. removeField("radius");
  85. }
  86. void BoxEnvironmentProbe::inspectPostApply()
  87. {
  88. Parent::inspectPostApply();
  89. mDirty = true;
  90. // Flag the network mask to send the updates
  91. // to the client object
  92. setMaskBits(-1);
  93. }
  94. bool BoxEnvironmentProbe::onAdd()
  95. {
  96. if (!Parent::onAdd())
  97. return false;
  98. return true;
  99. }
  100. void BoxEnvironmentProbe::onRemove()
  101. {
  102. Parent::onRemove();
  103. }
  104. U32 BoxEnvironmentProbe::packUpdate(NetConnection *conn, U32 mask, BitStream *stream)
  105. {
  106. // Allow the Parent to get a crack at writing its info
  107. U32 retMask = Parent::packUpdate(conn, mask, stream);
  108. if (stream->writeFlag(mask & StaticDataMask))
  109. {
  110. stream->write(mAtten);
  111. }
  112. return retMask;
  113. }
  114. void BoxEnvironmentProbe::unpackUpdate(NetConnection *conn, BitStream *stream)
  115. {
  116. // Let the Parent read any info it sent
  117. Parent::unpackUpdate(conn, stream);
  118. if (stream->readFlag()) // StaticDataMask
  119. {
  120. stream->read(&mAtten);
  121. mDirty = true;
  122. }
  123. if (mDirty)
  124. {
  125. updateProbeParams();
  126. }
  127. }
  128. //-----------------------------------------------------------------------------
  129. // Object Rendering
  130. //-----------------------------------------------------------------------------
  131. void BoxEnvironmentProbe::updateProbeParams()
  132. {
  133. mProbeShapeType = ProbeInfo::Box;
  134. mProbeInfo.mAtten = mAtten;
  135. Parent::updateProbeParams();
  136. }
  137. void BoxEnvironmentProbe::setPreviewMatParameters(SceneRenderState* renderState, BaseMatInstance* mat)
  138. {
  139. Parent::setPreviewMatParameters(renderState, mat);
  140. }