117 lines
2.3 KiB
C++
117 lines
2.3 KiB
C++
#pragma once
|
|
|
|
#include <d3d9.h>
|
|
#include <d3dx9.h>
|
|
|
|
struct InstanceData
|
|
{
|
|
float pos[3];
|
|
float size;
|
|
float intensity;
|
|
};
|
|
|
|
struct FluidSettings
|
|
{
|
|
float Softness;
|
|
float LightTransferAmmount;
|
|
float SpecularFactor;
|
|
float SpecularPower;
|
|
float TextureScale;
|
|
float TranslucencyAmmount;
|
|
float SurfaceTension;
|
|
float RefractAmmount;
|
|
int BlurSteps;
|
|
float RenderTextureSizeScale;
|
|
|
|
IDirect3DTexture9* DiffuseTexture;
|
|
};
|
|
|
|
struct Fluid
|
|
{
|
|
FluidSettings Settings;
|
|
|
|
IDirect3DTexture9* renderTexture[4];
|
|
IDirect3DSurface9* renderSurface[4];
|
|
|
|
IDirect3DTexture9* renderTexturePingPong[8];
|
|
IDirect3DSurface9* renderSurfacePingPong[8];
|
|
IDirect3DSurface9* pongPongDepthBuffer;
|
|
|
|
D3DXVECTOR4 renderTargetPingPongDDX;
|
|
};
|
|
|
|
struct FluidParticleSystem
|
|
{
|
|
unsigned int InstanceCount;
|
|
IDirect3DVertexBuffer9* InstanceDataBuffer;
|
|
};
|
|
|
|
class FluidContext
|
|
{
|
|
public:
|
|
void BuildUp(IDirect3DDevice9* device, int screenX, int screenY);
|
|
|
|
void RenderParticles(const FluidParticleSystem& particleInfo);
|
|
|
|
void Begin(const D3DXMATRIX& viewProj, const D3DXMATRIX& view, const D3DXMATRIX& inverseView, const D3DXVECTOR4& eye, const D3DXVECTOR4& eyeDir, const Fluid& fluid);
|
|
void End();
|
|
void Display(const Fluid& fluid, IDirect3DTexture9* backgroundTexture);
|
|
|
|
FluidParticleSystem GenerateFluidParticleSystem(unsigned int instanceCount, InstanceData* initialData = NULL);
|
|
Fluid GenerateFluid(FluidSettings settings);
|
|
ID3DXEffect* effect;
|
|
|
|
private:
|
|
IDirect3DDevice9* d3dDevice;
|
|
IDirect3DVertexDeclaration9* quadVertexDecl;
|
|
IDirect3DVertexDeclaration9* vertexDecl;
|
|
IDirect3DIndexBuffer9* quadIndexBuffer;
|
|
IDirect3DVertexBuffer9* quadVertexBuffer;
|
|
|
|
static const int renderTextureCount = 4; // pos, normal, density, ballpos
|
|
|
|
IDirect3DSurface9* backBufferDepthBuffer;
|
|
IDirect3DSurface9* backBuffer;
|
|
|
|
int renderTargetWidth;
|
|
int renderTargetHeight;
|
|
D3DXVECTOR4 renderTargetDDX;
|
|
|
|
const Fluid* currentFluid;
|
|
};
|
|
|
|
static const float particleQuadVerts[20] =
|
|
{
|
|
-1.0f,-1.0f, 0.0f,
|
|
0.0f, 1.0f,
|
|
|
|
-1.0f, 1.0f, 0.0f,
|
|
0.0f, 0.0f,
|
|
|
|
1.0f, 1.0f, 0.0f,
|
|
1.0f, 0.0f,
|
|
|
|
1.0f, -1.0f, 0.0f,
|
|
1.0f, 1.0f
|
|
};
|
|
|
|
static const float screenQuadVerts[30] =
|
|
{
|
|
-1.0f,-1.0f, 1.0f,
|
|
0.0f, 1.0f,
|
|
|
|
-1.0f, 1.0f, 1.0f,
|
|
0.0f, 0.0f,
|
|
|
|
1.0f, 1.0f, 1.0f,
|
|
1.0f, 0.0f,
|
|
|
|
1.0f, 1.0f, 1.0f,
|
|
1.0f, 0.0f,
|
|
|
|
-1.0f,-1.0f, 1.0f,
|
|
0.0f, 1.0f,
|
|
|
|
1.0f, -1.0f, 1.0f,
|
|
1.0f, 1.0f
|
|
}; |