浏览代码

Merge branch 'hackweek2017' of https://github.com/stramit/MaterialGraph into hackweek2017

/main
Florent Guinier 8 年前
当前提交
f13a8ff6
共有 20 个文件被更改,包括 455 次插入30 次删除
  1. 2
      MaterialGraphProject/Assets/Eduardo/EduardoTestGraph.ShaderGraph
  2. 2
      MaterialGraphProject/Assets/Eduardo/FunctionNInNOut.cs
  3. 2
      MaterialGraphProject/Assets/Eduardo/HeightToNormalNode.cs
  4. 2
      MaterialGraphProject/Assets/Matt/SubsurfaceMaster.ShaderGraph
  5. 14
      MaterialGraphProject/Assets/Rinaldo/BlendModeNode.cs
  6. 2
      MaterialGraphProject/Assets/Rinaldo/BlendModesEnum.cs
  7. 2
      MaterialGraphProject/Assets/Rinaldo/Editor/BlendModeNodePresenter.cs
  8. 10
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/AbstractMaterialNode.cs
  9. 12
      MaterialGraphProject/Assets/Vlad/TextureAssetNode.cs
  10. 15
      MaterialGraphProject/Assets/Vlad/UVTriPlanar.cs
  11. 46
      MaterialGraphProject/Assets/Eduardo/ChannelBlendNode.cs
  12. 12
      MaterialGraphProject/Assets/Eduardo/ChannelBlendNode.cs.meta
  13. 20
      MaterialGraphProject/Assets/Eduardo/ReciprocalSqrtNode.cs
  14. 12
      MaterialGraphProject/Assets/Eduardo/ReciprocalSqrtNode.cs.meta
  15. 1
      MaterialGraphProject/Assets/Matt/ClothMaster.ShaderGraph
  16. 9
      MaterialGraphProject/Assets/Matt/ClothMaster.ShaderGraph.meta
  17. 96
      MaterialGraphProject/Assets/Matt/ClothMasterNode.cs
  18. 12
      MaterialGraphProject/Assets/Matt/ClothMasterNode.cs.meta
  19. 202
      MaterialGraphProject/Assets/NewNodes/WIP/MultiLayerParallaxNode.cs
  20. 12
      MaterialGraphProject/Assets/NewNodes/WIP/MultiLayerParallaxNode.cs.meta

2
MaterialGraphProject/Assets/Eduardo/EduardoTestGraph.ShaderGraph
文件差异内容过多而无法显示
查看文件

2
MaterialGraphProject/Assets/Eduardo/FunctionNInNOut.cs


private string GetOutputDeclaration()
{
string outDeclaration = "";
foreach (ISlot outSlot in GetOutputSlots<ISlot>())
foreach (MaterialSlot outSlot in GetOutputSlots<MaterialSlot>())
{
outDeclaration += "\n " + precision + GetSlotTypeName(outSlot.id) + " " + GetVariableNameForSlot(outSlot.id) + ";\n";
}

2
MaterialGraphProject/Assets/Eduardo/HeightToNormalNode.cs


namespace UnityEngine.MaterialGraph
{
[Title("HeightToNormal")]
[Title("Utility/Heightmap To Normalmap")]
public class HeightToNormalNode : FunctionNInNOut, IGeneratesFunction
{

2
MaterialGraphProject/Assets/Matt/SubsurfaceMaster.ShaderGraph
文件差异内容过多而无法显示
查看文件

14
MaterialGraphProject/Assets/Rinaldo/BlendModeNode.cs


}
}
}
/*This is to overide input to be vector 3, not really necessary anymore*/
/*This is to overide input to be vector 3, not really necessary */
/*
protected override MaterialSlot GetInputSlot1()
{

var outputString = new ShaderGenerator();
switch (m_BlendMode)
{
/* case BlendModesEnum.AddSub:
outputString.AddShaderChunk(GetFunctionPrototype("arg1", "arg2"), false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("return 2.0 * arg1 + arg2 - 1.0;", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
break;
*/
case BlendModesEnum.Burn:
outputString.AddShaderChunk(GetFunctionPrototype("arg1", "arg2"), false);
outputString.AddShaderChunk("{", false);

outputString.Deindent();
outputString.AddShaderChunk("}", false);
break;
case BlendModesEnum.LinearLight:
case BlendModesEnum.LinearLight_AddSub:
outputString.AddShaderChunk(GetFunctionPrototype("arg1", "arg2"), false);
outputString.AddShaderChunk("{", false);
outputString.Indent();

outputString.AddShaderChunk("}", false);
break;
}
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
}
}

2
MaterialGraphProject/Assets/Rinaldo/BlendModesEnum.cs


Lighten,
LinearBurn,
LinearDodge,
LinearLight,
LinearLight_AddSub,
Multiply,
Negation,
Overlay,

2
MaterialGraphProject/Assets/Rinaldo/Editor/BlendModeNodePresenter.cs


*/
public override float GetHeight()
{
return 3 * (EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing) + EditorGUIUtility.standardVerticalSpacing;
return EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing + EditorGUIUtility.standardVerticalSpacing;
}
}

10
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/AbstractMaterialNode.cs


if (inputSlot == null)
return string.Empty;
string sufix = "";
var edges = owner.GetEdges(inputSlot.slotReference).ToArray();
if (edges.Any())

if (slot == null)
return string.Empty;
if (slot.concreteValueType == ConcreteSlotValueType.sampler2D)
sufix += "_Uniform";
return ShaderGenerator.AdaptNodeOutput(fromNode, slot.id, slot.concreteValueType) + sufix;
return ShaderGenerator.AdaptNodeOutput(fromNode, slot.id, slot.concreteValueType);
if (inputSlot.concreteValueType == ConcreteSlotValueType.sampler2D)
sufix += "_Uniform";
return inputSlot.GetDefaultValue(generationMode) + sufix;
return inputSlot.GetDefaultValue(generationMode);
}
private ConcreteSlotValueType FindCommonChannelType(ConcreteSlotValueType from, ConcreteSlotValueType to)

12
MaterialGraphProject/Assets/Vlad/TextureAssetNode.cs


get { return new[] { OutputSlotRgbaId }; }
}
public override string GetVariableNameForSlot(int slotId)
{
string slotOutput;
switch (slotId)
{
default:
slotOutput = "";
break;
}
return GetVariableNameForNode() + slotOutput;
}
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
{
properties.Add(GetPreviewProperty());

15
MaterialGraphProject/Assets/Vlad/UVTriPlanar.cs


UpdateNodeAfterDeserialization();
}
protected override string GetFunctionPrototype(string argName)
public override bool hasPreview
{
get { return true; }
}
public override PreviewMode previewMode
{
get
{
return PreviewMode.Preview3D;
}
}
protected override string GetFunctionPrototype(string argName)
{
return "inline " + precision + outputDimension + " " + GetFunctionName() + " ("
+ "sampler2D " + argName + ", float3 normal, float3 pos)";

46
MaterialGraphProject/Assets/Eduardo/ChannelBlendNode.cs


using UnityEngine.Graphing;
using System.Linq;
using System.Collections;
namespace UnityEngine.MaterialGraph
{
[Title("Art/ChannelBlend")]
public class ChannelBlend : FunctionNInNOut, IGeneratesFunction
{
public ChannelBlend()
{
name = "ChannelBlend";
AddSlot("Mask", "mask", Graphing.SlotType.Input, SlotValueType.Vector4, Vector4.zero);
AddSlot("RColor", "rCol", Graphing.SlotType.Input, SlotValueType.Vector4, Vector4.zero);
AddSlot("GColor", "gCol", Graphing.SlotType.Input, SlotValueType.Vector4, Vector4.zero);
AddSlot("BColor", "bCol", Graphing.SlotType.Input, SlotValueType.Vector4, Vector4.zero);
AddSlot("AColor", "aCol", Graphing.SlotType.Input, SlotValueType.Vector4, Vector4.zero);
AddSlot("BGColor", "bgCol", Graphing.SlotType.Input, SlotValueType.Vector4, Vector4.zero);
AddSlot("BlendedColor", "blendCol", Graphing.SlotType.Output, SlotValueType.Vector4, Vector4.zero);
}
protected override string GetFunctionName()
{
return "unity_ChannelBlend";
}
public override bool hasPreview
{
get { return true; }
}
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)
{
var outputString = new ShaderGenerator();
outputString.AddShaderChunk(GetFunctionPrototype(), false);
outputString.AddShaderChunk("{", false);
outputString.AddShaderChunk("float4 background = step(max(mask.r,max(mask.g,mask.b)), 0.001) * bgCol;", false);
outputString.AddShaderChunk("blendCol = mask.r * rCol + mask.g * gCol + mask.b * bCol + mask.a * aCol + background;", false);
outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
}
}
}

12
MaterialGraphProject/Assets/Eduardo/ChannelBlendNode.cs.meta


fileFormatVersion: 2
guid: a3ee559026fa1ca4aab68fafbdcfbc56
timeCreated: 1495618140
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

20
MaterialGraphProject/Assets/Eduardo/ReciprocalSqrtNode.cs


namespace UnityEngine.MaterialGraph
{
[Title("Math/Advanced/Reciprocal Square Root")]
public class ReciprocalSqrtNode : Function1Input
{
public ReciprocalSqrtNode()
{
name = "ReciprocalSquareRoot";
}
public override bool hasPreview
{
get { return false; }
}
protected override string GetFunctionName() { return "rsqrt"; }
}
}

12
MaterialGraphProject/Assets/Eduardo/ReciprocalSqrtNode.cs.meta


fileFormatVersion: 2
guid: d67c532974f20f74ca83c79573c45a61
timeCreated: 1495627989
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

1
MaterialGraphProject/Assets/Matt/ClothMaster.ShaderGraph
文件差异内容过多而无法显示
查看文件

9
MaterialGraphProject/Assets/Matt/ClothMaster.ShaderGraph.meta


fileFormatVersion: 2
guid: c6f272d98c8edc642b85922a6d8ffe9c
timeCreated: 1495626442
licenseType: Pro
ScriptedImporter:
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 11500000, guid: 625f186215c104763be7675aa2d941aa, type: 3}

96
MaterialGraphProject/Assets/Matt/ClothMasterNode.cs


using System;
using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
[Serializable]
[Title("Master/Cloth")]
public class ClothMasterNode : AbstractAdvancedMasterNode
{
//public const string MetallicSlotName = "Metallic";
//public const int MetallicSlotId = 2;
public const string FuzzSlotName = "Fuzz";
public const int FuzzSlotId = 9;
public const string ClothFactorSlotName = "ClothFactor";
public const int ClothFactorSlotId = 10;
public const string LightFunctionName = "Advanced";
public const string SurfaceOutputStructureName = "SurfaceOutputAdvanced";
public ClothMasterNode()
{
name = "Cloth";
UpdateNodeAfterDeserialization();
}
public override string GetMaterialID()
{
return "SHADINGMODELID_CLOTH";
}
public override int[] GetCustomDataSlots()
{
return new int[] { 9, 10 };
}
public override string[] GetCustomData()
{
string fuzzInput = GetVariableNameForSlotAtId(9);
if (fuzzInput == "")
fuzzInput = "float3(0,0,0)";
else
fuzzInput = fuzzInput + ".rgb";
string clothFactorInput = GetVariableNameForSlotAtId(10);
if (clothFactorInput == "")
clothFactorInput = "0";
else
clothFactorInput = clothFactorInput + ".r";
return new string[] { "o.CustomData = float4(" + fuzzInput + ", "+ clothFactorInput + ");" };
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(AlbedoSlotId, AlbedoSlotName, AlbedoSlotName, SlotType.Input, SlotValueType.Vector3, Vector4.zero));
AddSlot(new MaterialSlot(NormalSlotId, NormalSlotName, NormalSlotName, SlotType.Input, SlotValueType.Vector3, Vector4.zero));
AddSlot(new MaterialSlot(EmissionSlotId, EmissionSlotName, EmissionSlotName, SlotType.Input, SlotValueType.Vector3, Vector4.zero));
//AddSlot(new MaterialSlot(MetallicSlotId, MetallicSlotName, MetallicSlotName, SlotType.Input, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(SmoothnessSlotId, SmoothnessSlotName, SmoothnessSlotName, SlotType.Input, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(OcclusionSlotId, OcclusionSlotName, OcclusionSlotName, SlotType.Input, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(AnisotropySlotId, AnisotropySlotName, AnisotropySlotName, SlotType.Input, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(TangentSlotId, TangentSlotName, TangentSlotName, SlotType.Input, SlotValueType.Vector3, Vector4.zero));
AddSlot(new MaterialSlot(AnisotropySlotId, AnisotropySlotName, AnisotropySlotName, SlotType.Input, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(FuzzSlotId, FuzzSlotName, FuzzSlotName, SlotType.Input, SlotValueType.Vector3, Vector4.zero));
AddSlot(new MaterialSlot(ClothFactorSlotId, ClothFactorSlotName, ClothFactorSlotName, SlotType.Input, SlotValueType.Vector1, Vector4.zero));
// clear out slot names that do not match the slots
// we support
RemoveSlotsNameNotMatching(
new[]
{
AlbedoSlotId,
NormalSlotId,
EmissionSlotId,
//MetallicSlotId,
SmoothnessSlotId,
OcclusionSlotId,
AlphaSlotId,
AnisotropySlotId,
TangentSlotId,
FuzzSlotId,
ClothFactorSlotId
});
}
public override string GetSurfaceOutputName()
{
return SurfaceOutputStructureName;
}
public override string GetLightFunction()
{
return LightFunctionName;
}
}
}

12
MaterialGraphProject/Assets/Matt/ClothMasterNode.cs.meta


fileFormatVersion: 2
guid: 4a9c7c58817be884f8b788d9e11dbef0
timeCreated: 1478188276
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

202
MaterialGraphProject/Assets/NewNodes/WIP/MultiLayerParallaxNode.cs


using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
[Title("UV/MultiLayerParallax")]
public class MultiLayerParallaxNode : AbstractMaterialNode, IGeneratesBodyCode, IGeneratesFunction, IMayRequireMeshUV, IMayRequireViewDirectionTangentSpace
{
protected const string kInputDepthShaderName = "Depth";
protected const string kInputFadeRateShaderName = "FadeRate";
protected const string kInputLayerCountShaderName = "LayerCount";
protected const string kTextureSlotShaderName = "Texture";
protected const string kOutputSlotShaderName = "Result";
public const int InputDepthSlotId = 0; // 'depth'
public const int InputFadeRateSlotId = 1; // 'fade_rate'
public const int InputLayerCountSlotId = 2; // 'layer_count'
public const int TextureSlotId = 3; // 'tex'
public const int OutputSlotId = 4; // 'result'
public override bool hasPreview
{
get { return true; }
}
public override PreviewMode previewMode
{
get
{
return PreviewMode.Preview3D;
}
}
public MultiLayerParallaxNode()
{
name = "MultiLayerParallax";
UpdateNodeAfterDeserialization();
}
public string GetFunctionName()
{
return "unity_multilayer_parallax_" + precision;
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(GetInputDepthSlot());
AddSlot(GetInputFadeRateSlot());
AddSlot(GetInputLayerCountSlot());
AddSlot(GetTextureSlot());
AddSlot(GetOutputSlot());
RemoveSlotsNameNotMatching(validSlots);
}
protected int[] validSlots
{
get { return new[] { InputDepthSlotId, InputFadeRateSlotId, InputLayerCountSlotId, TextureSlotId, OutputSlotId }; }
}
protected virtual MaterialSlot GetInputDepthSlot()
{
return new MaterialSlot(InputDepthSlotId, GetInputSlot1Name(), kInputDepthShaderName, SlotType.Input, SlotValueType.Vector1, Vector4.zero);
}
protected virtual MaterialSlot GetInputFadeRateSlot()
{
return new MaterialSlot(InputFadeRateSlotId, GetInputSlot2Name(), kInputFadeRateShaderName, SlotType.Input, SlotValueType.Dynamic, Vector4.zero);
}
protected virtual MaterialSlot GetInputLayerCountSlot()
{
return new MaterialSlot(InputLayerCountSlotId, GetInputSlot3Name(), kInputLayerCountShaderName, SlotType.Input, SlotValueType.Dynamic, Vector4.zero);
}
protected virtual MaterialSlot GetTextureSlot()
{
return new MaterialSlot(TextureSlotId, GetTextureSlotName(), kTextureSlotShaderName, SlotType.Input, SlotValueType.sampler2D, Vector4.zero);
}
protected virtual MaterialSlot GetOutputSlot()
{
return new MaterialSlot(OutputSlotId, GetOutputSlotName(), kOutputSlotShaderName, SlotType.Output, SlotValueType.Dynamic, Vector4.zero);
}
protected virtual string GetInputSlot1Name()
{
return kInputDepthShaderName;
}
protected virtual string GetInputSlot2Name()
{
return kInputFadeRateShaderName;
}
protected virtual string GetInputSlot3Name()
{
return kInputLayerCountShaderName;
}
protected virtual string GetTextureSlotName()
{
return kTextureSlotShaderName;
}
protected virtual string GetOutputSlotName()
{
return kOutputSlotShaderName;
}
private string input1Dimension
{
get { return ConvertConcreteSlotValueTypeToString(FindInputSlot<MaterialSlot>(InputDepthSlotId).concreteValueType); }
}
private string input2Dimension
{
get { return ConvertConcreteSlotValueTypeToString(FindInputSlot<MaterialSlot>(InputFadeRateSlotId).concreteValueType); }
}
private string input3Dimension
{
get { return ConvertConcreteSlotValueTypeToString(FindInputSlot<MaterialSlot>(InputLayerCountSlotId).concreteValueType); }
}
public string outputDimension
{
get { return ConvertConcreteSlotValueTypeToString(FindOutputSlot<MaterialSlot>(OutputSlotId).concreteValueType); }
}
protected virtual string GetFunctionPrototype(string depth, string fadeRate, string layerCount, string tex, string UVs, string viewTangentSpace)
{
return "inline " + precision + outputDimension + " " + GetFunctionName() + " (" +
precision + input1Dimension + " " + depth + ", " +
precision + input2Dimension + " " + fadeRate + ", " +
precision + input3Dimension + " " + layerCount + ", " +
"sampler2D " + tex + ", " +
precision + "2 " + UVs + ", " +
precision + "3 " + viewTangentSpace + ")";
}
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
{
NodeUtils.SlotConfigurationExceptionIfBadConfiguration(this, new[] { InputDepthSlotId, InputFadeRateSlotId, InputLayerCountSlotId, TextureSlotId }, new[] { OutputSlotId });
string depthValue = GetSlotValue(InputDepthSlotId, generationMode);
string fadeRateValue = GetSlotValue(InputFadeRateSlotId, generationMode);
string layerCountValue = GetSlotValue(InputLayerCountSlotId, generationMode);
string textureValue = GetSlotValue(TextureSlotId, generationMode);
visitor.AddShaderChunk(
precision + outputDimension + " " + GetVariableNameForSlot(OutputSlotId) +
" = " + GetFunctionCallBody(depthValue, fadeRateValue, layerCountValue, textureValue) + ";", true);
}
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)
{
var outputString = new ShaderGenerator();
outputString.AddShaderChunk(GetFunctionPrototype("depth", "fadeRate", "layerCount", "tex", "UVs", "viewTangentSpace"), false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk(precision + "2 texcoord = UVs;", false);
outputString.AddShaderChunk(precision + "2 offset = -viewTangentSpace.xy * depth / layerCount;", false);
outputString.AddShaderChunk(precision + outputDimension + " result = 0.0f;", false);
outputString.AddShaderChunk(precision + outputDimension + " fade = 1.0f;", false);
outputString.AddShaderChunk(precision + " alpha = 0.0f;", false);
outputString.AddShaderChunk("for (int i = 0; i < 10; i++) {", false);
outputString.Indent();
outputString.AddShaderChunk("result += fade * tex2D(tex, texcoord);", false);
outputString.AddShaderChunk("texcoord += offset;", false);
outputString.AddShaderChunk("fade *= fadeRate;", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
outputString.AddShaderChunk("return result / layerCount;", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
}
protected virtual string GetFunctionCallBody(string depthValue, string fadeRateValue, string layerCountValue, string texValue)
{
return GetFunctionName() + " (" +
depthValue + ", " +
fadeRateValue + ", " +
layerCountValue + ", " +
texValue + ", " +
UVChannel.uv0.GetUVName() + ", " +
ShaderGeneratorNames.TangentSpaceViewDirection + ")";
}
public bool RequiresMeshUV(UVChannel channel)
{
return channel == UVChannel.uv0;
}
public bool RequiresViewDirectionTangentSpace()
{
return true;
}
}
}

12
MaterialGraphProject/Assets/NewNodes/WIP/MultiLayerParallaxNode.cs.meta


fileFormatVersion: 2
guid: 1970e51ab882ec24cb06ec8cbbefd184
timeCreated: 1495557243
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存