Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #13082 Shadow generator on NullEngine #13088

Merged
merged 4 commits into from Oct 10, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 48 additions & 0 deletions packages/dev/core/src/Engines/nullEngine.ts
Expand Up @@ -752,6 +752,54 @@ export class NullEngine extends Engine {
return rtWrapper;
}

/**
* Creates a new render target wrapper
* @param size defines the size of the texture
* @param options defines the options used to create the texture
* @returns a new render target wrapper
*/
public createRenderTargetCubeTexture(size: number, options?: Partial<RenderTargetCreationOptions>): RenderTargetWrapper {
const rtWrapper = this._createHardwareRenderTargetWrapper(false, true, size);

const fullOptions = {
generateMipMaps: true,
generateDepthBuffer: true,
generateStencilBuffer: false,
type: Constants.TEXTURETYPE_UNSIGNED_INT,
samplingMode: Constants.TEXTURE_TRILINEAR_SAMPLINGMODE,
format: Constants.TEXTUREFORMAT_RGBA,
...options,
};
fullOptions.generateStencilBuffer = fullOptions.generateDepthBuffer && fullOptions.generateStencilBuffer;

if (fullOptions.type === Constants.TEXTURETYPE_FLOAT && !this._caps.textureFloatLinearFiltering) {
// if floating point linear (gl.FLOAT) then force to NEAREST_SAMPLINGMODE
fullOptions.samplingMode = Constants.TEXTURE_NEAREST_SAMPLINGMODE;
} else if (fullOptions.type === Constants.TEXTURETYPE_HALF_FLOAT && !this._caps.textureHalfFloatLinearFiltering) {
// if floating point linear (HALF_FLOAT) then force to NEAREST_SAMPLINGMODE
fullOptions.samplingMode = Constants.TEXTURE_NEAREST_SAMPLINGMODE;
}

rtWrapper._generateDepthBuffer = fullOptions.generateDepthBuffer;
rtWrapper._generateStencilBuffer = fullOptions.generateStencilBuffer ? true : false;

const texture = new InternalTexture(this, InternalTextureSource.RenderTarget);
texture.baseWidth = size;
texture.baseHeight = size;
texture.width = size;
texture.height = size;
texture.isReady = true;
texture.isCube = true;
texture.samples = 1;
texture.generateMipMaps = fullOptions.generateMipMaps ? true : false;
texture.samplingMode = fullOptions.samplingMode;
texture.type = fullOptions.type;

this._internalTexturesCache.push(texture);

return rtWrapper;
}

/**
* Update the sampling mode of a given texture
* @param samplingMode defines the required sampling mode
Expand Down
@@ -0,0 +1,32 @@
import { NullEngine } from "core/Engines";
import type { Engine } from "core/Engines";
import { PointLight } from "core/Lights/pointLight";
import { ShadowGenerator } from "core/Lights/Shadows/shadowGenerator";
import { Vector3 } from "core/Maths/math.vector";
import { Scene } from "core/scene";

import "core/Lights/Shadows/shadowGeneratorSceneComponent";

describe("ShadowGenerator", () => {
describe("instantiate", () => {
let subject: Engine;

beforeEach(function () {
subject = new NullEngine({
renderHeight: 256,
renderWidth: 256,
textureSize: 256,
deterministicLockstep: false,
lockstepMaxSteps: 1,
});
});

it("should be able to be instantiated with a null engine", () => {
const scene = new Scene(subject);
const light = new PointLight("Point", new Vector3(1,1,1), scene);
const generator = new ShadowGenerator(1024, light);

expect(generator).not.toBeUndefined();
});
});
});