浏览代码

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

/main
Jennifer Nordwall 7 年前
当前提交
b94d71ca
共有 66 个文件被更改,包括 2924 次插入316 次删除
  1. 146
      MaterialGraphProject/Assets/Andre/Materials/Mat.mat
  2. 2
      MaterialGraphProject/Assets/Andre/Nodes/ToggleNode.cs
  3. 2
      MaterialGraphProject/Assets/Andre/Shaders/TestingGraph.ShaderGraph
  4. 2
      MaterialGraphProject/Assets/Eduardo/EduardoTestGraph.ShaderGraph
  5. 54
      MaterialGraphProject/Assets/Eduardo/FunctionNInNOut.cs
  6. 26
      MaterialGraphProject/Assets/Eduardo/HeightToNormalNode.cs
  7. 127
      MaterialGraphProject/Assets/GeneratedShader.shader
  8. 2
      MaterialGraphProject/Assets/Matt/AnisotropicMaster.ShaderGraph
  9. 2
      MaterialGraphProject/Assets/Matt/Examples/Swirl.ShaderGraph
  10. 2
      MaterialGraphProject/Assets/NewNodes/WIP/MultiLayerParallaxNode.cs
  11. 5
      MaterialGraphProject/Assets/TestAssets/Materials/Default.mat
  12. 2
      MaterialGraphProject/Assets/TestAssets/Teapot.fbx.meta
  13. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs
  14. 17
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/HelperShader.shader
  15. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/HelperShader.shader.meta
  16. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Templates/subshader.template
  17. 25
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/AbstractMaterialNode.cs
  18. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Function2Input.cs
  19. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/MaterialSlot.cs
  20. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/PropertyType.cs
  21. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/SlotValue.cs
  22. 16
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SurfaceModel/AbstractSurfaceMasterNode.cs
  23. 8
      MaterialGraphProject/Assets/Vlad/TextureAssetNode.cs
  24. 122
      MaterialGraphProject/Assets/Vlad/UVTriPlanar.cs
  25. 2
      MaterialGraphProject/Assets/_MingWai/ScatterNode.cs
  26. 9
      MaterialGraphProject/Assets/Florent.meta
  27. 1
      MaterialGraphProject/Assets/Matt/Examples/Anisotropy.ShaderGraph
  28. 9
      MaterialGraphProject/Assets/Matt/Examples/Anisotropy.ShaderGraph.meta
  29. 81
      MaterialGraphProject/Assets/Matt/Examples/Anisotropy.mat
  30. 9
      MaterialGraphProject/Assets/Matt/Examples/Anisotropy.mat.meta
  31. 1
      MaterialGraphProject/Assets/Matt/Examples/Grain.ShaderGraph
  32. 9
      MaterialGraphProject/Assets/Matt/Examples/Grain.ShaderGraph.meta
  33. 335
      MaterialGraphProject/Assets/NewNodes/WIP/POMNode.cs
  34. 12
      MaterialGraphProject/Assets/NewNodes/WIP/POMNode.cs.meta
  35. 1
      MaterialGraphProject/Assets/POM_Graph.ShaderGraph
  36. 9
      MaterialGraphProject/Assets/POM_Graph.ShaderGraph.meta
  37. 21
      MaterialGraphProject/Assets/TestAssets/TangentMap1.jpg
  38. 75
      MaterialGraphProject/Assets/TestAssets/TangentMap1.jpg.meta
  39. 33
      MaterialGraphProject/Assets/TestAssets/TangentMap2.jpg
  40. 75
      MaterialGraphProject/Assets/TestAssets/TangentMap2.jpg.meta
  41. 12
      MaterialGraphProject/Assets/TestAssets/TangentMap3.jpg
  42. 75
      MaterialGraphProject/Assets/TestAssets/TangentMap3.jpg.meta
  43. 151
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/ConvolutionFilterNodePresenter.cs
  44. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/ConvolutionFilterNodePresenter.cs.meta
  45. 64
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/SamplerStatePresenter.cs
  46. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/SamplerStatePresenter.cs.meta
  47. 52
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/TextureSamplerPresenter.cs
  48. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/TextureSamplerPresenter.cs.meta
  49. 445
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/bricks_height.png
  50. 75
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/bricks_height.png.meta
  51. 137
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/bricks_normal.tga
  52. 75
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/bricks_normal.tga.meta
  53. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/mur_Ambiant.bmp
  54. 75
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/mur_Ambiant.bmp.meta
  55. 52
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Templates/tesselationSubshader.template
  56. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Templates/tesselationSubshader.template.meta
  57. 9
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Art/Filters.meta
  58. 133
      MaterialGraphProject/Assets/Vlad/SamplerStateNode.cs
  59. 12
      MaterialGraphProject/Assets/Vlad/SamplerStateNode.cs.meta
  60. 246
      MaterialGraphProject/Assets/Vlad/TextureSamplerNode.cs
  61. 12
      MaterialGraphProject/Assets/Vlad/TextureSamplerNode.cs.meta
  62. 1
      MaterialGraphProject/Assets/Florent/GeneratedTexture.meta
  63. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Art/Filters/ConvolutionFilterNode.cs.meta
  64. 287
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Art/Filters/ConvolutionFilterNode.cs

146
MaterialGraphProject/Assets/Andre/Materials/Mat.mat


disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- Cubemap_181b280a_a8b7_461e_bbeb_30fa23931a56_Uniform:
m_Texture: {fileID: 8900000, guid: f7111c407ddfe4109af9703cb740eaf9, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- Cubemap_cfafd4ef_c0b8_4ca3_9f3c_7068e7916d3e_Uniform:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- Cubemap_dc3182b8_fe99_45ed_8c1d_67fb354034bd_Uniform:
m_Texture: {fileID: 8900000, guid: f7111c407ddfe4109af9703cb740eaf9, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- Cubemap_ee09e335_3be2_46ee_9d59_ce2673aeedf9_Uniform:
m_Texture: {fileID: 8900000, guid: f7111c407ddfe4109af9703cb740eaf9, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- TextureAsset_ebbe75eb_728a_4e6c_b8a1_994df86c74ad_Uniform:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- Texture_02e4013b_5c99_456a_a8d8_cafbb1dfc0da_Uniform:
m_Texture: {fileID: 2800000, guid: 5a5e07ee958edbd468227e1d9ac4726a, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- Texture_401188ed_6e9e_4a8a_9f5c_a7853502ba40_Uniform:
m_Texture: {fileID: 2800000, guid: aa460a2956f927d4ab684aa4970bf76a, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- Texture_5537060b_db74_4900_8f2b_178ba97b7f11_Uniform:
m_Texture: {fileID: 10305, guid: 0000000000000000f000000000000000, type: 0}
m_Scale: {x: 1, y: 2}
m_Offset: {x: 0, y: 0}
- Texture_6df69ae7_cb4c_435c_a029_13f370817e4c_Uniform:
m_Texture: {fileID: 2800000, guid: 84462bdfeee9d694bbebf34e5f3faa74, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- Texture_73d7755c_9da7_46d2_90c6_35c2a880d380_Uniform:
m_Texture: {fileID: 2800000, guid: 5a5e07ee958edbd468227e1d9ac4726a, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- Texture_7e044bc6_b639_4457_83f6_752bfaedcb11_Uniform:
m_Texture: {fileID: 2800000, guid: 330f42016073a97418a4aae5517e32c8, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- Texture_8304e17f_0ca3_45b8_9081_4e083e4ffba7_Uniform:
m_Texture: {fileID: 2800000, guid: 330f42016073a97418a4aae5517e32c8, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- Texture_aa489395_d5b1_4bce_a08c_71ce4329894d_Uniform:
m_Texture: {fileID: 2800000, guid: 330f42016073a97418a4aae5517e32c8, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- Texture_bac51ec0_c299_4919_8bbd_573b26865795_Uniform:
m_Texture: {fileID: 2800000, guid: 556373d2abe91394795e2c7b920330f0, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- Texture_c007d40f_e93f_40ea_9867_1b70cebcd3fd_Uniform:
m_Texture: {fileID: 2800000, guid: aa460a2956f927d4ab684aa4970bf76a, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- Texture_cfc1ad3f_b7ac_495b_a5d4_bbf5e525f27c_Uniform:
m_Texture: {fileID: 2800000, guid: 46dd7a1d84b1ee64ca65752c24cfd890, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- Texture_d48530d7_5921_4987_918e_46411222e797_Uniform:
m_Texture: {fileID: 2800000, guid: 5b01c9e873ba169449186e98e1483a23, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- Texture_d6d1ed65_5575_444c_8f92_38740ace2353_Uniform:
m_Texture: {fileID: 2800000, guid: 5a5e07ee958edbd468227e1d9ac4726a, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- Texture_f6eb7ab6_0df6_4d1f_a833_847f9eefa1ce_Uniform:
m_Texture: {fileID: 2800000, guid: 915047e45d68d412f9e6857db8439117, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- Texture_fd9422b7_6255_4b8e_b616_78346d444d21_Uniform:
m_Texture: {fileID: 2800000, guid: 84462bdfeee9d694bbebf34e5f3faa74, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_TexEnvs: []
- Toggle_bda28932_b1ab_4b0b_ba54_ca5db612047a_Uniform: 0.6
- Vector1_15d5efb3_faea_4990_90ce_629f350a50cb_Uniform: 0
- Vector1_20d0d38d_52d0_4444_8ef4_da01a311590e_Uniform: 0.05
- Vector1_36d8f7c7_3ada_4604_9149_df2ba1745b80_Uniform: 8
- Vector1_48a064e9_29c4_4cdd_8bf7_34902bb50605_Uniform: 3
- Vector1_681e693a_7812_42ab_a37b_8a1edc00d63e_Uniform: 0.005
- Vector1_bc1392c9_f4d7_47a8_8add_f4f4b00fdfe5_Uniform: 0
- _BumpScale: 1
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1
- _Metallic: 0
- _Mode: 0
- _OcclusionStrength: 1
- _Parallax: 0.02
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _UVSec: 0
- _ZWrite: 1
m_Colors:
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- Vector1_a2ac4923_bc39_4a5c_924e_e77bd500d4f3_Uniform: 1
m_Colors: []

2
MaterialGraphProject/Assets/Andre/Nodes/ToggleNode.cs


public class ToggleNode : PropertyNode, IGeneratesBodyCode
{
[SerializeField]
private float m_Float;
//private float m_Float;
private bool m_ToggleState;
private const int kOutputSlotId = 0;

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

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

54
MaterialGraphProject/Assets/Eduardo/FunctionNInNOut.cs


else
nextSlotId = GetInputSlots<MaterialSlot>().Count() + 1;
bool useDefaultValue = (valueType != SlotValueType.sampler2D);
bool useDefaultValue = (valueType != SlotValueType.Texture2D);
AddSlot(new MaterialSlot(nextSlotId, displayName, nameInShader, slotType, valueType, defaultValue, useDefaultValue));
return nextSlotId;
}

public string GetSlotTypeName(int slotId)
{
return ConvertConcreteSlotValueTypeToString(FindSlot<MaterialSlot>(slotId).concreteValueType);
}
public ConcreteSlotValueType GetSlotValueType(int slotId)
{
return FindSlot<MaterialSlot>(slotId).concreteValueType;
}
protected string GetShaderOutputName(int slotId)

if (inSlot.isOutputSlot)
param += "out ";
if (FindSlot<MaterialSlot>(inSlot.id).concreteValueType != ConcreteSlotValueType.sampler2D)
if (FindSlot<MaterialSlot>(inSlot.id).concreteValueType != ConcreteSlotValueType.Texture2D
&& FindSlot<MaterialSlot>(inSlot.id).concreteValueType != ConcreteSlotValueType.SamplerState
)
param += precision;
param += GetSlotTypeName(inSlot.id) + " ";
param += GetShaderOutputName(inSlot.id);

int remainingParams = GetSlots<ISlot>().Count();
foreach (ISlot inSlot in GetSlots<ISlot>())
{
param += GetSlotValue(inSlot.id, generationMode);
if (FindSlot<MaterialSlot>(inSlot.id).concreteValueType == ConcreteSlotValueType.SamplerState)
param += GetSamplerInput(inSlot.id);
else
param += GetSlotValue(inSlot.id, generationMode);
if (remainingParams > 1)
param += ", ";

private string GetFunctionCall(GenerationMode generationMode)
{
return GetFunctionName() +
string prefix = "";
string sufix = "";
foreach (ISlot slot in GetInputSlots<MaterialSlot>())
{
if (GetSlotValueType(slot.id) == ConcreteSlotValueType.Texture2D || GetSlotValueType(slot.id) == ConcreteSlotValueType.SamplerState)
{
prefix = "#ifdef UNITY_COMPILER_HLSL \n";
sufix = "\n #endif";
}
}
return prefix + GetFunctionName() +
");";
");" + sufix;
}
private string GetOutputDeclaration()

outputString.AddShaderChunk(GetFunctionCall(generationMode), false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
}
public string GetSamplerInput(int slotID)
{
//default sampler if no input is provided
var samplerName = "my_linear_repeat_sampler";
//Sampler input slot
var samplerSlot = FindInputSlot<MaterialSlot>(slotID);
if (samplerSlot != null)
{
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);
}
}
return samplerName;
}
}
}

26
MaterialGraphProject/Assets/Eduardo/HeightToNormalNode.cs


namespace UnityEngine.MaterialGraph
{
[Title("Utility/Heightmap To Normalmap")]
public class HeightToNormalNode : FunctionNInNOut, IGeneratesFunction
public class HeightToNormalNode : FunctionNInNOut, IGeneratesFunction, IGenerateProperties
AddSlot("HeightMap", "heightmap", Graphing.SlotType.Input, SlotValueType.sampler2D, Vector4.zero);
AddSlot("HeightMap", "heightmap", Graphing.SlotType.Input, SlotValueType.Texture2D, Vector4.zero);
AddSlot("UV", "texCoord", Graphing.SlotType.Input, SlotValueType.Vector2, Vector4.zero);
AddSlot("Offset", "texOffset", Graphing.SlotType.Input, SlotValueType.Vector1, new Vector4(0.005f, 0,0,0));
AddSlot("Strength", "strength", Graphing.SlotType.Input, SlotValueType.Vector1, new Vector4(8,0,0,0));

get { return true; }
}
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)
{
base.GeneratePropertyUsages(visitor, generationMode);
visitor.AddShaderChunk("#ifdef UNITY_COMPILER_HLSL", false);
visitor.AddShaderChunk("SamplerState my_linear_repeat_sampler;", false);
visitor.AddShaderChunk("#endif", false);
}
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)
{
var outputString = new ShaderGenerator();

outputString.AddShaderChunk("float2 offsetV = float2(texCoord.x, texCoord.y + texOffset);", false);
outputString.AddShaderChunk("float normalSample = tex2D(heightmap, texCoord).r;", false);
outputString.AddShaderChunk("float uSample = tex2D(heightmap, offsetU).r;", false);
outputString.AddShaderChunk("float vSample = tex2D(heightmap, offsetV).r;", false);
outputString.AddShaderChunk("float normalSample = 0;", false);
outputString.AddShaderChunk("float uSample = 0;", false);
outputString.AddShaderChunk("float vSample = 0;", false);
visitor.AddShaderChunk("#ifdef UNITY_COMPILER_HLSL", false);
outputString.AddShaderChunk("normalSample = heightmap.Sample(my_linear_repeat_sampler, texCoord).r;", false);
outputString.AddShaderChunk("uSample = heightmap.Sample(my_linear_repeat_sampler, offsetU).r;", false);
outputString.AddShaderChunk("vSample = heightmap.Sample(my_linear_repeat_sampler, offsetV).r;", false);
visitor.AddShaderChunk("#endif", false);
outputString.AddShaderChunk("float uMinusNormal = uSample - normalSample;", false);
outputString.AddShaderChunk("float vMinusNormal = vSample - normalSample;", false);

127
MaterialGraphProject/Assets/GeneratedShader.shader


Shader "Hidden/PreviewShader/Posterize_f232fbec_5ce8_4ba5_8491_a7a66291d45f_Output" {
Properties {
Vector1_20d0d38d_52d0_4444_8ef4_da01a311590e_Uniform("", Float) = 0.1
Shader "Graph/Generated.MetallicMasterNode554b91b5-7a00-4f5f-b71a-f7729fcbdee8"
{
Properties
{
[NonModifiableTextureData] TextureAsset_8f4a8771_6c8f_4107_9c0b_83da34d57a9b_Uniform("TextureAsset", 2D) = "white" {}
SubShader {
// inside SubShader
SubShader
{
"Queue"="Geometry"
"IgnoreProjector"="True"
"Queue"="Geometry"
// inside Pass
Blend One Zero
Cull Back
ZTest LEqual
Blend One Zero
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
LOD 200
CGPROGRAM
#pragma target 3.0
#pragma surface surf Standard vertex:vert
#pragma glsl
#pragma debug
float3 ReflectionProbe_4f8cb744_19c5_4a6e_9bc1_172200f2fa25_normalDir;
float Vector1_20d0d38d_52d0_4444_8ef4_da01a311590e_Uniform;
#ifdef UNITY_COMPILER_HLSL
Texture2D TextureAsset_8f4a8771_6c8f_4107_9c0b_83da34d57a9b_Uniform;
#endif
float HeightToNormal_81cdd9a9_500d_41e2_9771_df274a2363bd_texOffset;
float HeightToNormal_81cdd9a9_500d_41e2_9771_df274a2363bd_strength;
#ifdef UNITY_COMPILER_HLSL
SamplerState my_linear_repeat_sampler;
#endif
#ifdef UNITY_COMPILER_HLSL
#endif
inline void unity_HeightToNormal (Texture2D heightmap, float2 texCoord, float texOffset, float strength, out float3 normalRes)
{
float2 offsetU = float2(texCoord.x + texOffset, texCoord.y);
float2 offsetV = float2(texCoord.x, texCoord.y + texOffset);
float normalSample = 0;
float uSample = 0;
float vSample = 0;
normalSample = heightmap.Sample(my_linear_repeat_sampler, texCoord).r;
uSample = heightmap.Sample(my_linear_repeat_sampler, offsetU).r;
vSample = heightmap.Sample(my_linear_repeat_sampler, offsetV).r;
float uMinusNormal = uSample - normalSample;
float vMinusNormal = vSample - normalSample;
uMinusNormal = uMinusNormal * strength;
vMinusNormal = vMinusNormal * strength;
float3 va = float3(1, 0, uMinusNormal);
float3 vb = float3(0, 1, vMinusNormal);
normalRes = cross(va, vb);
}
struct v2f
{
float4 pos : SV_POSITION;
float4 color : COLOR;
float3 worldNormal : TEXCOORD1;
};
struct Input
{
float4 color : COLOR;
half4 meshUV0;
inline float unity_posterize_float (float input, float stepsize)
{
return floor(input / stepsize) * stepsize;
}
};
void vert (inout appdata_full v, out Input o)
{
UNITY_INITIALIZE_OUTPUT(Input,o);
o.meshUV0 = v.texcoord;
v2f vert (appdata_full v)
{
v2f o = (v2f)0;
o.pos = UnityObjectToClipPos(v.vertex);;
float3 worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
float3 viewDir = UnityWorldSpaceViewDir(worldPos);
float4 screenPos = ComputeScreenPos(UnityObjectToClipPos(v.vertex));
float3 worldNormal = UnityObjectToWorldNormal(v.normal);
o.worldNormal = worldNormal;
}
void surf (Input IN, inout SurfaceOutputStandard o)
{
half4 uv0 = IN.meshUV0;
float4 UV_de8d7b89_7b50_499d_aa73_0f2a725356e6_UV = uv0;
float3 HeightToNormal_81cdd9a9_500d_41e2_9771_df274a2363bd_normalRes;
#ifdef UNITY_COMPILER_HLSL
unity_HeightToNormal (TextureAsset_8f4a8771_6c8f_4107_9c0b_83da34d57a9b_Uniform, UV_de8d7b89_7b50_499d_aa73_0f2a725356e6_UV, HeightToNormal_81cdd9a9_500d_41e2_9771_df274a2363bd_texOffset, HeightToNormal_81cdd9a9_500d_41e2_9771_df274a2363bd_strength, HeightToNormal_81cdd9a9_500d_41e2_9771_df274a2363bd_normalRes);
#endif
o.Normal = HeightToNormal_81cdd9a9_500d_41e2_9771_df274a2363bd_normalRes;
o.Normal += 1e-6;
return o;
}
}
ENDCG
}
half4 frag (v2f IN) : COLOR
{
float3 worldSpaceNormal = normalize(IN.worldNormal);
float3 ReflectionProbe_4f8cb744_19c5_4a6e_9bc1_172200f2fa25 = ShadeSH9(float4(worldSpaceNormal.xyz , 1));
float4 Split_f630c862_c9a4_4765_b085_f9b01dd46061 = float4(ReflectionProbe_4f8cb744_19c5_4a6e_9bc1_172200f2fa25, 1.0);
float Posterize_f232fbec_5ce8_4ba5_8491_a7a66291d45f_Output = unity_posterize_float (Split_f630c862_c9a4_4765_b085_f9b01dd46061.r, Vector1_20d0d38d_52d0_4444_8ef4_da01a311590e_Uniform);
return half4(Posterize_f232fbec_5ce8_4ba5_8491_a7a66291d45f_Output, Posterize_f232fbec_5ce8_4ba5_8491_a7a66291d45f_Output, Posterize_f232fbec_5ce8_4ba5_8491_a7a66291d45f_Output, 1.0);
}
ENDCG
}
}
Fallback Off
}
FallBack "Diffuse"
CustomEditor "LegacyIlluminShaderGUI"
}

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

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

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


protected virtual MaterialSlot GetTextureSlot()
{
return new MaterialSlot(TextureSlotId, GetTextureSlotName(), kTextureSlotShaderName, SlotType.Input, SlotValueType.sampler2D, Vector4.zero);
return new MaterialSlot(TextureSlotId, GetTextureSlotName(), kTextureSlotShaderName, SlotType.Input, SlotValueType.Texture2D, Vector4.zero);
}
protected virtual MaterialSlot GetOutputSlot()

5
MaterialGraphProject/Assets/TestAssets/Materials/Default.mat


m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: Default
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
m_Shader: {fileID: 4800000, guid: 9ab5e16c2083a4fe689209a8c1ae425e, type: 3}
m_LightmapFlags: 4
m_LightmapFlags: 0
m_EnableInstancingVariants: 0
m_CustomRenderQueue: -1
stringTagMap: {}

m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- Vector1_a2ac4923_bc39_4a5c_924e_e77bd500d4f3_Uniform: 1
- _BumpScale: 1
- _Cutoff: 0.5
- _DetailNormalMapScale: 1

2
MaterialGraphProject/Assets/TestAssets/Teapot.fbx.meta


useFileScale: 1
tangentSpace:
normalSmoothAngle: 60
normalImportMode: 0
normalImportMode: 1
tangentImportMode: 3
normalCalculationMode: 4
importAnimation: 1

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


typeMapper[typeof(GradientNode)] = typeof(GradientNodePresenter);
typeMapper[typeof(ScatterNode)] = typeof(ScatterNodePresenter);
typeMapper[typeof(TextureNode)] = typeof(TextureNodePresenter);
typeMapper[typeof(TextureSamplerNode)] = typeof(TextureSamplerNodePresenter);
typeMapper[typeof(TextureAssetNode)] = typeof(TextureAssetNodePresenter);
typeMapper[typeof(TextureLODNode)] = typeof(TextureLODNodePresenter);
typeMapper[typeof(CubemapNode)] = typeof(CubeNodePresenter);

typeMapper[typeof(Matrix4Node)] = typeof(Matrix4NodePresenter);
typeMapper[typeof(MatrixCommonNode)] = typeof(MatrixCommonNodePresenter);
typeMapper[typeof(TransformNode)] = typeof(TransformNodePresenter);
typeMapper[typeof(ConvolutionFilterNode)] = typeof(ConvolutionFilterNodePresenter);
}
public override List<NodeAnchorPresenter> GetCompatibleAnchors(NodeAnchorPresenter startAnchor, NodeAdapter nodeAdapter)

17
MaterialGraphProject/Assets/UnityShaderEditor/Editor/HelperShader.shader


Shader "Graph/UnityEngine.MaterialGraph.MetallicMasterNode0dd415f6-2593-4617-b37c-c9d9dd315a4c"
Shader "Graph/UnityEngine.MaterialGraph.MetallicMasterNode68c240e8-1bfd-46d4-86b7-3459bc630675"
Vector1_20d0d38d_52d0_4444_8ef4_da01a311590e_Uniform("", Float) = 0.1
}

#pragma glsl
#pragma debug
inline float unity_posterize_float (float input, float stepsize)
{
return floor(input / stepsize) * stepsize;
}
float Vector1_20d0d38d_52d0_4444_8ef4_da01a311590e_Uniform;
float3 worldNormal;
};

void surf (Input IN, inout SurfaceOutputStandard o)
{
float3 worldSpaceNormal = normalize(IN.worldNormal);
float3 ReflectionProbe_4f8cb744_19c5_4a6e_9bc1_172200f2fa25 = ShadeSH9(float4(worldSpaceNormal.xyz , 1));
float4 Split_f630c862_c9a4_4765_b085_f9b01dd46061 = float4(ReflectionProbe_4f8cb744_19c5_4a6e_9bc1_172200f2fa25, 1.0);
float Posterize_f232fbec_5ce8_4ba5_8491_a7a66291d45f_Output = unity_posterize_float (Split_f630c862_c9a4_4765_b085_f9b01dd46061.r, Vector1_20d0d38d_52d0_4444_8ef4_da01a311590e_Uniform);
float Posterize_3187d243_6c53_430c_9d5e_fa7a1561872c_Output = unity_posterize_float (Split_f630c862_c9a4_4765_b085_f9b01dd46061.g, Vector1_20d0d38d_52d0_4444_8ef4_da01a311590e_Uniform);
float Posterize_c83cc006_d2b4_4a06_8f45_52c85f6e2a73_Output = unity_posterize_float (Split_f630c862_c9a4_4765_b085_f9b01dd46061.b, Vector1_20d0d38d_52d0_4444_8ef4_da01a311590e_Uniform);
float4 Combine_2e6d43a4_be04_453e_a0f2_a0520f41fea5_Output = float4(Posterize_f232fbec_5ce8_4ba5_8491_a7a66291d45f_Output,Posterize_3187d243_6c53_430c_9d5e_fa7a1561872c_Output,Posterize_c83cc006_d2b4_4a06_8f45_52c85f6e2a73_Output,0.0);
o.Emission = Combine_2e6d43a4_be04_453e_a0f2_a0520f41fea5_Output;
}
ENDCG

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/HelperShader.shader.meta


fileFormatVersion: 2
guid: 9ab5e16c2083a4fe689209a8c1ae425e
timeCreated: 1495643268
timeCreated: 1495720140
licenseType: Pro
ShaderImporter:
defaultTextures: []

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Templates/subshader.template


#pragma glsl
#pragma debug
${ShaderPropertyUsages}
${ShaderPropertyUsages}
struct Input
{

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


if (edges.Any())
continue;
inputSlot.GeneratePropertyUsages(visitor, generationMode);
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);
}
}

return ConcreteSlotValueType.Vector3;
case SlotValueType.Vector4:
return ConcreteSlotValueType.Vector4;
case SlotValueType.sampler2D:
return ConcreteSlotValueType.sampler2D;
case SlotValueType.Texture2D:
return ConcreteSlotValueType.Texture2D;
case SlotValueType.Matrix2:
return ConcreteSlotValueType.Matrix2;
case SlotValueType.Matrix3:

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

return "3";
case ConcreteSlotValueType.Vector4:
return "4";
case ConcreteSlotValueType.sampler2D:
return "sampler2D";
case ConcreteSlotValueType.Texture2D:
return "Texture2D";
case ConcreteSlotValueType.Matrix2:
return "2x2";
case ConcreteSlotValueType.Matrix3:

case ConcreteSlotValueType.SamplerState:
return "SamplerState";
default:
return "Error";
}

{
switch (slotValue)
{
case ConcreteSlotValueType.sampler2D:
case ConcreteSlotValueType.Texture2D:
return PropertyType.Texture;
case ConcreteSlotValueType.Vector1:
return PropertyType.Float;

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

6
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Function2Input.cs


+ precision + input2Dimension + " " + arg2Name + ")";
}
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
public virtual void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
{
NodeUtils.SlotConfigurationExceptionIfBadConfiguration(this, new[] { InputSlot1Id, InputSlot2Id }, new[] { OutputSlotId });
string input1Value = GetSlotValue(InputSlot1Id, generationMode);

get { return ConvertConcreteSlotValueTypeToString(FindOutputSlot<MaterialSlot>(OutputSlotId).concreteValueType); }
}
private string input1Dimension
protected string input1Dimension
private string input2Dimension
protected string input2Dimension
{
get { return ConvertConcreteSlotValueTypeToString(FindInputSlot<MaterialSlot>(InputSlot2Id).concreteValueType); }
}

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


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

3
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/PropertyType.cs


Vector4,
Matrix2,
Matrix3,
Matrix4
Matrix4,
SamplerState
}
}

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


[Serializable]
public enum SlotValueType
{
SamplerState,
sampler2D,
Texture2D,
Dynamic,
Vector4,
Vector3,

public enum ConcreteSlotValueType
{
SamplerState = 9,
sampler2D = 5,
Texture2D = 5,
Vector4 = 4,
Vector3 = 3,
Vector2 = 2,

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


foreach (var node in activeNodeList.OfType<AbstractMaterialNode>())
{
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);
nodeFunction.AddShaderChunk(sufix, false);
}
node.GeneratePropertyUsages(propertyUsages, mode);
}

8
MaterialGraphProject/Assets/Vlad/TextureAssetNode.cs


public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(OutputSlotRgbaId, kOutputSlotRGBAName, kOutputSlotRGBAName, SlotType.Output, SlotValueType.sampler2D, Vector4.zero, false));
AddSlot(new MaterialSlot(OutputSlotRgbaId, kOutputSlotRGBAName, kOutputSlotRGBAName, SlotType.Output, SlotValueType.Texture2D, Vector4.zero, false));
RemoveSlotsNameNotMatching(validSlots);
}

public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)
{
visitor.AddShaderChunk("sampler2D " + propertyName + ";", true);
visitor.AddShaderChunk("#ifdef UNITY_COMPILER_HLSL", true);
visitor.AddShaderChunk("Texture2D " + propertyName + ";", true);
visitor.AddShaderChunk("#endif", true);
public override PreviewProperty GetPreviewProperty()

122
MaterialGraphProject/Assets/Vlad/UVTriPlanar.cs


namespace UnityEngine.MaterialGraph
{
[Title("UV/Tri-Planar Mapping")]
public class UVTriPlanar : Function3Input, IGeneratesFunction, IMayRequireNormal, IMayRequireWorldPosition
public class UVTriPlanar : FunctionNInNOut, IGeneratesFunction, IMayRequireNormal, IMayRequireWorldPosition
private int slot0, slot1, slot2, slot3, slot4, slot5, slot6 = 0;
private const string kTextureSlotName = "Texture";
private const string kTileSlotName = "Tile";
private const string kBlendSlotName = "Blend";
private string slot0Name = "texRef";
private string slot1Name = "tileFactor";
private string slot2Name = "blendFactor";
private string slot3Name = "samplerRef";
private string slot4Name = "normalRef";
private string slot5Name = "posRef";
private string slot6Name = "outputRef";
protected override string GetFunctionName()
{

protected override MaterialSlot GetInputSlot1()
public UVTriPlanar()
return new MaterialSlot(InputSlot1Id, kTextureSlotName, kTextureSlotName, SlotType.Input, SlotValueType.sampler2D, Vector4.zero, false);
}
name = "UVTriPlanar";
protected override MaterialSlot GetInputSlot2()
{
return new MaterialSlot(InputSlot2Id, kTileSlotName, kTileSlotName, SlotType.Input, SlotValueType.Vector1, Vector4.one);
}
slot0 = AddSlot("Texture", slot0Name, Graphing.SlotType.Input, SlotValueType.Texture2D, Vector4.zero);
slot1 = AddSlot("Tile", slot1Name, Graphing.SlotType.Input, SlotValueType.Vector1, Vector4.zero);
slot2 = AddSlot("Blend", slot2Name, Graphing.SlotType.Input, SlotValueType.Vector1, Vector4.zero);
slot3 = AddSlot("Sampler", slot3Name, Graphing.SlotType.Input, SlotValueType.SamplerState, Vector4.zero);
slot4 = AddSlot("Normals", slot4Name, Graphing.SlotType.Input, SlotValueType.Vector3, Vector3.one);
slot5 = AddSlot("Position", slot5Name, Graphing.SlotType.Input, SlotValueType.Vector3, Vector3.one);
slot6 = AddSlot("RGBA ", slot6Name, Graphing.SlotType.Output, SlotValueType.Vector4, Vector4.zero);
protected override MaterialSlot GetInputSlot3()
{
return new MaterialSlot(InputSlot3Id, kBlendSlotName, kBlendSlotName, SlotType.Input, SlotValueType.Vector1, Vector4.one);
}
protected override MaterialSlot GetOutputSlot()
{
return new MaterialSlot(OutputSlotId, kTextureSlotName, kOutputSlotShaderName, SlotType.Output, SlotValueType.Vector4, Vector4.zero);
}
public UVTriPlanar()
{
name = "UVTriPlanar";
UpdateNodeAfterDeserialization();
}

}
}
protected override string GetFunctionPrototype(string arg1Name, string arg2Name, string arg3Name)
{
return "inline " + precision + outputDimension + " " + GetFunctionName() + " ("
+ "sampler2D " + arg1Name + ", "
+ precision + " " + arg2Name + ", "
+ precision + " " + arg3Name +
", float3 normal, float3 pos)";
}
protected override string GetFunctionCallBody(string input1Value, string input2Value, string input3Value)
{
return GetFunctionName() + " (" + input1Value + ", " + input2Value + ", " + input3Value + ", IN.worldNormal, IN.worldPos)";
}
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)
{
base.GeneratePropertyUsages(visitor, generationMode);
}
//TODO:Externalize
//Reference code from:http://www.chilliant.com/rgb2hsv.html

var textureSlot = FindInputSlot<MaterialSlot>(InputSlot1Id);
if (textureSlot == null)
return;
var textureName = "";
//Sampler input
var samplerName = GetSamplerInput(3);
outputString.AddShaderChunk("#ifdef UNITY_COMPILER_HLSL", false);
var edges = owner.GetEdges(textureSlot.slotReference).ToList();
if (edges.Count > 0)
{
var edge = edges[0];
var fromNode = owner.GetNodeFromGuid<AbstractMaterialNode>(edge.outputSlot.nodeGuid);
textureName = ShaderGenerator.AdaptNodeOutput(fromNode, edge.outputSlot.slotId, ConcreteSlotValueType.sampler2D, true);
}
outputString.AddShaderChunk(GetFunctionPrototype("arg1", "arg2", "arg3"), false);
// outputString.AddShaderChunk(GetFunctionPrototype("arg1", "arg2", "arg3", samplerName), false);
outputString.AddShaderChunk(GetFunctionPrototype(), false);
outputString.Indent();
outputString.Indent();
outputString.AddShaderChunk("fixed3 uvs = pos * arg2;", false);
outputString.AddShaderChunk("float3 uvs = " + slot5Name + "*" + slot1Name + ";", false);
outputString.AddShaderChunk("half3 blend = pow(abs(normal), arg3);", false);
outputString.AddShaderChunk("half3 blend = pow(abs(" + slot4Name + ")," + slot2Name + ");", false);
outputString.AddShaderChunk("fixed4 cx = tex2D(arg1, uvs.yz);", false);
outputString.AddShaderChunk("fixed4 cy = tex2D(arg1, uvs.xz);", false);
outputString.AddShaderChunk("fixed4 cz = tex2D(arg1, uvs.xy);", false);
outputString.AddShaderChunk("float4 cx = " + slot0Name + ".Sample(" + slot3Name + ", uvs.yz);", false);
outputString.AddShaderChunk("float4 cy = " + slot0Name + ".Sample(" + slot3Name + ", uvs.xz);", false);
outputString.AddShaderChunk("float4 cz = " + slot0Name + ".Sample(" + slot3Name + ", uvs.xy);", false);
outputString.AddShaderChunk("fixed4 c = cx * blend.x + cy * blend.y + cz * blend.z;", false);
outputString.AddShaderChunk("return " + "c;", false);
outputString.AddShaderChunk(slot6Name + " = cx * blend.x + cy * blend.y + cz * blend.z;", false);
//outputString.AddShaderChunk("return " + "c;", false);
outputString.AddShaderChunk("#endif", true);
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)
{
//Sampler input slot
base.GeneratePropertyUsages(visitor, generationMode);
var samplerSlot = FindInputSlot<MaterialSlot>(slot3);
if (samplerSlot != null)
{
var samplerName = GetSamplerInput(slot3);
visitor.AddShaderChunk("#ifdef UNITY_COMPILER_HLSL", false);
visitor.AddShaderChunk("SamplerState " + samplerName + ";", true);
visitor.AddShaderChunk("#endif", false);
}
}
var slot = FindInputSlot<MaterialSlot>(InputSlot1Id);
var slot = FindInputSlot<MaterialSlot>(0);
if (slot == null)
return;

2
MaterialGraphProject/Assets/_MingWai/ScatterNode.cs


public ScatterNode()
{
name = "Scatter";
AddSlot("Texture", "inputTex", Graphing.SlotType.Input, SlotValueType.sampler2D, Vector4.zero);
AddSlot("Texture", "inputTex", Graphing.SlotType.Input, SlotValueType.Texture2D, Vector4.zero);
AddSlot("UV", "inputUV", Graphing.SlotType.Input, SlotValueType.Vector2, Vector2.one);
AddSlot("Seed", "seed", Graphing.SlotType.Input, SlotValueType.Vector2, Vector2.one);
AddSlot("PositionRange", "p_range", Graphing.SlotType.Input, SlotValueType.Vector2, Vector2.zero);

9
MaterialGraphProject/Assets/Florent.meta


fileFormatVersion: 2
guid: e9dab59e587c7f244adde1add29b34fc
folderAsset: yes
timeCreated: 1495531757
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

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

9
MaterialGraphProject/Assets/Matt/Examples/Anisotropy.ShaderGraph.meta


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

81
MaterialGraphProject/Assets/Matt/Examples/Anisotropy.mat


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: Anisotropy
m_Shader: {fileID: 4800000, guid: 9ab5e16c2083a4fe689209a8c1ae425e, type: 3}
m_ShaderKeywords:
m_LightmapFlags: 0
m_EnableInstancingVariants: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- Texture_3db1140f_b814_4ba5_a49c_d40499367921_Uniform:
m_Texture: {fileID: 2800000, guid: cbf25f5368b2350408963109a1c8f22d, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- Vector1_3c037cd0_a4ae_48b0_8e8c_e1507ff6f738_Uniform: 1
- Vector1_da8ece50_8bc4_4e14_b77a_24dfc74c32da_Uniform: 0.817
- _BumpScale: 1
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1
- _Metallic: 0
- _Mode: 0
- _OcclusionStrength: 1
- _Parallax: 0.02
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _UVSec: 0
- _ZWrite: 1
m_Colors:
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}

9
MaterialGraphProject/Assets/Matt/Examples/Anisotropy.mat.meta


fileFormatVersion: 2
guid: b691b84f941db2740ba393773c55e10e
timeCreated: 1495722255
licenseType: Pro
NativeFormatImporter:
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:

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

9
MaterialGraphProject/Assets/Matt/Examples/Grain.ShaderGraph.meta


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

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


using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
[Title("UV/ParallaxOcclusionMapping")]
public class ParallaxOcclusionMappingNode :
AbstractMaterialNode,
IGeneratesBodyCode,
IGeneratesFunction,
IMayRequireMeshUV,
IMayRequireViewDirection,
IMayRequireNormal,
IMayRequireViewDirectionTangentSpace
{
protected const string kInputHeightScaleShaderName = "HeightScale";
protected const string kTextureSlotShaderName = "Texture";
protected const string kOutputSlotShaderName = "UV";
public const int HeightScaleSlotId = 0; // 'height_scale'
public const int TextureSlotId = 1; // 'tex'
public const int OutputSlotId = 2;
public override bool hasPreview
{
get { return true; }
}
public override PreviewMode previewMode
{
get
{
return PreviewMode.Preview3D;
}
}
public ParallaxOcclusionMappingNode()
{
name = "ParallaxOcclusionMapping";
UpdateNodeAfterDeserialization();
}
public string GetFunctionName()
{
return "unity_parallax_occlusion_mapping_" + precision;
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(GetInputHeightScaleSlot());
AddSlot(GetTextureSlot());
AddSlot(GetOutputSlot());
RemoveSlotsNameNotMatching(validSlots);
}
protected int[] validSlots
{
get { return new[] { HeightScaleSlotId, TextureSlotId, OutputSlotId }; }
}
protected virtual string GetInputHeightScaleName()
{
return kInputHeightScaleShaderName;
}
protected virtual MaterialSlot GetInputHeightScaleSlot()
{
return new MaterialSlot(
HeightScaleSlotId, GetInputHeightScaleName(), kInputHeightScaleShaderName, SlotType.Input, SlotValueType.Vector1, Vector4.zero);
}
protected virtual MaterialSlot GetTextureSlot()
{
return new MaterialSlot(TextureSlotId, GetTextureSlotName(), kTextureSlotShaderName, SlotType.Input, SlotValueType.Texture2D, Vector4.zero);
}
protected virtual MaterialSlot GetOutputSlot()
{
return new MaterialSlot(OutputSlotId, GetOutputSlotName(), kOutputSlotShaderName, SlotType.Output, SlotValueType.Vector2, Vector4.zero);
}
protected virtual string GetTextureSlotName()
{
return kTextureSlotShaderName;
}
protected virtual string GetOutputSlotName()
{
return kOutputSlotShaderName;
}
private string inputHeightScaleDimension
{
get { return ConvertConcreteSlotValueTypeToString(FindInputSlot<MaterialSlot>(HeightScaleSlotId).concreteValueType); }
}
protected virtual string GetFunctionPrototype(
string heightScale, string tex, string UVs, string viewTangentSpace, string worldSpaceNormal, string worldSpaceViewDirection)
{
return "inline " + precision + "2 " + GetFunctionName() + " (" +
precision + inputHeightScaleDimension + " " + heightScale + ", " +
"sampler2D " + tex + ", " +
precision + "2 " + UVs + ", " +
precision + "3 " + viewTangentSpace + ", " +
precision + "3 " + worldSpaceNormal + ", " +
precision + "3 " + worldSpaceViewDirection + ")";
}
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
{
NodeUtils.SlotConfigurationExceptionIfBadConfiguration(
this,
new[] { HeightScaleSlotId, TextureSlotId },
new[] { OutputSlotId });
string heightScaleValue = GetSlotValue(HeightScaleSlotId, generationMode);
string textureValue = GetSlotValue(TextureSlotId, generationMode);
visitor.AddShaderChunk(precision + "2 " + GetVariableNameForSlot(OutputSlotId) + " = " +
GetFunctionCallBody(heightScaleValue, textureValue) + ";", true);
}
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)
{
var outputString = new ShaderGenerator();
outputString.AddShaderChunk(
GetFunctionPrototype("heightScale", "tex", "UVs", "viewTangentSpace", "worldSpaceNormal", "worldSpaceViewDirection" ),
false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk(precision + "2 " + "height_map_dimensions = " + precision + "2" + "(256.0f, 256.0f); //HARDCODE", false);
//height_map.tex.GetDimensions(height_map_dimensions.x, height_map_dimensions.y);
outputString.AddShaderChunk(precision + "2 texcoord= UVs;", false);
// Compute the current gradients:
outputString.AddShaderChunk(precision + "2 " + " texcoords_per_size = texcoord * height_map_dimensions;", false);
// Compute all 4 derivatives in x and y in a single instruction to optimize:
outputString.AddShaderChunk("float2 dx, dy;", false);
outputString.AddShaderChunk(" float4 temp_ddx = ddx(float4(texcoords_per_size, texcoord));", false);
outputString.AddShaderChunk("dx.xy = temp_ddx.zw;", false);
outputString.AddShaderChunk("float4 temp_ddy = ddy(float4(texcoords_per_size, texcoord));", false);
outputString.AddShaderChunk("dy.xy = temp_ddy.zw;", false);
// Start the current sample located at the input texture coordinate, which would correspond
// to computing a bump mapping result:
outputString.AddShaderChunk(precision + "2 " + "result_texcoord = texcoord;", false);
outputString.AddShaderChunk("float height_scale_value = heightScale;", false);
outputString.AddShaderChunk("float height_scale_adjust = height_scale_value;", false);
outputString.AddShaderChunk("float per_pixel_height_scale_value = height_scale_value * heightScale;", false);
// Parallax occlusion mapping offset computation
//--------------
// Utilize dynamic flow control to change the number of samples per ray
// depending on the viewing angle for the surface. Oblique angles require
// smaller step sizes to achieve more accurate precision for computing displacement.
// We express the sampling rate as a linear function of the angle between
// the geometric normal and the view direction ray:
outputString.AddShaderChunk("float max_samples = 30.0f;", false);
outputString.AddShaderChunk("float min_samples = 4.0f;", false);
outputString.AddShaderChunk("float view_dot_normal= dot(worldSpaceNormal, worldSpaceViewDirection);", false);
outputString.AddShaderChunk("int number_of_steps = (int)lerp(max_samples, min_samples, saturate(view_dot_normal));", false);
// Intersect the view ray with the height field profile along the direction of
// the parallax offset ray (computed in the vertex shader. Note that the code is
// designed specifically to take advantage of the dynamic flow control constructs
// in HLSL and is very sensitive to specific syntax. When converting to other examples,
// if still want to use dynamic flow control in the resulting assembly shader,
// care must be applied.
//
// In the below steps we approximate the height field profile as piecewise linear
// curve. We find the pair of endpoints between which the intersection between the
// height field profile and the view ray is found and then compute line segment
// intersection for the view ray and the line segment formed by the two endpoints.
// This intersection is the displacement offset from the original texture coordinate.
// See the above SI3D 06 paper for more details about the process and derivation.
//
outputString.AddShaderChunk("float current_height = 0.0;", false);
outputString.AddShaderChunk("float step_size = 1.0 / (float)number_of_steps;", false);
outputString.AddShaderChunk("float previous_height = 1.0;", false);
outputString.AddShaderChunk("float next_height = 0.0;", false);
outputString.AddShaderChunk("int step_index = 0;", false);
// Optimization: this should move to vertex shader, however, we compute it here for simplicity of
// integration into our shaders for now.
outputString.AddShaderChunk("float3 normalized_view_dir_in_tangent_space = normalize(viewTangentSpace.xyz);", false);
// Compute initial parallax displacement direction:
outputString.AddShaderChunk("float2 parallax_direction = normalize(viewTangentSpace.xy);", false);
// The length of this vector determines the furthest amount of displacement:
outputString.AddShaderChunk("float parallax_direction_length = length(normalized_view_dir_in_tangent_space);", false);
outputString.AddShaderChunk(
"float max_parallax_amount = sqrt(parallax_direction_length * parallax_direction_length - viewTangentSpace.z * viewTangentSpace.z) / viewTangentSpace.z;", false);
// Compute the actual reverse parallax displacement vector:
outputString.AddShaderChunk("float2 parallax_offset_in_tangent_space = parallax_direction * max_parallax_amount;", false);
// Need to scale the amount of displacement to account for different height ranges
// in height maps. This is controlled by an artist-editable parameter:
outputString.AddShaderChunk("parallax_offset_in_tangent_space *= saturate(heightScale);", false);
outputString.AddShaderChunk("float2 texcoord_offset_per_step = step_size * parallax_offset_in_tangent_space;", false);
outputString.AddShaderChunk(precision + "2 " + "current_texcoord_offset = texcoord;", false);
outputString.AddShaderChunk("float current_bound = 1.0;", false);
outputString.AddShaderChunk("float current_parallax_amount = 0.0;", false);
outputString.AddShaderChunk("float2 pt1 = 0;", false);
outputString.AddShaderChunk("float2 pt2 = 0;", false);
outputString.AddShaderChunk(precision + "2 " + "temp_texcoord_offset = 0;", false);
outputString.AddShaderChunk("while (step_index < number_of_steps)", false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("current_texcoord_offset -= texcoord_offset_per_step;", false);
// Sample height map which in this case is stored in the alpha channel of the normal map:
outputString.AddShaderChunk("current_height = tex2Dgrad(tex, current_texcoord_offset, dx, dy).r;", false);
outputString.AddShaderChunk("current_bound -= step_size;", false);
outputString.AddShaderChunk("if (current_height > current_bound)", false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("pt1 = float2(current_bound, current_height);", false);
outputString.AddShaderChunk("pt2 = float2(current_bound + step_size, previous_height);", false);
outputString.AddShaderChunk("temp_texcoord_offset = current_texcoord_offset - texcoord_offset_per_step;", false);
outputString.AddShaderChunk("step_index = number_of_steps + 1;", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
outputString.AddShaderChunk("else", false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("step_index++;", false);
outputString.AddShaderChunk("previous_height = current_height;", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
outputString.Deindent();
outputString.AddShaderChunk("} // End of while ( step_index < number_of_steps)", false);
outputString.AddShaderChunk("float delta2 = pt2.x - pt2.y;", false);
outputString.AddShaderChunk("float delta1 = pt1.x - pt1.y;", false);
outputString.AddShaderChunk("float denominator = delta2 - delta1;", false);
// SM 3.0 and above requires a check for divide by zero since that operation
// will generate an 'Inf' number instead of 0
outputString.AddShaderChunk("if (denominator== 0.0f) ", false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("current_parallax_amount= 0.0f;", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
outputString.AddShaderChunk("else", false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("current_parallax_amount= (pt1.x* delta2 - pt2.x* delta1) / denominator;", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
outputString.AddShaderChunk("float2 parallax_offset = parallax_offset_in_tangent_space * (1.0f - current_parallax_amount);", false);
// The computed texture offset for the displaced point on the pseudo-extruded surface:
outputString.AddShaderChunk("float2 parallaxed_texcoord = texcoord - parallax_offset;", false);
outputString.AddShaderChunk("return parallaxed_texcoord;", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
}
protected virtual string GetFunctionCallBody(string heightScale, string texValue)
{
var channel = UVChannel.uv0;
return GetFunctionName() + " (" +
heightScale + ", " +
texValue + ", " +
channel.GetUVName() + ", " +
ShaderGeneratorNames.TangentSpaceViewDirection + ", " +
ShaderGeneratorNames.WorldSpaceNormal + ", " +
ShaderGeneratorNames.WorldSpaceViewDirection + ")";
}
public bool RequiresMeshUV(UVChannel channel)
{
return channel == UVChannel.uv0;
}
public bool RequiresViewDirectionTangentSpace()
{
return true;
}
public bool RequiresNormal()
{
return true;
}
public bool RequiresViewDirection()
{
return true;
}
}
}

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


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

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

9
MaterialGraphProject/Assets/POM_Graph.ShaderGraph.meta


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

21
MaterialGraphProject/Assets/TestAssets/TangentMap1.jpg

之前 之后
宽度: 187  |  高度: 187  |  大小: 6.5 KiB

75
MaterialGraphProject/Assets/TestAssets/TangentMap1.jpg.meta


fileFormatVersion: 2
guid: fd9dcc0042b460046917799942414fe0
timeCreated: 1495721640
licenseType: Pro
TextureImporter:
fileIDToRecycleName: {}
serializedVersion: 4
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: -1
aniso: -1
mipBias: -1
wrapU: -1
wrapV: -1
wrapW: -1
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spritePixelsToUnits: 100
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
platformSettings:
- buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
spritePackingTag:
userData:
assetBundleName:
assetBundleVariant:

33
MaterialGraphProject/Assets/TestAssets/TangentMap2.jpg

之前 之后
宽度: 187  |  高度: 187  |  大小: 8.7 KiB

75
MaterialGraphProject/Assets/TestAssets/TangentMap2.jpg.meta


fileFormatVersion: 2
guid: ff1fa8d5d8b0945499c7785f1b0f2a4f
timeCreated: 1495721640
licenseType: Pro
TextureImporter:
fileIDToRecycleName: {}
serializedVersion: 4
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: -1
aniso: -1
mipBias: -1
wrapU: -1
wrapV: -1
wrapW: -1
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spritePixelsToUnits: 100
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
platformSettings:
- buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
spritePackingTag:
userData:
assetBundleName:
assetBundleVariant:

12
MaterialGraphProject/Assets/TestAssets/TangentMap3.jpg

之前 之后
宽度: 187  |  高度: 187  |  大小: 4.4 KiB

75
MaterialGraphProject/Assets/TestAssets/TangentMap3.jpg.meta


fileFormatVersion: 2
guid: cbf25f5368b2350408963109a1c8f22d
timeCreated: 1495721640
licenseType: Pro
TextureImporter:
fileIDToRecycleName: {}
serializedVersion: 4
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: -1
aniso: -1
mipBias: -1
wrapU: -1
wrapV: -1
wrapW: -1
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spritePixelsToUnits: 100
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
platformSettings:
- buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
spritePackingTag:
userData:
assetBundleName:
assetBundleVariant:

151
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/ConvolutionFilterNodePresenter.cs


using System;
using System.Collections.Generic;
using RMGUI.GraphView;
using UnityEditor.Graphing.Drawing;
using UnityEngine.MaterialGraph;
using UnityEngine;
namespace UnityEditor.MaterialGraph.Drawing
{
class ConvolutionFilterControlPresenter : GraphControlPresenter
{
enum KernelPresets
{
Presets,
BoxBlur,
GaussianBlur,
EdgesDetection,
EnhanceEdges,
Sharpen,
Emboss,
};
private void ApplyPreset(KernelPresets preset, ref float[,] values, ref float divisor)
{
if (preset == KernelPresets.BoxBlur)
{
values = new float[,] { {1,1,1,1,1},
{1,1,1,1,1},
{1,1,1,1,1},
{1,1,1,1,1},
{1,1,1,1,1} };
divisor = 25;
}
if (preset == KernelPresets.GaussianBlur)
{
values = new float[,] { { 1, 4, 6, 4, 1},
{ 4,16,24,16, 4},
{ 6,24,36,24, 6},
{ 4,16,24,16, 4},
{ 1, 4, 6, 4, 1} };
divisor = 256;
}
if (preset == KernelPresets.EdgesDetection)
{
values = new float[,] { {-1,-1,-1, -1,-1},
{-1,-2,-2, -2,-1},
{-1,-2, 33,-2,-1},
{-1,-2,-2, -2,-1},
{-1,-1,-1, -1,-1} };
divisor = 1;
}
if (preset == KernelPresets.EnhanceEdges)
{
values = new float[,] { { 0, 0, 0, 0, 0},
{ 0, 1, 1, 1, 0},
{ 0, 1,-7, 1, 0},
{ 0, 1, 1, 1, 0},
{ 0, 0, 0, 0, 0} };
divisor = 1;
}
if (preset == KernelPresets.Sharpen)
{
values = new float[,] { {-1,-1,-1, -1,-1},
{-1, 2, 2, 2,-1},
{-1, 2, 8, 2,-1},
{-1, 2, 2, 2,-1},
{-1,-1,-1, -1,-1} };
divisor = 8;
}
if (preset == KernelPresets.Emboss)
{
values = new float[,] { {-1,-1,-1,-1, 0},
{-1,-1,-1, 0, 1},
{-1,-1, 0, 1, 1},
{-1, 0, 1, 1, 1},
{ 0, 1, 1, 1, 1} };
divisor = 1;
}
}
public override void OnGUIHandler()
{
base.OnGUIHandler();
var tNode = node as ConvolutionFilterNode;
if (tNode == null)
return;
float divisor = tNode.GetConvolutionDivisor();
float[,] values = new float[5,5];
for (int row = 0; row < 5; ++row)
{
for (int col = 0; col < 5; ++col)
{
values[row,col] = tNode.GetConvolutionWeight(row,col);
}
}
EditorGUILayout.BeginVertical();
EditorGUI.BeginChangeCheck();
EditorGUILayout.LabelField("Kernel");
KernelPresets kernelPresets = KernelPresets.Presets;
kernelPresets = (KernelPresets)EditorGUILayout.EnumPopup(kernelPresets);
ApplyPreset(kernelPresets, ref values, ref divisor);
for (int col = 0; col < 5; ++col)
{
EditorGUILayout.BeginHorizontal();
for (int row = 0; row < 5; ++row)
{
values[row, col] = EditorGUILayout.FloatField(values[row, col], GUILayout.Width(35));
}
EditorGUILayout.EndHorizontal();
}
EditorGUILayout.Space();
divisor = EditorGUILayout.FloatField("Divisor", divisor);
EditorGUILayout.EndVertical();
if (EditorGUI.EndChangeCheck())
{
tNode.SetConvolutionDivisor(divisor);
for (int row = 0; row < 5; ++row)
{
for (int col = 0; col < 5; ++col)
{
tNode.SetConvolutionWeight(row, col, values[row, col]);
}
}
}
}
public override float GetHeight()
{
return (EditorGUIUtility.singleLineHeight * 10 + EditorGUIUtility.standardVerticalSpacing) + EditorGUIUtility.standardVerticalSpacing;
}
}
[Serializable]
public class ConvolutionFilterNodePresenter : PropertyNodePresenter
{
protected override IEnumerable<GraphElementPresenter> GetControlData()
{
var instance = CreateInstance<ConvolutionFilterControlPresenter>();
instance.Initialize(node);
return new List<GraphElementPresenter>(base.GetControlData()) { instance };
}
}
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/ConvolutionFilterNodePresenter.cs.meta


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

64
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/SamplerStatePresenter.cs


using System;
using System.Collections.Generic;
using UnityEngine.MaterialGraph;
using RMGUI.GraphView;
using UnityEditor.Graphing.Drawing;
namespace UnityEditor.MaterialGraph.Drawing
{
[Serializable]
class SamplerStateControlPresenter : GraphControlPresenter
{
private string[] samplerFilterMode;
private string[] samplerWrapMode;
private string[] _samplerFilterMode
{
get
{
if (samplerFilterMode == null)
samplerFilterMode = Enum.GetNames(typeof(SamplerStateNode.FilterMode));
return samplerFilterMode;
}
}
private string[] _samplerWrapMode
{
get
{
if (samplerWrapMode == null)
samplerWrapMode = Enum.GetNames(typeof(SamplerStateNode.WrapMode));
return samplerWrapMode;
}
}
public override void OnGUIHandler()
{
base.OnGUIHandler();
var cNode = node as UnityEngine.MaterialGraph.SamplerStateNode;
if (cNode == null)
return;
cNode.filter = (SamplerStateNode.FilterMode)EditorGUILayout.Popup((int)cNode.filter, _samplerFilterMode, EditorStyles.popup);
cNode.wrap = (SamplerStateNode.WrapMode)EditorGUILayout.Popup((int)cNode.wrap, _samplerWrapMode, EditorStyles.popup);
}
public override float GetHeight()
{
return EditorGUIUtility.singleLineHeight + EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
}
}
[Serializable]
public class SamplerStateNodePresenter : MaterialNodePresenter
{
protected override IEnumerable<GraphElementPresenter> GetControlData()
{
var instance = CreateInstance<SamplerStateControlPresenter>();
instance.Initialize(node);
return new List<GraphElementPresenter> { instance };
}
}
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/SamplerStatePresenter.cs.meta


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

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


using System;
using System.Collections.Generic;
using RMGUI.GraphView;
using UnityEditor.Graphing.Drawing;
using UnityEngine;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.Drawing
{
class TextureSamplerContolPresenter : GraphControlPresenter
{
private string[] m_TextureTypeNames;
private string[] textureTypeNames
{
get
{
if (m_TextureTypeNames == null)
m_TextureTypeNames = Enum.GetNames(typeof(TextureType));
return m_TextureTypeNames;
}
}
public override void OnGUIHandler()
{
base.OnGUIHandler();
var tNode = node as UnityEngine.MaterialGraph.TextureAssetNode;
if (tNode == null)
return;
tNode.exposedState = (PropertyNode.ExposedState)EditorGUILayout.EnumPopup(new GUIContent("Exposed"), tNode.exposedState);
tNode.defaultTexture = EditorGUILayout.MiniThumbnailObjectField(new GUIContent("Texture"), tNode.defaultTexture, typeof(Texture), null) as Texture;
tNode.textureType = (TextureType)EditorGUILayout.Popup((int)tNode.textureType, textureTypeNames, EditorStyles.popup);
}
public override float GetHeight()
{
return 3 * (EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing) + EditorGUIUtility.standardVerticalSpacing;
}
}
[Serializable]
public class TextureSamplerNodePresenter : MaterialNodePresenter
{
protected override IEnumerable<GraphElementPresenter> GetControlData()
{
var instance = CreateInstance<TextureSamplerContolPresenter>();
instance.Initialize(node);
return new List<GraphElementPresenter> { instance };
}
}
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/TextureSamplerPresenter.cs.meta


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

445
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/bricks_height.png

之前 之后
宽度: 256  |  高度: 256  |  大小: 76 KiB

75
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/bricks_height.png.meta


fileFormatVersion: 2
guid: 5d84e1086e00e3347aaa0bbba206bb80
timeCreated: 1495717214
licenseType: Pro
TextureImporter:
fileIDToRecycleName: {}
serializedVersion: 4
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: -1
aniso: -1
mipBias: -1
wrapU: -1
wrapV: -1
wrapW: -1
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spritePixelsToUnits: 100
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
platformSettings:
- buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
spritePackingTag:
userData:
assetBundleName:
assetBundleVariant:

137
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/bricks_normal.tga
文件差异内容过多而无法显示
查看文件

75
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/bricks_normal.tga.meta


fileFormatVersion: 2
guid: e017404169662f041a969b0a924cc2ed
timeCreated: 1495717224
licenseType: Pro
TextureImporter:
fileIDToRecycleName: {}
serializedVersion: 4
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: -1
aniso: -1
mipBias: -1
wrapU: -1
wrapV: -1
wrapW: -1
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spritePixelsToUnits: 100
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
platformSettings:
- buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
spritePackingTag:
userData:
assetBundleName:
assetBundleVariant:

1
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/mur_Ambiant.bmp
文件差异内容过多而无法显示
查看文件

75
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/mur_Ambiant.bmp.meta


fileFormatVersion: 2
guid: b5a88303611082242a4eb08e645752d2
timeCreated: 1495717081
licenseType: Pro
TextureImporter:
fileIDToRecycleName: {}
serializedVersion: 4
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: -1
aniso: -1
mipBias: -1
wrapU: -1
wrapV: -1
wrapW: -1
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spritePixelsToUnits: 100
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
platformSettings:
- buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
spritePackingTag:
userData:
assetBundleName:
assetBundleVariant:

52
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Templates/tesselationSubshader.template


SubShader
{
${Tags}
${Blending}
${Culling}
${ZTest}
${ZWrite}
LOD ${LOD}
CGPROGRAM
#include "Tessellation.cginc"
#pragma target 4.6
#pragma surface surf ${LightingFunctionName} ${VertexShaderDecl} vertex:Displacement tessellate:tessEdge tessphong:_Phong
#pragma glsl
#pragma debug
//Tessellation Edge Function
float4 tessEdge(appdata v0, appdata v1, appdata v2)
{
float quality = 20-(_Subdivision * 2);
return UnityEdgeLengthBasedTess(v0.vertex, v1.vertex, v2.vertex, quality);
}
//Tessellation Vertex Function
void Displacement (inout appdata v)
{
float d = tex2Dlod(_DisplacementTex, float4(v.texcoord.xy * (_DisplacementTex_ST.xy * float2(_WeaveScale*25, _WeaveScale*25)) + _DisplacementTex_ST.zw, 0, 0)).r * _Displacement*0.1;
v.vertex.xyz += v.normal * (d * 0.5);
}
${ShaderFunctions}
${ShaderPropertyUsages}
struct Input
{
${ShaderInputs}
};
void vert (inout appdata_full v, out Input o)
{
UNITY_INITIALIZE_OUTPUT(Input,o);
${VertexShaderBody}
}
void surf (Input IN, inout ${SurfaceOutputStructureName} o)
{
${PixelShaderBody}
}
ENDCG
}

8
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Templates/tesselationSubshader.template.meta


fileFormatVersion: 2
guid: 71a3d46ddb1693340a7de3973be90309
timeCreated: 1481194716
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

9
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Art/Filters.meta


fileFormatVersion: 2
guid: 7ed888a282fe7b54e968311cd68c4862
folderAsset: yes
timeCreated: 1495638073
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

133
MaterialGraphProject/Assets/Vlad/SamplerStateNode.cs


using System.Collections.Generic;
using UnityEngine.MaterialGraph;
using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
[Title("Input/Sampler State")]
public class SamplerStateNode : AbstractMaterialNode, IGeneratesBodyCode
{
public enum FilterMode
{
Linear,
Point
}
public enum WrapMode
{
Repeat,
Clamp
}
static Dictionary<FilterMode, string> filterMode = new Dictionary<FilterMode, string>
{
{FilterMode.Linear, "_linear"},
{FilterMode.Point, "_point"},
};
static Dictionary<WrapMode, string> wrapMode = new Dictionary<WrapMode, string>
{
{WrapMode.Repeat, "_repeat"},
{WrapMode.Clamp, "_clamp"},
};
[SerializeField]
private FilterMode m_filter = FilterMode.Linear;
public FilterMode filter
{
get { return m_filter; }
set
{
if (m_filter == value)
return;
m_filter = value;
if (onModified != null)
{
onModified(this, ModificationScope.Graph);
}
}
}
[SerializeField]
private WrapMode m_wrap = WrapMode.Repeat;
public WrapMode wrap
{
get { return m_wrap; }
set
{
if (m_wrap == value)
return;
m_wrap = value;
if (onModified != null)
{
onModified(this, ModificationScope.Graph);
}
}
}
public SamplerStateNode()
{
name = "SamplerState";
UpdateNodeAfterDeserialization();
}
public override bool hasPreview { get { return false; } }
private const int kOutputSlotId = 0;
private const string kOutputSlotName = "Sampler Output";
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.SamplerState, Vector4.zero, false));
RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
}
/*
public override PropertyType propertyType
{
get { return PropertyType.SamplerState; }
}
public override PreviewProperty GetPreviewProperty()
{
return new PreviewProperty
{
m_Name = propertyName + "HEEEEEEYYYYY",
m_PropType = PropertyType.Float,
// m_Float = filterMode[filter];
};
}
*/
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
public override string GetVariableNameForNode()
{
return "my" + filterMode[filter] + wrapMode[wrap] + "_sampler";
}
}
}

12
MaterialGraphProject/Assets/Vlad/SamplerStateNode.cs.meta


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

246
MaterialGraphProject/Assets/Vlad/TextureSamplerNode.cs


using System;
using System.Collections.Generic;
using System.Linq;
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
[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;
m_TextureType = value;
if (onModified != null)
{
onModified(this, ModificationScope.Graph);
}
}
}
public TextureSamplerNode()
{
name = "TextureSamplerNode";
UpdateNodeAfterDeserialization();
}
public sealed override void 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);
}
protected int[] validSlots
{
get { return new[] { OutputSlotRGBAId, SamplerSlotId, UVSlotId, TextureAssetSlotId }; }
}
// Node generations
public virtual void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
{
//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)
return;
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)
{
//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("#ifdef UNITY_COMPILER_HLSL", false);
visitor.AddShaderChunk(samplerSlot.valueType + " " + samplerName + ";", true);
visitor.AddShaderChunk("#endif", false);
}
public override PreviewProperty GetPreviewProperty()
{
return new PreviewProperty
{
m_Name = propertyName,
m_PropType = PropertyType.Texture,
m_Texture = defaultTexture
};
}
public override PropertyType propertyType { get { return PropertyType.Texture; } }
public bool RequiresMeshUV(UVChannel channel)
{
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;
}
//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 edges = owner.GetEdges(slot.slotReference).ToList();
hasError |= edges.Count == 0;
}
}
}

12
MaterialGraphProject/Assets/Vlad/TextureSamplerNode.cs.meta


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

1
MaterialGraphProject/Assets/Florent/GeneratedTexture.meta


guid: fbb15485f0112484eaa58e88a4ac393f

12
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Art/Filters/ConvolutionFilterNode.cs.meta


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

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


using UnityEngine.Graphing;
using System.Collections.Generic;
using System.Linq;
using System;
namespace UnityEngine.MaterialGraph
{
[Title("Art/Filters/Convolution")]
public class ConvolutionFilterNode : Function2Input, IGeneratesFunction, IGeneratesBodyCode, IMayRequireMeshUV
{
private const string kUVSlotName = "UV";
private const string kTextureSlotName = "Texture";
private const int kNumConvolutionVector4 = 7;
[SerializeField]
private Vector4[] m_ConvolutionFilter = new Vector4[kNumConvolutionVector4]
{ new Vector4(1,1,1,1),
new Vector4(1,1,1,1),
new Vector4(1,1,1,1),
new Vector4(1,1,1,1),
new Vector4(1,1,1,1),
new Vector4(1,1,1,1),
new Vector4(1,0,0,25.0f) };
private void GetPositionInData(int row, int col, out int vectorIndex, out int vectorOffset)
{
row = Math.Max(row, 0);
col = Math.Max(col, 0);
row = Math.Min(row, 4);
col = Math.Min(col, 4);
int valueIndex = col * 5 + row;
vectorIndex = valueIndex / 4;
vectorOffset = valueIndex % 4;
}
public float GetConvolutionDivisor()
{
return m_ConvolutionFilter[6].w;
}
public void SetConvolutionDivisor(float value)
{
if (value == m_ConvolutionFilter[6].w)
return;
m_ConvolutionFilter[6].w = value;
if (onModified != null)
onModified(this, ModificationScope.Node);
}
public float GetConvolutionWeight(int row, int col)
{
int vectorIndex;
int vectorOffset;
GetPositionInData(row, col, out vectorIndex, out vectorOffset);
switch(vectorOffset)
{
case 0: return m_ConvolutionFilter[vectorIndex].x;
case 1: return m_ConvolutionFilter[vectorIndex].y;
case 2: return m_ConvolutionFilter[vectorIndex].z;
default: return m_ConvolutionFilter[vectorIndex].w;
}
}
public void SetConvolutionWeight(int row, int col, float value)
{
float prevValue = GetConvolutionWeight(row, col);
if (value == prevValue)
return;
int vectorIndex;
int vectorOffset;
GetPositionInData(row, col, out vectorIndex, out vectorOffset);
switch (vectorOffset)
{
case 0: m_ConvolutionFilter[vectorIndex].x = value; break;
case 1: m_ConvolutionFilter[vectorIndex].y = value; break;
case 2: m_ConvolutionFilter[vectorIndex].z = value; break;
default: m_ConvolutionFilter[vectorIndex].w = value; break;
}
if (onModified != null)
onModified(this, ModificationScope.Node);
}
protected override string GetFunctionName()
{
return "unity_convolution_" + precision;
}
protected override MaterialSlot GetInputSlot1()
{
return new MaterialSlot(InputSlot1Id, kTextureSlotName, kTextureSlotName, SlotType.Input, SlotValueType.Texture2D, Vector4.zero, false);
}
protected override MaterialSlot GetInputSlot2()
{
return new MaterialSlot(InputSlot2Id, kUVSlotName, kUVSlotName, SlotType.Input, SlotValueType.Vector2, Vector4.zero, false);
}
protected override MaterialSlot GetOutputSlot()
{
return new MaterialSlot(OutputSlotId, kOutputSlotShaderName, kOutputSlotShaderName, SlotType.Output, SlotValueType.Vector4, Vector4.zero);
}
public ConvolutionFilterNode()
{
name = "Convolution";
UpdateNodeAfterDeserialization();
}
public override bool hasPreview
{
get { return true; }
}
public override PreviewMode previewMode
{
get
{
return PreviewMode.Preview2D;
}
}
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)
{
if (generationMode.IsPreview())
{
string propGuid = guid.ToString().Replace("-", "_");
for (int i = 0; i < kNumConvolutionVector4; ++i)
{
visitor.AddShaderChunk(precision + "4 " + GetPropertyName(i, propGuid) + ";", true);
}
}
}
private string GetPropertyName(int index, string nodeGuid)
{
return "convolutionFilter" + index + "_" + nodeGuid;
}
public override void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
{
NodeUtils.SlotConfigurationExceptionIfBadConfiguration(this, new[] { InputSlot1Id, InputSlot2Id }, new[] { OutputSlotId });
if (!generationMode.IsPreview())
{
string propGuid = guid.ToString().Replace("-", "_");
for (int i = 0; i < kNumConvolutionVector4; ++i)
{
visitor.AddShaderChunk(precision + "4 " + GetPropertyName(i, propGuid) + "=" + precision + "4 (" + m_ConvolutionFilter[i].x + ", " + m_ConvolutionFilter[i].y + ", " + m_ConvolutionFilter[i].z + ", " + m_ConvolutionFilter[i].w + ");", true);
}
}
string samplerName = GetSlotValue(InputSlot1Id, generationMode);
//uv
var uvSlot = FindInputSlot<MaterialSlot>(InputSlot2Id);
if (uvSlot == null)
return;
var baseUV = string.Format("{0}.xy", UVChannel.uv0.GetUVName());
var uvEdges = owner.GetEdges(uvSlot.slotReference).ToList();
if (uvEdges.Count > 0)
{
var uvEdge = uvEdges[0];
var fromNode = owner.GetNodeFromGuid<AbstractMaterialNode>(uvEdge.outputSlot.nodeGuid);
baseUV = ShaderGenerator.AdaptNodeOutput(fromNode, uvEdge.outputSlot.slotId, ConcreteSlotValueType.Vector2, true);
}
//texelSize
string texelSize = samplerName + "_TexelSize.xy";
visitor.AddShaderChunk(precision + "4 " + GetVariableNameForSlot(OutputSlotId) + " = " + GetFunctionCallBody(samplerName, baseUV, texelSize) + ";", true);
}
protected string GetFunctionCallBody(string samplerName, string baseUv, string texelSize)
{
string propGuid = guid.ToString().Replace("-", "_");
return GetFunctionName() + " (" + samplerName + ", " + baseUv + ", "
+ GetPropertyName(0, propGuid) + ", "
+ GetPropertyName(1, propGuid) + ", "
+ GetPropertyName(2, propGuid) + ", "
+ GetPropertyName(3, propGuid) + ", "
+ GetPropertyName(4, propGuid) + ", "
+ GetPropertyName(5, propGuid) + ", "
+ GetPropertyName(6, propGuid) + ", "
+ texelSize + ")";
}
protected override string GetFunctionPrototype(string arg1Name, string arg2Name)
{
string propGuid = guid.ToString().Replace("-", "_");
return "inline " + precision + "4 " + GetFunctionName() + " ("
+ "sampler2D " + arg1Name + ", "
+ precision + "2 " + arg2Name + ", "
+ precision + "4 weights0,"
+ precision + "4 weights1,"
+ precision + "4 weights2,"
+ precision + "4 weights3,"
+ precision + "4 weights4,"
+ precision + "4 weights5,"
+ precision + "4 weights6, float2 texelSize)";
}
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)
{
var outputString = new ShaderGenerator();
outputString.AddShaderChunk(GetFunctionPrototype("textSampler", "baseUv"), false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("fixed4 fetches = fixed4(0,0,0,0);", false);
outputString.AddShaderChunk("fixed weight = 1;", false);
string[] channelNames = { ".x", ".y", ".z", ".w" };
for(int col=0; col < 5; ++col)
{
for(int row=0; row < 5; ++row)
{
int valueIndex = col * 5 + row;
int vectorIndex = valueIndex / 4;
int vectorOffset = valueIndex % 4;
outputString.AddShaderChunk("weight = weights" + vectorIndex + channelNames[vectorOffset] + ";", false);
outputString.AddShaderChunk("fetches += weight * tex2D(textSampler, baseUv + texelSize * fixed2("+(row-2)+","+(col-2)+"));", false);
}
}
outputString.AddShaderChunk("fetches /= weights6.w;", false);
outputString.AddShaderChunk("return fetches;", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
}
//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>(InputSlot1Id);
if (slot == null)
return;
var edges = owner.GetEdges(slot.slotReference).ToList();
hasError |= edges.Count == 0;
}
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
{
base.CollectPreviewMaterialProperties(properties);
string propGuid = guid.ToString().Replace("-", "_");
for (int i = 0; i < kNumConvolutionVector4; ++i)
{
properties.Add(new PreviewProperty { m_Name = GetPropertyName(i, propGuid), m_PropType = PropertyType.Vector4, m_Vector4 = m_ConvolutionFilter[i] });
}
}
public bool RequiresMeshUV(UVChannel channel)
{
if (channel != UVChannel.uv0)
{
return false;
}
var uvSlot = FindInputSlot<MaterialSlot>(InputSlot2Id);
if (uvSlot == null)
return true;
var edges = owner.GetEdges(uvSlot.slotReference).ToList();
return edges.Count == 0;
}
}
}
正在加载...
取消
保存