diff --git a/cocos/core/3d/builtin/effects.ts b/cocos/core/3d/builtin/effects.ts index 9f78b7ab7c..a1b68b0d1b 100644 --- a/cocos/core/3d/builtin/effects.ts +++ b/cocos/core/3d/builtin/effects.ts @@ -273,18 +273,18 @@ export default [ "shaders": [ { "name": "builtin-sprite|sprite-vs:vert|sprite-fs:frag", - "hash": 2999916052, + "hash": 951794746, "glsl3": { "vert": `\nprecision mediump float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\n#if USE_LOCAL\nuniform CCLocal {\n highp mat4 cc_matWorld;\n highp mat4 cc_matWorldIT;\n highp vec4 cc_lightingMapUVParam;\n};\n#endif\nin vec3 a_position;\nin vec2 a_texCoord;\nin vec4 a_color;\nout vec4 color;\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(); }`, - "frag": `\nprecision mediump float;\nvec4 CCSampleTexture(sampler2D tex, vec2 uv) {\n#if CC_ALPHA_SEPARATED\n return vec4(texture(tex, uv).rgb, texture(tex, uv + vec2(0.0, 0.5)).r);\n#else\n return texture(tex, uv);\n#endif\n}\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 *= CCSampleTexture(mainTexture, uv0);\n #if IS_GRAY\n float gray = 0.2126 * o.r + 0.7152 * o.g + 0.0722 * o.b;\n o.r = o.g = o.b = gray;\n #endif\n #endif\n o *= color;\n return o;\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }` + "frag": `\nprecision mediump float;\nvec4 CCSampleTexture(sampler2D tex, vec2 uv) {\n#if CC_USE_EMBEDDED_ALPHA\n return vec4(texture(tex, uv).rgb, texture(tex, uv + vec2(0.0, 0.5)).r);\n#else\n return texture(tex, uv);\n#endif\n}\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 *= CCSampleTexture(mainTexture, uv0);\n #if IS_GRAY\n float gray = 0.2126 * o.r + 0.7152 * o.g + 0.0722 * o.b;\n o.r = o.g = o.b = gray;\n #endif\n #endif\n o *= color;\n return o;\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }` }, "glsl1": { "vert": `\nprecision mediump float;\nuniform highp mat4 cc_matViewProj;\n#if USE_LOCAL\nuniform highp mat4 cc_matWorld;\n#endif\nattribute vec3 a_position;\nattribute vec2 a_texCoord;\nattribute vec4 a_color;\nvarying vec4 color;\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(); }`, - "frag": `\nprecision mediump float;\nvec4 CCSampleTexture(sampler2D tex, vec2 uv) {\n#if CC_ALPHA_SEPARATED\n return vec4(texture2D(tex, uv).rgb, texture2D(tex, uv + vec2(0.0, 0.5)).r);\n#else\n return texture2D(tex, uv);\n#endif\n}\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 *= CCSampleTexture(mainTexture, uv0);\n #if IS_GRAY\n float gray = 0.2126 * o.r + 0.7152 * o.g + 0.0722 * o.b;\n o.r = o.g = o.b = gray;\n #endif\n #endif\n o *= color;\n return o;\n}\nvoid main() { gl_FragColor = frag(); }` + "frag": `\nprecision mediump float;\nvec4 CCSampleTexture(sampler2D tex, vec2 uv) {\n#if CC_USE_EMBEDDED_ALPHA\n return vec4(texture2D(tex, uv).rgb, texture2D(tex, uv + vec2(0.0, 0.5)).r);\n#else\n return texture2D(tex, uv);\n#endif\n}\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 *= CCSampleTexture(mainTexture, uv0);\n #if IS_GRAY\n float gray = 0.2126 * o.r + 0.7152 * o.g + 0.0722 * o.b;\n o.r = o.g = o.b = gray;\n #endif\n #endif\n o *= color;\n return o;\n}\nvoid main() { gl_FragColor = frag(); }` }, "glsl4": { "vert": `\nprecision mediump float;\nlayout(binding = 23) uniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\n#if USE_LOCAL\nlayout(binding = 21) uniform CCLocal {\n highp mat4 cc_matWorld;\n highp mat4 cc_matWorldIT;\n highp vec4 cc_lightingMapUVParam;\n};\n#endif\nlayout(location = 0) in vec3 a_position;\nlayout(location = 1) in vec2 a_texCoord;\nlayout(location = 2) in vec4 a_color;\nlayout(location = 0) out vec4 color;\nlayout(location = 1) out 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(); }`, - "frag": `\nprecision mediump float;\nvec4 CCSampleTexture(sampler2D tex, vec2 uv) {\n#if CC_ALPHA_SEPARATED\n return vec4(texture(tex, uv).rgb, texture(tex, uv + vec2(0.0, 0.5)).r);\n#else\n return texture(tex, uv);\n#endif\n}\nlayout(location = 0) in vec4 color;\n#if USE_TEXTURE\n layout(location = 1) in vec2 uv0;\n layout(binding = 31) uniform sampler2D mainTexture;\n#endif\nvec4 frag () {\n vec4 o = vec4(1, 1, 1, 1);\n #if USE_TEXTURE\n o *= CCSampleTexture(mainTexture, uv0);\n #if IS_GRAY\n float gray = 0.2126 * o.r + 0.7152 * o.g + 0.0722 * o.b;\n o.r = o.g = o.b = gray;\n #endif\n #endif\n o *= color;\n return o;\n}\nlayout(location = 0) out vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }` + "frag": `\nprecision mediump float;\nvec4 CCSampleTexture(sampler2D tex, vec2 uv) {\n#if CC_USE_EMBEDDED_ALPHA\n return vec4(texture(tex, uv).rgb, texture(tex, uv + vec2(0.0, 0.5)).r);\n#else\n return texture(tex, uv);\n#endif\n}\nlayout(location = 0) in vec4 color;\n#if USE_TEXTURE\n layout(location = 1) in vec2 uv0;\n layout(binding = 31) uniform sampler2D mainTexture;\n#endif\nvec4 frag () {\n vec4 o = vec4(1, 1, 1, 1);\n #if USE_TEXTURE\n o *= CCSampleTexture(mainTexture, uv0);\n #if IS_GRAY\n float gray = 0.2126 * o.r + 0.7152 * o.g + 0.0722 * o.b;\n o.r = o.g = o.b = gray;\n #endif\n #endif\n o *= color;\n return o;\n}\nlayout(location = 0) out vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }` }, "builtins": { "globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }], "samplers": [] }, @@ -292,7 +292,7 @@ export default [ }, "defines": [ { "name": "USE_LOCAL", "type": "boolean" }, - { "name": "CC_ALPHA_SEPARATED", "type": "boolean" }, + { "name": "CC_USE_EMBEDDED_ALPHA", "type": "boolean" }, { "name": "USE_TEXTURE", "type": "boolean" }, { "name": "IS_GRAY", "type": "boolean" } ], @@ -317,18 +317,18 @@ export default [ "shaders": [ { "name": "builtin-standard|standard-vs:vert|standard-fs:frag", - "hash": 3362455208, + "hash": 2331158049, "glsl3": { "vert": `\nprecision highp float;\nstruct StandardVertInput {\n highp vec4 position;\n vec3 normal;\n vec4 tangent;\n};\nin vec3 a_position;\nin vec3 a_normal;\nin vec2 a_texCoord;\nin vec4 a_tangent;\n#if CC_USE_MORPH\n in float a_vertexId;\n int getVertexId() {\n return int(a_vertexId);\n }\nuniform CCMorph {\n vec4 cc_displacementWeights[15];\n vec4 cc_displacementTextureInfo;\n};\n vec4 fetchFlatPixel(sampler2D tex, int pixelIndex) {\n float pixelIndexF = float(pixelIndex);\n vec2 textureResolution = vec2(float(cc_displacementTextureInfo.x), float(cc_displacementTextureInfo.y));\n float pixelX = mod(pixelIndexF, textureResolution.x);\n float pixelY = floor(pixelIndexF / textureResolution.x);\n vec2 uv = (vec2(pixelX, pixelY) + .5) / textureResolution;\n return texture(tex, uv);\n }\nfloat getDisplacementWeight(int index) {\n float m = mod(float(index), 4.0);\n if (m < 1.0) {\n return cc_displacementWeights[index / 4].x;\n } else if (m < 2.0) {\n return cc_displacementWeights[index / 4].y;\n } else if (m < 3.0) {\n return cc_displacementWeights[index / 4].z;\n } else {\n return cc_displacementWeights[index / 4].w;\n }\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\n return fetchFlatPixel(tex, vertexIndex).rgb;\n#else\n vec3 result = vec3(0, 0, 0);\n for (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\n int dataPixelStart = int(fetchFlatPixel(tex, iTarget).r);\n result += (fetchFlatPixel(tex, dataPixelStart + vertexIndex).rgb * getDisplacementWeight(iTarget));\n }\n return result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\n uniform sampler2D cc_PositionDisplacements;\n vec3 getPositionDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n uniform sampler2D cc_NormalDisplacements;\n vec3 getNormalDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n uniform sampler2D cc_TangentDisplacements;\n vec3 getTangentDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n }\n#endif\nvoid applyMorph (inout StandardVertInput attr) {\n int vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\n attr.position.xyz = attr.position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n attr.normal.xyz = attr.normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n attr.tangent.xyz = attr.tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\n position.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\nin vec4 a_joints;\nin vec4 a_weights;\n#if CC_USE_BAKED_ANIMATION\n #if USE_INSTANCING\n in highp vec4 a_jointAnimInfo;\n #endif\n uniform CCSkinningTexture {\n highp vec4 cc_jointTextureInfo;\n };\n uniform CCSkinningAnimation {\n highp vec4 cc_jointAnimInfo;\n };\n uniform sampler2D cc_jointTexture;\n #if !CC_SUPPORT_FLOAT_TEXTURE\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#else\n uniform CCSkinning {\n highp vec4 cc_joints[30 * 3];\n };\n#endif\n#if CC_USE_BAKED_ANIMATION\n #if CC_SUPPORT_FLOAT_TEXTURE\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 3.0 * (a_jointAnimInfo.x * a_jointAnimInfo.y + i) + a_jointAnimInfo.z;\n #else\n highp float j = 3.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = texture(cc_jointTexture, vec2((x + 0.5) * invSize, y));\n vec4 v2 = texture(cc_jointTexture, vec2((x + 1.5) * invSize, y));\n vec4 v3 = texture(cc_jointTexture, vec2((x + 2.5) * invSize, y));\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #else\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 12.0 * (a_jointAnimInfo.x * a_jointAnimInfo.y + i) + a_jointAnimInfo.z;\n #else\n highp float j = 12.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = vec4(\n decode32(texture(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n );\n vec4 v2 = vec4(\n decode32(texture(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n );\n vec4 v3 = vec4(\n decode32(texture(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n );\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #endif\n#else\n mat4 getJointMatrix (float i) {\n int idx = int(i);\n vec4 v1 = cc_joints[idx * 3];\n vec4 v2 = cc_joints[idx * 3 + 1];\n vec4 v3 = cc_joints[idx * 3 + 2];\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n#endif\nmat4 skinMatrix () {\n return getJointMatrix(a_joints.x) * a_weights.x\n + getJointMatrix(a_joints.y) * a_weights.y;\n + getJointMatrix(a_joints.z) * a_weights.z;\n + getJointMatrix(a_joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\n mat4 m = skinMatrix();\n position = m * position;\n}\nvoid CCSkin (inout StandardVertInput attr) {\n mat4 m = skinMatrix();\n attr.position = m * attr.position;\n attr.normal = (m * vec4(attr.normal, 0.0)).xyz;\n attr.tangent.xyz = (m * vec4(attr.tangent.xyz, 0.0)).xyz;\n}\n#endif\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\n#if USE_INSTANCING\n in vec4 a_matWorld0;\n in vec4 a_matWorld1;\n in vec4 a_matWorld2;\n#elif USE_BATCHING\n in float a_dyn_batch_id;\n uniform CCLocalBatched {\n highp mat4 cc_matWorlds[10];\n };\n#else\nuniform CCLocal {\n highp mat4 cc_matWorld;\n highp mat4 cc_matWorldIT;\n highp vec4 cc_lightingMapUVParam;\n};\n#endif\nuniform Constants {\n vec4 tilingOffset;\n vec4 albedo;\n vec4 albedoScaleAndCutoff;\n vec4 pbrParams;\n vec4 emissive;\n vec4 emissiveScaleParam;\n};\nfloat LinearFog(vec4 pos) {\n vec4 wPos = pos;\n float cam_dis = distance(cc_cameraPos, wPos);\n float fogStart = cc_fogBase.x;\n float fogEnd = cc_fogBase.y;\n return clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float fogDensity = cc_fogBase.z;\n float cam_dis = distance(cc_cameraPos, wPos) / fogAtten * 4.;\n float f = exp(-cam_dis * fogDensity);\n return f;\n}\nfloat ExpSquaredFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float fogDensity = cc_fogBase.z;\n float cam_dis = distance(cc_cameraPos, wPos) / fogAtten * 4.;\n float f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\n return f;\n}\nfloat LayeredFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float _FogTop = cc_fogAdd.x;\n float _FogRange = cc_fogAdd.y;\n vec3 camWorldProj = cc_cameraPos.xyz;\n camWorldProj.y = 0.;\n vec3 worldPosProj = wPos.xyz;\n worldPosProj.y = 0.;\n float fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\n float fDeltaY, fDensityIntegral;\n if (cc_cameraPos.y > _FogTop) {\n if (wPos.y < _FogTop) {\n fDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\n fDensityIntegral = fDeltaY * fDeltaY * 0.5;\n } else {\n fDeltaY = 0.;\n fDensityIntegral = 0.;\n }\n } else {\n if (wPos.y < _FogTop) {\n float fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\n float fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\n fDeltaY = abs(fDeltaA - fDeltaB);\n fDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n } else {\n fDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\n fDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n }\n }\n float fDensity;\n if (fDeltaY != 0.) {\n fDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n } else {\n fDensity = 0.;\n }\n float f = exp(-fDensity);\n return f;\n}\nfloat CC_TRANSFER_FOG(vec4 pos) {\n #if CC_USE_FOG == 1\n return LinearFog(pos);\n #elif CC_USE_FOG == 2\n return ExpFog(pos);\n #elif CC_USE_FOG == 3\n return ExpSquaredFog(pos);\n #elif CC_USE_FOG == 4\n return LayeredFog(pos);\n #endif\n return 1.;\n}\n#if USE_VERTEX_COLOR\n in vec3 a_color;\n out vec3 v_color;\n#endif\nout vec3 v_position;\nout vec3 v_normal;\nout vec2 v_uv;\nout vec2 v_uv1;\nout float factor_fog;\n#if USE_NORMAL_MAP\n out vec3 v_tangent;\n out vec3 v_bitangent;\n#endif\n#if HAS_SECOND_UV\n in vec2 a_texCoord1;\n#endif\n#if USE_LIGHTMAP && !USE_BATCHING && !USE_INSTANCING\n out vec2 v_luv;\n#endif\nvec4 vert () {\n StandardVertInput In;\n In.position = vec4(a_position, 1.0);\n In.normal = a_normal;\n In.tangent = a_tangent;\n #if CC_USE_MORPH\n applyMorph(In);\n #endif\n #if CC_USE_SKINNING\n CCSkin(In);\n #endif\n mat4 matWorld, matWorldIT;\n #if USE_INSTANCING\n matWorld = mat4(\n vec4(a_matWorld0.xyz, 0.0),\n vec4(a_matWorld1.xyz, 0.0),\n vec4(a_matWorld2.xyz, 0.0),\n vec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)\n );\n matWorldIT = matWorld;\n #elif USE_BATCHING\n matWorld = cc_matWorlds[int(a_dyn_batch_id)];\n matWorldIT = matWorld;\n #else\n matWorld = cc_matWorld;\n matWorldIT = cc_matWorldIT;\n #endif\n vec4 pos = matWorld * In.position;\n v_position = pos.xyz;\n v_normal = normalize((matWorldIT * vec4(In.normal, 0.0)).xyz);\n #if USE_NORMAL_MAP\n v_tangent = normalize((matWorld * vec4(In.tangent.xyz, 0.0)).xyz);\n v_bitangent = cross(v_normal, v_tangent) * In.tangent.w;\n #endif\n v_uv = a_texCoord * tilingOffset.xy + tilingOffset.zw;\n #if HAS_SECOND_UV\n v_uv1 = a_texCoord1 * tilingOffset.xy + tilingOffset.zw;\n #endif\n #if USE_VERTEX_COLOR\n v_color = a_color;\n #endif\n factor_fog = CC_TRANSFER_FOG(matWorld * In.position);\n #if USE_LIGHTMAP && HAS_SECOND_UV && !USE_BATCHING && !USE_INSTANCING\n v_luv = cc_lightingMapUVParam.xy + a_texCoord1 * cc_lightingMapUVParam.zw;\n #endif\n return cc_matProj * (cc_matView * matWorld) * In.position;\n}\nvoid main() { gl_Position = vert(); }`, - "frag": `\nprecision highp float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\n#if CC_USE_IBL\nuniform samplerCube cc_environment;\nvec3 unpackRGBE (vec4 rgbe) {\n return rgbe.rgb * pow(2.0, rgbe.a * 255.0 - 128.0);\n}\nvec4 fragTextureLod (sampler2D tex, vec2 coord, float lod) {\n return textureLod(tex, coord, lod);\n}\nvec4 fragTextureLod (samplerCube tex, vec3 coord, float lod) {\n return textureLod(tex, coord, lod);\n}\n#endif\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\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}\nstruct StandardSurface {\n vec4 albedo;\n vec3 position;\n vec3 normal;\n vec3 emissive;\n float roughness;\n float metallic;\n float occlusion;\n};\n#if CC_FORWARD_ADD\nuniform CCForwardLight {\n highp vec4 cc_lightPos[1];\n vec4 cc_lightColor[1];\n vec4 cc_lightSizeRangeAngle[1];\n vec4 cc_lightDir[1];\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}\n vec4 CCStandardShading (StandardSurface s) {\n vec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\n vec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\n vec3 diffuseContrib = diffuse / 3.14159265359;\n vec3 N = normalize(s.normal);\n vec3 V = normalize(cc_cameraPos.xyz - s.position);\n float NV = max(abs(dot(N, V)), 0.001);\n specular = BRDFApprox(specular, s.roughness, NV);\n vec3 finalColor = vec3(0.0);\n for (int i = 0; i < 1; i++) {\n vec3 SLU = cc_lightPos[i].xyz - s.position;\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_lightSizeRangeAngle[i].x;\n float litRadiusSqr = litRadius * litRadius;\n float illum = 3.14159265359 * (litRadiusSqr / max(litRadiusSqr , distSqr));\n float attRadiusSqrInv = 1.0 / max(cc_lightSizeRangeAngle[i].y, 0.01);\n attRadiusSqrInv *= attRadiusSqrInv;\n float att = GetDistAtt(distSqr, attRadiusSqrInv);\n vec3 lspec = specular * CalcSpecular(s.roughness, SNH, SH, N);\n #if CC_SPOTLIGHT\n float cosInner = max(dot(-cc_lightDir[i].xyz, SL), 0.01);\n float cosOuter = cc_lightSizeRangeAngle[i].z;\n float litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\n float litAngleOffset = -cosOuter * litAngleScale;\n att *= GetAngleAtt(SL, -cc_lightDir[i].xyz, litAngleScale, litAngleOffset);\n #endif\n finalColor += SNL * cc_lightColor[i].rgb * cc_lightColor[i].w * illum * att * (diffuseContrib + lspec);\n }\n return vec4(finalColor, 0.0);\n }\n#else\n vec4 CCStandardShading (StandardSurface s) {\n vec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\n vec3 specular = mix(vec3(0.04), s.albedo.rgb, 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 diffuseContrib = diffuse / 3.14159265359;\n vec3 specularContrib = specular * CalcSpecular(s.roughness, NH, H, N);\n vec3 finalColor = NL * cc_mainLitColor.rgb * cc_mainLitColor.w * (diffuseContrib + specularContrib);\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 vec4 envmap = fragTextureLod(cc_environment, R, s.roughness * cc_ambientGround.w);\n #if CC_USE_IBL == 2\n vec3 env = unpackRGBE(envmap);\n #else\n vec3 env = SRGBToLinear(envmap.rgb);\n #endif\n finalColor += env * cc_ambientSky.w * 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.albedo.a);\n }\n#endif\nvec3 ACESToneMap (vec3 color) {\n color = min(color, vec3(8.0));\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}\nvec4 CCFragOutput (vec4 color) {\n #if !CC_USE_HDR\n color.rgb = sqrt(ACESToneMap(color.rgb));\n #endif\n return color;\n}\nuniform Constants {\n vec4 tilingOffset;\n vec4 albedo;\n vec4 albedoScaleAndCutoff;\n vec4 pbrParams;\n vec4 emissive;\n vec4 emissiveScaleParam;\n};\nin vec3 v_position;\nin vec2 v_uv;\nin vec2 v_uv1;\nin vec3 v_normal;\n#if USE_VERTEX_COLOR\n in vec3 v_color;\n#endif\n#if USE_ALBEDO_MAP\n uniform sampler2D albedoMap;\n#endif\n#if USE_NORMAL_MAP\n in vec3 v_tangent;\n in vec3 v_bitangent;\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\n#if USE_LIGHTMAP\n in vec2 v_luv;\n uniform sampler2D cc_lightingMap;\n#endif\n#if USE_ALPHA_TEST\n#endif\nin float factor_fog;\nvoid surf (out StandardSurface s) {\n vec4 baseColor = albedo;\n #if USE_VERTEX_COLOR\n baseColor.rgb *= v_color;\n #endif\n #if USE_ALBEDO_MAP\n vec4 texColor = texture(albedoMap, ALBEDO_UV);\n texColor.rgb = SRGBToLinear(texColor.rgb);\n baseColor *= texColor;\n #endif\n s.albedo = baseColor;\n s.albedo.rgb *= albedoScaleAndCutoff.xyz;\n #if USE_ALPHA_TEST\n if (s.albedo.ALPHA_TEST_CHANNEL < albedoScaleAndCutoff.w) discard;\n #endif\n s.normal = v_normal;\n #if USE_NORMAL_MAP\n vec3 nmmp = texture(normalMap, NORMAL_UV).xyz - vec3(0.5);\n s.normal =\n (nmmp.x * pbrParams.w) * normalize(v_tangent) +\n (nmmp.y * pbrParams.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 vec4 res = texture(pbrMap, PBR_UV);\n pbr.x *= res.OCCLUSION_CHANNEL;\n pbr.y *= res.ROUGHNESS_CHANNEL;\n pbr.z *= res.METALLIC_CHANNEL;\n #endif\n #if USE_METALLIC_ROUGHNESS_MAP\n vec4 metallicRoughness = texture(metallicRoughnessMap, METALLIC_ROUGHNESS_UV);\n pbr.z *= metallicRoughness.METALLIC_CHANNEL;\n pbr.y *= metallicRoughness.ROUGHNESS_CHANNEL;\n #endif\n #if USE_OCCLUSION_MAP\n pbr.x *= texture(occlusionMap, OCCLUSION_UV).OCCLUSION_CHANNEL;\n #endif\n s.occlusion = clamp(pbr.x, 0.0, 0.96);\n s.roughness = clamp(pbr.y, 0.04, 1.0);\n s.metallic = pbr.z;\n s.emissive = emissive.rgb * emissiveScaleParam.xyz;\n #if USE_EMISSIVE_MAP\n s.emissive *= SRGBToLinear(texture(emissiveMap, EMISSIVE_UV).rgb);\n #endif\n}\nvec4 frag () {\n StandardSurface s; surf(s);\n vec4 color = CCStandardShading(s);\n #if USE_LIGHTMAP && !USE_BATCHING && !USE_INSTANCING && CC_FOWARD_ADD == 0\n vec4 lighting = texture(cc_lightingMap, v_luv);\n float fAmb = 0.5 - s.normal.y * 0.5;\n vec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb) * cc_ambientSky.w;\n vec3 finalColor = (ambDiff.rgb * s.albedo.rgb);\n finalColor += lighting.rgb * s.albedo.rgb;\n finalColor = finalColor * s.occlusion;\n finalColor += s.emissive;\n color.rgb = lighting.a * finalColor + (1.0 - lighting.a) * color.rgb;\n #endif\n color = vec4(mix(cc_fogColor.rgb, CC_FORWARD_ADD > 0 ? vec3(0.0) : color.rgb, factor_fog), color.a);\n return CCFragOutput(color);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }` + "frag": `\nprecision highp float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\n#if CC_USE_IBL\nuniform samplerCube cc_environment;\nvec3 unpackRGBE (vec4 rgbe) {\n return rgbe.rgb * pow(2.0, rgbe.a * 255.0 - 128.0);\n}\nvec4 fragTextureLod (sampler2D tex, vec2 coord, float lod) {\n return textureLod(tex, coord, lod);\n}\nvec4 fragTextureLod (samplerCube tex, vec3 coord, float lod) {\n return textureLod(tex, coord, lod);\n}\n#endif\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\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}\nstruct StandardSurface {\n vec4 albedo;\n vec3 position;\n vec3 normal;\n vec3 emissive;\n float roughness;\n float metallic;\n float occlusion;\n};\n#if CC_FORWARD_ADD\nuniform CCForwardLight {\n highp vec4 cc_lightPos[1];\n vec4 cc_lightColor[1];\n vec4 cc_lightSizeRangeAngle[1];\n vec4 cc_lightDir[1];\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}\n vec4 CCStandardShading (StandardSurface s) {\n vec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\n vec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\n vec3 diffuseContrib = diffuse / 3.14159265359;\n vec3 N = normalize(s.normal);\n vec3 V = normalize(cc_cameraPos.xyz - s.position);\n float NV = max(abs(dot(N, V)), 0.001);\n specular = BRDFApprox(specular, s.roughness, NV);\n vec3 finalColor = vec3(0.0);\n for (int i = 0; i < 1; i++) {\n vec3 SLU = cc_lightPos[i].xyz - s.position;\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_lightSizeRangeAngle[i].x;\n float litRadiusSqr = litRadius * litRadius;\n float illum = 3.14159265359 * (litRadiusSqr / max(litRadiusSqr , distSqr));\n float attRadiusSqrInv = 1.0 / max(cc_lightSizeRangeAngle[i].y, 0.01);\n attRadiusSqrInv *= attRadiusSqrInv;\n float att = GetDistAtt(distSqr, attRadiusSqrInv);\n vec3 lspec = specular * CalcSpecular(s.roughness, SNH, SH, N);\n #if CC_SPOTLIGHT\n float cosInner = max(dot(-cc_lightDir[i].xyz, SL), 0.01);\n float cosOuter = cc_lightSizeRangeAngle[i].z;\n float litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\n float litAngleOffset = -cosOuter * litAngleScale;\n att *= GetAngleAtt(SL, -cc_lightDir[i].xyz, litAngleScale, litAngleOffset);\n #endif\n finalColor += SNL * cc_lightColor[i].rgb * cc_lightColor[i].w * illum * att * (diffuseContrib + lspec);\n }\n finalColor = finalColor * s.occlusion;\n return vec4(finalColor, 0.0);\n }\n#else\n vec4 CCStandardShading (StandardSurface s) {\n vec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\n vec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\n vec3 N = normalize(s.normal);\n vec3 V = normalize(cc_cameraPos.xyz - s.position);\n float NV = max(abs(dot(N, V)), 0.001);\n specular = BRDFApprox(specular, s.roughness, NV);\n vec3 L = normalize(-cc_mainLitDir.xyz);\n vec3 H = normalize(L+V);\n float NH = max(dot(N, H), 0.0);\n float NL = max(dot(N, L), 0.001);\n vec3 finalColor = NL * cc_mainLitColor.rgb * cc_mainLitColor.w;\n #if USE_LIGHTMAP && !USE_BATCHING && !USE_INSTANCING\n vec4 lightmap = texture(cc_lightingMap, v_luv);\n finalColor = lightmap.a * lightmap.rgb + (1.0 - lightmap.a) * finalColor;\n #endif\n vec3 diffuseContrib = diffuse / 3.14159265359;\n vec3 specularContrib = specular * CalcSpecular(s.roughness, NH, H, N);\n finalColor *= (diffuseContrib + specularContrib);\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 vec4 envmap = fragTextureLod(cc_environment, R, s.roughness * cc_ambientGround.w);\n #if CC_USE_IBL == 2\n vec3 env = unpackRGBE(envmap);\n #else\n vec3 env = SRGBToLinear(envmap.rgb);\n #endif\n finalColor += env * cc_ambientSky.w * 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.albedo.a);\n }\n#endif\nvec3 ACESToneMap (vec3 color) {\n color = min(color, vec3(8.0));\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}\nvec4 CCFragOutput (vec4 color) {\n #if !CC_USE_HDR\n color.rgb = sqrt(ACESToneMap(color.rgb));\n #endif\n return color;\n}\nuniform Constants {\n vec4 tilingOffset;\n vec4 albedo;\n vec4 albedoScaleAndCutoff;\n vec4 pbrParams;\n vec4 emissive;\n vec4 emissiveScaleParam;\n};\nin vec3 v_position;\nin vec2 v_uv;\nin vec2 v_uv1;\nin vec3 v_normal;\n#if USE_VERTEX_COLOR\n in vec3 v_color;\n#endif\n#if USE_ALBEDO_MAP\n uniform sampler2D albedoMap;\n#endif\n#if USE_NORMAL_MAP\n in vec3 v_tangent;\n in vec3 v_bitangent;\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\n#if USE_LIGHTMAP\n in vec2 v_luv;\n uniform sampler2D cc_lightingMap;\n#endif\n#if USE_ALPHA_TEST\n#endif\nin float factor_fog;\nvoid surf (out StandardSurface s) {\n vec4 baseColor = albedo;\n #if USE_VERTEX_COLOR\n baseColor.rgb *= v_color;\n #endif\n #if USE_ALBEDO_MAP\n vec4 texColor = texture(albedoMap, ALBEDO_UV);\n texColor.rgb = SRGBToLinear(texColor.rgb);\n baseColor *= texColor;\n #endif\n s.albedo = baseColor;\n s.albedo.rgb *= albedoScaleAndCutoff.xyz;\n #if USE_ALPHA_TEST\n if (s.albedo.ALPHA_TEST_CHANNEL < albedoScaleAndCutoff.w) discard;\n #endif\n s.normal = v_normal;\n #if USE_NORMAL_MAP\n vec3 nmmp = texture(normalMap, NORMAL_UV).xyz - vec3(0.5);\n s.normal =\n (nmmp.x * pbrParams.w) * normalize(v_tangent) +\n (nmmp.y * pbrParams.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 vec4 res = texture(pbrMap, PBR_UV);\n pbr.x *= res.OCCLUSION_CHANNEL;\n pbr.y *= res.ROUGHNESS_CHANNEL;\n pbr.z *= res.METALLIC_CHANNEL;\n #endif\n #if USE_METALLIC_ROUGHNESS_MAP\n vec4 metallicRoughness = texture(metallicRoughnessMap, METALLIC_ROUGHNESS_UV);\n pbr.z *= metallicRoughness.METALLIC_CHANNEL;\n pbr.y *= metallicRoughness.ROUGHNESS_CHANNEL;\n #endif\n #if USE_OCCLUSION_MAP\n pbr.x *= texture(occlusionMap, OCCLUSION_UV).OCCLUSION_CHANNEL;\n #endif\n s.occlusion = clamp(pbr.x, 0.0, 0.96);\n s.roughness = clamp(pbr.y, 0.04, 1.0);\n s.metallic = pbr.z;\n s.emissive = emissive.rgb * emissiveScaleParam.xyz;\n #if USE_EMISSIVE_MAP\n s.emissive *= SRGBToLinear(texture(emissiveMap, EMISSIVE_UV).rgb);\n #endif\n}\nvec4 frag () {\n StandardSurface s; surf(s);\n vec4 color = CCStandardShading(s);\n color = vec4(mix(CC_FORWARD_ADD > 0 ? vec3(0.0) : cc_fogColor.rgb, color.rgb, factor_fog), color.a);\n return CCFragOutput(color);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }` }, "glsl1": { "vert": `\nprecision highp float;\nstruct StandardVertInput {\n highp vec4 position;\n vec3 normal;\n vec4 tangent;\n};\nattribute vec3 a_position;\nattribute vec3 a_normal;\nattribute vec2 a_texCoord;\nattribute vec4 a_tangent;\n#if CC_USE_MORPH\n attribute float a_vertexId;\n int getVertexId() {\n return int(a_vertexId);\n }\nuniform vec4 cc_displacementWeights[15];\nuniform vec4 cc_displacementTextureInfo;\n vec4 fetchFlatPixel(sampler2D tex, int pixelIndex) {\n float pixelIndexF = float(pixelIndex);\n vec2 textureResolution = vec2(float(cc_displacementTextureInfo.x), float(cc_displacementTextureInfo.y));\n float pixelX = mod(pixelIndexF, textureResolution.x);\n float pixelY = floor(pixelIndexF / textureResolution.x);\n vec2 uv = (vec2(pixelX, pixelY) + .5) / textureResolution;\n return texture2D(tex, uv);\n }\nfloat getDisplacementWeight(int index) {\n float m = mod(float(index), 4.0);\n if (m < 1.0) {\n return cc_displacementWeights[index / 4].x;\n } else if (m < 2.0) {\n return cc_displacementWeights[index / 4].y;\n } else if (m < 3.0) {\n return cc_displacementWeights[index / 4].z;\n } else {\n return cc_displacementWeights[index / 4].w;\n }\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\n return fetchFlatPixel(tex, vertexIndex).rgb;\n#else\n vec3 result = vec3(0, 0, 0);\n for (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\n int dataPixelStart = int(fetchFlatPixel(tex, iTarget).r);\n result += (fetchFlatPixel(tex, dataPixelStart + vertexIndex).rgb * getDisplacementWeight(iTarget));\n }\n return result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\n uniform sampler2D cc_PositionDisplacements;\n vec3 getPositionDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n uniform sampler2D cc_NormalDisplacements;\n vec3 getNormalDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n uniform sampler2D cc_TangentDisplacements;\n vec3 getTangentDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n }\n#endif\nvoid applyMorph (inout StandardVertInput attr) {\n int vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\n attr.position.xyz = attr.position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n attr.normal.xyz = attr.normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n attr.tangent.xyz = attr.tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\n position.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\nattribute vec4 a_joints;\nattribute vec4 a_weights;\n#if CC_USE_BAKED_ANIMATION\n #if USE_INSTANCING\n attribute highp vec4 a_jointAnimInfo;\n #endif\n uniform highp vec4 cc_jointTextureInfo;\n uniform highp vec4 cc_jointAnimInfo;\n uniform sampler2D cc_jointTexture;\n #if !CC_SUPPORT_FLOAT_TEXTURE\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#else\n uniform highp vec4 cc_joints[90];\n#endif\n#if CC_USE_BAKED_ANIMATION\n #if CC_SUPPORT_FLOAT_TEXTURE\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 3.0 * (a_jointAnimInfo.x * a_jointAnimInfo.y + i) + a_jointAnimInfo.z;\n #else\n highp float j = 3.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y));\n vec4 v2 = texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y));\n vec4 v3 = texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y));\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #else\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 12.0 * (a_jointAnimInfo.x * a_jointAnimInfo.y + i) + a_jointAnimInfo.z;\n #else\n highp float j = 12.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = vec4(\n decode32(texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n );\n vec4 v2 = vec4(\n decode32(texture2D(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n );\n vec4 v3 = vec4(\n decode32(texture2D(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n );\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #endif\n#else\n mat4 getJointMatrix (float i) {\n int idx = int(i);\n vec4 v1 = cc_joints[idx * 3];\n vec4 v2 = cc_joints[idx * 3 + 1];\n vec4 v3 = cc_joints[idx * 3 + 2];\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n#endif\nmat4 skinMatrix () {\n return getJointMatrix(a_joints.x) * a_weights.x\n + getJointMatrix(a_joints.y) * a_weights.y;\n + getJointMatrix(a_joints.z) * a_weights.z;\n + getJointMatrix(a_joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\n mat4 m = skinMatrix();\n position = m * position;\n}\nvoid CCSkin (inout StandardVertInput attr) {\n mat4 m = skinMatrix();\n attr.position = m * attr.position;\n attr.normal = (m * vec4(attr.normal, 0.0)).xyz;\n attr.tangent.xyz = (m * vec4(attr.tangent.xyz, 0.0)).xyz;\n}\n#endif\nuniform highp mat4 cc_matView;\nuniform highp mat4 cc_matProj;\nuniform highp vec4 cc_cameraPos;\nuniform mediump vec4 cc_fogBase;\nuniform mediump vec4 cc_fogAdd;\n#if USE_INSTANCING\n attribute vec4 a_matWorld0;\n attribute vec4 a_matWorld1;\n attribute vec4 a_matWorld2;\n#elif USE_BATCHING\n attribute float a_dyn_batch_id;\n uniform highp mat4 cc_matWorlds[10];\n#else\nuniform highp mat4 cc_matWorld;\nuniform highp mat4 cc_matWorldIT;\nuniform highp vec4 cc_lightingMapUVParam;\n#endif\nuniform vec4 tilingOffset;\nfloat LinearFog(vec4 pos) {\n vec4 wPos = pos;\n float cam_dis = distance(cc_cameraPos, wPos);\n float fogStart = cc_fogBase.x;\n float fogEnd = cc_fogBase.y;\n return clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float fogDensity = cc_fogBase.z;\n float cam_dis = distance(cc_cameraPos, wPos) / fogAtten * 4.;\n float f = exp(-cam_dis * fogDensity);\n return f;\n}\nfloat ExpSquaredFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float fogDensity = cc_fogBase.z;\n float cam_dis = distance(cc_cameraPos, wPos) / fogAtten * 4.;\n float f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\n return f;\n}\nfloat LayeredFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float _FogTop = cc_fogAdd.x;\n float _FogRange = cc_fogAdd.y;\n vec3 camWorldProj = cc_cameraPos.xyz;\n camWorldProj.y = 0.;\n vec3 worldPosProj = wPos.xyz;\n worldPosProj.y = 0.;\n float fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\n float fDeltaY, fDensityIntegral;\n if (cc_cameraPos.y > _FogTop) {\n if (wPos.y < _FogTop) {\n fDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\n fDensityIntegral = fDeltaY * fDeltaY * 0.5;\n } else {\n fDeltaY = 0.;\n fDensityIntegral = 0.;\n }\n } else {\n if (wPos.y < _FogTop) {\n float fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\n float fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\n fDeltaY = abs(fDeltaA - fDeltaB);\n fDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n } else {\n fDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\n fDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n }\n }\n float fDensity;\n if (fDeltaY != 0.) {\n fDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n } else {\n fDensity = 0.;\n }\n float f = exp(-fDensity);\n return f;\n}\nfloat CC_TRANSFER_FOG(vec4 pos) {\n #if CC_USE_FOG == 1\n return LinearFog(pos);\n #elif CC_USE_FOG == 2\n return ExpFog(pos);\n #elif CC_USE_FOG == 3\n return ExpSquaredFog(pos);\n #elif CC_USE_FOG == 4\n return LayeredFog(pos);\n #endif\n return 1.;\n}\n#if USE_VERTEX_COLOR\n attribute vec3 a_color;\n varying vec3 v_color;\n#endif\nvarying vec3 v_position;\nvarying vec3 v_normal;\nvarying vec2 v_uv;\nvarying vec2 v_uv1;\nvarying float factor_fog;\n#if USE_NORMAL_MAP\n varying vec3 v_tangent;\n varying vec3 v_bitangent;\n#endif\n#if HAS_SECOND_UV\n attribute vec2 a_texCoord1;\n#endif\n#if USE_LIGHTMAP && !USE_BATCHING && !USE_INSTANCING\n varying vec2 v_luv;\n#endif\nvec4 vert () {\n StandardVertInput In;\n In.position = vec4(a_position, 1.0);\n In.normal = a_normal;\n In.tangent = a_tangent;\n #if CC_USE_MORPH\n applyMorph(In);\n #endif\n #if CC_USE_SKINNING\n CCSkin(In);\n #endif\n mat4 matWorld, matWorldIT;\n #if USE_INSTANCING\n matWorld = mat4(\n vec4(a_matWorld0.xyz, 0.0),\n vec4(a_matWorld1.xyz, 0.0),\n vec4(a_matWorld2.xyz, 0.0),\n vec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)\n );\n matWorldIT = matWorld;\n #elif USE_BATCHING\n matWorld = cc_matWorlds[int(a_dyn_batch_id)];\n matWorldIT = matWorld;\n #else\n matWorld = cc_matWorld;\n matWorldIT = cc_matWorldIT;\n #endif\n vec4 pos = matWorld * In.position;\n v_position = pos.xyz;\n v_normal = normalize((matWorldIT * vec4(In.normal, 0.0)).xyz);\n #if USE_NORMAL_MAP\n v_tangent = normalize((matWorld * vec4(In.tangent.xyz, 0.0)).xyz);\n v_bitangent = cross(v_normal, v_tangent) * In.tangent.w;\n #endif\n v_uv = a_texCoord * tilingOffset.xy + tilingOffset.zw;\n #if HAS_SECOND_UV\n v_uv1 = a_texCoord1 * tilingOffset.xy + tilingOffset.zw;\n #endif\n #if USE_VERTEX_COLOR\n v_color = a_color;\n #endif\n factor_fog = CC_TRANSFER_FOG(matWorld * In.position);\n #if USE_LIGHTMAP && HAS_SECOND_UV && !USE_BATCHING && !USE_INSTANCING\n v_luv = cc_lightingMapUVParam.xy + a_texCoord1 * cc_lightingMapUVParam.zw;\n #endif\n return cc_matProj * (cc_matView * matWorld) * In.position;\n}\nvoid main() { gl_Position = vert(); }`, - "frag": `\n#ifdef GL_EXT_shader_texture_lod\n#extension GL_EXT_shader_texture_lod: enable\n#endif\nprecision highp float;\nuniform highp vec4 cc_cameraPos;\nuniform mediump vec4 cc_exposure;\nuniform mediump vec4 cc_mainLitDir;\nuniform mediump vec4 cc_mainLitColor;\nuniform mediump vec4 cc_ambientSky;\nuniform mediump vec4 cc_ambientGround;\nuniform mediump vec4 cc_fogColor;\n#if CC_USE_IBL\nuniform samplerCube cc_environment;\nvec3 unpackRGBE (vec4 rgbe) {\n return rgbe.rgb * pow(2.0, rgbe.a * 255.0 - 128.0);\n}\nvec4 fragTextureLod (sampler2D tex, vec2 coord, float lod) {\n #ifdef GL_EXT_shader_texture_lod\n return texture2DLodEXT(tex, coord, lod);\n #else\n return texture2D(tex, coord, lod);\n #endif\n}\nvec4 fragTextureLod (samplerCube tex, vec3 coord, float lod) {\n #ifdef GL_EXT_shader_texture_lod\n return textureCubeLodEXT(tex, coord, lod);\n #else\n return textureCube(tex, coord, lod);\n #endif\n}\n#endif\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\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}\nstruct StandardSurface {\n vec4 albedo;\n vec3 position;\n vec3 normal;\n vec3 emissive;\n float roughness;\n float metallic;\n float occlusion;\n};\n#if CC_FORWARD_ADD\nuniform highp vec4 cc_lightPos[1];\nuniform vec4 cc_lightColor[1];\nuniform vec4 cc_lightSizeRangeAngle[1];\nuniform vec4 cc_lightDir[1];\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}\n vec4 CCStandardShading (StandardSurface s) {\n vec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\n vec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\n vec3 diffuseContrib = diffuse / 3.14159265359;\n vec3 N = normalize(s.normal);\n vec3 V = normalize(cc_cameraPos.xyz - s.position);\n float NV = max(abs(dot(N, V)), 0.001);\n specular = BRDFApprox(specular, s.roughness, NV);\n vec3 finalColor = vec3(0.0);\n for (int i = 0; i < 1; i++) {\n vec3 SLU = cc_lightPos[i].xyz - s.position;\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_lightSizeRangeAngle[i].x;\n float litRadiusSqr = litRadius * litRadius;\n float illum = 3.14159265359 * (litRadiusSqr / max(litRadiusSqr , distSqr));\n float attRadiusSqrInv = 1.0 / max(cc_lightSizeRangeAngle[i].y, 0.01);\n attRadiusSqrInv *= attRadiusSqrInv;\n float att = GetDistAtt(distSqr, attRadiusSqrInv);\n vec3 lspec = specular * CalcSpecular(s.roughness, SNH, SH, N);\n #if CC_SPOTLIGHT\n float cosInner = max(dot(-cc_lightDir[i].xyz, SL), 0.01);\n float cosOuter = cc_lightSizeRangeAngle[i].z;\n float litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\n float litAngleOffset = -cosOuter * litAngleScale;\n att *= GetAngleAtt(SL, -cc_lightDir[i].xyz, litAngleScale, litAngleOffset);\n #endif\n finalColor += SNL * cc_lightColor[i].rgb * cc_lightColor[i].w * illum * att * (diffuseContrib + lspec);\n }\n return vec4(finalColor, 0.0);\n }\n#else\n vec4 CCStandardShading (StandardSurface s) {\n vec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\n vec3 specular = mix(vec3(0.04), s.albedo.rgb, 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 diffuseContrib = diffuse / 3.14159265359;\n vec3 specularContrib = specular * CalcSpecular(s.roughness, NH, H, N);\n vec3 finalColor = NL * cc_mainLitColor.rgb * cc_mainLitColor.w * (diffuseContrib + specularContrib);\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 vec4 envmap = fragTextureLod(cc_environment, R, s.roughness * cc_ambientGround.w);\n #if CC_USE_IBL == 2\n vec3 env = unpackRGBE(envmap);\n #else\n vec3 env = SRGBToLinear(envmap.rgb);\n #endif\n finalColor += env * cc_ambientSky.w * 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.albedo.a);\n }\n#endif\nvec3 ACESToneMap (vec3 color) {\n color = min(color, vec3(8.0));\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}\nvec4 CCFragOutput (vec4 color) {\n #if !CC_USE_HDR\n color.rgb = sqrt(ACESToneMap(color.rgb));\n #endif\n return color;\n}\nuniform vec4 albedo;\nuniform vec4 albedoScaleAndCutoff;\nuniform vec4 pbrParams;\nuniform vec4 emissive;\nuniform vec4 emissiveScaleParam;\nvarying vec3 v_position;\nvarying vec2 v_uv;\nvarying vec2 v_uv1;\nvarying vec3 v_normal;\n#if USE_VERTEX_COLOR\n varying vec3 v_color;\n#endif\n#if USE_ALBEDO_MAP\n uniform sampler2D albedoMap;\n#endif\n#if USE_NORMAL_MAP\n varying vec3 v_tangent;\n varying vec3 v_bitangent;\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\n#if USE_LIGHTMAP\n varying vec2 v_luv;\n uniform sampler2D cc_lightingMap;\n#endif\n#if USE_ALPHA_TEST\n#endif\nvarying float factor_fog;\nvoid surf (out StandardSurface s) {\n vec4 baseColor = albedo;\n #if USE_VERTEX_COLOR\n baseColor.rgb *= v_color;\n #endif\n #if USE_ALBEDO_MAP\n vec4 texColor = texture2D(albedoMap, ALBEDO_UV);\n texColor.rgb = SRGBToLinear(texColor.rgb);\n baseColor *= texColor;\n #endif\n s.albedo = baseColor;\n s.albedo.rgb *= albedoScaleAndCutoff.xyz;\n #if USE_ALPHA_TEST\n if (s.albedo.ALPHA_TEST_CHANNEL < albedoScaleAndCutoff.w) discard;\n #endif\n s.normal = v_normal;\n #if USE_NORMAL_MAP\n vec3 nmmp = texture2D(normalMap, NORMAL_UV).xyz - vec3(0.5);\n s.normal =\n (nmmp.x * pbrParams.w) * normalize(v_tangent) +\n (nmmp.y * pbrParams.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 vec4 res = texture2D(pbrMap, PBR_UV);\n pbr.x *= res.OCCLUSION_CHANNEL;\n pbr.y *= res.ROUGHNESS_CHANNEL;\n pbr.z *= res.METALLIC_CHANNEL;\n #endif\n #if USE_METALLIC_ROUGHNESS_MAP\n vec4 metallicRoughness = texture2D(metallicRoughnessMap, METALLIC_ROUGHNESS_UV);\n pbr.z *= metallicRoughness.METALLIC_CHANNEL;\n pbr.y *= metallicRoughness.ROUGHNESS_CHANNEL;\n #endif\n #if USE_OCCLUSION_MAP\n pbr.x *= texture2D(occlusionMap, OCCLUSION_UV).OCCLUSION_CHANNEL;\n #endif\n s.occlusion = clamp(pbr.x, 0.0, 0.96);\n s.roughness = clamp(pbr.y, 0.04, 1.0);\n s.metallic = pbr.z;\n s.emissive = emissive.rgb * emissiveScaleParam.xyz;\n #if USE_EMISSIVE_MAP\n s.emissive *= SRGBToLinear(texture2D(emissiveMap, EMISSIVE_UV).rgb);\n #endif\n}\nvec4 frag () {\n StandardSurface s; surf(s);\n vec4 color = CCStandardShading(s);\n #if USE_LIGHTMAP && !USE_BATCHING && !USE_INSTANCING && CC_FOWARD_ADD == 0\n vec4 lighting = texture2D(cc_lightingMap, v_luv);\n float fAmb = 0.5 - s.normal.y * 0.5;\n vec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb) * cc_ambientSky.w;\n vec3 finalColor = (ambDiff.rgb * s.albedo.rgb);\n finalColor += lighting.rgb * s.albedo.rgb;\n finalColor = finalColor * s.occlusion;\n finalColor += s.emissive;\n color.rgb = lighting.a * finalColor + (1.0 - lighting.a) * color.rgb;\n #endif\n color = vec4(mix(cc_fogColor.rgb, CC_FORWARD_ADD > 0 ? vec3(0.0) : color.rgb, factor_fog), color.a);\n return CCFragOutput(color);\n}\nvoid main() { gl_FragColor = frag(); }` + "frag": `\n#ifdef GL_EXT_shader_texture_lod\n#extension GL_EXT_shader_texture_lod: enable\n#endif\nprecision highp float;\nuniform highp vec4 cc_cameraPos;\nuniform mediump vec4 cc_exposure;\nuniform mediump vec4 cc_mainLitDir;\nuniform mediump vec4 cc_mainLitColor;\nuniform mediump vec4 cc_ambientSky;\nuniform mediump vec4 cc_ambientGround;\nuniform mediump vec4 cc_fogColor;\n#if CC_USE_IBL\nuniform samplerCube cc_environment;\nvec3 unpackRGBE (vec4 rgbe) {\n return rgbe.rgb * pow(2.0, rgbe.a * 255.0 - 128.0);\n}\nvec4 fragTextureLod (sampler2D tex, vec2 coord, float lod) {\n #ifdef GL_EXT_shader_texture_lod\n return texture2DLodEXT(tex, coord, lod);\n #else\n return texture2D(tex, coord, lod);\n #endif\n}\nvec4 fragTextureLod (samplerCube tex, vec3 coord, float lod) {\n #ifdef GL_EXT_shader_texture_lod\n return textureCubeLodEXT(tex, coord, lod);\n #else\n return textureCube(tex, coord, lod);\n #endif\n}\n#endif\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\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}\nstruct StandardSurface {\n vec4 albedo;\n vec3 position;\n vec3 normal;\n vec3 emissive;\n float roughness;\n float metallic;\n float occlusion;\n};\n#if CC_FORWARD_ADD\nuniform highp vec4 cc_lightPos[1];\nuniform vec4 cc_lightColor[1];\nuniform vec4 cc_lightSizeRangeAngle[1];\nuniform vec4 cc_lightDir[1];\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}\n vec4 CCStandardShading (StandardSurface s) {\n vec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\n vec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\n vec3 diffuseContrib = diffuse / 3.14159265359;\n vec3 N = normalize(s.normal);\n vec3 V = normalize(cc_cameraPos.xyz - s.position);\n float NV = max(abs(dot(N, V)), 0.001);\n specular = BRDFApprox(specular, s.roughness, NV);\n vec3 finalColor = vec3(0.0);\n for (int i = 0; i < 1; i++) {\n vec3 SLU = cc_lightPos[i].xyz - s.position;\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_lightSizeRangeAngle[i].x;\n float litRadiusSqr = litRadius * litRadius;\n float illum = 3.14159265359 * (litRadiusSqr / max(litRadiusSqr , distSqr));\n float attRadiusSqrInv = 1.0 / max(cc_lightSizeRangeAngle[i].y, 0.01);\n attRadiusSqrInv *= attRadiusSqrInv;\n float att = GetDistAtt(distSqr, attRadiusSqrInv);\n vec3 lspec = specular * CalcSpecular(s.roughness, SNH, SH, N);\n #if CC_SPOTLIGHT\n float cosInner = max(dot(-cc_lightDir[i].xyz, SL), 0.01);\n float cosOuter = cc_lightSizeRangeAngle[i].z;\n float litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\n float litAngleOffset = -cosOuter * litAngleScale;\n att *= GetAngleAtt(SL, -cc_lightDir[i].xyz, litAngleScale, litAngleOffset);\n #endif\n finalColor += SNL * cc_lightColor[i].rgb * cc_lightColor[i].w * illum * att * (diffuseContrib + lspec);\n }\n finalColor = finalColor * s.occlusion;\n return vec4(finalColor, 0.0);\n }\n#else\n vec4 CCStandardShading (StandardSurface s) {\n vec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\n vec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\n vec3 N = normalize(s.normal);\n vec3 V = normalize(cc_cameraPos.xyz - s.position);\n float NV = max(abs(dot(N, V)), 0.001);\n specular = BRDFApprox(specular, s.roughness, NV);\n vec3 L = normalize(-cc_mainLitDir.xyz);\n vec3 H = normalize(L+V);\n float NH = max(dot(N, H), 0.0);\n float NL = max(dot(N, L), 0.001);\n vec3 finalColor = NL * cc_mainLitColor.rgb * cc_mainLitColor.w;\n #if USE_LIGHTMAP && !USE_BATCHING && !USE_INSTANCING\n vec4 lightmap = texture2D(cc_lightingMap, v_luv);\n finalColor = lightmap.a * lightmap.rgb + (1.0 - lightmap.a) * finalColor;\n #endif\n vec3 diffuseContrib = diffuse / 3.14159265359;\n vec3 specularContrib = specular * CalcSpecular(s.roughness, NH, H, N);\n finalColor *= (diffuseContrib + specularContrib);\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 vec4 envmap = fragTextureLod(cc_environment, R, s.roughness * cc_ambientGround.w);\n #if CC_USE_IBL == 2\n vec3 env = unpackRGBE(envmap);\n #else\n vec3 env = SRGBToLinear(envmap.rgb);\n #endif\n finalColor += env * cc_ambientSky.w * 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.albedo.a);\n }\n#endif\nvec3 ACESToneMap (vec3 color) {\n color = min(color, vec3(8.0));\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}\nvec4 CCFragOutput (vec4 color) {\n #if !CC_USE_HDR\n color.rgb = sqrt(ACESToneMap(color.rgb));\n #endif\n return color;\n}\nuniform vec4 albedo;\nuniform vec4 albedoScaleAndCutoff;\nuniform vec4 pbrParams;\nuniform vec4 emissive;\nuniform vec4 emissiveScaleParam;\nvarying vec3 v_position;\nvarying vec2 v_uv;\nvarying vec2 v_uv1;\nvarying vec3 v_normal;\n#if USE_VERTEX_COLOR\n varying vec3 v_color;\n#endif\n#if USE_ALBEDO_MAP\n uniform sampler2D albedoMap;\n#endif\n#if USE_NORMAL_MAP\n varying vec3 v_tangent;\n varying vec3 v_bitangent;\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\n#if USE_LIGHTMAP\n varying vec2 v_luv;\n uniform sampler2D cc_lightingMap;\n#endif\n#if USE_ALPHA_TEST\n#endif\nvarying float factor_fog;\nvoid surf (out StandardSurface s) {\n vec4 baseColor = albedo;\n #if USE_VERTEX_COLOR\n baseColor.rgb *= v_color;\n #endif\n #if USE_ALBEDO_MAP\n vec4 texColor = texture2D(albedoMap, ALBEDO_UV);\n texColor.rgb = SRGBToLinear(texColor.rgb);\n baseColor *= texColor;\n #endif\n s.albedo = baseColor;\n s.albedo.rgb *= albedoScaleAndCutoff.xyz;\n #if USE_ALPHA_TEST\n if (s.albedo.ALPHA_TEST_CHANNEL < albedoScaleAndCutoff.w) discard;\n #endif\n s.normal = v_normal;\n #if USE_NORMAL_MAP\n vec3 nmmp = texture2D(normalMap, NORMAL_UV).xyz - vec3(0.5);\n s.normal =\n (nmmp.x * pbrParams.w) * normalize(v_tangent) +\n (nmmp.y * pbrParams.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 vec4 res = texture2D(pbrMap, PBR_UV);\n pbr.x *= res.OCCLUSION_CHANNEL;\n pbr.y *= res.ROUGHNESS_CHANNEL;\n pbr.z *= res.METALLIC_CHANNEL;\n #endif\n #if USE_METALLIC_ROUGHNESS_MAP\n vec4 metallicRoughness = texture2D(metallicRoughnessMap, METALLIC_ROUGHNESS_UV);\n pbr.z *= metallicRoughness.METALLIC_CHANNEL;\n pbr.y *= metallicRoughness.ROUGHNESS_CHANNEL;\n #endif\n #if USE_OCCLUSION_MAP\n pbr.x *= texture2D(occlusionMap, OCCLUSION_UV).OCCLUSION_CHANNEL;\n #endif\n s.occlusion = clamp(pbr.x, 0.0, 0.96);\n s.roughness = clamp(pbr.y, 0.04, 1.0);\n s.metallic = pbr.z;\n s.emissive = emissive.rgb * emissiveScaleParam.xyz;\n #if USE_EMISSIVE_MAP\n s.emissive *= SRGBToLinear(texture2D(emissiveMap, EMISSIVE_UV).rgb);\n #endif\n}\nvec4 frag () {\n StandardSurface s; surf(s);\n vec4 color = CCStandardShading(s);\n color = vec4(mix(CC_FORWARD_ADD > 0 ? vec3(0.0) : cc_fogColor.rgb, color.rgb, factor_fog), color.a);\n return CCFragOutput(color);\n}\nvoid main() { gl_FragColor = frag(); }` }, "glsl4": { "vert": `\n#ifdef GL_EXT_shader_explicit_arithmetic_types_int16\n#extension GL_EXT_shader_explicit_arithmetic_types_int16: enable\n#endif\nprecision highp float;\nstruct StandardVertInput {\n highp vec4 position;\n vec3 normal;\n vec4 tangent;\n};\nlayout(location = 0) in vec3 a_position;\nlayout(location = 1) in vec3 a_normal;\nlayout(location = 2) in vec2 a_texCoord;\nlayout(location = 3) in vec4 a_tangent;\n#if CC_USE_MORPH\n layout(location = 6) in float a_vertexId;\n int getVertexId() {\n return int(a_vertexId);\n }\nlayout(binding = 16) uniform CCMorph {\n vec4 cc_displacementWeights[15];\n vec4 cc_displacementTextureInfo;\n};\n vec4 fetchFlatPixel(sampler2D tex, int pixelIndex) {\n float pixelIndexF = float(pixelIndex);\n vec2 textureResolution = vec2(float(cc_displacementTextureInfo.x), float(cc_displacementTextureInfo.y));\n float pixelX = mod(pixelIndexF, textureResolution.x);\n float pixelY = floor(pixelIndexF / textureResolution.x);\n vec2 uv = (vec2(pixelX, pixelY) + .5) / textureResolution;\n return texture(tex, uv);\n }\nfloat getDisplacementWeight(int index) {\n float m = mod(float(index), 4.0);\n if (m < 1.0) {\n return cc_displacementWeights[index / 4].x;\n } else if (m < 2.0) {\n return cc_displacementWeights[index / 4].y;\n } else if (m < 3.0) {\n return cc_displacementWeights[index / 4].z;\n } else {\n return cc_displacementWeights[index / 4].w;\n }\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\n return fetchFlatPixel(tex, vertexIndex).rgb;\n#else\n vec3 result = vec3(0, 0, 0);\n for (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\n int dataPixelStart = int(fetchFlatPixel(tex, iTarget).r);\n result += (fetchFlatPixel(tex, dataPixelStart + vertexIndex).rgb * getDisplacementWeight(iTarget));\n }\n return result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\n layout(binding = 27) uniform sampler2D cc_PositionDisplacements;\n vec3 getPositionDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n layout(binding = 28) uniform sampler2D cc_NormalDisplacements;\n vec3 getNormalDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n layout(binding = 29) uniform sampler2D cc_TangentDisplacements;\n vec3 getTangentDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n }\n#endif\nvoid applyMorph (inout StandardVertInput attr) {\n int vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\n attr.position.xyz = attr.position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n attr.normal.xyz = attr.normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n attr.tangent.xyz = attr.tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\n position.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\nlayout(location = 4) in u16vec4 a_joints;\nlayout(location = 5) in vec4 a_weights;\n#if CC_USE_BAKED_ANIMATION\n #if USE_INSTANCING\n layout(location = 7) in highp vec4 a_jointAnimInfo;\n #endif\n layout(binding = 18) uniform CCSkinningTexture {\n highp vec4 cc_jointTextureInfo;\n };\n layout(binding = 19) uniform CCSkinningAnimation {\n highp vec4 cc_jointAnimInfo;\n };\n layout(binding = 25) uniform sampler2D cc_jointTexture;\n #if !CC_SUPPORT_FLOAT_TEXTURE\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#else\n layout(binding = 18) uniform CCSkinning {\n highp vec4 cc_joints[30 * 3];\n };\n#endif\n#if CC_USE_BAKED_ANIMATION\n #if CC_SUPPORT_FLOAT_TEXTURE\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 3.0 * (a_jointAnimInfo.x * a_jointAnimInfo.y + i) + a_jointAnimInfo.z;\n #else\n highp float j = 3.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = texture(cc_jointTexture, vec2((x + 0.5) * invSize, y));\n vec4 v2 = texture(cc_jointTexture, vec2((x + 1.5) * invSize, y));\n vec4 v3 = texture(cc_jointTexture, vec2((x + 2.5) * invSize, y));\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #else\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 12.0 * (a_jointAnimInfo.x * a_jointAnimInfo.y + i) + a_jointAnimInfo.z;\n #else\n highp float j = 12.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = vec4(\n decode32(texture(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n );\n vec4 v2 = vec4(\n decode32(texture(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n );\n vec4 v3 = vec4(\n decode32(texture(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n );\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #endif\n#else\n mat4 getJointMatrix (float i) {\n int idx = int(i);\n vec4 v1 = cc_joints[idx * 3];\n vec4 v2 = cc_joints[idx * 3 + 1];\n vec4 v3 = cc_joints[idx * 3 + 2];\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n#endif\nmat4 skinMatrix () {\n return getJointMatrix(a_joints.x) * a_weights.x\n + getJointMatrix(a_joints.y) * a_weights.y;\n + getJointMatrix(a_joints.z) * a_weights.z;\n + getJointMatrix(a_joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\n mat4 m = skinMatrix();\n position = m * position;\n}\nvoid CCSkin (inout StandardVertInput attr) {\n mat4 m = skinMatrix();\n attr.position = m * attr.position;\n attr.normal = (m * vec4(attr.normal, 0.0)).xyz;\n attr.tangent.xyz = (m * vec4(attr.tangent.xyz, 0.0)).xyz;\n}\n#endif\nlayout(binding = 23) uniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\n#if USE_INSTANCING\n layout(location = 8) in vec4 a_matWorld0;\n layout(location = 9) in vec4 a_matWorld1;\n layout(location = 10) in vec4 a_matWorld2;\n#elif USE_BATCHING\n layout(location = 11) in float a_dyn_batch_id;\n layout(binding = 21) uniform CCLocalBatched {\n highp mat4 cc_matWorlds[10];\n };\n#else\nlayout(binding = 21) uniform CCLocal {\n highp mat4 cc_matWorld;\n highp mat4 cc_matWorldIT;\n highp vec4 cc_lightingMapUVParam;\n};\n#endif\nlayout(binding = 0) uniform Constants {\n vec4 tilingOffset;\n vec4 albedo;\n vec4 albedoScaleAndCutoff;\n vec4 pbrParams;\n vec4 emissive;\n vec4 emissiveScaleParam;\n};\nfloat LinearFog(vec4 pos) {\n vec4 wPos = pos;\n float cam_dis = distance(cc_cameraPos, wPos);\n float fogStart = cc_fogBase.x;\n float fogEnd = cc_fogBase.y;\n return clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float fogDensity = cc_fogBase.z;\n float cam_dis = distance(cc_cameraPos, wPos) / fogAtten * 4.;\n float f = exp(-cam_dis * fogDensity);\n return f;\n}\nfloat ExpSquaredFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float fogDensity = cc_fogBase.z;\n float cam_dis = distance(cc_cameraPos, wPos) / fogAtten * 4.;\n float f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\n return f;\n}\nfloat LayeredFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float _FogTop = cc_fogAdd.x;\n float _FogRange = cc_fogAdd.y;\n vec3 camWorldProj = cc_cameraPos.xyz;\n camWorldProj.y = 0.;\n vec3 worldPosProj = wPos.xyz;\n worldPosProj.y = 0.;\n float fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\n float fDeltaY, fDensityIntegral;\n if (cc_cameraPos.y > _FogTop) {\n if (wPos.y < _FogTop) {\n fDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\n fDensityIntegral = fDeltaY * fDeltaY * 0.5;\n } else {\n fDeltaY = 0.;\n fDensityIntegral = 0.;\n }\n } else {\n if (wPos.y < _FogTop) {\n float fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\n float fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\n fDeltaY = abs(fDeltaA - fDeltaB);\n fDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n } else {\n fDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\n fDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n }\n }\n float fDensity;\n if (fDeltaY != 0.) {\n fDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n } else {\n fDensity = 0.;\n }\n float f = exp(-fDensity);\n return f;\n}\nfloat CC_TRANSFER_FOG(vec4 pos) {\n #if CC_USE_FOG == 1\n return LinearFog(pos);\n #elif CC_USE_FOG == 2\n return ExpFog(pos);\n #elif CC_USE_FOG == 3\n return ExpSquaredFog(pos);\n #elif CC_USE_FOG == 4\n return LayeredFog(pos);\n #endif\n return 1.;\n}\n#if USE_VERTEX_COLOR\n layout(location = 12) in vec3 a_color;\n layout(location = 0) out vec3 v_color;\n#endif\nlayout(location = 1) out vec3 v_position;\nlayout(location = 2) out vec3 v_normal;\nlayout(location = 3) out vec2 v_uv;\nlayout(location = 4) out vec2 v_uv1;\nlayout(location = 5) out float factor_fog;\n#if USE_NORMAL_MAP\n layout(location = 6) out vec3 v_tangent;\n layout(location = 7) out vec3 v_bitangent;\n#endif\n#if HAS_SECOND_UV\n layout(location = 13) in vec2 a_texCoord1;\n#endif\n#if USE_LIGHTMAP && !USE_BATCHING && !USE_INSTANCING\n layout(location = 8) out vec2 v_luv;\n#endif\nvec4 vert () {\n StandardVertInput In;\n In.position = vec4(a_position, 1.0);\n In.normal = a_normal;\n In.tangent = a_tangent;\n #if CC_USE_MORPH\n applyMorph(In);\n #endif\n #if CC_USE_SKINNING\n CCSkin(In);\n #endif\n mat4 matWorld, matWorldIT;\n #if USE_INSTANCING\n matWorld = mat4(\n vec4(a_matWorld0.xyz, 0.0),\n vec4(a_matWorld1.xyz, 0.0),\n vec4(a_matWorld2.xyz, 0.0),\n vec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)\n );\n matWorldIT = matWorld;\n #elif USE_BATCHING\n matWorld = cc_matWorlds[int(a_dyn_batch_id)];\n matWorldIT = matWorld;\n #else\n matWorld = cc_matWorld;\n matWorldIT = cc_matWorldIT;\n #endif\n vec4 pos = matWorld * In.position;\n v_position = pos.xyz;\n v_normal = normalize((matWorldIT * vec4(In.normal, 0.0)).xyz);\n #if USE_NORMAL_MAP\n v_tangent = normalize((matWorld * vec4(In.tangent.xyz, 0.0)).xyz);\n v_bitangent = cross(v_normal, v_tangent) * In.tangent.w;\n #endif\n v_uv = a_texCoord * tilingOffset.xy + tilingOffset.zw;\n #if HAS_SECOND_UV\n v_uv1 = a_texCoord1 * tilingOffset.xy + tilingOffset.zw;\n #endif\n #if USE_VERTEX_COLOR\n v_color = a_color;\n #endif\n factor_fog = CC_TRANSFER_FOG(matWorld * In.position);\n #if USE_LIGHTMAP && HAS_SECOND_UV && !USE_BATCHING && !USE_INSTANCING\n v_luv = cc_lightingMapUVParam.xy + a_texCoord1 * cc_lightingMapUVParam.zw;\n #endif\n return cc_matProj * (cc_matView * matWorld) * In.position;\n}\nvoid main() { gl_Position = vert(); }`, - "frag": `\nprecision highp float;\nlayout(binding = 23) uniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\n#if CC_USE_IBL\nlayout(binding = 26) uniform samplerCube cc_environment;\nvec3 unpackRGBE (vec4 rgbe) {\n return rgbe.rgb * pow(2.0, rgbe.a * 255.0 - 128.0);\n}\nvec4 fragTextureLod (sampler2D tex, vec2 coord, float lod) {\n return textureLod(tex, coord, lod);\n}\nvec4 fragTextureLod (samplerCube tex, vec3 coord, float lod) {\n return textureLod(tex, coord, lod);\n}\n#endif\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\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}\nstruct StandardSurface {\n vec4 albedo;\n vec3 position;\n vec3 normal;\n vec3 emissive;\n float roughness;\n float metallic;\n float occlusion;\n};\n#if CC_FORWARD_ADD\nlayout(binding = 20) uniform CCForwardLight {\n highp vec4 cc_lightPos[1];\n vec4 cc_lightColor[1];\n vec4 cc_lightSizeRangeAngle[1];\n vec4 cc_lightDir[1];\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}\n vec4 CCStandardShading (StandardSurface s) {\n vec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\n vec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\n vec3 diffuseContrib = diffuse / 3.14159265359;\n vec3 N = normalize(s.normal);\n vec3 V = normalize(cc_cameraPos.xyz - s.position);\n float NV = max(abs(dot(N, V)), 0.001);\n specular = BRDFApprox(specular, s.roughness, NV);\n vec3 finalColor = vec3(0.0);\n for (int i = 0; i < 1; i++) {\n vec3 SLU = cc_lightPos[i].xyz - s.position;\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_lightSizeRangeAngle[i].x;\n float litRadiusSqr = litRadius * litRadius;\n float illum = 3.14159265359 * (litRadiusSqr / max(litRadiusSqr , distSqr));\n float attRadiusSqrInv = 1.0 / max(cc_lightSizeRangeAngle[i].y, 0.01);\n attRadiusSqrInv *= attRadiusSqrInv;\n float att = GetDistAtt(distSqr, attRadiusSqrInv);\n vec3 lspec = specular * CalcSpecular(s.roughness, SNH, SH, N);\n #if CC_SPOTLIGHT\n float cosInner = max(dot(-cc_lightDir[i].xyz, SL), 0.01);\n float cosOuter = cc_lightSizeRangeAngle[i].z;\n float litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\n float litAngleOffset = -cosOuter * litAngleScale;\n att *= GetAngleAtt(SL, -cc_lightDir[i].xyz, litAngleScale, litAngleOffset);\n #endif\n finalColor += SNL * cc_lightColor[i].rgb * cc_lightColor[i].w * illum * att * (diffuseContrib + lspec);\n }\n return vec4(finalColor, 0.0);\n }\n#else\n vec4 CCStandardShading (StandardSurface s) {\n vec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\n vec3 specular = mix(vec3(0.04), s.albedo.rgb, 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 diffuseContrib = diffuse / 3.14159265359;\n vec3 specularContrib = specular * CalcSpecular(s.roughness, NH, H, N);\n vec3 finalColor = NL * cc_mainLitColor.rgb * cc_mainLitColor.w * (diffuseContrib + specularContrib);\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 vec4 envmap = fragTextureLod(cc_environment, R, s.roughness * cc_ambientGround.w);\n #if CC_USE_IBL == 2\n vec3 env = unpackRGBE(envmap);\n #else\n vec3 env = SRGBToLinear(envmap.rgb);\n #endif\n finalColor += env * cc_ambientSky.w * 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.albedo.a);\n }\n#endif\nvec3 ACESToneMap (vec3 color) {\n color = min(color, vec3(8.0));\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}\nvec4 CCFragOutput (vec4 color) {\n #if !CC_USE_HDR\n color.rgb = sqrt(ACESToneMap(color.rgb));\n #endif\n return color;\n}\nlayout(binding = 0) uniform Constants {\n vec4 tilingOffset;\n vec4 albedo;\n vec4 albedoScaleAndCutoff;\n vec4 pbrParams;\n vec4 emissive;\n vec4 emissiveScaleParam;\n};\nlayout(location = 1) in vec3 v_position;\nlayout(location = 3) in vec2 v_uv;\nlayout(location = 4) in vec2 v_uv1;\nlayout(location = 2) in vec3 v_normal;\n#if USE_VERTEX_COLOR\n layout(location = 0) in vec3 v_color;\n#endif\n#if USE_ALBEDO_MAP\n layout(binding = 31) uniform sampler2D albedoMap;\n#endif\n#if USE_NORMAL_MAP\n layout(location = 6) in vec3 v_tangent;\n layout(location = 7) in vec3 v_bitangent;\n layout(binding = 32) uniform sampler2D normalMap;\n#endif\n#if USE_PBR_MAP\n layout(binding = 33) uniform sampler2D pbrMap;\n#endif\n#if USE_METALLIC_ROUGHNESS_MAP\n layout(binding = 34) uniform sampler2D metallicRoughnessMap;\n#endif\n#if USE_OCCLUSION_MAP\n layout(binding = 35) uniform sampler2D occlusionMap;\n#endif\n#if USE_EMISSIVE_MAP\n layout(binding = 36) uniform sampler2D emissiveMap;\n#endif\n#if USE_LIGHTMAP\n layout(location = 8) in vec2 v_luv;\n layout(binding = 30) uniform sampler2D cc_lightingMap;\n#endif\n#if USE_ALPHA_TEST\n#endif\nlayout(location = 5) in float factor_fog;\nvoid surf (out StandardSurface s) {\n vec4 baseColor = albedo;\n #if USE_VERTEX_COLOR\n baseColor.rgb *= v_color;\n #endif\n #if USE_ALBEDO_MAP\n vec4 texColor = texture(albedoMap, ALBEDO_UV);\n texColor.rgb = SRGBToLinear(texColor.rgb);\n baseColor *= texColor;\n #endif\n s.albedo = baseColor;\n s.albedo.rgb *= albedoScaleAndCutoff.xyz;\n #if USE_ALPHA_TEST\n if (s.albedo.ALPHA_TEST_CHANNEL < albedoScaleAndCutoff.w) discard;\n #endif\n s.normal = v_normal;\n #if USE_NORMAL_MAP\n vec3 nmmp = texture(normalMap, NORMAL_UV).xyz - vec3(0.5);\n s.normal =\n (nmmp.x * pbrParams.w) * normalize(v_tangent) +\n (nmmp.y * pbrParams.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 vec4 res = texture(pbrMap, PBR_UV);\n pbr.x *= res.OCCLUSION_CHANNEL;\n pbr.y *= res.ROUGHNESS_CHANNEL;\n pbr.z *= res.METALLIC_CHANNEL;\n #endif\n #if USE_METALLIC_ROUGHNESS_MAP\n vec4 metallicRoughness = texture(metallicRoughnessMap, METALLIC_ROUGHNESS_UV);\n pbr.z *= metallicRoughness.METALLIC_CHANNEL;\n pbr.y *= metallicRoughness.ROUGHNESS_CHANNEL;\n #endif\n #if USE_OCCLUSION_MAP\n pbr.x *= texture(occlusionMap, OCCLUSION_UV).OCCLUSION_CHANNEL;\n #endif\n s.occlusion = clamp(pbr.x, 0.0, 0.96);\n s.roughness = clamp(pbr.y, 0.04, 1.0);\n s.metallic = pbr.z;\n s.emissive = emissive.rgb * emissiveScaleParam.xyz;\n #if USE_EMISSIVE_MAP\n s.emissive *= SRGBToLinear(texture(emissiveMap, EMISSIVE_UV).rgb);\n #endif\n}\nvec4 frag () {\n StandardSurface s; surf(s);\n vec4 color = CCStandardShading(s);\n #if USE_LIGHTMAP && !USE_BATCHING && !USE_INSTANCING && CC_FOWARD_ADD == 0\n vec4 lighting = texture(cc_lightingMap, v_luv);\n float fAmb = 0.5 - s.normal.y * 0.5;\n vec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb) * cc_ambientSky.w;\n vec3 finalColor = (ambDiff.rgb * s.albedo.rgb);\n finalColor += lighting.rgb * s.albedo.rgb;\n finalColor = finalColor * s.occlusion;\n finalColor += s.emissive;\n color.rgb = lighting.a * finalColor + (1.0 - lighting.a) * color.rgb;\n #endif\n color = vec4(mix(cc_fogColor.rgb, CC_FORWARD_ADD > 0 ? vec3(0.0) : color.rgb, factor_fog), color.a);\n return CCFragOutput(color);\n}\nlayout(location = 0) out vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }` + "frag": `\nprecision highp float;\nlayout(binding = 23) uniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\n#if CC_USE_IBL\nlayout(binding = 26) uniform samplerCube cc_environment;\nvec3 unpackRGBE (vec4 rgbe) {\n return rgbe.rgb * pow(2.0, rgbe.a * 255.0 - 128.0);\n}\nvec4 fragTextureLod (sampler2D tex, vec2 coord, float lod) {\n return textureLod(tex, coord, lod);\n}\nvec4 fragTextureLod (samplerCube tex, vec3 coord, float lod) {\n return textureLod(tex, coord, lod);\n}\n#endif\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\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}\nstruct StandardSurface {\n vec4 albedo;\n vec3 position;\n vec3 normal;\n vec3 emissive;\n float roughness;\n float metallic;\n float occlusion;\n};\n#if CC_FORWARD_ADD\nlayout(binding = 20) uniform CCForwardLight {\n highp vec4 cc_lightPos[1];\n vec4 cc_lightColor[1];\n vec4 cc_lightSizeRangeAngle[1];\n vec4 cc_lightDir[1];\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}\n vec4 CCStandardShading (StandardSurface s) {\n vec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\n vec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\n vec3 diffuseContrib = diffuse / 3.14159265359;\n vec3 N = normalize(s.normal);\n vec3 V = normalize(cc_cameraPos.xyz - s.position);\n float NV = max(abs(dot(N, V)), 0.001);\n specular = BRDFApprox(specular, s.roughness, NV);\n vec3 finalColor = vec3(0.0);\n for (int i = 0; i < 1; i++) {\n vec3 SLU = cc_lightPos[i].xyz - s.position;\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_lightSizeRangeAngle[i].x;\n float litRadiusSqr = litRadius * litRadius;\n float illum = 3.14159265359 * (litRadiusSqr / max(litRadiusSqr , distSqr));\n float attRadiusSqrInv = 1.0 / max(cc_lightSizeRangeAngle[i].y, 0.01);\n attRadiusSqrInv *= attRadiusSqrInv;\n float att = GetDistAtt(distSqr, attRadiusSqrInv);\n vec3 lspec = specular * CalcSpecular(s.roughness, SNH, SH, N);\n #if CC_SPOTLIGHT\n float cosInner = max(dot(-cc_lightDir[i].xyz, SL), 0.01);\n float cosOuter = cc_lightSizeRangeAngle[i].z;\n float litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\n float litAngleOffset = -cosOuter * litAngleScale;\n att *= GetAngleAtt(SL, -cc_lightDir[i].xyz, litAngleScale, litAngleOffset);\n #endif\n finalColor += SNL * cc_lightColor[i].rgb * cc_lightColor[i].w * illum * att * (diffuseContrib + lspec);\n }\n finalColor = finalColor * s.occlusion;\n return vec4(finalColor, 0.0);\n }\n#else\n vec4 CCStandardShading (StandardSurface s) {\n vec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\n vec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\n vec3 N = normalize(s.normal);\n vec3 V = normalize(cc_cameraPos.xyz - s.position);\n float NV = max(abs(dot(N, V)), 0.001);\n specular = BRDFApprox(specular, s.roughness, NV);\n vec3 L = normalize(-cc_mainLitDir.xyz);\n vec3 H = normalize(L+V);\n float NH = max(dot(N, H), 0.0);\n float NL = max(dot(N, L), 0.001);\n vec3 finalColor = NL * cc_mainLitColor.rgb * cc_mainLitColor.w;\n #if USE_LIGHTMAP && !USE_BATCHING && !USE_INSTANCING\n vec4 lightmap = texture(cc_lightingMap, v_luv);\n finalColor = lightmap.a * lightmap.rgb + (1.0 - lightmap.a) * finalColor;\n #endif\n vec3 diffuseContrib = diffuse / 3.14159265359;\n vec3 specularContrib = specular * CalcSpecular(s.roughness, NH, H, N);\n finalColor *= (diffuseContrib + specularContrib);\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 vec4 envmap = fragTextureLod(cc_environment, R, s.roughness * cc_ambientGround.w);\n #if CC_USE_IBL == 2\n vec3 env = unpackRGBE(envmap);\n #else\n vec3 env = SRGBToLinear(envmap.rgb);\n #endif\n finalColor += env * cc_ambientSky.w * 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.albedo.a);\n }\n#endif\nvec3 ACESToneMap (vec3 color) {\n color = min(color, vec3(8.0));\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}\nvec4 CCFragOutput (vec4 color) {\n #if !CC_USE_HDR\n color.rgb = sqrt(ACESToneMap(color.rgb));\n #endif\n return color;\n}\nlayout(binding = 0) uniform Constants {\n vec4 tilingOffset;\n vec4 albedo;\n vec4 albedoScaleAndCutoff;\n vec4 pbrParams;\n vec4 emissive;\n vec4 emissiveScaleParam;\n};\nlayout(location = 1) in vec3 v_position;\nlayout(location = 3) in vec2 v_uv;\nlayout(location = 4) in vec2 v_uv1;\nlayout(location = 2) in vec3 v_normal;\n#if USE_VERTEX_COLOR\n layout(location = 0) in vec3 v_color;\n#endif\n#if USE_ALBEDO_MAP\n layout(binding = 31) uniform sampler2D albedoMap;\n#endif\n#if USE_NORMAL_MAP\n layout(location = 6) in vec3 v_tangent;\n layout(location = 7) in vec3 v_bitangent;\n layout(binding = 32) uniform sampler2D normalMap;\n#endif\n#if USE_PBR_MAP\n layout(binding = 33) uniform sampler2D pbrMap;\n#endif\n#if USE_METALLIC_ROUGHNESS_MAP\n layout(binding = 34) uniform sampler2D metallicRoughnessMap;\n#endif\n#if USE_OCCLUSION_MAP\n layout(binding = 35) uniform sampler2D occlusionMap;\n#endif\n#if USE_EMISSIVE_MAP\n layout(binding = 36) uniform sampler2D emissiveMap;\n#endif\n#if USE_LIGHTMAP\n layout(location = 8) in vec2 v_luv;\n layout(binding = 30) uniform sampler2D cc_lightingMap;\n#endif\n#if USE_ALPHA_TEST\n#endif\nlayout(location = 5) in float factor_fog;\nvoid surf (out StandardSurface s) {\n vec4 baseColor = albedo;\n #if USE_VERTEX_COLOR\n baseColor.rgb *= v_color;\n #endif\n #if USE_ALBEDO_MAP\n vec4 texColor = texture(albedoMap, ALBEDO_UV);\n texColor.rgb = SRGBToLinear(texColor.rgb);\n baseColor *= texColor;\n #endif\n s.albedo = baseColor;\n s.albedo.rgb *= albedoScaleAndCutoff.xyz;\n #if USE_ALPHA_TEST\n if (s.albedo.ALPHA_TEST_CHANNEL < albedoScaleAndCutoff.w) discard;\n #endif\n s.normal = v_normal;\n #if USE_NORMAL_MAP\n vec3 nmmp = texture(normalMap, NORMAL_UV).xyz - vec3(0.5);\n s.normal =\n (nmmp.x * pbrParams.w) * normalize(v_tangent) +\n (nmmp.y * pbrParams.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 vec4 res = texture(pbrMap, PBR_UV);\n pbr.x *= res.OCCLUSION_CHANNEL;\n pbr.y *= res.ROUGHNESS_CHANNEL;\n pbr.z *= res.METALLIC_CHANNEL;\n #endif\n #if USE_METALLIC_ROUGHNESS_MAP\n vec4 metallicRoughness = texture(metallicRoughnessMap, METALLIC_ROUGHNESS_UV);\n pbr.z *= metallicRoughness.METALLIC_CHANNEL;\n pbr.y *= metallicRoughness.ROUGHNESS_CHANNEL;\n #endif\n #if USE_OCCLUSION_MAP\n pbr.x *= texture(occlusionMap, OCCLUSION_UV).OCCLUSION_CHANNEL;\n #endif\n s.occlusion = clamp(pbr.x, 0.0, 0.96);\n s.roughness = clamp(pbr.y, 0.04, 1.0);\n s.metallic = pbr.z;\n s.emissive = emissive.rgb * emissiveScaleParam.xyz;\n #if USE_EMISSIVE_MAP\n s.emissive *= SRGBToLinear(texture(emissiveMap, EMISSIVE_UV).rgb);\n #endif\n}\nvec4 frag () {\n StandardSurface s; surf(s);\n vec4 color = CCStandardShading(s);\n color = vec4(mix(CC_FORWARD_ADD > 0 ? vec3(0.0) : cc_fogColor.rgb, color.rgb, factor_fog), color.a);\n return CCFragOutput(color);\n}\nlayout(location = 0) out vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }` }, "builtins": { "globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }], "samplers": [{ "name": "cc_environment", "defines": ["CC_USE_IBL"] }] }, @@ -370,8 +370,7 @@ export default [ { "name": "ROUGHNESS_CHANNEL", "type": "string", "options": ["g", "b", "r"] }, { "name": "METALLIC_CHANNEL", "type": "string", "options": ["b", "r", "g"] }, { "name": "USE_ALPHA_TEST", "type": "boolean" }, - { "name": "ALPHA_TEST_CHANNEL", "type": "string", "options": ["a", "r"] }, - { "name": "CC_FOWARD_ADD", "type": "number", "range": [0, 3] } + { "name": "ALPHA_TEST_CHANNEL", "type": "string", "options": ["a", "r"] } ], "blocks": [ {"name": "Constants", "defines": [], "binding": 0, "shaderStages": 17, "members": [ @@ -419,18 +418,18 @@ export default [ "shaders": [ { "name": "builtin-terrain|terrain-vs:vert|terrain-fs:frag", - "hash": 2658384185, + "hash": 298856331, "glsl3": { "vert": `\n precision mediump float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\nuniform CCLocal {\n highp mat4 cc_matWorld;\n highp mat4 cc_matWorldIT;\n highp vec4 cc_lightingMapUVParam;\n};\nfloat LinearFog(vec4 pos) {\n vec4 wPos = pos;\n float cam_dis = distance(cc_cameraPos, wPos);\n float fogStart = cc_fogBase.x;\n float fogEnd = cc_fogBase.y;\n return clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float fogDensity = cc_fogBase.z;\n float cam_dis = distance(cc_cameraPos, wPos) / fogAtten * 4.;\n float f = exp(-cam_dis * fogDensity);\n return f;\n}\nfloat ExpSquaredFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float fogDensity = cc_fogBase.z;\n float cam_dis = distance(cc_cameraPos, wPos) / fogAtten * 4.;\n float f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\n return f;\n}\nfloat LayeredFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float _FogTop = cc_fogAdd.x;\n float _FogRange = cc_fogAdd.y;\n vec3 camWorldProj = cc_cameraPos.xyz;\n camWorldProj.y = 0.;\n vec3 worldPosProj = wPos.xyz;\n worldPosProj.y = 0.;\n float fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\n float fDeltaY, fDensityIntegral;\n if (cc_cameraPos.y > _FogTop) {\n if (wPos.y < _FogTop) {\n fDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\n fDensityIntegral = fDeltaY * fDeltaY * 0.5;\n } else {\n fDeltaY = 0.;\n fDensityIntegral = 0.;\n }\n } else {\n if (wPos.y < _FogTop) {\n float fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\n float fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\n fDeltaY = abs(fDeltaA - fDeltaB);\n fDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n } else {\n fDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\n fDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n }\n }\n float fDensity;\n if (fDeltaY != 0.) {\n fDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n } else {\n fDensity = 0.;\n }\n float f = exp(-fDensity);\n return f;\n}\nfloat CC_TRANSFER_FOG(vec4 pos) {\n #if CC_USE_FOG == 1\n return LinearFog(pos);\n #elif CC_USE_FOG == 2\n return ExpFog(pos);\n #elif CC_USE_FOG == 3\n return ExpSquaredFog(pos);\n #elif CC_USE_FOG == 4\n return LayeredFog(pos);\n #endif\n return 1.;\n}\n in vec3 a_position;\n in vec3 a_normal;\n in vec2 a_texCoord;\n out vec2 uvw;\n out vec2 uv0;\n out vec2 uv1;\n out vec2 uv2;\n out vec2 uv3;\n out vec2 luv;\n out vec3 diffuse;\n out float factor_fog;\n uniform TexCoords {\n vec4 UVScale;\n vec4 lightMapUVParam;\n };\n vec4 vert () {\n vec3 worldPos;\n worldPos.x = cc_matWorld[3][0] + a_position.x;\n worldPos.y = cc_matWorld[3][1] + a_position.y;\n worldPos.z = cc_matWorld[3][2] + a_position.z;\n vec4 pos = vec4(worldPos, 1);\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 float fAmb = dot(a_normal, vec3(0.0, -1.0, 0.0)) * 0.5 + 0.5;\n vec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb) * cc_ambientSky.w;\n#if LIGHT_MAP == 0\n vec3 L = normalize(-cc_mainLitDir.xyz);\n vec3 N = a_normal;\n diffuse = ambDiff + vec3(dot(N, L)) * cc_mainLitColor.rgb;\n#else\n diffuse = ambDiff;\n luv = lightMapUVParam.xy + a_texCoord * lightMapUVParam.zw;\n#endif\n factor_fog = CC_TRANSFER_FOG(vec4(worldPos, 1));\n return pos;\n }\nvoid main() { gl_Position = vert(); }`, - "frag": `\nprecision mediump float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\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 in vec2 luv;\n uniform sampler2D weightMap;\n uniform sampler2D detailMap0;\n uniform sampler2D detailMap1;\n uniform sampler2D detailMap2;\n uniform sampler2D detailMap3;\n uniform sampler2D lightMap;\n in float factor_fog;\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 vec3 lighting = diffuse;\n #if LIGHT_MAP == 1\n lighting += texture(lightMap, luv).rgb;\n #endif\n color.rgb *= lighting;\n color = vec4(mix(cc_fogColor.rgb, CC_FORWARD_ADD > 0 ? vec3(0.0) : color.rgb, factor_fog), color.a);\n return CCFragOutput(color);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }` + "frag": `\nprecision mediump float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\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 in vec2 luv;\n uniform sampler2D weightMap;\n uniform sampler2D detailMap0;\n uniform sampler2D detailMap1;\n uniform sampler2D detailMap2;\n uniform sampler2D detailMap3;\n uniform sampler2D lightMap;\n in float factor_fog;\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 vec3 lighting = diffuse;\n #if LIGHT_MAP == 1\n lighting += texture(lightMap, luv).rgb;\n #endif\n color.rgb *= lighting;\n color = vec4(mix(CC_FORWARD_ADD > 0 ? vec3(0.0) : cc_fogColor.rgb, color.rgb, factor_fog), color.a);\n return CCFragOutput(color);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }` }, "glsl1": { "vert": `\n precision mediump float;\nuniform highp mat4 cc_matViewProj;\nuniform highp vec4 cc_cameraPos;\nuniform mediump vec4 cc_mainLitDir;\nuniform mediump vec4 cc_mainLitColor;\nuniform mediump vec4 cc_ambientSky;\nuniform mediump vec4 cc_ambientGround;\nuniform mediump vec4 cc_fogBase;\nuniform mediump vec4 cc_fogAdd;\nuniform highp mat4 cc_matWorld;\nfloat LinearFog(vec4 pos) {\n vec4 wPos = pos;\n float cam_dis = distance(cc_cameraPos, wPos);\n float fogStart = cc_fogBase.x;\n float fogEnd = cc_fogBase.y;\n return clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float fogDensity = cc_fogBase.z;\n float cam_dis = distance(cc_cameraPos, wPos) / fogAtten * 4.;\n float f = exp(-cam_dis * fogDensity);\n return f;\n}\nfloat ExpSquaredFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float fogDensity = cc_fogBase.z;\n float cam_dis = distance(cc_cameraPos, wPos) / fogAtten * 4.;\n float f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\n return f;\n}\nfloat LayeredFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float _FogTop = cc_fogAdd.x;\n float _FogRange = cc_fogAdd.y;\n vec3 camWorldProj = cc_cameraPos.xyz;\n camWorldProj.y = 0.;\n vec3 worldPosProj = wPos.xyz;\n worldPosProj.y = 0.;\n float fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\n float fDeltaY, fDensityIntegral;\n if (cc_cameraPos.y > _FogTop) {\n if (wPos.y < _FogTop) {\n fDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\n fDensityIntegral = fDeltaY * fDeltaY * 0.5;\n } else {\n fDeltaY = 0.;\n fDensityIntegral = 0.;\n }\n } else {\n if (wPos.y < _FogTop) {\n float fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\n float fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\n fDeltaY = abs(fDeltaA - fDeltaB);\n fDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n } else {\n fDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\n fDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n }\n }\n float fDensity;\n if (fDeltaY != 0.) {\n fDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n } else {\n fDensity = 0.;\n }\n float f = exp(-fDensity);\n return f;\n}\nfloat CC_TRANSFER_FOG(vec4 pos) {\n #if CC_USE_FOG == 1\n return LinearFog(pos);\n #elif CC_USE_FOG == 2\n return ExpFog(pos);\n #elif CC_USE_FOG == 3\n return ExpSquaredFog(pos);\n #elif CC_USE_FOG == 4\n return LayeredFog(pos);\n #endif\n return 1.;\n}\n attribute vec3 a_position;\n attribute vec3 a_normal;\n attribute vec2 a_texCoord;\n varying vec2 uvw;\n varying vec2 uv0;\n varying vec2 uv1;\n varying vec2 uv2;\n varying vec2 uv3;\n varying vec2 luv;\n varying vec3 diffuse;\n varying float factor_fog;\n uniform vec4 UVScale;\nuniform vec4 lightMapUVParam;\n vec4 vert () {\n vec3 worldPos;\n worldPos.x = cc_matWorld[3][0] + a_position.x;\n worldPos.y = cc_matWorld[3][1] + a_position.y;\n worldPos.z = cc_matWorld[3][2] + a_position.z;\n vec4 pos = vec4(worldPos, 1);\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 float fAmb = dot(a_normal, vec3(0.0, -1.0, 0.0)) * 0.5 + 0.5;\n vec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb) * cc_ambientSky.w;\n#if LIGHT_MAP == 0\n vec3 L = normalize(-cc_mainLitDir.xyz);\n vec3 N = a_normal;\n diffuse = ambDiff + vec3(dot(N, L)) * cc_mainLitColor.rgb;\n#else\n diffuse = ambDiff;\n luv = lightMapUVParam.xy + a_texCoord * lightMapUVParam.zw;\n#endif\n factor_fog = CC_TRANSFER_FOG(vec4(worldPos, 1));\n return pos;\n }\nvoid main() { gl_Position = vert(); }`, - "frag": `\nprecision mediump float;\nuniform mediump vec4 cc_exposure;\nuniform mediump vec4 cc_fogColor;\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\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 varying vec2 luv;\n uniform sampler2D weightMap;\n uniform sampler2D detailMap0;\n uniform sampler2D detailMap1;\n uniform sampler2D detailMap2;\n uniform sampler2D detailMap3;\n uniform sampler2D lightMap;\n varying float factor_fog;\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 vec3 lighting = diffuse;\n #if LIGHT_MAP == 1\n lighting += texture2D(lightMap, luv).rgb;\n #endif\n color.rgb *= lighting;\n color = vec4(mix(cc_fogColor.rgb, CC_FORWARD_ADD > 0 ? vec3(0.0) : color.rgb, factor_fog), color.a);\n return CCFragOutput(color);\n}\nvoid main() { gl_FragColor = frag(); }` + "frag": `\nprecision mediump float;\nuniform mediump vec4 cc_exposure;\nuniform mediump vec4 cc_fogColor;\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\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 varying vec2 luv;\n uniform sampler2D weightMap;\n uniform sampler2D detailMap0;\n uniform sampler2D detailMap1;\n uniform sampler2D detailMap2;\n uniform sampler2D detailMap3;\n uniform sampler2D lightMap;\n varying float factor_fog;\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 vec3 lighting = diffuse;\n #if LIGHT_MAP == 1\n lighting += texture2D(lightMap, luv).rgb;\n #endif\n color.rgb *= lighting;\n color = vec4(mix(CC_FORWARD_ADD > 0 ? vec3(0.0) : cc_fogColor.rgb, color.rgb, factor_fog), color.a);\n return CCFragOutput(color);\n}\nvoid main() { gl_FragColor = frag(); }` }, "glsl4": { "vert": `\n precision mediump float;\nlayout(binding = 23) uniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\nlayout(binding = 21) uniform CCLocal {\n highp mat4 cc_matWorld;\n highp mat4 cc_matWorldIT;\n highp vec4 cc_lightingMapUVParam;\n};\nfloat LinearFog(vec4 pos) {\n vec4 wPos = pos;\n float cam_dis = distance(cc_cameraPos, wPos);\n float fogStart = cc_fogBase.x;\n float fogEnd = cc_fogBase.y;\n return clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float fogDensity = cc_fogBase.z;\n float cam_dis = distance(cc_cameraPos, wPos) / fogAtten * 4.;\n float f = exp(-cam_dis * fogDensity);\n return f;\n}\nfloat ExpSquaredFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float fogDensity = cc_fogBase.z;\n float cam_dis = distance(cc_cameraPos, wPos) / fogAtten * 4.;\n float f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\n return f;\n}\nfloat LayeredFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float _FogTop = cc_fogAdd.x;\n float _FogRange = cc_fogAdd.y;\n vec3 camWorldProj = cc_cameraPos.xyz;\n camWorldProj.y = 0.;\n vec3 worldPosProj = wPos.xyz;\n worldPosProj.y = 0.;\n float fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\n float fDeltaY, fDensityIntegral;\n if (cc_cameraPos.y > _FogTop) {\n if (wPos.y < _FogTop) {\n fDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\n fDensityIntegral = fDeltaY * fDeltaY * 0.5;\n } else {\n fDeltaY = 0.;\n fDensityIntegral = 0.;\n }\n } else {\n if (wPos.y < _FogTop) {\n float fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\n float fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\n fDeltaY = abs(fDeltaA - fDeltaB);\n fDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n } else {\n fDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\n fDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n }\n }\n float fDensity;\n if (fDeltaY != 0.) {\n fDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n } else {\n fDensity = 0.;\n }\n float f = exp(-fDensity);\n return f;\n}\nfloat CC_TRANSFER_FOG(vec4 pos) {\n #if CC_USE_FOG == 1\n return LinearFog(pos);\n #elif CC_USE_FOG == 2\n return ExpFog(pos);\n #elif CC_USE_FOG == 3\n return ExpSquaredFog(pos);\n #elif CC_USE_FOG == 4\n return LayeredFog(pos);\n #endif\n return 1.;\n}\n layout(location = 0) in vec3 a_position;\n layout(location = 1) in vec3 a_normal;\n layout(location = 2) in vec2 a_texCoord;\n layout(location = 0) out vec2 uvw;\n layout(location = 1) out vec2 uv0;\n layout(location = 2) out vec2 uv1;\n layout(location = 3) out vec2 uv2;\n layout(location = 4) out vec2 uv3;\n layout(location = 5) out vec2 luv;\n layout(location = 6) out vec3 diffuse;\n layout(location = 7) out float factor_fog;\n layout(binding = 0) uniform TexCoords {\n vec4 UVScale;\n vec4 lightMapUVParam;\n };\n vec4 vert () {\n vec3 worldPos;\n worldPos.x = cc_matWorld[3][0] + a_position.x;\n worldPos.y = cc_matWorld[3][1] + a_position.y;\n worldPos.z = cc_matWorld[3][2] + a_position.z;\n vec4 pos = vec4(worldPos, 1);\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 float fAmb = dot(a_normal, vec3(0.0, -1.0, 0.0)) * 0.5 + 0.5;\n vec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb) * cc_ambientSky.w;\n#if LIGHT_MAP == 0\n vec3 L = normalize(-cc_mainLitDir.xyz);\n vec3 N = a_normal;\n diffuse = ambDiff + vec3(dot(N, L)) * cc_mainLitColor.rgb;\n#else\n diffuse = ambDiff;\n luv = lightMapUVParam.xy + a_texCoord * lightMapUVParam.zw;\n#endif\n factor_fog = CC_TRANSFER_FOG(vec4(worldPos, 1));\n return pos;\n }\nvoid main() { gl_Position = vert(); }`, - "frag": `\nprecision mediump float;\nlayout(binding = 23) uniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\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 layout(location = 0) in vec2 uvw;\n layout(location = 1) in vec2 uv0;\n layout(location = 2) in vec2 uv1;\n layout(location = 3) in vec2 uv2;\n layout(location = 4) in vec2 uv3;\n layout(location = 6) in vec3 diffuse;\n layout(location = 5) in vec2 luv;\n layout(binding = 31) uniform sampler2D weightMap;\n layout(binding = 32) uniform sampler2D detailMap0;\n layout(binding = 33) uniform sampler2D detailMap1;\n layout(binding = 34) uniform sampler2D detailMap2;\n layout(binding = 35) uniform sampler2D detailMap3;\n layout(binding = 36) uniform sampler2D lightMap;\n layout(location = 7) in float factor_fog;\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 vec3 lighting = diffuse;\n #if LIGHT_MAP == 1\n lighting += texture(lightMap, luv).rgb;\n #endif\n color.rgb *= lighting;\n color = vec4(mix(cc_fogColor.rgb, CC_FORWARD_ADD > 0 ? vec3(0.0) : color.rgb, factor_fog), color.a);\n return CCFragOutput(color);\n}\nlayout(location = 0) out vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }` + "frag": `\nprecision mediump float;\nlayout(binding = 23) uniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\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 layout(location = 0) in vec2 uvw;\n layout(location = 1) in vec2 uv0;\n layout(location = 2) in vec2 uv1;\n layout(location = 3) in vec2 uv2;\n layout(location = 4) in vec2 uv3;\n layout(location = 6) in vec3 diffuse;\n layout(location = 5) in vec2 luv;\n layout(binding = 31) uniform sampler2D weightMap;\n layout(binding = 32) uniform sampler2D detailMap0;\n layout(binding = 33) uniform sampler2D detailMap1;\n layout(binding = 34) uniform sampler2D detailMap2;\n layout(binding = 35) uniform sampler2D detailMap3;\n layout(binding = 36) uniform sampler2D lightMap;\n layout(location = 7) in float factor_fog;\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 vec3 lighting = diffuse;\n #if LIGHT_MAP == 1\n lighting += texture(lightMap, luv).rgb;\n #endif\n color.rgb *= lighting;\n color = vec4(mix(CC_FORWARD_ADD > 0 ? vec3(0.0) : cc_fogColor.rgb, color.rgb, factor_fog), color.a);\n return CCFragOutput(color);\n}\nlayout(location = 0) out vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }` }, "builtins": { "globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }], "samplers": [] }, @@ -474,18 +473,18 @@ export default [ "shaders": [ { "name": "builtin-unlit|unlit-vs:vert|unlit-fs:frag", - "hash": 3926038961, + "hash": 136515770, "glsl3": { "vert": `\nprecision highp float;\nstruct StandardVertInput {\n highp vec4 position;\n vec3 normal;\n vec4 tangent;\n};\nin vec3 a_position;\nin vec3 a_normal;\nin vec2 a_texCoord;\nin vec4 a_tangent;\n#if CC_USE_MORPH\n in float a_vertexId;\n int getVertexId() {\n return int(a_vertexId);\n }\nuniform CCMorph {\n vec4 cc_displacementWeights[15];\n vec4 cc_displacementTextureInfo;\n};\n vec4 fetchFlatPixel(sampler2D tex, int pixelIndex) {\n float pixelIndexF = float(pixelIndex);\n vec2 textureResolution = vec2(float(cc_displacementTextureInfo.x), float(cc_displacementTextureInfo.y));\n float pixelX = mod(pixelIndexF, textureResolution.x);\n float pixelY = floor(pixelIndexF / textureResolution.x);\n vec2 uv = (vec2(pixelX, pixelY) + .5) / textureResolution;\n return texture(tex, uv);\n }\nfloat getDisplacementWeight(int index) {\n float m = mod(float(index), 4.0);\n if (m < 1.0) {\n return cc_displacementWeights[index / 4].x;\n } else if (m < 2.0) {\n return cc_displacementWeights[index / 4].y;\n } else if (m < 3.0) {\n return cc_displacementWeights[index / 4].z;\n } else {\n return cc_displacementWeights[index / 4].w;\n }\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\n return fetchFlatPixel(tex, vertexIndex).rgb;\n#else\n vec3 result = vec3(0, 0, 0);\n for (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\n int dataPixelStart = int(fetchFlatPixel(tex, iTarget).r);\n result += (fetchFlatPixel(tex, dataPixelStart + vertexIndex).rgb * getDisplacementWeight(iTarget));\n }\n return result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\n uniform sampler2D cc_PositionDisplacements;\n vec3 getPositionDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n uniform sampler2D cc_NormalDisplacements;\n vec3 getNormalDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n uniform sampler2D cc_TangentDisplacements;\n vec3 getTangentDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n }\n#endif\nvoid applyMorph (inout StandardVertInput attr) {\n int vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\n attr.position.xyz = attr.position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n attr.normal.xyz = attr.normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n attr.tangent.xyz = attr.tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\n position.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\nin vec4 a_joints;\nin vec4 a_weights;\n#if CC_USE_BAKED_ANIMATION\n #if USE_INSTANCING\n in highp vec4 a_jointAnimInfo;\n #endif\n uniform CCSkinningTexture {\n highp vec4 cc_jointTextureInfo;\n };\n uniform CCSkinningAnimation {\n highp vec4 cc_jointAnimInfo;\n };\n uniform sampler2D cc_jointTexture;\n #if !CC_SUPPORT_FLOAT_TEXTURE\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#else\n uniform CCSkinning {\n highp vec4 cc_joints[30 * 3];\n };\n#endif\n#if CC_USE_BAKED_ANIMATION\n #if CC_SUPPORT_FLOAT_TEXTURE\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 3.0 * (a_jointAnimInfo.x * a_jointAnimInfo.y + i) + a_jointAnimInfo.z;\n #else\n highp float j = 3.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = texture(cc_jointTexture, vec2((x + 0.5) * invSize, y));\n vec4 v2 = texture(cc_jointTexture, vec2((x + 1.5) * invSize, y));\n vec4 v3 = texture(cc_jointTexture, vec2((x + 2.5) * invSize, y));\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #else\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 12.0 * (a_jointAnimInfo.x * a_jointAnimInfo.y + i) + a_jointAnimInfo.z;\n #else\n highp float j = 12.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = vec4(\n decode32(texture(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n );\n vec4 v2 = vec4(\n decode32(texture(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n );\n vec4 v3 = vec4(\n decode32(texture(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n );\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #endif\n#else\n mat4 getJointMatrix (float i) {\n int idx = int(i);\n vec4 v1 = cc_joints[idx * 3];\n vec4 v2 = cc_joints[idx * 3 + 1];\n vec4 v3 = cc_joints[idx * 3 + 2];\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n#endif\nmat4 skinMatrix () {\n return getJointMatrix(a_joints.x) * a_weights.x\n + getJointMatrix(a_joints.y) * a_weights.y;\n + getJointMatrix(a_joints.z) * a_weights.z;\n + getJointMatrix(a_joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\n mat4 m = skinMatrix();\n position = m * position;\n}\nvoid CCSkin (inout StandardVertInput attr) {\n mat4 m = skinMatrix();\n attr.position = m * attr.position;\n attr.normal = (m * vec4(attr.normal, 0.0)).xyz;\n attr.tangent.xyz = (m * vec4(attr.tangent.xyz, 0.0)).xyz;\n}\n#endif\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\n#if USE_INSTANCING\n in vec4 a_matWorld0;\n in vec4 a_matWorld1;\n in vec4 a_matWorld2;\n#elif USE_BATCHING\n in float a_dyn_batch_id;\n uniform CCLocalBatched {\n highp mat4 cc_matWorlds[10];\n };\n#else\nuniform CCLocal {\n highp mat4 cc_matWorld;\n highp mat4 cc_matWorldIT;\n highp vec4 cc_lightingMapUVParam;\n};\n#endif\nfloat LinearFog(vec4 pos) {\n vec4 wPos = pos;\n float cam_dis = distance(cc_cameraPos, wPos);\n float fogStart = cc_fogBase.x;\n float fogEnd = cc_fogBase.y;\n return clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float fogDensity = cc_fogBase.z;\n float cam_dis = distance(cc_cameraPos, wPos) / fogAtten * 4.;\n float f = exp(-cam_dis * fogDensity);\n return f;\n}\nfloat ExpSquaredFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float fogDensity = cc_fogBase.z;\n float cam_dis = distance(cc_cameraPos, wPos) / fogAtten * 4.;\n float f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\n return f;\n}\nfloat LayeredFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float _FogTop = cc_fogAdd.x;\n float _FogRange = cc_fogAdd.y;\n vec3 camWorldProj = cc_cameraPos.xyz;\n camWorldProj.y = 0.;\n vec3 worldPosProj = wPos.xyz;\n worldPosProj.y = 0.;\n float fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\n float fDeltaY, fDensityIntegral;\n if (cc_cameraPos.y > _FogTop) {\n if (wPos.y < _FogTop) {\n fDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\n fDensityIntegral = fDeltaY * fDeltaY * 0.5;\n } else {\n fDeltaY = 0.;\n fDensityIntegral = 0.;\n }\n } else {\n if (wPos.y < _FogTop) {\n float fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\n float fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\n fDeltaY = abs(fDeltaA - fDeltaB);\n fDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n } else {\n fDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\n fDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n }\n }\n float fDensity;\n if (fDeltaY != 0.) {\n fDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n } else {\n fDensity = 0.;\n }\n float f = exp(-fDensity);\n return f;\n}\nfloat CC_TRANSFER_FOG(vec4 pos) {\n #if CC_USE_FOG == 1\n return LinearFog(pos);\n #elif CC_USE_FOG == 2\n return ExpFog(pos);\n #elif CC_USE_FOG == 3\n return ExpSquaredFog(pos);\n #elif CC_USE_FOG == 4\n return LayeredFog(pos);\n #endif\n return 1.;\n}\n#if USE_VERTEX_COLOR\n in lowp vec4 a_color;\n out lowp vec4 v_color;\n#endif\n#if USE_TEXTURE\n out vec2 v_uv;\n uniform TexCoords {\n vec4 tilingOffset;\n };\n#endif\nout float factor_fog;\nvec4 vert () {\n vec4 position;\n position = vec4(a_position, 1.0);\n #if CC_USE_MORPH\n applyMorph(position);\n #endif\n #if CC_USE_SKINNING\n CCSkin(position);\n #endif\n mat4 matWorld;\n #if USE_INSTANCING\n matWorld = mat4(\n vec4(a_matWorld0.xyz, 0.0),\n vec4(a_matWorld1.xyz, 0.0),\n vec4(a_matWorld2.xyz, 0.0),\n vec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)\n );\n #elif USE_BATCHING\n matWorld = cc_matWorlds[int(a_dyn_batch_id)];\n #else\n matWorld = cc_matWorld;\n #endif\n #if USE_TEXTURE\n v_uv = a_texCoord;\n #if FLIP_UV\n v_uv.y = 1.0 - v_uv.y;\n #endif\n v_uv = v_uv * tilingOffset.xy + tilingOffset.zw;\n #endif\n #if USE_VERTEX_COLOR\n v_color = a_color;\n #endif\n factor_fog = CC_TRANSFER_FOG(matWorld * position);\n return cc_matProj * (cc_matView * matWorld) * position;\n}\nvoid main() { gl_Position = vert(); }`, - "frag": `\nprecision highp float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\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_ALPHA_TEST\n#endif\n#if USE_TEXTURE\n in vec2 v_uv;\n uniform sampler2D mainTexture;\n#endif\nuniform Constant {\n vec4 mainColor;\n vec4 colorScaleAndCutoff;\n};\n#if USE_VERTEX_COLOR\n in lowp vec4 v_color;\n#endif\nin float factor_fog;\nvec4 frag () {\n vec4 o = mainColor;\n o.rgb *= colorScaleAndCutoff.xyz;\n #if USE_VERTEX_COLOR\n o *= v_color;\n #endif\n #if USE_TEXTURE\n o *= texture(mainTexture, v_uv);\n #endif\n #if USE_ALPHA_TEST\n if (o.ALPHA_TEST_CHANNEL < colorScaleAndCutoff.w) discard;\n #endif\n o = vec4(mix(cc_fogColor.rgb, CC_FORWARD_ADD > 0 ? vec3(0.0) : o.rgb, factor_fog), o.a);\n return CCFragOutput(o);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }` + "frag": `\nprecision highp float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\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_ALPHA_TEST\n#endif\n#if USE_TEXTURE\n in vec2 v_uv;\n uniform sampler2D mainTexture;\n#endif\nuniform Constant {\n vec4 mainColor;\n vec4 colorScaleAndCutoff;\n};\n#if USE_VERTEX_COLOR\n in lowp vec4 v_color;\n#endif\nin float factor_fog;\nvec4 frag () {\n vec4 o = mainColor;\n o.rgb *= colorScaleAndCutoff.xyz;\n #if USE_VERTEX_COLOR\n o *= v_color;\n #endif\n #if USE_TEXTURE\n o *= texture(mainTexture, v_uv);\n #endif\n #if USE_ALPHA_TEST\n if (o.ALPHA_TEST_CHANNEL < colorScaleAndCutoff.w) discard;\n #endif\n o = vec4(mix(CC_FORWARD_ADD > 0 ? vec3(0.0) : cc_fogColor.rgb, o.rgb, factor_fog), o.a);\n return CCFragOutput(o);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }` }, "glsl1": { "vert": `\nprecision highp float;\nstruct StandardVertInput {\n highp vec4 position;\n vec3 normal;\n vec4 tangent;\n};\nattribute vec3 a_position;\nattribute vec3 a_normal;\nattribute vec2 a_texCoord;\nattribute vec4 a_tangent;\n#if CC_USE_MORPH\n attribute float a_vertexId;\n int getVertexId() {\n return int(a_vertexId);\n }\nuniform vec4 cc_displacementWeights[15];\nuniform vec4 cc_displacementTextureInfo;\n vec4 fetchFlatPixel(sampler2D tex, int pixelIndex) {\n float pixelIndexF = float(pixelIndex);\n vec2 textureResolution = vec2(float(cc_displacementTextureInfo.x), float(cc_displacementTextureInfo.y));\n float pixelX = mod(pixelIndexF, textureResolution.x);\n float pixelY = floor(pixelIndexF / textureResolution.x);\n vec2 uv = (vec2(pixelX, pixelY) + .5) / textureResolution;\n return texture2D(tex, uv);\n }\nfloat getDisplacementWeight(int index) {\n float m = mod(float(index), 4.0);\n if (m < 1.0) {\n return cc_displacementWeights[index / 4].x;\n } else if (m < 2.0) {\n return cc_displacementWeights[index / 4].y;\n } else if (m < 3.0) {\n return cc_displacementWeights[index / 4].z;\n } else {\n return cc_displacementWeights[index / 4].w;\n }\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\n return fetchFlatPixel(tex, vertexIndex).rgb;\n#else\n vec3 result = vec3(0, 0, 0);\n for (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\n int dataPixelStart = int(fetchFlatPixel(tex, iTarget).r);\n result += (fetchFlatPixel(tex, dataPixelStart + vertexIndex).rgb * getDisplacementWeight(iTarget));\n }\n return result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\n uniform sampler2D cc_PositionDisplacements;\n vec3 getPositionDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n uniform sampler2D cc_NormalDisplacements;\n vec3 getNormalDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n uniform sampler2D cc_TangentDisplacements;\n vec3 getTangentDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n }\n#endif\nvoid applyMorph (inout StandardVertInput attr) {\n int vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\n attr.position.xyz = attr.position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n attr.normal.xyz = attr.normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n attr.tangent.xyz = attr.tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\n position.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\nattribute vec4 a_joints;\nattribute vec4 a_weights;\n#if CC_USE_BAKED_ANIMATION\n #if USE_INSTANCING\n attribute highp vec4 a_jointAnimInfo;\n #endif\n uniform highp vec4 cc_jointTextureInfo;\n uniform highp vec4 cc_jointAnimInfo;\n uniform sampler2D cc_jointTexture;\n #if !CC_SUPPORT_FLOAT_TEXTURE\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#else\n uniform highp vec4 cc_joints[90];\n#endif\n#if CC_USE_BAKED_ANIMATION\n #if CC_SUPPORT_FLOAT_TEXTURE\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 3.0 * (a_jointAnimInfo.x * a_jointAnimInfo.y + i) + a_jointAnimInfo.z;\n #else\n highp float j = 3.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y));\n vec4 v2 = texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y));\n vec4 v3 = texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y));\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #else\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 12.0 * (a_jointAnimInfo.x * a_jointAnimInfo.y + i) + a_jointAnimInfo.z;\n #else\n highp float j = 12.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = vec4(\n decode32(texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n );\n vec4 v2 = vec4(\n decode32(texture2D(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n );\n vec4 v3 = vec4(\n decode32(texture2D(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n );\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #endif\n#else\n mat4 getJointMatrix (float i) {\n int idx = int(i);\n vec4 v1 = cc_joints[idx * 3];\n vec4 v2 = cc_joints[idx * 3 + 1];\n vec4 v3 = cc_joints[idx * 3 + 2];\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n#endif\nmat4 skinMatrix () {\n return getJointMatrix(a_joints.x) * a_weights.x\n + getJointMatrix(a_joints.y) * a_weights.y;\n + getJointMatrix(a_joints.z) * a_weights.z;\n + getJointMatrix(a_joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\n mat4 m = skinMatrix();\n position = m * position;\n}\nvoid CCSkin (inout StandardVertInput attr) {\n mat4 m = skinMatrix();\n attr.position = m * attr.position;\n attr.normal = (m * vec4(attr.normal, 0.0)).xyz;\n attr.tangent.xyz = (m * vec4(attr.tangent.xyz, 0.0)).xyz;\n}\n#endif\nuniform highp mat4 cc_matView;\nuniform highp mat4 cc_matProj;\nuniform highp vec4 cc_cameraPos;\nuniform mediump vec4 cc_fogBase;\nuniform mediump vec4 cc_fogAdd;\n#if USE_INSTANCING\n attribute vec4 a_matWorld0;\n attribute vec4 a_matWorld1;\n attribute vec4 a_matWorld2;\n#elif USE_BATCHING\n attribute float a_dyn_batch_id;\n uniform highp mat4 cc_matWorlds[10];\n#else\nuniform highp mat4 cc_matWorld;\n#endif\nfloat LinearFog(vec4 pos) {\n vec4 wPos = pos;\n float cam_dis = distance(cc_cameraPos, wPos);\n float fogStart = cc_fogBase.x;\n float fogEnd = cc_fogBase.y;\n return clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float fogDensity = cc_fogBase.z;\n float cam_dis = distance(cc_cameraPos, wPos) / fogAtten * 4.;\n float f = exp(-cam_dis * fogDensity);\n return f;\n}\nfloat ExpSquaredFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float fogDensity = cc_fogBase.z;\n float cam_dis = distance(cc_cameraPos, wPos) / fogAtten * 4.;\n float f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\n return f;\n}\nfloat LayeredFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float _FogTop = cc_fogAdd.x;\n float _FogRange = cc_fogAdd.y;\n vec3 camWorldProj = cc_cameraPos.xyz;\n camWorldProj.y = 0.;\n vec3 worldPosProj = wPos.xyz;\n worldPosProj.y = 0.;\n float fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\n float fDeltaY, fDensityIntegral;\n if (cc_cameraPos.y > _FogTop) {\n if (wPos.y < _FogTop) {\n fDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\n fDensityIntegral = fDeltaY * fDeltaY * 0.5;\n } else {\n fDeltaY = 0.;\n fDensityIntegral = 0.;\n }\n } else {\n if (wPos.y < _FogTop) {\n float fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\n float fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\n fDeltaY = abs(fDeltaA - fDeltaB);\n fDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n } else {\n fDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\n fDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n }\n }\n float fDensity;\n if (fDeltaY != 0.) {\n fDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n } else {\n fDensity = 0.;\n }\n float f = exp(-fDensity);\n return f;\n}\nfloat CC_TRANSFER_FOG(vec4 pos) {\n #if CC_USE_FOG == 1\n return LinearFog(pos);\n #elif CC_USE_FOG == 2\n return ExpFog(pos);\n #elif CC_USE_FOG == 3\n return ExpSquaredFog(pos);\n #elif CC_USE_FOG == 4\n return LayeredFog(pos);\n #endif\n return 1.;\n}\n#if USE_VERTEX_COLOR\n attribute lowp vec4 a_color;\n varying lowp vec4 v_color;\n#endif\n#if USE_TEXTURE\n varying vec2 v_uv;\n uniform vec4 tilingOffset;\n#endif\nvarying float factor_fog;\nvec4 vert () {\n vec4 position;\n position = vec4(a_position, 1.0);\n #if CC_USE_MORPH\n applyMorph(position);\n #endif\n #if CC_USE_SKINNING\n CCSkin(position);\n #endif\n mat4 matWorld;\n #if USE_INSTANCING\n matWorld = mat4(\n vec4(a_matWorld0.xyz, 0.0),\n vec4(a_matWorld1.xyz, 0.0),\n vec4(a_matWorld2.xyz, 0.0),\n vec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)\n );\n #elif USE_BATCHING\n matWorld = cc_matWorlds[int(a_dyn_batch_id)];\n #else\n matWorld = cc_matWorld;\n #endif\n #if USE_TEXTURE\n v_uv = a_texCoord;\n #if FLIP_UV\n v_uv.y = 1.0 - v_uv.y;\n #endif\n v_uv = v_uv * tilingOffset.xy + tilingOffset.zw;\n #endif\n #if USE_VERTEX_COLOR\n v_color = a_color;\n #endif\n factor_fog = CC_TRANSFER_FOG(matWorld * position);\n return cc_matProj * (cc_matView * matWorld) * position;\n}\nvoid main() { gl_Position = vert(); }`, - "frag": `\nprecision highp float;\nuniform mediump vec4 cc_exposure;\nuniform mediump vec4 cc_fogColor;\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\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_ALPHA_TEST\n#endif\n#if USE_TEXTURE\n varying vec2 v_uv;\n uniform sampler2D mainTexture;\n#endif\nuniform vec4 mainColor;\nuniform vec4 colorScaleAndCutoff;\n#if USE_VERTEX_COLOR\n varying lowp vec4 v_color;\n#endif\nvarying float factor_fog;\nvec4 frag () {\n vec4 o = mainColor;\n o.rgb *= colorScaleAndCutoff.xyz;\n #if USE_VERTEX_COLOR\n o *= v_color;\n #endif\n #if USE_TEXTURE\n o *= texture2D(mainTexture, v_uv);\n #endif\n #if USE_ALPHA_TEST\n if (o.ALPHA_TEST_CHANNEL < colorScaleAndCutoff.w) discard;\n #endif\n o = vec4(mix(cc_fogColor.rgb, CC_FORWARD_ADD > 0 ? vec3(0.0) : o.rgb, factor_fog), o.a);\n return CCFragOutput(o);\n}\nvoid main() { gl_FragColor = frag(); }` + "frag": `\nprecision highp float;\nuniform mediump vec4 cc_exposure;\nuniform mediump vec4 cc_fogColor;\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\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_ALPHA_TEST\n#endif\n#if USE_TEXTURE\n varying vec2 v_uv;\n uniform sampler2D mainTexture;\n#endif\nuniform vec4 mainColor;\nuniform vec4 colorScaleAndCutoff;\n#if USE_VERTEX_COLOR\n varying lowp vec4 v_color;\n#endif\nvarying float factor_fog;\nvec4 frag () {\n vec4 o = mainColor;\n o.rgb *= colorScaleAndCutoff.xyz;\n #if USE_VERTEX_COLOR\n o *= v_color;\n #endif\n #if USE_TEXTURE\n o *= texture2D(mainTexture, v_uv);\n #endif\n #if USE_ALPHA_TEST\n if (o.ALPHA_TEST_CHANNEL < colorScaleAndCutoff.w) discard;\n #endif\n o = vec4(mix(CC_FORWARD_ADD > 0 ? vec3(0.0) : cc_fogColor.rgb, o.rgb, factor_fog), o.a);\n return CCFragOutput(o);\n}\nvoid main() { gl_FragColor = frag(); }` }, "glsl4": { "vert": `\n#ifdef GL_EXT_shader_explicit_arithmetic_types_int16\n#extension GL_EXT_shader_explicit_arithmetic_types_int16: enable\n#endif\nprecision highp float;\nstruct StandardVertInput {\n highp vec4 position;\n vec3 normal;\n vec4 tangent;\n};\nlayout(location = 0) in vec3 a_position;\nlayout(location = 1) in vec3 a_normal;\nlayout(location = 2) in vec2 a_texCoord;\nlayout(location = 3) in vec4 a_tangent;\n#if CC_USE_MORPH\n layout(location = 6) in float a_vertexId;\n int getVertexId() {\n return int(a_vertexId);\n }\nlayout(binding = 16) uniform CCMorph {\n vec4 cc_displacementWeights[15];\n vec4 cc_displacementTextureInfo;\n};\n vec4 fetchFlatPixel(sampler2D tex, int pixelIndex) {\n float pixelIndexF = float(pixelIndex);\n vec2 textureResolution = vec2(float(cc_displacementTextureInfo.x), float(cc_displacementTextureInfo.y));\n float pixelX = mod(pixelIndexF, textureResolution.x);\n float pixelY = floor(pixelIndexF / textureResolution.x);\n vec2 uv = (vec2(pixelX, pixelY) + .5) / textureResolution;\n return texture(tex, uv);\n }\nfloat getDisplacementWeight(int index) {\n float m = mod(float(index), 4.0);\n if (m < 1.0) {\n return cc_displacementWeights[index / 4].x;\n } else if (m < 2.0) {\n return cc_displacementWeights[index / 4].y;\n } else if (m < 3.0) {\n return cc_displacementWeights[index / 4].z;\n } else {\n return cc_displacementWeights[index / 4].w;\n }\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\n return fetchFlatPixel(tex, vertexIndex).rgb;\n#else\n vec3 result = vec3(0, 0, 0);\n for (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\n int dataPixelStart = int(fetchFlatPixel(tex, iTarget).r);\n result += (fetchFlatPixel(tex, dataPixelStart + vertexIndex).rgb * getDisplacementWeight(iTarget));\n }\n return result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\n layout(binding = 27) uniform sampler2D cc_PositionDisplacements;\n vec3 getPositionDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n layout(binding = 28) uniform sampler2D cc_NormalDisplacements;\n vec3 getNormalDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n layout(binding = 29) uniform sampler2D cc_TangentDisplacements;\n vec3 getTangentDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n }\n#endif\nvoid applyMorph (inout StandardVertInput attr) {\n int vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\n attr.position.xyz = attr.position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n attr.normal.xyz = attr.normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n attr.tangent.xyz = attr.tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\n position.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\nlayout(location = 4) in u16vec4 a_joints;\nlayout(location = 5) in vec4 a_weights;\n#if CC_USE_BAKED_ANIMATION\n #if USE_INSTANCING\n layout(location = 7) in highp vec4 a_jointAnimInfo;\n #endif\n layout(binding = 18) uniform CCSkinningTexture {\n highp vec4 cc_jointTextureInfo;\n };\n layout(binding = 19) uniform CCSkinningAnimation {\n highp vec4 cc_jointAnimInfo;\n };\n layout(binding = 25) uniform sampler2D cc_jointTexture;\n #if !CC_SUPPORT_FLOAT_TEXTURE\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#else\n layout(binding = 18) uniform CCSkinning {\n highp vec4 cc_joints[30 * 3];\n };\n#endif\n#if CC_USE_BAKED_ANIMATION\n #if CC_SUPPORT_FLOAT_TEXTURE\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 3.0 * (a_jointAnimInfo.x * a_jointAnimInfo.y + i) + a_jointAnimInfo.z;\n #else\n highp float j = 3.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = texture(cc_jointTexture, vec2((x + 0.5) * invSize, y));\n vec4 v2 = texture(cc_jointTexture, vec2((x + 1.5) * invSize, y));\n vec4 v3 = texture(cc_jointTexture, vec2((x + 2.5) * invSize, y));\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #else\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 12.0 * (a_jointAnimInfo.x * a_jointAnimInfo.y + i) + a_jointAnimInfo.z;\n #else\n highp float j = 12.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = vec4(\n decode32(texture(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n );\n vec4 v2 = vec4(\n decode32(texture(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n );\n vec4 v3 = vec4(\n decode32(texture(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n );\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #endif\n#else\n mat4 getJointMatrix (float i) {\n int idx = int(i);\n vec4 v1 = cc_joints[idx * 3];\n vec4 v2 = cc_joints[idx * 3 + 1];\n vec4 v3 = cc_joints[idx * 3 + 2];\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n#endif\nmat4 skinMatrix () {\n return getJointMatrix(a_joints.x) * a_weights.x\n + getJointMatrix(a_joints.y) * a_weights.y;\n + getJointMatrix(a_joints.z) * a_weights.z;\n + getJointMatrix(a_joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\n mat4 m = skinMatrix();\n position = m * position;\n}\nvoid CCSkin (inout StandardVertInput attr) {\n mat4 m = skinMatrix();\n attr.position = m * attr.position;\n attr.normal = (m * vec4(attr.normal, 0.0)).xyz;\n attr.tangent.xyz = (m * vec4(attr.tangent.xyz, 0.0)).xyz;\n}\n#endif\nlayout(binding = 23) uniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\n#if USE_INSTANCING\n layout(location = 8) in vec4 a_matWorld0;\n layout(location = 9) in vec4 a_matWorld1;\n layout(location = 10) in vec4 a_matWorld2;\n#elif USE_BATCHING\n layout(location = 11) in float a_dyn_batch_id;\n layout(binding = 21) uniform CCLocalBatched {\n highp mat4 cc_matWorlds[10];\n };\n#else\nlayout(binding = 21) uniform CCLocal {\n highp mat4 cc_matWorld;\n highp mat4 cc_matWorldIT;\n highp vec4 cc_lightingMapUVParam;\n};\n#endif\nfloat LinearFog(vec4 pos) {\n vec4 wPos = pos;\n float cam_dis = distance(cc_cameraPos, wPos);\n float fogStart = cc_fogBase.x;\n float fogEnd = cc_fogBase.y;\n return clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float fogDensity = cc_fogBase.z;\n float cam_dis = distance(cc_cameraPos, wPos) / fogAtten * 4.;\n float f = exp(-cam_dis * fogDensity);\n return f;\n}\nfloat ExpSquaredFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float fogDensity = cc_fogBase.z;\n float cam_dis = distance(cc_cameraPos, wPos) / fogAtten * 4.;\n float f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\n return f;\n}\nfloat LayeredFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float _FogTop = cc_fogAdd.x;\n float _FogRange = cc_fogAdd.y;\n vec3 camWorldProj = cc_cameraPos.xyz;\n camWorldProj.y = 0.;\n vec3 worldPosProj = wPos.xyz;\n worldPosProj.y = 0.;\n float fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\n float fDeltaY, fDensityIntegral;\n if (cc_cameraPos.y > _FogTop) {\n if (wPos.y < _FogTop) {\n fDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\n fDensityIntegral = fDeltaY * fDeltaY * 0.5;\n } else {\n fDeltaY = 0.;\n fDensityIntegral = 0.;\n }\n } else {\n if (wPos.y < _FogTop) {\n float fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\n float fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\n fDeltaY = abs(fDeltaA - fDeltaB);\n fDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n } else {\n fDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\n fDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n }\n }\n float fDensity;\n if (fDeltaY != 0.) {\n fDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n } else {\n fDensity = 0.;\n }\n float f = exp(-fDensity);\n return f;\n}\nfloat CC_TRANSFER_FOG(vec4 pos) {\n #if CC_USE_FOG == 1\n return LinearFog(pos);\n #elif CC_USE_FOG == 2\n return ExpFog(pos);\n #elif CC_USE_FOG == 3\n return ExpSquaredFog(pos);\n #elif CC_USE_FOG == 4\n return LayeredFog(pos);\n #endif\n return 1.;\n}\n#if USE_VERTEX_COLOR\n layout(location = 12) in lowp vec4 a_color;\n layout(location = 0) out lowp vec4 v_color;\n#endif\n#if USE_TEXTURE\n layout(location = 1) out vec2 v_uv;\n layout(binding = 0) uniform TexCoords {\n vec4 tilingOffset;\n };\n#endif\nlayout(location = 2) out float factor_fog;\nvec4 vert () {\n vec4 position;\n position = vec4(a_position, 1.0);\n #if CC_USE_MORPH\n applyMorph(position);\n #endif\n #if CC_USE_SKINNING\n CCSkin(position);\n #endif\n mat4 matWorld;\n #if USE_INSTANCING\n matWorld = mat4(\n vec4(a_matWorld0.xyz, 0.0),\n vec4(a_matWorld1.xyz, 0.0),\n vec4(a_matWorld2.xyz, 0.0),\n vec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)\n );\n #elif USE_BATCHING\n matWorld = cc_matWorlds[int(a_dyn_batch_id)];\n #else\n matWorld = cc_matWorld;\n #endif\n #if USE_TEXTURE\n v_uv = a_texCoord;\n #if FLIP_UV\n v_uv.y = 1.0 - v_uv.y;\n #endif\n v_uv = v_uv * tilingOffset.xy + tilingOffset.zw;\n #endif\n #if USE_VERTEX_COLOR\n v_color = a_color;\n #endif\n factor_fog = CC_TRANSFER_FOG(matWorld * position);\n return cc_matProj * (cc_matView * matWorld) * position;\n}\nvoid main() { gl_Position = vert(); }`, - "frag": `\nprecision highp float;\nlayout(binding = 23) uniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\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_ALPHA_TEST\n#endif\n#if USE_TEXTURE\n layout(location = 1) in vec2 v_uv;\n layout(binding = 31) uniform sampler2D mainTexture;\n#endif\nlayout(binding = 1) uniform Constant {\n vec4 mainColor;\n vec4 colorScaleAndCutoff;\n};\n#if USE_VERTEX_COLOR\n layout(location = 0) in lowp vec4 v_color;\n#endif\nlayout(location = 2) in float factor_fog;\nvec4 frag () {\n vec4 o = mainColor;\n o.rgb *= colorScaleAndCutoff.xyz;\n #if USE_VERTEX_COLOR\n o *= v_color;\n #endif\n #if USE_TEXTURE\n o *= texture(mainTexture, v_uv);\n #endif\n #if USE_ALPHA_TEST\n if (o.ALPHA_TEST_CHANNEL < colorScaleAndCutoff.w) discard;\n #endif\n o = vec4(mix(cc_fogColor.rgb, CC_FORWARD_ADD > 0 ? vec3(0.0) : o.rgb, factor_fog), o.a);\n return CCFragOutput(o);\n}\nlayout(location = 0) out vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }` + "frag": `\nprecision highp float;\nlayout(binding = 23) uniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\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_ALPHA_TEST\n#endif\n#if USE_TEXTURE\n layout(location = 1) in vec2 v_uv;\n layout(binding = 31) uniform sampler2D mainTexture;\n#endif\nlayout(binding = 1) uniform Constant {\n vec4 mainColor;\n vec4 colorScaleAndCutoff;\n};\n#if USE_VERTEX_COLOR\n layout(location = 0) in lowp vec4 v_color;\n#endif\nlayout(location = 2) in float factor_fog;\nvec4 frag () {\n vec4 o = mainColor;\n o.rgb *= colorScaleAndCutoff.xyz;\n #if USE_VERTEX_COLOR\n o *= v_color;\n #endif\n #if USE_TEXTURE\n o *= texture(mainTexture, v_uv);\n #endif\n #if USE_ALPHA_TEST\n if (o.ALPHA_TEST_CHANNEL < colorScaleAndCutoff.w) discard;\n #endif\n o = vec4(mix(CC_FORWARD_ADD > 0 ? vec3(0.0) : cc_fogColor.rgb, o.rgb, factor_fog), o.a);\n return CCFragOutput(o);\n}\nlayout(location = 0) out vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }` }, "builtins": { "globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }], "samplers": [] }, @@ -610,17 +609,17 @@ export default [ "shaders": [ { "name": "pipeline/skybox|sky-vs:vert|sky-fs:frag", - "hash": 4223502217, + "hash": 3377239621, "glsl3": { - "vert": `\nprecision highp float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\nstruct StandardVertInput {\n highp vec4 position;\n vec3 normal;\n vec4 tangent;\n};\nin vec3 a_position;\nin vec3 a_normal;\nin vec2 a_texCoord;\nin vec4 a_tangent;\nout mediump vec4 viewDir;\nvec4 vert () {\n viewDir = vec4(a_position, 1.0);\n mat4 matViewRotOnly = mat4(mat3(cc_matView));\n vec4 pos = matViewRotOnly * viewDir;\n vec2 f = cc_matProj[3][3] > 0.0 ? vec2(4.8, 2.4) : vec2(cc_matProj[1][1]);\n pos.xy *= vec2(cc_screenSize.y * cc_screenSize.z, 1.0) * f;\n pos.zw = vec2(-0.99999 * pos.z, -pos.z);\n return pos;\n}\nvoid main() { gl_Position = vert(); }`, + "vert": `\nprecision highp float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\nstruct StandardVertInput {\n highp vec4 position;\n vec3 normal;\n vec4 tangent;\n};\nin vec3 a_position;\nin vec3 a_normal;\nin vec2 a_texCoord;\nin vec4 a_tangent;\nout mediump vec4 viewDir;\nvec4 vert () {\n viewDir = vec4(a_position, 1.0);\n mat4 matViewRotOnly = mat4(mat3(cc_matView));\n vec4 pos = matViewRotOnly * viewDir;\n vec2 f = cc_matProj[3][3] > 0.0 ? vec2(4.8, 2.4) : vec2(cc_matProj[1][1]);\n pos.xy *= vec2(cc_screenSize.y * cc_screenSize.z * cc_cameraPos.w, 1.0) * f;\n pos.zw = vec2(-0.99999 * pos.z, -pos.z);\n return pos;\n}\nvoid main() { gl_Position = vert(); }`, "frag": `\nprecision mediump float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\nuniform samplerCube cc_environment;\nvec3 unpackRGBE (vec4 rgbe) {\n return rgbe.rgb * pow(2.0, rgbe.a * 255.0 - 128.0);\n}\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\n}\nvec3 ACESToneMap (vec3 color) {\n color = min(color, vec3(8.0));\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}\nvec4 CCFragOutput (vec4 color) {\n #if !CC_USE_HDR\n color.rgb = sqrt(ACESToneMap(color.rgb));\n #endif\n return color;\n}\nin mediump vec4 viewDir;\nvec4 frag () {\n #if USE_RGBE_CUBEMAP\n vec3 c = unpackRGBE(texture(cc_environment, viewDir.xyz));\n #else\n vec3 c = SRGBToLinear(texture(cc_environment, viewDir.xyz).rgb);\n #endif\n return CCFragOutput(vec4(c * cc_ambientSky.w, 1.0));\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }` }, "glsl1": { - "vert": `\nprecision highp float;\nuniform mediump vec4 cc_screenSize;\nuniform highp mat4 cc_matView;\nuniform highp mat4 cc_matProj;\nstruct StandardVertInput {\n highp vec4 position;\n vec3 normal;\n vec4 tangent;\n};\nattribute vec3 a_position;\nattribute vec3 a_normal;\nattribute vec2 a_texCoord;\nattribute vec4 a_tangent;\nvarying mediump vec4 viewDir;\nvec4 vert () {\n viewDir = vec4(a_position, 1.0);\n mat4 matViewRotOnly = mat4(mat3(cc_matView));\n vec4 pos = matViewRotOnly * viewDir;\n vec2 f = cc_matProj[3][3] > 0.0 ? vec2(4.8, 2.4) : vec2(cc_matProj[1][1]);\n pos.xy *= vec2(cc_screenSize.y * cc_screenSize.z, 1.0) * f;\n pos.zw = vec2(-0.99999 * pos.z, -pos.z);\n return pos;\n}\nvoid main() { gl_Position = vert(); }`, + "vert": `\nprecision highp float;\nuniform mediump vec4 cc_screenSize;\nuniform highp mat4 cc_matView;\nuniform highp mat4 cc_matProj;\nuniform highp vec4 cc_cameraPos;\nstruct StandardVertInput {\n highp vec4 position;\n vec3 normal;\n vec4 tangent;\n};\nattribute vec3 a_position;\nattribute vec3 a_normal;\nattribute vec2 a_texCoord;\nattribute vec4 a_tangent;\nvarying mediump vec4 viewDir;\nvec4 vert () {\n viewDir = vec4(a_position, 1.0);\n mat4 matViewRotOnly = mat4(mat3(cc_matView));\n vec4 pos = matViewRotOnly * viewDir;\n vec2 f = cc_matProj[3][3] > 0.0 ? vec2(4.8, 2.4) : vec2(cc_matProj[1][1]);\n pos.xy *= vec2(cc_screenSize.y * cc_screenSize.z * cc_cameraPos.w, 1.0) * f;\n pos.zw = vec2(-0.99999 * pos.z, -pos.z);\n return pos;\n}\nvoid main() { gl_Position = vert(); }`, "frag": `\nprecision mediump float;\nuniform mediump vec4 cc_ambientSky;\nuniform samplerCube cc_environment;\nvec3 unpackRGBE (vec4 rgbe) {\n return rgbe.rgb * pow(2.0, rgbe.a * 255.0 - 128.0);\n}\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\n}\nvec3 ACESToneMap (vec3 color) {\n color = min(color, vec3(8.0));\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}\nvec4 CCFragOutput (vec4 color) {\n #if !CC_USE_HDR\n color.rgb = sqrt(ACESToneMap(color.rgb));\n #endif\n return color;\n}\nvarying mediump vec4 viewDir;\nvec4 frag () {\n #if USE_RGBE_CUBEMAP\n vec3 c = unpackRGBE(textureCube(cc_environment, viewDir.xyz));\n #else\n vec3 c = SRGBToLinear(textureCube(cc_environment, viewDir.xyz).rgb);\n #endif\n return CCFragOutput(vec4(c * cc_ambientSky.w, 1.0));\n}\nvoid main() { gl_FragColor = frag(); }` }, "glsl4": { - "vert": `\nprecision highp float;\nlayout(binding = 23) uniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\nstruct StandardVertInput {\n highp vec4 position;\n vec3 normal;\n vec4 tangent;\n};\nlayout(location = 0) in vec3 a_position;\nlayout(location = 1) in vec3 a_normal;\nlayout(location = 2) in vec2 a_texCoord;\nlayout(location = 3) in vec4 a_tangent;\nlayout(location = 0) out mediump vec4 viewDir;\nvec4 vert () {\n viewDir = vec4(a_position, 1.0);\n mat4 matViewRotOnly = mat4(mat3(cc_matView));\n vec4 pos = matViewRotOnly * viewDir;\n vec2 f = cc_matProj[3][3] > 0.0 ? vec2(4.8, 2.4) : vec2(cc_matProj[1][1]);\n pos.xy *= vec2(cc_screenSize.y * cc_screenSize.z, 1.0) * f;\n pos.zw = vec2(-0.99999 * pos.z, -pos.z);\n return pos;\n}\nvoid main() { gl_Position = vert(); }`, + "vert": `\nprecision highp float;\nlayout(binding = 23) uniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\nstruct StandardVertInput {\n highp vec4 position;\n vec3 normal;\n vec4 tangent;\n};\nlayout(location = 0) in vec3 a_position;\nlayout(location = 1) in vec3 a_normal;\nlayout(location = 2) in vec2 a_texCoord;\nlayout(location = 3) in vec4 a_tangent;\nlayout(location = 0) out mediump vec4 viewDir;\nvec4 vert () {\n viewDir = vec4(a_position, 1.0);\n mat4 matViewRotOnly = mat4(mat3(cc_matView));\n vec4 pos = matViewRotOnly * viewDir;\n vec2 f = cc_matProj[3][3] > 0.0 ? vec2(4.8, 2.4) : vec2(cc_matProj[1][1]);\n pos.xy *= vec2(cc_screenSize.y * cc_screenSize.z * cc_cameraPos.w, 1.0) * f;\n pos.zw = vec2(-0.99999 * pos.z, -pos.z);\n return pos;\n}\nvoid main() { gl_Position = vert(); }`, "frag": `\nprecision mediump float;\nlayout(binding = 23) uniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\nlayout(binding = 26) uniform samplerCube cc_environment;\nvec3 unpackRGBE (vec4 rgbe) {\n return rgbe.rgb * pow(2.0, rgbe.a * 255.0 - 128.0);\n}\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\n}\nvec3 ACESToneMap (vec3 color) {\n color = min(color, vec3(8.0));\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}\nvec4 CCFragOutput (vec4 color) {\n #if !CC_USE_HDR\n color.rgb = sqrt(ACESToneMap(color.rgb));\n #endif\n return color;\n}\nlayout(location = 0) in mediump vec4 viewDir;\nvec4 frag () {\n #if USE_RGBE_CUBEMAP\n vec3 c = unpackRGBE(texture(cc_environment, viewDir.xyz));\n #else\n vec3 c = SRGBToLinear(texture(cc_environment, viewDir.xyz).rgb);\n #endif\n return CCFragOutput(vec4(c * cc_ambientSky.w, 1.0));\n}\nlayout(location = 0) out vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }` }, "builtins": { diff --git a/cocos/core/3d/builtin/init.ts b/cocos/core/3d/builtin/init.ts index 492225e3f3..538669bc69 100644 --- a/cocos/core/3d/builtin/init.ts +++ b/cocos/core/3d/builtin/init.ts @@ -173,25 +173,25 @@ class BuiltinResMgr { // sprite material const spriteColorMtl = new legacyCC.Material(); spriteColorMtl._uuid = 'ui-sprite-material'; - spriteColorMtl.initialize({ defines: { USE_TEXTURE: true, CC_ALPHA_SEPARATED: false, IS_GRAY: false }, effectName: 'builtin-sprite' }); + spriteColorMtl.initialize({ defines: { USE_TEXTURE: true, CC_USE_EMBEDDED_ALPHA: false, IS_GRAY: false }, effectName: 'builtin-sprite' }); resources[spriteColorMtl._uuid] = spriteColorMtl; // sprite gray material const spriteGrayMtl = new legacyCC.Material(); spriteGrayMtl._uuid = 'ui-sprite-gray-material'; - spriteGrayMtl.initialize({ defines: { USE_TEXTURE: true, CC_ALPHA_SEPARATED: false, IS_GRAY: true }, effectName: 'builtin-sprite' }); + spriteGrayMtl.initialize({ defines: { USE_TEXTURE: true, CC_USE_EMBEDDED_ALPHA: false, IS_GRAY: true }, effectName: 'builtin-sprite' }); resources[spriteGrayMtl._uuid] = spriteGrayMtl; // sprite alpha material const spriteAlphaMtl = new legacyCC.Material(); spriteAlphaMtl._uuid = 'ui-sprite-alpha-sep-material'; - spriteAlphaMtl.initialize({ defines: { USE_TEXTURE: true, CC_ALPHA_SEPARATED: true, IS_GRAY: false }, effectName: 'builtin-sprite' }); + spriteAlphaMtl.initialize({ defines: { USE_TEXTURE: true, CC_USE_EMBEDDED_ALPHA: true, IS_GRAY: false }, effectName: 'builtin-sprite' }); resources[spriteAlphaMtl._uuid] = spriteAlphaMtl; // sprite alpha & gray material const spriteAlphaGrayMtl = new legacyCC.Material(); spriteAlphaGrayMtl._uuid = 'ui-sprite-gray-alpha-sep-material'; - spriteAlphaGrayMtl.initialize({ defines: { USE_TEXTURE: true, CC_ALPHA_SEPARATED: true, IS_GRAY: true }, effectName: 'builtin-sprite' }); + spriteAlphaGrayMtl.initialize({ defines: { USE_TEXTURE: true, CC_USE_EMBEDDED_ALPHA: true, IS_GRAY: true }, effectName: 'builtin-sprite' }); resources[spriteAlphaGrayMtl._uuid] = spriteAlphaGrayMtl; // default particle material diff --git a/cocos/core/3d/framework/camera-component.ts b/cocos/core/3d/framework/camera-component.ts index 98c5cafee2..fb62c58d2f 100644 --- a/cocos/core/3d/framework/camera-component.ts +++ b/cocos/core/3d/framework/camera-component.ts @@ -34,7 +34,6 @@ import { Component } from '../../components/component'; import { ccclass, help, executeInEditMode, menu, property } from '../../data/class-decorator'; import { ray } from '../../geometry'; import { GFXClearFlag } from '../../gfx/define'; -import { GFXWindow } from '../../gfx/window'; import { Color, Rect, toRadian, Vec3 } from '../../math'; import { CAMERA_DEFAULT_MASK } from '../../pipeline/define'; import { view } from '../../platform/view'; @@ -45,6 +44,7 @@ import { Layers, Node, Scene } from '../../scene-graph'; import { Enum } from '../../value-types'; import { TransformBit } from '../../scene-graph/node-enum'; import { legacyCC } from '../../global-exports'; +import { RenderWindow } from '../../pipeline'; const _temp_vec3_1 = new Vec3(); @@ -65,6 +65,17 @@ const ClearFlag = Enum({ DONT_CLEAR: GFXClearFlag.NONE, }); +// tslint:disable: no-shadowed-variable +export namespace CameraComponent { + export type ProjectionType = EnumAlias; + export type FOVAxis = EnumAlias; + export type ClearFlag = EnumAlias; + export type Aperture = EnumAlias; + export type Shutter = EnumAlias; + export type ISO = EnumAlias; +} +// tslint:enable: no-shadowed-variable + /** * @en The Camera Component. * @zh 相机组件。 @@ -470,7 +481,8 @@ export class CameraComponent extends Component { set inEditorMode (value) { this._inEditorMode = value; if (this._camera) { - this._camera.changeTargetWindow(value ? legacyCC.director.root && legacyCC.director.root.mainWindow : legacyCC.director.root && legacyCC.director.root.tempWindow); + this._camera.changeTargetWindow(value ? legacyCC.director.root && legacyCC.director.root.mainWindow : + legacyCC.director.root && legacyCC.director.root.tempWindow); } } @@ -569,7 +581,8 @@ export class CameraComponent extends Component { name: this.node.name, node: this.node, projection: this._projection, - window: this._inEditorMode ? legacyCC.director.root && legacyCC.director.root.mainWindow : legacyCC.director.root && legacyCC.director.root.tempWindow, + window: this._inEditorMode ? legacyCC.director.root && legacyCC.director.root.mainWindow : + legacyCC.director.root && legacyCC.director.root.tempWindow, priority: this._priority, flows: this._flows, }); @@ -623,7 +636,7 @@ export class CameraComponent extends Component { } protected _chechTargetTextureEvent (old: RenderTexture | null) { - const resizeFunc = (window: GFXWindow) => { + const resizeFunc = (window: RenderWindow) => { if (this._camera) { this._camera.setFixedSize(window.width, window.height); } @@ -650,12 +663,3 @@ export class CameraComponent extends Component { } } } - -export namespace CameraComponent { - export type ProjectionType = EnumAlias; - export type FOVAxis = EnumAlias; - export type ClearFlag = EnumAlias; - export type Aperture = EnumAlias; - export type Shutter = EnumAlias; - export type ISO = EnumAlias; -} diff --git a/cocos/core/3d/framework/light-component.ts b/cocos/core/3d/framework/light-component.ts index efcc44b7fd..d95d4f6bcb 100644 --- a/cocos/core/3d/framework/light-component.ts +++ b/cocos/core/3d/framework/light-component.ts @@ -48,7 +48,7 @@ export const PhotometricTerm = Enum({ * @en static light settings. * @zh 静态灯光设置 */ -@ccclass('cc.ModelLightmapSettings') +@ccclass('cc.StaticLightSettings') class StaticLightSettings { @property protected _editorOnly: boolean = false; diff --git a/cocos/core/3d/misc/create-mesh.ts b/cocos/core/3d/misc/create-mesh.ts index 592189c1cd..fd47dc3392 100644 --- a/cocos/core/3d/misc/create-mesh.ts +++ b/cocos/core/3d/misc/create-mesh.ts @@ -5,6 +5,7 @@ import { Vec3 } from '../../math'; import { IGeometry } from '../../primitive/define'; import { writeBuffer } from './buffer'; import { BufferBlob } from './buffer-blob'; +import { legacyCC } from '../../global-exports'; const _defAttrs: IGFXAttribute[] = [ { name: GFXAttributeName.ATTR_POSITION, format: GFXFormat.RGB32F }, @@ -25,7 +26,8 @@ export function createMesh (geometry: IGeometry, out?: Mesh, options?: createMes let attr: IGFXAttribute | null; - if (geometry.positions.length > 0) { + const positions = geometry.positions.slice(); + if (positions.length > 0) { attr = null; if (geometry.attributes) { for (const att of geometry.attributes) { @@ -40,11 +42,18 @@ export function createMesh (geometry: IGeometry, out?: Mesh, options?: createMes attr = _defAttrs[0]; } + // device NDC correction const info = GFXFormatInfos[attr.format]; + const ySign = legacyCC.director.root.device.projectionSignY; + for (let i = 1; i < positions.length; i += info.count) { + positions[i] *= ySign; + } + attributes.push(attr); - vertCount = Math.max(vertCount, Math.floor(geometry.positions.length / info.count)); - channels.push({ offset: stride, data: geometry.positions, attribute: attr }); + vertCount = Math.max(vertCount, Math.floor(positions.length / info.count)); + channels.push({ offset: stride, data: positions, attribute: attr }); stride += info.size; + } if (geometry.normals && geometry.normals.length > 0) { @@ -199,7 +208,7 @@ export function createMesh (geometry: IGeometry, out?: Mesh, options?: createMes if (!minPosition && options.calculateBounds) { minPosition = Vec3.set(new Vec3(), Infinity, Infinity, Infinity); for (let iVertex = 0; iVertex < vertCount; ++iVertex) { - Vec3.set(v3_1, geometry.positions[iVertex * 3 + 0], geometry.positions[iVertex * 3 + 1], geometry.positions[iVertex * 3 + 2]); + Vec3.set(v3_1, positions[iVertex * 3 + 0], positions[iVertex * 3 + 1], positions[iVertex * 3 + 2]); Vec3.min(minPosition, minPosition, v3_1); } } @@ -207,7 +216,7 @@ export function createMesh (geometry: IGeometry, out?: Mesh, options?: createMes if (!maxPosition && options.calculateBounds) { maxPosition = Vec3.set(new Vec3(), -Infinity, -Infinity, -Infinity); for (let iVertex = 0; iVertex < vertCount; ++iVertex) { - Vec3.set(v3_1, geometry.positions[iVertex * 3 + 0], geometry.positions[iVertex * 3 + 1], geometry.positions[iVertex * 3 + 2]); + Vec3.set(v3_1, positions[iVertex * 3 + 0], positions[iVertex * 3 + 1], positions[iVertex * 3 + 2]); Vec3.max(maxPosition, maxPosition, v3_1); } } diff --git a/cocos/core/assets/mesh.ts b/cocos/core/assets/mesh.ts index 51e8ed05ec..6d5b47f254 100644 --- a/cocos/core/assets/mesh.ts +++ b/cocos/core/assets/mesh.ts @@ -44,7 +44,7 @@ import { GFXPrimitiveMode, } from '../gfx/define'; import { GFXDevice, GFXFeature } from '../gfx/device'; -import { IGFXAttribute } from '../gfx/input-assembler'; +import { IGFXAttribute, IGFXInputAssemblerInfo } from '../gfx/input-assembler'; import { warnID } from '../platform/debug'; import { sys } from '../platform/sys'; import { murmurhash2_32_gc } from '../utils/murmurhash2_gc'; @@ -102,7 +102,7 @@ export interface IFlatBuffer { /** * 渲染子网格。 */ -export class RenderingSubMesh { +export class RenderingSubMesh implements IGFXInputAssemblerInfo { /** * 使用的所有顶点缓冲区。 */ diff --git a/cocos/core/assets/morph-rendering.ts b/cocos/core/assets/morph-rendering.ts index b4a7c76e14..c6ca88ca32 100644 --- a/cocos/core/assets/morph-rendering.ts +++ b/cocos/core/assets/morph-rendering.ts @@ -27,7 +27,7 @@ const preferCpuComputing = false; */ export class StdMorphRendering implements MorphRendering { private _mesh: Mesh; - private _subMeshRenderings: Array = []; + private _subMeshRenderings: (SubMeshMorphRendering | null)[] = []; constructor (mesh: Mesh, gfxDevice: GFXDevice) { this._mesh = mesh; @@ -68,7 +68,7 @@ export class StdMorphRendering implements MorphRendering { public createInstance (): MorphRenderingInstance { const nSubMeshes = this._mesh.struct.primitives.length; - const subMeshInstances: Array = new Array(nSubMeshes); + const subMeshInstances: (SubMeshMorphRenderingInstance | null)[] = new Array(nSubMeshes); for (let iSubMesh = 0; iSubMesh < nSubMeshes; ++iSubMesh) { subMeshInstances[iSubMesh] = this._subMeshRenderings[iSubMesh]?.createInstance() ?? null; } @@ -137,18 +137,18 @@ interface SubMeshMorphRenderingInstance { /** * Asks the define overrides needed to do the rendering. */ - requiredPatches(): IMacroPatch[]; + requiredPatches (): IMacroPatch[]; /** * Adapts the pipelineState to apply the rendering. * @param pipelineState */ - adaptPipelineState(pipelineCreateInfo: IPSOCreateInfo): void; + adaptPipelineState (pipelineCreateInfo: IPSOCreateInfo): void; /** * Destroy this instance. */ - destroy(): void; + destroy (): void; } /** @@ -163,11 +163,11 @@ class GpuComputing implements SubMeshMorphRendering { width: number; height: number; }; - private _attributes: Array<{ + private _attributes: { name: string; texture: Texture2D; sampler: GFXSampler; - }>; + }[]; constructor (mesh: Mesh, subMeshIndex: number, morph: Morph, gfxDevice: GFXDevice) { this._gfxDevice = gfxDevice; @@ -195,7 +195,6 @@ class GpuComputing implements SubMeshMorphRendering { // Creates texture for each attribute. this._attributes = subMeshMorph.attributes.map((attributeName, attributeIndex) => { - const nTargets = subMeshMorph.targets.length; const textureInfo = { displacements: new Array(), targetOffsets: new Array(nTargets).fill(0), @@ -206,8 +205,8 @@ class GpuComputing implements SubMeshMorphRendering { textureInfo.displacements.push(...new Float32Array(meshData, displacements.offset, displacements.count)); }); - const pixelStride = 3; // For position, normal, tangent - const pixelFormat = Texture2D.PixelFormat.RGB32F; // For position, normal, tangent + const pixelStride = 4; // For position, normal, tangent + const pixelFormat = Texture2D.PixelFormat.RGBA32F; // For position, normal, tangent const textureSource = new Float32Array(pixelStride * width * height); const headPixels = nTargets; @@ -298,12 +297,12 @@ class GpuComputing implements SubMeshMorphRendering { */ class CpuComputing implements SubMeshMorphRendering { private _gfxDevice: GFXDevice; - private _attributes: Array<{ + private _attributes: { name: string; - targets: Array<{ + targets: { displacements: Float32Array; - }>; - }> = []; + }[]; + }[] = []; constructor (mesh: Mesh, subMeshIndex: number, morph: Morph, gfxDevice: GFXDevice) { this._gfxDevice = gfxDevice; diff --git a/cocos/core/assets/render-texture.ts b/cocos/core/assets/render-texture.ts index c8144680ee..8b4e4e4f77 100644 --- a/cocos/core/assets/render-texture.ts +++ b/cocos/core/assets/render-texture.ts @@ -3,13 +3,14 @@ */ import { ccclass, property } from '../data/class-decorator'; -import { GFXFormat, GFXTexture } from '../gfx'; +import { GFXFormat, GFXTexture, GFXColorAttachment, GFXDepthStencilAttachment, GFXTextureLayout } from '../gfx'; import { GFXDevice } from '../gfx/device'; -import { GFXWindow } from '../gfx/window'; import { ccenum } from '../value-types/enum'; import { DepthStencilFormat, PixelFormat } from './asset-enum'; import { TextureBase } from './texture-base'; import { legacyCC } from '../global-exports'; +import { RenderWindow } from '../pipeline'; +import { IRenderWindowInfo } from '../pipeline/render-window'; export interface IRenderTextureCreateInfo { name?: string; @@ -24,7 +25,7 @@ ccenum(DepthStencilFormat); @ccclass('cc.RenderTexture') export class RenderTexture extends TextureBase { public static DepthStencilFormat = DepthStencilFormat; - private _window: GFXWindow | null = null; + private _window: RenderWindow | null = null; @property private _depthStencilFormat: DepthStencilFormat = DepthStencilFormat.NONE; @@ -65,13 +66,11 @@ export class RenderTexture extends TextureBase { return this._window; } - public getGFXTexture ( - ): GFXTexture | null /* TODO: Explicit since ISSUE https://github.com/microsoft/TypeScript/issues/31280 , changes required once the issue is fixed. */ { - return this._window ? this._window.colorTexture : null; + public getGFXTexture (): GFXTexture | null { + return this._window ? this._window.colorTextures[0] : null; } - public getGFXStencilTexture ( - ): GFXTexture | null /* TODO: Explicit since ISSUE https://github.com/microsoft/TypeScript/issues/31280 , changes required once the issue is fixed. */ { + public getGFXStencilTexture (): GFXTexture | null { return this._window ? this._window.depthStencilTexture : null; } @@ -140,16 +139,24 @@ export class RenderTexture extends TextureBase { } protected _createWindow (device: GFXDevice) { - const config = { + const colorAttachment = new GFXColorAttachment(); + colorAttachment.format = this._format; + colorAttachment.endLayout = GFXTextureLayout.SHADER_READONLY_OPTIMAL; + const depthStencilAttachment = new GFXDepthStencilAttachment(); + depthStencilAttachment.format = this._depthStencilFormat as unknown as GFXFormat; + + const config: IRenderWindowInfo = { title: this.name, isOffscreen: true, width: this._width, height: this._height, - colorFmt: this._format, - depthStencilFmt: this._depthStencilFormat as unknown as GFXFormat, + renderPassInfo: { + colorAttachments: [colorAttachment], + depthStencilAttachment, + } }; - if (this._window){ + if (this._window) { this._window.initialize(config); return this._window; } diff --git a/cocos/core/components/ui-base/canvas-component.ts b/cocos/core/components/ui-base/canvas-component.ts index fd38e13141..609bc8d7ce 100644 --- a/cocos/core/components/ui-base/canvas-component.ts +++ b/cocos/core/components/ui-base/canvas-component.ts @@ -34,7 +34,6 @@ import { ccclass, help, disallowMultiple, executeInEditMode, executionOrder, men import { director, Director } from '../../director'; import { game } from '../../game'; import { GFXClearFlag } from '../../gfx/define'; -import { GFXWindow } from '../../gfx/window'; import { Color, Vec3, Rect } from '../../math'; import { view } from '../../platform/view'; import visibleRect from '../../platform/visible-rect'; @@ -45,6 +44,7 @@ import { Component } from '../component'; import { UITransformComponent } from './ui-transform-component'; import { EDITOR } from 'internal:constants'; import { legacyCC } from '../../global-exports'; +import { RenderWindow } from '../../pipeline'; const _worldPos = new Vec3(); @@ -110,7 +110,7 @@ export class CanvasComponent extends Component { @property({ tooltip: '清理颜色缓冲区后的颜色', }) - get color() { + get color () { return this._color; } @@ -386,7 +386,7 @@ export class CanvasComponent extends Component { } protected _checkTargetTextureEvent (old: RenderTexture | null) { - const resizeFunc = (win: GFXWindow) => { + const resizeFunc = (win: RenderWindow) => { if (this._camera) { this._camera.setFixedSize(win.width, win.height); } diff --git a/cocos/core/game.ts b/cocos/core/game.ts index d1b50f9e1f..4e48ba6ae9 100644 --- a/cocos/core/game.ts +++ b/cocos/core/game.ts @@ -583,7 +583,7 @@ export class Game extends EventTarget { } if (!JSB && !EDITOR && !PREVIEW && legacyCC.internal.SplashScreen) { - legacyCC.internal.SplashScreen.instance.main(this._gfxDevice); + legacyCC.internal.SplashScreen.instance.main(legacyCC.director.root); } legacyCC.director.root.dataPoolManager.jointTexturePool.registerCustomTextureLayouts(config.customJointTextureLayouts); @@ -738,12 +738,12 @@ export class Game extends EventTarget { window.rAF = window.requestAnimationFrame; window.cAF = window.cancelAnimationFrame; } - else { + else { if (this._intervalId) { window.cAF(this._intervalId); this._intervalId = 0; } - + if (frameRate !== 60 && frameRate !== 30) { window.rAF = this._stTime; window.cAF = this._ctTime; diff --git a/cocos/core/gfx/device.ts b/cocos/core/gfx/device.ts index a228323440..56df05a7dc 100644 --- a/cocos/core/gfx/device.ts +++ b/cocos/core/gfx/device.ts @@ -18,7 +18,6 @@ import { GFXRenderPass, IGFXRenderPassInfo } from './render-pass'; import { GFXSampler, IGFXSamplerInfo } from './sampler'; import { GFXShader, IGFXShaderInfo } from './shader'; import { GFXTexture, IGFXTextureInfo, IGFXTextureViewInfo } from './texture'; -import { GFXWindow, IGFXWindowInfo } from './window'; ccenum(GFXFormat); @@ -142,14 +141,6 @@ export abstract class GFXDevice { return this._nativeHeight; } - /** - * @en Device main window. - * @zh 设备主窗口。 - */ - get mainWindow (): GFXWindow { - return this._mainWindow as GFXWindow; - } - /** * @en Device command allocator. * @zh 命令分配器。 @@ -360,7 +351,6 @@ export abstract class GFXDevice { protected _height: number = 0; protected _nativeWidth: number = 0; protected _nativeHeight: number = 0; - protected _mainWindow: GFXWindow | null = null; protected _cmdAllocator: GFXCommandAllocator | null = null; protected _maxVertexAttributes: number = 0; protected _maxVertexUniformVectors: number = 0; @@ -498,13 +488,6 @@ export abstract class GFXDevice { */ public abstract createFence (info: IGFXFenceInfo): GFXFence; - /** - * @en Create window. - * @zh 创建窗口。 - * @param info GFX window description info. - */ - public abstract createWindow (info: IGFXWindowInfo): GFXWindow; - /** * @en Begin current frame. * @zh 开始当前帧。 diff --git a/cocos/core/gfx/index.ts b/cocos/core/gfx/index.ts index 66dbfd62bf..1541e3fca0 100644 --- a/cocos/core/gfx/index.ts +++ b/cocos/core/gfx/index.ts @@ -32,7 +32,6 @@ export * from './render-pass'; export * from './sampler'; export * from './shader'; export * from './texture'; -export * from './window'; legacyCC.GFXDevice = GFXDevice; legacyCC.GFXBuffer = GFXBuffer; diff --git a/cocos/core/gfx/render-pass.ts b/cocos/core/gfx/render-pass.ts index 6bef3ee061..bb8d6f236a 100644 --- a/cocos/core/gfx/render-pass.ts +++ b/cocos/core/gfx/render-pass.ts @@ -23,8 +23,8 @@ export class GFXColorAttachment { public loadOp: GFXLoadOp = GFXLoadOp.CLEAR; public storeOp: GFXStoreOp = GFXStoreOp.STORE; public sampleCount: number = 1; - public beginLayout: GFXTextureLayout = GFXTextureLayout.COLOR_ATTACHMENT_OPTIMAL; - public endLayout: GFXTextureLayout = GFXTextureLayout.COLOR_ATTACHMENT_OPTIMAL; + public beginLayout: GFXTextureLayout = GFXTextureLayout.UNDEFINED; + public endLayout: GFXTextureLayout = GFXTextureLayout.PRESENT_SRC; } /** @@ -38,7 +38,7 @@ export class GFXDepthStencilAttachment { public stencilLoadOp: GFXLoadOp = GFXLoadOp.CLEAR; public stencilStoreOp: GFXStoreOp = GFXStoreOp.STORE; public sampleCount: number = 1; - public beginLayout: GFXTextureLayout = GFXTextureLayout.DEPTH_STENCIL_ATTACHMENT_OPTIMAL; + public beginLayout: GFXTextureLayout = GFXTextureLayout.UNDEFINED; public endLayout: GFXTextureLayout = GFXTextureLayout.DEPTH_STENCIL_ATTACHMENT_OPTIMAL; } @@ -52,9 +52,9 @@ export interface IGFXSubPassInfo { } export interface IGFXRenderPassInfo { - colorAttachments?: GFXColorAttachment[]; - depthStencilAttachment?: GFXDepthStencilAttachment; - subPasses? : IGFXSubPassInfo[]; + colorAttachments: GFXColorAttachment[]; + depthStencilAttachment: GFXDepthStencilAttachment; + subPasses?: IGFXSubPassInfo[]; } /** diff --git a/cocos/core/gfx/webgl/webgl-commands.ts b/cocos/core/gfx/webgl/webgl-commands.ts index 6f7311d24e..ea94360907 100644 --- a/cocos/core/gfx/webgl/webgl-commands.ts +++ b/cocos/core/gfx/webgl/webgl-commands.ts @@ -81,6 +81,7 @@ export function GFXFormatToWebGLType (format: GFXFormat, gl: WebGLRenderingConte case GFXFormat.RGB32UI: return gl.UNSIGNED_INT; case GFXFormat.RGB32I: return gl.INT; + case GFXFormat.BGRA8: return gl.UNSIGNED_BYTE; case GFXFormat.RGBA8: return gl.UNSIGNED_BYTE; case GFXFormat.SRGB8_A8: return gl.UNSIGNED_BYTE; case GFXFormat.RGBA8SN: return gl.BYTE; @@ -156,6 +157,7 @@ export function GFXFormatToWebGLInternalFormat (format: GFXFormat, gl: WebGLRend case GFXFormat.RGB8: return gl.RGB; case GFXFormat.RGB16F: return gl.RGB; case GFXFormat.RGB32F: return gl.RGB; + case GFXFormat.BGRA8: return gl.RGBA; case GFXFormat.RGBA8: return gl.RGBA; case GFXFormat.RGBA16F: return gl.RGBA; case GFXFormat.RGBA32F: return gl.RGBA; @@ -210,6 +212,7 @@ export function GFXFormatToWebGLFormat (format: GFXFormat, gl: WebGLRenderingCon case GFXFormat.RGB8: return gl.RGB; case GFXFormat.RGB16F: return gl.RGB; case GFXFormat.RGB32F: return gl.RGB; + case GFXFormat.BGRA8: return gl.RGBA; case GFXFormat.RGBA8: return gl.RGBA; case GFXFormat.RGBA16F: return gl.RGBA; case GFXFormat.RGBA32F: return gl.RGBA; diff --git a/cocos/core/gfx/webgl/webgl-device.ts b/cocos/core/gfx/webgl/webgl-device.ts index f5d1b198a8..2d8ee0c752 100644 --- a/cocos/core/gfx/webgl/webgl-device.ts +++ b/cocos/core/gfx/webgl/webgl-device.ts @@ -29,7 +29,6 @@ import { GFXRenderPass, IGFXRenderPassInfo } from '../render-pass'; import { GFXSampler, IGFXSamplerInfo } from '../sampler'; import { GFXShader, IGFXShaderInfo } from '../shader'; import { GFXTexture, IGFXTextureInfo, IGFXTextureViewInfo } from '../texture'; -import { GFXWindow, IGFXWindowInfo } from '../window'; import { WebGLGFXBindingLayout } from './webgl-binding-layout'; import { WebGLGFXBuffer } from './webgl-buffer'; import { WebGLGFXCommandAllocator } from './webgl-command-allocator'; @@ -47,7 +46,6 @@ import { WebGLGFXSampler } from './webgl-sampler'; import { WebGLGFXShader } from './webgl-shader'; import { WebGLStateCache } from './webgl-state-cache'; import { WebGLGFXTexture } from './webgl-texture'; -import { WebGLGFXWindow } from './webgl-window'; export class WebGLGFXDevice extends GFXDevice { @@ -440,15 +438,6 @@ export class WebGLGFXDevice extends GFXDevice { // create primary window const canvas = this._webGLRC.canvas as HTMLCanvasElement; - this._mainWindow = this.createWindow({ - title: canvas.title || '', - left: canvas.offsetLeft || 0, - top: canvas.offsetTop || 0, - width: this._webGLRC.drawingBufferWidth, - height: this._webGLRC.drawingBufferHeight, - colorFmt: this._colorFmt, - depthStencilFmt: this._depthStencilFmt, - }); this._cmdAllocator = this.createCommandAllocator({}); @@ -518,11 +507,6 @@ export class WebGLGFXDevice extends GFXDevice { this.nullTexCube = null; } - if (this._mainWindow) { - this._mainWindow.destroy(); - this._mainWindow = null; - } - if (this._cmdAllocator) { this._cmdAllocator.destroy(); this._cmdAllocator = null; @@ -632,12 +616,6 @@ export class WebGLGFXDevice extends GFXDevice { return queue; } - public createWindow (info: IGFXWindowInfo): GFXWindow { - const window = new WebGLGFXWindow(this); - window.initialize(info); - return window; - } - public acquire () {} public present () { diff --git a/cocos/core/gfx/webgl/webgl-render-pass.ts b/cocos/core/gfx/webgl/webgl-render-pass.ts index 30d73ffd51..64c66fef7e 100644 --- a/cocos/core/gfx/webgl/webgl-render-pass.ts +++ b/cocos/core/gfx/webgl/webgl-render-pass.ts @@ -12,8 +12,8 @@ export class WebGLGFXRenderPass extends GFXRenderPass { public initialize (info: IGFXRenderPassInfo): boolean { - this._colorInfos = info.colorAttachments || []; - this._depthStencilInfo = info.depthStencilAttachment || null; + this._colorInfos = info.colorAttachments; + this._depthStencilInfo = info.depthStencilAttachment; this._gpuRenderPass = { colorAttachments: this._colorInfos, diff --git a/cocos/core/gfx/webgl/webgl-window.ts b/cocos/core/gfx/webgl/webgl-window.ts deleted file mode 100644 index d10daee871..0000000000 --- a/cocos/core/gfx/webgl/webgl-window.ts +++ /dev/null @@ -1,160 +0,0 @@ -import { - GFXFormat, - GFXLoadOp, - GFXStoreOp, - GFXTextureFlagBit, - GFXTextureLayout, - GFXTextureType, - GFXTextureUsageBit, - GFXStatus, -} from '../define'; -import { GFXWindow, IGFXWindowInfo } from '../window'; -import { GFXTexture } from '../../gfx/texture'; - -export class WebGLGFXWindow extends GFXWindow { - - public initialize (info: IGFXWindowInfo): boolean { - - if (info.title !== undefined) { - this._title = info.title; - } - - if (info.left !== undefined) { - this._left = info.left; - } - - if (info.top !== undefined) { - this._top = info.top; - } - - if (info.isOffscreen !== undefined) { - this._isOffscreen = info.isOffscreen; - } - - this._width = info.width; - this._height = info.height; - this._nativeWidth = this._width; - this._nativeHeight = this._height; - this._colorFmt = info.colorFmt; - this._depthStencilFmt = info.depthStencilFmt; - - this._renderPass = this._device.createRenderPass({ - colorAttachments: [{ - format: this._colorFmt, - loadOp: GFXLoadOp.CLEAR, - storeOp: GFXStoreOp.STORE, - sampleCount: 1, - beginLayout: GFXTextureLayout.COLOR_ATTACHMENT_OPTIMAL, - endLayout: GFXTextureLayout.PRESENT_SRC, - }], - depthStencilAttachment: { - format : this._depthStencilFmt, - depthLoadOp : GFXLoadOp.CLEAR, - depthStoreOp : GFXStoreOp.STORE, - stencilLoadOp : GFXLoadOp.CLEAR, - stencilStoreOp : GFXStoreOp.STORE, - sampleCount : 1, - beginLayout : GFXTextureLayout.DEPTH_STENCIL_ATTACHMENT_OPTIMAL, - endLayout : GFXTextureLayout.PRESENT_SRC, - }, - }); - - const colorTextures: GFXTexture[] = []; - - if (this._isOffscreen) { - if (this._colorFmt !== GFXFormat.UNKNOWN) { - this._colorTex = this._device.createTexture({ - type : GFXTextureType.TEX2D, - usage : GFXTextureUsageBit.COLOR_ATTACHMENT | GFXTextureUsageBit.SAMPLED, - format : this._colorFmt, - width : this._width, - height : this._height, - depth : 1, - arrayLayer : 1, - mipLevel : 1, - flags : GFXTextureFlagBit.NONE, - }); - colorTextures.push(this._colorTex); - } - - if (this._depthStencilFmt !== GFXFormat.UNKNOWN) { - this._depthStencilTex = this._device.createTexture({ - type : GFXTextureType.TEX2D, - usage : GFXTextureUsageBit.DEPTH_STENCIL_ATTACHMENT, - format : this._depthStencilFmt, - width : this._width, - height : this._height, - depth : 1, - arrayLayer : 1, - mipLevel : 1, - flags : GFXTextureFlagBit.NONE, - }); - } - } - - this._framebuffer = this._device.createFramebuffer({ - renderPass: this._renderPass, - colorTextures, - depthStencilTexture: this._depthStencilTex, - isOffscreen: this._isOffscreen, - }); - - this._status = GFXStatus.SUCCESS; - - return true; - } - - public destroy () { - if (this._depthStencilTex) { - this._depthStencilTex.destroy(); - this._depthStencilTex = null; - } - - if (this._colorTex) { - this._colorTex.destroy(); - this._colorTex = null; - } - - if (this._framebuffer) { - this._framebuffer.destroy(); - this._framebuffer = null; - } - - if (this._renderPass) { - this._renderPass.destroy(); - this._renderPass = null; - } - - this._status = GFXStatus.UNREADY; - } - - public resize (width: number, height: number) { - - this._width = width; - this._height = height; - - if (width > this._nativeWidth || - height > this._nativeHeight) { - - this._nativeWidth = width; - this._nativeHeight = height; - - if (this._depthStencilTex) { - this._depthStencilTex.resize(width, height); - } - - if (this._colorTex) { - this._colorTex.resize(width, height); - } - - if (this._framebuffer && this._framebuffer.isOffscreen) { - this._framebuffer.destroy(); - this._framebuffer.initialize({ - renderPass: this._renderPass!, - colorTextures: [ this._colorTex! ], - depthStencilTexture: this._depthStencilTex!, - }); - } - } - } -} diff --git a/cocos/core/gfx/webgl2/webgl2-commands.ts b/cocos/core/gfx/webgl2/webgl2-commands.ts index 05e9783299..9adaac6ae5 100644 --- a/cocos/core/gfx/webgl2/webgl2-commands.ts +++ b/cocos/core/gfx/webgl2/webgl2-commands.ts @@ -114,6 +114,7 @@ export function GFXFormatToWebGLType (format: GFXFormat, gl: WebGL2RenderingCont case GFXFormat.RGB32UI: return gl.UNSIGNED_INT; case GFXFormat.RGB32I: return gl.INT; + case GFXFormat.BGRA8: return gl.UNSIGNED_BYTE; case GFXFormat.RGBA8: return gl.UNSIGNED_BYTE; case GFXFormat.SRGB8_A8: return gl.UNSIGNED_BYTE; case GFXFormat.RGBA8SN: return gl.BYTE; @@ -198,6 +199,7 @@ export function GFXFormatToWebGLInternalFormat (format: GFXFormat, gl: WebGL2Ren case GFXFormat.RGB8SN: return gl.RGB8_SNORM; case GFXFormat.RGB8UI: return gl.RGB8UI; case GFXFormat.RGB8I: return gl.RGB8I; + case GFXFormat.BGRA8: return gl.RGBA8; case GFXFormat.RGBA8: return gl.RGBA8; case GFXFormat.RGBA8SN: return gl.RGBA8_SNORM; case GFXFormat.RGBA8UI: return gl.RGBA8UI; @@ -289,6 +291,7 @@ export function GFXFormatToWebGLFormat (format: GFXFormat, gl: WebGL2RenderingCo case GFXFormat.RGB8SN: case GFXFormat.RGB8UI: case GFXFormat.RGB8I: return gl.RGB; + case GFXFormat.BGRA8: case GFXFormat.RGBA8: case GFXFormat.RGBA8SN: case GFXFormat.RGBA8UI: diff --git a/cocos/core/gfx/webgl2/webgl2-device.ts b/cocos/core/gfx/webgl2/webgl2-device.ts index 597e767368..c2d24936d5 100644 --- a/cocos/core/gfx/webgl2/webgl2-device.ts +++ b/cocos/core/gfx/webgl2/webgl2-device.ts @@ -27,7 +27,6 @@ import { GFXRenderPass, IGFXRenderPassInfo } from '../render-pass'; import { GFXSampler, IGFXSamplerInfo } from '../sampler'; import { GFXShader, IGFXShaderInfo } from '../shader'; import { GFXTexture, IGFXTextureInfo, IGFXTextureViewInfo } from '../texture'; -import { GFXWindow, IGFXWindowInfo } from '../window'; import { WebGL2GFXBindingLayout } from './webgl2-binding-layout'; import { WebGL2GFXBuffer } from './webgl2-buffer'; import { WebGL2GFXCommandAllocator } from './webgl2-command-allocator'; @@ -48,7 +47,6 @@ import { WebGL2GFXSampler } from './webgl2-sampler'; import { WebGL2GFXShader } from './webgl2-shader'; import { WebGL2StateCache } from './webgl2-state-cache'; import { WebGL2GFXTexture } from './webgl2-texture'; -import { WebGL2GFXWindow } from './webgl2-window'; export class WebGL2GFXDevice extends GFXDevice { @@ -328,18 +326,6 @@ export class WebGL2GFXDevice extends GFXDevice { // create queue this._queue = this.createQueue({ type: GFXQueueType.GRAPHICS }); - // create primary window - const canvas = this._webGL2RC.canvas as HTMLCanvasElement; - this._mainWindow = this.createWindow({ - title: canvas.title || '', - left: canvas.offsetLeft || 0, - top: canvas.offsetTop || 0, - width: this._webGL2RC.drawingBufferWidth, - height: this._webGL2RC.drawingBufferHeight, - colorFmt: this._colorFmt, - depthStencilFmt: this._depthStencilFmt, - }); - this._cmdAllocator = this.createCommandAllocator({}); // create default null texture @@ -408,11 +394,6 @@ export class WebGL2GFXDevice extends GFXDevice { this.nullTexCube = null; } - if (this._mainWindow) { - this._mainWindow.destroy(); - this._mainWindow = null; - } - if (this._cmdAllocator) { this._cmdAllocator.destroy(); this._cmdAllocator = null; @@ -522,12 +503,6 @@ export class WebGL2GFXDevice extends GFXDevice { return queue; } - public createWindow (info: IGFXWindowInfo): GFXWindow { - const window = new WebGL2GFXWindow(this); - window.initialize(info); - return window; - } - public acquire () {} public present () { diff --git a/cocos/core/gfx/webgl2/webgl2-render-pass.ts b/cocos/core/gfx/webgl2/webgl2-render-pass.ts index 198e002a12..6c1226fa8e 100644 --- a/cocos/core/gfx/webgl2/webgl2-render-pass.ts +++ b/cocos/core/gfx/webgl2/webgl2-render-pass.ts @@ -12,8 +12,8 @@ export class WebGL2GFXRenderPass extends GFXRenderPass { public initialize (info: IGFXRenderPassInfo): boolean { - this._colorInfos = info.colorAttachments || []; - this._depthStencilInfo = info.depthStencilAttachment || null; + this._colorInfos = info.colorAttachments; + this._depthStencilInfo = info.depthStencilAttachment; this._gpuRenderPass = { colorAttachments: this._colorInfos, diff --git a/cocos/core/gfx/webgl2/webgl2-window.ts b/cocos/core/gfx/webgl2/webgl2-window.ts deleted file mode 100644 index a24107ff0c..0000000000 --- a/cocos/core/gfx/webgl2/webgl2-window.ts +++ /dev/null @@ -1,160 +0,0 @@ -import { - GFXFormat, - GFXLoadOp, - GFXStoreOp, - GFXTextureFlagBit, - GFXTextureLayout, - GFXTextureType, - GFXTextureUsageBit, - GFXStatus, -} from '../define'; -import { GFXTexture } from '../../gfx/texture'; -import { GFXWindow, IGFXWindowInfo } from '../window'; - -export class WebGL2GFXWindow extends GFXWindow { - - public initialize (info: IGFXWindowInfo): boolean { - - if (info.title !== undefined) { - this._title = info.title; - } - - if (info.left !== undefined) { - this._left = info.left; - } - - if (info.top !== undefined) { - this._top = info.top; - } - - if (info.isOffscreen !== undefined) { - this._isOffscreen = info.isOffscreen; - } - - this._width = info.width; - this._height = info.height; - this._nativeWidth = this._width; - this._nativeHeight = this._height; - this._colorFmt = info.colorFmt; - this._depthStencilFmt = info.depthStencilFmt; - - this._renderPass = this._device.createRenderPass({ - colorAttachments: [{ - format: this._colorFmt, - loadOp: GFXLoadOp.CLEAR, - storeOp: GFXStoreOp.STORE, - sampleCount: 1, - beginLayout: GFXTextureLayout.COLOR_ATTACHMENT_OPTIMAL, - endLayout: GFXTextureLayout.COLOR_ATTACHMENT_OPTIMAL, - }], - depthStencilAttachment: { - format : this._depthStencilFmt, - depthLoadOp : GFXLoadOp.CLEAR, - depthStoreOp : GFXStoreOp.STORE, - stencilLoadOp : GFXLoadOp.CLEAR, - stencilStoreOp : GFXStoreOp.STORE, - sampleCount : 1, - beginLayout : GFXTextureLayout.DEPTH_STENCIL_ATTACHMENT_OPTIMAL, - endLayout : GFXTextureLayout.DEPTH_STENCIL_ATTACHMENT_OPTIMAL, - }, - }); - - const colorTextures: GFXTexture[] = []; - - if (this._isOffscreen) { - if (this._colorFmt !== GFXFormat.UNKNOWN) { - this._colorTex = this._device.createTexture({ - type : GFXTextureType.TEX2D, - usage : GFXTextureUsageBit.COLOR_ATTACHMENT | GFXTextureUsageBit.SAMPLED, - format : this._colorFmt, - width : this._width, - height : this._height, - depth : 1, - arrayLayer : 1, - mipLevel : 1, - flags : GFXTextureFlagBit.NONE, - }); - colorTextures.push(this._colorTex); - } - - if (this._depthStencilFmt !== GFXFormat.UNKNOWN) { - this._depthStencilTex = this._device.createTexture({ - type : GFXTextureType.TEX2D, - usage : GFXTextureUsageBit.DEPTH_STENCIL_ATTACHMENT, - format : this._depthStencilFmt, - width : this._width, - height : this._height, - depth : 1, - arrayLayer : 1, - mipLevel : 1, - flags : GFXTextureFlagBit.NONE, - }); - } - } - - this._framebuffer = this._device.createFramebuffer({ - renderPass: this._renderPass, - colorTextures, - depthStencilTexture: this._depthStencilTex, - isOffscreen: this._isOffscreen, - }); - - this._status = GFXStatus.SUCCESS; - - return true; - } - - public destroy () { - if (this._depthStencilTex) { - this._depthStencilTex.destroy(); - this._depthStencilTex = null; - } - - if (this._colorTex) { - this._colorTex.destroy(); - this._colorTex = null; - } - - if (this._framebuffer) { - this._framebuffer.destroy(); - this._framebuffer = null; - } - - if (this._renderPass) { - this._renderPass.destroy(); - this._renderPass = null; - } - - this._status = GFXStatus.UNREADY; - } - - public resize (width: number, height: number) { - - this._width = width; - this._height = height; - - if (width > this._nativeWidth || - height > this._nativeHeight) { - - this._nativeWidth = width; - this._nativeHeight = height; - - if (this._depthStencilTex) { - this._depthStencilTex.resize(width, height); - } - - if (this._colorTex) { - this._colorTex.resize(width, height); - } - - if (this._framebuffer && this._framebuffer.isOffscreen) { - this._framebuffer.destroy(); - this._framebuffer.initialize({ - renderPass: this._renderPass!, - colorTextures: [ this._colorTex! ], - depthStencilTexture: this._depthStencilTex!, - }); - } - } - } -} diff --git a/cocos/core/gfx/window.ts b/cocos/core/gfx/window.ts deleted file mode 100644 index 8616d7ab71..0000000000 --- a/cocos/core/gfx/window.ts +++ /dev/null @@ -1,132 +0,0 @@ -/** - * @category gfx - */ - -import { GFXFormat, GFXObject, GFXObjectType } from './define'; -import { GFXDevice } from './device'; -import { GFXFramebuffer } from './framebuffer'; -import { GFXRenderPass } from './render-pass'; -import { GFXTexture } from './texture'; - -export interface IGFXWindowInfo { - title?: string; - left?: number; - top?: number; - width: number; - height: number; - colorFmt: GFXFormat; - depthStencilFmt: GFXFormat; - isOffscreen?: boolean; -} - -/** - * @en GFX window. - * @zh GFX 窗口。 - */ -export abstract class GFXWindow extends GFXObject { - - /** - * @en Get window width. - * @zh 窗口宽度。 - */ - get width (): number { - return this._width; - } - - /** - * @en Get window height. - * @zh 窗口高度。 - */ - get height (): number { - return this._height; - } - - /** - * @en Get window color format. - * @zh 窗口颜色格式。 - */ - get colorFormat (): GFXFormat { - return this._colorFmt; - } - - /** - * @en Get window depth stencil format. - * @zh 窗口深度模板格式。 - */ - get detphStencilFormat (): GFXFormat { - return this._depthStencilFmt; - } - - /** - * @en Is this window offscreen? - * @zh 是否是离屏的。 - */ - get isOffscreen (): boolean { - return this._isOffscreen; - } - - /** - * @en Get the render pass of this window. - * @zh GFX 渲染过程。 - */ - get renderPass (): GFXRenderPass { - return this._renderPass!; - } - - /** - * @en Get color texture of this window. - * @zh 颜色纹理。 - */ - get colorTexture (): GFXTexture | null { - return this._colorTex; - } - - /** - * @en Get depth stencil texture of this window. - * @zh 深度模板纹理。 - */ - get depthStencilTexture (): GFXTexture | null { - return this._depthStencilTex; - } - - /** - * @en Get window frame buffer. - * @zh GFX帧缓冲。 - */ - get framebuffer (): GFXFramebuffer { - return this._framebuffer!; - } - - protected _device: GFXDevice; - protected _title: string = ''; - protected _left: number = 0; - protected _top: number = 0; - protected _width: number = 0; - protected _height: number = 0; - protected _nativeWidth: number = 0; - protected _nativeHeight: number = 0; - protected _colorFmt: GFXFormat = GFXFormat.UNKNOWN; - protected _depthStencilFmt: GFXFormat = GFXFormat.UNKNOWN; - protected _isOffscreen: boolean = false; - protected _renderPass: GFXRenderPass | null = null; - protected _colorTex: GFXTexture | null = null; - protected _depthStencilTex: GFXTexture | null = null; - protected _framebuffer: GFXFramebuffer | null = null; - - constructor (device: GFXDevice) { - super(GFXObjectType.WINDOW); - this._device = device; - } - - public abstract initialize (info: IGFXWindowInfo): boolean; - - public abstract destroy (): void; - - /** - * @en Resize window. - * @zh 重置窗口大小。 - * @param width The new width. - * @param height The new height. - */ - public abstract resize (width: number, height: number): void; -} diff --git a/cocos/core/pipeline/index.ts b/cocos/core/pipeline/index.ts index 418f48ad3f..fbc023cdba 100644 --- a/cocos/core/pipeline/index.ts +++ b/cocos/core/pipeline/index.ts @@ -9,6 +9,7 @@ export { RenderPipeline } from './render-pipeline'; export { RenderFlow } from './render-flow'; export { RenderStage } from './render-stage'; export { RenderView } from './render-view'; +export { RenderWindow } from './render-window'; export { ForwardPipeline } from './forward/forward-pipeline'; export { ForwardFlow } from './forward/forward-flow'; diff --git a/cocos/core/pipeline/pipeline-state-manager.ts b/cocos/core/pipeline/pipeline-state-manager.ts index cd99aab306..ace828df5a 100644 --- a/cocos/core/pipeline/pipeline-state-manager.ts +++ b/cocos/core/pipeline/pipeline-state-manager.ts @@ -26,10 +26,21 @@ export class PipelineStateManager { const newHash = hash1 ^ hash2 ^ hash3; let pso = this._PSOHashMap.get(newHash); if (!pso) { - this._inputState.attributes = ia.attributes; const pipelineLayout = device.createPipelineLayout({ layouts: [psoCreateInfo.bindingLayout] }); + const iaAttrs = this._inputState.attributes = ia.attributes; + const shaderAttrs = psoCreateInfo.shaderInput.attributes; + for (let i = 0; i < iaAttrs.length; i++) { + const attr = iaAttrs[i]; let j = 0; + for (; j < shaderAttrs.length; j++) { + const shaderAttr = shaderAttrs[j]; + if (shaderAttr.name === attr.name) { + attr.location = shaderAttr.location; + break; + } + } + } pso = device.createPipelineState({ primitive: psoCreateInfo.primitive, shader: psoCreateInfo.shader, diff --git a/cocos/core/pipeline/render-pipeline.ts b/cocos/core/pipeline/render-pipeline.ts index 80bb6d318c..e70df65509 100644 --- a/cocos/core/pipeline/render-pipeline.ts +++ b/cocos/core/pipeline/render-pipeline.ts @@ -720,15 +720,7 @@ export abstract class RenderPipeline { this._colorFmt = GFXFormat.RGBA8; } - if (this._device.depthBits === 24) { - if (this._device.stencilBits === 8) { - this._depthStencilFmt = GFXFormat.D24S8; - } else { - this._depthStencilFmt = GFXFormat.D24; - } - } else { - this._depthStencilFmt = GFXFormat.D16; - } + this._depthStencilFmt = this._device.depthStencilFormat; // colorFmt = GFXFormat.RGBA16F; @@ -769,7 +761,7 @@ export abstract class RenderPipeline { format: this._getTextureFormat(rtd.format, rtd.usage), width: rtd.width, height: rtd.height, - //FIXME: need other args? + // FIXME: need other args? })); } for (let i = 0; i < this.renderPasses.length; i++) { @@ -801,7 +793,7 @@ export abstract class RenderPipeline { this._frameBuffers.set(fbd.name, this._device.createFramebuffer({ renderPass: rp, colorTextures: ts, - colorMipmapLevels: colorMipmapLevels, + colorMipmapLevels, depthStencilTexture: dsv, depStencilMipmapLevel: 0, })); diff --git a/cocos/core/pipeline/render-queue.ts b/cocos/core/pipeline/render-queue.ts index d5adf4dc5a..c1640113be 100644 --- a/cocos/core/pipeline/render-queue.ts +++ b/cocos/core/pipeline/render-queue.ts @@ -86,7 +86,7 @@ export class RenderQueue { const hash = (0 << 30) | pass.priority << 16 | subModel.priority << 8 | passIdx; const rp = this._passPool.add(); rp.hash = hash; - rp.depth = renderObj.depth; + rp.depth = renderObj.depth || 0; rp.shaderId = psoCreateInfo.shader.id; rp.subModel = subModel; rp.passIdx = passIdx; diff --git a/cocos/core/pipeline/render-stage.ts b/cocos/core/pipeline/render-stage.ts index 8a41b54e01..8723011ac4 100644 --- a/cocos/core/pipeline/render-stage.ts +++ b/cocos/core/pipeline/render-stage.ts @@ -235,8 +235,6 @@ export abstract class RenderStage { throw new Error(''); } - this._device = this._flow.pipeline.root.device; - this._clearColors = [{ r: 0.3, g: 0.6, b: 0.9, a: 1.0 }]; this._renderArea = { x: 0, y: 0, width: 0, height: 0 }; diff --git a/cocos/core/pipeline/render-view.ts b/cocos/core/pipeline/render-view.ts index 865952c929..2f869ba564 100644 --- a/cocos/core/pipeline/render-view.ts +++ b/cocos/core/pipeline/render-view.ts @@ -2,13 +2,13 @@ * @category pipeline */ -import { GFXWindow } from '../gfx/window'; import { Camera } from '../renderer/scene/camera'; import { Root } from '../root'; import { CAMERA_DEFAULT_MASK } from './define'; import { RenderFlowType } from './pipeline-serialization'; import { RenderFlow } from './render-flow'; import { legacyCC } from '../global-exports'; +import { RenderWindow } from './render-window'; /** * @zh @@ -134,7 +134,7 @@ export class RenderView { * @zh * GFX窗口。 */ - private _window: GFXWindow | null = null; + private _window: RenderWindow | null = null; /** * @zh diff --git a/cocos/core/pipeline/render-window.ts b/cocos/core/pipeline/render-window.ts new file mode 100644 index 0000000000..4a3ba90cf3 --- /dev/null +++ b/cocos/core/pipeline/render-window.ts @@ -0,0 +1,239 @@ +import { + GFXFormat, + GFXTextureFlagBit, + GFXTextureType, + GFXTextureUsageBit, +} from '../gfx/define'; +import { GFXRenderPass, GFXTexture, GFXFramebuffer, IGFXRenderPassInfo } from '../gfx'; +import { Root } from '../root'; + +export interface IRenderWindowInfo { + title?: string; + left?: number; + top?: number; + width: number; + height: number; + renderPassInfo: IGFXRenderPassInfo; + isOffscreen?: boolean; +} + +export class RenderWindow { + + /** + * @en Get window width. + * @zh 窗口宽度。 + */ + get width (): number { + return this._width; + } + + /** + * @en Get window height. + * @zh 窗口高度。 + */ + get height (): number { + return this._height; + } + + /** + * @en Is this window offscreen? + * @zh 是否是离屏的。 + */ + get isOffscreen (): boolean { + return this._isOffscreen; + } + + /** + * @en Get the render pass of this window. + * @zh GFX 渲染过程。 + */ + get renderPass (): GFXRenderPass { + return this._renderPass!; + } + + /** + * @en Get color texture of this window. + * @zh 颜色纹理。 + */ + get colorTextures (): GFXTexture[] { + return this._colorTexs; + } + + /** + * @en Get depth stencil texture of this window. + * @zh 深度模板纹理。 + */ + get depthStencilTexture (): GFXTexture | null { + return this._depthStencilTex; + } + + /** + * @en Get window frame buffer. + * @zh GFX帧缓冲。 + */ + get framebuffer (): GFXFramebuffer { + return this._framebuffer!; + } + + public static registerCreateFunc (root: Root) { + root._createWindowFun = (_root: Root): RenderWindow => new RenderWindow(_root); + } + + protected _root: Root; + protected _title: string = ''; + protected _left: number = 0; + protected _top: number = 0; + protected _width: number = 0; + protected _height: number = 0; + protected _nativeWidth: number = 0; + protected _nativeHeight: number = 0; + protected _isOffscreen: boolean = false; + protected _renderPass: GFXRenderPass | null = null; + protected _colorTexs: GFXTexture[] = []; + protected _depthStencilTex: GFXTexture | null = null; + protected _framebuffer: GFXFramebuffer | null = null; + + private constructor (root: Root) { + this._root = root; + } + + public initialize (info: IRenderWindowInfo): boolean { + + if (info.title !== undefined) { + this._title = info.title; + } + + if (info.left !== undefined) { + this._left = info.left; + } + + if (info.top !== undefined) { + this._top = info.top; + } + + if (info.isOffscreen !== undefined) { + this._isOffscreen = info.isOffscreen; + } + + this._width = info.width; + this._height = info.height; + this._nativeWidth = this._width; + this._nativeHeight = this._height; + + for (let i = 0; i < info.renderPassInfo.colorAttachments.length; i++) { + const attachment = info.renderPassInfo.colorAttachments[i]; + if (attachment.format === GFXFormat.UNKNOWN) { + attachment.format = this._root.device.colorFormat; + } + } + if (info.renderPassInfo.depthStencilAttachment) { + const attachment = info.renderPassInfo.depthStencilAttachment; + if (attachment.format === GFXFormat.UNKNOWN) { + attachment.format = this._root.device.depthStencilFormat; + } + } + this._renderPass = this._root.device.createRenderPass(info.renderPassInfo); + + let colorTexturesToCreate = info.renderPassInfo.colorAttachments.length; + if (!this._isOffscreen) { colorTexturesToCreate--; } // -1 for swapchain image + for (let i = 0; i < colorTexturesToCreate; i++) { + const format = info.renderPassInfo.colorAttachments[i].format; + const colorTex = this._root.device.createTexture({ + type: GFXTextureType.TEX2D, + usage: GFXTextureUsageBit.COLOR_ATTACHMENT | GFXTextureUsageBit.SAMPLED, + format, + width: this._width, + height: this._height, + depth: 1, + arrayLayer: 1, + mipLevel: 1, + flags: GFXTextureFlagBit.NONE, + }); + this._colorTexs.push(colorTex); + } + if (this._isOffscreen && info.renderPassInfo.depthStencilAttachment) { + const format = info.renderPassInfo.depthStencilAttachment.format; + this._depthStencilTex = this._root.device.createTexture({ + type: GFXTextureType.TEX2D, + usage: GFXTextureUsageBit.DEPTH_STENCIL_ATTACHMENT, + format, + width: this._width, + height: this._height, + depth: 1, + arrayLayer: 1, + mipLevel: 1, + flags: GFXTextureFlagBit.NONE, + }); + } + + this._framebuffer = this._root.device.createFramebuffer({ + renderPass: this._renderPass, + colorTextures: this._colorTexs, + depthStencilTexture: this._depthStencilTex, + isOffscreen: this._isOffscreen, + }); + + return true; + } + + public destroy () { + if (this._depthStencilTex) { + this._depthStencilTex.destroy(); + this._depthStencilTex = null; + } + + for (let i = 0; i < this._colorTexs.length; i++) { + if (this._colorTexs[i]) { + this._colorTexs[i].destroy(); + } + } + this._colorTexs.length = 0; + + if (this._framebuffer) { + this._framebuffer.destroy(); + this._framebuffer = null; + } + + if (this._renderPass) { + this._renderPass.destroy(); + this._renderPass = null; + } + } + + /** + * @en Resize window. + * @zh 重置窗口大小。 + * @param width The new width. + * @param height The new height. + */ + public resize (width: number, height: number) { + this._width = width; + this._height = height; + + if (width > this._nativeWidth || + height > this._nativeHeight) { + + this._nativeWidth = width; + this._nativeHeight = height; + + if (this._depthStencilTex) { + this._depthStencilTex.resize(width, height); + } + + for (let i = 0; i < this._colorTexs.length; i++) { + if (this._colorTexs[i]) { + this._colorTexs[i].resize(width, height); + } + } + + if (this._framebuffer && this._framebuffer.isOffscreen) { + this._framebuffer.destroy(); + this._framebuffer.initialize({ + renderPass: this._renderPass!, + colorTextures: this._colorTexs, + depthStencilTexture: this._depthStencilTex!, + }); + } + } + } +} diff --git a/cocos/core/pipeline/ui/ui-stage.ts b/cocos/core/pipeline/ui/ui-stage.ts index 1e82d3a068..824cc3e50a 100644 --- a/cocos/core/pipeline/ui/ui-stage.ts +++ b/cocos/core/pipeline/ui/ui-stage.ts @@ -3,10 +3,11 @@ */ import { GFXCommandBuffer } from '../../gfx/command-buffer'; -import { GFXCommandBufferType, IGFXColor } from '../../gfx/define'; +import { GFXCommandBufferType, IGFXColor, GFXLoadOp, GFXStoreOp, GFXTextureLayout } from '../../gfx/define'; import { RenderFlow } from '../render-flow'; import { IRenderStageInfo, RenderQueueSortMode, RenderStage } from '../render-stage'; import { RenderView } from '../render-view'; +import { legacyCC } from '../../global-exports'; const bufs: GFXCommandBuffer[] = []; const colors: IGFXColor[] = []; @@ -31,10 +32,45 @@ export class UIStage extends RenderStage { public activate (flow: RenderFlow) { super.activate(flow); this.createCmdBuffer(); + + const device = this._device!; + + // UI uses a exclusive render pass + const renderPass = device.createRenderPass({ + colorAttachments: [{ + format: device.colorFormat, + loadOp: GFXLoadOp.LOAD, // shouldn't clear color attachment + storeOp: GFXStoreOp.STORE, + sampleCount: 1, + beginLayout: GFXTextureLayout.PRESENT_SRC, + endLayout: GFXTextureLayout.PRESENT_SRC, + }], + depthStencilAttachment: { + format : device.depthStencilFormat, + depthLoadOp : GFXLoadOp.CLEAR, + depthStoreOp : GFXStoreOp.STORE, + stencilLoadOp : GFXLoadOp.CLEAR, + stencilStoreOp : GFXStoreOp.STORE, + sampleCount : 1, + beginLayout : GFXTextureLayout.DEPTH_STENCIL_ATTACHMENT_OPTIMAL, + endLayout : GFXTextureLayout.DEPTH_STENCIL_ATTACHMENT_OPTIMAL, + }, + }); + this._framebuffer = device.createFramebuffer({ + renderPass, + colorTextures: [], + depthStencilTexture: null, + isOffscreen: false + }); } public destroy () { + if (this._framebuffer) { + this._framebuffer.renderPass!.destroy(); + this._framebuffer.destroy(); + } + if (this._cmdBuff) { this._cmdBuff.destroy(); this._cmdBuff = null; @@ -60,8 +96,10 @@ export class UIStage extends RenderStage { } this._renderQueues[0].sort(); - const framebuffer = view.window!.framebuffer; - + let framebuffer = view.window!.framebuffer; + if (!framebuffer.isOffscreen) { + framebuffer = this._framebuffer!; + } const cmdBuff = this._cmdBuff!; const camera = view.camera!; diff --git a/cocos/core/renderer/scene/camera.ts b/cocos/core/renderer/scene/camera.ts index 3d82367b7b..d195a2c02a 100644 --- a/cocos/core/renderer/scene/camera.ts +++ b/cocos/core/renderer/scene/camera.ts @@ -1,6 +1,5 @@ import { frustum, ray } from '../../geometry'; import { GFXClearFlag, IGFXColor } from '../../gfx/define'; -import { GFXWindow } from '../../gfx/window'; import { lerp, Mat4, Rect, toRadian, Vec3 } from '../../math'; import { CAMERA_DEFAULT_MASK } from '../../pipeline/define'; import { RenderView } from '../../pipeline/render-view'; @@ -8,6 +7,7 @@ import { Node } from '../../scene-graph'; import { RenderScene } from './render-scene'; import { GFXDevice } from '../../gfx'; import { legacyCC } from '../../global-exports'; +import { RenderWindow } from '../../pipeline'; export enum CameraFOVAxis { VERTICAL, @@ -78,7 +78,7 @@ export interface ICameraInfo { node: Node; projection: number; targetDisplay?: number; - window?: GFXWindow | null; + window?: RenderWindow | null; priority: number; pipeline?: string; flows?: string[]; @@ -524,7 +524,7 @@ export class Camera { } } - public changeTargetWindow (window: GFXWindow | null = null) { + public changeTargetWindow (window: RenderWindow | null = null) { const win = window || legacyCC.director.root.mainWindow; if (win && this._view) { this._view.window = win; diff --git a/cocos/core/root.ts b/cocos/core/root.ts index d22cdf60af..c3133127bd 100644 --- a/cocos/core/root.ts +++ b/cocos/core/root.ts @@ -4,22 +4,19 @@ import { builtinResMgr } from './3d/builtin'; import { GFXDevice } from './gfx/device'; -import { GFXWindow, IGFXWindowInfo } from './gfx/window'; import { Pool } from './memop'; import { RenderPipeline } from './pipeline/render-pipeline'; import { IRenderViewInfo, RenderView } from './pipeline/render-view'; import { Camera, Light, Model } from './renderer'; import { DataPoolManager } from './renderer/data-pool-manager'; -import { DirectionalLight } from './renderer/scene/directional-light'; import { LightType } from './renderer/scene/light'; import { IRenderSceneInfo, RenderScene } from './renderer/scene/render-scene'; import { SphereLight } from './renderer/scene/sphere-light'; import { SpotLight } from './renderer/scene/spot-light'; import { UI } from './renderer/ui/ui'; import { legacyCC } from './global-exports'; - -export let _createSceneFun; -export let _createViewFun; +import { RenderWindow, IRenderWindowInfo } from './pipeline/render-window'; +import { GFXColorAttachment, GFXDepthStencilAttachment } from './gfx/render-pass'; /** * @zh @@ -55,7 +52,7 @@ export class Root { * @zh * 主窗口 */ - public get mainWindow (): GFXWindow | null { + public get mainWindow (): RenderWindow | null { return this._mainWindow; } @@ -63,11 +60,11 @@ export class Root { * @zh * 当前窗口 */ - public set curWindow (window: GFXWindow | null) { + public set curWindow (window: RenderWindow | null) { this._curWindow = window; } - public get curWindow (): GFXWindow | null { + public get curWindow (): RenderWindow | null { return this._curWindow; } @@ -75,11 +72,11 @@ export class Root { * @zh * 临时窗口(用于数据传输) */ - public set tempWindow (window: GFXWindow | null) { + public set tempWindow (window: RenderWindow | null) { this._tempWindow = window; } - public get tempWindow (): GFXWindow | null { + public get tempWindow (): RenderWindow | null { return this._tempWindow; } @@ -87,7 +84,7 @@ export class Root { * @zh * 窗口列表 */ - public get windows (): GFXWindow[] { + public get windows (): RenderWindow[] { return this._windows; } @@ -176,14 +173,15 @@ export class Root { return this._dataPoolMgr; } - public _createSceneFun; - public _createViewFun; + public _createSceneFun: (root: Root) => RenderScene = null!; + public _createViewFun: (root: Root, camera: Camera) => RenderView = null!; + public _createWindowFun: (root: Root) => RenderWindow = null!; private _device: GFXDevice; - private _windows: GFXWindow[] = []; - private _mainWindow: GFXWindow | null = null; - private _curWindow: GFXWindow | null = null; - private _tempWindow: GFXWindow | null = null; + private _windows: RenderWindow[] = []; + private _mainWindow: RenderWindow | null = null; + private _curWindow: RenderWindow | null = null; + private _tempWindow: RenderWindow | null = null; private _pipeline: RenderPipeline | null = null; private _ui: UI | null = null; private _dataPoolMgr: DataPoolManager; @@ -192,9 +190,6 @@ export class Root { private _modelPools: Map> = new Map>(); private _cameraPool: Pool | null = null; private _lightPools: Map> = new Map>(); - private _directLightPool: Pool | null = null; - private _sphereLightPool: Pool | null = null; - private _spotLightPool: Pool | null = null; private _time: number = 0; private _frameTime: number = 0; private _fpsTime: number = 0; @@ -213,6 +208,7 @@ export class Root { RenderScene.registerCreateFunc(this); RenderView.registerCreateFunc(this); + RenderWindow.registerCreateFunc(this); this._cameraPool = new Pool(() => new Camera(this._device), 4); } @@ -224,11 +220,15 @@ export class Root { */ public initialize (info: IRootInfo): boolean { - if (!this._device.mainWindow) { - return false; - } - - this._mainWindow = this._device.mainWindow; + this._mainWindow = this.createWindow({ + title: 'rootMainWindow', + width: this._device.width, + height: this._device.height, + renderPassInfo: { + colorAttachments: [ new GFXColorAttachment() ], + depthStencilAttachment: new GFXDepthStencilAttachment(), + }, + }); this._curWindow = this._mainWindow; builtinResMgr.initBuiltinRes(this._device); @@ -310,7 +310,7 @@ export class Root { * 激活指定窗口为当前窗口 * @param window GFX窗口 */ - public activeWindow (window: GFXWindow) { + public activeWindow (window: RenderWindow) { this._curWindow = window; } @@ -371,16 +371,11 @@ export class Root { * 创建窗口 * @param info GFX窗口描述信息 */ - public createWindow (info: IGFXWindowInfo): GFXWindow | null { - if (this._device) { - const window = this._device.createWindow(info); - if (window) { - this._windows.push(window); - return window; - } - } - - return null; + public createWindow (info: IRenderWindowInfo): RenderWindow | null { + const window = this._createWindowFun(this); + window.initialize(info); + this._windows.push(window); + return window; } /** @@ -388,7 +383,7 @@ export class Root { * 销毁指定的窗口 * @param window GFX窗口 */ - public destroyWindow (window: GFXWindow) { + public destroyWindow (window: RenderWindow) { for (let i = 0; i < this._windows.length; ++i) { if (this._windows[i] === window) { window.destroy(); diff --git a/cocos/core/splash-screen.ts b/cocos/core/splash-screen.ts index a5bd9690a3..4acdcfb030 100644 --- a/cocos/core/splash-screen.ts +++ b/cocos/core/splash-screen.ts @@ -21,6 +21,7 @@ import { GFXSampler } from './gfx'; import { IPSOCreateInfo } from './renderer'; import { PipelineStateManager } from './pipeline/pipeline-state-manager'; import { legacyCC } from './global-exports'; +import { Root } from './root'; export type SplashEffectType = 'NONE' | 'FADE-INOUT'; @@ -49,6 +50,7 @@ export class SplashScreen { private startTime: number = -1; private setting!: ISplashSetting; private image!: TexImageSource; + private root!: Root; private device!: GFXDevice; private sampler!: GFXSampler; private cmdBuff!: GFXCommandBuffer; @@ -80,8 +82,8 @@ export class SplashScreen { private screenWidth!: number; private screenHeight!: number; - public main (device: GFXDevice) { - if (device == null) return console.error('GFX DEVICE IS NULL.'); + public main (root: Root) { + if (root == null) return console.error('RENDER ROOT IS NULL.'); if (window._CCSettings && window._CCSettings.splashScreen) { this.setting = window._CCSettings.splashScreen; @@ -116,7 +118,8 @@ export class SplashScreen { } else { legacyCC.view.setDesignResolutionSize(960, 640, 4); } - this.device = device; + this.root = root; + this.device = root.device; legacyCC.game.once(legacyCC.Game.EVENT_GAME_INITED, () => { legacyCC.director._lateUpdate = performance.now(); }, legacyCC.director); @@ -386,7 +389,7 @@ export class SplashScreen { private initCMD () { const device = this.device as GFXDevice; this.renderArea = { x: 0, y: 0, width: device.width, height: device.height }; - this.framebuffer = device.mainWindow.framebuffer; + this.framebuffer = this.root.mainWindow!.framebuffer; this.cmdBuff = device.createCommandBuffer({ allocator: device.commandAllocator, diff --git a/cocos/core/utils/profiler/profiler.ts b/cocos/core/utils/profiler/profiler.ts index b8014bcaf8..83fbbea603 100644 --- a/cocos/core/utils/profiler/profiler.ts +++ b/cocos/core/utils/profiler/profiler.ts @@ -300,12 +300,6 @@ export class Profiler { } } - // device NDC correction - const ySign = this._device!.projectionSignY; - for (let i = 1; i < vertexPos.length; i += 3) { - vertexPos[i] *= ySign; - } - const modelCom = managerNode.addComponent('cc.ModelComponent') as ModelComponent; modelCom.mesh = createMesh({ positions: vertexPos, @@ -313,6 +307,7 @@ export class Profiler { colors: vertexUV, // pack all the necessary info in a_color: { x: u, y: v, z: id.x, w: id.y } }); + const ySign = this._device!.projectionSignY; const _material = new Material(); _material.initialize({ effectName: 'util/profiler' }); _material.setProperty('offset', new Vec4(-0.9, -0.9 * ySign, this._eachNumWidth, 0));