From fd315f15828b8537a48530c094ced845edc3a1d3 Mon Sep 17 00:00:00 2001 From: Fox Caminiti Date: Wed, 23 Nov 2022 20:39:55 -0500 Subject: effects reintroduction --- main.cpp | 152 +++++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 85 insertions(+), 67 deletions(-) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index 9c05334..ddf1560 100644 --- a/main.cpp +++ b/main.cpp @@ -91,8 +91,10 @@ static uint32 RandomGlobalIncrement = 0; #include "prenderer.cpp" #include "gl_calls.cpp" #include "bezier.cpp" -#if 0 +#include "effects_gl_shader.cpp" #include "effects.cpp" +#include "effects_constructors.cpp" +#if 0 #include "keyframes.cpp" #include "layer.cpp" #include "bitmap_calls.cpp" @@ -182,16 +184,19 @@ Main_InputTest(project_data *File, project_state *State, memory *Memory, ui *UI, ImGui_DebugUndoTree(Memory, State); } -#if 0 if (State->Initializing == 3) { Source_UICreateButton(File, State, Memory, Sorted.CompArray, Sorted.LayerArray); - block_layer *Layera = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, 2); + block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, 0); + Layer->Block_Effect_Index[0] = Effect_Init(State, Memory, 0, Layer->Block_Effect_Count); + Layer->Block_Effect_Count = 1; + } +#if 0 // Layera->x.IsToggled = true; // Layera->y.IsToggled = true; - block_layer *Layerb = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, 1); + // block_layer *Layerb = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, 1); // Layerb->x.IsToggled = true; // Layerb->y.IsToggled = true; - block_layer *Layerc = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, 0); + // block_layer *Layerc = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, 0); // Layerc->x.IsToggled = true; // Layerc->y.IsToggled = true; // Layer_Select(Memory, State, 0); @@ -272,6 +277,7 @@ Main_InputTest(project_data *File, project_state *State, memory *Memory, ui *UI, ImGui_File(File, State, Memory, io, Sorted.CompArray, Sorted.LayerArray); ImGui_PropertiesPanel(File, State, UI, Memory, io); ImGui_ColorPanel(File, State, UI, Memory, io); + ImGui_EffectsPanel(File, State, Memory, UI, io); #if STABLE ImGui_SD_Prompt(File, State, UI, Memory, io, Sorted.CompArray, Sorted.LayerArray); ImGui_SD_Thumbnail(File, State, UI, Memory, io, Sorted.CompArray, Sorted.LayerArray, Sorted.SourceArray, Sorted.TempSourceCount); @@ -299,6 +305,57 @@ Render_Main(void *Data, void *OutputBuffer, render_type RenderType, rectangle Re } } +static void +Layer_UpdateAllKeyframes(project_data *File, project_state *State, memory *Memory, block_layer *Layer, uint16 Index_Physical, sorted_property_info *SortedPropertyInfo, uint16 *SortedPropertyArray, uint16 Frame_Current) +{ + int32 Offset = (State->Interact_Active == interact_type_keyframe_move) ? (int32)State->Interact_Offset[0] : 0; + for (int h = 0; h < AmountOf(Layer->Property); h++) { + property_channel *Property = &Layer->Property[h]; + sorted_property_info *InfoLocation = Property_GetSortedInfo(SortedPropertyInfo, Index_Physical, h); + uint16 *ArrayLocation = Property_GetSortedArray(SortedPropertyArray, Index_Physical, h); + if (Property->Block_Bezier_Count) { + real32 MinY, MaxY; + Property_MinMax_Y(Memory, State, Property, InfoLocation, &MinY, &MaxY); + real32 Y_Increment = 1 / (MaxY - MinY); + v2 FirstPointPos[3]; + bezier_point *FirstPointAddress = Bezier_LookupAddress(Memory, Property, ArrayLocation[0]); + Bezier_EvaluateValue(State, FirstPointAddress, FirstPointPos); + v2 LastPointPos[3]; + bezier_point *LastPointAddress = Bezier_LookupAddress(Memory, Property, ArrayLocation[Property->Keyframe_Count - 1]); + Bezier_EvaluateValue(State, LastPointAddress, LastPointPos); + if (FirstPointPos[0].x >= Frame_Current) { + Property->CurrentValue = FirstPointPos[0].y; + } else if (LastPointPos[0].x <= Frame_Current) { + Property->CurrentValue = LastPointPos[0].y; + } else { + int KeyframeIndex = 0; + for (;;) { + v2 PointPos[3]; + bezier_point *PointAddress = Bezier_LookupAddress(Memory, Property, ArrayLocation[KeyframeIndex + 1]); + Bezier_EvaluateValue(State, PointAddress, PointPos, 1, Y_Increment); + if (PointPos[0].x >= Frame_Current) + break; + KeyframeIndex++; + } + v2 PointPos[3]; + bezier_point *PointAddress = Bezier_LookupAddress(Memory, Property, ArrayLocation[KeyframeIndex]); + Bezier_EvaluateValue(State, PointAddress, PointPos, 1, Y_Increment); + v2 NextPointPos[3]; + bezier_point *NextPointAddress = Bezier_LookupAddress(Memory, Property, ArrayLocation[KeyframeIndex + 1]); + Bezier_EvaluateValue(State, NextPointAddress, NextPointPos, 1, Y_Increment); + if (PointAddress->Type == interpolation_type_hold) { + Property->CurrentValue = PointPos[0].y; + } else if (PointAddress->Type == interpolation_type_linear && NextPointAddress->Type == interpolation_type_linear) { + real32 Ratio = (Frame_Current - PointPos[0].x) / (NextPointPos[0].x - PointPos[0].x); + Property->CurrentValue = PointPos[0].y + ((NextPointPos[0].y - PointPos[0].y) * Ratio); + } else { + Property->CurrentValue = Bezier_SolveYForX(PointPos[0], PointPos[0] + PointPos[2], NextPointPos[0] + NextPointPos[1], NextPointPos[0], Frame_Current); + } + } + } + } +} + static void * Render_Comp(project_data *File, project_state *State, memory *Memory, ImGuiIO io, sorted_comp_info *SortedCompArray, sorted_layer *SortedLayerArray, @@ -326,56 +383,12 @@ Render_Comp(project_data *File, project_state *State, memory *Memory, ImGuiIO io Layer->Frame_End > Frame_Current && Layer->IsVisible) { if (State->UpdateKeyframes) { - int32 Offset = (State->Interact_Active == interact_type_keyframe_move) ? (int32)State->Interact_Offset[0] : 0; - for (int h = 0; h < AmountOf(Layer->Property); h++) { - property_channel *Property = &Layer->Property[h]; - sorted_property_info *InfoLocation = Property_GetSortedInfo(SortedPropertyInfo, Index_Physical, h); - uint16 *ArrayLocation = Property_GetSortedArray(SortedPropertyArray, Index_Physical, h); - if (Property->Block_Bezier_Count) { - real32 MinY, MaxY; - Property_MinMax_Y(Memory, State, Property, InfoLocation, &MinY, &MaxY); - real32 Y_Increment = 1 / (MaxY - MinY); - v2 FirstPointPos[3]; - bezier_point *FirstPointAddress = Bezier_LookupAddress(Memory, Property, ArrayLocation[0]); - Bezier_EvaluateValue(State, FirstPointAddress, FirstPointPos); - v2 LastPointPos[3]; - bezier_point *LastPointAddress = Bezier_LookupAddress(Memory, Property, ArrayLocation[Property->Keyframe_Count - 1]); - Bezier_EvaluateValue(State, LastPointAddress, LastPointPos); - if (FirstPointPos[0].x >= Frame_Current) { - Property->CurrentValue = FirstPointPos[0].y; - } else if (LastPointPos[0].x <= Frame_Current) { - Property->CurrentValue = LastPointPos[0].y; - } else { - int KeyframeIndex = 0; - for (;;) { - v2 PointPos[3]; - bezier_point *PointAddress = Bezier_LookupAddress(Memory, Property, ArrayLocation[KeyframeIndex + 1]); - Bezier_EvaluateValue(State, PointAddress, PointPos, 1, Y_Increment); - if (PointPos[0].x >= Frame_Current) - break; - KeyframeIndex++; - } - v2 PointPos[3]; - bezier_point *PointAddress = Bezier_LookupAddress(Memory, Property, ArrayLocation[KeyframeIndex]); - Bezier_EvaluateValue(State, PointAddress, PointPos, 1, Y_Increment); - v2 NextPointPos[3]; - bezier_point *NextPointAddress = Bezier_LookupAddress(Memory, Property, ArrayLocation[KeyframeIndex + 1]); - Bezier_EvaluateValue(State, NextPointAddress, NextPointPos, 1, Y_Increment); - if (PointAddress->Type == interpolation_type_hold) { - Property->CurrentValue = PointPos[0].y; - } else if (PointAddress->Type == interpolation_type_linear && NextPointAddress->Type == interpolation_type_linear) { - real32 Ratio = (Frame_Current - PointPos[0].x) / (NextPointPos[0].x - PointPos[0].x); - Property->CurrentValue = PointPos[0].y + ((NextPointPos[0].y - PointPos[0].y) * Ratio); - } else { - Property->CurrentValue = Bezier_SolveYForX(PointPos[0], PointPos[0] + PointPos[2], NextPointPos[0] + NextPointPos[1], NextPointPos[0], Frame_Current); - } - } - } - } + Layer_UpdateAllKeyframes(File, State, Memory, Layer, Index_Physical, SortedPropertyInfo, SortedPropertyArray, Frame_Current); } layer_bitmap_state *BitmapState = &State->Render.Bitmap[Index_Physical]; void *BitmapAddress = NULL; + void *SecondSourceBitmap = NULL; // If there are effects or we're in interact_type_brush, we need to redirect to another scratch bitmap. int Width = 0, Height = 0, BytesPerPixel = 0; uint64 ScratchActive = 0; if (!Layer->IsPrecomp) { @@ -390,7 +403,7 @@ Render_Comp(project_data *File, project_state *State, memory *Memory, ImGuiIO io Assert(Source->Type == source_type_principal); void *SourceBitmapAddress = Memory_Block_AddressAtIndex(Memory, F_PrincipalBitmaps, Source->Bitmap_Index, 0); ScratchActive = Source->Width * Source->Height * Source->BytesPerPixel; - void *SecondSourceBitmap = Memory_PushScratch(Memory, ScratchActive); + SecondSourceBitmap = Memory_PushScratch(Memory, ScratchActive); Memory_Copy((uint8 *)SecondSourceBitmap, (uint8 *)SourceBitmapAddress, ScratchActive); // TODO(fox): Do all these extra precomputes really make a difference in the renderer? rectangle RenderRegion = { 0, 0, Source->Width, Source->Height }; @@ -438,19 +451,21 @@ Render_Comp(project_data *File, project_state *State, memory *Memory, ImGuiIO io } Assert(BitmapAddress); - // for (int a = 0; a < Layer->Block_Mask_Count; a++) { - // } - // for (int a = 0; a < Layer->Block_Effect_Count; a++) { - // } - - /* - for (int h = 0; h < AmountOf(Layer->Property); h++) { - property_channel *Property = &Layer->Property[h]; - if (Property->Keyframe_Count) { - Property->CurrentValue = State->Frame_Current * 2; + if (Layer->Block_Effect_Count && !SecondSourceBitmap) { + block_source *Source; + if ((State->PreviewSource != -1) && Layer->IsSelected) { + Source = (block_source *)Memory_Block_AddressAtIndex(Memory, F_Sources, State->PreviewSource); + } else { + Source = (block_source *)Memory_Block_AddressAtIndex(Memory, F_Sources, Layer->Block_Source_Index); } + void *SourceBitmapAddress = Memory_Block_AddressAtIndex(Memory, F_PrincipalBitmaps, Source->Bitmap_Index, 0); + ScratchActive = Source->Width * Source->Height * Source->BytesPerPixel; + SecondSourceBitmap = Memory_PushScratch(Memory, ScratchActive); + Memory_Copy((uint8 *)SecondSourceBitmap, (uint8 *)SourceBitmapAddress, ScratchActive); + BitmapAddress = SecondSourceBitmap; } - */ + + Layer_UpdateMasksEffects(State, Layer, Memory, BitmapAddress, Width, Height, BytesPerPixel); Assert(Width); Assert(Height); @@ -526,6 +541,7 @@ int main(int argc, char *argv[]) { Memory_InitTable(&GlobalMemory, &Memory, 1 * 1024 * 1024, F_Precomps, "Precomps", sizeof(block_composition)); Memory_InitTable(&GlobalMemory, &Memory, 2 * 1024 * 1024, F_Layers, "Layers", sizeof(block_layer)); Memory_InitTable(&GlobalMemory, &Memory, 1 * 1024 * 1024, F_Sources, "Sources", sizeof(block_source)); + Memory_InitTable(&GlobalMemory, &Memory, 2 * 1024 * 1024, F_Effects, "Properties", sizeof(block_effect)); Memory_InitTable(&GlobalMemory, &Memory, 2 * 1024 * 1024, F_Properties, "Properties", sizeof(property_channel)); Memory_InitTable(&GlobalMemory, &Memory, 4 * 1024 * 1024, F_Bezier, "Bezier paths (keyframes, masks)", sizeof(block_bezier)); Memory_InitTable(&GlobalMemory, &Memory, 4 * 1024 * 1024, F_Strings, "Strings", sizeof(block_string)); @@ -587,13 +603,13 @@ int main(int argc, char *argv[]) { File->Comp_Count = 1; -#if 0 { - uint16 SourceIndex = Source_Generate(File, State, &Memory, (void *)"../asset/hand/a.png"); + uint16 SourceIndex = Source_Generate(File, State, &Memory, (void *)"../asset/a.jpg"); block_source *Source = (block_source *)Memory_Block_AddressAtIndex(&Memory, F_Sources, 0); Source->IsSelected = true; } +#if 0 { uint16 SourceIndex = Source_Generate(File, State, &Memory, (void *)"../asset/hand/b.jpg"); block_source *Source = (block_source *)Memory_Block_AddressAtIndex(&Memory, F_Sources, 1); @@ -683,6 +699,8 @@ int main(int argc, char *argv[]) { GL_InitDefaultShader(); GL_InitDefaultVerts(); + Effect_InitEntries(State); + SDL_GL_MakeCurrent(window, gl_context); SDL_Event Event; @@ -717,7 +735,7 @@ int main(int argc, char *argv[]) { Brush_CalcBitmapAlphaFromSize(&Memory, &State->Brush, 4); State_BindBrushTexture(&Memory, &State->Brush, 4); - File_Open(File, State, &Memory, "test"); + // File_Open(File, State, &Memory, "test"); #if STABLE curl_global_init(CURL_GLOBAL_ALL); @@ -740,7 +758,7 @@ int main(int argc, char *argv[]) { if (State->IsPlaying) { block_composition *MainComp = (block_composition *)Memory_Block_AddressAtIndex(&Memory, F_Precomps, File->PrincipalCompIndex); - State->Frame_Current = ((State->Frame_Current + 1) >= MainComp->Frame_Count) ? 0 : State->Frame_Current + 1; + Playhead_Increment(&State->Frame_Current, MainComp->Frame_Start, MainComp->Frame_End, 1); State->UpdateFrame = true; State->UpdateKeyframes = true; } -- cgit v1.2.3