waterObject.h
Engine/source/environment/waterObject.h
Classes:
class
class
Public Functions
GFXDeclareVertexFormat(GFXWaterVertex )
Detailed Description
Public Functions
GFXDeclareVertexFormat(GFXWaterVertex )
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#ifndef _WATEROBJECT_H_ 25#define _WATEROBJECT_H_ 26 27#ifndef _SCENEOBJECT_H_ 28#include "scene/sceneObject.h" 29#endif 30#ifndef _GFXSTRUCTS_H_ 31#include "gfx/gfxStructs.h" 32#endif 33#ifndef _FOGSTRUCTS_H_ 34#include "scene/fogStructs.h" 35#endif 36#ifndef _GFXSTATEBLOCK_H_ 37#include "gfx/gfxStateBlock.h" 38#endif 39#ifndef _REFLECTOR_H_ 40#include "scene/reflector.h" 41#endif 42#ifndef _ALIGNEDARRAY_H_ 43#include "core/util/tAlignedArray.h" 44#endif 45#ifndef _MATTEXTURETARGET_H_ 46#include "materials/matTextureTarget.h" 47#endif 48 49GFXDeclareVertexFormat( GFXWaterVertex ) 50{ 51 Point3F point; 52 Point3F normal; 53 Point2F undulateData; 54 Point4F horizonFactor; 55}; 56 57 58class MaterialParameterHandle; 59class BaseMatInstance; 60class ShaderData; 61class MatrixSet; 62 63struct WaterMatParams 64{ 65 MaterialParameterHandle* mRippleMatSC; 66 MaterialParameterHandle* mRippleDirSC; 67 MaterialParameterHandle* mRippleTexScaleSC; 68 MaterialParameterHandle* mRippleSpeedSC; 69 MaterialParameterHandle* mRippleMagnitudeSC; 70 MaterialParameterHandle* mFoamDirSC; 71 MaterialParameterHandle* mFoamTexScaleSC; 72 MaterialParameterHandle* mFoamOpacitySC; 73 MaterialParameterHandle* mFoamSpeedSC; 74 MaterialParameterHandle* mWaveDirSC; 75 MaterialParameterHandle* mWaveDataSC; 76 MaterialParameterHandle* mReflectTexSizeSC; 77 MaterialParameterHandle* mBaseColorSC; 78 MaterialParameterHandle* mMiscParamsSC; 79 MaterialParameterHandle* mReflectParamsSC; 80 MaterialParameterHandle* mReflectNormalSC; 81 MaterialParameterHandle* mHorizonPositionSC; 82 MaterialParameterHandle* mFogParamsSC; 83 MaterialParameterHandle* mMoreFogParamsSC; 84 MaterialParameterHandle* mFarPlaneDistSC; 85 MaterialParameterHandle* mWetnessParamsSC; 86 MaterialParameterHandle* mDistortionParamsSC; 87 MaterialParameterHandle* mUndulateMaxDistSC; 88 MaterialParameterHandle* mAmbientColorSC; 89 MaterialParameterHandle* mLightDirSC; 90 MaterialParameterHandle* mFoamParamsSC; 91 MaterialParameterHandle* mGridElementSizeSC; 92 MaterialParameterHandle* mElapsedTimeSC; 93 MaterialParameterHandle* mModelMatSC; 94 MaterialParameterHandle* mFoamSamplerSC; 95 MaterialParameterHandle* mRippleSamplerSC; 96 MaterialParameterHandle* mCubemapSamplerSC; 97 MaterialParameterHandle* mSpecularParamsSC; 98 MaterialParameterHandle* mDepthGradMaxSC; 99 MaterialParameterHandle* mReflectivitySC; 100 MaterialParameterHandle* mDepthGradSamplerSC; 101 102 void clear(); 103 void init(BaseMatInstance* matInst); 104}; 105 106 107class GFXOcclusionQuery; 108class PostEffect; 109class CubemapData; 110 111//------------------------------------------------------------------------- 112// WaterObject Class 113//------------------------------------------------------------------------- 114 115class WaterObject : public SceneObject 116{ 117 typedef SceneObject Parent; 118 119protected: 120 121 enum MaskBits { 122 UpdateMask = Parent::NextFreeMask << 0, 123 WaveMask = Parent::NextFreeMask << 1, 124 MaterialMask = Parent::NextFreeMask << 2, 125 TextureMask = Parent::NextFreeMask << 3, 126 SoundMask = Parent::NextFreeMask << 4, 127 NextFreeMask = Parent::NextFreeMask << 5 128 }; 129 130 enum consts { 131 MAX_WAVES = 3, 132 MAX_FOAM = 2, 133 NUM_ANIM_FRAMES = 32, 134 }; 135 136 enum MaterialType 137 { 138 WaterMat = 0, 139 UnderWaterMat, 140 BasicWaterMat, 141 BasicUnderWaterMat, 142 NumMatTypes 143 }; 144 145public: 146 147 WaterObject(); 148 virtual ~WaterObject(); 149 150 DECLARE_CONOBJECT( WaterObject ); 151 152 // ConsoleObject 153 static void consoleInit(); 154 static void initPersistFields(); 155 156 // SimObject 157 virtual bool onAdd(); 158 virtual void onRemove(); 159 virtual void inspectPostApply(); 160 virtual bool processArguments(S32 argc, ConsoleValueRef *argv); 161 162 // NetObject 163 virtual U32 packUpdate( NetConnection * conn, U32 mask, BitStream *stream ); 164 virtual void unpackUpdate( NetConnection * conn, BitStream *stream ); 165 166 // SceneObject 167 virtual void prepRenderImage( SceneRenderState *state ); 168 virtual void renderObject( ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance *overrideMat ); 169 virtual SFXAmbience* getSoundAmbience() const { return mSoundAmbience; } 170 virtual bool containsPoint( const Point3F& point ) { return isUnderwater( point ); } 171 172 // WaterObject 173 virtual F32 getViscosity() const { return mViscosity; } 174 virtual F32 getDensity() const { return mDensity; } 175 virtual F32 getSurfaceHeight( const Point2F &pos ) const { return 0.0f; }; 176 virtual const char* getLiquidType() const { return mLiquidType; } 177 virtual F32 getWaterCoverage( const Box3F &worldBox ) const { return 0.0f; } 178 virtual VectorF getFlow( const Point3F &pos ) const { return Point3F::Zero; } 179 virtual void updateUnderwaterEffect( SceneRenderState *state ); 180 virtual bool isUnderwater( const Point3F &pnt ) const { return false; } 181 182protected: 183 184 virtual void setShaderXForms( BaseMatInstance *mat ) {}; 185 virtual void setupVBIB() {}; 186 virtual void innerRender( SceneRenderState *state ) {}; 187 virtual void setCustomTextures( S32 matIdx, U32 pass, const WaterMatParams ¶mHandles ); 188 void drawUnderwaterFilter( SceneRenderState *state ); 189 190 virtual void setShaderParams( SceneRenderState *state, BaseMatInstance *mat, const WaterMatParams ¶mHandles ); 191 PostEffect* getUnderwaterEffect(); 192 193 bool initMaterial( S32 idx ); 194 void cleanupMaterials(); 195 S32 getMaterialIndex( const Point3F &camPos ); 196 197 void initTextures(); 198 199 virtual void _getWaterPlane( const Point3F &camPos, PlaneF &outPlane, Point3F &outPos ) {} 200 201 /// Callback used internally when smDisableTrueReflections changes. 202 void _onDisableTrueRelfections(); 203 204protected: 205 206 static bool _setFullReflect( void *object, const char *index, const char *data ); 207 static bool _checkDensity(void *object, const char *index, const char *data); 208 209 // WaterObject 210 F32 mViscosity; 211 F32 mDensity; 212 String mLiquidType; 213 F32 mFresnelBias; 214 F32 mFresnelPower; 215 F32 mSpecularPower; 216 LinearColorF mSpecularColor; 217 bool mEmissive; 218 219 // Reflection 220 bool mFullReflect; 221 PlaneReflector mPlaneReflector; 222 ReflectorDesc mReflectorDesc; 223 PlaneF mWaterPlane; 224 Point3F mWaterPos; 225 bool mReflectNormalUp; 226 F32 mReflectivity; 227 228 // Water Fogging 229 WaterFogData mWaterFogData; 230 231 // Distortion 232 F32 mDistortStartDist; 233 F32 mDistortEndDist; 234 F32 mDistortFullDepth; 235 236 // Ripples 237 Point2F mRippleDir[ MAX_WAVES ]; 238 F32 mRippleSpeed[ MAX_WAVES ]; 239 Point2F mRippleTexScale[ MAX_WAVES ]; 240 F32 mRippleMagnitude[ MAX_WAVES ]; 241 242 F32 mOverallRippleMagnitude; 243 244 // Waves 245 Point2F mWaveDir[ MAX_WAVES ]; 246 F32 mWaveSpeed[ MAX_WAVES ]; 247 F32 mWaveMagnitude[ MAX_WAVES ]; 248 249 F32 mOverallWaveMagnitude; 250 251 // Foam 252 Point2F mFoamDir[ MAX_WAVES ]; 253 F32 mFoamSpeed[ MAX_WAVES ]; 254 Point2F mFoamTexScale[ MAX_WAVES ]; 255 F32 mFoamOpacity[ MAX_WAVES ]; 256 257 F32 mOverallFoamOpacity; 258 F32 mFoamMaxDepth; 259 F32 mFoamAmbientLerp; 260 F32 mFoamRippleInfluence; 261 262 // Basic Lighting 263 F32 mClarity; 264 ColorI mUnderwaterColor; 265 266 // Misc 267 F32 mDepthGradientMax; 268 269 // Other textures 270 String mRippleTexName; 271 String mFoamTexName; 272 String mCubemapName; 273 String mDepthGradientTexName; 274 275 // Sound 276 SFXAmbience* mSoundAmbience; 277 278 // Not fields... 279 280 /// Defined here and sent to the shader in WaterCommon::setShaderParams 281 /// but needs to be initialized in child classes prior to that call. 282 F32 mUndulateMaxDist; 283 284 /// Defined in WaterCommon but set and used by child classes. 285 /// If true will refuse to render a reflection even if called from 286 /// the ReflectionManager, is set true if occlusion query is enabled and 287 /// it determines it is occluded. 288 //bool mSkipReflectUpdate; 289 290 /// Derived classes can set this value prior to calling Parent::setShaderConst 291 /// to pass it into the shader miscParam.w 292 F32 mMiscParamW; 293 294 SimObjectPtr<PostEffect> mUnderwaterPostFx; 295 296 /// A global for enabling wireframe rendering 297 /// on all water objects. 298 static bool smWireframe; 299 300 /// Force all water objects to use static cubemap reflections 301 static bool smDisableTrueReflections; 302 303 // Rendering 304 bool mBasicLighting; 305 //U32 mRenderUpdateCount; 306 //U32 mReflectUpdateCount; 307 bool mGenerateVB; 308 String mSurfMatName[NumMatTypes]; 309 BaseMatInstance* mMatInstances[NumMatTypes]; 310 WaterMatParams mMatParamHandles[NumMatTypes]; 311 bool mUnderwater; 312 GFXStateBlockRef mUnderwaterSB; 313 GFXTexHandle mRippleTex; 314 GFXTexHandle mDepthGradientTex; 315 GFXTexHandle mFoamTex; 316 CubemapData *mCubemap; 317 MatrixSet *mMatrixSet; 318 NamedTexTarget mNamedDepthGradTex; 319}; 320 321#endif // _WATEROBJECT_H_ 322