浏览代码
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 年前
当前提交
ea69972e
共有 10 个文件被更改,包括 405 次插入 和 10 次删除
-
4MaterialGraphProject/Assets/Eduardo/FunctionNAddNode.cs
-
4MaterialGraphProject/Assets/Eduardo/FunctionNInNOut.cs
-
10MaterialGraphProject/Assets/Rinaldo/FractalNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Procedural/CheckerboardNode.cs
-
48MaterialGraphProject/Assets/UnityShaderEditor/Editor/Templates/ExportTexture.template
-
4MaterialGraphProject/Assets/UnityShaderEditor/Editor/Templates/ExportTexture.template.meta
-
77MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/UV/SpherizeNode.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/UV/SpherizeNode.cs.meta
-
242MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SurfaceModel/ExportTextureMasterNode.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SurfaceModel/ExportTextureMasterNode.cs.meta
|
|||
Shader "${ShaderName}" |
|||
{ |
|||
Properties |
|||
{ |
|||
${ShaderPropertiesHeader} |
|||
} |
|||
|
|||
SubShader |
|||
{ |
|||
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } |
|||
|
|||
ZWrite Off |
|||
Blend SrcAlpha OneMinusSrcAlpha |
|||
|
|||
Pass |
|||
{ |
|||
CGPROGRAM |
|||
#pragma vertex vert |
|||
#pragma fragment frag |
|||
#include "UnityCG.cginc" |
|||
|
|||
struct v2f |
|||
{ |
|||
float4 pos : SV_POSITION; |
|||
float2 uv : TEXCOORD0; |
|||
}; |
|||
|
|||
sampler2D ${ShaderTextureName}; |
|||
float4 ${ShaderTextureName}_ST; |
|||
|
|||
v2f vert (appdata_full v) |
|||
{ |
|||
v2f o = (v2f)0; |
|||
o.pos = UnityObjectToClipPos(v.vertex); |
|||
o.uv = TRANSFORM_TEX(v.texcoord, ${ShaderTextureName}); |
|||
return o; |
|||
} |
|||
|
|||
half4 frag (v2f IN) : COLOR |
|||
{ |
|||
half4 col = tex2D(${ShaderTextureName}, IN.uv); |
|||
return col; |
|||
} |
|||
ENDCG |
|||
} |
|||
} |
|||
Fallback Off |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: db810b4437bc78b4f94f31af1d276775 |
|||
DefaultImporter: |
|||
userData: |
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Title("UV/Spherize")] |
|||
public class SpherizeNode : Function3Input, IGeneratesFunction |
|||
{ |
|||
public SpherizeNode() |
|||
{ |
|||
name = "Spherize"; |
|||
} |
|||
|
|||
protected override string GetFunctionName() |
|||
{ |
|||
return "unity_spherize_" + precision; |
|||
} |
|||
|
|||
protected override string GetInputSlot1Name() |
|||
{ |
|||
return "UV"; |
|||
} |
|||
|
|||
protected override MaterialSlot GetInputSlot1() |
|||
{ |
|||
return new MaterialSlot(InputSlot1Id, GetInputSlot1Name(), kInputSlot1ShaderName, UnityEngine.Graphing.SlotType.Input, SlotValueType.Vector2, Vector2.zero); |
|||
} |
|||
|
|||
protected override string GetInputSlot2Name() |
|||
{ |
|||
return "Position"; |
|||
} |
|||
|
|||
protected override MaterialSlot GetInputSlot2() |
|||
{ |
|||
return new MaterialSlot(InputSlot2Id, GetInputSlot2Name(), kInputSlot2ShaderName, UnityEngine.Graphing.SlotType.Input, SlotValueType.Vector2, Vector2.zero); |
|||
} |
|||
|
|||
protected override string GetInputSlot3Name() |
|||
{ |
|||
return "RadiusAndStrength"; |
|||
} |
|||
|
|||
protected override MaterialSlot GetInputSlot3() |
|||
{ |
|||
return new MaterialSlot(InputSlot3Id, GetInputSlot3Name(), kInputSlot3ShaderName, UnityEngine.Graphing.SlotType.Input, SlotValueType.Vector2, Vector3.zero); |
|||
} |
|||
|
|||
protected override MaterialSlot GetOutputSlot() |
|||
{ |
|||
return new MaterialSlot(OutputSlotId, GetOutputSlotName(), kOutputSlotShaderName, UnityEngine.Graphing.SlotType.Output, SlotValueType.Vector2, Vector2.zero); |
|||
} |
|||
|
|||
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
var outputString = new ShaderGenerator(); |
|||
outputString.AddShaderChunk(GetFunctionPrototype("uv", "position", "radiusAndStrength"), false); |
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
|
|||
//vec2 fromUVToPoint = pos - uv;
|
|||
//dist = length(fromUVToPoint);
|
|||
|
|||
//float mag = (1.0 - (dist / radius)) * strength;
|
|||
//mag *= step(dist, radius);
|
|||
|
|||
//return uv + (mag * fromUVToPoint);
|
|||
|
|||
outputString.AddShaderChunk("float2 fromUVToPoint = position - uv;", false); |
|||
outputString.AddShaderChunk("float dist = length(fromUVToPoint);", false); |
|||
outputString.AddShaderChunk("float mag = ((1.0 - (dist / radiusAndStrength.x)) * radiusAndStrength.y) * step(dist, radiusAndStrength.x);", false); |
|||
outputString.AddShaderChunk("return uv + (mag * fromUVToPoint);", false); |
|||
|
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", false); |
|||
|
|||
visitor.AddShaderChunk(outputString.GetShaderString(0), true); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 249d9b9165bdf234e84a85cdb8aca2aa |
|||
timeCreated: 1495555169 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
using System.Linq; |
|||
using System.Text.RegularExpressions; |
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Serializable] |
|||
[Title("Master/Export Texture")] |
|||
public class ExportTextureMasterNode : AbstractMasterNode |
|||
{ |
|||
public const string ColorSlotName = "Color"; |
|||
public const int ColorSlotId = 0; |
|||
|
|||
[SerializeField] |
|||
private SurfaceMaterialOptions m_MaterialOptions = new SurfaceMaterialOptions(); |
|||
|
|||
public SurfaceMaterialOptions options |
|||
{ |
|||
get { return m_MaterialOptions; } |
|||
} |
|||
|
|||
public ExportTextureMasterNode() |
|||
{ |
|||
name = "ExportTextureMasterNode"; |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
public sealed override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
AddSlot(new MaterialSlot(ColorSlotId, ColorSlotName, ColorSlotName, SlotType.Input, SlotValueType.Vector4, Vector4.zero)); |
|||
|
|||
// clear out slot names that do not match the slots we support
|
|||
RemoveSlotsNameNotMatching(new[] { ColorSlotId }); |
|||
} |
|||
|
|||
public override PreviewMode previewMode |
|||
{ |
|||
get |
|||
{ |
|||
return PreviewMode.Preview2D; |
|||
} |
|||
} |
|||
|
|||
public override string GetSubShader(GenerationMode mode, PropertyGenerator shaderPropertiesVisitor) |
|||
{ |
|||
return ""; |
|||
} |
|||
|
|||
public override bool has3DPreview() |
|||
{ |
|||
return false; |
|||
} |
|||
|
|||
public override string GetFullShader(GenerationMode mode, out List<PropertyGenerator.TextureInfo> configuredTextures) |
|||
{ |
|||
/* |
|||
// figure out what kind of preview we want!
|
|||
var activeNodeList = ListPool<INode>.Get(); |
|||
NodeUtils.DepthFirstCollectNodesFromNode(activeNodeList, this); |
|||
|
|||
string templateLocation = ShaderGenerator.GetTemplatePath("2DPreview.template"); |
|||
if (!File.Exists(templateLocation)) |
|||
{ |
|||
configuredTextures = new List<PropertyGenerator.TextureInfo>(); |
|||
return string.Empty; |
|||
} |
|||
|
|||
string template = File.ReadAllText(templateLocation); |
|||
|
|||
var shaderBodyVisitor = new ShaderGenerator(); |
|||
var shaderFunctionVisitor = new ShaderGenerator(); |
|||
var shaderPropertiesVisitor = new PropertyGenerator(); |
|||
var shaderPropertyUsagesVisitor = new ShaderGenerator(); |
|||
|
|||
|
|||
var shaderName = "Hidden/PreviewShader/" + GetType() + guid.ToString(); |
|||
//var shaderName = "Hidden/PreviewShader/" + this.GetVariableNameForSlot(this.GetOutputSlots<MaterialSlot>().First().id);
|
|||
|
|||
|
|||
var shaderInputVisitor = new ShaderGenerator(); |
|||
var vertexShaderBlock = new ShaderGenerator(); |
|||
|
|||
// always add color because why not.
|
|||
shaderInputVisitor.AddShaderChunk("float4 color : COLOR;", true); |
|||
|
|||
vertexShaderBlock.AddShaderChunk("float3 worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;", true); |
|||
vertexShaderBlock.AddShaderChunk("float3 viewDir = UnityWorldSpaceViewDir(worldPos);", true); |
|||
vertexShaderBlock.AddShaderChunk("float4 screenPos = ComputeScreenPos(UnityObjectToClipPos(v.vertex));", true); |
|||
vertexShaderBlock.AddShaderChunk("float3 worldNormal = UnityObjectToWorldNormal(v.normal);", true); |
|||
|
|||
bool needBitangent = activeNodeList.OfType<IMayRequireBitangent>().Any(x => x.RequiresBitangent()); |
|||
bool needsWorldPos = activeNodeList.OfType<IMayRequireViewDirection>().Any(x => x.RequiresViewDirection()); |
|||
if (needsWorldPos || activeNodeList.OfType<IMayRequireWorldPosition>().Any(x => x.RequiresWorldPosition())) |
|||
{ |
|||
shaderInputVisitor.AddShaderChunk("float3 worldPos : TEXCOORD0;", true); |
|||
vertexShaderBlock.AddShaderChunk("o.worldPos = worldPos;", true); |
|||
shaderBodyVisitor.AddShaderChunk("float3 " + ShaderGeneratorNames.WorldSpacePosition + " = IN.worldPos;", true); |
|||
} |
|||
|
|||
if (needBitangent || activeNodeList.OfType<IMayRequireNormal>().Any(x => x.RequiresNormal())) |
|||
{ |
|||
shaderInputVisitor.AddShaderChunk("float3 worldNormal : TEXCOORD1;", true); |
|||
vertexShaderBlock.AddShaderChunk("o.worldNormal = worldNormal;", true); |
|||
shaderBodyVisitor.AddShaderChunk("float3 " + ShaderGeneratorNames.WorldSpaceNormal + " = normalize(IN.worldNormal);", true); |
|||
} |
|||
|
|||
for (int uvIndex = 0; uvIndex < ShaderGeneratorNames.UVCount; ++uvIndex) |
|||
{ |
|||
var channel = (UVChannel)uvIndex; |
|||
if (activeNodeList.OfType<IMayRequireMeshUV>().Any(x => x.RequiresMeshUV(channel))) |
|||
{ |
|||
shaderInputVisitor.AddShaderChunk(string.Format("half4 meshUV{0} : TEXCOORD{1};", uvIndex, (uvIndex + 5)), true); |
|||
vertexShaderBlock.AddShaderChunk(string.Format("o.meshUV{0} = v.texcoord{1};", uvIndex, uvIndex == 0 ? "" : uvIndex.ToString()), true); |
|||
shaderBodyVisitor.AddShaderChunk(string.Format("half4 {0} = IN.meshUV{1};", channel.GetUVName(), uvIndex), true); |
|||
} |
|||
} |
|||
|
|||
if (activeNodeList.OfType<IMayRequireViewDirection>().Any(x => x.RequiresViewDirection())) |
|||
{ |
|||
shaderBodyVisitor.AddShaderChunk( |
|||
"float3 " |
|||
+ ShaderGeneratorNames.WorldSpaceViewDirection |
|||
+ " = normalize(UnityWorldSpaceViewDir(" |
|||
+ ShaderGeneratorNames.WorldSpacePosition |
|||
+ "));", true); |
|||
} |
|||
|
|||
if (activeNodeList.OfType<IMayRequireScreenPosition>().Any(x => x.RequiresScreenPosition())) |
|||
{ |
|||
shaderInputVisitor.AddShaderChunk("float4 screenPos : TEXCOORD3;", true); |
|||
vertexShaderBlock.AddShaderChunk("o.screenPos = screenPos;", true); |
|||
shaderBodyVisitor.AddShaderChunk("half4 " + ShaderGeneratorNames.ScreenPosition + " = IN.screenPos;", true); |
|||
} |
|||
|
|||
if (needBitangent || activeNodeList.OfType<IMayRequireTangent>().Any(x => x.RequiresTangent())) |
|||
{ |
|||
shaderInputVisitor.AddShaderChunk("float4 worldTangent : TEXCOORD4;", true); |
|||
vertexShaderBlock.AddShaderChunk("o.worldTangent = float4(UnityObjectToWorldDir(v.tangent.xyz), v.tangent.w);", true); |
|||
shaderBodyVisitor.AddShaderChunk("float3 " + ShaderGeneratorNames.WorldSpaceTangent + " = normalize(IN.worldTangent.xyz);", true); |
|||
} |
|||
|
|||
if (needBitangent) |
|||
{ |
|||
shaderBodyVisitor.AddShaderChunk(string.Format("float3 {0} = cross({1}, {2}) * IN.worldTangent.w;", ShaderGeneratorNames.WorldSpaceBitangent, ShaderGeneratorNames.WorldSpaceNormal, ShaderGeneratorNames.WorldSpaceTangent), true); |
|||
} |
|||
|
|||
if (activeNodeList.OfType<IMayRequireVertexColor>().Any(x => x.RequiresVertexColor())) |
|||
{ |
|||
vertexShaderBlock.AddShaderChunk("o.color = v.color;", true); |
|||
shaderBodyVisitor.AddShaderChunk("float4 " + ShaderGeneratorNames.VertexColor + " = IN.color;", true); |
|||
} |
|||
|
|||
var generationMode = GenerationMode.Preview; |
|||
foreach (var activeNode in activeNodeList.OfType<AbstractMaterialNode>()) |
|||
{ |
|||
if (activeNode is IGeneratesFunction) |
|||
(activeNode as IGeneratesFunction).GenerateNodeFunction(shaderFunctionVisitor, generationMode); |
|||
if (activeNode is IGeneratesBodyCode) |
|||
(activeNode as IGeneratesBodyCode).GenerateNodeCode(shaderBodyVisitor, generationMode); |
|||
|
|||
activeNode.GeneratePropertyBlock(shaderPropertiesVisitor, generationMode); |
|||
activeNode.GeneratePropertyUsages(shaderPropertyUsagesVisitor, generationMode); |
|||
} |
|||
|
|||
//shaderBodyVisitor.AddShaderChunk("return " + ShaderGenerator.AdaptNodeOutputForPreview(this, GetOutputSlots<MaterialSlot>().First().id) + ";", true);
|
|||
//shaderBodyVisitor.AddShaderChunk("return " + AdaptNodeInputForPreview(this, ColorSlotId) + ";", true);
|
|||
shaderBodyVisitor.AddShaderChunk("return " + GetVariableNameForSlot(GetSlotReference(ColorSlotId).slotId) + ";", true); |
|||
|
|||
|
|||
|
|||
ListPool<INode>.Release(activeNodeList); |
|||
|
|||
template = template.Replace("${ShaderName}", shaderName); |
|||
template = template.Replace("${ShaderPropertiesHeader}", shaderPropertiesVisitor.GetShaderString(2)); |
|||
template = template.Replace("${ShaderPropertyUsages}", shaderPropertyUsagesVisitor.GetShaderString(3)); |
|||
template = template.Replace("${ShaderInputs}", shaderInputVisitor.GetShaderString(4)); |
|||
template = template.Replace("${ShaderFunctions}", shaderFunctionVisitor.GetShaderString(3)); |
|||
template = template.Replace("${VertexShaderBody}", vertexShaderBlock.GetShaderString(4)); |
|||
template = template.Replace("${PixelShaderBody}", shaderBodyVisitor.GetShaderString(4)); |
|||
|
|||
string vertexShaderBody = vertexShaderBlock.GetShaderString(4); |
|||
if (vertexShaderBody.Length > 0) |
|||
{ |
|||
template = template.Replace("${VertexShaderDecl}", "vertex:vert"); |
|||
template = template.Replace("${VertexShaderBody}", vertexShaderBody); |
|||
} |
|||
else |
|||
{ |
|||
template = template.Replace("${VertexShaderDecl}", ""); |
|||
template = template.Replace("${VertexShaderBody}", vertexShaderBody); |
|||
} |
|||
|
|||
configuredTextures = shaderPropertiesVisitor.GetConfiguredTexutres(); |
|||
return Regex.Replace(template, @"\r\n|\n\r|\n|\r", Environment.NewLine); |
|||
*/ |
|||
//=============================================================================================
|
|||
|
|||
|
|||
string templateLocation = ShaderGenerator.GetTemplatePath("ExportTexture.template"); |
|||
|
|||
if (!File.Exists(templateLocation)) |
|||
{ |
|||
configuredTextures = new List<PropertyGenerator.TextureInfo>(); |
|||
return string.Empty; |
|||
} |
|||
|
|||
var shaderPropertiesVisitor = new PropertyGenerator(); |
|||
|
|||
// figure out what kind of preview we want!
|
|||
var activeNodeList = ListPool<INode>.Get(); |
|||
NodeUtils.DepthFirstCollectNodesFromNode(activeNodeList, this); |
|||
foreach (var node in activeNodeList.OfType<AbstractMaterialNode>()) |
|||
{ |
|||
//if (node is IGeneratesFunction)
|
|||
// (node as IGeneratesFunction).GenerateNodeFunction(nodeFunction, mode);
|
|||
node.GeneratePropertyBlock(shaderPropertiesVisitor, mode); |
|||
} |
|||
|
|||
string texName = "_ExportTexture"; |
|||
|
|||
if (shaderPropertiesVisitor.GetConfiguredTexutres().Count > 0) |
|||
texName = shaderPropertiesVisitor.GetConfiguredTexutres()[0].name; |
|||
|
|||
|
|||
string template = File.ReadAllText(templateLocation); |
|||
var shaderName = "Hidden/ExportTexture/" + this.GetVariableNameForSlot(this.GetInputSlots<MaterialSlot>().First().id); |
|||
template = template.Replace("${ShaderName}", shaderName); |
|||
template = template.Replace("${ShaderPropertiesHeader}", shaderPropertiesVisitor.GetShaderString(0)); |
|||
template = template.Replace("${ShaderTextureName}", texName); |
|||
|
|||
configuredTextures = shaderPropertiesVisitor.GetConfiguredTexutres(); |
|||
|
|||
ListPool<INode>.Release(activeNodeList); |
|||
|
|||
return Regex.Replace(template, @"\r\n|\n\r|\n|\r", Environment.NewLine); |
|||
|
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 318b40c0b58f791468e39e5c358b64be |
|||
timeCreated: 1495482393 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue