More pattern work

This commit is contained in:
PS 2021-03-22 19:09:30 -07:00
parent d81b809970
commit ef4eb84a83
5 changed files with 189 additions and 47 deletions

View File

@ -1,37 +1,37 @@
version(1); version(1);
project_name = "main.exe"; project_name = "main.exe";
patterns = { patterns = {
"*.c", "*.c",
"*.cpp", "*.cpp",
"*.h", "*.h",
"*.m", "*.m",
"*.bat", "*.bat",
"*.sh", "*.sh",
"*.4coder", "*.4coder",
}; };
blacklist_patterns = { blacklist_patterns = {
".*", ".*",
}; };
load_paths_base = { load_paths_base = {
{ "src", .relative = true, .recursive = true, }, { "src", .relative = true, .recursive = true, },
{ "meta", .relative = true, .recursive = true, }, { "meta", .relative = true, .recursive = true, },
{ "gs_libs", .relative = true, .recursive = true, }, { "gs_libs", .relative = true, .recursive = true, },
}; };
load_paths = { load_paths = {
{ load_paths_base, .os = "win", }, { load_paths_base, .os = "win", },
{ load_paths_base, .os = "linux", }, { load_paths_base, .os = "linux", },
{ load_paths_base, .os = "mac", }, { load_paths_base, .os = "mac", },
}; };
command_list = { command_list = {
{ .name = "build_application", { .name = "build_application",
.out = "*app compilation*", .footer_panel = false, .save_dirty_files = true, .out = "*compilation*", .footer_panel = false, .save_dirty_files = true,
.cmd = { { "build\build_app_msvc_win32_debug.bat" , .os = "win" }, .cmd = { { "build\build_app_msvc_win32_debug.bat" , .os = "win" },
{ "./build.sh", .os = "linux" }, { "./build.sh", .os = "linux" },
{ "./build.sh", .os = "mac" }, }, }, { "./build.sh", .os = "mac" }, }, },
{ .name = "build_meta", { .name = "build_meta",
.out = "*meta compilation*", .footer_panel = false, .save_dirty_files = true, .out = "*compilation*", .footer_panel = true, .save_dirty_files = true,
.cmd = { { "build\build_meta_msvc_win32_debug.bat" , .os = "win" }, .cmd = { { "build\build_meta_msvc_win32_debug.bat" , .os = "win" },
{ "./build_meta.sh", .os = "linux" }, { "./build_meta.sh", .os = "linux" },
{ "./build_meta.sh", .os = "mac" }, }, }, { "./build_meta.sh", .os = "mac" }, }, },
}; };

View File

@ -18,6 +18,25 @@ Smoothstep(r32 T, r32 A, r32 B)
{ {
return LerpR32(Smoothstep(T), A, B); return LerpR32(Smoothstep(T), A, B);
} }
internal v3
Smoothstep(v3 P)
{
v3 R = {};
R.x = Smoothstep(P.x);
R.y = Smoothstep(P.y);
R.z = Smoothstep(P.z);
return R;
}
internal v3
AbsV3(v3 P)
{
v3 Result = {};
Result.x = Abs(P.x);
Result.y = Abs(P.y);
Result.z = Abs(P.z);
return Result;
}
internal v2 internal v2
FloorV2(v2 P) FloorV2(v2 P)
@ -112,6 +131,15 @@ Hash3(v2 P)
return FractV3(SinV3(Q) * 43758.5453f); return FractV3(SinV3(Q) * 43758.5453f);
} }
internal r32
HashV3ToR32(v3 P)
{
v3 Pp = FractV3(P * 0.3183099f + v3{0.1f, 0.1f, 0.1f});
Pp *= 17.0f;
r32 Result = FractR32(Pp.x * Pp.y * Pp.z * (Pp.x + Pp.y + Pp.z));
return Result;
}
internal r32 internal r32
Random(v2 N) Random(v2 N)
{ {
@ -135,7 +163,35 @@ Noise2D(v2 P)
} }
internal r32 internal r32
Noise3D(v3 Pp) Noise3D(v3 P)
{
P = AbsV3(P);
v3 PFloor = FloorV3(P);
v3 PFract = FractV3(P);
v3 F = Smoothstep(PFract);
r32 Result = LerpR32(F.z,
LerpR32(F.y,
LerpR32(F.x,
HashV3ToR32(PFloor + v3{0, 0, 0}),
HashV3ToR32(PFloor + v3{1, 0, 0})),
LerpR32(F.x,
HashV3ToR32(PFloor + v3{0, 1, 0}),
HashV3ToR32(PFloor + v3{1, 1, 0}))),
LerpR32(F.y,
LerpR32(F.x,
HashV3ToR32(PFloor + v3{0, 0, 1}),
HashV3ToR32(PFloor + v3{1, 0, 1})),
LerpR32(F.x,
HashV3ToR32(PFloor + v3{0, 1, 1}),
HashV3ToR32(PFloor + v3{1, 1, 1}))));
Assert(Result >= 0 && Result <= 1);
return Result;
}
internal r32
Noise3D_(v3 Pp)
{ {
v3 P = FloorV3(Pp); v3 P = FloorV3(Pp);
v3 W = FractV3(Pp); v3 W = FractV3(Pp);
@ -219,6 +275,26 @@ Fbm3D(v3 P)
return A; return A;
} }
internal r32
Fbm3D(v3 P, r32 T)
{
v3 Tt = v3{T, T, T};
r32 SinT = SinR32(T);
v3 Tv = v3{SinT, SinT, SinT};
v3 Pp = P;
r32 F = 0.0;
F += 0.500000f * Noise3D(Pp + Tt); Pp = Pp * 2.02;
F += 0.031250f * Noise3D(Pp); Pp = Pp * 2.01;
F += 0.250000f * Noise3D(Pp); Pp = Pp * 2.03;
F += 0.125000f * Noise3D(Pp); Pp = Pp * 2.01;
F += 0.062500f * Noise3D(Pp); Pp = Pp * 2.04;
F += 0.015625f * Noise3D(Pp + Tv);
F = F / 0.984375f;
return F;
}
internal r32 internal r32
Voronoise(v2 P, r32 U, r32 V) Voronoise(v2 P, r32 U, r32 V)
{ {
@ -974,6 +1050,7 @@ Pattern_Wavy(led_buffer* Leds, assembly Assembly, r32 Time, gs_memory_arena* Tra
internal void internal void
Pattern_Patchy(led_buffer* Leds, assembly Assembly, r32 Time, gs_memory_arena* Transient, u8* UserData) Pattern_Patchy(led_buffer* Leds, assembly Assembly, r32 Time, gs_memory_arena* Transient, u8* UserData)
{ {
#if 0
for (u32 LedIndex = 0; LedIndex < Leds->LedCount; LedIndex++) for (u32 LedIndex = 0; LedIndex < Leds->LedCount; LedIndex++)
{ {
v4 P = Leds->Positions[LedIndex]; v4 P = Leds->Positions[LedIndex];
@ -994,6 +1071,49 @@ Pattern_Patchy(led_buffer* Leds, assembly Assembly, r32 Time, gs_memory_arena* T
Leds->Colors[LedIndex] = V4ToRGBPixel(C); Leds->Colors[LedIndex] = V4ToRGBPixel(C);
//Leds->Colors[LedIndex] = pixel{NV, NV, NV}; //Leds->Colors[LedIndex] = pixel{NV, NV, NV};
} }
#elif 1
for (u32 LedIndex = 0; LedIndex < Leds->LedCount; LedIndex++)
{
v4 P = Leds->Positions[LedIndex];
r32 LedRange = 300.0f;
r32 ScaleFactor = 1.0f / LedRange;
v3 Pp = P.xyz + v3{150, 100, 0};
r32 NoiseA = Noise3D((Pp / 38) + v3{0, 0, Time});
NoiseA = PowR32(NoiseA, 3);
NoiseA = Smoothstep(NoiseA);
v4 CA = v4{1, 0, 1, 1} * NoiseA;
r32 NoiseB = Noise3D((Pp / 75) + v3{Time * 0.5f, 0, 0});
NoiseB = PowR32(NoiseB, 3);
NoiseB = Smoothstep(NoiseB);
v4 CB = v4{0, 1, 1, 1} * NoiseB;
v4 C = CA + CB;
Leds->Colors[LedIndex] = V4ToRGBPixel(C);
}
#else
for (u32 LedIndex = 0; LedIndex < Leds->LedCount; LedIndex++)
{
v4 P = Leds->Positions[LedIndex];
r32 LedRange = 300.0f;
r32 ScaleFactor = 1.0f / LedRange;
v3 Pp = P.xyz + v3{150, 100, 0};
r32 NoiseA = Fbm3D((Pp / 35), Time * 0.5f);
//NoiseA = PowR32(NoiseA, 3);
NoiseA = Smoothstep(NoiseA);
v4 CA = v4{1, 0, 1, 1} * NoiseA;
r32 NoiseB = Noise3D((Pp / 35) + v3{0, 0, Time * 5});
NoiseB = PowR32(NoiseB, 3);
NoiseB = Smoothstep(NoiseB);
v4 CB = v4{0, 1, 1, 1};
v4 C = V4Lerp(NoiseB, CA, CB);
Leds->Colors[LedIndex] = V4ToRGBPixel(C);
}
#endif
} }
internal void internal void

View File

@ -683,7 +683,7 @@ WinMain (
Context.UpdateAndRender(&Context, InputQueue, &RenderBuffer, &OutputData); Context.UpdateAndRender(&Context, InputQueue, &RenderBuffer, &OutputData);
bool Multithread = true; bool Multithread = false;
if (Multithread) if (Multithread)
{ {
for (addressed_data_buffer* At = OutputData.Root; for (addressed_data_buffer* At = OutputData.Root;

View File

@ -74,38 +74,60 @@ HANDLE
Win32SerialPort_Open(char* PortName) Win32SerialPort_Open(char* PortName)
{ {
DEBUG_TRACK_FUNCTION; DEBUG_TRACK_FUNCTION;
HANDLE ComPortHandle = CreateFile(PortName, HANDLE ComPortHandle = INVALID_HANDLE_VALUE;;
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, // Default Security Attr
OPEN_EXISTING,
0, // Not overlapped I/O
NULL);
if (ComPortHandle != INVALID_HANDLE_VALUE) WIN32_FIND_DATA FindData;
HANDLE ComPortExists = FindFirstFile(PortName, &FindData);
// TODO(PS): we aren't sure yet if FindFirstFile will actually work
// for the purpose of checking to see if a ComPort actually exists.
// When you go to Foldspace next time, make sure we are still connecting
// the sculpture
if (ComPortExists != INVALID_HANDLE_VALUE)
{ {
COMMTIMEOUTS Timeouts = { 0 };
Timeouts.ReadIntervalTimeout = 0; // in milliseconds
Timeouts.ReadTotalTimeoutConstant = 0; // in milliseconds
Timeouts.ReadTotalTimeoutMultiplier = 0; // in milliseconds
Timeouts.WriteTotalTimeoutConstant = 0; // in milliseconds
Timeouts.WriteTotalTimeoutMultiplier = 0; // in milliseconds
if (SetCommTimeouts(ComPortHandle, &Timeouts)) ComPortHandle = CreateFile(PortName,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, // Default Security Attr
OPEN_EXISTING,
0, // Not overlapped I/O
NULL);
bool HasError = false;
if (ComPortHandle != INVALID_HANDLE_VALUE)
{ {
COMMTIMEOUTS Timeouts = { 0 };
Timeouts.ReadIntervalTimeout = 0; // in milliseconds
Timeouts.ReadTotalTimeoutConstant = 0; // in milliseconds
Timeouts.ReadTotalTimeoutMultiplier = 0; // in milliseconds
Timeouts.WriteTotalTimeoutConstant = 0; // in milliseconds
Timeouts.WriteTotalTimeoutMultiplier = 0; // in milliseconds
HasError = !SetCommTimeouts(ComPortHandle, &Timeouts);
} }
else else
{ {
s32 Error = GetLastError(); HasError = true;
// TODO(pjs): Error logging }
if (HasError)
{
// Error
s32 Error = GetLastError();
switch (Error)
{
case ERROR_NO_SUCH_DEVICE:
case ERROR_FILE_NOT_FOUND:
{
// NOTE(PS): The outer scope should handle these cases
ComPortHandle = INVALID_HANDLE_VALUE;
}break;
InvalidDefaultCase;
}
} }
}
else
{
// Error
s32 Error = GetLastError();
// TODO(pjs): Error logging
} }
return ComPortHandle; return ComPortHandle;

View File

@ -173,7 +173,7 @@ BlumenLumen_CustomInit(app_state* State, context Context)
BLState->MicListenJobData.OutgoingMsgQueue = &BLState->OutgoingMsgQueue; BLState->MicListenJobData.OutgoingMsgQueue = &BLState->OutgoingMsgQueue;
BLState->MicListenJobData.ListenSocket = CreateSocket(Context.SocketManager, "127.0.0.1", "20185"); BLState->MicListenJobData.ListenSocket = CreateSocket(Context.SocketManager, "127.0.0.1", "20185");
#if 1 #if 0
BLState->MicListenThread = CreateThread(Context.ThreadManager, BlumenLumen_MicListenJob, (u8*)&BLState->MicListenJobData); BLState->MicListenThread = CreateThread(Context.ThreadManager, BlumenLumen_MicListenJob, (u8*)&BLState->MicListenJobData);
#endif #endif
@ -213,7 +213,7 @@ BlumenLumen_CustomInit(app_state* State, context Context)
Anim2.PlayableRange.Max = SecondsToFrames(15, State->AnimationSystem); Anim2.PlayableRange.Max = SecondsToFrames(15, State->AnimationSystem);
Animation_AddLayer(&Anim2, MakeString("Base Layer"), BlendMode_Overwrite, &State->AnimationSystem); Animation_AddLayer(&Anim2, MakeString("Base Layer"), BlendMode_Overwrite, &State->AnimationSystem);
Animation_AddBlock(&Anim2, 0, Anim0.PlayableRange.Max, Patterns_IndexToHandle(17), 0); Animation_AddBlock(&Anim2, 0, Anim0.PlayableRange.Max, Patterns_IndexToHandle(16), 0);
BLState->AnimHandles[2] = AnimationArray_Push(&State->AnimationSystem.Animations, Anim2); BLState->AnimHandles[2] = AnimationArray_Push(&State->AnimationSystem.Animations, Anim2);