diff --git a/v3/src/cache/GlobalCache.js b/v3/src/cache/GlobalCache.js index 04f18d8ff..adf936abd 100644 --- a/v3/src/cache/GlobalCache.js +++ b/v3/src/cache/GlobalCache.js @@ -81,6 +81,14 @@ var GlobalCache = new Class({ */ this.text = new BaseCache(); + /** + * [description] + * + * @property {Phaser.Cache.BaseCache} obj + * @protected + */ + this.obj = new BaseCache(); + /** * [description] * diff --git a/v3/src/gameobjects/graphics/Graphics.js b/v3/src/gameobjects/graphics/Graphics.js index 1d6331894..bd9e84644 100644 --- a/v3/src/gameobjects/graphics/Graphics.js +++ b/v3/src/gameobjects/graphics/Graphics.js @@ -7,7 +7,10 @@ var Ellipse = require('../../geom/ellipse/'); var GameObject = require('../GameObject'); var GetValue = require('../../utils/object/GetValue'); var MATH_CONST = require('../../math/const'); +var Matrix4 = require('../../math/Matrix4'); +var Mesh = require('../../geom/mesh/Mesh'); var Render = require('./GraphicsRender'); +var Vector3 = require('../../math/Vector3'); var Graphics = new Class({ @@ -49,6 +52,22 @@ var Graphics = new Class({ this.setDefaultStyles(options); + // Mesh viewport camera + + this.viewportWidth = scene.sys.game.config.width; + this.viewportHeight = scene.sys.game.config.height; + + this.camera = { + position: new Vector3(), + target: new Vector3() + }; + + this.up = new Vector3().up(); + this.projectionMatrix = new Matrix4(); + this.viewMatrix = new Matrix4().lookAt(this.camera.position, this.camera.target, this.up); + + this.setViewport(this.viewportWidth, this.viewportHeight); + var resourceManager = scene.sys.game.renderer.resourceManager; if (resourceManager !== undefined) @@ -398,6 +417,158 @@ var Graphics = new Class({ return this; }, + // MESH + VIEWPORT + CAMERA + + cameraX: { + + get: function () + { + return this.camera.position.x; + }, + + set: function (value) + { + this.camera.position.x = value; + this.viewMatrix.lookAt(this.camera.position, this.camera.target, this.up); + } + + }, + + cameraY: { + + get: function () + { + return this.camera.position.y; + }, + + set: function (value) + { + this.camera.position.y = value; + this.viewMatrix.lookAt(this.camera.position, this.camera.target, this.up); + } + + }, + + cameraZ: { + + get: function () + { + return this.camera.position.z; + }, + + set: function (value) + { + this.camera.position.z = value; + this.viewMatrix.lookAt(this.camera.position, this.camera.target, this.up); + } + + }, + + cameraTargetX: { + + get: function () + { + return this.camera.target.x; + }, + + set: function (value) + { + this.camera.target.x = value; + this.viewMatrix.lookAt(this.camera.position, this.camera.target, this.up); + } + + }, + + cameraTargetY: { + + get: function () + { + return this.camera.target.y; + }, + + set: function (value) + { + this.camera.target.y = value; + this.viewMatrix.lookAt(this.camera.position, this.camera.target, this.up); + } + + }, + + cameraTargetZ: { + + get: function () + { + return this.camera.target.z; + }, + + set: function (value) + { + this.camera.target.z = value; + this.viewMatrix.lookAt(this.camera.position, this.camera.target, this.up); + } + + }, + + setCameraPosition: function (x, y, z) + { + this.camera.position.set(x, y, z); + + this.viewMatrix.lookAt(this.camera.position, this.camera.target, this.up); + + return this; + }, + + setCameraTarget: function (x, y, z) + { + this.camera.target.set(x, y, z); + + this.viewMatrix.lookAt(this.camera.position, this.camera.target, this.up); + + return this; + }, + + // @param {number} fovy Vertical field of view in radians + // @param {number} near Near bound of the frustum + // @param {number} far Far bound of the frustum + setViewport: function (width, height, fov, near, far) + { + if (fov === undefined) { fov = 0.8; } + if (near === undefined) { near = 0.01; } + if (far === undefined) { far = 1; } + + this.viewportWidth = width; + this.viewportHeight = height; + + // fov, aspect, near, far + this.projectionMatrix.perspective(fov, width / height, near, far); + + return this; + }, + + // Allow key to be a data array OR object containing the rest of the properties + color etc + createMesh: function (key, x, y, z) + { + var data = this.scene.sys.cache.obj.get(key); + + var mesh = new Mesh(data, x, y, z); + + return mesh; + }, + + fillMesh: function (mesh) + { + mesh.fill(this); + + return this; + }, + + strokeMesh: function (mesh) + { + mesh.stroke(this); + + return this; + }, + // TRANSFORM save: function () diff --git a/v3/src/gameobjects/graphics/GraphicsCanvasRenderer.js b/v3/src/gameobjects/graphics/GraphicsCanvasRenderer.js index 24f680055..e85992082 100644 --- a/v3/src/gameobjects/graphics/GraphicsCanvasRenderer.js +++ b/v3/src/gameobjects/graphics/GraphicsCanvasRenderer.js @@ -102,7 +102,7 @@ var GraphicsCanvasRenderer = function (renderer, src, interpolationPercentage, c break; case Commands.FILL_PATH: - if (!allowClip) + if (!allowClip) { ctx.fill(); } @@ -143,7 +143,7 @@ var GraphicsCanvasRenderer = function (renderer, src, interpolationPercentage, c ctx.lineTo(commandBuffer[index + 3], commandBuffer[index + 4]); ctx.lineTo(commandBuffer[index + 5], commandBuffer[index + 6]); ctx.closePath(); - if (!allowClip) + if (!allowClip) { ctx.fill(); } diff --git a/v3/src/gameobjects/graphics/GraphicsWebGLRenderer.js b/v3/src/gameobjects/graphics/GraphicsWebGLRenderer.js index c2ec1d187..3faf3e94f 100644 --- a/v3/src/gameobjects/graphics/GraphicsWebGLRenderer.js +++ b/v3/src/gameobjects/graphics/GraphicsWebGLRenderer.js @@ -1,14 +1,15 @@ -var GameObject = require('../GameObject'); var Commands = require('./Commands'); +var GameObject = require('../GameObject'); var TransformMatrix = require('../components/TransformMatrix'); -var pathArray = []; + var cos = Math.cos; var sin = Math.sin; -var sqrt = Math.sqrt; -var tempMatrix = new TransformMatrix(); + +var currentMatrix = new TransformMatrix(); var matrixStack = new Float32Array(6 * 1000); var matrixStackLength = 0; -var currentMatrix = new TransformMatrix(); +var pathArray = []; +var tempMatrix = new TransformMatrix(); var Point = function (x, y, width, rgb, alpha) { @@ -35,19 +36,14 @@ var GraphicsWebGLRenderer = function (renderer, gameObject, interpolationPercent var renderTarget = forceRenderTarget || gameObject.renderTarget; var shapeBatch = renderer.shapeBatch; - var vertexDataBuffer = shapeBatch.vertexDataBuffer; - var vertexBufferF32 = vertexDataBuffer.floatView; - var vertexBufferU32 = vertexDataBuffer.uintView; - var vertexOffset = 0; var cameraScrollX = camera.scrollX * gameObject.scrollFactorX; var cameraScrollY = camera.scrollY * gameObject.scrollFactorY; - const srcX = gameObject.x - cameraScrollX; - const srcY = gameObject.y - cameraScrollY; - const srcScaleX = gameObject.scaleX; - const srcScaleY = gameObject.scaleY; - const srcRotation = -gameObject.rotation; + var srcX = gameObject.x - cameraScrollX; + var srcY = gameObject.y - cameraScrollY; + var srcScaleX = gameObject.scaleX; + var srcScaleY = gameObject.scaleY; + var srcRotation = -gameObject.rotation; var commandBuffer = gameObject.commandBuffer; - var value; var lineAlpha = 1.0; var fillAlpha = 1.0; var lineColor = 0; @@ -61,22 +57,10 @@ var GraphicsWebGLRenderer = function (renderer, gameObject, interpolationPercent var ty = 0; var ta = 0; var x, y, radius, startAngle, endAngle, anticlockwise; - var width, height, txw, tyh; - var vertexCount = shapeBatch.vertexCount; - var polygon = []; - var x0, y0, x1, y1, x2, y2; - var tx0, ty0, tx1, ty1, tx2, ty2; - var v0, v1, v2; - var polygonIndex; var path; - var pathLength; - var point; - var maxVertices = shapeBatch.maxVertices; - var translateX, translateY; var tempMatrixMatrix = tempMatrix.matrix; var sra, srb, src, srd, sre, srf, cma, cmb, cmc, cmd, cme, cmf; var mva, mvb, mvc, mvd, mve, mvf; - var abs = Math.abs; tempMatrix.applyITRS(srcX, srcY, srcRotation, srcScaleX, srcScaleY); @@ -105,9 +89,9 @@ var GraphicsWebGLRenderer = function (renderer, gameObject, interpolationPercent for (var cmdIndex = 0, cmdLength = commandBuffer.length; cmdIndex < cmdLength; ++cmdIndex) { - var cmd = commandBuffer[cmdIndex]; + cmd = commandBuffer[cmdIndex]; - switch(cmd) + switch (cmd) { case Commands.ARC: iteration = 0; @@ -198,7 +182,7 @@ var GraphicsWebGLRenderer = function (renderer, gameObject, interpolationPercent pathArrayIndex < pathArrayLength; ++pathArrayIndex) { - var path = pathArray[pathArrayIndex]; + path = pathArray[pathArrayIndex]; shapeBatch.addStrokePath( /* Graphics Game Object Properties */ srcX, srcY, srcScaleX, srcScaleY, srcRotation, @@ -211,7 +195,6 @@ var GraphicsWebGLRenderer = function (renderer, gameObject, interpolationPercent mva, mvb, mvc, mvd, mve, mvf, path === this._lastPath, currentMatrix - ); } break; @@ -230,7 +213,6 @@ var GraphicsWebGLRenderer = function (renderer, gameObject, interpolationPercent /* Transform */ mva, mvb, mvc, mvd, mve, mvf, currentMatrix - ); cmdIndex += 4; @@ -252,7 +234,6 @@ var GraphicsWebGLRenderer = function (renderer, gameObject, interpolationPercent /* Transform */ mva, mvb, mvc, mvd, mve, mvf, currentMatrix - ); cmdIndex += 6; @@ -275,11 +256,10 @@ var GraphicsWebGLRenderer = function (renderer, gameObject, interpolationPercent /* Transform */ mva, mvb, mvc, mvd, mve, mvf, currentMatrix - ); cmdIndex += 6; - break + break; case Commands.LINE_TO: if (lastPath !== null) @@ -304,8 +284,8 @@ var GraphicsWebGLRenderer = function (renderer, gameObject, interpolationPercent if (lastPath !== null) { lastPath.points.push(new Point( - commandBuffer[cmdIndex + 1], - commandBuffer[cmdIndex + 2], + commandBuffer[cmdIndex + 1], + commandBuffer[cmdIndex + 2], commandBuffer[cmdIndex + 3], commandBuffer[cmdIndex + 4], commandBuffer[cmdIndex + 5] @@ -314,8 +294,8 @@ var GraphicsWebGLRenderer = function (renderer, gameObject, interpolationPercent else { lastPath = new Path( - commandBuffer[cmdIndex + 1], - commandBuffer[cmdIndex + 2], + commandBuffer[cmdIndex + 1], + commandBuffer[cmdIndex + 2], commandBuffer[cmdIndex + 3], commandBuffer[cmdIndex + 4], commandBuffer[cmdIndex + 5] @@ -327,8 +307,8 @@ var GraphicsWebGLRenderer = function (renderer, gameObject, interpolationPercent case Commands.MOVE_FX_TO: lastPath = new Path( - commandBuffer[cmdIndex + 1], - commandBuffer[cmdIndex + 2], + commandBuffer[cmdIndex + 1], + commandBuffer[cmdIndex + 2], commandBuffer[cmdIndex + 3], commandBuffer[cmdIndex + 4], commandBuffer[cmdIndex + 5] @@ -385,6 +365,7 @@ var GraphicsWebGLRenderer = function (renderer, gameObject, interpolationPercent break; } } + currentMatrix.loadIdentity(); pathArray.length = 0; }; diff --git a/v3/src/gameobjects/lightlayer/Const.js b/v3/src/gameobjects/lightlayer/Const.js index 5c3b38646..8ed6b23ed 100644 --- a/v3/src/gameobjects/lightlayer/Const.js +++ b/v3/src/gameobjects/lightlayer/Const.js @@ -1,6 +1,6 @@ module.exports = { MAX_LIGHTS: 10, - DEFERRED_MAX_LIGHTS: 100 + DEFERRED_MAX_LIGHTS: 50 }; diff --git a/v3/src/geom/index.js b/v3/src/geom/index.js index 5e417db88..f63ba3174 100644 --- a/v3/src/geom/index.js +++ b/v3/src/geom/index.js @@ -6,6 +6,7 @@ module.exports = { Ellipse: require('./ellipse'), Intersects: require('./intersects'), Line: require('./line'), + Mesh: require('./mesh'), Point: require('./point'), Polygon: require('./polygon'), Rectangle: require('./rectangle'), diff --git a/v3/src/geom/mesh/Mesh.js b/v3/src/geom/mesh/Mesh.js new file mode 100644 index 000000000..d8ff3eddd --- /dev/null +++ b/v3/src/geom/mesh/Mesh.js @@ -0,0 +1,264 @@ +var Class = require('../../utils/Class'); +var Matrix4 = require('../../math/Matrix4'); +var Vector2 = require('../../math/Vector2'); +var Vector3 = require('../../math/Vector3'); + +var Mesh = new Class({ + + initialize: + + function Mesh (data, x, y, z) + { + this.vertices = data.verts; + this.faces = data.faces; + + this.position = new Vector3(x, y, z); + this.rotation = new Vector3(); + this.scale = new Vector3(1, 1, 1); + + this.visible = true; + + this.thickness = 1; + this.strokeColor = 0x00ff00; + this.strokeAlpha = 1; + + this.fillColor = 0x00ff00; + this.fillAlpha = 1; + + this._pA = new Vector2(); + this._pB = new Vector2(); + this._pC = new Vector2(); + this._pD = new Vector2(); + + this._tempVec3 = new Vector3(); + + this.worldMatrix = new Matrix4(); + }, + + fill: function (graphics) + { + if (!this.visible || this.alpha === 0) + { + return; + } + + var pa = this._pA; + var pb = this._pB; + var pc = this._pC; + + var world = this.worldMatrix; + + world.setWorldMatrix(this.rotation, this.position, this.scale, graphics.viewMatrix, graphics.projectionMatrix); + + graphics.fillStyle(this.fillColor, this.fillAlpha); + + for (var f = 0; f < this.faces.length; f++) + { + var face = this.faces[f]; + var verts = this.vertices; + + this.project(graphics, pa, verts[face.A].pos, world); + this.project(graphics, pb, verts[face.B].pos, world); + this.project(graphics, pc, verts[face.C].pos, world); + + graphics.fillTriangle(pa.x, pa.y, pb.x, pb.y, pc.x, pc.y); + } + }, + + stroke: function (graphics) + { + if (!this.visible || this.alpha === 0) + { + return; + } + + var pa = this._pA; + var pb = this._pB; + var pc = this._pC; + var pd = this._pD; + + var world = this.worldMatrix; + + world.setWorldMatrix(this.rotation, this.position, this.scale, graphics.viewMatrix, graphics.projectionMatrix); + + graphics.lineStyle(this.thickness, this.strokeColor, this.strokeAlpha); + graphics.beginPath(); + + for (var f = 0; f < this.faces.length; f++) + { + var face = this.faces[f]; + var verts = this.vertices; + + this.project(graphics, pa, verts[face.A].pos, world); + this.project(graphics, pb, verts[face.B].pos, world); + this.project(graphics, pc, verts[face.C].pos, world); + this.project(graphics, pd, verts[face.D].pos, world); + + graphics.moveTo(pa.x, pa.y); + graphics.lineTo(pb.x, pb.y); + + graphics.moveTo(pb.x, pb.y); + graphics.lineTo(pc.x, pc.y); + + graphics.moveTo(pc.x, pc.y); + graphics.lineTo(pd.x, pd.y); + + graphics.moveTo(pd.x, pd.y); + graphics.lineTo(pa.x, pa.y); + } + + graphics.closePath(); + graphics.strokePath(); + }, + + project: function (graphics, local, coord, transMat) + { + var w = graphics.viewportWidth; + var h = graphics.viewportHeight; + + var point = this._tempVec3; + + point.copy(coord); + + point.transformCoordinates(transMat); + + local.x = point.x * w + w / 2 >> 0; + local.y = -point.y * h + h / 2 >> 0; + }, + + setPosition: function (x, y, z) + { + if (x === undefined) { x = 0; } + if (y === undefined) { y = x; } + if (z === undefined) { z = x; } + + this.position.x = x; + this.position.y = y; + this.position.z = z; + + return this; + }, + + setRotation: function (x, y, z) + { + if (x === undefined) { x = 0; } + if (y === undefined) { y = x; } + if (z === undefined) { z = x; } + + this.rotation.x = x; + this.rotation.y = y; + this.rotation.z = z; + + return this; + }, + + setScale: function (x, y, z) + { + if (x === undefined) { x = 1; } + if (y === undefined) { y = x; } + if (z === undefined) { z = x; } + + this.scale.x = x; + this.scale.y = y; + this.scale.z = z; + + return this; + }, + + setStrokeColor: function (color) + { + this.strokeColor = color; + + return this; + }, + + setStrokeAlpha: function (alpha) + { + this.strokeAlpha = alpha; + + return this; + }, + + setFillColor: function (color) + { + this.fillColor = color; + + return this; + }, + + setFillAlpha: function (alpha) + { + this.fillAlpha = alpha; + + return this; + }, + + lineStyle: function (lineWidth, color, alpha) + { + this.thickness = lineWidth; + this.strokeColor = color; + this.strokeAlpha = alpha; + + return this; + }, + + fillStyle: function (color, alpha) + { + this.fillColor = color; + this.fillAlpha = alpha; + + return this; + }, + + setVisible: function (value) + { + this.visible = value; + + return this; + }, + + x: { + + get: function () + { + return this.position.x; + }, + + set: function (value) + { + this.position.x = value; + } + + }, + + y: { + + get: function () + { + return this.position.y; + }, + + set: function (value) + { + this.position.y = value; + } + + }, + + z: { + + get: function () + { + return this.position.z; + }, + + set: function (value) + { + this.position.z = value; + } + + } + +}); + +module.exports = Mesh; diff --git a/v3/src/geom/mesh/index.js b/v3/src/geom/mesh/index.js new file mode 100644 index 000000000..808fa77b6 --- /dev/null +++ b/v3/src/geom/mesh/index.js @@ -0,0 +1,21 @@ +// Phaser.Geom.Mesh + +var Mesh = require('./Mesh'); + +// Circle.Area = require('./Area'); +// Circle.Circumference = require('./Circumference'); +// Circle.CircumferencePoint = require('./CircumferencePoint'); +// Circle.Clone = require('./Clone'); +// Circle.Contains = require('./Contains'); +// Circle.ContainsPoint = require('./ContainsPoint'); +// Circle.ContainsRect = require('./ContainsRect'); +// Circle.CopyFrom = require('./CopyFrom'); +// Circle.Equals = require('./Equals'); +// Circle.GetBounds = require('./GetBounds'); +// Circle.GetPoint = require('./GetPoint'); +// Circle.GetPoints = require('./GetPoints'); +// Circle.Offset = require('./Offset'); +// Circle.OffsetPoint = require('./OffsetPoint'); +// Circle.Random = require('./Random'); + +module.exports = Mesh; diff --git a/v3/src/loader/BaseLoader.js b/v3/src/loader/BaseLoader.js index e874d2f69..ee86e65d9 100644 --- a/v3/src/loader/BaseLoader.js +++ b/v3/src/loader/BaseLoader.js @@ -418,6 +418,10 @@ var BaseLoader = new Class({ cache.text.add(file.key, file.data); break; + case 'obj': + cache.obj.add(file.key, file.data); + break; + case 'binary': cache.binary.add(file.key, file.data); break; diff --git a/v3/src/loader/filetypes/WavefrontFile.js b/v3/src/loader/filetypes/WavefrontFile.js new file mode 100644 index 000000000..b54b32abd --- /dev/null +++ b/v3/src/loader/filetypes/WavefrontFile.js @@ -0,0 +1,172 @@ +var Class = require('../../utils/Class'); +var CONST = require('../const'); +var File = require('../File'); +var GetFastValue = require('../../utils/object/GetFastValue'); +var Vector3 = require('../../math/Vector3'); + +// Phaser.Loader.FileTypes.WavefrontFile + +var WavefrontFile = new Class({ + + Extends: File, + + initialize: + + function WavefrontFile (key, url, path, xhrSettings) + { + var fileKey = (typeof key === 'string') ? key : GetFastValue(key, 'key', ''); + + var fileConfig = { + type: 'obj', + extension: GetFastValue(key, 'extension', 'obj'), + responseType: 'text', + key: fileKey, + url: GetFastValue(key, 'file', url), + path: path, + xhrSettings: GetFastValue(key, 'xhr', xhrSettings) + }; + + File.call(this, fileConfig); + }, + + onProcess: function (callback) + { + this.state = CONST.FILE_PROCESSING; + + var text = this.xhrLoader.responseText; + + var verts = []; + var faces = []; + + // split the text into lines + var lines = text.replace('\r', '').split('\n'); + var count = lines.length; + var tokens; + var i; + var face; + + for (i = 0; i < count; i++) + { + var line = lines[i]; + + if (line[0] === 'v') + { + // lines that start with 'v' are vertices + tokens = line.split(' '); + + var pos = new Vector3(parseFloat(tokens[1]), parseFloat(tokens[2]), parseFloat(tokens[3])); + var normal = new Vector3(); + + if (tokens.length > 4) + { + normal.x = parseFloat(tokens[5]); + normal.y = parseFloat(tokens[6]); + normal.z = parseFloat(tokens[7]); + } + + verts.push({ + pos: pos, + normal: normal + }); + } + else if (line[0] === 'f') + { + // lines that start with 'f' are faces + tokens = line.split(' '); + + face = { + A: parseInt(tokens[1], 10), + B: parseInt(tokens[2], 10), + C: parseInt(tokens[3], 10), + D: parseInt(tokens[4], 10) + }; + + if (face.A < 0) + { + face.A = verts.length + face.A; + } + else + { + face.A--; + } + + if (face.B < 0) + { + face.B = verts.length + face.B; + } + else + { + face.B--; + } + + if (face.C < 0) + { + face.C = verts.length + face.C; + } + else + { + face.C--; + } + + if (!face.D) + { + face.D = face.C; + } + else if (face.D < 0) + { + face.D = verts.length + face.D; + } + else + { + face.D--; + } + + faces.push(face); + } + } + + // Compute normals + for (i = 0; i < faces.length; i++) + { + face = faces[i]; + + var vertA = verts[face.A]; + var vertB = verts[face.B]; + var vertC = verts[face.C]; + + face.normal = vertA.normal.clone(); + face.normal.add(vertB.normal).add(vertC.normal).scale(1 / 3).normalize(); + } + + this.data = { + verts: verts, + faces: faces + }; + + this.onComplete(); + + callback(this); + } + +}); + +WavefrontFile.create = function (loader, key, url, xhrSettings) +{ + if (Array.isArray(key)) + { + for (var i = 0; i < key.length; i++) + { + // If it's an array it has to be an array of Objects, so we get everything out of the 'key' object + loader.addFile(new WavefrontFile(key[i], url, loader.path, xhrSettings)); + } + } + else + { + loader.addFile(new WavefrontFile(key, url, loader.path, xhrSettings)); + } + + // For method chaining + return loader; +}; + +module.exports = WavefrontFile; diff --git a/v3/src/math/Matrix3.js b/v3/src/math/Matrix3.js index f06a1be02..911dfe709 100644 --- a/v3/src/math/Matrix3.js +++ b/v3/src/math/Matrix3.js @@ -408,8 +408,4 @@ var Matrix3 = new Class({ }); -Matrix3.prototype.mul = Matrix3.prototype.multiply; -Matrix3.prototype.idt = Matrix3.prototype.identity; -Matrix3.prototype.reset = Matrix3.prototype.identity; - module.exports = Matrix3; diff --git a/v3/src/math/Matrix4.js b/v3/src/math/Matrix4.js index 040e0b3f2..d951fe4ca 100644 --- a/v3/src/math/Matrix4.js +++ b/v3/src/math/Matrix4.js @@ -84,6 +84,57 @@ var Matrix4 = new Class({ return this; }, + zero: function () + { + var out = this.val; + + out[0] = 0; + out[1] = 0; + out[2] = 0; + out[3] = 0; + out[4] = 0; + out[5] = 0; + out[6] = 0; + out[7] = 0; + out[8] = 0; + out[9] = 0; + out[10] = 0; + out[11] = 0; + out[12] = 0; + out[13] = 0; + out[14] = 0; + out[15] = 0; + + return this; + }, + + xyz: function (x, y, z) + { + this.identity(); + + var out = this.val; + + out[12] = x; + out[13] = y; + out[14] = z; + + return this; + }, + + scaling: function (x, y, z) + { + this.zero(); + + var out = this.val; + + out[0] = x; + out[5] = y; + out[10] = z; + out[15] = 1; + + return this; + }, + identity: function () { var out = this.val; @@ -360,6 +411,35 @@ var Matrix4 = new Class({ return this; }, + multiplyLocal: function (src) + { + var a = []; + var m1 = this.val; + var m2 = src.val; + + a[0] = m1[0] * m2[0] + m1[1] * m2[4] + m1[2] * m2[8] + m1[3] * m2[12]; + a[1] = m1[0] * m2[1] + m1[1] * m2[5] + m1[2] * m2[9] + m1[3] * m2[13]; + a[2] = m1[0] * m2[2] + m1[1] * m2[6] + m1[2] * m2[10] + m1[3] * m2[14]; + a[3] = m1[0] * m2[3] + m1[1] * m2[7] + m1[2] * m2[11] + m1[3] * m2[15]; + + a[4] = m1[4] * m2[0] + m1[5] * m2[4] + m1[6] * m2[8] + m1[7] * m2[12]; + a[5] = m1[4] * m2[1] + m1[5] * m2[5] + m1[6] * m2[9] + m1[7] * m2[13]; + a[6] = m1[4] * m2[2] + m1[5] * m2[6] + m1[6] * m2[10] + m1[7] * m2[14]; + a[7] = m1[4] * m2[3] + m1[5] * m2[7] + m1[6] * m2[11] + m1[7] * m2[15]; + + a[8] = m1[8] * m2[0] + m1[9] * m2[4] + m1[10] * m2[8] + m1[11] * m2[12]; + a[9] = m1[8] * m2[1] + m1[9] * m2[5] + m1[10] * m2[9] + m1[11] * m2[13]; + a[10] = m1[8] * m2[2] + m1[9] * m2[6] + m1[10] * m2[10] + m1[11] * m2[14]; + a[11] = m1[8] * m2[3] + m1[9] * m2[7] + m1[10] * m2[11] + m1[11] * m2[15]; + + a[12] = m1[12] * m2[0] + m1[13] * m2[4] + m1[14] * m2[8] + m1[15] * m2[12]; + a[13] = m1[12] * m2[1] + m1[13] * m2[5] + m1[14] * m2[9] + m1[15] * m2[13]; + a[14] = m1[12] * m2[2] + m1[13] * m2[6] + m1[14] * m2[10] + m1[15] * m2[14]; + a[15] = m1[12] * m2[3] + m1[13] * m2[7] + m1[14] * m2[11] + m1[15] * m2[15]; + + return this.fromArray(a); + }, + translate: function (v) { var x = v.x; @@ -424,6 +504,7 @@ var Matrix4 = new Class({ return this; }, + // aka rotationAxis rotate: function (rad, axis) { var a = this.val; @@ -718,7 +799,8 @@ var Matrix4 = new Class({ }, /** - * Generates a perspective projection matrix with the given bounds + * Generates a perspective projection matrix with the given bounds. + * perspective fov lh * * @param {number} fovy Vertical field of view in radians * @param {number} aspect Aspect ratio. typically viewport width/height @@ -755,6 +837,33 @@ var Matrix4 = new Class({ return this; }, + perspectiveLH: function (width, height, near, far) + { + var out = this.val; + + out[0] = (2 * near) / width; + out[1] = 0; + out[2] = 0; + out[3] = 0; + + out[4] = 0; + out[5] = (2 * near) / height; + out[6] = 0; + out[7] = 0; + + out[8] = 0; + out[9] = 0; + out[10] = -far / (near - far); + out[11] = 1; + + out[12] = 0; + out[13] = 0; + out[14] = (near * far) / (near - far); + out[15] = 0; + + return this; + }, + /** * Generates a orthogonal projection matrix with the given bounds * @@ -902,13 +1011,84 @@ var Matrix4 = new Class({ out[14] = -(z0 * eyex + z1 * eyey + z2 * eyez); out[15] = 1; + return this; + }, + + yawPitchRoll: function (yaw, pitch, roll) + { + this.zero(); + _tempMat1.zero(); + _tempMat2.zero(); + + var m0 = this.val; + var m1 = _tempMat1.val; + var m2 = _tempMat2.val; + + // Rotate Z + var s = Math.sin(roll); + var c = Math.cos(roll); + + m0[10] = 1; + m0[15] = 1; + m0[0] = c; + m0[1] = s; + m0[4] = -s; + m0[5] = c; + + // Rotate X + s = Math.sin(pitch); + c = Math.cos(pitch); + + m1[0] = 1; + m1[15] = 1; + m1[5] = c; + m1[10] = c; + m1[9] = -s; + m1[6] = s; + + // Rotate Y + s = Math.sin(yaw); + c = Math.cos(yaw); + + m2[5] = 1; + m2[15] = 1; + m2[0] = c; + m2[2] = -s; + m2[8] = s; + m2[10] = c; + + this.multiplyLocal(_tempMat1); + this.multiplyLocal(_tempMat2); + + return this; + }, + + setWorldMatrix: function (rotation, position, scale, viewMatrix, projectionMatrix) + { + this.yawPitchRoll(rotation.y, rotation.x, rotation.z); + + _tempMat1.scaling(scale.x, scale.y, scale.z); + _tempMat2.xyz(position.x, position.y, position.z); + + this.multiplyLocal(_tempMat1); + this.multiplyLocal(_tempMat2); + + if (viewMatrix !== undefined) + { + this.multiplyLocal(viewMatrix); + } + + if (projectionMatrix !== undefined) + { + this.multiplyLocal(projectionMatrix); + } + return this; } }); -Matrix4.prototype.mul = Matrix4.prototype.multiply; -Matrix4.prototype.idt = Matrix4.prototype.identity; -Matrix4.prototype.reset = Matrix4.prototype.idt; +var _tempMat1 = new Matrix4(); +var _tempMat2 = new Matrix4(); module.exports = Matrix4; diff --git a/v3/src/math/RotateVec3.js b/v3/src/math/RotateVec3.js index 3af665a5d..7405571c9 100644 --- a/v3/src/math/RotateVec3.js +++ b/v3/src/math/RotateVec3.js @@ -21,7 +21,7 @@ var tmpVec3 = new Vector3(); * * @return {Phaser.Math.Vector3} [description] */ -var RotateVec3 = function(vec, axis, radians) +var RotateVec3 = function (vec, axis, radians) { // Set the quaternion to our axis angle tmpQuat.setAxisAngle(axis, radians); diff --git a/v3/src/math/Vector2.js b/v3/src/math/Vector2.js index 6cb2213a1..7d49a2822 100644 --- a/v3/src/math/Vector2.js +++ b/v3/src/math/Vector2.js @@ -260,12 +260,4 @@ var Vector2 = new Class({ }); -Vector2.prototype.sub = Vector2.prototype.subtract; -Vector2.prototype.mul = Vector2.prototype.multiply; -Vector2.prototype.div = Vector2.prototype.divide; -Vector2.prototype.dist = Vector2.prototype.distance; -Vector2.prototype.distSq = Vector2.prototype.distanceSq; -Vector2.prototype.len = Vector2.prototype.length; -Vector2.prototype.lenSq = Vector2.prototype.lengthSq; - module.exports = Vector2; diff --git a/v3/src/math/Vector3.js b/v3/src/math/Vector3.js index 0f14e6f30..de51577bd 100644 --- a/v3/src/math/Vector3.js +++ b/v3/src/math/Vector3.js @@ -23,6 +23,15 @@ var Vector3 = new Class({ } }, + up: function () + { + this.x = 0; + this.y = 1; + this.z = 0; + + return this; + }, + clone: function () { return new Vector3(this.x, this.y, this.z); @@ -258,6 +267,25 @@ var Vector3 = new Class({ return this; }, + transformCoordinates: function (mat) + { + var x = this.x; + var y = this.y; + var z = this.z; + var m = mat.val; + + var tx = (x * m[0]) + (y * m[4]) + (z * m[8]) + m[12]; + var ty = (x * m[1]) + (y * m[5]) + (z * m[9]) + m[13]; + var tz = (x * m[2]) + (y * m[6]) + (z * m[10]) + m[14]; + var tw = (x * m[3]) + (y * m[7]) + (z * m[11]) + m[15]; + + this.x = tx / tw; + this.y = ty / tw; + this.z = tz / tw; + + return this; + }, + transformQuat: function (q) { // benchmarks: http://jsperf.com/quaternion-transform-vec3-implementations @@ -368,12 +396,76 @@ var Vector3 = new Class({ }); -Vector3.prototype.sub = Vector3.prototype.subtract; -Vector3.prototype.mul = Vector3.prototype.multiply; -Vector3.prototype.div = Vector3.prototype.divide; -Vector3.prototype.dist = Vector3.prototype.distance; -Vector3.prototype.distSq = Vector3.prototype.distanceSq; -Vector3.prototype.len = Vector3.prototype.length; -Vector3.prototype.lenSq = Vector3.prototype.lengthSq; +/* +Vector3.Zero = function () +{ + return new Vector3(0, 0, 0); +}; + +Vector3.Up = function () +{ + return new Vector3(0, 1.0, 0); +}; + +Vector3.Copy = function (source) +{ + return new Vector3(source.x, source.y, source.z); +}; + +Vector3.TransformCoordinates = function (vector, transformation) +{ + var x = (vector.x * transformation.m[0]) + (vector.y * transformation.m[4]) + (vector.z * transformation.m[8]) + transformation.m[12]; + var y = (vector.x * transformation.m[1]) + (vector.y * transformation.m[5]) + (vector.z * transformation.m[9]) + transformation.m[13]; + var z = (vector.x * transformation.m[2]) + (vector.y * transformation.m[6]) + (vector.z * transformation.m[10]) + transformation.m[14]; + var w = (vector.x * transformation.m[3]) + (vector.y * transformation.m[7]) + (vector.z * transformation.m[11]) + transformation.m[15]; + + return new Vector3(x / w, y / w, z / w); +}; + +Vector3.TransformNormal = function (vector, transformation) +{ + var x = (vector.x * transformation.m[0]) + (vector.y * transformation.m[4]) + (vector.z * transformation.m[8]); + var y = (vector.x * transformation.m[1]) + (vector.y * transformation.m[5]) + (vector.z * transformation.m[9]); + var z = (vector.x * transformation.m[2]) + (vector.y * transformation.m[6]) + (vector.z * transformation.m[10]); + + return new Vector3(x, y, z); +}; + +Vector3.Dot = function (left, right) +{ + return (left.x * right.x + left.y * right.y + left.z * right.z); +}; + +Vector3.Cross = function (left, right) +{ + var x = left.y * right.z - left.z * right.y; + var y = left.z * right.x - left.x * right.z; + var z = left.x * right.y - left.y * right.x; + + return new Vector3(x, y, z); +}; + +Vector3.Normalize = function (vector) +{ + var newVector = Vector3.Copy(vector); + newVector.normalize(); + + return newVector; +}; + +Vector3.Distance = function (value1, value2) +{ + return Math.sqrt(Vector3.DistanceSquared(value1, value2)); +}; + +Vector3.DistanceSquared = function (value1, value2) +{ + var x = value1.x - value2.x; + var y = value1.y - value2.y; + var z = value1.z - value2.z; + + return (x * x) + (y * y) + (z * z); +}; +*/ module.exports = Vector3; diff --git a/v3/src/renderer/webgl/ResourceManager.js b/v3/src/renderer/webgl/ResourceManager.js index bd6a5d9bf..c075fa5b6 100644 --- a/v3/src/renderer/webgl/ResourceManager.js +++ b/v3/src/renderer/webgl/ResourceManager.js @@ -93,16 +93,19 @@ var ResourceManager = new Class({ } }, - createTexture: function (mipLevel, minFilter, magFilter, wrapT, wrapS, format, pixels, width, height) + createTexture: function (mipLevel, minFilter, magFilter, wrapT, wrapS, format, pixels, width, height, pma) { var gl = this.gl; var texture = gl.createTexture(); + pma = (pma === undefined || pma === null) ? true : pma; + gl.bindTexture(gl.TEXTURE_2D, texture); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, minFilter); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, magFilter); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, wrapS); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, wrapT); + gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, pma); if (pixels === null || pixels === undefined) { diff --git a/v3/src/renderer/webgl/WebGLRenderer.js b/v3/src/renderer/webgl/WebGLRenderer.js index 326aacf03..3f057a9bd 100644 --- a/v3/src/renderer/webgl/WebGLRenderer.js +++ b/v3/src/renderer/webgl/WebGLRenderer.js @@ -142,7 +142,6 @@ var WebGLRenderer = new Class({ gl.disable(gl.CULL_FACE); gl.enable(gl.BLEND); gl.clearColor(color.redGL, color.greenGL, color.blueGL, color.alphaGL); - gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true); // Map Blend Modes this.blendModes = []; diff --git a/v3/src/renderer/webgl/resources/Texture.js b/v3/src/renderer/webgl/resources/Texture.js index 2cc75ab09..6ccd76182 100644 --- a/v3/src/renderer/webgl/resources/Texture.js +++ b/v3/src/renderer/webgl/resources/Texture.js @@ -4,12 +4,13 @@ var Texture = new Class({ initialize: - function Texture (texture, width, height) + function Texture (texture, width, height, pma) { this.texture = texture; this.width = width; this.height = height; this.isRenderTexture = false; + this.isAlphaPremultiplied = pma; } }); diff --git a/v3/src/renderer/webgl/shaders/GBufferShader.js b/v3/src/renderer/webgl/shaders/GBufferShader.js index 49228dd20..fd4a4319b 100644 --- a/v3/src/renderer/webgl/shaders/GBufferShader.js +++ b/v3/src/renderer/webgl/shaders/GBufferShader.js @@ -2,6 +2,8 @@ var GBufferShader = function () { var frag = [ '#extension GL_EXT_draw_buffers : require', + + '// G-Buffer Shader', 'precision mediump float;', @@ -17,7 +19,7 @@ var GBufferShader = function () ' vec4 spriteColor = texture2D(uMainTexture, v_tex_coord) * vec4(v_color, v_alpha);', ' vec3 spriteNormal = texture2D(uNormTexture, v_tex_coord).rgb;', - ' gl_FragData[0] = vec4(spriteColor.rgb * spriteColor.a, spriteColor.a);', + ' gl_FragData[0] = spriteColor;', ' gl_FragData[1] = vec4(spriteNormal, spriteColor.a);', '}' ]; diff --git a/v3/src/renderer/webgl/shaders/LightFragmentShader.js b/v3/src/renderer/webgl/shaders/LightFragmentShader.js index 13544d7c7..376dc3eb0 100644 --- a/v3/src/renderer/webgl/shaders/LightFragmentShader.js +++ b/v3/src/renderer/webgl/shaders/LightFragmentShader.js @@ -1,6 +1,8 @@ var LightFragmentShader = function (maxLights) { var frag = [ + '// Light Fragment Shader ', + 'precision mediump float;', 'struct Light', diff --git a/v3/src/renderer/webgl/shaders/MaskShader.js b/v3/src/renderer/webgl/shaders/MaskShader.js index 5b06b273e..1c50a9de5 100644 --- a/v3/src/renderer/webgl/shaders/MaskShader.js +++ b/v3/src/renderer/webgl/shaders/MaskShader.js @@ -1,5 +1,7 @@ module.exports = { vert: [ + '// Mask Shader ', + 'precision mediump float;', 'attribute vec2 a_position;', 'void main()', @@ -9,6 +11,8 @@ module.exports = { '' ].join('\n'), frag: [ + '// Mask Shader ', + 'precision mediump float;', 'uniform vec2 u_resolution;', 'uniform sampler2D u_main_sampler;', diff --git a/v3/src/renderer/webgl/shaders/ParticleShader.js b/v3/src/renderer/webgl/shaders/ParticleShader.js index 0fbd91fce..504bea966 100644 --- a/v3/src/renderer/webgl/shaders/ParticleShader.js +++ b/v3/src/renderer/webgl/shaders/ParticleShader.js @@ -1,6 +1,8 @@ var ParticleShader = function () { var vert = [ + '// Particle Shader', + 'precision mediump float;', 'uniform mat4 u_view_matrix;', @@ -21,6 +23,8 @@ var ParticleShader = function () ]; var frag = [ + '// Particle Shader', + 'precision mediump float;', 'uniform sampler2D u_main_sampler;', @@ -31,7 +35,7 @@ var ParticleShader = function () 'void main()', '{', ' vec4 sample_color = texture2D(u_main_sampler, v_tex_coord) * v_color;', - ' gl_FragColor = vec4(sample_color.rgb * sample_color.a, sample_color.a);', + ' gl_FragColor = sample_color;', '}' ]; diff --git a/v3/src/renderer/webgl/shaders/Phong2DShaderDeferred.js b/v3/src/renderer/webgl/shaders/Phong2DShaderDeferred.js index 7d4dc8114..9501b4237 100644 --- a/v3/src/renderer/webgl/shaders/Phong2DShaderDeferred.js +++ b/v3/src/renderer/webgl/shaders/Phong2DShaderDeferred.js @@ -1,6 +1,8 @@ var Phong2DShaderDeferred = function (maxLights) { var vert = [ + '// Phong 2D Shader Deferred', + 'precision mediump float;', 'attribute vec2 vertexPosition;', 'void main()', @@ -10,6 +12,8 @@ var Phong2DShaderDeferred = function (maxLights) ]; var frag = [ + '// Phong 2D Shader Deferred', + 'precision mediump float;', 'struct Light', @@ -50,7 +54,7 @@ var Phong2DShaderDeferred = function (maxLights) ' }', ' vec4 color_output = vec4(uAmbientLightColor + finalColor, gbColor.a);', - ' gl_FragColor = vec4(color_output.rgb * color_output.a, color_output.a);', + ' gl_FragColor = color_output;', '}' ]; diff --git a/v3/src/renderer/webgl/shaders/TexturedAndAlphaShader.js b/v3/src/renderer/webgl/shaders/TexturedAndAlphaShader.js index d4f408e92..79f6a5014 100644 --- a/v3/src/renderer/webgl/shaders/TexturedAndAlphaShader.js +++ b/v3/src/renderer/webgl/shaders/TexturedAndAlphaShader.js @@ -1,5 +1,7 @@ module.exports = { vert: [ + '// Textured and Alpha Shader', + 'uniform mat4 u_view_matrix;', 'attribute vec2 a_position;', 'attribute vec2 a_tex_coord;', @@ -13,13 +15,15 @@ module.exports = { '}' ].join('\n'), frag: [ + '// Textured and Alpha Shader', + 'precision mediump float;', 'uniform sampler2D u_sampler2D;', 'varying vec2 v_tex_coord;', 'varying float v_alpha;', 'void main() {', ' vec4 output_color = texture2D(u_sampler2D, v_tex_coord);', - ' gl_FragColor = vec4(output_color.rgb * v_alpha * output_color.a, v_alpha * output_color.a);', + ' gl_FragColor = output_color;', '}' ].join('\n') }; diff --git a/v3/src/renderer/webgl/shaders/TexturedAndNormalizedTintedShader.js b/v3/src/renderer/webgl/shaders/TexturedAndNormalizedTintedShader.js index 39b743888..f2c885aae 100644 --- a/v3/src/renderer/webgl/shaders/TexturedAndNormalizedTintedShader.js +++ b/v3/src/renderer/webgl/shaders/TexturedAndNormalizedTintedShader.js @@ -1,5 +1,7 @@ module.exports = { vert: [ + '// Textured and Normalized Tint Shader', + 'uniform mat4 u_view_matrix;', 'attribute vec2 a_position;', 'attribute vec2 a_tex_coord;', @@ -16,6 +18,8 @@ module.exports = { '}' ].join('\n'), frag: [ + '// Textured and Normalized Tint Shader', + 'precision mediump float;', 'uniform sampler2D u_sampler2D;', 'varying vec2 v_tex_coord;', @@ -23,7 +27,7 @@ module.exports = { 'varying float v_alpha;', 'void main() {', ' vec4 sample_color = texture2D(u_sampler2D, v_tex_coord);', - ' gl_FragColor = vec4(sample_color.rgb * v_alpha * sample_color.a, v_alpha * sample_color.a);', + ' gl_FragColor = sample_color;', '}' ].join('\n') }; diff --git a/v3/src/renderer/webgl/shaders/TexturedShader.js b/v3/src/renderer/webgl/shaders/TexturedShader.js index ae56ebec0..31ea458ee 100644 --- a/v3/src/renderer/webgl/shaders/TexturedShader.js +++ b/v3/src/renderer/webgl/shaders/TexturedShader.js @@ -1,5 +1,7 @@ module.exports = { vert: [ + '// Textured Shader', + 'uniform mat4 u_view_matrix;', 'attribute vec2 a_position;', 'attribute vec2 a_tex_coord;', @@ -10,12 +12,14 @@ module.exports = { '}' ].join('\n'), frag: [ + '// Textured Shader', + 'precision mediump float;', 'uniform sampler2D u_sampler;', 'varying vec2 v_tex_coord;', 'void main(void) {', ' vec4 output_color = texture2D(u_sampler, v_tex_coord);', - ' gl_FragColor = vec4(output_color.rgb * output_color.a, output_color.a);', + ' gl_FragColor = output_color;', '}' ].join('\n') }; diff --git a/v3/src/renderer/webgl/shaders/TexturedTwirlShader.js b/v3/src/renderer/webgl/shaders/TexturedTwirlShader.js index 80e7db8a7..537d43f8f 100644 --- a/v3/src/renderer/webgl/shaders/TexturedTwirlShader.js +++ b/v3/src/renderer/webgl/shaders/TexturedTwirlShader.js @@ -1,5 +1,7 @@ module.exports = { vert: [ + '// Textured Twirl Shader', + 'attribute vec2 a_position;', 'attribute vec2 a_tex_coord;', 'varying vec2 v_tex_coord;', @@ -9,6 +11,8 @@ module.exports = { '}' ].join('\n'), frag: [ + '// Textured Twirl Shader', + 'precision mediump float;', 'uniform sampler2D u_sampler;', 'uniform float time;', @@ -27,7 +31,7 @@ module.exports = { ' coord = vec2(coord.x * c - coord.y * s, coord.x * s + coord.y * c);', ' }', ' vec4 output_color = texture2D(u_sampler, coord + offset);', - ' gl_FragColor = vec4(output_color.rgb * output_color.a, output_color.a);', + ' gl_FragColor = output_color;', '}' ].join('\n') }; diff --git a/v3/src/renderer/webgl/shaders/TilemapShader.js b/v3/src/renderer/webgl/shaders/TilemapShader.js index a6a9c5898..cb712b25d 100644 --- a/v3/src/renderer/webgl/shaders/TilemapShader.js +++ b/v3/src/renderer/webgl/shaders/TilemapShader.js @@ -1,5 +1,7 @@ module.exports = { vert: [ + '// Tilemap Shader', + 'precision mediump float;', '', 'uniform mat4 u_view_matrix;', @@ -25,13 +27,15 @@ module.exports = { '' ].join('\n'), frag: [ + '// Tilemap Shader', + 'precision mediump float;', 'uniform sampler2D u_sampler2D;', 'varying vec2 v_tex_coord;', 'void main()', '{', ' vec4 output_color = texture2D(u_sampler2D, v_tex_coord);', - ' gl_FragColor = vec4(output_color.rgb * output_color.a, output_color.a);', + ' gl_FragColor = output_color;', '}' ].join('\n') }; diff --git a/v3/src/renderer/webgl/shaders/UntexturedAndNormalizedTintedShader.js b/v3/src/renderer/webgl/shaders/UntexturedAndNormalizedTintedShader.js index f607f565d..5dfc7deef 100644 --- a/v3/src/renderer/webgl/shaders/UntexturedAndNormalizedTintedShader.js +++ b/v3/src/renderer/webgl/shaders/UntexturedAndNormalizedTintedShader.js @@ -1,5 +1,7 @@ module.exports = { vert: [ + '// Untextured And Normalized Tinted Shader', + 'precision mediump float;', 'uniform mat4 u_view_matrix;', 'attribute vec2 a_position;', @@ -14,6 +16,8 @@ module.exports = { '}' ].join('\n'), frag: [ + '// Untextured And Normalized Tinted Shader', + 'precision mediump float;', 'varying vec4 v_color;', 'varying float v_alpha;', diff --git a/v3/src/renderer/webgl/shaders/UntexturedAndTintedShader.js b/v3/src/renderer/webgl/shaders/UntexturedAndTintedShader.js index 7eba0f7d8..77dbcf827 100644 --- a/v3/src/renderer/webgl/shaders/UntexturedAndTintedShader.js +++ b/v3/src/renderer/webgl/shaders/UntexturedAndTintedShader.js @@ -1,5 +1,7 @@ module.exports = { vert: [ + '// Untextured And Tinted Shader', + 'uniform mat4 u_view_matrix;', 'attribute vec2 a_position;', 'attribute vec4 a_color;', @@ -10,10 +12,12 @@ module.exports = { '}' ].join('\n'), frag:[ + '// Untextured And Tinted Shader', + 'precision lowp float;', 'varying vec4 v_color;', 'void main() {', - ' gl_FragColor = vec4(v_color.rgb * v_color.a, v_color.a);', + ' gl_FragColor = vec4(v_color.rgb, v_color.a);', '}' ].join('\n') }; diff --git a/v3/src/renderer/webgl/shaders/UntexturedPlasmaShader.js b/v3/src/renderer/webgl/shaders/UntexturedPlasmaShader.js index e98291c94..394481ba0 100644 --- a/v3/src/renderer/webgl/shaders/UntexturedPlasmaShader.js +++ b/v3/src/renderer/webgl/shaders/UntexturedPlasmaShader.js @@ -1,11 +1,15 @@ module.exports = { vert: [ + '// Untextured Plasma Shader', + 'attribute vec2 a_position;', 'void main(void) {', ' gl_Position = vec4(a_position, 0.0, 1.0);', '}' ].join('\n'), frag: [ + '// Untextured Plasma Shader', + 'precision mediump float;', 'uniform float time;', '// Oldskool plasma shader. (c) Victor Korsun, bitekas@gmail.com; 1996-2013.', diff --git a/v3/src/scene/plugins/Loader.js b/v3/src/scene/plugins/Loader.js index db777ae6f..c5b5df4b1 100644 --- a/v3/src/scene/plugins/Loader.js +++ b/v3/src/scene/plugins/Loader.js @@ -1,10 +1,11 @@ var BaseLoader = require('../../loader/BaseLoader'); var Class = require('../../utils/Class'); -var NumberArray = require('../../utils/array/NumberArray'); var CONST = require('../../loader/const'); +var NumberArray = require('../../utils/array/NumberArray'); var AnimationJSONFile = require('../../loader/filetypes/AnimationJSONFile'); var AtlasJSONFile = require('../../loader/filetypes/AtlasJSONFile'); +var AudioFile = require('../../loader/filetypes/AudioFile'); var BinaryFile = require('../../loader/filetypes/BinaryFile'); var BitmapFontFile = require('../../loader/filetypes/BitmapFontFile'); var GLSLFile = require('../../loader/filetypes/GLSLFile'); @@ -15,11 +16,11 @@ var ScriptFile = require('../../loader/filetypes/ScriptFile'); var SpriteSheet = require('../../loader/filetypes/SpriteSheet'); var SVGFile = require('../../loader/filetypes/SVGFile'); var TextFile = require('../../loader/filetypes/TextFile'); -var UnityAtlasFile = require('../../loader/filetypes/UnityAtlasFile'); -var XMLFile = require('../../loader/filetypes/XMLFile'); -var AudioFile = require('../../loader/filetypes/AudioFile'); var TilemapCSVFile = require('../../loader/filetypes/TilemapCSVFile'); var TilemapJSONFile = require('../../loader/filetypes/TilemapJSONFile'); +var UnityAtlasFile = require('../../loader/filetypes/UnityAtlasFile'); +var WavefrontFile = require('../../loader/filetypes/WavefrontFile'); +var XMLFile = require('../../loader/filetypes/XMLFile'); var Loader = new Class({ @@ -86,6 +87,11 @@ var Loader = new Class({ return SVGFile.create(this, key, url, xhrSettings); }, + obj: function (key, url, xhrSettings) + { + return WavefrontFile.create(this, key, url, xhrSettings); + }, + // config can include: frameWidth, frameHeight, startFrame, endFrame, margin, spacing spritesheet: function (key, url, config, xhrSettings) { @@ -281,7 +287,7 @@ var Loader = new Class({ entry = this.audioSprite(file.key, file.urls, file.json, file.config, file.audioXhrSettings, file.jsonXhrSettings); break; - // image, json, xml, binary, text, glsl, svg + // image, json, xml, binary, text, glsl, svg, obj default: entry = this[file.type](file.key, file.url, file.xhrSettings); break;