Browse Source

Initial port of SGSR2 2-pass compute shaders to HLSL (untested)

sgsr2_fs
Nico de Poel 1 year ago
parent
commit
14fa1bc7d2
  1. 4
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/PostProcessResources.asset
  2. 16
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/SGSR2.cs
  3. 8
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/2_pass_cs.meta
  4. 136
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/2_pass_cs/sgsr2_convert.compute
  5. 7
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/2_pass_cs/sgsr2_convert.compute.meta
  6. 332
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/2_pass_cs/sgsr2_upscale.compute
  7. 7
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/2_pass_cs/sgsr2_upscale.compute.meta
  8. 8
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2Upscaler.cs

4
Packages/com.unity.postprocessing@3.2.2/PostProcessing/PostProcessResources.asset

@ -150,6 +150,10 @@ MonoBehaviour:
tcrAutoGenPass: {fileID: 7200000, guid: 75cdc6ef23f08ed498d4da511923fcea, type: 3}
debugViewPass: {fileID: 7200000, guid: cb24a71d54164c54eb5e86839acd48c5, type: 3}
sgsr2Upscaler:
twoPassCompute:
convert: {fileID: 7200000, guid: 073ee927fbee25841a31cf364834071c, type: 3}
upscale: {fileID: 7200000, guid: d7bacd7d04c6521499bef936d93921cc, type: 3}
threePassCompute:
convert: {fileID: 7200000, guid: a41757aacd8b70e42a4001d514bfbe53, type: 3}
activate: {fileID: 7200000, guid: d7de362950af6fe4e90da7d6e32f9826, type: 3}
upscale: {fileID: 7200000, guid: 5d28d29787492b74aa736a21f70572c7, type: 3}

16
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/SGSR2.cs

@ -3,7 +3,7 @@ using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SGSR2
public static class SGSR2
{
[Serializable]
public struct Params
@ -25,11 +25,23 @@ public class SGSR2
[Serializable]
public class Shaders
{
public TwoPassCompute twoPassCompute;
public ThreePassCompute threePassCompute;
[Serializable]
public class TwoPassCompute
{
public ComputeShader convert;
public ComputeShader upscale;
}
[Serializable]
public class ThreePassCompute
{
public ComputeShader convert;
public ComputeShader activate;
public ComputeShader upscale;
}
}
}

8
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/2_pass_cs.meta

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: def18d58a2ff64f44a2d9f73e487a689
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

136
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/2_pass_cs/sgsr2_convert.compute

@ -0,0 +1,136 @@
#pragma kernel CS
//============================================================================================================
//
//
// Copyright (c) 2024, Qualcomm Innovation Center, Inc. All rights reserved.
// SPDX-License-Identifier: BSD-3-Clause
//
//============================================================================================================
float2 decodeVelocityFromTexture(float2 ev) {
const float inv_div = 1.0f / (0.499f * 0.5f);
float2 dv;
dv.xy = ev.xy * inv_div - 32767.0f / 65535.0f * inv_div;
//dv.z = uintBitsToFloat((uint(round(ev.z * 65535.0f)) << 16) | uint(round(ev.w * 65535.0f)));
return dv;
}
Texture2D InputColor : register(t0);
Texture2D<float> InputDepth : register(t1);
Texture2D<float2> InputVelocity : register(t2);
RWTexture2D<float4> MotionDepthClipAlphaBuffer : register(u0);
RWTexture2D<uint> YCoCgColor : register(u1);
cbuffer Params : register(b0)
{
uint2 renderSize;
uint2 displaySize;
float2 renderSizeRcp;
float2 displaySizeRcp;
float2 jitterOffset;
float2 padding1;
float4 clipToPrevClip[4];
float preExposure;
float cameraFovAngleHor;
float cameraNear;
float MinLerpContribution;
uint bSameCamera;
uint reset;
};
SamplerState s_PointClamp : register(s0);
SamplerState s_LinearClamp : register(s1);
[numthreads(8, 8, 1)]
void CS(uint3 globalInvocationID : SV_DispatchThreadID)
{
float Exposure_co_rcp = preExposure;
float2 ViewportSizeInverse = displaySizeRcp.xy;
uint2 InputPos = globalInvocationID.xy;
float2 gatherCoord = float2(globalInvocationID.xy) * ViewportSizeInverse;
float2 ViewportUV = gatherCoord + 0.5f * ViewportSizeInverse;
//derived from ffx_fsr2_reconstruct_dilated_velocity_and_previous_depth.h
//FindNearestDepth
float4 topleft = InputDepth.GatherRed(s_PointClamp, gatherCoord);
float2 v10 = float2(ViewportSizeInverse.x*2.0, 0.0);
float4 topRight = InputDepth.GatherRed(s_PointClamp, (gatherCoord+v10));
float2 v12 = float2(0.0, ViewportSizeInverse.y*2.0);
float4 bottomLeft = InputDepth.GatherRed(s_PointClamp, (gatherCoord+v12));
float2 v14 = float2(ViewportSizeInverse.x*2.0, ViewportSizeInverse.y*2.0);
float4 bottomRight = InputDepth.GatherRed(s_PointClamp, (gatherCoord+v14));
float maxC = max(max(max(topleft.y,topRight.x),bottomLeft.z),bottomRight.w);
float topleft4 = max(max(max(topleft.y,topleft.x),topleft.z),topleft.w);
float topLeftMax9 = max(bottomLeft.w,max(max(maxC,topleft4),topRight.w));
float depthclip = 0.0;
if (maxC > 1.0e-05f)
{
float topRight4 = max(max(max(topRight.y,topRight.x),topRight.z),topRight.w);
float bottomLeft4 = max(max(max(bottomLeft.y,bottomLeft.x),bottomLeft.z),bottomLeft.w);
float bottomRight4 = max(max(max(bottomRight.y,bottomRight.x),bottomRight.z),bottomRight.w);
float Wdepth = 0.0;
float Ksep = 1.37e-05f;
float Kfov = cameraFovAngleHor;
float diagonal_length = length(float2(renderSize));
float Ksep_Kfov_diagonal = Ksep * Kfov * diagonal_length;
float Depthsep = Ksep_Kfov_diagonal * (1.0 - maxC);
float EPSILON = 1.19e-07f;
Wdepth += clamp((Depthsep / (abs(maxC - topleft4) + EPSILON)), 0.0, 1.0);
Wdepth += clamp((Depthsep / (abs(maxC - topRight4) + EPSILON)), 0.0, 1.0);
Wdepth += clamp((Depthsep / (abs(maxC - bottomLeft4) + EPSILON)), 0.0, 1.0);
Wdepth += clamp((Depthsep / (abs(maxC - bottomRight4) + EPSILON)), 0.0, 1.0);
depthclip = clamp(1.0f - Wdepth*0.25, 0.0, 1.0);
}
//refer to ue/fsr2 PostProcessFFX_FSR2ConvertVelocity.usf, and using nearest depth for dilated motion
float2 EncodedVelocity = InputVelocity[InputPos];
float2 motion;
if (EncodedVelocity.x > 0.0)
{
motion = decodeVelocityFromTexture(EncodedVelocity.xy);
}
else
{
#ifdef REQUEST_NDC_Y_UP
float2 ScreenPos = float2(2.0f * ViewportUV.x - 1.0f, 1.0f - 2.0f * ViewportUV.y);
#else
float2 ScreenPos = float2(2.0f * ViewportUV - 1.0f);
#endif
float3 Position = float3(ScreenPos, topLeftMax9); //this_clip
float4 PreClip = clipToPrevClip[3] + ((clipToPrevClip[2] * Position.z) + ((clipToPrevClip[1] * ScreenPos.y) + (clipToPrevClip[0] * ScreenPos.x)));
float2 PreScreen = PreClip.xy / PreClip.w;
motion = Position.xy - PreScreen;
}
motion = EncodedVelocity;
////////////compute luma
float3 Colorrgb = InputColor[InputPos].xyz;
///simple tonemap
float ColorMax = max(max(Colorrgb.x, Colorrgb.y), Colorrgb.z) + Exposure_co_rcp;
Colorrgb /= ColorMax;
float3 Colorycocg;
Colorycocg.x = 0.25 * (Colorrgb.x + 2.0 * Colorrgb.y + Colorrgb.z);
Colorycocg.y = clamp(0.5 * Colorrgb.x + 0.5 - 0.5 * Colorrgb.z, 0.0, 1.0);
Colorycocg.z = clamp(Colorycocg.x + Colorycocg.y - Colorrgb.x, 0.0, 1.0);
//now color YCoCG all in the range of [0,1]
uint x11 = uint(Colorycocg.x * 2047.5);
uint y11 = uint(Colorycocg.y * 2047.5);
uint z10 = uint(Colorycocg.z * 1023.5);
YCoCgColor[InputPos] = ((x11 << 21u) | (y11 << 10u)) | z10;
float4 v29 = float4(motion, depthclip, ColorMax);
MotionDepthClipAlphaBuffer[InputPos] = v29;
}

7
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/2_pass_cs/sgsr2_convert.compute.meta

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 073ee927fbee25841a31cf364834071c
ComputeShaderImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

332
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/2_pass_cs/sgsr2_upscale.compute

@ -0,0 +1,332 @@
#pragma kernel CS
//============================================================================================================
//
//
// Copyright (c) 2024, Qualcomm Innovation Center, Inc. All rights reserved.
// SPDX-License-Identifier: BSD-3-Clause
//
//============================================================================================================
float FastLanczos(float base)
{
float y = base - 1.0f;
float y2 = y * y;
float y_temp = 0.75f * y + y2;
return y_temp * y2;
}
float3 DecodeColor(uint sample32)
{
uint x11 = sample32 >> 21u;
uint y11 = sample32 & (2047u << 10u);
uint z10 = sample32 & 1023u;
float3 samplecolor;
samplecolor.x = (float(x11) * (1.0 / 2047.5));
samplecolor.y = (float(y11) * (4.76953602e-7)) - 0.5;
samplecolor.z = (float(z10) * (1.0 / 1023.5)) - 0.5;
return samplecolor;
}
Texture2D PrevHistoryOutput : register(t0);
Texture2D MotionDepthClipAlphaBuffer : register(t1);
Texture2D<uint> YCoCgColor : register(t2);
RWTexture2D<float4> SceneColorOutput : register(u0);
RWTexture2D<float4> HistoryOutput : register(u1);
cbuffer Params : register(b0)
{
uint2 renderSize;
uint2 displaySize;
float2 renderSizeRcp;
float2 displaySizeRcp;
float2 jitterOffset;
float2 padding1;
float4 clipToPrevClip[4];
float preExposure;
float cameraFovAngleHor;
float cameraNear;
float MinLerpContribution;
uint bSameCamera;
uint reset;
};
SamplerState s_PointClamp : register(s0);
SamplerState s_LinearClamp : register(s1);
[numthreads(8, 8, 1)]
void CS(uint3 globalInvocationID : SV_DispatchThreadID)
{
float Biasmax_viewportXScale = min(float(displaySize.x) / float(renderSize.x), 1.99); //Biasmax_viewportXScale
float scalefactor = min(20.0, pow((float(displaySize.x) / float(renderSize.x)) * (float(displaySize.y) / float(renderSize.y)), 3.0));
float f2 = preExposure; //1.0; //preExposure
float2 HistoryInfoViewportSizeInverse = displaySizeRcp;
float2 HistoryInfoViewportSize = float2(displaySize);
float2 InputJitter = jitterOffset;
float2 InputInfoViewportSize = float2(renderSize);
float2 Hruv = (float2(globalInvocationID.xy) + 0.5f) * HistoryInfoViewportSizeInverse;
float2 Jitteruv;
Jitteruv.x = clamp(Hruv.x + (InputJitter.x * HistoryInfoViewportSizeInverse.x), 0.0, 1.0);
Jitteruv.y = clamp(Hruv.y + (InputJitter.y * HistoryInfoViewportSizeInverse.y), 0.0, 1.0);
int2 InputPos = int2(Jitteruv * InputInfoViewportSize);
float4 mda = MotionDepthClipAlphaBuffer.SampleLevel(s_LinearClamp, Jitteruv, 0).xyzw;
float2 Motion = mda.xy;
///ScreenPosToViewportScale&Bias
float2 PrevUV;
PrevUV.x = clamp(-0.5 * Motion.x + Hruv.x, 0.0, 1.0);
#ifdef REQUEST_NDC_Y_UP
PrevUV.y = clamp(0.5 * Motion.y + Hruv.y, 0.0, 1.0);
#else
PrevUV.y = clamp(-0.5 * Motion.y + Hruv.y, 0.0, 1.0);
#endif
float depthfactor = mda.z;
float ColorMax = mda.w;
float4 History = PrevHistoryOutput.SampleLevel(s_LinearClamp, PrevUV, 0);
float3 HistoryColor = History.xyz;
float Historyw = History.w;
float Wfactor = clamp(abs(Historyw), 0.0, 1.0);
/////upsample and compute box
float4 Upsampledcw = 0.0f;
float kernelfactor = clamp(Wfactor + float(reset), 0.0, 1.0);
float biasmax = Biasmax_viewportXScale - Biasmax_viewportXScale * kernelfactor;
float biasmin = max(1.0f, 0.3 + 0.3 * biasmax);
float biasfactor = max(0.25f * depthfactor, kernelfactor);
float kernelbias = lerp(biasmax, biasmin, biasfactor);
float motion_viewport_len = length(Motion * HistoryInfoViewportSize);
float curvebias = lerp(-2.0, -3.0, clamp(motion_viewport_len * 0.02, 0.0, 1.0));
float3 rectboxcenter = 0.0f;
float3 rectboxvar = 0.0f;
float rectboxweight = 0.0f;
float2 srcpos = float2(InputPos) + 0.5f - InputJitter;
float2 srcOutputPos = Hruv * InputInfoViewportSize;
kernelbias *= 0.5f;
float kernelbias2 = kernelbias * kernelbias;
float2 srcpos_srcOutputPos = srcpos - srcOutputPos;
int2 InputPosBtmRight = 1 + InputPos;
float2 gatherCoord = float2(InputPos) * renderSizeRcp;
uint btmRight = YCoCgColor[InputPosBtmRight].x;
uint4 topleft = YCoCgColor.GatherRed(s_PointClamp, gatherCoord);
uint2 topRight = 0;
uint2 bottomLeft = 0;
uint sameCameraFrmNum = bSameCamera;
if (sameCameraFrmNum!=0u)
{
topRight = YCoCgColor.GatherRed(s_PointClamp, gatherCoord + float2(renderSizeRcp.x, 0.0)).yz;
bottomLeft = YCoCgColor.GatherRed(s_PointClamp, gatherCoord + float2(0.0, renderSizeRcp.y)).xy;
}
else
{
uint2 btmRight = YCoCgColor.GatherRed(s_PointClamp, gatherCoord + float2(renderSizeRcp.x, renderSizeRcp.y)).xz;
bottomLeft.y = btmRight.x;
topRight.x = btmRight.y;
}
float3 rectboxmin;
float3 rectboxmax;
{
float3 samplecolor = DecodeColor(bottomLeft.y);
float2 baseoffset = srcpos_srcOutputPos + float2(0.0, 1.0);
float baseoffset_dot = dot(baseoffset, baseoffset);
float base = clamp(baseoffset_dot * kernelbias2, 0.0f, 1.0f);
float weight = FastLanczos(base);
Upsampledcw += float4(samplecolor * weight, weight);
float boxweight = exp(baseoffset_dot * curvebias);
rectboxmin = samplecolor;
rectboxmax = samplecolor;
float3 wsample = samplecolor * boxweight;
rectboxcenter += wsample;
rectboxvar += (samplecolor * wsample);
rectboxweight += boxweight;
}
{
float3 samplecolor = DecodeColor(topRight.x);
float2 baseoffset = srcpos_srcOutputPos + float2(1.0, 0.0);
float baseoffset_dot = dot(baseoffset, baseoffset);
float base = clamp(baseoffset_dot * kernelbias2, 0.0f, 1.0f);
float weight = FastLanczos(base);
Upsampledcw += float4(samplecolor * weight, weight);
float boxweight = exp(baseoffset_dot * curvebias);
rectboxmin = min(rectboxmin, samplecolor);
rectboxmax = max(rectboxmax, samplecolor);
float3 wsample = samplecolor * boxweight;
rectboxcenter += wsample;
rectboxvar += (samplecolor * wsample);
rectboxweight += boxweight;
}
{
float3 samplecolor = DecodeColor(topleft.x);
float2 baseoffset = srcpos_srcOutputPos + float2(-1.0, 0.0);
float baseoffset_dot = dot(baseoffset, baseoffset);
float base = clamp(baseoffset_dot * kernelbias2, 0.0f, 1.0f);
float weight = FastLanczos(base);
Upsampledcw += float4(samplecolor * weight, weight);
float boxweight = exp(baseoffset_dot * curvebias);
rectboxmin = min(rectboxmin, samplecolor);
rectboxmax = max(rectboxmax, samplecolor);
float3 wsample = samplecolor * boxweight;
rectboxcenter += wsample;
rectboxvar += (samplecolor * wsample);
rectboxweight += boxweight;
}
{
float3 samplecolor = DecodeColor(topleft.y);
float2 baseoffset = srcpos_srcOutputPos;
float baseoffset_dot = dot(baseoffset, baseoffset);
float base = clamp(baseoffset_dot * kernelbias2, 0.0f, 1.0f);
float weight = FastLanczos(base);
Upsampledcw += float4(samplecolor * weight, weight);
float boxweight = exp(baseoffset_dot * curvebias);
rectboxmin = min(rectboxmin, samplecolor);
rectboxmax = max(rectboxmax, samplecolor);
float3 wsample = samplecolor * boxweight;
rectboxcenter += wsample;
rectboxvar += (samplecolor * wsample);
rectboxweight += boxweight;
}
{
float3 samplecolor = DecodeColor(topleft.z);
float2 baseoffset = srcpos_srcOutputPos + float2(0.0, -1.0);
float baseoffset_dot = dot(baseoffset, baseoffset);
float base = clamp(baseoffset_dot * kernelbias2, 0.0f, 1.0f);
float weight = FastLanczos(base);
Upsampledcw += float4(samplecolor * weight, weight);
float boxweight = exp(baseoffset_dot * curvebias);
rectboxmin = min(rectboxmin, samplecolor);
rectboxmax = max(rectboxmax, samplecolor);
float3 wsample = samplecolor * boxweight;
rectboxcenter += wsample;
rectboxvar += (samplecolor * wsample);
rectboxweight += boxweight;
}
if (sameCameraFrmNum!=0u)
{
{
float3 samplecolor = DecodeColor(btmRight);
float2 baseoffset = srcpos_srcOutputPos + float2(1.0, 1.0);
float baseoffset_dot = dot(baseoffset, baseoffset);
float base = clamp(baseoffset_dot * kernelbias2, 0.0, 1.0);
float weight = FastLanczos(base);
Upsampledcw += float4(samplecolor * weight, weight);
float boxweight = exp(baseoffset_dot * curvebias);
rectboxmin = min(rectboxmin, samplecolor);
rectboxmax = max(rectboxmax, samplecolor);
float3 wsample = samplecolor * boxweight;
rectboxcenter += wsample;
rectboxvar += (samplecolor * wsample);
rectboxweight += boxweight;
}
{
float3 samplecolor = DecodeColor(bottomLeft.x);
float2 baseoffset = srcpos_srcOutputPos + float2(-1.0, 1.0);
float baseoffset_dot = dot(baseoffset, baseoffset);
float base = clamp(baseoffset_dot * kernelbias2, 0.0f, 1.0f);
float weight = FastLanczos(base);
Upsampledcw += float4(samplecolor * weight, weight);
float boxweight = exp(baseoffset_dot * curvebias);
rectboxmin = min(rectboxmin, samplecolor);
rectboxmax = max(rectboxmax, samplecolor);
float3 wsample = samplecolor * boxweight;
rectboxcenter += wsample;
rectboxvar += (samplecolor * wsample);
rectboxweight += boxweight;
}
{
float3 samplecolor = DecodeColor(topRight.y);
float2 baseoffset = srcpos_srcOutputPos + float2(1.0, -1.0);
float baseoffset_dot = dot(baseoffset, baseoffset);
float base = clamp(baseoffset_dot * kernelbias2, 0.0f, 1.0f);
float weight = FastLanczos(base);
Upsampledcw += float4(samplecolor * weight, weight);
float boxweight = exp(baseoffset_dot * curvebias);
rectboxmin = min(rectboxmin, samplecolor);
rectboxmax = max(rectboxmax, samplecolor);
float3 wsample = samplecolor * boxweight;
rectboxcenter += wsample;
rectboxvar += (samplecolor * wsample);
rectboxweight += boxweight;
}
{
float3 samplecolor = DecodeColor(topleft.w);
float2 baseoffset = srcpos_srcOutputPos + float2(-1.0, -1.0);
float baseoffset_dot = dot(baseoffset, baseoffset);
float base = clamp(baseoffset_dot * kernelbias2, 0.0f, 1.0f);
float weight = FastLanczos(base);
Upsampledcw += float4(samplecolor * weight, weight);
float boxweight = exp(baseoffset_dot * curvebias);
rectboxmin = min(rectboxmin, samplecolor);
rectboxmax = max(rectboxmax, samplecolor);
float3 wsample = samplecolor * boxweight;
rectboxcenter += wsample;
rectboxvar += (samplecolor * wsample);
rectboxweight += boxweight;
}
}
rectboxweight = 1.0 / rectboxweight;
rectboxcenter *= rectboxweight;
rectboxvar *= rectboxweight;
rectboxvar = sqrt(abs(rectboxvar - rectboxcenter * rectboxcenter));
Upsampledcw.xyz = clamp(Upsampledcw.xyz / Upsampledcw.w, rectboxmin-0.05f, rectboxmax+0.05f);
Upsampledcw.w = Upsampledcw.w * (1.0f / 3.0f) ;
float OneMinusWfactor = 1.0f - Wfactor;
float baseupdate = OneMinusWfactor - OneMinusWfactor * depthfactor;
baseupdate = min(baseupdate, lerp(baseupdate, Upsampledcw.w *10.0f, clamp(10.0f* motion_viewport_len, 0.0, 1.0)));
baseupdate = min(baseupdate, lerp(baseupdate, Upsampledcw.w, clamp(motion_viewport_len *0.05f, 0.0, 1.0)));
float basealpha = baseupdate;
const float EPSILON = 1.192e-07f;
float boxscale = max(depthfactor, clamp(motion_viewport_len * 0.05f, 0.0, 1.0));
float boxsize = lerp(scalefactor, 1.0f, boxscale);
float3 sboxvar = rectboxvar * boxsize;
float3 boxmin = rectboxcenter - sboxvar;
float3 boxmax = rectboxcenter + sboxvar;
rectboxmax = min(rectboxmax, boxmax);
rectboxmin = max(rectboxmin, boxmin);
float3 clampedcolor = clamp(HistoryColor, rectboxmin, rectboxmax);
float startLerpValue = MinLerpContribution; //MinLerpContribution; //MinLerpContribution;
if ((abs(mda.x) + abs(mda.y)) > 0.000001) startLerpValue = 0.0;
float lerpcontribution = (any(rectboxmin > HistoryColor) || any(HistoryColor > rectboxmax)) ? startLerpValue : 1.0f;
HistoryColor = lerp(clampedcolor, HistoryColor, clamp(lerpcontribution, 0.0, 1.0));
float basemin = min(basealpha, 0.1f);
basealpha = lerp(basemin, basealpha, clamp(lerpcontribution, 0.0, 1.0));
////blend color
float alphasum = max(EPSILON, basealpha + Upsampledcw.w);
float alpha = clamp(Upsampledcw.w / alphasum + float(reset), 0.0, 1.0);
Upsampledcw.xyz = lerp(HistoryColor, Upsampledcw.xyz, alpha);
HistoryOutput[globalInvocationID.xy] = float4(Upsampledcw.xyz, Wfactor);
////ycocg to rgb
float x_z = Upsampledcw.x - Upsampledcw.z;
Upsampledcw.xyz = float3(
clamp(x_z + Upsampledcw.y, 0.0, 1.0),
clamp(Upsampledcw.x + Upsampledcw.z, 0.0, 1.0),
clamp(x_z - Upsampledcw.y, 0.0, 1.0));
float compMax = max(Upsampledcw.x, Upsampledcw.y);
compMax = clamp(max(compMax, Upsampledcw.z), 0.0f, 1.0f);
float scale = preExposure / ((1.0f + 600.0f / 65504.0f) - compMax);
if (ColorMax > 4000.0f) scale = ColorMax;
Upsampledcw.xyz = Upsampledcw.xyz * scale;
SceneColorOutput[globalInvocationID.xy] = Upsampledcw;
}

7
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2/Shaders/2_pass_cs/sgsr2_upscale.compute.meta

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: d7bacd7d04c6521499bef936d93921cc
ComputeShaderImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

8
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/SGSR2Upscaler.cs

@ -53,7 +53,7 @@ namespace UnityEngine.Rendering.PostProcessing
parms.renderSizeRcp = new Vector2(1.0f / parms.renderSize.x, 1.0f / parms.renderSize.y);
parms.displaySizeRcp = new Vector2(1.0f / parms.displaySize.x, 1.0f / parms.displaySize.y);
parms.jitterOffset = config.JitterOffset;
parms.clipToPrevClip = Matrix4x4.identity; // TODO: clipToPrevClip
parms.clipToPrevClip = Matrix4x4.identity; // TODO: clipToPrevClip => (previous_view_proj * inv_vp)
parms.preExposure = config.preExposure;
parms.cameraFovAngleHor = Mathf.Tan(context.camera.fieldOfView * Mathf.Deg2Rad * 0.5f) * (float)parms.renderSize.x / parms.renderSize.y;
parms.cameraNear = context.camera.nearClipPlane;
@ -84,7 +84,7 @@ namespace UnityEngine.Rendering.PostProcessing
private void Convert(CommandBuffer cmd, PostProcessRenderContext context, Upscaling config)
{
var shader = context.resources.computeShaders.sgsr2Upscaler.convert;
var shader = context.resources.computeShaders.sgsr2Upscaler.threePassCompute.convert;
int kernelIndex = shader.FindKernel("CS");
cmd.SetComputeConstantBufferParam(shader, "Params", _paramsBuffer, 0, Marshal.SizeOf<SGSR2.Params>());
@ -103,7 +103,7 @@ namespace UnityEngine.Rendering.PostProcessing
private void Activate(CommandBuffer cmd, PostProcessRenderContext context)
{
var shader = context.resources.computeShaders.sgsr2Upscaler.activate;
var shader = context.resources.computeShaders.sgsr2Upscaler.threePassCompute.activate;
int kernelIndex = shader.FindKernel("CS");
uint frameIndex = _frameCount % 2;
@ -122,7 +122,7 @@ namespace UnityEngine.Rendering.PostProcessing
private void Upscale(CommandBuffer cmd, PostProcessRenderContext context)
{
var shader = context.resources.computeShaders.sgsr2Upscaler.upscale;
var shader = context.resources.computeShaders.sgsr2Upscaler.threePassCompute.upscale;
int kernelIndex = shader.FindKernel("CS");
uint frameIndex = _frameCount % 2;

Loading…
Cancel
Save