Skip to content

[Feature] Compute Deformation Node #166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 43 commits into from
May 14, 2020
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
1fdc616
[Feature] Create node for compute deformations.
Apr 6, 2020
52dc535
[Feature] Adding some missing files for Compute Deformation node
Apr 6, 2020
ad6e50d
Fix skinning nodes
svens-unity Apr 14, 2020
64c2b28
Clean-up of LBS & Deform Compute SG nodes.
svens-unity Apr 15, 2020
77068bc
Moved LinearBlendSkinning node into Mesh Deformations folder
svens-unity Apr 15, 2020
fea2f6d
Both nodes add the shader properties automatically.
svens-unity Apr 15, 2020
886311e
Add sub graph support for both nodes.
svens-unity Apr 15, 2020
fde6b2c
Add vertexID, bone weights and indices to AttributeData
Apr 16, 2020
ee378ae
Add correct semantic for vertexID
Apr 16, 2020
f3eb6fd
Add setup error to compute deform node if compute define is not enabled.
Apr 17, 2020
8eea6cc
Remove warning about vector truncation from Compute Deform Node
Apr 17, 2020
d783334
[Documentation] Added documentation for LBS and Compute node
Apr 17, 2020
91ae952
Get objects to visualize in gameobject mode.
svens-unity Apr 17, 2020
dc5e924
Merge branch 'dots-deformations' of github.com:Unity-Technologies/Gra…
svens-unity Apr 17, 2020
f27c5db
Add setup error to CD and LBS nodes if Hybrid Renderer package is not…
Apr 17, 2020
f94e60c
Merge remote-tracking branch 'origin/dots-deformations' into dots-def…
Apr 17, 2020
9cee664
Merge branch 'master' into dots-deformations
svens-unity Apr 17, 2020
0602112
Update shadergraph changelog
Apr 17, 2020
443fb31
Updated Compute-Deformation-Node and Linear-Blend-Skinning-Node
sharlenet Apr 17, 2020
3804528
Add defines to SG nodes to remove supported features in Hybrid V1.
svens-unity Apr 20, 2020
20724cd
Merge branch 'dots-deformations' of github.com:Unity-Technologies/Gra…
svens-unity Apr 20, 2020
71aa8c4
Updated Linear Blend Skinning Node
sharlenet Apr 20, 2020
601fd24
Add defines for LBS node to work with Hybrid Renderer prior to data p…
Apr 21, 2020
a90ab12
Added link to Hybrid Renderer. Updated Ports table.
svens-unity Apr 21, 2020
8e9099b
Added missing input port entries in Ports table
svens-unity Apr 21, 2020
67b6805
Move LinearBlendSkinning node into 'Mesh Deformation' group.
svens-unity Apr 21, 2020
4cadeee
Add defines for material property to work with hybrid renderer v2 pre…
Apr 21, 2020
c32ecaa
Update shader graph define to 0.5.0
Apr 21, 2020
94d1fc1
Update compute deformation node define to be hybrid renderer 0.5.0
Apr 21, 2020
bc0b8bc
Merge remote-tracking branch 'origin/dots-deformations' into dots-def…
Apr 21, 2020
07a2e04
Merge remote-tracking branch 'origin/master' into dots-deformations
svens-unity Apr 21, 2020
ab77a3e
Bump ShaderGraph importer version
svens-unity Apr 21, 2020
5a37915
Update hybrid renderer version define to include preview version 4 an…
Apr 21, 2020
b4089d2
Added punctuation.
sharlenet Apr 21, 2020
bc7b6f4
Updated TableOfContents.md
sharlenet Apr 22, 2020
75972ad
Update Node error messages
svens-unity Apr 23, 2020
ede321b
Add 'package' to error message.
svens-unity Apr 23, 2020
3afee37
Merge branch 'master' into dots-deformations
Apr 28, 2020
cfb9a28
Use float3 for deformed mesh tangents instead of float4
Apr 29, 2020
f55325a
[Clean Up] Rename Input and Output slots for LBS and Compute Deform node
Apr 30, 2020
4c76690
Merge branch 'master' of github.com:Unity-Technologies/Graphics into …
svens-unity May 12, 2020
b42c201
Update guid to objectId
svens-unity May 12, 2020
38f0bfb
Update hybrid renderer assembly define for Shader Graph
May 13, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using UnityEditor.ShaderGraph;
using UnityEditor.ShaderGraph;

namespace UnityEditor.Rendering.HighDefinition.ShaderGraph
{
Expand Down Expand Up @@ -28,6 +28,8 @@ public struct AttributesMesh
"COLOR", subscriptOptions : StructFieldOptions.Optional);
public static FieldDescriptor instanceID = new FieldDescriptor(AttributesMesh.name, "instanceID", "", ShaderValueType.Uint,
"INSTANCEID_SEMANTIC", "UNITY_ANY_INSTANCING_ENABLED");
public static FieldDescriptor vertexID = new FieldDescriptor(AttributesMesh.name, "vertexID", "ATTRIBUTES_NEED_VERTEXID", ShaderValueType.Uint,
"SV_VertexID", subscriptOptions: StructFieldOptions.Optional);
}

public struct VaryingsMeshToPS
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using UnityEditor.ShaderGraph;
using UnityEditor.ShaderGraph;

namespace UnityEditor.Rendering.HighDefinition.ShaderGraph
{
Expand All @@ -21,6 +21,7 @@ static class HDStructs
HDStructFields.AttributesMesh.instanceID,
HDStructFields.AttributesMesh.weights,
HDStructFields.AttributesMesh.indices,
HDStructFields.AttributesMesh.vertexID,
}
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine.Rendering;
Expand Down Expand Up @@ -173,6 +173,7 @@ static class CoreFieldDependencies

new FieldDependency(StructFields.VertexDescriptionInputs.BoneWeights, HDStructFields.AttributesMesh.weights),
new FieldDependency(StructFields.VertexDescriptionInputs.BoneIndices, HDStructFields.AttributesMesh.indices),
new FieldDependency(StructFields.VertexDescriptionInputs.VertexID, HDStructFields.AttributesMesh.vertexID),
};

public static DependencyCollection SurfaceDescription = new DependencyCollection
Expand Down Expand Up @@ -212,6 +213,10 @@ static class CoreFieldDependencies
new FieldDependency(StructFields.SurfaceDescriptionInputs.FaceSign, HDStructFields.FragInputs.IsFrontFace),

new FieldDependency(HDFields.DepthOffset, HDStructFields.FragInputs.positionRWS),

new FieldDependency(StructFields.SurfaceDescriptionInputs.BoneWeights, StructFields.SurfaceDescriptionInputs.BoneIndices),
new FieldDependency(StructFields.SurfaceDescriptionInputs.BoneIndices, StructFields.SurfaceDescriptionInputs.BoneWeights),
new FieldDependency(StructFields.SurfaceDescriptionInputs.VertexID, StructFields.SurfaceDescriptionInputs.VertexID),
Comment on lines +217 to +219
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we would not have these be part of surface descriptions? However, they are required to have the nodes work in subgraphs...

};

public static DependencyCollection Default = new DependencyCollection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ VertexDescriptionInputs AttributesMeshToVertexDescriptionInputs(AttributesMesh i
$VertexDescriptionInputs.VertexColor: output.VertexColor = input.color;
$VertexDescriptionInputs.BoneWeights: output.BoneWeights = input.weights;
$VertexDescriptionInputs.BoneIndices: output.BoneIndices = input.indices;
$VertexDescriptionInputs.VertexID: output.VertexID = input.vertexID;

return output;
}
Expand Down
3 changes: 3 additions & 0 deletions com.unity.shadergraph/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Added AlphaToMask render state.
- Added a field to the Master Nodes that overrides the generated shader's ShaderGUI, which determines how a Material that uses a Shader Graph looks.
- Added Redirect Nodes. You can now double-click an edge to add a control point that allows you to route edges around other nodes and connect multiple output edges.
- Added `Compute Deformation` Node to read deformed vertex data from Dots Deformations.

### Changed
- Changed the `Branch` node so that it uses a ternary operator (`Out = bool ? a : B`) instead of a linear interpolate function.
- Copied nodes are now pasted at the cursor location instead of slightly offset from their original location
- Error messages reported on Sub Graph output nodes for invalid previews now present clearer information, with documentation support.
- Added support for `Linear Blend Skinning` Node to Universal Render Pipeline.

### Fixed
- Edges no longer produce errors when you save a Shader Graph.
Expand Down Expand Up @@ -91,6 +93,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed a bug where the `Position` node would change coordinate spaces from `World` to `Absolute World` when shaders recompile. [1184617](https://issuetracker.unity3d.com/product/unity/issues/guid/1184617/)
- Fixed a bug where instanced shaders wouldn't compile on PS4.
- Optimized loading a large Shader Graph. [1209047](https://issuetracker.unity3d.com/issues/shader-graph-unresponsive-editor-when-using-large-graphs)
- Fixed issue where `Linear Blend Skinning` node could not be converted to Sub Graph [1227087](https://issuetracker.unity3d.com/issues/shadergraph-linear-blend-skinning-node-reports-an-error-and-prevents-shader-compilation-when-used-within-a-sub-graph)

## [7.1.1] - 2019-09-05
### Added
Expand Down
12 changes: 12 additions & 0 deletions com.unity.shadergraph/Documentation~/Compute-Deformation-Node.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Compute Deformation Node

## Description

This node lets you pass compute deformed data to a vertex shader. You must provide `DeformedVertexData` in the `_DeformedMeshData` buffer. The node uses the `_ComputeMeshIndex` property to calculate where the `DeformedVertexData` associated with the current mesh are located in the `_DeformedMeshData` buffer. To output data, you must either install both the DOTS Hybrid Renderer and DOTS Animation packages, or use a custom solution.

## Ports
| Name | Direction | Type | Stage | Description |
|:------------ |:-----------|:--------|:-------|:------------|
| OutPosition | Output | Vector3 | Vertex | Outputs the deformed position |
| OutNormal | Output | Vector3 | Vertex | Outputs the deformed normal |
| OutTangent | Output | Vector3 | Vertex | Outputs the deformed tangent |
12 changes: 12 additions & 0 deletions com.unity.shadergraph/Documentation~/Linear-Blend-Skinning-Node.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Linear Blend Skinning Node

## Description

This node lets you authorize Linear Blend Vertex Skinning, and is only available in the High Definition Render Pipeline (HDRP). You must provide skinned matrices in the `_SkinMatrices` buffer. The node uses the `_SkinMatrixIndex` property to calculate where the matrices associated with the current mesh are located in the `_SkinMatrices` buffer.

## Ports
| Name | Direction | Type | Stage | Description |
|:------------ |:-----------|:--------|:-------|:------------|
| OutPosition | Output | Vector3 | Vertex | Outputs the skinned position |
| OutNormal | Output | Vector3 | Vertex | Outputs the skinned normal |
| OutTangent | Output | Vector3 | Vertex | Outputs the skinned tangent |
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public struct ShaderGraphRequirements
[SerializeField] bool m_RequiresCameraOpaqueTexture;
[SerializeField] bool m_RequiresTime;
[SerializeField] bool m_RequiresVertexSkinning;
[SerializeField] bool m_RequiresVertexID;

internal static ShaderGraphRequirements none
{
Expand Down Expand Up @@ -111,6 +112,12 @@ public bool requiresVertexSkinning
internal set { m_RequiresVertexSkinning = value; }
}

public bool requiresVertexID
{
get { return m_RequiresVertexID; }
internal set { m_RequiresVertexID = value; }
}

internal bool NeedsTangentSpace()
{
var compoundSpaces = m_RequiresBitangent | m_RequiresNormal | m_RequiresPosition
Expand All @@ -135,6 +142,7 @@ internal ShaderGraphRequirements Union(ShaderGraphRequirements other)
newReqs.m_RequiresCameraOpaqueTexture = other.m_RequiresCameraOpaqueTexture | m_RequiresCameraOpaqueTexture;
newReqs.m_RequiresTime = other.m_RequiresTime | m_RequiresTime;
newReqs.m_RequiresVertexSkinning = other.m_RequiresVertexSkinning | m_RequiresVertexSkinning;
newReqs.m_RequiresVertexID = other.m_RequiresVertexID | m_RequiresVertexID;


newReqs.m_RequiresMeshUVs = new List<UVChannel>();
Expand All @@ -160,6 +168,7 @@ internal static ShaderGraphRequirements FromNodes<T>(List<T> nodes, ShaderStageC
bool requiresCameraOpaqueTexture = nodes.OfType<IMayRequireCameraOpaqueTexture>().Any(x => x.RequiresCameraOpaqueTexture());
bool requiresTime = nodes.Any(x => x.RequiresTime());
bool requiresVertexSkinning = nodes.OfType<IMayRequireVertexSkinning>().Any(x => x.RequiresVertexSkinning(stageCapability));
bool requiresVertexID = nodes.OfType<IMayRequireVertexID>().Any(x => x.RequiresVertexID(stageCapability));

var meshUV = new List<UVChannel>();
for (int uvIndex = 0; uvIndex < ShaderGeneratorNames.UVCount; ++uvIndex)
Expand Down Expand Up @@ -200,10 +209,11 @@ internal static ShaderGraphRequirements FromNodes<T>(List<T> nodes, ShaderStageC
m_RequiresDepthTexture = requiresDepthTexture,
m_RequiresCameraOpaqueTexture = requiresCameraOpaqueTexture,
m_RequiresTime = requiresTime,
m_RequiresVertexSkinning = requiresVertexSkinning
m_RequiresVertexSkinning = requiresVertexSkinning,
m_RequiresVertexID = requiresVertexID,
};

return reqs;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using UnityEditor.Graphing;

namespace UnityEditor.ShaderGraph
{
interface IMayRequireVertexID
{
bool RequiresVertexID(ShaderStageCapability stageCapability = ShaderStageCapability.All);
}

static class MayRequireVertexIDExtensions
{
public static bool RequiresVertexID(this ISlot slot)
{
var mayRequireVertexID = slot as IMayRequireVertexID;
return mayRequireVertexID != null && mayRequireVertexID.RequiresVertexID();
}
}
}

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
using UnityEngine;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Internal;

namespace UnityEditor.ShaderGraph
{
[Title("Mesh Deformation", "Compute Deformation")]
class ComputeDeformNode : AbstractMaterialNode, IGeneratesBodyCode, IGeneratesFunction, IMayRequirePosition, IMayRequireNormal, IMayRequireTangent, IMayRequireVertexID
{
public const int kPositionOutputSlotId = 0;
public const int kNormalOutputSlotId = 1;
public const int kTangentOutputSlotId = 2;

public const string kOutputSlotPositionName = "Position";
public const string kOutputSlotNormalName = "Normal";
public const string kOutputSlotTangentName = "Tangent";

public ComputeDeformNode()
{
name = "Compute Deformation";
UpdateNodeAfterDeserialization();
}

public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new Vector3MaterialSlot(kPositionOutputSlotId, kOutputSlotPositionName, kOutputSlotPositionName, SlotType.Output, Vector3.zero, ShaderStageCapability.Vertex));
AddSlot(new Vector3MaterialSlot(kNormalOutputSlotId, kOutputSlotNormalName, kOutputSlotNormalName, SlotType.Output, Vector3.zero, ShaderStageCapability.Vertex));
AddSlot(new Vector3MaterialSlot(kTangentOutputSlotId, kOutputSlotTangentName, kOutputSlotTangentName, SlotType.Output, Vector3.zero, ShaderStageCapability.Vertex));
RemoveSlotsNameNotMatching(new[] { kPositionOutputSlotId, kNormalOutputSlotId, kTangentOutputSlotId });
}

protected override void CalculateNodeHasError()
{
#if !ENABLE_COMPUTE_DEFORMATIONS
owner.AddSetupError(guid, "ENABLE_COMPUTE_DEFORMATIONS define needs to be enabled in Player Settings for Compute Deformation node to work");
hasError = true;
#endif
#if !HYBRID_RENDERER_0_4_0_OR_NEWER
owner.AddSetupError(guid, "Could not find 0.4.0 version or newer of Hybrid Renderer installed");
hasError = true;
#endif
}

public bool RequiresVertexID(ShaderStageCapability stageCapability = ShaderStageCapability.All)
{
return true;
}

public NeededCoordinateSpace RequiresPosition(ShaderStageCapability stageCapability = ShaderStageCapability.All)
{
if (stageCapability == ShaderStageCapability.Vertex || stageCapability == ShaderStageCapability.All)
return NeededCoordinateSpace.Object;
else
return NeededCoordinateSpace.None;
}

public NeededCoordinateSpace RequiresNormal(ShaderStageCapability stageCapability = ShaderStageCapability.All)
{
if (stageCapability == ShaderStageCapability.Vertex || stageCapability == ShaderStageCapability.All)
return NeededCoordinateSpace.Object;
else
return NeededCoordinateSpace.None;
}

public NeededCoordinateSpace RequiresTangent(ShaderStageCapability stageCapability = ShaderStageCapability.All)
{
if (stageCapability == ShaderStageCapability.Vertex || stageCapability == ShaderStageCapability.All)
return NeededCoordinateSpace.Object;
else
return NeededCoordinateSpace.None;
}

public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode)
{
properties.AddShaderProperty(new Vector1ShaderProperty()
{
overrideReferenceName = "_ComputeMeshIndex",
gpuInstanced = true,
hidden = true,
value = 0
});

base.CollectShaderProperties(properties, generationMode);
}

public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
{
sb.AppendLine("#if defined(UNITY_DOTS_INSTANCING_ENABLED)");
sb.AppendLine("$precision3 {0} = 0;", GetVariableNameForSlot(kPositionOutputSlotId));
sb.AppendLine("$precision3 {0} = 0;", GetVariableNameForSlot(kNormalOutputSlotId));
sb.AppendLine("$precision3 {0} = 0;", GetVariableNameForSlot(kTangentOutputSlotId));
if (generationMode == GenerationMode.ForReals)
{
sb.AppendLine($"{GetFunctionName()}(" +
$"IN.VertexID, " +
$"{GetVariableNameForSlot(kPositionOutputSlotId)}, " +
$"{GetVariableNameForSlot(kNormalOutputSlotId)}, " +
$"{GetVariableNameForSlot(kTangentOutputSlotId)});");
}
sb.AppendLine("#else");
sb.AppendLine("$precision3 {0} = IN.ObjectSpacePosition;", GetVariableNameForSlot(kPositionOutputSlotId));
sb.AppendLine("$precision3 {0} = IN.ObjectSpaceNormal;", GetVariableNameForSlot(kNormalOutputSlotId));
sb.AppendLine("$precision3 {0} = IN.ObjectSpaceTangent;", GetVariableNameForSlot(kTangentOutputSlotId));
sb.AppendLine("#endif");
}

public void GenerateNodeFunction(FunctionRegistry registry, GenerationMode generationMode)
{
registry.ProvideFunction("DeformedMeshData", sb =>
{
sb.AppendLine("struct DeformedVertexData");
sb.AppendLine("{");
using (sb.IndentScope())
{
sb.AppendLine("float3 Position;");
sb.AppendLine("float3 Normal;");
sb.AppendLine("float4 Tangent;");
}
sb.AppendLine("};");
sb.AppendLine("uniform StructuredBuffer<DeformedVertexData> _DeformedMeshData : register(t1);");
});

registry.ProvideFunction(GetFunctionName(), sb =>
{
sb.AppendLine($"void {GetFunctionName()}(" +
"uint vertexID, " +
"out $precision3 positionOut, " +
"out $precision3 normalOut, " +
"out $precision3 tangentOut)");

sb.AppendLine("{");
using (sb.IndentScope())
{
sb.AppendLine("const DeformedVertexData vertexData = _DeformedMeshData[asuint(_ComputeMeshIndex) + vertexID];");
sb.AppendLine("positionOut = vertexData.Position;");
sb.AppendLine("normalOut = vertexData.Normal;");
sb.AppendLine("tangentOut = vertexData.Tangent.xyz;");
}
sb.AppendLine("}");
});
}

string GetFunctionName()
{
return $"Unity_ComputeDeformedVertex_{concretePrecision.ToShaderString()}";
}
}
}

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

Loading