コード例 #1
0
    private static string Tiling_Herringbone([Slot(0, Binding.None)] Vector2 UV, [Slot(1, Binding.None, 1, 0, 0, 0)] Vector1 CellSize, [Slot(2, Binding.None)] Vector1 Offset, [Slot(3, Binding.None)] out Vector2 Out, [Slot(4, Binding.None)] out Vector2 CellIndex, [Slot(5, Binding.None)] out Vector2 CellPosition)
    {
        Out          = Vector2.zero;
        CellIndex    = Vector2.zero;
        CellPosition = Vector2.zero;
        return(@"
{   
    const float2x2 RotA = float2x2(0.7071068, 0.7071068, -0.7071068, 0.7071068);
    const float2x2 RotB = float2x2(0.7071068, -0.7071068, 0.7071068, 0.7071068);

    const float root2 = 1.73205080757;

    float Width = 0.5*CellSize;
    
    float2 P = 2*round(0.5*(UV.xx/Width - float2(0, 1))) + float2(0, 1);

    float2 X = UV.xx - Width * P;
    float2 Y = UV.yy - 0.5*P;
    float2 Q = round(Y - X * float2(1, -1));
    Y = Y - Q;
    float2 A = mul(RotA, float2(X.x, Y.x));
    float2 B = mul(RotB, float2(X.y, Y.y));
    
    if(abs(X.x + Y.x) < Width){
        Out = A;
        CellIndex = float2(P.x, Q.x);
    } else {
        Out = B;
        CellIndex = float2(P.y, Q.y);
    }
        
    CellPosition = float2(CellIndex.x * Width, 0.5*CellIndex.x + CellIndex.y);
}
");
    }
コード例 #2
0
    private static string SDFSample([Slot(0, Binding.None)] Vector1 SDF, [Slot(1, Binding.None)] Vector1 Offset, [Slot(2, Binding.None)] out Vector1 Out)
    {
        return(@"
{
    Out = SDF - Offset;
    Out = saturate(-Out / fwidth(Out));
}
");
    }
コード例 #3
0
    private static string SDFLine([Slot(0, Binding.WorldSpacePosition)] Vector2 UV, [Slot(1, Binding.None)] Vector1 Position, [Slot(2, Binding.None, 0.1f, 0, 0, 0)] Vector1 Width, [Slot(3, Binding.None)] out Vector1 SDF)
    {
        return(@"
{    
    SDF = abs(UV.x - Position) - 0.5*Width;
}
");
    }
コード例 #4
0
    private static string SDFCircle([Slot(0, Binding.WorldSpacePosition)] Vector2 UV, [Slot(1, Binding.None)] Vector2 Position, [Slot(2, Binding.None, 0.25f, 0, 0, 0)] Vector1 Radius, [Slot(3, Binding.None)] out Vector1 SDF)
    {
        return(@"
{
    SDF = length(UV - Position) - Radius;
}
");
    }
コード例 #5
0
    private static string SDFPolygon([Slot(0, Binding.WorldSpacePosition)] Vector2 UV, [Slot(1, Binding.None)] Vector2 Position, [Slot(2, Binding.None, 0.25f, 0, 0, 0)] Vector1 Radius, [Slot(3, Binding.None, 6, 0, 0, 0)] Vector1 Sides, [Slot(4, Binding.None)] Vector1 CornerRadius, [Slot(5, Binding.None)] out Vector1 SDF)
    {
        return(@"
{    
    float2 f = UV - Position;
	float theta = atan2(f.y, f.x);
	float angle = 6.2831853071/Sides;

	float SinSide, CosSide;
	sincos(round(theta / angle) * angle, SinSide, CosSide); 

    float2 d = float2(SinSide, -CosSide); 
	float2 n = float2(CosSide, SinSide);
    float t = dot(d, f);
    float sideLength = Radius * tan(0.5*angle);
    SDF = abs(t) < Radius * tan(0.5*angle) ? dot(f, n) - Radius : length(f - (Radius * n + d * clamp(dot(d, f), -sideLength, sideLength)));
    SDF = SDF - CornerRadius;
}
");
    }
コード例 #6
0
ファイル: DmxVector.cs プロジェクト: sebsegard/Perso
        public static float operator /(DmxVector Vector1, DmxVector Vector2)
        {
            DmxPoint Rapport = new DmxPoint();

            return(Vector1.GetLongueur() / Vector2.GetLongueur());
        }
コード例 #7
0
    private static string SDFBooleanSoft_Union([Slot(0, Binding.None)] Vector1 A, [Slot(1, Binding.None)] Vector1 B, [Slot(2, Binding.None, 0.1f, 0, 0, 0)] Vector1 Smoothing, [Slot(3, Binding.None)] out Vector1 Out)
    {
        return(@"
{
    float t = clamp(0.5 * (1 + (B - A) / Smoothing), 0, 1);
    Out = lerp(B, A, t) - Smoothing * t * (1 - t);
}
");
    }
コード例 #8
0
    static string RandomIntegerRange([Slot(0, Binding.None)] Vector2 Seed, [Slot(1, Binding.None)] Vector1 Min, [Slot(2, Binding.None, 10, 0, 0, 0)] Vector1 Max, [Slot(3, Binding.None)] out Vector1 Out)
    {
        return(@"
{
	float r = frac(sin(dot(Seed, float2(127.1,311.7))) * 43758.5453);
	Min = ceiling(Min);
	Max = ceiling(Max);
    return Min + (Max-Min)*floor(r * (Max-Min));
}
");
    }
コード例 #9
0
    static string SphereNormal([Slot(0, Binding.None)] Vector3 Position, [Slot(1, Binding.None)] Vector3 Direction, [Slot(2, Binding.None)] Vector1 Radius, [Slot(3, Binding.None)] out Vector3 Normal, [Slot(4, Binding.None)] out Vector1 Alpha)
    {
        Normal = Vector3.zero;
        return(@"
{
    float DD = dot(Direction, Direction);
    float DP = dot(Direction, Position);
    float PP = dot(Position, Position);
    float det2 = DP*DP-DD*(PP - Radius*Radius);
	Alpha = saturate(det2/fwidth(det2));
    float t = (-DP - sqrt(det2))/DD;
    Normal = (Position + t*Direction)/Radius;
}
");
    }
コード例 #10
0
    static string TruchetTriangle([Slot(0, Binding.WorldSpacePosition)] Vector2 Position, [Slot(1, Binding.None, 0.25f, 0, 0, 0)] Vector1 Size, [Slot(2, Binding.None, 1, 0, 0, 0)] Vector1 Number, [Slot(3, Binding.None)] Vector1 Seed, [Slot(4, Binding.None)] CodeFunctionNode.Boolean Rotate, [Slot(5, Binding.None)] CodeFunctionNode.Boolean Reflect, [Slot(6, Binding.None)] out Vector1 Index, [Slot(7, Binding.None)] out Vector2 UV)
    {
        UV = Vector2.zero;
        return(@"
{
    const float3 Cos = float3(1, 0.5, -0.5);
    const float3 Sin = float3(0, 0.86602540378, 0.86602540378);

    const float2 a = float2(1, 0);
    const float2 b = float2(0.5, 0.86602540378);
    
    UV = Position / Size;
    float d = (a.x*b.y-a.y*b.x);
    float ta = (b.y*UV.x-b.x*UV.y)/d;
    float tb = (a.x*UV.y-a.y*UV.x)/d;

    float3 cell = floor(float3(ta, tb, frac(ta) +frac(tb)));
    float rand = frac(sin(dot(cell + Seed, float3(12.9898,78.233, 45.652))) * 43758.5453);
    float nRotation = Rotate ? 3 : 1;
    float nReflection = Reflect ? 2 : 1;
    float randInt = floor(rand * Number * nRotation * nReflection);
    Index = randInt % Number;
    randInt = floor(randInt / Number);
    float Rot = cell.z + 2*(randInt % nRotation);
    randInt = floor(randInt / nRotation);
    float Refl = randInt % nReflection;
    UV = UV - a*(cell.x + 0.3333333333*(1 + cell.z)) - b*(cell.y + 0.3333333333*(1 + cell.z));
    UV.x = (1-2*Refl) * UV.x;
    UV = 1.73205080757*UV;
    UV = 0.5+ 0.5*(Rot >= 3 ? -1 : 1) * float2(UV.x*Cos[Rot%3] + UV.y *-Sin[Rot%3], UV.x*Sin[Rot%3] + UV.y *Cos[Rot%3]);
}
");
    }
コード例 #11
0
    static string TruchetSquare([Slot(0, Binding.WorldSpacePosition)] Vector2 Position, [Slot(1, Binding.None, 0.25f, 0, 0, 0)] Vector1 Size, [Slot(2, Binding.None, 1, 0, 0, 0)] Vector1 Number, [Slot(3, Binding.None)] Vector1 Seed, [Slot(4, Binding.None)] CodeFunctionNode.Boolean Rotate, [Slot(5, Binding.None)] CodeFunctionNode.Boolean Reflect, [Slot(6, Binding.None)] out Vector1 Index, [Slot(7, Binding.None)] out Vector2 UV)
    {
        UV = Vector2.zero;
        return(@"
{
    const float4 Cos = float4(1, 0, -1, 0);
    const float4 Sin = float4(0, 1, 0, -1);
    UV = Position / Size;
    float2 cell = floor(UV);
    float rand = frac(sin(dot(cell.xy + Seed, float2(12.9898,78.233))) * 43758.5453);
    float nRotation = Rotate ? 4 : 1;
    float nReflection = Reflect ? 2 : 1;
    float randInt = floor(rand * Number * nRotation * nReflection);
    Index = randInt % Number;
    randInt = floor(randInt / Number);
    float Rot = randInt % nRotation;
    randInt = floor(randInt / nRotation);
    float Refl = randInt % nReflection;
    UV = UV - cell - 0.5;
    UV.x = (1-2*Refl) * UV.x;
    UV = 0.5 + float2(UV.x*Cos[Rot] + UV.y *-Sin[Rot], UV.x*Sin[Rot] + UV.y *Cos[Rot]);
}
");
    }
コード例 #12
0
    static string TruchetHexagon([Slot(0, Binding.WorldSpacePosition)] Vector2 Position, [Slot(1, Binding.None, 0.25f, 0, 0, 0)] Vector1 Size, [Slot(2, Binding.None, 1, 0, 0, 0)] Vector1 Number, [Slot(3, Binding.None)] Vector1 Seed, [Slot(4, Binding.None)] CodeFunctionNode.Boolean Rotate, [Slot(5, Binding.None)] CodeFunctionNode.Boolean Reflect, [Slot(6, Binding.None)] out Vector1 Index, [Slot(7, Binding.None)] out Vector2 UV)
    {
        UV = Vector2.zero;
        return(@"
{
    const float3 Cos = float3(1, 0.5, -0.5);
    const float3 Sin = float3(0, 0.86602540378, 0.86602540378);

    const float2 a = float2(1, 0);
    const float2 b = float2(0.5, 0.86602540378);
    
    UV = 2 * Position / Size;
    float d = (a.x*b.y-a.y*b.x);
    float ta = (b.y*UV.x-b.x*UV.y)/d;
    float tb = (a.x*UV.y-a.y*UV.x)/d;

    float3 cell3 = floor(float3(ta, tb, frac(ta) +frac(tb)));
    float mod = cell3.x - cell3.y;
    mod = mod - 3 * floor(mod*0.33333333333);
    float2 cell = float2(cell3.x + (mod == 0 ? cell3.z : 0) + (mod == 2 ? 1 : 0), cell3.y + (mod == 0 ? cell3.z : 0) + (mod == 1 ? 1 : 0));
    float rand = frac(sin(dot(cell.xy + Seed, float2(12.9898,78.233))) * 43758.5453);
    float nRotation = Rotate ? 6 : 1;
    float nReflection = Reflect ? 2 : 1;
    float randInt = floor(rand * Number * nRotation * nReflection);
    Index = randInt % Number;
    randInt = floor(randInt / Number);
    float Rot = randInt % nRotation;
    randInt = floor(randInt / nRotation);
    float Refl = randInt % nReflection;
    UV = UV - a * cell.x - b*cell.y;
    UV.x = (1-2*Refl) * UV.x;
    UV = 0.5+ 0.5*(Rot >= 3 ? -1 : 1) * float2(UV.x*Cos[Rot%3] + UV.y *-Sin[Rot%3], UV.x*Sin[Rot%3] + UV.y *Cos[Rot%3]);
}
");
    }
コード例 #13
0
    private static string Rotation([Slot(0, Binding.None)] Vector2 UV, [Slot(1, Binding.None)] Vector2 Position, [Slot(2, Binding.None)] Vector1 Angle, [Slot(3, Binding.None, 2, 0, 0, 0)] Vector1 Order, [Slot(4, Binding.None)] out Vector2 Out)
    {
        Out = Vector2.zero;
        return(@"
{    
    UV = UV - Position;
    float angle = atan2(UV.y, UV.x) - Angle;
    float rotation = -floor(angle * Order * 0.15915494309) / (Order * 0.15915494309);
    float Sin, Cos;
    sincos(rotation, Sin, Cos);
    Out.x = Cos * UV.x - Sin * UV.y;
    Out.y = Sin * UV.x + Cos * UV.y;
    Out = Out + Position;
}
");
    }
コード例 #14
0
    private static string Reflection([Slot(0, Binding.None)] Vector2 UV, [Slot(1, Binding.None)] Vector2 Position, [Slot(2, Binding.None, 0, 1, 0, 0)] Vector2 Direction, [Slot(3, Binding.None)] Vector1 Glide, [Slot(4, Binding.None)] out Vector2 Out)
    {
        Out = Vector2.zero;
        return(@"
{    
    UV = UV - Position;
    float2 Normal = float2(Direction.y, -Direction.x);
    float distance = dot(Normal, UV);
    Out = (dot(Direction, UV) + (distance < 0 ? -Glide : 0)) * Direction + abs(distance) * Normal;
    Out = Out + Position;
}
");
    }
コード例 #15
0
    static string PixelPointGrid([Slot(0, Binding.WorldSpacePosition)] Vector2 UV, [Slot(1, Binding.None)] Vector2 Position, [Slot(2, Binding.None, 0.1f, 0, 0, 0)] Vector1 Width, [Slot(3, Binding.None)] out Vector1 Out)
    {
        return(@"
{
    float2 f = UV - Position;
	float2 rounded = {round(f.x/Width), round(f.y/Width)};
	f = f - Width * rounded;
    float2 ddxUV = ddx(UV);
    float2 ddyUV = ddy(UV);
	
	float InvD = 1/(ddxUV.x*ddyUV.y-ddxUV.y*ddyUV.x);

	float tx = (ddyUV.y*f.x-ddyUV.x*f.y)*InvD;
	float ty = (-ddxUV.y*f.x+ddxUV.x*f.y)*InvD;

    Out = (tx > -0.5 && tx <= 0.5) && (ty > -0.5 && ty <= 0.5) ? 1 : 0;
}
");
    }
コード例 #16
0
    static string SphereUV([Slot(0, Binding.None)] Vector3 Position, [Slot(1, Binding.None)] out Vector2 UV1, [Slot(2, Binding.None)] out Vector2 UV2, [Slot(3, Binding.None)] out Vector1 Alpha)
    {
        UV1 = Vector2.zero;
        UV2 = Vector2.zero;
        return(@"
{
    float theta = 0.5 + 0.15915494309 * atan2(Position.z, Position.x);
    UV1.x = theta;
    UV1.y = 0.5 + 0.31830988618 * asin(Position.y);
    UV2.x = fmod(theta + 0.5, 1); - 0.5;
    UV2.y = UV1.y;
    Alpha = 2 * abs(theta - 0.5);
}
");
    }
コード例 #17
0
    static string PixelRay([Slot(0, Binding.WorldSpacePosition)] Vector2 UV, [Slot(1, Binding.None)] Vector2 Position, [Slot(2, Binding.None, 1, 0, 0, 0)] Vector2 Direction, [Slot(3, Binding.None)] out Vector1 Out)
    {
        return(@"
{
    float2 d = Direction;
    float2 f = UV - Position;
    float2 ddxUV = ddx(UV);
    float2 ddyUV = ddy(UV);

    float tq1 = (d.x * f.y - d.y * f.x) / (ddxUV.y * d.x - ddxUV.x * d.y);
    float tq2 = (d.x * f.y - d.y * f.x) / (ddyUV.y * d.x - ddyUV.x * d.y);

    Out = (tq1 > -0.5 && tq1 <= 0.5) || (tq2 > -0.5 && tq2 <= 0.5) ? 1 : 0;
}
");
    }
コード例 #18
0
    static string PixelRays([Slot(0, Binding.WorldSpacePosition)] Vector2 UV, [Slot(1, Binding.None)] Vector2 Position, [Slot(2, Binding.None, 1, 0, 0, 0)] Vector2 Direction, [Slot(3, Binding.None, 0.1f, 0, 0, 0)] Vector1 Width, [Slot(4, Binding.None)] out Vector1 Out)
    {
        return(@"
{
    float2 d = Direction;
	float2 n = {-Direction.y, Direction.x};
	n = normalize(n);
    float2 f = UV - Position;
	f = f - Width * round(dot(n, f)/Width) * n;
    float2 ddxUV = ddx(UV);
    float2 ddyUV = ddy(UV);

    float tq1 = (d.x * f.y - d.y * f.x) / (ddxUV.y * d.x - ddxUV.x * d.y);
    float tq2 = (d.x * f.y - d.y * f.x) / (ddyUV.y * d.x - ddyUV.x * d.y);

    Out = (tq1 > -0.5 && tq1 <= 0.5) || (tq2 > -0.5 && tq2 <= 0.5) ? 1 : 0;
}
");
    }
コード例 #19
0
    private static string SDFBoolean_Difference([Slot(0, Binding.None)] Vector1 A, [Slot(1, Binding.None)] Vector1 B, [Slot(2, Binding.None)] out Vector1 Out)
    {
        return(@"
{
    Out = max(A, -B);
}
");
    }
コード例 #20
0
    static string PixelLine([Slot(0, Binding.WorldSpacePosition)] Vector2 UV, [Slot(1, Binding.None)] Vector2 Position1, [Slot(2, Binding.None)] Vector2 Position2, [Slot(3, Binding.None)] out Vector1 Out)
    {
        return(@"

{
    float2 d = Position2 - Position1;
    float2 f = UV - Position1;
    float2 ddxUV = ddx(UV);
    float2 ddyUV = ddy(UV);

    float InvD1 = 1/(ddxUV.y * d.x - ddxUV.x * d.y);
    float InvD2 = 1/(ddyUV.y * d.x - ddyUV.x * d.y);

    float tp1 = -(ddxUV.x * f.y - ddxUV.y * f.x) * InvD1;
    float tq1 = (d.x * f.y - d.y * f.x) * InvD1;

    float tp2 = -(ddyUV.x * f.y - ddyUV.y * f.x) * InvD2;
    float tq2 = (d.x * f.y - d.y * f.x) * InvD2;

    Out = (tp1 >= 0 && tp1 <= 1 && tq1 > -0.5 && tq1 <= 0.5) || (tp2 >= 0 && tp2 <= 1 && tq2 > -0.5 && tq2 <= 0.5) ? 1 : 0;
}
");
    }
コード例 #21
0
    private static string SDFBooleanSoft_Difference([Slot(0, Binding.None)] Vector1 A, [Slot(1, Binding.None)] Vector1 B, [Slot(2, Binding.None, 0.1f, 0, 0, 0)] Vector1 Smoothing, [Slot(3, Binding.None)] out Vector1 Out)
    {
        return(@"
{
    float t = clamp(0.5 * (1 + (A + B) / Smoothing), 0, 1);
    Out = -(lerp(B, -A, t) - Smoothing * t * (1 - t));
}
");
    }
コード例 #22
0
    static string PixelPoint([Slot(0, Binding.WorldSpacePosition)] Vector2 UV, [Slot(1, Binding.None)] Vector2 Position, [Slot(2, Binding.None)] out Vector1 Out)
    {
        return(@"
{
    float2 f = UV - Position;
    float2 ddxUV = ddx(UV);
    float2 ddyUV = ddy(UV);
	
	float InvD = 1/(ddxUV.x*ddyUV.y-ddxUV.y*ddyUV.x);

	float tx = (ddyUV.y*f.x-ddyUV.x*f.y)*InvD;
	float ty = (-ddxUV.y*f.x+ddxUV.x*f.y)*InvD;

    Out = (tx > -0.5 && tx <= 0.5) && (ty > -0.5 && ty <= 0.5) ? 1 : 0;
}
");
    }
コード例 #23
0
    private static string SDFRectangle([Slot(0, Binding.WorldSpacePosition)] Vector2 UV, [Slot(1, Binding.None)] Vector2 Position, [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)] Vector1 CornerRadius, [Slot(5, Binding.None)] out Vector1 SDF)
    {
        return(@"
{    
    float2 d = abs(UV - Position) - 0.5*float2(Width, Height);
    SDF = min(max(d.x,d.y), 0) + length(max(d, 0));
    SDF = SDF - CornerRadius;
}
");
    }
コード例 #24
0
    static string PixelLines([Slot(0, Binding.WorldSpacePosition)] Vector2 UV, [Slot(1, Binding.None)] Vector2 Position1, [Slot(2, Binding.None)] Vector2 Position2, [Slot(3, Binding.None, 0.1f, 0, 0, 0)] Vector1 Width, [Slot(4, Binding.None)] out Vector1 Out)
    {
        return(@"

{
    float2 d = Position2 - Position1;
	float2 n = {-d.y, d.x};
	n = normalize(n);
    float2 f = UV - Position1;
	f = f - Width * round(dot(n, f)/Width) * n;
    float2 ddxUV = ddx(UV);
    float2 ddyUV = ddy(UV);

    float InvD1 = 1/(ddxUV.y * d.x - ddxUV.x * d.y);
    float InvD2 = 1/(ddyUV.y * d.x - ddyUV.x * d.y);

    float tp1 = -(ddxUV.x * f.y - ddxUV.y * f.x) * InvD1;
    float tq1 = (d.x * f.y - d.y * f.x) * InvD1;

    float tp2 = -(ddyUV.x * f.y - ddyUV.y * f.x) * InvD2;
    float tq2 = (d.x * f.y - d.y * f.x) * InvD2;

    Out = (tp1 >= 0 && tp1 <= 1 && tq1 > -0.5 && tq1 <= 0.5) || (tp2 >= 0 && tp2 <= 1 && tq2 > -0.5 && tq2 <= 0.5) ? 1 : 0;
}
");
    }
コード例 #25
0
 /// <summary>
 /// Write instruction operands into bytecode stream.
 /// </summary>
 /// <param name="writer">Bytecode writer.</param>
 public override void WriteOperands(WordWriter writer)
 {
     Vector1.Write(writer);
     Vector2.Write(writer);
 }
コード例 #26
0
    static string PixelCircle([Slot(0, Binding.WorldSpacePosition)] Vector2 UV, [Slot(1, Binding.None)] Vector2 Center, [Slot(2, Binding.None, 0.5f, 0, 0, 0)] Vector1 Radius, [Slot(3, Binding.None)] out Vector1 Out)
    {
        return(@"

{
    float2 f = UV - Center;
    float2 ddxUV = ddx(UV);
    float2 ddyUV = ddy(UV);

	float r2 = Radius * Radius;
	
	float2 fx1, fx2, fy1, fy2;
	fx1 = f - 0.5*ddxUV;
	fx2 = f + 0.5*ddxUV;
	fy1 = f - 0.5*ddyUV;
	fy2 = f + 0.5*ddyUV;
	
    Out = ((dot(fx1, fx1) - r2) * (dot(fx2, fx2) - r2) <= 0 || (dot(fy1, fy1) - r2) * (dot(fy2, fy2) - r2) <= 0) ? 1 : 0;
}
");
    }
コード例 #27
0
    private static string SDFSampleStrip([Slot(0, Binding.None)] Vector1 SDF, [Slot(1, Binding.None, -0.05f, 0.05f, 0, 0)] Vector2 Offset, [Slot(2, Binding.None)] out Vector1 Out)
    {
        return(@"
{
    Out = max(-(SDF - Offset.x), SDF - Offset.y);
    Out = saturate(-Out / fwidth(Out));
}
");
    }
コード例 #28
0
    static string PixelPolygon([Slot(0, Binding.WorldSpacePosition)] Vector2 UV, [Slot(1, Binding.None)] Vector2 Center, [Slot(2, Binding.None, 0.5f, 0, 0, 0)] Vector1 Radius, [Slot(3, Binding.None, 6, 0, 0, 0)] Vector1 Sides, [Slot(4, Binding.None)] Vector1 Angle, [Slot(5, Binding.None)] out Vector1 Out)
    {
        return(@"

{
    float2 f = UV - Center;
	float theta = atan2(f.y, f.x);
	float angle = 6.2831853071/Sides;
	Angle = 0.0174533*Angle;

	float SinSide, CosSide;
	sincos(round((theta - Angle) / angle) * angle + Angle, SinSide, CosSide); 

    float2 d = float2(SinSide, -CosSide);
	float2 n = float2(CosSide, SinSide);
    f = f - n*Radius;
    float2 ddxUV = ddx(UV);
    float2 ddyUV = ddy(UV);

    float tq1 = (d.x * f.y - d.y * f.x) / (ddxUV.y * d.x - ddxUV.x * d.y);
    float tq2 = (d.x * f.y - d.y * f.x) / (ddyUV.y * d.x - ddyUV.x * d.y);

    Out = (tq1 > -0.5 && tq1 <= 0.5) || (tq2 > -0.5 && tq2 <= 0.5) ? 1 : 0;
}
");
    }
コード例 #29
0
    private static string SDFBoolean_Union([Slot(0, Binding.None)] Vector1 A, [Slot(1, Binding.None)] Vector1 B, [Slot(2, Binding.None)] out Vector1 Out)
    {
        return(@"
{
    Out = min(A, B);
}
");
    }
コード例 #30
0
    private static string Tiling_Triangle([Slot(0, Binding.None)] Vector2 UV, [Slot(1, Binding.None, 1, 0, 0, 0)] Vector1 CellSize, [Slot(2, Binding.None)] Vector1 Offset, [Slot(3, Binding.None)] out Vector2 Out, [Slot(4, Binding.None)] out Vector2 CellIndex, [Slot(5, Binding.None)] out Vector2 CellPosition)
    {
        Out          = Vector2.zero;
        CellIndex    = Vector2.zero;
        CellPosition = Vector2.zero;
        return(@"
{       //-0.57735026919, 1.15470053838
    const float2x2 Tri = float2x2(1, -0.57735026919, 0, 1.15470053838);
        
    float2 UV2 = UV/CellSize;
    float2 P = mul(Tri, UV2);
    float Z = floor(frac(P.x) + frac(P.y));
    float2 floorP = floor(P);
    CellIndex = float2(2 * floorP.x + Z, floorP.y);
    CellPosition = CellSize * (float2(floorP.x + 0.5*floorP.y, 0.86602540378*floorP.y) + (2 + 2*Z) * float2(0.25, 0.14433756729));
    Out = (2*Z-1)*(UV - CellPosition);
}
");
    }