浏览代码

Merge pull request #248 from keijiro/shapes-aa

Antialiasing with procedural shapes.
/main
GitHub 7 年前
当前提交
0f41473d
共有 4 个文件被更改,包括 10 次插入20 次删除
  1. 5
      com.unity.shadergraph/Editor/Data/Nodes/Procedural/Shape/EllipseNode.cs
  2. 3
      com.unity.shadergraph/Editor/Data/Nodes/Procedural/Shape/PolygonNode.cs
  3. 8
      com.unity.shadergraph/Editor/Data/Nodes/Procedural/Shape/RectangleNode.cs
  4. 14
      com.unity.shadergraph/Editor/Data/Nodes/Procedural/Shape/RoundedRectangleNode.cs

5
com.unity.shadergraph/Editor/Data/Nodes/Procedural/Shape/EllipseNode.cs


return
@"
{
UV = (UV * 2.0 - 1.0);
UV = UV / {precision}2(Width, Height);
Out = step(length(UV), 1);
{precision} d = length((UV * 2 - 1) / {precision}2(Width, Height));
Out = saturate((1 - d) / fwidth(d));
}";
}
}

3
com.unity.shadergraph/Editor/Data/Nodes/Procedural/Shape/PolygonNode.cs


{precision} pCoord = atan2(uv.x, uv.y);
{precision} r = tau / Sides;
{precision} distance = cos(floor(0.5 + pCoord / r) * r - pCoord) * length(uv);
{precision} value = 1 - step(1, smoothstep(0, 1, distance));
Out = value;
Out = saturate((1 - distance) / fwidth(distance));
}
";
}

8
com.unity.shadergraph/Editor/Data/Nodes/Procedural/Shape/RectangleNode.cs


return
@"
{
{precision}2 XMinAndMax = {precision}2(0.5 - Width / 2, 0.5 + Width / 2);
{precision}2 YMinAndMax = {precision}2(0.5 - Height / 2, 0.5 + Height / 2);
{precision} x = step( XMinAndMax.x, UV.x ) - step( XMinAndMax.y, UV.x );
{precision} y = step( YMinAndMax.x, UV.y ) - step( YMinAndMax.y, UV.y );
Out = x * y;
{precision}2 d = abs(UV * 2 - 1) - {precision}2(Width, Height);
d = 1 - d / fwidth(d);
Out = saturate(min(d.x, d.y));
}";
}
}

14
com.unity.shadergraph/Editor/Data/Nodes/Procedural/Shape/RoundedRectangleNode.cs


return
@"
{
Radius = min(abs(Radius), 0.5 * min(abs(Width), abs(Height)));
{precision}2 XMinAndMax = {precision}2(0.5 - abs(Width) / 2, 0.5 + abs(Width) / 2);
{precision}2 YMinAndMax = {precision}2(0.5 - abs(Height) / 2, 0.5 + abs(Height) / 2);
{precision} wide = (step( XMinAndMax.x, UV.x ) - step( XMinAndMax.y, UV.x )) * (step( YMinAndMax.x + Radius, UV.y ) - step( YMinAndMax.y - Radius, UV.y ));
{precision} tall = (step( XMinAndMax.x + Radius, UV.x ) - step( XMinAndMax.y - Radius, UV.x )) * (step( YMinAndMax.x, UV.y ) - step( YMinAndMax.y, UV.y ));
{precision} sw = step(length(UV - {precision}2(XMinAndMax.x + Radius, YMinAndMax.x + Radius)), Radius);
{precision} se = step(length(UV - {precision}2(XMinAndMax.y - Radius, YMinAndMax.x + Radius)), Radius);
{precision} nw = step(length(UV - {precision}2(XMinAndMax.x + Radius, YMinAndMax.y - Radius)), Radius);
{precision} ne = step(length(UV - {precision}2(XMinAndMax.y - Radius, YMinAndMax.y - Radius)), Radius);
Out = saturate(wide + tall + sw + se + nw + ne);
Radius = max(min(min(abs(Radius * 2), abs(Width)), abs(Height)), 1e-5);
{precision}2 uv = abs(UV * 2 - 1) - {precision}2(Width, Height) + Radius;
{precision} d = length(max(0, uv)) / Radius;
Out = saturate((1 - d) / fwidth(d));
}";
}
}
正在加载...
取消
保存