Skip to content

Commit

Permalink
fix: cascade issue in renderer ext
Browse files Browse the repository at this point in the history
  • Loading branch information
hoffstadt committed Jan 3, 2025
1 parent d69e55f commit 2bc2277
Show file tree
Hide file tree
Showing 13 changed files with 796 additions and 321 deletions.
24 changes: 23 additions & 1 deletion extensions/pl_ecs_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ static plEntity pl_ecs_create_perspective_camera (plComponentLibrary*, const cha
static plEntity pl_ecs_create_orthographic_camera(plComponentLibrary*, const char* pcName, plVec3 tPos, float fWidth, float fHeight, float fNearZ, float fFarZ, plCameraComponent**);
static plEntity pl_ecs_create_directional_light (plComponentLibrary*, const char* pcName, plVec3 tDirection, plLightComponent**);
static plEntity pl_ecs_create_point_light (plComponentLibrary*, const char* pcName, plVec3 tPosition, plLightComponent**);
static plEntity pl_ecs_create_spot_light (plComponentLibrary*, const char* pcName, plVec3 tPosition, plVec3 tDirection, plLightComponent**);
static plEntity pl_ecs_create_script (plComponentLibrary*, const char* pcFile, plScriptFlags, plScriptComponent**);
static void pl_ecs_attach_script (plComponentLibrary*, const char* pcFile, plScriptFlags, plEntity, plScriptComponent**);

Expand Down Expand Up @@ -216,6 +217,8 @@ pl_ecs_init_component_library(plComponentLibrary* ptLibrary)
ptLibrary->pInternal = PL_ALLOC(sizeof(plComponentLibraryData));
memset(ptLibrary->pInternal, 0, sizeof(plComponentLibraryData));

pl_sb_push(ptLibrary->sbtEntityGenerations, UINT32_MAX);

pl_log_info(gptLog, uLogChannelEcs, "initialized component library");
}

Expand Down Expand Up @@ -654,8 +657,10 @@ pl_ecs_add_component(plComponentLibrary* ptLibrary, plComponentType tType, plEnt
.tColor = {1.0f, 1.0f, 1.0f},
.tDirection = {0.0f, -1.0f, 0.0f},
.fIntensity = 1.0f,
.fRange = 10.0f,
.fRange = 5.0f,
.fRadius = 0.025f,
.fInnerConeAngle = 0.0f,
.fOuterConeAngle = PL_PI_4 * 0.5f,
.tType = PL_LIGHT_TYPE_DIRECTIONAL,
.uCascadeCount = 0,
.tFlags = 0,
Expand Down Expand Up @@ -761,6 +766,22 @@ pl_ecs_create_point_light(plComponentLibrary* ptLibrary, const char* pcName, plV
return tNewEntity;
}

static plEntity
pl_ecs_create_spot_light(plComponentLibrary* ptLibrary, const char* pcName, plVec3 tPosition, plVec3 tDirection, plLightComponent** pptCompOut)
{
pcName = pcName ? pcName : "unnamed spot light";
pl_log_debug_f(gptLog, uLogChannelEcs, "created spot light: '%s'", pcName);
plEntity tNewEntity = pl_ecs_create_tag(ptLibrary, pcName);
plLightComponent* ptLight = pl_ecs_add_component(ptLibrary, PL_COMPONENT_TYPE_LIGHT, tNewEntity);
ptLight->tPosition = tPosition;
ptLight->tDirection = tDirection;
ptLight->tType = PL_LIGHT_TYPE_SPOT;

if(pptCompOut)
*pptCompOut = ptLight;
return tNewEntity;
}

static plEntity
pl_ecs_create_script(plComponentLibrary* ptLibrary, const char* pcFile, plScriptFlags tFlags, plScriptComponent** pptCompOut)
{
Expand Down Expand Up @@ -1760,6 +1781,7 @@ pl_load_ecs_ext(plApiRegistryI* ptApiRegistry, bool bReload)
.create_animation_data = pl_ecs_create_animation_data,
.create_directional_light = pl_ecs_create_directional_light,
.create_point_light = pl_ecs_create_point_light,
.create_spot_light = pl_ecs_create_spot_light,
.create_script = pl_ecs_create_script,
.attach_script = pl_ecs_attach_script,
.attach_component = pl_ecs_attach_component,
Expand Down
9 changes: 7 additions & 2 deletions extensions/pl_ecs_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ typedef struct _plEcsI
plEntity (*create_orthographic_camera)(plComponentLibrary*, const char* pcName, plVec3 tPos, float fWidth, float fHeight, float fNearZ, float fFarZ, plCameraComponent**);
plEntity (*create_directional_light) (plComponentLibrary*, const char* pcName, plVec3 tDirection, plLightComponent**);
plEntity (*create_point_light) (plComponentLibrary*, const char* pcName, plVec3 tPosition, plLightComponent**);
plEntity (*create_spot_light) (plComponentLibrary*, const char* pcName, plVec3 tPosition, plVec3 tDirection, plLightComponent**);

// scripts
plEntity (*create_script)(plComponentLibrary*, const char* pcFile, plScriptFlags, plScriptComponent**);
Expand Down Expand Up @@ -289,14 +290,16 @@ enum _plMeshFormatFlags

enum _plLightFlags
{
PL_LIGHT_FLAG_NONE = 0,
PL_LIGHT_FLAG_NONE = 0,
PL_LIGHT_FLAG_CAST_SHADOW = 1 << 0,
PL_LIGHT_FLAG_VISUALIZER = 1 << 2,
};

enum _plLightType
{
PL_LIGHT_TYPE_DIRECTIONAL,
PL_LIGHT_TYPE_POINT
PL_LIGHT_TYPE_POINT,
PL_LIGHT_TYPE_SPOT
};

enum _plHumanoidBone
Expand Down Expand Up @@ -461,6 +464,8 @@ typedef struct _plLightComponent
float fIntensity;
float fRange;
float fRadius;
float fInnerConeAngle; // default: 0
float fOuterConeAngle; // default: 45
plVec3 tPosition;
plVec3 tDirection;
uint32_t uShadowResolution; // 0 -> automatic
Expand Down
Loading

0 comments on commit 2bc2277

Please sign in to comment.