浏览代码

Initial implementation of stochastic alpha test using TAA

/stochastic_alpha_test
Evgenii Golubev 7 年前
当前提交
4b498c82
共有 4 个文件被更改,包括 32 次插入1 次删除
  1. 13
      ScriptableRenderPipeline/HDRenderPipeline/Camera/HDCamera.cs
  2. 2
      ScriptableRenderPipeline/HDRenderPipeline/HDStringConstants.cs
  3. 14
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitData.hlsl
  4. 4
      ScriptableRenderPipeline/HDRenderPipeline/ShaderVariables.hlsl

13
ScriptableRenderPipeline/HDRenderPipeline/Camera/HDCamera.cs


// happen, but you never know...
int m_LastFrameActive;
int m_FrameID; // i % 2^24
int m_FrameID_TAA; // i % 8
static Dictionary<Camera, HDCamera> s_Cameras = new Dictionary<Camera, HDCamera>();
static List<Camera> s_Cleanup = new List<Camera>(); // Recycled to reduce GC pressure

}
m_LastFrameActive = Time.frameCount;
int k = Time.renderedFrameCount;
m_FrameID = k & ((1 << 24) - 1);
m_FrameID_TAA = k & 7;
}
public void Reset()

cmd.SetGlobalVector(HDShaderIDs._ScreenSize, screenSize);
cmd.SetGlobalMatrix(HDShaderIDs._PrevViewProjMatrix, prevViewProjMatrix);
cmd.SetGlobalVectorArray(HDShaderIDs._FrustumPlanes, frustumPlaneEquations);
cmd.SetGlobalFloat(HDShaderIDs._FrameID, m_FrameID); // TODO: SetGlobalInt()
cmd.SetGlobalFloat(HDShaderIDs._FrameID_TAA, m_FrameID_TAA); // TODO: SetGlobalInt()
}
// Does not modify global settings. Used for shadows, low res. rendering, etc.

material.SetVector(HDShaderIDs._ScreenSize, screenSize);
material.SetMatrix(HDShaderIDs._PrevViewProjMatrix, prevViewProjMatrix);
material.SetVectorArray(HDShaderIDs._FrustumPlanes, frustumPlaneEquations);
material.SetInt(HDShaderIDs._FrameID, m_FrameID);
material.SetInt(HDShaderIDs._FrameID_TAA, m_FrameID_TAA);
}
public void SetupComputeShader(ComputeShader cs, CommandBuffer cmd)

cmd.SetComputeVectorParam(cs, HDShaderIDs._ScreenParams, Shader.GetGlobalVector(HDShaderIDs._ScreenParams));
cmd.SetComputeVectorParam(cs, HDShaderIDs._ZBufferParams, Shader.GetGlobalVector(HDShaderIDs._ZBufferParams));
cmd.SetComputeVectorParam(cs, HDShaderIDs._WorldSpaceCameraPos, Shader.GetGlobalVector(HDShaderIDs._WorldSpaceCameraPos));
cmd.SetComputeIntParam(cs, HDShaderIDs._FrameID, m_FrameID);
cmd.SetComputeIntParam(cs, HDShaderIDs._FrameID_TAA, m_FrameID_TAA);
}
}
}

2
ScriptableRenderPipeline/HDRenderPipeline/HDStringConstants.cs


public static readonly int _ScreenSize = Shader.PropertyToID("_ScreenSize");
public static readonly int _PrevViewProjMatrix = Shader.PropertyToID("_PrevViewProjMatrix");
public static readonly int _FrustumPlanes = Shader.PropertyToID("_FrustumPlanes");
public static readonly int _FrameID = Shader.PropertyToID("_FrameID");
public static readonly int _FrameID_TAA = Shader.PropertyToID("_FrameID_TAA");
public static readonly int _DepthTexture = Shader.PropertyToID("_DepthTexture");
public static readonly int _CameraColorTexture = Shader.PropertyToID("_CameraColorTexture");

14
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitData.hlsl


#include "../../../Core/ShaderLibrary/SampleUVMapping.hlsl"
#include "../MaterialUtilities.hlsl"
float GetStochasticAlphaTestRefValue()
{
static const int r[] = {0, 4, 2, 6, 1, 5, 3, 7};
int i = _FrameID_TAA;
int n = 8; // TAA
int j = r[i];
return (j + 1) * rcp(n);
}
void DoAlphaTest(float alpha, float alphaCutoff)
{
// For Deferred:

#if ((SHADER_PASS == SHADERPASS_GBUFFER) && !defined(_BYPASS_ALPHA_TEST)) || (SHADER_PASS == SHADERPASS_FORWARD && defined(SURFACE_TYPE_TRANSPARENT))
clip(alpha - alphaCutoff);
//clip(alpha - alphaCutoff);
clip(alpha - GetStochasticAlphaTestRefValue());
#endif
}

4
ScriptableRenderPipeline/HDRenderPipeline/ShaderVariables.hlsl


float4 _InvProjParam;
float4 _ScreenSize; // (w, h, 1/w, 1/h)
float4 _FrustumPlanes[6]; // (N, -dot(N, P))
int _FrameID; // k % 2^24
int _FrameID_TAA; // k % 8
int _Pad128_0;
int _Pad128_1;
// Volumetric lighting. Should be a struct in 'UnityPerFrame'.
// Unfortunately, we cannot modify the layout of 'UnityPerFrame',

正在加载...
取消
保存