Skip to content

Commit b7f9efb

Browse files
mvaligurskyMartin Valigursky
andauthored
Additional frustum culling events in order to better support indirect drawing (#7778)
Co-authored-by: Martin Valigursky <[email protected]>
1 parent be4c344 commit b7f9efb

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

src/scene/constants.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,15 +1081,22 @@ export const EVENT_PRERENDER_LAYER = 'prerender:layer';
10811081
export const EVENT_POSTRENDER_LAYER = 'postrender:layer';
10821082

10831083
/**
1084-
* Name of event fired before visibility culling is performed for the camera
1084+
* Name of event fired before visibility culling is performed for the camera.
10851085
*
10861086
* @ignore
10871087
*/
10881088
export const EVENT_PRECULL = 'precull';
10891089

10901090
/**
1091-
* Name of event after before visibility culling is performed for the camera
1091+
* Name of event after visibility culling is performed for the camera.
10921092
*
10931093
* @ignore
10941094
*/
10951095
export const EVENT_POSTCULL = 'postcull';
1096+
1097+
/**
1098+
* Name of event after the engine has finished culling all cameras.
1099+
*
1100+
* @ignore
1101+
*/
1102+
export const EVENT_CULL_END = 'cull:end';

src/scene/renderer/renderer.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ import {
2424
VIEW_CENTER, PROJECTION_ORTHOGRAPHIC,
2525
LIGHTTYPE_DIRECTIONAL, MASK_AFFECT_DYNAMIC, MASK_AFFECT_LIGHTMAPPED, MASK_BAKE,
2626
SHADOWUPDATE_NONE, SHADOWUPDATE_THISFRAME,
27-
EVENT_PRECULL,
28-
EVENT_POSTCULL
27+
EVENT_PRECULL, EVENT_POSTCULL, EVENT_CULL_END
2928
} from '../constants.js';
3029
import { LightCube } from '../graphics/light-cube.js';
3130
import { getBlueNoiseTexture } from '../graphics/noise-textures.js';
@@ -1137,6 +1136,9 @@ class Renderer {
11371136
// cull shadow casters for all lights
11381137
this.cullShadowmaps(comp);
11391138

1139+
// event after the engine has finished culling all cameras
1140+
scene?.fire(EVENT_CULL_END);
1141+
11401142
// #if _PROFILER
11411143
this._cullTime += now() - cullTime;
11421144
// #endif

src/scene/renderer/shadow-renderer.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import { DebugGraphics } from '../../platform/graphics/debug-graphics.js';
1212
import { drawQuadWithShader } from '../graphics/quad-render-utils.js';
1313
import {
1414
BLUR_GAUSSIAN,
15+
EVENT_POSTCULL,
16+
EVENT_PRECULL,
1517
LIGHTTYPE_DIRECTIONAL, LIGHTTYPE_OMNI,
1618
SHADER_SHADOW,
1719
SHADOWUPDATE_NONE, SHADOWUPDATE_THISFRAME,
@@ -163,6 +165,9 @@ class ShadowRenderer {
163165
*/
164166
cullShadowCasters(comp, light, visible, camera, casters) {
165167

168+
// event before the camera is culling
169+
this.renderer.scene?.fire(EVENT_PRECULL, camera);
170+
166171
visible.length = 0;
167172

168173
// if the casters are supplied, use them
@@ -193,6 +198,9 @@ class ShadowRenderer {
193198

194199
// this sorts the shadow casters by the shader id
195200
visible.sort(this.sortCompareShader);
201+
202+
// event after the camera is done with culling
203+
this.renderer.scene?.fire(EVENT_POSTCULL, camera);
196204
}
197205

198206
sortCompareShader(drawCallA, drawCallB) {

0 commit comments

Comments
 (0)