浏览代码

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

/main
RinaldoTjan 8 年前
当前提交
c5984a7b
共有 278 个文件被更改,包括 3029 次插入1858 次删除
  1. 1
      MaterialGraphProject/Assets/Eduardo/ConstantsNode.cs
  2. 2
      MaterialGraphProject/Assets/Eduardo/EduardoTestGraph.ShaderGraph
  3. 54
      MaterialGraphProject/Assets/Eduardo/FunctionNInNOut.cs
  4. 26
      MaterialGraphProject/Assets/Eduardo/HeightToNormalNode.cs
  5. 896
      MaterialGraphProject/Assets/GeneratedShader.shader
  6. 8
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Implementation/NodeUtils.cs
  7. 2
      MaterialGraphProject/Assets/Matt/AnisotropicMaster.ShaderGraph
  8. 2
      MaterialGraphProject/Assets/Matt/EyeMaster.ShaderGraph
  9. 2
      MaterialGraphProject/Assets/NewNodes/WIP/MultiLayerParallaxNode.cs
  10. 5
      MaterialGraphProject/Assets/TestAssets/Materials/Default.mat
  11. 2
      MaterialGraphProject/Assets/TestAssets/Teapot.fbx.meta
  12. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/AbstractMaterialGraphInspector.cs
  13. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/ColorNodePresenter.cs
  14. 5
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/CustomCodeNodePresenter.cs
  15. 25
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs
  16. 49
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Vector1NodePresenter.cs
  17. 93
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/HelperShader.shader
  18. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/HelperShader.shader.meta
  19. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Templates/subshader.template
  20. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/PropertyChunkTests.cs
  21. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/PropertyNodeTests.cs
  22. 43
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/AbstractMaterialNode.cs
  23. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Function2Input.cs
  24. 23
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/ColorNode.cs
  25. 14
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Texture/CubemapNode.cs
  26. 54
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Vector/Vector1Node.cs
  27. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Vector/Vector2Node.cs
  28. 32
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/MaterialSlot.cs
  29. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Procedural/CheckerboardNode.cs
  30. 42
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Procedural/VoronoiNoise.cs
  31. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/PropertyNode.cs
  32. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/PropertyType.cs
  33. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/SlotValue.cs
  34. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/UV/UVTileNode.cs
  35. 126
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SurfaceModel/AbstractSurfaceMasterNode.cs
  36. 35
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SurfaceModel/MetallicMasterNode.cs
  37. 30
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SurfaceModel/SpecularMasterNode.cs
  38. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/ColorPropertyChunk.cs
  39. 39
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/FloatPropertyChunk.cs
  40. 8
      MaterialGraphProject/Assets/Vlad/TextureAssetNode.cs
  41. 122
      MaterialGraphProject/Assets/Vlad/UVTriPlanar.cs
  42. 9
      MaterialGraphProject/Assets/Andre/Nodes/ToggleNode.cs
  43. 8
      MaterialGraphProject/Assets/Andre/Scenes/Andre_scene.unity
  44. 127
      MaterialGraphProject/Assets/Andre/Materials/Mat.mat
  45. 9
      MaterialGraphProject/Assets/Andre/Materials/Sky.mat
  46. 102
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Matrix/MatrixMultiplyNode.cs
  47. 21
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Matrix/MatrixTransposeNode.cs
  48. 998
      MaterialGraphProject/Assets/Andre/Scenes/EmissionTest/LightingData.asset
  49. 4
      MaterialGraphProject/Assets/Andre/Scenes/LightProbeTesting/ReflectionProbe-0.exr.meta
  50. 9
      MaterialGraphProject/Assets/Andre/Materials.meta
  51. 9
      MaterialGraphProject/Assets/Andre/Nodes.meta
  52. 9
      MaterialGraphProject/Assets/Andre/Scenes.meta
  53. 9
      MaterialGraphProject/Assets/Andre/Scripts.meta
  54. 9
      MaterialGraphProject/Assets/Andre/Shaders.meta
  55. 1
      MaterialGraphProject/Assets/Brandon/Electricity.ShaderGraph
  56. 9
      MaterialGraphProject/Assets/Brandon/Electricity.ShaderGraph.meta
  57. 1
      MaterialGraphProject/Assets/Brandon/Flame.ShaderGraph
  58. 9
      MaterialGraphProject/Assets/Brandon/Flame.ShaderGraph.meta
  59. 1
      MaterialGraphProject/Assets/Code Graph.ShaderGraph
  60. 9
      MaterialGraphProject/Assets/Code Graph.ShaderGraph.meta
  61. 83
      MaterialGraphProject/Assets/Eduardo/EduardoTestMat.mat
  62. 9
      MaterialGraphProject/Assets/Eduardo/EduardoTestMat.mat.meta
  63. 64
      MaterialGraphProject/Assets/Eduardo/VertexNormalNode.cs
  64. 12
      MaterialGraphProject/Assets/Eduardo/VertexNormalNode.cs.meta
  65. 64
      MaterialGraphProject/Assets/Eduardo/VertexPositionNode.cs
  66. 12
      MaterialGraphProject/Assets/Eduardo/VertexPositionNode.cs.meta
  67. 363
      MaterialGraphProject/Assets/Eduardo/eduardoScene.unity
  68. 8
      MaterialGraphProject/Assets/Eduardo/eduardoScene.unity.meta
  69. 9
      MaterialGraphProject/Assets/Florent.meta
  70. 22
      MaterialGraphProject/Assets/Matt/CommonMatrixType.cs
  71. 12
      MaterialGraphProject/Assets/Matt/CommonMatrixType.cs.meta
  72. 9
      MaterialGraphProject/Assets/Matt/Examples.meta
  73. 1
      MaterialGraphProject/Assets/Matt/Test.ShaderGraph
  74. 9
      MaterialGraphProject/Assets/Matt/Test.ShaderGraph.meta
  75. 335
      MaterialGraphProject/Assets/NewNodes/WIP/POMNode.cs
  76. 12
      MaterialGraphProject/Assets/NewNodes/WIP/POMNode.cs.meta
  77. 1
      MaterialGraphProject/Assets/POM_Graph.ShaderGraph
  78. 9
      MaterialGraphProject/Assets/POM_Graph.ShaderGraph.meta
  79. 21
      MaterialGraphProject/Assets/TestAssets/TangentMap1.jpg
  80. 75
      MaterialGraphProject/Assets/TestAssets/TangentMap1.jpg.meta
  81. 33
      MaterialGraphProject/Assets/TestAssets/TangentMap2.jpg
  82. 75
      MaterialGraphProject/Assets/TestAssets/TangentMap2.jpg.meta
  83. 12
      MaterialGraphProject/Assets/TestAssets/TangentMap3.jpg
  84. 75
      MaterialGraphProject/Assets/TestAssets/TangentMap3.jpg.meta
  85. 29
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeInspectors/PropertyNodeInspector.cs
  86. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeInspectors/PropertyNodeInspector.cs.meta
  87. 151
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/ConvolutionFilterNodePresenter.cs
  88. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/ConvolutionFilterNodePresenter.cs.meta
  89. 72
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/GradientNodePresenter.cs
  90. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/GradientNodePresenter.cs.meta
  91. 40
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Matrix2NodePresenter.cs
  92. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Matrix2NodePresenter.cs.meta
  93. 41
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Matrix3NodePresenter.cs

1
MaterialGraphProject/Assets/Eduardo/ConstantsNode.cs


static Dictionary<ConstantType, float> m_constantList = new Dictionary<ConstantType, float>
{
{ConstantType.PI, 3.1415926f },
{ConstantType.TAU, 6.28318530f},
{ConstantType.PHI, 1.618034f},
{ConstantType.E, 2.718282f},

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);

896
MaterialGraphProject/Assets/GeneratedShader.shader


Shader "Graph/Generated.AnisotropicMetallicMasterNoded3249a79-099e-4f35-8185-c418a23965c8"
Shader "Graph/Generated.MetallicMasterNode554b91b5-7a00-4f5f-b71a-f7729fcbdee8"
[NonModifiableTextureData] TextureAsset_8f4a8771_6c8f_4107_9c0b_83da34d57a9b_Uniform("TextureAsset", 2D) = "white" {}
}

LOD 200
CGPROGRAM
#include "UnityCG.cginc"
//#include "AdvancedBRDF.cginc"
//#include "AdvancedShading.cginc"
//#include "AdvancedLighting.cginc"
#define SHADINGMODELID_STANDARD
// ------------------------------------------------------------------
// Diffuse
// From UE4 - Used for Cloth (Deprecated)
float3 Diffuse_Lambert(float3 DiffuseColor)
{
return DiffuseColor * (1 / UNITY_PI);
}
// ------------------------------------------------------------------
// Fresnel
// From UE4 - Used for Cloth
// [Schlick 1994, "An Inexpensive BRDF Model for Physically-Based Rendering"]
float3 F_Schlick(float3 SpecularColor, float VoH)
{
float Fc = Pow5(1 - VoH); // 1 sub, 3 mul
//return Fc + (1 - Fc) * SpecularColor; // 1 add, 3 mad
// Anything less than 2% is physically impossible and is instead considered to be shadowing
return saturate(50.0 * SpecularColor.g) * Fc + (1 - Fc) * SpecularColor;
}
// ------------------------------------------------------------------
// Distribution
// From UE4 - USed for Cloth
// GGX / Trowbridge-Reitz
// [Walter et al. 2007, "Microfacet models for refraction through rough surfaces"]
float D_GGX(float roughness, float NdotH)
{
float a = roughness * roughness;
float a2 = a * a;
float d = (NdotH * a2 - NdotH) * NdotH + 1; // 2 mad
return a2 / (UNITY_PI*d*d); // 4 mul, 1 rcp
}
// Anisotropic GGX
// Taken from HDRenderPipeline
float D_GGXAnisotropic(float TdotH, float BdotH, float NdotH, float roughnessT, float roughnessB)
{
float f = TdotH * TdotH / (roughnessT * roughnessT) + BdotH * BdotH / (roughnessB * roughnessB) + NdotH * NdotH;
return 1.0 / (roughnessT * roughnessB * f * f);
}
// From UE4 - Used for Cloth
float D_InvGGX(float roughness, float NdotH)
{
float a = roughness * roughness;
float a2 = a * a;
float A = 4;
float d = (NdotH - a2 * NdotH) * NdotH + a2;
return 1/(UNITY_PI * (1 + A*a2)) * (1 + 4 * a2*a2 / (d*d)); //RCP
}
// ------------------------------------------------------------------
// Visibility
// From UE4 - Used for Cloth
// Appoximation of joint Smith term for GGX
// [Heitz 2014, "Understanding the Masking-Shadowing Function in Microfacet-Based BRDFs"]
float Vis_SmithJointApprox(float Roughness, float NoV, float NoL)
{
float a = (Roughness*Roughness);
float Vis_SmithV = NoL * (NoV * (1 - a) + a);
float Vis_SmithL = NoV * (NoL * (1 - a) + a);
// Note: will generate NaNs with Roughness = 0. MinRoughness is used to prevent this
return 0.5 * 1/(Vis_SmithV + Vis_SmithL); //RCP
}
// From UE4 - Used for Cloth
float Vis_Cloth(float NoV, float NoL)
{
return 1/(4 * (NoL + NoV - NoL * NoV)); //RCP
}
// ------------------------------------------------------------------
// SORT THESE
// Smith Joint GGX Anisotropic Visibility
// Taken from https://cedec.cesa.or.jp/2015/session/ENG/14698.html
float SmithJointGGXAnisotropic(float TdotV, float BdotV, float NdotV, float TdotL, float BdotL, float NdotL, float roughnessT, float roughnessB)
{
float aT = roughnessT;
float aT2 = aT * aT;
float aB = roughnessB;
float aB2 = aB * aB;
float lambdaV = NdotL * sqrt(aT2 * TdotV * TdotV + aB2 * BdotV * BdotV + NdotV * NdotV);
float lambdaL = NdotV * sqrt(aT2 * TdotL * TdotL + aB2 * BdotL * BdotL + NdotL * NdotL);
return 0.5 / (lambdaV + lambdaL);
}
// Convert Anistropy to roughness
void ConvertAnisotropyToRoughness(float roughness, float anisotropy, out float roughnessT, out float roughnessB)
{
// (0 <= anisotropy <= 1), therefore (0 <= anisoAspect <= 1)
// The 0.9 factor limits the aspect ratio to 10:1.
float anisoAspect = sqrt(1.0 - 0.9 * anisotropy);
roughnessT = roughness / anisoAspect; // Distort along tangent (rougher)
roughnessB = roughness * anisoAspect; // Straighten along bitangent (smoother)
}
// Schlick Fresnel
float FresnelSchlick(float f0, float f90, float u)
{
float x = 1.0 - u;
float x5 = x * x;
x5 = x5 * x5 * x;
return (f90 - f0) * x5 + f0; // sub mul mul mul sub mad
}
//Clamp roughness
float ClampRoughnessForAnalyticalLights(float roughness)
{
return max(roughness, 0.000001);
}
//Calculate tangent warp for IBL (Reference Version - not used)
float3 SpecularGGXIBLRef(float3 viewDir, float3 normalDir, float3 tangentDir, float3 bitangentDir, float roughnessT, float roughnessB)
{
return float3(1, 1, 1);
//Hidden in UnityAnisotropicLighting.cginc
}
// Sample Anisotropic Direction for IBL (Reference Version - not used)
void SampleAnisoGGXDir(float2 u, float3 viewDir, float3 normalDir, float3 tangent, float3 bitangent, float roughnessT, float roughnessB, out float3 halfDir, out float3 lightDir)
{
// AnisoGGX NDF sampling
halfDir = sqrt(u.x / (1.0 - u.x)) * (roughnessT * cos((UNITY_PI * 2) * u.y) * tangent + roughnessB * sin((UNITY_PI * 2) * u.y) * bitangent) + normalDir;
halfDir = normalize(halfDir);
// Convert sample from half angle to incident angle
lightDir = 2.0 * saturate(dot(viewDir, halfDir)) * halfDir - viewDir;
}
// Ref: Donald Revie - Implementing Fur Using Deferred Shading (GPU Pro 2)
// The grain direction (e.g. hair or brush direction) is assumed to be orthogonal to the normal.
// The returned normal is NOT normalized.
float3 ComputeGrainNormal(float3 grainDir, float3 V)
{
float3 B = cross(-V, grainDir);
return cross(B, grainDir);
}
//Modify Normal for Anisotropic IBL (Realtime version)
// Fake anisotropic by distorting the normal.
// The grain direction (e.g. hair or brush direction) is assumed to be orthogonal to N.
// Anisotropic ratio (0->no isotropic; 1->full anisotropy in tangent direction)
float3 GetAnisotropicModifiedNormal(float3 grainDir, float3 N, float3 V, float anisotropy)
{
float3 grainNormal = ComputeGrainNormal(grainDir, V);
// TODO: test whether normalizing 'grainNormal' is worth it.
return normalize(lerp(N, grainNormal, anisotropy));
}
/// REGION END - ANISOTROPY
/// REGION START - SUBSURFACE SCATTERING
half Fresnel(half3 H, half3 V, half F0)
{
half base = 1.0 - dot(V, H);
half exponential = pow(base, 5.0);
return exponential + F0 * (1.0 - exponential);
}
/*
inline half3 KelemenSzirmayKalosSpecular(half3 normal, half3 lightDir, half3 viewDir, float roughness, float rho_s)
{
half3 result = half3(0, 0, 0);
half NdotL = dot(normal, lightDir);
if (NdotL > 0.0)
{
half3 h = lightDir + viewDir;
half3 H = normalize(h);
half NdotH = dot(normal, H);
half PH = pow(2.0 * tex2D(_BeckmannPrecomputedTex, half2(NdotH, roughness)).r, 10.0);
half F = Fresnel(H, viewDir, 0.028);
half frSpec = max(PH * F / dot(h, h), 0);
half term = NdotL * rho_s * frSpec;
result = half3(term, term, term);
}
return result;
}*/
/*
half3 SkinDiffuse(float curv, float3 NdotL)
{
float3 lookup = NdotL * 0.5 + 0.5;
float3 diffuse;
diffuse.r = tex2D(_DiffusionProfileTexture, float2(lookup.r, curv)).r;
diffuse.g = tex2D(_DiffusionProfileTexture, float2(lookup.g, curv)).g;
diffuse.b = tex2D(_DiffusionProfileTexture, float2(lookup.b, curv)).b;
return diffuse;
}*/
/// REGION END - SUBSURFACE SCATTERING
// Upgrade NOTE: replaced 'defined SHADINGMODELID_CLEARCOAT' with 'defined (SHADINGMODELID_CLEARCOAT)'
// Upgrade NOTE: replaced 'defined SHADINGMODELID_CLOTH' with 'defined (SHADINGMODELID_CLOTH)'
// Upgrade NOTE: replaced 'defined SHADINGMODELID_EYE' with 'defined (SHADINGMODELID_EYE)'
// Upgrade NOTE: replaced 'defined SHADINGMODELID_FOLIAGE' with 'defined (SHADINGMODELID_FOLIAGE)'
// Upgrade NOTE: replaced 'defined SHADINGMODELID_HAIR' with 'defined (SHADINGMODELID_HAIR)'
// Upgrade NOTE: replaced 'defined SHADINGMODELID_SKIN' with 'defined (SHADINGMODELID_SKIN)'
// Upgrade NOTE: replaced 'defined SHADINGMODELID_SUBSURFACE' with 'defined (SHADINGMODELID_SUBSURFACE)'
// ------------------------------------------------------------------
// Shading models
//#pragma multi_compile SHADINGMODELID_UNLIT SHADINGMODELID_STANDARD SHADINGMODELID_SUBSURFACE SHADINGMODELID_SKIN SHADINGMODELID_FOLIAGE SHADINGMODELID_CLEARCOAT SHADINGMODELID_CLOTH SHADINGMODELID_EYE
// ------------------------------------------------------------------
// Input
half _ShadingModel;
sampler2D _AnisotropyMap;
half _Anisotropy;
sampler2D _TangentMap;
half4 _TranslucentColor;
sampler2D _TranslucencyMap;
sampler2D _FuzzTex;
half3 _FuzzColor;
half _Cloth;
sampler2D _IrisNormal;
sampler2D _IrisMask;
half _IrisDistance;
half _TDistortion;
half _TScale;
half _TAmbient;
half _TPower;
half _TAttenuation;
half _TransmissionOverallStrength;
// ------------------------------------------------------------------
// Maths helpers
// Octahedron Normal Vectors
// [Cigolle 2014, "A Survey of Efficient Representations for Independent Unit Vectors"]
// Mean Max
// oct 8:8 0.33709 0.94424
// snorm 8:8:8 0.17015 0.38588
// oct 10:10 0.08380 0.23467
// snorm 10:10:10 0.04228 0.09598
// oct 12:12 0.02091 0.05874
float2 UnitVectorToOctahedron(float3 N)
{
N.xy /= dot(float3(1,1,1), abs(N));
if (N.z <= 0)
{
N.xy = (1 - abs(N.yx)) * (N.xy >= 0 ? float2(1, 1) : float2(-1, -1));
}
return N.xy;
}
float3 OctahedronToUnitVector(float2 Oct)
{
float3 N = float3(Oct, 1 - dot(float2(1,1), abs(Oct)));
if (N.z < 0)
{
N.xy = (1 - abs(N.yx)) * (N.xy >= 0 ? float2(1, 1) : float2(-1, -1));
}
return float3(1, 1, 1);
return normalize(N);
}
// ------------------------------------------------------------------
// Surface helpers
half Anisotropy(float2 uv)
{
return tex2D(_AnisotropyMap, uv) * _Anisotropy;
}
half3 Fuzz(float2 uv)
{
return tex2D(_FuzzTex, uv) * _FuzzColor;
}
half Cloth()
{
return _Cloth;
}
half4 Iris(float2 uv)
{
float2 n = UnitVectorToOctahedron(normalize(UnpackNormal(tex2D(_IrisNormal, uv)).rgb)) * 0.5 + 0.5;
float m = saturate(tex2D(_IrisMask, uv).r); // Iris Mask
float d = saturate(_IrisDistance); // Iris Distance
return float4(n.x, n.y, m, d);
}
half3 Translucency(float2 uv)
{
return tex2D(_TranslucencyMap, uv).rgb * _TranslucentColor.rgb;
}
// ------------------------------------------------------------------
// Unlit Shading Function
float4 UnlitShading(float3 diffColor)
{
return half4(diffColor, 1);
}
// ------------------------------------------------------------------
// Standard Shading Function
float4 StandardShading(float3 diffColor, float3 specColor, float oneMinusReflectivity, float smoothness, float3 normal, float3x3 worldVectors,
float anisotropy, float metallic, float3 viewDir, UnityLight light, UnityIndirect gi)
{
//Unpack world vectors
float3 tangent = worldVectors[0];
float3 bitangent = worldVectors[1];
//Normal shift
float shiftAmount = dot(normal, viewDir);
normal = shiftAmount < 0.0f ? normal + viewDir * (-shiftAmount + 1e-5f) : normal;
//Regular vectors
float NdotL = saturate(dot(normal, light.dir)); //sat?
float NdotV = abs(dot(normal, viewDir)); //abs?
float LdotV = dot(light.dir, viewDir);
float3 H = Unity_SafeNormalize(light.dir + viewDir);
float invLenLV = rsqrt(abs(2 + 2 * normalize(LdotV)));
//float invLenLV = rsqrt(abs(2 + 2 * LdotV));
//float NdotH = (NdotL + normalize(NdotV)) * invLenLV;
float NdotH = saturate(dot(normal, H));
//float NdotH = saturate((NdotL + normalize(NdotV)) * invLenLV);
//float H = (light.dir + viewDir) * invLenLV;
float LdotH = saturate(dot(light.dir, H));
//Tangent vectors
float TdotH = dot(tangent, H);
float TdotL = dot(tangent, light.dir);
float BdotH = dot(bitangent, H);
float BdotL = dot(bitangent, light.dir);
float TdotV = dot(viewDir, tangent);
float BdotV = dot(viewDir, bitangent);
//Fresnels
half grazingTerm = saturate(smoothness + (1 - oneMinusReflectivity));
float3 F = FresnelLerp(specColor, grazingTerm, NdotV); //Original Schlick - Replace from SRP?
//float3 fresnel0 = lerp(specColor, diffColor, metallic);
//float3 F = FresnelSchlick(fresnel0, 1.0, LdotH);
//Calculate roughness
float roughnessT;
float roughnessB;
float perceptualRoughness = SmoothnessToPerceptualRoughness(smoothness);
float roughness = PerceptualRoughnessToRoughness(perceptualRoughness);
ConvertAnisotropyToRoughness(roughness, anisotropy, roughnessT, roughnessB);
//Clamp roughness
//roughness = ClampRoughnessForAnalyticalLights(roughness);
roughnessT = ClampRoughnessForAnalyticalLights(roughnessT);
roughnessB = ClampRoughnessForAnalyticalLights(roughnessB);
//Visibility & Distribution terms
float V = SmithJointGGXAnisotropic(TdotV, BdotV, NdotV, TdotL, BdotL, NdotL, roughnessT, roughnessB);
float D = D_GGXAnisotropic(TdotH, BdotH, NdotH, roughnessT, roughnessB);
//Specular term
float3 specularTerm = V * D; //*UNITY_PI;
# ifdef UNITY_COLORSPACE_GAMMA
specularTerm = sqrt(max(1e-4h, specularTerm));
# endif
// specularTerm * nl can be NaN on Metal in some cases, use max() to make sure it's a sane value
specularTerm = max(0, specularTerm * NdotL);
#if defined(_SPECULARHIGHLIGHTS_OFF)
specularTerm = 0.0;
#endif
//Diffuse term
float diffuseTerm = DisneyDiffuse(NdotV, NdotL, LdotH, perceptualRoughness) * NdotL;// - Need this NdotL multiply?
//Reduction
half surfaceReduction;
# ifdef UNITY_COLORSPACE_GAMMA
surfaceReduction = 1.0 - 0.28*roughness*perceptualRoughness; // 1-0.28*x^3 as approximation for (1/(x^4+1))^(1/2.2) on the domain [0;1]
# else
surfaceReduction = 1.0 / (roughness*roughness + 1.0); // fade \in [0.5;1]
# endif
//Final
half3 color = (diffColor * (gi.diffuse + light.color * diffuseTerm))
+ specularTerm * light.color * FresnelTerm(specColor, LdotH)
+ surfaceReduction * gi.specular * FresnelLerp(specColor, grazingTerm, NdotV);
return half4(color, 1);
}
// ------------------------------------------------------------------
// Cloth Shading Function
//float3 ClothShading(FGBufferData GBuffer, float3 LobeRoughness, float3 LobeEnergy, float3 L, float3 V, half3 N)
float4 ClothShading(float3 diffColor, float3 specColor, float3 fuzzColor, float cloth, float oneMinusReflectivity, float smoothness, float3 normal, float3 viewDir, UnityLight light, UnityIndirect gi, float3x3 worldVectors, float anisotropy)
{
const float3 FuzzColor = saturate(fuzzColor);
const float Cloth = saturate(cloth);
//Regular vectors
float NdotL = saturate(dot(normal, light.dir)); //sat?
float NdotV = abs(dot(normal, viewDir)); //abs?
float LdotV = dot(light.dir, viewDir);
//float invLenLV = rsqrt(abs(2 + 2 * normalize(LdotV)));
////float invLenLV = rsqrt(abs(2 + 2 * LdotV));
//float NdotH = (NdotL + normalize(NdotV)) * invLenLV;
//float NdotH = saturate((NdotL + normalize(NdotV)) * invLenLV);
float3 H = Unity_SafeNormalize(light.dir + viewDir);
//float H = (light.dir + viewDir) * invLenLV;
float LdotH = saturate(dot(light.dir, H));
//float3 H = normalize(viewDir + light.dir);
//float NdotL = saturate(dot(normal, light.dir));
//float NdotV = saturate(abs(dot(normal, viewDir)) + 1e-5);
float NdotH = saturate(dot(normal, H));
float VdotH = saturate(dot(viewDir, H));
//float LdotH = saturate(dot(light.dir, H));
half grazingTerm = saturate(smoothness + (1 - oneMinusReflectivity));
// Diffuse
float perceptualRoughness = SmoothnessToPerceptualRoughness(smoothness);
float roughness = PerceptualRoughnessToRoughness(perceptualRoughness);
float diffuseTerm = DisneyDiffuse(NdotV, NdotL, LdotH, perceptualRoughness) * NdotL;// - Need this NdotL multiply?
// Cloth - Asperity Scattering - Inverse Beckmann Layer
float3 F1 = FresnelTerm(fuzzColor, LdotH);// FresnelLerp(fuzzColor, grazingTerm, NdotV);// FresnelTerm(FuzzColor, LdotH);// F_Schlick(FuzzColor, VdotH);
float D1 = D_InvGGX(roughness, NdotH);
float V1 = Vis_Cloth(NdotV, NdotL);
//Specular term
float3 specularTerm1 = V1 * D1; //*UNITY_PI;
# ifdef UNITY_COLORSPACE_GAMMA
specularTerm1 = sqrt(max(1e-4h, specularTerm1));
# endif
// specularTerm * nl can be NaN on Metal in some cases, use max() to make sure it's a sane value
// specularTerm1 = max(0, specularTerm1 * NdotL);
#if defined(_SPECULARHIGHLIGHTS_OFF)
specularTerm1 = 0.0;
#endif
float3 Spec1 = specularTerm1 * light.color * FresnelTerm(fuzzColor, LdotH);
// Generalized microfacet specular
/*float3 F2 = F_Schlick(specColor, VdotH);
float D2 = D_GGX(roughness, NdotH);
float V2 = Vis_SmithJointApprox(roughness, NdotV, NdotL);
float3 Spec2 = D2 * V2 * F2 * light.color;*/
//Unpack world vectors
float3 tangent = worldVectors[0];
float3 bitangent = worldVectors[1];
//Tangent vectors
float TdotH = dot(tangent, H);
float TdotL = dot(tangent, light.dir);
float BdotH = dot(bitangent, H);
float BdotL = dot(bitangent, light.dir);
float TdotV = dot(viewDir, tangent);
float BdotV = dot(viewDir, bitangent);
//Fresnels
float3 F2 = FresnelLerp(specColor, grazingTerm, NdotV);// FresnelTerm(specColor, LdotH);// FresnelLerp(specColor, grazingTerm, NdotV); //Original Schlick - Replace from SRP?
float roughnessT;
float roughnessB;
//float perceptualRoughness = SmoothnessToPerceptualRoughness(smoothness);
//float roughness = PerceptualRoughnessToRoughness(perceptualRoughness);
ConvertAnisotropyToRoughness(roughness, anisotropy, roughnessT, roughnessB);
//Clamp roughness
//roughness = ClampRoughnessForAnalyticalLights(roughness);
roughnessT = ClampRoughnessForAnalyticalLights(roughnessT);
roughnessB = ClampRoughnessForAnalyticalLights(roughnessB);
//Visibility & Distribution terms
float V2 = SmithJointGGXAnisotropic(TdotV, BdotV, NdotV, TdotL, BdotL, NdotL, roughnessT, roughnessB);
float D2 = D_GGXAnisotropic(TdotH, BdotH, NdotH, roughnessT, roughnessB);
//Specular term
float3 specularTerm2 = V2 * D2; //*UNITY_PI;
# ifdef UNITY_COLORSPACE_GAMMA
specularTerm2 = sqrt(max(1e-4h, specularTerm2));
# endif
// specularTerm * nl can be NaN on Metal in some cases, use max() to make sure it's a sane value
specularTerm2 = max(0, specularTerm2 * NdotL);
#if defined(_SPECULARHIGHLIGHTS_OFF)
specularTerm2 = 0.0;
#endif
float3 Spec2 = specularTerm2 * light.color * FresnelTerm(specColor, LdotH);
float3 Spec = lerp(Spec2, Spec1, Cloth);
//Reduction
half surfaceReduction;
# ifdef UNITY_COLORSPACE_GAMMA
surfaceReduction = 1.0 - 0.28*roughness*perceptualRoughness; // 1-0.28*x^3 as approximation for (1/(x^4+1))^(1/2.2) on the domain [0;1]
# else
surfaceReduction = 1.0 / (roughness*roughness + 1.0); // fade \in [0.5;1]
# endif
//Final
//half grazingTerm = saturate(smoothness + (1 - oneMinusReflectivity));
half3 color = (diffColor * (gi.diffuse + light.color * diffuseTerm))
+ Spec
+ surfaceReduction * gi.specular * FresnelLerp(specColor, grazingTerm, NdotV);
return half4(color, 1);
}
// ------------------------------------------------------------------
// Eye Shading Function
//float3 EyeShading(FGBufferData GBuffer, float3 LobeRoughness, float3 LobeEnergy, float3 L, float3 V, half3 N)
float4 EyeShading(float3 diffColor, float3 specColor, float3 viewDir, half3 normal, float smoothness, float oneMinusReflectivity, UnityLight light, UnityIndirect gi)
{
float3 H = normalize(viewDir + light.dir);
float NdotL = saturate(dot(normal, light.dir));
float NdotV = saturate(abs(dot(normal, viewDir)) + 1e-5);
float NdotH = saturate(dot(normal, H));
float VdotH = saturate(dot(viewDir, H));
float LdotH = saturate(dot(light.dir, H));
// Generalized microfacet specular
float perceptualRoughness = SmoothnessToPerceptualRoughness(smoothness);
float roughness = PerceptualRoughnessToRoughness(perceptualRoughness);
float D = D_GGX(roughness, NdotH);// *LobeEnergy[1];
float V = Vis_SmithJointApprox(roughness, NdotV, NdotL);
float3 F = F_Schlick(specColor, VdotH);
float3 specularTerm = V * D; //*UNITY_PI;
# ifdef UNITY_COLORSPACE_GAMMA
specularTerm = sqrt(max(1e-4h, specularTerm));
# endif
// specularTerm * nl can be NaN on Metal in some cases, use max() to make sure it's a sane value
specularTerm = max(0, specularTerm * NdotL);
#if defined(_SPECULARHIGHLIGHTS_OFF)
specularTerm = 0.0;
#endif
half grazingTerm = saturate(smoothness + (1 - oneMinusReflectivity));
half surfaceReduction;
# ifdef UNITY_COLORSPACE_GAMMA
surfaceReduction = 1.0 - 0.28*roughness*perceptualRoughness; // 1-0.28*x^3 as approximation for (1/(x^4+1))^(1/2.2) on the domain [0;1]
# else
surfaceReduction = 1.0 / (roughness*roughness + 1.0); // fade \in [0.5;1]
# endif
float diffuseTerm = DisneyDiffuse(NdotV, NdotL, LdotH, perceptualRoughness) * NdotL; // TODO - Unreal does not apply diffuse in Shading function
//Final
half3 color = (diffColor * (gi.diffuse + light.color * diffuseTerm))
+ specularTerm * light.color * FresnelTerm(specColor, LdotH)
+ surfaceReduction * gi.specular * FresnelLerp(specColor, grazingTerm, NdotV);
return half4(color, 1);
}
// ------------------------------------------------------------------
// Subsurface Shading Function
float3 SubsurfaceShadingSimple(float3 diffColor, float3 normal, float3 viewDir, float3 thickness, UnityLight light)
{
half3 vLTLight = light.dir + normal * _TDistortion;
half fLTDot = pow(saturate(dot(viewDir, -vLTLight)), _TPower) * _TScale;
half3 fLT = _TAttenuation * (fLTDot + _TAmbient) * (thickness);
return diffColor * ((light.color * fLT) * _TransmissionOverallStrength);
}
// ------------------------------------------------------------------
// Eye Subsurface Shading Function
//float3 EyeSubsurfaceShading(FGBufferData GBuffer, float3 L, float3 V, half3 N)
float3 EyeSubsurfaceShading(float3 diffColor, float3 specColor, float3 viewDir, half3 normal, float smoothness, float4 iris, UnityLight light)
{
float2 irisNormal = iris.rg;
float irisMask = iris.z;
float irisDistance = iris.w;
float3 H = normalize(viewDir + light.dir);
float VdotH = saturate(dot(viewDir, H));
float NdotV = saturate(abs(dot(normal, viewDir)) + 1e-5);
float LdotH = saturate(dot(light.dir, H));
// F_Schlick
//float F0 = GBuffer.Specular * 0.08;
//float Fc = Pow5(1 - VoH);
//float F = Fc + (1 - Fc) * F0;
float3 fresnel0 = lerp(specColor, diffColor, smoothness);
float3 F = FresnelSchlick(fresnel0, 1.0, LdotH);
//float IrisDistance = GBuffer.CustomData.w;
//float IrisMask = GBuffer.CustomData.z;
float3 IrisNormal;
IrisNormal = OctahedronToUnitVector(irisNormal * 2 - 1);
// Blend in the negative intersection normal to create some concavity
// Not great as it ties the concavity to the convexity of the cornea surface
// No good justification for that. On the other hand, if we're just looking to
// introduce some concavity, this does the job.
float3 CausticNormal = normalize(lerp(IrisNormal, -normal, irisMask*irisDistance));
float NdotL = saturate(dot(IrisNormal, light.dir));
float Power = lerp(12, 1, NdotL);
float Caustic = 0.6 + 0.2 * (Power + 1) * pow(saturate(dot(CausticNormal, light.dir)), Power);
float Iris = NdotL * Caustic;
// http://blog.stevemcauley.com/2011/12/03/energy-conserving-wrapped-diffuse/
float Wrap = 0.15;
float Sclera = saturate((dot(normal, light.dir) + Wrap) / (1 + Wrap) * (1 + Wrap));
return (1 - F) * lerp(Sclera, Iris, irisMask) * diffColor / UNITY_PI;
}
// ------------------------------------------------------------------
// Shading function selectors
//float3 SurfaceShading(/*FGBufferData GBuffer,*/ float3 LobeRoughness, float3 LobeEnergy, float3 L, float3 V, half3 N, uint2 Random)
float4 SurfaceShading(float3 diffColor, float3 specColor, float oneMinusReflectivity, float smoothness, float3 normal,
float3x3 worldVectors, float anisotropy, float4 customData, float metallic, float3 viewDir, UnityLight light, UnityIndirect gi)
{
#if defined(SHADINGMODELID_UNLIT)
{
return UnlitShading(diffColor);
}
#elif defined(SHADINGMODELID_STANDARD) || defined(SHADINGMODELID_SUBSURFACE) || defined(SHADINGMODELID_SKIN) || defined(SHADINGMODELID_FOLIAGE)
{
return StandardShading(diffColor, specColor, oneMinusReflectivity, smoothness,
normal, worldVectors, anisotropy, metallic, viewDir, light, gi);
}
#elif defined (SHADINGMODELID_CLEARCOAT)
{
return float4(1, 1, 1, 1); //ClearCoatShading(GBuffer, LobeRoughness, LobeEnergy, L, V, N);
}
#elif defined (SHADINGMODELID_CLOTH)
{
return ClothShading(diffColor, specColor, customData.rgb, customData.a, oneMinusReflectivity, smoothness, normal, viewDir, light, gi, worldVectors, anisotropy);
}
#elif defined (SHADINGMODELID_EYE)
{
return EyeShading(diffColor, specColor, viewDir, normal, smoothness, oneMinusReflectivity, light, gi); //EyeShading(GBuffer, LobeRoughness, LobeEnergy, L, V, N);
}
#endif
return float4(0, 0, 0, 0);
}
//float3 SubsurfaceShading(/*FGBufferData GBuffer,*/ float3 L, float3 V, half3 N, float Shadow, uint2 Random)
float3 SubsurfaceShading(float3 diffColor, float3 specColor, float3 normal, float smoothness, float3 viewDir, float4 customData, UnityLight light)
{
#if defined (SHADINGMODELID_SUBSURFACE)
{
return SubsurfaceShadingSimple(diffColor, normal, viewDir, customData.rgb, light);
}
#elif defined (SHADINGMODELID_SKIN)
{
return float3(0, 0, 0); //SubsurfaceShadingPreintegratedSkin(GBuffer, L, V, N);
}
#elif defined (SHADINGMODELID_FOLIAGE)
{
return float3(0, 0, 0); //SubsurfaceShadingTwoSided(SubsurfaceColor, L, V, N);
}
#elif defined (SHADINGMODELID_HAIR)
{
return float3(0, 0, 0); //HairShading(GBuffer, L, V, N, Shadow, 1, 0, Random);
}
#elif defined (SHADINGMODELID_EYE)
{
return EyeSubsurfaceShading(diffColor, specColor, viewDir, normal, smoothness, customData, light); //EyeSubsurfaceShading(GBuffer, L, V, N);
}
#endif
return float3(0, 0, 0);
}
//#endif UNITY_ADVANCED_SHADINGMODELS_INCLUDED
//-------------------------------------------------------------------------------------
// Lighting Helpers
// Glossy Environment
half3 Unity_AnisotropicGlossyEnvironment(UNITY_ARGS_TEXCUBE(tex), half4 hdr, Unity_GlossyEnvironmentData glossIn, half anisotropy) //Reference IBL from HD Pipe (Add half3 L input and replace R)
{
half perceptualRoughness = glossIn.roughness /* perceptualRoughness */;
// TODO: CAUTION: remap from Morten may work only with offline convolution, see impact with runtime convolution!
// For now disabled
#if 0
float m = PerceptualRoughnessToRoughness(perceptualRoughness); // m is the real roughness parameter
const float fEps = 1.192092896e-07F; // smallest such that 1.0+FLT_EPSILON != 1.0 (+1e-4h is NOT good here. is visibly very wrong)
float n = (2.0 / max(fEps, m*m)) - 2.0; // remap to spec power. See eq. 21 in --> https://dl.dropboxusercontent.com/u/55891920/papers/mm_brdf.pdf
n /= 4; // remap from n_dot_h formulatino to n_dot_r. See section "Pre-convolved Cube Maps vs Path Tracers" --> https://s3.amazonaws.com/docs.knaldtech.com/knald/1.0.0/lys_power_drops.html
perceptualRoughness = pow(2 / (n + 2), 0.25); // remap back to square root of real roughness (0.25 include both the sqrt root of the conversion and sqrt for going from roughness to perceptualRoughness)
#else
// MM: came up with a surprisingly close approximation to what the #if 0'ed out code above does.
perceptualRoughness = perceptualRoughness*(1.7 - 0.7*perceptualRoughness);
#endif
half mip = perceptualRoughnessToMipmapLevel(perceptualRoughness);
half3 R = glossIn.reflUVW;// -half3(anisotropy, 0, 0);
half4 rgbm = UNITY_SAMPLE_TEXCUBE_LOD(tex, R, mip);
return DecodeHDR(rgbm, hdr);
}
// Indirect Specular
inline half3 UnityGI_AnisotropicIndirectSpecular(UnityGIInput data, half occlusion, Unity_GlossyEnvironmentData glossIn, half anisotropy, half3x3 worldVectors)
{
half3 specular;
float3 tangentX = worldVectors[0];
float3 tangentY = worldVectors[1];
float3 N = worldVectors[2];
float3 V = data.worldViewDir;
float3 iblNormalWS = GetAnisotropicModifiedNormal(tangentY, N, V, anisotropy);
float3 iblR = reflect(-V, iblNormalWS);
#ifdef UNITY_SPECCUBE_BOX_PROJECTION
// we will tweak reflUVW in glossIn directly (as we pass it to Unity_GlossyEnvironment twice for probe0 and probe1), so keep original to pass into BoxProjectedCubemapDirection
#pragma target 3.0
#pragma surface surf Standard vertex:vert
#pragma glsl
#pragma debug
half3 originalReflUVW = glossIn.reflUVW;
glossIn.reflUVW = BoxProjectedCubemapDirection(iblR, data.worldPos, data.probePosition[0], data.boxMin[0], data.boxMax[0]);
#endif
#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 _GLOSSYREFLECTIONS_OFF
specular = unity_IndirectSpecColor.rgb;
#else
half3 env0 = Unity_AnisotropicGlossyEnvironment(UNITY_PASS_TEXCUBE(unity_SpecCube0), data.probeHDR[0], glossIn, anisotropy);
//half3 env0 = Unity_AnisotropicGlossyEnvironment(UNITY_PASS_TEXCUBE(unity_SpecCube0), data.probeHDR[0], glossIn, anisotropy, L); //Reference IBL from HD Pipe
#ifdef UNITY_SPECCUBE_BLENDING
const float kBlendFactor = 0.99999;
float blendLerp = data.boxMin[0].w;
UNITY_BRANCH
if (blendLerp < kBlendFactor)
{
#ifdef UNITY_SPECCUBE_BOX_PROJECTION
glossIn.reflUVW = BoxProjectedCubemapDirection(iblR, data.worldPos, data.probePosition[1], data.boxMin[1], data.boxMax[1]);
#endif
half3 env1 = Unity_AnisotropicGlossyEnvironment(UNITY_PASS_TEXCUBE_SAMPLER(unity_SpecCube1, unity_SpecCube0), data.probeHDR[1], glossIn, anisotropy);
//half3 env1 = Unity_AnisotropicGlossyEnvironment(UNITY_PASS_TEXCUBE_SAMPLER(unity_SpecCube1, unity_SpecCube0), data.probeHDR[1], glossIn, anisotropy, L); //Reference IBL from HD Pipe
specular = lerp(env1, env0, blendLerp);
}
else
#ifdef UNITY_COMPILER_HLSL
#endif
inline void unity_HeightToNormal (Texture2D heightmap, float2 texCoord, float texOffset, float strength, out float3 normalRes)
specular = env0;
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);
#else
specular = env0;
#endif
#endif
return specular * occlusion;// *weightOverPdf; //Reference IBL from HD Pipe
//return specular * occlusion * weightOverPdf; //Reference IBL from HD Pipe
}
// Global Illumination
inline UnityGI UnityAnisotropicGlobalIllumination(UnityGIInput data, half occlusion, half3 normalWorld, Unity_GlossyEnvironmentData glossIn, half anisotropy, half3x3 worldVectors)
{
UnityGI o_gi = UnityGI_Base(data, occlusion, normalWorld);
o_gi.indirect.specular = UnityGI_AnisotropicIndirectSpecular(data, occlusion, glossIn, anisotropy, worldVectors);
return o_gi;
}
//-------------------------------------------------------------------------------------
// Lighting Functions
//Surface Description
struct SurfaceOutputAdvanced
{
fixed3 Albedo; // base (diffuse or specular) color
fixed3 Normal; // tangent space normal, if written
half3 Emission;
half Metallic; // 0=non-metal, 1=metal
// Smoothness is the user facing name, it should be perceptual smoothness but user should not have to deal with it.
// Everywhere in the code you meet smoothness it is perceptual smoothness
half Smoothness; // 0=rough, 1=smooth
half Occlusion; // occlusion (default 1)
fixed Alpha; // alpha for transparencies
half3 Tangent;
half Anisotropy;
half4 CustomData;
float3x3 WorldVectors;
//half ShadingModel;
};
inline half4 LightingAdvanced(SurfaceOutputAdvanced s, half3 viewDir, UnityGI gi)
{
s.Normal = normalize(s.Normal);
half oneMinusReflectivity;
half3 specColor;
s.Albedo = DiffuseAndSpecularFromMetallic(s.Albedo, s.Metallic, /*out*/ specColor, /*out*/ oneMinusReflectivity);
// shader relies on pre-multiply alpha-blend (_SrcBlend = One, _DstBlend = OneMinusSrcAlpha)
// this is necessary to handle transparency in physically correct way - only diffuse component gets affected by alpha
half outputAlpha;
s.Albedo = PreMultiplyAlpha(s.Albedo, s.Alpha, oneMinusReflectivity, /*out*/ outputAlpha);
half4 c = SurfaceShading(s.Albedo, specColor, oneMinusReflectivity, s.Smoothness, s.Normal, s.WorldVectors, s.Anisotropy, s.CustomData, s.Metallic, viewDir, gi.light, gi.indirect);
c.rgb += SubsurfaceShading(s.Albedo, specColor, s.Normal, s.Smoothness, viewDir, s.CustomData, gi.light);
//c.rgb += UNITY_BRDF_GI(s.Albedo, specColor, oneMinusReflectivity, s.Smoothness, s.Normal, viewDir, s.Occlusion, gi);
c.a = outputAlpha;
return c;
}
//This is pointless as always forward?
inline half4 LightingAdvanced_Deferred(SurfaceOutputAdvanced s, half3 viewDir, UnityGI gi, out half4 outGBuffer0, out half4 outGBuffer1, out half4 outGBuffer2)
{
half oneMinusReflectivity;
half3 specColor;
s.Albedo = DiffuseAndSpecularFromMetallic(s.Albedo, s.Metallic, /*out*/ specColor, /*out*/ oneMinusReflectivity);
half4 c = SurfaceShading(s.Albedo, specColor, oneMinusReflectivity, s.Smoothness, s.Normal, s.WorldVectors, s.Anisotropy, s.CustomData, s.Metallic, viewDir, gi.light, gi.indirect);
c.rgb += SubsurfaceShading(s.Albedo, specColor, s.Normal, s.Smoothness, viewDir, s.CustomData, gi.light);
UnityStandardData data;
data.diffuseColor = s.Albedo;
data.occlusion = s.Occlusion;
data.specularColor = specColor;
data.smoothness = s.Smoothness;
data.normalWorld = s.Normal;
UnityStandardDataToGbuffer(data, outGBuffer0, outGBuffer1, outGBuffer2);
half4 emission = half4(s.Emission + c.rgb, 1);
return emission;
}
inline void LightingAdvanced_GI(SurfaceOutputAdvanced s, UnityGIInput data, inout UnityGI gi)
{
#if defined(UNITY_PASS_DEFERRED) && UNITY_ENABLE_REFLECTION_BUFFERS
gi = UnityGlobalIllumination(data, s.Occlusion, s.Normal);
#else
Unity_GlossyEnvironmentData g = UnityGlossyEnvironmentSetup(s.Smoothness, data.worldViewDir, s.Normal, lerp(unity_ColorSpaceDielectricSpec.rgb, s.Albedo, s.Metallic));
gi = UnityAnisotropicGlobalIllumination(data, s.Occlusion, s.Normal, g, s.Anisotropy, s.WorldVectors);
#endif
}
///END
#pragma target 5.0
#pragma surface surf Advanced vertex:vert
#pragma glsl
#pragma debug
float4 Color_eb55295a_2a33_4a48_b612_9d279e2cf480_Uniform;
float Vector1_58a74627_6519_4fc6_ac27_ff4e37beadf7_Uniform;
float4 worldTangent;
float3 worldNormal;
half4 meshUV0;
};

o.worldTangent = float4(UnityObjectToWorldDir(v.tangent.xyz), v.tangent.w);
o.meshUV0 = v.texcoord;
void surf (Input IN, inout SurfaceOutputAdvanced o)
void surf (Input IN, inout SurfaceOutputStandard o)
float3 worldSpaceTangent = normalize(IN.worldTangent.xyz);
float3 worldSpaceNormal = normalize(IN.worldNormal);
float3 worldSpaceBitangent = cross(worldSpaceNormal, worldSpaceTangent) * IN.worldTangent.w;
o.Albedo = Color_eb55295a_2a33_4a48_b612_9d279e2cf480_Uniform;
o.Metallic = Vector1_58a74627_6519_4fc6_ac27_ff4e37beadf7_Uniform;
o.Smoothness = Vector1_58a74627_6519_4fc6_ac27_ff4e37beadf7_Uniform;
o.Anisotropy = Vector1_58a74627_6519_4fc6_ac27_ff4e37beadf7_Uniform;
o.WorldVectors = float3x3(worldSpaceTangent, worldSpaceBitangent, worldSpaceNormal);
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;
}
ENDCG

FallBack "Diffuse"
CustomEditor "LegacyIlluminShaderGUI"
}

8
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Implementation/NodeUtils.cs


Exclude
}
public static void DepthFirstCollectNodesFromNode(List<INode> nodeList, INode node, IncludeSelf includeSelf = IncludeSelf.Include)
public static void DepthFirstCollectNodesFromNode(List<INode> nodeList, INode node, IncludeSelf includeSelf = IncludeSelf.Include, List<int>slotIds = null)
{
// no where to start
if (node == null)

remapper.DepthFirstCollectNodesFromNodeSlotList(nodeList, includeSelf);
return;
}
var ids = node.GetInputSlots<ISlot>().Select(x => x.id);
if (slotIds != null)
ids = node.GetInputSlots<ISlot>().Where(x => slotIds.Contains(x.id)).Select(x => x.id);
foreach (var slot in node.GetInputSlots<ISlot>().Select(x => x.id))
foreach (var slot in ids)
{
foreach (var edge in node.owner.GetEdges(node.GetSlotReference(slot)))
{

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

2
MaterialGraphProject/Assets/Matt/EyeMaster.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

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/AbstractMaterialGraphInspector.cs


{
get
{
yield return new TypeMapping(typeof(AbstractSurfaceMasterNode), typeof(SurfaceMasterNodeInspector));
yield return new TypeMapping(typeof(AbstractSurfaceMasterNode), typeof(SurfaceMasterNodeInspector));
yield return new TypeMapping(typeof(PropertyNode), typeof(PropertyNodeInspector));
yield return new TypeMapping(typeof(SubGraphInputNode), typeof(SubgraphInputNodeInspector));
yield return new TypeMapping(typeof(SubGraphOutputNode), typeof(SubgraphOutputNodeInspector));
}

8
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/ColorNodePresenter.cs


using System.Collections.Generic;
using RMGUI.GraphView;
using UnityEditor.Graphing.Drawing;
using UnityEngine;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.Drawing
{

if (cNode == null)
return;
cNode.color = EditorGUILayout.ColorField("Color", cNode.color);
cNode.exposedState = (PropertyNode.ExposedState)EditorGUILayout.EnumPopup(new GUIContent("Exposed"), cNode.exposedState);
cNode.color = EditorGUILayout.ColorField(new GUIContent ("Color"), cNode.color, true, true, cNode.HDR, new ColorPickerHDRConfig(0f, 8f, 0.125f, 3f));
cNode.HDR = EditorGUILayout.Toggle("HDR", cNode.HDR);
return EditorGUIUtility.singleLineHeight + 2 * EditorGUIUtility.standardVerticalSpacing;
return EditorGUIUtility.singleLineHeight + 18 * EditorGUIUtility.standardVerticalSpacing;
}
}

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


if (codeEditorPopup == null)
{
codeEditorPopup = new CodeEditorPopup(tNode);
tNode.Code = "//Write your function below.\r\nvoid test(float a, float b, out float c)\r\n{\r\n\tc = a + b;\r\n}\r\n";
if (string.IsNullOrEmpty(tNode.Code))
{
tNode.Code = "//Write your function below.\r\nvoid test(float a, float b, out float c)\r\n{\r\n\tc = a + b;\r\n}\r\n";
}
}
string buttonText = codeEditorPopup.IsOpen ? "Close Code Editor" : "Open Code Editor";

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


using UnityEditor.Graphing.Drawing;
using UnityEngine.MaterialGraph;
using System.Collections.Generic;
using System.Linq;
using RMGUI.GraphView;
namespace UnityEditor.MaterialGraph.Drawing
{

{
typeMapper[typeof(AbstractMaterialNode)] = typeof(MaterialNodePresenter);
typeMapper[typeof(ColorNode)] = typeof(ColorNodePresenter);
typeMapper[typeof(GradientNode)] = typeof(GradientNodePresenter);
typeMapper[typeof(ScatterNode)] = typeof(ScatterNodePresenter);
typeMapper[typeof(TextureSamplerNode)] = typeof(TextureSamplerNodePresenter);
typeMapper[typeof(SamplerStateNode)] = typeof(SamplerStateNodePresenter);
typeMapper[typeof(CubemapNode)] = typeof(CubeNodePresenter);
typeMapper[typeof(ToggleNode)] = typeof(ToggleNodePresenter);
typeMapper[typeof(UVNode)] = typeof(UVNodePresenter);

typeMapper[typeof(AddManyNode)] = typeof(AddManyNodePresenter);
typeMapper[typeof(IfNode)] = typeof(IfNodePresenter);
typeMapper[typeof(CustomCodeNode)] = typeof(CustomCodePresenter);
typeMapper[typeof(Matrix2Node)] = typeof(Matrix2NodePresenter);
typeMapper[typeof(Matrix3Node)] = typeof(Matrix3NodePresenter);
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)
{
return allChildren.OfType<NodeAnchorPresenter>()
.Where(nap => nap.IsConnectable() &&
nap.orientation == startAnchor.orientation &&
nap.direction != startAnchor.direction &&
nodeAdapter.GetAdapter(nap.source, startAnchor.source) != null &&
(startAnchor is GraphAnchorPresenter && ((GraphAnchorPresenter)nap).slot is MaterialSlot &&
((MaterialSlot)((GraphAnchorPresenter)startAnchor).slot).IsCompatibleWithInputSlotType(((MaterialSlot)((GraphAnchorPresenter)nap).slot).valueType)))
.ToList();
}
}
}

49
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Vector1NodePresenter.cs


using RMGUI.GraphView;
using UnityEditor.Graphing.Drawing;
using UnityEngine.MaterialGraph;
using UnityEngine;
public override void OnGUIHandler()
{
base.OnGUIHandler();

return;
tNode.value = EditorGUILayout.FloatField("Value:", tNode.value);
tNode.floatType = (FloatPropertyChunk.FloatType)EditorGUILayout.EnumPopup ("Float", tNode.floatType);
Vector3 ranges = tNode.rangeValues;
switch(tNode.floatType){
case FloatPropertyChunk.FloatType.Float:
tNode.floatType = FloatPropertyChunk.FloatType.Float;
tNode.value = EditorGUILayout.FloatField ("Value:", tNode.value);
break;
case FloatPropertyChunk.FloatType.Range:
tNode.floatType = FloatPropertyChunk.FloatType.Range;
tNode.value = EditorGUILayout.Slider (tNode.value, tNode.rangeValues.x, tNode.rangeValues.y);
EditorGUILayout.BeginHorizontal ();
ranges.x = EditorGUILayout.FloatField (ranges.x);
//very dirty...
for (int i = 0; i < 15; i++) {
EditorGUILayout.Space ();
}
ranges.y = EditorGUILayout.FloatField (ranges.y);
EditorGUILayout.EndHorizontal ();
tNode.rangeValues = ranges;
break;
case FloatPropertyChunk.FloatType.PowerSlider:
tNode.floatType = FloatPropertyChunk.FloatType.PowerSlider;
tNode.value = EditorGUILayout.Slider (tNode.value, tNode.rangeValues.x, tNode.rangeValues.y);
EditorGUILayout.BeginHorizontal ();
ranges.x = EditorGUILayout.FloatField (ranges.x);
ranges.y = EditorGUILayout.FloatField (ranges.y);
//power needs to be name
ranges.z = EditorGUILayout.FloatField (ranges.z);
EditorGUILayout.EndHorizontal ();
tNode.rangeValues = ranges;
break;
case FloatPropertyChunk.FloatType.Toggle:
bool toggleState = tNode.value == 0f ? false : true;
tNode.floatType = FloatPropertyChunk.FloatType.Toggle;
toggleState = EditorGUILayout.Toggle (toggleState);
tNode.value = toggleState == true ? 1f : 0f;
break;
}
return (EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing) + EditorGUIUtility.standardVerticalSpacing;
return (EditorGUIUtility.singleLineHeight + 16 * EditorGUIUtility.standardVerticalSpacing) + EditorGUIUtility.standardVerticalSpacing;
}
}

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


Shader "Graph/UnityEngine.MaterialGraph.MetallicMasterNode56fdded2-bae1-4a2c-b2db-6e9c206bf8ff"
Shader "Graph/UnityEngine.MaterialGraph.MetallicMasterNode68c240e8-1bfd-46d4-86b7-3459bc630675"
Vector1_681e693a_7812_42ab_a37b_8a1edc00d63e_Uniform("", Float) = 0.005
Vector1_bc1392c9_f4d7_47a8_8add_f4f4b00fdfe5_Uniform("", Float) = 0
Vector1_36d8f7c7_3ada_4604_9149_df2ba1745b80_Uniform("", Float) = 8
}

#pragma glsl
#pragma debug
inline float4 unity_add_float (float4 arg1, float4 arg2)
{
return arg1 + arg2;
}
inline float2 unity_multiply_float (float2 arg1, float2 arg2)
{
return arg1 * arg2;
}
inline float2 unity_voronoi_noise_randomVector (float2 uv, float offset)
{
float2x2 m = float2x2(15.27, 47.63, 99.41, 89.98);
uv = frac(sin(mul(uv, m)) * 46839.32);
return float2(sin(uv.y*+offset)*0.5+0.5, cos(uv.x*offset)*0.5+0.5);
}
inline float unity_voronoinoise_float (float2 uv, float angleOffset)
{
float2 g = floor(uv);
float2 f = frac(uv);
float t = 8.0;
float3 res = float3(8.0, 0.0, 0.0);
for(int y=-1; y<=1; y++)
{
for(int x=-1; x<=1; x++)
{
float2 lattice = float2(x,y);
float2 offset = unity_voronoi_noise_randomVector(lattice + g, angleOffset);
float d = distance(lattice + offset, f);
if(d < res.x)
{
res = float3(d, offset.x, offset.y);
}
}
}
return res.x;
}
inline float unity_oneminus_float (float arg1)
{
return arg1 * -1 + 1;
}
inline float4 unity_multiply_float (float4 arg1, float4 arg2)
{
return arg1 * arg2;
}
inline float unity_subtract_float (float arg1, float arg2)
{
return arg1 - arg2;
}
inline float unity_multiply_float (float arg1, float arg2)
{
return arg1 * arg2;
}
float Vector1_681e693a_7812_42ab_a37b_8a1edc00d63e_Uniform;
float Vector1_bc1392c9_f4d7_47a8_8add_f4f4b00fdfe5_Uniform;
float Vector1_36d8f7c7_3ada_4604_9149_df2ba1745b80_Uniform;
half4 meshUV0;
};

o.meshUV0 = v.texcoord;
half4 uv0 = IN.meshUV0;
float4 Color_a5c79f09_af3c_413d_a03a_0fbcda1f305f_Uniform = float4 (0.5588235, 0.5588235, 0.5588235, 0);
float Vector1_b212d213_1dc1_491d_8dbf_0add4ab24246_Uniform = 1;
float Vector1_c753024a_f95d_4487_bcb7_13a86e18dd68_Uniform = 0;
float4 Combine_523239ba_f790_4fca_a9e2_babb69c74568_Output = float4(Vector1_681e693a_7812_42ab_a37b_8a1edc00d63e_Uniform,Vector1_bc1392c9_f4d7_47a8_8add_f4f4b00fdfe5_Uniform,0.0, 0.0);
float4 UV_2eb2b635_fc17_44ea_90c4_c1188f10857b_UV = uv0;
float4 Add_2c8c5705_3762_4ed4_b2de_b611d458bd65_Output = unity_add_float (Combine_523239ba_f790_4fca_a9e2_babb69c74568_Output, UV_2eb2b635_fc17_44ea_90c4_c1188f10857b_UV);
float4 Split_0c1c11c9_9ee2_40d8_9cb0_b913d2f3e22a = float4(Add_2c8c5705_3762_4ed4_b2de_b611d458bd65_Output);
float2 Multiply_f3f41634_3594_48d4_b7b6_3104b523e7dd_Output = unity_multiply_float (Split_0c1c11c9_9ee2_40d8_9cb0_b913d2f3e22a.rg, float2 (20,20));
float VoronoiNoise_175ef02c_a94e_44e5_9668_dff18e2112fe_Output = unity_voronoinoise_float (Multiply_f3f41634_3594_48d4_b7b6_3104b523e7dd_Output, _Time.w);
float OneMinus_0b02f4c6_d95f_4305_9d7c_5e720ad0d2c4_Output = unity_oneminus_float (VoronoiNoise_175ef02c_a94e_44e5_9668_dff18e2112fe_Output);
float4 Multiply_766862d4_1f32_4bdc_93ba_e17532ee9f8b_Output = unity_multiply_float (UV_2eb2b635_fc17_44ea_90c4_c1188f10857b_UV, float4 (20,20,0,0));
float VoronoiNoise_b5d8acbb_4b86_4780_8ba2_9b79cdf9b0ba_Output = unity_voronoinoise_float (Multiply_766862d4_1f32_4bdc_93ba_e17532ee9f8b_Output, _Time.w);
float OneMinus_95c0d854_a598_4448_b1ec_19f0ae2e3207_Output = unity_oneminus_float (VoronoiNoise_b5d8acbb_4b86_4780_8ba2_9b79cdf9b0ba_Output);
float Subtract_d442f4ab_3183_4dba_88bb_12b82b1e4b22_Output = unity_subtract_float (OneMinus_0b02f4c6_d95f_4305_9d7c_5e720ad0d2c4_Output, OneMinus_95c0d854_a598_4448_b1ec_19f0ae2e3207_Output);
float Multiply_223da849_596f_4a92_ac44_065f9082e924_Output = unity_multiply_float (Subtract_d442f4ab_3183_4dba_88bb_12b82b1e4b22_Output, Vector1_36d8f7c7_3ada_4604_9149_df2ba1745b80_Uniform);
float4 Combine_261925f9_60e1_402b_9b71_69912cd8c284_Output = float4(Vector1_b212d213_1dc1_491d_8dbf_0add4ab24246_Uniform,Vector1_c753024a_f95d_4487_bcb7_13a86e18dd68_Uniform,Multiply_223da849_596f_4a92_ac44_065f9082e924_Output,0.0);
float4 Split_637f528c_802b_4b35_abbe_e94b103a0f9a = float4(Combine_261925f9_60e1_402b_9b71_69912cd8c284_Output);
float4 Combine_1399c2cd_55f2_48bf_a413_58c773e76556_Output = float4(Vector1_bc1392c9_f4d7_47a8_8add_f4f4b00fdfe5_Uniform,Vector1_681e693a_7812_42ab_a37b_8a1edc00d63e_Uniform,0.0, 0.0);
float4 Add_3698bc9c_3a9c_4f77_86ad_50ac01252625_Output = unity_add_float (UV_2eb2b635_fc17_44ea_90c4_c1188f10857b_UV, Combine_1399c2cd_55f2_48bf_a413_58c773e76556_Output);
float4 Multiply_94a1c8a0_7a01_42a5_baf8_3460cc52ccce_Output = unity_multiply_float (Add_3698bc9c_3a9c_4f77_86ad_50ac01252625_Output, float4 (20,20,0,0));
float VoronoiNoise_041c0818_8a7a_490c_ae6b_362b2e498fa6_Output = unity_voronoinoise_float (Multiply_94a1c8a0_7a01_42a5_baf8_3460cc52ccce_Output, _Time.w);
float OneMinus_b7c5d2e2_90e6_4cb2_be5c_3aa34ea18363_Output = unity_oneminus_float (VoronoiNoise_041c0818_8a7a_490c_ae6b_362b2e498fa6_Output);
float Subtract_c4f59a4e_29c0_4f5e_92c7_52ab56cc6a23_Output = unity_subtract_float (OneMinus_b7c5d2e2_90e6_4cb2_be5c_3aa34ea18363_Output, OneMinus_95c0d854_a598_4448_b1ec_19f0ae2e3207_Output);
float Multiply_f3bd2e5b_f8c4_486a_83c8_df44e04bc77a_Output = unity_multiply_float (Vector1_36d8f7c7_3ada_4604_9149_df2ba1745b80_Uniform, Subtract_c4f59a4e_29c0_4f5e_92c7_52ab56cc6a23_Output);
float4 Combine_d1411122_6465_494a_88e6_98e96eba037a_Output = float4(Vector1_c753024a_f95d_4487_bcb7_13a86e18dd68_Uniform,Vector1_b212d213_1dc1_491d_8dbf_0add4ab24246_Uniform,Multiply_f3bd2e5b_f8c4_486a_83c8_df44e04bc77a_Output,0.0);
float4 Split_bdd63fad_c244_45a4_ae4c_ed756a69ac03 = float4(Combine_d1411122_6465_494a_88e6_98e96eba037a_Output);
float3 CrossProduct_0955bdd9_9b65_4141_b394_1b86aa4c7d3f_Output = cross (Split_637f528c_802b_4b35_abbe_e94b103a0f9a.rgb, Split_bdd63fad_c244_45a4_ae4c_ed756a69ac03.rgb);
o.Albedo = Color_a5c79f09_af3c_413d_a03a_0fbcda1f305f_Uniform;
o.Normal = CrossProduct_0955bdd9_9b65_4141_b394_1b86aa4c7d3f_Output;
o.Normal += 1e-6;
}
ENDCG

FallBack "Diffuse"
CustomEditor "LegacyIlluminShaderGUI"
}

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


fileFormatVersion: 2
guid: 9ab5e16c2083a4fe689209a8c1ae425e
timeCreated: 1495630928
timeCreated: 1495720140
defaultTextures:
- TextureAsset_ebbe75eb_728a_4e6c_b8a1_994df86c74ad_Uniform: {fileID: 2800000, guid: 225a31f233f5b82488f996901413908d,
type: 3}
nonModifiableTextures:
- Texture_94ba0aed_e579_4ba0_b677_86c6deda72a2_Uniform: {fileID: 2800000, guid: 9c50a18d04437449b86568cfcbb668a7,
type: 3}
- Texture_65e72eb9_bdc7_4c17_b514_379aaeefd7ca_Uniform: {fileID: 2800000, guid: 84462bdfeee9d694bbebf34e5f3faa74,
type: 3}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

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


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

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/PropertyChunkTests.cs


public void TestColorChunkReturnsValidValues()
{
var expectedPropertyString = "ThePropertyName(\"ThePropertyDescription\", Color) = (1,0,0,1)";
var chunk = new ColorPropertyChunk(kPropertyName, kPropertyDescription, Color.red, PropertyChunk.HideState.Visible);
var chunk = new ColorPropertyChunk(kPropertyName, kPropertyDescription, Color.red, ColorPropertyChunk.ColorType.Default, PropertyChunk.HideState.Visible);
Assert.AreEqual(kPropertyName, chunk.propertyName);
Assert.AreEqual(kPropertyDescription, chunk.propertyDescription);
Assert.AreEqual(expectedPropertyString, chunk.GetPropertyString());

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


m_Graph.AddNode(m_PropertyNode);
}
[Test]
/* [Test]
public void TestExposedPropertyReturnsRawName()
{
m_PropertyNode.exposedState = PropertyNode.ExposedState.Exposed;

m_Vector2Node.ValidateNode();
Assert.IsFalse(m_Vector1Node.hasError);
Assert.IsFalse(m_Vector2Node.hasError);
}
}*/
[Test]
public void TestPropertyExposedOnSubgraphReturnsFalse()

43
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:
return ConcreteSlotValueType.Matrix3;
case SlotValueType.Matrix4:
return ConcreteSlotValueType.Matrix4;
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:
return "3x3";
case ConcreteSlotValueType.Matrix4:
return "4x4";
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.Vector3;
case ConcreteSlotValueType.Vector4:
return PropertyType.Vector4;
case ConcreteSlotValueType.Matrix2:
return PropertyType.Matrix2;
case ConcreteSlotValueType.Matrix3:
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); }
}

23
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/ColorNode.cs


[Title("Input/Color")]
public class ColorNode : PropertyNode, IGeneratesBodyCode
{
[SerializeField]
[SerializeField]
private bool m_HDR;
[SerializeField]
public bool HDR
{
get { return m_HDR; }
set
{
if (m_HDR == value)
return;
m_HDR = value;
if (onModified != null)
{
onModified(this, ModificationScope.Node);
}
}
}
public ColorNode()
{

public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode)
{
if (exposedState == ExposedState.Exposed)
visitor.AddShaderProperty(new ColorPropertyChunk(propertyName, description, color, PropertyChunk.HideState.Visible));
visitor.AddShaderProperty(new ColorPropertyChunk(propertyName, description, color, m_HDR ? ColorPropertyChunk.ColorType.HDR : ColorPropertyChunk.ColorType.Default , PropertyChunk.HideState.Visible));
}
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)

14
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Texture/CubemapNode.cs


protected const string kOutputSlotAName = "A";
protected const string kInputSlotLodName = "MipLevel";
public const int UvSlotId = 0;
public const int RefDirSlot = 0;
public const int InputSlotLod = 6;
public const int OutputSlotRgbaId = 1;
public const int OutputSlotRId = 2;

AddSlot(new MaterialSlot(OutputSlotGId, kOutputSlotGName, kOutputSlotGName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotBId, kOutputSlotBName, kOutputSlotBName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotAId, kOutputSlotAName, kOutputSlotAName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(UvSlotId, kUVSlotName, kUVSlotName, SlotType.Input, SlotValueType.Vector3, Vector3.zero, false));
AddSlot(new MaterialSlot(RefDirSlot, kUVSlotName, kUVSlotName, SlotType.Input, SlotValueType.Vector3, Vector3.zero, false));
AddSlot (new MaterialSlot(InputSlotLod, kInputSlotLodName, kInputSlotLodName, SlotType.Input, SlotValueType.Vector1, Vector2.zero));
RemoveSlotsNameNotMatching(validSlots);
}

protected int[] validSlots
{
get { return new[] {OutputSlotRgbaId, OutputSlotRId, OutputSlotGId, OutputSlotBId, OutputSlotAId, UvSlotId, InputSlotLod}; }
get { return new[] {OutputSlotRgbaId, OutputSlotRId, OutputSlotGId, OutputSlotBId, OutputSlotAId, RefDirSlot, InputSlotLod}; }
var uvSlot = FindInputSlot<MaterialSlot>(UvSlotId);
var uvSlot = FindInputSlot<MaterialSlot>(RefDirSlot);
if (uvSlot == null)
return;

{
case OutputSlotRId:
slotOutput = ".r";
break;
case InputSlotLod:
slotOutput = "_lod";
break;
case RefDirSlot:
slotOutput = "_RefDir";
break;
case OutputSlotGId:
slotOutput = ".g";

54
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Vector/Vector1Node.cs


[SerializeField]
private float m_Value;
[SerializeField]
private FloatPropertyChunk.FloatType m_floatType;
[SerializeField]
private Vector3 m_rangeValues = new Vector3(0f, 1f, 2f);
public const int OutputSlotId = 0;
private const string kOutputSlotName = "Value";

}
}
public FloatPropertyChunk.FloatType floatType
{
get { return m_floatType; }
set
{
if (m_floatType == value)
return;
m_floatType = value;
if (onModified != null)
onModified(this, ModificationScope.Node);
}
}
public Vector3 rangeValues
{
get { return m_rangeValues; }
set
{
if (m_rangeValues == value)
return;
m_rangeValues = value;
if (onModified != null)
onModified(this, ModificationScope.Node);
}
}
if (exposedState == ExposedState.Exposed)
visitor.AddShaderProperty(new FloatPropertyChunk(propertyName, description, m_Value, PropertyChunk.HideState.Visible));
if (exposedState == ExposedState.Exposed) {
switch(m_floatType){
case FloatPropertyChunk.FloatType.Float:
visitor.AddShaderProperty (new FloatPropertyChunk (propertyName, description, m_Value, PropertyChunk.HideState.Visible));
break;
case FloatPropertyChunk.FloatType.Toggle:
visitor.AddShaderProperty (new FloatPropertyChunk (propertyName, description, m_Value, m_floatType, PropertyChunk.HideState.Visible));
break;
case FloatPropertyChunk.FloatType.Range:
visitor.AddShaderProperty (new FloatPropertyChunk (propertyName, description, m_Value, m_floatType, m_rangeValues, PropertyChunk.HideState.Visible));
break;
case FloatPropertyChunk.FloatType.PowerSlider:
visitor.AddShaderProperty (new FloatPropertyChunk (propertyName, description, m_Value, m_floatType, m_rangeValues, PropertyChunk.HideState.Visible));
break;
}
}
}
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Vector/Vector2Node.cs


if (exposedState == ExposedState.Exposed || generationMode.IsPreview())
return;
visitor.AddShaderChunk(precision + "2 " + propertyName + " = " + precision + "2 (" + m_Value.x + ", " + m_Value.y + ");", true);
visitor.AddShaderChunk(precision + "2x2 " + propertyName + " = " + precision + "2 " + propertyName + " = " + precision + "2 (" + m_Value.x + ", " + m_Value.y + ");", true);
}
public override PreviewProperty GetPreviewProperty()

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


return "(3)";
case ConcreteSlotValueType.Vector4:
return "(4)";
case ConcreteSlotValueType.Matrix2:
return "(2x2)";
case ConcreteSlotValueType.Matrix3:
return "(3x3)";
case ConcreteSlotValueType.Matrix4:
return "(4x4)";
default:
return "(E)";
}

case SlotValueType.Vector3:
concreteValueType = ConcreteSlotValueType.Vector3;
break;
case SlotValueType.Matrix2:
concreteValueType = ConcreteSlotValueType.Matrix2;
break;
case SlotValueType.Matrix3:
concreteValueType = ConcreteSlotValueType.Matrix3;
break;
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;

visitor.AddShaderChunk(matOwner.precision + AbstractMaterialNode.ConvertConcreteSlotValueTypeToString(concreteValueType) + " " + matOwner.GetVariableNameForSlot(id) + ";", true);
}
public bool IsCompatibleWithInputSlotType(SlotValueType inputType)
{
return (inputType == SlotValueType.Dynamic || valueType == SlotValueType.Vector1 || valueType <= inputType);
}
public string GetDefaultValue(GenerationMode generationMode)
{
var matOwner = owner as AbstractMaterialNode;

return matOwner.precision + "3 (" + m_CurrentValue.x + "," + m_CurrentValue.y + "," + m_CurrentValue.z + ")";
case ConcreteSlotValueType.Vector4:
return matOwner.precision + "4 (" + m_CurrentValue.x + "," + m_CurrentValue.y + "," + m_CurrentValue.z + "," + m_CurrentValue.w + ")";
case ConcreteSlotValueType.Matrix2:
return matOwner.precision + "2x2 (" + m_CurrentValue.x + ", " + m_CurrentValue.x + ", " + m_CurrentValue.y + ", "+ m_CurrentValue.y + ")";
case ConcreteSlotValueType.Matrix3:
return matOwner.precision + "3x3 (" + m_CurrentValue.x + ", " + m_CurrentValue.x + ", " + m_CurrentValue.x + ", " + m_CurrentValue.y + ", " + m_CurrentValue.y + ", " + m_CurrentValue.y + ", " + m_CurrentValue.z + ", " + m_CurrentValue.z + ", " + m_CurrentValue.z + ")";
case ConcreteSlotValueType.Matrix4:
return matOwner.precision + "4x4 (" + m_CurrentValue.x + ", " + m_CurrentValue.x + ", " + m_CurrentValue.x + ", " + m_CurrentValue.x + ", " + m_CurrentValue.y + ", " + m_CurrentValue.y + ", " + m_CurrentValue.y + ", " + m_CurrentValue.y + ", " + m_CurrentValue.z + ", " + m_CurrentValue.z + ", " + m_CurrentValue.z + ", " + m_CurrentValue.z + ", " + m_CurrentValue.w + ", " + m_CurrentValue.w + ", " + m_CurrentValue.w + ", " + m_CurrentValue.w + ")";
default:
return "error";
}

4
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Procedural/CheckerboardNode.cs


protected override MaterialSlot GetInputSlot2()
{
return new MaterialSlot(InputSlot2Id, GetInputSlot2Name(), kInputSlot2ShaderName, UnityEngine.Graphing.SlotType.Input, SlotValueType.Vector1, Vector4.zero);
return new MaterialSlot(InputSlot2Id, GetInputSlot2Name(), kInputSlot2ShaderName, UnityEngine.Graphing.SlotType.Input, SlotValueType.Vector1, new Vector4(10,0,0,0));
return new MaterialSlot(InputSlot3Id, GetInputSlot3Name(), kInputSlot3ShaderName, UnityEngine.Graphing.SlotType.Input, SlotValueType.Vector1, Vector4.zero);
return new MaterialSlot(InputSlot3Id, GetInputSlot3Name(), kInputSlot3ShaderName, UnityEngine.Graphing.SlotType.Input, SlotValueType.Vector1, new Vector4(10, 0, 0, 0));
}
protected override MaterialSlot GetOutputSlot()
{

42
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Procedural/VoronoiNoise.cs


namespace UnityEngine.MaterialGraph
{
[Title("Procedural/Voronoi Noise")]
public class VoronoiNoiseNode : Function2Input, IGeneratesFunction
public class VoronoiNoiseNode : FunctionNInNOut, IGeneratesFunction
AddSlot("UV", "uv", Graphing.SlotType.Input, SlotValueType.Vector2, Vector4.zero);
AddSlot("AngleOffset", "angleOffset", Graphing.SlotType.Input, SlotValueType.Vector1, new Vector4(2.0f,0,0,0));
AddSlot("Cellular", "n1", Graphing.SlotType.Output, SlotValueType.Vector1, Vector4.zero);
AddSlot("Tile", "n2", Graphing.SlotType.Output, SlotValueType.Vector1, Vector4.zero);
AddSlot("1 - Cellular", "n3", Graphing.SlotType.Output, SlotValueType.Vector1, Vector4.zero);
}
protected override string GetFunctionName()

protected override string GetInputSlot1Name()
{
return "UV";
}
protected override MaterialSlot GetInputSlot1()
{
return new MaterialSlot(InputSlot1Id, GetInputSlot1Name(), kInputSlot1ShaderName, UnityEngine.Graphing.SlotType.Input, SlotValueType.Vector2, Vector2.zero);
}
protected override string GetInputSlot2Name()
{
return "AngleOffset";
}
protected override MaterialSlot GetInputSlot2()
public override bool hasPreview
return new MaterialSlot(InputSlot2Id, GetInputSlot2Name(), kInputSlot2ShaderName, UnityEngine.Graphing.SlotType.Input, SlotValueType.Vector1, Vector2.zero);
}
protected override MaterialSlot GetOutputSlot()
{
return new MaterialSlot(OutputSlotId, GetOutputSlotName(), kOutputSlotShaderName, UnityEngine.Graphing.SlotType.Output, SlotValueType.Vector1, Vector2.zero);
get
{
return true;
}
}
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)

outputString.Deindent();
outputString.AddShaderChunk("}", false);
outputString.AddShaderChunk(GetFunctionPrototype("uv", "angleOffset"), false);
outputString.AddShaderChunk(GetFunctionPrototype(), false);
outputString.AddShaderChunk("{", false);
outputString.Indent();

outputString.AddShaderChunk("float3 res = float3(8.0, 0.0, 0.0);", false);
outputString.AddShaderChunk("for(int y=-1; y<=1; y++)", false);
outputString.AddShaderChunk("{", false);

outputString.Indent();
outputString.AddShaderChunk("res = float3(d, offset.x, offset.y);", false);
outputString.AddShaderChunk("n1 = res.x;", false);
outputString.AddShaderChunk("n2 = res.y;", false);
outputString.AddShaderChunk("n3 = 1.0 - res.x;", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);

outputString.Deindent();
outputString.AddShaderChunk("}", false);
outputString.AddShaderChunk("return res.x;", false);
outputString.Deindent();

12
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/PropertyNode.cs


}
[SerializeField]
private string m_PropertyName = string.Empty;
[SerializeField]
private string m_Description = string.Empty;
[SerializeField]

{
get
{
if (string.IsNullOrEmpty(m_Description))
return m_PropertyName;
return m_Description;
return string.IsNullOrEmpty(m_Description) ? name : m_Description;
}
set { m_Description = value; }
}

get
{
if (exposedState == ExposedState.NotExposed || string.IsNullOrEmpty(m_PropertyName))
return m_PropertyName + "_Uniform";
set { m_PropertyName = value; }
}
public abstract PropertyType propertyType { get; }

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


Float,
Vector2,
Vector3,
Vector4
Vector4,
Matrix2,
Matrix3,
Matrix4,
SamplerState
}
}

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


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

public enum ConcreteSlotValueType
{
sampler2D = 5,
SamplerState = 9,
Matrix4 = 8,
Matrix3 = 7,
Matrix2 = 6,
Texture2D = 5,
Vector4 = 4,
Vector3 = 3,
Vector2 = 2,

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/UV/UVTileNode.cs


protected override MaterialSlot GetInputSlot2()
{
return new MaterialSlot(InputSlot2Id, GetInputSlot2Name(), kInputSlot2ShaderName, UnityEngine.Graphing.SlotType.Input, SlotValueType.Vector2, Vector2.zero);
return new MaterialSlot(InputSlot2Id, GetInputSlot2Name(), kInputSlot2ShaderName, UnityEngine.Graphing.SlotType.Input, SlotValueType.Vector2, new Vector2(2,2));
}
protected override MaterialSlot GetOutputSlot()

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


public const string SmoothnessSlotName = "Smoothness";
public const string OcclusionSlotName = "Occlusion";
public const string AlphaSlotName = "Alpha";
public const string VertexOffsetName = "VertexPosition";
public const int AlbedoSlotId = 0;
public const int NormalSlotId = 1;

public const int AlphaSlotId = 6;
public const int VertexOffsetId = 7;
[SerializeField]
private SurfaceMaterialOptions m_MaterialOptions = new SurfaceMaterialOptions();

public abstract string GetSurfaceOutputName();
public abstract string GetLightFunction();
void GenerateNodeFunctionsAndPropertyUsages(
ShaderGenerator shaderBody,
ShaderGenerator propertyUsages,
ShaderGenerator nodeFunction,
GenerationMode mode,
int[] validNodeIds)
{
var activeNodeList = new List<INode>();
NodeUtils.DepthFirstCollectNodesFromNode(activeNodeList, this, NodeUtils.IncludeSelf.Include,
new List<int>(validNodeIds));
foreach (var node in activeNodeList.OfType<AbstractMaterialNode>())
{
if (node is IGeneratesFunction)
(node as IGeneratesFunction).GenerateNodeFunction(nodeFunction, mode);
node.GeneratePropertyUsages(propertyUsages, mode);
}
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>(vertexInputs));
for (var i = 0; i < nodes.Count; i++)
{
var node = nodes[i];
if (node is IGeneratesBodyCode)
(node as IGeneratesBodyCode).GenerateNodeCode(shaderBody, mode);
}
ListPool<INode>.Release(nodes);
}
void GenerateVertexShaderInternal(
ShaderGenerator propertyUsages,
ShaderGenerator shaderBody,
ShaderGenerator nodeFunction,
ShaderGenerator vertexShaderBlock,
GenerationMode mode)
{
GenerateNodeFunctionsAndPropertyUsages(vertexShaderBlock, propertyUsages, nodeFunction, mode, vertexInputs);
var slot = FindInputSlot<MaterialSlot>(VertexOffsetId);
foreach (var edge in owner.GetEdges(slot.slotReference))
{
var outputRef = edge.outputSlot;
var fromNode = owner.GetNodeFromGuid<AbstractMaterialNode>(outputRef.nodeGuid);
if (fromNode == null)
continue;
var remapper = fromNode as INodeGroupRemapper;
if (remapper != null && !remapper.IsValidSlotConnection(outputRef.slotId))
continue;
vertexShaderBlock.AddShaderChunk("v.vertex.xyz = " + fromNode.GetVariableNameForSlot(outputRef.slotId) + ";", true);
}
}
public override string GetSubShader(GenerationMode mode, PropertyGenerator shaderPropertiesVisitor)
{
var templateLocation = ShaderGenerator.GetTemplatePath("subshader.template");

vertexShaderBlock,
mode);
GenerateVertexShaderInternal(
shaderPropertyUsagesVisitor,
shaderBodyVisitor,
shaderFunctionVisitor,
vertexShaderBlock,
mode);
var tagsVisitor = new ShaderGenerator();
var blendingVisitor = new ShaderGenerator();
var cullingVisitor = new ShaderGenerator();

return Regex.Replace(resultShader, @"\r\n|\n\r|\n|\r", Environment.NewLine);
}
protected abstract int[] surfaceInputs
{
get;
}
protected abstract int[] vertexInputs
{
get;
}
private void GenerateSurfaceShaderInternal(
ShaderGenerator propertyUsages,
ShaderGenerator shaderBody,

GenerationMode mode)
{
var activeNodeList = new List<INode>();
NodeUtils.DepthFirstCollectNodesFromNode(activeNodeList, this);
NodeUtils.DepthFirstCollectNodesFromNode(activeNodeList, this, NodeUtils.IncludeSelf.Include,
new List<int>(surfaceInputs));
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);
}

var nodes = ListPool<INode>.Get();
//Get the rest of the nodes for all the other slots
NodeUtils.DepthFirstCollectNodesFromNode(nodes, this, NodeUtils.IncludeSelf.Exclude);
NodeUtils.DepthFirstCollectNodesFromNode(nodes, this, NodeUtils.IncludeSelf.Exclude, new List<int>(surfaceInputs));
for (var i = 0; i < nodes.Count; i++)
{
var node = nodes[i];

foreach (var slot in GetInputSlots<MaterialSlot>())
{
foreach (var edge in owner.GetEdges(slot.slotReference))
if (surfaceInputs.Contains(slot.id))
var outputRef = edge.outputSlot;
var fromNode = owner.GetNodeFromGuid<AbstractMaterialNode>(outputRef.nodeGuid);
if (fromNode == null)
continue;
foreach (var edge in owner.GetEdges(slot.slotReference))
{
var outputRef = edge.outputSlot;
var fromNode = owner.GetNodeFromGuid<AbstractMaterialNode>(outputRef.nodeGuid);
if (fromNode == null)
continue;
var remapper = fromNode as INodeGroupRemapper;
if (remapper != null && !remapper.IsValidSlotConnection(outputRef.slotId))
continue;
var remapper = fromNode as INodeGroupRemapper;
if (remapper != null && !remapper.IsValidSlotConnection(outputRef.slotId))
continue;
shaderBody.AddShaderChunk("o." + slot.shaderOutputName + " = " + fromNode.GetVariableNameForSlot(outputRef.slotId) + ";", true);
shaderBody.AddShaderChunk("o." + slot.shaderOutputName + " = " + fromNode.GetVariableNameForSlot(outputRef.slotId) + ";", true);
if (slot.id == NormalSlotId)
shaderBody.AddShaderChunk("o." + slot.shaderOutputName + " += 1e-6;", true);
if (slot.id == NormalSlotId)
shaderBody.AddShaderChunk("o." + slot.shaderOutputName + " += 1e-6;", true);
}
}
}
}

35
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SurfaceModel/MetallicMasterNode.cs


public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(VertexOffsetId, VertexOffsetName, VertexOffsetName, SlotType.Input, SlotValueType.Vector3, Vector4.zero));
AddSlot(new MaterialSlot(AlbedoSlotId, AlbedoSlotName, AlbedoSlotName, SlotType.Input, SlotValueType.Vector3, Vector4.zero));
AddSlot(new MaterialSlot(NormalSlotId, NormalSlotName, NormalSlotName, SlotType.Input, SlotValueType.Vector3, Vector4.zero));
AddSlot(new MaterialSlot(EmissionSlotId, EmissionSlotName, EmissionSlotName, SlotType.Input, SlotValueType.Vector3, Vector4.zero));

MetallicSlotId,
SmoothnessSlotId,
OcclusionSlotId,
AlphaSlotId
AlphaSlotId,
VertexOffsetId
protected override int[] surfaceInputs
{
get
{
return new[]
{
AlbedoSlotId,
NormalSlotId,
EmissionSlotId,
MetallicSlotId,
SmoothnessSlotId,
OcclusionSlotId,
AlphaSlotId,
};
}
}
protected override int[] vertexInputs
{
get
{
return new[]
{
VertexOffsetId
};
}
}
public override string GetSurfaceOutputName()
{
return SurfaceOutputStructureName;

30
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SurfaceModel/SpecularMasterNode.cs


UpdateNodeAfterDeserialization();
}
protected override int[] surfaceInputs
{
get
{
return new[]
{
AlbedoSlotId,
NormalSlotId,
EmissionSlotId,
SmoothnessSlotId,
OcclusionSlotId,
AlphaSlotId,
SpecularSlotId
};
}
}
protected override int[] vertexInputs
{
get
{
return new[]
{
VertexOffsetId
};
}
}
AddSlot(new MaterialSlot(VertexOffsetId, VertexOffsetName, VertexOffsetName, SlotType.Input, SlotValueType.Vector3, Vector4.zero));
AddSlot(new MaterialSlot(AlbedoSlotId, AlbedoSlotName, AlbedoSlotName, SlotType.Input, SlotValueType.Vector3, Vector4.zero));
AddSlot(new MaterialSlot(NormalSlotId, NormalSlotName, NormalSlotName, SlotType.Input, SlotValueType.Vector3, Vector4.zero));
AddSlot(new MaterialSlot(EmissionSlotId, EmissionSlotName, EmissionSlotName, SlotType.Input, SlotValueType.Vector3, Vector4.zero));

12
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/ColorPropertyChunk.cs


{
public class ColorPropertyChunk : PropertyChunk
{
public enum ColorType
{
Default,
HDR
}
private ColorType m_colorType;
public ColorPropertyChunk(string propertyName, string propertyDescription, Color defaultColor, HideState hideState)
public ColorPropertyChunk(string propertyName, string propertyDescription, Color defaultColor, ColorType colorType, HideState hideState)
m_colorType = colorType;
m_DefaultColor = defaultColor;
}

public override string GetPropertyString()
{
var result = new StringBuilder();
if(m_colorType == ColorType.HDR)
result.Append ("[HDR]");
result.Append(propertyName);
result.Append("(\"");
result.Append(propertyDescription);

39
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/FloatPropertyChunk.cs


{
public class FloatPropertyChunk : PropertyChunk
{
public enum FloatType
{
Float,
Toggle,
Range,
PowerSlider
}
private readonly FloatType m_FloatType;
private readonly Vector3 m_rangeValues;
public FloatPropertyChunk(string propertyName, string propertyDescription, float defaultValue, HideState hideState)
: base(propertyName, propertyDescription, hideState)
{

public FloatPropertyChunk(string propertyName, string propertyDescription, float defaultValue, FloatType floatType, HideState hideState)
: base(propertyName, propertyDescription, hideState)
{
m_FloatType = floatType;
m_DefaultValue = defaultValue;
}
public FloatPropertyChunk(string propertyName, string propertyDescription, float defaultValue, FloatType floatType, Vector3 rangeValues, HideState hideState)
: base(propertyName, propertyDescription, hideState)
{
m_FloatType = floatType;
m_rangeValues = rangeValues;
m_DefaultValue = defaultValue;
}
public float defaultValue
{
get { return m_DefaultValue; }

{
var result = new StringBuilder();
if (m_FloatType == FloatType.Toggle)
result.Append ("[Toggle]");
else if(m_FloatType == FloatType.PowerSlider)
result.Append ("[PowerSlider(" + m_rangeValues.z + ")]");
result.Append("\", Float) = ");
if (m_FloatType == FloatType.Float || m_FloatType == FloatType.Toggle) {
result.Append ("\", Float) = ");
}else if(m_FloatType == FloatType.Range || m_FloatType == FloatType.PowerSlider){
result.Append ("\", Range(");
result.Append (m_rangeValues.x + ", " + m_rangeValues.y);
result.Append (")) = ");
}
result.Append(defaultValue);
return result.ToString();
}

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;

9
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;

name = "Toggle";
UpdateNodeAfterDeserialization();
}
/* public override bool hasPreview
{
get { return true; }
}*/
public sealed override void UpdateNodeAfterDeserialization()
{

public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode)
{
if (exposedState == ExposedState.Exposed)
visitor.AddShaderProperty(new FloatPropertyChunk(propertyName, description, 0f, PropertyChunk.HideState.Visible));
visitor.AddShaderProperty(new FloatPropertyChunk(propertyName, description, 0f, FloatPropertyChunk.FloatType.Toggle, PropertyChunk.HideState.Visible));
}
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)

8
MaterialGraphProject/Assets/Andre/Scenes/Andre_scene.unity


m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1883063129}
m_LocalRotation: {x: 0.82629114, y: 0.24945803, z: -0.45485297, w: 0.21936849}
m_LocalRotation: {x: 0.826291, y: 0.249458, z: -0.4548529, w: 0.21936846}
m_LocalPosition: {x: -0.469, y: -0.431, z: -0.358}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []

m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 2080471397}
m_LocalRotation: {x: -0.07791633, y: 0.13852377, z: -0.01431427, w: -0.98718554}
m_LocalRotation: {x: 0.039958883, y: -0.06547875, z: 0.8823947, w: -0.46421504}
m_LocalScale: {x: 0.42098072, y: 0.42098078, z: 0.42098078}
m_LocalScale: {x: 1.6328479, y: 1.6328486, z: 1.6328486}
m_LocalEulerAnglesHint: {x: -189.079, y: -195.945, z: -179.613}
m_LocalEulerAnglesHint: {x: -184.5, y: -172.431, z: -304.206}
--- !u!1 &2129034570
GameObject:
m_ObjectHideFlags: 0

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


m_Name: Mat
m_Shader: {fileID: 4800000, guid: 9ab5e16c2083a4fe689209a8c1ae425e, type: 3}
m_ShaderKeywords:
m_LightmapFlags: 4
m_LightmapFlags: 0
m_EnableInstancingVariants: 0
m_CustomRenderQueue: -1
stringTagMap: {}

m_TexEnvs:
- 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}
- 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_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_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_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: []

9
MaterialGraphProject/Assets/Andre/Materials/Sky.mat


m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: Sky
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
m_Shader: {fileID: 103, guid: 0000000000000000f000000000000000, type: 0}
m_ShaderKeywords:
m_LightmapFlags: 4
m_EnableInstancingVariants: 0

m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _Tex:
m_Texture: {fileID: 8900000, guid: f7111c407ddfe4109af9703cb740eaf9, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _Exposure: 1
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1

- _Parallax: 0.02
- _Rotation: 0
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1

- _Color: {r: 1, g: 1, b: 1, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _Tint: {r: 0.5, g: 0.5, b: 0.5, a: 0.5}

102
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Matrix/MatrixMultiplyNode.cs


using UnityEngine.Graphing;
[Title("Matrix/Multiply Node")]
public class MatrixMultiplyNode : Function2Input, IGeneratesFunction
[Title("Math/Matrix/MultiplyMatrix")]
public class MatrixMultiplyNode : AbstractMaterialNode, IGeneratesBodyCode, IGeneratesFunction
protected const string kInputSlot1ShaderName = "Input1";
protected const string kInputSlot2ShaderName = "Input2";
protected const string kOutputSlotShaderName = "Output";
public const int InputSlot1Id = 0;
public const int InputSlot2Id = 1;
public const int OutputSlotId = 2;
public override bool hasPreview
{
get { return false; }
}
name = "MatrixMultiplyNode";
name = "MultiplyMatrix";
UpdateNodeAfterDeserialization();
protected override string GetFunctionName()
protected string GetFunctionName()
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(GetInputSlot1());
AddSlot(GetInputSlot2());
AddSlot(GetOutputSlot());
RemoveSlotsNameNotMatching(validSlots);
}
protected int[] validSlots
{
get { return new[] { InputSlot1Id, InputSlot2Id, OutputSlotId }; }
}
protected MaterialSlot GetInputSlot1()
{
return new MaterialSlot(InputSlot1Id, GetInputSlot1Name(), kInputSlot1ShaderName, SlotType.Input, SlotValueType.Matrix4, Vector4.zero);
}
protected MaterialSlot GetInputSlot2()
{
return new MaterialSlot(InputSlot2Id, GetInputSlot2Name(), kInputSlot2ShaderName, SlotType.Input, SlotValueType.Matrix4, Vector4.zero);
}
protected MaterialSlot GetOutputSlot()
{
return new MaterialSlot(OutputSlotId, GetOutputSlotName(), kOutputSlotShaderName, SlotType.Output, SlotValueType.Matrix4, Vector4.zero);
}
protected virtual string GetInputSlot1Name()
{
return "Input1";
}
protected virtual string GetInputSlot2Name()
{
return "Input2";
}
protected string GetOutputSlotName()
{
return "Output";
}
protected string GetFunctionPrototype(string arg1Name, string arg2Name)
{
return "inline " + precision + outputDimension + " " + GetFunctionName() + " ("
+ precision + input1Dimension + " " + arg1Name + ", "
+ precision + input2Dimension + " " + arg2Name + ")";
}
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
{
NodeUtils.SlotConfigurationExceptionIfBadConfiguration(this, new[] { InputSlot1Id, InputSlot2Id }, new[] { OutputSlotId });
string input1Value = GetSlotValue(InputSlot1Id, generationMode);
string input2Value = GetSlotValue(InputSlot2Id, generationMode);
visitor.AddShaderChunk(precision + outputDimension + " " + GetVariableNameForSlot(OutputSlotId) + " = " + GetFunctionCallBody(input1Value, input2Value) + ";", true);
}
protected string GetFunctionCallBody(string input1Value, string input2Value)
{
return GetFunctionName() + " (" + input1Value + ", " + input2Value + ")";
}
public string outputDimension
{
get { return ConvertConcreteSlotValueTypeToString(FindInputSlot<MaterialSlot>(InputSlot2Id).concreteValueType); }
}
private string input1Dimension
{
get { return ConvertConcreteSlotValueTypeToString(FindInputSlot<MaterialSlot>(InputSlot1Id).concreteValueType); }
}
private string input2Dimension
{
get { return ConvertConcreteSlotValueTypeToString(FindInputSlot<MaterialSlot>(InputSlot2Id).concreteValueType); }
}
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)

21
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Math/Matrix/MatrixTransposeNode.cs


using UnityEngine.Graphing;
[Title("Matrix/Transpose Node")]
[Title("Math/Matrix/TransposeMatrix")]
name = "MatrixTranspose";
name = "TransposeMatrix";
}
public override bool hasPreview
{
get { return false; }
}
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)

outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
}
protected override MaterialSlot GetInputSlot()
{
return new MaterialSlot(InputSlotId, GetInputSlotName(), kInputSlotShaderName, SlotType.Input, SlotValueType.Matrix4, Vector4.zero);
}
protected override MaterialSlot GetOutputSlot()
{
return new MaterialSlot(OutputSlotId, GetOutputSlotName(), kOutputSlotShaderName, SlotType.Output, SlotValueType.Matrix4, Vector4.zero);
}
}
}

998
MaterialGraphProject/Assets/Andre/Scenes/EmissionTest/LightingData.asset
文件差异内容过多而无法显示
查看文件

4
MaterialGraphProject/Assets/Andre/Scenes/LightProbeTesting/ReflectionProbe-0.exr.meta


fileFormatVersion: 2
guid: 035e8eb0a74634d93a5fdf702b66c951
timeCreated: 1495567387
guid: 2d98e9d8df33a488f886cdd1eab0d9d6
timeCreated: 1495641031
licenseType: Pro
TextureImporter:
fileIDToRecycleName:

9
MaterialGraphProject/Assets/Andre/Materials.meta


fileFormatVersion: 2
guid: 7d10d324ed0f94cb09a5c4478eee9945
folderAsset: yes
timeCreated: 1495628966
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

9
MaterialGraphProject/Assets/Andre/Nodes.meta


fileFormatVersion: 2
guid: 9d0a876dd165a46c6b30eac1bbbef3a7
folderAsset: yes
timeCreated: 1495628893
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

9
MaterialGraphProject/Assets/Andre/Scenes.meta


fileFormatVersion: 2
guid: 788be86d1d83c4b5596351884aa015a9
folderAsset: yes
timeCreated: 1495628982
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

9
MaterialGraphProject/Assets/Andre/Scripts.meta


fileFormatVersion: 2
guid: 1a53c91de66c7460fb9b67844e09076d
folderAsset: yes
timeCreated: 1495628928
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

9
MaterialGraphProject/Assets/Andre/Shaders.meta


fileFormatVersion: 2
guid: 2eded065f6ee74c53a9261b91dc002ff
folderAsset: yes
timeCreated: 1495628909
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

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

9
MaterialGraphProject/Assets/Brandon/Electricity.ShaderGraph.meta


fileFormatVersion: 2
guid: 9c4fda6a69c679d49acc351c2a1709bf
timeCreated: 1495610699
licenseType: Pro
ScriptedImporter:
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 11500000, guid: 625f186215c104763be7675aa2d941aa, type: 3}

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

9
MaterialGraphProject/Assets/Brandon/Flame.ShaderGraph.meta


fileFormatVersion: 2
guid: 98bd80683fc0ce3468161776bcacc8dc
timeCreated: 1495484022
licenseType: Pro
ScriptedImporter:
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 11500000, guid: 625f186215c104763be7675aa2d941aa, type: 3}

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

9
MaterialGraphProject/Assets/Code Graph.ShaderGraph.meta


fileFormatVersion: 2
guid: 6e7da496d1011f54b8e707ce39eb4b5f
timeCreated: 1495644036
licenseType: Pro
ScriptedImporter:
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 11500000, guid: 625f186215c104763be7675aa2d941aa, type: 3}

83
MaterialGraphProject/Assets/Eduardo/EduardoTestMat.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: EduardoTestMat
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_8fd49eff_ec05_41e3_9bc1_5bdfc20db019_Uniform:
m_Texture: {fileID: 2800000, guid: 6ff1e57e8df9d2948bb6d703d02af730, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- Texture_ec519094_93da_4612_af61_2f8bcdc6589e_Uniform:
m_Texture: {fileID: 2800000, guid: 6ff1e57e8df9d2948bb6d703d02af730, 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:
- _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/Eduardo/EduardoTestMat.mat.meta


fileFormatVersion: 2
guid: 51689361644e44b41aa59664b34a6e45
timeCreated: 1495654926
licenseType: Pro
NativeFormatImporter:
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:

64
MaterialGraphProject/Assets/Eduardo/VertexNormalNode.cs


using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
[Title("Input/Geometry/Vertex Normal")]
public class VertexNormalNode : AbstractMaterialNode
{
private const string kOutputSlotName = "XYZW";
private const string kOutputSlotNameXYZ = "XYZ";
private const string kOutputSlotNameX = "X";
private const string kOutputSlotNameY = "Y";
private const string kOutputSlotNameZ = "Z";
private const string kOutputSlotNameW = "W";
public const int OutputSlotId = 0;
public const int OutputSlotIdXYZ = 1;
public const int OutputSlotIdX = 2;
public const int OutputSlotIdY = 3;
public const int OutputSlotIdZ = 4;
public const int OutputSlotIdW = 5;
public VertexNormalNode()
{
name = "VertexNormal";
UpdateNodeAfterDeserialization();
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Vector4, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotIdXYZ, kOutputSlotNameXYZ, kOutputSlotNameXYZ, SlotType.Output, SlotValueType.Vector3, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotIdX, kOutputSlotNameX, kOutputSlotNameX, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotIdY, kOutputSlotNameY, kOutputSlotNameY, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotIdZ, kOutputSlotNameZ, kOutputSlotNameZ, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotIdW, kOutputSlotNameW, kOutputSlotNameW, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
RemoveSlotsNameNotMatching(validSlots);
}
protected int[] validSlots
{
get { return new[] { OutputSlotId, OutputSlotIdXYZ, OutputSlotIdX, OutputSlotIdY, OutputSlotIdZ, OutputSlotIdW }; }
}
public override string GetVariableNameForSlot(int slotId)
{
switch (slotId)
{
case OutputSlotIdXYZ:
return "v.normal.xyz";
case OutputSlotIdX:
return "v.normal.x";
case OutputSlotIdY:
return "v.normal.y";
case OutputSlotIdZ:
return "v.normal.z";
case OutputSlotIdW:
return "v.normal.w";
default:
return "v.normal";
}
}
}
}

12
MaterialGraphProject/Assets/Eduardo/VertexNormalNode.cs.meta


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

64
MaterialGraphProject/Assets/Eduardo/VertexPositionNode.cs


using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
[Title("Input/Geometry/Vertex Position")]
public class VertexPositionNode : AbstractMaterialNode
{
private const string kOutputSlotName = "XYZW";
private const string kOutputSlotNameXYZ = "XYZ";
private const string kOutputSlotNameX = "X";
private const string kOutputSlotNameY = "Y";
private const string kOutputSlotNameZ = "Z";
private const string kOutputSlotNameW = "W";
public const int OutputSlotId = 0;
public const int OutputSlotIdXYZ = 1;
public const int OutputSlotIdX = 2;
public const int OutputSlotIdY = 3;
public const int OutputSlotIdZ = 4;
public const int OutputSlotIdW = 5;
public VertexPositionNode()
{
name = "VertexPostion";
UpdateNodeAfterDeserialization();
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Vector4, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotIdXYZ, kOutputSlotNameXYZ, kOutputSlotNameXYZ, SlotType.Output, SlotValueType.Vector3, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotIdX, kOutputSlotNameX, kOutputSlotNameX, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotIdY, kOutputSlotNameY, kOutputSlotNameY, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotIdZ, kOutputSlotNameZ, kOutputSlotNameZ, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotIdW, kOutputSlotNameW, kOutputSlotNameW, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
RemoveSlotsNameNotMatching(validSlots);
}
protected int[] validSlots
{
get { return new[] { OutputSlotId, OutputSlotIdXYZ ,OutputSlotIdX, OutputSlotIdY, OutputSlotIdZ, OutputSlotIdW }; }
}
public override string GetVariableNameForSlot(int slotId)
{
switch (slotId)
{
case OutputSlotIdXYZ:
return "v.vertex.xyz";
case OutputSlotIdX:
return "v.vertex.x";
case OutputSlotIdY:
return "v.vertex.y";
case OutputSlotIdZ:
return "v.vertex.z";
case OutputSlotIdW:
return "v.vertex.w";
default:
return "v.vertex";
}
}
}
}

12
MaterialGraphProject/Assets/Eduardo/VertexPositionNode.cs.meta


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

363
MaterialGraphProject/Assets/Eduardo/eduardoScene.unity


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!29 &1
OcclusionCullingSettings:
m_ObjectHideFlags: 0
serializedVersion: 2
m_OcclusionBakeSettings:
smallestOccluder: 5
smallestHole: 0.25
backfaceThreshold: 100
m_SceneGUID: 00000000000000000000000000000000
m_OcclusionCullingData: {fileID: 0}
--- !u!104 &2
RenderSettings:
m_ObjectHideFlags: 0
serializedVersion: 8
m_Fog: 0
m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
m_FogMode: 3
m_FogDensity: 0.01
m_LinearFogStart: 0
m_LinearFogEnd: 300
m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1}
m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1}
m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1}
m_AmbientIntensity: 1
m_AmbientMode: 0
m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1}
m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0}
m_HaloStrength: 0.5
m_FlareStrength: 1
m_FlareFadeSpeed: 3
m_HaloTexture: {fileID: 0}
m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0}
m_DefaultReflectionMode: 0
m_DefaultReflectionResolution: 128
m_ReflectionBounces: 1
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0.18028316, g: 0.22571331, b: 0.306922, a: 1}
--- !u!157 &3
LightmapSettings:
m_ObjectHideFlags: 0
serializedVersion: 11
m_GIWorkflowMode: 0
m_GISettings:
serializedVersion: 2
m_BounceScale: 1
m_IndirectOutputScale: 1
m_AlbedoBoost: 1
m_TemporalCoherenceThreshold: 1
m_EnvironmentLightingMode: 0
m_EnableBakedLightmaps: 1
m_EnableRealtimeLightmaps: 1
m_LightmapEditorSettings:
serializedVersion: 9
m_Resolution: 2
m_BakeResolution: 40
m_TextureWidth: 1024
m_TextureHeight: 1024
m_AO: 0
m_AOMaxDistance: 1
m_CompAOExponent: 1
m_CompAOExponentDirect: 0
m_Padding: 2
m_LightmapParameters: {fileID: 0}
m_LightmapsBakeMode: 1
m_TextureCompression: 1
m_FinalGather: 0
m_FinalGatherFiltering: 1
m_FinalGatherRayCount: 256
m_ReflectionCompression: 2
m_MixedBakeMode: 2
m_BakeBackend: 0
m_PVRSampling: 1
m_PVRDirectSampleCount: 32
m_PVRSampleCount: 500
m_PVRBounces: 2
m_PVRFiltering: 0
m_PVRFilteringMode: 1
m_PVRCulling: 1
m_PVRFilteringGaussRadiusDirect: 1
m_PVRFilteringGaussRadiusIndirect: 5
m_PVRFilteringGaussRadiusAO: 2
m_PVRFilteringAtrousColorSigma: 1
m_PVRFilteringAtrousNormalSigma: 1
m_PVRFilteringAtrousPositionSigma: 1
m_LightingDataAsset: {fileID: 0}
m_UseShadowmask: 1
--- !u!196 &4
NavMeshSettings:
serializedVersion: 2
m_ObjectHideFlags: 0
m_BuildSettings:
serializedVersion: 2
agentTypeID: 0
agentRadius: 0.5
agentHeight: 2
agentSlope: 45
agentClimb: 0.4
ledgeDropHeight: 0
maxJumpAcrossDistance: 0
minRegionArea: 2
manualCellSize: 0
cellSize: 0.16666667
manualTileSize: 0
tileSize: 256
accuratePlacement: 0
debug:
m_Flags: 0
m_NavMeshData: {fileID: 0}
--- !u!1 &165786477
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 165786481}
- component: {fileID: 165786480}
- component: {fileID: 165786479}
- component: {fileID: 165786478}
m_Layer: 0
m_Name: Cube
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!23 &165786478
MeshRenderer:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 165786477}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_Materials:
- {fileID: 2100000, guid: 51689361644e44b41aa59664b34a6e45, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!65 &165786479
BoxCollider:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 165786477}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!33 &165786480
MeshFilter:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 165786477}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!4 &165786481
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 165786477}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &545929005
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 545929010}
- component: {fileID: 545929009}
- component: {fileID: 545929008}
- component: {fileID: 545929007}
- component: {fileID: 545929006}
m_Layer: 0
m_Name: Main Camera
m_TagString: MainCamera
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!81 &545929006
AudioListener:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 545929005}
m_Enabled: 1
--- !u!124 &545929007
Behaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 545929005}
m_Enabled: 1
--- !u!92 &545929008
Behaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 545929005}
m_Enabled: 1
--- !u!20 &545929009
Camera:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 545929005}
m_Enabled: 1
serializedVersion: 2
m_ClearFlags: 1
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0}
m_NormalizedViewPortRect:
serializedVersion: 2
x: 0
y: 0
width: 1
height: 1
near clip plane: 0.3
far clip plane: 1000
field of view: 60
orthographic: 0
orthographic size: 5
m_Depth: -1
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_RenderingPath: -1
m_TargetTexture: {fileID: 0}
m_TargetDisplay: 0
m_TargetEye: 3
m_HDR: 1
m_AllowMSAA: 1
m_ForceIntoRT: 0
m_OcclusionCulling: 1
m_StereoConvergence: 10
m_StereoSeparation: 0.022
m_StereoMirrorMode: 0
--- !u!4 &545929010
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 545929005}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 1, z: -10}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1301173965
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 1301173967}
- component: {fileID: 1301173966}
m_Layer: 0
m_Name: Directional Light
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!108 &1301173966
Light:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1301173965}
m_Enabled: 1
serializedVersion: 8
m_Type: 1
m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1}
m_Intensity: 1
m_Range: 10
m_SpotAngle: 30
m_CookieSize: 10
m_Shadows:
m_Type: 2
m_Resolution: -1
m_CustomResolution: -1
m_Strength: 1
m_Bias: 0.05
m_NormalBias: 0.4
m_NearPlane: 0.2
m_Cookie: {fileID: 0}
m_DrawHalo: 0
m_Flare: {fileID: 0}
m_RenderMode: 0
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_Lightmapping: 4
m_AreaSize: {x: 1, y: 1}
m_BounceIntensity: 1
m_FalloffTable:
m_Table[0]: 0
m_Table[1]: 0
m_Table[2]: 0
m_Table[3]: 0
m_Table[4]: 0
m_Table[5]: 0
m_Table[6]: 0
m_Table[7]: 0
m_Table[8]: 0
m_Table[9]: 0
m_Table[10]: 0
m_Table[11]: 0
m_Table[12]: 0
m_ColorTemperature: 6570
m_UseColorTemperature: 0
m_ShadowRadius: 0
m_ShadowAngle: 0
--- !u!4 &1301173967
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1301173965}
m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261}
m_LocalPosition: {x: 0, y: 3, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}

8
MaterialGraphProject/Assets/Eduardo/eduardoScene.unity.meta


fileFormatVersion: 2
guid: 418471c069e40784489ba3ba9d0bb95b
timeCreated: 1495655530
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

9
MaterialGraphProject/Assets/Florent.meta


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

22
MaterialGraphProject/Assets/Matt/CommonMatrixType.cs


namespace UnityEngine.MaterialGraph
{
public enum CommonMatrixType
{
ModelView,
View,
Projection,
ViewProjection,
TransposeModelView,
InverseTransposeModelView,
ObjectToWorld,
WorldToObject
};
public enum SimpleMatrixType
{
World,
Local,
Tangent,
View
};
}

12
MaterialGraphProject/Assets/Matt/CommonMatrixType.cs.meta


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

9
MaterialGraphProject/Assets/Matt/Examples.meta


fileFormatVersion: 2
guid: 6a5311f2c2db6e34f8da2333309aab50
folderAsset: yes
timeCreated: 1495713891
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

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

9
MaterialGraphProject/Assets/Matt/Test.ShaderGraph.meta


fileFormatVersion: 2
guid: fd03b3a3f54f741498f9bea81e951ebb
timeCreated: 1495668190
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:

29
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeInspectors/PropertyNodeInspector.cs


using UnityEditor.Graphing.Drawing;
using UnityEngine;
using UnityEngine.Graphing;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.Drawing
{
public class PropertyNodeInspector : BasicNodeInspector
{
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
var propertyNode = node as PropertyNode;
if (propertyNode == null)
return;
GUILayout.Label("Settings", EditorStyles.boldLabel);
EditorGUI.BeginChangeCheck();
//propertyNode.name = EditorGUILayout.TextField ("Name", propertyNode.name);
propertyNode.description = EditorGUILayout.TextField ("Description", propertyNode.description);
if (EditorGUI.EndChangeCheck())
node.onModified(node, ModificationScope.Node);
}
}
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeInspectors/PropertyNodeInspector.cs.meta


fileFormatVersion: 2
guid: 4a761301a6b844baa9202a1dc4293b67
timeCreated: 1495644228
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
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:

72
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/GradientNodePresenter.cs


using System;
using System.Collections.Generic;
using RMGUI.GraphView;
using UnityEditor.Graphing.Drawing;
using UnityEngine;
namespace UnityEditor.MaterialGraph.Drawing
{
[Serializable]
class GradientContolPresenter : GraphControlPresenter
{
private GradientObject gradientobj;
private SerializedObject hserializedObject;
private SerializedProperty hcolorGradient;
private UnityEngine.MaterialGraph.GradientNode prevnode;
private string prevWindow = "";
public override void OnGUIHandler()
{
base.OnGUIHandler();
var cNode = node as UnityEngine.MaterialGraph.GradientNode;
if (cNode == null)
return;
if(gradientobj == null || prevnode != cNode)
{
prevnode = cNode;
gradientobj = new GradientObject();
hserializedObject = new SerializedObject(gradientobj);
hcolorGradient = hserializedObject.FindProperty("gradient");
}
EditorGUILayout.PropertyField(hcolorGradient, true, null);
hserializedObject.ApplyModifiedProperties();
cNode.gradient = gradientobj.gradient;
Event e = Event.current;
if (EditorWindow.focusedWindow != null && prevWindow != EditorWindow.focusedWindow.ToString() && EditorWindow.focusedWindow.ToString() != "(UnityEditor.GradientPicker)")
{
cNode.UpdateGradient();
prevWindow = EditorWindow.focusedWindow.ToString();
Debug.Log("Update Gradient Shader");
}
}
public override float GetHeight()
{
return EditorGUIUtility.singleLineHeight + 10 * EditorGUIUtility.standardVerticalSpacing;
}
}
[Serializable]
public class GradientNodePresenter : MaterialNodePresenter
{
protected override IEnumerable<GraphElementPresenter> GetControlData()
{
var instance = CreateInstance<GradientContolPresenter>();
instance.Initialize(node);
return new List<GraphElementPresenter> { instance };
}
}
public class GradientObject : ScriptableObject
{
public Gradient gradient = new Gradient();
}
}

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


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

40
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Matrix2NodePresenter.cs


using System;
using System.Collections.Generic;
using RMGUI.GraphView;
using UnityEditor.Graphing.Drawing;
using UnityEngine;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.Drawing
{
class Matrix2ControlPresenter : GraphControlPresenter
{
public override void OnGUIHandler()
{
base.OnGUIHandler();
var tNode = node as UnityEngine.MaterialGraph.Matrix2Node;
if (tNode == null)
return;
tNode[0] = EditorGUILayout.Vector2Field("", tNode[0]);
tNode[1] = EditorGUILayout.Vector2Field("", tNode[1]);
}
public override float GetHeight()
{
return (EditorGUIUtility.singleLineHeight * 2 + EditorGUIUtility.standardVerticalSpacing) + EditorGUIUtility.standardVerticalSpacing;
}
}
[Serializable]
public class Matrix2NodePresenter : PropertyNodePresenter
{
protected override IEnumerable<GraphElementPresenter> GetControlData()
{
var instance = CreateInstance<Matrix2ControlPresenter>();
instance.Initialize(node);
return new List<GraphElementPresenter>(base.GetControlData()) { instance };
}
}
}

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


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

41
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Matrix3NodePresenter.cs


using System;
using System.Collections.Generic;
using RMGUI.GraphView;
using UnityEditor.Graphing.Drawing;
using UnityEngine;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.Drawing
{
class Matrix3ControlPresenter : GraphControlPresenter
{
public override void OnGUIHandler()
{
base.OnGUIHandler();
var tNode = node as UnityEngine.MaterialGraph.Matrix3Node;
if (tNode == null)
return;
tNode[0] = EditorGUILayout.Vector3Field("", tNode[0]);
tNode[1] = EditorGUILayout.Vector3Field("", tNode[1]);
tNode[2] = EditorGUILayout.Vector3Field("", tNode[2]);
}
public override float GetHeight()
{
return (EditorGUIUtility.singleLineHeight * 3 + EditorGUIUtility.standardVerticalSpacing) + EditorGUIUtility.standardVerticalSpacing;
}
}
[Serializable]
public class Matrix3NodePresenter : PropertyNodePresenter
{
protected override IEnumerable<GraphElementPresenter> GetControlData()
{
var instance = CreateInstance<Matrix3ControlPresenter>();
instance.Initialize(node);
return new List<GraphElementPresenter>(base.GetControlData()) { instance };
}
}
}

部分文件因为文件数量过多而无法显示

正在加载...
取消
保存