Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public static class XRBuiltinShaderConstants
/// </summary>
static public readonly int unity_StereoWorldSpaceCameraPos = Shader.PropertyToID("unity_StereoWorldSpaceCameraPos");

/// <summary>
/// Cached unique id for unity_StereoEyeIndex
/// </summary>
static public readonly int unity_StereoEyeIndex = Shader.PropertyToID("unity_StereoEyeIndex");

// Pre-allocate arrays to avoid GC
static Matrix4x4[] s_cameraProjMatrix = new Matrix4x4[2];
static Matrix4x4[] s_invCameraProjMatrix = new Matrix4x4[2];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,11 @@ void RecordRenderGraph(RenderRequest renderRequest,
GenerateColorPyramid(m_RenderGraph, hdCamera, colorBuffer, distortionColorPyramid, FullScreenDebugMode.PreRefractionColorPyramid, distortionRendererList);
currentColorPyramid = distortionColorPyramid;


// The color pyramid for distortion is not an history, so it need to be sampled appropriate RT handle scale. Thus we need to update it
var newScale = new Vector4(RTHandles.rtHandleProperties.rtHandleScale.x, RTHandles.rtHandleProperties.rtHandleScale.y, 0, 0);
m_ShaderVariablesGlobalCB._ColorPyramidUvScaleAndLimitCurrentFrame = newScale;
// The color pyramid for distortion is not an history buffer, so it needs to be sampled using an appropriate RT handle scale. Thus we need to update the scale and the limit.
// It's relatively straightforward to update the scale because we store it in rtHandleScale but we miss the limit values. For now, we approximate them by setting them to the scale value.
// This is imperfect but resetting limit at (0, 0) gives worse results (UUM-130925).
var newScaleLimits = new Vector4(RTHandles.rtHandleProperties.rtHandleScale.x, RTHandles.rtHandleProperties.rtHandleScale.y, RTHandles.rtHandleProperties.rtHandleScale.x, RTHandles.rtHandleProperties.rtHandleScale.y);
m_ShaderVariablesGlobalCB._ColorPyramidUvScaleAndLimitCurrentFrame = newScaleLimits;
PushGlobalCameraParams(m_RenderGraph, hdCamera);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,8 @@ NeighborTapData GetNeighborTapDataSample_HR(uint2 groupThreadId, int2 offset)
return GetNeighborTapDataSample_HR(OffsetToLDSAdress_HR(groupThreadId, offset));
}

NeighborTapData GetNeighborTapDataSample_HR_NOLDS(uint2 fulLResCoord, int2 offset)
NeighborTapData GetNeighborTapDataSample_HR_NOLDS(uint2 tapCoord)
{
int2 tapCoord = (fulLResCoord / 2 + offset) * 2;
tapCoord = int2(clamp(tapCoord.x, 0, (int)_ScreenSize.x - 1), clamp(tapCoord.y, 0, (int)_ScreenSize.y - 1));

NeighborTapData outVal;
outVal.lighting = LOAD_TEXTURE2D_X(_IndirectDiffuseTexture, tapCoord / 2).xyz;
outVal.linearDepth = Linear01Depth(LOAD_TEXTURE2D_X(_DepthTexture, tapCoord).x, _ZBufferParams);
Expand Down Expand Up @@ -278,11 +275,15 @@ void IndirectDiffuseIntegrationUpscaleHalfRes(uint3 dispatchThreadId : SV_Dispat
{
for(int x = -HALF_RES_OUT_REGION_SIZE; x < HALF_RES_OUT_REGION_SIZE; ++x)
{
int2 tapCoord = (targetCoord / 2 + int2(x,y)) * 2;
if (any(tapCoord < 0) || any(tapCoord >= _ScreenSize.xy))
continue;

#ifndef WITHOUT_LDS
// Grab the neighbor data
NeighborTapData neighborData = GetNeighborTapDataSample_HR(groupThreadId, int2(x,y));
#else
NeighborTapData neighborData = GetNeighborTapDataSample_HR_NOLDS(targetCoord, int2(x,y));
NeighborTapData neighborData = GetNeighborTapDataSample_HR_NOLDS(tapCoord);
#endif
// Evaluate the weight of this neighbor
float weight = EvaluateNeighborWeight(neighborData, normalData.normalWS, linearDepth);
Expand Down Expand Up @@ -416,6 +417,10 @@ void IndirectDiffuseIntegrationUpscaleFullRes(uint3 dispatchThreadId : SV_Dispat
{
for(int x = -FULL_RES_OUT_REGION_SIZE; x < FULL_RES_OUT_REGION_SIZE; ++x)
{
int2 tapCoord = targetCoord + int2(x,y);
if (any(tapCoord < 0) || any(tapCoord >= _ScreenSize.xy))
continue;

#ifndef WITHOUT_LDS
// Grab the neighbor data
NeighborTapData neighborData = GetNeighborTapDataSample_FR(groupThreadId, int2(x,y));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,20 +178,12 @@ internal void Render(RenderGraph graph, ContextContainer frameData, Renderer2DDa
Universal2DResourceData universal2DResourceData = frameData.Get<Universal2DResourceData>();
UniversalCameraData cameraData = frameData.Get<UniversalCameraData>();

DebugHandler debugHandler = ScriptableRenderPass.GetActiveDebugHandler(cameraData);
var isDebugLightingActive = debugHandler?.IsLightingActive ?? true;

#if UNITY_EDITOR
if (cameraData.isSceneViewCamera && UnityEditor.SceneView.currentDrawingSceneView != null)
isDebugLightingActive &= UnityEditor.SceneView.currentDrawingSceneView.sceneLighting;

if (cameraData.camera.cameraType == CameraType.Preview)
isDebugLightingActive = false;
#endif
// Check for lighting in scene/prefab/preview camera
var isLightingActive = Renderer2D.s_IsLightingActive;

if (!layerBatch.lightStats.useLights ||
isVolumetric && !layerBatch.lightStats.useVolumetricLights ||
!isDebugLightingActive)
!isLightingActive)
return;

// Render single RTs by for apis that don't support MRTs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private static void Execute(RasterGraphContext context, PassData passData)
RendererLighting.SetLightShaderGlobals(cmd, passData.lightBlendStyles, passData.blendStyleIndices);

#if UNITY_EDITOR
if (passData.isLitView)
if (passData.isLightingActive)
#endif
{
if (passData.layerUseLights)
Expand Down Expand Up @@ -85,7 +85,7 @@ class PassData
internal bool activeDebugHandler;

#if UNITY_EDITOR
internal bool isLitView; // Required for prefab view and preview camera
internal bool isLightingActive; // Required for prefab view and preview camera
#endif
}

Expand All @@ -98,35 +98,23 @@ public void Render(RenderGraph graph, ContextContainer frameData, Renderer2DData
CommonResourceData commonResourceData = frameData.Get<CommonResourceData>();

var layerBatch = layerBatches[batchIndex];
bool isLitView = true;

#if UNITY_EDITOR
// Early out for prefabs
if (cameraData.isSceneViewCamera && UnityEditor.SceneView.currentDrawingSceneView != null)
isLitView = UnityEditor.SceneView.currentDrawingSceneView.sceneLighting;

// Early out for preview camera
if (cameraData.cameraType == CameraType.Preview)
isLitView = false;

DebugHandler debugHandler = GetActiveDebugHandler(cameraData);
if (debugHandler != null)
isLitView = debugHandler.IsLightingActive;
#endif
// Check for lighting in scene/prefab/preview camera
var isLightingActive = Renderer2D.s_IsLightingActive;

// Preset global light textures for first batch
if (batchIndex == 0)
{
using (var builder = graph.AddRasterRenderPass<SetGlobalPassData>(k_SetLightBlendTexture, out var passData, m_SetLightBlendTextureProfilingSampler))
{
if (layerBatch.lightStats.useLights && isLitView)
if (layerBatch.lightStats.useLights && isLightingActive)
{
passData.lightTextures = universal2DResourceData.lightTextures[batchIndex];
for (var i = 0; i < passData.lightTextures.Length; i++)
builder.UseTexture(passData.lightTextures[i]);
}

SetGlobalLightTextures(graph, builder, passData.lightTextures, ref layerBatch, rendererData, isLitView);
SetGlobalLightTextures(graph, builder, passData.lightTextures, ref layerBatch, rendererData, isLightingActive);

builder.AllowPassCulling(false);
builder.AllowGlobalStateModification(true);
Expand All @@ -146,7 +134,7 @@ public void Render(RenderGraph graph, ContextContainer frameData, Renderer2DData
passData.isSceneLit = rendererData.lightCullResult.IsSceneLit();
passData.layerUseLights = layerBatch.lightStats.useLights;
#if UNITY_EDITOR
passData.isLitView = isLitView;
passData.isLightingActive = isLightingActive;
#endif

var drawSettings = CreateDrawingSettings(k_ShaderTags, renderingData, cameraData, lightData, SortingCriteria.CommonTransparent);
Expand All @@ -171,7 +159,7 @@ public void Render(RenderGraph graph, ContextContainer frameData, Renderer2DData
builder.UseRendererList(passData.rendererList);
}

if (passData.layerUseLights && isLitView)
if (passData.layerUseLights && isLightingActive)
{
passData.lightTextures = universal2DResourceData.lightTextures[batchIndex];
for (var i = 0; i < passData.lightTextures.Length; i++)
Expand All @@ -192,7 +180,7 @@ public void Render(RenderGraph graph, ContextContainer frameData, Renderer2DData
// Post set global light textures for next renderer pass
var nextBatch = batchIndex + 1;
if (nextBatch < universal2DResourceData.lightTextures.Length)
SetGlobalLightTextures(graph, builder, universal2DResourceData.lightTextures[nextBatch], ref layerBatches[nextBatch], rendererData, isLitView);
SetGlobalLightTextures(graph, builder, universal2DResourceData.lightTextures[nextBatch], ref layerBatches[nextBatch], rendererData, isLightingActive);

builder.SetRenderFunc((PassData data, RasterGraphContext context) =>
{
Expand All @@ -201,9 +189,9 @@ public void Render(RenderGraph graph, ContextContainer frameData, Renderer2DData
}
}

void SetGlobalLightTextures(RenderGraph graph, IRasterRenderGraphBuilder builder, TextureHandle[] lightTextures, ref LayerBatch layerBatch, Renderer2DData rendererData, bool isLitView)
void SetGlobalLightTextures(RenderGraph graph, IRasterRenderGraphBuilder builder, TextureHandle[] lightTextures, ref LayerBatch layerBatch, Renderer2DData rendererData, bool isLightingActive)
{
if (isLitView)
if (isLightingActive)
{
if (layerBatch.lightStats.useLights)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ internal sealed partial class Renderer2D : ScriptableRenderer
int m_BatchCount;

bool ppcUpscaleRT = false;
static internal bool s_IsLightingActive;

private struct ImportResourceSummary
{
Expand Down Expand Up @@ -202,8 +203,10 @@ ImportResourceSummary GetImportResourceSummary(RenderGraph renderGraph, Universa
void InitializeLayerBatches()
{
Universal2DResourceData resourceData = frameData.Get<Universal2DResourceData>();
UniversalCameraData cameraData = frameData.Get<UniversalCameraData>();

m_LayerBatches = LayerUtility.CalculateBatches(m_Renderer2DData, out m_BatchCount);
s_IsLightingActive = IsSceneViewOrPreviewLightingActive(cameraData);

// Initialize textures dependent on batch size
if (resourceData.normalsTexture.Length != m_BatchCount)
Expand Down Expand Up @@ -857,5 +860,21 @@ private void CleanupRenderGraphResources()
m_CameraSortingLayerHandle?.Release();
Light2DLookupTexture.Release();
}

static internal bool IsSceneViewOrPreviewLightingActive(UniversalCameraData cameraData)
{
DebugHandler debugHandler = ScriptableRenderPass.GetActiveDebugHandler(cameraData);
var isLightingActive = debugHandler?.IsLightingActive ?? true;

#if UNITY_EDITOR
if (cameraData.isSceneViewCamera && UnityEditor.SceneView.currentDrawingSceneView != null)
isLightingActive &= UnityEditor.SceneView.currentDrawingSceneView.sceneLighting;

if (cameraData.isPreviewCamera && cameraData.camera.name == "Preview Scene Camera")
isLightingActive = false;
#endif

return isLightingActive;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,7 @@ void LensFlareDataDriven(ref UniversalCameraData cameraData, CommandBuffer cmd,
Matrix4x4 gpuVPXR = GL.GetGPUProjectionMatrix(cameraData.GetProjectionMatrixNoJitter(xrIdx), true) * cameraData.GetViewMatrix(xrIdx);

LensFlareCommonSRP.DoLensFlareDataDrivenCommon(
m_Materials.lensFlareDataDriven, camera, pixelRect, cameraData.xr, cameraData.xr.multipassId,
m_Materials.lensFlareDataDriven, camera, pixelRect, cameraData.xr, xrIdx,
(float)m_Descriptor.width, (float)m_Descriptor.height,
usePanini, paniniDistance, paniniCropToFit, true,
camera.transform.position,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1255,7 +1255,7 @@ public void RenderLensFlareDataDriven(RenderGraph renderGraph, UniversalResource
Matrix4x4 nonJitteredViewProjMatrix_k = GL.GetGPUProjectionMatrix(data.cameraData.GetProjectionMatrixNoJitter(xrIdx), true) * data.cameraData.GetViewMatrix(xrIdx);

LensFlareCommonSRP.DoLensFlareDataDrivenCommon(
data.material, data.cameraData.camera, data.viewport, xr, data.cameraData.xr.multipassId,
data.material, data.cameraData.camera, data.viewport, xr, xrIdx,
data.width, data.height,
data.usePanini, data.paniniDistance, data.paniniCropToFit,
true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,10 @@ void SetPerCameraShaderVariables(RasterCommandBuffer cmd, UniversalCameraData ca
cameraHeight = (float)cameraTargetSizeCopy.y;

useRenderPassEnabled = false;

// Multi-pass needs to set unity_StereoEyeIndex builtin param for skybox-panoramic.shader to work correctly (UUM-120719)
if (!cameraData.xr.singlePassEnabled)
cmd.SetGlobalVector(XRBuiltinShaderConstants.unity_StereoEyeIndex, new Vector4(cameraData.xr.multipassId, 0, 0, 0));
}

if (camera.allowDynamicResolution)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,9 @@ public override void RecordRenderGraph(RenderGraph renderGraph, ContextContainer
builder.SetRenderFunc((PassData data, RasterGraphContext context) =>
{
// Enable an MSAA shader keyword based on the source texture MSAA sample count
// when depth must be resolved manually in the copy shader
RTHandle sourceTex = data.source;
int cameraSamples = sourceTex.rt.antiAliasing;
int cameraSamples = sourceTex.rt.bindTextureMS ? sourceTex.rt.antiAliasing : 1;
context.cmd.SetKeyword(data.keyword_DepthMsaa2, cameraSamples == 2);
context.cmd.SetKeyword(data.keyword_DepthMsaa4, cameraSamples == 4);
context.cmd.SetKeyword(data.keyword_DepthMsaa8, cameraSamples == 8);
Expand Down
Loading