diff --git a/cocos/3d/builtin/effects.js b/cocos/3d/builtin/effects.js index 664dcdaff4..7411715829 100644 --- a/cocos/3d/builtin/effects.js +++ b/cocos/3d/builtin/effects.js @@ -1,5 +1,47 @@ // absolute essential effects export default [ + { + "name": "builtin-particle-trail", + "techniques": [ + {"name":"add", "passes":[{"rasterizerState":{"cullMode":0}, "blendState":{"targets":[{"blend":true, "blendSrc":2, "blendDst":1, "blendSrcAlpha":2, "blendDstAlpha":1}]}, "program":"builtin-particle-trail|particle-trail:vs_main|tinted-fs:add", "depthStencilState":{"depthTest":true, "depthWrite":false}, "properties":{"mainTexture":{"value":"grey", "type":28}, "mainTiling_Offset":{"value":[1, 1, 0, 0], "type":16}, "frameTile_velLenScale":{"value":[1, 1, 0, 0], "type":16}, "tintColor":{"value":[0.5, 0.5, 0.5, 0.5], "inspector":{"type":"color"}, "type":16}}}]} + ], + "shaders": [ + { + "name": "builtin-particle-trail|particle-trail:vs_main|tinted-fs:add", + "hash": 2386140965, + "glsl3": { + "vert": `\nprecision mediump float;\nuniform Constants {\n vec4 mainTiling_Offset;\n vec4 frameTile_velLenScale;\n};\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};\nuniform CCLocal {\n mat4 cc_matWorld;\n mat4 cc_matWorldIT;\n};\nout vec2 uv;\nout vec4 color;\nvoid computeVertPos(inout vec4 pos, vec2 vertOffset\n#if CC_USE_BILLBOARD || CC_USE_VERTICAL_BILLBOARD\n , mat4 view\n#endif\n#if CC_USE_STRETCHED_BILLBOARD\n , vec3 eye\n , vec4 velocity\n , float velocityScale\n , float lengthScale\n , float size\n , float xIndex\n#endif\n) {\n#if CC_USE_BILLBOARD\n vec3 camRight = normalize(vec3(view[0][0], view[1][0], view[2][0]));\n vec3 camUp = normalize(vec3(view[0][1], view[1][1], view[2][1]));\n pos.xyz += (camRight * vertOffset.x) + (camUp * vertOffset.y);\n#elif CC_USE_STRETCHED_BILLBOARD\n vec3 camRight = normalize(cross(pos.xyz - eye, velocity.xyz));\n vec3 camUp = velocity.xyz * velocityScale + normalize(velocity.xyz) * lengthScale * size;\n pos.xyz += (camRight * abs(vertOffset.x) * sign(vertOffset.y)) - camUp * xIndex;\n#elif CC_USE_HORIZONTAL_BILLBOARD\n vec3 camRight = vec3(1, 0, 0);\n vec3 camUp = vec3(0, 0, -1);\n pos.xyz += (camRight * vertOffset.x) + (camUp * vertOffset.y);\n#elif CC_USE_VERTICAL_BILLBOARD\n vec3 camRight = normalize(vec3(view[0][0], view[1][0], view[2][0]));\n vec3 camUp = vec3(0, 1, 0);\n pos.xyz += (camRight * vertOffset.x) + (camUp * vertOffset.y);\n#else\n pos.x += vertOffset.x;\n pos.y += vertOffset.y;\n#endif\n}\nvec2 computeUV(float frameIndex, vec2 vertIndex, vec2 frameTile) {\n vec2 aniUV = vec2(0, floor(frameIndex * frameTile.y));\n aniUV.x = floor(frameIndex * frameTile.x * frameTile.y - aniUV.y * frameTile.x);\n \n vertIndex.x = 1. - vertIndex.x;\n return (aniUV.xy + vertIndex) / vec2(frameTile.x, frameTile.y);\n}\nvoid rotateCorner(inout vec2 corner, float angle) {\n float xOS = cos(angle) * corner.x - sin(angle) * corner.y;\n float yOS = sin(angle) * corner.x + cos(angle) * corner.y;\n corner.x = xOS;\n corner.y = yOS;\n}\nin vec3 a_position; \nin vec4 a_texCoord; \nin vec3 a_texCoord1; \nin vec4 a_color;\nvec4 vs_main() {\n vec4 pos = vec4(a_position, 1);\n vec4 velocity = vec4(a_texCoord1.xyz, 0);\n #if !CC_USE_WORLD_SPACE\n pos = cc_matWorld * pos;\n velocity = cc_matWorld * velocity;\n #endif\n float vertOffset = (a_texCoord.x - 0.5) * a_texCoord.y;\n vec3 camUp = normalize(cross(pos.xyz - cc_cameraPos.xyz, velocity.xyz));\n pos.xyz += camUp * vertOffset;\n pos = cc_matViewProj * pos;\n uv = a_texCoord.zw;\n color = a_color;\n return pos;\n}\nvoid main() { gl_Position = vs_main(); }\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 uv;\nin vec4 color;\nuniform sampler2D mainTexture;\nuniform FragConstants {\n vec4 tintColor;\n};\nvec4 add () {\n vec4 col = 2.0 * color * tintColor * texture(mainTexture, uv);\n return PostProcess(col);\n}\nvec4 multiply () {\n vec4 col;\n vec4 texColor = texture(mainTexture, uv);\n col.rgb = tintColor.rgb * texColor.rgb * color.rgb * vec3(2.0);\n col.a = (1.0 - texColor.a) * (tintColor.a * color.a * 2.0);\n return PostProcess(col);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = add(); }\n` + }, + "glsl1": { + "vert": `\nprecision mediump float;\nuniform mat4 cc_matViewProj;\nuniform vec4 cc_cameraPos;\nuniform mat4 cc_matWorld;\nvarying vec2 uv;\nvarying vec4 color;\nvoid computeVertPos(inout vec4 pos, vec2 vertOffset\n#if CC_USE_BILLBOARD || CC_USE_VERTICAL_BILLBOARD\n , mat4 view\n#endif\n#if CC_USE_STRETCHED_BILLBOARD\n , vec3 eye\n , vec4 velocity\n , float velocityScale\n , float lengthScale\n , float size\n , float xIndex\n#endif\n) {\n#if CC_USE_BILLBOARD\n vec3 camRight = normalize(vec3(view[0][0], view[1][0], view[2][0]));\n vec3 camUp = normalize(vec3(view[0][1], view[1][1], view[2][1]));\n pos.xyz += (camRight * vertOffset.x) + (camUp * vertOffset.y);\n#elif CC_USE_STRETCHED_BILLBOARD\n vec3 camRight = normalize(cross(pos.xyz - eye, velocity.xyz));\n vec3 camUp = velocity.xyz * velocityScale + normalize(velocity.xyz) * lengthScale * size;\n pos.xyz += (camRight * abs(vertOffset.x) * sign(vertOffset.y)) - camUp * xIndex;\n#elif CC_USE_HORIZONTAL_BILLBOARD\n vec3 camRight = vec3(1, 0, 0);\n vec3 camUp = vec3(0, 0, -1);\n pos.xyz += (camRight * vertOffset.x) + (camUp * vertOffset.y);\n#elif CC_USE_VERTICAL_BILLBOARD\n vec3 camRight = normalize(vec3(view[0][0], view[1][0], view[2][0]));\n vec3 camUp = vec3(0, 1, 0);\n pos.xyz += (camRight * vertOffset.x) + (camUp * vertOffset.y);\n#else\n pos.x += vertOffset.x;\n pos.y += vertOffset.y;\n#endif\n}\nvec2 computeUV(float frameIndex, vec2 vertIndex, vec2 frameTile) {\n vec2 aniUV = vec2(0, floor(frameIndex * frameTile.y));\n aniUV.x = floor(frameIndex * frameTile.x * frameTile.y - aniUV.y * frameTile.x);\n \n vertIndex.x = 1. - vertIndex.x;\n return (aniUV.xy + vertIndex) / vec2(frameTile.x, frameTile.y);\n}\nvoid rotateCorner(inout vec2 corner, float angle) {\n float xOS = cos(angle) * corner.x - sin(angle) * corner.y;\n float yOS = sin(angle) * corner.x + cos(angle) * corner.y;\n corner.x = xOS;\n corner.y = yOS;\n}\nattribute vec3 a_position; \nattribute vec4 a_texCoord; \nattribute vec3 a_texCoord1; \nattribute vec4 a_color;\nvec4 vs_main() {\n vec4 pos = vec4(a_position, 1);\n vec4 velocity = vec4(a_texCoord1.xyz, 0);\n #if !CC_USE_WORLD_SPACE\n pos = cc_matWorld * pos;\n velocity = cc_matWorld * velocity;\n #endif\n float vertOffset = (a_texCoord.x - 0.5) * a_texCoord.y;\n vec3 camUp = normalize(cross(pos.xyz - cc_cameraPos.xyz, velocity.xyz));\n pos.xyz += camUp * vertOffset;\n pos = cc_matViewProj * pos;\n uv = a_texCoord.zw;\n color = a_color;\n return pos;\n}\nvoid main() { gl_Position = vs_main(); }\n`, + "frag": `\nprecision mediump float;\nuniform vec4 cc_exposure;\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 uv;\nvarying vec4 color;\nuniform sampler2D mainTexture;\nuniform vec4 tintColor;\nvec4 add () {\n vec4 col = 2.0 * color * tintColor * texture2D(mainTexture, uv);\n return PostProcess(col);\n}\nvec4 multiply () {\n vec4 col;\n vec4 texColor = texture2D(mainTexture, uv);\n col.rgb = tintColor.rgb * texColor.rgb * color.rgb * vec3(2.0);\n col.a = (1.0 - texColor.a) * (tintColor.a * color.a * 2.0);\n return PostProcess(col);\n}\nvoid main() { gl_FragColor = add(); }\n` + }, + "builtins": {"globals":{"blocks":["CCGlobal"], "samplers":[]}, "locals":{"blocks":["CCLocal"], "samplers":[]}}, + "defines": [ + {"name":"CC_USE_BILLBOARD", "type":"boolean", "defines":[]}, + {"name":"CC_USE_STRETCHED_BILLBOARD", "type":"boolean", "defines":[]}, + {"name":"CC_USE_HORIZONTAL_BILLBOARD", "type":"boolean", "defines":[]}, + {"name":"CC_USE_VERTICAL_BILLBOARD", "type":"boolean", "defines":[]}, + {"name":"CC_USE_WORLD_SPACE", "type":"boolean", "defines":[]}, + {"name":"CC_USE_HDR", "type":"boolean", "defines":[]} + ], + "blocks": [ + {"name": "Constants", "size": 32, "defines": [], "binding": 0, "members": [ + {"name":"mainTiling_Offset", "type":16, "count":1, "size":16}, + {"name":"frameTile_velLenScale", "type":16, "count":1, "size":16} + ]}, + {"name": "FragConstants", "size": 16, "defines": [], "binding": 1, "members": [ + {"name":"tintColor", "type":16, "count":1, "size":16} + ]} + ], + "samplers": [ + {"name":"mainTexture", "type":28, "count":1, "defines":[], "binding":2} + ], + "dependencies": {} + } + ] + }, { "name": "builtin-particle", "techniques": [ @@ -111,21 +153,20 @@ export default [ "shaders": [ { "name": "builtin-standard|standard-vs:vert|standard-fs:frag", - "hash": 2465682243, + "hash": 376987808, "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};\nuniform CCLocal {\n mat4 cc_matWorld;\n mat4 cc_matWorldIT;\n};\nuniform Constants {\n vec4 tilingOffset;\n vec4 albedo;\n vec4 albedoScale; \n vec4 pbrParams; \n vec4 pbrScale; \n vec4 emissive;\n vec4 emissiveScale;\n};\n#if CC_USE_SKINNING\nin vec4 a_weights;\nin vec4 a_joints;\n#if CC_USE_JOINTS_TEXTURE\nuniform CCSkinningTextureCase {\n vec4 cc_jointsTextureSize;\n};\n#else \nuniform CCSkinning {\n vec4 cc_matJoint[30 * 3];\n};\n#endif\n#if CC_USE_JOINTS_TEXTURE\nuniform sampler2D cc_jointsTexture;\n#if CC_USE_JOINTS_TEXTURE_RGBA8888\nhighp float decode32(highp vec4 rgba) {\n highp float Sign = 1. - step(128., rgba[0]) * 2.;\n highp float Exponent = 2. * mod(rgba[0], 128.) + step(128., rgba[1]) - 127.;\n if (Exponent == -127.) {\n return 0.;\n }\n highp float Mantissa = mod(rgba[1], 128.) * 65536. + rgba[2] * 256. +\n rgba[3] + float(0x800000);\n return Sign * exp2(Exponent - 23.) * Mantissa;\n}\nhighp vec4 decodevec4(highp vec4 x, highp vec4 y, highp vec4 z, highp vec4 w) {\n return vec4(decode32(x * 255.), decode32(y * 255.), decode32(z * 255.),\n decode32(w * 255.));\n}\nhighp mat4 getBoneMatrix(const in float i) {\n float size = cc_jointsTextureSize.x;\n float j = i * 16.;\n float x = mod(j, size);\n float y = floor(j / size);\n float dx = 1. / size;\n float dy = 1. / size;\n y = dy * (y + .5);\n highp vec4 v1 =\n decodevec4(texture(cc_jointsTexture, vec2(dx * (x + .5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 1.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 2.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 3.5), y)));\n highp vec4 v2 =\n decodevec4(texture(cc_jointsTexture, vec2(dx * (x + 4.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 5.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 6.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 7.5), y)));\n highp vec4 v3 =\n decodevec4(texture(cc_jointsTexture, vec2(dx * (x + 8.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 9.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 10.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 11.5), y)));\n highp vec4 v4 =\n decodevec4(texture(cc_jointsTexture, vec2(dx * (x + 12.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 13.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 14.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 15.5), y)));\n return mat4(v1, v2, v3, v4);\n}\n#else\n#if CC_SUPPORT_TEXEL_FETCH\nmat4 getBoneMatrix(const in int i) {\n ivec2 size = ivec2(int(cc_jointsTextureSize.x), 0);\n \n int start = i * 4;\n int x = start % size.x;\n int y = start / size.x;\n vec4 v1 = texelFetch(cc_jointsTexture, ivec2(x + 0, y), 0);\n vec4 v2 = texelFetch(cc_jointsTexture, ivec2(x + 1, y), 0);\n vec4 v3 = texelFetch(cc_jointsTexture, ivec2(x + 2, y), 0);\n vec4 v4 = texelFetch(cc_jointsTexture, ivec2(x + 3, y), 0);\n return mat4(v1, v2, v3, v4);\n}\n#else\nmat4 getBoneMatrix(const in float i) {\n float size = cc_jointsTextureSize.x;\n float j = i * 4.;\n float x = mod(j, size);\n float y = floor(j / size);\n float dx = 1. / size;\n float dy = 1. / size;\n y = dy * (y + .5);\n vec4 v1 = texture(cc_jointsTexture, vec2(dx * (x + .5), y));\n vec4 v2 = texture(cc_jointsTexture, vec2(dx * (x + 1.5), y));\n vec4 v3 = texture(cc_jointsTexture, vec2(dx * (x + 2.5), y));\n vec4 v4 = texture(cc_jointsTexture, vec2(dx * (x + 3.5), y));\n return mat4(v1, v2, v3, v4);\n}\n#endif \n#endif\n#if CC_BINDPOSE_COMPUTATION_DEFERED\nhighp mat4 skinMatrix() {\n#if CC_SUPPORT_TEXEL_FETCH\n ivec4 joints = ivec4(int(a_joints.x), int(a_joints.y), int(a_joints.z),\n int(a_joints.w));\n return getBoneMatrix(joints.x * 2 + 1) * getBoneMatrix(joints.x * 2 + 0) *\n a_weights.x +\n getBoneMatrix(joints.y * 2 + 1) * getBoneMatrix(joints.y * 2 + 0) *\n a_weights.y +\n getBoneMatrix(joints.z * 2 + 1) * getBoneMatrix(joints.z * 2 + 0) *\n a_weights.z +\n getBoneMatrix(joints.w * 2 + 1) * getBoneMatrix(joints.w * 2 + 0) *\n a_weights.w;\n#else\n return getBoneMatrix(a_joints.x * 2. + 1.) *\n getBoneMatrix(a_joints.x * 2. + 0.) * a_weights.x +\n getBoneMatrix(a_joints.y * 2. + 1.) *\n getBoneMatrix(a_joints.y * 2. + 0.) * a_weights.y +\n getBoneMatrix(a_joints.z * 2. + 1.) *\n getBoneMatrix(a_joints.z * 2. + 0.) * a_weights.z +\n getBoneMatrix(a_joints.w * 2. + 1.) *\n getBoneMatrix(a_joints.w * 2. + 0.) * a_weights.w;\n#endif\n}\n#else\nhighp mat4 skinMatrix() {\n#if CC_SUPPORT_TEXEL_FETCH\n ivec4 joints = ivec4(int(a_joints.x), int(a_joints.y), int(a_joints.z),\n int(a_joints.w));\n return getBoneMatrix(joints.x) * a_weights.x +\n getBoneMatrix(joints.y) * a_weights.y +\n getBoneMatrix(joints.z) * a_weights.z +\n getBoneMatrix(joints.w) * a_weights.w;\n#else\n return getBoneMatrix(a_joints.x) * a_weights.x +\n getBoneMatrix(a_joints.y) * a_weights.y +\n getBoneMatrix(a_joints.z) * a_weights.z +\n getBoneMatrix(a_joints.w) * a_weights.w;\n#endif\n}\n#endif\n#else\nmat4 getBoneMatrix(const in float i) {\n vec4 _0 = cc_matJoint[3 * int(i) + 0];\n vec4 _1 = cc_matJoint[3 * int(i) + 1];\n vec4 _2 = cc_matJoint[3 * int(i) + 2];\n return mat4(vec4(_0.x, _0.y, _0.z, 0), vec4(_0.w, _1.x, _1.y, 0),\n vec4(_1.z, _1.w, _2.x, 0), vec4(_2.y, _2.z, _2.w, 1));\n}\nmat4 skinMatrix() {\n return getBoneMatrix(a_joints.x) * a_weights.x +\n getBoneMatrix(a_joints.y) * a_weights.y +\n getBoneMatrix(a_joints.z) * a_weights.z +\n getBoneMatrix(a_joints.w) * a_weights.w;\n}\n#endif\nvoid skinVertex(inout highp vec4 a1) {\n highp mat4 m = skinMatrix();\n a1 = m * a1;\n}\nvoid skinVertex(inout highp vec4 a1, inout vec4 a2) {\n highp mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n}\nvoid skinVertex(inout highp vec4 a1, inout vec4 a2, inout vec4 a3) {\n highp mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n a3 = m * a3;\n}\n#endif\nin vec3 a_position;\nin vec3 a_normal;\nin vec4 a_tangent;\nout vec3 v_worldPos;\nout vec3 v_worldNormal;\n#if USE_ALBEDO_MAP || USE_NORMAL_MAP || USE_PBR_MAP || USE_EMISSIVE_MAP\n in vec2 a_texCoord;\n out vec2 v_uv;\n#endif\n#if USE_NORMAL_MAP\n out vec3 v_tangent;\n#endif\nvec4 vert () {\n vec4 pos = vec4(a_position, 1.0);\n vec4 normal = vec4(a_normal, 0.0);\n #if CC_USE_SKINNING\n skinVertex(pos, normal);\n #else\n pos = cc_matWorld * pos;\n normal = cc_matWorldIT * normal;\n #endif\n v_worldPos = pos.xyz;\n v_worldNormal = normal.xyz;\n #if USE_ALBEDO_MAP || USE_NORMAL_MAP || USE_PBR_MAP || USE_EMISSIVE_MAP\n v_uv = a_texCoord * tilingOffset.xy + tilingOffset.zw;\n #endif\n #if USE_NORMAL_MAP\n v_tangent = (cc_matWorldIT * vec4(a_tangent.xyz, 0.0)).xyz;\n #endif\n return cc_matViewProj * pos;\n}\nvoid main() { gl_Position = vert(); }\n`, + "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};\nuniform CCLocal {\n mat4 cc_matWorld;\n mat4 cc_matWorldIT;\n};\nuniform Constants {\n vec4 tilingOffset;\n vec4 albedo;\n vec4 albedoScale; \n vec4 pbrParams; \n vec4 pbrScale; \n vec4 emissive;\n vec4 emissiveScale;\n};\n#if CC_USE_SKINNING\nin vec4 a_weights;\nin vec4 a_joints;\n#if CC_USE_JOINTS_TEXTURE\nuniform CCSkinningTextureCase {\n vec4 cc_jointsTextureSize;\n};\n#else \nuniform CCSkinning {\n vec4 cc_matJoint[30 * 3];\n};\n#endif\n#if CC_USE_JOINTS_TEXTURE\n \n uniform sampler2D cc_jointsTexture;\n #if CC_JOINTS_TEXTURE_RGBA8\n float decode32(highp vec4 rgba) {\n float Sign = 1.0 - step(128.0, rgba[0]) * 2.0;\n float Exponent = 2.0 * mod(rgba[0], 128.0) + step(128.0, rgba[1]) - 127.0;\n float Mantissa = mod(rgba[1], 128.0) * 65536.0 + rgba[2] * 256.0 + rgba[3] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\n }\n vec4 decodevec4 (highp vec4 x, highp vec4 y, highp vec4 z, highp vec4 w) {\n \n return vec4(\n decode32(x.wzyx * 255.0),\n decode32(y.wzyx * 255.0),\n decode32(z.wzyx * 255.0),\n decode32(w.wzyx * 255.0)\n );\n }\n mat4 getBoneMatrix(const in float i) {\n float size = cc_jointsTextureSize.x;\n float j = i * 16.0;\n float x = mod(j, size);\n float y = floor(j / size);\n float dx = 1.0 / size;\n float dy = 1.0 / size;\n y = dy * (y + 0.5);\n vec4 v1 = decodevec4(\n texture(cc_jointsTexture, vec2(dx * (x + 0.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 1.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 2.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 3.5), y))\n );\n vec4 v2 = decodevec4(\n texture(cc_jointsTexture, vec2(dx * (x + 4.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 5.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 6.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 7.5), y))\n );\n vec4 v3 = decodevec4(\n texture(cc_jointsTexture, vec2(dx * (x + 8.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 9.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 10.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 11.5), y))\n );\n vec4 v4 = decodevec4(\n texture(cc_jointsTexture, vec2(dx * (x + 12.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 13.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 14.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 15.5), y))\n );\n return mat4(v1, v2, v3, v4);\n }\n #else\n mat4 getBoneMatrix(const in float i) {\n float size = cc_jointsTextureSize.x;\n float j = i * 4.0;\n float x = mod(j, size);\n float y = floor(j / size);\n float dx = 1.0 / size;\n float dy = 1.0 / size;\n y = dy * (y + 0.5);\n vec4 v1 = texture(cc_jointsTexture, vec2(dx * (x + 0.5), y));\n vec4 v2 = texture(cc_jointsTexture, vec2(dx * (x + 1.5), y));\n vec4 v3 = texture(cc_jointsTexture, vec2(dx * (x + 2.5), y));\n vec4 v4 = texture(cc_jointsTexture, vec2(dx * (x + 3.5), y));\n return mat4(v1, v2, v3, v4);\n }\n #endif\n #if CC_BINDPOSE_COMPUTATION_DEFERED\n mat4 skinMatrix() {\n return\n getBoneMatrix(a_joints.x * 2.0 + 1.0) * getBoneMatrix(a_joints.x * 2.0 + 0.0) * a_weights.x +\n getBoneMatrix(a_joints.y * 2.0 + 1.0) * getBoneMatrix(a_joints.y * 2.0 + 0.0) * a_weights.y +\n getBoneMatrix(a_joints.z * 2.0 + 1.0) * getBoneMatrix(a_joints.z * 2.0 + 0.0) * a_weights.z +\n getBoneMatrix(a_joints.w * 2.0 + 1.0) * getBoneMatrix(a_joints.w * 2.0 + 0.0) * a_weights.w;\n }\n #else\n mat4 skinMatrix() {\n return\n getBoneMatrix(a_joints.x) * a_weights.x +\n getBoneMatrix(a_joints.y) * a_weights.y +\n getBoneMatrix(a_joints.z) * a_weights.z +\n getBoneMatrix(a_joints.w) * a_weights.w;\n }\n #endif\n#else\n mat4 getBoneMatrix(const in float i) {\n vec4 _0 = cc_matJoint[3 * int(i) + 0];\n vec4 _1 = cc_matJoint[3 * int(i) + 1];\n vec4 _2 = cc_matJoint[3 * int(i) + 2];\n return mat4(\n vec4(_0.x, _0.y, _0.z, 0),\n vec4(_0.w, _1.x, _1.y, 0),\n vec4(_1.z, _1.w, _2.x, 0),\n vec4(_2.y, _2.z, _2.w, 1)\n );\n }\n mat4 skinMatrix() {\n return\n getBoneMatrix(a_joints.x) * a_weights.x +\n getBoneMatrix(a_joints.y) * a_weights.y +\n getBoneMatrix(a_joints.z) * a_weights.z +\n getBoneMatrix(a_joints.w) * a_weights.w;\n }\n#endif\nvoid skinVertex(inout vec4 a1) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n}\nvoid skinVertex(inout vec4 a1, inout vec4 a2) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n}\nvoid skinVertex(inout vec4 a1, inout vec4 a2, inout vec4 a3) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n a3 = m * a3;\n}\n#endif\nin vec3 a_position;\nin vec3 a_normal;\nin vec4 a_tangent;\nout vec3 v_worldPos;\nout vec3 v_worldNormal;\n#if USE_ALBEDO_MAP || USE_NORMAL_MAP || USE_PBR_MAP || USE_EMISSIVE_MAP\n in vec2 a_texCoord;\n out vec2 v_uv;\n#endif\n#if USE_NORMAL_MAP\n out vec3 v_tangent;\n#endif\nvec4 vert () {\n vec4 pos = vec4(a_position, 1.0);\n vec4 normal = vec4(a_normal, 0.0);\n #if CC_USE_SKINNING\n skinVertex(pos, normal);\n #else\n pos = cc_matWorld * pos;\n normal = cc_matWorldIT * normal;\n #endif\n v_worldPos = pos.xyz;\n v_worldNormal = normal.xyz;\n #if USE_ALBEDO_MAP || USE_NORMAL_MAP || USE_PBR_MAP || USE_EMISSIVE_MAP\n v_uv = a_texCoord * tilingOffset.xy + tilingOffset.zw;\n #endif\n #if USE_NORMAL_MAP\n v_tangent = (cc_matWorldIT * vec4(a_tangent.xyz, 0.0)).xyz;\n #endif\n return cc_matViewProj * 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};\n#define MAX_LIGHTS 2\nuniform CCForwardLight {\n vec4 cc_sphereLitPos[2]; \n vec4 cc_sphereLitSizeRange[2]; \n vec4 cc_sphereLitColor[2]; \n vec4 cc_spotLitPos[2]; \n vec4 cc_spotLitSizeRangeAngle[2]; \n vec4 cc_spotLitDir[2]; \n vec4 cc_spotLitColor[2]; \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 0.0009765625\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}\nfloat SmoothDistAtt2(float distSqr, float invSqrAttRadius)\n{\n float factor = distSqr * invSqrAttRadius; \n float factor2 = factor * factor; \n float factor3 = factor2 * factor2; \n float smoothFactor = clamp(1.0 - factor3 * factor3, 0.0, 1.0);\n return smoothFactor * smoothFactor;\n}\nfloat SmoothDistAtt(float distSqr, float invSqrAttRadius)\n{\n float factor = distSqr * invSqrAttRadius;\n float smoothFactor = clamp(1.0 - factor * factor, 0.0, 1.0);\n return smoothFactor * smoothFactor;\n}\nfloat GetDistAtt(float distSqr, float invSqrAttRadius)\n{\n float attenuation = 1.0 / max(distSqr, 0.01*0.01);\n attenuation *= SmoothDistAtt(distSqr , invSqrAttRadius);\n return attenuation;\n}\nfloat GetAngleAtt(vec3 L, vec3 litDir, float litAngleScale, float litAngleOffset)\n{\n float cd = dot(litDir, L);\n float attenuation = clamp(cd * litAngleScale + litAngleOffset, 0.0, 1.0);\n return (attenuation * attenuation);\n}\nfloat GGXMobile(float roughness, float NoH, vec3 H, vec3 N)\n{\n vec3 NxH = cross(N, H);\n float OneMinusNoHSqr = dot(NxH, NxH);\n float a = roughness * roughness;\n float n = NoH * a;\n float p = a / (OneMinusNoHSqr + n * n);\n return p * p;\n}\nfloat CalcSpecular(float roughness, float NoH, vec3 H, vec3 N)\n{\n return (roughness*0.25 + 0.25) * GGXMobile(roughness, NoH, H, N);\n}\nvec3 BRDFApprox(vec3 specular, float roughness, float NoV)\n{\n const vec4 c0 = vec4(-1.0, -0.0275, -0.572, 0.022);\n const vec4 c1 = vec4(1.0, 0.0425, 1.04, -0.04);\n vec4 r = roughness * c0 + c1;\n float a004 = min( r.x * r.x, exp2( -9.28 * NoV ) ) * r.x + r.y;\n vec2 AB = vec2( -1.04, 1.04 ) * a004 + r.zw;\n AB.y *= clamp(50.0 * specular.g, 0.0, 1.0);\n return specular * AB.x + AB.y;\n}\nuniform Constants {\n vec4 tilingOffset;\n vec4 albedo;\n vec4 albedoScale; \n vec4 pbrParams; \n vec4 pbrScale; \n vec4 emissive;\n vec4 emissiveScale;\n};\nin vec3 v_worldPos;\nin vec3 v_worldNormal;\n#if USE_ALBEDO_MAP || USE_NORMAL_MAP || USE_PBR_MAP || USE_EMISSIVE_MAP\n in vec2 v_uv;\n#endif\n#if USE_NORMAL_MAP\n in vec3 v_tangent;\n#endif\n#if USE_ALBEDO_MAP\n uniform sampler2D albedoMap;\n#endif\n#if USE_NORMAL_MAP\n uniform sampler2D normalMap;\n#endif\n#if USE_PBR_MAP\n uniform sampler2D pbrMap;\n#endif\n#if USE_EMISSIVE_MAP\n uniform sampler2D emissiveMap;\n#endif\n#ifdef USE_IBL\n uniform samplerCube envMap;\n#endif\nvec4 frag () {\n #if USE_ALBEDO_MAP\n vec4 baseColor = texture(albedoMap, v_uv) * albedo;\n #else\n vec4 baseColor = albedo;\n #endif\n baseColor.rgb *= albedoScale.rgb;\n baseColor.rgb = SRGBToLinear(baseColor.rgb);\n #if USE_ALPHA_TEST\n if(baseColor.a < albedoScale.a)\n discard;\n #endif\n vec3 N = normalize(v_worldNormal);\n #if USE_NORMAL_MAP\n vec3 normal = texture(normalMap, v_uv).rgb;\n normal = 2.0 * normal.xyz - 1.0;\n vec3 tangent = normalize(v_tangent);\n vec3 binormal = normalize(cross(tangent, N));\n mat3 matTBN = mat3(tangent, binormal, N);\n N = normalize(matTBN * normal);\n #endif\n #if USE_PBR_MAP\n vec4 pbr = texture(pbrMap, v_uv);\n #else\n vec4 pbr = pbrParams;\n #endif\n pbr *= pbrScale;\n float roughness = clamp(pbr.ROUGHNESS_CHANNEL, 0.04, 1.0);\n float metallic = clamp(pbr.METALLIC_CHANNEL, 0.0, 0.96);\n vec3 diffuse = baseColor.rgb * (1.0 - metallic);\n vec3 specular = mix(vec3(0.04), baseColor.rgb, metallic);\n vec3 V = normalize(cc_cameraPos.xyz - v_worldPos);\n vec3 L = normalize(-cc_mainLitDir.xyz);\n vec3 H = normalize(L+V);\n float NV = max(abs(dot(N, V)), 0.001);\n float NL = max(dot(N, L), 0.001);\n float NH = max(dot(N, H), 0.0);\n specular = BRDFApprox(specular, roughness, NV);\n vec3 specularContrib = specular * CalcSpecular(roughness, NH, H, N);\n vec3 diffuseContrib = diffuse / 3.14159265359;\n vec3 finalColor = NL * cc_mainLitColor.rgb * cc_mainLitColor.w * (diffuseContrib + specularContrib);\n for (int i = 0; i < 2; i++) {\n \n vec3 PLU = cc_sphereLitPos[i].xyz - v_worldPos;\n vec3 PL = normalize(PLU);\n vec3 PH = normalize(PL+V);\n float PNL = max(dot(N, PL), 0.001);\n float PNH = max(dot(N, PH), 0.0);\n float distSqr = dot(PLU, PLU);\n float litRadius = cc_sphereLitSizeRange[i].x;\n float litRadiusSqr = litRadius * litRadius;\n float illum = 3.14159265359 * (litRadiusSqr / max(litRadiusSqr , distSqr));\n float attRadiusSqrInv = 1.0 / max(cc_sphereLitSizeRange[i].y, 0.01);\n attRadiusSqrInv *= attRadiusSqrInv;\n float att = GetDistAtt(distSqr, attRadiusSqrInv);\n vec3 lspec = specular * CalcSpecular(roughness, PNH, PH, N);\n finalColor += PNL * cc_sphereLitColor[i].rgb * cc_sphereLitColor[i].w * illum * att * (diffuseContrib + lspec);\n }\n for (int i = 0; i < 2; i++) {\n \n vec3 SLU = cc_spotLitPos[i].xyz - v_worldPos;\n vec3 SL = normalize(SLU);\n vec3 SH = normalize(SL+V);\n float SNL = max(dot(N, SL), 0.001);\n float SNH = max(dot(N, SH), 0.0);\n float distSqr = dot(SLU, SLU);\n float litRadius = cc_spotLitSizeRangeAngle[i].x;\n float litRadiusSqr = litRadius * litRadius;\n float illum = 3.14159265359 * (litRadiusSqr / max(litRadiusSqr , distSqr));\n float attRadiusSqrInv = 1.0 / max(cc_spotLitSizeRangeAngle[i].y, 0.01);\n attRadiusSqrInv *= attRadiusSqrInv;\n float cosInner = max(dot(-cc_spotLitDir[i].xyz, SL), 0.01);\n float cosOuter = cc_spotLitSizeRangeAngle[i].z;\n float litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\n float litAngleOffset = -cosOuter * litAngleScale;\n float att = GetDistAtt(distSqr, attRadiusSqrInv);\n att *= GetAngleAtt(SL, -cc_spotLitDir[i].xyz, litAngleScale, litAngleOffset);\n vec3 lspec = specular * CalcSpecular(roughness, SNH, SH, N);\n finalColor += SNL * cc_spotLitColor[i].rgb * cc_spotLitColor[i].w * illum * att * (diffuseContrib + lspec);\n }\n float fAmb = dot(N, vec3(0.0, -1.0, 0.0)) * 0.5 + 0.5;\n vec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb) * cc_ambientSky.w;\n finalColor += (ambDiff.rgb * diffuse);\n #if USE_IBL\n vec3 R = normalize(reflect(-V, N));\n vec4 env = texture(envMap, R);\n env.rgb = SRGBToLinear(env.rgb) * cc_ambientSky.w;\n finalColor += (env.rgb * specular);\n #endif\n finalColor = mix(finalColor, finalColor * pbr.AO_CHANNEL, pbrParams.z);\n #if USE_EMISSIVE_MAP\n vec3 emissiveColor = texture(emissiveMap, v_uv).rgb;\n emissiveColor = SRGBToLinear(emissiveColor);\n #if CC_USE_HDR\n emissiveColor *= cc_exposure.w;\n #endif\n finalColor += emissiveColor * emissive.rgb * emissiveScale.xyz;\n #endif\n #if !CC_USE_HDR\n finalColor = LinearToSRGB(finalColor);\n #endif\n return vec4(finalColor, baseColor.a);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }\n` }, "glsl1": { - "vert": `\nprecision mediump float;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matWorld;\nuniform mat4 cc_matWorldIT;\nuniform vec4 tilingOffset;\n#if CC_USE_SKINNING\nattribute vec4 a_weights;\nattribute vec4 a_joints;\n#if CC_USE_JOINTS_TEXTURE\nuniform vec4 cc_jointsTextureSize;\n#else \nuniform vec4 cc_matJoint[90];\n#endif\n#if CC_USE_JOINTS_TEXTURE\nuniform sampler2D cc_jointsTexture;\n#if CC_USE_JOINTS_TEXTURE_RGBA8888\nhighp float decode32(highp vec4 rgba) {\n highp float Sign = 1. - step(128., rgba[0]) * 2.;\n highp float Exponent = 2. * mod(rgba[0], 128.) + step(128., rgba[1]) - 127.;\n if (Exponent == -127.) {\n return 0.;\n }\n highp float Mantissa = mod(rgba[1], 128.) * 65536. + rgba[2] * 256. +\n rgba[3] + float(0x800000);\n return Sign * exp2(Exponent - 23.) * Mantissa;\n}\nhighp vec4 decodevec4(highp vec4 x, highp vec4 y, highp vec4 z, highp vec4 w) {\n return vec4(decode32(x * 255.), decode32(y * 255.), decode32(z * 255.),\n decode32(w * 255.));\n}\nhighp mat4 getBoneMatrix(const in float i) {\n float size = cc_jointsTextureSize.x;\n float j = i * 16.;\n float x = mod(j, size);\n float y = floor(j / size);\n float dx = 1. / size;\n float dy = 1. / size;\n y = dy * (y + .5);\n highp vec4 v1 =\n decodevec4(texture2D(cc_jointsTexture, vec2(dx * (x + .5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 1.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 2.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 3.5), y)));\n highp vec4 v2 =\n decodevec4(texture2D(cc_jointsTexture, vec2(dx * (x + 4.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 5.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 6.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 7.5), y)));\n highp vec4 v3 =\n decodevec4(texture2D(cc_jointsTexture, vec2(dx * (x + 8.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 9.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 10.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 11.5), y)));\n highp vec4 v4 =\n decodevec4(texture2D(cc_jointsTexture, vec2(dx * (x + 12.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 13.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 14.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 15.5), y)));\n return mat4(v1, v2, v3, v4);\n}\n#else\n#if CC_SUPPORT_TEXEL_FETCH\nmat4 getBoneMatrix(const in int i) {\n ivec2 size = ivec2(int(cc_jointsTextureSize.x), 0);\n \n int start = i * 4;\n int x = start % size.x;\n int y = start / size.x;\n vec4 v1 = texelFetch(cc_jointsTexture, ivec2(x + 0, y), 0);\n vec4 v2 = texelFetch(cc_jointsTexture, ivec2(x + 1, y), 0);\n vec4 v3 = texelFetch(cc_jointsTexture, ivec2(x + 2, y), 0);\n vec4 v4 = texelFetch(cc_jointsTexture, ivec2(x + 3, y), 0);\n return mat4(v1, v2, v3, v4);\n}\n#else\nmat4 getBoneMatrix(const in float i) {\n float size = cc_jointsTextureSize.x;\n float j = i * 4.;\n float x = mod(j, size);\n float y = floor(j / size);\n float dx = 1. / size;\n float dy = 1. / size;\n y = dy * (y + .5);\n vec4 v1 = texture2D(cc_jointsTexture, vec2(dx * (x + .5), y));\n vec4 v2 = texture2D(cc_jointsTexture, vec2(dx * (x + 1.5), y));\n vec4 v3 = texture2D(cc_jointsTexture, vec2(dx * (x + 2.5), y));\n vec4 v4 = texture2D(cc_jointsTexture, vec2(dx * (x + 3.5), y));\n return mat4(v1, v2, v3, v4);\n}\n#endif \n#endif\n#if CC_BINDPOSE_COMPUTATION_DEFERED\nhighp mat4 skinMatrix() {\n#if CC_SUPPORT_TEXEL_FETCH\n ivec4 joints = ivec4(int(a_joints.x), int(a_joints.y), int(a_joints.z),\n int(a_joints.w));\n return getBoneMatrix(joints.x * 2 + 1) * getBoneMatrix(joints.x * 2 + 0) *\n a_weights.x +\n getBoneMatrix(joints.y * 2 + 1) * getBoneMatrix(joints.y * 2 + 0) *\n a_weights.y +\n getBoneMatrix(joints.z * 2 + 1) * getBoneMatrix(joints.z * 2 + 0) *\n a_weights.z +\n getBoneMatrix(joints.w * 2 + 1) * getBoneMatrix(joints.w * 2 + 0) *\n a_weights.w;\n#else\n return getBoneMatrix(a_joints.x * 2. + 1.) *\n getBoneMatrix(a_joints.x * 2. + 0.) * a_weights.x +\n getBoneMatrix(a_joints.y * 2. + 1.) *\n getBoneMatrix(a_joints.y * 2. + 0.) * a_weights.y +\n getBoneMatrix(a_joints.z * 2. + 1.) *\n getBoneMatrix(a_joints.z * 2. + 0.) * a_weights.z +\n getBoneMatrix(a_joints.w * 2. + 1.) *\n getBoneMatrix(a_joints.w * 2. + 0.) * a_weights.w;\n#endif\n}\n#else\nhighp mat4 skinMatrix() {\n#if CC_SUPPORT_TEXEL_FETCH\n ivec4 joints = ivec4(int(a_joints.x), int(a_joints.y), int(a_joints.z),\n int(a_joints.w));\n return getBoneMatrix(joints.x) * a_weights.x +\n getBoneMatrix(joints.y) * a_weights.y +\n getBoneMatrix(joints.z) * a_weights.z +\n getBoneMatrix(joints.w) * a_weights.w;\n#else\n return getBoneMatrix(a_joints.x) * a_weights.x +\n getBoneMatrix(a_joints.y) * a_weights.y +\n getBoneMatrix(a_joints.z) * a_weights.z +\n getBoneMatrix(a_joints.w) * a_weights.w;\n#endif\n}\n#endif\n#else\nmat4 getBoneMatrix(const in float i) {\n vec4 _0 = cc_matJoint[3 * int(i) + 0];\n vec4 _1 = cc_matJoint[3 * int(i) + 1];\n vec4 _2 = cc_matJoint[3 * int(i) + 2];\n return mat4(vec4(_0.x, _0.y, _0.z, 0), vec4(_0.w, _1.x, _1.y, 0),\n vec4(_1.z, _1.w, _2.x, 0), vec4(_2.y, _2.z, _2.w, 1));\n}\nmat4 skinMatrix() {\n return getBoneMatrix(a_joints.x) * a_weights.x +\n getBoneMatrix(a_joints.y) * a_weights.y +\n getBoneMatrix(a_joints.z) * a_weights.z +\n getBoneMatrix(a_joints.w) * a_weights.w;\n}\n#endif\nvoid skinVertex(inout highp vec4 a1) {\n highp mat4 m = skinMatrix();\n a1 = m * a1;\n}\nvoid skinVertex(inout highp vec4 a1, inout vec4 a2) {\n highp mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n}\nvoid skinVertex(inout highp vec4 a1, inout vec4 a2, inout vec4 a3) {\n highp mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n a3 = m * a3;\n}\n#endif\nattribute vec3 a_position;\nattribute vec3 a_normal;\nattribute vec4 a_tangent;\nvarying vec3 v_worldPos;\nvarying vec3 v_worldNormal;\n#if USE_ALBEDO_MAP || USE_NORMAL_MAP || USE_PBR_MAP || USE_EMISSIVE_MAP\n attribute vec2 a_texCoord;\n varying vec2 v_uv;\n#endif\n#if USE_NORMAL_MAP\n varying vec3 v_tangent;\n#endif\nvec4 vert () {\n vec4 pos = vec4(a_position, 1.0);\n vec4 normal = vec4(a_normal, 0.0);\n #if CC_USE_SKINNING\n skinVertex(pos, normal);\n #else\n pos = cc_matWorld * pos;\n normal = cc_matWorldIT * normal;\n #endif\n v_worldPos = pos.xyz;\n v_worldNormal = normal.xyz;\n #if USE_ALBEDO_MAP || USE_NORMAL_MAP || USE_PBR_MAP || USE_EMISSIVE_MAP\n v_uv = a_texCoord * tilingOffset.xy + tilingOffset.zw;\n #endif\n #if USE_NORMAL_MAP\n v_tangent = (cc_matWorldIT * vec4(a_tangent.xyz, 0.0)).xyz;\n #endif\n return cc_matViewProj * pos;\n}\nvoid main() { gl_Position = vert(); }\n`, + "vert": `\nprecision mediump float;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matWorld;\nuniform mat4 cc_matWorldIT;\nuniform vec4 tilingOffset;\n#if CC_USE_SKINNING\nattribute vec4 a_weights;\nattribute vec4 a_joints;\n#if CC_USE_JOINTS_TEXTURE\nuniform vec4 cc_jointsTextureSize;\n#else \nuniform vec4 cc_matJoint[90];\n#endif\n#if CC_USE_JOINTS_TEXTURE\n \n uniform sampler2D cc_jointsTexture;\n #if CC_JOINTS_TEXTURE_RGBA8\n float decode32(highp vec4 rgba) {\n float Sign = 1.0 - step(128.0, rgba[0]) * 2.0;\n float Exponent = 2.0 * mod(rgba[0], 128.0) + step(128.0, rgba[1]) - 127.0;\n float Mantissa = mod(rgba[1], 128.0) * 65536.0 + rgba[2] * 256.0 + rgba[3] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\n }\n vec4 decodevec4 (highp vec4 x, highp vec4 y, highp vec4 z, highp vec4 w) {\n \n return vec4(\n decode32(x.wzyx * 255.0),\n decode32(y.wzyx * 255.0),\n decode32(z.wzyx * 255.0),\n decode32(w.wzyx * 255.0)\n );\n }\n mat4 getBoneMatrix(const in float i) {\n float size = cc_jointsTextureSize.x;\n float j = i * 16.0;\n float x = mod(j, size);\n float y = floor(j / size);\n float dx = 1.0 / size;\n float dy = 1.0 / size;\n y = dy * (y + 0.5);\n vec4 v1 = decodevec4(\n texture2D(cc_jointsTexture, vec2(dx * (x + 0.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 1.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 2.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 3.5), y))\n );\n vec4 v2 = decodevec4(\n texture2D(cc_jointsTexture, vec2(dx * (x + 4.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 5.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 6.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 7.5), y))\n );\n vec4 v3 = decodevec4(\n texture2D(cc_jointsTexture, vec2(dx * (x + 8.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 9.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 10.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 11.5), y))\n );\n vec4 v4 = decodevec4(\n texture2D(cc_jointsTexture, vec2(dx * (x + 12.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 13.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 14.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 15.5), y))\n );\n return mat4(v1, v2, v3, v4);\n }\n #else\n mat4 getBoneMatrix(const in float i) {\n float size = cc_jointsTextureSize.x;\n float j = i * 4.0;\n float x = mod(j, size);\n float y = floor(j / size);\n float dx = 1.0 / size;\n float dy = 1.0 / size;\n y = dy * (y + 0.5);\n vec4 v1 = texture2D(cc_jointsTexture, vec2(dx * (x + 0.5), y));\n vec4 v2 = texture2D(cc_jointsTexture, vec2(dx * (x + 1.5), y));\n vec4 v3 = texture2D(cc_jointsTexture, vec2(dx * (x + 2.5), y));\n vec4 v4 = texture2D(cc_jointsTexture, vec2(dx * (x + 3.5), y));\n return mat4(v1, v2, v3, v4);\n }\n #endif\n #if CC_BINDPOSE_COMPUTATION_DEFERED\n mat4 skinMatrix() {\n return\n getBoneMatrix(a_joints.x * 2.0 + 1.0) * getBoneMatrix(a_joints.x * 2.0 + 0.0) * a_weights.x +\n getBoneMatrix(a_joints.y * 2.0 + 1.0) * getBoneMatrix(a_joints.y * 2.0 + 0.0) * a_weights.y +\n getBoneMatrix(a_joints.z * 2.0 + 1.0) * getBoneMatrix(a_joints.z * 2.0 + 0.0) * a_weights.z +\n getBoneMatrix(a_joints.w * 2.0 + 1.0) * getBoneMatrix(a_joints.w * 2.0 + 0.0) * a_weights.w;\n }\n #else\n mat4 skinMatrix() {\n return\n getBoneMatrix(a_joints.x) * a_weights.x +\n getBoneMatrix(a_joints.y) * a_weights.y +\n getBoneMatrix(a_joints.z) * a_weights.z +\n getBoneMatrix(a_joints.w) * a_weights.w;\n }\n #endif\n#else\n mat4 getBoneMatrix(const in float i) {\n vec4 _0 = cc_matJoint[3 * int(i) + 0];\n vec4 _1 = cc_matJoint[3 * int(i) + 1];\n vec4 _2 = cc_matJoint[3 * int(i) + 2];\n return mat4(\n vec4(_0.x, _0.y, _0.z, 0),\n vec4(_0.w, _1.x, _1.y, 0),\n vec4(_1.z, _1.w, _2.x, 0),\n vec4(_2.y, _2.z, _2.w, 1)\n );\n }\n mat4 skinMatrix() {\n return\n getBoneMatrix(a_joints.x) * a_weights.x +\n getBoneMatrix(a_joints.y) * a_weights.y +\n getBoneMatrix(a_joints.z) * a_weights.z +\n getBoneMatrix(a_joints.w) * a_weights.w;\n }\n#endif\nvoid skinVertex(inout vec4 a1) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n}\nvoid skinVertex(inout vec4 a1, inout vec4 a2) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n}\nvoid skinVertex(inout vec4 a1, inout vec4 a2, inout vec4 a3) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n a3 = m * a3;\n}\n#endif\nattribute vec3 a_position;\nattribute vec3 a_normal;\nattribute vec4 a_tangent;\nvarying vec3 v_worldPos;\nvarying vec3 v_worldNormal;\n#if USE_ALBEDO_MAP || USE_NORMAL_MAP || USE_PBR_MAP || USE_EMISSIVE_MAP\n attribute vec2 a_texCoord;\n varying vec2 v_uv;\n#endif\n#if USE_NORMAL_MAP\n varying vec3 v_tangent;\n#endif\nvec4 vert () {\n vec4 pos = vec4(a_position, 1.0);\n vec4 normal = vec4(a_normal, 0.0);\n #if CC_USE_SKINNING\n skinVertex(pos, normal);\n #else\n pos = cc_matWorld * pos;\n normal = cc_matWorldIT * normal;\n #endif\n v_worldPos = pos.xyz;\n v_worldNormal = normal.xyz;\n #if USE_ALBEDO_MAP || USE_NORMAL_MAP || USE_PBR_MAP || USE_EMISSIVE_MAP\n v_uv = a_texCoord * tilingOffset.xy + tilingOffset.zw;\n #endif\n #if USE_NORMAL_MAP\n v_tangent = (cc_matWorldIT * vec4(a_tangent.xyz, 0.0)).xyz;\n #endif\n return cc_matViewProj * pos;\n}\nvoid main() { gl_Position = vert(); }\n`, "frag": `\nprecision mediump float;\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 MAX_LIGHTS 2\nuniform vec4 cc_sphereLitPos[2];\nuniform vec4 cc_sphereLitSizeRange[2];\nuniform vec4 cc_sphereLitColor[2];\nuniform vec4 cc_spotLitPos[2];\nuniform vec4 cc_spotLitSizeRangeAngle[2];\nuniform vec4 cc_spotLitDir[2];\nuniform vec4 cc_spotLitColor[2];\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 0.0009765625\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}\nfloat SmoothDistAtt2(float distSqr, float invSqrAttRadius)\n{\n float factor = distSqr * invSqrAttRadius; \n float factor2 = factor * factor; \n float factor3 = factor2 * factor2; \n float smoothFactor = clamp(1.0 - factor3 * factor3, 0.0, 1.0);\n return smoothFactor * smoothFactor;\n}\nfloat SmoothDistAtt(float distSqr, float invSqrAttRadius)\n{\n float factor = distSqr * invSqrAttRadius;\n float smoothFactor = clamp(1.0 - factor * factor, 0.0, 1.0);\n return smoothFactor * smoothFactor;\n}\nfloat GetDistAtt(float distSqr, float invSqrAttRadius)\n{\n float attenuation = 1.0 / max(distSqr, 0.01*0.01);\n attenuation *= SmoothDistAtt(distSqr , invSqrAttRadius);\n return attenuation;\n}\nfloat GetAngleAtt(vec3 L, vec3 litDir, float litAngleScale, float litAngleOffset)\n{\n float cd = dot(litDir, L);\n float attenuation = clamp(cd * litAngleScale + litAngleOffset, 0.0, 1.0);\n return (attenuation * attenuation);\n}\nfloat GGXMobile(float roughness, float NoH, vec3 H, vec3 N)\n{\n vec3 NxH = cross(N, H);\n float OneMinusNoHSqr = dot(NxH, NxH);\n float a = roughness * roughness;\n float n = NoH * a;\n float p = a / (OneMinusNoHSqr + n * n);\n return p * p;\n}\nfloat CalcSpecular(float roughness, float NoH, vec3 H, vec3 N)\n{\n return (roughness*0.25 + 0.25) * GGXMobile(roughness, NoH, H, N);\n}\nvec3 BRDFApprox(vec3 specular, float roughness, float NoV)\n{\n const vec4 c0 = vec4(-1.0, -0.0275, -0.572, 0.022);\n const vec4 c1 = vec4(1.0, 0.0425, 1.04, -0.04);\n vec4 r = roughness * c0 + c1;\n float a004 = min( r.x * r.x, exp2( -9.28 * NoV ) ) * r.x + r.y;\n vec2 AB = vec2( -1.04, 1.04 ) * a004 + r.zw;\n AB.y *= clamp(50.0 * specular.g, 0.0, 1.0);\n return specular * AB.x + AB.y;\n}\nuniform vec4 albedo;\nuniform vec4 albedoScale;\nuniform vec4 pbrParams;\nuniform vec4 pbrScale;\nuniform vec4 emissive;\nuniform vec4 emissiveScale;\nvarying vec3 v_worldPos;\nvarying vec3 v_worldNormal;\n#if USE_ALBEDO_MAP || USE_NORMAL_MAP || USE_PBR_MAP || USE_EMISSIVE_MAP\n varying vec2 v_uv;\n#endif\n#if USE_NORMAL_MAP\n varying vec3 v_tangent;\n#endif\n#if USE_ALBEDO_MAP\n uniform sampler2D albedoMap;\n#endif\n#if USE_NORMAL_MAP\n uniform sampler2D normalMap;\n#endif\n#if USE_PBR_MAP\n uniform sampler2D pbrMap;\n#endif\n#if USE_EMISSIVE_MAP\n uniform sampler2D emissiveMap;\n#endif\n#ifdef USE_IBL\n uniform samplerCube envMap;\n#endif\nvec4 frag () {\n #if USE_ALBEDO_MAP\n vec4 baseColor = texture2D(albedoMap, v_uv) * albedo;\n #else\n vec4 baseColor = albedo;\n #endif\n baseColor.rgb *= albedoScale.rgb;\n baseColor.rgb = SRGBToLinear(baseColor.rgb);\n #if USE_ALPHA_TEST\n if(baseColor.a < albedoScale.a)\n discard;\n #endif\n vec3 N = normalize(v_worldNormal);\n #if USE_NORMAL_MAP\n vec3 normal = texture2D(normalMap, v_uv).rgb;\n normal = 2.0 * normal.xyz - 1.0;\n vec3 tangent = normalize(v_tangent);\n vec3 binormal = normalize(cross(tangent, N));\n mat3 matTBN = mat3(tangent, binormal, N);\n N = normalize(matTBN * normal);\n #endif\n #if USE_PBR_MAP\n vec4 pbr = texture2D(pbrMap, v_uv);\n #else\n vec4 pbr = pbrParams;\n #endif\n pbr *= pbrScale;\n float roughness = clamp(pbr.ROUGHNESS_CHANNEL, 0.04, 1.0);\n float metallic = clamp(pbr.METALLIC_CHANNEL, 0.0, 0.96);\n vec3 diffuse = baseColor.rgb * (1.0 - metallic);\n vec3 specular = mix(vec3(0.04), baseColor.rgb, metallic);\n vec3 V = normalize(cc_cameraPos.xyz - v_worldPos);\n vec3 L = normalize(-cc_mainLitDir.xyz);\n vec3 H = normalize(L+V);\n float NV = max(abs(dot(N, V)), 0.001);\n float NL = max(dot(N, L), 0.001);\n float NH = max(dot(N, H), 0.0);\n specular = BRDFApprox(specular, roughness, NV);\n vec3 specularContrib = specular * CalcSpecular(roughness, NH, H, N);\n vec3 diffuseContrib = diffuse / 3.14159265359;\n vec3 finalColor = NL * cc_mainLitColor.rgb * cc_mainLitColor.w * (diffuseContrib + specularContrib);\n for (int i = 0; i < 2; i++) {\n \n vec3 PLU = cc_sphereLitPos[i].xyz - v_worldPos;\n vec3 PL = normalize(PLU);\n vec3 PH = normalize(PL+V);\n float PNL = max(dot(N, PL), 0.001);\n float PNH = max(dot(N, PH), 0.0);\n float distSqr = dot(PLU, PLU);\n float litRadius = cc_sphereLitSizeRange[i].x;\n float litRadiusSqr = litRadius * litRadius;\n float illum = 3.14159265359 * (litRadiusSqr / max(litRadiusSqr , distSqr));\n float attRadiusSqrInv = 1.0 / max(cc_sphereLitSizeRange[i].y, 0.01);\n attRadiusSqrInv *= attRadiusSqrInv;\n float att = GetDistAtt(distSqr, attRadiusSqrInv);\n vec3 lspec = specular * CalcSpecular(roughness, PNH, PH, N);\n finalColor += PNL * cc_sphereLitColor[i].rgb * cc_sphereLitColor[i].w * illum * att * (diffuseContrib + lspec);\n }\n for (int i = 0; i < 2; i++) {\n \n vec3 SLU = cc_spotLitPos[i].xyz - v_worldPos;\n vec3 SL = normalize(SLU);\n vec3 SH = normalize(SL+V);\n float SNL = max(dot(N, SL), 0.001);\n float SNH = max(dot(N, SH), 0.0);\n float distSqr = dot(SLU, SLU);\n float litRadius = cc_spotLitSizeRangeAngle[i].x;\n float litRadiusSqr = litRadius * litRadius;\n float illum = 3.14159265359 * (litRadiusSqr / max(litRadiusSqr , distSqr));\n float attRadiusSqrInv = 1.0 / max(cc_spotLitSizeRangeAngle[i].y, 0.01);\n attRadiusSqrInv *= attRadiusSqrInv;\n float cosInner = max(dot(-cc_spotLitDir[i].xyz, SL), 0.01);\n float cosOuter = cc_spotLitSizeRangeAngle[i].z;\n float litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\n float litAngleOffset = -cosOuter * litAngleScale;\n float att = GetDistAtt(distSqr, attRadiusSqrInv);\n att *= GetAngleAtt(SL, -cc_spotLitDir[i].xyz, litAngleScale, litAngleOffset);\n vec3 lspec = specular * CalcSpecular(roughness, SNH, SH, N);\n finalColor += SNL * cc_spotLitColor[i].rgb * cc_spotLitColor[i].w * illum * att * (diffuseContrib + lspec);\n }\n float fAmb = dot(N, vec3(0.0, -1.0, 0.0)) * 0.5 + 0.5;\n vec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb) * cc_ambientSky.w;\n finalColor += (ambDiff.rgb * diffuse);\n #if USE_IBL\n vec3 R = normalize(reflect(-V, N));\n vec4 env = textureCube(envMap, R);\n env.rgb = SRGBToLinear(env.rgb) * cc_ambientSky.w;\n finalColor += (env.rgb * specular);\n #endif\n finalColor = mix(finalColor, finalColor * pbr.AO_CHANNEL, pbrParams.z);\n #if USE_EMISSIVE_MAP\n vec3 emissiveColor = texture2D(emissiveMap, v_uv).rgb;\n emissiveColor = SRGBToLinear(emissiveColor);\n #if CC_USE_HDR\n emissiveColor *= cc_exposure.w;\n #endif\n finalColor += emissiveColor * emissive.rgb * emissiveScale.xyz;\n #endif\n #if !CC_USE_HDR\n finalColor = LinearToSRGB(finalColor);\n #endif\n return vec4(finalColor, baseColor.a);\n}\nvoid main() { gl_FragColor = frag(); }\n` }, "builtins": {"globals":{"blocks":["CCGlobal"], "samplers":[]}, "locals":{"blocks":["CCLocal", "CCSkinningTextureCase", "CCSkinning", "CCForwardLight"], "samplers":["cc_jointsTexture"]}}, "defines": [ {"name":"CC_USE_SKINNING", "type":"boolean", "defines":[]}, {"name":"CC_USE_JOINTS_TEXTURE", "type":"boolean", "defines":["CC_USE_SKINNING"]}, - {"name":"CC_USE_JOINTS_TEXTURE_RGBA8888", "type":"boolean", "defines":["CC_USE_SKINNING", "CC_USE_JOINTS_TEXTURE"]}, - {"name":"CC_SUPPORT_TEXEL_FETCH", "type":"boolean", "defines":["CC_USE_SKINNING", "CC_USE_JOINTS_TEXTURE"]}, + {"name":"CC_JOINTS_TEXTURE_RGBA8", "type":"boolean", "defines":["CC_USE_SKINNING", "CC_USE_JOINTS_TEXTURE"]}, {"name":"CC_BINDPOSE_COMPUTATION_DEFERED", "type":"boolean", "defines":["CC_USE_SKINNING", "CC_USE_JOINTS_TEXTURE"]}, {"name":"USE_ALBEDO_MAP", "type":"boolean", "defines":[]}, {"name":"USE_NORMAL_MAP", "type":"boolean", "defines":[]}, @@ -160,21 +201,20 @@ export default [ }, { "name": "builtin-standard|planar-shadow-vs:vert|planar-shadow-fs:frag", - "hash": 1895262330, + "hash": 3684747021, "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};\nuniform CCLocal {\n mat4 cc_matWorld;\n mat4 cc_matWorldIT;\n};\nuniform CCShadow {\n mat4 cc_matLightPlaneProj;\n vec4 cc_shadowColor;\n};\n#if CC_USE_SKINNING\nin vec4 a_weights;\nin vec4 a_joints;\n#if CC_USE_JOINTS_TEXTURE\nuniform CCSkinningTextureCase {\n vec4 cc_jointsTextureSize;\n};\n#else \nuniform CCSkinning {\n vec4 cc_matJoint[30 * 3];\n};\n#endif\n#if CC_USE_JOINTS_TEXTURE\nuniform sampler2D cc_jointsTexture;\n#if CC_USE_JOINTS_TEXTURE_RGBA8888\nhighp float decode32(highp vec4 rgba) {\n highp float Sign = 1. - step(128., rgba[0]) * 2.;\n highp float Exponent = 2. * mod(rgba[0], 128.) + step(128., rgba[1]) - 127.;\n if (Exponent == -127.) {\n return 0.;\n }\n highp float Mantissa = mod(rgba[1], 128.) * 65536. + rgba[2] * 256. +\n rgba[3] + float(0x800000);\n return Sign * exp2(Exponent - 23.) * Mantissa;\n}\nhighp vec4 decodevec4(highp vec4 x, highp vec4 y, highp vec4 z, highp vec4 w) {\n return vec4(decode32(x * 255.), decode32(y * 255.), decode32(z * 255.),\n decode32(w * 255.));\n}\nhighp mat4 getBoneMatrix(const in float i) {\n float size = cc_jointsTextureSize.x;\n float j = i * 16.;\n float x = mod(j, size);\n float y = floor(j / size);\n float dx = 1. / size;\n float dy = 1. / size;\n y = dy * (y + .5);\n highp vec4 v1 =\n decodevec4(texture(cc_jointsTexture, vec2(dx * (x + .5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 1.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 2.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 3.5), y)));\n highp vec4 v2 =\n decodevec4(texture(cc_jointsTexture, vec2(dx * (x + 4.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 5.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 6.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 7.5), y)));\n highp vec4 v3 =\n decodevec4(texture(cc_jointsTexture, vec2(dx * (x + 8.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 9.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 10.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 11.5), y)));\n highp vec4 v4 =\n decodevec4(texture(cc_jointsTexture, vec2(dx * (x + 12.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 13.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 14.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 15.5), y)));\n return mat4(v1, v2, v3, v4);\n}\n#else\n#if CC_SUPPORT_TEXEL_FETCH\nmat4 getBoneMatrix(const in int i) {\n ivec2 size = ivec2(int(cc_jointsTextureSize.x), 0);\n \n int start = i * 4;\n int x = start % size.x;\n int y = start / size.x;\n vec4 v1 = texelFetch(cc_jointsTexture, ivec2(x + 0, y), 0);\n vec4 v2 = texelFetch(cc_jointsTexture, ivec2(x + 1, y), 0);\n vec4 v3 = texelFetch(cc_jointsTexture, ivec2(x + 2, y), 0);\n vec4 v4 = texelFetch(cc_jointsTexture, ivec2(x + 3, y), 0);\n return mat4(v1, v2, v3, v4);\n}\n#else\nmat4 getBoneMatrix(const in float i) {\n float size = cc_jointsTextureSize.x;\n float j = i * 4.;\n float x = mod(j, size);\n float y = floor(j / size);\n float dx = 1. / size;\n float dy = 1. / size;\n y = dy * (y + .5);\n vec4 v1 = texture(cc_jointsTexture, vec2(dx * (x + .5), y));\n vec4 v2 = texture(cc_jointsTexture, vec2(dx * (x + 1.5), y));\n vec4 v3 = texture(cc_jointsTexture, vec2(dx * (x + 2.5), y));\n vec4 v4 = texture(cc_jointsTexture, vec2(dx * (x + 3.5), y));\n return mat4(v1, v2, v3, v4);\n}\n#endif \n#endif\n#if CC_BINDPOSE_COMPUTATION_DEFERED\nhighp mat4 skinMatrix() {\n#if CC_SUPPORT_TEXEL_FETCH\n ivec4 joints = ivec4(int(a_joints.x), int(a_joints.y), int(a_joints.z),\n int(a_joints.w));\n return getBoneMatrix(joints.x * 2 + 1) * getBoneMatrix(joints.x * 2 + 0) *\n a_weights.x +\n getBoneMatrix(joints.y * 2 + 1) * getBoneMatrix(joints.y * 2 + 0) *\n a_weights.y +\n getBoneMatrix(joints.z * 2 + 1) * getBoneMatrix(joints.z * 2 + 0) *\n a_weights.z +\n getBoneMatrix(joints.w * 2 + 1) * getBoneMatrix(joints.w * 2 + 0) *\n a_weights.w;\n#else\n return getBoneMatrix(a_joints.x * 2. + 1.) *\n getBoneMatrix(a_joints.x * 2. + 0.) * a_weights.x +\n getBoneMatrix(a_joints.y * 2. + 1.) *\n getBoneMatrix(a_joints.y * 2. + 0.) * a_weights.y +\n getBoneMatrix(a_joints.z * 2. + 1.) *\n getBoneMatrix(a_joints.z * 2. + 0.) * a_weights.z +\n getBoneMatrix(a_joints.w * 2. + 1.) *\n getBoneMatrix(a_joints.w * 2. + 0.) * a_weights.w;\n#endif\n}\n#else\nhighp mat4 skinMatrix() {\n#if CC_SUPPORT_TEXEL_FETCH\n ivec4 joints = ivec4(int(a_joints.x), int(a_joints.y), int(a_joints.z),\n int(a_joints.w));\n return getBoneMatrix(joints.x) * a_weights.x +\n getBoneMatrix(joints.y) * a_weights.y +\n getBoneMatrix(joints.z) * a_weights.z +\n getBoneMatrix(joints.w) * a_weights.w;\n#else\n return getBoneMatrix(a_joints.x) * a_weights.x +\n getBoneMatrix(a_joints.y) * a_weights.y +\n getBoneMatrix(a_joints.z) * a_weights.z +\n getBoneMatrix(a_joints.w) * a_weights.w;\n#endif\n}\n#endif\n#else\nmat4 getBoneMatrix(const in float i) {\n vec4 _0 = cc_matJoint[3 * int(i) + 0];\n vec4 _1 = cc_matJoint[3 * int(i) + 1];\n vec4 _2 = cc_matJoint[3 * int(i) + 2];\n return mat4(vec4(_0.x, _0.y, _0.z, 0), vec4(_0.w, _1.x, _1.y, 0),\n vec4(_1.z, _1.w, _2.x, 0), vec4(_2.y, _2.z, _2.w, 1));\n}\nmat4 skinMatrix() {\n return getBoneMatrix(a_joints.x) * a_weights.x +\n getBoneMatrix(a_joints.y) * a_weights.y +\n getBoneMatrix(a_joints.z) * a_weights.z +\n getBoneMatrix(a_joints.w) * a_weights.w;\n}\n#endif\nvoid skinVertex(inout highp vec4 a1) {\n highp mat4 m = skinMatrix();\n a1 = m * a1;\n}\nvoid skinVertex(inout highp vec4 a1, inout vec4 a2) {\n highp mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n}\nvoid skinVertex(inout highp vec4 a1, inout vec4 a2, inout vec4 a3) {\n highp mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n a3 = m * a3;\n}\n#endif\nin vec3 a_position;\nvec4 vert () {\n vec4 pos = vec4(a_position, 1);\n #if CC_USE_SKINNING\n skinVertex(pos);\n #else\n pos = cc_matWorld * pos;\n #endif\n pos = cc_matViewProj * cc_matLightPlaneProj * pos;\n pos.z -= 0.0001;\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n`, + "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};\nuniform CCLocal {\n mat4 cc_matWorld;\n mat4 cc_matWorldIT;\n};\nuniform CCShadow {\n mat4 cc_matLightPlaneProj;\n vec4 cc_shadowColor;\n};\n#if CC_USE_SKINNING\nin vec4 a_weights;\nin vec4 a_joints;\n#if CC_USE_JOINTS_TEXTURE\nuniform CCSkinningTextureCase {\n vec4 cc_jointsTextureSize;\n};\n#else \nuniform CCSkinning {\n vec4 cc_matJoint[30 * 3];\n};\n#endif\n#if CC_USE_JOINTS_TEXTURE\n \n uniform sampler2D cc_jointsTexture;\n #if CC_JOINTS_TEXTURE_RGBA8\n float decode32(highp vec4 rgba) {\n float Sign = 1.0 - step(128.0, rgba[0]) * 2.0;\n float Exponent = 2.0 * mod(rgba[0], 128.0) + step(128.0, rgba[1]) - 127.0;\n float Mantissa = mod(rgba[1], 128.0) * 65536.0 + rgba[2] * 256.0 + rgba[3] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\n }\n vec4 decodevec4 (highp vec4 x, highp vec4 y, highp vec4 z, highp vec4 w) {\n \n return vec4(\n decode32(x.wzyx * 255.0),\n decode32(y.wzyx * 255.0),\n decode32(z.wzyx * 255.0),\n decode32(w.wzyx * 255.0)\n );\n }\n mat4 getBoneMatrix(const in float i) {\n float size = cc_jointsTextureSize.x;\n float j = i * 16.0;\n float x = mod(j, size);\n float y = floor(j / size);\n float dx = 1.0 / size;\n float dy = 1.0 / size;\n y = dy * (y + 0.5);\n vec4 v1 = decodevec4(\n texture(cc_jointsTexture, vec2(dx * (x + 0.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 1.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 2.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 3.5), y))\n );\n vec4 v2 = decodevec4(\n texture(cc_jointsTexture, vec2(dx * (x + 4.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 5.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 6.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 7.5), y))\n );\n vec4 v3 = decodevec4(\n texture(cc_jointsTexture, vec2(dx * (x + 8.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 9.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 10.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 11.5), y))\n );\n vec4 v4 = decodevec4(\n texture(cc_jointsTexture, vec2(dx * (x + 12.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 13.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 14.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 15.5), y))\n );\n return mat4(v1, v2, v3, v4);\n }\n #else\n mat4 getBoneMatrix(const in float i) {\n float size = cc_jointsTextureSize.x;\n float j = i * 4.0;\n float x = mod(j, size);\n float y = floor(j / size);\n float dx = 1.0 / size;\n float dy = 1.0 / size;\n y = dy * (y + 0.5);\n vec4 v1 = texture(cc_jointsTexture, vec2(dx * (x + 0.5), y));\n vec4 v2 = texture(cc_jointsTexture, vec2(dx * (x + 1.5), y));\n vec4 v3 = texture(cc_jointsTexture, vec2(dx * (x + 2.5), y));\n vec4 v4 = texture(cc_jointsTexture, vec2(dx * (x + 3.5), y));\n return mat4(v1, v2, v3, v4);\n }\n #endif\n #if CC_BINDPOSE_COMPUTATION_DEFERED\n mat4 skinMatrix() {\n return\n getBoneMatrix(a_joints.x * 2.0 + 1.0) * getBoneMatrix(a_joints.x * 2.0 + 0.0) * a_weights.x +\n getBoneMatrix(a_joints.y * 2.0 + 1.0) * getBoneMatrix(a_joints.y * 2.0 + 0.0) * a_weights.y +\n getBoneMatrix(a_joints.z * 2.0 + 1.0) * getBoneMatrix(a_joints.z * 2.0 + 0.0) * a_weights.z +\n getBoneMatrix(a_joints.w * 2.0 + 1.0) * getBoneMatrix(a_joints.w * 2.0 + 0.0) * a_weights.w;\n }\n #else\n mat4 skinMatrix() {\n return\n getBoneMatrix(a_joints.x) * a_weights.x +\n getBoneMatrix(a_joints.y) * a_weights.y +\n getBoneMatrix(a_joints.z) * a_weights.z +\n getBoneMatrix(a_joints.w) * a_weights.w;\n }\n #endif\n#else\n mat4 getBoneMatrix(const in float i) {\n vec4 _0 = cc_matJoint[3 * int(i) + 0];\n vec4 _1 = cc_matJoint[3 * int(i) + 1];\n vec4 _2 = cc_matJoint[3 * int(i) + 2];\n return mat4(\n vec4(_0.x, _0.y, _0.z, 0),\n vec4(_0.w, _1.x, _1.y, 0),\n vec4(_1.z, _1.w, _2.x, 0),\n vec4(_2.y, _2.z, _2.w, 1)\n );\n }\n mat4 skinMatrix() {\n return\n getBoneMatrix(a_joints.x) * a_weights.x +\n getBoneMatrix(a_joints.y) * a_weights.y +\n getBoneMatrix(a_joints.z) * a_weights.z +\n getBoneMatrix(a_joints.w) * a_weights.w;\n }\n#endif\nvoid skinVertex(inout vec4 a1) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n}\nvoid skinVertex(inout vec4 a1, inout vec4 a2) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n}\nvoid skinVertex(inout vec4 a1, inout vec4 a2, inout vec4 a3) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n a3 = m * a3;\n}\n#endif\nin vec3 a_position;\nvec4 vert () {\n vec4 pos = vec4(a_position, 1);\n #if CC_USE_SKINNING\n skinVertex(pos);\n #else\n pos = cc_matWorld * pos;\n #endif\n pos = cc_matViewProj * cc_matLightPlaneProj * pos;\n pos.z -= 0.0001;\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n`, "frag": `\nprecision mediump float;\nuniform CCShadow {\n mat4 cc_matLightPlaneProj;\n vec4 cc_shadowColor;\n};\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}\nvec4 frag () {\n return PostProcess(cc_shadowColor);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }\n` }, "glsl1": { - "vert": `\nprecision mediump float;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matWorld;\nuniform mat4 cc_matLightPlaneProj;\n#if CC_USE_SKINNING\nattribute vec4 a_weights;\nattribute vec4 a_joints;\n#if CC_USE_JOINTS_TEXTURE\nuniform vec4 cc_jointsTextureSize;\n#else \nuniform vec4 cc_matJoint[90];\n#endif\n#if CC_USE_JOINTS_TEXTURE\nuniform sampler2D cc_jointsTexture;\n#if CC_USE_JOINTS_TEXTURE_RGBA8888\nhighp float decode32(highp vec4 rgba) {\n highp float Sign = 1. - step(128., rgba[0]) * 2.;\n highp float Exponent = 2. * mod(rgba[0], 128.) + step(128., rgba[1]) - 127.;\n if (Exponent == -127.) {\n return 0.;\n }\n highp float Mantissa = mod(rgba[1], 128.) * 65536. + rgba[2] * 256. +\n rgba[3] + float(0x800000);\n return Sign * exp2(Exponent - 23.) * Mantissa;\n}\nhighp vec4 decodevec4(highp vec4 x, highp vec4 y, highp vec4 z, highp vec4 w) {\n return vec4(decode32(x * 255.), decode32(y * 255.), decode32(z * 255.),\n decode32(w * 255.));\n}\nhighp mat4 getBoneMatrix(const in float i) {\n float size = cc_jointsTextureSize.x;\n float j = i * 16.;\n float x = mod(j, size);\n float y = floor(j / size);\n float dx = 1. / size;\n float dy = 1. / size;\n y = dy * (y + .5);\n highp vec4 v1 =\n decodevec4(texture2D(cc_jointsTexture, vec2(dx * (x + .5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 1.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 2.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 3.5), y)));\n highp vec4 v2 =\n decodevec4(texture2D(cc_jointsTexture, vec2(dx * (x + 4.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 5.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 6.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 7.5), y)));\n highp vec4 v3 =\n decodevec4(texture2D(cc_jointsTexture, vec2(dx * (x + 8.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 9.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 10.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 11.5), y)));\n highp vec4 v4 =\n decodevec4(texture2D(cc_jointsTexture, vec2(dx * (x + 12.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 13.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 14.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 15.5), y)));\n return mat4(v1, v2, v3, v4);\n}\n#else\n#if CC_SUPPORT_TEXEL_FETCH\nmat4 getBoneMatrix(const in int i) {\n ivec2 size = ivec2(int(cc_jointsTextureSize.x), 0);\n \n int start = i * 4;\n int x = start % size.x;\n int y = start / size.x;\n vec4 v1 = texelFetch(cc_jointsTexture, ivec2(x + 0, y), 0);\n vec4 v2 = texelFetch(cc_jointsTexture, ivec2(x + 1, y), 0);\n vec4 v3 = texelFetch(cc_jointsTexture, ivec2(x + 2, y), 0);\n vec4 v4 = texelFetch(cc_jointsTexture, ivec2(x + 3, y), 0);\n return mat4(v1, v2, v3, v4);\n}\n#else\nmat4 getBoneMatrix(const in float i) {\n float size = cc_jointsTextureSize.x;\n float j = i * 4.;\n float x = mod(j, size);\n float y = floor(j / size);\n float dx = 1. / size;\n float dy = 1. / size;\n y = dy * (y + .5);\n vec4 v1 = texture2D(cc_jointsTexture, vec2(dx * (x + .5), y));\n vec4 v2 = texture2D(cc_jointsTexture, vec2(dx * (x + 1.5), y));\n vec4 v3 = texture2D(cc_jointsTexture, vec2(dx * (x + 2.5), y));\n vec4 v4 = texture2D(cc_jointsTexture, vec2(dx * (x + 3.5), y));\n return mat4(v1, v2, v3, v4);\n}\n#endif \n#endif\n#if CC_BINDPOSE_COMPUTATION_DEFERED\nhighp mat4 skinMatrix() {\n#if CC_SUPPORT_TEXEL_FETCH\n ivec4 joints = ivec4(int(a_joints.x), int(a_joints.y), int(a_joints.z),\n int(a_joints.w));\n return getBoneMatrix(joints.x * 2 + 1) * getBoneMatrix(joints.x * 2 + 0) *\n a_weights.x +\n getBoneMatrix(joints.y * 2 + 1) * getBoneMatrix(joints.y * 2 + 0) *\n a_weights.y +\n getBoneMatrix(joints.z * 2 + 1) * getBoneMatrix(joints.z * 2 + 0) *\n a_weights.z +\n getBoneMatrix(joints.w * 2 + 1) * getBoneMatrix(joints.w * 2 + 0) *\n a_weights.w;\n#else\n return getBoneMatrix(a_joints.x * 2. + 1.) *\n getBoneMatrix(a_joints.x * 2. + 0.) * a_weights.x +\n getBoneMatrix(a_joints.y * 2. + 1.) *\n getBoneMatrix(a_joints.y * 2. + 0.) * a_weights.y +\n getBoneMatrix(a_joints.z * 2. + 1.) *\n getBoneMatrix(a_joints.z * 2. + 0.) * a_weights.z +\n getBoneMatrix(a_joints.w * 2. + 1.) *\n getBoneMatrix(a_joints.w * 2. + 0.) * a_weights.w;\n#endif\n}\n#else\nhighp mat4 skinMatrix() {\n#if CC_SUPPORT_TEXEL_FETCH\n ivec4 joints = ivec4(int(a_joints.x), int(a_joints.y), int(a_joints.z),\n int(a_joints.w));\n return getBoneMatrix(joints.x) * a_weights.x +\n getBoneMatrix(joints.y) * a_weights.y +\n getBoneMatrix(joints.z) * a_weights.z +\n getBoneMatrix(joints.w) * a_weights.w;\n#else\n return getBoneMatrix(a_joints.x) * a_weights.x +\n getBoneMatrix(a_joints.y) * a_weights.y +\n getBoneMatrix(a_joints.z) * a_weights.z +\n getBoneMatrix(a_joints.w) * a_weights.w;\n#endif\n}\n#endif\n#else\nmat4 getBoneMatrix(const in float i) {\n vec4 _0 = cc_matJoint[3 * int(i) + 0];\n vec4 _1 = cc_matJoint[3 * int(i) + 1];\n vec4 _2 = cc_matJoint[3 * int(i) + 2];\n return mat4(vec4(_0.x, _0.y, _0.z, 0), vec4(_0.w, _1.x, _1.y, 0),\n vec4(_1.z, _1.w, _2.x, 0), vec4(_2.y, _2.z, _2.w, 1));\n}\nmat4 skinMatrix() {\n return getBoneMatrix(a_joints.x) * a_weights.x +\n getBoneMatrix(a_joints.y) * a_weights.y +\n getBoneMatrix(a_joints.z) * a_weights.z +\n getBoneMatrix(a_joints.w) * a_weights.w;\n}\n#endif\nvoid skinVertex(inout highp vec4 a1) {\n highp mat4 m = skinMatrix();\n a1 = m * a1;\n}\nvoid skinVertex(inout highp vec4 a1, inout vec4 a2) {\n highp mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n}\nvoid skinVertex(inout highp vec4 a1, inout vec4 a2, inout vec4 a3) {\n highp mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n a3 = m * a3;\n}\n#endif\nattribute vec3 a_position;\nvec4 vert () {\n vec4 pos = vec4(a_position, 1);\n #if CC_USE_SKINNING\n skinVertex(pos);\n #else\n pos = cc_matWorld * pos;\n #endif\n pos = cc_matViewProj * cc_matLightPlaneProj * pos;\n pos.z -= 0.0001;\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n`, + "vert": `\nprecision mediump float;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matWorld;\nuniform mat4 cc_matLightPlaneProj;\n#if CC_USE_SKINNING\nattribute vec4 a_weights;\nattribute vec4 a_joints;\n#if CC_USE_JOINTS_TEXTURE\nuniform vec4 cc_jointsTextureSize;\n#else \nuniform vec4 cc_matJoint[90];\n#endif\n#if CC_USE_JOINTS_TEXTURE\n \n uniform sampler2D cc_jointsTexture;\n #if CC_JOINTS_TEXTURE_RGBA8\n float decode32(highp vec4 rgba) {\n float Sign = 1.0 - step(128.0, rgba[0]) * 2.0;\n float Exponent = 2.0 * mod(rgba[0], 128.0) + step(128.0, rgba[1]) - 127.0;\n float Mantissa = mod(rgba[1], 128.0) * 65536.0 + rgba[2] * 256.0 + rgba[3] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\n }\n vec4 decodevec4 (highp vec4 x, highp vec4 y, highp vec4 z, highp vec4 w) {\n \n return vec4(\n decode32(x.wzyx * 255.0),\n decode32(y.wzyx * 255.0),\n decode32(z.wzyx * 255.0),\n decode32(w.wzyx * 255.0)\n );\n }\n mat4 getBoneMatrix(const in float i) {\n float size = cc_jointsTextureSize.x;\n float j = i * 16.0;\n float x = mod(j, size);\n float y = floor(j / size);\n float dx = 1.0 / size;\n float dy = 1.0 / size;\n y = dy * (y + 0.5);\n vec4 v1 = decodevec4(\n texture2D(cc_jointsTexture, vec2(dx * (x + 0.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 1.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 2.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 3.5), y))\n );\n vec4 v2 = decodevec4(\n texture2D(cc_jointsTexture, vec2(dx * (x + 4.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 5.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 6.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 7.5), y))\n );\n vec4 v3 = decodevec4(\n texture2D(cc_jointsTexture, vec2(dx * (x + 8.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 9.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 10.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 11.5), y))\n );\n vec4 v4 = decodevec4(\n texture2D(cc_jointsTexture, vec2(dx * (x + 12.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 13.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 14.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 15.5), y))\n );\n return mat4(v1, v2, v3, v4);\n }\n #else\n mat4 getBoneMatrix(const in float i) {\n float size = cc_jointsTextureSize.x;\n float j = i * 4.0;\n float x = mod(j, size);\n float y = floor(j / size);\n float dx = 1.0 / size;\n float dy = 1.0 / size;\n y = dy * (y + 0.5);\n vec4 v1 = texture2D(cc_jointsTexture, vec2(dx * (x + 0.5), y));\n vec4 v2 = texture2D(cc_jointsTexture, vec2(dx * (x + 1.5), y));\n vec4 v3 = texture2D(cc_jointsTexture, vec2(dx * (x + 2.5), y));\n vec4 v4 = texture2D(cc_jointsTexture, vec2(dx * (x + 3.5), y));\n return mat4(v1, v2, v3, v4);\n }\n #endif\n #if CC_BINDPOSE_COMPUTATION_DEFERED\n mat4 skinMatrix() {\n return\n getBoneMatrix(a_joints.x * 2.0 + 1.0) * getBoneMatrix(a_joints.x * 2.0 + 0.0) * a_weights.x +\n getBoneMatrix(a_joints.y * 2.0 + 1.0) * getBoneMatrix(a_joints.y * 2.0 + 0.0) * a_weights.y +\n getBoneMatrix(a_joints.z * 2.0 + 1.0) * getBoneMatrix(a_joints.z * 2.0 + 0.0) * a_weights.z +\n getBoneMatrix(a_joints.w * 2.0 + 1.0) * getBoneMatrix(a_joints.w * 2.0 + 0.0) * a_weights.w;\n }\n #else\n mat4 skinMatrix() {\n return\n getBoneMatrix(a_joints.x) * a_weights.x +\n getBoneMatrix(a_joints.y) * a_weights.y +\n getBoneMatrix(a_joints.z) * a_weights.z +\n getBoneMatrix(a_joints.w) * a_weights.w;\n }\n #endif\n#else\n mat4 getBoneMatrix(const in float i) {\n vec4 _0 = cc_matJoint[3 * int(i) + 0];\n vec4 _1 = cc_matJoint[3 * int(i) + 1];\n vec4 _2 = cc_matJoint[3 * int(i) + 2];\n return mat4(\n vec4(_0.x, _0.y, _0.z, 0),\n vec4(_0.w, _1.x, _1.y, 0),\n vec4(_1.z, _1.w, _2.x, 0),\n vec4(_2.y, _2.z, _2.w, 1)\n );\n }\n mat4 skinMatrix() {\n return\n getBoneMatrix(a_joints.x) * a_weights.x +\n getBoneMatrix(a_joints.y) * a_weights.y +\n getBoneMatrix(a_joints.z) * a_weights.z +\n getBoneMatrix(a_joints.w) * a_weights.w;\n }\n#endif\nvoid skinVertex(inout vec4 a1) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n}\nvoid skinVertex(inout vec4 a1, inout vec4 a2) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n}\nvoid skinVertex(inout vec4 a1, inout vec4 a2, inout vec4 a3) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n a3 = m * a3;\n}\n#endif\nattribute vec3 a_position;\nvec4 vert () {\n vec4 pos = vec4(a_position, 1);\n #if CC_USE_SKINNING\n skinVertex(pos);\n #else\n pos = cc_matWorld * pos;\n #endif\n pos = cc_matViewProj * cc_matLightPlaneProj * pos;\n pos.z -= 0.0001;\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n`, "frag": `\nprecision mediump float;\nuniform vec4 cc_shadowColor;\nuniform vec4 cc_exposure;\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}\nvec4 frag () {\n return PostProcess(cc_shadowColor);\n}\nvoid main() { gl_FragColor = frag(); }\n` }, "builtins": {"globals":{"blocks":["CCGlobal", "CCShadow"], "samplers":[]}, "locals":{"blocks":["CCLocal", "CCSkinningTextureCase", "CCSkinning"], "samplers":["cc_jointsTexture"]}}, "defines": [ {"name":"CC_USE_SKINNING", "type":"boolean", "defines":[]}, {"name":"CC_USE_JOINTS_TEXTURE", "type":"boolean", "defines":["CC_USE_SKINNING"]}, - {"name":"CC_USE_JOINTS_TEXTURE_RGBA8888", "type":"boolean", "defines":["CC_USE_SKINNING", "CC_USE_JOINTS_TEXTURE"]}, - {"name":"CC_SUPPORT_TEXEL_FETCH", "type":"boolean", "defines":["CC_USE_SKINNING", "CC_USE_JOINTS_TEXTURE"]}, + {"name":"CC_JOINTS_TEXTURE_RGBA8", "type":"boolean", "defines":["CC_USE_SKINNING", "CC_USE_JOINTS_TEXTURE"]}, {"name":"CC_BINDPOSE_COMPUTATION_DEFERED", "type":"boolean", "defines":["CC_USE_SKINNING", "CC_USE_JOINTS_TEXTURE"]}, {"name":"CC_USE_HDR", "type":"boolean", "defines":[]} ], @@ -192,21 +232,20 @@ export default [ "shaders": [ { "name": "builtin-unlit|unlit-vs:vert|unlit-fs:frag", - "hash": 3614457750, + "hash": 2744730382, "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};\nuniform CCLocal {\n mat4 cc_matWorld;\n mat4 cc_matWorldIT;\n};\n#if CC_USE_SKINNING\nin vec4 a_weights;\nin vec4 a_joints;\n#if CC_USE_JOINTS_TEXTURE\nuniform CCSkinningTextureCase {\n vec4 cc_jointsTextureSize;\n};\n#else \nuniform CCSkinning {\n vec4 cc_matJoint[30 * 3];\n};\n#endif\n#if CC_USE_JOINTS_TEXTURE\nuniform sampler2D cc_jointsTexture;\n#if CC_USE_JOINTS_TEXTURE_RGBA8888\nhighp float decode32(highp vec4 rgba) {\n highp float Sign = 1. - step(128., rgba[0]) * 2.;\n highp float Exponent = 2. * mod(rgba[0], 128.) + step(128., rgba[1]) - 127.;\n if (Exponent == -127.) {\n return 0.;\n }\n highp float Mantissa = mod(rgba[1], 128.) * 65536. + rgba[2] * 256. +\n rgba[3] + float(0x800000);\n return Sign * exp2(Exponent - 23.) * Mantissa;\n}\nhighp vec4 decodevec4(highp vec4 x, highp vec4 y, highp vec4 z, highp vec4 w) {\n return vec4(decode32(x * 255.), decode32(y * 255.), decode32(z * 255.),\n decode32(w * 255.));\n}\nhighp mat4 getBoneMatrix(const in float i) {\n float size = cc_jointsTextureSize.x;\n float j = i * 16.;\n float x = mod(j, size);\n float y = floor(j / size);\n float dx = 1. / size;\n float dy = 1. / size;\n y = dy * (y + .5);\n highp vec4 v1 =\n decodevec4(texture(cc_jointsTexture, vec2(dx * (x + .5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 1.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 2.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 3.5), y)));\n highp vec4 v2 =\n decodevec4(texture(cc_jointsTexture, vec2(dx * (x + 4.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 5.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 6.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 7.5), y)));\n highp vec4 v3 =\n decodevec4(texture(cc_jointsTexture, vec2(dx * (x + 8.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 9.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 10.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 11.5), y)));\n highp vec4 v4 =\n decodevec4(texture(cc_jointsTexture, vec2(dx * (x + 12.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 13.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 14.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 15.5), y)));\n return mat4(v1, v2, v3, v4);\n}\n#else\n#if CC_SUPPORT_TEXEL_FETCH\nmat4 getBoneMatrix(const in int i) {\n ivec2 size = ivec2(int(cc_jointsTextureSize.x), 0);\n \n int start = i * 4;\n int x = start % size.x;\n int y = start / size.x;\n vec4 v1 = texelFetch(cc_jointsTexture, ivec2(x + 0, y), 0);\n vec4 v2 = texelFetch(cc_jointsTexture, ivec2(x + 1, y), 0);\n vec4 v3 = texelFetch(cc_jointsTexture, ivec2(x + 2, y), 0);\n vec4 v4 = texelFetch(cc_jointsTexture, ivec2(x + 3, y), 0);\n return mat4(v1, v2, v3, v4);\n}\n#else\nmat4 getBoneMatrix(const in float i) {\n float size = cc_jointsTextureSize.x;\n float j = i * 4.;\n float x = mod(j, size);\n float y = floor(j / size);\n float dx = 1. / size;\n float dy = 1. / size;\n y = dy * (y + .5);\n vec4 v1 = texture(cc_jointsTexture, vec2(dx * (x + .5), y));\n vec4 v2 = texture(cc_jointsTexture, vec2(dx * (x + 1.5), y));\n vec4 v3 = texture(cc_jointsTexture, vec2(dx * (x + 2.5), y));\n vec4 v4 = texture(cc_jointsTexture, vec2(dx * (x + 3.5), y));\n return mat4(v1, v2, v3, v4);\n}\n#endif \n#endif\n#if CC_BINDPOSE_COMPUTATION_DEFERED\nhighp mat4 skinMatrix() {\n#if CC_SUPPORT_TEXEL_FETCH\n ivec4 joints = ivec4(int(a_joints.x), int(a_joints.y), int(a_joints.z),\n int(a_joints.w));\n return getBoneMatrix(joints.x * 2 + 1) * getBoneMatrix(joints.x * 2 + 0) *\n a_weights.x +\n getBoneMatrix(joints.y * 2 + 1) * getBoneMatrix(joints.y * 2 + 0) *\n a_weights.y +\n getBoneMatrix(joints.z * 2 + 1) * getBoneMatrix(joints.z * 2 + 0) *\n a_weights.z +\n getBoneMatrix(joints.w * 2 + 1) * getBoneMatrix(joints.w * 2 + 0) *\n a_weights.w;\n#else\n return getBoneMatrix(a_joints.x * 2. + 1.) *\n getBoneMatrix(a_joints.x * 2. + 0.) * a_weights.x +\n getBoneMatrix(a_joints.y * 2. + 1.) *\n getBoneMatrix(a_joints.y * 2. + 0.) * a_weights.y +\n getBoneMatrix(a_joints.z * 2. + 1.) *\n getBoneMatrix(a_joints.z * 2. + 0.) * a_weights.z +\n getBoneMatrix(a_joints.w * 2. + 1.) *\n getBoneMatrix(a_joints.w * 2. + 0.) * a_weights.w;\n#endif\n}\n#else\nhighp mat4 skinMatrix() {\n#if CC_SUPPORT_TEXEL_FETCH\n ivec4 joints = ivec4(int(a_joints.x), int(a_joints.y), int(a_joints.z),\n int(a_joints.w));\n return getBoneMatrix(joints.x) * a_weights.x +\n getBoneMatrix(joints.y) * a_weights.y +\n getBoneMatrix(joints.z) * a_weights.z +\n getBoneMatrix(joints.w) * a_weights.w;\n#else\n return getBoneMatrix(a_joints.x) * a_weights.x +\n getBoneMatrix(a_joints.y) * a_weights.y +\n getBoneMatrix(a_joints.z) * a_weights.z +\n getBoneMatrix(a_joints.w) * a_weights.w;\n#endif\n}\n#endif\n#else\nmat4 getBoneMatrix(const in float i) {\n vec4 _0 = cc_matJoint[3 * int(i) + 0];\n vec4 _1 = cc_matJoint[3 * int(i) + 1];\n vec4 _2 = cc_matJoint[3 * int(i) + 2];\n return mat4(vec4(_0.x, _0.y, _0.z, 0), vec4(_0.w, _1.x, _1.y, 0),\n vec4(_1.z, _1.w, _2.x, 0), vec4(_2.y, _2.z, _2.w, 1));\n}\nmat4 skinMatrix() {\n return getBoneMatrix(a_joints.x) * a_weights.x +\n getBoneMatrix(a_joints.y) * a_weights.y +\n getBoneMatrix(a_joints.z) * a_weights.z +\n getBoneMatrix(a_joints.w) * a_weights.w;\n}\n#endif\nvoid skinVertex(inout highp vec4 a1) {\n highp mat4 m = skinMatrix();\n a1 = m * a1;\n}\nvoid skinVertex(inout highp vec4 a1, inout vec4 a2) {\n highp mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n}\nvoid skinVertex(inout highp vec4 a1, inout vec4 a2, inout vec4 a3) {\n highp mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n a3 = m * a3;\n}\n#endif\nin vec3 a_position;\n#if USE_TEXTURE\n in vec2 a_texCoord;\n out vec2 uv0;\n uniform TexCoords {\n vec4 tilingOffset;\n };\n#endif\nvec4 vert () {\n vec4 pos = vec4(a_position, 1);\n #if CC_USE_SKINNING\n skinVertex(pos);\n #else\n pos = cc_matWorld * pos;\n #endif\n pos = cc_matViewProj * pos;\n #if USE_TEXTURE\n uv0 = a_texCoord * tilingOffset.xy + tilingOffset.zw;\n #endif\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n`, + "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};\nuniform CCLocal {\n mat4 cc_matWorld;\n mat4 cc_matWorldIT;\n};\n#if CC_USE_SKINNING\nin vec4 a_weights;\nin vec4 a_joints;\n#if CC_USE_JOINTS_TEXTURE\nuniform CCSkinningTextureCase {\n vec4 cc_jointsTextureSize;\n};\n#else \nuniform CCSkinning {\n vec4 cc_matJoint[30 * 3];\n};\n#endif\n#if CC_USE_JOINTS_TEXTURE\n \n uniform sampler2D cc_jointsTexture;\n #if CC_JOINTS_TEXTURE_RGBA8\n float decode32(highp vec4 rgba) {\n float Sign = 1.0 - step(128.0, rgba[0]) * 2.0;\n float Exponent = 2.0 * mod(rgba[0], 128.0) + step(128.0, rgba[1]) - 127.0;\n float Mantissa = mod(rgba[1], 128.0) * 65536.0 + rgba[2] * 256.0 + rgba[3] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\n }\n vec4 decodevec4 (highp vec4 x, highp vec4 y, highp vec4 z, highp vec4 w) {\n \n return vec4(\n decode32(x.wzyx * 255.0),\n decode32(y.wzyx * 255.0),\n decode32(z.wzyx * 255.0),\n decode32(w.wzyx * 255.0)\n );\n }\n mat4 getBoneMatrix(const in float i) {\n float size = cc_jointsTextureSize.x;\n float j = i * 16.0;\n float x = mod(j, size);\n float y = floor(j / size);\n float dx = 1.0 / size;\n float dy = 1.0 / size;\n y = dy * (y + 0.5);\n vec4 v1 = decodevec4(\n texture(cc_jointsTexture, vec2(dx * (x + 0.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 1.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 2.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 3.5), y))\n );\n vec4 v2 = decodevec4(\n texture(cc_jointsTexture, vec2(dx * (x + 4.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 5.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 6.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 7.5), y))\n );\n vec4 v3 = decodevec4(\n texture(cc_jointsTexture, vec2(dx * (x + 8.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 9.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 10.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 11.5), y))\n );\n vec4 v4 = decodevec4(\n texture(cc_jointsTexture, vec2(dx * (x + 12.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 13.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 14.5), y)),\n texture(cc_jointsTexture, vec2(dx * (x + 15.5), y))\n );\n return mat4(v1, v2, v3, v4);\n }\n #else\n mat4 getBoneMatrix(const in float i) {\n float size = cc_jointsTextureSize.x;\n float j = i * 4.0;\n float x = mod(j, size);\n float y = floor(j / size);\n float dx = 1.0 / size;\n float dy = 1.0 / size;\n y = dy * (y + 0.5);\n vec4 v1 = texture(cc_jointsTexture, vec2(dx * (x + 0.5), y));\n vec4 v2 = texture(cc_jointsTexture, vec2(dx * (x + 1.5), y));\n vec4 v3 = texture(cc_jointsTexture, vec2(dx * (x + 2.5), y));\n vec4 v4 = texture(cc_jointsTexture, vec2(dx * (x + 3.5), y));\n return mat4(v1, v2, v3, v4);\n }\n #endif\n #if CC_BINDPOSE_COMPUTATION_DEFERED\n mat4 skinMatrix() {\n return\n getBoneMatrix(a_joints.x * 2.0 + 1.0) * getBoneMatrix(a_joints.x * 2.0 + 0.0) * a_weights.x +\n getBoneMatrix(a_joints.y * 2.0 + 1.0) * getBoneMatrix(a_joints.y * 2.0 + 0.0) * a_weights.y +\n getBoneMatrix(a_joints.z * 2.0 + 1.0) * getBoneMatrix(a_joints.z * 2.0 + 0.0) * a_weights.z +\n getBoneMatrix(a_joints.w * 2.0 + 1.0) * getBoneMatrix(a_joints.w * 2.0 + 0.0) * a_weights.w;\n }\n #else\n mat4 skinMatrix() {\n return\n getBoneMatrix(a_joints.x) * a_weights.x +\n getBoneMatrix(a_joints.y) * a_weights.y +\n getBoneMatrix(a_joints.z) * a_weights.z +\n getBoneMatrix(a_joints.w) * a_weights.w;\n }\n #endif\n#else\n mat4 getBoneMatrix(const in float i) {\n vec4 _0 = cc_matJoint[3 * int(i) + 0];\n vec4 _1 = cc_matJoint[3 * int(i) + 1];\n vec4 _2 = cc_matJoint[3 * int(i) + 2];\n return mat4(\n vec4(_0.x, _0.y, _0.z, 0),\n vec4(_0.w, _1.x, _1.y, 0),\n vec4(_1.z, _1.w, _2.x, 0),\n vec4(_2.y, _2.z, _2.w, 1)\n );\n }\n mat4 skinMatrix() {\n return\n getBoneMatrix(a_joints.x) * a_weights.x +\n getBoneMatrix(a_joints.y) * a_weights.y +\n getBoneMatrix(a_joints.z) * a_weights.z +\n getBoneMatrix(a_joints.w) * a_weights.w;\n }\n#endif\nvoid skinVertex(inout vec4 a1) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n}\nvoid skinVertex(inout vec4 a1, inout vec4 a2) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n}\nvoid skinVertex(inout vec4 a1, inout vec4 a2, inout vec4 a3) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n a3 = m * a3;\n}\n#endif\nin vec3 a_position;\n#if USE_TEXTURE\n in vec2 a_texCoord;\n out vec2 uv0;\n uniform TexCoords {\n vec4 tilingOffset;\n };\n#endif\nvec4 vert () {\n vec4 pos = vec4(a_position, 1);\n #if CC_USE_SKINNING\n skinVertex(pos);\n #else\n pos = cc_matWorld * pos;\n #endif\n pos = cc_matViewProj * pos;\n #if USE_TEXTURE\n uv0 = a_texCoord * tilingOffset.xy + tilingOffset.zw;\n #endif\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}\n#if USE_TEXTURE\n in vec2 uv0;\n uniform sampler2D mainTexture;\n#endif\n#if USE_COLOR\n uniform Constant {\n vec4 color;\n };\n#endif\nvec4 frag () {\n vec4 o = vec4(1, 1, 1, 1);\n #if USE_TEXTURE\n o *= texture(mainTexture, uv0);\n #endif\n #if USE_COLOR\n o *= color;\n #endif\n return PostProcess(o);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }\n` }, "glsl1": { - "vert": `\nprecision mediump float;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matWorld;\n#if CC_USE_SKINNING\nattribute vec4 a_weights;\nattribute vec4 a_joints;\n#if CC_USE_JOINTS_TEXTURE\nuniform vec4 cc_jointsTextureSize;\n#else \nuniform vec4 cc_matJoint[90];\n#endif\n#if CC_USE_JOINTS_TEXTURE\nuniform sampler2D cc_jointsTexture;\n#if CC_USE_JOINTS_TEXTURE_RGBA8888\nhighp float decode32(highp vec4 rgba) {\n highp float Sign = 1. - step(128., rgba[0]) * 2.;\n highp float Exponent = 2. * mod(rgba[0], 128.) + step(128., rgba[1]) - 127.;\n if (Exponent == -127.) {\n return 0.;\n }\n highp float Mantissa = mod(rgba[1], 128.) * 65536. + rgba[2] * 256. +\n rgba[3] + float(0x800000);\n return Sign * exp2(Exponent - 23.) * Mantissa;\n}\nhighp vec4 decodevec4(highp vec4 x, highp vec4 y, highp vec4 z, highp vec4 w) {\n return vec4(decode32(x * 255.), decode32(y * 255.), decode32(z * 255.),\n decode32(w * 255.));\n}\nhighp mat4 getBoneMatrix(const in float i) {\n float size = cc_jointsTextureSize.x;\n float j = i * 16.;\n float x = mod(j, size);\n float y = floor(j / size);\n float dx = 1. / size;\n float dy = 1. / size;\n y = dy * (y + .5);\n highp vec4 v1 =\n decodevec4(texture2D(cc_jointsTexture, vec2(dx * (x + .5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 1.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 2.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 3.5), y)));\n highp vec4 v2 =\n decodevec4(texture2D(cc_jointsTexture, vec2(dx * (x + 4.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 5.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 6.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 7.5), y)));\n highp vec4 v3 =\n decodevec4(texture2D(cc_jointsTexture, vec2(dx * (x + 8.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 9.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 10.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 11.5), y)));\n highp vec4 v4 =\n decodevec4(texture2D(cc_jointsTexture, vec2(dx * (x + 12.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 13.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 14.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 15.5), y)));\n return mat4(v1, v2, v3, v4);\n}\n#else\n#if CC_SUPPORT_TEXEL_FETCH\nmat4 getBoneMatrix(const in int i) {\n ivec2 size = ivec2(int(cc_jointsTextureSize.x), 0);\n \n int start = i * 4;\n int x = start % size.x;\n int y = start / size.x;\n vec4 v1 = texelFetch(cc_jointsTexture, ivec2(x + 0, y), 0);\n vec4 v2 = texelFetch(cc_jointsTexture, ivec2(x + 1, y), 0);\n vec4 v3 = texelFetch(cc_jointsTexture, ivec2(x + 2, y), 0);\n vec4 v4 = texelFetch(cc_jointsTexture, ivec2(x + 3, y), 0);\n return mat4(v1, v2, v3, v4);\n}\n#else\nmat4 getBoneMatrix(const in float i) {\n float size = cc_jointsTextureSize.x;\n float j = i * 4.;\n float x = mod(j, size);\n float y = floor(j / size);\n float dx = 1. / size;\n float dy = 1. / size;\n y = dy * (y + .5);\n vec4 v1 = texture2D(cc_jointsTexture, vec2(dx * (x + .5), y));\n vec4 v2 = texture2D(cc_jointsTexture, vec2(dx * (x + 1.5), y));\n vec4 v3 = texture2D(cc_jointsTexture, vec2(dx * (x + 2.5), y));\n vec4 v4 = texture2D(cc_jointsTexture, vec2(dx * (x + 3.5), y));\n return mat4(v1, v2, v3, v4);\n}\n#endif \n#endif\n#if CC_BINDPOSE_COMPUTATION_DEFERED\nhighp mat4 skinMatrix() {\n#if CC_SUPPORT_TEXEL_FETCH\n ivec4 joints = ivec4(int(a_joints.x), int(a_joints.y), int(a_joints.z),\n int(a_joints.w));\n return getBoneMatrix(joints.x * 2 + 1) * getBoneMatrix(joints.x * 2 + 0) *\n a_weights.x +\n getBoneMatrix(joints.y * 2 + 1) * getBoneMatrix(joints.y * 2 + 0) *\n a_weights.y +\n getBoneMatrix(joints.z * 2 + 1) * getBoneMatrix(joints.z * 2 + 0) *\n a_weights.z +\n getBoneMatrix(joints.w * 2 + 1) * getBoneMatrix(joints.w * 2 + 0) *\n a_weights.w;\n#else\n return getBoneMatrix(a_joints.x * 2. + 1.) *\n getBoneMatrix(a_joints.x * 2. + 0.) * a_weights.x +\n getBoneMatrix(a_joints.y * 2. + 1.) *\n getBoneMatrix(a_joints.y * 2. + 0.) * a_weights.y +\n getBoneMatrix(a_joints.z * 2. + 1.) *\n getBoneMatrix(a_joints.z * 2. + 0.) * a_weights.z +\n getBoneMatrix(a_joints.w * 2. + 1.) *\n getBoneMatrix(a_joints.w * 2. + 0.) * a_weights.w;\n#endif\n}\n#else\nhighp mat4 skinMatrix() {\n#if CC_SUPPORT_TEXEL_FETCH\n ivec4 joints = ivec4(int(a_joints.x), int(a_joints.y), int(a_joints.z),\n int(a_joints.w));\n return getBoneMatrix(joints.x) * a_weights.x +\n getBoneMatrix(joints.y) * a_weights.y +\n getBoneMatrix(joints.z) * a_weights.z +\n getBoneMatrix(joints.w) * a_weights.w;\n#else\n return getBoneMatrix(a_joints.x) * a_weights.x +\n getBoneMatrix(a_joints.y) * a_weights.y +\n getBoneMatrix(a_joints.z) * a_weights.z +\n getBoneMatrix(a_joints.w) * a_weights.w;\n#endif\n}\n#endif\n#else\nmat4 getBoneMatrix(const in float i) {\n vec4 _0 = cc_matJoint[3 * int(i) + 0];\n vec4 _1 = cc_matJoint[3 * int(i) + 1];\n vec4 _2 = cc_matJoint[3 * int(i) + 2];\n return mat4(vec4(_0.x, _0.y, _0.z, 0), vec4(_0.w, _1.x, _1.y, 0),\n vec4(_1.z, _1.w, _2.x, 0), vec4(_2.y, _2.z, _2.w, 1));\n}\nmat4 skinMatrix() {\n return getBoneMatrix(a_joints.x) * a_weights.x +\n getBoneMatrix(a_joints.y) * a_weights.y +\n getBoneMatrix(a_joints.z) * a_weights.z +\n getBoneMatrix(a_joints.w) * a_weights.w;\n}\n#endif\nvoid skinVertex(inout highp vec4 a1) {\n highp mat4 m = skinMatrix();\n a1 = m * a1;\n}\nvoid skinVertex(inout highp vec4 a1, inout vec4 a2) {\n highp mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n}\nvoid skinVertex(inout highp vec4 a1, inout vec4 a2, inout vec4 a3) {\n highp mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n a3 = m * a3;\n}\n#endif\nattribute vec3 a_position;\n#if USE_TEXTURE\n attribute vec2 a_texCoord;\n varying vec2 uv0;\n uniform vec4 tilingOffset;\n#endif\nvec4 vert () {\n vec4 pos = vec4(a_position, 1);\n #if CC_USE_SKINNING\n skinVertex(pos);\n #else\n pos = cc_matWorld * pos;\n #endif\n pos = cc_matViewProj * pos;\n #if USE_TEXTURE\n uv0 = a_texCoord * tilingOffset.xy + tilingOffset.zw;\n #endif\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n`, + "vert": `\nprecision mediump float;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matWorld;\n#if CC_USE_SKINNING\nattribute vec4 a_weights;\nattribute vec4 a_joints;\n#if CC_USE_JOINTS_TEXTURE\nuniform vec4 cc_jointsTextureSize;\n#else \nuniform vec4 cc_matJoint[90];\n#endif\n#if CC_USE_JOINTS_TEXTURE\n \n uniform sampler2D cc_jointsTexture;\n #if CC_JOINTS_TEXTURE_RGBA8\n float decode32(highp vec4 rgba) {\n float Sign = 1.0 - step(128.0, rgba[0]) * 2.0;\n float Exponent = 2.0 * mod(rgba[0], 128.0) + step(128.0, rgba[1]) - 127.0;\n float Mantissa = mod(rgba[1], 128.0) * 65536.0 + rgba[2] * 256.0 + rgba[3] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\n }\n vec4 decodevec4 (highp vec4 x, highp vec4 y, highp vec4 z, highp vec4 w) {\n \n return vec4(\n decode32(x.wzyx * 255.0),\n decode32(y.wzyx * 255.0),\n decode32(z.wzyx * 255.0),\n decode32(w.wzyx * 255.0)\n );\n }\n mat4 getBoneMatrix(const in float i) {\n float size = cc_jointsTextureSize.x;\n float j = i * 16.0;\n float x = mod(j, size);\n float y = floor(j / size);\n float dx = 1.0 / size;\n float dy = 1.0 / size;\n y = dy * (y + 0.5);\n vec4 v1 = decodevec4(\n texture2D(cc_jointsTexture, vec2(dx * (x + 0.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 1.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 2.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 3.5), y))\n );\n vec4 v2 = decodevec4(\n texture2D(cc_jointsTexture, vec2(dx * (x + 4.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 5.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 6.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 7.5), y))\n );\n vec4 v3 = decodevec4(\n texture2D(cc_jointsTexture, vec2(dx * (x + 8.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 9.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 10.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 11.5), y))\n );\n vec4 v4 = decodevec4(\n texture2D(cc_jointsTexture, vec2(dx * (x + 12.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 13.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 14.5), y)),\n texture2D(cc_jointsTexture, vec2(dx * (x + 15.5), y))\n );\n return mat4(v1, v2, v3, v4);\n }\n #else\n mat4 getBoneMatrix(const in float i) {\n float size = cc_jointsTextureSize.x;\n float j = i * 4.0;\n float x = mod(j, size);\n float y = floor(j / size);\n float dx = 1.0 / size;\n float dy = 1.0 / size;\n y = dy * (y + 0.5);\n vec4 v1 = texture2D(cc_jointsTexture, vec2(dx * (x + 0.5), y));\n vec4 v2 = texture2D(cc_jointsTexture, vec2(dx * (x + 1.5), y));\n vec4 v3 = texture2D(cc_jointsTexture, vec2(dx * (x + 2.5), y));\n vec4 v4 = texture2D(cc_jointsTexture, vec2(dx * (x + 3.5), y));\n return mat4(v1, v2, v3, v4);\n }\n #endif\n #if CC_BINDPOSE_COMPUTATION_DEFERED\n mat4 skinMatrix() {\n return\n getBoneMatrix(a_joints.x * 2.0 + 1.0) * getBoneMatrix(a_joints.x * 2.0 + 0.0) * a_weights.x +\n getBoneMatrix(a_joints.y * 2.0 + 1.0) * getBoneMatrix(a_joints.y * 2.0 + 0.0) * a_weights.y +\n getBoneMatrix(a_joints.z * 2.0 + 1.0) * getBoneMatrix(a_joints.z * 2.0 + 0.0) * a_weights.z +\n getBoneMatrix(a_joints.w * 2.0 + 1.0) * getBoneMatrix(a_joints.w * 2.0 + 0.0) * a_weights.w;\n }\n #else\n mat4 skinMatrix() {\n return\n getBoneMatrix(a_joints.x) * a_weights.x +\n getBoneMatrix(a_joints.y) * a_weights.y +\n getBoneMatrix(a_joints.z) * a_weights.z +\n getBoneMatrix(a_joints.w) * a_weights.w;\n }\n #endif\n#else\n mat4 getBoneMatrix(const in float i) {\n vec4 _0 = cc_matJoint[3 * int(i) + 0];\n vec4 _1 = cc_matJoint[3 * int(i) + 1];\n vec4 _2 = cc_matJoint[3 * int(i) + 2];\n return mat4(\n vec4(_0.x, _0.y, _0.z, 0),\n vec4(_0.w, _1.x, _1.y, 0),\n vec4(_1.z, _1.w, _2.x, 0),\n vec4(_2.y, _2.z, _2.w, 1)\n );\n }\n mat4 skinMatrix() {\n return\n getBoneMatrix(a_joints.x) * a_weights.x +\n getBoneMatrix(a_joints.y) * a_weights.y +\n getBoneMatrix(a_joints.z) * a_weights.z +\n getBoneMatrix(a_joints.w) * a_weights.w;\n }\n#endif\nvoid skinVertex(inout vec4 a1) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n}\nvoid skinVertex(inout vec4 a1, inout vec4 a2) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n}\nvoid skinVertex(inout vec4 a1, inout vec4 a2, inout vec4 a3) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n a3 = m * a3;\n}\n#endif\nattribute vec3 a_position;\n#if USE_TEXTURE\n attribute vec2 a_texCoord;\n varying vec2 uv0;\n uniform vec4 tilingOffset;\n#endif\nvec4 vert () {\n vec4 pos = vec4(a_position, 1);\n #if CC_USE_SKINNING\n skinVertex(pos);\n #else\n pos = cc_matWorld * pos;\n #endif\n pos = cc_matViewProj * pos;\n #if USE_TEXTURE\n uv0 = a_texCoord * tilingOffset.xy + tilingOffset.zw;\n #endif\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n`, "frag": `\nprecision mediump float;\nuniform vec4 cc_exposure;\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}\n#if USE_TEXTURE\n varying vec2 uv0;\n uniform sampler2D mainTexture;\n#endif\n#if USE_COLOR\n uniform vec4 color;\n#endif\nvec4 frag () {\n vec4 o = vec4(1, 1, 1, 1);\n #if USE_TEXTURE\n o *= texture2D(mainTexture, uv0);\n #endif\n #if USE_COLOR\n o *= color;\n #endif\n return PostProcess(o);\n}\nvoid main() { gl_FragColor = frag(); }\n` }, "builtins": {"globals":{"blocks":["CCGlobal"], "samplers":[]}, "locals":{"blocks":["CCLocal", "CCSkinningTextureCase", "CCSkinning"], "samplers":["cc_jointsTexture"]}}, "defines": [ {"name":"CC_USE_SKINNING", "type":"boolean", "defines":[]}, {"name":"CC_USE_JOINTS_TEXTURE", "type":"boolean", "defines":["CC_USE_SKINNING"]}, - {"name":"CC_USE_JOINTS_TEXTURE_RGBA8888", "type":"boolean", "defines":["CC_USE_SKINNING", "CC_USE_JOINTS_TEXTURE"]}, - {"name":"CC_SUPPORT_TEXEL_FETCH", "type":"boolean", "defines":["CC_USE_SKINNING", "CC_USE_JOINTS_TEXTURE"]}, + {"name":"CC_JOINTS_TEXTURE_RGBA8", "type":"boolean", "defines":["CC_USE_SKINNING", "CC_USE_JOINTS_TEXTURE"]}, {"name":"CC_BINDPOSE_COMPUTATION_DEFERED", "type":"boolean", "defines":["CC_USE_SKINNING", "CC_USE_JOINTS_TEXTURE"]}, {"name":"USE_TEXTURE", "type":"boolean", "defines":[]}, {"name":"CC_USE_HDR", "type":"boolean", "defines":[]}, diff --git a/cocos/3d/builtin/init.ts b/cocos/3d/builtin/init.ts index 12de9aff5d..cea9c61828 100644 --- a/cocos/3d/builtin/init.ts +++ b/cocos/3d/builtin/init.ts @@ -174,6 +174,12 @@ class BuiltinResMgr { defaultParticleMtl.initialize({ effectName: 'builtin-particle' }); resources[defaultParticleMtl._uuid] = defaultParticleMtl; + // default particle material + const defaultTrailMtl = new cc.Material(); + defaultTrailMtl._uuid = 'default-trail-material'; + defaultTrailMtl.initialize({ effectName: 'builtin-particle-trail' }); + resources[defaultTrailMtl._uuid] = defaultTrailMtl; + // customization for special effects const tmp = aabb.create(); customizationManager.register('bounds-merge-shadow', { diff --git a/cocos/3d/framework/particle/animator/curve-range.ts b/cocos/3d/framework/particle/animator/curve-range.ts index 4d4569f968..b3106c5eda 100644 --- a/cocos/3d/framework/particle/animator/curve-range.ts +++ b/cocos/3d/framework/particle/animator/curve-range.ts @@ -14,6 +14,8 @@ export const Mode = Enum({ @ccclass('cc.CurveRange') export default class CurveRange { + public static Mode = Mode; + @property({ type: Mode, }) diff --git a/cocos/3d/framework/particle/animator/force-overtime.ts b/cocos/3d/framework/particle/animator/force-overtime.ts index f7ba02d4a5..5cfbfc9b83 100644 --- a/cocos/3d/framework/particle/animator/force-overtime.ts +++ b/cocos/3d/framework/particle/animator/force-overtime.ts @@ -1,7 +1,8 @@ import { CCClass } from '../../../../core/data'; import { ccclass, property } from '../../../../core/data/class-decorator'; import { pseudoRandom, quat, vec3 } from '../../../../core/vmath'; -import { calculateTransform, Space } from '../particle-general-function'; +import { Space } from '../enum'; +import { calculateTransform } from '../particle-general-function'; import CurveRange from './curve-range'; // tslint:disable: max-line-length diff --git a/cocos/3d/framework/particle/animator/gradient-range.ts b/cocos/3d/framework/particle/animator/gradient-range.ts index 3a16fec119..be8b84ff8d 100644 --- a/cocos/3d/framework/particle/animator/gradient-range.ts +++ b/cocos/3d/framework/particle/animator/gradient-range.ts @@ -26,6 +26,8 @@ const Mode = Enum({ @ccclass('cc.GradientRange') export default class GradientRange { + public static Mode = Mode; + @property({ type: Mode, }) diff --git a/cocos/3d/framework/particle/animator/gradient.ts b/cocos/3d/framework/particle/animator/gradient.ts index 14b31d6a62..3c22644ab8 100644 --- a/cocos/3d/framework/particle/animator/gradient.ts +++ b/cocos/3d/framework/particle/animator/gradient.ts @@ -43,6 +43,8 @@ export class AlphaKey { @ccclass('cc.Gradient') export default class Gradient { + public static Mode = Mode; + @property public colorKeys = new Array(); diff --git a/cocos/3d/framework/particle/animator/limit-velocity-overtime.ts b/cocos/3d/framework/particle/animator/limit-velocity-overtime.ts index 1c04585c27..b07ab97d22 100644 --- a/cocos/3d/framework/particle/animator/limit-velocity-overtime.ts +++ b/cocos/3d/framework/particle/animator/limit-velocity-overtime.ts @@ -1,8 +1,8 @@ import { CCClass } from '../../../../core/data'; import { ccclass, property } from '../../../../core/data/class-decorator'; import { lerp, pseudoRandom, vec3 } from '../../../../core/vmath'; +import { Space } from '../enum'; import Particle from '../particle'; -import { Space } from '../particle-general-function'; import CurveRange from './curve-range'; // tslint:disable: max-line-length diff --git a/cocos/3d/framework/particle/animator/velocity-overtime.ts b/cocos/3d/framework/particle/animator/velocity-overtime.ts index 9bc06f719b..d645822d37 100644 --- a/cocos/3d/framework/particle/animator/velocity-overtime.ts +++ b/cocos/3d/framework/particle/animator/velocity-overtime.ts @@ -1,8 +1,9 @@ import { CCClass } from '../../../../core/data'; import { ccclass, property } from '../../../../core/data/class-decorator'; import { mat4, pseudoRandom, quat, vec3 } from '../../../../core/vmath'; +import { Space } from '../enum'; import Particle from '../particle'; -import { calculateTransform, Space } from '../particle-general-function'; +import { calculateTransform } from '../particle-general-function'; import CurveRange from './curve-range'; // tslint:disable: max-line-length diff --git a/cocos/3d/framework/particle/burst.ts b/cocos/3d/framework/particle/burst.ts index a401b1c312..e0a7efe07b 100644 --- a/cocos/3d/framework/particle/burst.ts +++ b/cocos/3d/framework/particle/burst.ts @@ -88,6 +88,10 @@ export default class Burst { } } } + + public getMaxCount (psys) { + return this.count.getMax() * Math.min(Math.floor(psys.duration / this.repeatInterval), this.repeatCount); + } } // CCClass.fastDefine('cc.Burst', Burst, { diff --git a/cocos/3d/framework/particle/emitter/shape-module.ts b/cocos/3d/framework/particle/emitter/shape-module.ts index fb7d27caab..3107c41ce0 100644 --- a/cocos/3d/framework/particle/emitter/shape-module.ts +++ b/cocos/3d/framework/particle/emitter/shape-module.ts @@ -1,106 +1,17 @@ -import { randomUnitVector, particleEmitZAxis, randomSortArray, randomSign, randomPointBetweenSphere, randomPointInCube, randomPointBetweenCircleAtFixedAngle, fixedAngleUnitVector2 } from '../particle-general-function'; -import { vec3, vec2, random, randomRange, mat4, quat, clamp, repeat, pingPong, toRadian, toDegree } from '../../../../core/vmath'; -import { Enum, Vec3 } from '../../../../core/value-types'; -import CurveRange from '../animator/curve-range'; import { CCClass } from '../../../../core/data'; -import { property, ccclass } from '../../../../core/data/class-decorator'; +import { ccclass, property } from '../../../../core/data/class-decorator'; +import { Enum, Vec3 } from '../../../../core/value-types'; +import { clamp, mat4, pingPong, quat, random, randomRange, repeat, toDegree, toRadian, vec2, vec3 } from '../../../../core/vmath'; +import CurveRange from '../animator/curve-range'; +import { fixedAngleUnitVector2, particleEmitZAxis, randomPointBetweenCircleAtFixedAngle, randomPointBetweenSphere, randomPointInCube, randomSign, randomSortArray, randomUnitVector } from '../particle-general-function'; import { ParticleSystemComponent } from '../particle-system-component'; +import { ShapeType, EmitLocation, ArcMode } from '../enum'; // tslint:disable: max-line-length const _intermediVec = vec3.create(0, 0, 0); const _intermediArr = new Array(); const _unitBoxExtent = vec3.create(0.5, 0.5, 0.5); -/** - * 粒子发射器类型 - * @enum shapeModule.ShapeType - */ -const ShapeType = Enum({ - /** - * 立方体类型粒子发射器 - * @property {Number} Box - */ - Box: 0, - - /** - * 圆形粒子发射器 - * @property {Number} Circle - */ - Circle: 1, - - /** - * 圆锥体粒子发射器 - * @property {Number} Cone - */ - Cone: 2, - - /** - * 球体粒子发射器 - * @property {Number} Sphere - */ - Sphere: 3, - - /** - * 半球体粒子发射器 - * @property {Number} Hemisphere - */ - Hemisphere: 4, -}); - -/** - * 粒子从发射器的哪个部位发射 - * @enum shapeModule.EmitLocation - */ -const EmitLocation = Enum({ - /** - * 基础位置发射(仅对 Circle 类型及 Cone 类型的粒子发射器适用) - * @property {Number} Base - */ - Base: 0, - - /** - * 边框位置发射(仅对 Box 类型及 Circle 类型的粒子发射器适用) - * @property {Number} Edge - */ - Edge: 1, - - /** - * 表面位置发射(对所有类型的粒子发射器都适用) - * @property {Number} Shell - */ - Shell: 2, - - /** - * 内部位置发射(对所有类型的粒子发射器都适用) - * @property {Number} Volume - */ - Volume: 3, -}); - -/** - * 粒子在扇形区域的发射方式 - * @enum shapeModule.ArcMode - */ -const ArcMode = Enum({ - /** - * 随机位置发射 - * @property {Number} Random - */ - Random: 0, - - /** - * 沿某一方向循环发射,每次循环方向相同 - * @property {Number} Loop - */ - Loop: 1, - - /** - * 循环发射,每次循环方向相反 - * @property {Number} PingPong - */ - PingPong: 2, -}); - @ccclass('cc.ShapeModule') export default class ShapeModule { diff --git a/cocos/3d/framework/particle/enum.ts b/cocos/3d/framework/particle/enum.ts new file mode 100644 index 0000000000..f976cdd0a6 --- /dev/null +++ b/cocos/3d/framework/particle/enum.ts @@ -0,0 +1,163 @@ +import { Enum } from '../../../core'; + +export const Space = Enum({ + World: 0, + Local: 1, + Custom: 2, +}); + +/** + * 粒子的生成模式 + * @enum ParticleSystemRenderer.RenderMode + */ +export const RenderMode = Enum({ + + /** + * 粒子始终面向摄像机 + */ + Billboard: 0, + + /** + * 粒子始终面向摄像机但会根据参数进行拉伸 + */ + StrecthedBillboard: 1, + + /** + * 粒子始终与 XZ 平面平行 + */ + HorizontalBillboard: 2, + + /** + * 粒子始终与 Y 轴平行且朝向摄像机 + */ + VerticalBillboard: 3, + + /** + * 粒子保持模型本身状态 + */ + Mesh: 4, +}); + +/** + * 粒子发射器类型 + * @enum shapeModule.ShapeType + */ +export const ShapeType = Enum({ + /** + * 立方体类型粒子发射器 + * @property {Number} Box + */ + Box: 0, + + /** + * 圆形粒子发射器 + * @property {Number} Circle + */ + Circle: 1, + + /** + * 圆锥体粒子发射器 + * @property {Number} Cone + */ + Cone: 2, + + /** + * 球体粒子发射器 + * @property {Number} Sphere + */ + Sphere: 3, + + /** + * 半球体粒子发射器 + * @property {Number} Hemisphere + */ + Hemisphere: 4, +}); + +/** + * 粒子从发射器的哪个部位发射 + * @enum shapeModule.EmitLocation + */ +export const EmitLocation = Enum({ + /** + * 基础位置发射(仅对 Circle 类型及 Cone 类型的粒子发射器适用) + * @property {Number} Base + */ + Base: 0, + + /** + * 边框位置发射(仅对 Box 类型及 Circle 类型的粒子发射器适用) + * @property {Number} Edge + */ + Edge: 1, + + /** + * 表面位置发射(对所有类型的粒子发射器都适用) + * @property {Number} Shell + */ + Shell: 2, + + /** + * 内部位置发射(对所有类型的粒子发射器都适用) + * @property {Number} Volume + */ + Volume: 3, +}); + +/** + * 粒子在扇形区域的发射方式 + * @enum shapeModule.ArcMode + */ +export const ArcMode = Enum({ + /** + * 随机位置发射 + * @property {Number} Random + */ + Random: 0, + + /** + * 沿某一方向循环发射,每次循环方向相同 + * @property {Number} Loop + */ + Loop: 1, + + /** + * 循环发射,每次循环方向相反 + * @property {Number} PingPong + */ + PingPong: 2, +}); + +/** + * 选择如何为粒子系统生成轨迹 + * @enum trailModule.TrailMode + */ +export const TrailMode = Enum({ + /** + * 粒子模式 + * 创建一种效果,其中每个粒子在其路径中留下固定的轨迹 + */ + Particles: 0, + + /** + * 带模式 + * 根据其生命周期创建连接每个粒子的轨迹带 + */ + Ribbon: 1, +}); + +/** + * 纹理填充模式 + * @enum trailModule.TextureMode + */ +export const TextureMode = Enum({ + /** + * 拉伸填充纹理 + */ + Stretch: 0, + + /** + * 重复填充纹理 + */ + Repeat: 1, +}); diff --git a/cocos/3d/framework/particle/particle-general-function.ts b/cocos/3d/framework/particle/particle-general-function.ts index a838f626ca..ed55b106d9 100644 --- a/cocos/3d/framework/particle/particle-general-function.ts +++ b/cocos/3d/framework/particle/particle-general-function.ts @@ -1,15 +1,10 @@ -import { mat4, quat, randomRange, vec3, random, vec2, randomRangeInt } from '../../../core/vmath'; -import { sign } from '../../../core/vmath/bits'; import { Enum } from '../../../core/value-types'; +import { mat4, quat, random, randomRange, randomRangeInt, vec2, vec3 } from '../../../core/vmath'; +import { sign } from '../../../core/vmath/bits'; +import { Space } from './enum'; export const particleEmitZAxis = vec3.create(0, 0, -1); -export const Space = Enum({ - World: 0, - Local: 1, - Custom: 2, -}); - export function calculateTransform (systemSpace: number, moduleSpace: number, worldTransform: mat4, outQuat: quat) { if (moduleSpace !== systemSpace) { if (systemSpace === Space.World) { diff --git a/cocos/3d/framework/particle/particle-system-component.ts b/cocos/3d/framework/particle/particle-system-component.ts index d1fc013080..8a1154a075 100644 --- a/cocos/3d/framework/particle/particle-system-component.ts +++ b/cocos/3d/framework/particle/particle-system-component.ts @@ -3,25 +3,26 @@ // tslint:disable: max-line-length import { Component } from '../../../components/component'; -import { vec3, vec2, mat4, quat, randomRangeInt, pseudoRandom } from '../../../core/vmath'; -import CurveRange from './animator/curve-range'; -import GradientRange from './animator/gradient-range'; -import ParticleSystemRenderer from './renderer/particle-system-renderer'; -import SizeOvertimeModule from './animator/size-overtime'; +import { ccclass, executeInEditMode, executionOrder, menu, property, requireComponent } from '../../../core/data/class-decorator'; +import { mat4, pseudoRandom, quat, randomRangeInt, vec2, vec3 } from '../../../core/vmath'; +import { INT_MAX } from '../../../core/vmath/bits'; +import { Material } from '../../assets'; +import { RenderableComponent } from '../renderable-component'; import ColorOverLifetimeModule from './animator/color-overtime'; -import VelocityOvertimeModule from './animator/velocity-overtime'; +import CurveRange from './animator/curve-range'; import ForceOvertimeModule from './animator/force-overtime'; +import GradientRange from './animator/gradient-range'; import LimitVelocityOvertimeModule from './animator/limit-velocity-overtime'; import RotationOvertimeModule from './animator/rotation-overtime'; +import SizeOvertimeModule from './animator/size-overtime'; import TextureAnimationModule from './animator/texture-animation'; -import ShapeModule from './emitter/shape-module'; +import VelocityOvertimeModule from './animator/velocity-overtime'; import Burst from './burst'; -import { particleEmitZAxis, Space } from './particle-general-function'; -import { INT_MAX } from '../../../core/vmath/bits'; -import { ccclass, executionOrder, executeInEditMode, property, requireComponent, menu } from '../../../core/data/class-decorator'; +import ShapeModule from './emitter/shape-module'; +import { Space } from './enum'; +import { particleEmitZAxis } from './particle-general-function'; +import ParticleSystemRenderer from './renderer/particle-system-renderer'; import TrailModule from './renderer/trail'; -import { RenderableComponent } from '../renderable-component'; -import { Material } from '../../assets'; const _world_mat = mat4.create(); diff --git a/cocos/3d/framework/particle/renderer/particle-system-renderer.ts b/cocos/3d/framework/particle/renderer/particle-system-renderer.ts index b8a74209bc..5eb834d0ae 100644 --- a/cocos/3d/framework/particle/renderer/particle-system-renderer.ts +++ b/cocos/3d/framework/particle/renderer/particle-system-renderer.ts @@ -5,13 +5,12 @@ import { GFXAttributeName, GFXFormat } from '../../../../gfx/define'; import { IGFXAttribute } from '../../../../gfx/input-assembler'; import * as renderer from '../../../../renderer'; import ParticleBatchModel from '../../../../renderer/models/particle-batch-model'; -import { Material } from '../../../assets/material'; -import RecyclePool from '../../../memop/recycle-pool'; -import Particle from '../particle'; -import { RenderableComponent } from '../../renderable-component'; -import { Space } from '../particle-general-function'; -import { builtinResMgr } from '../../../builtin'; import { Mesh } from '../../../assets'; +import { Material } from '../../../assets/material'; +import { builtinResMgr } from '../../../builtin'; +import RecyclePool from '../../../memop/recycle-pool'; +import { RenderMode, Space } from '../enum'; +import Particle from '../particle'; // import ParticleSystemComponent from '../particle-system-component'; // tslint:disable: max-line-length @@ -27,38 +26,6 @@ const _uvs = [ 1, 1, // top-right ]; -/** - * 粒子的生成模式 - * @enum ParticleSystemRenderer.RenderMode - */ -const RenderMode = Enum({ - - /** - * 粒子始终面向摄像机 - */ - Billboard: 0, - - /** - * 粒子始终面向摄像机但会根据参数进行拉伸 - */ - StrecthedBillboard: 1, - - /** - * 粒子始终与 XZ 平面平行 - */ - HorizontalBillboard: 2, - - /** - * 粒子始终与 Y 轴平行且朝向摄像机 - */ - VerticalBillboard: 3, - - /** - * 粒子保持模型本身状态 - */ - Mesh: 4, -}); - const CC_USE_WORLD_SPACE = 'CC_USE_WORLD_SPACE'; const CC_USE_BILLBOARD = 'CC_USE_BILLBOARD'; const CC_USE_STRETCHED_BILLBOARD = 'CC_USE_STRETCHED_BILLBOARD'; @@ -220,6 +187,7 @@ export default class ParticleSystemRenderer { private particleSystem: any; private _particles: RecyclePool | null = null; private _defaultMat: Material | null = null; + private _defaultTrailMat: Material | null = null; constructor () { this._model = null; @@ -252,7 +220,7 @@ export default class ParticleSystemRenderer { return; } if (this._model == null) { - this._model = this.particleSystem._getRenderScene().createModel(ParticleBatchModel, this.node) as ParticleBatchModel; + this._model = this.particleSystem._getRenderScene().createModel(ParticleBatchModel, this.particleSystem.node) as ParticleBatchModel; } if (!this._model.inited) { this._model.setCapacity(this.particleSystem.capacity); @@ -444,10 +412,8 @@ export default class ParticleSystemRenderer { const mat: Material | null = this.particleSystem.sharedMaterial ? this.particleMaterial : this._defaultMat; if (this.particleSystem._simulationSpace === Space.World) { this._defines[CC_USE_WORLD_SPACE] = true; - this._trailDefines[CC_USE_WORLD_SPACE] = true; } else { this._defines[CC_USE_WORLD_SPACE] = false; - this._trailDefines[CC_USE_WORLD_SPACE] = false; } if (this._renderMode === RenderMode.Billboard) { @@ -499,12 +465,18 @@ export default class ParticleSystemRenderer { private _updateTrailMaterial () { if (this.particleSystem.trailModule.enable) { - if (this.particleSystem._simulationSpace === Space.World) { + if (this.particleSystem._simulationSpace === Space.World || this.particleSystem.trailModule.space === Space.World) { this._trailDefines[CC_USE_WORLD_SPACE] = true; } else { this._trailDefines[CC_USE_WORLD_SPACE] = false; } - const mat = this.trailMaterial; + let mat = this.trailMaterial; + if (mat === null && this._defaultTrailMat === null) { + this._defaultTrailMat = Material.getInstantiatedMaterial(builtinResMgr.get('default-trail-material'), this.particleSystem, true); + } + if (mat === null) { + mat = this._defaultTrailMat; + } mat!.recompileShaders(this._trailDefines); this.particleSystem.trailModule._updateMaterial(); } diff --git a/cocos/3d/framework/particle/renderer/trail.ts b/cocos/3d/framework/particle/renderer/trail.ts index 30287754f7..4c5877b2b5 100644 --- a/cocos/3d/framework/particle/renderer/trail.ts +++ b/cocos/3d/framework/particle/renderer/trail.ts @@ -1,5 +1,5 @@ import { Color, Vec3 } from '../../../../core'; -import { property, ccclass } from '../../../../core/data/class-decorator'; +import { ccclass, property } from '../../../../core/data/class-decorator'; import Enum from '../../../../core/value-types/enum'; import { vec3 } from '../../../../core/vmath'; import { GFX_DRAW_INFO_SIZE, GFXBuffer, IGFXIndirectBuffer } from '../../../../gfx/buffer'; @@ -10,47 +10,18 @@ import { Model } from '../../../../renderer'; import { IRenderingSubmesh } from '../../../assets/mesh'; import { Pool } from '../../../memop'; import CurveRange from '../animator/curve-range'; +import { Space, TrailMode, TextureMode } from '../enum'; import Particle from '../particle'; -import { Space } from '../particle-general-function'; +import { Material } from '../../../assets'; +import { builtinResMgr } from '../../../builtin'; const PRE_TRIANGLE_INDEX = 1; const NEXT_TRIANGLE_INDEX = 1 << 2; const _temp_trailEle = {} as ITrailElement; - -/** - * 选择如何为粒子系统生成轨迹 - * @enum trailModule.TrailMode - */ -const TrailMode = Enum({ - /** - * 粒子模式 - * 创建一种效果,其中每个粒子在其路径中留下固定的轨迹 - */ - Particles: 0, - - /** - * 带模式 - * 根据其生命周期创建连接每个粒子的轨迹带 - */ - Ribbon: 1, -}); - -/** - * 纹理填充模式 - * @enum trailModule.TextureMode - */ -const TextureMode = Enum({ - /** - * 拉伸填充纹理 - */ - Stretch: 0, - - /** - * 重复填充纹理 - */ - Repeat: 1, -}); +const _temp_quat = cc.quat(); +const _temp_xform = cc.mat4(); +const _temp_vec3 = cc.v3(); interface ITrailElement { position: Vec3; @@ -141,7 +112,7 @@ export default class TrailModule { this._createModel(); } if (val && !this._enable) { - this._updateMaterial(); + this._particleSystem.renderer._updateTrailMaterial(); } this._enable = val; if (this._trailModel) { @@ -196,14 +167,14 @@ export default class TrailModule { @property public _minParticleDistance = 0.1; - // /** - // * 轨迹设定时的坐标系 - // */ - // @property({ - // type: Space, - // displayOrder: 6, - // }) - // public space = Space.World; + /** + * 轨迹设定时的坐标系 + */ + @property({ + type: Space, + displayOrder: 6, + }) + public space = Space.World; /** * 粒子本身是否存在 @@ -248,6 +219,8 @@ export default class TrailModule { private _vbF32: Float32Array; private _vbUint32: Uint32Array; private _iBuffer: Uint16Array; + private _needTransform: boolean; + private _defaultMat: Material | null = null; constructor () { this._iaInfo = { @@ -279,7 +252,11 @@ export default class TrailModule { public init (ps) { this._particleSystem = ps; this.lifeTime.constant = 1; - this._trailNum = ps.startLifetime.getMax() * this.lifeTime.getMax() * 60 * ps.rateOverTime.getMax() * ps.duration; + let burstCount = 0; + for (const b of ps.bursts) { + burstCount += b.getMaxCount(ps); + } + this._trailNum = ps.startLifetime.getMax() * this.lifeTime.getMax() * 60 * (ps.rateOverTime.getMax() * ps.duration + burstCount); this._trailSegments = new Pool(() => new TrailSegment(ps.startLifetime.getMax() * this.lifeTime.getMax() * 60), Math.ceil(ps.rateOverTime.getMax() * ps.duration)); if (this._enable) { this.enable = this._enable; @@ -359,12 +336,21 @@ export default class TrailModule { const mat = this._particleSystem.renderer.trailMaterial; if (mat) { this._trailModel!.setSubModelMaterial(0, mat); + } else { + this._trailModel!.setSubModelMaterial(0, this._particleSystem.renderer._defaultTrailMat); } } } public update () { this._trailLifetime = this.lifeTime.evaluate(this._particleSystem._time, 1)!; + if (this.space === Space.World && this._particleSystem._simulationSpace === Space.Local) { + this._needTransform = true; + this._particleSystem.node.getWorldMatrix(_temp_xform); + this._particleSystem.node.getWorldRotation(_temp_quat); + } else { + this._needTransform = false; + } } public animate (p: Particle, scaledDt: number) { @@ -374,17 +360,26 @@ export default class TrailModule { this._particleTrail.set(p, trail); } let lastSeg = trail.getTailElement(); + if (this._needTransform) { + vec3.transformMat4(_temp_vec3, p.position, _temp_xform); + } else { + vec3.copy(_temp_vec3, p.position); + } if (lastSeg) { trail.iterateElement(this, this._updateTrailElement, scaledDt); - if (vec3.squaredDistance(lastSeg.position, p.position) < this._minSquaredDistance) { + if (vec3.squaredDistance(lastSeg.position, _temp_vec3) < this._minSquaredDistance) { return; } } lastSeg = trail.addElement(); - vec3.copy(lastSeg.position, p.position); + vec3.copy(lastSeg.position, _temp_vec3); lastSeg.lifetime = 0; lastSeg.width = p.size.x; - vec3.copy(lastSeg.velocity, p.ultimateVelocity); + if (this._needTransform) { + vec3.transformQuat(lastSeg.velocity, p.ultimateVelocity, _temp_quat); + } else { + vec3.copy(lastSeg.velocity, p.ultimateVelocity); + } lastSeg.color.set(p.color); }