merge from 3d-stable

This commit is contained in:
jerrywwl
2019-03-22 09:46:07 +08:00
45 changed files with 454 additions and 315 deletions
+2 -1
View File
@@ -207,7 +207,8 @@ export class Material extends Asset {
protected _update (keepProps: boolean = true) {
const asset = this._effectAsset;
if (!asset) { this._passes = builtinResMgr.get<Material>('default-material')._passes.slice(); return; }
// ugly yellow indicating missing effect
if (!asset) { this._passes = builtinResMgr.get<Material>('missing-effect-material')._passes.slice(); return; }
// create passes
this._passes = Effect.parseEffect(asset, {
techIdx: this._techIdx,
+8 -7
View File
@@ -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": [
@@ -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": [
+19 -25
View File
@@ -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),
@@ -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';
@@ -149,15 +133,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();
+2 -2
View File
@@ -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;
@@ -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)
@@ -0,0 +1,144 @@
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')
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,
flows: ['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;
}
}
}
+2
View File
@@ -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;
+1 -1
View File
@@ -284,6 +284,6 @@ export class ModelComponent extends RenderableComponent {
private _getBuiltinMaterial () {
// classic ugly pink indicating missing material
return builtinResMgr.get<Material>('default-material');
return builtinResMgr.get<Material>('missing-material');
}
}
@@ -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));
+1 -1
View File
@@ -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);
}
+1 -1
View File
@@ -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);
}
+1 -1
View File
@@ -178,7 +178,7 @@ export class CanvasComponent extends Component {
targetDisplay: 0,
priority: this._priority,
isUI: true,
pipeline: 'ui',
stages: ['UIFlow'],
});
this._camera!.fov = 45;
+11 -3
View File
@@ -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;
}
+3 -3
View File
@@ -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;
@@ -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;
+6 -13
View File
@@ -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,
+14 -24
View File
@@ -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;
+19 -13
View File
@@ -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<string, SpriteFrame | null> = new Map<string, SpriteFrame | null>();
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<SpriteFrame | null> = [];
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]);
}
}
}
+12 -40
View File
@@ -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. <br/>
* 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,
};
}
+7 -1
View File
@@ -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 () {
+9 -50
View File
@@ -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 = [];
}
}
+3 -3
View File
@@ -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;
}
}
+4 -1
View File
@@ -30,7 +30,10 @@ export class ForwardFlow extends RenderFlow {
return true;
}
public destroy (): void {
public destroy () {
this.destroyStages();
}
public rebuild () {
}
}
@@ -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;
}
@@ -116,6 +123,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);
+3
View File
@@ -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!;
+3
View File
@@ -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!;
+3
View File
@@ -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!;
+14 -4
View File
@@ -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 () {
}
}
+15
View File
@@ -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();
}
}
}
+23 -16
View File
@@ -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!;
+1
View File
@@ -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) {
+11 -8
View File
@@ -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) {
@@ -184,7 +190,7 @@ export abstract class RenderPipeline {
this.updateUBOs(view);
for (const flow of this._flows) {
for (const flow of view.flows) {
flow.render(view);
}
}
@@ -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)) {
@@ -670,13 +678,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);
+1
View File
@@ -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) {
+24 -1
View File
@@ -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,6 +17,7 @@ export interface IRenderViewInfo {
name: string;
priority: number;
isUI: boolean;
flows?: string[];
}
export interface IRenderTargetInfo {
@@ -47,6 +49,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 +73,14 @@ export class RenderView {
return this._isUI;
}
public get flows (): RenderFlow[] {
return this._flows;
}
public set isOffscreen (isOffscreen: boolean) {
this._isOffscreen = isOffscreen;
}
public get isOffscreen (): boolean {
return this._isOffscreen;
}
@@ -88,6 +101,7 @@ export class RenderView {
private _camera: Camera;
private _isEnable: boolean = true;
private _isUI: boolean = false;
private _flows: RenderFlow[] = [];
private _isOffscreen: boolean = false;
// For offscreen
@@ -107,7 +121,16 @@ export class RenderView {
this._name = info.name;
this._isUI = info.isUI;
this._priority = info.priority;
this.priority = info.priority;
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;
}
+5 -1
View File
@@ -30,7 +30,11 @@ export class UIFlow extends RenderFlow {
return true;
}
public destroy (): void {
public destroy () {
this.destroyStages();
}
public rebuild () {
}
}
-49
View File
@@ -1,49 +0,0 @@
import { Root } from '../../core/root';
import { mat4 } from '../../core/vmath';
import { UBOGlobal } from '../define';
import { IRenderPipelineInfo, RenderPipeline } from '../render-pipeline';
import { RenderView } from '../render-view';
import { UIFlow } from './ui-flow';
const _vec4Array = new Float32Array(4);
const _mat4Array = new Float32Array(16);
export class UIPipeline extends RenderPipeline {
constructor (root: Root) {
super(root);
}
public initialize (info: IRenderPipelineInfo): boolean {
if (!this.createUBOs()) {
return false;
}
// create flows
this.createFlow<UIFlow>(UIFlow, {
name: 'UIFlow',
priority: 0,
});
return true;
}
public destroy () {
this._destroy();
}
protected updateUBOs (view: RenderView) {
const camera = view.camera;
mat4.array(_mat4Array, camera.matViewProj);
this._defaultUboGlobal!.view.set(_mat4Array, UBOGlobal.MAT_VIEW_PROJ_OFFSET);
_vec4Array[0] = camera.exposure;
_vec4Array[1] = _vec4Array[0] * this._fpScaleInv;
_vec4Array[2] = 0.0;
_vec4Array[3] = 1.0 / _vec4Array[1];
this._defaultUboGlobal!.view.set(_vec4Array, UBOGlobal.EXPOSURE_OFFSET);
// update ubos
this._globalBindings.get(UBOGlobal.BLOCK.name)!.buffer!.update(this._defaultUboGlobal!.view.buffer);
}
}
+7 -1
View File
@@ -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;
+18 -1
View File
@@ -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<string, GFXSampler> = {};
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];
@@ -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 () {
+4 -1
View File
@@ -73,6 +73,7 @@ export interface ICameraInfo {
priority: number;
pipeline?: string;
isUI?: boolean;
flows?: 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,
flows: info.flows,
});
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;
+1 -1
View File
@@ -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;
+2 -10
View File
@@ -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;
+2 -2
View File
@@ -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<IRaycastResult>(() => {
return { node: null!, distance: Infinity };
}, 8);
const results: IRaycastResult[] = [];
-4
View File
@@ -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);
+9 -13
View File
@@ -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>(UIBatchModel, null), 2);
});
} else {
this._scene = this._root.createScene({
name: 'GUIScene',
});
this._uiModelPool = new Pool(() => this._scene.createModel<UIBatchModel>(UIBatchModel, null), 2);
}
this._scene = this._root.createScene({
name: 'GUIScene',
});
this._uiModelPool = new Pool(() => this._scene.createModel<UIBatchModel>(UIBatchModel, null), 2);
this._modelInUse = new CachedArray<UIBatchModel>(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)!;
+1 -1
View File
@@ -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);