diff --git a/cocos/3d/builtin/effects.js b/cocos/3d/builtin/effects.ts similarity index 81% rename from cocos/3d/builtin/effects.js rename to cocos/3d/builtin/effects.ts index 389226db4c..d5f30d2438 100644 --- a/cocos/3d/builtin/effects.js +++ b/cocos/3d/builtin/effects.ts @@ -1,3 +1,4 @@ +// tslint:disable // absolute essential effects export default [ { @@ -51,14 +52,14 @@ export default [ "shaders": [ { "name": "builtin-particle-trail|particle-trail:vs_main|tinted-fs:add", - "hash": 2501294573, + "hash": 1264919710, "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 highp 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 * mainTiling_Offset.xy + mainTiling_Offset.zw;;\n color = a_color;\n return pos;\n}\nvoid main() { gl_Position = vs_main(); }\n`, - "frag": `\nprecision highp float;\nuniform CCGlobal {\n vec4 cc_time; \n vec4 cc_screenSize; \n vec4 cc_screenScale; \n vec4 cc_nativeSize; \n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos; \n vec4 cc_exposure; \n vec4 cc_mainLitDir; \n vec4 cc_mainLitColor; \n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\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` + "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 vec4 mainTiling_Offset;\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 highp 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 * mainTiling_Offset.xy + mainTiling_Offset.zw;;\n color = a_color;\n return pos;\n}\nvoid main() { gl_Position = vs_main(); }\n`, - "frag": `\nprecision highp 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` + "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": [ @@ -196,13 +197,13 @@ export default [ "shaders": [ { "name": "builtin-standard|standard-vs:vert|standard-fs:frag", - "hash": 3864949562, + "hash": 2753708482, "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_SKINNING == 1\n \n uniform CCSkinning {\n vec4 cc_matJoint[30 * 3];\n };\n#else\n \n uniform CCSkinningTexture {\n vec4 cc_jointsTextureSizeInv;\n };\n \n uniform sampler2D cc_jointsTexture;\n#endif\n#if CC_USE_SKINNING == 2\n float decode32(highp vec4 rgba) {\n rgba = rgba * 255.0; \n float Sign = 1.0 - step(128.0, rgba[3]) * 2.0;\n float Exponent = 2.0 * mod(rgba[3], 128.0) + step(128.0, rgba[2]) - 127.0;\n float Mantissa = mod(rgba[2], 128.0) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\n }\n#endif\n#if CC_USE_SKINNING == 1\n mat4 getJointMatrix(float i) {\n vec4 v1 = cc_matJoint[3 * int(i)];\n vec4 v2 = cc_matJoint[3 * int(i) + 1];\n vec4 v3 = cc_matJoint[3 * int(i) + 2];\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n#elif CC_USE_SKINNING == 2\n vec3 getJointMatrix(float i) {\n float y = (i + 0.5) * cc_jointsTextureSizeInv.y;\n vec4 v1 = vec4(\n decode32(texture(cc_jointsTexture, vec2((0.5 / 12.0), y))),\n decode32(texture(cc_jointsTexture, vec2((1.5 / 12.0), y))),\n decode32(texture(cc_jointsTexture, vec2((2.5 / 12.0), y))),\n decode32(texture(cc_jointsTexture, vec2((3.5 / 12.0), y)))\n );\n vec4 v2 = vec4(\n decode32(texture(cc_jointsTexture, vec2((4.5 / 12.0), y))),\n decode32(texture(cc_jointsTexture, vec2((5.5 / 12.0), y))),\n decode32(texture(cc_jointsTexture, vec2((6.5 / 12.0), y))),\n decode32(texture(cc_jointsTexture, vec2((7.5 / 12.0), y)))\n );\n vec4 v3 = vec4(\n decode32(texture(cc_jointsTexture, vec2((8.5 / 12.0), y))),\n decode32(texture(cc_jointsTexture, vec2((9.5 / 12.0), y))),\n decode32(texture(cc_jointsTexture, vec2((10.5 / 12.0), y))),\n decode32(texture(cc_jointsTexture, vec2((11.5 / 12.0), y)))\n );\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n#elif CC_USE_SKINNING == 3\n mat4 getJointMatrix(float i) {\n float y = (i + 0.5) * cc_jointsTextureSizeInv.y;\n vec4 v1 = texture(cc_jointsTexture, vec2((0.5 / 3.0), y));\n vec4 v2 = texture(cc_jointsTexture, vec2((1.5 / 3.0), y));\n vec4 v3 = texture(cc_jointsTexture, vec2((2.5 / 3.0), y));\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n#endif\nmat4 skinMatrix() {\n return getJointMatrix(a_joints.x) * a_weights.x\n + getJointMatrix(a_joints.y) * a_weights.y;\n + getJointMatrix(a_joints.z) * a_weights.z;\n + getJointMatrix(a_joints.w) * a_weights.w;\n}\nvoid skinVertex(inout vec4 pos) {\n mat4 m = skinMatrix();\n pos = m * pos;\n}\nvoid skinVertex(inout vec4 pos, inout vec4 a2) {\n mat4 m = skinMatrix();\n pos = m * pos;\n a2 = m * a2;\n}\nvoid skinVertex(inout vec4 pos, inout vec4 a2, inout vec4 a3) {\n mat4 m = skinMatrix();\n pos = m * pos;\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 #endif\n pos = cc_matWorld * pos;\n normal = cc_matWorldIT * normal;\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_SKINNING == 1\n \n uniform CCSkinning {\n vec4 cc_matJoint[30 * 3];\n };\n#else\n \n uniform CCSkinningTexture {\n vec4 cc_jointsTextureSizeInv;\n };\n \n uniform sampler2D cc_jointsTexture;\n#endif\n#if CC_USE_SKINNING == 2\n float decode32(highp vec4 rgba) {\n rgba = rgba * 255.0; \n float Sign = 1.0 - step(128.0, rgba[3]) * 2.0;\n float Exponent = 2.0 * mod(rgba[3], 128.0) + step(128.0, rgba[2]) - 127.0;\n float Mantissa = mod(rgba[2], 128.0) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\n }\n#endif\n#if CC_USE_SKINNING == 1\n vec3 getJointDQ(float i, out vec4 Qr, out vec4 Qt) {\n Qr = cc_matJoint[3 * int(i)];\n Qt = cc_matJoint[3 * int(i) + 1];\n return cc_matJoint[3 * int(i) + 2].xyz;\n }\n#elif CC_USE_SKINNING == 2\n vec3 getJointDQ(float i, out vec4 Qr, out vec4 Qt) {\n float y = (i + 0.5) * cc_jointsTextureSizeInv.y;\n Qr = vec4(\n decode32(texture(cc_jointsTexture, vec2((0.5 / 12.0), y))),\n decode32(texture(cc_jointsTexture, vec2((1.5 / 12.0), y))),\n decode32(texture(cc_jointsTexture, vec2((2.5 / 12.0), y))),\n decode32(texture(cc_jointsTexture, vec2((3.5 / 12.0), y)))\n );\n Qt = vec4(\n decode32(texture(cc_jointsTexture, vec2((4.5 / 12.0), y))),\n decode32(texture(cc_jointsTexture, vec2((5.5 / 12.0), y))),\n decode32(texture(cc_jointsTexture, vec2((6.5 / 12.0), y))),\n decode32(texture(cc_jointsTexture, vec2((7.5 / 12.0), y)))\n );\n return vec3(\n decode32(texture(cc_jointsTexture, vec2((8.5 / 12.0), y))),\n decode32(texture(cc_jointsTexture, vec2((9.5 / 12.0), y))),\n decode32(texture(cc_jointsTexture, vec2((10.5 / 12.0), y)))\n );\n }\n#elif CC_USE_SKINNING == 3\n vec3 getJointDQ(float i, out vec4 Qr, out vec4 Qt) {\n float y = (i + 0.5) * cc_jointsTextureSizeInv.y;\n Qr = texture(cc_jointsTexture, vec2((0.5 / 3.0), y));\n Qt = texture(cc_jointsTexture, vec2((1.5 / 3.0), y));\n return texture(cc_jointsTexture, vec2((2.5 / 3.0), y)).xyz;\n }\n#endif\nvoid skinRTS(out vec4 R, out vec3 T, out vec3 S) {\n vec4 r, t, Qt = vec4(0.0);\n R = vec4(0.0); S = vec3(0.0);\n for (int i = 0; i < 4; i++) {\n float w = a_weights[i];\n S += getJointDQ(a_joints[i], r, t) * w;\n R += r * w; Qt += t * w;\n }\n float invNorm = 1.0 / length(R); R *= invNorm; Qt *= invNorm;\n T = 2.0 * (R.w * Qt.xyz - Qt.w * R.xyz + cross(R.xyz, Qt.xyz)); \n}\nvec3 VectorTransformQuat(vec3 v, vec4 Q) {\n return v + 2.0 * cross(Q.xyz, cross(Q.xyz, v) + Q.w * v);\n}\nvoid skinVertex(inout vec4 pos) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n pos.xyz = VectorTransformQuat(pos.xyz * S, R) + T;\n}\nvoid skinVertex(inout vec4 pos, inout vec4 a2) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n pos.xyz = VectorTransformQuat(pos.xyz * S, R) + T;\n a2.xyz = VectorTransformQuat(a2.xyz, R);\n}\nvoid skinVertex(inout vec4 pos, inout vec4 a2, inout vec4 a3) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n pos.xyz = VectorTransformQuat(pos.xyz * S, R) + T;\n a2.xyz = VectorTransformQuat(a2.xyz, R);\n a3.xyz = VectorTransformQuat(a3.xyz, R);\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 #endif\n pos = cc_matWorld * pos;\n normal = cc_matWorldIT * normal;\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};\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 saturate(a) clamp( a, 0.0, 1.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}\nvec3 CalcDynamicLighting(vec3 worldPos, vec3 N, vec3 V, vec3 diffuse, vec3 specular, float roughness)\n{\n vec3 lighting = vec3(0.0);\n vec3 diffuseContrib = diffuse / 3.14159265359;\n for (int i = 0; i < 2; i++) {\n vec3 PLU = cc_sphereLitPos[i].xyz - 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 lighting += PNL * cc_sphereLitColor[i].rgb * cc_sphereLitColor[i].w * illum * att * (diffuseContrib + lspec);\n }\n for (int i = 0; i < 2; i++) {\n vec3 SLU = cc_spotLitPos[i].xyz - 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 lighting += SNL * cc_spotLitColor[i].rgb * cc_spotLitColor[i].w * illum * att * (diffuseContrib + lspec);\n }\n return lighting;\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 finalColor += CalcDynamicLighting(v_worldPos, N, V, diffuse, specular, roughness);\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_SKINNING == 1\n \n uniform vec4 cc_matJoint[90];\n#else\n \n uniform vec4 cc_jointsTextureSizeInv;\n uniform sampler2D cc_jointsTexture;\n#endif\n#if CC_USE_SKINNING == 2\n float decode32(highp vec4 rgba) {\n rgba = rgba * 255.0; \n float Sign = 1.0 - step(128.0, rgba[3]) * 2.0;\n float Exponent = 2.0 * mod(rgba[3], 128.0) + step(128.0, rgba[2]) - 127.0;\n float Mantissa = mod(rgba[2], 128.0) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\n }\n#endif\n#if CC_USE_SKINNING == 1\n mat4 getJointMatrix(float i) {\n vec4 v1 = cc_matJoint[3 * int(i)];\n vec4 v2 = cc_matJoint[3 * int(i) + 1];\n vec4 v3 = cc_matJoint[3 * int(i) + 2];\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n#elif CC_USE_SKINNING == 2\n vec3 getJointMatrix(float i) {\n float y = (i + 0.5) * cc_jointsTextureSizeInv.y;\n vec4 v1 = vec4(\n decode32(texture2D(cc_jointsTexture, vec2((0.5 / 12.0), y))),\n decode32(texture2D(cc_jointsTexture, vec2((1.5 / 12.0), y))),\n decode32(texture2D(cc_jointsTexture, vec2((2.5 / 12.0), y))),\n decode32(texture2D(cc_jointsTexture, vec2((3.5 / 12.0), y)))\n );\n vec4 v2 = vec4(\n decode32(texture2D(cc_jointsTexture, vec2((4.5 / 12.0), y))),\n decode32(texture2D(cc_jointsTexture, vec2((5.5 / 12.0), y))),\n decode32(texture2D(cc_jointsTexture, vec2((6.5 / 12.0), y))),\n decode32(texture2D(cc_jointsTexture, vec2((7.5 / 12.0), y)))\n );\n vec4 v3 = vec4(\n decode32(texture2D(cc_jointsTexture, vec2((8.5 / 12.0), y))),\n decode32(texture2D(cc_jointsTexture, vec2((9.5 / 12.0), y))),\n decode32(texture2D(cc_jointsTexture, vec2((10.5 / 12.0), y))),\n decode32(texture2D(cc_jointsTexture, vec2((11.5 / 12.0), y)))\n );\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n#elif CC_USE_SKINNING == 3\n mat4 getJointMatrix(float i) {\n float y = (i + 0.5) * cc_jointsTextureSizeInv.y;\n vec4 v1 = texture2D(cc_jointsTexture, vec2((0.5 / 3.0), y));\n vec4 v2 = texture2D(cc_jointsTexture, vec2((1.5 / 3.0), y));\n vec4 v3 = texture2D(cc_jointsTexture, vec2((2.5 / 3.0), y));\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n#endif\nmat4 skinMatrix() {\n return getJointMatrix(a_joints.x) * a_weights.x\n + getJointMatrix(a_joints.y) * a_weights.y;\n + getJointMatrix(a_joints.z) * a_weights.z;\n + getJointMatrix(a_joints.w) * a_weights.w;\n}\nvoid skinVertex(inout vec4 pos) {\n mat4 m = skinMatrix();\n pos = m * pos;\n}\nvoid skinVertex(inout vec4 pos, inout vec4 a2) {\n mat4 m = skinMatrix();\n pos = m * pos;\n a2 = m * a2;\n}\nvoid skinVertex(inout vec4 pos, inout vec4 a2, inout vec4 a3) {\n mat4 m = skinMatrix();\n pos = m * pos;\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 #endif\n pos = cc_matWorld * pos;\n normal = cc_matWorldIT * normal;\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_SKINNING == 1\n \n uniform vec4 cc_matJoint[90];\n#else\n \n uniform vec4 cc_jointsTextureSizeInv;\n uniform sampler2D cc_jointsTexture;\n#endif\n#if CC_USE_SKINNING == 2\n float decode32(highp vec4 rgba) {\n rgba = rgba * 255.0; \n float Sign = 1.0 - step(128.0, rgba[3]) * 2.0;\n float Exponent = 2.0 * mod(rgba[3], 128.0) + step(128.0, rgba[2]) - 127.0;\n float Mantissa = mod(rgba[2], 128.0) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\n }\n#endif\n#if CC_USE_SKINNING == 1\n vec3 getJointDQ(float i, out vec4 Qr, out vec4 Qt) {\n Qr = cc_matJoint[3 * int(i)];\n Qt = cc_matJoint[3 * int(i) + 1];\n return cc_matJoint[3 * int(i) + 2].xyz;\n }\n#elif CC_USE_SKINNING == 2\n vec3 getJointDQ(float i, out vec4 Qr, out vec4 Qt) {\n float y = (i + 0.5) * cc_jointsTextureSizeInv.y;\n Qr = vec4(\n decode32(texture2D(cc_jointsTexture, vec2((0.5 / 12.0), y))),\n decode32(texture2D(cc_jointsTexture, vec2((1.5 / 12.0), y))),\n decode32(texture2D(cc_jointsTexture, vec2((2.5 / 12.0), y))),\n decode32(texture2D(cc_jointsTexture, vec2((3.5 / 12.0), y)))\n );\n Qt = vec4(\n decode32(texture2D(cc_jointsTexture, vec2((4.5 / 12.0), y))),\n decode32(texture2D(cc_jointsTexture, vec2((5.5 / 12.0), y))),\n decode32(texture2D(cc_jointsTexture, vec2((6.5 / 12.0), y))),\n decode32(texture2D(cc_jointsTexture, vec2((7.5 / 12.0), y)))\n );\n return vec3(\n decode32(texture2D(cc_jointsTexture, vec2((8.5 / 12.0), y))),\n decode32(texture2D(cc_jointsTexture, vec2((9.5 / 12.0), y))),\n decode32(texture2D(cc_jointsTexture, vec2((10.5 / 12.0), y)))\n );\n }\n#elif CC_USE_SKINNING == 3\n vec3 getJointDQ(float i, out vec4 Qr, out vec4 Qt) {\n float y = (i + 0.5) * cc_jointsTextureSizeInv.y;\n Qr = texture2D(cc_jointsTexture, vec2((0.5 / 3.0), y));\n Qt = texture2D(cc_jointsTexture, vec2((1.5 / 3.0), y));\n return texture2D(cc_jointsTexture, vec2((2.5 / 3.0), y)).xyz;\n }\n#endif\nvoid skinRTS(out vec4 R, out vec3 T, out vec3 S) {\n vec4 r, t, Qt = vec4(0.0);\n R = vec4(0.0); S = vec3(0.0);\n for (int i = 0; i < 4; i++) {\n float w = a_weights[i];\n S += getJointDQ(a_joints[i], r, t) * w;\n R += r * w; Qt += t * w;\n }\n float invNorm = 1.0 / length(R); R *= invNorm; Qt *= invNorm;\n T = 2.0 * (R.w * Qt.xyz - Qt.w * R.xyz + cross(R.xyz, Qt.xyz)); \n}\nvec3 VectorTransformQuat(vec3 v, vec4 Q) {\n return v + 2.0 * cross(Q.xyz, cross(Q.xyz, v) + Q.w * v);\n}\nvoid skinVertex(inout vec4 pos) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n pos.xyz = VectorTransformQuat(pos.xyz * S, R) + T;\n}\nvoid skinVertex(inout vec4 pos, inout vec4 a2) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n pos.xyz = VectorTransformQuat(pos.xyz * S, R) + T;\n a2.xyz = VectorTransformQuat(a2.xyz, R);\n}\nvoid skinVertex(inout vec4 pos, inout vec4 a2, inout vec4 a3) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n pos.xyz = VectorTransformQuat(pos.xyz * S, R) + T;\n a2.xyz = VectorTransformQuat(a2.xyz, R);\n a3.xyz = VectorTransformQuat(a3.xyz, R);\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 #endif\n pos = cc_matWorld * pos;\n normal = cc_matWorldIT * normal;\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;\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 saturate(a) clamp( a, 0.0, 1.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}\nvec3 CalcDynamicLighting(vec3 worldPos, vec3 N, vec3 V, vec3 diffuse, vec3 specular, float roughness)\n{\n vec3 lighting = vec3(0.0);\n vec3 diffuseContrib = diffuse / 3.14159265359;\n for (int i = 0; i < 2; i++) {\n vec3 PLU = cc_sphereLitPos[i].xyz - 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 lighting += PNL * cc_sphereLitColor[i].rgb * cc_sphereLitColor[i].w * illum * att * (diffuseContrib + lspec);\n }\n for (int i = 0; i < 2; i++) {\n vec3 SLU = cc_spotLitPos[i].xyz - 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 lighting += SNL * cc_spotLitColor[i].rgb * cc_spotLitColor[i].w * illum * att * (diffuseContrib + lspec);\n }\n return lighting;\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 finalColor += CalcDynamicLighting(v_worldPos, N, V, diffuse, specular, roughness);\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", "CCSkinning", "CCSkinningTexture", "CCForwardLight"], "samplers":["cc_jointsTexture"]}}, @@ -213,9 +214,9 @@ export default [ {"name":"USE_PBR_MAP", "type":"boolean", "defines":[]}, {"name":"USE_EMISSIVE_MAP", "type":"boolean", "defines":[]}, {"name":"USE_IBL", "type":"boolean", "defines":[]}, - {"name":"ROUGHNESS_CHANNEL", "type":"string", "options":["r", "g", "b", "a"]}, - {"name":"METALLIC_CHANNEL", "type":"string", "options":["g", "r", "b", "a"]}, - {"name":"AO_CHANNEL", "type":"string", "options":["b", "r", "g", "a"]}, + {"name":"ROUGHNESS_CHANNEL", "type":"string", "defines":[], "options":["r", "g", "b", "a"]}, + {"name":"METALLIC_CHANNEL", "type":"string", "defines":[], "options":["g", "r", "b", "a"]}, + {"name":"AO_CHANNEL", "type":"string", "defines":[], "options":["b", "r", "g", "a"]}, {"name":"USE_ALPHA_TEST", "type":"boolean", "defines":[]}, {"name":"CC_USE_HDR", "type":"boolean", "defines":[]} ], @@ -241,13 +242,13 @@ export default [ }, { "name": "builtin-standard|planar-shadow-vs:vert|planar-shadow-fs:frag", - "hash": 4254435637, + "hash": 1783478207, "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_SKINNING == 1\n \n uniform CCSkinning {\n vec4 cc_matJoint[30 * 3];\n };\n#else\n \n uniform CCSkinningTexture {\n vec4 cc_jointsTextureSizeInv;\n };\n \n uniform sampler2D cc_jointsTexture;\n#endif\n#if CC_USE_SKINNING == 2\n float decode32(highp vec4 rgba) {\n rgba = rgba * 255.0; \n float Sign = 1.0 - step(128.0, rgba[3]) * 2.0;\n float Exponent = 2.0 * mod(rgba[3], 128.0) + step(128.0, rgba[2]) - 127.0;\n float Mantissa = mod(rgba[2], 128.0) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\n }\n#endif\n#if CC_USE_SKINNING == 1\n mat4 getJointMatrix(float i) {\n vec4 v1 = cc_matJoint[3 * int(i)];\n vec4 v2 = cc_matJoint[3 * int(i) + 1];\n vec4 v3 = cc_matJoint[3 * int(i) + 2];\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n#elif CC_USE_SKINNING == 2\n vec3 getJointMatrix(float i) {\n float y = (i + 0.5) * cc_jointsTextureSizeInv.y;\n vec4 v1 = vec4(\n decode32(texture(cc_jointsTexture, vec2((0.5 / 12.0), y))),\n decode32(texture(cc_jointsTexture, vec2((1.5 / 12.0), y))),\n decode32(texture(cc_jointsTexture, vec2((2.5 / 12.0), y))),\n decode32(texture(cc_jointsTexture, vec2((3.5 / 12.0), y)))\n );\n vec4 v2 = vec4(\n decode32(texture(cc_jointsTexture, vec2((4.5 / 12.0), y))),\n decode32(texture(cc_jointsTexture, vec2((5.5 / 12.0), y))),\n decode32(texture(cc_jointsTexture, vec2((6.5 / 12.0), y))),\n decode32(texture(cc_jointsTexture, vec2((7.5 / 12.0), y)))\n );\n vec4 v3 = vec4(\n decode32(texture(cc_jointsTexture, vec2((8.5 / 12.0), y))),\n decode32(texture(cc_jointsTexture, vec2((9.5 / 12.0), y))),\n decode32(texture(cc_jointsTexture, vec2((10.5 / 12.0), y))),\n decode32(texture(cc_jointsTexture, vec2((11.5 / 12.0), y)))\n );\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n#elif CC_USE_SKINNING == 3\n mat4 getJointMatrix(float i) {\n float y = (i + 0.5) * cc_jointsTextureSizeInv.y;\n vec4 v1 = texture(cc_jointsTexture, vec2((0.5 / 3.0), y));\n vec4 v2 = texture(cc_jointsTexture, vec2((1.5 / 3.0), y));\n vec4 v3 = texture(cc_jointsTexture, vec2((2.5 / 3.0), y));\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n#endif\nmat4 skinMatrix() {\n return getJointMatrix(a_joints.x) * a_weights.x\n + getJointMatrix(a_joints.y) * a_weights.y;\n + getJointMatrix(a_joints.z) * a_weights.z;\n + getJointMatrix(a_joints.w) * a_weights.w;\n}\nvoid skinVertex(inout vec4 pos) {\n mat4 m = skinMatrix();\n pos = m * pos;\n}\nvoid skinVertex(inout vec4 pos, inout vec4 a2) {\n mat4 m = skinMatrix();\n pos = m * pos;\n a2 = m * a2;\n}\nvoid skinVertex(inout vec4 pos, inout vec4 a2, inout vec4 a3) {\n mat4 m = skinMatrix();\n pos = m * pos;\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_SKINNING == 1\n \n uniform CCSkinning {\n vec4 cc_matJoint[30 * 3];\n };\n#else\n \n uniform CCSkinningTexture {\n vec4 cc_jointsTextureSizeInv;\n };\n \n uniform sampler2D cc_jointsTexture;\n#endif\n#if CC_USE_SKINNING == 2\n float decode32(highp vec4 rgba) {\n rgba = rgba * 255.0; \n float Sign = 1.0 - step(128.0, rgba[3]) * 2.0;\n float Exponent = 2.0 * mod(rgba[3], 128.0) + step(128.0, rgba[2]) - 127.0;\n float Mantissa = mod(rgba[2], 128.0) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\n }\n#endif\n#if CC_USE_SKINNING == 1\n vec3 getJointDQ(float i, out vec4 Qr, out vec4 Qt) {\n Qr = cc_matJoint[3 * int(i)];\n Qt = cc_matJoint[3 * int(i) + 1];\n return cc_matJoint[3 * int(i) + 2].xyz;\n }\n#elif CC_USE_SKINNING == 2\n vec3 getJointDQ(float i, out vec4 Qr, out vec4 Qt) {\n float y = (i + 0.5) * cc_jointsTextureSizeInv.y;\n Qr = vec4(\n decode32(texture(cc_jointsTexture, vec2((0.5 / 12.0), y))),\n decode32(texture(cc_jointsTexture, vec2((1.5 / 12.0), y))),\n decode32(texture(cc_jointsTexture, vec2((2.5 / 12.0), y))),\n decode32(texture(cc_jointsTexture, vec2((3.5 / 12.0), y)))\n );\n Qt = vec4(\n decode32(texture(cc_jointsTexture, vec2((4.5 / 12.0), y))),\n decode32(texture(cc_jointsTexture, vec2((5.5 / 12.0), y))),\n decode32(texture(cc_jointsTexture, vec2((6.5 / 12.0), y))),\n decode32(texture(cc_jointsTexture, vec2((7.5 / 12.0), y)))\n );\n return vec3(\n decode32(texture(cc_jointsTexture, vec2((8.5 / 12.0), y))),\n decode32(texture(cc_jointsTexture, vec2((9.5 / 12.0), y))),\n decode32(texture(cc_jointsTexture, vec2((10.5 / 12.0), y)))\n );\n }\n#elif CC_USE_SKINNING == 3\n vec3 getJointDQ(float i, out vec4 Qr, out vec4 Qt) {\n float y = (i + 0.5) * cc_jointsTextureSizeInv.y;\n Qr = texture(cc_jointsTexture, vec2((0.5 / 3.0), y));\n Qt = texture(cc_jointsTexture, vec2((1.5 / 3.0), y));\n return texture(cc_jointsTexture, vec2((2.5 / 3.0), y)).xyz;\n }\n#endif\nvoid skinRTS(out vec4 R, out vec3 T, out vec3 S) {\n vec4 r, t, Qt = vec4(0.0);\n R = vec4(0.0); S = vec3(0.0);\n for (int i = 0; i < 4; i++) {\n float w = a_weights[i];\n S += getJointDQ(a_joints[i], r, t) * w;\n R += r * w; Qt += t * w;\n }\n float invNorm = 1.0 / length(R); R *= invNorm; Qt *= invNorm;\n T = 2.0 * (R.w * Qt.xyz - Qt.w * R.xyz + cross(R.xyz, Qt.xyz)); \n}\nvec3 VectorTransformQuat(vec3 v, vec4 Q) {\n return v + 2.0 * cross(Q.xyz, cross(Q.xyz, v) + Q.w * v);\n}\nvoid skinVertex(inout vec4 pos) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n pos.xyz = VectorTransformQuat(pos.xyz * S, R) + T;\n}\nvoid skinVertex(inout vec4 pos, inout vec4 a2) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n pos.xyz = VectorTransformQuat(pos.xyz * S, R) + T;\n a2.xyz = VectorTransformQuat(a2.xyz, R);\n}\nvoid skinVertex(inout vec4 pos, inout vec4 a2, inout vec4 a3) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n pos.xyz = VectorTransformQuat(pos.xyz * S, R) + T;\n a2.xyz = VectorTransformQuat(a2.xyz, R);\n a3.xyz = VectorTransformQuat(a3.xyz, R);\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_SKINNING == 1\n \n uniform vec4 cc_matJoint[90];\n#else\n \n uniform vec4 cc_jointsTextureSizeInv;\n uniform sampler2D cc_jointsTexture;\n#endif\n#if CC_USE_SKINNING == 2\n float decode32(highp vec4 rgba) {\n rgba = rgba * 255.0; \n float Sign = 1.0 - step(128.0, rgba[3]) * 2.0;\n float Exponent = 2.0 * mod(rgba[3], 128.0) + step(128.0, rgba[2]) - 127.0;\n float Mantissa = mod(rgba[2], 128.0) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\n }\n#endif\n#if CC_USE_SKINNING == 1\n mat4 getJointMatrix(float i) {\n vec4 v1 = cc_matJoint[3 * int(i)];\n vec4 v2 = cc_matJoint[3 * int(i) + 1];\n vec4 v3 = cc_matJoint[3 * int(i) + 2];\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n#elif CC_USE_SKINNING == 2\n vec3 getJointMatrix(float i) {\n float y = (i + 0.5) * cc_jointsTextureSizeInv.y;\n vec4 v1 = vec4(\n decode32(texture2D(cc_jointsTexture, vec2((0.5 / 12.0), y))),\n decode32(texture2D(cc_jointsTexture, vec2((1.5 / 12.0), y))),\n decode32(texture2D(cc_jointsTexture, vec2((2.5 / 12.0), y))),\n decode32(texture2D(cc_jointsTexture, vec2((3.5 / 12.0), y)))\n );\n vec4 v2 = vec4(\n decode32(texture2D(cc_jointsTexture, vec2((4.5 / 12.0), y))),\n decode32(texture2D(cc_jointsTexture, vec2((5.5 / 12.0), y))),\n decode32(texture2D(cc_jointsTexture, vec2((6.5 / 12.0), y))),\n decode32(texture2D(cc_jointsTexture, vec2((7.5 / 12.0), y)))\n );\n vec4 v3 = vec4(\n decode32(texture2D(cc_jointsTexture, vec2((8.5 / 12.0), y))),\n decode32(texture2D(cc_jointsTexture, vec2((9.5 / 12.0), y))),\n decode32(texture2D(cc_jointsTexture, vec2((10.5 / 12.0), y))),\n decode32(texture2D(cc_jointsTexture, vec2((11.5 / 12.0), y)))\n );\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n#elif CC_USE_SKINNING == 3\n mat4 getJointMatrix(float i) {\n float y = (i + 0.5) * cc_jointsTextureSizeInv.y;\n vec4 v1 = texture2D(cc_jointsTexture, vec2((0.5 / 3.0), y));\n vec4 v2 = texture2D(cc_jointsTexture, vec2((1.5 / 3.0), y));\n vec4 v3 = texture2D(cc_jointsTexture, vec2((2.5 / 3.0), y));\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n#endif\nmat4 skinMatrix() {\n return getJointMatrix(a_joints.x) * a_weights.x\n + getJointMatrix(a_joints.y) * a_weights.y;\n + getJointMatrix(a_joints.z) * a_weights.z;\n + getJointMatrix(a_joints.w) * a_weights.w;\n}\nvoid skinVertex(inout vec4 pos) {\n mat4 m = skinMatrix();\n pos = m * pos;\n}\nvoid skinVertex(inout vec4 pos, inout vec4 a2) {\n mat4 m = skinMatrix();\n pos = m * pos;\n a2 = m * a2;\n}\nvoid skinVertex(inout vec4 pos, inout vec4 a2, inout vec4 a3) {\n mat4 m = skinMatrix();\n pos = m * pos;\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_SKINNING == 1\n \n uniform vec4 cc_matJoint[90];\n#else\n \n uniform vec4 cc_jointsTextureSizeInv;\n uniform sampler2D cc_jointsTexture;\n#endif\n#if CC_USE_SKINNING == 2\n float decode32(highp vec4 rgba) {\n rgba = rgba * 255.0; \n float Sign = 1.0 - step(128.0, rgba[3]) * 2.0;\n float Exponent = 2.0 * mod(rgba[3], 128.0) + step(128.0, rgba[2]) - 127.0;\n float Mantissa = mod(rgba[2], 128.0) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\n }\n#endif\n#if CC_USE_SKINNING == 1\n vec3 getJointDQ(float i, out vec4 Qr, out vec4 Qt) {\n Qr = cc_matJoint[3 * int(i)];\n Qt = cc_matJoint[3 * int(i) + 1];\n return cc_matJoint[3 * int(i) + 2].xyz;\n }\n#elif CC_USE_SKINNING == 2\n vec3 getJointDQ(float i, out vec4 Qr, out vec4 Qt) {\n float y = (i + 0.5) * cc_jointsTextureSizeInv.y;\n Qr = vec4(\n decode32(texture2D(cc_jointsTexture, vec2((0.5 / 12.0), y))),\n decode32(texture2D(cc_jointsTexture, vec2((1.5 / 12.0), y))),\n decode32(texture2D(cc_jointsTexture, vec2((2.5 / 12.0), y))),\n decode32(texture2D(cc_jointsTexture, vec2((3.5 / 12.0), y)))\n );\n Qt = vec4(\n decode32(texture2D(cc_jointsTexture, vec2((4.5 / 12.0), y))),\n decode32(texture2D(cc_jointsTexture, vec2((5.5 / 12.0), y))),\n decode32(texture2D(cc_jointsTexture, vec2((6.5 / 12.0), y))),\n decode32(texture2D(cc_jointsTexture, vec2((7.5 / 12.0), y)))\n );\n return vec3(\n decode32(texture2D(cc_jointsTexture, vec2((8.5 / 12.0), y))),\n decode32(texture2D(cc_jointsTexture, vec2((9.5 / 12.0), y))),\n decode32(texture2D(cc_jointsTexture, vec2((10.5 / 12.0), y)))\n );\n }\n#elif CC_USE_SKINNING == 3\n vec3 getJointDQ(float i, out vec4 Qr, out vec4 Qt) {\n float y = (i + 0.5) * cc_jointsTextureSizeInv.y;\n Qr = texture2D(cc_jointsTexture, vec2((0.5 / 3.0), y));\n Qt = texture2D(cc_jointsTexture, vec2((1.5 / 3.0), y));\n return texture2D(cc_jointsTexture, vec2((2.5 / 3.0), y)).xyz;\n }\n#endif\nvoid skinRTS(out vec4 R, out vec3 T, out vec3 S) {\n vec4 r, t, Qt = vec4(0.0);\n R = vec4(0.0); S = vec3(0.0);\n for (int i = 0; i < 4; i++) {\n float w = a_weights[i];\n S += getJointDQ(a_joints[i], r, t) * w;\n R += r * w; Qt += t * w;\n }\n float invNorm = 1.0 / length(R); R *= invNorm; Qt *= invNorm;\n T = 2.0 * (R.w * Qt.xyz - Qt.w * R.xyz + cross(R.xyz, Qt.xyz)); \n}\nvec3 VectorTransformQuat(vec3 v, vec4 Q) {\n return v + 2.0 * cross(Q.xyz, cross(Q.xyz, v) + Q.w * v);\n}\nvoid skinVertex(inout vec4 pos) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n pos.xyz = VectorTransformQuat(pos.xyz * S, R) + T;\n}\nvoid skinVertex(inout vec4 pos, inout vec4 a2) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n pos.xyz = VectorTransformQuat(pos.xyz * S, R) + T;\n a2.xyz = VectorTransformQuat(a2.xyz, R);\n}\nvoid skinVertex(inout vec4 pos, inout vec4 a2, inout vec4 a3) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n pos.xyz = VectorTransformQuat(pos.xyz * S, R) + T;\n a2.xyz = VectorTransformQuat(a2.xyz, R);\n a3.xyz = VectorTransformQuat(a3.xyz, R);\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", "CCSkinning", "CCSkinningTexture"], "samplers":["cc_jointsTexture"]}}, @@ -269,13 +270,13 @@ export default [ "shaders": [ { "name": "builtin-unlit|unlit-vs:vert|unlit-fs:frag", - "hash": 1031276028, + "hash": 1632165798, "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_SKINNING == 1\n \n uniform CCSkinning {\n vec4 cc_matJoint[30 * 3];\n };\n#else\n \n uniform CCSkinningTexture {\n vec4 cc_jointsTextureSizeInv;\n };\n \n uniform sampler2D cc_jointsTexture;\n#endif\n#if CC_USE_SKINNING == 2\n float decode32(highp vec4 rgba) {\n rgba = rgba * 255.0; \n float Sign = 1.0 - step(128.0, rgba[3]) * 2.0;\n float Exponent = 2.0 * mod(rgba[3], 128.0) + step(128.0, rgba[2]) - 127.0;\n float Mantissa = mod(rgba[2], 128.0) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\n }\n#endif\n#if CC_USE_SKINNING == 1\n mat4 getJointMatrix(float i) {\n vec4 v1 = cc_matJoint[3 * int(i)];\n vec4 v2 = cc_matJoint[3 * int(i) + 1];\n vec4 v3 = cc_matJoint[3 * int(i) + 2];\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n#elif CC_USE_SKINNING == 2\n vec3 getJointMatrix(float i) {\n float y = (i + 0.5) * cc_jointsTextureSizeInv.y;\n vec4 v1 = vec4(\n decode32(texture(cc_jointsTexture, vec2((0.5 / 12.0), y))),\n decode32(texture(cc_jointsTexture, vec2((1.5 / 12.0), y))),\n decode32(texture(cc_jointsTexture, vec2((2.5 / 12.0), y))),\n decode32(texture(cc_jointsTexture, vec2((3.5 / 12.0), y)))\n );\n vec4 v2 = vec4(\n decode32(texture(cc_jointsTexture, vec2((4.5 / 12.0), y))),\n decode32(texture(cc_jointsTexture, vec2((5.5 / 12.0), y))),\n decode32(texture(cc_jointsTexture, vec2((6.5 / 12.0), y))),\n decode32(texture(cc_jointsTexture, vec2((7.5 / 12.0), y)))\n );\n vec4 v3 = vec4(\n decode32(texture(cc_jointsTexture, vec2((8.5 / 12.0), y))),\n decode32(texture(cc_jointsTexture, vec2((9.5 / 12.0), y))),\n decode32(texture(cc_jointsTexture, vec2((10.5 / 12.0), y))),\n decode32(texture(cc_jointsTexture, vec2((11.5 / 12.0), y)))\n );\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n#elif CC_USE_SKINNING == 3\n mat4 getJointMatrix(float i) {\n float y = (i + 0.5) * cc_jointsTextureSizeInv.y;\n vec4 v1 = texture(cc_jointsTexture, vec2((0.5 / 3.0), y));\n vec4 v2 = texture(cc_jointsTexture, vec2((1.5 / 3.0), y));\n vec4 v3 = texture(cc_jointsTexture, vec2((2.5 / 3.0), y));\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n#endif\nmat4 skinMatrix() {\n return getJointMatrix(a_joints.x) * a_weights.x\n + getJointMatrix(a_joints.y) * a_weights.y;\n + getJointMatrix(a_joints.z) * a_weights.z;\n + getJointMatrix(a_joints.w) * a_weights.w;\n}\nvoid skinVertex(inout vec4 pos) {\n mat4 m = skinMatrix();\n pos = m * pos;\n}\nvoid skinVertex(inout vec4 pos, inout vec4 a2) {\n mat4 m = skinMatrix();\n pos = m * pos;\n a2 = m * a2;\n}\nvoid skinVertex(inout vec4 pos, inout vec4 a2, inout vec4 a3) {\n mat4 m = skinMatrix();\n pos = m * pos;\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 #endif\n pos = cc_matViewProj * cc_matWorld * 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_SKINNING == 1\n \n uniform CCSkinning {\n vec4 cc_matJoint[30 * 3];\n };\n#else\n \n uniform CCSkinningTexture {\n vec4 cc_jointsTextureSizeInv;\n };\n \n uniform sampler2D cc_jointsTexture;\n#endif\n#if CC_USE_SKINNING == 2\n float decode32(highp vec4 rgba) {\n rgba = rgba * 255.0; \n float Sign = 1.0 - step(128.0, rgba[3]) * 2.0;\n float Exponent = 2.0 * mod(rgba[3], 128.0) + step(128.0, rgba[2]) - 127.0;\n float Mantissa = mod(rgba[2], 128.0) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\n }\n#endif\n#if CC_USE_SKINNING == 1\n vec3 getJointDQ(float i, out vec4 Qr, out vec4 Qt) {\n Qr = cc_matJoint[3 * int(i)];\n Qt = cc_matJoint[3 * int(i) + 1];\n return cc_matJoint[3 * int(i) + 2].xyz;\n }\n#elif CC_USE_SKINNING == 2\n vec3 getJointDQ(float i, out vec4 Qr, out vec4 Qt) {\n float y = (i + 0.5) * cc_jointsTextureSizeInv.y;\n Qr = vec4(\n decode32(texture(cc_jointsTexture, vec2((0.5 / 12.0), y))),\n decode32(texture(cc_jointsTexture, vec2((1.5 / 12.0), y))),\n decode32(texture(cc_jointsTexture, vec2((2.5 / 12.0), y))),\n decode32(texture(cc_jointsTexture, vec2((3.5 / 12.0), y)))\n );\n Qt = vec4(\n decode32(texture(cc_jointsTexture, vec2((4.5 / 12.0), y))),\n decode32(texture(cc_jointsTexture, vec2((5.5 / 12.0), y))),\n decode32(texture(cc_jointsTexture, vec2((6.5 / 12.0), y))),\n decode32(texture(cc_jointsTexture, vec2((7.5 / 12.0), y)))\n );\n return vec3(\n decode32(texture(cc_jointsTexture, vec2((8.5 / 12.0), y))),\n decode32(texture(cc_jointsTexture, vec2((9.5 / 12.0), y))),\n decode32(texture(cc_jointsTexture, vec2((10.5 / 12.0), y)))\n );\n }\n#elif CC_USE_SKINNING == 3\n vec3 getJointDQ(float i, out vec4 Qr, out vec4 Qt) {\n float y = (i + 0.5) * cc_jointsTextureSizeInv.y;\n Qr = texture(cc_jointsTexture, vec2((0.5 / 3.0), y));\n Qt = texture(cc_jointsTexture, vec2((1.5 / 3.0), y));\n return texture(cc_jointsTexture, vec2((2.5 / 3.0), y)).xyz;\n }\n#endif\nvoid skinRTS(out vec4 R, out vec3 T, out vec3 S) {\n vec4 r, t, Qt = vec4(0.0);\n R = vec4(0.0); S = vec3(0.0);\n for (int i = 0; i < 4; i++) {\n float w = a_weights[i];\n S += getJointDQ(a_joints[i], r, t) * w;\n R += r * w; Qt += t * w;\n }\n float invNorm = 1.0 / length(R); R *= invNorm; Qt *= invNorm;\n T = 2.0 * (R.w * Qt.xyz - Qt.w * R.xyz + cross(R.xyz, Qt.xyz)); \n}\nvec3 VectorTransformQuat(vec3 v, vec4 Q) {\n return v + 2.0 * cross(Q.xyz, cross(Q.xyz, v) + Q.w * v);\n}\nvoid skinVertex(inout vec4 pos) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n pos.xyz = VectorTransformQuat(pos.xyz * S, R) + T;\n}\nvoid skinVertex(inout vec4 pos, inout vec4 a2) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n pos.xyz = VectorTransformQuat(pos.xyz * S, R) + T;\n a2.xyz = VectorTransformQuat(a2.xyz, R);\n}\nvoid skinVertex(inout vec4 pos, inout vec4 a2, inout vec4 a3) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n pos.xyz = VectorTransformQuat(pos.xyz * S, R) + T;\n a2.xyz = VectorTransformQuat(a2.xyz, R);\n a3.xyz = VectorTransformQuat(a3.xyz, R);\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 #endif\n pos = cc_matViewProj * cc_matWorld * 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_SKINNING == 1\n \n uniform vec4 cc_matJoint[90];\n#else\n \n uniform vec4 cc_jointsTextureSizeInv;\n uniform sampler2D cc_jointsTexture;\n#endif\n#if CC_USE_SKINNING == 2\n float decode32(highp vec4 rgba) {\n rgba = rgba * 255.0; \n float Sign = 1.0 - step(128.0, rgba[3]) * 2.0;\n float Exponent = 2.0 * mod(rgba[3], 128.0) + step(128.0, rgba[2]) - 127.0;\n float Mantissa = mod(rgba[2], 128.0) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\n }\n#endif\n#if CC_USE_SKINNING == 1\n mat4 getJointMatrix(float i) {\n vec4 v1 = cc_matJoint[3 * int(i)];\n vec4 v2 = cc_matJoint[3 * int(i) + 1];\n vec4 v3 = cc_matJoint[3 * int(i) + 2];\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n#elif CC_USE_SKINNING == 2\n vec3 getJointMatrix(float i) {\n float y = (i + 0.5) * cc_jointsTextureSizeInv.y;\n vec4 v1 = vec4(\n decode32(texture2D(cc_jointsTexture, vec2((0.5 / 12.0), y))),\n decode32(texture2D(cc_jointsTexture, vec2((1.5 / 12.0), y))),\n decode32(texture2D(cc_jointsTexture, vec2((2.5 / 12.0), y))),\n decode32(texture2D(cc_jointsTexture, vec2((3.5 / 12.0), y)))\n );\n vec4 v2 = vec4(\n decode32(texture2D(cc_jointsTexture, vec2((4.5 / 12.0), y))),\n decode32(texture2D(cc_jointsTexture, vec2((5.5 / 12.0), y))),\n decode32(texture2D(cc_jointsTexture, vec2((6.5 / 12.0), y))),\n decode32(texture2D(cc_jointsTexture, vec2((7.5 / 12.0), y)))\n );\n vec4 v3 = vec4(\n decode32(texture2D(cc_jointsTexture, vec2((8.5 / 12.0), y))),\n decode32(texture2D(cc_jointsTexture, vec2((9.5 / 12.0), y))),\n decode32(texture2D(cc_jointsTexture, vec2((10.5 / 12.0), y))),\n decode32(texture2D(cc_jointsTexture, vec2((11.5 / 12.0), y)))\n );\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n#elif CC_USE_SKINNING == 3\n mat4 getJointMatrix(float i) {\n float y = (i + 0.5) * cc_jointsTextureSizeInv.y;\n vec4 v1 = texture2D(cc_jointsTexture, vec2((0.5 / 3.0), y));\n vec4 v2 = texture2D(cc_jointsTexture, vec2((1.5 / 3.0), y));\n vec4 v3 = texture2D(cc_jointsTexture, vec2((2.5 / 3.0), y));\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n#endif\nmat4 skinMatrix() {\n return getJointMatrix(a_joints.x) * a_weights.x\n + getJointMatrix(a_joints.y) * a_weights.y;\n + getJointMatrix(a_joints.z) * a_weights.z;\n + getJointMatrix(a_joints.w) * a_weights.w;\n}\nvoid skinVertex(inout vec4 pos) {\n mat4 m = skinMatrix();\n pos = m * pos;\n}\nvoid skinVertex(inout vec4 pos, inout vec4 a2) {\n mat4 m = skinMatrix();\n pos = m * pos;\n a2 = m * a2;\n}\nvoid skinVertex(inout vec4 pos, inout vec4 a2, inout vec4 a3) {\n mat4 m = skinMatrix();\n pos = m * pos;\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 #endif\n pos = cc_matViewProj * cc_matWorld * 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_SKINNING == 1\n \n uniform vec4 cc_matJoint[90];\n#else\n \n uniform vec4 cc_jointsTextureSizeInv;\n uniform sampler2D cc_jointsTexture;\n#endif\n#if CC_USE_SKINNING == 2\n float decode32(highp vec4 rgba) {\n rgba = rgba * 255.0; \n float Sign = 1.0 - step(128.0, rgba[3]) * 2.0;\n float Exponent = 2.0 * mod(rgba[3], 128.0) + step(128.0, rgba[2]) - 127.0;\n float Mantissa = mod(rgba[2], 128.0) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\n }\n#endif\n#if CC_USE_SKINNING == 1\n vec3 getJointDQ(float i, out vec4 Qr, out vec4 Qt) {\n Qr = cc_matJoint[3 * int(i)];\n Qt = cc_matJoint[3 * int(i) + 1];\n return cc_matJoint[3 * int(i) + 2].xyz;\n }\n#elif CC_USE_SKINNING == 2\n vec3 getJointDQ(float i, out vec4 Qr, out vec4 Qt) {\n float y = (i + 0.5) * cc_jointsTextureSizeInv.y;\n Qr = vec4(\n decode32(texture2D(cc_jointsTexture, vec2((0.5 / 12.0), y))),\n decode32(texture2D(cc_jointsTexture, vec2((1.5 / 12.0), y))),\n decode32(texture2D(cc_jointsTexture, vec2((2.5 / 12.0), y))),\n decode32(texture2D(cc_jointsTexture, vec2((3.5 / 12.0), y)))\n );\n Qt = vec4(\n decode32(texture2D(cc_jointsTexture, vec2((4.5 / 12.0), y))),\n decode32(texture2D(cc_jointsTexture, vec2((5.5 / 12.0), y))),\n decode32(texture2D(cc_jointsTexture, vec2((6.5 / 12.0), y))),\n decode32(texture2D(cc_jointsTexture, vec2((7.5 / 12.0), y)))\n );\n return vec3(\n decode32(texture2D(cc_jointsTexture, vec2((8.5 / 12.0), y))),\n decode32(texture2D(cc_jointsTexture, vec2((9.5 / 12.0), y))),\n decode32(texture2D(cc_jointsTexture, vec2((10.5 / 12.0), y)))\n );\n }\n#elif CC_USE_SKINNING == 3\n vec3 getJointDQ(float i, out vec4 Qr, out vec4 Qt) {\n float y = (i + 0.5) * cc_jointsTextureSizeInv.y;\n Qr = texture2D(cc_jointsTexture, vec2((0.5 / 3.0), y));\n Qt = texture2D(cc_jointsTexture, vec2((1.5 / 3.0), y));\n return texture2D(cc_jointsTexture, vec2((2.5 / 3.0), y)).xyz;\n }\n#endif\nvoid skinRTS(out vec4 R, out vec3 T, out vec3 S) {\n vec4 r, t, Qt = vec4(0.0);\n R = vec4(0.0); S = vec3(0.0);\n for (int i = 0; i < 4; i++) {\n float w = a_weights[i];\n S += getJointDQ(a_joints[i], r, t) * w;\n R += r * w; Qt += t * w;\n }\n float invNorm = 1.0 / length(R); R *= invNorm; Qt *= invNorm;\n T = 2.0 * (R.w * Qt.xyz - Qt.w * R.xyz + cross(R.xyz, Qt.xyz)); \n}\nvec3 VectorTransformQuat(vec3 v, vec4 Q) {\n return v + 2.0 * cross(Q.xyz, cross(Q.xyz, v) + Q.w * v);\n}\nvoid skinVertex(inout vec4 pos) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n pos.xyz = VectorTransformQuat(pos.xyz * S, R) + T;\n}\nvoid skinVertex(inout vec4 pos, inout vec4 a2) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n pos.xyz = VectorTransformQuat(pos.xyz * S, R) + T;\n a2.xyz = VectorTransformQuat(a2.xyz, R);\n}\nvoid skinVertex(inout vec4 pos, inout vec4 a2, inout vec4 a3) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n pos.xyz = VectorTransformQuat(pos.xyz * S, R) + T;\n a2.xyz = VectorTransformQuat(a2.xyz, R);\n a3.xyz = VectorTransformQuat(a3.xyz, R);\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 #endif\n pos = cc_matViewProj * cc_matWorld * 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", "CCSkinning", "CCSkinningTexture"], "samplers":["cc_jointsTexture"]}}, diff --git a/cocos/3d/builtin/init.ts b/cocos/3d/builtin/init.ts index 00ab0cf6b8..b219da53ff 100644 --- a/cocos/3d/builtin/init.ts +++ b/cocos/3d/builtin/init.ts @@ -129,7 +129,7 @@ class BuiltinResMgr { resources[spriteFrame._uuid] = spriteFrame; // builtin effects - effects.forEach((e: any) => { + effects.forEach((e) => { const effect = Object.assign(new cc.EffectAsset(), e); effect.onLoaded(); }); diff --git a/cocos/3d/framework/skinning-model-component.ts b/cocos/3d/framework/skinning-model-component.ts index 92f317b25f..5a262997a4 100644 --- a/cocos/3d/framework/skinning-model-component.ts +++ b/cocos/3d/framework/skinning-model-component.ts @@ -178,7 +178,7 @@ export class SkinningModelComponent extends ModelComponent { quat.multiply(qt_1, cur.rotation, bindpose.localRotation); vec3.multiply(v3_2, cur.scale, bindpose.localScale); - skinningModel.updateJointData(i, v3_1, qt_1, v3_2); + skinningModel.updateJointData(i, v3_1, qt_1, v3_2, i === 0); } skinningModel.commitJointData(); diff --git a/cocos/renderer/models/skinning-model.ts b/cocos/renderer/models/skinning-model.ts index 13864031b7..fe689e150b 100644 --- a/cocos/renderer/models/skinning-model.ts +++ b/cocos/renderer/models/skinning-model.ts @@ -52,6 +52,9 @@ const qt_1 = new Quat(); const f4_1 = new Float32Array(4); export class SkinningModel extends Model { + // change here and cc-skinning.inc to use other skinning algorithms + public updateJointData = this.updateJointDataDQS; + private _jointsMedium: IJointsInfo | null = null; constructor (scene: RenderScene, node: Node) { @@ -89,11 +92,21 @@ export class SkinningModel extends Model { } } - public updateJointData (idx: number, pos: Vec3, rot: Quat, scale: Vec3) { + public commitJointData () { + if (!this._jointsMedium) { return; } + const { type, nativeData, buffer, texture } = this._jointsMedium; + if (type === JointsMediumType.UNIFORM) { + buffer.update(nativeData, UBOSkinning.MAT_JOINT_OFFSET); + } else { + texture!.uploadData(nativeData.buffer); + } + } + + // Linear Blending Skinning + protected updateJointDataLBS (idx: number, pos: Vec3, rot: Quat, scale: Vec3) { if (!this._jointsMedium) { return; } const out = this._jointsMedium.nativeData; const base = 12 * idx; - /* Linear Blending Skinning */ mat4.fromRTS(m4_1, rot, pos, scale); out[base + 0] = m4_1.m00; out[base + 1] = m4_1.m01; @@ -107,9 +120,15 @@ export class SkinningModel extends Model { out[base + 9] = m4_1.m09; out[base + 10] = m4_1.m10; out[base + 11] = m4_1.m14; - /* Dual Quaternion Skinning * + } + + // Dual Quaternion Skinning + protected updateJointDataDQS (idx: number, pos: Vec3, rot: Quat, scale: Vec3, first = false) { + if (!this._jointsMedium) { return; } + const out = this._jointsMedium.nativeData; + const base = 12 * idx; // sign consistency - if (idx === 0) { quat.copy(qt_0, rot); } + if (first) { quat.copy(qt_0, rot); } else if (quat.dot(qt_0, rot) < 0) { quat.scale(rot, rot, -1); } // conversion quat.set(qt_1, pos.x, pos.y, pos.z, 0); @@ -126,17 +145,6 @@ export class SkinningModel extends Model { out[base + 8] = scale.x; out[base + 9] = scale.y; out[base + 10] = scale.z; - /* */ - } - - public commitJointData () { - if (!this._jointsMedium) { return; } - const { type, nativeData, buffer, texture } = this._jointsMedium; - if (type === JointsMediumType.UNIFORM) { - buffer.update(nativeData, UBOSkinning.MAT_JOINT_OFFSET); - } else { - texture!.uploadData(nativeData.buffer); - } } protected _doCreatePSO (pass: Pass) {