Skip to content

Commit

Permalink
Merge branch 'master' of github.com:playcanvas/engine
Browse files Browse the repository at this point in the history
  • Loading branch information
daredevildave committed Sep 16, 2016
2 parents 902816c + 8646e59 commit 4790aad
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**
Expand Down
14 changes: 14 additions & 0 deletions src/graphics/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions src/graphics/graphics.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 11 additions & 0 deletions src/graphics/program-lib/chunks/tonemappingAces.frag
Original file line number Diff line number Diff line change
@@ -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);
}
9 changes: 9 additions & 0 deletions src/graphics/program-lib/chunks/tonemappingHejl.frag
Original file line number Diff line number Diff line change
@@ -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);
}

4 changes: 4 additions & 0 deletions src/graphics/program-lib/program-lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
Expand Down
21 changes: 21 additions & 0 deletions src/graphics/texture.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -77,13 +80,20 @@ 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
this.name = null;
this.rgbm = rgbm;
this.fixCubemapSeams = fixCubemapSeams;

// #ifdef PROFILER
this.profilerHint = hint;
// #endif

// PRIVATE
this._cubemap = cubemap;
this._format = format;
Expand Down Expand Up @@ -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;
}
},
Expand Down
6 changes: 6 additions & 0 deletions src/resources/texture.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -204,6 +207,9 @@ pc.extend(pc, function () {
}

var texOptions = {
// #ifdef PROFILER
profilerHint: pc.TEXHINT_ASSET,
// #endif
width: width,
height: height,
format: format,
Expand Down
6 changes: 6 additions & 0 deletions src/scene/forward-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
16 changes: 11 additions & 5 deletions src/scene/lightmapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ pc.extend(pc, function () {
this._stats = {
renderPasses: 0,
lightmapCount: 0,
lightmapMem: 0,
totalRenderTime: 0,
forwardTime: 0,
fboTime: 0,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -262,7 +261,11 @@ pc.extend(pc, function () {
size = this.calculateLightmapSize(nodes[i]);
texSize.push(size);
for(pass=0; pass<passCount; pass++) {
tex = new pc.Texture(device, {width:size,
tex = new pc.Texture(device, {
// #ifdef PROFILER
profilerHint: pc.TEXHINT_LIGHTMAP,
// #endif
width:size,
height:size,
format:pc.PIXELFORMAT_R8_G8_B8_A8,
autoMipmap:false,
Expand All @@ -272,11 +275,14 @@ pc.extend(pc, function () {
tex._minFilter = pc.FILTER_NEAREST;
tex._magFilter = pc.FILTER_NEAREST
lmaps[pass].push(tex);
stats.lightmapMem += size * size * 4;
}

if (!texPool[size]) {
var tex2 = new pc.Texture(device, {width:size,
var tex2 = new pc.Texture(device, {
// #ifdef PROFILER
profilerHint: pc.TEXHINT_LIGHTMAP,
// #endif
width:size,
height:size,
format:pc.PIXELFORMAT_R8_G8_B8_A8,
autoMipmap:false,
Expand Down
4 changes: 4 additions & 0 deletions src/scene/scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@

TONEMAP_LINEAR: 0,
TONEMAP_FILMIC: 1,
TONEMAP_HEJL: 2,
TONEMAP_ACES: 3,

SPECOCC_NONE: 0,
SPECOCC_AO: 1,
Expand Down Expand Up @@ -250,6 +252,8 @@ pc.extend(pc, function () {
* <ul>
* <li>pc.TONEMAP_LINEAR</li>
* <li>pc.TONEMAP_FILMIC</li>
* <li>pc.TONEMAP_HEJL</li>
* <li>pc.TONEMAP_ACES</li>
* </ul>
* Defaults to pc.TONEMAP_LINEAR.
* @property {pc.Texture} skybox A cube map texture used as the scene's skybox. Defaults to null.
Expand Down

0 comments on commit 4790aad

Please sign in to comment.