Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
hoffstadt committed Dec 30, 2024
1 parent 27041b6 commit 2234382
Show file tree
Hide file tree
Showing 12 changed files with 1,885 additions and 993 deletions.
1 change: 1 addition & 0 deletions extensions/pl_ecs_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,7 @@ pl_ecs_add_component(plComponentLibrary* ptLibrary, plComponentType tType, plEnt
.tDirection = {0.0f, -1.0f, 0.0f},
.fIntensity = 1.0f,
.fRange = 10.0f,
.fRadius = 0.025f,
.tType = PL_LIGHT_TYPE_DIRECTIONAL,
.uCascadeCount = 0,
.tFlags = 0,
Expand Down
1 change: 1 addition & 0 deletions extensions/pl_ecs_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ typedef struct _plLightComponent
plVec3 tColor;
float fIntensity;
float fRange;
float fRadius;
plVec3 tPosition;
plVec3 tDirection;
uint32_t uShadowResolution; // 0 -> automatic
Expand Down
1,724 changes: 937 additions & 787 deletions extensions/pl_renderer_ext.c

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion extensions/pl_renderer_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ typedef struct _plRendererI

// per frame
void (*run_ecs) (uint32_t uSceneHandle);
void (*render_scene)(uint32_t uSceneHandle, uint32_t uViewHandle, plViewOptions tOptions);
void (*render_scene)(uint32_t uSceneHandle, const uint32_t* auViewHandles, const plViewOptions* atOptions, uint32_t uViewCount);
bool (*begin_frame) (void);
void (*end_frame) (void);
plEntity (*get_picked_entity)(void);
Expand Down
721 changes: 607 additions & 114 deletions extensions/pl_renderer_internal.c

Large diffs are not rendered by default.

79 changes: 56 additions & 23 deletions extensions/pl_renderer_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ typedef struct _plGPUMaterial
int iOcclusionTexIdx;
} plGPUMaterial;

typedef struct _plGPULight
typedef struct _plGPUDLight
{
plVec3 tPosition;
float fIntensity;
Expand All @@ -183,18 +183,44 @@ typedef struct _plGPULight

int iShadowIndex;
int iCascadeCount;
int _unused[2];
} plGPULight;
int iCastShadow;
int _unused[1];
} plGPUDLight;

typedef struct _plGPULightShadowData
typedef struct _plGPUDLightShadowData
{
plVec4 cascadeSplits;
plMat4 cascadeViewProjMat[4];
int iShadowMapTexIdx;
float fFactor;
float fXOffset;
float fYOffset;
} plGPULightShadowData;
} plGPUDLightShadowData;

typedef struct _plGPUPLight
{
plVec3 tPosition;
float fIntensity;

plVec3 tDirection;
int iType;

plVec3 tColor;
float fRange;

int iShadowIndex;
int iCastShadow;
int _unused[2];
} plGPUPLight;

typedef struct _plGPUPLightShadowData
{
plMat4 viewProjMat[6];
int iShadowMapTexIdx;
float fFactor;
float fXOffset;
float fYOffset;
} plGPUPLightShadowData;

typedef struct _BindGroup_0
{
Expand All @@ -219,11 +245,6 @@ typedef struct _DynamicData
plMat4 tModel;
} DynamicData;

typedef struct _plShadowData
{
plBufferHandle atCameraBuffers[PL_MAX_FRAMES_IN_FLIGHT];
} plShadowData;

typedef struct _plRefView
{
// renderpasses
Expand Down Expand Up @@ -269,9 +290,9 @@ typedef struct _plRefView
plDrawList3D* pt3DSelectionDrawList;

// shadows
plShadowData tShadowData;
plBufferHandle atLightShadowDataBuffer[PL_MAX_FRAMES_IN_FLIGHT];
plGPULightShadowData* sbtLightShadowData;
plBufferHandle atDShadowCameraBuffers[PL_MAX_FRAMES_IN_FLIGHT];
plBufferHandle atDLightShadowDataBuffer[PL_MAX_FRAMES_IN_FLIGHT];
plGPUDLightShadowData* sbtDLightShadowData;
} plRefView;

typedef struct _plRefScene
Expand Down Expand Up @@ -301,21 +322,31 @@ typedef struct _plRefScene
uint32_t* sbuIndexBuffer;
plGPUMaterial* sbtMaterialBuffer;
plVec4* sbtSkinVertexDataBuffer;
plGPULight* sbtLightData;
plGPUDLight* sbtDLightData;
plGPUPLight* sbtPLightData;

// GPU buffers
plBufferHandle tVertexBuffer;
plBufferHandle tIndexBuffer;
plBufferHandle tStorageBuffer;
plBufferHandle tMaterialDataBuffer;
plBufferHandle tSkinStorageBuffer;
plBufferHandle atLightBuffer[PL_MAX_VIEWS_PER_SCENE];
plBufferHandle atDLightBuffer[PL_MAX_VIEWS_PER_SCENE];
plBufferHandle atPLightBuffer[PL_MAX_VIEWS_PER_SCENE];

// views
uint32_t uViewCount;
plRefView atViews[PL_MAX_VIEWS_PER_SCENE];
plSkinData* sbtSkinData;

// shadow atlas
plPackRect* sbtShadowRects;
plRenderPassHandle tFirstShadowRenderPass;
plRenderPassHandle tShadowRenderPass;
uint32_t uShadowAtlasResolution;
plTextureHandle tShadowTexture[PL_MAX_FRAMES_IN_FLIGHT];
uint32_t atShadowTextureBindlessIndices[PL_MAX_FRAMES_IN_FLIGHT];

// ECS component library
plComponentLibrary tComponentLibrary;

Expand All @@ -340,6 +371,11 @@ typedef struct _plRefScene
plMaterialComponent* sbtMaterials;
plHashMap* ptMaterialHashmap;

// shadows
plBufferHandle atPShadowCameraBuffers[PL_MAX_FRAMES_IN_FLIGHT];
plBufferHandle atPLightShadowDataBuffer[PL_MAX_FRAMES_IN_FLIGHT];
plGPUPLightShadowData* sbtPLightShadowData;

} plRefScene;

typedef struct _plRefRendererData
Expand Down Expand Up @@ -421,6 +457,8 @@ typedef struct _plRefRendererData
// sync
plTimelineSemaphore* aptSemaphores[PL_MAX_FRAMES_IN_FLIGHT];
uint64_t aulNextTimelineValue[PL_MAX_FRAMES_IN_FLIGHT];
plTimelineSemaphore* ptClickSemaphore;
uint64_t ulSemClickNextValue;

// command pools
plCommandPool* atCmdPools[PL_MAX_FRAMES_IN_FLIGHT];
Expand All @@ -432,13 +470,6 @@ typedef struct _plRefRendererData
plTextureHandle* sbtTextureHandles;
plHashMap* ptTextureHashmap;

// shadow atlas
plPackRect* sbtShadowRects;
plRenderPassHandle tShadowRenderPass;
uint32_t uShadowAtlasResolution;
plTextureHandle tShadowTexture[PL_MAX_FRAMES_IN_FLIGHT];
uint32_t atShadowTextureBindlessIndices[PL_MAX_FRAMES_IN_FLIGHT];

// graphics options
bool bReloadSwapchain;
bool bReloadMSAA;
Expand Down Expand Up @@ -523,7 +554,9 @@ static bool pl__sat_visibility_test(plCameraComponent*, const plAABB*);
// scene render helpers
static void pl_refr_update_skin_textures(plCommandBuffer*, uint32_t);
static void pl_refr_perform_skinning(plCommandBuffer*, uint32_t);
static void pl_refr_generate_cascaded_shadow_map(plRenderEncoder*, plCommandBuffer*, uint32_t, uint32_t, plEntity tCamera);
static bool pl_refr_pack_shadow_atlas(uint32_t uSceneHandle, const uint32_t* auViewHandles, uint32_t uViewCount);
static void pl_refr_generate_cascaded_shadow_map(plRenderEncoder*, plCommandBuffer*, uint32_t, uint32_t, uint32_t, plEntity tCamera);
static void pl_refr_generate_shadow_maps(plRenderEncoder*, plCommandBuffer*, uint32_t);
static void pl_refr_post_process_scene(plCommandBuffer*, uint32_t, uint32_t, const plMat4*);

// shader variant system
Expand Down
6 changes: 4 additions & 2 deletions sandbox/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,9 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plEditorData* ptEditorData)
ptLight->uShadowResolution = 2048;
ptLight->tFlags |= PL_LIGHT_FLAG_CAST_SHADOW;

gptEcs->create_point_light(ptMainComponentLibrary, "light", (plVec3){6.0f, 4.0f, -3.0f}, NULL);
gptEcs->create_point_light(ptMainComponentLibrary, "light", (plVec3){0.0f, 2.0f, 2.0f}, &ptLight);
ptLight->uShadowResolution = 2048;
ptLight->tFlags |= PL_LIGHT_FLAG_CAST_SHADOW;

// load models

Expand Down Expand Up @@ -352,7 +354,7 @@ pl_app_update(plEditorData* ptEditorData)
.ptViewCamera = &ptEditorData->tMainCamera,
.ptCullCamera = ptEditorData->bFreezeCullCamera ? &ptEditorData->tCullCamera : NULL
};
gptRenderer->render_scene(ptEditorData->uSceneHandle0, ptEditorData->uViewHandle0, tViewOptions);
gptRenderer->render_scene(ptEditorData->uSceneHandle0, &ptEditorData->uViewHandle0, &tViewOptions, 1);
}

gptUi->set_next_window_pos((plVec2){0, 0}, PL_UI_COND_ONCE);
Expand Down
Loading

0 comments on commit 2234382

Please sign in to comment.