diff --git a/Packages/com.unity.render-pipelines.core/Documentation~/TableOfContents.md b/Packages/com.unity.render-pipelines.core/Documentation~/TableOfContents.md index 6adc3f35232..172b72b8a8c 100644 --- a/Packages/com.unity.render-pipelines.core/Documentation~/TableOfContents.md +++ b/Packages/com.unity.render-pipelines.core/Documentation~/TableOfContents.md @@ -12,6 +12,7 @@ * [Free Camera](Free-Camera.md) * [Camera Switcher](Camera-Switcher.md) * [Render Requests](User-Render-Requests.md) +* [Render from another camera inside a camera's rendering loop](in-loop-render-requests.md) * [Render Graph](render-graph-system.md) * [Benefits of the render graph system](render-graph-benefits.md) * [Render graph fundamentals](render-graph-fundamentals.md) diff --git a/Packages/com.unity.render-pipelines.core/Documentation~/in-loop-render-requests.md b/Packages/com.unity.render-pipelines.core/Documentation~/in-loop-render-requests.md new file mode 100644 index 00000000000..409f3e1da7b --- /dev/null +++ b/Packages/com.unity.render-pipelines.core/Documentation~/in-loop-render-requests.md @@ -0,0 +1,139 @@ +# Render from another camera inside a camera's rendering loop + +Render from cameras nested inside the render loop of other cameras. + +Attach the provided script to a GameObject with a Camera component to nest multiple cameras, that are rendering with [RenderPipeline.SubmitRenderRequest](https://docs.unity3d.com/6000.0/Documentation/ScriptReference/Rendering.RenderPipeline.SubmitRenderRequest.html), inside the render loop of other cameras. + +**Note**: If your project uses the [Universal Render Pipeline](https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@latest/index.html) (URP), the recommended best practice is to use [UniversalRenderPipeline.SingleCameraRequest](https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@17.0/api/UnityEngine.Rendering.Universal.UniversalRenderPipeline.SingleCameraRequest.html) instead of [StandardRequest](https://docs.unity3d.com/6000.0/Documentation/ScriptReference/Rendering.RenderPipeline.StandardRequest.html), to make sure you only render the camera provided to the `RenderRequest` API instead of the full stack of cameras. + +## Attach the script to nest + +Follow these steps: + +1. Create a new C# script. +2. Add the `using` statements shown below and the `RequireComponent` attribute with the `Camera` type. + + ```c# + using System.Collections.Generic; + using UnityEngine; + using UnityEngine.Rendering; + + [RequireComponent(typeof(Camera))] + public class InLoopRenderRequest : MonoBehaviour + { + + } + ``` + +3. Add a property with the type `Camera` to the `InLoopRenderRequest` class. +4. Add a property with the type `RenderTexture` for each callback the camera uses, as shown below: + + ```c# + [RequireComponent(typeof(Camera))] + public class InLoopRenderRequest : MonoBehaviour + { + public Camera renderRequestCamera; + + public RenderTexture onBeginCameraRendering; + public RenderTexture onBeginContextRendering; + public RenderTexture onEndCameraRendering; + public RenderTexture onEndContextRendering; + } + ``` + +## Full code example + +The following is an example of the finalized code which you attach to the secondary camera: + +```c# +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.Rendering; + +[RequireComponent(typeof(Camera))] +public class InLoopRenderRequest : MonoBehaviour +{ + // Add a reference to the secondary camera that will render the textures + // It's recommended to disable the secondary camera. + public Camera renderRequestCamera; + + // Add references to the Render Textures that will contain the rendered image from the secondary camera. + public RenderTexture onBeginCameraRendering; + public RenderTexture onBeginContextRendering; + public RenderTexture onEndCameraRendering; + public RenderTexture onEndContextRendering; + + void OnEnable() + { + // Subscribe to the RenderPipelineManager callbacks + RenderPipelineManager.beginCameraRendering += OnBeginCameraRender; + RenderPipelineManager.beginContextRendering += OnBeginContextRendering; + RenderPipelineManager.endCameraRendering += OnEndCameraRender; + RenderPipelineManager.endContextRendering += OnEndContextRendering; + } + + public void OnDisable() + { + // Unsubscribe to the callbacks from RenderPipelineManager when we disable the component + RenderPipelineManager.beginCameraRendering -= OnBeginCameraRender; + RenderPipelineManager.beginContextRendering -= OnBeginContextRendering; + RenderPipelineManager.endCameraRendering -= OnEndCameraRender; + RenderPipelineManager.endContextRendering -= OnEndContextRendering; + } + + void SubmitStandardRenderRequest(RenderTexture rt, Camera cam) + { + RenderPipeline.StandardRequest request = new(); + + // Check that the Scriptable Render Pipeline (SRP) we're using supports the given render data. + if (RenderPipeline.SupportsRenderRequest(cam, request)) + { + // Set the request RenderTexture + request.destination = rt; + + // Render the camera output to the RenderTexture synchronously + // When this is complete, the RenderTexture in renderTextures[i] contains the scene rendered from the point of view of the secondary cameras + RenderPipeline.SubmitRenderRequest(cam, request); + } + } + + // StandardRequest and UniversalRenderPipeline.SingleCameraRequest also trigger RenderPipelineManager callbacks. + // Check that the callbacks are from the GameObject's Camera component to avoid a recursive rendering of the same camera. + private void OnBeginContextRendering(ScriptableRenderContext ctx, List cams) + { + if (cams.Contains(GetComponent())) + { + SubmitStandardRenderRequest(onBeginContextRendering, renderRequestCamera); + } + } + + private void OnEndContextRendering(ScriptableRenderContext ctx, List cams) + { + if (cams.Contains(GetComponent())) + { + SubmitStandardRenderRequest(onEndContextRendering, renderRequestCamera); + } + } + + private void OnBeginCameraRender(ScriptableRenderContext ctx, Camera cam) + { + if (cam == GetComponent()) + { + SubmitStandardRenderRequest(onBeginCameraRendering, renderRequestCamera); + } + } + + private void OnEndCameraRender(ScriptableRenderContext ctx, Camera cam) + { + if (cam == GetComponent()) + { + SubmitStandardRenderRequest(onEndCameraRendering, renderRequestCamera); + } + } +} +``` + +## Additional resources +- [Render Requests](User-Render-Requests.md) +- [Creating a custom render pipeline](srp-custom.md) + diff --git a/Packages/com.unity.render-pipelines.high-definition/Documentation~/Default-Settings-Window.md b/Packages/com.unity.render-pipelines.high-definition/Documentation~/Default-Settings-Window.md index 74248e7696a..a58dd6c4047 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Documentation~/Default-Settings-Window.md +++ b/Packages/com.unity.render-pipelines.high-definition/Documentation~/Default-Settings-Window.md @@ -6,6 +6,12 @@ The section contains the following settings that let you define project-wide set You can also add your own settings. Refer to [Add custom settings](https://docs.unity3d.com/Packages/com.unity.render-pipelines.core@17.0/manual/add-custom-graphics-settings.html) in the Scriptable Render Pipeline (SRP) Core manual for more information. +## Lightmap Sampling Settings + +| **Property** | **Description** | +| --------------------------| ------------------------------------------------------------ | +| **Use Bicubic Lightmap Sampling** | Improves the visual fidelity of lightmaps by smoothening sharp or jagged edges, especially at the edges of shadows. Enabling this property might reduce performance on lower-end platforms. | + ## Additional Shader Stripping Settings | **Property** | **Description** | diff --git a/Packages/com.unity.render-pipelines.high-definition/Documentation~/HDRP-Features.md b/Packages/com.unity.render-pipelines.high-definition/Documentation~/HDRP-Features.md index a6f354177fa..5f02b45770f 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Documentation~/HDRP-Features.md +++ b/Packages/com.unity.render-pipelines.high-definition/Documentation~/HDRP-Features.md @@ -432,7 +432,7 @@ Use HDRP's water system to create and control realistic water surfaces. HDRP's w - Simulation-based caustics. - Underwater rendering. - Deformer. -- Foam Generator. +- Foam. - Water Excluder. - A mirrored simulation on the CPU for high-fidelity game interactions. - A shader graph interaction for advanced visual customization. diff --git a/Packages/com.unity.render-pipelines.high-definition/Documentation~/HDRP-Sample-Content.md b/Packages/com.unity.render-pipelines.high-definition/Documentation~/HDRP-Sample-Content.md index fef1813e34c..75b9064d04d 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Documentation~/HDRP-Sample-Content.md +++ b/Packages/com.unity.render-pipelines.high-definition/Documentation~/HDRP-Sample-Content.md @@ -79,7 +79,7 @@ This sample includes examples on how to create a [Fullscreen Shader](create-a-fu The Water samples contain the following scenes you can use to learn about HDRP's [Water](water.md) features: - Pool: Demonstrates ripples and buoyancy. -- Glacier: Demonstrates current, water deformers, floating objects, and a water mask. +- Glacier: Demonstrates current, water deformers, floating objects, and a simulation mask. - Island: Demonstrates waves, foam, and the water excluder. - Rain: Demonstrates how to add pertubations to the normals using shader graph. - Waterline: Demonstrates how to override rendering of the waterline using a [Custom Pass](Custom-Pass.md). diff --git a/Packages/com.unity.render-pipelines.high-definition/Documentation~/Images/foam-in-the-wake-of-a-gameobject.jpg b/Packages/com.unity.render-pipelines.high-definition/Documentation~/Images/foam-in-the-wake-of-a-gameobject.jpg new file mode 100644 index 00000000000..dd71b811c70 Binary files /dev/null and b/Packages/com.unity.render-pipelines.high-definition/Documentation~/Images/foam-in-the-wake-of-a-gameobject.jpg differ diff --git a/Packages/com.unity.render-pipelines.high-definition/Documentation~/Images/foam-on-the-crests-of-waves-amount-one.jpg b/Packages/com.unity.render-pipelines.high-definition/Documentation~/Images/foam-on-the-crests-of-waves-amount-one.jpg new file mode 100644 index 00000000000..d36dc530c99 Binary files /dev/null and b/Packages/com.unity.render-pipelines.high-definition/Documentation~/Images/foam-on-the-crests-of-waves-amount-one.jpg differ diff --git a/Packages/com.unity.render-pipelines.high-definition/Documentation~/Images/foam-on-the-crests-of-waves-amount-zero.jpg b/Packages/com.unity.render-pipelines.high-definition/Documentation~/Images/foam-on-the-crests-of-waves-amount-zero.jpg new file mode 100644 index 00000000000..bcbae0bb9ae Binary files /dev/null and b/Packages/com.unity.render-pipelines.high-definition/Documentation~/Images/foam-on-the-crests-of-waves-amount-zero.jpg differ diff --git a/Packages/com.unity.render-pipelines.high-definition/Documentation~/Images/more-deep-foam.jpg b/Packages/com.unity.render-pipelines.high-definition/Documentation~/Images/more-deep-foam.jpg new file mode 100644 index 00000000000..c2298bf86d5 Binary files /dev/null and b/Packages/com.unity.render-pipelines.high-definition/Documentation~/Images/more-deep-foam.jpg differ diff --git a/Packages/com.unity.render-pipelines.high-definition/Documentation~/Images/more-surface-foam.jpg b/Packages/com.unity.render-pipelines.high-definition/Documentation~/Images/more-surface-foam.jpg new file mode 100644 index 00000000000..5eaf6cf6086 Binary files /dev/null and b/Packages/com.unity.render-pipelines.high-definition/Documentation~/Images/more-surface-foam.jpg differ diff --git a/Packages/com.unity.render-pipelines.high-definition/Documentation~/Images/trailing-foam.jpg b/Packages/com.unity.render-pipelines.high-definition/Documentation~/Images/trailing-foam.jpg new file mode 100644 index 00000000000..035d564f753 Binary files /dev/null and b/Packages/com.unity.render-pipelines.high-definition/Documentation~/Images/trailing-foam.jpg differ diff --git a/Packages/com.unity.render-pipelines.high-definition/Documentation~/Images/water-debug-watermask.png b/Packages/com.unity.render-pipelines.high-definition/Documentation~/Images/water-debug-simulationmask.png similarity index 100% rename from Packages/com.unity.render-pipelines.high-definition/Documentation~/Images/water-debug-watermask.png rename to Packages/com.unity.render-pipelines.high-definition/Documentation~/Images/water-debug-simulationmask.png diff --git a/Packages/com.unity.render-pipelines.high-definition/Documentation~/Images/water-sample-island-scene.jpg b/Packages/com.unity.render-pipelines.high-definition/Documentation~/Images/water-sample-island-scene.jpg new file mode 100644 index 00000000000..bdecc26eeda Binary files /dev/null and b/Packages/com.unity.render-pipelines.high-definition/Documentation~/Images/water-sample-island-scene.jpg differ diff --git a/Packages/com.unity.render-pipelines.high-definition/Documentation~/Images/watersystem-simulation-foam.png b/Packages/com.unity.render-pipelines.high-definition/Documentation~/Images/watersystem-simulation-foam.png deleted file mode 100644 index c0d263a386e..00000000000 Binary files a/Packages/com.unity.render-pipelines.high-definition/Documentation~/Images/watersystem-simulation-foam.png and /dev/null differ diff --git a/Packages/com.unity.render-pipelines.high-definition/Documentation~/Ray-Tracing-Getting-Started.md b/Packages/com.unity.render-pipelines.high-definition/Documentation~/Ray-Tracing-Getting-Started.md index 19bd8c84fc3..6b8bae70c4d 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Documentation~/Ray-Tracing-Getting-Started.md +++ b/Packages/com.unity.render-pipelines.high-definition/Documentation~/Ray-Tracing-Getting-Started.md @@ -123,15 +123,15 @@ To make HDRP calculate ray tracing effects for [Cameras](hdrp-camera-component-r To enable ray tracing by default: -1. Open the Project Settings window (menu: **Edit > Project Settings**), then select the HDRP Default Settings tab. -2. Select Camera from the Default Frame Settings For drop-down. -3. In the **Rendering** section, enable **Ray Tracing**. +1. From the main menu, select **Edit** > **Project Settings**. +2. In the **Project Settings** window, go to the **Pipeline Specific Settings** section, then select the **HDRP** tab. +3. Under **Frame Settings (Default Values)** > **Camera** > **Rendering**, enable **Ray Tracing**. -To enable ray tracing for a specific Camera: +To enable ray tracing for a specific camera: -1. Click on the Camera in the Scene or Hierarchy to view it in the Inspector. -2. In the **General** section, enable **Custom Frame Settings**. This exposes Frame Settings just for this Camera. -3. in the **Rendering** section, enable **Ray Tracing**. +1. Select the camera in the scene or **Hierarchy** window to view it in the **Inspector** window. +2. In the **Rendering** section, enable **Custom Frame Settings**. This exposes frame settings for this camera only. +3. Use the foldout (triangle) to expand **Rendering**, then enable **Ray Tracing**. #### Build settings diff --git a/Packages/com.unity.render-pipelines.high-definition/Documentation~/TableOfContents.md b/Packages/com.unity.render-pipelines.high-definition/Documentation~/TableOfContents.md index 97c93cbd8ec..8323f1d2ab4 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Documentation~/TableOfContents.md +++ b/Packages/com.unity.render-pipelines.high-definition/Documentation~/TableOfContents.md @@ -210,9 +210,13 @@ * [Enable mask and water decals](enable-mask-and-water-decals.md) * [Configure swell, agitation, or ripples](add-swell-agitation-or-ripples.md) * [Simulating currents with water decals](simulating-currents-with-water-decals.md) - * [Simulating foam or ripples with masks](simulating-foam-or-ripples-with-masks.md) + * [Simulating ripples with masks](simulating-foam-or-ripples-with-masks.md) * [Decals and masking in the water system](water-decals-and-masking-in-the-water-system.md) * [Foam in the Water System](water-foam-in-the-water-system.md) + * [Introduction to foam](introduction-to-foam.md) + * [Create wind-driven foam on the whole water surface](create-wind-driven-foam-on-the-whole-water-surface.md) + * [Create local foam in the wake of a GameObject](create-local-foam-in-the-wake-of-a-gameobject.md) + * [Add foam with a script](add-foam-with-script.md) * [Caustics in the Water System](water-caustics-in-the-water-system.md) * [Create a current in the Water System](water-create-a-current-in-the-water-system.md) * [Deform a water surface](water-deform-a-water-surface.md) diff --git a/Packages/com.unity.render-pipelines.high-definition/Documentation~/add-caustics-and-foam-and-check-waves-and-ripples.md b/Packages/com.unity.render-pipelines.high-definition/Documentation~/add-caustics-and-foam-and-check-waves-and-ripples.md index d884b4a1a13..7c5ba60a2fe 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Documentation~/add-caustics-and-foam-and-check-waves-and-ripples.md +++ b/Packages/com.unity.render-pipelines.high-definition/Documentation~/add-caustics-and-foam-and-check-waves-and-ripples.md @@ -1,11 +1,10 @@ -# Add caustics or foam and check waves and ripples +# Add caustics and check waves and ripples -To add caustics or foam, or get information about water surface displacement due to waves and ripples, get buffers from the [`WaterSurface`](xref:UnityEngine.Rendering.HighDefinition.WaterSurface) class: +To add caustics or get information about water surface displacement due to waves and ripples, get buffers from the [`WaterSurface`](xref:UnityEngine.Rendering.HighDefinition.WaterSurface) class: | Action | API | |-----------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | Add caustics | [GetCausticsBuffer](../api/UnityEngine.Rendering.HighDefinition.WaterSurface.html#UnityEngine_Rendering_HighDefinition_WaterSurface_GetCausticsBuffer_System_Single__) | -| Add foam | [GetFoamBuffer](../api/UnityEngine.Rendering.HighDefinition.WaterSurface.html#UnityEngine_Rendering_HighDefinition_WaterSurface_GetFoamBuffer_UnityEngine_Vector2__) | | Check waves and ripples | [GetDeformationBuffer](../api/UnityEngine.Rendering.HighDefinition.WaterSurface.html#UnityEngine_Rendering_HighDefinition_WaterSurface_GetDeformationBuffer) | ## Example: Add caustics @@ -44,45 +43,6 @@ public class WaterCausticsExample : MonoBehaviour } ``` -## Example: Add foam - -``` -using UnityEngine; -using UnityEngine.Rendering.HighDefinition; - -public class WaterFoamExample : MonoBehaviour -{ - // Reference to the water surface component - public WaterSurface waterSurface; - - // The area of the water surface where the foam buffer should be queried - public Vector2 foamArea; - - // Material to apply the foam effect - public Material waterMaterial; - - // Shader property name for foam texture in the water material - private readonly string _foamTextureProperty = "_FoamTex"; - - void Start() - { - // Get the foam buffer for the specified 2D area on the water surface - Texture foamBuffer = waterSurface.GetFoamBuffer(out foamArea); - - if (foamBuffer != null) - { - // Apply the foam buffer as a texture to the water material - waterMaterial.SetTexture(_foamTextureProperty, foamBuffer); - Debug.Log("Foam buffer applied successfully."); - } - else - { - Debug.LogWarning("Foam buffer could not be retrieved."); - } - } -} -``` - ## Example: Check waves and ripples ``` diff --git a/Packages/com.unity.render-pipelines.high-definition/Documentation~/add-foam-with-script.md b/Packages/com.unity.render-pipelines.high-definition/Documentation~/add-foam-with-script.md new file mode 100644 index 00000000000..0b78538ed6b --- /dev/null +++ b/Packages/com.unity.render-pipelines.high-definition/Documentation~/add-foam-with-script.md @@ -0,0 +1,42 @@ +# Add foam with a script + +To add caustics or foam, or get information about water surface displacement due to waves and ripples, get buffers from the [GetFoamBuffer](../api/UnityEngine.Rendering.HighDefinition.WaterSurface.html#UnityEngine_Rendering_HighDefinition_WaterSurface_GetFoamBuffer_UnityEngine_Vector2__) API. + +## Example: Add foam + +``` +using UnityEngine; +using UnityEngine.Rendering.HighDefinition; + +public class WaterFoamExample : MonoBehaviour +{ + // Reference to the water surface component + public WaterSurface waterSurface; + + // The area of the water surface where the foam buffer should be queried + public Vector2 foamArea; + + // Material to apply the foam effect + public Material waterMaterial; + + // Shader property name for foam texture in the water material + private readonly string _foamTextureProperty = "_FoamTex"; + + void Start() + { + // Get the foam buffer for the specified 2D area on the water surface + Texture foamBuffer = waterSurface.GetFoamBuffer(out foamArea); + + if (foamBuffer != null) + { + // Apply the foam buffer as a texture to the water material + waterMaterial.SetTexture(_foamTextureProperty, foamBuffer); + Debug.Log("Foam buffer applied successfully."); + } + else + { + Debug.LogWarning("Foam buffer could not be retrieved."); + } + } +} +``` diff --git a/Packages/com.unity.render-pipelines.high-definition/Documentation~/add-swell-agitation-or-ripples.md b/Packages/com.unity.render-pipelines.high-definition/Documentation~/add-swell-agitation-or-ripples.md index fd359130751..1fc300e8f0f 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Documentation~/add-swell-agitation-or-ripples.md +++ b/Packages/com.unity.render-pipelines.high-definition/Documentation~/add-swell-agitation-or-ripples.md @@ -1,10 +1,10 @@ -# Configure swell, agitation, or ripples with a water mask +# Configure swell, agitation, or ripples with a simulation mask -To configure swell, agitation or ripples, use a Water Mask to affect the influence the simulation has on specific areas of the water surface. +To configure swell, agitation, or ripples, use a simulation mask to affect the influence the simulation has on specific areas of the water surface. Masks take into account the Wrap Mode of the texture. For Ocean, Sea, or Lake water surface types, select **Clamp** rather than the default **Repeat** value. -To add a Water Mask: +To add a simulation mask: 1. Create and import a texture where the color channels represent the fluctuations. @@ -21,7 +21,7 @@ To add a Water Mask: The darker the color of a channel, the lesser the effect. For example, use white for 100% intensity and black for 0% intensity. -1. In the Water Volume Inspector window, drag the texture to the **Water Mask** property. +1. In the Water Volume Inspector window, drag the texture to the **Simulation Mask** property. @@ -34,7 +34,7 @@ To add a Water Mask:
-In this example, the red channel has a gradient that reduces the first and second simulation bands. The noise on the green channel reduces ripples. For more information, refer to the Water Mask property description. +In this example, the red channel has a gradient that reduces the first and second simulation bands. The noise on the green channel reduces ripples. For more information, refer to the Simulation Mask property description.
diff --git a/Packages/com.unity.render-pipelines.high-definition/Documentation~/color-checker-tool-reference.md b/Packages/com.unity.render-pipelines.high-definition/Documentation~/color-checker-tool-reference.md new file mode 100644 index 00000000000..e9e166c593e --- /dev/null +++ b/Packages/com.unity.render-pipelines.high-definition/Documentation~/color-checker-tool-reference.md @@ -0,0 +1,79 @@ +--- +uid: um-script-colorcheckertool +--- + +# Color Checker Tool reference + +Use the Color Checker Tool to analyze and compare colors across different visual settings and configurations. + +## Color Palette + +This procedural color checker calibrates colors and lighting, offering customizable and persistent color fields with support for up to 64 values. + +| Value | Description | +|----------------------|-------------------------------------------------------------------------------------------------------------------------------------| +| **Color Fields** | Specifies the total number of color fields. | +| **Fields per Row** | Sets the number of color fields displayed in each row. | +| **Fields Margin** | Defines the spacing between individual color fields. | +| **Add Gradient** | Adds a gradient at the bottom of the color checker. | +| **Sphere Mode** | Instantiates spheres for each field. | +| **Compare to Unlit** | Splits the fields into lit and pre-exposed unlit values, which is useful for calibration. Post-process still applies to both sides. | + +## Cross Polarized Grayscale + +Values are measured without specular lighting using a cross-polarized filter, enhancing accuracy for light calibration in PBR. + +| Value | Description | +|----------------------|-------------------------------------------------------------------------------------------------------------------------------------| +| **Fields Margin** | Defines the spacing between individual color fields. | +| **Add Gradient** | Adds a gradient at the bottom of the color checker. | +| **Sphere Mode** | Instantiates spheres for each field. | +| **Compare to Unlit** | Splits the fields into lit and pre-exposed unlit values, which is useful for calibration. Post-process still applies to both sides. | + +## Middle Gray + +Neutral 5, the mid-gray value. + +| Value | Description | +|----------------------|-------------------------------------------------------------------------------------------------------------------------------------| +| **Fields Margin** | Defines the spacing between individual color fields. | +| **Sphere Mode** | Instantiates spheres for each field. | +| **Compare to Unlit** | Splits the fields into lit and pre-exposed unlit values, which is useful for calibration. Post-process still applies to both sides. | + +## Reflection + +Useful for checking local reflections. + +| Value | Description | +|-------------------|------------------------------------------------------| +| **Fields Margin** | Defines the spacing between individual color fields. | + +## Stepped Luminance + +Stepped luminance allows to check gamma calibration. + +| Value | Description | +|----------------------|-------------------------------------------------------------------------------------------------------------------------------------| +| **Add Gradient** | Adds a gradient at the bottom of the color checker. | +| **Compare to Unlit** | Splits the fields into lit and pre-exposed unlit values, which is useful for calibration. Post-process still applies to both sides. | + +## Material Palette + +Material fields are customizable and persistent, with up to 12 values. Each row in the palette represents a material with varying smoothness. + +| Value | Description | +|---------------------|------------------------------------------------------| +| **Material Fields** | Specifies the total number of material fields. | +| **is Metallic** | Makes the material highly reflective. | +| **Fields Margin** | Defines the spacing between individual color fields. | + +## External Texture + +Useful for calibration using captured data. + +| Value | Description | +|-------------------|--------------------------------------------------------------------------------| +| **Texture** | Select a lit base texture. | +| **Unlit Texture** | Select an unlit comparison texture. | +| **Pre Exposure** | Make the texture values adapt to exposure. Uncheck this when using raw values. | +| **Slicer** | Compares lit values to unlit, raw values. You can disable pre-exposure. | diff --git a/Packages/com.unity.render-pipelines.high-definition/Documentation~/create-local-foam-in-the-wake-of-a-gameobject.md b/Packages/com.unity.render-pipelines.high-definition/Documentation~/create-local-foam-in-the-wake-of-a-gameobject.md new file mode 100644 index 00000000000..4e576ac3b99 --- /dev/null +++ b/Packages/com.unity.render-pipelines.high-definition/Documentation~/create-local-foam-in-the-wake-of-a-gameobject.md @@ -0,0 +1,17 @@ +# Create local foam near a GameObject + +To create foam on a water surface near a GameObject, follow these steps: + +1. In the **Hierarchy** window, open the context menu (right-click) and select **Water > Surface**, then create a water surface. + +1. In the **Inspector** window of the water surface, in the **Water decals** section, enable **Foam**. + +1. In the **Hierarchy** window, right-click a GameObject and select **Water > Surface > Water decal**. + + The new water decal is now a child of the GameObject. + +1. In the **Scene** view, move the water decal close to the GameObject. + +1. Move the GameObject along the water surface and notice how a trail of foam forms in its wake. + +![Local foam near a GameObject](Images/trailing-foam.jpg) diff --git a/Packages/com.unity.render-pipelines.high-definition/Documentation~/create-wind-driven-foam-on-the-whole-water-surface.md b/Packages/com.unity.render-pipelines.high-definition/Documentation~/create-wind-driven-foam-on-the-whole-water-surface.md new file mode 100644 index 00000000000..e039e0564e2 --- /dev/null +++ b/Packages/com.unity.render-pipelines.high-definition/Documentation~/create-wind-driven-foam-on-the-whole-water-surface.md @@ -0,0 +1,32 @@ +# Create wind-driven foam on the entire water surface + +You can create foaming whitecaps to simulate waves breaking when wind speeds exceed a certain threshold. + +Simulation foam automatically appears on local maximum on high wave crests depending on the properties set below. + +To create foam on the entire water surface: + +- In the **Hierarchy** window, open the context menu (right-click) and select **Water** > **Surface**, then create a river, an ocean, a sea, or a lake. + +- To create more deep foam, increase the Distant Wind Speed in the **Simulation** section of the **Inspector** window of the water surface. + + ![Distant Wind Speed set to 250](Images/more-deep-foam.jpg) + + Distant Wind Speed set to 250. + +- To create more surface foam, also increase the foam amount in the **Foam** section of the **Inspector** window of the water surface. + + ![Distant Wind Speed set to 250 and foam amount set to 1](Images/more-surface-foam.jpg) + + Distant Wind Speed set to 250 and foam amount set to 1. + +- To fine-tune foam generation across wind conditions, edit the Wind Speed Dimmer curve in the **Foam** section of the **Inspector** window of the water surface. + + This control determines the amount of foam that Distant Wind Speed values produce. + + ![Wind Speed Dimmer curve](Images/water-foam-dimmer.png)
+ * A: Distant Wind Speed values at the bottom of the curve don't produce any foam. + * B: Distant Wind Speed values in the range where the curve rises produce some foam. + * C: Distant Wind Speed values in the range at the top of the curve produce lots of foam. + * D: The x-axis of this graph represents normalized Distant Wind Speed. + * E: The y-axis of this graph represents the percentage of the maximum foam amount. diff --git a/Packages/com.unity.render-pipelines.high-definition/Documentation~/graphics-compositor-window-reference.md b/Packages/com.unity.render-pipelines.high-definition/Documentation~/graphics-compositor-window-reference.md index cd958c02ec6..2da4fc23988 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Documentation~/graphics-compositor-window-reference.md +++ b/Packages/com.unity.render-pipelines.high-definition/Documentation~/graphics-compositor-window-reference.md @@ -57,7 +57,9 @@ you can use filters to apply common color processing operations to Sub-layers. T **Note**: It is possible to implement the functionality of many filters with nodes in the Composition Graph, but if you use the built-in filters instead, it makes the Composition Graph simpler. #### Chroma Keying + Applies a chroma keying algorithm to the Sub-layer. When you select this filter, you can use the following properties to customize it. + | **Property** | **Description** | | ---- | ---- | |**Key Color**| Specifies a color to indicate the areas of the image to mask/make transparent. | diff --git a/Packages/com.unity.render-pipelines.high-definition/Documentation~/introduction-to-foam.md b/Packages/com.unity.render-pipelines.high-definition/Documentation~/introduction-to-foam.md new file mode 100644 index 00000000000..1a8d7ddfa51 --- /dev/null +++ b/Packages/com.unity.render-pipelines.high-definition/Documentation~/introduction-to-foam.md @@ -0,0 +1,39 @@ +# Introduction to foam + +There are two types of foam you may want to create, which you can implement in two different ways: + +- To implement wind-driven foam on a whole water surface, use simulation foam. +- To implement local foam in the wake of a GameObject, such as a sailing boat or an object falling into a pool, use a water decal. + +![HDRP water sample Island scene](Images/water-sample-island-scene.jpg) + +HDRP water sample Island scene + +## Wind-driven foam on the whole water surface + +When you create a new water ocean, sea, or lake, simulation foam appears at or underneath the whole water surface, depending on the wind speed profile and the amount of foam you set. + +![Foam amount is zero or wind profile doesn't create foam](Images/foam-on-the-crests-of-waves-amount-zero.jpg) + +Foam does not appear if the foam amount is zero or if the wind profile doesn't generate enough turbulence to create foam. + +![Foam amount is greater than zero and wind profile creates foam](Images/foam-on-the-crests-of-waves-amount-one.jpg) + +Foam appears when the foam amount is greater than zero and the wind profile generates enough turbulence to create foam. + +### Deep foam and surface foam + +The following types of foam can appear at or underneath the water surface: + +- Surface foam: Found at or near the water surface. Forms light streaks and patches. Influenced by **Distant Wind Speed** and **Wind Speed Dimmer**. + +- Deep foam: Found beneath the water surface. Forms dark streaks and patches. Influenced by **Distant Wind Speed** and **Wind Speed Dimmer**. + +## Local foam in the wake of a GameObject + +You can create foam behind GameObjects to simulate the trail left by a moving boat. + +You can also create static, circular foam patches to simulate foam appearing in coastal areas or tidal flats, or when an object falls into the water. + +![Local foam in the wake of a GameObject](Images/foam-in-the-wake-of-a-gameobject.jpg) + diff --git a/Packages/com.unity.render-pipelines.high-definition/Documentation~/settings-and-properties-related-to-the-water-system.md b/Packages/com.unity.render-pipelines.high-definition/Documentation~/settings-and-properties-related-to-the-water-system.md index 20580625e0a..24fd2f5e78c 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Documentation~/settings-and-properties-related-to-the-water-system.md +++ b/Packages/com.unity.render-pipelines.high-definition/Documentation~/settings-and-properties-related-to-the-water-system.md @@ -176,10 +176,10 @@ Determines the speed at which HDRP presents the water simulation. Values above 1 -Water Mask +Simulation Mask -Set the texture HDRP uses to reduce or stop water frequencies depending on the water surface type.
  • Ocean: Reduces swell (red channel), agitation (green), and ripples (blue).
  • River: Reduces agitation (red channel) and ripples (green channel).
  • Pool: Reduces ripples (red channel).
The Water Mask reduces the intensity of these water effects by multiplying the mask values with the corresponding water properties in the shader. Darker areas (closer to black) reduce the intensity, while lighter areas (closer to white) increase it.
For more information, refer to Decals and masking in the Water System. +Set the texture HDRP uses to reduce or stop water frequencies depending on the water surface type.
  • Ocean: Reduces swell (red channel), agitation (green), and ripples (blue).
  • River: Reduces agitation (red channel) and ripples (green channel).
  • Pool: Reduces ripples (red channel).
The simulation mask reduces the intensity of these water effects by multiplying the mask values with the corresponding water properties in the shader. Darker areas (closer to black) reduce the intensity, while lighter areas (closer to white) increase it.
For more information, refer to Decals and masking in the Water System. @@ -521,77 +521,77 @@ X - + - + X - + X + + + Foam - -Simulation Foam Amount - -Determines the amount of surface foam. Higher values generate larger foam patches. The Wind Speed Dimmer configuration determines which Distant Wind Speed values generate foam, and how much; refer to Foam in the water system. + Persistence Multiplier + Determines the lifespan of surface foam. Higher values cause foam to persist longer and leave a trail. - -Simulation Foam Smoothness +Current Influence -Determines the lifespan of surface foam. Higher values cause foam to persist longer and leave a trail. +Specifies the influence of the swell current on foam. A value of zero means foam stays still, a value of one makes the foam match with current direction and speed. Ripple motion doesn't have any impact on foam. -Texture Tiling +Color -Determines the tile size of the foam texture, in meters. +Determines the foam color, which HDRP multiplies by the foam texture to produce the final appearance. -Custom Texture +Smoothness -Choose a texture Unity can use to define foam's appearance. If this is None, HDRP uses the default texture. +Determines how much the foam reflects light. -Mask +Texture Tiling -Select a texture whose red channel Unity uses to reduce or remove foam. +Sets the per-meter tiling for the foam texture. - -Wind Speed Dimmer - -Determines foam intensity. The normalized Distant Wind Speed determines the X axis value. The spline editor configures the Y axis value. Refer to Foam in the water system for more information. + Wind Speed Dimmer + Determines foam intensity. The normalized Distant Wind Speed determines the X axis value. The spline editor configures the Y axis value. Refer to Foam in the water system for more information. + + + Simulation Foam Amount + Determines the amount of surface foam. Higher values generate larger foam patches. - - - -X - - -X - - -X - - -Appearance - + + X + + + X + + + X + + + Appearance + @@ -1017,7 +1017,6 @@ Determines the influence of the Settings and properties related to the water system diff --git a/Packages/com.unity.render-pipelines.high-definition/Documentation~/water-debug-mode.md b/Packages/com.unity.render-pipelines.high-definition/Documentation~/water-debug-mode.md index 4afccf381bc..b24f9ebf7ea 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Documentation~/water-debug-mode.md +++ b/Packages/com.unity.render-pipelines.high-definition/Documentation~/water-debug-mode.md @@ -3,12 +3,12 @@ For authoring purposes, the water surface component has debug view modes. Those views are available in Miscellaneous section in the water surface component. They are especially useful for placing the different areas (Mask, Deformation, Foam) precisely. -## Water Mask -The Water Mask mode displays the reduction of each simulation band. White means no reduction. Black means 100% reduction. -You can select which channel of the water mask to debug by using the **Water Mask Mode** dropdown. +## Simulation Mask +The Simulation Mask mode displays the reduction of each simulation band. White means no reduction. Black means 100% reduction. +You can select which channel of the water mask to debug by using the **Simulation Mask Mode** dropdown. Note that, for saving texture space, the red channel always attenuate the first band (First swell band for oceans, Agitation for rivers, Ripples for pools), green channel, the second band (Second swell band for oceans, ripples for rivers)... etc -![](Images/water-debug-watermask.png) +![](Images/water-debug-simulationmask.png) ## Simulation Foam Mask diff --git a/Packages/com.unity.render-pipelines.high-definition/Documentation~/water-decals-and-masking-in-the-water-system.md b/Packages/com.unity.render-pipelines.high-definition/Documentation~/water-decals-and-masking-in-the-water-system.md index 043e63400b2..9a431ef2ec8 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Documentation~/water-decals-and-masking-in-the-water-system.md +++ b/Packages/com.unity.render-pipelines.high-definition/Documentation~/water-decals-and-masking-in-the-water-system.md @@ -1,9 +1,9 @@ # Decals and masking in the water system ## Masks -You can use a **Water Mask** to affect the influence the simulation has on specific areas of the water surface. +You can use a simulation mask to affect the influence the simulation has on specific areas of the water surface. -Masks take into account the **Wrap Mode** of the texture on the importer. For **Ocean, Sea, or Lake** water surface types, choose **Clamp** rather the default, **Repeat**. +Masks take into account the **Wrap Mode** of the texture on the importer. For **Ocean, Sea, or Lake** water surface types, choose **Clamp** rather than the default, **Repeat**. @@ -16,7 +16,7 @@ Masks take into account the **Wrap Mode** of the texture on the importer. For **
-In this example, the Red channel attenuates the First and Second bands with a gradient. The noise on the Green channel attenuates ripples. See the Water Mask property description for more information. +In this example, the Red channel attenuates the First and Second bands with a gradient. The noise on the Green channel attenuates ripples. See the Simulation Mask property description for more information.
diff --git a/Packages/com.unity.render-pipelines.high-definition/Documentation~/water-decals-masking-landing.md b/Packages/com.unity.render-pipelines.high-definition/Documentation~/water-decals-masking-landing.md index 5a1f6dda3f8..9892a8f17a8 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Documentation~/water-decals-masking-landing.md +++ b/Packages/com.unity.render-pipelines.high-definition/Documentation~/water-decals-masking-landing.md @@ -1,8 +1,8 @@ # Water surface fluctuations -You can apply effects like swell, agitation, deformation, and foam across the water surface. +You can apply effects like swell, agitation, and deformation across the water surface. -You can add fluctuations such as swell, agitation, or ripples to the whole of a water surface based on texture channels with a Water Mask. +You can add fluctuations such as swell, agitation, or ripples to the whole of a water surface based on texture channels with a simulation mask. You can also add detailed visual effects to localized water areas with water decals, a type of shader graph nodes. @@ -11,4 +11,4 @@ You can also add detailed visual effects to localized water areas with water dec | **[Enable mask and water decals](enable-mask-and-water-decals.md)** | Mask and current water decals are disabled by default. | | **[Configure swell, agitation, or ripples with a water mask](add-swell-agitation-or-ripples.md)** | Configure swell, agitation, or ripples across the water surface. | | **[Simulate currents with a water decal](simulating-currents-with-water-decals.md)** | Simulate water currents by projecting textures. | -| **[Simulate foam or ripples with masks](simulating-foam-or-ripples-with-masks.md)** | Create effects like foam or ripples. | +| **[Simulate ripples with masks](simulating-foam-or-ripples-with-masks.md)** | Create effects like ripples. | diff --git a/Packages/com.unity.render-pipelines.high-definition/Documentation~/water-exclude-part-of-the-water-surface.md b/Packages/com.unity.render-pipelines.high-definition/Documentation~/water-exclude-part-of-the-water-surface.md index bfc9beeb0da..cc2931feb86 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Documentation~/water-exclude-part-of-the-water-surface.md +++ b/Packages/com.unity.render-pipelines.high-definition/Documentation~/water-exclude-part-of-the-water-surface.md @@ -1,6 +1,6 @@ # Exclude part of a water surface -Sometimes you might want to prevent water from appearing on top of other surfaces. For static environments, you can use a [water mask](water-decals-and-masking-in-the-water-system.md) to make sure the water stays under the terrain. For dynamic objects, it’s more practical to use a water excluder. A water excluder is a GameObject that marks pixels on screen that should not receive a water surface. +Sometimes you might want to prevent water from appearing on top of other surfaces. For static environments, you can use a [simulation mask](water-decals-and-masking-in-the-water-system.md) to make sure the water stays under the terrain. For dynamic objects, it’s more practical to use a water excluder. A water excluder is a GameObject that marks pixels on screen that should not receive a water surface. You can use a water excluder to remove a water surface inside a floating object. The following example shows a water excluder applied to the inside of a boat. @@ -52,4 +52,4 @@ You can also right-click on a GameObject in the Hierarchy and select **Water** > ## Change the shape of a Water Excluder -If you want to exclude water from the inside of a boat, you will probably need to author a custom mesh that fits the shape of your boat. To do this, create a simplified version of the inside of your boat in a 3D modelling software, then assign the mesh to a Water Excluder object. \ No newline at end of file +If you want to exclude water from the inside of a boat, you will probably need to author a custom mesh that fits the shape of your boat. To do this, create a simplified version of the inside of your boat in a 3D modelling software, then assign the mesh to a Water Excluder object. diff --git a/Packages/com.unity.render-pipelines.high-definition/Documentation~/water-foam-in-the-water-system.md b/Packages/com.unity.render-pipelines.high-definition/Documentation~/water-foam-in-the-water-system.md index 66457da3e8e..7072e910c06 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Documentation~/water-foam-in-the-water-system.md +++ b/Packages/com.unity.render-pipelines.high-definition/Documentation~/water-foam-in-the-water-system.md @@ -1,105 +1,13 @@ -# Foam in the water system +# Foam -The foam properties make it possible to control how much foam appears on your water surface and to make small adjustments to the foam's appearance. -On the water system there is two different type of foam: Simulation foam and Generated foam. +Simulate and customize foam effects for water surfaces in your project. -## Simulation Foam +Foam effects enhance the realism of water by simulating phenomena like wind-driven foam or trailing foam behind objects. Learn how to create and control foam on water surfaces, including scripting options and reference settings. -The simulation foam automatically appears on local maximum on high amplitude waves crests depending on the properties set below. -It is currently best practice to only adjust two of the foam settings: **Simulation Foam Amount** and the **Wind Speed Dimmer**. - -![](Images/watersystem-simulation-foam.png) - -**Simulation Foam Amount** determines foam patch size. -### Wind Speed Dimmer -This control determines the amount of foam that **Distant Wind Speed** values produce. - -![](Images/water-foam-dimmer.png)
-* A: **Distant Wind Speeds** at the bottom of the curve do not produce any foam. -* B: **Distant Wind Speeds** in the range where the curve rises produce some foam. -* C: **Distant Wind Speeds** in the range at the top of the curve produce lots of foam. -* D: The x axis of this graph represents normalized **Distant Wind Speed**. -* E: The y axis of this graph represents the percentage of the maximum foam amount. - -## Generated Foam - -The generated foam is foam injected at specific location using a foam generator with a specific shape. -Note that the [Shore Wave Deformer](WaterSystem-waterdeformer.md#deformer-type-shorewave) has a foam generator included to generate foam behind the waves. -This foam persistence can be adjusted and can also follow the swell's current direction. - -![](Images/watersystem-generated-foam.png) - -### Create a Foam Generator - -To create a Foam Generator: - -1. Go to **GameObject** > **Water** > **Foam Generator.** - -To make a foam generator affect a water surface: - -1. Select the Water Surface to open it in the Inspector. -2. Select the Foam drop-down. -3. Select the **Enable** toggle. - -You must also make sure it is enabled in your Project’s HDRP Asset : - -1. Select the HDRP Asset in the Project window and, in the Inspector, go to **Rendering** > **Water** and enable the **Foam** checkbox. - -Lastly, make sure that your foam generator is inside the foam area. To see the area, you can select foam in the debug dropdown in the Miscellaneous foldout at the bottom of the water surface inspector. - - - -### Configure a Foam Generator - -The properties in the Water Deformer inspector window change based on the type you select. - -**Note**: The **Move** tool only moves a water deformer along the X and Z axes. To make a deformer move above or below the water surface, change the **Amplitude** value. - -### Common properties - -The following properties exist in all Deformer types. - -| **Property** | | **Description** | -| --------------- | -------------- | ------------------------------------------------------------ | -| **Scale Mode** | | The scaling mode to apply to the deformer. | -| | **Scale Invariant** | Ignores the scale set in the Transform component and uses the region size directly. -| | **Inherit from Hierarchy** | Multiplies the Deformer’s region size by the [lossy scale](https://docs.unity3d.com/ScriptReference/Transform-lossyScale.html) of the Transform. Note that since the Deformer uses a top down projection, if the transformation hierarchy is [skewed](https://docs.unity3d.com/Manual/class-Transform.html), the deformer does not scale correctly. | -| **Region Size** | | Control the size of the foam generator in meters. | -| **Type** | | | -| | **Disk** | Create a foam generator in the shape of a disk. | -| | **Rectangle** | Create a foam generator in the shape of a Rectangle. | -| | **Texture** | Customize the shape of a foam generator with a texture. For information about the properties specific to this type, see [Texture](#foam-generator-type-texture). | -| | **Material** | Customize the shape of a foam generator with a ShaderGraph. For information about the properties specific to this type, see [Material](#foam-generator-type-material). | -| **Surface Foam Dimmer** | | Control the dimmer for the surface foam. The higher the value, the more surface foam appears. | -| **Deep Foam Dimmer** | | Control the dimmer for the deep foam. The higher the value, the more deep foam appears. | - - - -### Texture - -These properties are specific to the Texture foam generator type. - -| **Property** | **Description** | -| ------------ | ------------------------------------------------------------ | -| Texture | Specifies the texture used to generate the foam. The red channel holds the surface foam and the green channel holds the deep foam.
This texture can be a regular texture or a Render Texture, which can be updated at runtime by modifying a render target with a full screen shader graph for example. For a Render Texture, use the R16_UNorm format. | - - - -### Material - -These properties are specific to the Material foam generator type. - -| **Property** | **Description** | -| ------------ | ------------------------------------------------------------ | -| Resolution | The material specified by this foam generator will be blit into the intermediate foam atlas to be used later by the water system. This property specifies the size that it should occupy in the atlas. | -| Update Mode | The frequency at which the material should be rendered inside the atlas. When update mode is **On Demand**, you can use the **RequestUpdate** function on the **Deformer** script to trigger an update. | -| Material | The material used by the foam generator. This should be a Material with a shader created from the ShaderGraph Water Decal master node. Use the **Surface foam** and **Deep foam** output to inject foam. | - - -## Limitations -This foam implementation is monochromatic. You cannot add a tint to represent algae, for example. - -The foam injected using the custom foam input in the water shader graph is not affected when disabling foam on a water surface. - -## Additional resources -* Settings and properties related to the water system \ No newline at end of file +| **Topic** | **Description** | +| :----------------------------------------------------------------------------------------- | :--------------------------------------------------------------------- | +| **[Introduction to foam](introduction-to-foam.md)** | Overview of foam effects in the water system. | +| **[Create wind-driven foam on the entire water surface](create-wind-driven-foam-on-the-whole-water-surface.md)** | Enable simulation to display foam across the entire water surface. | +| **[Add foam with a script](add-foam-with-script.md)** | Guide to scripting foam effects programmatically. | +| **[Create local foam near a GameObject](create-local-foam-in-the-wake-of-a-gameobject.md)** | Display local foam, such as trailing foam behind a floating, moving object. | +| **[Foam reference](settings-and-properties-related-to-the-water-system.md)** | Detailed settings and properties related to foam in the water system. | diff --git a/Packages/com.unity.render-pipelines.high-definition/Documentation~/water-scripting-in-the-water-system.md b/Packages/com.unity.render-pipelines.high-definition/Documentation~/water-scripting-in-the-water-system.md index c114ea4d0bf..c9c250d1f1e 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Documentation~/water-scripting-in-the-water-system.md +++ b/Packages/com.unity.render-pipelines.high-definition/Documentation~/water-scripting-in-the-water-system.md @@ -8,5 +8,5 @@ To align objects correctly with the water surface you can retrieve the normal of |----------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------| | [Float objects on a water surface](float-objects-on-a-water-surface.md) | Add buoyancy to the water simulation. | | [Align objects to the water surface using normals](align-objects-to-water-surface-using-normals.md) | Make objects follow the curvature of the water in real time. | -| [Add caustics or foam and check waves and ripples](add-caustics-and-foam-and-check-waves-and-ripples.md) | Incorporate caustics or foam and check or retrieve information about the displacement of the water surface. | +| [Add caustics and check waves and ripples](add-caustics-and-foam-and-check-waves-and-ripples.md) | Incorporate caustics and check or retrieve information about the displacement of the water surface. | | [Synchronize water surfaces](synchronize-water-surfaces.md) | Synchronize water simulation across all clients in a multiplayer game. | diff --git a/Packages/com.unity.render-pipelines.high-definition/Documentation~/water.md b/Packages/com.unity.render-pipelines.high-definition/Documentation~/water.md index f46fa11d839..9980f9777cf 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Documentation~/water.md +++ b/Packages/com.unity.render-pipelines.high-definition/Documentation~/water.md @@ -9,7 +9,7 @@ Create water in the High Definition Render Pipeline (HDRP). | [Water system simulation](water-water-system-simulation.md) | How the water system simulation works. | | [Quality and performance decisions](water-quality-and-performance-decisions.md) | How to make quality decisions and optimize performance. | | [Water Override for Volumes](water-the-water-system-volume-override.md) | Purpose of the water Volume Override. | -| [Decals and masking in the water system](water-decals-and-masking-in-the-water-system.md) | How foam works in the water system. | +| [Decals and masking in the water system](water-decals-and-masking-in-the-water-system.md) | How decals and masks work in the water system. | | [Foam in the water system](water-foam-in-the-water-system.md) | Control how much foam appears on your water surface. | | [Caustics in the water system](water-caustics-in-the-water-system.md) | What caustics are, how to adjust them, and their limitations. | | [Create a current in the water system](water-create-a-current-in-the-water-system.md) | Apply a current map to a water surface. | diff --git a/Packages/com.unity.render-pipelines.high-definition/Editor/BuildProcessors/HDRPPreprocessShaders.cs b/Packages/com.unity.render-pipelines.high-definition/Editor/BuildProcessors/HDRPPreprocessShaders.cs index d4d4cb8dff7..5449cf26c0c 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Editor/BuildProcessors/HDRPPreprocessShaders.cs +++ b/Packages/com.unity.render-pipelines.high-definition/Editor/BuildProcessors/HDRPPreprocessShaders.cs @@ -296,7 +296,8 @@ protected override bool DoShadersStripper(HDRenderPipelineAsset hdrpAsset, Shade bool useBicubicLightmapSampling = false; if (GraphicsSettings.TryGetRenderPipelineSettings(out var lightmapSamplingSettings)) useBicubicLightmapSampling = lightmapSamplingSettings.useBicubicLightmapSampling; - return inputData.shaderKeywordSet.IsEnabled(m_LightmapBicubicSampling) != useBicubicLightmapSampling; + if (inputData.shaderKeywordSet.IsEnabled(m_LightmapBicubicSampling) != useBicubicLightmapSampling) + return true; } #if !ENABLE_SENSOR_SDK diff --git a/Packages/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDSubTarget.cs b/Packages/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDSubTarget.cs index 49ef88a43ee..02c1f8fbab2 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDSubTarget.cs +++ b/Packages/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDSubTarget.cs @@ -213,7 +213,9 @@ protected SubShaderDescriptor PostProcessSubShader(SubShaderDescriptor subShader { if (passDescriptor.defines == null) passDescriptor.defines = new(); - passDescriptor.defines.Add(CoreDefines.SupportGlobalMipBias); + + if (!passDescriptor.defines.Any(d => d.descriptor.referenceName == CoreDefines.SupportGlobalMipBias.First().descriptor.referenceName)) + passDescriptor.defines.Add(CoreDefines.SupportGlobalMipBias); } CollectPassKeywords(ref passDescriptor); @@ -287,7 +289,9 @@ protected KernelDescriptor PostProcessKernel(KernelDescriptor kernel) { if (passDescriptor.defines == null) passDescriptor.defines = new(); - passDescriptor.defines.Add(CoreDefines.SupportGlobalMipBias); + + if (!passDescriptor.defines.Any(d => d.descriptor.referenceName == CoreDefines.SupportGlobalMipBias.First().descriptor.referenceName)) + passDescriptor.defines.Add(CoreDefines.SupportGlobalMipBias); } CollectPassKeywords(ref passDescriptor); diff --git a/Packages/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Shaders/Templates/PlanarPrimitive/DXR/Unlit/EvaluateMaterialData.template b/Packages/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Shaders/Templates/PlanarPrimitive/DXR/Unlit/EvaluateMaterialData.template index d2ba12ff949..fa694289aae 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Shaders/Templates/PlanarPrimitive/DXR/Unlit/EvaluateMaterialData.template +++ b/Packages/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Shaders/Templates/PlanarPrimitive/DXR/Unlit/EvaluateMaterialData.template @@ -9,6 +9,7 @@ void EvaluateUnlitMaterialData(in AttributeData attributeData, out float4 outCol // Load the VFX attributes that we need for this ${VFXLoadAttributes} ${VFXProcessBlocks} + float2 uv = attributeData.barycentrics; ${VFXGetColorRT} // Return the color diff --git a/Packages/com.unity.render-pipelines.high-definition/Runtime/Tools/ColorCheckerTool.cs b/Packages/com.unity.render-pipelines.high-definition/Runtime/Tools/ColorCheckerTool.cs index fb9cd9ea978..58c3c25b5ac 100644 --- a/Packages/com.unity.render-pipelines.high-definition/Runtime/Tools/ColorCheckerTool.cs +++ b/Packages/com.unity.render-pipelines.high-definition/Runtime/Tools/ColorCheckerTool.cs @@ -3,13 +3,14 @@ using System.Collections; using UnityEngine; using UnityEngine.Rendering; - +using UnityEngine.Rendering.HighDefinition; [ExecuteInEditMode] [SelectionBaseAttribute] /// /// This component generates a procedural color checker. /// +[HDRPHelpURL("color-checker-tool-reference")] public class ColorCheckerTool : MonoBehaviour { /// diff --git a/Packages/com.unity.render-pipelines.universal/Editor/2D/LightBatchingDebugger/LightBatchingDebugger.cs b/Packages/com.unity.render-pipelines.universal/Editor/2D/LightBatchingDebugger/LightBatchingDebugger.cs index c0111c57645..67b44df185c 100644 --- a/Packages/com.unity.render-pipelines.universal/Editor/2D/LightBatchingDebugger/LightBatchingDebugger.cs +++ b/Packages/com.unity.render-pipelines.universal/Editor/2D/LightBatchingDebugger/LightBatchingDebugger.cs @@ -48,16 +48,20 @@ public static void ShowExample() private Vector3 cachedCamPos; ILight2DCullResult lightCullResult + { + get + { + return renderer2DData?.lightCullResult; + } + } + + Renderer2DData renderer2DData { get { // Game view main camera var renderer = Camera.main?.GetUniversalAdditionalCameraData().scriptableRenderer as Renderer2D; - var data = renderer?.GetRenderer2DData(); - if (data != null && data.lightCullResult.IsGameView()) - return data?.lightCullResult; - - return null; + return renderer?.GetRenderer2DData(); } } @@ -69,7 +73,7 @@ private bool PopulateData() batchList.Clear(); var layers = Light2DManager.GetCachedSortingLayer(); - var batches = LayerUtility.CalculateBatches(lightCullResult, out var batchCount); + var batches = LayerUtility.CalculateBatches(renderer2DData, out var batchCount); for (var i = 0; i < batchCount; i++) { diff --git a/Packages/com.unity.render-pipelines.universal/Editor/Camera/UniversalRenderPipelineCameraUI.Drawers.cs b/Packages/com.unity.render-pipelines.universal/Editor/Camera/UniversalRenderPipelineCameraUI.Drawers.cs index 3d1880e244d..b98125c0477 100644 --- a/Packages/com.unity.render-pipelines.universal/Editor/Camera/UniversalRenderPipelineCameraUI.Drawers.cs +++ b/Packages/com.unity.render-pipelines.universal/Editor/Camera/UniversalRenderPipelineCameraUI.Drawers.cs @@ -7,7 +7,7 @@ namespace UnityEditor.Rendering.Universal static partial class UniversalRenderPipelineCameraUI { - [URPHelpURL("cameras")] + [URPHelpURL("camera-component-reference")] public enum Expandable { /// Projection diff --git a/Packages/com.unity.render-pipelines.universal/Runtime/2D/Light2DManager.cs b/Packages/com.unity.render-pipelines.universal/Runtime/2D/Light2DManager.cs index 87e525cea2a..1fe354baf54 100644 --- a/Packages/com.unity.render-pipelines.universal/Runtime/2D/Light2DManager.cs +++ b/Packages/com.unity.render-pipelines.universal/Runtime/2D/Light2DManager.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Linq; namespace UnityEngine.Rendering.Universal { @@ -9,6 +8,20 @@ internal static class Light2DManager public static List lights { get; } = new List(); + internal static void Initialize() + { +#if UNITY_EDITOR + SortingLayer.onLayerChanged += OnSortingLayerChanged; +#endif + } + + internal static void Dispose() + { +#if UNITY_EDITOR + SortingLayer.onLayerChanged -= OnSortingLayerChanged; +#endif + } + // Called during OnEnable public static void RegisterLight(Light2D light) { @@ -108,5 +121,13 @@ public static SortingLayer[] GetCachedSortingLayer() return s_SortingLayers; } + +#if UNITY_EDITOR + internal static void OnSortingLayerChanged() + { + // Update sorting layers that were added or removed or changed order + s_SortingLayers = SortingLayer.layers; + } +#endif } } diff --git a/Packages/com.unity.render-pipelines.universal/Runtime/2D/Passes/Render2DLightingPass.cs b/Packages/com.unity.render-pipelines.universal/Runtime/2D/Passes/Render2DLightingPass.cs index 05664a160a9..336c8278a57 100644 --- a/Packages/com.unity.render-pipelines.universal/Runtime/2D/Passes/Render2DLightingPass.cs +++ b/Packages/com.unity.render-pipelines.universal/Runtime/2D/Passes/Render2DLightingPass.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using UnityEngine.Profiling; -using UnityEngine.Experimental.Rendering; namespace UnityEngine.Rendering.Universal { @@ -167,7 +166,6 @@ private int DrawLayerBatches( CommandBuffer cmd, ScriptableRenderContext context, ref RenderingData renderingData, - ref FilteringSettings filterSettings, ref DrawingSettings normalsDrawSettings, ref DrawingSettings drawSettings, ref RenderTextureDescriptor desc) @@ -206,7 +204,7 @@ private int DrawLayerBatches( if (layerBatch.useNormals) { - filterSettings.sortingLayerRange = layerBatch.layerRange; + LayerUtility.GetFilterSettings(m_Renderer2DData, ref layerBatch, out var filterSettings); var depthTarget = m_NeedsDepth ? depthAttachmentHandle : null; this.RenderNormals(context, renderingData, normalsDrawSettings, filterSettings, depthTarget, normalsFirstClear); normalsFirstClear = false; @@ -284,23 +282,18 @@ private int DrawLayerBatches( copyStoreAction = resolveDuringBatch == i && resolveIsAfterCopy ? RenderBufferStoreAction.Resolve : RenderBufferStoreAction.StoreAndResolve; else copyStoreAction = RenderBufferStoreAction.Store; - // If our camera sorting layer texture bound is inside our batch we need to break up the DrawRenderers into two batches - if (cameraSortingLayerBoundsIndex >= layerBatch.layerRange.lowerBound && cameraSortingLayerBoundsIndex < layerBatch.layerRange.upperBound && m_Renderer2DData.useCameraSortingLayerTexture) - { - filterSettings.sortingLayerRange = new SortingLayerRange(layerBatch.layerRange.lowerBound, cameraSortingLayerBoundsIndex); - Render(context, cmd, ref renderingData, ref filterSettings, drawSettings); - CopyCameraSortingLayerRenderTexture(context, renderingData, copyStoreAction); - filterSettings.sortingLayerRange = new SortingLayerRange((short)(cameraSortingLayerBoundsIndex + 1), layerBatch.layerRange.upperBound); - Render(context, cmd, ref renderingData, ref filterSettings, drawSettings); - } - else - { - filterSettings.sortingLayerRange = new SortingLayerRange(layerBatch.layerRange.lowerBound, layerBatch.layerRange.upperBound); - Render(context, cmd, ref renderingData, ref filterSettings, drawSettings); - if (cameraSortingLayerBoundsIndex == layerBatch.layerRange.upperBound && m_Renderer2DData.useCameraSortingLayerTexture) + LayerUtility.GetFilterSettings(m_Renderer2DData, ref layerBatch, out var filterSettings); + + Render(context, cmd, ref renderingData, ref filterSettings, drawSettings); + + if (m_Renderer2DData.useCameraSortingLayerTexture) + { + if (cameraSortingLayerBoundsIndex >= layerBatch.layerRange.lowerBound && cameraSortingLayerBoundsIndex <= layerBatch.layerRange.upperBound) + { CopyCameraSortingLayerRenderTexture(context, renderingData, copyStoreAction); + } } RendererLighting.DisableAllKeywords(CommandBufferHelpers.GetRasterCommandBuffer(cmd)); @@ -389,11 +382,11 @@ public override void Execute(ScriptableRenderContext context, ref RenderingData ShadowRendering.CallOnBeforeRender(renderingData.cameraData.camera, m_Renderer2DData.lightCullResult); - var layerBatches = LayerUtility.CalculateBatches(m_Renderer2DData.lightCullResult, out var batchCount); + var layerBatches = LayerUtility.CalculateBatches(m_Renderer2DData, out var batchCount); var batchesDrawn = 0; for (var i = 0; i < batchCount; i += batchesDrawn) - batchesDrawn = DrawLayerBatches(layerBatches, batchCount, i, cmd, context, ref renderingData, ref filterSettings, ref normalsDrawSettings, ref combinedDrawSettings, ref desc); + batchesDrawn = DrawLayerBatches(layerBatches, batchCount, i, cmd, context, ref renderingData, ref normalsDrawSettings, ref combinedDrawSettings, ref desc); RendererLighting.DisableAllKeywords(CommandBufferHelpers.GetRasterCommandBuffer(cmd)); context.ExecuteCommandBuffer(cmd); diff --git a/Packages/com.unity.render-pipelines.universal/Runtime/2D/Passes/Utility/LayerUtility.cs b/Packages/com.unity.render-pipelines.universal/Runtime/2D/Passes/Utility/LayerUtility.cs index 42866e800dc..586b32a2d5e 100644 --- a/Packages/com.unity.render-pipelines.universal/Runtime/2D/Passes/Utility/LayerUtility.cs +++ b/Packages/com.unity.render-pipelines.universal/Runtime/2D/Passes/Utility/LayerUtility.cs @@ -103,13 +103,31 @@ private static bool CanBatchLightsInLayer(int layerIndex1, int layerIndex2, Sort return true; } - private static int FindUpperBoundInBatch(int startLayerIndex, SortingLayer[] sortingLayers, ILight2DCullResult lightCullResult) + private static bool CanBatchCameraSortingLayer(int startLayerIndex, SortingLayer[] sortingLayers, Renderer2DData rendererData) { + if (rendererData.useCameraSortingLayerTexture) + { + var cameraSortingLayerBoundsIndex = Render2DLightingPass.GetCameraSortingLayerBoundsIndex(rendererData); + return sortingLayers[startLayerIndex].value == cameraSortingLayerBoundsIndex; + } + + return false; + } + + private static int FindUpperBoundInBatch(int startLayerIndex, SortingLayer[] sortingLayers, Renderer2DData rendererData) + { + // break layer if camera sorting layer is active + if (CanBatchCameraSortingLayer(startLayerIndex, sortingLayers, rendererData)) + return startLayerIndex; + // start checking at the next layer for (var i = startLayerIndex + 1; i < sortingLayers.Length; i++) { - if (!CanBatchLightsInLayer(startLayerIndex, i, sortingLayers, lightCullResult)) + if (!CanBatchLightsInLayer(startLayerIndex, i, sortingLayers, rendererData.lightCullResult)) return i - 1; + + if (CanBatchCameraSortingLayer(i, sortingLayers, rendererData)) + return i; } return sortingLayers.Length - 1; } @@ -141,7 +159,7 @@ private static void InitializeBatchInfos(SortingLayer[] cachedSortingLayers) } } - public static LayerBatch[] CalculateBatches(ILight2DCullResult lightCullResult, out int batchCount) + public static LayerBatch[] CalculateBatches(Renderer2DData rendererData, out int batchCount) { var cachedSortingLayers = Light2DManager.GetCachedSortingLayer(); InitializeBatchInfos(cachedSortingLayers); @@ -152,10 +170,10 @@ public static LayerBatch[] CalculateBatches(ILight2DCullResult lightCullResult, { var layerToRender = cachedSortingLayers[i].id; ref var layerBatch = ref s_LayerBatches[batchCount++]; - var lightStats = lightCullResult.GetLightStatsByLayer(layerToRender, ref layerBatch); + var lightStats = rendererData.lightCullResult.GetLightStatsByLayer(layerToRender, ref layerBatch); // Find the highest layer that share the same set of lights and shadows as this layer. - var upperLayerInBatch = FindUpperBoundInBatch(i, cachedSortingLayers, lightCullResult); + var upperLayerInBatch = FindUpperBoundInBatch(i, cachedSortingLayers, rendererData); // Some renderers override their sorting layer value with short.MinValue or short.MaxValue. // When drawing the first sorting layer, we should include the range from short.MinValue to layerValue. @@ -195,19 +213,13 @@ public static LayerBatch[] CalculateBatches(ILight2DCullResult lightCullResult, return s_LayerBatches; } - public static void GetFilterSettings(Renderer2DData rendererData, ref LayerBatch layerBatch, short cameraSortingLayerBoundsIndex, out FilteringSettings filterSettings) + public static void GetFilterSettings(Renderer2DData rendererData, ref LayerBatch layerBatch, out FilteringSettings filterSettings) { filterSettings = FilteringSettings.defaultValue; filterSettings.renderQueueRange = RenderQueueRange.all; filterSettings.layerMask = -1; filterSettings.renderingLayerMask = 0xFFFFFFFF; - - short upperBound = layerBatch.layerRange.upperBound; - - if (rendererData.useCameraSortingLayerTexture && cameraSortingLayerBoundsIndex >= layerBatch.layerRange.lowerBound && cameraSortingLayerBoundsIndex < layerBatch.layerRange.upperBound) - upperBound = cameraSortingLayerBoundsIndex; - - filterSettings.sortingLayerRange = new SortingLayerRange(layerBatch.layerRange.lowerBound, upperBound); + filterSettings.sortingLayerRange = layerBatch.layerRange; } static void SetupActiveBlendStyles() diff --git a/Packages/com.unity.render-pipelines.universal/Runtime/2D/Renderer2D.cs b/Packages/com.unity.render-pipelines.universal/Runtime/2D/Renderer2D.cs index f69a8b0be85..37ea0047a97 100644 --- a/Packages/com.unity.render-pipelines.universal/Runtime/2D/Renderer2D.cs +++ b/Packages/com.unity.render-pipelines.universal/Runtime/2D/Renderer2D.cs @@ -112,6 +112,8 @@ public Renderer2D(Renderer2DData data) : base(data) LensFlareCommonSRP.mergeNeeded = 0; LensFlareCommonSRP.maxLensFlareWithOcclusionTemporalSample = 1; LensFlareCommonSRP.Initialize(); + + Light2DManager.Initialize(); } protected override void Dispose(bool disposing) @@ -127,6 +129,7 @@ protected override void Dispose(bool disposing) m_FinalBlitPass?.Dispose(); m_DrawOffscreenUIPass?.Dispose(); m_DrawOverlayUIPass?.Dispose(); + Light2DManager.Dispose(); CoreUtils.Destroy(m_BlitMaterial); CoreUtils.Destroy(m_BlitHDRMaterial); diff --git a/Packages/com.unity.render-pipelines.universal/Runtime/2D/Rendergraph/CopyCameraSortingLayerPass.cs b/Packages/com.unity.render-pipelines.universal/Runtime/2D/Rendergraph/CopyCameraSortingLayerPass.cs index 7b12a3b4a76..c6a2b9b8d9d 100644 --- a/Packages/com.unity.render-pipelines.universal/Runtime/2D/Rendergraph/CopyCameraSortingLayerPass.cs +++ b/Packages/com.unity.render-pipelines.universal/Runtime/2D/Rendergraph/CopyCameraSortingLayerPass.cs @@ -11,7 +11,7 @@ internal class CopyCameraSortingLayerPass : ScriptableRenderPass private static readonly ProfilingSampler m_ProfilingSampler = new ProfilingSampler(k_CopyCameraSortingLayerPass); private static readonly ProfilingSampler m_ExecuteProfilingSampler = new ProfilingSampler("Copy"); internal static readonly string k_CameraSortingLayerTexture = "_CameraSortingLayerTexture"; - private static readonly int k_CameraSortingLayerTextureId = Shader.PropertyToID(k_CameraSortingLayerTexture); + internal static readonly int k_CameraSortingLayerTextureId = Shader.PropertyToID(k_CameraSortingLayerTexture); static Material m_BlitMaterial; public CopyCameraSortingLayerPass(Material blitMaterial) @@ -57,18 +57,19 @@ class PassData internal TextureHandle source; } - public void Render(RenderGraph graph, in TextureHandle cameraColorAttachment, in TextureHandle destination) + public void Render(RenderGraph graph, ContextContainer frameData) { + UniversalResourceData commonResourceData = frameData.Get(); + Universal2DResourceData universal2DResourceData = frameData.Get(); + using (var builder = graph.AddRasterRenderPass(k_CopyCameraSortingLayerPass, out var passData, m_ProfilingSampler)) { - passData.source = cameraColorAttachment; + passData.source = commonResourceData.activeColorTexture; - builder.SetRenderAttachment(destination, 0); + builder.SetRenderAttachment(universal2DResourceData.cameraSortingLayerTexture, 0); builder.UseTexture(passData.source); builder.AllowPassCulling(false); - builder.SetGlobalTextureAfterPass(destination, k_CameraSortingLayerTextureId); - builder.SetRenderFunc((PassData data, RasterGraphContext context) => { Execute(context.cmd, data.source); diff --git a/Packages/com.unity.render-pipelines.universal/Runtime/2D/Rendergraph/DrawNormal2DPass.cs b/Packages/com.unity.render-pipelines.universal/Runtime/2D/Rendergraph/DrawNormal2DPass.cs index bd151105ed8..49a99b14a19 100644 --- a/Packages/com.unity.render-pipelines.universal/Runtime/2D/Rendergraph/DrawNormal2DPass.cs +++ b/Packages/com.unity.render-pipelines.universal/Runtime/2D/Rendergraph/DrawNormal2DPass.cs @@ -41,11 +41,7 @@ public void Render(RenderGraph graph, ContextContainer frameData, Renderer2DData using (var builder = graph.AddRasterRenderPass(k_NormalPass, out var passData, m_ProfilingSampler)) { - var filterSettings = FilteringSettings.defaultValue; - filterSettings.renderQueueRange = RenderQueueRange.all; - filterSettings.layerMask = -1; - filterSettings.renderingLayerMask = 0xFFFFFFFF; - filterSettings.sortingLayerRange = new SortingLayerRange(layerBatch.layerRange.lowerBound, layerBatch.layerRange.upperBound); + LayerUtility.GetFilterSettings(rendererData, ref layerBatch, out var filterSettings); var drawSettings = CreateDrawingSettings(k_NormalsRenderingPassName, renderingData, cameraData, lightData, SortingCriteria.CommonTransparent); var sortSettings = drawSettings.sortingSettings; diff --git a/Packages/com.unity.render-pipelines.universal/Runtime/2D/Rendergraph/GlobalPropertiesPass.cs b/Packages/com.unity.render-pipelines.universal/Runtime/2D/Rendergraph/GlobalPropertiesPass.cs index 2b8b6b2bb8c..fb1e2c41f3d 100644 --- a/Packages/com.unity.render-pipelines.universal/Runtime/2D/Rendergraph/GlobalPropertiesPass.cs +++ b/Packages/com.unity.render-pipelines.universal/Runtime/2D/Rendergraph/GlobalPropertiesPass.cs @@ -16,8 +16,10 @@ class PassData internal Vector2Int screenParams; } - internal static void Setup(RenderGraph graph, UniversalCameraData cameraData) + internal static void Setup(RenderGraph graph, ContextContainer frameData, Renderer2DData rendererData, UniversalCameraData cameraData) { + Universal2DResourceData universal2DResourceData = frameData.Get(); + using (var builder = graph.AddRasterRenderPass(k_SetGlobalProperties, out var passData, m_SetGlobalPropertiesProfilingSampler)) { // Set screenParams when pixel perfect camera is used with the reference resolution @@ -36,6 +38,9 @@ internal static void Setup(RenderGraph graph, UniversalCameraData cameraData) builder.SetGlobalTextureAfterPass(graph.defaultResources.whiteTexture, k_DefaultWhiteTextureID); #endif + if (rendererData.useCameraSortingLayerTexture) + builder.SetGlobalTextureAfterPass(universal2DResourceData.cameraSortingLayerTexture, CopyCameraSortingLayerPass.k_CameraSortingLayerTextureId); + builder.AllowPassCulling(false); builder.AllowGlobalStateModification(true); diff --git a/Packages/com.unity.render-pipelines.universal/Runtime/2D/Rendergraph/Renderer2DRendergraph.cs b/Packages/com.unity.render-pipelines.universal/Runtime/2D/Rendergraph/Renderer2DRendergraph.cs index a47e518bebb..d49e919ceee 100644 --- a/Packages/com.unity.render-pipelines.universal/Runtime/2D/Rendergraph/Renderer2DRendergraph.cs +++ b/Packages/com.unity.render-pipelines.universal/Runtime/2D/Rendergraph/Renderer2DRendergraph.cs @@ -144,7 +144,7 @@ void InitializeLayerBatches() { Universal2DResourceData resourceData = frameData.Get(); - m_LayerBatches = LayerUtility.CalculateBatches(m_Renderer2DData.lightCullResult, out m_BatchCount); + m_LayerBatches = LayerUtility.CalculateBatches(m_Renderer2DData, out m_BatchCount); // Initialize textures dependent on batch size if (resourceData.normalsTexture.Length != m_BatchCount) @@ -529,7 +529,7 @@ private void OnMainRendering(RenderGraph renderGraph) var cameraSortingLayerBoundsIndex = Render2DLightingPass.GetCameraSortingLayerBoundsIndex(m_Renderer2DData); // Set Global Properties and Textures - GlobalPropertiesPass.Setup(renderGraph, cameraData); + GlobalPropertiesPass.Setup(renderGraph, frameData, m_Renderer2DData, cameraData); // Main render passes @@ -557,7 +557,7 @@ private void OnMainRendering(RenderGraph renderGraph) ref var layerBatch = ref m_LayerBatches[i]; - LayerUtility.GetFilterSettings(m_Renderer2DData, ref m_LayerBatches[i], cameraSortingLayerBoundsIndex, out var filterSettings); + LayerUtility.GetFilterSettings(m_Renderer2DData, ref m_LayerBatches[i], out var filterSettings); m_RendererPass.Render(renderGraph, frameData, m_Renderer2DData, ref m_LayerBatches, i, ref filterSettings); // Shadow Volumetric Pass @@ -569,17 +569,9 @@ private void OnMainRendering(RenderGraph renderGraph) // Camera Sorting Layer Pass if (m_Renderer2DData.useCameraSortingLayerTexture) { - // Split Render Pass if CameraSortingLayer is in the middle of a batch - if (cameraSortingLayerBoundsIndex >= layerBatch.layerRange.lowerBound && cameraSortingLayerBoundsIndex < layerBatch.layerRange.upperBound) + if (cameraSortingLayerBoundsIndex >= layerBatch.layerRange.lowerBound && cameraSortingLayerBoundsIndex <= layerBatch.layerRange.upperBound) { - m_CopyCameraSortingLayerPass.Render(renderGraph, commonResourceData.activeColorTexture, universal2DResourceData.cameraSortingLayerTexture); - - filterSettings.sortingLayerRange = new SortingLayerRange((short)(cameraSortingLayerBoundsIndex + 1), layerBatch.layerRange.upperBound); - m_RendererPass.Render(renderGraph, frameData, m_Renderer2DData, ref m_LayerBatches, i, ref filterSettings); - } - else if (cameraSortingLayerBoundsIndex == layerBatch.layerRange.upperBound) - { - m_CopyCameraSortingLayerPass.Render(renderGraph, commonResourceData.activeColorTexture, universal2DResourceData.cameraSortingLayerTexture); + m_CopyCameraSortingLayerPass.Render(renderGraph, frameData); } } } diff --git a/Packages/com.unity.render-pipelines.universal/Runtime/ForwardLights.cs b/Packages/com.unity.render-pipelines.universal/Runtime/ForwardLights.cs index 39923aad370..e6e5e141728 100644 --- a/Packages/com.unity.render-pipelines.universal/Runtime/ForwardLights.cs +++ b/Packages/com.unity.render-pipelines.universal/Runtime/ForwardLights.cs @@ -506,6 +506,8 @@ internal void Cleanup() m_TileMasksBuffer = null; m_ReflectionProbeManager.Dispose(); } + m_LightCookieManager?.Dispose(); + m_LightCookieManager = null; } void InitializeLightConstants(NativeArray lights, int lightIndex, bool supportsLightLayers, out Vector4 lightPos, out Vector4 lightColor, out Vector4 lightAttenuation, out Vector4 lightSpotDir, out Vector4 lightOcclusionProbeChannel, out uint lightLayerMask, out bool isSubtractive) diff --git a/Packages/com.unity.render-pipelines.universal/ShaderLibrary/DBuffer.hlsl b/Packages/com.unity.render-pipelines.universal/ShaderLibrary/DBuffer.hlsl index 3023b08ce00..18617146701 100644 --- a/Packages/com.unity.render-pipelines.universal/ShaderLibrary/DBuffer.hlsl +++ b/Packages/com.unity.render-pipelines.universal/ShaderLibrary/DBuffer.hlsl @@ -139,7 +139,7 @@ void ApplyDecal(float4 positionCS, // Always test the normal as we can have decompression artifact if (decalSurfaceData.normalWS.w < 1.0) { - normalWS.xyz = normalize(normalWS.xyz * decalSurfaceData.normalWS.w + decalSurfaceData.normalWS.xyz); + normalWS.xyz = SafeNormalize(normalWS.xyz * decalSurfaceData.normalWS.w + decalSurfaceData.normalWS.xyz); } #endif diff --git a/Packages/com.unity.shadergraph/Editor/Drawing/Inspector/MasterPreviewView.cs b/Packages/com.unity.shadergraph/Editor/Drawing/Inspector/MasterPreviewView.cs index 5037063cdb4..6780a27ef64 100644 --- a/Packages/com.unity.shadergraph/Editor/Drawing/Inspector/MasterPreviewView.cs +++ b/Packages/com.unity.shadergraph/Editor/Drawing/Inspector/MasterPreviewView.cs @@ -1,22 +1,19 @@ using System; using System.Collections.Generic; -using System.Diagnostics.Eventing.Reader; using System.Linq; using System.Reflection; using UnityEngine; using UnityEditor.Graphing; using UnityEditor.Graphing.Util; -using UnityEditor.ShaderGraph.Internal; +using UnityEditor.ShaderGraph.Drawing.Interfaces; using Object = UnityEngine.Object; using UnityEditor.UIElements; using UnityEngine.UIElements; -using UnityEngine.UIElements.StyleSheets; -using UnityEditor.SearchService; namespace UnityEditor.ShaderGraph.Drawing.Inspector { - class MasterPreviewView : VisualElement + class MasterPreviewView : VisualElement, ISGResizable { PreviewManager m_PreviewManager; GraphData m_Graph; @@ -34,14 +31,7 @@ public Image previewTextureView Mesh m_PreviousMesh; - bool m_RecalculateLayout; - - ResizeBorderFrame m_PreviewResizeBorderFrame; - - public ResizeBorderFrame previewResizeBorderFrame - { - get { return m_PreviewResizeBorderFrame; } - } + ResizableElement m_ResizableElement; VisualElement m_Preview; Label m_Title; @@ -54,13 +44,14 @@ public VisualElement preview List m_DoNotShowPrimitives = new List(new string[] { PrimitiveType.Plane.ToString() }); static Type s_ObjectSelector = AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => x.GetTypesOrNothing()).FirstOrDefault(t => t.FullName == "UnityEditor.ObjectSelector"); - public string assetName { get { return m_Title.text; } set { m_Title.text = value; } } + public Action onResized; + public MasterPreviewView(PreviewManager previewManager, GraphData graph) { style.overflow = Overflow.Hidden; @@ -75,6 +66,9 @@ public MasterPreviewView(PreviewManager previewManager, GraphData graph) m_PreviewRenderHandle.onPreviewChanged += OnPreviewChanged; } + var mainContainer = new VisualElement(); + mainContainer.AddToClassList("mainContainer"); + var topContainer = new VisualElement() { name = "top" }; { m_Title = new Label() { name = "title" }; @@ -82,7 +76,7 @@ public MasterPreviewView(PreviewManager previewManager, GraphData graph) topContainer.Add(m_Title); } - Add(topContainer); + mainContainer.Add(topContainer); m_Preview = new VisualElement { name = "middle" }; { @@ -91,14 +85,14 @@ public MasterPreviewView(PreviewManager previewManager, GraphData graph) preview.Add(m_PreviewTextureView); preview.AddManipulator(new Scrollable(OnScroll)); } - Add(preview); + mainContainer.Add(preview); + + Add(mainContainer); - m_PreviewResizeBorderFrame = new ResizeBorderFrame(this, this) { name = "resizeBorderFrame" }; - m_PreviewResizeBorderFrame.maintainAspectRatio = true; - Add(m_PreviewResizeBorderFrame); + m_ResizableElement = new ResizableElement(); + Add(m_ResizableElement); - m_RecalculateLayout = false; - this.RegisterCallback(OnGeometryChanged); + RegisterCallback(OnGeometryChanged); } Image CreatePreview(Texture texture) @@ -191,15 +185,6 @@ void ChangeMeshCustom() void OnGeometryChanged(GeometryChangedEvent evt) { - if (m_RecalculateLayout) - { - WindowDockingLayout dockingLayout = new WindowDockingLayout(); - dockingLayout.CalculateDockingCornerAndOffset(layout, parent.layout); - dockingLayout.ClampToParentWindow(); - dockingLayout.ApplyPosition(this); - m_RecalculateLayout = false; - } - var currentWidth = m_PreviewRenderHandle?.texture != null ? m_PreviewRenderHandle.texture.width : -1; var currentHeight = m_PreviewRenderHandle?.texture != null ? m_PreviewRenderHandle.texture.height : -1; @@ -210,7 +195,10 @@ void OnGeometryChanged(GeometryChangedEvent evt) return; m_PreviewTextureView.style.width = evt.newRect.width; - m_PreviewTextureView.style.height = evt.newRect.height - 40.0f; + + const float offsetFromHeader = 40.0f; + const float offsetFromMargin = 2 * 6.0f; + m_PreviewTextureView.style.height = evt.newRect.height - (offsetFromHeader + offsetFromMargin); m_PreviewManager.ResizeMasterPreview(new Vector2(evt.newRect.width, evt.newRect.width)); } @@ -235,5 +223,17 @@ void OnMouseDragPreviewMesh(Vector2 deltaMouse) m_PreviewManager.UpdateMasterPreview(ModificationScope.Node); } + + public void OnStartResize() + { + } + + public void OnResized() + { + onResized?.Invoke(); + } + + public bool CanResizePastParentBounds() => false; + public bool KeepSquareAspect() => true; } } diff --git a/Packages/com.unity.shadergraph/Editor/Drawing/Interfaces/IResizable.cs b/Packages/com.unity.shadergraph/Editor/Drawing/Interfaces/IResizable.cs index e0941391ceb..6e712ce7f85 100644 --- a/Packages/com.unity.shadergraph/Editor/Drawing/Interfaces/IResizable.cs +++ b/Packages/com.unity.shadergraph/Editor/Drawing/Interfaces/IResizable.cs @@ -6,5 +6,8 @@ interface ISGResizable : IResizable { // Depending on the return value, the ElementResizer either allows resizing past parent view edge (like in case of StickyNote) or clamps the size at the edges of parent view (like for GraphSubWindows) bool CanResizePastParentBounds(); + + // If true, element will be kept square when resizing. Otherwise, both axes can be resized freely. + bool KeepSquareAspect() => false; } } diff --git a/Packages/com.unity.shadergraph/Editor/Drawing/Manipulators/ElementResizer.cs b/Packages/com.unity.shadergraph/Editor/Drawing/Manipulators/ElementResizer.cs index 5c99ce352d9..4d5fda89b98 100644 --- a/Packages/com.unity.shadergraph/Editor/Drawing/Manipulators/ElementResizer.cs +++ b/Packages/com.unity.shadergraph/Editor/Drawing/Manipulators/ElementResizer.cs @@ -1,6 +1,5 @@ using System; using UnityEditor.ShaderGraph.Drawing.Interfaces; -using UnityEditor.ShaderGraph.Drawing.Views; using UnityEngine; using UnityEngine.UIElements; @@ -9,6 +8,7 @@ namespace UnityEditor.ShaderGraph.Drawing class ElementResizer : Manipulator { bool m_IsEnabled = true; + public bool isEnabled { get => m_IsEnabled; @@ -84,49 +84,158 @@ void OnMouseDown(MouseDownEvent e) } } + void ApplyLayoutToTargetAsStyle(Rect rect) + { + var resizedTarget = resizedElement.parent; + resizedTarget.style.left = rect.x; + resizedTarget.style.top = rect.y; + resizedTarget.style.width = rect.width; + resizedTarget.style.height = rect.height; + } + + static Rect CropToParent(Rect rect, Rect parent) + { + rect.xMin = Mathf.Max(rect.xMin, parent.xMin); + rect.yMin = Mathf.Max(rect.yMin, parent.yMin); + rect.xMax = Mathf.Min(rect.xMax, parent.xMax); + rect.yMax = Mathf.Min(rect.yMax, parent.yMax); + return rect; + } + + static float GetSquareSize(Rect rect, ResizableElement.Resizer resizeDirection) + { + var horizontal = (resizeDirection & (ResizableElement.Resizer.Left | ResizableElement.Resizer.Right)) != 0; + var vertical = (resizeDirection & (ResizableElement.Resizer.Top | ResizableElement.Resizer.Bottom)) != 0; + + if (horizontal && vertical) + { + return Mathf.Min(rect.width, rect.height); + } + + return horizontal ? rect.width : rect.height; + } + + Rect ApplySquareAspect(Rect element, ResizableElement.Resizer resizeDirection, Rect? keepInParent = null) + { + var newLayout = element; + var size = GetSquareSize(element, resizeDirection); + + size = Mathf.Clamp(size, m_MinSize.x, m_MaxSize.x); + size = Mathf.Clamp(size, m_MinSize.y, m_MaxSize.y); + ResizeNewLayoutAndFixPosition(resizeDirection, size); + + if (keepInParent is { } parentRect) + { + newLayout = CropToParent(newLayout, parentRect); + size = Mathf.Min(newLayout.width, newLayout.height); + ResizeNewLayoutAndFixPosition(resizeDirection, size); + } + + return newLayout; + + void ResizeNewLayoutAndFixPosition(ResizableElement.Resizer grabbedSide, float newSize) + { + newLayout.width = newSize; + newLayout.height = newSize; + + var deltaWidth = element.width - newSize; + var deltaHeight = element.height - newSize; + + // Anchoring rules were written with the main preview in mind, which is in the bottom-right corner + // by default. + switch (grabbedSide) + { + // Anchor to bottom-right. + case ResizableElement.Resizer.Top: + case ResizableElement.Resizer.Top | ResizableElement.Resizer.Left: + case ResizableElement.Resizer.Left: + { + newLayout.x = element.x + deltaWidth; + newLayout.y = element.y + deltaHeight; + break; + } + + // Anchor to bottom-left. + case ResizableElement.Resizer.Top | ResizableElement.Resizer.Right: + { + newLayout.y = element.y + deltaHeight; + break; + } + + // Anchor to top-left. + case ResizableElement.Resizer.Right: + case ResizableElement.Resizer.Bottom | ResizableElement.Resizer.Right: + case ResizableElement.Resizer.Bottom: + { + // Element is positioned by its top-left, so no adjustment is needed. + break; + } + + // Anchor to top-right. + case ResizableElement.Resizer.Bottom | ResizableElement.Resizer.Left: + { + newLayout.x = element.x + deltaWidth; + break; + } + + case ResizableElement.Resizer.None: + default: + break; + } + } + } + void OnMouseMove(MouseMoveEvent e) { if (!isEnabled) return; - VisualElement resizedTarget = resizedElement.parent; - VisualElement resizedBase = resizedTarget.parent; + var resizedTarget = resizedElement.parent; + var resizedBase = resizedTarget.parent; // Top left position of the parent visual element var parentRootPosition = resizedBase.worldBound; + // Top left of the target visual element for resizing var targetRootPosition = resizedTarget.worldBound; - var canResizePastParentBounds = ((ISGResizable)resizedTarget).CanResizePastParentBounds(); - Vector2 mousePos = resizedBase.WorldToLocal(e.mousePosition); + var sgResizable = resizedTarget as ISGResizable; + var canResizePastParentBounds = sgResizable?.CanResizePastParentBounds() ?? false; + var keepSquareAspect = sgResizable?.KeepSquareAspect() ?? false; + + var mousePos = resizedBase.WorldToLocal(e.mousePosition); if (!m_DragStarted) { - if (resizedTarget is ISGResizable resizable) - resizable.OnStartResize(); + sgResizable?.OnStartResize(); m_DragStarted = true; } + var newLayout = new Rect(m_StartPosition, m_StartSize); + if ((direction & ResizableElement.Resizer.Right) != 0) { - var newWidth = m_StartSize.x + mousePos.x - m_StartMouse.x; + newLayout.width = m_StartSize.x + mousePos.x - m_StartMouse.x; var parentRightBoundary = parentRootPosition.x + resizedBase.layout.width; + // Also ensure resizing does not happen past edge of parent views boundaries if the target does not allow it if (!canResizePastParentBounds) { - if ((targetRootPosition.x + newWidth) > parentRightBoundary) + if ((targetRootPosition.x + newLayout.width) > parentRightBoundary) { var targetToRightBoundaryDelta = parentRightBoundary - targetRootPosition.x; - newWidth = targetToRightBoundaryDelta; + newLayout.width = targetToRightBoundaryDelta; } + var newLayoutLeft = targetRootPosition.x - parentRootPosition.x; + // When resizing to right, make sure to calculate and set the target elements Style.left before resizing to ensure correct resizing behavior // If Style.left is NaNpx it results in scaling towards the left // This is due to how the WindowDockingLayout code affects GraphSubWindows - resizedTarget.style.left = newLayoutLeft; + newLayout.x = newLayoutLeft; } - resizedTarget.style.width = Mathf.Clamp(newWidth, m_MinSize.x, m_MaxSize.x); + newLayout.width = Mathf.Clamp(newLayout.width, m_MinSize.x, m_MaxSize.x); } else if ((direction & ResizableElement.Resizer.Left) != 0) { @@ -141,7 +250,7 @@ void OnMouseMove(MouseMoveEvent e) delta = -m_MaxSize.x + m_StartSize.x; } - var newWidth = -delta + m_StartSize.x; + newLayout.width = -delta + m_StartSize.x; var targetToLeftBoundaryDelta = delta + m_StartPosition.x; if (!canResizePastParentBounds) @@ -151,38 +260,36 @@ void OnMouseMove(MouseMoveEvent e) // Clamps width to max out at left edge of parent window if (Mathf.Approximately(targetToLeftBoundaryDelta, 2.5f)) - newWidth = (m_StartPosition.x + m_StartSize.x); + newLayout.width = (m_StartPosition.x + m_StartSize.x); - newWidth = Mathf.Clamp(newWidth, m_MinSize.x, m_MaxSize.x); + newLayout.width = Mathf.Clamp(newLayout.width, m_MinSize.x, m_MaxSize.x); } - resizedTarget.style.left = targetToLeftBoundaryDelta; - resizedTarget.style.width = newWidth; + newLayout.x = targetToLeftBoundaryDelta; } if ((direction & ResizableElement.Resizer.Bottom) != 0) { var delta = mousePos.y - m_StartMouse.y; - var newHeight = m_StartSize.y + delta; + newLayout.height = m_StartSize.y + delta; var parentBottomBoundary = parentRootPosition.y + resizedBase.layout.height; if (!canResizePastParentBounds) { - if ((targetRootPosition.y + newHeight) > parentBottomBoundary) + if ((targetRootPosition.y + newLayout.height) > parentBottomBoundary) { var targetToBottomBoundaryDelta = parentBottomBoundary - targetRootPosition.y; - newHeight = targetToBottomBoundaryDelta; + newLayout.height = targetToBottomBoundaryDelta; } + var targetToTopBoundaryDelta = targetRootPosition.y - parentRootPosition.y; + // When resizing to bottom, make sure to calculate and set the target elements Style.top before resizing to ensure correct resizing behavior // If Style.top is NaNpx it results in scaling towards the bottom // This is due to how the WindowDockingLayout code affects GraphSubWindows - resizedTarget.style.top = targetToTopBoundaryDelta; - - newHeight = Mathf.Clamp(newHeight, m_MinSize.y, m_MaxSize.y); + newLayout.y = targetToTopBoundaryDelta; + newLayout.height = Mathf.Clamp(newLayout.height, m_MinSize.y, m_MaxSize.y); } - - resizedTarget.style.height = newHeight; } else if ((direction & ResizableElement.Resizer.Top) != 0) { @@ -197,7 +304,7 @@ void OnMouseMove(MouseMoveEvent e) delta = -m_MaxSize.y + m_StartSize.y; } - var newHeight = -delta + m_StartSize.y; + newLayout.height = -delta + m_StartSize.y; var targetToTopBoundaryDelta = m_StartPosition.y + delta; if (!canResizePastParentBounds) { @@ -206,14 +313,24 @@ void OnMouseMove(MouseMoveEvent e) // Clamps height to max out at top edge of parent window if (Mathf.Approximately(targetToTopBoundaryDelta, 2.5f)) - newHeight = (m_StartPosition.y + m_StartSize.y); + newLayout.height = (m_StartPosition.y + m_StartSize.y); - newHeight = Mathf.Clamp(newHeight, m_MinSize.y, m_MaxSize.y); + newLayout.height = Mathf.Clamp(newLayout.height, m_MinSize.y, m_MaxSize.y); } - resizedTarget.style.top = targetToTopBoundaryDelta; - resizedTarget.style.height = newHeight; + newLayout.y = targetToTopBoundaryDelta; } + + if (keepSquareAspect) + { + newLayout = ApplySquareAspect( + newLayout, + direction, + canResizePastParentBounds ? null : new Rect(0, 0, parentRootPosition.width, parentRootPosition.height) + ); + } + + ApplyLayoutToTargetAsStyle(newLayout); e.StopPropagation(); } @@ -230,6 +347,7 @@ void OnMouseUp(MouseUpEvent e) if (resizedTarget is ISGResizable resizable) resizable.OnResized(); } + target.UnregisterCallback(OnMouseMove); target.ReleaseMouse(); e.StopPropagation(); diff --git a/Packages/com.unity.shadergraph/Editor/Drawing/Manipulators/ResizeBorderFrame.cs b/Packages/com.unity.shadergraph/Editor/Drawing/Manipulators/ResizeBorderFrame.cs deleted file mode 100644 index 719c800c610..00000000000 --- a/Packages/com.unity.shadergraph/Editor/Drawing/Manipulators/ResizeBorderFrame.cs +++ /dev/null @@ -1,71 +0,0 @@ -using System; -using System.Collections.Generic; -using UnityEngine; -using UnityEditor.ShaderGraph.Drawing; -using UnityEngine.Networking; -using UnityEngine.UIElements; - -class ResizeBorderFrame : VisualElement -{ - List m_ResizeSideHandles; - - bool m_MaintainApsectRatio; - - public bool maintainAspectRatio - { - get { return m_MaintainApsectRatio; } - set - { - m_MaintainApsectRatio = value; - foreach (ResizeSideHandle resizeHandle in m_ResizeSideHandles) - { - resizeHandle.maintainAspectRatio = value; - } - } - } - - public Action OnResizeFinished; - - public ResizeBorderFrame(VisualElement target) - { - InitializeResizeBorderFrame(target, target); - } - - public ResizeBorderFrame(VisualElement target, VisualElement container) - { - InitializeResizeBorderFrame(target, container); - } - - void InitializeResizeBorderFrame(VisualElement target, VisualElement container) - { - pickingMode = PickingMode.Ignore; - - AddToClassList("resizeBorderFrame"); - - m_ResizeSideHandles = new List(); - - // Add resize handles along the border - // m_ResizeSideHandles.Add(new ResizeSideHandle(target, container, ResizeHandleAnchor.TopLeft)); - // m_ResizeSideHandles.Add(new ResizeSideHandle(target, container, ResizeHandleAnchor.Top)); - // m_ResizeSideHandles.Add(new ResizeSideHandle(target, container, ResizeHandleAnchor.TopRight)); - // m_ResizeSideHandles.Add(new ResizeSideHandle(target, container, ResizeHandleAnchor.Right)); - m_ResizeSideHandles.Add(new ResizeSideHandle(target, container, ResizeHandleAnchor.BottomRight)); - // m_ResizeSideHandles.Add(new ResizeSideHandle(target, container, ResizeHandleAnchor.Bottom)); - // m_ResizeSideHandles.Add(new ResizeSideHandle(target, container, ResizeHandleAnchor.BottomLeft)); - // m_ResizeSideHandles.Add(new ResizeSideHandle(target, container, ResizeHandleAnchor.Left)); - - foreach (ResizeSideHandle resizeHandle in m_ResizeSideHandles) - { - resizeHandle.OnResizeFinished += HandleResizefinished; - Add(resizeHandle); - } - } - - void HandleResizefinished() - { - if (OnResizeFinished != null) - { - OnResizeFinished(); - } - } -} diff --git a/Packages/com.unity.shadergraph/Editor/Drawing/Manipulators/ResizeBorderFrame.cs.meta b/Packages/com.unity.shadergraph/Editor/Drawing/Manipulators/ResizeBorderFrame.cs.meta deleted file mode 100644 index c7684fba513..00000000000 --- a/Packages/com.unity.shadergraph/Editor/Drawing/Manipulators/ResizeBorderFrame.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 1128492b211994d46be4acd2ccac15fb -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/com.unity.shadergraph/Editor/Drawing/Manipulators/ResizeSideHandle.cs b/Packages/com.unity.shadergraph/Editor/Drawing/Manipulators/ResizeSideHandle.cs deleted file mode 100644 index 2060816d2fd..00000000000 --- a/Packages/com.unity.shadergraph/Editor/Drawing/Manipulators/ResizeSideHandle.cs +++ /dev/null @@ -1,365 +0,0 @@ -using System; -using UnityEngine; -using UnityEngine.UIElements; -using UnityEngine.UIElements.StyleSheets; - -namespace UnityEditor.ShaderGraph.Drawing -{ - enum ResizeDirection - { - Any, - Vertical, - Horizontal - } - - enum ResizeHandleAnchor - { - Top, - TopRight, - Right, - BottomRight, - Bottom, - BottomLeft, - Left, - TopLeft - } - - class ResizeSideHandle : ImmediateModeElement - { - VisualElement m_ResizeTarget; - VisualElement m_Container; - - WindowDockingLayout m_WindowDockingLayout; - - bool m_MaintainAspectRatio; - - public bool maintainAspectRatio - { - get { return m_MaintainAspectRatio; } - set { m_MaintainAspectRatio = value; } - } - - public Action OnResizeFinished; - - bool m_Dragging; - - Rect m_ResizeBeginLayout; - Vector2 m_ResizeBeginMousePosition; - - private GUIStyle m_StyleWidget; - private GUIStyle m_StyleLabel; - private Texture image { get; set; } - - public ResizeSideHandle(VisualElement resizeTarget, VisualElement container, ResizeHandleAnchor anchor) - { - m_WindowDockingLayout = new WindowDockingLayout(); - - m_ResizeTarget = resizeTarget; - m_Container = container; - - AddToClassList("resize"); - - switch (anchor) - { - case ResizeHandleAnchor.Top: - { - AddToClassList("vertical"); - AddToClassList("top"); - RegisterCallback(HandleResizeFromTop); - break; - } - case ResizeHandleAnchor.TopRight: - { - AddToClassList("diagonal"); - AddToClassList("top-right"); - RegisterCallback(HandleResizeFromTopRight); - break; - } - case ResizeHandleAnchor.Right: - { - AddToClassList("horizontal"); - AddToClassList("right"); - RegisterCallback(HandleResizeFromRight); - break; - } - case ResizeHandleAnchor.BottomRight: - { - AddToClassList("diagonal"); - AddToClassList("bottom-right"); - RegisterCallback(HandleResizeFromBottomRight); - break; - } - case ResizeHandleAnchor.Bottom: - { - AddToClassList("vertical"); - AddToClassList("bottom"); - RegisterCallback(HandleResizeFromBottom); - break; - } - case ResizeHandleAnchor.BottomLeft: - { - AddToClassList("diagonal"); - AddToClassList("bottom-left"); - RegisterCallback(HandleResizeFromBottomLeft); - break; - } - case ResizeHandleAnchor.Left: - { - AddToClassList("horizontal"); - AddToClassList("left"); - RegisterCallback(HandleResizeFromLeft); - break; - } - case ResizeHandleAnchor.TopLeft: - { - AddToClassList("diagonal"); - AddToClassList("top-left"); - RegisterCallback(HandleResizeFromTopLeft); - break; - } - } - - RegisterCallback(HandleMouseDown); - RegisterCallback(HandleDraggableMouseUp); - - m_ResizeTarget.RegisterCallback(InitialLayoutSetup); - } - - void InitialLayoutSetup(GeometryChangedEvent evt) - { - m_ResizeTarget.UnregisterCallback(InitialLayoutSetup); - } - - void HandleResizeFromTop(MouseMoveEvent mouseMoveEvent) - { - if (!m_Dragging) - return; - - Vector2 relativeMousePosition = mouseMoveEvent.mousePosition - m_ResizeBeginMousePosition; - - // Set anchor points for positioning - m_Container.style.top = float.NaN; - m_Container.style.bottom = m_Container.parent.layout.height - m_Container.layout.yMax; - - float newHeight = Mathf.Max(0f, m_ResizeBeginLayout.height - relativeMousePosition.y); - - m_ResizeTarget.style.height = newHeight; - - if (maintainAspectRatio) - m_ResizeTarget.style.width = newHeight; - - mouseMoveEvent.StopImmediatePropagation(); - } - - void HandleResizeFromTopRight(MouseMoveEvent mouseMoveEvent) - { - if (!m_Dragging) - return; - - Vector2 relativeMousePosition = mouseMoveEvent.mousePosition - m_ResizeBeginMousePosition; - - // Set anchor points for positioning - m_Container.style.top = float.NaN; - m_Container.style.bottom = m_Container.parent.layout.height - m_Container.layout.yMax; - m_Container.style.left = m_Container.layout.xMin; - m_Container.style.right = float.NaN; - - float newWidth = Mathf.Max(0f, m_ResizeBeginLayout.width + relativeMousePosition.x); - float newHeight = Mathf.Max(0f, m_ResizeBeginLayout.height - relativeMousePosition.y); - - if (maintainAspectRatio) - newWidth = newHeight = Mathf.Min(newWidth, newHeight); - - m_ResizeTarget.style.width = newWidth; - m_ResizeTarget.style.height = newHeight; - - mouseMoveEvent.StopPropagation(); - } - - void HandleResizeFromRight(MouseMoveEvent mouseMoveEvent) - { - if (!m_Dragging) - return; - - Vector2 relativeMousePosition = mouseMoveEvent.mousePosition - m_ResizeBeginMousePosition; - - // Set anchor points for positioning - m_Container.style.left = m_Container.layout.xMin; - m_Container.style.right = float.NaN; - - float newWidth = Mathf.Max(0f, m_ResizeBeginLayout.width + relativeMousePosition.x); - - m_ResizeTarget.style.width = newWidth; - - if (maintainAspectRatio) - { - m_ResizeTarget.style.height = newWidth; - } - - mouseMoveEvent.StopPropagation(); - } - - void HandleResizeFromBottomRight(MouseMoveEvent mouseMoveEvent) - { - if (!m_Dragging) - return; - - Vector2 relativeMousePosition = mouseMoveEvent.mousePosition - m_ResizeBeginMousePosition; - - // Set anchor points for positioning - m_Container.style.top = m_Container.layout.yMin; - m_Container.style.bottom = float.NaN; - m_Container.style.left = m_Container.layout.xMin; - m_Container.style.right = float.NaN; - - float newWidth = Mathf.Max(0f, m_ResizeBeginLayout.width + relativeMousePosition.x); - float newHeight = Mathf.Max(0f, m_ResizeBeginLayout.height + relativeMousePosition.y); - - if (maintainAspectRatio) - newWidth = newHeight = Mathf.Min(newWidth, newHeight); - - m_ResizeTarget.style.width = newWidth; - m_ResizeTarget.style.height = newHeight; - - mouseMoveEvent.StopPropagation(); - } - - void HandleResizeFromBottom(MouseMoveEvent mouseMoveEvent) - { - if (!m_Dragging) - return; - - Vector2 relativeMousePosition = mouseMoveEvent.mousePosition - m_ResizeBeginMousePosition; - - // Set anchor points for positioning - m_Container.style.top = m_Container.layout.yMin; - m_Container.style.bottom = float.NaN; - - float newHeight = Mathf.Max(0f, m_ResizeBeginLayout.height + relativeMousePosition.y); - - m_ResizeTarget.style.height = newHeight; - - if (maintainAspectRatio) - m_ResizeTarget.style.width = newHeight; - - mouseMoveEvent.StopPropagation(); - } - - void HandleResizeFromBottomLeft(MouseMoveEvent mouseMoveEvent) - { - if (!m_Dragging) - return; - - Vector2 relativeMousePosition = mouseMoveEvent.mousePosition - m_ResizeBeginMousePosition; - - // Set anchor points for positioning - m_Container.style.top = m_Container.layout.yMin; - m_Container.style.bottom = float.NaN; - m_Container.style.left = float.NaN; - m_Container.style.right = m_Container.parent.layout.width - m_Container.layout.xMax; - - float newWidth = Mathf.Max(0f, m_ResizeBeginLayout.width - relativeMousePosition.x); - float newHeight = Mathf.Max(0f, m_ResizeBeginLayout.height + relativeMousePosition.y); - - if (maintainAspectRatio) - newWidth = newHeight = Mathf.Min(newWidth, newHeight); - - m_ResizeTarget.style.width = newWidth; - m_ResizeTarget.style.height = newHeight; - - mouseMoveEvent.StopPropagation(); - } - - void HandleResizeFromLeft(MouseMoveEvent mouseMoveEvent) - { - if (!m_Dragging) - return; - - Vector2 relativeMousePosition = mouseMoveEvent.mousePosition - m_ResizeBeginMousePosition; - - // Set anchor points for positioning - m_Container.style.left = float.NaN; - m_Container.style.right = m_Container.parent.layout.width - m_Container.layout.xMax; - - float newWidth = Mathf.Max(0f, m_ResizeBeginLayout.width - relativeMousePosition.x); - - m_ResizeTarget.style.width = newWidth; - - if (maintainAspectRatio) - m_ResizeTarget.style.height = newWidth; - - mouseMoveEvent.StopPropagation(); - } - - void HandleResizeFromTopLeft(MouseMoveEvent mouseMoveEvent) - { - if (!m_Dragging) - return; - - Vector2 relativeMousePosition = mouseMoveEvent.mousePosition - m_ResizeBeginMousePosition; - - // Set anchor points for positioning - m_Container.style.top = float.NaN; - m_Container.style.bottom = m_Container.parent.layout.height - m_Container.layout.yMax; - m_Container.style.left = float.NaN; - m_Container.style.right = m_Container.parent.layout.width - m_Container.layout.xMax; - - float newWidth = Mathf.Max(0f, m_ResizeBeginLayout.width - relativeMousePosition.x); - float newHeight = Mathf.Max(0f, m_ResizeBeginLayout.height - relativeMousePosition.y); - - if (maintainAspectRatio) - newWidth = newHeight = Mathf.Min(newWidth, newHeight); - - m_ResizeTarget.style.width = newWidth; - m_ResizeTarget.style.height = newHeight; - - mouseMoveEvent.StopPropagation(); - } - - void HandleMouseDown(MouseDownEvent mouseDownEvent) - { - // Get the docking settings for the window, as well as the - // layout and mouse position when resize begins. - m_WindowDockingLayout.CalculateDockingCornerAndOffset(m_Container.layout, m_Container.parent.layout); - m_WindowDockingLayout.ApplyPosition(m_Container); - - m_ResizeBeginLayout = m_ResizeTarget.layout; - m_ResizeBeginMousePosition = mouseDownEvent.mousePosition; - - m_Dragging = true; - this.CaptureMouse(); - mouseDownEvent.StopPropagation(); - } - - void HandleDraggableMouseUp(MouseUpEvent mouseUpEvent) - { - m_Dragging = false; - - if (this.HasMouseCapture()) - this.ReleaseMouse(); - - if (OnResizeFinished != null) - OnResizeFinished(); - - m_WindowDockingLayout.CalculateDockingCornerAndOffset(m_Container.layout, m_Container.parent.layout); - m_WindowDockingLayout.ApplyPosition(m_Container); - } - - protected override void ImmediateRepaint() - { - if (m_StyleWidget == null) - { - m_StyleWidget = new GUIStyle("WindowBottomResize") { fixedHeight = 0 }; - image = m_StyleWidget.normal.background; - } - - if (image == null) - { - Debug.LogWarning("null texture passed to GUI.DrawTexture"); - return; - } - - GUI.DrawTexture(contentRect, image, ScaleMode.ScaleAndCrop, true, 0, GUI.color, 0, 0); - } - } -} diff --git a/Packages/com.unity.shadergraph/Editor/Drawing/Manipulators/ResizeSideHandle.cs.meta b/Packages/com.unity.shadergraph/Editor/Drawing/Manipulators/ResizeSideHandle.cs.meta deleted file mode 100644 index 56aa2002698..00000000000 --- a/Packages/com.unity.shadergraph/Editor/Drawing/Manipulators/ResizeSideHandle.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: b165bcb20989fa2428253e51bc4f440f -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/com.unity.shadergraph/Editor/Drawing/Views/GraphEditorView.cs b/Packages/com.unity.shadergraph/Editor/Drawing/Views/GraphEditorView.cs index d9863a7ccdc..f6ff8c2b5f0 100644 --- a/Packages/com.unity.shadergraph/Editor/Drawing/Views/GraphEditorView.cs +++ b/Packages/com.unity.shadergraph/Editor/Drawing/Views/GraphEditorView.cs @@ -487,7 +487,7 @@ void CreateMasterPreview() m_GraphView.Add(m_MasterPreviewView); masterPreviewViewDraggable.OnDragFinished += UpdateSerializedWindowLayout; - m_MasterPreviewView.previewResizeBorderFrame.OnResizeFinished += UpdateSerializedWindowLayout; + m_MasterPreviewView.onResized += UpdateSerializedWindowLayout; } void CreateInspector() diff --git a/Packages/com.unity.shadergraph/Editor/Drawing/Views/ResizableElement.cs b/Packages/com.unity.shadergraph/Editor/Drawing/Views/ResizableElement.cs index 7c13ed967a5..84a545d8cc0 100644 --- a/Packages/com.unity.shadergraph/Editor/Drawing/Views/ResizableElement.cs +++ b/Packages/com.unity.shadergraph/Editor/Drawing/Views/ResizableElement.cs @@ -1,5 +1,5 @@ +using System; using System.Collections.Generic; -using UnityEditor.ShaderGraph.Drawing; using UnityEngine; using UnityEngine.UIElements; @@ -72,6 +72,7 @@ public void SetResizeRules(Resizer allowedResizeDirections) } } + [Flags] public enum Resizer { None = 0, diff --git a/Packages/com.unity.shadergraph/Editor/Generation/ShaderGraphVfxAsset.cs b/Packages/com.unity.shadergraph/Editor/Generation/ShaderGraphVfxAsset.cs index 4b37554f1b1..d283c23fec8 100644 --- a/Packages/com.unity.shadergraph/Editor/Generation/ShaderGraphVfxAsset.cs +++ b/Packages/com.unity.shadergraph/Editor/Generation/ShaderGraphVfxAsset.cs @@ -133,6 +133,11 @@ public string outputStructName internal set { m_OutputStructName = value; } } + internal void SetGUID(string guid) + { + m_Data.OverrideObjectId(guid, "SerializedVfxAssetData"); + } + public List properties { get diff --git a/Packages/com.unity.shadergraph/Editor/Generation/Targets/BuiltIn/Editor/ShaderGraph/Includes/PBRDeferredPass.hlsl b/Packages/com.unity.shadergraph/Editor/Generation/Targets/BuiltIn/Editor/ShaderGraph/Includes/PBRDeferredPass.hlsl index 2230ce8795d..a36cea6f837 100644 --- a/Packages/com.unity.shadergraph/Editor/Generation/Targets/BuiltIn/Editor/ShaderGraph/Includes/PBRDeferredPass.hlsl +++ b/Packages/com.unity.shadergraph/Editor/Generation/Targets/BuiltIn/Editor/ShaderGraph/Includes/PBRDeferredPass.hlsl @@ -55,7 +55,7 @@ void PBRDeferredFragment(v2f_surf IN, SurfaceOutputStandard o, out half4 outGBuffer1 : SV_Target1, out half4 outGBuffer2 : SV_Target2, out half4 outEmission : SV_Target3 -#if defined(SHADOWS_SHADOWMASK) && (UNITY_ALLOWED_MRT_COUNT > 4) +#if OUTPUT_SHADOWMASK , out half4 outShadowMask : SV_Target4 #endif ) @@ -126,7 +126,7 @@ void PBRDeferredFragment(v2f_surf IN, SurfaceOutputStandard o, // call lighting function to output g-buffer outEmission = LightingStandard_Deferred (o, worldViewDir, gi, outGBuffer0, outGBuffer1, outGBuffer2); - #if defined(SHADOWS_SHADOWMASK) && (UNITY_ALLOWED_MRT_COUNT > 4) + #if OUTPUT_SHADOWMASK outShadowMask = UnityGetRawBakedOcclusions (IN.lmap.xy, worldPos); #endif #ifndef UNITY_HDR_ON diff --git a/Packages/com.unity.shadergraph/Editor/Importers/ShaderGraphImporter.cs b/Packages/com.unity.shadergraph/Editor/Importers/ShaderGraphImporter.cs index a27eb52a309..902978d272e 100644 --- a/Packages/com.unity.shadergraph/Editor/Importers/ShaderGraphImporter.cs +++ b/Packages/com.unity.shadergraph/Editor/Importers/ShaderGraphImporter.cs @@ -986,6 +986,7 @@ void AddCoordinateSpaceSnippets(InterpolatorType interpolatorType, Func #top { +.mainContainer > #top { flex-direction: row; justify-content: space-between; - background-color: rgb(64, 64, 64); + background-color: #393939; padding: 8px; border-top-left-radius: 6px; border-top-right-radius: 6px; } -MasterPreviewView > #top > #title { +.mainContainer > #top > #title { overflow: hidden; font-size: 14px; color: rgb(180, 180, 180); padding: 1px 2px 2px; } -MasterPreviewView > #middle { - background-color: rgb(49, 49, 49); +.mainContainer > #middle { + background-color: #2e2e2e; flex-grow: 1; flex-direction: row; } -MasterPreviewView > #middle > #preview { +.mainContainer > #middle > #preview { flex-grow: 1; width: 100px; height: 100px; diff --git a/Packages/com.unity.visualeffectgraph/Editor/Controls/VFXSliderField.cs b/Packages/com.unity.visualeffectgraph/Editor/Controls/VFXSliderField.cs index 23f003d87df..8d90de871cc 100644 --- a/Packages/com.unity.visualeffectgraph/Editor/Controls/VFXSliderField.cs +++ b/Packages/com.unity.visualeffectgraph/Editor/Controls/VFXSliderField.cs @@ -76,7 +76,7 @@ public float ToScaled(float linearValue) } } - abstract class VFXBaseSliderField : VisualElement, INotifyValueChanged + abstract class VFXBaseSliderField : VisualElement, IVFXNotifyValueChanged { protected readonly Slider m_Slider; protected readonly TextValueField m_Field; @@ -160,6 +160,11 @@ public void SetValueWithoutNotify(T newValue) SetValueWithoutNotify(ValueToFloat(newValue), newValue); } + public void SetValueWithoutNotify(T newValue, bool force) + { + SetValueWithoutNotify(ValueToFloat(newValue), newValue, force); + } + public T value { get => m_Value; diff --git a/Packages/com.unity.visualeffectgraph/Editor/GraphView/Blackboard/VFXBlackboard.cs b/Packages/com.unity.visualeffectgraph/Editor/GraphView/Blackboard/VFXBlackboard.cs index 6314210ce5c..f51cb0f8521 100644 --- a/Packages/com.unity.visualeffectgraph/Editor/GraphView/Blackboard/VFXBlackboard.cs +++ b/Packages/com.unity.visualeffectgraph/Editor/GraphView/Blackboard/VFXBlackboard.cs @@ -1225,6 +1225,11 @@ public IEnumerable GetAttributeRowsFromNames(string[] return m_Treeview.Query().Where(x => attributeNames.Any(y => VFXAttributeHelper.IsMatching(y, x.attribute.title, true))).ToList(); } + public void ClearAllAttributesHighlights() + { + m_Treeview.Query().ForEach(r => r.RemoveFromClassList("hovered")); + } + public void OnControllerChanged(ref ControllerChangedEvent e) { switch (e.change) diff --git a/Packages/com.unity.visualeffectgraph/Editor/GraphView/Elements/VFXBlockUI.cs b/Packages/com.unity.visualeffectgraph/Editor/GraphView/Elements/VFXBlockUI.cs index 6766e4c4644..0915b332aeb 100644 --- a/Packages/com.unity.visualeffectgraph/Editor/GraphView/Elements/VFXBlockUI.cs +++ b/Packages/com.unity.visualeffectgraph/Editor/GraphView/Elements/VFXBlockUI.cs @@ -67,10 +67,7 @@ protected override void SelfChange() private void OnDetachFromPanel(DetachFromPanelEvent evt) { var view = evt.originPanel.visualTree.Q(); - if (view != null) - { - UpdateHover(view, false); - } + view?.blackboard?.ClearAllAttributesHighlights(); } private void OnMouseHover(EventBase evt) diff --git a/Packages/com.unity.visualeffectgraph/Editor/GraphView/Views/Controller/VFXViewController.cs b/Packages/com.unity.visualeffectgraph/Editor/GraphView/Views/Controller/VFXViewController.cs index 93ff5de4878..cbed3df2fde 100644 --- a/Packages/com.unity.visualeffectgraph/Editor/GraphView/Views/Controller/VFXViewController.cs +++ b/Packages/com.unity.visualeffectgraph/Editor/GraphView/Views/Controller/VFXViewController.cs @@ -682,11 +682,20 @@ public void Remove(IEnumerable removedControllers, bool explicitDele public void RemoveElement(Controller element, bool explicitDelete = false) { + bool HasCustomAttributes(VFXModel model) + { + return model is IVFXAttributeUsage attributeUsage && + attributeUsage.usedAttributes.Any(x => graph.attributesManager.IsCustom(x.name)); + } + VFXModel removedModel = null; + bool needSyncCustomAttributes = false; + if (element is VFXContextController contextController) { VFXContext context = contextController.model; removedModel = context; + needSyncCustomAttributes = HasCustomAttributes(removedModel); contextController.NodeGoingToBeRemoved(); // Remove connections from context @@ -716,6 +725,7 @@ public void RemoveElement(Controller element, bool explicitDelete = false) else if (element is VFXBlockController block) { removedModel = block.model; + needSyncCustomAttributes = HasCustomAttributes(removedModel); block.NodeGoingToBeRemoved(); block.contextController.RemoveBlock(block.model); @@ -724,6 +734,7 @@ public void RemoveElement(Controller element, bool explicitDelete = false) else if (element is VFXParameterNodeController parameter) { removedModel = parameter.model; + needSyncCustomAttributes = HasCustomAttributes(removedModel); parameter.NodeGoingToBeRemoved(); parameter.parentController.model.RemoveNode(parameter.infos); RemoveFromGroupNodes(parameter); @@ -736,6 +747,7 @@ public void RemoveElement(Controller element, bool explicitDelete = false) if (element is VFXNodeController nodeController) { removedModel = nodeController.model; + needSyncCustomAttributes = HasCustomAttributes(removedModel); container = removedModel as IVFXSlotContainer; nodeController.NodeGoingToBeRemoved(); RemoveFromGroupNodes(nodeController); @@ -743,6 +755,7 @@ public void RemoveElement(Controller element, bool explicitDelete = false) else { removedModel = ((VFXParameterController)element).model; + needSyncCustomAttributes = HasCustomAttributes(removedModel); container = (IVFXSlotContainer)removedModel; foreach (var parameterNode in m_SyncedModels[removedModel]) { @@ -814,7 +827,7 @@ public void RemoveElement(Controller element, bool explicitDelete = false) Debug.LogErrorFormat("Unexpected type : {0}", element.GetType().FullName); } - if (removedModel is IVFXAttributeUsage attributeUsage && attributeUsage.usedAttributes.Any(x => graph.attributesManager.IsCustom(x.name))) + if (needSyncCustomAttributes) { graph.SyncCustomAttributes(); } diff --git a/Packages/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/PropertyRM.cs b/Packages/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/PropertyRM.cs index 33c133ac44b..aa9476d9519 100644 --- a/Packages/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/PropertyRM.cs +++ b/Packages/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/PropertyRM.cs @@ -36,6 +36,10 @@ interface IPropertyRMProvider void EndLiveModification(); } + interface IVFXNotifyValueChanged : INotifyValueChanged + { + void SetValueWithoutNotify(T typedNewValue, bool force = false); + } class SimplePropertyRMProvider : IPropertyRMProvider { @@ -253,7 +257,7 @@ public void Update() Profiler.EndSample(); Profiler.EndSample(); } - + void UpdateExpandable() { if (IsExpandable()) @@ -617,7 +621,10 @@ public override void UpdateGUI(bool force) try { var value = (U)System.Convert.ChangeType(m_Value, typeof(U)); - m_Field.SetValueWithoutNotify(value); + if (m_Field is IVFXNotifyValueChanged vfxNotifyValueChanged) + vfxNotifyValueChanged.SetValueWithoutNotify(value, force); + else + m_Field.SetValueWithoutNotify(value); } catch (System.Exception ex) { diff --git a/Packages/com.unity.visualeffectgraph/Editor/GraphView/Views/VFXHelpDropdownButton.cs b/Packages/com.unity.visualeffectgraph/Editor/GraphView/Views/VFXHelpDropdownButton.cs index 997f300714d..9e373e8569e 100644 --- a/Packages/com.unity.visualeffectgraph/Editor/GraphView/Views/VFXHelpDropdownButton.cs +++ b/Packages/com.unity.visualeffectgraph/Editor/GraphView/Views/VFXHelpDropdownButton.cs @@ -14,10 +14,6 @@ class VFXHelpDropdownButton : DropDownButtonBase const string k_AdditionalHelpers = "OutputEvent Helpers"; const string k_LearningSamples = "Learning Templates"; const string k_ManualUrl = @"https://docs.unity3d.com/Packages/com.unity.visualeffectgraph@{0}/index.html"; - const string k_ForumUrl = @"https://forum.unity.com/forums/visual-effect-graph.428/"; - const string k_SpaceShipUrl = @"https://github.com/Unity-Technologies/SpaceshipDemo"; - const string k_SamplesUrl = @"https://github.com/Unity-Technologies/VisualEffectGraph-Samples"; - const string k_VfxGraphUrl = @"https://unity.com/visual-effect-graph"; string m_ManualUrlWithVersion; ListRequest m_PackageManagerRequest; @@ -40,18 +36,6 @@ public VFXHelpDropdownButton(VFXView vfxView) var installLearningButton = m_PopupContent.Q