@babylonjs/materials 6.38.0 → 6.39.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -93,11 +93,10 @@ export class CustomMaterial extends StandardMaterial {
93
93
  return code;
94
94
  }
95
95
  _getCustomCode(shaderType) {
96
- var _a, _b;
97
96
  if (shaderType === "vertex") {
98
97
  return {
99
98
  CUSTOM_VERTEX_BEGIN: this.CustomParts.Vertex_Begin,
100
- CUSTOM_VERTEX_DEFINITIONS: (((_a = this._customUniform) === null || _a === void 0 ? void 0 : _a.join("\n")) || "") + (this.CustomParts.Vertex_Definitions || ""),
99
+ CUSTOM_VERTEX_DEFINITIONS: (this._customUniform?.join("\n") || "") + (this.CustomParts.Vertex_Definitions || ""),
101
100
  CUSTOM_VERTEX_MAIN_BEGIN: this.CustomParts.Vertex_MainBegin,
102
101
  CUSTOM_VERTEX_UPDATE_POSITION: this.CustomParts.Vertex_Before_PositionUpdated,
103
102
  CUSTOM_VERTEX_UPDATE_NORMAL: this.CustomParts.Vertex_Before_NormalUpdated,
@@ -107,7 +106,7 @@ export class CustomMaterial extends StandardMaterial {
107
106
  }
108
107
  return {
109
108
  CUSTOM_FRAGMENT_BEGIN: this.CustomParts.Fragment_Begin,
110
- CUSTOM_FRAGMENT_DEFINITIONS: (((_b = this._customUniform) === null || _b === void 0 ? void 0 : _b.join("\n")) || "") + (this.CustomParts.Fragment_Definitions || ""),
109
+ CUSTOM_FRAGMENT_DEFINITIONS: (this._customUniform?.join("\n") || "") + (this.CustomParts.Fragment_Definitions || ""),
111
110
  CUSTOM_FRAGMENT_MAIN_BEGIN: this.CustomParts.Fragment_MainBegin,
112
111
  CUSTOM_FRAGMENT_UPDATE_DIFFUSE: this.CustomParts.Fragment_Custom_Diffuse,
113
112
  CUSTOM_FRAGMENT_UPDATE_ALPHA: this.CustomParts.Fragment_Custom_Alpha,
@@ -1 +1 @@
1
- {"version":3,"file":"customMaterial.js","sourceRoot":"","sources":["../../../../dev/materials/src/custom/customMaterial.ts"],"names":[],"mappings":"AAEA,OAA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,cAAc,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { Texture } from \"core/Materials/Textures/texture\";\r\nimport { Effect } from \"core/Materials/effect\";\r\nimport type { MaterialDefines } from \"core/Materials/materialDefines\";\r\nimport { StandardMaterial } from \"core/Materials/standardMaterial\";\r\nimport type { Mesh } from \"core/Meshes/mesh\";\r\nimport type { Scene } from \"core/scene\";\r\nimport { RegisterClass } from \"core/Misc/typeStore\";\r\nimport { Color3, Color4 } from \"core/Maths/math.color\";\r\nimport type { Nullable } from \"core/types\";\r\n\r\nexport class CustomShaderStructure {\r\n public FragmentStore: string;\r\n public VertexStore: string;\r\n\r\n constructor() {}\r\n}\r\n\r\nexport class ShaderSpecialParts {\r\n constructor() {}\r\n\r\n public Fragment_Begin: string;\r\n public Fragment_Definitions: string;\r\n public Fragment_MainBegin: string;\r\n public Fragment_MainEnd: string;\r\n\r\n // diffuseColor\r\n public Fragment_Custom_Diffuse: string;\r\n // lights\r\n public Fragment_Before_Lights: string;\r\n // fog\r\n public Fragment_Before_Fog: string;\r\n // alpha\r\n public Fragment_Custom_Alpha: string;\r\n\r\n public Fragment_Before_FragColor: string;\r\n\r\n public Vertex_Begin: string;\r\n public Vertex_Definitions: string;\r\n public Vertex_MainBegin: string;\r\n\r\n // positionUpdated\r\n public Vertex_Before_PositionUpdated: string;\r\n\r\n // normalUpdated\r\n public Vertex_Before_NormalUpdated: string;\r\n\r\n // worldPosComputed\r\n public Vertex_After_WorldPosComputed: string;\r\n\r\n // mainEnd\r\n public Vertex_MainEnd: string;\r\n}\r\n\r\nexport class CustomMaterial extends StandardMaterial {\r\n public static ShaderIndexer = 1;\r\n public CustomParts: ShaderSpecialParts;\r\n _createdShaderName: string;\r\n _customUniform: string[];\r\n _newUniforms: string[];\r\n _newUniformInstances: { [name: string]: any };\r\n _newSamplerInstances: { [name: string]: Texture };\r\n _customAttributes: string[];\r\n\r\n public FragmentShader: string;\r\n public VertexShader: string;\r\n\r\n public AttachAfterBind(mesh: Mesh | undefined, effect: Effect) {\r\n if (this._newUniformInstances) {\r\n for (const el in this._newUniformInstances) {\r\n const ea = el.toString().split(\"-\");\r\n if (ea[0] == \"vec2\") {\r\n effect.setVector2(ea[1], this._newUniformInstances[el]);\r\n } else if (ea[0] == \"vec3\") {\r\n if (this._newUniformInstances[el] instanceof Color3) {\r\n effect.setColor3(ea[1], this._newUniformInstances[el]);\r\n } else {\r\n effect.setVector3(ea[1], this._newUniformInstances[el]);\r\n }\r\n } else if (ea[0] == \"vec4\") {\r\n if (this._newUniformInstances[el] instanceof Color4) {\r\n effect.setDirectColor4(ea[1], this._newUniformInstances[el]);\r\n } else {\r\n effect.setVector4(ea[1], this._newUniformInstances[el]);\r\n }\r\n effect.setVector4(ea[1], this._newUniformInstances[el]);\r\n } else if (ea[0] == \"mat4\") {\r\n effect.setMatrix(ea[1], this._newUniformInstances[el]);\r\n } else if (ea[0] == \"float\") {\r\n effect.setFloat(ea[1], this._newUniformInstances[el]);\r\n }\r\n }\r\n }\r\n if (this._newSamplerInstances) {\r\n for (const el in this._newSamplerInstances) {\r\n const ea = el.toString().split(\"-\");\r\n if (ea[0] == \"sampler2D\" && this._newSamplerInstances[el].isReady && this._newSamplerInstances[el].isReady()) {\r\n effect.setTexture(ea[1], this._newSamplerInstances[el]);\r\n }\r\n }\r\n }\r\n }\r\n\r\n public ReviewUniform(name: string, arr: string[]): string[] {\r\n if (name == \"uniform\" && this._newUniforms) {\r\n for (let ind = 0; ind < this._newUniforms.length; ind++) {\r\n if (this._customUniform[ind].indexOf(\"sampler\") == -1) {\r\n arr.push(this._newUniforms[ind].replace(/\\[\\d*\\]/g, \"\"));\r\n }\r\n }\r\n }\r\n if (name == \"sampler\" && this._newUniforms) {\r\n for (let ind = 0; ind < this._newUniforms.length; ind++) {\r\n if (this._customUniform[ind].indexOf(\"sampler\") != -1) {\r\n arr.push(this._newUniforms[ind].replace(/\\[\\d*\\]/g, \"\"));\r\n }\r\n }\r\n }\r\n return arr;\r\n }\r\n\r\n public Builder(shaderName: string, uniforms: string[], uniformBuffers: string[], samplers: string[], defines: MaterialDefines | string[], attributes?: string[]): string {\r\n if (attributes && this._customAttributes && this._customAttributes.length > 0) {\r\n attributes.push(...this._customAttributes);\r\n }\r\n\r\n this.ReviewUniform(\"uniform\", uniforms);\r\n this.ReviewUniform(\"sampler\", samplers);\r\n\r\n const name = this._createdShaderName;\r\n\r\n if (Effect.ShadersStore[name + \"VertexShader\"] && Effect.ShadersStore[name + \"PixelShader\"]) {\r\n return name;\r\n }\r\n Effect.ShadersStore[name + \"VertexShader\"] = this._injectCustomCode(this.VertexShader, \"vertex\");\r\n Effect.ShadersStore[name + \"PixelShader\"] = this._injectCustomCode(this.FragmentShader, \"fragment\");\r\n\r\n return name;\r\n }\r\n\r\n protected _injectCustomCode(code: string, shaderType: string): string {\r\n const customCode = this._getCustomCode(shaderType);\r\n\r\n for (const point in customCode) {\r\n const injectedCode = customCode[point];\r\n\r\n if (injectedCode && injectedCode.length > 0) {\r\n const fullPointName = \"#define \" + point;\r\n code = code.replace(fullPointName, \"\\n\" + injectedCode + \"\\n\" + fullPointName);\r\n }\r\n }\r\n\r\n return code;\r\n }\r\n\r\n protected _getCustomCode(shaderType: string): { [pointName: string]: string } {\r\n if (shaderType === \"vertex\") {\r\n return {\r\n CUSTOM_VERTEX_BEGIN: this.CustomParts.Vertex_Begin,\r\n CUSTOM_VERTEX_DEFINITIONS: (this._customUniform?.join(\"\\n\") || \"\") + (this.CustomParts.Vertex_Definitions || \"\"),\r\n CUSTOM_VERTEX_MAIN_BEGIN: this.CustomParts.Vertex_MainBegin,\r\n CUSTOM_VERTEX_UPDATE_POSITION: this.CustomParts.Vertex_Before_PositionUpdated,\r\n CUSTOM_VERTEX_UPDATE_NORMAL: this.CustomParts.Vertex_Before_NormalUpdated,\r\n CUSTOM_VERTEX_MAIN_END: this.CustomParts.Vertex_MainEnd,\r\n CUSTOM_VERTEX_UPDATE_WORLDPOS: this.CustomParts.Vertex_After_WorldPosComputed,\r\n };\r\n }\r\n return {\r\n CUSTOM_FRAGMENT_BEGIN: this.CustomParts.Fragment_Begin,\r\n CUSTOM_FRAGMENT_DEFINITIONS: (this._customUniform?.join(\"\\n\") || \"\") + (this.CustomParts.Fragment_Definitions || \"\"),\r\n CUSTOM_FRAGMENT_MAIN_BEGIN: this.CustomParts.Fragment_MainBegin,\r\n CUSTOM_FRAGMENT_UPDATE_DIFFUSE: this.CustomParts.Fragment_Custom_Diffuse,\r\n CUSTOM_FRAGMENT_UPDATE_ALPHA: this.CustomParts.Fragment_Custom_Alpha,\r\n CUSTOM_FRAGMENT_BEFORE_LIGHTS: this.CustomParts.Fragment_Before_Lights,\r\n CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR: this.CustomParts.Fragment_Before_FragColor,\r\n CUSTOM_FRAGMENT_MAIN_END: this.CustomParts.Fragment_MainEnd,\r\n CUSTOM_FRAGMENT_BEFORE_FOG: this.CustomParts.Fragment_Before_Fog,\r\n };\r\n }\r\n\r\n constructor(name: string, scene?: Scene) {\r\n super(name, scene);\r\n this.CustomParts = new ShaderSpecialParts();\r\n this.customShaderNameResolve = this.Builder;\r\n\r\n this.FragmentShader = Effect.ShadersStore[\"defaultPixelShader\"];\r\n this.VertexShader = Effect.ShadersStore[\"defaultVertexShader\"];\r\n\r\n CustomMaterial.ShaderIndexer++;\r\n this._createdShaderName = \"custom_\" + CustomMaterial.ShaderIndexer;\r\n }\r\n\r\n protected _afterBind(mesh?: Mesh, effect: Nullable<Effect> = null): void {\r\n if (!effect) {\r\n return;\r\n }\r\n this.AttachAfterBind(mesh, effect);\r\n try {\r\n super._afterBind(mesh, effect);\r\n } catch (e) {}\r\n }\r\n\r\n public AddUniform(name: string, kind: string, param: any): CustomMaterial {\r\n if (!this._customUniform) {\r\n this._customUniform = new Array();\r\n this._newUniforms = new Array();\r\n this._newSamplerInstances = {};\r\n this._newUniformInstances = {};\r\n }\r\n if (param) {\r\n if (kind.indexOf(\"sampler\") != -1) {\r\n (<any>this._newSamplerInstances)[kind + \"-\" + name] = param;\r\n } else {\r\n (<any>this._newUniformInstances)[kind + \"-\" + name] = param;\r\n }\r\n }\r\n this._customUniform.push(\"uniform \" + kind + \" \" + name + \";\");\r\n this._newUniforms.push(name);\r\n\r\n return this;\r\n }\r\n\r\n public AddAttribute(name: string): CustomMaterial {\r\n if (!this._customAttributes) {\r\n this._customAttributes = [];\r\n }\r\n\r\n this._customAttributes.push(name);\r\n\r\n return this;\r\n }\r\n\r\n public Fragment_Begin(shaderPart: string): CustomMaterial {\r\n this.CustomParts.Fragment_Begin = shaderPart;\r\n return this;\r\n }\r\n\r\n public Fragment_Definitions(shaderPart: string): CustomMaterial {\r\n this.CustomParts.Fragment_Definitions = shaderPart;\r\n return this;\r\n }\r\n\r\n public Fragment_MainBegin(shaderPart: string): CustomMaterial {\r\n this.CustomParts.Fragment_MainBegin = shaderPart;\r\n return this;\r\n }\r\n\r\n public Fragment_MainEnd(shaderPart: string): CustomMaterial {\r\n this.CustomParts.Fragment_MainEnd = shaderPart;\r\n return this;\r\n }\r\n\r\n public Fragment_Custom_Diffuse(shaderPart: string): CustomMaterial {\r\n this.CustomParts.Fragment_Custom_Diffuse = shaderPart.replace(\"result\", \"diffuseColor\");\r\n return this;\r\n }\r\n\r\n public Fragment_Custom_Alpha(shaderPart: string): CustomMaterial {\r\n this.CustomParts.Fragment_Custom_Alpha = shaderPart.replace(\"result\", \"alpha\");\r\n return this;\r\n }\r\n\r\n public Fragment_Before_Lights(shaderPart: string): CustomMaterial {\r\n this.CustomParts.Fragment_Before_Lights = shaderPart;\r\n return this;\r\n }\r\n\r\n public Fragment_Before_Fog(shaderPart: string): CustomMaterial {\r\n this.CustomParts.Fragment_Before_Fog = shaderPart;\r\n return this;\r\n }\r\n\r\n public Fragment_Before_FragColor(shaderPart: string): CustomMaterial {\r\n this.CustomParts.Fragment_Before_FragColor = shaderPart.replace(\"result\", \"color\");\r\n return this;\r\n }\r\n\r\n public Vertex_Begin(shaderPart: string): CustomMaterial {\r\n this.CustomParts.Vertex_Begin = shaderPart;\r\n return this;\r\n }\r\n\r\n public Vertex_Definitions(shaderPart: string): CustomMaterial {\r\n this.CustomParts.Vertex_Definitions = shaderPart;\r\n return this;\r\n }\r\n\r\n public Vertex_MainBegin(shaderPart: string): CustomMaterial {\r\n this.CustomParts.Vertex_MainBegin = shaderPart;\r\n return this;\r\n }\r\n\r\n public Vertex_Before_PositionUpdated(shaderPart: string): CustomMaterial {\r\n this.CustomParts.Vertex_Before_PositionUpdated = shaderPart.replace(\"result\", \"positionUpdated\");\r\n return this;\r\n }\r\n\r\n public Vertex_Before_NormalUpdated(shaderPart: string): CustomMaterial {\r\n this.CustomParts.Vertex_Before_NormalUpdated = shaderPart.replace(\"result\", \"normalUpdated\");\r\n return this;\r\n }\r\n\r\n public Vertex_After_WorldPosComputed(shaderPart: string): CustomMaterial {\r\n this.CustomParts.Vertex_After_WorldPosComputed = shaderPart;\r\n return this;\r\n }\r\n\r\n public Vertex_MainEnd(shaderPart: string): CustomMaterial {\r\n this.CustomParts.Vertex_MainEnd = shaderPart;\r\n return this;\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.CustomMaterial\", CustomMaterial);\r\n"]}
1
+ {"version":3,"file":"customMaterial.js","sourceRoot":"","sources":["../../../../dev/materials/src/custom/customMaterial.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,4CAA8B;AAE/C,OAAO,EAAE,gBAAgB,EAAE,sDAAwC;AAGnE,OAAO,EAAE,aAAa,EAAE,0CAA4B;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,4CAA8B;AAGvD,MAAM,OAAO,qBAAqB;IAI9B,gBAAe,CAAC;CACnB;AAED,MAAM,OAAO,kBAAkB;IAC3B,gBAAe,CAAC;CAiCnB;AAED,MAAM,OAAO,cAAe,SAAQ,gBAAgB;IAazC,eAAe,CAAC,IAAsB,EAAE,MAAc;QACzD,IAAI,IAAI,C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CAAC,WAAW,CAAC,kBAAkB,GAAG,UAAU,CAAC;QACjD,OAAO,IAAI,CAAC;IAChB,CAAC;IAEM,gBAAgB,CAAC,UAAkB;QACtC,IAAI,CAAC,WAAW,CAAC,gBAAgB,GAAG,UAAU,CAAC;QAC/C,OAAO,IAAI,CAAC;IAChB,CAAC;IAEM,6BAA6B,CAAC,UAAkB;QACnD,IAAI,CAAC,WAAW,CAAC,6BAA6B,GAAG,UAAU,CAAC,OAAO,CAAC,QAAQ,EAAE,iBAAiB,CAAC,CAAC;QACjG,OAAO,IAAI,CAAC;IAChB,CAAC;IAEM,2BAA2B,CAAC,UAAkB;QACjD,IAAI,CAAC,WAAW,CAAC,2BAA2B,GAAG,UAAU,CAAC,OAAO,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC;QAC7F,OAAO,IAAI,CAAC;IAChB,CAAC;IAEM,6BAA6B,CAAC,UAAkB;QACnD,IAAI,CAAC,WAAW,CAAC,6BAA6B,GAAG,UAAU,CAAC;QAC5D,OAAO,IAAI,CAAC;IAChB,CAAC;IAEM,cAAc,CAAC,UAAkB;QACpC,IAAI,CAAC,WAAW,CAAC,cAAc,GAAG,UAAU,CAAC;QAC7C,OAAO,IAAI,CAAC;IAChB,CAAC;;AA/Pa,4BAAa,GAAG,CAAC,CAAC;AAkQpC,aAAa,CAAC,wBAAwB,EAAE,cAAc,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { Texture } from \"core/Materials/Textures/texture\";\r\nimport { Effect } from \"core/Materials/effect\";\r\nimport type { MaterialDefines } from \"core/Materials/materialDefines\";\r\nimport { StandardMaterial } from \"core/Materials/standardMaterial\";\r\nimport type { Mesh } from \"core/Meshes/mesh\";\r\nimport type { Scene } from \"core/scene\";\r\nimport { RegisterClass } from \"core/Misc/typeStore\";\r\nimport { Color3, Color4 } from \"core/Maths/math.color\";\r\nimport type { Nullable } from \"core/types\";\r\n\r\nexport class CustomShaderStructure {\r\n public FragmentStore: string;\r\n public VertexStore: string;\r\n\r\n constructor() {}\r\n}\r\n\r\nexport class ShaderSpecialParts {\r\n constructor() {}\r\n\r\n public Fragment_Begin: string;\r\n public Fragment_Definitions: string;\r\n public Fragment_MainBegin: string;\r\n public Fragment_MainEnd: string;\r\n\r\n // diffuseColor\r\n public Fragment_Custom_Diffuse: string;\r\n // lights\r\n public Fragment_Before_Lights: string;\r\n // fog\r\n public Fragment_Before_Fog: string;\r\n // alpha\r\n public Fragment_Custom_Alpha: string;\r\n\r\n public Fragment_Before_FragColor: string;\r\n\r\n public Vertex_Begin: string;\r\n public Vertex_Definitions: string;\r\n public Vertex_MainBegin: string;\r\n\r\n // positionUpdated\r\n public Vertex_Before_PositionUpdated: string;\r\n\r\n // normalUpdated\r\n public Vertex_Before_NormalUpdated: string;\r\n\r\n // worldPosComputed\r\n public Vertex_After_WorldPosComputed: string;\r\n\r\n // mainEnd\r\n public Vertex_MainEnd: string;\r\n}\r\n\r\nexport class CustomMaterial extends StandardMaterial {\r\n public static ShaderIndexer = 1;\r\n public CustomParts: ShaderSpecialParts;\r\n _createdShaderName: string;\r\n _customUniform: string[];\r\n _newUniforms: string[];\r\n _newUniformInstances: { [name: string]: any };\r\n _newSamplerInstances: { [name: string]: Texture };\r\n _customAttributes: string[];\r\n\r\n public FragmentShader: string;\r\n public VertexShader: string;\r\n\r\n public AttachAfterBind(mesh: Mesh | undefined, effect: Effect) {\r\n if (this._newUniformInstances) {\r\n for (const el in this._newUniformInstances) {\r\n const ea = el.toString().split(\"-\");\r\n if (ea[0] == \"vec2\") {\r\n effect.setVector2(ea[1], this._newUniformInstances[el]);\r\n } else if (ea[0] == \"vec3\") {\r\n if (this._newUniformInstances[el] instanceof Color3) {\r\n effect.setColor3(ea[1], this._newUniformInstances[el]);\r\n } else {\r\n effect.setVector3(ea[1], this._newUniformInstances[el]);\r\n }\r\n } else if (ea[0] == \"vec4\") {\r\n if (this._newUniformInstances[el] instanceof Color4) {\r\n effect.setDirectColor4(ea[1], this._newUniformInstances[el]);\r\n } else {\r\n effect.setVector4(ea[1], this._newUniformInstances[el]);\r\n }\r\n effect.setVector4(ea[1], this._newUniformInstances[el]);\r\n } else if (ea[0] == \"mat4\") {\r\n effect.setMatrix(ea[1], this._newUniformInstances[el]);\r\n } else if (ea[0] == \"float\") {\r\n effect.setFloat(ea[1], this._newUniformInstances[el]);\r\n }\r\n }\r\n }\r\n if (this._newSamplerInstances) {\r\n for (const el in this._newSamplerInstances) {\r\n const ea = el.toString().split(\"-\");\r\n if (ea[0] == \"sampler2D\" && this._newSamplerInstances[el].isReady && this._newSamplerInstances[el].isReady()) {\r\n effect.setTexture(ea[1], this._newSamplerInstances[el]);\r\n }\r\n }\r\n }\r\n }\r\n\r\n public ReviewUniform(name: string, arr: string[]): string[] {\r\n if (name == \"uniform\" && this._newUniforms) {\r\n for (let ind = 0; ind < this._newUniforms.length; ind++) {\r\n if (this._customUniform[ind].indexOf(\"sampler\") == -1) {\r\n arr.push(this._newUniforms[ind].replace(/\\[\\d*\\]/g, \"\"));\r\n }\r\n }\r\n }\r\n if (name == \"sampler\" && this._newUniforms) {\r\n for (let ind = 0; ind < this._newUniforms.length; ind++) {\r\n if (this._customUniform[ind].indexOf(\"sampler\") != -1) {\r\n arr.push(this._newUniforms[ind].replace(/\\[\\d*\\]/g, \"\"));\r\n }\r\n }\r\n }\r\n return arr;\r\n }\r\n\r\n public Builder(shaderName: string, uniforms: string[], uniformBuffers: string[], samplers: string[], defines: MaterialDefines | string[], attributes?: string[]): string {\r\n if (attributes && this._customAttributes && this._customAttributes.length > 0) {\r\n attributes.push(...this._customAttributes);\r\n }\r\n\r\n this.ReviewUniform(\"uniform\", uniforms);\r\n this.ReviewUniform(\"sampler\", samplers);\r\n\r\n const name = this._createdShaderName;\r\n\r\n if (Effect.ShadersStore[name + \"VertexShader\"] && Effect.ShadersStore[name + \"PixelShader\"]) {\r\n return name;\r\n }\r\n Effect.ShadersStore[name + \"VertexShader\"] = this._injectCustomCode(this.VertexShader, \"vertex\");\r\n Effect.ShadersStore[name + \"PixelShader\"] = this._injectCustomCode(this.FragmentShader, \"fragment\");\r\n\r\n return name;\r\n }\r\n\r\n protected _injectCustomCode(code: string, shaderType: string): string {\r\n const customCode = this._getCustomCode(shaderType);\r\n\r\n for (const point in customCode) {\r\n const injectedCode = customCode[point];\r\n\r\n if (injectedCode && injectedCode.length > 0) {\r\n const fullPointName = \"#define \" + point;\r\n code = code.replace(fullPointName, \"\\n\" + injectedCode + \"\\n\" + fullPointName);\r\n }\r\n }\r\n\r\n return code;\r\n }\r\n\r\n protected _getCustomCode(shaderType: string): { [pointName: string]: string } {\r\n if (shaderType === \"vertex\") {\r\n return {\r\n CUSTOM_VERTEX_BEGIN: this.CustomParts.Vertex_Begin,\r\n CUSTOM_VERTEX_DEFINITIONS: (this._customUniform?.join(\"\\n\") || \"\") + (this.CustomParts.Vertex_Definitions || \"\"),\r\n CUSTOM_VERTEX_MAIN_BEGIN: this.CustomParts.Vertex_MainBegin,\r\n CUSTOM_VERTEX_UPDATE_POSITION: this.CustomParts.Vertex_Before_PositionUpdated,\r\n CUSTOM_VERTEX_UPDATE_NORMAL: this.CustomParts.Vertex_Before_NormalUpdated,\r\n CUSTOM_VERTEX_MAIN_END: this.CustomParts.Vertex_MainEnd,\r\n CUSTOM_VERTEX_UPDATE_WORLDPOS: this.CustomParts.Vertex_After_WorldPosComputed,\r\n };\r\n }\r\n return {\r\n CUSTOM_FRAGMENT_BEGIN: this.CustomParts.Fragment_Begin,\r\n CUSTOM_FRAGMENT_DEFINITIONS: (this._customUniform?.join(\"\\n\") || \"\") + (this.CustomParts.Fragment_Definitions || \"\"),\r\n CUSTOM_FRAGMENT_MAIN_BEGIN: this.CustomParts.Fragment_MainBegin,\r\n CUSTOM_FRAGMENT_UPDATE_DIFFUSE: this.CustomParts.Fragment_Custom_Diffuse,\r\n CUSTOM_FRAGMENT_UPDATE_ALPHA: this.CustomParts.Fragment_Custom_Alpha,\r\n CUSTOM_FRAGMENT_BEFORE_LIGHTS: this.CustomParts.Fragment_Before_Lights,\r\n CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR: this.CustomParts.Fragment_Before_FragColor,\r\n CUSTOM_FRAGMENT_MAIN_END: this.CustomParts.Fragment_MainEnd,\r\n CUSTOM_FRAGMENT_BEFORE_FOG: this.CustomParts.Fragment_Before_Fog,\r\n };\r\n }\r\n\r\n constructor(name: string, scene?: Scene) {\r\n super(name, scene);\r\n this.CustomParts = new ShaderSpecialParts();\r\n this.customShaderNameResolve = this.Builder;\r\n\r\n this.FragmentShader = Effect.ShadersStore[\"defaultPixelShader\"];\r\n this.VertexShader = Effect.ShadersStore[\"defaultVertexShader\"];\r\n\r\n CustomMaterial.ShaderIndexer++;\r\n this._createdShaderName = \"custom_\" + CustomMaterial.ShaderIndexer;\r\n }\r\n\r\n protected _afterBind(mesh?: Mesh, effect: Nullable<Effect> = null): void {\r\n if (!effect) {\r\n return;\r\n }\r\n this.AttachAfterBind(mesh, effect);\r\n try {\r\n super._afterBind(mesh, effect);\r\n } catch (e) {}\r\n }\r\n\r\n public AddUniform(name: string, kind: string, param: any): CustomMaterial {\r\n if (!this._customUniform) {\r\n this._customUniform = new Array();\r\n this._newUniforms = new Array();\r\n this._newSamplerInstances = {};\r\n this._newUniformInstances = {};\r\n }\r\n if (param) {\r\n if (kind.indexOf(\"sampler\") != -1) {\r\n (<any>this._newSamplerInstances)[kind + \"-\" + name] = param;\r\n } else {\r\n (<any>this._newUniformInstances)[kind + \"-\" + name] = param;\r\n }\r\n }\r\n this._customUniform.push(\"uniform \" + kind + \" \" + name + \";\");\r\n this._newUniforms.push(name);\r\n\r\n return this;\r\n }\r\n\r\n public AddAttribute(name: string): CustomMaterial {\r\n if (!this._customAttributes) {\r\n this._customAttributes = [];\r\n }\r\n\r\n this._customAttributes.push(name);\r\n\r\n return this;\r\n }\r\n\r\n public Fragment_Begin(shaderPart: string): CustomMaterial {\r\n this.CustomParts.Fragment_Begin = shaderPart;\r\n return this;\r\n }\r\n\r\n public Fragment_Definitions(shaderPart: string): CustomMaterial {\r\n this.CustomParts.Fragment_Definitions = shaderPart;\r\n return this;\r\n }\r\n\r\n public Fragment_MainBegin(shaderPart: string): CustomMaterial {\r\n this.CustomParts.Fragment_MainBegin = shaderPart;\r\n return this;\r\n }\r\n\r\n public Fragment_MainEnd(shaderPart: string): CustomMaterial {\r\n this.CustomParts.Fragment_MainEnd = shaderPart;\r\n return this;\r\n }\r\n\r\n public Fragment_Custom_Diffuse(shaderPart: string): CustomMaterial {\r\n this.CustomParts.Fragment_Custom_Diffuse = shaderPart.replace(\"result\", \"diffuseColor\");\r\n return this;\r\n }\r\n\r\n public Fragment_Custom_Alpha(shaderPart: string): CustomMaterial {\r\n this.CustomParts.Fragment_Custom_Alpha = shaderPart.replace(\"result\", \"alpha\");\r\n return this;\r\n }\r\n\r\n public Fragment_Before_Lights(shaderPart: string): CustomMaterial {\r\n this.CustomParts.Fragment_Before_Lights = shaderPart;\r\n return this;\r\n }\r\n\r\n public Fragment_Before_Fog(shaderPart: string): CustomMaterial {\r\n this.CustomParts.Fragment_Before_Fog = shaderPart;\r\n return this;\r\n }\r\n\r\n public Fragment_Before_FragColor(shaderPart: string): CustomMaterial {\r\n this.CustomParts.Fragment_Before_FragColor = shaderPart.replace(\"result\", \"color\");\r\n return this;\r\n }\r\n\r\n public Vertex_Begin(shaderPart: string): CustomMaterial {\r\n this.CustomParts.Vertex_Begin = shaderPart;\r\n return this;\r\n }\r\n\r\n public Vertex_Definitions(shaderPart: string): CustomMaterial {\r\n this.CustomParts.Vertex_Definitions = shaderPart;\r\n return this;\r\n }\r\n\r\n public Vertex_MainBegin(shaderPart: string): CustomMaterial {\r\n this.CustomParts.Vertex_MainBegin = shaderPart;\r\n return this;\r\n }\r\n\r\n public Vertex_Before_PositionUpdated(shaderPart: string): CustomMaterial {\r\n this.CustomParts.Vertex_Before_PositionUpdated = shaderPart.replace(\"result\", \"positionUpdated\");\r\n return this;\r\n }\r\n\r\n public Vertex_Before_NormalUpdated(shaderPart: string): CustomMaterial {\r\n this.CustomParts.Vertex_Before_NormalUpdated = shaderPart.replace(\"result\", \"normalUpdated\");\r\n return this;\r\n }\r\n\r\n public Vertex_After_WorldPosComputed(shaderPart: string): CustomMaterial {\r\n this.CustomParts.Vertex_After_WorldPosComputed = shaderPart;\r\n return this;\r\n }\r\n\r\n public Vertex_MainEnd(shaderPart: string): CustomMaterial {\r\n this.CustomParts.Vertex_MainEnd = shaderPart;\r\n return this;\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.CustomMaterial\", CustomMaterial);\r\n"]}
@@ -107,11 +107,10 @@ export class PBRCustomMaterial extends PBRMaterial {
107
107
  return code;
108
108
  }
109
109
  _getCustomCode(shaderType) {
110
- var _a, _b;
111
110
  if (shaderType === "vertex") {
112
111
  return {
113
112
  CUSTOM_VERTEX_BEGIN: this.CustomParts.Vertex_Begin,
114
- CUSTOM_VERTEX_DEFINITIONS: (((_a = this._customUniform) === null || _a === void 0 ? void 0 : _a.join("\n")) || "") + (this.CustomParts.Vertex_Definitions || ""),
113
+ CUSTOM_VERTEX_DEFINITIONS: (this._customUniform?.join("\n") || "") + (this.CustomParts.Vertex_Definitions || ""),
115
114
  CUSTOM_VERTEX_MAIN_BEGIN: this.CustomParts.Vertex_MainBegin,
116
115
  CUSTOM_VERTEX_UPDATE_POSITION: this.CustomParts.Vertex_Before_PositionUpdated,
117
116
  CUSTOM_VERTEX_UPDATE_NORMAL: this.CustomParts.Vertex_Before_NormalUpdated,
@@ -122,7 +121,7 @@ export class PBRCustomMaterial extends PBRMaterial {
122
121
  return {
123
122
  CUSTOM_FRAGMENT_BEGIN: this.CustomParts.Fragment_Begin,
124
123
  CUSTOM_FRAGMENT_MAIN_BEGIN: this.CustomParts.Fragment_MainBegin,
125
- CUSTOM_FRAGMENT_DEFINITIONS: (((_b = this._customUniform) === null || _b === void 0 ? void 0 : _b.join("\n")) || "") + (this.CustomParts.Fragment_Definitions || ""),
124
+ CUSTOM_FRAGMENT_DEFINITIONS: (this._customUniform?.join("\n") || "") + (this.CustomParts.Fragment_Definitions || ""),
126
125
  CUSTOM_FRAGMENT_UPDATE_ALBEDO: this.CustomParts.Fragment_Custom_Albedo,
127
126
  CUSTOM_FRAGMENT_UPDATE_ALPHA: this.CustomParts.Fragment_Custom_Alpha,
128
127
  CUSTOM_FRAGMENT_BEFORE_LIGHTS: this.CustomParts.Fragment_Before_Lights,
@@ -1 +1 @@
1
- {"version":3,"file":"pbrCustomMaterial.js","sourceRoot":"","sources":["../../../../dev/materials/src/custom/pbrCustomMaterial.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,4CAA8B;AAE/C,OAAO,EAAE,WAAW,EAAE,qDAAuC;AAG7D,OAAO,EAAE,aAAa,EAAE,0CAA4B;AACpD,OAAO,EAAE,iBAAiB,EAAE,gEAAkD;AAE9E,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,4CAA8B;AAGvD,MAAM,OAAO,iBAAiB;IAC1B,gBAAe,CAAC;CAuCnB;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,iBAAiB,CAAC;AAEnD,MAAM,OAAO,iBAAkB,SAAQ,WAAW;IAavC,eAAe,CAAC,IAAsB,EAAE,MAAc;QACzD,IAAI,IAAI,CAAC,oBAAoB,EAAE;YAC3B,KAAK,MAAM,EAAE,IAAI,IAAI,CAAC,oBAAoB,EAAE;gBACxC,MAAM,EAAE,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBACpC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,MAAM,EAAE;oBACjB,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,oBAAoB,CAAC,EAAE,CAAC,CAAC,CAAC;iBAC3D;qBAAM,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,MAAM,EAAE;oBACxB,IAAI,IAAI,CA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AAC;IAEM,gBAAgB,CAAC,UAAkB;QACtC,IAAI,CAAC,WAAW,CAAC,gBAAgB,GAAG,UAAU,CAAC;QAC/C,OAAO,IAAI,CAAC;IAChB,CAAC;IAEM,6BAA6B,CAAC,UAAkB;QACnD,IAAI,CAAC,WAAW,CAAC,6BAA6B,GAAG,UAAU,CAAC,OAAO,CAAC,QAAQ,EAAE,iBAAiB,CAAC,CAAC;QACjG,OAAO,IAAI,CAAC;IAChB,CAAC;IAEM,2BAA2B,CAAC,UAAkB;QACjD,IAAI,CAAC,WAAW,CAAC,2BAA2B,GAAG,UAAU,CAAC,OAAO,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC;QAC7F,OAAO,IAAI,CAAC;IAChB,CAAC;IAEM,6BAA6B,CAAC,UAAkB;QACnD,IAAI,CAAC,WAAW,CAAC,6BAA6B,GAAG,UAAU,CAAC;QAC5D,OAAO,IAAI,CAAC;IAChB,CAAC;IAEM,cAAc,CAAC,UAAkB;QACpC,IAAI,CAAC,WAAW,CAAC,cAAc,GAAG,UAAU,CAAC;QAC7C,OAAO,IAAI,CAAC;IAChB,CAAC;;AA1Sa,+BAAa,GAAG,CAAC,CAAC;AA6SpC,aAAa,CAAC,2BAA2B,EAAE,iBAAiB,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { Texture } from \"core/Materials/Textures/texture\";\r\nimport { Effect } from \"core/Materials/effect\";\r\nimport type { MaterialDefines } from \"core/Materials/materialDefines\";\r\nimport { PBRMaterial } from \"core/Materials/PBR/pbrMaterial\";\r\nimport type { Mesh } from \"core/Meshes/mesh\";\r\nimport type { Scene } from \"core/scene\";\r\nimport { RegisterClass } from \"core/Misc/typeStore\";\r\nimport { ShaderCodeInliner } from \"core/Engines/Processors/shaderCodeInliner\";\r\nimport type { ICustomShaderNameResolveOptions } from \"core/Materials/material\";\r\nimport { Color3, Color4 } from \"core/Maths/math.color\";\r\nimport type { Nullable } from \"core/types\";\r\n\r\nexport class ShaderAlbedoParts {\r\n constructor() {}\r\n\r\n public Fragment_Begin: string;\r\n public Fragment_Definitions: string;\r\n public Fragment_MainBegin: string;\r\n public Fragment_MainEnd: string;\r\n\r\n // albedoColor\r\n public Fragment_Custom_Albedo: string;\r\n // lights\r\n public Fragment_Before_Lights: string;\r\n // roughness\r\n public Fragment_Custom_MetallicRoughness: string;\r\n // microsurface\r\n public Fragment_Custom_MicroSurface: string;\r\n // fog\r\n public Fragment_Before_Fog: string;\r\n // alpha\r\n public Fragment_Custom_Alpha: string;\r\n // color composition\r\n public Fragment_Before_FinalColorComposition: string;\r\n // frag color\r\n public Fragment_Before_FragColor: string;\r\n\r\n public Vertex_Begin: string;\r\n public Vertex_Definitions: string;\r\n public Vertex_MainBegin: string;\r\n\r\n // positionUpdated\r\n public Vertex_Before_PositionUpdated: string;\r\n\r\n // normalUpdated\r\n public Vertex_Before_NormalUpdated: string;\r\n\r\n // worldPosComputed\r\n public Vertex_After_WorldPosComputed: string;\r\n\r\n // mainEnd\r\n public Vertex_MainEnd: string;\r\n}\r\n\r\n/**\r\n * @deprecated use ShaderAlbedoParts instead.\r\n */\r\nexport const ShaderAlebdoParts = ShaderAlbedoParts;\r\n\r\nexport class PBRCustomMaterial extends PBRMaterial {\r\n public static ShaderIndexer = 1;\r\n public CustomParts: ShaderAlbedoParts;\r\n _createdShaderName: string;\r\n _customUniform: string[];\r\n _newUniforms: string[];\r\n _newUniformInstances: { [name: string]: any };\r\n _newSamplerInstances: { [name: string]: Texture };\r\n _customAttributes: string[];\r\n\r\n public FragmentShader: string;\r\n public VertexShader: string;\r\n\r\n public AttachAfterBind(mesh: Mesh | undefined, effect: Effect) {\r\n if (this._newUniformInstances) {\r\n for (const el in this._newUniformInstances) {\r\n const ea = el.toString().split(\"-\");\r\n if (ea[0] == \"vec2\") {\r\n effect.setVector2(ea[1], this._newUniformInstances[el]);\r\n } else if (ea[0] == \"vec3\") {\r\n if (this._newUniformInstances[el] instanceof Color3) {\r\n effect.setColor3(ea[1], this._newUniformInstances[el]);\r\n } else {\r\n effect.setVector3(ea[1], this._newUniformInstances[el]);\r\n }\r\n } else if (ea[0] == \"vec4\") {\r\n if (this._newUniformInstances[el] instanceof Color4) {\r\n effect.setDirectColor4(ea[1], this._newUniformInstances[el]);\r\n } else {\r\n effect.setVector4(ea[1], this._newUniformInstances[el]);\r\n }\r\n effect.setVector4(ea[1], this._newUniformInstances[el]);\r\n } else if (ea[0] == \"mat4\") {\r\n effect.setMatrix(ea[1], this._newUniformInstances[el]);\r\n } else if (ea[0] == \"float\") {\r\n effect.setFloat(ea[1], this._newUniformInstances[el]);\r\n }\r\n }\r\n }\r\n if (this._newSamplerInstances) {\r\n for (const el in this._newSamplerInstances) {\r\n const ea = el.toString().split(\"-\");\r\n if (ea[0] == \"sampler2D\" && this._newSamplerInstances[el].isReady && this._newSamplerInstances[el].isReady()) {\r\n effect.setTexture(ea[1], this._newSamplerInstances[el]);\r\n }\r\n }\r\n }\r\n }\r\n\r\n public ReviewUniform(name: string, arr: string[]): string[] {\r\n if (name == \"uniform\" && this._newUniforms) {\r\n for (let ind = 0; ind < this._newUniforms.length; ind++) {\r\n if (this._customUniform[ind].indexOf(\"sampler\") == -1) {\r\n arr.push(this._newUniforms[ind].replace(/\\[\\d*\\]/g, \"\"));\r\n }\r\n }\r\n }\r\n if (name == \"sampler\" && this._newUniforms) {\r\n for (let ind = 0; ind < this._newUniforms.length; ind++) {\r\n if (this._customUniform[ind].indexOf(\"sampler\") != -1) {\r\n arr.push(this._newUniforms[ind].replace(/\\[\\d*\\]/g, \"\"));\r\n }\r\n }\r\n }\r\n return arr;\r\n }\r\n\r\n public Builder(\r\n shaderName: string,\r\n uniforms: string[],\r\n uniformBuffers: string[],\r\n samplers: string[],\r\n defines: MaterialDefines | string[],\r\n attributes?: string[],\r\n options?: ICustomShaderNameResolveOptions\r\n ): string {\r\n if (options) {\r\n const currentProcessing = options.processFinalCode;\r\n options.processFinalCode = (type: string, code: string) => {\r\n if (type === \"vertex\") {\r\n return currentProcessing ? currentProcessing(type, code) : code;\r\n }\r\n const sci = new ShaderCodeInliner(code);\r\n sci.inlineToken = \"#define pbr_inline\";\r\n sci.processCode();\r\n return currentProcessing ? currentProcessing(type, sci.code) : sci.code;\r\n };\r\n }\r\n\r\n if (attributes && this._customAttributes && this._customAttributes.length > 0) {\r\n attributes.push(...this._customAttributes);\r\n }\r\n\r\n this.ReviewUniform(\"uniform\", uniforms);\r\n this.ReviewUniform(\"sampler\", samplers);\r\n\r\n const name = this._createdShaderName;\r\n\r\n if (Effect.ShadersStore[name + \"VertexShader\"] && Effect.ShadersStore[name + \"PixelShader\"]) {\r\n return name;\r\n }\r\n Effect.ShadersStore[name + \"VertexShader\"] = this._injectCustomCode(this.VertexShader, \"vertex\");\r\n Effect.ShadersStore[name + \"PixelShader\"] = this._injectCustomCode(this.FragmentShader, \"fragment\");\r\n\r\n return name;\r\n }\r\n\r\n protected _injectCustomCode(code: string, shaderType: string): string {\r\n const customCode = this._getCustomCode(shaderType);\r\n\r\n for (const point in customCode) {\r\n const injectedCode = customCode[point];\r\n\r\n if (injectedCode && injectedCode.length > 0) {\r\n const fullPointName = \"#define \" + point;\r\n code = code.replace(fullPointName, \"\\n\" + injectedCode + \"\\n\" + fullPointName);\r\n }\r\n }\r\n\r\n return code;\r\n }\r\n\r\n protected _getCustomCode(shaderType: string): { [pointName: string]: string } {\r\n if (shaderType === \"vertex\") {\r\n return {\r\n CUSTOM_VERTEX_BEGIN: this.CustomParts.Vertex_Begin,\r\n CUSTOM_VERTEX_DEFINITIONS: (this._customUniform?.join(\"\\n\") || \"\") + (this.CustomParts.Vertex_Definitions || \"\"),\r\n CUSTOM_VERTEX_MAIN_BEGIN: this.CustomParts.Vertex_MainBegin,\r\n CUSTOM_VERTEX_UPDATE_POSITION: this.CustomParts.Vertex_Before_PositionUpdated,\r\n CUSTOM_VERTEX_UPDATE_NORMAL: this.CustomParts.Vertex_Before_NormalUpdated,\r\n CUSTOM_VERTEX_MAIN_END: this.CustomParts.Vertex_MainEnd,\r\n CUSTOM_VERTEX_UPDATE_WORLDPOS: this.CustomParts.Vertex_After_WorldPosComputed,\r\n };\r\n }\r\n return {\r\n CUSTOM_FRAGMENT_BEGIN: this.CustomParts.Fragment_Begin,\r\n CUSTOM_FRAGMENT_MAIN_BEGIN: this.CustomParts.Fragment_MainBegin,\r\n CUSTOM_FRAGMENT_DEFINITIONS: (this._customUniform?.join(\"\\n\") || \"\") + (this.CustomParts.Fragment_Definitions || \"\"),\r\n CUSTOM_FRAGMENT_UPDATE_ALBEDO: this.CustomParts.Fragment_Custom_Albedo,\r\n CUSTOM_FRAGMENT_UPDATE_ALPHA: this.CustomParts.Fragment_Custom_Alpha,\r\n CUSTOM_FRAGMENT_BEFORE_LIGHTS: this.CustomParts.Fragment_Before_Lights,\r\n CUSTOM_FRAGMENT_UPDATE_METALLICROUGHNESS: this.CustomParts.Fragment_Custom_MetallicRoughness,\r\n CUSTOM_FRAGMENT_UPDATE_MICROSURFACE: this.CustomParts.Fragment_Custom_MicroSurface,\r\n CUSTOM_FRAGMENT_BEFORE_FINALCOLORCOMPOSITION: this.CustomParts.Fragment_Before_FinalColorComposition,\r\n CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR: this.CustomParts.Fragment_Before_FragColor,\r\n CUSTOM_FRAGMENT_MAIN_END: this.CustomParts.Fragment_MainEnd,\r\n CUSTOM_FRAGMENT_BEFORE_FOG: this.CustomParts.Fragment_Before_Fog,\r\n };\r\n }\r\n\r\n constructor(name: string, scene?: Scene) {\r\n super(name, scene);\r\n this.CustomParts = new ShaderAlbedoParts();\r\n this.customShaderNameResolve = this.Builder;\r\n\r\n this.FragmentShader = Effect.ShadersStore[\"pbrPixelShader\"];\r\n this.VertexShader = Effect.ShadersStore[\"pbrVertexShader\"];\r\n\r\n this.FragmentShader = this.FragmentShader.replace(/#include<pbrBlockAlbedoOpacity>/g, Effect.IncludesShadersStore[\"pbrBlockAlbedoOpacity\"]);\r\n this.FragmentShader = this.FragmentShader.replace(/#include<pbrBlockReflectivity>/g, Effect.IncludesShadersStore[\"pbrBlockReflectivity\"]);\r\n this.FragmentShader = this.FragmentShader.replace(/#include<pbrBlockFinalColorComposition>/g, Effect.IncludesShadersStore[\"pbrBlockFinalColorComposition\"]);\r\n\r\n PBRCustomMaterial.ShaderIndexer++;\r\n this._createdShaderName = \"custompbr_\" + PBRCustomMaterial.ShaderIndexer;\r\n }\r\n\r\n protected _afterBind(mesh?: Mesh, effect: Nullable<Effect> = null): void {\r\n if (!effect) {\r\n return;\r\n }\r\n this.AttachAfterBind(mesh, effect);\r\n try {\r\n super._afterBind(mesh, effect);\r\n } catch (e) {}\r\n }\r\n\r\n public AddUniform(name: string, kind: string, param: any): PBRCustomMaterial {\r\n if (!this._customUniform) {\r\n this._customUniform = new Array();\r\n this._newUniforms = new Array();\r\n this._newSamplerInstances = {};\r\n this._newUniformInstances = {};\r\n }\r\n if (param) {\r\n if (kind.indexOf(\"sampler\") != -1) {\r\n (<any>this._newSamplerInstances)[kind + \"-\" + name] = param;\r\n } else {\r\n (<any>this._newUniformInstances)[kind + \"-\" + name] = param;\r\n }\r\n }\r\n this._customUniform.push(\"uniform \" + kind + \" \" + name + \";\");\r\n this._newUniforms.push(name);\r\n\r\n return this;\r\n }\r\n\r\n public AddAttribute(name: string): PBRCustomMaterial {\r\n if (!this._customAttributes) {\r\n this._customAttributes = [];\r\n }\r\n\r\n this._customAttributes.push(name);\r\n\r\n return this;\r\n }\r\n\r\n public Fragment_Begin(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Fragment_Begin = shaderPart;\r\n return this;\r\n }\r\n\r\n public Fragment_Definitions(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Fragment_Definitions = shaderPart;\r\n return this;\r\n }\r\n\r\n public Fragment_MainBegin(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Fragment_MainBegin = shaderPart;\r\n return this;\r\n }\r\n\r\n public Fragment_Custom_Albedo(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Fragment_Custom_Albedo = shaderPart.replace(\"result\", \"surfaceAlbedo\");\r\n return this;\r\n }\r\n\r\n public Fragment_Custom_Alpha(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Fragment_Custom_Alpha = shaderPart.replace(\"result\", \"alpha\");\r\n return this;\r\n }\r\n\r\n public Fragment_Before_Lights(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Fragment_Before_Lights = shaderPart;\r\n return this;\r\n }\r\n\r\n public Fragment_Custom_MetallicRoughness(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Fragment_Custom_MetallicRoughness = shaderPart;\r\n return this;\r\n }\r\n\r\n public Fragment_Custom_MicroSurface(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Fragment_Custom_MicroSurface = shaderPart;\r\n return this;\r\n }\r\n\r\n public Fragment_Before_Fog(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Fragment_Before_Fog = shaderPart;\r\n return this;\r\n }\r\n\r\n public Fragment_Before_FinalColorComposition(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Fragment_Before_FinalColorComposition = shaderPart;\r\n return this;\r\n }\r\n\r\n public Fragment_Before_FragColor(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Fragment_Before_FragColor = shaderPart.replace(\"result\", \"color\");\r\n return this;\r\n }\r\n\r\n public Fragment_MainEnd(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Fragment_MainEnd = shaderPart;\r\n return this;\r\n }\r\n\r\n public Vertex_Begin(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Vertex_Begin = shaderPart;\r\n return this;\r\n }\r\n\r\n public Vertex_Definitions(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Vertex_Definitions = shaderPart;\r\n return this;\r\n }\r\n\r\n public Vertex_MainBegin(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Vertex_MainBegin = shaderPart;\r\n return this;\r\n }\r\n\r\n public Vertex_Before_PositionUpdated(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Vertex_Before_PositionUpdated = shaderPart.replace(\"result\", \"positionUpdated\");\r\n return this;\r\n }\r\n\r\n public Vertex_Before_NormalUpdated(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Vertex_Before_NormalUpdated = shaderPart.replace(\"result\", \"normalUpdated\");\r\n return this;\r\n }\r\n\r\n public Vertex_After_WorldPosComputed(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Vertex_After_WorldPosComputed = shaderPart;\r\n return this;\r\n }\r\n\r\n public Vertex_MainEnd(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Vertex_MainEnd = shaderPart;\r\n return this;\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.PBRCustomMaterial\", PBRCustomMaterial);\r\n"]}
1
+ {"version":3,"file":"pbrCustomMaterial.js","sourceRoot":"","sources":["../../../../dev/materials/src/custom/pbrCustomMaterial.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,4CAA8B;AAE/C,OAAO,EAAE,WAAW,EAAE,qDAAuC;AAG7D,OAAO,EAAE,aAAa,EAAE,0CAA4B;AACpD,OAAO,EAAE,iBAAiB,EAAE,gEAAkD;AAE9E,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,4CAA8B;AAGvD,MAAM,OAAO,iBAAiB;IAC1B,gBAAe,CAAC;CAuCnB;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,iBAAiB,CAAC;AAEnD,MAAM,OAAO,iBAAkB,SAAQ,WAAW;IAavC,eAAe,CAAC,IAAsB,EAAE,MAAc;QACzD,IAAI,IAAI,CAAC,oBAAoB,EAAE;YAC3B,KAAK,MAAM,EAAE,IAAI,IAAI,CAAC,oBAAoB,EAAE;gBACxC,MAAM,EAAE,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CA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M,YAAY,CAAC,UAAkB;QAClC,IAAI,CAAC,WAAW,CAAC,YAAY,GAAG,UAAU,CAAC;QAC3C,OAAO,IAAI,CAAC;IAChB,CAAC;IAEM,kBAAkB,CAAC,UAAkB;QACxC,IAAI,CAAC,WAAW,CAAC,kBAAkB,GAAG,UAAU,CAAC;QACjD,OAAO,IAAI,CAAC;IAChB,CAAC;IAEM,gBAAgB,CAAC,UAAkB;QACtC,IAAI,CAAC,WAAW,CAAC,gBAAgB,GAAG,UAAU,CAAC;QAC/C,OAAO,IAAI,CAAC;IAChB,CAAC;IAEM,6BAA6B,CAAC,UAAkB;QACnD,IAAI,CAAC,WAAW,CAAC,6BAA6B,GAAG,UAAU,CAAC,OAAO,CAAC,QAAQ,EAAE,iBAAiB,CAAC,CAAC;QACjG,OAAO,IAAI,CAAC;IAChB,CAAC;IAEM,2BAA2B,CAAC,UAAkB;QACjD,IAAI,CAAC,WAAW,CAAC,2BAA2B,GAAG,UAAU,CAAC,OAAO,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC;QAC7F,OAAO,IAAI,CAAC;IAChB,CAAC;IAEM,6BAA6B,CAAC,UAAkB;QACnD,IAAI,CAAC,WAAW,CAAC,6BAA6B,GAAG,UAAU,CAAC;QAC5D,OAAO,IAAI,CAAC;IAChB,CAAC;IAEM,cAAc,CAAC,UAAkB;QACpC,IAAI,CAAC,WAAW,CAAC,cAAc,GAAG,UAAU,CAAC;QAC7C,OAAO,IAAI,CAAC;IAChB,CAAC;;AA1Sa,+BAAa,GAAG,CAAC,CAAC;AA6SpC,aAAa,CAAC,2BAA2B,EAAE,iBAAiB,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { Texture } from \"core/Materials/Textures/texture\";\r\nimport { Effect } from \"core/Materials/effect\";\r\nimport type { MaterialDefines } from \"core/Materials/materialDefines\";\r\nimport { PBRMaterial } from \"core/Materials/PBR/pbrMaterial\";\r\nimport type { Mesh } from \"core/Meshes/mesh\";\r\nimport type { Scene } from \"core/scene\";\r\nimport { RegisterClass } from \"core/Misc/typeStore\";\r\nimport { ShaderCodeInliner } from \"core/Engines/Processors/shaderCodeInliner\";\r\nimport type { ICustomShaderNameResolveOptions } from \"core/Materials/material\";\r\nimport { Color3, Color4 } from \"core/Maths/math.color\";\r\nimport type { Nullable } from \"core/types\";\r\n\r\nexport class ShaderAlbedoParts {\r\n constructor() {}\r\n\r\n public Fragment_Begin: string;\r\n public Fragment_Definitions: string;\r\n public Fragment_MainBegin: string;\r\n public Fragment_MainEnd: string;\r\n\r\n // albedoColor\r\n public Fragment_Custom_Albedo: string;\r\n // lights\r\n public Fragment_Before_Lights: string;\r\n // roughness\r\n public Fragment_Custom_MetallicRoughness: string;\r\n // microsurface\r\n public Fragment_Custom_MicroSurface: string;\r\n // fog\r\n public Fragment_Before_Fog: string;\r\n // alpha\r\n public Fragment_Custom_Alpha: string;\r\n // color composition\r\n public Fragment_Before_FinalColorComposition: string;\r\n // frag color\r\n public Fragment_Before_FragColor: string;\r\n\r\n public Vertex_Begin: string;\r\n public Vertex_Definitions: string;\r\n public Vertex_MainBegin: string;\r\n\r\n // positionUpdated\r\n public Vertex_Before_PositionUpdated: string;\r\n\r\n // normalUpdated\r\n public Vertex_Before_NormalUpdated: string;\r\n\r\n // worldPosComputed\r\n public Vertex_After_WorldPosComputed: string;\r\n\r\n // mainEnd\r\n public Vertex_MainEnd: string;\r\n}\r\n\r\n/**\r\n * @deprecated use ShaderAlbedoParts instead.\r\n */\r\nexport const ShaderAlebdoParts = ShaderAlbedoParts;\r\n\r\nexport class PBRCustomMaterial extends PBRMaterial {\r\n public static ShaderIndexer = 1;\r\n public CustomParts: ShaderAlbedoParts;\r\n _createdShaderName: string;\r\n _customUniform: string[];\r\n _newUniforms: string[];\r\n _newUniformInstances: { [name: string]: any };\r\n _newSamplerInstances: { [name: string]: Texture };\r\n _customAttributes: string[];\r\n\r\n public FragmentShader: string;\r\n public VertexShader: string;\r\n\r\n public AttachAfterBind(mesh: Mesh | undefined, effect: Effect) {\r\n if (this._newUniformInstances) {\r\n for (const el in this._newUniformInstances) {\r\n const ea = el.toString().split(\"-\");\r\n if (ea[0] == \"vec2\") {\r\n effect.setVector2(ea[1], this._newUniformInstances[el]);\r\n } else if (ea[0] == \"vec3\") {\r\n if (this._newUniformInstances[el] instanceof Color3) {\r\n effect.setColor3(ea[1], this._newUniformInstances[el]);\r\n } else {\r\n effect.setVector3(ea[1], this._newUniformInstances[el]);\r\n }\r\n } else if (ea[0] == \"vec4\") {\r\n if (this._newUniformInstances[el] instanceof Color4) {\r\n effect.setDirectColor4(ea[1], this._newUniformInstances[el]);\r\n } else {\r\n effect.setVector4(ea[1], this._newUniformInstances[el]);\r\n }\r\n effect.setVector4(ea[1], this._newUniformInstances[el]);\r\n } else if (ea[0] == \"mat4\") {\r\n effect.setMatrix(ea[1], this._newUniformInstances[el]);\r\n } else if (ea[0] == \"float\") {\r\n effect.setFloat(ea[1], this._newUniformInstances[el]);\r\n }\r\n }\r\n }\r\n if (this._newSamplerInstances) {\r\n for (const el in this._newSamplerInstances) {\r\n const ea = el.toString().split(\"-\");\r\n if (ea[0] == \"sampler2D\" && this._newSamplerInstances[el].isReady && this._newSamplerInstances[el].isReady()) {\r\n effect.setTexture(ea[1], this._newSamplerInstances[el]);\r\n }\r\n }\r\n }\r\n }\r\n\r\n public ReviewUniform(name: string, arr: string[]): string[] {\r\n if (name == \"uniform\" && this._newUniforms) {\r\n for (let ind = 0; ind < this._newUniforms.length; ind++) {\r\n if (this._customUniform[ind].indexOf(\"sampler\") == -1) {\r\n arr.push(this._newUniforms[ind].replace(/\\[\\d*\\]/g, \"\"));\r\n }\r\n }\r\n }\r\n if (name == \"sampler\" && this._newUniforms) {\r\n for (let ind = 0; ind < this._newUniforms.length; ind++) {\r\n if (this._customUniform[ind].indexOf(\"sampler\") != -1) {\r\n arr.push(this._newUniforms[ind].replace(/\\[\\d*\\]/g, \"\"));\r\n }\r\n }\r\n }\r\n return arr;\r\n }\r\n\r\n public Builder(\r\n shaderName: string,\r\n uniforms: string[],\r\n uniformBuffers: string[],\r\n samplers: string[],\r\n defines: MaterialDefines | string[],\r\n attributes?: string[],\r\n options?: ICustomShaderNameResolveOptions\r\n ): string {\r\n if (options) {\r\n const currentProcessing = options.processFinalCode;\r\n options.processFinalCode = (type: string, code: string) => {\r\n if (type === \"vertex\") {\r\n return currentProcessing ? currentProcessing(type, code) : code;\r\n }\r\n const sci = new ShaderCodeInliner(code);\r\n sci.inlineToken = \"#define pbr_inline\";\r\n sci.processCode();\r\n return currentProcessing ? currentProcessing(type, sci.code) : sci.code;\r\n };\r\n }\r\n\r\n if (attributes && this._customAttributes && this._customAttributes.length > 0) {\r\n attributes.push(...this._customAttributes);\r\n }\r\n\r\n this.ReviewUniform(\"uniform\", uniforms);\r\n this.ReviewUniform(\"sampler\", samplers);\r\n\r\n const name = this._createdShaderName;\r\n\r\n if (Effect.ShadersStore[name + \"VertexShader\"] && Effect.ShadersStore[name + \"PixelShader\"]) {\r\n return name;\r\n }\r\n Effect.ShadersStore[name + \"VertexShader\"] = this._injectCustomCode(this.VertexShader, \"vertex\");\r\n Effect.ShadersStore[name + \"PixelShader\"] = this._injectCustomCode(this.FragmentShader, \"fragment\");\r\n\r\n return name;\r\n }\r\n\r\n protected _injectCustomCode(code: string, shaderType: string): string {\r\n const customCode = this._getCustomCode(shaderType);\r\n\r\n for (const point in customCode) {\r\n const injectedCode = customCode[point];\r\n\r\n if (injectedCode && injectedCode.length > 0) {\r\n const fullPointName = \"#define \" + point;\r\n code = code.replace(fullPointName, \"\\n\" + injectedCode + \"\\n\" + fullPointName);\r\n }\r\n }\r\n\r\n return code;\r\n }\r\n\r\n protected _getCustomCode(shaderType: string): { [pointName: string]: string } {\r\n if (shaderType === \"vertex\") {\r\n return {\r\n CUSTOM_VERTEX_BEGIN: this.CustomParts.Vertex_Begin,\r\n CUSTOM_VERTEX_DEFINITIONS: (this._customUniform?.join(\"\\n\") || \"\") + (this.CustomParts.Vertex_Definitions || \"\"),\r\n CUSTOM_VERTEX_MAIN_BEGIN: this.CustomParts.Vertex_MainBegin,\r\n CUSTOM_VERTEX_UPDATE_POSITION: this.CustomParts.Vertex_Before_PositionUpdated,\r\n CUSTOM_VERTEX_UPDATE_NORMAL: this.CustomParts.Vertex_Before_NormalUpdated,\r\n CUSTOM_VERTEX_MAIN_END: this.CustomParts.Vertex_MainEnd,\r\n CUSTOM_VERTEX_UPDATE_WORLDPOS: this.CustomParts.Vertex_After_WorldPosComputed,\r\n };\r\n }\r\n return {\r\n CUSTOM_FRAGMENT_BEGIN: this.CustomParts.Fragment_Begin,\r\n CUSTOM_FRAGMENT_MAIN_BEGIN: this.CustomParts.Fragment_MainBegin,\r\n CUSTOM_FRAGMENT_DEFINITIONS: (this._customUniform?.join(\"\\n\") || \"\") + (this.CustomParts.Fragment_Definitions || \"\"),\r\n CUSTOM_FRAGMENT_UPDATE_ALBEDO: this.CustomParts.Fragment_Custom_Albedo,\r\n CUSTOM_FRAGMENT_UPDATE_ALPHA: this.CustomParts.Fragment_Custom_Alpha,\r\n CUSTOM_FRAGMENT_BEFORE_LIGHTS: this.CustomParts.Fragment_Before_Lights,\r\n CUSTOM_FRAGMENT_UPDATE_METALLICROUGHNESS: this.CustomParts.Fragment_Custom_MetallicRoughness,\r\n CUSTOM_FRAGMENT_UPDATE_MICROSURFACE: this.CustomParts.Fragment_Custom_MicroSurface,\r\n CUSTOM_FRAGMENT_BEFORE_FINALCOLORCOMPOSITION: this.CustomParts.Fragment_Before_FinalColorComposition,\r\n CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR: this.CustomParts.Fragment_Before_FragColor,\r\n CUSTOM_FRAGMENT_MAIN_END: this.CustomParts.Fragment_MainEnd,\r\n CUSTOM_FRAGMENT_BEFORE_FOG: this.CustomParts.Fragment_Before_Fog,\r\n };\r\n }\r\n\r\n constructor(name: string, scene?: Scene) {\r\n super(name, scene);\r\n this.CustomParts = new ShaderAlbedoParts();\r\n this.customShaderNameResolve = this.Builder;\r\n\r\n this.FragmentShader = Effect.ShadersStore[\"pbrPixelShader\"];\r\n this.VertexShader = Effect.ShadersStore[\"pbrVertexShader\"];\r\n\r\n this.FragmentShader = this.FragmentShader.replace(/#include<pbrBlockAlbedoOpacity>/g, Effect.IncludesShadersStore[\"pbrBlockAlbedoOpacity\"]);\r\n this.FragmentShader = this.FragmentShader.replace(/#include<pbrBlockReflectivity>/g, Effect.IncludesShadersStore[\"pbrBlockReflectivity\"]);\r\n this.FragmentShader = this.FragmentShader.replace(/#include<pbrBlockFinalColorComposition>/g, Effect.IncludesShadersStore[\"pbrBlockFinalColorComposition\"]);\r\n\r\n PBRCustomMaterial.ShaderIndexer++;\r\n this._createdShaderName = \"custompbr_\" + PBRCustomMaterial.ShaderIndexer;\r\n }\r\n\r\n protected _afterBind(mesh?: Mesh, effect: Nullable<Effect> = null): void {\r\n if (!effect) {\r\n return;\r\n }\r\n this.AttachAfterBind(mesh, effect);\r\n try {\r\n super._afterBind(mesh, effect);\r\n } catch (e) {}\r\n }\r\n\r\n public AddUniform(name: string, kind: string, param: any): PBRCustomMaterial {\r\n if (!this._customUniform) {\r\n this._customUniform = new Array();\r\n this._newUniforms = new Array();\r\n this._newSamplerInstances = {};\r\n this._newUniformInstances = {};\r\n }\r\n if (param) {\r\n if (kind.indexOf(\"sampler\") != -1) {\r\n (<any>this._newSamplerInstances)[kind + \"-\" + name] = param;\r\n } else {\r\n (<any>this._newUniformInstances)[kind + \"-\" + name] = param;\r\n }\r\n }\r\n this._customUniform.push(\"uniform \" + kind + \" \" + name + \";\");\r\n this._newUniforms.push(name);\r\n\r\n return this;\r\n }\r\n\r\n public AddAttribute(name: string): PBRCustomMaterial {\r\n if (!this._customAttributes) {\r\n this._customAttributes = [];\r\n }\r\n\r\n this._customAttributes.push(name);\r\n\r\n return this;\r\n }\r\n\r\n public Fragment_Begin(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Fragment_Begin = shaderPart;\r\n return this;\r\n }\r\n\r\n public Fragment_Definitions(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Fragment_Definitions = shaderPart;\r\n return this;\r\n }\r\n\r\n public Fragment_MainBegin(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Fragment_MainBegin = shaderPart;\r\n return this;\r\n }\r\n\r\n public Fragment_Custom_Albedo(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Fragment_Custom_Albedo = shaderPart.replace(\"result\", \"surfaceAlbedo\");\r\n return this;\r\n }\r\n\r\n public Fragment_Custom_Alpha(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Fragment_Custom_Alpha = shaderPart.replace(\"result\", \"alpha\");\r\n return this;\r\n }\r\n\r\n public Fragment_Before_Lights(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Fragment_Before_Lights = shaderPart;\r\n return this;\r\n }\r\n\r\n public Fragment_Custom_MetallicRoughness(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Fragment_Custom_MetallicRoughness = shaderPart;\r\n return this;\r\n }\r\n\r\n public Fragment_Custom_MicroSurface(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Fragment_Custom_MicroSurface = shaderPart;\r\n return this;\r\n }\r\n\r\n public Fragment_Before_Fog(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Fragment_Before_Fog = shaderPart;\r\n return this;\r\n }\r\n\r\n public Fragment_Before_FinalColorComposition(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Fragment_Before_FinalColorComposition = shaderPart;\r\n return this;\r\n }\r\n\r\n public Fragment_Before_FragColor(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Fragment_Before_FragColor = shaderPart.replace(\"result\", \"color\");\r\n return this;\r\n }\r\n\r\n public Fragment_MainEnd(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Fragment_MainEnd = shaderPart;\r\n return this;\r\n }\r\n\r\n public Vertex_Begin(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Vertex_Begin = shaderPart;\r\n return this;\r\n }\r\n\r\n public Vertex_Definitions(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Vertex_Definitions = shaderPart;\r\n return this;\r\n }\r\n\r\n public Vertex_MainBegin(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Vertex_MainBegin = shaderPart;\r\n return this;\r\n }\r\n\r\n public Vertex_Before_PositionUpdated(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Vertex_Before_PositionUpdated = shaderPart.replace(\"result\", \"positionUpdated\");\r\n return this;\r\n }\r\n\r\n public Vertex_Before_NormalUpdated(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Vertex_Before_NormalUpdated = shaderPart.replace(\"result\", \"normalUpdated\");\r\n return this;\r\n }\r\n\r\n public Vertex_After_WorldPosComputed(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Vertex_After_WorldPosComputed = shaderPart;\r\n return this;\r\n }\r\n\r\n public Vertex_MainEnd(shaderPart: string): PBRCustomMaterial {\r\n this.CustomParts.Vertex_MainEnd = shaderPart;\r\n return this;\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.PBRCustomMaterial\", PBRCustomMaterial);\r\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babylonjs/materials",
3
- "version": "6.38.0",
3
+ "version": "6.39.0",
4
4
  "main": "index.js",
5
5
  "module": "index.js",
6
6
  "types": "index.d.ts",
@@ -18,7 +18,7 @@
18
18
  "postcompile": "build-tools -c add-js-to-es6"
19
19
  },
20
20
  "devDependencies": {
21
- "@babylonjs/core": "^6.38.0",
21
+ "@babylonjs/core": "^6.39.0",
22
22
  "@dev/build-tools": "^1.0.0",
23
23
  "@lts/materials": "^1.0.0"
24
24
  },
@@ -62,7 +62,6 @@ export class ShadowOnlyMaterial extends PushMaterial {
62
62
  }
63
63
  // Methods
64
64
  isReadyForSubMesh(mesh, subMesh, useInstances) {
65
- var _a;
66
65
  if (this.isFrozen) {
67
66
  if (subMesh.effect && subMesh.effect._wasPreviouslyReady && subMesh.effect._wasPreviouslyUsingInstances === useInstances) {
68
67
  return true;
@@ -96,7 +95,7 @@ export class ShadowOnlyMaterial extends PushMaterial {
96
95
  MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, this, defines, useInstances ? true : false);
97
96
  MaterialHelper.PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines);
98
97
  defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, 1);
99
- const shadowGenerator = (_a = this._getFirstShadowLightForMesh(mesh)) === null || _a === void 0 ? void 0 : _a.getShadowGenerator();
98
+ const shadowGenerator = this._getFirstShadowLightForMesh(mesh)?.getShadowGenerator();
100
99
  this._needAlphaBlending = true;
101
100
  if (shadowGenerator && shadowGenerator.getClassName && shadowGenerator.getClassName() === "CascadedShadowGenerator") {
102
101
  const csg = shadowGenerator;
@@ -1 +1 @@
1
- {"version":3,"file":"shadowOnlyMaterial.js","sourceRoot":"","sources":["../../../../dev/materials/src/shadowOnly/shadowOnlyMaterial.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,2CAA6B;AAE3D,OAAO,EAAE,MAAM,EAAE,4CAA8B;AAI/C,OAAO,EAAE,eAAe,EAAE,qDAAuC;AACjE,OAAO,EAAE,cAAc,EAAE,oDAAsC;AAC/D,OAAO,EAAE,YAAY,EAAE,kDAAoC;AAC3D,OAAO,EAAE,YAAY,EAAE,0CAA4B;AAInD,OAAO,EAAE,KAAK,EAAE,iCAAmB;AACnC,OAAO,EAAE,aAAa,EAAE,0CAA4B;AAEpD,OAAO,uBAAuB,CAAC;AAC/B,OAAO,qBAAqB,CAAC;AAC7B,OAAO,EAAE,eAAe,EAAE,qDAAuC;AAEjE,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,6DAA+C;AAE7F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AC,YAAY,CAAC,EAAE;YACtG,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,MAAM,EAAE,KAAK,CAAC,aAAa,EAAE,CAAC,CAAC;SAC/D;QAED,MAAM;QACN,cAAc,CAAC,iBAAiB,CAAC,KAAK,EAAE,IAAI,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;QAElE,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IAC9C,CAAC;IAEM,KAAK,CAAC,IAAY;QACrB,OAAO,mBAAmB,CAAC,KAAK,CAAqB,GAAG,EAAE,CAAC,IAAI,kBAAkB,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC;IACpH,CAAC;IAEM,SAAS;QACZ,MAAM,mBAAmB,GAAG,KAAK,CAAC,SAAS,EAAE,CAAC;QAC9C,mBAAmB,CAAC,UAAU,GAAG,4BAA4B,CAAC;QAC9D,OAAO,mBAAmB,CAAC;IAC/B,CAAC;IAEM,YAAY;QACf,OAAO,oBAAoB,CAAC;IAChC,CAAC;IAED,UAAU;IACH,MAAM,CAAC,KAAK,CAAC,MAAW,EAAE,KAAY,EAAE,OAAe;QAC1D,OAAO,mBAAmB,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,kBAAkB,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;IAC/G,CAAC;CACJ;AAED,aAAa,CAAC,4BAA4B,EAAE,kBAAkB,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { Nullable } from \"core/types\";\r\nimport { SerializationHelper } from \"core/Misc/decorators\";\r\nimport type { Matrix } from \"core/Maths/math.vector\";\r\nimport { Color3 } from \"core/Maths/math.color\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport type { IShadowLight } from \"core/Lights/shadowLight\";\r\nimport type { IEffectCreationOptions } from \"core/Materials/effect\";\r\nimport { MaterialDefines } from \"core/Materials/materialDefines\";\r\nimport { MaterialHelper } from \"core/Materials/materialHelper\";\r\nimport { PushMaterial } from \"core/Materials/pushMaterial\";\r\nimport { VertexBuffer } from \"core/Buffers/buffer\";\r\nimport type { AbstractMesh } from \"core/Meshes/abstractMesh\";\r\nimport type { SubMesh } from \"core/Meshes/subMesh\";\r\nimport type { Mesh } from \"core/Meshes/mesh\";\r\nimport { Scene } from \"core/scene\";\r\nimport { RegisterClass } from \"core/Misc/typeStore\";\r\n\r\nimport \"./shadowOnly.fragment\";\r\nimport \"./shadowOnly.vertex\";\r\nimport { EffectFallbacks } from \"core/Materials/effectFallbacks\";\r\nimport type { CascadedShadowGenerator } from \"core/Lights/Shadows/cascadedShadowGenerator\";\r\nimport { addClipPlaneUniforms, bindClipPlane } from \"core/Materials/clipPlaneMaterialHelper\";\r\n\r\nclass ShadowOnlyMaterialDefines extends MaterialDefines {\r\n public CLIPPLANE = false;\r\n public CLIPPLANE2 = false;\r\n public CLIPPLANE3 = false;\r\n public CLIPPLANE4 = false;\r\n public CLIPPLANE5 = false;\r\n public CLIPPLANE6 = false;\r\n public POINTSIZE = false;\r\n public FOG = false;\r\n public NORMAL = false;\r\n public NUM_BONE_INFLUENCERS = 0;\r\n public BonesPerMesh = 0;\r\n public INSTANCES = false;\r\n public IMAGEPROCESSINGPOSTPROCESS = false;\r\n public SKIPFINALCOLORCLAMP = false;\r\n public LOGARITHMICDEPTH = false;\r\n\r\n constructor() {\r\n super();\r\n this.rebuild();\r\n }\r\n}\r\n\r\nexport class ShadowOnlyMaterial extends PushMaterial {\r\n private _activeLight: IShadowLight;\r\n private _needAlphaBlending = true;\r\n\r\n constructor(name: string, scene?: Scene) {\r\n super(name, scene);\r\n }\r\n\r\n public shadowColor = Color3.Black();\r\n\r\n public needAlphaBlending(): boolean {\r\n return this._needAlphaBlending;\r\n }\r\n\r\n public needAlphaTesting(): boolean {\r\n return false;\r\n }\r\n\r\n public getAlphaTestTexture(): Nullable<BaseTexture> {\r\n return null;\r\n }\r\n\r\n public get activeLight(): IShadowLight {\r\n return this._activeLight;\r\n }\r\n\r\n public set activeLight(light: IShadowLight) {\r\n this._activeLight = light;\r\n }\r\n\r\n private _getFirstShadowLightForMesh(mesh: AbstractMesh): Nullable<IShadowLight> {\r\n for (const light of mesh.lightSources) {\r\n if (light.shadowEnabled) {\r\n return light as IShadowLight;\r\n }\r\n }\r\n return null;\r\n }\r\n\r\n // Methods\r\n public isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean {\r\n if (this.isFrozen) {\r\n if (subMesh.effect && subMesh.effect._wasPreviouslyReady && subMesh.effect._wasPreviouslyUsingInstances === useInstances) {\r\n return true;\r\n }\r\n }\r\n\r\n if (!subMesh.materialDefines) {\r\n subMesh.materialDefines = new ShadowOnlyMaterialDefines();\r\n }\r\n\r\n const defines = <ShadowOnlyMaterialDefines>subMesh.materialDefines;\r\n const scene = this.getScene();\r\n\r\n if (this._isReadyForSubMesh(subMesh)) {\r\n return true;\r\n }\r\n\r\n const engine = scene.getEngine();\r\n\r\n // Ensure that active light is the first shadow light\r\n if (this._activeLight) {\r\n for (const light of mesh.lightSources) {\r\n if (light.shadowEnabled) {\r\n if (this._activeLight === light) {\r\n break; // We are good\r\n }\r\n\r\n const lightPosition = mesh.lightSources.indexOf(this._activeLight);\r\n\r\n if (lightPosition !== -1) {\r\n mesh.lightSources.splice(lightPosition, 1);\r\n mesh.lightSources.splice(0, 0, this._activeLight);\r\n }\r\n break;\r\n }\r\n }\r\n }\r\n\r\n MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, this, defines, useInstances ? true : false);\r\n\r\n MaterialHelper.PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines);\r\n\r\n defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, 1);\r\n\r\n const shadowGenerator = this._getFirstShadowLightForMesh(mesh)?.getShadowGenerator();\r\n\r\n this._needAlphaBlending = true;\r\n\r\n if (shadowGenerator && (shadowGenerator as any).getClassName && (shadowGenerator as any).getClassName() === \"CascadedShadowGenerator\") {\r\n const csg = shadowGenerator as CascadedShadowGenerator;\r\n\r\n this._needAlphaBlending = !csg.autoCalcDepthBounds;\r\n }\r\n\r\n // Attribs\r\n MaterialHelper.PrepareDefinesForAttributes(mesh, defines, false, true);\r\n\r\n // Get correct effect\r\n if (defines.isDirty) {\r\n defines.markAsProcessed();\r\n\r\n scene.resetCachedMaterial();\r\n\r\n // Fallbacks\r\n const fallbacks = new EffectFallbacks();\r\n if (defines.FOG) {\r\n fallbacks.addFallback(1, \"FOG\");\r\n }\r\n\r\n MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, 1);\r\n\r\n if (defines.NUM_BONE_INFLUENCERS > 0) {\r\n fallbacks.addCPUSkinningFallback(0, mesh);\r\n }\r\n\r\n defines.IMAGEPROCESSINGPOSTPROCESS = scene.imageProcessingConfiguration.applyByPostProcess;\r\n\r\n //Attributes\r\n const attribs = [VertexBuffer.PositionKind];\r\n\r\n if (defines.NORMAL) {\r\n attribs.push(VertexBuffer.NormalKind);\r\n }\r\n\r\n MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);\r\n MaterialHelper.PrepareAttributesForInstances(attribs, defines);\r\n\r\n const shaderName = \"shadowOnly\";\r\n const join = defines.toString();\r\n const uniforms = [\r\n \"world\",\r\n \"view\",\r\n \"viewProjection\",\r\n \"vEyePosition\",\r\n \"vLightsType\",\r\n \"vFogInfos\",\r\n \"vFogColor\",\r\n \"pointSize\",\r\n \"alpha\",\r\n \"shadowColor\",\r\n \"mBones\",\r\n \"logarithmicDepthConstant\",\r\n ];\r\n const samplers: string[] = [];\r\n\r\n const uniformBuffers: string[] = [];\r\n\r\n addClipPlaneUniforms(uniforms);\r\n MaterialHelper.PrepareUniformsAndSamplersList(<IEffectCreationOptions>{\r\n uniformsNames: uniforms,\r\n uniformBuffersNames: uniformBuffers,\r\n samplers: samplers,\r\n defines: defines,\r\n maxSimultaneousLights: 1,\r\n });\r\n\r\n subMesh.setEffect(\r\n scene.getEngine().createEffect(\r\n shaderName,\r\n <IEffectCreationOptions>{\r\n attributes: attribs,\r\n uniformsNames: uniforms,\r\n uniformBuffersNames: uniformBuffers,\r\n samplers: samplers,\r\n defines: join,\r\n fallbacks: fallbacks,\r\n onCompiled: this.onCompiled,\r\n onError: this.onError,\r\n indexParameters: { maxSimultaneousLights: 1 },\r\n },\r\n engine\r\n ),\r\n defines,\r\n this._materialContext\r\n );\r\n }\r\n if (!subMesh.effect || !subMesh.effect.isReady()) {\r\n return false;\r\n }\r\n\r\n defines._renderId = scene.getRenderId();\r\n subMesh.effect._wasPreviouslyReady = true;\r\n subMesh.effect._wasPreviouslyUsingInstances = !!useInstances;\r\n\r\n return true;\r\n }\r\n\r\n public bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void {\r\n const scene = this.getScene();\r\n\r\n const defines = <ShadowOnlyMaterialDefines>subMesh.materialDefines;\r\n if (!defines) {\r\n return;\r\n }\r\n\r\n const effect = subMesh.effect;\r\n if (!effect) {\r\n return;\r\n }\r\n this._activeEffect = effect;\r\n\r\n // Matrices\r\n this.bindOnlyWorldMatrix(world);\r\n this._activeEffect.setMatrix(\"viewProjection\", scene.getTransformMatrix());\r\n\r\n // Bones\r\n MaterialHelper.BindBonesParameters(mesh, this._activeEffect);\r\n\r\n if (this._mustRebind(scene, effect)) {\r\n // Clip plane\r\n bindClipPlane(effect, this, scene);\r\n\r\n // Point size\r\n if (this.pointsCloud) {\r\n this._activeEffect.setFloat(\"pointSize\", this.pointSize);\r\n }\r\n\r\n this._activeEffect.setFloat(\"alpha\", this.alpha);\r\n this._activeEffect.setColor3(\"shadowColor\", this.shadowColor);\r\n\r\n // Log. depth\r\n if (this._useLogarithmicDepth) {\r\n MaterialHelper.BindLogDepth(defines, effect, scene);\r\n }\r\n\r\n scene.bindEyePosition(effect);\r\n }\r\n\r\n // Lights\r\n if (scene.lightsEnabled) {\r\n MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, 1);\r\n\r\n const light = this._getFirstShadowLightForMesh(mesh);\r\n\r\n if (light) {\r\n // Make sure the uniforms for this light will be rebound for other materials using this light when rendering the current frame.\r\n // Indeed, there is an optimization in Light that binds the light uniforms only once per frame for a given light (if using ubo).\r\n // Doing this way assumes that all uses of this light are the same, meaning all parameters passed to Light._bindLlight\r\n // are the same, notably useSpecular. However, isReadyForSubMesh (see above) is passing false for this parameter, which may not be\r\n // the value the other materials may pass.\r\n light._renderId = -1;\r\n }\r\n }\r\n\r\n // View\r\n if ((scene.fogEnabled && mesh.applyFog && scene.fogMode !== Scene.FOGMODE_NONE) || defines[\"SHADOWCSM0\"]) {\r\n this._activeEffect.setMatrix(\"view\", scene.getViewMatrix());\r\n }\r\n\r\n // Fog\r\n MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);\r\n\r\n this._afterBind(mesh, this._activeEffect);\r\n }\r\n\r\n public clone(name: string): ShadowOnlyMaterial {\r\n return SerializationHelper.Clone<ShadowOnlyMaterial>(() => new ShadowOnlyMaterial(name, this.getScene()), this);\r\n }\r\n\r\n public serialize(): any {\r\n const serializationObject = super.serialize();\r\n serializationObject.customType = \"BABYLON.ShadowOnlyMaterial\";\r\n return serializationObject;\r\n }\r\n\r\n public getClassName(): string {\r\n return \"ShadowOnlyMaterial\";\r\n }\r\n\r\n // Statics\r\n public static Parse(source: any, scene: Scene, rootUrl: string): ShadowOnlyMaterial {\r\n return SerializationHelper.Parse(() => new ShadowOnlyMaterial(source.name, scene), source, scene, rootUrl);\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.ShadowOnlyMaterial\", ShadowOnlyMaterial);\r\n"]}
1
+ {"version":3,"file":"shadowOnlyMaterial.js","sourceRoot":"","sources":["../../../../dev/materials/src/shadowOnly/sh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E,KAAY,EAAE,OAAe;QAC1D,OAAO,mBAAmB,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,kBAAkB,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;IAC/G,CAAC;CACJ;AAED,aAAa,CAAC,4BAA4B,EAAE,kBAAkB,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { Nullable } from \"core/types\";\r\nimport { SerializationHelper } from \"core/Misc/decorators\";\r\nimport type { Matrix } from \"core/Maths/math.vector\";\r\nimport { Color3 } from \"core/Maths/math.color\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport type { IShadowLight } from \"core/Lights/shadowLight\";\r\nimport type { IEffectCreationOptions } from \"core/Materials/effect\";\r\nimport { MaterialDefines } from \"core/Materials/materialDefines\";\r\nimport { MaterialHelper } from \"core/Materials/materialHelper\";\r\nimport { PushMaterial } from \"core/Materials/pushMaterial\";\r\nimport { VertexBuffer } from \"core/Buffers/buffer\";\r\nimport type { AbstractMesh } from \"core/Meshes/abstractMesh\";\r\nimport type { SubMesh } from \"core/Meshes/subMesh\";\r\nimport type { Mesh } from \"core/Meshes/mesh\";\r\nimport { Scene } from \"core/scene\";\r\nimport { RegisterClass } from \"core/Misc/typeStore\";\r\n\r\nimport \"./shadowOnly.fragment\";\r\nimport \"./shadowOnly.vertex\";\r\nimport { EffectFallbacks } from \"core/Materials/effectFallbacks\";\r\nimport type { CascadedShadowGenerator } from \"core/Lights/Shadows/cascadedShadowGenerator\";\r\nimport { addClipPlaneUniforms, bindClipPlane } from \"core/Materials/clipPlaneMaterialHelper\";\r\n\r\nclass ShadowOnlyMaterialDefines extends MaterialDefines {\r\n public CLIPPLANE = false;\r\n public CLIPPLANE2 = false;\r\n public CLIPPLANE3 = false;\r\n public CLIPPLANE4 = false;\r\n public CLIPPLANE5 = false;\r\n public CLIPPLANE6 = false;\r\n public POINTSIZE = false;\r\n public FOG = false;\r\n public NORMAL = false;\r\n public NUM_BONE_INFLUENCERS = 0;\r\n public BonesPerMesh = 0;\r\n public INSTANCES = false;\r\n public IMAGEPROCESSINGPOSTPROCESS = false;\r\n public SKIPFINALCOLORCLAMP = false;\r\n public LOGARITHMICDEPTH = false;\r\n\r\n constructor() {\r\n super();\r\n this.rebuild();\r\n }\r\n}\r\n\r\nexport class ShadowOnlyMaterial extends PushMaterial {\r\n private _activeLight: IShadowLight;\r\n private _needAlphaBlending = true;\r\n\r\n constructor(name: string, scene?: Scene) {\r\n super(name, scene);\r\n }\r\n\r\n public shadowColor = Color3.Black();\r\n\r\n public needAlphaBlending(): boolean {\r\n return this._needAlphaBlending;\r\n }\r\n\r\n public needAlphaTesting(): boolean {\r\n return false;\r\n }\r\n\r\n public getAlphaTestTexture(): Nullable<BaseTexture> {\r\n return null;\r\n }\r\n\r\n public get activeLight(): IShadowLight {\r\n return this._activeLight;\r\n }\r\n\r\n public set activeLight(light: IShadowLight) {\r\n this._activeLight = light;\r\n }\r\n\r\n private _getFirstShadowLightForMesh(mesh: AbstractMesh): Nullable<IShadowLight> {\r\n for (const light of mesh.lightSources) {\r\n if (light.shadowEnabled) {\r\n return light as IShadowLight;\r\n }\r\n }\r\n return null;\r\n }\r\n\r\n // Methods\r\n public isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean {\r\n if (this.isFrozen) {\r\n if (subMesh.effect && subMesh.effect._wasPreviouslyReady && subMesh.effect._wasPreviouslyUsingInstances === useInstances) {\r\n return true;\r\n }\r\n }\r\n\r\n if (!subMesh.materialDefines) {\r\n subMesh.materialDefines = new ShadowOnlyMaterialDefines();\r\n }\r\n\r\n const defines = <ShadowOnlyMaterialDefines>subMesh.materialDefines;\r\n const scene = this.getScene();\r\n\r\n if (this._isReadyForSubMesh(subMesh)) {\r\n return true;\r\n }\r\n\r\n const engine = scene.getEngine();\r\n\r\n // Ensure that active light is the first shadow light\r\n if (this._activeLight) {\r\n for (const light of mesh.lightSources) {\r\n if (light.shadowEnabled) {\r\n if (this._activeLight === light) {\r\n break; // We are good\r\n }\r\n\r\n const lightPosition = mesh.lightSources.indexOf(this._activeLight);\r\n\r\n if (lightPosition !== -1) {\r\n mesh.lightSources.splice(lightPosition, 1);\r\n mesh.lightSources.splice(0, 0, this._activeLight);\r\n }\r\n break;\r\n }\r\n }\r\n }\r\n\r\n MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, this, defines, useInstances ? true : false);\r\n\r\n MaterialHelper.PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines);\r\n\r\n defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, 1);\r\n\r\n const shadowGenerator = this._getFirstShadowLightForMesh(mesh)?.getShadowGenerator();\r\n\r\n this._needAlphaBlending = true;\r\n\r\n if (shadowGenerator && (shadowGenerator as any).getClassName && (shadowGenerator as any).getClassName() === \"CascadedShadowGenerator\") {\r\n const csg = shadowGenerator as CascadedShadowGenerator;\r\n\r\n this._needAlphaBlending = !csg.autoCalcDepthBounds;\r\n }\r\n\r\n // Attribs\r\n MaterialHelper.PrepareDefinesForAttributes(mesh, defines, false, true);\r\n\r\n // Get correct effect\r\n if (defines.isDirty) {\r\n defines.markAsProcessed();\r\n\r\n scene.resetCachedMaterial();\r\n\r\n // Fallbacks\r\n const fallbacks = new EffectFallbacks();\r\n if (defines.FOG) {\r\n fallbacks.addFallback(1, \"FOG\");\r\n }\r\n\r\n MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, 1);\r\n\r\n if (defines.NUM_BONE_INFLUENCERS > 0) {\r\n fallbacks.addCPUSkinningFallback(0, mesh);\r\n }\r\n\r\n defines.IMAGEPROCESSINGPOSTPROCESS = scene.imageProcessingConfiguration.applyByPostProcess;\r\n\r\n //Attributes\r\n const attribs = [VertexBuffer.PositionKind];\r\n\r\n if (defines.NORMAL) {\r\n attribs.push(VertexBuffer.NormalKind);\r\n }\r\n\r\n MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);\r\n MaterialHelper.PrepareAttributesForInstances(attribs, defines);\r\n\r\n const shaderName = \"shadowOnly\";\r\n const join = defines.toString();\r\n const uniforms = [\r\n \"world\",\r\n \"view\",\r\n \"viewProjection\",\r\n \"vEyePosition\",\r\n \"vLightsType\",\r\n \"vFogInfos\",\r\n \"vFogColor\",\r\n \"pointSize\",\r\n \"alpha\",\r\n \"shadowColor\",\r\n \"mBones\",\r\n \"logarithmicDepthConstant\",\r\n ];\r\n const samplers: string[] = [];\r\n\r\n const uniformBuffers: string[] = [];\r\n\r\n addClipPlaneUniforms(uniforms);\r\n MaterialHelper.PrepareUniformsAndSamplersList(<IEffectCreationOptions>{\r\n uniformsNames: uniforms,\r\n uniformBuffersNames: uniformBuffers,\r\n samplers: samplers,\r\n defines: defines,\r\n maxSimultaneousLights: 1,\r\n });\r\n\r\n subMesh.setEffect(\r\n scene.getEngine().createEffect(\r\n shaderName,\r\n <IEffectCreationOptions>{\r\n attributes: attribs,\r\n uniformsNames: uniforms,\r\n uniformBuffersNames: uniformBuffers,\r\n samplers: samplers,\r\n defines: join,\r\n fallbacks: fallbacks,\r\n onCompiled: this.onCompiled,\r\n onError: this.onError,\r\n indexParameters: { maxSimultaneousLights: 1 },\r\n },\r\n engine\r\n ),\r\n defines,\r\n this._materialContext\r\n );\r\n }\r\n if (!subMesh.effect || !subMesh.effect.isReady()) {\r\n return false;\r\n }\r\n\r\n defines._renderId = scene.getRenderId();\r\n subMesh.effect._wasPreviouslyReady = true;\r\n subMesh.effect._wasPreviouslyUsingInstances = !!useInstances;\r\n\r\n return true;\r\n }\r\n\r\n public bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void {\r\n const scene = this.getScene();\r\n\r\n const defines = <ShadowOnlyMaterialDefines>subMesh.materialDefines;\r\n if (!defines) {\r\n return;\r\n }\r\n\r\n const effect = subMesh.effect;\r\n if (!effect) {\r\n return;\r\n }\r\n this._activeEffect = effect;\r\n\r\n // Matrices\r\n this.bindOnlyWorldMatrix(world);\r\n this._activeEffect.setMatrix(\"viewProjection\", scene.getTransformMatrix());\r\n\r\n // Bones\r\n MaterialHelper.BindBonesParameters(mesh, this._activeEffect);\r\n\r\n if (this._mustRebind(scene, effect)) {\r\n // Clip plane\r\n bindClipPlane(effect, this, scene);\r\n\r\n // Point size\r\n if (this.pointsCloud) {\r\n this._activeEffect.setFloat(\"pointSize\", this.pointSize);\r\n }\r\n\r\n this._activeEffect.setFloat(\"alpha\", this.alpha);\r\n this._activeEffect.setColor3(\"shadowColor\", this.shadowColor);\r\n\r\n // Log. depth\r\n if (this._useLogarithmicDepth) {\r\n MaterialHelper.BindLogDepth(defines, effect, scene);\r\n }\r\n\r\n scene.bindEyePosition(effect);\r\n }\r\n\r\n // Lights\r\n if (scene.lightsEnabled) {\r\n MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, 1);\r\n\r\n const light = this._getFirstShadowLightForMesh(mesh);\r\n\r\n if (light) {\r\n // Make sure the uniforms for this light will be rebound for other materials using this light when rendering the current frame.\r\n // Indeed, there is an optimization in Light that binds the light uniforms only once per frame for a given light (if using ubo).\r\n // Doing this way assumes that all uses of this light are the same, meaning all parameters passed to Light._bindLlight\r\n // are the same, notably useSpecular. However, isReadyForSubMesh (see above) is passing false for this parameter, which may not be\r\n // the value the other materials may pass.\r\n light._renderId = -1;\r\n }\r\n }\r\n\r\n // View\r\n if ((scene.fogEnabled && mesh.applyFog && scene.fogMode !== Scene.FOGMODE_NONE) || defines[\"SHADOWCSM0\"]) {\r\n this._activeEffect.setMatrix(\"view\", scene.getViewMatrix());\r\n }\r\n\r\n // Fog\r\n MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);\r\n\r\n this._afterBind(mesh, this._activeEffect);\r\n }\r\n\r\n public clone(name: string): ShadowOnlyMaterial {\r\n return SerializationHelper.Clone<ShadowOnlyMaterial>(() => new ShadowOnlyMaterial(name, this.getScene()), this);\r\n }\r\n\r\n public serialize(): any {\r\n const serializationObject = super.serialize();\r\n serializationObject.customType = \"BABYLON.ShadowOnlyMaterial\";\r\n return serializationObject;\r\n }\r\n\r\n public getClassName(): string {\r\n return \"ShadowOnlyMaterial\";\r\n }\r\n\r\n // Statics\r\n public static Parse(source: any, scene: Scene, rootUrl: string): ShadowOnlyMaterial {\r\n return SerializationHelper.Parse(() => new ShadowOnlyMaterial(source.name, scene), source, scene, rootUrl);\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.ShadowOnlyMaterial\", ShadowOnlyMaterial);\r\n"]}