Browse Source

Merge pull request #6035 from MackeyK24/master

PBRMaterialBase Custom Shader Name Resolve Support
David Catuhe 6 năm trước cách đây
mục cha
commit
d8c5e39550

+ 2 - 1
dist/preview release/what's new.md

@@ -8,7 +8,8 @@
 - Added [support for AmmoJS](https://doc.babylonjs.com/how_to/using_the_physics_engine) as a physics plugin (Composite objects, motors, joints) ([TrevorDev](https://github.com/TrevorDev))
   - Added support for soft bodies, which are 3D softbody, 2D cloth and 1D rope, in Ammo physics plugin. [Doc](https://doc.babylonjs.com/how_to/soft_bodies) ([JohnK](https://github.com/BabylonJSGuide))
   - Added support for [Convex Hull Impostor][https://github.com/kripken/ammo.js/blob/master/bullet/src/BulletCollision/CollisionShapes/btConvexHullShape.h] using Ammo.js plugin ([MackeyK24](https://github.com/mackeyk24))
-  - Added getShaderName to PBRMaterialBase to allow subclasses to specify custom PBR shaders [MackeyK24](https://github.com/mackeyk24))
+  - Added customShaderNameResolve to PBRMaterialBase to allow subclasses to specify custom shader information [MackeyK24](https://github.com/mackeyk24))
+  - Added PBRCustomMaterial to material library to allow easy subclassing of PBR materials [MackeyK24](https://github.com/mackeyk24))  
 - Added support for [WebXR](https://doc.babylonjs.com/how_to/webxr) ([TrevorDev](https://github.com/TrevorDev))
   - Add customAnimationFrameRequester to allow sessions to hook into engine's render loop ([TrevorDev](https://github.com/TrevorDev))
   - camera customDefaultRenderTarget to allow cameras to render to a custom render target (eg. xr framebuffer) instead of the canvas ([TrevorDev](https://github.com/TrevorDev))

+ 26 - 8
materialsLibrary/src/custom/customMaterial.ts

@@ -24,7 +24,10 @@ export class ShaderSpecialParts {
 
     // diffuseColor
     public Fragment_Custom_Diffuse: string;
-
+    // lights
+    public Fragment_Before_Lights: string;
+    // fog
+    public Fragment_Before_Fog: string;
     // alpha
     public Fragment_Custom_Alpha: string;
 
@@ -39,6 +42,9 @@ export class ShaderSpecialParts {
 
     // normalUpdated
     public Vertex_Before_NormalUpdated: string;
+
+    // mainEnd
+    public Vertex_MainEnd: string;
 }
 
 export class CustomMaterial extends StandardMaterial {
@@ -127,9 +133,8 @@ export class CustomMaterial extends StandardMaterial {
             .replace('#define CUSTOM_VERTEX_DEFINITIONS', (this._customUniform ? this._customUniform.join("\n") : "") + (this.CustomParts.Vertex_Definitions ? this.CustomParts.Vertex_Definitions : ""))
             .replace('#define CUSTOM_VERTEX_MAIN_BEGIN', (this.CustomParts.Vertex_MainBegin ? this.CustomParts.Vertex_MainBegin : ""))
             .replace('#define CUSTOM_VERTEX_UPDATE_POSITION', (this.CustomParts.Vertex_Before_PositionUpdated ? this.CustomParts.Vertex_Before_PositionUpdated : ""))
-            .replace('#define CUSTOM_VERTEX_UPDATE_NORMAL', (this.CustomParts.Vertex_Before_NormalUpdated ? this.CustomParts.Vertex_Before_NormalUpdated : ""));
-
-        // #define CUSTOM_VERTEX_MAIN_END
+            .replace('#define CUSTOM_VERTEX_UPDATE_NORMAL', (this.CustomParts.Vertex_Before_NormalUpdated ? this.CustomParts.Vertex_Before_NormalUpdated : ""))
+            .replace('#define CUSTOM_VERTEX_MAIN_END', (this.CustomParts.Vertex_MainEnd ? this.CustomParts.Vertex_MainEnd : ""));
 
         Effect.ShadersStore[name + "PixelShader"] = this.FragmentShader
             .replace('#define CUSTOM_FRAGMENT_BEGIN', (this.CustomParts.Fragment_Begin ? this.CustomParts.Fragment_Begin : ""))
@@ -137,12 +142,10 @@ export class CustomMaterial extends StandardMaterial {
             .replace('#define CUSTOM_FRAGMENT_DEFINITIONS', (this._customUniform ? this._customUniform.join("\n") : "") + (this.CustomParts.Fragment_Definitions ? this.CustomParts.Fragment_Definitions : ""))
             .replace('#define CUSTOM_FRAGMENT_UPDATE_DIFFUSE', (this.CustomParts.Fragment_Custom_Diffuse ? this.CustomParts.Fragment_Custom_Diffuse : ""))
             .replace('#define CUSTOM_FRAGMENT_UPDATE_ALPHA', (this.CustomParts.Fragment_Custom_Alpha ? this.CustomParts.Fragment_Custom_Alpha : ""))
+            .replace('#define CUSTOM_FRAGMENT_BEFORE_LIGHTS', (this.CustomParts.Fragment_Before_Lights ? this.CustomParts.Fragment_Before_Lights : ""))
+            .replace('#define CUSTOM_FRAGMENT_BEFORE_FOG', (this.CustomParts.Fragment_Before_Fog ? this.CustomParts.Fragment_Before_Fog : ""))
             .replace('#define CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR', (this.CustomParts.Fragment_Before_FragColor ? this.CustomParts.Fragment_Before_FragColor : ""));
 
-        // #define CUSTOM_FRAGMENT_BEFORE_LIGHTS
-
-        // #define CUSTOM_FRAGMENT_BEFORE_FOG
-
         this._isCreatedShader = true;
         this._createdShaderName = name;
 
@@ -204,6 +207,16 @@ export class CustomMaterial extends StandardMaterial {
         return this;
     }
 
+    public Fragment_Before_Lights(shaderPart: string): CustomMaterial {
+        this.CustomParts.Fragment_Before_Lights = shaderPart;
+        return this;
+    }
+
+    public Fragment_Before_Fog(shaderPart: string): CustomMaterial {
+        this.CustomParts.Fragment_Before_Fog = shaderPart;
+        return this;
+    }
+
     public Fragment_Before_FragColor(shaderPart: string): CustomMaterial {
         this.CustomParts.Fragment_Before_FragColor = shaderPart.replace("result", "color");
         return this;
@@ -233,6 +246,11 @@ export class CustomMaterial extends StandardMaterial {
         this.CustomParts.Vertex_Before_NormalUpdated = shaderPart.replace("result", "normalUpdated");
         return this;
     }
+
+    public Vertex_MainEnd(shaderPart: string): CustomMaterial {
+        this.CustomParts.Vertex_MainEnd = shaderPart;
+        return this;
+    }
 }
 
 _TypeStore.RegisteredTypes["BABYLON.CustomMaterial"] = CustomMaterial;

+ 2 - 1
materialsLibrary/src/custom/index.ts

@@ -1 +1,2 @@
-export * from "./customMaterial";
+export * from "./customMaterial";
+export * from "./pbrCustomMaterial";

+ 248 - 0
materialsLibrary/src/custom/pbrCustomMaterial.ts

@@ -0,0 +1,248 @@
+import { Texture } from "babylonjs/Materials/Textures/texture";
+import { Effect } from "babylonjs/Materials/effect";
+import { PBRMaterialDefines } from "babylonjs/Materials/PBR/pbrBaseMaterial";
+import { PBRMaterial } from "babylonjs/Materials/PBR/pbrMaterial";
+import { Mesh } from "babylonjs/Meshes/mesh";
+import { Scene } from "babylonjs/scene";
+import { _TypeStore } from 'babylonjs/Misc/typeStore';
+
+export class ShaderAlebdoParts {
+
+    constructor() { }
+
+    public Fragment_Begin: string;
+    public Fragment_Definitions: string;
+    public Fragment_MainBegin: string;
+
+    // albedoColor
+    public Fragment_Custom_Albedo: string;
+    // lights
+    public Fragment_Before_Lights: string;
+    // fog
+    public Fragment_Before_Fog: string;
+    // alpha
+    public Fragment_Custom_Alpha: string;
+
+    public Fragment_Before_FragColor: string;
+
+    public Vertex_Begin: string;
+    public Vertex_Definitions: string;
+    public Vertex_MainBegin: string;
+
+    // positionUpdated
+    public Vertex_Before_PositionUpdated: string;
+
+    // normalUpdated
+    public Vertex_Before_NormalUpdated: string;
+
+    // mainEnd
+    public Vertex_MainEnd: string;
+}
+
+export class PBRCustomMaterial extends PBRMaterial {
+    public static ShaderIndexer = 1;
+    public CustomParts: ShaderAlebdoParts;
+    _isCreatedShader: boolean;
+    _createdShaderName: string;
+    _customUniform: string[];
+    _newUniforms: string[];
+    _newUniformInstances: any[];
+    _newSamplerInstances: Texture[];
+
+    public FragmentShader: string;
+    public VertexShader: string;
+
+    public AttachAfterBind(mesh: Mesh, effect: Effect) {
+        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') {
+                effect.setVector3(ea[1], this._newUniformInstances[el]);
+            }
+            else if (ea[0] == 'vec4') {
+                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]);
+            }
+        }
+        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]);
+            }
+        }
+    }
+
+    public ReviewUniform(name: string, arr: string[]): string[] {
+        if (name == "uniform") {
+            for (var ind in this._newUniforms) {
+                if (this._customUniform[ind].indexOf('sampler') == -1) {
+                    arr.push(this._newUniforms[ind]);
+                }
+            }
+        }
+        if (name == "sampler") {
+            for (var ind in this._newUniforms) {
+                if (this._customUniform[ind].indexOf('sampler') != -1) {
+                    arr.push(this._newUniforms[ind]);
+                }
+            }
+        }
+        return arr;
+    }
+
+    public Builder(shaderName: string, uniforms: string[], uniformBuffers: string[], samplers: string[], defines: PBRMaterialDefines): string {
+
+        if (this._isCreatedShader) {
+            return this._createdShaderName;
+        }
+        this._isCreatedShader = false;
+
+        PBRCustomMaterial.ShaderIndexer++;
+        var name: string = "custom_" + PBRCustomMaterial.ShaderIndexer;
+
+        this.ReviewUniform("uniform", uniforms);
+        this.ReviewUniform("sampler", samplers);
+
+        var fn_afterBind = this._afterBind.bind(this);
+        this._afterBind = (m, e) => {
+            if (!e) {
+                return;
+            }
+            this.AttachAfterBind(m, e);
+            try { fn_afterBind(m, e); }
+            catch (e) { }
+        };
+
+        Effect.ShadersStore[name + "VertexShader"] = this.VertexShader
+            .replace('#define CUSTOM_VERTEX_BEGIN', (this.CustomParts.Vertex_Begin ? this.CustomParts.Vertex_Begin : ""))
+            .replace('#define CUSTOM_VERTEX_DEFINITIONS', (this._customUniform ? this._customUniform.join("\n") : "") + (this.CustomParts.Vertex_Definitions ? this.CustomParts.Vertex_Definitions : ""))
+            .replace('#define CUSTOM_VERTEX_MAIN_BEGIN', (this.CustomParts.Vertex_MainBegin ? this.CustomParts.Vertex_MainBegin : ""))
+            .replace('#define CUSTOM_VERTEX_UPDATE_POSITION', (this.CustomParts.Vertex_Before_PositionUpdated ? this.CustomParts.Vertex_Before_PositionUpdated : ""))
+            .replace('#define CUSTOM_VERTEX_UPDATE_NORMAL', (this.CustomParts.Vertex_Before_NormalUpdated ? this.CustomParts.Vertex_Before_NormalUpdated : ""))
+            .replace('#define CUSTOM_VERTEX_MAIN_END', (this.CustomParts.Vertex_MainEnd ? this.CustomParts.Vertex_MainEnd : ""));
+
+        Effect.ShadersStore[name + "PixelShader"] = this.FragmentShader
+            .replace('#define CUSTOM_FRAGMENT_BEGIN', (this.CustomParts.Fragment_Begin ? this.CustomParts.Fragment_Begin : ""))
+            .replace('#define CUSTOM_FRAGMENT_MAIN_BEGIN', (this.CustomParts.Fragment_MainBegin ? this.CustomParts.Fragment_MainBegin : ""))
+            .replace('#define CUSTOM_FRAGMENT_DEFINITIONS', (this._customUniform ? this._customUniform.join("\n") : "") + (this.CustomParts.Fragment_Definitions ? this.CustomParts.Fragment_Definitions : ""))
+            .replace('#define CUSTOM_FRAGMENT_UPDATE_ALBEDO', (this.CustomParts.Fragment_Custom_Albedo ? this.CustomParts.Fragment_Custom_Albedo : ""))
+            .replace('#define CUSTOM_FRAGMENT_UPDATE_ALPHA', (this.CustomParts.Fragment_Custom_Alpha ? this.CustomParts.Fragment_Custom_Alpha : ""))
+            .replace('#define CUSTOM_FRAGMENT_BEFORE_LIGHTS', (this.CustomParts.Fragment_Before_Lights ? this.CustomParts.Fragment_Before_Lights : ""))
+            .replace('#define CUSTOM_FRAGMENT_BEFORE_FOG', (this.CustomParts.Fragment_Before_Fog ? this.CustomParts.Fragment_Before_Fog : ""))
+            .replace('#define CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR', (this.CustomParts.Fragment_Before_FragColor ? this.CustomParts.Fragment_Before_FragColor : ""));
+
+        this._isCreatedShader = true;
+        this._createdShaderName = name;
+
+        return name;
+    }
+
+    constructor(name: string, scene: Scene) {
+        super(name, scene);
+        this.CustomParts = new ShaderAlebdoParts();
+        this.customShaderNameResolve = this.Builder;
+
+        this.FragmentShader = Effect.ShadersStore["pbrPixelShader"];
+        this.VertexShader = Effect.ShadersStore["pbrVertexShader"];
+    }
+
+    public AddUniform(name: string, kind: string, param: any): PBRCustomMaterial {
+        if (!this._customUniform) {
+            this._customUniform = new Array();
+            this._newUniforms = new Array();
+            this._newSamplerInstances = new Array();
+            this._newUniformInstances = new Array();
+        }
+        if (param) {
+            if (kind.indexOf("sampler") == -1) {
+                (<any>this._newUniformInstances)[kind + "-" + name] = param;
+            }
+            else {
+                (<any>this._newUniformInstances)[kind + "-" + name] = param;
+            }
+        }
+        this._customUniform.push("uniform " + kind + " " + name + ";");
+        this._newUniforms.push(name);
+
+        return this;
+    }
+
+    public Fragment_Begin(shaderPart: string): PBRCustomMaterial {
+        this.CustomParts.Fragment_Begin = shaderPart;
+        return this;
+    }
+
+    public Fragment_Definitions(shaderPart: string): PBRCustomMaterial {
+        this.CustomParts.Fragment_Definitions = shaderPart;
+        return this;
+    }
+
+    public Fragment_MainBegin(shaderPart: string): PBRCustomMaterial {
+        this.CustomParts.Fragment_MainBegin = shaderPart;
+        return this;
+    }
+
+    public Fragment_Custom_Albedo(shaderPart: string): PBRCustomMaterial {
+        this.CustomParts.Fragment_Custom_Albedo = shaderPart.replace("result", "surfaceAlbedo");
+        return this;
+    }
+
+    public Fragment_Custom_Alpha(shaderPart: string): PBRCustomMaterial {
+        this.CustomParts.Fragment_Custom_Alpha = shaderPart.replace("result", "alpha");
+        return this;
+    }
+
+    public Fragment_Before_Lights(shaderPart: string): PBRCustomMaterial {
+        this.CustomParts.Fragment_Before_Lights = shaderPart;
+        return this;
+    }
+
+    public Fragment_Before_Fog(shaderPart: string): PBRCustomMaterial {
+        this.CustomParts.Fragment_Before_Fog = shaderPart;
+        return this;
+    }
+
+    public Fragment_Before_FragColor(shaderPart: string): PBRCustomMaterial {
+        this.CustomParts.Fragment_Before_FragColor = shaderPart.replace("result", "color");
+        return this;
+    }
+
+    public Vertex_Begin(shaderPart: string): PBRCustomMaterial {
+        this.CustomParts.Vertex_Begin = shaderPart;
+        return this;
+    }
+
+    public Vertex_Definitions(shaderPart: string): PBRCustomMaterial {
+        this.CustomParts.Vertex_Definitions = shaderPart;
+        return this;
+    }
+
+    public Vertex_MainBegin(shaderPart: string): PBRCustomMaterial {
+        this.CustomParts.Vertex_MainBegin = shaderPart;
+        return this;
+    }
+
+    public Vertex_Before_PositionUpdated(shaderPart: string): PBRCustomMaterial {
+        this.CustomParts.Vertex_Before_PositionUpdated = shaderPart.replace("result", "positionUpdated");
+        return this;
+    }
+
+    public Vertex_Before_NormalUpdated(shaderPart: string): PBRCustomMaterial {
+        this.CustomParts.Vertex_Before_NormalUpdated = shaderPart.replace("result", "normalUpdated");
+        return this;
+    }
+
+    public Vertex_MainEnd(shaderPart: string): PBRCustomMaterial {
+        this.CustomParts.Vertex_MainEnd = shaderPart;
+        return this;
+    }
+}
+
+_TypeStore.RegisteredTypes["BABYLON.PBRCustomMaterial"] = PBRCustomMaterial;

+ 15 - 4
materialsLibrary/src/custom/readme.md

@@ -1,10 +1,13 @@
 
-CustomMaterial
-==============
+Custom Materials
+================
 
 ### CustomMaterial is a StandardMaterial with some customizable Options 
+
+### PBRCustomMaterial is a PBRMaterial with some customizable Options 
+
 1- manage part of current shader
-> CustomMaterial put some part of shader in special part of current shader and make new shader in ShaderStore 
+> CustomMaterial or PBRCustomMaterial put some part of shader in special part of current shader and make new shader in ShaderStore 
  > shaders struct  :
  >
  >   [ Begin ]
@@ -28,7 +31,7 @@ CustomMaterial
 
 
 method : SelectVersion(ver:string) 
-> Custom material for now Supported just ver 3.0.0 of BabylonJs and this is default of currentVersion for now
+> Custom materials for now Supported just ver 3.0.0 of BabylonJs and this is default of currentVersion for now
 > Add other old version in Progress %
   
   
@@ -56,6 +59,7 @@ method : Fragment_MainBegin(shaderPart:string):CustomMaterial
 > shaderPart is Shader Structure append in start place of the main function in fragment shader 
 
 
+**CustomMaterial Only**
 method : Fragment_Custom_Diffuse(shaderPart:string):CustomMaterial 
 > shaderPart is Shader Structure append after diffuseColor is defined of the main function in fragment shader </br>
 > usage : new CustomMaterial(...).Fragment_Custom_Diffuse('diffuseColor = vec3(sin(vPositionW.x));')  </br>
@@ -63,6 +67,13 @@ method : Fragment_Custom_Diffuse(shaderPart:string):CustomMaterial
 > * diffuseColor is vec3 variable </br>
 > * you can use result (vec3) too that replaced by diffuseColor
 
+**PBRCustomMaterial Only**
+method : Fragment_Custom_Albedo(shaderPart:string):PBRCustomMaterial 
+> shaderPart is Shader Structure append after surfaceAlbedo is defined of the main function in fragment shader </br>
+> usage : new PBRCustomMaterial(...).Fragment_Custom_Albedo('surfaceAlbedo = vec3(sin(vPositionW.x));')  </br>
+>       : new PBRCustomMaterial(...).Fragment_Custom_Albedo('result = vec3(sin(vPositionW.x));')  </br>
+> * surfaceAlbedo is vec3 variable </br>
+> * you can use result (vec3) too that replaced by surfaceAlbedo
 
 method : Fragment_Custom_Alpha(shaderPart:string):CustomMaterial 
 > shaderPart is Shader Structure append when material need a alpha parameter in fragment shader </br>

+ 14 - 11
src/Materials/PBR/pbrBaseMaterial.ts

@@ -39,9 +39,9 @@ import "../../Shaders/pbr.vertex";
 
 /**
  * Manages the defines for the PBR Material.
- * @hiddenChildren
+ * @hidden
  */
-class PBRMaterialDefines extends MaterialDefines
+export class PBRMaterialDefines extends MaterialDefines
     implements IImageProcessingConfigurationDefines,
     IMaterialClearCoatDefines,
     IMaterialAnisotropicDefines,
@@ -726,6 +726,11 @@ export abstract class PBRBaseMaterial extends PushMaterial {
     public readonly sheen = new PBRSheenConfiguration(this._markAllSubMeshesAsTexturesDirty.bind(this));
 
     /**
+     * Custom callback helping to override the default shader used in the material.
+     */
+    public customShaderNameResolve: (shaderName: string, uniforms: string[], uniformBuffers: string[], samplers: string[], defines: PBRMaterialDefines) => string;
+
+    /**
      * Instantiates a new PBRMaterial instance.
      *
      * @param name The material name
@@ -777,14 +782,6 @@ export abstract class PBRBaseMaterial extends PushMaterial {
     }
 
     /**
-     * Gets the name of the material shader.
-     * @returns - string that specifies the shader program of the material.
-     */
-    public getShaderName(): string {
-        return "pbr";
-    }
-
-    /**
      * Enabled the use of logarithmic depth buffers, which is good for wide depth buffers.
      */
     @serialize()
@@ -1182,6 +1179,8 @@ export abstract class PBRBaseMaterial extends PushMaterial {
         MaterialHelper.PrepareAttributesForInstances(attribs, defines);
         MaterialHelper.PrepareAttributesForMorphTargets(attribs, mesh, defines);
 
+        var shaderName = "pbr";
+
         var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vAmbientColor", "vAlbedoColor", "vReflectivityColor", "vEmissiveColor", "visibility", "vReflectionColor",
             "vFogInfos", "vFogColor", "pointSize",
             "vAlbedoInfos", "vAmbientInfos", "vOpacityInfos", "vReflectionInfos", "vReflectionPosition", "vReflectionSize", "vEmissiveInfos", "vReflectivityInfos",
@@ -1228,8 +1227,12 @@ export abstract class PBRBaseMaterial extends PushMaterial {
             maxSimultaneousLights: this._maxSimultaneousLights
         });
 
+        if (this.customShaderNameResolve) {
+            shaderName = this.customShaderNameResolve(shaderName, uniforms, uniformBuffers, samplers, defines);
+        }
+
         var join = defines.toString();
-        return engine.createEffect(this.getShaderName(), <EffectCreationOptions>{
+        return engine.createEffect(shaderName, <EffectCreationOptions>{
             attributes: attribs,
             uniformsNames: uniforms,
             uniformBuffersNames: uniformBuffers,

+ 15 - 1
src/Shaders/pbr.fragment.fx

@@ -6,6 +6,8 @@
 #extension GL_EXT_shader_texture_lod : enable
 #endif
 
+#define CUSTOM_FRAGMENT_BEGIN
+
 #ifdef LOGARITHMICDEPTH
 #extension GL_EXT_frag_depth : enable
 #endif
@@ -44,9 +46,13 @@ precision highp float;
     #include<reflectionFunction>
 #endif
 
+#define CUSTOM_FRAGMENT_DEFINITIONS
+
 // _____________________________ MAIN FUNCTION ____________________________
 void main(void) {
 
+    #define CUSTOM_FRAGMENT_MAIN_BEGIN
+
     #include<clipPlaneFragment>
 
 // _____________________________ Geometry Information ____________________________
@@ -99,6 +105,8 @@ void main(void) {
     surfaceAlbedo *= vColor.rgb;
 #endif
 
+#define CUSTOM_FRAGMENT_UPDATE_ALBEDO
+
 // _____________________________ Alpha Information _______________________________
 #ifdef OPACITY
     vec4 opacityMap = texture2D(opacitySampler, vOpacityUV + uvOffset);
@@ -128,8 +136,12 @@ void main(void) {
     #endif
 #endif
 
+#define CUSTOM_FRAGMENT_UPDATE_ALPHA
+
 #include<depthPrePass>
 
+#define CUSTOM_FRAGMENT_BEFORE_LIGHTS
+
 // _____________________________ AO    Information _______________________________
     vec3 ambientOcclusionColor = vec3(1., 1., 1.);
 
@@ -1106,9 +1118,10 @@ void main(void) {
     #endif
 #endif
 
+#define CUSTOM_FRAGMENT_BEFORE_FOG
+
 // _____________________________ Finally ___________________________________________
     finalColor = max(finalColor, 0.0);
-
 #include<logDepthFragment>
 #include<fogFragment>(color, finalColor)
 
@@ -1128,6 +1141,7 @@ void main(void) {
     finalColor.rgb *= finalColor.a;
 #endif
 
+#define CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR
     gl_FragColor = finalColor;
 
 #include<pbrDebug>

+ 13 - 0
src/Shaders/pbr.vertex.fx

@@ -2,6 +2,8 @@
 
 #include<__decl__pbrVertex>
 
+#define CUSTOM_VERTEX_BEGIN
+
 // Attributes
 attribute vec3 position;
 #ifdef NORMAL
@@ -125,8 +127,12 @@ varying vec3 vDirectionW;
 #endif
 
 #include<logDepthDeclaration>
+#define CUSTOM_VERTEX_DEFINITIONS
 
 void main(void) {
+
+	#define CUSTOM_VERTEX_MAIN_BEGIN
+
     vec3 positionUpdated = position;
 #ifdef NORMAL
     vec3 normalUpdated = normal;
@@ -145,6 +151,10 @@ void main(void) {
     #endif
 #endif 
 
+#define CUSTOM_VERTEX_UPDATE_POSITION
+
+#define CUSTOM_VERTEX_UPDATE_NORMAL
+
 #include<instancesVertex>
 #include<bonesVertex>
 
@@ -376,4 +386,7 @@ void main(void) {
 
     // Log. depth
 #include<logDepthVertex>
+
+#define CUSTOM_VERTEX_MAIN_END
+
 }