Skip to content

Commit 687f3a4

Browse files
authored
Remove circular dependency from shFromCubemap (playcanvas#2648)
1 parent 57eb975 commit 687f3a4

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/graphics/prefilter-cubemap.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ import { shaderChunks } from './program-lib/chunks/chunks.js';
1212
import { RenderTarget } from './render-target.js';
1313
import { Texture } from './texture.js';
1414

15-
import { Application } from '../framework/application.js';
16-
1715
function syncToCpu(device, targ, face) {
1816
var tex = targ._colorBuffer;
1917
if (tex.format != PIXELFORMAT_R8_G8_B8_A8) return;
@@ -41,7 +39,9 @@ function prefilterCubemap(options) {
4139
var cpuSync = options.cpuSync;
4240

4341
if (cpuSync && !sourceCubemap._levels[0]) {
42+
// #ifdef DEBUG
4443
console.error("ERROR: prefilter: cubemap must have _levels");
44+
// #endif
4545
return;
4646
}
4747

@@ -306,24 +306,27 @@ function texelCoordSolidAngle(u, v, size) {
306306
return solidAngle;
307307
}
308308

309-
function shFromCubemap(source, dontFlipX) {
309+
function shFromCubemap(device, source, dontFlipX) {
310310
var face;
311311
var cubeSize = source.width;
312312
var x, y;
313313

314-
if (source.format != PIXELFORMAT_R8_G8_B8_A8) {
314+
if (source.format !== PIXELFORMAT_R8_G8_B8_A8) {
315+
// #ifdef DEBUG
315316
console.error("ERROR: SH: cubemap must be RGBA8");
317+
// #endif
316318
return;
317319
}
318320
if (!source._levels[0]) {
321+
// #ifdef DEBUG
319322
console.error("ERROR: SH: cubemap must be synced to CPU");
323+
// #endif
320324
return;
321325
}
322326
if (!source._levels[0][0].length) {
323327
// Cubemap is not composed of arrays
324328
if (source._levels[0][0] instanceof HTMLImageElement) {
325329
// Cubemap is made of imgs - convert to arrays
326-
var device = Application.getApplication().graphicsDevice;
327330
var gl = device.gl;
328331
var shader = createShaderFromCode(device,
329332
shaderChunks.fullscreenQuadVS,
@@ -368,7 +371,9 @@ function shFromCubemap(source, dontFlipX) {
368371
source._levels[0][face] = pixels;
369372
}
370373
} else {
374+
// #ifdef DEBUG
371375
console.error("ERROR: SH: cubemap must be composed of arrays or images");
376+
// #endif
372377
return;
373378
}
374379
}

src/scene/materials/standard-material.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,7 @@ Object.assign(StandardMaterial.prototype, {
981981
var atlas = [prefilteredCubeMap128, prefilteredCubeMap64, prefilteredCubeMap32,
982982
prefilteredCubeMap16, prefilteredCubeMap8, prefilteredCubeMap4];
983983
prefilteredCubeMap128.dpAtlas = generateDpAtlas(device, atlas);
984-
prefilteredCubeMap128.sh = shFromCubemap(prefilteredCubeMap16);
984+
prefilteredCubeMap128.sh = shFromCubemap(device, prefilteredCubeMap16);
985985
}
986986
this.dpAtlas = prefilteredCubeMap128.dpAtlas;
987987
this.ambientSH = prefilteredCubeMap128.sh;

0 commit comments

Comments
 (0)