From 6e8e20a30714a3110feae84e253b1947a9fe4124 Mon Sep 17 00:00:00 2001 From: Joachim Ante Date: Mon, 8 Feb 2021 12:43:52 +0100 Subject: [PATCH 01/30] Graft SRP-Picking changes --- .../ShaderLibrary/CommonMaterial.hlsl | 22 ++- .../ShaderLibrary/Debug.hlsl | 13 ++ .../ShaderLibrary/Packing.hlsl | 11 +- .../Runtime/Debug/DebugDisplay.cs | 22 ++- .../Runtime/Debug/DebugDisplay.cs.hlsl | 46 ++++--- .../Runtime/Debug/DebugFullScreen.shader | 11 ++ .../Debug/DebugViewMaterialGBuffer.shader | 2 +- .../Runtime/Debug/MaterialDebug.cs | 6 + .../Runtime/Material/Builtin/BuiltinData.cs | 8 ++ .../Material/Builtin/BuiltinData.cs.hlsl | 10 ++ .../Runtime/Material/Builtin/BuiltinData.hlsl | 14 ++ .../Runtime/Material/Decal/DecalSystem.cs | 1 + .../RenderPipeline/HDRenderPipeline.cs | 129 +++++++++++++++++- .../RenderPass/AOV/AOVRequest.cs | 72 +++++++++- .../ShaderPass/ShaderPassForward.hlsl | 4 +- .../ShaderPass/ShaderPassForwardUnlit.hlsl | 2 +- .../ShaderLibrary/ShaderVariables.hlsl | 2 + .../VFXGraph/Shaders/VFXLitPixelOutput.hlsl | 2 +- .../ShaderGraph/Includes/PBRForwardPass.hlsl | 72 ++++++++++ .../Targets/UniversalLitSubTarget.cs | 80 +++++++++++ .../ShaderGraph/Targets/UniversalTarget.cs | 19 +++ .../Runtime/Passes/DrawObjectsPass.cs | 31 +++++ .../Runtime/UniversalRenderPipeline.cs | 110 ++++++++++++++- .../ShaderLibrary/DataExtraction.hlsl | 91 ++++++++++++ .../ShaderLibrary/DataExtraction.hlsl.meta | 10 ++ .../UniversalDOTSInstancing.hlsl | 2 + .../Shaders/Lit.shader | 46 +++++++ .../Shaders/LitExtractionPass.hlsl | 127 +++++++++++++++++ .../Shaders/LitExtractionPass.hlsl.meta | 10 ++ .../Shaders/LitForwardPass.hlsl | 3 +- .../Editor/Data/Util/KeywordUtil.cs | 4 + .../Generation/Enumerations/KeywordType.cs | 3 +- 32 files changed, 947 insertions(+), 38 deletions(-) create mode 100644 com.unity.render-pipelines.universal/ShaderLibrary/DataExtraction.hlsl create mode 100644 com.unity.render-pipelines.universal/ShaderLibrary/DataExtraction.hlsl.meta create mode 100644 com.unity.render-pipelines.universal/Shaders/LitExtractionPass.hlsl create mode 100644 com.unity.render-pipelines.universal/Shaders/LitExtractionPass.hlsl.meta diff --git a/com.unity.render-pipelines.core/ShaderLibrary/CommonMaterial.hlsl b/com.unity.render-pipelines.core/ShaderLibrary/CommonMaterial.hlsl index 86e0eaa8015..0c9850105e0 100644 --- a/com.unity.render-pipelines.core/ShaderLibrary/CommonMaterial.hlsl +++ b/com.unity.render-pipelines.core/ShaderLibrary/CommonMaterial.hlsl @@ -58,9 +58,9 @@ real PerceptualSmoothnessToPerceptualRoughness(real perceptualSmoothness) // but chopping the far tails of GGX and keeping 94% of the mass yields a distribution with a defined variance where // we can then relate the roughness of GGX to a variance (see Ray Tracing Gems p153 - the reference is wrong though, // the Conty paper doesn't mention this at all, but it can be found in stats using quantiles): -// +// // roughnessGGX^2 = variance / 2 -// +// // From the two previous, if we want roughly comparable variances of slopes between a Beckmann and a GGX NDF, we can // equate the variances and get a conversion of their roughnesses: // @@ -329,4 +329,22 @@ real3 LerpWhiteTo(real3 b, real t) real oneMinusT = 1.0 - t; return real3(oneMinusT, oneMinusT, oneMinusT) + b * t; } + +// ---------------------------------------------------------------------------- +// Helper methods to convert specular <-> metallic workflow +// NOTE: Specular -> metallic is lossy, metallic can not fully represent all possible specular materials. +// ---------------------------------------------------------------------------- + +void ConvertSpecularToMetallic(float3 diffuseColor, float3 specularColor, out float3 baseColor, out float metallic) +{ + metallic = saturate( (Max3(specularColor.r, specularColor.g, specularColor.b) - 0.1F) / 0.45F); + baseColor = lerp(diffuseColor, specularColor, metallic); +} + +void ConvertMetallicToSpecular(float3 baseColor, float metallic, out float3 diffuseColor, out float3 specularColor) +{ + diffuseColor = ComputeDiffuseColor(baseColor, metallic); + specularColor = ComputeFresnel0(baseColor, metallic, DEFAULT_SPECULAR_VALUE); +} + #endif // UNITY_COMMON_MATERIAL_INCLUDED diff --git a/com.unity.render-pipelines.core/ShaderLibrary/Debug.hlsl b/com.unity.render-pipelines.core/ShaderLibrary/Debug.hlsl index 105bac1171f..9abd44ca422 100644 --- a/com.unity.render-pipelines.core/ShaderLibrary/Debug.hlsl +++ b/com.unity.render-pipelines.core/ShaderLibrary/Debug.hlsl @@ -276,4 +276,17 @@ real3 GetColorCodeFunction(real value, real4 threshold) return outColor; } +float3 PackIndexToRGB16f(uint entityId) +{ + // half can represent up to 2^11 exactly as an integer, + // use 10 bits of each channel. + uint b0 = (entityId >> 0) & 0x3ff; + uint b1 = (entityId >> 10) & 0x3ff; + uint b2 = (entityId >> 20) & 0x3ff; + float f0 = (float)b0 / 1023.0f; + float f1 = (float)b1 / 1023.0f; + float f2 = (float)b2 / 1023.0f; + return float3(f0, f1, f2); +} + #endif // UNITY_DEBUG_INCLUDED diff --git a/com.unity.render-pipelines.core/ShaderLibrary/Packing.hlsl b/com.unity.render-pipelines.core/ShaderLibrary/Packing.hlsl index 882aa4d3cc3..33edf74cbe0 100644 --- a/com.unity.render-pipelines.core/ShaderLibrary/Packing.hlsl +++ b/com.unity.render-pipelines.core/ShaderLibrary/Packing.hlsl @@ -173,6 +173,13 @@ real3 UnpackNormalRGBNoScale(real4 packedNormal) return packedNormal.rgb * 2.0 - 1.0; } +real3 PackNormalRGB(real3 normal, real scale = 1.0) +{ + normal = normal * 0.5 + 0.5; + normal.xy *= scale; + return normal; +} + real3 UnpackNormalAG(real4 packedNormal, real scale = 1.0) { real3 normal; @@ -548,7 +555,7 @@ float3 PackFloat2To888(float2 f) // Unpack 2 float of 12bit packed into a 888 float2 Unpack888ToFloat2(float3 x) { - uint3 i = (uint3)(x * 255.5); // +0.5 to fix precision error on iOS + uint3 i = (uint3)(x * 255.5); // +0.5 to fix precision error on iOS // 8 bit in lo, 4 bit in hi uint hi = i.z >> 4; uint lo = i.z & 15; @@ -567,7 +574,7 @@ float PackFloat2To8(float2 f) return x_y_expanded / 255.0; // above 4 lines equivalent to: - //return (16.0 * f.x + f.y) / 17.0; + //return (16.0 * f.x + f.y) / 17.0; } // Unpack 2 float values from the [0, 1] range, packed in an 8 bits float from the [0, 1] range diff --git a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs index 3d9e1d0fd55..952159a2202 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs @@ -40,6 +40,7 @@ unsafe struct ShaderVariablesDebugDisplay public int _DebugSingleShadowIndex; public int _DebugProbeVolumeMode; + public int _DebugAllowsRGBConversion; public Vector3 _DebugDisplayPad0; } @@ -71,6 +72,7 @@ public enum FullScreenDebugMode PreRefractionColorPyramid, /// Display the Depth Pyramid. DepthPyramid, + WorldSpacePosition, /// Display the final color pyramid for the frame. FinalColorPyramid, @@ -208,8 +210,12 @@ public class DebugData public int fullScreenContactShadowLightIndex = 0; /// XR single pass test mode. public bool xrSinglePassTestMode = false; + /// Enable range remapping. + public bool allowSRGBConversion = true; /// Whether to display the average timings every second. public bool averageProfilerTimingsOverASecond = false; + /// Debug value requires high precision. + public bool requireHighPrecision = false; /// Current material debug settings. public MaterialDebugSettings materialDebugSettings = new MaterialDebugSettings(); @@ -617,6 +623,15 @@ public void SetFullScreenDebugMode(FullScreenDebugMode value) data.fullScreenDebugMode = value; } + internal void SetAllowSRGBConversion(bool allow) + { + data.allowSRGBConversion = allow; + } + internal bool GetAllowSRGBConversion() + { + return data.allowSRGBConversion; + } + /// /// Set the current Shadow Map Debug Mode. /// @@ -1416,7 +1431,7 @@ void RegisterLightingDebug() { var container = new DebugUI.Container { - children = + children = { new DebugUI.EnumField { displayName = "Light Volume Debug Type", getter = () => (int)data.lightingDebugSettings.lightVolumeDebugByCategory, setter = value => data.lightingDebugSettings.lightVolumeDebugByCategory = (LightVolumeDebug)value, autoEnum = typeof(LightVolumeDebug), getIndex = () => data.lightVolumeDebugTypeEnumIndex, setIndex = value => data.lightVolumeDebugTypeEnumIndex = value, onValueChanged = RefreshLightingDebug } } @@ -1966,5 +1981,10 @@ internal bool DebugNeedsExposure() (data.fullScreenDebugMode == FullScreenDebugMode.PreRefractionColorPyramid || data.fullScreenDebugMode == FullScreenDebugMode.FinalColorPyramid || data.fullScreenDebugMode == FullScreenDebugMode.ScreenSpaceReflections || data.fullScreenDebugMode == FullScreenDebugMode.ScreenSpaceReflectionsPrev || data.fullScreenDebugMode == FullScreenDebugMode.ScreenSpaceReflectionsAccum || data.fullScreenDebugMode == FullScreenDebugMode.LightCluster || data.fullScreenDebugMode == FullScreenDebugMode.ScreenSpaceShadows || data.fullScreenDebugMode == FullScreenDebugMode.NanTracker || data.fullScreenDebugMode == FullScreenDebugMode.ColorLog) || data.fullScreenDebugMode == FullScreenDebugMode.ScreenSpaceGlobalIllumination || (debugLighting == DebugLightingMode.ProbeVolume || debugProbeVolume == ProbeVolumeDebugMode.VisualizeAtlas); } + + public void SetRequireHighPrecision(bool requireHighPrecision) + { + data.requireHighPrecision = requireHighPrecision; + } } } diff --git a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs.hlsl index f23e6568552..ec8f4894065 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs.hlsl @@ -17,28 +17,29 @@ #define FULLSCREENDEBUGMODE_SCREEN_SPACE_SHADOWS (7) #define FULLSCREENDEBUGMODE_PRE_REFRACTION_COLOR_PYRAMID (8) #define FULLSCREENDEBUGMODE_DEPTH_PYRAMID (9) -#define FULLSCREENDEBUGMODE_FINAL_COLOR_PYRAMID (10) -#define FULLSCREENDEBUGMODE_LIGHT_CLUSTER (11) -#define FULLSCREENDEBUGMODE_SCREEN_SPACE_GLOBAL_ILLUMINATION (12) -#define FULLSCREENDEBUGMODE_RECURSIVE_RAY_TRACING (13) -#define FULLSCREENDEBUGMODE_RAY_TRACED_SUB_SURFACE (14) -#define FULLSCREENDEBUGMODE_MAX_LIGHTING_FULL_SCREEN_DEBUG (15) -#define FULLSCREENDEBUGMODE_MIN_RENDERING_FULL_SCREEN_DEBUG (16) -#define FULLSCREENDEBUGMODE_MOTION_VECTORS (17) -#define FULLSCREENDEBUGMODE_NAN_TRACKER (18) -#define FULLSCREENDEBUGMODE_COLOR_LOG (19) -#define FULLSCREENDEBUGMODE_DEPTH_OF_FIELD_COC (20) -#define FULLSCREENDEBUGMODE_TRANSPARENCY_OVERDRAW (21) -#define FULLSCREENDEBUGMODE_QUAD_OVERDRAW (22) -#define FULLSCREENDEBUGMODE_VERTEX_DENSITY (23) -#define FULLSCREENDEBUGMODE_REQUESTED_VIRTUAL_TEXTURE_TILES (24) -#define FULLSCREENDEBUGMODE_MAX_RENDERING_FULL_SCREEN_DEBUG (25) -#define FULLSCREENDEBUGMODE_MIN_MATERIAL_FULL_SCREEN_DEBUG (26) -#define FULLSCREENDEBUGMODE_VALIDATE_DIFFUSE_COLOR (27) -#define FULLSCREENDEBUGMODE_VALIDATE_SPECULAR_COLOR (28) -#define FULLSCREENDEBUGMODE_MAX_MATERIAL_FULL_SCREEN_DEBUG (29) -#define FULLSCREENDEBUGMODE_SCREEN_SPACE_REFLECTIONS_PREV (30) -#define FULLSCREENDEBUGMODE_SCREEN_SPACE_REFLECTIONS_ACCUM (31) +#define FULLSCREENDEBUGMODE_WORLD_SPACE_POSITION (10) +#define FULLSCREENDEBUGMODE_FINAL_COLOR_PYRAMID (11) +#define FULLSCREENDEBUGMODE_LIGHT_CLUSTER (12) +#define FULLSCREENDEBUGMODE_SCREEN_SPACE_GLOBAL_ILLUMINATION (13) +#define FULLSCREENDEBUGMODE_RECURSIVE_RAY_TRACING (14) +#define FULLSCREENDEBUGMODE_RAY_TRACED_SUB_SURFACE (15) +#define FULLSCREENDEBUGMODE_MAX_LIGHTING_FULL_SCREEN_DEBUG (16) +#define FULLSCREENDEBUGMODE_MIN_RENDERING_FULL_SCREEN_DEBUG (17) +#define FULLSCREENDEBUGMODE_MOTION_VECTORS (18) +#define FULLSCREENDEBUGMODE_NAN_TRACKER (19) +#define FULLSCREENDEBUGMODE_COLOR_LOG (20) +#define FULLSCREENDEBUGMODE_DEPTH_OF_FIELD_COC (21) +#define FULLSCREENDEBUGMODE_TRANSPARENCY_OVERDRAW (22) +#define FULLSCREENDEBUGMODE_QUAD_OVERDRAW (23) +#define FULLSCREENDEBUGMODE_VERTEX_DENSITY (24) +#define FULLSCREENDEBUGMODE_REQUESTED_VIRTUAL_TEXTURE_TILES (25) +#define FULLSCREENDEBUGMODE_MAX_RENDERING_FULL_SCREEN_DEBUG (26) +#define FULLSCREENDEBUGMODE_MIN_MATERIAL_FULL_SCREEN_DEBUG (27) +#define FULLSCREENDEBUGMODE_VALIDATE_DIFFUSE_COLOR (28) +#define FULLSCREENDEBUGMODE_VALIDATE_SPECULAR_COLOR (29) +#define FULLSCREENDEBUGMODE_MAX_MATERIAL_FULL_SCREEN_DEBUG (30) +#define FULLSCREENDEBUGMODE_SCREEN_SPACE_REFLECTIONS_PREV (31) +#define FULLSCREENDEBUGMODE_SCREEN_SPACE_REFLECTIONS_ACCUM (32) // Generated from UnityEngine.Rendering.HighDefinition.ShaderVariablesDebugDisplay // PackingRules = Exact @@ -68,6 +69,7 @@ CBUFFER_START(ShaderVariablesDebugDisplay) float _MatcapViewScale; int _DebugSingleShadowIndex; int _DebugProbeVolumeMode; + int _DebugAllowsRGBConversion; float3 _DebugDisplayPad0; CBUFFER_END diff --git a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugFullScreen.shader b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugFullScreen.shader index 951f62b6d71..1e421d9b929 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugFullScreen.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugFullScreen.shader @@ -332,6 +332,17 @@ Shader "Hidden/HDRP/DebugFullScreen" return float4(linearDepth.xxx, 1.0); } + if (_FullScreenDebugMode == FULLSCREENDEBUGMODE_WORLD_SPACE_POSITION) + { + float depth = LoadCameraDepth(input.positionCS.xy); + PositionInputs posInput = GetPositionInput(input.positionCS.xy, _ScreenSize.zw, depth, UNITY_MATRIX_I_VP, UNITY_MATRIX_V); + float3 positionWS = GetAbsolutePositionWS(posInput.positionWS); + + if (depth != 0) + return float4(positionWS.xyz, 1.0); + return float4(0.0, 0.0, 0.0, 0.0); + } + if (_FullScreenDebugMode == FULLSCREENDEBUGMODE_TRANSPARENCY_OVERDRAW) { float4 color = (float4)0; diff --git a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugViewMaterialGBuffer.shader b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugViewMaterialGBuffer.shader index a394ee02686..b96aa04e326 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugViewMaterialGBuffer.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugViewMaterialGBuffer.shader @@ -119,7 +119,7 @@ Shader "Hidden/HDRP/DebugViewMaterialGBuffer" // TEMP! // For now, the final blit in the backbuffer performs an sRGB write // So in the meantime we apply the inverse transform to linear data to compensate. - if (!needLinearToSRGB) + if (!needLinearToSRGB && _DebugAllowsRGBConversion) result = SRGBToLinear(max(0, result)); return float4(result, 1.0); diff --git a/com.unity.render-pipelines.high-definition/Runtime/Debug/MaterialDebug.cs b/com.unity.render-pipelines.high-definition/Runtime/Debug/MaterialDebug.cs index 11c320933de..8bff9da5a8b 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Debug/MaterialDebug.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Debug/MaterialDebug.cs @@ -106,6 +106,10 @@ public enum MaterialSharedProperty Specular, /// Display alpha. Alpha, + /// Display entity ID. + EntityId, + /// Display object ID. + ObjectId, } class MaterialSharedPropertyMappingAttribute : Attribute @@ -354,6 +358,8 @@ static void BuildDebugRepresentation() { MaterialSharedProperty.Metal, new List() }, { MaterialSharedProperty.Specular, new List() }, { MaterialSharedProperty.Alpha, new List() }, + { MaterialSharedProperty.EntityId, new List() }, + { MaterialSharedProperty.ObjectId, new List() }, }; // builtins parameters diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Builtin/BuiltinData.cs b/com.unity.render-pipelines.high-definition/Runtime/Material/Builtin/BuiltinData.cs index 047bb09be6e..b693f9036ed 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Builtin/BuiltinData.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Builtin/BuiltinData.cs @@ -66,6 +66,14 @@ public struct BuiltinData [SurfaceDataAttributes("VT Packed Feedback", precision = FieldPrecision.Real)] public Vector4 vtPackedFeedback; + + [MaterialSharedPropertyMapping(MaterialSharedProperty.EntityId)] + [SurfaceDataAttributes("Entity Id")] + public uint entityId; + + [MaterialSharedPropertyMapping(MaterialSharedProperty.ObjectId)] + [SurfaceDataAttributes("Object Id")] + public uint objectId; }; //----------------------------------------------------------------------------- diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Builtin/BuiltinData.cs.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/Builtin/BuiltinData.cs.hlsl index 108595d8bd4..da74007e2e9 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Builtin/BuiltinData.cs.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Builtin/BuiltinData.cs.hlsl @@ -22,6 +22,8 @@ #define DEBUGVIEW_BUILTIN_BUILTINDATA_RENDERING_LAYERS (112) #define DEBUGVIEW_BUILTIN_BUILTINDATA_DEPTH_OFFSET (113) #define DEBUGVIEW_BUILTIN_BUILTINDATA_VT_PACKED_FEEDBACK (114) +#define DEBUGVIEW_BUILTIN_BUILTINDATA_ENTITY_ID (115) +#define DEBUGVIEW_BUILTIN_BUILTINDATA_OBJECT_ID (116) // Generated from UnityEngine.Rendering.HighDefinition.Builtin+BuiltinData // PackingRules = Exact @@ -42,6 +44,8 @@ struct BuiltinData uint renderingLayers; float depthOffset; real4 vtPackedFeedback; + uint entityId; + uint objectId; }; // Generated from UnityEngine.Rendering.HighDefinition.Builtin+LightTransportData @@ -106,6 +110,12 @@ void GetGeneratedBuiltinDataDebug(uint paramId, BuiltinData builtindata, inout f case DEBUGVIEW_BUILTIN_BUILTINDATA_VT_PACKED_FEEDBACK: result = builtindata.vtPackedFeedback.xyz; break; + case DEBUGVIEW_BUILTIN_BUILTINDATA_ENTITY_ID: + result = GetIndexColor(builtindata.entityId); + break; + case DEBUGVIEW_BUILTIN_BUILTINDATA_OBJECT_ID: + result = GetIndexColor(builtindata.objectId); + break; } } diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Builtin/BuiltinData.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/Builtin/BuiltinData.hlsl index 39c22b59120..154a7d5b928 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Builtin/BuiltinData.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Builtin/BuiltinData.hlsl @@ -78,6 +78,20 @@ void GetBuiltinDataDebug(uint paramId, BuiltinData builtinData, PositionInputs p case DEBUGVIEW_BUILTIN_BUILTINDATA_DISTORTION: result = float3((builtinData.distortion / (abs(builtinData.distortion) + 1) + 1) * 0.5, 0.5); break; + case DEBUGVIEW_BUILTIN_BUILTINDATA_ENTITY_ID: +#ifdef UNITY_DOTS_INSTANCING_ENABLED + result = PackIndexToRGB16f(unity_EntityId.x); +#else + result = 0; +#endif + break; + case DEBUGVIEW_BUILTIN_BUILTINDATA_OBJECT_ID: +#ifdef UNITY_SHADER_VARIABLES_INCLUDED + result = PackIndexToRGB16f(asuint(unity_LODFade.z)); +#else + result = 0; +#endif + break; #ifdef DEBUG_DISPLAY case DEBUGVIEW_BUILTIN_BUILTINDATA_RENDERING_LAYERS: // Only 8 first rendering layers are currently in use (used by light layers) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalSystem.cs b/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalSystem.cs index 9364a3f5fac..9c01c9ff35e 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalSystem.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalSystem.cs @@ -527,6 +527,7 @@ public DecalHandle AddDecal(int materialID, in DecalProjector.CachedDecalData da ulong[] newCachedSceneLayerMask = new ulong[m_DecalsCount + kDecalBlockSize]; var cachedDecalLayerMask = new DecalLayerEnum[m_DecalsCount + kDecalBlockSize]; float[] newCachedFadeFactor = new float[m_DecalsCount + kDecalBlockSize]; + m_ResultIndices = new int[m_DecalsCount + kDecalBlockSize]; m_Handles.CopyTo(newHandles, 0); diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs index 25bcafaf651..804164e7020 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs @@ -3,6 +3,7 @@ using System; using System.Diagnostics; using System.Linq; +using Unity.Collections; using UnityEngine.Experimental.GlobalIllumination; using UnityEngine.Experimental.Rendering; using UnityEngine.Experimental.Rendering.RenderGraphModule; @@ -304,6 +305,9 @@ internal int GetMaxScreenSpaceShadows() RTHandle m_DebugFullScreenTempBuffer; // This target is only used in Dev builds as an intermediate destination for post process and where debug rendering will be done. RTHandle m_IntermediateAfterPostProcessBuffer; + RTHandle m_IntermediateAfterPostProcessBufferFloat; + RTHandle m_HighPrecisionDebugBufferFloat; + // We need this flag because otherwise if no full screen debug is pushed (like for example if the corresponding pass is disabled), when we render the result in RenderDebug m_DebugFullScreenTempBuffer will contain potential garbage bool m_FullScreenDebugPushed; bool m_ValidAPI; // False by default mean we render normally, true mean we don't render anything @@ -834,9 +838,11 @@ void DestroyRenderTextures() RTHandles.Release(m_DebugColorPickerBuffer); RTHandles.Release(m_DebugFullScreenTempBuffer); RTHandles.Release(m_IntermediateAfterPostProcessBuffer); + RTHandles.Release(m_IntermediateAfterPostProcessBufferFloat); m_DebugColorPickerBuffer = null; m_DebugFullScreenTempBuffer = null; m_IntermediateAfterPostProcessBuffer = null; + m_IntermediateAfterPostProcessBufferFloat = null; if (m_RayTracingSupported) { @@ -2976,7 +2982,7 @@ void Callback(CommandBuffer c, HDCamera cam) RenderCustomPass(renderContext, cmd, hdCamera, customPassCullingResults, CustomPassInjectionPoint.BeforePostProcess, aovRequest, aovCustomPassBuffers); if (aovRequest.isValid) - aovRequest.PushCameraTexture(cmd, AOVBuffers.Color, hdCamera, m_CameraColorBuffer, aovBuffers); + aovRequest.PushCameraTexture(cmd, AOVBuffers.Color, hdCamera, GetDebugViewTargetBuffer(), aovBuffers); RenderTargetIdentifier postProcessDest = HDUtils.PostProcessIsFinalPass(hdCamera) ? target.id : m_IntermediateAfterPostProcessBuffer; RenderPostProcess(cullingResults, hdCamera, postProcessDest, renderContext, cmd); @@ -3156,6 +3162,115 @@ static void BlitFinalCameraTexture(BlitFinalCameraTextureParameters parameters, HDUtils.DrawFullScreen(cmd, parameters.viewport, parameters.blitMaterial, destination, propertyBlock, 0, parameters.dstTexArraySlice); } + protected override void ProcessRenderRequests(ScriptableRenderContext renderContext, Camera camera, List renderRequests) + { + var previousRT = RenderTexture.active; + RenderTexture.active = null; + + if (m_IntermediateAfterPostProcessBufferFloat == null) + m_IntermediateAfterPostProcessBufferFloat = RTHandles.Alloc(Vector2.one, TextureXR.slices, dimension: TextureXR.dimension, colorFormat: GraphicsFormat.R32G32B32A32_SFloat, useDynamicScale: true, name: "AfterPostProcessFloat"); + + var previousPostprocessBuffer = m_IntermediateAfterPostProcessBuffer; + m_IntermediateAfterPostProcessBuffer = m_IntermediateAfterPostProcessBufferFloat; + + try + { + if (renderRequests.Count == 1 && + renderRequests[0].isValid && + renderRequests[0].mode == Camera.RenderRequestMode.OutlineMask) + { + var additionalCameraData = camera.GetComponent(); + if (additionalCameraData == null) + { + camera.gameObject.AddComponent(); + additionalCameraData = camera.GetComponent(); + } + + additionalCameraData.customRender += RenderOutlineMask; + m_OutlineMaskTarget = renderRequests[0].result; + + try + { + Render(renderContext, new[] {camera}); + } + finally + { + additionalCameraData.customRender -= RenderOutlineMask; + } + + return; + } + + var requests = new AOVRequestBuilder(); + foreach (var request in renderRequests) + { + var aovRequest = AOVRequest.NewDefault().SetRenderRequestMode(request.mode); + var aovBuffers = AOVBuffers.Color; + if (request.mode == Camera.RenderRequestMode.Depth || + request.mode == Camera.RenderRequestMode.WorldPosition) + aovBuffers = AOVBuffers.Output; + + requests.Add( + aovRequest, + // NOTE: RTHandles.Alloc is never allocated because the texture is passed in explicitly. + (AOVBuffers aovBufferId) => RTHandles.Alloc(request.result), + null, + new[] {aovBuffers}, + (cmd, textures, properties) => + { + //if (request.result != null) + // cmd.Blit(textures[0], request.result); + }); + } + + var additionaCameraData = camera.GetComponent(); + if (additionaCameraData == null) + { + camera.gameObject.AddComponent(); + additionaCameraData = camera.GetComponent(); + } + additionaCameraData.SetAOVRequests(requests.Build()); + + Render(renderContext, new[] {camera}); + + additionaCameraData.SetAOVRequests(null); + } + finally + { + m_IntermediateAfterPostProcessBuffer = previousPostprocessBuffer; + RenderTexture.active = previousRT; + } + } + + RenderTexture m_OutlineMaskTarget; + void RenderOutlineMask(ScriptableRenderContext context, HDCamera hdCamera) + { + Debug.Log("RenderOutlineMask"); + var cmd = CommandBufferPool.Get(""); + + // TODO: Need depth target. + cmd.SetRenderTarget(m_OutlineMaskTarget); + cmd.ClearRenderTarget(true, true, Color.black); + + var camera = hdCamera.camera; + camera.TryGetCullingParameters(out var cullingParameters); + var cullingResults = context.Cull(ref cullingParameters); + + var sceneSelectionTag = new ShaderTagId("SceneSelectionPass"); + + var drawingSettings = new DrawingSettings( + sceneSelectionTag, + new SortingSettings(camera) { criteria = SortingCriteria.None}); + + var filteringSettings = FilteringSettings.defaultValue; + + context.ExecuteCommandBuffer(cmd); + context.DrawRenderers( + cullingResults, + ref drawingSettings, + ref filteringSettings); + } + void SetupCameraProperties(HDCamera hdCamera, ScriptableRenderContext renderContext, CommandBuffer cmd) { // The next 2 functions are required to flush the command buffer before calling functions directly on the render context. @@ -4094,7 +4209,8 @@ void RenderDebugViewMaterial(CullingResults cull, HDCamera hdCamera, ScriptableR { // When rendering debug material we shouldn't rely on a depth prepass for optimizing the alpha clip test. As it is control on the material inspector side // we must override the state here. - CoreUtils.SetRenderTarget(cmd, m_CameraColorBuffer, m_SharedRTManager.GetDepthStencilBuffer(), ClearFlag.All, Color.clear); + var debugViewTargetBuffer = GetDebugViewTargetBuffer(); + CoreUtils.SetRenderTarget(cmd, debugViewTargetBuffer, m_SharedRTManager.GetDepthStencilBuffer(), ClearFlag.All, Color.clear); // [case 1273223] When the camera is stacked on top of another one, we need to clear the debug view RT using the data from the previous camera in the stack var clearColorTexture = Compositor.CompositionManager.GetClearTextureForStackedCamera(hdCamera); // returns null if is not a stacked camera @@ -4115,6 +4231,14 @@ void RenderDebugViewMaterial(CullingResults cull, HDCamera hdCamera, ScriptableR } } + private RTHandle GetDebugViewTargetBuffer() + { + if (m_CurrentDebugDisplaySettings.data.requireHighPrecision) + return m_DebugFullScreenTempBuffer; + else + return m_CameraColorBuffer; + } + struct TransparencyOverdrawParameters { public ShaderVariablesDebugDisplay constantBuffer; @@ -5125,6 +5249,7 @@ unsafe void ApplyDebugDisplaySettings(HDCamera hdCamera, CommandBuffer cmd) cb._ColorPickerMode = (int)m_CurrentDebugDisplaySettings.GetDebugColorPickerMode(); cb._DebugFullScreenMode = (int)m_CurrentDebugDisplaySettings.data.fullScreenDebugMode; cb._DebugProbeVolumeMode = (int)m_CurrentDebugDisplaySettings.GetProbeVolumeDebugMode(); + cb._DebugAllowsRGBConversion = m_CurrentDebugDisplaySettings.GetAllowSRGBConversion() ? 1 : 0; #if UNITY_EDITOR cb._MatcapMixAlbedo = HDRenderPipelinePreferences.matcapViewMixAlbedo ? 1 : 0; diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVRequest.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVRequest.cs index 97bedec4d4f..ed58665dd8a 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVRequest.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVRequest.cs @@ -52,9 +52,13 @@ public unsafe struct AOVRequest m_MaterialProperty = MaterialSharedProperty.None, m_LightingProperty = LightingProperty.None, m_DebugFullScreen = DebugFullScreen.None, - m_LightFilterProperty = DebugLightFilterMode.None + m_LightFilterProperty = DebugLightFilterMode.None, + m_RequestMode = Camera.RenderRequestMode.None }; + + + Camera.RenderRequestMode m_RequestMode; MaterialSharedProperty m_MaterialProperty; LightingProperty m_LightingProperty; DebugLightFilterMode m_LightFilterProperty; @@ -77,6 +81,7 @@ public AOVRequest(AOVRequest other) m_LightingProperty = other.m_LightingProperty; m_DebugFullScreen = other.m_DebugFullScreen; m_LightFilterProperty = other.m_LightFilterProperty; + m_RequestMode = other.m_RequestMode; } /// State the property to render. In case of several SetFullscreenOutput chained call, only last will be used. @@ -115,6 +120,12 @@ public ref AOVRequest SetLightFilter(DebugLightFilterMode filter) return ref *thisPtr; } + public ref AOVRequest SetRenderRequestMode(Camera.RenderRequestMode mode) + { + m_RequestMode = mode; + return ref *thisPtr; + } + /// /// Populate the debug display settings with the AOV data. /// @@ -175,6 +186,65 @@ public void FillDebugData(DebugDisplaySettings debug) default: throw new ArgumentException("Unknown DebugFullScreen"); } + + if (m_RequestMode != Camera.RenderRequestMode.None) + { + debug.SetAllowSRGBConversion(false); + debug.SetRequireHighPrecision(false); + + switch (m_RequestMode) + { + case Camera.RenderRequestMode.ObjectId: + debug.SetRequireHighPrecision(true); + debug.SetDebugViewCommonMaterialProperty(MaterialSharedProperty.ObjectId); + break; + case Camera.RenderRequestMode.Depth: + debug.SetFullScreenDebugMode(FullScreenDebugMode.DepthPyramid); + break; + case Camera.RenderRequestMode.VertexNormal: + debug.SetDebugViewVarying(DebugViewVarying.VertexNormalWS); + break; + case Camera.RenderRequestMode.WorldPosition: + debug.SetFullScreenDebugMode(FullScreenDebugMode.WorldSpacePosition); + break; + case Camera.RenderRequestMode.EntityId: + debug.SetRequireHighPrecision(true); + debug.SetDebugViewCommonMaterialProperty(MaterialSharedProperty.EntityId); + break; + case Camera.RenderRequestMode.BaseColor: + //@TODO: This should perform metallic / specular conversion + debug.SetDebugViewCommonMaterialProperty(MaterialSharedProperty.Albedo); + break; + case Camera.RenderRequestMode.SpecularColor: + debug.SetDebugViewCommonMaterialProperty(MaterialSharedProperty.Specular); + break; + case Camera.RenderRequestMode.Metallic: + debug.SetDebugViewCommonMaterialProperty(MaterialSharedProperty.Metal); + break; + case Camera.RenderRequestMode.Emission: + debug.SetDebugLightingMode(DebugLightingMode.EmissiveLighting); + break; + case Camera.RenderRequestMode.Normal: + debug.SetDebugViewCommonMaterialProperty(MaterialSharedProperty.Normal); + break; + case Camera.RenderRequestMode.Smoothness: + debug.SetDebugViewCommonMaterialProperty(MaterialSharedProperty.Smoothness); + break; + case Camera.RenderRequestMode.Occlusion: + debug.SetDebugViewCommonMaterialProperty(MaterialSharedProperty.AmbientOcclusion); + break; + case Camera.RenderRequestMode.DiffuseColor: + //@TODO: This should perform metallic / specular conversion + debug.SetDebugViewCommonMaterialProperty(MaterialSharedProperty.Albedo); + break; + default: + throw new ArgumentOutOfRangeException(nameof(m_RequestMode), m_RequestMode, null); + } + } + else + { + debug.SetAllowSRGBConversion(true); + } } } } diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassForward.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassForward.hlsl index b4b8f76bc69..b8e1b41c038 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassForward.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassForward.hlsl @@ -184,8 +184,8 @@ void Frag(PackedVaryingsToPS packedInput, // TEMP! // For now, the final blit in the backbuffer performs an sRGB write // So in the meantime we apply the inverse transform to linear data to compensate. - if (!needLinearToSRGB) - result = SRGBToLinear(max(0, result)); + if (needLinearToSRGB && _DebugAllowsRGBConversion != 0) + result = LinearToSRGB(max(0, result)); outColor = float4(result, 1.0); } diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassForwardUnlit.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassForwardUnlit.hlsl index 8627bbae2f3..270f84ae061 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassForwardUnlit.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassForwardUnlit.hlsl @@ -139,7 +139,7 @@ void Frag(PackedVaryingsToPS packedInput, // TEMP! // For now, the final blit in the backbuffer performs an sRGB write // So in the meantime we apply the inverse transform to linear data to compensate. - if (!needLinearToSRGB) + if (!needLinearToSRGB && _DebugAllowsRGBConversion != 0) result = SRGBToLinear(max(0, result)); outResult = float4(result, 1.0); diff --git a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl index 6f35c90e717..b59153a5779 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl @@ -372,6 +372,7 @@ UNITY_DOTS_INSTANCING_START(BuiltinPropertyMetadata) UNITY_DOTS_INSTANCED_PROP(float4, unity_ProbesOcclusion) UNITY_DOTS_INSTANCED_PROP(float3x4, unity_MatrixPreviousM) UNITY_DOTS_INSTANCED_PROP(float3x4, unity_MatrixPreviousMI) + UNITY_DOTS_INSTANCED_PROP(uint2, unity_EntityId) UNITY_DOTS_INSTANCING_END(BuiltinPropertyMetadata) // Note: Macros for unity_ObjectToWorld and unity_WorldToObject are declared elsewhere @@ -389,6 +390,7 @@ UNITY_DOTS_INSTANCING_END(BuiltinPropertyMetadata) #define unity_SHBb UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_SHBb) #define unity_SHC UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_SHC) #define unity_ProbesOcclusion UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_ProbesOcclusion) +#define unity_EntityId UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(uint2, Metadata_unity_EntityId) #define unity_MatrixPreviousM LoadDOTSInstancedData_float4x4_from_float3x4(UNITY_DOTS_INSTANCED_METADATA_NAME_FROM_MACRO(float3x4, Metadata_unity_MatrixPreviousM)) #define unity_MatrixPreviousMI LoadDOTSInstancedData_float4x4_from_float3x4(UNITY_DOTS_INSTANCED_METADATA_NAME_FROM_MACRO(float3x4, Metadata_unity_MatrixPreviousMI)) diff --git a/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXLitPixelOutput.hlsl b/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXLitPixelOutput.hlsl index ab8602b8766..abfceaf4d75 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXLitPixelOutput.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXLitPixelOutput.hlsl @@ -67,7 +67,7 @@ float4 VFXCalcPixelOutputForward(const SurfaceData surfaceData, const BuiltinDat // TEMP! // For now, the final blit in the backbuffer performs an sRGB write // So in the meantime we apply the inverse transform to linear data to compensate. - if (!needLinearToSRGB) + if (!needLinearToSRGB && _DebugAllowsRGBConversion != 0) result = SRGBToLinear(max(0, result)); outColor = float4(result, 1.0); diff --git a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/PBRForwardPass.hlsl b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/PBRForwardPass.hlsl index a884b754e73..4d2cdbda2da 100644 --- a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/PBRForwardPass.hlsl +++ b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/PBRForwardPass.hlsl @@ -1,3 +1,5 @@ +#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DataExtraction.hlsl" + void BuildInputData(Varyings input, SurfaceDescription surfaceDescription, out InputData inputData) { inputData.positionWS = input.positionWS; @@ -93,3 +95,73 @@ half4 frag(PackedVaryings packedInput) : SV_TARGET color.rgb = MixFog(color.rgb, inputData.fogCoord); return color; } + +PackedVaryings vertExtraction( + Attributes input) +{ + Varyings output = (Varyings)0; + output = BuildVaryings(input); + PackedVaryings packedOutput = (PackedVaryings)0; + packedOutput = PackVaryings(output); + +/* Not yet supported. + if (UNITY_DataExtraction_Space == 0) + packedOutput.positionCS = float4(uv0, 0.0F, 1.0f); + else if (UNITY_DataExtraction_Space == 1) + packedOutput.positionCS = float4(uv1, 0.0F, 1.0f); + else if (UNITY_DataExtraction_Space == 2) + packedOutput.positionCS = float4(uv2, 0.0F, 1.0f); + else if (UNITY_DataExtraction_Space == 3) + packedOutput.positionCS = float4(uv3, 0.0F, 1.0f); + else if (UNITY_DataExtraction_Space == 4) + packedOutput.positionCS = float4(uv4, 0.0F, 1.0f); + else if (UNITY_DataExtraction_Space == 5) + packedOutput.positionCS = float4(uv5, 0.0F, 1.0f); + else if (UNITY_DataExtraction_Space == 6) + packedOutput.positionCS = float4(uv6, 0.0F, 1.0f); + else if (UNITY_DataExtraction_Space == 7) + packedOutput.positionCS = float4(uv7, 0.0F, 1.0f); +*/ + return packedOutput; +} + +half4 fragExtraction(PackedVaryings packedInput) : SV_TARGET +{ + Varyings unpacked = UnpackVaryings(packedInput); + UNITY_SETUP_INSTANCE_ID(unpacked); + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(unpacked); + + SurfaceDescriptionInputs surfaceDescriptionInputs = BuildSurfaceDescriptionInputs(unpacked); + SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs); + + #if _AlphaClip + half alpha = surfaceDescription.Alpha; + clip(alpha - surfaceDescription.AlphaClipThreshold); + #elif _SURFACE_TYPE_TRANSPARENT + half alpha = surfaceDescription.Alpha; + #else + half alpha = 1; + #endif + + InputData inputData; + BuildInputData(unpacked, surfaceDescription, inputData); + + ExtractionInputs extraction; + extraction.vertexNormalWS = unpacked.normalWS; + extraction.pixelNormalWS = inputData.normalWS; + extraction.positionWS = inputData.positionWS; + extraction.baseColor = surfaceDescription.BaseColor; + extraction.alpha = alpha; + #ifdef _SPECULAR_SETUP + extraction.specular = surfaceDescription.Specular; + #else + extraction.metallic = surfaceDescription.Metallic; + #endif + extraction.smoothness = surfaceDescription.Smoothness; + extraction.occlusion = surfaceDescription.Occlusion; + extraction.emission = surfaceDescription.Emission.xyz; + + return OutputExtraction(extraction); +} + + diff --git a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalLitSubTarget.cs b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalLitSubTarget.cs index 2855f110f0f..dc2ef87fab5 100644 --- a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalLitSubTarget.cs +++ b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalLitSubTarget.cs @@ -290,6 +290,7 @@ private static PassDescriptor PassVariant( in PassDescriptor source, BlockFieldD passes = new PassCollection { { PassVariant(LitPasses.Forward, CorePragmas.DOTSForward) }, + { PassVariant(LitPasses.DataExtraction, CorePragmas.DOTSDataExtraction) }, { LitPasses.GBuffer }, { PassVariant(CorePasses.ShadowCaster, CorePragmas.DOTSInstanced) }, { PassVariant(CorePasses.DepthOnly, CorePragmas.DOTSInstanced) }, @@ -345,6 +346,7 @@ private static PassDescriptor PassVariant( in PassDescriptor source, BlockFieldD passes = new PassCollection { { LitPasses.ForwardOnly }, + { LitPasses.DataExtraction }, { CorePasses.ShadowCaster }, { CorePasses.DepthOnly }, { LitPasses.DepthNormalOnly }, @@ -385,6 +387,34 @@ static class LitPasses keywords = LitKeywords.Forward, includes = LitIncludes.Forward, }; + + public static PassDescriptor DataExtraction = new PassDescriptor + { + // Definition + displayName = "Data Extraction", + referenceName = "DATA_EXTRACTION", + lightMode = "DataExtraction", + useInPreview = false, + + // Template + passTemplatePath = GenerationUtils.GetDefaultTemplatePath("PassMesh.template"), + sharedTemplateDirectories = GenerationUtils.GetDefaultSharedTemplateDirectories(), + + // Port Mask + validVertexBlocks = CoreBlockMasks.Vertex, + validPixelBlocks = LitBlockMasks.FragmentLit, + + // Fields + structs = CoreStructCollections.Default, + requiredFields = LitRequiredFields.Forward, + fieldDependencies = CoreFieldDependencies.Default, + + // Conditional State + renderStates = CoreRenderStates.Default, + pragmas = CorePragmas.DataExtraction, + keywords = LitKeywords.DataExtraction, + includes = LitIncludes.Forward, + }; public static PassDescriptor ForwardOnly = new PassDescriptor { @@ -674,6 +704,56 @@ static class LitKeywords { CoreKeywordDescriptors.LightmapShadowMixing }, { CoreKeywordDescriptors.ShadowsShadowmask }, }; + + public static KeywordCollection DataExtraction = new KeywordCollection + { + new KeywordDescriptor() + { + displayName = "Extraction Modes", + referenceName = "", + type = KeywordType.MultiCompile, + definition = KeywordDefinition.MultiCompile, + scope = KeywordScope.Global, + value = 0, + entries = new[] + { + new KeywordEntry("None", "_"), + new KeywordEntry("Object Id", "RENDER_OBJECT_ID"), + new KeywordEntry("Depth", "RENDER_DEPTH"), + new KeywordEntry("World Normals (face)", "RENDER_WORLD_NORMALS_FACE"), + new KeywordEntry("World Normals (pixel)", "RENDER_WORLD_NORMALS_PIXEL"), + new KeywordEntry("World Position", "RENDER_WORLD_POSITION"), + new KeywordEntry("Base Color + Alpha", "RENDER_BASE_COLOR_ALPHA"), + new KeywordEntry("Specular(RGB) Metallic(A)", "RENDER_SPECULAR_METALLIC"), + new KeywordEntry("Emission(RGB)", "RENDER_EMISSION"), + new KeywordEntry("Smoothness(r) + Occlusion (g)", "RENDER_SMOOTHNESS_OCCLUSION"), + new KeywordEntry("EntityId", "RENDER_ENTITY_ID"), + }, + }, + new KeywordDescriptor() + { + displayName = "Extraction Output Space", + referenceName = "", + type = KeywordType.MultiCompile, + definition = KeywordDefinition.MultiCompile, + scope = KeywordScope.Global, + value = 0, + entries = new[] + { + new KeywordEntry("Mesh", "_"), + new KeywordEntry("UV0", "RENDER_SPACE_UV0"), + new KeywordEntry("UV1", "RENDER_SPACE_UV1"), + new KeywordEntry("UV2", "RENDER_SPACE_UV2"), + new KeywordEntry("UV3", "RENDER_SPACE_UV3"), + new KeywordEntry("UV4", "RENDER_SPACE_UV4"), + new KeywordEntry("UV5", "RENDER_SPACE_UV5"), + new KeywordEntry("UV6", "RENDER_SPACE_UV6"), + new KeywordEntry("UV7", "RENDER_SPACE_UV7"), + new KeywordEntry("UV8", "RENDER_SPACE_UV8"), + }, + } + }; + public static readonly KeywordCollection GBuffer = new KeywordCollection { diff --git a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalTarget.cs b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalTarget.cs index 98454ea1c45..6e0b2422591 100644 --- a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalTarget.cs +++ b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalTarget.cs @@ -545,6 +545,15 @@ static class CorePragmas { Pragma.Fragment("frag") }, }; + public static readonly PragmaCollection DataExtraction = new PragmaCollection + { + { Pragma.Target(ShaderModel.Target20) }, + { Pragma.OnlyRenderers(new[]{ Platform.GLES, Platform.GLES3, Platform.GLCore }) }, + { Pragma.MultiCompileInstancing }, + { Pragma.Vertex("vertExtraction") }, + { Pragma.Fragment("fragExtraction") }, + }; + public static readonly PragmaCollection _2DDefault = new PragmaCollection { { Pragma.Target(ShaderModel.Target20) }, @@ -582,6 +591,16 @@ static class CorePragmas { Pragma.Fragment("frag") }, }; + public static readonly PragmaCollection DOTSDataExtraction = new PragmaCollection + { + { Pragma.Target(ShaderModel.Target45) }, + { Pragma.ExcludeRenderers(new[]{ Platform.GLES, Platform.GLES3, Platform.GLCore }) }, + { Pragma.MultiCompileFog }, + { Pragma.DOTSInstancing }, + { Pragma.Vertex("vertExtraction") }, + { Pragma.Fragment("fragExtraction") }, + }; + public static readonly PragmaCollection DOTSGBuffer = new PragmaCollection { { Pragma.Target(ShaderModel.Target45) }, diff --git a/com.unity.render-pipelines.universal/Runtime/Passes/DrawObjectsPass.cs b/com.unity.render-pipelines.universal/Runtime/Passes/DrawObjectsPass.cs index d04ba87033f..4b1ec3491f2 100644 --- a/com.unity.render-pipelines.universal/Runtime/Passes/DrawObjectsPass.cs +++ b/com.unity.render-pipelines.universal/Runtime/Passes/DrawObjectsPass.cs @@ -18,9 +18,30 @@ public class DrawObjectsPass : ScriptableRenderPass string m_ProfilerTag; ProfilingSampler m_ProfilingSampler; bool m_IsOpaque; + + List m_AdditionalShaderKeywords = new List(); + Dictionary m_AdditionalValues = new Dictionary(); static readonly int s_DrawObjectPassDataPropID = Shader.PropertyToID("_DrawObjectPassData"); + public void SetAdditionalKeywords(IEnumerable words) + { + m_AdditionalShaderKeywords.Clear(); + foreach (var word in words) + { + m_AdditionalShaderKeywords.Add(word); + } + } + + public void SetAdditionalValues(List> values) + { + m_AdditionalValues.Clear(); + foreach (var word in values) + { + m_AdditionalValues.Add(word.Item1, word.Item2); + } + } + public DrawObjectsPass(string profilerTag, ShaderTagId[] shaderTagIds, bool opaque, RenderPassEvent evt, RenderQueueRange renderQueueRange, LayerMask layerMask, StencilState stencilState, int stencilReference) { base.profilingSampler = new ProfilingSampler(nameof(DrawObjectsPass)); @@ -68,6 +89,11 @@ public override void Execute(ScriptableRenderContext context, ref RenderingData Vector4 drawObjectPassData = new Vector4(0.0f, 0.0f, 0.0f, (m_IsOpaque) ? 1.0f : 0.0f); cmd.SetGlobalVector(s_DrawObjectPassDataPropID, drawObjectPassData); + foreach (var word in m_AdditionalShaderKeywords) + cmd.EnableShaderKeyword(word); + foreach (var value in m_AdditionalValues) + cmd.SetGlobalInt(value.Key, value.Value); + // scaleBias.x = flipSign // scaleBias.y = scale // scaleBias.z = bias @@ -96,6 +122,11 @@ public override void Execute(ScriptableRenderContext context, ref RenderingData context.DrawRenderers(renderingData.cullResults, ref drawSettings, ref filterSettings, ref m_RenderStateBlock); + foreach (var word in m_AdditionalShaderKeywords) + cmd.DisableShaderKeyword(word); + context.ExecuteCommandBuffer(cmd); + cmd.Clear(); + // Render objects that did not match any shader pass with error shader RenderingUtils.RenderObjectsWithError(context, ref renderingData.cullResults, camera, filterSettings, SortingCriteria.None); } diff --git a/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs b/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs index d19fd025b85..9035710359b 100644 --- a/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs +++ b/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs @@ -9,6 +9,7 @@ using Lightmapping = UnityEngine.Experimental.GlobalIllumination.Lightmapping; using UnityEngine.Experimental.Rendering; using UnityEngine.Profiling; +using UnityEngine.Rendering.Universal.Internal; namespace UnityEngine.Rendering.LWRP { @@ -136,7 +137,7 @@ public static int maxVisibleAdditionalLights // GLES can be selected as platform on Windows (not a mobile platform) but uniform buffer size so we must use a low light count. return (isMobile || SystemInfo.graphicsDeviceType == GraphicsDeviceType.OpenGLCore || SystemInfo.graphicsDeviceType == GraphicsDeviceType.OpenGLES2 || SystemInfo.graphicsDeviceType == GraphicsDeviceType.OpenGLES3) - ? k_MaxVisibleAdditionalLightsMobile : k_MaxVisibleAdditionalLightsNonMobile; + ? k_MaxVisibleAdditionalLightsMobile : k_MaxVisibleAdditionalLightsNonMobile; } } @@ -190,6 +191,113 @@ protected override void Dispose(bool disposing) CameraCaptureBridge.enabled = false; } + protected override void ProcessRenderRequests(ScriptableRenderContext renderContext, Camera camera, List renderRequests) + { + var cameras = new [] {camera}; + BeginFrameRendering(renderContext, cameras); + + GraphicsSettings.lightsUseLinearIntensity = (QualitySettings.activeColorSpace == ColorSpace.Linear); + GraphicsSettings.useScriptableRenderPipelineBatching = asset.useSRPBatcher; + SetupPerFrameShaderConstants(); + + BeginCameraRendering(renderContext, camera); +#if VISUAL_EFFECT_GRAPH_0_0_1_OR_NEWER + //It should be called before culling to prepare material. When there isn't any VisualEffect component, this method has no effect. + VFX.VFXManager.PrepareCamera(camera); +#endif + UpdateVolumeFramework(camera, null); + + + var cameraTarget = camera.targetTexture; + + foreach (var renderRequest in renderRequests) + { + + if (!renderRequest.isValid) + continue; + RenderWithMode(renderContext, camera, renderRequest); + } + + EndCameraRendering(renderContext, camera); + EndFrameRendering(renderContext, cameras); + camera.targetTexture = cameraTarget; + } + + void RenderWithMode(ScriptableRenderContext renderContext, Camera camera, Camera.RenderRequest renderRequest) + { + camera.targetTexture = renderRequest.result; + + UniversalAdditionalCameraData additionalCameraData = null; + if (IsGameCamera(camera)) + camera.gameObject.TryGetComponent(out additionalCameraData); + + if (additionalCameraData != null && additionalCameraData.renderType != CameraRenderType.Base) + { + Debug.LogWarning("Only Base cameras can be rendered with standalone RenderSingleCamera. Camera will be skipped."); + return; + } + + var data = ScriptableObject.CreateInstance(); + data.request = renderRequest; + InitializeCameraData(camera, additionalCameraData, true, out var cameraData); + cameraData.renderer = data.InternalCreateRenderer(); + RenderSingleCamera(renderContext, cameraData, false); + Object.DestroyImmediate(data); + } + + public class RenderRequestRendererData : ScriptableRendererData + { + protected override ScriptableRenderer Create() + { + return new RenderRequestRenderer(this); + } + + public Camera.RenderRequest request { get; set; } + } + + class RenderRequestRenderer : ScriptableRenderer + { + DrawObjectsPass m_RenderOpaqueForwardPass; + DrawObjectsPass m_RenderTransparentForwardPass; + + LayerMask m_OpaqueLayerMask = -1; + LayerMask m_TransparentLayerMask = -1; + StencilState m_DefaultStencilState = StencilState.defaultValue; + + public RenderRequestRenderer(RenderRequestRendererData data) : base(data) + { + var shaderTags = new[] {new ShaderTagId("DataExtraction")}; + m_RenderOpaqueForwardPass = new DrawObjectsPass("Render Opaques", shaderTags, true, RenderPassEvent.BeforeRenderingOpaques, RenderQueueRange.opaque, m_OpaqueLayerMask, m_DefaultStencilState, 0 ); + m_RenderTransparentForwardPass = new DrawObjectsPass("Render Transparents", shaderTags, false, RenderPassEvent.BeforeRenderingTransparents, RenderQueueRange.transparent, m_TransparentLayerMask, m_DefaultStencilState, 0); + + + List> values = new List> + { + new Tuple("UNITY_DataExtraction_Mode", (int)data.request.mode), + new Tuple("UNITY_DataExtraction_Space", (int)data.request.outputSpace), + }; + + m_RenderOpaqueForwardPass.SetAdditionalValues(values); + m_RenderTransparentForwardPass.SetAdditionalValues(values); + } + + + /// + public override void Setup(ScriptableRenderContext context, ref RenderingData renderingData) + { + EnqueuePass(m_RenderOpaqueForwardPass); + EnqueuePass(m_RenderTransparentForwardPass); + } + + public override void FinishRendering(CommandBuffer cmd) + { + base.FinishRendering(cmd); + cmd.SetGlobalInt("UNITY_DataExtraction_Mode", 0); + cmd.SetGlobalInt("UNITY_DataExtraction_Space", 0); + + } + } + #if UNITY_2021_1_OR_NEWER protected override void Render(ScriptableRenderContext renderContext, Camera[] cameras) { diff --git a/com.unity.render-pipelines.universal/ShaderLibrary/DataExtraction.hlsl b/com.unity.render-pipelines.universal/ShaderLibrary/DataExtraction.hlsl new file mode 100644 index 00000000000..c112b255fa9 --- /dev/null +++ b/com.unity.render-pipelines.universal/ShaderLibrary/DataExtraction.hlsl @@ -0,0 +1,91 @@ +#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Debug.hlsl" + +int UNITY_DataExtraction_Mode; +int UNITY_DataExtraction_Space; + +#define RENDER_OBJECT_ID 1 +#define RENDER_DEPTH 2 +#define RENDER_WORLD_NORMALS_FACE_RGB 3 +#define RENDER_WORLD_POSITION_RGB 4 +#define RENDER_ENTITY_ID 5 +#define RENDER_BASE_COLOR_RGBA 6 +#define RENDER_SPECULAR_RGB 7 +#define RENDER_METALLIC_R 8 +#define RENDER_EMISSION_RGB 9 +#define RENDER_WORLD_NORMALS_PIXEL_RGB 10 +#define RENDER_SMOOTHNESS_R 11 +#define RENDER_OCCLUSION_R 12 +#define RENDER_DIFFUSE_COLOR_RGBA 13 +#define RENDER_OUTLINE_MASK 14 + +struct ExtractionInputs +{ + float3 vertexNormalWS; + float3 pixelNormalWS; + float3 positionWS; + + float3 baseColor; + float alpha; + +#ifdef _SPECULAR_SETUP + float3 specular; +#else + float metallic; +#endif + float smoothness; + float occlusion; + float3 emission; +}; + +float4 OutputExtraction(ExtractionInputs inputs) +{ + float3 specular, diffuse, baseColor; + float metallic; + + #ifdef _SPECULAR_SETUP + specular = inputs.specular; + diffuse = inputs.baseColor; + ConvertSpecularToMetallic(inputs.baseColor, inputs.specular, baseColor, metallic); + #else + baseColor = inputs.baseColor; + metallic = inputs.metallic; + ConvertMetallicToSpecular(inputs.baseColor, inputs.metallic, diffuse, specular); + #endif + + if (UNITY_DataExtraction_Mode == RENDER_OBJECT_ID) + return float4(PackIndexToRGB16f(asuint(unity_LODFade.z)), 1.0); + //@TODO + if (UNITY_DataExtraction_Mode == RENDER_DEPTH) + return 0; + if (UNITY_DataExtraction_Mode == RENDER_WORLD_NORMALS_FACE_RGB) + return float4(PackNormalRGB(inputs.vertexNormalWS), 1.0f); + if (UNITY_DataExtraction_Mode == RENDER_WORLD_POSITION_RGB) + return float4(inputs.positionWS, 1.0); +#ifdef UNITY_DOTS_INSTANCING_ENABLED + if (UNITY_DataExtraction_Mode == RENDER_ENTITY_ID) + return float4(PackIndexToRGB16f(unity_EntityId.x), 1.0F); +#else + if (UNITY_DataExtraction_Mode == RENDER_ENTITY_ID) + return 0; +#endif + if (UNITY_DataExtraction_Mode == RENDER_BASE_COLOR_RGBA) + return float4(baseColor, inputs.alpha); + if (UNITY_DataExtraction_Mode == RENDER_SPECULAR_RGB) + return float4(specular.xxx, 1); + if (UNITY_DataExtraction_Mode == RENDER_METALLIC_R) + return float4(metallic.xxx, 1.0); + if (UNITY_DataExtraction_Mode == RENDER_EMISSION_RGB) + return float4(inputs.emission, 1.0); + if (UNITY_DataExtraction_Mode == RENDER_WORLD_NORMALS_PIXEL_RGB) + return float4(PackNormalRGB(inputs.pixelNormalWS), 1.0f); + if (UNITY_DataExtraction_Mode == RENDER_SMOOTHNESS_R) + return float4(inputs.smoothness.xxx, 1.0); + if (UNITY_DataExtraction_Mode == RENDER_OCCLUSION_R) + return float4(inputs.occlusion.xxx, 1.0); + if (UNITY_DataExtraction_Mode == RENDER_DIFFUSE_COLOR_RGBA) + return float4(diffuse, inputs.alpha); + if (UNITY_DataExtraction_Mode == RENDER_OUTLINE_MASK) + return float4(0, 1, 1, 1); + + return 0; +} diff --git a/com.unity.render-pipelines.universal/ShaderLibrary/DataExtraction.hlsl.meta b/com.unity.render-pipelines.universal/ShaderLibrary/DataExtraction.hlsl.meta new file mode 100644 index 00000000000..f828fe827db --- /dev/null +++ b/com.unity.render-pipelines.universal/ShaderLibrary/DataExtraction.hlsl.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 996764835d9cb402689335d7811b93e8 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + preprocessorOverride: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.render-pipelines.universal/ShaderLibrary/UniversalDOTSInstancing.hlsl b/com.unity.render-pipelines.universal/ShaderLibrary/UniversalDOTSInstancing.hlsl index 202173d5b18..34c5755fe23 100644 --- a/com.unity.render-pipelines.universal/ShaderLibrary/UniversalDOTSInstancing.hlsl +++ b/com.unity.render-pipelines.universal/ShaderLibrary/UniversalDOTSInstancing.hlsl @@ -25,6 +25,7 @@ UNITY_DOTS_INSTANCING_START(BuiltinPropertyMetadata) UNITY_DOTS_INSTANCED_PROP(float4, unity_SHBg) UNITY_DOTS_INSTANCED_PROP(float4, unity_SHBb) UNITY_DOTS_INSTANCED_PROP(float4, unity_SHC) + UNITY_DOTS_INSTANCED_PROP(uint2, unity_EntityId) UNITY_DOTS_INSTANCING_END(BuiltinPropertyMetadata) // Note: Macros for unity_ObjectToWorld and unity_WorldToObject are declared in UnityInstancing.hlsl @@ -45,6 +46,7 @@ UNITY_DOTS_INSTANCING_END(BuiltinPropertyMetadata) #define unity_SHBg UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_SHBg) #define unity_SHBb UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_SHBb) #define unity_SHC UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4, Metadata_unity_SHC) +#define unity_EntityId UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(uint2, Metadata_unity_EntityId) #endif #endif diff --git a/com.unity.render-pipelines.universal/Shaders/Lit.shader b/com.unity.render-pipelines.universal/Shaders/Lit.shader index d46635d6aa9..035f2e314ff 100644 --- a/com.unity.render-pipelines.universal/Shaders/Lit.shader +++ b/com.unity.render-pipelines.universal/Shaders/Lit.shader @@ -141,6 +141,7 @@ Shader "Universal Render Pipeline/Lit" ENDHLSL } + Pass { Name "ShadowCaster" @@ -325,6 +326,51 @@ Shader "Universal Render Pipeline/Lit" ENDHLSL } + + Pass + { + Name "Data Extraction" + Tags{"LightMode" = "DataExtraction"} + + Blend[_SrcBlend][_DstBlend] + ZWrite[_ZWrite] + Cull[_Cull] + + HLSLPROGRAM + #pragma exclude_renderers d3d11_9x gles + #pragma target 4.5 + + // ------------------------------------- + // Material Keywords + #pragma shader_feature_local _NORMALMAP + #pragma shader_feature_local_fragment _ALPHATEST_ON + #pragma shader_feature_local_fragment _ALPHAPREMULTIPLY_ON + #pragma shader_feature_local_fragment _EMISSION + #pragma shader_feature_local_fragment _METALLICSPECGLOSSMAP + #pragma shader_feature_local_fragment _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A + #pragma shader_feature_local_fragment _OCCLUSIONMAP + + #pragma shader_feature_local_fragment _ _CLEARCOAT _CLEARCOATMAP + + #pragma shader_feature_local_fragment _SPECULARHIGHLIGHTS_OFF + #pragma shader_feature_local_fragment _ENVIRONMENTREFLECTIONS_OFF + #pragma shader_feature_local_fragment _SPECULAR_SETUP + #pragma shader_feature_local _RECEIVE_SHADOWS_OFF + + //-------------------------------------- + // GPU Instancing + #pragma multi_compile_instancing + #pragma multi_compile _ DOTS_INSTANCING_ON + + #pragma vertex ExtractionVertex + #pragma fragment ExtractionFragment + + #include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl" + #include "Packages/com.unity.render-pipelines.universal/Shaders/LitExtractionPass.hlsl" + + ENDHLSL + } + Pass { Name "Universal2D" diff --git a/com.unity.render-pipelines.universal/Shaders/LitExtractionPass.hlsl b/com.unity.render-pipelines.universal/Shaders/LitExtractionPass.hlsl new file mode 100644 index 00000000000..81eca962835 --- /dev/null +++ b/com.unity.render-pipelines.universal/Shaders/LitExtractionPass.hlsl @@ -0,0 +1,127 @@ +#ifndef UNIVERSAL_LIT_EXTRACTION_PASS_INCLUDED +#define UNIVERSAL_LIT_EXTRACTION_PASS_INCLUDED + +#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" +#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DataExtraction.hlsl" + +struct Attributes +{ + float4 positionOS : POSITION; + float3 normalOS : NORMAL; + float4 tangentOS : TANGENT; + float2 texcoord : TEXCOORD0; + float2 uv1 : TEXCOORD1; + float2 uv2 : TEXCOORD2; + float2 uv3 : TEXCOORD3; + float2 uv4 : TEXCOORD4; + float2 uv5 : TEXCOORD5; + float2 uv6 : TEXCOORD6; + float2 uv7 : TEXCOORD7; + + UNITY_VERTEX_INPUT_INSTANCE_ID +}; + +struct Varyings +{ + float2 uv : TEXCOORD0; + float3 positionWS : TEXCOORD1; + float3 normalWS : TEXCOORD3; + float4 tangentWS : TEXCOORD4; // xyz: tangent, w: sign + float4 positionCS : SV_POSITION; + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO +}; + +void InitializeInputData(Varyings input, half3 normalTS, out InputData inputData) +{ + inputData = (InputData)0; + + inputData.positionWS = input.positionWS; + +#ifdef _NORMALMAP + float sgn = input.tangentWS.w; // should be either +1 or -1 + float3 bitangent = sgn * cross(input.normalWS.xyz, input.tangentWS.xyz); + inputData.normalWS = TransformTangentToWorld(normalTS, half3x3(input.tangentWS.xyz, bitangent.xyz, input.normalWS.xyz)); +#else + inputData.normalWS = input.normalWS; +#endif + + inputData.normalWS = NormalizeNormalPerPixel(inputData.normalWS); + inputData.normalizedScreenSpaceUV = input.positionCS.xy; +} + +Varyings ExtractionVertex(Attributes input) +{ + Varyings output = (Varyings)0; + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz); + + // normalWS and tangentWS already normalize. + // this is required to avoid skewing the direction during interpolation + // also required for per-vertex lighting and SH evaluation + VertexNormalInputs normalInput = GetVertexNormalInputs(input.normalOS, input.tangentOS); + + output.uv = TRANSFORM_TEX(input.texcoord, _BaseMap); + + // already normalized from normal transform to WS. + output.normalWS = normalInput.normalWS; + real sign = input.tangentOS.w * GetOddNegativeScale(); + output.tangentWS = half4(normalInput.tangentWS.xyz, sign); + + output.positionWS = vertexInput.positionWS; + output.positionCS = vertexInput.positionCS; + + if (UNITY_DataExtraction_Space == 0) + output.positionCS = float4(input.texcoord, 0.0F, 1.0f); + else if (UNITY_DataExtraction_Space == 1) + output.positionCS = float4(input.uv1.xy, 0.0F, 1.0f); + else if (UNITY_DataExtraction_Space == 2) + output.positionCS = float4(input.uv2, 0.0F, 1.0f); + else if (UNITY_DataExtraction_Space == 3) + output.positionCS = float4(input.uv3, 0.0F, 1.0f); + else if (UNITY_DataExtraction_Space == 4) + output.positionCS = float4(input.uv4, 0.0F, 1.0f); + else if (UNITY_DataExtraction_Space == 5) + output.positionCS = float4(input.uv5, 0.0F, 1.0f); + else if (UNITY_DataExtraction_Space == 6) + output.positionCS = float4(input.uv6, 0.0F, 1.0f); + else if (UNITY_DataExtraction_Space == 7) + output.positionCS = float4(input.uv7, 0.0F, 1.0f); + + return output; +} + +float4 ExtractionFragment(Varyings input) : SV_Target +{ + UNITY_SETUP_INSTANCE_ID(input); + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input); + + SurfaceData surfaceData; + InitializeStandardLitSurfaceData(input.uv, surfaceData); + + InputData inputData; + InitializeInputData(input, surfaceData.normalTS, inputData); + + ExtractionInputs extraction; + extraction.vertexNormalWS = input.normalWS; + extraction.pixelNormalWS = inputData.normalWS; + extraction.positionWS = inputData.positionWS; + extraction.baseColor = surfaceData.albedo; + extraction.alpha = OutputAlpha(UniversalFragmentPBR(inputData, surfaceData).a); + #ifdef _SPECULAR_SETUP + extraction.specular = surfaceData.specular; + #else + extraction.metallic = surfaceData.metallic; + #endif + extraction.smoothness = surfaceData.smoothness; + extraction.occlusion = surfaceData.occlusion; + extraction.emission = surfaceData.emission; + + return OutputExtraction(extraction); +} + +#endif diff --git a/com.unity.render-pipelines.universal/Shaders/LitExtractionPass.hlsl.meta b/com.unity.render-pipelines.universal/Shaders/LitExtractionPass.hlsl.meta new file mode 100644 index 00000000000..c3553f11953 --- /dev/null +++ b/com.unity.render-pipelines.universal/Shaders/LitExtractionPass.hlsl.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 22ccac106383e4c4f823f473865d5971 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + preprocessorOverride: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.render-pipelines.universal/Shaders/LitForwardPass.hlsl b/com.unity.render-pipelines.universal/Shaders/LitForwardPass.hlsl index 02f97fc041d..af1ffea5df3 100644 --- a/com.unity.render-pipelines.universal/Shaders/LitForwardPass.hlsl +++ b/com.unity.render-pipelines.universal/Shaders/LitForwardPass.hlsl @@ -149,6 +149,7 @@ Varyings LitPassVertex(Attributes input) return output; } + // Used in Standard (Physically Based) shader half4 LitPassFragment(Varyings input) : SV_Target { @@ -171,11 +172,11 @@ half4 LitPassFragment(Varyings input) : SV_Target InitializeInputData(input, surfaceData.normalTS, inputData); half4 color = UniversalFragmentPBR(inputData, surfaceData); - color.rgb = MixFog(color.rgb, inputData.fogCoord); color.a = OutputAlpha(color.a, _Surface); return color; } + #endif diff --git a/com.unity.shadergraph/Editor/Data/Util/KeywordUtil.cs b/com.unity.shadergraph/Editor/Data/Util/KeywordUtil.cs index 4cd748d2c63..6c529e74953 100644 --- a/com.unity.shadergraph/Editor/Data/Util/KeywordUtil.cs +++ b/com.unity.shadergraph/Editor/Data/Util/KeywordUtil.cs @@ -79,6 +79,10 @@ public static string ToDeclarationString(this KeywordDescriptor keyword) var enumEntryDefinitions = keyword.entries.Select(x => $"{keyword.referenceName}_{x.referenceName}"); string enumEntriesString = string.Join(" ", enumEntryDefinitions); return $"#pragma {definitionString} {enumEntriesString}"; + case KeywordType.MultiCompile: + var multiCompileEntryDefinitions = keyword.entries.Select(x => $"{x.referenceName}"); + string multiCompileEntriesString = string.Join(" ", multiCompileEntryDefinitions); + return $"#pragma {definitionString} {multiCompileEntriesString}"; default: throw new ArgumentOutOfRangeException(); } diff --git a/com.unity.shadergraph/Editor/Generation/Enumerations/KeywordType.cs b/com.unity.shadergraph/Editor/Generation/Enumerations/KeywordType.cs index 1a896f570da..36951a4835d 100644 --- a/com.unity.shadergraph/Editor/Generation/Enumerations/KeywordType.cs +++ b/com.unity.shadergraph/Editor/Generation/Enumerations/KeywordType.cs @@ -4,6 +4,7 @@ internal enum KeywordType { Boolean, - Enum + Enum, + MultiCompile } } From 24868e9178602c6aeb6ad495feecf50857711ed7 Mon Sep 17 00:00:00 2001 From: Jussi Knuuttila Date: Mon, 8 Feb 2021 18:58:40 +0200 Subject: [PATCH 02/30] Disable Gizmos and Wireframe overlay during RenderRequests --- .../Runtime/ScriptableRenderer.cs | 10 +++++++--- .../Runtime/UniversalRenderPipeline.cs | 1 + .../Runtime/UniversalRenderPipelineCore.cs | 1 + 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/com.unity.render-pipelines.universal/Runtime/ScriptableRenderer.cs b/com.unity.render-pipelines.universal/Runtime/ScriptableRenderer.cs index bf0034fe031..6dc7b8d510c 100644 --- a/com.unity.render-pipelines.universal/Runtime/ScriptableRenderer.cs +++ b/com.unity.render-pipelines.universal/Runtime/ScriptableRenderer.cs @@ -557,7 +557,8 @@ public void Execute(ScriptableRenderContext context, ref RenderingData rendering } // Draw Gizmos... - DrawGizmos(context, camera, GizmoSubset.PreImageEffects); + if (!cameraData.isRenderRequest) + DrawGizmos(context, camera, GizmoSubset.PreImageEffects); // In this block after rendering drawing happens, e.g, post processing, video player capture. if (renderBlocks.GetLength(RenderPassBlock.AfterRendering) > 0) @@ -568,8 +569,11 @@ public void Execute(ScriptableRenderContext context, ref RenderingData rendering EndXRRendering(cmd, context, ref renderingData.cameraData); - DrawWireOverlay(context, camera); - DrawGizmos(context, camera, GizmoSubset.PostImageEffects); + if (!cameraData.isRenderRequest) + { + DrawWireOverlay(context, camera); + DrawGizmos(context, camera, GizmoSubset.PostImageEffects); + } InternalFinishRendering(context, cameraData.resolveFinalTarget); } diff --git a/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs b/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs index 9035710359b..512082d7553 100644 --- a/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs +++ b/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs @@ -240,6 +240,7 @@ void RenderWithMode(ScriptableRenderContext renderContext, Camera camera, Camera var data = ScriptableObject.CreateInstance(); data.request = renderRequest; InitializeCameraData(camera, additionalCameraData, true, out var cameraData); + cameraData.isRenderRequest = true; cameraData.renderer = data.InternalCreateRenderer(); RenderSingleCamera(renderContext, cameraData, false); Object.DestroyImmediate(data); diff --git a/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipelineCore.cs b/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipelineCore.cs index 0b772842cb9..cedfdbe5c66 100644 --- a/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipelineCore.cs +++ b/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipelineCore.cs @@ -108,6 +108,7 @@ public Matrix4x4 GetGPUProjectionMatrix(int viewIndex = 0) public bool isHdrEnabled; public bool requiresDepthTexture; public bool requiresOpaqueTexture; + public bool isRenderRequest; #if ENABLE_VR && ENABLE_XR_MODULE public bool xrRendering; #endif From 1b08eddbfdc63fee879327e6ed1a3b62e1735413 Mon Sep 17 00:00:00 2001 From: Jussi Knuuttila Date: Tue, 9 Feb 2021 13:23:26 +0200 Subject: [PATCH 03/30] Z-fail passes for selection outline --- .../Runtime/Passes/DrawObjectsPass.cs | 5 ++ .../Runtime/UniversalRenderPipeline.cs | 84 +++++++++++++++++-- .../ShaderLibrary/DataExtraction.hlsl | 3 +- 3 files changed, 85 insertions(+), 7 deletions(-) diff --git a/com.unity.render-pipelines.universal/Runtime/Passes/DrawObjectsPass.cs b/com.unity.render-pipelines.universal/Runtime/Passes/DrawObjectsPass.cs index 4b1ec3491f2..813f2736338 100644 --- a/com.unity.render-pipelines.universal/Runtime/Passes/DrawObjectsPass.cs +++ b/com.unity.render-pipelines.universal/Runtime/Passes/DrawObjectsPass.cs @@ -24,6 +24,11 @@ public class DrawObjectsPass : ScriptableRenderPass static readonly int s_DrawObjectPassDataPropID = Shader.PropertyToID("_DrawObjectPassData"); + public RenderStateBlock RenderStateBlock + { + get => m_RenderStateBlock; + set => m_RenderStateBlock = value; + } public void SetAdditionalKeywords(IEnumerable words) { m_AdditionalShaderKeywords.Clear(); diff --git a/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs b/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs index 512082d7553..fab7b830bfe 100644 --- a/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs +++ b/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs @@ -260,34 +260,103 @@ class RenderRequestRenderer : ScriptableRenderer { DrawObjectsPass m_RenderOpaqueForwardPass; DrawObjectsPass m_RenderTransparentForwardPass; + DrawObjectsPass m_RenderOpaqueForwardPassZFail; + DrawObjectsPass m_RenderTransparentForwardPassZFail; LayerMask m_OpaqueLayerMask = -1; LayerMask m_TransparentLayerMask = -1; StencilState m_DefaultStencilState = StencilState.defaultValue; - + Camera.RenderRequestMode m_Mode; + public RenderRequestRenderer(RenderRequestRendererData data) : base(data) { + m_Mode = data.request.mode; + var shaderTags = new[] {new ShaderTagId("DataExtraction")}; + + // TODO: Outline mask requires a Z-bias? + m_RenderOpaqueForwardPass = new DrawObjectsPass("Render Opaques", shaderTags, true, RenderPassEvent.BeforeRenderingOpaques, RenderQueueRange.opaque, m_OpaqueLayerMask, m_DefaultStencilState, 0 ); m_RenderTransparentForwardPass = new DrawObjectsPass("Render Transparents", shaderTags, false, RenderPassEvent.BeforeRenderingTransparents, RenderQueueRange.transparent, m_TransparentLayerMask, m_DefaultStencilState, 0); - + // Selection mask requires separate passes for occluded objects + if (IsSelectionMaskRequest) + { + m_RenderOpaqueForwardPassZFail = new DrawObjectsPass("Render Opaques (Z-fail)", shaderTags, true, RenderPassEvent.BeforeRenderingOpaques, RenderQueueRange.opaque, m_OpaqueLayerMask, m_DefaultStencilState, 0 ); + m_RenderTransparentForwardPassZFail = new DrawObjectsPass("Render Transparents (Z-fail)", shaderTags, false, RenderPassEvent.BeforeRenderingTransparents, RenderQueueRange.transparent, m_TransparentLayerMask, m_DefaultStencilState, 0); + + var state = m_RenderOpaqueForwardPassZFail.RenderStateBlock; + var depthState = state.depthState; + depthState.compareFunction = FlipCompareFunction(depthState.compareFunction); + depthState.writeEnabled = false; + state.depthState = depthState; + state.mask = RenderStateMask.Depth; + m_RenderOpaqueForwardPassZFail.RenderStateBlock = state; + m_RenderTransparentForwardPassZFail.RenderStateBlock = state; + } + List> values = new List> { new Tuple("UNITY_DataExtraction_Mode", (int)data.request.mode), new Tuple("UNITY_DataExtraction_Space", (int)data.request.outputSpace), + new Tuple("UNITY_DataExtraction_Value", 255), }; - + m_RenderOpaqueForwardPass.SetAdditionalValues(values); m_RenderTransparentForwardPass.SetAdditionalValues(values); + + if (IsSelectionMaskRequest) + { + // Occluded selection mask rendered with 50% value + List> valuesZFail = new List> + { + new Tuple("UNITY_DataExtraction_Mode", (int)data.request.mode), + new Tuple("UNITY_DataExtraction_Space", (int)data.request.outputSpace), + new Tuple("UNITY_DataExtraction_Value", 128), + }; + + m_RenderOpaqueForwardPassZFail.SetAdditionalValues(valuesZFail); + m_RenderTransparentForwardPassZFail.SetAdditionalValues(valuesZFail); + } } - - + + private CompareFunction FlipCompareFunction(CompareFunction depthStateCompareFunction) + { + switch (depthStateCompareFunction) + { + case CompareFunction.Disabled: + default: + return CompareFunction.Disabled; + case CompareFunction.Never: + return CompareFunction.Always; + case CompareFunction.Less: + return CompareFunction.GreaterEqual; + case CompareFunction.Equal: + return CompareFunction.NotEqual; + case CompareFunction.LessEqual: + return CompareFunction.Greater; + case CompareFunction.Greater: + return CompareFunction.LessEqual; + case CompareFunction.NotEqual: + return CompareFunction.Equal; + case CompareFunction.GreaterEqual: + return CompareFunction.Less; + case CompareFunction.Always: + return CompareFunction.Never; + } + } + /// public override void Setup(ScriptableRenderContext context, ref RenderingData renderingData) { EnqueuePass(m_RenderOpaqueForwardPass); EnqueuePass(m_RenderTransparentForwardPass); + + if (IsSelectionMaskRequest) + { + EnqueuePass(m_RenderOpaqueForwardPassZFail); + EnqueuePass(m_RenderTransparentForwardPassZFail); + } } public override void FinishRendering(CommandBuffer cmd) @@ -295,8 +364,11 @@ public override void FinishRendering(CommandBuffer cmd) base.FinishRendering(cmd); cmd.SetGlobalInt("UNITY_DataExtraction_Mode", 0); cmd.SetGlobalInt("UNITY_DataExtraction_Space", 0); - + cmd.SetGlobalInt("UNITY_DataExtraction_Value", 0); + } + + public bool IsSelectionMaskRequest => m_Mode == Camera.RenderRequestMode.SelectionMask; } #if UNITY_2021_1_OR_NEWER diff --git a/com.unity.render-pipelines.universal/ShaderLibrary/DataExtraction.hlsl b/com.unity.render-pipelines.universal/ShaderLibrary/DataExtraction.hlsl index c112b255fa9..3a9c28423cf 100644 --- a/com.unity.render-pipelines.universal/ShaderLibrary/DataExtraction.hlsl +++ b/com.unity.render-pipelines.universal/ShaderLibrary/DataExtraction.hlsl @@ -2,6 +2,7 @@ int UNITY_DataExtraction_Mode; int UNITY_DataExtraction_Space; +int UNITY_DataExtraction_Value; #define RENDER_OBJECT_ID 1 #define RENDER_DEPTH 2 @@ -85,7 +86,7 @@ float4 OutputExtraction(ExtractionInputs inputs) if (UNITY_DataExtraction_Mode == RENDER_DIFFUSE_COLOR_RGBA) return float4(diffuse, inputs.alpha); if (UNITY_DataExtraction_Mode == RENDER_OUTLINE_MASK) - return float4(0, 1, 1, 1); + return float4(0, (float)UNITY_DataExtraction_Value / 255.0, 1, 1); return 0; } From 4e23729866103610b1d733cfa2383effa6a6dacf Mon Sep 17 00:00:00 2001 From: Jussi Knuuttila Date: Tue, 9 Feb 2021 14:10:08 +0200 Subject: [PATCH 04/30] Selection outline rendering should now more closely match the old C++ code. --- .../Runtime/UniversalRenderPipeline.cs | 73 +++++++------------ 1 file changed, 25 insertions(+), 48 deletions(-) diff --git a/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs b/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs index fab7b830bfe..09e4163b648 100644 --- a/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs +++ b/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs @@ -260,8 +260,8 @@ class RenderRequestRenderer : ScriptableRenderer { DrawObjectsPass m_RenderOpaqueForwardPass; DrawObjectsPass m_RenderTransparentForwardPass; - DrawObjectsPass m_RenderOpaqueForwardPassZFail; - DrawObjectsPass m_RenderTransparentForwardPassZFail; + DrawObjectsPass m_RenderOpaqueForwardPassZDisabled; + DrawObjectsPass m_RenderTransparentForwardPassZDisabled; LayerMask m_OpaqueLayerMask = -1; LayerMask m_TransparentLayerMask = -1; @@ -274,25 +274,29 @@ public RenderRequestRenderer(RenderRequestRendererData data) : base(data) var shaderTags = new[] {new ShaderTagId("DataExtraction")}; - // TODO: Outline mask requires a Z-bias? - m_RenderOpaqueForwardPass = new DrawObjectsPass("Render Opaques", shaderTags, true, RenderPassEvent.BeforeRenderingOpaques, RenderQueueRange.opaque, m_OpaqueLayerMask, m_DefaultStencilState, 0 ); m_RenderTransparentForwardPass = new DrawObjectsPass("Render Transparents", shaderTags, false, RenderPassEvent.BeforeRenderingTransparents, RenderQueueRange.transparent, m_TransparentLayerMask, m_DefaultStencilState, 0); // Selection mask requires separate passes for occluded objects if (IsSelectionMaskRequest) { - m_RenderOpaqueForwardPassZFail = new DrawObjectsPass("Render Opaques (Z-fail)", shaderTags, true, RenderPassEvent.BeforeRenderingOpaques, RenderQueueRange.opaque, m_OpaqueLayerMask, m_DefaultStencilState, 0 ); - m_RenderTransparentForwardPassZFail = new DrawObjectsPass("Render Transparents (Z-fail)", shaderTags, false, RenderPassEvent.BeforeRenderingTransparents, RenderQueueRange.transparent, m_TransparentLayerMask, m_DefaultStencilState, 0); - - var state = m_RenderOpaqueForwardPassZFail.RenderStateBlock; - var depthState = state.depthState; - depthState.compareFunction = FlipCompareFunction(depthState.compareFunction); - depthState.writeEnabled = false; - state.depthState = depthState; - state.mask = RenderStateMask.Depth; - m_RenderOpaqueForwardPassZFail.RenderStateBlock = state; - m_RenderTransparentForwardPassZFail.RenderStateBlock = state; + m_RenderOpaqueForwardPassZDisabled = new DrawObjectsPass("Render Opaques (Occluded)", shaderTags, true, RenderPassEvent.BeforeRenderingOpaques, RenderQueueRange.opaque, m_OpaqueLayerMask, m_DefaultStencilState, 0 ); + m_RenderTransparentForwardPassZDisabled = new DrawObjectsPass("Render Transparents (Occluded)", shaderTags, false, RenderPassEvent.BeforeRenderingTransparents, RenderQueueRange.transparent, m_TransparentLayerMask, m_DefaultStencilState, 0); + + var state = m_RenderOpaqueForwardPassZDisabled.RenderStateBlock; + state.rasterState = new RasterState(CullMode.Off, 0, -0.02f); + state.blendState = new BlendState + { + blendState0 = new RenderTargetBlendState( + ColorWriteMask.Blue | ColorWriteMask.Green, + sourceColorBlendMode: BlendMode.One, + destinationColorBlendMode: BlendMode.One, + colorBlendOperation: BlendOp.Max), + }; + state.depthState = new DepthState {compareFunction = CompareFunction.Always, writeEnabled = false}; + state.mask = RenderStateMask.Everything; + m_RenderOpaqueForwardPassZDisabled.RenderStateBlock = state; + m_RenderTransparentForwardPassZDisabled.RenderStateBlock = state; } List> values = new List> @@ -307,42 +311,15 @@ public RenderRequestRenderer(RenderRequestRendererData data) : base(data) if (IsSelectionMaskRequest) { - // Occluded selection mask rendered with 50% value - List> valuesZFail = new List> + List> valuesZDisabled = new List> { new Tuple("UNITY_DataExtraction_Mode", (int)data.request.mode), new Tuple("UNITY_DataExtraction_Space", (int)data.request.outputSpace), - new Tuple("UNITY_DataExtraction_Value", 128), + new Tuple("UNITY_DataExtraction_Value", 0), }; - m_RenderOpaqueForwardPassZFail.SetAdditionalValues(valuesZFail); - m_RenderTransparentForwardPassZFail.SetAdditionalValues(valuesZFail); - } - } - - private CompareFunction FlipCompareFunction(CompareFunction depthStateCompareFunction) - { - switch (depthStateCompareFunction) - { - case CompareFunction.Disabled: - default: - return CompareFunction.Disabled; - case CompareFunction.Never: - return CompareFunction.Always; - case CompareFunction.Less: - return CompareFunction.GreaterEqual; - case CompareFunction.Equal: - return CompareFunction.NotEqual; - case CompareFunction.LessEqual: - return CompareFunction.Greater; - case CompareFunction.Greater: - return CompareFunction.LessEqual; - case CompareFunction.NotEqual: - return CompareFunction.Equal; - case CompareFunction.GreaterEqual: - return CompareFunction.Less; - case CompareFunction.Always: - return CompareFunction.Never; + m_RenderOpaqueForwardPassZDisabled.SetAdditionalValues(valuesZDisabled); + m_RenderTransparentForwardPassZDisabled.SetAdditionalValues(valuesZDisabled); } } @@ -354,8 +331,8 @@ public override void Setup(ScriptableRenderContext context, ref RenderingData re if (IsSelectionMaskRequest) { - EnqueuePass(m_RenderOpaqueForwardPassZFail); - EnqueuePass(m_RenderTransparentForwardPassZFail); + EnqueuePass(m_RenderOpaqueForwardPassZDisabled); + EnqueuePass(m_RenderTransparentForwardPassZDisabled); } } From d080abea2a99eacdc8cb7c9a24b4cd8fdc241533 Mon Sep 17 00:00:00 2001 From: Jussi Knuuttila Date: Wed, 10 Feb 2021 14:07:54 +0200 Subject: [PATCH 05/30] One-pass implementation for occlusion support in outline mask. --- .../Runtime/UniversalRenderPipeline.cs | 27 ++++++++----------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs b/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs index 09e4163b648..7cd0f110b18 100644 --- a/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs +++ b/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs @@ -280,21 +280,13 @@ public RenderRequestRenderer(RenderRequestRendererData data) : base(data) // Selection mask requires separate passes for occluded objects if (IsSelectionMaskRequest) { - m_RenderOpaqueForwardPassZDisabled = new DrawObjectsPass("Render Opaques (Occluded)", shaderTags, true, RenderPassEvent.BeforeRenderingOpaques, RenderQueueRange.opaque, m_OpaqueLayerMask, m_DefaultStencilState, 0 ); - m_RenderTransparentForwardPassZDisabled = new DrawObjectsPass("Render Transparents (Occluded)", shaderTags, false, RenderPassEvent.BeforeRenderingTransparents, RenderQueueRange.transparent, m_TransparentLayerMask, m_DefaultStencilState, 0); + m_RenderOpaqueForwardPassZDisabled = new DrawObjectsPass("Render Opaques (Z disabled)", shaderTags, true, RenderPassEvent.BeforeRenderingOpaques, RenderQueueRange.opaque, m_OpaqueLayerMask, m_DefaultStencilState, 0 ); + m_RenderTransparentForwardPassZDisabled = new DrawObjectsPass("Render Transparents (Z disabled)", shaderTags, false, RenderPassEvent.BeforeRenderingTransparents, RenderQueueRange.transparent, m_TransparentLayerMask, m_DefaultStencilState, 0); var state = m_RenderOpaqueForwardPassZDisabled.RenderStateBlock; - state.rasterState = new RasterState(CullMode.Off, 0, -0.02f); - state.blendState = new BlendState - { - blendState0 = new RenderTargetBlendState( - ColorWriteMask.Blue | ColorWriteMask.Green, - sourceColorBlendMode: BlendMode.One, - destinationColorBlendMode: BlendMode.One, - colorBlendOperation: BlendOp.Max), - }; + state.rasterState = new RasterState(CullMode.Back, 0, -0.02f); state.depthState = new DepthState {compareFunction = CompareFunction.Always, writeEnabled = false}; - state.mask = RenderStateMask.Everything; + state.mask = RenderStateMask.Raster | RenderStateMask.Depth; m_RenderOpaqueForwardPassZDisabled.RenderStateBlock = state; m_RenderTransparentForwardPassZDisabled.RenderStateBlock = state; } @@ -303,7 +295,7 @@ public RenderRequestRenderer(RenderRequestRendererData data) : base(data) { new Tuple("UNITY_DataExtraction_Mode", (int)data.request.mode), new Tuple("UNITY_DataExtraction_Space", (int)data.request.outputSpace), - new Tuple("UNITY_DataExtraction_Value", 255), + new Tuple("UNITY_DataExtraction_Value", 0), }; m_RenderOpaqueForwardPass.SetAdditionalValues(values); @@ -315,6 +307,7 @@ public RenderRequestRenderer(RenderRequestRendererData data) : base(data) { new Tuple("UNITY_DataExtraction_Mode", (int)data.request.mode), new Tuple("UNITY_DataExtraction_Space", (int)data.request.outputSpace), + // TODO: Unique object identifier here? new Tuple("UNITY_DataExtraction_Value", 0), }; @@ -326,14 +319,16 @@ public RenderRequestRenderer(RenderRequestRendererData data) : base(data) /// public override void Setup(ScriptableRenderContext context, ref RenderingData renderingData) { - EnqueuePass(m_RenderOpaqueForwardPass); - EnqueuePass(m_RenderTransparentForwardPass); - if (IsSelectionMaskRequest) { EnqueuePass(m_RenderOpaqueForwardPassZDisabled); EnqueuePass(m_RenderTransparentForwardPassZDisabled); } + else + { + EnqueuePass(m_RenderOpaqueForwardPass); + EnqueuePass(m_RenderTransparentForwardPass); + } } public override void FinishRendering(CommandBuffer cmd) From 52642327f6d7a9dd1bbcb44771975139964e62e4 Mon Sep 17 00:00:00 2001 From: Jussi Knuuttila Date: Wed, 10 Feb 2021 14:08:44 +0200 Subject: [PATCH 06/30] One-pass occlusion support for selection outline, shader code. --- .../ShaderLibrary/DataExtraction.hlsl | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.universal/ShaderLibrary/DataExtraction.hlsl b/com.unity.render-pipelines.universal/ShaderLibrary/DataExtraction.hlsl index 3a9c28423cf..57e729165ab 100644 --- a/com.unity.render-pipelines.universal/ShaderLibrary/DataExtraction.hlsl +++ b/com.unity.render-pipelines.universal/ShaderLibrary/DataExtraction.hlsl @@ -3,6 +3,7 @@ int UNITY_DataExtraction_Mode; int UNITY_DataExtraction_Space; int UNITY_DataExtraction_Value; +TEXTURE2D(unity_EditorViz_DepthBuffer); SAMPLER(sampler_unity_EditorViz_DepthBuffer); #define RENDER_OBJECT_ID 1 #define RENDER_DEPTH 2 @@ -86,7 +87,24 @@ float4 OutputExtraction(ExtractionInputs inputs) if (UNITY_DataExtraction_Mode == RENDER_DIFFUSE_COLOR_RGBA) return float4(diffuse, inputs.alpha); if (UNITY_DataExtraction_Mode == RENDER_OUTLINE_MASK) - return float4(0, (float)UNITY_DataExtraction_Value / 255.0, 1, 1); + { + float3 ndcZ = ComputeNormalizedDeviceCoordinatesWithZ(inputs.positionWS, UNITY_MATRIX_VP); + float sceneZ = SAMPLE_TEXTURE2D(unity_EditorViz_DepthBuffer, sampler_unity_EditorViz_DepthBuffer, ndcZ.xy).r; + // Use a small multiplicative Z bias to make it less likely for objects to self occlude in the outline buffer + static const float zBias = 0.02; +#if UNITY_REVERSED_Z + float pixelZ = ndcZ.z * (1 + zBias); + bool occluded = pixelZ < sceneZ; +#else + float pixelZ = ndcZ.z * (1 - zBias); + bool occluded = pixelZ > sceneZ; +#endif + // Red channel = unique identifier, can be used to separate groups of objects from each other + // to get outlines between them. + // Green channel = occluded behind depth buffer (0) or not occluded (1) + // Blue channel = always 1 = not cleared to zero = there's an outlined object at this pixel + return float4((float)UNITY_DataExtraction_Value / 255.0, occluded ? 0 : 1, 1, 1); + } return 0; } From 3465bd174c44f11803f9ed4ab0936fefeabc7d33 Mon Sep 17 00:00:00 2001 From: Jussi Knuuttila Date: Wed, 10 Feb 2021 18:04:49 +0200 Subject: [PATCH 07/30] Fix parts of HDRP Outline rendering --- .../Runtime/RenderPipeline/HDRenderPipeline.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs index 804164e7020..070e45ad5fa 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs @@ -3177,7 +3177,7 @@ protected override void ProcessRenderRequests(ScriptableRenderContext renderCont { if (renderRequests.Count == 1 && renderRequests[0].isValid && - renderRequests[0].mode == Camera.RenderRequestMode.OutlineMask) + renderRequests[0].mode == Camera.RenderRequestMode.SelectionMask) { var additionalCameraData = camera.GetComponent(); if (additionalCameraData == null) @@ -3245,12 +3245,11 @@ protected override void ProcessRenderRequests(ScriptableRenderContext renderCont RenderTexture m_OutlineMaskTarget; void RenderOutlineMask(ScriptableRenderContext context, HDCamera hdCamera) { - Debug.Log("RenderOutlineMask"); var cmd = CommandBufferPool.Get(""); // TODO: Need depth target. cmd.SetRenderTarget(m_OutlineMaskTarget); - cmd.ClearRenderTarget(true, true, Color.black); + //cmd.ClearRenderTarget(true, true, Color.black); var camera = hdCamera.camera; camera.TryGetCullingParameters(out var cullingParameters); From 590c36a4d0e1e8e6a8db98fd26ff5aa1a7847dd7 Mon Sep 17 00:00:00 2001 From: Jussi Knuuttila Date: Wed, 10 Feb 2021 19:05:31 +0200 Subject: [PATCH 08/30] Switched ObjectId and EntityId DataExtraction to use RGBA8888 to be compatible with gizmo picking. --- .../ShaderLibrary/Debug.hlsl | 13 +++++++++++++ .../ShaderLibrary/DataExtraction.hlsl | 11 +++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/com.unity.render-pipelines.core/ShaderLibrary/Debug.hlsl b/com.unity.render-pipelines.core/ShaderLibrary/Debug.hlsl index 9abd44ca422..3d71f9a24a9 100644 --- a/com.unity.render-pipelines.core/ShaderLibrary/Debug.hlsl +++ b/com.unity.render-pipelines.core/ShaderLibrary/Debug.hlsl @@ -289,4 +289,17 @@ float3 PackIndexToRGB16f(uint entityId) return float3(f0, f1, f2); } +float4 PackId32ToRGBA8888(uint id32) +{ + uint b0 = (id32 >> 0) & 0xff; + uint b1 = (id32 >> 8) & 0xff; + uint b2 = (id32 >> 16) & 0xff; + uint b3 = (id32 >> 24) & 0xff; + float f0 = (float)b0 / 255.0f; + float f1 = (float)b1 / 255.0f; + float f2 = (float)b2 / 255.0f; + float f3 = (float)b3 / 255.0f; + return float4(f0, f1, f2, f3); +} + #endif // UNITY_DEBUG_INCLUDED diff --git a/com.unity.render-pipelines.universal/ShaderLibrary/DataExtraction.hlsl b/com.unity.render-pipelines.universal/ShaderLibrary/DataExtraction.hlsl index 57e729165ab..70f12012b25 100644 --- a/com.unity.render-pipelines.universal/ShaderLibrary/DataExtraction.hlsl +++ b/com.unity.render-pipelines.universal/ShaderLibrary/DataExtraction.hlsl @@ -54,8 +54,14 @@ float4 OutputExtraction(ExtractionInputs inputs) ConvertMetallicToSpecular(inputs.baseColor, inputs.metallic, diffuse, specular); #endif +#ifdef UNITY_DOTS_INSTANCING_ENABLED + // Entities always have zero ObjectId + if (UNITY_DataExtraction_Mode == RENDER_OBJECT_ID) + return 0; +#else if (UNITY_DataExtraction_Mode == RENDER_OBJECT_ID) - return float4(PackIndexToRGB16f(asuint(unity_LODFade.z)), 1.0); + return PackId32ToRGBA8888(asuint(unity_LODFade.z)); +#endif //@TODO if (UNITY_DataExtraction_Mode == RENDER_DEPTH) return 0; @@ -65,8 +71,9 @@ float4 OutputExtraction(ExtractionInputs inputs) return float4(inputs.positionWS, 1.0); #ifdef UNITY_DOTS_INSTANCING_ENABLED if (UNITY_DataExtraction_Mode == RENDER_ENTITY_ID) - return float4(PackIndexToRGB16f(unity_EntityId.x), 1.0F); + return PackId32ToRGBA8888(unity_EntityId.x); #else + // GameObjects always have zero EntityId if (UNITY_DataExtraction_Mode == RENDER_ENTITY_ID) return 0; #endif From 10cd2480e7353f2a42f351cbe0708d8b4f0243ee Mon Sep 17 00:00:00 2001 From: Jussi Knuuttila Date: Thu, 11 Feb 2021 20:38:47 +0200 Subject: [PATCH 09/30] Picking and outline working in HDRP. --- .../ShaderLibrary/Debug.hlsl | 19 +++ .../Runtime/Material/Lit/LitProperties.hlsl | 9 +- .../Material/Unlit/UnlitProperties.hlsl | 10 +- .../Runtime/RenderPipeline/HDProfileId.cs | 2 + .../RenderPipeline/HDRenderPipeline.cs | 119 ++++++++++++------ .../ShaderPass/ShaderPassDepthOnly.hlsl | 19 ++- .../ShaderLibrary/PickingSpaceTransforms.hlsl | 2 +- .../ShaderLibrary/DataExtraction.hlsl | 16 +-- 8 files changed, 138 insertions(+), 58 deletions(-) diff --git a/com.unity.render-pipelines.core/ShaderLibrary/Debug.hlsl b/com.unity.render-pipelines.core/ShaderLibrary/Debug.hlsl index 3d71f9a24a9..c61b2dd3328 100644 --- a/com.unity.render-pipelines.core/ShaderLibrary/Debug.hlsl +++ b/com.unity.render-pipelines.core/ShaderLibrary/Debug.hlsl @@ -289,6 +289,25 @@ float3 PackIndexToRGB16f(uint entityId) return float3(f0, f1, f2); } +float4 ComputeSelectionMask(float objectGroupId, float3 ndcWithZ, TEXTURE2D_PARAM(depthBuffer, sampler_depthBuffer)) +{ + float sceneZ = SAMPLE_TEXTURE2D(depthBuffer, sampler_depthBuffer, ndcWithZ.xy).r; + // Use a small multiplicative Z bias to make it less likely for objects to self occlude in the outline buffer + static const float zBias = 0.02; +#if UNITY_REVERSED_Z + float pixelZ = ndcWithZ.z * (1 + zBias); + bool occluded = pixelZ < sceneZ; +#else + float pixelZ = ndcWithZ.z * (1 - zBias); + bool occluded = pixelZ > sceneZ; +#endif + // Red channel = unique identifier, can be used to separate groups of objects from each other + // to get outlines between them. + // Green channel = occluded behind depth buffer (0) or not occluded (1) + // Blue channel = always 1 = not cleared to zero = there's an outlined object at this pixel + return float4(objectGroupId, occluded ? 0 : 1, 1, 1); +} + float4 PackId32ToRGBA8888(uint id32) { uint b0 = (id32 >> 0) & 0xff; diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitProperties.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitProperties.hlsl index b5b7aeb9e6b..e7f2394a349 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitProperties.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitProperties.hlsl @@ -291,12 +291,15 @@ float _TessellationObjectScale; float _TessellationTilingScale; #endif -// Following three variables are feeded by the C++ Editor for Scene selection +CBUFFER_END + +// Following variables and textures are fed by the C++ Editor for Scene selection +// These are global on purpose so they don't go in the main constant buffer. int _ObjectId; int _PassValue; float4 _SelectionID; - -CBUFFER_END +TEXTURE2D(unity_EditorViz_DepthBuffer); +SAMPLER(sampler_unity_EditorViz_DepthBuffer); #if defined(UNITY_DOTS_INSTANCING_ENABLED) #if defined(LAYERED_LIT_SHADER) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/UnlitProperties.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/UnlitProperties.hlsl index d259d3ae6df..66ac1c7a075 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/UnlitProperties.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/UnlitProperties.hlsl @@ -37,11 +37,15 @@ float3 _EmissionColor; // By default, the emissive is contributing float _IncludeIndirectLighting; -// Following two variables are feeded by the C++ Editor for Scene selection +CBUFFER_END + +// Following variables and textures are fed by the C++ Editor for Scene selection +// These are global on purpose so they don't go in the main constant buffer. int _ObjectId; int _PassValue; - -CBUFFER_END +float4 _SelectionID; +TEXTURE2D(unity_EditorViz_DepthBuffer); +SAMPLER(sampler_unity_EditorViz_DepthBuffer); #ifdef UNITY_DOTS_INSTANCING_ENABLED diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDProfileId.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDProfileId.cs index 86b5f85d8df..e3b626fc6df 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDProfileId.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDProfileId.cs @@ -239,6 +239,8 @@ internal enum HDProfileId BuildGPULightListProbeVolumes, PushProbeVolumeLightListGlobalParameters, + RenderSceneSelection, + AOVExecute, // Enum AOVBuffers AOVOutput, diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs index 070e45ad5fa..039d39d4091 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs @@ -952,7 +952,7 @@ bool IsSupportedPlatformAndDevice(out GraphicsDeviceType unsupportedGraphicDevic { HDUtils.DisplayMessageNotification("Unable to compile Default Material based on Lit.shader. Either there is a compile error in Lit.shader or the current platform / API isn't compatible."); return false; - } + } #if UNITY_EDITOR UnityEditor.BuildTarget activeBuildTarget = UnityEditor.EditorUserBuildSettings.activeBuildTarget; @@ -3162,6 +3162,19 @@ static void BlitFinalCameraTexture(BlitFinalCameraTextureParameters parameters, HDUtils.DrawFullScreen(cmd, parameters.viewport, parameters.blitMaterial, destination, propertyBlock, 0, parameters.dstTexArraySlice); } + private bool IsSceneSelectionRequest(Camera.RenderRequest renderRequest) + { + switch (renderRequest.mode) + { + case Camera.RenderRequestMode.EntityId: + case Camera.RenderRequestMode.ObjectId: + case Camera.RenderRequestMode.SelectionMask: + return true; + default: + return false; + } + } + protected override void ProcessRenderRequests(ScriptableRenderContext renderContext, Camera camera, List renderRequests) { var previousRT = RenderTexture.active; @@ -3173,12 +3186,16 @@ protected override void ProcessRenderRequests(ScriptableRenderContext renderCont var previousPostprocessBuffer = m_IntermediateAfterPostProcessBuffer; m_IntermediateAfterPostProcessBuffer = m_IntermediateAfterPostProcessBufferFloat; + // Process RenderRequests in two batches. First, process every SceneSelection request, which + // is handled using a special codepath. Then, process every other request, which will go through + // the AOV system. try { - if (renderRequests.Count == 1 && - renderRequests[0].isValid && - renderRequests[0].mode == Camera.RenderRequestMode.SelectionMask) + foreach (var request in renderRequests) { + if (!IsSceneSelectionRequest(request)) + continue; + var additionalCameraData = camera.GetComponent(); if (additionalCameraData == null) { @@ -3186,24 +3203,26 @@ protected override void ProcessRenderRequests(ScriptableRenderContext renderCont additionalCameraData = camera.GetComponent(); } - additionalCameraData.customRender += RenderOutlineMask; - m_OutlineMaskTarget = renderRequests[0].result; - try { + additionalCameraData.customRender += RenderSceneSelectionRequest; + m_SceneSelectionMode = request.mode; + m_SceneSelectionTarget = request.result; Render(renderContext, new[] {camera}); } finally { - additionalCameraData.customRender -= RenderOutlineMask; + additionalCameraData.customRender -= RenderSceneSelectionRequest; } - - return; } + bool haveAOVRequests = false; var requests = new AOVRequestBuilder(); foreach (var request in renderRequests) { + if (IsSceneSelectionRequest(request)) + continue; + var aovRequest = AOVRequest.NewDefault().SetRenderRequestMode(request.mode); var aovBuffers = AOVBuffers.Color; if (request.mode == Camera.RenderRequestMode.Depth || @@ -3221,19 +3240,24 @@ protected override void ProcessRenderRequests(ScriptableRenderContext renderCont //if (request.result != null) // cmd.Blit(textures[0], request.result); }); + haveAOVRequests = true; } - var additionaCameraData = camera.GetComponent(); - if (additionaCameraData == null) + if (haveAOVRequests) { - camera.gameObject.AddComponent(); - additionaCameraData = camera.GetComponent(); - } - additionaCameraData.SetAOVRequests(requests.Build()); + var additionaCameraData = camera.GetComponent(); + if (additionaCameraData == null) + { + camera.gameObject.AddComponent(); + additionaCameraData = camera.GetComponent(); + } - Render(renderContext, new[] {camera}); + additionaCameraData.SetAOVRequests(requests.Build()); - additionaCameraData.SetAOVRequests(null); + Render(renderContext, new[] {camera}); + + additionaCameraData.SetAOVRequests(null); + } } finally { @@ -3242,32 +3266,53 @@ protected override void ProcessRenderRequests(ScriptableRenderContext renderCont } } - RenderTexture m_OutlineMaskTarget; - void RenderOutlineMask(ScriptableRenderContext context, HDCamera hdCamera) + Camera.RenderRequestMode m_SceneSelectionMode; + RenderTexture m_SceneSelectionTarget; + void RenderSceneSelectionRequest(ScriptableRenderContext context, HDCamera hdCamera) { - var cmd = CommandBufferPool.Get(""); + var cmd = CommandBufferPool.Get("RenderSceneSelectionRequest"); + + using (new ProfilingScope(cmd, ProfilingSampler.Get(HDProfileId.RenderSceneSelection))) + { + cmd.SetRenderTarget(m_SceneSelectionTarget); + cmd.ClearRenderTarget(true, true, Color.clear); + cmd.SetGlobalInt("_ObjectId", 0); + cmd.SetGlobalInt("_PassValue", 1); + cmd.SetGlobalVector("_SelectionID", new Vector4((float)(int)m_SceneSelectionMode, 0, 0, 0)); - // TODO: Need depth target. - cmd.SetRenderTarget(m_OutlineMaskTarget); - //cmd.ClearRenderTarget(true, true, Color.black); + hdCamera.UpdateShaderVariablesGlobalCB(ref m_ShaderVariablesGlobalCB, 0); + ConstantBuffer.PushGlobal(cmd, m_ShaderVariablesGlobalCB, HDShaderIDs._ShaderVariablesGlobal); - var camera = hdCamera.camera; - camera.TryGetCullingParameters(out var cullingParameters); - var cullingResults = context.Cull(ref cullingParameters); + var camera = hdCamera.camera; + camera.TryGetCullingParameters(out var cullingParameters); + var cullingResults = context.Cull(ref cullingParameters); - var sceneSelectionTag = new ShaderTagId("SceneSelectionPass"); + ShaderTagId shaderTagId; + switch (m_SceneSelectionMode) + { + case Camera.RenderRequestMode.ObjectId: + case Camera.RenderRequestMode.EntityId: + shaderTagId = new ShaderTagId("Picking"); + break; + case Camera.RenderRequestMode.SelectionMask: + shaderTagId = new ShaderTagId("SceneSelectionPass"); + break; + default: + return; + } - var drawingSettings = new DrawingSettings( - sceneSelectionTag, - new SortingSettings(camera) { criteria = SortingCriteria.None}); + var drawingSettings = new DrawingSettings( + shaderTagId, + new SortingSettings(camera) { criteria = SortingCriteria.None}); - var filteringSettings = FilteringSettings.defaultValue; + var filteringSettings = FilteringSettings.defaultValue; - context.ExecuteCommandBuffer(cmd); - context.DrawRenderers( - cullingResults, - ref drawingSettings, - ref filteringSettings); + context.ExecuteCommandBuffer(cmd); + context.DrawRenderers( + cullingResults, + ref drawingSettings, + ref filteringSettings); + } } void SetupCameraProperties(HDCamera hdCamera, ScriptableRenderContext renderContext, CommandBuffer cmd) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl index 06f2851687a..cb1fc61a664 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl @@ -100,9 +100,24 @@ void Frag( PackedVaryingsToPS packedInput #ifdef SCENESELECTIONPASS // We use depth prepass for scene selection in the editor, this code allow to output the outline correctly - outColor = float4(_ObjectId, _PassValue, 1.0, 1.0); + // outColor = float4(_ObjectId, _PassValue, 1.0, 1.0); + outColor = ComputeSelectionMask( + _ObjectId, + float3(posInput.positionNDC, posInput.deviceDepth), + TEXTURE2D_ARGS(unity_EditorViz_DepthBuffer, sampler_unity_EditorViz_DepthBuffer)); #elif defined(SCENEPICKINGPASS) - outColor = _SelectionID; + #ifdef UNITY_DOTS_INSTANCING_ENABLED + if (_SelectionID.x == 5.0) // EntityId = 5, + outColor = PackId32ToRGBA8888(unity_EntityId.x); + else + outColor = float4(0, 0, 0, 0); // GameObjects output EntityId = 0 + #else + if (_SelectionID.x == 1.0) // ObjectId = 1, + outColor = PackId32ToRGBA8888(asuint(unity_LODFade.z)); + else + outColor = float4(0, 0, 0, 0); // Entities output ObjectId = 0 + #endif + //outColor = _SelectionID; #else // Depth and Alpha to coverage diff --git a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl index 0b3be72d754..2847580463b 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl @@ -1,7 +1,7 @@ #ifndef UNITY_PICKING_SPACE_TRANSFORMS_INCLUDED #define UNITY_PICKING_SPACE_TRANSFORMS_INCLUDED -#ifdef SCENEPICKINGPASS +#if 0 //def SCENEPICKINGPASS // The picking pass uses custom matrices defined directly from the c++ // So we have to redefine the space transform functions to overwrite the used matrices diff --git a/com.unity.render-pipelines.universal/ShaderLibrary/DataExtraction.hlsl b/com.unity.render-pipelines.universal/ShaderLibrary/DataExtraction.hlsl index 70f12012b25..42e5bdb1731 100644 --- a/com.unity.render-pipelines.universal/ShaderLibrary/DataExtraction.hlsl +++ b/com.unity.render-pipelines.universal/ShaderLibrary/DataExtraction.hlsl @@ -95,22 +95,14 @@ float4 OutputExtraction(ExtractionInputs inputs) return float4(diffuse, inputs.alpha); if (UNITY_DataExtraction_Mode == RENDER_OUTLINE_MASK) { - float3 ndcZ = ComputeNormalizedDeviceCoordinatesWithZ(inputs.positionWS, UNITY_MATRIX_VP); - float sceneZ = SAMPLE_TEXTURE2D(unity_EditorViz_DepthBuffer, sampler_unity_EditorViz_DepthBuffer, ndcZ.xy).r; - // Use a small multiplicative Z bias to make it less likely for objects to self occlude in the outline buffer - static const float zBias = 0.02; -#if UNITY_REVERSED_Z - float pixelZ = ndcZ.z * (1 + zBias); - bool occluded = pixelZ < sceneZ; -#else - float pixelZ = ndcZ.z * (1 - zBias); - bool occluded = pixelZ > sceneZ; -#endif // Red channel = unique identifier, can be used to separate groups of objects from each other // to get outlines between them. // Green channel = occluded behind depth buffer (0) or not occluded (1) // Blue channel = always 1 = not cleared to zero = there's an outlined object at this pixel - return float4((float)UNITY_DataExtraction_Value / 255.0, occluded ? 0 : 1, 1, 1); + return ComputeSelectionMask( + (float)UNITY_DataExtraction_Value / 255.0, + ComputeNormalizedDeviceCoordinatesWithZ(inputs.positionWS, UNITY_MATRIX_VP), + TEXTURE2D_ARGS(unity_EditorViz_DepthBuffer, sampler_unity_EditorViz_DepthBuffer)); } return 0; From 4f525644072773085a3bdf39e33d017ec65477dc Mon Sep 17 00:00:00 2001 From: Joachim Ante Date: Fri, 12 Feb 2021 01:09:16 +0100 Subject: [PATCH 10/30] DrawGizmos render request mode --- .../Runtime/ScriptableRenderer.cs | 9 ++++++--- .../Runtime/UniversalRenderPipeline.cs | 3 ++- .../Runtime/UniversalRenderPipelineCore.cs | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/com.unity.render-pipelines.universal/Runtime/ScriptableRenderer.cs b/com.unity.render-pipelines.universal/Runtime/ScriptableRenderer.cs index 6dc7b8d510c..37e024df46e 100644 --- a/com.unity.render-pipelines.universal/Runtime/ScriptableRenderer.cs +++ b/com.unity.render-pipelines.universal/Runtime/ScriptableRenderer.cs @@ -557,7 +557,7 @@ public void Execute(ScriptableRenderContext context, ref RenderingData rendering } // Draw Gizmos... - if (!cameraData.isRenderRequest) + if (cameraData.renderRequestMode == Camera.RenderRequestMode.None) DrawGizmos(context, camera, GizmoSubset.PreImageEffects); // In this block after rendering drawing happens, e.g, post processing, video player capture. @@ -569,12 +569,15 @@ public void Execute(ScriptableRenderContext context, ref RenderingData rendering EndXRRendering(cmd, context, ref renderingData.cameraData); - if (!cameraData.isRenderRequest) + if (cameraData.renderRequestMode == Camera.RenderRequestMode.None) { DrawWireOverlay(context, camera); DrawGizmos(context, camera, GizmoSubset.PostImageEffects); } - + + if (cameraData.renderRequestMode == Camera.RenderRequestMode.ObjectId) + DrawGizmos(context, camera, GizmoSubset.RenderRequestInstanceID); + InternalFinishRendering(context, cameraData.resolveFinalTarget); } diff --git a/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs b/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs index 7cd0f110b18..b68d8bdbaea 100644 --- a/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs +++ b/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs @@ -237,10 +237,11 @@ void RenderWithMode(ScriptableRenderContext renderContext, Camera camera, Camera return; } + //@TODO: What crazy sauce is this? var data = ScriptableObject.CreateInstance(); data.request = renderRequest; InitializeCameraData(camera, additionalCameraData, true, out var cameraData); - cameraData.isRenderRequest = true; + cameraData.renderRequestMode = renderRequest.mode; cameraData.renderer = data.InternalCreateRenderer(); RenderSingleCamera(renderContext, cameraData, false); Object.DestroyImmediate(data); diff --git a/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipelineCore.cs b/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipelineCore.cs index cedfdbe5c66..02f49c44bf7 100644 --- a/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipelineCore.cs +++ b/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipelineCore.cs @@ -108,7 +108,7 @@ public Matrix4x4 GetGPUProjectionMatrix(int viewIndex = 0) public bool isHdrEnabled; public bool requiresDepthTexture; public bool requiresOpaqueTexture; - public bool isRenderRequest; + public Camera.RenderRequestMode renderRequestMode; #if ENABLE_VR && ENABLE_XR_MODULE public bool xrRendering; #endif From 3f6c180af46ec80a465d1505fa2e09369f0ef24d Mon Sep 17 00:00:00 2001 From: Jussi Knuuttila Date: Fri, 12 Feb 2021 13:04:35 +0200 Subject: [PATCH 11/30] Use blending to make sure "unoccluded" values always remain on top in the selection outline buffer --- .../Runtime/UniversalRenderPipeline.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs b/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs index b68d8bdbaea..91702ad9600 100644 --- a/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs +++ b/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs @@ -286,8 +286,23 @@ public RenderRequestRenderer(RenderRequestRendererData data) : base(data) var state = m_RenderOpaqueForwardPassZDisabled.RenderStateBlock; state.rasterState = new RasterState(CullMode.Back, 0, -0.02f); + // There is no Z buffer for selection mask, use blending to make sure "unoccluded" (G = 1) values + // always remain on top. + state.blendState = new BlendState + { + blendState0 = new RenderTargetBlendState + { + colorBlendOperation = BlendOp.Max, + sourceColorBlendMode = BlendMode.One, + destinationColorBlendMode = BlendMode.One, + alphaBlendOperation = BlendOp.Max, + sourceAlphaBlendMode = BlendMode.One, + destinationAlphaBlendMode = BlendMode.One, + writeMask = ColorWriteMask.Green | ColorWriteMask.Blue | ColorWriteMask.Alpha, + } + }; state.depthState = new DepthState {compareFunction = CompareFunction.Always, writeEnabled = false}; - state.mask = RenderStateMask.Raster | RenderStateMask.Depth; + state.mask = RenderStateMask.Everything; m_RenderOpaqueForwardPassZDisabled.RenderStateBlock = state; m_RenderTransparentForwardPassZDisabled.RenderStateBlock = state; } From aa05312ae0ec6c6599826cedd10694400627710b Mon Sep 17 00:00:00 2001 From: Jussi Knuuttila Date: Fri, 12 Feb 2021 13:23:47 +0200 Subject: [PATCH 12/30] Use blending to make sure "unoccluded" values always remain on top in the selection outline buffer, HDRP implementation --- .../RenderPipeline/HDRenderPipeline.cs | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs index 039d39d4091..b49f835161b 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs @@ -3287,6 +3287,8 @@ void RenderSceneSelectionRequest(ScriptableRenderContext context, HDCamera hdCam camera.TryGetCullingParameters(out var cullingParameters); var cullingResults = context.Cull(ref cullingParameters); + var renderState = new RenderStateBlock(RenderStateMask.Nothing); + ShaderTagId shaderTagId; switch (m_SceneSelectionMode) { @@ -3296,6 +3298,24 @@ void RenderSceneSelectionRequest(ScriptableRenderContext context, HDCamera hdCam break; case Camera.RenderRequestMode.SelectionMask: shaderTagId = new ShaderTagId("SceneSelectionPass"); + renderState.rasterState = new RasterState(CullMode.Back, 0, -0.02f); + // There is no Z buffer for selection mask, use blending to make sure "unoccluded" (G = 1) values + // always remain on top. + renderState.blendState = new BlendState + { + blendState0 = new RenderTargetBlendState + { + colorBlendOperation = BlendOp.Max, + sourceColorBlendMode = BlendMode.One, + destinationColorBlendMode = BlendMode.One, + alphaBlendOperation = BlendOp.Max, + sourceAlphaBlendMode = BlendMode.One, + destinationAlphaBlendMode = BlendMode.One, + writeMask = ColorWriteMask.Green | ColorWriteMask.Blue | ColorWriteMask.Alpha, + } + }; + renderState.depthState = new DepthState {compareFunction = CompareFunction.Always, writeEnabled = false}; + renderState.mask = RenderStateMask.Everything; break; default: return; @@ -3311,7 +3331,8 @@ void RenderSceneSelectionRequest(ScriptableRenderContext context, HDCamera hdCam context.DrawRenderers( cullingResults, ref drawingSettings, - ref filteringSettings); + ref filteringSettings, + ref renderState); } } From 988920a5ff195f386d2c46dfaec2789c4be893e8 Mon Sep 17 00:00:00 2001 From: Jussi Knuuttila Date: Fri, 9 Apr 2021 19:52:17 +0300 Subject: [PATCH 13/30] Clean up unused things from new picking and outline rendering --- .../ShaderLibrary/Debug.hlsl | 13 ------------- .../Runtime/Debug/DebugDisplay.cs | 7 ------- .../Runtime/Debug/MaterialDebug.cs | 6 ------ .../Runtime/Material/Builtin/BuiltinData.cs | 8 -------- .../Runtime/Material/Builtin/BuiltinData.hlsl | 14 -------------- .../Runtime/RenderPipeline/HDRenderPipeline.cs | 14 +++++++------- .../RenderPipeline/RenderPass/AOV/AOVRequest.cs | 9 --------- .../ShaderPass/ShaderPassDepthOnly.hlsl | 6 ++++-- .../ShaderLibrary/PickingSpaceTransforms.hlsl | 7 ++++++- 9 files changed, 17 insertions(+), 67 deletions(-) diff --git a/com.unity.render-pipelines.core/ShaderLibrary/Debug.hlsl b/com.unity.render-pipelines.core/ShaderLibrary/Debug.hlsl index c61b2dd3328..cc3baf498e5 100644 --- a/com.unity.render-pipelines.core/ShaderLibrary/Debug.hlsl +++ b/com.unity.render-pipelines.core/ShaderLibrary/Debug.hlsl @@ -276,19 +276,6 @@ real3 GetColorCodeFunction(real value, real4 threshold) return outColor; } -float3 PackIndexToRGB16f(uint entityId) -{ - // half can represent up to 2^11 exactly as an integer, - // use 10 bits of each channel. - uint b0 = (entityId >> 0) & 0x3ff; - uint b1 = (entityId >> 10) & 0x3ff; - uint b2 = (entityId >> 20) & 0x3ff; - float f0 = (float)b0 / 1023.0f; - float f1 = (float)b1 / 1023.0f; - float f2 = (float)b2 / 1023.0f; - return float3(f0, f1, f2); -} - float4 ComputeSelectionMask(float objectGroupId, float3 ndcWithZ, TEXTURE2D_PARAM(depthBuffer, sampler_depthBuffer)) { float sceneZ = SAMPLE_TEXTURE2D(depthBuffer, sampler_depthBuffer, ndcWithZ.xy).r; diff --git a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs index 952159a2202..34c025e7f73 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs @@ -214,8 +214,6 @@ public class DebugData public bool allowSRGBConversion = true; /// Whether to display the average timings every second. public bool averageProfilerTimingsOverASecond = false; - /// Debug value requires high precision. - public bool requireHighPrecision = false; /// Current material debug settings. public MaterialDebugSettings materialDebugSettings = new MaterialDebugSettings(); @@ -1981,10 +1979,5 @@ internal bool DebugNeedsExposure() (data.fullScreenDebugMode == FullScreenDebugMode.PreRefractionColorPyramid || data.fullScreenDebugMode == FullScreenDebugMode.FinalColorPyramid || data.fullScreenDebugMode == FullScreenDebugMode.ScreenSpaceReflections || data.fullScreenDebugMode == FullScreenDebugMode.ScreenSpaceReflectionsPrev || data.fullScreenDebugMode == FullScreenDebugMode.ScreenSpaceReflectionsAccum || data.fullScreenDebugMode == FullScreenDebugMode.LightCluster || data.fullScreenDebugMode == FullScreenDebugMode.ScreenSpaceShadows || data.fullScreenDebugMode == FullScreenDebugMode.NanTracker || data.fullScreenDebugMode == FullScreenDebugMode.ColorLog) || data.fullScreenDebugMode == FullScreenDebugMode.ScreenSpaceGlobalIllumination || (debugLighting == DebugLightingMode.ProbeVolume || debugProbeVolume == ProbeVolumeDebugMode.VisualizeAtlas); } - - public void SetRequireHighPrecision(bool requireHighPrecision) - { - data.requireHighPrecision = requireHighPrecision; - } } } diff --git a/com.unity.render-pipelines.high-definition/Runtime/Debug/MaterialDebug.cs b/com.unity.render-pipelines.high-definition/Runtime/Debug/MaterialDebug.cs index 8bff9da5a8b..11c320933de 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Debug/MaterialDebug.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Debug/MaterialDebug.cs @@ -106,10 +106,6 @@ public enum MaterialSharedProperty Specular, /// Display alpha. Alpha, - /// Display entity ID. - EntityId, - /// Display object ID. - ObjectId, } class MaterialSharedPropertyMappingAttribute : Attribute @@ -358,8 +354,6 @@ static void BuildDebugRepresentation() { MaterialSharedProperty.Metal, new List() }, { MaterialSharedProperty.Specular, new List() }, { MaterialSharedProperty.Alpha, new List() }, - { MaterialSharedProperty.EntityId, new List() }, - { MaterialSharedProperty.ObjectId, new List() }, }; // builtins parameters diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Builtin/BuiltinData.cs b/com.unity.render-pipelines.high-definition/Runtime/Material/Builtin/BuiltinData.cs index b693f9036ed..047bb09be6e 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Builtin/BuiltinData.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Builtin/BuiltinData.cs @@ -66,14 +66,6 @@ public struct BuiltinData [SurfaceDataAttributes("VT Packed Feedback", precision = FieldPrecision.Real)] public Vector4 vtPackedFeedback; - - [MaterialSharedPropertyMapping(MaterialSharedProperty.EntityId)] - [SurfaceDataAttributes("Entity Id")] - public uint entityId; - - [MaterialSharedPropertyMapping(MaterialSharedProperty.ObjectId)] - [SurfaceDataAttributes("Object Id")] - public uint objectId; }; //----------------------------------------------------------------------------- diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Builtin/BuiltinData.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/Builtin/BuiltinData.hlsl index 154a7d5b928..39c22b59120 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Builtin/BuiltinData.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Builtin/BuiltinData.hlsl @@ -78,20 +78,6 @@ void GetBuiltinDataDebug(uint paramId, BuiltinData builtinData, PositionInputs p case DEBUGVIEW_BUILTIN_BUILTINDATA_DISTORTION: result = float3((builtinData.distortion / (abs(builtinData.distortion) + 1) + 1) * 0.5, 0.5); break; - case DEBUGVIEW_BUILTIN_BUILTINDATA_ENTITY_ID: -#ifdef UNITY_DOTS_INSTANCING_ENABLED - result = PackIndexToRGB16f(unity_EntityId.x); -#else - result = 0; -#endif - break; - case DEBUGVIEW_BUILTIN_BUILTINDATA_OBJECT_ID: -#ifdef UNITY_SHADER_VARIABLES_INCLUDED - result = PackIndexToRGB16f(asuint(unity_LODFade.z)); -#else - result = 0; -#endif - break; #ifdef DEBUG_DISPLAY case DEBUGVIEW_BUILTIN_BUILTINDATA_RENDERING_LAYERS: // Only 8 first rendering layers are currently in use (used by light layers) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs index b49f835161b..3f4c23855a5 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs @@ -306,7 +306,9 @@ internal int GetMaxScreenSpaceShadows() // This target is only used in Dev builds as an intermediate destination for post process and where debug rendering will be done. RTHandle m_IntermediateAfterPostProcessBuffer; RTHandle m_IntermediateAfterPostProcessBufferFloat; - RTHandle m_HighPrecisionDebugBufferFloat; + // These are used to pass scene selection settings to the method that renders it + Camera.RenderRequestMode m_SceneSelectionMode; + RenderTexture m_SceneSelectionTarget; // We need this flag because otherwise if no full screen debug is pushed (like for example if the corresponding pass is disabled), when we render the result in RenderDebug m_DebugFullScreenTempBuffer will contain potential garbage bool m_FullScreenDebugPushed; @@ -3209,6 +3211,8 @@ protected override void ProcessRenderRequests(ScriptableRenderContext renderCont m_SceneSelectionMode = request.mode; m_SceneSelectionTarget = request.result; Render(renderContext, new[] {camera}); + // Clear the target field to make sure we're not leaking a reference to it + m_SceneSelectionTarget = null; } finally { @@ -3266,8 +3270,6 @@ protected override void ProcessRenderRequests(ScriptableRenderContext renderCont } } - Camera.RenderRequestMode m_SceneSelectionMode; - RenderTexture m_SceneSelectionTarget; void RenderSceneSelectionRequest(ScriptableRenderContext context, HDCamera hdCamera) { var cmd = CommandBufferPool.Get("RenderSceneSelectionRequest"); @@ -4298,10 +4300,8 @@ void RenderDebugViewMaterial(CullingResults cull, HDCamera hdCamera, ScriptableR private RTHandle GetDebugViewTargetBuffer() { - if (m_CurrentDebugDisplaySettings.data.requireHighPrecision) - return m_DebugFullScreenTempBuffer; - else - return m_CameraColorBuffer; + // Used to contain a test whether to return a float16 target, but no longer needed + return m_CameraColorBuffer; } struct TransparencyOverdrawParameters diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVRequest.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVRequest.cs index ed58665dd8a..7023d007327 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVRequest.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVRequest.cs @@ -190,14 +190,9 @@ public void FillDebugData(DebugDisplaySettings debug) if (m_RequestMode != Camera.RenderRequestMode.None) { debug.SetAllowSRGBConversion(false); - debug.SetRequireHighPrecision(false); switch (m_RequestMode) { - case Camera.RenderRequestMode.ObjectId: - debug.SetRequireHighPrecision(true); - debug.SetDebugViewCommonMaterialProperty(MaterialSharedProperty.ObjectId); - break; case Camera.RenderRequestMode.Depth: debug.SetFullScreenDebugMode(FullScreenDebugMode.DepthPyramid); break; @@ -207,10 +202,6 @@ public void FillDebugData(DebugDisplaySettings debug) case Camera.RenderRequestMode.WorldPosition: debug.SetFullScreenDebugMode(FullScreenDebugMode.WorldSpacePosition); break; - case Camera.RenderRequestMode.EntityId: - debug.SetRequireHighPrecision(true); - debug.SetDebugViewCommonMaterialProperty(MaterialSharedProperty.EntityId); - break; case Camera.RenderRequestMode.BaseColor: //@TODO: This should perform metallic / specular conversion debug.SetDebugViewCommonMaterialProperty(MaterialSharedProperty.Albedo); diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl index cb1fc61a664..14ad18d5e7f 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl @@ -107,15 +107,17 @@ void Frag( PackedVaryingsToPS packedInput TEXTURE2D_ARGS(unity_EditorViz_DepthBuffer, sampler_unity_EditorViz_DepthBuffer)); #elif defined(SCENEPICKINGPASS) #ifdef UNITY_DOTS_INSTANCING_ENABLED + // When rendering EntityIds, GameObjects output EntityId = 0 if (_SelectionID.x == 5.0) // EntityId = 5, outColor = PackId32ToRGBA8888(unity_EntityId.x); else - outColor = float4(0, 0, 0, 0); // GameObjects output EntityId = 0 + outColor = float4(0, 0, 0, 0); #else + // When rendering ObjectIds, Entities output ObjectId = 0 if (_SelectionID.x == 1.0) // ObjectId = 1, outColor = PackId32ToRGBA8888(asuint(unity_LODFade.z)); else - outColor = float4(0, 0, 0, 0); // Entities output ObjectId = 0 + outColor = float4(0, 0, 0, 0); #endif //outColor = _SelectionID; #else diff --git a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl index 2847580463b..1264c10e415 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl @@ -1,7 +1,11 @@ +#if 0 +// This file overrides a large amount of macros to be compatible with the old +// Unity C++ picking. It is no longer necessary with the new SRP based picking. + #ifndef UNITY_PICKING_SPACE_TRANSFORMS_INCLUDED #define UNITY_PICKING_SPACE_TRANSFORMS_INCLUDED -#if 0 //def SCENEPICKINGPASS +#ifdef SCENEPICKINGPASS // The picking pass uses custom matrices defined directly from the c++ // So we have to redefine the space transform functions to overwrite the used matrices @@ -66,3 +70,4 @@ float4x4 glstate_matrix_projection; #endif #endif +#endif From 4a04626b3d74c2ff3d0b816bcb43fcb8ef2049e5 Mon Sep 17 00:00:00 2001 From: Jussi Knuuttila Date: Fri, 9 Apr 2021 20:08:05 +0300 Subject: [PATCH 14/30] Share data extraction shader code between HDRP and URP --- .../ShaderLibrary/DataExtraction.hlsl | 53 +++++++++++++++++++ .../ShaderLibrary/DataExtraction.hlsl.meta | 3 ++ .../ShaderLibrary/Debug.hlsl | 32 ----------- .../ShaderPass/ShaderPassDepthOnly.hlsl | 5 +- .../ShaderLibrary/DataExtraction.hlsl | 16 +----- 5 files changed, 60 insertions(+), 49 deletions(-) create mode 100644 com.unity.render-pipelines.core/ShaderLibrary/DataExtraction.hlsl create mode 100644 com.unity.render-pipelines.core/ShaderLibrary/DataExtraction.hlsl.meta diff --git a/com.unity.render-pipelines.core/ShaderLibrary/DataExtraction.hlsl b/com.unity.render-pipelines.core/ShaderLibrary/DataExtraction.hlsl new file mode 100644 index 00000000000..446529473c4 --- /dev/null +++ b/com.unity.render-pipelines.core/ShaderLibrary/DataExtraction.hlsl @@ -0,0 +1,53 @@ +#ifndef UNITY_DATA_EXTRACTION_INCLUDED +#define UNITY_DATA_EXTRACTION_INCLUDED + +// These correspond to UnityEngine.Camera.RenderRequestMode enum values +#define RENDER_OBJECT_ID 1 +#define RENDER_DEPTH 2 +#define RENDER_WORLD_NORMALS_FACE_RGB 3 +#define RENDER_WORLD_POSITION_RGB 4 +#define RENDER_ENTITY_ID 5 +#define RENDER_BASE_COLOR_RGBA 6 +#define RENDER_SPECULAR_RGB 7 +#define RENDER_METALLIC_R 8 +#define RENDER_EMISSION_RGB 9 +#define RENDER_WORLD_NORMALS_PIXEL_RGB 10 +#define RENDER_SMOOTHNESS_R 11 +#define RENDER_OCCLUSION_R 12 +#define RENDER_DIFFUSE_COLOR_RGBA 13 +#define RENDER_OUTLINE_MASK 14 + +float4 ComputeSelectionMask(float objectGroupId, float3 ndcWithZ, TEXTURE2D_PARAM(depthBuffer, sampler_depthBuffer)) +{ + float sceneZ = SAMPLE_TEXTURE2D(depthBuffer, sampler_depthBuffer, ndcWithZ.xy).r; + // Use a small multiplicative Z bias to make it less likely for objects to self occlude in the outline buffer + static const float zBias = 0.02; +#if UNITY_REVERSED_Z + float pixelZ = ndcWithZ.z * (1 + zBias); + bool occluded = pixelZ < sceneZ; +#else + float pixelZ = ndcWithZ.z * (1 - zBias); + bool occluded = pixelZ > sceneZ; +#endif + // Red channel = unique identifier, can be used to separate groups of objects from each other + // to get outlines between them. + // Green channel = occluded behind depth buffer (0) or not occluded (1) + // Blue channel = always 1 = not cleared to zero = there's an outlined object at this pixel + return float4(objectGroupId, occluded ? 0 : 1, 1, 1); +} + +float4 PackId32ToRGBA8888(uint id32) +{ + uint b0 = (id32 >> 0) & 0xff; + uint b1 = (id32 >> 8) & 0xff; + uint b2 = (id32 >> 16) & 0xff; + uint b3 = (id32 >> 24) & 0xff; + float f0 = (float)b0 / 255.0f; + float f1 = (float)b1 / 255.0f; + float f2 = (float)b2 / 255.0f; + float f3 = (float)b3 / 255.0f; + return float4(f0, f1, f2, f3); +} + +#endif + diff --git a/com.unity.render-pipelines.core/ShaderLibrary/DataExtraction.hlsl.meta b/com.unity.render-pipelines.core/ShaderLibrary/DataExtraction.hlsl.meta new file mode 100644 index 00000000000..570e8777432 --- /dev/null +++ b/com.unity.render-pipelines.core/ShaderLibrary/DataExtraction.hlsl.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 2457427cd93a466db488bb565b0624b0 +timeCreated: 1617987396 \ No newline at end of file diff --git a/com.unity.render-pipelines.core/ShaderLibrary/Debug.hlsl b/com.unity.render-pipelines.core/ShaderLibrary/Debug.hlsl index cc3baf498e5..105bac1171f 100644 --- a/com.unity.render-pipelines.core/ShaderLibrary/Debug.hlsl +++ b/com.unity.render-pipelines.core/ShaderLibrary/Debug.hlsl @@ -276,36 +276,4 @@ real3 GetColorCodeFunction(real value, real4 threshold) return outColor; } -float4 ComputeSelectionMask(float objectGroupId, float3 ndcWithZ, TEXTURE2D_PARAM(depthBuffer, sampler_depthBuffer)) -{ - float sceneZ = SAMPLE_TEXTURE2D(depthBuffer, sampler_depthBuffer, ndcWithZ.xy).r; - // Use a small multiplicative Z bias to make it less likely for objects to self occlude in the outline buffer - static const float zBias = 0.02; -#if UNITY_REVERSED_Z - float pixelZ = ndcWithZ.z * (1 + zBias); - bool occluded = pixelZ < sceneZ; -#else - float pixelZ = ndcWithZ.z * (1 - zBias); - bool occluded = pixelZ > sceneZ; -#endif - // Red channel = unique identifier, can be used to separate groups of objects from each other - // to get outlines between them. - // Green channel = occluded behind depth buffer (0) or not occluded (1) - // Blue channel = always 1 = not cleared to zero = there's an outlined object at this pixel - return float4(objectGroupId, occluded ? 0 : 1, 1, 1); -} - -float4 PackId32ToRGBA8888(uint id32) -{ - uint b0 = (id32 >> 0) & 0xff; - uint b1 = (id32 >> 8) & 0xff; - uint b2 = (id32 >> 16) & 0xff; - uint b3 = (id32 >> 24) & 0xff; - float f0 = (float)b0 / 255.0f; - float f1 = (float)b1 / 255.0f; - float f2 = (float)b2 / 255.0f; - float f3 = (float)b3 / 255.0f; - return float4(f0, f1, f2, f3); -} - #endif // UNITY_DEBUG_INCLUDED diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl index 14ad18d5e7f..cb3f5910cca 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl @@ -6,6 +6,7 @@ #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS) #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl" #endif +#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/DataExtraction.hlsl" PackedVaryingsType Vert(AttributesMesh inputMesh) { @@ -108,13 +109,13 @@ void Frag( PackedVaryingsToPS packedInput #elif defined(SCENEPICKINGPASS) #ifdef UNITY_DOTS_INSTANCING_ENABLED // When rendering EntityIds, GameObjects output EntityId = 0 - if (_SelectionID.x == 5.0) // EntityId = 5, + if (_SelectionID.x == RENDER_ENTITY_ID) outColor = PackId32ToRGBA8888(unity_EntityId.x); else outColor = float4(0, 0, 0, 0); #else // When rendering ObjectIds, Entities output ObjectId = 0 - if (_SelectionID.x == 1.0) // ObjectId = 1, + if (_SelectionID.x == RENDER_OBJECT_ID) outColor = PackId32ToRGBA8888(asuint(unity_LODFade.z)); else outColor = float4(0, 0, 0, 0); diff --git a/com.unity.render-pipelines.universal/ShaderLibrary/DataExtraction.hlsl b/com.unity.render-pipelines.universal/ShaderLibrary/DataExtraction.hlsl index 42e5bdb1731..bf016f14f46 100644 --- a/com.unity.render-pipelines.universal/ShaderLibrary/DataExtraction.hlsl +++ b/com.unity.render-pipelines.universal/ShaderLibrary/DataExtraction.hlsl @@ -1,25 +1,11 @@ #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Debug.hlsl" +#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/DataExtraction.hlsl" int UNITY_DataExtraction_Mode; int UNITY_DataExtraction_Space; int UNITY_DataExtraction_Value; TEXTURE2D(unity_EditorViz_DepthBuffer); SAMPLER(sampler_unity_EditorViz_DepthBuffer); -#define RENDER_OBJECT_ID 1 -#define RENDER_DEPTH 2 -#define RENDER_WORLD_NORMALS_FACE_RGB 3 -#define RENDER_WORLD_POSITION_RGB 4 -#define RENDER_ENTITY_ID 5 -#define RENDER_BASE_COLOR_RGBA 6 -#define RENDER_SPECULAR_RGB 7 -#define RENDER_METALLIC_R 8 -#define RENDER_EMISSION_RGB 9 -#define RENDER_WORLD_NORMALS_PIXEL_RGB 10 -#define RENDER_SMOOTHNESS_R 11 -#define RENDER_OCCLUSION_R 12 -#define RENDER_DIFFUSE_COLOR_RGBA 13 -#define RENDER_OUTLINE_MASK 14 - struct ExtractionInputs { float3 vertexNormalWS; From d8cf4780aa78b79444ba01033a6485d793579665 Mon Sep 17 00:00:00 2001 From: Jussi Knuuttila Date: Fri, 9 Apr 2021 20:16:37 +0300 Subject: [PATCH 15/30] Cleaned up unused "DataExtraction_Value" and placed outline mask test first for improved performance. --- .../Runtime/UniversalRenderPipeline.cs | 15 ++++------- .../ShaderLibrary/DataExtraction.hlsl | 26 ++++++++++--------- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs b/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs index 91702ad9600..2a82c813069 100644 --- a/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs +++ b/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs @@ -199,7 +199,7 @@ protected override void ProcessRenderRequests(ScriptableRenderContext renderCont GraphicsSettings.lightsUseLinearIntensity = (QualitySettings.activeColorSpace == ColorSpace.Linear); GraphicsSettings.useScriptableRenderPipelineBatching = asset.useSRPBatcher; SetupPerFrameShaderConstants(); - + BeginCameraRendering(renderContext, camera); #if VISUAL_EFFECT_GRAPH_0_0_1_OR_NEWER //It should be called before culling to prepare material. When there isn't any VisualEffect component, this method has no effect. @@ -212,12 +212,12 @@ protected override void ProcessRenderRequests(ScriptableRenderContext renderCont foreach (var renderRequest in renderRequests) { - + if (!renderRequest.isValid) continue; RenderWithMode(renderContext, camera, renderRequest); } - + EndCameraRendering(renderContext, camera); EndFrameRendering(renderContext, cameras); camera.targetTexture = cameraTarget; @@ -256,7 +256,7 @@ protected override ScriptableRenderer Create() public Camera.RenderRequest request { get; set; } } - + class RenderRequestRenderer : ScriptableRenderer { DrawObjectsPass m_RenderOpaqueForwardPass; @@ -311,7 +311,6 @@ public RenderRequestRenderer(RenderRequestRendererData data) : base(data) { new Tuple("UNITY_DataExtraction_Mode", (int)data.request.mode), new Tuple("UNITY_DataExtraction_Space", (int)data.request.outputSpace), - new Tuple("UNITY_DataExtraction_Value", 0), }; m_RenderOpaqueForwardPass.SetAdditionalValues(values); @@ -323,8 +322,6 @@ public RenderRequestRenderer(RenderRequestRendererData data) : base(data) { new Tuple("UNITY_DataExtraction_Mode", (int)data.request.mode), new Tuple("UNITY_DataExtraction_Space", (int)data.request.outputSpace), - // TODO: Unique object identifier here? - new Tuple("UNITY_DataExtraction_Value", 0), }; m_RenderOpaqueForwardPassZDisabled.SetAdditionalValues(valuesZDisabled); @@ -352,13 +349,11 @@ public override void FinishRendering(CommandBuffer cmd) base.FinishRendering(cmd); cmd.SetGlobalInt("UNITY_DataExtraction_Mode", 0); cmd.SetGlobalInt("UNITY_DataExtraction_Space", 0); - cmd.SetGlobalInt("UNITY_DataExtraction_Value", 0); - } public bool IsSelectionMaskRequest => m_Mode == Camera.RenderRequestMode.SelectionMask; } - + #if UNITY_2021_1_OR_NEWER protected override void Render(ScriptableRenderContext renderContext, Camera[] cameras) { diff --git a/com.unity.render-pipelines.universal/ShaderLibrary/DataExtraction.hlsl b/com.unity.render-pipelines.universal/ShaderLibrary/DataExtraction.hlsl index bf016f14f46..1b9016002b8 100644 --- a/com.unity.render-pipelines.universal/ShaderLibrary/DataExtraction.hlsl +++ b/com.unity.render-pipelines.universal/ShaderLibrary/DataExtraction.hlsl @@ -3,7 +3,6 @@ int UNITY_DataExtraction_Mode; int UNITY_DataExtraction_Space; -int UNITY_DataExtraction_Value; TEXTURE2D(unity_EditorViz_DepthBuffer); SAMPLER(sampler_unity_EditorViz_DepthBuffer); struct ExtractionInputs @@ -30,6 +29,20 @@ float4 OutputExtraction(ExtractionInputs inputs) float3 specular, diffuse, baseColor; float metallic; + // Outline mask is the most performance sensitive (rendered each frame when selection is active), + // so it is tested first. + if (UNITY_DataExtraction_Mode == RENDER_OUTLINE_MASK) + { + // Red channel = unique identifier, can be used to separate groups of objects from each other + // to get outlines between them. + // Green channel = occluded behind depth buffer (0) or not occluded (1) + // Blue channel = always 1 = not cleared to zero = there's an outlined object at this pixel + return ComputeSelectionMask( + 0, // Object unique identifier currently unused + ComputeNormalizedDeviceCoordinatesWithZ(inputs.positionWS, UNITY_MATRIX_VP), + TEXTURE2D_ARGS(unity_EditorViz_DepthBuffer, sampler_unity_EditorViz_DepthBuffer)); + } + #ifdef _SPECULAR_SETUP specular = inputs.specular; diffuse = inputs.baseColor; @@ -79,17 +92,6 @@ float4 OutputExtraction(ExtractionInputs inputs) return float4(inputs.occlusion.xxx, 1.0); if (UNITY_DataExtraction_Mode == RENDER_DIFFUSE_COLOR_RGBA) return float4(diffuse, inputs.alpha); - if (UNITY_DataExtraction_Mode == RENDER_OUTLINE_MASK) - { - // Red channel = unique identifier, can be used to separate groups of objects from each other - // to get outlines between them. - // Green channel = occluded behind depth buffer (0) or not occluded (1) - // Blue channel = always 1 = not cleared to zero = there's an outlined object at this pixel - return ComputeSelectionMask( - (float)UNITY_DataExtraction_Value / 255.0, - ComputeNormalizedDeviceCoordinatesWithZ(inputs.positionWS, UNITY_MATRIX_VP), - TEXTURE2D_ARGS(unity_EditorViz_DepthBuffer, sampler_unity_EditorViz_DepthBuffer)); - } return 0; } From 2bf3d12515a512c7375249f1106c86541b0b9cfd Mon Sep 17 00:00:00 2001 From: Jussi Knuuttila Date: Thu, 6 May 2021 15:44:27 +0300 Subject: [PATCH 16/30] Split RenderRequestRenderer and RenderRequestRendererData into a separate .cs file. --- .../Runtime/RenderRequests.cs | 113 ++++++++++++++++++ .../Runtime/RenderRequests.cs.meta | 3 + .../Runtime/UniversalRenderPipeline.cs | 111 +---------------- 3 files changed, 118 insertions(+), 109 deletions(-) create mode 100644 com.unity.render-pipelines.universal/Runtime/RenderRequests.cs create mode 100644 com.unity.render-pipelines.universal/Runtime/RenderRequests.cs.meta diff --git a/com.unity.render-pipelines.universal/Runtime/RenderRequests.cs b/com.unity.render-pipelines.universal/Runtime/RenderRequests.cs new file mode 100644 index 00000000000..d51f87a878d --- /dev/null +++ b/com.unity.render-pipelines.universal/Runtime/RenderRequests.cs @@ -0,0 +1,113 @@ +using System; +using System.Collections.Generic; +using UnityEngine.Rendering.Universal.Internal; + +namespace UnityEngine.Rendering.Universal +{ + internal class RenderRequestRendererData : ScriptableRendererData + { + protected override ScriptableRenderer Create() + { + return new RenderRequestRenderer(this); + } + + public Camera.RenderRequest request { get; set; } + } + + internal class RenderRequestRenderer : ScriptableRenderer + { + DrawObjectsPass m_RenderOpaqueForwardPass; + DrawObjectsPass m_RenderTransparentForwardPass; + DrawObjectsPass m_RenderOpaqueForwardPassZDisabled; + DrawObjectsPass m_RenderTransparentForwardPassZDisabled; + + LayerMask m_OpaqueLayerMask = -1; + LayerMask m_TransparentLayerMask = -1; + StencilState m_DefaultStencilState = StencilState.defaultValue; + Camera.RenderRequestMode m_Mode; + + public RenderRequestRenderer(RenderRequestRendererData data) : base(data) + { + m_Mode = data.request.mode; + + var shaderTags = new[] {new ShaderTagId("DataExtraction")}; + + m_RenderOpaqueForwardPass = new DrawObjectsPass("Render Opaques", shaderTags, true, RenderPassEvent.BeforeRenderingOpaques, RenderQueueRange.opaque, m_OpaqueLayerMask, m_DefaultStencilState, 0 ); + m_RenderTransparentForwardPass = new DrawObjectsPass("Render Transparents", shaderTags, false, RenderPassEvent.BeforeRenderingTransparents, RenderQueueRange.transparent, m_TransparentLayerMask, m_DefaultStencilState, 0); + + // Selection mask requires separate passes for occluded objects + if (IsSelectionMaskRequest) + { + m_RenderOpaqueForwardPassZDisabled = new DrawObjectsPass("Render Opaques (Z disabled)", shaderTags, true, RenderPassEvent.BeforeRenderingOpaques, RenderQueueRange.opaque, m_OpaqueLayerMask, m_DefaultStencilState, 0 ); + m_RenderTransparentForwardPassZDisabled = new DrawObjectsPass("Render Transparents (Z disabled)", shaderTags, false, RenderPassEvent.BeforeRenderingTransparents, RenderQueueRange.transparent, m_TransparentLayerMask, m_DefaultStencilState, 0); + + var state = m_RenderOpaqueForwardPassZDisabled.RenderStateBlock; + state.rasterState = new RasterState(CullMode.Back, 0, -0.02f); + // There is no Z buffer for selection mask, use blending to make sure "unoccluded" (G = 1) values + // always remain on top. + state.blendState = new BlendState + { + blendState0 = new RenderTargetBlendState + { + colorBlendOperation = BlendOp.Max, + sourceColorBlendMode = BlendMode.One, + destinationColorBlendMode = BlendMode.One, + alphaBlendOperation = BlendOp.Max, + sourceAlphaBlendMode = BlendMode.One, + destinationAlphaBlendMode = BlendMode.One, + writeMask = ColorWriteMask.Green | ColorWriteMask.Blue | ColorWriteMask.Alpha, + } + }; + state.depthState = new DepthState {compareFunction = CompareFunction.Always, writeEnabled = false}; + state.mask = RenderStateMask.Everything; + m_RenderOpaqueForwardPassZDisabled.RenderStateBlock = state; + m_RenderTransparentForwardPassZDisabled.RenderStateBlock = state; + } + + List> values = new List> + { + new Tuple("UNITY_DataExtraction_Mode", (int)data.request.mode), + new Tuple("UNITY_DataExtraction_Space", (int)data.request.outputSpace), + }; + + m_RenderOpaqueForwardPass.SetAdditionalValues(values); + m_RenderTransparentForwardPass.SetAdditionalValues(values); + + if (IsSelectionMaskRequest) + { + List> valuesZDisabled = new List> + { + new Tuple("UNITY_DataExtraction_Mode", (int)data.request.mode), + new Tuple("UNITY_DataExtraction_Space", (int)data.request.outputSpace), + }; + + m_RenderOpaqueForwardPassZDisabled.SetAdditionalValues(valuesZDisabled); + m_RenderTransparentForwardPassZDisabled.SetAdditionalValues(valuesZDisabled); + } + } + + /// + public override void Setup(ScriptableRenderContext context, ref RenderingData renderingData) + { + if (IsSelectionMaskRequest) + { + EnqueuePass(m_RenderOpaqueForwardPassZDisabled); + EnqueuePass(m_RenderTransparentForwardPassZDisabled); + } + else + { + EnqueuePass(m_RenderOpaqueForwardPass); + EnqueuePass(m_RenderTransparentForwardPass); + } + } + + public override void FinishRendering(CommandBuffer cmd) + { + base.FinishRendering(cmd); + cmd.SetGlobalInt("UNITY_DataExtraction_Mode", 0); + cmd.SetGlobalInt("UNITY_DataExtraction_Space", 0); + } + + public bool IsSelectionMaskRequest => m_Mode == Camera.RenderRequestMode.SelectionMask; + } +} diff --git a/com.unity.render-pipelines.universal/Runtime/RenderRequests.cs.meta b/com.unity.render-pipelines.universal/Runtime/RenderRequests.cs.meta new file mode 100644 index 00000000000..d77995d370c --- /dev/null +++ b/com.unity.render-pipelines.universal/Runtime/RenderRequests.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 043b52e37a9f484eb91eaccca2f853f3 +timeCreated: 1620303141 \ No newline at end of file diff --git a/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs b/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs index 2a82c813069..d77e99440d2 100644 --- a/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs +++ b/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs @@ -223,7 +223,7 @@ protected override void ProcessRenderRequests(ScriptableRenderContext renderCont camera.targetTexture = cameraTarget; } - void RenderWithMode(ScriptableRenderContext renderContext, Camera camera, Camera.RenderRequest renderRequest) + private static void RenderWithMode(ScriptableRenderContext renderContext, Camera camera, Camera.RenderRequest renderRequest) { camera.targetTexture = renderRequest.result; @@ -237,7 +237,7 @@ void RenderWithMode(ScriptableRenderContext renderContext, Camera camera, Camera return; } - //@TODO: What crazy sauce is this? + //@TODO: What crazy sauce is this? Perhaps this should be stored in a member and not recreated each time? var data = ScriptableObject.CreateInstance(); data.request = renderRequest; InitializeCameraData(camera, additionalCameraData, true, out var cameraData); @@ -247,113 +247,6 @@ void RenderWithMode(ScriptableRenderContext renderContext, Camera camera, Camera Object.DestroyImmediate(data); } - public class RenderRequestRendererData : ScriptableRendererData - { - protected override ScriptableRenderer Create() - { - return new RenderRequestRenderer(this); - } - - public Camera.RenderRequest request { get; set; } - } - - class RenderRequestRenderer : ScriptableRenderer - { - DrawObjectsPass m_RenderOpaqueForwardPass; - DrawObjectsPass m_RenderTransparentForwardPass; - DrawObjectsPass m_RenderOpaqueForwardPassZDisabled; - DrawObjectsPass m_RenderTransparentForwardPassZDisabled; - - LayerMask m_OpaqueLayerMask = -1; - LayerMask m_TransparentLayerMask = -1; - StencilState m_DefaultStencilState = StencilState.defaultValue; - Camera.RenderRequestMode m_Mode; - - public RenderRequestRenderer(RenderRequestRendererData data) : base(data) - { - m_Mode = data.request.mode; - - var shaderTags = new[] {new ShaderTagId("DataExtraction")}; - - m_RenderOpaqueForwardPass = new DrawObjectsPass("Render Opaques", shaderTags, true, RenderPassEvent.BeforeRenderingOpaques, RenderQueueRange.opaque, m_OpaqueLayerMask, m_DefaultStencilState, 0 ); - m_RenderTransparentForwardPass = new DrawObjectsPass("Render Transparents", shaderTags, false, RenderPassEvent.BeforeRenderingTransparents, RenderQueueRange.transparent, m_TransparentLayerMask, m_DefaultStencilState, 0); - - // Selection mask requires separate passes for occluded objects - if (IsSelectionMaskRequest) - { - m_RenderOpaqueForwardPassZDisabled = new DrawObjectsPass("Render Opaques (Z disabled)", shaderTags, true, RenderPassEvent.BeforeRenderingOpaques, RenderQueueRange.opaque, m_OpaqueLayerMask, m_DefaultStencilState, 0 ); - m_RenderTransparentForwardPassZDisabled = new DrawObjectsPass("Render Transparents (Z disabled)", shaderTags, false, RenderPassEvent.BeforeRenderingTransparents, RenderQueueRange.transparent, m_TransparentLayerMask, m_DefaultStencilState, 0); - - var state = m_RenderOpaqueForwardPassZDisabled.RenderStateBlock; - state.rasterState = new RasterState(CullMode.Back, 0, -0.02f); - // There is no Z buffer for selection mask, use blending to make sure "unoccluded" (G = 1) values - // always remain on top. - state.blendState = new BlendState - { - blendState0 = new RenderTargetBlendState - { - colorBlendOperation = BlendOp.Max, - sourceColorBlendMode = BlendMode.One, - destinationColorBlendMode = BlendMode.One, - alphaBlendOperation = BlendOp.Max, - sourceAlphaBlendMode = BlendMode.One, - destinationAlphaBlendMode = BlendMode.One, - writeMask = ColorWriteMask.Green | ColorWriteMask.Blue | ColorWriteMask.Alpha, - } - }; - state.depthState = new DepthState {compareFunction = CompareFunction.Always, writeEnabled = false}; - state.mask = RenderStateMask.Everything; - m_RenderOpaqueForwardPassZDisabled.RenderStateBlock = state; - m_RenderTransparentForwardPassZDisabled.RenderStateBlock = state; - } - - List> values = new List> - { - new Tuple("UNITY_DataExtraction_Mode", (int)data.request.mode), - new Tuple("UNITY_DataExtraction_Space", (int)data.request.outputSpace), - }; - - m_RenderOpaqueForwardPass.SetAdditionalValues(values); - m_RenderTransparentForwardPass.SetAdditionalValues(values); - - if (IsSelectionMaskRequest) - { - List> valuesZDisabled = new List> - { - new Tuple("UNITY_DataExtraction_Mode", (int)data.request.mode), - new Tuple("UNITY_DataExtraction_Space", (int)data.request.outputSpace), - }; - - m_RenderOpaqueForwardPassZDisabled.SetAdditionalValues(valuesZDisabled); - m_RenderTransparentForwardPassZDisabled.SetAdditionalValues(valuesZDisabled); - } - } - - /// - public override void Setup(ScriptableRenderContext context, ref RenderingData renderingData) - { - if (IsSelectionMaskRequest) - { - EnqueuePass(m_RenderOpaqueForwardPassZDisabled); - EnqueuePass(m_RenderTransparentForwardPassZDisabled); - } - else - { - EnqueuePass(m_RenderOpaqueForwardPass); - EnqueuePass(m_RenderTransparentForwardPass); - } - } - - public override void FinishRendering(CommandBuffer cmd) - { - base.FinishRendering(cmd); - cmd.SetGlobalInt("UNITY_DataExtraction_Mode", 0); - cmd.SetGlobalInt("UNITY_DataExtraction_Space", 0); - } - - public bool IsSelectionMaskRequest => m_Mode == Camera.RenderRequestMode.SelectionMask; - } - #if UNITY_2021_1_OR_NEWER protected override void Render(ScriptableRenderContext renderContext, Camera[] cameras) { From 3bc9a111e9a4caafb62985869fb15b233698426b Mon Sep 17 00:00:00 2001 From: Jussi Knuuttila Date: Thu, 6 May 2021 16:03:42 +0300 Subject: [PATCH 17/30] Split selection masks into a separate renderer class since they had a different code path. --- .../Runtime/RenderRequests.cs | 128 ++++++++++-------- 1 file changed, 73 insertions(+), 55 deletions(-) diff --git a/com.unity.render-pipelines.universal/Runtime/RenderRequests.cs b/com.unity.render-pipelines.universal/Runtime/RenderRequests.cs index d51f87a878d..97a39e81a8c 100644 --- a/com.unity.render-pipelines.universal/Runtime/RenderRequests.cs +++ b/com.unity.render-pipelines.universal/Runtime/RenderRequests.cs @@ -8,7 +8,13 @@ internal class RenderRequestRendererData : ScriptableRendererData { protected override ScriptableRenderer Create() { - return new RenderRequestRenderer(this); + switch (request.mode) + { + case Camera.RenderRequestMode.SelectionMask: + return new RenderRequestSelectionMaskRenderer(this); + default: + return new RenderRequestRenderer(this); + } } public Camera.RenderRequest request { get; set; } @@ -18,52 +24,18 @@ internal class RenderRequestRenderer : ScriptableRenderer { DrawObjectsPass m_RenderOpaqueForwardPass; DrawObjectsPass m_RenderTransparentForwardPass; - DrawObjectsPass m_RenderOpaqueForwardPassZDisabled; - DrawObjectsPass m_RenderTransparentForwardPassZDisabled; LayerMask m_OpaqueLayerMask = -1; LayerMask m_TransparentLayerMask = -1; StencilState m_DefaultStencilState = StencilState.defaultValue; - Camera.RenderRequestMode m_Mode; public RenderRequestRenderer(RenderRequestRendererData data) : base(data) { - m_Mode = data.request.mode; - var shaderTags = new[] {new ShaderTagId("DataExtraction")}; m_RenderOpaqueForwardPass = new DrawObjectsPass("Render Opaques", shaderTags, true, RenderPassEvent.BeforeRenderingOpaques, RenderQueueRange.opaque, m_OpaqueLayerMask, m_DefaultStencilState, 0 ); m_RenderTransparentForwardPass = new DrawObjectsPass("Render Transparents", shaderTags, false, RenderPassEvent.BeforeRenderingTransparents, RenderQueueRange.transparent, m_TransparentLayerMask, m_DefaultStencilState, 0); - // Selection mask requires separate passes for occluded objects - if (IsSelectionMaskRequest) - { - m_RenderOpaqueForwardPassZDisabled = new DrawObjectsPass("Render Opaques (Z disabled)", shaderTags, true, RenderPassEvent.BeforeRenderingOpaques, RenderQueueRange.opaque, m_OpaqueLayerMask, m_DefaultStencilState, 0 ); - m_RenderTransparentForwardPassZDisabled = new DrawObjectsPass("Render Transparents (Z disabled)", shaderTags, false, RenderPassEvent.BeforeRenderingTransparents, RenderQueueRange.transparent, m_TransparentLayerMask, m_DefaultStencilState, 0); - - var state = m_RenderOpaqueForwardPassZDisabled.RenderStateBlock; - state.rasterState = new RasterState(CullMode.Back, 0, -0.02f); - // There is no Z buffer for selection mask, use blending to make sure "unoccluded" (G = 1) values - // always remain on top. - state.blendState = new BlendState - { - blendState0 = new RenderTargetBlendState - { - colorBlendOperation = BlendOp.Max, - sourceColorBlendMode = BlendMode.One, - destinationColorBlendMode = BlendMode.One, - alphaBlendOperation = BlendOp.Max, - sourceAlphaBlendMode = BlendMode.One, - destinationAlphaBlendMode = BlendMode.One, - writeMask = ColorWriteMask.Green | ColorWriteMask.Blue | ColorWriteMask.Alpha, - } - }; - state.depthState = new DepthState {compareFunction = CompareFunction.Always, writeEnabled = false}; - state.mask = RenderStateMask.Everything; - m_RenderOpaqueForwardPassZDisabled.RenderStateBlock = state; - m_RenderTransparentForwardPassZDisabled.RenderStateBlock = state; - } - List> values = new List> { new Tuple("UNITY_DataExtraction_Mode", (int)data.request.mode), @@ -72,33 +44,81 @@ public RenderRequestRenderer(RenderRequestRendererData data) : base(data) m_RenderOpaqueForwardPass.SetAdditionalValues(values); m_RenderTransparentForwardPass.SetAdditionalValues(values); + } + + /// + public override void Setup(ScriptableRenderContext context, ref RenderingData renderingData) + { + EnqueuePass(m_RenderOpaqueForwardPass); + EnqueuePass(m_RenderTransparentForwardPass); + } - if (IsSelectionMaskRequest) + public override void FinishRendering(CommandBuffer cmd) + { + base.FinishRendering(cmd); + cmd.SetGlobalInt("UNITY_DataExtraction_Mode", 0); + cmd.SetGlobalInt("UNITY_DataExtraction_Space", 0); + } + } + + internal class RenderRequestSelectionMaskRenderer : ScriptableRenderer + { + DrawObjectsPass m_RenderOpaqueForwardPassZDisabled; + DrawObjectsPass m_RenderTransparentForwardPassZDisabled; + + LayerMask m_OpaqueLayerMask = -1; + LayerMask m_TransparentLayerMask = -1; + StencilState m_DefaultStencilState = StencilState.defaultValue; + + private const float kSelectionZFudgeFactor = -0.02f; + + public RenderRequestSelectionMaskRenderer(RenderRequestRendererData data) : base(data) + { + Debug.Assert(data.request.mode == Camera.RenderRequestMode.SelectionMask, "RenderRequestSelectionMaskRenderer should only be used with RenderRequestMode.SelectionMask"); + + var shaderTags = new[] {new ShaderTagId("DataExtraction")}; + + // There is no Z buffer for selection mask, use blending to make sure "unoccluded" (G = 1) values + // always remain on top when both occluded and unoccluded objects overlap. + + m_RenderOpaqueForwardPassZDisabled = new DrawObjectsPass("Render Opaques (Z disabled)", shaderTags, true, RenderPassEvent.BeforeRenderingOpaques, RenderQueueRange.opaque, m_OpaqueLayerMask, m_DefaultStencilState, 0 ); + m_RenderTransparentForwardPassZDisabled = new DrawObjectsPass("Render Transparents (Z disabled)", shaderTags, false, RenderPassEvent.BeforeRenderingTransparents, RenderQueueRange.transparent, m_TransparentLayerMask, m_DefaultStencilState, 0); + + var state = m_RenderOpaqueForwardPassZDisabled.RenderStateBlock; + state.rasterState = new RasterState(CullMode.Back, 0, kSelectionZFudgeFactor); + state.blendState = new BlendState { - List> valuesZDisabled = new List> + blendState0 = new RenderTargetBlendState { - new Tuple("UNITY_DataExtraction_Mode", (int)data.request.mode), - new Tuple("UNITY_DataExtraction_Space", (int)data.request.outputSpace), - }; + colorBlendOperation = BlendOp.Max, + sourceColorBlendMode = BlendMode.One, + destinationColorBlendMode = BlendMode.One, + alphaBlendOperation = BlendOp.Max, + sourceAlphaBlendMode = BlendMode.One, + destinationAlphaBlendMode = BlendMode.One, + writeMask = ColorWriteMask.Green | ColorWriteMask.Blue | ColorWriteMask.Alpha, + } + }; + state.depthState = new DepthState {compareFunction = CompareFunction.Always, writeEnabled = false}; + state.mask = RenderStateMask.Everything; + m_RenderOpaqueForwardPassZDisabled.RenderStateBlock = state; + m_RenderTransparentForwardPassZDisabled.RenderStateBlock = state; - m_RenderOpaqueForwardPassZDisabled.SetAdditionalValues(valuesZDisabled); - m_RenderTransparentForwardPassZDisabled.SetAdditionalValues(valuesZDisabled); - } + List> values = new List> + { + new Tuple("UNITY_DataExtraction_Mode", (int)data.request.mode), + new Tuple("UNITY_DataExtraction_Space", (int)data.request.outputSpace), + }; + + m_RenderOpaqueForwardPassZDisabled.SetAdditionalValues(values); + m_RenderTransparentForwardPassZDisabled.SetAdditionalValues(values); } /// public override void Setup(ScriptableRenderContext context, ref RenderingData renderingData) { - if (IsSelectionMaskRequest) - { - EnqueuePass(m_RenderOpaqueForwardPassZDisabled); - EnqueuePass(m_RenderTransparentForwardPassZDisabled); - } - else - { - EnqueuePass(m_RenderOpaqueForwardPass); - EnqueuePass(m_RenderTransparentForwardPass); - } + EnqueuePass(m_RenderOpaqueForwardPassZDisabled); + EnqueuePass(m_RenderTransparentForwardPassZDisabled); } public override void FinishRendering(CommandBuffer cmd) @@ -107,7 +127,5 @@ public override void FinishRendering(CommandBuffer cmd) cmd.SetGlobalInt("UNITY_DataExtraction_Mode", 0); cmd.SetGlobalInt("UNITY_DataExtraction_Space", 0); } - - public bool IsSelectionMaskRequest => m_Mode == Camera.RenderRequestMode.SelectionMask; } } From 0515bd7ac29bda4e1a79988f58bde7c819d93e0e Mon Sep 17 00:00:00 2001 From: Jussi Knuuttila Date: Thu, 6 May 2021 20:19:15 +0300 Subject: [PATCH 18/30] Add missing software Z-buffer declarations for HLSL files and templates which affect selection outline passes. --- .../Editor/Material/ShaderGraph/Templates/ShaderPass.template | 2 ++ .../VFXGraph/Shaders/Templates/Sphere/PassDepthOrMV.template | 2 ++ .../Editor/VFXGraph/Shaders/VFXPasses.template | 2 ++ .../Runtime/Material/AxF/AxFProperties.hlsl | 2 ++ .../Runtime/Material/TerrainLit/TerrainLitData.hlsl | 2 ++ .../Shaders/ParticleDecals/Pass.template | 2 ++ com.unity.visualeffectgraph/Shaders/VFXParticleCommon.template | 2 ++ 7 files changed, 14 insertions(+) diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/Templates/ShaderPass.template b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/Templates/ShaderPass.template index c5abaa8c21b..b90ba53d2a5 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/Templates/ShaderPass.template +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/Templates/ShaderPass.template @@ -135,6 +135,8 @@ Pass #ifdef SCENESELECTIONPASS int _ObjectId; int _PassValue; + TEXTURE2D(unity_EditorViz_DepthBuffer); + SAMPLER(sampler_unity_EditorViz_DepthBuffer); #endif // Includes diff --git a/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Shaders/Templates/Sphere/PassDepthOrMV.template b/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Shaders/Templates/Sphere/PassDepthOrMV.template index d682634471f..f638bc2c4cd 100644 --- a/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Shaders/Templates/Sphere/PassDepthOrMV.template +++ b/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Shaders/Templates/Sphere/PassDepthOrMV.template @@ -34,6 +34,8 @@ ${VFXIncludeRP("VFXLit.template")} #if VFX_PASSDEPTH == VFX_PASSDEPTH_SELECTION int _ObjectId; int _PassValue; +TEXTURE2D(unity_EditorViz_DepthBuffer); +SAMPLER(sampler_unity_EditorViz_DepthBuffer); #endif #pragma fragment frag diff --git a/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Shaders/VFXPasses.template b/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Shaders/VFXPasses.template index 66b5144b32b..6ec629ad01a 100644 --- a/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Shaders/VFXPasses.template +++ b/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Shaders/VFXPasses.template @@ -40,6 +40,8 @@ ${SHADERGRAPH_PIXEL_CODE_DEPTHONLY} #if VFX_PASSDEPTH == VFX_PASSDEPTH_SELECTION int _ObjectId; int _PassValue; +TEXTURE2D(unity_EditorViz_DepthBuffer); +SAMPLER(sampler_unity_EditorViz_DepthBuffer); #endif #pragma fragment frag diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxFProperties.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxFProperties.hlsl index aab094c1a09..76fdd29d0e4 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxFProperties.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxFProperties.hlsl @@ -138,5 +138,7 @@ float3 _EmissionColor; int _ObjectId; int _PassValue; float4 _SelectionID; +TEXTURE2D(unity_EditorViz_DepthBuffer); +SAMPLER(sampler_unity_EditorViz_DepthBuffer); CBUFFER_END diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/TerrainLit/TerrainLitData.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/TerrainLit/TerrainLitData.hlsl index 8a65550acff..4f91fed6c1d 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/TerrainLit/TerrainLitData.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/TerrainLit/TerrainLitData.hlsl @@ -32,6 +32,8 @@ CBUFFER_START(UnityTerrain) #ifdef SCENESELECTIONPASS int _ObjectId; int _PassValue; + TEXTURE2D(unity_EditorViz_DepthBuffer); + SAMPLER(sampler_unity_EditorViz_DepthBuffer); #endif CBUFFER_END diff --git a/com.unity.visualeffectgraph/Shaders/ParticleDecals/Pass.template b/com.unity.visualeffectgraph/Shaders/ParticleDecals/Pass.template index 99be7d009b2..bc236b8ced5 100644 --- a/com.unity.visualeffectgraph/Shaders/ParticleDecals/Pass.template +++ b/com.unity.visualeffectgraph/Shaders/ParticleDecals/Pass.template @@ -91,6 +91,8 @@ ${VFXInclude("Shaders/ParticleHexahedron/Pass.template")} #if VFX_PASSDEPTH == VFX_PASSDEPTH_SELECTION int _ObjectId; int _PassValue; +TEXTURE2D(unity_EditorViz_DepthBuffer); +SAMPLER(sampler_unity_EditorViz_DepthBuffer); #endif #pragma fragment frag diff --git a/com.unity.visualeffectgraph/Shaders/VFXParticleCommon.template b/com.unity.visualeffectgraph/Shaders/VFXParticleCommon.template index 2d4c680c282..0d8c4b5c138 100644 --- a/com.unity.visualeffectgraph/Shaders/VFXParticleCommon.template +++ b/com.unity.visualeffectgraph/Shaders/VFXParticleCommon.template @@ -169,6 +169,8 @@ ${SHADERGRAPH_PIXEL_CODE_DEPTHONLY} #if VFX_PASSDEPTH == VFX_PASSDEPTH_SELECTION int _ObjectId; int _PassValue; +TEXTURE2D(unity_EditorViz_DepthBuffer); +SAMPLER(sampler_unity_EditorViz_DepthBuffer); #endif #pragma fragment frag From 7427e2629b721bdd3bf01d7d84169c0e27ebcc18 Mon Sep 17 00:00:00 2001 From: Jussi Knuuttila Date: Thu, 6 May 2021 20:31:08 +0300 Subject: [PATCH 19/30] Removed PickingSpaceTransforms.hlsl, it is no longer necessary. --- .../ShaderLibrary/SpaceTransforms.hlsl | 2 - .../Decal/ShaderGraph/DecalSubTarget.cs | 1 - .../Material/ShaderGraph/HDShaderPasses.cs | 1 - .../Editor/Material/ShaderGraph/HDTarget.cs | 1 - .../Runtime/Material/AxF/AxF.shader | 1 - .../Runtime/Material/Decal/Decal.shader | 1 - .../Material/LayeredLit/LayeredLit.shader | 1 - .../LayeredLit/LayeredLitTessellation.shader | 1 - .../Runtime/Material/Lit/Lit.shader | 1 - .../Material/Lit/LitTessellation.shader | 1 - .../ShaderLibrary/PickingSpaceTransforms.hlsl | 73 ------------------- .../PickingSpaceTransforms.hlsl.meta | 10 --- 12 files changed, 94 deletions(-) delete mode 100644 com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl delete mode 100644 com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl.meta diff --git a/com.unity.render-pipelines.core/ShaderLibrary/SpaceTransforms.hlsl b/com.unity.render-pipelines.core/ShaderLibrary/SpaceTransforms.hlsl index c1484607d35..3c4d47b74d2 100644 --- a/com.unity.render-pipelines.core/ShaderLibrary/SpaceTransforms.hlsl +++ b/com.unity.render-pipelines.core/ShaderLibrary/SpaceTransforms.hlsl @@ -1,8 +1,6 @@ #ifndef UNITY_SPACE_TRANSFORMS_INCLUDED #define UNITY_SPACE_TRANSFORMS_INCLUDED -// Caution: For HDRP, adding a function in this file requires adding the appropriate #define in PickingSpaceTransforms.hlsl - // Return the PreTranslated ObjectToWorld Matrix (i.e matrix with _WorldSpaceCameraPos apply to it if we use camera relative rendering) float4x4 GetObjectToWorldMatrix() { diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalSubTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalSubTarget.cs index ce6de387b40..321dea70b46 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalSubTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalSubTarget.cs @@ -586,7 +586,6 @@ static class DecalIncludes { kFunctions, IncludeLocation.Pregraph }, { CoreIncludes.MinimalCorePregraph }, { kDecal, IncludeLocation.Pregraph }, - { CoreIncludes.kPickingSpaceTransforms, IncludeLocation.Pregraph }, { kPassDecal, IncludeLocation.Postgraph }, }; } diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs index bbba4254347..4caf31dcb9d 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs @@ -101,7 +101,6 @@ IncludeCollection GenerateIncludes() includes.Add(CoreIncludes.kPassPlaceholder, IncludeLocation.Pregraph); includes.Add(CoreIncludes.CoreUtility); includes.Add(CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph); - includes.Add(CoreIncludes.kPickingSpaceTransforms, IncludeLocation.Pregraph); includes.Add(CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph); return includes; diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDTarget.cs index 453c67fe165..419b13f7be0 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDTarget.cs @@ -879,7 +879,6 @@ static class CoreIncludes public const string kFragInputs = "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl"; public const string kMaterial = "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"; public const string kDebugDisplay = "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl"; - public const string kPickingSpaceTransforms = "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl"; // CoreUtility public const string kBuiltInUtilities = "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl"; diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxF.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxF.shader index 36e7e1c361a..54d26784a38 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxF.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxF.shader @@ -237,7 +237,6 @@ Shader "HDRP/AxF" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxF.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/ShaderPass/AxFDepthPass.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxFData.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl" #pragma vertex Vert diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/Decal.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/Decal.shader index 29620bcf231..e18cab3a0d2 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/Decal.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/Decal.shader @@ -287,7 +287,6 @@ Shader "HDRP/Decal" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalProperties.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/Decal.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/ShaderPass/DecalSharePass.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDecal.hlsl" #pragma editor_sync_compilation diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLit.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLit.shader index 0b5fe40941e..6123bdd834a 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLit.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLit.shader @@ -559,7 +559,6 @@ Shader "HDRP/LayeredLit" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitDepthPass.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLitData.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl" #pragma vertex Vert diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLitTessellation.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLitTessellation.shader index ece9c4ca7b3..e606c7f4b78 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLitTessellation.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLitTessellation.shader @@ -570,7 +570,6 @@ Shader "HDRP/LayeredLitTessellation" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitDepthPass.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLitData.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl" #pragma vertex Vert diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.shader index 9264518dd5e..70904306378 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.shader @@ -380,7 +380,6 @@ Shader "HDRP/Lit" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitDepthPass.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitData.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl" #pragma vertex Vert diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitTessellation.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitTessellation.shader index 7a3a9b4993d..21be3d8b1b7 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitTessellation.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitTessellation.shader @@ -385,7 +385,6 @@ Shader "HDRP/LitTessellation" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitDepthPass.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitData.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl" #pragma vertex Vert diff --git a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl deleted file mode 100644 index 1264c10e415..00000000000 --- a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl +++ /dev/null @@ -1,73 +0,0 @@ -#if 0 -// This file overrides a large amount of macros to be compatible with the old -// Unity C++ picking. It is no longer necessary with the new SRP based picking. - -#ifndef UNITY_PICKING_SPACE_TRANSFORMS_INCLUDED -#define UNITY_PICKING_SPACE_TRANSFORMS_INCLUDED - -#ifdef SCENEPICKINGPASS - -// The picking pass uses custom matrices defined directly from the c++ -// So we have to redefine the space transform functions to overwrite the used matrices - -#undef SHADEROPTIONS_CAMERA_RELATIVE_RENDERING - -// Define the correct matrices -#undef unity_ObjectToWorld -#undef unity_MatrixVP -float4x4 unity_MatrixV; -float4x4 unity_MatrixVP; -float4x4 glstate_matrix_projection; - -#undef UNITY_MATRIX_M -#define UNITY_MATRIX_M unity_ObjectToWorld - -#undef UNITY_MATRIX_I_M -#define UNITY_MATRIX_I_M Inverse(unity_ObjectToWorld) - -#undef UNITY_MATRIX_V -#define UNITY_MATRIX_V unity_MatrixV - -#undef UNITY_MATRIX_VP -#define UNITY_MATRIX_VP unity_MatrixVP - -#undef UNITY_MATRIX_P -#define UNITY_MATRIX_P glstate_matrix_projection - - -// Overwrite the SpaceTransforms functions -#define GetObjectToWorldMatrix GetObjectToWorldMatrix_Picking -#define GetWorldToObjectMatrix GetWorldToObjectMatrix_Picking -#define GetWorldToViewMatrix GetWorldToViewMatrix_Picking -#define GetWorldToHClipMatrix GetWorldToHClipMatrix_Picking -#define GetViewToHClipMatrix GetViewToHClipMatrix_Picking -#define GetAbsolutePositionWS GetAbsolutePositionWS_Picking -#define GetCameraRelativePositionWS GetCameraRelativePositionWS_Picking -#define GetOddNegativeScale GetOddNegativeScale_Picking -#define TransformObjectToWorld TransformObjectToWorld_Picking -#define TransformWorldToObject TransformWorldToObject_Picking -#define TransformWorldToView TransformWorldToView_Picking -#define TransformObjectToHClip TransformObjectToHClip_Picking -#define TransformWorldToHClip TransformWorldToHClip_Picking -#define TransformWViewToHClip TransformWViewToHClip_Picking -#define TransformObjectToWorldDir TransformObjectToWorldDir_Picking -#define TransformWorldToObjectDir TransformWorldToObjectDir_Picking -#define TransformWorldToViewDir TransformWorldToViewDir_Picking -#define TransformWorldToHClipDir TransformWorldToHClipDir_Picking -#define TransformObjectToWorldNormal TransformObjectToWorldNormal_Picking -#define TransformWorldToObjectNormal TransformWorldToObjectNormal_Picking -#define CreateTangentToWorld CreateTangentToWorld_Picking -#define TransformTangentToWorld TransformTangentToWorld_Picking -#define TransformWorldToTangent TransformWorldToTangent_Picking -#define TransformTangentToObject TransformTangentToObject_Picking -#define TransformObjectToTangent TransformObjectToTangent_Picking - - -// Redefine the functions using the new macros -#undef UNITY_SPACE_TRANSFORMS_INCLUDED -#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/SpaceTransforms.hlsl" - - -#endif -#endif -#endif diff --git a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl.meta b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl.meta deleted file mode 100644 index 6af1b1fc268..00000000000 --- a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl.meta +++ /dev/null @@ -1,10 +0,0 @@ -fileFormatVersion: 2 -guid: 07878c52127f8a248be207c0fb1b6e77 -ShaderImporter: - externalObjects: {} - defaultTextures: [] - nonModifiableTextures: [] - preprocessorOverride: 0 - userData: - assetBundleName: - assetBundleVariant: From 57f501d25bdd021832ba5accec494e6742f04c74 Mon Sep 17 00:00:00 2001 From: Jussi Knuuttila Date: Fri, 7 May 2021 12:54:08 +0300 Subject: [PATCH 20/30] Fixed some shader warnings. --- .../Editor/ShaderGraph/Includes/PBRForwardPass.hlsl | 3 ++- .../ShaderLibrary/DataExtraction.hlsl | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/PBRForwardPass.hlsl b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/PBRForwardPass.hlsl index 4d2cdbda2da..adc9a65a8c3 100644 --- a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/PBRForwardPass.hlsl +++ b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/PBRForwardPass.hlsl @@ -161,7 +161,8 @@ half4 fragExtraction(PackedVaryings packedInput) : SV_TARGET extraction.occlusion = surfaceDescription.Occlusion; extraction.emission = surfaceDescription.Emission.xyz; - return OutputExtraction(extraction); + // half precision will not preserve things like IDs which require exact results. + return half4(OutputExtraction(extraction)); } diff --git a/com.unity.render-pipelines.universal/ShaderLibrary/DataExtraction.hlsl b/com.unity.render-pipelines.universal/ShaderLibrary/DataExtraction.hlsl index 1b9016002b8..2f48d35c423 100644 --- a/com.unity.render-pipelines.universal/ShaderLibrary/DataExtraction.hlsl +++ b/com.unity.render-pipelines.universal/ShaderLibrary/DataExtraction.hlsl @@ -31,18 +31,25 @@ float4 OutputExtraction(ExtractionInputs inputs) // Outline mask is the most performance sensitive (rendered each frame when selection is active), // so it is tested first. + // For some weird reason, using a direct return inside the branch causes a warning about + // a potentially uninitialized variable, so use an explicitly initialized return value variable + // to avoid it. + float4 selectionMask = 0; if (UNITY_DataExtraction_Mode == RENDER_OUTLINE_MASK) { // Red channel = unique identifier, can be used to separate groups of objects from each other // to get outlines between them. // Green channel = occluded behind depth buffer (0) or not occluded (1) // Blue channel = always 1 = not cleared to zero = there's an outlined object at this pixel - return ComputeSelectionMask( + selectionMask = ComputeSelectionMask( 0, // Object unique identifier currently unused ComputeNormalizedDeviceCoordinatesWithZ(inputs.positionWS, UNITY_MATRIX_VP), TEXTURE2D_ARGS(unity_EditorViz_DepthBuffer, sampler_unity_EditorViz_DepthBuffer)); } + if (UNITY_DataExtraction_Mode == RENDER_OUTLINE_MASK) + return selectionMask; + #ifdef _SPECULAR_SETUP specular = inputs.specular; diffuse = inputs.baseColor; From 582826e62fbd69fe32e862f4a95448ef74b36fd0 Mon Sep 17 00:00:00 2001 From: Jussi Knuuttila Date: Fri, 4 Jun 2021 16:31:24 +0300 Subject: [PATCH 21/30] Remove unused GetDebugViewTargetBuffer method to reduce diff from master --- .../Runtime/RenderPipeline/HDRenderPipeline.cs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs index 3f4c23855a5..22ec29eecea 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs @@ -2984,7 +2984,7 @@ void Callback(CommandBuffer c, HDCamera cam) RenderCustomPass(renderContext, cmd, hdCamera, customPassCullingResults, CustomPassInjectionPoint.BeforePostProcess, aovRequest, aovCustomPassBuffers); if (aovRequest.isValid) - aovRequest.PushCameraTexture(cmd, AOVBuffers.Color, hdCamera, GetDebugViewTargetBuffer(), aovBuffers); + aovRequest.PushCameraTexture(cmd, AOVBuffers.Color, hdCamera, m_CameraColorBuffer, aovBuffers); RenderTargetIdentifier postProcessDest = HDUtils.PostProcessIsFinalPass(hdCamera) ? target.id : m_IntermediateAfterPostProcessBuffer; RenderPostProcess(cullingResults, hdCamera, postProcessDest, renderContext, cmd); @@ -4276,8 +4276,7 @@ void RenderDebugViewMaterial(CullingResults cull, HDCamera hdCamera, ScriptableR { // When rendering debug material we shouldn't rely on a depth prepass for optimizing the alpha clip test. As it is control on the material inspector side // we must override the state here. - var debugViewTargetBuffer = GetDebugViewTargetBuffer(); - CoreUtils.SetRenderTarget(cmd, debugViewTargetBuffer, m_SharedRTManager.GetDepthStencilBuffer(), ClearFlag.All, Color.clear); + CoreUtils.SetRenderTarget(cmd, m_CameraColorBuffer, m_SharedRTManager.GetDepthStencilBuffer(), ClearFlag.All, Color.clear); // [case 1273223] When the camera is stacked on top of another one, we need to clear the debug view RT using the data from the previous camera in the stack var clearColorTexture = Compositor.CompositionManager.GetClearTextureForStackedCamera(hdCamera); // returns null if is not a stacked camera @@ -4298,12 +4297,6 @@ void RenderDebugViewMaterial(CullingResults cull, HDCamera hdCamera, ScriptableR } } - private RTHandle GetDebugViewTargetBuffer() - { - // Used to contain a test whether to return a float16 target, but no longer needed - return m_CameraColorBuffer; - } - struct TransparencyOverdrawParameters { public ShaderVariablesDebugDisplay constantBuffer; From c650a6bf740d036276d09d5d798d728d2249b353 Mon Sep 17 00:00:00 2001 From: Jussi Knuuttila Date: Fri, 4 Jun 2021 17:49:42 +0300 Subject: [PATCH 22/30] Rename a variable with a typo --- .../Runtime/Debug/DebugDisplay.cs | 2 +- .../Runtime/RenderPipeline/HDRenderPipeline.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs index 34c025e7f73..39d21c1313d 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs @@ -40,7 +40,7 @@ unsafe struct ShaderVariablesDebugDisplay public int _DebugSingleShadowIndex; public int _DebugProbeVolumeMode; - public int _DebugAllowsRGBConversion; + public int _DebugAllowRGBConversion; public Vector3 _DebugDisplayPad0; } diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs index 22ec29eecea..b0ff1f053e6 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs @@ -5307,7 +5307,7 @@ unsafe void ApplyDebugDisplaySettings(HDCamera hdCamera, CommandBuffer cmd) cb._ColorPickerMode = (int)m_CurrentDebugDisplaySettings.GetDebugColorPickerMode(); cb._DebugFullScreenMode = (int)m_CurrentDebugDisplaySettings.data.fullScreenDebugMode; cb._DebugProbeVolumeMode = (int)m_CurrentDebugDisplaySettings.GetProbeVolumeDebugMode(); - cb._DebugAllowsRGBConversion = m_CurrentDebugDisplaySettings.GetAllowSRGBConversion() ? 1 : 0; + cb._DebugAllowRGBConversion = m_CurrentDebugDisplaySettings.GetAllowSRGBConversion() ? 1 : 0; #if UNITY_EDITOR cb._MatcapMixAlbedo = HDRenderPipelinePreferences.matcapViewMixAlbedo ? 1 : 0; From 5c4ea9686202b459f4b2be35264e702b4b92684a Mon Sep 17 00:00:00 2001 From: Jussi Knuuttila Date: Fri, 4 Jun 2021 18:27:15 +0300 Subject: [PATCH 23/30] Move picking ID packing to Packing.hlsl --- .../ShaderLibrary/DataExtraction.hlsl | 15 ++------------- .../ShaderLibrary/Packing.hlsl | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/com.unity.render-pipelines.core/ShaderLibrary/DataExtraction.hlsl b/com.unity.render-pipelines.core/ShaderLibrary/DataExtraction.hlsl index 446529473c4..6519b3f3a15 100644 --- a/com.unity.render-pipelines.core/ShaderLibrary/DataExtraction.hlsl +++ b/com.unity.render-pipelines.core/ShaderLibrary/DataExtraction.hlsl @@ -1,6 +1,8 @@ #ifndef UNITY_DATA_EXTRACTION_INCLUDED #define UNITY_DATA_EXTRACTION_INCLUDED +#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Packing.hlsl" + // These correspond to UnityEngine.Camera.RenderRequestMode enum values #define RENDER_OBJECT_ID 1 #define RENDER_DEPTH 2 @@ -36,18 +38,5 @@ float4 ComputeSelectionMask(float objectGroupId, float3 ndcWithZ, TEXTURE2D_PARA return float4(objectGroupId, occluded ? 0 : 1, 1, 1); } -float4 PackId32ToRGBA8888(uint id32) -{ - uint b0 = (id32 >> 0) & 0xff; - uint b1 = (id32 >> 8) & 0xff; - uint b2 = (id32 >> 16) & 0xff; - uint b3 = (id32 >> 24) & 0xff; - float f0 = (float)b0 / 255.0f; - float f1 = (float)b1 / 255.0f; - float f2 = (float)b2 / 255.0f; - float f3 = (float)b3 / 255.0f; - return float4(f0, f1, f2, f3); -} - #endif diff --git a/com.unity.render-pipelines.core/ShaderLibrary/Packing.hlsl b/com.unity.render-pipelines.core/ShaderLibrary/Packing.hlsl index 33edf74cbe0..2e4e6a05c9b 100644 --- a/com.unity.render-pipelines.core/ShaderLibrary/Packing.hlsl +++ b/com.unity.render-pipelines.core/ShaderLibrary/Packing.hlsl @@ -563,6 +563,22 @@ float2 Unpack888ToFloat2(float3 x) return cb / 4095.0; } + +// Pack a 32-bit integer into four 8-bit color channels such that the integer can be +// exactly reconstructed afterwards. +float4 PackId32ToRGBA8888(uint id32) +{ + uint b0 = (id32 >> 0) & 0xff; + uint b1 = (id32 >> 8) & 0xff; + uint b2 = (id32 >> 16) & 0xff; + uint b3 = (id32 >> 24) & 0xff; + float f0 = (float)b0 / 255.0f; + float f1 = (float)b1 / 255.0f; + float f2 = (float)b2 / 255.0f; + float f3 = (float)b3 / 255.0f; + return float4(f0, f1, f2, f3); +} + #endif // SHADER_API_GLES // Pack 2 float values from the [0, 1] range, to an 8 bits float from the [0, 1] range From 35bc5d41bdd71f199c910ff3d28a758060b24c7b Mon Sep 17 00:00:00 2001 From: Jussi Knuuttila Date: Fri, 4 Jun 2021 20:06:12 +0300 Subject: [PATCH 24/30] Change outline mask to use LOAD as per review request --- .../ShaderLibrary/DataExtraction.hlsl | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.core/ShaderLibrary/DataExtraction.hlsl b/com.unity.render-pipelines.core/ShaderLibrary/DataExtraction.hlsl index 6519b3f3a15..c8688c86d27 100644 --- a/com.unity.render-pipelines.core/ShaderLibrary/DataExtraction.hlsl +++ b/com.unity.render-pipelines.core/ShaderLibrary/DataExtraction.hlsl @@ -21,7 +21,13 @@ float4 ComputeSelectionMask(float objectGroupId, float3 ndcWithZ, TEXTURE2D_PARAM(depthBuffer, sampler_depthBuffer)) { - float sceneZ = SAMPLE_TEXTURE2D(depthBuffer, sampler_depthBuffer, ndcWithZ.xy).r; + // float sceneZ = SAMPLE_TEXTURE2D(depthBuffer, sampler_depthBuffer, ndcWithZ.xy).r; + // Use LOAD so this is compatible with MSAA. Original SAMPLE kept here for reference. + float2 depthBufferSize; + depthBuffer.GetDimensions(depthBufferSize.x, depthBufferSize.y); + float2 unnormalizedUV = depthBufferSize * ndcWithZ.xy; + float sceneZ = LOAD_TEXTURE2D(depthBuffer, unnormalizedUV).r; + // Use a small multiplicative Z bias to make it less likely for objects to self occlude in the outline buffer static const float zBias = 0.02; #if UNITY_REVERSED_Z From f5ce64c502daf56622501bf7ea7af5545aa41690 Mon Sep 17 00:00:00 2001 From: Jussi Knuuttila Date: Mon, 7 Jun 2021 14:04:25 +0300 Subject: [PATCH 25/30] Add ConvertMetallicToSpecular and ConvertSpecularToMetallic to DataExtraction.hlsl, they were removed from CommonMaterial.hlsl --- .../ShaderLibrary/DataExtraction.hlsl | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/com.unity.render-pipelines.universal/ShaderLibrary/DataExtraction.hlsl b/com.unity.render-pipelines.universal/ShaderLibrary/DataExtraction.hlsl index 2f48d35c423..3b966b5269e 100644 --- a/com.unity.render-pipelines.universal/ShaderLibrary/DataExtraction.hlsl +++ b/com.unity.render-pipelines.universal/ShaderLibrary/DataExtraction.hlsl @@ -24,6 +24,20 @@ struct ExtractionInputs float3 emission; }; +// These used to be in CommonMaterial.hlsl but no longer are. They are still +// needed for DataExtraction, so we have them here now. +void ConvertSpecularToMetallic(float3 diffuseColor, float3 specularColor, out float3 baseColor, out float metallic) +{ + metallic = saturate( (Max3(specularColor.r, specularColor.g, specularColor.b) - 0.1F) / 0.45F); + baseColor = lerp(diffuseColor, specularColor, metallic); +} + +void ConvertMetallicToSpecular(float3 baseColor, float metallic, out float3 diffuseColor, out float3 specularColor) +{ + diffuseColor = ComputeDiffuseColor(baseColor, metallic); + specularColor = ComputeFresnel0(baseColor, metallic, DEFAULT_SPECULAR_VALUE); +} + float4 OutputExtraction(ExtractionInputs inputs) { float3 specular, diffuse, baseColor; From 192c7882a1267fd0f3d940b60952145a8453e3d7 Mon Sep 17 00:00:00 2001 From: Jussi Knuuttila Date: Mon, 7 Jun 2021 16:48:51 +0300 Subject: [PATCH 26/30] Add 1 to entityIDs when rendering picking, so the entityID zero gets a value different from the clear value. --- .../ShaderLibrary/DataExtraction.hlsl | 8 ++++++++ .../RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl | 2 +- .../ShaderLibrary/DataExtraction.hlsl | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/com.unity.render-pipelines.core/ShaderLibrary/DataExtraction.hlsl b/com.unity.render-pipelines.core/ShaderLibrary/DataExtraction.hlsl index c8688c86d27..0c3f4c633b9 100644 --- a/com.unity.render-pipelines.core/ShaderLibrary/DataExtraction.hlsl +++ b/com.unity.render-pipelines.core/ShaderLibrary/DataExtraction.hlsl @@ -19,6 +19,14 @@ #define RENDER_DIFFUSE_COLOR_RGBA 13 #define RENDER_OUTLINE_MASK 14 +float4 ComputeEntityPickingValue(uint entityID) +{ + // Add 1 to the ID, so the entity ID 0 gets a value that is not equal + // to the clear value. + uint pickingValue = entityID + 1; + return PackId32ToRGBA8888(pickingValue); +} + float4 ComputeSelectionMask(float objectGroupId, float3 ndcWithZ, TEXTURE2D_PARAM(depthBuffer, sampler_depthBuffer)) { // float sceneZ = SAMPLE_TEXTURE2D(depthBuffer, sampler_depthBuffer, ndcWithZ.xy).r; diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl index cb3f5910cca..4f5d8f62bfb 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl @@ -110,7 +110,7 @@ void Frag( PackedVaryingsToPS packedInput #ifdef UNITY_DOTS_INSTANCING_ENABLED // When rendering EntityIds, GameObjects output EntityId = 0 if (_SelectionID.x == RENDER_ENTITY_ID) - outColor = PackId32ToRGBA8888(unity_EntityId.x); + outColor = ComputeEntityPickingValue(unity_EntityId.x); else outColor = float4(0, 0, 0, 0); #else diff --git a/com.unity.render-pipelines.universal/ShaderLibrary/DataExtraction.hlsl b/com.unity.render-pipelines.universal/ShaderLibrary/DataExtraction.hlsl index 3b966b5269e..223d56b0997 100644 --- a/com.unity.render-pipelines.universal/ShaderLibrary/DataExtraction.hlsl +++ b/com.unity.render-pipelines.universal/ShaderLibrary/DataExtraction.hlsl @@ -91,7 +91,7 @@ float4 OutputExtraction(ExtractionInputs inputs) return float4(inputs.positionWS, 1.0); #ifdef UNITY_DOTS_INSTANCING_ENABLED if (UNITY_DataExtraction_Mode == RENDER_ENTITY_ID) - return PackId32ToRGBA8888(unity_EntityId.x); + return ComputeEntityPickingValue(unity_EntityId.x); #else // GameObjects always have zero EntityId if (UNITY_DataExtraction_Mode == RENDER_ENTITY_ID) From afdbc195c378205abaf08187ef328cb77e249da6 Mon Sep 17 00:00:00 2001 From: Jussi Knuuttila Date: Thu, 17 Jun 2021 19:47:02 +0300 Subject: [PATCH 27/30] Remove DebugAllowRGBConversion which has been replaced by DebugAOVOutput --- .../Runtime/Debug/DebugDisplay.cs | 14 +------------- .../Runtime/Debug/DebugDisplay.cs.hlsl | 1 - .../Runtime/RenderPipeline/HDRenderPipeline.cs | 1 - .../RenderPipeline/RenderPass/AOV/AOVRequest.cs | 6 ------ 4 files changed, 1 insertion(+), 21 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs index aa96258b241..e24122a59ce 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs @@ -40,10 +40,9 @@ unsafe struct ShaderVariablesDebugDisplay public int _DebugSingleShadowIndex; public int _DebugProbeVolumeMode; - public int _DebugAllowRGBConversion; public int _DebugAOVOutput; public int _DebugDisplayPad0; - public int _DebugDisplayPad1; + public int _DebugDisplayPad1; } /// @@ -212,8 +211,6 @@ public class DebugData public int fullScreenContactShadowLightIndex = 0; /// XR single pass test mode. public bool xrSinglePassTestMode = false; - /// Enable range remapping. - public bool allowSRGBConversion = true; /// Whether to display the average timings every second. public bool averageProfilerTimingsOverASecond = false; @@ -628,15 +625,6 @@ public void SetFullScreenDebugMode(FullScreenDebugMode value) data.fullScreenDebugMode = value; } - internal void SetAllowSRGBConversion(bool allow) - { - data.allowSRGBConversion = allow; - } - internal bool GetAllowSRGBConversion() - { - return data.allowSRGBConversion; - } - /// /// Set the current Shadow Map Debug Mode. /// diff --git a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs.hlsl index c7fae57e29d..c69d82d464b 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs.hlsl @@ -69,7 +69,6 @@ CBUFFER_START(ShaderVariablesDebugDisplay) float _MatcapViewScale; int _DebugSingleShadowIndex; int _DebugProbeVolumeMode; - int _DebugAllowRGBConversion; int _DebugAOVOutput; int _DebugDisplayPad0; int _DebugDisplayPad1; diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs index d1237850501..14dfa3e5d89 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs @@ -5371,7 +5371,6 @@ unsafe void ApplyDebugDisplaySettings(HDCamera hdCamera, CommandBuffer cmd, bool cb._ColorPickerMode = (int)m_CurrentDebugDisplaySettings.GetDebugColorPickerMode(); cb._DebugFullScreenMode = (int)m_CurrentDebugDisplaySettings.data.fullScreenDebugMode; cb._DebugProbeVolumeMode = (int)m_CurrentDebugDisplaySettings.GetProbeVolumeDebugMode(); - cb._DebugAllowRGBConversion = m_CurrentDebugDisplaySettings.GetAllowSRGBConversion() ? 1 : 0; #if UNITY_EDITOR cb._MatcapMixAlbedo = HDRenderPipelinePreferences.matcapViewMixAlbedo ? 1 : 0; diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVRequest.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVRequest.cs index f660e993145..cf74fcbf8d5 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVRequest.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVRequest.cs @@ -189,8 +189,6 @@ public void FillDebugData(DebugDisplaySettings debug) if (m_RequestMode != Camera.RenderRequestMode.None) { - debug.SetAllowSRGBConversion(false); - switch (m_RequestMode) { case Camera.RenderRequestMode.Depth: @@ -232,10 +230,6 @@ public void FillDebugData(DebugDisplaySettings debug) throw new ArgumentOutOfRangeException(nameof(m_RequestMode), m_RequestMode, null); } } - else - { - debug.SetAllowSRGBConversion(true); - } } /// From 653966e894835c348fe9458c2a981df61cf36987 Mon Sep 17 00:00:00 2001 From: Jussi Knuuttila Date: Thu, 2 Sep 2021 19:58:50 +0300 Subject: [PATCH 28/30] Fix some objects (e.g. Plane mesh) not getting correctly picked due to incorrect backface culling. --- .../Runtime/RenderPipeline/HDRenderPipeline.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs index 8c815bfe303..dba9df36bcf 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs @@ -3349,6 +3349,9 @@ void RenderSceneSelectionRequest(ScriptableRenderContext context, HDCamera hdCam case Camera.RenderRequestMode.ObjectId: case Camera.RenderRequestMode.EntityId: shaderTagId = new ShaderTagId("Picking"); + // TODO: Find out why CullMode.Back does not work correctly here + renderState.rasterState = new RasterState(CullMode.Off); + renderState.mask = RenderStateMask.Raster; break; case Camera.RenderRequestMode.SelectionMask: shaderTagId = new ShaderTagId("SceneSelectionPass"); From 037342520a7f44708951b82d05ae51ab5d2d99c2 Mon Sep 17 00:00:00 2001 From: Jussi Knuuttila Date: Fri, 3 Sep 2021 13:34:25 +0300 Subject: [PATCH 29/30] Clarify comment for disabling backface culling. --- .../Runtime/RenderPipeline/HDRenderPipeline.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs index dba9df36bcf..3dd89888313 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs @@ -3349,7 +3349,8 @@ void RenderSceneSelectionRequest(ScriptableRenderContext context, HDCamera hdCam case Camera.RenderRequestMode.ObjectId: case Camera.RenderRequestMode.EntityId: shaderTagId = new ShaderTagId("Picking"); - // TODO: Find out why CullMode.Back does not work correctly here + // Turn backface culling off. HDRP Picking passes set "Cull Off" regardless, but things + // don't seem to always work properly unless it's done here as well. renderState.rasterState = new RasterState(CullMode.Off); renderState.mask = RenderStateMask.Raster; break; From 5ae8bc75966c053e64d3620eaab330f6c7b1928a Mon Sep 17 00:00:00 2001 From: Jussi Knuuttila Date: Fri, 3 Sep 2021 15:52:26 +0300 Subject: [PATCH 30/30] Remove PickingSpaceTransforms includes from parent merge --- .../Editor/Material/ShaderGraph/HDShaderPasses.cs | 1 - .../Runtime/Material/AxF/AxF.shader | 1 - .../Runtime/Material/LayeredLit/LayeredLit.shader | 1 - .../Runtime/Material/LayeredLit/LayeredLitTessellation.shader | 1 - .../Runtime/Material/Lit/Lit.shader | 1 - .../Runtime/Material/Lit/LitTessellation.shader | 1 - .../Runtime/Material/TerrainLit/TerrainLitTemplate.hlsl | 1 - .../Runtime/Material/Unlit/Unlit.shader | 1 - 8 files changed, 8 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs index 4b85b301af7..d0ad061a86a 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs @@ -132,7 +132,6 @@ IncludeCollection GenerateIncludes() { var includes = new IncludeCollection(); - includes.Add(CoreIncludes.kPickingSpaceTransforms, IncludeLocation.Pregraph); includes.Add(CoreIncludes.CorePregraph); if (supportLighting) includes.Add(CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph); diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxF.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxF.shader index f4eab105998..eae5f5b006a 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxF.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxF.shader @@ -260,7 +260,6 @@ Shader "HDRP/AxF" // We reuse depth prepass for the scene selection, allow to handle alpha correctly as well as tessellation and vertex animation #define SHADERPASS SHADERPASS_DEPTH_ONLY #define SCENESELECTIONPASS // This will drive the output of the scene selection shader - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxF.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/ShaderPass/AxFDepthPass.hlsl" diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLit.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLit.shader index 309c3b1bc0e..3d3a01ce4cb 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLit.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLit.shader @@ -589,7 +589,6 @@ Shader "HDRP/LayeredLit" #define SHADERPASS SHADERPASS_DEPTH_ONLY #define SCENESELECTIONPASS // This will drive the output of the scene selection shader - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitDepthPass.hlsl" diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLitTessellation.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLitTessellation.shader index b9eadccf132..66ebb280e02 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLitTessellation.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLitTessellation.shader @@ -608,7 +608,6 @@ Shader "HDRP/LayeredLitTessellation" #define SHADERPASS SHADERPASS_DEPTH_ONLY #define SCENESELECTIONPASS // This will drive the output of the scene selection shader - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitDepthPass.hlsl" diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.shader index cb4a54a345e..c6f9b9879f7 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.shader @@ -393,7 +393,6 @@ Shader "HDRP/Lit" // We reuse depth prepass for the scene selection, allow to handle alpha correctly as well as tessellation and vertex animation #define SHADERPASS SHADERPASS_DEPTH_ONLY #define SCENESELECTIONPASS // This will drive the output of the scene selection shader - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitDepthPass.hlsl" diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitTessellation.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitTessellation.shader index 629dec47571..3e8bdf731ef 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitTessellation.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitTessellation.shader @@ -413,7 +413,6 @@ Shader "HDRP/LitTessellation" // We reuse depth prepass for the scene selection, allow to handle alpha correctly as well as tessellation and vertex animation #define SHADERPASS SHADERPASS_DEPTH_ONLY #define SCENESELECTIONPASS // This will drive the output of the scene selection shader - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitDepthPass.hlsl" diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/TerrainLit/TerrainLitTemplate.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/TerrainLit/TerrainLitTemplate.hlsl index 1a2ea16d0bf..992f80ecda5 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/TerrainLit/TerrainLitTemplate.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/TerrainLit/TerrainLitTemplate.hlsl @@ -26,7 +26,6 @@ #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" #endif #ifdef SCENESELECTIONPASS - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl" #endif #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/Unlit.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/Unlit.shader index e0eb3c46d3d..280ca84a4f5 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/Unlit.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/Unlit.shader @@ -165,7 +165,6 @@ Shader "HDRP/Unlit" #define SHADERPASS SHADERPASS_DEPTH_ONLY #define SCENESELECTIONPASS // This will drive the output of the scene selection shader - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/Unlit.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/ShaderPass/UnlitDepthPass.hlsl"