Skip to content

Commit d27a1a6

Browse files
authored
Merge pull request #8131 from Unity-Technologies/internal/2022.3/staging
Internal/2022.3/staging
2 parents 32265cd + c983a9f commit d27a1a6

File tree

11 files changed

+433
-215
lines changed

11 files changed

+433
-215
lines changed

Packages/com.unity.render-pipelines.core/Editor/Debugging/DebugUIDrawer.Builtins.cs

+7-4
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,10 @@ public override bool OnGUI(DebugUI.Widget widget, DebugState state)
801801

802802
rowRect.xMin += 2;
803803
rowRect.xMax -= 2;
804-
EditorGUI.LabelField(rowRect, GUIContent.none, EditorGUIUtility.TrTextContent(row.displayName), DebugWindow.Styles.centeredLeft);
804+
805+
bool isAlternate = r % 2 == 0;
806+
807+
EditorGUI.LabelField(rowRect, GUIContent.none, EditorGUIUtility.TrTextContent(row.displayName),isAlternate ? DebugWindow.Styles.centeredLeft : DebugWindow.Styles.centeredLeftAlternate);
805808
rowRect.xMin -= 2;
806809
rowRect.xMax += 2;
807810

@@ -812,7 +815,7 @@ public override bool OnGUI(DebugUI.Widget widget, DebugState state)
812815
rowRect.x += rowRect.width;
813816
rowRect.width = columns[visible[c]].width;
814817
if (!row.isHidden)
815-
DisplayChild(rowRect, row.children[visible[c] - 1]);
818+
DisplayChild(rowRect, row.children[visible[c] - 1], isAlternate);
816819
}
817820
rowRect.y += rowRect.height;
818821
}
@@ -855,7 +858,7 @@ internal Rect DrawOutline(Rect rect)
855858
return new Rect(rect.x + size, rect.y + size, rect.width - 2 * size, rect.height - 2 * size);
856859
}
857860

858-
internal void DisplayChild(Rect rect, DebugUI.Widget child)
861+
internal void DisplayChild(Rect rect, DebugUI.Widget child, bool isAlternate)
859862
{
860863
rect.xMin += 2;
861864
rect.xMax -= 2;
@@ -869,7 +872,7 @@ internal void DisplayChild(Rect rect, DebugUI.Widget child)
869872
if (child.GetType() == typeof(DebugUI.Value))
870873
{
871874
var widget = Cast<DebugUI.Value>(child);
872-
EditorGUI.LabelField(rect, GUIContent.none, EditorGUIUtility.TrTextContent(widget.GetValue().ToString()));
875+
EditorGUI.LabelField(rect, GUIContent.none, EditorGUIUtility.TrTextContent(widget.GetValue().ToString()), isAlternate ? DebugWindow.Styles.centeredLeft : DebugWindow.Styles.centeredLeftAlternate);
873876
}
874877
else if (child.GetType() == typeof(DebugUI.ColorField))
875878
{

Packages/com.unity.render-pipelines.core/Editor/Debugging/DebugWindow.cs

+17
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using UnityEngine;
1111
using UnityEngine.Assertions;
1212
using UnityEngine.Rendering;
13+
using PackageInfo = UnityEditor.PackageManager.PackageInfo;
1314

1415
namespace UnityEditor.Rendering
1516
{
@@ -582,6 +583,7 @@ public class Styles
582583
public readonly Color skinBackgroundColor;
583584

584585
public static GUIStyle centeredLeft = new GUIStyle(EditorStyles.label) { alignment = TextAnchor.MiddleLeft };
586+
public static GUIStyle centeredLeftAlternate = new GUIStyle(EditorStyles.label) { alignment = TextAnchor.MiddleLeft };
585587
public static float singleRowHeight = EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
586588

587589
public static int foldoutColumnWidth = 70;
@@ -593,6 +595,12 @@ public Styles()
593595
Color backgroundColorDarkSkin = new Color32(38, 38, 38, 128);
594596
Color backgroundColorLightSkin = new Color32(128, 128, 128, 96);
595597

598+
centeredLeftAlternate.normal.background = CoreEditorUtils.CreateColoredTexture2D(
599+
EditorGUIUtility.isProSkin
600+
? new Color(63 / 255.0f, 63 / 255.0f, 63 / 255.0f, 255 / 255.0f)
601+
: new Color(202 / 255.0f, 202 / 255.0f, 202 / 255.0f, 255 / 255.0f),
602+
"centeredLeftAlternate Background");
603+
596604
sectionScrollView = new GUIStyle(sectionScrollView);
597605
sectionScrollView.overflow.bottom += 1;
598606

@@ -604,6 +612,15 @@ public Styles()
604612
sectionHeader.margin.left += 1;
605613
sectionHeader.normal.textColor = EditorGUIUtility.isProSkin ? textColorDarkSkin : textColorLightSkin;
606614
skinBackgroundColor = EditorGUIUtility.isProSkin ? backgroundColorDarkSkin : backgroundColorLightSkin;
615+
616+
// Make sure that textures are unloaded on domain reloads.
617+
void OnBeforeAssemblyReload()
618+
{
619+
UnityEngine.Object.DestroyImmediate(centeredLeftAlternate.normal.background);
620+
AssemblyReloadEvents.beforeAssemblyReload -= OnBeforeAssemblyReload;
621+
}
622+
623+
AssemblyReloadEvents.beforeAssemblyReload += OnBeforeAssemblyReload;
607624
}
608625
}
609626

Packages/com.unity.render-pipelines.core/Runtime/Debugging/DebugDisplaySettingsVolumes.cs

+253-178
Large diffs are not rendered by default.

Packages/com.unity.render-pipelines.core/Runtime/Debugging/VolumeDebugSettings.cs

+10-24
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ public IEnumerable<Camera> cameras
8080

8181
if (camera.cameraType != CameraType.Preview && camera.cameraType != CameraType.Reflection)
8282
{
83-
if (camera.TryGetComponent<T>(out T additionalData))
83+
if (!camera.TryGetComponent<T>(out T additionalData))
84+
additionalData = camera.gameObject.AddComponent<T>();
85+
86+
if (additionalData != null)
8487
m_Cameras.Add(camera);
8588
}
8689
}
@@ -270,21 +273,9 @@ public bool RefreshVolumes(Volume[] newVolumes)
270273
/// <returns>The weight of the volume</returns>
271274
public float GetVolumeWeight(Volume volume)
272275
{
273-
if (weights == null)
274-
return 0;
275-
276-
float total = 0f, weight = 0f;
277-
for (int i = 0; i < volumes.Length; i++)
278-
{
279-
weight = weights[i];
280-
weight *= 1f - total;
281-
total += weight;
282-
283-
if (volumes[i] == volume)
284-
return weight;
285-
}
286-
287-
return 0f;
276+
// TODO: Store the calculated weight in the stack for the volumes that have influence and return it here
277+
var triggerPos = selectedCameraPosition;
278+
return ComputeWeight(volume, triggerPos);
288279
}
289280

290281
/// <summary>
@@ -294,14 +285,9 @@ public float GetVolumeWeight(Volume volume)
294285
/// <returns>If the volume has influence</returns>
295286
public bool VolumeHasInfluence(Volume volume)
296287
{
297-
if (weights == null)
298-
return false;
299-
300-
int index = Array.IndexOf(volumes, volume);
301-
if (index == -1)
302-
return false;
303-
304-
return weights[index] != 0f;
288+
// TODO: Store the calculated weight in the stack for the volumes that have influence and return it here
289+
var triggerPos = selectedCameraPosition;
290+
return ComputeWeight(volume, triggerPos) > 0.0f;
305291
}
306292
}
307293
}

Packages/com.unity.render-pipelines.core/Runtime/Volume/VolumeComponent.cs

+11
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,17 @@ internal static void FindParameters(object o, List<VolumeParameter> parameters,
162162
if (filter?.Invoke(field) ?? true)
163163
{
164164
VolumeParameter volumeParameter = (VolumeParameter)field.GetValue(o);
165+
#if UNITY_EDITOR || DEVELOPMENT_BUILD
166+
var attr = (DisplayInfoAttribute[])field.GetCustomAttributes(typeof(DisplayInfoAttribute), true);
167+
if (attr.Length != 0)
168+
{
169+
volumeParameter.debugId = attr[0].name;
170+
}
171+
else
172+
{
173+
volumeParameter.debugId = field.Name;
174+
}
175+
#endif
165176
parameters.Add(volumeParameter);
166177
}
167178
}

Packages/com.unity.render-pipelines.core/Runtime/Volume/VolumeParameter.cs

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ namespace UnityEngine.Rendering
1818
/// <seealso cref="VolumeParameter{T}"/>
1919
public abstract class VolumeParameter : ICloneable
2020
{
21+
#if UNITY_EDITOR || DEVELOPMENT_BUILD
22+
internal string debugId { get; set; }
23+
#endif
24+
2125
/// <summary>
2226
/// A beautified string for debugger output. This is set on a <c>DebuggerDisplay</c> on every
2327
/// parameter types.

Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightEvaluation.hlsl

+15-7
Original file line numberDiff line numberDiff line change
@@ -276,20 +276,28 @@ SHADOW_TYPE EvaluateShadow_Directional( LightLoopContext lightLoopContext, Posit
276276
}
277277
else if (shadowSplitIndex == int(_CascadeShadowCount) - 1)
278278
{
279-
// float fade = lightLoopContext.shadowContext.fade;
280-
float3 camToPixel = posInput.positionWS - GetPrimaryCameraPosition();
281-
float distanceCamToPixel2 = dot(camToPixel, camToPixel);
282-
283-
HDDirectionalShadowData dsd = lightLoopContext.shadowContext.directionalShadowData;
284-
float fade = saturate(distanceCamToPixel2 * dsd.fadeScale + dsd.fadeBias);
279+
float fade = lightLoopContext.shadowContext.fade;
285280
// In the transition code (both dithering and blend) we use shadow = lerp( shadow, 1.0, fade ) for last transition
286281
// mean if we expend the code we have (shadow * (1 - fade) + fade). Here to make transition with shadow mask
287282
// we will remove fade and add fade * shadowMask which mean we do a lerp with shadow mask
288283
shadow = shadow - fade + fade * shadowMask;
289284
}
290285

291286
// See comment in EvaluateBSDF_Punctual
292-
shadow = light.nonLightMappedOnly ? min(shadowMask, shadow) : shadow;
287+
if (light.nonLightMappedOnly)
288+
{
289+
shadow = min(shadowMask, shadow);
290+
}
291+
else
292+
{
293+
// Use shadowmask when shadow value ​​cannot be retrieved due to shadow caster culling.
294+
float3 camToPixel = posInput.positionWS - GetPrimaryCameraPosition();
295+
float distanceCamToPixel2 = dot(camToPixel, camToPixel);
296+
297+
HDDirectionalShadowData dsd = lightLoopContext.shadowContext.directionalShadowData;
298+
float alpha = saturate(distanceCamToPixel2 * dsd.fadeScale + dsd.fadeBias);
299+
shadow = min(shadow, lerp(1.0, shadowMask, alpha * alpha));
300+
}
293301
#endif
294302

295303
shadow = lerp(shadowMask.SHADOW_TYPE_REPLICATE, shadow, light.shadowDimmer);

Packages/com.unity.render-pipelines.universal/Documentation~/TableOfContents.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@
143143
* [Scriptable Render Passes](renderer-features/scriptable-render-passes.md)
144144
* [Scriptable Render Passes](renderer-features/intro-to-scriptable-render-passes.md)
145145
* [Write a Scriptable Render Pass](renderer-features/write-a-scriptable-render-pass.md)
146-
* [Inject a pass via scripting](customize/inject-render-pass-via-script.md)
146+
* [Inject a pass via scripting](customize/inject-render-pass-via-script.md)
147+
* [Restrict a render pass to a scene area](customize/restrict-render-pass-scene-area.md)
147148
* [Scriptable Renderer Features](renderer-features/scriptable-renderer-features/scriptable-renderer-features-landing.md)
148149
* [Introduction to Scriptable Renderer Features](renderer-features/scriptable-renderer-features/intro-to-scriptable-renderer-features.md)
149150
* [Inject a custom render pass using a Scriptable Renderer Feature](renderer-features/scriptable-renderer-features/inject-a-pass-using-a-scriptable-renderer-feature.md)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# Restrict a render pass to a scene area in URP
2+
3+
To restrict a render pass to a specific area of a scene, add a [volume](../Volumes.md) to the scene, then add code to your render pass and your shader to check if the camera is inside the volume.
4+
5+
Follow these steps:
6+
7+
1. Update your shader code to enable or disable your custom rendering effect based on a Boolean value.
8+
9+
For example, add the following code to your shader:
10+
11+
```hlsl
12+
Pass
13+
{
14+
...
15+
16+
// Add a variable to enable or disable your custom rendering effect
17+
float _Enabled;
18+
19+
...
20+
21+
float4 Frag(Varyings input) : SV_Target0
22+
{
23+
...
24+
25+
// Return the color with the effect if the variable is 1, or the original color if the variable is 0
26+
if (_Enabled == 1){
27+
return colorWithEffect;
28+
} else {
29+
return originalColor;
30+
}
31+
}
32+
}
33+
```
34+
35+
2. Create a script that implements the `VolumeComponent` class. This creates a volume override component that you can add to a volume.
36+
37+
```c#
38+
using UnityEngine;
39+
using UnityEngine.Rendering;
40+
41+
public class MyVolumeOverride : VolumeComponent
42+
{
43+
}
44+
```
45+
46+
3. In the **Hierarchy** window, select the **Add** (**+**) button, then select **GameObject** > **Volume** > **Box Volume**.
47+
48+
4. In the **Inspector** window for the new box volume, under **Volume**, select **New** to create a new volume profile.
49+
50+
5. Select **Add override**, then select your volume override component, for example **My Volume Override**.
51+
52+
6. Add a property to the volume override script. Unity adds the property in the **Inspector** window of the volume override.
53+
54+
For example:
55+
56+
```c#
57+
public class MyVolumeOverride : VolumeComponent
58+
{
59+
// Add an 'Effect Enabled' checkbox to the Volume Override, with a default value of true.
60+
public BoolParameter effectEnabled = new BoolParameter(true);
61+
}
62+
```
63+
64+
5. In your custom pass, use the `GetComponent` API to get the volume override component and check the value of the property.
65+
66+
For example:
67+
68+
```c#
69+
class myCustomPass : ScriptableRenderPass
70+
{
71+
72+
...
73+
74+
public void Setup(Material material)
75+
{
76+
// Get the volume override component
77+
MyVolumeOverride myOverride = VolumeManager.instance.stack.GetComponent<MyVolumeOverride>();
78+
79+
// Get the value of the 'Effect Enabled' property
80+
bool effectStatus = myOverride.effectEnabled.overrideState ? myOverride.effectEnabled.value : false;
81+
}
82+
}
83+
```
84+
85+
6. Pass the value of the property to the variable you added to the shader code.
86+
87+
For example:
88+
89+
```c#
90+
class myCustomPass : ScriptableRenderPass
91+
{
92+
93+
...
94+
95+
public void Setup(Material material)
96+
{
97+
MyVolumeOverride myOverride = VolumeManager.instance.stack.GetComponent<MyVolumeOverride>();
98+
bool effectStatus = myOverride.effectEnabled.overrideState ? myOverride.effectEnabled.value : false;
99+
100+
// Pass the value to the shader
101+
material.SetFloat("_Enabled", effectStatus ? 1 : 0);
102+
}
103+
}
104+
```
105+
106+
Your custom rendering effect is now enabled when the camera is inside the volume, and disabled when the camera is outside the volume.
107+
108+
## Additional resources
109+
110+
- [Write a Scriptable Render Pass](../renderer-features/write-a-scriptable-render-pass.md)
111+
- [Volumes in URP](../volumes.md)
112+
- [Writing custom shaders in URP](../writing-custom-shaders-urp.md)

Packages/com.unity.render-pipelines.universal/Documentation~/renderer-features/scriptable-render-passes.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Use the `ScriptableRenderPass` API to write a custom render pass. You can then i
77
|[Introduction to Scriptable Render Passes](intro-to-scriptable-render-passes.md)|What a Scriptable Render Pass is, and how you can inject it into a scene.|
88
|[Write a Scriptable Render Pass](write-a-scriptable-render-pass.md)|An example of a `ScriptableRenderPass` instance that uses `Blit` to create a red tint effect.|
99
|[Inject a pass via scripting](../customize/inject-render-pass-via-script.md)|Use the `RenderPipelineManager` API to inject a render pass, without using a Scriptable Renderer Feature.|
10+
|[Restrict a render pass to a scene area](../customize/restrict-render-pass-scene-area.md) | Enable a custom rendering effect only if the camera is inside a volume in a scene. |
1011

1112
## Additional resources
1213

Tests/SRPTests/Projects/HDRP_Tests/Assets/GraphicTests/Scenes/2x_Lighting/2324_Shadow_Mask_Directional_Blending/Scene Settings Profile.asset

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ MonoBehaviour:
1616
interCascadeBorders: 1
1717
maxShadowDistance:
1818
m_OverrideState: 1
19-
m_Value: 5
19+
m_Value: 7
2020
directionalTransmissionMultiplier:
2121
m_OverrideState: 1
2222
m_Value: 1

0 commit comments

Comments
 (0)