// Standard 2D rotation formula. private static float2x2 Rotate2x2(float a) { float c = Hlsl.Cos(a); float s = Hlsl.Sin(a); return(new(c, -s, s, c)); }
// A standard square grid 2D blobby Truchet routine: Render circles // in opposite corners of a tile, reverse the pattern on alternate // checker tiles, and randomly rotate. private static float Truchet(Float2 p) { const float sc = 0.5f; Float2 ip = Hlsl.Floor(p / sc) + 0.5f; p -= ip * sc; float rnd = Hlsl.Frac(Hlsl.Sin(Hlsl.Dot(ip, new Float2(1, 113))) * 45758.5453f); if (rnd < .5) { p.Y = -p.Y; } float d = Hlsl.Min(Distance(p - 0.5f * sc), Distance(p + 0.5f * sc)) - 0.5f * sc; if (SHAPE == 4) { d += (0.5f - 0.5f / Hlsl.Sqrt(2.0f)) * sc; } if (rnd < 0.5f) { d = -d; } if (Mod(ip.X + ip.Y, 2.0f) < 0.5f) { d = -d; } return(d - 0.03f); }
/// <inheritdoc/> public float4 Execute() { float2 position = ((float2)(256 * ThreadIds.XY)) / DispatchSize.X + time; float4 color = 0; for (int i = 0; i < 6; i++) { float2 a = Hlsl.Floor(position); float2 b = Hlsl.Frac(position); float4 w = Hlsl.Frac( (Hlsl.Sin(a.X * 7 + 31.0f * a.Y + 0.01f * time) + new float4(0.035f, 0.01f, 0, 0.7f)) * 13.545317f); color.XYZ += w.XYZ * 2.0f * Hlsl.SmoothStep(0.45f, 0.55f, w.W) * Hlsl.Sqrt(16.0f * b.X * b.Y * (1.0f - b.X) * (1.0f - b.Y)); position /= 2.0f; color /= 2.0f; } color.XYZ = Hlsl.Pow(color.XYZ, new float3(0.7f, 0.8f, 0.5f)); color.W = 1.0f; return(color); }
// float2 to float2 hash. private float2 Hash22(float2 p) { float n = Hlsl.Sin(Hlsl.Dot(p, new float2(1, 113))); p = Hlsl.Frac(new float2(262144, 32768) * n); return(Hlsl.Sin(p * 6.2831853f + time)); }
public void Execute(ThreadIds ids) { B[0] = Hlsl.Sin(A); B[1] = Hlsl.Cos(A); Hlsl.SinCos(A, out float sine, out float cosine); B[2] = sine; B[3] = cosine; }
public void Execute() { buffer[0] = Pi; buffer[1] = SinPi; buffer[2] = Hlsl.Sin(3.14f); buffer[3] = Mat.M11; buffer[4] = Mat.M12; buffer[5] = Mat.M21; buffer[6] = Mat.M22; buffer[7] = Combo; }
public void IntrinsicWithInlineOutParamater() { float angle = 80; using ReadWriteBuffer <float> buffer = Gpu.Default.AllocateReadWriteBuffer <float>(4); Action <ThreadIds> action = id => { buffer[0] = Hlsl.Sin(angle); buffer[1] = Hlsl.Cos(angle); Hlsl.SinCos(angle, out float sine, out float cosine); buffer[2] = sine; buffer[3] = cosine; };
/// <summary> /// Makes some magic happen. /// </summary> private float4 Tex(float3 p) { float t = time + 78.0f; float4 o = new(p.X, p.Y, p.Z, 3.0f * Hlsl.Sin(t * 0.1f)); float4 dec = new float4(1.0f, 0.9f, 0.1f, 0.15f) + new float4(0.06f * Hlsl.Cos(t * 0.1f), 0, 0, 0.14f * Hlsl.Cos(t * 0.23f)); for (int i = 0; i++ < NumberOfIterations;) { o.XZYW = Hlsl.Abs(o / Hlsl.Dot(o, o) - dec); } return(o); }
/// <inheritdoc/> public float4 Execute() { float2 scenePos = D2D.GetScenePosition().XY; float xo = scenePos.X - (this.width >> 1); float yo = scenePos.Y - (this.height >> 1); float rm = 0.5f * this.diameter; float km = 0.7f / this.diameter * MathF.PI; float w = rm / 10.0f; float yd = yo * yo; float xd = xo * xo; float d = xd + yd; float v = 1.0f + (1.0f + Hlsl.Tanh((rm - Hlsl.Sqrt(d)) / w)) * Hlsl.Sin(km * d) * 0.5f; return(new Float4(v, v, v, 1.0f)); }
// Fast hash for a pair of floats static float Hash21(float2 p) { return(Hlsl.Frac(Hlsl.Sin(Hlsl.Dot(p, new float2(27.619f, 57.583f))) * 43758.5453f)); }
// float2 to float2 hash. private static float2 Hash22B(float2 p) { float n = Hlsl.Sin(Hlsl.Dot(p, new float2(41, 289))); return(Hlsl.Frac(new float2(262144, 32768) * n) * 2.0f - 1.0f); }
// float3 to float hash. private static float Hash21(float2 p) { return(Hlsl.Frac(Hlsl.Sin(Hlsl.Dot(p, new float2(41, 289))) * 45758.5453f)); }
public void Execute(ThreadIds ids) { B[0] = Hlsl.Sin(A); B[1] = Hlsl.Cos(A); Hlsl.SinCos(A, out B[2], out B[3]); }
public void Execute(ThreadIds ids) { B[0] = Hlsl.Sin(A); Hlsl.SinCos(A, out float sine, out _); B[1] = sine; }
private static Float2x2 Rotate(float a) { float c = Hlsl.Cos(a), s = Hlsl.Sin(a); return(new(c, s, -s, c)); }