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
19 changes: 17 additions & 2 deletions src/materials/nodes/LineBasicNodeMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import { LineBasicMaterial } from '../LineBasicMaterial.js';

const _defaultValues = /*@__PURE__*/ new LineBasicMaterial();

/**
* Node material version of `LineBasicMaterial`.
*
* @augments NodeMaterial
*/
class LineBasicNodeMaterial extends NodeMaterial {

static get type() {
Expand All @@ -12,14 +17,24 @@ class LineBasicNodeMaterial extends NodeMaterial {

}

/**
* Constructs a new line basic node material.
*
* @param {Object?} parameters - The configuration parameter.
*/
constructor( parameters ) {

super();

/**
* This flag can be used for type testing.
*
* @type {Boolean}
* @readonly
* @default true
*/
this.isLineBasicNodeMaterial = true;

this.lights = false;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have removed these statements since the default of lights is already false.


this.setDefaultValues( _defaultValues );

this.setValues( parameters );
Expand Down
81 changes: 77 additions & 4 deletions src/materials/nodes/LineDashedNodeMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import { LineDashedMaterial } from '../LineDashedMaterial.js';

const _defaultValues = /*@__PURE__*/ new LineDashedMaterial();

/**
* Node material version of `LineDashedMaterial`.
*
* @augments NodeMaterial
*/
class LineDashedNodeMaterial extends NodeMaterial {

static get type() {
Expand All @@ -16,33 +21,101 @@ class LineDashedNodeMaterial extends NodeMaterial {

}

/**
* Constructs a new line dashed node material.
*
* @param {Object?} parameters - The configuration parameter.
*/
constructor( parameters ) {

super();

/**
* This flag can be used for type testing.
*
* @type {Boolean}
* @readonly
* @default true
*/
this.isLineDashedNodeMaterial = true;

this.lights = false;

this.setDefaultValues( _defaultValues );

/**
* The dash offset.
*
* @type {Number}
* @default 0
*/
this.dashOffset = 0;

/**
* The offset of dash materials is by default inferred from the `dashOffset`
* property. This node property allows to overwrite the default
* and define the offset with a node instead.
*
* If you don't want to overwrite the offset but modify the existing
* value instead, use {@link module:MaterialNode.materialLineDashOffset}.
*
* @type {Node<float>?}
* @default null
*/
this.offsetNode = null;

/**
* The scale of dash materials is by default inferred from the `scale`
* property. This node property allows to overwrite the default
* and define the scale with a node instead.
*
* If you don't want to overwrite the scale but modify the existing
* value instead, use {@link module:MaterialNode.materialLineScale}.
*
* @type {Node<float>?}
* @default null
*/
this.dashScaleNode = null;

/**
* The dash size of dash materials is by default inferred from the `dashSize`
* property. This node property allows to overwrite the default
* and define the dash size with a node instead.
*
* If you don't want to overwrite the dash size but modify the existing
* value instead, use {@link module:MaterialNode.materialLineDashSize}.
*
* @type {Node<float>?}
* @default null
*/
this.dashSizeNode = null;

/**
* The gap size of dash materials is by default inferred from the `gapSize`
* property. This node property allows to overwrite the default
* and define the gap size with a node instead.
*
* If you don't want to overwrite the gap size but modify the existing
* value instead, use {@link module:MaterialNode.materialLineGapSize}.
*
* @type {Node<float>?}
* @default null
*/
this.gapSizeNode = null;

this.setValues( parameters );

}

setupVariants() {
/**
* Setups the dash specific node variables.
*
* @param {NodeBuilder} builder - The current node builder.
*/
setupVariants( /* builder */ ) {

const offsetNode = this.offsetNode ? float( this.offsetNodeNode ) : materialLineDashOffset;
const dashScaleNode = this.dashScaleNode ? float( this.dashScaleNode ) : materialLineScale;
const dashSizeNode = this.dashSizeNode ? float( this.dashSizeNode ) : materialLineDashSize;
const gapSizeNode = this.dashSizeNode ? float( this.dashGapNode ) : materialLineGapSize;
const gapSizeNode = this.gapSizeNode ? float( this.gapSizeNode ) : materialLineGapSize;

dashSize.assign( dashSizeNode );
gapSize.assign( gapSizeNode );
Expand Down
56 changes: 56 additions & 0 deletions src/materials/nodes/MeshBasicNodeMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import { MeshBasicMaterial } from '../MeshBasicMaterial.js';

const _defaultValues = /*@__PURE__*/ new MeshBasicMaterial();

/**
* Node material version of `MeshBasicMaterial`.
*
* @augments NodeMaterial
*/
class MeshBasicNodeMaterial extends NodeMaterial {

static get type() {
Expand All @@ -18,12 +23,32 @@ class MeshBasicNodeMaterial extends NodeMaterial {

}

/**
* Constructs a new mesh basic node material.
*
* @param {Object?} parameters - The configuration parameter.
*/
constructor( parameters ) {

super();

/**
* This flag can be used for type testing.
*
* @type {Boolean}
* @readonly
* @default true
*/
this.isMeshBasicNodeMaterial = true;

/**
* Although the basic material is by definition unlit, we set
* this property to `true` since we use a lighting model to compute
* the outgoing light of the fragment shader.
*
* @type {Boolean}
* @default true
*/
this.lights = true;

this.setDefaultValues( _defaultValues );
Expand All @@ -32,12 +57,25 @@ class MeshBasicNodeMaterial extends NodeMaterial {

}

/**
* Basic materials are not affected by normal and bump maps so we
* return by default {@link module:Normal.normalView}.
*
* @return {Node<vec3>} The normal node.
*/
setupNormal() {

return normalView; // see #28839

}

/**
* Overwritten since this type of material uses {@link BasicEnvironmentNode}
* to implement the default environment mapping.
*
* @param {NodeBuilder} builder - The current node builder.
* @return {BasicEnvironmentNode<vec3>?} The environment node.
*/
setupEnvironment( builder ) {

const envNode = super.setupEnvironment( builder );
Expand All @@ -46,6 +84,13 @@ class MeshBasicNodeMaterial extends NodeMaterial {

}

/**
* This method must be overwriten since light maps are evaluated
* with a special scaling factor for basic materials.
*
* @param {NodeBuilder} builder - The current node builder.
* @return {BasicLightMapNode<vec3>?} The light map node.
*/
setupLightMap( builder ) {

let node = null;
Expand All @@ -60,12 +105,23 @@ class MeshBasicNodeMaterial extends NodeMaterial {

}

/**
* The material overwrites this method because `lights` is set to `true` but
* we still want to return the diffuse color as the outgoing light.
*
* @return {Node<vec3>} The outgoing light node.
*/
setupOutgoingLight() {

return diffuseColor.rgb;

}

/**
* Setups the lighting model.
*
* @return {BasicLightingModel} The lighting model.
*/
setupLightingModel() {

return new BasicLightingModel();
Expand Down
35 changes: 35 additions & 0 deletions src/materials/nodes/MeshLambertNodeMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import { MeshLambertMaterial } from '../MeshLambertMaterial.js';

const _defaultValues = /*@__PURE__*/ new MeshLambertMaterial();

/**
* Node material version of `MeshLambertMaterial`.
*
* @augments NodeMaterial
*/
class MeshLambertNodeMaterial extends NodeMaterial {

static get type() {
Expand All @@ -14,12 +19,30 @@ class MeshLambertNodeMaterial extends NodeMaterial {

}

/**
* Constructs a new mesh lambert node material.
*
* @param {Object?} parameters - The configuration parameter.
*/
constructor( parameters ) {

super();

/**
* This flag can be used for type testing.
*
* @type {Boolean}
* @readonly
* @default true
*/
this.isMeshLambertNodeMaterial = true;

/**
* Set to `true` because lambert materials react on lights.
*
* @type {Boolean}
* @default true
*/
this.lights = true;

this.setDefaultValues( _defaultValues );
Expand All @@ -28,6 +51,13 @@ class MeshLambertNodeMaterial extends NodeMaterial {

}

/**
* Overwritten since this type of material uses {@link BasicEnvironmentNode}
* to implement the default environment mapping.
*
* @param {NodeBuilder} builder - The current node builder.
* @return {BasicEnvironmentNode<vec3>?} The environment node.
*/
setupEnvironment( builder ) {

const envNode = super.setupEnvironment( builder );
Expand All @@ -36,6 +66,11 @@ class MeshLambertNodeMaterial extends NodeMaterial {

}

/**
* Setups the lighting model.
*
* @return {PhongLightingModel} The lighting model.
*/
setupLightingModel( /*builder*/ ) {

return new PhongLightingModel( false ); // ( specular ) -> force lambert
Expand Down
24 changes: 22 additions & 2 deletions src/materials/nodes/MeshMatcapNodeMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import { MeshMatcapMaterial } from '../MeshMatcapMaterial.js';

const _defaultValues = /*@__PURE__*/ new MeshMatcapMaterial();

/**
* Node material version of `MeshMatcapMaterial`.
*
* @augments NodeMaterial
*/
class MeshMatcapNodeMaterial extends NodeMaterial {

static get type() {
Expand All @@ -17,12 +22,22 @@ class MeshMatcapNodeMaterial extends NodeMaterial {

}

/**
* Constructs a new mesh normal node material.
*
* @param {Object?} parameters - The configuration parameter.
*/
constructor( parameters ) {

super();

this.lights = false;

/**
* This flag can be used for type testing.
*
* @type {Boolean}
* @readonly
* @default true
*/
this.isMeshMatcapNodeMaterial = true;

this.setDefaultValues( _defaultValues );
Expand All @@ -31,6 +46,11 @@ class MeshMatcapNodeMaterial extends NodeMaterial {

}

/**
* Setups the matcap specific node variables.
*
* @param {NodeBuilder} builder - The current node builder.
*/
setupVariants( builder ) {

const uv = matcapUV;
Expand Down
Loading
Loading