diff --git a/README.md b/README.md index e93d22951dc..54ea64a780c 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,8 @@ The PlayCanvas Engine is a fully featured 3D game engine. * 3D Positional audio via Web Audio API * **Resource Loading** * Simple and powerful resource loading + * Streaming of individual assets + * Asset Variants - loads compressed textures (DXT, PVR, ETC1) based on platform support * **Entity / Component System** * Built-in components: model, sound, animation, camera, collision, light, rigidbody, script, particlesystem * **Scripting system** diff --git a/src/graphics/device.js b/src/graphics/device.js index 9a558981f04..2d055914bea 100644 --- a/src/graphics/device.js +++ b/src/graphics/device.js @@ -647,6 +647,11 @@ pc.extend(pc, function () { this._renderTargetCreationTime = 0; this._vram = { + // #ifdef PROFILER + texShadow: 0, + texAsset: 0, + texLightmap: 0, + // #endif tex: 0, vb: 0, ib: 0 @@ -1201,6 +1206,15 @@ pc.extend(pc, function () { if (texture._gpuSize) this._vram.tex -= texture._gpuSize; texture._gpuSize = gpuTexSize(gl, texture); this._vram.tex += texture._gpuSize; + // #ifdef PROFILER + if (texture.profilerHint===pc.TEXHINT_SHADOWMAP) { + this._vram.texShadow += texture._gpuSize; + } else if (texture.profilerHint===pc.TEXHINT_ASSET) { + this._vram.texAsset += texture._gpuSize; + } else if (texture.profilerHint===pc.TEXHINT_LIGHTMAP) { + this._vram.texLightmap += texture._gpuSize; + } + // #endif }, setTexture: function (texture, textureUnit) { diff --git a/src/graphics/graphics.js b/src/graphics/graphics.js index 1d39b8b1a95..0bcfa30a0c9 100644 --- a/src/graphics/graphics.js +++ b/src/graphics/graphics.js @@ -667,6 +667,11 @@ */ TEXTURELOCK_WRITE: 2, + TEXHINT_NONE: 0, + TEXHINT_SHADOWMAP: 1, + TEXHINT_ASSET: 2, + TEXHINT_LIGHTMAP: 3, + UNIFORMTYPE_BOOL: 0, UNIFORMTYPE_INT: 1, UNIFORMTYPE_FLOAT: 2, diff --git a/src/graphics/program-lib/chunks/tonemappingAces.frag b/src/graphics/program-lib/chunks/tonemappingAces.frag new file mode 100644 index 00000000000..2f421fae8f6 --- /dev/null +++ b/src/graphics/program-lib/chunks/tonemappingAces.frag @@ -0,0 +1,11 @@ +uniform float exposure; + +vec3 toneMap(vec3 color) { + float tA = 2.51; + float tB = 0.03; + float tC = 2.43; + float tD = 0.59; + float tE = 0.14; + vec3 x = color * exposure; + return (x*(tA*x+tB))/(x*(tC*x+tD)+tE); +} diff --git a/src/graphics/program-lib/chunks/tonemappingHejl.frag b/src/graphics/program-lib/chunks/tonemappingHejl.frag new file mode 100644 index 00000000000..e12a56cedf8 --- /dev/null +++ b/src/graphics/program-lib/chunks/tonemappingHejl.frag @@ -0,0 +1,9 @@ +uniform float exposure; + +vec3 toneMap(vec3 color) { + color *= exposure; + vec3 x = max(vec3(0.0), color - vec3(0.004)); + color = (x*(6.2*x + 0.5)) / (x*(6.2*x + 1.7) + 0.06); + return gammaCorrectInput(color); +} + diff --git a/src/graphics/program-lib/program-lib.js b/src/graphics/program-lib/program-lib.js index 95310911418..9127307808a 100644 --- a/src/graphics/program-lib/program-lib.js +++ b/src/graphics/program-lib/program-lib.js @@ -9,6 +9,10 @@ pc.programlib = { return pc.shaderChunks.tonemappingFilmicPS; } else if (value===pc.TONEMAP_LINEAR) { return pc.shaderChunks.tonemappingLinearPS; + } else if (value===pc.TONEMAP_HEJL) { + return pc.shaderChunks.tonemappingHejlPS; + } else if (value===pc.TONEMAP_ACES) { + return pc.shaderChunks.tonemappingAcesPS; } return pc.shaderChunks.tonemappingNonePS; }, diff --git a/src/graphics/texture.js b/src/graphics/texture.js index f1e2aa0dc14..98235731aa9 100644 --- a/src/graphics/texture.js +++ b/src/graphics/texture.js @@ -69,6 +69,9 @@ pc.extend(pc, function () { var cubemap = false; var rgbm = false; var fixCubemapSeams = false; + // #ifdef PROFILER + var hint = 0; + // #endif if (options !== undefined) { width = (options.width !== undefined) ? options.width : width; @@ -77,6 +80,9 @@ pc.extend(pc, function () { cubemap = (options.cubemap !== undefined) ? options.cubemap : cubemap; rgbm = (options.rgbm !== undefined)? options.rgbm : rgbm; fixCubemapSeams = (options.fixCubemapSeams !== undefined)? options.fixCubemapSeams : fixCubemapSeams; + // #ifdef PROFILER + hint = (options.profilerHint !== undefined)? options.profilerHint : 0; + // #endif } // PUBLIC @@ -84,6 +90,10 @@ pc.extend(pc, function () { this.rgbm = rgbm; this.fixCubemapSeams = fixCubemapSeams; + // #ifdef PROFILER + this.profilerHint = hint; + // #endif + // PRIVATE this._cubemap = cubemap; this._format = format; @@ -348,7 +358,18 @@ pc.extend(pc, function () { if (this._glTextureId) { var gl = this.device.gl; gl.deleteTexture(this._glTextureId); + this.device._vram.tex -= this._gpuSize; + // #ifdef PROFILER + if (this.profilerHint===pc.TEXHINT_SHADOWMAP) { + this.device._vram.texShadow -= this._gpuSize; + } else if (this.profilerHint===pc.TEXHINT_ASSET) { + this.device._vram.texAsset -= this._gpuSize; + } else if (this.profilerHint===pc.TEXHINT_LIGHTMAP) { + this.device._vram.texLightmap -= this._gpuSize; + } + // #endif + this._glTextureId = null; } }, diff --git a/src/resources/texture.js b/src/resources/texture.js index 988813a63d4..0b1e0b72055 100644 --- a/src/resources/texture.js +++ b/src/resources/texture.js @@ -108,6 +108,9 @@ pc.extend(pc, function () { format = (ext === ".jpg" || ext === ".jpeg") ? pc.PIXELFORMAT_R8_G8_B8 : pc.PIXELFORMAT_R8_G8_B8_A8; texture = new pc.Texture(this._device, { + // #ifdef PROFILER + profilerHint: pc.TEXHINT_ASSET, + // #endif width: img.width, height: img.height, format: format @@ -204,6 +207,9 @@ pc.extend(pc, function () { } var texOptions = { + // #ifdef PROFILER + profilerHint: pc.TEXHINT_ASSET, + // #endif width: width, height: height, format: format, diff --git a/src/scene/forward-renderer.js b/src/scene/forward-renderer.js index d1eb40771c4..9c9509b9035 100644 --- a/src/scene/forward-renderer.js +++ b/src/scene/forward-renderer.js @@ -352,6 +352,9 @@ pc.extend(pc, function () { function createShadowMap(device, width, height, shadowType) { var format = getShadowFormat(shadowType); var shadowMap = new pc.Texture(device, { + // #ifdef PROFILER + profilerHint: pc.TEXHINT_SHADOWMAP, + // #endif format: format, width: width, height: height, @@ -367,6 +370,9 @@ pc.extend(pc, function () { function createShadowCubeMap(device, size) { var cubemap = new pc.Texture(device, { + // #ifdef PROFILER + profilerHint: pc.TEXHINT_SHADOWMAP, + // #endif format: pc.PIXELFORMAT_R8_G8_B8_A8, width: size, height: size, diff --git a/src/scene/lightmapper.js b/src/scene/lightmapper.js index c8125fa91ef..e8773e1bdb9 100644 --- a/src/scene/lightmapper.js +++ b/src/scene/lightmapper.js @@ -87,7 +87,6 @@ pc.extend(pc, function () { this._stats = { renderPasses: 0, lightmapCount: 0, - lightmapMem: 0, totalRenderTime: 0, forwardTime: 0, fboTime: 0, @@ -176,7 +175,7 @@ pc.extend(pc, function () { var pass; // #ifdef PROFILER - stats.renderPasses = stats.lightmapMem = stats.shadowMapTime = stats.forwardTime = 0; + stats.renderPasses = stats.shadowMapTime = stats.forwardTime = 0; var startShaders = device._shaderStats.linked; var startFboTime = device._renderTargetCreationTime; var startCompileTime = device._shaderStats.compileTime; @@ -262,7 +261,11 @@ pc.extend(pc, function () { size = this.calculateLightmapSize(nodes[i]); texSize.push(size); for(pass=0; pass *
  • pc.TONEMAP_LINEAR
  • *
  • pc.TONEMAP_FILMIC
  • + *
  • pc.TONEMAP_HEJL
  • + *
  • pc.TONEMAP_ACES
  • * * Defaults to pc.TONEMAP_LINEAR. * @property {pc.Texture} skybox A cube map texture used as the scene's skybox. Defaults to null.