浏览代码

Move the volumetric lighting preset to ShaderConfig

/Yibing-Project-2
Evgenii Golubev 7 年前
当前提交
389ea636
共有 9 个文件被更改,包括 33 次插入32 次删除
  1. 2
      ScriptableRenderPipeline/Core/ShaderLibrary/VolumeRendering.hlsl
  2. 5
      ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs
  3. 2
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightEvaluation.hlsl
  4. 22
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/Volumetrics/Resources/VolumetricLighting.compute
  5. 17
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/Volumetrics/VolumetricLighting.cs
  6. 9
      ScriptableRenderPipeline/HDRenderPipeline/ShaderConfig.cs
  7. 1
      ScriptableRenderPipeline/HDRenderPipeline/ShaderConfig.cs.hlsl
  8. 4
      ScriptableRenderPipeline/HDRenderPipeline/Sky/AtmosphericScattering/AtmosphericScattering.hlsl
  9. 3
      ScriptableRenderPipeline/HDRenderPipeline/Sky/HDRISky/Resources/SkyHDRI.shader

2
ScriptableRenderPipeline/Core/ShaderLibrary/VolumeRendering.hlsl


return -log(transmittanceColor + FLT_EPS) / max(atDistance, FLT_EPS);
}
#define VOLUMETRIC_LIGHTING_ENABLED
// Interpolation in the log space is non-linear.
// Therefore, given 'logEncodedDepth', we compute a new depth value
// which allows us to perform HW interpolation which is linear in the view space.

5
ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs


if (m_VolumetricLightingPreset != VolumetricLightingPreset.Off)
{
// TODO: enable keyword VOLUMETRIC_LIGHTING_ENABLED.
// TODO: set SHADEROPTIONS_VOLUMETRIC_LIGHTING_PRESET.
// TODO: disable keyword VOLUMETRIC_LIGHTING_ENABLED.
// We should not access any volumetric lighting data in our shaders.
// TODO: set SHADEROPTIONS_VOLUMETRIC_LIGHTING_PRESET to 0.
}
}
}

2
ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightEvaluation.hlsl


#endif
}
#ifdef VOLUMETRIC_LIGHTING_ENABLED
#if (SHADEROPTIONS_VOLUMETRIC_LIGHTING_PRESET != 0)
[flatten] if (lightData.lightType == GPULIGHTTYPE_PROJECTOR_BOX)
{
float3 lightToSample = positionWS - lightData.positionWS;

22
ScriptableRenderPipeline/HDRenderPipeline/Lighting/Volumetrics/Resources/VolumetricLighting.compute


#define DEBUG_REPROJECTION 0
#include "../../../ShaderPass/ShaderPass.cs.hlsl"
#define SHADERPASS SHADERPASS_VOLUMETRIC_LIGHTING
#define GROUP_SIZE_1D 16
#define GROUP_SIZE_2D (GROUP_SIZE_1D * GROUP_SIZE_1D)
#define SHADERPASS SHADERPASS_VOLUMETRIC_LIGHTING
#ifdef PRESET_ULTRA
// E.g. for 1080p: (1920/4)x(1080/4)x(256) = 33,177,600 voxels
#define VBUFFER_TILE_SIZE 4
#define VBUFFER_SLICE_COUNT 256
#else
#include "../../../ShaderConfig.cs.hlsl"
#if (SHADEROPTIONS_VOLUMETRIC_LIGHTING_PRESET == 1)
#endif // PRESET_ULTRA
#else
// E.g. for 1080p: (1920/4)x(1080/4)x(256) = 33,177,600 voxels
#define VBUFFER_TILE_SIZE 4
#define VBUFFER_SLICE_COUNT 256
#endif
#define GROUP_SIZE_1D 16
#define GROUP_SIZE_2D (GROUP_SIZE_1D * GROUP_SIZE_1D)
//--------------------------------------------------------------------------------------------------
// Included headers

// TODO: avoid creating another Constant Buffer...
CBUFFER_START(UnityVolumetricLighting)
float4 _VBufferSampleOffset; // {x, y, z}, w = unused
float4 _VBufferSampleOffset; // {x, y, z}, w = rendered frame count
float4x4 _VBufferCoordToViewDirWS; // Actually just 3x3, but Unity can only set 4x4
CBUFFER_END

17
ScriptableRenderPipeline/HDRenderPipeline/Lighting/Volumetrics/VolumetricLighting.cs


Count
};
VolumetricLightingPreset m_VolumetricLightingPreset = VolumetricLightingPreset.Normal;
VolumetricLightingPreset m_VolumetricLightingPreset
{ get { return (VolumetricLightingPreset)Math.Min(ShaderConfig.s_VolumetricLightingPreset, (int)VolumetricLightingPreset.Count); } }
ComputeShader m_VolumetricLightingCS { get { return m_Asset.renderPipelineResources.volumetricLightingCS; } }
float m_VBufferNearPlane = 0.5f; // Distance in meters; dynamic modifications not handled by reprojection

RenderTargetIdentifier GetVBufferLightingHistory() // From the previous frame
{
bool evenFrame = (Time.renderedFrameCount & 1) == 0; // Does not work in the Scene view
return m_VBufferLightingRT[evenFrame ? 0 : 1];
return m_VBufferLightingRT[(Time.renderedFrameCount + 0) & 1]; // Does not work in the Scene view
bool evenFrame = (Time.renderedFrameCount & 1) == 0; // Does not work in the Scene view
return m_VBufferLightingRT[evenFrame ? 1 : 0];
return m_VBufferLightingRT[(Time.renderedFrameCount + 1) & 1]; // Does not work in the Scene view
}
RenderTargetIdentifier GetVBufferLightingIntegral() // Of the current frame

}
bool enableClustered = m_FrameSettings.lightLoopSettings.enableTileAndCluster;
bool enableReprojection = Application.isPlaying;
bool enableReprojection = Application.isPlaying && camera.camera.cameraType == CameraType.Game;
int kernel;

// | x | x | x | x | x | x | x |
float[] zSeq = {7.0f/14.0f, 3.0f/14.0f, 11.0f/14.0f, 5.0f/14.0f, 9.0f/14.0f, 1.0f/14.0f, 13.0f/14.0f};
uint sampleIndex = (uint)Time.renderedFrameCount % 7;
Vector4 offset = new Vector4(xySeq[sampleIndex].x, xySeq[sampleIndex].y, zSeq[sampleIndex]);
int rfc = Time.renderedFrameCount;
int sampleIndex = rfc % 7;
Vector4 offset = new Vector4(xySeq[sampleIndex].x, xySeq[sampleIndex].y, zSeq[sampleIndex], rfc);
// TODO: set 'm_VolumetricLightingPreset'.
cmd.SetComputeVectorParam( m_VolumetricLightingCS, HDShaderIDs._VBufferSampleOffset, offset);

9
ScriptableRenderPipeline/HDRenderPipeline/ShaderConfig.cs


[GenerateHLSL(PackingRules.Exact)]
public enum ShaderOptions
{
CameraRelativeRendering = 1 // Rendering sets the origin of the world to the position of the primary (scene view) camera
CameraRelativeRendering = 1, // Rendering sets the origin of the world to the position of the primary (scene view) camera
VolumetricLightingPreset = 1 // 0 = disabled, 1 = normal, 2 = ultra
};
// 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_CameraRelativeRendering = (int)ShaderOptions.CameraRelativeRendering;
public static int s_CameraRelativeRendering = (int)ShaderOptions.CameraRelativeRendering;
public const int k_CameraRelativeRendering = (int)ShaderOptions.CameraRelativeRendering;
public static int s_CameraRelativeRendering = (int)ShaderOptions.CameraRelativeRendering;
public const int k_VolumetricLightingPreset = (int)ShaderOptions.VolumetricLightingPreset;
public static int s_VolumetricLightingPreset = (int)ShaderOptions.VolumetricLightingPreset;
}
}

1
ScriptableRenderPipeline/HDRenderPipeline/ShaderConfig.cs.hlsl


// UnityEngine.Experimental.Rendering.HDPipeline.ShaderOptions: static fields
//
#define SHADEROPTIONS_CAMERA_RELATIVE_RENDERING (1)
#define SHADEROPTIONS_VOLUMETRIC_LIGHTING_PRESET (1)
#endif

4
ScriptableRenderPipeline/HDRenderPipeline/Sky/AtmosphericScattering/AtmosphericScattering.hlsl


#include "../SkyVariables.hlsl"
#include "../../ShaderVariables.hlsl"
#ifdef VOLUMETRIC_LIGHTING_ENABLED
#if (SHADEROPTIONS_VOLUMETRIC_LIGHTING_PRESET != 0)
TEXTURE3D(_VBufferLighting);
#endif

// Returns fog color in rgb and fog factor in alpha.
float4 EvaluateAtmosphericScattering(PositionInputs posInput)
{
#ifdef VOLUMETRIC_LIGHTING_ENABLED
#if (SHADEROPTIONS_VOLUMETRIC_LIGHTING_PRESET != 0)
return SampleInScatteredRadianceAndTransmittance(TEXTURE3D_PARAM(_VBufferLighting, s_trilinear_clamp_sampler),
posInput.positionNDC, posInput.linearDepth,
_VBufferResolution, _VBufferScaleAndSliceCount,

3
ScriptableRenderPipeline/HDRenderPipeline/Sky/HDRISky/Resources/SkyHDRI.shader


#include "ShaderLibrary/VolumeRendering.hlsl"
TEXTURECUBE(_Cubemap);
#ifdef VOLUMETRIC_LIGHTING_ENABLED
TEXTURE3D(_VBufferLighting);
#endif
float4 _SkyParam; // x exposure, y multiplier, z rotation
float4x4 _PixelCoordToViewDirWS; // Actually just 3x3, but Unity can only set 4x4

正在加载...
取消
保存