浏览代码

Add an option to the HDRP asset to increase the resolution of volumetric lighting

/main
Evgenii Golubev 6 年前
当前提交
f7ce098c
共有 15 个文件被更改,包括 144 次插入166 次删除
  1. 1
      com.unity.render-pipelines.high-definition/CHANGELOG.md
  2. 5
      com.unity.render-pipelines.high-definition/HDRP/Editor/RenderPipeline/Settings/RenderPipelineSettingsUI.cs
  3. 2
      com.unity.render-pipelines.high-definition/HDRP/Editor/RenderPipeline/Settings/SerializedFrameSettings.cs
  4. 36
      com.unity.render-pipelines.high-definition/HDRP/Editor/RenderPipeline/Settings/SerializedRenderPipelineSettings.cs
  5. 11
      com.unity.render-pipelines.high-definition/HDRP/HDRenderPipelineAsset.asset
  6. 2
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightEvaluation.hlsl
  7. 43
      com.unity.render-pipelines.high-definition/HDRP/Lighting/Volumetrics/VolumeVoxelization.compute
  8. 67
      com.unity.render-pipelines.high-definition/HDRP/Lighting/Volumetrics/VolumetricLighting.compute
  9. 114
      com.unity.render-pipelines.high-definition/HDRP/Lighting/Volumetrics/VolumetricLighting.cs
  10. 12
      com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/Settings/FrameSettings.cs
  11. 3
      com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/Settings/RenderPipelineSettings.cs
  12. 6
      com.unity.render-pipelines.high-definition/HDRP/ShaderConfig.cs
  13. 2
      com.unity.render-pipelines.high-definition/HDRP/ShaderConfig.cs.hlsl
  14. 2
      com.unity.render-pipelines.high-definition/HDRP/Sky/AtmosphericScattering/AtmosphericScattering.cs
  15. 4
      com.unity.render-pipelines.high-definition/HDRP/Sky/AtmosphericScattering/AtmosphericScattering.hlsl

1
com.unity.render-pipelines.high-definition/CHANGELOG.md


- Add PCSS shadow filter support (from SRP Core)
- Exposed shadow budget parameters in HDRP asset
- Add an option to generate an emissive mesh for area lights (currently rectangle light only). The mesh fits the size, intensity and color of the light.
- Add an option to the HDRP asset to increase the resolution of volumetric lighting.
### Changed
- Re-enable shadow mask mode in debug view

5
com.unity.render-pipelines.high-definition/HDRP/Editor/RenderPipeline/Settings/RenderPipelineSettingsUI.cs


EditorGUILayout.PropertyField(d.supportOnlyForward, _.GetContent("Support Only Forward|Remove all the memory and shader variant of GBuffer. The renderer can be switch to deferred anymore."));
EditorGUILayout.PropertyField(d.supportMotionVectors, _.GetContent("Support Motion Vectors|Motion vector are use for Motion Blur, TAA, temporal re-projection of various effect like SSR."));
EditorGUILayout.PropertyField(d.supportStereo, _.GetContent("Support Stereo Rendering"));
EditorGUILayout.PropertyField(d.increaseSssSampleCount, _.GetContent("Increase SSS Sample Count|This allow better SSS quality. Warning: Slow feature, don't use for game."));
EditorGUILayout.PropertyField(d.supportVolumetric, _.GetContent("Support volumetric|Enable memory and shader variant for volumetric."));
EditorGUILayout.PropertyField(d.increaseSssSampleCount, _.GetContent("Increase SSS Sample Count|This allows for better SSS quality. Warning: high performance cost, do not enable on consoles."));
EditorGUILayout.PropertyField(d.supportVolumetrics, _.GetContent("Support volumetrics|Enable memory and shader variant for volumetric."));
EditorGUILayout.PropertyField(d.increaseResolutionOfVolumetrics, _.GetContent("Increase resolution of volumetrics|Increase the resolution of volumetric lighting buffers. Warning: high performance cost, do not enable on consoles."));
EditorGUILayout.PropertyField(d.supportRuntimeDebugDisplay, _.GetContent("Support runtime debug display|Remove all debug display shader variant only in the player. Allow faster build."));
EditorGUILayout.PropertyField(d.supportDitheringCrossFade, _.GetContent("Support dithering cross fade|Remove all dithering cross fade shader variant only in the player. Allow faster build."));

2
com.unity.render-pipelines.high-definition/HDRP/Editor/RenderPipeline/Settings/SerializedFrameSettings.cs


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);
enableVolumetric = root.Find((FrameSettings d) => d.enableVolumetrics);
diffuseGlobalDimmer = root.Find((FrameSettings d) => d.diffuseGlobalDimmer);
specularGlobalDimmer = root.Find((FrameSettings d) => d.specularGlobalDimmer);
enableForwardRenderingOnly = root.Find((FrameSettings d) => d.enableForwardRenderingOnly);

36
com.unity.render-pipelines.high-definition/HDRP/Editor/RenderPipeline/Settings/SerializedRenderPipelineSettings.cs


public SerializedProperty supportMotionVectors;
public SerializedProperty supportStereo;
public SerializedProperty increaseSssSampleCount;
public SerializedProperty supportVolumetric;
public SerializedProperty supportVolumetrics;
public SerializedProperty increaseResolutionOfVolumetrics;
public SerializedProperty supportRuntimeDebugDisplay;
public SerializedProperty supportDitheringCrossFade;

{
this.root = root;
supportShadowMask = root.Find((RenderPipelineSettings s) => s.supportShadowMask);
supportSSR = root.Find((RenderPipelineSettings s) => s.supportSSR);
supportSSAO = root.Find((RenderPipelineSettings s) => s.supportSSAO);
supportDBuffer = root.Find((RenderPipelineSettings s) => s.supportDBuffer);
supportMSAA = root.Find((RenderPipelineSettings s) => s.supportMSAA);
MSAASampleCount = root.Find((RenderPipelineSettings s) => s.msaaSampleCount);
supportSubsurfaceScattering = root.Find((RenderPipelineSettings s) => s.supportSubsurfaceScattering);
supportOnlyForward = root.Find((RenderPipelineSettings s) => s.supportOnlyForward);
supportMotionVectors = root.Find((RenderPipelineSettings s) => s.supportMotionVectors);
supportStereo = root.Find((RenderPipelineSettings s) => s.supportStereo);
increaseSssSampleCount = root.Find((RenderPipelineSettings s) => s.increaseSssSampleCount);
supportVolumetric = root.Find((RenderPipelineSettings s) => s.supportVolumetric);
supportRuntimeDebugDisplay = root.Find((RenderPipelineSettings s) => s.supportRuntimeDebugDisplay);
supportDitheringCrossFade = root.Find((RenderPipelineSettings s) => s.supportDitheringCrossFade);
supportShadowMask = root.Find((RenderPipelineSettings s) => s.supportShadowMask);
supportSSR = root.Find((RenderPipelineSettings s) => s.supportSSR);
supportSSAO = root.Find((RenderPipelineSettings s) => s.supportSSAO);
supportDBuffer = root.Find((RenderPipelineSettings s) => s.supportDBuffer);
supportMSAA = root.Find((RenderPipelineSettings s) => s.supportMSAA);
MSAASampleCount = root.Find((RenderPipelineSettings s) => s.msaaSampleCount);
supportSubsurfaceScattering = root.Find((RenderPipelineSettings s) => s.supportSubsurfaceScattering);
supportOnlyForward = root.Find((RenderPipelineSettings s) => s.supportOnlyForward);
supportMotionVectors = root.Find((RenderPipelineSettings s) => s.supportMotionVectors);
supportStereo = root.Find((RenderPipelineSettings s) => s.supportStereo);
increaseSssSampleCount = root.Find((RenderPipelineSettings s) => s.increaseSssSampleCount);
supportVolumetrics = root.Find((RenderPipelineSettings s) => s.supportVolumetrics);
increaseResolutionOfVolumetrics = root.Find((RenderPipelineSettings s) => s.increaseResolutionOfVolumetrics);
supportRuntimeDebugDisplay = root.Find((RenderPipelineSettings s) => s.supportRuntimeDebugDisplay);
supportDitheringCrossFade = root.Find((RenderPipelineSettings s) => s.supportDitheringCrossFade);
shadowInitParams = new SerializedShadowInitParameters(root.Find((RenderPipelineSettings s) => s.shadowInitParams));
decalSettings = new SerializedGlobalDecalSettings(root.Find((RenderPipelineSettings s) => s.decalSettings));
shadowInitParams = new SerializedShadowInitParameters(root.Find((RenderPipelineSettings s) => s.shadowInitParams));
decalSettings = new SerializedGlobalDecalSettings(root.Find((RenderPipelineSettings s) => s.decalSettings));
}
}
}

11
com.unity.render-pipelines.high-definition/HDRP/HDRenderPipelineAsset.asset


m_Name: HDRenderPipelineAsset
m_EditorClassIdentifier:
version: 1
m_RenderPipelineResources: {fileID: 11400000, guid: 3ce144cff5783da45aa5d4fdc2da14b7,
type: 2}
m_RenderPipelineResources: {fileID: 11400000, guid: 3ce144cff5783da45aa5d4fdc2da14b7, type: 2}
m_FrameSettings:
enableShadow: 1
enableContactShadows: 1

enableTransmission: 1
enableAtmosphericScattering: 1
enableVolumetric: 1
enableVolumetrics: 1
diffuseGlobalDimmer: 1
specularGlobalDimmer: 1
enableForwardRenderingOnly: 0

supportSubsurfaceScattering: 1
supportOnlyForward: 0
increaseSssSampleCount: 0
supportVolumetric: 1
supportVolumetrics: 1
increaseResolutionOfVolumetrics: 0
supportRuntimeDebugDisplay: 1
supportDitheringCrossFade: 1
supportDBuffer: 1

atlasWidth: 4096
atlasHeight: 4096
allowShaderVariantStripping: 1
diffusionProfileSettings: {fileID: 11400000, guid: 404820c4cf36ad944862fa59c56064f0,
type: 2}
diffusionProfileSettings: {fileID: 11400000, guid: 404820c4cf36ad944862fa59c56064f0, type: 2}

2
com.unity.render-pipelines.high-definition/HDRP/Lighting/LightEvaluation.hlsl


attenuation = SmoothPunctualLightAttenuation(distances, lightData.rangeAttenuationScale, lightData.rangeAttenuationBias,
lightData.angleScale, lightData.angleOffset);
#if (SHADEROPTIONS_VOLUMETRIC_LIGHTING_PRESET != 0)
#endif
// Projector lights always have cookies, so we can perform clipping inside the if().
UNITY_BRANCH if (lightData.cookieIndex >= 0)

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


// Definitions
//--------------------------------------------------------------------------------------------------
#pragma kernel VolumeVoxelizationBruteforce VolumeVoxelization=VolumeVoxelizationBruteforce LIGHTLOOP_SINGLE_PASS
#pragma kernel VolumeVoxelizationClustered VolumeVoxelization=VolumeVoxelizationClustered LIGHTLOOP_TILE_PASS USE_CLUSTERED_LIGHTLIST
#pragma kernel VolumeVoxelizationBruteforceMQ VolumeVoxelization=VolumeVoxelizationBruteforceMQ VL_PRESET_MQ LIGHTLOOP_SINGLE_PASS
#pragma kernel VolumeVoxelizationClusteredMQ VolumeVoxelization=VolumeVoxelizationClusteredMQ VL_PRESET_MQ LIGHTLOOP_TILE_PASS USE_CLUSTERED_LIGHTLIST
#pragma kernel VolumeVoxelizationBruteforceHQ VolumeVoxelization=VolumeVoxelizationBruteforceHQ VL_PRESET_HQ LIGHTLOOP_SINGLE_PASS
#pragma kernel VolumeVoxelizationClusteredHQ VolumeVoxelization=VolumeVoxelizationClusteredHQ VL_PRESET_HQ LIGHTLOOP_TILE_PASS USE_CLUSTERED_LIGHTLIST
#include "../../ShaderPass/ShaderPass.cs.hlsl"
#define SHADERPASS SHADERPASS_VOLUME_VOXELIZATION
#include "../../ShaderConfig.cs.hlsl"
#if (SHADEROPTIONS_VOLUMETRIC_LIGHTING_PRESET == 1)
#ifdef VL_PRESET_MQ
#define VBUFFER_TILE_SIZE 8
#define VBUFFER_SLICE_COUNT 64
#else
#define VBUFFER_TILE_SIZE 8
#endif
#ifdef VL_PRESET_HQ
#define VBUFFER_TILE_SIZE 4
#define VBUFFER_SLICE_COUNT 128
#define VBUFFER_TILE_SIZE 4
#include "../../ShaderPass/ShaderPass.cs.hlsl"
#define SHADERPASS SHADERPASS_VOLUME_VOXELIZATION
//--------------------------------------------------------------------------------------------------
// Included headers
//--------------------------------------------------------------------------------------------------

#include "../../ShaderVariables.hlsl"
#include "VolumetricLighting.cs.hlsl"
#define UNITY_MATERIAL_VOLUMETRIC // Define before including Lighting.hlsl and Material.hlsl
#include "../Lighting.hlsl" // Includes Material.hlsl
#define UNITY_MATERIAL_VOLUMETRIC // Define before including Lighting.hlsl and Material.hlsl
#include "../Lighting.hlsl" // Includes Material.hlsl
#pragma only_renderers d3d11 ps4 xboxone vulkan metal

float3 voxelAxisRight, float3 voxelAxisUp, float3 voxelAxisForward)
{
float n = _VBufferDepthDecodingParams.x + _VBufferDepthDecodingParams.z;
float z0 = n; // Start the computation from the near plane
float de = rcp(VBUFFER_SLICE_COUNT); // Log-encoded distance between slices
float z0 = n; // Start the computation from the near plane
float de = _VBufferSliceCount.y; // Log-encoded distance between slices
#ifdef USE_CLUSTERED_LIGHTLIST
// The voxel can overlap up to 2 light clusters along Z, so we have to iterate over both.

LIGHTCATEGORY_DENSITY_VOLUME, volumeStarts[0], volumeCounts[0]);
#endif // USE_CLUSTERED_LIGHTLIST
#if defined(SHADER_API_METAL)
[fastopt]
for (uint slice = 0; slice < VBUFFER_SLICE_COUNT; slice++)
#else
uint sliceCountHack = max(VBUFFER_SLICE_COUNT, (uint)_VBufferDepthEncodingParams.w); // Prevent unrolling...
// TODO: replace 'sliceCountHack' with VBUFFER_SLICE_COUNT when the shader compiler bug is fixed.
for (uint slice = 0; slice < sliceCountHack; slice++)
#endif
for (uint slice = 0; slice < (uint)_VBufferSliceCount.x; slice++)
{
uint3 voxelCoord = uint3(posInput.positionSS, slice);

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


// Definitions
//--------------------------------------------------------------------------------------------------
#pragma kernel VolumetricLightingBruteforce VolumetricLighting=VolumetricLightingBruteforce ENABLE_REPROJECTION=0 LIGHTLOOP_SINGLE_PASS
#pragma kernel VolumetricLightingBruteforceReproj VolumetricLighting=VolumetricLightingBruteforceReproj ENABLE_REPROJECTION=1 LIGHTLOOP_SINGLE_PASS
#pragma kernel VolumetricLightingClustered VolumetricLighting=VolumetricLightingClustered ENABLE_REPROJECTION=0 LIGHTLOOP_TILE_PASS USE_CLUSTERED_LIGHTLIST
#pragma kernel VolumetricLightingClusteredReproj VolumetricLighting=VolumetricLightingClusteredReproj ENABLE_REPROJECTION=1 LIGHTLOOP_TILE_PASS USE_CLUSTERED_LIGHTLIST
#pragma kernel VolumetricLightingBruteforceMQ VolumetricLighting=VolumetricLightingBruteforceMQ VL_PRESET_MQ ENABLE_REPROJECTION=0 LIGHTLOOP_SINGLE_PASS
#pragma kernel VolumetricLightingBruteforceReprojMQ VolumetricLighting=VolumetricLightingBruteforceReprojMQ VL_PRESET_MQ ENABLE_REPROJECTION=1 LIGHTLOOP_SINGLE_PASS
#pragma kernel VolumetricLightingClusteredMQ VolumetricLighting=VolumetricLightingClusteredMQ VL_PRESET_MQ ENABLE_REPROJECTION=0 LIGHTLOOP_TILE_PASS USE_CLUSTERED_LIGHTLIST
#pragma kernel VolumetricLightingClusteredReprojMQ VolumetricLighting=VolumetricLightingClusteredReprojMQ VL_PRESET_MQ ENABLE_REPROJECTION=1 LIGHTLOOP_TILE_PASS USE_CLUSTERED_LIGHTLIST
#pragma kernel VolumetricLightingBruteforceHQ VolumetricLighting=VolumetricLightingBruteforceHQ VL_PRESET_HQ ENABLE_REPROJECTION=0 LIGHTLOOP_SINGLE_PASS
#pragma kernel VolumetricLightingBruteforceReprojHQ VolumetricLighting=VolumetricLightingBruteforceReprojHQ VL_PRESET_HQ ENABLE_REPROJECTION=1 LIGHTLOOP_SINGLE_PASS
#pragma kernel VolumetricLightingClusteredHQ VolumetricLighting=VolumetricLightingClusteredHQ VL_PRESET_HQ ENABLE_REPROJECTION=0 LIGHTLOOP_TILE_PASS USE_CLUSTERED_LIGHTLIST
#pragma kernel VolumetricLightingClusteredReprojHQ VolumetricLighting=VolumetricLightingClusteredReprojHQ VL_PRESET_HQ ENABLE_REPROJECTION=1 LIGHTLOOP_TILE_PASS USE_CLUSTERED_LIGHTLIST
#define SHADOW_USE_ONLY_VIEW_BASED_BIASING 1 // We don't use normal biasing as it is not available when doing volumetric
#include "../../ShaderPass/ShaderPass.cs.hlsl"
#define SHADERPASS SHADERPASS_VOLUMETRIC_LIGHTING
#include "../../ShaderConfig.cs.hlsl"
#if (SHADEROPTIONS_VOLUMETRIC_LIGHTING_PRESET == 1)
#ifdef VL_PRESET_MQ
#define VBUFFER_TILE_SIZE 8
#define VBUFFER_SLICE_COUNT 64
#else
#define VBUFFER_TILE_SIZE 8
#endif
#ifdef VL_PRESET_HQ
#define VBUFFER_TILE_SIZE 4
#define VBUFFER_SLICE_COUNT 128
#define VBUFFER_TILE_SIZE 4
#define SUPPORT_PUNCTUAL_LIGHTS 1 // Punctual lights contribute to fog lighting
#define GROUP_SIZE_1D 8
#define GROUP_SIZE_1D 8
#define SUPPORT_PUNCTUAL_LIGHTS 1 // Punctual lights contribute to fog lighting
#define SHADOW_USE_ONLY_VIEW_BASED_BIASING 1 // We don't use normal biasing as it is not available when doing volumetric
#if (SHADEROPTIONS_VOLUMETRIC_LIGHTING_PRESET != 0) // Switch between the full and the empty shader
#include "../../ShaderPass/ShaderPass.cs.hlsl"
#define SHADERPASS SHADERPASS_VOLUMETRIC_LIGHTING
//--------------------------------------------------------------------------------------------------
// Included headers

#include "VolumetricLighting.cs.hlsl"
#include "VBuffer.hlsl"
#define UNITY_MATERIAL_VOLUMETRIC // Define before including Lighting.hlsl and Material.hlsl
#include "../Lighting.hlsl" // Includes Material.hlsl
#define UNITY_MATERIAL_VOLUMETRIC // Define before including Lighting.hlsl and Material.hlsl
#include "../Lighting.hlsl" // Includes Material.hlsl
#include "../LightEvaluation.hlsl"
#pragma only_renderers d3d11 ps4 xboxone vulkan metal switch

PositionInputs posInput, DualRay ray)
{
const float n = _VBufferDepthDecodingParams.x + _VBufferDepthDecodingParams.z;
const float z0 = n; // Start integration from the near plane
const float de = rcp(VBUFFER_SLICE_COUNT); // Log-encoded distance between slices
const float z0 = n; // Start integration from the near plane
const float de = _VBufferSliceCount.y; // Log-encoded distance between slices
float t0 = ConvertLinearDepthToJitterRayDist(ray, z0);

lightClusters[0] = GetLightClusterIndex(posInput.tileCoord, z0);
#endif // USE_CLUSTERED_LIGHTLIST
#if defined(SHADER_API_METAL)
[fastopt]
for (uint slice = 0; slice < VBUFFER_SLICE_COUNT; slice++)
#else
uint sliceCountHack = max(VBUFFER_SLICE_COUNT, (uint)_VBufferDepthEncodingParams.w); // Prevent unrolling...
// TODO: replace 'sliceCountHack' with VBUFFER_SLICE_COUNT when the shader compiler bug is fixed.
for (uint slice = 0; slice < sliceCountHack; slice++)
#endif
for (uint slice = 0; slice < (uint)_VBufferSliceCount.x; slice++)
{
uint3 voxelCoord = uint3(posInput.positionSS, slice);

FillVolumetricLightingBuffer(context, featureFlags, posInput, ray);
}
#else
[numthreads(GROUP_SIZE_1D, GROUP_SIZE_1D, 1)]
void VolumetricLighting(uint2 groupId : SV_GroupID,
uint2 groupThreadId : SV_GroupThreadID)
{
// Reduce compile times if the feature is disabled.
}
#endif // SHADEROPTIONS_VOLUMETRIC_LIGHTING_PRESET

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


[GenerateHLSL]
public struct DensityVolumeData
{
public Vector3 scattering; // [0, 1], prefer sRGB
public float extinction;// [0, 1], prefer sRGB
public Vector3 scattering; // [0, 1]
public float extinction; // [0, 1]
public int textureIndex;//
public int textureIndex;
public Vector3 textureScroll;
public static DensityVolumeData GetNeutralValues()

data.scattering = Vector3.zero;
data.extinction = 0;
data.textureIndex = -1;
data.scattering = Vector3.zero;
data.extinction = 0;
data.textureIndex = -1;
data.textureTiling = Vector3.one;
data.textureScroll = Vector3.zero;

public enum VolumetricLightingPreset
{
Off,
Normal,
Ultra,
Medium,
High,
Count
} // enum VolumetricLightingPreset

}
} // struct Parameters
public VolumetricLightingPreset preset { get { return (VolumetricLightingPreset)Math.Min(ShaderConfig.s_VolumetricLightingPreset, (int)VolumetricLightingPreset.Count); } }
public VolumetricLightingPreset preset = VolumetricLightingPreset.Off;
static ComputeShader m_VolumeVoxelizationCS = null;
static ComputeShader m_VolumetricLightingCS = null;

RTHandleSystem.RTHandle m_DensityBufferHandle;
RTHandleSystem.RTHandle m_LightingBufferHandle;
// Do we support volumetric or not?
bool m_supportVolumetric = false;
// Is the feature globally disabled?
bool m_supportVolumetrics = false;
m_supportVolumetric = asset.renderPipelineSettings.supportVolumetric;
m_supportVolumetrics = asset.renderPipelineSettings.supportVolumetrics;
if (!m_supportVolumetric)
if (!m_supportVolumetrics)
preset = asset.renderPipelineSettings.increaseResolutionOfVolumetrics ? VolumetricLightingPreset.High :
VolumetricLightingPreset.Medium;
m_VolumeVoxelizationCS = asset.renderPipelineResources.volumeVoxelizationCS;
m_VolumetricLightingCS = asset.renderPipelineResources.volumetricLightingCS;

{
// 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)
if (!m_supportVolumetrics)
return;
// Start with the same parameters for both frames. Then update them one by one every frame.

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

{
switch (preset)
{
case VolumetricLightingPreset.Normal:
case VolumetricLightingPreset.Medium:
case VolumetricLightingPreset.Ultra:
case VolumetricLightingPreset.High:
return 4;
case VolumetricLightingPreset.Off:
return 0;

{
switch (preset)
{
case VolumetricLightingPreset.Normal:
case VolumetricLightingPreset.Medium:
case VolumetricLightingPreset.Ultra:
case VolumetricLightingPreset.High:
return 128;
case VolumetricLightingPreset.Off:
return 0;

public void PushGlobalParams(HDCamera hdCamera, CommandBuffer cmd, uint frameIndex)
{
if (!hdCamera.frameSettings.enableVolumetric)
return;
if (visualEnvironment.fogType != FogType.Volumetric)
if (!hdCamera.frameSettings.enableVolumetrics || visualEnvironment.fogType != FogType.Volumetric)
{
// Set the neutral black texture.
cmd.SetGlobalTexture(HDShaderIDs._VBufferLighting, CoreUtils.blackVolumeTexture);

{
DensityVolumeList densityVolumes = new DensityVolumeList();
if (!hdCamera.frameSettings.enableVolumetric)
if (!hdCamera.frameSettings.enableVolumetrics)
return densityVolumes;
var visualEnvironment = VolumeManager.instance.stack.GetComponent<VisualEnvironment>();

public void VolumeVoxelizationPass(HDCamera hdCamera, CommandBuffer cmd, uint frameIndex, DensityVolumeList densityVolumes)
{
if (!hdCamera.frameSettings.enableVolumetric)
if (!hdCamera.frameSettings.enableVolumetrics)
return;
var visualEnvironment = VolumeManager.instance.stack.GetComponent<VisualEnvironment>();

{
int numVisibleVolumes = m_VisibleVolumeBounds.Count;
if (numVisibleVolumes == 0)
{
// Clear the render target instead of running the shader.
// Note: the clear must take the global fog into account!
// CoreUtils.SetRenderTarget(cmd, vBuffer.GetDensityBuffer(), ClearFlag.Color, CoreUtils.clearColorAllBlack);
// return;
// Clearing 3D textures does not seem to work!
// Use the workaround by running the full shader with 0 density
}
bool highQuality = preset == VolumetricLightingPreset.High;
int kernel = m_VolumeVoxelizationCS.FindKernel(enableClustered ? "VolumeVoxelizationClustered"
: "VolumeVoxelizationBruteforce");
int kernel;
if (highQuality)
{
kernel = m_VolumeVoxelizationCS.FindKernel(enableClustered ? "VolumeVoxelizationClusteredHQ"
: "VolumeVoxelizationBruteforceHQ");
}
else
{
kernel = m_VolumeVoxelizationCS.FindKernel(enableClustered ? "VolumeVoxelizationClusteredMQ"
: "VolumeVoxelizationBruteforceMQ");
}
var frameParams = hdCamera.vBufferParams[0];
Vector4 resolution = frameParams.resolution;

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

using (new ProfilingSample(cmd, "Volumetric Lighting"))
{
// Only available in the Play Mode because all the frame counters in the Edit Mode are broken.
bool highQuality = preset == VolumetricLightingPreset.High;
if (enableReprojection)
if (highQuality)
kernel = m_VolumetricLightingCS.FindKernel(enableClustered ? "VolumetricLightingClusteredReproj"
: "VolumetricLightingBruteforceReproj");
if (enableReprojection)
{
kernel = m_VolumetricLightingCS.FindKernel(enableClustered ? "VolumetricLightingClusteredReprojHQ"
: "VolumetricLightingBruteforceReprojHQ");
}
else
{
kernel = m_VolumetricLightingCS.FindKernel(enableClustered ? "VolumetricLightingClusteredHQ"
: "VolumetricLightingBruteforceHQ");
}
kernel = m_VolumetricLightingCS.FindKernel(enableClustered ? "VolumetricLightingClustered"
: "VolumetricLightingBruteforce");
if (enableReprojection)
{
kernel = m_VolumetricLightingCS.FindKernel(enableClustered ? "VolumetricLightingClusteredReprojMQ"
: "VolumetricLightingBruteforceReprojMQ");
}
else
{
kernel = m_VolumetricLightingCS.FindKernel(enableClustered ? "VolumetricLightingClusteredMQ"
: "VolumetricLightingBruteforceMQ");
}
}
var frameParams = hdCamera.vBufferParams[0];

// TODO: set 'm_VolumetricLightingPreset'.
// TODO: set the constant buffer data only once.
cmd.SetComputeMatrixParam(m_VolumetricLightingCS, HDShaderIDs._VBufferCoordToViewDirWS, transform);
cmd.SetComputeVectorParam(m_VolumetricLightingCS, HDShaderIDs._VBufferSampleOffset, offset);
cmd.SetComputeFloatParam(m_VolumetricLightingCS, HDShaderIDs._CornetteShanksConstant, CornetteShanksPhasePartConstant(fog.anisotropy));
cmd.SetComputeTextureParam(m_VolumetricLightingCS, kernel, HDShaderIDs._VBufferDensity, m_DensityBufferHandle);// Read
cmd.SetComputeMatrixParam( m_VolumetricLightingCS, HDShaderIDs._VBufferCoordToViewDirWS, transform);
cmd.SetComputeVectorParam( m_VolumetricLightingCS, HDShaderIDs._VBufferSampleOffset, offset);
cmd.SetComputeFloatParam( m_VolumetricLightingCS, HDShaderIDs._CornetteShanksConstant, CornetteShanksPhasePartConstant(fog.anisotropy));
cmd.SetComputeTextureParam(m_VolumetricLightingCS, kernel, HDShaderIDs._VBufferDensity, m_DensityBufferHandle); // Read
cmd.SetComputeTextureParam(m_VolumetricLightingCS, kernel, HDShaderIDs._VBufferLightingIntegral, m_LightingBufferHandle); // Write
if (enableReprojection)
{

12
com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/Settings/FrameSettings.cs


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;
public bool enableVolumetrics = true;
// Setup by system
public float diffuseGlobalDimmer = 1.0f;

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

if (!CoreUtils.IsSceneViewFogEnabled(camera))
aggregate.enableAtmosphericScattering = false;
// Volumetric are disabled if there is no atmospheric scattering
aggregate.enableVolumetric = srcFrameSettings.enableVolumetric && renderPipelineSettings.supportVolumetric && aggregate.enableAtmosphericScattering;
aggregate.enableVolumetrics = srcFrameSettings.enableVolumetrics && renderPipelineSettings.supportVolumetrics && aggregate.enableAtmosphericScattering;
aggregate.enableVolumetric = false;
aggregate.enableVolumetrics = false;
// We have to fall back to forward-only rendering when scene view is using wireframe rendering mode
// as rendering everything in wireframe + deferred do not play well together

aggregate.enableSSR = false;
aggregate.enableSSAO = false;
aggregate.enableAtmosphericScattering = false;
aggregate.enableVolumetric = false;
aggregate.enableVolumetrics = false;
aggregate.enableTransparentPrepass = false;
aggregate.enableMotionVectors = false;
aggregate.enableObjectMotionVectors = false;

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 },
new DebugUI.BoolField { displayName = "Enable volumetrics", getter = () => frameSettings.enableVolumetrics, setter = value => frameSettings.enableVolumetrics = value },
}
}
});

3
com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/Settings/RenderPipelineSettings.cs


[FormerlySerializedAs("supportForwardOnly")]
public bool supportOnlyForward = false;
public bool increaseSssSampleCount = false;
public bool supportVolumetric = true;
public bool supportVolumetrics = true;
public bool increaseResolutionOfVolumetrics = false;
// reduce variant
public bool supportRuntimeDebugDisplay = true;

6
com.unity.render-pipelines.high-definition/HDRP/ShaderConfig.cs


public enum ShaderOptions
{
CameraRelativeRendering = 1, // Rendering sets the origin of the world to the position of the primary (scene view) camera
UseDisneySSS = 1, // Allow to chose between Burley Normalized Diffusion (Multi + Fix direction single scattering) or Jimenez diffusion approximation (Multiscattering only - More blurry) for Subsurface scattering
VolumetricLightingPreset = 1 // 0 = disabled, 1 = normal, 2 = ultra
UseDisneySSS = 1 // Allow to chose between Burley Normalized Diffusion (Multi + Fix direction single scattering) or Jimenez diffusion approximation (Multiscattering only - More blurry) for Subsurface scattering
};
// Note: #define can't be use in include file in C# so we chose this way to configure both C# and hlsl

public const int k_UseDisneySSS = (int)ShaderOptions.UseDisneySSS;
public static int s_UseDisneySSS = (int)ShaderOptions.UseDisneySSS;
public const int k_VolumetricLightingPreset = (int)ShaderOptions.VolumetricLightingPreset;
public static int s_VolumetricLightingPreset = (int)ShaderOptions.VolumetricLightingPreset;
}
}

2
com.unity.render-pipelines.high-definition/HDRP/ShaderConfig.cs.hlsl


//
#define SHADEROPTIONS_CAMERA_RELATIVE_RENDERING (1)
#define SHADEROPTIONS_USE_DISNEY_SSS (1)
#define SHADEROPTIONS_VOLUMETRIC_LIGHTING_PRESET (1)
#endif

2
com.unity.render-pipelines.high-definition/HDRP/Sky/AtmosphericScattering/AtmosphericScattering.cs


// In case volumetric lighting is enabled, we need to make sure that all rendering passes
// (not just the atmospheric scattering one) receive neutral parameters.
if (hdCamera.frameSettings.enableVolumetric)
if (hdCamera.frameSettings.enableVolumetrics)
{
var data = DensityVolumeData.GetNeutralValues();

4
com.unity.render-pipelines.high-definition/HDRP/Sky/AtmosphericScattering/AtmosphericScattering.hlsl


#include "../../ShaderVariables.hlsl"
#include "../../Lighting/Volumetrics/VBuffer.hlsl"
#if (SHADEROPTIONS_VOLUMETRIC_LIGHTING_PRESET != 0)
#endif
CBUFFER_START(AtmosphericScattering)
int _AtmosphericScatteringType;

}
case FOGTYPE_VOLUMETRIC:
{
#if (SHADEROPTIONS_VOLUMETRIC_LIGHTING_PRESET != 0)
float4 volFog = SampleVolumetricLighting(TEXTURE3D_PARAM(_VBufferLighting, s_linear_clamp_sampler),
posInput.positionNDC,
posInput.linearDepth,

fogFactor = 1 - volFog.a; // Opacity from transmittance
fogColor = volFog.rgb * min(rcp(fogFactor), FLT_MAX); // Un-premultiply, clamp to avoid (0 * INF = NaN)
#endif
break;
}
}

正在加载...
取消
保存