Skip to content

Commit 5704055

Browse files
committed
Renamed the pipelines to make them less ambiguous and sorted out lots of config properties
1 parent 8f5ee53 commit 5704055

5 files changed

Lines changed: 266 additions & 194 deletions

File tree

src/renderer/webgl/pipelines/ForwardDiffuseLightPipeline.js renamed to src/renderer/webgl/pipelines/LightPipeline.js

Lines changed: 62 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,47 +6,81 @@
66
*/
77

88
var Class = require('../../../utils/Class');
9-
var ShaderSourceFS = require('../shaders/ForwardDiffuse-frag.js');
10-
var TextureTintPipeline = require('./TextureTintPipeline');
9+
var GetFastValue = require('../../../utils/object/GetFastValue');
10+
var ShaderSourceFS = require('../shaders/Light-frag.js');
11+
var MultiPipeline = require('./MultiPipeline');
1112
var WebGLPipeline = require('../WebGLPipeline');
1213

1314
var LIGHT_COUNT = 10;
1415

1516
/**
1617
* @classdesc
17-
* ForwardDiffuseLightPipeline implements a forward rendering approach for 2D lights.
1818
*
19-
* It works by using a custom shader, combined with Light Game Objects, that provides an ambient
20-
* illumination effect in your games.
19+
* The Light Pipeline is an extension of the Multi Pipeline and uses a custom shader
20+
* designed to handle forward diffused rendering of 2D lights in a Scene.
2121
*
22-
* This pipeline extends TextureTintPipeline so it implements all of its rendering functions and batching system.
22+
* The shader works in tandem with Light Game Objects, and optionally texture normal maps,
23+
* to provide an ambient illumination effect.
2324
*
24-
* @class ForwardDiffuseLightPipeline
25-
* @extends Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline
25+
* If you wish to provide your own shader, you can use the `%LIGHT_COUNT%` declaration in the source,
26+
* and it will be automatically replaced at run-time with the total number of configured lights.
27+
*
28+
* The maximum number of lights can be set in the Render Config `maxLights` property and defaults to 10.
29+
*
30+
* Prior to Phaser v3.50 this pipeline was called the `ForwardDiffuseLightPipeline`.
31+
*
32+
* The fragment shader it uses can be found in `shaders/src/Light.frag`.
33+
* The vertex shader it uses can be found in `shaders/src/Multi.vert`.
34+
*
35+
* The default shader attributes for this pipeline are:
36+
*
37+
* `inPosition` (vec2, offset 0)
38+
* `inTexCoord` (vec2, offset 8)
39+
* `inTexId` (float, offset 16)
40+
* `inTintEffect` (float, offset 20)
41+
* `inTint` (vec4, offset 24, normalized)
42+
*
43+
* The default shader uniforms for this pipeline are:
44+
*
45+
* `uProjectionMatrix` (mat4)
46+
* `uViewMatrix` (mat4)
47+
* `uModelMatrix` (mat4)
48+
* `uMainSampler` (sampler2D)
49+
* `uNormSampler` (sampler2D)
50+
* `uCamera` (vec4)
51+
* `uResolution` (vec2)
52+
* `uAmbientLightColor` (vec3)
53+
* `uInverseRotationMatrix` (mat3)
54+
* `uLights` (Light struct)
55+
*
56+
* @class LightPipeline
57+
* @extends Phaser.Renderer.WebGL.Pipelines.MultiPipeline
2658
* @memberof Phaser.Renderer.WebGL.Pipelines
2759
* @constructor
28-
* @since 3.0.0
60+
* @since 3.50.0
2961
*
30-
* @param {object} config - The configuration of the pipeline, same as the {@link Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline}. The fragment shader will be replaced with the lighting shader.
62+
* @param {Phaser.Types.Renderer.WebGL.WebGLPipelineConfig} config - The configuration options for this pipeline.
3163
*/
32-
var ForwardDiffuseLightPipeline = new Class({
64+
var LightPipeline = new Class({
3365

34-
Extends: TextureTintPipeline,
66+
Extends: MultiPipeline,
3567

3668
initialize:
3769

38-
function ForwardDiffuseLightPipeline (config)
70+
function LightPipeline (config)
3971
{
40-
LIGHT_COUNT = config.maxLights;
72+
LIGHT_COUNT = config.game.renderer.config.maxLights;
73+
74+
var fragmentShaderSource = GetFastValue(config, 'fragShader', ShaderSourceFS);
4175

42-
config.fragShader = ShaderSourceFS.replace('%LIGHT_COUNT%', LIGHT_COUNT.toString());
76+
config.fragShader = fragmentShaderSource.replace('%LIGHT_COUNT%', LIGHT_COUNT.toString());
4377

44-
TextureTintPipeline.call(this, config);
78+
MultiPipeline.call(this, config);
4579

4680
/**
4781
* Inverse rotation matrix for normal map rotations.
4882
*
49-
* @name Phaser.Renderer.WebGL.Pipelines.ForwardDiffuseLightPipeline#inverseRotationMatrix
83+
* @name Phaser.Renderer.WebGL.Pipelines.LightPipeline#inverseRotationMatrix
5084
* @type {Float32Array}
5185
* @private
5286
* @since 3.16.0
@@ -61,7 +95,7 @@ var ForwardDiffuseLightPipeline = new Class({
6195
* Stores a default normal map, which is an object with a `glTexture` property that
6296
* maps to a 1x1 texture of the color #7f7fff created in the `boot` method.
6397
*
64-
* @name Phaser.Renderer.WebGL.Pipelines.ForwardDiffuseLightPipeline#defaultNormalMap
98+
* @name Phaser.Renderer.WebGL.Pipelines.LightPipeline#defaultNormalMap
6599
* @type {object}
66100
* @since 3.50.0
67101
*/
@@ -70,7 +104,7 @@ var ForwardDiffuseLightPipeline = new Class({
70104
/**
71105
* Stores the previous number of lights rendered.
72106
*
73-
* @name Phaser.Renderer.WebGL.Pipelines.ForwardDiffuseLightPipeline#lightCount
107+
* @name Phaser.Renderer.WebGL.Pipelines.LightPipeline#lightCount
74108
* @type {number}
75109
* @since 3.50.0
76110
*/
@@ -85,7 +119,7 @@ var ForwardDiffuseLightPipeline = new Class({
85119
* By this stage all Game level systems are now in place and you can perform any final
86120
* tasks that the pipeline may need that relied on game systems such as the Texture Manager.
87121
*
88-
* @method Phaser.Renderer.WebGL.ForwardDiffuseLightPipeline#boot
122+
* @method Phaser.Renderer.WebGL.LightPipeline#boot
89123
* @since 3.11.0
90124
*/
91125
boot: function ()
@@ -112,7 +146,7 @@ var ForwardDiffuseLightPipeline = new Class({
112146
* Sets the shader program, vertex buffer and other resources.
113147
* Should only be called when changing pipeline.
114148
*
115-
* @method Phaser.Renderer.WebGL.Pipelines.ForwardDiffuseLightPipeline#bind
149+
* @method Phaser.Renderer.WebGL.Pipelines.LightPipeline#bind
116150
* @since 3.50.0
117151
*
118152
* @return {this} This WebGLPipeline instance.
@@ -134,7 +168,7 @@ var ForwardDiffuseLightPipeline = new Class({
134168
/**
135169
* This function sets all the needed resources for each camera pass.
136170
*
137-
* @method Phaser.Renderer.WebGL.Pipelines.ForwardDiffuseLightPipeline#onRender
171+
* @method Phaser.Renderer.WebGL.Pipelines.LightPipeline#onRender
138172
* @since 3.0.0
139173
*
140174
* @param {Phaser.Scene} scene - The Scene being rendered.
@@ -218,7 +252,7 @@ var ForwardDiffuseLightPipeline = new Class({
218252
* Rotates the normal map vectors inversely by the given angle.
219253
* Only works in 2D space.
220254
*
221-
* @method Phaser.Renderer.WebGL.Pipelines.ForwardDiffuseLightPipeline#setNormalMapRotation
255+
* @method Phaser.Renderer.WebGL.Pipelines.LightPipeline#setNormalMapRotation
222256
* @since 3.16.0
223257
*
224258
* @param {number} rotation - The angle of rotation in radians.
@@ -259,7 +293,7 @@ var ForwardDiffuseLightPipeline = new Class({
259293
/**
260294
* Assigns a texture to the current batch. If a different texture is already set it creates a new batch object.
261295
*
262-
* @method Phaser.Renderer.WebGL.Pipelines.ForwardDiffuseLightPipeline#setTexture2D
296+
* @method Phaser.Renderer.WebGL.Pipelines.LightPipeline#setTexture2D
263297
* @since 3.50.0
264298
*
265299
* @param {WebGLTexture} [texture] - WebGLTexture that will be assigned to the current batch. If not given uses blankTexture.
@@ -294,7 +328,7 @@ var ForwardDiffuseLightPipeline = new Class({
294328
* Custom pipelines can use this method in order to perform any required pre-batch tasks
295329
* for the given Game Object. It must return the texture unit the Game Object was assigned.
296330
*
297-
* @method Phaser.Renderer.WebGL.Pipelines.ForwardDiffuseLightPipeline#setGameObject
331+
* @method Phaser.Renderer.WebGL.Pipelines.LightPipeline#setGameObject
298332
* @since 3.50.0
299333
*
300334
* @param {Phaser.GameObjects.GameObject} gameObject - The Game Object being rendered or added to the batch.
@@ -329,7 +363,7 @@ var ForwardDiffuseLightPipeline = new Class({
329363
* Returns the normal map WebGLTexture from the given Game Object.
330364
* If the Game Object doesn't have one, it returns the default normal map from this pipeline instead.
331365
*
332-
* @method Phaser.Renderer.WebGL.Pipelines.ForwardDiffuseLightPipeline#getNormalMap
366+
* @method Phaser.Renderer.WebGL.Pipelines.LightPipeline#getNormalMap
333367
* @since 3.50.0
334368
*
335369
* @param {Phaser.GameObjects.GameObject} [gameObject] - The Game Object to get the normal map from.
@@ -374,6 +408,6 @@ var ForwardDiffuseLightPipeline = new Class({
374408

375409
});
376410

377-
ForwardDiffuseLightPipeline.LIGHT_COUNT = LIGHT_COUNT;
411+
LightPipeline.LIGHT_COUNT = LIGHT_COUNT;
378412

379-
module.exports = ForwardDiffuseLightPipeline;
413+
module.exports = LightPipeline;

0 commit comments

Comments
 (0)