Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/scene/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -1081,15 +1081,22 @@ export const EVENT_PRERENDER_LAYER = 'prerender:layer';
export const EVENT_POSTRENDER_LAYER = 'postrender:layer';

/**
* Name of event fired before visibility culling is performed for the camera
* Name of event fired before visibility culling is performed for the camera.
*
* @ignore
*/
export const EVENT_PRECULL = 'precull';

/**
* Name of event after before visibility culling is performed for the camera
* Name of event after visibility culling is performed for the camera.
*
* @ignore
*/
export const EVENT_POSTCULL = 'postcull';

/**
* Name of event after the engine has finished culling all cameras.
*
* @ignore
*/
export const EVENT_CULL_END = 'cull:end';
6 changes: 4 additions & 2 deletions src/scene/renderer/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ import {
VIEW_CENTER, PROJECTION_ORTHOGRAPHIC,
LIGHTTYPE_DIRECTIONAL, MASK_AFFECT_DYNAMIC, MASK_AFFECT_LIGHTMAPPED, MASK_BAKE,
SHADOWUPDATE_NONE, SHADOWUPDATE_THISFRAME,
EVENT_PRECULL,
EVENT_POSTCULL
EVENT_PRECULL, EVENT_POSTCULL, EVENT_CULL_END
} from '../constants.js';
import { LightCube } from '../graphics/light-cube.js';
import { getBlueNoiseTexture } from '../graphics/noise-textures.js';
Expand Down Expand Up @@ -1137,6 +1136,9 @@ class Renderer {
// cull shadow casters for all lights
this.cullShadowmaps(comp);

// event after the engine has finished culling all cameras
scene?.fire(EVENT_CULL_END);

// #if _PROFILER
this._cullTime += now() - cullTime;
// #endif
Expand Down
8 changes: 8 additions & 0 deletions src/scene/renderer/shadow-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { DebugGraphics } from '../../platform/graphics/debug-graphics.js';
import { drawQuadWithShader } from '../graphics/quad-render-utils.js';
import {
BLUR_GAUSSIAN,
EVENT_POSTCULL,
EVENT_PRECULL,
LIGHTTYPE_DIRECTIONAL, LIGHTTYPE_OMNI,
SHADER_SHADOW,
SHADOWUPDATE_NONE, SHADOWUPDATE_THISFRAME,
Expand Down Expand Up @@ -163,6 +165,9 @@ class ShadowRenderer {
*/
cullShadowCasters(comp, light, visible, camera, casters) {

// event before the camera is culling
this.renderer.scene?.fire(EVENT_PRECULL, camera);

visible.length = 0;

// if the casters are supplied, use them
Expand Down Expand Up @@ -193,6 +198,9 @@ class ShadowRenderer {

// this sorts the shadow casters by the shader id
visible.sort(this.sortCompareShader);

// event after the camera is done with culling
this.renderer.scene?.fire(EVENT_POSTCULL, camera);
}

sortCompareShader(drawCallA, drawCallB) {
Expand Down