initial commit
This commit is contained in:
parent
6715289efe
commit
788c3389af
37645 changed files with 2526849 additions and 80 deletions
|
@ -0,0 +1,156 @@
|
|||
using UnityEngine;
|
||||
using UnityEditor.Graphing;
|
||||
using UnityEditor.ShaderGraph.Internal;
|
||||
|
||||
namespace UnityEditor.ShaderGraph
|
||||
{
|
||||
[Title("Input", "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 = "Deformed Position";
|
||||
public const string kOutputSlotNormalName = "Deformed Normal";
|
||||
public const string kOutputSlotTangentName = "Deformed 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 !HYBRID_RENDERER_0_6_0_OR_NEWER
|
||||
owner.AddSetupError(objectId, "Could not find version 0.6.0 or newer of the Hybrid Renderer package installed in the project.");
|
||||
hasError = true;
|
||||
#endif
|
||||
#if !ENABLE_COMPUTE_DEFORMATIONS
|
||||
owner.AddSetupError(objectId, "For the Compute Deformation node to work, you must go to Project Settings>Player>Other Settings and add the ENABLE_COMPUTE_DEFORMATIONS define to Scripting Define Symbols.");
|
||||
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()
|
||||
{
|
||||
displayName = "Compute Mesh Buffer Index Offset",
|
||||
overrideReferenceName = "_ComputeMeshIndex",
|
||||
overrideHLSLDeclaration = true,
|
||||
hlslDeclarationOverride = HLSLDeclaration.HybridPerInstance,
|
||||
#if ENABLE_HYBRID_RENDERER_V2
|
||||
hidden = true,
|
||||
#endif
|
||||
value = 0
|
||||
});
|
||||
|
||||
base.CollectShaderProperties(properties, generationMode);
|
||||
}
|
||||
|
||||
public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
|
||||
{
|
||||
#if ENABLE_HYBRID_RENDERER_V2
|
||||
sb.AppendLine("#if defined(UNITY_DOTS_INSTANCING_ENABLED)");
|
||||
#endif
|
||||
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)});");
|
||||
}
|
||||
#if ENABLE_HYBRID_RENDERER_V2
|
||||
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");
|
||||
#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("float3 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(UNITY_ACCESS_HYBRID_INSTANCED_PROP(_ComputeMeshIndex, float)) + vertexID];");
|
||||
sb.AppendLine("positionOut = vertexData.Position;");
|
||||
sb.AppendLine("normalOut = vertexData.Normal;");
|
||||
sb.AppendLine("tangentOut = vertexData.Tangent;");
|
||||
}
|
||||
sb.AppendLine("}");
|
||||
});
|
||||
}
|
||||
|
||||
string GetFunctionName()
|
||||
{
|
||||
return "Unity_ComputeDeformedVertex_$precision";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1b8bcd39f0b64c14eba5885020ae7349
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,183 @@
|
|||
using UnityEngine;
|
||||
using UnityEditor.Graphing;
|
||||
using UnityEditor.ShaderGraph.Internal;
|
||||
|
||||
namespace UnityEditor.ShaderGraph
|
||||
{
|
||||
[Title("Input", "Mesh Deformation", "Linear Blend Skinning")]
|
||||
class LinearBlendSkinningNode : AbstractMaterialNode, IGeneratesBodyCode, IGeneratesFunction, IMayRequireVertexSkinning, IMayRequirePosition, IMayRequireNormal, IMayRequireTangent
|
||||
{
|
||||
public const int kPositionSlotId = 0;
|
||||
public const int kNormalSlotId = 1;
|
||||
public const int kTangentSlotId = 2;
|
||||
public const int kPositionOutputSlotId = 3;
|
||||
public const int kNormalOutputSlotId = 4;
|
||||
public const int kTangentOutputSlotId = 5;
|
||||
|
||||
public const string kSlotPositionName = "Vertex Position";
|
||||
public const string kSlotNormalName = "Vertex Normal";
|
||||
public const string kSlotTangentName = "Vertex Tangent";
|
||||
public const string kOutputSlotPositionName = "Skinned Position";
|
||||
public const string kOutputSlotNormalName = "Skinned Normal";
|
||||
public const string kOutputSlotTangentName = "Skinned Tangent";
|
||||
|
||||
public LinearBlendSkinningNode()
|
||||
{
|
||||
name = "Linear Blend Skinning";
|
||||
UpdateNodeAfterDeserialization();
|
||||
}
|
||||
|
||||
public sealed override void UpdateNodeAfterDeserialization()
|
||||
{
|
||||
AddSlot(new PositionMaterialSlot(kPositionSlotId, kSlotPositionName, kSlotPositionName, CoordinateSpace.Object, ShaderStageCapability.Vertex));
|
||||
AddSlot(new NormalMaterialSlot(kNormalSlotId, kSlotNormalName, kSlotNormalName, CoordinateSpace.Object, ShaderStageCapability.Vertex));
|
||||
AddSlot(new TangentMaterialSlot(kTangentSlotId, kSlotTangentName, kSlotTangentName, CoordinateSpace.Object, ShaderStageCapability.Vertex));
|
||||
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[] { kPositionSlotId, kNormalSlotId, kTangentSlotId, kPositionOutputSlotId, kNormalOutputSlotId, kTangentOutputSlotId });
|
||||
}
|
||||
|
||||
public bool RequiresVertexSkinning(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)
|
||||
{
|
||||
#if HYBRID_RENDERER_0_6_0_OR_NEWER
|
||||
properties.AddShaderProperty(new Vector1ShaderProperty()
|
||||
{
|
||||
displayName = "Skin Matrix Index Offset",
|
||||
overrideReferenceName = "_SkinMatrixIndex",
|
||||
overrideHLSLDeclaration = true,
|
||||
hlslDeclarationOverride = HLSLDeclaration.HybridPerInstance,
|
||||
#if ENABLE_HYBRID_RENDERER_V2
|
||||
hidden = true,
|
||||
#endif
|
||||
value = 0
|
||||
});
|
||||
|
||||
#else
|
||||
properties.AddShaderProperty(new Vector1ShaderProperty()
|
||||
{
|
||||
overrideReferenceName = "_SkinMatricesOffset",
|
||||
overrideHLSLDeclaration = true,
|
||||
hlslDeclarationOverride = HLSLDeclaration.HybridPerInstance,
|
||||
#if ENABLE_HYBRID_RENDERER_V2
|
||||
hidden = true,
|
||||
#endif
|
||||
value = 0
|
||||
});
|
||||
#endif
|
||||
|
||||
|
||||
base.CollectShaderProperties(properties, generationMode);
|
||||
}
|
||||
|
||||
public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
|
||||
{
|
||||
#if ENABLE_HYBRID_RENDERER_V2
|
||||
sb.AppendLine("#if defined(UNITY_DOTS_INSTANCING_ENABLED)");
|
||||
#endif
|
||||
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.BoneIndices, " +
|
||||
$"IN.BoneWeights, " +
|
||||
$"{GetSlotValue(kPositionSlotId, generationMode)}, " +
|
||||
$"{GetSlotValue(kNormalSlotId, generationMode)}, " +
|
||||
$"{GetSlotValue(kTangentSlotId, generationMode)}, " +
|
||||
$"{GetVariableNameForSlot(kPositionOutputSlotId)}, " +
|
||||
$"{GetVariableNameForSlot(kNormalOutputSlotId)}, " +
|
||||
$"{GetVariableNameForSlot(kTangentOutputSlotId)});");
|
||||
}
|
||||
#if ENABLE_HYBRID_RENDERER_V2
|
||||
sb.AppendLine("#else");
|
||||
sb.AppendLine("$precision3 {0} = {1};", GetVariableNameForSlot(kPositionOutputSlotId), GetSlotValue(kPositionSlotId, generationMode));
|
||||
sb.AppendLine("$precision3 {0} = {1};", GetVariableNameForSlot(kNormalOutputSlotId), GetSlotValue(kNormalSlotId, generationMode));
|
||||
sb.AppendLine("$precision3 {0} = {1};", GetVariableNameForSlot(kTangentOutputSlotId), GetSlotValue(kTangentSlotId, generationMode));
|
||||
sb.AppendLine("#endif");
|
||||
#endif
|
||||
}
|
||||
|
||||
public void GenerateNodeFunction(FunctionRegistry registry, GenerationMode generationMode)
|
||||
{
|
||||
registry.ProvideFunction("SkinMatrices", sb =>
|
||||
{
|
||||
sb.AppendLine("uniform StructuredBuffer<float3x4> _SkinMatrices;");
|
||||
});
|
||||
|
||||
registry.ProvideFunction(GetFunctionName(), sb =>
|
||||
{
|
||||
sb.AppendLine($"void {GetFunctionName()}(" +
|
||||
"uint4 indices, " +
|
||||
"$precision4 weights, " +
|
||||
"$precision3 positionIn, " +
|
||||
"$precision3 normalIn, " +
|
||||
"$precision3 tangentIn, " +
|
||||
"out $precision3 positionOut, " +
|
||||
"out $precision3 normalOut, " +
|
||||
"out $precision3 tangentOut)");
|
||||
sb.AppendLine("{");
|
||||
using (sb.IndentScope())
|
||||
{
|
||||
sb.AppendLine("positionOut = 0;");
|
||||
sb.AppendLine("normalOut = 0;");
|
||||
sb.AppendLine("tangentOut = 0;");
|
||||
sb.AppendLine("for (int i = 0; i < 4; ++i)");
|
||||
sb.AppendLine("{");
|
||||
using (sb.IndentScope())
|
||||
{
|
||||
#if HYBRID_RENDERER_0_6_0_OR_NEWER
|
||||
sb.AppendLine("$precision3x4 skinMatrix = _SkinMatrices[indices[i] + asint(UNITY_ACCESS_HYBRID_INSTANCED_PROP(_SkinMatrixIndex,float))];");
|
||||
#else
|
||||
sb.AppendLine("$precision3x4 skinMatrix = _SkinMatrices[indices[i] + (int)UNITY_ACCESS_HYBRID_INSTANCED_PROP(_SkinMatricesOffset,float)];");
|
||||
#endif
|
||||
sb.AppendLine("$precision3 vtransformed = mul(skinMatrix, $precision4(positionIn, 1));");
|
||||
sb.AppendLine("$precision3 ntransformed = mul(skinMatrix, $precision4(normalIn, 0));");
|
||||
sb.AppendLine("$precision3 ttransformed = mul(skinMatrix, $precision4(tangentIn, 0));");
|
||||
sb.AppendLine("");
|
||||
sb.AppendLine("positionOut += vtransformed * weights[i];");
|
||||
sb.AppendLine("normalOut += ntransformed * weights[i];");
|
||||
sb.AppendLine("tangentOut += ttransformed * weights[i];");
|
||||
}
|
||||
sb.AppendLine("}");
|
||||
}
|
||||
sb.AppendLine("}");
|
||||
});
|
||||
}
|
||||
|
||||
string GetFunctionName()
|
||||
{
|
||||
return "Unity_LinearBlendSkinning_$precision";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f0e25259c308af440a82e1a5e66acf40
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Add table
Add a link
Reference in a new issue