mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 07:42:38 +08:00
ae9129668a
merge 3d-v1.0.0-terrain into 3d-v1.0.0
476 lines
141 KiB
TypeScript
476 lines
141 KiB
TypeScript
// tslint:disable
|
|
// absolute essential effects
|
|
export default [
|
|
{
|
|
"name": "builtin-billboard",
|
|
"techniques": [
|
|
{"name":"add", "passes":[{"rasterizerState":{"cullMode":0}, "blendState":{"targets":[{"blend":true, "blendSrc":2, "blendDst":1, "blendSrcAlpha":2, "blendDstAlpha":1}]}, "program":"builtin-billboard|vert:vs_main|tinted-fs:add", "depthStencilState":{"depthTest":true, "depthWrite":false}, "properties":{"mainTexture":{"value":"grey", "type":28}, "mainTiling_Offset":{"value":[1, 1, 0, 0], "type":16}, "tintColor":{"value":[0.5, 0.5, 0.5, 0.5], "inspector":{"type":"color"}, "type":16}}}]}
|
|
],
|
|
"shaders": [
|
|
{
|
|
"name": "builtin-billboard|vert:vs_main|tinted-fs:add",
|
|
"hash": 2865781192,
|
|
"glsl3": {
|
|
"vert": `\nprecision mediump float;\nuniform Constants {\n vec4 mainTiling_Offset;\n vec4 frameTile_velLenScale;\n vec4 scale;\n};\nuniform CCGlobal {\n vec4 cc_time;\n vec4 cc_screenSize;\n vec4 cc_screenScale;\n vec4 cc_nativeSize;\n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos;\n vec4 cc_exposure;\n vec4 cc_mainLitDir;\n vec4 cc_mainLitColor;\n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\nuniform CCLocal {\n highp mat4 cc_matWorld;\n mat4 cc_matWorldIT;\n};\nout vec2 uv;\nout vec4 color;\nvoid computeVertPos(inout vec4 pos, vec2 vertOffset, vec3 scale\n#if 1 || CC_USE_VERTICAL_BILLBOARD\n , mat4 view\n#endif\n#if CC_USE_STRETCHED_BILLBOARD\n , vec3 eye\n , vec4 velocity\n , float velocityScale\n , float lengthScale\n , float size\n , float xIndex\n#endif\n) {\n#if 1\n vec3 camRight = normalize(vec3(view[0][0], view[1][0], view[2][0]));\n vec3 camUp = normalize(vec3(view[0][1], view[1][1], view[2][1]));\n pos.xyz += ((camRight * vertOffset.x) + (camUp * vertOffset.y)) * scale;\n#elif CC_USE_STRETCHED_BILLBOARD\n vec3 camRight = normalize(cross(pos.xyz - eye, velocity.xyz));\n vec3 camUp = velocity.xyz * velocityScale + normalize(velocity.xyz) * lengthScale * size;\n pos.xyz += ((camRight * abs(vertOffset.x) * sign(vertOffset.y)) - camUp * xIndex) * scale;\n#elif CC_USE_HORIZONTAL_BILLBOARD\n vec3 camRight = vec3(1, 0, 0);\n vec3 camUp = vec3(0, 0, -1);\n pos.xyz += ((camRight * vertOffset.x) + (camUp * vertOffset.y)) * scale;\n#elif CC_USE_VERTICAL_BILLBOARD\n vec3 camRight = normalize(vec3(view[0][0], view[1][0], view[2][0]));\n vec3 camUp = vec3(0, 1, 0);\n pos.xyz += ((camRight * vertOffset.x) + (camUp * vertOffset.y)) * scale;\n#else\n pos.x += vertOffset.x;\n pos.y += vertOffset.y;\n#endif\n}\nvec2 computeUV(float frameIndex, vec2 vertIndex, vec2 frameTile) {\n vec2 aniUV = vec2(0, floor(frameIndex * frameTile.y));\n aniUV.x = floor(frameIndex * frameTile.x * frameTile.y - aniUV.y * frameTile.x);\n#if !CC_USE_MESH\n vertIndex.y = 1. - vertIndex.y;\n#endif\n return (aniUV.xy + vertIndex) / vec2(frameTile.x, frameTile.y);\n}\nvoid rotateCorner(inout vec2 corner, float angle) {\n float xOS = cos(angle) * corner.x - sin(angle) * corner.y;\n float yOS = sin(angle) * corner.x + cos(angle) * corner.y;\n corner.x = xOS;\n corner.y = yOS;\n}\nin vec3 a_position;\nin vec2 a_texCoord;\nin vec4 a_color;\nuniform builtin {\n vec4 cc_size_rotation;\n};\nvec4 vs_main() {\n vec4 pos = vec4(a_position, 1);\n pos = cc_matWorld * pos;\n vec2 vertOffset = (a_texCoord.xy - 0.5) * cc_size_rotation.xy;\n rotateCorner(vertOffset, cc_size_rotation.z);\n computeVertPos(pos, vertOffset, vec3(1,1,1), cc_matView);\n pos = cc_matViewProj * pos;\n uv = a_texCoord.xy;\n color = a_color;\n return pos;\n}\nvoid main() { gl_Position = vs_main(); }\n`,
|
|
"frag": `\nprecision mediump float;\nuniform CCGlobal {\n vec4 cc_time;\n vec4 cc_screenSize;\n vec4 cc_screenScale;\n vec4 cc_nativeSize;\n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos;\n vec4 cc_exposure;\n vec4 cc_mainLitDir;\n vec4 cc_mainLitColor;\n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\nvec3 SRGBToLinear(vec3 gamma)\n{\n return pow(gamma, vec3(2.2));\n}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\n}\nvec4 CCFragOutput(vec4 color) {\n #if CC_USE_HDR\n color.rgb = mix(color.rgb, SRGBToLinear(color.rgb) * cc_exposure.w, vec3(cc_exposure.z));\n #endif\n return color;\n}\nin vec2 uv;\nin vec4 color;\nuniform sampler2D mainTexture;\nuniform FragConstants {\n vec4 tintColor;\n};\nvec4 add () {\n vec4 col = 2.0 * color * tintColor * texture(mainTexture, uv);\n return CCFragOutput(col);\n}\nvec4 multiply () {\n vec4 col;\n vec4 texColor = texture(mainTexture, uv);\n col.rgb = tintColor.rgb * texColor.rgb * color.rgb * vec3(2.0);\n col.a = (1.0 - texColor.a) * (tintColor.a * color.a * 2.0);\n return CCFragOutput(col);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = add(); }\n`
|
|
},
|
|
"glsl1": {
|
|
"vert": `\nprecision mediump float;\nuniform vec4 scale;\nuniform mat4 cc_matView;\nuniform mat4 cc_matViewProj;\nuniform highp mat4 cc_matWorld;\nvarying vec2 uv;\nvarying vec4 color;\nvoid computeVertPos(inout vec4 pos, vec2 vertOffset, vec3 scale\n#if 1 || CC_USE_VERTICAL_BILLBOARD\n , mat4 view\n#endif\n#if CC_USE_STRETCHED_BILLBOARD\n , vec3 eye\n , vec4 velocity\n , float velocityScale\n , float lengthScale\n , float size\n , float xIndex\n#endif\n) {\n#if 1\n vec3 camRight = normalize(vec3(view[0][0], view[1][0], view[2][0]));\n vec3 camUp = normalize(vec3(view[0][1], view[1][1], view[2][1]));\n pos.xyz += ((camRight * vertOffset.x) + (camUp * vertOffset.y)) * scale;\n#elif CC_USE_STRETCHED_BILLBOARD\n vec3 camRight = normalize(cross(pos.xyz - eye, velocity.xyz));\n vec3 camUp = velocity.xyz * velocityScale + normalize(velocity.xyz) * lengthScale * size;\n pos.xyz += ((camRight * abs(vertOffset.x) * sign(vertOffset.y)) - camUp * xIndex) * scale;\n#elif CC_USE_HORIZONTAL_BILLBOARD\n vec3 camRight = vec3(1, 0, 0);\n vec3 camUp = vec3(0, 0, -1);\n pos.xyz += ((camRight * vertOffset.x) + (camUp * vertOffset.y)) * scale;\n#elif CC_USE_VERTICAL_BILLBOARD\n vec3 camRight = normalize(vec3(view[0][0], view[1][0], view[2][0]));\n vec3 camUp = vec3(0, 1, 0);\n pos.xyz += ((camRight * vertOffset.x) + (camUp * vertOffset.y)) * scale;\n#else\n pos.x += vertOffset.x;\n pos.y += vertOffset.y;\n#endif\n}\nvec2 computeUV(float frameIndex, vec2 vertIndex, vec2 frameTile) {\n vec2 aniUV = vec2(0, floor(frameIndex * frameTile.y));\n aniUV.x = floor(frameIndex * frameTile.x * frameTile.y - aniUV.y * frameTile.x);\n#if !CC_USE_MESH\n vertIndex.y = 1. - vertIndex.y;\n#endif\n return (aniUV.xy + vertIndex) / vec2(frameTile.x, frameTile.y);\n}\nvoid rotateCorner(inout vec2 corner, float angle) {\n float xOS = cos(angle) * corner.x - sin(angle) * corner.y;\n float yOS = sin(angle) * corner.x + cos(angle) * corner.y;\n corner.x = xOS;\n corner.y = yOS;\n}\nattribute vec3 a_position;\nattribute vec2 a_texCoord;\nattribute vec4 a_color;\nuniform vec4 cc_size_rotation;\nvec4 vs_main() {\n vec4 pos = vec4(a_position, 1);\n pos = cc_matWorld * pos;\n vec2 vertOffset = (a_texCoord.xy - 0.5) * cc_size_rotation.xy;\n rotateCorner(vertOffset, cc_size_rotation.z);\n computeVertPos(pos, vertOffset, vec3(1,1,1), cc_matView);\n pos = cc_matViewProj * pos;\n uv = a_texCoord.xy;\n color = a_color;\n return pos;\n}\nvoid main() { gl_Position = vs_main(); }\n`,
|
|
"frag": `\nprecision mediump float;\nuniform vec4 cc_exposure;\nvec3 SRGBToLinear(vec3 gamma)\n{\n return pow(gamma, vec3(2.2));\n}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\n}\nvec4 CCFragOutput(vec4 color) {\n #if CC_USE_HDR\n color.rgb = mix(color.rgb, SRGBToLinear(color.rgb) * cc_exposure.w, vec3(cc_exposure.z));\n #endif\n return color;\n}\nvarying vec2 uv;\nvarying vec4 color;\nuniform sampler2D mainTexture;\nuniform vec4 tintColor;\nvec4 add () {\n vec4 col = 2.0 * color * tintColor * texture2D(mainTexture, uv);\n return CCFragOutput(col);\n}\nvec4 multiply () {\n vec4 col;\n vec4 texColor = texture2D(mainTexture, uv);\n col.rgb = tintColor.rgb * texColor.rgb * color.rgb * vec3(2.0);\n col.a = (1.0 - texColor.a) * (tintColor.a * color.a * 2.0);\n return CCFragOutput(col);\n}\nvoid main() { gl_FragColor = add(); }\n`
|
|
},
|
|
"builtins": {"globals":{"blocks":[{"name":"CCGlobal", "defines":[]}], "samplers":[]}, "locals":{"blocks":[{"name":"CCLocal", "defines":[]}], "samplers":[]}},
|
|
"defines": [
|
|
{"name":"CC_USE_STRETCHED_BILLBOARD", "type":"boolean", "defines":[]},
|
|
{"name":"CC_USE_HORIZONTAL_BILLBOARD", "type":"boolean", "defines":[]},
|
|
{"name":"CC_USE_VERTICAL_BILLBOARD", "type":"boolean", "defines":[]},
|
|
{"name":"CC_USE_MESH", "type":"boolean", "defines":[]},
|
|
{"name":"CC_USE_HDR", "type":"boolean", "defines":[]}
|
|
],
|
|
"blocks": [
|
|
{"name": "Constants", "defines": [], "binding": 0, "members": [
|
|
{"name":"mainTiling_Offset", "type":16, "count":1},
|
|
{"name":"frameTile_velLenScale", "type":16, "count":1},
|
|
{"name":"scale", "type":16, "count":1}
|
|
]},
|
|
{"name": "builtin", "defines": [], "binding": 1, "members": [
|
|
{"name":"cc_size_rotation", "type":16, "count":1}
|
|
]},
|
|
{"name": "FragConstants", "defines": [], "binding": 2, "members": [
|
|
{"name":"tintColor", "type":16, "count":1}
|
|
]}
|
|
],
|
|
"samplers": [
|
|
{"name":"mainTexture", "type":28, "count":1, "defines":[], "binding":30}
|
|
],
|
|
"dependencies": {}
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"name": "builtin-particle-trail",
|
|
"techniques": [
|
|
{"name":"add", "passes":[{"rasterizerState":{"cullMode":0}, "blendState":{"targets":[{"blend":true, "blendSrc":2, "blendDst":1, "blendSrcAlpha":2, "blendDstAlpha":1}]}, "program":"builtin-particle-trail|particle-trail:vs_main|tinted-fs:add", "depthStencilState":{"depthTest":true, "depthWrite":false}, "properties":{"mainTexture":{"value":"grey", "type":28}, "mainTiling_Offset":{"value":[1, 1, 0, 0], "type":16}, "frameTile_velLenScale":{"value":[1, 1, 0, 0], "type":16}, "tintColor":{"value":[0.5, 0.5, 0.5, 0.5], "inspector":{"type":"color"}, "type":16}}}]}
|
|
],
|
|
"shaders": [
|
|
{
|
|
"name": "builtin-particle-trail|particle-trail:vs_main|tinted-fs:add",
|
|
"hash": 1171919216,
|
|
"glsl3": {
|
|
"vert": `\nprecision mediump float;\nuniform Constants {\n vec4 mainTiling_Offset;\n vec4 frameTile_velLenScale;\n vec4 scale;\n};\nuniform CCGlobal {\n vec4 cc_time;\n vec4 cc_screenSize;\n vec4 cc_screenScale;\n vec4 cc_nativeSize;\n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos;\n vec4 cc_exposure;\n vec4 cc_mainLitDir;\n vec4 cc_mainLitColor;\n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\nuniform CCLocal {\n highp mat4 cc_matWorld;\n mat4 cc_matWorldIT;\n};\nout vec2 uv;\nout vec4 color;\nvoid computeVertPos(inout vec4 pos, vec2 vertOffset, vec3 scale\n#if CC_USE_BILLBOARD || CC_USE_VERTICAL_BILLBOARD\n , mat4 view\n#endif\n#if CC_USE_STRETCHED_BILLBOARD\n , vec3 eye\n , vec4 velocity\n , float velocityScale\n , float lengthScale\n , float size\n , float xIndex\n#endif\n) {\n#if CC_USE_BILLBOARD\n vec3 camRight = normalize(vec3(view[0][0], view[1][0], view[2][0]));\n vec3 camUp = normalize(vec3(view[0][1], view[1][1], view[2][1]));\n pos.xyz += ((camRight * vertOffset.x) + (camUp * vertOffset.y)) * scale;\n#elif CC_USE_STRETCHED_BILLBOARD\n vec3 camRight = normalize(cross(pos.xyz - eye, velocity.xyz));\n vec3 camUp = velocity.xyz * velocityScale + normalize(velocity.xyz) * lengthScale * size;\n pos.xyz += ((camRight * abs(vertOffset.x) * sign(vertOffset.y)) - camUp * xIndex) * scale;\n#elif CC_USE_HORIZONTAL_BILLBOARD\n vec3 camRight = vec3(1, 0, 0);\n vec3 camUp = vec3(0, 0, -1);\n pos.xyz += ((camRight * vertOffset.x) + (camUp * vertOffset.y)) * scale;\n#elif CC_USE_VERTICAL_BILLBOARD\n vec3 camRight = normalize(vec3(view[0][0], view[1][0], view[2][0]));\n vec3 camUp = vec3(0, 1, 0);\n pos.xyz += ((camRight * vertOffset.x) + (camUp * vertOffset.y)) * scale;\n#else\n pos.x += vertOffset.x;\n pos.y += vertOffset.y;\n#endif\n}\nvec2 computeUV(float frameIndex, vec2 vertIndex, vec2 frameTile) {\n vec2 aniUV = vec2(0, floor(frameIndex * frameTile.y));\n aniUV.x = floor(frameIndex * frameTile.x * frameTile.y - aniUV.y * frameTile.x);\n#if !CC_USE_MESH\n vertIndex.y = 1. - vertIndex.y;\n#endif\n return (aniUV.xy + vertIndex) / vec2(frameTile.x, frameTile.y);\n}\nvoid rotateCorner(inout vec2 corner, float angle) {\n float xOS = cos(angle) * corner.x - sin(angle) * corner.y;\n float yOS = sin(angle) * corner.x + cos(angle) * corner.y;\n corner.x = xOS;\n corner.y = yOS;\n}\nin vec3 a_position;\nin vec4 a_texCoord;\nin vec3 a_texCoord1;\nin vec4 a_color;\nvec4 vs_main() {\n highp vec4 pos = vec4(a_position, 1);\n vec4 velocity = vec4(a_texCoord1.xyz, 0);\n #if !CC_USE_WORLD_SPACE\n pos = cc_matWorld * pos;\n velocity = cc_matWorld * velocity;\n #endif\n float vertOffset = (a_texCoord.x - 0.5) * a_texCoord.y;\n vec3 camUp = normalize(cross(pos.xyz - cc_cameraPos.xyz, velocity.xyz));\n pos.xyz += camUp * vertOffset;\n pos = cc_matViewProj * pos;\n uv = a_texCoord.zw * mainTiling_Offset.xy + mainTiling_Offset.zw;;\n color = a_color;\n return pos;\n}\nvoid main() { gl_Position = vs_main(); }\n`,
|
|
"frag": `\nprecision mediump float;\nuniform CCGlobal {\n vec4 cc_time;\n vec4 cc_screenSize;\n vec4 cc_screenScale;\n vec4 cc_nativeSize;\n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos;\n vec4 cc_exposure;\n vec4 cc_mainLitDir;\n vec4 cc_mainLitColor;\n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\nvec3 SRGBToLinear(vec3 gamma)\n{\n return pow(gamma, vec3(2.2));\n}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\n}\nvec4 CCFragOutput(vec4 color) {\n #if CC_USE_HDR\n color.rgb = mix(color.rgb, SRGBToLinear(color.rgb) * cc_exposure.w, vec3(cc_exposure.z));\n #endif\n return color;\n}\nin vec2 uv;\nin vec4 color;\nuniform sampler2D mainTexture;\nuniform FragConstants {\n vec4 tintColor;\n};\nvec4 add () {\n vec4 col = 2.0 * color * tintColor * texture(mainTexture, uv);\n return CCFragOutput(col);\n}\nvec4 multiply () {\n vec4 col;\n vec4 texColor = texture(mainTexture, uv);\n col.rgb = tintColor.rgb * texColor.rgb * color.rgb * vec3(2.0);\n col.a = (1.0 - texColor.a) * (tintColor.a * color.a * 2.0);\n return CCFragOutput(col);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = add(); }\n`
|
|
},
|
|
"glsl1": {
|
|
"vert": `\nprecision mediump float;\nuniform vec4 mainTiling_Offset;\nuniform vec4 scale;\nuniform mat4 cc_matViewProj;\nuniform vec4 cc_cameraPos;\nuniform highp mat4 cc_matWorld;\nvarying vec2 uv;\nvarying vec4 color;\nvoid computeVertPos(inout vec4 pos, vec2 vertOffset, vec3 scale\n#if CC_USE_BILLBOARD || CC_USE_VERTICAL_BILLBOARD\n , mat4 view\n#endif\n#if CC_USE_STRETCHED_BILLBOARD\n , vec3 eye\n , vec4 velocity\n , float velocityScale\n , float lengthScale\n , float size\n , float xIndex\n#endif\n) {\n#if CC_USE_BILLBOARD\n vec3 camRight = normalize(vec3(view[0][0], view[1][0], view[2][0]));\n vec3 camUp = normalize(vec3(view[0][1], view[1][1], view[2][1]));\n pos.xyz += ((camRight * vertOffset.x) + (camUp * vertOffset.y)) * scale;\n#elif CC_USE_STRETCHED_BILLBOARD\n vec3 camRight = normalize(cross(pos.xyz - eye, velocity.xyz));\n vec3 camUp = velocity.xyz * velocityScale + normalize(velocity.xyz) * lengthScale * size;\n pos.xyz += ((camRight * abs(vertOffset.x) * sign(vertOffset.y)) - camUp * xIndex) * scale;\n#elif CC_USE_HORIZONTAL_BILLBOARD\n vec3 camRight = vec3(1, 0, 0);\n vec3 camUp = vec3(0, 0, -1);\n pos.xyz += ((camRight * vertOffset.x) + (camUp * vertOffset.y)) * scale;\n#elif CC_USE_VERTICAL_BILLBOARD\n vec3 camRight = normalize(vec3(view[0][0], view[1][0], view[2][0]));\n vec3 camUp = vec3(0, 1, 0);\n pos.xyz += ((camRight * vertOffset.x) + (camUp * vertOffset.y)) * scale;\n#else\n pos.x += vertOffset.x;\n pos.y += vertOffset.y;\n#endif\n}\nvec2 computeUV(float frameIndex, vec2 vertIndex, vec2 frameTile) {\n vec2 aniUV = vec2(0, floor(frameIndex * frameTile.y));\n aniUV.x = floor(frameIndex * frameTile.x * frameTile.y - aniUV.y * frameTile.x);\n#if !CC_USE_MESH\n vertIndex.y = 1. - vertIndex.y;\n#endif\n return (aniUV.xy + vertIndex) / vec2(frameTile.x, frameTile.y);\n}\nvoid rotateCorner(inout vec2 corner, float angle) {\n float xOS = cos(angle) * corner.x - sin(angle) * corner.y;\n float yOS = sin(angle) * corner.x + cos(angle) * corner.y;\n corner.x = xOS;\n corner.y = yOS;\n}\nattribute vec3 a_position;\nattribute vec4 a_texCoord;\nattribute vec3 a_texCoord1;\nattribute vec4 a_color;\nvec4 vs_main() {\n highp vec4 pos = vec4(a_position, 1);\n vec4 velocity = vec4(a_texCoord1.xyz, 0);\n #if !CC_USE_WORLD_SPACE\n pos = cc_matWorld * pos;\n velocity = cc_matWorld * velocity;\n #endif\n float vertOffset = (a_texCoord.x - 0.5) * a_texCoord.y;\n vec3 camUp = normalize(cross(pos.xyz - cc_cameraPos.xyz, velocity.xyz));\n pos.xyz += camUp * vertOffset;\n pos = cc_matViewProj * pos;\n uv = a_texCoord.zw * mainTiling_Offset.xy + mainTiling_Offset.zw;;\n color = a_color;\n return pos;\n}\nvoid main() { gl_Position = vs_main(); }\n`,
|
|
"frag": `\nprecision mediump float;\nuniform vec4 cc_exposure;\nvec3 SRGBToLinear(vec3 gamma)\n{\n return pow(gamma, vec3(2.2));\n}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\n}\nvec4 CCFragOutput(vec4 color) {\n #if CC_USE_HDR\n color.rgb = mix(color.rgb, SRGBToLinear(color.rgb) * cc_exposure.w, vec3(cc_exposure.z));\n #endif\n return color;\n}\nvarying vec2 uv;\nvarying vec4 color;\nuniform sampler2D mainTexture;\nuniform vec4 tintColor;\nvec4 add () {\n vec4 col = 2.0 * color * tintColor * texture2D(mainTexture, uv);\n return CCFragOutput(col);\n}\nvec4 multiply () {\n vec4 col;\n vec4 texColor = texture2D(mainTexture, uv);\n col.rgb = tintColor.rgb * texColor.rgb * color.rgb * vec3(2.0);\n col.a = (1.0 - texColor.a) * (tintColor.a * color.a * 2.0);\n return CCFragOutput(col);\n}\nvoid main() { gl_FragColor = add(); }\n`
|
|
},
|
|
"builtins": {"globals":{"blocks":[{"name":"CCGlobal", "defines":[]}], "samplers":[]}, "locals":{"blocks":[{"name":"CCLocal", "defines":[]}], "samplers":[]}},
|
|
"defines": [
|
|
{"name":"CC_USE_BILLBOARD", "type":"boolean", "defines":[]},
|
|
{"name":"CC_USE_STRETCHED_BILLBOARD", "type":"boolean", "defines":[]},
|
|
{"name":"CC_USE_HORIZONTAL_BILLBOARD", "type":"boolean", "defines":[]},
|
|
{"name":"CC_USE_VERTICAL_BILLBOARD", "type":"boolean", "defines":[]},
|
|
{"name":"CC_USE_MESH", "type":"boolean", "defines":[]},
|
|
{"name":"CC_USE_WORLD_SPACE", "type":"boolean", "defines":[]},
|
|
{"name":"CC_USE_HDR", "type":"boolean", "defines":[]}
|
|
],
|
|
"blocks": [
|
|
{"name": "Constants", "defines": [], "binding": 0, "members": [
|
|
{"name":"mainTiling_Offset", "type":16, "count":1},
|
|
{"name":"frameTile_velLenScale", "type":16, "count":1},
|
|
{"name":"scale", "type":16, "count":1}
|
|
]},
|
|
{"name": "FragConstants", "defines": [], "binding": 1, "members": [
|
|
{"name":"tintColor", "type":16, "count":1}
|
|
]}
|
|
],
|
|
"samplers": [
|
|
{"name":"mainTexture", "type":28, "count":1, "defines":[], "binding":30}
|
|
],
|
|
"dependencies": {}
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"name": "builtin-particle",
|
|
"techniques": [
|
|
{"name":"add", "passes":[{"rasterizerState":{"cullMode":0}, "blendState":{"targets":[{"blend":true, "blendSrc":2, "blendDst":1, "blendSrcAlpha":2, "blendDstAlpha":1}]}, "program":"builtin-particle|particle-vs-legacy:lpvs_main|tinted-fs:add", "depthStencilState":{"depthTest":true, "depthWrite":false}, "properties":{"mainTexture":{"value":"grey", "type":28}, "mainTiling_Offset":{"value":[1, 1, 0, 0], "type":16}, "frameTile_velLenScale":{"value":[1, 1, 0, 0], "type":16}, "tintColor":{"value":[0.5, 0.5, 0.5, 0.5], "inspector":{"type":"color"}, "type":16}}}]}
|
|
],
|
|
"shaders": [
|
|
{
|
|
"name": "builtin-particle|particle-vs-legacy:lpvs_main|tinted-fs:add",
|
|
"hash": 2725599499,
|
|
"glsl3": {
|
|
"vert": `\nprecision highp float;\nuniform Constants {\n vec4 mainTiling_Offset;\n vec4 frameTile_velLenScale;\n vec4 scale;\n};\nuniform CCGlobal {\n vec4 cc_time;\n vec4 cc_screenSize;\n vec4 cc_screenScale;\n vec4 cc_nativeSize;\n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos;\n vec4 cc_exposure;\n vec4 cc_mainLitDir;\n vec4 cc_mainLitColor;\n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\nuniform CCLocal {\n highp mat4 cc_matWorld;\n mat4 cc_matWorldIT;\n};\nout vec2 uv;\nout vec4 color;\nvoid computeVertPos(inout vec4 pos, vec2 vertOffset, vec3 scale\n#if CC_USE_BILLBOARD || CC_USE_VERTICAL_BILLBOARD\n , mat4 view\n#endif\n#if CC_USE_STRETCHED_BILLBOARD\n , vec3 eye\n , vec4 velocity\n , float velocityScale\n , float lengthScale\n , float size\n , float xIndex\n#endif\n) {\n#if CC_USE_BILLBOARD\n vec3 camRight = normalize(vec3(view[0][0], view[1][0], view[2][0]));\n vec3 camUp = normalize(vec3(view[0][1], view[1][1], view[2][1]));\n pos.xyz += ((camRight * vertOffset.x) + (camUp * vertOffset.y)) * scale;\n#elif CC_USE_STRETCHED_BILLBOARD\n vec3 camRight = normalize(cross(pos.xyz - eye, velocity.xyz));\n vec3 camUp = velocity.xyz * velocityScale + normalize(velocity.xyz) * lengthScale * size;\n pos.xyz += ((camRight * abs(vertOffset.x) * sign(vertOffset.y)) - camUp * xIndex) * scale;\n#elif CC_USE_HORIZONTAL_BILLBOARD\n vec3 camRight = vec3(1, 0, 0);\n vec3 camUp = vec3(0, 0, -1);\n pos.xyz += ((camRight * vertOffset.x) + (camUp * vertOffset.y)) * scale;\n#elif CC_USE_VERTICAL_BILLBOARD\n vec3 camRight = normalize(vec3(view[0][0], view[1][0], view[2][0]));\n vec3 camUp = vec3(0, 1, 0);\n pos.xyz += ((camRight * vertOffset.x) + (camUp * vertOffset.y)) * scale;\n#else\n pos.x += vertOffset.x;\n pos.y += vertOffset.y;\n#endif\n}\nvec2 computeUV(float frameIndex, vec2 vertIndex, vec2 frameTile) {\n vec2 aniUV = vec2(0, floor(frameIndex * frameTile.y));\n aniUV.x = floor(frameIndex * frameTile.x * frameTile.y - aniUV.y * frameTile.x);\n#if !CC_USE_MESH\n vertIndex.y = 1. - vertIndex.y;\n#endif\n return (aniUV.xy + vertIndex) / vec2(frameTile.x, frameTile.y);\n}\nvoid rotateCorner(inout vec2 corner, float angle) {\n float xOS = cos(angle) * corner.x - sin(angle) * corner.y;\n float yOS = sin(angle) * corner.x + cos(angle) * corner.y;\n corner.x = xOS;\n corner.y = yOS;\n}\nvec4 quaternionFromAxisAngle(float angle, vec3 axis){\n angle /= 2.;\n float s = sin(angle);\n vec4 res;\n res.xyz = s * axis;\n res.w = cos(angle);\n return res;\n}\nmat4 matrixFromRT(vec4 q, vec3 p){\n float x2 = q.x + q.x;\n float y2 = q.y + q.y;\n float z2 = q.z + q.z;\n float xx = q.x * x2;\n float xy = q.x * y2;\n float xz = q.x * z2;\n float yy = q.y * y2;\n float yz = q.y * z2;\n float zz = q.z * z2;\n float wx = q.w * x2;\n float wy = q.w * y2;\n float wz = q.w * z2;\n return mat4(\n 1. - (yy + zz), xy + wz, xz - wy, 0,\n xy - wz, 1. - (xx + zz), yz + wx, 0,\n xz + wy, yz - wx, 1. - (xx + yy), 0,\n p.x, p.y, p.z, 1\n );\n}\nvoid scaleMatrix(inout mat4 m, float s){\n m[0].xyz *= s;\n m[1].xyz *= s;\n m[2].xyz *= s;\n}\nin vec3 a_position;\nin vec3 a_texCoord;\nin vec2 a_texCoord1;\nin vec4 a_color;\n#if CC_USE_STRETCHED_BILLBOARD\n in vec3 a_color1;\n#endif\n#if CC_USE_MESH\n in vec3 a_texCoord2;\n in vec3 a_normal;\n in vec4 a_color1;\n#endif\nvec4 lpvs_main() {\n #if CC_USE_MESH\n vec4 pos = vec4(a_texCoord2, 1);\n mat4 xformNoScale = matrixFromRT(quaternionFromAxisAngle(a_texCoord1.y, vec3(0, 0, -1)), a_position);\n mat4 xform = mat4(xformNoScale);\n scaleMatrix(xform, a_texCoord1.x);\n pos = xform * pos;\n vec4 normal = xformNoScale * vec4(a_normal,0);\n #else\n vec4 pos = vec4(a_position, 1);\n #if CC_USE_STRETCHED_BILLBOARD\n vec4 velocity = vec4(a_color1.xyz, 0);\n #endif\n #endif\n #if !CC_USE_WORLD_SPACE\n pos = cc_matWorld * pos;\n #if CC_USE_STRETCHED_BILLBOARD\n velocity = cc_matWorld * velocity;\n #endif\n #endif\n #if !CC_USE_MESH\n vec2 cornerOffset = vec2((a_texCoord.xy - 0.5) * a_texCoord1.x);\n #if !CC_USE_STRETCHED_BILLBOARD\n rotateCorner(cornerOffset, a_texCoord1.y);\n #endif\n computeVertPos(pos, cornerOffset, vec3(scale)\n #if CC_USE_BILLBOARD || CC_USE_VERTICAL_BILLBOARD\n , cc_matView\n #endif\n #if CC_USE_STRETCHED_BILLBOARD\n , cc_cameraPos.xyz\n , velocity\n , frameTile_velLenScale.z\n , frameTile_velLenScale.w\n , a_texCoord1.x\n , a_texCoord.x\n #endif\n );\n color = a_color;\n #else\n color = a_color * a_color1;\n #endif\n uv = computeUV(a_texCoord.z, a_texCoord.xy, frameTile_velLenScale.xy) * mainTiling_Offset.xy + mainTiling_Offset.zw;\n pos = cc_matViewProj * pos;\n return pos;\n}\nvoid main() { gl_Position = lpvs_main(); }\n`,
|
|
"frag": `\nprecision highp float;\nuniform CCGlobal {\n vec4 cc_time;\n vec4 cc_screenSize;\n vec4 cc_screenScale;\n vec4 cc_nativeSize;\n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos;\n vec4 cc_exposure;\n vec4 cc_mainLitDir;\n vec4 cc_mainLitColor;\n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\nvec3 SRGBToLinear(vec3 gamma)\n{\n return pow(gamma, vec3(2.2));\n}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\n}\nvec4 CCFragOutput(vec4 color) {\n #if CC_USE_HDR\n color.rgb = mix(color.rgb, SRGBToLinear(color.rgb) * cc_exposure.w, vec3(cc_exposure.z));\n #endif\n return color;\n}\nin vec2 uv;\nin vec4 color;\nuniform sampler2D mainTexture;\nuniform FragConstants {\n vec4 tintColor;\n};\nvec4 add () {\n vec4 col = 2.0 * color * tintColor * texture(mainTexture, uv);\n return CCFragOutput(col);\n}\nvec4 multiply () {\n vec4 col;\n vec4 texColor = texture(mainTexture, uv);\n col.rgb = tintColor.rgb * texColor.rgb * color.rgb * vec3(2.0);\n col.a = (1.0 - texColor.a) * (tintColor.a * color.a * 2.0);\n return CCFragOutput(col);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = add(); }\n`
|
|
},
|
|
"glsl1": {
|
|
"vert": `\nprecision highp float;\nuniform vec4 mainTiling_Offset;\nuniform vec4 frameTile_velLenScale;\nuniform vec4 scale;\nuniform mat4 cc_matView;\nuniform mat4 cc_matViewProj;\nuniform vec4 cc_cameraPos;\nuniform highp mat4 cc_matWorld;\nvarying vec2 uv;\nvarying vec4 color;\nvoid computeVertPos(inout vec4 pos, vec2 vertOffset, vec3 scale\n#if CC_USE_BILLBOARD || CC_USE_VERTICAL_BILLBOARD\n , mat4 view\n#endif\n#if CC_USE_STRETCHED_BILLBOARD\n , vec3 eye\n , vec4 velocity\n , float velocityScale\n , float lengthScale\n , float size\n , float xIndex\n#endif\n) {\n#if CC_USE_BILLBOARD\n vec3 camRight = normalize(vec3(view[0][0], view[1][0], view[2][0]));\n vec3 camUp = normalize(vec3(view[0][1], view[1][1], view[2][1]));\n pos.xyz += ((camRight * vertOffset.x) + (camUp * vertOffset.y)) * scale;\n#elif CC_USE_STRETCHED_BILLBOARD\n vec3 camRight = normalize(cross(pos.xyz - eye, velocity.xyz));\n vec3 camUp = velocity.xyz * velocityScale + normalize(velocity.xyz) * lengthScale * size;\n pos.xyz += ((camRight * abs(vertOffset.x) * sign(vertOffset.y)) - camUp * xIndex) * scale;\n#elif CC_USE_HORIZONTAL_BILLBOARD\n vec3 camRight = vec3(1, 0, 0);\n vec3 camUp = vec3(0, 0, -1);\n pos.xyz += ((camRight * vertOffset.x) + (camUp * vertOffset.y)) * scale;\n#elif CC_USE_VERTICAL_BILLBOARD\n vec3 camRight = normalize(vec3(view[0][0], view[1][0], view[2][0]));\n vec3 camUp = vec3(0, 1, 0);\n pos.xyz += ((camRight * vertOffset.x) + (camUp * vertOffset.y)) * scale;\n#else\n pos.x += vertOffset.x;\n pos.y += vertOffset.y;\n#endif\n}\nvec2 computeUV(float frameIndex, vec2 vertIndex, vec2 frameTile) {\n vec2 aniUV = vec2(0, floor(frameIndex * frameTile.y));\n aniUV.x = floor(frameIndex * frameTile.x * frameTile.y - aniUV.y * frameTile.x);\n#if !CC_USE_MESH\n vertIndex.y = 1. - vertIndex.y;\n#endif\n return (aniUV.xy + vertIndex) / vec2(frameTile.x, frameTile.y);\n}\nvoid rotateCorner(inout vec2 corner, float angle) {\n float xOS = cos(angle) * corner.x - sin(angle) * corner.y;\n float yOS = sin(angle) * corner.x + cos(angle) * corner.y;\n corner.x = xOS;\n corner.y = yOS;\n}\nvec4 quaternionFromAxisAngle(float angle, vec3 axis){\n angle /= 2.;\n float s = sin(angle);\n vec4 res;\n res.xyz = s * axis;\n res.w = cos(angle);\n return res;\n}\nmat4 matrixFromRT(vec4 q, vec3 p){\n float x2 = q.x + q.x;\n float y2 = q.y + q.y;\n float z2 = q.z + q.z;\n float xx = q.x * x2;\n float xy = q.x * y2;\n float xz = q.x * z2;\n float yy = q.y * y2;\n float yz = q.y * z2;\n float zz = q.z * z2;\n float wx = q.w * x2;\n float wy = q.w * y2;\n float wz = q.w * z2;\n return mat4(\n 1. - (yy + zz), xy + wz, xz - wy, 0,\n xy - wz, 1. - (xx + zz), yz + wx, 0,\n xz + wy, yz - wx, 1. - (xx + yy), 0,\n p.x, p.y, p.z, 1\n );\n}\nvoid scaleMatrix(inout mat4 m, float s){\n m[0].xyz *= s;\n m[1].xyz *= s;\n m[2].xyz *= s;\n}\nattribute vec3 a_position;\nattribute vec3 a_texCoord;\nattribute vec2 a_texCoord1;\nattribute vec4 a_color;\n#if CC_USE_STRETCHED_BILLBOARD\n attribute vec3 a_color1;\n#endif\n#if CC_USE_MESH\n attribute vec3 a_texCoord2;\n attribute vec3 a_normal;\n attribute vec4 a_color1;\n#endif\nvec4 lpvs_main() {\n #if CC_USE_MESH\n vec4 pos = vec4(a_texCoord2, 1);\n mat4 xformNoScale = matrixFromRT(quaternionFromAxisAngle(a_texCoord1.y, vec3(0, 0, -1)), a_position);\n mat4 xform = mat4(xformNoScale);\n scaleMatrix(xform, a_texCoord1.x);\n pos = xform * pos;\n vec4 normal = xformNoScale * vec4(a_normal,0);\n #else\n vec4 pos = vec4(a_position, 1);\n #if CC_USE_STRETCHED_BILLBOARD\n vec4 velocity = vec4(a_color1.xyz, 0);\n #endif\n #endif\n #if !CC_USE_WORLD_SPACE\n pos = cc_matWorld * pos;\n #if CC_USE_STRETCHED_BILLBOARD\n velocity = cc_matWorld * velocity;\n #endif\n #endif\n #if !CC_USE_MESH\n vec2 cornerOffset = vec2((a_texCoord.xy - 0.5) * a_texCoord1.x);\n #if !CC_USE_STRETCHED_BILLBOARD\n rotateCorner(cornerOffset, a_texCoord1.y);\n #endif\n computeVertPos(pos, cornerOffset, vec3(scale)\n #if CC_USE_BILLBOARD || CC_USE_VERTICAL_BILLBOARD\n , cc_matView\n #endif\n #if CC_USE_STRETCHED_BILLBOARD\n , cc_cameraPos.xyz\n , velocity\n , frameTile_velLenScale.z\n , frameTile_velLenScale.w\n , a_texCoord1.x\n , a_texCoord.x\n #endif\n );\n color = a_color;\n #else\n color = a_color * a_color1;\n #endif\n uv = computeUV(a_texCoord.z, a_texCoord.xy, frameTile_velLenScale.xy) * mainTiling_Offset.xy + mainTiling_Offset.zw;\n pos = cc_matViewProj * pos;\n return pos;\n}\nvoid main() { gl_Position = lpvs_main(); }\n`,
|
|
"frag": `\nprecision highp float;\nuniform vec4 cc_exposure;\nvec3 SRGBToLinear(vec3 gamma)\n{\n return pow(gamma, vec3(2.2));\n}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\n}\nvec4 CCFragOutput(vec4 color) {\n #if CC_USE_HDR\n color.rgb = mix(color.rgb, SRGBToLinear(color.rgb) * cc_exposure.w, vec3(cc_exposure.z));\n #endif\n return color;\n}\nvarying vec2 uv;\nvarying vec4 color;\nuniform sampler2D mainTexture;\nuniform vec4 tintColor;\nvec4 add () {\n vec4 col = 2.0 * color * tintColor * texture2D(mainTexture, uv);\n return CCFragOutput(col);\n}\nvec4 multiply () {\n vec4 col;\n vec4 texColor = texture2D(mainTexture, uv);\n col.rgb = tintColor.rgb * texColor.rgb * color.rgb * vec3(2.0);\n col.a = (1.0 - texColor.a) * (tintColor.a * color.a * 2.0);\n return CCFragOutput(col);\n}\nvoid main() { gl_FragColor = add(); }\n`
|
|
},
|
|
"builtins": {"globals":{"blocks":[{"name":"CCGlobal", "defines":[]}], "samplers":[]}, "locals":{"blocks":[{"name":"CCLocal", "defines":[]}], "samplers":[]}},
|
|
"defines": [
|
|
{"name":"CC_USE_BILLBOARD", "type":"boolean", "defines":[]},
|
|
{"name":"CC_USE_STRETCHED_BILLBOARD", "type":"boolean", "defines":[]},
|
|
{"name":"CC_USE_HORIZONTAL_BILLBOARD", "type":"boolean", "defines":[]},
|
|
{"name":"CC_USE_VERTICAL_BILLBOARD", "type":"boolean", "defines":[]},
|
|
{"name":"CC_USE_MESH", "type":"boolean", "defines":[]},
|
|
{"name":"CC_USE_WORLD_SPACE", "type":"boolean", "defines":[]},
|
|
{"name":"CC_USE_HDR", "type":"boolean", "defines":[]}
|
|
],
|
|
"blocks": [
|
|
{"name": "Constants", "defines": [], "binding": 0, "members": [
|
|
{"name":"mainTiling_Offset", "type":16, "count":1},
|
|
{"name":"frameTile_velLenScale", "type":16, "count":1},
|
|
{"name":"scale", "type":16, "count":1}
|
|
]},
|
|
{"name": "FragConstants", "defines": [], "binding": 1, "members": [
|
|
{"name":"tintColor", "type":16, "count":1}
|
|
]}
|
|
],
|
|
"samplers": [
|
|
{"name":"mainTexture", "type":28, "count":1, "defines":[], "binding":30}
|
|
],
|
|
"dependencies": {}
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"name": "builtin-skybox",
|
|
"techniques": [
|
|
{"passes":[{"rasterizerState":{"cullMode":0}, "program":"builtin-skybox|sky-vs:vert|sky-fs:frag", "priority":245, "depthStencilState":{"depthTest":true, "depthWrite":false}}]}
|
|
],
|
|
"shaders": [
|
|
{
|
|
"name": "builtin-skybox|sky-vs:vert|sky-fs:frag",
|
|
"hash": 1980673445,
|
|
"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;\nvoid CCDecode (out vec3 position) {\n position = a_position;\n}\n#if CC_USE_SKINNING\nstruct StandardAttributes {\n vec3 position;\n vec3 normal;\n vec4 tangent;\n};\nin vec4 a_weights;\nin vec4 a_joints;\nuniform CCSkinningTexture {\n highp vec4 cc_jointsTextureInfo;\n};\nuniform sampler2D cc_jointsTexture;\n#if CC_USE_SKINNING == 1\n highp float decode32(highp vec4 rgba) {\n rgba = rgba * 255.0;\n highp float Sign = 1.0 - step(128.0, rgba[3]) * 2.0;\n highp float Exponent = 2.0 * mod(rgba[3], 128.0) + step(128.0, rgba[2]) - 127.0;\n highp float Mantissa = mod(rgba[2], 128.0) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\n }\n#endif\n#if CC_USE_SKINNING == 1\n void getJointDQ(float i, out vec4 Qr, out vec4 Qt, out vec3 S) {\n highp float j = 12.0 * (cc_jointsTextureInfo.z * i + cc_jointsTextureInfo.w) + cc_jointsTextureInfo.y;\n highp float invSize = 1.0 / cc_jointsTextureInfo.x;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointsTextureInfo.x;\n y = (y + 0.5) * invSize;\n Qr = vec4(\n decode32(texture(cc_jointsTexture, vec2((x + 0.5) * invSize, y))),\n decode32(texture(cc_jointsTexture, vec2((x + 1.5) * invSize, y))),\n decode32(texture(cc_jointsTexture, vec2((x + 2.5) * invSize, y))),\n decode32(texture(cc_jointsTexture, vec2((x + 3.5) * invSize, y)))\n );\n Qt = vec4(\n decode32(texture(cc_jointsTexture, vec2((x + 4.5) * invSize, y))),\n decode32(texture(cc_jointsTexture, vec2((x + 5.5) * invSize, y))),\n decode32(texture(cc_jointsTexture, vec2((x + 6.5) * invSize, y))),\n decode32(texture(cc_jointsTexture, vec2((x + 7.5) * invSize, y)))\n );\n S = vec3(\n decode32(texture(cc_jointsTexture, vec2((x + 8.5) * invSize, y))),\n decode32(texture(cc_jointsTexture, vec2((x + 9.5) * invSize, y))),\n decode32(texture(cc_jointsTexture, vec2((x + 10.5) * invSize, y)))\n );\n }\n#elif CC_USE_SKINNING == 2\n void getJointDQ(float i, out vec4 Qr, out vec4 Qt, out vec3 S) {\n highp float j = 3.0 * (cc_jointsTextureInfo.z * i + cc_jointsTextureInfo.w) + cc_jointsTextureInfo.y;\n highp float invSize = 1.0 / cc_jointsTextureInfo.x;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointsTextureInfo.x;\n y = (y + 0.5) * invSize;\n Qr = texture(cc_jointsTexture, vec2((x + 0.5) * invSize, y));\n Qt = texture(cc_jointsTexture, vec2((x + 1.5) * invSize, y));\n S = texture(cc_jointsTexture, vec2((x + 2.5) * invSize, y)).xyz;\n }\n#endif\nvoid skinRTS(out vec4 R, out vec3 T, out vec3 S) {\n vec4 r, t, Qt = vec4(0.0); vec3 s;\n R = vec4(0.0); S = vec3(0.0);\n for (int i = 0; i < 4; i++) {\n float w = a_weights[i];\n getJointDQ(a_joints[i], r, t, s);\n S += s * w; R += r * w; Qt += t * w;\n }\n float invNorm = 1.0 / length(R); R *= invNorm; Qt *= invNorm;\n T = 2.0 * (R.w * Qt.xyz - Qt.w * R.xyz + cross(R.xyz, Qt.xyz));\n}\nvec3 VectorTransformQuat(vec3 v, vec4 Q) {\n return v + 2.0 * cross(Q.xyz, cross(Q.xyz, v) + Q.w * v);\n}\nvoid CCSkin(inout vec3 position) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n position = VectorTransformQuat(position * S, R) + T;\n}\nvoid CCSkin(inout StandardAttributes attr) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n attr.position = VectorTransformQuat(attr.position * S, R) + T;\n attr.normal = VectorTransformQuat(attr.normal, R);\n attr.tangent.xyz = VectorTransformQuat(attr.tangent.xyz, R);\n}\n#endif\nvoid CCVertInput (out highp vec3 position) {\n CCDecode(position);\n #if CC_USE_SKINNING\n CCSkin(position);\n #endif\n}\nout vec3 viewDir;\nvec4 vert () {\n CCVertInput(viewDir);\n mat4 matViewRotOnly = mat4(mat3(cc_matView));\n highp vec4 pos = cc_matProj * matViewRotOnly * vec4(viewDir, 1.0);\n pos.z = pos.w * 0.99999;\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n`,
|
|
"frag": `\nprecision mediump float;\nuniform samplerCube cc_environment;\nvec3 unpackNormal(vec4 nmap) {\n return nmap.xyz * 2.0 - 1.0;\n}\nvec3 unpackRGBE(vec4 rgbe) {\n return rgbe.rgb * pow(2.0, rgbe.a * 255.0 - 128.0);\n}\nvec3 SRGBToLinear(vec3 gamma)\n{\n return pow(gamma, vec3(2.2));\n}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\n}\nuniform CCGlobal {\n vec4 cc_time;\n vec4 cc_screenSize;\n vec4 cc_screenScale;\n vec4 cc_nativeSize;\n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos;\n vec4 cc_exposure;\n vec4 cc_mainLitDir;\n vec4 cc_mainLitColor;\n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\nvec4 CCFragOutput(vec4 color) {\n #if CC_USE_HDR\n color.rgb = mix(color.rgb, SRGBToLinear(color.rgb) * cc_exposure.w, vec3(cc_exposure.z));\n #endif\n return color;\n}\nin vec3 viewDir;\nvec4 frag () {\n #if USE_RGBE_CUBEMAP\n vec3 c = unpackRGBE(texture(cc_environment, viewDir));\n c = LinearToSRGB(c / (1.0 + c));\n vec4 o = vec4(c, 1.0);\n #else\n vec4 o = texture(cc_environment, viewDir);\n #endif\n return CCFragOutput(o);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }\n`
|
|
},
|
|
"glsl1": {
|
|
"vert": `\nprecision mediump float;\nuniform mat4 cc_matView;\nuniform mat4 cc_matProj;\nattribute vec3 a_position;\nvoid CCDecode (out vec3 position) {\n position = a_position;\n}\n#if CC_USE_SKINNING\nstruct StandardAttributes {\n vec3 position;\n vec3 normal;\n vec4 tangent;\n};\nattribute vec4 a_weights;\nattribute vec4 a_joints;\nuniform highp vec4 cc_jointsTextureInfo;\nuniform sampler2D cc_jointsTexture;\n#if CC_USE_SKINNING == 1\n highp float decode32(highp vec4 rgba) {\n rgba = rgba * 255.0;\n highp float Sign = 1.0 - step(128.0, rgba[3]) * 2.0;\n highp float Exponent = 2.0 * mod(rgba[3], 128.0) + step(128.0, rgba[2]) - 127.0;\n highp float Mantissa = mod(rgba[2], 128.0) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\n }\n#endif\n#if CC_USE_SKINNING == 1\n void getJointDQ(float i, out vec4 Qr, out vec4 Qt, out vec3 S) {\n highp float j = 12.0 * (cc_jointsTextureInfo.z * i + cc_jointsTextureInfo.w) + cc_jointsTextureInfo.y;\n highp float invSize = 1.0 / cc_jointsTextureInfo.x;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointsTextureInfo.x;\n y = (y + 0.5) * invSize;\n Qr = vec4(\n decode32(texture2D(cc_jointsTexture, vec2((x + 0.5) * invSize, y))),\n decode32(texture2D(cc_jointsTexture, vec2((x + 1.5) * invSize, y))),\n decode32(texture2D(cc_jointsTexture, vec2((x + 2.5) * invSize, y))),\n decode32(texture2D(cc_jointsTexture, vec2((x + 3.5) * invSize, y)))\n );\n Qt = vec4(\n decode32(texture2D(cc_jointsTexture, vec2((x + 4.5) * invSize, y))),\n decode32(texture2D(cc_jointsTexture, vec2((x + 5.5) * invSize, y))),\n decode32(texture2D(cc_jointsTexture, vec2((x + 6.5) * invSize, y))),\n decode32(texture2D(cc_jointsTexture, vec2((x + 7.5) * invSize, y)))\n );\n S = vec3(\n decode32(texture2D(cc_jointsTexture, vec2((x + 8.5) * invSize, y))),\n decode32(texture2D(cc_jointsTexture, vec2((x + 9.5) * invSize, y))),\n decode32(texture2D(cc_jointsTexture, vec2((x + 10.5) * invSize, y)))\n );\n }\n#elif CC_USE_SKINNING == 2\n void getJointDQ(float i, out vec4 Qr, out vec4 Qt, out vec3 S) {\n highp float j = 3.0 * (cc_jointsTextureInfo.z * i + cc_jointsTextureInfo.w) + cc_jointsTextureInfo.y;\n highp float invSize = 1.0 / cc_jointsTextureInfo.x;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointsTextureInfo.x;\n y = (y + 0.5) * invSize;\n Qr = texture2D(cc_jointsTexture, vec2((x + 0.5) * invSize, y));\n Qt = texture2D(cc_jointsTexture, vec2((x + 1.5) * invSize, y));\n S = texture2D(cc_jointsTexture, vec2((x + 2.5) * invSize, y)).xyz;\n }\n#endif\nvoid skinRTS(out vec4 R, out vec3 T, out vec3 S) {\n vec4 r, t, Qt = vec4(0.0); vec3 s;\n R = vec4(0.0); S = vec3(0.0);\n for (int i = 0; i < 4; i++) {\n float w = a_weights[i];\n getJointDQ(a_joints[i], r, t, s);\n S += s * w; R += r * w; Qt += t * w;\n }\n float invNorm = 1.0 / length(R); R *= invNorm; Qt *= invNorm;\n T = 2.0 * (R.w * Qt.xyz - Qt.w * R.xyz + cross(R.xyz, Qt.xyz));\n}\nvec3 VectorTransformQuat(vec3 v, vec4 Q) {\n return v + 2.0 * cross(Q.xyz, cross(Q.xyz, v) + Q.w * v);\n}\nvoid CCSkin(inout vec3 position) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n position = VectorTransformQuat(position * S, R) + T;\n}\nvoid CCSkin(inout StandardAttributes attr) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n attr.position = VectorTransformQuat(attr.position * S, R) + T;\n attr.normal = VectorTransformQuat(attr.normal, R);\n attr.tangent.xyz = VectorTransformQuat(attr.tangent.xyz, R);\n}\n#endif\nvoid CCVertInput (out highp vec3 position) {\n CCDecode(position);\n #if CC_USE_SKINNING\n CCSkin(position);\n #endif\n}\nvarying vec3 viewDir;\nvec4 vert () {\n CCVertInput(viewDir);\n mat4 matViewRotOnly = mat4(mat3(cc_matView));\n highp vec4 pos = cc_matProj * matViewRotOnly * vec4(viewDir, 1.0);\n pos.z = pos.w * 0.99999;\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n`,
|
|
"frag": `\nprecision mediump float;\nuniform samplerCube cc_environment;\nvec3 unpackNormal(vec4 nmap) {\n return nmap.xyz * 2.0 - 1.0;\n}\nvec3 unpackRGBE(vec4 rgbe) {\n return rgbe.rgb * pow(2.0, rgbe.a * 255.0 - 128.0);\n}\nvec3 SRGBToLinear(vec3 gamma)\n{\n return pow(gamma, vec3(2.2));\n}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\n}\nuniform vec4 cc_exposure;\nvec4 CCFragOutput(vec4 color) {\n #if CC_USE_HDR\n color.rgb = mix(color.rgb, SRGBToLinear(color.rgb) * cc_exposure.w, vec3(cc_exposure.z));\n #endif\n return color;\n}\nvarying vec3 viewDir;\nvec4 frag () {\n #if USE_RGBE_CUBEMAP\n vec3 c = unpackRGBE(textureCube(cc_environment, viewDir));\n c = LinearToSRGB(c / (1.0 + c));\n vec4 o = vec4(c, 1.0);\n #else\n vec4 o = textureCube(cc_environment, viewDir);\n #endif\n return CCFragOutput(o);\n}\nvoid main() { gl_FragColor = frag(); }\n`
|
|
},
|
|
"builtins": {"globals":{"blocks":[{"name":"CCGlobal", "defines":[]}], "samplers":[{"name":"cc_environment", "defines":[]}]}, "locals":{"blocks":[{"name":"CCSkinningTexture", "defines":["CC_USE_SKINNING"]}], "samplers":[{"name":"cc_jointsTexture", "defines":["CC_USE_SKINNING"]}]}},
|
|
"defines": [
|
|
{"name":"CC_USE_SKINNING", "type":"number", "defines":[], "range":[0, 2]},
|
|
{"name":"CC_USE_HDR", "type":"boolean", "defines":[]},
|
|
{"name":"USE_RGBE_CUBEMAP", "type":"boolean", "defines":[]}
|
|
],
|
|
"blocks": [],
|
|
"samplers": [],
|
|
"dependencies": {}
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"name": "builtin-sprite",
|
|
"techniques": [
|
|
{"passes":[{"blendState":{"targets":[{"blend":true, "blendSrc":2, "blendDst":4, "blendDstAlpha":4}]}, "rasterizerState":{"cullMode":0}, "program":"builtin-sprite|sprite-vs:vert|sprite-fs:frag", "priority":244, "depthStencilState":{"depthTest":false, "depthWrite":false}, "properties":{"mainTexture":{"value":"white", "type":28}}}]}
|
|
],
|
|
"shaders": [
|
|
{
|
|
"name": "builtin-sprite|sprite-vs:vert|sprite-fs:frag",
|
|
"hash": 1287302882,
|
|
"glsl3": {
|
|
"vert": `\nprecision mediump float;\nuniform CCGlobal {\n vec4 cc_time;\n vec4 cc_screenSize;\n vec4 cc_screenScale;\n vec4 cc_nativeSize;\n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos;\n vec4 cc_exposure;\n vec4 cc_mainLitDir;\n vec4 cc_mainLitColor;\n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\n#if USE_LOCAL\nuniform CCLocal {\n highp mat4 cc_matWorld;\n mat4 cc_matWorldIT;\n};\n#endif\nin vec3 a_position;\nin vec4 a_color;\nout vec4 color;\nin vec2 a_texCoord;\nout vec2 uv0;\nvec4 vert () {\n vec4 pos = vec4(a_position, 1);\n #if USE_LOCAL\n pos = cc_matViewProj * cc_matWorld * pos;\n #else\n pos = cc_matViewProj * pos;\n #endif\n uv0 = a_texCoord;\n color = a_color;\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n`,
|
|
"frag": `\nprecision mediump float;\nin vec4 color;\n#if USE_TEXTURE\n in vec2 uv0;\n uniform sampler2D mainTexture;\n#endif\nvec4 frag () {\n vec4 o = vec4(1, 1, 1, 1);\n #if USE_TEXTURE\n o *= texture(mainTexture, uv0);\n #endif\n o *= color;\n return o;\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }\n`
|
|
},
|
|
"glsl1": {
|
|
"vert": `\nprecision mediump float;\nuniform mat4 cc_matViewProj;\n#if USE_LOCAL\nuniform highp mat4 cc_matWorld;\n#endif\nattribute vec3 a_position;\nattribute vec4 a_color;\nvarying vec4 color;\nattribute vec2 a_texCoord;\nvarying vec2 uv0;\nvec4 vert () {\n vec4 pos = vec4(a_position, 1);\n #if USE_LOCAL\n pos = cc_matViewProj * cc_matWorld * pos;\n #else\n pos = cc_matViewProj * pos;\n #endif\n uv0 = a_texCoord;\n color = a_color;\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n`,
|
|
"frag": `\nprecision mediump float;\nvarying vec4 color;\n#if USE_TEXTURE\n varying vec2 uv0;\n uniform sampler2D mainTexture;\n#endif\nvec4 frag () {\n vec4 o = vec4(1, 1, 1, 1);\n #if USE_TEXTURE\n o *= texture2D(mainTexture, uv0);\n #endif\n o *= color;\n return o;\n}\nvoid main() { gl_FragColor = frag(); }\n`
|
|
},
|
|
"builtins": {"globals":{"blocks":[{"name":"CCGlobal", "defines":[]}], "samplers":[]}, "locals":{"blocks":[{"name":"CCLocal", "defines":["USE_LOCAL"]}], "samplers":[]}},
|
|
"defines": [
|
|
{"name":"USE_LOCAL", "type":"boolean", "defines":[]},
|
|
{"name":"USE_TEXTURE", "type":"boolean", "defines":[]}
|
|
],
|
|
"blocks": [],
|
|
"samplers": [
|
|
{"name":"mainTexture", "type":28, "count":1, "defines":["USE_TEXTURE"], "binding":30}
|
|
],
|
|
"dependencies": {}
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"name": "builtin-standard",
|
|
"techniques": [
|
|
{"name":"opaque", "passes":[{"program":"builtin-standard|standard-vs:vert|standard-fs:frag", "properties":{"tilingOffset":{"value":[1, 1, 0, 0], "type":16}, "albedo":{"value":[1, 1, 1, 1], "inspector":{"type":"color"}, "type":16}, "albedoScale":{"value":[1, 1, 1, 0], "type":16}, "pbrParams":{"value":[0.8, 0.6, 1, 1], "type":16}, "pbrScale":{"value":[1, 1, 1, 1], "type":16}, "emissive":{"value":[0, 0, 0, 1], "inspector":{"type":"color"}, "type":16}, "emissiveScale":{"value":[1, 1, 1, 1], "type":16}, "albedoMap":{"value":"grey", "type":28}, "normalMap":{"value":"normal", "type":28}, "pbrMap":{"value":"grey", "type":28}, "metallicRoughnessMap":{"value":"grey", "type":28}, "occlusionMap":{"value":"white", "type":28}, "emissiveMap":{"value":"grey", "type":28}}}]}
|
|
],
|
|
"shaders": [
|
|
{
|
|
"name": "builtin-standard|standard-vs:vert|standard-fs:frag",
|
|
"hash": 902260667,
|
|
"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 highp mat4 cc_matWorld;\n mat4 cc_matWorldIT;\n};\nstruct StandardAttributes {\n vec3 position;\n vec3 normal;\n vec4 tangent;\n};\nin vec3 a_position;\nin vec3 a_normal;\nin vec4 a_tangent;\nvoid CCDecode (out StandardAttributes attr) {\n attr.position = a_position;\n attr.normal = a_normal;\n attr.tangent = a_tangent;\n}\n#if CC_USE_SKINNING\nin vec4 a_weights;\nin vec4 a_joints;\nuniform CCSkinningTexture {\n highp vec4 cc_jointsTextureInfo;\n};\nuniform sampler2D cc_jointsTexture;\n#if CC_USE_SKINNING == 1\n highp float decode32(highp vec4 rgba) {\n rgba = rgba * 255.0;\n highp float Sign = 1.0 - step(128.0, rgba[3]) * 2.0;\n highp float Exponent = 2.0 * mod(rgba[3], 128.0) + step(128.0, rgba[2]) - 127.0;\n highp float Mantissa = mod(rgba[2], 128.0) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\n }\n#endif\n#if CC_USE_SKINNING == 1\n void getJointDQ(float i, out vec4 Qr, out vec4 Qt, out vec3 S) {\n highp float j = 12.0 * (cc_jointsTextureInfo.z * i + cc_jointsTextureInfo.w) + cc_jointsTextureInfo.y;\n highp float invSize = 1.0 / cc_jointsTextureInfo.x;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointsTextureInfo.x;\n y = (y + 0.5) * invSize;\n Qr = vec4(\n decode32(texture(cc_jointsTexture, vec2((x + 0.5) * invSize, y))),\n decode32(texture(cc_jointsTexture, vec2((x + 1.5) * invSize, y))),\n decode32(texture(cc_jointsTexture, vec2((x + 2.5) * invSize, y))),\n decode32(texture(cc_jointsTexture, vec2((x + 3.5) * invSize, y)))\n );\n Qt = vec4(\n decode32(texture(cc_jointsTexture, vec2((x + 4.5) * invSize, y))),\n decode32(texture(cc_jointsTexture, vec2((x + 5.5) * invSize, y))),\n decode32(texture(cc_jointsTexture, vec2((x + 6.5) * invSize, y))),\n decode32(texture(cc_jointsTexture, vec2((x + 7.5) * invSize, y)))\n );\n S = vec3(\n decode32(texture(cc_jointsTexture, vec2((x + 8.5) * invSize, y))),\n decode32(texture(cc_jointsTexture, vec2((x + 9.5) * invSize, y))),\n decode32(texture(cc_jointsTexture, vec2((x + 10.5) * invSize, y)))\n );\n }\n#elif CC_USE_SKINNING == 2\n void getJointDQ(float i, out vec4 Qr, out vec4 Qt, out vec3 S) {\n highp float j = 3.0 * (cc_jointsTextureInfo.z * i + cc_jointsTextureInfo.w) + cc_jointsTextureInfo.y;\n highp float invSize = 1.0 / cc_jointsTextureInfo.x;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointsTextureInfo.x;\n y = (y + 0.5) * invSize;\n Qr = texture(cc_jointsTexture, vec2((x + 0.5) * invSize, y));\n Qt = texture(cc_jointsTexture, vec2((x + 1.5) * invSize, y));\n S = texture(cc_jointsTexture, vec2((x + 2.5) * invSize, y)).xyz;\n }\n#endif\nvoid skinRTS(out vec4 R, out vec3 T, out vec3 S) {\n vec4 r, t, Qt = vec4(0.0); vec3 s;\n R = vec4(0.0); S = vec3(0.0);\n for (int i = 0; i < 4; i++) {\n float w = a_weights[i];\n getJointDQ(a_joints[i], r, t, s);\n S += s * w; R += r * w; Qt += t * w;\n }\n float invNorm = 1.0 / length(R); R *= invNorm; Qt *= invNorm;\n T = 2.0 * (R.w * Qt.xyz - Qt.w * R.xyz + cross(R.xyz, Qt.xyz));\n}\nvec3 VectorTransformQuat(vec3 v, vec4 Q) {\n return v + 2.0 * cross(Q.xyz, cross(Q.xyz, v) + Q.w * v);\n}\nvoid CCSkin(inout vec3 position) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n position = VectorTransformQuat(position * S, R) + T;\n}\nvoid CCSkin(inout StandardAttributes attr) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n attr.position = VectorTransformQuat(attr.position * S, R) + T;\n attr.normal = VectorTransformQuat(attr.normal, R);\n attr.tangent.xyz = VectorTransformQuat(attr.tangent.xyz, R);\n}\n#endif\nstruct StandardVertInput {\n highp vec3 position;\n vec3 normal;\n vec4 tangent;\n};\nvoid CCAttrToInput (in StandardAttributes attr, out StandardVertInput In) {\n In.position = attr.position;\n In.normal = attr.normal;\n In.tangent = attr.tangent;\n}\nvoid CCVertInput (out StandardVertInput In) {\n StandardAttributes attr;\n CCDecode(attr);\n #if CC_USE_SKINNING\n CCSkin(attr);\n #endif\n CCAttrToInput(attr, In);\n}\nuniform Constants {\n vec4 tilingOffset;\n vec4 albedo;\n vec4 albedoScale;\n vec4 pbrParams;\n vec4 pbrScale;\n vec4 emissive;\n vec4 emissiveScale;\n};\nout vec3 v_position;\nout vec3 v_normal;\n#if USE_NORMAL_MAP\n out vec3 v_tangent;\n out vec3 v_bitangent;\n#endif\n#if USE_ALBEDO_MAP || USE_NORMAL_MAP || USE_PBR_MAP || USE_EMISSIVE_MAP || USE_METALLIC_ROUGHNESS_MAP || USE_OCCLUSION_MAP\n in vec2 a_texCoord;\n out vec2 v_uv;\n#endif\nvec4 vert () {\n StandardVertInput In;\n CCVertInput(In);\n vec4 pos = cc_matWorld * vec4(In.position, 1.0);\n v_position = pos.xyz;\n v_normal = (cc_matWorldIT * vec4(In.normal, 0.0)).xyz;\n #if USE_NORMAL_MAP\n v_tangent = (cc_matWorldIT * vec4(In.tangent.xyz, 0.0)).xyz;\n v_bitangent = cross(v_tangent, v_normal) * In.tangent.w;\n #endif\n #if USE_ALBEDO_MAP || USE_NORMAL_MAP || USE_PBR_MAP || USE_EMISSIVE_MAP || USE_METALLIC_ROUGHNESS_MAP || USE_OCCLUSION_MAP\n v_uv = a_texCoord * tilingOffset.xy + tilingOffset.zw;\n #endif\n return cc_matViewProj * 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};\nuniform CCForwardLight {\n highp vec4 cc_sphereLitPos[2];\n vec4 cc_sphereLitSizeRange[2];\n vec4 cc_sphereLitColor[2];\n highp vec4 cc_spotLitPos[2];\n vec4 cc_spotLitSizeRangeAngle[2];\n vec4 cc_spotLitDir[2];\n vec4 cc_spotLitColor[2];\n};\n#if CC_USE_IBL\nuniform samplerCube cc_environment;\n#endif\n#define saturate(a) clamp( a, 0.0, 1.0 )\nvec3 SRGBToLinear(vec3 gamma)\n{\n return pow(gamma, vec3(2.2));\n}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\n}\nfloat SmoothDistAtt2(float distSqr, float invSqrAttRadius) {\n float factor = distSqr * invSqrAttRadius;\n float factor2 = factor * factor;\n float factor3 = factor2 * factor2;\n float smoothFactor = clamp(1.0 - factor3 * factor3, 0.0, 1.0);\n return smoothFactor * smoothFactor;\n}\nfloat SmoothDistAtt(float distSqr, float invSqrAttRadius) {\n float factor = distSqr * invSqrAttRadius;\n float smoothFactor = clamp(1.0 - factor * factor, 0.0, 1.0);\n return smoothFactor * smoothFactor;\n}\nfloat GetDistAtt(float distSqr, float invSqrAttRadius) {\n float attenuation = 1.0 / max(distSqr, 0.01*0.01);\n attenuation *= SmoothDistAtt(distSqr , invSqrAttRadius);\n return attenuation;\n}\nfloat GetAngleAtt(vec3 L, vec3 litDir, float litAngleScale, float litAngleOffset) {\n float cd = dot(litDir, L);\n float attenuation = clamp(cd * litAngleScale + litAngleOffset, 0.0, 1.0);\n return (attenuation * attenuation);\n}\nfloat GGXMobile(float roughness, float NoH, vec3 H, vec3 N) {\n vec3 NxH = cross(N, H);\n float OneMinusNoHSqr = dot(NxH, NxH);\n float a = roughness * roughness;\n float n = NoH * a;\n float p = a / (OneMinusNoHSqr + n * n);\n return p * p;\n}\nfloat CalcSpecular(float roughness, float NoH, vec3 H, vec3 N) {\n return (roughness*0.25 + 0.25) * GGXMobile(roughness, NoH, H, N);\n}\nvec3 BRDFApprox(vec3 specular, float roughness, float NoV) {\n const vec4 c0 = vec4(-1.0, -0.0275, -0.572, 0.022);\n const vec4 c1 = vec4(1.0, 0.0425, 1.04, -0.04);\n vec4 r = roughness * c0 + c1;\n float a004 = min( r.x * r.x, exp2( -9.28 * NoV ) ) * r.x + r.y;\n vec2 AB = vec2( -1.04, 1.04 ) * a004 + r.zw;\n AB.y *= clamp(50.0 * specular.g, 0.0, 1.0);\n return specular * AB.x + AB.y;\n}\nvec3 CalcDynamicLighting(vec3 worldPos, vec3 N, vec3 V, vec3 diffuse, vec3 specular, float roughness) {\n vec3 lighting = vec3(0.0);\n vec3 diffuseContrib = diffuse / 3.14159265359;\n for (int i = 0; i < 2; i++) {\n vec3 PLU = cc_sphereLitPos[i].xyz - worldPos;\n vec3 PL = normalize(PLU);\n vec3 PH = normalize(PL+V);\n float PNL = max(dot(N, PL), 0.001);\n float PNH = max(dot(N, PH), 0.0);\n float distSqr = dot(PLU, PLU);\n float litRadius = cc_sphereLitSizeRange[i].x;\n float litRadiusSqr = litRadius * litRadius;\n float illum = 3.14159265359 * (litRadiusSqr / max(litRadiusSqr , distSqr));\n float attRadiusSqrInv = 1.0 / max(cc_sphereLitSizeRange[i].y, 0.01);\n attRadiusSqrInv *= attRadiusSqrInv;\n float att = GetDistAtt(distSqr, attRadiusSqrInv);\n vec3 lspec = specular * CalcSpecular(roughness, PNH, PH, N);\n lighting += PNL * cc_sphereLitColor[i].rgb * cc_sphereLitColor[i].w * illum * att * (diffuseContrib + lspec);\n }\n for (int i = 0; i < 2; i++) {\n vec3 SLU = cc_spotLitPos[i].xyz - worldPos;\n vec3 SL = normalize(SLU);\n vec3 SH = normalize(SL+V);\n float SNL = max(dot(N, SL), 0.001);\n float SNH = max(dot(N, SH), 0.0);\n float distSqr = dot(SLU, SLU);\n float litRadius = cc_spotLitSizeRangeAngle[i].x;\n float litRadiusSqr = litRadius * litRadius;\n float illum = 3.14159265359 * (litRadiusSqr / max(litRadiusSqr , distSqr));\n float attRadiusSqrInv = 1.0 / max(cc_spotLitSizeRangeAngle[i].y, 0.01);\n attRadiusSqrInv *= attRadiusSqrInv;\n float cosInner = max(dot(-cc_spotLitDir[i].xyz, SL), 0.01);\n float cosOuter = cc_spotLitSizeRangeAngle[i].z;\n float litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\n float litAngleOffset = -cosOuter * litAngleScale;\n float att = GetDistAtt(distSqr, attRadiusSqrInv);\n att *= GetAngleAtt(SL, -cc_spotLitDir[i].xyz, litAngleScale, litAngleOffset);\n vec3 lspec = specular * CalcSpecular(roughness, SNH, SH, N);\n lighting += SNL * cc_spotLitColor[i].rgb * cc_spotLitColor[i].w * illum * att * (diffuseContrib + lspec);\n }\n return lighting;\n}\nstruct StandardSurface {\n vec3 albedo;\n float alpha;\n vec3 position;\n vec3 normal;\n float roughness;\n float metallic;\n float occlusion;\n vec3 emissive;\n};\nvec4 CCStandardShading (StandardSurface s) {\n vec3 diffuse = s.albedo * (1.0 - s.metallic);\n vec3 specular = mix(vec3(0.04), s.albedo, s.metallic);\n vec3 N = normalize(s.normal);\n vec3 V = normalize(cc_cameraPos.xyz - s.position);\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, s.roughness, NV);\n vec3 specularContrib = specular * CalcSpecular(s.roughness, NH, H, N);\n vec3 diffuseContrib = diffuse / 3.14159265359;\n vec3 finalColor = NL * cc_mainLitColor.rgb * cc_mainLitColor.w * (diffuseContrib + specularContrib);\n finalColor += CalcDynamicLighting(s.position, N, V, diffuse, specular, s.roughness);\n float fAmb = 0.5 - N.y * 0.5;\n vec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb) * cc_ambientSky.w;\n finalColor += (ambDiff.rgb * diffuse);\n #if CC_USE_IBL\n vec3 R = normalize(reflect(-V, N));\n vec3 env = SRGBToLinear(texture(cc_environment, R).rgb) * cc_ambientSky.w;\n finalColor += env * specular;\n #endif\n finalColor = finalColor * s.occlusion;\n #if CC_USE_HDR\n s.emissive *= cc_exposure.w;\n #endif\n finalColor += s.emissive;\n return vec4(finalColor, s.alpha);\n}\nvec4 CCFragOutput (vec4 color) {\n #if !CC_USE_HDR\n color.rgb = LinearToSRGB(color.rgb);\n #endif\n return color;\n}\nuniform Constants {\n vec4 tilingOffset;\n vec4 albedo;\n vec4 albedoScale;\n vec4 pbrParams;\n vec4 pbrScale;\n vec4 emissive;\n vec4 emissiveScale;\n};\nin vec3 v_position;\n#if USE_ALBEDO_MAP || USE_NORMAL_MAP || USE_PBR_MAP || USE_EMISSIVE_MAP || USE_METALLIC_ROUGHNESS_MAP || USE_OCCLUSION_MAP\n in vec2 v_uv;\n#endif\nin vec3 v_normal;\n#if USE_NORMAL_MAP\n in vec3 v_tangent;\n in vec3 v_bitangent;\n#endif\n#if USE_ALBEDO_MAP\n uniform sampler2D albedoMap;\n#endif\n#if USE_NORMAL_MAP\n uniform sampler2D normalMap;\n#endif\n#if USE_PBR_MAP\n uniform sampler2D pbrMap;\n#endif\n#if USE_METALLIC_ROUGHNESS_MAP\n uniform sampler2D metallicRoughnessMap;\n#endif\n#if USE_OCCLUSION_MAP\n uniform sampler2D occlusionMap;\n#endif\n#if USE_EMISSIVE_MAP\n uniform sampler2D emissiveMap;\n#endif\nvoid surf (out StandardSurface s) {\n vec4 baseColor = albedo;\n #if USE_ALBEDO_MAP\n vec4 texColor = texture(albedoMap, v_uv);\n texColor.rgb = SRGBToLinear(texColor.rgb);\n baseColor *= texColor;\n #endif\n s.albedo = baseColor.rgb * albedoScale.xyz;\n s.alpha = baseColor.a;\n #if USE_ALPHA_TEST\n if(s.alpha < albedoScale.w)\n discard;\n #endif\n s.normal = v_normal;\n #if USE_NORMAL_MAP\n vec3 nmmp = texture(normalMap, v_uv).xyz - vec3(0.5);\n s.normal =\n (nmmp.x * pbrScale.w) * normalize(v_tangent) +\n (nmmp.y * pbrScale.w) * normalize(v_bitangent) +\n nmmp.z * normalize(s.normal);\n #endif\n s.position = v_position;\n vec4 pbr = pbrParams;\n #if USE_PBR_MAP\n pbr = texture(pbrMap, v_uv);\n #endif\n #if USE_METALLIC_ROUGHNESS_MAP\n vec4 metallicRoughness = texture(metallicRoughnessMap, v_uv);\n pbr.METALLIC_CHANNEL = metallicRoughness.METALLIC_CHANNEL;\n pbr.ROUGHNESS_CHANNEL = metallicRoughness.ROUGHNESS_CHANNEL;\n #endif\n #if USE_OCCLUSION_MAP\n pbr.OCCLUSION_CHANNEL = texture(occlusionMap, v_uv).OCCLUSION_CHANNEL;\n #endif\n pbr *= pbrScale;\n s.roughness = clamp(pbr.ROUGHNESS_CHANNEL, 0.04, 1.0);\n s.metallic = clamp(pbr.METALLIC_CHANNEL, 0.0, 0.96);\n s.occlusion = pbr.OCCLUSION_CHANNEL;\n s.emissive = emissive.rgb * emissiveScale.xyz;\n #if USE_EMISSIVE_MAP\n s.emissive *= SRGBToLinear(texture(emissiveMap, v_uv).rgb);\n #endif\n}\nvec4 frag () {\n StandardSurface s; surf(s);\n vec4 color = CCStandardShading(s);\n return CCFragOutput(color);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }\n`
|
|
},
|
|
"glsl1": {
|
|
"vert": `\nprecision highp float;\nuniform mat4 cc_matViewProj;\nuniform highp mat4 cc_matWorld;\nuniform mat4 cc_matWorldIT;\nstruct StandardAttributes {\n vec3 position;\n vec3 normal;\n vec4 tangent;\n};\nattribute vec3 a_position;\nattribute vec3 a_normal;\nattribute vec4 a_tangent;\nvoid CCDecode (out StandardAttributes attr) {\n attr.position = a_position;\n attr.normal = a_normal;\n attr.tangent = a_tangent;\n}\n#if CC_USE_SKINNING\nattribute vec4 a_weights;\nattribute vec4 a_joints;\nuniform highp vec4 cc_jointsTextureInfo;\nuniform sampler2D cc_jointsTexture;\n#if CC_USE_SKINNING == 1\n highp float decode32(highp vec4 rgba) {\n rgba = rgba * 255.0;\n highp float Sign = 1.0 - step(128.0, rgba[3]) * 2.0;\n highp float Exponent = 2.0 * mod(rgba[3], 128.0) + step(128.0, rgba[2]) - 127.0;\n highp float Mantissa = mod(rgba[2], 128.0) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\n }\n#endif\n#if CC_USE_SKINNING == 1\n void getJointDQ(float i, out vec4 Qr, out vec4 Qt, out vec3 S) {\n highp float j = 12.0 * (cc_jointsTextureInfo.z * i + cc_jointsTextureInfo.w) + cc_jointsTextureInfo.y;\n highp float invSize = 1.0 / cc_jointsTextureInfo.x;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointsTextureInfo.x;\n y = (y + 0.5) * invSize;\n Qr = vec4(\n decode32(texture2D(cc_jointsTexture, vec2((x + 0.5) * invSize, y))),\n decode32(texture2D(cc_jointsTexture, vec2((x + 1.5) * invSize, y))),\n decode32(texture2D(cc_jointsTexture, vec2((x + 2.5) * invSize, y))),\n decode32(texture2D(cc_jointsTexture, vec2((x + 3.5) * invSize, y)))\n );\n Qt = vec4(\n decode32(texture2D(cc_jointsTexture, vec2((x + 4.5) * invSize, y))),\n decode32(texture2D(cc_jointsTexture, vec2((x + 5.5) * invSize, y))),\n decode32(texture2D(cc_jointsTexture, vec2((x + 6.5) * invSize, y))),\n decode32(texture2D(cc_jointsTexture, vec2((x + 7.5) * invSize, y)))\n );\n S = vec3(\n decode32(texture2D(cc_jointsTexture, vec2((x + 8.5) * invSize, y))),\n decode32(texture2D(cc_jointsTexture, vec2((x + 9.5) * invSize, y))),\n decode32(texture2D(cc_jointsTexture, vec2((x + 10.5) * invSize, y)))\n );\n }\n#elif CC_USE_SKINNING == 2\n void getJointDQ(float i, out vec4 Qr, out vec4 Qt, out vec3 S) {\n highp float j = 3.0 * (cc_jointsTextureInfo.z * i + cc_jointsTextureInfo.w) + cc_jointsTextureInfo.y;\n highp float invSize = 1.0 / cc_jointsTextureInfo.x;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointsTextureInfo.x;\n y = (y + 0.5) * invSize;\n Qr = texture2D(cc_jointsTexture, vec2((x + 0.5) * invSize, y));\n Qt = texture2D(cc_jointsTexture, vec2((x + 1.5) * invSize, y));\n S = texture2D(cc_jointsTexture, vec2((x + 2.5) * invSize, y)).xyz;\n }\n#endif\nvoid skinRTS(out vec4 R, out vec3 T, out vec3 S) {\n vec4 r, t, Qt = vec4(0.0); vec3 s;\n R = vec4(0.0); S = vec3(0.0);\n for (int i = 0; i < 4; i++) {\n float w = a_weights[i];\n getJointDQ(a_joints[i], r, t, s);\n S += s * w; R += r * w; Qt += t * w;\n }\n float invNorm = 1.0 / length(R); R *= invNorm; Qt *= invNorm;\n T = 2.0 * (R.w * Qt.xyz - Qt.w * R.xyz + cross(R.xyz, Qt.xyz));\n}\nvec3 VectorTransformQuat(vec3 v, vec4 Q) {\n return v + 2.0 * cross(Q.xyz, cross(Q.xyz, v) + Q.w * v);\n}\nvoid CCSkin(inout vec3 position) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n position = VectorTransformQuat(position * S, R) + T;\n}\nvoid CCSkin(inout StandardAttributes attr) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n attr.position = VectorTransformQuat(attr.position * S, R) + T;\n attr.normal = VectorTransformQuat(attr.normal, R);\n attr.tangent.xyz = VectorTransformQuat(attr.tangent.xyz, R);\n}\n#endif\nstruct StandardVertInput {\n highp vec3 position;\n vec3 normal;\n vec4 tangent;\n};\nvoid CCAttrToInput (in StandardAttributes attr, out StandardVertInput In) {\n In.position = attr.position;\n In.normal = attr.normal;\n In.tangent = attr.tangent;\n}\nvoid CCVertInput (out StandardVertInput In) {\n StandardAttributes attr;\n CCDecode(attr);\n #if CC_USE_SKINNING\n CCSkin(attr);\n #endif\n CCAttrToInput(attr, In);\n}\nuniform vec4 tilingOffset;\nvarying vec3 v_position;\nvarying vec3 v_normal;\n#if USE_NORMAL_MAP\n varying vec3 v_tangent;\n varying vec3 v_bitangent;\n#endif\n#if USE_ALBEDO_MAP || USE_NORMAL_MAP || USE_PBR_MAP || USE_EMISSIVE_MAP || USE_METALLIC_ROUGHNESS_MAP || USE_OCCLUSION_MAP\n attribute vec2 a_texCoord;\n varying vec2 v_uv;\n#endif\nvec4 vert () {\n StandardVertInput In;\n CCVertInput(In);\n vec4 pos = cc_matWorld * vec4(In.position, 1.0);\n v_position = pos.xyz;\n v_normal = (cc_matWorldIT * vec4(In.normal, 0.0)).xyz;\n #if USE_NORMAL_MAP\n v_tangent = (cc_matWorldIT * vec4(In.tangent.xyz, 0.0)).xyz;\n v_bitangent = cross(v_tangent, v_normal) * In.tangent.w;\n #endif\n #if USE_ALBEDO_MAP || USE_NORMAL_MAP || USE_PBR_MAP || USE_EMISSIVE_MAP || USE_METALLIC_ROUGHNESS_MAP || USE_OCCLUSION_MAP\n v_uv = a_texCoord * tilingOffset.xy + tilingOffset.zw;\n #endif\n return cc_matViewProj * pos;\n}\nvoid main() { gl_Position = vert(); }\n`,
|
|
"frag": `\nprecision highp float;\nuniform vec4 cc_cameraPos;\nuniform vec4 cc_exposure;\nuniform vec4 cc_mainLitDir;\nuniform vec4 cc_mainLitColor;\nuniform vec4 cc_ambientSky;\nuniform vec4 cc_ambientGround;\nuniform highp vec4 cc_sphereLitPos[2];\nuniform vec4 cc_sphereLitSizeRange[2];\nuniform vec4 cc_sphereLitColor[2];\nuniform highp vec4 cc_spotLitPos[2];\nuniform vec4 cc_spotLitSizeRangeAngle[2];\nuniform vec4 cc_spotLitDir[2];\nuniform vec4 cc_spotLitColor[2];\n#if CC_USE_IBL\nuniform samplerCube cc_environment;\n#endif\n#define saturate(a) clamp( a, 0.0, 1.0 )\nvec3 SRGBToLinear(vec3 gamma)\n{\n return pow(gamma, vec3(2.2));\n}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\n}\nfloat SmoothDistAtt2(float distSqr, float invSqrAttRadius) {\n float factor = distSqr * invSqrAttRadius;\n float factor2 = factor * factor;\n float factor3 = factor2 * factor2;\n float smoothFactor = clamp(1.0 - factor3 * factor3, 0.0, 1.0);\n return smoothFactor * smoothFactor;\n}\nfloat SmoothDistAtt(float distSqr, float invSqrAttRadius) {\n float factor = distSqr * invSqrAttRadius;\n float smoothFactor = clamp(1.0 - factor * factor, 0.0, 1.0);\n return smoothFactor * smoothFactor;\n}\nfloat GetDistAtt(float distSqr, float invSqrAttRadius) {\n float attenuation = 1.0 / max(distSqr, 0.01*0.01);\n attenuation *= SmoothDistAtt(distSqr , invSqrAttRadius);\n return attenuation;\n}\nfloat GetAngleAtt(vec3 L, vec3 litDir, float litAngleScale, float litAngleOffset) {\n float cd = dot(litDir, L);\n float attenuation = clamp(cd * litAngleScale + litAngleOffset, 0.0, 1.0);\n return (attenuation * attenuation);\n}\nfloat GGXMobile(float roughness, float NoH, vec3 H, vec3 N) {\n vec3 NxH = cross(N, H);\n float OneMinusNoHSqr = dot(NxH, NxH);\n float a = roughness * roughness;\n float n = NoH * a;\n float p = a / (OneMinusNoHSqr + n * n);\n return p * p;\n}\nfloat CalcSpecular(float roughness, float NoH, vec3 H, vec3 N) {\n return (roughness*0.25 + 0.25) * GGXMobile(roughness, NoH, H, N);\n}\nvec3 BRDFApprox(vec3 specular, float roughness, float NoV) {\n const vec4 c0 = vec4(-1.0, -0.0275, -0.572, 0.022);\n const vec4 c1 = vec4(1.0, 0.0425, 1.04, -0.04);\n vec4 r = roughness * c0 + c1;\n float a004 = min( r.x * r.x, exp2( -9.28 * NoV ) ) * r.x + r.y;\n vec2 AB = vec2( -1.04, 1.04 ) * a004 + r.zw;\n AB.y *= clamp(50.0 * specular.g, 0.0, 1.0);\n return specular * AB.x + AB.y;\n}\nvec3 CalcDynamicLighting(vec3 worldPos, vec3 N, vec3 V, vec3 diffuse, vec3 specular, float roughness) {\n vec3 lighting = vec3(0.0);\n vec3 diffuseContrib = diffuse / 3.14159265359;\n for (int i = 0; i < 2; i++) {\n vec3 PLU = cc_sphereLitPos[i].xyz - worldPos;\n vec3 PL = normalize(PLU);\n vec3 PH = normalize(PL+V);\n float PNL = max(dot(N, PL), 0.001);\n float PNH = max(dot(N, PH), 0.0);\n float distSqr = dot(PLU, PLU);\n float litRadius = cc_sphereLitSizeRange[i].x;\n float litRadiusSqr = litRadius * litRadius;\n float illum = 3.14159265359 * (litRadiusSqr / max(litRadiusSqr , distSqr));\n float attRadiusSqrInv = 1.0 / max(cc_sphereLitSizeRange[i].y, 0.01);\n attRadiusSqrInv *= attRadiusSqrInv;\n float att = GetDistAtt(distSqr, attRadiusSqrInv);\n vec3 lspec = specular * CalcSpecular(roughness, PNH, PH, N);\n lighting += PNL * cc_sphereLitColor[i].rgb * cc_sphereLitColor[i].w * illum * att * (diffuseContrib + lspec);\n }\n for (int i = 0; i < 2; i++) {\n vec3 SLU = cc_spotLitPos[i].xyz - worldPos;\n vec3 SL = normalize(SLU);\n vec3 SH = normalize(SL+V);\n float SNL = max(dot(N, SL), 0.001);\n float SNH = max(dot(N, SH), 0.0);\n float distSqr = dot(SLU, SLU);\n float litRadius = cc_spotLitSizeRangeAngle[i].x;\n float litRadiusSqr = litRadius * litRadius;\n float illum = 3.14159265359 * (litRadiusSqr / max(litRadiusSqr , distSqr));\n float attRadiusSqrInv = 1.0 / max(cc_spotLitSizeRangeAngle[i].y, 0.01);\n attRadiusSqrInv *= attRadiusSqrInv;\n float cosInner = max(dot(-cc_spotLitDir[i].xyz, SL), 0.01);\n float cosOuter = cc_spotLitSizeRangeAngle[i].z;\n float litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\n float litAngleOffset = -cosOuter * litAngleScale;\n float att = GetDistAtt(distSqr, attRadiusSqrInv);\n att *= GetAngleAtt(SL, -cc_spotLitDir[i].xyz, litAngleScale, litAngleOffset);\n vec3 lspec = specular * CalcSpecular(roughness, SNH, SH, N);\n lighting += SNL * cc_spotLitColor[i].rgb * cc_spotLitColor[i].w * illum * att * (diffuseContrib + lspec);\n }\n return lighting;\n}\nstruct StandardSurface {\n vec3 albedo;\n float alpha;\n vec3 position;\n vec3 normal;\n float roughness;\n float metallic;\n float occlusion;\n vec3 emissive;\n};\nvec4 CCStandardShading (StandardSurface s) {\n vec3 diffuse = s.albedo * (1.0 - s.metallic);\n vec3 specular = mix(vec3(0.04), s.albedo, s.metallic);\n vec3 N = normalize(s.normal);\n vec3 V = normalize(cc_cameraPos.xyz - s.position);\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, s.roughness, NV);\n vec3 specularContrib = specular * CalcSpecular(s.roughness, NH, H, N);\n vec3 diffuseContrib = diffuse / 3.14159265359;\n vec3 finalColor = NL * cc_mainLitColor.rgb * cc_mainLitColor.w * (diffuseContrib + specularContrib);\n finalColor += CalcDynamicLighting(s.position, N, V, diffuse, specular, s.roughness);\n float fAmb = 0.5 - N.y * 0.5;\n vec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb) * cc_ambientSky.w;\n finalColor += (ambDiff.rgb * diffuse);\n #if CC_USE_IBL\n vec3 R = normalize(reflect(-V, N));\n vec3 env = SRGBToLinear(textureCube(cc_environment, R).rgb) * cc_ambientSky.w;\n finalColor += env * specular;\n #endif\n finalColor = finalColor * s.occlusion;\n #if CC_USE_HDR\n s.emissive *= cc_exposure.w;\n #endif\n finalColor += s.emissive;\n return vec4(finalColor, s.alpha);\n}\nvec4 CCFragOutput (vec4 color) {\n #if !CC_USE_HDR\n color.rgb = LinearToSRGB(color.rgb);\n #endif\n return color;\n}\nuniform vec4 albedo;\nuniform vec4 albedoScale;\nuniform vec4 pbrParams;\nuniform vec4 pbrScale;\nuniform vec4 emissive;\nuniform vec4 emissiveScale;\nvarying vec3 v_position;\n#if USE_ALBEDO_MAP || USE_NORMAL_MAP || USE_PBR_MAP || USE_EMISSIVE_MAP || USE_METALLIC_ROUGHNESS_MAP || USE_OCCLUSION_MAP\n varying vec2 v_uv;\n#endif\nvarying vec3 v_normal;\n#if USE_NORMAL_MAP\n varying vec3 v_tangent;\n varying vec3 v_bitangent;\n#endif\n#if USE_ALBEDO_MAP\n uniform sampler2D albedoMap;\n#endif\n#if USE_NORMAL_MAP\n uniform sampler2D normalMap;\n#endif\n#if USE_PBR_MAP\n uniform sampler2D pbrMap;\n#endif\n#if USE_METALLIC_ROUGHNESS_MAP\n uniform sampler2D metallicRoughnessMap;\n#endif\n#if USE_OCCLUSION_MAP\n uniform sampler2D occlusionMap;\n#endif\n#if USE_EMISSIVE_MAP\n uniform sampler2D emissiveMap;\n#endif\nvoid surf (out StandardSurface s) {\n vec4 baseColor = albedo;\n #if USE_ALBEDO_MAP\n vec4 texColor = texture2D(albedoMap, v_uv);\n texColor.rgb = SRGBToLinear(texColor.rgb);\n baseColor *= texColor;\n #endif\n s.albedo = baseColor.rgb * albedoScale.xyz;\n s.alpha = baseColor.a;\n #if USE_ALPHA_TEST\n if(s.alpha < albedoScale.w)\n discard;\n #endif\n s.normal = v_normal;\n #if USE_NORMAL_MAP\n vec3 nmmp = texture2D(normalMap, v_uv).xyz - vec3(0.5);\n s.normal =\n (nmmp.x * pbrScale.w) * normalize(v_tangent) +\n (nmmp.y * pbrScale.w) * normalize(v_bitangent) +\n nmmp.z * normalize(s.normal);\n #endif\n s.position = v_position;\n vec4 pbr = pbrParams;\n #if USE_PBR_MAP\n pbr = texture2D(pbrMap, v_uv);\n #endif\n #if USE_METALLIC_ROUGHNESS_MAP\n vec4 metallicRoughness = texture2D(metallicRoughnessMap, v_uv);\n pbr.METALLIC_CHANNEL = metallicRoughness.METALLIC_CHANNEL;\n pbr.ROUGHNESS_CHANNEL = metallicRoughness.ROUGHNESS_CHANNEL;\n #endif\n #if USE_OCCLUSION_MAP\n pbr.OCCLUSION_CHANNEL = texture2D(occlusionMap, v_uv).OCCLUSION_CHANNEL;\n #endif\n pbr *= pbrScale;\n s.roughness = clamp(pbr.ROUGHNESS_CHANNEL, 0.04, 1.0);\n s.metallic = clamp(pbr.METALLIC_CHANNEL, 0.0, 0.96);\n s.occlusion = pbr.OCCLUSION_CHANNEL;\n s.emissive = emissive.rgb * emissiveScale.xyz;\n #if USE_EMISSIVE_MAP\n s.emissive *= SRGBToLinear(texture2D(emissiveMap, v_uv).rgb);\n #endif\n}\nvec4 frag () {\n StandardSurface s; surf(s);\n vec4 color = CCStandardShading(s);\n return CCFragOutput(color);\n}\nvoid main() { gl_FragColor = frag(); }\n`
|
|
},
|
|
"builtins": {"globals":{"blocks":[{"name":"CCGlobal", "defines":[]}], "samplers":[{"name":"cc_environment", "defines":["CC_USE_IBL"]}]}, "locals":{"blocks":[{"name":"CCLocal", "defines":[]}, {"name":"CCSkinningTexture", "defines":["CC_USE_SKINNING"]}, {"name":"CCForwardLight", "defines":[]}], "samplers":[{"name":"cc_jointsTexture", "defines":["CC_USE_SKINNING"]}]}},
|
|
"defines": [
|
|
{"name":"CC_USE_SKINNING", "type":"number", "defines":[], "range":[0, 2]},
|
|
{"name":"USE_NORMAL_MAP", "type":"boolean", "defines":[]},
|
|
{"name":"USE_ALBEDO_MAP", "type":"boolean", "defines":[]},
|
|
{"name":"CC_USE_IBL", "type":"boolean", "defines":[]},
|
|
{"name":"CC_USE_HDR", "type":"boolean", "defines":[]},
|
|
{"name":"USE_PBR_MAP", "type":"boolean", "defines":[]},
|
|
{"name":"USE_METALLIC_ROUGHNESS_MAP", "type":"boolean", "defines":[]},
|
|
{"name":"USE_OCCLUSION_MAP", "type":"boolean", "defines":[]},
|
|
{"name":"USE_EMISSIVE_MAP", "type":"boolean", "defines":[]},
|
|
{"name":"ROUGHNESS_CHANNEL", "type":"string", "defines":[], "options":["r", "g", "b", "a"]},
|
|
{"name":"METALLIC_CHANNEL", "type":"string", "defines":[], "options":["g", "r", "b", "a"]},
|
|
{"name":"OCCLUSION_CHANNEL", "type":"string", "defines":[], "options":["b", "r", "g", "a"]},
|
|
{"name":"USE_ALPHA_TEST", "type":"boolean", "defines":[]}
|
|
],
|
|
"blocks": [
|
|
{"name": "Constants", "defines": [], "binding": 0, "members": [
|
|
{"name":"tilingOffset", "type":16, "count":1},
|
|
{"name":"albedo", "type":16, "count":1},
|
|
{"name":"albedoScale", "type":16, "count":1},
|
|
{"name":"pbrParams", "type":16, "count":1},
|
|
{"name":"pbrScale", "type":16, "count":1},
|
|
{"name":"emissive", "type":16, "count":1},
|
|
{"name":"emissiveScale", "type":16, "count":1}
|
|
]}
|
|
],
|
|
"samplers": [
|
|
{"name":"albedoMap", "type":28, "count":1, "defines":["USE_ALBEDO_MAP"], "binding":30},
|
|
{"name":"normalMap", "type":28, "count":1, "defines":["USE_NORMAL_MAP"], "binding":31},
|
|
{"name":"pbrMap", "type":28, "count":1, "defines":["USE_PBR_MAP"], "binding":32},
|
|
{"name":"metallicRoughnessMap", "type":28, "count":1, "defines":["USE_METALLIC_ROUGHNESS_MAP"], "binding":33},
|
|
{"name":"occlusionMap", "type":28, "count":1, "defines":["USE_OCCLUSION_MAP"], "binding":34},
|
|
{"name":"emissiveMap", "type":28, "count":1, "defines":["USE_EMISSIVE_MAP"], "binding":35}
|
|
],
|
|
"dependencies": {}
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"name": "builtin-terrain",
|
|
"techniques": [
|
|
{"name":"opaque", "passes":[{"program":"builtin-terrain|terrain-vs:vert|terrain-fs:frag", "properties":{"UVScale":{"value":[1, 1, 1, 1], "type":16}, "weightMap":{"value":"black", "type":28}, "detailMap0":{"value":"grey", "type":28}, "detailMap1":{"value":"grey", "type":28}, "detailMap2":{"value":"grey", "type":28}, "detailMap3":{"value":"grey", "type":28}}}]}
|
|
],
|
|
"shaders": [
|
|
{
|
|
"name": "builtin-terrain|terrain-vs:vert|terrain-fs:frag",
|
|
"hash": 2211091679,
|
|
"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 highp mat4 cc_matWorld;\n mat4 cc_matWorldIT;\n};\nin vec3 a_position;\nin vec3 a_normal;\nin vec2 a_texCoord;\nout vec2 uvw;\nout vec2 uv0;\nout vec2 uv1;\nout vec2 uv2;\nout vec2 uv3;\nout vec3 diffuse;\nuniform TexCoords {\n vec4 UVScale;\n};\nvec4 vert () {\n vec4 pos = vec4(a_position, 1);\n pos = cc_matWorld * pos;\n pos = cc_matViewProj * pos;\n uvw = a_texCoord;\n uv0 = a_position.xz * UVScale.x;\n uv1 = a_position.xz * UVScale.y;\n uv2 = a_position.xz * UVScale.z;\n uv3 = a_position.xz * UVScale.w;\n vec3 L = normalize(-cc_mainLitDir.xyz);\n vec3 N = a_normal;\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 diffuse = ambDiff + vec3(dot(N, L));\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};\nvec3 SRGBToLinear(vec3 gamma)\n{\n return pow(gamma, vec3(2.2));\n}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\n}\nvec4 CCFragOutput(vec4 color) {\n #if CC_USE_HDR\n color.rgb = mix(color.rgb, SRGBToLinear(color.rgb) * cc_exposure.w, vec3(cc_exposure.z));\n #endif\n return color;\n}\n in vec2 uvw;\n in vec2 uv0;\n in vec2 uv1;\n in vec2 uv2;\n in vec2 uv3;\n in vec3 diffuse;\n uniform sampler2D weightMap;\n uniform sampler2D detailMap0;\n uniform sampler2D detailMap1;\n uniform sampler2D detailMap2;\n uniform sampler2D detailMap3;\nvec4 frag () {\n vec4 color = vec4(0, 0, 0, 0);\n #if LAYERS == 1\n color = texture(detailMap0, uv0);\n #elif LAYERS == 2\n vec4 w = texture(weightMap, uvw);\n color += texture(detailMap0, uv0) * w.r;\n color += texture(detailMap1, uv1) * w.g;\n #elif LAYERS == 3\n vec4 w = texture(weightMap, uvw);\n color += texture(detailMap0, uv0) * w.r;\n color += texture(detailMap1, uv1) * w.g;\n color += texture(detailMap2, uv2) * w.b;\n #elif LAYERS == 4\n vec4 w = texture(weightMap, uvw);\n color += texture(detailMap0, uv0) * w.r;\n color += texture(detailMap1, uv1) * w.g;\n color += texture(detailMap2, uv2) * w.b;\n color += texture(detailMap3, uv3) * w.a;\n #else\n color = texture(detailMap0, uv0);\n #endif\n color.rgb *= diffuse;\n return CCFragOutput(color);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }\n`
|
|
},
|
|
"glsl1": {
|
|
"vert": `\nprecision mediump float;\nuniform mat4 cc_matViewProj;\nuniform vec4 cc_mainLitDir;\nuniform vec4 cc_ambientSky;\nuniform vec4 cc_ambientGround;\nuniform highp mat4 cc_matWorld;\nattribute vec3 a_position;\nattribute vec3 a_normal;\nattribute vec2 a_texCoord;\nvarying vec2 uvw;\nvarying vec2 uv0;\nvarying vec2 uv1;\nvarying vec2 uv2;\nvarying vec2 uv3;\nvarying vec3 diffuse;\nuniform vec4 UVScale;\nvec4 vert () {\n vec4 pos = vec4(a_position, 1);\n pos = cc_matWorld * pos;\n pos = cc_matViewProj * pos;\n uvw = a_texCoord;\n uv0 = a_position.xz * UVScale.x;\n uv1 = a_position.xz * UVScale.y;\n uv2 = a_position.xz * UVScale.z;\n uv3 = a_position.xz * UVScale.w;\n vec3 L = normalize(-cc_mainLitDir.xyz);\n vec3 N = a_normal;\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 diffuse = ambDiff + vec3(dot(N, L));\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n`,
|
|
"frag": `\nprecision mediump float;\nuniform vec4 cc_exposure;\nvec3 SRGBToLinear(vec3 gamma)\n{\n return pow(gamma, vec3(2.2));\n}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\n}\nvec4 CCFragOutput(vec4 color) {\n #if CC_USE_HDR\n color.rgb = mix(color.rgb, SRGBToLinear(color.rgb) * cc_exposure.w, vec3(cc_exposure.z));\n #endif\n return color;\n}\n varying vec2 uvw;\n varying vec2 uv0;\n varying vec2 uv1;\n varying vec2 uv2;\n varying vec2 uv3;\n varying vec3 diffuse;\n uniform sampler2D weightMap;\n uniform sampler2D detailMap0;\n uniform sampler2D detailMap1;\n uniform sampler2D detailMap2;\n uniform sampler2D detailMap3;\nvec4 frag () {\n vec4 color = vec4(0, 0, 0, 0);\n #if LAYERS == 1\n color = texture2D(detailMap0, uv0);\n #elif LAYERS == 2\n vec4 w = texture2D(weightMap, uvw);\n color += texture2D(detailMap0, uv0) * w.r;\n color += texture2D(detailMap1, uv1) * w.g;\n #elif LAYERS == 3\n vec4 w = texture2D(weightMap, uvw);\n color += texture2D(detailMap0, uv0) * w.r;\n color += texture2D(detailMap1, uv1) * w.g;\n color += texture2D(detailMap2, uv2) * w.b;\n #elif LAYERS == 4\n vec4 w = texture2D(weightMap, uvw);\n color += texture2D(detailMap0, uv0) * w.r;\n color += texture2D(detailMap1, uv1) * w.g;\n color += texture2D(detailMap2, uv2) * w.b;\n color += texture2D(detailMap3, uv3) * w.a;\n #else\n color = texture2D(detailMap0, uv0);\n #endif\n color.rgb *= diffuse;\n return CCFragOutput(color);\n}\nvoid main() { gl_FragColor = frag(); }\n`
|
|
},
|
|
"builtins": {"globals":{"blocks":[{"name":"CCGlobal", "defines":[]}], "samplers":[]}, "locals":{"blocks":[{"name":"CCLocal", "defines":[]}], "samplers":[]}},
|
|
"defines": [
|
|
{"name":"CC_USE_HDR", "type":"boolean", "defines":[]},
|
|
{"name":"LAYERS", "type":"number", "defines":[], "range":[0, 3]}
|
|
],
|
|
"blocks": [
|
|
{"name": "TexCoords", "defines": [], "binding": 0, "members": [
|
|
{"name":"UVScale", "type":16, "count":1}
|
|
]}
|
|
],
|
|
"samplers": [
|
|
{"name":"weightMap", "type":28, "count":1, "defines":[], "binding":30},
|
|
{"name":"detailMap0", "type":28, "count":1, "defines":[], "binding":31},
|
|
{"name":"detailMap1", "type":28, "count":1, "defines":[], "binding":32},
|
|
{"name":"detailMap2", "type":28, "count":1, "defines":[], "binding":33},
|
|
{"name":"detailMap3", "type":28, "count":1, "defines":[], "binding":34}
|
|
],
|
|
"dependencies": {}
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"name": "builtin-unlit",
|
|
"techniques": [
|
|
{"name":"opaque", "passes":[{"program":"builtin-unlit|unlit-vs:vert|unlit-fs:frag", "properties":{"color":{"value":[1, 1, 1, 1], "inspector":{"type":"color"}, "type":16}, "tilingOffset":{"value":[1, 1, 0, 0], "type":16}, "mainTexture":{"value":"grey", "type":28}}}]}
|
|
],
|
|
"shaders": [
|
|
{
|
|
"name": "builtin-unlit|unlit-vs:vert|unlit-fs:frag",
|
|
"hash": 1799561064,
|
|
"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 highp mat4 cc_matWorld;\n mat4 cc_matWorldIT;\n};\nin vec3 a_position;\nvoid CCDecode (out vec3 position) {\n position = a_position;\n}\n#if CC_USE_SKINNING\nstruct StandardAttributes {\n vec3 position;\n vec3 normal;\n vec4 tangent;\n};\nin vec4 a_weights;\nin vec4 a_joints;\nuniform CCSkinningTexture {\n highp vec4 cc_jointsTextureInfo;\n};\nuniform sampler2D cc_jointsTexture;\n#if CC_USE_SKINNING == 1\n highp float decode32(highp vec4 rgba) {\n rgba = rgba * 255.0;\n highp float Sign = 1.0 - step(128.0, rgba[3]) * 2.0;\n highp float Exponent = 2.0 * mod(rgba[3], 128.0) + step(128.0, rgba[2]) - 127.0;\n highp float Mantissa = mod(rgba[2], 128.0) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\n }\n#endif\n#if CC_USE_SKINNING == 1\n void getJointDQ(float i, out vec4 Qr, out vec4 Qt, out vec3 S) {\n highp float j = 12.0 * (cc_jointsTextureInfo.z * i + cc_jointsTextureInfo.w) + cc_jointsTextureInfo.y;\n highp float invSize = 1.0 / cc_jointsTextureInfo.x;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointsTextureInfo.x;\n y = (y + 0.5) * invSize;\n Qr = vec4(\n decode32(texture(cc_jointsTexture, vec2((x + 0.5) * invSize, y))),\n decode32(texture(cc_jointsTexture, vec2((x + 1.5) * invSize, y))),\n decode32(texture(cc_jointsTexture, vec2((x + 2.5) * invSize, y))),\n decode32(texture(cc_jointsTexture, vec2((x + 3.5) * invSize, y)))\n );\n Qt = vec4(\n decode32(texture(cc_jointsTexture, vec2((x + 4.5) * invSize, y))),\n decode32(texture(cc_jointsTexture, vec2((x + 5.5) * invSize, y))),\n decode32(texture(cc_jointsTexture, vec2((x + 6.5) * invSize, y))),\n decode32(texture(cc_jointsTexture, vec2((x + 7.5) * invSize, y)))\n );\n S = vec3(\n decode32(texture(cc_jointsTexture, vec2((x + 8.5) * invSize, y))),\n decode32(texture(cc_jointsTexture, vec2((x + 9.5) * invSize, y))),\n decode32(texture(cc_jointsTexture, vec2((x + 10.5) * invSize, y)))\n );\n }\n#elif CC_USE_SKINNING == 2\n void getJointDQ(float i, out vec4 Qr, out vec4 Qt, out vec3 S) {\n highp float j = 3.0 * (cc_jointsTextureInfo.z * i + cc_jointsTextureInfo.w) + cc_jointsTextureInfo.y;\n highp float invSize = 1.0 / cc_jointsTextureInfo.x;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointsTextureInfo.x;\n y = (y + 0.5) * invSize;\n Qr = texture(cc_jointsTexture, vec2((x + 0.5) * invSize, y));\n Qt = texture(cc_jointsTexture, vec2((x + 1.5) * invSize, y));\n S = texture(cc_jointsTexture, vec2((x + 2.5) * invSize, y)).xyz;\n }\n#endif\nvoid skinRTS(out vec4 R, out vec3 T, out vec3 S) {\n vec4 r, t, Qt = vec4(0.0); vec3 s;\n R = vec4(0.0); S = vec3(0.0);\n for (int i = 0; i < 4; i++) {\n float w = a_weights[i];\n getJointDQ(a_joints[i], r, t, s);\n S += s * w; R += r * w; Qt += t * w;\n }\n float invNorm = 1.0 / length(R); R *= invNorm; Qt *= invNorm;\n T = 2.0 * (R.w * Qt.xyz - Qt.w * R.xyz + cross(R.xyz, Qt.xyz));\n}\nvec3 VectorTransformQuat(vec3 v, vec4 Q) {\n return v + 2.0 * cross(Q.xyz, cross(Q.xyz, v) + Q.w * v);\n}\nvoid CCSkin(inout vec3 position) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n position = VectorTransformQuat(position * S, R) + T;\n}\nvoid CCSkin(inout StandardAttributes attr) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n attr.position = VectorTransformQuat(attr.position * S, R) + T;\n attr.normal = VectorTransformQuat(attr.normal, R);\n attr.tangent.xyz = VectorTransformQuat(attr.tangent.xyz, R);\n}\n#endif\nvoid CCVertInput (out highp vec3 position) {\n CCDecode(position);\n #if CC_USE_SKINNING\n CCSkin(position);\n #endif\n}\n#if USE_VERTEX_COLOR\n in vec4 a_color;\n out vec4 v_color;\n#endif\n#if USE_TEXTURE\n in vec2 a_texCoord;\n out vec2 v_uv;\n uniform TexCoords {\n vec4 tilingOffset;\n };\n#endif\nhighp vec4 vert () {\n vec3 position;\n CCVertInput(position);\n highp vec4 pos = cc_matViewProj * cc_matWorld * vec4(position, 1.0);\n #if USE_TEXTURE\n v_uv = a_texCoord * tilingOffset.xy + tilingOffset.zw;\n #endif\n #if USE_VERTEX_COLOR\n v_color = a_color;\n #endif\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n`,
|
|
"frag": `\nprecision mediump float;\nuniform CCGlobal {\n vec4 cc_time;\n vec4 cc_screenSize;\n vec4 cc_screenScale;\n vec4 cc_nativeSize;\n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos;\n vec4 cc_exposure;\n vec4 cc_mainLitDir;\n vec4 cc_mainLitColor;\n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\nvec3 SRGBToLinear(vec3 gamma)\n{\n return pow(gamma, vec3(2.2));\n}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\n}\nvec4 CCFragOutput(vec4 color) {\n #if CC_USE_HDR\n color.rgb = mix(color.rgb, SRGBToLinear(color.rgb) * cc_exposure.w, vec3(cc_exposure.z));\n #endif\n return color;\n}\n#if USE_TEXTURE\n in vec2 v_uv;\n uniform sampler2D mainTexture;\n#endif\n#if USE_COLOR\n uniform Constant {\n vec4 color;\n };\n#endif\n#if USE_VERTEX_COLOR\n in vec4 v_color;\n#endif\nvec4 frag () {\n vec4 o = vec4(1, 1, 1, 1);\n #if USE_TEXTURE\n o *= texture(mainTexture, v_uv);\n #endif\n #if USE_COLOR\n o *= color;\n #endif\n #if USE_VERTEX_COLOR\n o *= v_color;\n #endif\n return CCFragOutput(o);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }\n`
|
|
},
|
|
"glsl1": {
|
|
"vert": `\nprecision mediump float;\nuniform mat4 cc_matViewProj;\nuniform highp mat4 cc_matWorld;\nattribute vec3 a_position;\nvoid CCDecode (out vec3 position) {\n position = a_position;\n}\n#if CC_USE_SKINNING\nstruct StandardAttributes {\n vec3 position;\n vec3 normal;\n vec4 tangent;\n};\nattribute vec4 a_weights;\nattribute vec4 a_joints;\nuniform highp vec4 cc_jointsTextureInfo;\nuniform sampler2D cc_jointsTexture;\n#if CC_USE_SKINNING == 1\n highp float decode32(highp vec4 rgba) {\n rgba = rgba * 255.0;\n highp float Sign = 1.0 - step(128.0, rgba[3]) * 2.0;\n highp float Exponent = 2.0 * mod(rgba[3], 128.0) + step(128.0, rgba[2]) - 127.0;\n highp float Mantissa = mod(rgba[2], 128.0) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\n }\n#endif\n#if CC_USE_SKINNING == 1\n void getJointDQ(float i, out vec4 Qr, out vec4 Qt, out vec3 S) {\n highp float j = 12.0 * (cc_jointsTextureInfo.z * i + cc_jointsTextureInfo.w) + cc_jointsTextureInfo.y;\n highp float invSize = 1.0 / cc_jointsTextureInfo.x;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointsTextureInfo.x;\n y = (y + 0.5) * invSize;\n Qr = vec4(\n decode32(texture2D(cc_jointsTexture, vec2((x + 0.5) * invSize, y))),\n decode32(texture2D(cc_jointsTexture, vec2((x + 1.5) * invSize, y))),\n decode32(texture2D(cc_jointsTexture, vec2((x + 2.5) * invSize, y))),\n decode32(texture2D(cc_jointsTexture, vec2((x + 3.5) * invSize, y)))\n );\n Qt = vec4(\n decode32(texture2D(cc_jointsTexture, vec2((x + 4.5) * invSize, y))),\n decode32(texture2D(cc_jointsTexture, vec2((x + 5.5) * invSize, y))),\n decode32(texture2D(cc_jointsTexture, vec2((x + 6.5) * invSize, y))),\n decode32(texture2D(cc_jointsTexture, vec2((x + 7.5) * invSize, y)))\n );\n S = vec3(\n decode32(texture2D(cc_jointsTexture, vec2((x + 8.5) * invSize, y))),\n decode32(texture2D(cc_jointsTexture, vec2((x + 9.5) * invSize, y))),\n decode32(texture2D(cc_jointsTexture, vec2((x + 10.5) * invSize, y)))\n );\n }\n#elif CC_USE_SKINNING == 2\n void getJointDQ(float i, out vec4 Qr, out vec4 Qt, out vec3 S) {\n highp float j = 3.0 * (cc_jointsTextureInfo.z * i + cc_jointsTextureInfo.w) + cc_jointsTextureInfo.y;\n highp float invSize = 1.0 / cc_jointsTextureInfo.x;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointsTextureInfo.x;\n y = (y + 0.5) * invSize;\n Qr = texture2D(cc_jointsTexture, vec2((x + 0.5) * invSize, y));\n Qt = texture2D(cc_jointsTexture, vec2((x + 1.5) * invSize, y));\n S = texture2D(cc_jointsTexture, vec2((x + 2.5) * invSize, y)).xyz;\n }\n#endif\nvoid skinRTS(out vec4 R, out vec3 T, out vec3 S) {\n vec4 r, t, Qt = vec4(0.0); vec3 s;\n R = vec4(0.0); S = vec3(0.0);\n for (int i = 0; i < 4; i++) {\n float w = a_weights[i];\n getJointDQ(a_joints[i], r, t, s);\n S += s * w; R += r * w; Qt += t * w;\n }\n float invNorm = 1.0 / length(R); R *= invNorm; Qt *= invNorm;\n T = 2.0 * (R.w * Qt.xyz - Qt.w * R.xyz + cross(R.xyz, Qt.xyz));\n}\nvec3 VectorTransformQuat(vec3 v, vec4 Q) {\n return v + 2.0 * cross(Q.xyz, cross(Q.xyz, v) + Q.w * v);\n}\nvoid CCSkin(inout vec3 position) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n position = VectorTransformQuat(position * S, R) + T;\n}\nvoid CCSkin(inout StandardAttributes attr) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n attr.position = VectorTransformQuat(attr.position * S, R) + T;\n attr.normal = VectorTransformQuat(attr.normal, R);\n attr.tangent.xyz = VectorTransformQuat(attr.tangent.xyz, R);\n}\n#endif\nvoid CCVertInput (out highp vec3 position) {\n CCDecode(position);\n #if CC_USE_SKINNING\n CCSkin(position);\n #endif\n}\n#if USE_VERTEX_COLOR\n attribute vec4 a_color;\n varying vec4 v_color;\n#endif\n#if USE_TEXTURE\n attribute vec2 a_texCoord;\n varying vec2 v_uv;\n uniform vec4 tilingOffset;\n#endif\nhighp vec4 vert () {\n vec3 position;\n CCVertInput(position);\n highp vec4 pos = cc_matViewProj * cc_matWorld * vec4(position, 1.0);\n #if USE_TEXTURE\n v_uv = a_texCoord * tilingOffset.xy + tilingOffset.zw;\n #endif\n #if USE_VERTEX_COLOR\n v_color = a_color;\n #endif\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n`,
|
|
"frag": `\nprecision mediump float;\nuniform vec4 cc_exposure;\nvec3 SRGBToLinear(vec3 gamma)\n{\n return pow(gamma, vec3(2.2));\n}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\n}\nvec4 CCFragOutput(vec4 color) {\n #if CC_USE_HDR\n color.rgb = mix(color.rgb, SRGBToLinear(color.rgb) * cc_exposure.w, vec3(cc_exposure.z));\n #endif\n return color;\n}\n#if USE_TEXTURE\n varying vec2 v_uv;\n uniform sampler2D mainTexture;\n#endif\n#if USE_COLOR\n uniform vec4 color;\n#endif\n#if USE_VERTEX_COLOR\n varying vec4 v_color;\n#endif\nvec4 frag () {\n vec4 o = vec4(1, 1, 1, 1);\n #if USE_TEXTURE\n o *= texture2D(mainTexture, v_uv);\n #endif\n #if USE_COLOR\n o *= color;\n #endif\n #if USE_VERTEX_COLOR\n o *= v_color;\n #endif\n return CCFragOutput(o);\n}\nvoid main() { gl_FragColor = frag(); }\n`
|
|
},
|
|
"builtins": {"globals":{"blocks":[{"name":"CCGlobal", "defines":[]}], "samplers":[]}, "locals":{"blocks":[{"name":"CCLocal", "defines":[]}, {"name":"CCSkinningTexture", "defines":["CC_USE_SKINNING"]}], "samplers":[{"name":"cc_jointsTexture", "defines":["CC_USE_SKINNING"]}]}},
|
|
"defines": [
|
|
{"name":"CC_USE_SKINNING", "type":"number", "defines":[], "range":[0, 2]},
|
|
{"name":"USE_VERTEX_COLOR", "type":"boolean", "defines":[]},
|
|
{"name":"USE_TEXTURE", "type":"boolean", "defines":[]},
|
|
{"name":"CC_USE_HDR", "type":"boolean", "defines":[]},
|
|
{"name":"USE_COLOR", "type":"boolean", "defines":[]}
|
|
],
|
|
"blocks": [
|
|
{"name": "TexCoords", "defines": ["USE_TEXTURE"], "binding": 0, "members": [
|
|
{"name":"tilingOffset", "type":16, "count":1}
|
|
]},
|
|
{"name": "Constant", "defines": ["USE_COLOR"], "binding": 1, "members": [
|
|
{"name":"color", "type":16, "count":1}
|
|
]}
|
|
],
|
|
"samplers": [
|
|
{"name":"mainTexture", "type":28, "count":1, "defines":["USE_TEXTURE"], "binding":30}
|
|
],
|
|
"dependencies": {}
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"name": "editor/terrain-circle-brush",
|
|
"techniques": [
|
|
{"name":"transparent", "passes":[{"blendState":{"targets":[{"blend":true, "blendSrc":2, "blendDst":4, "blendDstAlpha":4}]}, "program":"editor/terrain-circle-brush|terrain-brush-vs:vert|terrain-brush-fs:frag", "depthStencilState":{"depthTest":true, "depthWrite":false}, "properties":{"BrushPos":{"value":[0, 0, 0, 1], "type":16}, "BrushParams":{"value":[2.5, 2.5, 0, 0], "type":16}}}]}
|
|
],
|
|
"shaders": [
|
|
{
|
|
"name": "editor/terrain-circle-brush|terrain-brush-vs:vert|terrain-brush-fs:frag",
|
|
"hash": 3864386462,
|
|
"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 highp mat4 cc_matWorld;\n mat4 cc_matWorldIT;\n};\nin vec3 a_position;\nout vec4 wposition;\nvec4 vert () {\n vec4 pos = vec4(a_position, 1);\n wposition = cc_matWorld * pos;\n wposition.y += 0.01;\n pos = cc_matViewProj * wposition;\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};\nvec3 SRGBToLinear(vec3 gamma)\n{\n return pow(gamma, vec3(2.2));\n}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\n}\nvec4 CCFragOutput(vec4 color) {\n #if CC_USE_HDR\n color.rgb = mix(color.rgb, SRGBToLinear(color.rgb) * cc_exposure.w, vec3(cc_exposure.z));\n #endif\n return color;\n}\nin vec4 wposition;\nuniform TexCoords {\n vec4 BrushPos;\n vec4 BrushParams;\n};\nvec4 frag () {\n float Radius = BrushParams.x;\n float Falloff = BrushParams.y;\n float Distance = length(wposition.xz - BrushPos.xz);\n float k = 0.0;\n #if LINEAR\n if (Distance <= Radius) {\n k = 1.0;\n }\n else if (Distance > Radius + Falloff) {\n k = 0.0;\n }\n else {\n k = max(0.0, 1.0 - (Distance - Radius) / Falloff);\n }\n #elif SMOOTH\n if (Distance <= Radius) {\n k = 1.0;\n }\n else if (Distance > Radius + Falloff) {\n k = 0.0;\n }\n else {\n float y = (Distance - Radius) / Falloff;\n k = sqrt(1.0 - y * y);\n }\n #elif SPHERICAL\n if (Distance <= Radius) {\n k = 1.0;\n }\n else if (Distance > Radius + Falloff) {\n k = 0.0;\n }\n else {\n k = max(0.0, 1.0 - (Distance - Radius) / Falloff);\n }\n k = k*k*(3 - 2 * k);\n #elif TIP\n if (Distance <= Radius) {\n k = 1.0;\n }\n else if (Distance > Radius + Falloff) {\n k = 0.0;\n }\n else {\n float y = (Falloff + Radius - Distance) / Falloff;\n k = 1.0 - sqrt(1.0 - y * y);\n }\n #endif\n vec4 color = vec4(0, 0, 0, 0);\n color.rgb = vec3(100, 100, 135) / 255.0;\n color.a = 0.85 * k;\n return CCFragOutput(color);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }\n`
|
|
},
|
|
"glsl1": {
|
|
"vert": `\nprecision mediump float;\nuniform mat4 cc_matViewProj;\nuniform highp mat4 cc_matWorld;\nattribute vec3 a_position;\nvarying vec4 wposition;\nvec4 vert () {\n vec4 pos = vec4(a_position, 1);\n wposition = cc_matWorld * pos;\n wposition.y += 0.01;\n pos = cc_matViewProj * wposition;\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n`,
|
|
"frag": `\nprecision mediump float;\nuniform vec4 cc_exposure;\nvec3 SRGBToLinear(vec3 gamma)\n{\n return pow(gamma, vec3(2.2));\n}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\n}\nvec4 CCFragOutput(vec4 color) {\n #if CC_USE_HDR\n color.rgb = mix(color.rgb, SRGBToLinear(color.rgb) * cc_exposure.w, vec3(cc_exposure.z));\n #endif\n return color;\n}\nvarying vec4 wposition;\nuniform vec4 BrushPos;\nuniform vec4 BrushParams;\nvec4 frag () {\n float Radius = BrushParams.x;\n float Falloff = BrushParams.y;\n float Distance = length(wposition.xz - BrushPos.xz);\n float k = 0.0;\n #if LINEAR\n if (Distance <= Radius) {\n k = 1.0;\n }\n else if (Distance > Radius + Falloff) {\n k = 0.0;\n }\n else {\n k = max(0.0, 1.0 - (Distance - Radius) / Falloff);\n }\n #elif SMOOTH\n if (Distance <= Radius) {\n k = 1.0;\n }\n else if (Distance > Radius + Falloff) {\n k = 0.0;\n }\n else {\n float y = (Distance - Radius) / Falloff;\n k = sqrt(1.0 - y * y);\n }\n #elif SPHERICAL\n if (Distance <= Radius) {\n k = 1.0;\n }\n else if (Distance > Radius + Falloff) {\n k = 0.0;\n }\n else {\n k = max(0.0, 1.0 - (Distance - Radius) / Falloff);\n }\n k = k*k*(3 - 2 * k);\n #elif TIP\n if (Distance <= Radius) {\n k = 1.0;\n }\n else if (Distance > Radius + Falloff) {\n k = 0.0;\n }\n else {\n float y = (Falloff + Radius - Distance) / Falloff;\n k = 1.0 - sqrt(1.0 - y * y);\n }\n #endif\n vec4 color = vec4(0, 0, 0, 0);\n color.rgb = vec3(100, 100, 135) / 255.0;\n color.a = 0.85 * k;\n return CCFragOutput(color);\n}\nvoid main() { gl_FragColor = frag(); }\n`
|
|
},
|
|
"builtins": {"globals":{"blocks":[{"name":"CCGlobal", "defines":[]}], "samplers":[]}, "locals":{"blocks":[{"name":"CCLocal", "defines":[]}], "samplers":[]}},
|
|
"defines": [
|
|
{"name":"CC_USE_HDR", "type":"boolean", "defines":[]},
|
|
{"name":"LINEAR", "type":"boolean", "defines":[]},
|
|
{"name":"SMOOTH", "type":"boolean", "defines":[]},
|
|
{"name":"SPHERICAL", "type":"boolean", "defines":[]},
|
|
{"name":"TIP", "type":"boolean", "defines":[]}
|
|
],
|
|
"blocks": [
|
|
{"name": "TexCoords", "defines": [], "binding": 0, "members": [
|
|
{"name":"BrushPos", "type":16, "count":1},
|
|
{"name":"BrushParams", "type":16, "count":1}
|
|
]}
|
|
],
|
|
"samplers": [],
|
|
"dependencies": {}
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"name": "pipeline/planar-shadow",
|
|
"techniques": [
|
|
{"passes":[{"phase":"planarShadow", "blendState":{"targets":[{"blend":true, "blendSrc":2, "blendDst":4, "blendDstAlpha":4}]}, "program":"pipeline/planar-shadow|planar-shadow-vs:vert|planar-shadow-fs:frag", "depthStencilState":{"depthTest":true, "depthWrite":false, "stencilTestFront":true, "stencilFuncFront":5, "stencilPassOpFront":2, "stencilWriteMaskBack":128, "stencilWriteMaskFront":128, "stencilReadMaskBack":128, "stencilReadMaskFront":128, "stencilRefBack":128, "stencilRefFront":128}}]}
|
|
],
|
|
"shaders": [
|
|
{
|
|
"name": "pipeline/planar-shadow|planar-shadow-vs:vert|planar-shadow-fs:frag",
|
|
"hash": 3410639340,
|
|
"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 highp mat4 cc_matWorld;\n mat4 cc_matWorldIT;\n};\nuniform CCShadow {\n mat4 cc_matLightPlaneProj;\n vec4 cc_shadowColor;\n};\nin vec3 a_position;\nvoid CCDecode (out vec3 position) {\n position = a_position;\n}\n#if CC_USE_SKINNING\nstruct StandardAttributes {\n vec3 position;\n vec3 normal;\n vec4 tangent;\n};\nin vec4 a_weights;\nin vec4 a_joints;\nuniform CCSkinningTexture {\n highp vec4 cc_jointsTextureInfo;\n};\nuniform sampler2D cc_jointsTexture;\n#if CC_USE_SKINNING == 1\n highp float decode32(highp vec4 rgba) {\n rgba = rgba * 255.0;\n highp float Sign = 1.0 - step(128.0, rgba[3]) * 2.0;\n highp float Exponent = 2.0 * mod(rgba[3], 128.0) + step(128.0, rgba[2]) - 127.0;\n highp float Mantissa = mod(rgba[2], 128.0) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\n }\n#endif\n#if CC_USE_SKINNING == 1\n void getJointDQ(float i, out vec4 Qr, out vec4 Qt, out vec3 S) {\n highp float j = 12.0 * (cc_jointsTextureInfo.z * i + cc_jointsTextureInfo.w) + cc_jointsTextureInfo.y;\n highp float invSize = 1.0 / cc_jointsTextureInfo.x;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointsTextureInfo.x;\n y = (y + 0.5) * invSize;\n Qr = vec4(\n decode32(texture(cc_jointsTexture, vec2((x + 0.5) * invSize, y))),\n decode32(texture(cc_jointsTexture, vec2((x + 1.5) * invSize, y))),\n decode32(texture(cc_jointsTexture, vec2((x + 2.5) * invSize, y))),\n decode32(texture(cc_jointsTexture, vec2((x + 3.5) * invSize, y)))\n );\n Qt = vec4(\n decode32(texture(cc_jointsTexture, vec2((x + 4.5) * invSize, y))),\n decode32(texture(cc_jointsTexture, vec2((x + 5.5) * invSize, y))),\n decode32(texture(cc_jointsTexture, vec2((x + 6.5) * invSize, y))),\n decode32(texture(cc_jointsTexture, vec2((x + 7.5) * invSize, y)))\n );\n S = vec3(\n decode32(texture(cc_jointsTexture, vec2((x + 8.5) * invSize, y))),\n decode32(texture(cc_jointsTexture, vec2((x + 9.5) * invSize, y))),\n decode32(texture(cc_jointsTexture, vec2((x + 10.5) * invSize, y)))\n );\n }\n#elif CC_USE_SKINNING == 2\n void getJointDQ(float i, out vec4 Qr, out vec4 Qt, out vec3 S) {\n highp float j = 3.0 * (cc_jointsTextureInfo.z * i + cc_jointsTextureInfo.w) + cc_jointsTextureInfo.y;\n highp float invSize = 1.0 / cc_jointsTextureInfo.x;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointsTextureInfo.x;\n y = (y + 0.5) * invSize;\n Qr = texture(cc_jointsTexture, vec2((x + 0.5) * invSize, y));\n Qt = texture(cc_jointsTexture, vec2((x + 1.5) * invSize, y));\n S = texture(cc_jointsTexture, vec2((x + 2.5) * invSize, y)).xyz;\n }\n#endif\nvoid skinRTS(out vec4 R, out vec3 T, out vec3 S) {\n vec4 r, t, Qt = vec4(0.0); vec3 s;\n R = vec4(0.0); S = vec3(0.0);\n for (int i = 0; i < 4; i++) {\n float w = a_weights[i];\n getJointDQ(a_joints[i], r, t, s);\n S += s * w; R += r * w; Qt += t * w;\n }\n float invNorm = 1.0 / length(R); R *= invNorm; Qt *= invNorm;\n T = 2.0 * (R.w * Qt.xyz - Qt.w * R.xyz + cross(R.xyz, Qt.xyz));\n}\nvec3 VectorTransformQuat(vec3 v, vec4 Q) {\n return v + 2.0 * cross(Q.xyz, cross(Q.xyz, v) + Q.w * v);\n}\nvoid CCSkin(inout vec3 position) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n position = VectorTransformQuat(position * S, R) + T;\n}\nvoid CCSkin(inout StandardAttributes attr) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n attr.position = VectorTransformQuat(attr.position * S, R) + T;\n attr.normal = VectorTransformQuat(attr.normal, R);\n attr.tangent.xyz = VectorTransformQuat(attr.tangent.xyz, R);\n}\n#endif\nvoid CCVertInput (out highp vec3 position) {\n CCDecode(position);\n #if CC_USE_SKINNING\n CCSkin(position);\n #endif\n}\nvec4 vert () {\n vec3 position;\n CCVertInput(position);\n vec4 pos = cc_matWorld * vec4(position, 1.0);\n pos = cc_matViewProj * cc_matLightPlaneProj * pos;\n pos.z -= 0.0001;\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n`,
|
|
"frag": `\nprecision mediump float;\nuniform CCShadow {\n mat4 cc_matLightPlaneProj;\n vec4 cc_shadowColor;\n};\nuniform CCGlobal {\n vec4 cc_time;\n vec4 cc_screenSize;\n vec4 cc_screenScale;\n vec4 cc_nativeSize;\n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos;\n vec4 cc_exposure;\n vec4 cc_mainLitDir;\n vec4 cc_mainLitColor;\n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\nvec3 SRGBToLinear(vec3 gamma)\n{\n return pow(gamma, vec3(2.2));\n}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\n}\nvec4 CCFragOutput(vec4 color) {\n #if CC_USE_HDR\n color.rgb = mix(color.rgb, SRGBToLinear(color.rgb) * cc_exposure.w, vec3(cc_exposure.z));\n #endif\n return color;\n}\nvec4 frag () {\n return CCFragOutput(cc_shadowColor);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }\n`
|
|
},
|
|
"glsl1": {
|
|
"vert": `\nprecision mediump float;\nuniform mat4 cc_matViewProj;\nuniform highp mat4 cc_matWorld;\nuniform mat4 cc_matLightPlaneProj;\nattribute vec3 a_position;\nvoid CCDecode (out vec3 position) {\n position = a_position;\n}\n#if CC_USE_SKINNING\nstruct StandardAttributes {\n vec3 position;\n vec3 normal;\n vec4 tangent;\n};\nattribute vec4 a_weights;\nattribute vec4 a_joints;\nuniform highp vec4 cc_jointsTextureInfo;\nuniform sampler2D cc_jointsTexture;\n#if CC_USE_SKINNING == 1\n highp float decode32(highp vec4 rgba) {\n rgba = rgba * 255.0;\n highp float Sign = 1.0 - step(128.0, rgba[3]) * 2.0;\n highp float Exponent = 2.0 * mod(rgba[3], 128.0) + step(128.0, rgba[2]) - 127.0;\n highp float Mantissa = mod(rgba[2], 128.0) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\n }\n#endif\n#if CC_USE_SKINNING == 1\n void getJointDQ(float i, out vec4 Qr, out vec4 Qt, out vec3 S) {\n highp float j = 12.0 * (cc_jointsTextureInfo.z * i + cc_jointsTextureInfo.w) + cc_jointsTextureInfo.y;\n highp float invSize = 1.0 / cc_jointsTextureInfo.x;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointsTextureInfo.x;\n y = (y + 0.5) * invSize;\n Qr = vec4(\n decode32(texture2D(cc_jointsTexture, vec2((x + 0.5) * invSize, y))),\n decode32(texture2D(cc_jointsTexture, vec2((x + 1.5) * invSize, y))),\n decode32(texture2D(cc_jointsTexture, vec2((x + 2.5) * invSize, y))),\n decode32(texture2D(cc_jointsTexture, vec2((x + 3.5) * invSize, y)))\n );\n Qt = vec4(\n decode32(texture2D(cc_jointsTexture, vec2((x + 4.5) * invSize, y))),\n decode32(texture2D(cc_jointsTexture, vec2((x + 5.5) * invSize, y))),\n decode32(texture2D(cc_jointsTexture, vec2((x + 6.5) * invSize, y))),\n decode32(texture2D(cc_jointsTexture, vec2((x + 7.5) * invSize, y)))\n );\n S = vec3(\n decode32(texture2D(cc_jointsTexture, vec2((x + 8.5) * invSize, y))),\n decode32(texture2D(cc_jointsTexture, vec2((x + 9.5) * invSize, y))),\n decode32(texture2D(cc_jointsTexture, vec2((x + 10.5) * invSize, y)))\n );\n }\n#elif CC_USE_SKINNING == 2\n void getJointDQ(float i, out vec4 Qr, out vec4 Qt, out vec3 S) {\n highp float j = 3.0 * (cc_jointsTextureInfo.z * i + cc_jointsTextureInfo.w) + cc_jointsTextureInfo.y;\n highp float invSize = 1.0 / cc_jointsTextureInfo.x;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointsTextureInfo.x;\n y = (y + 0.5) * invSize;\n Qr = texture2D(cc_jointsTexture, vec2((x + 0.5) * invSize, y));\n Qt = texture2D(cc_jointsTexture, vec2((x + 1.5) * invSize, y));\n S = texture2D(cc_jointsTexture, vec2((x + 2.5) * invSize, y)).xyz;\n }\n#endif\nvoid skinRTS(out vec4 R, out vec3 T, out vec3 S) {\n vec4 r, t, Qt = vec4(0.0); vec3 s;\n R = vec4(0.0); S = vec3(0.0);\n for (int i = 0; i < 4; i++) {\n float w = a_weights[i];\n getJointDQ(a_joints[i], r, t, s);\n S += s * w; R += r * w; Qt += t * w;\n }\n float invNorm = 1.0 / length(R); R *= invNorm; Qt *= invNorm;\n T = 2.0 * (R.w * Qt.xyz - Qt.w * R.xyz + cross(R.xyz, Qt.xyz));\n}\nvec3 VectorTransformQuat(vec3 v, vec4 Q) {\n return v + 2.0 * cross(Q.xyz, cross(Q.xyz, v) + Q.w * v);\n}\nvoid CCSkin(inout vec3 position) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n position = VectorTransformQuat(position * S, R) + T;\n}\nvoid CCSkin(inout StandardAttributes attr) {\n vec4 R; vec3 T, S;\n skinRTS(R, T, S);\n attr.position = VectorTransformQuat(attr.position * S, R) + T;\n attr.normal = VectorTransformQuat(attr.normal, R);\n attr.tangent.xyz = VectorTransformQuat(attr.tangent.xyz, R);\n}\n#endif\nvoid CCVertInput (out highp vec3 position) {\n CCDecode(position);\n #if CC_USE_SKINNING\n CCSkin(position);\n #endif\n}\nvec4 vert () {\n vec3 position;\n CCVertInput(position);\n vec4 pos = cc_matWorld * vec4(position, 1.0);\n pos = cc_matViewProj * cc_matLightPlaneProj * pos;\n pos.z -= 0.0001;\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n`,
|
|
"frag": `\nprecision mediump float;\nuniform vec4 cc_shadowColor;\nuniform vec4 cc_exposure;\nvec3 SRGBToLinear(vec3 gamma)\n{\n return pow(gamma, vec3(2.2));\n}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\n}\nvec4 CCFragOutput(vec4 color) {\n #if CC_USE_HDR\n color.rgb = mix(color.rgb, SRGBToLinear(color.rgb) * cc_exposure.w, vec3(cc_exposure.z));\n #endif\n return color;\n}\nvec4 frag () {\n return CCFragOutput(cc_shadowColor);\n}\nvoid main() { gl_FragColor = frag(); }\n`
|
|
},
|
|
"builtins": {"globals":{"blocks":[{"name":"CCGlobal", "defines":[]}, {"name":"CCShadow", "defines":[]}], "samplers":[]}, "locals":{"blocks":[{"name":"CCLocal", "defines":[]}, {"name":"CCSkinningTexture", "defines":["CC_USE_SKINNING"]}], "samplers":[{"name":"cc_jointsTexture", "defines":["CC_USE_SKINNING"]}]}},
|
|
"defines": [
|
|
{"name":"CC_USE_SKINNING", "type":"number", "defines":[], "range":[0, 2]},
|
|
{"name":"CC_USE_HDR", "type":"boolean", "defines":[]}
|
|
],
|
|
"blocks": [],
|
|
"samplers": [],
|
|
"dependencies": {}
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"name": "pipeline/smaa",
|
|
"techniques": [
|
|
{"name":"smaa", "passes":[{"program":"pipeline/smaa|smaa-edge-vs:vert|smaa-edge-fs:frag", "depthStencilState":{"depthTest":false, "depthWrite":false}, "properties":{"u_texSampler":{"sampler":[2, 2, null, 2, 2], "type":28}}}, {"program":"pipeline/smaa|smaa-blend-vs:vert|smaa-blend-fs:frag", "depthStencilState":{"depthTest":false, "depthWrite":false}, "properties":{"u_edgeTexSampler":{"sampler":[2, 2, null, 2, 2], "type":28}, "u_areaTexSampler":{"sampler":[2, 2, null, 2, 2], "type":28}, "u_searchTexSampler":{"sampler":[1, 1, null, 2, 2], "type":28}}}]}
|
|
],
|
|
"shaders": [
|
|
{
|
|
"name": "pipeline/smaa|smaa-edge-vs:vert|smaa-edge-fs:frag",
|
|
"hash": 467513197,
|
|
"glsl3": {
|
|
"vert": `\nprecision highp float;\nuniform CCGlobal {\n vec4 cc_time;\n vec4 cc_screenSize;\n vec4 cc_screenScale;\n vec4 cc_nativeSize;\n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos;\n vec4 cc_exposure;\n vec4 cc_mainLitDir;\n vec4 cc_mainLitColor;\n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\nin vec2 a_position;\nin vec2 a_texCoord;\nout vec2 v_uv;\nout vec4 v_offsets[3];\nvec4 vert () {\n vec4 pos = vec4(a_position, 0.0, 1.0);\n v_uv = a_texCoord * cc_screenScale.xy;\n v_offsets[0] = v_uv.xyxy + cc_nativeSize.zwzw * vec4(-1.0, 0.0, 0.0, 1.0);\n v_offsets[1] = v_uv.xyxy + cc_nativeSize.zwzw * vec4( 1.0, 0.0, 0.0, -1.0);\n v_offsets[2] = v_uv.xyxy + cc_nativeSize.zwzw * vec4(-2.0, 0.0, 0.0, 2.0);\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n`,
|
|
"frag": `\nprecision highp float;\nuniform CCGlobal {\n vec4 cc_time;\n vec4 cc_screenSize;\n vec4 cc_screenScale;\n vec4 cc_nativeSize;\n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos;\n vec4 cc_exposure;\n vec4 cc_mainLitDir;\n vec4 cc_mainLitColor;\n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\n#define saturate(a) clamp( a, 0.0, 1.0 )\nvec3 SRGBToLinear(vec3 gamma)\n{\n return pow(gamma, vec3(2.2));\n}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\n}\nvec3 ACESToneMap(vec3 color) {\n const float A = 2.51;\n const float B = 0.03;\n const float C = 2.43;\n const float D = 0.59;\n const float E = 0.14;\n return (color * (A * color + B)) / (color * (C * color + D) + E);\n}\nin vec2 v_uv;\nin vec4 v_offsets[3];\nuniform sampler2D u_texSampler;\nvec3 ToLDR(vec3 color) {\n#if CC_USE_HDR\n color *= cc_exposure.x * 1024.0;\n color = ACESToneMap(color);\n color = LinearToSRGB(color);\n#endif\n return color;\n}\nvec4 frag () {\n vec2 threshold = vec2(0.1, 0.1);\n vec4 delta;\n vec3 C = ToLDR(texture(u_texSampler, v_uv).rgb);\n vec3 Cleft = ToLDR(texture(u_texSampler, v_offsets[0].xy).rgb);\n vec3 t = abs(C - Cleft);\n delta.x = max(max(t.r, t.g), t.b);\n vec3 Ctop = ToLDR(texture(u_texSampler, v_offsets[0].zw).rgb);\n t = abs(C - Ctop);\n delta.y = max(max(t.r, t.g), t.b);\n vec2 edges = step(threshold, delta.xy);\n if (dot(edges, vec2(1.0, 1.0)) == 0.0)\n discard;\n vec3 Cright = ToLDR(texture(u_texSampler, v_offsets[1].xy).rgb);\n t = abs(C - Cright);\n delta.z = max(max(t.r, t.g), t.b);\n vec3 Cbottom = ToLDR(texture(u_texSampler, v_offsets[1].zw).rgb);\n t = abs(C - Cbottom);\n delta.w = max(max(t.r, t.g), t.b);\n float maxDelta = max(max(max(delta.x, delta.y), delta.z), delta.w);\n vec3 Cleftleft = ToLDR(texture(u_texSampler, v_offsets[2].xy).rgb);\n t = abs(C - Cleftleft);\n delta.z = max(max(t.r, t.g), t.b);\n vec3 Ctoptop = ToLDR(texture(u_texSampler, v_offsets[2].zw).rgb);\n t = abs(C - Ctoptop);\n delta.w = max(max(t.r, t.g), t.b);\n maxDelta = max(max(maxDelta, delta.z), delta.w);\n edges.xy *= step(0.5 * maxDelta, delta.xy);\n vec4 o = vec4(edges, 0.0, 0.0);\n return o;\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }\n`
|
|
},
|
|
"glsl1": {
|
|
"vert": `\nprecision highp float;\nuniform vec4 cc_screenScale;\nuniform vec4 cc_nativeSize;\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_exposure;\n#define saturate(a) clamp( a, 0.0, 1.0 )\nvec3 SRGBToLinear(vec3 gamma)\n{\n return pow(gamma, vec3(2.2));\n}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\n}\nvec3 ACESToneMap(vec3 color) {\n const float A = 2.51;\n const float B = 0.03;\n const float C = 2.43;\n const float D = 0.59;\n const float E = 0.14;\n return (color * (A * color + B)) / (color * (C * color + D) + E);\n}\nvarying vec2 v_uv;\nvarying vec4 v_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":[{"name":"CCGlobal", "defines":[]}], "samplers":[]}, "locals":{"blocks":[], "samplers":[]}},
|
|
"defines": [
|
|
{"name":"CC_USE_HDR", "type":"boolean", "defines":[]}
|
|
],
|
|
"blocks": [],
|
|
"samplers": [
|
|
{"name":"u_texSampler", "type":28, "count":1, "defines":[], "binding":30}
|
|
],
|
|
"dependencies": {}
|
|
},
|
|
{
|
|
"name": "pipeline/smaa|smaa-blend-vs:vert|smaa-blend-fs:frag",
|
|
"hash": 2322562369,
|
|
"glsl3": {
|
|
"vert": `\nprecision highp float;\nuniform CCGlobal {\n vec4 cc_time;\n vec4 cc_screenSize;\n vec4 cc_screenScale;\n vec4 cc_nativeSize;\n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos;\n vec4 cc_exposure;\n vec4 cc_mainLitDir;\n vec4 cc_mainLitColor;\n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\nin vec2 a_position;\nin vec2 a_texCoord;\nout vec2 v_uv;\nout vec4 v_offsets[3];\nout vec2 v_pixCoord;\nvec4 vert () {\n vec4 pos = vec4(a_position, 0.0, 1.0);\n v_uv = a_texCoord * cc_screenScale.xy;\n v_pixCoord = v_uv * cc_nativeSize.xy;\n v_offsets[0] = v_uv.xyxy + cc_nativeSize.zwzw * vec4(-0.25, 0.125, 1.25, 0.125);\n v_offsets[1] = v_uv.xyxy + cc_nativeSize.zwzw * vec4(-0.125, 0.25, -0.125, -1.25);\n v_offsets[2] = vec4(v_offsets[0].xz, v_offsets[1].yw) + vec4(-2.0, 2.0, -2.0, 2.0) * cc_nativeSize.zzww * float(8);\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n`,
|
|
"frag": `\nprecision highp float;\nuniform CCGlobal {\n vec4 cc_time;\n vec4 cc_screenSize;\n vec4 cc_screenScale;\n vec4 cc_nativeSize;\n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos;\n vec4 cc_exposure;\n vec4 cc_mainLitDir;\n vec4 cc_mainLitColor;\n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\nin vec2 v_uv;\nin vec4 v_offsets[3];\nin vec2 v_pixCoord;\nuniform sampler2D u_edgeTexSampler;\nuniform sampler2D u_areaTexSampler;\nuniform sampler2D u_searchTexSampler;\nfloat SMAASearchLength(vec2 e, float bias, float scale) {\n e.r = bias + e.r * scale;\n return 255.0 * texture(u_searchTexSampler, e).r;\n}\nfloat SMAASearchXLeft(vec2 texcoord, float end) {\n vec2 e = vec2(0.0, 1.0);\n for (int i = 0; i < 8; ++i) {\n e = texture(u_edgeTexSampler, texcoord).rg;\n texcoord -= vec2( 2.0, 0.0 ) * cc_nativeSize.zw;\n if (!(texcoord.x > end && e.g > 0.8281 && e.r == 0.0))\n break;\n }\n texcoord.x += 0.25 * cc_nativeSize.z;\n texcoord.x += cc_nativeSize.z;\n texcoord.x += 2.0 * cc_nativeSize.z;\n texcoord.x -= cc_nativeSize.z * SMAASearchLength(e, 0.0, 0.5);\n return texcoord.x;\n}\nfloat SMAASearchXRight(vec2 texcoord, float end) {\n vec2 e = vec2(0.0, 1.0);\n for (int i = 0; i < 8; ++i) {\n e = texture(u_edgeTexSampler, texcoord).rg;\n texcoord += vec2( 2.0, 0.0 ) * cc_nativeSize.zw;\n if (!(texcoord.x < end && e.g > 0.8281 && e.r == 0.0))\n break;\n }\n texcoord.x -= 0.25 * cc_nativeSize.z;\n texcoord.x -= cc_nativeSize.z;\n texcoord.x -= 2.0 * cc_nativeSize.z;\n texcoord.x += cc_nativeSize.z * SMAASearchLength(e, 0.5, 0.5);\n return texcoord.x;\n}\nfloat SMAASearchYUp(vec2 texcoord, float end) {\n vec2 e = vec2(1.0, 0.0);\n for (int i = 0; i < 8; ++i) {\n e = texture(u_edgeTexSampler, texcoord).rg;\n texcoord += vec2( 0.0, 2.0 ) * cc_nativeSize.zw;\n if (!(texcoord.y > end && e.r > 0.8281 && e.g == 0.0))\n break;\n }\n texcoord.y -= 0.25 * cc_nativeSize.w;\n texcoord.y -= cc_nativeSize.w;\n texcoord.y -= 2.0 * cc_nativeSize.w;\n texcoord.y += cc_nativeSize.w * SMAASearchLength(e.gr, 0.0, 0.5);\n return texcoord.y;\n}\nfloat SMAASearchYDown(vec2 texcoord, float end) {\n vec2 e = vec2(1.0, 0.0);\n for (int i = 0; i < 8; ++i) {\n e = texture(u_edgeTexSampler, texcoord).rg;\n texcoord -= vec2( 0.0, 2.0 ) * cc_nativeSize.zw;\n if (!(texcoord.y < end && e.r > 0.8281 && e.g == 0.0))\n break;\n }\n texcoord.y += 0.25 * cc_nativeSize.w;\n texcoord.y += cc_nativeSize.w;\n texcoord.y += 2.0 * cc_nativeSize.w;\n texcoord.y -= cc_nativeSize.w * SMAASearchLength(e.gr, 0.5, 0.5);\n return texcoord.y;\n}\nvec2 Round(vec2 x) {\n return sign(x) * floor(abs(x) + 0.5);\n}\nvec2 SMAAArea(vec2 dist, float e1, float e2) {\n vec2 texcoord = float(16) * Round(4.0 * vec2(e1, e2)) + dist;\n texcoord = (1.0 / vec2(160.0, 560.0)) * texcoord + 0.5 * (1.0 / vec2(160.0, 560.0));\n return texture(u_areaTexSampler, texcoord).rg;\n}\nvec4 frag () {\n vec4 weights = vec4(0.0);\n vec2 e = texture(u_edgeTexSampler, v_uv).rg;\n vec2 d;\n vec2 coords;\n if ( e.g > 0.0 ) {\n coords.x = SMAASearchXLeft(v_offsets[0].xy, v_offsets[2].x);\n coords.y = v_offsets[1].y;\n d.x = coords.x;\n float e1 = texture(u_edgeTexSampler, coords).r;\n coords.x = SMAASearchXRight(v_offsets[0].zw, v_offsets[2].y);\n d.y = coords.x;\n d = d / cc_nativeSize.z - v_pixCoord.x;\n vec2 sqrt_d = sqrt(abs(d));\n coords.y -= 1.0 * cc_nativeSize.w;\n float e2 = texture(u_edgeTexSampler, coords + vec2(cc_nativeSize.z, 0.0)).r;\n weights.rg = SMAAArea(sqrt_d, e1, e2);\n }\n if ( e.r > 0.0 ) {\n coords.y = SMAASearchYUp(v_offsets[1].xy, v_offsets[2].z);\n coords.x = v_offsets[0].x;\n d.x = coords.y;\n float e1 = texture(u_edgeTexSampler, coords).g;\n coords.y = SMAASearchYDown(v_offsets[1].zw, v_offsets[2].w);\n d.y = coords.y;\n d = d / cc_nativeSize.w - v_pixCoord.y;\n vec2 sqrt_d = sqrt(abs(d));\n coords.y -= 1.0 * cc_nativeSize.w;\n float e2 = texture(u_edgeTexSampler, coords + vec2(0.0, cc_nativeSize.w)).g;\n weights.ba = SMAAArea(sqrt_d, e1, e2);\n }\n return weights;\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }\n`
|
|
},
|
|
"glsl1": {
|
|
"vert": `\nprecision highp float;\nuniform vec4 cc_screenScale;\nuniform vec4 cc_nativeSize;\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_nativeSize;\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":[{"name":"CCGlobal", "defines":[]}], "samplers":[]}, "locals":{"blocks":[], "samplers":[]}},
|
|
"defines": [],
|
|
"blocks": [],
|
|
"samplers": [
|
|
{"name":"u_edgeTexSampler", "type":28, "count":1, "defines":[], "binding":30},
|
|
{"name":"u_areaTexSampler", "type":28, "count":1, "defines":[], "binding":31},
|
|
{"name":"u_searchTexSampler", "type":28, "count":1, "defines":[], "binding":32}
|
|
],
|
|
"dependencies": {}
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"name": "pipeline/tonemap",
|
|
"techniques": [
|
|
{"name":"tonemap", "passes":[{"program":"pipeline/tonemap|tonemap-vs:vert|tonemap-fs:frag", "depthStencilState":{"depthTest":false, "depthWrite":false}, "properties":{"u_texSampler":{"sampler":[2, 2, null, 2, 2], "type":28}, "u_blendTexSampler":{"sampler":[2, 2, null, 2, 2], "type":28}}}]}
|
|
],
|
|
"shaders": [
|
|
{
|
|
"name": "pipeline/tonemap|tonemap-vs:vert|tonemap-fs:frag",
|
|
"hash": 3483372138,
|
|
"glsl3": {
|
|
"vert": `\nprecision highp float;\n#define saturate(a) clamp( a, 0.0, 1.0 )\nuniform CCGlobal {\n vec4 cc_time;\n vec4 cc_screenSize;\n vec4 cc_screenScale;\n vec4 cc_nativeSize;\n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos;\n vec4 cc_exposure;\n vec4 cc_mainLitDir;\n vec4 cc_mainLitColor;\n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\nin vec2 a_position;\nin vec2 a_texCoord;\nout vec2 v_uv;\nout vec4 v_offset;\nvec4 vert () {\n vec4 pos = vec4(a_position, 0, 1);\n v_uv = a_texCoord * cc_screenScale.xy;\n v_offset = v_uv.xyxy + cc_nativeSize.zwzw * vec4(1.0, 0.0, 0.0, -1.0);\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n`,
|
|
"frag": `\nprecision highp float;\nuniform CCGlobal {\n vec4 cc_time;\n vec4 cc_screenSize;\n vec4 cc_screenScale;\n vec4 cc_nativeSize;\n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos;\n vec4 cc_exposure;\n vec4 cc_mainLitDir;\n vec4 cc_mainLitColor;\n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\n#define saturate(a) clamp( a, 0.0, 1.0 )\nvec3 SRGBToLinear(vec3 gamma)\n{\n return pow(gamma, vec3(2.2));\n}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\n}\nvec3 ACESToneMap(vec3 color) {\n const float A = 2.51;\n const float B = 0.03;\n const float C = 2.43;\n const float D = 0.59;\n const float E = 0.14;\n return (color * (A * color + B)) / (color * (C * color + D) + E);\n}\nin vec2 v_uv;\nin vec4 v_offset;\nuniform sampler2D u_texSampler;\nuniform sampler2D u_blendTexSampler;\nvec3 ToLDR(vec3 color) {\n #if CC_USE_HDR\n color *= cc_exposure.x * 1024.0;\n color = ACESToneMap(color);\n color = LinearToSRGB(color);\n #endif\n return color;\n}\nvec4 frag () {\n #if CC_USE_SMAA\n vec4 a;\n a.rb = texture(u_blendTexSampler, v_uv).rb;\n a.g = texture(u_blendTexSampler, v_offset.zw).g;\n a.a = texture(u_blendTexSampler, v_offset.xy).a;\n if (dot(a, vec4(1.0)) < 1e-5) {\n vec4 o = texture(u_texSampler, v_uv);\n o.rgb = ToLDR(o.rgb);\n return o;\n } else {\n vec2 offset;\n offset.x = a.a > a.b ? a.a : -a.b;\n offset.y = a.g > a.r ? -a.g : a.r;\n if (abs(offset.x) > abs(offset.y)) {\n offset.y = 0.0;\n } else {\n offset.x = 0.0;\n }\n vec4 C = texture(u_texSampler, v_uv);\n C.rgb = ToLDR(C.rgb);\n vec2 uv = v_uv + sign(offset) * cc_nativeSize.zw;\n vec4 Cop = texture(u_texSampler, uv);\n Cop.rgb = ToLDR(Cop.rgb);\n float s = abs(offset.x) > abs(offset.y) ? abs(offset.x) : abs(offset.y);\n C.rgb = pow(C.rgb, vec3(2.2));\n Cop.rgb = pow(Cop.rgb, vec3(2.2));\n vec4 mixed = mix(C, Cop, s);\n mixed.rgb = pow(mixed.rgb, vec3(1.0 / 2.2));\n return mixed;\n }\n #else\n vec4 o = texture(u_texSampler, v_uv);\n o.rgb = ToLDR(o.rgb);\n return o;\n #endif\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }\n`
|
|
},
|
|
"glsl1": {
|
|
"vert": `\nprecision highp float;\n#define saturate(a) clamp( a, 0.0, 1.0 )\nuniform vec4 cc_screenScale;\nuniform vec4 cc_nativeSize;\nattribute vec2 a_position;\nattribute vec2 a_texCoord;\nvarying vec2 v_uv;\nvarying vec4 v_offset;\nvec4 vert () {\n vec4 pos = vec4(a_position, 0, 1);\n v_uv = a_texCoord * cc_screenScale.xy;\n v_offset = v_uv.xyxy + cc_nativeSize.zwzw * vec4(1.0, 0.0, 0.0, -1.0);\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n`,
|
|
"frag": `\nprecision highp float;\nuniform vec4 cc_nativeSize;\nuniform vec4 cc_exposure;\n#define saturate(a) clamp( a, 0.0, 1.0 )\nvec3 SRGBToLinear(vec3 gamma)\n{\n return pow(gamma, vec3(2.2));\n}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\n}\nvec3 ACESToneMap(vec3 color) {\n const float A = 2.51;\n const float B = 0.03;\n const float C = 2.43;\n const float D = 0.59;\n const float E = 0.14;\n return (color * (A * color + B)) / (color * (C * color + D) + E);\n}\nvarying vec2 v_uv;\nvarying vec4 v_offset;\nuniform sampler2D u_texSampler;\nuniform sampler2D u_blendTexSampler;\nvec3 ToLDR(vec3 color) {\n #if CC_USE_HDR\n color *= cc_exposure.x * 1024.0;\n color = ACESToneMap(color);\n color = LinearToSRGB(color);\n #endif\n return color;\n}\nvec4 frag () {\n #if CC_USE_SMAA\n vec4 a;\n a.rb = texture2D(u_blendTexSampler, v_uv).rb;\n a.g = texture2D(u_blendTexSampler, v_offset.zw).g;\n a.a = texture2D(u_blendTexSampler, v_offset.xy).a;\n if (dot(a, vec4(1.0)) < 1e-5) {\n vec4 o = texture2D(u_texSampler, v_uv);\n o.rgb = ToLDR(o.rgb);\n return o;\n } else {\n vec2 offset;\n offset.x = a.a > a.b ? a.a : -a.b;\n offset.y = a.g > a.r ? -a.g : a.r;\n if (abs(offset.x) > abs(offset.y)) {\n offset.y = 0.0;\n } else {\n offset.x = 0.0;\n }\n vec4 C = texture2D(u_texSampler, v_uv);\n C.rgb = ToLDR(C.rgb);\n vec2 uv = v_uv + sign(offset) * cc_nativeSize.zw;\n vec4 Cop = texture2D(u_texSampler, uv);\n Cop.rgb = ToLDR(Cop.rgb);\n float s = abs(offset.x) > abs(offset.y) ? abs(offset.x) : abs(offset.y);\n C.rgb = pow(C.rgb, vec3(2.2));\n Cop.rgb = pow(Cop.rgb, vec3(2.2));\n vec4 mixed = mix(C, Cop, s);\n mixed.rgb = pow(mixed.rgb, vec3(1.0 / 2.2));\n return mixed;\n }\n #else\n vec4 o = texture2D(u_texSampler, v_uv);\n o.rgb = ToLDR(o.rgb);\n return o;\n #endif\n}\nvoid main() { gl_FragColor = frag(); }\n`
|
|
},
|
|
"builtins": {"globals":{"blocks":[{"name":"CCGlobal", "defines":[]}], "samplers":[]}, "locals":{"blocks":[], "samplers":[]}},
|
|
"defines": [
|
|
{"name":"CC_USE_HDR", "type":"boolean", "defines":[]},
|
|
{"name":"CC_USE_SMAA", "type":"boolean", "defines":[]}
|
|
],
|
|
"blocks": [],
|
|
"samplers": [
|
|
{"name":"u_texSampler", "type":28, "count":1, "defines":[], "binding":30},
|
|
{"name":"u_blendTexSampler", "type":28, "count":1, "defines":[], "binding":31}
|
|
],
|
|
"dependencies": {}
|
|
}
|
|
]
|
|
}
|
|
];
|