diff --git a/src/loader/GLTFParser.js b/src/loader/GLTFParser.js index d4d13517..32f158b9 100644 --- a/src/loader/GLTFParser.js +++ b/src/loader/GLTFParser.js @@ -571,6 +571,12 @@ const GLTFParser = Class.create(/** @lends GLTFParser.prototype */{ if (emissiveTexture) { material.emission = this.getTexture(emissiveTexture); } + + const emissiveFactor = values.emissiveFactor; + if (emissiveFactor) { + material.emissionFactor.fromArray(emissiveFactor); + material.emissionFactor.a = 1; + } } else { material.lightType = 'NONE'; } diff --git a/src/material/PBRMaterial.js b/src/material/PBRMaterial.js index a9d78715..fbab8df4 100644 --- a/src/material/PBRMaterial.js +++ b/src/material/PBRMaterial.js @@ -164,12 +164,19 @@ const PBRMaterial = Class.create(/** @lends PBRMaterial.prototype */ { isSpecularEnvMapIncludeMipmaps: false, /** - * 放射光贴图(sRGB 空间),或颜色 + * 放射光贴图(sRGB 空间) * @default null - * @type {Texture|Color} + * @type {Texture} */ emission: null, + /** + * The emissive color of the material. + * @default new Color(0, 0, 0) + * @type {Color} + */ + emissionFactor: null, + /** * 是否基于反射光泽度的 PBR,具体见 [KHR_materials_pbrSpecularGlossiness]{@link https://github.com/KhronosGroup/glTF/tree/master/extensions/Khronos/KHR_materials_pbrSpecularGlossiness} * @default false @@ -259,6 +266,7 @@ const PBRMaterial = Class.create(/** @lends PBRMaterial.prototype */ { constructor(params) { this.baseColor = new Color(1, 1, 1); this.specular = new Color(1, 1, 1); + this.emissionFactor = new Color(0, 0, 0); PBRMaterial.superclass.constructor.call(this, params); @@ -267,6 +275,7 @@ const PBRMaterial = Class.create(/** @lends PBRMaterial.prototype */ { u_metallic: 'METALLIC', u_roughness: 'ROUGHNESS', u_specular: 'SPECULAR', + u_emissionFactor: 'EMISSIONFACTOR', u_glossiness: 'GLOSSINESS', u_brdfLUT: 'BRDFLUT', u_diffuseEnvMap: 'DIFFUSEENVMAP', diff --git a/src/material/semantic.js b/src/material/semantic.js index 52f8833d..c533d022 100644 --- a/src/material/semantic.js +++ b/src/material/semantic.js @@ -952,6 +952,17 @@ const semantic = { } }, + /** + * EMISSION FACTOR + * @type {Object} + */ + EMISSIONFACTOR: { + get(mesh, material, programInfo) { + return material.emissionFactor.elements; + } + }, + + /** * @type {semanticObject} */ @@ -970,7 +981,6 @@ const semantic = { } }, - /** * @type {semanticObject} */ diff --git a/src/shader/chunk/pbr.frag b/src/shader/chunk/pbr.frag index 8fa9d679..a5ed2e47 100644 --- a/src/shader/chunk/pbr.frag +++ b/src/shader/chunk/pbr.frag @@ -3,6 +3,8 @@ #pragma glslify: import('./fixMathCrash.glsl'); uniform vec4 u_baseColor; +uniform vec4 u_emissionFactor; + #ifdef HILO_BASE_COLOR_MAP uniform HILO_SAMPLER_2D u_baseColorMap; #endif diff --git a/src/shader/chunk/pbr_main.frag b/src/shader/chunk/pbr_main.frag index dbfe3167..04dd1b0f 100644 --- a/src/shader/chunk/pbr_main.frag +++ b/src/shader/chunk/pbr_main.frag @@ -1,4 +1,5 @@ vec4 baseColor = u_baseColor; +vec3 emissionColor = u_emissionFactor.rgb; #ifdef HILO_BASE_COLOR_MAP #ifdef HILO_GAMMA_CORRECTION @@ -185,16 +186,19 @@ color.a = baseColor.a; #ifdef HILO_EMISSION_MAP #ifdef HILO_GAMMA_CORRECTION - color.rgb += sRGBToLinear(HILO_TEXTURE_2D(u_emission)).rgb; + emissionColor *= sRGBToLinear(HILO_TEXTURE_2D(u_emission)).rgb; #else - color.rgb += HILO_TEXTURE_2D(u_emission).rgb; + emissionColor *= HILO_TEXTURE_2D(u_emission).rgb; #endif #endif + color.rgb += emissionColor; + #ifdef HILO_HAS_CLEARCOAT float t = clearcoatFactor * clearCoatFresnel; color.rgb = color.rgb * (1.0 - t) + clearCoatLayer * t; #endif #else color = baseColor; + color.rgb += emissionColor; #endif \ No newline at end of file