Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HDRP][PathTracing] High resolution sky on camera ray misses #3389

Merged
merged 79 commits into from Feb 25, 2021
Merged
Show file tree
Hide file tree
Changes from 75 commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
b9da5fa
Hd/fix 1299116 tesselation cull (#3057)
kecho Jan 14, 2021
5b57f64
Change the source value for the ray tracing frame index iterator from…
anisunity Jan 14, 2021
b21345b
[HDRP] Added a RenderGraph pass that resets the camera size after the…
alelievr Jan 14, 2021
9581f38
Fix Light Intensity UI Prefab Override Application (1299563) (#3061)
johnpars Jan 14, 2021
525ebf5
Fix Undo/Redo Stability for Light Temperature (1304176, 1301076) (#3079)
johnpars Jan 14, 2021
8007c48
Fix labels style (#3046)
adrien-de-tocqueville Jan 14, 2021
2df0185
Fixed side effect on styles during compositor rendering. (#3081)
adrien-de-tocqueville Jan 14, 2021
bf833ce
[HDRP][Compositor] Fix size and spacing of compositor info boxes (#3101)
pmavridis Jan 14, 2021
7be5e6c
[HDRP][Compositor] Fix color picker UI glitch in the Graphics Composi…
pmavridis Jan 14, 2021
6413dc6
Fix 1299233 ies resize bug (#3094)
skhiat Jan 14, 2021
8998567
filter for xbone addded (#3116)
martint-unity Jan 15, 2021
027cb37
[Yamato] Enable cache server for standalone build jobs (#3106)
sophiaaar Jan 15, 2021
6429445
Fix undo redo on layered lit editor (#3059)
adrien-de-tocqueville Jan 15, 2021
d910dc8
Merge branch 'master' into hd/bugfix
sebastienlagarde Jan 15, 2021
9c216c8
[HDRP] Added Vulkan install in system requirements (#3122)
alelievr Jan 15, 2021
8dbde86
[HDRP] Fix issue with compositor related custom passes (#3055)
pmavridis Jan 15, 2021
a5a6590
Fixed some render texture leaks. (#3050)
JulienIgnace-Unity Jan 15, 2021
229f3e8
Hd/fix wizard runtime resources (#3123)
RSlysz Jan 15, 2021
0a42f9b
[HDRP] Fixed lookdev reload bug when viewing a scene object (#3108)
alelievr Jan 15, 2021
eb1d074
[HDRP] Fix error in Depth Of Field near radius blur calculation (#3131)
pmavridis Jan 15, 2021
22b5b7f
[HDRP] Fix GC allocs (#3136)
pmavridis Jan 15, 2021
8cd8fe6
Revert: Fix 1299233 ies resize bug (#3094)
sebastienlagarde Jan 15, 2021
9bcb75f
Merge branch 'master' into hd/bugfix
sebastienlagarde Jan 16, 2021
31defd2
Merge branch 'master' into hd/bugfix
sebastienlagarde Jan 16, 2021
6dffbc8
Hide light shadow near plane gizmo when shadows are disabled (#3114)
adrien-de-tocqueville Jan 16, 2021
9ba9620
Hd/fix backplate globalcubemap2 (#3111)
JulienIgnace-Unity Jan 18, 2021
b4214a4
[HDRP][Path Tracing] Added alpha channel to path traced results (#3127)
eturquin Jan 18, 2021
feb0fe0
Doc update (#3160)
JulienIgnace-Unity Jan 18, 2021
d315646
Merge branch 'master' into hd/bugfix
sebastienlagarde Jan 18, 2021
f9c97c1
Fix various shader warnings (#3158)
FrancescoC-unity Jan 18, 2021
316d6a6
Update Override-Screen-Space-GI.md
sebastienlagarde Jan 18, 2021
be8f685
Fixed shadow matte not working with ambient occlusion when MSAA is en…
sebastienlagarde Jan 18, 2021
44ba81f
Merge branch 'master' into hd/bugfix
sebastienlagarde Jan 18, 2021
4de9b07
Update HDLightUI.cs (#3203)
sebastienlagarde Jan 20, 2021
1557004
[HDRP] fix nullref when chaging RP from HDRP to URP (#3191)
alelievr Jan 20, 2021
acd6199
fix case 1307653 (#3205)
sebastienlagarde Jan 20, 2021
f18d053
Merge branch 'master' into hd/bugfix
sebastienlagarde Jan 21, 2021
abd7de7
Fix LookDev env library assignment after leaving playmode. (#3214)
JulienIgnace-Unity Jan 21, 2021
6349ef2
Update Hair Shader Preset Documentation (#3208)
johnpars Jan 21, 2021
cace53e
[HDRP] Fix locale diffusion profile shader property value in ShaderGr…
alelievr Jan 21, 2021
760837b
Fix error in the RTHandle scale of Depth Of Field when TAA is enabled…
pmavridis Jan 21, 2021
3f480bd
Reset to current quality settings after preprocess build in HDRP (#3218)
jenniferd-unity Jan 21, 2021
4c7dfb6
Merge branch 'master' into hd/bugfix
sebastienlagarde Jan 21, 2021
3b4b1fb
Have bilinear default (#3223)
FrancescoC-unity Jan 21, 2021
50af2f9
Merged changes for high res sky display in path tracing.
eturquin Jan 25, 2021
44355b4
Uncommented PS5 includes.
eturquin Jan 26, 2021
32a16ff
Merge branch 'master' into hd/pt_env_high_res
eturquin Jan 26, 2021
992ceb6
Cosmetic.
eturquin Jan 29, 2021
a890c49
Merge branch 'master' into hd/bugfix
sebastienlagarde Feb 1, 2021
4477283
Update CHANGELOG.md
sebastienlagarde Feb 1, 2021
3112950
Added missing character to the layered lit document (#3310)
JordanL8 Feb 1, 2021
ac55059
Fix needs of exposure for debug display "SSR Transparent" (#3308)
skhiat Feb 1, 2021
bc0aa7d
[HDRP] Fix GUI exception in material UI (#3315)
alelievr Feb 1, 2021
c34ba38
[HDRP] Update decal angle fade tooltip (#3322)
alelievr Feb 1, 2021
1f827f1
Mention in TAA doc that a certain use case will lead to problems. (#3…
FrancescoC-unity Feb 1, 2021
fe86016
Hide shadow resolution value (#3335)
adrien-de-tocqueville Feb 1, 2021
7a6ec1e
Bump timer of 2nd runtime test to make it work on all platforms. (#3…
FrancescoC-unity Feb 2, 2021
b84c14b
Fix light frustum planes (#3341)
adrien-de-tocqueville Feb 2, 2021
2cc4b51
Project skybox without perspective for ortho cameras (#2955)
adrien-de-tocqueville Feb 2, 2021
1c9a0ff
Fix non temporal SSAO issues with the rendergraph pass (#3351)
FrancescoC-unity Feb 2, 2021
b648896
Merge branch 'master' into hd/bugfix
sebastienlagarde Feb 2, 2021
4338bc4
Reset ambient probe upon switching to very different skies (#3340)
FrancescoC-unity Feb 2, 2021
0c56c5f
Fix white flash on camera cuts with volumetric (#3354)
FrancescoC-unity Feb 3, 2021
43e6d15
Fix issues with light layers issues when editing multiple lights (#3323)
FrancescoC-unity Feb 3, 2021
bd1934f
Maximum of reflection distance must be bound by the min of all dimens…
kecho Feb 3, 2021
e813067
Fixed debug panel reseting when going through enum items (#3370)
JulienIgnace-Unity Feb 3, 2021
e05a4c4
Made the code more rendergraph compliant and cleaner.
eturquin Feb 4, 2021
317f976
Fix keywords with fbx importer (#3350)
adrien-de-tocqueville Feb 4, 2021
9a085d0
Higt res env on camera misses, render sky only on first accum frame.
eturquin Feb 4, 2021
2ad6fc6
Updated changelog.
eturquin Feb 4, 2021
d8ab1b1
Support for camera motion blur when recording.
eturquin Feb 4, 2021
2d17429
Fixed typo.
eturquin Feb 4, 2021
ff27488
Merge branch 'hd/bugfix' into hd/pt_env_high_res
eturquin Feb 4, 2021
09748ca
Merge branch 'master' into hd/pt_env_high_res
sebastienlagarde Feb 17, 2021
2383469
Update CHANGELOG.md
sebastienlagarde Feb 17, 2021
26df9ed
Formatting
sebastienlagarde Feb 18, 2021
19938c2
Update 5005 PT screenshots
sebastienlagarde Feb 18, 2021
0cd037c
Fixed dirtiness issue with multiple cameras setup.
eturquin Feb 18, 2021
514e0e0
Merge branch 'master' into hd/pt_env_high_res
eturquin Feb 22, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions com.unity.render-pipelines.high-definition/CHANGELOG.md
Expand Up @@ -69,6 +69,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Change labels about scroll direction and cloud type.
- Improved shadow cascade GUI drawing with pixel perfect, hover and focus functionalities.
- Improving the screen space global illumination.
- Changed resolution (to match the render buffer) of the sky used for camera misses in Path Tracing. (case 1304114).

## [11.0.0] - 2020-10-21

Expand Down
Expand Up @@ -4,11 +4,11 @@

#pragma kernel KMain

#pragma multi_compile _ INPUT_FROM_RADIANCE_TEXTURE
#pragma multi_compile _ INPUT_FROM_FRAME_TEXTURE

// Inputs
#ifdef INPUT_FROM_RADIANCE_TEXTURE
TEXTURE2D_X(_RadianceTexture);
#ifdef INPUT_FROM_FRAME_TEXTURE
TEXTURE2D_X(_FrameTexture);
#endif

float4 _AccumulationWeights;
Expand Down Expand Up @@ -63,8 +63,8 @@ void KMain(uint3 dispatchThreadId : SV_DispatchThreadID)
}
else
{
#ifdef INPUT_FROM_RADIANCE_TEXTURE
float4 color = _RadianceTexture[COORD_TEXTURE2D_X(dispatchThreadId.xy)];
#ifdef INPUT_FROM_FRAME_TEXTURE
float4 color = _FrameTexture[COORD_TEXTURE2D_X(dispatchThreadId.xy)];
#else
float4 color = _CameraColorTextureRW[COORD_TEXTURE2D_X(dispatchThreadId.xy)];
#endif
Expand Down
Expand Up @@ -286,7 +286,7 @@ RenderAccumulationParameters PrepareRenderAccumulationParameters(HDCamera hdCame
parameters.accumulationCS.shaderKeywords = null;
if (inputFromRadianceTexture)
{
parameters.accumulationCS.EnableKeyword("INPUT_FROM_RADIANCE_TEXTURE");
parameters.accumulationCS.EnableKeyword("INPUT_FROM_FRAME_TEXTURE");
}
return parameters;
}
Expand All @@ -311,7 +311,7 @@ static void RenderAccumulation(in RenderAccumulationParameters parameters, RTHan
cmd.SetComputeTextureParam(accumulationShader, parameters.accumulationKernel, HDShaderIDs._CameraColorTextureRW, outputTexture);
if (!inputTexture.Equals(outputTexture))
{
cmd.SetComputeTextureParam(accumulationShader, parameters.accumulationKernel, HDShaderIDs._RadianceTexture, inputTexture);
cmd.SetComputeTextureParam(accumulationShader, parameters.accumulationKernel, HDShaderIDs._FrameTexture, inputTexture);
}
cmd.SetComputeVectorParam(accumulationShader, HDShaderIDs._AccumulationWeights, frameWeights);
cmd.SetComputeIntParam(accumulationShader, HDShaderIDs._AccumulationNeedsExposure, parameters.needExposure ? 1 : 0);
Expand Down
Expand Up @@ -116,7 +116,7 @@ class TempPassData {};

if (hdCamera.viewCount == 1)
{
colorBuffer = RenderPathTracing(m_RenderGraph, hdCamera);
colorBuffer = RenderPathTracing(m_RenderGraph, hdCamera, colorBuffer);
}
else
{
Expand Down
Expand Up @@ -473,7 +473,7 @@ public HDRenderPipeline(HDRenderPipelineAsset asset, HDRenderPipelineAsset defau
InitRayTracedIndirectDiffuse();
InitRaytracingDeferred();
InitRecursiveRenderer();
InitPathTracing();
InitPathTracing(m_RenderGraph);
InitRayTracingAmbientOcclusion();
}

Expand Down
Expand Up @@ -717,12 +717,13 @@ static class HDShaderIDs
public static readonly int _SubSurfaceLightingBuffer = Shader.PropertyToID("_SubSurfaceLightingBuffer");
public static readonly int _IndirectDiffuseLightingBuffer = Shader.PropertyToID("_IndirectDiffuseLightingBuffer");

// Accumulation
// Accumulation and path tracing
public static readonly int _AccumulationFrameIndex = Shader.PropertyToID("_AccumulationFrameIndex");
public static readonly int _AccumulationNumSamples = Shader.PropertyToID("_AccumulationNumSamples");
public static readonly int _AccumulationWeights = Shader.PropertyToID("_AccumulationWeights");
public static readonly int _AccumulationNeedsExposure = Shader.PropertyToID("_AccumulationNeedsExposure");
public static readonly int _RadianceTexture = Shader.PropertyToID("_RadianceTexture");
public static readonly int _FrameTexture = Shader.PropertyToID("_FrameTexture");
public static readonly int _SkyCameraTexture = Shader.PropertyToID("_SkyCameraTexture");

// Preintegrated texture name
public static readonly int _PreIntegratedFGD_GGXDisneyDiffuse = Shader.PropertyToID("_PreIntegratedFGD_GGXDisneyDiffuse");
Expand Down
Expand Up @@ -69,20 +69,31 @@ public partial class HDRenderPipeline
#endif // UNITY_EDITOR
ulong m_CacheAccelSize = 0;
uint m_CacheLightCount = 0;
bool m_RenderSky = true;

RTHandle m_RadianceTexture; // stores the per-pixel results of path tracing for this frame
TextureHandle m_FrameTexture; // stores the per-pixel results of path tracing for one frame
TextureHandle m_SkyTexture; // stores the sky background

void InitPathTracing()
void InitPathTracing(RenderGraph renderGraph)
{
#if UNITY_EDITOR
Undo.postprocessModifications += OnUndoRecorded;
Undo.undoRedoPerformed += OnSceneEdit;
SceneView.duringSceneGui += OnSceneGui;
#endif // UNITY_EDITOR

m_RadianceTexture = RTHandles.Alloc(Vector2.one, TextureXR.slices, colorFormat: GraphicsFormat.R32G32B32A32_SFloat, dimension: TextureXR.dimension,
enableRandomWrite: true, useMipMap: false, autoGenerateMips: false,
name: "PathTracingFrameBuffer");
TextureDesc td = new TextureDesc(Vector2.one, true, true);
td.colorFormat = GraphicsFormat.R32G32B32A32_SFloat;
td.useMipMap = false;
td.autoGenerateMips = false;

td.name = "PathTracingFrameBuffer";
td.enableRandomWrite = true;
m_FrameTexture = renderGraph.CreateSharedTexture(td);

td.name = "PathTracingSkyBuffer";
td.enableRandomWrite = false;
m_SkyTexture = renderGraph.CreateSharedTexture(td);
}

void ReleasePathTracing()
Expand All @@ -92,15 +103,21 @@ void ReleasePathTracing()
Undo.undoRedoPerformed -= OnSceneEdit;
SceneView.duringSceneGui -= OnSceneGui;
#endif // UNITY_EDITOR

RTHandles.Release(m_RadianceTexture);
}

internal void ResetPathTracing()
{
m_RenderSky = true;
m_SubFrameManager.Reset();
}

internal void ResetPathTracing(int camID, CameraData camData)
{
m_RenderSky = true;
camData.ResetIteration();
m_SubFrameManager.SetCameraData(camID, camData);
}

private Vector4 ComputeDoFConstants(HDCamera hdCamera, PathTracing settings)
{
var dofSettings = hdCamera.volumeStack.GetComponent<DepthOfField>();
Expand All @@ -119,6 +136,7 @@ private void OnSceneEdit()
// If we just change the sample count, we don't necessarily want to reset iteration
if (m_PathTracingSettings && m_CacheMaxIteration != m_PathTracingSettings.maximumSamples.value)
{
m_RenderSky = true;
m_CacheMaxIteration = (uint)m_PathTracingSettings.maximumSamples.value;
m_SubFrameManager.SelectiveReset(m_CacheMaxIteration);
}
Expand Down Expand Up @@ -157,8 +175,7 @@ private void CheckDirtiness(HDCamera hdCamera)
{
camData.width = (uint)hdCamera.actualWidth;
camData.height = (uint)hdCamera.actualHeight;
camData.ResetIteration();
m_SubFrameManager.SetCameraData(camID, camData);
ResetPathTracing(camID, camData);
return;
}

Expand All @@ -167,8 +184,7 @@ private void CheckDirtiness(HDCamera hdCamera)
if (enabled != camData.skyEnabled)
{
camData.skyEnabled = enabled;
camData.ResetIteration();
m_SubFrameManager.SetCameraData(camID, camData);
ResetPathTracing(camID, camData);
return;
}

Expand All @@ -177,16 +193,14 @@ private void CheckDirtiness(HDCamera hdCamera)
if (enabled != camData.fogEnabled)
{
camData.fogEnabled = enabled;
camData.ResetIteration();
m_SubFrameManager.SetCameraData(camID, camData);
ResetPathTracing(camID, camData);
return;
}

// Check camera matrix dirtiness
if (hdCamera.mainViewConstants.nonJitteredViewProjMatrix != (hdCamera.mainViewConstants.prevViewProjMatrix))
{
camData.ResetIteration();
m_SubFrameManager.SetCameraData(camID, camData);
ResetPathTracing(camID, camData);
return;
}

Expand All @@ -203,6 +217,7 @@ private void CheckDirtiness(HDCamera hdCamera)
{
m_TransformDirty = false;
ResetPathTracing();
return;
}

// Check lights dirtiness
Expand Down Expand Up @@ -270,7 +285,7 @@ PathTracingParameters PreparePathTracingParameters(HDCamera hdCamera)
return parameters;
}

static void RenderPathTracing(in PathTracingParameters parameters, RTHandle radianceTexture, CommandBuffer cmd)
static void RenderPathTracing(in PathTracingParameters parameters, RTHandle frameTexture, RTHandle skyTexture, CommandBuffer cmd)
{
// Define the shader pass to use for the path tracing pass
cmd.SetRayTracingShaderPass(parameters.pathTracingShader, "PathTracingDXR");
Expand All @@ -291,10 +306,11 @@ static void RenderPathTracing(in PathTracingParameters parameters, RTHandle radi
// Set the data for the ray miss
cmd.SetRayTracingIntParam(parameters.pathTracingShader, HDShaderIDs._RaytracingCameraSkyEnabled, parameters.cameraData.skyEnabled ? 1 : 0);
cmd.SetRayTracingVectorParam(parameters.pathTracingShader, HDShaderIDs._RaytracingCameraClearColor, parameters.backgroundColor);
cmd.SetRayTracingTextureParam(parameters.pathTracingShader, HDShaderIDs._SkyCameraTexture, skyTexture);
cmd.SetRayTracingTextureParam(parameters.pathTracingShader, HDShaderIDs._SkyTexture, parameters.skyReflection);

// Additional data for path tracing
cmd.SetRayTracingTextureParam(parameters.pathTracingShader, HDShaderIDs._RadianceTexture, radianceTexture);
cmd.SetRayTracingTextureParam(parameters.pathTracingShader, HDShaderIDs._FrameTexture, frameTexture);
cmd.SetRayTracingMatrixParam(parameters.pathTracingShader, HDShaderIDs._PixelCoordToViewDirWS, parameters.pixelCoordToViewDirWS);
cmd.SetRayTracingVectorParam(parameters.pathTracingShader, HDShaderIDs._PathTracedDoFConstants, parameters.dofParameters);

Expand All @@ -306,26 +322,52 @@ class RenderPathTracingData
{
public PathTracingParameters parameters;
public TextureHandle output;
public TextureHandle sky;
}

TextureHandle RenderPathTracing(RenderGraph renderGraph, in PathTracingParameters parameters, TextureHandle pathTracingBuffer)
TextureHandle RenderPathTracing(RenderGraph renderGraph, in PathTracingParameters parameters, TextureHandle pathTracingBuffer, TextureHandle skyBuffer)
{
using (var builder = renderGraph.AddRenderPass<RenderPathTracingData>("Render PathTracing", out var passData))
{
passData.parameters = parameters;
passData.output = builder.WriteTexture(pathTracingBuffer);
passData.sky = builder.ReadTexture(skyBuffer);

builder.SetRenderFunc(
(RenderPathTracingData data, RenderGraphContext ctx) =>
{
RenderPathTracing(data.parameters, data.output, ctx.cmd);
RenderPathTracing(data.parameters, data.output, data.sky, ctx.cmd);
});

return passData.output;
}
}

TextureHandle RenderPathTracing(RenderGraph renderGraph, HDCamera hdCamera)
// Simpler variant used by path tracing, without depth buffer or volumetric computations
void RenderSky(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle skyBuffer)
{
if (m_CurrentDebugDisplaySettings.DebugHideSky(hdCamera))
return;

using (var builder = renderGraph.AddRenderPass<RenderSkyPassData>("Render Sky for Path Tracing", out var passData))
{
passData.visualEnvironment = hdCamera.volumeStack.GetComponent<VisualEnvironment>();
passData.sunLight = GetCurrentSunLight();
passData.hdCamera = hdCamera;
passData.colorBuffer = builder.WriteTexture(skyBuffer);
passData.depthTexture = builder.WriteTexture(CreateDepthBuffer(renderGraph, true, false));
passData.debugDisplaySettings = m_CurrentDebugDisplaySettings;
passData.skyManager = m_SkyManager;

builder.SetRenderFunc(
(RenderSkyPassData data, RenderGraphContext context) =>
{
data.skyManager.RenderSky(data.hdCamera, data.sunLight, data.colorBuffer, data.depthTexture, data.debugDisplaySettings, context.cmd);
});
}
}

TextureHandle RenderPathTracing(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle colorBuffer)
{
RayTracingShader pathTracingShader = m_Asset.renderPipelineRayTracingResources.pathTracing;
m_PathTracingSettings = hdCamera.volumeStack.GetComponent<PathTracing>();
Expand All @@ -336,34 +378,33 @@ TextureHandle RenderPathTracing(RenderGraph renderGraph, HDCamera hdCamera)

CheckDirtiness(hdCamera);

var parameters = PreparePathTracingParameters(hdCamera);
TextureHandle outputTexture = CreateColorBuffer(renderGraph, hdCamera, false);
// TODO RENDERGRAPH: This texture needs to be persistent
// (apparently it only matters for some tests, loading a regular scene with pathtracing works even if this one is not persistent)
// So we need to import a regular RTHandle. This is not good because it means the texture will always be allocate even if not used...
// Refactor that when we formalize how to handle persistent textures better (with automatic lifetime and such).
var radianceTexture = renderGraph.ImportTexture(m_RadianceTexture);

if (!m_SubFrameManager.isRecording)
{
// If we are recording, the max iteration is set/overridden by the subframe manager, otherwise we read it from the path tracing volume
m_SubFrameManager.subFrameCount = (uint)m_PathTracingSettings.maximumSamples.value;
}


#if UNITY_HDRP_DXR_TESTS_DEFINE
if (Application.isPlaying)
m_SubFrameManager.subFrameCount = 1;
#endif

var parameters = PreparePathTracingParameters(hdCamera);
if (parameters.cameraData.currentIteration < m_SubFrameManager.subFrameCount)
{
RenderPathTracing(m_RenderGraph, parameters, radianceTexture);
// Keep a sky texture around, that we compute only once per accumulation (except when recording, with potential camera motion blur)
if (m_RenderSky || m_SubFrameManager.isRecording)
{
RenderSky(m_RenderGraph, hdCamera, m_SkyTexture);
m_RenderSky = false;
}

RenderPathTracing(m_RenderGraph, parameters, m_FrameTexture, m_SkyTexture);
}

RenderAccumulation(m_RenderGraph, hdCamera, radianceTexture, outputTexture, true);
RenderAccumulation(m_RenderGraph, hdCamera, m_FrameTexture, colorBuffer, true);

return outputTexture;
return colorBuffer;
}
}
}
Expand Up @@ -26,21 +26,23 @@
float4x4 _PixelCoordToViewDirWS;
int _RaytracingCameraSkyEnabled;
float4 _RaytracingCameraClearColor;

// DoF related parameters
float4 _PathTracedDoFConstants; // x: aperture radius, y: focus distance, zw: unused
TEXTURE2D_X(_SkyCameraTexture);

// Output(s)
RWTexture2D<float4> _RadianceTexture;
RW_TEXTURE2D_X(float4, _FrameTexture);

// DoF related parameters
float4 _PathTracedDoFConstants; // x: aperture radius, y: focus distance, zw: unused

[shader("miss")]
void MissCamera(inout PathIntersection pathIntersection : SV_RayPayload)
{
bool skyEnabled = _EnvLightSkyEnabled && _RaytracingCameraSkyEnabled;
pathIntersection.value = skyEnabled ? SampleSkyTexture(WorldRayDirection(), 0.0, 0).xyz : _RaytracingCameraClearColor.xyz * GetInverseCurrentExposureMultiplier();
pathIntersection.alpha = skyEnabled ? 1.0 : _RaytracingCameraClearColor.w;
float4 missColor = skyEnabled ? _SkyCameraTexture[COORD_TEXTURE2D_X(pathIntersection.pixelCoord)] : _RaytracingCameraClearColor;
pathIntersection.value = missColor.xyz * GetInverseCurrentExposureMultiplier();
pathIntersection.alpha = missColor.w;

ApplyFogAttenuation(WorldRayOrigin(), WorldRayDirection(), pathIntersection.value);
ApplyFogAttenuation(WorldRayOrigin(), WorldRayDirection(), pathIntersection.value, pathIntersection.alpha);

if (_EnableVolumetricFog && _RaytracingMinRecursion <= 1)
{
Expand Down Expand Up @@ -149,7 +151,7 @@ void RayGen()
// Evaluate the ray intersection
TraceRay(_RaytracingAccelerationStructure, RAY_FLAG_CULL_BACK_FACING_TRIANGLES, RAYTRACINGRENDERERFLAG_PATH_TRACING, 0, 1, 0, rayDescriptor, pathIntersection);

_RadianceTexture[currentPixelCoord] = float4(pathIntersection.value, pathIntersection.alpha);
_FrameTexture[COORD_TEXTURE2D_X(currentPixelCoord)] = float4(pathIntersection.value, pathIntersection.alpha);
}

// This should never be called, return magenta just in case
Expand Down
Expand Up @@ -35,4 +35,21 @@ void ApplyFogAttenuation(float3 origin, float3 direction, inout float3 value)
}
}

void ApplyFogAttenuation(float3 origin, float3 direction, inout float3 value, inout float alpha)
{
if (_FogEnabled)
{
float dist = min(_MipFogFar, _MaxFogDistance);
float absFogBaseHeight = _HeightFogBaseHeight;
float fogTransmittance = TransmittanceHeightFog(_HeightFogBaseExtinction, absFogBaseHeight, _HeightFogExponents, direction.y, origin.y, dist);

// This is designed to match the raster volumes... even though I'm not sure why it's working that way
float3 fogColor = !_EnableVolumetricFog ?
GetFogColor(-direction, dist) * _HeightFogBaseScattering.xyz / _HeightFogBaseExtinction :
0.0;
value = lerp(fogColor, value, fogTransmittance);
alpha = saturate(1.0 - fogTransmittance);
}
}

#endif // UNITY_ATMOSPHERIC_SCATTERING_RAY_TRACING_INCLUDED