86 lines
2.8 KiB
Plaintext
86 lines
2.8 KiB
Plaintext
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
|
|
|
|
#pragma kernel KMain
|
|
|
|
#pragma multi_compile _ INPUT_FROM_RADIANCE_TEXTURE
|
|
|
|
// Inputs
|
|
#ifdef INPUT_FROM_RADIANCE_TEXTURE
|
|
TEXTURE2D_X(_RadianceTexture);
|
|
#endif
|
|
|
|
float4 _AccumulationWeights;
|
|
int _AccumulationNeedsExposure;
|
|
uint _AccumulationFrameIndex;
|
|
uint _AccumulationNumSamples;
|
|
|
|
// Input - Output(s)
|
|
RW_TEXTURE2D_X(float4, _CameraColorTextureRW);
|
|
RW_TEXTURE2D_X(float4, _AccumulatedFrameTexture);
|
|
|
|
void AddConvergenceCue(uint2 pixelCoord, uint sampleCount, inout float3 color)
|
|
{
|
|
// If we reached 100%, do not display the bar anymore
|
|
if (sampleCount >= _AccumulationNumSamples)
|
|
return;
|
|
|
|
uint width = _ScreenSize.x;
|
|
uint height = _ScreenSize.y;
|
|
|
|
// Change color only in a region corresponding to a progress bar, on the bottom 1% of the screen
|
|
if (pixelCoord.y < 4 && (float)pixelCoord.x / width <= (float)sampleCount / _AccumulationNumSamples)
|
|
{
|
|
float lum = Luminance(color);
|
|
|
|
if (lum > 1.0)
|
|
{
|
|
color /= lum;
|
|
lum = 1.0;
|
|
}
|
|
|
|
// Make dark color brighter, and vice versa
|
|
color += lum > 0.5 ? -0.5 * lum : 0.05 + 0.5 * lum;
|
|
}
|
|
}
|
|
|
|
[numthreads(8, 8, 1)]
|
|
void KMain(uint3 dispatchThreadId : SV_DispatchThreadID)
|
|
{
|
|
UNITY_XR_ASSIGN_VIEW_INDEX(dispatchThreadId.z);
|
|
uint2 currentPixelCoord = dispatchThreadId.xy;
|
|
|
|
float4 exposureMultiplier;
|
|
exposureMultiplier.xyz = (_AccumulationNeedsExposure != 0) ? GetCurrentExposureMultiplier() : 1.0;
|
|
exposureMultiplier.w = 1.0;
|
|
|
|
// Have we reached max sampling?
|
|
uint sampleCount = _AccumulationFrameIndex;
|
|
if (sampleCount >= _AccumulationNumSamples)
|
|
{
|
|
_CameraColorTextureRW[COORD_TEXTURE2D_X(currentPixelCoord)] = _AccumulatedFrameTexture[COORD_TEXTURE2D_X(currentPixelCoord)] * exposureMultiplier;
|
|
}
|
|
else
|
|
{
|
|
#ifdef INPUT_FROM_RADIANCE_TEXTURE
|
|
float4 color = _RadianceTexture[COORD_TEXTURE2D_X(dispatchThreadId.xy)];
|
|
#else
|
|
float4 color = _CameraColorTextureRW[COORD_TEXTURE2D_X(dispatchThreadId.xy)];
|
|
#endif
|
|
|
|
if (sampleCount++)
|
|
color = (_AccumulatedFrameTexture[COORD_TEXTURE2D_X(currentPixelCoord)] * _AccumulationWeights.y + _AccumulationWeights.x * color) * _AccumulationWeights.z;
|
|
|
|
_AccumulatedFrameTexture[COORD_TEXTURE2D_X(currentPixelCoord)] = color;
|
|
|
|
// Apply exposure modifier
|
|
color *= exposureMultiplier;
|
|
|
|
// Add a little convergence cue to our result
|
|
AddConvergenceCue(currentPixelCoord, sampleCount, color.xyz);
|
|
|
|
_CameraColorTextureRW[COORD_TEXTURE2D_X(currentPixelCoord)] = color;
|
|
}
|
|
}
|