@@ -54,6 +54,16 @@ var ForwardDiffuseLightPipeline = new Class({
5454 0 , 0 , 1
5555 ] ) ;
5656
57+ /**
58+ * Stores a default normal map, which is an object with a `glTexture` property that
59+ * maps to a 1x1 texture of the color #7f7fff created in the `boot` method.
60+ *
61+ * @name Phaser.Renderer.WebGL.Pipelines.ForwardDiffuseLightPipeline#defaultNormalMap
62+ * @type {object }
63+ * @since 3.25.0
64+ */
65+ this . defaultNormalMap ;
66+
5767 /**
5868 * Stores the previous number of lights rendered.
5969 *
@@ -64,6 +74,34 @@ var ForwardDiffuseLightPipeline = new Class({
6474 this . lightCount = 0 ;
6575 } ,
6676
77+ /**
78+ * Called when the Game has fully booted and the Renderer has finished setting up.
79+ *
80+ * By this stage all Game level systems are now in place and you can perform any final
81+ * tasks that the pipeline may need that relied on game systems such as the Texture Manager.
82+ *
83+ * @method Phaser.Renderer.WebGL.ForwardDiffuseLightPipeline#boot
84+ * @since 3.11.0
85+ */
86+ boot : function ( )
87+ {
88+ WebGLPipeline . prototype . boot . call ( this ) ;
89+
90+ var gl = this . gl ;
91+
92+ var tempTexture = gl . createTexture ( ) ;
93+
94+ gl . activeTexture ( gl . TEXTURE0 ) ;
95+
96+ gl . bindTexture ( gl . TEXTURE_2D , tempTexture ) ;
97+
98+ gl . texImage2D ( gl . TEXTURE_2D , 0 , gl . RGBA , 1 , 1 , 0 , gl . RGBA , gl . UNSIGNED_BYTE , new Uint8Array ( [ 127 , 127 , 255 , 255 ] ) ) ;
99+
100+ this . defaultNormalMap = { glTexture : tempTexture } ;
101+
102+ return this ;
103+ } ,
104+
67105 /**
68106 * Called every time the pipeline is bound by the renderer.
69107 * Sets the shader program, vertex buffer and other resources.
@@ -292,14 +330,16 @@ var ForwardDiffuseLightPipeline = new Class({
292330 }
293331 }
294332
295- if ( normalTexture )
333+ if ( ! normalTexture )
296334 {
297- TextureTintPipeline . prototype . batchTexture . call ( this , gameObject , texture , textureWidth , textureHeight , srcX , srcY , srcWidth , srcHeight , scaleX , scaleY , rotation , flipX , flipY , scrollFactorX , scrollFactorY , displayOriginX , displayOriginY , frameX , frameY , frameWidth , frameHeight , tintTL , tintTR , tintBL , tintBR , tintEffect , uOffset , vOffset , camera , parentTransformMatrix , skipFlip , true ) ;
335+ normalTexture = this . defaultNormalMap ;
336+ }
298337
299- this . renderer . setNormalMap ( normalTexture . glTexture ) ;
338+ TextureTintPipeline . prototype . batchTexture . call ( this , gameObject , texture , textureWidth , textureHeight , srcX , srcY , srcWidth , srcHeight , scaleX , scaleY , rotation , flipX , flipY , scrollFactorX , scrollFactorY , displayOriginX , displayOriginY , frameX , frameY , frameWidth , frameHeight , tintTL , tintTR , tintBL , tintBR , tintEffect , uOffset , vOffset , camera , parentTransformMatrix , skipFlip , true ) ;
300339
301- this . setNormalMapRotation ( rotation ) ;
302- }
340+ this . renderer . setNormalMap ( normalTexture . glTexture ) ;
341+
342+ this . setNormalMapRotation ( rotation ) ;
303343 } ,
304344
305345 /**
@@ -321,14 +361,16 @@ var ForwardDiffuseLightPipeline = new Class({
321361
322362 var normalTexture = sprite . texture . dataSource [ sprite . frame . sourceIndex ] ;
323363
324- if ( normalTexture )
364+ if ( ! normalTexture )
325365 {
326- TextureTintPipeline . prototype . batchSprite . call ( this , sprite , camera , parentTransformMatrix , true ) ;
366+ normalTexture = this . defaultNormalMap ;
367+ }
327368
328- this . renderer . setNormalMap ( normalTexture . glTexture ) ;
369+ TextureTintPipeline . prototype . batchSprite . call ( this , sprite , camera , parentTransformMatrix , true ) ;
329370
330- this . setNormalMapRotation ( sprite . rotation ) ;
331- }
371+ this . renderer . setNormalMap ( normalTexture . glTexture ) ;
372+
373+ this . setNormalMapRotation ( sprite . rotation ) ;
332374 }
333375
334376} ) ;
0 commit comments