Fixed problem where leds were being drawn with the wrong color

This commit is contained in:
Peter Slattery 2020-06-27 14:10:25 -07:00
parent 266f42c4f6
commit 295a5aaaa0
4 changed files with 49 additions and 25 deletions

View File

@ -94,18 +94,10 @@ TestPatternOne(led_buffer* Assembly, r32 Time)
for (u32 LedIndex = 0; LedIndex < Assembly->LedCount; LedIndex++)
{
v4 LedPosition = Assembly->Positions[LedIndex];
if (LedPosition.x < 0)
{
Assembly->Colors[LedIndex].R = 255;
Assembly->Colors[LedIndex].B = 255;
Assembly->Colors[LedIndex].G = 255;
}
else
{
Assembly->Colors[LedIndex].R = 0;
Assembly->Colors[LedIndex].B = 0;
Assembly->Colors[LedIndex].G = 0;
}
float PercentX = GSRemap(LedPosition.x, -150.0f, 150.0f, 0.0f, 1.0f);
float PercentY = GSRemap(LedPosition.y, -150.0f, 150.0f, 0.0f, 1.0f);
Assembly->Colors[LedIndex].R = (u8)(PercentX * 255);
Assembly->Colors[LedIndex].G = (u8)(PercentY * 255);
}
}

View File

@ -127,7 +127,7 @@ LoadAssembly (assembly_array* Assemblies, led_system* LedSystem, memory_arena* S
NewAssembly->Arena.PlatformMemory = Context.PlatformMemory;
if (ParseAssemblyFile(NewAssembly, AssemblyFileText, Scratch))
{
v4 Offset = TempAssemblyOffsets[Assemblies->Count % TempAssemblyOffsetsCount];
v4 Offset = v4{0,0,0,0}; //TempAssemblyOffsets[Assemblies->Count % TempAssemblyOffsetsCount];
ConstructAssemblyFromDefinition(NewAssembly, FileName, Offset, LedSystem);
PlatformFree(Context.PlatformMemory, AssemblyFile.Data.Base, AssemblyFile.Data.Size);
}

View File

@ -19,6 +19,7 @@ struct camera
inline m44
GetCameraModelViewMatrix (camera Camera)
{
#if 0
// Forward
v4 CamForward = V4(Normalize(Camera.Position - Camera.LookAt), 0);
// Right
@ -42,6 +43,10 @@ GetCameraModelViewMatrix (camera Camera)
0, 0, 1, 0,
-X, -Y, -Z, 1
);
#else
m44 RotationMatrix = GetLookAtMatrix(V4(Camera.Position, 1), V4(Camera.LookAt, 1));
m44 PositionMatrix = GetPositionM44(V4(Camera.Position, 1));
#endif
m44 ModelViewMatrix = PositionMatrix * RotationMatrix;

View File

@ -72,14 +72,10 @@ SculptureView_Cleanup(panel* Panel, app_state* State)
struct draw_leds_job_data
{
v4 CameraPosition;
v4* Positions;
pixel* Colors;
led_buffer LedBuffer;
s32 StartIndex;
s32 OnePastLastIndex;
render_quad_batch_constructor* Batch;
m44 FaceCameraMatrix;
m44 ModelViewMatrix;
r32 LEDHalfWidth;
};
@ -93,6 +89,9 @@ DrawLEDsInBufferRangeJob (s32 ThreadID, void* JobData)
s32 LEDCount = Data->OnePastLastIndex - Data->StartIndex;
// TODO(Peter): Why are we doing this here? Shouldn't we be able to tell what the range
// needs to be at the time of creation? That way its all on one thread and we're not
// worried about locking up.
quad_batch_constructor_reserved_range BatchReservedRange = ThreadSafeReserveRangeInQuadConstructor(Data->Batch, LEDCount * 2);
s32 TrisUsed = 0;
@ -108,12 +107,12 @@ DrawLEDsInBufferRangeJob (s32 ThreadID, void* JobData)
v2 UV2 = v2{1, 1};
v2 UV3 = v2{0, 1};
for (s32 LedIndex = 0; LedIndex < LEDCount; LedIndex++)
for (s32 LedIndex = Data->StartIndex; LedIndex < Data->OnePastLastIndex; LedIndex++)
{
pixel PixelColor = Data->Colors[LedIndex];
pixel PixelColor = Data->LedBuffer.Colors[LedIndex];
v4 Color = v4{PixelColor.R / 255.f, PixelColor.G / 255.f, PixelColor.B / 255.f, 1.0f};
v4 Position = Data->Positions[Data->StartIndex + LedIndex];
v4 Position = Data->LedBuffer.Positions[LedIndex];
m44 FaceCameraMatrix = GetLookAtMatrix(Position, Data->CameraPosition);
v4 PositionOffset = V4(Position.xyz, 0); // Ensure PositionOffset is a vector, not a point
@ -152,21 +151,24 @@ SculptureView_Render(panel Panel, rect PanelBounds, render_command_buffer* Rende
u32 MaxLEDsPerJob = 2048;
render_quad_batch_constructor RenderLEDsBatch = PushRenderQuad3DBatch(RenderBuffer, State->LedSystem.LedsCountTotal);
u32 FocusPixel = 256;
for (u32 i = 0; i < State->Assemblies.Count; i++)
{
assembly Assembly = State->Assemblies.Values[i];
led_buffer* LedBuffer = LedSystemGetBuffer(&State->LedSystem, Assembly.LedBufferIndex);
u32 JobsNeeded = IntegerDivideRoundUp(LedBuffer->LedCount, MaxLEDsPerJob);
// TODO(Peter): TEMPORARY - identify this pixel
LedBuffer->Colors[FocusPixel] = pixel{ 255, 0, 255 };
for (u32 Job = 0; Job < JobsNeeded; Job++)
{
draw_leds_job_data* JobData = PushStruct(&State->Transient, draw_leds_job_data);
JobData->Positions = LedBuffer->Positions;
JobData->Colors = LedBuffer->Colors;
JobData->LedBuffer = *LedBuffer;
JobData->StartIndex = Job * MaxLEDsPerJob;
JobData->OnePastLastIndex = GSMin(JobData->StartIndex + MaxLEDsPerJob, LedBuffer->LedCount);
JobData->Batch = &RenderLEDsBatch;
//JobData->FaceCameraMatrix = FaceCameraMatrix;
JobData->ModelViewMatrix = ModelViewMatrix;
JobData->LEDHalfWidth = LEDHalfWidth;
@ -176,8 +178,33 @@ SculptureView_Render(panel Panel, rect PanelBounds, render_command_buffer* Rende
}
}
// TODO(Peter): I don't like the fact that setting an orthographic view inside a panel render function
// needs to relyon the window bounds rather than the panel bounds. Ideally the panel only needs to know where
// itself is, and nothing else.
PushRenderOrthographic(RenderBuffer,
State->WindowBounds.Min.x, State->WindowBounds.Min.y,
State->WindowBounds.Max.x, State->WindowBounds.Max.y);
if (State->Assemblies.Count > 0)
{
assembly Assembly = State->Assemblies.Values[0];
led_buffer* LedBuffer = LedSystemGetBuffer(&State->LedSystem, Assembly.LedBufferIndex);
//__debugbreak();
v4 LedPosition = LedBuffer->Positions[FocusPixel];
m44 Matrix = GetCameraPerspectiveProjectionMatrix(State->Camera) * GetCameraModelViewMatrix(State->Camera);
v4 LedProjectedPosition = Matrix * LedPosition;
v2 LedOnScreenPosition = LedProjectedPosition.xy;
string TempString = PushString(&State->Transient, 256);
PrintF(&TempString, "%f %f", LedOnScreenPosition.x, LedOnScreenPosition.y);
DrawString(RenderBuffer, TempString, State->Interface.Style.Font, v2{PanelBounds.Min.x + 100, PanelBounds.Max.y - 200}, WhiteV4);
v2 BoxHalfDim = v2{ 25, 25 };
v2 BoxMin = LedOnScreenPosition - BoxHalfDim;
v2 BoxMax = LedOnScreenPosition + BoxHalfDim;
PushRenderBoundingBox2D(RenderBuffer, BoxMin, BoxMax, 2.0f, TealV4);
}
Context.GeneralWorkQueue->DoQueueWorkUntilDone(Context.GeneralWorkQueue, 0);
}