1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
|
// This code contains NVIDIA Confidential Information and is disclosed
// under the Mutual Non-Disclosure Agreement.
//
// Notice
// ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES
// NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
// THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT,
// MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
//
// NVIDIA Corporation assumes no responsibility for the consequences of use of such
// information or for any infringement of patents or other rights of third parties that may
// result from its use. No license is granted by implication or otherwise under any patent
// or patent rights of NVIDIA Corporation. No third party distribution is allowed unless
// expressly authorized by NVIDIA. Details are subject to change without notice.
// This code supersedes and replaces all information previously supplied.
// NVIDIA Corporation products are not authorized for use as critical
// components in life support devices or systems without express written approval of
// NVIDIA Corporation.
//
// Copyright � 2008- 2013 NVIDIA Corporation. All rights reserved.
//
// NVIDIA Corporation and its licensors retain all intellectual property and proprietary
// rights in and to this software and related documentation and any modifications thereto.
// Any use, reproduction, disclosure or distribution of this software and related
// documentation without an express license agreement from NVIDIA Corporation is
// strictly prohibited.
//
#ifndef _OCEAN_VESSEL_H
#define _OCEAN_VESSEL_H
#include <D3DX11Effect.h>
#include "GFSDK_WaveWorks_Types.h"
#include "SDKmesh.h"
#include <vector>
class OceanHullProfile;
struct OceanEnvironment;
class OceanSmoke;
class CBaseCamera;
class OceanSurfaceHeights;
class OceanHullSensors;
class OceanPSM;
class BoatMesh : public CDXUTSDKMesh
{
public:
// Hook to create input layout from mesh data
HRESULT CreateInputLayout( ID3D11Device* pd3dDevice,
UINT iMesh, UINT iVB,
const void *pShaderBytecodeWithInputSignature, SIZE_T BytecodeLength,
ID3D11InputLayout** pIL
);
const SDKMESH_VERTEX_BUFFER_HEADER* getVBHeader(int i) const { return m_pVertexBufferArray + i; }
const SDKMESH_INDEX_BUFFER_HEADER* getIBHeader(int i) const { return m_pIndexBufferArray + i; }
};
struct OceanVesselSubset {
ID3D11Buffer* pIB;
DXGI_FORMAT ib_format;
int index_count;
};
struct OceanVesselDynamicState
{
OceanVesselDynamicState();
void setPosition(D3DXVECTOR2 pos);
void setHeading(D3DXVECTOR2 heading, FLOAT speed);
D3DXVECTOR2 m_Position;
D3DXVECTOR2 m_NominalHeading;
FLOAT m_Speed;
FLOAT m_Pitch;
FLOAT m_PitchRate;
FLOAT m_Roll;
FLOAT m_RollRate;
FLOAT m_Yaw;
FLOAT m_YawRate;
FLOAT m_PrevSeaYaw;
FLOAT m_Height;
FLOAT m_HeightRate;
UINT m_DynamicsCountdown;
bool m_bFirstUpdate;
D3DXMATRIX m_CameraToWorld;
D3DXMATRIX m_LocalToWorld;
D3DXMATRIX m_WakeToWorld;
private:
void ResetDynamicState();
};
class OceanVessel
{
public:
OceanVessel(OceanVesselDynamicState* pDynamicState);
~OceanVessel();
HRESULT init(LPCTSTR cfg_string, bool allow_smoke);
void updateVesselMotion(ID3D11DeviceContext* pDC, GFSDK_WaveWorks_SimulationHandle hSim, FLOAT sea_level, FLOAT time_delta, FLOAT water_scale);
void renderVesselToScene( ID3D11DeviceContext* pDC,
const D3DXMATRIX& matView,
const D3DXMATRIX& matProj,
const OceanEnvironment& ocean_env,
const OceanVesselSubset* pSubsetOverride,
bool wireframe
);
void renderReflectedVesselToScene( ID3D11DeviceContext* pDC,
const CBaseCamera& camera,
const D3DXPLANE& world_reflection_plane,
const OceanEnvironment& ocean_env
);
void updateVesselShadows(ID3D11DeviceContext* pDC);
void updateVesselLightsInEnv(OceanEnvironment& env, const D3DXMATRIX& matView, float lighting_mult, int objectID = 0);
void renderVesselToHullProfile(ID3D11DeviceContext* pDC, OceanHullProfile& profile);
void renderHullProfileInUI(ID3D11DeviceContext* pDC);
void updateSmokeSimulation(ID3D11DeviceContext* pDC, const CBaseCamera& camera, FLOAT time_delta, const D3DXVECTOR2& wind_dir, FLOAT wind_speed, FLOAT emit_rate_scale);
void renderSmokeToScene( ID3D11DeviceContext* pDC,
const CBaseCamera& camera,
const OceanEnvironment& ocean_env
);
void beginRenderToPSM(ID3D11DeviceContext* pDC, const D3DXVECTOR2& wind_dir);
void endRenderToPSM(ID3D11DeviceContext* pDC);
void renderSmokeToPSM( ID3D11DeviceContext* pDC,
const OceanEnvironment& ocean_env
);
void renderTextureToUI(ID3D11DeviceContext* pDC, ID3D11ShaderResourceView* pSRV);
const D3DXMATRIX* getCameraXform() const { return &m_pDynamicState->m_CameraToWorld; }
const D3DXMATRIX* getWorldXform() const { return &m_pDynamicState->m_LocalToWorld; }
const D3DXMATRIX* getWakeToWorldXform() const { return &m_pDynamicState->m_WakeToWorld; }
const D3DXMATRIX* getMeshToLocalXform() const { return &m_MeshToLocal; }
FLOAT getLength() const { return m_Length; }
BoatMesh* getMesh() const;
OceanSurfaceHeights* getSurfaceHeights() const { return m_pSurfaceHeights; }
OceanPSM* getPSM() const { return m_pPSM; }
OceanHullSensors* getHullSensors() const { return m_pHullSensors; }
float getYaw() const { return m_pDynamicState->m_Yaw; }
float getYawRate() const { return m_pDynamicState->m_YawRate; }
private:
// ---------------------------------- GPU shading data ------------------------------------
// D3D objects
ID3D11Device* m_pd3dDevice;
BoatMesh* m_pMesh;
FLOAT m_meshRenderScale;
FLOAT m_DiffuseGamma;
ID3D11InputLayout* m_pLayout;
ID3DX11Effect* m_pFX;
ID3DX11EffectTechnique* m_pRenderToSceneTechnique;
ID3DX11EffectTechnique* m_pRenderToShadowMapTechnique;
ID3DX11EffectTechnique* m_pRenderToHullProfileTechnique;
ID3DX11EffectTechnique* m_pRenderQuadToUITechnique;
ID3DX11EffectTechnique* m_pRenderQuadToCrackFixTechnique;
ID3DX11EffectTechnique* m_pWireframeOverrideTechnique;
ID3DX11EffectMatrixVariable* m_pMatWorldViewProjVariable;
ID3DX11EffectMatrixVariable* m_pMatWorldViewVariable;
ID3DX11EffectMatrixVariable* m_pMatWorldVariable;
ID3DX11EffectShaderResourceVariable *m_pTexDiffuseVariable;
ID3DX11EffectShaderResourceVariable *m_pTexRustMapVariable;
ID3DX11EffectShaderResourceVariable *m_pTexRustVariable;
ID3DX11EffectShaderResourceVariable *m_pTexBumpVariable;
ID3DX11EffectVectorVariable* m_pDiffuseColorVariable;
ID3DX11EffectVectorVariable* m_pLightDirectionVariable;
ID3DX11EffectVectorVariable* m_pLightColorVariable;
ID3DX11EffectVectorVariable* m_pAmbientColorVariable;
ID3DX11EffectScalarVariable* m_pSpotlightNumVariable;
ID3DX11EffectVectorVariable* m_pSpotlightPositionVariable;
ID3DX11EffectVectorVariable* m_pSpotLightAxisAndCosAngleVariable;
ID3DX11EffectVectorVariable* m_pSpotlightColorVariable;
ID3DX11EffectMatrixVariable* m_pSpotlightShadowMatrixVar;
ID3DX11EffectShaderResourceVariable* m_pSpotlightShadowResourceVar;
ID3DX11EffectVectorVariable* m_pLightningPositionVariable;
ID3DX11EffectVectorVariable* m_pLightningColorVariable;
ID3DX11EffectScalarVariable* m_pFogExponentVariable;
ID3D11ShaderResourceView* m_pWhiteTextureSRV;
ID3D11ShaderResourceView* m_pRustMapSRV;
ID3D11ShaderResourceView* m_pRustSRV;
ID3D11ShaderResourceView* m_pBumpSRV;
ID3D11ShaderResourceView* m_pHullProfileSRV[2];
ID3D11RenderTargetView* m_pHullProfileRTV[2];
ID3D11DepthStencilView* m_pHullProfileDSV;
void renderVessel( ID3D11DeviceContext* pDC,
ID3DX11EffectTechnique* pTechnique,
const OceanVesselSubset* pSubsetOverride,
bool wireframe,
bool depthOnly);
FLOAT m_Draft;
FLOAT m_Length;
FLOAT m_Beam;
FLOAT m_MeshHeight;
FLOAT m_BuoyantArea;
FLOAT m_Mass;
FLOAT m_PitchInertia;
FLOAT m_RollInertia;
FLOAT m_MetacentricHeight;
FLOAT m_LongitudinalCOM;
FLOAT m_MassMult;
FLOAT m_PitchInertiaMult;
FLOAT m_RollInertiaMult;
FLOAT m_InitialPitch;
FLOAT m_InitialHeight;
D3DXVECTOR3 m_bbCentre;
D3DXVECTOR3 m_bbExtents;
OceanVesselDynamicState* m_pDynamicState;
FLOAT m_HeightDrag;
FLOAT m_PitchDrag;
FLOAT m_YawDrag;
FLOAT m_YawCoefficient;
FLOAT m_RollDrag;
FLOAT m_CameraHeightAboveWater;
FLOAT m_CameraLongitudinalOffset;
INT m_HullProfileTextureWH;
LPTSTR m_MeshFileName;
D3DXMATRIX m_MeshToLocal;
D3DXMATRIX m_CameraToLocal;
struct Spotlight{
D3DVECTOR position;
D3DVECTOR axis;
float beam_angle;
D3DVECTOR color;
};
std::vector<Spotlight> m_Spotlights;
struct SpotlightShadow
{
SpotlightShadow()
: m_pResource(NULL)
, m_pDSV(NULL)
, m_pSRV(NULL)
, m_Dirty(true)
{}
~SpotlightShadow()
{
SAFE_RELEASE(m_pResource);
SAFE_RELEASE(m_pDSV);
SAFE_RELEASE(m_pSRV);
}
D3DMATRIX m_ViewProjMatrix;
bool m_Dirty;
ID3D11Texture2D* m_pResource;
ID3D11DepthStencilView* m_pDSV;
ID3D11ShaderResourceView* m_pSRV;
};
std::vector<SpotlightShadow> m_SpotlightsShadows;
HRESULT parseConfig(LPCTSTR cfg_string);
Spotlight* processGlobalConfigLine(const char* line);
Spotlight* processSpotlightConfigLine(const char* line, Spotlight* pSpot);
// Smoke sim
FLOAT m_FunnelHeightAboveWater;
FLOAT m_FunnelLongitudinalOffset;
D3DXVECTOR2 m_FunnelMouthSize;
D3DXMATRIX m_FunnelMouthToLocal;
LPTSTR m_SmokeTextureFileName;
INT m_NumSmokeParticles;
FLOAT m_SmokeParticleEmitRate;
FLOAT m_SmokeParticleBeginSize;
FLOAT m_SmokeParticleEndSize;
FLOAT m_SmokeParticleEmitMinVelocity;
FLOAT m_SmokeParticleEmitMaxVelocity;
FLOAT m_SmokeParticleEmitSpread;
FLOAT m_SmokeParticleMinBuoyancy;
FLOAT m_SmokeParticleMaxBuoyancy;
FLOAT m_SmokeParticleCoolingRate;
FLOAT m_SmokeWindDrag;
FLOAT m_SmokePSMBoundsFadeMargin;
FLOAT m_SmokeWindNoiseLevel;
FLOAT m_SmokeWindNoiseSpatialScale;
FLOAT m_SmokeWindNoiseTimeScale;
D3DXVECTOR3 m_SmokeTint;
FLOAT m_SmokeShadowOpacity;
OceanSmoke* m_pSmoke;
int m_PSMRes;
D3DXVECTOR3 m_PSMMinCorner;
D3DXVECTOR3 m_PSMMaxCorner;
OceanPSM* m_pPSM;
INT m_NumSurfaceHeightSamples;
OceanSurfaceHeights* m_pSurfaceHeights;
OceanHullSensors* m_pHullSensors;
bool m_bFirstSensorUpdate;
};
#endif // _OCEAN_VESSEL_H
|