This commit is contained in:
2024-09-20 20:30:10 +02:00
commit 4fabf1a6fd
29169 changed files with 1706941 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
using System.Reflection;
using UnityEngine;
namespace UnityEditor.ShaderGraph
{
[Title("Procedural", "Shape", "Ellipse")]
class EllipseNode : CodeFunctionNode
{
public EllipseNode()
{
name = "Ellipse";
synonyms = new string[] { "circle" };
}
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_Ellipse", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_Ellipse(
[Slot(0, Binding.MeshUV0)] Vector2 UV,
[Slot(2, Binding.None, 0.5f, 0, 0, 0)] Vector1 Width,
[Slot(3, Binding.None, 0.5f, 0, 0, 0)] Vector1 Height,
[Slot(4, Binding.None, ShaderStageCapability.Fragment)] out Vector1 Out)
{
return
@"
{
#if defined(SHADER_STAGE_RAY_TRACING)
Out = saturate((1.0 - length((UV * 2 - 1) / $precision2(Width, Height))) * 1e7);
#else
$precision d = length((UV * 2 - 1) / $precision2(Width, Height));
Out = saturate((1 - d) / fwidth(d));
#endif
}";
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: c65ff5e45f92e3b498f3ec3aa63b9598
timeCreated: 1495550756
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,48 @@
using System.Reflection;
using UnityEngine;
namespace UnityEditor.ShaderGraph
{
[Title("Procedural", "Shape", "Polygon")]
class PolygonNode : CodeFunctionNode
{
public PolygonNode()
{
name = "Polygon";
synonyms = new string[] { "shape" };
}
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_Polygon", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_Polygon(
[Slot(0, Binding.MeshUV0)] Vector2 UV,
[Slot(1, Binding.None, 6, 0, 0, 0)] Vector1 Sides,
[Slot(2, Binding.None, 0.5f, 0, 0, 0)] Vector1 Width,
[Slot(3, Binding.None, 0.5f, 0, 0, 0)] Vector1 Height,
[Slot(4, Binding.None, ShaderStageCapability.Fragment)] out DynamicDimensionVector Out)
{
return
@"
{
$precision pi = 3.14159265359;
$precision aWidth = Width * cos(pi / Sides);
$precision aHeight = Height * cos(pi / Sides);
$precision2 uv = (UV * 2 - 1) / $precision2(aWidth, aHeight);
uv.y *= -1;
$precision pCoord = atan2(uv.x, uv.y);
$precision r = 2 * pi / Sides;
$precision distance = cos(floor(0.5 + pCoord / r) * r - pCoord) * length(uv);
#if defined(SHADER_STAGE_RAY_TRACING)
Out = saturate((1.0 - distance) * 1e7);
#else
Out = saturate((1 - distance) / fwidth(distance));
#endif
}
";
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 97e0f55e76f7d88449d41fe897188d67
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,95 @@
using System.Reflection;
using UnityEngine;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Controls;
namespace UnityEditor.ShaderGraph
{
enum ClampType
{
Fastest,
Nicest
};
[Title("Procedural", "Shape", "Rectangle")]
class RectangleNode : CodeFunctionNode
{
public RectangleNode()
{
name = "Rectangle";
synonyms = new string[] { "square" };
}
[SerializeField]
private ClampType m_ClampType = ClampType.Fastest;
[EnumControl("")]
public ClampType clampType
{
get { return m_ClampType; }
set
{
if (m_ClampType == value)
return;
m_ClampType = value;
Dirty(ModificationScope.Graph);
}
}
protected override MethodInfo GetFunctionToConvert()
{
switch (clampType)
{
case ClampType.Nicest:
return GetType().GetMethod("Unity_Rectangle_Nicest", BindingFlags.Static | BindingFlags.NonPublic);
case ClampType.Fastest:
default:
return GetType().GetMethod("Unity_Rectangle_Fastest", BindingFlags.Static | BindingFlags.NonPublic);
}
}
static string Unity_Rectangle_Fastest(
[Slot(0, Binding.MeshUV0)] Vector2 UV,
[Slot(1, Binding.None, 0.5f, 0, 0, 0)] Vector1 Width,
[Slot(2, Binding.None, 0.5f, 0, 0, 0)] Vector1 Height,
[Slot(3, Binding.None, ShaderStageCapability.Fragment)] out Vector1 Out)
{
return
@"
{
$precision2 d = abs(UV * 2 - 1) - $precision2(Width, Height);
#if defined(SHADER_STAGE_RAY_TRACING)
d = saturate((1 - saturate(d * 1e7)));
#else
d = saturate(1 - d / fwidth(d));
#endif
Out = min(d.x, d.y);
}";
}
static string Unity_Rectangle_Nicest(
[Slot(0, Binding.MeshUV0)] Vector2 UV,
[Slot(1, Binding.None, 0.5f, 0, 0, 0)] Vector1 Width,
[Slot(2, Binding.None, 0.5f, 0, 0, 0)] Vector1 Height,
[Slot(3, Binding.None, ShaderStageCapability.Fragment)] out Vector1 Out)
{
return
@"
{
UV = UV * 2.0 - 1.0;
$precision2 w = $precision2(Width, Height); // rectangle width/height
#if defined(SHADER_STAGE_RAY_TRACING)
$precision2 o = saturate(0.5f + 1e7 * (w - abs(UV)));
o = min(o, 1e7 * w * 2.0f);
#else
$precision2 f = min(fwidth(UV), 0.5f);
$precision2 k = 1.0f / f;
$precision2 o = saturate(0.5f + k * (w - abs(UV)));
o = min(o, k * w * 2.0f);
#endif
Out = o.x * o.y;
}";
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 0f23589566e318c408af431d95bb492c
timeCreated: 1495565599
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,91 @@
using System.Reflection;
using UnityEngine;
namespace UnityEditor.ShaderGraph
{
[Title("Procedural", "Shape", "Rounded Polygon")]
class RoundedPolygonNode : CodeFunctionNode
{
public RoundedPolygonNode()
{
name = "Rounded Polygon";
synonyms = new string[] { "shape" };
}
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("RoundedPolygon_Func", BindingFlags.Static | BindingFlags.NonPublic);
}
static string RoundedPolygon_Func(
[Slot(0, Binding.MeshUV0)] Vector2 UV,
[Slot(1, Binding.None, 0.5f, 0, 0, 0)] Vector1 Width,
[Slot(2, Binding.None, 0.5f, 0, 0, 0)] Vector1 Height,
[Slot(3, Binding.None, 5f, 0, 0, 0)] Vector1 Sides,
[Slot(4, Binding.None, 0.3f, 0, 0, 0)] Vector1 Roundness,
[Slot(5, Binding.None)] out Vector1 Out)
{
return
@"
{
UV = UV * 2. + $precision2(-1.,-1.);
$precision epsilon = 1e-6;
UV.x = UV.x / ( Width + (Width==0)*epsilon);
UV.y = UV.y / ( Height + (Height==0)*epsilon);
Roundness = clamp(Roundness, 1e-6, 1.);
$precision i_sides = floor( abs( Sides ) );
$precision fullAngle = 2. * PI / i_sides;
$precision halfAngle = fullAngle / 2.;
$precision opositeAngle = HALF_PI - halfAngle;
$precision diagonal = 1. / cos( halfAngle );
// Chamfer values
$precision chamferAngle = Roundness * halfAngle; // Angle taken by the chamfer
$precision remainingAngle = halfAngle - chamferAngle; // Angle that remains
$precision ratio = tan(remainingAngle) / tan(halfAngle); // This is the ratio between the length of the polygon's triangle and the distance of the chamfer center to the polygon center
// Center of the chamfer arc
$precision2 chamferCenter = $precision2(
cos(halfAngle) ,
sin(halfAngle)
)* ratio * diagonal;
// starting of the chamfer arc
$precision2 chamferOrigin = $precision2(
1.,
tan(remainingAngle)
);
// Using Al Kashi algebra, we determine:
// The distance distance of the center of the chamfer to the center of the polygon (side A)
$precision distA = length(chamferCenter);
// The radius of the chamfer (side B)
$precision distB = 1. - chamferCenter.x;
// The refence length of side C, which is the distance to the chamfer start
$precision distCref = length(chamferOrigin);
// This will rescale the chamfered polygon to fit the uv space
// diagonal = length(chamferCenter) + distB;
$precision uvScale = diagonal;
UV *= uvScale;
$precision2 polaruv = $precision2 (
atan2( UV.y, UV.x ),
length(UV)
);
polaruv.x += HALF_PI + 2*PI;
polaruv.x = fmod( polaruv.x + halfAngle, fullAngle );
polaruv.x = abs(polaruv.x - halfAngle);
UV = $precision2( cos(polaruv.x), sin(polaruv.x) ) * polaruv.y;
// Calculate the angle needed for the Al Kashi algebra
$precision angleRatio = 1. - (polaruv.x-remainingAngle) / chamferAngle;
// Calculate the distance of the polygon center to the chamfer extremity
$precision distC = sqrt( distA*distA + distB*distB - 2.*distA*distB*cos( PI - halfAngle * angleRatio ) );
Out = UV.x;
float chamferZone = ( halfAngle - polaruv.x ) < chamferAngle;
Out = lerp( UV.x, polaruv.y / distC, chamferZone );
// Output this to have the shape mask instead of the distance field
#if defined(SHADER_STAGE_RAY_TRACING)
Out = saturate((1 - Out) * 1e7);
#else
Out = saturate((1 - Out) / fwidth(Out));
#endif
}
";
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9fe360949f7225e49ba3073ff7044159
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,42 @@
using System.Reflection;
using UnityEngine;
namespace UnityEditor.ShaderGraph
{
[Title("Procedural", "Shape", "Rounded Rectangle")]
class RoundedRectangleNode : CodeFunctionNode
{
public RoundedRectangleNode()
{
name = "Rounded Rectangle";
synonyms = new string[] { "square" };
}
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_RoundedRectangle", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_RoundedRectangle(
[Slot(0, Binding.MeshUV0)] Vector2 UV,
[Slot(1, Binding.None, 0.5f, 0, 0, 0)] Vector1 Width,
[Slot(2, Binding.None, 0.5f, 0, 0, 0)] Vector1 Height,
[Slot(3, Binding.None, 0.1f, 0, 0, 0)] Vector1 Radius,
[Slot(4, Binding.None, ShaderStageCapability.Fragment)] out Vector1 Out)
{
return
@"
{
Radius = max(min(min(abs(Radius * 2), abs(Width)), abs(Height)), 1e-5);
$precision2 uv = abs(UV * 2 - 1) - $precision2(Width, Height) + Radius;
$precision d = length(max(0, uv)) / Radius;
#if defined(SHADER_STAGE_RAY_TRACING)
Out = saturate((1 - d) * 1e7);
#else
$precision fwd = max(fwidth(d), 1e-5);
Out = saturate((1 - d) / fwd);
#endif
}";
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: faba19d28a5fc1d4187c0124658f1822
timeCreated: 1495565599
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: