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

BREAKING: WebGPU support (MToonNodeMaterial) #1384

Merged
merged 43 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
d4352ed
deps: Bump three.js to r160
0b5vr Dec 25, 2023
ac686ce
examples: Change light intensity from 1 to PI
0b5vr Jan 10, 2024
bdaf2c7
refactor: add COMPAT comment on pre-r156 compats addressed in https:/…
0b5vr Jan 10, 2024
c92cdbb
wip feature: MToon for WebGPU
0b5vr Jan 10, 2024
6f5f087
fix (WebGPU, MToon): Fix outline, it should scale in world space inst…
0b5vr Jan 11, 2024
ebeb237
fix (WebGPU, MToon): Fix transparentWithZWrite
0b5vr Jan 11, 2024
62ebea8
fix: Fix outline width when model normal is not normalized
0b5vr Jan 11, 2024
8072596
fix: Ignore vertex color if it's defined
0b5vr Jan 11, 2024
d15cf35
fix: (WebGPU, MToon): Fix parametricRim formula
0b5vr Jan 12, 2024
638d0ee
fix (WebGPU, MToon): Fix outline color calculation method
0b5vr Jan 12, 2024
b77f355
fix (WebGPU, MToon): set alpha to 1 when the material is transparent
0b5vr Jan 12, 2024
0d8d79a
feature (WebGPU, MToon): support screenCoordinate width outline and o…
0b5vr Jan 12, 2024
74acea5
fix (WebGPU, MToon): fix matcap and parametric rim intensity when rim…
0b5vr Jan 12, 2024
3037a5d
fix (WebGPU, MToon): Fix outline color alpha
0b5vr Jan 12, 2024
ce08f6f
improve (WebGPU, MToon): improve customProgramCacheKey
0b5vr Jan 15, 2024
962b75c
improve (WebGPU, MToon): remove outlineWidthMode from customProgramCa…
0b5vr Jan 15, 2024
bc9e6ab
improve (WebGPU, MToon): Improve code around parametric rim
0b5vr Jan 15, 2024
33fc057
improve: Improve removeUnnecessaryJoints
0b5vr Jan 16, 2024
7bf8901
fix: apply patch-package for `NodeMaterial.setupOutput`
0b5vr Jan 16, 2024
1b854e0
Revert "improve: Improve removeUnnecessaryJoints"
0b5vr Jan 24, 2024
97d4c22
Merge branch 'bump-three-r162' into webgpu
0b5vr Mar 6, 2024
2dee4ed
fix: update type definition
0b5vr Mar 12, 2024
3c309e4
fix: tidy up NodeMaterial stuff
0b5vr Mar 22, 2024
1311e6c
fix: Fix rotation order of MToonAnimatedUVNode
0b5vr Mar 25, 2024
c1cbcbe
feature: add `sameBoneCounts` option to `removeUnnecessaryJoints`
0b5vr Mar 25, 2024
efacd16
feature!: MToonNodeMaterialLoaderPlugin
0b5vr Mar 25, 2024
de795b3
Merge branch 'jsdelivr' into webgpu
0b5vr Mar 27, 2024
0b61ba1
chore: change cdn from unpkg to jsDelivr for WebGPU examples
0b5vr Mar 27, 2024
98dee38
fix: Patch the ShaderNodeObject circular reference issue on `@types/t…
0b5vr Apr 8, 2024
21499d2
Merge branch 'dev' into webgpu
0b5vr Apr 8, 2024
48eb0dd
Merge branch 'dev' into webgpu
0b5vr May 14, 2024
644f168
Merge branch 'dev' into webgpu
0b5vr May 14, 2024
115e2dc
fix: Workaround the `addAssign` issue by using `add` and `assign` sep…
0b5vr May 14, 2024
8e3bde5
Merge branch 'dev' into webgpu
0b5vr May 14, 2024
f3401d3
Merge branch 'dev' into webgpu
0b5vr May 14, 2024
95eff3e
chore: reintroduce webgpu-dnd.html
0b5vr May 14, 2024
b80841e
fix: Fix uv animation transform order
0b5vr May 15, 2024
e5a5b73
examples: Bump Three.js version of new webgpu examples
0b5vr May 15, 2024
09641a7
Merge branch 'dev-v3' into webgpu
0b5vr May 24, 2024
36f064f
fix: Fix MToon default parameters
0b5vr May 28, 2024
4aa9976
feat: emit a compatibility warning if the developer attempts to use M…
0b5vr May 30, 2024
afe9143
feat: MToonNodeMaterial, Move and modify the "set alpha to 1 if it is…
0b5vr May 30, 2024
8e813ec
Merge branch 'dev-v3' into webgpu
0b5vr May 30, 2024
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
8 changes: 8 additions & 0 deletions packages/three-vrm-materials-mtoon/examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,13 @@ <h1>examples of <a href="https://github.com/pixiv/three-vrm/tree/dev/packages/th
<a href="emissive-strength.html">emissive-strength.html</a><br />
Combine VRMC_materials_mtoon with KHR_materials_emissive_strength
</p>
<p>
<a href="webgpu-feature-test.html">webgpu-feature-test.html</a><br />
A test scene for various MToon features, on WebGPU
</p>
<p>
<a href="webgpu-loader-plugin.html">webgpu-loader-plugin.html</a><br />
Import an MToon material from gltf, on WebGPU
</p>
</body>
</html>
325 changes: 325 additions & 0 deletions packages/three-vrm-materials-mtoon/examples/webgpu-feature-test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,325 @@
<!DOCTYPE html>

<html>
<head>
<meta charset="utf-8" />
<title>three-vrm example</title>
<meta
name="viewport"
content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"
/>
<style>
body {
margin: 0;
background: #000;
}
canvas {
display: block;
}
</style>
</head>

<body>
<script type="importmap">
{
"imports": {
"three": "https://cdn.jsdelivr.net/npm/[email protected]/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/[email protected]/examples/jsm/",
"@pixiv/three-vrm-materials-mtoon": "../lib/three-vrm-materials-mtoon.module.js"
}
}
</script>

<script type="module">
import * as THREE from 'three';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
import WebGPURenderer from 'three/addons/renderers/webgpu/WebGPURenderer.js';
import { MToonNodeMaterial } from '@pixiv/three-vrm-materials-mtoon';

// renderer
const renderer = new WebGPURenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setPixelRatio( window.devicePixelRatio );
document.body.appendChild( renderer.domElement );

// camera
const camera = new THREE.PerspectiveCamera( 30.0, window.innerWidth / window.innerHeight, 0.1, 20.0 );
camera.position.set( 0.0, 0.0, 10.0 );

// camera controls
const controls = new OrbitControls( camera, renderer.domElement );
controls.screenSpacePanning = true;
controls.target.set( 0.0, 0.0, 0.0 );
controls.update();

// scene
const scene = new THREE.Scene();

// light
const light = new THREE.DirectionalLight( 0xffffff, Math.PI );
scene.add( light );

// test objects
const textureUVGrid = new THREE.TextureLoader().load( './models/uv-grid.png' );
textureUVGrid.wrapS = THREE.RepeatWrapping;
textureUVGrid.wrapT = THREE.RepeatWrapping;

const textureNormalPerlin = new THREE.TextureLoader().load( './models/normal-perlin.jpg' );
textureNormalPerlin.repeat.set( 2.0, 1.0 );
textureNormalPerlin.wrapS = THREE.RepeatWrapping;
textureNormalPerlin.wrapT = THREE.RepeatWrapping;

const textureBlind = new THREE.TextureLoader().load( './models/blind.png' );
textureBlind.repeat.set( 2.0, 1.0 );
textureBlind.wrapS = THREE.RepeatWrapping;
textureBlind.wrapT = THREE.RepeatWrapping;
textureBlind.magFilter = THREE.NearestFilter;
textureBlind.minFilter = THREE.NearestFilter;

const textureGrid = new THREE.TextureLoader().load( './models/grid.png' );
textureGrid.wrapS = THREE.RepeatWrapping;
textureGrid.wrapT = THREE.RepeatWrapping;
textureGrid.magFilter = THREE.NearestFilter;
textureGrid.minFilter = THREE.NearestFilter;

const textureBinaryHalf = new THREE.TextureLoader().load( './models/binary-half.png' );
textureBinaryHalf.repeat.set( 2.0, 1.0 );
textureBinaryHalf.wrapS = THREE.RepeatWrapping;
textureBinaryHalf.wrapT = THREE.RepeatWrapping;
textureBinaryHalf.magFilter = THREE.NearestFilter;
textureBinaryHalf.minFilter = THREE.NearestFilter;

const textureVroidRim = new THREE.TextureLoader().load( './models/vroid-rim.png' );

const geometrySphere = new THREE.SphereGeometry( 0.4 );

const meshes = [

// map
{

map: textureUVGrid,
shadeMultiplyTexture: textureUVGrid,

},

// lit-shade
{

color: 0xffffff,
shadeColorFactor: 0xff4488,

},

// cell shading
{

color: 0xddbbaa,
shadeColorFactor: 0x664422,
shadingToonyFactor: 1.0,

},

// lambert
{

color: 0xffffff,
shadeColorFactor: 0x000000,
shadingToonyFactor: 0.5,
shadingShiftFactor: - 0.5,

},

// half lambert
{

color: 0xffffff,
shadeColorFactor: 0x000000,
shadingToonyFactor: 0.0,
shadingShiftFactor: 0.0,

},

// map, uv scroll
{

map: textureUVGrid,
shadeMultiplyTexture: textureUVGrid,
uvAnimationScrollXSpeedFactor: 0.5,

},

// map, uv scroll with mask
{

map: textureUVGrid,
shadeMultiplyTexture: textureUVGrid,
uvAnimationScrollXSpeedFactor: 0.5,
uvAnimationMaskTexture: textureBlind,

},

// normal
{

color: 0x77bbee,
shadeColorFactor: 0x225577,
normalMap: textureNormalPerlin,

},

// map, normal
{

map: textureUVGrid,
shadeMultiplyTexture: textureUVGrid,
color: 0xffffff,
shadeColorFactor: 0x444444,
normalMap: textureNormalPerlin,

},

// map, normal, uv scroll with mask
{

map: textureUVGrid,
shadeMultiplyTexture: textureUVGrid,
color: 0xffffff,
shadeColorFactor: 0x444444,
normalMap: textureNormalPerlin,
uvAnimationScrollXSpeedFactor: 0.5,
uvAnimationMaskTexture: textureBlind,

},

// map, emissive
{

map: textureUVGrid,
shadeMultiplyTexture: textureUVGrid,
color: 0x444444,
shadeColorFactor: 0x222222,
emissiveMap: textureGrid,
emissive: 0xff8800,

},

// map, emissive, uv scroll with mask
{

map: textureUVGrid,
shadeMultiplyTexture: textureUVGrid,
color: 0x444444,
shadeColorFactor: 0x222222,
emissiveMap: textureGrid,
emissive: 0xff8800,
uvAnimationScrollXSpeedFactor: 0.5,
uvAnimationMaskTexture: textureBlind,

},

// map, normal, parametric rim
{

map: textureUVGrid,
shadeMultiplyTexture: textureUVGrid,
color: 0x444444,
shadeColorFactor: 0x222222,
normalMap: textureNormalPerlin,
parametricRimColorFactor: 0xff8800,
parametricRimFresnelPowerFactor: 3.0,

},

// map, normal, parametric rim with mask
{

map: textureUVGrid,
shadeMultiplyTexture: textureUVGrid,
color: 0x444444,
shadeColorFactor: 0x222222,
normalMap: textureNormalPerlin,
parametricRimColorFactor: 0xff8800,
parametricRimFresnelPowerFactor: 3.0,
rimMultiplyTexture: textureBinaryHalf,

},

// map, vroid style classic rim
{

map: textureUVGrid,
shadeMultiplyTexture: textureUVGrid,
color: 0x444444,
shadeColorFactor: 0x222222,
normalMap: textureNormalPerlin,
matcapFactor: 0xffffff,
matcapTexture: textureVroidRim,

},

// map, vroid style classic rim with mask
{

map: textureUVGrid,
shadeMultiplyTexture: textureUVGrid,
color: 0x444444,
shadeColorFactor: 0x222222,
normalMap: textureNormalPerlin,
matcapFactor: 0xffffff,
matcapTexture: textureVroidRim,
rimMultiplyTexture: textureBinaryHalf,

},

].map( ( params, i ) => {

const material = new MToonNodeMaterial( params );
const mesh = new THREE.Mesh( geometrySphere, material );

const x = ( i % 5 ) - 2.0;
const y = Math.floor( i / 5 ) - 2.0;
mesh.position.set( x, y, 0 );

scene.add( mesh );

return mesh;

} );

// helpers
const gridHelper = new THREE.GridHelper( 10, 10 );
scene.add( gridHelper );

const axesHelper = new THREE.AxesHelper( 5 );
scene.add( axesHelper );

// animate
const clock = new THREE.Clock();
clock.start();

function animate() {

requestAnimationFrame( animate );

const delta = clock.getDelta();

const theta = clock.elapsedTime;
const cosTheta = Math.cos( theta );
const sinTheta = Math.sin( theta );
light.position.set( cosTheta, 2.0, sinTheta ).normalize();

for ( const mesh of meshes ) {

mesh.material.update( delta );

}

renderer.renderAsync( scene, camera );

}

animate();
</script>
</body>
</html>
Loading
Loading