diff --git a/cocos/3d/builtin/effects.ts b/cocos/3d/builtin/effects.ts index 38fe567159..2457f39370 100644 --- a/cocos/3d/builtin/effects.ts +++ b/cocos/3d/builtin/effects.ts @@ -9,14 +9,14 @@ export default [ "shaders": [ { "name": "builtin-billboard|vert:vs_main|tinted-fs:add", - "hash": 1837336543, + "hash": 2332126617, "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 1 || 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 1\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 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 vec2 a_texCoord;\nin vec4 a_color;\nuniform builtin {\n vec4 cc_size_rotation;\n};\nvec4 vs_main() {\n vec4 pos = vec4(a_position, 1);\n pos = cc_matWorld * pos;\n vec2 vertOffset = (a_texCoord.xy - 0.5) * cc_size_rotation.xy;\n rotateCorner(vertOffset, cc_size_rotation.z);\n computeVertPos(pos, vertOffset, cc_matView);\n pos = cc_matViewProj * pos;\n uv = a_texCoord.xy;\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 CCOutput(vec4 color) {\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 CCOutput(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 CCOutput(col);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = add(); }\n` + "vert": `\nprecision mediump float;\nuniform Constants {\n vec4 mainTiling_Offset;\n vec4 frameTile_velLenScale;\n vec4 scale;\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, vec3 scale\n#if 1 || 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 1\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)) * scale;\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) * scale;\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)) * scale;\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)) * scale;\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 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 vec2 a_texCoord;\nin vec4 a_color;\nuniform builtin {\n vec4 cc_size_rotation;\n};\nvec4 vs_main() {\n vec4 pos = vec4(a_position, 1);\n pos = cc_matWorld * pos;\n vec2 vertOffset = (a_texCoord.xy - 0.5) * cc_size_rotation.xy;\n rotateCorner(vertOffset, cc_size_rotation.z);\n computeVertPos(pos, vertOffset, cc_matView);\n pos = cc_matViewProj * pos;\n uv = a_texCoord.xy;\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 CCFragOutput(vec4 color) {\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 CCFragOutput(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 CCFragOutput(col);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = add(); }\n` }, "glsl1": { - "vert": `\nprecision mediump float;\nuniform mat4 cc_matView;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matWorld;\nvarying vec2 uv;\nvarying vec4 color;\nvoid computeVertPos(inout vec4 pos, vec2 vertOffset\n#if 1 || 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 1\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 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 vec2 a_texCoord;\nattribute vec4 a_color;\nuniform vec4 cc_size_rotation;\nvec4 vs_main() {\n vec4 pos = vec4(a_position, 1);\n pos = cc_matWorld * pos;\n vec2 vertOffset = (a_texCoord.xy - 0.5) * cc_size_rotation.xy;\n rotateCorner(vertOffset, cc_size_rotation.z);\n computeVertPos(pos, vertOffset, cc_matView);\n pos = cc_matViewProj * pos;\n uv = a_texCoord.xy;\n color = a_color;\n return pos;\n}\nvoid main() { gl_Position = vs_main(); }\n`, - "frag": `\nprecision mediump float;\nuniform vec4 cc_exposure;\nvec4 CCOutput(vec4 color) {\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 CCOutput(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 CCOutput(col);\n}\nvoid main() { gl_FragColor = add(); }\n` + "vert": `\nprecision mediump float;\nuniform vec4 scale;\nuniform mat4 cc_matView;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matWorld;\nvarying vec2 uv;\nvarying vec4 color;\nvoid computeVertPos(inout vec4 pos, vec2 vertOffset, vec3 scale\n#if 1 || 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 1\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)) * scale;\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) * scale;\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)) * scale;\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)) * scale;\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 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 vec2 a_texCoord;\nattribute vec4 a_color;\nuniform vec4 cc_size_rotation;\nvec4 vs_main() {\n vec4 pos = vec4(a_position, 1);\n pos = cc_matWorld * pos;\n vec2 vertOffset = (a_texCoord.xy - 0.5) * cc_size_rotation.xy;\n rotateCorner(vertOffset, cc_size_rotation.z);\n computeVertPos(pos, vertOffset, cc_matView);\n pos = cc_matViewProj * pos;\n uv = a_texCoord.xy;\n color = a_color;\n return pos;\n}\nvoid main() { gl_Position = vs_main(); }\n`, + "frag": `\nprecision mediump float;\nuniform vec4 cc_exposure;\nvec4 CCFragOutput(vec4 color) {\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 CCFragOutput(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 CCFragOutput(col);\n}\nvoid main() { gl_FragColor = add(); }\n` }, "builtins": {"globals":{"blocks":["CCGlobal"], "samplers":[]}, "locals":{"blocks":["CCLocal"], "samplers":[]}}, "defines": [ @@ -26,9 +26,10 @@ export default [ {"name":"CC_USE_HDR", "type":"boolean", "defines":[]} ], "blocks": [ - {"name": "Constants", "size": 32, "defines": [], "binding": 0, "members": [ + {"name": "Constants", "size": 48, "defines": [], "binding": 0, "members": [ {"name":"mainTiling_Offset", "type":16, "count":1, "size":16}, - {"name":"frameTile_velLenScale", "type":16, "count":1, "size":16} + {"name":"frameTile_velLenScale", "type":16, "count":1, "size":16}, + {"name":"scale", "type":16, "count":1, "size":16} ]}, {"name": "builtin", "size": 16, "defines": [], "binding": 1, "members": [ {"name":"cc_size_rotation", "type":16, "count":1, "size":16} @@ -38,7 +39,7 @@ export default [ ]} ], "samplers": [ - {"name":"mainTexture", "type":28, "count":1, "defines":[], "binding":3} + {"name":"mainTexture", "type":28, "count":1, "defines":[], "binding":30} ], "dependencies": {} } @@ -52,14 +53,14 @@ export default [ "shaders": [ { "name": "builtin-particle-trail|particle-trail:vs_main|tinted-fs:add", - "hash": 3035112421, + "hash": 3275786469, "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 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 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 CCOutput(vec4 color) {\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 CCOutput(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 CCOutput(col);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = add(); }\n` + "vert": `\nprecision mediump float;\nuniform Constants {\n vec4 mainTiling_Offset;\n vec4 frameTile_velLenScale;\n vec4 scale;\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, vec3 scale\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)) * scale;\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) * scale;\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)) * scale;\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)) * scale;\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 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 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 CCFragOutput(vec4 color) {\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 CCFragOutput(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 CCFragOutput(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 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 mediump float;\nuniform vec4 cc_exposure;\nvec4 CCOutput(vec4 color) {\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 CCOutput(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 CCOutput(col);\n}\nvoid main() { gl_FragColor = add(); }\n` + "vert": `\nprecision mediump float;\nuniform vec4 mainTiling_Offset;\nuniform vec4 scale;\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, vec3 scale\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)) * scale;\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) * scale;\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)) * scale;\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)) * scale;\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 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 mediump float;\nuniform vec4 cc_exposure;\nvec4 CCFragOutput(vec4 color) {\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 CCFragOutput(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 CCFragOutput(col);\n}\nvoid main() { gl_FragColor = add(); }\n` }, "builtins": {"globals":{"blocks":["CCGlobal"], "samplers":[]}, "locals":{"blocks":["CCLocal"], "samplers":[]}}, "defines": [ @@ -71,16 +72,17 @@ export default [ {"name":"CC_USE_HDR", "type":"boolean", "defines":[]} ], "blocks": [ - {"name": "Constants", "size": 32, "defines": [], "binding": 0, "members": [ + {"name": "Constants", "size": 48, "defines": [], "binding": 0, "members": [ {"name":"mainTiling_Offset", "type":16, "count":1, "size":16}, - {"name":"frameTile_velLenScale", "type":16, "count":1, "size":16} + {"name":"frameTile_velLenScale", "type":16, "count":1, "size":16}, + {"name":"scale", "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} + {"name":"mainTexture", "type":28, "count":1, "defines":[], "binding":30} ], "dependencies": {} } @@ -94,14 +96,14 @@ export default [ "shaders": [ { "name": "builtin-particle|particle-vs-legacy:lpvs_main|tinted-fs:add", - "hash": 1777415840, + "hash": 1707658047, "glsl3": { - "vert": `\nprecision highp 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 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}\nvec4 quaternionFromAxisAngle(float angle, vec3 axis){\n angle /= 2.;\n float s = sin(angle);\n vec4 res;\n res.xyz = s * axis;\n res.w = cos(angle);\n return res;\n}\nmat4 matrixFromRT(vec4 q, vec3 p){\n float x2 = q.x + q.x;\n float y2 = q.y + q.y;\n float z2 = q.z + q.z;\n float xx = q.x * x2;\n float xy = q.x * y2;\n float xz = q.x * z2;\n float yy = q.y * y2;\n float yz = q.y * z2;\n float zz = q.z * z2;\n float wx = q.w * x2;\n float wy = q.w * y2;\n float wz = q.w * z2;\n return mat4(\n 1. - (yy + zz), xy + wz, xz - wy, 0,\n xy - wz, 1. - (xx + zz), yz + wx, 0,\n xz + wy, yz - wx, 1. - (xx + yy), 0,\n p.x, p.y, p.z, 1\n );\n}\nvoid scaleMatrix(inout mat4 m, float s){\n m[0].xyz *= s;\n m[1].xyz *= s;\n m[2].xyz *= s;\n}\nin vec3 a_position;\nin vec3 a_texCoord;\nin vec2 a_texCoord1;\nin vec4 a_color;\n#if CC_USE_STRETCHED_BILLBOARD\n in vec3 a_color1;\n#endif\n#if CC_USE_MESH\n in vec3 a_texCoord2;\n in vec3 a_normal;\n in vec4 a_color1;\n#endif\nvec4 lpvs_main() {\n #if CC_USE_MESH\n vec4 pos = vec4(a_texCoord2, 1);\n mat4 xformNoScale = matrixFromRT(quaternionFromAxisAngle(a_texCoord1.y, vec3(0, 0, -1)), a_position);\n mat4 xform = mat4(xformNoScale);\n scaleMatrix(xform, a_texCoord1.x);\n pos = xform * pos;\n vec4 normal = xformNoScale * vec4(a_normal,0);\n #else\n vec4 pos = vec4(a_position, 1);\n #if CC_USE_STRETCHED_BILLBOARD\n vec4 velocity = vec4(a_color1.xyz, 0);\n #endif\n #endif\n #if !CC_USE_WORLD_SPACE\n pos = cc_matWorld * pos;\n #if CC_USE_STRETCHED_BILLBOARD\n velocity = cc_matWorld * velocity;\n #endif\n #endif\n #if !CC_USE_MESH\n vec2 cornerOffset = vec2((a_texCoord.xy - 0.5) * a_texCoord1.x);\n #if !CC_USE_STRETCHED_BILLBOARD\n rotateCorner(cornerOffset, a_texCoord1.y);\n #endif\n computeVertPos(pos, cornerOffset\n #if CC_USE_BILLBOARD || CC_USE_VERTICAL_BILLBOARD\n , cc_matView\n #endif\n #if CC_USE_STRETCHED_BILLBOARD\n , cc_cameraPos.xyz\n , velocity\n , frameTile_velLenScale.z\n , frameTile_velLenScale.w\n , a_texCoord1.x\n , a_texCoord.x\n #endif\n );\n uv = computeUV(a_texCoord.z, a_texCoord.xy, frameTile_velLenScale.xy) * mainTiling_Offset.xy + mainTiling_Offset.zw;\n color = a_color;\n #else\n uv = a_texCoord.xy;\n color = a_color * a_color1;\n #endif\n pos = cc_matViewProj * pos;\n return pos;\n}\nvoid main() { gl_Position = lpvs_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 CCOutput(vec4 color) {\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 CCOutput(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 CCOutput(col);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = add(); }\n` + "vert": `\nprecision highp float;\nuniform Constants {\n vec4 mainTiling_Offset;\n vec4 frameTile_velLenScale;\n vec4 scale;\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, vec3 scale\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)) * scale;\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) * scale;\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)) * scale;\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)) * scale;\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 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}\nvec4 quaternionFromAxisAngle(float angle, vec3 axis){\n angle /= 2.;\n float s = sin(angle);\n vec4 res;\n res.xyz = s * axis;\n res.w = cos(angle);\n return res;\n}\nmat4 matrixFromRT(vec4 q, vec3 p){\n float x2 = q.x + q.x;\n float y2 = q.y + q.y;\n float z2 = q.z + q.z;\n float xx = q.x * x2;\n float xy = q.x * y2;\n float xz = q.x * z2;\n float yy = q.y * y2;\n float yz = q.y * z2;\n float zz = q.z * z2;\n float wx = q.w * x2;\n float wy = q.w * y2;\n float wz = q.w * z2;\n return mat4(\n 1. - (yy + zz), xy + wz, xz - wy, 0,\n xy - wz, 1. - (xx + zz), yz + wx, 0,\n xz + wy, yz - wx, 1. - (xx + yy), 0,\n p.x, p.y, p.z, 1\n );\n}\nvoid scaleMatrix(inout mat4 m, float s){\n m[0].xyz *= s;\n m[1].xyz *= s;\n m[2].xyz *= s;\n}\nin vec3 a_position;\nin vec3 a_texCoord;\nin vec2 a_texCoord1;\nin vec4 a_color;\n#if CC_USE_STRETCHED_BILLBOARD\n in vec3 a_color1;\n#endif\n#if CC_USE_MESH\n in vec3 a_texCoord2;\n in vec3 a_normal;\n in vec4 a_color1;\n#endif\nvec4 lpvs_main() {\n #if CC_USE_MESH\n vec4 pos = vec4(a_texCoord2, 1);\n mat4 xformNoScale = matrixFromRT(quaternionFromAxisAngle(a_texCoord1.y, vec3(0, 0, -1)), a_position);\n mat4 xform = mat4(xformNoScale);\n scaleMatrix(xform, a_texCoord1.x);\n pos = xform * pos;\n vec4 normal = xformNoScale * vec4(a_normal,0);\n #else\n vec4 pos = vec4(a_position, 1);\n #if CC_USE_STRETCHED_BILLBOARD\n vec4 velocity = vec4(a_color1.xyz, 0);\n #endif\n #endif\n #if !CC_USE_WORLD_SPACE\n pos = cc_matWorld * pos;\n #if CC_USE_STRETCHED_BILLBOARD\n velocity = cc_matWorld * velocity;\n #endif\n #endif\n #if !CC_USE_MESH\n vec2 cornerOffset = vec2((a_texCoord.xy - 0.5) * a_texCoord1.x);\n #if !CC_USE_STRETCHED_BILLBOARD\n rotateCorner(cornerOffset, a_texCoord1.y);\n #endif\n computeVertPos(pos, cornerOffset, vec3(scale)\n #if CC_USE_BILLBOARD || CC_USE_VERTICAL_BILLBOARD\n , cc_matView\n #endif\n #if CC_USE_STRETCHED_BILLBOARD\n , cc_cameraPos.xyz\n , velocity\n , frameTile_velLenScale.z\n , frameTile_velLenScale.w\n , a_texCoord1.x\n , a_texCoord.x\n #endif\n );\n uv = computeUV(a_texCoord.z, a_texCoord.xy, frameTile_velLenScale.xy) * mainTiling_Offset.xy + mainTiling_Offset.zw;\n color = a_color;\n #else\n uv = a_texCoord.xy;\n color = a_color * a_color1;\n #endif\n pos = cc_matViewProj * pos;\n return pos;\n}\nvoid main() { gl_Position = lpvs_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 CCFragOutput(vec4 color) {\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 CCFragOutput(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 CCFragOutput(col);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = add(); }\n` }, "glsl1": { - "vert": `\nprecision highp float;\nuniform vec4 mainTiling_Offset;\nuniform vec4 frameTile_velLenScale;\nuniform mat4 cc_matView;\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 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}\nvec4 quaternionFromAxisAngle(float angle, vec3 axis){\n angle /= 2.;\n float s = sin(angle);\n vec4 res;\n res.xyz = s * axis;\n res.w = cos(angle);\n return res;\n}\nmat4 matrixFromRT(vec4 q, vec3 p){\n float x2 = q.x + q.x;\n float y2 = q.y + q.y;\n float z2 = q.z + q.z;\n float xx = q.x * x2;\n float xy = q.x * y2;\n float xz = q.x * z2;\n float yy = q.y * y2;\n float yz = q.y * z2;\n float zz = q.z * z2;\n float wx = q.w * x2;\n float wy = q.w * y2;\n float wz = q.w * z2;\n return mat4(\n 1. - (yy + zz), xy + wz, xz - wy, 0,\n xy - wz, 1. - (xx + zz), yz + wx, 0,\n xz + wy, yz - wx, 1. - (xx + yy), 0,\n p.x, p.y, p.z, 1\n );\n}\nvoid scaleMatrix(inout mat4 m, float s){\n m[0].xyz *= s;\n m[1].xyz *= s;\n m[2].xyz *= s;\n}\nattribute vec3 a_position;\nattribute vec3 a_texCoord;\nattribute vec2 a_texCoord1;\nattribute vec4 a_color;\n#if CC_USE_STRETCHED_BILLBOARD\n attribute vec3 a_color1;\n#endif\n#if CC_USE_MESH\n attribute vec3 a_texCoord2;\n attribute vec3 a_normal;\n attribute vec4 a_color1;\n#endif\nvec4 lpvs_main() {\n #if CC_USE_MESH\n vec4 pos = vec4(a_texCoord2, 1);\n mat4 xformNoScale = matrixFromRT(quaternionFromAxisAngle(a_texCoord1.y, vec3(0, 0, -1)), a_position);\n mat4 xform = mat4(xformNoScale);\n scaleMatrix(xform, a_texCoord1.x);\n pos = xform * pos;\n vec4 normal = xformNoScale * vec4(a_normal,0);\n #else\n vec4 pos = vec4(a_position, 1);\n #if CC_USE_STRETCHED_BILLBOARD\n vec4 velocity = vec4(a_color1.xyz, 0);\n #endif\n #endif\n #if !CC_USE_WORLD_SPACE\n pos = cc_matWorld * pos;\n #if CC_USE_STRETCHED_BILLBOARD\n velocity = cc_matWorld * velocity;\n #endif\n #endif\n #if !CC_USE_MESH\n vec2 cornerOffset = vec2((a_texCoord.xy - 0.5) * a_texCoord1.x);\n #if !CC_USE_STRETCHED_BILLBOARD\n rotateCorner(cornerOffset, a_texCoord1.y);\n #endif\n computeVertPos(pos, cornerOffset\n #if CC_USE_BILLBOARD || CC_USE_VERTICAL_BILLBOARD\n , cc_matView\n #endif\n #if CC_USE_STRETCHED_BILLBOARD\n , cc_cameraPos.xyz\n , velocity\n , frameTile_velLenScale.z\n , frameTile_velLenScale.w\n , a_texCoord1.x\n , a_texCoord.x\n #endif\n );\n uv = computeUV(a_texCoord.z, a_texCoord.xy, frameTile_velLenScale.xy) * mainTiling_Offset.xy + mainTiling_Offset.zw;\n color = a_color;\n #else\n uv = a_texCoord.xy;\n color = a_color * a_color1;\n #endif\n pos = cc_matViewProj * pos;\n return pos;\n}\nvoid main() { gl_Position = lpvs_main(); }\n`, - "frag": `\nprecision highp float;\nuniform vec4 cc_exposure;\nvec4 CCOutput(vec4 color) {\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 CCOutput(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 CCOutput(col);\n}\nvoid main() { gl_FragColor = add(); }\n` + "vert": `\nprecision highp float;\nuniform vec4 mainTiling_Offset;\nuniform vec4 frameTile_velLenScale;\nuniform vec4 scale;\nuniform mat4 cc_matView;\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, vec3 scale\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)) * scale;\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) * scale;\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)) * scale;\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)) * scale;\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 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}\nvec4 quaternionFromAxisAngle(float angle, vec3 axis){\n angle /= 2.;\n float s = sin(angle);\n vec4 res;\n res.xyz = s * axis;\n res.w = cos(angle);\n return res;\n}\nmat4 matrixFromRT(vec4 q, vec3 p){\n float x2 = q.x + q.x;\n float y2 = q.y + q.y;\n float z2 = q.z + q.z;\n float xx = q.x * x2;\n float xy = q.x * y2;\n float xz = q.x * z2;\n float yy = q.y * y2;\n float yz = q.y * z2;\n float zz = q.z * z2;\n float wx = q.w * x2;\n float wy = q.w * y2;\n float wz = q.w * z2;\n return mat4(\n 1. - (yy + zz), xy + wz, xz - wy, 0,\n xy - wz, 1. - (xx + zz), yz + wx, 0,\n xz + wy, yz - wx, 1. - (xx + yy), 0,\n p.x, p.y, p.z, 1\n );\n}\nvoid scaleMatrix(inout mat4 m, float s){\n m[0].xyz *= s;\n m[1].xyz *= s;\n m[2].xyz *= s;\n}\nattribute vec3 a_position;\nattribute vec3 a_texCoord;\nattribute vec2 a_texCoord1;\nattribute vec4 a_color;\n#if CC_USE_STRETCHED_BILLBOARD\n attribute vec3 a_color1;\n#endif\n#if CC_USE_MESH\n attribute vec3 a_texCoord2;\n attribute vec3 a_normal;\n attribute vec4 a_color1;\n#endif\nvec4 lpvs_main() {\n #if CC_USE_MESH\n vec4 pos = vec4(a_texCoord2, 1);\n mat4 xformNoScale = matrixFromRT(quaternionFromAxisAngle(a_texCoord1.y, vec3(0, 0, -1)), a_position);\n mat4 xform = mat4(xformNoScale);\n scaleMatrix(xform, a_texCoord1.x);\n pos = xform * pos;\n vec4 normal = xformNoScale * vec4(a_normal,0);\n #else\n vec4 pos = vec4(a_position, 1);\n #if CC_USE_STRETCHED_BILLBOARD\n vec4 velocity = vec4(a_color1.xyz, 0);\n #endif\n #endif\n #if !CC_USE_WORLD_SPACE\n pos = cc_matWorld * pos;\n #if CC_USE_STRETCHED_BILLBOARD\n velocity = cc_matWorld * velocity;\n #endif\n #endif\n #if !CC_USE_MESH\n vec2 cornerOffset = vec2((a_texCoord.xy - 0.5) * a_texCoord1.x);\n #if !CC_USE_STRETCHED_BILLBOARD\n rotateCorner(cornerOffset, a_texCoord1.y);\n #endif\n computeVertPos(pos, cornerOffset, vec3(scale)\n #if CC_USE_BILLBOARD || CC_USE_VERTICAL_BILLBOARD\n , cc_matView\n #endif\n #if CC_USE_STRETCHED_BILLBOARD\n , cc_cameraPos.xyz\n , velocity\n , frameTile_velLenScale.z\n , frameTile_velLenScale.w\n , a_texCoord1.x\n , a_texCoord.x\n #endif\n );\n uv = computeUV(a_texCoord.z, a_texCoord.xy, frameTile_velLenScale.xy) * mainTiling_Offset.xy + mainTiling_Offset.zw;\n color = a_color;\n #else\n uv = a_texCoord.xy;\n color = a_color * a_color1;\n #endif\n pos = cc_matViewProj * pos;\n return pos;\n}\nvoid main() { gl_Position = lpvs_main(); }\n`, + "frag": `\nprecision highp float;\nuniform vec4 cc_exposure;\nvec4 CCFragOutput(vec4 color) {\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 CCFragOutput(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 CCFragOutput(col);\n}\nvoid main() { gl_FragColor = add(); }\n` }, "builtins": {"globals":{"blocks":["CCGlobal"], "samplers":[]}, "locals":{"blocks":["CCLocal"], "samplers":[]}}, "defines": [ @@ -114,16 +116,17 @@ export default [ {"name":"CC_USE_HDR", "type":"boolean", "defines":[]} ], "blocks": [ - {"name": "Constants", "size": 32, "defines": [], "binding": 0, "members": [ + {"name": "Constants", "size": 48, "defines": [], "binding": 0, "members": [ {"name":"mainTiling_Offset", "type":16, "count":1, "size":16}, - {"name":"frameTile_velLenScale", "type":16, "count":1, "size":16} + {"name":"frameTile_velLenScale", "type":16, "count":1, "size":16}, + {"name":"scale", "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} + {"name":"mainTexture", "type":28, "count":1, "defines":[], "binding":30} ], "dependencies": {} } @@ -137,14 +140,14 @@ export default [ "shaders": [ { "name": "builtin-skybox|sky-vs:vert|sky-fs:frag", - "hash": 316228518, + "hash": 3120258626, "glsl3": { - "vert": `\nprecision mediump float;\nuniform CCGlobal {\n vec4 cc_time;\n vec4 cc_screenSize;\n vec4 cc_screenScale;\n vec4 cc_nativeSize;\n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos;\n vec4 cc_exposure;\n vec4 cc_mainLitDir;\n vec4 cc_mainLitColor;\n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\nin vec3 a_position;\nin vec3 a_normal;\nin vec3 a_tangent;struct CCAttributes {\n vec3 position;\n vec3 normal;\n vec3 tangent;\n};void CCDecode (out CCAttributes attr) {\n attr.position = a_position;\n attr.normal = a_normal;\n attr.tangent = a_tangent;\n}\n#if CC_USE_SKINNING\nin vec4 a_weights;\nin vec4 a_joints;\n#if CC_USE_SKINNING == 1\n uniform CCSkinning {\n vec4 cc_jointsData[30 * 3];\n };\n#else\n uniform CCSkinningTexture {\n vec4 cc_jointsTextureSizeInv;\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 int idx = 3 * int(i);\n Qr = cc_jointsData[idx];\n Qt = cc_jointsData[idx + 1];\n return cc_jointsData[idx + 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 CCSkin(inout CCAttributes attr) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n attr.position = VectorTransformQuat(attr.position * S, R) + T;\n attr.normal = VectorTransformQuat(attr.normal, R);\n attr.tangent = VectorTransformQuat(attr.tangent, R);\n}\n#endif\nstruct StandardInput {\n vec3 position;\n vec3 normal;\n vec3 tangent;\n};\nvoid CCAttrToInput (in CCAttributes attr, out StandardInput In) {\n In.position = attr.position;\n In.normal = attr.normal;\n In.tangent = attr.tangent;\n}\nvoid CCGetStandardInput (out StandardInput In) {\n CCAttributes attr;\n CCDecode(attr);\n #if CC_USE_SKINNING\n CCSkin(attr);\n #endif\n CCAttrToInput(attr, In);\n}\nout vec3 viewDir;\nvec4 vert () {\n StandardInput In;\n CCGetStandardInput(In);\n mat4 matViewRotOnly = mat4(mat3(cc_matView));\n vec4 clipPos = cc_matProj * matViewRotOnly * vec4(In.position, 1.0);\n viewDir = a_position;\n clipPos.z = clipPos.w * 0.99999;\n return clipPos;\n}\nvoid main() { gl_Position = vert(); }\n`, - "frag": `\nprecision mediump float;\nvec3 unpackNormal(vec4 nmap) {\n return nmap.xyz * 2.0 - 1.0;\n}\nvec3 unpackRGBE(vec4 rgbe) {\n return rgbe.rgb * pow(2.0, rgbe.a * 255.0 - 128.0);\n}\nvec3 SRGBToLinear(vec3 gamma)\n{\n return pow(gamma, vec3(2.2));\n}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\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 CCOutput(vec4 color) {\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 vec3 viewDir;\nuniform samplerCube cubeMap;\nvec4 frag () {\n vec4 o;\n #if USE_RGBE_CUBEMAP\n vec3 c = unpackRGBE(texture(cubeMap, viewDir));\n c = LinearToSRGB(c / (1.0 + c));\n o = vec4(c, 1.0);\n #else\n o = texture(cubeMap, viewDir);\n #endif\n return CCOutput(o);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }\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};\nin vec3 a_position;\nvoid CCDecode (out vec3 position) {\n position = a_position;\n}\n#if CC_USE_SKINNING\nstruct StandardAttributes {\n vec3 position;\n vec3 normal;\n vec3 tangent;\n};\n in vec4 a_weights;\n in vec4 a_joints;\n #if CC_USE_SKINNING == 1\n uniform CCSkinning {\n vec4 cc_jointsData[30 * 3];\n };\n #else\n uniform CCSkinningTexture {\n vec4 cc_jointsTextureSizeInv;\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 int idx = 3 * int(i);\n Qr = cc_jointsData[idx];\n Qt = cc_jointsData[idx + 1];\n return cc_jointsData[idx + 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 CCSkin(inout vec3 position) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n position = VectorTransformQuat(position * S, R) + T;\n}\nvoid CCSkin(inout StandardAttributes attr) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n attr.position = VectorTransformQuat(attr.position * S, R) + T;\n attr.normal = VectorTransformQuat(attr.normal, R);\n attr.tangent = VectorTransformQuat(attr.tangent, R);\n}\n#endif\nvoid CCVertInput (out vec3 position) {\n CCDecode(position);\n #if CC_USE_SKINNING\n CCSkin(position);\n #endif\n}\nout vec3 viewDir;\nvec4 vert () {\n CCVertInput(viewDir);\n mat4 matViewRotOnly = mat4(mat3(cc_matView));\n vec4 clipPos = cc_matProj * matViewRotOnly * vec4(viewDir, 1.0);\n vec4 pos = clipPos;\n pos.z = clipPos.w * 0.99999;\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n`, + "frag": `\nprecision mediump float;\nvec3 unpackNormal(vec4 nmap) {\n return nmap.xyz * 2.0 - 1.0;\n}\nvec3 unpackRGBE(vec4 rgbe) {\n return rgbe.rgb * pow(2.0, rgbe.a * 255.0 - 128.0);\n}\nvec3 SRGBToLinear(vec3 gamma)\n{\n return pow(gamma, vec3(2.2));\n}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\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 CCFragOutput(vec4 color) {\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 vec3 viewDir;\nuniform samplerCube cubeMap;\nvec4 frag () {\n #if USE_RGBE_CUBEMAP\n vec3 c = unpackRGBE(texture(cubeMap, viewDir));\n c = LinearToSRGB(c / (1.0 + c));\n vec4 o = vec4(c, 1.0);\n #else\n vec4 o = texture(cubeMap, viewDir);\n #endif\n return CCFragOutput(o);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }\n` }, "glsl1": { - "vert": `\nprecision mediump float;\nuniform mat4 cc_matView;\nuniform mat4 cc_matProj;\nattribute vec3 a_position;\nattribute vec3 a_normal;\nattribute vec3 a_tangent;struct CCAttributes {\n vec3 position;\n vec3 normal;\n vec3 tangent;\n};void CCDecode (out CCAttributes attr) {\n attr.position = a_position;\n attr.normal = a_normal;\n attr.tangent = a_tangent;\n}\n#if CC_USE_SKINNING\nattribute vec4 a_weights;\nattribute vec4 a_joints;\n#if CC_USE_SKINNING == 1\n uniform vec4 cc_jointsData[90];\n#else\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 int idx = 3 * int(i);\n Qr = cc_jointsData[idx];\n Qt = cc_jointsData[idx + 1];\n return cc_jointsData[idx + 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 CCSkin(inout CCAttributes attr) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n attr.position = VectorTransformQuat(attr.position * S, R) + T;\n attr.normal = VectorTransformQuat(attr.normal, R);\n attr.tangent = VectorTransformQuat(attr.tangent, R);\n}\n#endif\nstruct StandardInput {\n vec3 position;\n vec3 normal;\n vec3 tangent;\n};\nvoid CCAttrToInput (in CCAttributes attr, out StandardInput In) {\n In.position = attr.position;\n In.normal = attr.normal;\n In.tangent = attr.tangent;\n}\nvoid CCGetStandardInput (out StandardInput In) {\n CCAttributes attr;\n CCDecode(attr);\n #if CC_USE_SKINNING\n CCSkin(attr);\n #endif\n CCAttrToInput(attr, In);\n}\nvarying vec3 viewDir;\nvec4 vert () {\n StandardInput In;\n CCGetStandardInput(In);\n mat4 matViewRotOnly = mat4(mat3(cc_matView));\n vec4 clipPos = cc_matProj * matViewRotOnly * vec4(In.position, 1.0);\n viewDir = a_position;\n clipPos.z = clipPos.w * 0.99999;\n return clipPos;\n}\nvoid main() { gl_Position = vert(); }\n`, - "frag": `\nprecision mediump float;\nvec3 unpackNormal(vec4 nmap) {\n return nmap.xyz * 2.0 - 1.0;\n}\nvec3 unpackRGBE(vec4 rgbe) {\n return rgbe.rgb * pow(2.0, rgbe.a * 255.0 - 128.0);\n}\nvec3 SRGBToLinear(vec3 gamma)\n{\n return pow(gamma, vec3(2.2));\n}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\n}\nuniform vec4 cc_exposure;\nvec4 CCOutput(vec4 color) {\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 vec3 viewDir;\nuniform samplerCube cubeMap;\nvec4 frag () {\n vec4 o;\n #if USE_RGBE_CUBEMAP\n vec3 c = unpackRGBE(textureCube(cubeMap, viewDir));\n c = LinearToSRGB(c / (1.0 + c));\n o = vec4(c, 1.0);\n #else\n o = textureCube(cubeMap, viewDir);\n #endif\n return CCOutput(o);\n}\nvoid main() { gl_FragColor = frag(); }\n` + "vert": `\nprecision mediump float;\nuniform mat4 cc_matView;\nuniform mat4 cc_matProj;\nattribute vec3 a_position;\nvoid CCDecode (out vec3 position) {\n position = a_position;\n}\n#if CC_USE_SKINNING\nstruct StandardAttributes {\n vec3 position;\n vec3 normal;\n vec3 tangent;\n};\n attribute vec4 a_weights;\n attribute vec4 a_joints;\n #if CC_USE_SKINNING == 1\n uniform vec4 cc_jointsData[90];\n #else\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 int idx = 3 * int(i);\n Qr = cc_jointsData[idx];\n Qt = cc_jointsData[idx + 1];\n return cc_jointsData[idx + 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 CCSkin(inout vec3 position) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n position = VectorTransformQuat(position * S, R) + T;\n}\nvoid CCSkin(inout StandardAttributes attr) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n attr.position = VectorTransformQuat(attr.position * S, R) + T;\n attr.normal = VectorTransformQuat(attr.normal, R);\n attr.tangent = VectorTransformQuat(attr.tangent, R);\n}\n#endif\nvoid CCVertInput (out vec3 position) {\n CCDecode(position);\n #if CC_USE_SKINNING\n CCSkin(position);\n #endif\n}\nvarying vec3 viewDir;\nvec4 vert () {\n CCVertInput(viewDir);\n mat4 matViewRotOnly = mat4(mat3(cc_matView));\n vec4 clipPos = cc_matProj * matViewRotOnly * vec4(viewDir, 1.0);\n vec4 pos = clipPos;\n pos.z = clipPos.w * 0.99999;\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n`, + "frag": `\nprecision mediump float;\nvec3 unpackNormal(vec4 nmap) {\n return nmap.xyz * 2.0 - 1.0;\n}\nvec3 unpackRGBE(vec4 rgbe) {\n return rgbe.rgb * pow(2.0, rgbe.a * 255.0 - 128.0);\n}\nvec3 SRGBToLinear(vec3 gamma)\n{\n return pow(gamma, vec3(2.2));\n}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\n}\nuniform vec4 cc_exposure;\nvec4 CCFragOutput(vec4 color) {\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 vec3 viewDir;\nuniform samplerCube cubeMap;\nvec4 frag () {\n #if USE_RGBE_CUBEMAP\n vec3 c = unpackRGBE(textureCube(cubeMap, viewDir));\n c = LinearToSRGB(c / (1.0 + c));\n vec4 o = vec4(c, 1.0);\n #else\n vec4 o = textureCube(cubeMap, viewDir);\n #endif\n return CCFragOutput(o);\n}\nvoid main() { gl_FragColor = frag(); }\n` }, "builtins": {"globals":{"blocks":["CCGlobal"], "samplers":[]}, "locals":{"blocks":["CCSkinning", "CCSkinningTexture"], "samplers":["cc_jointsTexture"]}}, "defines": [ @@ -154,7 +157,7 @@ export default [ ], "blocks": [], "samplers": [ - {"name":"cubeMap", "type":31, "count":1, "defines":[], "binding":0} + {"name":"cubeMap", "type":31, "count":1, "defines":[], "binding":30} ], "dependencies": {} } @@ -168,14 +171,14 @@ export default [ "shaders": [ { "name": "builtin-sprite|sprite-vs:vert|sprite-fs:frag", - "hash": 3400569611, + "hash": 1801375381, "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};\n#if USE_LOCAL\nuniform CCLocal {\n mat4 cc_matWorld;\n mat4 cc_matWorldIT;\n};\n#endif\nin vec3 a_position;\nin vec4 a_color;\nout vec4 color;\nin vec2 a_texCoord;\nout vec2 uv0;\nvec4 vert () {\n vec4 pos = vec4(a_position, 1);\n #if USE_LOCAL\n pos = cc_matViewProj * cc_matWorld * pos;\n #else\n pos = cc_matViewProj * pos;\n #endif\n uv0 = a_texCoord;\n color = a_color;\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n`, - "frag": `\nprecision mediump float;\nin vec4 color;\n#if USE_TEXTURE\nin vec2 uv0;\nuniform sampler2D mainTexture;\n#endif\nvec4 frag () {\n vec4 o = vec4(1, 1, 1, 1);\n #if USE_TEXTURE\n o *= texture(mainTexture, uv0);\n #endif\n o *= color;\n return o;\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }\n` + "frag": `\nprecision mediump float;\nin vec4 color;\n#if USE_TEXTURE\n in vec2 uv0;\n uniform sampler2D mainTexture;\n#endif\nvec4 frag () {\n vec4 o = vec4(1, 1, 1, 1);\n #if USE_TEXTURE\n o *= texture(mainTexture, uv0);\n #endif\n o *= color;\n return o;\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }\n` }, "glsl1": { "vert": `\nprecision mediump float;\nuniform mat4 cc_matViewProj;\n#if USE_LOCAL\nuniform mat4 cc_matWorld;\n#endif\nattribute vec3 a_position;\nattribute vec4 a_color;\nvarying vec4 color;\nattribute vec2 a_texCoord;\nvarying vec2 uv0;\nvec4 vert () {\n vec4 pos = vec4(a_position, 1);\n #if USE_LOCAL\n pos = cc_matViewProj * cc_matWorld * pos;\n #else\n pos = cc_matViewProj * pos;\n #endif\n uv0 = a_texCoord;\n color = a_color;\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n`, - "frag": `\nprecision mediump float;\nvarying vec4 color;\n#if USE_TEXTURE\nvarying vec2 uv0;\nuniform sampler2D mainTexture;\n#endif\nvec4 frag () {\n vec4 o = vec4(1, 1, 1, 1);\n #if USE_TEXTURE\n o *= texture2D(mainTexture, uv0);\n #endif\n o *= color;\n return o;\n}\nvoid main() { gl_FragColor = frag(); }\n` + "frag": `\nprecision mediump float;\nvarying vec4 color;\n#if USE_TEXTURE\n varying vec2 uv0;\n uniform sampler2D mainTexture;\n#endif\nvec4 frag () {\n vec4 o = vec4(1, 1, 1, 1);\n #if USE_TEXTURE\n o *= texture2D(mainTexture, uv0);\n #endif\n o *= color;\n return o;\n}\nvoid main() { gl_FragColor = frag(); }\n` }, "builtins": {"globals":{"blocks":["CCGlobal"], "samplers":[]}, "locals":{"blocks":["CCLocal"], "samplers":[]}}, "defines": [ @@ -184,7 +187,7 @@ export default [ ], "blocks": [], "samplers": [ - {"name":"mainTexture", "type":28, "count":1, "defines":["USE_TEXTURE"], "binding":0} + {"name":"mainTexture", "type":28, "count":1, "defines":["USE_TEXTURE"], "binding":30} ], "dependencies": {} } @@ -193,33 +196,33 @@ export default [ { "name": "builtin-standard", "techniques": [ - {"name":"opaque", "passes":[{"program":"builtin-standard|standard-vs:vert|standard-fs:frag", "properties":{"tilingOffset":{"value":[1, 1, 0, 0], "type":16}, "albedo":{"value":[1, 1, 1, 1], "inspector":{"type":"color"}, "type":16}, "albedoScale":{"value":[1, 1, 1, 0], "type":16}, "pbrParams":{"value":[0.8, 0.6, 0, 1], "type":16}, "pbrScale":{"value":[1, 1, 1, 1], "type":16}, "emissive":{"value":[1, 1, 1, 1], "inspector":{"type":"color"}, "type":16}, "emissiveScale":{"value":[1, 1, 1, 1], "type":16}, "albedoMap":{"value":"grey", "type":28}, "normalMap":{"value":"normal", "type":28}, "pbrMap":{"value":"grey", "type":28}, "emissiveMap":{"value":"grey", "type":28}, "envMap":{"value":"default-cube", "type":31}}}, {"customizations":["bounds-merge-shadow"], "blendState":{"targets":[{"blend":true, "blendSrc":2, "blendDst":4, "blendDstAlpha":4}]}, "program":"builtin-standard|planar-shadow-vs:vert|planar-shadow-fs:frag", "depthStencilState":{"depthTest":true, "depthWrite":false, "stencilTestFront":true, "stencilFuncFront":5, "stencilPassOpFront":2, "stencilWriteMaskBack":128, "stencilWriteMaskFront":128, "stencilReadMaskBack":128, "stencilReadMaskFront":128, "stencilRefBack":128, "stencilRefFront":128}, "switch":"USE_PLANAR_SHADOW"}]} + {"name":"opaque", "passes":[{"program":"builtin-standard|standard-vs:vert|standard-fs:frag", "properties":{"tilingOffset":{"value":[1, 1, 0, 0], "type":16}, "albedo":{"value":[1, 1, 1, 1], "inspector":{"type":"color"}, "type":16}, "albedoScale":{"value":[1, 1, 1, 0], "type":16}, "pbrParams":{"value":[0.8, 0.6, 0, 1], "type":16}, "pbrScale":{"value":[1, 1, 1, 1], "type":16}, "emissive":{"value":[1, 1, 1, 1], "inspector":{"type":"color"}, "type":16}, "emissiveScale":{"value":[1, 1, 1, 1], "type":16}, "albedoMap":{"value":"grey", "type":28}, "normalMap":{"value":"normal", "type":28}, "pbrMap":{"value":"grey", "type":28}, "emissiveMap":{"value":"grey", "type":28}}}, {"customizations":["bounds-merge-shadow"], "blendState":{"targets":[{"blend":true, "blendSrc":2, "blendDst":4, "blendDstAlpha":4}]}, "program":"builtin-standard|planar-shadow-vs:vert|planar-shadow-fs:frag", "depthStencilState":{"depthTest":true, "depthWrite":false, "stencilTestFront":true, "stencilFuncFront":5, "stencilPassOpFront":2, "stencilWriteMaskBack":128, "stencilWriteMaskFront":128, "stencilReadMaskBack":128, "stencilReadMaskFront":128, "stencilRefBack":128, "stencilRefFront":128}, "switch":"USE_PLANAR_SHADOW"}]} ], "shaders": [ { "name": "builtin-standard|standard-vs:vert|standard-fs:frag", - "hash": 2674111314, + "hash": 1399273552, "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};\nin vec3 a_position;\nin vec3 a_normal;\nin vec3 a_tangent;struct CCAttributes {\n vec3 position;\n vec3 normal;\n vec3 tangent;\n};void CCDecode (out CCAttributes attr) {\n attr.position = a_position;\n attr.normal = a_normal;\n attr.tangent = a_tangent;\n}\n#if CC_USE_SKINNING\nin vec4 a_weights;\nin vec4 a_joints;\n#if CC_USE_SKINNING == 1\n uniform CCSkinning {\n vec4 cc_jointsData[30 * 3];\n };\n#else\n uniform CCSkinningTexture {\n vec4 cc_jointsTextureSizeInv;\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 int idx = 3 * int(i);\n Qr = cc_jointsData[idx];\n Qt = cc_jointsData[idx + 1];\n return cc_jointsData[idx + 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 CCSkin(inout CCAttributes attr) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n attr.position = VectorTransformQuat(attr.position * S, R) + T;\n attr.normal = VectorTransformQuat(attr.normal, R);\n attr.tangent = VectorTransformQuat(attr.tangent, R);\n}\n#endif\nstruct StandardInput {\n vec3 position;\n vec3 normal;\n vec3 tangent;\n};\nvoid CCAttrToInput (in CCAttributes attr, out StandardInput In) {\n In.position = attr.position;\n In.normal = attr.normal;\n In.tangent = attr.tangent;\n}\nvoid CCGetStandardInput (out StandardInput In) {\n CCAttributes attr;\n CCDecode(attr);\n #if CC_USE_SKINNING\n CCSkin(attr);\n #endif\n CCAttrToInput(attr, In);\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 USE_ALBEDO_MAP || USE_NORMAL_MAP || USE_PBR_MAP || USE_EMISSIVE_MAP\n in vec2 a_texCoord;\n out vec2 v_uv;\n#endif\nout vec3 v_worldPos;\nout vec3 v_normal;\n#if USE_NORMAL_MAP\n out vec3 v_tangent;\n out vec3 v_bitangent;\n#endif\nvec4 vert () {\n StandardInput In;\n CCGetStandardInput(In);\n vec4 pos = cc_matWorld * vec4(In.position, 1.0);\n vec4 normal = cc_matWorldIT * vec4(In.normal, 0.0);\n v_worldPos = pos.xyz;\n v_normal = 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(In.tangent, 0.0)).xyz;\n v_bitangent = cross(v_tangent, v_normal);\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}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\n}\nfloat SmoothDistAtt2(float distSqr, float invSqrAttRadius) {\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 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 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 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 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 return (roughness*0.25 + 0.25) * GGXMobile(roughness, NoH, H, N);\n}\nvec3 BRDFApprox(vec3 specular, float roughness, float NoV) {\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 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;\n#if USE_ALBEDO_MAP || USE_NORMAL_MAP || USE_PBR_MAP || USE_EMISSIVE_MAP\n in vec2 v_uv;\n#endif\nin vec3 v_normal;\n#if USE_NORMAL_MAP\n in vec3 v_tangent;\n in vec3 v_bitangent;\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#if 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_normal);\n #if USE_NORMAL_MAP\n vec3 nmmp = texture(normalMap, v_uv).xyz - vec3(0.5);\n N = normalize(\n nmmp.x * normalize(v_tangent) +\n nmmp.y * normalize(v_bitangent) +\n nmmp.z * N);\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` + "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};\nstruct StandardAttributes {\n vec3 position;\n vec3 normal;\n vec3 tangent;\n};\nin vec3 a_position;\nin vec3 a_normal;\nin vec3 a_tangent;\nvoid CCDecode (out StandardAttributes attr) {\n attr.position = a_position;\n attr.normal = a_normal;\n attr.tangent = a_tangent;\n}\n#if CC_USE_SKINNING\n in vec4 a_weights;\n in vec4 a_joints;\n #if CC_USE_SKINNING == 1\n uniform CCSkinning {\n vec4 cc_jointsData[30 * 3];\n };\n #else\n uniform CCSkinningTexture {\n vec4 cc_jointsTextureSizeInv;\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 int idx = 3 * int(i);\n Qr = cc_jointsData[idx];\n Qt = cc_jointsData[idx + 1];\n return cc_jointsData[idx + 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 CCSkin(inout vec3 position) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n position = VectorTransformQuat(position * S, R) + T;\n}\nvoid CCSkin(inout StandardAttributes attr) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n attr.position = VectorTransformQuat(attr.position * S, R) + T;\n attr.normal = VectorTransformQuat(attr.normal, R);\n attr.tangent = VectorTransformQuat(attr.tangent, R);\n}\n#endif\nstruct StandardVertInput {\n vec3 position;\n vec3 normal;\n vec3 tangent;\n};\nvoid CCAttrToInput (in StandardAttributes attr, out StandardVertInput In) {\n In.position = attr.position;\n In.normal = attr.normal;\n In.tangent = attr.tangent;\n}\nvoid CCVertInput (out StandardVertInput In) {\n StandardAttributes attr;\n CCDecode(attr);\n #if CC_USE_SKINNING\n CCSkin(attr);\n #endif\n CCAttrToInput(attr, In);\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 USE_ALBEDO_MAP || USE_NORMAL_MAP || USE_PBR_MAP || USE_EMISSIVE_MAP\n in vec2 a_texCoord;\n out vec2 v_uv;\n#endif\nout vec3 v_worldPos;\nout vec3 v_normal;\n#if USE_NORMAL_MAP\n out vec3 v_tangent;\n out vec3 v_bitangent;\n#endif\nvec4 vert () {\n StandardVertInput In;\n CCVertInput(In);\n vec4 pos = cc_matWorld * vec4(In.position, 1.0);\n vec4 normal = cc_matWorldIT * vec4(In.normal, 0.0);\n v_worldPos = pos.xyz;\n v_normal = 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(In.tangent, 0.0)).xyz;\n v_bitangent = cross(v_tangent, v_normal);\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#if CC_USE_IBL\n uniform samplerCube cc_environment;\n#endif\n#define saturate(a) clamp( a, 0.0, 1.0 )\nvec3 SRGBToLinear(vec3 gamma)\n{\n return pow(gamma, vec3(2.2));\n}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\n}\nfloat SmoothDistAtt2(float distSqr, float invSqrAttRadius) {\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 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 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 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 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 return (roughness*0.25 + 0.25) * GGXMobile(roughness, NoH, H, N);\n}\nvec3 BRDFApprox(vec3 specular, float roughness, float NoV) {\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 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}\nstruct StandardSurface {\n vec3 albedo;\n float alpha;\n vec3 normal;\n vec3 worldPos;\n float roughness;\n float metallic;\n float occlusion;\n vec3 emissive;\n};\nvec4 CCStandardShading (StandardSurface s) {\n vec3 diffuse = s.albedo * (1.0 - s.metallic);\n vec3 specular = mix(vec3(0.04), s.albedo, s.metallic);\n vec3 V = normalize(cc_cameraPos.xyz - s.worldPos);\n vec3 L = normalize(-cc_mainLitDir.xyz);\n vec3 H = normalize(L+V);\n float NV = max(abs(dot(s.normal, V)), 0.001);\n float NL = max(dot(s.normal, L), 0.001);\n float NH = max(dot(s.normal, H), 0.0);\n specular = BRDFApprox(specular, s.roughness, NV);\n vec3 specularContrib = specular * CalcSpecular(s.roughness, NH, H, s.normal);\n vec3 diffuseContrib = diffuse / 3.14159265359;\n vec3 finalColor = NL * cc_mainLitColor.rgb * cc_mainLitColor.w * (diffuseContrib + specularContrib);\n finalColor += CalcDynamicLighting(s.worldPos, s.normal, V, diffuse, specular, s.roughness);\n float fAmb = dot(s.normal, 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 CC_USE_IBL\n vec3 R = normalize(reflect(-V, s.normal));\n vec3 env = SRGBToLinear(texture(cc_environment, R).rgb) * cc_ambientSky.w;\n finalColor += env * specular;\n #endif\n finalColor = finalColor * s.occlusion;\n #if CC_USE_HDR\n s.emissive *= cc_exposure.w;\n #endif\n finalColor += s.emissive;\n return vec4(finalColor, s.alpha);\n}\nvec4 CCFragOutput (vec4 color) {\n #if !CC_USE_HDR\n color.rgb = LinearToSRGB(color.rgb);\n #endif\n return color;\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;\n#if USE_ALBEDO_MAP || USE_NORMAL_MAP || USE_PBR_MAP || USE_EMISSIVE_MAP\n in vec2 v_uv;\n#endif\nin vec3 v_normal;\n#if USE_NORMAL_MAP\n in vec3 v_tangent;\n in vec3 v_bitangent;\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\nvoid surf (out StandardSurface s) {\n #if USE_ALBEDO_MAP\n vec4 baseColor = texture(albedoMap, v_uv) * albedo;\n s.albedo = baseColor.rgb;\n s.alpha = baseColor.a;\n #else\n s.albedo = albedo.rgb;\n s.alpha = albedo.a;\n #endif\n s.albedo *= albedoScale.rgb;\n s.albedo = SRGBToLinear(s.albedo);\n #if USE_ALPHA_TEST\n if(s.alpha < albedoScale.a)\n discard;\n #endif\n s.normal = normalize(v_normal);\n #if USE_NORMAL_MAP\n vec3 nmmp = texture(normalMap, v_uv).xyz - vec3(0.5);\n s.normal = normalize(\n nmmp.x * normalize(v_tangent) +\n nmmp.y * normalize(v_bitangent) +\n nmmp.z * s.normal);\n #endif\n s.worldPos = v_worldPos;\n #if USE_PBR_MAP\n vec4 pbr = texture(pbrMap, v_uv);\n #else\n vec4 pbr = pbrParams;\n #endif\n pbr *= pbrScale;\n s.roughness = clamp(pbr.ROUGHNESS_CHANNEL, 0.04, 1.0);\n s.metallic = clamp(pbr.METALLIC_CHANNEL, 0.0, 0.96);\n s.occlusion = mix(1.0, pbr.AO_CHANNEL, pbrParams.z);\n #if USE_EMISSIVE_MAP\n s.emissive = texture(emissiveMap, v_uv).rgb;\n s.emissive = SRGBToLinear(s.emissive);\n s.emissive *= emissive.rgb * emissiveScale.xyz;\n #endif\n}\nvec4 frag () {\n StandardSurface s; surf(s);\n vec4 color = CCStandardShading(s);\n return CCFragOutput(color);\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;\nattribute vec3 a_position;\nattribute vec3 a_normal;\nattribute vec3 a_tangent;struct CCAttributes {\n vec3 position;\n vec3 normal;\n vec3 tangent;\n};void CCDecode (out CCAttributes attr) {\n attr.position = a_position;\n attr.normal = a_normal;\n attr.tangent = a_tangent;\n}\n#if CC_USE_SKINNING\nattribute vec4 a_weights;\nattribute vec4 a_joints;\n#if CC_USE_SKINNING == 1\n uniform vec4 cc_jointsData[90];\n#else\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 int idx = 3 * int(i);\n Qr = cc_jointsData[idx];\n Qt = cc_jointsData[idx + 1];\n return cc_jointsData[idx + 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 CCSkin(inout CCAttributes attr) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n attr.position = VectorTransformQuat(attr.position * S, R) + T;\n attr.normal = VectorTransformQuat(attr.normal, R);\n attr.tangent = VectorTransformQuat(attr.tangent, R);\n}\n#endif\nstruct StandardInput {\n vec3 position;\n vec3 normal;\n vec3 tangent;\n};\nvoid CCAttrToInput (in CCAttributes attr, out StandardInput In) {\n In.position = attr.position;\n In.normal = attr.normal;\n In.tangent = attr.tangent;\n}\nvoid CCGetStandardInput (out StandardInput In) {\n CCAttributes attr;\n CCDecode(attr);\n #if CC_USE_SKINNING\n CCSkin(attr);\n #endif\n CCAttrToInput(attr, In);\n}\nuniform vec4 tilingOffset;\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\nvarying vec3 v_worldPos;\nvarying vec3 v_normal;\n#if USE_NORMAL_MAP\n varying vec3 v_tangent;\n varying vec3 v_bitangent;\n#endif\nvec4 vert () {\n StandardInput In;\n CCGetStandardInput(In);\n vec4 pos = cc_matWorld * vec4(In.position, 1.0);\n vec4 normal = cc_matWorldIT * vec4(In.normal, 0.0);\n v_worldPos = pos.xyz;\n v_normal = 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(In.tangent, 0.0)).xyz;\n v_bitangent = cross(v_tangent, v_normal);\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}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\n}\nfloat SmoothDistAtt2(float distSqr, float invSqrAttRadius) {\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 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 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 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 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 return (roughness*0.25 + 0.25) * GGXMobile(roughness, NoH, H, N);\n}\nvec3 BRDFApprox(vec3 specular, float roughness, float NoV) {\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 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;\n#if USE_ALBEDO_MAP || USE_NORMAL_MAP || USE_PBR_MAP || USE_EMISSIVE_MAP\n varying vec2 v_uv;\n#endif\nvarying vec3 v_normal;\n#if USE_NORMAL_MAP\n varying vec3 v_tangent;\n varying vec3 v_bitangent;\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#if 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_normal);\n #if USE_NORMAL_MAP\n vec3 nmmp = texture2D(normalMap, v_uv).xyz - vec3(0.5);\n N = normalize(\n nmmp.x * normalize(v_tangent) +\n nmmp.y * normalize(v_bitangent) +\n nmmp.z * N);\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` + "vert": `\nprecision mediump float;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matWorld;\nuniform mat4 cc_matWorldIT;\nstruct StandardAttributes {\n vec3 position;\n vec3 normal;\n vec3 tangent;\n};\nattribute vec3 a_position;\nattribute vec3 a_normal;\nattribute vec3 a_tangent;\nvoid CCDecode (out StandardAttributes attr) {\n attr.position = a_position;\n attr.normal = a_normal;\n attr.tangent = a_tangent;\n}\n#if CC_USE_SKINNING\n attribute vec4 a_weights;\n attribute vec4 a_joints;\n #if CC_USE_SKINNING == 1\n uniform vec4 cc_jointsData[90];\n #else\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 int idx = 3 * int(i);\n Qr = cc_jointsData[idx];\n Qt = cc_jointsData[idx + 1];\n return cc_jointsData[idx + 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 CCSkin(inout vec3 position) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n position = VectorTransformQuat(position * S, R) + T;\n}\nvoid CCSkin(inout StandardAttributes attr) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n attr.position = VectorTransformQuat(attr.position * S, R) + T;\n attr.normal = VectorTransformQuat(attr.normal, R);\n attr.tangent = VectorTransformQuat(attr.tangent, R);\n}\n#endif\nstruct StandardVertInput {\n vec3 position;\n vec3 normal;\n vec3 tangent;\n};\nvoid CCAttrToInput (in StandardAttributes attr, out StandardVertInput In) {\n In.position = attr.position;\n In.normal = attr.normal;\n In.tangent = attr.tangent;\n}\nvoid CCVertInput (out StandardVertInput In) {\n StandardAttributes attr;\n CCDecode(attr);\n #if CC_USE_SKINNING\n CCSkin(attr);\n #endif\n CCAttrToInput(attr, In);\n}\nuniform vec4 tilingOffset;\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\nvarying vec3 v_worldPos;\nvarying vec3 v_normal;\n#if USE_NORMAL_MAP\n varying vec3 v_tangent;\n varying vec3 v_bitangent;\n#endif\nvec4 vert () {\n StandardVertInput In;\n CCVertInput(In);\n vec4 pos = cc_matWorld * vec4(In.position, 1.0);\n vec4 normal = cc_matWorldIT * vec4(In.normal, 0.0);\n v_worldPos = pos.xyz;\n v_normal = 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(In.tangent, 0.0)).xyz;\n v_bitangent = cross(v_tangent, v_normal);\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#if CC_USE_IBL\n uniform samplerCube cc_environment;\n#endif\n#define saturate(a) clamp( a, 0.0, 1.0 )\nvec3 SRGBToLinear(vec3 gamma)\n{\n return pow(gamma, vec3(2.2));\n}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\n}\nfloat SmoothDistAtt2(float distSqr, float invSqrAttRadius) {\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 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 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 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 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 return (roughness*0.25 + 0.25) * GGXMobile(roughness, NoH, H, N);\n}\nvec3 BRDFApprox(vec3 specular, float roughness, float NoV) {\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 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}\nstruct StandardSurface {\n vec3 albedo;\n float alpha;\n vec3 normal;\n vec3 worldPos;\n float roughness;\n float metallic;\n float occlusion;\n vec3 emissive;\n};\nvec4 CCStandardShading (StandardSurface s) {\n vec3 diffuse = s.albedo * (1.0 - s.metallic);\n vec3 specular = mix(vec3(0.04), s.albedo, s.metallic);\n vec3 V = normalize(cc_cameraPos.xyz - s.worldPos);\n vec3 L = normalize(-cc_mainLitDir.xyz);\n vec3 H = normalize(L+V);\n float NV = max(abs(dot(s.normal, V)), 0.001);\n float NL = max(dot(s.normal, L), 0.001);\n float NH = max(dot(s.normal, H), 0.0);\n specular = BRDFApprox(specular, s.roughness, NV);\n vec3 specularContrib = specular * CalcSpecular(s.roughness, NH, H, s.normal);\n vec3 diffuseContrib = diffuse / 3.14159265359;\n vec3 finalColor = NL * cc_mainLitColor.rgb * cc_mainLitColor.w * (diffuseContrib + specularContrib);\n finalColor += CalcDynamicLighting(s.worldPos, s.normal, V, diffuse, specular, s.roughness);\n float fAmb = dot(s.normal, 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 CC_USE_IBL\n vec3 R = normalize(reflect(-V, s.normal));\n vec3 env = SRGBToLinear(textureCube(cc_environment, R).rgb) * cc_ambientSky.w;\n finalColor += env * specular;\n #endif\n finalColor = finalColor * s.occlusion;\n #if CC_USE_HDR\n s.emissive *= cc_exposure.w;\n #endif\n finalColor += s.emissive;\n return vec4(finalColor, s.alpha);\n}\nvec4 CCFragOutput (vec4 color) {\n #if !CC_USE_HDR\n color.rgb = LinearToSRGB(color.rgb);\n #endif\n return color;\n}\nuniform vec4 albedo;\nuniform vec4 albedoScale;\nuniform vec4 pbrParams;\nuniform vec4 pbrScale;\nuniform vec4 emissive;\nuniform vec4 emissiveScale;\nvarying vec3 v_worldPos;\n#if USE_ALBEDO_MAP || USE_NORMAL_MAP || USE_PBR_MAP || USE_EMISSIVE_MAP\n varying vec2 v_uv;\n#endif\nvarying vec3 v_normal;\n#if USE_NORMAL_MAP\n varying vec3 v_tangent;\n varying vec3 v_bitangent;\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\nvoid surf (out StandardSurface s) {\n #if USE_ALBEDO_MAP\n vec4 baseColor = texture2D(albedoMap, v_uv) * albedo;\n s.albedo = baseColor.rgb;\n s.alpha = baseColor.a;\n #else\n s.albedo = albedo.rgb;\n s.alpha = albedo.a;\n #endif\n s.albedo *= albedoScale.rgb;\n s.albedo = SRGBToLinear(s.albedo);\n #if USE_ALPHA_TEST\n if(s.alpha < albedoScale.a)\n discard;\n #endif\n s.normal = normalize(v_normal);\n #if USE_NORMAL_MAP\n vec3 nmmp = texture2D(normalMap, v_uv).xyz - vec3(0.5);\n s.normal = normalize(\n nmmp.x * normalize(v_tangent) +\n nmmp.y * normalize(v_bitangent) +\n nmmp.z * s.normal);\n #endif\n s.worldPos = v_worldPos;\n #if USE_PBR_MAP\n vec4 pbr = texture2D(pbrMap, v_uv);\n #else\n vec4 pbr = pbrParams;\n #endif\n pbr *= pbrScale;\n s.roughness = clamp(pbr.ROUGHNESS_CHANNEL, 0.04, 1.0);\n s.metallic = clamp(pbr.METALLIC_CHANNEL, 0.0, 0.96);\n s.occlusion = mix(1.0, pbr.AO_CHANNEL, pbrParams.z);\n #if USE_EMISSIVE_MAP\n s.emissive = texture2D(emissiveMap, v_uv).rgb;\n s.emissive = SRGBToLinear(s.emissive);\n s.emissive *= emissive.rgb * emissiveScale.xyz;\n #endif\n}\nvec4 frag () {\n StandardSurface s; surf(s);\n vec4 color = CCStandardShading(s);\n return CCFragOutput(color);\n}\nvoid main() { gl_FragColor = frag(); }\n` }, - "builtins": {"globals":{"blocks":["CCGlobal"], "samplers":[]}, "locals":{"blocks":["CCLocal", "CCSkinning", "CCSkinningTexture", "CCForwardLight"], "samplers":["cc_jointsTexture"]}}, + "builtins": {"globals":{"blocks":["CCGlobal"], "samplers":["cc_environment"]}, "locals":{"blocks":["CCLocal", "CCSkinning", "CCSkinningTexture", "CCForwardLight"], "samplers":["cc_jointsTexture"]}}, "defines": [ {"name":"CC_USE_SKINNING", "type":"number", "defines":[], "range":[0, 3]}, {"name":"USE_ALBEDO_MAP", "type":"boolean", "defines":[]}, {"name":"USE_NORMAL_MAP", "type":"boolean", "defines":[]}, + {"name":"CC_USE_IBL", "type":"boolean", "defines":[]}, + {"name":"CC_USE_HDR", "type":"boolean", "defines":[]}, {"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", "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":[]} + {"name":"USE_ALPHA_TEST", "type":"boolean", "defines":[]} ], "blocks": [ {"name": "Constants", "size": 112, "defines": [], "binding": 0, "members": [ @@ -233,24 +236,23 @@ export default [ ]} ], "samplers": [ - {"name":"albedoMap", "type":28, "count":1, "defines":["USE_ALBEDO_MAP"], "binding":1}, - {"name":"normalMap", "type":28, "count":1, "defines":["USE_NORMAL_MAP"], "binding":2}, - {"name":"pbrMap", "type":28, "count":1, "defines":["USE_PBR_MAP"], "binding":3}, - {"name":"emissiveMap", "type":28, "count":1, "defines":["USE_EMISSIVE_MAP"], "binding":4}, - {"name":"envMap", "type":31, "count":1, "defines":["USE_IBL"], "binding":5} + {"name":"albedoMap", "type":28, "count":1, "defines":["USE_ALBEDO_MAP"], "binding":30}, + {"name":"normalMap", "type":28, "count":1, "defines":["USE_NORMAL_MAP"], "binding":31}, + {"name":"pbrMap", "type":28, "count":1, "defines":["USE_PBR_MAP"], "binding":32}, + {"name":"emissiveMap", "type":28, "count":1, "defines":["USE_EMISSIVE_MAP"], "binding":33} ], "dependencies": {} }, { "name": "builtin-standard|planar-shadow-vs:vert|planar-shadow-fs:frag", - "hash": 71711775, + "hash": 1730327791, "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};\nin vec3 a_position;\nin vec3 a_normal;\nin vec3 a_tangent;struct CCAttributes {\n vec3 position;\n vec3 normal;\n vec3 tangent;\n};void CCDecode (out CCAttributes attr) {\n attr.position = a_position;\n attr.normal = a_normal;\n attr.tangent = a_tangent;\n}\n#if CC_USE_SKINNING\nin vec4 a_weights;\nin vec4 a_joints;\n#if CC_USE_SKINNING == 1\n uniform CCSkinning {\n vec4 cc_jointsData[30 * 3];\n };\n#else\n uniform CCSkinningTexture {\n vec4 cc_jointsTextureSizeInv;\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 int idx = 3 * int(i);\n Qr = cc_jointsData[idx];\n Qt = cc_jointsData[idx + 1];\n return cc_jointsData[idx + 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 CCSkin(inout CCAttributes attr) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n attr.position = VectorTransformQuat(attr.position * S, R) + T;\n attr.normal = VectorTransformQuat(attr.normal, R);\n attr.tangent = VectorTransformQuat(attr.tangent, R);\n}\n#endif\nstruct StandardInput {\n vec3 position;\n vec3 normal;\n vec3 tangent;\n};\nvoid CCAttrToInput (in CCAttributes attr, out StandardInput In) {\n In.position = attr.position;\n In.normal = attr.normal;\n In.tangent = attr.tangent;\n}\nvoid CCGetStandardInput (out StandardInput In) {\n CCAttributes attr;\n CCDecode(attr);\n #if CC_USE_SKINNING\n CCSkin(attr);\n #endif\n CCAttrToInput(attr, In);\n}\nvec4 vert () {\n StandardInput In;\n CCGetStandardInput(In);\n vec4 pos = cc_matWorld * vec4(In.position, 1.0);\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 CCOutput(vec4 color) {\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 CCOutput(cc_shadowColor);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }\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};\nin vec3 a_position;\nvoid CCDecode (out vec3 position) {\n position = a_position;\n}\n#if CC_USE_SKINNING\nstruct StandardAttributes {\n vec3 position;\n vec3 normal;\n vec3 tangent;\n};\n in vec4 a_weights;\n in vec4 a_joints;\n #if CC_USE_SKINNING == 1\n uniform CCSkinning {\n vec4 cc_jointsData[30 * 3];\n };\n #else\n uniform CCSkinningTexture {\n vec4 cc_jointsTextureSizeInv;\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 int idx = 3 * int(i);\n Qr = cc_jointsData[idx];\n Qt = cc_jointsData[idx + 1];\n return cc_jointsData[idx + 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 CCSkin(inout vec3 position) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n position = VectorTransformQuat(position * S, R) + T;\n}\nvoid CCSkin(inout StandardAttributes attr) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n attr.position = VectorTransformQuat(attr.position * S, R) + T;\n attr.normal = VectorTransformQuat(attr.normal, R);\n attr.tangent = VectorTransformQuat(attr.tangent, R);\n}\n#endif\nvoid CCVertInput (out vec3 position) {\n CCDecode(position);\n #if CC_USE_SKINNING\n CCSkin(position);\n #endif\n}\nvec4 vert () {\n vec3 position;\n CCVertInput(position);\n vec4 pos = cc_matWorld * vec4(position, 1.0);\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 CCFragOutput(vec4 color) {\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 CCFragOutput(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;\nattribute vec3 a_position;\nattribute vec3 a_normal;\nattribute vec3 a_tangent;struct CCAttributes {\n vec3 position;\n vec3 normal;\n vec3 tangent;\n};void CCDecode (out CCAttributes attr) {\n attr.position = a_position;\n attr.normal = a_normal;\n attr.tangent = a_tangent;\n}\n#if CC_USE_SKINNING\nattribute vec4 a_weights;\nattribute vec4 a_joints;\n#if CC_USE_SKINNING == 1\n uniform vec4 cc_jointsData[90];\n#else\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 int idx = 3 * int(i);\n Qr = cc_jointsData[idx];\n Qt = cc_jointsData[idx + 1];\n return cc_jointsData[idx + 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 CCSkin(inout CCAttributes attr) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n attr.position = VectorTransformQuat(attr.position * S, R) + T;\n attr.normal = VectorTransformQuat(attr.normal, R);\n attr.tangent = VectorTransformQuat(attr.tangent, R);\n}\n#endif\nstruct StandardInput {\n vec3 position;\n vec3 normal;\n vec3 tangent;\n};\nvoid CCAttrToInput (in CCAttributes attr, out StandardInput In) {\n In.position = attr.position;\n In.normal = attr.normal;\n In.tangent = attr.tangent;\n}\nvoid CCGetStandardInput (out StandardInput In) {\n CCAttributes attr;\n CCDecode(attr);\n #if CC_USE_SKINNING\n CCSkin(attr);\n #endif\n CCAttrToInput(attr, In);\n}\nvec4 vert () {\n StandardInput In;\n CCGetStandardInput(In);\n vec4 pos = cc_matWorld * vec4(In.position, 1.0);\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 CCOutput(vec4 color) {\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 CCOutput(cc_shadowColor);\n}\nvoid main() { gl_FragColor = frag(); }\n` + "vert": `\nprecision mediump float;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matWorld;\nuniform mat4 cc_matLightPlaneProj;\nattribute vec3 a_position;\nvoid CCDecode (out vec3 position) {\n position = a_position;\n}\n#if CC_USE_SKINNING\nstruct StandardAttributes {\n vec3 position;\n vec3 normal;\n vec3 tangent;\n};\n attribute vec4 a_weights;\n attribute vec4 a_joints;\n #if CC_USE_SKINNING == 1\n uniform vec4 cc_jointsData[90];\n #else\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 int idx = 3 * int(i);\n Qr = cc_jointsData[idx];\n Qt = cc_jointsData[idx + 1];\n return cc_jointsData[idx + 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 CCSkin(inout vec3 position) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n position = VectorTransformQuat(position * S, R) + T;\n}\nvoid CCSkin(inout StandardAttributes attr) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n attr.position = VectorTransformQuat(attr.position * S, R) + T;\n attr.normal = VectorTransformQuat(attr.normal, R);\n attr.tangent = VectorTransformQuat(attr.tangent, R);\n}\n#endif\nvoid CCVertInput (out vec3 position) {\n CCDecode(position);\n #if CC_USE_SKINNING\n CCSkin(position);\n #endif\n}\nvec4 vert () {\n vec3 position;\n CCVertInput(position);\n vec4 pos = cc_matWorld * vec4(position, 1.0);\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 CCFragOutput(vec4 color) {\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 CCFragOutput(cc_shadowColor);\n}\nvoid main() { gl_FragColor = frag(); }\n` }, "builtins": {"globals":{"blocks":["CCGlobal", "CCShadow"], "samplers":[]}, "locals":{"blocks":["CCLocal", "CCSkinning", "CCSkinningTexture"], "samplers":["cc_jointsTexture"]}}, "defines": [ @@ -271,14 +273,14 @@ export default [ "shaders": [ { "name": "builtin-unlit|unlit-vs:vert|unlit-fs:frag", - "hash": 502451384, + "hash": 1214215395, "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};\nin vec3 a_position;\nin vec3 a_normal;\nin vec3 a_tangent;struct CCAttributes {\n vec3 position;\n vec3 normal;\n vec3 tangent;\n};void CCDecode (out CCAttributes attr) {\n attr.position = a_position;\n attr.normal = a_normal;\n attr.tangent = a_tangent;\n}\n#if CC_USE_SKINNING\nin vec4 a_weights;\nin vec4 a_joints;\n#if CC_USE_SKINNING == 1\n uniform CCSkinning {\n vec4 cc_jointsData[30 * 3];\n };\n#else\n uniform CCSkinningTexture {\n vec4 cc_jointsTextureSizeInv;\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 int idx = 3 * int(i);\n Qr = cc_jointsData[idx];\n Qt = cc_jointsData[idx + 1];\n return cc_jointsData[idx + 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 CCSkin(inout CCAttributes attr) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n attr.position = VectorTransformQuat(attr.position * S, R) + T;\n attr.normal = VectorTransformQuat(attr.normal, R);\n attr.tangent = VectorTransformQuat(attr.tangent, R);\n}\n#endif\nstruct StandardInput {\n vec3 position;\n vec3 normal;\n vec3 tangent;\n};\nvoid CCAttrToInput (in CCAttributes attr, out StandardInput In) {\n In.position = attr.position;\n In.normal = attr.normal;\n In.tangent = attr.tangent;\n}\nvoid CCGetStandardInput (out StandardInput In) {\n CCAttributes attr;\n CCDecode(attr);\n #if CC_USE_SKINNING\n CCSkin(attr);\n #endif\n CCAttrToInput(attr, In);\n}\n#if USE_VERTEX_COLOR\n in vec4 a_color;\n out vec4 v_color;\n#endif\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 StandardInput In;\n CCGetStandardInput(In);\n vec4 pos = cc_matViewProj * cc_matWorld * vec4(In.position, 1.0);\n #if USE_TEXTURE\n uv0 = a_texCoord * tilingOffset.xy + tilingOffset.zw;\n #endif\n #if USE_VERTEX_COLOR\n v_color = a_color;\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 CCOutput(vec4 color) {\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\n#if USE_VERTEX_COLOR\n in vec4 v_color;\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 #if USE_VERTEX_COLOR\n o *= v_color;\n #endif\n return CCOutput(o);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }\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};\nin vec3 a_position;\nvoid CCDecode (out vec3 position) {\n position = a_position;\n}\n#if CC_USE_SKINNING\nstruct StandardAttributes {\n vec3 position;\n vec3 normal;\n vec3 tangent;\n};\n in vec4 a_weights;\n in vec4 a_joints;\n #if CC_USE_SKINNING == 1\n uniform CCSkinning {\n vec4 cc_jointsData[30 * 3];\n };\n #else\n uniform CCSkinningTexture {\n vec4 cc_jointsTextureSizeInv;\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 int idx = 3 * int(i);\n Qr = cc_jointsData[idx];\n Qt = cc_jointsData[idx + 1];\n return cc_jointsData[idx + 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 CCSkin(inout vec3 position) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n position = VectorTransformQuat(position * S, R) + T;\n}\nvoid CCSkin(inout StandardAttributes attr) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n attr.position = VectorTransformQuat(attr.position * S, R) + T;\n attr.normal = VectorTransformQuat(attr.normal, R);\n attr.tangent = VectorTransformQuat(attr.tangent, R);\n}\n#endif\nvoid CCVertInput (out vec3 position) {\n CCDecode(position);\n #if CC_USE_SKINNING\n CCSkin(position);\n #endif\n}\n#if USE_VERTEX_COLOR\n in vec4 a_color;\n out vec4 v_color;\n#endif\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 vec3 position;\n CCVertInput(position);\n vec4 pos = cc_matViewProj * cc_matWorld * vec4(position, 1.0);\n #if USE_TEXTURE\n uv0 = a_texCoord * tilingOffset.xy + tilingOffset.zw;\n #endif\n #if USE_VERTEX_COLOR\n v_color = a_color;\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 CCFragOutput(vec4 color) {\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\n#if USE_VERTEX_COLOR\n in vec4 v_color;\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 #if USE_VERTEX_COLOR\n o *= v_color;\n #endif\n return CCFragOutput(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;\nattribute vec3 a_position;\nattribute vec3 a_normal;\nattribute vec3 a_tangent;struct CCAttributes {\n vec3 position;\n vec3 normal;\n vec3 tangent;\n};void CCDecode (out CCAttributes attr) {\n attr.position = a_position;\n attr.normal = a_normal;\n attr.tangent = a_tangent;\n}\n#if CC_USE_SKINNING\nattribute vec4 a_weights;\nattribute vec4 a_joints;\n#if CC_USE_SKINNING == 1\n uniform vec4 cc_jointsData[90];\n#else\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 int idx = 3 * int(i);\n Qr = cc_jointsData[idx];\n Qt = cc_jointsData[idx + 1];\n return cc_jointsData[idx + 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 CCSkin(inout CCAttributes attr) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n attr.position = VectorTransformQuat(attr.position * S, R) + T;\n attr.normal = VectorTransformQuat(attr.normal, R);\n attr.tangent = VectorTransformQuat(attr.tangent, R);\n}\n#endif\nstruct StandardInput {\n vec3 position;\n vec3 normal;\n vec3 tangent;\n};\nvoid CCAttrToInput (in CCAttributes attr, out StandardInput In) {\n In.position = attr.position;\n In.normal = attr.normal;\n In.tangent = attr.tangent;\n}\nvoid CCGetStandardInput (out StandardInput In) {\n CCAttributes attr;\n CCDecode(attr);\n #if CC_USE_SKINNING\n CCSkin(attr);\n #endif\n CCAttrToInput(attr, In);\n}\n#if USE_VERTEX_COLOR\n attribute vec4 a_color;\n varying vec4 v_color;\n#endif\n#if USE_TEXTURE\n attribute vec2 a_texCoord;\n varying vec2 uv0;\n uniform vec4 tilingOffset;\n#endif\nvec4 vert () {\n StandardInput In;\n CCGetStandardInput(In);\n vec4 pos = cc_matViewProj * cc_matWorld * vec4(In.position, 1.0);\n #if USE_TEXTURE\n uv0 = a_texCoord * tilingOffset.xy + tilingOffset.zw;\n #endif\n #if USE_VERTEX_COLOR\n v_color = a_color;\n #endif\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n`, - "frag": `\nprecision mediump float;\nuniform vec4 cc_exposure;\nvec4 CCOutput(vec4 color) {\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\n#if USE_VERTEX_COLOR\n varying vec4 v_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 #if USE_VERTEX_COLOR\n o *= v_color;\n #endif\n return CCOutput(o);\n}\nvoid main() { gl_FragColor = frag(); }\n` + "vert": `\nprecision mediump float;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matWorld;\nattribute vec3 a_position;\nvoid CCDecode (out vec3 position) {\n position = a_position;\n}\n#if CC_USE_SKINNING\nstruct StandardAttributes {\n vec3 position;\n vec3 normal;\n vec3 tangent;\n};\n attribute vec4 a_weights;\n attribute vec4 a_joints;\n #if CC_USE_SKINNING == 1\n uniform vec4 cc_jointsData[90];\n #else\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 int idx = 3 * int(i);\n Qr = cc_jointsData[idx];\n Qt = cc_jointsData[idx + 1];\n return cc_jointsData[idx + 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 CCSkin(inout vec3 position) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n position = VectorTransformQuat(position * S, R) + T;\n}\nvoid CCSkin(inout StandardAttributes attr) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n attr.position = VectorTransformQuat(attr.position * S, R) + T;\n attr.normal = VectorTransformQuat(attr.normal, R);\n attr.tangent = VectorTransformQuat(attr.tangent, R);\n}\n#endif\nvoid CCVertInput (out vec3 position) {\n CCDecode(position);\n #if CC_USE_SKINNING\n CCSkin(position);\n #endif\n}\n#if USE_VERTEX_COLOR\n attribute vec4 a_color;\n varying vec4 v_color;\n#endif\n#if USE_TEXTURE\n attribute vec2 a_texCoord;\n varying vec2 uv0;\n uniform vec4 tilingOffset;\n#endif\nvec4 vert () {\n vec3 position;\n CCVertInput(position);\n vec4 pos = cc_matViewProj * cc_matWorld * vec4(position, 1.0);\n #if USE_TEXTURE\n uv0 = a_texCoord * tilingOffset.xy + tilingOffset.zw;\n #endif\n #if USE_VERTEX_COLOR\n v_color = a_color;\n #endif\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n`, + "frag": `\nprecision mediump float;\nuniform vec4 cc_exposure;\nvec4 CCFragOutput(vec4 color) {\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\n#if USE_VERTEX_COLOR\n varying vec4 v_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 #if USE_VERTEX_COLOR\n o *= v_color;\n #endif\n return CCFragOutput(o);\n}\nvoid main() { gl_FragColor = frag(); }\n` }, "builtins": {"globals":{"blocks":["CCGlobal"], "samplers":[]}, "locals":{"blocks":["CCLocal", "CCSkinning", "CCSkinningTexture"], "samplers":["cc_jointsTexture"]}}, "defines": [ @@ -297,7 +299,7 @@ export default [ ]} ], "samplers": [ - {"name":"mainTexture", "type":28, "count":1, "defines":["USE_TEXTURE"], "binding":2} + {"name":"mainTexture", "type":28, "count":1, "defines":["USE_TEXTURE"], "binding":30} ], "dependencies": {} } @@ -311,7 +313,7 @@ export default [ "shaders": [ { "name": "pipeline/smaa|smaa-edge-vs:vert|smaa-edge-fs:frag", - "hash": 1827337539, + "hash": 467513197, "glsl3": { "vert": `\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};\nin vec2 a_position;\nin vec2 a_texCoord;\nout vec2 v_uv;\nout vec4 v_offsets[3];\nvec4 vert () {\n vec4 pos = vec4(a_position, 0.0, 1.0);\n v_uv = a_texCoord * cc_screenScale.xy;\n v_offsets[0] = v_uv.xyxy + cc_nativeSize.zwzw * vec4(-1.0, 0.0, 0.0, 1.0);\n v_offsets[1] = v_uv.xyxy + cc_nativeSize.zwzw * vec4( 1.0, 0.0, 0.0, -1.0);\n v_offsets[2] = v_uv.xyxy + cc_nativeSize.zwzw * vec4(-2.0, 0.0, 0.0, 2.0);\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n`, "frag": `\nprecision highp float;\nuniform CCGlobal {\n vec4 cc_time;\n vec4 cc_screenSize;\n vec4 cc_screenScale;\n vec4 cc_nativeSize;\n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos;\n vec4 cc_exposure;\n vec4 cc_mainLitDir;\n vec4 cc_mainLitColor;\n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\n#define saturate(a) clamp( a, 0.0, 1.0 )\nvec3 SRGBToLinear(vec3 gamma)\n{\n return pow(gamma, vec3(2.2));\n}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\n}\nvec3 ACESToneMap(vec3 color) {\n const float A = 2.51;\n const float B = 0.03;\n const float C = 2.43;\n const float D = 0.59;\n const float E = 0.14;\n return (color * (A * color + B)) / (color * (C * color + D) + E);\n}\nin vec2 v_uv;\nin vec4 v_offsets[3];\nuniform sampler2D u_texSampler;\nvec3 ToLDR(vec3 color) {\n#if CC_USE_HDR\n color *= cc_exposure.x * 1024.0;\n color = ACESToneMap(color);\n color = LinearToSRGB(color);\n#endif\n return color;\n}\nvec4 frag () {\n vec2 threshold = vec2(0.1, 0.1);\n vec4 delta;\n vec3 C = ToLDR(texture(u_texSampler, v_uv).rgb);\n vec3 Cleft = ToLDR(texture(u_texSampler, v_offsets[0].xy).rgb);\n vec3 t = abs(C - Cleft);\n delta.x = max(max(t.r, t.g), t.b);\n vec3 Ctop = ToLDR(texture(u_texSampler, v_offsets[0].zw).rgb);\n t = abs(C - Ctop);\n delta.y = max(max(t.r, t.g), t.b);\n vec2 edges = step(threshold, delta.xy);\n if (dot(edges, vec2(1.0, 1.0)) == 0.0)\n discard;\n vec3 Cright = ToLDR(texture(u_texSampler, v_offsets[1].xy).rgb);\n t = abs(C - Cright);\n delta.z = max(max(t.r, t.g), t.b);\n vec3 Cbottom = ToLDR(texture(u_texSampler, v_offsets[1].zw).rgb);\n t = abs(C - Cbottom);\n delta.w = max(max(t.r, t.g), t.b);\n float maxDelta = max(max(max(delta.x, delta.y), delta.z), delta.w);\n vec3 Cleftleft = ToLDR(texture(u_texSampler, v_offsets[2].xy).rgb);\n t = abs(C - Cleftleft);\n delta.z = max(max(t.r, t.g), t.b);\n vec3 Ctoptop = ToLDR(texture(u_texSampler, v_offsets[2].zw).rgb);\n t = abs(C - Ctoptop);\n delta.w = max(max(t.r, t.g), t.b);\n maxDelta = max(max(maxDelta, delta.z), delta.w);\n edges.xy *= step(0.5 * maxDelta, delta.xy);\n vec4 o = vec4(edges, 0.0, 0.0);\n return o;\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }\n` @@ -326,13 +328,13 @@ export default [ ], "blocks": [], "samplers": [ - {"name":"u_texSampler", "type":28, "count":1, "defines":[], "binding":0} + {"name":"u_texSampler", "type":28, "count":1, "defines":[], "binding":30} ], "dependencies": {} }, { "name": "pipeline/smaa|smaa-blend-vs:vert|smaa-blend-fs:frag", - "hash": 2477120406, + "hash": 2322562369, "glsl3": { "vert": `\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};\nin vec2 a_position;\nin vec2 a_texCoord;\nout vec2 v_uv;\nout vec4 v_offsets[3];\nout vec2 v_pixCoord;\nvec4 vert () {\n vec4 pos = vec4(a_position, 0.0, 1.0);\n v_uv = a_texCoord * cc_screenScale.xy;\n v_pixCoord = v_uv * cc_nativeSize.xy;\n v_offsets[0] = v_uv.xyxy + cc_nativeSize.zwzw * vec4(-0.25, 0.125, 1.25, 0.125);\n v_offsets[1] = v_uv.xyxy + cc_nativeSize.zwzw * vec4(-0.125, 0.25, -0.125, -1.25);\n v_offsets[2] = vec4(v_offsets[0].xz, v_offsets[1].yw) + vec4(-2.0, 2.0, -2.0, 2.0) * cc_nativeSize.zzww * float(8);\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n`, "frag": `\nprecision highp float;\nuniform CCGlobal {\n vec4 cc_time;\n vec4 cc_screenSize;\n vec4 cc_screenScale;\n vec4 cc_nativeSize;\n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos;\n vec4 cc_exposure;\n vec4 cc_mainLitDir;\n vec4 cc_mainLitColor;\n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\nin vec2 v_uv;\nin vec4 v_offsets[3];\nin vec2 v_pixCoord;\nuniform sampler2D u_edgeTexSampler;\nuniform sampler2D u_areaTexSampler;\nuniform sampler2D u_searchTexSampler;\nfloat SMAASearchLength(vec2 e, float bias, float scale) {\n e.r = bias + e.r * scale;\n return 255.0 * texture(u_searchTexSampler, e).r;\n}\nfloat SMAASearchXLeft(vec2 texcoord, float end) {\n vec2 e = vec2(0.0, 1.0);\n for (int i = 0; i < 8; ++i) {\n e = texture(u_edgeTexSampler, texcoord).rg;\n texcoord -= vec2( 2.0, 0.0 ) * cc_nativeSize.zw;\n if (!(texcoord.x > end && e.g > 0.8281 && e.r == 0.0))\n break;\n }\n texcoord.x += 0.25 * cc_nativeSize.z;\n texcoord.x += cc_nativeSize.z;\n texcoord.x += 2.0 * cc_nativeSize.z;\n texcoord.x -= cc_nativeSize.z * SMAASearchLength(e, 0.0, 0.5);\n return texcoord.x;\n}\nfloat SMAASearchXRight(vec2 texcoord, float end) {\n vec2 e = vec2(0.0, 1.0);\n for (int i = 0; i < 8; ++i) {\n e = texture(u_edgeTexSampler, texcoord).rg;\n texcoord += vec2( 2.0, 0.0 ) * cc_nativeSize.zw;\n if (!(texcoord.x < end && e.g > 0.8281 && e.r == 0.0))\n break;\n }\n texcoord.x -= 0.25 * cc_nativeSize.z;\n texcoord.x -= cc_nativeSize.z;\n texcoord.x -= 2.0 * cc_nativeSize.z;\n texcoord.x += cc_nativeSize.z * SMAASearchLength(e, 0.5, 0.5);\n return texcoord.x;\n}\nfloat SMAASearchYUp(vec2 texcoord, float end) {\n vec2 e = vec2(1.0, 0.0);\n for (int i = 0; i < 8; ++i) {\n e = texture(u_edgeTexSampler, texcoord).rg;\n texcoord += vec2( 0.0, 2.0 ) * cc_nativeSize.zw;\n if (!(texcoord.y > end && e.r > 0.8281 && e.g == 0.0))\n break;\n }\n texcoord.y -= 0.25 * cc_nativeSize.w;\n texcoord.y -= cc_nativeSize.w;\n texcoord.y -= 2.0 * cc_nativeSize.w;\n texcoord.y += cc_nativeSize.w * SMAASearchLength(e.gr, 0.0, 0.5);\n return texcoord.y;\n}\nfloat SMAASearchYDown(vec2 texcoord, float end) {\n vec2 e = vec2(1.0, 0.0);\n for (int i = 0; i < 8; ++i) {\n e = texture(u_edgeTexSampler, texcoord).rg;\n texcoord -= vec2( 0.0, 2.0 ) * cc_nativeSize.zw;\n if (!(texcoord.y < end && e.r > 0.8281 && e.g == 0.0))\n break;\n }\n texcoord.y += 0.25 * cc_nativeSize.w;\n texcoord.y += cc_nativeSize.w;\n texcoord.y += 2.0 * cc_nativeSize.w;\n texcoord.y -= cc_nativeSize.w * SMAASearchLength(e.gr, 0.5, 0.5);\n return texcoord.y;\n}\nvec2 Round(vec2 x) {\n return sign(x) * floor(abs(x) + 0.5);\n}\nvec2 SMAAArea(vec2 dist, float e1, float e2) {\n vec2 texcoord = float(16) * Round(4.0 * vec2(e1, e2)) + dist;\n texcoord = (1.0 / vec2(160.0, 560.0)) * texcoord + 0.5 * (1.0 / vec2(160.0, 560.0));\n return texture(u_areaTexSampler, texcoord).rg;\n}\nvec4 frag () {\n vec4 weights = vec4(0.0);\n vec2 e = texture(u_edgeTexSampler, v_uv).rg;\n vec2 d;\n vec2 coords;\n if ( e.g > 0.0 ) {\n coords.x = SMAASearchXLeft(v_offsets[0].xy, v_offsets[2].x);\n coords.y = v_offsets[1].y;\n d.x = coords.x;\n float e1 = texture(u_edgeTexSampler, coords).r;\n coords.x = SMAASearchXRight(v_offsets[0].zw, v_offsets[2].y);\n d.y = coords.x;\n d = d / cc_nativeSize.z - v_pixCoord.x;\n vec2 sqrt_d = sqrt(abs(d));\n coords.y -= 1.0 * cc_nativeSize.w;\n float e2 = texture(u_edgeTexSampler, coords + vec2(cc_nativeSize.z, 0.0)).r;\n weights.rg = SMAAArea(sqrt_d, e1, e2);\n }\n if ( e.r > 0.0 ) {\n coords.y = SMAASearchYUp(v_offsets[1].xy, v_offsets[2].z);\n coords.x = v_offsets[0].x;\n d.x = coords.y;\n float e1 = texture(u_edgeTexSampler, coords).g;\n coords.y = SMAASearchYDown(v_offsets[1].zw, v_offsets[2].w);\n d.y = coords.y;\n d = d / cc_nativeSize.w - v_pixCoord.y;\n vec2 sqrt_d = sqrt(abs(d));\n coords.y -= 1.0 * cc_nativeSize.w;\n float e2 = texture(u_edgeTexSampler, coords + vec2(0.0, cc_nativeSize.w)).g;\n weights.ba = SMAAArea(sqrt_d, e1, e2);\n }\n return weights;\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }\n` @@ -345,9 +347,9 @@ export default [ "defines": [], "blocks": [], "samplers": [ - {"name":"u_edgeTexSampler", "type":28, "count":1, "defines":[], "binding":0}, - {"name":"u_areaTexSampler", "type":28, "count":1, "defines":[], "binding":1}, - {"name":"u_searchTexSampler", "type":28, "count":1, "defines":[], "binding":2} + {"name":"u_edgeTexSampler", "type":28, "count":1, "defines":[], "binding":30}, + {"name":"u_areaTexSampler", "type":28, "count":1, "defines":[], "binding":31}, + {"name":"u_searchTexSampler", "type":28, "count":1, "defines":[], "binding":32} ], "dependencies": {} } @@ -361,14 +363,14 @@ export default [ "shaders": [ { "name": "pipeline/tonemap|tonemap-vs:vert|tonemap-fs:frag", - "hash": 1101183755, + "hash": 840457535, "glsl3": { "vert": `\nprecision highp float;\n#define saturate(a) clamp( a, 0.0, 1.0 )\nuniform CCGlobal {\n vec4 cc_time;\n vec4 cc_screenSize;\n vec4 cc_screenScale;\n vec4 cc_nativeSize;\n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos;\n vec4 cc_exposure;\n vec4 cc_mainLitDir;\n vec4 cc_mainLitColor;\n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\nin vec2 a_position;\nin vec2 a_texCoord;\nout vec2 v_uv;\nout vec4 v_offset;\nvec4 vert () {\n vec4 pos = vec4(a_position, 0, 1);\n v_uv = a_texCoord * cc_screenScale.xy;\n v_offset = v_uv.xyxy + cc_nativeSize.zwzw * vec4(1.0, 0.0, 0.0, -1.0);\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n`, - "frag": `\nprecision highp float;\nuniform CCGlobal {\n vec4 cc_time;\n vec4 cc_screenSize;\n vec4 cc_screenScale;\n vec4 cc_nativeSize;\n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos;\n vec4 cc_exposure;\n vec4 cc_mainLitDir;\n vec4 cc_mainLitColor;\n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\n#define saturate(a) clamp( a, 0.0, 1.0 )\nvec3 SRGBToLinear(vec3 gamma)\n{\n return pow(gamma, vec3(2.2));\n}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\n}\nvec3 ACESToneMap(vec3 color) {\n const float A = 2.51;\n const float B = 0.03;\n const float C = 2.43;\n const float D = 0.59;\n const float E = 0.14;\n return (color * (A * color + B)) / (color * (C * color + D) + E);\n}\nin vec2 v_uv;\nin vec4 v_offset;\nuniform sampler2D u_texSampler;\nuniform sampler2D u_blendTexSampler;\nvec3 ToLDR(vec3 color) {\n#if CC_USE_HDR\n color *= cc_exposure.x * 1024.0;\n color = ACESToneMap(color);\n color = LinearToSRGB(color);\n#else\n color = SRGBToLinear(color);\n color = ACESToneMap(color);\n color = LinearToSRGB(color);\n#endif\n return color;\n}\nvec4 frag () {\n#if CC_USE_SMAA\n vec4 a;\n a.rb = texture(u_blendTexSampler, v_uv).rb;\n a.g = texture(u_blendTexSampler, v_offset.zw).g;\n a.a = texture(u_blendTexSampler, v_offset.xy).a;\n if (dot(a, vec4(1.0)) < 1e-5) {\n vec4 o = texture(u_texSampler, v_uv);\n o.rgb = ToLDR(o.rgb);\n return o;\n } else {\n vec2 offset;\n offset.x = a.a > a.b ? a.a : -a.b;\n offset.y = a.g > a.r ? -a.g : a.r;\n if (abs(offset.x) > abs(offset.y)) {\n offset.y = 0.0;\n } else {\n offset.x = 0.0;\n }\n vec4 C = texture(u_texSampler, v_uv);\n C.rgb = ToLDR(C.rgb);\n vec2 uv = v_uv + sign(offset) * cc_nativeSize.zw;\n vec4 Cop = texture(u_texSampler, uv);\n Cop.rgb = ToLDR(Cop.rgb);\n float s = abs(offset.x) > abs(offset.y) ? abs(offset.x) : abs(offset.y);\n C.rgb = pow(C.rgb, vec3(2.2));\n Cop.rgb = pow(Cop.rgb, vec3(2.2));\n vec4 mixed = mix(C, Cop, s);\n mixed.rgb = pow(mixed.rgb, vec3(1.0 / 2.2));\n return mixed;\n }\n#else\n vec4 o = texture(u_texSampler, v_uv);\n o.rgb = ToLDR(o.rgb);\n return o;\n#endif\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }\n` + "frag": `\nprecision highp float;\nuniform CCGlobal {\n vec4 cc_time;\n vec4 cc_screenSize;\n vec4 cc_screenScale;\n vec4 cc_nativeSize;\n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos;\n vec4 cc_exposure;\n vec4 cc_mainLitDir;\n vec4 cc_mainLitColor;\n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\n#define saturate(a) clamp( a, 0.0, 1.0 )\nvec3 SRGBToLinear(vec3 gamma)\n{\n return pow(gamma, vec3(2.2));\n}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\n}\nvec3 ACESToneMap(vec3 color) {\n const float A = 2.51;\n const float B = 0.03;\n const float C = 2.43;\n const float D = 0.59;\n const float E = 0.14;\n return (color * (A * color + B)) / (color * (C * color + D) + E);\n}\nin vec2 v_uv;\nin vec4 v_offset;\nuniform sampler2D u_texSampler;\nuniform sampler2D u_blendTexSampler;\nvec3 ToLDR(vec3 color) {\n #if CC_USE_HDR\n color *= cc_exposure.x * 1024.0;\n color = ACESToneMap(color);\n color = LinearToSRGB(color);\n #endif\n return color;\n}\nvec4 frag () {\n#if CC_USE_SMAA\n vec4 a;\n a.rb = texture(u_blendTexSampler, v_uv).rb;\n a.g = texture(u_blendTexSampler, v_offset.zw).g;\n a.a = texture(u_blendTexSampler, v_offset.xy).a;\n if (dot(a, vec4(1.0)) < 1e-5) {\n vec4 o = texture(u_texSampler, v_uv);\n o.rgb = ToLDR(o.rgb);\n return o;\n } else {\n vec2 offset;\n offset.x = a.a > a.b ? a.a : -a.b;\n offset.y = a.g > a.r ? -a.g : a.r;\n if (abs(offset.x) > abs(offset.y)) {\n offset.y = 0.0;\n } else {\n offset.x = 0.0;\n }\n vec4 C = texture(u_texSampler, v_uv);\n C.rgb = ToLDR(C.rgb);\n vec2 uv = v_uv + sign(offset) * cc_nativeSize.zw;\n vec4 Cop = texture(u_texSampler, uv);\n Cop.rgb = ToLDR(Cop.rgb);\n float s = abs(offset.x) > abs(offset.y) ? abs(offset.x) : abs(offset.y);\n C.rgb = pow(C.rgb, vec3(2.2));\n Cop.rgb = pow(Cop.rgb, vec3(2.2));\n vec4 mixed = mix(C, Cop, s);\n mixed.rgb = pow(mixed.rgb, vec3(1.0 / 2.2));\n return mixed;\n }\n#else\n vec4 o = texture(u_texSampler, v_uv);\n o.rgb = ToLDR(o.rgb);\n return o;\n#endif\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }\n` }, "glsl1": { "vert": `\nprecision highp float;\n#define saturate(a) clamp( a, 0.0, 1.0 )\nuniform vec4 cc_screenScale;\nuniform vec4 cc_nativeSize;\nattribute vec2 a_position;\nattribute vec2 a_texCoord;\nvarying vec2 v_uv;\nvarying vec4 v_offset;\nvec4 vert () {\n vec4 pos = vec4(a_position, 0, 1);\n v_uv = a_texCoord * cc_screenScale.xy;\n v_offset = v_uv.xyxy + cc_nativeSize.zwzw * vec4(1.0, 0.0, 0.0, -1.0);\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n`, - "frag": `\nprecision highp float;\nuniform vec4 cc_nativeSize;\nuniform vec4 cc_exposure;\n#define saturate(a) clamp( a, 0.0, 1.0 )\nvec3 SRGBToLinear(vec3 gamma)\n{\n return pow(gamma, vec3(2.2));\n}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\n}\nvec3 ACESToneMap(vec3 color) {\n const float A = 2.51;\n const float B = 0.03;\n const float C = 2.43;\n const float D = 0.59;\n const float E = 0.14;\n return (color * (A * color + B)) / (color * (C * color + D) + E);\n}\nvarying vec2 v_uv;\nvarying vec4 v_offset;\nuniform sampler2D u_texSampler;\nuniform sampler2D u_blendTexSampler;\nvec3 ToLDR(vec3 color) {\n#if CC_USE_HDR\n color *= cc_exposure.x * 1024.0;\n color = ACESToneMap(color);\n color = LinearToSRGB(color);\n#else\n color = SRGBToLinear(color);\n color = ACESToneMap(color);\n color = LinearToSRGB(color);\n#endif\n return color;\n}\nvec4 frag () {\n#if CC_USE_SMAA\n vec4 a;\n a.rb = texture2D(u_blendTexSampler, v_uv).rb;\n a.g = texture2D(u_blendTexSampler, v_offset.zw).g;\n a.a = texture2D(u_blendTexSampler, v_offset.xy).a;\n if (dot(a, vec4(1.0)) < 1e-5) {\n vec4 o = texture2D(u_texSampler, v_uv);\n o.rgb = ToLDR(o.rgb);\n return o;\n } else {\n vec2 offset;\n offset.x = a.a > a.b ? a.a : -a.b;\n offset.y = a.g > a.r ? -a.g : a.r;\n if (abs(offset.x) > abs(offset.y)) {\n offset.y = 0.0;\n } else {\n offset.x = 0.0;\n }\n vec4 C = texture2D(u_texSampler, v_uv);\n C.rgb = ToLDR(C.rgb);\n vec2 uv = v_uv + sign(offset) * cc_nativeSize.zw;\n vec4 Cop = texture2D(u_texSampler, uv);\n Cop.rgb = ToLDR(Cop.rgb);\n float s = abs(offset.x) > abs(offset.y) ? abs(offset.x) : abs(offset.y);\n C.rgb = pow(C.rgb, vec3(2.2));\n Cop.rgb = pow(Cop.rgb, vec3(2.2));\n vec4 mixed = mix(C, Cop, s);\n mixed.rgb = pow(mixed.rgb, vec3(1.0 / 2.2));\n return mixed;\n }\n#else\n vec4 o = texture2D(u_texSampler, v_uv);\n o.rgb = ToLDR(o.rgb);\n return o;\n#endif\n}\nvoid main() { gl_FragColor = frag(); }\n` + "frag": `\nprecision highp float;\nuniform vec4 cc_nativeSize;\nuniform vec4 cc_exposure;\n#define saturate(a) clamp( a, 0.0, 1.0 )\nvec3 SRGBToLinear(vec3 gamma)\n{\n return pow(gamma, vec3(2.2));\n}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\n}\nvec3 ACESToneMap(vec3 color) {\n const float A = 2.51;\n const float B = 0.03;\n const float C = 2.43;\n const float D = 0.59;\n const float E = 0.14;\n return (color * (A * color + B)) / (color * (C * color + D) + E);\n}\nvarying vec2 v_uv;\nvarying vec4 v_offset;\nuniform sampler2D u_texSampler;\nuniform sampler2D u_blendTexSampler;\nvec3 ToLDR(vec3 color) {\n #if CC_USE_HDR\n color *= cc_exposure.x * 1024.0;\n color = ACESToneMap(color);\n color = LinearToSRGB(color);\n #endif\n return color;\n}\nvec4 frag () {\n#if CC_USE_SMAA\n vec4 a;\n a.rb = texture2D(u_blendTexSampler, v_uv).rb;\n a.g = texture2D(u_blendTexSampler, v_offset.zw).g;\n a.a = texture2D(u_blendTexSampler, v_offset.xy).a;\n if (dot(a, vec4(1.0)) < 1e-5) {\n vec4 o = texture2D(u_texSampler, v_uv);\n o.rgb = ToLDR(o.rgb);\n return o;\n } else {\n vec2 offset;\n offset.x = a.a > a.b ? a.a : -a.b;\n offset.y = a.g > a.r ? -a.g : a.r;\n if (abs(offset.x) > abs(offset.y)) {\n offset.y = 0.0;\n } else {\n offset.x = 0.0;\n }\n vec4 C = texture2D(u_texSampler, v_uv);\n C.rgb = ToLDR(C.rgb);\n vec2 uv = v_uv + sign(offset) * cc_nativeSize.zw;\n vec4 Cop = texture2D(u_texSampler, uv);\n Cop.rgb = ToLDR(Cop.rgb);\n float s = abs(offset.x) > abs(offset.y) ? abs(offset.x) : abs(offset.y);\n C.rgb = pow(C.rgb, vec3(2.2));\n Cop.rgb = pow(Cop.rgb, vec3(2.2));\n vec4 mixed = mix(C, Cop, s);\n mixed.rgb = pow(mixed.rgb, vec3(1.0 / 2.2));\n return mixed;\n }\n#else\n vec4 o = texture2D(u_texSampler, v_uv);\n o.rgb = ToLDR(o.rgb);\n return o;\n#endif\n}\nvoid main() { gl_FragColor = frag(); }\n` }, "builtins": {"globals":{"blocks":["CCGlobal"], "samplers":[]}, "locals":{"blocks":[], "samplers":[]}}, "defines": [ @@ -377,8 +379,8 @@ export default [ ], "blocks": [], "samplers": [ - {"name":"u_texSampler", "type":28, "count":1, "defines":[], "binding":0}, - {"name":"u_blendTexSampler", "type":28, "count":1, "defines":[], "binding":1} + {"name":"u_texSampler", "type":28, "count":1, "defines":[], "binding":30}, + {"name":"u_blendTexSampler", "type":28, "count":1, "defines":[], "binding":31} ], "dependencies": {} } diff --git a/cocos/renderer/ui/ui-batch-model.ts b/cocos/renderer/ui/ui-batch-model.ts index 62d4e1d9a9..e79cc37a6f 100644 --- a/cocos/renderer/ui/ui-batch-model.ts +++ b/cocos/renderer/ui/ui-batch-model.ts @@ -19,6 +19,7 @@ export class UIBatchModel extends Model { } public updateUBOs () { + return false; } public initialize (ia: GFXInputAssembler, batch: UIDrawBatch) { diff --git a/cocos/renderer/ui/ui.ts b/cocos/renderer/ui/ui.ts index 2e5a95f59a..06c519166b 100644 --- a/cocos/renderer/ui/ui.ts +++ b/cocos/renderer/ui/ui.ts @@ -12,6 +12,7 @@ import { GFXDevice } from '../../gfx/device'; import { IGFXAttribute } from '../../gfx/input-assembler'; import { GFXPipelineState } from '../../gfx/pipeline-state'; import { GFXTextureView } from '../../gfx/texture-view'; +import { UniformBinding } from '../../pipeline/define'; import { Node } from '../../scene-graph/node'; import { Camera } from '../scene/camera'; import { Model } from '../scene/model'; @@ -71,7 +72,7 @@ export class UI { return this._currMeshBuffer; } - get debugScreen (){ + get debugScreen () { return this._debugScreen; } @@ -288,7 +289,8 @@ export class UI { } } else { const bindingLayout = batch.bindingLayout!; - bindingLayout.bindTextureView(0, batch.texView!); + // assumes sprite materials has only one sampler + bindingLayout.bindTextureView(UniformBinding.CUSTOM_SAMPLER_BINDING_START_POINT, batch.texView!); bindingLayout.update(); const ia = batch.bufferBatch!.ia!;