Skip to content

Universal Staging #6054

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

Merged
merged 5 commits into from
Oct 19, 2021
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,6 @@ MonoBehaviour:
XrSdk:
StereoModes: 0
Reason: Needs MSAA fixing on OpenGLES3
- FilteredScene: {fileID: 0}
FilteredScenes:
- {fileID: 102900000, guid: 2b6b74b7929ae4191b3b936c12236e0a, type: 3}
- {fileID: 102900000, guid: a770620fcd2f84f248d06edf3744b2c0, type: 3}
- {fileID: 102900000, guid: bcb8635ea84c143f0ae0823f1e9b6f25, type: 3}
ColorSpace: -1
BuildPlatform: -2
GraphicsDevice: 4
XrSdk:
StereoModes: 0
Reason: To be added
- FilteredScene: {fileID: 0}
FilteredScenes:
- {fileID: 102900000, guid: 2b6b74b7929ae4191b3b936c12236e0a, type: 3}
Expand Down
4 changes: 4 additions & 0 deletions com.unity.render-pipelines.universal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed memory leak with XR combined occlusion meshes. [case 1366173]
- Fixed a bug with Sprite Targets in ShaderGraph not rendering correctly in game view [1352225]

### Changed
- Remove use of deprecated UNITY_USE_NATIVE_HDR keyword in shaders.

## [12.0.0] - 2021-01-11
### Added
- Added support for default sprite mask shaders for the 2D Renderer in URP.
Expand Down Expand Up @@ -228,6 +231,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Support undo of URP Global Settings asset assignation (case 1342987).
- Removed unsupported fields from Presets of Light and Camera [case 1335979].
- Fixed graphical artefact when terrain height map is used with rendering layer mask for lighting.
- Fixed URP's vignette effect to respect XR's view center, since with Asymmetric FOV, the center of the view is not always the center of the texture [case 1358336](https://issuetracker.unity3d.com/issues/xr-sdk-urp-vignette-post-processing-effect-is-overlapping-between-eyes)
- Fixed an issue where screen space shadows has flickering with deferred mode [case 1354681](https://issuetracker.unity3d.com/issues/screen-space-shadows-flicker-in-scene-view-when-using-deferred-rendering)
- Fixed shadowCascadeBlendCullingFactor to be 1.0
- Fixed missing property values in a RendererFeature of screen space shadows by adding tooltip for it instead of showing them. [case 1327356]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ void Swap(ref ScriptableRenderer r)
// Setup other effects constants
SetupLensDistortion(m_Materials.uber, isSceneViewCamera);
SetupChromaticAberration(m_Materials.uber);
SetupVignette(m_Materials.uber);
SetupVignette(m_Materials.uber, cameraData.xr);
SetupColorGrading(cmd, ref renderingData, m_Materials.uber);

// Only apply dithering & grain if there isn't a final pass.
Expand Down Expand Up @@ -1265,12 +1265,25 @@ void SetupChromaticAberration(Material material)

#region Vignette

void SetupVignette(Material material)
void SetupVignette(Material material, XRPass xrPass)
{
var color = m_Vignette.color.value;
var center = m_Vignette.center.value;
var aspectRatio = m_Descriptor.width / (float)m_Descriptor.height;


#if ENABLE_VR && ENABLE_XR_MODULE
if (xrPass != null && xrPass.enabled)
{
if (xrPass.singlePassEnabled)
material.SetVector(ShaderConstants._Vignette_ParamsXR, xrPass.ApplyXRViewCenterOffset(center));
else
// In multi-pass mode we need to modify the eye center with the values from .xy of the corrected
// center since the version of the shader that is not single-pass will use the value in _Vignette_Params2
center = xrPass.ApplyXRViewCenterOffset(center);
}
#endif

var v1 = new Vector4(
color.r, color.g, color.b,
m_Vignette.rounded.value ? aspectRatio : 1f
Expand Down Expand Up @@ -1533,6 +1546,7 @@ static class ShaderConstants
public static readonly int _Chroma_Params = Shader.PropertyToID("_Chroma_Params");
public static readonly int _Vignette_Params1 = Shader.PropertyToID("_Vignette_Params1");
public static readonly int _Vignette_Params2 = Shader.PropertyToID("_Vignette_Params2");
public static readonly int _Vignette_ParamsXR = Shader.PropertyToID("_Vignette_ParamsXR");
public static readonly int _Lut_Params = Shader.PropertyToID("_Lut_Params");
public static readonly int _UserLut_Params = Shader.PropertyToID("_UserLut_Params");
public static readonly int _InternalLut = Shader.PropertyToID("_InternalLut");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,10 +396,11 @@ static void RenderSingleCamera(ScriptableRenderContext context, CameraData camer
#if UNITY_EDITOR
// Emit scene view UI
if (isSceneViewCamera)
{
ScriptableRenderContext.EmitWorldGeometryForSceneView(camera);
}
else
#endif
if (cameraData.camera.targetTexture != null && cameraData.cameraType != CameraType.Preview)
ScriptableRenderContext.EmitGeometryForCamera(camera);

var cullResults = context.Cull(ref cullingParameters);
InitializeRenderingData(asset, ref cameraData, ref cullResults, anyPostProcessingEnabled, out var renderingData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -855,10 +855,9 @@ public override void Setup(ScriptableRenderContext context, ref RenderingData re
}

#if UNITY_EDITOR
if (isSceneViewCamera || isGizmosEnabled)
if (isSceneViewCamera || (isGizmosEnabled && lastCameraInTheStack))
{
// Scene view camera should always resolve target (not stacked)
Assertions.Assert.IsTrue(lastCameraInTheStack, "Editor camera must resolve target upon finish rendering.");
m_FinalDepthCopyPass.Setup(m_DepthTexture, RenderTargetHandle.CameraTarget);
m_FinalDepthCopyPass.MssaSamples = 0;
EnqueuePass(m_FinalDepthCopyPass);
Expand Down
35 changes: 35 additions & 0 deletions com.unity.render-pipelines.universal/Runtime/XR/XRPass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ internal struct XRView
internal readonly Rect viewport;
internal readonly Mesh occlusionMesh;
internal readonly int textureArraySlice;
internal readonly Vector2 eyeCenterUV;

internal XRView(Matrix4x4 proj, Matrix4x4 view, Rect vp, int dstSlice)
{
Expand All @@ -46,6 +47,8 @@ internal XRView(Matrix4x4 proj, Matrix4x4 view, Rect vp, int dstSlice)
viewport = vp;
occlusionMesh = null;
textureArraySlice = dstSlice;

eyeCenterUV = ComputeEyeCenterUV(proj);
}

internal XRView(XRDisplaySubsystem.XRRenderPass renderPass, XRDisplaySubsystem.XRRenderParameter renderParameter)
Expand All @@ -61,6 +64,18 @@ internal XRView(XRDisplaySubsystem.XRRenderPass renderPass, XRDisplaySubsystem.X
viewport.width *= renderPass.renderTargetDesc.width;
viewport.y *= renderPass.renderTargetDesc.height;
viewport.height *= renderPass.renderTargetDesc.height;

eyeCenterUV = ComputeEyeCenterUV(projMatrix);
}

private static Vector2 ComputeEyeCenterUV(Matrix4x4 proj)
{
var projectionParameters = proj.decomposeProjection;
float left = Math.Abs(projectionParameters.left);
float right = Math.Abs(projectionParameters.right);
float top = Math.Abs(projectionParameters.top);
float bottom = Math.Abs(projectionParameters.bottom);
return new Vector2(left / (right + left), top / (top + bottom));
}
}

Expand Down Expand Up @@ -436,6 +451,26 @@ internal void RenderOcclusionMesh(CommandBuffer cmd)
}
}

// Take a point that is center-relative (0.5, 0.5) and modify it to be placed relative to the view's center instead,
// respecting the asymmetric FOV (if it is used)
internal Vector4 ApplyXRViewCenterOffset(Vector2 center)
{
Vector4 result = Vector4.zero;
float centerDeltaX = 0.5f - center.x;
float centerDeltaY = 0.5f - center.y;

result.x = views[0].eyeCenterUV.x - centerDeltaX;
result.y = views[0].eyeCenterUV.y - centerDeltaY;
if (singlePassEnabled)
{
// With single-pass XR, we need to add the data for the 2nd view
result.z = views[1].eyeCenterUV.x - centerDeltaX;
result.w = views[1].eyeCenterUV.y - centerDeltaY;
}

return result;
}

// Store array to avoid allocating every frame
private Matrix4x4[] stereoProjectionMatrix = new Matrix4x4[2];
private Matrix4x4[] stereoViewMatrix = new Matrix4x4[2];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,7 @@ half3 CalculateIrradianceFromReflectionProbes(half3 reflectVector, float3 positi

half4 encodedIrradiance = half4(SAMPLE_TEXTURECUBE_LOD(unity_SpecCube0, samplerunity_SpecCube0, reflectVector, mip));

#if defined(UNITY_USE_NATIVE_HDR)
irradiance += weightProbe0 * encodedIrradiance.rbg;
#else
irradiance += weightProbe0 * DecodeHDREnvironment(encodedIrradiance, unity_SpecCube0_HDR);
#endif // UNITY_USE_NATIVE_HDR
}

// Sample the second reflection probe
Expand All @@ -235,23 +231,23 @@ half3 CalculateIrradianceFromReflectionProbes(half3 reflectVector, float3 positi
#endif // _REFLECTION_PROBE_BOX_PROJECTION
half4 encodedIrradiance = half4(SAMPLE_TEXTURECUBE_LOD(unity_SpecCube1, samplerunity_SpecCube1, reflectVector, mip));

#if defined(UNITY_USE_NATIVE_HDR) || defined(UNITY_DOTS_INSTANCING_ENABLED)
#if defined(UNITY_DOTS_INSTANCING_ENABLED)
irradiance += weightProbe1 * encodedIrradiance.rbg;
#else
irradiance += weightProbe1 * DecodeHDREnvironment(encodedIrradiance, unity_SpecCube1_HDR);
#endif // UNITY_USE_NATIVE_HDR || UNITY_DOTS_INSTANCING_ENABLED
#endif // UNITY_DOTS_INSTANCING_ENABLED
}

// Use any remaining weight to blend to environment reflection cube map
if (totalWeight < 0.99f)
{
half4 encodedIrradiance = half4(SAMPLE_TEXTURECUBE_LOD(_GlossyEnvironmentCubeMap, sampler_GlossyEnvironmentCubeMap, originalReflectVector, mip));

#if defined(UNITY_USE_NATIVE_HDR) || defined(UNITY_DOTS_INSTANCING_ENABLED)
#if defined(UNITY_DOTS_INSTANCING_ENABLED)
irradiance += (1.0f - totalWeight) * encodedIrradiance.rbg;
#else
irradiance += (1.0f - totalWeight) * DecodeHDREnvironment(encodedIrradiance, _GlossyEnvironmentCubeMap_HDR);
#endif // UNITY_USE_NATIVE_HDR || UNITY_DOTS_INSTANCING_ENABLED
#endif // UNITY_DOTS_INSTANCING_ENABLED
}

return irradiance;
Expand All @@ -271,11 +267,7 @@ half3 GlossyEnvironmentReflection(half3 reflectVector, float3 positionWS, half p
half mip = PerceptualRoughnessToMipmapLevel(perceptualRoughness);
half4 encodedIrradiance = half4(SAMPLE_TEXTURECUBE_LOD(unity_SpecCube0, samplerunity_SpecCube0, reflectVector, mip));

#if defined(UNITY_USE_NATIVE_HDR)
irradiance = encodedIrradiance.rgb;
#else
irradiance = DecodeHDREnvironment(encodedIrradiance, unity_SpecCube0_HDR);
#endif // UNITY_USE_NATIVE_HDR
#endif // _REFLECTION_PROBE_BLENDING
return irradiance * occlusion;
#else
Expand All @@ -290,11 +282,7 @@ half3 GlossyEnvironmentReflection(half3 reflectVector, half perceptualRoughness,
half mip = PerceptualRoughnessToMipmapLevel(perceptualRoughness);
half4 encodedIrradiance = half4(SAMPLE_TEXTURECUBE_LOD(unity_SpecCube0, samplerunity_SpecCube0, reflectVector, mip));

#if defined(UNITY_USE_NATIVE_HDR)
irradiance = encodedIrradiance.rgb;
#else
irradiance = DecodeHDREnvironment(encodedIrradiance, unity_SpecCube0_HDR);
#endif // UNITY_USE_NATIVE_HDR

return irradiance * occlusion;
#else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ Shader "Hidden/Universal Render Pipeline/UberPost"
float _Chroma_Params;
half4 _Vignette_Params1;
float4 _Vignette_Params2;
#ifdef USING_STEREO_MATRICES
float4 _Vignette_ParamsXR;
#endif
float2 _Grain_Params;
float4 _Grain_TilingParams;
float4 _Bloom_Texture_TexelSize;
Expand All @@ -68,7 +71,12 @@ Shader "Hidden/Universal Render Pipeline/UberPost"
#define LensDirtIntensity _LensDirt_Intensity.x

#define VignetteColor _Vignette_Params1.xyz
#ifdef USING_STEREO_MATRICES
#define VignetteCenterEye0 _Vignette_ParamsXR.xy
#define VignetteCenterEye1 _Vignette_ParamsXR.zw
#else
#define VignetteCenter _Vignette_Params2.xy
#endif
#define VignetteIntensity _Vignette_Params2.z
#define VignetteSmoothness _Vignette_Params2.w
#define VignetteRoundness _Vignette_Params1.w
Expand Down Expand Up @@ -191,6 +199,12 @@ Shader "Hidden/Universal Render Pipeline/UberPost"
UNITY_BRANCH
if (VignetteIntensity > 0)
{
#ifdef USING_STEREO_MATRICES
// With XR, the views can use asymmetric FOV which will have the center of each
// view be at a different location.
const float2 VignetteCenter = unity_StereoEyeIndex == 0 ? VignetteCenterEye0 : VignetteCenterEye1;
#endif

color = ApplyVignette(color, uvDistorted, VignetteCenter, VignetteIntensity, VignetteRoundness, VignetteSmoothness, VignetteColor);
}

Expand Down
Loading