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

NodeMaterial: Added energy preservation flag #17163

Merged
merged 1 commit into from
Aug 5, 2019
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
4 changes: 4 additions & 0 deletions examples/jsm/nodes/materials/nodes/StandardNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ function StandardNode() {
this.roughness = new FloatNode( 0.5 );
this.metalness = new FloatNode( 0.5 );

this.energyPreservation = true;

}

StandardNode.prototype = Object.create( Node.prototype );
Expand All @@ -32,6 +34,8 @@ StandardNode.prototype.build = function ( builder ) {

builder.define( this.clearCoat || this.clearCoatRoughness ? 'PHYSICAL' : 'STANDARD' );

if ( this.energyPreservation ) builder.define( 'ENERGY_PRESERVATION' );

builder.requires.lights = true;

builder.extensions.shaderTextureLOD = true;
Expand Down
2 changes: 2 additions & 0 deletions src/materials/MeshStandardMaterial.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface MeshStandardMaterialParameters extends MaterialParameters {
alphaMap?: Texture;
envMap?: Texture;
envMapIntensity?: number;
energyPreservation: boolean;
refractionRatio?: number;
wireframe?: boolean;
wireframeLinewidth?: number;
Expand Down Expand Up @@ -66,6 +67,7 @@ export class MeshStandardMaterial extends Material {
alphaMap: Texture | null;
envMap: Texture | null;
envMapIntensity: number;
energyPreservation: boolean;
refractionRatio: number;
wireframe: boolean;
wireframeLinewidth: number;
Expand Down
6 changes: 6 additions & 0 deletions src/materials/MeshStandardMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ import { Color } from '../math/Color.js';
* envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
* envMapIntensity: <float>
*
* energyPreservation: <bool>,
*
* refractionRatio: <float>,
*
* wireframe: <boolean>,
Expand Down Expand Up @@ -99,6 +101,8 @@ function MeshStandardMaterial( parameters ) {
this.envMap = null;
this.envMapIntensity = 1.0;

this.energyPreservation = true;

this.refractionRatio = 0.98;

this.wireframe = false;
Expand Down Expand Up @@ -161,6 +165,8 @@ MeshStandardMaterial.prototype.copy = function ( source ) {
this.envMap = source.envMap;
this.envMapIntensity = source.envMapIntensity;

this.energyPreservation = source.energyPreservation;

this.refractionRatio = source.refractionRatio;

this.wireframe = source.wireframe;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in GeometricCo

// Defer to the IndirectSpecular function to compute
// the indirectDiffuse if energy preservation is enabled.
#ifndef ENVMAP_TYPE_CUBE_UV
#ifndef ENERGY_PRESERVATION

reflectedLight.indirectDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );

Expand All @@ -120,7 +120,7 @@ void RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 irradia

// Both indirect specular and diffuse light accumulate here
// if energy preservation enabled, and PMREM provided.
#if defined( ENVMAP_TYPE_CUBE_UV )
#if defined( ENERGY_PRESERVATION )

vec3 singleScattering = vec3( 0.0 );
vec3 multiScattering = vec3( 0.0 );
Expand Down
2 changes: 2 additions & 0 deletions src/renderers/webgl/WebGLProgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,8 @@ function WebGLProgram( renderer, extensions, code, material, shader, parameters,

parameters.physicallyCorrectLights ? '#define PHYSICALLY_CORRECT_LIGHTS' : '',

parameters.energyPreservation ? '#define ENERGY_PRESERVATION' : '',

parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
parameters.logarithmicDepthBuffer && ( capabilities.isWebGL2 || extensions.get( 'EXT_frag_depth' ) ) ? '#define USE_LOGDEPTHBUF_EXT' : '',

Expand Down
2 changes: 2 additions & 0 deletions src/renderers/webgl/WebGLPrograms.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ function WebGLPrograms( renderer, extensions, capabilities ) {
toneMapping: renderer.toneMapping,
physicallyCorrectLights: renderer.physicallyCorrectLights,

energyPreservation: material.energyPreservation,

premultipliedAlpha: material.premultipliedAlpha,

alphaTest: material.alphaTest,
Expand Down