-
Notifications
You must be signed in to change notification settings - Fork 500
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
4,444 additions
and
4 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
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
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,109 @@ | ||
#pragma once | ||
#include "pch.h" | ||
#include <EffectBase.h> | ||
#include "EffectDefines.h" | ||
#include "FfxEasuTransform.h" | ||
#include "FfxRcasTransform.h" | ||
|
||
|
||
class FSREffect : public EffectBase { | ||
public: | ||
IFACEMETHODIMP Initialize( | ||
_In_ ID2D1EffectContext* pEffectContext, | ||
_In_ ID2D1TransformGraph* pTransformGraph | ||
) { | ||
HRESULT hr = FfxEasuTransform::Create(pEffectContext, &_easuTransform); | ||
if (FAILED(hr)) { | ||
return hr; | ||
} | ||
hr = FfxRcasTransform::Create(pEffectContext, &_rcasTransform); | ||
if (FAILED(hr)) { | ||
return hr; | ||
} | ||
|
||
hr = pTransformGraph->AddNode(_easuTransform.Get()); | ||
if (FAILED(hr)) { | ||
return hr; | ||
} | ||
hr = pTransformGraph->AddNode(_rcasTransform.Get()); | ||
if (FAILED(hr)) { | ||
return hr; | ||
} | ||
|
||
hr = pTransformGraph->ConnectToEffectInput(0, _easuTransform.Get(), 0); | ||
if (FAILED(hr)) { | ||
return hr; | ||
} | ||
hr = pTransformGraph->ConnectNode(_easuTransform.Get(), _rcasTransform.Get(), 0); | ||
if (FAILED(hr)) { | ||
return hr; | ||
} | ||
hr = pTransformGraph->SetOutputNode(_rcasTransform.Get()); | ||
if (FAILED(hr)) { | ||
return hr; | ||
} | ||
|
||
return S_OK; | ||
} | ||
|
||
HRESULT SetScale(D2D_VECTOR_2F value) { | ||
if (value.x <= 0 || value.y <= 0) { | ||
return E_INVALIDARG; | ||
} | ||
|
||
_easuTransform->SetScale(value); | ||
return S_OK; | ||
} | ||
|
||
D2D_VECTOR_2F GetScale() const { | ||
return _easuTransform->GetScale(); | ||
} | ||
|
||
enum PROPS { | ||
PROP_SCALE = 0, | ||
}; | ||
|
||
static HRESULT Register(_In_ ID2D1Factory1* pFactory) { | ||
const D2D1_PROPERTY_BINDING bindings[] = | ||
{ | ||
D2D1_VALUE_TYPE_BINDING(L"Scale", &SetScale, &GetScale) | ||
}; | ||
|
||
HRESULT hr = pFactory->RegisterEffectFromString(CLSID_MAGPIE_FSR_EFFECT, XML( | ||
<?xml version='1.0'?> | ||
<Effect> | ||
<!--System Properties--> | ||
<Property name='DisplayName' type='string' value='FSR'/> | ||
<Property name='Author' type='string' value='Blinue'/> | ||
<Property name='Category' type='string' value='FFX'/> | ||
<Property name='Description' type='string' value='FSR'/> | ||
<Inputs> | ||
<Input name='Source'/> | ||
</Inputs> | ||
<Property name='Scale' type='vector2'> | ||
<Property name='DisplayName' type='string' value='Scale'/> | ||
<Property name='Default' type='vector2' value='(1,1)'/> | ||
</Property> | ||
|
||
</Effect> | ||
), bindings, ARRAYSIZE(bindings), CreateEffect); | ||
|
||
return hr; | ||
} | ||
|
||
static HRESULT CALLBACK CreateEffect(_Outptr_ IUnknown** ppEffectImpl) { | ||
*ppEffectImpl = static_cast<ID2D1EffectImpl*>(new FSREffect()); | ||
|
||
if (*ppEffectImpl == nullptr) { | ||
return E_OUTOFMEMORY; | ||
} | ||
|
||
return S_OK; | ||
} | ||
|
||
private: | ||
FSREffect() {} | ||
|
||
ComPtr<FfxEasuTransform> _easuTransform = nullptr; | ||
ComPtr<FfxRcasTransform> _rcasTransform = nullptr; | ||
}; |
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,45 @@ | ||
cbuffer constants : register(b0) { | ||
int2 srcSize : packoffset(c0.x); | ||
int2 destSize : packoffset(c0.z); | ||
}; | ||
|
||
#define MAGPIE_INPUT_COUNT 1 | ||
#include "common.hlsli" | ||
|
||
|
||
#define A_GPU 1 | ||
#define A_HLSL 1 | ||
#include "ffx_a.hlsli" | ||
#define FSR_EASU_F 1 | ||
|
||
AF4 FsrEasuRF(AF2 p) { | ||
return GatherInputRed(0, p * srcSize * Coord(0).zw); | ||
} | ||
AF4 FsrEasuGF(AF2 p) { | ||
return GatherInputGreen(0, p * srcSize * Coord(0).zw); | ||
} | ||
AF4 FsrEasuBF(AF2 p) { | ||
return GatherInputBlue(0, p * srcSize * Coord(0).zw); | ||
} | ||
|
||
|
||
#include "ffx_fsr1.hlsli" | ||
|
||
|
||
MAGPIE_ENTRY(main) { | ||
float2 rcpSrc = rcp(srcSize); | ||
float2 rcpDest = rcp(destSize); | ||
float2 scale = srcSize * rcpDest; | ||
|
||
float3 c; | ||
FsrEasuF( | ||
c, | ||
Coord(0).xy / Coord(0).zw, | ||
asuint(float4(scale, 0.5 * scale - 0.5)), | ||
asuint(float4(rcpSrc.xy, rcpSrc.x, -rcpSrc.y)), | ||
asuint(float4(-rcpSrc.x, 2 * rcpSrc.y, rcpSrc.x, 2 * rcpSrc.y)), | ||
asuint(float4(0, 4 * rcpSrc.y, 0, 0)) | ||
); | ||
|
||
return float4(c, 1.0f); | ||
} |
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,41 @@ | ||
#pragma once | ||
#include "pch.h" | ||
#include <SimpleScaleTransform.h> | ||
#include "EffectDefines.h" | ||
|
||
|
||
class FfxEasuTransform : public SimpleScaleTransform { | ||
private: | ||
FfxEasuTransform() : SimpleScaleTransform(GUID_MAGPIE_FFX_EASU_SHADER) {} | ||
public: | ||
static HRESULT Create(_In_ ID2D1EffectContext* d2dEC, _Outptr_ FfxEasuTransform** ppOutput) { | ||
if (!ppOutput) { | ||
return E_INVALIDARG; | ||
} | ||
|
||
HRESULT hr = LoadShader(d2dEC, MAGPIE_FFX_EASU_SHADER, GUID_MAGPIE_FFX_EASU_SHADER); | ||
if (FAILED(hr)) { | ||
return hr; | ||
} | ||
|
||
*ppOutput = new FfxEasuTransform(); | ||
return hr; | ||
} | ||
|
||
protected: | ||
void _SetShaderContantBuffer(const SIZE& srcSize, const SIZE& destSize) override { | ||
struct { | ||
INT32 srcWidth; | ||
INT32 srcHeight; | ||
INT32 destWidth; | ||
INT32 destHeight; | ||
} shaderConstants{ | ||
srcSize.cx, | ||
srcSize.cy, | ||
destSize.cx, | ||
destSize.cy | ||
}; | ||
|
||
_drawInfo->SetPixelShaderConstantBuffer((BYTE*)&shaderConstants, sizeof(shaderConstants)); | ||
} | ||
}; |
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,31 @@ | ||
cbuffer constants : register(b0) { | ||
uint2 srcSize : packoffset(c0.x); | ||
float sharpness : packoffset(c0.z); | ||
}; | ||
|
||
#define MAGPIE_INPUT_COUNT 1 | ||
#define MAGPIE_NO_CHECK | ||
#include "common.hlsli" | ||
|
||
|
||
#define A_GPU | ||
#define A_HLSL | ||
#include "ffx_a.hlsli" | ||
#define FSR_RCAS_F | ||
|
||
AF4 FsrRcasLoadF(ASU2 p) { return LoadInput(0, int3(ASU2(p), 0)); } | ||
void FsrRcasInputF(inout AF1 r, inout AF1 g, inout AF1 b) {} | ||
|
||
|
||
#include "ffx_fsr1.hlsli" | ||
|
||
|
||
MAGPIE_ENTRY(main) { | ||
float s = AExp2F1(-sharpness); | ||
varAF2(hSharp) = initAF2(s, s); | ||
|
||
float3 c; | ||
FsrRcasF(c.r, c.g, c.b, Coord(0).xy / Coord(0).zw, float4(AU1_AF1(s), AU1_AH2_AF2(hSharp), 0, 0)); | ||
|
||
return float4(c, 1.0f); | ||
} |
Oops, something went wrong.