From 7dc0bbef3076b5ea2d2d9f64afa40944117c3dcf Mon Sep 17 00:00:00 2001 From: Yun Hsiao Wu Date: Thu, 21 Mar 2019 00:18:29 +0800 Subject: [PATCH 01/11] preview (#4071) * yellow for missing effect * default viewID --- cocos/3d/assets/material.ts | 3 ++- cocos/3d/builtin/init.ts | 24 +++++++++++++++++------- cocos/3d/framework/model-component.ts | 2 +- cocos/3d/geom-utils/ray.ts | 2 +- cocos/3d/geom-utils/triangle.ts | 2 +- cocos/renderer/scene/model.ts | 2 +- cocos/renderer/scene/render-scene.ts | 4 ++-- playground/planarShadow.html | 2 +- 8 files changed, 26 insertions(+), 15 deletions(-) diff --git a/cocos/3d/assets/material.ts b/cocos/3d/assets/material.ts index 718caf9e55..fd9e739fab 100644 --- a/cocos/3d/assets/material.ts +++ b/cocos/3d/assets/material.ts @@ -207,7 +207,8 @@ export class Material extends Asset { protected _update (keepProps: boolean = true) { const asset = this._effectAsset; - if (!asset) { this._passes = builtinResMgr.get('default-material')._passes.slice(); return; } + // ugly yellow indicating missing effect + if (!asset) { this._passes = builtinResMgr.get('missing-effect-material')._passes.slice(); return; } // create passes this._passes = Effect.parseEffect(asset, { techIdx: this._techIdx, diff --git a/cocos/3d/builtin/init.ts b/cocos/3d/builtin/init.ts index 59bc2d6131..fd121e6650 100644 --- a/cocos/3d/builtin/init.ts +++ b/cocos/3d/builtin/init.ts @@ -125,7 +125,7 @@ class BuiltinResMgr { effect.onLoaded(); }); - // tonemap material + // smaa material const smaaMtl = new cc.Material(); smaaMtl._uuid = 'smaa-material'; smaaMtl.initialize({ @@ -149,15 +149,25 @@ class BuiltinResMgr { }); resources[standardMtl._uuid] = standardMtl; - // default material - const defaultMtl = new cc.Material(); - defaultMtl._uuid = 'default-material'; - defaultMtl.initialize({ + // material indicating missing material (purple) + const missingMtl = new cc.Material(); + missingMtl._uuid = 'missing-material'; + missingMtl.initialize({ effectName: 'builtin-unlit', defines: { USE_COLOR: true }, }); - defaultMtl.setProperty('color', cc.color('#ff00ff')); - resources[defaultMtl._uuid] = defaultMtl; + missingMtl.setProperty('color', cc.color('#ff00ff')); + resources[missingMtl._uuid] = missingMtl; + + // material indicating missing effect (yellow) + const missingEfxMtl = new cc.Material(); + missingEfxMtl._uuid = 'missing-effect-material'; + missingEfxMtl.initialize({ + effectName: 'builtin-unlit', + defines: { USE_COLOR: true }, + }); + missingEfxMtl.setProperty('color', cc.color('#ffff00')); + resources[missingEfxMtl._uuid] = missingEfxMtl; // sprite material const spriteMtl = new cc.Material(); diff --git a/cocos/3d/framework/model-component.ts b/cocos/3d/framework/model-component.ts index c27ef4da4b..1a7dbd93c9 100644 --- a/cocos/3d/framework/model-component.ts +++ b/cocos/3d/framework/model-component.ts @@ -284,6 +284,6 @@ export class ModelComponent extends RenderableComponent { private _getBuiltinMaterial () { // classic ugly pink indicating missing material - return builtinResMgr.get('default-material'); + return builtinResMgr.get('missing-material'); } } diff --git a/cocos/3d/geom-utils/ray.ts b/cocos/3d/geom-utils/ray.ts index 421bc40790..08e0db4f3b 100644 --- a/cocos/3d/geom-utils/ray.ts +++ b/cocos/3d/geom-utils/ray.ts @@ -14,7 +14,7 @@ export default class ray { * @param {number} dz dir Z component * @return {ray} */ - public static create (ox, oy, oz, dx, dy, dz) { + public static create (ox = 0, oy = 0, oz = 0, dx = 0, dy = 0, dz = 1) { return new ray(ox, oy, oz, dx, dy, dz); } diff --git a/cocos/3d/geom-utils/triangle.ts b/cocos/3d/geom-utils/triangle.ts index f221ac30f6..2db49b5c88 100644 --- a/cocos/3d/geom-utils/triangle.ts +++ b/cocos/3d/geom-utils/triangle.ts @@ -17,7 +17,7 @@ export default class triangle { * @param {number} cz * @return {triangle} */ - public static create (ax, ay, az, bx, by, bz, cx, cy, cz) { + public static create (ax = 1, ay = 0, az = 0, bx = 0, by = 0, bz = 0, cx = 0, cy = 0, cz = 1) { return new triangle(ax, ay, az, bx, by, bz, cx, cy, cz); } diff --git a/cocos/renderer/scene/model.ts b/cocos/renderer/scene/model.ts index 054df30e0d..eaf18cfb5c 100644 --- a/cocos/renderer/scene/model.ts +++ b/cocos/renderer/scene/model.ts @@ -121,7 +121,7 @@ export class Model { protected _node: Node | null; protected _id: number; protected _enabled: boolean = false; - protected _viewID: number = -1; + protected _viewID: number = 1; protected _cameraID: number = -1; protected _userKey: number = -1; protected _worldBounds: aabb | null = null; diff --git a/cocos/renderer/scene/render-scene.ts b/cocos/renderer/scene/render-scene.ts index 4c599d0d41..46d885b65e 100644 --- a/cocos/renderer/scene/render-scene.ts +++ b/cocos/renderer/scene/render-scene.ts @@ -247,8 +247,8 @@ const v3 = new Vec3(); const m4 = new Mat4(); let distance = Infinity; const tri = triangle.create(); -const pool = new RecyclePool(() => { - return { node: null, distance: Infinity }; +const pool = new RecyclePool(() => { + return { node: null!, distance: Infinity }; }, 8); const results: IRaycastResult[] = []; diff --git a/playground/planarShadow.html b/playground/planarShadow.html index 8a73ee44cf..2cc9ab0495 100644 --- a/playground/planarShadow.html +++ b/playground/planarShadow.html @@ -127,7 +127,7 @@ // const spNode = new cc.Node('test'); // spNode.parent = rt; // const spCom = spNode.addComponent('cc.ModelComponent'); - // spCom.material = cc.builtinResMgr.get('default-material'); + // spCom.material = cc.builtinResMgr.get('missing-material'); // spCom.mesh = cc.utils.createMesh(sp); cc.director.runSceneImmediate(scene); From 5f7ae5ca9e25c9a53b103465b5d716d3ac7b6c38 Mon Sep 17 00:00:00 2001 From: jerrywwl Date: Thu, 21 Mar 2019 09:47:49 +0800 Subject: [PATCH 02/11] complete smaa --- cocos/3d/builtin/effects.js | 9 ++--- cocos/3d/builtin/init.ts | 16 --------- cocos/pipeline/forward/forward-flow.ts | 5 ++- cocos/pipeline/forward/forward-pipeline.ts | 6 ++++ cocos/pipeline/forward/forward-stage.ts | 3 ++ cocos/pipeline/ppfx/smaa-blend-stage.ts | 3 ++ cocos/pipeline/ppfx/smaa-edge-stage.ts | 3 ++ cocos/pipeline/ppfx/smaa-flow.ts | 18 +++++++--- cocos/pipeline/ppfx/tonemap-flow.ts | 15 +++++++++ cocos/pipeline/ppfx/tonemap-stage.ts | 39 +++++++++++++--------- cocos/pipeline/render-flow.ts | 1 + cocos/pipeline/render-pipeline.ts | 8 +++++ cocos/pipeline/render-stage.ts | 1 + cocos/pipeline/ui/ui-flow.ts | 6 +++- cocos/pipeline/ui/ui-pipeline.ts | 3 ++ cocos/pipeline/ui/ui-stage.ts | 8 ++++- 16 files changed, 101 insertions(+), 43 deletions(-) diff --git a/cocos/3d/builtin/effects.js b/cocos/3d/builtin/effects.js index aa1dd51421..87ba1db86e 100644 --- a/cocos/3d/builtin/effects.js +++ b/cocos/3d/builtin/effects.js @@ -258,18 +258,19 @@ export default [ "shaders": [ { "name": "builtin-tonemap|tonemap-vs:vert|tonemap-fs:frag", - "hash": 4107803358, + "hash": 2576875653, "glsl3": { "vert": `\nprecision highp float;\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define EPSILON 1e-6\n#define LOG2 1.442695\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#define FP_MAX = 65504.0;\n#define FP_SCALE (1.0/1024.0);\n#define FP_SCALE_INV 1024.0;\nuniform CCGlobal {\n vec4 cc_time; \n vec4 cc_screenSize; \n vec4 cc_screenScale; \n vec4 cc_nativeSize; \n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos; \n vec4 cc_exposure; \n vec4 cc_mainLitDir; \n vec4 cc_mainLitColor; \n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\nin vec2 a_position;\nin vec2 a_texCoord;\nout vec2 v_uv;\nout vec4 v_offset;\nvec4 vert () {\n vec4 pos = vec4(a_position, 0, 1);\n v_uv = a_texCoord * cc_screenScale.xy;\n v_offset = v_uv.xyxy + cc_nativeSize.zwzw * vec4(1.0, 0.0, 0.0, -1.0);\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n`, - "frag": `\nprecision highp float;\nuniform CCGlobal {\n vec4 cc_time; \n vec4 cc_screenSize; \n vec4 cc_screenScale; \n vec4 cc_nativeSize; \n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos; \n vec4 cc_exposure; \n vec4 cc_mainLitDir; \n vec4 cc_mainLitColor; \n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define EPSILON 1e-6\n#define LOG2 1.442695\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#define FP_MAX = 65504.0;\n#define FP_SCALE (1.0/1024.0);\n#define FP_SCALE_INV 1024.0;\nvec3 SRGBToLinear(vec3 gamma)\n{\n return pow(gamma, vec3(2.2));\n \n}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\n \n}\nvec3 ACESToneMap(vec3 color) {\n const float A = 2.51;\n const float B = 0.03;\n const float C = 2.43;\n const float D = 0.59;\n const float E = 0.14;\n return (color * (A * color + B)) / (color * (C * color + D) + E);\n}\nin vec2 v_uv;\nin vec4 v_offset;\nuniform sampler2D u_texSampler;\nuniform sampler2D u_blendTexSampler;\nvec3 ToLDR(vec3 color) {\n#if CC_USE_HDR\n color *= cc_exposure.x * 1024.0;;\n color = ACESToneMap(color);\n color = LinearToSRGB(color);\n#endif\n return color;\n}\n#define CC_USE_SMAA 1\nvec4 frag () {\n#if 1\n \n vec4 a;\n a.rb = texture(u_blendTexSampler, v_uv).rb; \n a.g = texture(u_blendTexSampler, v_offset.zw).g; \n a.a = texture(u_blendTexSampler, v_offset.xy).a; \n if (dot(a, vec4(1.0)) < 1e-5) {\n vec4 o = texture(u_texSampler, v_uv);\n o.rgb = ToLDR(o.rgb);\n return o;\n } else {\n vec2 offset;\n offset.x = a.a > a.b ? a.a : -a.b;\n offset.y = a.g > a.r ? -a.g : a.r;\n if (abs(offset.x) > abs(offset.y)) {\n offset.y = 0.0;\n } else {\n offset.x = 0.0;\n }\n vec4 C = texture(u_texSampler, v_uv);\n C.rgb = ToLDR(C.rgb);\n vec2 uv = v_uv + sign(offset) * cc_nativeSize.zw;\n vec4 Cop = texture(u_texSampler, uv);\n Cop.rgb = ToLDR(Cop.rgb);\n float s = abs(offset.x) > abs(offset.y) ? abs(offset.x) : abs(offset.y);\n C.rgb = pow(C.rgb, vec3(2.2));\n Cop.rgb = pow(Cop.rgb, vec3(2.2));\n vec4 mixed = mix(C, Cop, s);\n mixed.rgb = pow(mixed.rgb, vec3(1.0 / 2.2));\n return mixed;\n }\n#else \n vec4 o = texture(u_texSampler, v_uv);\n \n o.rgb = ToLDR(o.rgb);\n return o;\n#endif\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }\n` + "frag": `\nprecision highp float;\nuniform CCGlobal {\n vec4 cc_time; \n vec4 cc_screenSize; \n vec4 cc_screenScale; \n vec4 cc_nativeSize; \n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos; \n vec4 cc_exposure; \n vec4 cc_mainLitDir; \n vec4 cc_mainLitColor; \n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define EPSILON 1e-6\n#define LOG2 1.442695\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#define FP_MAX = 65504.0;\n#define FP_SCALE (1.0/1024.0);\n#define FP_SCALE_INV 1024.0;\nvec3 SRGBToLinear(vec3 gamma)\n{\n return pow(gamma, vec3(2.2));\n \n}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\n \n}\nvec3 ACESToneMap(vec3 color) {\n const float A = 2.51;\n const float B = 0.03;\n const float C = 2.43;\n const float D = 0.59;\n const float E = 0.14;\n return (color * (A * color + B)) / (color * (C * color + D) + E);\n}\nin vec2 v_uv;\nin vec4 v_offset;\nuniform sampler2D u_texSampler;\nuniform sampler2D u_blendTexSampler;\nvec3 ToLDR(vec3 color) {\n#if CC_USE_HDR\n color *= cc_exposure.x * 1024.0;;\n color = ACESToneMap(color);\n color = LinearToSRGB(color);\n#endif\n return color;\n}\nvec4 frag () {\n#if CC_USE_SMAA\n \n vec4 a;\n a.rb = texture(u_blendTexSampler, v_uv).rb; \n a.g = texture(u_blendTexSampler, v_offset.zw).g; \n a.a = texture(u_blendTexSampler, v_offset.xy).a; \n if (dot(a, vec4(1.0)) < 1e-5) {\n vec4 o = texture(u_texSampler, v_uv);\n o.rgb = ToLDR(o.rgb);\n return o;\n } else {\n vec2 offset;\n offset.x = a.a > a.b ? a.a : -a.b;\n offset.y = a.g > a.r ? -a.g : a.r;\n if (abs(offset.x) > abs(offset.y)) {\n offset.y = 0.0;\n } else {\n offset.x = 0.0;\n }\n vec4 C = texture(u_texSampler, v_uv);\n C.rgb = ToLDR(C.rgb);\n vec2 uv = v_uv + sign(offset) * cc_nativeSize.zw;\n vec4 Cop = texture(u_texSampler, uv);\n Cop.rgb = ToLDR(Cop.rgb);\n float s = abs(offset.x) > abs(offset.y) ? abs(offset.x) : abs(offset.y);\n C.rgb = pow(C.rgb, vec3(2.2));\n Cop.rgb = pow(Cop.rgb, vec3(2.2));\n vec4 mixed = mix(C, Cop, s);\n mixed.rgb = pow(mixed.rgb, vec3(1.0 / 2.2));\n return mixed;\n }\n#else \n vec4 o = texture(u_texSampler, v_uv);\n \n o.rgb = ToLDR(o.rgb);\n return o;\n#endif\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }\n` }, "glsl1": { "vert": `\nprecision highp float;\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define EPSILON 1e-6\n#define LOG2 1.442695\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#define FP_MAX = 65504.0;\n#define FP_SCALE (1.0/1024.0);\n#define FP_SCALE_INV 1024.0;\nuniform vec4 cc_time;\nuniform vec4 cc_screenSize;\nuniform vec4 cc_screenScale;\nuniform vec4 cc_nativeSize;\nuniform mat4 cc_matView;\nuniform mat4 cc_matViewInv;\nuniform mat4 cc_matProj;\nuniform mat4 cc_matProjInv;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matViewProjInv;\nuniform vec4 cc_cameraPos;\nuniform vec4 cc_exposure;\nuniform vec4 cc_mainLitDir;\nuniform vec4 cc_mainLitColor;\nuniform vec4 cc_ambientSky;\nuniform vec4 cc_ambientGround;\nattribute vec2 a_position;\nattribute vec2 a_texCoord;\nvarying vec2 v_uv;\nvarying vec4 v_offset;\nvec4 vert () {\n vec4 pos = vec4(a_position, 0, 1);\n v_uv = a_texCoord * cc_screenScale.xy;\n v_offset = v_uv.xyxy + cc_nativeSize.zwzw * vec4(1.0, 0.0, 0.0, -1.0);\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n`, - "frag": `\nprecision highp float;\nuniform vec4 cc_time;\nuniform vec4 cc_screenSize;\nuniform vec4 cc_screenScale;\nuniform vec4 cc_nativeSize;\nuniform mat4 cc_matView;\nuniform mat4 cc_matViewInv;\nuniform mat4 cc_matProj;\nuniform mat4 cc_matProjInv;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matViewProjInv;\nuniform vec4 cc_cameraPos;\nuniform vec4 cc_exposure;\nuniform vec4 cc_mainLitDir;\nuniform vec4 cc_mainLitColor;\nuniform vec4 cc_ambientSky;\nuniform vec4 cc_ambientGround;\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define EPSILON 1e-6\n#define LOG2 1.442695\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#define FP_MAX = 65504.0;\n#define FP_SCALE (1.0/1024.0);\n#define FP_SCALE_INV 1024.0;\nvec3 SRGBToLinear(vec3 gamma)\n{\n return pow(gamma, vec3(2.2));\n \n}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\n \n}\nvec3 ACESToneMap(vec3 color) {\n const float A = 2.51;\n const float B = 0.03;\n const float C = 2.43;\n const float D = 0.59;\n const float E = 0.14;\n return (color * (A * color + B)) / (color * (C * color + D) + E);\n}\nvarying vec2 v_uv;\nvarying vec4 v_offset;\nuniform sampler2D u_texSampler;\nuniform sampler2D u_blendTexSampler;\nvec3 ToLDR(vec3 color) {\n#if CC_USE_HDR\n color *= cc_exposure.x * 1024.0;;\n color = ACESToneMap(color);\n color = LinearToSRGB(color);\n#endif\n return color;\n}\n#define CC_USE_SMAA 1\nvec4 frag () {\n#if 1\n \n vec4 a;\n a.rb = texture2D(u_blendTexSampler, v_uv).rb; \n a.g = texture2D(u_blendTexSampler, v_offset.zw).g; \n a.a = texture2D(u_blendTexSampler, v_offset.xy).a; \n if (dot(a, vec4(1.0)) < 1e-5) {\n vec4 o = texture2D(u_texSampler, v_uv);\n o.rgb = ToLDR(o.rgb);\n return o;\n } else {\n vec2 offset;\n offset.x = a.a > a.b ? a.a : -a.b;\n offset.y = a.g > a.r ? -a.g : a.r;\n if (abs(offset.x) > abs(offset.y)) {\n offset.y = 0.0;\n } else {\n offset.x = 0.0;\n }\n vec4 C = texture2D(u_texSampler, v_uv);\n C.rgb = ToLDR(C.rgb);\n vec2 uv = v_uv + sign(offset) * cc_nativeSize.zw;\n vec4 Cop = texture2D(u_texSampler, uv);\n Cop.rgb = ToLDR(Cop.rgb);\n float s = abs(offset.x) > abs(offset.y) ? abs(offset.x) : abs(offset.y);\n C.rgb = pow(C.rgb, vec3(2.2));\n Cop.rgb = pow(Cop.rgb, vec3(2.2));\n vec4 mixed = mix(C, Cop, s);\n mixed.rgb = pow(mixed.rgb, vec3(1.0 / 2.2));\n return mixed;\n }\n#else \n vec4 o = texture2D(u_texSampler, v_uv);\n \n o.rgb = ToLDR(o.rgb);\n return o;\n#endif\n}\nvoid main() { gl_FragColor = frag(); }\n` + "frag": `\nprecision highp float;\nuniform vec4 cc_time;\nuniform vec4 cc_screenSize;\nuniform vec4 cc_screenScale;\nuniform vec4 cc_nativeSize;\nuniform mat4 cc_matView;\nuniform mat4 cc_matViewInv;\nuniform mat4 cc_matProj;\nuniform mat4 cc_matProjInv;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matViewProjInv;\nuniform vec4 cc_cameraPos;\nuniform vec4 cc_exposure;\nuniform vec4 cc_mainLitDir;\nuniform vec4 cc_mainLitColor;\nuniform vec4 cc_ambientSky;\nuniform vec4 cc_ambientGround;\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define EPSILON 1e-6\n#define LOG2 1.442695\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#define FP_MAX = 65504.0;\n#define FP_SCALE (1.0/1024.0);\n#define FP_SCALE_INV 1024.0;\nvec3 SRGBToLinear(vec3 gamma)\n{\n return pow(gamma, vec3(2.2));\n \n}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\n \n}\nvec3 ACESToneMap(vec3 color) {\n const float A = 2.51;\n const float B = 0.03;\n const float C = 2.43;\n const float D = 0.59;\n const float E = 0.14;\n return (color * (A * color + B)) / (color * (C * color + D) + E);\n}\nvarying vec2 v_uv;\nvarying vec4 v_offset;\nuniform sampler2D u_texSampler;\nuniform sampler2D u_blendTexSampler;\nvec3 ToLDR(vec3 color) {\n#if CC_USE_HDR\n color *= cc_exposure.x * 1024.0;;\n color = ACESToneMap(color);\n color = LinearToSRGB(color);\n#endif\n return color;\n}\nvec4 frag () {\n#if CC_USE_SMAA\n \n vec4 a;\n a.rb = texture2D(u_blendTexSampler, v_uv).rb; \n a.g = texture2D(u_blendTexSampler, v_offset.zw).g; \n a.a = texture2D(u_blendTexSampler, v_offset.xy).a; \n if (dot(a, vec4(1.0)) < 1e-5) {\n vec4 o = texture2D(u_texSampler, v_uv);\n o.rgb = ToLDR(o.rgb);\n return o;\n } else {\n vec2 offset;\n offset.x = a.a > a.b ? a.a : -a.b;\n offset.y = a.g > a.r ? -a.g : a.r;\n if (abs(offset.x) > abs(offset.y)) {\n offset.y = 0.0;\n } else {\n offset.x = 0.0;\n }\n vec4 C = texture2D(u_texSampler, v_uv);\n C.rgb = ToLDR(C.rgb);\n vec2 uv = v_uv + sign(offset) * cc_nativeSize.zw;\n vec4 Cop = texture2D(u_texSampler, uv);\n Cop.rgb = ToLDR(Cop.rgb);\n float s = abs(offset.x) > abs(offset.y) ? abs(offset.x) : abs(offset.y);\n C.rgb = pow(C.rgb, vec3(2.2));\n Cop.rgb = pow(Cop.rgb, vec3(2.2));\n vec4 mixed = mix(C, Cop, s);\n mixed.rgb = pow(mixed.rgb, vec3(1.0 / 2.2));\n return mixed;\n }\n#else \n vec4 o = texture2D(u_texSampler, v_uv);\n \n o.rgb = ToLDR(o.rgb);\n return o;\n#endif\n}\nvoid main() { gl_FragColor = frag(); }\n` }, "builtins": {"globals":{"blocks":["CCGlobal"], "samplers":[]}, "locals":{"blocks":[], "samplers":[]}}, "defines": [ - {"name":"CC_USE_HDR", "type":"boolean", "defines":[]} + {"name":"CC_USE_HDR", "type":"boolean", "defines":[]}, + {"name":"CC_USE_SMAA", "type":"boolean", "defines":[]} ], "blocks": [], "samplers": [ diff --git a/cocos/3d/builtin/init.ts b/cocos/3d/builtin/init.ts index 59bc2d6131..1775a86aca 100644 --- a/cocos/3d/builtin/init.ts +++ b/cocos/3d/builtin/init.ts @@ -125,22 +125,6 @@ class BuiltinResMgr { effect.onLoaded(); }); - // tonemap material - const smaaMtl = new cc.Material(); - smaaMtl._uuid = 'smaa-material'; - smaaMtl.initialize({ - effectName: 'builtin-smaa', - }); - resources[smaaMtl._uuid] = smaaMtl; - - // tonemap material - const tonemapMtl = new cc.Material(); - tonemapMtl._uuid = 'tonemap-material'; - tonemapMtl.initialize({ - effectName: 'builtin-tonemap', - }); - resources[tonemapMtl._uuid] = tonemapMtl; - // standard material const standardMtl = new cc.Material(); standardMtl._uuid = 'standard-material'; diff --git a/cocos/pipeline/forward/forward-flow.ts b/cocos/pipeline/forward/forward-flow.ts index 28a3695692..09c30b20c4 100644 --- a/cocos/pipeline/forward/forward-flow.ts +++ b/cocos/pipeline/forward/forward-flow.ts @@ -30,7 +30,10 @@ export class ForwardFlow extends RenderFlow { return true; } - public destroy (): void { + public destroy () { this.destroyStages(); } + + public rebuild () { + } } diff --git a/cocos/pipeline/forward/forward-pipeline.ts b/cocos/pipeline/forward/forward-pipeline.ts index be4be19bda..df683983f6 100644 --- a/cocos/pipeline/forward/forward-pipeline.ts +++ b/cocos/pipeline/forward/forward-pipeline.ts @@ -116,6 +116,12 @@ export class ForwardPipeline extends RenderPipeline { this._destroy(); } + public rebuild () { + for (const flow of this._flows) { + flow.rebuild(); + } + } + protected updateUBOs (view: RenderView) { super.updateUBOs(view); diff --git a/cocos/pipeline/forward/forward-stage.ts b/cocos/pipeline/forward/forward-stage.ts index 657153937c..feb8308802 100644 --- a/cocos/pipeline/forward/forward-stage.ts +++ b/cocos/pipeline/forward/forward-stage.ts @@ -40,6 +40,9 @@ export class ForwardStage extends RenderStage { public resize (width: number, height: number) { } + public rebuild () { + } + public render (view: RenderView) { const cmdBuff = this._cmdBuff!; diff --git a/cocos/pipeline/ppfx/smaa-blend-stage.ts b/cocos/pipeline/ppfx/smaa-blend-stage.ts index a16e004a2d..13f2a953fb 100644 --- a/cocos/pipeline/ppfx/smaa-blend-stage.ts +++ b/cocos/pipeline/ppfx/smaa-blend-stage.ts @@ -88,6 +88,9 @@ export class SMAABlendStage extends RenderStage { public resize (width: number, height: number) { } + public rebuild () { + } + public render (view: RenderView) { if (this._isLoaded) { const camera = view.camera!; diff --git a/cocos/pipeline/ppfx/smaa-edge-stage.ts b/cocos/pipeline/ppfx/smaa-edge-stage.ts index 9bf63cfb5b..a13c8001d2 100644 --- a/cocos/pipeline/ppfx/smaa-edge-stage.ts +++ b/cocos/pipeline/ppfx/smaa-edge-stage.ts @@ -57,6 +57,9 @@ export class SMAAEdgeStage extends RenderStage { public resize (width: number, height: number) { } + public rebuild () { + } + public render (view: RenderView) { const camera = view.camera!; diff --git a/cocos/pipeline/ppfx/smaa-flow.ts b/cocos/pipeline/ppfx/smaa-flow.ts index d091074325..6cc69bd22f 100644 --- a/cocos/pipeline/ppfx/smaa-flow.ts +++ b/cocos/pipeline/ppfx/smaa-flow.ts @@ -17,12 +17,13 @@ export class SMAAEdgeFlow extends RenderFlow { this._priority = info.priority; - const material = new cc.Material(); - material.initialize({ + const smaaMtl = new cc.Material(); + smaaMtl._uuid = 'smaa-material'; + smaaMtl.initialize({ effectName: 'builtin-smaa', }); - this._material = material; + this._material = smaaMtl; this.createStage(SMAAEdgeStage, { name: 'SMAAEdgeStage', @@ -39,7 +40,16 @@ export class SMAAEdgeFlow extends RenderFlow { return true; } - public destroy (): void { + public destroy () { + + if (this._material) { + this._material.destroy(); + this._material = null; + } + this.destroyStages(); } + + public rebuild () { + } } diff --git a/cocos/pipeline/ppfx/tonemap-flow.ts b/cocos/pipeline/ppfx/tonemap-flow.ts index 745ea8960f..da0e038955 100644 --- a/cocos/pipeline/ppfx/tonemap-flow.ts +++ b/cocos/pipeline/ppfx/tonemap-flow.ts @@ -19,6 +19,7 @@ export class ToneMapFlow extends RenderFlow { const material = new cc.Material(); material.initialize({ effectName: 'builtin-tonemap', + defines: { CC_USE_SMAA: this._pipeline.useSMAA }, }); this._material = material; @@ -37,4 +38,18 @@ export class ToneMapFlow extends RenderFlow { public destroy (): void { this.destroyStages(); } + + public rebuild () { + if (this._material) { + this._material.destroy(); + this._material.initialize({ + effectName: 'builtin-tonemap', + defines: { CC_USE_SMAA: this._pipeline.useSMAA }, + }); + } + + for (const stage of this._stages) { + stage.rebuild(); + } + } } diff --git a/cocos/pipeline/ppfx/tonemap-stage.ts b/cocos/pipeline/ppfx/tonemap-stage.ts index f6dc92e43c..18816af2e9 100644 --- a/cocos/pipeline/ppfx/tonemap-stage.ts +++ b/cocos/pipeline/ppfx/tonemap-stage.ts @@ -1,6 +1,5 @@ import { GFXBindingLayout } from '../../gfx/binding-layout'; -import { GFXCommandBuffer } from '../../gfx/command-buffer'; -import { GFXClearFlag, GFXCommandBufferType, IGFXColor } from '../../gfx/define'; +import { GFXClearFlag, GFXCommandBufferType } from '../../gfx/define'; import { UBOGlobal } from '../define'; import { RenderFlow } from '../render-flow'; import { IRenderStageInfo, RenderStage } from '../render-stage'; @@ -33,20 +32,7 @@ export class ToneMapStage extends RenderStage { type: GFXCommandBufferType.PRIMARY, }); - this._pass = this._flow.material.passes[0]; - this._hTexSampler = this._pass.getBinding('u_texSampler'); - this._hBlendTexSampler = this._pass.getBinding('u_blendTexSampler'); - - const globalUBO = this._pipeline.globalBindings.get(UBOGlobal.BLOCK.name); - - this._pso = this._pass.createPipelineState(); - this._bindingLayout = this._pso!.pipelineLayout.layouts[0]; - - this._pass.bindBuffer(UBOGlobal.BLOCK.binding, globalUBO!.buffer!); - this._pass.bindTextureView(this._hTexSampler, this._pipeline.curShadingTexView); - this._pass.bindTextureView(this._hBlendTexSampler, this._pipeline.smaaBlendTexView); - this._pass.update(); - this._bindingLayout.update(); + this.rebuild(); return true; } @@ -61,6 +47,27 @@ export class ToneMapStage extends RenderStage { public resize (width: number, height: number) { } + public rebuild () { + this._pass = this._flow.material.passes[0]; + this._hTexSampler = this._pass.getBinding('u_texSampler'); + + const globalUBO = this._pipeline.globalBindings.get(UBOGlobal.BLOCK.name); + + this._pso = this._pass.createPipelineState(); + this._bindingLayout = this._pso!.pipelineLayout.layouts[0]; + + this._pass.bindBuffer(UBOGlobal.BLOCK.binding, globalUBO!.buffer!); + this._pass.bindTextureView(this._hTexSampler, this._pipeline.curShadingTexView); + + if (this._pipeline.useSMAA) { + this._hBlendTexSampler = this._pass.getBinding('u_blendTexSampler'); + this._pass.bindTextureView(this._hBlendTexSampler, this._pipeline.smaaBlendTexView); + } + + this._pass.update(); + this._bindingLayout.update(); + } + public render (view: RenderView) { const camera = view.camera!; diff --git a/cocos/pipeline/render-flow.ts b/cocos/pipeline/render-flow.ts index 1a4fbfae7d..0e1a270947 100644 --- a/cocos/pipeline/render-flow.ts +++ b/cocos/pipeline/render-flow.ts @@ -49,6 +49,7 @@ export abstract class RenderFlow { public abstract initialize (info: IRenderFlowInfo): boolean; public abstract destroy (); + public abstract rebuild (); public resize (width: number, height: number) { for (const stage of this._stages) { diff --git a/cocos/pipeline/render-pipeline.ts b/cocos/pipeline/render-pipeline.ts index 24325f8b7a..fbd88c7735 100644 --- a/cocos/pipeline/render-pipeline.ts +++ b/cocos/pipeline/render-pipeline.ts @@ -36,6 +36,7 @@ const _outMat = new Mat4(); export interface IRenderPipelineInfo { enableHDR?: boolean; + enableSMAA?: boolean; } export abstract class RenderPipeline { @@ -84,6 +85,10 @@ export abstract class RenderPipeline { return this._shadingFBOs[this._prevIdx]; } + public get useSMAA (): boolean { + return this._useSMAA; + } + public get smaaEdgeTexView (): GFXTextureView { return this._smaaEdgeTexView!; } @@ -169,6 +174,7 @@ export abstract class RenderPipeline { public abstract initialize (info: IRenderPipelineInfo): boolean; public abstract destroy (); + public abstract rebuild (); public resize (width: number, height: number) { for (const flow of this._flows) { @@ -254,6 +260,8 @@ export abstract class RenderPipeline { protected _initialize (info: IRenderPipelineInfo): boolean { + this._useSMAA = (info.enableSMAA !== undefined ? info.enableSMAA : true); + if (this._device.hasFeature(GFXFeature.FORMAT_R11G11B10F) || this._device.hasFeature(GFXFeature.TEXTURE_HALF_FLOAT) || this._device.hasFeature(GFXFeature.TEXTURE_FLOAT)) { diff --git a/cocos/pipeline/render-stage.ts b/cocos/pipeline/render-stage.ts index e315e0c873..d8c3ebe2e0 100644 --- a/cocos/pipeline/render-stage.ts +++ b/cocos/pipeline/render-stage.ts @@ -64,6 +64,7 @@ export abstract class RenderStage { public abstract destroy (); public abstract render (view: RenderView); public abstract resize (width: number, height: number); + public abstract rebuild (); public setClearColor (color: IGFXColor) { if (this._clearColors.length > 0) { diff --git a/cocos/pipeline/ui/ui-flow.ts b/cocos/pipeline/ui/ui-flow.ts index 28072b095a..3a23ba3327 100644 --- a/cocos/pipeline/ui/ui-flow.ts +++ b/cocos/pipeline/ui/ui-flow.ts @@ -30,7 +30,11 @@ export class UIFlow extends RenderFlow { return true; } - public destroy (): void { + public destroy () { this.destroyStages(); } + + public rebuild () { + } + } diff --git a/cocos/pipeline/ui/ui-pipeline.ts b/cocos/pipeline/ui/ui-pipeline.ts index 7f95a1d3f5..8f357eabe8 100644 --- a/cocos/pipeline/ui/ui-pipeline.ts +++ b/cocos/pipeline/ui/ui-pipeline.ts @@ -33,6 +33,9 @@ export class UIPipeline extends RenderPipeline { this._destroy(); } + public rebuild () { + } + protected updateUBOs (view: RenderView) { const camera = view.camera; mat4.array(_mat4Array, camera.matViewProj); diff --git a/cocos/pipeline/ui/ui-stage.ts b/cocos/pipeline/ui/ui-stage.ts index 442505809a..eda3d8257f 100644 --- a/cocos/pipeline/ui/ui-stage.ts +++ b/cocos/pipeline/ui/ui-stage.ts @@ -19,7 +19,10 @@ export class UIStage extends RenderStage { } this._priority = info.priority; - this._framebuffer = info.framebuffer; + + if (info.framebuffer !== undefined) { + this._framebuffer = info.framebuffer; + } this._cmdBuff = this._device.createCommandBuffer({ allocator: this._device.commandAllocator, @@ -40,6 +43,9 @@ export class UIStage extends RenderStage { public resize (width: number, height: number) { } + public rebuild () { + } + public render (view: RenderView) { const framebuffer = view.window!.framebuffer; From 0fab11ed5afae73f9f70152eabd1a7b162de05a6 Mon Sep 17 00:00:00 2001 From: zxg0622 <247274249@qq.com> Date: Thu, 21 Mar 2019 11:24:08 +0800 Subject: [PATCH 03/11] modify ui renderpipeline (#4070) --- cocos/3d/framework/camera-component.ts | 4 +- cocos/3d/framework/editor-camera-component.ts | 145 ++++++++++++++++++ cocos/3d/framework/index.ts | 2 + cocos/3d/ui/components/canvas-component.ts | 2 +- cocos/components/component.js | 8 +- cocos/core/root.ts | 59 ++----- cocos/pipeline/forward/forward-pipeline.ts | 7 + cocos/pipeline/render-flow.ts | 4 + cocos/pipeline/render-pipeline.ts | 4 +- cocos/pipeline/render-view.ts | 17 +- cocos/renderer/scene/camera.ts | 5 +- cocos/renderer/ui/ui-material.ts | 4 - cocos/renderer/ui/ui.ts | 22 ++- 13 files changed, 209 insertions(+), 74 deletions(-) create mode 100644 cocos/3d/framework/editor-camera-component.ts diff --git a/cocos/3d/framework/camera-component.ts b/cocos/3d/framework/camera-component.ts index 5bedee0787..fdad6ac0f2 100644 --- a/cocos/3d/framework/camera-component.ts +++ b/cocos/3d/framework/camera-component.ts @@ -74,7 +74,7 @@ const CameraClearFlag = Enum({ */ @ccclass('cc.CameraComponent') @menu('Components/CameraComponent') -@executeInEditMode +// @executeInEditMode export class CameraComponent extends Component { public static ProjectionType = ProjectionType; @@ -370,7 +370,7 @@ export class CameraComponent extends Component { }); this._camera.viewport = this._rect; - this._camera.fov = this._fov; + this._camera.fov = toRadian(this._fov); this._camera.nearClip = this._near; this._camera.farClip = this._far; this._camera.clearColor = color4.create(this._color.r / 255, this._color.g / 255, this._color.b / 255, this._color.a / 255) diff --git a/cocos/3d/framework/editor-camera-component.ts b/cocos/3d/framework/editor-camera-component.ts new file mode 100644 index 0000000000..16280c4e3a --- /dev/null +++ b/cocos/3d/framework/editor-camera-component.ts @@ -0,0 +1,145 @@ +import { CameraComponent } from "./camera-component"; +import { ccclass, executeInEditMode } from "../../core/data/class-decorator"; +import { RenderView } from "../../pipeline/render-view"; +import { Camera } from "../../renderer"; +import { color4, toRadian } from "../../core/vmath"; + +@ccclass('cc.EditorCameraComponent') +@executeInEditMode +export class EditorCameraComponent extends CameraComponent { + + private _uiEditorCamera: Camera | null = null; + + set projection (val) { + super.projection = val; + if (this._uiEditorCamera) { + this._uiEditorCamera.projectionType = val; + } + } + + set fov (val) { + super.fov = val; + if (this._uiEditorCamera) { + this._uiEditorCamera.fov = toRadian(val); + } + } + + set orthoHeight (val) { + super.orthoHeight = val; + if (this._uiEditorCamera) { + this._uiEditorCamera.orthoHeight = val; + } + } + + set near (val) { + super.near = val; + if (this._uiEditorCamera) { + this._uiEditorCamera.nearClip = val; + } + } + + set far (val) { + super.far = val; + if (this._uiEditorCamera) { + this._uiEditorCamera.farClip = val; + } + } + + set color (val) { + super.color = val; + if (this._uiEditorCamera) { + this._uiEditorCamera.clearColor = + color4.create(val.r / 255, val.g / 255, val.b / 255, val.a / 255); + } + } + + set depth (val) { + super.depth = val; + if (this._uiEditorCamera) { + this._uiEditorCamera.clearDepth = val; + } + } + + set stencil (val) { + super.stencil = val; + if (this._uiEditorCamera) { + this._uiEditorCamera.clearStencil = val; + } + } + + set clearFlags (val) { + super.clearFlags = val; + if (this._uiEditorCamera) { + this._uiEditorCamera.clearFlag = val; + } + } + + set rect (val) { + super.rect = val; + if (this._uiEditorCamera) { + this._uiEditorCamera.viewport = val; + } + } + + set screenScale (val) { + super.screenScale = val; + if (this._uiEditorCamera) { + this._uiEditorCamera.screenScale = val; + } + } + + set targetDisplay (val) { + super.targetDisplay = val; + if (this._uiEditorCamera) { + this._uiEditorCamera.changeTargetDisplay(val); + } + } + + public onLoad () { + super.onLoad(); + } + + public onEnable () { + super.onEnable(); + } + + public onDisable () { + super.onDisable(); + } + + public onDestroy () { + super.onDestroy(); + if (this._uiEditorCamera) { + cc.director.root.ui.renderScene.destroyCamera(this._uiEditorCamera); + this._uiEditorCamera = null; + } + } + + protected _createCamera () { + const priorCamera = this._camera; + super._createCamera(); + if (this._camera !== priorCamera && this._camera) { + if (this._uiEditorCamera) { + cc.director.root.ui.renderScene.destroyCamera(this._uiEditorCamera); + this._uiEditorCamera = null; + } + this._uiEditorCamera = cc.director.root.ui.renderScene.createCamera({ + name: 'Editor UICamera', + node: this._camera.node, + projection: this._projection, + targetDisplay: this._targetDisplay, + priority: this._priority, + isUI: true, + stages: ['UIFlow'], + }); + this._uiEditorCamera!.viewport = this._camera.viewport; + this._uiEditorCamera!.fov = this._camera.fov; + this._uiEditorCamera!.nearClip = this._camera.nearClip; + this._uiEditorCamera!.farClip = this._camera.farClip; + this._uiEditorCamera!.clearColor = this._camera.clearColor; + this._uiEditorCamera!.clearDepth = this._camera.clearDepth; + this._uiEditorCamera!.clearStencil = this._camera.clearStencil; + this._uiEditorCamera!.clearFlag = this._camera.clearFlag; + } + } +} diff --git a/cocos/3d/framework/index.ts b/cocos/3d/framework/index.ts index 034a7d4d5b..f7ab5361cb 100644 --- a/cocos/3d/framework/index.ts +++ b/cocos/3d/framework/index.ts @@ -37,6 +37,7 @@ import { RenderableComponent } from './renderable-component'; import { SkinningModelComponent } from './skinning-model-component'; import { SphereLightComponent } from './sphere-light-component'; import { SpotLightComponent } from './spot-light-component'; +import { EditorCameraComponent } from './editor-camera-component'; export * from './physics'; export { @@ -56,6 +57,7 @@ export { cc.AnimationComponent = AnimationComponent; cc.AudioSourceComponent = AudioSourceComponent; cc.CameraComponent = CameraComponent; +cc.EditorComponent = EditorCameraComponent; cc.RenderableComponent = RenderableComponent; cc.ModelComponent = ModelComponent; cc.SkinningModelComponent = SkinningModelComponent; diff --git a/cocos/3d/ui/components/canvas-component.ts b/cocos/3d/ui/components/canvas-component.ts index 310a6d38af..689ce1bdba 100644 --- a/cocos/3d/ui/components/canvas-component.ts +++ b/cocos/3d/ui/components/canvas-component.ts @@ -178,7 +178,7 @@ export class CanvasComponent extends Component { targetDisplay: 0, priority: this._priority, isUI: true, - pipeline: 'ui', + stages: ['UIFlow'], }); this._camera!.fov = 45; diff --git a/cocos/components/component.js b/cocos/components/component.js index 50168cb464..dc00992681 100644 --- a/cocos/components/component.js +++ b/cocos/components/component.js @@ -196,8 +196,14 @@ class Component extends CCObject { static system = null; + _sceneGetter = null; + _getRenderScene() { - return this.node._scene._renderScene; + if (this._sceneGetter) { + return this._sceneGetter(); + } else { + return this.node._scene._renderScene; + } } constructor () { diff --git a/cocos/core/root.ts b/cocos/core/root.ts index 6fc333228a..200023c092 100644 --- a/cocos/core/root.ts +++ b/cocos/core/root.ts @@ -4,7 +4,6 @@ import { GFXWindow, IGFXWindowInfo } from '../gfx/window'; import { ForwardPipeline } from '../pipeline/forward/forward-pipeline'; import { RenderPipeline } from '../pipeline/render-pipeline'; import { IRenderViewInfo, RenderView } from '../pipeline/render-view'; -import { UIPipeline } from '../pipeline/ui/ui-pipeline'; import { IRenderSceneInfo, RenderScene } from '../renderer/scene/render-scene'; import { UI } from '../renderer/ui/ui'; @@ -41,10 +40,6 @@ export class Root { return this._pipeline!; } - public get uiPipeline (): UIPipeline { - return this._uiPipeline!; - } - public get ui (): UI { return this._ui as UI; } @@ -69,11 +64,9 @@ export class Root { private _mainWindow: GFXWindow | null = null; private _curWindow: GFXWindow | null = null; private _pipeline: RenderPipeline | null = null; - private _uiPipeline: UIPipeline | null = null; private _ui: UI | null = null; private _scenes: RenderScene[] = []; private _views: RenderView[] = []; - private _uiViews: RenderView[] = []; private _frameTime: number = 0; constructor (device: GFXDevice) { @@ -100,12 +93,6 @@ export class Root { return false; } - this._uiPipeline = new UIPipeline(this); - if (!this._uiPipeline.initialize(info)) { - this.destroy(); - return false; - } - this._ui = new UI(this); if (!this._ui.initialize()) { this.destroy(); @@ -172,12 +159,6 @@ export class Root { } } - for (const view of this._uiViews) { - if (view.isEnable && view.window === this._mainWindow) { - this._uiPipeline!.render(view); - } - } - this._device.present(); } @@ -239,37 +220,20 @@ export class Root { view.initialize(info); // view.camera.resize(cc.game.canvas.width, cc.game.canvas.height); - if (!view.isUI) { - this._views.push(view); - this._views.sort((a: RenderView, b: RenderView) => { - return a.priority - b.priority; - }); - } else { - this._uiViews.push(view); - this._uiViews.sort((a: RenderView, b: RenderView) => { - return a.priority - b.priority; - }); - } + this._views.push(view); + this._views.sort((a: RenderView, b: RenderView) => { + return a.priority - b.priority; + }); return view; } public destroyView (view: RenderView) { - if (!view.isUI) { - for (let i = 0; i < this._views.length; ++i) { - if (this._views[i] === view) { - this._views.splice(i, 1); - view.destroy(); - return; - } - } - } else { - for (let i = 0; i < this._uiViews.length; ++i) { - if (this._uiViews[i] === view) { - this._uiViews.splice(i, 1); - view.destroy(); - return; - } + for (let i = 0; i < this._views.length; ++i) { + if (this._views[i] === view) { + this._views.splice(i, 1); + view.destroy(); + return; } } } @@ -279,10 +243,5 @@ export class Root { view.destroy(); } this._views = []; - - for (const view of this._uiViews) { - view.destroy(); - } - this._uiViews = []; } } diff --git a/cocos/pipeline/forward/forward-pipeline.ts b/cocos/pipeline/forward/forward-pipeline.ts index be4be19bda..dfa735a985 100644 --- a/cocos/pipeline/forward/forward-pipeline.ts +++ b/cocos/pipeline/forward/forward-pipeline.ts @@ -17,9 +17,11 @@ import { ToneMapFlow } from '../ppfx/tonemap-flow'; import { IRenderPipelineInfo, RenderPipeline } from '../render-pipeline'; import { RenderView } from '../render-view'; import { ForwardFlow } from './forward-flow'; +import { UIFlow } from '../ui/ui-flow'; export enum ForwardFlowPriority { FORWARD = 0, + UI = 10, } const _vec4Array = new Float32Array(4); @@ -103,6 +105,11 @@ export class ForwardPipeline extends RenderPipeline { priority: 0, }); + this.createFlow(UIFlow, { + name: 'UIFlow', + priority: ForwardFlowPriority.UI, + }); + return true; } diff --git a/cocos/pipeline/render-flow.ts b/cocos/pipeline/render-flow.ts index 1a4fbfae7d..de2c8a47c5 100644 --- a/cocos/pipeline/render-flow.ts +++ b/cocos/pipeline/render-flow.ts @@ -35,6 +35,10 @@ export abstract class RenderFlow { return this._material!; } + public get name (): string { + return this._name; + } + protected _device: GFXDevice; protected _pipeline: RenderPipeline; protected _name: string = ''; diff --git a/cocos/pipeline/render-pipeline.ts b/cocos/pipeline/render-pipeline.ts index 24325f8b7a..470ce5f5a0 100644 --- a/cocos/pipeline/render-pipeline.ts +++ b/cocos/pipeline/render-pipeline.ts @@ -185,7 +185,9 @@ export abstract class RenderPipeline { this.updateUBOs(view); for (const flow of this._flows) { - flow.render(view); + if (view.stages.indexOf(flow.name) !== -1) { + flow.render(view); + } } } diff --git a/cocos/pipeline/render-view.ts b/cocos/pipeline/render-view.ts index 7ff7baae7b..e52cb62023 100644 --- a/cocos/pipeline/render-view.ts +++ b/cocos/pipeline/render-view.ts @@ -16,6 +16,7 @@ export interface IRenderViewInfo { name: string; priority: number; isUI: boolean; + stages?: string[]; } export interface IRenderTargetInfo { @@ -47,6 +48,9 @@ export class RenderView { public set priority (val: number) { this._priority = val; + if (this.isUI) { + this._priority |= 1 << 30; + } } public set visibility (vis) { @@ -68,6 +72,10 @@ export class RenderView { return this._isUI; } + public get stages (): string[] { + return this._stages; + } + public get isOffscreen (): boolean { return this._isOffscreen; } @@ -88,6 +96,7 @@ export class RenderView { private _camera: Camera; private _isEnable: boolean = true; private _isUI: boolean = false; + private _stages: string[] = []; private _isOffscreen: boolean = false; // For offscreen @@ -107,7 +116,13 @@ export class RenderView { this._name = info.name; this._isUI = info.isUI; - this._priority = info.priority; + this.priority = info.priority; + if (info.stages) { + this._stages.push(...info.stages); + } else { + this._stages.push('ForwardFlow'); + this._stages.push('ToneMapFlow'); + } return true; } diff --git a/cocos/renderer/scene/camera.ts b/cocos/renderer/scene/camera.ts index ef8b1d8314..829b5a1c9f 100644 --- a/cocos/renderer/scene/camera.ts +++ b/cocos/renderer/scene/camera.ts @@ -73,6 +73,7 @@ export interface ICameraInfo { priority: number; pipeline?: string; isUI?: boolean; + stages?: string[]; } const v_a = cc.v3(); @@ -96,7 +97,7 @@ export class Camera { private _clearStencil: number = 0; private _clearDepth: number = 1.0; private _clearFlag: GFXClearFlag = GFXClearFlag.NONE; - private _clearColor: IGFXColor = {r: 0, g: 0, b: 0, a: 0}; + private _clearColor: IGFXColor = { r: 0, g: 0, b: 0, a: 0 }; private _viewport: Rect = new Rect(0, 0, 1, 1); private _matView: Mat4 = new Mat4(); private _matProj: Mat4 = new Mat4(); @@ -138,6 +139,7 @@ export class Camera { name: this._name, priority: this._priority, isUI, + stages: info.stages, }); this.changeTargetDisplay(info.targetDisplay); @@ -358,6 +360,7 @@ export class Camera { set visibility (vis) { this._visibility = vis; + this._view.visibility = vis; } get visibility () { return this._visibility; diff --git a/cocos/renderer/ui/ui-material.ts b/cocos/renderer/ui/ui-material.ts index be58a65f4f..afb2b3496c 100644 --- a/cocos/renderer/ui/ui-material.ts +++ b/cocos/renderer/ui/ui-material.ts @@ -38,10 +38,6 @@ export class UIMaterial { this._psos = new Pool(() => { const pso = this._pass!.createPipelineState()!; - if (!CC_EDITOR) { - pso.pipelineLayout.layouts[0].bindBuffer(UBOGlobal.BLOCK.binding, - cc.director.root.uiPipeline.globalBindings.get(UBOGlobal.BLOCK.name).buffer); - } return pso; }, 1); diff --git a/cocos/renderer/ui/ui.ts b/cocos/renderer/ui/ui.ts index 9c84806271..133ad35a5c 100644 --- a/cocos/renderer/ui/ui.ts +++ b/cocos/renderer/ui/ui.ts @@ -24,6 +24,7 @@ import { Camera } from '../scene/camera'; import { RenderScene } from '../scene/render-scene'; import { UIBatchModel } from './ui-batch-model'; import { UIMaterial } from './ui-material'; +import { CameraComponent } from '../../3d'; export class UIDrawBatch { public camera: Camera | null = null; @@ -99,19 +100,10 @@ export class UI { constructor (private _root: Root) { this.device = _root.device; - if (CC_EDITOR) { - cc.director.on(cc.Director.EVENT_BEFORE_SCENE_LAUNCH, (scene) => { - this._scene = scene.renderScene; - // the models will be destroyed in renderScene - this._modelInUse.clear(); - this._uiModelPool = new Pool(() => this._scene.createModel(UIBatchModel, null), 2); - }); - } else { - this._scene = this._root.createScene({ - name: 'GUIScene', - }); - this._uiModelPool = new Pool(() => this._scene.createModel(UIBatchModel, null), 2); - } + this._scene = this._root.createScene({ + name: 'GUIScene', + }); + this._uiModelPool = new Pool(() => this._scene.createModel(UIBatchModel, null), 2); this._modelInUse = new CachedArray(10); this._batches = new CachedArray(64); @@ -154,6 +146,10 @@ export class UI { } } + public getRenderSceneGetter () { + return Object.getOwnPropertyDescriptor(Object.getPrototypeOf(this), 'renderScene')!.get!.bind(this); + } + public _getUIMaterial (mat: Material): UIMaterial { if (this._uiMaterials.has(mat.hash)) { return this._uiMaterials.get(mat.hash)!; From c932cd3289184c1daade72484525e930548102d8 Mon Sep 17 00:00:00 2001 From: jerrywwl Date: Thu, 21 Mar 2019 11:30:34 +0800 Subject: [PATCH 04/11] add a interface to set offscreen camera --- cocos/gfx/webgl2/webgl2-device.ts | 6 +++--- cocos/pipeline/render-view.ts | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/cocos/gfx/webgl2/webgl2-device.ts b/cocos/gfx/webgl2/webgl2-device.ts index f96bd80d37..9b1a68b871 100644 --- a/cocos/gfx/webgl2/webgl2-device.ts +++ b/cocos/gfx/webgl2/webgl2-device.ts @@ -417,7 +417,7 @@ export class WebGL2GFXDevice extends GFXDevice { const curFBO = this.stateCache.glFramebuffer; if (this.stateCache.glFramebuffer !== gpuFramebuffer.glFramebuffer) { - gl.bindFramebuffer(WebGLRenderingContext.FRAMEBUFFER, gpuFramebuffer.glFramebuffer); + gl.bindFramebuffer(WebGL2RenderingContext.FRAMEBUFFER, gpuFramebuffer.glFramebuffer); this.stateCache.glFramebuffer = gpuFramebuffer.glFramebuffer; } @@ -433,11 +433,11 @@ export class WebGL2GFXDevice extends GFXDevice { const data = view.subarray(buffOffset, buffOffset + memSize); gl.readPixels(region.texOffset.x, region.texOffset.y, w, h, - WebGLRenderingContext.RGBA, WebGLRenderingContext.UNSIGNED_BYTE, data); + WebGL2RenderingContext.RGBA, WebGL2RenderingContext.UNSIGNED_BYTE, data); } if (this.stateCache.glFramebuffer !== curFBO) { - gl.bindFramebuffer(WebGLRenderingContext.FRAMEBUFFER, curFBO); + gl.bindFramebuffer(WebGL2RenderingContext.FRAMEBUFFER, curFBO); this.stateCache.glFramebuffer = curFBO; } } diff --git a/cocos/pipeline/render-view.ts b/cocos/pipeline/render-view.ts index 7ff7baae7b..7db6da637e 100644 --- a/cocos/pipeline/render-view.ts +++ b/cocos/pipeline/render-view.ts @@ -68,6 +68,10 @@ export class RenderView { return this._isUI; } + public set isOffscreen (isOffscreen: boolean) { + this._isOffscreen = isOffscreen; + } + public get isOffscreen (): boolean { return this._isOffscreen; } From b7a02bb21b16015bd4803edc417c648821425a0c Mon Sep 17 00:00:00 2001 From: Yun Hsiao Wu Date: Thu, 21 Mar 2019 15:08:34 +0800 Subject: [PATCH 05/11] execute camera component (#4075) --- cocos/3d/framework/camera-component.ts | 2 +- cocos/3d/framework/editor-camera-component.ts | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/cocos/3d/framework/camera-component.ts b/cocos/3d/framework/camera-component.ts index fdad6ac0f2..3517b22185 100644 --- a/cocos/3d/framework/camera-component.ts +++ b/cocos/3d/framework/camera-component.ts @@ -74,7 +74,7 @@ const CameraClearFlag = Enum({ */ @ccclass('cc.CameraComponent') @menu('Components/CameraComponent') -// @executeInEditMode +@executeInEditMode export class CameraComponent extends Component { public static ProjectionType = ProjectionType; diff --git a/cocos/3d/framework/editor-camera-component.ts b/cocos/3d/framework/editor-camera-component.ts index 16280c4e3a..e058eb9fa0 100644 --- a/cocos/3d/framework/editor-camera-component.ts +++ b/cocos/3d/framework/editor-camera-component.ts @@ -1,11 +1,10 @@ -import { CameraComponent } from "./camera-component"; -import { ccclass, executeInEditMode } from "../../core/data/class-decorator"; -import { RenderView } from "../../pipeline/render-view"; -import { Camera } from "../../renderer"; -import { color4, toRadian } from "../../core/vmath"; +import { ccclass, executeInEditMode } from '../../core/data/class-decorator'; +import { color4, toRadian } from '../../core/vmath'; +import { RenderView } from '../../pipeline/render-view'; +import { Camera } from '../../renderer'; +import { CameraComponent } from './camera-component'; @ccclass('cc.EditorCameraComponent') -@executeInEditMode export class EditorCameraComponent extends CameraComponent { private _uiEditorCamera: Camera | null = null; From 351a7e5c82ecbdb6ebd70be65d63165473d66e55 Mon Sep 17 00:00:00 2001 From: JoneLau <32630749+JoneLau@users.noreply.github.com> Date: Thu, 21 Mar 2019 15:29:03 +0800 Subject: [PATCH 06/11] fix using spriteframe in atlas failed (#4073) --- cocos/3d/ui/components/label-component.ts | 14 +++++-- cocos/3d/ui/components/toggle-component.ts | 6 +-- .../ui/components/toggle-group-component.ts | 6 +-- cocos/3d/ui/components/widget-component.ts | 19 +++------- cocos/assets/CCSpriteFrame.ts | 38 +++++++------------ cocos/assets/sprite-atlas.ts | 32 +++++++++------- 6 files changed, 56 insertions(+), 59 deletions(-) diff --git a/cocos/3d/ui/components/label-component.ts b/cocos/3d/ui/components/label-component.ts index fd4469ae07..5ff856cf09 100644 --- a/cocos/3d/ui/components/label-component.ts +++ b/cocos/3d/ui/components/label-component.ts @@ -79,6 +79,8 @@ export enum VerticalTextAlignment { BOTTOM = 2, } +ccenum(VerticalTextAlignment); + /** * !#en Enum for Overflow. * !#zh Overflow 类型 @@ -169,7 +171,9 @@ export class LabelComponent extends UIRenderComponent { * !#zh 文本内容的水平对齐方式。 * @property {Label.HorizontalAlign} horizontalAlign */ - @property() + @property({ + type: HorizontalTextAlignment, + }) get horizontalAlign () { return this._horizontalAlign; } @@ -188,7 +192,9 @@ export class LabelComponent extends UIRenderComponent { * !#zh 文本内容的垂直对齐方式。 * @property {Label.VerticalAlign} VerticalTextAlignment */ - @property() + @property({ + type: VerticalTextAlignment, + }) get verticalAlign () { return this._verticalAlign; } @@ -277,7 +283,9 @@ export class LabelComponent extends UIRenderComponent { * !#zh 文字显示超出范围时的处理方式。 * @property {Overflow} overflow */ - @property() + @property({ + type: Overflow, + }) get overflow () { return this._overflow; } diff --git a/cocos/3d/ui/components/toggle-component.ts b/cocos/3d/ui/components/toggle-component.ts index 06d75da8cd..944ec5a1b1 100644 --- a/cocos/3d/ui/components/toggle-component.ts +++ b/cocos/3d/ui/components/toggle-component.ts @@ -27,7 +27,7 @@ import { EventHandler as ComponentEventHandler } from '../../../components/compo import { ccclass, executeInEditMode, executionOrder, menu, property } from '../../../core/data/class-decorator'; import { ButtonComponent} from './button-component'; import { SpriteComponent} from './sprite-component'; -import { ToggleGroupComponent} from './toggle-group-component'; +import { ToggleContainerComponent} from './toggle-group-component'; /** * !#en The toggle component is a CheckBox, when it used together with a ToggleGroup, it @@ -70,7 +70,7 @@ export class ToggleComponent extends ButtonComponent { * @property {ToggleGroup} toggleGroup */ @property({ - type: ToggleGroupComponent, + type: ToggleContainerComponent, }) get toggleGroup () { return this._toggleGroup; @@ -136,7 +136,7 @@ export class ToggleComponent extends ButtonComponent { @property private _isChecked: boolean = true; @property - private _toggleGroup: ToggleGroupComponent | null = null; + private _toggleGroup: ToggleContainerComponent | null = null; @property private _checkMark: SpriteComponent | null = null; diff --git a/cocos/3d/ui/components/toggle-group-component.ts b/cocos/3d/ui/components/toggle-group-component.ts index 8782e8befa..960121a994 100644 --- a/cocos/3d/ui/components/toggle-group-component.ts +++ b/cocos/3d/ui/components/toggle-group-component.ts @@ -37,11 +37,11 @@ import { ToggleComponent} from './toggle-component'; * @extends Component */ -@ccclass('cc.ToggleGroupComponent') +@ccclass('cc.ToggleContainerComponent') @executionOrder(100) @menu('UI/ToggleGroup') @executeInEditMode -export class ToggleGroupComponent extends Component { +export class ToggleContainerComponent extends Component { @property({ type: ComponentEventHandler, }) @@ -137,4 +137,4 @@ export class ToggleGroupComponent extends Component { } } -cc.ToggleGroupComponent = ToggleGroupComponent; +cc.ToggleContainerComponent = ToggleContainerComponent; diff --git a/cocos/3d/ui/components/widget-component.ts b/cocos/3d/ui/components/widget-component.ts index b5ecd8f88b..8f83c139aa 100644 --- a/cocos/3d/ui/components/widget-component.ts +++ b/cocos/3d/ui/components/widget-component.ts @@ -512,7 +512,6 @@ export class WidgetComponent extends Component { @property private _alignFlags = 0; - private _wasAlignOnce = false; @property private _target: Node | null = null; @property @@ -568,16 +567,6 @@ export class WidgetComponent extends Component { } protected onLoad () { - // TODO: - // if (this._wasAlignOnce) { - // // migrate for old version - // this.alignMode = this._wasAlignOnce ? AlignMode.ONCE : AlignMode.ALWAYS; - // this._wasAlignOnce = false; - // } - - if (this._alignMode === AlignMode.ONCE){ - this._wasAlignOnce = true; - } } protected onEnable () { @@ -604,6 +593,7 @@ export class WidgetComponent extends Component { this._originalWidth = this.node.width!; // test check conflict if (CC_EDITOR /*&& !cc.engine.isPlaying*/) { + // TODO: // _Scene.DetectConflict.checkConflict_Widget(this); } } @@ -613,13 +603,14 @@ export class WidgetComponent extends Component { // become stretch this._originalHeight = this.node.height!; // test check conflict - if (CC_EDITOR && !cc.engine.isPlaying) { + if (CC_EDITOR /*&& !cc.engine.isPlaying*/) { + // TODO: // _Scene.DetectConflict.checkConflict_Widget(this); } } } - if (CC_EDITOR && !cc.engine._isPlaying && this.node.parent) { + if (CC_EDITOR && this.node.parent) { // adjust the offsets to keep the size and position unchanged after alignment chagned cc._widgetManager.updateOffsetsToStayPut(this, flag); } @@ -641,6 +632,8 @@ export class WidgetComponent extends Component { } } +cc.WidgetComponent = WidgetComponent; + /** * !#en * When turned on, it will only be aligned once at the end of the onEnable frame, diff --git a/cocos/assets/CCSpriteFrame.ts b/cocos/assets/CCSpriteFrame.ts index c8d4524ed9..ea58edd9f9 100644 --- a/cocos/assets/CCSpriteFrame.ts +++ b/cocos/assets/CCSpriteFrame.ts @@ -121,9 +121,9 @@ export class SpriteFrame extends EventTargetFactory(Texture2D) { set insetTop (value) { this._capInsets[INSET_TOP] = value; - // if (this._texture) { - this._calculateSlicedUV(); - // } + if (this.image) { + this._calculateSlicedUV(); + } } /** @@ -139,9 +139,9 @@ export class SpriteFrame extends EventTargetFactory(Texture2D) { set insetBottom (value) { this._capInsets[INSET_BOTTOM] = value; - // if (this._texture) { - this._calculateSlicedUV(); - // } + if (this.image) { + this._calculateSlicedUV(); + } } /** @@ -157,9 +157,9 @@ export class SpriteFrame extends EventTargetFactory(Texture2D) { set insetLeft (value) { this._capInsets[INSET_LEFT] = value; - // if (this._texture) { - this._calculateSlicedUV(); - // } + if (this.image) { + this._calculateSlicedUV(); + } } /** @@ -175,9 +175,9 @@ export class SpriteFrame extends EventTargetFactory(Texture2D) { set insetRight (value) { this._capInsets[INSET_RIGHT] = value; - // if (this._texture) { - this._calculateSlicedUV(); - // } + if (this.image) { + this._calculateSlicedUV(); + } } get atlasUuid () { @@ -188,14 +188,6 @@ export class SpriteFrame extends EventTargetFactory(Texture2D) { this._atlasUuid = value; } - get atlasSize () { - return this._atlasSize; - } - - set atlasSize (value: Size) { - this._atlasSize = value; - } - public vertices: IVertices | null = null; public uv: number[] = []; @@ -216,12 +208,10 @@ export class SpriteFrame extends EventTargetFactory(Texture2D) { private _capInsets = [0, 0, 0, 0]; // store original info before packed to dynamic atlas - private _original = null; + // private _original = null; private _atlasUuid: string = ''; - private _atlasSize = new Size(); - /** * !#en * Constructor of SpriteFrame class. @@ -436,10 +426,10 @@ export class SpriteFrame extends EventTargetFactory(Texture2D) { * @method clone * @return {SpriteFrame} */ - public clone () { const cloneSprite = new SpriteFrame(); cloneSprite.name = this.name; + cloneSprite.atlasUuid = this.atlasUuid; cloneSprite.setOriginalSize(this._originalSize); cloneSprite.setRect(this._rect); const cap = this._capInsets; diff --git a/cocos/assets/sprite-atlas.ts b/cocos/assets/sprite-atlas.ts index f3c6c82a48..d7cbd88ae0 100644 --- a/cocos/assets/sprite-atlas.ts +++ b/cocos/assets/sprite-atlas.ts @@ -25,6 +25,7 @@ ****************************************************************************/ import { ccclass, property } from '../core/data/class-decorator'; +import * as js from '../core/utils/js'; import { Asset } from './asset'; import { SpriteFrame } from './CCSpriteFrame'; @@ -40,10 +41,14 @@ interface ISpriteAtlasSerializeData{ spriteFrames: string[]; } +interface ISpriteFrameList { + [key: string]: SpriteFrame | null; +} + @ccclass('cc.SpriteAtlas') export class SpriteAtlas extends Asset { @property - public spriteFrames: Map = new Map(); + public spriteFrames: ISpriteFrameList = js.createMap(); /** * Returns the texture of the sprite atlas @@ -51,10 +56,10 @@ export class SpriteAtlas extends Asset { * @returns {Texture2D} */ public getTexture () { - const values = this.spriteFrames.values; - if (values.length > 0) { - const spriteFrame = values[0]; - return spriteFrame && spriteFrame.image ? spriteFrame.image : null; + const keys = Object.keys(this.spriteFrames); + if (keys.length > 0) { + const spriteFrame = this.spriteFrames[keys[0]]; + return spriteFrame ? spriteFrame.image : null; } else { return null; @@ -85,8 +90,10 @@ export class SpriteAtlas extends Asset { */ public getSpriteFrames () { const frames: Array = []; - for (const spriteFrame of this.spriteFrames) { - frames.push(spriteFrame[1]); + const spriteFrames = this.spriteFrames; + + for (const key of Object.keys(spriteFrames)) { + frames.push(spriteFrames[key]); } return frames; @@ -94,9 +101,9 @@ export class SpriteAtlas extends Asset { public _serialize () { const frames: string[] = []; - for (const spriteFrame of this.spriteFrames) { - const id = spriteFrame[1] ? spriteFrame[1]._uuid : ''; - frames.push(spriteFrame[0]); + for (const key of Object.keys(this.spriteFrames)) { + const spriteFrame = this.spriteFrames[key]; + const id = spriteFrame ? spriteFrame._uuid : ''; frames.push(id); } @@ -110,10 +117,9 @@ export class SpriteAtlas extends Asset { const data = serializeData as ISpriteAtlasSerializeData; this._name = data.name; const frames = data.spriteFrames; - this.spriteFrames.clear(); + this.spriteFrames = js.createMap(); for (let i = 0; i < frames.length; i += 2) { - this.spriteFrames.set(frames[i], new SpriteFrame()); - handle.result.push(this.spriteFrames, `${i}`, frames[i + 1]); + handle.result.push(this.spriteFrames, frames[i], frames[i + 1]); } } } From 685b44b1f97b3aaf03d4e855c8f6ba5e30703a16 Mon Sep 17 00:00:00 2001 From: zxg0622 <247274249@qq.com> Date: Thu, 21 Mar 2019 15:32:53 +0800 Subject: [PATCH 07/11] fix particle destroy error (#4074) --- .../renderer/particle-system-renderer.ts | 21 +++++++++++++------ cocos/pipeline/render-view.ts | 1 + cocos/renderer/models/particle-batch-model.ts | 10 ++++++--- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/cocos/3d/framework/particle/renderer/particle-system-renderer.ts b/cocos/3d/framework/particle/renderer/particle-system-renderer.ts index e3e208f7ee..106a311085 100644 --- a/cocos/3d/framework/particle/renderer/particle-system-renderer.ts +++ b/cocos/3d/framework/particle/renderer/particle-system-renderer.ts @@ -144,19 +144,24 @@ export default class ParticleSystemRenderer extends RenderableComponent { } if (this._model == null) { this._model = this._getRenderScene().createModel(ParticleBatchModel, this.node) as ParticleBatchModel; + } + if (!this._model.inited) { this._model.setCapacity(this.particleSystem.capacity); this._model.setVertexAttributes(this._vertAttrs); this._model.node = this.node; + } + this._model.enabled = this.enabledInHierarchy; + } + + public onDisable () { + if (this._model) { this._model.enabled = this.enabledInHierarchy; } } - public onDisable () { - this._getRenderScene().destroyModel(this._model!); - } - public onDestroy () { - this._model!.destroy(); + this._getRenderScene().destroyModel(this._model!); + this._model = null; } public clear () { @@ -316,8 +321,12 @@ export default class ParticleSystemRenderer extends RenderableComponent { } else { console.warn(`particle system renderMode ${this._renderMode} not support.`); } + const ea = mat!.effectAsset; mat!.destroy(); - mat!.initialize({ defines: this._defines }); + mat!.initialize({ + defines: this._defines, + effectAsset: ea, + }); if (this.particleSystem.textureAnimationModule.enable) { mat!.setProperty('frameTile_velLenScale', vec2.set(this.frameTile_velLenScale, this.particleSystem.textureAnimationModule.numTilesX, this.particleSystem.textureAnimationModule.numTilesY)); diff --git a/cocos/pipeline/render-view.ts b/cocos/pipeline/render-view.ts index 14f8b858dd..fec9cd2a39 100644 --- a/cocos/pipeline/render-view.ts +++ b/cocos/pipeline/render-view.ts @@ -126,6 +126,7 @@ export class RenderView { } else { this._stages.push('ForwardFlow'); this._stages.push('ToneMapFlow'); + this._stages.push('SMAAFlow'); } return true; diff --git a/cocos/renderer/models/particle-batch-model.ts b/cocos/renderer/models/particle-batch-model.ts index 3d26a8e3fa..f9c166a84a 100644 --- a/cocos/renderer/models/particle-batch-model.ts +++ b/cocos/renderer/models/particle-batch-model.ts @@ -67,9 +67,9 @@ export default class ParticleBatchModel extends Model { // rebuid this._vBuffer = this._createSubMeshData(); this._vertAttrsFloatCount = this._vertSize / 4; // number of float - this._vBuffer = new ArrayBuffer(this._capacity * this._vertSize * 4); this._vdataF32 = new Float32Array(this._vBuffer); this._vdataUint32 = new Uint32Array(this._vBuffer); + this._inited = true; } public _createSubMeshData (): ArrayBuffer { @@ -156,8 +156,8 @@ export default class ParticleBatchModel extends Model { offset += 2; } else if (curAttr.format === GFXFormat.RGB32F) { this._vdataF32![offset] = pvdata[i].x; - this._vdataF32![offset + 1] = pvdata[i].y; this._vdataF32![offset + 2] = pvdata[i].z; + this._vdataF32![offset + 1] = pvdata[i].y; offset += 3; } else if (curAttr.format === GFXFormat.RGBA8) { this._vdataUint32![offset] = pvdata[i]; @@ -181,9 +181,13 @@ export default class ParticleBatchModel extends Model { public destroy () { super.destroy(); + this._vBuffer = null; this._vdataF32 = null; - this.destroySubMeshData(); + if (this._subMeshData) { + this.destroySubMeshData(); + } this._iaInfoBuffer.destroy(); + this._subMeshData = null; } private destroySubMeshData () { From 18319250d120f5dc0e4e8cbc3cafd583ee74e642 Mon Sep 17 00:00:00 2001 From: jerrywwl Date: Thu, 21 Mar 2019 16:52:50 +0800 Subject: [PATCH 08/11] fix render target rendering --- cocos/3d/builtin/effects.js | 6 +++--- cocos/core/game.js | 2 +- cocos/pipeline/render-pipeline.ts | 9 ++------- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/cocos/3d/builtin/effects.js b/cocos/3d/builtin/effects.js index 87ba1db86e..1ea0347f64 100644 --- a/cocos/3d/builtin/effects.js +++ b/cocos/3d/builtin/effects.js @@ -155,14 +155,14 @@ export default [ "shaders": [ { "name": "builtin-sprite|sprite-vs:vert|sprite-fs:frag", - "hash": 1848606651, + "hash": 3858451829, "glsl3": { "vert": `\nprecision mediump float;\nuniform CCGlobal {\n vec4 cc_time; \n vec4 cc_screenSize; \n vec4 cc_screenScale; \n vec4 cc_nativeSize; \n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos; \n vec4 cc_exposure; \n vec4 cc_mainLitDir; \n vec4 cc_mainLitColor; \n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\nin vec3 a_position;\nin vec2 a_texCoord;\nin vec4 a_color;\nout vec2 uv0;\nout vec4 color;\nvec4 vert () {\n vec4 pos = vec4(a_position, 1);\n pos = cc_matViewProj * pos;\n uv0 = a_texCoord;\n color = a_color;\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n`, - "frag": `\nprecision mediump float;\nuniform CCGlobal {\n vec4 cc_time; \n vec4 cc_screenSize; \n vec4 cc_screenScale; \n vec4 cc_nativeSize; \n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos; \n vec4 cc_exposure; \n vec4 cc_mainLitDir; \n vec4 cc_mainLitColor; \n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\nvec4 PostProcess(vec4 color)\n{\n#if CC_USE_HDR\n color.rgb = mix(color.rgb, pow(color.rgb, vec3(2.2)) * cc_exposure.w, vec3(cc_exposure.z));\n#endif\n return color;\n}\nin vec2 uv0;\nin vec4 color;\nuniform sampler2D mainTexture;\nvec4 frag () {\n vec4 o = vec4(1, 1, 1, 1);\n o *= texture(mainTexture, uv0);\n o *= color;\n return PostProcess(o);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }\n` + "frag": `\nprecision mediump float;\nuniform CCGlobal {\n vec4 cc_time; \n vec4 cc_screenSize; \n vec4 cc_screenScale; \n vec4 cc_nativeSize; \n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos; \n vec4 cc_exposure; \n vec4 cc_mainLitDir; \n vec4 cc_mainLitColor; \n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\nvec4 PostProcess(vec4 color)\n{\n#if CC_USE_HDR\n color.rgb = mix(color.rgb, pow(color.rgb, vec3(2.2)) * cc_exposure.w, vec3(cc_exposure.z));\n#endif\n return color;\n}\nin vec2 uv0;\nin vec4 color;\nuniform sampler2D mainTexture;\nvec4 frag () {\n vec4 o = vec4(1, 1, 1, 1);\n o *= texture(mainTexture, uv0);\n o *= color;\n return o;\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }\n` }, "glsl1": { "vert": `\nprecision mediump float;\nuniform vec4 cc_time;\nuniform vec4 cc_screenSize;\nuniform vec4 cc_screenScale;\nuniform vec4 cc_nativeSize;\nuniform mat4 cc_matView;\nuniform mat4 cc_matViewInv;\nuniform mat4 cc_matProj;\nuniform mat4 cc_matProjInv;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matViewProjInv;\nuniform vec4 cc_cameraPos;\nuniform vec4 cc_exposure;\nuniform vec4 cc_mainLitDir;\nuniform vec4 cc_mainLitColor;\nuniform vec4 cc_ambientSky;\nuniform vec4 cc_ambientGround;\nattribute vec3 a_position;\nattribute vec2 a_texCoord;\nattribute vec4 a_color;\nvarying vec2 uv0;\nvarying vec4 color;\nvec4 vert () {\n vec4 pos = vec4(a_position, 1);\n pos = cc_matViewProj * pos;\n uv0 = a_texCoord;\n color = a_color;\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n`, - "frag": `\nprecision mediump float;\nuniform vec4 cc_time;\nuniform vec4 cc_screenSize;\nuniform vec4 cc_screenScale;\nuniform vec4 cc_nativeSize;\nuniform mat4 cc_matView;\nuniform mat4 cc_matViewInv;\nuniform mat4 cc_matProj;\nuniform mat4 cc_matProjInv;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matViewProjInv;\nuniform vec4 cc_cameraPos;\nuniform vec4 cc_exposure;\nuniform vec4 cc_mainLitDir;\nuniform vec4 cc_mainLitColor;\nuniform vec4 cc_ambientSky;\nuniform vec4 cc_ambientGround;\nvec4 PostProcess(vec4 color)\n{\n#if CC_USE_HDR\n color.rgb = mix(color.rgb, pow(color.rgb, vec3(2.2)) * cc_exposure.w, vec3(cc_exposure.z));\n#endif\n return color;\n}\nvarying vec2 uv0;\nvarying vec4 color;\nuniform sampler2D mainTexture;\nvec4 frag () {\n vec4 o = vec4(1, 1, 1, 1);\n o *= texture2D(mainTexture, uv0);\n o *= color;\n return PostProcess(o);\n}\nvoid main() { gl_FragColor = frag(); }\n` + "frag": `\nprecision mediump float;\nuniform vec4 cc_time;\nuniform vec4 cc_screenSize;\nuniform vec4 cc_screenScale;\nuniform vec4 cc_nativeSize;\nuniform mat4 cc_matView;\nuniform mat4 cc_matViewInv;\nuniform mat4 cc_matProj;\nuniform mat4 cc_matProjInv;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matViewProjInv;\nuniform vec4 cc_cameraPos;\nuniform vec4 cc_exposure;\nuniform vec4 cc_mainLitDir;\nuniform vec4 cc_mainLitColor;\nuniform vec4 cc_ambientSky;\nuniform vec4 cc_ambientGround;\nvec4 PostProcess(vec4 color)\n{\n#if CC_USE_HDR\n color.rgb = mix(color.rgb, pow(color.rgb, vec3(2.2)) * cc_exposure.w, vec3(cc_exposure.z));\n#endif\n return color;\n}\nvarying vec2 uv0;\nvarying vec4 color;\nuniform sampler2D mainTexture;\nvec4 frag () {\n vec4 o = vec4(1, 1, 1, 1);\n o *= texture2D(mainTexture, uv0);\n o *= color;\n return o;\n}\nvoid main() { gl_FragColor = frag(); }\n` }, "builtins": {"globals":{"blocks":["CCGlobal"], "samplers":[]}, "locals":{"blocks":[], "samplers":[]}}, "defines": [ diff --git a/cocos/core/game.js b/cocos/core/game.js index 17347422dd..15d50760cf 100644 --- a/cocos/core/game.js +++ b/cocos/core/game.js @@ -701,7 +701,7 @@ class Game extends EventTarget { } } - // useWebGL2 = false; + useWebGL2 = false; if (useWebGL2) { this._gfxDevice = new cc.WebGL2GFXDevice(); } else { diff --git a/cocos/pipeline/render-pipeline.ts b/cocos/pipeline/render-pipeline.ts index 448cfb91ed..5661a0da5a 100644 --- a/cocos/pipeline/render-pipeline.ts +++ b/cocos/pipeline/render-pipeline.ts @@ -680,13 +680,8 @@ export abstract class RenderPipeline { _vec4Array[3] = 1.0 / _vec4Array[1]; this._defaultUboGlobal!.view.set(_vec4Array, UBOGlobal.SCREEN_SIZE_OFFSET); - if (!view.isOffscreen) { - _vec4Array[0] = camera.width / this._shadingTexWidth; - _vec4Array[1] = camera.height / this._shadingTexHeight; - } else { - _vec4Array[0] = 1.0; - _vec4Array[1] = 1.0; - } + _vec4Array[0] = camera.width / this._shadingTexWidth; + _vec4Array[1] = camera.height / this._shadingTexHeight; _vec4Array[2] = 1.0 / _vec4Array[0]; _vec4Array[3] = 1.0 / _vec4Array[1]; this._defaultUboGlobal!.view.set(_vec4Array, UBOGlobal.SCREEN_SCALE_OFFSET); From b8a53dac3d93e2853d85b63f5684163a1c55c1a8 Mon Sep 17 00:00:00 2001 From: jerrywwl Date: Thu, 21 Mar 2019 16:53:27 +0800 Subject: [PATCH 09/11] commit file --- cocos/core/game.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/core/game.js b/cocos/core/game.js index 15d50760cf..17347422dd 100644 --- a/cocos/core/game.js +++ b/cocos/core/game.js @@ -701,7 +701,7 @@ class Game extends EventTarget { } } - useWebGL2 = false; + // useWebGL2 = false; if (useWebGL2) { this._gfxDevice = new cc.WebGL2GFXDevice(); } else { From 986e4c5f641ef35c08bb275e2c0e28744a018a6d Mon Sep 17 00:00:00 2001 From: zxg0622 <247274249@qq.com> Date: Thu, 21 Mar 2019 16:55:27 +0800 Subject: [PATCH 10/11] modify flows in view (#4078) --- cocos/3d/framework/editor-camera-component.ts | 2 +- cocos/pipeline/render-pipeline.ts | 6 ++--- cocos/pipeline/render-view.ts | 23 +++++++++++-------- cocos/renderer/scene/camera.ts | 4 ++-- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/cocos/3d/framework/editor-camera-component.ts b/cocos/3d/framework/editor-camera-component.ts index e058eb9fa0..0fe280a886 100644 --- a/cocos/3d/framework/editor-camera-component.ts +++ b/cocos/3d/framework/editor-camera-component.ts @@ -129,7 +129,7 @@ export class EditorCameraComponent extends CameraComponent { targetDisplay: this._targetDisplay, priority: this._priority, isUI: true, - stages: ['UIFlow'], + flows: ['UIFlow'], }); this._uiEditorCamera!.viewport = this._camera.viewport; this._uiEditorCamera!.fov = this._camera.fov; diff --git a/cocos/pipeline/render-pipeline.ts b/cocos/pipeline/render-pipeline.ts index 5661a0da5a..c6d07c5ac8 100644 --- a/cocos/pipeline/render-pipeline.ts +++ b/cocos/pipeline/render-pipeline.ts @@ -190,10 +190,8 @@ export abstract class RenderPipeline { this.updateUBOs(view); - for (const flow of this._flows) { - if (view.stages.indexOf(flow.name) !== -1) { - flow.render(view); - } + for (const flow of view.flows) { + flow.render(view); } } diff --git a/cocos/pipeline/render-view.ts b/cocos/pipeline/render-view.ts index fec9cd2a39..c95265d93e 100644 --- a/cocos/pipeline/render-view.ts +++ b/cocos/pipeline/render-view.ts @@ -6,6 +6,7 @@ import { GFXTexture } from '../gfx/texture'; import { GFXTextureView } from '../gfx/texture-view'; import { GFXWindow } from '../gfx/window'; import { Camera } from '../renderer/scene/camera'; +import { RenderFlow } from './render-flow'; export enum RenderViewPriority { GENERAL = 100, @@ -16,7 +17,7 @@ export interface IRenderViewInfo { name: string; priority: number; isUI: boolean; - stages?: string[]; + flows?: string[]; } export interface IRenderTargetInfo { @@ -72,8 +73,8 @@ export class RenderView { return this._isUI; } - public get stages (): string[] { - return this._stages; + public get flows (): RenderFlow[] { + return this._flows; } public set isOffscreen (isOffscreen: boolean) { @@ -100,7 +101,7 @@ export class RenderView { private _camera: Camera; private _isEnable: boolean = true; private _isUI: boolean = false; - private _stages: string[] = []; + private _flows: RenderFlow[] = []; private _isOffscreen: boolean = false; // For offscreen @@ -121,12 +122,14 @@ export class RenderView { this._name = info.name; this._isUI = info.isUI; this.priority = info.priority; - if (info.stages) { - this._stages.push(...info.stages); - } else { - this._stages.push('ForwardFlow'); - this._stages.push('ToneMapFlow'); - this._stages.push('SMAAFlow'); + if (!info.flows) { + info.flows = ['ForwardFlow', 'ToneMapFlow', 'SMAAFlow']; + } + const pipelineFlows = cc.director.root.pipeline.flows; + for (const f of pipelineFlows) { + if (info.flows.indexOf(f.name) !== -1) { + this.flows.push(f); + } } return true; diff --git a/cocos/renderer/scene/camera.ts b/cocos/renderer/scene/camera.ts index 829b5a1c9f..7e7e73c6c4 100644 --- a/cocos/renderer/scene/camera.ts +++ b/cocos/renderer/scene/camera.ts @@ -73,7 +73,7 @@ export interface ICameraInfo { priority: number; pipeline?: string; isUI?: boolean; - stages?: string[]; + flows?: string[]; } const v_a = cc.v3(); @@ -139,7 +139,7 @@ export class Camera { name: this._name, priority: this._priority, isUI, - stages: info.stages, + flows: info.flows, }); this.changeTargetDisplay(info.targetDisplay); From 9d03bf48095b8d712672ce24e70d38f7ade2384f Mon Sep 17 00:00:00 2001 From: Yun Hsiao Wu Date: Thu, 21 Mar 2019 18:18:01 +0800 Subject: [PATCH 11/11] generate mipmap depend on mip filter (#4081) --- cocos/3d/builtin/init.ts | 6 +-- cocos/3d/framework/camera-component.ts | 2 +- cocos/assets/texture-base.ts | 52 ++++++-------------------- cocos/renderer/core/sampler-lib.ts | 19 +++++++++- cocos/renderer/scene/planar-shadow.ts | 12 +----- 5 files changed, 36 insertions(+), 55 deletions(-) diff --git a/cocos/3d/builtin/init.ts b/cocos/3d/builtin/init.ts index 26255b294c..99f2fa6750 100644 --- a/cocos/3d/builtin/init.ts +++ b/cocos/3d/builtin/init.ts @@ -35,7 +35,7 @@ class BuiltinResMgr { // black texture const blackCubeTexture = new TextureCube(); blackCubeTexture._uuid = 'black-cube-texture'; - blackCubeTexture.setGenMipmap(true); + blackCubeTexture.setMipFilter(TextureCube.Filter.LINEAR); blackCubeTexture.image = { front: new ImageAsset(canvas), back: new ImageAsset(canvas), @@ -65,7 +65,7 @@ class BuiltinResMgr { // white cube texture const whiteCubeTexture = new TextureCube(); whiteCubeTexture._uuid = 'white-cube-texture'; - whiteCubeTexture.setGenMipmap(true); + whiteCubeTexture.setMipFilter(TextureCube.Filter.LINEAR); whiteCubeTexture.image = { front: new ImageAsset(canvas), back: new ImageAsset(canvas), @@ -99,7 +99,7 @@ class BuiltinResMgr { // default cube texture const defaultCubeTexture = new TextureCube(); - defaultCubeTexture.setGenMipmap(true); + defaultCubeTexture.setMipFilter(TextureCube.Filter.LINEAR); defaultCubeTexture._uuid = 'default-cube-texture'; defaultCubeTexture.image = { front: new ImageAsset(canvas), diff --git a/cocos/3d/framework/camera-component.ts b/cocos/3d/framework/camera-component.ts index 3517b22185..dd7e20ddf9 100644 --- a/cocos/3d/framework/camera-component.ts +++ b/cocos/3d/framework/camera-component.ts @@ -103,7 +103,7 @@ export class CameraComponent extends Component { @property protected _screenScale = 1; @property - protected _targetDisplay = -1; + protected _targetDisplay = 0; protected _camera: Camera | null = null; diff --git a/cocos/assets/texture-base.ts b/cocos/assets/texture-base.ts index 9b01c98083..635785e39a 100644 --- a/cocos/assets/texture-base.ts +++ b/cocos/assets/texture-base.ts @@ -129,6 +129,7 @@ export enum WrapMode { * @enum {number} */ export enum Filter { + NONE = GFXFilter.NONE, /** * Specifies linear filtering. */ @@ -180,9 +181,6 @@ export class TextureBase extends EventTargetFactory(Asset) { return texture._format >= PixelFormat.RGB_PVRTC_2BPPV1 && texture._format <= PixelFormat.RGBA_PVRTC_4BPPV1; } - @property - protected _genMipmap = false; - @property protected _format: number = PixelFormat.RGBA8888; @@ -199,7 +197,7 @@ export class TextureBase extends EventTargetFactory(Asset) { protected _magFilter: number = Filter.LINEAR; @property - protected _mipFilter: number = Filter.LINEAR; + protected _mipFilter: number = Filter.NONE; @property protected _wrapS: number = WrapMode.REPEAT; @@ -294,16 +292,6 @@ export class TextureBase extends EventTargetFactory(Asset) { return this._anisotropy; } - /** - * !#en - * Whether or not to generate mipmap. - * !#zh 检查纹理在上传 GPU 时是否生成 mipmap。 - * @return - */ - public genMipmap () { - return this._genMipmap || false; - } - /** * !#en Sets the wrap s and wrap t options.
* If the texture size is NPOT (non power of 2), then in can only use gl.CLAMP_TO_EDGE in gl.TEXTURE_WRAP_{S,T}. @@ -314,10 +302,10 @@ export class TextureBase extends EventTargetFactory(Asset) { * @param wrapR */ public setWrapMode (wrapS: WrapMode, wrapT: WrapMode, wrapR?: WrapMode) { - if (wrapS !== this._wrapS) { this._wrapS = wrapS; this._samplerInfo[SamplerInfoIndex.addressU] = wrapS; } - if (wrapT !== this._wrapT) { this._wrapT = wrapT; this._samplerInfo[SamplerInfoIndex.addressV] = wrapT; } + this._wrapS = wrapS; this._samplerInfo[SamplerInfoIndex.addressU] = wrapS; + this._wrapT = wrapT; this._samplerInfo[SamplerInfoIndex.addressV] = wrapT; if (wrapR === undefined) { return; } - if (wrapR !== this._wrapR) { this._wrapR = wrapR; this._samplerInfo[SamplerInfoIndex.addressW] = wrapR; } + this._wrapR = wrapR; this._samplerInfo[SamplerInfoIndex.addressW] = wrapR; } /** @@ -327,8 +315,8 @@ export class TextureBase extends EventTargetFactory(Asset) { * @param magFilter */ public setFilters (minFilter: Filter, magFilter: Filter) { - if (minFilter !== this._minFilter) { this._minFilter = minFilter; this._samplerInfo[SamplerInfoIndex.minFilter] = minFilter; } - if (magFilter !== this._magFilter) { this._magFilter = magFilter; this._samplerInfo[SamplerInfoIndex.magFilter] = magFilter; } + this._minFilter = minFilter; this._samplerInfo[SamplerInfoIndex.minFilter] = minFilter; + this._magFilter = magFilter; this._samplerInfo[SamplerInfoIndex.magFilter] = magFilter; } /** @@ -337,7 +325,7 @@ export class TextureBase extends EventTargetFactory(Asset) { * @param mipFilter */ public setMipFilter (mipFilter: Filter) { - if (mipFilter !== this._mipFilter) { this._mipFilter = mipFilter; this._samplerInfo[SamplerInfoIndex.mipFilter] = mipFilter; } + this._mipFilter = mipFilter; this._samplerInfo[SamplerInfoIndex.mipFilter] = mipFilter; } /** @@ -366,21 +354,7 @@ export class TextureBase extends EventTargetFactory(Asset) { * @param anisotropy */ public setAnisotropy (anisotropy: number) { - if (anisotropy !== this._anisotropy) { this._anisotropy = anisotropy; this._samplerInfo[SamplerInfoIndex.maxAnisotropy] = anisotropy; } - } - - /** - * !#en - * Sets whether generate mipmaps for the texture - * !#zh 是否为纹理设置生成 mipmaps。 - * @param mipmap - */ - public setGenMipmap (mipmap: boolean) { - if (this._genMipmap !== mipmap) { - this._genMipmap = mipmap; - this._recreateTexture(); - this.updateImage(); - } + this._anisotropy = anisotropy; this._samplerInfo[SamplerInfoIndex.maxAnisotropy] = anisotropy; } public destroy () { @@ -411,8 +385,7 @@ export class TextureBase extends EventTargetFactory(Asset) { this._wrapS + ',' + this._wrapT + ',' + (this._premultiplyAlpha ? 1 : 0) + ',' + this._mipFilter + ',' + this._anisotropy + ',' + - (this._flipY ? 1 : 0) + ',' + - (this._genMipmap ? 1 : 0); + (this._flipY ? 1 : 0); } /** @@ -435,9 +408,8 @@ export class TextureBase extends EventTargetFactory(Asset) { this.setMipFilter(parseInt(fields[6])); this.setAnisotropy(parseInt(fields[7])); } - if (fields.length >= 10) { + if (fields.length >= 9) { this._flipY = fields[8].charCodeAt(0) === CHAR_CODE_1; - this._genMipmap = fields[9].charCodeAt(0) === CHAR_CODE_1; } } @@ -543,7 +515,7 @@ export class TextureBase extends EventTargetFactory(Asset) { width: this._potientialWidth, height: this._potientialHeight, mipLevel: this._mipmapLevel, - flags: this._genMipmap ? GFXTextureFlagBit.GEN_MIPMAP : GFXTextureFlagBit.NONE, + flags: this._mipFilter !== Filter.NONE ? GFXTextureFlagBit.GEN_MIPMAP : GFXTextureFlagBit.NONE, }; } diff --git a/cocos/renderer/core/sampler-lib.ts b/cocos/renderer/core/sampler-lib.ts index 9c387618d9..ce83aab033 100644 --- a/cocos/renderer/core/sampler-lib.ts +++ b/cocos/renderer/core/sampler-lib.ts @@ -1,5 +1,6 @@ // Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. +import { GFXAddress, GFXComparisonFunc, GFXFilter } from '../../gfx/define'; import { GFXDevice } from '../../gfx/device'; import { GFXSampler, IGFXSamplerInfo } from '../../gfx/sampler'; @@ -19,13 +20,29 @@ export enum SamplerInfoIndex { total = borderColor + 4, } +const defaultInfo = [ + GFXFilter.LINEAR, + GFXFilter.LINEAR, + GFXFilter.NONE, + GFXAddress.WRAP, + GFXAddress.WRAP, + GFXAddress.WRAP, + 16, + GFXComparisonFunc.NEVER, + 0, 1000, 0, + 0, 0, 0, 0, +]; + const gfxInfo: IGFXSamplerInfo = {}; class SamplerLib { protected _cache: Record = {}; public getSampler (device: GFXDevice, info: number[]) { - const hash = info.toString(); + let hash = ''; + for (let i = 0; i < defaultInfo.length; i++) { + hash += (info[i] || defaultInfo[i]) + ','; + } const cache = this._cache[hash]; if (cache) { return cache; } gfxInfo.minFilter = info[SamplerInfoIndex.minFilter]; diff --git a/cocos/renderer/scene/planar-shadow.ts b/cocos/renderer/scene/planar-shadow.ts index 267b2f743e..f4c2e12a06 100644 --- a/cocos/renderer/scene/planar-shadow.ts +++ b/cocos/renderer/scene/planar-shadow.ts @@ -25,13 +25,6 @@ export class PlanarShadow { return this._distance; } - set offset (val: number) { - this._offset = val; - } - get offset () { - return this._offset; - } - set shadowColor (color: Color) { color4.array(this._data, color, UBOShadow.SHADOW_COLOR_OFFSET); } @@ -43,7 +36,6 @@ export class PlanarShadow { protected _scene: RenderScene; protected _normal = new Vec3(0, 1, 0); protected _distance = 0; - protected _offset = 0.01; protected _data = Float32Array.from([ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, // matLightPlaneProj 0.3, 0.3, 0.3, 1.0, // shadowColor @@ -56,7 +48,7 @@ export class PlanarShadow { // tslint:disable: one-variable-per-declaration public updateSphereLight (light: SphereLight) { light.node.getWorldPosition(_v3); - const n = this._normal, d = this._distance + this._offset; + const n = this._normal, d = this._distance; const NdL = vec3.dot(n, _v3); const lx = _v3.x, ly = _v3.y, lz = _v3.z; const nx = n.x, ny = n.y, nz = n.z; @@ -82,7 +74,7 @@ export class PlanarShadow { public updateDirLight (light: DirectionalLight) { light.node.getWorldRotation(_qt); vec3.transformQuat(_v3, _forward, _qt); - const n = this._normal, d = this._distance + this._offset; + const n = this._normal, d = this._distance; const NdL = vec3.dot(n, _v3), scale = 1 / NdL; const lx = _v3.x * scale, ly = _v3.y * scale, lz = _v3.z * scale; const nx = n.x, ny = n.y, nz = n.z;