-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add prettier, simplify logic, add example to readme
- Loading branch information
Showing
4 changed files
with
73 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
trailingComma: 'es5' | ||
semi: false | ||
singleQuote: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,19 @@ | ||
<!doctype html> | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" type="image/svg+xml" href="/vite.svg" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Vite App</title> | ||
</head> | ||
|
||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" type="image/svg+xml" href="/vite.svg" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Vite App</title> | ||
</head> | ||
|
||
<body> | ||
<div id="app"></div> | ||
<style> | ||
body { | ||
margin: 0; | ||
} | ||
</style> | ||
<script type="module" src="/main.js"></script> | ||
</body> | ||
|
||
</html> | ||
<body> | ||
<div id="app"></div> | ||
<style> | ||
body { | ||
margin: 0; | ||
} | ||
</style> | ||
<script type="module" src="/main.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,41 @@ | ||
import * as THREE from "three"; | ||
import { WebGPURenderer } from "three/webgpu"; | ||
import * as TSL from "three/tsl"; | ||
import { MeshBasicNodeMaterial } from "three/webgpu"; | ||
import * as THREE from 'three' | ||
import { WebGPURenderer } from 'three/webgpu' | ||
import { mix, vec3, uv } from 'three/tsl' | ||
import { MeshBasicNodeMaterial } from 'three/webgpu' | ||
|
||
// This is a checkerboard pattern from material x made into tsl | ||
//input: color1, color2, uvtiling, uvoffset | ||
const color1 = TSL.uniform(new THREE.Color(1, 0, 0)); | ||
const color2 = TSL.uniform(new THREE.Color(0, 1, 0)); | ||
const uvtiling = TSL.uniform(new THREE.Vector2(8, 8)); | ||
const uvoffset = TSL.uniform(new THREE.Vector2(0, 0)); | ||
const mix = TSL.uv().mul(uvtiling).sub(uvoffset).floor().dot(1).mod(2); | ||
const red = vec3(1, 0, 0) | ||
const green = vec3(0, 1, 0) | ||
const checkerboard = uv().mul(8).floor().dot(1).mod(2) | ||
const colorNode = mix(red, green, checkerboard) | ||
|
||
const output = TSL.mix(color1, color2, mix); | ||
const width = window.innerWidth | ||
const height = window.innerHeight | ||
|
||
//output: color3 | ||
const camera = new THREE.PerspectiveCamera(70, width / height, 0.01, 10) | ||
camera.position.z = 1 | ||
|
||
const width = window.innerWidth; | ||
const height = window.innerHeight; | ||
const scene = new THREE.Scene() | ||
|
||
const camera = new THREE.PerspectiveCamera(70, width / height, 0.01, 10); | ||
camera.position.z = 1; | ||
const geometry = new THREE.BoxGeometry(0.2, 0.2, 0.2) | ||
const material = new MeshBasicNodeMaterial() | ||
material.colorNode = colorNode | ||
|
||
const scene = new THREE.Scene(); | ||
const mesh = new THREE.Mesh(geometry, material) | ||
scene.add(mesh) | ||
|
||
const geometry = new THREE.BoxGeometry(0.2, 0.2, 0.2); | ||
const material = new MeshBasicNodeMaterial(); | ||
material.colorNode = output; | ||
|
||
const mesh = new THREE.Mesh(geometry, material); | ||
scene.add(mesh); | ||
|
||
const renderer = new WebGPURenderer({ antialias: true }); | ||
await renderer.init(); | ||
renderer.setSize(width, height); | ||
renderer.setAnimationLoop(animate); | ||
document.body.appendChild(renderer.domElement); | ||
const renderer = new WebGPURenderer({ antialias: true }) | ||
await renderer.init() | ||
renderer.setSize(width, height) | ||
renderer.setAnimationLoop(animate) | ||
document.body.appendChild(renderer.domElement) | ||
|
||
console.log( | ||
renderer.backend.isWebGPUBackend ? "WebGPU Backend" : "WebGL Backend" | ||
); | ||
renderer.backend.isWebGPUBackend ? 'WebGPU Backend' : 'WebGL Backend' | ||
) | ||
|
||
function animate(time) { | ||
mesh.rotation.x = time / 2000; | ||
mesh.rotation.y = time / 1000; | ||
mesh.rotation.x = time / 2000 | ||
mesh.rotation.y = time / 1000 | ||
|
||
renderer.render(scene, camera); | ||
renderer.render(scene, camera) | ||
} | ||
|
||
window.addEventListener("resize", () => { | ||
const newWidth = window.innerWidth; | ||
const newHeight = window.innerHeight; | ||
|
||
camera.aspect = newWidth / newHeight; | ||
camera.updateProjectionMatrix(); | ||
|
||
renderer.setSize(newWidth, newHeight); | ||
}); |