port from perforce

This commit is contained in:
2026-04-18 22:31:51 +02:00
commit 8d0ab5b7cc
8409 changed files with 3972376 additions and 0 deletions

Binary file not shown.

View File

@@ -0,0 +1,23 @@
e:\blu-flame.org\hgplus\particles\liveedit\vc120.pdb
e:\blu-flame.org\hgplus\particles\liveedit\vc120.idb
e:\blu-flame.org\hgplus\particles\liveedit\main.obj
e:\blu-flame.org\hgplus\sdfparticles\liveedit\vc120.pdb
e:\blu-flame.org\hgplus\sdfparticles\liveedit\vc120.idb
e:\blu-flame.org\hgplus\sdfparticles\liveedit\main.obj
e:\blu-flame.org\hgplus\particles\liveedit\particles.ilk
e:\blu-flame.org\hgplus\particles\liveedit\particles.exe
e:\blu-flame.org\hgplus\particles\liveedit\particles.pdb
e:\blu-flame.org\hgplus\sdfparticles\liveedit\particles.ilk
e:\blu-flame.org\hgplus\sdfparticles\liveedit\particles.exe
e:\blu-flame.org\hgplus\sdfparticles\liveedit\particles.pdb
e:\blu-flame.org\hgplus\sdfparticles\liveedit\test.cso
e:\blu-flame.org\hgplus\sdfparticles\liveedit\particles.tlog\cl.command.1.tlog
e:\blu-flame.org\hgplus\sdfparticles\liveedit\particles.tlog\cl.read.1.tlog
e:\blu-flame.org\hgplus\sdfparticles\liveedit\particles.tlog\cl.write.1.tlog
e:\blu-flame.org\hgplus\sdfparticles\liveedit\particles.tlog\custombuild.command.1.tlog
e:\blu-flame.org\hgplus\sdfparticles\liveedit\particles.tlog\custombuild.read.1.tlog
e:\blu-flame.org\hgplus\sdfparticles\liveedit\particles.tlog\custombuild.write.1.tlog
e:\blu-flame.org\hgplus\sdfparticles\liveedit\particles.tlog\link.command.1.tlog
e:\blu-flame.org\hgplus\sdfparticles\liveedit\particles.tlog\link.read.1.tlog
e:\blu-flame.org\hgplus\sdfparticles\liveedit\particles.tlog\link.write.1.tlog
e:\blu-flame.org\hgplus\sdfparticles\liveedit\particles.tlog\particles.write.1u.tlog

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,18 @@
Build started 21.07.2018 17:25:05.
1>Project "E:\blu-flame.org\hgplus\sdfparticles\particles.vcxproj" on node 2 (Build target(s)).
1>InitializeBuildStatus:
Touching "LiveEdit\particles.tlog\unsuccessfulbuild".
ClCompile:
All outputs are up-to-date.
Link:
All outputs are up-to-date.
particles.vcxproj -> E:\blu-flame.org\hgplus\sdfparticles\LiveEdit\particles.exe
particles.vcxproj -> E:\blu-flame.org\hgplus\sdfparticles\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\sdfparticles\particles.vcxproj" (Build target(s)).
Build succeeded.
Time Elapsed 00:00:00.03

Binary file not shown.

View File

@@ -0,0 +1,2 @@
#TargetFrameworkVersion=v4.0:PlatformToolSet=v141:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=8.1
LiveEdit|Win32|E:\blu-flame.org\hgplus\sdfparticles\|

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

225
hgplus/sdfparticles/data.h Normal file
View File

@@ -0,0 +1,225 @@
#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 PARTICLE_COUNT 512
#define PARTICLE_STRIDE 56
#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* particleBufferUAV;
static ID3D11ShaderResourceView* particleBufferSRV;
static ID3D11Buffer* particleBuffer;
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 ID3D11BlendState* alphaBlendState;
static ID3D11RasterizerState* rasterizerState;
static ID3D11VertexShader* raymarchingVertexShader;
static ID3D11PixelShader* raymarchingPixelShader;
//---
// Postprocessing shaders
//---
static ID3D11UnorderedAccessView* backBufferUAV;
static ID3D11ComputeShader* csDistortChroma;
static ID3D11ComputeShader* csRadialBlur;
static ID3D11ComputeShader* csCircumferentialBlur;
static ID3D11ComputeShader* csStreaks;
static ID3D11ComputeShader* csLensDirt;
static ID3D11ComputeShader* csBlurH;
static ID3D11ComputeShader* csBlurV;
static ID3D11ComputeShader* csGhosts;
static ID3D11ComputeShader* csMerge;
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,
1, 0, DXGI_USAGE_RENDER_TARGET_OUTPUT | DXGI_USAGE_UNORDERED_ACCESS | 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,
1, 0, DXGI_USAGE_RENDER_TARGET_OUTPUT | DXGI_USAGE_UNORDERED_ACCESS | 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(".rasterizerDesc")
static D3D11_RASTERIZER_DESC rasterizerDesc =
{
D3D11_FILL_SOLID,
D3D11_CULL_NONE,
TRUE,
0,
0.0f,
0.0f,
TRUE,
FALSE,
FALSE,
FALSE
};
#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 =
{
PARTICLE_COUNT * PARTICLE_COUNT * PARTICLE_STRIDE,
D3D11_USAGE_DEFAULT,
D3D11_BIND_UNORDERED_ACCESS | D3D11_BIND_SHADER_RESOURCE,
0,
D3D11_RESOURCE_MISC_BUFFER_STRUCTURED,
PARTICLE_STRIDE
};
#pragma data_seg(".particleBufferDesc")
static D3D11_SHADER_RESOURCE_VIEW_DESC particleSrvDesc =
{
DXGI_FORMAT_UNKNOWN,
D3D11_SRV_DIMENSION_BUFFER,
{
0,
PARTICLE_COUNT * PARTICLE_COUNT
}
};
#pragma data_seg(".particleUavDesc")
static D3D11_UNORDERED_ACCESS_VIEW_DESC particleUavDesc =
{
DXGI_FORMAT_UNKNOWN,
D3D11_UAV_DIMENSION_BUFFER,
0,
PARTICLE_COUNT * PARTICLE_COUNT,
0
};
#pragma data_seg(".backBufferRtvDesc")
static D3D11_RENDER_TARGET_VIEW_DESC backBufferRtvDesc =
{
DXGI_FORMAT_R16G16B16A16_FLOAT,
D3D11_RTV_DIMENSION_TEXTURE2DMS,
{
0
}
};
#pragma data_seg(".swapChainViewport")
static D3D11_VIEWPORT swapChainViewport =
{
0,
0,
WIDTH,
HEIGHT,
0.0f,
1.0f,
};
#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,
}
};

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,356 @@
#include "data.h"
#include "shaders.h"
struct TEXTURE_2D_SRV_UAV_RTV {
ID3D11Texture2D* TEX;
ID3D11ShaderResourceView* SRV;
ID3D11UnorderedAccessView* UAV;
ID3D11RenderTargetView* RTV;
};
void setNullUAVSRV() {
ID3D11UnorderedAccessView* nullUAV[] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
ID3D11ShaderResourceView* nullSRV[] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
context->CSSetUnorderedAccessViews(0, 8, nullUAV, NULL);
context->CSSetShaderResources(0, 8, nullSRV);
}
void createSRVUAVRTV(TEXTURE_2D_SRV_UAV_RTV* tex, int width, int height) {
D3D11_TEXTURE2D_DESC texDesc = {
width, height, 0, 1, DXGI_FORMAT_R16G16B16A16_FLOAT,
{1, 0}, D3D11_USAGE_DEFAULT,
D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_UNORDERED_ACCESS,
0, D3D11_RESOURCE_MISC_GENERATE_MIPS
};
device->CreateTexture2D(&texDesc, NULL, &tex->TEX);
device->CreateShaderResourceView(tex->TEX, NULL, &tex->SRV);
device->CreateUnorderedAccessView(tex->TEX, NULL, &tex->UAV);
device->CreateRenderTargetView(tex->TEX, NULL, &tex->RTV);
}
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->CreateUnorderedAccessView(backBufferTexture, NULL, &backBufferUAV);
device->CreateBuffer(&constantBufferDesc, NULL, &constantBuffer);
device->CreateBuffer(&particleBufferDesc, NULL, &particleBuffer);
device->CreateUnorderedAccessView(particleBuffer, &particleUavDesc, &particleBufferUAV);
device->CreateShaderResourceView(particleBuffer, &particleSrvDesc, &particleBufferSRV);
device->CreateRenderTargetView(backBufferTexture, &backBufferRtvDesc, &backBufferRtv);
device->CreateBlendState(&alphaBlendDesc, &alphaBlendState);
device->CreateRasterizerState(&rasterizerDesc, &rasterizerState);
#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
//---
// Postprocessing setup
//---
D3D11_SAMPLER_DESC samplerDesc = {
D3D11_FILTER_MIN_MAG_MIP_LINEAR, //D3D11_FILTER_MIN_MAG_MIP_LINEAR, D3D11_FILTER_ANISOTROPIC, D3D11_FILTER_MIN_MAG_MIP_POINT
D3D11_TEXTURE_ADDRESS_CLAMP,
D3D11_TEXTURE_ADDRESS_CLAMP,
D3D11_TEXTURE_ADDRESS_CLAMP,
0.0f,
1,
D3D11_COMPARISON_ALWAYS,
{0,0,0,0},
0,
D3D11_FLOAT32_MAX
};
ID3D11SamplerState* sampler;
device->CreateSamplerState(&samplerDesc, &sampler);
context->CSSetSamplers(0, 1, &sampler);
TEXTURE_2D_SRV_UAV_RTV tex0;
createSRVUAVRTV(&tex0, WIDTH, HEIGHT);
TEXTURE_2D_SRV_UAV_RTV pingPongTex1;
createSRVUAVRTV(&pingPongTex1, WIDTH, HEIGHT);
TEXTURE_2D_SRV_UAV_RTV ghostsTex4;
createSRVUAVRTV(&ghostsTex4, WIDTH/4, HEIGHT/4);
TEXTURE_2D_SRV_UAV_RTV streaksTex4;
createSRVUAVRTV(&streaksTex4, WIDTH/4, HEIGHT/4);
TEXTURE_2D_SRV_UAV_RTV lensDirt2;
createSRVUAVRTV(&lensDirt2, WIDTH/2, HEIGHT/2);
TEXTURE_2D_SRV_UAV_RTV tmpTex1;
TEXTURE_2D_SRV_UAV_RTV blurTex1;
createSRVUAVRTV(&tmpTex1, WIDTH, HEIGHT);
createSRVUAVRTV(&blurTex1, WIDTH, HEIGHT);
TEXTURE_2D_SRV_UAV_RTV tmpTex8;
TEXTURE_2D_SRV_UAV_RTV blurTex8;
createSRVUAVRTV(&tmpTex8, WIDTH/8, HEIGHT/8);
createSRVUAVRTV(&blurTex8, WIDTH/8, HEIGHT/8);
TEXTURE_2D_SRV_UAV_RTV tmpTex32;
TEXTURE_2D_SRV_UAV_RTV blurTex32;
createSRVUAVRTV(&tmpTex32, WIDTH/32, HEIGHT/32);
createSRVUAVRTV(&blurTex32, WIDTH/32, HEIGHT/32);
ID3D11UnorderedAccessView* uavs[] = { particleBufferUAV };
ID3D11ShaderResourceView* srvs[] = { particleBufferSRV };
context->RSSetState(rasterizerState);
context->CSSetUnorderedAccessViews(0, 1, uavs, NULL);
context->CSSetConstantBuffers(0, 1, &constantBuffer);
context->CSSetShader(initShader, NULL, 0);
context->Dispatch(PARTICLE_COUNT / 16, PARTICLE_COUNT / 16, 1);
context->VSSetConstantBuffers(0, 1, &constantBuffer);
context->PSSetConstantBuffers(0, 1, &constantBuffer);
context->OMSetBlendState(alphaBlendState, NULL, 0xffffffff);
context->RSSetViewports(1, &swapChainViewport);
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);
// For postprocessing
context->ClearRenderTargetView(tex0.RTV, zero);
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);
startTime = time;
demoTime += deltaTime;
constantBufferVertexData->demoTime = demoTime;
constantBufferVertexData->deltaTime = deltaTime;
constantBufferVertexData->dummy1 = 1.0f;
constantBufferVertexData->dummy2 = 1.0f;
context->Unmap(constantBuffer, 0);
//context->OMSetRenderTargets(1, &backBufferRtv, NULL;
// For postprocessing
context->OMSetRenderTargets(1, &tex0.RTV, NULL);
// particle update
if (true)
{
context->CSSetUnorderedAccessViews(0, 1, uavs, NULL);
context->CSSetShader(updateShader, NULL, 0);
context->Dispatch(PARTICLE_COUNT / 16, PARTICLE_COUNT / 16, 1);
context->CSSetUnorderedAccessViews(0, 1, (ID3D11UnorderedAccessView* const *)zero, NULL);
}
// raymarching draw
context->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
context->VSSetShader(raymarchingVertexShader, NULL, 0);
context->GSSetShader(NULL, NULL, 0);
context->PSSetShader(raymarchingPixelShader, NULL, 0);
context->Draw(4, 0);
// particle draw
if (true)
{
context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
context->VSSetShader(particleVertexShader, NULL, 0);
context->GSSetShader(particleGeometryShader, NULL, 0);
context->PSSetShader(particlePixelShader, NULL, 0);
context->VSSetShaderResources(0, 1, srvs);
context->Draw(PARTICLE_COUNT * PARTICLE_COUNT, 0);
context->VSSetShaderResources(0, 1, (ID3D11ShaderResourceView* const*)zero);
}
ID3D11RenderTargetView* nullRTV[] = {NULL};
context->OMSetRenderTargets(1, nullRTV, NULL);
// tex0 is the input texture
context->GenerateMips(tex0.SRV);
setNullUAVSRV();
// Distort Chroma
context->CSSetUnorderedAccessViews(0, 1, &tmpTex1.UAV, NULL);
context->CSSetShaderResources(0, 1, &tex0.SRV);
context->CSSetShader(csDistortChroma, NULL, 0);
context->Dispatch(80, 45, 1);
setNullUAVSRV();
context->GenerateMips(tmpTex1.SRV);
// Radial Blur
context->CSSetUnorderedAccessViews(0, 1, &pingPongTex1.UAV, NULL);
context->CSSetShaderResources(0, 1, &tmpTex1.SRV);
context->CSSetShader(csRadialBlur, NULL, 0);
context->Dispatch(80, 45, 1);
setNullUAVSRV();
context->GenerateMips(pingPongTex1.SRV);
// Circumferential Blur -> (MipMap) -> Streaks
context->CSSetUnorderedAccessViews(0, 1, &tex0.UAV, NULL);
context->CSSetShaderResources(0, 1, &pingPongTex1.SRV);
context->CSSetShader(csCircumferentialBlur, NULL, 0);
context->Dispatch(80, 45, 1);
setNullUAVSRV();
context->GenerateMips(tex0.SRV);
// Streaks
context->CSSetUnorderedAccessViews(0, 1, &streaksTex4.UAV, NULL);
context->CSSetShaderResources(0, 1, &tex0.SRV);
context->CSSetShader(csStreaks, NULL, 0);
context->Dispatch(20, 12, 1);
// Lens dirt
context->CSSetUnorderedAccessViews(0, 1, &lensDirt2.UAV, NULL);
context->CSSetShader(csLensDirt, NULL, 0);
context->Dispatch(40, 23, 1);
// BlurV (1/1)
context->CSSetUnorderedAccessViews(0, 1, &tmpTex1.UAV, NULL);
context->CSSetShaderResources(0, 1, &tex0.SRV);
context->CSSetShader(csBlurV, NULL, 0);
context->Dispatch(80, 45, 1);
// BlurH (1/1) -> blurTex1
context->CSSetUnorderedAccessViews(0, 1, &blurTex1.UAV, NULL);
context->CSSetShaderResources(0, 1, &tmpTex1.SRV);
context->CSSetShader(csBlurH, NULL, 0);
context->Dispatch(80, 45, 1);
context->GenerateMips(blurTex1.SRV);
// BlurV (1/8)
context->CSSetUnorderedAccessViews(0, 1, &tmpTex8.UAV, NULL);
context->CSSetShaderResources(0, 1, &blurTex1.SRV);
context->CSSetShader(csBlurV, NULL, 0);
context->Dispatch(10, 6, 1);
// BlurH (1/8) -> blurTex8 -> merge / ghosts
context->CSSetUnorderedAccessViews(0, 1, &blurTex8.UAV, NULL);
context->CSSetShaderResources(0, 1, &tmpTex8.SRV);
context->CSSetShader(csBlurH, NULL, 0);
context->Dispatch(10, 6, 1);
context->GenerateMips(blurTex8.SRV);
// BlurV (1/32)
context->CSSetUnorderedAccessViews(0, 1, &tmpTex32.UAV, NULL);
context->CSSetShaderResources(0, 1, &blurTex8.SRV);
context->CSSetShader(csBlurV, NULL, 0);
context->Dispatch(3, 2, 1);
// BlurH (1/32) -> blurTex32 -> merge / lensDirt / smallDirt / ghosts
context->CSSetUnorderedAccessViews(0, 1, &blurTex32.UAV, NULL);
context->CSSetShaderResources(0, 1, &tmpTex32.SRV);
context->CSSetShader(csBlurV, NULL, 0);
context->Dispatch(3, 2, 1);
context->GenerateMips(tex0.SRV);
// Ghosts
ID3D11ShaderResourceView* ghostsSRV[] = {blurTex1.SRV, blurTex8.SRV};
context->CSSetUnorderedAccessViews(0, 1, &ghostsTex4.UAV, NULL);
context->CSSetShaderResources(0, 2, ghostsSRV);
context->CSSetShader(csGhosts, NULL, 0);
context->Dispatch(20, 12, 1);
setNullUAVSRV();
// Merge
ID3D11ShaderResourceView* mergeSRV[] = {tex0.SRV, blurTex1.SRV, blurTex8.SRV, blurTex32.SRV, streaksTex4.SRV, lensDirt2.SRV, ghostsTex4.SRV, NULL};
context->CSSetUnorderedAccessViews(0, 1, &backBufferUAV, NULL);
context->CSSetShaderResources(0, 8, mergeSRV);
context->CSSetShader(csMerge, NULL, 0);
context->Dispatch(80, 45, 1);
setNullUAVSRV();
swapChain->Present(1, 0);
#ifdef _DEBUG
#ifndef SHADERDEBUG
if (::WaitForSingleObject(shaderCompileEvent, 0) == WAIT_OBJECT_0)
{
::Sleep(50);
CreateShaders();
context->CSSetUnorderedAccessViews(0, 1, uavs, NULL);
context->CSSetShader(initShader, NULL, 0);
context->Dispatch(64, 64, 1);
::Sleep(50);
QueryPerformanceCounter(&time);
startTime = time;
}
#endif
#endif
} while (!GetAsyncKeyState(VK_ESCAPE));
return EXIT_SUCCESS;
}

View 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

Binary file not shown.

View 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>

View 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/sdfparticles/pgs.cso Normal file

Binary file not shown.

BIN
hgplus/sdfparticles/pgs.pdb Normal file

Binary file not shown.

BIN
hgplus/sdfparticles/pps.cso Normal file

Binary file not shown.

BIN
hgplus/sdfparticles/pps.pdb Normal file

Binary file not shown.

BIN
hgplus/sdfparticles/pvs.cso Normal file

Binary file not shown.

BIN
hgplus/sdfparticles/pvs.pdb Normal file

Binary file not shown.

BIN
hgplus/sdfparticles/rps.cso Normal file

Binary file not shown.

BIN
hgplus/sdfparticles/rps.pdb Normal file

Binary file not shown.

BIN
hgplus/sdfparticles/rvs.cso Normal file

Binary file not shown.

BIN
hgplus/sdfparticles/rvs.pdb Normal file

Binary file not shown.

View File

@@ -0,0 +1,8 @@
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
fxc /Zi /E"rvs" /Od /Fo"rvs.cso" /Fd"rvs.pdb" /T vs_5_0 /nologo test.hlsl
fxc /Zi /E"rps" /Od /Fo"rps.cso" /Fd"rps.pdb" /T ps_5_0 /nologo test.hlsl

View File

@@ -0,0 +1,225 @@
#ifdef _DEBUG
#include <process.h>
#include <io.h>
#include <stdio.h>
HANDLE shaderCompileEvent;
static char** lastShader;
static __time64_t shaderChangedDate;
#define shaderDir ""
#define shaderFile "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);
CompileShader("pps", ps_5_0);
device->CreatePixelShader(shaderCode, shaderSize, 0, &particlePixelShader);
CompileShader("rvs", vs_5_0);
device->CreateVertexShader(shaderCode, shaderSize, 0, &raymarchingVertexShader);
CompileShader("rps", ps_5_0);
device->CreatePixelShader(shaderCode, shaderSize, 0, &raymarchingPixelShader);
//---
// Compile postprocessing shaders
//---
CompileShader("csDistortChroma", cs_5_0);
device->CreateComputeShader(shaderCode, shaderSize, 0, &csDistortChroma);
CompileShader("csRadialBlur", cs_5_0);
device->CreateComputeShader(shaderCode, shaderSize, 0, &csRadialBlur);
CompileShader("csCircumferentialBlur", cs_5_0);
device->CreateComputeShader(shaderCode, shaderSize, 0, &csCircumferentialBlur);
CompileShader("csStreaks", cs_5_0);
device->CreateComputeShader(shaderCode, shaderSize, 0, &csStreaks);
CompileShader("csLensDirt", cs_5_0);
device->CreateComputeShader(shaderCode, shaderSize, 0, &csLensDirt);
CompileShader("csBlurH", cs_5_0);
device->CreateComputeShader(shaderCode, shaderSize, 0, &csBlurH);
CompileShader("csBlurV", cs_5_0);
device->CreateComputeShader(shaderCode, shaderSize, 0, &csBlurV);
CompileShader("csGhosts", cs_5_0);
device->CreateComputeShader(shaderCode, shaderSize, 0, &csGhosts);
CompileShader("csMerge", cs_5_0);
device->CreateComputeShader(shaderCode, shaderSize, 0, &csMerge);
}

View File

@@ -0,0 +1,783 @@
struct ParticleState
{
float3 oldPosition;
float3 currentPosition;
float3 velocity;
float3 tangent;
float opacity;
float size;
};//56 bytes
#define PI 3.14159265
#define SDF_SIMILARITY 64.0 // try 0.2 for fractal flames, you can also go up to 64
#define TANGENT_SPEED 8.0 // increase to add more chaos
#define GRADIENT_SPEED 64.0
#define SDF_SPEED 1.0
float rand(float x, inout float seed)
{
seed = frac(sin(dot(float2(x, seed), float2(12.9898, 78.233))) * 43758.5453);
return seed;
}
cbuffer _0 : register(b0)
{
float demoTime;
float deltaTime;
float dummy1;
float dummy2;
};
RWStructuredBuffer<ParticleState> particles:register(u0);
StructuredBuffer<ParticleState> drawParticles:register(t0);
void initParticle(int idx)
{
float seed = idx;
particles[idx].currentPosition =
particles[idx].oldPosition = rand(idx, seed) * 12 * float3(rand(idx, seed) * 2 - 1, rand(idx, seed) * 2 - 1, rand(idx, seed) * 2 - 1) + float3(0, -24, -24);
particles[idx].tangent = rand(idx, seed) * normalize(float3(rand(idx, seed) * 2 - 1, rand(idx, seed) * 2 - 1, rand(idx, seed) * 2 - 1));
particles[idx].velocity = rand(idx, seed) * normalize(float3(rand(idx, seed) * 2 - 1, rand(idx, seed) * 2 - 1, rand(idx, seed) * 2 - 1));
particles[idx].size = 2 * rand(idx, seed);
particles[idx].opacity = 1.0;
}
[numthreads(16, 16, 1)]
void init(int3 id:SV_DispatchThreadID)
{
int idx = 1024 * id.y + id.x;
initParticle(idx);
}
float3 fusion(float x) {
float t = saturate(x);
return saturate(float3(sqrt(t), t*t*t, max(sin(3.1415*1.75*t), pow(t, 12.0))));
}
float3 project(float3 v)
{
return float3(v.x / 1.6, 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; }
float sdSphere(float3 p, float s)
{
return length(p) - s;
}
float sdTorus(float3 p, float2 t)
{
float2 q = float2(length(p.xz) - t.x, p.y);
return length(q) - t.y;
}
float sdCapsule(float3 p, float3 a, float3 b, float r)
{
float3 pa = p - a, ba = b - a;
float h = clamp(dot(pa, ba) / dot(ba, ba), 0.0, 1.0);
return length(pa - ba*h) - r;
}
float lengthN(float2 v, float n)
{
v = pow(v, n);
return pow(v.x + v.y, 1.0 / n);
}
float sdTorus82(float3 p, float2 t)
{
float2 q = float2(lengthN(p.xz, 2) - t.x, p.y);
return lengthN(q, 8) - t.y;
}
float opRep(float3 p, float3 c)
{
float3 q = sign(p) * fmod(p, c) - 0.5*c;
return sdTorus82(q, float2(1.0, 0.5));
}
void rX(inout float3 p, float a)
{
float c, s; float3 q = p;
c = cos(a); s = sin(a);
p.y = c * q.y - s * q.z;
p.z = s * q.y + c * q.z;
}
float sdBox(float3 p, float3 b)
{
float3 d = abs(p) - b;
return min(max(d.x, max(d.y, d.z)), 0.0) + length(max(d, 0.0));
}
float f1(float3 p)
{
p.z += 24.0;
p.x += sin(demoTime * SDF_SPEED * 0.5) * 4;
p.y += cos(demoTime * SDF_SPEED * 1.5) * 2;
float d = opRep(p, float3(5.0, 5.0, 5.0));
d = max(d, sdBox(p, float3(9.0, 8.0, 9.0)));
return d;
}
float menger(float3 p)
{
float d = sdBox(p, float3(1.0, 1.0, 1.0));
float s = 1.0;
for (int m = 0; m<8; m++)
{
float3 a = sign(p) * fmod(p*s, 2.0) - 1.0;
s *= 3.0;
float3 r = abs(1.0 - 3.0*abs(a));
float da = max(r.x, r.y);
float db = max(r.y, r.z);
float dc = max(r.z, r.x);
float c = (min(da, min(db, dc)) - 1.0) / s;
d = max(d, c);
}
return d;
}
static const float fd = 0.763;
static const float fu = 10.0;
static const float fs = 1.0;
static const float3 fc = float3(0, 0, 0);
static const float ff = -0.50000;
static const float3 cs = float3(0.80800, 0.80800, 1.16700);
float dE(float3 p)
{
float dEfactor = 1.;
//int fractal_iterations = 12;
for (int i = 0; i<12; i++) {
//box folding
p = 2.*clamp(p, -cs, cs) - p;
//inversion
float k = max(fs / dot(p, p), 1.);
p *= k;
dEfactor *= k;
//julia seed
p += fc;
}
//call basic shape and scale its DE
//need to adjust fractal_distancemult with non zero julia seed
float rxy = length(p.xy) - fu;
//distance from pos to the pseudo kleinian basic shape ...
return (fd*max(rxy, abs(length(p.xy)*p.z) / sqrt(dot(p, p))) / abs(dEfactor));
}
float f(float3 p)
{
p.z += 4.0;
p.x += sin(demoTime * SDF_SPEED * 0.5) * 4;
p.y += cos(demoTime * SDF_SPEED * 1.5) * 0.5;
return dE(p);
}
[numthreads(16, 16, 1)]
void update(int3 id:SV_DispatchThreadID)
{
int idx = 1024 * id.y + id.x;
float3 p = particles[idx].currentPosition;
float2 e = float2(1, 0) * 0.001;
float d = f(p);
if (d > 90 || p.y > 30)
{
initParticle(idx);
}
float3 v = -normalize(float3(f(p + e.xyy) - f(p - e.xyy), f(p + e.yxy) - f(p - e.yxy), f(p + e.yyx) - f(p - e.yyx)));
v = lerp(particles[idx].velocity, v, saturate(deltaTime * SDF_SIMILARITY));
v = lerp(float3(0, 1, 0), v, 0.99);
float3 t = cross(particles[idx].tangent, v);
particles[idx].oldPosition = particles[idx].currentPosition;
particles[idx].currentPosition += (TANGENT_SPEED * t / (1 + pow(abs(d), 0.5)) + GRADIENT_SPEED * v * d * (0.5 + 0.5 * step(0, -d))) * deltaTime;
particles[idx].velocity = v;
particles[idx].opacity = d;
}
struct _2
{
float3 pos1 : TEXCOORD0;
float3 pos2 : TEXCOORD1;
float3 dir : TEXCOORD2;
float opacity : OPACITY;
float size : SIZE;
};
struct _3
{
float4 pos : SV_POSITION;
float opacity : OPACITY;
float hue : HUE;
};
void pvs(uint id : SV_VertexID, out _2 o)
{
ParticleState particle = drawParticles[id];
o.pos1 = particle.oldPosition;
o.pos2 = particle.currentPosition;
o.dir = particle.velocity;
o.opacity = particle.opacity;
o.size = particle.size;
}
float particleSize(float z)
{
return 0.01f / -z;
}
[maxvertexcount(18)]
void pgs(point _2 input[1], inout TriangleStream<_3> o)
{
_2 p = input[0];
float s1 = particleSize(p.pos1.z) * p.size;
float s2 = particleSize(p.pos2.z) * p.size;
float3 p1 = project(p.pos1);
float3 p2 = project(p.pos2);
float2 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;
float l = distance(p1.xy, p2.xy);
if (l > 0.1)
return;
r.opacity = l * p.opacity;
r.hue = p.opacity;
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 / (max(0, i.opacity) + 64);
float3 color = 100*fusion(i.hue*50);//h2r(abs(i.hue) / 8 + demoTime * 0.1, 0.6, 1.0);
return float4(color, intensity);
}
float3 intersect(float3 ro, float3 rd)
{
float maxd = 70.0;
float precis = 0.001;
float h = precis*2.0;
float t = 0.0;
float d = 0.0;
float j = 0.0;
for (int i = 0; i < 90; i++)
{
if (abs(h)<precis || t>maxd) continue;//break;
t += h;
float res = f(ro + rd*t);
h = res/*.x*/;
j = i;
//d = res.y;
}
float m = (t>maxd) ? -1.0 : 1.0;
return float3(t, m, j / 90.0f);
}
void rvs(uint id : SV_VertexID, out float2 q : QUAD, out float4 svPos : SV_POSITION)
{
if (id == 0)
svPos = float4(-1.0, -1.0, 0.0, 1.0);
else if (id == 1)
svPos = float4(-1.0, 1.0, 0.0, 1.0);
else if (id == 2)
svPos = float4(1.0, -1.0, 0.0, 1.0);
else
svPos = float4(1.0, 1.0, 0.0, 1.0);
q = svPos.xy;
}
float4 rps(float2 p : QUAD) : SV_Target
{
float an = sin(-0.25 + 0.31416*demoTime);
float3 ro = float3(0, 0, 0);
float3 rd = normalize(float3(p.x * 1.6, p.y, -1.0));
// raymarch
float3 rm = intersect(ro, rd);
if (rm.y > 0)
{
return float4(rm.z, rm.z, rm.z, 0.2);
}
return float4(0, 0, 0, 1);
}
//---
// Postprocessing computer shaders
//---
RWTexture2D<float4> out0:register(u0);
SamplerState sampler0 : register(s0);
Texture2D tex0: register(t0);
Texture2D tex1: register(t1);
Texture2D tex2: register(t2);
Texture2D tex3: register(t3);
Texture2D tex4: register(t4);
Texture2D tex5: register(t5);
Texture2D tex6: register(t6);
Texture2D tex7: register(t7);
static uint rndSeed = 0;
void setRndSeed(uint seed) {
rndSeed = seed;
}
uint hash(uint x) {
x += x << 10, x ^= x >> 6, x += x << 3, x ^= x >> 11, x += x << 15;
return x;
}
float rnd() {
return asfloat((rndSeed = hash(rndSeed) & 0x007fffff) | 0x3f800000) - 1;
}
float srnd() {
return asfloat((rndSeed = hash(rndSeed) & 0x007fffff) | 0x40000000) - 3;
}
float rnd(uint s) {
return asfloat((s & 0x007fffff) | 0x3f800000) - 1;
}
float srnd(uint s) {
return asfloat((s & 0x007fffff) | 0x40000000) - 3;
}
float mod(float x, float y) {
return x - y * floor(x / y);
}
float2 mod(float2 x, float2 y) {
return x - y * floor(x / y);
}
float3 mod(float3 x, float3 y) {
return x - y * floor(x / y);
}
float2 mod(float2 x, float y) {
return x - y * floor(x / y);
}
float3 mod(float3 x, float y) {
return x - y * floor(x / y);
}
float pulse(float center, float width, float x) {
float t = abs(x - center);
if (t > width) return 0;
t /= width;
return 1 - t*t*(3 - 2 * t);
}
//---
// Radial and circumferential blur
//---
static const float rcfMipmapFactor = 1.5;
static const float rcfStepFactor = 5;
static const float rcfStrengthRadial = 50;
static const float rcfStrengthCircumferential = 50;
static const float rcfRadius = 15;
static const float2 rcfCenter = {0.5, 0.5};
float rcfRadialFalloff(float radius, float amount) {
return radius * (1 + amount*radius*0.01);
}
float4 rcfBlur(float2 tc, float2 resolution, float strength, float circumFerentialStrength) {
// Direction from rcfCenter to the current tc, aspect ratio corrected
float2 d = (tc - rcfCenter) * float2(resolution.x/resolution.y, 1);
// Compute convolution step size
float delta = length(d);
float distortedDelta = rcfRadialFalloff(delta, strength);
float stepSize = abs(delta - distortedDelta) * rcfStepFactor;
float radius = rcfRadius;
// Circumferential blur
if (circumFerentialStrength > 0) {
d = float2(d.y, -d.x);
stepSize *= circumFerentialStrength;
radius = floor(rcfRadius * circumFerentialStrength);
}
// Early exit
if (radius <= 0.5) {// || stepSize <= 1/resolution.x) {
return tex0.SampleLevel(sampler0, tc, 0);
}
// Adjust direction
d = normalize(d) * stepSize / resolution;
// Convolution
float mipLevel = sqrt(stepSize) * rcfMipmapFactor;
float sigma = radius/2;
float twoSigmaSquared = 2 * sigma * sigma;
float4 a = 0;
for (float i = -radius; i <= radius; ++i) {
float weight = exp(-i*i/twoSigmaSquared);
a += tex0.SampleLevel(sampler0, i * d + tc, mipLevel) * weight;
}
return a / sqrt(twoSigmaSquared * PI);
}
[numthreads(16, 16, 1)] void csRadialBlur(int3 id:SV_DispatchThreadID) {
float2 resolution;
out0.GetDimensions(resolution.x, resolution.y);
float2 tc = (id.xy + 0.5) / resolution;
out0[id.xy] = rcfBlur(tc, resolution, rcfStrengthRadial, 0);
}
[numthreads(16, 16, 1)] void csCircumferentialBlur(int3 id:SV_DispatchThreadID) {
float2 resolution;
out0.GetDimensions(resolution.x, resolution.y);
float2 tc = (id.xy + 0.5) / resolution;
out0[id.xy] = rcfBlur(tc, resolution, rcfStrengthCircumferential, 1);
}
//---
// Sensor dirt
//---
[numthreads(16, 16, 1)] void csSensorDirt(int3 id:SV_DispatchThreadID) {
float2 tc = id.xy + .5;
}
//---
// Lens dirt
//---
static const float ldMinRadius = 0.025;
static const float ldMaxRadius = 0.075;
static const float ldCellWidth = 3*ldMaxRadius;
static const float ldBorderWidthHalf = 0.00125;
static const float ldSeed = 3;
static const float ldNumLayers = 4;
[numthreads(16, 16, 1)] void csLensDirt(int3 id:SV_DispatchThreadID) {
float2 resolution;
out0.GetDimensions(resolution.x, resolution.y);
float2 tc = (id.xy + 0.5) / resolution;
tc *= float2(resolution.x/resolution.y, 1);
//float2 tc = id.xy + .5;
rndSeed = ldSeed;
float4 a = 0;
for (int i = 0; i < ldNumLayers; ++i) {
// Modulo repeat, find cell
float2 p = mod(tc, ldCellWidth) - ldCellWidth / 2;
float2 c = floor(tc / ldCellWidth);
// Backup seed
uint seedBackup = rndSeed;
// Modifiy seed with cell coordinates
rndSeed += (c.x + c.y*ldCellWidth + i*ldCellWidth*ldCellWidth) * resolution.x;
// Determine radius and jitter
float r = lerp(ldMinRadius, ldMaxRadius, rnd());
p += float2(srnd(), srnd()) * (ldCellWidth / 2 - r);
// Shapes
// Hexagon
//p = abs(p);
//float d = max(p.y + p.x*0.57735, p.x*1.1547);
// Circle
//float d = length(p);
// Pentagon
//float phi = 0.145;
//float2 n[] = {
// { sin(0*PI/5 + phi), cos(0*PI/5 + phi) },
// { sin(2*PI/5 + phi), cos(2*PI/5 + phi) },
// { sin(4*PI/5 + phi), cos(4*PI/5 + phi) },
// { sin(6*PI/5 + phi), cos(6*PI/5 + phi) },
// { sin(8*PI/5 + phi), cos(8*PI/5 + phi) }
//};
//// Difference between circumcircle and incircle radii
//float delta = r - (1 + sqrt(5)) / 4 * r;
//float d = max(max(max(max(dot(p, n[0]), dot(p, n[1])), dot(p, n[2])), dot(p, n[3])), dot(p, n[4]));
//// Mix between sphere and pentagon
//d = lerp(length(p), d+ delta, 0.5);
float d = length(p);
// Random color
a += (float4(rnd(), rnd(), rnd(), 1) + 0.5) * (smoothstep(r, r - ldBorderWidthHalf * 2, d) + 0.25 * smoothstep(ldBorderWidthHalf, 0, abs(d - r + ldBorderWidthHalf * 2)));
//a += float4(c, 0, 1)*0.1;
// Restore seed
rndSeed = seedBackup;
// Displace grid
tc += ldCellWidth / ldNumLayers;
}
//out0[id.xy] = float4(a.xyz / ldNumLayers, 1);
out0[id.xy] = float4(a.xyz / ldNumLayers, 1);
}
//---
// Blur
//---
static const float bRadius = 160;
static const float bSigma = bRadius / 3.5;
static const float bTwoSigmaSquared = 2 * bSigma * bSigma;
void bBlur(int3 id, float2 direction) {
float2 resolution;
out0.GetDimensions(resolution.x, resolution.y);
float2 sourceResolution;
tex0.GetDimensions(sourceResolution.x, sourceResolution.y);
float mipLevel = log2(sourceResolution.x / resolution.x);
float2 tc = (id.xy + 0.5) / resolution;
float2 d = direction / resolution;
float4 a = 0;
for (float i = -bRadius; i <= bRadius; ++i) {
float weight = exp(-i*i/bTwoSigmaSquared);
a += tex0.SampleLevel(sampler0, i * d + tc, mipLevel) * weight;
}
out0[id.xy] = a / sqrt(bTwoSigmaSquared * PI);
}
[numthreads(16, 16, 1)] void csBlurH(int3 id:SV_DispatchThreadID) { bBlur(id, float2(1,0)); }
[numthreads(16, 16, 1)] void csBlurV(int3 id:SV_DispatchThreadID) { bBlur(id, float2(0,1)); }
//---
// Streaks
//---
static const float stRadius = 160;
[numthreads(16, 16, 1)] void csStreaks(int3 id:SV_DispatchThreadID) {
float2 resolution;
out0.GetDimensions(resolution.x, resolution.y);
float2 sourceResolution;
tex0.GetDimensions(sourceResolution.x, sourceResolution.y);
float mipLevel = log2(sourceResolution.x / resolution.x);
float2 tc = (id.xy + 0.5) / resolution;
float2 d = float2(1, 0) / resolution;
// Convolution with parabolic tent filter
float4 a = 0;
for (float i = -stRadius+1; i < stRadius; ++i) {
float weight = (stRadius - abs(i)) * (stRadius - abs(i));
a += tex0.SampleLevel(sampler0, i * d + tc, mipLevel) * weight;
}
out0[id.xy] = a * 1.5 / (stRadius * stRadius * stRadius);
}
//---
// Distort Chroma
//---
static const float dcStrength = 10.0;
static const float2 dcCenter = {0.5, 0.5};
static const int dcSamples = 12;
float dcRadialFalloff(float radius, float amount) {
return radius * (1 + amount*radius*0.01);
}
float4 dcSample(float2 tc, float amount, float2 resolution) {
// Direction from cdCenter to the current tc, aspect ratio corrected
float2 d = (tc - dcCenter) * float2(resolution.x/resolution.y, 1);
float radius = length(d);
d /= radius == 0 ? d : radius;
return tex0.SampleLevel(sampler0, dcCenter + d * dcRadialFalloff(radius, amount) / float2(resolution.x/resolution.y, 1), 0);
}
[numthreads(16, 16, 1)] void csDistortChroma(int3 id:SV_DispatchThreadID) {
float2 resolution;
out0.GetDimensions(resolution.x, resolution.y);
float2 tc = (id.xy + 0.5) / resolution;
float4 original = tex0.SampleLevel(sampler0, tc, 0);
if (dcStrength == 0) {
out0[id.xy] = original;
return;
}
// Accumulate along spectrum
float4 a = 0;
for (int i = 1; i <= dcSamples; ++i) {
float lambda = 0.4f * (i/float(dcSamples+1)) + 0.35f;
float4 w = float4(pulse(0.65, 0.1, lambda), pulse(0.55, 0.1, lambda), pulse(0.45, 0.1, lambda), 0.25) * 4.0;
a += w * dcSample(tc, -(i-1)/float(dcSamples) * dcStrength , resolution);
}
a /= dcSamples;
out0[id.xy] = lerp(original, a, saturate(dcStrength));
}
//---
// Ghosts
//---
float4 ghRainbow(float angle) {
return float4(sin(angle), sin(angle + 3.1415*2.0/3.0), sin(angle + 3.1415*4.0/3.0), 1) * 0.5 + 0.5;
}
[numthreads(16, 16, 1)] void csGhosts(int3 id:SV_DispatchThreadID) {
float2 resolution;
out0.GetDimensions(resolution.x, resolution.y);
float2 tc = (id.xy + 0.5) / resolution;
tc = 1 - tc;
float2 texelSize = 1 / resolution;
float2 aspectCorrection = float2(resolution.x/resolution.y, 1);
float2 direction = (0.5 - tc) * 2;
float4 a = 0;
for (int i = 0; i < 5; ++i) {
float2 sc0 = 1 - frac(tc + direction * i * 0.2);
float2 sc1 = 1 - frac(tc + direction * i * 0.1999);
float r = length((sc0 - 0.5) * aspectCorrection);
a += max(0, tex0.SampleLevel(sampler0, sc0, 0) - 0.125) * lerp(1, ghRainbow(r*20), 1.5*r);
a += max(0, tex1.SampleLevel(sampler0, sc0, 0) - 0.125) * lerp(1, ghRainbow(r*15+i), 1.5*r);
}
out0[id.xy] = float4(a.xyz/5, 1);
}
//---
// Merge
//---
float3 saturation(float3 color, float saturation) {
return lerp(dot(color, float3(0.2126, 0.7152, 0.0722)), color, saturation);
}
float3 liftGammaGain(float3 color, float3 lift, float3 gamma, float3 gain) {
return pow(saturate(gain*color + lift*(-gain*color + 1)), 1/gamma);
}
float3 uncharted2ToneMapping(float3 c) {
float A = 0.15;
float B = 0.50;
float C = 0.10;
float D = 0.20;
float E = 0.02;
float F = 0.30;
float W = 11.2;
c = ((c * (A * c + C * B) + D * E) / (c * (A * c + B) + D * F)) - E / F;
float white = ((W * (A * W + C * B) + D * E) / (W * (A * W + B) + D * F)) - E / F;
return c / white;
}
[numthreads(16, 16, 1)] void csMerge(int3 id:SV_DispatchThreadID) {
float2 resolution;
out0.GetDimensions(resolution.x, resolution.y);
float2 tc = (id.xy + 0.5) / resolution;
rndSeed = (id.y * 720 + id.x);// * int(time * 1000);
float3 rndNoiseXYT = float3(rnd(), rnd(), rnd());
rndSeed = id.y;
float3 rndNoiseY = float3(rnd(), rnd(), rnd());
float3 base = tex0.SampleLevel(sampler0, tc, 0).xyz;
float3 blur1 = tex1.SampleLevel(sampler0, tc, 0).xyz;
float3 blur8 = tex2.SampleLevel(sampler0, tc, 0).xyz;
float3 blur32 = tex3.SampleLevel(sampler0, tc, 0).xyz;
float3 streaks = tex4.SampleLevel(sampler0, tc, 0).xyz;
float3 lensDirt = tex5.SampleLevel(sampler0, tc, 0).xyz;
float3 ghosts = tex6.SampleLevel(sampler0, tc, 0).xyz;
float3 color = base.xyz;
color += blur1*0.125;
color += blur8*0.125;
color += blur32*0.125;
// Streaks
color += streaks * (lerp(1, rndNoiseY.x, 0.25)) * 0.25;// * rnd();
// Lens dirt
//color += lensDirt * 0.25 * max(0, dot(tex2.SampleLevel(sampler0, frac(1-tc), 0).xyz, float3(0.299, 0.587, 0.114)) - 1.0);
// Ghosts
color += ghosts * 0.125;// * ghosts * 0.25;
// Grain
color *= lerp(1, rndNoiseXYT, 0.35);
//color = base;
// Tonemapping
color = max(0, uncharted2ToneMapping(max(0, color*0.5)));
//color *= color;
color = liftGammaGain(color, float3(0, 0, 0), float3(1, 1, 1), float3(1, 1, 1));
//color = saturation(color, 1.5);
//color = pow(color, 1/2.2);
float4 result = float4(color, dot(color, float3(0.299, 0.587, 0.114)));
out0[id.xy] = result;
}

Binary file not shown.

Binary file not shown.