-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from henrikvik/development
Sprint 2
- Loading branch information
Showing
65 changed files
with
1,333 additions
and
278 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,18 @@ | ||
|
||
static const float gaussianFilter[5] = { | ||
0.06136, 0.24477, 0.38774, 0.24477, 0.06136 | ||
}; | ||
#include "ShaderConstants.h" | ||
|
||
|
||
Texture2D inputTexture : register(t0); | ||
RWTexture2D<float4> output; | ||
RWTexture2D<unorm float4> output : register(u0); | ||
|
||
[numthreads(16, 16, 1)] | ||
void main( uint3 DTid : SV_DispatchThreadID ) | ||
[numthreads(16, 9, 1)] | ||
void CS(uint3 DTid : SV_DispatchThreadID) | ||
{ | ||
int3 textureLocation = DTid * 2 - int3(KERNELSIZE -1, 0, 0); | ||
|
||
int3 textureLocation = DTid - int3(2, 0, 0); | ||
|
||
float4 final = { 0.0, 0.0, 0.0, 1.0 }; | ||
for (uint x = 0; x < 5; x++) | ||
final += inputTexture.Load(textureLocation + int3(x, 0, 0)) * gaussianFilter[x]; | ||
float4 final = { 0.0, 0.0, 0.0, 1.0 }; | ||
for (uint x = 0; x < KERNELSIZE; x++) | ||
final += inputTexture.Load(textureLocation + int3(x * 2, 0, 0)) * gaussianFilter[x]; | ||
|
||
|
||
output[DTid.xy] = final; | ||
output[DTid.xy] = final; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
Texture2D backBuffer : register(t0); | ||
Texture2D toMerge : register(t1); | ||
RWTexture2D<unorm float4> output : register(u0); | ||
sampler Sampler : register(s0); | ||
|
||
[numthreads(16, 9, 1)] | ||
void CS( uint3 DTid : SV_DispatchThreadID ) | ||
{ | ||
float2 uv; | ||
uv.x = DTid.x / 1280.f; | ||
uv.y = DTid.y / 720.f; | ||
|
||
|
||
float3 color = backBuffer.SampleLevel(Sampler, uv, 0); | ||
color += toMerge.SampleLevel(Sampler, uv, 0); | ||
color = saturate(color); | ||
|
||
output[DTid.xy] = float4(color, 1); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#pragma once | ||
#define KERNELSIZE 7 | ||
static const float gaussianFilter[KERNELSIZE] = | ||
{ | ||
0.070159, 0.131075, 0.190713, 0.216106, 0.190713, 0.131075, 0.070159 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#include "PostProccessor.h" | ||
#include <WICTextureLoader.h> | ||
#include "ThrowIfFailed.h" | ||
#include <string> | ||
#define _USE_MATH_DEFINES | ||
#include <math.h> | ||
#define KERNELSIZE 7 | ||
#define SIGMA 2 | ||
|
||
Graphics::PostProcessor::PostProcessor(ID3D11Device * device, ID3D11DeviceContext * context) | ||
: glow(device, SHADER_PATH("Glow.hlsl")) | ||
, glow2(device, SHADER_PATH("GlowSecond.hlsl")) | ||
, merger(device, SHADER_PATH("Merger.hlsl")) | ||
, glowPass0(device, WIN_WIDTH / 2, WIN_HEIGHT / 2) | ||
, glowPass1(device, WIN_WIDTH / 2, WIN_HEIGHT / 2) | ||
{ | ||
this->states = new DirectX::CommonStates(device); | ||
|
||
//Enable this only if you want a new gaussian filter | ||
//auto kernels = generateKernel(KERNELSIZE, SIGMA); | ||
|
||
} | ||
|
||
Graphics::PostProcessor::~PostProcessor() | ||
{ | ||
delete states; | ||
} | ||
|
||
std::vector<float> Graphics::PostProcessor::generateKernel(int kernelSize, float sigma) | ||
{ | ||
if (kernelSize % 2 == 0) kernelSize--; | ||
|
||
std::vector<float> kernel(kernelSize); | ||
|
||
auto g = [&](int x) -> float { | ||
static float gMult = 1.0f / (sqrt(2.0f * M_PI) * sigma); | ||
return gMult * pow(M_E, -(pow(x, 2) / (2.0f * pow(sigma, 2)))); | ||
}; | ||
|
||
float kernelSum = 0; | ||
int halfWidth = (kernelSize + 1) / 2; | ||
for (int x = 0; x < halfWidth; x++) { | ||
float factor = g(x); | ||
kernelSum += factor * (x == 0 ? 1 : 2); | ||
kernel[halfWidth-1 + x] = factor; | ||
kernel[halfWidth-1 - x] = factor; | ||
} | ||
|
||
for (auto& k : kernel) { | ||
k /= kernelSum; | ||
} | ||
|
||
std::wstring output = L""; | ||
|
||
for (size_t i = 0; i < kernel.size(); i++) | ||
{ | ||
output += std::to_wstring(kernel[i]); | ||
output += L", "; | ||
} | ||
output += L"\n"; | ||
OutputDebugStringW(output.c_str()); | ||
|
||
return kernel; | ||
} | ||
|
||
void Graphics::PostProcessor::addGlow(ID3D11DeviceContext * context, ID3D11ShaderResourceView * backBuffer, ID3D11ShaderResourceView * glowMap, ShaderResource * outputTexture) | ||
{ | ||
ID3D11UnorderedAccessView * nullUAV = nullptr; | ||
ID3D11ShaderResourceView * nullSRV = nullptr; | ||
|
||
context->CSSetShader(glow, nullptr, 0); | ||
context->CSSetUnorderedAccessViews(0, 1, glowPass0, nullptr); | ||
context->CSSetShaderResources(0, 1, &glowMap); | ||
context->Dispatch(WIN_WIDTH / 32, WIN_HEIGHT / 18, 1); | ||
|
||
|
||
context->CSSetUnorderedAccessViews(0, 1, glowPass1, nullptr); | ||
context->CSSetShaderResources(0, 1, glowPass0); | ||
|
||
context->CSSetShader(glow2, nullptr, 0); | ||
context->Dispatch(WIN_WIDTH / 32, WIN_HEIGHT / 18, 1); | ||
|
||
context->CSSetUnorderedAccessViews(0, 1, &nullUAV, nullptr); | ||
|
||
context->CSSetShader(merger, nullptr, 0); | ||
auto sampler = states->LinearWrap(); | ||
context->CSSetSamplers(0, 1, &sampler); | ||
|
||
context->CSSetShaderResources(0, 1, &backBuffer); | ||
context->CSSetShaderResources(1, 1, glowPass1); | ||
context->CSSetUnorderedAccessViews(0, 1, *outputTexture, nullptr); | ||
|
||
context->Dispatch(WIN_WIDTH / 16, WIN_HEIGHT / 9, 1); | ||
|
||
context->CSSetUnorderedAccessViews(0, 1, &nullUAV, nullptr); | ||
context->CSSetShaderResources(0, 1, &nullSRV); | ||
context->CSSetShaderResources(1, 1, &nullSRV); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#pragma once | ||
#include "Resources\Shader.h" | ||
#include <Engine\Constants.h> | ||
#include "Resources\ShaderResource.h" | ||
#include <CommonStates.h> | ||
#include "Utility\ConstantBuffer.h" | ||
#include <vector> | ||
|
||
namespace Graphics | ||
{ | ||
class PostProcessor | ||
{ | ||
public: | ||
PostProcessor(ID3D11Device * device, ID3D11DeviceContext * context); | ||
~PostProcessor(); | ||
|
||
void addGlow(ID3D11DeviceContext * context, ID3D11ShaderResourceView * backBuffer, ID3D11ShaderResourceView * glowMap, ShaderResource * outputTexture); | ||
|
||
std::vector<float> generateKernel(int kernelSize, float sigma); | ||
private: | ||
ComputeShader glow; | ||
ComputeShader glow2; | ||
ComputeShader merger; | ||
|
||
ShaderResource glowPass0; | ||
ShaderResource glowPass1; | ||
|
||
DirectX::CommonStates * states; | ||
}; | ||
} |
Oops, something went wrong.