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

WebGPURenderer: New AfterImageNode for the PostProcessing renderer. #746

Merged
merged 6 commits into from
Jan 16, 2024
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
50 changes: 45 additions & 5 deletions examples-testing/changes.patch
Original file line number Diff line number Diff line change
Expand Up @@ -13303,7 +13303,7 @@ index fa96129..58f8d4a 100644
// and does so without distortion. Akin to CSS object-fit: contain.
// Source: https://github.com/mrdoob/three.js/pull/17199
diff --git a/examples-testing/examples/webgl_tonemapping.ts b/examples-testing/examples/webgl_tonemapping.ts
index 9f7ce3f..60893f1 100644
index df42a7b..a55fe3d 100644
--- a/examples-testing/examples/webgl_tonemapping.ts
+++ b/examples-testing/examples/webgl_tonemapping.ts
@@ -1,22 +1,35 @@
Expand All @@ -13318,6 +13318,9 @@ index 9f7ce3f..60893f1 100644
-let mesh, renderer, scene, camera, controls;
-let gui,
- guiExposure = null;
+type ToneMapping = 'None' | 'Linear' | 'Reinhard' | 'Cineon' | 'ACESFilmic' | 'AgX' | 'Custom';

-const params = {
+interface Params {
+ exposure: number;
+ toneMapping: ToneMapping;
Expand All @@ -13333,12 +13336,9 @@ index 9f7ce3f..60893f1 100644
+let gui: GUI,
+ guiExposure: NumberController<Params, 'exposure'> | null = null;
+
+type ToneMapping = 'None' | 'Linear' | 'Reinhard' | 'Cineon' | 'ACESFilmic' | 'AgX' | 'Custom';

-const params = {
+const params: Params = {
exposure: 1.0,
toneMapping: 'ACESFilmic',
toneMapping: 'AgX',
blurriness: 0.3,
intensity: 1.0,
};
Expand Down Expand Up @@ -13993,6 +13993,46 @@ index 5cc6547..87058f0 100644
gui.add(influences, value, 0, 1, 0.01).name(key.replace('blendShape1.', '')).listen();
}
});
diff --git a/examples-testing/examples/webgpu_postprocessing_afterimage.ts b/examples-testing/examples/webgpu_postprocessing_afterimage.ts
index 4310fdb..0ac9b10 100644
--- a/examples-testing/examples/webgpu_postprocessing_afterimage.ts
+++ b/examples-testing/examples/webgpu_postprocessing_afterimage.ts
@@ -3,12 +3,13 @@ import * as THREE from 'three';
import { GUI } from 'three/addons/libs/lil-gui.module.min.js';

import WebGPU from 'three/addons/capabilities/WebGPU.js';
+import type WebGPUBackend from 'three/addons/renderers/webgpu/WebGPUBackend.js';
import WebGPURenderer from 'three/addons/renderers/webgpu/WebGPURenderer.js';
import PostProcessing from 'three/addons/renderers/common/PostProcessing.js';
-import { pass } from 'three/nodes';
+import { AfterImageNode, pass, ShaderNodeObject } from 'three/nodes';

-let camera, scene, renderer;
-let mesh, postProcessing, combinedPass;
+let camera: THREE.PerspectiveCamera, scene: THREE.Scene, renderer: WebGPURenderer;
+let mesh: THREE.Mesh, postProcessing: PostProcessing, combinedPass: ShaderNodeObject<AfterImageNode>;

const params = {
damp: 0.96,
@@ -48,8 +49,7 @@ function init() {
const scenePass = pass(scene, camera);
const scenePassColor = scenePass.getTextureNode();

- combinedPass = scenePassColor;
- combinedPass = combinedPass.afterImage(params.damp);
+ combinedPass = scenePassColor.afterImage(params.damp);

postProcessing.outputNode = combinedPass;

@@ -72,7 +72,7 @@ function render() {
mesh.rotation.x += 0.0075;
mesh.rotation.y += 0.015;

- if (renderer.backend.isWebGPUBackend) {
+ if ((renderer.backend as WebGPUBackend).isWebGPUBackend) {
postProcessing.render();
} else {
renderer.render(scene, camera);
diff --git a/examples-testing/examples/webgpu_shadowmap.ts b/examples-testing/examples/webgpu_shadowmap.ts
index 4184cb4..f6d36c0 100644
--- a/examples-testing/examples/webgpu_shadowmap.ts
Expand Down
1 change: 1 addition & 0 deletions examples-testing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ const files = {
// 'webgpu_tsl_editor',
// 'webgpu_tsl_transpiler',
'webgpu_video_panorama',
'webgpu_postprocessing_afterimage',
],
webaudio: ['webaudio_orientation', 'webaudio_sandbox', 'webaudio_timing', 'webaudio_visualizer'],
webxr: [
Expand Down
2 changes: 1 addition & 1 deletion three.js
Submodule three.js updated 53 files
+5 −5 .github/workflows/ci.yml
+3 −3 .github/workflows/codeql-code-scanning.yml
+1 −1 .github/workflows/read-size.yml
+1 −1 .github/workflows/report-size.yml
+1 −1 build/three.cjs
+1 −1 build/three.js
+1 −1 build/three.min.js
+1 −1 build/three.module.js
+1 −1 build/three.module.min.js
+2 −1 docs/api/ar/constants/Renderer.html
+4 −3 docs/api/en/materials/Material.html
+2 −1 docs/api/fr/constants/Renderer.html
+2 −1 docs/api/it/constants/Renderer.html
+2 −0 docs/api/ko/constants/Renderer.html
+2 −1 docs/api/pt-br/constants/Renderer.html
+2 −0 docs/api/zh/constants/Renderer.html
+1 −1 docs/api/zh/lights/RectAreaLight.html
+4 −4 docs/api/zh/renderers/WebGLRenderer.html
+84 −0 docs/examples/en/loaders/LUT3dlLoader.html
+83 −0 docs/examples/en/loaders/LUTCubeLoader.html
+14 −29 docs/examples/en/misc/Timer.html
+2 −0 docs/list.json
+2 −1 editor/js/Sidebar.Project.Renderer.js
+2 −1 examples/files.json
+56 −34 examples/jsm/controls/OrbitControls.js
+78 −46 examples/jsm/loaders/LUT3dlLoader.js
+81 −67 examples/jsm/loaders/LUTCubeLoader.js
+27 −3 examples/jsm/loaders/MaterialXLoader.js
+2 −1 examples/jsm/loaders/SVGLoader.js
+27 −52 examples/jsm/misc/Timer.js
+2 −0 examples/jsm/nodes/Nodes.js
+131 −0 examples/jsm/nodes/display/AfterImageNode.js
+5 −5 examples/jsm/nodes/display/GaussianBlurNode.js
+1 −1 examples/jsm/nodes/shadernode/ShaderNode.js
+1 −1 examples/jsm/postprocessing/GTAOPass.js
+8 −1 examples/jsm/renderers/common/Renderer.js
+1 −1 examples/jsm/renderers/webgl/WebGLBackend.js
+2 −0 examples/jsm/renderers/webgl/utils/WebGLTextureUtils.js
+4 −1 examples/jsm/renderers/webgpu/WebGPUBackend.js
+ examples/screenshots/webgl_tonemapping.jpg
+ examples/screenshots/webgpu_backdrop_water.jpg
+ examples/screenshots/webgpu_compute_particles.jpg
+ examples/screenshots/webgpu_compute_particles_snow.jpg
+ examples/screenshots/webgpu_postprocessing_afterimage.jpg
+1 −1 examples/webgl_tonemapping.html
+9 −10 examples/webgpu_backdrop_water.html
+14 −12 examples/webgpu_compute_particles.html
+7 −7 examples/webgpu_compute_particles_snow.html
+128 −0 examples/webgpu_postprocessing_afterimage.html
+1 −1 package.json
+1 −1 src/constants.js
+1 −1 src/renderers/webgl/WebGLPrograms.js
+1 −0 test/e2e/puppeteer.js
3 changes: 3 additions & 0 deletions types/three/examples/jsm/nodes/Nodes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,9 @@ export {
depthPixel,
ViewportDepthNodeScope,
} from './display/ViewportDepthNode.js';
export { default as AfterImageNode, afterImage } from './display/AfterImageNode.js';

export { default as PassNode, pass, depthPass, PassNodeScope } from './display/PassNode.js';

// code
export { default as ExpressionNode, expression } from './code/ExpressionNode.js';
Expand Down
23 changes: 23 additions & 0 deletions types/three/examples/jsm/nodes/display/AfterImageNode.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Node from '../core/Node.js';
import TempNode from '../core/TempNode.js';
import TextureNode from '../accessors/TextureNode.js';
import UniformNode from '../core/UniformNode.js';
import { ShaderNodeObject } from '../shadernode/ShaderNode.js';

export default class AfterImageNode extends TempNode {
textureNode: TextureNode;
textureNodeOld: Node;
damp: UniformNode<number>;

constructor(textureNode: Node, damp?: number);

setSize(width: number, height: number): void;
}

export const afterImage: (node: Node, damp?: number) => ShaderNodeObject<AfterImageNode>;

declare module '../shadernode/ShaderNode.js' {
interface NodeElements {
afterImage: typeof afterImage;
}
}
42 changes: 42 additions & 0 deletions types/three/examples/jsm/nodes/display/PassNode.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Camera, RenderTarget, Scene, Texture } from '../../../../src/Three.js';
import { ShaderNodeObject } from '../shadernode/ShaderNode.js';
import TempNode from '../core/TempNode.js';
import TextureNode from '../accessors/TextureNode.js';

declare class PassTextureNode extends TextureNode {
passNode: PassNode;

constructor(passNode: PassNode, texture: Texture);
}

export default class PassNode extends TempNode {
scope: PassNodeScope;
scene: Scene;
camera: Camera;

renderTarget: RenderTarget;

readonly isPassNode: true;

constructor(scope: PassNodeScope, scene: Scene, camera: Camera);

getTextureNode(): ShaderNodeObject<PassTextureNode>;

getTextureDepthNode(): ShaderNodeObject<PassTextureNode>;

getDepthNode(): Node;

setSize(width: number, height: number): void;

setPixelRatio(pixelRatio: number): void;

dispose(): void;

static COLOR: 'color';
static DEPTH: 'depth';
}

export type PassNodeScope = typeof PassNode.COLOR | typeof PassNode.DEPTH;

export const pass: (scene: Scene, camera: Camera) => ShaderNodeObject<PassNode>;
export const depthPass: (scene: Scene, camera: Camera) => ShaderNodeObject<PassNode>;
11 changes: 11 additions & 0 deletions types/three/examples/jsm/renderers/common/PostProcessing.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Renderer from './Renderer.js';
import { Node } from '../../nodes/Nodes.js';

export default class PostProcessing {
renderer: Renderer;
outputNode: Node;

constructor(renderer: Renderer, outputNode?: Node);

render(): void;
}
2 changes: 2 additions & 0 deletions types/three/examples/jsm/renderers/webgpu/WebGPUBackend.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export interface WebGPUBackendParameters extends BackendParameters {
}

export default class WebGPUBackend extends Backend {
readonly isWebGPUBackend: true;

constructor(parameters?: WebGPUBackendParameters);

get coordinateSystem(): CoordinateSystem;
Expand Down