mirror of
https://github.com/photonstorm/phaser
synced 2024-11-22 04:33:31 +00:00
Add default normal map texture __NORMAL.
Remove `LightPipeline.defaultNormalMap`, as this universal texture is now available to use.
This commit is contained in:
parent
23a672bc48
commit
2e8a8f8081
4 changed files with 43 additions and 26 deletions
|
@ -133,6 +133,7 @@ Several changes were made to the rendering system to support these improvements.
|
|||
- Added property `glFramebufferWrappers` of type `WebGLFramebufferWrapper[]`
|
||||
- Added property `glAttribLocationWrappers` of type `WebGLAttribLocationWrapper[]`
|
||||
- Added property `glUniformLocationWrappers` of type `WebGLUniformLocationWrapper[]`
|
||||
- Added property `normalTexture` of type `WebGLTextureWrapper`
|
||||
- `currentFramebuffer` property type changed from `WebGLFramebuffer` to `WebGLFramebufferWrapper`
|
||||
- `fboStack` property type changed from `WebGLFramebuffer[]` to `WebGLFramebufferWrapper[]`
|
||||
- `currentProgram` property type changed from `WebGLProgram` to `WebGLProgramWrapper`
|
||||
|
@ -197,6 +198,18 @@ Several changes were made to the rendering system to support these improvements.
|
|||
- `Phaser.Renderers.WebGL.WebGLShader`
|
||||
- `program` property type changed from `WebGLProgram` to `WebGLProgramWrapper`
|
||||
- Added method `syncUniforms` for use during context recovery
|
||||
- `Phaser.Renderers.WebGL.Pipelines.LightPipeline`
|
||||
- Removed property `defaultNormalMap`. There is now a default normal map at `WebGLRenderer.normalTexture`, or the texture key `'__NORMAL'`.
|
||||
- `currentNormalMap` property type changed from `WebGLTexture` to `WebGLTextureWrapper`
|
||||
- `#setTexture2D` method:
|
||||
- `texture` parameter type changed from `WebGLTexture` to `WebGLTextureWrapper`
|
||||
- `#isNewNormalMap` method:
|
||||
- `texture` parameter type changed from `WebGLTexture` to `WebGLTextureWrapper`
|
||||
- `normalMap` parameter type changed from `WebGLTexture` to `WebGLTextureWrapper`
|
||||
- `#getNormalMap` method:
|
||||
- Return type changed from `WebGLTexture` to `WebGLTextureWrapper`
|
||||
- `#batchTexture` method:
|
||||
- `texture` parameter type changed from `WebGLTexture` to `WebGLTextureWrapper`
|
||||
- `Phaser.Renderers.WebGL.Pipelines.MultiPipeline`
|
||||
- `#batchTexture` method:
|
||||
- `texture` parameter type changed from `WebGLTexture` to `WebGLTextureWrapper`
|
||||
|
@ -222,10 +235,12 @@ Several changes were made to the rendering system to support these improvements.
|
|||
- Constructor
|
||||
- `source` parameter type options added `WebGLTextureWrapper`
|
||||
- `Phaser.Textures.TextureManager`
|
||||
- A texture with the key `'__NORMAL'` is created on boot if the WebGL renderer is being used. This is a 1x1 texture of colour #7f7fff, or a flat normal map.
|
||||
- `#addGLTexture` method:
|
||||
- `glTexture` parameter type changed from `WebGLTexture` to `WebGLTextureWrapper`
|
||||
- `width` parameter removed
|
||||
- `height` parameter removed
|
||||
- `#getTextureKeys` now excludes `'__NORMAL'` as well as `'__DEFAULT'`, `'__MISSING'`, and `'__WHITE'`.
|
||||
- Added method `addUint8Array` for creating textures from raw colour data
|
||||
- `Phaser.Textures.TextureSource`
|
||||
- `glTexture` property type changed from `WebGLTexture` to `WebGLTextureWrapper`
|
||||
|
|
|
@ -471,6 +471,18 @@ var WebGLRenderer = new Class({
|
|||
*/
|
||||
this.blankTexture = null;
|
||||
|
||||
/**
|
||||
* A blank 1x1 #7f7fff texture, a flat normal map,
|
||||
* as used by the Graphics system where needed.
|
||||
* This is set in the `boot` method.
|
||||
*
|
||||
* @name Phaser.Renderer.WebGL.WebGLRenderer#normalTexture
|
||||
* @type {Phaser.Renderer.WebGL.Wrappers.WebGLTextureWrapper}
|
||||
* @readonly
|
||||
* @since 3.80.0
|
||||
*/
|
||||
this.normalTexture = null;
|
||||
|
||||
/**
|
||||
* A pure white 4x4 texture, as used by the Graphics system where needed.
|
||||
* This is set in the `boot` method.
|
||||
|
@ -979,6 +991,7 @@ var WebGLRenderer = new Class({
|
|||
// Set-up default textures, fbo and scissor
|
||||
|
||||
this.blankTexture = game.textures.getFrame('__DEFAULT').glTexture;
|
||||
this.normalTexture = game.textures.getFrame('__NORMAL').glTexture;
|
||||
this.whiteTexture = game.textures.getFrame('__WHITE').glTexture;
|
||||
|
||||
var gl = this.gl;
|
||||
|
|
|
@ -10,7 +10,6 @@ var GetFastValue = require('../../../utils/object/GetFastValue');
|
|||
var LightShaderSourceFS = require('../shaders/Light-frag.js');
|
||||
var MultiPipeline = require('./MultiPipeline');
|
||||
var TransformMatrix = require('../../../gameobjects/components/TransformMatrix');
|
||||
var UUID = require('../../../utils/string/UUID.js');
|
||||
var Vec2 = require('../../../math/Vector2');
|
||||
var WebGLPipeline = require('../WebGLPipeline');
|
||||
|
||||
|
@ -86,21 +85,11 @@ var LightPipeline = new Class({
|
|||
0, 0, 1
|
||||
]);
|
||||
|
||||
/**
|
||||
* Stores a default normal map, which is an object with a `glTexture` property that
|
||||
* maps to a 1x1 texture of the color #7f7fff created in the `boot` method.
|
||||
*
|
||||
* @name Phaser.Renderer.WebGL.Pipelines.LightPipeline#defaultNormalMap
|
||||
* @type {object}
|
||||
* @since 3.50.0
|
||||
*/
|
||||
this.defaultNormalMap;
|
||||
|
||||
/**
|
||||
* The currently bound normal map texture at texture unit one, if any.
|
||||
*
|
||||
* @name Phaser.Renderer.WebGL.Pipelines.LightPipeline#currentNormalMap;
|
||||
* @type {?WebGLTexture}
|
||||
* @type {?Phaser.Renderer.WebGL.Wrappers.WebGLTextureWrapper}
|
||||
* @since 3.60.0
|
||||
*/
|
||||
this.currentNormalMap;
|
||||
|
@ -158,10 +147,6 @@ var LightPipeline = new Class({
|
|||
boot: function ()
|
||||
{
|
||||
WebGLPipeline.prototype.boot.call(this);
|
||||
|
||||
var tempTexture = this.renderer.game.textures.addUint8Array(UUID(), new Uint8Array([ 127, 127, 255, 255 ]), 1, 1);
|
||||
|
||||
this.defaultNormalMap = { glTexture: tempTexture };
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -272,7 +257,7 @@ var LightPipeline = new Class({
|
|||
* @ignore
|
||||
* @since 3.50.0
|
||||
*
|
||||
* @param {WebGLTexture} [texture] - WebGLTexture that will be assigned to the current batch. If not given uses blankTexture.
|
||||
* @param {Phaser.Renderer.WebGL.Wrappers.WebGLTextureWrapper} [texture] - Texture that will be assigned to the current batch. If not given uses blankTexture.
|
||||
* @param {Phaser.GameObjects.GameObject} [gameObject] - The Game Object being rendered or added to the batch.
|
||||
*/
|
||||
setTexture2D: function (texture, gameObject)
|
||||
|
@ -363,8 +348,8 @@ var LightPipeline = new Class({
|
|||
* @method Phaser.Renderer.WebGL.WebGLRenderer#isNewNormalMap
|
||||
* @since 3.50.0
|
||||
*
|
||||
* @param {WebGLTexture} texture - The WebGL diffuse texture.
|
||||
* @param {WebGLTexture} normalMap - The WebGL normal map texture.
|
||||
* @param {Phaser.Renderer.WebGL.Wrappers.WebGLTextureWrapper} texture - The diffuse texture.
|
||||
* @param {Phaser.Renderer.WebGL.Wrappers.WebGLTextureWrapper} normalMap - The normal map texture.
|
||||
*
|
||||
* @return {boolean} Returns `false` if this combination is already set, or `true` if it's a new combination.
|
||||
*/
|
||||
|
@ -374,7 +359,7 @@ var LightPipeline = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* Returns the normal map WebGLTexture from the given Game Object.
|
||||
* Returns the normal map WebGLTextureWrapper from the given Game Object.
|
||||
* If the Game Object doesn't have one, it returns the default normal map from this pipeline instead.
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.Pipelines.LightPipeline#getNormalMap
|
||||
|
@ -382,7 +367,7 @@ var LightPipeline = new Class({
|
|||
*
|
||||
* @param {Phaser.GameObjects.GameObject} [gameObject] - The Game Object to get the normal map from.
|
||||
*
|
||||
* @return {WebGLTexture} The normal map texture.
|
||||
* @return {Phaser.Renderer.WebGL.Wrappers.WebGLTextureWrapper} The normal map texture.
|
||||
*/
|
||||
getNormalMap: function (gameObject)
|
||||
{
|
||||
|
@ -390,7 +375,7 @@ var LightPipeline = new Class({
|
|||
|
||||
if (!gameObject)
|
||||
{
|
||||
normalMap = this.defaultNormalMap;
|
||||
return this.renderer.normalMap;
|
||||
}
|
||||
else if (gameObject.displayTexture)
|
||||
{
|
||||
|
@ -414,7 +399,7 @@ var LightPipeline = new Class({
|
|||
|
||||
if (!normalMap)
|
||||
{
|
||||
normalMap = this.defaultNormalMap;
|
||||
return this.renderer.normalMap;
|
||||
}
|
||||
|
||||
return normalMap.glTexture;
|
||||
|
@ -445,7 +430,7 @@ var LightPipeline = new Class({
|
|||
* @since 3.50.0
|
||||
*
|
||||
* @param {Phaser.GameObjects.GameObject} gameObject - Source GameObject.
|
||||
* @param {WebGLTexture} texture - Raw WebGLTexture associated with the quad.
|
||||
* @param {Phaser.Renderer.WebGL.Wrappers.WebGLTextureWrapper} texture - Texture associated with the quad.
|
||||
* @param {number} textureWidth - Real texture width.
|
||||
* @param {number} textureHeight - Real texture height.
|
||||
* @param {number} srcX - X coordinate of the quad.
|
||||
|
|
|
@ -187,6 +187,10 @@ var TextureManager = new Class({
|
|||
this.addBase64('__DEFAULT', config.defaultImage);
|
||||
this.addBase64('__MISSING', config.missingImage);
|
||||
this.addBase64('__WHITE', config.whiteImage);
|
||||
if (this.game.renderer.gl)
|
||||
{
|
||||
this.addUint8Array('__NORMAL', new Uint8Array([ 127, 127, 255, 255 ]), 1, 1);
|
||||
}
|
||||
|
||||
this.game.events.once(GameEvents.DESTROY, this.destroy, this);
|
||||
|
||||
|
@ -1351,7 +1355,7 @@ var TextureManager = new Class({
|
|||
|
||||
/**
|
||||
* Returns an array with all of the keys of all Textures in this Texture Manager.
|
||||
* The output array will exclude the `__DEFAULT`, `__MISSING`, and `__WHITE` keys.
|
||||
* The output array will exclude the `__DEFAULT`, `__MISSING`, `__WHITE`, and `__NORMAL` keys.
|
||||
*
|
||||
* @method Phaser.Textures.TextureManager#getTextureKeys
|
||||
* @since 3.0.0
|
||||
|
@ -1364,7 +1368,7 @@ var TextureManager = new Class({
|
|||
|
||||
for (var key in this.list)
|
||||
{
|
||||
if (key !== '__DEFAULT' && key !== '__MISSING' && key !== '__WHITE')
|
||||
if (key !== '__DEFAULT' && key !== '__MISSING' && key !== '__WHITE' && key !== '__NORMAL')
|
||||
{
|
||||
output.push(key);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue