cloudLayer.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. GFXDeclareVertexFormat( GFXCloudVertex )
  40. {
  41. Point3F point;
  42. Point3F normal;
  43. Point3F binormal;
  44. Point3F tangent;
  45. Point2F texCoord;
  46. };
  47. class CloudLayer : public SceneObject
  48. {
  49. typedef SceneObject Parent;
  50. enum
  51. {
  52. CloudLayerMask = Parent::NextFreeMask,
  53. NextFreeMask = Parent::NextFreeMask << 1,
  54. };
  55. #define TEX_COUNT 3
  56. public:
  57. CloudLayer();
  58. virtual ~CloudLayer() {}
  59. DECLARE_CONOBJECT( CloudLayer );
  60. // ConsoleObject
  61. virtual bool onAdd();
  62. virtual void onRemove();
  63. static void initPersistFields();
  64. virtual void inspectPostApply();
  65. // NetObject
  66. virtual U32 packUpdate( NetConnection *conn, U32 mask, BitStream *stream );
  67. virtual void unpackUpdate( NetConnection *conn, BitStream *stream );
  68. // SceneObject
  69. void prepRenderImage( SceneRenderState *state );
  70. void renderObject( ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance *mi );
  71. protected:
  72. void _initTexture();
  73. void _initBuffers();
  74. protected:
  75. static U32 smVertStride;
  76. static U32 smStrideMinusOne;
  77. static U32 smVertCount;
  78. static U32 smTriangleCount;
  79. GFXTexHandle mTexture;
  80. GFXShaderRef mShader;
  81. GFXStateBlockRef mStateblock;
  82. GFXShaderConstBufferRef mShaderConsts;
  83. GFXShaderConstHandle *mModelViewProjSC;
  84. GFXShaderConstHandle *mAmbientColorSC;
  85. GFXShaderConstHandle *mSunColorSC;
  86. GFXShaderConstHandle *mSunVecSC;
  87. GFXShaderConstHandle *mTexOffsetSC[3];
  88. GFXShaderConstHandle *mTexScaleSC;
  89. GFXShaderConstHandle *mBaseColorSC;
  90. GFXShaderConstHandle *mCoverageSC;
  91. GFXShaderConstHandle *mExposureSC;
  92. GFXShaderConstHandle *mEyePosWorldSC;
  93. GFXVertexBufferHandle<GFXCloudVertex> mVB;
  94. GFXPrimitiveBufferHandle mPB;
  95. Point2F mTexOffset[3];
  96. U32 mLastTime;
  97. // Fields...
  98. String mTextureName;
  99. F32 mTexScale[TEX_COUNT];
  100. Point2F mTexDirection[TEX_COUNT];
  101. F32 mTexSpeed[TEX_COUNT];
  102. ColorF mBaseColor;
  103. F32 mExposure;
  104. F32 mCoverage;
  105. F32 mWindSpeed;
  106. F32 mHeight;
  107. };
  108. #endif // _CLOUDLAYER_H_