浏览代码

Check for out of bounds uv in ApplyDistortion

/stochastic_alpha_test
Frédéric Vauchelles 7 年前
当前提交
19a6004a
共有 1 个文件被更改,包括 21 次插入10 次删除
  1. 31
      ScriptableRenderPipeline/HDRenderPipeline/RenderPipelineResources/ApplyDistorsion.compute

31
ScriptableRenderPipeline/HDRenderPipeline/RenderPipelineResources/ApplyDistorsion.compute


bool distortionIsSourceValid;
DecodeDistortion(encodedDistortion, distortion, distortionBlur, distortionIsSourceValid);
uint2 distortedEncodedDistortionId = dispatchThreadId + int2(distortion);
// Reject the pixel if it is not in the distortion mask
if (!distortionIsSourceValid)
return;
int2 distortedEncodedDistortionId = dispatchThreadId + int2(distortion);
// Reject distortion if we try to fetch a pixel out of the buffer
if (any(distortedEncodedDistortionId < 0)
|| any(distortedEncodedDistortionId > int2(_Size.xy)))
return;
// We fetch a second time the _DistortionTexture for the at the distorded coordinate
// Then we check if this pixels is in the distorded mask (eg: behind any distorted object)
// Otherwise we reject the distortion
float2 distordedDistortion;
float distordedDistortionBlur;
bool distordedIsSourceValid;

// We apply distortion only if both this pixel and source pixel are behind any distortion object
if (distortionIsSourceValid && distordedIsSourceValid)
{
// Get source pixel for distortion
float2 distordedUV = float2(dispatchThreadId + int2(distortion * _FetchBias)) * _Size.zw;
float mip = (_GaussianPyramidColorMipSize.z - 1) * clamp(distortionBlur, 0.0, 1.0);
float4 sampled = SAMPLE_TEXTURE2D_LOD(_GaussianPyramidColorTexture, sampler_GaussianPyramidColorTexture, distordedUV, mip);
if (!distordedIsSourceValid)
return;
// Get source pixel for distortion
float2 distordedUV = float2(dispatchThreadId + int2(distortion * _FetchBias)) * _Size.zw;
float mip = (_GaussianPyramidColorMipSize.z - 1) * clamp(distortionBlur, 0.0, 1.0);
float4 sampled = SAMPLE_TEXTURE2D_LOD(_GaussianPyramidColorTexture, sampler_GaussianPyramidColorTexture, distordedUV, mip);
_CameraColorTexture[dispatchThreadId] = sampled;
}
_CameraColorTexture[dispatchThreadId] = sampled;
}
正在加载...
取消
保存