Phaser v3.25.0 Beta 0
Pre-releaseWebGL Multi-Texture Rendering
The Texture Tint Pipeline has had its core flow rewritten to eliminate the need for constantly creating batch
objects. Instead, it now supports the new multi-texture shader, vastly increasing rendering performance, especially on drawcall-bound systems.
All of the internal functions, such as batchQuad
and batchSprite
have been updated to use the new method of texture setting. The method signatures all remain the same, unless indicated below.
Config.render.maxTextures
is a new game config setting that allows you to control how many texture units will be used in WebGL.WebGL.Utils.checkShaderMax
is a new function, used internally by the renderer, to determine the maximum number of texture units the GPU + browser supports.- The property
WebGLRenderer.currentActiveTextureUnit
has been renamed tocurrentActiveTexture
. WebGLRenderer.startActiveTexture
is a new read-only property contains the current starting active texture unit.WebGLRenderer.maxTextures
is a new read-only property that contains the maximum number of texture units WebGL can use.WebGLRenderer.textureIndexes
is a new read-only array that contains all of the available WebGL texture units.WebGLRenderer.tempTextures
is a new read-only array that contains temporary WebGL textures.- The
WebGLRenderer.currentTextures
property has been removed, as it's no longer used. TextureSource.glIndex
is a new property that holds the currently assigned texture unit for the Texture Source.TextureSource.glIndexCounter
is a new property that holds the time the index was assigned to the Texture Source.WebGLRenderer.currentTextures
has been removed, as it's no longer used internally.WebGLRenderer.setBlankTexture
no longer has aforce
parameter, as it's set by default.- The Mesh Game Object WebGL Renderer function has been updated to support multi-texture units.
- The Blitter Game Object WebGL Renderer function has been updated to support multi-texture units.
- The Bitmap Text Game Object WebGL Renderer function has been updated to support multi-texture units.
- The Dynamic Bitmap Text Game Object WebGL Renderer function has been updated to support multi-texture units.
- The Particle Emitter Game Object WebGL Renderer function has been updated to support multi-texture units.
- The Texture Tint vertex and fragment shaders have been updated to support the
inTexId
float attribute and dynamic generation. - The Texture Tint Pipeline has a new attribute,
inTexId
which is agl.FLOAT
. TextureTintPipeline.bind
is a new method that sets theuMainSampler
uniform.- The
TextureTintPipeline.requireTextureBatch
method has been removed, as it's no longer required. - The
TextureTintPipeline.pushBatch
method has been removed, as it's no longer required. - The
TextureTintPipeline.maxQuads
property has been removed, as it's no longer required. - The
TextureTintPipeline.batches
property has been removed, as it's no longer required. TextureTintPipeline.flush
has been rewritten to support multi-textures.TextureTintPipeline.flush
no longer creates a sub-array if the batch is full, but instead usesbufferData
for speed.WebGLPipeline.currentUnit
is a new property that holds the most recently assigned texture unit. Treat as read-only.WebGLRenderer.setTextureSource
is a new method, used by pipelines and Game Objects, that will assign a texture unit to the given Texture Source.- The
WebGLRenderer.setTexture2D
method has been updated to use the new texture unit assignment. It no longer takes thetextureUnit
orflush
parameters and these have been removed from its method signature. WebGLRenderer.setTextureZero
is a new method that activates texture zero and binds the given texture to it. Useful for fbo backed game objects.WebGLRenderer.clearTextureZero
is a new method that clears the texture tha was bound to unit zero.WebGLRenderer.textureZero
is a new property that holds the currently bound unit zero texture.WebGLRenderer.normalTexture
is a new property that holds the currently bound normal map (texture unit one).WebGLRenderer.setNormalMap
is a new method that sets the current normal map texture.WebGLRenderer.clearNormalMap
is a new method that clears the current normal map texture.WebGLRenderer.resetTextures
is a new method that flushes the pipeline, resets all textures back to the temporary ones and resets the active texture counter.WebGLPipeline.boot
will now check all of the attributes and store the pointer location within the attribute entry.WebGLPipeline.bind
no longer looks-up and enables every attribute, every frame. Instead it uses the cached pointer location stored in the attribute entry, cutting down on redundant WebGL operations.WebGLRenderer.isNewNormalMap
is a new method that returns a boolean if the given parameters are not currently used.WebGLPipeline.forceZero
is a new property that informs Game Objects if the pipeline requires a zero bound texture unit.WebGLPipeline.setAttribPointers
is a new method that will set the vertex attribute pointers for the pipeline.WebGLRenderer.unbindTextures
is a new method that will activate and then null bind all WebGL textures.
Forward Diffuse Light Pipeline API Changes
This Light2D pipeline, which is responsible for rendering lights under WebGL, has been rewritten to work with the new Texture Tint Pipeline functions. Lots of redundant code has been removed and the following changes and improvements took place:
- The pipeline now works with Game Objects that do not have a normal map. They will be rendered using the new default normal map, which allows for a flat light effect to pass over them and merge with their diffuse map colors.
- Fixed a bug in the way lights were handled that caused Tilemaps to render one tile at a time, causing massive slow down. They're now batched properly, making a combination of lights and tilemaps possible again.
- The Bitmap Text (Static and Dynamic) Game Objects now support rendering with normal maps.
- The TileSprite Game Objects now support rendering with normal maps.
- Mesh and Quad Game Objects now support rendering with normal maps.
- The Graphics Game Objects now support rendering in Light2d. You can even use normal map textures for the texture fills.
- Particle Emitter Game Object now supports rendering in Light2d.
- All Shape Game Objects (Rectangle, IsoBox, Star, Polygon, etc) now support rendering in Light2d.
- The Text Game Object now supports rendering in Light2d, no matter which font, stroke or style it is using.
- Both Static and Dynamic Tilemap Layer Game Objects now support the Light2d pipeline, with or without normal maps.
- The pipeline will no longer look-up and set all of the light uniforms unless the
Light
is dirty. - The pipeline will no longer reset all of the lights unless the quantity of lights has changed.
- The
ForwardDiffuseLightPipeline.defaultNormalMap
property has changed, it's now an object with aglTexture
property that maps to the pipelines default normal map. - The
ForwardDiffuseLightPipeline.boot
method has been changed to now generate a default normal map. - The
ForwardDiffuseLightPipeline.onBind
method has been removed as it's no longer required. - The
ForwardDiffuseLightPipeline.setNormalMap
method has been removed as it's no longer required. ForwardDiffuseLightPipeline.bind
is a new method that handles setting-up the shader uniforms.- The
ForwardDiffuseLightPipeline.batchTexture
method has been rewritten to use the Texture Tint Pipeline function instead. - The
ForwardDiffuseLightPipeline.batchSprite
method has been rewritten to use the Texture Tint Pipeline function instead. ForwardDiffuseLightPipeline.lightCount
is a new property that stores the previous number of lights rendered.ForwardDiffuseLightPipeline.getNormalMap
is a new method that will look-up and return a normal map for the given object.
Lights
Light.dirty
is a new property that controls if the light is dirty, or not, and needs its uniforms updating.Light
has been recoded so that all of its properties are now setters that activate itsdirty
flag.LightsManager.destroy
will now clear thelightPool
array when destroyed, where-as previously it didn't.LightsManager.cull
now takes the viewport height from the renderer instead of the game config (thanks zenwaichi)
WebGL ModelViewProjection API Changes
The ModelViewProjection
object contained a lot of functions that Phaser never used internally. These have now been
moved to external functions, which can be easily excluded from Custom builds to save space.
If you used any of them in your code, please update to the new function names below:
Phaser.Renderer.WebGL.MVP
is a new namespace under which the Model View Projection functions now live.projIdentity
is now available as a stand-alone functionPhaser.Renderer.WebGL.MVP.ProjectIdentity
projPersp
is now available as a stand-alone functionPhaser.Renderer.WebGL.MVP.ProjectPerspective
modelRotateX
is now available as a stand-alone functionPhaser.Renderer.WebGL.MVP.RotateX
modelRotateY
is now available as a stand-alone functionPhaser.Renderer.WebGL.MVP.RotateY
modelRotateZ
is now available as a stand-alone functionPhaser.Renderer.WebGL.MVP.RotateZ
viewLoad
is now available as a stand-alone functionPhaser.Renderer.WebGL.MVP.ViewLoad
viewRotateX
is now available as a stand-alone functionPhaser.Renderer.WebGL.MVP.ViewRotateX
viewRotateY
is now available as a stand-alone functionPhaser.Renderer.WebGL.MVP.ViewRotateY
viewRotateZ
is now available as a stand-alone functionPhaser.Renderer.WebGL.MVP.ViewRotateZ
viewScale
is now available as a stand-alone functionPhaser.Renderer.WebGL.MVP.ViewScale
viewTranslate
is now available as a stand-alone functionPhaser.Renderer.WebGL.MVP.ViewTranslate
modelIdentity
is now available as a stand-alone functionPhaser.Renderer.WebGL.MVP.Identity
modelScale
is now available as a stand-alone functionPhaser.Renderer.WebGL.MVP.Scale
modelTranslate
is now available as a stand-alone functionPhaser.Renderer.WebGL.MVP.Translate
viewIdentity
is now available as a stand-alone functionPhaser.Renderer.WebGL.MVP.ViewIdentity
viewLoad2D
is now available as a stand-alone functionPhaser.Renderer.WebGL.MVP.ViewLoad2D
projOrtho
is now available as a stand-alone functionPhaser.Renderer.WebGL.MVP.ProjectOrtho
Phaser.Renderer.WebGL.MVP.SetIdentity
is a new function the others use, to save on space.
New Features
WebGLRenderer.setInt1iv
will allow you to look-up and set a 1iv uniform on the given shader.
Updates and API Changes
Config.batchSize
has been increased from 2000 to 4096.- Removed the Deferred Diffuse fragment and vertex shaders from the project, as they're not used.
StaticTilemapLayer.upload
will now set the vertex attributes and buffer the data, and handles internal checks more efficiently.StaticTilemapLayer
now includes theModelViewProjection
mixin, so it doesn't need to modify the pipeline during rendering.WebGLRenderer.textureFlush
is a new property that keeps track of the total texture flushes per frame.- The
TextureTintStripPipeline
now extendsTextureTintPipeline
and just changes the topolgy, vastly reducing the filesize.
Bug Fixes
RenderTexture.resize
(which is called fromsetSize
) wouldn't correctly set theTextureSource.glTexture
property, leading tobindTexture: attempt to use a deleted object
errors under WebGL.- The
MatterAttractors
plugin, which enables attractors between bodies, has been fixed. The original plugin only worked if the body with the attractor was first in the world bodies list. It can now attract any body, no matter where in the world list it is. Fix #5160 (thanks @strahius)
Examples, Documentation and TypeScript
My thanks to the following for helping with the Phaser 3 Examples, Docs and TypeScript definitions, either by reporting errors, fixing them or helping author the docs: