summaryrefslogtreecommitdiff
path: root/demo/ocean_surface.h
blob: eb7f6bd8f3b7cff2db4a0acd0d5b344fa56956ed (plain) (blame)
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
// 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_WAVE_H
#define _OCEAN_WAVE_H

#include <D3DX11Effect.h>

#include <GFSDK_WaveWorks.h>

class OceanHullProfile;
struct OceanEnvironment;
struct OceanSkyMapInfo;

//#define DEBUG_VS
//#define DEBUG_PS

// Ocean grid setting
#define BICOLOR_TEX_SIZE			256

#define LOCAL_FOAMMAP_TEX_SIZE			1024


struct OceanSurfaceParameters
{
	// Shading properties
    D3DXVECTOR4 waterbody_color;
    float sky_blending;
};

struct OceanSurfaceState
{
	D3DXMATRIX m_matView;
	D3DXMATRIX m_matProj;
};

class OceanSurface
{
public:
	OceanSurface(OceanSurfaceState* pSurfaceState);
	~OceanSurface();

	OceanSurfaceParameters m_params;

	HRESULT init(const OceanSurfaceParameters& params);

	// create color/fresnel lookup table.
	void createFresnelMap();
	
	// create local foam maps
	void OceanSurface::createLocalFoamMaps();

	// ---------------------------------- GPU shading data ------------------------------------

	// D3D objects
	ID3D11Device* m_pd3dDevice;
	ID3D11InputLayout* m_pQuadLayout;
	
	// Color look up 1D texture
	ID3D11ShaderResourceView* m_pBicolorMap;			// (RGBA8)
	ID3D11ShaderResourceView* m_pFoamIntensityMap;
	ID3D11ShaderResourceView* m_pFoamDiffuseMap;
	ID3D11ShaderResourceView* m_pWakeMap;
	ID3D11ShaderResourceView* m_pShipFoamMap;
	ID3D11ShaderResourceView* m_pGustMap;


	ID3DX11EffectTechnique*	  m_pShiftFadeBlurLocalFoamTechnique;
	ID3DX11EffectPass*		  m_pShiftFadeBlurLocalFoamShadedPass;
	ID3DX11EffectVectorVariable* m_pShiftFadeBlurLocalFoamUVOffsetBlurVariable;
	ID3DX11EffectScalarVariable* m_pShiftFadeBlurLocalFoamFadeAmountVariable;
	ID3DX11EffectShaderResourceVariable* m_pShiftFadeBlurLocalFoamTextureVariable;
	ID3D11Texture2D*		  m_pLocalFoamMapReceiver;
	ID3D11ShaderResourceView* m_pLocalFoamMapReceiverSRV;
	ID3D11RenderTargetView*   m_pLocalFoamMapReceiverRTV;
	ID3D11Texture2D*		  m_pLocalFoamMapFader;
	ID3D11ShaderResourceView* m_pLocalFoamMapFaderSRV;
	ID3D11RenderTargetView*   m_pLocalFoamMapFaderRTV;
	ID3DX11EffectShaderResourceVariable* m_pRenderSurfaceLocalFoamMapVariable;


	ID3DX11Effect* m_pOceanFX;
	ID3DX11EffectTechnique* m_pRenderSurfaceTechnique;
	ID3DX11EffectPass* m_pRenderSurfaceShadedPass;
	ID3DX11EffectPass* m_pRenderSurfaceWireframePass;
	ID3DX11EffectMatrixVariable* m_pRenderSurfaceMatViewProjVariable;
	ID3DX11EffectMatrixVariable* m_pRenderSurfaceMatViewVariable;
    ID3DX11EffectVectorVariable* m_pRenderSurfaceSkyColorVariable;
	ID3DX11EffectVectorVariable* m_pRenderSurfaceLightDirectionVariable;
	ID3DX11EffectVectorVariable* m_pRenderSurfaceLightColorVariable;
	ID3DX11EffectVectorVariable* m_pRenderSurfaceWaterColorVariable;
	ID3DX11EffectVectorVariable* m_pRenderSurfacePatchColorVariable;
	ID3DX11EffectShaderResourceVariable* m_pRenderSurfaceColorMapVariable;
	ID3DX11EffectShaderResourceVariable* m_pRenderSurfaceCubeMap0Variable;
	ID3DX11EffectShaderResourceVariable* m_pRenderSurfaceCubeMap1Variable;
	ID3DX11EffectScalarVariable* m_pRenderSurfaceCubeBlendVariable;
	ID3DX11EffectVectorVariable* m_pRenderSurfaceCube0RotateSinCosVariable;
	ID3DX11EffectVectorVariable* m_pRenderSurfaceCube1RotateSinCosVariable;
	ID3DX11EffectVectorVariable* m_pRenderSurfaceCubeMultVariable;

	ID3DX11EffectScalarVariable* m_pSpotlightNumVariable;
	ID3DX11EffectVectorVariable* m_pRenderSurfaceSpotlightPositionVariable;
	ID3DX11EffectVectorVariable* m_pRenderSurfaceSpotLightAxisAndCosAngleVariable;
	ID3DX11EffectVectorVariable* m_pRenderSurfaceSpotlightColorVariable;
	ID3DX11EffectMatrixVariable* m_pSpotlightShadowMatrixVar;
	ID3DX11EffectShaderResourceVariable* m_pSpotlightShadowResourceVar;

	ID3DX11EffectScalarVariable* m_pRenderSurfaceFogExponentVariable;

	ID3DX11EffectShaderResourceVariable* m_pRenderSurfaceFoamIntensityMapVariable;
	ID3DX11EffectShaderResourceVariable* m_pRenderSurfaceFoamDiffuseMapVariable;
	ID3DX11EffectScalarVariable* m_pGlobalFoamFadeVariable;

	ID3DX11EffectVectorVariable* m_pRenderSurfaceHullProfileCoordOffsetAndScaleVariable;
	ID3DX11EffectVectorVariable* m_pRenderSurfaceHullProfileHeightOffsetAndHeightScaleAndTexelSizeVariable;
	ID3DX11EffectShaderResourceVariable* m_pRenderSurfaceHullProfileMapVariable;

	ID3DX11EffectShaderResourceVariable* m_pRenderSurfaceWakeMapVariable;
	ID3DX11EffectShaderResourceVariable* m_pRenderSurfaceShipFoamMapVariable;
	ID3DX11EffectMatrixVariable*		 m_pRenderSurfaceWorldToShipVariable;
	ID3DX11EffectShaderResourceVariable* m_pRenderSurfaceGustMapVariable;
	ID3DX11EffectVectorVariable*		 m_pRenderSurfaceGustUVVariable;

	ID3DX11EffectShaderResourceVariable* m_pRenderSurfaceReflectionTextureVariable;
	ID3DX11EffectShaderResourceVariable* m_pRenderSurfaceReflectionDepthTextureVariable;
    ID3DX11EffectShaderResourceVariable* m_pRenderSurfaceReflectionPosTextureVariable;
	ID3DX11EffectVectorVariable*		 m_pRenderSurfaceScreenSizeInvVariable;

	ID3DX11EffectMatrixVariable*		 m_pRenderSurfaceSceneToShadowMapVariable;
	ID3DX11EffectVectorVariable*		 m_pRenderSurfaceLightningPositionVariable;
	ID3DX11EffectVectorVariable*		 m_pRenderSurfaceLightningColorVariable;

	ID3DX11EffectScalarVariable*		 m_pRenderSurfaceCloudFactorVariable;
	ID3DX11EffectScalarVariable*		 m_pRenderSurfaceShowSpraySimVariable;
	ID3DX11EffectScalarVariable*		 m_pRenderSurfaceShowFoamSimVariable;

	ID3DX11EffectScalarVariable*		 m_pRenderSurfaceGustsEnabledVariable;
	ID3DX11EffectScalarVariable*		 m_pRenderSurfaceWakeEnabledVariable;


	// --------------------------------- Rendering routines -----------------------------------

	// Rendering
	void renderShaded(	ID3D11DeviceContext* pDC,
						const D3DXMATRIX& matCameraView, const D3DXMATRIX& matView, const D3DXMATRIX& matProj,
						GFSDK_WaveWorks_SimulationHandle hSim, GFSDK_WaveWorks_SavestateHandle hSavestate,
						const OceanEnvironment& ocean_env,
						BOOL freeze_cam,
						float foam_fade,
						bool show_spray_sim,
						bool show_foam_sim,
						bool gusts_enabled,
						bool wake_enabled
						);
	void renderWireframe(	ID3D11DeviceContext* pDC,
							const D3DXMATRIX& matView, const D3DXMATRIX& matProj,
							GFSDK_WaveWorks_SimulationHandle hSim, GFSDK_WaveWorks_SavestateHandle hSavestate,
							BOOL freeze_cam
							);

    void simulateSprayParticles( ID3D11DeviceContext* pDC, float timeStep );

    void renderSprayParticles(  ID3D11DeviceContext* pDC,
						        const D3DXMATRIX& matView, const D3DXMATRIX& matProj,
						        const OceanEnvironment& ocean_env,
						        BOOL freeze_cam
						        );
	void getQuadTreeStats(GFSDK_WaveWorks_Quadtree_Stats& stats);
	void setHullProfiles(const OceanHullProfile* hullProfiles, UINT NumHullProfiles);
	void setWorldToShipMatrix(const D3DXMATRIX& matShip);

	void beginRenderToLocalFoamMap(ID3D11DeviceContext* pDC, D3DXMATRIX& matWorldToFoam);
	void endRenderToLocalFoamMap(ID3D11DeviceContext* pDC, D3DXVECTOR2 shift_amount, float blur_amount, float fade_amount);

	// --------------------------------- Surface geometry -----------------------------------
	GFSDK_WaveWorks_QuadtreeHandle m_hOceanQuadTree;
	HRESULT initQuadTree(const GFSDK_WaveWorks_Quadtree_Params& params);

	UINT* m_pQuadTreeShaderInputMappings_Shaded;
	UINT* m_pQuadTreeShaderInputMappings_Wireframe;

	UINT* m_pSimulationShaderInputMappings_Shaded;
	UINT* m_pSimulationShaderInputMappings_Wireframe;

	OceanSurfaceState* m_pSurfaceState;

	D3DXMATRIX m_matWorldToShip;

    ID3D11Buffer*               m_pParticlesBuffer[2];
    ID3D11UnorderedAccessView*  m_pParticlesBufferUAV[2];
    ID3D11ShaderResourceView*   m_pParticlesBufferSRV[2];

    UINT                        m_ParticleWriteBuffer;

    ID3D11Buffer*               m_pDrawParticlesCB;
    ID3D11Buffer*               m_pDrawParticlesBuffer;
    ID3D11UnorderedAccessView*  m_pDrawParticlesBufferUAV;
    
    ID3DX11EffectTechnique*     m_pRenderSprayParticlesTechnique;
    ID3DX11EffectTechnique*     m_pSimulateSprayParticlesTechnique;
    ID3DX11EffectTechnique*     m_pDispatchArgumentsTechnique;

    ID3DX11EffectVectorVariable* m_pViewRightVariable;
    ID3DX11EffectVectorVariable* m_pViewUpVariable;
    ID3DX11EffectVectorVariable* m_pViewForwardVariable;
    ID3DX11EffectScalarVariable* m_pTimeStep;

    ID3DX11EffectShaderResourceVariable* m_pParticlesBufferVariable;
};

#endif	// _OCEAN_WAVE_H