Skip to content

Commit

Permalink
WebGPURenderer: NodeMaterial extends Material (#962)
Browse files Browse the repository at this point in the history
* WebGPURenderer: NodeMaterial extends Material

* Format

* Update three.js and add examples

* Update patch

* Delete examples
  • Loading branch information
Methuselah96 authored May 18, 2024
1 parent 674a1b5 commit c6fcdfa
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 14 deletions.
17 changes: 11 additions & 6 deletions examples-testing/changes.patch
Original file line number Diff line number Diff line change
Expand Up @@ -3977,7 +3977,7 @@ index dd2f61f9..6dab1b6e 100644
mouseY = (event.clientY - windowHalfY) * 10;
}
diff --git a/examples-testing/examples/webgl_framebuffer_texture.ts b/examples-testing/examples/webgl_framebuffer_texture.ts
index 521261a0..5844c437 100644
index df4acc9d..636f9db9 100644
--- a/examples-testing/examples/webgl_framebuffer_texture.ts
+++ b/examples-testing/examples/webgl_framebuffer_texture.ts
@@ -3,10 +3,10 @@ import * as THREE from 'three';
Expand Down Expand Up @@ -14059,7 +14059,7 @@ index 3a13ab5a..2850b1be 100644
}
});
diff --git a/examples-testing/examples/webgpu_multiple_rendertargets_readback.ts b/examples-testing/examples/webgpu_multiple_rendertargets_readback.ts
index 19e195de..e321b7a1 100644
index 19e195de..6a7d4ceb 100644
--- a/examples-testing/examples/webgpu_multiple_rendertargets_readback.ts
+++ b/examples-testing/examples/webgpu_multiple_rendertargets_readback.ts
@@ -26,8 +26,14 @@ import WebGPURenderer from 'three/addons/renderers/webgpu/WebGPURenderer.js';
Expand All @@ -14079,11 +14079,13 @@ index 19e195de..e321b7a1 100644

const gui = new GUI();

@@ -38,7 +44,11 @@ const options = {
@@ -38,7 +44,13 @@ const options = {
gui.add(options, 'selection', ['mrt', 'diffuse', 'normal']);

class WriteGBufferMaterial extends NodeMaterial {
- constructor(diffuseTexture) {
+ lights: boolean;
+ fog: boolean;
+ colorSpaced: boolean;
+
+ diffuseTexture: THREE.Texture;
Expand All @@ -14092,16 +14094,19 @@ index 19e195de..e321b7a1 100644
super();

this.lights = false;
@@ -62,7 +72,7 @@ class WriteGBufferMaterial extends NodeMaterial {
@@ -62,7 +74,10 @@ class WriteGBufferMaterial extends NodeMaterial {
}

class ReadGBufferMaterial extends NodeMaterial {
- constructor(tDiffuse, tNormal) {
+ lights: boolean;
+ fog: boolean;
+
+ constructor(tDiffuse: THREE.Texture, tNormal: THREE.Texture) {
super();

this.lights = false;
@@ -159,7 +169,7 @@ function onWindowResize() {
@@ -159,7 +174,7 @@ function onWindowResize() {
renderTarget.setSize(window.innerWidth * dpr, window.innerHeight * dpr);
}

Expand All @@ -14110,7 +14115,7 @@ index 19e195de..e321b7a1 100644
const selection = options.selection;

torus.rotation.y = (time / 1000) * 0.4;
@@ -189,12 +199,26 @@ async function readback() {
@@ -189,12 +204,26 @@ async function readback() {
const selection = options.selection;

if (selection === 'diffuse') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export default class LineBasicNodeMaterial extends NodeMaterial {
// Properties from LineBasicMaterial
readonly isLineBasicMaterial: true;
color: Color;
fog: boolean;
linewidth: number;
linecap: string;
linejoin: string;
map: Texture | null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Color, Combine, MeshBasicMaterialParameters, Texture } from "three";
import { Color, Combine, Euler, MeshBasicMaterialParameters, Texture } from "three";
import NodeMaterial, { NodeMaterialParameters } from "./NodeMaterial.js";

export interface MeshBasicNodeMaterialParameters extends NodeMaterialParameters, MeshBasicMaterialParameters {
Expand All @@ -18,11 +18,15 @@ export default class MeshBasicNodeMaterial extends NodeMaterial {
specularMap: Texture | null;
alphaMap: Texture | null;
envMap: Texture | null;
envMapRotation: Euler;
combine: Combine;
reflectivity: number;
refractionRatio: number;
wireframe: boolean;
wireframeLinewidth: number;
wireframeLinecap: string;
wireframeLinejoin: string;
fog: boolean;

constructor(parameters?: MeshBasicNodeMaterialParameters);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default class MeshMatcapNodeMaterial extends NodeMaterial {
displacementBias: number;
alphaMap: Texture | null;
flatShading: boolean;
fog: boolean;

constructor(paramters: MeshMatcapNodeMaterialParameters);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export default class MeshNormalNodeMaterial extends NodeMaterial {
displacementMap: Texture | null;
displacementScale: number;
displacementBias: number;
wireframe: boolean;
wireframeLinewidth: number;
flatShading: boolean;

constructor(parameters?: MeshBasicNodeMaterialParameters);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Color, Combine, MeshPhongMaterialParameters, NormalMapTypes, Texture, Vector2 } from "three";
import { Color, Combine, Euler, MeshPhongMaterialParameters, NormalMapTypes, Texture, Vector2 } from "three";
import Node from "../core/Node.js";
import { ShaderNodeObject } from "../shadernode/ShaderNode.js";
import NodeMaterial, { NodeMaterialParameters } from "./NodeMaterial.js";
Expand Down Expand Up @@ -36,13 +36,17 @@ export default class MeshPhongNodeMaterial extends NodeMaterial {
specularMap: Texture | null;
alphaMap: Texture | null;
envMap: Texture | null;
envMapRotation: Euler;
combine: Combine;
reflectivity: number;
refractionRatio: number;
wireframe: boolean;
wireframeLinewidth: number;
wireframeLinecap: string;
wireframeLinejoin: string;
flatShading: boolean;
metal: boolean;
fog: boolean;

constructor(parameters?: MeshPhongNodeMaterialParameters);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Color, MeshStandardMaterialParameters, NormalMapTypes, Texture, Vector2 } from "three";
import { Color, Euler, MeshStandardMaterialParameters, NormalMapTypes, Texture, Vector2 } from "three";
import Node from "../core/Node.js";
import { ShaderNodeObject } from "../shadernode/ShaderNode.js";
import NodeMaterial, { NodeMaterialParameters } from "./NodeMaterial.js";
Expand Down Expand Up @@ -39,10 +39,14 @@ export default class MeshStandardNodeMaterial extends NodeMaterial {
metalnessMap: Texture | null;
alphaMap: Texture | null;
envMap: Texture | null;
envMapRotation: Euler;
envMapIntensity: number;
wireframe: boolean;
wireframeLinewidth: number;
wireframeLinecap: string;
wireframeLinejoin: string;
flatShading: boolean;
fog: boolean;

constructor(paramters?: MeshStandardNodeMaterialParameters);
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ export default class MeshToonNodeMaterial extends NodeMaterial {
displacementScale: number;
displacementBias: number;
alphaMap: Texture | null;
wireframe: boolean;
wireframeLinewidth: number;
wireframeLinecap: string;
wireframeLinejoin: string;
fog: boolean;

constructor(paramters: MeshToonNodeMaterialParameters);
}
7 changes: 3 additions & 4 deletions types/three/examples/jsm/nodes/materials/NodeMaterial.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
LineBasicMaterial,
Material,
MaterialParameters,
MeshBasicMaterial,
MeshMatcapMaterial,
MeshNormalMaterial,
Expand All @@ -9,8 +10,6 @@ import {
MeshStandardMaterial,
MeshToonMaterial,
PointsMaterial,
ShaderMaterial,
ShaderMaterialParameters,
ShadowMaterial,
SpriteMaterial,
} from "three";
Expand All @@ -32,7 +31,7 @@ import PointsNodeMaterial from "./PointsNodeMaterial.js";
import ShadowNodeMaterial from "./ShadowNodeMaterial.js";
import SpriteNodeMaterial from "./SpriteNodeMaterial.js";

export interface NodeMaterialParameters extends ShaderMaterialParameters {
export interface NodeMaterialParameters extends MaterialParameters {
normals?: boolean | undefined;

colorSpaced?: boolean | undefined;
Expand All @@ -59,7 +58,7 @@ export interface NodeMaterialParameters extends ShaderMaterialParameters {
vertexNode?: ShaderNodeObject<Node> | null | undefined;
}

export default class NodeMaterial extends ShaderMaterial {
export default class NodeMaterial extends Material {
readonly isNodeMaterial: true;

normals: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default class PointsNodeMaterial extends NodeMaterial {
alphaMap: Texture | null;
size: number;
sizeAttenuation: boolean;
fog: boolean;

constructor(parameters?: PointsNodeMaterialParameters);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default class ShadowNodeMaterial extends NodeMaterial {
// Properties from ShadowMaterial
readonly isShadowMaterial: true;
color: Color;
fog: boolean;

constructor(parameters?: ShadowNodeMaterialParameters);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default class SpriteNodeMaterial extends NodeMaterial {
alphaMap: Texture | null;
rotation: number;
sizeAttenuation: boolean;
fog: boolean;

constructor(parameters?: SpriteNodeMaterialParameters);
}

0 comments on commit c6fcdfa

Please sign in to comment.