Skip to content

Commit 092871c

Browse files
authored
TSL: Introduce varying.setInterpolation() (#1609)
* TSL: Introduce varying.setInterpolation() * Update three.js * Add src * Update patch and delete src * Update declarations * Add examples * Update patch and delete examples
1 parent d011b13 commit 092871c

File tree

6 files changed

+284
-130
lines changed

6 files changed

+284
-130
lines changed

examples-testing/changes.patch

Lines changed: 98 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14108,6 +14108,103 @@ index 15527632..58f5cc14 100644
1410814108
const amount = ev.deltaY;
1410914109
if (amount === 0) return;
1411014110
const dir = amount / Math.abs(amount);
14111+
diff --git a/examples-testing/examples/webgpu_centroid_sampling.ts b/examples-testing/examples/webgpu_centroid_sampling.ts
14112+
index ac77927f..c3c883d9 100644
14113+
--- a/examples-testing/examples/webgpu_centroid_sampling.ts
14114+
+++ b/examples-testing/examples/webgpu_centroid_sampling.ts
14115+
@@ -1,15 +1,15 @@
14116+
-import * as THREE from 'three';
14117+
+import * as THREE from 'three/webgpu';
14118+
import { varying, uv, texture, Fn } from 'three/tsl';
14119+
14120+
import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
14121+
14122+
-let rendererAntialiasingEnabled;
14123+
-let rendererAntialiasingDisabled;
14124+
-let camera;
14125+
-let scene;
14126+
-let gui;
14127+
+let rendererAntialiasingEnabled: THREE.WebGPURenderer;
14128+
+let rendererAntialiasingDisabled: THREE.WebGPURenderer;
14129+
+let camera: THREE.PerspectiveCamera;
14130+
+let scene: THREE.Scene;
14131+
+let gui: GUI;
14132+
14133+
-const effectController = {
14134+
+const effectController: { sampling: THREE.InterpolationSamplingMode } = {
14135+
sampling: 'normal',
14136+
};
14137+
14138+
@@ -17,7 +17,7 @@ const atlasCanvas = document.createElement('canvas');
14139+
atlasCanvas.width = 16;
14140+
atlasCanvas.height = 16;
14141+
14142+
-const ctx = atlasCanvas.getContext('2d');
14143+
+const ctx = atlasCanvas.getContext('2d')!;
14144+
ctx.fillStyle = 'red';
14145+
ctx.fillRect(0, 0, 8, 8);
14146+
14147+
@@ -62,7 +62,7 @@ function init() {
14148+
14149+
scene = new THREE.Scene();
14150+
14151+
- const makeFaceGeometry = uvs => {
14152+
+ const makeFaceGeometry = (uvs: number[]) => {
14153+
const geometry = new THREE.BufferGeometry();
14154+
const positions = [-1, -1, 0, 1, -1, 0, 1, 1, 0, -1, 1, 0];
14155+
geometry.setAttribute('position', new THREE.BufferAttribute(new Float32Array(positions), 3));
14156+
@@ -78,7 +78,7 @@ function init() {
14157+
const material = new THREE.MeshBasicNodeMaterial();
14158+
const testUV = varying(uv(), 'testUV');
14159+
14160+
- const createShader = (type, sampling) => {
14161+
+ const createShader = (type: THREE.InterpolationSamplingType, sampling: THREE.InterpolationSamplingMode) => {
14162+
return Fn(() => {
14163+
testUV.setInterpolation(type, sampling);
14164+
14165+
@@ -86,8 +86,14 @@ function init() {
14166+
});
14167+
};
14168+
14169+
- const withFlatFirstShader = createShader('flat', 'first');
14170+
- const withFlatEitherShader = createShader('flat', 'either');
14171+
+ const withFlatFirstShader = createShader(
14172+
+ THREE.InterpolationSamplingType.FLAT,
14173+
+ THREE.InterpolationSamplingMode.FLAT_FIRST,
14174+
+ );
14175+
+ const withFlatEitherShader = createShader(
14176+
+ THREE.InterpolationSamplingType.FLAT,
14177+
+ THREE.InterpolationSamplingMode.FLAT_EITHER,
14178+
+ );
14179+
14180+
const withSampleShader = Fn(() => {
14181+
testUV.setInterpolation(THREE.InterpolationSamplingType.PERSPECTIVE, THREE.InterpolationSamplingMode.SAMPLE);
14182+
@@ -107,7 +113,7 @@ function init() {
14183+
14184+
material.colorNode = withoutInterpolationShader();
14185+
14186+
- const faceMeshes = [];
14187+
+ const faceMeshes: THREE.Mesh<THREE.BufferGeometry, THREE.MeshBasicNodeMaterial>[] = [];
14188+
14189+
for (let x = -5; x < 5; x++) {
14190+
for (let y = -5; y < 5; y++) {
14191+
@@ -136,13 +142,13 @@ function init() {
14192+
forceWebGL: forceWebGL,
14193+
});
14194+
14195+
- document.body.querySelector('#antialising-enabled').appendChild(rendererAntialiasingEnabled.domElement);
14196+
+ document.body.querySelector('#antialising-enabled')!.appendChild(rendererAntialiasingEnabled.domElement);
14197+
rendererAntialiasingEnabled.setPixelRatio(window.devicePixelRatio);
14198+
rendererAntialiasingEnabled.setSize(window.innerWidth / 2, window.innerHeight);
14199+
rendererAntialiasingEnabled.setAnimationLoop(animateAliased);
14200+
14201+
- document.body.querySelector('#antialising-disabled').appendChild(rendererAntialiasingDisabled.domElement);
14202+
- document.body.querySelector('#antialising-disabled').appendChild(rendererAntialiasingDisabled.domElement);
14203+
+ document.body.querySelector('#antialising-disabled')!.appendChild(rendererAntialiasingDisabled.domElement);
14204+
+ document.body.querySelector('#antialising-disabled')!.appendChild(rendererAntialiasingDisabled.domElement);
14205+
14206+
onWindowResize();
14207+
1411114208
diff --git a/examples-testing/examples/webgpu_clearcoat.ts b/examples-testing/examples/webgpu_clearcoat.ts
1411214209
index 0d5b70a2..0c147364 100644
1411314210
--- a/examples-testing/examples/webgpu_clearcoat.ts
@@ -15210,7 +15307,7 @@ index 67269546..f39f2d74 100644
1521015307

1521115308
gui.add(params, 'translation', 0, 10).onChange(function (val) {
1521215309
diff --git a/examples-testing/examples/webgpu_loader_gltf.ts b/examples-testing/examples/webgpu_loader_gltf.ts
15213-
index 64d1fda4..079b75d7 100644
15310+
index afd9b7e4..feff7485 100644
1521415311
--- a/examples-testing/examples/webgpu_loader_gltf.ts
1521515312
+++ b/examples-testing/examples/webgpu_loader_gltf.ts
1521615313
@@ -1,11 +1,11 @@

0 commit comments

Comments
 (0)