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

Encoding should match scene's color management settings #5157

Merged
merged 1 commit into from
Nov 20, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/scene/screenshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ module.exports.Component = registerComponent('screenshot', {

getRenderTarget: function (width, height) {
return new THREE.WebGLRenderTarget(width, height, {
encoding: THREE.sRGBEncoding,
encoding: this.el.sceneEl.renderer.outputEncoding,
minFilter: THREE.LinearFilter,
magFilter: THREE.LinearFilter,
wrapS: THREE.ClampToEdgeWrapping,
Expand Down
54 changes: 43 additions & 11 deletions tests/components/scene/screenshot.test.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,58 @@
/* global assert, setup, suite, test */
/* global THREE, assert, setup, suite, test */
suite('screenshot', function () {
var component;
var sceneEl;

function checkRenderTarget (renderTarget, encoding) {
const texture = renderTarget.texture;
assert.equal(texture.encoding, encoding);
assert.equal(texture.minFilter, THREE.LinearFilter);
assert.equal(texture.magFilter, THREE.LinearFilter);
assert.equal(texture.wrapS, THREE.ClampToEdgeWrapping);
assert.equal(texture.wrapT, THREE.ClampToEdgeWrapping);
assert.equal(texture.format, THREE.RGBAFormat);
assert.equal(texture.type, THREE.UnsignedByteType);
}

setup(function (done) {
sceneEl = document.createElement('a-scene');
done();
// rest of scene setup has to be done inside the scripts to allow for
// variation of colorManagement parameter, which can only be set on screen creation.
});

test('capture is called when key shortcut is pressed', function () {
sceneEl.addEventListener('loaded', () => {
component = sceneEl.components.screenshot;
done();
var captureStub = this.sinon.stub(component, 'capture');
// Must call onKeyDown method directly because Chrome doesn't provide a reliable method
// for KeyboardEvent.
component.onKeyDown({
keyCode: 83,
altKey: true,
ctrlKey: true
});
assert.ok(captureStub.called);
});
document.body.appendChild(sceneEl);
});

test('capture is called when key shortcut is pressed', function () {
var captureStub = this.sinon.stub(component, 'capture');
// Must call onKeyDown method directly because Chrome doesn't provide a reliable method
// for KeyboardEvent.
component.onKeyDown({
keyCode: 83,
altKey: true,
ctrlKey: true
test('capture renders screenshot correctly (w/o Color Management)', function () {
sceneEl.addEventListener('loaded', () => {
component = sceneEl.components.screenshot;
const renderTarget = component.getRenderTarget();
checkRenderTarget(renderTarget, THREE.LinearEncoding);
});
assert.ok(captureStub.called);
document.body.appendChild(sceneEl);
});

test('capture renders screenshot correctly (w/ Color Management)', function () {
sceneEl.setAttribute('renderer', 'colorManagement: true');
sceneEl.addEventListener('loaded', () => {
component = sceneEl.components.screenshot;
const renderTarget = component.getRenderTarget();
checkRenderTarget(renderTarget, THREE.sRGBEncoding);
});
document.body.appendChild(sceneEl);
});
});