Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
5792ffa
Adding dispose property drawer callback
Sep 22, 2021
fef610e
New space transform shared utility
Sep 22, 2021
d66b0c8
Adding ShaderStringBuilder helper functions
Sep 22, 2021
b5093dc
Update Transform Node to use the shared Util, control normalize, use …
Sep 23, 2021
48937fe
Add directional tangent space transforms
Sep 23, 2021
790944e
Fixing comments
Sep 23, 2021
507ff54
Adding "Normal" conversion type, fixing WorldToTangent to use the pro…
Sep 23, 2021
2e09d30
Adding changelog
Sep 23, 2021
8648c7a
Adding node tests for transform node
Sep 24, 2021
78845c7
fix for HDRP compile
Sep 27, 2021
b6165a9
adding image artifacts for failures
Sep 27, 2021
04d7364
Testing artifact generation
Sep 27, 2021
a70b117
Added expected and actual images
Sep 27, 2021
2fe5f88
Always write all results so we can see what's happening on linux
Sep 28, 2021
1136ada
Removing debug code
Sep 29, 2021
1bddcb4
Test reporting artifacts
Sep 29, 2021
e5753db
Can we get report image diffs to work?
Sep 29, 2021
93501fc
Cleaning up code, adding more transform tests
Sep 30, 2021
e6a5a19
Merge branch 'sg/fix/1346477-tests' into sg/fix/1346477
Sep 30, 2021
97f6d65
Cleaning up comments
Oct 1, 2021
2346d00
Comment cleanup
Oct 4, 2021
fab53e2
Fixing one more comment
Oct 4, 2021
c871da5
Fixing non-normalized tangent transforms (when your tangentToWorld is…
Oct 5, 2021
e24c5f1
Adding comments about what "tangentToWorld" matrix means
Oct 5, 2021
c96fa6b
Merge branch 'master' into sg/fix/1346477
jessebarker Oct 5, 2021
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
@@ -0,0 +1,129 @@
using System.Reflection;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Controls;
using UnityEngine;

namespace UnityEditor.ShaderGraph
{
[Title("Procedural", "Noise", "Integer Hash")]
class IntegerHashNode : AbstractMaterialNode, IGeneratesBodyCode, IGeneratesFunction
{
public IntegerHashNode()
{
name = "Integer Hash";
UpdateNodeAfterDeserialization();
}

public override bool hasPreview { get { return true; } }

// Input slots
private const int kInputSlotId = 1;
private const string kInputSlotName = "Coord";

// Output slots
private const int kOutputSlotId = 0;
private const string kOutputSlotName = "Hash";

// Local state
public enum HashType
{
Tchou_2_1,
Tchou_2_3,
Tchou_3_1,
Tchou_3_3,
};

struct Description
{
public string functionName;
public int inputDimension;
public int outputDimension;
public Description(string f, int i, int o) { functionName = f; inputDimension = i; outputDimension = o; }
};

static Description[] k_hashDescriptions =
{
new Description("Hash_Tchou_2_1_float", 2, 1),
new Description("Hash_Tchou_2_3_float", 2, 3),
new Description("Hash_Tchou_3_1_float", 3, 1),
new Description("Hash_Tchou_3_3_float", 3, 3),
};

[SerializeField]
private HashType m_HashType = HashType.Tchou_2_3;

[EnumControl("Hash")]
public HashType hashType
{
get
{
return m_HashType;
}
set
{
if (m_HashType == value)
return;

m_HashType = value;
Dirty(ModificationScope.Topological);
UpdateNodeAfterDeserialization();
}
}

Description hashDescription => ((int) hashType >= 0 && (int) hashType < k_hashDescriptions.Length) ? k_hashDescriptions[(int)hashType] : k_hashDescriptions[0];

public MaterialSlot CreateVectorSlot(int dimension, int id, string name, SlotType slotType, Vector4 value = default)
{
MaterialSlot slot = null;
switch (dimension)
{
case 1:
slot = new Vector1MaterialSlot(id, name, name, slotType, value.x);
break;
case 2:
slot = new Vector2MaterialSlot(id, name, name, slotType, value);
break;
case 3:
slot = new Vector3MaterialSlot(id, name, name, slotType, value);
break;
case 4:
slot = new Vector4MaterialSlot(id, name, name, slotType, value);
break;
}
return slot;
}

public sealed override void UpdateNodeAfterDeserialization()
{
var desc = hashDescription;

MaterialSlot inputSlot = CreateVectorSlot(desc.inputDimension, kInputSlotId, kInputSlotName, SlotType.Input);
AddSlot(inputSlot);

MaterialSlot outputSlot = CreateVectorSlot(desc.outputDimension, kOutputSlotId, kOutputSlotName, SlotType.Output);
AddSlot(outputSlot);

RemoveSlotsNameNotMatching(new[]
{
kInputSlotId,
kOutputSlotId
});
}

public void GenerateNodeFunction(FunctionRegistry registry, GenerationMode generationMode)
{
registry.RequiresIncludePath("Packages/com.unity.render-pipelines.core/ShaderLibrary/Hashes.hlsl");
}

public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
{
var desc = hashDescription;

var outputVar = GetVariableNameForSlot(kOutputSlotId);
var input = GetSlotValue(kInputSlotId, generationMode);

sb.AppendLine($"$precision{desc.outputDimension} {outputVar};");
sb.AppendLine($"{desc.functionName}({input}, {outputVar});");
}
}
}

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

Loading