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

Add colorContribution property to lights for shadow-only lights #30094

Closed
wants to merge 5 commits into from
Closed
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
3 changes: 3 additions & 0 deletions src/lights/Light.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Light extends Object3D {

this.color = new Color( color );
this.intensity = intensity;
this.colorContribution = true; // Whether this light contributes to the color lighting

}

Expand All @@ -28,6 +29,7 @@ class Light extends Object3D {

this.color.copy( source.color );
this.intensity = source.intensity;
this.colorContribution = source.colorContribution;

return this;

Expand All @@ -39,6 +41,7 @@ class Light extends Object3D {

data.object.color = this.color.getHex();
data.object.intensity = this.intensity;
data.object.colorContribution = this.colorContribution;

if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();

Expand Down
12 changes: 6 additions & 6 deletions src/renderers/webgl/WebGLLights.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ function WebGLLights( extensions ) {

const uniforms = cache.get( light );

uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
uniforms.color.copy( light.color ).multiplyScalar( light.colorContribution ? light.intensity : 0 );

if ( light.castShadow ) {

Expand Down Expand Up @@ -293,7 +293,7 @@ function WebGLLights( extensions ) {

uniforms.position.setFromMatrixPosition( light.matrixWorld );

uniforms.color.copy( color ).multiplyScalar( intensity );
uniforms.color.copy( color ).multiplyScalar( light.colorContribution ? intensity : 0 );
uniforms.distance = distance;

uniforms.coneCos = Math.cos( light.angle );
Expand Down Expand Up @@ -342,7 +342,7 @@ function WebGLLights( extensions ) {

const uniforms = cache.get( light );

uniforms.color.copy( color ).multiplyScalar( intensity );
uniforms.color.copy( color ).multiplyScalar( light.colorContribution ? intensity : 0 );

uniforms.halfWidth.set( light.width * 0.5, 0.0, 0.0 );
uniforms.halfHeight.set( 0.0, light.height * 0.5, 0.0 );
Expand All @@ -355,7 +355,7 @@ function WebGLLights( extensions ) {

const uniforms = cache.get( light );

uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
uniforms.color.copy( light.color ).multiplyScalar( light.colorContribution ? light.intensity : 0 );
uniforms.distance = light.distance;
uniforms.decay = light.decay;

Expand Down Expand Up @@ -389,8 +389,8 @@ function WebGLLights( extensions ) {

const uniforms = cache.get( light );

uniforms.skyColor.copy( light.color ).multiplyScalar( intensity );
uniforms.groundColor.copy( light.groundColor ).multiplyScalar( intensity );
uniforms.skyColor.copy( light.color ).multiplyScalar( light.colorContribution ? intensity : 0 );
uniforms.groundColor.copy( light.groundColor ).multiplyScalar( light.colorContribution ? intensity : 0 );

state.hemi[ hemiLength ] = uniforms;

Expand Down
99 changes: 33 additions & 66 deletions test/unit/src/lights/DirectionalLight.tests.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,23 @@
/* global QUnit */

import { DirectionalLight } from '../../../../src/lights/DirectionalLight.js';

import { Light } from '../../../../src/lights/Light.js';
import { runStdLightTests } from '../../utils/qunit-utils.js';
import { Object3D } from '../../../../src/core/Object3D.js';

export default QUnit.module( 'Lights', () => {

QUnit.module( 'DirectionalLight', ( hooks ) => {

let lights = undefined;
hooks.beforeEach( function () {

const parameters = {
color: 0xaaaaaa,
intensity: 0.8
};

lights = [
new DirectionalLight(),
new DirectionalLight( parameters.color ),
new DirectionalLight( parameters.color, parameters.intensity )
];

} );
QUnit.module( 'DirectionalLight', () => {

// INHERITANCE
QUnit.test( 'Extending', ( assert ) => {

const object = new DirectionalLight();
assert.strictEqual(
object instanceof Light, true,
'DirectionalLight extends from Light'
object instanceof Object3D, true,
'DirectionalLight extends from Object3D'
);

} );

// INSTANCING
QUnit.test( 'Instancing', ( assert ) => {

const object = new DirectionalLight();
assert.ok( object, 'Can instantiate a DirectionalLight.' );

} );

// PROPERTIES
QUnit.test( 'type', ( assert ) => {

Expand All @@ -55,56 +29,49 @@ export default QUnit.module( 'Lights', () => {

} );

QUnit.todo( 'position', ( assert ) => {

assert.ok( false, 'everything\'s gonna be alright' );

} );

QUnit.todo( 'target', ( assert ) => {

assert.ok( false, 'everything\'s gonna be alright' );

} );

QUnit.todo( 'shadow', ( assert ) => {

assert.ok( false, 'everything\'s gonna be alright' );

} );
// PROPERTIES
QUnit.test( 'colorContribution', ( assert ) => {

// PUBLIC
QUnit.test( 'isDirectionalLight', ( assert ) => {
const light = new DirectionalLight();
assert.ok(
light.colorContribution === true,
'DirectionalLight.colorContribution should be true by default'
);

const object = new DirectionalLight();
light.colorContribution = false;
assert.ok(
object.isDirectionalLight,
'DirectionalLight.isDirectionalLight should be true'
light.colorContribution === false,
'DirectionalLight.colorContribution can be set to false'
);

} );

QUnit.test( 'dispose', ( assert ) => {
// COPY
QUnit.test( 'copy', ( assert ) => {

assert.expect( 0 );
const a = new DirectionalLight( 0xaaaaaa, 0.5 );
a.colorContribution = false;
const b = new DirectionalLight();
b.copy( a );

const object = new DirectionalLight();
object.dispose();

// ensure calls dispose() on shadow
assert.ok(
b.colorContribution === false,
'DirectionalLight.colorContribution is copied'
);

} );

QUnit.todo( 'copy', ( assert ) => {

assert.ok( false, 'everything\'s gonna be alright' );
// JSON
QUnit.test( 'toJSON', ( assert ) => {

} );

// OTHERS
QUnit.test( 'Standard light tests', ( assert ) => {
const light = new DirectionalLight( 0xaaaaaa, 0.5 );
light.colorContribution = false;
const json = light.toJSON();

runStdLightTests( assert, lights );
assert.ok(
json.object.colorContribution === false,
'DirectionalLight.colorContribution is included in JSON'
);

} );

Expand Down
80 changes: 31 additions & 49 deletions test/unit/src/lights/Light.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,14 @@

import { Light } from '../../../../src/lights/Light.js';

import { Object3D } from '../../../../src/core/Object3D.js';
import { runStdLightTests } from '../../utils/qunit-utils.js';

export default QUnit.module( 'Lights', () => {

QUnit.module( 'Light', ( hooks ) => {

let lights = undefined;
hooks.beforeEach( function () {

const parameters = {
color: 0xaaaaaa,
intensity: 0.5
};

lights = [
new Light(),
new Light( parameters.color ),
new Light( parameters.color, parameters.intensity )
];

} );
QUnit.module( 'Light', () => {

// INHERITANCE
QUnit.test( 'Extending', ( assert ) => {
QUnit.todo( 'Extending', ( assert ) => {

const object = new Light();
assert.strictEqual(
object instanceof Object3D, true,
'Light extends from Object3D'
);
assert.ok( false, 'everything\'s gonna be alright' );

} );

Expand All @@ -41,6 +18,7 @@ export default QUnit.module( 'Lights', () => {

const object = new Light();
assert.ok( object, 'Can instantiate a Light.' );
assert.ok( object.isLight, 'Light.isLight should be true' );

} );

Expand Down Expand Up @@ -68,42 +46,46 @@ export default QUnit.module( 'Lights', () => {
} );

// PUBLIC
QUnit.test( 'isLight', ( assert ) => {
QUnit.test( 'colorContribution', ( assert ) => {

const object = new Light();
const light = new Light();
assert.ok(
object.isLight,
'Light.isLight should be true'
light.colorContribution === true,
'Light.colorContribution should be true by default'
);

} );

QUnit.test( 'dispose', ( assert ) => {

assert.expect( 0 );

// empty, test exists
const object = new Light();
object.dispose();
light.colorContribution = false;
assert.ok(
light.colorContribution === false,
'Light.colorContribution can be set to false'
);

} );

QUnit.todo( 'copy', ( assert ) => {

assert.ok( false, 'everything\'s gonna be alright' );

} );
QUnit.test( 'copy', ( assert ) => {

QUnit.todo( 'toJSON', ( assert ) => {
const a = new Light( 0xaaaaaa, 0.5 );
a.colorContribution = false;
const b = new Light();
b.copy( a );

assert.ok( false, 'everything\'s gonna be alright' );
assert.ok(
b.colorContribution === false,
'Light.colorContribution is copied'
);

} );

// OTHERS
QUnit.test( 'Standard light tests', ( assert ) => {
QUnit.test( 'toJSON', ( assert ) => {

runStdLightTests( assert, lights );
const light = new Light( 0xaaaaaa, 0.5 );
light.colorContribution = false;
const json = light.toJSON();

assert.ok(
json.object.colorContribution === false,
'Light.colorContribution is included in JSON'
);

} );

Expand Down
Loading