浏览代码

Merge pull request #1334 from Unity-Technologies/Add-framesettings-support

Add enableVolumetric in the FrameSettings
/main
GitHub 6 年前
当前提交
1d661e75
共有 7 个文件被更改,包括 56 次插入32 次删除
  1. 2
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Camera/HDCamera.cs
  2. 3
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/RenderLoopSettings/FrameSettingsUI.cs
  3. 6
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/RenderLoopSettings/SerializedFrameSettings.cs
  4. 46
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/VolumetricLighting.cs
  5. 23
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipeline/FrameSettings.cs
  6. 4
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Sky/AtmosphericScattering/AtmosphericScattering.cs
  7. 4
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Sky/VisualEnvironment.cs

2
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Camera/HDCamera.cs


s_Cleanup.Clear();
}
// Look for any camera that hasn't been used in the last frame and remove them for the pool.
// Look for any camera that hasn't been used in the last frame and remove them from the pool.
public static void CleanUnused()
{
int frameCheck = Time.frameCount - 1;

3
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/RenderLoopSettings/FrameSettingsUI.cs


EditorGUILayout.PropertyField(p.enableMotionVectors, _.GetContent("Enable Motion Vectors"));
EditorGUILayout.PropertyField(p.enableObjectMotionVectors, _.GetContent("Enable Object Motion Vectors"));
EditorGUILayout.PropertyField(p.enableDBuffer, _.GetContent("Enable DBuffer"));
EditorGUILayout.PropertyField(p.enableAtmosphericScattering, _.GetContent("Enable Atmospheric Scattering"));
EditorGUILayout.PropertyField(p.enableRoughRefraction, _.GetContent("Enable Rough Refraction"));
EditorGUILayout.PropertyField(p.enableDistortion, _.GetContent("Enable Distortion"));
EditorGUILayout.PropertyField(p.enablePostprocess, _.GetContent("Enable Postprocess"));

EditorGUILayout.PropertyField(p.enableSSAO, _.GetContent("Enable SSAO"));
EditorGUILayout.PropertyField(p.enableSubsurfaceScattering, _.GetContent("Enable Subsurface Scattering"));
EditorGUILayout.PropertyField(p.enableTransmission, _.GetContent("Enable Transmission"));
EditorGUILayout.PropertyField(p.enableAtmosphericScattering, _.GetContent("Enable Atmospheric Scattering"));
EditorGUILayout.PropertyField(p.enableVolumetric, _.GetContent(" Enable Volumetric"));
EditorGUILayout.PropertyField(p.enableShadow, _.GetContent("Enable Shadow"));
EditorGUILayout.PropertyField(p.enableContactShadow, _.GetContent("Enable Contact Shadows"));
EditorGUILayout.PropertyField(p.enableShadowMask, _.GetContent("Enable Shadow Masks"));

6
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/RenderLoopSettings/SerializedFrameSettings.cs


public SerializedProperty enableSSAO;
public SerializedProperty enableSubsurfaceScattering;
public SerializedProperty enableTransmission;
public SerializedProperty enableAtmosphericScattering;
public SerializedProperty enableVolumetric;
public SerializedProperty diffuseGlobalDimmer;
public SerializedProperty specularGlobalDimmer;

public SerializedProperty enableMotionVectors;
public SerializedProperty enableObjectMotionVectors;
public SerializedProperty enableDBuffer;
public SerializedProperty enableAtmosphericScattering;
public SerializedProperty enableRoughRefraction;
public SerializedProperty enableTransparentPostpass;
public SerializedProperty enableDistortion;

enableSSAO = root.Find((FrameSettings d) => d.enableSSAO);
enableSubsurfaceScattering = root.Find((FrameSettings d) => d.enableSubsurfaceScattering);
enableTransmission = root.Find((FrameSettings d) => d.enableTransmission);
enableAtmosphericScattering = root.Find((FrameSettings d) => d.enableAtmosphericScattering);
enableVolumetric = root.Find((FrameSettings d) => d.enableVolumetric);
diffuseGlobalDimmer = root.Find((FrameSettings d) => d.diffuseGlobalDimmer);
specularGlobalDimmer = root.Find((FrameSettings d) => d.specularGlobalDimmer);
enableForwardRenderingOnly = root.Find((FrameSettings d) => d.enableForwardRenderingOnly);

enableObjectMotionVectors = root.Find((FrameSettings d) => d.enableObjectMotionVectors);
enableDBuffer = root.Find((FrameSettings d) => d.enableDBuffer);
enableAtmosphericScattering = root.Find((FrameSettings d) => d.enableAtmosphericScattering);
enableRoughRefraction = root.Find((FrameSettings d) => d.enableRoughRefraction);
enableTransparentPostpass = root.Find((FrameSettings d) => d.enableTransparentPostpass);
enableDistortion = root.Find((FrameSettings d) => d.enableDistortion);

46
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/VolumetricLighting.cs


RTHandleSystem.RTHandle m_DensityBufferHandle;
RTHandleSystem.RTHandle m_LightingBufferHandle;
// Do we support volumetric or not?
bool m_supportVolumetric = false;
if (preset == VolumetricLightingPreset.Off) return;
m_supportVolumetric = asset.renderPipelineSettings.supportVolumetric;
if (!m_supportVolumetric)
return;
m_VolumeVoxelizationCS = asset.renderPipelineResources.volumeVoxelizationCS;
m_VolumetricLightingCS = asset.renderPipelineResources.volumetricLightingCS;

public void InitializePerCameraData(HDCamera hdCamera)
{
if (preset == VolumetricLightingPreset.Off) return;
// 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_supportVolumetric)
return;
// Start with the same parameters for both frames. Then update them one by one every frame.
var parameters = ComputeVBufferParameters(hdCamera, true);

// The results are undefined otherwise.
public void UpdatePerCameraData(HDCamera hdCamera)
{
if (preset == VolumetricLightingPreset.Off) return;
if (!hdCamera.frameSettings.enableVolumetric)
return;
var parameters = ComputeVBufferParameters(hdCamera, false);

void DestroyBuffers()
{
RTHandles.Release(m_DensityBufferHandle);
RTHandles.Release(m_LightingBufferHandle);
if (m_DensityBufferHandle != null)
RTHandles.Release(m_DensityBufferHandle);
if (m_LightingBufferHandle != null)
RTHandles.Release(m_LightingBufferHandle);
CoreUtils.SafeRelease(s_VisibleVolumeBoundsBuffer);
CoreUtils.SafeRelease(s_VisibleVolumeDataBuffer);

public void Cleanup()
{
if (preset == VolumetricLightingPreset.Off) return;
// Note: No need to test for support volumetric here, we do saferelease and null assignation
DestroyBuffers();
m_VolumeVoxelizationCS = null;

public void PushGlobalParams(HDCamera hdCamera, CommandBuffer cmd, uint frameIndex)
{
if (preset == VolumetricLightingPreset.Off) return;
if (!hdCamera.frameSettings.enableVolumetric)
return;
var visualEnvironment = VolumeManager.instance.stack.GetComponent<VisualEnvironment>();

{
DensityVolumeList densityVolumes = new DensityVolumeList();
if (preset == VolumetricLightingPreset.Off) return densityVolumes;
if (!hdCamera.frameSettings.enableVolumetric)
return densityVolumes;
if (visualEnvironment.fogType != FogType.Volumetric) return densityVolumes;
if (visualEnvironment.fogType != FogType.Volumetric)
return densityVolumes;
using (new ProfilingSample(cmd, "Prepare Visible Density Volume List"))
{

public void VolumeVoxelizationPass(HDCamera hdCamera, CommandBuffer cmd, uint frameIndex, DensityVolumeList densityVolumes)
{
if (preset == VolumetricLightingPreset.Off) return;
if (!hdCamera.frameSettings.enableVolumetric)
return;
if (visualEnvironment.fogType != FogType.Volumetric) return;
if (visualEnvironment.fogType != FogType.Volumetric)
return;
using (new ProfilingSample(cmd, "Volume Voxelization"))
{

public void VolumetricLightingPass(HDCamera hdCamera, CommandBuffer cmd, uint frameIndex)
{
if (preset == VolumetricLightingPreset.Off) return;
if (!hdCamera.frameSettings.enableVolumetric)
return;
if (visualEnvironment.fogType != FogType.Volumetric) return;
if (visualEnvironment.fogType != FogType.Volumetric)
return;
using (new ProfilingSample(cmd, "Volumetric Lighting"))
{

23
ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipeline/FrameSettings.cs


public bool enableSSAO = true;
public bool enableSubsurfaceScattering = true;
public bool enableTransmission = true; // Caution: this is only for debug, it doesn't save the cost of Transmission execution
public bool enableAtmosphericScattering = true;
public bool enableVolumetric = true;
// Setup by system

public bool enableMotionVectors = true; // Enable/disable whole motion vectors pass (Camera + Object).
public bool enableObjectMotionVectors = true;
public bool enableDBuffer = true;
public bool enableAtmosphericScattering = true;
public bool enableRoughRefraction = true; // Depends on DepthPyramid - If not enable, just do a copy of the scene color (?) - how to disable rough refraction ?
public bool enableTransparentPostpass = true;
public bool enableDistortion = true;

frameSettings.enableSSAO = this.enableSSAO;
frameSettings.enableSubsurfaceScattering = this.enableSubsurfaceScattering;
frameSettings.enableTransmission = this.enableTransmission;
frameSettings.enableAtmosphericScattering = this.enableAtmosphericScattering;
frameSettings.enableVolumetric = this.enableVolumetric;
frameSettings.diffuseGlobalDimmer = this.diffuseGlobalDimmer;
frameSettings.specularGlobalDimmer = this.specularGlobalDimmer;

frameSettings.enableMotionVectors = this.enableMotionVectors;
frameSettings.enableObjectMotionVectors = this.enableObjectMotionVectors;
frameSettings.enableDBuffer = this.enableDBuffer;
frameSettings.enableAtmosphericScattering = this.enableAtmosphericScattering;
frameSettings.enableRoughRefraction = this.enableRoughRefraction;
frameSettings.enableTransparentPostpass = this.enableTransparentPostpass;
frameSettings.enableDistortion = this.enableDistortion;

aggregate.enableSSAO = srcFrameSettings.enableSSAO && renderPipelineSettings.supportSSAO;
aggregate.enableSubsurfaceScattering = camera.cameraType != CameraType.Reflection && srcFrameSettings.enableSubsurfaceScattering && renderPipelineSettings.supportSubsurfaceScattering;
aggregate.enableTransmission = srcFrameSettings.enableTransmission;
aggregate.enableVolumetric = srcFrameSettings.enableVolumetric && renderPipelineSettings.supportVolumetric;
aggregate.enableAtmosphericScattering = srcFrameSettings.enableAtmosphericScattering;
// We must take care of the scene view fog flags in the editor
if (!CoreUtils.IsSceneViewFogEnabled(camera))
aggregate.enableAtmosphericScattering = false;
// Volumetric are disabled if there is no atmospheric scattering
aggregate.enableVolumetric = srcFrameSettings.enableVolumetric && renderPipelineSettings.supportVolumetric && aggregate.enableAtmosphericScattering;
// TODO: Add support of volumetric in planar reflection
if (camera.cameraType == CameraType.Reflection)

aggregate.enableMotionVectors = camera.cameraType != CameraType.Reflection && srcFrameSettings.enableMotionVectors && renderPipelineSettings.supportMotionVectors;
aggregate.enableObjectMotionVectors = camera.cameraType != CameraType.Reflection && srcFrameSettings.enableObjectMotionVectors && renderPipelineSettings.supportMotionVectors;
aggregate.enableDBuffer = srcFrameSettings.enableDBuffer && renderPipelineSettings.supportDBuffer;
aggregate.enableAtmosphericScattering = srcFrameSettings.enableAtmosphericScattering;
// We must take care of the scene view fog flags in the editor
if (!CoreUtils.IsSceneViewFogEnabled(camera))
aggregate.enableAtmosphericScattering = false;
aggregate.enableRoughRefraction = srcFrameSettings.enableRoughRefraction;
aggregate.enableTransparentPostpass = srcFrameSettings.enableTransparentPostpass;
aggregate.enableDistortion = camera.cameraType != CameraType.Reflection && srcFrameSettings.enableDistortion;

aggregate.enableContactShadows = false;
aggregate.enableSSR = false;
aggregate.enableSSAO = false;
aggregate.enableAtmosphericScattering = false;
aggregate.enableVolumetric = false;
aggregate.enableAtmosphericScattering = false;
aggregate.enableVolumetric = false;
}
LightLoopSettings.InitializeLightLoopSettings(camera, aggregate, renderPipelineSettings, srcFrameSettings, ref aggregate.lightLoopSettings);

new DebugUI.BoolField { displayName = "Enable Motion Vectors", getter = () => frameSettings.enableMotionVectors, setter = value => frameSettings.enableMotionVectors = value },
new DebugUI.BoolField { displayName = "Enable Object Motion Vectors", getter = () => frameSettings.enableObjectMotionVectors, setter = value => frameSettings.enableObjectMotionVectors = value },
new DebugUI.BoolField { displayName = "Enable DBuffer", getter = () => frameSettings.enableDBuffer, setter = value => frameSettings.enableDBuffer = value },
new DebugUI.BoolField { displayName = "Enable Atmospheric Scattering", getter = () => frameSettings.enableAtmosphericScattering, setter = value => frameSettings.enableAtmosphericScattering = value },
new DebugUI.BoolField { displayName = "Enable Rough Refraction", getter = () => frameSettings.enableRoughRefraction, setter = value => frameSettings.enableRoughRefraction = value },
new DebugUI.BoolField { displayName = "Enable Distortion", getter = () => frameSettings.enableDistortion, setter = value => frameSettings.enableDistortion = value },
new DebugUI.BoolField { displayName = "Enable Postprocess", getter = () => frameSettings.enablePostprocess, setter = value => frameSettings.enablePostprocess = value },

new DebugUI.BoolField { displayName = "Enable Shadows", getter = () => frameSettings.enableShadow, setter = value => frameSettings.enableShadow = value },
new DebugUI.BoolField { displayName = "Enable Contact Shadows", getter = () => frameSettings.enableContactShadows, setter = value => frameSettings.enableContactShadows = value },
new DebugUI.BoolField { displayName = "Enable ShadowMask", getter = () => frameSettings.enableShadowMask, setter = value => frameSettings.enableShadowMask = value },
new DebugUI.BoolField { displayName = "Enable Atmospheric Scattering", getter = () => frameSettings.enableAtmosphericScattering, setter = value => frameSettings.enableAtmosphericScattering = value },
new DebugUI.BoolField { displayName = " Enable volumetric", getter = () => frameSettings.enableVolumetric, setter = value => frameSettings.enableVolumetric = value },
}
}
});

4
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Sky/AtmosphericScattering/AtmosphericScattering.cs


public abstract void PushShaderParameters(HDCamera hdCamera, CommandBuffer cmd);
public static void PushNeutralShaderParameters(CommandBuffer cmd)
public static void PushNeutralShaderParameters(HDCamera hdCamera, CommandBuffer cmd)
if (ShaderConfig.s_VolumetricLightingPreset != 0)
if (hdCamera.frameSettings.enableVolumetric)
{
var data = DensityVolumeData.GetNeutralValues();

4
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Sky/VisualEnvironment.cs


{
if (!hdCamera.frameSettings.enableAtmosphericScattering)
{
AtmosphericScattering.PushNeutralShaderParameters(cmd);
AtmosphericScattering.PushNeutralShaderParameters(hdCamera, cmd);
return;
}

{
AtmosphericScattering.PushNeutralShaderParameters(cmd);
AtmosphericScattering.PushNeutralShaderParameters(hdCamera, cmd);
break;
}
case FogType.Linear:

正在加载...
取消
保存