@@ -9,9 +9,11 @@ var Class = require('../../../utils/Class');
99var GetFastValue = require ( '../../../utils/object/GetFastValue' ) ;
1010var LightShaderSourceFS = require ( '../shaders/Light-frag.js' ) ;
1111var MultiPipeline = require ( './MultiPipeline' ) ;
12+ var Vec2 = require ( '../../../math/Vector2' ) ;
1213var WebGLPipeline = require ( '../WebGLPipeline' ) ;
1314
1415var LIGHT_COUNT = 10 ;
16+ var tempVec2 = new Vec2 ( ) ;
1517
1618/**
1719 * @classdesc
@@ -97,15 +99,6 @@ var LightPipeline = new Class({
9799 * @since 3.50.0
98100 */
99101 this . defaultNormalMap ;
100-
101- /**
102- * Stores the previous number of lights rendered.
103- *
104- * @name Phaser.Renderer.WebGL.Pipelines.LightPipeline#lightCount
105- * @type {number }
106- * @since 3.50.0
107- */
108- this . lightCount = 0 ;
109102 } ,
110103
111104 /**
@@ -162,56 +155,35 @@ var LightPipeline = new Class({
162155 return ;
163156 }
164157
165- var lights = lightManager . cull ( camera ) ;
166- var lightCount = Math . min ( lights . length , LIGHT_COUNT ) ;
167-
168- if ( lightCount === 0 )
169- {
170- return ;
171- }
158+ var lights = lightManager . getLights ( camera ) ;
172159
173160 var renderer = this . renderer ;
174161 var cameraMatrix = camera . matrix ;
175- var point = { x : 0 , y : 0 } ;
176162 var height = renderer . height ;
177163 var i ;
178164
179- // Reset lights if we've a different total (probably not strict enough test)
180- if ( lightCount !== this . lightCount )
165+ for ( i = 0 ; i < LIGHT_COUNT ; i ++ )
181166 {
182- for ( i = 0 ; i < LIGHT_COUNT ; i ++ )
183- {
184- this . set1f ( 'uLights[' + i + '].radius' , 0 ) ;
185- }
186-
187- this . lightCount = lightCount ;
167+ this . set1f ( 'uLights[' + i + '].radius' , 0 ) ;
188168 }
189169
190-
191- if ( camera . dirty )
192- {
193- this . set4f ( 'uCamera' , camera . x , camera . y , camera . rotation , camera . zoom ) ;
194- }
170+ this . set4f ( 'uCamera' , camera . x , camera . y , camera . rotation , camera . zoom ) ;
195171
196172 this . set3f ( 'uAmbientLightColor' , lightManager . ambientColor . r , lightManager . ambientColor . g , lightManager . ambientColor . b ) ;
197173
198- for ( i = 0 ; i < lightCount ; i ++ )
174+ for ( i = 0 ; i < lights . length ; i ++ )
199175 {
200- var light = lights [ i ] ;
201- var lightName = 'uLights[' + i + '].' ;
176+ var light = lights [ i ] . light ;
177+ var color = light . color ;
202178
203- cameraMatrix . transformPoint ( light . x , light . y , point ) ;
179+ var lightName = 'uLights[' + i + '].' ;
204180
205- this . set2f ( lightName + 'position' , point . x - ( camera . scrollX * light . scrollFactorX * camera . zoom ) , height - ( point . y - ( camera . scrollY * light . scrollFactorY ) * camera . zoom ) ) ;
181+ cameraMatrix . transformPoint ( light . x , light . y , tempVec2 ) ;
206182
207- if ( light . dirty )
208- {
209- this . set3f ( lightName + 'color' , light . r , light . g , light . b ) ;
210- this . set1f ( lightName + 'intensity' , light . intensity ) ;
211- this . set1f ( lightName + 'radius' , light . radius ) ;
212-
213- light . dirty = false ;
214- }
183+ this . set2f ( lightName + 'position' , tempVec2 . x - ( camera . scrollX * light . scrollFactorX * camera . zoom ) , height - ( tempVec2 . y - ( camera . scrollY * light . scrollFactorY ) * camera . zoom ) ) ;
184+ this . set3f ( lightName + 'color' , color . r , color . g , color . b ) ;
185+ this . set1f ( lightName + 'intensity' , light . intensity ) ;
186+ this . set1f ( lightName + 'radius' , light . radius ) ;
215187 }
216188
217189 this . currentNormalMapRotation = null ;
0 commit comments