Compare commits
2 Commits
e9583e6fdc
...
2d834cf06a
| Author | SHA1 | Date | |
|---|---|---|---|
| 2d834cf06a | |||
| d694bdc43b |
@ -4707,6 +4707,10 @@ PrefabInstance:
|
|||||||
propertyPath: m_Name
|
propertyPath: m_Name
|
||||||
value: NestedParentArmature_Unpack
|
value: NestedParentArmature_Unpack
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 8508310942573128499, guid: c708a3b79cd542b42bbfedb17e213bc1, type: 3}
|
||||||
|
propertyPath: m_RenderPostProcessing
|
||||||
|
value: 1
|
||||||
|
objectReference: {fileID: 0}
|
||||||
m_RemovedComponents:
|
m_RemovedComponents:
|
||||||
- {fileID: 3543048675319490572, guid: c708a3b79cd542b42bbfedb17e213bc1, type: 3}
|
- {fileID: 3543048675319490572, guid: c708a3b79cd542b42bbfedb17e213bc1, type: 3}
|
||||||
m_RemovedGameObjects: []
|
m_RemovedGameObjects: []
|
||||||
|
|||||||
@ -1,6 +1,3 @@
|
|||||||
using System;
|
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Rendering;
|
using UnityEngine.Rendering;
|
||||||
|
|
||||||
|
|||||||
@ -63,6 +63,41 @@ MonoBehaviour:
|
|||||||
- {fileID: 5935297997615179469}
|
- {fileID: 5935297997615179469}
|
||||||
- {fileID: -4720686990112659349}
|
- {fileID: -4720686990112659349}
|
||||||
- {fileID: 9109530758031880643}
|
- {fileID: 9109530758031880643}
|
||||||
|
- {fileID: 4702212335856883116}
|
||||||
|
--- !u!114 &4702212335856883116
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 3
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 0}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: af08f034e95c2d246b0cbaf4305dfbc4, type: 3}
|
||||||
|
m_Name: AutoExposureVolumeProfile
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
active: 1
|
||||||
|
filtering:
|
||||||
|
m_OverrideState: 0
|
||||||
|
m_Value: {x: 50, y: 95}
|
||||||
|
minLuminance:
|
||||||
|
m_OverrideState: 0
|
||||||
|
m_Value: 0
|
||||||
|
maxLuminance:
|
||||||
|
m_OverrideState: 0
|
||||||
|
m_Value: 0
|
||||||
|
exposureCompensation:
|
||||||
|
m_OverrideState: 0
|
||||||
|
m_Value: 1
|
||||||
|
eyeAdaptation:
|
||||||
|
m_OverrideState: 0
|
||||||
|
m_Value: 0
|
||||||
|
speedUp:
|
||||||
|
m_OverrideState: 0
|
||||||
|
m_Value: 2
|
||||||
|
speedDown:
|
||||||
|
m_OverrideState: 0
|
||||||
|
m_Value: 1
|
||||||
--- !u!114 &5935297997615179469
|
--- !u!114 &5935297997615179469
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
m_ObjectHideFlags: 3
|
m_ObjectHideFlags: 3
|
||||||
|
|||||||
@ -75,7 +75,7 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: 5a00a63fdd6bd2a45ab1f2d869305ffd, type: 3}
|
m_Script: {fileID: 11500000, guid: 5a00a63fdd6bd2a45ab1f2d869305ffd, type: 3}
|
||||||
m_Name: OasisFogVolumeComponent
|
m_Name: OasisFogVolumeComponent
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
active: 1
|
active: 0
|
||||||
Density:
|
Density:
|
||||||
m_OverrideState: 1
|
m_OverrideState: 1
|
||||||
m_Value: 0.002
|
m_Value: 0.002
|
||||||
@ -103,7 +103,7 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: 66f335fb1ffd8684294ad653bf1c7564, type: 3}
|
m_Script: {fileID: 11500000, guid: 66f335fb1ffd8684294ad653bf1c7564, type: 3}
|
||||||
m_Name: ColorAdjustments
|
m_Name: ColorAdjustments
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
active: 1
|
active: 0
|
||||||
postExposure:
|
postExposure:
|
||||||
m_OverrideState: 1
|
m_OverrideState: 1
|
||||||
m_Value: 2
|
m_Value: 2
|
||||||
|
|||||||
@ -108,6 +108,25 @@ MonoBehaviour:
|
|||||||
cutoffThreshold: 0.2
|
cutoffThreshold: 0.2
|
||||||
binaryValue: 0.9
|
binaryValue: 0.9
|
||||||
flags: 13
|
flags: 13
|
||||||
|
--- !u!114 &-7143664486661302651
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 0}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: d34dacd53c1ace84a8c6ac5ff4afb555, type: 3}
|
||||||
|
m_Name: AutoExposure
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
m_Active: 1
|
||||||
|
settings:
|
||||||
|
HistogramRenderPassEvent: 550
|
||||||
|
AutoExposureRenderPassEvent: 550
|
||||||
|
BlitMat: {fileID: 2100000, guid: b04591ed716b35e41857f554d491ef4b, type: 2}
|
||||||
|
ComputeHistogramComputeShader: {fileID: 7200000, guid: b140e27dc74a1fb4d9ae30f8566b8919, type: 3}
|
||||||
|
AutoExposureComputeShader: {fileID: 7200000, guid: 6febb5a945f3510429c58ed4a45c1846, type: 3}
|
||||||
--- !u!114 &-5418649131825517062
|
--- !u!114 &-5418649131825517062
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@ -337,7 +356,8 @@ MonoBehaviour:
|
|||||||
- {fileID: 7541218312462517771}
|
- {fileID: 7541218312462517771}
|
||||||
- {fileID: 5808157236138506604}
|
- {fileID: 5808157236138506604}
|
||||||
- {fileID: -5418649131825517062}
|
- {fileID: -5418649131825517062}
|
||||||
m_RendererFeatureMap: bc3f630842f2e70dd6a559c442a94bfd4529d15534f2d3de228858dca8d12222716523fbf3439fdb7a327b7bff4bdd446ac59dfa966ffa88ca6373cd5da9013d6cff55ca297e5e908a7b3653203b82383b2141bb05fbe69aec5704e48e2763e90bc6ff9f19caa7686c79a6bb3bb89a50faad0fe75217cdb4
|
- {fileID: -7143664486661302651}
|
||||||
|
m_RendererFeatureMap: bc3f630842f2e70dd6a559c442a94bfd4529d15534f2d3de228858dca8d12222716523fbf3439fdb7a327b7bff4bdd446ac59dfa966ffa88ca6373cd5da9013d6cff55ca297e5e908a7b3653203b82383b2141bb05fbe69aec5704e48e2763e90bc6ff9f19caa7686c79a6bb3bb89a50faad0fe75217cdb485d6fa85ff9adc9c
|
||||||
m_UseNativeRenderPass: 0
|
m_UseNativeRenderPass: 0
|
||||||
postProcessData: {fileID: 11400000, guid: 41439944d30ece34e96484bdb6645b55, type: 2}
|
postProcessData: {fileID: 11400000, guid: 41439944d30ece34e96484bdb6645b55, type: 2}
|
||||||
shaders:
|
shaders:
|
||||||
|
|||||||
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 22bff87638890aa4c9ea2a933d910433
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,235 @@
|
|||||||
|
using System;
|
||||||
|
using System.Drawing.Drawing2D;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.Experimental.Rendering;
|
||||||
|
using UnityEngine.Rendering;
|
||||||
|
using UnityEngine.Rendering.Universal;
|
||||||
|
|
||||||
|
namespace X.Rendering.Feature
|
||||||
|
{
|
||||||
|
public class AutoExposure : ScriptableRendererFeature
|
||||||
|
{
|
||||||
|
[Serializable]
|
||||||
|
public class Settings
|
||||||
|
{
|
||||||
|
public RenderPassEvent HistogramRenderPassEvent = RenderPassEvent.BeforeRenderingPostProcessing;
|
||||||
|
public RenderPassEvent AutoExposureRenderPassEvent = RenderPassEvent.BeforeRenderingPostProcessing;
|
||||||
|
public Material BlitMat;
|
||||||
|
public ComputeShader ComputeHistogramComputeShader;
|
||||||
|
public ComputeShader AutoExposureComputeShader;
|
||||||
|
}
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
Settings settings;
|
||||||
|
AutoExposurePass autoExposurePass;
|
||||||
|
ComputeLuminanceHistogramPass computeLuminanceHistogramPass;
|
||||||
|
|
||||||
|
public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
|
||||||
|
{
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
if(renderingData.cameraData.isSceneViewCamera || renderingData.cameraData.isPreviewCamera)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
renderer.EnqueuePass(computeLuminanceHistogramPass);
|
||||||
|
renderer.EnqueuePass(autoExposurePass);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Create()
|
||||||
|
{
|
||||||
|
computeLuminanceHistogramPass = new(settings);
|
||||||
|
autoExposurePass = new(settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
base.Dispose(disposing);
|
||||||
|
autoExposurePass?.Dispose();
|
||||||
|
computeLuminanceHistogramPass?.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
class ComputeLuminanceHistogramPass : ScriptableRenderPass, IDisposable
|
||||||
|
{
|
||||||
|
private ProfilingSampler profiler;
|
||||||
|
private Settings settings;
|
||||||
|
private GraphicsBuffer histogramBuffer;
|
||||||
|
|
||||||
|
public const int k_Bins = 128;
|
||||||
|
public static GraphicsBufferHandle HistogramBufferHandle;
|
||||||
|
|
||||||
|
public ComputeLuminanceHistogramPass(Settings settings)
|
||||||
|
{
|
||||||
|
this.settings = settings;
|
||||||
|
profiler = new(nameof(ComputeLuminanceHistogramPass));
|
||||||
|
renderPassEvent = settings.HistogramRenderPassEvent;
|
||||||
|
histogramBuffer = new GraphicsBuffer(GraphicsBuffer.Target.Structured, k_Bins, sizeof(uint));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
histogramBuffer?.Release();
|
||||||
|
histogramBuffer = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
|
||||||
|
{
|
||||||
|
var stack = VolumeManager.instance.stack;
|
||||||
|
var autoExposureVolume = stack.GetComponent<AutoExposureVolumeProfile>();
|
||||||
|
if (!autoExposureVolume || !autoExposureVolume.IsActive())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var cmd = renderingData.commandBuffer;
|
||||||
|
using var scp = new ProfilingScope(cmd, profiler);
|
||||||
|
var scaleOffsetRes = AutoExposureVolumeProfile.GetHistogramScaleOffsetRes();
|
||||||
|
var computeShader = settings.ComputeHistogramComputeShader;
|
||||||
|
int kernel = computeShader.FindKernel("KEyeHistogramClear");
|
||||||
|
cmd.SetComputeBufferParam(computeShader, kernel, "_HistogramBuffer", histogramBuffer);
|
||||||
|
computeShader.GetKernelThreadGroupSizes(kernel, out var threadX, out var threadY, out var threadZ);
|
||||||
|
cmd.DispatchCompute(computeShader, kernel, Mathf.CeilToInt(k_Bins / (float)threadX), 1, 1);
|
||||||
|
|
||||||
|
// Get a log histogram
|
||||||
|
kernel = 1;
|
||||||
|
HistogramBufferHandle = histogramBuffer.bufferHandle;
|
||||||
|
cmd.SetComputeBufferParam(computeShader, kernel, "_HistogramBuffer", histogramBuffer);
|
||||||
|
cmd.SetComputeTextureParam(computeShader, kernel, "_Source", renderingData.cameraData.renderer.cameraColorTargetHandle);
|
||||||
|
cmd.SetComputeVectorParam(computeShader, "_ScaleOffsetRes", scaleOffsetRes);
|
||||||
|
|
||||||
|
computeShader.GetKernelThreadGroupSizes(kernel, out threadX, out threadY, out threadZ);
|
||||||
|
|
||||||
|
cmd.DispatchCompute(computeShader, kernel,
|
||||||
|
Mathf.CeilToInt(scaleOffsetRes.z / 2f / threadX),
|
||||||
|
Mathf.CeilToInt(scaleOffsetRes.w / 2f / threadY),
|
||||||
|
1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AutoExposurePass : ScriptableRenderPass, IDisposable
|
||||||
|
{
|
||||||
|
private Settings settings;
|
||||||
|
private int computeCounter;
|
||||||
|
private ProfilingSampler profiler;
|
||||||
|
|
||||||
|
const int k_NumAutoExposureTextures = 2;
|
||||||
|
private RTHandle[] autoExposureHandles;
|
||||||
|
private int autoExposurePingPong;
|
||||||
|
|
||||||
|
private static AutoExposureVolumeProfile autoExposureVolume = null;
|
||||||
|
private bool reset = false;
|
||||||
|
|
||||||
|
public AutoExposurePass(Settings settings)
|
||||||
|
{
|
||||||
|
this.settings = settings;
|
||||||
|
renderPassEvent = settings.AutoExposureRenderPassEvent;
|
||||||
|
profiler = new(nameof(AutoExposurePass));
|
||||||
|
|
||||||
|
var desc = new RenderTextureDescriptor(1,1,GraphicsFormat.R32_SFloat,0,1)
|
||||||
|
{
|
||||||
|
enableRandomWrite = true,
|
||||||
|
msaaSamples = 1,
|
||||||
|
useMipMap = false
|
||||||
|
};
|
||||||
|
|
||||||
|
autoExposureHandles = new RTHandle[k_NumAutoExposureTextures];
|
||||||
|
|
||||||
|
for (var i = 0; i < autoExposureHandles.Length; i++)
|
||||||
|
{
|
||||||
|
RenderingUtils.ReAllocateIfNeeded(ref autoExposureHandles[i], desc, name: $"AutoExposure_{i}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
|
||||||
|
{
|
||||||
|
var stack = VolumeManager.instance.stack;
|
||||||
|
autoExposureVolume = stack.GetComponent<AutoExposureVolumeProfile>();
|
||||||
|
if (!autoExposureVolume || !autoExposureVolume.IsActive())
|
||||||
|
{
|
||||||
|
reset = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var cmd = renderingData.commandBuffer;
|
||||||
|
using var scp = new ProfilingScope(cmd, profiler);
|
||||||
|
var filteringMinMax = autoExposureVolume.filtering.value;
|
||||||
|
float lowPercent = filteringMinMax.x;
|
||||||
|
float highPercent = filteringMinMax.y;
|
||||||
|
const float kMinDelta = 1e-2f;
|
||||||
|
highPercent = Mathf.Clamp(highPercent, 1f + kMinDelta, 99f);
|
||||||
|
lowPercent = Mathf.Clamp(lowPercent, 1f, highPercent - kMinDelta);
|
||||||
|
|
||||||
|
// Clamp min/max adaptation values as well
|
||||||
|
float minLum = autoExposureVolume.minLuminance.value;
|
||||||
|
float maxLum = autoExposureVolume.maxLuminance.value;
|
||||||
|
minLum = Mathf.Min(minLum, maxLum);
|
||||||
|
maxLum = Mathf.Max(minLum, maxLum);
|
||||||
|
var speedDown = Mathf.Max(0, autoExposureVolume.speedDown.value);
|
||||||
|
var speedUp = Mathf.Max(0, autoExposureVolume.speedUp.value);
|
||||||
|
var exposureCompensation = autoExposureVolume.exposureCompensation.value;
|
||||||
|
string adaptation = null;
|
||||||
|
|
||||||
|
if (autoExposureVolume.eyeAdaptation.value == AutoExposureVolumeProfile.EyeAdaptation.Fixed)
|
||||||
|
adaptation = "KAutoExposureAvgLuminance_fixed";
|
||||||
|
else
|
||||||
|
adaptation = "KAutoExposureAvgLuminance_progressive";
|
||||||
|
|
||||||
|
var compute = settings.AutoExposureComputeShader;
|
||||||
|
int kernel = compute.FindKernel(adaptation);
|
||||||
|
int pp = autoExposurePingPong;
|
||||||
|
var src = autoExposureHandles[++pp % 2];
|
||||||
|
var dst = autoExposureHandles[++pp % 2];
|
||||||
|
|
||||||
|
if (reset)
|
||||||
|
{
|
||||||
|
cmd.SetRenderTarget(src, loadAction: RenderBufferLoadAction.DontCare, storeAction: RenderBufferStoreAction.Store);
|
||||||
|
cmd.ClearRenderTarget(false, true, Color.clear);
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.SetComputeBufferParam(compute, kernel, "_HistogramBuffer", ComputeLuminanceHistogramPass.HistogramBufferHandle);
|
||||||
|
cmd.SetComputeVectorParam(compute, "_Params1", new Vector4(lowPercent * 0.01f, highPercent * 0.01f, Mathf.Pow(2, minLum), Mathf.Pow(2, maxLum)));
|
||||||
|
cmd.SetComputeVectorParam(compute, "_Params2", new Vector4(speedDown, speedUp, exposureCompensation, Time.smoothDeltaTime));
|
||||||
|
cmd.SetComputeVectorParam(compute, "_ScaleOffsetRes", AutoExposureVolumeProfile.GetHistogramScaleOffsetRes());
|
||||||
|
|
||||||
|
cmd.SetComputeTextureParam(compute, kernel, "_Source", src);
|
||||||
|
cmd.SetComputeTextureParam(compute, kernel, "_Destination", dst);
|
||||||
|
cmd.DispatchCompute(compute, kernel, 1, 1, 1);
|
||||||
|
autoExposurePingPong = ++pp % 2;
|
||||||
|
|
||||||
|
|
||||||
|
var renderer = renderingData.cameraData.renderer;
|
||||||
|
settings.BlitMat.SetTexture("_SourceTexture", renderer.cameraColorTargetHandle);
|
||||||
|
settings.BlitMat.SetTexture("_AutoExposureTexture", dst);
|
||||||
|
var destination = renderer.GetCameraColorFrontBuffer(cmd);
|
||||||
|
cmd.SetRenderTarget(destination, loadAction: RenderBufferLoadAction.DontCare, storeAction: RenderBufferStoreAction.Store);
|
||||||
|
cmd.DrawProcedural(Matrix4x4.identity, settings.BlitMat, 0, MeshTopology.Triangles, 3);
|
||||||
|
renderer.SwapColorBuffer(cmd);
|
||||||
|
reset = false;
|
||||||
|
//cmd.RequestAsyncReadback(dst, (a) =>
|
||||||
|
//{
|
||||||
|
// if (!a.hasError)
|
||||||
|
// {
|
||||||
|
// var data = a.GetData<float>();
|
||||||
|
// for (var i = 0; i < data.Length; i++)
|
||||||
|
// {
|
||||||
|
// Debug.Log(data[i]);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
if (autoExposureHandles != null)
|
||||||
|
{
|
||||||
|
foreach (var autoExposureHandle in autoExposureHandles)
|
||||||
|
{
|
||||||
|
autoExposureHandle?.Release();
|
||||||
|
}
|
||||||
|
|
||||||
|
autoExposureHandles = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d34dacd53c1ace84a8c6ac5ff4afb555
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,86 @@
|
|||||||
|
using System;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.Rendering;
|
||||||
|
using UnityEngine.Rendering.Universal;
|
||||||
|
|
||||||
|
namespace X.Rendering.Feature
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
public class AutoExposureVolumeProfile : VolumeComponent, IPostProcessComponent
|
||||||
|
{
|
||||||
|
public const int rangeMin = -9; // ev
|
||||||
|
public const int rangeMax = 9; // ev
|
||||||
|
|
||||||
|
public static Vector4 GetHistogramScaleOffsetRes()
|
||||||
|
{
|
||||||
|
float diff = rangeMax - rangeMin;
|
||||||
|
float scale = 1f / diff;
|
||||||
|
float offset = -rangeMin * scale;
|
||||||
|
return new Vector4(scale, offset, Screen.width, Screen.height);
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum EyeAdaptation
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Progressive (smooth) eye adaptation.
|
||||||
|
/// </summary>
|
||||||
|
Progressive,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Fixed (instant) eye adaptation.
|
||||||
|
/// </summary>
|
||||||
|
Fixed
|
||||||
|
}
|
||||||
|
|
||||||
|
[Serializable]
|
||||||
|
public sealed class EyeAdaptationParameter : VolumeParameter<EyeAdaptation> { }
|
||||||
|
|
||||||
|
[Range(1f, 99f)]
|
||||||
|
public Vector2Parameter filtering = new Vector2Parameter(new Vector2(50f, 95f));
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Minimum average luminance to consider for auto exposure (in EV).
|
||||||
|
/// </summary>
|
||||||
|
[Range(rangeMin, rangeMax), InspectorName("Minimum (EV)")]
|
||||||
|
public FloatParameter minLuminance = new FloatParameter (0f);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Maximum average luminance to consider for auto exposure (in EV).
|
||||||
|
/// </summary>
|
||||||
|
[Range(rangeMin, rangeMax), InspectorName("Maximum (EV)")]
|
||||||
|
public FloatParameter maxLuminance = new FloatParameter (0f);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Middle-grey value. Use this to compensate the global exposure of the scene.
|
||||||
|
/// </summary>
|
||||||
|
[Min(0f), InspectorName("Exposure Compensation"), Tooltip("Use this to scale the global exposure of the scene.")]
|
||||||
|
public FloatParameter exposureCompensation = new FloatParameter (1f);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The type of eye adaptation to use.
|
||||||
|
/// </summary>
|
||||||
|
[InspectorName("Type"), Tooltip("Use \"Progressive\" if you want auto exposure to be animated. Use \"Fixed\" otherwise.")]
|
||||||
|
public EyeAdaptationParameter eyeAdaptation = new EyeAdaptationParameter() { value = EyeAdaptation.Progressive };
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The adaptation speed from a dark to a light environment.
|
||||||
|
/// </summary>
|
||||||
|
[Min(0f), Tooltip("Adaptation speed from a dark to a light environment.")]
|
||||||
|
public FloatParameter speedUp = new FloatParameter (2f);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The adaptation speed from a light to a dark environment.
|
||||||
|
/// </summary>
|
||||||
|
[Min(0f), Tooltip("Adaptation speed from a light to a dark environment.")]
|
||||||
|
public FloatParameter speedDown = new FloatParameter (1f);
|
||||||
|
|
||||||
|
|
||||||
|
public bool IsActive() => filtering.overrideState;
|
||||||
|
|
||||||
|
public bool IsTileCompatible()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: af08f034e95c2d246b0cbaf4305dfbc4
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: e293ab2d371d5a04c941cba0a04a7ecc
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,184 @@
|
|||||||
|
#pragma warning(disable : 3568)
|
||||||
|
|
||||||
|
#pragma kernel KAutoExposureAvgLuminance_fixed MAIN=KAutoExposureAvgLuminance_fixed
|
||||||
|
#pragma kernel KAutoExposureAvgLuminance_progressive MAIN=KAutoExposureAvgLuminance_progressive PROGRESSIVE
|
||||||
|
|
||||||
|
#pragma enable_d3d11_debug_symbols
|
||||||
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||||
|
#define EPSILON 1.0e-4
|
||||||
|
|
||||||
|
#define HISTOGRAM_BINS 128
|
||||||
|
#define HISTOGRAM_TEXELS HISTOGRAM_BINS / 4
|
||||||
|
|
||||||
|
#if SHADER_API_GLES3 || SHADER_API_METAL
|
||||||
|
#define HISTOGRAM_THREAD_X 8
|
||||||
|
#define HISTOGRAM_THREAD_Y 8
|
||||||
|
#define HISTOGRAM_REDUCTION_THREAD_X 8
|
||||||
|
#define HISTOGRAM_REDUCTION_THREAD_Y 8
|
||||||
|
#define HISTOGRAM_REDUCTION_ALT_PATH 1
|
||||||
|
#else
|
||||||
|
#define HISTOGRAM_THREAD_X 16
|
||||||
|
#define HISTOGRAM_THREAD_Y 16
|
||||||
|
#define HISTOGRAM_REDUCTION_THREAD_X HISTOGRAM_THREAD_X
|
||||||
|
#define HISTOGRAM_REDUCTION_THREAD_Y HISTOGRAM_BINS / HISTOGRAM_THREAD_Y
|
||||||
|
#define HISTOGRAM_REDUCTION_ALT_PATH 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define HISTOGRAM_REDUCTION_BINS HISTOGRAM_REDUCTION_THREAD_X * HISTOGRAM_REDUCTION_THREAD_Y
|
||||||
|
|
||||||
|
half Luminance(half3 linearRgb)
|
||||||
|
{
|
||||||
|
return dot(linearRgb, float3(0.2126729, 0.7151522, 0.0721750));
|
||||||
|
}
|
||||||
|
|
||||||
|
half Luminance(half4 linearRgba)
|
||||||
|
{
|
||||||
|
return Luminance(linearRgba.rgb);
|
||||||
|
}
|
||||||
|
|
||||||
|
float GetHistogramBinFromLuminance(float value, float2 scaleOffset)
|
||||||
|
{
|
||||||
|
return saturate(log2(value) * scaleOffset.x + scaleOffset.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
float GetLuminanceFromHistogramBin(float bin, float2 scaleOffset)
|
||||||
|
{
|
||||||
|
return exp2((bin - scaleOffset.y) / scaleOffset.x);
|
||||||
|
}
|
||||||
|
|
||||||
|
float GetBinValue(StructuredBuffer<uint> buffer, uint index, float maxHistogramValue)
|
||||||
|
{
|
||||||
|
return float(buffer[index]) * maxHistogramValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
float FindMaxHistogramValue(StructuredBuffer<uint> buffer)
|
||||||
|
{
|
||||||
|
uint maxValue = 0u;
|
||||||
|
|
||||||
|
for (uint i = 0; i < HISTOGRAM_BINS; i++)
|
||||||
|
{
|
||||||
|
uint h = buffer[i];
|
||||||
|
maxValue = max(maxValue, h);
|
||||||
|
}
|
||||||
|
|
||||||
|
return float(maxValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FilterLuminance(StructuredBuffer<uint> buffer, uint i, float maxHistogramValue, float2 scaleOffset, inout float4 filter)
|
||||||
|
{
|
||||||
|
float binValue = GetBinValue(buffer, i, maxHistogramValue);
|
||||||
|
|
||||||
|
// Filter dark areas
|
||||||
|
float offset = min(filter.z, binValue);
|
||||||
|
binValue -= offset;
|
||||||
|
filter.zw -= offset.xx;
|
||||||
|
|
||||||
|
// Filter highlights
|
||||||
|
binValue = min(filter.w, binValue);
|
||||||
|
filter.w -= binValue;
|
||||||
|
|
||||||
|
// Luminance at the bin
|
||||||
|
float luminance = GetLuminanceFromHistogramBin(float(i) / float(HISTOGRAM_BINS), scaleOffset);
|
||||||
|
|
||||||
|
filter.xy += float2(luminance * binValue, binValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
float GetAverageLuminance(StructuredBuffer<uint> buffer, float4 params, float maxHistogramValue, float2 scaleOffset)
|
||||||
|
{
|
||||||
|
// Sum of all bins
|
||||||
|
uint i;
|
||||||
|
float totalSum = 0.0;
|
||||||
|
|
||||||
|
UNITY_UNROLL
|
||||||
|
|
||||||
|
for (i = 0; i < HISTOGRAM_BINS; i++)
|
||||||
|
totalSum += GetBinValue(buffer, i, maxHistogramValue);
|
||||||
|
|
||||||
|
// Skip darker and lighter parts of the histogram to stabilize the auto exposure
|
||||||
|
// x: filtered sum
|
||||||
|
// y: accumulator
|
||||||
|
// zw: fractions
|
||||||
|
float4 filter = float4(0.0, 0.0, totalSum * params.xy);
|
||||||
|
|
||||||
|
UNITY_UNROLL
|
||||||
|
|
||||||
|
for (i = 0; i < HISTOGRAM_BINS; i++)
|
||||||
|
FilterLuminance(buffer, i, maxHistogramValue, scaleOffset, filter);
|
||||||
|
|
||||||
|
// Clamp to user brightness range
|
||||||
|
return clamp(filter.x / max(filter.y, EPSILON), params.z, params.w);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
StructuredBuffer<uint> _HistogramBuffer;
|
||||||
|
Texture2D<float> _Source;
|
||||||
|
RWTexture2D<float> _Destination;
|
||||||
|
|
||||||
|
float4 _Params1; // x: lowPercent, y: highPercent, z: minBrightness, w: maxBrightness
|
||||||
|
float4 _Params2; // x: speed down, y: speed up, z: exposure compensation, w: delta time
|
||||||
|
float4 _ScaleOffsetRes; // x: scale, y: offset, w: histogram pass width, h: histogram pass height
|
||||||
|
|
||||||
|
groupshared uint gs_pyramid[HISTOGRAM_REDUCTION_BINS];
|
||||||
|
|
||||||
|
float GetExposureMultiplier(float avgLuminance)
|
||||||
|
{
|
||||||
|
avgLuminance = max(EPSILON, avgLuminance);
|
||||||
|
//float keyValue = 1.03 - (2.0 / (2.0 + log2(avgLuminance + 1.0)));
|
||||||
|
float keyValue = _Params2.z;
|
||||||
|
float exposure = keyValue / avgLuminance;
|
||||||
|
return exposure;
|
||||||
|
}
|
||||||
|
|
||||||
|
float InterpolateExposure(float newExposure, float oldExposure)
|
||||||
|
{
|
||||||
|
float delta = newExposure - oldExposure;
|
||||||
|
float speed = delta > 0.0 ? _Params2.x : _Params2.y;
|
||||||
|
float exposure = oldExposure + delta * (1.0 - exp2(-_Params2.w * speed));
|
||||||
|
return exposure;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[numthreads(HISTOGRAM_REDUCTION_THREAD_X, HISTOGRAM_REDUCTION_THREAD_Y, 1)]
|
||||||
|
void MAIN(uint2 groupThreadId : SV_GroupThreadID)
|
||||||
|
{
|
||||||
|
#if HISTOGRAM_REDUCTION_ALT_PATH
|
||||||
|
const uint thread_id = groupThreadId.y * HISTOGRAM_REDUCTION_THREAD_X + groupThreadId.x;
|
||||||
|
gs_pyramid[thread_id] = max(_HistogramBuffer[thread_id], _HistogramBuffer[thread_id + HISTOGRAM_REDUCTION_BINS]);
|
||||||
|
#else
|
||||||
|
const uint thread_id = groupThreadId.y * HISTOGRAM_REDUCTION_THREAD_X + groupThreadId.x;
|
||||||
|
gs_pyramid[thread_id] = _HistogramBuffer[thread_id];
|
||||||
|
#endif
|
||||||
|
|
||||||
|
GroupMemoryBarrierWithGroupSync();
|
||||||
|
|
||||||
|
// Parallel reduction to find the max value
|
||||||
|
UNITY_UNROLL
|
||||||
|
|
||||||
|
for (uint i = HISTOGRAM_REDUCTION_BINS >> 1u; i > 0u; i >>= 1u)
|
||||||
|
{
|
||||||
|
if (thread_id < i)
|
||||||
|
gs_pyramid[thread_id] = max(gs_pyramid[thread_id], gs_pyramid[thread_id + i]);
|
||||||
|
|
||||||
|
GroupMemoryBarrierWithGroupSync();
|
||||||
|
}
|
||||||
|
|
||||||
|
GroupMemoryBarrierWithGroupSync();
|
||||||
|
|
||||||
|
if (thread_id == 0u)
|
||||||
|
{
|
||||||
|
float maxValue = 1.0 / float(gs_pyramid[0]);
|
||||||
|
|
||||||
|
#if PROGRESSIVE
|
||||||
|
float avgLuminance = GetAverageLuminance(_HistogramBuffer, _Params1, maxValue, _ScaleOffsetRes.xy);
|
||||||
|
float exposure = GetExposureMultiplier(avgLuminance);
|
||||||
|
float prevExposure = _Source[uint2(0u, 0u)].x;
|
||||||
|
exposure = InterpolateExposure(exposure, prevExposure);
|
||||||
|
_Destination[uint2(0u, 0u)].x = exposure.x;
|
||||||
|
#else
|
||||||
|
float avgLuminance = GetAverageLuminance(_HistogramBuffer, _Params1, maxValue, _ScaleOffsetRes.xy);
|
||||||
|
float exposure = GetExposureMultiplier(avgLuminance);
|
||||||
|
_Destination[uint2(0u, 0u)].x = exposure.x;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 6febb5a945f3510429c58ed4a45c1846
|
||||||
|
ComputeShaderImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,52 @@
|
|||||||
|
Shader "XRP/AutoExposure"
|
||||||
|
{
|
||||||
|
SubShader
|
||||||
|
{
|
||||||
|
Tags
|
||||||
|
{
|
||||||
|
"RenderType"="Opaque"
|
||||||
|
}
|
||||||
|
ZWrite Off Cull Off
|
||||||
|
|
||||||
|
Pass
|
||||||
|
{
|
||||||
|
Name "Auto Exposure Pass"
|
||||||
|
|
||||||
|
HLSLPROGRAM
|
||||||
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||||
|
#include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
|
||||||
|
|
||||||
|
// #pragma enable_d3d11_debug_symbols
|
||||||
|
|
||||||
|
#pragma vertex vert
|
||||||
|
#pragma fragment frag
|
||||||
|
|
||||||
|
TEXTURE2D_X(_SourceTexture);
|
||||||
|
TEXTURE2D_X(_AutoExposureTexture);
|
||||||
|
|
||||||
|
half GammaCorrect_half(half linearColor)
|
||||||
|
{
|
||||||
|
return pow(linearColor,1/2.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
Varyings vert(uint vertexID: SV_VertexID)
|
||||||
|
{
|
||||||
|
Varyings o;
|
||||||
|
o.positionCS = GetFullScreenTriangleVertexPosition(vertexID);
|
||||||
|
o.texcoord = GetFullScreenTriangleTexCoord(vertexID);
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
|
||||||
|
float4 frag(Varyings input) : SV_Target
|
||||||
|
{
|
||||||
|
float2 uv = input.texcoord.xy;
|
||||||
|
half4 color = SAMPLE_TEXTURE2D_X_LOD(_SourceTexture, sampler_LinearClamp, uv, _BlitMipLevel);
|
||||||
|
float luminance = GammaCorrect_half(SAMPLE_TEXTURE2D_X_LOD(_AutoExposureTexture, sampler_LinearRepeat, float2(0,0), _BlitMipLevel).x) ;
|
||||||
|
|
||||||
|
return color * luminance;
|
||||||
|
}
|
||||||
|
|
||||||
|
ENDHLSL
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 86423a03f0e6a0441b2b00ff89b6c753
|
||||||
|
ShaderImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
defaultTextures: []
|
||||||
|
nonModifiableTextures: []
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,134 @@
|
|||||||
|
#pragma warning(disable : 3568)
|
||||||
|
|
||||||
|
#pragma kernel KEyeHistogram
|
||||||
|
#pragma kernel KEyeHistogram USE_VIGNETTE_WEIGHTING
|
||||||
|
#pragma kernel KEyeHistogramClear
|
||||||
|
#pragma enable_d3d11_debug_symbols
|
||||||
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||||
|
#define EPSILON 1.0e-4
|
||||||
|
|
||||||
|
#define HISTOGRAM_BINS 128
|
||||||
|
#define HISTOGRAM_TEXELS HISTOGRAM_BINS / 4
|
||||||
|
|
||||||
|
#if SHADER_API_GLES3 || SHADER_API_METAL
|
||||||
|
#define HISTOGRAM_THREAD_X 8
|
||||||
|
#define HISTOGRAM_THREAD_Y 8
|
||||||
|
#define HISTOGRAM_REDUCTION_THREAD_X 8
|
||||||
|
#define HISTOGRAM_REDUCTION_THREAD_Y 8
|
||||||
|
#define HISTOGRAM_REDUCTION_ALT_PATH 1
|
||||||
|
#else
|
||||||
|
#define HISTOGRAM_THREAD_X 16
|
||||||
|
#define HISTOGRAM_THREAD_Y 16
|
||||||
|
#define HISTOGRAM_REDUCTION_THREAD_X HISTOGRAM_THREAD_X
|
||||||
|
#define HISTOGRAM_REDUCTION_THREAD_Y HISTOGRAM_BINS / HISTOGRAM_THREAD_Y
|
||||||
|
#define HISTOGRAM_REDUCTION_ALT_PATH 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define HISTOGRAM_REDUCTION_BINS HISTOGRAM_REDUCTION_THREAD_X * HISTOGRAM_REDUCTION_THREAD_Y
|
||||||
|
|
||||||
|
half Luminance(half3 linearRgb)
|
||||||
|
{
|
||||||
|
return dot(linearRgb, float3(0.2126729, 0.7151522, 0.0721750));
|
||||||
|
}
|
||||||
|
|
||||||
|
half Luminance(half4 linearRgba)
|
||||||
|
{
|
||||||
|
return Luminance(linearRgba.rgb);
|
||||||
|
}
|
||||||
|
float GetHistogramBinFromLuminance(float value, float2 scaleOffset)
|
||||||
|
{
|
||||||
|
return saturate(log2(value) * scaleOffset.x + scaleOffset.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
float GetLuminanceFromHistogramBin(float bin, float2 scaleOffset)
|
||||||
|
{
|
||||||
|
return exp2((bin - scaleOffset.y) / scaleOffset.x);
|
||||||
|
}
|
||||||
|
|
||||||
|
float GetBinValue(StructuredBuffer<uint> buffer, uint index, float maxHistogramValue)
|
||||||
|
{
|
||||||
|
return float(buffer[index]) * maxHistogramValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
RWStructuredBuffer<uint> _HistogramBuffer;
|
||||||
|
Texture2D<float4> _Source;
|
||||||
|
SamplerState sampler_LinearClamp;
|
||||||
|
|
||||||
|
cbuffer Params
|
||||||
|
{
|
||||||
|
float4 _ScaleOffsetRes; // x: scale, y: offset, z: width, w: height
|
||||||
|
};
|
||||||
|
|
||||||
|
groupshared uint gs_histogram[HISTOGRAM_BINS];
|
||||||
|
|
||||||
|
|
||||||
|
[numthreads(HISTOGRAM_THREAD_X, HISTOGRAM_THREAD_Y, 1)]
|
||||||
|
void KEyeHistogram(uint2 dispatchThreadId : SV_DispatchThreadID, uint2 groupThreadId : SV_GroupThreadID)
|
||||||
|
{
|
||||||
|
const uint localThreadId = groupThreadId.y * HISTOGRAM_THREAD_X + groupThreadId.x;
|
||||||
|
|
||||||
|
// Clears the shared memory
|
||||||
|
#if HISTOGRAM_REDUCTION_ALT_PATH
|
||||||
|
uint localThreadIdOff = localThreadId << 1u;
|
||||||
|
if (localThreadIdOff < HISTOGRAM_BINS)
|
||||||
|
{
|
||||||
|
gs_histogram[localThreadIdOff ] = 0u;
|
||||||
|
gs_histogram[localThreadIdOff + 1] = 0u;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
if (localThreadId < HISTOGRAM_BINS)
|
||||||
|
{
|
||||||
|
gs_histogram[localThreadId] = 0u;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
float2 ipos = float2(dispatchThreadId) * 2.0;
|
||||||
|
|
||||||
|
GroupMemoryBarrierWithGroupSync();
|
||||||
|
|
||||||
|
// Gather local group histogram
|
||||||
|
if (ipos.x < _ScaleOffsetRes.z && ipos.y < _ScaleOffsetRes.w)
|
||||||
|
{
|
||||||
|
uint weight = 1u;
|
||||||
|
float2 sspos = ipos / _ScaleOffsetRes.zw;
|
||||||
|
|
||||||
|
// Vignette weighting to put more focus on what's in the center of the screen
|
||||||
|
#if USE_VIGNETTE_WEIGHTING
|
||||||
|
{
|
||||||
|
float2 d = abs(sspos - (0.5).xx);
|
||||||
|
float vfactor = saturate(1.0 - dot(d, d));
|
||||||
|
vfactor *= vfactor;
|
||||||
|
weight = (uint)(64.0 * vfactor);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
float3 color = _Source.SampleLevel(sampler_LinearClamp, sspos, 0.0).xyz; // Bilinear downsample 2x
|
||||||
|
float luminance = Luminance(color);
|
||||||
|
float logLuminance = GetHistogramBinFromLuminance(luminance, _ScaleOffsetRes.xy);
|
||||||
|
uint idx = (uint) (logLuminance * (HISTOGRAM_BINS - 1u));
|
||||||
|
InterlockedAdd(gs_histogram[idx], weight);
|
||||||
|
}
|
||||||
|
|
||||||
|
GroupMemoryBarrierWithGroupSync();
|
||||||
|
|
||||||
|
// Merge everything
|
||||||
|
#if HISTOGRAM_REDUCTION_ALT_PATH
|
||||||
|
if (localThreadIdOff < HISTOGRAM_BINS)
|
||||||
|
{
|
||||||
|
InterlockedAdd(_HistogramBuffer[localThreadIdOff ], gs_histogram[localThreadIdOff ]);
|
||||||
|
InterlockedAdd(_HistogramBuffer[localThreadIdOff + 1], gs_histogram[localThreadIdOff + 1]);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
if (localThreadId < HISTOGRAM_BINS)
|
||||||
|
{
|
||||||
|
InterlockedAdd(_HistogramBuffer[localThreadId], gs_histogram[localThreadId]);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
[numthreads(HISTOGRAM_THREAD_X, 1, 1)]
|
||||||
|
void KEyeHistogramClear(uint dispatchThreadId : SV_DispatchThreadID)
|
||||||
|
{
|
||||||
|
if (dispatchThreadId < HISTOGRAM_BINS)
|
||||||
|
_HistogramBuffer[dispatchThreadId] = 0u;
|
||||||
|
}
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: b140e27dc74a1fb4d9ae30f8566b8919
|
||||||
|
ComputeShaderImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,29 @@
|
|||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!21 &2100000
|
||||||
|
Material:
|
||||||
|
serializedVersion: 8
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_Name: XRP_AutoExposure
|
||||||
|
m_Shader: {fileID: 4800000, guid: 86423a03f0e6a0441b2b00ff89b6c753, type: 3}
|
||||||
|
m_Parent: {fileID: 0}
|
||||||
|
m_ModifiedSerializedProperties: 0
|
||||||
|
m_ValidKeywords: []
|
||||||
|
m_InvalidKeywords: []
|
||||||
|
m_LightmapFlags: 4
|
||||||
|
m_EnableInstancingVariants: 0
|
||||||
|
m_DoubleSidedGI: 0
|
||||||
|
m_CustomRenderQueue: -1
|
||||||
|
stringTagMap: {}
|
||||||
|
disabledShaderPasses: []
|
||||||
|
m_LockedProperties:
|
||||||
|
m_SavedProperties:
|
||||||
|
serializedVersion: 3
|
||||||
|
m_TexEnvs: []
|
||||||
|
m_Ints: []
|
||||||
|
m_Floats: []
|
||||||
|
m_Colors: []
|
||||||
|
m_BuildTextureStacks: []
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: b04591ed716b35e41857f554d491ef4b
|
||||||
|
NativeFormatImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
mainObjectFileID: 2100000
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -1,4 +1,4 @@
|
|||||||
Shader "Unlit/Blur"
|
Shader "XRP/Blur"
|
||||||
{
|
{
|
||||||
|
|
||||||
SubShader
|
SubShader
|
||||||
@ -87,5 +87,58 @@ Shader "Unlit/Blur"
|
|||||||
|
|
||||||
ENDHLSL
|
ENDHLSL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Pass
|
||||||
|
{
|
||||||
|
NAME "KawaseBlu"
|
||||||
|
|
||||||
|
HLSLPROGRAM
|
||||||
|
|
||||||
|
#pragma vertex KawaseBlurVert
|
||||||
|
#pragma fragment KawaseBlurFrag
|
||||||
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||||
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
|
||||||
|
|
||||||
|
struct Varyings
|
||||||
|
{
|
||||||
|
float4 positionHCS : SV_POSITION;
|
||||||
|
float2 uv : TEXCOORD0;
|
||||||
|
float2 uvTopRight : TEXCOORD1;
|
||||||
|
float2 uvTopLeft : TEXCOORD2;
|
||||||
|
float2 uvBottomRight : TEXCOORD3;
|
||||||
|
float2 uvBottomLeft : TEXCOORD4;
|
||||||
|
};
|
||||||
|
|
||||||
|
float _KawaseBlurOffset;
|
||||||
|
TEXTURE2D(_BlitTexture);
|
||||||
|
SAMPLER(sampler_LinearClamp);
|
||||||
|
float4 _BlitTexture_TexelSize;
|
||||||
|
|
||||||
|
Varyings KawaseBlurVert(uint vertexID: SV_VertexID)
|
||||||
|
{
|
||||||
|
Varyings output;
|
||||||
|
output.positionHCS = GetFullScreenTriangleVertexPosition(vertexID);
|
||||||
|
float2 uv = GetFullScreenTriangleTexCoord(vertexID);
|
||||||
|
output.uv = uv;
|
||||||
|
output.uvTopRight = output.uv + float2( _KawaseBlurOffset, _KawaseBlurOffset) * _BlitTexture_TexelSize.xy;
|
||||||
|
output.uvTopLeft = output.uv + float2(-_KawaseBlurOffset, _KawaseBlurOffset) * _BlitTexture_TexelSize.xy;
|
||||||
|
output.uvBottomRight = output.uv + float2( _KawaseBlurOffset, -_KawaseBlurOffset) * _BlitTexture_TexelSize.xy;
|
||||||
|
output.uvBottomLeft = output.uv + float2(-_KawaseBlurOffset, -_KawaseBlurOffset) * _BlitTexture_TexelSize.xy;
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
float4 KawaseBlurFrag(Varyings input) : SV_Target
|
||||||
|
{
|
||||||
|
float4 color = SAMPLE_TEXTURE2D(_BlitTexture, sampler_LinearClamp, input.uv) * 0.2;
|
||||||
|
color += SAMPLE_TEXTURE2D(_BlitTexture, sampler_LinearClamp, input.uvTopRight) * 0.2;
|
||||||
|
color += SAMPLE_TEXTURE2D(_BlitTexture, sampler_LinearClamp, input.uvTopLeft) * 0.2;
|
||||||
|
color += SAMPLE_TEXTURE2D(_BlitTexture, sampler_LinearClamp, input.uvBottomRight) * 0.2;
|
||||||
|
color += SAMPLE_TEXTURE2D(_BlitTexture, sampler_LinearClamp, input.uvBottomLeft) * 0.2;
|
||||||
|
return float4(color.rgb, 1.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
ENDHLSL
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
Shader "Unlit/PlanarShadow"
|
Shader "XRP/PlanarShadow"
|
||||||
{
|
{
|
||||||
|
|
||||||
SubShader
|
SubShader
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
Shader "Unlit/SoftShadowMask"
|
Shader "XRP/SoftShadowMask"
|
||||||
{
|
{
|
||||||
SubShader
|
SubShader
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
Shader "MRP/SR/GSR1"
|
Shader "XRP/SR/GSR1"
|
||||||
{
|
{
|
||||||
SubShader
|
SubShader
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
Shader "MRP/SR/GSR2"
|
Shader "XRP/SR/GSR2"
|
||||||
{
|
{
|
||||||
SubShader
|
SubShader
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
Shader "Unlit/XessRcas"
|
Shader "XRP/XessRcas"
|
||||||
{
|
{
|
||||||
|
|
||||||
SubShader
|
SubShader
|
||||||
|
|||||||
@ -170,7 +170,7 @@ Shader "Universal Render Pipeline/Lit"
|
|||||||
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DOTS.hlsl"
|
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DOTS.hlsl"
|
||||||
|
|
||||||
#pragma multi_compile_vertex _ ENABLE_VS_SKINNING
|
#pragma multi_compile_vertex _ ENABLE_VS_SKINNING
|
||||||
#pragma enable_d3d11_debug_symbols
|
// #pragma enable_d3d11_debug_symbols
|
||||||
#include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
|
#include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
|
||||||
#include "Packages/com.unity.render-pipelines.universal/Shaders/LitForwardPass.hlsl"
|
#include "Packages/com.unity.render-pipelines.universal/Shaders/LitForwardPass.hlsl"
|
||||||
ENDHLSL
|
ENDHLSL
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user