浏览代码

Add sphere-packed offsets in XY

/Yibing-Project-2
Evgenii Golubev 7 年前
当前提交
97ac113b
共有 3 个文件被更改,包括 47 次插入10 次删除
  1. 2
      ScriptableRenderPipeline/HDRenderPipeline/HDStringConstants.cs
  2. 6
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/Volumetrics/Resources/VolumetricLighting.compute
  3. 49
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/Volumetrics/VolumetricLighting.cs

2
ScriptableRenderPipeline/HDRenderPipeline/HDStringConstants.cs


public static readonly int _VBufferLightingIntegral = Shader.PropertyToID("_VBufferLightingIntegral");
public static readonly int _VBufferLightingHistory = Shader.PropertyToID("_VBufferLightingHistory");
public static readonly int _VBufferLightingFeedback = Shader.PropertyToID("_VBufferLightingFeedback");
public static readonly int _VBufferIntegrationOffset = Shader.PropertyToID("_VBufferIntegrationOffset");
public static readonly int _VBufferSampleOffset = Shader.PropertyToID("_VBufferSampleOffset");
}
}

6
ScriptableRenderPipeline/HDRenderPipeline/Lighting/Volumetrics/Resources/VolumetricLighting.compute


// TODO: avoid creating another Constant Buffer...
CBUFFER_START(UnityVolumetricLighting)
float4 _VBufferSampleOffset; // {x, y, z}, w = unused
float4 _VBufferIntegrationOffset; // {x, y, z}, w = unused
CBUFFER_END
//--------------------------------------------------------------------------------------------------

#if ENABLE_REPROJECTION
// This is a sequence of 7 equidistant numbers from 1/14 to 13/14.
// Each of them is the centroid of the interval of length 2/14.
float rndVal = _VBufferIntegrationOffset.z;
float rndVal = _VBufferSampleOffset.z;
#else
float rndVal = 0.5;
#endif

float2 centerCoord = voxelCoord + 0.5;
#if ENABLE_REPROJECTION
float2 sampleCoord = voxelCoord + _VBufferIntegrationOffset.xy;
float2 sampleCoord = centerCoord + _VBufferSampleOffset.xy;
#else
float2 sampleCoord = centerCoord;
#endif

49
ScriptableRenderPipeline/HDRenderPipeline/Lighting/Volumetrics/VolumetricLighting.cs


cmd.SetGlobalTexture(HDShaderIDs._VBufferLighting, GetVBufferLightingIntegral());
}
// Ref: https://en.wikipedia.org/wiki/Close-packing_of_equal_spheres
// The returned {x, y} coordinates (all spheres) are all within the (-0.5, 0.5)^2 range.
Vector2[] GetHexagonalClosePackedSpheres7()
{
Vector2[] coords = new Vector2[7];
// The width is 3 spheres, so 6 radii.
float r = 1.0f / 6.0f;
float d = 2 * r;
float s = r * Mathf.Sqrt(3);
// (7)(5) ( )( ) ( )( ) ( )( ) ( )( ) ( )(o) ( )(x) (o)(x) (x)(x)
// (2)(1)(3) ( )(o)( ) (o)(x)( ) (x)(x)(o) (x)(x)(x) (x)(x)(x) (x)(x)(x) (x)(x)(x) (x)(x)(x)
// (4)(6) ( )( ) ( )( ) ( )( ) (o)( ) (x)( ) (x)(o) (x)(x) (x)(x)
coords[0] = new Vector2( 0, 0);
coords[1] = new Vector2(-d, 0);
coords[2] = new Vector2( d, 0);
coords[3] = new Vector2(-r, -s);
coords[4] = new Vector2( r, s);
coords[5] = new Vector2( r, -s);
coords[6] = new Vector2(-r, s);
return coords;
}
void VolumetricLightingPass(HDCamera camera, CommandBuffer cmd)
{
if (m_VolumetricLightingPreset == VolumetricLightingPreset.Off) return;

camera.SetupComputeShader(m_VolumetricLightingCS, cmd);
Vector2[] xySeq = GetHexagonalClosePackedSpheres7();
float[] seq = {7.0f/14.0f, 3.0f/14.0f, 11.0f/14.0f, 5.0f/14.0f, 9.0f/14.0f, 1.0f/14.0f, 13.0f/14.0f};
// | 6 | 2 | 4 | 1 | 5 | 3 | 7 |
// | | | | o | | | |
// | | o | | x | | | |
// | | x | | x | | o | |
// | | x | o | x | | x | |
// | | x | x | x | o | x | |
// | o | x | x | x | x | x | |
// | x | x | x | x | x | x | o |
// | x | x | x | x | x | x | x |
float[] zSeq = {7.0f/14.0f, 3.0f/14.0f, 11.0f/14.0f, 5.0f/14.0f, 9.0f/14.0f, 1.0f/14.0f, 13.0f/14.0f};
Vector4 offset = new Vector4(xySeq[sampleIndex].x, xySeq[sampleIndex].y, zSeq[sampleIndex]);
cmd.SetComputeMatrixParam( m_VolumetricLightingCS, HDShaderIDs._VBufferCoordToViewDirWS, transform);
cmd.SetComputeVectorParam( m_VolumetricLightingCS, HDShaderIDs._VBufferIntegrationOffset, new Vector4(0.0f, 0.0f, seq[sampleIndex]));
cmd.SetComputeTextureParam(m_VolumetricLightingCS, kernel, HDShaderIDs._VBufferLightingHistory, GetVBufferLightingHistory()); // Read
cmd.SetComputeTextureParam(m_VolumetricLightingCS, kernel, HDShaderIDs._VBufferLightingFeedback, GetVBufferLightingFeedback()); // Write
cmd.SetComputeTextureParam(m_VolumetricLightingCS, kernel, HDShaderIDs._VBufferLightingIntegral, GetVBufferLightingIntegral()); // Write
cmd.SetComputeVectorParam( m_VolumetricLightingCS, HDShaderIDs._VBufferSampleOffset, offset);
cmd.SetComputeMatrixParam( m_VolumetricLightingCS, HDShaderIDs._VBufferCoordToViewDirWS, transform);
cmd.SetComputeTextureParam(m_VolumetricLightingCS, kernel, HDShaderIDs._VBufferLightingHistory, GetVBufferLightingHistory()); // Read
cmd.SetComputeTextureParam(m_VolumetricLightingCS, kernel, HDShaderIDs._VBufferLightingFeedback, GetVBufferLightingFeedback()); // Write
cmd.SetComputeTextureParam(m_VolumetricLightingCS, kernel, HDShaderIDs._VBufferLightingIntegral, GetVBufferLightingIntegral()); // Write
// The shader defines GROUP_SIZE_1D = 16.
cmd.DispatchCompute(m_VolumetricLightingCS, kernel, (w + 15) / 16, (h + 15) / 16, 1);

正在加载...
取消
保存