117 lines
2.1 KiB
C++
117 lines
2.1 KiB
C++
#pragma once
|
|
|
|
#include <d3dx9.h>
|
|
|
|
extern IDirect3DDevice9* g_d3d_device;
|
|
|
|
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;
|
|
float* DepthDifferenceBlur;
|
|
int* BlurSteps;
|
|
float* RenderTextureSizeScale;
|
|
|
|
IDirect3DBaseTexture9* DiffuseTexture;
|
|
};
|
|
|
|
struct Fluid
|
|
{
|
|
FluidSettings Settings;
|
|
|
|
IDirect3DTexture9* renderTexturePingPong[4];
|
|
IDirect3DSurface9* renderSurfacePingPong[4];
|
|
|
|
D3DXVECTOR4 renderTargetPingPongDDX;
|
|
};
|
|
|
|
struct FluidParticleSystem
|
|
{
|
|
bool IsVisible;
|
|
unsigned int InstanceCount;
|
|
IDirect3DVertexBuffer9* InstanceDataBuffer;
|
|
};
|
|
|
|
class FluidContext
|
|
{
|
|
public:
|
|
void BuildUp(int screenX, int screenY, D3DMULTISAMPLE_TYPE multiSampleType);
|
|
|
|
void RenderParticles(const FluidParticleSystem& particleInfo);
|
|
void RenderParticleDepth(const FluidParticleSystem& particleInfo);
|
|
|
|
void Begin(const Fluid& fluid);
|
|
void End();
|
|
void Display(const Fluid& fluid);
|
|
|
|
FluidParticleSystem GenerateFluidParticleSystem(unsigned int instanceCount, InstanceData* initialData = NULL);
|
|
Fluid GenerateFluid(const FluidSettings& settings);
|
|
|
|
static void MeltObject(int objectIndex, int fluidIndex, int pointMapIndex, float time);
|
|
|
|
private:
|
|
IDirect3DVertexDeclaration9* quadVertexDecl;
|
|
IDirect3DVertexDeclaration9* vertexDecl;
|
|
IDirect3DIndexBuffer9* quadIndexBuffer;
|
|
IDirect3DVertexBuffer9* quadVertexBuffer;
|
|
|
|
IDirect3DSurface9* renderSurface;
|
|
|
|
static const int renderTextureCount = 2; // pos, normal
|
|
|
|
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, 1.0f,
|
|
|
|
-1.0f,-1.0f, 1.0f,
|
|
0.0f, 1.0f,
|
|
|
|
1.0f, 1.0f, 1.0f,
|
|
1.0f, 0.0f
|
|
}; |