cloudLayer.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 _CLOUDLAYER_H_
  23. #define _CLOUDLAYER_H_
  24. #ifndef _SCENEOBJECT_H_
  25. #include "scene/sceneObject.h"
  26. #endif
  27. #ifndef _GFXTEXTUREHANDLE_H_
  28. #include "gfx/gfxTextureHandle.h"
  29. #endif
  30. #ifndef _GFXVERTEXBUFFER_H_
  31. #include "gfx/gfxVertexBuffer.h"
  32. #endif
  33. #ifndef _GFXPRIMITIVEBUFFER_H_
  34. #include "gfx/gfxPrimitiveBuffer.h"
  35. #endif
  36. #ifndef _MATINSTANCE_H_
  37. #include "materials/matInstance.h"
  38. #endif
  39. #include "T3D/assets/ImageAsset.h"
  40. GFXDeclareVertexFormat( GFXCloudVertex )
  41. {
  42. Point3F point;
  43. Point3F normal;
  44. Point3F binormal;
  45. Point3F tangent;
  46. Point2F texCoord;
  47. };
  48. class CloudLayer : public SceneObject
  49. {
  50. typedef SceneObject Parent;
  51. enum
  52. {
  53. CloudLayerMask = Parent::NextFreeMask,
  54. NextFreeMask = Parent::NextFreeMask << 1,
  55. };
  56. #define TEX_COUNT 3
  57. public:
  58. CloudLayer();
  59. virtual ~CloudLayer() {}
  60. DECLARE_CONOBJECT( CloudLayer );
  61. // ConsoleObject
  62. virtual bool onAdd();
  63. virtual void onRemove();
  64. static void initPersistFields();
  65. virtual void inspectPostApply();
  66. // NetObject
  67. virtual U32 packUpdate( NetConnection *conn, U32 mask, BitStream *stream );
  68. virtual void unpackUpdate( NetConnection *conn, BitStream *stream );
  69. // SceneObject
  70. void prepRenderImage( SceneRenderState *state );
  71. void renderObject( ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance *mi );
  72. void onImageChanged() {}
  73. protected:
  74. void _initBuffers();
  75. protected:
  76. static U32 smVertStride;
  77. static U32 smStrideMinusOne;
  78. static U32 smVertCount;
  79. static U32 smTriangleCount;
  80. DECLARE_IMAGEASSET(CloudLayer, Texture, onImageChanged, GFXStaticTextureSRGBProfile);
  81. DECLARE_ASSET_NET_SETGET(CloudLayer, Texture, CloudLayerMask);
  82. GFXShaderRef mShader;
  83. GFXStateBlockRef mStateblock;
  84. GFXShaderConstBufferRef mShaderConsts;
  85. GFXShaderConstHandle *mModelViewProjSC;
  86. GFXShaderConstHandle *mAmbientColorSC;
  87. GFXShaderConstHandle *mSunColorSC;
  88. GFXShaderConstHandle *mSunVecSC;
  89. GFXShaderConstHandle *mTexOffsetSC[3];
  90. GFXShaderConstHandle *mTexScaleSC;
  91. GFXShaderConstHandle *mBaseColorSC;
  92. GFXShaderConstHandle *mCoverageSC;
  93. GFXShaderConstHandle *mExposureSC;
  94. GFXShaderConstHandle *mEyePosWorldSC;
  95. GFXShaderConstHandle *mNormalHeightMapSC;
  96. GFXVertexBufferHandle<GFXCloudVertex> mVB;
  97. GFXPrimitiveBufferHandle mPB;
  98. Point2F mTexOffset[3];
  99. U32 mLastTime;
  100. // Fields...
  101. F32 mTexScale[TEX_COUNT];
  102. Point2F mTexDirection[TEX_COUNT];
  103. F32 mTexSpeed[TEX_COUNT];
  104. LinearColorF mBaseColor;
  105. F32 mExposure;
  106. F32 mCoverage;
  107. F32 mWindSpeed;
  108. F32 mHeight;
  109. };
  110. #endif // _CLOUDLAYER_H_