浏览代码

Added support for checking compatible no-presenter anchors.

/main
damian 7 年前
当前提交
e9b2550a
共有 4 个文件被更改,包括 58 次插入42 次删除
  1. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs
  2. 43
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/MaterialGraphView.cs
  3. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/MaterialNodeView.cs
  4. 54
      MaterialGraphProject/GeneratedShader.shader

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


if (nodePresenter != null)
m_Elements.Remove(nodePresenter);
var nodeView = m_GraphView.nodes.ToList().OfType<MaterialNodeView>().FirstOrDefault(p => p.node.guid == change.node.guid);
var nodeView = m_GraphView.nodes.ToList().OfType<MaterialNodeView>().FirstOrDefault(p => p.node != null && p.node.guid == change.node.guid);
if (nodeView != null)
m_GraphView.RemoveElement(nodeView);
}

43
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/MaterialGraphView.cs


if (startStage == ShaderStage.Dynamic)
startStage = NodeUtils.FindEffectiveShaderStage(startSlot.owner, startSlot.isOutputSlot);
foreach (var anchor in anchors.ToList())
foreach (var candidateAnchor in anchors.ToList())
var candidateAnchorPresenter = anchor.presenter as GraphAnchorPresenter;
if (candidateAnchorPresenter == null)
continue;
MaterialSlot candidateSlot = null;
var candidateAnchorPresenter = candidateAnchor.presenter as GraphAnchorPresenter;
if (candidateAnchorPresenter != null)
{
if (!candidateAnchorPresenter.IsConnectable())
continue;
if (candidateAnchorPresenter.orientation != startAnchor.orientation)
continue;
if (candidateAnchorPresenter.direction == startAnchor.direction)
continue;
if (nodeAdapter.GetAdapter(candidateAnchorPresenter.source, startAnchor.source) == null)
continue;
candidateSlot = candidateAnchorPresenter.slot as MaterialSlot;
}
else
{
if (!candidateAnchor.IsConnectable())
continue;
if (candidateAnchor.orientation != startAnchor.orientation)
continue;
if (candidateAnchor.direction == startAnchor.direction)
continue;
if (nodeAdapter.GetAdapter(candidateAnchor.source, startAnchor.source) == null)
continue;
candidateSlot = candidateAnchor.userData as MaterialSlot;
}
if (!candidateAnchorPresenter.IsConnectable())
continue;
if (candidateAnchorPresenter.orientation != startAnchor.orientation)
continue;
if (candidateAnchorPresenter.direction == startAnchor.direction)
continue;
if (nodeAdapter.GetAdapter(candidateAnchorPresenter.source, startAnchor.source) == null)
continue;
var candidateSlot = candidateAnchorPresenter.slot as MaterialSlot;
if (candidateSlot == null)
continue;
if (candidateSlot.owner == startSlot.owner)

continue;
}
compatibleAnchors.Add(anchor);
compatibleAnchors.Add(candidateAnchor);
}
return compatibleAnchors;
}

1
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/MaterialNodeView.cs


var data = InstantiateNodeAnchor(Orientation.Horizontal, slot.isInputSlot ? Direction.Input : Direction.Output, typeof(Vector4));
data.capabilities &= ~Capabilities.Movable;
data.anchorName = slot.displayName;
data.userData = slot;
if (slot.isOutputSlot)
{

54
MaterialGraphProject/GeneratedShader.shader


Shader "hidden/preview/_E2A7472C"
Shader "hidden/preview/Gradient_BB2657E7"
{
Properties
{

void Unity_AACheckerboard_float(float2 uv, float4 colorA, float4 colorB, float3 aaTweak, float2 frequency, out float4 result)
void Unity_Gradient_BB2657E7_float(float value, out float4 result)
float4 derivatives = float4(ddx(uv), ddy(uv));
float2 duv_length = sqrt(float2(dot(derivatives.xz, derivatives.xz), dot(derivatives.yw, derivatives.yw)));
float width = 0.5f;
float2 distance3 = 2.0f * abs(frac(uv.xy * frequency) - 0.5f) - width;
float2 scale = aaTweak.x / duv_length.xy;
float2 blend_out = saturate((scale - aaTweak.zz) / (aaTweak.yy - aaTweak.zz));
float2 vector_alpha = clamp(distance3 * scale.xy * blend_out.xy, -1.0f, 1.0f);
float alpha = saturate(0.5f + 0.5f * vector_alpha.x * vector_alpha.y);
result= lerp(colorA, colorB, alpha.xxxx);
float3 color0=float3(1,1,1);
float colorp0=0;
float3 color1=float3(1,1,1);
float colorp1=1;
float3 gradcolor = color0;
float colorLerpPosition0=smoothstep(colorp0,colorp1,value);
gradcolor = lerp(gradcolor,color1,colorLerpPosition0);
float alpha0=1;
float alphap0=0;
float alpha1=1;
float alphap1=1;
float gradalpha = alpha0;
float alphaLerpPosition0=smoothstep(alphap0,alphap1,value);
gradalpha = lerp(gradalpha,alpha1,alphaLerpPosition0);
result = float4(gradcolor,gradalpha);
}
struct GraphVertexInput
{

UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct SurfaceInputs{
half4 uv0;
float4 _E2A7472C_result;
float4 Gradient_BB2657E7_result;
float4 _E2A7472C_uv;
float4 _E2A7472C_colorA;
float4 _E2A7472C_colorB;
float4 _E2A7472C_aaTweak;
float4 _E2A7472C_frequency;
float Gradient_BB2657E7_value;
half4 uv0 = IN.uv0;
float4 _E2A7472C_result;
Unity_AACheckerboard_float(uv0, _E2A7472C_colorA, _E2A7472C_colorB, _E2A7472C_aaTweak, _E2A7472C_frequency, _E2A7472C_result);
float4 Gradient_BB2657E7_result;
Unity_Gradient_BB2657E7_float(Gradient_BB2657E7_value, Gradient_BB2657E7_result);
surface._E2A7472C_result = _E2A7472C_result;
surface.Gradient_BB2657E7_result = Gradient_BB2657E7_result;
return surface;
}
ENDCG

struct GraphVertexOutput
{
float4 position : POSITION;
half4 uv0 : TEXCOORD;
};
GraphVertexOutput vert (GraphVertexInput v)
{

o.uv0 = v.texcoord0;
float4 uv0 = IN.uv0;
surfaceInput.uv0 =uv0;
return half4(surf._E2A7472C_result.x, surf._E2A7472C_result.y, surf._E2A7472C_result.z, 1.0);
return half4(surf.Gradient_BB2657E7_result.x, surf.Gradient_BB2657E7_result.y, surf.Gradient_BB2657E7_result.z, 1.0);
}
ENDCG
}
正在加载...
取消
保存