Skip to content

Commit

Permalink
feature (1.0, mtoon): MToonMaterial now supports emissiveIntensity
Browse files Browse the repository at this point in the history
This is required in order to support KHR_materials_emissive_strength extension

See: KhronosGroup/glTF#1994
Ref: https://github.com/mrdoob/three.js/pull/23867/files

I could have `_emissive` and `_emissiveStrength` and multiply them on JS side instead, but I decided to multiply on shader side because of code difficulty
  • Loading branch information
0b5vr committed May 25, 2022
1 parent 3ff3b7b commit a88e669
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
9 changes: 9 additions & 0 deletions packages/three-vrm-materials-mtoon/src/MToonMaterial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class MToonMaterial extends THREE.ShaderMaterial {
normalMapUvTransform: THREE.IUniform<THREE.Matrix3>;
normalScale: THREE.IUniform<THREE.Vector2>;
emissive: THREE.IUniform<THREE.Color>;
emissiveIntensity: THREE.IUniform<number>;
emissiveMap: THREE.IUniform<THREE.Texture | null>;
emissiveMapUvTransform: THREE.IUniform<THREE.Matrix3>;
shadeColorFactor: THREE.IUniform<THREE.Color>;
Expand Down Expand Up @@ -93,6 +94,13 @@ export class MToonMaterial extends THREE.ShaderMaterial {
this.uniforms.emissive.value = value;
}

public get emissiveIntensity(): number {
return this.uniforms.emissiveIntensity.value;
}
public set emissiveIntensity(value: number) {
this.uniforms.emissiveIntensity.value = value;
}

public get emissiveMap(): THREE.Texture | null {
return this.uniforms.emissiveMap.value;
}
Expand Down Expand Up @@ -425,6 +433,7 @@ export class MToonMaterial extends THREE.ShaderMaterial {
parametricRimFresnelPowerFactor: { value: 1.0 },
parametricRimLiftFactor: { value: 0.0 },
emissive: { value: new THREE.Color(0.0, 0.0, 0.0) },
emissiveIntensity: { value: 1.0 },
emissiveMapUvTransform: { value: new THREE.Matrix3() },
outlineWidthMultiplyTexture: { value: null },
outlineWidthMultiplyTextureUvTransform: { value: new THREE.Matrix3() },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface MToonMaterialParameters extends THREE.ShaderMaterialParameters
normalMap?: THREE.Texture;
normalScale?: THREE.Vector2;
emissive?: THREE.Color;
emissiveIntensity?: number;
emissiveMap?: THREE.Texture;
shadeColorFactor?: THREE.Color;
shadeMultiplyTexture?: THREE.Texture;
Expand Down
3 changes: 2 additions & 1 deletion packages/three-vrm-materials-mtoon/src/shaders/mtoon.frag
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ uniform float parametricRimLiftFactor;
#endif

uniform vec3 emissive;
uniform float emissiveIntensity;

uniform vec3 outlineColorFactor;
uniform float outlineLightingMixFactor;
Expand Down Expand Up @@ -342,7 +343,7 @@ void main() {

vec4 diffuseColor = vec4( litFactor, opacity );
ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
vec3 totalEmissiveRadiance = emissive;
vec3 totalEmissiveRadiance = emissive * emissiveIntensity;

#include <logdepthbuf_fragment>

Expand Down

0 comments on commit a88e669

Please sign in to comment.