skySphere.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 _SKYSPHERE_H_
  23. #define _SKYSPHERE_H_
  24. #ifndef _SCENEOBJECT_H_
  25. #include "scene/sceneObject.h"
  26. #endif
  27. #ifndef _GFXDEVICE_H_
  28. #include "gfx/gfxDevice.h"
  29. #endif
  30. #ifndef _CUBEMAPDATA_H_
  31. #include "gfx/sim/cubemapData.h"
  32. #endif
  33. #ifndef _MATERIALLIST_H_
  34. #include "materials/materialList.h"
  35. #endif
  36. #ifndef _GFXVERTEXBUFFER_H_
  37. #include "gfx/gfxVertexBuffer.h"
  38. #endif
  39. #ifndef _GFXPRIMITIVEBUFFER_H_
  40. #include "gfx/gfxPrimitiveBuffer.h"
  41. #endif
  42. #include "T3D/assets/MaterialAsset.h"
  43. struct SkyMatParams
  44. {
  45. void init(BaseMatInstance* matInst) {};
  46. };
  47. class MatrixSet;
  48. class SkySphere : public SceneObject
  49. {
  50. typedef SceneObject Parent;
  51. public:
  52. SkySphere();
  53. virtual ~SkySphere();
  54. DECLARE_CONOBJECT(SkySphere);
  55. // SimObject
  56. void onStaticModified(const char* slotName, const char* newValue);
  57. // ConsoleObject
  58. virtual bool onAdd();
  59. virtual void onRemove();
  60. static void initPersistFields();
  61. virtual void inspectPostApply();
  62. // NetObject
  63. virtual U32 packUpdate(NetConnection* conn, U32 mask, BitStream* stream);
  64. virtual void unpackUpdate(NetConnection* conn, BitStream* stream);
  65. // SceneObject
  66. void prepRenderImage(SceneRenderState* state);
  67. /// Our render delegate.
  68. void _renderObject(ObjectRenderInst* ri, SceneRenderState* state, BaseMatInstance* mi);
  69. void clearVectors();
  70. void addVertex(Point3F vert);
  71. void addNormal(Point3F nor);
  72. void addTexcoord(F32 s, F32 t);
  73. void addColor(ColorI col);
  74. void BuildFinalVert();
  75. void BuildFinalFogVert();
  76. /// Prepares rendering structures and geometry.
  77. void _initRender();
  78. struct SphereVertex
  79. {
  80. Point3F pos;
  81. Point3F nor;
  82. F32 s, t;
  83. };
  84. Vector<SphereVertex> tmpVertices;
  85. Vector<F32> vertsVec;
  86. Vector<F32> texCoordVec;
  87. Vector<F32> normsVec;
  88. struct FinalVertexData
  89. {
  90. Point3F pos;
  91. Point3F nor;
  92. F32 s;
  93. F32 t;
  94. };
  95. Vector<FinalVertexData> finalVertData;
  96. struct FogVertex
  97. {
  98. // might need normals for smoothing.
  99. Point3F pos;
  100. ColorI col;
  101. };
  102. Vector<FogVertex> finalFogVertex;
  103. Vector<FogVertex> tempFogVertex;
  104. Vector<ColorI> colVec;
  105. Vector<F32> fogVerts;
  106. protected:
  107. // Material
  108. DECLARE_MATERIALASSET(SkySphere, Material);
  109. DECLARE_ASSET_NET_SETGET(SkySphere, Material, -1);
  110. BaseMatInstance* mMatInstance;
  111. SkyMatParams mMatParamHandle;
  112. GFXVertexBufferHandle<GFXVertexPNT> mVB;
  113. GFXVertexBufferHandle<GFXVertexPC> mFogBandVB;
  114. Material* mFogBandMat;
  115. BaseMatInstance* mFogBandMatInst;
  116. LinearColorF mLastFogColor;
  117. bool mIsVBDirty;
  118. U32 mPrimCount;
  119. MatrixSet* mMatrixSet;
  120. F32 mFogBandHeight;
  121. U32 mFogPrimCount;
  122. void _updateMaterial();
  123. void _initMaterial();
  124. BaseMatInstance* _getMaterialInstance();
  125. };
  126. #endif