Skip to content

Commit

Permalink
Merge pull request #8114 from Unity-Technologies/internal/2021.3/staging
Browse files Browse the repository at this point in the history
Internal/2021.3/staging
  • Loading branch information
UnityAljosha authored Dec 17, 2024
2 parents 3d53173 + 4f918c9 commit b881bd6
Show file tree
Hide file tree
Showing 21 changed files with 675 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Custom Material Inspectors enable you to define how Unity displays properties in

The implementation for custom Material Inspectors differs between URP and HDRP. For example, for compatibility purposes, every custom Material Inspector in HDRP must inherit from `HDShaderGUI` which does not exist in URP. For information on how to create custom Material Inspectors for the respective render pipelines, see:

- **HDRP**: [HDRP custom Material Inspectors](https://docs.unity3d.com/Packages/com.unity.render-pipelines.high-definition@latest?subfolder=/manual/hdrp-custom-material-inspector.html).
- **HDRP**: [HDRP custom Material Inspectors](https://docs.unity3d.com/Packages/com.unity.render-pipelines.high-definition@latest?subfolder=/manual/custom-material-inspectors.html).
- **URP**: [Unity Custom Shader GUI](https://docs.unity3d.com/Manual/SL-CustomShaderGUI.html).

## Assigning a custom Material Inspector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class MyRenderPipeline : RenderPipeline

void InitializeRenderGraph()
{
m_RenderGraph = new RenderGraph(MyRenderGraph);
m_RenderGraph = new RenderGraph("MyRenderGraph");
}

void CleanupRenderGraph()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Finally, access the Frame Settings structure itself. This controls the actual va
- **Camera**: `HDAdditionalCameraData.renderingPathCustomFrameSettings`
- **Reflection Probe**: `HDAdditionalReflectionData.frameSettings`

For information on the API available for `FrameSettings`, including how to edit the value of a Frame Setting, see [FrameSettings Scripting API](framesettings-scripting-api).
For information on the API available for `FrameSettings`, including how to edit the value of a Frame Setting, see [FrameSettings Scripting API](#framesettings-scripting-api).

## Frame Setting enumerations

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -601,8 +601,9 @@ void GetHairAngleLocal(float3 wo, float3 wi, inout HairAngle angles)

void GetHairAngleWorld(float3 V, float3 L, float3 T, inout HairAngle angles)
{
angles.sinThetaO = dot(T, V);
angles.sinThetaI = dot(T, L);
// It might exceed the range [-1, 1], so explicitly clamp here to prevent nan output from FastASin.
angles.sinThetaO = clamp(dot(T, V), -1.0, 1.0);
angles.sinThetaI = clamp(dot(T, L), -1.0, 1.0);

float thetaO = FastASin(angles.sinThetaO);
float thetaI = FastASin(angles.sinThetaI);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ This section uses the example `RedTintRenderPass` Scriptable Render Pass from th
material = CoreUtils.CreateEngineMaterial(shader);
redTintRenderPass = new RedTintRenderPass(material);

renderPassEvent = RenderPassEvent.AfterRenderingSkybox;
redTintRenderPass.renderPassEvent = RenderPassEvent.AfterRenderingSkybox;
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ protected override LightingExplorerTableColumn[] GetReflectionProbeColumns()
new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Enum, Styles.Resolution, "m_Resolution", 100, (r, prop, dep) =>
{
EditorGUI.IntPopup(r, prop, Styles.ReflectionProbeSizeTitles, Styles.ReflectionProbeSizeValues, GUIContent.none);
},
(lhs, rhs) =>
{
return lhs.intValue.CompareTo(rhs.intValue);
}), // 4: Probe Resolution
new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Float, Styles.ShadowDistance, "m_ShadowDistance", 100), // 5: Shadow Distance
new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Float, Styles.NearPlane, "m_NearClip", 70), // 6: Near Plane
Expand Down
13 changes: 12 additions & 1 deletion Packages/com.unity.shadergraph/Editor/Data/Graphs/GroupData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace UnityEditor.ShaderGraph
{
[Serializable]
public class GroupData : JsonObject
public class GroupData : JsonObject, IRectInterface
{
[SerializeField]
string m_Title;
Expand All @@ -16,6 +16,7 @@ public string title
set { m_Title = value; }
}


[SerializeField]
Vector2 m_Position;

Expand All @@ -25,6 +26,16 @@ public Vector2 position
set { m_Position = value; }
}

Rect IRectInterface.rect
{
get => new Rect(position, Vector2.one);
set
{
position = value.position;
}
}


public GroupData() : base() { }

public GroupData(string title, Vector2 position)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ public void GenerateNodeFunction(FunctionRegistry registry, GenerationMode gener
s.AppendLine("$precision2 offsetU = $precision2(UV.x + Offset, UV.y);");
s.AppendLine("$precision2 offsetV = $precision2(UV.x, UV.y + Offset);");

s.AppendLine("$precision normalSample = SAMPLE_TEXTURE2D(Texture, Sampler, UV);");
s.AppendLine("$precision uSample = SAMPLE_TEXTURE2D(Texture, Sampler, offsetU);");
s.AppendLine("$precision vSample = SAMPLE_TEXTURE2D(Texture, Sampler, offsetV);");
s.AppendLine("$precision normalSample = SAMPLE_TEXTURE2D(Texture, Sampler, UV).r;");
s.AppendLine("$precision uSample = SAMPLE_TEXTURE2D(Texture, Sampler, offsetU).r;");
s.AppendLine("$precision vSample = SAMPLE_TEXTURE2D(Texture, Sampler, offsetV).r;");

s.AppendLine("$precision3 va = $precision3(1, 0, (uSample - normalSample) * Strength);");
s.AppendLine("$precision3 vb = $precision3(0, 1, (vSample - normalSample) * Strength);");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1478,7 +1478,12 @@ internal static void InsertCopyPasteGraph(this MaterialGraphView graphView, Copy
{
var nodeList = copyGraph.GetNodes<AbstractMaterialNode>();

ClampNodesWithinView(graphView, new List<IRectInterface>().Union(nodeList).Union(copyGraph.stickyNotes));
ClampNodesWithinView(graphView,
new List<IRectInterface>()
.Union(nodeList)
.Union(copyGraph.stickyNotes)
.Union(copyGraph.groups)
);

graphView.graph.PasteGraph(copyGraph, remappedNodes, remappedEdges);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,13 @@ public override bool AcceptsElement(GraphElement element, ref string reasonWhyNo

return true;
}

protected override void SetScopePositionOnly(Rect newPos)
{
base.SetScopePositionOnly(newPos);

userData.position = newPos.position;
}

}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Velocity from Direction & Speed (Change Speed)

> [!IMPORTANT]
> This feature is experimental. To use this feature, open the **Preferences** window, go to the **Visual Effects** tab, and enable **Experimental Operators/Blocks**.
Menu Path : **Velocity > [Set/Add] Velocity from Direction & Speed (Change Speed)**

The **Velocity from Direction And Speed : Change Speed** Block calculates a velocity for the particle based on the direction attribute.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Velocity from Direction & Speed (New Direction)

> [!IMPORTANT]
> This feature is experimental. To use this feature, open the **Preferences** window, go to the **Visual Effects** tab, and enable **Experimental Operators/Blocks**.
Menu Path : **Velocity > [Set/Add] Velocity from Direction & Speed (New Direction)**

The **Velocity from Direction And Speed (New Direction)** Block calculates a velocity for the particle based on a blend ratio between a given direction, and the direction attribute.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Velocity from Direction & Speed (Random Direction)

> [!IMPORTANT]
> This feature is experimental. To use this feature, open the **Preferences** window, go to the **Visual Effects** tab, and enable **Experimental Operators/Blocks**.
Menu Path : **Velocity > [Set/Add] Velocity from Direction & Speed (Random Direction)**

The **Velocity from Direction And Speed (Random Direction)** Block calculates a velocity for the particle based on a blend ratio between a random direction (per-particle), and the direction attribute.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Velocity from Direction & Speed (Spherical)

> [!IMPORTANT]
> This feature is experimental. To use this feature, open the **Preferences** window, go to the **Visual Effects** tab, and enable **Experimental Operators/Blocks**.
Menu Path : **Velocity > [Set/Add] Velocity from Direction & Speed (Spherical)**

The **Velocity from Direction And Speed (Spherical)** Block calculates a velocity for the particle based on a blend ratio between the direction attribute and a spherical vector.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Velocity from Direction & Speed (Tangent)

> [!IMPORTANT]
> This feature is experimental. To use this feature, open the **Preferences** window, go to the **Visual Effects** tab, and enable **Experimental Operators/Blocks**.
Menu Path : **Velocity > [Set/Add] Velocity from Direction & Speed (Tangent)**

The **Velocity from Direction And Speed (Tangent)** Block calculates a velocity for the particle based on a blend ratio between the direction attribute and a tangent vector.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Point Cache

> [!IMPORTANT]
> This feature is experimental. To use this feature, open the **Preferences** window, go to the **Visual Effects** tab, and enable **Experimental Operators/Blocks**.
Menu Path : **Operator > Utility > Point Cache**

The **Point Cache** Operator exposes the attribute maps and the point count stored into a [Point Cache asset](point-cache-asset.md).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Sample Attribute Map

> [!IMPORTANT]
> This feature is experimental. To use this feature, open the **Preferences** window, go to the **Visual Effects** tab, and enable **Experimental Operators/Blocks**.
**Menu Path : Operator > Sampling > Attribute Map**

The Sample Attribute Map Operator enables you to sample an [attribute map](point-cache-in-vfx-graph.md#attribute-map) from a [Point Cache](point-cache-in-vfx-graph.md).
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEngine.UIElements;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing;
using UnityEditor.ShaderGraph.Internal;


namespace UnityEditor.ShaderGraph.UnitTests
{
[TestFixture]
internal class GroupTests
{
static string kGraphName = "Assets/CommonAssets/Graphs/Group.shadergraph";
GraphData m_Graph;

GraphEditorView m_GraphEditorView;
MaterialGraphEditWindow m_Window;

[OneTimeSetUp]
public void LoadGraph()
{
List<PropertyCollector.TextureInfo> lti;
var assetCollection = new AssetCollection();
ShaderGraphImporter.GetShaderText(kGraphName, out lti, assetCollection, out m_Graph);
Assert.NotNull(m_Graph, $"Invalid graph data found for {kGraphName}");

m_Graph.ValidateGraph();
// Open up the window
if (!ShaderGraphImporterEditor.ShowGraphEditWindow(kGraphName))
{
Assert.Fail("ShaderGraphImporterEditor.ShowGraphEditWindow could not open " + kGraphName);
}

m_Window = EditorWindow.GetWindow<MaterialGraphEditWindow>();
if (m_Window == null)
{
Assert.Fail("Could not open window");
}

// EditorWindow.GetWindow will return a new window if one is not found. A new window will have graphObject == null.
if (m_Window.graphObject == null)
{
Assert.Fail("Existing Shader Graph window of " + kGraphName + " not found.");
}

m_GraphEditorView = m_Window.graphEditorView;

}

class TestExecuteCommandEvent : ExecuteCommandEvent
{
public void SetCommandName(string command)
{
commandName = command;
}
}

[UnityTest]
public IEnumerator TestEmptyGroupPastePosition()
{
var materialGraphView = m_GraphEditorView.graphView;
var materialGraphViewType = typeof(MaterialGraphView);

var cutMethodInfo = materialGraphViewType.GetMethod("CutSelectionCallback",
BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);
var pasteMethodInfo = materialGraphViewType.GetMethod("PasteCallback",
BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);

var mousePositionPropertyInfo = materialGraphViewType.GetProperty("cachedMousePosition",
typeof(Vector2));

Assert.NotNull(cutMethodInfo, "CutSelectionCallback method not found.");
Assert.NotNull(pasteMethodInfo, "PasteCallback method not found.");
Assert.NotNull(mousePositionPropertyInfo, "cachedMousePosition property not found.");

var groupList = materialGraphView.Query<ShaderGroup>()
.Where(x => x.userData.title == "Empty Group")
.ToList();

Assert.AreEqual(1, groupList.Count());



materialGraphView.ClearSelection();
materialGraphView.AddToSelection(groupList[0]);

cutMethodInfo.Invoke(materialGraphView, null);
yield return null;

groupList = materialGraphView.Query<ShaderGroup>()
.Where(x => x.userData.title == "Empty Group")
.ToList();

Assert.AreEqual(0, groupList.Count());

mousePositionPropertyInfo.SetValue(materialGraphView, new Vector2(100,100));
pasteMethodInfo.Invoke(materialGraphView, null);
yield return null;

mousePositionPropertyInfo.SetValue(materialGraphView, new Vector2(100,200));
pasteMethodInfo.Invoke(materialGraphView, null);
yield return null;

groupList = materialGraphView.Query<ShaderGroup>()
.Where(x => x.userData.title == "Empty Group")
.ToList();

Assert.AreEqual(2, groupList.Count());

Assert.AreNotEqual(groupList[0].GetPosition().position, groupList[1].GetPosition().position,
"When the cursor position changes, the pasted group's position should be adjusted accordingly");
}

}
}

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

Loading

0 comments on commit b881bd6

Please sign in to comment.