port from perforce
This commit is contained in:
20
ice/ice.sln
Normal file
20
ice/ice.sln
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 10.00
|
||||
# Visual Studio 2008
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ice", "src/ice.vcproj", "{D91DFF9F-B3F5-4F75-AD44-19AD5F1DEB00}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Release|Win32 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{D91DFF9F-B3F5-4F75-AD44-19AD5F1DEB00}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{D91DFF9F-B3F5-4F75-AD44-19AD5F1DEB00}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{D91DFF9F-B3F5-4F75-AD44-19AD5F1DEB00}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{D91DFF9F-B3F5-4F75-AD44-19AD5F1DEB00}.Release|Win32.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
BIN
ice/ice.suo
Normal file
BIN
ice/ice.suo
Normal file
Binary file not shown.
BIN
ice/link.exe
Normal file
BIN
ice/link.exe
Normal file
Binary file not shown.
BIN
ice/shader2h.exe
Normal file
BIN
ice/shader2h.exe
Normal file
Binary file not shown.
279
ice/src/FluidContext.cpp
Normal file
279
ice/src/FluidContext.cpp
Normal file
@@ -0,0 +1,279 @@
|
||||
#include "FluidContext.h"
|
||||
|
||||
#define RENDER(c) \
|
||||
{\
|
||||
unsigned int passes;\
|
||||
effect->Begin(&passes, 0);\
|
||||
effect->BeginPass(0);\
|
||||
c;\
|
||||
effect->EndPass();\
|
||||
effect->End();\
|
||||
}
|
||||
|
||||
void FluidContext::BuildUp(IDirect3DDevice9* device, int screenX, int screenY)
|
||||
{
|
||||
d3dDevice = device;
|
||||
currentFluid = NULL;
|
||||
|
||||
#if _DEBUG
|
||||
ID3DXBuffer* errors = NULL;
|
||||
DWORD hr = ::D3DXCreateEffectFromFile(d3dDevice, L"shader.hlsl", NULL, NULL, D3DXSHADER_DEBUG, NULL, &effect, &errors);
|
||||
if (errors != 0 && hr != 0)
|
||||
{
|
||||
OutputDebugStringA((char*)errors->GetBufferPointer());
|
||||
errors->Release();
|
||||
DebugBreak();
|
||||
}
|
||||
if (effect == NULL)
|
||||
DebugBreak();
|
||||
#else
|
||||
::D3DXCreateEffectFromFile(d3dDevice, L"shader.hlsl", NULL, NULL, 0, NULL, &effect, NULL);
|
||||
#endif
|
||||
|
||||
D3DVERTEXELEMENT9 decl[] =
|
||||
{
|
||||
{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
|
||||
{0, 12, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0},
|
||||
{1, 0, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
|
||||
{1, 16, D3DDECLTYPE_FLOAT1, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1},
|
||||
D3DDECL_END()
|
||||
};
|
||||
|
||||
d3dDevice->CreateVertexDeclaration(decl, &vertexDecl);
|
||||
|
||||
D3DVERTEXELEMENT9 quadDecl[] =
|
||||
{
|
||||
{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
|
||||
{0, 12, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
|
||||
D3DDECL_END()
|
||||
};
|
||||
|
||||
d3dDevice->CreateVertexDeclaration(quadDecl, &quadVertexDecl);
|
||||
float* quadData;
|
||||
d3dDevice->CreateVertexBuffer(sizeof(float) * 20, D3DUSAGE_WRITEONLY, 0, D3DPOOL_MANAGED, &quadVertexBuffer, NULL);
|
||||
quadVertexBuffer->Lock(0, sizeof(float) * 20, (void**)&quadData, 0);
|
||||
::memcpy(quadData, particleQuadVerts, sizeof(float) * 20);
|
||||
quadVertexBuffer->Unlock();
|
||||
|
||||
int* quadIndexData;
|
||||
d3dDevice->CreateIndexBuffer(6 * sizeof(int), D3DUSAGE_WRITEONLY, D3DFMT_INDEX32, D3DPOOL_MANAGED, &quadIndexBuffer, NULL);
|
||||
quadIndexBuffer->Lock(0, 0, (void**)&quadIndexData, 0);
|
||||
quadIndexData[0] = 0;
|
||||
quadIndexData[1] = 1;
|
||||
quadIndexData[2] = 2;
|
||||
quadIndexData[3] = 2;
|
||||
quadIndexData[4] = 0;
|
||||
quadIndexData[5] = 3;
|
||||
quadIndexBuffer->Unlock();
|
||||
|
||||
// build up the render targets
|
||||
renderTargetWidth = screenX;
|
||||
renderTargetHeight = screenY;
|
||||
renderTargetDDX = D3DXVECTOR4(1.0f / renderTargetWidth, 1.0f / renderTargetHeight, 0.00f, 0.0f );
|
||||
|
||||
d3dDevice->GetRenderTarget(0, &backBuffer);
|
||||
d3dDevice->GetDepthStencilSurface(&backBufferDepthBuffer);
|
||||
}
|
||||
|
||||
void FluidContext::RenderParticles(const FluidParticleSystem& particleInfo)
|
||||
{
|
||||
d3dDevice->SetStreamSource(0, quadVertexBuffer, 0, sizeof(float) * 5);
|
||||
d3dDevice->SetStreamSourceFreq(0, D3DSTREAMSOURCE_INDEXEDDATA | particleInfo.InstanceCount);
|
||||
|
||||
d3dDevice->SetStreamSource(1, particleInfo.InstanceDataBuffer, 0, sizeof(InstanceData));
|
||||
d3dDevice->SetStreamSourceFreq(1, D3DSTREAMSOURCE_INSTANCEDATA | 1ul);
|
||||
|
||||
d3dDevice->SetVertexDeclaration(vertexDecl);
|
||||
d3dDevice->SetIndices(quadIndexBuffer);
|
||||
|
||||
// Begin
|
||||
{
|
||||
effect->SetTechnique("Deferred");
|
||||
|
||||
effect->SetTexture("positionTexture", NULL);
|
||||
effect->SetTexture("normalTexture", NULL);
|
||||
|
||||
d3dDevice->SetRenderTarget(0, currentFluid->renderSurface[0]);
|
||||
d3dDevice->SetRenderTarget(1, currentFluid->renderSurface[1]);
|
||||
|
||||
d3dDevice->BeginScene();
|
||||
d3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x0, 1.0f, 0);
|
||||
|
||||
RENDER(d3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 4, 0, 2));
|
||||
|
||||
d3dDevice->EndScene();
|
||||
}
|
||||
|
||||
{
|
||||
effect->SetTechnique("Density");
|
||||
|
||||
d3dDevice->SetRenderTarget(0, currentFluid->renderSurface[2]);
|
||||
d3dDevice->SetRenderTarget(1, NULL);
|
||||
|
||||
d3dDevice->BeginScene();
|
||||
d3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x0, 1.0f, 0);
|
||||
|
||||
RENDER(d3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 4, 0, 2));
|
||||
|
||||
d3dDevice->EndScene();
|
||||
}
|
||||
|
||||
{
|
||||
effect->SetTechnique("ParticlePosition");
|
||||
|
||||
d3dDevice->SetRenderTarget(0, currentFluid->renderSurface[3]);
|
||||
d3dDevice->SetRenderTarget(1, NULL);
|
||||
|
||||
d3dDevice->BeginScene();
|
||||
d3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x0, 1.0f, 0);
|
||||
|
||||
RENDER(d3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 4, 0, 2));
|
||||
|
||||
d3dDevice->EndScene();
|
||||
}
|
||||
|
||||
d3dDevice->SetStreamSourceFreq(0, 1);
|
||||
d3dDevice->SetStreamSourceFreq(1, 1);
|
||||
}
|
||||
|
||||
|
||||
void FluidContext::Begin(const D3DXMATRIX& viewProj, const D3DXMATRIX& view, const D3DXMATRIX& inverseView, const D3DXVECTOR4& eye, const D3DXVECTOR4& eyeDir, const Fluid& fluid)
|
||||
{
|
||||
currentFluid = &fluid;
|
||||
|
||||
effect->SetMatrix("viewProj", &viewProj);
|
||||
effect->SetMatrix("view", &view);
|
||||
effect->SetMatrix("inverseView", &inverseView);
|
||||
effect->SetVector("eye", &eye);
|
||||
effect->SetVector("eyeDir", &eyeDir);
|
||||
|
||||
effect->SetValue("softness", &fluid.Settings.Softness, sizeof(fluid.Settings.Softness));
|
||||
effect->SetValue("lightTransferAmmount", &fluid.Settings.LightTransferAmmount, sizeof(fluid.Settings.LightTransferAmmount));
|
||||
effect->SetValue("specularFactor", &fluid.Settings.SpecularFactor, sizeof(fluid.Settings.SpecularFactor));
|
||||
effect->SetValue("specularPower", &fluid.Settings.SpecularPower, sizeof(fluid.Settings.SpecularPower));
|
||||
effect->SetValue("translucencyAmmount", &fluid.Settings.TranslucencyAmmount, sizeof(fluid.Settings.TranslucencyAmmount));
|
||||
effect->SetValue("textureScale", &fluid.Settings.TextureScale, sizeof(fluid.Settings.TextureScale));
|
||||
effect->SetValue("surfaceTension", &fluid.Settings.SurfaceTension, sizeof(fluid.Settings.SurfaceTension));
|
||||
effect->SetValue("refractAmmount", &fluid.Settings.RefractAmmount, sizeof(fluid.Settings.RefractAmmount));
|
||||
}
|
||||
|
||||
|
||||
void FluidContext::End()
|
||||
{
|
||||
d3dDevice->SetStreamSourceFreq(0, 1);
|
||||
d3dDevice->SetStreamSourceFreq(1, 1);
|
||||
|
||||
d3dDevice->SetVertexDeclaration(quadVertexDecl);
|
||||
effect->SetVector("quadddx", ¤tFluid->renderTargetPingPongDDX);
|
||||
|
||||
// blur
|
||||
{
|
||||
effect->SetTechnique("Blur");
|
||||
|
||||
for (int k = 0; k < currentFluid->Settings.BlurSteps * 2; ++k)
|
||||
{
|
||||
d3dDevice->SetRenderTarget(0, currentFluid->renderSurfacePingPong[0 + ((k+1)%2)]);
|
||||
d3dDevice->SetRenderTarget(1, currentFluid->renderSurfacePingPong[2 + ((k+1)%2)]);
|
||||
d3dDevice->SetRenderTarget(2, currentFluid->renderSurfacePingPong[4 + ((k+1)%2)]);
|
||||
d3dDevice->SetRenderTarget(3, currentFluid->renderSurfacePingPong[6 + ((k+1)%2)]);
|
||||
|
||||
effect->SetVector("ddx", k == 0 ? &renderTargetDDX : ¤tFluid->renderTargetPingPongDDX);
|
||||
effect->SetTexture("positionTexture", k == 0 ? currentFluid->renderTexture[0] : currentFluid->renderTexturePingPong[0 + k%2]);
|
||||
effect->SetTexture("normalTexture", k == 0 ? currentFluid->renderTexture[1] : currentFluid->renderTexturePingPong[2 + k%2]);
|
||||
effect->SetTexture("densityTexture", k == 0 ? currentFluid->renderTexture[2] : currentFluid->renderTexturePingPong[4 + k%2]);
|
||||
effect->SetTexture("particlePositionTexture", k == 0 ? currentFluid->renderTexture[3] : currentFluid->renderTexturePingPong[6 + k%2]);
|
||||
|
||||
d3dDevice->BeginScene();
|
||||
d3dDevice->Clear(0, NULL, D3DCLEAR_ZBUFFER, 0x0, 1.0f, 0);
|
||||
RENDER(d3dDevice->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 2, screenQuadVerts, 20));
|
||||
d3dDevice->EndScene();
|
||||
}
|
||||
}
|
||||
|
||||
currentFluid = NULL;
|
||||
}
|
||||
|
||||
|
||||
void FluidContext::Display(const Fluid& fluid, IDirect3DTexture9* backgroundTexture)
|
||||
{
|
||||
effect->SetTexture("backgroundTexture", backgroundTexture);
|
||||
#ifdef _DEBUG
|
||||
if (GetAsyncKeyState(VK_SPACE))
|
||||
effect->SetTechnique("ComposeDebug");
|
||||
else
|
||||
#endif
|
||||
effect->SetTechnique("Compose");
|
||||
|
||||
effect->SetTexture("positionTexture", fluid.renderTexturePingPong[1]);
|
||||
effect->SetTexture("normalTexture", fluid.renderTexturePingPong[3]);
|
||||
effect->SetTexture("densityTexture", fluid.renderTexturePingPong[5]);
|
||||
effect->SetTexture("particlePositionTexture", fluid.renderTexturePingPong[7]);
|
||||
effect->SetTexture("diffuseTexture", fluid.Settings.DiffuseTexture);
|
||||
|
||||
d3dDevice->SetRenderTarget(0, backBuffer);
|
||||
d3dDevice->SetRenderTarget(1, NULL);
|
||||
d3dDevice->SetRenderTarget(2, NULL);
|
||||
d3dDevice->SetRenderTarget(3, NULL);
|
||||
|
||||
d3dDevice->BeginScene();
|
||||
d3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x0, 1.0f, 0);
|
||||
RENDER(d3dDevice->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 2, screenQuadVerts, 20));
|
||||
d3dDevice->EndScene();
|
||||
}
|
||||
|
||||
|
||||
FluidParticleSystem FluidContext::GenerateFluidParticleSystem(unsigned int instanceCount, InstanceData* initialData)
|
||||
{
|
||||
FluidParticleSystem result;
|
||||
result.InstanceCount = instanceCount;
|
||||
|
||||
InstanceData* instanceData;
|
||||
d3dDevice->CreateVertexBuffer(sizeof(InstanceData) * instanceCount, D3DUSAGE_WRITEONLY, D3DFVF_TEX1, D3DPOOL_MANAGED, &result.InstanceDataBuffer, NULL);
|
||||
if (initialData != NULL)
|
||||
{
|
||||
result.InstanceDataBuffer->Lock(0, sizeof(InstanceData) * instanceCount, (void**)&instanceData, 0);
|
||||
::memcpy(instanceData, initialData, sizeof(InstanceData) * instanceCount);
|
||||
result.InstanceDataBuffer->Unlock();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Fluid FluidContext::GenerateFluid(FluidSettings settings)
|
||||
{
|
||||
Fluid result;
|
||||
result.Settings = settings;
|
||||
result.renderTargetPingPongDDX = D3DXVECTOR4( 1.0f / (renderTargetWidth * settings.RenderTextureSizeScale), 1.0f / (renderTargetHeight * settings.RenderTextureSizeScale), 0.0f, 0.0f );
|
||||
|
||||
for (int i = 0; i < renderTextureCount; ++i)
|
||||
{
|
||||
d3dDevice->CreateTexture(renderTargetWidth,
|
||||
renderTargetHeight,
|
||||
1,
|
||||
D3DUSAGE_RENDERTARGET,
|
||||
D3DFMT_A16B16G16R16F,
|
||||
D3DPOOL_DEFAULT,
|
||||
&result.renderTexture[i],
|
||||
NULL);
|
||||
result.renderTexture[i]->GetSurfaceLevel(0, &result.renderSurface[i]);
|
||||
|
||||
for (int k = 0; k < 2; ++k)
|
||||
{
|
||||
d3dDevice->CreateTexture((UINT)(renderTargetWidth * settings.RenderTextureSizeScale),
|
||||
(UINT)(renderTargetHeight * settings.RenderTextureSizeScale),
|
||||
1,
|
||||
D3DUSAGE_RENDERTARGET,
|
||||
D3DFMT_A16B16G16R16F,
|
||||
D3DPOOL_DEFAULT,
|
||||
&result.renderTexturePingPong[i * 2 + k],
|
||||
NULL);
|
||||
result.renderTexturePingPong[i * 2 + k]->GetSurfaceLevel(0, &result.renderSurfacePingPong[i * 2 + k]);
|
||||
}
|
||||
}
|
||||
|
||||
d3dDevice->CreateDepthStencilSurface((UINT)(renderTargetWidth * settings.RenderTextureSizeScale),
|
||||
(UINT)(renderTargetHeight * settings.RenderTextureSizeScale), D3DFMT_D24S8, D3DMULTISAMPLE_NONE, 0, false, &result.pongPongDepthBuffer, NULL);
|
||||
|
||||
return result;
|
||||
}
|
||||
117
ice/src/FluidContext.h
Normal file
117
ice/src/FluidContext.h
Normal file
@@ -0,0 +1,117 @@
|
||||
#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
|
||||
};
|
||||
BIN
ice/src/Lighthouse.jpg
Normal file
BIN
ice/src/Lighthouse.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 548 KiB |
109
ice/src/PointMapGenerator.cpp
Normal file
109
ice/src/PointMapGenerator.cpp
Normal file
@@ -0,0 +1,109 @@
|
||||
#include "PointMapGenerator.h"
|
||||
|
||||
|
||||
int PointMapGenerator::GeneratePointMap(IDirect3DVertexBuffer9* vertexBuffer, IDirect3DIndexBuffer9* indexBuffer, int faceCount, int vertexStride, int positionOffset, float pointDensity, D3DXVECTOR3* outPointMap)
|
||||
{
|
||||
char* vertexData;
|
||||
PMG_INDEX_FORMAT* indexData;
|
||||
vertexBuffer->Lock(0, 0, (void**)&vertexData, D3DLOCK_READONLY);
|
||||
indexBuffer->Lock(0, 0, (void**)&indexData, D3DLOCK_READONLY);
|
||||
|
||||
int pointCount = GeneratePointMap(vertexData, indexData, faceCount, vertexStride, positionOffset, pointDensity, outPointMap);
|
||||
|
||||
vertexBuffer->Unlock();
|
||||
indexBuffer->Unlock();
|
||||
|
||||
return pointCount;
|
||||
}
|
||||
|
||||
|
||||
int PointMapGenerator::GeneratePointMap(IDirect3DVertexBuffer9* vertexBuffer, IDirect3DIndexBuffer9* indexBuffer, int faceCount, int vertexStride, int positionOffset, D3DXVECTOR3 boundingBoxSize[2], float pointDensity, D3DXVECTOR3* outPointMap)
|
||||
{
|
||||
char* vertexData;
|
||||
PMG_INDEX_FORMAT* indexData;
|
||||
vertexBuffer->Lock(0, 0, (void**)&vertexData, D3DLOCK_READONLY);
|
||||
indexBuffer->Lock(0, 0, (void**)&indexData, D3DLOCK_READONLY);
|
||||
|
||||
int pointCount = GeneratePointMap(vertexData, indexData, faceCount, vertexStride, positionOffset, boundingBoxSize, pointDensity, outPointMap);
|
||||
|
||||
vertexBuffer->Unlock();
|
||||
indexBuffer->Unlock();
|
||||
|
||||
return pointCount;
|
||||
}
|
||||
|
||||
|
||||
int PointMapGenerator::GeneratePointMap(char* vertexData, PMG_INDEX_FORMAT* indexData, int faceCount, int vertexStride, int positionOffset, float pointDensity, D3DXVECTOR3* outPointMap)
|
||||
{
|
||||
D3DXVECTOR3 boundingBoxSize[2];
|
||||
EstimateBoundingBoxSize(vertexData, indexData, faceCount, vertexStride, positionOffset, boundingBoxSize[0], boundingBoxSize[1]);
|
||||
return GeneratePointMap(vertexData, indexData, faceCount, vertexStride, positionOffset, boundingBoxSize, pointDensity, outPointMap);
|
||||
}
|
||||
|
||||
|
||||
int PointMapGenerator::GeneratePointMap(char* vertexData, PMG_INDEX_FORMAT* indexData, int faceCount, int vertexStride, int positionOffset, D3DXVECTOR3 boundingBoxSize[2], float pointDensity, D3DXVECTOR3* outPointMap)
|
||||
{
|
||||
int pointCount = 0;
|
||||
|
||||
for (float x = boundingBoxSize[0].x; x <= boundingBoxSize[1].x; x += pointDensity)
|
||||
for (float y = boundingBoxSize[0].y; y <= boundingBoxSize[1].y; y += pointDensity)
|
||||
for (float z = boundingBoxSize[0].z; z <= boundingBoxSize[1].z; z += pointDensity)
|
||||
{
|
||||
D3DXVECTOR3 position = D3DXVECTOR3(x, y, z);
|
||||
if (IsPointInside(vertexData, indexData, faceCount, vertexStride, positionOffset, position))
|
||||
{
|
||||
outPointMap[pointCount ++] = position;
|
||||
}
|
||||
}
|
||||
|
||||
return pointCount;
|
||||
}
|
||||
|
||||
|
||||
bool PointMapGenerator::IsPointInside(char* vertexData, PMG_INDEX_FORMAT* indexData, int faceCount, int vertexStride, int positionOffset, D3DXVECTOR3 point)
|
||||
{
|
||||
int hitCount = 0;
|
||||
float dist;
|
||||
BOOL hitSomething = FALSE;
|
||||
D3DXVECTOR3 rayDir = D3DXVECTOR3(0.0f, 0.0f, -1.0f);
|
||||
for (int i = 0; i < faceCount; ++i)
|
||||
{
|
||||
PMG_INDEX_FORMAT* index = &indexData[i * 3];
|
||||
|
||||
D3DXVECTOR3* v1 = (D3DXVECTOR3*)&vertexData[index[0] * vertexStride + positionOffset];
|
||||
D3DXVECTOR3* v2 = (D3DXVECTOR3*)&vertexData[index[1] * vertexStride + positionOffset];
|
||||
D3DXVECTOR3* v3 = (D3DXVECTOR3*)&vertexData[index[2] * vertexStride + positionOffset];
|
||||
|
||||
hitSomething = ::D3DXIntersectTri(v1, v2, v3, &point, &rayDir, NULL, NULL, &dist);
|
||||
if (hitSomething)
|
||||
hitCount ++;
|
||||
}
|
||||
|
||||
return hitCount % 2 != 0;
|
||||
}
|
||||
|
||||
|
||||
void PointMapGenerator::EstimateBoundingBoxSize(char* vertexData, PMG_INDEX_FORMAT* indexData, int faceCount, int vertexStride, int positionOffset, D3DXVECTOR3& minSize, D3DXVECTOR3& maxSize)
|
||||
{
|
||||
maxSize = minSize = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
|
||||
for (int i = 0; i < faceCount * 3; ++i)
|
||||
{
|
||||
D3DXVECTOR3* v = (D3DXVECTOR3*)&vertexData[indexData[i] * vertexStride + positionOffset];
|
||||
D3DXVECTOR3 tmp = *v;
|
||||
|
||||
if (i == 0)
|
||||
{
|
||||
minSize = maxSize = tmp;
|
||||
}
|
||||
else
|
||||
{
|
||||
minSize.x = min(minSize.x, tmp.x);
|
||||
minSize.y = min(minSize.y, tmp.y);
|
||||
minSize.z = min(minSize.z, tmp.z);
|
||||
|
||||
maxSize.x = max(maxSize.x, tmp.x);
|
||||
maxSize.y = max(maxSize.y, tmp.y);
|
||||
maxSize.z = max(maxSize.z, tmp.z);
|
||||
}
|
||||
}
|
||||
}
|
||||
19
ice/src/PointMapGenerator.h
Normal file
19
ice/src/PointMapGenerator.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <d3d9.h>
|
||||
#include <d3dx9.h>
|
||||
|
||||
#define PMG_INDEX_FORMAT short
|
||||
|
||||
class PointMapGenerator
|
||||
{
|
||||
public:
|
||||
static int GeneratePointMap(IDirect3DVertexBuffer9* vertexBuffer, IDirect3DIndexBuffer9* indexBuffer, int faceCount, int vertexStride, int positionOffset, float pointDensity, D3DXVECTOR3* outPointMap);
|
||||
static int GeneratePointMap(IDirect3DVertexBuffer9* vertexBuffer, IDirect3DIndexBuffer9* indexBuffer, int faceCount, int vertexStride, int positionOffset, D3DXVECTOR3 boundingBoxSize[2], float pointDensity, D3DXVECTOR3* outPointMap);
|
||||
static int GeneratePointMap(char* vertexData, PMG_INDEX_FORMAT* indexData, int faceCount, int vertexStride, int positionOffset, float pointDensity, D3DXVECTOR3* outPointMap);
|
||||
static int GeneratePointMap(char* vertexData, PMG_INDEX_FORMAT* indexData, int faceCount, int vertexStride, int positionOffset, D3DXVECTOR3 boundingBoxSize[2], float pointDensity, D3DXVECTOR3* outPointMap);
|
||||
|
||||
private:
|
||||
static bool IsPointInside(char* vertexData, PMG_INDEX_FORMAT* indexData, int faceCount, int vertexStride, int positionOffset, D3DXVECTOR3 point);
|
||||
static void EstimateBoundingBoxSize(char* vertexData, PMG_INDEX_FORMAT* indexData, int faceCount, int vertexStride, int positionOffset, D3DXVECTOR3& minSize, D3DXVECTOR3& maxSize);
|
||||
};
|
||||
17
ice/src/debug.h
Normal file
17
ice/src/debug.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define COMPILE_SHADER(entry, profile, buffer) \
|
||||
{ \
|
||||
ID3DXBuffer* errors = 0; \
|
||||
D3DXCompileShader(shaderCode, shaderSize, 0, 0, entry, profile, D3DXSHADER_DEBUG, buffer, &errors, 0); \
|
||||
if (errors != 0) \
|
||||
{ \
|
||||
OutputDebugStringA((char*)errors->GetBufferPointer()); \
|
||||
errors->Release(); \
|
||||
DebugBreak(); \
|
||||
} \
|
||||
}
|
||||
#else
|
||||
#define COMPILE_SHADER(entry, profile, buffer) D3DXCompileShader(shaderCode, shaderSize, 0, 0, entry, profile, 0, buffer, 0, 0);
|
||||
#endif
|
||||
BIN
ice/src/grass.png
Normal file
BIN
ice/src/grass.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 763 KiB |
159
ice/src/ice.cpp
Normal file
159
ice/src/ice.cpp
Normal file
@@ -0,0 +1,159 @@
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_EXTRA_LEAN
|
||||
#include <windows.h>
|
||||
#include <d3d9.h>
|
||||
#include <d3dx9.h>
|
||||
#include "variables.h"
|
||||
#include "debug.h"
|
||||
#include "FluidContext.h"
|
||||
#include "PointMapGenerator.h"
|
||||
|
||||
|
||||
#pragma bss_seg("._fltused")
|
||||
extern "C" int _fltused = 0;
|
||||
|
||||
#define RENDER(c) \
|
||||
{\
|
||||
unsigned int passes;\
|
||||
effect->Begin(&passes, 0);\
|
||||
effect->BeginPass(0);\
|
||||
c;\
|
||||
effect->EndPass();\
|
||||
effect->End();\
|
||||
}
|
||||
|
||||
#pragma code_seg(".main")
|
||||
|
||||
static D3DXVECTOR3 pointMap[100000];
|
||||
|
||||
void main(void)
|
||||
{
|
||||
d3d = Direct3DCreate9(D3D_SDK_VERSION);
|
||||
devParams.hDeviceWindow = CreateWindowExA(0, "static", 0, WS_POPUP | WS_VISIBLE, 0, 0, screenX, screenY, 0, 0, 0, 0);
|
||||
d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, devParams.hDeviceWindow, D3DCREATE_HARDWARE_VERTEXPROCESSING, &devParams, &d3dDevice);
|
||||
|
||||
IDirect3DTexture9* texture;
|
||||
D3DXCreateTextureFromFile(d3dDevice, L"grass.png", &texture);
|
||||
|
||||
IDirect3DTexture9* backgroundTexture;
|
||||
D3DXCreateTextureFromFile(d3dDevice, L"Lighthouse.jpg", &backgroundTexture);
|
||||
|
||||
ID3DXMesh* teapot;
|
||||
::D3DXCreateTeapot(d3dDevice, &teapot, NULL);
|
||||
|
||||
IDirect3DVertexBuffer9* teapotVB;
|
||||
IDirect3DIndexBuffer9* teapotIB;
|
||||
teapot->GetVertexBuffer(&teapotVB);
|
||||
teapot->GetIndexBuffer(&teapotIB);
|
||||
|
||||
float pointMapDensity = 0.05f;
|
||||
int pointCount = PointMapGenerator::GeneratePointMap(teapotVB, teapotIB, teapot->GetNumFaces(), teapot->GetNumBytesPerVertex(), 0, pointMapDensity, pointMap);
|
||||
|
||||
ShowCursor(0);
|
||||
|
||||
// build up the fluid stuff
|
||||
FluidContext fluidContext;
|
||||
fluidContext.BuildUp(d3dDevice, screenX, screenY);
|
||||
FluidSettings fluidSettings;
|
||||
fluidSettings.BlurSteps = 5;
|
||||
fluidSettings.DiffuseTexture = texture;
|
||||
fluidSettings.LightTransferAmmount = 8.25f;
|
||||
fluidSettings.Softness = 3.0f;
|
||||
fluidSettings.SpecularFactor = 2.0f;
|
||||
fluidSettings.SpecularPower = 16.0f;
|
||||
fluidSettings.SurfaceTension = 0.1f;
|
||||
fluidSettings.TextureScale = 50.0f;
|
||||
fluidSettings.TranslucencyAmmount = 0.0f;
|
||||
fluidSettings.RefractAmmount = 0.5;
|
||||
fluidSettings.RenderTextureSizeScale = 0.5;
|
||||
Fluid fluid = fluidContext.GenerateFluid(fluidSettings);
|
||||
FluidParticleSystem particleSystem = fluidContext.GenerateFluidParticleSystem(pointCount);
|
||||
|
||||
// initial fill the particle system
|
||||
InstanceData* instanceData;
|
||||
particleSystem.InstanceDataBuffer->Lock(0, sizeof(InstanceData) * particleSystem.InstanceCount, (void**)&instanceData, 0);//D3DLOCK_DISCARD);
|
||||
const float posFactor = 3.0f;
|
||||
for (unsigned int i = 0; i < particleSystem.InstanceCount; ++i)
|
||||
{
|
||||
//float r = (((rand() % 1000) / 1000.0f - 0.5f) + 2 ) * posFactor;
|
||||
//float h = ((rand() % 1000) / 1000.0f - 0.5f) * posFactor * 0.5f;
|
||||
//float d = ((rand() % 1000) / 1000.0f - 0.5f) * 3.141f * 2;
|
||||
//float x = sin(d) * r;
|
||||
//float y = cos(d) * r;
|
||||
//float z = h;
|
||||
|
||||
//instanceData[i].pos[0] = x;
|
||||
//instanceData[i].pos[1] = y;
|
||||
//instanceData[i].pos[2] = z;
|
||||
//instanceData[i].pos[3] = (r - 1.5f) * 3 * (rand() % 900) / 900.0f * 0.25f + 0.1f; // scale
|
||||
|
||||
instanceData[i].pos[0] = (pointMap[i].x + pointMapDensity * ((rand() % 1000) / 1000.0f - 0.5f) ) * posFactor;
|
||||
instanceData[i].pos[1] = (pointMap[i].y + pointMapDensity * ((rand() % 1000) / 1000.0f - 0.5f) ) * posFactor;
|
||||
instanceData[i].pos[2] = (pointMap[i].z + pointMapDensity * ((rand() % 1000) / 1000.0f - 0.5f) ) * posFactor;
|
||||
|
||||
/*instanceData[i].pos[0] = pointMap[i].x * posFactor;
|
||||
instanceData[i].pos[1] = pointMap[i].y * posFactor;
|
||||
instanceData[i].pos[2] = pointMap[i].z * posFactor;*/
|
||||
|
||||
instanceData[i].size = 0.5f;
|
||||
instanceData[i].intensity = 0.5;
|
||||
}
|
||||
particleSystem.InstanceDataBuffer->Unlock();
|
||||
|
||||
d3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
|
||||
|
||||
do
|
||||
{
|
||||
const float t = GetTickCount() / 1000.0f;
|
||||
|
||||
// Fill pos/depth and normal/matId
|
||||
D3DXMATRIX view;
|
||||
D3DXMATRIX inverseView;
|
||||
D3DXMATRIX proj;
|
||||
D3DXMATRIX viewProj;
|
||||
//D3DXVECTOR3 eye(0, 0, 10.0f);
|
||||
float dist = 10.0f;
|
||||
D3DXVECTOR3 eye(cos(t * 0.1f) * dist, sin(t * 0.1f) * dist, sin(t * 0.1f) * dist);
|
||||
//D3DXVECTOR3 eye(cos(t) * 10, sin(t) * 5, 5.0f);
|
||||
D3DXVECTOR4 eye4(eye.x, eye.y, eye.z, 0.0f);
|
||||
D3DXVECTOR3 at(0.0f, 0.0f, 0.0f);
|
||||
D3DXVECTOR3 up(0.0f, 1.0f, 0.0f);
|
||||
D3DXVECTOR3 right, direction;
|
||||
D3DXVec3Subtract(&direction, &at, &eye);
|
||||
D3DXVec3Normalize(&direction, &direction);
|
||||
D3DXVec3Cross(&right, &direction, &up);
|
||||
D3DXVec3Cross(&up, &right, &direction);
|
||||
D3DXMatrixLookAtLH(&view, &eye, &at, &up);
|
||||
D3DXMatrixPerspectiveFovLH(&proj, D3DX_PI / 4.0f, 4.0f/3.0f, 1.0f, 100.0f);
|
||||
D3DXMatrixMultiply(&viewProj, &view, &proj);
|
||||
D3DXVECTOR4 direction4(direction.x, direction.y, direction.z, 0.0f);
|
||||
D3DXMatrixInverse(&inverseView, NULL, &view);
|
||||
|
||||
fluidContext.Begin(viewProj, view, inverseView, eye4, direction4, fluid);
|
||||
fluidContext.RenderParticles(particleSystem);
|
||||
fluidContext.End();
|
||||
fluidContext.Display(fluid, backgroundTexture);
|
||||
|
||||
d3dDevice->Present(NULL, NULL, NULL, NULL);
|
||||
|
||||
// move particle
|
||||
/*particleSystem.InstanceDataBuffer->Lock(0, sizeof(InstanceData) * particleSystem.InstanceCount, (void**)&instanceData, 0);
|
||||
for (unsigned int i = 0; i < particleSystem.InstanceCount; ++i)
|
||||
{
|
||||
D3DXVECTOR2 pos(instanceData[i].pos[0], instanceData[i].pos[1]);
|
||||
float r = D3DXVec2Length(&pos);
|
||||
float d = atan2(pos.x, pos.y);
|
||||
d += (r - 1.5f) / 2.0f * 0.001f;
|
||||
|
||||
float x = sin(d) * r;
|
||||
float y = cos(d) * r;
|
||||
|
||||
instanceData[i].pos[0] = x;
|
||||
instanceData[i].pos[1] = y;
|
||||
}
|
||||
particleSystem.InstanceDataBuffer->Unlock();*/
|
||||
} while (!GetAsyncKeyState(VK_ESCAPE));
|
||||
|
||||
ExitProcess(0);
|
||||
}
|
||||
|
||||
345
ice/src/ice.cpp.old
Normal file
345
ice/src/ice.cpp.old
Normal file
@@ -0,0 +1,345 @@
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_EXTRA_LEAN
|
||||
#include <windows.h>
|
||||
#include <d3d9.h>
|
||||
#include <d3dx9.h>
|
||||
#include "variables.h"
|
||||
#include "debug.h"
|
||||
|
||||
|
||||
#pragma bss_seg("._fltused")
|
||||
extern "C" int _fltused = 0;
|
||||
|
||||
#define RENDER(c) \
|
||||
{\
|
||||
unsigned int passes;\
|
||||
effect->Begin(&passes, 0);\
|
||||
effect->BeginPass(0);\
|
||||
c;\
|
||||
effect->EndPass();\
|
||||
effect->End();\
|
||||
}
|
||||
|
||||
#pragma code_seg(".main")
|
||||
void main(void)
|
||||
{
|
||||
d3d = Direct3DCreate9(D3D_SDK_VERSION);
|
||||
devParams.hDeviceWindow = CreateWindowExA(0, "static", 0, WS_POPUP | WS_VISIBLE, 0, 0, screenX, screenY, 0, 0, 0, 0);
|
||||
d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, devParams.hDeviceWindow, D3DCREATE_HARDWARE_VERTEXPROCESSING, &devParams, &d3dDevice);
|
||||
|
||||
IDirect3DTexture9* texture;
|
||||
D3DXCreateTextureFromFile(d3dDevice, L"grass.png", &texture);
|
||||
|
||||
IDirect3DTexture9* backgroundTexture;
|
||||
D3DXCreateTextureFromFile(d3dDevice, L"Lighthouse.jpg", &backgroundTexture);
|
||||
|
||||
ID3DXEffect* effect = NULL;
|
||||
ID3DXBuffer* errors = NULL;
|
||||
DWORD hr = ::D3DXCreateEffectFromFile(d3dDevice, L"shader.hlsl", NULL, NULL, D3DXSHADER_DEBUG, NULL, &effect, &errors);
|
||||
if (errors != 0 && hr != 0)
|
||||
{
|
||||
OutputDebugStringA((char*)errors->GetBufferPointer());
|
||||
errors->Release();
|
||||
DebugBreak();
|
||||
}
|
||||
if (effect == NULL)
|
||||
DebugBreak();
|
||||
|
||||
ShowCursor(0);
|
||||
|
||||
/*D3DVERTEXELEMENT9 decl[] =
|
||||
{
|
||||
{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
|
||||
{0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0},
|
||||
{1, 0, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
|
||||
{1, 16, D3DDECLTYPE_FLOAT1, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1},
|
||||
D3DDECL_END()
|
||||
};*/
|
||||
|
||||
D3DVERTEXELEMENT9 decl[] =
|
||||
{
|
||||
{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
|
||||
{0, 12, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0},
|
||||
{1, 0, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
|
||||
{1, 16, D3DDECLTYPE_FLOAT1, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1},
|
||||
D3DDECL_END()
|
||||
};
|
||||
|
||||
IDirect3DVertexDeclaration9* vertexDecl;
|
||||
d3dDevice->CreateVertexDeclaration(decl, &vertexDecl);
|
||||
|
||||
D3DVERTEXELEMENT9 quadDecl[] =
|
||||
{
|
||||
{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
|
||||
{0, 12, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
|
||||
D3DDECL_END() // this macro is needed as the last item!
|
||||
};
|
||||
IDirect3DVertexDeclaration9* quadVertexDecl;
|
||||
d3dDevice->CreateVertexDeclaration(quadDecl, &quadVertexDecl);
|
||||
IDirect3DVertexBuffer9* quadVertexBuffer;
|
||||
float* quadData;
|
||||
d3dDevice->CreateVertexBuffer(sizeof(float) * 20, D3DUSAGE_WRITEONLY, 0, D3DPOOL_MANAGED, &quadVertexBuffer, NULL);
|
||||
quadVertexBuffer->Lock(0, sizeof(float) * 20, (void**)&quadData, 0);//D3DLOCK_DISCARD);
|
||||
::memcpy(quadData, quadVerts2, sizeof(float) * 20);
|
||||
quadVertexBuffer->Unlock();
|
||||
|
||||
IDirect3DIndexBuffer9* quadIndexBuffer;
|
||||
int* quadIndexData;
|
||||
d3dDevice->CreateIndexBuffer(6 * sizeof(int), D3DUSAGE_WRITEONLY, D3DFMT_INDEX32, D3DPOOL_MANAGED, &quadIndexBuffer, NULL);
|
||||
quadIndexBuffer->Lock(0, 0, (void**)&quadIndexData, 0);//D3DLOCK_DISCARD);
|
||||
quadIndexData[0] = 0;
|
||||
quadIndexData[1] = 1;
|
||||
quadIndexData[2] = 2;
|
||||
quadIndexData[3] = 2;
|
||||
quadIndexData[4] = 0;
|
||||
quadIndexData[5] = 3;
|
||||
quadIndexBuffer->Unlock();
|
||||
|
||||
|
||||
const unsigned int instanceCount = 5000;
|
||||
IDirect3DVertexBuffer9* instanceDataBuffer;
|
||||
InstanceData* instanceData;
|
||||
d3dDevice->CreateVertexBuffer(sizeof(InstanceData) * instanceCount, D3DUSAGE_WRITEONLY, D3DFVF_TEX1, D3DPOOL_MANAGED, &instanceDataBuffer, NULL);
|
||||
instanceDataBuffer->Lock(0, sizeof(InstanceData) * instanceCount, (void**)&instanceData, 0);//D3DLOCK_DISCARD);
|
||||
const float posFactor = 2.0f;
|
||||
for (int i = 0; i < instanceCount; ++i)
|
||||
{
|
||||
float r = (((rand() % 1000) / 1000.0f - 0.5f) + 2 ) * posFactor;
|
||||
float h = ((rand() % 1000) / 1000.0f - 0.5f) * posFactor * 0.5;
|
||||
float d = ((rand() % 1000) / 1000.0f - 0.5f) * 3.141 * 2;
|
||||
float x = sin(d) * r;
|
||||
float y = cos(d) * r;
|
||||
float z = h;
|
||||
|
||||
instanceData[i].pos[0] = x;
|
||||
instanceData[i].pos[1] = y;
|
||||
instanceData[i].pos[2] = z;
|
||||
instanceData[i].pos[3] = (r - 1.5) * 3 * (rand() % 900) / 900.0f * 0.25f + 0.1f; // scale
|
||||
instanceData[i].intensity = (((rand() % 1000) / 1000.0f)*0.2 + 0.01) * 0.5;
|
||||
}
|
||||
instanceDataBuffer->Unlock();
|
||||
|
||||
const int renderTextureCount = 4; // pos, normal, density, ballpos
|
||||
static LPDIRECT3DTEXTURE9 renderTexture[renderTextureCount];
|
||||
static LPDIRECT3DSURFACE9 renderSurface[renderTextureCount];
|
||||
|
||||
static LPDIRECT3DTEXTURE9 renderTexturePingPong[renderTextureCount * 2];
|
||||
static LPDIRECT3DSURFACE9 renderSurfacePingPong[renderTextureCount * 2];
|
||||
|
||||
const int renderTargetWidth = screenX;
|
||||
const int renderTargetHeight = screenY;
|
||||
|
||||
const float pingPongDevider = 2.0f;
|
||||
const D3DXVECTOR4 renderTargetDDX( 1.0f / renderTargetWidth, 1.0f / renderTargetHeight, 0.00f, 0.0f );
|
||||
const D3DXVECTOR4 renderTargetPingPongDDX( 1.0f / (renderTargetWidth / pingPongDevider), 1.0f / (renderTargetHeight / pingPongDevider), 0.00f, 0.0f );
|
||||
|
||||
for (int i = 0; i < renderTextureCount; ++i)
|
||||
{
|
||||
d3dDevice->CreateTexture(renderTargetWidth,
|
||||
renderTargetHeight,
|
||||
1,
|
||||
D3DUSAGE_RENDERTARGET,
|
||||
D3DFMT_A16B16G16R16F,
|
||||
D3DPOOL_DEFAULT,
|
||||
&renderTexture[i],
|
||||
NULL);
|
||||
renderTexture[i]->GetSurfaceLevel(0, &renderSurface[i]);
|
||||
|
||||
for (int k = 0; k < 2; ++k)
|
||||
{
|
||||
d3dDevice->CreateTexture(renderTargetWidth / pingPongDevider,
|
||||
renderTargetHeight / pingPongDevider,
|
||||
1,
|
||||
D3DUSAGE_RENDERTARGET,
|
||||
D3DFMT_A16B16G16R16F,
|
||||
D3DPOOL_DEFAULT,
|
||||
&renderTexturePingPong[i * 2 + k],
|
||||
NULL);
|
||||
renderTexturePingPong[i * 2 + k]->GetSurfaceLevel(0, &renderSurfacePingPong[i * 2 + k]);
|
||||
}
|
||||
}
|
||||
IDirect3DSurface9* pongPongDepthBuffer;
|
||||
hr = d3dDevice->CreateDepthStencilSurface(renderTargetWidth / pingPongDevider,
|
||||
renderTargetHeight / pingPongDevider, D3DFMT_D24S8, D3DMULTISAMPLE_NONE, 0, false, &pongPongDepthBuffer, NULL);
|
||||
|
||||
LPDIRECT3DSURFACE9 backBuffer = NULL;
|
||||
d3dDevice->GetRenderTarget(0, &backBuffer);
|
||||
IDirect3DSurface9* backBufferDepthBuffer;
|
||||
d3dDevice->GetDepthStencilSurface(&backBufferDepthBuffer);
|
||||
|
||||
d3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
|
||||
effect->SetTexture("diffuseTexture", texture);
|
||||
effect->SetTexture("backgroundTexture", backgroundTexture);
|
||||
do
|
||||
{
|
||||
const float t = GetTickCount() / 1000.0f;
|
||||
|
||||
// Fill pos/depth and normal/matId
|
||||
D3DXMATRIX view;
|
||||
D3DXMATRIX inverseView;
|
||||
D3DXMATRIX proj;
|
||||
D3DXMATRIX viewProj;
|
||||
//D3DXVECTOR3 eye(0, 0, 10.0f);
|
||||
float dist = 10;
|
||||
D3DXVECTOR3 eye(cos(t * 0.1) * dist, sin(t * 0.1) * dist, sin(t * 0.1) * dist);
|
||||
//D3DXVECTOR3 eye(cos(t) * 10, sin(t) * 5, 5.0f);
|
||||
D3DXVECTOR4 eye4(eye.x, eye.y, eye.z, 0.0f);
|
||||
D3DXVECTOR3 at(0.0f, 0.0f, 0.0f);
|
||||
D3DXVECTOR3 up(0.0f, 1.0f, 0.0f);
|
||||
D3DXVECTOR3 right, direction;
|
||||
D3DXVec3Subtract(&direction, &at, &eye);
|
||||
D3DXVec3Normalize(&direction, &direction);
|
||||
D3DXVec3Cross(&right, &direction, &up);
|
||||
D3DXVec3Cross(&up, &right, &direction);
|
||||
D3DXMatrixLookAtLH(&view, &eye, &at, &up);
|
||||
D3DXMatrixPerspectiveFovLH(&proj, D3DX_PI / 4.0f, 4.0f/3.0f, 1.0f, 100.0f);
|
||||
D3DXMatrixMultiply(&viewProj, &view, &proj);
|
||||
D3DXVECTOR4 direction4(direction.x, direction.y, direction.z, 0.0f);
|
||||
D3DXMatrixInverse(&inverseView, NULL, &view);
|
||||
|
||||
effect->SetMatrix("viewProj", &viewProj);
|
||||
effect->SetMatrix("view", &view);
|
||||
effect->SetMatrix("inverseView", &inverseView);
|
||||
effect->SetVector("eye", &eye4);
|
||||
effect->SetVector("eyeDir", &direction4);
|
||||
|
||||
d3dDevice->SetStreamSource(0, quadVertexBuffer, 0, sizeof(float) * 5);
|
||||
//d3dDevice->SetStreamSource(0, sphereVertexBuffer, 0, sphereMesh->GetNumBytesPerVertex());
|
||||
d3dDevice->SetStreamSourceFreq(0, D3DSTREAMSOURCE_INDEXEDDATA | instanceCount);
|
||||
|
||||
d3dDevice->SetStreamSource(1, instanceDataBuffer, 0, sizeof(InstanceData));
|
||||
d3dDevice->SetStreamSourceFreq(1, D3DSTREAMSOURCE_INSTANCEDATA | 1ul);
|
||||
|
||||
d3dDevice->SetVertexDeclaration(vertexDecl);
|
||||
d3dDevice->SetIndices(quadIndexBuffer);
|
||||
|
||||
//d3dDevice->SetIndices(sphereIndexBuffer);
|
||||
|
||||
// Begin
|
||||
{
|
||||
effect->SetTechnique("Deferred");
|
||||
|
||||
effect->SetTexture("positionTexture", NULL);
|
||||
effect->SetTexture("normalTexture", NULL);
|
||||
|
||||
d3dDevice->SetRenderTarget(0, renderSurface[0]);
|
||||
d3dDevice->SetRenderTarget(1, renderSurface[1]);
|
||||
|
||||
d3dDevice->BeginScene();
|
||||
d3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x0, 1.0f, 0);
|
||||
|
||||
RENDER(d3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 4, 0, 2));
|
||||
//RENDER(d3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, sphereMesh->GetNumVertices(), 0, sphereMesh->GetNumFaces()));
|
||||
|
||||
d3dDevice->EndScene();
|
||||
|
||||
/*d3dDevice->Present(NULL, NULL, NULL, NULL);
|
||||
continue;*/
|
||||
}
|
||||
|
||||
{
|
||||
effect->SetTechnique("Density");
|
||||
|
||||
d3dDevice->SetRenderTarget(0, renderSurface[2]);
|
||||
d3dDevice->SetRenderTarget(1, NULL);
|
||||
|
||||
d3dDevice->BeginScene();
|
||||
d3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x0, 1.0f, 0);
|
||||
|
||||
RENDER(d3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 4, 0, 2));
|
||||
//RENDER(d3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, sphereMesh->GetNumVertices(), 0, sphereMesh->GetNumFaces()));
|
||||
|
||||
d3dDevice->EndScene();
|
||||
}
|
||||
|
||||
{
|
||||
effect->SetTechnique("ParticlePosition");
|
||||
|
||||
d3dDevice->SetRenderTarget(0, renderSurface[3]);
|
||||
d3dDevice->SetRenderTarget(1, NULL);
|
||||
|
||||
d3dDevice->BeginScene();
|
||||
d3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x0, 1.0f, 0);
|
||||
|
||||
RENDER(d3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 4, 0, 2));
|
||||
//RENDER(d3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, sphereMesh->GetNumVertices(), 0, sphereMesh->GetNumFaces()));
|
||||
|
||||
d3dDevice->EndScene();
|
||||
}
|
||||
|
||||
d3dDevice->SetStreamSourceFreq(0, 1);
|
||||
d3dDevice->SetStreamSourceFreq(1, 1);
|
||||
|
||||
d3dDevice->SetVertexDeclaration(quadVertexDecl);
|
||||
effect->SetVector("quadddx", &renderTargetPingPongDDX);
|
||||
|
||||
// blur
|
||||
{
|
||||
effect->SetTechnique("Blur");
|
||||
|
||||
for (int k = 0; k < 8; ++k)
|
||||
{
|
||||
d3dDevice->SetRenderTarget(0, renderSurfacePingPong[0 + ((k+1)%2)]);
|
||||
d3dDevice->SetRenderTarget(1, renderSurfacePingPong[2 + ((k+1)%2)]);
|
||||
d3dDevice->SetRenderTarget(2, renderSurfacePingPong[4 + ((k+1)%2)]);
|
||||
d3dDevice->SetRenderTarget(3, renderSurfacePingPong[6 + ((k+1)%2)]);
|
||||
|
||||
effect->SetVector("ddx", k == 0 ? &renderTargetDDX : &renderTargetPingPongDDX);
|
||||
effect->SetTexture("positionTexture", k == 0 ? renderTexture[0] : renderTexturePingPong[0 + k%2]);
|
||||
effect->SetTexture("normalTexture", k == 0 ? renderTexture[1] : renderTexturePingPong[2 + k%2]);
|
||||
effect->SetTexture("densityTexture", k == 0 ? renderTexture[2] : renderTexturePingPong[4 + k%2]);
|
||||
effect->SetTexture("particlePositionTexture", k == 0 ? renderTexture[3] : renderTexturePingPong[6 + k%2]);
|
||||
|
||||
d3dDevice->BeginScene();
|
||||
d3dDevice->Clear(0, NULL, D3DCLEAR_ZBUFFER, 0x0, 1.0f, 0);
|
||||
RENDER(d3dDevice->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 2, quadVerts, 20));
|
||||
d3dDevice->EndScene();
|
||||
}
|
||||
}
|
||||
|
||||
// Compose
|
||||
{
|
||||
if (GetAsyncKeyState(VK_SPACE))
|
||||
effect->SetTechnique("ComposeDebug");
|
||||
else
|
||||
effect->SetTechnique("Compose");
|
||||
|
||||
effect->SetTexture("positionTexture", renderTexturePingPong[1]);
|
||||
effect->SetTexture("normalTexture", renderTexturePingPong[3]);
|
||||
effect->SetTexture("densityTexture", renderTexturePingPong[5]);
|
||||
effect->SetTexture("particlePositionTexture", renderTexturePingPong[7]);
|
||||
|
||||
d3dDevice->SetRenderTarget(0, backBuffer);
|
||||
d3dDevice->SetRenderTarget(1, NULL);
|
||||
d3dDevice->SetRenderTarget(2, NULL);
|
||||
d3dDevice->SetRenderTarget(3, NULL);
|
||||
|
||||
d3dDevice->BeginScene();
|
||||
d3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x0, 1.0f, 0);
|
||||
RENDER(d3dDevice->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 2, quadVerts, 20));
|
||||
d3dDevice->EndScene();
|
||||
}
|
||||
|
||||
d3dDevice->Present(NULL, NULL, NULL, NULL);
|
||||
|
||||
// move particle
|
||||
instanceDataBuffer->Lock(0, sizeof(InstanceData) * instanceCount, (void**)&instanceData, 0);
|
||||
for (int i = 0; i < instanceCount; ++i)
|
||||
{
|
||||
D3DXVECTOR2 pos(instanceData[i].pos[0], instanceData[i].pos[1]);
|
||||
float r = D3DXVec2Length(&pos);
|
||||
float d = atan2(pos.x, pos.y);
|
||||
d += (r - 1.5) / 2.0 * 0.001;
|
||||
|
||||
float x = sin(d) * r;
|
||||
float y = cos(d) * r;
|
||||
|
||||
instanceData[i].pos[0] = x;
|
||||
instanceData[i].pos[1] = y;
|
||||
}
|
||||
instanceDataBuffer->Unlock();
|
||||
} while (!GetAsyncKeyState(VK_ESCAPE));
|
||||
|
||||
ExitProcess(0);
|
||||
}
|
||||
|
||||
254
ice/src/ice.vcproj
Normal file
254
ice/src/ice.vcproj
Normal file
@@ -0,0 +1,254 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="9,00"
|
||||
Name="ice"
|
||||
ProjectGUID="{D91DFF9F-B3F5-4F75-AD44-19AD5F1DEB00}"
|
||||
RootNamespace="ice"
|
||||
Keyword="Win32Proj"
|
||||
TargetFrameworkVersion="196613"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="$(SolutionDir)bin"
|
||||
IntermediateDirectory="$(SolutionDir)obj\$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
CommandLine=""
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
WarningLevel="3"
|
||||
DebugInformationFormat="4"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="d3d9.lib d3dx9.lib"
|
||||
OutputFile="$(OutDir)\$(ProjectName)D.exe"
|
||||
LinkIncremental="2"
|
||||
GenerateDebugInformation="true"
|
||||
ProgramDatabaseFile="$(TargetDir)$(TargetName).pdb"
|
||||
SubSystem="1"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
UseFAT32Workaround="true"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="$(SolutionDir)bin"
|
||||
IntermediateDirectory="$(SolutionDir)obj\$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
WholeProgramOptimization="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
CommandLine=""
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="1"
|
||||
EnableIntrinsicFunctions="true"
|
||||
FavorSizeOrSpeed="2"
|
||||
OmitFramePointers="true"
|
||||
WholeProgramOptimization="false"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
|
||||
ExceptionHandling="0"
|
||||
RuntimeLibrary="2"
|
||||
BufferSecurityCheck="false"
|
||||
EnableFunctionLevelLinking="false"
|
||||
FloatingPointModel="2"
|
||||
ForceConformanceInForLoopScope="false"
|
||||
RuntimeTypeInfo="false"
|
||||
WarningLevel="0"
|
||||
DebugInformationFormat="0"
|
||||
CallingConvention="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalOptions="/CRINKLER /COMPMODE:SLOW /ORDERTRIES:1000 /HASHSIZE:200 /HASHTRIES:100 /REPORT:report.html"
|
||||
AdditionalDependencies="d3d9.lib d3dx9.lib"
|
||||
SuppressStartupBanner="false"
|
||||
GenerateManifest="false"
|
||||
GenerateDebugInformation="false"
|
||||
SubSystem="2"
|
||||
LinkTimeCodeGeneration="0"
|
||||
EntryPointSymbol="main"
|
||||
RandomizedBaseAddress="0"
|
||||
DataExecutionPrevention="0"
|
||||
TargetMachine="0"
|
||||
ErrorReporting="0"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
EmbedManifest="false"
|
||||
UseFAT32Workaround="true"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\FluidContext.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\ice.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\PointMapGenerator.cpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
||||
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\debug.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\FluidContext.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\PointMapGenerator.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\variables.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Resource Files"
|
||||
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
|
||||
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\Lighthouse.jpg"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\texture.png"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<File
|
||||
RelativePath=".\ice.cpp.old"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\shader.hlsl"
|
||||
>
|
||||
</File>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
65
ice/src/ice.vcproj.FIARA.Frank.user
Normal file
65
ice/src/ice.vcproj.FIARA.Frank.user
Normal file
@@ -0,0 +1,65 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioUserFile
|
||||
ProjectType="Visual C++"
|
||||
Version="9,00"
|
||||
ShowAllFiles="false"
|
||||
>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<DebugSettings
|
||||
Command="$(TargetPath)"
|
||||
WorkingDirectory=""
|
||||
CommandArguments=""
|
||||
Attach="false"
|
||||
DebuggerType="3"
|
||||
Remote="1"
|
||||
RemoteMachine="SHAIKUR"
|
||||
RemoteCommand=""
|
||||
HttpUrl=""
|
||||
PDBPath=""
|
||||
SQLDebugging=""
|
||||
Environment=""
|
||||
EnvironmentMerge="true"
|
||||
DebuggerFlavor=""
|
||||
MPIRunCommand=""
|
||||
MPIRunArguments=""
|
||||
MPIRunWorkingDirectory=""
|
||||
ApplicationCommand=""
|
||||
ApplicationArguments=""
|
||||
ShimCommand=""
|
||||
MPIAcceptMode=""
|
||||
MPIAcceptFilter=""
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<DebugSettings
|
||||
Command="$(TargetPath)"
|
||||
WorkingDirectory=""
|
||||
CommandArguments=""
|
||||
Attach="false"
|
||||
DebuggerType="3"
|
||||
Remote="1"
|
||||
RemoteMachine="SHAIKUR"
|
||||
RemoteCommand=""
|
||||
HttpUrl=""
|
||||
PDBPath=""
|
||||
SQLDebugging=""
|
||||
Environment=""
|
||||
EnvironmentMerge="true"
|
||||
DebuggerFlavor=""
|
||||
MPIRunCommand=""
|
||||
MPIRunArguments=""
|
||||
MPIRunWorkingDirectory=""
|
||||
ApplicationCommand=""
|
||||
ApplicationArguments=""
|
||||
ShimCommand=""
|
||||
MPIAcceptMode=""
|
||||
MPIAcceptFilter=""
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
</VisualStudioUserFile>
|
||||
0
ice/src/outShader.h
Normal file
0
ice/src/outShader.h
Normal file
407
ice/src/shader.hlsl
Normal file
407
ice/src/shader.hlsl
Normal file
@@ -0,0 +1,407 @@
|
||||
texture positionTexture;
|
||||
texture particlePositionTexture;
|
||||
texture normalTexture;
|
||||
texture densityTexture;
|
||||
texture diffuseTexture;
|
||||
texture backgroundTexture;
|
||||
|
||||
float4x4 viewProj;
|
||||
float4x4 view;
|
||||
float4x4 inverseView;
|
||||
float2 ddx;
|
||||
float2 quadddx;
|
||||
float3 eye;
|
||||
float3 eyeDir;
|
||||
float softness;
|
||||
float lightTransferAmmount;
|
||||
float specularFactor;
|
||||
float specularPower;
|
||||
float translucencyAmmount;
|
||||
float textureScale;
|
||||
float surfaceTension;
|
||||
float refractAmmount;
|
||||
|
||||
sampler samplerPosition = sampler_state
|
||||
{
|
||||
Texture = <positionTexture>;
|
||||
MinFilter = Linear;
|
||||
MagFilter = Linear;
|
||||
AddressU = Clamp;
|
||||
AddressV = Clamp;
|
||||
};
|
||||
|
||||
sampler samplerParticlePosition = sampler_state
|
||||
{
|
||||
Texture = <particlePositionTexture>;
|
||||
MinFilter = Linear;
|
||||
MagFilter = Linear;
|
||||
AddressU = Clamp;
|
||||
AddressV = Clamp;
|
||||
};
|
||||
|
||||
sampler samplerNormal = sampler_state
|
||||
{
|
||||
Texture = <normalTexture>;
|
||||
MinFilter = Linear;
|
||||
MagFilter = Linear;
|
||||
AddressU = Clamp;
|
||||
AddressV = Clamp;
|
||||
};
|
||||
|
||||
sampler samplerDensity = sampler_state
|
||||
{
|
||||
Texture = <densityTexture>;
|
||||
MinFilter = Linear;
|
||||
MagFilter = Linear;
|
||||
AddressU = Clamp;
|
||||
AddressV = Clamp;
|
||||
};
|
||||
|
||||
sampler samplerDiffuse = sampler_state
|
||||
{
|
||||
Texture = <diffuseTexture>;
|
||||
MinFilter = Linear;
|
||||
MagFilter = Linear;
|
||||
AddressU = Wrap;
|
||||
AddressV = Wrap;
|
||||
};
|
||||
|
||||
sampler samplerBackground = sampler_state
|
||||
{
|
||||
Texture = <backgroundTexture>;
|
||||
MinFilter = Linear;
|
||||
MagFilter = Linear;
|
||||
AddressU = Clamp;
|
||||
AddressV = Clamp;
|
||||
};
|
||||
|
||||
struct QuadInput
|
||||
{
|
||||
float4 p:position;
|
||||
float2 t:texcoord0;
|
||||
};
|
||||
|
||||
struct QuadOutput
|
||||
{
|
||||
float4 p:position;
|
||||
float2 t:texcoord0;
|
||||
float4 q:texcoord1;
|
||||
};
|
||||
|
||||
struct IndexedQuadInput
|
||||
{
|
||||
float4 p:position;
|
||||
float2 n:normal;
|
||||
float4 i:texcoord0;
|
||||
float k:texcoord1;
|
||||
};
|
||||
|
||||
struct IndexedQuadOutput
|
||||
{
|
||||
float4 q:position;
|
||||
float3 n:normal;
|
||||
float4 p:texcoord0;
|
||||
float4 k:texcoord1;
|
||||
float2 t:texcoord2;
|
||||
float size:texcoord3;
|
||||
};
|
||||
|
||||
struct BlurResult
|
||||
{
|
||||
float4 position : color0;
|
||||
float4 normal : color1;
|
||||
float4 density : color2;
|
||||
float4 particlePosition : color3;
|
||||
};
|
||||
|
||||
struct PosNormalDepth
|
||||
{
|
||||
float4 position : color0;
|
||||
float4 normal : color1;
|
||||
float depth : depth;
|
||||
};
|
||||
|
||||
struct ColorDepth
|
||||
{
|
||||
float4 color : color0;
|
||||
float depth : depth;
|
||||
};
|
||||
|
||||
float CalcDepth(float4 pos, float difference, float size)
|
||||
{
|
||||
float3 eyeVector = viewProj._m02_m12_m22;
|
||||
pos.xyz -= eyeVector * difference * size;
|
||||
float4 finalDepth = mul(pos, viewProj);
|
||||
return finalDepth.z / finalDepth.w;
|
||||
}
|
||||
|
||||
PosNormalDepth psDeferred(IndexedQuadOutput i)
|
||||
{
|
||||
float dist = 1.0 - length(i.t.xy * 2 - 1.0);
|
||||
if (dist < 0)
|
||||
discard;
|
||||
|
||||
PosNormalDepth result;
|
||||
result.position = abs(float4(i.p.xyz, 1));
|
||||
|
||||
float3 normal = float3(i.t.xy * 2 - 1.0, 0.0);
|
||||
normal.z = 1.0 - length(normal.xy);
|
||||
normal = normalize(normal);
|
||||
normal = mul((float3x3)view, normal);
|
||||
result.normal = float4(normal, 1.0);
|
||||
result.depth = CalcDepth(i.p, dist, i.size);
|
||||
return result;
|
||||
}
|
||||
|
||||
void vsDeferred(IndexedQuadInput i, out IndexedQuadOutput o)
|
||||
{
|
||||
float3 eyeVector = viewProj._m02_m12_m22;
|
||||
float3 side;
|
||||
float3 up;
|
||||
|
||||
side = normalize(cross(eyeVector, float3(0,1,0)));
|
||||
up = normalize(cross(side,eyeVector));
|
||||
|
||||
float3 finalPos = i.i.xyz;
|
||||
float size = i.i.w*0.2;
|
||||
finalPos += (i.p.x) * side * size;
|
||||
finalPos += (i.p.y) * up * size;
|
||||
|
||||
float4 finalPos4 = float4(finalPos, 1);
|
||||
|
||||
o.q = mul(finalPos4, viewProj);
|
||||
|
||||
o.t = i.n;
|
||||
o.n.xy = i.n;
|
||||
o.n.z = 0.0;
|
||||
o.p = finalPos4;
|
||||
o.k.xyz = i.p.xyz;
|
||||
o.k.a = i.k;
|
||||
o.size = size;
|
||||
}
|
||||
|
||||
ColorDepth psDensity(IndexedQuadOutput i)
|
||||
{
|
||||
float dist = 1.0 - length(i.t.xy * 2 - 1.0);
|
||||
if (dist < 0)
|
||||
discard;
|
||||
|
||||
ColorDepth result;
|
||||
result.color = i.k.a;
|
||||
result.depth = CalcDepth(i.p, dist, i.size);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
ColorDepth psParticlePosition(IndexedQuadOutput i)
|
||||
{
|
||||
float dist = 1.0 - length(i.t.xy * 2 - 1.0);
|
||||
if (dist < 0)
|
||||
discard;
|
||||
|
||||
ColorDepth result;
|
||||
|
||||
float3 eyeVector = viewProj._m02_m12_m22;
|
||||
float3 side = normalize(cross(eyeVector, float3(0,1,0)));
|
||||
float3 up = normalize(cross(side,eyeVector));
|
||||
|
||||
float3 finalPos = 0;
|
||||
float size = 0.2f;
|
||||
finalPos += (i.k.x) * side * size;
|
||||
finalPos += (i.k.y) * up * size;
|
||||
finalPos += eyeVector * dist * size;
|
||||
|
||||
result.color = float4(finalPos, 1.0) * 10;
|
||||
result.depth = CalcDepth(i.p, dist, i.size);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
BlurResult psBlur(QuadOutput input)
|
||||
{
|
||||
const int strength = 8;
|
||||
|
||||
float2 SamplePos;
|
||||
float2 SamplePosSmall;
|
||||
float pi4 = 3.141 * 2.0 / strength;
|
||||
|
||||
float4 resultNormal = 0;
|
||||
float4 resultPosition = 0;
|
||||
float4 resultDensity = 0;
|
||||
float4 resultParticlePosition = 0;
|
||||
|
||||
int cnt = 0;
|
||||
for (int i = 0; i < strength; i++)
|
||||
{
|
||||
SamplePos = input.t + ddx * softness * float2(sin(pi4 * i), cos(pi4 * i));
|
||||
SamplePosSmall = input.t + 0.1 * ddx * softness * float2(sin(pi4 * i), cos(pi4 * i));
|
||||
resultDensity += tex2D(samplerDensity, SamplePos);
|
||||
resultPosition += tex2D(samplerPosition, SamplePos);
|
||||
resultParticlePosition += tex2D(samplerParticlePosition, SamplePosSmall);
|
||||
|
||||
float4 normal = tex2D(samplerNormal, SamplePos);
|
||||
resultNormal.a += normal.a;
|
||||
if (length(normal.xyz) > 0)
|
||||
{
|
||||
resultNormal.xyz += normal.xyz;
|
||||
cnt ++;
|
||||
}
|
||||
}
|
||||
resultNormal.a /= strength;
|
||||
if (cnt > 0)
|
||||
resultNormal.xyz = (resultNormal.xyz / cnt);
|
||||
resultPosition /= strength;
|
||||
resultDensity /= strength;
|
||||
resultParticlePosition /= strength;
|
||||
|
||||
BlurResult result;
|
||||
result.normal = resultNormal;
|
||||
result.position = resultPosition;
|
||||
result.density = resultDensity;
|
||||
result.particlePosition = resultParticlePosition;
|
||||
return result;
|
||||
}
|
||||
|
||||
float4 psComposeDebug(QuadOutput i):color0
|
||||
{
|
||||
float4 a = tex2D(samplerPosition, i.t);
|
||||
float4 b = tex2D(samplerNormal, i.t);
|
||||
float4 c = tex2D(samplerDensity, i.t);
|
||||
float4 d = tex2D(samplerParticlePosition, i.t);
|
||||
return d;
|
||||
if (i.t.y > 0.5)
|
||||
{
|
||||
float len = length(b.xyz);
|
||||
if (len > 0)
|
||||
b.xyz /= len;
|
||||
if (i.t.x > 0.5)
|
||||
return b * a.a;
|
||||
if (b.a > 0)
|
||||
return float4(d.xyz, 1.0);
|
||||
return float4(1,0,0,1);
|
||||
}
|
||||
if (i.t.x > 0.5)
|
||||
return c;
|
||||
return a;
|
||||
}
|
||||
|
||||
QuadOutput vsCompose(QuadInput i)
|
||||
{
|
||||
QuadOutput o;
|
||||
i.p.xy *= 1.0 + quadddx;
|
||||
o.p = i.p;
|
||||
o.q = i.p;
|
||||
o.t = i.t;
|
||||
return o;
|
||||
}
|
||||
|
||||
float4 psCompose(QuadOutput i):color0
|
||||
{
|
||||
float4 density = tex2D(samplerDensity, i.t);
|
||||
float optDensity = min(1.0, max(0, density.a - surfaceTension) * (1+translucencyAmmount) );
|
||||
float4 particlePosition = tex2D(samplerParticlePosition, i.t);
|
||||
float4 a = tex2D(samplerPosition, i.t);
|
||||
float4 b = tex2D(samplerNormal, i.t);
|
||||
float3 lightPos = float3(10,10,10);
|
||||
float3 normal = normalize(b.xyz);
|
||||
float3 position = a.xyz;
|
||||
|
||||
float3 vLightDir = normalize(lightPos - position); // calc LightDirection
|
||||
float3 sssNormal = normalize(normal + vLightDir * max(0.0, lightTransferAmmount - density.a));
|
||||
float fDiffuse = dot(sssNormal, vLightDir); // get diffuse
|
||||
|
||||
float3 viewDir = normalize(a.xyz - eye);
|
||||
float3 vReflect = reflect(normal, vLightDir);
|
||||
float fSpecular = dot(vReflect, normalize(viewDir));
|
||||
if (fSpecular > 0)
|
||||
fSpecular = pow( fSpecular, specularPower) * specularFactor;
|
||||
else
|
||||
fSpecular = 0;
|
||||
|
||||
float fAtten = 10.0f;
|
||||
float LD = length(position - lightPos);
|
||||
fAtten *= 1.f/(0 +
|
||||
1*LD +
|
||||
0*LD*LD);
|
||||
fAtten = min(1.0f, fAtten);
|
||||
|
||||
float texFac = 1 / textureScale;
|
||||
float4 diffuse = (tex2D(samplerDiffuse, particlePosition.xy * texFac) + tex2D(samplerDiffuse, particlePosition.xz * texFac)) * 0.5;
|
||||
diffuse = fAtten * lerp(fDiffuse, 1.0, saturate(1.0 - optDensity)) * diffuse;// + fAtten * fSpecular;
|
||||
float2 tex = i.t;
|
||||
|
||||
tex += normal.xy * optDensity * refractAmmount;
|
||||
float4 background = tex2D(samplerBackground, tex);
|
||||
return lerp(diffuse, background, saturate(1.0 - optDensity));
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
technique Deferred
|
||||
{
|
||||
pass P0
|
||||
{
|
||||
VertexShader = compile vs_3_0 vsDeferred();
|
||||
PixelShader = compile ps_3_0 psDeferred();
|
||||
}
|
||||
}
|
||||
|
||||
technique Density
|
||||
{
|
||||
pass P0
|
||||
{
|
||||
VertexShader = compile vs_3_0 vsDeferred();
|
||||
PixelShader = compile ps_3_0 psDensity();
|
||||
AlphaBlendEnable= TRUE;
|
||||
SrcBlend = ONE;
|
||||
DestBlend = ONE;
|
||||
CullMode = CCW;
|
||||
ZEnable = true;
|
||||
ZFunc = ALWAYS;
|
||||
ZWriteEnable = false;
|
||||
}
|
||||
}
|
||||
|
||||
technique ParticlePosition
|
||||
{
|
||||
pass P0
|
||||
{
|
||||
VertexShader = compile vs_3_0 vsDeferred();
|
||||
PixelShader = compile ps_3_0 psParticlePosition();
|
||||
AlphaBlendEnable= TRUE;
|
||||
SrcBlend = ONE;
|
||||
DestBlend = ZERO;
|
||||
CullMode = CCW;
|
||||
ZEnable = true;
|
||||
ZFunc = LESSEQUAL ;
|
||||
ZWriteEnable = true;
|
||||
}
|
||||
}
|
||||
|
||||
technique Blur
|
||||
{
|
||||
pass P0
|
||||
{
|
||||
VertexShader = compile vs_3_0 vsCompose();
|
||||
PixelShader = compile ps_3_0 psBlur();
|
||||
}
|
||||
}
|
||||
|
||||
technique Compose
|
||||
{
|
||||
pass P0
|
||||
{
|
||||
VertexShader = compile vs_3_0 vsCompose();
|
||||
PixelShader = compile ps_3_0 psCompose();
|
||||
}
|
||||
}
|
||||
|
||||
technique ComposeDebug
|
||||
{
|
||||
pass P0
|
||||
{
|
||||
VertexShader = compile vs_3_0 vsCompose();
|
||||
PixelShader = compile ps_3_0 psComposeDebug();
|
||||
}
|
||||
}
|
||||
BIN
ice/src/texture.png
Normal file
BIN
ice/src/texture.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 758 KiB |
14
ice/src/variables.h
Normal file
14
ice/src/variables.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#pragma bss_seg(".nothing")
|
||||
static IDirect3DDevice9* d3dDevice;
|
||||
static IDirect3D9* d3d;
|
||||
|
||||
#pragma data_seg(".screenX")
|
||||
static const int screenX = 640;
|
||||
|
||||
#pragma data_seg(".screenY")
|
||||
static const int screenY = 480;
|
||||
|
||||
#pragma data_seg(".devParams")
|
||||
static D3DPRESENT_PARAMETERS devParams = {screenX, screenY, D3DFMT_A8R8G8B8, 0, D3DMULTISAMPLE_NONE, 0, D3DSWAPEFFECT_DISCARD, 0, true, true, D3DFMT_D24S8, 0, 0, D3DPRESENT_INTERVAL_IMMEDIATE};
|
||||
Reference in New Issue
Block a user