浏览代码

Stop NaN propagation within volumetric lighting shader (v2)

/hdrp-staging
Evgenii Golubev 6 年前
当前提交
bee9896f
共有 4 个文件被更改,包括 42 次插入19 次删除
  1. 9
      com.unity.render-pipelines.high-definition/HDRP/Lighting/Volumetrics/VolumeVoxelization.compute
  2. 12
      com.unity.render-pipelines.high-definition/HDRP/Lighting/Volumetrics/VolumetricLighting.compute
  3. 33
      com.unity.render-pipelines.high-definition/HDRP/Lighting/Volumetrics/VolumetricLighting.cs
  4. 7
      com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/HDStringConstants.cs

9
com.unity.render-pipelines.high-definition/HDRP/Lighting/Volumetrics/VolumeVoxelization.compute


// TODO: avoid creating another Constant Buffer...
CBUFFER_START(UnityVolumetricLighting)
float4x4 _VBufferCoordToViewDirWS; // Actually just 3x3, but Unity can only set 4x4
float4 _VBufferSampleOffset; // Not used by this shader
float _CornetteShanksConstant; // Not used by this shader
float4x4 _VBufferCoordToViewDirWS; // Actually just 3x3, but Unity can only set 4x4
float4 _VBufferSampleOffset; // Not used by this shader
float4 _VolumeMaskDimensions; // x = 1/numTextures , y = width, z = depth = width * numTextures, w = maxLod
float4 _VolumeMaskDimensions; //x = 1/numTextures , y = width, z = depth = width * numTextures, w = maxLod
float _CornetteShanksConstant; // Not used by this shader
uint _VBufferLightingHistoryIsValid; // Not used by this shader
CBUFFER_END
//--------------------------------------------------------------------------------------------------

12
com.unity.render-pipelines.high-definition/HDRP/Lighting/Volumetrics/VolumetricLighting.compute


// TODO: avoid creating another Constant Buffer...
CBUFFER_START(UnityVolumetricLighting)
float4x4 _VBufferCoordToViewDirWS; // Actually just 3x3, but Unity can only set 4x4
float4 _VBufferSampleOffset; // Not used by this shader
float _CornetteShanksConstant; // Not used by this shader
uint _NumVisibleDensityVolumes;
float4 _VBufferSampleOffset;
float4 _VolumeMaskDimensions; // Not used by this shader
uint _NumVisibleDensityVolumes; // Not used by this shader
float _CornetteShanksConstant;
uint _VBufferLightingHistoryIsValid;
CBUFFER_END
//--------------------------------------------------------------------------------------------------

float3 blendedRadiance = lighting.radianceNoPhase;
// Uninitialized history texture may contain NaNs.
// TODO: clear the texture after creating it. Clearing 3D textures is broken in Unity. :-(
bool reprojSuccess = (reprojValue.a != 0) && !isnan(reprojValue.a);
bool reprojSuccess = (_VBufferLightingHistoryIsValid != 0) && (reprojValue.a != 0);
if (reprojSuccess)
{

33
com.unity.render-pipelines.high-definition/HDRP/Lighting/Volumetrics/VolumetricLighting.cs


RTHandleSystem.RTHandle m_LightingBufferHandle;
// Is the feature globally disabled?
bool m_supportVolumetrics = false;
bool m_SupportVolumetrics = false;
// The history buffer starts in the uninitialized state after being created or resized,
// and contains arbitrary data. Therefore, we must initialize it before use.
Vector3Int m_PreviousResolutionOfHistoryBuffer = Vector3Int.zero;
m_supportVolumetrics = asset.renderPipelineSettings.supportVolumetrics;
m_SupportVolumetrics = asset.renderPipelineSettings.supportVolumetrics;
if (!m_supportVolumetrics)
if (!m_SupportVolumetrics)
return;
preset = asset.renderPipelineSettings.increaseResolutionOfVolumetrics ? VolumetricLightingPreset.High :

{
// Note: Here we can't test framesettings as they are not initialize yet
// TODO: Here we allocate history even for camera that may not use volumetric
if (!m_supportVolumetrics)
if (!m_SupportVolumetrics)
return;
// Start with the same parameters for both frames. Then update them one by one every frame.

cmd.SetComputeTextureParam(m_VolumetricLightingCS, kernel, HDShaderIDs._VBufferLightingIntegral, m_LightingBufferHandle); // Write
if (enableReprojection)
{
cmd.SetComputeTextureParam(m_VolumetricLightingCS, kernel, HDShaderIDs._VBufferLightingHistory, hdCamera.GetPreviousFrameRT((int)HDCameraFrameHistoryType.VolumetricLighting));// Read
cmd.SetComputeTextureParam(m_VolumetricLightingCS, kernel, HDShaderIDs._VBufferLightingFeedback, hdCamera.GetCurrentFrameRT((int)HDCameraFrameHistoryType.VolumetricLighting)); // Write
var historyRT = hdCamera.GetPreviousFrameRT((int)HDCameraFrameHistoryType.VolumetricLighting);
var feedbackRT = hdCamera.GetCurrentFrameRT((int)HDCameraFrameHistoryType.VolumetricLighting);
// Detect if the history buffer has been recreated or resized.
Vector3Int currentResolutionOfHistoryBuffer = new Vector3Int();
currentResolutionOfHistoryBuffer.x = historyRT.rt.width;
currentResolutionOfHistoryBuffer.y = historyRT.rt.height;
currentResolutionOfHistoryBuffer.z = historyRT.rt.volumeDepth;
// We allow downsizing, as this does not cause a reallocation.
bool validHistory = (currentResolutionOfHistoryBuffer.x <= m_PreviousResolutionOfHistoryBuffer.x &&
currentResolutionOfHistoryBuffer.y <= m_PreviousResolutionOfHistoryBuffer.y &&
currentResolutionOfHistoryBuffer.z <= m_PreviousResolutionOfHistoryBuffer.z);
cmd.SetComputeIntParam( m_VolumetricLightingCS, HDShaderIDs._VBufferLightingHistoryIsValid, validHistory ? 1 : 0);
cmd.SetComputeTextureParam(m_VolumetricLightingCS, kernel, HDShaderIDs._VBufferLightingHistory, historyRT); // Read
cmd.SetComputeTextureParam(m_VolumetricLightingCS, kernel, HDShaderIDs._VBufferLightingFeedback, feedbackRT); // Write
m_PreviousResolutionOfHistoryBuffer = currentResolutionOfHistoryBuffer;
}
int w = (int)resolution.x;

7
com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/HDStringConstants.cs


public static readonly string s_MeshDecalsAOSStr = "DBufferMesh_AOS";
public static readonly string s_MeshDecalsMAOSStr = "DBufferMesh_MAOS";
public static readonly string s_MeshDecals3RTStr = "DBufferMesh_3RT";
// ShaderPass name
public static readonly ShaderPassName s_EmptyName = new ShaderPassName(s_EmptyStr);
public static readonly ShaderPassName s_ForwardName = new ShaderPassName(s_ForwardStr);

public static readonly int _NumTileFtplY = Shader.PropertyToID("_NumTileFtplY");
public static readonly int _NumTileClusteredX = Shader.PropertyToID("_NumTileClusteredX");
public static readonly int _NumTileClusteredY = Shader.PropertyToID("_NumTileClusteredY");
public static readonly int _IndirectLightingMultiplier = Shader.PropertyToID("_IndirectLightingMultiplier");
public static readonly int g_isLogBaseBufferEnabled = Shader.PropertyToID("g_isLogBaseBufferEnabled");

public static readonly int _VBufferLighting = Shader.PropertyToID("_VBufferLighting");
public static readonly int _VBufferLightingIntegral = Shader.PropertyToID("_VBufferLightingIntegral");
public static readonly int _VBufferLightingHistory = Shader.PropertyToID("_VBufferLightingHistory");
public static readonly int _VBufferLightingHistoryIsValid = Shader.PropertyToID("_VBufferLightingHistoryIsValid");
public static readonly int _VBufferLightingFeedback = Shader.PropertyToID("_VBufferLightingFeedback");
public static readonly int _VBufferSampleOffset = Shader.PropertyToID("_VBufferSampleOffset");
public static readonly int _VolumeBounds = Shader.PropertyToID("_VolumeBounds");

public static readonly int _VolumeMaskDimensions = Shader.PropertyToID("_VolumeMaskDimensions");
public static readonly int _EnableLightLayers = Shader.PropertyToID("_EnableLightLayers");
// Preintegrated texture name

正在加载...
取消
保存