浏览代码

Texture asset is now a real asset type...

/main
Tim Cooper 8 年前
当前提交
d0d60781
共有 45 个文件被更改,包括 347 次插入585 次删除
  1. 2
      .gitmodules
  2. 4
      MaterialGraphProject/Assets/Eduardo/Editor/AddManyNodePresenter.cs
  3. 4
      MaterialGraphProject/Assets/Eduardo/FunctionNAddNode.cs
  4. 6
      MaterialGraphProject/Assets/Eduardo/FunctionNInNOut.cs
  5. 4
      MaterialGraphProject/Assets/NewNodes/WIP/AACheckerBoard3dNode.cs
  6. 4
      MaterialGraphProject/Assets/NewNodes/WIP/AACheckerBoardNode.cs
  7. 8
      MaterialGraphProject/Assets/NewNodes/WIP/AnyNode.cs
  8. 2
      MaterialGraphProject/Assets/NewNodes/WIP/POMNode.cs
  9. 64
      MaterialGraphProject/Assets/NewNodes/WIP/RadialShearNode.cs
  10. 62
      MaterialGraphProject/Assets/NewNodes/WIP/ScaleOffsetNode.cs
  11. 66
      MaterialGraphProject/Assets/NewNodes/WIP/SphereWarpNode.cs
  12. 104
      MaterialGraphProject/Assets/NewNodes/WIP/SphericalIndentationNode.cs
  13. 2
      MaterialGraphProject/Assets/TestGraph.ShaderGraph
  14. 9
      MaterialGraphProject/Assets/TestGraph.ShaderGraph.meta
  15. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/AnyNodePresenter.cs
  16. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/CustomCodeNodePresenter.cs
  17. 18
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs
  18. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/SamplerAssetPresenter.cs
  19. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/ScatterNodePresenter.cs
  20. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/TextureAssetPresenter.cs
  21. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/TextureNodePresenter.cs
  22. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/TextureSamplerPresenter.cs
  23. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/PropertyNodeTests.cs
  24. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/PropertyNodeTests.cs
  25. 34
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/AbstractMaterialNode.cs
  26. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Art/Filters/ConvolutionFilterNode.cs
  27. 11
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Channel/SplitNode.cs
  28. 5
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Channel/SwizzleNode.cs
  29. 7
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/HLSLNode.cs
  30. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Texture/SamplerAssetNode.cs
  31. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Texture/TextureNode.cs
  32. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Logic/CustomCodeNode.cs
  33. 9
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/MaterialSlot.cs
  34. 54
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/SlotValue.cs
  35. 24
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SurfaceModel/AbstractSurfaceMasterNode.cs
  36. 45
      MaterialGraphProject/Assets/Vlad/SamplerStateNode.cs
  37. 292
      MaterialGraphProject/Assets/Vlad/TextureSamplerNode.cs
  38. 17
      MaterialGraphProject/Assets/Vlad/UVTriPlanar.cs
  39. 13
      MaterialGraphProject/Assets/Vlad/Texture2DNode.cs
  40. 2
      MaterialGraphProject/Assets/Vlad/Texture2DNode.cs.meta
  41. 2
      MaterialGraphProject/Assets/_MingWai/GeneratedTextureDemo/0-UnityLogo-Texture.asset.meta
  42. 2
      MaterialGraphProject/Assets/_MingWai/Gradient.asset.meta
  43. 4
      MaterialGraphProject/Assets/_MingWai/ScatterNode.cs
  44. 0
      /MaterialGraphProject/Assets/Vlad/Texture2DNode.cs
  45. 0
      /MaterialGraphProject/Assets/Vlad/Texture2DNode.cs.meta

2
.gitmodules


[submodule "MaterialGraphProject/Assets/GraphView/Editor"]
path = MaterialGraphProject/Assets/GraphView/Editor
url = https://github.com/chikuba/GraphView.git
url=https://github.com/Unity-Technologies/graphview.git

4
MaterialGraphProject/Assets/Eduardo/Editor/AddManyNodePresenter.cs


namespace UnityEditor.MaterialGraph.Drawing
{
[Serializable]
/* [Serializable]
class AddManyContolPresenter : GraphControlPresenter
{

instance.Initialize(node);
return new List<GraphElementPresenter> { instance };
}
}
}*/
}

4
MaterialGraphProject/Assets/Eduardo/FunctionNAddNode.cs


namespace UnityEngine.MaterialGraph
{
[Title("Math/Advanced/Adder")]
/* [Title("Math/Advanced/Adder")]
public class AddManyNode : FunctionNInNOut, IGeneratesFunction
{
int m_nodeInputCount = 2;

visitor.AddShaderChunk(outputString.GetShaderString(0), true);
}
}
}*/
}

6
MaterialGraphProject/Assets/Eduardo/FunctionNInNOut.cs


namespace UnityEngine.MaterialGraph
{
public abstract class FunctionNInNOut : AbstractMaterialNode, IGeneratesBodyCode
/* public abstract class FunctionNInNOut : AbstractMaterialNode, IGeneratesBodyCode
{
public FunctionNInNOut()

var outputString = new ShaderGenerator();
outputString.AddShaderChunk(GetOutputDeclaration(), false);
outputString.AddShaderChunk(GetFunctionCall(generationMode), false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
}

return samplerName;
}
}
}*/
}

4
MaterialGraphProject/Assets/NewNodes/WIP/AACheckerBoard3dNode.cs


namespace UnityEngine.MaterialGraph
{
[Title("Procedural/AACheckerboard3d")]
/*[Title("Procedural/AACheckerboard3d")]
public class AACheckerboard3dNode : AnyNode<AACheckerboard3dNode.Definition>
{
public class Definition : IAnyNodeDefinition

}
}
}
}
}*/
}

4
MaterialGraphProject/Assets/NewNodes/WIP/AACheckerBoardNode.cs


namespace UnityEngine.MaterialGraph
{
[Title("Procedural/AACheckerboard")]
/* [Title("Procedural/AACheckerboard")]
public class AACheckerboardNode : AnyNode<AACheckerboardNode.Definition>
{
public class Definition : IAnyNodeDefinition

}
}
}
}
}*/
}

8
MaterialGraphProject/Assets/NewNodes/WIP/AnyNode.cs


namespace UnityEngine.MaterialGraph
{
public enum ShaderGlobal
/* public enum ShaderGlobal
{
UV0,
UV1,

// , IMayRequireViewDirection
// , IMayRequireWorldPosition
// , IMayRequireVertexColor
, IMayRequireViewDirectionTangentSpace
, IMayRequireViewDirectionTangentSpace
where DEFINITION : IAnyNodeDefinition, new()
{

foreach (AnyNodeProperty p in m_properties)
{
// only exposed properties go in the property usage (hlsl declaration)
if ((p.state == AnyNodePropertyState.Exposed) ||
if ((p.state == AnyNodePropertyState.Exposed) ||
(p.state == AnyNodePropertyState.Constant && generationMode.IsPreview())) // constant properties are exposed in preview mode for fast iteration update
{
string typeDecl = p.getTypeDecl(precision);

return false;
}
}
}*/
}

2
MaterialGraphProject/Assets/NewNodes/WIP/POMNode.cs


}
static string Unity_POM(
[Slot(1, Binding.None)] Sampler2D tex,
[Slot(1, Binding.None)] Texture2D tex,
[Slot(2, Binding.None)] Vector1 heightScale,
[Slot(3, Binding.MeshUV0)] Vector2 UVs,
[Slot(4, Binding.ViewDirectionTangentSpace)] Vector3 viewTangentSpace,

64
MaterialGraphProject/Assets/NewNodes/WIP/RadialShearNode.cs


using UnityEngine.Graphing;
using System.Reflection;
public class RadialShearNode : AnyNode<RadialShearNode.Definition>
public class RadialShearNode : CodeFunctionNode
public class Definition : IAnyNodeDefinition
protected override MethodInfo GetFunctionToConvert()
public string name { get { return "RadialShear"; } }
public AnyNodeProperty[] properties
{
get
{
return new AnyNodeProperty[]
{
// slotId is the 'immutable' value we used to connect things
new AnyNodeProperty { slotId= 0, name = "inUVs", description = "Input UV coords", propertyType = PropertyType.Vector2, value = Vector4.zero, state = AnyNodePropertyState.Slot },
new AnyNodeProperty { slotId= 1, name = "center", description = "UV radial center point", propertyType = PropertyType.Vector2, value= new Vector4(0.5f, 0.5f, 0.5f, 0.5f), state = AnyNodePropertyState.Constant },
new AnyNodeProperty { slotId= 2, name = "shearAmount", description = "Shear amount", propertyType = PropertyType.Vector2, value= Vector4.one, state = AnyNodePropertyState.Constant },
new AnyNodeProperty { slotId= 3, name = "offset", description = "UV offset", propertyType = PropertyType.Vector2, value= Vector4.zero, state = AnyNodePropertyState.Constant },
};
}
}
public AnyNodeSlot[] outputs
{
get
{
return new AnyNodeSlot[]
{
new AnyNodeSlot { slotId= 4, name = "outUVs", description = "Output UV texture coordinates", slotValueType = SlotValueType.Vector2, value = Vector4.zero }
};
}
}
public ShaderGlobal[] globals { get { return new ShaderGlobal[] { }; } }
return GetType().GetMethod("Unity_RadialShear", BindingFlags.Static | BindingFlags.NonPublic);
}
public string hlsl
{
get
{
return
"float2 delta = inUVs - center;\n" +
"float delta2 = dot(delta.xy, delta.xy);\n" +
"float2 delta_offset = delta2 * shearAmount;\n" +
"outUVs = inUVs + float2(delta.y, -delta.x) * delta_offset + offset;";
}
}
static string Unity_RadialShear(
[Slot(0, Binding.MeshUV0)] Vector2 uv,
[Slot(1, Binding.None, 0.5f, 0.5f, 0.5f, 0.5f)] Vector2 center,
[Slot(2, Binding.None, 1f, 1f, 1f, 1f)] Vector2 shearAmount,
[Slot(3, Binding.None)] Vector2 offset,
[Slot(4, Binding.None)] out Vector2 result)
{
result = Vector2.zero;
return
@"
{
float2 delta = uv - center;
float delta2 = dot(delta.xy, delta.xy);
float2 delta_offset = delta2 * shearAmount;
result = uv + float2(delta.y, -delta.x) * delta_offset + offset;
}
";
}
}

62
MaterialGraphProject/Assets/NewNodes/WIP/ScaleOffsetNode.cs


using UnityEngine.Graphing;
using System.Reflection;
public class ScaleOffsetNode : AnyNode<ScaleOffsetNode.Definition>
public class ScaleOffsetNode : CodeFunctionNode
public class Definition : IAnyNodeDefinition
protected override MethodInfo GetFunctionToConvert()
public string name { get { return "ScaleOffset"; } }
public AnyNodeProperty[] properties
{
get
{
return new AnyNodeProperty[]
{
// slotId is the 'immutable' value we used to connect things
new AnyNodeProperty { slotId= 0, name = "inUVs", description = "Input UV coords", propertyType = PropertyType.Vector2, value = Vector4.zero, state = AnyNodePropertyState.Slot },
new AnyNodeProperty { slotId= 1, name = "scale", description = "UV scale", propertyType = PropertyType.Vector2, value= Vector4.one, state = AnyNodePropertyState.Constant },
new AnyNodeProperty { slotId= 2, name = "scaleCenter", description = "UV scale center", propertyType = PropertyType.Vector2, value= new Vector4(0.5f, 0.5f, 0.5f, 0.5f), state = AnyNodePropertyState.Constant },
new AnyNodeProperty { slotId= 3, name = "offset", description = "UV offset", propertyType = PropertyType.Vector2, value= Vector4.zero, state = AnyNodePropertyState.Constant },
};
}
}
public AnyNodeSlot[] outputs
{
get
{
return new AnyNodeSlot[]
{
new AnyNodeSlot { slotId= 4, name = "outUVs", description = "Output UV texture coordinates", slotValueType = SlotValueType.Vector2, value = Vector4.zero }
};
}
}
return GetType().GetMethod("Unity_ScaleAndOffset", BindingFlags.Static | BindingFlags.NonPublic);
}
public ShaderGlobal[] globals { get { return new ShaderGlobal[] { }; } }
static string Unity_ScaleAndOffset(
[Slot(0, Binding.MeshUV0)] Vector2 uv,
[Slot(1, Binding.None, 1f, 1f, 1f, 1f)] Vector2 scale,
[Slot(2, Binding.None, 0.5f, 0.5f, 0.5f, 0.5f)] Vector2 scaleCenter,
[Slot(3, Binding.None)] Vector2 offset,
[Slot(4, Binding.None)] out Vector2 result)
{
result = Vector2.zero;
return
@"
{
float4 xform = float4(scale, offset + scaleCenter - scaleCenter * scale);
result = uv * xform.xy + xform.zw;
}
";
}
public string hlsl
{
get
{
return
"float4 xform= float4(scale, offset + scaleCenter - scaleCenter * scale);\n" +
"outUVs = inUVs * xform.xy + xform.zw;";
}
}
}
}
}

66
MaterialGraphProject/Assets/NewNodes/WIP/SphereWarpNode.cs


using UnityEngine.Graphing;
using System.Reflection;
public class SphereWarpNode : AnyNode<SphereWarpNode.Definition>
public class SphereWarpNode : CodeFunctionNode
public class Definition : IAnyNodeDefinition
protected override MethodInfo GetFunctionToConvert()
public string name { get { return "SphereWarp"; } }
public AnyNodeProperty[] properties
{
get
{
return new AnyNodeProperty[]
{
// slotId is the 'immutable' value we used to connect things
new AnyNodeProperty { slotId= 0, name = "inUVs", description = "Input UV coords", propertyType = PropertyType.Vector2, value = Vector4.zero, state = AnyNodePropertyState.Slot },
new AnyNodeProperty { slotId= 1, name = "center", description = "UV radial center point", propertyType = PropertyType.Vector2, value= new Vector4(0.5f, 0.5f, 0.5f, 0.5f), state = AnyNodePropertyState.Constant },
new AnyNodeProperty { slotId= 2, name = "warpAmount", description = "Warp amount", propertyType = PropertyType.Vector2, value= Vector4.one, state = AnyNodePropertyState.Constant },
new AnyNodeProperty { slotId= 3, name = "offset", description = "UV offset", propertyType = PropertyType.Vector2, value= Vector4.zero, state = AnyNodePropertyState.Constant },
};
}
}
public AnyNodeSlot[] outputs
{
get
{
return new AnyNodeSlot[]
{
new AnyNodeSlot { slotId= 4, name = "outUVs", description = "Output UV texture coordinates", slotValueType = SlotValueType.Vector2, value = Vector4.zero }
};
}
}
return GetType().GetMethod("Unity_SphereWarp", BindingFlags.Static | BindingFlags.NonPublic);
}
public ShaderGlobal[] globals { get { return new ShaderGlobal[]{ }; } }
public string hlsl
{
get
{
return
"float2 delta = inUVs - center;\n" +
"float delta2 = dot(delta.xy, delta.xy);\n" +
"float delta4 = delta2 * delta2;\n" +
"float2 delta_offset = delta4 * warpAmount;\n" +
"outUVs = inUVs + delta * delta_offset + offset;";
}
}
static string Unity_SphereWarp(
[Slot(0, Binding.MeshUV0)] Vector2 uv,
[Slot(1, Binding.None, 0.5f, 0.5f, 0.5f, 0.5f)] Vector2 center,
[Slot(2, Binding.None, 1f, 1f, 1f, 1f)] Vector2 warpAmount,
[Slot(3, Binding.None)] Vector2 offset,
[Slot(4, Binding.None)] out Vector2 result)
{
result = Vector2.zero;
return
@"
{
float2 delta = uv - center;
float delta2 = dot(delta.xy, delta.xy);
float delta4 = delta2 * delta2;
float2 delta_offset = delta4 * warpAmount;
result = uv + delta * delta_offset + offset;
}";
}
}
}

104
MaterialGraphProject/Assets/NewNodes/WIP/SphericalIndentationNode.cs


using UnityEngine.Graphing;
using System.Reflection;
[Title("UV/SphericalIndentation")]
public class SphericalIndentationNode : AnyNode<SphericalIndentationNode.Definition>
{
public class Definition : IAnyNodeDefinition
{
public string name { get { return "SphericalIndentation"; } }
public AnyNodeProperty[] properties
{
get
{
return new AnyNodeProperty[]
{
// slotId is the 'immutable' value we used to connect things
new AnyNodeProperty { slotId= 0, name = "inUVs", description = "Input UV coords", propertyType = PropertyType.Vector2, value = Vector4.zero, state = AnyNodePropertyState.Slot },
new AnyNodeProperty { slotId= 1, name = "center", description = "UV center point", propertyType = PropertyType.Vector2, value= new Vector4(0.5f, 0.5f, 0.5f, 0.5f), state = AnyNodePropertyState.Constant },
new AnyNodeProperty { slotId= 2, name = "height", description = "Height off surface", propertyType = PropertyType.Float, value= Vector4.zero, state = AnyNodePropertyState.Constant },
new AnyNodeProperty { slotId= 3, name = "radius", description = "Radius", propertyType = PropertyType.Float, value= Vector4.one, state = AnyNodePropertyState.Constant },
};
}
}
public AnyNodeSlot[] outputs
{
get
{
return new AnyNodeSlot[]
{
new AnyNodeSlot { slotId= 4, name = "outUVs", description = "Output UVW texture coordinates", slotValueType = SlotValueType.Vector3, value = Vector4.zero },
new AnyNodeSlot { slotId= 5, name = "outNormal", description = "Output Normal in tangent space", slotValueType = SlotValueType.Vector3, value = Vector4.zero }
};
}
}
public ShaderGlobal[] globals { get { return new ShaderGlobal[] { ShaderGlobal.TangentSpaceViewDirection }; } }
public string hlsl
{
get
{
return
"float radius2= radius*radius;\n" +
"float3 cur= float3(inUVs.xy, 0.0f);\n" +
"float3 sphereCenter = float3(center, height);\n" +
"float3 edgeA = sphereCenter - cur;\n" +
"float a2 = dot(edgeA, edgeA);\n" +
"outUVs= float3(inUVs.xy, 0.0f);\n" +
"outNormal= float3(0.0f, 0.0f, 1.0f);\n" +
"if (a2 < radius2)\n" +
"{\n" +
" float a = sqrt(a2);\n" +
" edgeA = edgeA / a;\n" +
" float cosineR = dot(edgeA, tangentSpaceViewDirection.xyz);\n" +
" float x = cosineR * a - sqrt(-a2 + radius2 + a2 * cosineR * cosineR);\n" +
" float3 intersectedEdge = cur + tangentSpaceViewDirection * x;\n" +
" outNormal= normalize(sphereCenter - intersectedEdge);\n" +
" outUVs = intersectedEdge.xyz;\n" +
"}\n";
[Title("UV/SphericalIndentation")]
public class SphericalIndentationNode : CodeFunctionNode
{
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_SphericalIndentation", BindingFlags.Static | BindingFlags.NonPublic);
}
}
}
}
}
static string Unity_SphericalIndentation(
[Slot(0, Binding.MeshUV0)] Vector2 uv,
[Slot(1, Binding.None, 0.5f, 0.5f, 0.5f, 0.5f)] Vector2 center,
[Slot(2, Binding.None)] Vector1 height,
[Slot(3, Binding.None, 1f, 1f, 1f, 1f)] Vector1 radius,
[Slot(4, Binding.None)] out Vector3 resultUV,
[Slot(5, Binding.None)] out Vector2 resultNormal)
{
resultUV = Vector3.zero;
resultNormal = Vector3.up;
return
@"
{
float radius2= radius*radius;
float3 cur= float3(uv.xy, 0.0f);
float3 sphereCenter = float3(center, height);
float3 edgeA = sphereCenter - cur;
float a2 = dot(edgeA, edgeA);
outUVs= float3(inUVs.xy, 0.0f);
outNormal= float3(0.0f, 0.0f, 1.0f);
if (a2 < radius2)
{
float a = sqrt(a2);
edgeA = edgeA / a;
float cosineR = dot(edgeA, tangentSpaceViewDirection.xyz);
float x = cosineR * a - sqrt(-a2 + radius2 + a2 * cosineR * cosineR);
float3 intersectedEdge = cur + tangentSpaceViewDirection * x;
resultNormal= normalize(sphereCenter - intersectedEdge);
resultUV = intersectedEdge.xyz;
}
}";
}
}
}

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

9
MaterialGraphProject/Assets/TestGraph.ShaderGraph.meta


fileFormatVersion: 2
guid: 037778188549d9b4e8102cd29dea21a9
timeCreated: 1495526245
timeCreated: 1500622808
ScriptedImporter:
ShaderImporter:
defaultTextures: []
nonModifiableTextures:
- Texture2D_Texture2D_2F9B0B05_Uniform: {fileID: 2800000, guid: 79b61ba99411748ae8fa11666dceaee5,
type: 3}
script: {fileID: 11500000, guid: 625f186215c104763be7675aa2d941aa, type: 3}

4
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/AnyNodePresenter.cs


namespace UnityEditor.MaterialGraph.Drawing
{
class AnyNodeControlPresenter : GraphControlPresenter
/* class AnyNodeControlPresenter : GraphControlPresenter
{
public override void OnGUIHandler()
{

instance.Initialize(node);
return new List<GraphElementPresenter>(base.GetControlData()) { instance };
}
}
}*/
}

4
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/CustomCodeNodePresenter.cs


namespace UnityEditor.MaterialGraph.Drawing
{
class CustomCodeControlPresenter : GraphControlPresenter
/*class CustomCodeControlPresenter : GraphControlPresenter
{
public class CodeEditorPopup : PopupWindowContent
{

instance.Initialize(node);
return new List<GraphElementPresenter>(base.GetControlData()) { instance };
}
}
}*/
}

18
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs


typeMapper[typeof(AbstractMaterialNode)] = typeof(MaterialNodePresenter);
typeMapper[typeof(ColorNode)] = typeof(ColorNodePresenter);
typeMapper[typeof(GradientNode)] = typeof(GradientNodePresenter);
typeMapper[typeof(ScatterNode)] = typeof(ScatterNodePresenter);
typeMapper[typeof(TextureNode)] = typeof(TextureNodePresenter);
typeMapper[typeof(SamplerAssetNode)] = typeof(SamplerAssetNodePresenter);
typeMapper[typeof(TextureSamplerNode)] = typeof(TextureSamplerNodePresenter);
typeMapper[typeof(TextureAssetNode)] = typeof(TextureAssetNodePresenter);
// typeMapper[typeof(ScatterNode)] = typeof(ScatterNodePresenter);
//typeMapper[typeof(TextureNode)] = typeof(TextureNodePresenter);
//typeMapper[typeof(SamplerAssetNode)] = typeof(SamplerAssetNodePresenter);
//typeMapper[typeof(TextureSamplerNode)] = typeof(TextureSamplerNodePresenter);
typeMapper[typeof(Texture2DNode)] = typeof(TextureAssetNodePresenter);
typeMapper[typeof(TextureLODNode)] = typeof(TextureLODNodePresenter);
typeMapper[typeof(SamplerStateNode)] = typeof(SamplerStateNodePresenter);
typeMapper[typeof(CubemapNode)] = typeof(CubeNodePresenter);

typeMapper[typeof(Vector2Node)] = typeof(Vector2NodePresenter);
typeMapper[typeof(Vector3Node)] = typeof(Vector3NodePresenter);
typeMapper[typeof(Vector4Node)] = typeof(Vector4NodePresenter);
typeMapper[typeof(ScaleOffsetNode)] = typeof(AnyNodePresenter); // anything derived from AnyNode should use the AnyNodePresenter
/* typeMapper[typeof(ScaleOffsetNode)] = typeof(AnyNodePresenter); // anything derived from AnyNode should use the AnyNodePresenter
typeMapper[typeof(AACheckerboard3dNode)] = typeof(AnyNodePresenter); // anything derived from AnyNode should use the AnyNodePresenter
typeMapper[typeof(AACheckerboard3dNode)] = typeof(AnyNodePresenter); // anything derived from AnyNode should use the AnyNodePresenter*/
typeMapper[typeof(SubGraphNode)] = typeof(SubgraphNodePresenter);
typeMapper[typeof(RemapMasterNode)] = typeof(RemapMasterNodePresenter);
typeMapper[typeof(MasterRemapInputNode)] = typeof(RemapInputNodePresenter);

typeMapper[typeof(ConstantsNode)] = typeof(ConstantsNodePresenter);
//typeMapper[typeof(SwizzleNode)] = typeof(SwizzleNodePresenter);
typeMapper[typeof(BlendModeNode)] = typeof(BlendModeNodePresenter);
typeMapper[typeof(AddManyNode)] = typeof(AddManyNodePresenter);
// typeMapper[typeof(AddManyNode)] = typeof(AddManyNodePresenter);
typeMapper[typeof(CustomCodeNode)] = typeof(CustomCodePresenter);
//typeMapper[typeof(CustomCodeNode)] = typeof(CustomCodePresenter);
typeMapper[typeof(Matrix2Node)] = typeof(Matrix2NodePresenter);
typeMapper[typeof(Matrix3Node)] = typeof(Matrix3NodePresenter);
typeMapper[typeof(Matrix4Node)] = typeof(Matrix4NodePresenter);

4
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/SamplerAssetPresenter.cs


namespace UnityEditor.MaterialGraph.Drawing
{
class SamplerAssetControlPresenter : GraphControlPresenter
/*class SamplerAssetControlPresenter : GraphControlPresenter
{
private string[] m_TextureTypeNames;
private string[] textureTypeNames

instance.Initialize(node);
return new List<GraphElementPresenter> { instance };
}
}
}*/
}

4
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/ScatterNodePresenter.cs


namespace UnityEditor.MaterialGraph.Drawing
{
[Serializable]
/>an class="p">* [Serializable]
class ScatterContolPresenter : GraphControlPresenter
{
public override void OnGUIHandler()

}
}
*/
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/TextureAssetPresenter.cs


{
base.OnGUIHandler();
var tNode = node as UnityEngine.MaterialGraph.TextureAssetNode;
var tNode = node as UnityEngine.MaterialGraph.Texture2DNode;
if (tNode == null)
return;

4
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/TextureNodePresenter.cs


namespace UnityEditor.MaterialGraph.Drawing
{
class TextureContolPresenter : GraphControlPresenter
/* class TextureContolPresenter : GraphControlPresenter
{
private string[] m_TextureTypeNames;
private string[] textureTypeNames

instance.Initialize(node);
return new List<GraphElementPresenter> { instance };
}
}
}*/
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/TextureSamplerPresenter.cs


{
base.OnGUIHandler();
var tNode = node as UnityEngine.MaterialGraph.TextureAssetNode;
var tNode = node as UnityEngine.MaterialGraph.Texture2DNode;
if (tNode == null)
return;

4
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/PropertyNodeTests.cs


public class PropertyNodeTests
{
private UnityEngine.MaterialGraph.MaterialGraph m_Graph;
private TextureNode m_TextureNode;
private Texture2DNode m_TextureNode;
[TestFixtureSetUp]
public void RunBeforeAnyTests()

public void TestSetUp()
{
m_Graph = new UnityEngine.MaterialGraph.MaterialGraph();
m_TextureNode = new TextureNode();
m_TextureNode = new Texture2DNode();
m_Graph.AddNode(m_TextureNode);
}

4
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/PropertyNodeTests.cs


private Vector3Node m_Vector3Node;
private Vector4Node m_Vector4Node;
private ColorNode m_ColorNode;
private TextureNode m_TextureNode;
private Texture2DNode m_TextureNode;
private TestPropertyNode m_PropertyNode;
private const string kPropertyName = "PropertyName";

m_Vector3Node = new Vector3Node();
m_Vector4Node = new Vector4Node();
m_ColorNode = new ColorNode();
m_TextureNode = new TextureNode();
m_TextureNode = new Texture2DNode();
m_PropertyNode = new TestPropertyNode();
m_Graph.AddNode(m_Vector1Node);

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


if (edges.Any())
continue;
if (inputSlot.valueType == SlotValueType.SamplerState)
{
visitor.AddShaderChunk("#ifdef UNITY_COMPILER_HLSL", false);
visitor.AddShaderChunk(inputSlot.valueType + " my_linear_repeat_sampler;", false);
visitor.AddShaderChunk("#endif", false);
}
else
inputSlot.GeneratePropertyUsages(visitor, generationMode);
inputSlot.GeneratePropertyUsages(visitor, generationMode);
}
}

return ConcreteSlotValueType.Matrix4;
case SlotValueType.SamplerState:
return ConcreteSlotValueType.SamplerState;
case SlotValueType.Sampler2D:
return ConcreteSlotValueType.Sampler2D;
}
return ConcreteSlotValueType.Error;
}

if (from == to)
return true;
var fromCount = SlotValueHelper.GetChannelCount(from);
var toCount = SlotValueHelper.GetChannelCount(to);
// can convert from v1 vectors :)
if (from == ConcreteSlotValueType.Vector1 && toCount > 0)
return true;
if (toCount == 0)
return false;
if (toCount <= fromCount)
return true;
return from >= to || from == ConcreteSlotValueType.Vector1;
}

return "4x4";
case ConcreteSlotValueType.SamplerState:
return "SamplerState";
case ConcreteSlotValueType.Sampler2D:
return "sampler2D";
default:
return "Error";
}

return "Matrix4x4";
case ConcreteSlotValueType.SamplerState:
return "SamplerState";
case ConcreteSlotValueType.Sampler2D:
return "sampler2D";
default:
return "Error";
}

return PropertyType.Matrix4;
case ConcreteSlotValueType.SamplerState:
return PropertyType.SamplerState;
case ConcreteSlotValueType.Sampler2D:
return PropertyType.Texture;
default:
return PropertyType.Vector4;
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Art/Filters/ConvolutionFilterNode.cs


}
//prevent validation errors when a sampler2D input is missing
//use on any input requiring a TextureAssetNode
//use on any input requiring a Texture2DNode
public override void ValidateNode()
{
base.ValidateNode();

11
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Channel/SplitNode.cs


public const int OutputSlotAId = 4;
public const int OutputSlotRGBId = 5;
public const int OutputSlotRGId = 6;
public SplitNode()
{
name = "Split";

if (inputSlot == null)
return "1.0";
int numInputChannels = (int)inputSlot.concreteValueType;
int numInputChannels = (int)SlotValueHelper.GetChannelCount(inputSlot.concreteValueType);
if (numInputChannels > 4)
numInputChannels = 0;
if (owner.GetEdges(inputSlot.slotReference).ToList().Count() == 0)
numInputChannels = 0;

}
public override string GetVariableNameForSlot(int slotId)
{
{
string slotOutput;
switch (slotId)

default:
slotOutput = "";
break;
}
}
return GetVariableNameForNode() + slotOutput;
}
}

5
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Channel/SwizzleNode.cs


if (outputSlot == null)
return "1.0";
int numInputChannels = (int)inputSlot.concreteValueType;
int numInputChannels = (int)SlotValueHelper.GetChannelCount(inputSlot.concreteValueType);
int numOutputChannels = (int)SlotValueHelper.GetChannelCount(outputSlot.concreteValueType);
//int numInputChannels = (int)inputSlot.concreteValueType;
int numOutputChannels = (int)outputSlot.concreteValueType;
if (owner.GetEdges(inputSlot.slotReference).ToList().Count() == 0)
numInputChannels = 0;

7
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/HLSLNode.cs


protected struct Texture2D
{}
protected struct Sampler2D
{}
protected struct SamplerState
{}

if (t == typeof(Texture2D))
{
return SlotValueType.Texture2D;
}
if (t == typeof(Sampler2D))
{
return SlotValueType.Sampler2D;
}
if (t == typeof(SamplerState))
{

8
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Texture/SamplerAssetNode.cs


namespace UnityEngine.MaterialGraph
{
[Title("Input/Texture/Sampler Asset")]
/* [Title("Input/Texture/Sampler Asset")]
public class SamplerAssetNode : PropertyNode
{

public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(OutputID, kOutputSlotRGBAName, kOutputSlotRGBAName, SlotType.Output, SlotValueType.Sampler2D, Vector4.zero));
AddSlot(new MaterialSlot(OutputID, kOutputSlotRGBAName, kOutputSlotRGBAName, SlotType.Output, SlotValueType.Sampler2D, Vector4.zero));
RemoveSlotsNameNotMatching(validSlots);
}

}
public override PropertyType propertyType { get { return PropertyType.Texture; } }
}
}*/
}

6
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Texture/TextureNode.cs


namespace UnityEngine.MaterialGraph
{
[Title("Input/Texture/Texture")]
/* [Title("Input/Texture/Texture")]
public class TextureNode : PropertyNode, IGeneratesBodyCode, IMayRequireMeshUV
{
protected const string kUVSlotName = "UV";

return false;
}
*/
*
public override PreviewProperty GetPreviewProperty()
{

var edges = owner.GetEdges(uvSlot.slotReference).ToList();
return edges.Count == 0;
}
}
}*/
}

4
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Logic/CustomCodeNode.cs


namespace UnityEngine.MaterialGraph
{
[Title("Logic/CustomCode")]
/>an class="p">*> [Title("Logic/CustomCode")]
public class CustomCodeNode : FunctionNInNOut, IGeneratesFunction
{
[SerializeField] private string m_code;

return outputArguments;
}
}
}*/
}

9
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/MaterialSlot.cs


return "(SS)";
case ConcreteSlotValueType.Texture2D:
return "(T)";
case ConcreteSlotValueType.Sampler2D:
return "(S)";
default:
return "(E)";
}

case SlotValueType.SamplerState:
concreteValueType = ConcreteSlotValueType.SamplerState;
break;
case SlotValueType.Sampler2D:
concreteValueType = ConcreteSlotValueType.Sampler2D;
break;
default:
concreteValueType = ConcreteSlotValueType.Vector4;
break;

public void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)
{
if (!generationMode.IsPreview())
return;
if (concreteValueType == ConcreteSlotValueType.SamplerState ||
concreteValueType == ConcreteSlotValueType.Texture2D)
return;
var matOwner = owner as AbstractMaterialNode;

54
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/SlotValue.cs


[Serializable]
public enum SlotValueType
{
Sampler2D,
SamplerState,
SamplerState,
Matrix4,
Matrix3,
Matrix2,

public enum ConcreteSlotValueType
{
Sampler2D = 10,
SamplerState = 9,
Matrix4 = 8,
Matrix3 = 7,
Matrix2 = 6,
Texture2D = 5,
Vector4 = 4,
Vector3 = 3,
Vector2 = 2,
Vector1 = 1,
Error = 0
SamplerState,
Matrix4,
Matrix3,
Matrix2,
Texture2D,
Vector4,
Vector3,
Vector2,
Vector1,
Error
public static class SlotValueHelper
{
public enum ChannelCount
{
Zero = 0,
One = 1,
Two = 2,
Three = 3,
Four = 4,
}
public static ChannelCount GetChannelCount(ConcreteSlotValueType type)
{
switch (type)
{
case ConcreteSlotValueType.Vector4:
return ChannelCount.Four;
case ConcreteSlotValueType.Vector3:
return ChannelCount.Three;
case ConcreteSlotValueType.Vector2:
return ChannelCount.Two;
case ConcreteSlotValueType.Vector1:
return ChannelCount.One;
default:
return ChannelCount.Zero;
}
}
}
}

24
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SurfaceModel/AbstractSurfaceMasterNode.cs


{
GenerateNodeFunctionsAndPropertyUsages(vertexShaderBlock, propertyUsages, nodeFunction, mode, vertexInputs);
var slot = FindInputSlot<MaterialSlot>(VertexOffsetId);
foreach (var edge in owner.GetEdges(slot.slotReference))
{

}
var templateText = File.ReadAllText(templateLocation);
var shaderPropertiesVisitor = new PropertyGenerator();
var resultShader = templateText.Replace("${ShaderName}", GetType() + guid.ToString());
resultShader = resultShader.Replace("${SubShader}", GetSubShader(mode, shaderPropertiesVisitor));

GenerationMode mode)
{
var activeNodeList = new List<INode>();
NodeUtils.DepthFirstCollectNodesFromNode(activeNodeList, this, NodeUtils.IncludeSelf.Include,
NodeUtils.DepthFirstCollectNodesFromNode(activeNodeList, this, NodeUtils.IncludeSelf.Include,
string prefix = "";
string sufix = "";
foreach (ISlot slot in node.GetInputSlots<MaterialSlot>())
{
SlotValueType slotValueType = FindSlot<MaterialSlot>(slot.id).valueType;
if (slotValueType == SlotValueType.Texture2D || slotValueType == SlotValueType.SamplerState)
{
prefix = "#ifdef UNITY_COMPILER_HLSL \n";
sufix = "\n #endif";
}
}
nodeFunction.AddShaderChunk(prefix, false);
(node as IGeneratesFunction).GenerateNodeFunction(nodeFunction, mode);
nodeFunction.AddShaderChunk(sufix, false);
((IGeneratesFunction) node).GenerateNodeFunction(nodeFunction, mode);
}
node.GeneratePropertyUsages(propertyUsages, mode);

public void GenerateNodeCode(ShaderGenerator shaderBody, GenerationMode generationMode)
{
var nodes = ListPool<INode>.Get();
//Get the rest of the nodes for all the other slots
NodeUtils.DepthFirstCollectNodesFromNode(nodes, this, NodeUtils.IncludeSelf.Exclude, new List<int>(surfaceInputs));
for (var i = 0; i < nodes.Count; i++)

45
MaterialGraphProject/Assets/Vlad/SamplerStateNode.cs


namespace UnityEngine.MaterialGraph
{
[Title("Input/Sampler State")]
public class SamplerStateNode : AbstractMaterialNode, IGeneratesBodyCode
[Title("Input/Texture/Sampler State")]
public class SamplerStateNode : AbstractMaterialNode
{
public enum FilterMode

[SerializeField]
private FilterMode m_filter = FilterMode.Linear;
public FilterMode filter
{
get { return m_filter; }

[SerializeField]
private WrapMode m_wrap = WrapMode.Repeat;
public WrapMode wrap
{

RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
}
/*
public override PropertyType propertyType
public override string GetVariableNameForSlot(int slotId)
get { return PropertyType.SamplerState; }
return GetVariableNameForNode();
public override PreviewProperty GetPreviewProperty()
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)
return new PreviewProperty
{
m_Name = propertyName + "HEEEEEEYYYYY",
m_PropType = PropertyType.Float,
// m_Float = filterMode[filter];
};
var decl = string.Format(@"
#ifdef UNITY_COMPILER_HLSL
SamplerState {0};
#endif", GetVariableNameForNode());
visitor.AddShaderChunk(decl, true);
*/
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
{
// GetVariableNameForSlot();
}
public override string GetVariableNameForSlot(int slotId)
{
// var slot = FindSlot<MaterialSlot>(slotId);
//if (slot == null)
// throw new ArgumentException(string.Format("Attempting to use MaterialSlot({0}) on node of type {1} where this slot can not be found", slotId, this), "slotId");
return GetVariableNameForNode();
}
//my_linear_repeat_sampler
return "my" + filterMode[filter] + wrapMode[wrap] + "_sampler";
return base.GetVariableNameForNode() + filterMode[filter] + wrapMode[wrap] + "_sampler";
}
}
}

292
MaterialGraphProject/Assets/Vlad/TextureSamplerNode.cs


using System;
using System.Collections.Generic;
using System.Linq;
#if UNITY_EDITOR
using UnityEditor;
#endif
using System.Linq;
using System.Reflection;
{
[Title("Texture/Sample 2D")]
public class Sample2DTexture : AbstractMaterialNode, IGeneratesBodyCode, IMayRequireMeshUV
[Title("Input/Texture/Texture Sampler")]
public class TextureSamplerNode : PropertyNode, IGeneratesBodyCode, IMayRequireMeshUV
{
private const string kTextureAssetName = "Texture Asset";
private const string kUVSlotName = "UV";
private const string kSamplerName = "Sampler";
protected const string kOutputSlotRGBAName = "RGBA";
public const int TextureAssetSlotId = 0;
public const int UVSlotId = 1;
public const int SamplerSlotId = 2;
public const int OutputSlotRGBAId = 3;
[SerializeField]
private string m_SerializedTexture;
[SerializeField]
private TextureType m_TextureType;
[Serializable]
private class TextureHelper
{
public Texture2D texture;
}
public override bool hasPreview { get { return true; } }
#if UNITY_EDITOR
public Texture2D defaultTexture
{
get
{
if (string.IsNullOrEmpty(m_SerializedTexture))
return null;
var tex = new TextureHelper();
EditorJsonUtility.FromJsonOverwrite(m_SerializedTexture, tex);
return tex.texture;
}
set
{
if (defaultTexture == value)
return;
var tex = new TextureHelper();
tex.texture = value;
m_SerializedTexture = EditorJsonUtility.ToJson(tex, true);
if (onModified != null)
{
onModified(this, ModificationScope.Node);
}
}
}
#else
public Texture2D defaultTexture {get; set; }
#endif
public TextureType textureType
{
get { return m_TextureType; }
set
{
if (m_TextureType == value)
return;
public const int OutputSlotId = 0;
public const int TextureInputId = 1;
public const int UVInput = 2;
public const int SamplerInput = 3;
private const string kOutputSlotName = "rgba";
private const string kTextureInputName = "Tex";
private const string kUVInputName = "UV";
private const string kSamplerInputName = "Sampler";
m_TextureType = value;
if (onModified != null)
{
onModified(this, ModificationScope.Graph);
}
}
}
public override bool hasPreview { get { return true; } }
public TextureSamplerNode()
{
name = "TextureSamplerNode";
UpdateNodeAfterDeserialization();
}
public Sample2DTexture()
{
name = "Sample2DTexture";
UpdateNodeAfterDeserialization();
}
{
AddSlot(new MaterialSlot(TextureAssetSlotId, kTextureAssetName, kTextureAssetName, SlotType.Input, SlotValueType.Texture2D, Vector4.zero, false));
AddSlot(new MaterialSlot(UVSlotId, kUVSlotName, kUVSlotName, SlotType.Input, SlotValueType.Vector2, Vector4.zero, false));
AddSlot(new MaterialSlot(SamplerSlotId, kSamplerName, kSamplerName, SlotType.Input, SlotValueType.SamplerState, Vector4.zero, false));
AddSlot(new MaterialSlot(OutputSlotRGBAId, kOutputSlotRGBAName, kOutputSlotRGBAName, SlotType.Output, SlotValueType.Vector4, Vector4.zero));
RemoveSlotsNameNotMatching(validSlots);
}
{
AddSlot(new MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Vector4, Vector4.zero));
AddSlot(new MaterialSlot(TextureInputId, kTextureInputName, kTextureInputName, SlotType.Input, SlotValueType.Texture2D, Vector4.zero));
AddSlot(new MaterialSlot(UVInput, kUVInputName, kUVInputName, SlotType.Input, SlotValueType.Vector2, Vector4.zero));
AddSlot(new MaterialSlot(SamplerInput, kSamplerInputName, kSamplerInputName, SlotType.Input, SlotValueType.SamplerState, Vector4.zero));
RemoveSlotsNameNotMatching(new[] { OutputSlotId, TextureInputId, UVInput, SamplerInput });
}
protected int[] validSlots
{
get { return new[] { OutputSlotRGBAId, SamplerSlotId, UVSlotId, TextureAssetSlotId }; }
}
// Node generations
public virtual void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
// Node generations
public virtual void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
{
//Texture input slot
var textureSlot = FindInputSlot<MaterialSlot>(TextureInputId);
var edgesTexture = owner.GetEdges(textureSlot.slotReference);
// if no texture connected return nothing
if (!edgesTexture.Any())
//Texture input slot
var textureSlot = FindInputSlot<MaterialSlot>(TextureAssetSlotId);
var textureAssetName = "";
var edgesTexture = owner.GetEdges(textureSlot.slotReference).ToList();
if (edgesTexture.Count > 0)
{
var edge = edgesTexture[0];
var fromNode = owner.GetNodeFromGuid<AbstractMaterialNode>(edge.outputSlot.nodeGuid);
textureAssetName = ShaderGenerator.AdaptNodeOutput(fromNode, edge.outputSlot.slotId, ConcreteSlotValueType.Texture2D, true);
}
//UV input slot
var uvSlot = FindInputSlot<MaterialSlot>(UVSlotId);
var uvName = string.Format("{0}.xy", UVChannel.uv0.GetUVName());
if (uvSlot == null)
visitor.AddShaderChunk(precision + "4 " + GetVariableNameForSlot(OutputSlotId) + " = " + precision + "4(0,0,0,0);", true);
var edgesUV = owner.GetEdges(uvSlot.slotReference).ToList();
if (edgesUV.Count > 0)
{
var edge = edgesUV[0];
var fromNode = owner.GetNodeFromGuid<AbstractMaterialNode>(edge.outputSlot.nodeGuid);
uvName = ShaderGenerator.AdaptNodeOutput(fromNode, edge.outputSlot.slotId, ConcreteSlotValueType.Vector2, true);
}
//Sampler input slot
var samplerSlot = FindInputSlot<MaterialSlot>(SamplerSlotId);
var samplerName = "my_linear_repeat_sampler";
if (samplerSlot == null)
return;
var edgesSampler = owner.GetEdges(samplerSlot.slotReference).ToList();
if (edgesSampler.Count > 0)
{
var edge = edgesSampler[0];
var fromNode = owner.GetNodeFromGuid<AbstractMaterialNode>(edge.outputSlot.nodeGuid);
samplerName = ShaderGenerator.AdaptNodeOutput(fromNode, edge.outputSlot.slotId, ConcreteSlotValueType.SamplerState, true);
}
visitor.AddShaderChunk(precision + "4 " + GetVariableNameForNode() + "_Uniform = " + precision + "4(0,0,0,0);", true);
visitor.AddShaderChunk("#ifdef UNITY_COMPILER_HLSL", true);
string body = textureAssetName + ".Sample(" + samplerName + ", " + uvName + ");";
if (m_TextureType == TextureType.Bump)
body = precision + "4(UnpackNormal(" + body + "), 0)";
visitor.AddShaderChunk(GetVariableNameForNode() + "_Uniform" + " = " + body, true);
visitor.AddShaderChunk("#endif", true);
}
// Properties
public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode)
{ /*
visitor.AddShaderProperty(
new TexturePropertyChunk(
propertyName,
description,
defaultTexture, m_TextureType,
PropertyChunk.HideState.Visible,
exposedState == ExposedState.Exposed ?
TexturePropertyChunk.ModifiableState.Modifiable
: TexturePropertyChunk.ModifiableState.NonModifiable));
*/
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)
{
//UV input slot
var uvSlot = FindInputSlot<MaterialSlot>(UVInput);
var uvName = string.Format("{0}.xy", UVChannel.uv0.GetUVName());
var edgesUV = owner.GetEdges(uvSlot.slotReference);
if (edgesUV.Any())
uvName = GetSlotValue(UVInput, generationMode);
var samplerSlot = FindInputSlot<MaterialSlot>(SamplerSlotId);
var samplerName = "my_linear_repeat_sampler";
var samplerSlot = FindInputSlot<MaterialSlot>(SamplerInput);
var edgesSampler = owner.GetEdges(samplerSlot.slotReference);
if (samplerSlot == null)
return;
var edgesSampler = owner.GetEdges(samplerSlot.slotReference).ToList();
if (edgesSampler.Count > 0)
string result;
if (edgesSampler.Any())
var edge = edgesSampler[0];
var fromNode = owner.GetNodeFromGuid<AbstractMaterialNode>(edge.outputSlot.nodeGuid);
samplerName = ShaderGenerator.AdaptNodeOutput(fromNode, edge.outputSlot.slotId, ConcreteSlotValueType.SamplerState, true);
result = string.Format(@"
#ifdef UNITY_COMPILER_HLSL
{0}4 {1} = {2}.Sample({3}, {4});
#else
{0}4 {1} = UNITY_SAMPLE_TEX2D({2}, {4});
#endif"
, precision
, GetVariableNameForSlot(OutputSlotId)
, GetSlotValue(TextureInputId, generationMode)
, GetSlotValue(SamplerInput, generationMode)
, uvName);
visitor.AddShaderChunk("#ifdef UNITY_COMPILER_HLSL", false);
visitor.AddShaderChunk(samplerSlot.valueType + " " + samplerName + ";", true);
visitor.AddShaderChunk("#endif", false);
}
public override PreviewProperty GetPreviewProperty()
else
return new PreviewProperty
{
m_Name = propertyName,
m_PropType = PropertyType.Texture,
m_Texture = defaultTexture
};
result = string.Format("{0}4 {1} = UNITY_SAMPLE_TEX2D({2},{3});"
, precision
, GetVariableNameForSlot(OutputSlotId)
, GetSlotValue(TextureInputId, generationMode)
, uvName);
public override PropertyType propertyType { get { return PropertyType.Texture; } }
visitor.AddShaderChunk(result, true);
}
public bool RequiresMeshUV(UVChannel channel)
public bool RequiresMeshUV(UVChannel channel)
{
if (channel != UVChannel.uv0)
if (channel != UVChannel.uv0)
{
return false;
}
var uvSlot = FindInputSlot<MaterialSlot>(UVSlotId);
if (uvSlot == null)
return true;
var edges = owner.GetEdges(uvSlot.slotReference).ToList();
return edges.Count == 0;
return false;
//prevent validation errors when a sampler2D input is missing
//use on any input requiring a TextureAssetNode
public override void ValidateNode()
{
base.ValidateNode();
var slot = FindInputSlot<MaterialSlot>(TextureAssetSlotId);
if (slot == null)
return;
var uvSlot = FindInputSlot<MaterialSlot>(UVInput);
if (uvSlot == null)
return true;
var edges = owner.GetEdges(slot.slotReference).ToList();
hasError |= edges.Count == 0;
var edges = owner.GetEdges(uvSlot.slotReference).ToList();
return edges.Count == 0;
}
}

17
MaterialGraphProject/Assets/Vlad/UVTriPlanar.cs


namespace UnityEngine.MaterialGraph
{
[Title("UV/Tri-Planar Mapping")]
/* [Title("UV/Tri-Planar Mapping")]
public class UVTriPlanar : FunctionNInNOut, IGeneratesFunction, IMayRequireNormal, IMayRequireWorldPosition
{
private int slot0, slot1, slot2, slot3, slot4, slot5, slot6 = 0;

visitor.AddShaderChunk(outputString.GetShaderString(0), true);
}
//use on any input requiring a TextureAssetNode
//use on any input requiring a Texture2DNode
public override void ValidateNode()
{
base.ValidateNode();

public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)
{
base.GeneratePropertyUsages(visitor, generationMode);
var samplerSlot = FindInputSlot<MaterialSlot>(slot3);

//prevent validation errors when a sampler2D input is missing
//use on any input requiring a TextureAssetNode
//use on any input requiring a Texture2DNode
public override void ValidateNode()
{
base.ValidateNode();

{
return true;
}
}
}*/
*/

13
MaterialGraphProject/Assets/Vlad/Texture2DNode.cs


namespace UnityEngine.MaterialGraph
{
[Title("Input/Texture/Texture Asset")]
public class TextureAssetNode : PropertyNode
public class Texture2DNode : PropertyNode
{
protected const string textureName = "Texture";

}
}
public TextureAssetNode()
public Texture2DNode()
name = "TextureAsset";
name = "Texture2D";
UpdateNodeAfterDeserialization();
}

{
var edgesTexture2D = owner.GetEdges(slotTexture2D.slotReference).ToList();
if (edgesTexture2D.Count > 0)
{
visitor.AddShaderChunk("#ifdef UNITY_COMPILER_HLSL", true);
visitor.AddShaderChunk("Texture2D " + propertyName + ";", true);
visitor.AddShaderChunk("#endif", true);
}
visitor.AddShaderChunk("UNITY_DECLARE_TEX2D(" + propertyName + ");", true);
public override PreviewProperty GetPreviewProperty()

2
MaterialGraphProject/Assets/Vlad/Texture2DNode.cs.meta


fileFormatVersion: 2
guid: 9def76d530f56804b9f696a9b36eccfa
timeCreated: 1495535587
timeCreated: 1500545522
licenseType: Pro
MonoImporter:
serializedVersion: 2

2
MaterialGraphProject/Assets/_MingWai/GeneratedTextureDemo/0-UnityLogo-Texture.asset.meta


fileFormatVersion: 2
guid: 28805740b89754d4f87ecf03fa9a100d
guid: 8dfb75ebba6ad4fe1866fa19ab61a229
timeCreated: 1495750594
licenseType: Pro
NativeFormatImporter:

2
MaterialGraphProject/Assets/_MingWai/Gradient.asset.meta


fileFormatVersion: 2
guid: 28805740b89754d4f87ecf03fa9a100d
guid: 4a6270d074d534b00999ae9354b1223d
timeCreated: 1495750594
licenseType: Pro
NativeFormatImporter:

4
MaterialGraphProject/Assets/_MingWai/ScatterNode.cs


namespace UnityEngine.MaterialGraph
{
[Title("Procedural/Scatter")]
/* [Title("Procedural/Scatter")]
public class ScatterNode : FunctionNInNOut, IGeneratesFunction
{

visitor.AddShaderChunk(outputString.GetShaderString(0), true);
}
}
}*/
}

/MaterialGraphProject/Assets/Vlad/TextureAssetNode.cs → /MaterialGraphProject/Assets/Vlad/Texture2DNode.cs

/MaterialGraphProject/Assets/Vlad/TextureAssetNode.cs.meta → /MaterialGraphProject/Assets/Vlad/Texture2DNode.cs.meta

正在加载...
取消
保存