Skip to content

Commit

Permalink
Merge pull request #25 from henrikvik/development
Browse files Browse the repository at this point in the history
Sprint 2
  • Loading branch information
henrikvik authored Sep 29, 2017
2 parents 62d08ba + ffb2a26 commit 2817517
Show file tree
Hide file tree
Showing 65 changed files with 1,333 additions and 278 deletions.
21 changes: 2 additions & 19 deletions Engine/Engine.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -184,31 +184,14 @@
<ItemGroup>
<ClInclude Include="Constants.h" />
<ClInclude Include="Engine.h" />
</ItemGroup>
<ItemGroup>
<FxCompile Include="Resources\Shaders\LightGridCulling.hlsl">
<EntryPointName Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">CS</EntryPointName>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Compute</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">5.0</ShaderModel>
<EntryPointName Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">CS</EntryPointName>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Compute</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">5.0</ShaderModel>
<EntryPointName Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">CS</EntryPointName>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Compute</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">5.0</ShaderModel>
<EntryPointName Condition="'$(Configuration)|$(Platform)'=='Release|x64'">CS</EntryPointName>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Compute</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|x64'">5.0</ShaderModel>
</FxCompile>
<ClInclude Include="Resources\Shaders\ShaderConstants.h" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\Data\Button.lw" />
<None Include="Resources\Data\Cards.lw" />
<None Include="Resources\Data\Effects.lw" />
<None Include="Resources\Data\Highscore.lw" />
<None Include="Resources\Data\Menu.lw" />
<None Include="Resources\Shaders\Vertex.hlsl">
<FileType>Document</FileType>
</None>
</ItemGroup>
<ItemGroup>
<Text Include="Resources\data\Text.lw" />
Expand Down
8 changes: 4 additions & 4 deletions Engine/Engine.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@
<ClInclude Include="Constants.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Resources\Shaders\ShaderConstants.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="Resources\Shaders\Vertex.hlsl" />
<None Include="Resources\Data\Effects.lw" />
<None Include="Resources\Data\Menu.lw" />
<None Include="Resources\Data\Button.lw" />
<None Include="Resources\Data\Cards.lw" />
<None Include="Resources\Data\Highscore.lw" />
</ItemGroup>
<ItemGroup>
<Text Include="Resources\data\Text.lw" />
</ItemGroup>
<ItemGroup>
<FxCompile Include="Resources\Shaders\LightGridCulling.hlsl" />
</ItemGroup>
</Project>
Empty file.
Binary file added Engine/Resources/Models/CrossBow.brf
Binary file not shown.
14 changes: 9 additions & 5 deletions Engine/Resources/Shaders/ForwardPlus.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ struct VSOutput {
float3 tangent : TANGENT;
};

struct PSOutput
{
float4 backBuffer : SV_Target0;
float4 glowMap : SV_Target1;
};

VSOutput VS(VSInput input, uint instanceId : SV_InstanceId) {
VSOutput output;

Expand Down Expand Up @@ -105,10 +111,7 @@ SamplerComparisonState cmpSampler : register(s1);
Texture2D diffuseMap : register(t10);
Texture2D normalMap : register(t11);
Texture2D specularMap : register(t12);

struct PSOutput {
float4 color : SV_Target;
};
Texture2D glowMap : register(t13);

//Returns the shadow amount of a given position
float getShadowValue(float4 lightPos, int sampleCount = 1)
Expand Down Expand Up @@ -205,7 +208,8 @@ PSOutput PS(VSOutput input) {

float3 lighting = saturate(finalDiffuse + finalSpecular + ambient);

output.color = float4(lighting, 1);
output.backBuffer = float4(lighting, 1);
output.glowMap = glowMap.Sample(Sampler, input.uv);

return output;
}
Expand Down
22 changes: 9 additions & 13 deletions Engine/Resources/Shaders/Glow.hlsl
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;
}
21 changes: 21 additions & 0 deletions Engine/Resources/Shaders/Merger.hlsl
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);

}
6 changes: 6 additions & 0 deletions Engine/Resources/Shaders/ShaderConstants.h
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
};
16 changes: 6 additions & 10 deletions Engine/Resources/Shaders/glowSecond.hlsl
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@

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 - int3(0, 2, 0);
int3 textureLocation = DTid - int3(0, KERNELSIZE / 2, 0);

float4 final = { 0.0, 0.0, 0.0, 1.0 };
for (uint y = 0; y < 5; y++)
for (uint y = 0; y < KERNELSIZE; y++)
final += inputTexture.Load(textureLocation + int3(0, y, 0)) * gaussianFilter[y];


Expand Down
Binary file added Engine/Resources/Textures/glowMapTree.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions Graphics/Graphics.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<ClCompile Include="include\Camera.cpp" />
<ClCompile Include="include\Lights\Sun.cpp" />
<ClCompile Include="include\Lights\LightGrid.cpp" />
<ClCompile Include="include\PostProccessor.cpp" />
<ClCompile Include="include\Renderer.cpp" />
<ClCompile Include="include\Resources\BRFImportHandler.cpp" />
<ClCompile Include="include\Resources\DepthStencil.cpp" />
Expand All @@ -35,6 +36,7 @@
<ClCompile Include="include\Resources\MeshManager.cpp" />
<ClCompile Include="include\Resources\ResourceManager.cpp" />
<ClCompile Include="include\Resources\Shader.cpp" />
<ClCompile Include="include\Resources\ShaderResource.cpp" />
<ClCompile Include="include\Resources\TextureManager.cpp" />
<ClCompile Include="include\SkyRenderer.cpp" />
</ItemGroup>
Expand All @@ -51,6 +53,7 @@
<ClInclude Include="include\Graphics.h" />
<ClInclude Include="include\Lights\Sun.h" />
<ClInclude Include="include\Lights\LightGrid.h" />
<ClInclude Include="include\PostProccessor.h" />
<ClInclude Include="include\Renderer.h" />
<ClInclude Include="include\Resources\BRFImportHandler.h" />
<ClInclude Include="include\Resources\DepthStencil.h" />
Expand All @@ -60,6 +63,7 @@
<ClInclude Include="include\Resources\MeshManager.h" />
<ClInclude Include="include\Resources\ResourceManager.h" />
<ClInclude Include="include\Resources\Shader.h" />
<ClInclude Include="include\Resources\ShaderResource.h" />
<ClInclude Include="include\Resources\TextureManager.h" />
<ClInclude Include="include\SkyRenderer.h" />
<ClInclude Include="include\Structs.h" />
Expand Down
98 changes: 98 additions & 0 deletions Graphics/include/PostProccessor.cpp
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);
}
30 changes: 30 additions & 0 deletions Graphics/include/PostProccessor.h
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;
};
}
Loading

0 comments on commit 2817517

Please sign in to comment.