initial commit

This commit is contained in:
Jo 2025-01-07 02:06:59 +01:00
parent 6715289efe
commit 788c3389af
37645 changed files with 2526849 additions and 80 deletions

View file

@ -0,0 +1,42 @@
using System;
using System.Reflection;
using UnityEngine;
namespace UnityEditor.ShaderGraph
{
[Title("Channel", "Combine")]
class CombineNode : CodeFunctionNode
{
public CombineNode()
{
name = "Combine";
synonyms = new string[] { "append" };
}
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_Combine", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_Combine(
[Slot(0, Binding.None)] Vector1 R,
[Slot(1, Binding.None)] Vector1 G,
[Slot(2, Binding.None)] Vector1 B,
[Slot(3, Binding.None)] Vector1 A,
[Slot(4, Binding.None)] out Vector4 RGBA,
[Slot(5, Binding.None)] out Vector3 RGB,
[Slot(6, Binding.None)] out Vector2 RG)
{
RGBA = Vector4.zero;
RGB = Vector3.zero;
RG = Vector2.zero;
return @"
{
RGBA = $precision4(R, G, B, A);
RGB = $precision3(R, G, B);
RG = $precision2(R, G);
}
";
}
}
}

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 3738e97908dea1f4bbc5e5a7cf562ecc
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View file

@ -0,0 +1,175 @@
using System;
using System.Collections.Generic;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Controls;
using UnityEditor.ShaderGraph.Internal;
using UnityEngine;
namespace UnityEditor.ShaderGraph
{
[Title("Channel", "Flip")]
class FlipNode : AbstractMaterialNode, IGeneratesBodyCode, IGeneratesFunction
{
public FlipNode()
{
name = "Flip";
UpdateNodeAfterDeserialization();
}
const int InputSlotId = 0;
const int OutputSlotId = 1;
const string kInputSlotName = "In";
const string kOutputSlotName = "Out";
public override bool hasPreview
{
get { return true; }
}
string GetFunctionName()
{
// NOTE: it's important we use the $precision generic form of the slot type in the name here
return $"Unity_Flip_{FindSlot<MaterialSlot>(InputSlotId).concreteValueType.ToShaderString()}";
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new DynamicVectorMaterialSlot(InputSlotId, kInputSlotName, kInputSlotName, SlotType.Input, Vector4.zero));
AddSlot(new DynamicVectorMaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, Vector4.zero));
RemoveSlotsNameNotMatching(new[] { InputSlotId, OutputSlotId });
}
int channelCount { get { return SlotValueHelper.GetChannelCount(FindSlot<MaterialSlot>(InputSlotId).concreteValueType); } }
[SerializeField]
private bool m_RedChannel;
[ToggleControl("Red")]
public ToggleData redChannel
{
get { return new ToggleData(m_RedChannel, channelCount > 0); }
set
{
if (m_RedChannel == value.isOn)
return;
m_RedChannel = value.isOn;
Dirty(ModificationScope.Node);
}
}
[SerializeField]
private bool m_GreenChannel;
[ToggleControl("Green")]
public ToggleData greenChannel
{
get { return new ToggleData(m_GreenChannel, channelCount > 1); }
set
{
if (m_GreenChannel == value.isOn)
return;
m_GreenChannel = value.isOn;
Dirty(ModificationScope.Node);
}
}
[SerializeField]
private bool m_BlueChannel;
[ToggleControl("Blue")]
public ToggleData blueChannel
{
get { return new ToggleData(m_BlueChannel, channelCount > 2); }
set
{
if (m_BlueChannel == value.isOn)
return;
m_BlueChannel = value.isOn;
Dirty(ModificationScope.Node);
}
}
[SerializeField]
private bool m_AlphaChannel;
[ToggleControl("Alpha")]
public ToggleData alphaChannel
{
get { return new ToggleData(m_AlphaChannel, channelCount > 3); }
set
{
if (m_AlphaChannel == value.isOn)
return;
m_AlphaChannel = value.isOn;
Dirty(ModificationScope.Node);
}
}
public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
{
var inputValue = GetSlotValue(InputSlotId, generationMode);
var outputValue = GetSlotValue(OutputSlotId, generationMode);
sb.AppendLine("{0} {1};", FindOutputSlot<MaterialSlot>(OutputSlotId).concreteValueType.ToShaderString(), GetVariableNameForSlot(OutputSlotId));
if (!generationMode.IsPreview())
{
sb.TryAppendIndentation();
sb.Append("{0} _{1}_Flip = {0} ({2}",
FindInputSlot<MaterialSlot>(InputSlotId).concreteValueType.ToShaderString(),
GetVariableNameForNode(),
Convert.ToInt32(m_RedChannel));
if (channelCount > 1)
sb.Append(", {0}", Convert.ToInt32(m_GreenChannel));
if (channelCount > 2)
sb.Append(", {0}", Convert.ToInt32(m_BlueChannel));
if (channelCount > 3)
sb.Append(", {0}", Convert.ToInt32(m_AlphaChannel));
sb.Append(");");
sb.AppendNewLine();
}
sb.AppendLine("{0}({1}, _{2}_Flip, {3});", GetFunctionName(), inputValue, GetVariableNameForNode(), outputValue);
}
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
{
base.CollectPreviewMaterialProperties(properties);
properties.Add(new PreviewProperty(PropertyType.Vector4)
{
name = string.Format("_{0}_Flip", GetVariableNameForNode()),
vector4Value = new Vector4(Convert.ToInt32(m_RedChannel), Convert.ToInt32(m_GreenChannel), Convert.ToInt32(m_BlueChannel), Convert.ToInt32(m_AlphaChannel)),
});
}
public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode)
{
if (!generationMode.IsPreview())
return;
base.CollectShaderProperties(properties, generationMode);
properties.AddShaderProperty(new Vector4ShaderProperty
{
overrideReferenceName = string.Format("_{0}_Flip", GetVariableNameForNode()),
generatePropertyBlock = false
});
}
public void GenerateNodeFunction(FunctionRegistry registry, GenerationMode generationMode)
{
registry.ProvideFunction(GetFunctionName(), s =>
{
s.AppendLine("void {0}({1} In, {2} Flip, out {3} Out)",
GetFunctionName(),
FindInputSlot<MaterialSlot>(InputSlotId).concreteValueType.ToShaderString(),
FindInputSlot<MaterialSlot>(InputSlotId).concreteValueType.ToShaderString(),
FindOutputSlot<MaterialSlot>(OutputSlotId).concreteValueType.ToShaderString());
using (s.BlockScope())
{
s.AppendLine("Out = (Flip * -2 + 1) * In;");
}
});
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: fa443691530c547418e195e22597f2af
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,63 @@
using System;
using System.Linq;
using UnityEngine;
using UnityEditor.Graphing;
namespace UnityEditor.ShaderGraph
{
[Title("Channel", "Split")]
class SplitNode : AbstractMaterialNode, IGeneratesBodyCode
{
const string kInputSlotName = "In";
const string kOutputSlotRName = "R";
const string kOutputSlotGName = "G";
const string kOutputSlotBName = "B";
const string kOutputSlotAName = "A";
public const int InputSlotId = 0;
public const int OutputSlotRId = 1;
public const int OutputSlotGId = 2;
public const int OutputSlotBId = 3;
public const int OutputSlotAId = 4;
public SplitNode()
{
name = "Split";
synonyms = new string[] { "separate" };
UpdateNodeAfterDeserialization();
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new DynamicVectorMaterialSlot(InputSlotId, kInputSlotName, kInputSlotName, SlotType.Input, Vector4.zero));
AddSlot(new Vector1MaterialSlot(OutputSlotRId, kOutputSlotRName, kOutputSlotRName, SlotType.Output, 0));
AddSlot(new Vector1MaterialSlot(OutputSlotGId, kOutputSlotGName, kOutputSlotGName, SlotType.Output, 0));
AddSlot(new Vector1MaterialSlot(OutputSlotBId, kOutputSlotBName, kOutputSlotBName, SlotType.Output, 0));
AddSlot(new Vector1MaterialSlot(OutputSlotAId, kOutputSlotAName, kOutputSlotAName, SlotType.Output, 0));
RemoveSlotsNameNotMatching(new int[] { InputSlotId, OutputSlotRId, OutputSlotGId, OutputSlotBId, OutputSlotAId });
}
static int[] s_OutputSlots = { OutputSlotRId, OutputSlotGId, OutputSlotBId, OutputSlotAId };
public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
{
var inputValue = GetSlotValue(InputSlotId, generationMode);
var inputSlot = FindInputSlot<MaterialSlot>(InputSlotId);
var numInputChannels = 0;
if (inputSlot != null)
{
numInputChannels = SlotValueHelper.GetChannelCount(inputSlot.concreteValueType);
if (numInputChannels > 4)
numInputChannels = 0;
}
for (var i = 0; i < 4; i++)
{
var outputFormat = numInputChannels == 1 ? inputValue : string.Format("{0}[{1}]", inputValue, i);
var outputValue = i >= numInputChannels ? "0" : outputFormat;
sb.AppendLine(string.Format("$precision {0} = {1};", GetVariableNameForSlot(s_OutputSlots[i]), outputValue));
}
}
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 892fc353b154d0347854e3bebf1b49e7
timeCreated: 1490896965
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,194 @@
using System.Collections.Generic;
using System.Linq;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Controls;
using UnityEngine;
using UnityEditor.Rendering;
namespace UnityEditor.ShaderGraph
{
[Title("Channel", "Swizzle")]
class SwizzleNode : AbstractMaterialNode, IGeneratesBodyCode
{
public SwizzleNode()
{
name = "Swizzle";
synonyms = new string[] { "swap", "reorder", "component mask" };
UpdateNodeAfterDeserialization();
}
const int InputSlotId = 0;
const int OutputSlotId = 1;
const string kInputSlotName = "In";
const string kOutputSlotName = "Out";
public override bool hasPreview
{
get { return true; }
}
[SerializeField]
string _maskInput = "xyzw";
[TextControl("Mask:")]
public string maskInput
{
get { return _maskInput; }
set
{
if (_maskInput.Equals(value))
return;
_maskInput = value;
UpdateNodeAfterDeserialization();
Dirty(ModificationScope.Topological);
}
}
public string convertedMask;
public bool ValidateMaskInput(int InputValueSize)
{
convertedMask = _maskInput.ToLower();
Dictionary<char, char> mask_map = new Dictionary<char, char>
{
{'r', 'x' },
{'g', 'y' },
{'b', 'z' },
{'a', 'w' },
};
bool MaskInputIsValid = true;
char[] MaskChars = convertedMask.ToCharArray();
char[] AllChars = { 'x', 'y', 'z', 'w', 'r', 'g', 'b', 'a' };
List<char> CurrentChars = new List<char>();
for (int i = 0; i < InputValueSize; i++)
{
CurrentChars.Add(AllChars[i]);
CurrentChars.Add(AllChars[i + 4]);
}
foreach (char c in MaskChars)
{
if (!CurrentChars.Contains(c))
{
MaskInputIsValid = false;
}
}
if (MaskChars.Length <= 0 || MaskChars.Length > 4)
{
MaskInputIsValid = false;
}
//Convert "rgba" input to "xyzw" to avoid mismathcing
if (MaskInputIsValid)
{
char[] rgba = { 'r', 'g', 'b', 'a' };
for (int i = 0; i < MaskChars.Length; i++)
{
if (rgba.Contains(MaskChars[i]))
{
MaskChars[i] = mask_map[MaskChars[i]];
}
}
convertedMask = new string(MaskChars);
}
return MaskInputIsValid;
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new DynamicVectorMaterialSlot(InputSlotId, kInputSlotName, kInputSlotName, SlotType.Input, Vector4.zero));
switch (_maskInput.Length)
{
case 1:
AddSlot(new Vector1MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, 0));
break;
case 2:
AddSlot(new Vector2MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, Vector2.zero));
break;
case 3:
AddSlot(new Vector3MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, Vector3.zero));
break;
default:
AddSlot(new Vector4MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, Vector4.zero));
break;
}
RemoveSlotsNameNotMatching(new[] { InputSlotId, OutputSlotId });
}
public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
{
var outputSlotType = FindOutputSlot<MaterialSlot>(OutputSlotId).concreteValueType.ToShaderString();
var outputName = GetVariableNameForSlot(OutputSlotId);
var inputValue = GetSlotValue(InputSlotId, generationMode);
var inputValueType = FindInputSlot<MaterialSlot>(InputSlotId).concreteValueType;
var InputValueSize = SlotValueHelper.GetChannelCount(inputValueType);
if (!ValidateMaskInput(InputValueSize))
{
sb.AppendLine(string.Format("{0} {1} = 0;", outputSlotType, outputName));
}
else
{
sb.AppendLine("{0} {1} = {2}.{3};", outputSlotType, outputName, inputValue, convertedMask);
}
}
public override void ValidateNode()
{
base.ValidateNode();
var inputValueType = FindInputSlot<MaterialSlot>(InputSlotId).concreteValueType;
var InputValueSize = SlotValueHelper.GetChannelCount(inputValueType);
if (!ValidateMaskInput(InputValueSize))
{
owner.AddValidationError(objectId, "Invalid mask for a Vector" + InputValueSize + " input.", ShaderCompilerMessageSeverity.Error);
}
}
public override int latestVersion => 1;
public override void OnAfterMultiDeserialize(string json)
{
//collect texturechannel properties
//get the value
//pass it to maskInput
if (sgVersion < 1)
{
LegacySwizzleChannelData.LegacySwizzleChannel(json, this);
ChangeVersion(1);
UpdateNodeAfterDeserialization();
}
}
public override IEnumerable<int> allowedNodeVersions => new List<int> { 1 };
class LegacySwizzleChannelData
{
//collect texturechannel properties
[SerializeField]
public TextureChannel m_RedChannel;
[SerializeField]
public TextureChannel m_GreenChannel;
[SerializeField]
public TextureChannel m_BlueChannel;
[SerializeField]
public TextureChannel m_AlphaChannel;
public static void LegacySwizzleChannel(string json, SwizzleNode node)
{
Dictionary<TextureChannel, string> s_ComponentList = new Dictionary<TextureChannel, string>
{
{TextureChannel.Red, "r" },
{TextureChannel.Green, "g" },
{TextureChannel.Blue, "b" },
{TextureChannel.Alpha, "a" },
};
var legacySwizzleChannelData = new LegacySwizzleChannelData();
JsonUtility.FromJsonOverwrite(json, legacySwizzleChannelData);
node._maskInput = s_ComponentList[legacySwizzleChannelData.m_RedChannel] + s_ComponentList[legacySwizzleChannelData.m_GreenChannel] + s_ComponentList[legacySwizzleChannelData.m_BlueChannel] + s_ComponentList[legacySwizzleChannelData.m_AlphaChannel];
}
}
}
}

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 408ee761513fda7449bb3e428095726a
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData: