Skip to content

Commit

Permalink
Merge pull request #42 from virtual-cast/BREAKING-CHANGE-upgrade-baby…
Browse files Browse the repository at this point in the history
…lonjs-to-4.1.0-beta.18

Breaking change upgrade babylonjs to 4.1.0 beta.18
  • Loading branch information
il-masaru-yamagishi authored Jan 6, 2020
2 parents 777a52d + 6e9fb32 commit cccae27
Show file tree
Hide file tree
Showing 6 changed files with 2,343 additions and 881 deletions.
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ workflows:
jobs:
build:
docker:
- image: circleci/node:8
- image: circleci/node:12
working_directory: ~/repo
steps:
- checkout
Expand All @@ -43,7 +43,7 @@ jobs:

lint:
docker:
- image: circleci/node:8
- image: circleci/node:12
working_directory: ~/repo
steps:
- checkout
Expand All @@ -64,7 +64,7 @@ jobs:

release:
docker:
- image: circleci/node:8
- image: circleci/node:12
working_directory: ~/repo
steps:
- checkout
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# babylon-mtoon-material

[![npm version](https://badge.fury.io/js/babylon-mtoon-material.svg)](https://badge.fury.io/js/babylon-mtoon-material) [![Greenkeeper badge](https://badges.greenkeeper.io/virtual-cast/babylon-mtoon-material.svg)](https://greenkeeper.io/) [![CircleCI](https://circleci.com/gh/virtual-cast/babylon-mtoon-material.svg?style=svg)](https://circleci.com/gh/virtual-cast/babylon-mtoon-material) [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
[![npm version](https://badge.fury.io/js/babylon-mtoon-material.svg)](https://badge.fury.io/js/babylon-mtoon-material) [![CircleCI](https://circleci.com/gh/virtual-cast/babylon-mtoon-material.svg?style=svg)](https://circleci.com/gh/virtual-cast/babylon-mtoon-material) [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)

![](mtoon.png)

[Unity Santarh/MToon Shader](https://github.com/Santarh/MToon/) WebGL porting to [babylon.js](https://www.babylonjs.com/).

This is **Work In Progress**. Some settings will be ignored or generates inconsistent lighting.
Some settings will be ignored or generates inconsistent lighting.

When you use babylon.js-beta.17 or older, please use [v1.9.0](https://github.com/virtual-cast/babylon-mtoon-material/releases/tag/v1.9.0).

[About MToon](https://vrm.dev/en/univrm/shaders/mtoon/)([ja](https://vrm.dev/univrm/shaders/mtoon/))

Expand Down
56 changes: 26 additions & 30 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,41 +20,37 @@
"Material"
],
"files": [
"package.json",
"README.md",
"dist/index.js",
"dist/index.d.ts",
"dist/index.module.js",
"dist/mtoon-material.d.ts"
"dist/**/*",
"!dist/test/**/*"
],
"typings": "dist/index.d.ts",
"main": "dist/index.module.js",
"dependencies": {},
"devDependencies": {
"@babylonjs/core": "^4.0.0",
"@babylonjs/inspector": "^4.0.0",
"@semantic-release/commit-analyzer": "^6.2.0",
"@semantic-release/git": "^7.0.14",
"@semantic-release/github": "^5.4.0",
"@semantic-release/npm": "^5.1.13",
"@semantic-release/release-notes-generator": "^7.2.1",
"@babylonjs/core": "^4.1.0-beta.18",
"@babylonjs/inspector": "^4.1.0-beta.18",
"@semantic-release/commit-analyzer": "^6.3.3",
"@semantic-release/git": "^7.0.18",
"@semantic-release/github": "^5.5.5",
"@semantic-release/npm": "^5.3.5",
"@semantic-release/release-notes-generator": "^7.3.5",
"@types/node": "^12.0.12",
"cz-conventional-changelog": "2.1.0",
"gh-pages": "^2.0.1",
"http-server": "^0.11.1",
"jest": "^24.8.0",
"jest-dev-server": "^4.2.0",
"jest-puppeteer": "^4.2.0",
"puppeteer": "^1.18.1",
"raw-loader": "^3.0.0",
"semantic-release": "^15.13.18",
"ts-loader": "^6.0.4",
"tslint": "^5.18.0",
"typescript": "^3.5.2",
"webpack": "^4.35.0",
"webpack-cli": "^3.3.5",
"webpack-dev-server": "^3.7.2",
"webpack-merge": "^4.2.1"
"cz-conventional-changelog": "3.0.2",
"gh-pages": "^2.1.1",
"http-server": "^0.12.0",
"jest": "^24.9.0",
"jest-dev-server": "^4.4.0",
"jest-puppeteer": "^4.4.0",
"puppeteer": "^2.0.0",
"raw-loader": "^4.0.0",
"semantic-release": "^15.14.0",
"ts-loader": "^6.2.1",
"tslint": "^5.20.1",
"typescript": "^3.7.4",
"webpack": "^4.41.5",
"webpack-cli": "^3.3.10",
"webpack-dev-server": "^3.10.1",
"webpack-merge": "^4.2.2"
},
"scripts": {
"build": "webpack",
Expand Down Expand Up @@ -99,6 +95,6 @@
]
},
"peerDependencies": {
"@babylonjs/core": "^4.0.0"
"@babylonjs/core": "^4.1.0-beta.18"
}
}
2 changes: 2 additions & 0 deletions src/mtoon-material-defines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ export class MToonMaterialDefines extends MaterialDefines {
public CLIPPLANE2 = false;
public CLIPPLANE3 = false;
public CLIPPLANE4 = false;
public CLIPPLANE5 = false;
public CLIPPLANE6 = false;
public BONETEXTURE = false;
public INSTANCES = false;
public SHADOWFLOAT = false;
Expand Down
31 changes: 22 additions & 9 deletions src/mtoon-material.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Constants } from '@babylonjs/core/Engines/constants';
import { Effect, EffectFallbacks } from '@babylonjs/core/Materials/effect';
import { Effect, IEffectCreationOptions } from '@babylonjs/core/Materials/effect';
import { EffectFallbacks } from '@babylonjs/core/Materials/effectFallbacks';
import { Material } from '@babylonjs/core/Materials/material';
import { MaterialHelper } from '@babylonjs/core/Materials/materialHelper';
import { PushMaterial } from '@babylonjs/core/Materials/pushMaterial';
Expand All @@ -10,7 +11,7 @@ import { VertexBuffer } from '@babylonjs/core/Meshes/buffer';
import { Mesh } from '@babylonjs/core/Meshes/mesh';
import { SubMesh } from '@babylonjs/core/Meshes/subMesh';
import { expandToProperty, SerializationHelper, serialize, serializeAsColor3, serializeAsTexture } from '@babylonjs/core/Misc/decorators';
import { IAnimatable } from '@babylonjs/core/Misc/tools';
import { IAnimatable } from '@babylonjs/core/Animations/animatable.interface';
import { Scene } from '@babylonjs/core/scene';
import { Nullable } from '@babylonjs/core/types';
import { getInspectableCustomProperties } from './inspectable-custom-properties';
Expand Down Expand Up @@ -240,6 +241,7 @@ export class MToonMaterial extends PushMaterial {
*/
@expandToProperty('_markAllSubMeshesAsLightsDirty')
public alphaCutOff = 0.5;
private _rebuildInParallel = false;
//#endregion

//#region Colors
Expand Down Expand Up @@ -555,7 +557,7 @@ export class MToonMaterial extends PushMaterial {
*/
public isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances = false): boolean {
if (subMesh.effect && this.isFrozen) {
if (this._wasPreviouslyReady) {
if (subMesh.effect._wasPreviouslyReady) {
return true;
}
}
Expand Down Expand Up @@ -674,6 +676,7 @@ export class MToonMaterial extends PushMaterial {

// Get correct effect
if (defines.isDirty) {
const lightDisposed = defines._areLightsDisposed;
defines.markAsProcessed();

// Fallbacks
Expand Down Expand Up @@ -729,7 +732,7 @@ export class MToonMaterial extends PushMaterial {
const uniforms = [
'world', 'view', 'viewProjection', 'vLightsType',
'visibility', 'mBones',
'vClipPlane', 'vClipPlane2', 'vClipPlane3', 'vClipPlane4',
'vClipPlane', 'vClipPlane2', 'vClipPlane3', 'vClipPlane4', 'vClipPlane5', 'vClipPlane6',
'vFogInfos', 'vFogColor', 'pointSize',
'alphaCutOff', 'logarithmicDepthConstant', 'vTangentSpaceParams', 'boneTextureWidth',

Expand Down Expand Up @@ -768,7 +771,7 @@ export class MToonMaterial extends PushMaterial {
samplers,
defines,
maxSimultaneousLights: this.maxSimultaneousLights,
} as any);
} as IEffectCreationOptions);

this.applyDefines(defines);

Expand All @@ -788,14 +791,22 @@ export class MToonMaterial extends PushMaterial {
maxSimultaneousLights: this.maxSimultaneousLights,
maxSimultaneousMorphTargets: defines.NUM_MORPH_INFLUENCERS,
},
} as any, engine);
} as IEffectCreationOptions, engine);

if (effect) {
// Use previous effect while new one is compiling
if (this.allowShaderHotSwapping && previousEffect && !effect.isReady()) {
effect = previousEffect;
this._rebuildInParallel = true;
defines.markAsUnprocessed();

if (lightDisposed) {
// re register in case it takes more than one frame.
defines._areLightsDisposed = true;
return false;
}
} else {
this._rebuildInParallel = false;
scene.resetCachedMaterial();
subMesh.setEffect(effect, defines);
this.buildUniformLayout();
Expand All @@ -808,7 +819,7 @@ export class MToonMaterial extends PushMaterial {
}

defines._renderId = scene.getRenderId();
this._wasPreviouslyReady = true;
subMesh.effect._wasPreviouslyReady = true;

return true;
}
Expand Down Expand Up @@ -913,7 +924,7 @@ export class MToonMaterial extends PushMaterial {
if (mustRebind || !this.isFrozen) {
// `freeze` しない限り毎回更新される値
if (scene.lightsEnabled && !this.disableLighting) {
MaterialHelper.BindLights(scene, mesh, effect, defines, this.maxSimultaneousLights);
MaterialHelper.BindLights(scene, mesh, effect, defines, this.maxSimultaneousLights, this._rebuildInParallel);
}

// View
Expand All @@ -930,7 +941,9 @@ export class MToonMaterial extends PushMaterial {
}

// Log. depth
MaterialHelper.BindLogDepth(defines, effect, scene);
if (this.useLogarithmicDepth) {
MaterialHelper.BindLogDepth(defines, effect, scene);
}
}
effect.setFloat('aspect', scene.getEngine().getAspectRatio(scene.activeCamera!));
effect.setFloat('isOutline', 0.0);
Expand Down
Loading

0 comments on commit cccae27

Please sign in to comment.