Skip to content
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
12 changes: 11 additions & 1 deletion examples/jsm/tsl/display/DepthOfFieldNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,14 @@ class DepthOfFieldNode extends TempNode {
*/
this._CoCTextureNode = texture( this._CoCRT.texture );

/**
* The Gaussian blur node used to blur the near field's circle of confusion.
*
* @private
* @type {GaussianBlurNode}
*/
this._CoCBlurNode = gaussianBlur( this._CoCTextureNode, 1, 2 );

/**
* The result of the blur64 pass as a texture node.
*
Expand Down Expand Up @@ -381,7 +389,7 @@ class DepthOfFieldNode extends TempNode {

// blurred CoC for near field

this._CoCBlurredMaterial.colorNode = gaussianBlur( this._CoCTextureNode, 1, 2 );
this._CoCBlurredMaterial.colorNode = this._CoCBlurNode;
this._CoCBlurredMaterial.needsUpdate = true;

// bokeh 64 blur pass
Expand Down Expand Up @@ -539,6 +547,8 @@ class DepthOfFieldNode extends TempNode {
this._blur16Material.dispose();
this._compositeMaterial.dispose();

this._CoCBlurNode.dispose();

}

}
Expand Down
6 changes: 3 additions & 3 deletions src/core/BufferAttribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -670,9 +670,9 @@ class BufferAttribute extends EventDispatcher {
normalized: this.normalized
};

if ( this.name !== '' ) data.name = this.name;
if ( this.usage !== StaticDrawUsage ) data.usage = this.usage;
if ( this.gpuType !== FloatType ) data.gpuType = this.gpuType;
data.name = this.name;
data.usage = this.usage;
data.gpuType = this.gpuType;

return data;

Expand Down
2 changes: 1 addition & 1 deletion src/core/BufferGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -1241,7 +1241,7 @@ class BufferGeometry extends EventDispatcher {

data.uuid = this.uuid;
data.type = ( this.parameters !== undefined && this._transformed === true ) ? 'BufferGeometry' : this.type;
if ( this.name !== '' ) data.name = this.name;
data.name = this.name;
if ( Object.keys( this.userData ).length > 0 ) data.userData = this.userData;

if ( this.parameters !== undefined && this._transformed !== true ) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/InterleavedBuffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ class InterleavedBuffer {
stride: this.stride
};

if ( this.usage !== StaticDrawUsage ) json.usage = this.usage;
json.usage = this.usage;

return json;

Expand Down
18 changes: 9 additions & 9 deletions src/core/Object3D.js
Original file line number Diff line number Diff line change
Expand Up @@ -1320,13 +1320,15 @@ class Object3D extends EventDispatcher {
object.uuid = this.uuid;
object.type = this.type;

if ( this.name !== '' ) object.name = this.name;
if ( this.castShadow === true ) object.castShadow = true;
if ( this.receiveShadow === true ) object.receiveShadow = true;
if ( this.visible === false ) object.visible = false;
if ( this.frustumCulled === false ) object.frustumCulled = false;
if ( this.renderOrder !== 0 ) object.renderOrder = this.renderOrder;
if ( this.static !== false ) object.static = this.static;
object.name = this.name;
object.castShadow = this.castShadow;
object.receiveShadow = this.receiveShadow;
object.visible = this.visible;
object.frustumCulled = this.frustumCulled;
object.renderOrder = this.renderOrder;
object.static = this.static;
object.matrixAutoUpdate = this.matrixAutoUpdate;

if ( Object.keys( this.userData ).length > 0 ) object.userData = this.userData;

object.layers = this.layers.mask;
Expand All @@ -1335,8 +1337,6 @@ class Object3D extends EventDispatcher {

if ( this.pivot !== null ) object.pivot = this.pivot.toArray();

if ( this.matrixAutoUpdate === false ) object.matrixAutoUpdate = false;

if ( this.morphTargetDictionary !== undefined ) object.morphTargetDictionary = Object.assign( {}, this.morphTargetDictionary );
if ( this.morphTargetInfluences !== undefined ) object.morphTargetInfluences = this.morphTargetInfluences.slice();

Expand Down
12 changes: 6 additions & 6 deletions src/lights/LightShadow.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,12 +329,12 @@ class LightShadow {

const object = {};

if ( this.intensity !== 1 ) object.intensity = this.intensity;
if ( this.bias !== 0 ) object.bias = this.bias;
if ( this.normalBias !== 0 ) object.normalBias = this.normalBias;
if ( this.radius !== 1 ) object.radius = this.radius;
if ( this.blurSamples !== 8 ) object.blurSamples = this.blurSamples;
if ( this.mapSize.x !== 512 || this.mapSize.y !== 512 ) object.mapSize = this.mapSize.toArray();
object.intensity = this.intensity;
object.bias = this.bias;
object.normalBias = this.normalBias;
object.radius = this.radius;
object.blurSamples = this.blurSamples;
object.mapSize = this.mapSize.toArray();

object.camera = this.camera.toJSON( false ).object;
delete object.camera.matrix;
Expand Down
4 changes: 2 additions & 2 deletions src/lights/SpotLightShadow.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ class SpotLightShadow extends LightShadow {

const object = super.toJSON();

if ( this.focus !== 1 ) object.focus = this.focus;
if ( this.aspect !== 1 ) object.aspect = this.aspect;
object.focus = this.focus;
object.aspect = this.aspect;

return object;

Expand Down
132 changes: 66 additions & 66 deletions src/materials/Material.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Color } from '../math/Color.js';
import { EventDispatcher } from '../core/EventDispatcher.js';
import { FrontSide, NormalBlending, LessEqualDepth, AddEquation, OneMinusSrcAlphaFactor, SrcAlphaFactor, AlwaysStencilFunc, KeepStencilOp, BasicDepthPacking } from '../constants.js';
import { FrontSide, NormalBlending, LessEqualDepth, AddEquation, OneMinusSrcAlphaFactor, SrcAlphaFactor, AlwaysStencilFunc, KeepStencilOp } from '../constants.js';
import { generateUUID } from '../math/MathUtils.js';
import { warn } from '../utils.js';
import { Vector2 } from '../math/Vector2.js';
Expand Down Expand Up @@ -629,10 +629,61 @@ class Material extends EventDispatcher {
};

// standard Material serialization

data.uuid = this.uuid;
data.type = this.type;

if ( this.name !== '' ) data.name = this.name;
data.blending = this.blending;
data.side = this.side;
data.shadowSide = this.shadowSide;
data.vertexColors = this.vertexColors;

data.opacity = this.opacity;
data.transparent = this.transparent;

data.blendSrc = this.blendSrc;
data.blendDst = this.blendDst;
data.blendEquation = this.blendEquation;
data.blendSrcAlpha = this.blendSrcAlpha;
data.blendDstAlpha = this.blendDstAlpha;
data.blendEquationAlpha = this.blendEquationAlpha;
data.blendColor = this.blendColor.getHex();
data.blendAlpha = this.blendAlpha;

data.depthFunc = this.depthFunc;
data.depthTest = this.depthTest;
data.depthWrite = this.depthWrite;
data.colorWrite = this.colorWrite;

data.clipIntersection = this.clipIntersection;
data.clipShadows = this.clipShadows;

data.stencilWriteMask = this.stencilWriteMask;
data.stencilFunc = this.stencilFunc;
data.stencilRef = this.stencilRef;
data.stencilFuncMask = this.stencilFuncMask;
data.stencilFail = this.stencilFail;
data.stencilZFail = this.stencilZFail;
data.stencilZPass = this.stencilZPass;
data.stencilWrite = this.stencilWrite;

data.polygonOffset = this.polygonOffset;
data.polygonOffsetFactor = this.polygonOffsetFactor;
data.polygonOffsetUnits = this.polygonOffsetUnits;

data.dithering = this.dithering;

data.alphaTest = this.alphaTest;
data.alphaHash = this.alphaHash;
data.alphaToCoverage = this.alphaToCoverage;
data.premultipliedAlpha = this.premultipliedAlpha;
data.forceSinglePass = this.forceSinglePass;
data.allowOverride = this.allowOverride;

data.visible = this.visible;
data.toneMapped = this.toneMapped;

data.name = this.name;

if ( this.color && this.color.isColor ) data.color = this.color.getHex();

Expand All @@ -643,7 +694,7 @@ class Material extends EventDispatcher {
if ( this.sheenColor && this.sheenColor.isColor ) data.sheenColor = this.sheenColor.getHex();
if ( this.sheenRoughness !== undefined ) data.sheenRoughness = this.sheenRoughness;
if ( this.emissive && this.emissive.isColor ) data.emissive = this.emissive.getHex();
if ( this.emissiveIntensity !== undefined && this.emissiveIntensity !== 1 ) data.emissiveIntensity = this.emissiveIntensity;
if ( this.emissiveIntensity !== undefined ) data.emissiveIntensity = this.emissiveIntensity;

if ( this.specular && this.specular.isColor ) data.specular = this.specular.getHex();
if ( this.specularIntensity !== undefined ) data.specularIntensity = this.specularIntensity;
Expand Down Expand Up @@ -783,90 +834,39 @@ class Material extends EventDispatcher {
if ( this.transmissionMap && this.transmissionMap.isTexture ) data.transmissionMap = this.transmissionMap.toJSON( meta ).uuid;
if ( this.thickness !== undefined ) data.thickness = this.thickness;
if ( this.thicknessMap && this.thicknessMap.isTexture ) data.thicknessMap = this.thicknessMap.toJSON( meta ).uuid;
if ( this.attenuationDistance !== undefined && this.attenuationDistance !== Infinity ) data.attenuationDistance = this.attenuationDistance;
if ( this.attenuationDistance !== undefined ) data.attenuationDistance = this.attenuationDistance;
if ( this.attenuationColor !== undefined ) data.attenuationColor = this.attenuationColor.getHex();

if ( this.size !== undefined ) data.size = this.size;
if ( this.shadowSide !== null ) data.shadowSide = this.shadowSide;
if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;

if ( this.blending !== NormalBlending ) data.blending = this.blending;
if ( this.side !== FrontSide ) data.side = this.side;
if ( this.vertexColors === true ) data.vertexColors = true;

if ( this.opacity < 1 ) data.opacity = this.opacity;
if ( this.transparent === true ) data.transparent = true;

if ( this.blendSrc !== SrcAlphaFactor ) data.blendSrc = this.blendSrc;
if ( this.blendDst !== OneMinusSrcAlphaFactor ) data.blendDst = this.blendDst;
if ( this.blendEquation !== AddEquation ) data.blendEquation = this.blendEquation;
if ( this.blendSrcAlpha !== null ) data.blendSrcAlpha = this.blendSrcAlpha;
if ( this.blendDstAlpha !== null ) data.blendDstAlpha = this.blendDstAlpha;
if ( this.blendEquationAlpha !== null ) data.blendEquationAlpha = this.blendEquationAlpha;
if ( this.blendColor && this.blendColor.isColor ) data.blendColor = this.blendColor.getHex();
if ( this.blendAlpha !== 0 ) data.blendAlpha = this.blendAlpha;

if ( this.depthFunc !== LessEqualDepth ) data.depthFunc = this.depthFunc;
if ( this.depthTest === false ) data.depthTest = this.depthTest;
if ( this.depthWrite === false ) data.depthWrite = this.depthWrite;
if ( this.colorWrite === false ) data.colorWrite = this.colorWrite;

if ( Array.isArray( this.clippingPlanes ) && this.clippingPlanes.length > 0 ) {

data.clippingPlanes = this.clippingPlanes.map( plane => plane.toJSON() );

}

if ( this.clipIntersection === true ) data.clipIntersection = true;
if ( this.clipShadows === true ) data.clipShadows = true;

if ( this.stencilWriteMask !== 0xff ) data.stencilWriteMask = this.stencilWriteMask;
if ( this.stencilFunc !== AlwaysStencilFunc ) data.stencilFunc = this.stencilFunc;
if ( this.stencilRef !== 0 ) data.stencilRef = this.stencilRef;
if ( this.stencilFuncMask !== 0xff ) data.stencilFuncMask = this.stencilFuncMask;
if ( this.stencilFail !== KeepStencilOp ) data.stencilFail = this.stencilFail;
if ( this.stencilZFail !== KeepStencilOp ) data.stencilZFail = this.stencilZFail;
if ( this.stencilZPass !== KeepStencilOp ) data.stencilZPass = this.stencilZPass;
if ( this.stencilWrite === true ) data.stencilWrite = this.stencilWrite;

// rotation (SpriteMaterial)
if ( this.rotation !== undefined && this.rotation !== 0 ) data.rotation = this.rotation;
if ( this.rotation !== undefined ) data.rotation = this.rotation;

// depthPacking (MeshDepthMaterial)
if ( this.depthPacking !== undefined && this.depthPacking !== BasicDepthPacking ) data.depthPacking = this.depthPacking;

if ( this.polygonOffset === true ) data.polygonOffset = true;
if ( this.polygonOffsetFactor !== 0 ) data.polygonOffsetFactor = this.polygonOffsetFactor;
if ( this.polygonOffsetUnits !== 0 ) data.polygonOffsetUnits = this.polygonOffsetUnits;
if ( this.depthPacking !== undefined ) data.depthPacking = this.depthPacking;

if ( this.linewidth !== undefined && this.linewidth !== 1 ) data.linewidth = this.linewidth;
if ( this.linecap !== undefined && this.linecap !== 'round' ) data.linecap = this.linecap;
if ( this.linejoin !== undefined && this.linejoin !== 'round' ) data.linejoin = this.linejoin;
if ( this.linewidth !== undefined ) data.linewidth = this.linewidth;
if ( this.linecap !== undefined ) data.linecap = this.linecap;
if ( this.linejoin !== undefined ) data.linejoin = this.linejoin;
if ( this.dashSize !== undefined ) data.dashSize = this.dashSize;
if ( this.gapSize !== undefined ) data.gapSize = this.gapSize;
if ( this.scale !== undefined ) data.scale = this.scale;

if ( this.dithering === true ) data.dithering = true;

if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
if ( this.alphaHash === true ) data.alphaHash = true;
if ( this.alphaToCoverage === true ) data.alphaToCoverage = true;
if ( this.premultipliedAlpha === true ) data.premultipliedAlpha = true;
if ( this.forceSinglePass === true ) data.forceSinglePass = true;
if ( this.allowOverride === false ) data.allowOverride = false;

if ( this.wireframe === true ) data.wireframe = true;
if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;
if ( this.wireframeLinecap !== 'round' ) data.wireframeLinecap = this.wireframeLinecap;
if ( this.wireframeLinejoin !== 'round' ) data.wireframeLinejoin = this.wireframeLinejoin;

if ( this.flatShading === true ) data.flatShading = true;

if ( this.visible === false ) data.visible = false;
if ( this.wireframe !== undefined ) data.wireframe = this.wireframe;
if ( this.wireframeLinewidth !== undefined ) data.wireframeLinewidth = this.wireframeLinewidth;
if ( this.wireframeLinecap !== undefined ) data.wireframeLinecap = this.wireframeLinecap;
if ( this.wireframeLinejoin !== undefined ) data.wireframeLinejoin = this.wireframeLinejoin;

if ( this.toneMapped === false ) data.toneMapped = false;
if ( this.flatShading !== undefined ) data.flatShading = this.flatShading;

if ( this.fog === false ) data.fog = false;
if ( this.fog !== undefined ) data.fog = this.fog;

if ( Object.keys( this.userData ).length > 0 ) data.userData = this.userData;

Expand Down
Loading