@@ -264,6 +264,11 @@ pl_renderer_initialize(plRendererSettings tSettings)
264264 gptData -> tRuntimeOptions .fSaturation = 1.0f ;
265265 gptData -> tRuntimeOptions .tTonemapMode = PL_TONEMAP_MODE_SIMPLE ;
266266
267+ gptData -> tRuntimeOptions .fGridCellSize = 0.025f ;
268+ gptData -> tRuntimeOptions .fGridMinPixelsBetweenCells = 2.0f ;
269+ gptData -> tRuntimeOptions .tGridColorThin = (plVec4 ){0.5f , 0.5f , 0.5f , 1.0f };
270+ gptData -> tRuntimeOptions .tGridColorThick = (plVec4 ){1.0f , 1.0f , 1.0f , 1.0f };
271+
267272 gptResource -> initialize ((plResourceManagerInit ){.ptDevice = gptData -> ptDevice , .uMaxTextureResolution = tSettings .uMaxTextureResolution });
268273
269274 if (gptData -> tDeviceInfo .tCapabilities & PL_DEVICE_CAPABILITY_MULTIPLE_VIEWPORTS )
@@ -2789,6 +2794,33 @@ pl_renderer_render_view(plView* ptView, plCamera* ptCamera, plCamera* ptCullCame
27892794 }
27902795 gptGfx -> draw_stream (ptSceneEncoder , 1 , & tArea );
27912796
2797+ if (ptView -> bShowGrid )
2798+ {
2799+ plShaderHandle tGridShader = gptShaderVariant -> get_shader ("grid" , NULL , NULL , NULL , & gptData -> tRenderPassLayout );
2800+ gptGfx -> bind_shader (ptSceneEncoder , tGridShader );
2801+
2802+ plDynamicBinding tGridDynamicBinding = pl__allocate_dynamic_data (ptDevice );
2803+ plGpuDynGrid * ptGridDynamicData = (plGpuDynGrid * )tGridDynamicBinding .pcData ;
2804+ const float fGridFactor = pl_squaref (ptCamera -> fFarZ ) - pl_squaref (ptCamera -> tPos .y );
2805+ ptGridDynamicData -> fGridSize = fGridFactor > 0.0f ? sqrtf (fGridFactor ) : 100.0f ;
2806+ ptGridDynamicData -> fGridCellSize = gptData -> tRuntimeOptions .fGridCellSize ;
2807+ ptGridDynamicData -> fGridMinPixelsBetweenCells = gptData -> tRuntimeOptions .fGridMinPixelsBetweenCells ;
2808+ ptGridDynamicData -> tGridColorThin = gptData -> tRuntimeOptions .tGridColorThin ;
2809+ ptGridDynamicData -> tGridColorThick = gptData -> tRuntimeOptions .tGridColorThick ;
2810+ ptGridDynamicData -> fCameraXPos = ptCamera -> tPos .x ;
2811+ ptGridDynamicData -> fCameraZPos = ptCamera -> tPos .z ;
2812+ ptGridDynamicData -> tCameraViewProjection = tMVP ;
2813+
2814+ gptGfx -> bind_graphics_bind_groups (ptSceneEncoder , tGridShader , 0 , 0 , NULL , 1 , & tGridDynamicBinding );
2815+
2816+ plDraw tGridDraw = {
2817+ .uVertexCount = 6 ,
2818+ .uInstanceCount = 1 ,
2819+ };
2820+ * gptData -> pdDrawCalls += 1.0 ;
2821+ gptGfx -> draw (ptSceneEncoder , 1 , & tGridDraw );
2822+ }
2823+
27922824 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~debug drawing~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
27932825
27942826 // bounding boxes
@@ -3706,6 +3738,12 @@ pl_renderer_show_skybox(plView* ptView)
37063738 ptView -> bShowSkybox = true;
37073739}
37083740
3741+ void
3742+ pl_renderer_show_grid (plView * ptView )
3743+ {
3744+ ptView -> bShowGrid = true;
3745+ }
3746+
37093747static void
37103748pl__object_update_job (plInvocationData tInvoData , void * pData , void * pGroupSharedMemory )
37113749{
@@ -3999,6 +4037,7 @@ pl_load_renderer_ext(plApiRegistryI* ptApiRegistry, bool bReload)
39994037 tApi .debug_draw_all_bound_boxes = pl_renderer_debug_draw_all_bound_boxes ;
40004038 tApi .debug_draw_bvh = pl_renderer_debug_draw_bvh ;
40014039 tApi .show_skybox = pl_renderer_show_skybox ;
4040+ tApi .show_grid = pl_renderer_show_grid ;
40024041 tApi .register_ecs_system = pl_renderer_register_system ;
40034042 tApi .create_material = pl_renderer_create_material ;
40044043 tApi .create_skin = pl_renderer_create_skin ;
0 commit comments