浏览代码

Port the VolumetricLightingController to the Interpolation Volume framework

/main
Evgenii Golubev 6 年前
当前提交
98510e9c
共有 2 个文件被更改,包括 21 次插入90 次删除
  1. 61
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/VolumetricLighting.cs
  2. 50
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/VolumetricLightingController.cs

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


Count
} // enum VolumetricLightingPreset
[Serializable]
public struct ControllerParameters
{
public float vBufferNearPlane; // Distance in meters
public float vBufferFarPlane; // Distance in meters
public float depthSliceDistributionUniformity; // Controls the exponential depth distribution: [0, 1]
public static ControllerParameters GetDefaults()
{
ControllerParameters parameters;
parameters.vBufferNearPlane = 0.5f;
parameters.vBufferFarPlane = 64.0f;
parameters.depthSliceDistributionUniformity = 0.75f;
return parameters;
}
} // struct ControllerParameters
public struct VBufferParameters
{
public Vector4 resolution;

public Vector4 depthDecodingParams;
public VBufferParameters(Vector3Int viewportResolution, Vector3Int bufferResolution, ControllerParameters controlParams)
public VBufferParameters(Vector3Int viewportResolution, Vector3Int bufferResolution, Vector2 depthRange, float depthDistributionUniformity)
{
int w = viewportResolution.x;
int h = viewportResolution.y;

resolution = new Vector4(w, h, 1.0f / w, 1.0f / h);
sliceCount = new Vector2(d, 1.0f / d);
uvScaleAndLimit = new Vector4(uvScale.x, uvScale.y, uvLimit.x, uvLimit.y);
depthEncodingParams = Vector4.zero; // C# doesn't allow function calls before all members have been init
depthDecodingParams = Vector4.zero; // C# doesn't allow function calls before all members have been init
Update(controlParams);
}
public void Update(ControllerParameters controlParams)
{
float n = controlParams.vBufferNearPlane;
float f = controlParams.vBufferFarPlane;
float c = 2 - 2 * controlParams.depthSliceDistributionUniformity; // remap [0, 1] -> [2, 0]
float n = depthRange.x;
float f = depthRange.y;
float c = 2 - 2 * depthDistributionUniformity; // remap [0, 1] -> [2, 0]
} // struct Parameters
public VolumetricLightingPreset preset { get { return (VolumetricLightingPreset)Math.Min(ShaderConfig.s_VolumetricLightingPreset, (int)VolumetricLightingPreset.Count); } }

// For the initial allocation, no suballocation happens (the texture is full size).
VBufferParameters ComputeVBufferParameters(HDCamera camera, bool isInitialAllocation)
{
ControllerParameters controlParams;
var controller = camera.camera.GetComponent<VolumetricLightingController>();
if (controller != null)
{
controlParams = controller.parameters;
}
else
{
controlParams = ControllerParameters.GetDefaults();
}
Vector3Int viewportResolution = ComputeVBufferResolution(preset, camera.camera.pixelWidth, camera.camera.pixelHeight);
Vector3Int bufferResolution; // Could be higher due to sub-allocation (resource aliasing) in the RTHandle system

bufferResolution = new Vector3Int(m_LightingBufferHandle.rt.width, m_LightingBufferHandle.rt.height, m_LightingBufferHandle.rt.volumeDepth);
}
return new VBufferParameters(viewportResolution, bufferResolution, controlParams);
var controller = VolumeManager.instance.stack.GetComponent<VolumetricLightingController>();
// We must not allow the V-Buffer to extend outside of the camera's frustum.
float n = camera.camera.nearClipPlane;
float f = camera.camera.farClipPlane;
Vector2 vBufferDepthRange = controller.depthRange.value;
vBufferDepthRange.y = Mathf.Clamp(vBufferDepthRange.y, n, f); // far
vBufferDepthRange.x = Mathf.Clamp(vBufferDepthRange.x, n, vBufferDepthRange.y); // near
float vBufferDepthDistributionUniformity = controller.depthDistributionUniformity.value;
return new VBufferParameters(viewportResolution, bufferResolution, vBufferDepthRange, vBufferDepthDistributionUniformity);
}
public void InitializePerCameraData(HDCamera camera)

50
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/VolumetricLightingController.cs


namespace UnityEngine.Experimental.Rendering.HDPipeline
{
[ExecuteInEditMode]
[AddComponentMenu("Rendering/Volumetric Lighting Controller", 1101)]
public class VolumetricLightingController : MonoBehaviour
public class VolumetricLightingController : VolumeComponent
public VolumetricLightingSystem.ControllerParameters parameters;
public VolumetricLightingController()
{
parameters = VolumetricLightingSystem.ControllerParameters.GetDefaults();
}
private void Awake()
{
}
private void OnEnable()
{
}
private void OnDisable()
{
}
private void Update()
{
}
private void OnValidate()
{
var camera = GetComponent<Camera>();
if (camera != null)
{
// We must not allow the V-Buffer to extend past the camera's frustum.
float n = camera.nearClipPlane;
float f = camera.farClipPlane;
parameters.vBufferFarPlane = Mathf.Clamp(parameters.vBufferFarPlane, n, f);
parameters.vBufferNearPlane = Mathf.Clamp(parameters.vBufferNearPlane, n, parameters.vBufferFarPlane);
parameters.depthSliceDistributionUniformity = Mathf.Clamp01(parameters.depthSliceDistributionUniformity);
}
else
{
Debug.Log("Volumetric Lighting Controller must be attached to a camera!");
}
}
[Tooltip("Near and far planes of camera's volumetric lighting buffers (in meters).")]
public FloatRangeParameter depthRange = new FloatRangeParameter(new Vector2(0.5f, 64.0f), 0.01f, 10000.0f);
[Tooltip("Controls the slice distribution: 0 = exponential (more slices near the camera, fewer slices far away), 1 = linear (uniform spacing).")]
public ClampedFloatParameter depthDistributionUniformity = new ClampedFloatParameter(0.75f, 0, 1);
}
} // UnityEngine.Experimental.Rendering.HDPipeline
正在加载...
取消
保存