diff --git a/cocos/3d/assets/effect-asset.ts b/cocos/3d/assets/effect-asset.ts index eb82e89160..f3e58736d2 100644 --- a/cocos/3d/assets/effect-asset.ts +++ b/cocos/3d/assets/effect-asset.ts @@ -10,7 +10,7 @@ export interface IPropertyInfo { type: number; // auto-extracted if not specified value?: number[] | string; displayName?: string; - sampler?: IGFXSamplerInfo; + sampler?: number[]; } export interface IPassStates { priority?: number; diff --git a/cocos/3d/builtin/effects.js b/cocos/3d/builtin/effects.js index 4984d859a2..09baa3c29d 100644 --- a/cocos/3d/builtin/effects.js +++ b/cocos/3d/builtin/effects.js @@ -8,13 +8,13 @@ export default [ "shaders": [ { "name": "builtin-base|base-vs:vert|base-fs:frag", - "hash": 3702598092, + "hash": 3414276249, "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 vec4 a_color;\nout vec4 color;\nvec4 vert () {\n vec4 pos = vec4(a_position, 1);\n pos = cc_matViewProj * pos;\n color = a_color;\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n`, + "vert": `\nprecision mediump float;\nuniform CCGlobal {\n vec4 cc_time; \n vec4 cc_screenSize; \n vec4 cc_screenScale; \n 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 vec4 a_color;\nout vec4 color;\nvec4 vert () {\n vec4 pos = vec4(a_position, 1);\n pos = cc_matViewProj * pos;\n color = a_color;\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n`, "frag": `\nprecision mediump float;\nin vec4 color;\nvec4 frag () {\n vec4 o = vec4(1, 1, 1, 1);\n o *= color;\n return o;\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }\n` }, "glsl1": { - "vert": `\nprecision mediump float;\nuniform vec4 cc_time;\nuniform vec4 cc_screenSize;\nuniform vec4 cc_screenScale;\nuniform vec4 cc_nativeSize;\nuniform mat4 cc_matView;\nuniform mat4 cc_matViewInv;\nuniform mat4 cc_matProj;\nuniform mat4 cc_matProjInv;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matViewProjInv;\nuniform vec4 cc_cameraPos;\nuniform vec4 cc_exposure;\nuniform vec4 cc_mainLitDir;\nuniform vec4 cc_mainLitColor;\nuniform vec4 cc_ambientSky;\nuniform vec4 cc_ambientGround;\nattribute vec3 a_position;\nattribute vec4 a_color;\nvarying vec4 color;\nvec4 vert () {\n vec4 pos = vec4(a_position, 1);\n pos = cc_matViewProj * pos;\n color = a_color;\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n`, + "vert": `\nprecision mediump float;\nuniform vec4 cc_time;\nuniform vec4 cc_screenSize;\nuniform vec4 cc_screenScale;\nuniform mat4 cc_matView;\nuniform mat4 cc_matViewInv;\nuniform mat4 cc_matProj;\nuniform mat4 cc_matProjInv;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matViewProjInv;\nuniform vec4 cc_cameraPos;\nuniform vec4 cc_exposure;\nuniform vec4 cc_mainLitDir;\nuniform vec4 cc_mainLitColor;\nuniform vec4 cc_ambientSky;\nuniform vec4 cc_ambientGround;\nattribute vec3 a_position;\nattribute vec4 a_color;\nvarying vec4 color;\nvec4 vert () {\n vec4 pos = vec4(a_position, 1);\n pos = cc_matViewProj * pos;\n color = a_color;\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n`, "frag": `\nprecision mediump float;\nvarying vec4 color;\nvec4 frag () {\n vec4 o = vec4(1, 1, 1, 1);\n o *= color;\n return o;\n}\nvoid main() { gl_FragColor = frag(); }\n` }, "builtins": {"globals":{"blocks":["CCGlobal"], "samplers":[]}, "locals":{"blocks":[], "samplers":[]}}, @@ -33,14 +33,14 @@ export default [ "shaders": [ { "name": "builtin-particle|particle-vs-legacy:lpvs_main|tinted-fs:add", - "hash": 3974572805, + "hash": 1697722855, "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 USE_BILLBOARD || USE_VERTICAL_BILLBOARD\n , mat4 view\n#endif\n#if 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 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 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 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 USE_VERTICAL_BILLBOARD\n vec3 camRight = normalize(vec3(view[0][0], view[1][0], view[2][0]));\n vec3 camUp = vec3(0, 1, 0);\n pos.xyz += (camRight * vertOffset.x) + (camUp * vertOffset.y);\n#else\n pos.x += vertOffset.x;\n pos.y += vertOffset.y;\n#endif\n}\nvec2 computeUV(float frameIndex, vec2 vertIndex, vec2 frameTile) {\n vec2 aniUV = vec2(0, floor(frameIndex * frameTile.y));\n aniUV.x = floor(frameIndex * frameTile.x * frameTile.y - aniUV.y * frameTile.x);\n \n vertIndex.x = 1. - vertIndex.x;\n return (aniUV.xy + vertIndex) / vec2(frameTile.x, frameTile.y);\n}\nvoid rotateCorner(inout vec2 corner, float angle) {\n float xOS = cos(angle) * corner.x - sin(angle) * corner.y;\n float yOS = sin(angle) * corner.x + cos(angle) * corner.y;\n corner.x = xOS;\n corner.y = yOS;\n}\nin vec3 a_position; \nin vec3 a_texCoord; \nin vec2 a_texCoord1; \nin vec4 a_color;\n#if USE_STRETCHED_BILLBOARD\nin vec3 a_color1; \n#endif\nvec4 lpvs_main() {\n vec4 pos = vec4(a_position, 1);\n#if USE_STRETCHED_BILLBOARD\n vec4 velocity = vec4(a_color1.xyz, 0);\n#endif\n#if !USE_WORLD_SPACE\n pos = cc_matWorld * pos;\n #if USE_STRETCHED_BILLBOARD\n velocity = cc_matWorld * velocity;\n #endif\n#endif\n vec2 cornerOffset = vec2((a_texCoord.xy - 0.5) * a_texCoord1.x);\n#if !USE_STRETCHED_BILLBOARD\n rotateCorner(cornerOffset, a_texCoord1.y);\n#endif\n computeVertPos(pos, cornerOffset\n #if USE_BILLBOARD || USE_VERTICAL_BILLBOARD\n , cc_matView\n #endif\n #if 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 pos = cc_matViewProj * pos;\n uv = computeUV(a_texCoord.z, a_texCoord.xy, frameTile_velLenScale.xy) * mainTiling_Offset.xy + mainTiling_Offset.zw;\n color = a_color;\n return pos;\n}\nvoid main() { gl_Position = lpvs_main(); }\n`, - "frag": `\nprecision mediump float;\nuniform CCGlobal {\n vec4 cc_time; \n vec4 cc_screenSize; \n vec4 cc_screenScale; \n vec4 cc_nativeSize; \n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos; \n vec4 cc_exposure; \n vec4 cc_mainLitDir; \n vec4 cc_mainLitColor; \n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\nvec4 PostProcess(vec4 color, float scale, float isHDR)\n{\n#if CC_USE_HDR\n color.rgb = mix(color.rgb, pow(color.rgb, vec3(2.2)) * scale, vec3(isHDR));\n#endif\n return color;\n}\nin vec2 uv;\nin vec4 color;\nuniform sampler2D mainTexture;\nuniform FragConstants {\n vec4 tintColor;\n};\nvec4 add () {\n vec4 col = 2.0 * color * tintColor * texture(mainTexture, uv);\n return PostProcess(col, cc_exposure.w, cc_exposure.z);\n}\nvec4 multiply () {\n vec4 col;\n vec4 texColor = texture(mainTexture, uv);\n col.rgb = tintColor.rgb * texColor.rgb * color.rgb * vec3(2.0);\n col.a = (1.0 - texColor.a) * (tintColor.a * color.a * 2.0);\n return PostProcess(col, cc_exposure.w, cc_exposure.z);\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};\nuniform CCGlobal {\n vec4 cc_time; \n vec4 cc_screenSize; \n vec4 cc_screenScale; \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 USE_BILLBOARD || USE_VERTICAL_BILLBOARD\n , mat4 view\n#endif\n#if 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 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 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 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 USE_VERTICAL_BILLBOARD\n vec3 camRight = normalize(vec3(view[0][0], view[1][0], view[2][0]));\n vec3 camUp = vec3(0, 1, 0);\n pos.xyz += (camRight * vertOffset.x) + (camUp * vertOffset.y);\n#else\n pos.x += vertOffset.x;\n pos.y += vertOffset.y;\n#endif\n}\nvec2 computeUV(float frameIndex, vec2 vertIndex, vec2 frameTile) {\n vec2 aniUV = vec2(0, floor(frameIndex * frameTile.y));\n aniUV.x = floor(frameIndex * frameTile.x * frameTile.y - aniUV.y * frameTile.x);\n \n vertIndex.x = 1. - vertIndex.x;\n return (aniUV.xy + vertIndex) / vec2(frameTile.x, frameTile.y);\n}\nvoid rotateCorner(inout vec2 corner, float angle) {\n float xOS = cos(angle) * corner.x - sin(angle) * corner.y;\n float yOS = sin(angle) * corner.x + cos(angle) * corner.y;\n corner.x = xOS;\n corner.y = yOS;\n}\nin vec3 a_position; \nin vec3 a_texCoord; \nin vec2 a_texCoord1; \nin vec4 a_color;\n#if USE_STRETCHED_BILLBOARD\nin vec3 a_color1; \n#endif\nvec4 lpvs_main() {\n vec4 pos = vec4(a_position, 1);\n#if USE_STRETCHED_BILLBOARD\n vec4 velocity = vec4(a_color1.xyz, 0);\n#endif\n#if !USE_WORLD_SPACE\n pos = cc_matWorld * pos;\n #if USE_STRETCHED_BILLBOARD\n velocity = cc_matWorld * velocity;\n #endif\n#endif\n vec2 cornerOffset = vec2((a_texCoord.xy - 0.5) * a_texCoord1.x);\n#if !USE_STRETCHED_BILLBOARD\n rotateCorner(cornerOffset, a_texCoord1.y);\n#endif\n computeVertPos(pos, cornerOffset\n #if USE_BILLBOARD || USE_VERTICAL_BILLBOARD\n , cc_matView\n #endif\n #if 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 pos = cc_matViewProj * pos;\n uv = computeUV(a_texCoord.z, a_texCoord.xy, frameTile_velLenScale.xy) * mainTiling_Offset.xy + mainTiling_Offset.zw;\n color = a_color;\n return pos;\n}\nvoid main() { gl_Position = lpvs_main(); }\n`, + "frag": `\nprecision mediump float;\nuniform CCGlobal {\n vec4 cc_time; \n vec4 cc_screenSize; \n vec4 cc_screenScale; \n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos; \n vec4 cc_exposure; \n vec4 cc_mainLitDir; \n vec4 cc_mainLitColor; \n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\nvec4 PostProcess(vec4 color)\n{\n#if CC_USE_HDR\n color.rgb = mix(color.rgb, pow(color.rgb, vec3(2.2)) * cc_exposure.w, vec3(cc_exposure.z));\n#endif\n return color;\n}\nin vec2 uv;\nin vec4 color;\nuniform sampler2D mainTexture;\nuniform FragConstants {\n vec4 tintColor;\n};\nvec4 add () {\n vec4 col = 2.0 * color * tintColor * texture(mainTexture, uv);\n return PostProcess(col);\n}\nvec4 multiply () {\n vec4 col;\n vec4 texColor = texture(mainTexture, uv);\n col.rgb = tintColor.rgb * texColor.rgb * color.rgb * vec3(2.0);\n col.a = (1.0 - texColor.a) * (tintColor.a * color.a * 2.0);\n return PostProcess(col);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = add(); }\n` }, "glsl1": { - "vert": `\nprecision mediump float;\nuniform vec4 mainTiling_Offset;\nuniform vec4 frameTile_velLenScale;\nuniform vec4 cc_time;\nuniform vec4 cc_screenSize;\nuniform vec4 cc_screenScale;\nuniform vec4 cc_nativeSize;\nuniform mat4 cc_matView;\nuniform mat4 cc_matViewInv;\nuniform mat4 cc_matProj;\nuniform mat4 cc_matProjInv;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matViewProjInv;\nuniform vec4 cc_cameraPos;\nuniform vec4 cc_exposure;\nuniform vec4 cc_mainLitDir;\nuniform vec4 cc_mainLitColor;\nuniform vec4 cc_ambientSky;\nuniform vec4 cc_ambientGround;\nuniform mat4 cc_matWorld;\nuniform mat4 cc_matWorldIT;\nvarying vec2 uv;\nvarying vec4 color;\nvoid computeVertPos(inout vec4 pos, vec2 vertOffset\n#if USE_BILLBOARD || USE_VERTICAL_BILLBOARD\n , mat4 view\n#endif\n#if 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 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 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 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 USE_VERTICAL_BILLBOARD\n vec3 camRight = normalize(vec3(view[0][0], view[1][0], view[2][0]));\n vec3 camUp = vec3(0, 1, 0);\n pos.xyz += (camRight * vertOffset.x) + (camUp * vertOffset.y);\n#else\n pos.x += vertOffset.x;\n pos.y += vertOffset.y;\n#endif\n}\nvec2 computeUV(float frameIndex, vec2 vertIndex, vec2 frameTile) {\n vec2 aniUV = vec2(0, floor(frameIndex * frameTile.y));\n aniUV.x = floor(frameIndex * frameTile.x * frameTile.y - aniUV.y * frameTile.x);\n \n vertIndex.x = 1. - vertIndex.x;\n return (aniUV.xy + vertIndex) / vec2(frameTile.x, frameTile.y);\n}\nvoid rotateCorner(inout vec2 corner, float angle) {\n float xOS = cos(angle) * corner.x - sin(angle) * corner.y;\n float yOS = sin(angle) * corner.x + cos(angle) * corner.y;\n corner.x = xOS;\n corner.y = yOS;\n}\nattribute vec3 a_position; \nattribute vec3 a_texCoord; \nattribute vec2 a_texCoord1; \nattribute vec4 a_color;\n#if USE_STRETCHED_BILLBOARD\nattribute vec3 a_color1; \n#endif\nvec4 lpvs_main() {\n vec4 pos = vec4(a_position, 1);\n#if USE_STRETCHED_BILLBOARD\n vec4 velocity = vec4(a_color1.xyz, 0);\n#endif\n#if !USE_WORLD_SPACE\n pos = cc_matWorld * pos;\n #if USE_STRETCHED_BILLBOARD\n velocity = cc_matWorld * velocity;\n #endif\n#endif\n vec2 cornerOffset = vec2((a_texCoord.xy - 0.5) * a_texCoord1.x);\n#if !USE_STRETCHED_BILLBOARD\n rotateCorner(cornerOffset, a_texCoord1.y);\n#endif\n computeVertPos(pos, cornerOffset\n #if USE_BILLBOARD || USE_VERTICAL_BILLBOARD\n , cc_matView\n #endif\n #if 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 pos = cc_matViewProj * pos;\n uv = computeUV(a_texCoord.z, a_texCoord.xy, frameTile_velLenScale.xy) * mainTiling_Offset.xy + mainTiling_Offset.zw;\n color = a_color;\n return pos;\n}\nvoid main() { gl_Position = lpvs_main(); }\n`, - "frag": `\nprecision mediump float;\nuniform vec4 cc_time;\nuniform vec4 cc_screenSize;\nuniform vec4 cc_screenScale;\nuniform vec4 cc_nativeSize;\nuniform mat4 cc_matView;\nuniform mat4 cc_matViewInv;\nuniform mat4 cc_matProj;\nuniform mat4 cc_matProjInv;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matViewProjInv;\nuniform vec4 cc_cameraPos;\nuniform vec4 cc_exposure;\nuniform vec4 cc_mainLitDir;\nuniform vec4 cc_mainLitColor;\nuniform vec4 cc_ambientSky;\nuniform vec4 cc_ambientGround;\nvec4 PostProcess(vec4 color, float scale, float isHDR)\n{\n#if CC_USE_HDR\n color.rgb = mix(color.rgb, pow(color.rgb, vec3(2.2)) * scale, vec3(isHDR));\n#endif\n return color;\n}\nvarying vec2 uv;\nvarying vec4 color;\nuniform sampler2D mainTexture;\nuniform vec4 tintColor;\nvec4 add () {\n vec4 col = 2.0 * color * tintColor * texture2D(mainTexture, uv);\n return PostProcess(col, cc_exposure.w, cc_exposure.z);\n}\nvec4 multiply () {\n vec4 col;\n vec4 texColor = texture2D(mainTexture, uv);\n col.rgb = tintColor.rgb * texColor.rgb * color.rgb * vec3(2.0);\n col.a = (1.0 - texColor.a) * (tintColor.a * color.a * 2.0);\n return PostProcess(col, cc_exposure.w, cc_exposure.z);\n}\nvoid main() { gl_FragColor = add(); }\n` + "vert": `\nprecision mediump float;\nuniform vec4 mainTiling_Offset;\nuniform vec4 frameTile_velLenScale;\nuniform vec4 cc_time;\nuniform vec4 cc_screenSize;\nuniform vec4 cc_screenScale;\nuniform mat4 cc_matView;\nuniform mat4 cc_matViewInv;\nuniform mat4 cc_matProj;\nuniform mat4 cc_matProjInv;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matViewProjInv;\nuniform vec4 cc_cameraPos;\nuniform vec4 cc_exposure;\nuniform vec4 cc_mainLitDir;\nuniform vec4 cc_mainLitColor;\nuniform vec4 cc_ambientSky;\nuniform vec4 cc_ambientGround;\nuniform mat4 cc_matWorld;\nuniform mat4 cc_matWorldIT;\nvarying vec2 uv;\nvarying vec4 color;\nvoid computeVertPos(inout vec4 pos, vec2 vertOffset\n#if USE_BILLBOARD || USE_VERTICAL_BILLBOARD\n , mat4 view\n#endif\n#if 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 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 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 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 USE_VERTICAL_BILLBOARD\n vec3 camRight = normalize(vec3(view[0][0], view[1][0], view[2][0]));\n vec3 camUp = vec3(0, 1, 0);\n pos.xyz += (camRight * vertOffset.x) + (camUp * vertOffset.y);\n#else\n pos.x += vertOffset.x;\n pos.y += vertOffset.y;\n#endif\n}\nvec2 computeUV(float frameIndex, vec2 vertIndex, vec2 frameTile) {\n vec2 aniUV = vec2(0, floor(frameIndex * frameTile.y));\n aniUV.x = floor(frameIndex * frameTile.x * frameTile.y - aniUV.y * frameTile.x);\n \n vertIndex.x = 1. - vertIndex.x;\n return (aniUV.xy + vertIndex) / vec2(frameTile.x, frameTile.y);\n}\nvoid rotateCorner(inout vec2 corner, float angle) {\n float xOS = cos(angle) * corner.x - sin(angle) * corner.y;\n float yOS = sin(angle) * corner.x + cos(angle) * corner.y;\n corner.x = xOS;\n corner.y = yOS;\n}\nattribute vec3 a_position; \nattribute vec3 a_texCoord; \nattribute vec2 a_texCoord1; \nattribute vec4 a_color;\n#if USE_STRETCHED_BILLBOARD\nattribute vec3 a_color1; \n#endif\nvec4 lpvs_main() {\n vec4 pos = vec4(a_position, 1);\n#if USE_STRETCHED_BILLBOARD\n vec4 velocity = vec4(a_color1.xyz, 0);\n#endif\n#if !USE_WORLD_SPACE\n pos = cc_matWorld * pos;\n #if USE_STRETCHED_BILLBOARD\n velocity = cc_matWorld * velocity;\n #endif\n#endif\n vec2 cornerOffset = vec2((a_texCoord.xy - 0.5) * a_texCoord1.x);\n#if !USE_STRETCHED_BILLBOARD\n rotateCorner(cornerOffset, a_texCoord1.y);\n#endif\n computeVertPos(pos, cornerOffset\n #if USE_BILLBOARD || USE_VERTICAL_BILLBOARD\n , cc_matView\n #endif\n #if 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 pos = cc_matViewProj * pos;\n uv = computeUV(a_texCoord.z, a_texCoord.xy, frameTile_velLenScale.xy) * mainTiling_Offset.xy + mainTiling_Offset.zw;\n color = a_color;\n return pos;\n}\nvoid main() { gl_Position = lpvs_main(); }\n`, + "frag": `\nprecision mediump float;\nuniform vec4 cc_time;\nuniform vec4 cc_screenSize;\nuniform vec4 cc_screenScale;\nuniform mat4 cc_matView;\nuniform mat4 cc_matViewInv;\nuniform mat4 cc_matProj;\nuniform mat4 cc_matProjInv;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matViewProjInv;\nuniform vec4 cc_cameraPos;\nuniform vec4 cc_exposure;\nuniform vec4 cc_mainLitDir;\nuniform vec4 cc_mainLitColor;\nuniform vec4 cc_ambientSky;\nuniform vec4 cc_ambientGround;\nvec4 PostProcess(vec4 color)\n{\n#if CC_USE_HDR\n color.rgb = mix(color.rgb, pow(color.rgb, vec3(2.2)) * cc_exposure.w, vec3(cc_exposure.z));\n#endif\n return color;\n}\nvarying vec2 uv;\nvarying vec4 color;\nuniform sampler2D mainTexture;\nuniform vec4 tintColor;\nvec4 add () {\n vec4 col = 2.0 * color * tintColor * texture2D(mainTexture, uv);\n return PostProcess(col);\n}\nvec4 multiply () {\n vec4 col;\n vec4 texColor = texture2D(mainTexture, uv);\n col.rgb = tintColor.rgb * texColor.rgb * color.rgb * vec3(2.0);\n col.a = (1.0 - texColor.a) * (tintColor.a * color.a * 2.0);\n return PostProcess(col);\n}\nvoid main() { gl_FragColor = add(); }\n` }, "builtins": {"globals":{"blocks":["CCGlobal"], "samplers":[]}, "locals":{"blocks":["CCLocal"], "samplers":[]}}, "defines": [ @@ -75,14 +75,14 @@ export default [ "shaders": [ { "name": "builtin-skybox|sky-vs:vert|sky-fs:frag", - "hash": 434392379, + "hash": 1728334606, "glsl3": { - "vert": `\nprecision mediump float;\nin vec3 a_position;\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};\nout vec3 viewDir;\nvec4 vert () {\n mat4 matViewRotOnly = mat4(mat3(cc_matView));\n vec4 clipPos = cc_matProj * matViewRotOnly * vec4(a_position, 1.0);\n viewDir = a_position;\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;\nin vec3 viewDir;\nuniform samplerCube cubeMap;\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}\nuniform CCGlobal {\n vec4 cc_time; \n vec4 cc_screenSize; \n vec4 cc_screenScale; \n vec4 cc_nativeSize; \n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos; \n vec4 cc_exposure; \n vec4 cc_mainLitDir; \n vec4 cc_mainLitColor; \n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\nvec4 PostProcess(vec4 color, float scale, float isHDR)\n{\n#if CC_USE_HDR\n color.rgb = mix(color.rgb, pow(color.rgb, vec3(2.2)) * scale, vec3(isHDR));\n#endif\n return color;\n}\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 PostProcess(o, cc_exposure.w, cc_exposure.z);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }\n` + "vert": `\nprecision mediump float;\nin vec3 a_position;\nuniform CCGlobal {\n vec4 cc_time; \n vec4 cc_screenSize; \n vec4 cc_screenScale; \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};\nout vec3 viewDir;\nvec4 vert () {\n mat4 matViewRotOnly = mat4(mat3(cc_matView));\n vec4 clipPos = cc_matProj * matViewRotOnly * vec4(a_position, 1.0);\n viewDir = a_position;\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;\nin vec3 viewDir;\nuniform samplerCube cubeMap;\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 \n}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\n \n}\nuniform CCGlobal {\n vec4 cc_time; \n vec4 cc_screenSize; \n vec4 cc_screenScale; \n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos; \n vec4 cc_exposure; \n vec4 cc_mainLitDir; \n vec4 cc_mainLitColor; \n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\nvec4 PostProcess(vec4 color)\n{\n#if CC_USE_HDR\n color.rgb = mix(color.rgb, pow(color.rgb, vec3(2.2)) * cc_exposure.w, vec3(cc_exposure.z));\n#endif\n return color;\n}\nvec4 frag () {\n#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 PostProcess(o);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }\n` }, "glsl1": { - "vert": `\nprecision mediump float;\nattribute vec3 a_position;\nuniform vec4 cc_time;\nuniform vec4 cc_screenSize;\nuniform vec4 cc_screenScale;\nuniform vec4 cc_nativeSize;\nuniform mat4 cc_matView;\nuniform mat4 cc_matViewInv;\nuniform mat4 cc_matProj;\nuniform mat4 cc_matProjInv;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matViewProjInv;\nuniform vec4 cc_cameraPos;\nuniform vec4 cc_exposure;\nuniform vec4 cc_mainLitDir;\nuniform vec4 cc_mainLitColor;\nuniform vec4 cc_ambientSky;\nuniform vec4 cc_ambientGround;\nvarying vec3 viewDir;\nvec4 vert () {\n mat4 matViewRotOnly = mat4(mat3(cc_matView));\n vec4 clipPos = cc_matProj * matViewRotOnly * vec4(a_position, 1.0);\n viewDir = a_position;\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;\nvarying vec3 viewDir;\nuniform samplerCube cubeMap;\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}\nuniform vec4 cc_time;\nuniform vec4 cc_screenSize;\nuniform vec4 cc_screenScale;\nuniform vec4 cc_nativeSize;\nuniform mat4 cc_matView;\nuniform mat4 cc_matViewInv;\nuniform mat4 cc_matProj;\nuniform mat4 cc_matProjInv;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matViewProjInv;\nuniform vec4 cc_cameraPos;\nuniform vec4 cc_exposure;\nuniform vec4 cc_mainLitDir;\nuniform vec4 cc_mainLitColor;\nuniform vec4 cc_ambientSky;\nuniform vec4 cc_ambientGround;\nvec4 PostProcess(vec4 color, float scale, float isHDR)\n{\n#if CC_USE_HDR\n color.rgb = mix(color.rgb, pow(color.rgb, vec3(2.2)) * scale, vec3(isHDR));\n#endif\n return color;\n}\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 PostProcess(o, cc_exposure.w, cc_exposure.z);\n}\nvoid main() { gl_FragColor = frag(); }\n` + "vert": `\nprecision mediump float;\nattribute vec3 a_position;\nuniform vec4 cc_time;\nuniform vec4 cc_screenSize;\nuniform vec4 cc_screenScale;\nuniform mat4 cc_matView;\nuniform mat4 cc_matViewInv;\nuniform mat4 cc_matProj;\nuniform mat4 cc_matProjInv;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matViewProjInv;\nuniform vec4 cc_cameraPos;\nuniform vec4 cc_exposure;\nuniform vec4 cc_mainLitDir;\nuniform vec4 cc_mainLitColor;\nuniform vec4 cc_ambientSky;\nuniform vec4 cc_ambientGround;\nvarying vec3 viewDir;\nvec4 vert () {\n mat4 matViewRotOnly = mat4(mat3(cc_matView));\n vec4 clipPos = cc_matProj * matViewRotOnly * vec4(a_position, 1.0);\n viewDir = a_position;\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;\nvarying vec3 viewDir;\nuniform samplerCube cubeMap;\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 \n}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\n \n}\nuniform vec4 cc_time;\nuniform vec4 cc_screenSize;\nuniform vec4 cc_screenScale;\nuniform mat4 cc_matView;\nuniform mat4 cc_matViewInv;\nuniform mat4 cc_matProj;\nuniform mat4 cc_matProjInv;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matViewProjInv;\nuniform vec4 cc_cameraPos;\nuniform vec4 cc_exposure;\nuniform vec4 cc_mainLitDir;\nuniform vec4 cc_mainLitColor;\nuniform vec4 cc_ambientSky;\nuniform vec4 cc_ambientGround;\nvec4 PostProcess(vec4 color)\n{\n#if CC_USE_HDR\n color.rgb = mix(color.rgb, pow(color.rgb, vec3(2.2)) * cc_exposure.w, vec3(cc_exposure.z));\n#endif\n return color;\n}\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 PostProcess(o);\n}\nvoid main() { gl_FragColor = frag(); }\n` }, "builtins": {"globals":{"blocks":["CCGlobal"], "samplers":[]}, "locals":{"blocks":[], "samplers":[]}}, "defines": [ @@ -97,56 +97,6 @@ export default [ } ] }, - { - "name": "builtin-smaa", - "techniques": [ - {"name":"smaa", "passes":[{"depthStencilState":{"depthTest":false, "depthWrite":false}, "program":"builtin-smaa|smaa-edge-vs:vert|smaa-edge-fs:frag", "properties":{"u_texSampler":{"type":29, "sampler":{"minFilter":2, "magFilter":2, "addressU":2, "addressV":2}}}}, {"depthStencilState":{"depthTest":false, "depthWrite":false}, "program":"builtin-smaa|smaa-blend-vs:vert|smaa-blend-fs:frag", "properties":{"u_edgeTexSampler":{"type":29, "sampler":{"minFilter":2, "magFilter":2, "addressU":2, "addressV":2}}, "u_areaTexSampler":{"type":29, "sampler":{"minFilter":2, "magFilter":2, "addressU":2, "addressV":2}}, "u_searchTexSampler":{"type":29, "sampler":{"minFilter":1, "magFilter":1, "addressU":2, "addressV":2}}}}]} - ], - "shaders": [ - { - "name": "builtin-smaa|smaa-edge-vs:vert|smaa-edge-fs:frag", - "hash": 3900072987, - "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 PI 3.14159265359\n#define PI2 6.28318530718\n#define EPSILON 1e-6\n#define LOG2 1.442695\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#define FP_MAX = 65504.0;\n#define FP_SCALE (1.0/1024.0);\n#define FP_SCALE_INV 1024.0;\nvec3 SRGBToLinear(vec3 gamma)\n{\n return pow(gamma, vec3(2.2));\n \n}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\n \n}\nvec3 ACESToneMap(vec3 color) {\n const float A = 2.51;\n const float B = 0.03;\n const float C = 2.43;\n const float D = 0.59;\n const float E = 0.14;\n return (color * (A * color + B)) / (color * (C * color + D) + E);\n}\n#define SMAA_THRESHOLD 0.1\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` - }, - "glsl1": { - "vert": `\nprecision highp float;\nuniform vec4 cc_time;\nuniform vec4 cc_screenSize;\nuniform vec4 cc_screenScale;\nuniform vec4 cc_nativeSize;\nuniform mat4 cc_matView;\nuniform mat4 cc_matViewInv;\nuniform mat4 cc_matProj;\nuniform mat4 cc_matProjInv;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matViewProjInv;\nuniform vec4 cc_cameraPos;\nuniform vec4 cc_exposure;\nuniform vec4 cc_mainLitDir;\nuniform vec4 cc_mainLitColor;\nuniform vec4 cc_ambientSky;\nuniform vec4 cc_ambientGround;\nattribute vec2 a_position;\nattribute vec2 a_texCoord;\nvarying vec2 v_uv;\nvarying 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 vec4 cc_time;\nuniform vec4 cc_screenSize;\nuniform vec4 cc_screenScale;\nuniform vec4 cc_nativeSize;\nuniform mat4 cc_matView;\nuniform mat4 cc_matViewInv;\nuniform mat4 cc_matProj;\nuniform mat4 cc_matProjInv;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matViewProjInv;\nuniform vec4 cc_cameraPos;\nuniform vec4 cc_exposure;\nuniform vec4 cc_mainLitDir;\nuniform vec4 cc_mainLitColor;\nuniform vec4 cc_ambientSky;\nuniform vec4 cc_ambientGround;\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define EPSILON 1e-6\n#define LOG2 1.442695\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#define FP_MAX = 65504.0;\n#define FP_SCALE (1.0/1024.0);\n#define FP_SCALE_INV 1024.0;\nvec3 SRGBToLinear(vec3 gamma)\n{\n return pow(gamma, vec3(2.2));\n \n}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\n \n}\nvec3 ACESToneMap(vec3 color) {\n const float A = 2.51;\n const float B = 0.03;\n const float C = 2.43;\n const float D = 0.59;\n const float E = 0.14;\n return (color * (A * color + B)) / (color * (C * color + D) + E);\n}\n#define SMAA_THRESHOLD 0.1\nvarying vec2 v_uv;\nvarying 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(texture2D(u_texSampler, v_uv).rgb);\n vec3 Cleft = ToLDR(texture2D(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(texture2D(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(texture2D(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(texture2D(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(texture2D(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(texture2D(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}\nvoid main() { gl_FragColor = frag(); }\n` - }, - "builtins": {"globals":{"blocks":["CCGlobal"], "samplers":[]}, "locals":{"blocks":[], "samplers":[]}}, - "defines": [ - {"name":"CC_USE_HDR", "type":"boolean", "defines":[]} - ], - "blocks": [], - "samplers": [ - {"name":"u_texSampler", "type":29, "count":1, "defines":[], "binding":0} - ], - "dependencies": {} - }, - { - "name": "builtin-smaa|smaa-blend-vs:vert|smaa-blend-fs:frag", - "hash": 3646492622, - "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};\n#define SMAA_MAX_SEARCH_STEPS 8\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};\n#define SMAA_MAX_SEARCH_STEPS 8\n#define SMAA_AREATEX_MAX_DISTANCE 16\n#define SMAA_AREATEX_PIXEL_SIZE (1.0 / vec2(160.0, 560.0))\n#define SMAA_AREATEX_SUBTEX_SIZE (1.0 / 7.0)\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` - }, - "glsl1": { - "vert": `\nprecision highp float;\nuniform vec4 cc_time;\nuniform vec4 cc_screenSize;\nuniform vec4 cc_screenScale;\nuniform vec4 cc_nativeSize;\nuniform mat4 cc_matView;\nuniform mat4 cc_matViewInv;\nuniform mat4 cc_matProj;\nuniform mat4 cc_matProjInv;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matViewProjInv;\nuniform vec4 cc_cameraPos;\nuniform vec4 cc_exposure;\nuniform vec4 cc_mainLitDir;\nuniform vec4 cc_mainLitColor;\nuniform vec4 cc_ambientSky;\nuniform vec4 cc_ambientGround;\n#define SMAA_MAX_SEARCH_STEPS 8\nattribute vec2 a_position;\nattribute vec2 a_texCoord;\nvarying vec2 v_uv;\nvarying vec4 v_offsets[3];\nvarying 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 vec4 cc_time;\nuniform vec4 cc_screenSize;\nuniform vec4 cc_screenScale;\nuniform vec4 cc_nativeSize;\nuniform mat4 cc_matView;\nuniform mat4 cc_matViewInv;\nuniform mat4 cc_matProj;\nuniform mat4 cc_matProjInv;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matViewProjInv;\nuniform vec4 cc_cameraPos;\nuniform vec4 cc_exposure;\nuniform vec4 cc_mainLitDir;\nuniform vec4 cc_mainLitColor;\nuniform vec4 cc_ambientSky;\nuniform vec4 cc_ambientGround;\n#define SMAA_MAX_SEARCH_STEPS 8\n#define SMAA_AREATEX_MAX_DISTANCE 16\n#define SMAA_AREATEX_PIXEL_SIZE (1.0 / vec2(160.0, 560.0))\n#define SMAA_AREATEX_SUBTEX_SIZE (1.0 / 7.0)\nvarying vec2 v_uv;\nvarying vec4 v_offsets[3];\nvarying 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 * texture2D(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 = texture2D(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 = texture2D(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 = texture2D(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 = texture2D(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 texture2D(u_areaTexSampler, texcoord).rg;\n}\nvec4 frag () {\n vec4 weights = vec4(0.0);\n vec2 e = texture2D(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 = texture2D(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 = texture2D(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 = texture2D(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 = texture2D(u_edgeTexSampler, coords + vec2(0.0, cc_nativeSize.w)).g;\n weights.ba = SMAAArea(sqrt_d, e1, e2);\n }\n return weights;\n}\nvoid main() { gl_FragColor = frag(); }\n` - }, - "builtins": {"globals":{"blocks":["CCGlobal"], "samplers":[]}, "locals":{"blocks":[], "samplers":[]}}, - "defines": [], - "blocks": [], - "samplers": [ - {"name":"u_edgeTexSampler", "type":29, "count":1, "defines":[], "binding":0}, - {"name":"u_areaTexSampler", "type":29, "count":1, "defines":[], "binding":1}, - {"name":"u_searchTexSampler", "type":29, "count":1, "defines":[], "binding":2} - ], - "dependencies": {} - } - ] - }, { "name": "builtin-sprite", "techniques": [ @@ -155,14 +105,14 @@ export default [ "shaders": [ { "name": "builtin-sprite|sprite-vs:vert|sprite-fs:frag", - "hash": 1325858369, + "hash": 748330719, "glsl3": { - "vert": `\nprecision mediump float;\nuniform CCGlobal {\n vec4 cc_time; \n vec4 cc_screenSize; \n vec4 cc_screenScale; \n vec4 cc_nativeSize; \n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos; \n vec4 cc_exposure; \n vec4 cc_mainLitDir; \n vec4 cc_mainLitColor; \n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\nin vec3 a_position;\nin vec2 a_texCoord;\nin vec4 a_color;\nout vec2 uv0;\nout vec4 color;\nvec4 vert () {\n vec4 pos = vec4(a_position, 1);\n pos = cc_matViewProj * pos;\n uv0 = a_texCoord;\n color = a_color;\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n`, - "frag": `\nprecision mediump float;\nuniform CCGlobal {\n vec4 cc_time; \n vec4 cc_screenSize; \n vec4 cc_screenScale; \n vec4 cc_nativeSize; \n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos; \n vec4 cc_exposure; \n vec4 cc_mainLitDir; \n vec4 cc_mainLitColor; \n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\nvec4 PostProcess(vec4 color, float scale, float isHDR)\n{\n#if CC_USE_HDR\n color.rgb = mix(color.rgb, pow(color.rgb, vec3(2.2)) * scale, vec3(isHDR));\n#endif\n return color;\n}\nin vec2 uv0;\nin vec4 color;\nuniform sampler2D mainTexture;\nvec4 frag () {\n vec4 o = vec4(1, 1, 1, 1);\n o *= texture(mainTexture, uv0);\n o *= color;\n return PostProcess(o, cc_exposure.w, cc_exposure.z);\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 mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos; \n vec4 cc_exposure; \n vec4 cc_mainLitDir; \n vec4 cc_mainLitColor; \n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\nin vec3 a_position;\nin vec2 a_texCoord;\nin vec4 a_color;\nout vec2 uv0;\nout vec4 color;\nvec4 vert () {\n vec4 pos = vec4(a_position, 1);\n pos = cc_matViewProj * pos;\n uv0 = a_texCoord;\n color = a_color;\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n`, + "frag": `\nprecision mediump float;\nuniform CCGlobal {\n vec4 cc_time; \n vec4 cc_screenSize; \n vec4 cc_screenScale; \n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos; \n vec4 cc_exposure; \n vec4 cc_mainLitDir; \n vec4 cc_mainLitColor; \n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\nvec4 PostProcess(vec4 color)\n{\n#if CC_USE_HDR\n color.rgb = mix(color.rgb, pow(color.rgb, vec3(2.2)) * cc_exposure.w, vec3(cc_exposure.z));\n#endif\n return color;\n}\nin vec2 uv0;\nin vec4 color;\nuniform sampler2D mainTexture;\nvec4 frag () {\n vec4 o = vec4(1, 1, 1, 1);\n o *= texture(mainTexture, uv0);\n o *= color;\n return PostProcess(o);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }\n` }, "glsl1": { - "vert": `\nprecision mediump float;\nuniform vec4 cc_time;\nuniform vec4 cc_screenSize;\nuniform vec4 cc_screenScale;\nuniform vec4 cc_nativeSize;\nuniform mat4 cc_matView;\nuniform mat4 cc_matViewInv;\nuniform mat4 cc_matProj;\nuniform mat4 cc_matProjInv;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matViewProjInv;\nuniform vec4 cc_cameraPos;\nuniform vec4 cc_exposure;\nuniform vec4 cc_mainLitDir;\nuniform vec4 cc_mainLitColor;\nuniform vec4 cc_ambientSky;\nuniform vec4 cc_ambientGround;\nattribute vec3 a_position;\nattribute vec2 a_texCoord;\nattribute vec4 a_color;\nvarying vec2 uv0;\nvarying vec4 color;\nvec4 vert () {\n vec4 pos = vec4(a_position, 1);\n pos = cc_matViewProj * pos;\n uv0 = a_texCoord;\n color = a_color;\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n`, - "frag": `\nprecision mediump float;\nuniform vec4 cc_time;\nuniform vec4 cc_screenSize;\nuniform vec4 cc_screenScale;\nuniform vec4 cc_nativeSize;\nuniform mat4 cc_matView;\nuniform mat4 cc_matViewInv;\nuniform mat4 cc_matProj;\nuniform mat4 cc_matProjInv;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matViewProjInv;\nuniform vec4 cc_cameraPos;\nuniform vec4 cc_exposure;\nuniform vec4 cc_mainLitDir;\nuniform vec4 cc_mainLitColor;\nuniform vec4 cc_ambientSky;\nuniform vec4 cc_ambientGround;\nvec4 PostProcess(vec4 color, float scale, float isHDR)\n{\n#if CC_USE_HDR\n color.rgb = mix(color.rgb, pow(color.rgb, vec3(2.2)) * scale, vec3(isHDR));\n#endif\n return color;\n}\nvarying vec2 uv0;\nvarying vec4 color;\nuniform sampler2D mainTexture;\nvec4 frag () {\n vec4 o = vec4(1, 1, 1, 1);\n o *= texture2D(mainTexture, uv0);\n o *= color;\n return PostProcess(o, cc_exposure.w, cc_exposure.z);\n}\nvoid main() { gl_FragColor = frag(); }\n` + "vert": `\nprecision mediump float;\nuniform vec4 cc_time;\nuniform vec4 cc_screenSize;\nuniform vec4 cc_screenScale;\nuniform mat4 cc_matView;\nuniform mat4 cc_matViewInv;\nuniform mat4 cc_matProj;\nuniform mat4 cc_matProjInv;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matViewProjInv;\nuniform vec4 cc_cameraPos;\nuniform vec4 cc_exposure;\nuniform vec4 cc_mainLitDir;\nuniform vec4 cc_mainLitColor;\nuniform vec4 cc_ambientSky;\nuniform vec4 cc_ambientGround;\nattribute vec3 a_position;\nattribute vec2 a_texCoord;\nattribute vec4 a_color;\nvarying vec2 uv0;\nvarying vec4 color;\nvec4 vert () {\n vec4 pos = vec4(a_position, 1);\n pos = cc_matViewProj * pos;\n uv0 = a_texCoord;\n color = a_color;\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n`, + "frag": `\nprecision mediump float;\nuniform vec4 cc_time;\nuniform vec4 cc_screenSize;\nuniform vec4 cc_screenScale;\nuniform mat4 cc_matView;\nuniform mat4 cc_matViewInv;\nuniform mat4 cc_matProj;\nuniform mat4 cc_matProjInv;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matViewProjInv;\nuniform vec4 cc_cameraPos;\nuniform vec4 cc_exposure;\nuniform vec4 cc_mainLitDir;\nuniform vec4 cc_mainLitColor;\nuniform vec4 cc_ambientSky;\nuniform vec4 cc_ambientGround;\nvec4 PostProcess(vec4 color)\n{\n#if CC_USE_HDR\n color.rgb = mix(color.rgb, pow(color.rgb, vec3(2.2)) * cc_exposure.w, vec3(cc_exposure.z));\n#endif\n return color;\n}\nvarying vec2 uv0;\nvarying vec4 color;\nuniform sampler2D mainTexture;\nvec4 frag () {\n vec4 o = vec4(1, 1, 1, 1);\n o *= texture2D(mainTexture, uv0);\n o *= color;\n return PostProcess(o);\n}\nvoid main() { gl_FragColor = frag(); }\n` }, "builtins": {"globals":{"blocks":["CCGlobal"], "samplers":[]}, "locals":{"blocks":[], "samplers":[]}}, "defines": [ @@ -179,19 +129,19 @@ export default [ { "name": "builtin-standard", "techniques": [ - {"name":"opaque", "passes":[{"program":"builtin-standard|standard-vs:vert|standard-fs:frag", "properties":{"tilingOffset":{"type":16, "value":[1, 1, 0, 0]}, "albedo":{"type":17, "value":[1, 1, 1, 1]}, "albedoScale":{"type":16, "value":[1, 1, 1, 0]}, "pbrParams":{"type":16, "value":[0.2, 0.6, 1, 1]}, "pbrScale":{"type":16, "value":[1, 1, 1, 1]}, "emissive":{"type":17, "value":[1, 1, 1, 1]}, "emissiveScale":{"type":16, "value":[1, 1, 1, 1]}, "albedoMap":{"type":29, "value":"grey"}, "normalMap":{"type":29, "value":"normal"}, "pbrMap":{"type":29, "value":"grey"}, "emissiveMap":{"type":29, "value":"grey"}, "envMap":{"type":32, "value":"default-cube"}}}, {"depthStencilState":{"depthTest":true, "depthWrite":false}, "program":"builtin-standard|planar-shadow-vs:vert|planar-shadow-fs:frag", "switch":"USE_PLANAR_SHADOW"}]} + {"name":"opaque", "passes":[{"program":"builtin-standard|standard-vs:vert|standard-fs:frag", "properties":{"tilingOffset":{"type":16, "value":[1, 1, 0, 0]}, "albedo":{"type":17, "value":[1, 1, 1, 1]}, "albedoScale":{"type":16, "value":[1, 1, 1, 0]}, "pbrParams":{"type":16, "value":[0.2, 0.6, 1, 1]}, "pbrScale":{"type":16, "value":[1, 1, 1, 1]}, "emissive":{"type":17, "value":[1, 1, 1, 1]}, "emissiveScale":{"type":16, "value":[1, 1, 1, 1]}, "albedoMap":{"type":29, "value":"grey"}, "normalMap":{"type":29, "value":"normal"}, "pbrMap":{"type":29, "value":"grey"}, "emissiveMap":{"type":29, "value":"grey"}, "envMap":{"type":32, "value":"default-cube"}}}, {"depthStencilState":{"depthTest":true, "depthWrite":false}, "blendState":{"targets":[{"blend":true, "blendSrc":2, "blendDst":4, "blendDstAlpha":4}]}, "program":"builtin-standard|planar-shadow-vs:vert|planar-shadow-fs:frag", "switch":"USE_PLANAR_SHADOW"}]} ], "shaders": [ { "name": "builtin-standard|standard-vs:vert|standard-fs:frag", - "hash": 2605281062, + "hash": 2134030718, "glsl3": { - "vert": `\nprecision mediump float;\nuniform CCGlobal {\n vec4 cc_time; \n vec4 cc_screenSize; \n vec4 cc_screenScale; \n vec4 cc_nativeSize; \n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos; \n vec4 cc_exposure; \n vec4 cc_mainLitDir; \n vec4 cc_mainLitColor; \n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\nuniform CCLocal {\n mat4 cc_matWorld;\n mat4 cc_matWorldIT;\n};\nuniform Constants {\n vec4 tilingOffset;\n vec4 albedo;\n vec4 albedoScale; \n vec4 pbrParams; \n vec4 pbrScale; \n vec4 emissive;\n vec4 emissiveScale;\n};\n#if CC_USE_SKINNING\nin vec4 a_weights;\nin vec4 a_joints;\nuniform CCSkinning {\n mat4 cc_matJoint[128];\n vec4 cc_jointsTextureSize;\n};\n#if CC_USE_JOINTS_TEXTURE\nuniform sampler2D cc_jointsTexture;\nmat4 getBoneMatrix(const in float i) {\n float size = cc_jointsTextureSize.x;\n float j = i * 4.0;\n float x = mod(j, size);\n float y = floor(j / size);\n float dx = 1.0 / size;\n float dy = 1.0 / size;\n y = dy * (y + 0.5);\n vec4 v1 = texture(cc_jointsTexture, vec2(dx * (x + 0.5), y));\n vec4 v2 = texture(cc_jointsTexture, vec2(dx * (x + 1.5), y));\n vec4 v3 = texture(cc_jointsTexture, vec2(dx * (x + 2.5), y));\n vec4 v4 = texture(cc_jointsTexture, vec2(dx * (x + 3.5), y));\n return mat4(v1, v2, v3, v4);\n}\n#else\nmat4 getBoneMatrix(const in float i) {\n return cc_matJoint[int(i)];\n}\n#endif\nmat4 skinMatrix() {\n return\n getBoneMatrix(a_joints.x) * a_weights.x +\n getBoneMatrix(a_joints.y) * a_weights.y +\n getBoneMatrix(a_joints.z) * a_weights.z +\n getBoneMatrix(a_joints.w) * a_weights.w;\n}\nvoid skinVertex(inout vec4 a1) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n}\nvoid skinVertex(inout vec4 a1, inout vec4 a2) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n}\nvoid skinVertex(inout vec4 a1, inout vec4 a2, inout vec4 a3) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n a3 = m * a3;\n}\n#endif\nin vec3 a_position;\nin vec3 a_normal;\nout vec3 v_worldPos;\nout vec3 v_worldNormal;\n#if USE_ALBEDO_MAP || USE_NORMAL_MAP || USE_PBR_MAP || USE_EMISSIVE_MAP\n in vec2 a_texCoord;\n out vec2 v_uv;\n#endif\nvec4 vert () {\n vec4 pos = vec4(a_position, 1.0);\n vec4 normal = vec4(a_normal, 0.0);\n #if CC_USE_SKINNING\n skinVertex(pos, normal);\n #endif\n v_worldPos = (cc_matWorld * pos).xyz;\n v_worldNormal = (cc_matWorldIT * 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 return cc_matViewProj * cc_matWorld * pos;\n}\nvoid main() { gl_Position = vert(); }\n`, - "frag": `\nprecision mediump float;\nuniform CCGlobal {\n vec4 cc_time; \n vec4 cc_screenSize; \n vec4 cc_screenScale; \n vec4 cc_nativeSize; \n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos; \n vec4 cc_exposure; \n vec4 cc_mainLitDir; \n vec4 cc_mainLitColor; \n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\n#define MAX_LIGHTS 2\nuniform CCForwardLight {\n vec4 cc_sphereLitPos[2]; \n vec4 cc_sphereLitSizeRange[2]; \n vec4 cc_sphereLitColor[2]; \n vec4 cc_spotLitPos[2]; \n vec4 cc_spotLitSizeRangeAngle[2]; \n vec4 cc_spotLitDir[2]; \n vec4 cc_spotLitColor[2]; \n};\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define EPSILON 1e-6\n#define LOG2 1.442695\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#define FP_MAX = 65504.0;\n#define FP_SCALE (1.0/1024.0);\n#define FP_SCALE_INV 1024.0;\nvec3 SRGBToLinear(vec3 gamma)\n{\n return pow(gamma, vec3(2.2));\n \n}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\n \n}\nfloat SmoothDistAtt2(float distSqr, float invSqrAttRadius)\n{\n float factor = distSqr * invSqrAttRadius; \n float factor2 = factor * factor; \n float factor3 = factor2 * factor2; \n float smoothFactor = clamp(1.0 - factor3 * factor3, 0.0, 1.0);\n return smoothFactor * smoothFactor;\n}\nfloat SmoothDistAtt(float distSqr, float invSqrAttRadius)\n{\n float factor = distSqr * invSqrAttRadius;\n float smoothFactor = clamp(1.0 - factor * factor, 0.0, 1.0);\n return smoothFactor * smoothFactor;\n}\nfloat GetDistAtt(float distSqr, float invSqrAttRadius)\n{\n float attenuation = 1.0 / max(distSqr, 0.01*0.01);\n attenuation *= SmoothDistAtt(distSqr , invSqrAttRadius);\n return attenuation;\n}\nfloat GetAngleAtt(vec3 L, vec3 litDir, float litAngleScale, float litAngleOffset)\n{\n float cd = dot(litDir, L);\n float attenuation = clamp(cd * litAngleScale + litAngleOffset, 0.0, 1.0);\n return (attenuation * attenuation);\n}\nfloat GGXMobile(float roughness, float NoH, vec3 H, vec3 N)\n{\n vec3 NxH = cross(N, H);\n float OneMinusNoHSqr = dot(NxH, NxH);\n float a = roughness * roughness;\n float n = NoH * a;\n float p = a / (OneMinusNoHSqr + n * n);\n return p * p;\n}\nfloat CalcSpecular(float roughness, float NoH, vec3 H, vec3 N)\n{\n return (roughness*0.25 + 0.25) * GGXMobile(roughness, NoH, H, N);\n}\nvec3 BRDFApprox(vec3 specular, float roughness, float NoV)\n{\n const vec4 c0 = vec4(-1.0, -0.0275, -0.572, 0.022);\n const vec4 c1 = vec4(1.0, 0.0425, 1.04, -0.04);\n vec4 r = roughness * c0 + c1;\n float a004 = min( r.x * r.x, exp2( -9.28 * NoV ) ) * r.x + r.y;\n vec2 AB = vec2( -1.04, 1.04 ) * a004 + r.zw;\n AB.y *= clamp(50.0 * specular.g, 0.0, 1.0);\n return specular * AB.x + AB.y;\n}\nuniform Constants {\n vec4 tilingOffset;\n vec4 albedo;\n vec4 albedoScale; \n vec4 pbrParams; \n vec4 pbrScale; \n vec4 emissive;\n vec4 emissiveScale;\n};\nin vec3 v_worldPos;\nin vec3 v_worldNormal;\n#if USE_ALBEDO_MAP || USE_NORMAL_MAP || USE_PBR_MAP || USE_EMISSIVE_MAP\n in vec2 v_uv;\n#endif\n#if USE_ALBEDO_MAP\n uniform sampler2D albedoMap;\n#endif\n#if USE_NORMAL_MAP\n uniform sampler2D normalMap;\n#endif\n#if USE_PBR_MAP\n uniform sampler2D pbrMap;\n#endif\n#if USE_EMISSIVE_MAP\n uniform sampler2D emissiveMap;\n#endif\n#ifdef USE_IBL\n uniform samplerCube envMap;\n#endif\n#if USE_NORMAL_MAP\n vec3 getNormal(vec3 pos, vec3 normal) {\n vec3 q0 = vec3( dFdx( pos.x ), dFdx( pos.y ), dFdx( pos.z ) );\n vec3 q1 = vec3( dFdy( pos.x ), dFdy( pos.y ), dFdy( pos.z ) );\n vec2 st0 = dFdx( v_uv.st );\n vec2 st1 = dFdy( v_uv.st );\n vec3 S = normalize( q0 * st1.t - q1 * st0.t );\n vec3 T = normalize( -q0 * st1.s + q1 * st0.s );\n vec3 N = normal;\n vec3 mapN = texture(normalMap, v_uv).rgb * 2.0 - 1.0;\n mapN.xy = 1.0 * mapN.xy;\n mat3 tsn = mat3( S, T, N );\n return normalize( tsn * mapN );\n }\n#endif\nvec4 frag () {\n #if USE_ALBEDO_MAP\n vec4 baseColor = texture(albedoMap, v_uv);\n #else\n vec4 baseColor = albedo;\n #endif\n baseColor.rgb *= albedoScale.rgb;\n baseColor.rgb = SRGBToLinear(baseColor.rgb);\n #if USE_ALPHA_TEST\n if(baseColor.a < albedoScale.a)\n discard;\n #endif\n vec3 N = normalize(v_worldNormal);\n #if USE_NORMAL_MAP\n N = getNormal(v_worldPos, 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, 1.0);\n vec3 diffuse = baseColor.rgb * 0.96 * (1.0 - metallic);\n vec3 specular = mix(vec3(0.04), baseColor.rgb, metallic);\n vec3 V = normalize(cc_cameraPos.xyz - v_worldPos);\n vec3 L = normalize(-cc_mainLitDir.xyz);\n vec3 H = normalize(L+V);\n float NV = max(abs(dot(N, V)), 0.001);\n float NL = max(dot(N, L), 0.001);\n float NH = max(dot(N, H), 0.0);\n specular = BRDFApprox(specular, roughness, NV);\n vec3 specularContrib = specular * CalcSpecular(roughness, NH, H, N);\n vec3 diffuseContrib = diffuse / 3.14159265359;\n vec3 finalColor = NL * cc_mainLitColor.rgb * cc_mainLitColor.w * (diffuseContrib + specularContrib);\n for (int i = 0; i < 2; i++) {\n \n vec3 PLU = cc_sphereLitPos[i].xyz - v_worldPos;\n vec3 PL = normalize(PLU);\n vec3 PH = normalize(PL+V);\n float PNL = max(dot(N, PL), 0.001);\n float PNH = max(dot(N, PH), 0.0);\n float distSqr = dot(PLU, PLU);\n float litRadius = cc_sphereLitSizeRange[i].x;\n float litRadiusSqr = litRadius * litRadius;\n float illum = 3.14159265359 * (litRadiusSqr / max(litRadiusSqr , distSqr));\n float attRadiusSqrInv = 1.0 / max(cc_sphereLitSizeRange[i].y, 0.01);\n attRadiusSqrInv *= attRadiusSqrInv;\n float att = GetDistAtt(distSqr, attRadiusSqrInv);\n vec3 lspec = specular * CalcSpecular(roughness, PNH, PH, N);\n finalColor += PNL * cc_sphereLitColor[i].rgb * cc_sphereLitColor[i].w * illum * att * (diffuseContrib + lspec);\n }\n for (int i = 0; i < 2; i++) {\n \n vec3 SLU = cc_spotLitPos[i].xyz - v_worldPos;\n vec3 SL = normalize(SLU);\n vec3 SH = normalize(SL+V);\n float SNL = max(dot(N, SL), 0.001);\n float SNH = max(dot(N, SH), 0.0);\n float distSqr = dot(SLU, SLU);\n float litRadius = cc_spotLitSizeRangeAngle[i].x;\n float litRadiusSqr = litRadius * litRadius;\n float illum = 3.14159265359 * (litRadiusSqr / max(litRadiusSqr , distSqr));\n float attRadiusSqrInv = 1.0 / max(cc_spotLitSizeRangeAngle[i].y, 0.01);\n attRadiusSqrInv *= attRadiusSqrInv;\n float cosInner = max(dot(-cc_spotLitDir[i].xyz, SL), 0.01);\n float cosOuter = cc_spotLitSizeRangeAngle[i].z;\n float litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\n float litAngleOffset = -cosOuter * litAngleScale;\n float att = GetDistAtt(distSqr, attRadiusSqrInv);\n att *= GetAngleAtt(SL, -cc_spotLitDir[i].xyz, litAngleScale, litAngleOffset);\n vec3 lspec = specular * CalcSpecular(roughness, SNH, SH, N);\n finalColor += SNL * cc_spotLitColor[i].rgb * cc_spotLitColor[i].w * illum * att * (diffuseContrib + lspec);\n }\n float fAmb = dot(N, vec3(0.0, -1.0, 0.0)) * 0.5 + 0.5;\n vec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb) * cc_ambientSky.w;\n finalColor += (ambDiff.rgb * diffuse);\n#if USE_IBL\n vec3 R = normalize(reflect(-V, N));\n vec4 env = texture(envMap, R);\n env.rgb = SRGBToLinear(env.rgb) * cc_ambientSky.w;\n finalColor += (env.rgb * specular);\n#endif\n#if CC_USE_HDR\n finalColor *= (1.0/1024.0);;\n#else\n finalColor *= cc_exposure.x;\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 mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos; \n vec4 cc_exposure; \n vec4 cc_mainLitDir; \n vec4 cc_mainLitColor; \n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\nuniform CCLocal {\n mat4 cc_matWorld;\n mat4 cc_matWorldIT;\n};\nuniform Constants {\n vec4 tilingOffset;\n vec4 albedo;\n vec4 albedoScale; \n vec4 pbrParams; \n vec4 pbrScale; \n vec4 emissive;\n vec4 emissiveScale;\n};\n#if CC_USE_SKINNING\nin vec4 a_weights;\nin vec4 a_joints;\nuniform CCSkinning {\n mat4 cc_matJoint[128];\n vec4 cc_jointsTextureSize;\n};\n#if CC_USE_JOINTS_TEXTURE\nuniform sampler2D cc_jointsTexture;\nmat4 getBoneMatrix(const in float i) {\n float size = cc_jointsTextureSize.x;\n float j = i * 4.0;\n float x = mod(j, size);\n float y = floor(j / size);\n float dx = 1.0 / size;\n float dy = 1.0 / size;\n y = dy * (y + 0.5);\n vec4 v1 = texture(cc_jointsTexture, vec2(dx * (x + 0.5), y));\n vec4 v2 = texture(cc_jointsTexture, vec2(dx * (x + 1.5), y));\n vec4 v3 = texture(cc_jointsTexture, vec2(dx * (x + 2.5), y));\n vec4 v4 = texture(cc_jointsTexture, vec2(dx * (x + 3.5), y));\n return mat4(v1, v2, v3, v4);\n}\n#else\nmat4 getBoneMatrix(const in float i) {\n return cc_matJoint[int(i)];\n}\n#endif\nmat4 skinMatrix() {\n return\n getBoneMatrix(a_joints.x) * a_weights.x +\n getBoneMatrix(a_joints.y) * a_weights.y +\n getBoneMatrix(a_joints.z) * a_weights.z +\n getBoneMatrix(a_joints.w) * a_weights.w;\n}\nvoid skinVertex(inout vec4 a1) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n}\nvoid skinVertex(inout vec4 a1, inout vec4 a2) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n}\nvoid skinVertex(inout vec4 a1, inout vec4 a2, inout vec4 a3) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n a3 = m * a3;\n}\n#endif\nin vec3 a_position;\nin vec3 a_normal;\nout vec3 v_worldPos;\nout vec3 v_worldNormal;\n#if USE_ALBEDO_MAP || USE_NORMAL_MAP || USE_PBR_MAP || USE_EMISSIVE_MAP\n in vec2 a_texCoord;\n out vec2 v_uv;\n#endif\nvec4 vert () {\n vec4 pos = vec4(a_position, 1.0);\n vec4 normal = vec4(a_normal, 0.0);\n #if CC_USE_SKINNING\n skinVertex(pos, normal);\n #endif\n v_worldPos = (cc_matWorld * pos).xyz;\n v_worldNormal = (cc_matWorldIT * 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 return cc_matViewProj * cc_matWorld * 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 mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos; \n vec4 cc_exposure; \n vec4 cc_mainLitDir; \n vec4 cc_mainLitColor; \n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\n#define MAX_LIGHTS 2\nuniform CCForwardLight {\n vec4 cc_sphereLitPos[2]; \n vec4 cc_sphereLitSizeRange[2]; \n vec4 cc_sphereLitColor[2]; \n vec4 cc_spotLitPos[2]; \n vec4 cc_spotLitSizeRangeAngle[2]; \n vec4 cc_spotLitDir[2]; \n vec4 cc_spotLitColor[2]; \n};\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define EPSILON 1e-6\n#define LOG2 1.442695\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#define FP_MAX = 65504.0;\n#define FP_SCALE (1.0/1024.0);\n#define FP_SCALE_INV 1024.0;\nvec3 SRGBToLinear(vec3 gamma)\n{\n return pow(gamma, vec3(2.2));\n \n}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\n \n}\nfloat SmoothDistAtt2(float distSqr, float invSqrAttRadius)\n{\n float factor = distSqr * invSqrAttRadius; \n float factor2 = factor * factor; \n float factor3 = factor2 * factor2; \n float smoothFactor = clamp(1.0 - factor3 * factor3, 0.0, 1.0);\n return smoothFactor * smoothFactor;\n}\nfloat SmoothDistAtt(float distSqr, float invSqrAttRadius)\n{\n float factor = distSqr * invSqrAttRadius;\n float smoothFactor = clamp(1.0 - factor * factor, 0.0, 1.0);\n return smoothFactor * smoothFactor;\n}\nfloat GetDistAtt(float distSqr, float invSqrAttRadius)\n{\n float attenuation = 1.0 / max(distSqr, 0.01*0.01);\n attenuation *= SmoothDistAtt(distSqr , invSqrAttRadius);\n return attenuation;\n}\nfloat GetAngleAtt(vec3 L, vec3 litDir, float litAngleScale, float litAngleOffset)\n{\n float cd = dot(litDir, L);\n float attenuation = clamp(cd * litAngleScale + litAngleOffset, 0.0, 1.0);\n return (attenuation * attenuation);\n}\nfloat GGXMobile(float roughness, float NoH, vec3 H, vec3 N)\n{\n vec3 NxH = cross(N, H);\n float OneMinusNoHSqr = dot(NxH, NxH);\n float a = roughness * roughness;\n float n = NoH * a;\n float p = a / (OneMinusNoHSqr + n * n);\n return p * p;\n}\nfloat CalcSpecular(float roughness, float NoH, vec3 H, vec3 N)\n{\n return (roughness*0.25 + 0.25) * GGXMobile(roughness, NoH, H, N);\n}\nvec3 BRDFApprox(vec3 specular, float roughness, float NoV)\n{\n const vec4 c0 = vec4(-1.0, -0.0275, -0.572, 0.022);\n const vec4 c1 = vec4(1.0, 0.0425, 1.04, -0.04);\n vec4 r = roughness * c0 + c1;\n float a004 = min( r.x * r.x, exp2( -9.28 * NoV ) ) * r.x + r.y;\n vec2 AB = vec2( -1.04, 1.04 ) * a004 + r.zw;\n AB.y *= clamp(50.0 * specular.g, 0.0, 1.0);\n return specular * AB.x + AB.y;\n}\nuniform Constants {\n vec4 tilingOffset;\n vec4 albedo;\n vec4 albedoScale; \n vec4 pbrParams; \n vec4 pbrScale; \n vec4 emissive;\n vec4 emissiveScale;\n};\nin vec3 v_worldPos;\nin vec3 v_worldNormal;\n#if USE_ALBEDO_MAP || USE_NORMAL_MAP || USE_PBR_MAP || USE_EMISSIVE_MAP\n in vec2 v_uv;\n#endif\n#if USE_ALBEDO_MAP\n uniform sampler2D albedoMap;\n#endif\n#if USE_NORMAL_MAP\n uniform sampler2D normalMap;\n#endif\n#if USE_PBR_MAP\n uniform sampler2D pbrMap;\n#endif\n#if USE_EMISSIVE_MAP\n uniform sampler2D emissiveMap;\n#endif\n#ifdef USE_IBL\n uniform samplerCube envMap;\n#endif\n#if USE_NORMAL_MAP\n vec3 getNormal(vec3 pos, vec3 normal) {\n vec3 q0 = vec3( dFdx( pos.x ), dFdx( pos.y ), dFdx( pos.z ) );\n vec3 q1 = vec3( dFdy( pos.x ), dFdy( pos.y ), dFdy( pos.z ) );\n vec2 st0 = dFdx( v_uv.st );\n vec2 st1 = dFdy( v_uv.st );\n vec3 S = normalize( q0 * st1.t - q1 * st0.t );\n vec3 T = normalize( -q0 * st1.s + q1 * st0.s );\n vec3 N = normal;\n vec3 mapN = texture(normalMap, v_uv).rgb * 2.0 - 1.0;\n mapN.xy = 1.0 * mapN.xy;\n mat3 tsn = mat3( S, T, N );\n return normalize( tsn * mapN );\n }\n#endif\nvec4 frag () {\n #if USE_ALBEDO_MAP\n vec4 baseColor = texture(albedoMap, v_uv);\n #else\n vec4 baseColor = albedo;\n #endif\n baseColor.rgb *= albedoScale.rgb;\n baseColor.rgb = SRGBToLinear(baseColor.rgb);\n #if USE_ALPHA_TEST\n if(baseColor.a < albedoScale.a)\n discard;\n #endif\n vec3 N = normalize(v_worldNormal);\n #if USE_NORMAL_MAP\n N = getNormal(v_worldPos, 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, 1.0);\n vec3 diffuse = baseColor.rgb * 0.96 * (1.0 - metallic);\n vec3 specular = mix(vec3(0.04), baseColor.rgb, metallic);\n vec3 V = normalize(cc_cameraPos.xyz - v_worldPos);\n vec3 L = normalize(-cc_mainLitDir.xyz);\n vec3 H = normalize(L+V);\n float NV = max(abs(dot(N, V)), 0.001);\n float NL = max(dot(N, L), 0.001);\n float NH = max(dot(N, H), 0.0);\n specular = BRDFApprox(specular, roughness, NV);\n vec3 specularContrib = specular * CalcSpecular(roughness, NH, H, N);\n vec3 diffuseContrib = diffuse / 3.14159265359;\n vec3 finalColor = NL * cc_mainLitColor.rgb * cc_mainLitColor.w * (diffuseContrib + specularContrib);\n for (int i = 0; i < 2; i++) {\n \n vec3 PLU = cc_sphereLitPos[i].xyz - v_worldPos;\n vec3 PL = normalize(PLU);\n vec3 PH = normalize(PL+V);\n float PNL = max(dot(N, PL), 0.001);\n float PNH = max(dot(N, PH), 0.0);\n float distSqr = dot(PLU, PLU);\n float litRadius = cc_sphereLitSizeRange[i].x;\n float litRadiusSqr = litRadius * litRadius;\n float illum = 3.14159265359 * (litRadiusSqr / max(litRadiusSqr , distSqr));\n float attRadiusSqrInv = 1.0 / max(cc_sphereLitSizeRange[i].y, 0.01);\n attRadiusSqrInv *= attRadiusSqrInv;\n float att = GetDistAtt(distSqr, attRadiusSqrInv);\n vec3 lspec = specular * CalcSpecular(roughness, PNH, PH, N);\n finalColor += PNL * cc_sphereLitColor[i].rgb * cc_sphereLitColor[i].w * illum * att * (diffuseContrib + lspec);\n }\n for (int i = 0; i < 2; i++) {\n \n vec3 SLU = cc_spotLitPos[i].xyz - v_worldPos;\n vec3 SL = normalize(SLU);\n vec3 SH = normalize(SL+V);\n float SNL = max(dot(N, SL), 0.001);\n float SNH = max(dot(N, SH), 0.0);\n float distSqr = dot(SLU, SLU);\n float litRadius = cc_spotLitSizeRangeAngle[i].x;\n float litRadiusSqr = litRadius * litRadius;\n float illum = 3.14159265359 * (litRadiusSqr / max(litRadiusSqr , distSqr));\n float attRadiusSqrInv = 1.0 / max(cc_spotLitSizeRangeAngle[i].y, 0.01);\n attRadiusSqrInv *= attRadiusSqrInv;\n float cosInner = max(dot(-cc_spotLitDir[i].xyz, SL), 0.01);\n float cosOuter = cc_spotLitSizeRangeAngle[i].z;\n float litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\n float litAngleOffset = -cosOuter * litAngleScale;\n float att = GetDistAtt(distSqr, attRadiusSqrInv);\n att *= GetAngleAtt(SL, -cc_spotLitDir[i].xyz, litAngleScale, litAngleOffset);\n vec3 lspec = specular * CalcSpecular(roughness, SNH, SH, N);\n finalColor += SNL * cc_spotLitColor[i].rgb * cc_spotLitColor[i].w * illum * att * (diffuseContrib + lspec);\n }\n float fAmb = dot(N, vec3(0.0, -1.0, 0.0)) * 0.5 + 0.5;\n vec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb) * cc_ambientSky.w;\n finalColor += (ambDiff.rgb * diffuse);\n#if USE_IBL\n vec3 R = normalize(reflect(-V, N));\n vec4 env = texture(envMap, R);\n env.rgb = SRGBToLinear(env.rgb) * cc_ambientSky.w;\n finalColor += (env.rgb * specular);\n#endif\n#if CC_USE_HDR\n finalColor *= (1.0/1024.0);;\n#else\n finalColor *= cc_exposure.x;\n finalColor = LinearToSRGB(finalColor);\n#endif\n return vec4(finalColor, baseColor.a);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }\n` }, "glsl1": { - "vert": `\nprecision mediump float;\nuniform vec4 cc_time;\nuniform vec4 cc_screenSize;\nuniform vec4 cc_screenScale;\nuniform vec4 cc_nativeSize;\nuniform mat4 cc_matView;\nuniform mat4 cc_matViewInv;\nuniform mat4 cc_matProj;\nuniform mat4 cc_matProjInv;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matViewProjInv;\nuniform vec4 cc_cameraPos;\nuniform vec4 cc_exposure;\nuniform vec4 cc_mainLitDir;\nuniform vec4 cc_mainLitColor;\nuniform vec4 cc_ambientSky;\nuniform vec4 cc_ambientGround;\nuniform mat4 cc_matWorld;\nuniform mat4 cc_matWorldIT;\nuniform vec4 tilingOffset;\nuniform vec4 albedo;\nuniform vec4 albedoScale;\nuniform vec4 pbrParams;\nuniform vec4 pbrScale;\nuniform vec4 emissive;\nuniform vec4 emissiveScale;\n#if CC_USE_SKINNING\nattribute vec4 a_weights;\nattribute vec4 a_joints;\nuniform mat4 cc_matJoint[128];\nuniform vec4 cc_jointsTextureSize;\n#if CC_USE_JOINTS_TEXTURE\nuniform sampler2D cc_jointsTexture;\nmat4 getBoneMatrix(const in float i) {\n float size = cc_jointsTextureSize.x;\n float j = i * 4.0;\n float x = mod(j, size);\n float y = floor(j / size);\n float dx = 1.0 / size;\n float dy = 1.0 / size;\n y = dy * (y + 0.5);\n vec4 v1 = texture2D(cc_jointsTexture, vec2(dx * (x + 0.5), y));\n vec4 v2 = texture2D(cc_jointsTexture, vec2(dx * (x + 1.5), y));\n vec4 v3 = texture2D(cc_jointsTexture, vec2(dx * (x + 2.5), y));\n vec4 v4 = texture2D(cc_jointsTexture, vec2(dx * (x + 3.5), y));\n return mat4(v1, v2, v3, v4);\n}\n#else\nmat4 getBoneMatrix(const in float i) {\n return cc_matJoint[int(i)];\n}\n#endif\nmat4 skinMatrix() {\n return\n getBoneMatrix(a_joints.x) * a_weights.x +\n getBoneMatrix(a_joints.y) * a_weights.y +\n getBoneMatrix(a_joints.z) * a_weights.z +\n getBoneMatrix(a_joints.w) * a_weights.w;\n}\nvoid skinVertex(inout vec4 a1) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n}\nvoid skinVertex(inout vec4 a1, inout vec4 a2) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n}\nvoid skinVertex(inout vec4 a1, inout vec4 a2, inout vec4 a3) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n a3 = m * a3;\n}\n#endif\nattribute vec3 a_position;\nattribute vec3 a_normal;\nvarying vec3 v_worldPos;\nvarying vec3 v_worldNormal;\n#if USE_ALBEDO_MAP || USE_NORMAL_MAP || USE_PBR_MAP || USE_EMISSIVE_MAP\n attribute vec2 a_texCoord;\n varying vec2 v_uv;\n#endif\nvec4 vert () {\n vec4 pos = vec4(a_position, 1.0);\n vec4 normal = vec4(a_normal, 0.0);\n #if CC_USE_SKINNING\n skinVertex(pos, normal);\n #endif\n v_worldPos = (cc_matWorld * pos).xyz;\n v_worldNormal = (cc_matWorldIT * 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 return cc_matViewProj * cc_matWorld * pos;\n}\nvoid main() { gl_Position = vert(); }\n`, - "frag": `\nprecision mediump float;\nuniform vec4 cc_time;\nuniform vec4 cc_screenSize;\nuniform vec4 cc_screenScale;\nuniform vec4 cc_nativeSize;\nuniform mat4 cc_matView;\nuniform mat4 cc_matViewInv;\nuniform mat4 cc_matProj;\nuniform mat4 cc_matProjInv;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matViewProjInv;\nuniform vec4 cc_cameraPos;\nuniform vec4 cc_exposure;\nuniform vec4 cc_mainLitDir;\nuniform vec4 cc_mainLitColor;\nuniform vec4 cc_ambientSky;\nuniform vec4 cc_ambientGround;\n#define MAX_LIGHTS 2\nuniform vec4 cc_sphereLitPos[2];\nuniform vec4 cc_sphereLitSizeRange[2];\nuniform vec4 cc_sphereLitColor[2];\nuniform vec4 cc_spotLitPos[2];\nuniform vec4 cc_spotLitSizeRangeAngle[2];\nuniform vec4 cc_spotLitDir[2];\nuniform vec4 cc_spotLitColor[2];\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define EPSILON 1e-6\n#define LOG2 1.442695\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#define FP_MAX = 65504.0;\n#define FP_SCALE (1.0/1024.0);\n#define FP_SCALE_INV 1024.0;\nvec3 SRGBToLinear(vec3 gamma)\n{\n return pow(gamma, vec3(2.2));\n \n}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\n \n}\nfloat SmoothDistAtt2(float distSqr, float invSqrAttRadius)\n{\n float factor = distSqr * invSqrAttRadius; \n float factor2 = factor * factor; \n float factor3 = factor2 * factor2; \n float smoothFactor = clamp(1.0 - factor3 * factor3, 0.0, 1.0);\n return smoothFactor * smoothFactor;\n}\nfloat SmoothDistAtt(float distSqr, float invSqrAttRadius)\n{\n float factor = distSqr * invSqrAttRadius;\n float smoothFactor = clamp(1.0 - factor * factor, 0.0, 1.0);\n return smoothFactor * smoothFactor;\n}\nfloat GetDistAtt(float distSqr, float invSqrAttRadius)\n{\n float attenuation = 1.0 / max(distSqr, 0.01*0.01);\n attenuation *= SmoothDistAtt(distSqr , invSqrAttRadius);\n return attenuation;\n}\nfloat GetAngleAtt(vec3 L, vec3 litDir, float litAngleScale, float litAngleOffset)\n{\n float cd = dot(litDir, L);\n float attenuation = clamp(cd * litAngleScale + litAngleOffset, 0.0, 1.0);\n return (attenuation * attenuation);\n}\nfloat GGXMobile(float roughness, float NoH, vec3 H, vec3 N)\n{\n vec3 NxH = cross(N, H);\n float OneMinusNoHSqr = dot(NxH, NxH);\n float a = roughness * roughness;\n float n = NoH * a;\n float p = a / (OneMinusNoHSqr + n * n);\n return p * p;\n}\nfloat CalcSpecular(float roughness, float NoH, vec3 H, vec3 N)\n{\n return (roughness*0.25 + 0.25) * GGXMobile(roughness, NoH, H, N);\n}\nvec3 BRDFApprox(vec3 specular, float roughness, float NoV)\n{\n const vec4 c0 = vec4(-1.0, -0.0275, -0.572, 0.022);\n const vec4 c1 = vec4(1.0, 0.0425, 1.04, -0.04);\n vec4 r = roughness * c0 + c1;\n float a004 = min( r.x * r.x, exp2( -9.28 * NoV ) ) * r.x + r.y;\n vec2 AB = vec2( -1.04, 1.04 ) * a004 + r.zw;\n AB.y *= clamp(50.0 * specular.g, 0.0, 1.0);\n return specular * AB.x + AB.y;\n}\nuniform vec4 tilingOffset;\nuniform vec4 albedo;\nuniform vec4 albedoScale;\nuniform vec4 pbrParams;\nuniform vec4 pbrScale;\nuniform vec4 emissive;\nuniform vec4 emissiveScale;\nvarying vec3 v_worldPos;\nvarying vec3 v_worldNormal;\n#if USE_ALBEDO_MAP || USE_NORMAL_MAP || USE_PBR_MAP || USE_EMISSIVE_MAP\n varying vec2 v_uv;\n#endif\n#if USE_ALBEDO_MAP\n uniform sampler2D albedoMap;\n#endif\n#if USE_NORMAL_MAP\n uniform sampler2D normalMap;\n#endif\n#if USE_PBR_MAP\n uniform sampler2D pbrMap;\n#endif\n#if USE_EMISSIVE_MAP\n uniform sampler2D emissiveMap;\n#endif\n#ifdef USE_IBL\n uniform samplerCube envMap;\n#endif\n#if USE_NORMAL_MAP\n vec3 getNormal(vec3 pos, vec3 normal) {\n vec3 q0 = vec3( dFdx( pos.x ), dFdx( pos.y ), dFdx( pos.z ) );\n vec3 q1 = vec3( dFdy( pos.x ), dFdy( pos.y ), dFdy( pos.z ) );\n vec2 st0 = dFdx( v_uv.st );\n vec2 st1 = dFdy( v_uv.st );\n vec3 S = normalize( q0 * st1.t - q1 * st0.t );\n vec3 T = normalize( -q0 * st1.s + q1 * st0.s );\n vec3 N = normal;\n vec3 mapN = texture2D(normalMap, v_uv).rgb * 2.0 - 1.0;\n mapN.xy = 1.0 * mapN.xy;\n mat3 tsn = mat3( S, T, N );\n return normalize( tsn * mapN );\n }\n#endif\nvec4 frag () {\n #if USE_ALBEDO_MAP\n vec4 baseColor = texture2D(albedoMap, v_uv);\n #else\n vec4 baseColor = albedo;\n #endif\n baseColor.rgb *= albedoScale.rgb;\n baseColor.rgb = SRGBToLinear(baseColor.rgb);\n #if USE_ALPHA_TEST\n if(baseColor.a < albedoScale.a)\n discard;\n #endif\n vec3 N = normalize(v_worldNormal);\n #if USE_NORMAL_MAP\n N = getNormal(v_worldPos, 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, 1.0);\n vec3 diffuse = baseColor.rgb * 0.96 * (1.0 - metallic);\n vec3 specular = mix(vec3(0.04), baseColor.rgb, metallic);\n vec3 V = normalize(cc_cameraPos.xyz - v_worldPos);\n vec3 L = normalize(-cc_mainLitDir.xyz);\n vec3 H = normalize(L+V);\n float NV = max(abs(dot(N, V)), 0.001);\n float NL = max(dot(N, L), 0.001);\n float NH = max(dot(N, H), 0.0);\n specular = BRDFApprox(specular, roughness, NV);\n vec3 specularContrib = specular * CalcSpecular(roughness, NH, H, N);\n vec3 diffuseContrib = diffuse / 3.14159265359;\n vec3 finalColor = NL * cc_mainLitColor.rgb * cc_mainLitColor.w * (diffuseContrib + specularContrib);\n for (int i = 0; i < 2; i++) {\n \n vec3 PLU = cc_sphereLitPos[i].xyz - v_worldPos;\n vec3 PL = normalize(PLU);\n vec3 PH = normalize(PL+V);\n float PNL = max(dot(N, PL), 0.001);\n float PNH = max(dot(N, PH), 0.0);\n float distSqr = dot(PLU, PLU);\n float litRadius = cc_sphereLitSizeRange[i].x;\n float litRadiusSqr = litRadius * litRadius;\n float illum = 3.14159265359 * (litRadiusSqr / max(litRadiusSqr , distSqr));\n float attRadiusSqrInv = 1.0 / max(cc_sphereLitSizeRange[i].y, 0.01);\n attRadiusSqrInv *= attRadiusSqrInv;\n float att = GetDistAtt(distSqr, attRadiusSqrInv);\n vec3 lspec = specular * CalcSpecular(roughness, PNH, PH, N);\n finalColor += PNL * cc_sphereLitColor[i].rgb * cc_sphereLitColor[i].w * illum * att * (diffuseContrib + lspec);\n }\n for (int i = 0; i < 2; i++) {\n \n vec3 SLU = cc_spotLitPos[i].xyz - v_worldPos;\n vec3 SL = normalize(SLU);\n vec3 SH = normalize(SL+V);\n float SNL = max(dot(N, SL), 0.001);\n float SNH = max(dot(N, SH), 0.0);\n float distSqr = dot(SLU, SLU);\n float litRadius = cc_spotLitSizeRangeAngle[i].x;\n float litRadiusSqr = litRadius * litRadius;\n float illum = 3.14159265359 * (litRadiusSqr / max(litRadiusSqr , distSqr));\n float attRadiusSqrInv = 1.0 / max(cc_spotLitSizeRangeAngle[i].y, 0.01);\n attRadiusSqrInv *= attRadiusSqrInv;\n float cosInner = max(dot(-cc_spotLitDir[i].xyz, SL), 0.01);\n float cosOuter = cc_spotLitSizeRangeAngle[i].z;\n float litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\n float litAngleOffset = -cosOuter * litAngleScale;\n float att = GetDistAtt(distSqr, attRadiusSqrInv);\n att *= GetAngleAtt(SL, -cc_spotLitDir[i].xyz, litAngleScale, litAngleOffset);\n vec3 lspec = specular * CalcSpecular(roughness, SNH, SH, N);\n finalColor += SNL * cc_spotLitColor[i].rgb * cc_spotLitColor[i].w * illum * att * (diffuseContrib + lspec);\n }\n float fAmb = dot(N, vec3(0.0, -1.0, 0.0)) * 0.5 + 0.5;\n vec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb) * cc_ambientSky.w;\n finalColor += (ambDiff.rgb * diffuse);\n#if USE_IBL\n vec3 R = normalize(reflect(-V, N));\n vec4 env = textureCube(envMap, R);\n env.rgb = SRGBToLinear(env.rgb) * cc_ambientSky.w;\n finalColor += (env.rgb * specular);\n#endif\n#if CC_USE_HDR\n finalColor *= (1.0/1024.0);;\n#else\n finalColor *= cc_exposure.x;\n finalColor = LinearToSRGB(finalColor);\n#endif\n return vec4(finalColor, baseColor.a);\n}\nvoid main() { gl_FragColor = frag(); }\n` + "vert": `\nprecision mediump float;\nuniform vec4 cc_time;\nuniform vec4 cc_screenSize;\nuniform vec4 cc_screenScale;\nuniform mat4 cc_matView;\nuniform mat4 cc_matViewInv;\nuniform mat4 cc_matProj;\nuniform mat4 cc_matProjInv;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matViewProjInv;\nuniform vec4 cc_cameraPos;\nuniform vec4 cc_exposure;\nuniform vec4 cc_mainLitDir;\nuniform vec4 cc_mainLitColor;\nuniform vec4 cc_ambientSky;\nuniform vec4 cc_ambientGround;\nuniform mat4 cc_matWorld;\nuniform mat4 cc_matWorldIT;\nuniform vec4 tilingOffset;\nuniform vec4 albedo;\nuniform vec4 albedoScale;\nuniform vec4 pbrParams;\nuniform vec4 pbrScale;\nuniform vec4 emissive;\nuniform vec4 emissiveScale;\n#if CC_USE_SKINNING\nattribute vec4 a_weights;\nattribute vec4 a_joints;\nuniform mat4 cc_matJoint[128];\nuniform vec4 cc_jointsTextureSize;\n#if CC_USE_JOINTS_TEXTURE\nuniform sampler2D cc_jointsTexture;\nmat4 getBoneMatrix(const in float i) {\n float size = cc_jointsTextureSize.x;\n float j = i * 4.0;\n float x = mod(j, size);\n float y = floor(j / size);\n float dx = 1.0 / size;\n float dy = 1.0 / size;\n y = dy * (y + 0.5);\n vec4 v1 = texture2D(cc_jointsTexture, vec2(dx * (x + 0.5), y));\n vec4 v2 = texture2D(cc_jointsTexture, vec2(dx * (x + 1.5), y));\n vec4 v3 = texture2D(cc_jointsTexture, vec2(dx * (x + 2.5), y));\n vec4 v4 = texture2D(cc_jointsTexture, vec2(dx * (x + 3.5), y));\n return mat4(v1, v2, v3, v4);\n}\n#else\nmat4 getBoneMatrix(const in float i) {\n return cc_matJoint[int(i)];\n}\n#endif\nmat4 skinMatrix() {\n return\n getBoneMatrix(a_joints.x) * a_weights.x +\n getBoneMatrix(a_joints.y) * a_weights.y +\n getBoneMatrix(a_joints.z) * a_weights.z +\n getBoneMatrix(a_joints.w) * a_weights.w;\n}\nvoid skinVertex(inout vec4 a1) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n}\nvoid skinVertex(inout vec4 a1, inout vec4 a2) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n}\nvoid skinVertex(inout vec4 a1, inout vec4 a2, inout vec4 a3) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n a3 = m * a3;\n}\n#endif\nattribute vec3 a_position;\nattribute vec3 a_normal;\nvarying vec3 v_worldPos;\nvarying vec3 v_worldNormal;\n#if USE_ALBEDO_MAP || USE_NORMAL_MAP || USE_PBR_MAP || USE_EMISSIVE_MAP\n attribute vec2 a_texCoord;\n varying vec2 v_uv;\n#endif\nvec4 vert () {\n vec4 pos = vec4(a_position, 1.0);\n vec4 normal = vec4(a_normal, 0.0);\n #if CC_USE_SKINNING\n skinVertex(pos, normal);\n #endif\n v_worldPos = (cc_matWorld * pos).xyz;\n v_worldNormal = (cc_matWorldIT * 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 return cc_matViewProj * cc_matWorld * pos;\n}\nvoid main() { gl_Position = vert(); }\n`, + "frag": `\nprecision mediump float;\nuniform vec4 cc_time;\nuniform vec4 cc_screenSize;\nuniform vec4 cc_screenScale;\nuniform mat4 cc_matView;\nuniform mat4 cc_matViewInv;\nuniform mat4 cc_matProj;\nuniform mat4 cc_matProjInv;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matViewProjInv;\nuniform vec4 cc_cameraPos;\nuniform vec4 cc_exposure;\nuniform vec4 cc_mainLitDir;\nuniform vec4 cc_mainLitColor;\nuniform vec4 cc_ambientSky;\nuniform vec4 cc_ambientGround;\n#define MAX_LIGHTS 2\nuniform vec4 cc_sphereLitPos[2];\nuniform vec4 cc_sphereLitSizeRange[2];\nuniform vec4 cc_sphereLitColor[2];\nuniform vec4 cc_spotLitPos[2];\nuniform vec4 cc_spotLitSizeRangeAngle[2];\nuniform vec4 cc_spotLitDir[2];\nuniform vec4 cc_spotLitColor[2];\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define EPSILON 1e-6\n#define LOG2 1.442695\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#define FP_MAX = 65504.0;\n#define FP_SCALE (1.0/1024.0);\n#define FP_SCALE_INV 1024.0;\nvec3 SRGBToLinear(vec3 gamma)\n{\n return pow(gamma, vec3(2.2));\n \n}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\n \n}\nfloat SmoothDistAtt2(float distSqr, float invSqrAttRadius)\n{\n float factor = distSqr * invSqrAttRadius; \n float factor2 = factor * factor; \n float factor3 = factor2 * factor2; \n float smoothFactor = clamp(1.0 - factor3 * factor3, 0.0, 1.0);\n return smoothFactor * smoothFactor;\n}\nfloat SmoothDistAtt(float distSqr, float invSqrAttRadius)\n{\n float factor = distSqr * invSqrAttRadius;\n float smoothFactor = clamp(1.0 - factor * factor, 0.0, 1.0);\n return smoothFactor * smoothFactor;\n}\nfloat GetDistAtt(float distSqr, float invSqrAttRadius)\n{\n float attenuation = 1.0 / max(distSqr, 0.01*0.01);\n attenuation *= SmoothDistAtt(distSqr , invSqrAttRadius);\n return attenuation;\n}\nfloat GetAngleAtt(vec3 L, vec3 litDir, float litAngleScale, float litAngleOffset)\n{\n float cd = dot(litDir, L);\n float attenuation = clamp(cd * litAngleScale + litAngleOffset, 0.0, 1.0);\n return (attenuation * attenuation);\n}\nfloat GGXMobile(float roughness, float NoH, vec3 H, vec3 N)\n{\n vec3 NxH = cross(N, H);\n float OneMinusNoHSqr = dot(NxH, NxH);\n float a = roughness * roughness;\n float n = NoH * a;\n float p = a / (OneMinusNoHSqr + n * n);\n return p * p;\n}\nfloat CalcSpecular(float roughness, float NoH, vec3 H, vec3 N)\n{\n return (roughness*0.25 + 0.25) * GGXMobile(roughness, NoH, H, N);\n}\nvec3 BRDFApprox(vec3 specular, float roughness, float NoV)\n{\n const vec4 c0 = vec4(-1.0, -0.0275, -0.572, 0.022);\n const vec4 c1 = vec4(1.0, 0.0425, 1.04, -0.04);\n vec4 r = roughness * c0 + c1;\n float a004 = min( r.x * r.x, exp2( -9.28 * NoV ) ) * r.x + r.y;\n vec2 AB = vec2( -1.04, 1.04 ) * a004 + r.zw;\n AB.y *= clamp(50.0 * specular.g, 0.0, 1.0);\n return specular * AB.x + AB.y;\n}\nuniform vec4 tilingOffset;\nuniform vec4 albedo;\nuniform vec4 albedoScale;\nuniform vec4 pbrParams;\nuniform vec4 pbrScale;\nuniform vec4 emissive;\nuniform vec4 emissiveScale;\nvarying vec3 v_worldPos;\nvarying vec3 v_worldNormal;\n#if USE_ALBEDO_MAP || USE_NORMAL_MAP || USE_PBR_MAP || USE_EMISSIVE_MAP\n varying vec2 v_uv;\n#endif\n#if USE_ALBEDO_MAP\n uniform sampler2D albedoMap;\n#endif\n#if USE_NORMAL_MAP\n uniform sampler2D normalMap;\n#endif\n#if USE_PBR_MAP\n uniform sampler2D pbrMap;\n#endif\n#if USE_EMISSIVE_MAP\n uniform sampler2D emissiveMap;\n#endif\n#ifdef USE_IBL\n uniform samplerCube envMap;\n#endif\n#if USE_NORMAL_MAP\n vec3 getNormal(vec3 pos, vec3 normal) {\n vec3 q0 = vec3( dFdx( pos.x ), dFdx( pos.y ), dFdx( pos.z ) );\n vec3 q1 = vec3( dFdy( pos.x ), dFdy( pos.y ), dFdy( pos.z ) );\n vec2 st0 = dFdx( v_uv.st );\n vec2 st1 = dFdy( v_uv.st );\n vec3 S = normalize( q0 * st1.t - q1 * st0.t );\n vec3 T = normalize( -q0 * st1.s + q1 * st0.s );\n vec3 N = normal;\n vec3 mapN = texture2D(normalMap, v_uv).rgb * 2.0 - 1.0;\n mapN.xy = 1.0 * mapN.xy;\n mat3 tsn = mat3( S, T, N );\n return normalize( tsn * mapN );\n }\n#endif\nvec4 frag () {\n #if USE_ALBEDO_MAP\n vec4 baseColor = texture2D(albedoMap, v_uv);\n #else\n vec4 baseColor = albedo;\n #endif\n baseColor.rgb *= albedoScale.rgb;\n baseColor.rgb = SRGBToLinear(baseColor.rgb);\n #if USE_ALPHA_TEST\n if(baseColor.a < albedoScale.a)\n discard;\n #endif\n vec3 N = normalize(v_worldNormal);\n #if USE_NORMAL_MAP\n N = getNormal(v_worldPos, 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, 1.0);\n vec3 diffuse = baseColor.rgb * 0.96 * (1.0 - metallic);\n vec3 specular = mix(vec3(0.04), baseColor.rgb, metallic);\n vec3 V = normalize(cc_cameraPos.xyz - v_worldPos);\n vec3 L = normalize(-cc_mainLitDir.xyz);\n vec3 H = normalize(L+V);\n float NV = max(abs(dot(N, V)), 0.001);\n float NL = max(dot(N, L), 0.001);\n float NH = max(dot(N, H), 0.0);\n specular = BRDFApprox(specular, roughness, NV);\n vec3 specularContrib = specular * CalcSpecular(roughness, NH, H, N);\n vec3 diffuseContrib = diffuse / 3.14159265359;\n vec3 finalColor = NL * cc_mainLitColor.rgb * cc_mainLitColor.w * (diffuseContrib + specularContrib);\n for (int i = 0; i < 2; i++) {\n \n vec3 PLU = cc_sphereLitPos[i].xyz - v_worldPos;\n vec3 PL = normalize(PLU);\n vec3 PH = normalize(PL+V);\n float PNL = max(dot(N, PL), 0.001);\n float PNH = max(dot(N, PH), 0.0);\n float distSqr = dot(PLU, PLU);\n float litRadius = cc_sphereLitSizeRange[i].x;\n float litRadiusSqr = litRadius * litRadius;\n float illum = 3.14159265359 * (litRadiusSqr / max(litRadiusSqr , distSqr));\n float attRadiusSqrInv = 1.0 / max(cc_sphereLitSizeRange[i].y, 0.01);\n attRadiusSqrInv *= attRadiusSqrInv;\n float att = GetDistAtt(distSqr, attRadiusSqrInv);\n vec3 lspec = specular * CalcSpecular(roughness, PNH, PH, N);\n finalColor += PNL * cc_sphereLitColor[i].rgb * cc_sphereLitColor[i].w * illum * att * (diffuseContrib + lspec);\n }\n for (int i = 0; i < 2; i++) {\n \n vec3 SLU = cc_spotLitPos[i].xyz - v_worldPos;\n vec3 SL = normalize(SLU);\n vec3 SH = normalize(SL+V);\n float SNL = max(dot(N, SL), 0.001);\n float SNH = max(dot(N, SH), 0.0);\n float distSqr = dot(SLU, SLU);\n float litRadius = cc_spotLitSizeRangeAngle[i].x;\n float litRadiusSqr = litRadius * litRadius;\n float illum = 3.14159265359 * (litRadiusSqr / max(litRadiusSqr , distSqr));\n float attRadiusSqrInv = 1.0 / max(cc_spotLitSizeRangeAngle[i].y, 0.01);\n attRadiusSqrInv *= attRadiusSqrInv;\n float cosInner = max(dot(-cc_spotLitDir[i].xyz, SL), 0.01);\n float cosOuter = cc_spotLitSizeRangeAngle[i].z;\n float litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\n float litAngleOffset = -cosOuter * litAngleScale;\n float att = GetDistAtt(distSqr, attRadiusSqrInv);\n att *= GetAngleAtt(SL, -cc_spotLitDir[i].xyz, litAngleScale, litAngleOffset);\n vec3 lspec = specular * CalcSpecular(roughness, SNH, SH, N);\n finalColor += SNL * cc_spotLitColor[i].rgb * cc_spotLitColor[i].w * illum * att * (diffuseContrib + lspec);\n }\n float fAmb = dot(N, vec3(0.0, -1.0, 0.0)) * 0.5 + 0.5;\n vec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb) * cc_ambientSky.w;\n finalColor += (ambDiff.rgb * diffuse);\n#if USE_IBL\n vec3 R = normalize(reflect(-V, N));\n vec4 env = textureCube(envMap, R);\n env.rgb = SRGBToLinear(env.rgb) * cc_ambientSky.w;\n finalColor += (env.rgb * specular);\n#endif\n#if CC_USE_HDR\n finalColor *= (1.0/1024.0);;\n#else\n finalColor *= cc_exposure.x;\n finalColor = LinearToSRGB(finalColor);\n#endif\n return vec4(finalColor, baseColor.a);\n}\nvoid main() { gl_FragColor = frag(); }\n` }, "builtins": {"globals":{"blocks":["CCGlobal"], "samplers":[]}, "locals":{"blocks":["CCLocal", "CCSkinning", "CCForwardLight"], "samplers":["cc_jointsTexture"]}}, "defines": [ @@ -229,14 +179,14 @@ export default [ }, { "name": "builtin-standard|planar-shadow-vs:vert|planar-shadow-fs:frag", - "hash": 4065700799, + "hash": 3947426249, "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};\nuniform CCLocal {\n mat4 cc_matWorld;\n mat4 cc_matWorldIT;\n};\nuniform CCShadow {\n mat4 cc_matLightPlaneProj;\n vec4 cc_shadowColor;\n};\n#if CC_USE_SKINNING\nin vec4 a_weights;\nin vec4 a_joints;\nuniform CCSkinning {\n mat4 cc_matJoint[128];\n vec4 cc_jointsTextureSize;\n};\n#if CC_USE_JOINTS_TEXTURE\nuniform sampler2D cc_jointsTexture;\nmat4 getBoneMatrix(const in float i) {\n float size = cc_jointsTextureSize.x;\n float j = i * 4.0;\n float x = mod(j, size);\n float y = floor(j / size);\n float dx = 1.0 / size;\n float dy = 1.0 / size;\n y = dy * (y + 0.5);\n vec4 v1 = texture(cc_jointsTexture, vec2(dx * (x + 0.5), y));\n vec4 v2 = texture(cc_jointsTexture, vec2(dx * (x + 1.5), y));\n vec4 v3 = texture(cc_jointsTexture, vec2(dx * (x + 2.5), y));\n vec4 v4 = texture(cc_jointsTexture, vec2(dx * (x + 3.5), y));\n return mat4(v1, v2, v3, v4);\n}\n#else\nmat4 getBoneMatrix(const in float i) {\n return cc_matJoint[int(i)];\n}\n#endif\nmat4 skinMatrix() {\n return\n getBoneMatrix(a_joints.x) * a_weights.x +\n getBoneMatrix(a_joints.y) * a_weights.y +\n getBoneMatrix(a_joints.z) * a_weights.z +\n getBoneMatrix(a_joints.w) * a_weights.w;\n}\nvoid skinVertex(inout vec4 a1) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n}\nvoid skinVertex(inout vec4 a1, inout vec4 a2) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n}\nvoid skinVertex(inout vec4 a1, inout vec4 a2, inout vec4 a3) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n a3 = m * a3;\n}\n#endif\nin vec3 a_position;\nvec4 vert () {\n vec4 pos = vec4(a_position, 1);\n #if CC_USE_SKINNING\n skinVertex(pos);\n #endif\n return cc_matViewProj * cc_matLightPlaneProj * cc_matWorld * pos;\n}\nvoid main() { gl_Position = vert(); }\n`, - "frag": `\nprecision highp 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};\nvec3 SRGBToLinear(vec3 gamma)\n{\n return pow(gamma, vec3(2.2));\n \n}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\n \n}\nvec4 PostProcess(vec4 color, float scale, float isHDR)\n{\n#if CC_USE_HDR\n color.rgb = mix(color.rgb, pow(color.rgb, vec3(2.2)) * scale, vec3(isHDR));\n#endif\n return color;\n}\nvec4 frag () {\n return PostProcess(cc_shadowColor, cc_exposure.w, cc_exposure.z);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }\n` + "vert": `\nprecision highp float;\nuniform CCGlobal {\n vec4 cc_time; \n vec4 cc_screenSize; \n vec4 cc_screenScale; \n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos; \n vec4 cc_exposure; \n vec4 cc_mainLitDir; \n vec4 cc_mainLitColor; \n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\nuniform CCLocal {\n mat4 cc_matWorld;\n mat4 cc_matWorldIT;\n};\nuniform CCShadow {\n mat4 cc_matLightPlaneProj;\n vec4 cc_shadowColor;\n};\n#if CC_USE_SKINNING\nin vec4 a_weights;\nin vec4 a_joints;\nuniform CCSkinning {\n mat4 cc_matJoint[128];\n vec4 cc_jointsTextureSize;\n};\n#if CC_USE_JOINTS_TEXTURE\nuniform sampler2D cc_jointsTexture;\nmat4 getBoneMatrix(const in float i) {\n float size = cc_jointsTextureSize.x;\n float j = i * 4.0;\n float x = mod(j, size);\n float y = floor(j / size);\n float dx = 1.0 / size;\n float dy = 1.0 / size;\n y = dy * (y + 0.5);\n vec4 v1 = texture(cc_jointsTexture, vec2(dx * (x + 0.5), y));\n vec4 v2 = texture(cc_jointsTexture, vec2(dx * (x + 1.5), y));\n vec4 v3 = texture(cc_jointsTexture, vec2(dx * (x + 2.5), y));\n vec4 v4 = texture(cc_jointsTexture, vec2(dx * (x + 3.5), y));\n return mat4(v1, v2, v3, v4);\n}\n#else\nmat4 getBoneMatrix(const in float i) {\n return cc_matJoint[int(i)];\n}\n#endif\nmat4 skinMatrix() {\n return\n getBoneMatrix(a_joints.x) * a_weights.x +\n getBoneMatrix(a_joints.y) * a_weights.y +\n getBoneMatrix(a_joints.z) * a_weights.z +\n getBoneMatrix(a_joints.w) * a_weights.w;\n}\nvoid skinVertex(inout vec4 a1) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n}\nvoid skinVertex(inout vec4 a1, inout vec4 a2) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n}\nvoid skinVertex(inout vec4 a1, inout vec4 a2, inout vec4 a3) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n a3 = m * a3;\n}\n#endif\nin vec3 a_position;\nvec4 vert () {\n vec4 pos = vec4(a_position, 1);\n #if CC_USE_SKINNING\n skinVertex(pos);\n #endif\n return cc_matViewProj * cc_matLightPlaneProj * cc_matWorld * pos;\n}\nvoid main() { gl_Position = vert(); }\n`, + "frag": `\nprecision highp 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 mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos; \n vec4 cc_exposure; \n vec4 cc_mainLitDir; \n vec4 cc_mainLitColor; \n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\nvec4 PostProcess(vec4 color)\n{\n#if CC_USE_HDR\n color.rgb = mix(color.rgb, pow(color.rgb, vec3(2.2)) * cc_exposure.w, vec3(cc_exposure.z));\n#endif\n return color;\n}\nvec4 frag () {\n return PostProcess(cc_shadowColor);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }\n` }, "glsl1": { - "vert": `\nprecision highp float;\nuniform vec4 cc_time;\nuniform vec4 cc_screenSize;\nuniform vec4 cc_screenScale;\nuniform vec4 cc_nativeSize;\nuniform mat4 cc_matView;\nuniform mat4 cc_matViewInv;\nuniform mat4 cc_matProj;\nuniform mat4 cc_matProjInv;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matViewProjInv;\nuniform vec4 cc_cameraPos;\nuniform vec4 cc_exposure;\nuniform vec4 cc_mainLitDir;\nuniform vec4 cc_mainLitColor;\nuniform vec4 cc_ambientSky;\nuniform vec4 cc_ambientGround;\nuniform mat4 cc_matWorld;\nuniform mat4 cc_matWorldIT;\nuniform mat4 cc_matLightPlaneProj;\nuniform vec4 cc_shadowColor;\n#if CC_USE_SKINNING\nattribute vec4 a_weights;\nattribute vec4 a_joints;\nuniform mat4 cc_matJoint[128];\nuniform vec4 cc_jointsTextureSize;\n#if CC_USE_JOINTS_TEXTURE\nuniform sampler2D cc_jointsTexture;\nmat4 getBoneMatrix(const in float i) {\n float size = cc_jointsTextureSize.x;\n float j = i * 4.0;\n float x = mod(j, size);\n float y = floor(j / size);\n float dx = 1.0 / size;\n float dy = 1.0 / size;\n y = dy * (y + 0.5);\n vec4 v1 = texture2D(cc_jointsTexture, vec2(dx * (x + 0.5), y));\n vec4 v2 = texture2D(cc_jointsTexture, vec2(dx * (x + 1.5), y));\n vec4 v3 = texture2D(cc_jointsTexture, vec2(dx * (x + 2.5), y));\n vec4 v4 = texture2D(cc_jointsTexture, vec2(dx * (x + 3.5), y));\n return mat4(v1, v2, v3, v4);\n}\n#else\nmat4 getBoneMatrix(const in float i) {\n return cc_matJoint[int(i)];\n}\n#endif\nmat4 skinMatrix() {\n return\n getBoneMatrix(a_joints.x) * a_weights.x +\n getBoneMatrix(a_joints.y) * a_weights.y +\n getBoneMatrix(a_joints.z) * a_weights.z +\n getBoneMatrix(a_joints.w) * a_weights.w;\n}\nvoid skinVertex(inout vec4 a1) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n}\nvoid skinVertex(inout vec4 a1, inout vec4 a2) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n}\nvoid skinVertex(inout vec4 a1, inout vec4 a2, inout vec4 a3) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n a3 = m * a3;\n}\n#endif\nattribute vec3 a_position;\nvec4 vert () {\n vec4 pos = vec4(a_position, 1);\n #if CC_USE_SKINNING\n skinVertex(pos);\n #endif\n return cc_matViewProj * cc_matLightPlaneProj * cc_matWorld * pos;\n}\nvoid main() { gl_Position = vert(); }\n`, - "frag": `\nprecision highp float;\nuniform mat4 cc_matLightPlaneProj;\nuniform vec4 cc_shadowColor;\nuniform vec4 cc_time;\nuniform vec4 cc_screenSize;\nuniform vec4 cc_screenScale;\nuniform vec4 cc_nativeSize;\nuniform mat4 cc_matView;\nuniform mat4 cc_matViewInv;\nuniform mat4 cc_matProj;\nuniform mat4 cc_matProjInv;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matViewProjInv;\nuniform vec4 cc_cameraPos;\nuniform vec4 cc_exposure;\nuniform vec4 cc_mainLitDir;\nuniform vec4 cc_mainLitColor;\nuniform vec4 cc_ambientSky;\nuniform vec4 cc_ambientGround;\nvec3 SRGBToLinear(vec3 gamma)\n{\n return pow(gamma, vec3(2.2));\n \n}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\n \n}\nvec4 PostProcess(vec4 color, float scale, float isHDR)\n{\n#if CC_USE_HDR\n color.rgb = mix(color.rgb, pow(color.rgb, vec3(2.2)) * scale, vec3(isHDR));\n#endif\n return color;\n}\nvec4 frag () {\n return PostProcess(cc_shadowColor, cc_exposure.w, cc_exposure.z);\n}\nvoid main() { gl_FragColor = frag(); }\n` + "vert": `\nprecision highp float;\nuniform vec4 cc_time;\nuniform vec4 cc_screenSize;\nuniform vec4 cc_screenScale;\nuniform mat4 cc_matView;\nuniform mat4 cc_matViewInv;\nuniform mat4 cc_matProj;\nuniform mat4 cc_matProjInv;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matViewProjInv;\nuniform vec4 cc_cameraPos;\nuniform vec4 cc_exposure;\nuniform vec4 cc_mainLitDir;\nuniform vec4 cc_mainLitColor;\nuniform vec4 cc_ambientSky;\nuniform vec4 cc_ambientGround;\nuniform mat4 cc_matWorld;\nuniform mat4 cc_matWorldIT;\nuniform mat4 cc_matLightPlaneProj;\nuniform vec4 cc_shadowColor;\n#if CC_USE_SKINNING\nattribute vec4 a_weights;\nattribute vec4 a_joints;\nuniform mat4 cc_matJoint[128];\nuniform vec4 cc_jointsTextureSize;\n#if CC_USE_JOINTS_TEXTURE\nuniform sampler2D cc_jointsTexture;\nmat4 getBoneMatrix(const in float i) {\n float size = cc_jointsTextureSize.x;\n float j = i * 4.0;\n float x = mod(j, size);\n float y = floor(j / size);\n float dx = 1.0 / size;\n float dy = 1.0 / size;\n y = dy * (y + 0.5);\n vec4 v1 = texture2D(cc_jointsTexture, vec2(dx * (x + 0.5), y));\n vec4 v2 = texture2D(cc_jointsTexture, vec2(dx * (x + 1.5), y));\n vec4 v3 = texture2D(cc_jointsTexture, vec2(dx * (x + 2.5), y));\n vec4 v4 = texture2D(cc_jointsTexture, vec2(dx * (x + 3.5), y));\n return mat4(v1, v2, v3, v4);\n}\n#else\nmat4 getBoneMatrix(const in float i) {\n return cc_matJoint[int(i)];\n}\n#endif\nmat4 skinMatrix() {\n return\n getBoneMatrix(a_joints.x) * a_weights.x +\n getBoneMatrix(a_joints.y) * a_weights.y +\n getBoneMatrix(a_joints.z) * a_weights.z +\n getBoneMatrix(a_joints.w) * a_weights.w;\n}\nvoid skinVertex(inout vec4 a1) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n}\nvoid skinVertex(inout vec4 a1, inout vec4 a2) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n}\nvoid skinVertex(inout vec4 a1, inout vec4 a2, inout vec4 a3) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n a3 = m * a3;\n}\n#endif\nattribute vec3 a_position;\nvec4 vert () {\n vec4 pos = vec4(a_position, 1);\n #if CC_USE_SKINNING\n skinVertex(pos);\n #endif\n return cc_matViewProj * cc_matLightPlaneProj * cc_matWorld * pos;\n}\nvoid main() { gl_Position = vert(); }\n`, + "frag": `\nprecision highp float;\nuniform mat4 cc_matLightPlaneProj;\nuniform vec4 cc_shadowColor;\nuniform vec4 cc_time;\nuniform vec4 cc_screenSize;\nuniform vec4 cc_screenScale;\nuniform mat4 cc_matView;\nuniform mat4 cc_matViewInv;\nuniform mat4 cc_matProj;\nuniform mat4 cc_matProjInv;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matViewProjInv;\nuniform vec4 cc_cameraPos;\nuniform vec4 cc_exposure;\nuniform vec4 cc_mainLitDir;\nuniform vec4 cc_mainLitColor;\nuniform vec4 cc_ambientSky;\nuniform vec4 cc_ambientGround;\nvec4 PostProcess(vec4 color)\n{\n#if CC_USE_HDR\n color.rgb = mix(color.rgb, pow(color.rgb, vec3(2.2)) * cc_exposure.w, vec3(cc_exposure.z));\n#endif\n return color;\n}\nvec4 frag () {\n return PostProcess(cc_shadowColor);\n}\nvoid main() { gl_FragColor = frag(); }\n` }, "builtins": {"globals":{"blocks":["CCGlobal", "CCShadow"], "samplers":[]}, "locals":{"blocks":["CCLocal", "CCSkinning"], "samplers":["cc_jointsTexture"]}}, "defines": [ @@ -253,29 +203,27 @@ export default [ { "name": "builtin-tonemap", "techniques": [ - {"name":"tonemap", "passes":[{"depthStencilState":{"depthTest":false, "depthWrite":false}, "program":"builtin-tonemap|tonemap-vs:vert|tonemap-fs:frag", "properties":{"u_texSampler":{"type":29, "sampler":{"minFilter":2, "magFilter":2, "addressU":2, "addressV":2}}, "u_blendTexSampler":{"type":29, "sampler":{"minFilter":2, "magFilter":2, "addressU":2, "addressV":2}}}}]} + {"name":"tonemap", "passes":[{"depthStencilState":{"depthTest":false, "depthWrite":false}, "program":"builtin-tonemap|tonemap-vs:vert|tonemap-fs:frag", "properties":{"u_texSampler":{"sampler":[2, 2, null, 2, 2], "type":29}}}]} ], "shaders": [ { "name": "builtin-tonemap|tonemap-vs:vert|tonemap-fs:frag", - "hash": 3127693453, + "hash": 181338825, "glsl3": { - "vert": `\nprecision highp float;\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define EPSILON 1e-6\n#define LOG2 1.442695\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#define FP_MAX = 65504.0;\n#define FP_SCALE (1.0/1024.0);\n#define FP_SCALE_INV 1024.0;\nuniform CCGlobal {\n vec4 cc_time; \n vec4 cc_screenSize; \n vec4 cc_screenScale; \n vec4 cc_nativeSize; \n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos; \n vec4 cc_exposure; \n vec4 cc_mainLitDir; \n vec4 cc_mainLitColor; \n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\nin vec2 a_position;\nin vec2 a_texCoord;\nout vec2 v_uv;\nout vec4 v_offset;\nvec4 vert () {\n vec4 pos = vec4(a_position, 0, 1);\n v_uv = a_texCoord * cc_screenScale.xy;\n v_offset = v_uv.xyxy + cc_nativeSize.xyxy * vec4(1.0, 0.0, 0.0, 1.0);\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n`, - "frag": `\nprecision highp float;\nuniform CCGlobal {\n vec4 cc_time; \n vec4 cc_screenSize; \n vec4 cc_screenScale; \n vec4 cc_nativeSize; \n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos; \n vec4 cc_exposure; \n vec4 cc_mainLitDir; \n vec4 cc_mainLitColor; \n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define EPSILON 1e-6\n#define LOG2 1.442695\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#define FP_MAX = 65504.0;\n#define FP_SCALE (1.0/1024.0);\n#define FP_SCALE_INV 1024.0;\nvec3 SRGBToLinear(vec3 gamma)\n{\n return pow(gamma, vec3(2.2));\n \n}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\n \n}\nvec3 ACESToneMap(vec3 color) {\n const float A = 2.51;\n const float B = 0.03;\n const float C = 2.43;\n const float D = 0.59;\n const float E = 0.14;\n return (color * (A * color + B)) / (color * (C * color + D) + E);\n}\nin vec2 v_uv;\nin vec4 v_offset;\nuniform sampler2D u_texSampler;\nuniform sampler2D u_blendTexSampler;\nvec3 ToLDR(vec3 color) {\n#if CC_USE_HDR\n color *= cc_exposure.x * 1024.0;;\n color = ACESToneMap(color);\n color = LinearToSRGB(color);\n#endif\n return color;\n}\nvec4 frag () {\n#if USE_SMAA\n \n vec4 a;\n a.rb = texture(u_blendTexSampler, v_uv).rb; \n a.g = texture(u_blendTexSampler, v_offset.zw).g; \n a.a = texture(u_blendTexSampler, v_offset.xy).a; \n if (dot(a, vec4(1.0)) < 1e-5) {\n vec4 o = texture(u_texSampler, v_uv);\n o.rgb = ToLDR(o.rgb);\n return o;\n } else {\n vec2 offset;\n offset.x = a.a > a.b ? a.a : -a.b;\n offset.y = a.g > a.r ? -a.g : a.r;\n if (abs(offset.x) > abs(offset.y)) {\n offset.y = 0.0;\n } else {\n offset.x = 0.0;\n }\n vec4 C = texture(u_texSampler, v_uv);\n C.rgb = ToLDR(C.rgb);\n vec2 uv = v_uv + sign(offset) * cc_nativeSize.zw;\n vec4 Cop = texture(u_texSampler, uv);\n Cop.rgb = ToLDR(Cop.rgb);\n float s = abs(offset.x) > abs(offset.y) ? abs(offset.x) : abs(offset.y);\n C.rgb = pow(C.rgb, vec3(2.2));\n Cop.rgb = pow(Cop.rgb, vec3(2.2));\n vec4 mixed = mix(C, Cop, s);\n mixed.rgb = pow(mixed.rgb, vec3(1.0 / 2.2));\n return mixed;\n }\n#else \n vec4 o = texture(u_texSampler, v_uv);\n \n o.rgb = ToLDR(o.rgb);\n return o;\n#endif\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }\n` + "vert": `\nprecision highp float;\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define EPSILON 1e-6\n#define LOG2 1.442695\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#define FP_MAX = 65504.0;\n#define FP_SCALE (1.0/1024.0);\n#define FP_SCALE_INV 1024.0;\nuniform CCGlobal {\n vec4 cc_time; \n vec4 cc_screenSize; \n vec4 cc_screenScale; \n 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;\nvec4 vert () {\n vec4 pos = vec4(a_position, 0, 1);\n v_uv = a_texCoord * cc_screenScale.xy;\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 mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos; \n vec4 cc_exposure; \n vec4 cc_mainLitDir; \n vec4 cc_mainLitColor; \n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define EPSILON 1e-6\n#define LOG2 1.442695\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#define FP_MAX = 65504.0;\n#define FP_SCALE (1.0/1024.0);\n#define FP_SCALE_INV 1024.0;\nfloat ComputeEV100(float aperture, float shutterTime, float iso, float ec) {\n return log2((aperture * aperture) / shutterTime * 100.0 / iso) - ec;\n}\nfloat ComputeExposure(float ev100) {\n return 0.833333 / pow(2.0, ev100);\n}\nvec3 SRGBToLinear(vec3 gamma)\n{\n return pow(gamma, vec3(2.2));\n \n}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\n \n}\nvec3 ACESToneMap(vec3 color) {\n const float A = 2.51;\n const float B = 0.03;\n const float C = 2.43;\n const float D = 0.59;\n const float E = 0.14;\n return (color * (A * color + B)) / (color * (C * color + D) + E);\n}\nin vec2 v_uv;\nuniform sampler2D u_texSampler;\nvec4 frag () {\n vec4 o = texture(u_texSampler, v_uv);\n#if CC_USE_HDR\n o.rgb *= cc_exposure.x * 1024.0;;\n o.rgb = ACESToneMap(o.rgb);\n o.rgb = LinearToSRGB(o.rgb);\n#endif\n return o;\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }\n` }, "glsl1": { - "vert": `\nprecision highp float;\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define EPSILON 1e-6\n#define LOG2 1.442695\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#define FP_MAX = 65504.0;\n#define FP_SCALE (1.0/1024.0);\n#define FP_SCALE_INV 1024.0;\nuniform vec4 cc_time;\nuniform vec4 cc_screenSize;\nuniform vec4 cc_screenScale;\nuniform vec4 cc_nativeSize;\nuniform mat4 cc_matView;\nuniform mat4 cc_matViewInv;\nuniform mat4 cc_matProj;\nuniform mat4 cc_matProjInv;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matViewProjInv;\nuniform vec4 cc_cameraPos;\nuniform vec4 cc_exposure;\nuniform vec4 cc_mainLitDir;\nuniform vec4 cc_mainLitColor;\nuniform vec4 cc_ambientSky;\nuniform vec4 cc_ambientGround;\nattribute vec2 a_position;\nattribute vec2 a_texCoord;\nvarying vec2 v_uv;\nvarying vec4 v_offset;\nvec4 vert () {\n vec4 pos = vec4(a_position, 0, 1);\n v_uv = a_texCoord * cc_screenScale.xy;\n v_offset = v_uv.xyxy + cc_nativeSize.xyxy * vec4(1.0, 0.0, 0.0, 1.0);\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n`, - "frag": `\nprecision highp float;\nuniform vec4 cc_time;\nuniform vec4 cc_screenSize;\nuniform vec4 cc_screenScale;\nuniform vec4 cc_nativeSize;\nuniform mat4 cc_matView;\nuniform mat4 cc_matViewInv;\nuniform mat4 cc_matProj;\nuniform mat4 cc_matProjInv;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matViewProjInv;\nuniform vec4 cc_cameraPos;\nuniform vec4 cc_exposure;\nuniform vec4 cc_mainLitDir;\nuniform vec4 cc_mainLitColor;\nuniform vec4 cc_ambientSky;\nuniform vec4 cc_ambientGround;\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define EPSILON 1e-6\n#define LOG2 1.442695\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#define FP_MAX = 65504.0;\n#define FP_SCALE (1.0/1024.0);\n#define FP_SCALE_INV 1024.0;\nvec3 SRGBToLinear(vec3 gamma)\n{\n return pow(gamma, vec3(2.2));\n \n}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\n \n}\nvec3 ACESToneMap(vec3 color) {\n const float A = 2.51;\n const float B = 0.03;\n const float C = 2.43;\n const float D = 0.59;\n const float E = 0.14;\n return (color * (A * color + B)) / (color * (C * color + D) + E);\n}\nvarying vec2 v_uv;\nvarying vec4 v_offset;\nuniform sampler2D u_texSampler;\nuniform sampler2D u_blendTexSampler;\nvec3 ToLDR(vec3 color) {\n#if CC_USE_HDR\n color *= cc_exposure.x * 1024.0;;\n color = ACESToneMap(color);\n color = LinearToSRGB(color);\n#endif\n return color;\n}\nvec4 frag () {\n#if USE_SMAA\n \n vec4 a;\n a.rb = texture2D(u_blendTexSampler, v_uv).rb; \n a.g = texture2D(u_blendTexSampler, v_offset.zw).g; \n a.a = texture2D(u_blendTexSampler, v_offset.xy).a; \n if (dot(a, vec4(1.0)) < 1e-5) {\n vec4 o = texture2D(u_texSampler, v_uv);\n o.rgb = ToLDR(o.rgb);\n return o;\n } else {\n vec2 offset;\n offset.x = a.a > a.b ? a.a : -a.b;\n offset.y = a.g > a.r ? -a.g : a.r;\n if (abs(offset.x) > abs(offset.y)) {\n offset.y = 0.0;\n } else {\n offset.x = 0.0;\n }\n vec4 C = texture2D(u_texSampler, v_uv);\n C.rgb = ToLDR(C.rgb);\n vec2 uv = v_uv + sign(offset) * cc_nativeSize.zw;\n vec4 Cop = texture2D(u_texSampler, uv);\n Cop.rgb = ToLDR(Cop.rgb);\n float s = abs(offset.x) > abs(offset.y) ? abs(offset.x) : abs(offset.y);\n C.rgb = pow(C.rgb, vec3(2.2));\n Cop.rgb = pow(Cop.rgb, vec3(2.2));\n vec4 mixed = mix(C, Cop, s);\n mixed.rgb = pow(mixed.rgb, vec3(1.0 / 2.2));\n return mixed;\n }\n#else \n vec4 o = texture2D(u_texSampler, v_uv);\n \n o.rgb = ToLDR(o.rgb);\n return o;\n#endif\n}\nvoid main() { gl_FragColor = frag(); }\n` + "vert": `\nprecision highp float;\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define EPSILON 1e-6\n#define LOG2 1.442695\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#define FP_MAX = 65504.0;\n#define FP_SCALE (1.0/1024.0);\n#define FP_SCALE_INV 1024.0;\nuniform vec4 cc_time;\nuniform vec4 cc_screenSize;\nuniform vec4 cc_screenScale;\nuniform mat4 cc_matView;\nuniform mat4 cc_matViewInv;\nuniform mat4 cc_matProj;\nuniform mat4 cc_matProjInv;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matViewProjInv;\nuniform vec4 cc_cameraPos;\nuniform vec4 cc_exposure;\nuniform vec4 cc_mainLitDir;\nuniform vec4 cc_mainLitColor;\nuniform vec4 cc_ambientSky;\nuniform vec4 cc_ambientGround;\nattribute vec2 a_position;\nattribute vec2 a_texCoord;\nvarying vec2 v_uv;\nvec4 vert () {\n vec4 pos = vec4(a_position, 0, 1);\n v_uv = a_texCoord * cc_screenScale.xy;\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n`, + "frag": `\nprecision highp float;\nuniform vec4 cc_time;\nuniform vec4 cc_screenSize;\nuniform vec4 cc_screenScale;\nuniform mat4 cc_matView;\nuniform mat4 cc_matViewInv;\nuniform mat4 cc_matProj;\nuniform mat4 cc_matProjInv;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matViewProjInv;\nuniform vec4 cc_cameraPos;\nuniform vec4 cc_exposure;\nuniform vec4 cc_mainLitDir;\nuniform vec4 cc_mainLitColor;\nuniform vec4 cc_ambientSky;\nuniform vec4 cc_ambientGround;\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define EPSILON 1e-6\n#define LOG2 1.442695\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#define FP_MAX = 65504.0;\n#define FP_SCALE (1.0/1024.0);\n#define FP_SCALE_INV 1024.0;\nfloat ComputeEV100(float aperture, float shutterTime, float iso, float ec) {\n return log2((aperture * aperture) / shutterTime * 100.0 / iso) - ec;\n}\nfloat ComputeExposure(float ev100) {\n return 0.833333 / pow(2.0, ev100);\n}\nvec3 SRGBToLinear(vec3 gamma)\n{\n return pow(gamma, vec3(2.2));\n \n}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\n \n}\nvec3 ACESToneMap(vec3 color) {\n const float A = 2.51;\n const float B = 0.03;\n const float C = 2.43;\n const float D = 0.59;\n const float E = 0.14;\n return (color * (A * color + B)) / (color * (C * color + D) + E);\n}\nvarying vec2 v_uv;\nuniform sampler2D u_texSampler;\nvec4 frag () {\n vec4 o = texture2D(u_texSampler, v_uv);\n#if CC_USE_HDR\n o.rgb *= cc_exposure.x * 1024.0;;\n o.rgb = ACESToneMap(o.rgb);\n o.rgb = LinearToSRGB(o.rgb);\n#endif\n return o;\n}\nvoid main() { gl_FragColor = frag(); }\n` }, "builtins": {"globals":{"blocks":["CCGlobal"], "samplers":[]}, "locals":{"blocks":[], "samplers":[]}}, "defines": [ - {"name":"CC_USE_HDR", "type":"boolean", "defines":[]}, - {"name":"USE_SMAA", "type":"boolean", "defines":[]} + {"name":"CC_USE_HDR", "type":"boolean", "defines":[]} ], "blocks": [], "samplers": [ - {"name":"u_texSampler", "type":29, "count":1, "defines":[], "binding":0}, - {"name":"u_blendTexSampler", "type":29, "count":1, "defines":[], "binding":1} + {"name":"u_texSampler", "type":29, "count":1, "defines":[], "binding":0} ], "dependencies": {} } @@ -289,14 +237,14 @@ export default [ "shaders": [ { "name": "builtin-unlit|unlit-vs:vert|unlit-fs:frag", - "hash": 1263217225, + "hash": 2274567937, "glsl3": { - "vert": `\nprecision mediump float;\nuniform CCGlobal {\n vec4 cc_time; \n vec4 cc_screenSize; \n vec4 cc_screenScale; \n vec4 cc_nativeSize; \n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos; \n vec4 cc_exposure; \n vec4 cc_mainLitDir; \n vec4 cc_mainLitColor; \n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\nuniform CCLocal {\n mat4 cc_matWorld;\n mat4 cc_matWorldIT;\n};\n#if CC_USE_SKINNING\nin vec4 a_weights;\nin vec4 a_joints;\nuniform CCSkinning {\n mat4 cc_matJoint[128];\n vec4 cc_jointsTextureSize;\n};\n#if CC_USE_JOINTS_TEXTURE\nuniform sampler2D cc_jointsTexture;\nmat4 getBoneMatrix(const in float i) {\n float size = cc_jointsTextureSize.x;\n float j = i * 4.0;\n float x = mod(j, size);\n float y = floor(j / size);\n float dx = 1.0 / size;\n float dy = 1.0 / size;\n y = dy * (y + 0.5);\n vec4 v1 = texture(cc_jointsTexture, vec2(dx * (x + 0.5), y));\n vec4 v2 = texture(cc_jointsTexture, vec2(dx * (x + 1.5), y));\n vec4 v3 = texture(cc_jointsTexture, vec2(dx * (x + 2.5), y));\n vec4 v4 = texture(cc_jointsTexture, vec2(dx * (x + 3.5), y));\n return mat4(v1, v2, v3, v4);\n}\n#else\nmat4 getBoneMatrix(const in float i) {\n return cc_matJoint[int(i)];\n}\n#endif\nmat4 skinMatrix() {\n return\n getBoneMatrix(a_joints.x) * a_weights.x +\n getBoneMatrix(a_joints.y) * a_weights.y +\n getBoneMatrix(a_joints.z) * a_weights.z +\n getBoneMatrix(a_joints.w) * a_weights.w;\n}\nvoid skinVertex(inout vec4 a1) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n}\nvoid skinVertex(inout vec4 a1, inout vec4 a2) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n}\nvoid skinVertex(inout vec4 a1, inout vec4 a2, inout vec4 a3) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n a3 = m * a3;\n}\n#endif\nin vec3 a_position;\n#if USE_TEXTURE\n in vec2 a_texCoord;\n out vec2 uv0;\n uniform TexCoords {\n vec4 tilingOffset;\n };\n#endif\nvec4 vert () {\n vec4 pos = vec4(a_position, 1);\n #if CC_USE_SKINNING\n skinVertex(pos);\n #endif\n pos = cc_matViewProj * cc_matWorld * pos;\n #if USE_TEXTURE\n uv0 = a_texCoord * tilingOffset.xy + tilingOffset.zw;\n #endif\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n`, - "frag": `\nprecision mediump float;\nuniform CCGlobal {\n vec4 cc_time; \n vec4 cc_screenSize; \n vec4 cc_screenScale; \n vec4 cc_nativeSize; \n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos; \n vec4 cc_exposure; \n vec4 cc_mainLitDir; \n vec4 cc_mainLitColor; \n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\nvec4 PostProcess(vec4 color, float scale, float isHDR)\n{\n#if CC_USE_HDR\n color.rgb = mix(color.rgb, pow(color.rgb, vec3(2.2)) * scale, vec3(isHDR));\n#endif\n return color;\n}\n#if USE_TEXTURE\n in vec2 uv0;\n uniform sampler2D mainTexture;\n#endif\n#if USE_COLOR\n uniform Constant {\n vec4 color;\n };\n#endif\nvec4 frag () {\n vec4 o = vec4(1, 1, 1, 1);\n #if USE_TEXTURE\n o *= texture(mainTexture, uv0);\n #endif\n #if USE_COLOR\n o *= color;\n #endif\n return PostProcess(o, cc_exposure.w, cc_exposure.z);\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 mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos; \n vec4 cc_exposure; \n vec4 cc_mainLitDir; \n vec4 cc_mainLitColor; \n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\nuniform CCLocal {\n mat4 cc_matWorld;\n mat4 cc_matWorldIT;\n};\n#if CC_USE_SKINNING\nin vec4 a_weights;\nin vec4 a_joints;\nuniform CCSkinning {\n mat4 cc_matJoint[128];\n vec4 cc_jointsTextureSize;\n};\n#if CC_USE_JOINTS_TEXTURE\nuniform sampler2D cc_jointsTexture;\nmat4 getBoneMatrix(const in float i) {\n float size = cc_jointsTextureSize.x;\n float j = i * 4.0;\n float x = mod(j, size);\n float y = floor(j / size);\n float dx = 1.0 / size;\n float dy = 1.0 / size;\n y = dy * (y + 0.5);\n vec4 v1 = texture(cc_jointsTexture, vec2(dx * (x + 0.5), y));\n vec4 v2 = texture(cc_jointsTexture, vec2(dx * (x + 1.5), y));\n vec4 v3 = texture(cc_jointsTexture, vec2(dx * (x + 2.5), y));\n vec4 v4 = texture(cc_jointsTexture, vec2(dx * (x + 3.5), y));\n return mat4(v1, v2, v3, v4);\n}\n#else\nmat4 getBoneMatrix(const in float i) {\n return cc_matJoint[int(i)];\n}\n#endif\nmat4 skinMatrix() {\n return\n getBoneMatrix(a_joints.x) * a_weights.x +\n getBoneMatrix(a_joints.y) * a_weights.y +\n getBoneMatrix(a_joints.z) * a_weights.z +\n getBoneMatrix(a_joints.w) * a_weights.w;\n}\nvoid skinVertex(inout vec4 a1) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n}\nvoid skinVertex(inout vec4 a1, inout vec4 a2) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n}\nvoid skinVertex(inout vec4 a1, inout vec4 a2, inout vec4 a3) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n a3 = m * a3;\n}\n#endif\nin vec3 a_position;\n#if USE_TEXTURE\n in vec2 a_texCoord;\n out vec2 uv0;\n uniform TexCoords {\n vec4 tilingOffset;\n };\n#endif\nvec4 vert () {\n vec4 pos = vec4(a_position, 1);\n #if CC_USE_SKINNING\n skinVertex(pos);\n #endif\n pos = cc_matViewProj * cc_matWorld * pos;\n #if USE_TEXTURE\n uv0 = a_texCoord * tilingOffset.xy + tilingOffset.zw;\n #endif\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n`, + "frag": `\nprecision mediump float;\nuniform CCGlobal {\n vec4 cc_time; \n vec4 cc_screenSize; \n vec4 cc_screenScale; \n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos; \n vec4 cc_exposure; \n vec4 cc_mainLitDir; \n vec4 cc_mainLitColor; \n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\nvec4 PostProcess(vec4 color)\n{\n#if CC_USE_HDR\n color.rgb = mix(color.rgb, pow(color.rgb, vec3(2.2)) * cc_exposure.w, vec3(cc_exposure.z));\n#endif\n return color;\n}\n#if USE_TEXTURE\n in vec2 uv0;\n uniform sampler2D mainTexture;\n#endif\n#if USE_COLOR\n uniform Constant {\n vec4 color;\n };\n#endif\nvec4 frag () {\n vec4 o = vec4(1, 1, 1, 1);\n #if USE_TEXTURE\n o *= texture(mainTexture, uv0);\n #endif\n #if USE_COLOR\n o *= color;\n #endif\n return PostProcess(o);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }\n` }, "glsl1": { - "vert": `\nprecision mediump float;\nuniform vec4 cc_time;\nuniform vec4 cc_screenSize;\nuniform vec4 cc_screenScale;\nuniform vec4 cc_nativeSize;\nuniform mat4 cc_matView;\nuniform mat4 cc_matViewInv;\nuniform mat4 cc_matProj;\nuniform mat4 cc_matProjInv;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matViewProjInv;\nuniform vec4 cc_cameraPos;\nuniform vec4 cc_exposure;\nuniform vec4 cc_mainLitDir;\nuniform vec4 cc_mainLitColor;\nuniform vec4 cc_ambientSky;\nuniform vec4 cc_ambientGround;\nuniform mat4 cc_matWorld;\nuniform mat4 cc_matWorldIT;\n#if CC_USE_SKINNING\nattribute vec4 a_weights;\nattribute vec4 a_joints;\nuniform mat4 cc_matJoint[128];\nuniform vec4 cc_jointsTextureSize;\n#if CC_USE_JOINTS_TEXTURE\nuniform sampler2D cc_jointsTexture;\nmat4 getBoneMatrix(const in float i) {\n float size = cc_jointsTextureSize.x;\n float j = i * 4.0;\n float x = mod(j, size);\n float y = floor(j / size);\n float dx = 1.0 / size;\n float dy = 1.0 / size;\n y = dy * (y + 0.5);\n vec4 v1 = texture2D(cc_jointsTexture, vec2(dx * (x + 0.5), y));\n vec4 v2 = texture2D(cc_jointsTexture, vec2(dx * (x + 1.5), y));\n vec4 v3 = texture2D(cc_jointsTexture, vec2(dx * (x + 2.5), y));\n vec4 v4 = texture2D(cc_jointsTexture, vec2(dx * (x + 3.5), y));\n return mat4(v1, v2, v3, v4);\n}\n#else\nmat4 getBoneMatrix(const in float i) {\n return cc_matJoint[int(i)];\n}\n#endif\nmat4 skinMatrix() {\n return\n getBoneMatrix(a_joints.x) * a_weights.x +\n getBoneMatrix(a_joints.y) * a_weights.y +\n getBoneMatrix(a_joints.z) * a_weights.z +\n getBoneMatrix(a_joints.w) * a_weights.w;\n}\nvoid skinVertex(inout vec4 a1) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n}\nvoid skinVertex(inout vec4 a1, inout vec4 a2) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n}\nvoid skinVertex(inout vec4 a1, inout vec4 a2, inout vec4 a3) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n a3 = m * a3;\n}\n#endif\nattribute vec3 a_position;\n#if USE_TEXTURE\n attribute vec2 a_texCoord;\n varying vec2 uv0;\n uniform vec4 tilingOffset;\n#endif\nvec4 vert () {\n vec4 pos = vec4(a_position, 1);\n #if CC_USE_SKINNING\n skinVertex(pos);\n #endif\n pos = cc_matViewProj * cc_matWorld * pos;\n #if USE_TEXTURE\n uv0 = a_texCoord * tilingOffset.xy + tilingOffset.zw;\n #endif\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n`, - "frag": `\nprecision mediump float;\nuniform vec4 cc_time;\nuniform vec4 cc_screenSize;\nuniform vec4 cc_screenScale;\nuniform vec4 cc_nativeSize;\nuniform mat4 cc_matView;\nuniform mat4 cc_matViewInv;\nuniform mat4 cc_matProj;\nuniform mat4 cc_matProjInv;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matViewProjInv;\nuniform vec4 cc_cameraPos;\nuniform vec4 cc_exposure;\nuniform vec4 cc_mainLitDir;\nuniform vec4 cc_mainLitColor;\nuniform vec4 cc_ambientSky;\nuniform vec4 cc_ambientGround;\nvec4 PostProcess(vec4 color, float scale, float isHDR)\n{\n#if CC_USE_HDR\n color.rgb = mix(color.rgb, pow(color.rgb, vec3(2.2)) * scale, vec3(isHDR));\n#endif\n return color;\n}\n#if USE_TEXTURE\n varying vec2 uv0;\n uniform sampler2D mainTexture;\n#endif\n#if USE_COLOR\n uniform vec4 color;\n#endif\nvec4 frag () {\n vec4 o = vec4(1, 1, 1, 1);\n #if USE_TEXTURE\n o *= texture2D(mainTexture, uv0);\n #endif\n #if USE_COLOR\n o *= color;\n #endif\n return PostProcess(o, cc_exposure.w, cc_exposure.z);\n}\nvoid main() { gl_FragColor = frag(); }\n` + "vert": `\nprecision mediump float;\nuniform vec4 cc_time;\nuniform vec4 cc_screenSize;\nuniform vec4 cc_screenScale;\nuniform mat4 cc_matView;\nuniform mat4 cc_matViewInv;\nuniform mat4 cc_matProj;\nuniform mat4 cc_matProjInv;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matViewProjInv;\nuniform vec4 cc_cameraPos;\nuniform vec4 cc_exposure;\nuniform vec4 cc_mainLitDir;\nuniform vec4 cc_mainLitColor;\nuniform vec4 cc_ambientSky;\nuniform vec4 cc_ambientGround;\nuniform mat4 cc_matWorld;\nuniform mat4 cc_matWorldIT;\n#if CC_USE_SKINNING\nattribute vec4 a_weights;\nattribute vec4 a_joints;\nuniform mat4 cc_matJoint[128];\nuniform vec4 cc_jointsTextureSize;\n#if CC_USE_JOINTS_TEXTURE\nuniform sampler2D cc_jointsTexture;\nmat4 getBoneMatrix(const in float i) {\n float size = cc_jointsTextureSize.x;\n float j = i * 4.0;\n float x = mod(j, size);\n float y = floor(j / size);\n float dx = 1.0 / size;\n float dy = 1.0 / size;\n y = dy * (y + 0.5);\n vec4 v1 = texture2D(cc_jointsTexture, vec2(dx * (x + 0.5), y));\n vec4 v2 = texture2D(cc_jointsTexture, vec2(dx * (x + 1.5), y));\n vec4 v3 = texture2D(cc_jointsTexture, vec2(dx * (x + 2.5), y));\n vec4 v4 = texture2D(cc_jointsTexture, vec2(dx * (x + 3.5), y));\n return mat4(v1, v2, v3, v4);\n}\n#else\nmat4 getBoneMatrix(const in float i) {\n return cc_matJoint[int(i)];\n}\n#endif\nmat4 skinMatrix() {\n return\n getBoneMatrix(a_joints.x) * a_weights.x +\n getBoneMatrix(a_joints.y) * a_weights.y +\n getBoneMatrix(a_joints.z) * a_weights.z +\n getBoneMatrix(a_joints.w) * a_weights.w;\n}\nvoid skinVertex(inout vec4 a1) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n}\nvoid skinVertex(inout vec4 a1, inout vec4 a2) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n}\nvoid skinVertex(inout vec4 a1, inout vec4 a2, inout vec4 a3) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n a3 = m * a3;\n}\n#endif\nattribute vec3 a_position;\n#if USE_TEXTURE\n attribute vec2 a_texCoord;\n varying vec2 uv0;\n uniform vec4 tilingOffset;\n#endif\nvec4 vert () {\n vec4 pos = vec4(a_position, 1);\n #if CC_USE_SKINNING\n skinVertex(pos);\n #endif\n pos = cc_matViewProj * cc_matWorld * pos;\n #if USE_TEXTURE\n uv0 = a_texCoord * tilingOffset.xy + tilingOffset.zw;\n #endif\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n`, + "frag": `\nprecision mediump float;\nuniform vec4 cc_time;\nuniform vec4 cc_screenSize;\nuniform vec4 cc_screenScale;\nuniform mat4 cc_matView;\nuniform mat4 cc_matViewInv;\nuniform mat4 cc_matProj;\nuniform mat4 cc_matProjInv;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matViewProjInv;\nuniform vec4 cc_cameraPos;\nuniform vec4 cc_exposure;\nuniform vec4 cc_mainLitDir;\nuniform vec4 cc_mainLitColor;\nuniform vec4 cc_ambientSky;\nuniform vec4 cc_ambientGround;\nvec4 PostProcess(vec4 color)\n{\n#if CC_USE_HDR\n color.rgb = mix(color.rgb, pow(color.rgb, vec3(2.2)) * cc_exposure.w, vec3(cc_exposure.z));\n#endif\n return color;\n}\n#if USE_TEXTURE\n varying vec2 uv0;\n uniform sampler2D mainTexture;\n#endif\n#if USE_COLOR\n uniform vec4 color;\n#endif\nvec4 frag () {\n vec4 o = vec4(1, 1, 1, 1);\n #if USE_TEXTURE\n o *= texture2D(mainTexture, uv0);\n #endif\n #if USE_COLOR\n o *= color;\n #endif\n return PostProcess(o);\n}\nvoid main() { gl_FragColor = frag(); }\n` }, "builtins": {"globals":{"blocks":["CCGlobal"], "samplers":[]}, "locals":{"blocks":["CCLocal", "CCSkinning"], "samplers":["cc_jointsTexture"]}}, "defines": [ diff --git a/cocos/assets/texture-base.ts b/cocos/assets/texture-base.ts index a058eb61d1..9b01c98083 100644 --- a/cocos/assets/texture-base.ts +++ b/cocos/assets/texture-base.ts @@ -32,6 +32,7 @@ import { GFXAddress, GFXBufferTextureCopy, GFXFilter, GFXFormat, import { GFXDevice } from '../gfx/device'; import { GFXTexture, IGFXTextureInfo } from '../gfx/texture'; import { GFXTextureView, IGFXTextureViewInfo } from '../gfx/texture-view'; +import { SamplerInfoIndex } from '../renderer/core/sampler-lib'; import { Asset } from './asset'; import { ImageAsset } from './image-asset'; @@ -313,10 +314,10 @@ export class TextureBase extends EventTargetFactory(Asset) { * @param wrapR */ public setWrapMode (wrapS: WrapMode, wrapT: WrapMode, wrapR?: WrapMode) { - if (wrapS !== this._wrapS) { this._wrapS = wrapS; this._samplerInfo[3] = wrapS; } - if (wrapT !== this._wrapT) { this._wrapT = wrapT; this._samplerInfo[4] = wrapT; } + if (wrapS !== this._wrapS) { this._wrapS = wrapS; this._samplerInfo[SamplerInfoIndex.addressU] = wrapS; } + if (wrapT !== this._wrapT) { this._wrapT = wrapT; this._samplerInfo[SamplerInfoIndex.addressV] = wrapT; } if (wrapR === undefined) { return; } - if (wrapR !== this._wrapR) { this._wrapR = wrapR; this._samplerInfo[5] = wrapR; } + if (wrapR !== this._wrapR) { this._wrapR = wrapR; this._samplerInfo[SamplerInfoIndex.addressW] = wrapR; } } /** @@ -326,8 +327,8 @@ export class TextureBase extends EventTargetFactory(Asset) { * @param magFilter */ public setFilters (minFilter: Filter, magFilter: Filter) { - if (minFilter !== this._minFilter) { this._minFilter = minFilter; this._samplerInfo[0] = minFilter; } - if (magFilter !== this._magFilter) { this._magFilter = magFilter; this._samplerInfo[1] = magFilter; } + if (minFilter !== this._minFilter) { this._minFilter = minFilter; this._samplerInfo[SamplerInfoIndex.minFilter] = minFilter; } + if (magFilter !== this._magFilter) { this._magFilter = magFilter; this._samplerInfo[SamplerInfoIndex.magFilter] = magFilter; } } /** @@ -336,7 +337,7 @@ export class TextureBase extends EventTargetFactory(Asset) { * @param mipFilter */ public setMipFilter (mipFilter: Filter) { - if (mipFilter !== this._mipFilter) { this._mipFilter = mipFilter; this._samplerInfo[2] = mipFilter; } + if (mipFilter !== this._mipFilter) { this._mipFilter = mipFilter; this._samplerInfo[SamplerInfoIndex.mipFilter] = mipFilter; } } /** @@ -365,7 +366,7 @@ export class TextureBase extends EventTargetFactory(Asset) { * @param anisotropy */ public setAnisotropy (anisotropy: number) { - if (anisotropy !== this._anisotropy) { this._anisotropy = anisotropy; this._samplerInfo[6] = anisotropy; } + if (anisotropy !== this._anisotropy) { this._anisotropy = anisotropy; this._samplerInfo[SamplerInfoIndex.maxAnisotropy] = anisotropy; } } /** diff --git a/cocos/renderer/core/pass.ts b/cocos/renderer/core/pass.ts index de6befb91d..b0f9364066 100644 --- a/cocos/renderer/core/pass.ts +++ b/cocos/renderer/core/pass.ts @@ -172,11 +172,13 @@ export class Pass { for (const u of shaderInfo.samplers) { this._handleMap[u.name] = genHandle(GFXBindingType.SAMPLER, u.type, u.binding); const inf = info.properties && info.properties[u.name]; + if (inf && inf.sampler) { this._samplers[u.binding] = samplerLib.getSampler(device, inf.sampler); } const texName = inf && inf.value ? inf.value + '-texture' : _type2default[u.type]; const texture = builtinResMgr.get(texName); if (texture) { this._textureViews[u.binding] = texture.getGFXTextureView()!; - this._samplers[u.binding] = samplerLib.getSampler(device, texture.getGFXSamplerInfo()); + const samplerInfo = texture.getGFXSamplerInfo(); + if (!this._samplers[u.binding] || samplerInfo.length) { this._samplers[u.binding] = samplerLib.getSampler(device, samplerInfo); } } else { console.warn('illegal texture default value ' + texName); } } diff --git a/cocos/renderer/core/sampler-lib.ts b/cocos/renderer/core/sampler-lib.ts index db37cac841..9c387618d9 100644 --- a/cocos/renderer/core/sampler-lib.ts +++ b/cocos/renderer/core/sampler-lib.ts @@ -3,6 +3,22 @@ import { GFXDevice } from '../../gfx/device'; import { GFXSampler, IGFXSamplerInfo } from '../../gfx/sampler'; +export enum SamplerInfoIndex { + minFilter, + magFilter, + mipFilter, + addressU, + addressV, + addressW, + maxAnisotropy, + cmpFunc, + minLOD, + maxLOD, + mipLODBias, + borderColor, + total = borderColor + 4, +} + const gfxInfo: IGFXSamplerInfo = {}; class SamplerLib { @@ -12,19 +28,22 @@ class SamplerLib { const hash = info.toString(); const cache = this._cache[hash]; if (cache) { return cache; } - gfxInfo.minFilter = info[0]; - gfxInfo.magFilter = info[1]; - gfxInfo.mipFilter = info[2]; - gfxInfo.addressU = info[3]; - gfxInfo.addressV = info[4]; - gfxInfo.addressW = info[5]; - gfxInfo.maxAnisotropy = info[6]; - if (info.length > 7) { - gfxInfo.cmpFunc = info[7]; - gfxInfo.borderColor = { r: info[8], g: info[9], b: info[10], a: info[11] }; - gfxInfo.minLOD = info[12]; - gfxInfo.maxLOD = info[13]; - gfxInfo.mipLODBias = info[14]; + gfxInfo.minFilter = info[SamplerInfoIndex.minFilter]; + gfxInfo.magFilter = info[SamplerInfoIndex.magFilter]; + gfxInfo.mipFilter = info[SamplerInfoIndex.mipFilter]; + gfxInfo.addressU = info[SamplerInfoIndex.addressU]; + gfxInfo.addressV = info[SamplerInfoIndex.addressV]; + gfxInfo.addressW = info[SamplerInfoIndex.addressW]; + gfxInfo.maxAnisotropy = info[SamplerInfoIndex.maxAnisotropy]; + if (info.length > SamplerInfoIndex.cmpFunc) { + gfxInfo.cmpFunc = info[SamplerInfoIndex.cmpFunc]; + gfxInfo.minLOD = info[SamplerInfoIndex.minLOD]; + gfxInfo.maxLOD = info[SamplerInfoIndex.maxLOD]; + gfxInfo.mipLODBias = info[SamplerInfoIndex.mipLODBias]; + if (info.length >= SamplerInfoIndex.total) { + const ofs = SamplerInfoIndex.borderColor; + gfxInfo.borderColor = { r: info[ofs], g: info[ofs + 1], b: info[ofs + 2], a: info[ofs + 3] }; + } } const sampler = this._cache[hash] = device.createSampler(gfxInfo); return sampler; @@ -32,4 +51,3 @@ class SamplerLib { } export const samplerLib = new SamplerLib(); -cc.samplerLib = samplerLib; diff --git a/cocos/renderer/index.ts b/cocos/renderer/index.ts index b1cd8bc636..7627fd7675 100644 --- a/cocos/renderer/index.ts +++ b/cocos/renderer/index.ts @@ -7,6 +7,10 @@ export { addStage }; export { RenderQueue, PassStage } from './core/constants'; export { Pass } from './core/pass'; export { Effect } from './core/effect'; +export { programLib } from './core/program-lib'; +import { samplerLib } from './core/sampler-lib'; +cc.samplerLib = samplerLib; +export { samplerLib }; export { Light } from './scene/light'; export { Camera } from './scene/camera'; diff --git a/cocos/renderer/scene/skybox.ts b/cocos/renderer/scene/skybox.ts index 87da09c4da..649fe8e08e 100644 --- a/cocos/renderer/scene/skybox.ts +++ b/cocos/renderer/scene/skybox.ts @@ -21,7 +21,7 @@ export class Skybox extends Model { if (val === this._isRGBE) { return; } this._isRGBE = val; this._material.destroy(); - this._material.initialize({ defines: { USE_RGBE_CUBEMAP: val } }); + this._initMaterial(); this.setSubModelMaterial(0, this._material); this._updateBindingLayout(); } @@ -33,18 +33,12 @@ export class Skybox extends Model { protected _cubemap = this._default; protected _isRGBE = false; - protected _material: Material; + protected _material = new Material(); constructor (scene: RenderScene) { super(scene, null); this._scene = scene; - - this._material = new Material(); - this._material.initialize({ - effectName: 'builtin-skybox', - defines: { USE_RGBE_CUBEMAP: this._isRGBE }, - }); - this._material.setProperty('cubeMap', this._cubemap); + this._initMaterial(); const mesh = createMesh(box({ width: 2, height: 2, length: 2 })); const subMeshData = mesh.renderingMesh!.getSubmesh(0)!; @@ -52,6 +46,14 @@ export class Skybox extends Model { this._updateBindingLayout(); } + protected _initMaterial () { + this._material.initialize({ + effectName: 'builtin-skybox', + defines: { USE_RGBE_CUBEMAP: this._isRGBE }, + }); + this._material.setProperty('cubeMap', this._cubemap); + } + protected _updateBindingLayout () { this._matPSORecord.get(this._material)![0].pipelineLayout.layouts[0].update(); }