babylonjs-materials
Version:
Babylon.js Materials Library =====================
1,077 lines (1,023 loc) • 151 kB
JavaScript
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory(require("babylonjs"));
else if(typeof define === 'function' && define.amd)
define("babylonjs-materials", ["babylonjs"], factory);
else if(typeof exports === 'object')
exports["babylonjs-materials"] = factory(require("babylonjs"));
else
root["MATERIALS"] = factory(root["BABYLON"]);
})((typeof self !== "undefined" ? self : typeof global !== "undefined" ? global : this), (__WEBPACK_EXTERNAL_MODULE_babylonjs_Materials_effect__) => {
return /******/ (() => { // webpackBootstrap
/******/ "use strict";
/******/ var __webpack_modules__ = ({
/***/ "../../../dev/materials/src/custom/customMaterial.ts":
/*!***********************************************************!*\
!*** ../../../dev/materials/src/custom/customMaterial.ts ***!
\***********************************************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ CustomMaterial: () => (/* binding */ CustomMaterial),
/* harmony export */ CustomShaderStructure: () => (/* binding */ CustomShaderStructure),
/* harmony export */ ShaderSpecialParts: () => (/* binding */ ShaderSpecialParts)
/* harmony export */ });
/* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! tslib */ "../../../../node_modules/tslib/tslib.es6.mjs");
/* harmony import */ var babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.color */ "babylonjs/Materials/effect");
/* harmony import */ var babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__);
/**
* Structure of a custom shader
*/
var CustomShaderStructure = /** @class */ (function () {
function CustomShaderStructure() {
}
return CustomShaderStructure;
}());
/**
* Parts of a shader
*/
var ShaderSpecialParts = /** @class */ (function () {
function ShaderSpecialParts() {
}
return ShaderSpecialParts;
}());
/**
* Customized material
*/
var CustomMaterial = /** @class */ (function (_super) {
(0,tslib__WEBPACK_IMPORTED_MODULE_1__.__extends)(CustomMaterial, _super);
function CustomMaterial(name, scene) {
var _this = _super.call(this, name, scene) || this;
_this.CustomParts = new ShaderSpecialParts();
_this.customShaderNameResolve = _this.Builder;
_this.FragmentShader = babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__.Effect.ShadersStore["defaultPixelShader"];
_this.VertexShader = babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__.Effect.ShadersStore["defaultVertexShader"];
CustomMaterial.ShaderIndexer++;
_this._createdShaderName = "custom_" + CustomMaterial.ShaderIndexer;
return _this;
}
/**
* Runs after the material is bound to a mesh
* @param mesh mesh bound
* @param effect bound effect used to render
*/
CustomMaterial.prototype.AttachAfterBind = function (mesh, effect) {
if (this._newUniformInstances) {
for (var el in this._newUniformInstances) {
var ea = el.toString().split("-");
if (ea[0] == "vec2") {
effect.setVector2(ea[1], this._newUniformInstances[el]);
}
else if (ea[0] == "vec3") {
if (this._newUniformInstances[el] instanceof babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__.Color3) {
effect.setColor3(ea[1], this._newUniformInstances[el]);
}
else {
effect.setVector3(ea[1], this._newUniformInstances[el]);
}
}
else if (ea[0] == "vec4") {
if (this._newUniformInstances[el] instanceof babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__.Color4) {
effect.setDirectColor4(ea[1], this._newUniformInstances[el]);
}
else {
effect.setVector4(ea[1], this._newUniformInstances[el]);
}
effect.setVector4(ea[1], this._newUniformInstances[el]);
}
else if (ea[0] == "mat4") {
effect.setMatrix(ea[1], this._newUniformInstances[el]);
}
else if (ea[0] == "float") {
effect.setFloat(ea[1], this._newUniformInstances[el]);
}
}
}
if (this._newSamplerInstances) {
for (var el in this._newSamplerInstances) {
var ea = el.toString().split("-");
if (ea[0] == "sampler2D" && this._newSamplerInstances[el].isReady && this._newSamplerInstances[el].isReady()) {
effect.setTexture(ea[1], this._newSamplerInstances[el]);
}
}
}
};
/**
* @internal
*/
CustomMaterial.prototype.ReviewUniform = function (name, arr) {
if (name == "uniform" && this._newUniforms) {
for (var ind = 0; ind < this._newUniforms.length; ind++) {
if (this._customUniform[ind].indexOf("sampler") == -1) {
arr.push(this._newUniforms[ind].replace(/\[\d*\]/g, ""));
}
}
}
if (name == "sampler" && this._newUniforms) {
for (var ind = 0; ind < this._newUniforms.length; ind++) {
if (this._customUniform[ind].indexOf("sampler") != -1) {
arr.push(this._newUniforms[ind].replace(/\[\d*\]/g, ""));
}
}
}
return arr;
};
/**
* Builds the material
* @param shaderName name of the shader
* @param uniforms list of uniforms
* @param uniformBuffers list of uniform buffers
* @param samplers list of samplers
* @param defines list of defines
* @param attributes list of attributes
* @returns the shader name
*/
CustomMaterial.prototype.Builder = function (shaderName, uniforms, uniformBuffers, samplers, defines, attributes) {
if (attributes && this._customAttributes && this._customAttributes.length > 0) {
attributes.push.apply(attributes, this._customAttributes);
}
this.ReviewUniform("uniform", uniforms);
this.ReviewUniform("sampler", samplers);
var name = this._createdShaderName;
if (babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__.Effect.ShadersStore[name + "VertexShader"] && babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__.Effect.ShadersStore[name + "PixelShader"]) {
return name;
}
babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__.Effect.ShadersStore[name + "VertexShader"] = this._injectCustomCode(this.VertexShader, "vertex");
babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__.Effect.ShadersStore[name + "PixelShader"] = this._injectCustomCode(this.FragmentShader, "fragment");
return name;
};
CustomMaterial.prototype._injectCustomCode = function (code, shaderType) {
var customCode = this._getCustomCode(shaderType);
for (var point in customCode) {
var injectedCode = customCode[point];
if (injectedCode && injectedCode.length > 0) {
var fullPointName = "#define " + point;
code = code.replace(fullPointName, "\n" + injectedCode + "\n" + fullPointName);
}
}
return code;
};
CustomMaterial.prototype._getCustomCode = function (shaderType) {
var _a, _b;
if (shaderType === "vertex") {
return {
CUSTOM_VERTEX_BEGIN: this.CustomParts.Vertex_Begin,
CUSTOM_VERTEX_DEFINITIONS: (((_a = this._customUniform) === null || _a === void 0 ? void 0 : _a.join("\n")) || "") + (this.CustomParts.Vertex_Definitions || ""),
CUSTOM_VERTEX_MAIN_BEGIN: this.CustomParts.Vertex_MainBegin,
CUSTOM_VERTEX_UPDATE_POSITION: this.CustomParts.Vertex_Before_PositionUpdated,
CUSTOM_VERTEX_UPDATE_NORMAL: this.CustomParts.Vertex_Before_NormalUpdated,
CUSTOM_VERTEX_MAIN_END: this.CustomParts.Vertex_MainEnd,
CUSTOM_VERTEX_UPDATE_WORLDPOS: this.CustomParts.Vertex_After_WorldPosComputed,
};
}
return {
CUSTOM_FRAGMENT_BEGIN: this.CustomParts.Fragment_Begin,
CUSTOM_FRAGMENT_DEFINITIONS: (((_b = this._customUniform) === null || _b === void 0 ? void 0 : _b.join("\n")) || "") + (this.CustomParts.Fragment_Definitions || ""),
CUSTOM_FRAGMENT_MAIN_BEGIN: this.CustomParts.Fragment_MainBegin,
CUSTOM_FRAGMENT_UPDATE_DIFFUSE: this.CustomParts.Fragment_Custom_Diffuse,
CUSTOM_FRAGMENT_UPDATE_ALPHA: this.CustomParts.Fragment_Custom_Alpha,
CUSTOM_FRAGMENT_BEFORE_LIGHTS: this.CustomParts.Fragment_Before_Lights,
CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR: this.CustomParts.Fragment_Before_FragColor,
CUSTOM_FRAGMENT_MAIN_END: this.CustomParts.Fragment_MainEnd,
CUSTOM_FRAGMENT_BEFORE_FOG: this.CustomParts.Fragment_Before_Fog,
};
};
CustomMaterial.prototype._afterBind = function (mesh, effect, subMesh) {
if (effect === void 0) { effect = null; }
if (!effect) {
return;
}
this.AttachAfterBind(mesh, effect);
try {
_super.prototype._afterBind.call(this, mesh, effect, subMesh);
}
catch (e) { }
};
/**
* Adds a new uniform to the shader
* @param name the name of the uniform to add
* @param kind the type of the uniform to add
* @param param the value of the uniform to add
* @returns the current material
*/
CustomMaterial.prototype.AddUniform = function (name, kind, param) {
if (!this._customUniform) {
this._customUniform = new Array();
this._newUniforms = new Array();
this._newSamplerInstances = {};
this._newUniformInstances = {};
}
if (param) {
if (kind.indexOf("sampler") != -1) {
this._newSamplerInstances[kind + "-" + name] = param;
}
else {
this._newUniformInstances[kind + "-" + name] = param;
}
}
this._customUniform.push("uniform " + kind + " " + name + ";");
this._newUniforms.push(name);
return this;
};
/**
* Adds a custom attribute
* @param name the name of the attribute
* @returns the current material
*/
CustomMaterial.prototype.AddAttribute = function (name) {
if (!this._customAttributes) {
this._customAttributes = [];
}
this._customAttributes.push(name);
return this;
};
/**
* Sets the code on Fragment_Begin portion
* @param shaderPart the code string
* @returns the current material
*/
CustomMaterial.prototype.Fragment_Begin = function (shaderPart) {
this.CustomParts.Fragment_Begin = shaderPart;
return this;
};
/**
* Sets the code on Fragment_Definitions portion
* @param shaderPart the code string
* @returns the current material
*/
CustomMaterial.prototype.Fragment_Definitions = function (shaderPart) {
this.CustomParts.Fragment_Definitions = shaderPart;
return this;
};
/**
* Sets the code on Fragment_MainBegin portion
* @param shaderPart the code string
* @returns the current material
*/
CustomMaterial.prototype.Fragment_MainBegin = function (shaderPart) {
this.CustomParts.Fragment_MainBegin = shaderPart;
return this;
};
/**
* Sets the code on Fragment_MainEnd portion
* @param shaderPart the code string
* @returns the current material
*/
CustomMaterial.prototype.Fragment_MainEnd = function (shaderPart) {
this.CustomParts.Fragment_MainEnd = shaderPart;
return this;
};
/**
* Sets the code on Fragment_Custom_Diffuse portion
* @param shaderPart the code string
* @returns the current material
*/
CustomMaterial.prototype.Fragment_Custom_Diffuse = function (shaderPart) {
this.CustomParts.Fragment_Custom_Diffuse = shaderPart.replace("result", "diffuseColor");
return this;
};
/**
* Sets the code on Fragment_Custom_Alpha portion
* @param shaderPart the code string
* @returns the current material
*/
CustomMaterial.prototype.Fragment_Custom_Alpha = function (shaderPart) {
this.CustomParts.Fragment_Custom_Alpha = shaderPart.replace("result", "alpha");
return this;
};
/**
* Sets the code on Fragment_Before_Lights portion
* @param shaderPart the code string
* @returns the current material
*/
CustomMaterial.prototype.Fragment_Before_Lights = function (shaderPart) {
this.CustomParts.Fragment_Before_Lights = shaderPart;
return this;
};
/**
* Sets the code on Fragment_Before_Fog portion
* @param shaderPart the code string
* @returns the current material
*/
CustomMaterial.prototype.Fragment_Before_Fog = function (shaderPart) {
this.CustomParts.Fragment_Before_Fog = shaderPart;
return this;
};
/**
* Sets the code on Fragment_Before_FragColor portion
* @param shaderPart the code string
* @returns the current material
*/
CustomMaterial.prototype.Fragment_Before_FragColor = function (shaderPart) {
this.CustomParts.Fragment_Before_FragColor = shaderPart.replace("result", "color");
return this;
};
/**
* Sets the code on Vertex_Begin portion
* @param shaderPart the code string
* @returns the current material
*/
CustomMaterial.prototype.Vertex_Begin = function (shaderPart) {
this.CustomParts.Vertex_Begin = shaderPart;
return this;
};
/**
* Sets the code on Vertex_Definitions portion
* @param shaderPart the code string
* @returns the current material
*/
CustomMaterial.prototype.Vertex_Definitions = function (shaderPart) {
this.CustomParts.Vertex_Definitions = shaderPart;
return this;
};
/**
* Sets the code on Vertex_MainBegin portion
* @param shaderPart the code string
* @returns the current material
*/
CustomMaterial.prototype.Vertex_MainBegin = function (shaderPart) {
this.CustomParts.Vertex_MainBegin = shaderPart;
return this;
};
/**
* Sets the code on Vertex_Before_PositionUpdated portion
* @param shaderPart the code string
* @returns the current material
*/
CustomMaterial.prototype.Vertex_Before_PositionUpdated = function (shaderPart) {
this.CustomParts.Vertex_Before_PositionUpdated = shaderPart.replace("result", "positionUpdated");
return this;
};
/**
* Sets the code on Vertex_Before_NormalUpdated portion
* @param shaderPart the code string
* @returns the current material
*/
CustomMaterial.prototype.Vertex_Before_NormalUpdated = function (shaderPart) {
this.CustomParts.Vertex_Before_NormalUpdated = shaderPart.replace("result", "normalUpdated");
return this;
};
/**
* Sets the code on Vertex_After_WorldPosComputed portion
* @param shaderPart the code string
* @returns the current material
*/
CustomMaterial.prototype.Vertex_After_WorldPosComputed = function (shaderPart) {
this.CustomParts.Vertex_After_WorldPosComputed = shaderPart;
return this;
};
/**
* Sets the code on Vertex_MainEnd portion
* @param shaderPart the code string
* @returns the current material
*/
CustomMaterial.prototype.Vertex_MainEnd = function (shaderPart) {
this.CustomParts.Vertex_MainEnd = shaderPart;
return this;
};
/**
* Index for each created shader
*/
CustomMaterial.ShaderIndexer = 1;
return CustomMaterial;
}(babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__.StandardMaterial));
(0,babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__.RegisterClass)("BABYLON.CustomMaterial", CustomMaterial);
/***/ }),
/***/ "../../../dev/materials/src/custom/index.ts":
/*!**************************************************!*\
!*** ../../../dev/materials/src/custom/index.ts ***!
\**************************************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ CustomMaterial: () => (/* reexport safe */ _customMaterial__WEBPACK_IMPORTED_MODULE_0__.CustomMaterial),
/* harmony export */ CustomShaderStructure: () => (/* reexport safe */ _customMaterial__WEBPACK_IMPORTED_MODULE_0__.CustomShaderStructure),
/* harmony export */ PBRCustomMaterial: () => (/* reexport safe */ _pbrCustomMaterial__WEBPACK_IMPORTED_MODULE_1__.PBRCustomMaterial),
/* harmony export */ ShaderAlbedoParts: () => (/* reexport safe */ _pbrCustomMaterial__WEBPACK_IMPORTED_MODULE_1__.ShaderAlbedoParts),
/* harmony export */ ShaderAlebdoParts: () => (/* reexport safe */ _pbrCustomMaterial__WEBPACK_IMPORTED_MODULE_1__.ShaderAlebdoParts),
/* harmony export */ ShaderSpecialParts: () => (/* reexport safe */ _customMaterial__WEBPACK_IMPORTED_MODULE_0__.ShaderSpecialParts)
/* harmony export */ });
/* harmony import */ var _customMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./customMaterial */ "../../../dev/materials/src/custom/customMaterial.ts");
/* harmony import */ var _pbrCustomMaterial__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./pbrCustomMaterial */ "../../../dev/materials/src/custom/pbrCustomMaterial.ts");
/***/ }),
/***/ "../../../dev/materials/src/custom/pbrCustomMaterial.ts":
/*!**************************************************************!*\
!*** ../../../dev/materials/src/custom/pbrCustomMaterial.ts ***!
\**************************************************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ PBRCustomMaterial: () => (/* binding */ PBRCustomMaterial),
/* harmony export */ ShaderAlbedoParts: () => (/* binding */ ShaderAlbedoParts),
/* harmony export */ ShaderAlebdoParts: () => (/* binding */ ShaderAlebdoParts)
/* harmony export */ });
/* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! tslib */ "../../../../node_modules/tslib/tslib.es6.mjs");
/* harmony import */ var babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.color */ "babylonjs/Materials/effect");
/* harmony import */ var babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__);
/**
* Albedo parts of the shader
*/
var ShaderAlbedoParts = /** @class */ (function () {
function ShaderAlbedoParts() {
}
return ShaderAlbedoParts;
}());
/**
* @deprecated use ShaderAlbedoParts instead.
*/
var ShaderAlebdoParts = ShaderAlbedoParts;
var PBRCustomMaterial = /** @class */ (function (_super) {
(0,tslib__WEBPACK_IMPORTED_MODULE_1__.__extends)(PBRCustomMaterial, _super);
function PBRCustomMaterial(name, scene) {
var _this = _super.call(this, name, scene) || this;
_this.CustomParts = new ShaderAlbedoParts();
_this.customShaderNameResolve = _this.Builder;
_this.FragmentShader = babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__.Effect.ShadersStore["pbrPixelShader"];
_this.VertexShader = babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__.Effect.ShadersStore["pbrVertexShader"];
_this.FragmentShader = _this.FragmentShader.replace(/#include<pbrBlockAlbedoOpacity>/g, babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__.Effect.IncludesShadersStore["pbrBlockAlbedoOpacity"]);
_this.FragmentShader = _this.FragmentShader.replace(/#include<pbrBlockReflectivity>/g, babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__.Effect.IncludesShadersStore["pbrBlockReflectivity"]);
_this.FragmentShader = _this.FragmentShader.replace(/#include<pbrBlockFinalColorComposition>/g, babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__.Effect.IncludesShadersStore["pbrBlockFinalColorComposition"]);
PBRCustomMaterial.ShaderIndexer++;
_this._createdShaderName = "custompbr_" + PBRCustomMaterial.ShaderIndexer;
return _this;
}
/**
* Runs after the material is bound to a mesh
* @param mesh mesh bound
* @param effect bound effect used to render
*/
PBRCustomMaterial.prototype.AttachAfterBind = function (mesh, effect) {
if (this._newUniformInstances) {
for (var el in this._newUniformInstances) {
var ea = el.toString().split("-");
if (ea[0] == "vec2") {
effect.setVector2(ea[1], this._newUniformInstances[el]);
}
else if (ea[0] == "vec3") {
if (this._newUniformInstances[el] instanceof babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__.Color3) {
effect.setColor3(ea[1], this._newUniformInstances[el]);
}
else {
effect.setVector3(ea[1], this._newUniformInstances[el]);
}
}
else if (ea[0] == "vec4") {
if (this._newUniformInstances[el] instanceof babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__.Color4) {
effect.setDirectColor4(ea[1], this._newUniformInstances[el]);
}
else {
effect.setVector4(ea[1], this._newUniformInstances[el]);
}
effect.setVector4(ea[1], this._newUniformInstances[el]);
}
else if (ea[0] == "mat4") {
effect.setMatrix(ea[1], this._newUniformInstances[el]);
}
else if (ea[0] == "float") {
effect.setFloat(ea[1], this._newUniformInstances[el]);
}
}
}
if (this._newSamplerInstances) {
for (var el in this._newSamplerInstances) {
var ea = el.toString().split("-");
if (ea[0] == "sampler2D" && this._newSamplerInstances[el].isReady && this._newSamplerInstances[el].isReady()) {
effect.setTexture(ea[1], this._newSamplerInstances[el]);
}
}
}
};
/**
* @internal
*/
PBRCustomMaterial.prototype.ReviewUniform = function (name, arr) {
if (name == "uniform" && this._newUniforms) {
for (var ind = 0; ind < this._newUniforms.length; ind++) {
if (this._customUniform[ind].indexOf("sampler") == -1) {
arr.push(this._newUniforms[ind].replace(/\[\d*\]/g, ""));
}
}
}
if (name == "sampler" && this._newUniforms) {
for (var ind = 0; ind < this._newUniforms.length; ind++) {
if (this._customUniform[ind].indexOf("sampler") != -1) {
arr.push(this._newUniforms[ind].replace(/\[\d*\]/g, ""));
}
}
}
return arr;
};
/**
* Builds the material
* @param shaderName name of the shader
* @param uniforms list of uniforms
* @param uniformBuffers list of uniform buffers
* @param samplers list of samplers
* @param defines list of defines
* @param attributes list of attributes
* @param options options to compile the shader
* @returns the shader name
*/
PBRCustomMaterial.prototype.Builder = function (shaderName, uniforms, uniformBuffers, samplers, defines, attributes, options) {
if (options) {
var currentProcessing_1 = options.processFinalCode;
options.processFinalCode = function (type, code) {
if (type === "vertex") {
return currentProcessing_1 ? currentProcessing_1(type, code) : code;
}
var sci = new babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__.ShaderCodeInliner(code);
sci.inlineToken = "#define pbr_inline";
sci.processCode();
return currentProcessing_1 ? currentProcessing_1(type, sci.code) : sci.code;
};
}
if (attributes && this._customAttributes && this._customAttributes.length > 0) {
attributes.push.apply(attributes, this._customAttributes);
}
this.ReviewUniform("uniform", uniforms);
this.ReviewUniform("sampler", samplers);
var name = this._createdShaderName;
if (babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__.Effect.ShadersStore[name + "VertexShader"] && babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__.Effect.ShadersStore[name + "PixelShader"]) {
return name;
}
babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__.Effect.ShadersStore[name + "VertexShader"] = this._injectCustomCode(this.VertexShader, "vertex");
babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__.Effect.ShadersStore[name + "PixelShader"] = this._injectCustomCode(this.FragmentShader, "fragment");
return name;
};
PBRCustomMaterial.prototype._injectCustomCode = function (code, shaderType) {
var customCode = this._getCustomCode(shaderType);
for (var point in customCode) {
var injectedCode = customCode[point];
if (injectedCode && injectedCode.length > 0) {
var fullPointName = "#define " + point;
code = code.replace(fullPointName, "\n" + injectedCode + "\n" + fullPointName);
}
}
return code;
};
PBRCustomMaterial.prototype._getCustomCode = function (shaderType) {
var _a, _b;
if (shaderType === "vertex") {
return {
CUSTOM_VERTEX_BEGIN: this.CustomParts.Vertex_Begin,
CUSTOM_VERTEX_DEFINITIONS: (((_a = this._customUniform) === null || _a === void 0 ? void 0 : _a.join("\n")) || "") + (this.CustomParts.Vertex_Definitions || ""),
CUSTOM_VERTEX_MAIN_BEGIN: this.CustomParts.Vertex_MainBegin,
CUSTOM_VERTEX_UPDATE_POSITION: this.CustomParts.Vertex_Before_PositionUpdated,
CUSTOM_VERTEX_UPDATE_NORMAL: this.CustomParts.Vertex_Before_NormalUpdated,
CUSTOM_VERTEX_MAIN_END: this.CustomParts.Vertex_MainEnd,
CUSTOM_VERTEX_UPDATE_WORLDPOS: this.CustomParts.Vertex_After_WorldPosComputed,
};
}
return {
CUSTOM_FRAGMENT_BEGIN: this.CustomParts.Fragment_Begin,
CUSTOM_FRAGMENT_MAIN_BEGIN: this.CustomParts.Fragment_MainBegin,
CUSTOM_FRAGMENT_DEFINITIONS: (((_b = this._customUniform) === null || _b === void 0 ? void 0 : _b.join("\n")) || "") + (this.CustomParts.Fragment_Definitions || ""),
CUSTOM_FRAGMENT_UPDATE_ALBEDO: this.CustomParts.Fragment_Custom_Albedo,
CUSTOM_FRAGMENT_UPDATE_ALPHA: this.CustomParts.Fragment_Custom_Alpha,
CUSTOM_FRAGMENT_BEFORE_LIGHTS: this.CustomParts.Fragment_Before_Lights,
CUSTOM_FRAGMENT_UPDATE_METALLICROUGHNESS: this.CustomParts.Fragment_Custom_MetallicRoughness,
CUSTOM_FRAGMENT_UPDATE_MICROSURFACE: this.CustomParts.Fragment_Custom_MicroSurface,
CUSTOM_FRAGMENT_BEFORE_FINALCOLORCOMPOSITION: this.CustomParts.Fragment_Before_FinalColorComposition,
CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR: this.CustomParts.Fragment_Before_FragColor,
CUSTOM_FRAGMENT_MAIN_END: this.CustomParts.Fragment_MainEnd,
CUSTOM_FRAGMENT_BEFORE_FOG: this.CustomParts.Fragment_Before_Fog,
};
};
PBRCustomMaterial.prototype._afterBind = function (mesh, effect, subMesh) {
if (effect === void 0) { effect = null; }
if (!effect) {
return;
}
this.AttachAfterBind(mesh, effect);
try {
_super.prototype._afterBind.call(this, mesh, effect, subMesh);
}
catch (e) { }
};
/**
* Adds a new uniform to the shader
* @param name the name of the uniform to add
* @param kind the type of the uniform to add
* @param param the value of the uniform to add
* @returns the current material
*/
PBRCustomMaterial.prototype.AddUniform = function (name, kind, param) {
if (!this._customUniform) {
this._customUniform = new Array();
this._newUniforms = new Array();
this._newSamplerInstances = {};
this._newUniformInstances = {};
}
if (param) {
if (kind.indexOf("sampler") != -1) {
this._newSamplerInstances[kind + "-" + name] = param;
}
else {
this._newUniformInstances[kind + "-" + name] = param;
}
}
this._customUniform.push("uniform " + kind + " " + name + ";");
this._newUniforms.push(name);
return this;
};
/**
* Adds a custom attribute
* @param name the name of the attribute
* @returns the current material
*/
PBRCustomMaterial.prototype.AddAttribute = function (name) {
if (!this._customAttributes) {
this._customAttributes = [];
}
this._customAttributes.push(name);
return this;
};
/**
* Sets the code on Fragment_Begin portion
* @param shaderPart the code string
* @returns the current material
*/
PBRCustomMaterial.prototype.Fragment_Begin = function (shaderPart) {
this.CustomParts.Fragment_Begin = shaderPart;
return this;
};
/**
* Sets the code on Fragment_Definitions portion
* @param shaderPart the code string
* @returns the current material
*/
PBRCustomMaterial.prototype.Fragment_Definitions = function (shaderPart) {
this.CustomParts.Fragment_Definitions = shaderPart;
return this;
};
/**
* Sets the code on Fragment_MainBegin portion
* @param shaderPart the code string
* @returns the current material
*/
PBRCustomMaterial.prototype.Fragment_MainBegin = function (shaderPart) {
this.CustomParts.Fragment_MainBegin = shaderPart;
return this;
};
/**
* Sets the code on Fragment_Custom_Albedo portion
* @param shaderPart the code string
* @returns the current material
*/
PBRCustomMaterial.prototype.Fragment_Custom_Albedo = function (shaderPart) {
this.CustomParts.Fragment_Custom_Albedo = shaderPart.replace("result", "surfaceAlbedo");
return this;
};
/**
* Sets the code on Fragment_Custom_Alpha portion
* @param shaderPart the code string
* @returns the current material
*/
PBRCustomMaterial.prototype.Fragment_Custom_Alpha = function (shaderPart) {
this.CustomParts.Fragment_Custom_Alpha = shaderPart.replace("result", "alpha");
return this;
};
/**
* Sets the code on Fragment_Before_Lights portion
* @param shaderPart the code string
* @returns the current material
*/
PBRCustomMaterial.prototype.Fragment_Before_Lights = function (shaderPart) {
this.CustomParts.Fragment_Before_Lights = shaderPart;
return this;
};
/**
* Sets the code on Fragment_Custom_MetallicRoughness portion
* @param shaderPart the code string
* @returns the current material
*/
PBRCustomMaterial.prototype.Fragment_Custom_MetallicRoughness = function (shaderPart) {
this.CustomParts.Fragment_Custom_MetallicRoughness = shaderPart;
return this;
};
/**
* Sets the code on Fragment_Custom_MicroSurface portion
* @param shaderPart the code string
* @returns the current material
*/
PBRCustomMaterial.prototype.Fragment_Custom_MicroSurface = function (shaderPart) {
this.CustomParts.Fragment_Custom_MicroSurface = shaderPart;
return this;
};
/**
* Sets the code on Fragment_Before_Fog portion
* @param shaderPart the code string
* @returns the current material
*/
PBRCustomMaterial.prototype.Fragment_Before_Fog = function (shaderPart) {
this.CustomParts.Fragment_Before_Fog = shaderPart;
return this;
};
/**
* Sets the code on Fragment_Before_FinalColorComposition portion
* @param shaderPart the code string
* @returns the current material
*/
PBRCustomMaterial.prototype.Fragment_Before_FinalColorComposition = function (shaderPart) {
this.CustomParts.Fragment_Before_FinalColorComposition = shaderPart;
return this;
};
/**
* Sets the code on Fragment_Before_FragColor portion
* @param shaderPart the code string
* @returns the current material
*/
PBRCustomMaterial.prototype.Fragment_Before_FragColor = function (shaderPart) {
this.CustomParts.Fragment_Before_FragColor = shaderPart.replace("result", "color");
return this;
};
/**
* Sets the code on Fragment_MainEnd portion
* @param shaderPart the code string
* @returns the current material
*/
PBRCustomMaterial.prototype.Fragment_MainEnd = function (shaderPart) {
this.CustomParts.Fragment_MainEnd = shaderPart;
return this;
};
/**
* Sets the code on Vertex_Begin portion
* @param shaderPart the code string
* @returns the current material
*/
PBRCustomMaterial.prototype.Vertex_Begin = function (shaderPart) {
this.CustomParts.Vertex_Begin = shaderPart;
return this;
};
/**
* Sets the code on Vertex_Definitions portion
* @param shaderPart the code string
* @returns the current material
*/
PBRCustomMaterial.prototype.Vertex_Definitions = function (shaderPart) {
this.CustomParts.Vertex_Definitions = shaderPart;
return this;
};
/**
* Sets the code on Vertex_MainBegin portion
* @param shaderPart the code string
* @returns the current material
*/
PBRCustomMaterial.prototype.Vertex_MainBegin = function (shaderPart) {
this.CustomParts.Vertex_MainBegin = shaderPart;
return this;
};
/**
* Sets the code on Vertex_Before_PositionUpdated portion
* @param shaderPart the code string
* @returns the current material
*/
PBRCustomMaterial.prototype.Vertex_Before_PositionUpdated = function (shaderPart) {
this.CustomParts.Vertex_Before_PositionUpdated = shaderPart.replace("result", "positionUpdated");
return this;
};
/**
* Sets the code on Vertex_Before_NormalUpdated portion
* @param shaderPart the code string
* @returns the current material
*/
PBRCustomMaterial.prototype.Vertex_Before_NormalUpdated = function (shaderPart) {
this.CustomParts.Vertex_Before_NormalUpdated = shaderPart.replace("result", "normalUpdated");
return this;
};
/**
* Sets the code on Vertex_After_WorldPosComputed portion
* @param shaderPart the code string
* @returns the current material
*/
PBRCustomMaterial.prototype.Vertex_After_WorldPosComputed = function (shaderPart) {
this.CustomParts.Vertex_After_WorldPosComputed = shaderPart;
return this;
};
/**
* Sets the code on Vertex_MainEnd portion
* @param shaderPart the code string
* @returns the current material
*/
PBRCustomMaterial.prototype.Vertex_MainEnd = function (shaderPart) {
this.CustomParts.Vertex_MainEnd = shaderPart;
return this;
};
/**
* Index for each created shader
*/
PBRCustomMaterial.ShaderIndexer = 1;
return PBRCustomMaterial;
}(babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__.PBRMaterial));
(0,babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__.RegisterClass)("BABYLON.PBRCustomMaterial", PBRCustomMaterial);
/***/ }),
/***/ "../../../lts/materials/src/legacy/legacy-custom.ts":
/*!**********************************************************!*\
!*** ../../../lts/materials/src/legacy/legacy-custom.ts ***!
\**********************************************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ CustomMaterial: () => (/* reexport safe */ materials_custom_index__WEBPACK_IMPORTED_MODULE_0__.CustomMaterial),
/* harmony export */ CustomShaderStructure: () => (/* reexport safe */ materials_custom_index__WEBPACK_IMPORTED_MODULE_0__.CustomShaderStructure),
/* harmony export */ PBRCustomMaterial: () => (/* reexport safe */ materials_custom_index__WEBPACK_IMPORTED_MODULE_0__.PBRCustomMaterial),
/* harmony export */ ShaderAlbedoParts: () => (/* reexport safe */ materials_custom_index__WEBPACK_IMPORTED_MODULE_0__.ShaderAlbedoParts),
/* harmony export */ ShaderAlebdoParts: () => (/* reexport safe */ materials_custom_index__WEBPACK_IMPORTED_MODULE_0__.ShaderAlebdoParts),
/* harmony export */ ShaderSpecialParts: () => (/* reexport safe */ materials_custom_index__WEBPACK_IMPORTED_MODULE_0__.ShaderSpecialParts)
/* harmony export */ });
/* harmony import */ var materials_custom_index__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! materials/custom/index */ "../../../dev/materials/src/custom/index.ts");
/* eslint-disable import/no-internal-modules */
/**
* This is the entry point for the UMD module.
* The entry point for a future ESM package should be index.ts
*/
var globalObject = typeof __webpack_require__.g !== "undefined" ? __webpack_require__.g : typeof window !== "undefined" ? window : undefined;
if (typeof globalObject !== "undefined") {
for (var key in materials_custom_index__WEBPACK_IMPORTED_MODULE_0__) {
globalObject.BABYLON[key] = materials_custom_index__WEBPACK_IMPORTED_MODULE_0__[key];
}
}
/***/ }),
/***/ "babylonjs/Materials/effect":
/*!****************************************************************************************************!*\
!*** external {"root":"BABYLON","commonjs":"babylonjs","commonjs2":"babylonjs","amd":"babylonjs"} ***!
\****************************************************************************************************/
/***/ ((module) => {
module.exports = __WEBPACK_EXTERNAL_MODULE_babylonjs_Materials_effect__;
/***/ }),
/***/ "../../../../node_modules/tslib/tslib.es6.mjs":
/*!****************************************************!*\
!*** ../../../../node_modules/tslib/tslib.es6.mjs ***!
\****************************************************/
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ __addDisposableResource: () => (/* binding */ __addDisposableResource),
/* harmony export */ __assign: () => (/* binding */ __assign),
/* harmony export */ __asyncDelegator: () => (/* binding */ __asyncDelegator),
/* harmony export */ __asyncGenerator: () => (/* binding */ __asyncGenerator),
/* harmony export */ __asyncValues: () => (/* binding */ __asyncValues),
/* harmony export */ __await: () => (/* binding */ __await),
/* harmony export */ __awaiter: () => (/* binding */ __awaiter),
/* harmony export */ __classPrivateFieldGet: () => (/* binding */ __classPrivateFieldGet),
/* harmony export */ __classPrivateFieldIn: () => (/* binding */ __classPrivateFieldIn),
/* harmony export */ __classPrivateFieldSet: () => (/* binding */ __classPrivateFieldSet),
/* harmony export */ __createBinding: () => (/* binding */ __createBinding),
/* harmony export */ __decorate: () => (/* binding */ __decorate),
/* harmony export */ __disposeResources: () => (/* binding */ __disposeResources),
/* harmony export */ __esDecorate: () => (/* binding */ __esDecorate),
/* harmony export */ __exportStar: () => (/* binding */ __exportStar),
/* harmony export */ __extends: () => (/* binding */ __extends),
/* harmony export */ __generator: () => (/* binding */ __generator),
/* harmony export */ __importDefault: () => (/* binding */ __importDefault),
/* harmony export */ __importStar: () => (/* binding */ __importStar),
/* harmony export */ __makeTemplateObject: () => (/* binding */ __makeTemplateObject),
/* harmony export */ __metadata: () => (/* binding */ __metadata),
/* harmony export */ __param: () => (/* binding */ __param),
/* harmony export */ __propKey: () => (/* binding */ __propKey),
/* harmony export */ __read: () => (/* binding */ __read),
/* harmony export */ __rest: () => (/* binding */ __rest),
/* harmony export */ __runInitializers: () => (/* binding */ __runInitializers),
/* harmony export */ __setFunctionName: () => (/* binding */ __setFunctionName),
/* harmony export */ __spread: () => (/* binding */ __spread),
/* harmony export */ __spreadArray: () => (/* binding */ __spreadArray),
/* harmony export */ __spreadArrays: () => (/* binding */ __spreadArrays),
/* harmony export */ __values: () => (/* binding */ __values),
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
/* harmony export */ });
/******************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
/* global Reflect, Promise, SuppressedError, Symbol */
var extendStatics = function(d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
function __extends(d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
var __assign = function() {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
return t;
}
return __assign.apply(this, arguments);
}
function __rest(s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
}
function __decorate(decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
}
function __param(paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
}
function __esDecorate(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
var _, done = false;
for (var i = decorators.length - 1; i >= 0; i--) {
var context = {};
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
if (kind === "accessor") {
if (result === void 0) continue;
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
if (_ = accept(result.get)) descriptor.get = _;
if (_ = accept(result.set)) descriptor.set = _;
if (_ = accept(result.init)) initializers.unshift(_);
}
else if (_ = accept(result)) {
if (kind === "field") initializers.unshift(_);
else descriptor[key] = _;
}
}
if (target) Object.defineProperty(target, contextIn.name, descriptor);
done = true;
};
function __runInitializers(thisArg, initializers, value) {
var useValue = arguments.length > 2;
for (var i = 0; i < initializers.length; i++) {
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
}
return useValue ? value : void 0;
};
function __propKey(x) {
return typeof x === "symbol" ? x : "".concat(x);
};
function __setFunctionName(f, name, prefix) {
if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
};
function __metadata(metadataKey, metadataValue) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
}
function __awaiter(thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function __generator(thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
}