浏览代码

Write depth in distortion pass and ztest to discard pixel in front of distorted object

/stochastic_alpha_test
Frédéric Vauchelles 7 年前
当前提交
9bf881d7
共有 5 个文件被更改,包括 17 次插入13 次删除
  1. 19
      ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs
  2. 1
      ScriptableRenderPipeline/HDRenderPipeline/HDStringConstants.cs
  3. 2
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.shader
  4. 2
      ScriptableRenderPipeline/HDRenderPipeline/Material/Unlit/Unlit.shader
  5. 6
      ScriptableRenderPipeline/HDRenderPipeline/RenderPipelineResources/ApplyDistorsion.compute

19
ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs


// <<< Old SSS Model
readonly int m_VelocityBuffer;
readonly int m_DistortionBuffer;
readonly int m_DistortionDepthBuffer;
readonly int m_GaussianPyramidColorBuffer;
readonly int m_DepthPyramidBuffer;

// <<< Old SSS Model
readonly RenderTargetIdentifier m_VelocityBufferRT;
readonly RenderTargetIdentifier m_DistortionBufferRT;
readonly RenderTargetIdentifier m_DistortionDepthBufferRT;
readonly RenderTargetIdentifier m_GaussianPyramidColorBufferRT;
readonly RenderTargetIdentifier m_DepthPyramidBufferRT;
RenderTextureDescriptor m_GaussianPyramidColorBufferDesc;

m_DistortionBuffer = HDShaderIDs._DistortionTexture;
m_DistortionBufferRT = new RenderTargetIdentifier(m_DistortionBuffer);
m_DistortionDepthBuffer = HDShaderIDs._DistortionDepthTexture;
m_DistortionDepthBufferRT = new RenderTargetIdentifier(m_DistortionDepthBuffer);
m_GaussianPyramidKernel = m_GaussianPyramidCS.FindKernel("KMain");
m_GaussianPyramidColorBuffer = HDShaderIDs._GaussianPyramidColorTexture;

renderContext.DrawRenderers(cull.visibleRenderers, ref drawSettings, filterSettings, stateBlock.Value);
}
/// <summary>
/// Distortion is resolved in two steps:
/// - AccumulateDistortion is a pass that
/// 1. Accumulate distortion vectors (add)
/// 2. Accumulate smoothness (max)
/// 3. Mark in DistortionBuffer pixel eligible as source for distortion
/// 4. Mark in stencil buffer pixel eligible to be distorted
/// - RenderDistortion is a pass that distort eligible pixels with eligible sources with a specified smoothness
/// </summary>
void AccumulateDistortion(CullResults cullResults, Camera camera, ScriptableRenderContext renderContext, CommandBuffer cmd)
{
if (!m_CurrentDebugDisplaySettings.renderingDebugSettings.enableDistortion)

int w = camera.pixelWidth;
int h = camera.pixelHeight;
cmd.GetTemporaryRT(m_DistortionDepthBuffer, w, h, 24, FilterMode.Point, RenderTextureFormat.Depth, RenderTextureReadWrite.Linear);
cmd.SetRenderTarget(m_DistortionBufferRT, m_CameraDepthStencilBufferRT);
cmd.ClearRenderTarget(false, true, Color.clear);
cmd.SetRenderTarget(m_DistortionBufferRT, m_DistortionDepthBufferRT);
cmd.ClearRenderTarget(true, true, Color.clear);
// Only transparent object can render distortion vectors
RenderTransparentRenderList(cullResults, camera, renderContext, cmd, HDShaderPassNames.s_DistortionVectorsName);

uint x, y, z;
resources.applyDistortionCS.GetKernelThreadGroupSizes(resources.applyDistortionKernel, out x, out y, out z);
cmd.SetComputeTextureParam(resources.applyDistortionCS, resources.applyDistortionKernel, HDShaderIDs._DistortionTexture, m_DistortionBufferRT);
cmd.SetComputeTextureParam(resources.applyDistortionCS, resources.applyDistortionKernel, HDShaderIDs._DistortionDepthTexture, m_DistortionDepthBufferRT);
cmd.SetComputeTextureParam(resources.applyDistortionCS, resources.applyDistortionKernel, HDShaderIDs._GaussianPyramidColorTexture, m_GaussianPyramidColorBufferRT);
cmd.SetComputeTextureParam(resources.applyDistortionCS, resources.applyDistortionKernel, HDShaderIDs._CameraColorTexture, m_CameraColorBufferRT);
cmd.SetComputeTextureParam(resources.applyDistortionCS, resources.applyDistortionKernel, HDShaderIDs._DepthTexture, GetDepthTexture());

1
ScriptableRenderPipeline/HDRenderPipeline/HDStringConstants.cs


public static readonly int _VelocityTexture = Shader.PropertyToID("_VelocityTexture");
public static readonly int _DistortionTexture = Shader.PropertyToID("_DistortionTexture");
public static readonly int _DistortionDepthTexture = Shader.PropertyToID("_DistortionDepthTexture");
public static readonly int _GaussianPyramidColorTexture = Shader.PropertyToID("_GaussianPyramidColorTexture");
public static readonly int _DepthPyramidTexture = Shader.PropertyToID("_PyramidDepthTexture");
public static readonly int _GaussianPyramidColorMipSize = Shader.PropertyToID("_GaussianPyramidColorMipSize");

2
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.shader


Blend [_DistortionSrcBlend] [_DistortionDstBlend], [_DistortionBlurSrcBlend] [_DistortionBlurDstBlend]
BlendOp Add, [_DistortionBlurBlendOp]
ZTest [_ZTestMode]
ZWrite off
ZWrite on
Cull [_CullMode]
HLSLPROGRAM

2
ScriptableRenderPipeline/HDRenderPipeline/Material/Unlit/Unlit.shader


Blend [_DistortionSrcBlend] [_DistortionDstBlend], [_DistortionBlurSrcBlend] [_DistortionBlurDstBlend]
BlendOp Add, [_DistortionBlurBlendOp]
ZTest [_ZTestMode]
ZWrite off
ZWrite on
Cull [_CullMode]
HLSLPROGRAM

6
ScriptableRenderPipeline/HDRenderPipeline/RenderPipelineResources/ApplyDistorsion.compute


TEXTURE2D(_DepthTexture);
TEXTURE2D(_DistortionTexture);
TEXTURE2D(_DistortionDepthTexture);
TEXTURE2D(_GaussianPyramidColorTexture);
RW_TEXTURE2D(float4, _CameraColorTexture);

// Get distortion values
float4 encodedDistortion = LOAD_TEXTURE2D(_DistortionTexture, dispatchThreadId);
float depthRaw = LOAD_TEXTURE2D(_DistortionDepthTexture, dispatchThreadId).r;
float2 distortion;
float2 distortionBlur;

float2 distordedDistortion;
float2 distordedDistortionBlur;
float4 encodedDistordedDistortion = LOAD_TEXTURE2D(_DistortionTexture, distortedEncodedDistortionId);
float distordedDepthRaw = LOAD_TEXTURE2D(_DepthTexture, distortedEncodedDistortionId).r;
if (distordedDepthRaw > depthRaw)
return;
// Get source pixel for distortion
float2 distordedUV = float2(dispatchThreadId + int2(distortion * _FetchBias)) * _Size.zw;

正在加载...
取消
保存