Skip to content

WebGPURenderer: Tree shaking Materials - WIP #28328

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

Draft
wants to merge 2 commits into
base: dev
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createNodeFromType } from '../core/Node.js';
import { nodeObject } from '../shadernode/ShaderNode.js';
import { createNodeFromType } from '../nodes/core/Node.js';
import { nodeObject } from '../nodes/shadernode/ShaderNode.js';
import { FileLoader, Loader } from 'three';

class NodeLoader extends Loader {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @TODO: We can simplify "export { default as SomeNode, other, exports } from '...'" to just "export * from '...'" if we will use only named exports

export { default as NodeMaterial, addNodeMaterial, createNodeMaterialFromType } from './NodeMaterial.js';
/*
export { default as InstancedPointsNodeMaterial } from './InstancedPointsNodeMaterial.js';
export { default as LineBasicNodeMaterial } from './LineBasicNodeMaterial.js';
export { default as LineDashedNodeMaterial } from './LineDashedNodeMaterial.js';
Expand All @@ -17,3 +18,4 @@ export { default as MeshMatcapNodeMaterial } from './MeshMatcapNodeMaterial.js';
export { default as PointsNodeMaterial } from './PointsNodeMaterial.js';
export { default as SpriteNodeMaterial } from './SpriteNodeMaterial.js';
export { default as ShadowNodeMaterial } from './ShadowNodeMaterial.js';
*/
82 changes: 82 additions & 0 deletions examples/jsm/materials/MeshBasicMaterial.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import NodeMaterial from './NodeMaterial.js';
import { MultiplyOperation } from '../../../src/constants.js';
import { Color } from '../../../src/math/Color.js';
import { Euler } from '../../../src/math/Euler.js';

class MeshBasicMaterial extends NodeMaterial {

constructor( parameters ) {

super();

this.isMeshBasicMaterial = true;

this.color = new Color( 0xffffff ); // emissive

this.map = null;

this.lightMap = null;
this.lightMapIntensity = 1.0;

this.aoMap = null;
this.aoMapIntensity = 1.0;

this.specularMap = null;

this.alphaMap = null;

this.envMap = null;
this.envMapRotation = new Euler();
this.combine = MultiplyOperation;
this.reflectivity = 1;
this.refractionRatio = 0.98;

this.wireframe = false;
this.wireframeLinewidth = 1;
this.wireframeLinecap = 'round';
this.wireframeLinejoin = 'round';

this.fog = true;

this.setValues( parameters );

}

copy( source ) {

super.copy( source );

this.color.copy( source.color );

this.map = source.map;

this.lightMap = source.lightMap;
this.lightMapIntensity = source.lightMapIntensity;

this.aoMap = source.aoMap;
this.aoMapIntensity = source.aoMapIntensity;

this.specularMap = source.specularMap;

this.alphaMap = source.alphaMap;

this.envMap = source.envMap;
this.envMapRotation.copy( source.envMapRotation );
this.combine = source.combine;
this.reflectivity = source.reflectivity;
this.refractionRatio = source.refractionRatio;

this.wireframe = source.wireframe;
this.wireframeLinewidth = source.wireframeLinewidth;
this.wireframeLinecap = source.wireframeLinecap;
this.wireframeLinejoin = source.wireframeLinejoin;

this.fog = source.fog;

return this;

}

}

export default MeshBasicMaterial;
143 changes: 143 additions & 0 deletions examples/jsm/materials/MeshPhongMaterial.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import NodeMaterial from './NodeMaterial.js';
import { MultiplyOperation, TangentSpaceNormalMap } from '../../../src/constants.js';
import { Vector2 } from '../../../src/math/Vector2.js';
import { Color } from '../../../src/math/Color.js';
import { Euler } from '../../../src/math/Euler.js';

import {
shininess, specularColor,
materialShininess, materialSpecular
} from '../nodes/Nodes.js';

import PhongLightingModel from '../nodes/functions/PhongLightingModel.js';

class MeshPhongMaterial extends NodeMaterial {

constructor( parameters ) {

super();

this.isMeshPhongMaterial = true;

this.color = new Color( 0xffffff ); // diffuse
this.specular = new Color( 0x111111 );
this.shininess = 30;

this.map = null;

this.lightMap = null;
this.lightMapIntensity = 1.0;

this.aoMap = null;
this.aoMapIntensity = 1.0;

this.emissive = new Color( 0x000000 );
this.emissiveIntensity = 1.0;
this.emissiveMap = null;

this.bumpMap = null;
this.bumpScale = 1;

this.normalMap = null;
this.normalMapType = TangentSpaceNormalMap;
this.normalScale = new Vector2( 1, 1 );

this.displacementMap = null;
this.displacementScale = 1;
this.displacementBias = 0;

this.specularMap = null;

this.alphaMap = null;

this.envMap = null;
this.envMapRotation = new Euler();
this.combine = MultiplyOperation;
this.reflectivity = 1;
this.refractionRatio = 0.98;

this.wireframe = false;
this.wireframeLinewidth = 1;
this.wireframeLinecap = 'round';
this.wireframeLinejoin = 'round';

this.flatShading = false;

this.fog = true;

this.lights = true;

this.setValues( parameters );

}

setupLightingModel( /*builder*/ ) {

return new PhongLightingModel();

}

setupVariants() {

shininess.assign( materialShininess.max( 1e-4 ) ); // to prevent pow( 0.0, 0.0 ) );
specularColor.assign( materialSpecular );

}

copy( source ) {

super.copy( source );

this.color.copy( source.color );
this.specular.copy( source.specular );
this.shininess = source.shininess;

this.map = source.map;

this.lightMap = source.lightMap;
this.lightMapIntensity = source.lightMapIntensity;

this.aoMap = source.aoMap;
this.aoMapIntensity = source.aoMapIntensity;

this.emissive.copy( source.emissive );
this.emissiveMap = source.emissiveMap;
this.emissiveIntensity = source.emissiveIntensity;

this.bumpMap = source.bumpMap;
this.bumpScale = source.bumpScale;

this.normalMap = source.normalMap;
this.normalMapType = source.normalMapType;
this.normalScale.copy( source.normalScale );

this.displacementMap = source.displacementMap;
this.displacementScale = source.displacementScale;
this.displacementBias = source.displacementBias;

this.specularMap = source.specularMap;

this.alphaMap = source.alphaMap;

this.envMap = source.envMap;
this.envMapRotation.copy( source.envMapRotation );
this.combine = source.combine;
this.reflectivity = source.reflectivity;
this.refractionRatio = source.refractionRatio;

this.wireframe = source.wireframe;
this.wireframeLinewidth = source.wireframeLinewidth;
this.wireframeLinecap = source.wireframeLinecap;
this.wireframeLinejoin = source.wireframeLinejoin;

this.flatShading = source.flatShading;

this.fog = source.fog;

return this;

}

}

export default MeshPhongMaterial;
Loading