浏览代码
Merge branch 'hackweek2017' of https://github.com/stramit/MaterialGraph into hackweek2017
/main
Merge branch 'hackweek2017' of https://github.com/stramit/MaterialGraph into hackweek2017
/main
RinaldoTjan
8 年前
当前提交
41da8598
共有 323 个文件被更改,包括 1022 次插入 和 155 次删除
-
6MaterialGraphProject/Assets/Andre/New Material.mat
-
2MaterialGraphProject/Assets/Andre/New Shader Graph.ShaderGraph
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/LevelsNodePresenter.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/HelperShader.shader
-
6MaterialGraphProject/Assets/UnityShaderEditor/Editor/HelperShader.shader.meta
-
4MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Texture/CubemapNode.cs
-
38MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/UV/CartesianToPolarNode.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Procedural/CheckerboardNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Trigonometry/DegreesToRadiansNode.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Procedural/GradientRampNode.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Procedural/HexNode.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Procedural/ParticleNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Trigonometry/RadiansToDegreesNode.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Advanced/ReciprocalNode.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/UV/UVTileNode.cs
-
20MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Procedural/LineNode.cs
-
6MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/UV/UVPannerNode.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Basic/AddNode.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Vector/Vector4Node.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Legacy/LegacyBlendNode.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Basic/DivNode.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Vector/DotNode.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Vector/FresnelNode.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Basic/MultiplyNode.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Vector/ReflectNode.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Time/SinTimeNode.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Basic/SubtractNode.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Channel/SwizzleNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Time/TimeNode.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Normal/UnpackNormalNode.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Vector/Vector1Node.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Vector/Vector2Node.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Vector/Vector3Node.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/ColorNode.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/SceneData/ScreenPosNode.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Geometry/WorldSpacePositionNode.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Geometry/WorldSpaceViewDirectionNode.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Geometry/WorldSpaceNormalNode.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Geometry/WorldSpaceTangentNode.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Geometry/WorldSpaceBitangentNode.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Geometry/VertexColorNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Geometry/UVNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Texture/TextureNode.cs
-
10MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Art/Adjustments/LevelsNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Art/Conversion/HSVtoRGBNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Art/Adjustments/HueNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Art/Conversion/RGBtoHSVNode.cs
-
6MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Art/Adjustments/ContrastNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/SceneData/DepthTextureNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/SceneData/MotionVectorTextureNode.cs
-
6MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Art/Conversion/RGBtoLuminanceNode.cs
-
6MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Art/Adjustments/SaturationNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Art/Conversion/LinearToRGBNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Art/Conversion/RGBtoLinearNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Texture/TextureLODNode.cs
-
53MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/UV/UVRotatorNode.cs
-
104MaterialGraphProject/Assets/Brandon/NoiseNode.cs
-
12MaterialGraphProject/Assets/Brandon/NoiseNode.cs.meta
-
50MaterialGraphProject/Assets/Eduardo/Editor/AddManyNodePresenter.cs
-
12MaterialGraphProject/Assets/Eduardo/Editor/AddManyNodePresenter.cs.meta
-
70MaterialGraphProject/Assets/Eduardo/FunctionNAddNode.cs
-
12MaterialGraphProject/Assets/Eduardo/FunctionNAddNode.cs.meta
-
141MaterialGraphProject/Assets/Eduardo/FunctionNInNOut.cs
-
12MaterialGraphProject/Assets/Eduardo/FunctionNInNOut.cs.meta
-
1MaterialGraphProject/Assets/TestGraph.ShaderGraph
-
9MaterialGraphProject/Assets/TestGraph.ShaderGraph.meta
-
9MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Art.meta
-
9MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Channel.meta
-
9MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input.meta
-
9MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Legacy.meta
-
9MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math.meta
-
9MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Normal.meta
-
9MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Procedural.meta
-
9MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/UV.meta
-
9MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Art/Adjustments.meta
-
9MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Art/Conversion.meta
-
141MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Channel/CombineNode.cs
-
147MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Channel/SplitNode.cs
-
9MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Geometry.meta
-
9MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/SceneData.meta
-
9MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Texture.meta
-
9MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Time.meta
-
9MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Vector.meta
-
9MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Advanced.meta
2
MaterialGraphProject/Assets/Andre/New Shader Graph.ShaderGraph
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Title("Procedural/Noise")] |
|||
public class NoiseNode : Function1Input, IGeneratesFunction |
|||
{ |
|||
public NoiseNode() |
|||
{ |
|||
name = "Noise"; |
|||
} |
|||
|
|||
protected override string GetFunctionName() |
|||
{ |
|||
return "unity_noise_" + precision; |
|||
} |
|||
|
|||
protected override string GetInputSlotName() |
|||
{ |
|||
return "UV"; |
|||
} |
|||
|
|||
protected override MaterialSlot GetInputSlot() |
|||
{ |
|||
return new MaterialSlot(InputSlotId, GetInputSlotName(), kInputSlotShaderName, UnityEngine.Graphing.SlotType.Input, SlotValueType.Vector2, Vector2.zero); |
|||
} |
|||
|
|||
protected override MaterialSlot GetOutputSlot() |
|||
{ |
|||
return new MaterialSlot(OutputSlotId, GetOutputSlotName(), kOutputSlotShaderName, UnityEngine.Graphing.SlotType.Output, SlotValueType.Vector1, Vector2.zero); |
|||
} |
|||
|
|||
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
var outputString = new ShaderGenerator(); |
|||
|
|||
outputString.AddShaderChunk("inline float unity_noise_randomValue (float2 uv)", false); |
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
|
|||
outputString.AddShaderChunk("return frac(sin(dot(uv, float2(12.9898, 78.233)))*43758.5453);", false); |
|||
|
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", false); |
|||
|
|||
|
|||
outputString.AddShaderChunk("inline float unity_noise_interpolate (float a, float b, float t)", false); |
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
|
|||
outputString.AddShaderChunk("return (1.0-t)*a + (t*b);", false); |
|||
|
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", false); |
|||
|
|||
outputString.AddShaderChunk("inline float unity_valueNoise (float2 uv)", false); |
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
|
|||
outputString.AddShaderChunk("float2 i = floor(uv);", false); |
|||
outputString.AddShaderChunk("float2 f = frac(uv);", false); |
|||
outputString.AddShaderChunk("f = f * f * (3.0 - 2.0 * f);", false); |
|||
|
|||
outputString.AddShaderChunk("uv = abs(frac(uv) - 0.5);", false); |
|||
outputString.AddShaderChunk("float2 c0 = i + float2(0.0, 0.0);", false); |
|||
outputString.AddShaderChunk("float2 c1 = i + float2(1.0, 0.0);", false); |
|||
outputString.AddShaderChunk("float2 c2 = i + float2(0.0, 1.0);", false); |
|||
outputString.AddShaderChunk("float2 c3 = i + float2(1.0, 1.0);", false); |
|||
outputString.AddShaderChunk("float r0 = unity_noise_randomValue(c0);", false); |
|||
outputString.AddShaderChunk("float r1 = unity_noise_randomValue(c1);", false); |
|||
outputString.AddShaderChunk("float r2 = unity_noise_randomValue(c2);", false); |
|||
outputString.AddShaderChunk("float r3 = unity_noise_randomValue(c3);", false); |
|||
|
|||
outputString.AddShaderChunk("float bottomOfGrid = unity_noise_interpolate(r0, r1, f.x);", false); |
|||
outputString.AddShaderChunk("float topOfGrid = unity_noise_interpolate(r2, r3, f.x);", false); |
|||
outputString.AddShaderChunk("float t = unity_noise_interpolate(bottomOfGrid, topOfGrid, f.y);", false); |
|||
outputString.AddShaderChunk("return t;", false); |
|||
|
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", false); |
|||
|
|||
|
|||
outputString.AddShaderChunk(GetFunctionPrototype("uv"), false); |
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
|
|||
outputString.AddShaderChunk("float t = 0.0;", false); |
|||
outputString.AddShaderChunk("for(int i = 0; i < 3; i++)", false); |
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
|
|||
outputString.AddShaderChunk("float freq = pow(2.0, float(i));", false); |
|||
outputString.AddShaderChunk("float amp = pow(0.5, float(3-i));", false); |
|||
outputString.AddShaderChunk("t += unity_valueNoise(float2(uv.x/freq, uv.y/freq))*amp;", false); |
|||
|
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", false); |
|||
outputString.AddShaderChunk("return t;", false); |
|||
|
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", false); |
|||
|
|||
visitor.AddShaderChunk(outputString.GetShaderString(0), true); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 6e05bd4324babff4498e856ab63b993c |
|||
timeCreated: 1495526233 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using UnityEngine.MaterialGraph; |
|||
using RMGUI.GraphView; |
|||
using UnityEditor.Graphing.Drawing; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.MaterialGraph.Drawing |
|||
{ |
|||
[Serializable] |
|||
class AddManyContolPresenter : GraphControlPresenter |
|||
{ |
|||
|
|||
public override void OnGUIHandler() |
|||
{ |
|||
base.OnGUIHandler(); |
|||
|
|||
var addNode = node as UnityEngine.MaterialGraph.AddManyNode; |
|||
if (addNode == null) |
|||
return; |
|||
|
|||
if (GUILayout.Button("Add Input")) |
|||
{ |
|||
addNode.AddInputSlot(); |
|||
addNode.OnModified(); |
|||
} |
|||
if (GUILayout.Button("Remove Input")) |
|||
{ |
|||
addNode.RemoveInputSlot(); |
|||
addNode.OnModified(); |
|||
} |
|||
} |
|||
|
|||
public override float GetHeight() |
|||
{ |
|||
return EditorGUIUtility.singleLineHeight * 2 + 3 * EditorGUIUtility.standardVerticalSpacing; |
|||
} |
|||
} |
|||
|
|||
[Serializable] |
|||
public class AddManyNodePresenter : MaterialNodePresenter |
|||
{ |
|||
protected override IEnumerable<GraphElementPresenter> GetControlData() |
|||
{ |
|||
var instance = CreateInstance<AddManyContolPresenter>(); |
|||
instance.Initialize(node); |
|||
return new List<GraphElementPresenter> { instance }; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 0d89e5c0d48973c4ab16793131164a16 |
|||
timeCreated: 1495530357 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine.Graphing; |
|||
using System.Linq; |
|||
using System.Collections; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Title("Math/Advanced/Adder")] |
|||
public class AddManyNode : FunctionNInNOut, IGeneratesFunction |
|||
{ |
|||
int m_nodeInputCount = 2; |
|||
|
|||
public void AddInputSlot() |
|||
{ |
|||
string inputName = "Input" + GetInputSlots<ISlot>().Count().ToString(); |
|||
AddSlot(inputName, inputName, Graphing.SlotType.Input, SlotValueType.Dynamic); |
|||
} |
|||
|
|||
public AddManyNode() |
|||
{ |
|||
name = "Adder"; |
|||
for(int i = 0; i < m_nodeInputCount; ++i) |
|||
{ |
|||
AddInputSlot(); |
|||
} |
|||
|
|||
AddSlot("Sum", "finalSum", Graphing.SlotType.Output, SlotValueType.Dynamic); |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
public void OnModified() |
|||
{ |
|||
if (onModified != null) |
|||
onModified(this, ModificationScope.Node); |
|||
} |
|||
|
|||
protected override string GetFunctionName() |
|||
{ |
|||
return "unity_Adder"; |
|||
} |
|||
|
|||
string GetSumOfAllInputs() |
|||
{ |
|||
string sumString = ""; |
|||
int inputsLeft = GetInputSlots<ISlot>().Count(); |
|||
|
|||
foreach (ISlot slot in GetInputSlots<ISlot>()) |
|||
{ |
|||
sumString += GetShaderOutputName(slot.id); |
|||
if (inputsLeft > 1) |
|||
sumString += " + "; |
|||
--inputsLeft; |
|||
} |
|||
|
|||
return sumString; |
|||
} |
|||
|
|||
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
var outputString = new ShaderGenerator(); |
|||
outputString.AddShaderChunk(GetFunctionPrototype(), false); |
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
outputString.AddShaderChunk("finalSum = " + GetSumOfAllInputs() + ";", false); |
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", false); |
|||
|
|||
visitor.AddShaderChunk(outputString.GetShaderString(0), true); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 0518e86ee51c0b844a8721050900863a |
|||
timeCreated: 1495486161 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine.Graphing; |
|||
using System.Linq; |
|||
using System.Collections; |
|||
using System; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
public abstract class FunctionNInNOut : AbstractMaterialNode, IGeneratesBodyCode |
|||
{ |
|||
|
|||
public FunctionNInNOut() |
|||
{ |
|||
name = "FunctionNInNOut"; |
|||
} |
|||
|
|||
public override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
base.UpdateNodeAfterDeserialization(); |
|||
foreach (var slot in GetSlots<MaterialSlot>()) |
|||
{ |
|||
slot.showValue = true; |
|||
} |
|||
} |
|||
|
|||
public int AddSlot(string displayName, string nameInShader, SlotType slotType, SlotValueType valueType) |
|||
{ |
|||
int nextSlotId; |
|||
if (slotType == SlotType.Output) |
|||
nextSlotId = -( GetOutputSlots<MaterialSlot>().Count() + 1 ); |
|||
else |
|||
nextSlotId = GetInputSlots<MaterialSlot>().Count() + 1; |
|||
|
|||
AddSlot(new MaterialSlot(nextSlotId, displayName, nameInShader, slotType, valueType, Vector4.zero, true)); |
|||
return nextSlotId; |
|||
} |
|||
|
|||
public void RemoveOutputSlot() |
|||
{ |
|||
var lastSlotId = -GetOutputSlots<ISlot>().Count(); |
|||
RemoveSlotById(lastSlotId); |
|||
} |
|||
|
|||
public void RemoveInputSlot() |
|||
{ |
|||
var lastSlotId = GetInputSlots<ISlot>().Count(); |
|||
RemoveSlotById(lastSlotId); |
|||
} |
|||
|
|||
private void RemoveSlotById(int slotID) |
|||
{ |
|||
if (slotID == 0) |
|||
return; |
|||
RemoveSlot(slotID); |
|||
} |
|||
|
|||
public string GetSlotTypeName(int slotId) |
|||
{ |
|||
return ConvertConcreteSlotValueTypeToString(FindSlot<MaterialSlot>(slotId).concreteValueType); |
|||
} |
|||
|
|||
protected string GetShaderOutputName(int slotId) |
|||
{ |
|||
return FindSlot<MaterialSlot>(slotId).shaderOutputName; |
|||
} |
|||
|
|||
// Must override this
|
|||
protected abstract string GetFunctionName(); |
|||
|
|||
private string GetFunctionParameters() |
|||
{ |
|||
string param = ""; |
|||
int remainingParams = GetSlots<ISlot>().Count(); |
|||
foreach (ISlot inSlot in GetSlots<ISlot>()) |
|||
{ |
|||
if (inSlot.isOutputSlot) |
|||
param += "out "; |
|||
|
|||
param += precision + GetSlotTypeName(inSlot.id) + " "; |
|||
param += GetShaderOutputName(inSlot.id); |
|||
|
|||
if (remainingParams > 1) |
|||
param += ", "; |
|||
--remainingParams; |
|||
} |
|||
|
|||
return param; |
|||
} |
|||
|
|||
private string GetFunctionCallParameters(GenerationMode generationMode) |
|||
{ |
|||
string param = ""; |
|||
int remainingParams = GetSlots<ISlot>().Count(); |
|||
foreach (ISlot inSlot in GetSlots<ISlot>()) |
|||
{ |
|||
param += GetSlotValue(inSlot.id, generationMode); |
|||
|
|||
if (remainingParams > 1) |
|||
param += ", "; |
|||
--remainingParams; |
|||
} |
|||
|
|||
return param; |
|||
} |
|||
|
|||
protected string GetFunctionPrototype() |
|||
{ |
|||
return "inline " + "void" + " " + GetFunctionName() + |
|||
" (" + |
|||
GetFunctionParameters() + |
|||
")"; |
|||
} |
|||
|
|||
private string GetFunctionCall(GenerationMode generationMode) |
|||
{ |
|||
return GetFunctionName() + |
|||
" (" + |
|||
GetFunctionCallParameters(generationMode) + |
|||
");"; |
|||
} |
|||
|
|||
private string GetOutputDeclaration() |
|||
{ |
|||
string outDeclaration = ""; |
|||
foreach (ISlot outSlot in GetOutputSlots<ISlot>()) |
|||
{ |
|||
outDeclaration += "\n " + precision + GetSlotTypeName(outSlot.id) + " " + GetVariableNameForSlot(outSlot.id) + ";\n"; |
|||
} |
|||
|
|||
return outDeclaration; |
|||
} |
|||
|
|||
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
var outputString = new ShaderGenerator(); |
|||
outputString.AddShaderChunk(GetOutputDeclaration(), false); |
|||
outputString.AddShaderChunk(GetFunctionCall(generationMode), false); |
|||
|
|||
visitor.AddShaderChunk(outputString.GetShaderString(0), true); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: ef27c8075e4d9594eb52411936ff46cc |
|||
timeCreated: 1495483390 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
1
MaterialGraphProject/Assets/TestGraph.ShaderGraph
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: 037778188549d9b4e8102cd29dea21a9 |
|||
timeCreated: 1495526245 |
|||
licenseType: Pro |
|||
ScriptedImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|||
script: {fileID: 11500000, guid: 625f186215c104763be7675aa2d941aa, type: 3} |
|
|||
fileFormatVersion: 2 |
|||
guid: 8ee6f8ab31f6bf349a63fdd21fc88664 |
|||
folderAsset: yes |
|||
timeCreated: 1495532491 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 9e3d3d0ce68bbc843b9b8734ab8d4f02 |
|||
folderAsset: yes |
|||
timeCreated: 1495531110 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 0ab9e53346965db4a8ee81a2b978dca5 |
|||
folderAsset: yes |
|||
timeCreated: 1495526789 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: eb0cb153896a18c4ebb6d116283dfda4 |
|||
folderAsset: yes |
|||
timeCreated: 1495532221 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: e63f07e66d070412bb6e9582ca1eba72 |
|||
folderAsset: yes |
|||
timeCreated: 1495526358 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 8443203ba8104ff4bb0a6a0ed978034e |
|||
folderAsset: yes |
|||
timeCreated: 1495532369 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: e74e11761cab2b446b96ce63e2d657b3 |
|||
folderAsset: yes |
|||
timeCreated: 1495530729 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: f9c248f478f706147ba7b8a660035472 |
|||
folderAsset: yes |
|||
timeCreated: 1495529881 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 75cc6d701e07fe246ba5377a454f74c4 |
|||
folderAsset: yes |
|||
timeCreated: 1495532497 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 9134a2b351ed9f140bfbb2d46f9075b5 |
|||
folderAsset: yes |
|||
timeCreated: 1495532965 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Title("Channel/Combine")] |
|||
public class CombineNode : PropertyNode, IGeneratesBodyCode |
|||
{ |
|||
protected const string kOutputSlot0Id = "Input0"; |
|||
protected const string kOutputSlot1Id = "Input1"; |
|||
protected const string kOutputSlot2Id = "Input2"; |
|||
protected const string kOutputSlot3Id = "Input3"; |
|||
|
|||
protected const string kOutputSlotRGBAName = "RGBA"; |
|||
protected const string kOutputSlotRGBSlotName = "RGB"; |
|||
protected const string kOutputSlotRGSlotName = "RG"; |
|||
|
|||
public const int InputSlot0Id = 0; |
|||
public const int InputSlot1Id = 1; |
|||
public const int InputSlot2Id = 2; |
|||
public const int InputSlot3Id = 3; |
|||
|
|||
public const int OutputSlotRGBAId = 4; |
|||
public const int OutputSlotRGBId = 5; |
|||
public const int OutputSlotRGId = 6; |
|||
|
|||
public CombineNode() |
|||
{ |
|||
name = "Combine"; |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
public sealed override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
AddSlot(new MaterialSlot(InputSlot0Id, kOutputSlot0Id, kOutputSlot0Id, SlotType.Input, SlotValueType.Dynamic, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(InputSlot1Id, kOutputSlot1Id, kOutputSlot1Id, SlotType.Input, SlotValueType.Dynamic, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(InputSlot2Id, kOutputSlot2Id, kOutputSlot2Id, SlotType.Input, SlotValueType.Dynamic, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(InputSlot3Id, kOutputSlot3Id, kOutputSlot3Id, SlotType.Input, SlotValueType.Dynamic, Vector4.zero)); |
|||
|
|||
AddSlot(new MaterialSlot(OutputSlotRGBAId, kOutputSlotRGBAName, kOutputSlotRGBAName, SlotType.Output, SlotValueType.Vector4, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(OutputSlotRGBId, kOutputSlotRGBSlotName, kOutputSlotRGBSlotName, SlotType.Output, SlotValueType.Vector3, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(OutputSlotRGId, kOutputSlotRGSlotName, kOutputSlotRGSlotName, SlotType.Output, SlotValueType.Vector2, Vector4.zero)); |
|||
RemoveSlotsNameNotMatching(validSlots); |
|||
} |
|||
|
|||
protected int[] validSlots |
|||
{ |
|||
get { return new[] { InputSlot0Id, InputSlot1Id, InputSlot2Id, InputSlot3Id, OutputSlotRGBAId, OutputSlotRGBId, OutputSlotRGId }; } |
|||
} |
|||
|
|||
[SerializeField] |
|||
private Vector4 m_Value; |
|||
|
|||
public Vector4 value |
|||
{ |
|||
get { return m_Value; } |
|||
set |
|||
{ |
|||
if (m_Value == value) |
|||
return; |
|||
|
|||
m_Value = value; |
|||
|
|||
if (onModified != null) |
|||
onModified(this, ModificationScope.Node); |
|||
} |
|||
} |
|||
|
|||
public override PropertyType propertyType { get { return PropertyType.Vector4; } } |
|||
|
|||
public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
if (exposedState == ExposedState.Exposed) |
|||
visitor.AddShaderProperty(new VectorPropertyChunk(propertyName, description, m_Value, PropertyChunk.HideState.Visible)); |
|||
} |
|||
|
|||
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
if (exposedState == ExposedState.Exposed || generationMode.IsPreview()) |
|||
visitor.AddShaderChunk(precision + "4 " + propertyName + ";", true); |
|||
} |
|||
|
|||
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
//if (exposedState == ExposedState.Exposed || generationMode.IsPreview())
|
|||
// return;
|
|||
var inputValue = GetSlotValue(InputSlot0Id, generationMode); |
|||
visitor.AddShaderChunk(precision + "4 " + propertyName + " = " + inputValue + ";", false); |
|||
//visitor.AddShaderChunk(precision + "4 " + propertyName + " = " + precision + "4 (" + m_Value.x + ", " + m_Value.y + ", " + m_Value.z + ", " + m_Value.w + ");", true);
|
|||
} |
|||
|
|||
protected virtual MaterialSlot GetInputSlot() |
|||
{ |
|||
return new MaterialSlot(InputSlot0Id, GetInputSlotName(), kOutputSlot0Id, SlotType.Input, SlotValueType.Dynamic, Vector4.zero); |
|||
} |
|||
|
|||
protected virtual string GetInputSlotName() { return "Input"; } |
|||
|
|||
public override PreviewProperty GetPreviewProperty() |
|||
{ |
|||
return new PreviewProperty |
|||
{ |
|||
m_Name = propertyName, |
|||
m_PropType = PropertyType.Vector4, |
|||
m_Vector4 = m_Value |
|||
}; |
|||
} |
|||
|
|||
/*public override string GetVariableNameForSlot(int slotId) |
|||
{ |
|||
string slotOutput; |
|||
switch (slotId) |
|||
{ |
|||
case OutputSlotRId: |
|||
slotOutput = ".r"; |
|||
break; |
|||
case OutputSlotGId: |
|||
slotOutput = ".g"; |
|||
break; |
|||
case OutputSlotBId: |
|||
slotOutput = ".b"; |
|||
break; |
|||
case OutputSlotAId: |
|||
slotOutput = ".a"; |
|||
break; |
|||
default: |
|||
slotOutput = ""; |
|||
break; |
|||
} |
|||
return propertyName + slotOutput; |
|||
//return GetVariableNameForNode() + slotOutput;
|
|||
}*/ |
|||
|
|||
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties) |
|||
{ |
|||
properties.Add(GetPreviewProperty()); |
|||
} |
|||
} |
|||
} |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
#if UNITY_EDITOR
|
|||
using UnityEditor; |
|||
#endif
|
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Title("Channel/Split")] |
|||
public class SplitNode : PropertyNode, IGeneratesBodyCode |
|||
{ |
|||
protected const string kInputSlotName = "Input"; |
|||
protected const string kOutputSlotRName = "R"; |
|||
protected const string kOutputSlotGName = "G"; |
|||
protected const string kOutputSlotBName = "B"; |
|||
protected const string kOutputSlotAName = "A"; |
|||
protected const string kOutputSlotRGBName = "RGB"; |
|||
protected const string kOutputSlotRGName = "RG"; |
|||
|
|||
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 const int OutputSlotRGBId = 5; |
|||
public const int OutputSlotRGId = 6; |
|||
|
|||
public SplitNode() |
|||
{ |
|||
name = "Split"; |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
public sealed override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
AddSlot(new MaterialSlot(InputSlotId, kInputSlotName, kInputSlotName, SlotType.Input, SlotValueType.Dynamic, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(OutputSlotRId, kOutputSlotRName, kOutputSlotRName, SlotType.Output, SlotValueType.Vector1, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(OutputSlotGId, kOutputSlotGName, kOutputSlotGName, SlotType.Output, SlotValueType.Vector1, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(OutputSlotBId, kOutputSlotBName, kOutputSlotBName, SlotType.Output, SlotValueType.Vector1, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(OutputSlotAId, kOutputSlotAName, kOutputSlotAName, SlotType.Output, SlotValueType.Vector1, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(OutputSlotRGBId, kOutputSlotRGBName, kOutputSlotRGBName, SlotType.Output, SlotValueType.Vector3, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(OutputSlotRGId, kOutputSlotRGName, kOutputSlotRGName, SlotType.Output, SlotValueType.Vector2, Vector4.zero)); |
|||
RemoveSlotsNameNotMatching(validSlots); |
|||
} |
|||
|
|||
protected int[] validSlots |
|||
{ |
|||
get { return new[] { InputSlotId, OutputSlotRId, OutputSlotGId, OutputSlotBId, OutputSlotAId, OutputSlotRGBId, OutputSlotRGId }; } |
|||
} |
|||
|
|||
[SerializeField] |
|||
private Vector4 m_Value; |
|||
|
|||
public Vector4 value |
|||
{ |
|||
get { return m_Value; } |
|||
set |
|||
{ |
|||
if (m_Value == value) |
|||
return; |
|||
|
|||
m_Value = value; |
|||
|
|||
if (onModified != null) |
|||
onModified(this, ModificationScope.Node); |
|||
} |
|||
} |
|||
|
|||
public override PropertyType propertyType { get { return PropertyType.Vector4; } } |
|||
|
|||
public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
if (exposedState == ExposedState.Exposed) |
|||
visitor.AddShaderProperty(new VectorPropertyChunk(propertyName, description, m_Value, PropertyChunk.HideState.Visible)); |
|||
} |
|||
|
|||
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
if (exposedState == ExposedState.Exposed || generationMode.IsPreview()) |
|||
visitor.AddShaderChunk(precision + "4 " + propertyName + ";", true); |
|||
} |
|||
|
|||
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
//if (exposedState == ExposedState.Exposed || generationMode.IsPreview())
|
|||
// return;
|
|||
var inputValue = GetSlotValue(InputSlotId, generationMode); |
|||
visitor.AddShaderChunk(precision + "4 " + propertyName + " = " + inputValue + ";", false); |
|||
//visitor.AddShaderChunk(precision + "4 " + propertyName + " = " + precision + "4 (" + m_Value.x + ", " + m_Value.y + ", " + m_Value.z + ", " + m_Value.w + ");", true);
|
|||
} |
|||
|
|||
protected virtual MaterialSlot GetInputSlot() |
|||
{ |
|||
return new MaterialSlot(InputSlotId, GetInputSlotName(), kInputSlotName, SlotType.Input, SlotValueType.Dynamic, Vector4.zero); |
|||
} |
|||
|
|||
protected virtual string GetInputSlotName() { return "Input"; } |
|||
|
|||
public override PreviewProperty GetPreviewProperty() |
|||
{ |
|||
return new PreviewProperty |
|||
{ |
|||
m_Name = propertyName, |
|||
m_PropType = PropertyType.Vector4, |
|||
m_Vector4 = m_Value |
|||
}; |
|||
} |
|||
|
|||
public override string GetVariableNameForSlot(int slotId) |
|||
{ |
|||
string slotOutput; |
|||
switch (slotId) |
|||
{ |
|||
case OutputSlotRId: |
|||
slotOutput = ".r"; |
|||
break; |
|||
case OutputSlotGId: |
|||
slotOutput = ".g"; |
|||
break; |
|||
case OutputSlotBId: |
|||
slotOutput = ".b"; |
|||
break; |
|||
case OutputSlotAId: |
|||
slotOutput = ".a"; |
|||
break; |
|||
case OutputSlotRGBId: |
|||
slotOutput = ".rgb"; |
|||
break; |
|||
case OutputSlotRGId: |
|||
slotOutput = ".rg"; |
|||
break; |
|||
default: |
|||
slotOutput = ""; |
|||
break; |
|||
} |
|||
return propertyName + slotOutput; |
|||
//return GetVariableNameForNode() + slotOutput;
|
|||
} |
|||
|
|||
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties) |
|||
{ |
|||
properties.Add(GetPreviewProperty()); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 5e9138df313dc9e4fa20f92625c26b59 |
|||
folderAsset: yes |
|||
timeCreated: 1495527166 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: ad6f48f5ba4c9a24ab7b9df345b45d6f |
|||
folderAsset: yes |
|||
timeCreated: 1495527773 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 07cc6493671f2344089936cf4a0ab49b |
|||
folderAsset: yes |
|||
timeCreated: 1495528572 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 5d0ea40228d32a44c94e79db32eb2060 |
|||
folderAsset: yes |
|||
timeCreated: 1495529303 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 1ccfba538a5b85b43a9d78f3057e00f2 |
|||
folderAsset: yes |
|||
timeCreated: 1495526799 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 198ec765a01574320a8199338d27d9f1 |
|||
folderAsset: yes |
|||
timeCreated: 1495526831 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
部分文件因为文件数量过多而无法显示
撰写
预览
正在加载...
取消
保存
Reference in new issue