Tim Cooper
8 年前
当前提交
d0d60781
共有 45 个文件被更改,包括 347 次插入 和 585 次删除
-
2.gitmodules
-
4MaterialGraphProject/Assets/Eduardo/Editor/AddManyNodePresenter.cs
-
4MaterialGraphProject/Assets/Eduardo/FunctionNAddNode.cs
-
6MaterialGraphProject/Assets/Eduardo/FunctionNInNOut.cs
-
4MaterialGraphProject/Assets/NewNodes/WIP/AACheckerBoard3dNode.cs
-
4MaterialGraphProject/Assets/NewNodes/WIP/AACheckerBoardNode.cs
-
8MaterialGraphProject/Assets/NewNodes/WIP/AnyNode.cs
-
2MaterialGraphProject/Assets/NewNodes/WIP/POMNode.cs
-
64MaterialGraphProject/Assets/NewNodes/WIP/RadialShearNode.cs
-
62MaterialGraphProject/Assets/NewNodes/WIP/ScaleOffsetNode.cs
-
66MaterialGraphProject/Assets/NewNodes/WIP/SphereWarpNode.cs
-
104MaterialGraphProject/Assets/NewNodes/WIP/SphericalIndentationNode.cs
-
2MaterialGraphProject/Assets/TestGraph.ShaderGraph
-
9MaterialGraphProject/Assets/TestGraph.ShaderGraph.meta
-
4MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/AnyNodePresenter.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/CustomCodeNodePresenter.cs
-
18MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/SamplerAssetPresenter.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/ScatterNodePresenter.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/TextureAssetPresenter.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/TextureNodePresenter.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/TextureSamplerPresenter.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/PropertyNodeTests.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/PropertyNodeTests.cs
-
34MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/AbstractMaterialNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Art/Filters/ConvolutionFilterNode.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Channel/SplitNode.cs
-
5MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Channel/SwizzleNode.cs
-
7MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/HLSLNode.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Texture/SamplerAssetNode.cs
-
6MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Texture/TextureNode.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Logic/CustomCodeNode.cs
-
9MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/MaterialSlot.cs
-
54MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/SlotValue.cs
-
24MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SurfaceModel/AbstractSurfaceMasterNode.cs
-
45MaterialGraphProject/Assets/Vlad/SamplerStateNode.cs
-
292MaterialGraphProject/Assets/Vlad/TextureSamplerNode.cs
-
17MaterialGraphProject/Assets/Vlad/UVTriPlanar.cs
-
13MaterialGraphProject/Assets/Vlad/Texture2DNode.cs
-
2MaterialGraphProject/Assets/Vlad/Texture2DNode.cs.meta
-
2MaterialGraphProject/Assets/_MingWai/GeneratedTextureDemo/0-UnityLogo-Texture.asset.meta
-
2MaterialGraphProject/Assets/_MingWai/Gradient.asset.meta
-
4MaterialGraphProject/Assets/_MingWai/ScatterNode.cs
-
0/MaterialGraphProject/Assets/Vlad/Texture2DNode.cs
-
0/MaterialGraphProject/Assets/Vlad/Texture2DNode.cs.meta
|
|||
[submodule "MaterialGraphProject/Assets/GraphView/Editor"] |
|||
path = MaterialGraphProject/Assets/GraphView/Editor |
|||
url = https://github.com/chikuba/GraphView.git |
|||
url=https://github.com/Unity-Technologies/graphview.git |
|
|||
using UnityEngine.Graphing; |
|||
using System.Reflection; |
|||
public class RadialShearNode : AnyNode<RadialShearNode.Definition> |
|||
public class RadialShearNode : CodeFunctionNode |
|||
public class Definition : IAnyNodeDefinition |
|||
protected override MethodInfo GetFunctionToConvert() |
|||
public string name { get { return "RadialShear"; } } |
|||
|
|||
public AnyNodeProperty[] properties |
|||
{ |
|||
get |
|||
{ |
|||
return new AnyNodeProperty[] |
|||
{ |
|||
// slotId is the 'immutable' value we used to connect things
|
|||
new AnyNodeProperty { slotId= 0, name = "inUVs", description = "Input UV coords", propertyType = PropertyType.Vector2, value = Vector4.zero, state = AnyNodePropertyState.Slot }, |
|||
new AnyNodeProperty { slotId= 1, name = "center", description = "UV radial center point", propertyType = PropertyType.Vector2, value= new Vector4(0.5f, 0.5f, 0.5f, 0.5f), state = AnyNodePropertyState.Constant }, |
|||
new AnyNodeProperty { slotId= 2, name = "shearAmount", description = "Shear amount", propertyType = PropertyType.Vector2, value= Vector4.one, state = AnyNodePropertyState.Constant }, |
|||
new AnyNodeProperty { slotId= 3, name = "offset", description = "UV offset", propertyType = PropertyType.Vector2, value= Vector4.zero, state = AnyNodePropertyState.Constant }, |
|||
}; |
|||
} |
|||
} |
|||
|
|||
public AnyNodeSlot[] outputs |
|||
{ |
|||
get |
|||
{ |
|||
return new AnyNodeSlot[] |
|||
{ |
|||
new AnyNodeSlot { slotId= 4, name = "outUVs", description = "Output UV texture coordinates", slotValueType = SlotValueType.Vector2, value = Vector4.zero } |
|||
}; |
|||
} |
|||
} |
|||
public ShaderGlobal[] globals { get { return new ShaderGlobal[] { }; } } |
|||
return GetType().GetMethod("Unity_RadialShear", BindingFlags.Static | BindingFlags.NonPublic); |
|||
} |
|||
public string hlsl |
|||
{ |
|||
get |
|||
{ |
|||
return |
|||
"float2 delta = inUVs - center;\n" + |
|||
"float delta2 = dot(delta.xy, delta.xy);\n" + |
|||
"float2 delta_offset = delta2 * shearAmount;\n" + |
|||
"outUVs = inUVs + float2(delta.y, -delta.x) * delta_offset + offset;"; |
|||
} |
|||
} |
|||
static string Unity_RadialShear( |
|||
[Slot(0, Binding.MeshUV0)] Vector2 uv, |
|||
[Slot(1, Binding.None, 0.5f, 0.5f, 0.5f, 0.5f)] Vector2 center, |
|||
[Slot(2, Binding.None, 1f, 1f, 1f, 1f)] Vector2 shearAmount, |
|||
[Slot(3, Binding.None)] Vector2 offset, |
|||
[Slot(4, Binding.None)] out Vector2 result) |
|||
{ |
|||
result = Vector2.zero; |
|||
return |
|||
@"
|
|||
{ |
|||
float2 delta = uv - center; |
|||
float delta2 = dot(delta.xy, delta.xy); |
|||
float2 delta_offset = delta2 * shearAmount; |
|||
result = uv + float2(delta.y, -delta.x) * delta_offset + offset; |
|||
} |
|||
";
|
|||
} |
|||
} |
|||
|
|
|||
using UnityEngine.Graphing; |
|||
using System.Reflection; |
|||
public class ScaleOffsetNode : AnyNode<ScaleOffsetNode.Definition> |
|||
public class ScaleOffsetNode : CodeFunctionNode |
|||
public class Definition : IAnyNodeDefinition |
|||
protected override MethodInfo GetFunctionToConvert() |
|||
public string name { get { return "ScaleOffset"; } } |
|||
|
|||
public AnyNodeProperty[] properties |
|||
{ |
|||
get |
|||
{ |
|||
return new AnyNodeProperty[] |
|||
{ |
|||
// slotId is the 'immutable' value we used to connect things
|
|||
new AnyNodeProperty { slotId= 0, name = "inUVs", description = "Input UV coords", propertyType = PropertyType.Vector2, value = Vector4.zero, state = AnyNodePropertyState.Slot }, |
|||
new AnyNodeProperty { slotId= 1, name = "scale", description = "UV scale", propertyType = PropertyType.Vector2, value= Vector4.one, state = AnyNodePropertyState.Constant }, |
|||
new AnyNodeProperty { slotId= 2, name = "scaleCenter", description = "UV scale center", propertyType = PropertyType.Vector2, value= new Vector4(0.5f, 0.5f, 0.5f, 0.5f), state = AnyNodePropertyState.Constant }, |
|||
new AnyNodeProperty { slotId= 3, name = "offset", description = "UV offset", propertyType = PropertyType.Vector2, value= Vector4.zero, state = AnyNodePropertyState.Constant }, |
|||
}; |
|||
} |
|||
} |
|||
|
|||
public AnyNodeSlot[] outputs |
|||
{ |
|||
get |
|||
{ |
|||
return new AnyNodeSlot[] |
|||
{ |
|||
new AnyNodeSlot { slotId= 4, name = "outUVs", description = "Output UV texture coordinates", slotValueType = SlotValueType.Vector2, value = Vector4.zero } |
|||
}; |
|||
} |
|||
} |
|||
return GetType().GetMethod("Unity_ScaleAndOffset", BindingFlags.Static | BindingFlags.NonPublic); |
|||
} |
|||
public ShaderGlobal[] globals { get { return new ShaderGlobal[] { }; } } |
|||
static string Unity_ScaleAndOffset( |
|||
[Slot(0, Binding.MeshUV0)] Vector2 uv, |
|||
[Slot(1, Binding.None, 1f, 1f, 1f, 1f)] Vector2 scale, |
|||
[Slot(2, Binding.None, 0.5f, 0.5f, 0.5f, 0.5f)] Vector2 scaleCenter, |
|||
[Slot(3, Binding.None)] Vector2 offset, |
|||
[Slot(4, Binding.None)] out Vector2 result) |
|||
{ |
|||
result = Vector2.zero; |
|||
return |
|||
@"
|
|||
{ |
|||
float4 xform = float4(scale, offset + scaleCenter - scaleCenter * scale); |
|||
result = uv * xform.xy + xform.zw; |
|||
} |
|||
";
|
|||
} |
|||
public string hlsl |
|||
{ |
|||
get |
|||
{ |
|||
return |
|||
"float4 xform= float4(scale, offset + scaleCenter - scaleCenter * scale);\n" + |
|||
"outUVs = inUVs * xform.xy + xform.zw;"; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
using UnityEngine.Graphing; |
|||
using System.Reflection; |
|||
public class SphereWarpNode : AnyNode<SphereWarpNode.Definition> |
|||
public class SphereWarpNode : CodeFunctionNode |
|||
public class Definition : IAnyNodeDefinition |
|||
protected override MethodInfo GetFunctionToConvert() |
|||
public string name { get { return "SphereWarp"; } } |
|||
|
|||
public AnyNodeProperty[] properties |
|||
{ |
|||
get |
|||
{ |
|||
return new AnyNodeProperty[] |
|||
{ |
|||
// slotId is the 'immutable' value we used to connect things
|
|||
new AnyNodeProperty { slotId= 0, name = "inUVs", description = "Input UV coords", propertyType = PropertyType.Vector2, value = Vector4.zero, state = AnyNodePropertyState.Slot }, |
|||
new AnyNodeProperty { slotId= 1, name = "center", description = "UV radial center point", propertyType = PropertyType.Vector2, value= new Vector4(0.5f, 0.5f, 0.5f, 0.5f), state = AnyNodePropertyState.Constant }, |
|||
new AnyNodeProperty { slotId= 2, name = "warpAmount", description = "Warp amount", propertyType = PropertyType.Vector2, value= Vector4.one, state = AnyNodePropertyState.Constant }, |
|||
new AnyNodeProperty { slotId= 3, name = "offset", description = "UV offset", propertyType = PropertyType.Vector2, value= Vector4.zero, state = AnyNodePropertyState.Constant }, |
|||
}; |
|||
} |
|||
} |
|||
|
|||
public AnyNodeSlot[] outputs |
|||
{ |
|||
get |
|||
{ |
|||
return new AnyNodeSlot[] |
|||
{ |
|||
new AnyNodeSlot { slotId= 4, name = "outUVs", description = "Output UV texture coordinates", slotValueType = SlotValueType.Vector2, value = Vector4.zero } |
|||
}; |
|||
} |
|||
} |
|||
return GetType().GetMethod("Unity_SphereWarp", BindingFlags.Static | BindingFlags.NonPublic); |
|||
} |
|||
public ShaderGlobal[] globals { get { return new ShaderGlobal[]{ }; } } |
|||
|
|||
public string hlsl |
|||
{ |
|||
get |
|||
{ |
|||
return |
|||
"float2 delta = inUVs - center;\n" + |
|||
"float delta2 = dot(delta.xy, delta.xy);\n" + |
|||
"float delta4 = delta2 * delta2;\n" + |
|||
"float2 delta_offset = delta4 * warpAmount;\n" + |
|||
"outUVs = inUVs + delta * delta_offset + offset;"; |
|||
} |
|||
} |
|||
static string Unity_SphereWarp( |
|||
[Slot(0, Binding.MeshUV0)] Vector2 uv, |
|||
[Slot(1, Binding.None, 0.5f, 0.5f, 0.5f, 0.5f)] Vector2 center, |
|||
[Slot(2, Binding.None, 1f, 1f, 1f, 1f)] Vector2 warpAmount, |
|||
[Slot(3, Binding.None)] Vector2 offset, |
|||
[Slot(4, Binding.None)] out Vector2 result) |
|||
{ |
|||
result = Vector2.zero; |
|||
return |
|||
@"
|
|||
{ |
|||
float2 delta = uv - center; |
|||
float delta2 = dot(delta.xy, delta.xy); |
|||
float delta4 = delta2 * delta2; |
|||
float2 delta_offset = delta4 * warpAmount; |
|||
result = uv + delta * delta_offset + offset; |
|||
}";
|
|||
} |
|||
} |
|||
} |
|
|||
using UnityEngine.Graphing; |
|||
using System.Reflection; |
|||
[Title("UV/SphericalIndentation")] |
|||
public class SphericalIndentationNode : AnyNode<SphericalIndentationNode.Definition> |
|||
{ |
|||
public class Definition : IAnyNodeDefinition |
|||
{ |
|||
public string name { get { return "SphericalIndentation"; } } |
|||
|
|||
public AnyNodeProperty[] properties |
|||
{ |
|||
get |
|||
{ |
|||
return new AnyNodeProperty[] |
|||
{ |
|||
// slotId is the 'immutable' value we used to connect things
|
|||
new AnyNodeProperty { slotId= 0, name = "inUVs", description = "Input UV coords", propertyType = PropertyType.Vector2, value = Vector4.zero, state = AnyNodePropertyState.Slot }, |
|||
new AnyNodeProperty { slotId= 1, name = "center", description = "UV center point", propertyType = PropertyType.Vector2, value= new Vector4(0.5f, 0.5f, 0.5f, 0.5f), state = AnyNodePropertyState.Constant }, |
|||
new AnyNodeProperty { slotId= 2, name = "height", description = "Height off surface", propertyType = PropertyType.Float, value= Vector4.zero, state = AnyNodePropertyState.Constant }, |
|||
new AnyNodeProperty { slotId= 3, name = "radius", description = "Radius", propertyType = PropertyType.Float, value= Vector4.one, state = AnyNodePropertyState.Constant }, |
|||
}; |
|||
} |
|||
} |
|||
|
|||
public AnyNodeSlot[] outputs |
|||
{ |
|||
get |
|||
{ |
|||
return new AnyNodeSlot[] |
|||
{ |
|||
new AnyNodeSlot { slotId= 4, name = "outUVs", description = "Output UVW texture coordinates", slotValueType = SlotValueType.Vector3, value = Vector4.zero }, |
|||
new AnyNodeSlot { slotId= 5, name = "outNormal", description = "Output Normal in tangent space", slotValueType = SlotValueType.Vector3, value = Vector4.zero } |
|||
}; |
|||
} |
|||
} |
|||
|
|||
public ShaderGlobal[] globals { get { return new ShaderGlobal[] { ShaderGlobal.TangentSpaceViewDirection }; } } |
|||
|
|||
public string hlsl |
|||
{ |
|||
get |
|||
{ |
|||
return |
|||
"float radius2= radius*radius;\n" + |
|||
"float3 cur= float3(inUVs.xy, 0.0f);\n" + |
|||
"float3 sphereCenter = float3(center, height);\n" + |
|||
"float3 edgeA = sphereCenter - cur;\n" + |
|||
"float a2 = dot(edgeA, edgeA);\n" + |
|||
"outUVs= float3(inUVs.xy, 0.0f);\n" + |
|||
"outNormal= float3(0.0f, 0.0f, 1.0f);\n" + |
|||
"if (a2 < radius2)\n" + |
|||
"{\n" + |
|||
" float a = sqrt(a2);\n" + |
|||
" edgeA = edgeA / a;\n" + |
|||
" float cosineR = dot(edgeA, tangentSpaceViewDirection.xyz);\n" + |
|||
" float x = cosineR * a - sqrt(-a2 + radius2 + a2 * cosineR * cosineR);\n" + |
|||
" float3 intersectedEdge = cur + tangentSpaceViewDirection * x;\n" + |
|||
" outNormal= normalize(sphereCenter - intersectedEdge);\n" + |
|||
" outUVs = intersectedEdge.xyz;\n" + |
|||
"}\n"; |
|||
[Title("UV/SphericalIndentation")] |
|||
public class SphericalIndentationNode : CodeFunctionNode |
|||
{ |
|||
protected override MethodInfo GetFunctionToConvert() |
|||
{ |
|||
return GetType().GetMethod("Unity_SphericalIndentation", BindingFlags.Static | BindingFlags.NonPublic); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
static string Unity_SphericalIndentation( |
|||
[Slot(0, Binding.MeshUV0)] Vector2 uv, |
|||
[Slot(1, Binding.None, 0.5f, 0.5f, 0.5f, 0.5f)] Vector2 center, |
|||
[Slot(2, Binding.None)] Vector1 height, |
|||
[Slot(3, Binding.None, 1f, 1f, 1f, 1f)] Vector1 radius, |
|||
[Slot(4, Binding.None)] out Vector3 resultUV, |
|||
[Slot(5, Binding.None)] out Vector2 resultNormal) |
|||
{ |
|||
resultUV = Vector3.zero; |
|||
resultNormal = Vector3.up; |
|||
return |
|||
@"
|
|||
{ |
|||
float radius2= radius*radius; |
|||
float3 cur= float3(uv.xy, 0.0f); |
|||
float3 sphereCenter = float3(center, height); |
|||
float3 edgeA = sphereCenter - cur; |
|||
float a2 = dot(edgeA, edgeA); |
|||
outUVs= float3(inUVs.xy, 0.0f); |
|||
outNormal= float3(0.0f, 0.0f, 1.0f); |
|||
if (a2 < radius2) |
|||
{ |
|||
float a = sqrt(a2); |
|||
edgeA = edgeA / a; |
|||
float cosineR = dot(edgeA, tangentSpaceViewDirection.xyz); |
|||
float x = cosineR * a - sqrt(-a2 + radius2 + a2 * cosineR * cosineR); |
|||
float3 intersectedEdge = cur + tangentSpaceViewDirection * x; |
|||
resultNormal= normalize(sphereCenter - intersectedEdge); |
|||
resultUV = intersectedEdge.xyz; |
|||
} |
|||
}";
|
|||
} |
|||
} |
|||
} |
2
MaterialGraphProject/Assets/TestGraph.ShaderGraph
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: 037778188549d9b4e8102cd29dea21a9 |
|||
timeCreated: 1495526245 |
|||
timeCreated: 1500622808 |
|||
ScriptedImporter: |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
nonModifiableTextures: |
|||
- Texture2D_Texture2D_2F9B0B05_Uniform: {fileID: 2800000, guid: 79b61ba99411748ae8fa11666dceaee5, |
|||
type: 3} |
|||
script: {fileID: 11500000, guid: 625f186215c104763be7675aa2d941aa, type: 3} |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
#if UNITY_EDITOR
|
|||
using UnityEditor; |
|||
#endif
|
|||
using System.Linq; |
|||
using System.Reflection; |
|||
{ |
|||
|
|||
[Title("Texture/Sample 2D")] |
|||
public class Sample2DTexture : AbstractMaterialNode, IGeneratesBodyCode, IMayRequireMeshUV |
|||
[Title("Input/Texture/Texture Sampler")] |
|||
public class TextureSamplerNode : PropertyNode, IGeneratesBodyCode, IMayRequireMeshUV |
|||
{ |
|||
private const string kTextureAssetName = "Texture Asset"; |
|||
private const string kUVSlotName = "UV"; |
|||
private const string kSamplerName = "Sampler"; |
|||
protected const string kOutputSlotRGBAName = "RGBA"; |
|||
public const int TextureAssetSlotId = 0; |
|||
public const int UVSlotId = 1; |
|||
public const int SamplerSlotId = 2; |
|||
public const int OutputSlotRGBAId = 3; |
|||
|
|||
[SerializeField] |
|||
private string m_SerializedTexture; |
|||
|
|||
[SerializeField] |
|||
private TextureType m_TextureType; |
|||
|
|||
[Serializable] |
|||
private class TextureHelper |
|||
{ |
|||
public Texture2D texture; |
|||
} |
|||
|
|||
public override bool hasPreview { get { return true; } } |
|||
|
|||
#if UNITY_EDITOR
|
|||
public Texture2D defaultTexture |
|||
{ |
|||
get |
|||
{ |
|||
if (string.IsNullOrEmpty(m_SerializedTexture)) |
|||
return null; |
|||
|
|||
var tex = new TextureHelper(); |
|||
EditorJsonUtility.FromJsonOverwrite(m_SerializedTexture, tex); |
|||
return tex.texture; |
|||
} |
|||
set |
|||
{ |
|||
if (defaultTexture == value) |
|||
return; |
|||
|
|||
var tex = new TextureHelper(); |
|||
tex.texture = value; |
|||
m_SerializedTexture = EditorJsonUtility.ToJson(tex, true); |
|||
|
|||
if (onModified != null) |
|||
{ |
|||
onModified(this, ModificationScope.Node); |
|||
} |
|||
} |
|||
} |
|||
#else
|
|||
public Texture2D defaultTexture {get; set; } |
|||
#endif
|
|||
|
|||
public TextureType textureType |
|||
{ |
|||
get { return m_TextureType; } |
|||
set |
|||
{ |
|||
if (m_TextureType == value) |
|||
return; |
|||
public const int OutputSlotId = 0; |
|||
public const int TextureInputId = 1; |
|||
public const int UVInput = 2; |
|||
public const int SamplerInput = 3; |
|||
private const string kOutputSlotName = "rgba"; |
|||
private const string kTextureInputName = "Tex"; |
|||
private const string kUVInputName = "UV"; |
|||
private const string kSamplerInputName = "Sampler"; |
|||
m_TextureType = value; |
|||
if (onModified != null) |
|||
{ |
|||
onModified(this, ModificationScope.Graph); |
|||
} |
|||
} |
|||
} |
|||
public override bool hasPreview { get { return true; } } |
|||
public TextureSamplerNode() |
|||
{ |
|||
name = "TextureSamplerNode"; |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
public Sample2DTexture() |
|||
{ |
|||
name = "Sample2DTexture"; |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
{ |
|||
AddSlot(new MaterialSlot(TextureAssetSlotId, kTextureAssetName, kTextureAssetName, SlotType.Input, SlotValueType.Texture2D, Vector4.zero, false)); |
|||
AddSlot(new MaterialSlot(UVSlotId, kUVSlotName, kUVSlotName, SlotType.Input, SlotValueType.Vector2, Vector4.zero, false)); |
|||
AddSlot(new MaterialSlot(SamplerSlotId, kSamplerName, kSamplerName, SlotType.Input, SlotValueType.SamplerState, Vector4.zero, false)); |
|||
AddSlot(new MaterialSlot(OutputSlotRGBAId, kOutputSlotRGBAName, kOutputSlotRGBAName, SlotType.Output, SlotValueType.Vector4, Vector4.zero)); |
|||
RemoveSlotsNameNotMatching(validSlots); |
|||
} |
|||
{ |
|||
AddSlot(new MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Vector4, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(TextureInputId, kTextureInputName, kTextureInputName, SlotType.Input, SlotValueType.Texture2D, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(UVInput, kUVInputName, kUVInputName, SlotType.Input, SlotValueType.Vector2, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(SamplerInput, kSamplerInputName, kSamplerInputName, SlotType.Input, SlotValueType.SamplerState, Vector4.zero)); |
|||
RemoveSlotsNameNotMatching(new[] { OutputSlotId, TextureInputId, UVInput, SamplerInput }); |
|||
} |
|||
protected int[] validSlots |
|||
{ |
|||
get { return new[] { OutputSlotRGBAId, SamplerSlotId, UVSlotId, TextureAssetSlotId }; } |
|||
} |
|||
|
|||
// Node generations
|
|||
public virtual void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode) |
|||
// Node generations
|
|||
public virtual void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
//Texture input slot
|
|||
var textureSlot = FindInputSlot<MaterialSlot>(TextureInputId); |
|||
var edgesTexture = owner.GetEdges(textureSlot.slotReference); |
|||
// if no texture connected return nothing
|
|||
if (!edgesTexture.Any()) |
|||
|
|||
//Texture input slot
|
|||
var textureSlot = FindInputSlot<MaterialSlot>(TextureAssetSlotId); |
|||
var textureAssetName = ""; |
|||
var edgesTexture = owner.GetEdges(textureSlot.slotReference).ToList(); |
|||
|
|||
if (edgesTexture.Count > 0) |
|||
{ |
|||
var edge = edgesTexture[0]; |
|||
var fromNode = owner.GetNodeFromGuid<AbstractMaterialNode>(edge.outputSlot.nodeGuid); |
|||
textureAssetName = ShaderGenerator.AdaptNodeOutput(fromNode, edge.outputSlot.slotId, ConcreteSlotValueType.Texture2D, true); |
|||
} |
|||
|
|||
//UV input slot
|
|||
var uvSlot = FindInputSlot<MaterialSlot>(UVSlotId); |
|||
var uvName = string.Format("{0}.xy", UVChannel.uv0.GetUVName()); |
|||
if (uvSlot == null) |
|||
visitor.AddShaderChunk(precision + "4 " + GetVariableNameForSlot(OutputSlotId) + " = " + precision + "4(0,0,0,0);", true); |
|||
|
|||
var edgesUV = owner.GetEdges(uvSlot.slotReference).ToList(); |
|||
|
|||
if (edgesUV.Count > 0) |
|||
{ |
|||
var edge = edgesUV[0]; |
|||
var fromNode = owner.GetNodeFromGuid<AbstractMaterialNode>(edge.outputSlot.nodeGuid); |
|||
uvName = ShaderGenerator.AdaptNodeOutput(fromNode, edge.outputSlot.slotId, ConcreteSlotValueType.Vector2, true); |
|||
} |
|||
|
|||
|
|||
//Sampler input slot
|
|||
var samplerSlot = FindInputSlot<MaterialSlot>(SamplerSlotId); |
|||
var samplerName = "my_linear_repeat_sampler"; |
|||
|
|||
if (samplerSlot == null) |
|||
return; |
|||
|
|||
var edgesSampler = owner.GetEdges(samplerSlot.slotReference).ToList(); |
|||
|
|||
if (edgesSampler.Count > 0) |
|||
{ |
|||
var edge = edgesSampler[0]; |
|||
var fromNode = owner.GetNodeFromGuid<AbstractMaterialNode>(edge.outputSlot.nodeGuid); |
|||
samplerName = ShaderGenerator.AdaptNodeOutput(fromNode, edge.outputSlot.slotId, ConcreteSlotValueType.SamplerState, true); |
|||
} |
|||
|
|||
visitor.AddShaderChunk(precision + "4 " + GetVariableNameForNode() + "_Uniform = " + precision + "4(0,0,0,0);", true); |
|||
visitor.AddShaderChunk("#ifdef UNITY_COMPILER_HLSL", true); |
|||
string body = textureAssetName + ".Sample(" + samplerName + ", " + uvName + ");"; |
|||
if (m_TextureType == TextureType.Bump) |
|||
body = precision + "4(UnpackNormal(" + body + "), 0)"; |
|||
|
|||
visitor.AddShaderChunk(GetVariableNameForNode() + "_Uniform" + " = " + body, true); |
|||
|
|||
visitor.AddShaderChunk("#endif", true); |
|||
} |
|||
|
|||
// Properties
|
|||
public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode) |
|||
{ /* |
|||
visitor.AddShaderProperty( |
|||
new TexturePropertyChunk( |
|||
propertyName, |
|||
description, |
|||
defaultTexture, m_TextureType, |
|||
PropertyChunk.HideState.Visible, |
|||
exposedState == ExposedState.Exposed ? |
|||
TexturePropertyChunk.ModifiableState.Modifiable |
|||
: TexturePropertyChunk.ModifiableState.NonModifiable)); |
|||
*/ |
|||
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
//UV input slot
|
|||
var uvSlot = FindInputSlot<MaterialSlot>(UVInput); |
|||
var uvName = string.Format("{0}.xy", UVChannel.uv0.GetUVName()); |
|||
var edgesUV = owner.GetEdges(uvSlot.slotReference); |
|||
if (edgesUV.Any()) |
|||
uvName = GetSlotValue(UVInput, generationMode); |
|||
var samplerSlot = FindInputSlot<MaterialSlot>(SamplerSlotId); |
|||
var samplerName = "my_linear_repeat_sampler"; |
|||
var samplerSlot = FindInputSlot<MaterialSlot>(SamplerInput); |
|||
var edgesSampler = owner.GetEdges(samplerSlot.slotReference); |
|||
if (samplerSlot == null) |
|||
return; |
|||
|
|||
var edgesSampler = owner.GetEdges(samplerSlot.slotReference).ToList(); |
|||
|
|||
if (edgesSampler.Count > 0) |
|||
string result; |
|||
if (edgesSampler.Any()) |
|||
var edge = edgesSampler[0]; |
|||
var fromNode = owner.GetNodeFromGuid<AbstractMaterialNode>(edge.outputSlot.nodeGuid); |
|||
samplerName = ShaderGenerator.AdaptNodeOutput(fromNode, edge.outputSlot.slotId, ConcreteSlotValueType.SamplerState, true); |
|||
result = string.Format(@"
|
|||
#ifdef UNITY_COMPILER_HLSL |
|||
{0}4 {1} = {2}.Sample({3}, {4}); |
|||
#else
|
|||
{0}4 {1} = UNITY_SAMPLE_TEX2D({2}, {4}); |
|||
#endif"
|
|||
, precision |
|||
, GetVariableNameForSlot(OutputSlotId) |
|||
, GetSlotValue(TextureInputId, generationMode) |
|||
, GetSlotValue(SamplerInput, generationMode) |
|||
, uvName); |
|||
|
|||
visitor.AddShaderChunk("#ifdef UNITY_COMPILER_HLSL", false); |
|||
visitor.AddShaderChunk(samplerSlot.valueType + " " + samplerName + ";", true); |
|||
visitor.AddShaderChunk("#endif", false); |
|||
} |
|||
|
|||
|
|||
public override PreviewProperty GetPreviewProperty() |
|||
else |
|||
return new PreviewProperty |
|||
{ |
|||
m_Name = propertyName, |
|||
m_PropType = PropertyType.Texture, |
|||
m_Texture = defaultTexture |
|||
}; |
|||
result = string.Format("{0}4 {1} = UNITY_SAMPLE_TEX2D({2},{3});" |
|||
, precision |
|||
, GetVariableNameForSlot(OutputSlotId) |
|||
, GetSlotValue(TextureInputId, generationMode) |
|||
, uvName); |
|||
|
|||
public override PropertyType propertyType { get { return PropertyType.Texture; } } |
|||
visitor.AddShaderChunk(result, true); |
|||
} |
|||
public bool RequiresMeshUV(UVChannel channel) |
|||
public bool RequiresMeshUV(UVChannel channel) |
|||
{ |
|||
if (channel != UVChannel.uv0) |
|||
if (channel != UVChannel.uv0) |
|||
{ |
|||
return false; |
|||
} |
|||
|
|||
var uvSlot = FindInputSlot<MaterialSlot>(UVSlotId); |
|||
if (uvSlot == null) |
|||
return true; |
|||
|
|||
var edges = owner.GetEdges(uvSlot.slotReference).ToList(); |
|||
return edges.Count == 0; |
|||
return false; |
|||
//prevent validation errors when a sampler2D input is missing
|
|||
//use on any input requiring a TextureAssetNode
|
|||
public override void ValidateNode() |
|||
{ |
|||
base.ValidateNode(); |
|||
var slot = FindInputSlot<MaterialSlot>(TextureAssetSlotId); |
|||
if (slot == null) |
|||
return; |
|||
var uvSlot = FindInputSlot<MaterialSlot>(UVInput); |
|||
if (uvSlot == null) |
|||
return true; |
|||
var edges = owner.GetEdges(slot.slotReference).ToList(); |
|||
hasError |= edges.Count == 0; |
|||
var edges = owner.GetEdges(uvSlot.slotReference).ToList(); |
|||
return edges.Count == 0; |
|||
|
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue