Browse Source

Bit of cleanup and moving stuff around

mac-autoexp
Nico de Poel 3 years ago
parent
commit
2f5eaf48ba
  1. 0
      Assets/Resources/Shaders/FSR2_CopyDepth.shader
  2. 0
      Assets/Resources/Shaders/FSR2_CopyDepth.shader.meta
  3. 0
      Assets/Resources/Shaders/FSR2_CopyMotionVectors.shader
  4. 0
      Assets/Resources/Shaders/FSR2_CopyMotionVectors.shader.meta
  5. 40
      Assets/Resources/Shaders/FSRTest.shader
  6. 10
      Assets/Resources/Shaders/FSRTest.shader.meta
  7. 5
      Assets/Scripts/Fsr2.cs
  8. 13
      Assets/Scripts/Fsr2Controller.cs
  9. 9
      Assets/Scripts/SubsampleTest.cs

0
Assets/Resources/Shaders/FSR2CopyDepth.shader → Assets/Resources/Shaders/FSR2_CopyDepth.shader

0
Assets/Resources/Shaders/FSR2CopyDepth.shader.meta → Assets/Resources/Shaders/FSR2_CopyDepth.shader.meta

0
Assets/Resources/Shaders/FSR2CopyMotionVectors.shader → Assets/Resources/Shaders/FSR2_CopyMotionVectors.shader

0
Assets/Resources/Shaders/FSR2CopyMotionVectors.shader.meta → Assets/Resources/Shaders/FSR2_CopyMotionVectors.shader.meta

40
Assets/Resources/Shaders/FSRTest.shader

@ -1,40 +0,0 @@
Shader "FSR2/FSRTest"
{
Properties
{
_MainTex ("Texture", 2D) = "" {}
}
SubShader {
Pass {
ZTest Always Cull Off ZWrite Off
HLSLPROGRAM
// include the unityCG.cginc
#include "UnityCG.cginc"
// The default vert setup used in all the shaders
struct v2f {
float4 vertex : SV_POSITION;
float2 texCoord : TEXCOORD0;
};
#pragma vertex vert_img
#pragma fragment frag
sampler2D _MainTex;
sampler2D _CameraDepthTexture;
sampler2D_half _CameraMotionVectorsTexture;
fixed4 frag(v2f i) : COLOR
{
return tex2D(_MainTex, i.texCoord).rgba;
return fixed4(((tex2D(_CameraMotionVectorsTexture, i.texCoord) + 0.5f) / 2.0f).xyz, 1.0f);
//return tex2D(_CameraDepthTexture, i.texCoord).rrra;
}
ENDHLSL
}
}
Fallback Off
}

10
Assets/Resources/Shaders/FSRTest.shader.meta

@ -1,10 +0,0 @@
fileFormatVersion: 2
guid: ad642f5802989914585b30523ba86017
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
preprocessorOverride: 0
userData:
assetBundleName:
assetBundleVariant:

5
Assets/Scripts/Fsr2.cs

@ -58,6 +58,11 @@ namespace FidelityFX
renderWidth = (uint)(displayWidth / ratio); renderWidth = (uint)(displayWidth / ratio);
renderHeight = (uint)(displayHeight / ratio); renderHeight = (uint)(displayHeight / ratio);
} }
public static float GetMipmapBiasOffset(float renderScale)
{
return Mathf.Log(renderScale, 2.0f) - 1.0f;
}
public static int GetJitterPhaseCount(int renderWidth, int displayWidth) public static int GetJitterPhaseCount(int renderWidth, int displayWidth)
{ {

13
Assets/Scripts/Fsr2Controller.cs

@ -47,7 +47,7 @@ public class Fsr2Controller : MonoBehaviour
{ {
if (_copyDepthMat == null) if (_copyDepthMat == null)
{ {
var copyDepthShader = Fsr2.GlobalCallbacks.LoadShader("Shaders/FSR2CopyDepth");
var copyDepthShader = Fsr2.GlobalCallbacks.LoadShader("Shaders/FSR2_CopyDepth");
_copyDepthMat = new Material(copyDepthShader); _copyDepthMat = new Material(copyDepthShader);
} }
@ -62,7 +62,7 @@ public class Fsr2Controller : MonoBehaviour
{ {
if (_copyMotionMat == null) if (_copyMotionMat == null)
{ {
var copyMotionShader = Fsr2.GlobalCallbacks.LoadShader("Shaders/FSR2CopyMotionVectors");
var copyMotionShader = Fsr2.GlobalCallbacks.LoadShader("Shaders/FSR2_CopyMotionVectors");
_copyMotionMat = new Material(copyMotionShader); _copyMotionMat = new Material(copyMotionShader);
} }
@ -88,6 +88,7 @@ public class Fsr2Controller : MonoBehaviour
// TODO: enable motion vector jitter cancellation or not? // TODO: enable motion vector jitter cancellation or not?
_context = Fsr2.CreateContext(DisplaySize, RenderSize); _context = Fsr2.CreateContext(DisplaySize, RenderSize);
// TODO: do we need a depth buffer for the output? We will need depth & motion vectors for subsequent post-FX. How should FSR2 output these?
_outputRT = new RenderTexture(DisplaySize.x, DisplaySize.y, 24, RenderTextureFormat.ARGBHalf) { enableRandomWrite = true }; _outputRT = new RenderTexture(DisplaySize.x, DisplaySize.y, 24, RenderTextureFormat.ARGBHalf) { enableRandomWrite = true };
_outputRT.Create(); _outputRT.Create();
@ -122,11 +123,11 @@ public class Fsr2Controller : MonoBehaviour
public void UpdateInputResources(RenderTexture src) public void UpdateInputResources(RenderTexture src)
{ {
// I hate having to allocate extra RTs just to duplicate already existing Unity render buffers, but AFAIK there is no way to directly address these buffers individually from code // I hate having to allocate extra RTs just to duplicate already existing Unity render buffers, but AFAIK there is no way to directly address these buffers individually from code
var renderSize = RenderSize;
_colorRT = RenderTexture.GetTemporary(renderSize.x, renderSize.y, 0, RenderTextureFormat.ARGBHalf);
_depthRT = RenderTexture.GetTemporary(renderSize.x, renderSize.y, 0, RenderTextureFormat.RFloat);
_motionVectorsRT = RenderTexture.GetTemporary(renderSize.x, renderSize.y, 0, RenderTextureFormat.RGHalf);
_colorRT = RenderTexture.GetTemporary(src.width, src.height, 0, RenderTextureFormat.ARGBHalf);
_depthRT = RenderTexture.GetTemporary(src.width, src.height, 0, RenderTextureFormat.RFloat);
_motionVectorsRT = RenderTexture.GetTemporary(src.width, src.height, 0, RenderTextureFormat.RGHalf);
// TODO: might be able to combine color + depth into a single RT and separate them out using RenderTextureSubElement
Graphics.Blit(src, _colorRT); Graphics.Blit(src, _colorRT);
Graphics.Blit(src, _depthRT, CopyDepthMaterial); Graphics.Blit(src, _depthRT, CopyDepthMaterial);
Graphics.Blit(src, _motionVectorsRT, CopyMotionVectorsMaterial); Graphics.Blit(src, _motionVectorsRT, CopyMotionVectorsMaterial);

9
Assets/Scripts/SubsampleTest.cs

@ -61,13 +61,13 @@ public class SubsampleTest : MonoBehaviour
// Adjust texture mipmap LOD bias by log2(renderResolution/displayResolution) - 1.0; // Adjust texture mipmap LOD bias by log2(renderResolution/displayResolution) - 1.0;
// May need to leave this to the game dev, as we don't know which textures do and don't belong to the 3D scene // May need to leave this to the game dev, as we don't know which textures do and don't belong to the 3D scene
float biasOffset = GetMipmapBiasOffset();
float biasOffset = Fsr2.GetMipmapBiasOffset(renderScale);
Fsr2.GlobalCallbacks.ApplyMipmapBias(biasOffset); Fsr2.GlobalCallbacks.ApplyMipmapBias(biasOffset);
} }
private void OnDisable() private void OnDisable()
{ {
float biasOffset = GetMipmapBiasOffset();
float biasOffset = Fsr2.GetMipmapBiasOffset(renderScale);
Fsr2.GlobalCallbacks.ApplyMipmapBias(-biasOffset); Fsr2.GlobalCallbacks.ApplyMipmapBias(-biasOffset);
gameCamera.targetTexture.Release(); gameCamera.targetTexture.Release();
@ -77,11 +77,6 @@ public class SubsampleTest : MonoBehaviour
outputCamera.enabled = false; outputCamera.enabled = false;
} }
public float GetMipmapBiasOffset()
{
return Mathf.Log(renderScale) - 1.0f;
}
private void Update() private void Update()
{ {
outputCamera.enabled = gameCamera.enabled; outputCamera.enabled = gameCamera.enabled;

Loading…
Cancel
Save