浏览代码
Merge branch 'hackweek2017' of https://github.com/stramit/MaterialGraph into hackweek2017
/main
Merge branch 'hackweek2017' of https://github.com/stramit/MaterialGraph into hackweek2017
/main
Jennifer Nordwall
8 年前
当前提交
c51c8ff3
共有 19 个文件被更改,包括 492 次插入 和 46 次删除
-
2MaterialGraphProject/Assets/Eduardo/EduardoTestGraph.ShaderGraph
-
2MaterialGraphProject/Assets/Eduardo/FunctionNInNOut.cs
-
2MaterialGraphProject/Assets/Eduardo/HeightToNormalNode.cs
-
98MaterialGraphProject/Assets/Matt/AbstractAdvancedMasterNode.cs
-
2MaterialGraphProject/Assets/Matt/AnisotropicMaster.ShaderGraph
-
12MaterialGraphProject/Assets/Matt/AnisotropicMetallicMasterNode.cs
-
2MaterialGraphProject/Assets/Matt/New Material.mat
-
10MaterialGraphProject/Assets/UnityShaderEditor/Editor/Templates/advancedSubshader.template
-
1MaterialGraphProject/Assets/UnityShaderEditor/Editor/Templates/shader.template
-
12MaterialGraphProject/Assets/Vlad/TextureAssetNode.cs
-
15MaterialGraphProject/Assets/Vlad/UVTriPlanar.cs
-
46MaterialGraphProject/Assets/Eduardo/ChannelBlendNode.cs
-
12MaterialGraphProject/Assets/Eduardo/ChannelBlendNode.cs.meta
-
1MaterialGraphProject/Assets/Matt/SubsurfaceMaster.ShaderGraph
-
9MaterialGraphProject/Assets/Matt/SubsurfaceMaster.ShaderGraph.meta
-
86MaterialGraphProject/Assets/Matt/SubsurfaceMetallicMasterNode.cs
-
12MaterialGraphProject/Assets/Matt/SubsurfaceMetallicMasterNode.cs.meta
-
202MaterialGraphProject/Assets/NewNodes/WIP/MultiLayerParallaxNode.cs
-
12MaterialGraphProject/Assets/NewNodes/WIP/MultiLayerParallaxNode.cs.meta
2
MaterialGraphProject/Assets/Eduardo/EduardoTestGraph.ShaderGraph
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
2
MaterialGraphProject/Assets/Matt/AnisotropicMaster.ShaderGraph
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
using UnityEngine.Graphing; |
|||
using System.Linq; |
|||
using System.Collections; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Title("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); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: a3ee559026fa1ca4aab68fafbdcfbc56 |
|||
timeCreated: 1495618140 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
1
MaterialGraphProject/Assets/Matt/SubsurfaceMaster.ShaderGraph
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: 25497a67e7ee41d4c8f2039c1df994a1 |
|||
timeCreated: 1495614205 |
|||
licenseType: Pro |
|||
ScriptedImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|||
script: {fileID: 11500000, guid: 625f186215c104763be7675aa2d941aa, type: 3} |
|
|||
using System; |
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Serializable] |
|||
[Title("Master/SubsurfaceMetallic")] |
|||
public class SubsurfaceMetallicMasterNode : AbstractAdvancedMasterNode |
|||
{ |
|||
public const string MetallicSlotName = "Metallic"; |
|||
public const int MetallicSlotId = 2; |
|||
|
|||
public const string TranslucencySlotName = "Translucency"; |
|||
public const int TranslucencySlotId = 9; |
|||
|
|||
public const string LightFunctionName = "Advanced"; |
|||
public const string SurfaceOutputStructureName = "SurfaceOutputAdvanced"; |
|||
|
|||
public SubsurfaceMetallicMasterNode() |
|||
{ |
|||
name = "SubsurfaceMetallic"; |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
public override string GetMaterialID() |
|||
{ |
|||
return "SHADINGMODELID_SUBSURFACE"; |
|||
} |
|||
|
|||
public override int[] GetCustomDataSlots() |
|||
{ |
|||
return new int[] { 9 }; |
|||
} |
|||
|
|||
public override string[] GetCustomData() |
|||
{ |
|||
string translucencyInput = GetVariableNameForSlotAtId(9); |
|||
if (translucencyInput == "") |
|||
translucencyInput = "float3(0,0,0)"; |
|||
else |
|||
translucencyInput = translucencyInput + ".rgb"; |
|||
return new string[] { "o.CustomData = float4(" + translucencyInput + ", 0);" }; |
|||
} |
|||
|
|||
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(TranslucencySlotId, TranslucencySlotName, TranslucencySlotName, SlotType.Input, SlotValueType.Vector3, 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, |
|||
TranslucencySlotId |
|||
}); |
|||
} |
|||
|
|||
public override string GetSurfaceOutputName() |
|||
{ |
|||
return SurfaceOutputStructureName; |
|||
} |
|||
|
|||
public override string GetLightFunction() |
|||
{ |
|||
return LightFunctionName; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 7c541e9dc2ccc50469af225259c7cb17 |
|||
timeCreated: 1478188276 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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; |
|||
} |
|||
} |
|||
} |
|||
|
|
|||
fileFormatVersion: 2 |
|||
guid: 1970e51ab882ec24cb06ec8cbbefd184 |
|||
timeCreated: 1495557243 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue