port from perforce
This commit is contained in:
Binary file not shown.
21
hgplus/particles/LiveEdit/particles.log
Normal file
21
hgplus/particles/LiveEdit/particles.log
Normal file
@@ -0,0 +1,21 @@
|
||||
Build started 20.07.2018 20:12:29.
|
||||
1>Project "E:\blu-flame.org\hgplus\particles\particles.vcxproj" on node 2 (Build target(s)).
|
||||
1>InitializeBuildStatus:
|
||||
Touching "LiveEdit\particles.tlog\unsuccessfulbuild".
|
||||
ClCompile:
|
||||
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.10.25017\bin\HostX86\x86\CL.exe /c /ZI /nologo /W3 /WX- /diagnostics:classic /Od /Oy- /D WIN32 /D _DEBUG /D _CONSOLE /D _LIB /Gm /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"LiveEdit\\" /Fd"LiveEdit\vc141.pdb" /Gd /TP /analyze- /errorReport:prompt main.cpp
|
||||
main.cpp
|
||||
1>e:\blu-flame.org\hgplus\particles\main.cpp(26): warning C4838: conversion from 'int' to 'UINT' requires a narrowing conversion
|
||||
1>e:\blu-flame.org\hgplus\particles\main.cpp(165): warning C4838: conversion from 'int' to 'UINT' requires a narrowing conversion
|
||||
Link:
|
||||
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.10.25017\bin\HostX86\x86\link.exe /ERRORREPORT:PROMPT /OUT:"E:\blu-flame.org\hgplus\particles\LiveEdit\particles.exe" /INCREMENTAL /NOLOGO kernel32.lib user32.lib gdi32.lib d3d11.lib d3dcompiler.lib /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /DEBUG:FASTLINK /PDB:"E:\blu-flame.org\hgplus\particles\LiveEdit\particles.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"E:\blu-flame.org\hgplus\particles\LiveEdit\particles.lib" /MACHINE:X86 LiveEdit\main.obj
|
||||
particles.vcxproj -> E:\blu-flame.org\hgplus\particles\LiveEdit\particles.exe
|
||||
particles.vcxproj -> E:\blu-flame.org\hgplus\particles\LiveEdit\particles.pdb (Partial PDB)
|
||||
FinalizeBuildStatus:
|
||||
Deleting file "LiveEdit\particles.tlog\unsuccessfulbuild".
|
||||
Touching "LiveEdit\particles.tlog\particles.lastbuildstate".
|
||||
1>Done Building Project "E:\blu-flame.org\hgplus\particles\particles.vcxproj" (Build target(s)).
|
||||
|
||||
Build succeeded.
|
||||
|
||||
Time Elapsed 00:00:01.63
|
||||
BIN
hgplus/particles/LiveEdit/particles.tlog/CL.read.1.tlog
Normal file
BIN
hgplus/particles/LiveEdit/particles.tlog/CL.read.1.tlog
Normal file
Binary file not shown.
BIN
hgplus/particles/LiveEdit/particles.tlog/CL.write.1.tlog
Normal file
BIN
hgplus/particles/LiveEdit/particles.tlog/CL.write.1.tlog
Normal file
Binary file not shown.
BIN
hgplus/particles/LiveEdit/particles.tlog/cl.command.1.tlog
Normal file
BIN
hgplus/particles/LiveEdit/particles.tlog/cl.command.1.tlog
Normal file
Binary file not shown.
@@ -0,0 +1 @@
|
||||
|
||||
BIN
hgplus/particles/LiveEdit/particles.tlog/custombuild.read.1.tlog
Normal file
BIN
hgplus/particles/LiveEdit/particles.tlog/custombuild.read.1.tlog
Normal file
Binary file not shown.
@@ -0,0 +1 @@
|
||||
|
||||
BIN
hgplus/particles/LiveEdit/particles.tlog/link.command.1.tlog
Normal file
BIN
hgplus/particles/LiveEdit/particles.tlog/link.command.1.tlog
Normal file
Binary file not shown.
BIN
hgplus/particles/LiveEdit/particles.tlog/link.delete.1.tlog
Normal file
BIN
hgplus/particles/LiveEdit/particles.tlog/link.delete.1.tlog
Normal file
Binary file not shown.
BIN
hgplus/particles/LiveEdit/particles.tlog/link.read.1.tlog
Normal file
BIN
hgplus/particles/LiveEdit/particles.tlog/link.read.1.tlog
Normal file
Binary file not shown.
BIN
hgplus/particles/LiveEdit/particles.tlog/link.write.1.tlog
Normal file
BIN
hgplus/particles/LiveEdit/particles.tlog/link.write.1.tlog
Normal file
Binary file not shown.
@@ -0,0 +1,2 @@
|
||||
#TargetFrameworkVersion=v4.0:PlatformToolSet=v141:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=8.1
|
||||
LiveEdit|Win32|E:\blu-flame.org\hgplus\particles\|
|
||||
BIN
hgplus/particles/LiveEdit/particles.tlog/particles.write.1u.tlog
Normal file
BIN
hgplus/particles/LiveEdit/particles.tlog/particles.write.1u.tlog
Normal file
Binary file not shown.
BIN
hgplus/particles/LiveEdit/vc141.idb
Normal file
BIN
hgplus/particles/LiveEdit/vc141.idb
Normal file
Binary file not shown.
BIN
hgplus/particles/LiveEdit/vc141.pdb
Normal file
BIN
hgplus/particles/LiveEdit/vc141.pdb
Normal file
Binary file not shown.
BIN
hgplus/particles/clear.cso
Normal file
BIN
hgplus/particles/clear.cso
Normal file
Binary file not shown.
BIN
hgplus/particles/clear.pdb
Normal file
BIN
hgplus/particles/clear.pdb
Normal file
Binary file not shown.
261
hgplus/particles/data.h
Normal file
261
hgplus/particles/data.h
Normal file
@@ -0,0 +1,261 @@
|
||||
#define VC_EXTRALEAN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <Windows.h>
|
||||
#include <cstdlib>
|
||||
|
||||
#define D3D11_NO_HELPERS
|
||||
#include <d3d11.h>
|
||||
#include <dxgi.h>
|
||||
#include <d3dcompiler.h>
|
||||
|
||||
#define ATOM_EDIT 0xC018
|
||||
#define ATOM_STATIC 0xC019
|
||||
#define WIDTH 1280
|
||||
#define HEIGHT 720
|
||||
#define _FULLSCREEN
|
||||
|
||||
typedef struct {
|
||||
// DXGI_MODE_DESC BufferDesc;
|
||||
UINT Width;
|
||||
UINT Height;
|
||||
//DXGI_RATIONAL RefreshRate;
|
||||
UINT Numerator;
|
||||
UINT Denominator;
|
||||
DXGI_FORMAT Format;
|
||||
DXGI_MODE_SCANLINE_ORDER ScanlineOrdering;
|
||||
DXGI_MODE_SCALING Scaling;
|
||||
|
||||
// DXGI_SAMPLE_DESC SampleDesc;
|
||||
UINT Count;
|
||||
UINT Quality;
|
||||
|
||||
DXGI_USAGE BufferUsage;
|
||||
UINT BufferCount;
|
||||
HWND OutputWindow;
|
||||
BOOL Windowed;
|
||||
DXGI_SWAP_EFFECT SwapEffect;
|
||||
UINT Flags;
|
||||
} HG_DXGI_SWAP_CHAIN_DESC;
|
||||
|
||||
struct ConstantBufferType
|
||||
{
|
||||
float demoTime;
|
||||
float deltaTime;
|
||||
float dummy1;
|
||||
float dummy2;
|
||||
};
|
||||
|
||||
#pragma bss_seg(".bss")
|
||||
static HWND hWnd;
|
||||
static ID3D11Device* device;
|
||||
static ID3D11DeviceContext* context;
|
||||
static IDXGISwapChain* swapChain;
|
||||
static ID3D11Texture2D* backBufferTexture;
|
||||
static ID3D11RenderTargetView* renderTargetView;
|
||||
static ID3D11UnorderedAccessView* particleBuffer1UAV;
|
||||
static ID3D11ShaderResourceView* particleBuffer1SRV;
|
||||
static ID3D11UnorderedAccessView* particleBuffer2UAV;
|
||||
static ID3D11ShaderResourceView* particleBuffer2SRV;
|
||||
static ID3D11Buffer* particleBuffer1;
|
||||
static ID3D11Buffer* particleBuffer2;
|
||||
static ID3D11Texture2D* depthBuffer;
|
||||
static ID3D11Buffer* constantBuffer;
|
||||
static ID3D11ComputeShader* initShader;
|
||||
static ID3D11ComputeShader* updateShader;
|
||||
static ID3D11ComputeShader* drawShader;
|
||||
static ID3D11VertexShader* particleVertexShader;
|
||||
static ID3D11GeometryShader* particleGeometryShader;
|
||||
static ID3D11PixelShader* particlePixelShader;
|
||||
static ID3D11InputLayout* particleInputLayout;
|
||||
static ID3D11RenderTargetView* backBufferRtv;
|
||||
static ID3D11DepthStencilState* depthStencilState;
|
||||
static ID3D11DepthStencilView* depthStencilView;
|
||||
static ID3D11BlendState* alphaBlendState;
|
||||
static pD3DCompile d3dCompile;
|
||||
static ID3DBlob* shaderBlob;
|
||||
static void* shaderCode;
|
||||
static SIZE_T shaderSize;
|
||||
static D3D11_MAPPED_SUBRESOURCE mappedResource;
|
||||
static float zero[4];
|
||||
|
||||
#pragma data_seg(".d3dcompiler")
|
||||
static char* d3dcompiler = "d3dcompiler_47.dll";
|
||||
|
||||
#pragma data_seg(".swapChainDesc")
|
||||
#ifdef FULLSCREEN
|
||||
HG_DXGI_SWAP_CHAIN_DESC swapChainDesc = {
|
||||
WIDTH, HEIGHT, 0, 1, DXGI_FORMAT_R16G16B16A16_FLOAT,
|
||||
DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED, DXGI_MODE_SCALING_UNSPECIFIED,
|
||||
4, 0, DXGI_USAGE_RENDER_TARGET_OUTPUT | DXGI_USAGE_SHADER_INPUT, 1, 0, 0, DXGI_SWAP_EFFECT_DISCARD, 0
|
||||
};
|
||||
#else
|
||||
HG_DXGI_SWAP_CHAIN_DESC swapChainDesc = {
|
||||
WIDTH, HEIGHT, 0, 1, DXGI_FORMAT_R16G16B16A16_FLOAT,
|
||||
DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED, DXGI_MODE_SCALING_UNSPECIFIED,
|
||||
4, 0, DXGI_USAGE_RENDER_TARGET_OUTPUT | DXGI_USAGE_SHADER_INPUT, 1, 0, -1, DXGI_SWAP_EFFECT_DISCARD, 0
|
||||
};
|
||||
#endif
|
||||
|
||||
#pragma data_seg(".depthBufferDesc")
|
||||
static D3D11_TEXTURE2D_DESC depthBufferDesc =
|
||||
{
|
||||
WIDTH,
|
||||
HEIGHT,
|
||||
1,
|
||||
1,
|
||||
DXGI_FORMAT_D32_FLOAT,
|
||||
{
|
||||
1, 0
|
||||
},
|
||||
D3D11_USAGE_DEFAULT,
|
||||
D3D11_BIND_DEPTH_STENCIL,
|
||||
0,
|
||||
0
|
||||
};
|
||||
|
||||
#pragma data_seg(".constantBufferDesc")
|
||||
static D3D11_BUFFER_DESC constantBufferDesc =
|
||||
{
|
||||
16,
|
||||
D3D11_USAGE_DYNAMIC,
|
||||
D3D11_BIND_CONSTANT_BUFFER,
|
||||
D3D11_CPU_ACCESS_WRITE,
|
||||
0,
|
||||
0
|
||||
};
|
||||
|
||||
#pragma data_seg(".particleBufferDesc")
|
||||
static D3D11_BUFFER_DESC particleBufferDesc =
|
||||
{
|
||||
1024 * 1024 * 48,
|
||||
D3D11_USAGE_DEFAULT,
|
||||
D3D11_BIND_UNORDERED_ACCESS | D3D11_BIND_SHADER_RESOURCE,
|
||||
0,
|
||||
D3D11_RESOURCE_MISC_BUFFER_STRUCTURED,
|
||||
48
|
||||
};
|
||||
|
||||
#pragma data_seg(".particleBufferDesc")
|
||||
static D3D11_SHADER_RESOURCE_VIEW_DESC particleSrvDesc =
|
||||
{
|
||||
DXGI_FORMAT_UNKNOWN,
|
||||
D3D11_SRV_DIMENSION_BUFFER,
|
||||
{
|
||||
0,
|
||||
1024 * 1024
|
||||
}
|
||||
};
|
||||
|
||||
#pragma data_seg(".particleUavDesc")
|
||||
static D3D11_UNORDERED_ACCESS_VIEW_DESC particleUavDesc =
|
||||
{
|
||||
DXGI_FORMAT_UNKNOWN,
|
||||
D3D11_UAV_DIMENSION_BUFFER,
|
||||
0,
|
||||
1024 * 1024,
|
||||
D3D11_BUFFER_UAV_FLAG_APPEND
|
||||
};
|
||||
|
||||
#pragma data_seg(".vertexUavDesc")
|
||||
static D3D11_UNORDERED_ACCESS_VIEW_DESC vertexUavDesc =
|
||||
{
|
||||
DXGI_FORMAT_UNKNOWN,
|
||||
D3D11_UAV_DIMENSION_BUFFER,
|
||||
0,
|
||||
1024 * 1024,
|
||||
0
|
||||
};
|
||||
|
||||
#pragma data_seg(".particleInputElementDescs")
|
||||
static D3D11_INPUT_ELEMENT_DESC particleInputElementDescs[] =
|
||||
{
|
||||
{
|
||||
"SV_POSITION",
|
||||
0,
|
||||
DXGI_FORMAT_R32G32B32A32_FLOAT,
|
||||
0,
|
||||
0,
|
||||
D3D11_INPUT_PER_VERTEX_DATA,
|
||||
0
|
||||
},
|
||||
{
|
||||
"LENGTH",
|
||||
0,
|
||||
DXGI_FORMAT_R32_FLOAT,
|
||||
0,
|
||||
16,
|
||||
D3D11_INPUT_PER_VERTEX_DATA,
|
||||
0
|
||||
},
|
||||
{
|
||||
"AGE",
|
||||
0,
|
||||
DXGI_FORMAT_R32_FLOAT,
|
||||
0,
|
||||
20,
|
||||
D3D11_INPUT_PER_VERTEX_DATA,
|
||||
0
|
||||
},
|
||||
};
|
||||
|
||||
#pragma data_seg(".backBufferRtvDesc")
|
||||
static D3D11_RENDER_TARGET_VIEW_DESC backBufferRtvDesc =
|
||||
{
|
||||
DXGI_FORMAT_R16G16B16A16_FLOAT,
|
||||
D3D11_RTV_DIMENSION_TEXTURE2DMS,
|
||||
{
|
||||
0
|
||||
}
|
||||
};
|
||||
|
||||
#pragma data_seg(".depthStencilStateDesc")
|
||||
static D3D11_DEPTH_STENCIL_DESC depthStencilStateDesc =
|
||||
{
|
||||
FALSE, // TRUE
|
||||
D3D11_DEPTH_WRITE_MASK_ALL,
|
||||
D3D11_COMPARISON_LESS,
|
||||
FALSE,
|
||||
0,
|
||||
0,
|
||||
{},
|
||||
{}
|
||||
};
|
||||
|
||||
#pragma data_seg(".swapChainViewport")
|
||||
static D3D11_VIEWPORT swapChainViewport =
|
||||
{
|
||||
0,
|
||||
0,
|
||||
WIDTH,
|
||||
HEIGHT,
|
||||
0.0f,
|
||||
1.0f,
|
||||
};
|
||||
|
||||
#pragma data_seg(".depthStencilViewDesc")
|
||||
static D3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc =
|
||||
{
|
||||
DXGI_FORMAT_D32_FLOAT,
|
||||
D3D11_DSV_DIMENSION_TEXTURE2D,
|
||||
0,
|
||||
{
|
||||
0
|
||||
}
|
||||
};
|
||||
|
||||
#pragma data_seg(".alphaBlendDesc")
|
||||
static D3D11_BLEND_DESC alphaBlendDesc =
|
||||
{
|
||||
FALSE,
|
||||
FALSE,
|
||||
{
|
||||
TRUE,
|
||||
D3D11_BLEND_SRC_ALPHA,
|
||||
D3D11_BLEND_INV_SRC_ALPHA,
|
||||
D3D11_BLEND_OP_ADD,
|
||||
D3D11_BLEND_ONE,
|
||||
D3D11_BLEND_ONE,
|
||||
D3D11_BLEND_OP_ADD,
|
||||
D3D11_COLOR_WRITE_ENABLE_ALL,
|
||||
}
|
||||
};
|
||||
BIN
hgplus/particles/draw.cso
Normal file
BIN
hgplus/particles/draw.cso
Normal file
Binary file not shown.
BIN
hgplus/particles/draw.pdb
Normal file
BIN
hgplus/particles/draw.pdb
Normal file
Binary file not shown.
BIN
hgplus/particles/init.cso
Normal file
BIN
hgplus/particles/init.cso
Normal file
Binary file not shown.
BIN
hgplus/particles/init.pdb
Normal file
BIN
hgplus/particles/init.pdb
Normal file
Binary file not shown.
166
hgplus/particles/main.cpp
Normal file
166
hgplus/particles/main.cpp
Normal file
@@ -0,0 +1,166 @@
|
||||
#include "data.h"
|
||||
#include "shaders.h"
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
#ifdef FULLSCREEN
|
||||
ShowCursor(0);
|
||||
hWnd = CreateWindowExA(0, (LPCSTR)ATOM_STATIC, 0, WS_POPUP | WS_VISIBLE | WS_MAXIMIZE, 0, 0, 0, 0, 0, 0, 0, 0);
|
||||
//ShowWindow(hWnd, SW_SHOW);
|
||||
#else
|
||||
#ifdef _DEBUG
|
||||
WNDCLASSEX wndclass;
|
||||
wndclass.cbSize = sizeof (wndclass);
|
||||
wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
|
||||
wndclass.lpfnWndProc = (WNDPROC)DefWindowProc;
|
||||
wndclass.cbClsExtra = 0;
|
||||
wndclass.cbWndExtra = 0;
|
||||
wndclass.hInstance = NULL;
|
||||
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
|
||||
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
|
||||
wndclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
|
||||
wndclass.lpszMenuName = NULL;
|
||||
wndclass.lpszClassName = "BluFlame intro window class";
|
||||
wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
|
||||
|
||||
RegisterClassEx(&wndclass);
|
||||
|
||||
hWnd = CreateWindowExA(0,
|
||||
wndclass.lpszClassName,
|
||||
"Intro",
|
||||
WS_EX_APPWINDOW,
|
||||
GetSystemMetrics(SM_CXSCREEN) - WIDTH - 16,
|
||||
0,
|
||||
WIDTH + 16,
|
||||
HEIGHT + 40,
|
||||
NULL,
|
||||
NULL,
|
||||
GetModuleHandle(NULL),
|
||||
NULL
|
||||
);
|
||||
ShowWindow(hWnd, SW_NORMAL);
|
||||
SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
|
||||
#else
|
||||
hWnd = CreateWindowExA(0, (LPCSTR)ATOM_STATIC, 0, WS_POPUP | WS_VISIBLE, 0, 0, WIDTH, HEIGHT, 0, 0, 0, 0);
|
||||
#endif
|
||||
#endif
|
||||
swapChainDesc.OutputWindow = hWnd;
|
||||
D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, D3D11_CREATE_DEVICE_DEBUG, NULL, 0, D3D11_SDK_VERSION, (DXGI_SWAP_CHAIN_DESC*)&swapChainDesc, &swapChain, &device, NULL, &context);
|
||||
swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&backBufferTexture);
|
||||
|
||||
device->CreateTexture2D(&depthBufferDesc, NULL, &depthBuffer);
|
||||
|
||||
device->CreateBuffer(&constantBufferDesc, NULL, &constantBuffer);
|
||||
|
||||
device->CreateBuffer(&particleBufferDesc, NULL, &particleBuffer1);
|
||||
device->CreateUnorderedAccessView(particleBuffer1, &particleUavDesc, &particleBuffer1UAV);
|
||||
device->CreateShaderResourceView(particleBuffer1, &particleSrvDesc, &particleBuffer1SRV);
|
||||
|
||||
device->CreateBuffer(&particleBufferDesc, NULL, &particleBuffer2);
|
||||
device->CreateUnorderedAccessView(particleBuffer2, &particleUavDesc, &particleBuffer2UAV);
|
||||
device->CreateShaderResourceView(particleBuffer2, &particleSrvDesc, &particleBuffer2SRV);
|
||||
|
||||
device->CreateRenderTargetView(backBufferTexture, &backBufferRtvDesc, &backBufferRtv);
|
||||
device->CreateDepthStencilState(&depthStencilStateDesc, &depthStencilState);
|
||||
device->CreateDepthStencilView(depthBuffer, &depthStencilViewDesc, &depthStencilView);
|
||||
|
||||
device->CreateBlendState(&alphaBlendDesc, &alphaBlendState);
|
||||
|
||||
#ifndef _DEBUG
|
||||
CreateShaders();
|
||||
#else
|
||||
#ifndef SHADERDEBUG
|
||||
InitShader();
|
||||
shaderCompileEvent = ::CreateEvent(NULL, FALSE, FALSE, TEXT("WriteEvent"));
|
||||
SetThreadPriority((HANDLE)CreateThread(0, 0, &filemon, 0, 0, 0), THREAD_PRIORITY_BELOW_NORMAL);
|
||||
#endif
|
||||
CreateShaders();
|
||||
#endif
|
||||
|
||||
ID3D11UnorderedAccessView* uavs[] = { particleBuffer1UAV, particleBuffer2UAV };
|
||||
ID3D11ShaderResourceView* srvs[] = { particleBuffer1SRV, particleBuffer2SRV };
|
||||
|
||||
UINT indices[] = { -1, 0, 0, 0 };
|
||||
context->CSSetUnorderedAccessViews(0, 2, uavs, indices);
|
||||
context->CSSetConstantBuffers(0, 1, &constantBuffer);
|
||||
context->CSSetShader(initShader, NULL, 0);
|
||||
context->Dispatch(1, 1, 1);
|
||||
|
||||
float demoTime = 0.0f;
|
||||
LARGE_INTEGER startTime;
|
||||
QueryPerformanceCounter(&startTime);
|
||||
do {
|
||||
#ifdef _DEBUG
|
||||
MSG msg;
|
||||
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
|
||||
{
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
#endif
|
||||
context->ClearRenderTargetView(backBufferRtv, zero);
|
||||
context->ClearDepthStencilView(depthStencilView, D3D11_CLEAR_DEPTH, 1.0f, 0);
|
||||
auto uavtemp = uavs[1];
|
||||
uavs[1] = uavs[0];
|
||||
uavs[0] = uavtemp;
|
||||
auto srvtemp = srvs[1];
|
||||
srvs[1] = srvs[0];
|
||||
srvs[0] = srvtemp;
|
||||
context->ClearUnorderedAccessViewUint(uavs[1], (UINT*)zero);
|
||||
context->CSSetUnorderedAccessViews(0, 2, uavs, indices);
|
||||
|
||||
context->Map(constantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
|
||||
auto constantBufferVertexData = (ConstantBufferType*)mappedResource.pData;
|
||||
|
||||
LARGE_INTEGER time;
|
||||
LARGE_INTEGER freq;
|
||||
QueryPerformanceCounter(&time);
|
||||
QueryPerformanceFrequency(&freq);
|
||||
float deltaTime = (float(time.QuadPart - startTime.QuadPart) / freq.QuadPart);
|
||||
//deltaTime *= 0.05f;
|
||||
startTime = time;
|
||||
demoTime += deltaTime;
|
||||
constantBufferVertexData->demoTime = demoTime;
|
||||
constantBufferVertexData->deltaTime = deltaTime;
|
||||
constantBufferVertexData->dummy1 = 1.0f;
|
||||
constantBufferVertexData->dummy2 = 1.0f;
|
||||
|
||||
context->Unmap(constantBuffer, 0);
|
||||
|
||||
context->CSSetShader(updateShader, NULL, 0);
|
||||
context->Dispatch(1024, 1024, 1);
|
||||
context->CSSetUnorderedAccessViews(0, 2, (ID3D11UnorderedAccessView* const *)zero, NULL);
|
||||
|
||||
UINT strides[] = { 48 };
|
||||
context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
|
||||
context->VSSetConstantBuffers(0, 1, &constantBuffer);
|
||||
context->VSSetShader(particleVertexShader, NULL, 0);
|
||||
context->GSSetShader(particleGeometryShader, NULL, 0);
|
||||
context->PSSetShader(particlePixelShader, NULL, 0);
|
||||
context->OMSetRenderTargets(1, &backBufferRtv, NULL/*depthStencilView*/);
|
||||
//context->OMSetDepthStencilState(depthStencilState, 1);
|
||||
context->OMSetBlendState(alphaBlendState, NULL, 0xffffffff);
|
||||
context->RSSetViewports(1, &swapChainViewport);
|
||||
context->VSSetShaderResources(0, 1, &srvs[1]);
|
||||
|
||||
context->DrawInstanced(1024 * 1024, 1, 0, 0);
|
||||
|
||||
context->VSSetShaderResources(0, 1, (ID3D11ShaderResourceView* const*)zero);
|
||||
|
||||
swapChain->Present(1, 0);
|
||||
|
||||
//::Sleep(1000 * 0.05);
|
||||
|
||||
#ifdef _DEBUG
|
||||
#ifndef SHADERDEBUG
|
||||
if (::WaitForSingleObject(shaderCompileEvent, 0) == WAIT_OBJECT_0)
|
||||
{
|
||||
::Sleep(50);
|
||||
CreateShaders();
|
||||
::Sleep(50);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
} while (!GetAsyncKeyState(VK_ESCAPE));
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
25
hgplus/particles/particles.sln
Normal file
25
hgplus/particles/particles.sln
Normal file
@@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2013
|
||||
VisualStudioVersion = 12.0.21005.1
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "particles", "particles.vcxproj", "{5D25DE85-C37F-4D88-B675-E000CF62FD9F}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
LiveEdit|Win32 = LiveEdit|Win32
|
||||
Release|Win32 = Release|Win32
|
||||
ShaderDebug|Win32 = ShaderDebug|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{5D25DE85-C37F-4D88-B675-E000CF62FD9F}.LiveEdit|Win32.ActiveCfg = LiveEdit|Win32
|
||||
{5D25DE85-C37F-4D88-B675-E000CF62FD9F}.LiveEdit|Win32.Build.0 = LiveEdit|Win32
|
||||
{5D25DE85-C37F-4D88-B675-E000CF62FD9F}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{5D25DE85-C37F-4D88-B675-E000CF62FD9F}.Release|Win32.Build.0 = Release|Win32
|
||||
{5D25DE85-C37F-4D88-B675-E000CF62FD9F}.ShaderDebug|Win32.ActiveCfg = ShaderDebug|Win32
|
||||
{5D25DE85-C37F-4D88-B675-E000CF62FD9F}.ShaderDebug|Win32.Build.0 = ShaderDebug|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
BIN
hgplus/particles/particles.v12.suo
Normal file
BIN
hgplus/particles/particles.v12.suo
Normal file
Binary file not shown.
147
hgplus/particles/particles.vcxproj
Normal file
147
hgplus/particles/particles.vcxproj
Normal file
@@ -0,0 +1,147 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="LiveEdit|Win32">
|
||||
<Configuration>LiveEdit</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="ShaderDebug|Win32">
|
||||
<Configuration>ShaderDebug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{5D25DE85-C37F-4D88-B675-E000CF62FD9F}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>particles</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='LiveEdit|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<CharacterSet>NotSet</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ShaderDebug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<CharacterSet>NotSet</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>NotSet</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='LiveEdit|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='ShaderDebug|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='LiveEdit|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ShaderDebug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='LiveEdit|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;d3d11.lib;d3dcompiler.lib</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ShaderDebug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>SHADER_DEBUG;WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;d3d11.lib;d3dcompiler.lib</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ExceptionHandling>false</ExceptionHandling>
|
||||
<BufferSecurityCheck>false</BufferSecurityCheck>
|
||||
<FloatingPointModel>Fast</FloatingPointModel>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;d3d11.lib;d3dcompiler.lib</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<FxCompile Include="test.hlsl">
|
||||
<EntryPointName Condition="'$(Configuration)|$(Platform)'=='LiveEdit|Win32'">cs</EntryPointName>
|
||||
<EntryPointName Condition="'$(Configuration)|$(Platform)'=='ShaderDebug|Win32'">cs</EntryPointName>
|
||||
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='LiveEdit|Win32'">5.0</ShaderModel>
|
||||
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='ShaderDebug|Win32'">5.0</ShaderModel>
|
||||
<ShaderType Condition="'$(Configuration)|$(Platform)'=='LiveEdit|Win32'">Compute</ShaderType>
|
||||
<ShaderType Condition="'$(Configuration)|$(Platform)'=='ShaderDebug|Win32'">Compute</ShaderType>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='LiveEdit|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='ShaderDebug|Win32'">true</ExcludedFromBuild>
|
||||
</FxCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="data.h" />
|
||||
<ClInclude Include="shaders.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CustomBuild Include="shaders.cmd">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='ShaderDebug|Win32'">false</ExcludedFromBuild>
|
||||
<FileType>Document</FileType>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='ShaderDebug|Win32'">%(FullPath)</Command>
|
||||
<Message Condition="'$(Configuration)|$(Platform)'=='ShaderDebug|Win32'">Compiling shader...</Message>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='ShaderDebug|Win32'">%(FullPath)</Outputs>
|
||||
<AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='ShaderDebug|Win32'">$(ProjectDir)test.hlsl;%(AdditionalInputs)</AdditionalInputs>
|
||||
</CustomBuild>
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
6
hgplus/particles/particles.vcxproj.user
Normal file
6
hgplus/particles/particles.vcxproj.user
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<ShowAllFiles>false</ShowAllFiles>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
BIN
hgplus/particles/pgs.cso
Normal file
BIN
hgplus/particles/pgs.cso
Normal file
Binary file not shown.
BIN
hgplus/particles/pgs.pdb
Normal file
BIN
hgplus/particles/pgs.pdb
Normal file
Binary file not shown.
BIN
hgplus/particles/pps.cso
Normal file
BIN
hgplus/particles/pps.cso
Normal file
Binary file not shown.
BIN
hgplus/particles/pps.pdb
Normal file
BIN
hgplus/particles/pps.pdb
Normal file
Binary file not shown.
BIN
hgplus/particles/pvs.cso
Normal file
BIN
hgplus/particles/pvs.cso
Normal file
Binary file not shown.
BIN
hgplus/particles/pvs.pdb
Normal file
BIN
hgplus/particles/pvs.pdb
Normal file
Binary file not shown.
6
hgplus/particles/shaders.cmd
Normal file
6
hgplus/particles/shaders.cmd
Normal file
@@ -0,0 +1,6 @@
|
||||
fxc /Zi /E"init" /Od /Fo"init.cso" /Fd"init.pdb" /T cs_5_0 /nologo test.hlsl
|
||||
fxc /Zi /E"update" /Od /Fo"update.cso" /Fd"update.pdb" /T cs_5_0 /nologo test.hlsl
|
||||
fxc /Zi /E"pvs" /Od /Fo"pvs.cso" /Fd"pvs.pdb" /T vs_5_0 /nologo test.hlsl
|
||||
fxc /Zi /E"pgs" /Od /Fo"pgs.cso" /Fd"pgs.pdb" /T gs_5_0 /nologo test.hlsl
|
||||
fxc /Zi /E"pps" /Od /Fo"pps.cso" /Fd"pps.pdb" /T ps_5_0 /nologo test.hlsl
|
||||
|
||||
190
hgplus/particles/shaders.h
Normal file
190
hgplus/particles/shaders.h
Normal file
@@ -0,0 +1,190 @@
|
||||
#ifdef _DEBUG
|
||||
#include <process.h>
|
||||
#include <io.h>
|
||||
#include <stdio.h>
|
||||
HANDLE shaderCompileEvent;
|
||||
static char** lastShader;
|
||||
static __time64_t shaderChangedDate;
|
||||
#define shaderDir "E:\\blu-flame.org\\hgplus\\particles\\"
|
||||
#define shaderFile "E:\\blu-flame.org\\hgplus\\particles\\test.hlsl"
|
||||
|
||||
char* ReadFile(char* name, SIZE_T* fileLen)
|
||||
{
|
||||
FILE *file = 0;
|
||||
char *buffer = 0;
|
||||
|
||||
//Open file
|
||||
fopen_s(&file, name, "rb");
|
||||
if (!file)
|
||||
{
|
||||
printf("Unable to open file %s\n", name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
//Get file length
|
||||
fseek(file, 0, SEEK_END);
|
||||
*fileLen = ftell(file);
|
||||
fseek(file, 0, SEEK_SET);
|
||||
|
||||
//Allocate memory
|
||||
buffer = (char *)malloc(*fileLen + 1);
|
||||
if (!buffer)
|
||||
{
|
||||
fprintf(stderr, "Memory error!\n");
|
||||
fclose(file);
|
||||
return 0;
|
||||
}
|
||||
|
||||
//Read file contents into buffer
|
||||
fread(buffer, *fileLen, 1, file);
|
||||
fclose(file);
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
void log(char* text)
|
||||
{
|
||||
printf(text);
|
||||
OutputDebugStringA(text);
|
||||
}
|
||||
|
||||
DWORD WINAPI filemon(void* args)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
_finddata_t fdata;
|
||||
long hfile = _findfirst(shaderFile, &fdata);
|
||||
if (hfile != -1)
|
||||
{
|
||||
if (fdata.time_write != shaderChangedDate)
|
||||
{
|
||||
shaderChangedDate = fdata.time_write;
|
||||
::SetEvent(shaderCompileEvent);
|
||||
}
|
||||
_findclose(hfile);
|
||||
}
|
||||
::Sleep(100);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void InitShader()
|
||||
{
|
||||
_finddata_t fdata;
|
||||
long hfile = _findfirst(shaderFile, &fdata);
|
||||
if (hfile != -1)
|
||||
{
|
||||
shaderChangedDate = fdata.time_write;
|
||||
_findclose(hfile);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef _DEBUG
|
||||
#ifdef SHADER_DEBUG
|
||||
#define CompileShader(entryPoint, profile) CompileShaderD(shaderDir entryPoint ".cso", entryPoint, profile);
|
||||
#else
|
||||
#define CompileShader(entryPoint, profile) CompileShaderD(shaderFile, entryPoint, profile);
|
||||
#endif
|
||||
|
||||
void CompileShaderD(char* fileName, char* entryPoint, char* profile)
|
||||
{
|
||||
#ifdef SHADER_DEBUG
|
||||
shaderCode = ReadFile(fileName, &shaderSize);
|
||||
#else
|
||||
ID3DBlob* errorBlob;
|
||||
SIZE_T blobLength = 0;
|
||||
auto blob = ReadFile(fileName, &blobLength);
|
||||
d3dCompile(blob, blobLength, shaderFile, NULL, NULL, entryPoint, profile, 0, 0, &shaderBlob, &errorBlob);
|
||||
if (errorBlob != NULL)
|
||||
{
|
||||
auto error = errorBlob->GetBufferPointer();
|
||||
OutputDebugStringA((char*)error);
|
||||
if (shaderBlob == 0)
|
||||
{
|
||||
printf("Error compiling shader: ");
|
||||
printf((char*)error);
|
||||
printf("\n");
|
||||
ExitProcess(-1);
|
||||
}
|
||||
}
|
||||
if (shaderBlob != 0)
|
||||
{
|
||||
shaderSize = shaderBlob->GetBufferSize();
|
||||
shaderCode = shaderBlob->GetBufferPointer();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#else
|
||||
#define CompileShader(entryPoint, profile) CompileShaderR(entryPoint, profile);
|
||||
|
||||
#pragma code_seg(".CompileShader")
|
||||
void CompileShaderR(char* entryPoint, char* profile)
|
||||
{
|
||||
#ifndef COMPRESS
|
||||
ID3DBlob* errorBlob;
|
||||
d3dCompile(Shader_hlsl, sizeof(Shader_hlsl), NULL, NULL, NULL, entryPoint, profile, 0, 0, &shaderBlob, &errorBlob);
|
||||
if (errorBlob != NULL)
|
||||
{
|
||||
auto error = errorBlob->GetBufferPointer();
|
||||
OutputDebugStringA((char*)error);
|
||||
}
|
||||
#else
|
||||
d3dCompile(Shader_hlsl, sizeof(Shader_hlsl), NULL, NULL, NULL, entryPoint, profile, 0, 0, &shaderBlob, NULL);
|
||||
#endif
|
||||
//if (shaderBlob != 0)
|
||||
{
|
||||
shaderSize = shaderBlob->GetBufferSize();
|
||||
shaderCode = shaderBlob->GetBufferPointer();
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
#pragma data_seg(".vs_5_0")
|
||||
static char vs_5_0[] = "vs_5_0";
|
||||
|
||||
#pragma data_seg(".gs_5_0")
|
||||
static char gs_5_0[] = "gs_5_0";
|
||||
|
||||
#pragma data_seg(".ds_5_0")
|
||||
static char ds_5_0[] = "ds_5_0";
|
||||
|
||||
#pragma data_seg(".hs_5_0")
|
||||
static char hs_5_0[] = "hs_5_0";
|
||||
|
||||
#pragma data_seg(".ps_5_0")
|
||||
static char ps_5_0[] = "ps_5_0";
|
||||
|
||||
#pragma data_seg(".ps_5_0")
|
||||
static char cs_5_0[] = "cs_5_0";
|
||||
|
||||
#pragma code_seg(".CreateShaders")
|
||||
void CreateShaders()
|
||||
{
|
||||
HINSTANCE hl = LoadLibraryA(d3dcompiler);
|
||||
if (!hl)
|
||||
{
|
||||
d3dcompiler[13] = '3';
|
||||
hl = LoadLibraryA(d3dcompiler);
|
||||
}
|
||||
d3dCompile = (pD3DCompile)GetProcAddress(hl, "D3DCompile");
|
||||
|
||||
CompileShader("init", cs_5_0);
|
||||
device->CreateComputeShader(shaderCode, shaderSize, 0, &initShader);
|
||||
|
||||
CompileShader("update", cs_5_0);
|
||||
device->CreateComputeShader(shaderCode, shaderSize, 0, &updateShader);
|
||||
|
||||
CompileShader("pvs", vs_5_0);
|
||||
device->CreateVertexShader(shaderCode, shaderSize, 0, &particleVertexShader);
|
||||
|
||||
CompileShader("pgs", gs_5_0);
|
||||
device->CreateGeometryShader(shaderCode, shaderSize, 0, &particleGeometryShader);
|
||||
|
||||
//device->CreateInputLayout(particleInputElementDescs, 1, shaderCode, shaderSize, &particleInputLayout);
|
||||
|
||||
CompileShader("pps", ps_5_0);
|
||||
device->CreatePixelShader(shaderCode, shaderSize, 0, &particlePixelShader);
|
||||
}
|
||||
200
hgplus/particles/test.hlsl
Normal file
200
hgplus/particles/test.hlsl
Normal file
@@ -0,0 +1,200 @@
|
||||
#define ParticleType_Dead 0
|
||||
#define ParticleType_Emitter 1
|
||||
#define ParticleType_Point 2
|
||||
|
||||
struct ParticleState
|
||||
{
|
||||
int type;
|
||||
float3 oldPosition;
|
||||
float3 currentPosition;
|
||||
float3 direction;
|
||||
float creationTime;
|
||||
float mass;
|
||||
};//48 bytes
|
||||
|
||||
#define PI 3.14159265
|
||||
|
||||
float hash(float n) { return frac(sin(n)*43758.5453123); }
|
||||
|
||||
cbuffer _0 : register(b0)
|
||||
{
|
||||
float demoTime;
|
||||
float deltaTime;
|
||||
float dummy1;
|
||||
float dummy2;
|
||||
};
|
||||
|
||||
static const float emitRate = 0.00001f; //delay in seconds between each particle spawn
|
||||
static const float lifeTime = 1.0f; //particle lifetime in seconds
|
||||
|
||||
ConsumeStructuredBuffer<ParticleState> particles:register(u0);
|
||||
AppendStructuredBuffer<ParticleState> writeParticles:register(u1);
|
||||
StructuredBuffer<ParticleState> readParticles:register(t0);
|
||||
|
||||
void emit(int type, float3 oldPosition, float3 position, float3 direction, float time)
|
||||
{
|
||||
ParticleState emittedParticle;
|
||||
emittedParticle.type = type;
|
||||
emittedParticle.oldPosition = position;
|
||||
emittedParticle.currentPosition = position;
|
||||
emittedParticle.creationTime = time;
|
||||
emittedParticle.direction = direction;
|
||||
emittedParticle.mass = 1;
|
||||
writeParticles.Append(emittedParticle); // emit new particle
|
||||
}
|
||||
|
||||
void recycle(ParticleState particle)
|
||||
{
|
||||
ParticleState newParticle;
|
||||
newParticle.type = particle.type;
|
||||
newParticle.oldPosition = particle.currentPosition;
|
||||
newParticle.currentPosition = particle.currentPosition + particle.direction * deltaTime;
|
||||
newParticle.creationTime = particle.creationTime;
|
||||
newParticle.direction = particle.direction;
|
||||
if (particle.type == ParticleType_Point)
|
||||
newParticle.direction += float3(0, -10, 0) * deltaTime;
|
||||
newParticle.mass = particle.mass;
|
||||
writeParticles.Append(newParticle);
|
||||
}
|
||||
|
||||
[numthreads(1, 1, 1)]
|
||||
void init(int3 id:SV_DispatchThreadID)
|
||||
{
|
||||
emit(ParticleType_Emitter, float3(0, 0, 0), float3(0, 0, 0), float3(0, 0, 0), demoTime);
|
||||
}
|
||||
|
||||
float3 project(float3 v)
|
||||
{
|
||||
return float3(v.x, v.y, (1 - v.z) / 10.0f) / -v.z;
|
||||
}
|
||||
|
||||
float3 h2r(float h, float s, float v){ return lerp(saturate((abs(frac(h + float3(1, 2, 3) / 3) * 6 - 3) - 1)), 1, s)*v; }
|
||||
|
||||
[numthreads(1, 1, 1)]
|
||||
void update(int3 id:SV_DispatchThreadID)
|
||||
{
|
||||
float seed = 1024 * id.y + id.x + hash(demoTime) * 1024;
|
||||
ParticleState particle = particles.Consume();
|
||||
if (particle.type == ParticleType_Emitter)
|
||||
{
|
||||
float t = particle.creationTime;
|
||||
particle.currentPosition = float3(sin(t * 20), -1, cos(t * 20) - 3) * 0.3;
|
||||
if (demoTime - particle.creationTime < emitRate)
|
||||
{
|
||||
recycle(particle);
|
||||
}
|
||||
else
|
||||
{
|
||||
while (t <= demoTime)
|
||||
{
|
||||
particle.currentPosition = float3(sin(t * 20), -1, cos(t * 20) - 3) * 0.3;
|
||||
emit(ParticleType_Point, particle.currentPosition, particle.currentPosition, hash(seed++ * demoTime) * 5 * normalize(float3(hash(seed++) * 2 - 1, 10 * hash(seed++ * demoTime * demoTime), hash(seed++ * demoTime * 10) * 2 - 1)), t);
|
||||
t += emitRate;
|
||||
}
|
||||
emit(ParticleType_Emitter, particle.currentPosition, particle.currentPosition, particle.direction, t);
|
||||
}
|
||||
}
|
||||
else if (particle.type == ParticleType_Point)
|
||||
{
|
||||
float age = (demoTime - particle.creationTime) / lifeTime;
|
||||
uint index;
|
||||
|
||||
if (age <= 1)
|
||||
{
|
||||
recycle(particle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct _2
|
||||
{
|
||||
float3 pos1 : TEXCOORD0;
|
||||
float3 pos2 : TEXCOORD1;
|
||||
float3 dir : TEXCOORD2;
|
||||
float age : AGE;
|
||||
int valid : VALID;
|
||||
};
|
||||
|
||||
struct _3
|
||||
{
|
||||
float4 pos : SV_POSITION;
|
||||
float length : LENGTH;
|
||||
float age : AGE;
|
||||
};
|
||||
|
||||
void pvs(uint id : SV_VertexID, out _2 o)
|
||||
{
|
||||
ParticleState particle = readParticles[id];
|
||||
o.pos1 = particle.oldPosition;
|
||||
o.pos2 = particle.currentPosition;
|
||||
o.dir = particle.direction;
|
||||
o.age = (demoTime - particle.creationTime) / lifeTime;
|
||||
o.valid = particle.type == ParticleType_Point ? 1 : 0;
|
||||
}
|
||||
|
||||
float particleSize(float z)
|
||||
{
|
||||
return 0.0005f / -z;
|
||||
}
|
||||
|
||||
[maxvertexcount(18)]
|
||||
void pgs(point _2 input[1], inout TriangleStream<_3> o)
|
||||
{
|
||||
_2 p = input[0];
|
||||
if (p.valid == 0)
|
||||
return;
|
||||
|
||||
float s1 = particleSize(p.pos1.z);
|
||||
float s2 = particleSize(p.pos2.z);
|
||||
|
||||
float3 p1 = project(p.pos1);
|
||||
float3 p2 = project(p.pos2);
|
||||
float2 d = normalize(p2.xy - p1.xy);
|
||||
if (length(d) == 0)
|
||||
d = normalize(project(p.dir).xy);
|
||||
|
||||
float2 pr = float2(-d.y, d.x);
|
||||
p1.xy += d * s1 * 0.5;
|
||||
p2.xy -= d * s2 * 0.5;
|
||||
|
||||
_3 r;
|
||||
r.length = distance(p1.xy, p2.xy) * 128;
|
||||
r.age = p.age;
|
||||
|
||||
r.pos = float4(p1.xy - d * s1, p1.z, 1.0); o.Append(r);
|
||||
r.pos = float4(p1.xy + pr * s1, p1.z, 1.0); o.Append(r);
|
||||
r.pos = float4(p1.xy - pr * s1, p1.z, 1.0); o.Append(r);
|
||||
o.RestartStrip();
|
||||
|
||||
r.pos = float4(p1.xy - pr * s1, p1.z, 1.0); o.Append(r);
|
||||
r.pos = float4(p1, 1.0); o.Append(r);
|
||||
r.pos = float4(p2.xy - pr * s2, p2.z, 1.0); o.Append(r);
|
||||
o.RestartStrip();
|
||||
|
||||
r.pos = float4(p1, 1.0); o.Append(r);
|
||||
r.pos = float4(p2, 1.0); o.Append(r);
|
||||
r.pos = float4(p2.xy - pr * s2, p2.z, 1.0); o.Append(r);
|
||||
o.RestartStrip();
|
||||
|
||||
r.pos = float4(p1, 1.0); o.Append(r);
|
||||
r.pos = float4(p2.xy + pr * s2, p2.z, 1.0); o.Append(r);
|
||||
r.pos = float4(p2, 1.0); o.Append(r);
|
||||
o.RestartStrip();
|
||||
|
||||
r.pos = float4(p1, 1.0); o.Append(r);
|
||||
r.pos = float4(p1.xy + pr * s1, p1.z, 1.0); o.Append(r);
|
||||
r.pos = float4(p2.xy + pr * s2, p2.z, 1.0); o.Append(r);
|
||||
o.RestartStrip();
|
||||
|
||||
r.pos = float4(p2.xy + d * s2, p2.z, 1.0); o.Append(r);
|
||||
r.pos = float4(p2.xy - pr * s2, p2.z, 1.0); o.Append(r);
|
||||
r.pos = float4(p2.xy + pr * s2, p2.z, 1.0); o.Append(r);
|
||||
o.RestartStrip();
|
||||
}
|
||||
|
||||
float4 pps(_3 i) : SV_Target
|
||||
{
|
||||
float intensity = 1.0 / (i.length + 50);
|
||||
float3 color = h2r(i.age * 3, 0.2, 1.0);
|
||||
return float4(color, intensity);
|
||||
}
|
||||
BIN
hgplus/particles/update.cso
Normal file
BIN
hgplus/particles/update.cso
Normal file
Binary file not shown.
BIN
hgplus/particles/update.pdb
Normal file
BIN
hgplus/particles/update.pdb
Normal file
Binary file not shown.
Reference in New Issue
Block a user