-
Notifications
You must be signed in to change notification settings - Fork 9
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
82 changed files
with
5,392 additions
and
0 deletions.
There are no files selected for viewing
Git LFS file not shown
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,22 @@ | ||
{ | ||
"name": "Infinity.Render.Runtime", | ||
"references": [ | ||
"Unity.Mathematics", | ||
"Unity.Postprocessing.Runtime" | ||
], | ||
"includePlatforms": [], | ||
"excludePlatforms": [], | ||
"allowUnsafeCode": true, | ||
"overrideReferences": false, | ||
"precompiledReferences": [], | ||
"autoReferenced": true, | ||
"defineConstraints": [], | ||
"versionDefines": [ | ||
{ | ||
"name": "com.infinity.render", | ||
"expression": "0.0.0", | ||
"define": "InfinityRenderRuntime" | ||
} | ||
], | ||
"noEngineReferences": false | ||
} |
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
Runtime/RenderFeature/PyramidColorGenerator/Resources/Shaders.meta
Git LFS file not shown
126 changes: 126 additions & 0 deletions
126
...me/RenderFeature/PyramidColorGenerator/Resources/Shaders/GaussianDownsampleShader.compute
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,126 @@ | ||
float4 _Size; | ||
Texture2D<float4> _Source; | ||
RWTexture2D<float4> _Result; | ||
SamplerState sampler_LinearClamp; | ||
|
||
// 16x16 pixels with an 8x8 center that we will be blurring writing out. Each uint is two color | ||
// channels packed together. | ||
// The reason for separating channels is to reduce bank conflicts in the local data memory | ||
// controller. A large stride will cause more threads to collide on the same memory bank. | ||
groupshared uint gs_cacheR[128]; | ||
groupshared uint gs_cacheG[128]; | ||
groupshared uint gs_cacheB[128]; | ||
groupshared uint gs_cacheA[128]; | ||
|
||
float4 BlurPixels(float4 a, float4 b, float4 c, float4 d, float4 e, float4 f, float4 g, float4 h, float4 i) | ||
{ | ||
return 0.27343750 * (e ) | ||
+ 0.21875000 * (d + f) | ||
+ 0.10937500 * (c + g) | ||
+ 0.03125000 * (b + h) | ||
+ 0.00390625 * (a + i); | ||
} | ||
|
||
void Store2Pixels(uint index, float4 pixel1, float4 pixel2) | ||
{ | ||
gs_cacheR[index] = f32tof16(pixel1.r) | f32tof16(pixel2.r) << 16; | ||
gs_cacheG[index] = f32tof16(pixel1.g) | f32tof16(pixel2.g) << 16; | ||
gs_cacheB[index] = f32tof16(pixel1.b) | f32tof16(pixel2.b) << 16; | ||
gs_cacheA[index] = f32tof16(pixel1.a) | f32tof16(pixel2.a) << 16; | ||
} | ||
|
||
void Load2Pixels(uint index, out float4 pixel1, out float4 pixel2) | ||
{ | ||
uint rr = gs_cacheR[index]; | ||
uint gg = gs_cacheG[index]; | ||
uint bb = gs_cacheB[index]; | ||
uint aa = gs_cacheA[index]; | ||
pixel1 = float4(f16tof32(rr ), f16tof32(gg ), f16tof32(bb ), f16tof32(aa )); | ||
pixel2 = float4(f16tof32(rr >> 16), f16tof32(gg >> 16), f16tof32(bb >> 16), f16tof32(aa >> 16)); | ||
} | ||
|
||
void Store1Pixel(uint index, float4 pixel) | ||
{ | ||
gs_cacheR[index] = asuint(pixel.r); | ||
gs_cacheG[index] = asuint(pixel.g); | ||
gs_cacheB[index] = asuint(pixel.b); | ||
gs_cacheA[index] = asuint(pixel.a); | ||
} | ||
|
||
void Load1Pixel(uint index, out float4 pixel) | ||
{ | ||
pixel = asfloat(uint4(gs_cacheR[index], gs_cacheG[index], gs_cacheB[index], gs_cacheA[index])); | ||
} | ||
|
||
// Blur two pixels horizontally. This reduces LDS reads and pixel unpacking. | ||
void BlurHorizontally(uint outIndex, uint leftMostIndex) | ||
{ | ||
float4 s0, s1, s2, s3, s4, s5, s6, s7, s8, s9; | ||
Load2Pixels(leftMostIndex + 0, s0, s1); | ||
Load2Pixels(leftMostIndex + 1, s2, s3); | ||
Load2Pixels(leftMostIndex + 2, s4, s5); | ||
Load2Pixels(leftMostIndex + 3, s6, s7); | ||
Load2Pixels(leftMostIndex + 4, s8, s9); | ||
|
||
Store1Pixel(outIndex , BlurPixels(s0, s1, s2, s3, s4, s5, s6, s7, s8)); | ||
Store1Pixel(outIndex + 1, BlurPixels(s1, s2, s3, s4, s5, s6, s7, s8, s9)); | ||
} | ||
|
||
void BlurVertically(uint2 pixelCoord, uint topMostIndex) | ||
{ | ||
float4 s0, s1, s2, s3, s4, s5, s6, s7, s8; | ||
Load1Pixel(topMostIndex , s0); | ||
Load1Pixel(topMostIndex + 8, s1); | ||
Load1Pixel(topMostIndex + 16, s2); | ||
Load1Pixel(topMostIndex + 24, s3); | ||
Load1Pixel(topMostIndex + 32, s4); | ||
Load1Pixel(topMostIndex + 40, s5); | ||
Load1Pixel(topMostIndex + 48, s6); | ||
Load1Pixel(topMostIndex + 56, s7); | ||
Load1Pixel(topMostIndex + 64, s8); | ||
|
||
float4 blurred = BlurPixels(s0, s1, s2, s3, s4, s5, s6, s7, s8); | ||
|
||
// Write to the final target | ||
_Result[pixelCoord] = blurred; | ||
} | ||
|
||
#pragma kernel KMain | ||
|
||
#ifdef DISABLE_COMPUTE_SHADERS | ||
|
||
TRIVIAL_COMPUTE_KERNEL(KMain) | ||
|
||
#else | ||
|
||
[numthreads(8, 8, 1)] | ||
void KMain(uint2 groupId : SV_GroupID, uint2 groupThreadId : SV_GroupThreadID, uint2 dispatchThreadId : SV_DispatchThreadID) | ||
{ | ||
// Upper-left pixel coordinate of quad that this thread will read | ||
int2 threadUL = (groupThreadId << 1) + (groupId << 3) - 4; | ||
|
||
// Downsample the block | ||
float2 offset = float2(threadUL); | ||
float4 p00 = _Source.SampleLevel(sampler_LinearClamp, (offset + 0.5) * _Size.zw, 0.0); | ||
float4 p10 = _Source.SampleLevel(sampler_LinearClamp, (offset + float2(1.0, 0.0) + 0.5) * _Size.zw, 0.0); | ||
float4 p01 = _Source.SampleLevel(sampler_LinearClamp, (offset + float2(0.0, 1.0) + 0.5) * _Size.zw, 0.0); | ||
float4 p11 = _Source.SampleLevel(sampler_LinearClamp, (offset + float2(1.0, 1.0) + 0.5) * _Size.zw, 0.0); | ||
|
||
// Store the 4 downsampled pixels in LDS | ||
uint destIdx = groupThreadId.x + (groupThreadId.y << 4u); | ||
Store2Pixels(destIdx , p00, p10); | ||
Store2Pixels(destIdx + 8u, p01, p11); | ||
|
||
GroupMemoryBarrierWithGroupSync(); | ||
|
||
// Horizontally blur the pixels in LDS | ||
uint row = groupThreadId.y << 4u; | ||
BlurHorizontally(row + (groupThreadId.x << 1u), row + groupThreadId.x + (groupThreadId.x & 4u)); | ||
|
||
GroupMemoryBarrierWithGroupSync(); | ||
|
||
// Vertically blur the pixels in LDS and write the result to memory | ||
BlurVertically(dispatchThreadId, (groupThreadId.y << 3u) + groupThreadId.x); | ||
} | ||
|
||
#endif // DISABLE_COMPUTE_SHADERS |
3 changes: 3 additions & 0 deletions
3
...nderFeature/PyramidColorGenerator/Resources/Shaders/GaussianDownsampleShader.compute.meta
Git LFS file not shown
Git LFS file not shown
58 changes: 58 additions & 0 deletions
58
Runtime/RenderFeature/PyramidColorGenerator/Script/PyramidColorGenerator.cs
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,58 @@ | ||
using UnityEngine; | ||
using Unity.Mathematics; | ||
using UnityEngine.Rendering; | ||
|
||
namespace InfinityTech.Runtime.Rendering.Feature | ||
{ | ||
public static class PyramidColorUniform | ||
{ | ||
public static int PrevLevelColor = Shader.PropertyToID("_Source"); | ||
public static int CurrLevelColor = Shader.PropertyToID("_Result"); | ||
public static int PrevCurr_Size = Shader.PropertyToID("_Size"); | ||
public static int ColorPyramidNumLOD = Shader.PropertyToID("ColorPyramidNumLOD"); | ||
} | ||
|
||
public static class PyramidColorGenerator | ||
{ | ||
private static ComputeShader PyramidColorShader { | ||
get { | ||
return Resources.Load<ComputeShader>("Shaders/GaussianDownsampleShader"); | ||
} | ||
} | ||
|
||
public static void ColorPyramidInit(ref int[] ColorPyramidMipIDs) | ||
{ | ||
if (ColorPyramidMipIDs == null || ColorPyramidMipIDs.Length == 0) { | ||
ColorPyramidMipIDs = new int[12]; | ||
|
||
for (int i = 0; i < 12; i++) { | ||
ColorPyramidMipIDs[i] = Shader.PropertyToID("_SSSRGaussianMip" + i); | ||
} | ||
} | ||
} | ||
|
||
public static void ColorPyramidUpdate(ref int[] ColorPyramidMipIDs, ref int2 ScreenSize, RenderTargetIdentifier DstRT , CommandBuffer CmdBuffer) | ||
{ | ||
int ColorPyramidCount = Mathf.FloorToInt(Mathf.Log(ScreenSize.x, 2) - 3); | ||
ColorPyramidCount = Mathf.Min(ColorPyramidCount, 12); | ||
CmdBuffer.SetGlobalFloat(PyramidColorUniform.ColorPyramidNumLOD, (float)ColorPyramidCount); | ||
RenderTargetIdentifier PrevColorPyramid = DstRT; | ||
int2 ColorPyramidSize = ScreenSize; | ||
for (int i = 0; i < ColorPyramidCount; i++) { | ||
ColorPyramidSize.x >>= 1; | ||
ColorPyramidSize.y >>= 1; | ||
|
||
CmdBuffer.GetTemporaryRT(ColorPyramidMipIDs[i], ColorPyramidSize.x, ColorPyramidSize.y, 0, FilterMode.Bilinear, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Default, 1, true); | ||
CmdBuffer.SetComputeTextureParam(PyramidColorShader, 0, PyramidColorUniform.PrevLevelColor, PrevColorPyramid); | ||
CmdBuffer.SetComputeTextureParam(PyramidColorShader, 0, PyramidColorUniform.CurrLevelColor, ColorPyramidMipIDs[i]); | ||
CmdBuffer.SetComputeVectorParam(PyramidColorShader, PyramidColorUniform.PrevCurr_Size, new float4(ColorPyramidSize.x, ColorPyramidSize.y, 1f / ColorPyramidSize.x, 1f / ColorPyramidSize.y)); | ||
CmdBuffer.DispatchCompute(PyramidColorShader, 0, Mathf.CeilToInt(ColorPyramidSize.x / 8f), Mathf.CeilToInt(ColorPyramidSize.y / 8f), 1); | ||
CmdBuffer.CopyTexture(ColorPyramidMipIDs[i], 0, 0, DstRT, 0, i + 1); | ||
|
||
PrevColorPyramid = ColorPyramidMipIDs[i]; | ||
} for (int i = 0; i < ColorPyramidCount; i++) { | ||
CmdBuffer.ReleaseTemporaryRT(ColorPyramidMipIDs[i]); | ||
} | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Runtime/RenderFeature/PyramidColorGenerator/Script/PyramidColorGenerator.cs.meta
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
Runtime/RenderFeature/PyramidDepthGenerator/Resources/Shaders.meta
Git LFS file not shown
27 changes: 27 additions & 0 deletions
27
Runtime/RenderFeature/PyramidDepthGenerator/Resources/Shaders/HierarchicalZ_Shader.compute
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,27 @@ | ||
#pragma kernel HiZ_Generation | ||
|
||
float4 _PrevCurr_Inverse_Size; | ||
Texture2D<float> _PrevMipDepth; SamplerState sampler_PrevMipDepth; | ||
RWTexture2D<float> _HierarchicalDepth; | ||
|
||
[numthreads(8, 8, 1)] | ||
void HiZ_Generation (uint3 id : SV_DispatchThreadID) | ||
{ | ||
float2 uv = (id.xy + 0.5) * _PrevCurr_Inverse_Size.xy; | ||
float FinalMinZ = _PrevMipDepth.SampleLevel(sampler_PrevMipDepth, uv, 0); | ||
|
||
/*FinalMinZ = max( FinalMinZ, _PrevMipDepth.SampleLevel(sampler_PrevMipDepth, uv + int2( 1, 0) * _PrevCurr_Inverse_Size.zw, 0) ); | ||
FinalMinZ = max( FinalMinZ, _PrevMipDepth.SampleLevel(sampler_PrevMipDepth, uv + int2(-1, 0) * _PrevCurr_Inverse_Size.zw, 0) ); | ||
FinalMinZ = max( FinalMinZ, _PrevMipDepth.SampleLevel(sampler_PrevMipDepth, uv + int2( 0, 1) * _PrevCurr_Inverse_Size.zw, 0) ); | ||
FinalMinZ = max( FinalMinZ, _PrevMipDepth.SampleLevel(sampler_PrevMipDepth, uv + int2( 0, -1) * _PrevCurr_Inverse_Size.zw, 0) ); | ||
FinalMinZ = max( FinalMinZ, _PrevMipDepth.SampleLevel(sampler_PrevMipDepth, uv + int2( 1, 1) * _PrevCurr_Inverse_Size.zw, 0) ); | ||
FinalMinZ = max( FinalMinZ, _PrevMipDepth.SampleLevel(sampler_PrevMipDepth, uv + int2(-1, 1) * _PrevCurr_Inverse_Size.zw, 0) ); | ||
FinalMinZ = max( FinalMinZ, _PrevMipDepth.SampleLevel(sampler_PrevMipDepth, uv + int2( 1, -1) * _PrevCurr_Inverse_Size.zw, 0) ); | ||
FinalMinZ = max( FinalMinZ, _PrevMipDepth.SampleLevel(sampler_PrevMipDepth, uv + int2(-1, -1) * _PrevCurr_Inverse_Size.zw, 0) );*/ | ||
|
||
FinalMinZ = max(FinalMinZ, _PrevMipDepth.SampleLevel(sampler_PrevMipDepth, uv + int2(0, -1) * _PrevCurr_Inverse_Size.zw, 0)); | ||
FinalMinZ = max(FinalMinZ, _PrevMipDepth.SampleLevel(sampler_PrevMipDepth, uv + int2(-1, 0) * _PrevCurr_Inverse_Size.zw, 0)); | ||
FinalMinZ = max(FinalMinZ, _PrevMipDepth.SampleLevel(sampler_PrevMipDepth, uv + int2(-1, -1) * _PrevCurr_Inverse_Size.zw, 0)); | ||
|
||
_HierarchicalDepth[id.xy] = FinalMinZ; | ||
} |
3 changes: 3 additions & 0 deletions
3
...e/RenderFeature/PyramidDepthGenerator/Resources/Shaders/HierarchicalZ_Shader.compute.meta
Git LFS file not shown
Git LFS file not shown
58 changes: 58 additions & 0 deletions
58
Runtime/RenderFeature/PyramidDepthGenerator/Script/PyramidDepthGenerator.cs
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,58 @@ | ||
using UnityEngine; | ||
using Unity.Mathematics; | ||
using UnityEngine.Rendering; | ||
|
||
namespace InfinityTech.Runtime.Rendering.Feature | ||
{ | ||
public static class PyramidDepthUniform | ||
{ | ||
public static int PrevMipDepth = Shader.PropertyToID("_PrevMipDepth"); | ||
public static int HierarchicalDepth = Shader.PropertyToID("_HierarchicalDepth"); | ||
public static int PrevCurr_InvSize = Shader.PropertyToID("_PrevCurr_Inverse_Size"); | ||
} | ||
|
||
public static class PyramidDepthGenerator | ||
{ | ||
private static int MipCount = 9; | ||
|
||
private static ComputeShader PyramidDeptShader { | ||
get { | ||
return Resources.Load<ComputeShader>("Shaders/HierarchicalZ_Shader"); | ||
} | ||
} | ||
|
||
public static void DepthPyramidInit(ref int[] DepthPyramidMipIDs) | ||
{ | ||
if (DepthPyramidMipIDs == null || DepthPyramidMipIDs.Length == 0) { | ||
DepthPyramidMipIDs = new int[MipCount]; | ||
|
||
for (int i = 0; i < MipCount; i++) { | ||
DepthPyramidMipIDs[i] = Shader.PropertyToID("_SSSRDepthMip" + i); | ||
} | ||
} | ||
} | ||
|
||
public static void DepthPyramidUpdate(ref int[] DepthPyramidMipIDs, ref int2 ScreenSize, RenderTargetIdentifier DstRT, CommandBuffer CmdBuffer) { | ||
int2 HiZPyramidSize = ScreenSize; | ||
int2 PrevHiZPyramidSize = ScreenSize; | ||
RenderTargetIdentifier PrevHiZPyramid = DstRT; | ||
|
||
for (int i = 0; i < MipCount; i++) { | ||
HiZPyramidSize.x /= 2; | ||
HiZPyramidSize.y /= 2; | ||
|
||
CmdBuffer.GetTemporaryRT(DepthPyramidMipIDs[i], HiZPyramidSize.x, HiZPyramidSize.y, 0, FilterMode.Point, RenderTextureFormat.RHalf, RenderTextureReadWrite.Default, 1, true); | ||
CmdBuffer.SetComputeTextureParam(PyramidDeptShader, 0, PyramidDepthUniform.PrevMipDepth, PrevHiZPyramid); | ||
CmdBuffer.SetComputeTextureParam(PyramidDeptShader, 0, PyramidDepthUniform.HierarchicalDepth, DepthPyramidMipIDs[i]); | ||
CmdBuffer.SetComputeVectorParam(PyramidDeptShader, PyramidDepthUniform.PrevCurr_InvSize, new float4(1.0f / HiZPyramidSize.x, 1.0f / HiZPyramidSize.y, 1.0f / PrevHiZPyramidSize.x, 1.0f / PrevHiZPyramidSize.y)); | ||
CmdBuffer.DispatchCompute(PyramidDeptShader, 0, Mathf.CeilToInt(HiZPyramidSize.x / 8.0f), Mathf.CeilToInt(HiZPyramidSize.y / 8.0f), 1); | ||
CmdBuffer.CopyTexture(DepthPyramidMipIDs[i], 0, 0, DstRT, 0, i + 1); | ||
|
||
PrevHiZPyramid = DepthPyramidMipIDs[i]; | ||
PrevHiZPyramidSize = HiZPyramidSize; | ||
} for (int i = 0; i < MipCount; i++) { | ||
CmdBuffer.ReleaseTemporaryRT(DepthPyramidMipIDs[i]); | ||
} | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Runtime/RenderFeature/PyramidDepthGenerator/Script/PyramidDepthGenerator.cs.meta
Git LFS file not shown
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
Runtime/RenderFeature/ScreenSpaceGlobalIllumination/Resources.meta
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
Runtime/RenderFeature/ScreenSpaceGlobalIllumination/Resources/Shaders.meta
Git LFS file not shown
Oops, something went wrong.