-
Notifications
You must be signed in to change notification settings - Fork 849
[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
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.
52dc535
[Feature] Adding some missing files for Compute Deformation node
ad6e50d
Fix skinning nodes
svens-unity 64c2b28
Clean-up of LBS & Deform Compute SG nodes.
svens-unity 77068bc
Moved LinearBlendSkinning node into Mesh Deformations folder
svens-unity fea2f6d
Both nodes add the shader properties automatically.
svens-unity 886311e
Add sub graph support for both nodes.
svens-unity fde6b2c
Add vertexID, bone weights and indices to AttributeData
ee378ae
Add correct semantic for vertexID
f3eb6fd
Add setup error to compute deform node if compute define is not enabled.
8eea6cc
Remove warning about vector truncation from Compute Deform Node
d783334
[Documentation] Added documentation for LBS and Compute node
91ae952
Get objects to visualize in gameobject mode.
svens-unity dc5e924
Merge branch 'dots-deformations' of github.com:Unity-Technologies/Gra…
svens-unity f27c5db
Add setup error to CD and LBS nodes if Hybrid Renderer package is not…
f94e60c
Merge remote-tracking branch 'origin/dots-deformations' into dots-def…
9cee664
Merge branch 'master' into dots-deformations
svens-unity 0602112
Update shadergraph changelog
443fb31
Updated Compute-Deformation-Node and Linear-Blend-Skinning-Node
sharlenet 3804528
Add defines to SG nodes to remove supported features in Hybrid V1.
svens-unity 20724cd
Merge branch 'dots-deformations' of github.com:Unity-Technologies/Gra…
svens-unity 71aa8c4
Updated Linear Blend Skinning Node
sharlenet 601fd24
Add defines for LBS node to work with Hybrid Renderer prior to data p…
a90ab12
Added link to Hybrid Renderer. Updated Ports table.
svens-unity 8e9099b
Added missing input port entries in Ports table
svens-unity 67b6805
Move LinearBlendSkinning node into 'Mesh Deformation' group.
svens-unity 4cadeee
Add defines for material property to work with hybrid renderer v2 pre…
c32ecaa
Update shader graph define to 0.5.0
94d1fc1
Update compute deformation node define to be hybrid renderer 0.5.0
bc0b8bc
Merge remote-tracking branch 'origin/dots-deformations' into dots-def…
07a2e04
Merge remote-tracking branch 'origin/master' into dots-deformations
svens-unity ab77a3e
Bump ShaderGraph importer version
svens-unity 5a37915
Update hybrid renderer version define to include preview version 4 an…
b4089d2
Added punctuation.
sharlenet bc7b6f4
Updated TableOfContents.md
sharlenet 75972ad
Update Node error messages
svens-unity ede321b
Add 'package' to error message.
svens-unity 3afee37
Merge branch 'master' into dots-deformations
cfb9a28
Use float3 for deformed mesh tangents instead of float4
f55325a
[Clean Up] Rename Input and Output slots for LBS and Compute Deform node
4c76690
Merge branch 'master' of github.com:Unity-Technologies/Graphics into …
svens-unity b42c201
Update guid to objectId
svens-unity 38f0bfb
Update hybrid renderer assembly define for Shader Graph
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
com.unity.shadergraph/Documentation~/Compute-Deformation-Node.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
12
com.unity.shadergraph/Documentation~/Linear-Blend-Skinning-Node.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
com.unity.shadergraph/Editor/Data/Interfaces/IMayRequireVertexID.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
svens-unity marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
var mayRequireVertexID = slot as IMayRequireVertexID; | ||
return mayRequireVertexID != null && mayRequireVertexID.RequiresVertexID(); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
com.unity.shadergraph/Editor/Data/Interfaces/IMayRequireVertexID.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...ph/Editor/Data/Nodes/Vertex Skinning.meta → ...h/Editor/Data/Nodes/Mesh Deformation.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
148 changes: 148 additions & 0 deletions
148
com.unity.shadergraph/Editor/Data/Nodes/Mesh Deformation/ComputeDeformNode.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
svens-unity marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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()}"; | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
com.unity.shadergraph/Editor/Data/Nodes/Mesh Deformation/ComputeDeformNode.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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...