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

ProgressiveLightMap: Add WebGPU version. #1361

Merged
merged 4 commits into from
Nov 11, 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
56 changes: 56 additions & 0 deletions examples-testing/changes.patch
Original file line number Diff line number Diff line change
Expand Up @@ -15598,6 +15598,62 @@ index 4ce8b0a7..d41bc6f4 100644

init();

diff --git a/examples-testing/examples/webgpu_shadowmap_progressive.ts b/examples-testing/examples/webgpu_shadowmap_progressive.ts
index 5290c670..3bf0ecf6 100644
--- a/examples-testing/examples/webgpu_shadowmap_progressive.ts
+++ b/examples-testing/examples/webgpu_shadowmap_progressive.ts
@@ -1,4 +1,4 @@
-import * as THREE from 'three';
+import * as THREE from 'three/webgpu';
import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
@@ -9,17 +9,17 @@ import { ProgressiveLightMap } from 'three/addons/misc/ProgressiveLightMapGPU.js
const shadowMapRes = 1024,
lightMapRes = 1024,
lightCount = 4;
-let camera,
- scene,
- renderer,
- controls,
- control,
+let camera: THREE.PerspectiveCamera,
+ scene: THREE.Scene,
+ renderer: THREE.WebGPURenderer,
+ controls: OrbitControls,
+ control: TransformControls,
control2,
- object = new THREE.Mesh(),
- lightOrigin = null,
- progressiveSurfacemap;
-const dirLights = [],
- lightmapObjects = [];
+ object: THREE.Object3D = new THREE.Mesh(),
+ lightOrigin: THREE.Group,
+ progressiveSurfacemap: ProgressiveLightMap;
+const dirLights: THREE.DirectionalLight[] = [],
+ lightmapObjects: THREE.Object3D[] = [];
const params = {
Enable: true,
'Blur Edges': true,
@@ -99,14 +99,14 @@ function init() {
// model
function loadModel() {
object.traverse(function (child) {
- if (child.isMesh) {
+ if ((child as THREE.Mesh).isMesh) {
child.name = 'Loaded Mesh';
child.castShadow = true;
child.receiveShadow = true;
- child.material = new THREE.MeshPhongMaterial();
+ (child as THREE.Mesh).material = new THREE.MeshPhongMaterial();

// This adds the model to the lightmap
- lightmapObjects.push(child);
+ lightmapObjects.push(child as THREE.Mesh);
progressiveSurfacemap.addObjectsToLightMap(lightmapObjects);
} else {
child.layers.disableAll(); // Disable Rendering for this
diff --git a/examples-testing/examples/webgpu_shadowmap_vsm.ts b/examples-testing/examples/webgpu_shadowmap_vsm.ts
index a9f6f0e5..c68aa5fc 100644
--- a/examples-testing/examples/webgpu_shadowmap_vsm.ts
Expand Down
27 changes: 27 additions & 0 deletions types/three/examples/jsm/misc/ProgressiveLightMapGPU.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Camera, Material, Object3D, Vector3, WebGPURenderer } from "three/webgpu";

export interface UVBoxes {
w: number;
h: number;
index: number;
}

export interface LightMapContainers {
basicMat: Material | Material[];
object: Object3D;
}

declare class ProgressiveLightMap {
renderer: WebGPURenderer;
resolution: number;

constructor(renderer: WebGPURenderer, resolution?: number);

addObjectsToLightMap(objects: Object3D[]): void;

update(camera: Camera, blendWindow?: number, blurEdges?: boolean): void;

showDebugLightmap(visible: boolean, position?: Vector3 | null): void;
}

export { ProgressiveLightMap };
Loading