Skip to content

Commit 3064379

Browse files
authored
Merge pull request #8021 from Unity-Technologies/internal/master
Internal/master
2 parents e1f7861 + 230906e commit 3064379

File tree

168 files changed

+8186
-4092
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

168 files changed

+8186
-4092
lines changed

Packages/com.unity.render-pipelines.core/CHANGELOG.md

Lines changed: 111 additions & 6 deletions
Large diffs are not rendered by default.

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
* [RTHandle fundamentals](rthandle-system-fundamentals.md)
1515
* [Using the RTHandle system](rthandle-system-using.md)
1616
* [Custom Material Inspector](custom-material-inspector.md)
17-
* [Adding properties in the menu](adding-properties.md)
17+
* [Custom settings](settings.md)
18+
* [Adding properties in the menu](adding-properties.md)
19+
* [Add custom graphics settings](add-custom-graphics-settings.md)
20+
* [Get custom graphics settings](get-custom-graphics-settings.md)
21+
* [Include or excude a setting in your build](choose-whether-unity-includes-a-graphics-setting-in-your-build.md)
1822
* [Synchronizing shader code and C#](generating-shader-includes.md)
1923
* [Look Dev](Look-Dev.md)
2024
* [Environment Library](Look-Dev-Environment-Library.md)
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# Add custom graphics settings
2+
3+
You can add custom graphics settings to the **Edit** > **Project Settings** > **Graphics** window, then use the values of the settings to customize your build.
4+
5+
You can change the values of settings while you're editing your project. Unity makes the values static when it builds your project, so you can't change them at runtime.
6+
7+
## Add a setting
8+
9+
To add a setting, follow these steps:
10+
11+
1. Create a class that implements the `IRenderPipelineGraphicsSettings` interface, and add a `[Serializable]` attribute. This becomes a new settings group in the **Graphics** settings window.
12+
2. To set which render pipeline the setting applies to, add a `[SupportedOnRenderPipeline]` attribute and pass in a `RenderPipelineAsset` type.
13+
3. Add a property. This becomes a setting.
14+
4. Implement the `version` field and set it to `0`. Unity doesn't currently use the `version` field, but you must implement it.
15+
16+
For example, the following script adds a setting called **My Value** in a settings group called **My Settings**, in the graphics settings for the Universal Render Pipeline (URP).
17+
18+
```c#
19+
using UnityEngine;
20+
using UnityEngine.Rendering;
21+
using System;
22+
23+
[Serializable]
24+
[SupportedOnRenderPipeline(typeof(UniversalRenderPipelineAsset))]
25+
26+
// Create a new settings group by implementing the IRenderPipelineGraphicsSettings interface
27+
public class MySettings : IRenderPipelineGraphicsSettings
28+
{
29+
// Implement the version field
30+
public int version => 0;
31+
32+
// Create a new setting and set its default value to 100.
33+
public int myValue = 100;
34+
}
35+
```
36+
37+
## Add a reference property
38+
39+
[Reference properties](https://docs.unity3d.com/2023.3/Documentation/Manual/EditingValueProperties.html#references) take compatible project assets or GameObjects in the scene as inputs.
40+
41+
To add a reference property, follow these steps:
42+
43+
1. Create a class that implements the `IRenderPipelineResources` interface. This becomes a new settings group in the Graphics Settings window.
44+
2. Add a property. This becomes a reference property.
45+
3. Implement the `version` field and set it to `0`. Unity doesn't currently use the `version` field, but you must implement it.
46+
47+
For example, the following script adds a reference property called **My Material** that references a material.
48+
49+
```c#
50+
using UnityEngine;
51+
using UnityEngine.Rendering;
52+
using System;
53+
54+
[Serializable]
55+
[SupportedOnRenderPipeline(typeof(UniversalRenderPipelineAsset))]
56+
57+
// Create a new reference property group by implementing the IRenderPipelineResources interface
58+
public class MySettings: IRenderPipelineResources
59+
{
60+
// Implement the version field
61+
public int version => 0;
62+
63+
// Create a new reference property that references a material
64+
[SerializeField] public Material myMaterial;
65+
}
66+
```
67+
68+
To set a default asset, use a [`[ResourcePath]`](https://docs.unity3d.com/2023.3/Documentation/ScriptReference/Rendering.ResourcePathAttribute.html) attribute above the reference property. For example, in the example, add the following line above `public Material myMaterial`.
69+
70+
```c#
71+
[ResourcePath('path-to-default-file')]
72+
```
73+
74+
## Change the name and layout of a settings group
75+
76+
To change the name of a settings group in the **Graphics** settings window, follow these steps:
77+
78+
1. Add `using System.ComponentModel` to your script.
79+
2. Add a `[Category]` attribute to your script. For example, `[Category("My Category")]`.
80+
81+
You can also use the [PropertyDrawer](https://docs.unity3d.com/ScriptReference/PropertyDrawer.html) API to further customize the layout of custom settings.
82+
83+
## Set which render pipeline a setting applies to
84+
85+
To set which render pipeline a setting applies to, use the `[SupportedOnRenderPipeline]` attribute and pass in a `RenderPipelineAsset` type.
86+
87+
For example, if your project uses the Universal Rendering Pipeline (URP) and you want your setting to appear only in the **URP** tab of the **Graphics** settings window, use the following code:
88+
89+
```c#
90+
[SupportedOnRenderPipeline(typeof(UniversalRenderPipelineAsset))]
91+
```
92+
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Include or exclude a setting in your build
2+
3+
By default, Unity doesn't include a setting ("strips" the setting) in your built project. For example, if you create a custom reference property where you set a shader asset, Unity doesn't include that property in your build.
4+
5+
You can choose to include a setting in your build instead. You can then get the value of the setting at runtime. The value is read-only.
6+
7+
## Include a setting in your build
8+
9+
To include a setting in your build by default, set the `IsAvailableInPlayerBuild` property of your [settings class](add-custom-graphics-settings.md) to `true`.
10+
11+
For example, add the following line:
12+
13+
```c#
14+
public bool IsAvailableInPlayerBuild => true;
15+
```
16+
17+
## Create your own stripping code
18+
19+
You can override the `IsAvailableInPlayerBuild` property by implementing the `IRenderPipelineGraphicsSettingsStripper` interface, and writing code that conditionally strips or keeps the setting.
20+
21+
Follow these steps:
22+
23+
1. Create a class that implements the `IRenderPipelineGraphicsSettingsStripper` interface, and pass in your [settings class](add-custom-graphics-settings.md).
24+
2. Implement the `active` property. If you set `active` to `false`, the code in the class doesn't run.
25+
3. Implement the `CanRemoveSettings` method with your own code that decides whether to include the setting.
26+
4. In your code, return either `true` or `false` to strip or keep the setting.
27+
28+
For example, in the following code, the `CanRemoveSettings` method returns `true` and strips the setting if the value of the setting is larger than 100.
29+
30+
```c#
31+
using UnityEngine;
32+
using UnityEngine.Rendering;
33+
34+
// Implement the IRenderPipelineGraphicsSettingsStripper interface, and pass in our settings class
35+
class SettingsStripper : IRenderPipelineGraphicsSettingsStripper<MySettings>
36+
{
37+
38+
// Make this stripper active
39+
public bool active => true;
40+
41+
// Implement the CanRemoveSettings method with our own code
42+
public bool CanRemoveSettings(MySettings settings)
43+
{
44+
// Strip the setting (return true) if the value is larger than 100
45+
return settings.myValue > 100;
46+
}
47+
}
48+
```
49+
50+
If you implement `IRenderPipelineGraphicsSettingsStripper` multiple times for one setting, Unity only strips the setting if they all return `true`.
51+
52+
## Check if your build includes a setting
53+
54+
You can check if a setting exists at runtime. A setting might not exist at runtime for one of the following reasons:
55+
56+
- Unity didn't include the setting in your build.
57+
- The current pipeline doesn't support the setting.
58+
59+
Use `TryGetRenderPipelineSettings` to check if the setting exists. `TryGetRenderPipelineSettings` puts the setting in an `out` variable if it exists. Otherwise it returns `false`.
60+
61+
For example, the following code checks whether a settings group called `MySettings` exists at runtime:
62+
63+
```c#
64+
if (GraphicsSettings.TryGetRenderPipelineSettings<MySettings>(out var mySetting)){
65+
Debug.Log("The setting is in the build and its value is {mySetting.myValue}");
66+
}
67+
```
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Get custom graphics settings
2+
3+
To get a custom setting and read its value, use the `GetRenderPipelineSettings` method.
4+
5+
If you want to get a setting at runtime, you must [include the setting in your build](choose-whether-unity-includes-a-graphics-setting-in-your-build.md).
6+
7+
For example, the following script gets the `MySettings` settings class from the example in the [Add custom graphics settings](add-custom-graphics-settings.md) page, then logs the value of the `MyValue` setting:
8+
9+
```c#
10+
using UnityEngine;
11+
using UnityEngine.Rendering;
12+
13+
public class LogMySettingsValue : MonoBehaviour
14+
{
15+
// Unity calls the Update method once per frame
16+
void Update()
17+
{
18+
// Get the MySettings settings
19+
var mySettings = GraphicsSettings.GetRenderPipelineSettings<MySettings>();
20+
21+
// Log the value of the MyValue setting
22+
Debug.Log(mySettings.myValue);
23+
}
24+
}
25+
```
26+
27+
## Detect when a setting changes
28+
29+
You can configure a property so it notifies other scripts when its value changes. This only works while you're editing your project, not at runtime.
30+
31+
You can use this to fetch the value only when it changes, instead of every frame in the `Update()` method.
32+
33+
Follow these steps:
34+
35+
1. Create a public getter and setter in your setting class.
36+
37+
2. In the setter, set the value using the `SetValueAndNotify` method, so changing the setting value sends a notification to other scripts.
38+
39+
For example:
40+
41+
```c#
42+
using UnityEngine;
43+
using UnityEngine.Rendering;
44+
using System;
45+
46+
[Serializable]
47+
[SupportedOnRenderPipeline(typeof(UniversalRenderPipelineAsset))]
48+
49+
// Create a settings group by implementing the IRenderPipelineGraphicsSettings interface
50+
public class MySettings : IRenderPipelineGraphicsSettings
51+
{
52+
// Implement the version field
53+
public int version => 0;
54+
55+
// Create a MyValue setting and set its default value to 100
56+
[SerializeField] private int MyValue = 100;
57+
58+
public int myValue
59+
{
60+
get => MyValue;
61+
set => this.SetValueAndNotify(ref MyValue, value);
62+
}
63+
}
64+
```
65+
66+
If you use `SetValueAndModify' in a standalone application, Unity throws an exception.
67+
68+
3. Use the `GraphicsSettings.Subscribe` method to subscribe to notifications from the setting, and call an `Action` when the setting changes.
69+
70+
For example:
71+
72+
```c#
73+
using System;
74+
using UnityEngine;
75+
using UnityEngine.Rendering;
76+
77+
public class DetectSettingsChange : MonoBehaviour
78+
{
79+
80+
// Unity calls the Awake method when it loads the script instance.
81+
void Awake()
82+
{
83+
84+
// Log the new value of the setting
85+
Action<MySettings, string> onSettingChanged = (setting, name) =>
86+
{
87+
Debug.Log($"{name} changed to {setting.myValue}");
88+
};
89+
90+
// Subscribe to notifications from the MySettings settings, and call the OnSettingsChanged Action when notified
91+
GraphicsSettings.Subscribe<MySettings>(onSettingChanged);
92+
}
93+
}
94+
```
95+
96+
### Unsubscribe from the notifications from a setting
97+
98+
To stop calling a method when a setting changes, use the `GraphicsSettings.Unsubscribe` method. For example:
99+
100+
```c#
101+
GraphicsSettings.Unsubscribe<MySettings>(onSettingChanged);
102+
```
103+
104+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Custom settings
2+
3+
Add custom properties and settings to a Scriptable Render Pipeline.
4+
5+
|Page|Description|
6+
|-|-|
7+
|[Adding properties in the menu](adding-properties.md)|Add properties in the **Core Render Pipeline** settings section.|
8+
|[Add custom graphics settings](add-custom-graphics-settings.md)|Add custom graphics settings to the **Edit** > **Project Settings** > **Graphics** window, then use the values of the settings to customize your build.|
9+
|[Get custom graphics settings](get-custom-graphics-settings.md)|Get a custom graphics setting and read its value, or detect when a setting changes.|
10+
|[Include or exclude a setting in your build](choose-whether-unity-includes-a-graphics-setting-in-your-build.md)|Choose whether Unity includes or strips a graphics setting in your build, and check if a build includes a setting.|

Packages/com.unity.render-pipelines.core/Editor/Lighting/ProbeVolume/DynamicGI/DynamicGISkyOcclusion.compute

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#define RAYTRACING_BACKEND_COMPUTE
2-
#define GROUP_SIZE_X 16
2+
#define GROUP_SIZE_X 64
33
#define GROUP_SIZE_Y 1
44
#define RAYTRACING_GROUP_SIZE GROUP_SIZE_X*GROUP_SIZE_Y
5+
56
#include "DynamicGISkyOcclusion.hlsl"
67

78
int g_DispatchWidth;

Packages/com.unity.render-pipelines.core/Editor/Lighting/ProbeVolume/DynamicGI/DynamicGISkyOcclusion.hlsl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ UNITY_DECLARE_RT_ACCEL_STRUCT(_AccelStruct);
1212

1313
int _SampleCount;
1414
int _SampleId;
15-
int _ProbeOffset;
1615
int _MaxBounces;
1716
float _OffsetRay;
17+
float _AverageAlbedo;
18+
int _BackFaceCulling;
19+
int _BakeSkyShadingDirection;
20+
1821
StructuredBuffer<float3> _ProbePositions;
1922
StructuredBuffer<float3> _SkyShadingPrecomputedDirection;
2023
RWStructuredBuffer<float4> _SkyOcclusionOut;
2124
RWStructuredBuffer<float3> _SkyShadingOut;
2225
RWStructuredBuffer<uint> _SkyShadingDirectionIndexOut;
23-
float _AverageAlbedo;
24-
int _BackFaceCulling;
25-
int _BakeSkyShadingDirection;
2626

2727

2828
uint LinearSearchClosestDirection(float3 direction)
@@ -49,7 +49,7 @@ void RayGenExecute(UnifiedRT::DispatchInfo dispatchInfo)
4949
const float kSHBasis0 = 0.28209479177387814347f;
5050
const float kSHBasis1 = 0.48860251190291992159f;
5151

52-
int probeId = _ProbeOffset + dispatchInfo.globalThreadIndex;
52+
int probeId = dispatchInfo.globalThreadIndex;
5353

5454
RngState rngState;
5555
rngState.Init(uint2((uint)probeId, 0), 1, _SampleId);

Packages/com.unity.render-pipelines.core/Editor/Lighting/ProbeVolume/ProbeGIBaking.LightTransport.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ internal static bool PrepareBaking()
146146

147147
if (positions.Length == 0)
148148
{
149+
Clear();
149150
CleanBakeData();
150151
return false;
151152
}
@@ -702,8 +703,10 @@ public RayTracingContext context
702703
var resources = ScriptableObject.CreateInstance<RayTracingResources>();
703704
ResourceReloader.ReloadAllNullIn(resources, k_PackageLightTransport);
704705

705-
m_Backend = RayTracingContext.IsBackendSupported(RayTracingBackend.Hardware) ? RayTracingBackend.Hardware : RayTracingBackend.Compute;
706-
m_Backend = RayTracingBackend.Compute; // hardcoded to compute as hardware is broken for now (UUM-56242)
706+
// Hardware backend is still inconsistent on yamato, using only compute backend for now.
707+
//m_Backend = RayTracingContext.IsBackendSupported(RayTracingBackend.Hardware) ? RayTracingBackend.Hardware : RayTracingBackend.Compute;
708+
m_Backend = RayTracingBackend.Compute;
709+
707710
m_Context = new RayTracingContext(m_Backend, resources);
708711
}
709712

0 commit comments

Comments
 (0)