abc2cb62-7852-4525-a90d-d474487b88f2.json 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. {
  2. "__type__": "cc.EffectAsset",
  3. "_name": "builtin-phong",
  4. "_objFlags": 0,
  5. "_native": "",
  6. "properties": null,
  7. "techniques": [
  8. {
  9. "passes": [
  10. {
  11. "name": "phong",
  12. "rasterizerState": {
  13. "cullMode": 1029
  14. },
  15. "depthStencilState": {
  16. "depthTest": true,
  17. "depthWrite": true
  18. },
  19. "properties": {
  20. "alphaThreshold": {
  21. "value": [
  22. 0.5
  23. ],
  24. "type": 13
  25. },
  26. "mainTiling": {
  27. "value": [
  28. 1,
  29. 1
  30. ],
  31. "type": 14
  32. },
  33. "mainOffset": {
  34. "value": [
  35. 0,
  36. 0
  37. ],
  38. "type": 14
  39. },
  40. "diffuseColor": {
  41. "value": [
  42. 1,
  43. 1,
  44. 1,
  45. 1
  46. ],
  47. "editor": {
  48. "type": "color"
  49. },
  50. "type": 16
  51. },
  52. "diffuseTexture": {
  53. "value": "white",
  54. "type": 29
  55. },
  56. "specularColor": {
  57. "value": [
  58. 1,
  59. 1,
  60. 1,
  61. 1
  62. ],
  63. "editor": {
  64. "type": "color"
  65. },
  66. "type": 16
  67. },
  68. "specularTexture": {
  69. "value": "white",
  70. "type": 29
  71. },
  72. "emissiveColor": {
  73. "value": [
  74. 0,
  75. 0,
  76. 0,
  77. 1
  78. ],
  79. "editor": {
  80. "type": "color"
  81. },
  82. "type": 16
  83. },
  84. "emissiveTexture": {
  85. "value": "white",
  86. "type": 29
  87. },
  88. "glossiness": {
  89. "value": [
  90. 10
  91. ],
  92. "type": 13
  93. },
  94. "normalTexture": {
  95. "value": "white",
  96. "type": 29
  97. }
  98. },
  99. "program": "builtin-phong|phong-vs|phong-fs"
  100. },
  101. {
  102. "name": "shadowcast",
  103. "stage": "shadowcast",
  104. "rasterizerState": {
  105. "cullMode": 1029
  106. },
  107. "depthStencilState": {
  108. "depthTest": true,
  109. "depthWrite": true
  110. },
  111. "program": "builtin-phong|shadow-map-vs|shadow-map-fs"
  112. }
  113. ]
  114. }
  115. ],
  116. "shaders": [
  117. {
  118. "hash": 3560892936,
  119. "glsl3": {
  120. "vert": "\nprecision highp float;\nuniform CCLocal {\n mat4 cc_matWorld;\n mat4 cc_matWorldIT;\n};\nuniform CCGlobal {\n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos;\n vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n};\n#if CC_USE_SKINNING\n in vec4 a_weights;\n in vec4 a_joints;\n #if CC_USE_JOINTS_TEXTRUE\n uniform SKINNING {\n vec2 jointsTextureSize;\n };\n uniform sampler2D jointsTexture;\n #if CC_JOINTS_TEXTURE_FLOAT32\n mat4 getBoneMatrix(const in float i) {\n float width = jointsTextureSize.x;\n float height = jointsTextureSize.y;\n float j = i * 4.0;\n float x = mod(j, width);\n float y = floor(j / width);\n float dx = 1.0 / width;\n float dy = 1.0 / height;\n y = dy * (y + 0.5);\n vec4 v1 = texture(jointsTexture, vec2(dx * (x + 0.5), y));\n vec4 v2 = texture(jointsTexture, vec2(dx * (x + 1.5), y));\n vec4 v3 = texture(jointsTexture, vec2(dx * (x + 2.5), y));\n vec4 v4 = texture(jointsTexture, vec2(dx * (x + 3.5), y));\n return mat4(v1, v2, v3, v4);\n }\n #else\n float decode32(vec4 rgba) {\n float Sign = 1.0 - step(128.0, rgba[0]) * 2.0;\n float Exponent = 2.0 * mod(rgba[0], 128.0) + step(128.0, rgba[1]) - 127.0;\n float Mantissa = mod(rgba[1], 128.0) * 65536.0 + rgba[2] * 256.0 + rgba[3] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\n }\n vec4 decodevec4 (vec4 x, vec4 y, vec4 z, vec4 w) {\n return vec4(\n decode32(x.wzyx * 255.0),\n decode32(y.wzyx * 255.0),\n decode32(z.wzyx * 255.0),\n decode32(w.wzyx * 255.0)\n );\n }\n vec4 decodevec4 (float dx, float x, float y) {\n return decodevec4(\n texture(jointsTexture, vec2(dx * (x + 0.5), y)),\n texture(jointsTexture, vec2(dx * (x + 1.5), y)),\n texture(jointsTexture, vec2(dx * (x + 2.5), y)),\n texture(jointsTexture, vec2(dx * (x + 3.5), y))\n );\n }\n mat4 getBoneMatrix(const in float i) {\n float width = jointsTextureSize.x;\n float height = jointsTextureSize.y;\n float j = i * 16.0;\n float x = mod(j, width);\n float y = floor(j / width);\n float dx = 1.0 / width;\n float dy = 1.0 / height;\n y = dy * (y + 0.5);\n vec4 v1 = decodevec4(dx, x, y);\n vec4 v2 = decodevec4(dx, x+4.0, y);\n vec4 v3 = decodevec4(dx, x+8.0, y);\n vec4 v4 = decodevec4(dx, x+12.0, y);\n return mat4(v1, v2, v3, v4);\n }\n #endif\n #else\n uniform JOINT_MATRIX {\n mat4 jointMatrices[50];\n };\n mat4 getBoneMatrix(const in float i) {\n return jointMatrices[int(i)];\n }\n #endif\n mat4 skinMatrix() {\n return\n getBoneMatrix(a_joints.x) * a_weights.x +\n getBoneMatrix(a_joints.y) * a_weights.y +\n getBoneMatrix(a_joints.z) * a_weights.z +\n getBoneMatrix(a_joints.w) * a_weights.w\n ;\n }\n#endif\nstruct StandardVertInput {\n vec2 uv;\n vec4 position;\n vec3 normal;\n vec4 tangent;\n vec4 color;\n};\nin vec3 a_position;\n#if CC_USE_ATTRIBUTE_UV0\nin vec2 a_uv0;\n#endif\n#if CC_USE_ATTRIBUTE_COLOR\nin vec4 a_color;\n#endif\n#if CC_USE_ATTRIBUTE_NORMAL\nin vec3 a_normal;\n#endif\n#if CC_USE_ATTRIBUTE_TANGENT\nin vec4 a_tangent;\n#endif\nvoid CCAttribute (out StandardVertInput In) {\n In.position = vec4(a_position, 1.0);\n #if CC_USE_ATTRIBUTE_UV0\n In.uv = a_uv0;\n #else\n In.uv = vec2(0.0);\n #endif\n #if CC_USE_ATTRIBUTE_COLOR\n In.color = a_color;\n #else\n In.color = vec4(1.0);\n #endif\n #if CC_USE_ATTRIBUTE_NORMAL\n In.normal = a_normal;\n #else\n In.normal = vec3(0.0, 1.0, 0.0);\n #endif\n #if CC_USE_ATTRIBUTE_TANGENT\n In.tangent = a_tangent;\n #else\n In.tangent = vec4(1.0, 0.0, 0.0, 0.0);\n #endif\n}\nvoid CCVertInput(out StandardVertInput In) {\n CCAttribute(In);\n #if CC_USE_SKINNING\n mat4 m = skinMatrix();\n In.position = m * In.position;\n #if CC_USE_ATTRIBUTE_NORMAL\n In.normal = (m * vec4(In.normal, 0)).xyz;\n #endif\n #if CC_USE_ATTRIBUTE_TANGENT\n In.tangent = m * In.tangent;\n #endif\n #endif\n}\n#if CC_USE_SHADOW_MAP && CC_NUM_SHADOW_LIGHTS > 0\n uniform CC_SHADOW {\n mat4 cc_shadow_lightViewProjMatrix[2];\n vec4 cc_shadow_info[2];\n };\n #if CC_NUM_SHADOW_LIGHTS > 0\n uniform sampler2D cc_shadow_map_0;\n #endif\n #if CC_NUM_SHADOW_LIGHTS > 1\n uniform sampler2D cc_shadow_map_1;\n #endif\n varying vec4 v_posLightSpace[2];\n varying float v_depth[2];\n#endif\nvoid CCShadowInput (vec3 worldPos) {\n #if CC_USE_SHADOW_MAP && CC_NUM_SHADOW_LIGHTS > 0\n for (int i = 0; i < CC_NUM_SHADOW_LIGHTS; i++) {\n v_posLightSpace[i] = cc_shadow_lightViewProjMatrix[i] * vec4(worldPos, 1.0);\n v_depth[i] = (v_posLightSpace[i].z + cc_shadow_info[i].x) / (cc_shadow_info[i].x + cc_shadow_info[i].y);\n }\n #endif\n}\nuniform MAIN_TILING {\n vec2 mainTiling;\n vec2 mainOffset;\n};\n#if CC_USE_ATTRIBUTE_UV0 && (USE_DIFFUSE_TEXTURE || USE_EMISSIVE_TEXTURE || USE_SPECULAR_TEXTURE || USE_NORMAL_TEXTURE)\n out mediump vec2 v_uv0;\n#endif\n#if CC_USE_ATTRIBUTE_COLOR\n out lowp vec4 v_color;\n#endif\n#if USE_NORMAL_TEXTURE\n out vec3 v_tangent;\n out vec3 v_bitangent;\n#endif\nout vec3 v_worldNormal;\nout vec3 v_worldPos;\nout vec3 v_viewDirection;\nvoid main () {\n StandardVertInput In;\n CCVertInput(In);\n vec4 position = In.position;\n v_worldNormal = normalize((cc_matWorldIT * vec4(In.normal, 0)).xyz);\n v_worldPos = (cc_matWorld * position).xyz;\n v_viewDirection = normalize(cc_cameraPos.xyz - v_worldPos);\n #if CC_USE_ATTRIBUTE_UV0 && (USE_DIFFUSE_TEXTURE || USE_EMISSIVE_TEXTURE || USE_SPECULAR_TEXTURE || USE_NORMAL_TEXTURE)\n v_uv0 = In.uv * mainTiling + mainOffset;\n #endif\n #if CC_USE_ATTRIBUTE_COLOR\n v_color = In.color;\n #endif\n #if USE_NORMAL_TEXTURE\n v_tangent = normalize((cc_matWorld * vec4(In.tangent.xyz, 0.0)).xyz);\n v_bitangent = cross(v_worldNormal, v_tangent) * In.tangent.w;\n #endif\n CCShadowInput(v_worldPos);\n gl_Position = cc_matViewProj * cc_matWorld * position;\n}",
  121. "frag": "\nprecision highp float;\nuniform CCGlobal {\n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos;\n vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n};\nvec4 CCFragOutput (vec4 color) {\n #if OUTPUT_TO_GAMMA\n color.rgb = sqrt(color.rgb);\n #endif\n\treturn color;\n}\n#if USE_ALPHA_TEST\n uniform ALPHA_TEST {\n float alphaThreshold;\n };\n#endif\nvoid ALPHA_TEST (in vec4 color) {\n #if USE_ALPHA_TEST\n if (color.a < alphaThreshold) discard;\n #endif\n}\nvoid ALPHA_TEST (in float alpha) {\n #if USE_ALPHA_TEST\n if (alpha < alphaThreshold) discard;\n #endif\n}\nuniform PhongFrag {\n lowp vec4 diffuseColor;\n lowp vec4 specularColor;\n lowp vec4 emissiveColor;\n float glossiness;\n};\n#if USE_DIFFUSE_TEXTURE\n uniform sampler2D diffuseTexture;\n#endif\n#if USE_SPECULAR && USE_SPECULAR_TEXTURE\n uniform sampler2D specularTexture;\n#endif\n#if USE_EMISSIVE && USE_EMISSIVE_TEXTURE\n uniform sampler2D emissiveTexture;\n#endif\n#if USE_NORMAL_TEXTURE\n in vec3 v_tangent;\n in vec3 v_bitangent;\n uniform sampler2D normalTexture;\n#endif\nin vec3 v_worldNormal;\nin vec3 v_worldPos;\nin vec3 v_viewDirection;\n#if CC_USE_ATTRIBUTE_UV0 && (USE_DIFFUSE_TEXTURE || (USE_EMISSIVE && USE_EMISSIVE_TEXTURE) || (USE_SPECULAR && USE_SPECULAR_TEXTURE) || USE_NORMAL_TEXTURE)\n in mediump vec2 v_uv0;\n#endif\n#if CC_USE_ATTRIBUTE_COLOR\n in lowp vec4 v_color;\n#endif\n#if CC_USE_SHADOW_MAP && CC_NUM_SHADOW_LIGHTS > 0\n uniform CC_SHADOW {\n mat4 cc_shadow_lightViewProjMatrix[2];\n vec4 cc_shadow_info[2];\n };\n #if CC_NUM_SHADOW_LIGHTS > 0\n uniform sampler2D cc_shadow_map_0;\n #endif\n #if CC_NUM_SHADOW_LIGHTS > 1\n uniform sampler2D cc_shadow_map_1;\n #endif\n varying vec4 v_posLightSpace[2];\n varying float v_depth[2];\n#endif\nfloat unpackRGBAToDepth(vec4 color) {\n return dot(color, vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 160581375.0));\n}\nfloat getDepth(sampler2D shadowMap, vec2 shadowUV) {\n return unpackRGBAToDepth(texture(shadowMap, shadowUV));\n}\nfloat computeFallOff(float shadow, vec2 coords, float frustumEdgeFalloff) {\n return shadow;\n}\nfloat shadowSimple(sampler2D shadowMap, vec2 shadowUV, float currentDepth, float darkness) {\n float closestDepth = getDepth(shadowMap, shadowUV);\n return currentDepth > closestDepth ? 1.0 - darkness : 1.0;\n}\nfloat shadowPCF3X3(sampler2D shadowMap, vec2 shadowUV, float currentDepth, float darkness, float shadowSize) {\n float shadow = 0.0;\n for (int x = -1; x <= 1; ++x) {\n for (int y = -1; y <= 1; ++y) {\n float closestDepth = getDepth(shadowMap, shadowUV + vec2(x, y) * 1.0/shadowSize);\n shadow += currentDepth > closestDepth ? 1.0 - darkness : 1.0;\n }\n }\n shadow /= 9.0;\n return shadow;\n}\nfloat shadowPCF5X5(sampler2D shadowMap, vec2 shadowUV, float currentDepth, float darkness, float shadowSize) {\n float shadow = 0.0;\n for (int x = -2; x <= 2; ++x) {\n for (int y = -2; y <= 2; ++y) {\n float closestDepth = getDepth(shadowMap, shadowUV + vec2(x, y) * 1.0/shadowSize);\n shadow += currentDepth > closestDepth ? 1.0 - darkness : 1.0;\n }\n }\n shadow /= 25.0;\n return shadow;\n}\n#if CC_NUM_LIGHTS > 0\nuniform CCLIGHTS {\n vec4 cc_lightPositionAndRange[4];\n vec4 cc_lightDirection[4];\n vec4 cc_lightColor[4];\n};\n#endif\nstruct LightInfo {\n vec3 lightDir;\n vec3 radiance;\n vec4 lightColor;\n};\nLightInfo computeDirectionalLighting(\n vec4 lightDirection,\n vec4 lightColor\n) {\n LightInfo ret;\n ret.lightDir = -normalize(lightDirection.xyz);\n ret.radiance = lightColor.rgb;\n ret.lightColor = lightColor;\n return ret;\n}\nLightInfo computePointLighting(\n vec3 worldPosition,\n vec4 lightPositionAndRange,\n vec4 lightColor\n) {\n LightInfo ret;\n vec3 lightDir = lightPositionAndRange.xyz - worldPosition;\n float attenuation = max(0., 1.0 - length(lightDir) / lightPositionAndRange.w);\n ret.lightDir = normalize(lightDir);\n ret.radiance = lightColor.rgb * attenuation;\n ret.lightColor = lightColor;\n return ret;\n}\nLightInfo computeSpotLighting(\n vec3 worldPosition,\n vec4 lightPositionAndRange,\n vec4 lightDirection,\n vec4 lightColor\n) {\n LightInfo ret;\n vec3 lightDir = lightPositionAndRange.xyz - worldPosition;\n float attenuation = max(0., 1.0 - length(lightDir) / lightPositionAndRange.w);\n lightDir = normalize(lightDir);\n float cosConeAngle = max(0., dot(lightDirection.xyz, -lightDir));\n cosConeAngle = cosConeAngle < lightDirection.w ? 0. : cosConeAngle;\n cosConeAngle = pow(cosConeAngle, lightColor.w);\n ret.lightDir = lightDir;\n ret.radiance = lightColor.rgb * attenuation * cosConeAngle;\n ret.lightColor = lightColor;\n return ret;\n}\nstruct Lighting {\n vec3 diffuse;\n vec3 specular;\n};\nstruct PhongSurface {\n vec3 diffuse;\n vec3 emissive;\n vec3 specular;\n float opacity;\n float glossiness;\n vec3 position;\n vec3 normal;\n vec3 viewDirection;\n};\nLighting brdf (PhongSurface s, LightInfo info) {\n Lighting result;\n float ndh = 0.0;\n vec3 halfDir = normalize(s.viewDirection + info.lightDir);\n float NdotH = max(0.0, dot(s.normal, halfDir));\n NdotH = pow(NdotH, max(1.0, s.glossiness * 128.0));\n result.diffuse = info.radiance * max(0.0, dot(s.normal, info.lightDir));\n result.specular = info.radiance * NdotH;\n return result;\n}\nvec4 composePhongShading (Lighting lighting, PhongSurface s) {\n vec4 o = vec4(0.0, 0.0, 0.0, 1.0);\n o.rgb = lighting.diffuse * s.diffuse;\n #if USE_EMISSIVE\n o.rgb += s.emissive;\n #endif\n #if USE_SPECULAR\n o.rgb += lighting.specular * s.specular;\n #endif\n o.a = s.opacity;\n return o;\n}\nvec3 ambient(PhongSurface s, vec4 ambientColor) {\n return s.diffuse * ambientColor.rgb;\n}\nvec4 CCPhongShading (in PhongSurface s) {\n Lighting result;\n result.diffuse = vec3(0, 0, 0);\n result.specular = vec3(0, 0, 0);\n #if CC_NUM_LIGHTS > 0\n #if CC_LIGHT_0_TYPE == 3\n result.diffuse += ambient(s, cc_lightColor[0]);\n #else\n LightInfo info0;\n #if CC_LIGHT_0_TYPE == 0\n info0 = computeDirectionalLighting(cc_lightDirection[0], cc_lightColor[0]);\n #elif CC_LIGHT_0_TYPE == 1\n info0 = computePointLighting(s.position, cc_lightPositionAndRange[0], cc_lightColor[0]);\n #elif CC_LIGHT_0_TYPE == 2\n info0 = computeSpotLighting(s.position, cc_lightPositionAndRange[0], cc_lightDirection[0], cc_lightColor[0]);\n #endif\n Lighting result0 = brdf(s, info0);\n #if CC_USE_SHADOW_MAP && CC_NUM_SHADOW_LIGHTS > 0\n float shadow_0 = 1.0;\n vec2 projCoords0 = v_posLightSpace[0].xy / v_posLightSpace[0].w;\n vec2 shadowUV0 = projCoords0 * 0.5 + vec2(0.5);\n if (shadowUV0.x >= 0.0 && shadowUV0.x <= 1.0 && shadowUV0.y >= 0.0 && shadowUV0.y <= 1.0) {\n float currentDepth0 = clamp(v_depth[0], 0.0, 1.0);\n #if CC_SHADOW_0_TYPE == 3\n shadow_0 = shadowPCF3X3(cc_shadow_map_0, shadowUV0, currentDepth0, cc_shadow_info[0].w, cc_shadow_info[0].z);\n #elif CC_SHADOW_0_TYPE == 4\n shadow_0 = shadowPCF5X5(cc_shadow_map_0, shadowUV0, currentDepth0, cc_shadow_info[0].w, cc_shadow_info[0].z);\n #else\n shadow_0 = shadowSimple(cc_shadow_map_0, shadowUV0, currentDepth0, cc_shadow_info[0].w);\n #endif\n shadow_0 = computeFallOff(shadow_0, projCoords0, 0.0);\n }\n result0.diffuse *= shadow_0;\n result0.specular *= shadow_0;\n #endif\n result.diffuse += result0.diffuse;\n result.specular += result0.specular;\n #endif\n #endif\n #if CC_NUM_LIGHTS > 1\n #if CC_LIGHT_1_TYPE == 3\n result.diffuse += ambient(s, cc_lightColor[1]);\n #else\n LightInfo info1;\n #if CC_LIGHT_1_TYPE == 0\n info1 = computeDirectionalLighting(cc_lightDirection[1], cc_lightColor[1]);\n #elif CC_LIGHT_1_TYPE == 1\n info1 = computePointLighting(s.position, cc_lightPositionAndRange[1], cc_lightColor[1]);\n #elif CC_LIGHT_1_TYPE == 2\n info1 = computeSpotLighting(s.position, cc_lightPositionAndRange[1], cc_lightDirection[1], cc_lightColor[1]);\n #endif\n Lighting result1 = brdf(s, info1);\n #if CC_USE_SHADOW_MAP && CC_NUM_SHADOW_LIGHTS > 1\n float shadow_1 = 1.0;\n vec2 projCoords1 = v_posLightSpace[1].xy / v_posLightSpace[1].w;\n vec2 shadowUV1 = projCoords1 * 0.5 + vec2(0.5);\n if (shadowUV1.x >= 0.0 && shadowUV1.x <= 1.0 && shadowUV1.y >= 0.0 && shadowUV1.y <= 1.0) {\n float currentDepth1 = clamp(v_depth[1], 0.0, 1.0);\n #if CC_SHADOW_1_TYPE == 3\n shadow_1 = shadowPCF3X3(cc_shadow_map_1, shadowUV1, currentDepth1, cc_shadow_info[1].w, cc_shadow_info[1].z);\n #elif CC_SHADOW_1_TYPE == 4\n shadow_1 = shadowPCF5X5(cc_shadow_map_1, shadowUV1, currentDepth1, cc_shadow_info[1].w, cc_shadow_info[1].z);\n #else\n shadow_1 = shadowSimple(cc_shadow_map_1, shadowUV1, currentDepth1, cc_shadow_info[1].w);\n #endif\n shadow_1 = computeFallOff(shadow_1, projCoords1, 0.0);\n }\n result1.diffuse *= shadow_1;\n result1.specular *= shadow_1;\n #endif\n result.diffuse += result1.diffuse;\n result.specular += result1.specular;\n #endif\n #endif\n #if CC_NUM_LIGHTS > 2\n #if CC_LIGHT_2_TYPE == 3\n result.diffuse += ambient(s, cc_lightColor[2]);\n #else\n LightInfo info2;\n #if CC_LIGHT_2_TYPE == 0\n info2 = computeDirectionalLighting(cc_lightDirection[2], cc_lightColor[2]);\n #elif CC_LIGHT_2_TYPE == 1\n info2 = computePointLighting(s.position, cc_lightPositionAndRange[2], cc_lightColor[2]);\n #elif CC_LIGHT_2_TYPE == 2\n info2 = computeSpotLighting(s.position, cc_lightPositionAndRange[2], cc_lightDirection[2], cc_lightColor[2]);\n #endif\n Lighting result2 = brdf(s, info2);\n #if CC_USE_SHADOW_MAP && CC_NUM_SHADOW_LIGHTS > 2\n float shadow_2 = 1.0;\n vec2 projCoords2 = v_posLightSpace[2].xy / v_posLightSpace[2].w;\n vec2 shadowUV2 = projCoords2 * 0.5 + vec2(0.5);\n if (shadowUV2.x >= 0.0 && shadowUV2.x <= 1.0 && shadowUV2.y >= 0.0 && shadowUV2.y <= 1.0) {\n float currentDepth2 = clamp(v_depth[2], 0.0, 1.0);\n #if CC_SHADOW_2_TYPE == 3\n shadow_2 = shadowPCF3X3(cc_shadow_map_2, shadowUV2, currentDepth2, cc_shadow_info[2].w, cc_shadow_info[2].z);\n #elif CC_SHADOW_2_TYPE == 4\n shadow_2 = shadowPCF5X5(cc_shadow_map_2, shadowUV2, currentDepth2, cc_shadow_info[2].w, cc_shadow_info[2].z);\n #else\n shadow_2 = shadowSimple(cc_shadow_map_2, shadowUV2, currentDepth2, cc_shadow_info[2].w);\n #endif\n shadow_2 = computeFallOff(shadow_2, projCoords2, 0.0);\n }\n result2.diffuse *= shadow_2;\n result2.specular *= shadow_2;\n #endif\n result.diffuse += result2.diffuse;\n result.specular += result2.specular;\n #endif\n #endif\n #if CC_NUM_LIGHTS > 3\n #if CC_LIGHT_3_TYPE == 3\n result.diffuse += ambient(s, cc_lightColor[3]);\n #else\n LightInfo info3;\n #if CC_LIGHT_3_TYPE == 0\n info3 = computeDirectionalLighting(cc_lightDirection[3], cc_lightColor[3]);\n #elif CC_LIGHT_3_TYPE == 1\n info3 = computePointLighting(s.position, cc_lightPositionAndRange[3], cc_lightColor[3]);\n #elif CC_LIGHT_3_TYPE == 2\n info3 = computeSpotLighting(s.position, cc_lightPositionAndRange[3], cc_lightDirection[3], cc_lightColor[3]);\n #endif\n Lighting result3 = brdf(s, info3);\n #if CC_USE_SHADOW_MAP && CC_NUM_SHADOW_LIGHTS > 3\n float shadow_3 = 1.0;\n vec2 projCoords3 = v_posLightSpace[3].xy / v_posLightSpace[3].w;\n vec2 shadowUV3 = projCoords3 * 0.5 + vec2(0.5);\n if (shadowUV3.x >= 0.0 && shadowUV3.x <= 1.0 && shadowUV3.y >= 0.0 && shadowUV3.y <= 1.0) {\n float currentDepth3 = clamp(v_depth[3], 0.0, 1.0);\n #if CC_SHADOW_3_TYPE == 3\n shadow_3 = shadowPCF3X3(cc_shadow_map_3, shadowUV3, currentDepth3, cc_shadow_info[3].w, cc_shadow_info[3].z);\n #elif CC_SHADOW_3_TYPE == 4\n shadow_3 = shadowPCF5X5(cc_shadow_map_3, shadowUV3, currentDepth3, cc_shadow_info[3].w, cc_shadow_info[3].z);\n #else\n shadow_3 = shadowSimple(cc_shadow_map_3, shadowUV3, currentDepth3, cc_shadow_info[3].w);\n #endif\n shadow_3 = computeFallOff(shadow_3, projCoords3, 0.0);\n }\n result3.diffuse *= shadow_3;\n result3.specular *= shadow_3;\n #endif\n result.diffuse += result3.diffuse;\n result.specular += result3.specular;\n #endif\n #endif\n return composePhongShading(result, s);\n}\nvoid surf (out PhongSurface s) {\n vec4 diffuse = vec4(1, 1, 1, 1);\n #if CC_USE_ATTRIBUTE_COLOR\n diffuse *= v_color;\n #endif\n diffuse *= diffuseColor;\n #if USE_DIFFUSE_TEXTURE\n vec4 diffuseTexture_tmp = texture(diffuseTexture, v_uv0);\n #if CC_USE_ALPHA_ATLAS_diffuseTexture\n diffuseTexture_tmp.a *= texture(diffuseTexture, v_uv0 + vec2(0, 0.5)).r;\n #endif\n #if INPUT_IS_GAMMA\n diffuse.rgb *= (diffuseTexture_tmp.rgb * diffuseTexture_tmp.rgb);\n diffuse.a *= diffuseTexture_tmp.a;\n #else\n diffuse *= diffuseTexture_tmp;\n #endif\n #endif\n ALPHA_TEST(diffuse);\n s.diffuse = diffuse.rgb;\n s.opacity = diffuse.a;\n #if USE_EMISSIVE\n s.emissive = emissiveColor.rgb;\n #if USE_EMISSIVE_TEXTURE\n vec4 emissiveTexture_tmp = texture(emissiveTexture, v_uv0);\n #if CC_USE_ALPHA_ATLAS_emissiveTexture\n emissiveTexture_tmp.a *= texture(emissiveTexture, v_uv0 + vec2(0, 0.5)).r;\n #endif\n #if INPUT_IS_GAMMA\n s.emissive.rgb *= (emissiveTexture_tmp.rgb * emissiveTexture_tmp.rgb);\n #else\n s.emissive.rgb *= emissiveTexture_tmp.rgb;\n #endif\n #endif\n #endif\n #if USE_SPECULAR\n s.specular = specularColor.rgb;\n #if USE_SPECULAR_TEXTURE\n vec4 specularTexture_tmp = texture(specularTexture, v_uv0);\n #if CC_USE_ALPHA_ATLAS_specularTexture\n specularTexture_tmp.a *= texture(specularTexture, v_uv0 + vec2(0, 0.5)).r;\n #endif\n #if INPUT_IS_GAMMA\n s.specular.rgb *= (specularTexture_tmp.rgb * specularTexture_tmp.rgb);\n #else\n s.specular.rgb *= specularTexture_tmp.rgb;\n #endif\n #endif\n #endif\n s.normal = v_worldNormal;\n #if USE_NORMAL_TEXTURE\n vec3 nmmp = texture(normalTexture, v_uv0).xyz - vec3(0.5);\n s.normal =\n nmmp.x * normalize(v_tangent) +\n nmmp.y * normalize(v_bitangent) +\n nmmp.z * normalize(s.normal);\n s.normal = normalize(s.normal);\n #endif\n s.position = v_worldPos;\n s.viewDirection = v_viewDirection;\n s.glossiness = glossiness;\n}\nvoid main () {\n PhongSurface s;\n surf(s);\n vec4 color = CCPhongShading(s);\n gl_FragColor = CCFragOutput(color);\n}"
  122. },
  123. "glsl1": {
  124. "vert": "\nprecision highp float;\nuniform mat4 cc_matWorld;\nuniform mat4 cc_matWorldIT;\nuniform mat4 cc_matViewProj;\nuniform vec4 cc_cameraPos;\n#if CC_USE_SKINNING\n attribute vec4 a_weights;\n attribute vec4 a_joints;\n #if CC_USE_JOINTS_TEXTRUE\n uniform vec2 jointsTextureSize;\n uniform sampler2D jointsTexture;\n #if CC_JOINTS_TEXTURE_FLOAT32\n mat4 getBoneMatrix(const in float i) {\n float width = jointsTextureSize.x;\n float height = jointsTextureSize.y;\n float j = i * 4.0;\n float x = mod(j, width);\n float y = floor(j / width);\n float dx = 1.0 / width;\n float dy = 1.0 / height;\n y = dy * (y + 0.5);\n vec4 v1 = texture2D(jointsTexture, vec2(dx * (x + 0.5), y));\n vec4 v2 = texture2D(jointsTexture, vec2(dx * (x + 1.5), y));\n vec4 v3 = texture2D(jointsTexture, vec2(dx * (x + 2.5), y));\n vec4 v4 = texture2D(jointsTexture, vec2(dx * (x + 3.5), y));\n return mat4(v1, v2, v3, v4);\n }\n #else\n float decode32(vec4 rgba) {\n float Sign = 1.0 - step(128.0, rgba[0]) * 2.0;\n float Exponent = 2.0 * mod(rgba[0], 128.0) + step(128.0, rgba[1]) - 127.0;\n float Mantissa = mod(rgba[1], 128.0) * 65536.0 + rgba[2] * 256.0 + rgba[3] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\n }\n vec4 decodevec4 (vec4 x, vec4 y, vec4 z, vec4 w) {\n return vec4(\n decode32(x.wzyx * 255.0),\n decode32(y.wzyx * 255.0),\n decode32(z.wzyx * 255.0),\n decode32(w.wzyx * 255.0)\n );\n }\n vec4 decodevec4 (float dx, float x, float y) {\n return decodevec4(\n texture2D(jointsTexture, vec2(dx * (x + 0.5), y)),\n texture2D(jointsTexture, vec2(dx * (x + 1.5), y)),\n texture2D(jointsTexture, vec2(dx * (x + 2.5), y)),\n texture2D(jointsTexture, vec2(dx * (x + 3.5), y))\n );\n }\n mat4 getBoneMatrix(const in float i) {\n float width = jointsTextureSize.x;\n float height = jointsTextureSize.y;\n float j = i * 16.0;\n float x = mod(j, width);\n float y = floor(j / width);\n float dx = 1.0 / width;\n float dy = 1.0 / height;\n y = dy * (y + 0.5);\n vec4 v1 = decodevec4(dx, x, y);\n vec4 v2 = decodevec4(dx, x+4.0, y);\n vec4 v3 = decodevec4(dx, x+8.0, y);\n vec4 v4 = decodevec4(dx, x+12.0, y);\n return mat4(v1, v2, v3, v4);\n }\n #endif\n #else\n uniform mat4 jointMatrices[50];\n mat4 getBoneMatrix(const in float i) {\n return jointMatrices[int(i)];\n }\n #endif\n mat4 skinMatrix() {\n return\n getBoneMatrix(a_joints.x) * a_weights.x +\n getBoneMatrix(a_joints.y) * a_weights.y +\n getBoneMatrix(a_joints.z) * a_weights.z +\n getBoneMatrix(a_joints.w) * a_weights.w\n ;\n }\n#endif\nstruct StandardVertInput {\n vec2 uv;\n vec4 position;\n vec3 normal;\n vec4 tangent;\n vec4 color;\n};\nattribute vec3 a_position;\n#if CC_USE_ATTRIBUTE_UV0\nattribute vec2 a_uv0;\n#endif\n#if CC_USE_ATTRIBUTE_COLOR\nattribute vec4 a_color;\n#endif\n#if CC_USE_ATTRIBUTE_NORMAL\nattribute vec3 a_normal;\n#endif\n#if CC_USE_ATTRIBUTE_TANGENT\nattribute vec4 a_tangent;\n#endif\nvoid CCAttribute (out StandardVertInput In) {\n In.position = vec4(a_position, 1.0);\n #if CC_USE_ATTRIBUTE_UV0\n In.uv = a_uv0;\n #else\n In.uv = vec2(0.0);\n #endif\n #if CC_USE_ATTRIBUTE_COLOR\n In.color = a_color;\n #else\n In.color = vec4(1.0);\n #endif\n #if CC_USE_ATTRIBUTE_NORMAL\n In.normal = a_normal;\n #else\n In.normal = vec3(0.0, 1.0, 0.0);\n #endif\n #if CC_USE_ATTRIBUTE_TANGENT\n In.tangent = a_tangent;\n #else\n In.tangent = vec4(1.0, 0.0, 0.0, 0.0);\n #endif\n}\nvoid CCVertInput(out StandardVertInput In) {\n CCAttribute(In);\n #if CC_USE_SKINNING\n mat4 m = skinMatrix();\n In.position = m * In.position;\n #if CC_USE_ATTRIBUTE_NORMAL\n In.normal = (m * vec4(In.normal, 0)).xyz;\n #endif\n #if CC_USE_ATTRIBUTE_TANGENT\n In.tangent = m * In.tangent;\n #endif\n #endif\n}\n#if CC_USE_SHADOW_MAP && CC_NUM_SHADOW_LIGHTS > 0\n uniform mat4 cc_shadow_lightViewProjMatrix[2];\nuniform vec4 cc_shadow_info[2];\n #if CC_NUM_SHADOW_LIGHTS > 0\n uniform sampler2D cc_shadow_map_0;\n #endif\n #if CC_NUM_SHADOW_LIGHTS > 1\n uniform sampler2D cc_shadow_map_1;\n #endif\n varying vec4 v_posLightSpace[2];\n varying float v_depth[2];\n#endif\nvoid CCShadowInput (vec3 worldPos) {\n #if CC_USE_SHADOW_MAP && CC_NUM_SHADOW_LIGHTS > 0\n for (int i = 0; i < CC_NUM_SHADOW_LIGHTS; i++) {\n v_posLightSpace[i] = cc_shadow_lightViewProjMatrix[i] * vec4(worldPos, 1.0);\n v_depth[i] = (v_posLightSpace[i].z + cc_shadow_info[i].x) / (cc_shadow_info[i].x + cc_shadow_info[i].y);\n }\n #endif\n}\nuniform vec2 mainTiling;\nuniform vec2 mainOffset;\n#if CC_USE_ATTRIBUTE_UV0 && (USE_DIFFUSE_TEXTURE || USE_EMISSIVE_TEXTURE || USE_SPECULAR_TEXTURE || USE_NORMAL_TEXTURE)\n varying mediump vec2 v_uv0;\n#endif\n#if CC_USE_ATTRIBUTE_COLOR\n varying lowp vec4 v_color;\n#endif\n#if USE_NORMAL_TEXTURE\n varying vec3 v_tangent;\n varying vec3 v_bitangent;\n#endif\nvarying vec3 v_worldNormal;\nvarying vec3 v_worldPos;\nvarying vec3 v_viewDirection;\nvoid main () {\n StandardVertInput In;\n CCVertInput(In);\n vec4 position = In.position;\n v_worldNormal = normalize((cc_matWorldIT * vec4(In.normal, 0)).xyz);\n v_worldPos = (cc_matWorld * position).xyz;\n v_viewDirection = normalize(cc_cameraPos.xyz - v_worldPos);\n #if CC_USE_ATTRIBUTE_UV0 && (USE_DIFFUSE_TEXTURE || USE_EMISSIVE_TEXTURE || USE_SPECULAR_TEXTURE || USE_NORMAL_TEXTURE)\n v_uv0 = In.uv * mainTiling + mainOffset;\n #endif\n #if CC_USE_ATTRIBUTE_COLOR\n v_color = In.color;\n #endif\n #if USE_NORMAL_TEXTURE\n v_tangent = normalize((cc_matWorld * vec4(In.tangent.xyz, 0.0)).xyz);\n v_bitangent = cross(v_worldNormal, v_tangent) * In.tangent.w;\n #endif\n CCShadowInput(v_worldPos);\n gl_Position = cc_matViewProj * cc_matWorld * position;\n}",
  125. "frag": "\nprecision highp float;\nvec4 CCFragOutput (vec4 color) {\n #if OUTPUT_TO_GAMMA\n color.rgb = sqrt(color.rgb);\n #endif\n\treturn color;\n}\n#if USE_ALPHA_TEST\n uniform float alphaThreshold;\n#endif\nvoid ALPHA_TEST (in vec4 color) {\n #if USE_ALPHA_TEST\n if (color.a < alphaThreshold) discard;\n #endif\n}\nvoid ALPHA_TEST (in float alpha) {\n #if USE_ALPHA_TEST\n if (alpha < alphaThreshold) discard;\n #endif\n}\nuniform lowp vec4 diffuseColor;\nuniform lowp vec4 specularColor;\nuniform lowp vec4 emissiveColor;\nuniform float glossiness;\n#if USE_DIFFUSE_TEXTURE\n uniform sampler2D diffuseTexture;\n#endif\n#if USE_SPECULAR && USE_SPECULAR_TEXTURE\n uniform sampler2D specularTexture;\n#endif\n#if USE_EMISSIVE && USE_EMISSIVE_TEXTURE\n uniform sampler2D emissiveTexture;\n#endif\n#if USE_NORMAL_TEXTURE\n varying vec3 v_tangent;\n varying vec3 v_bitangent;\n uniform sampler2D normalTexture;\n#endif\nvarying vec3 v_worldNormal;\nvarying vec3 v_worldPos;\nvarying vec3 v_viewDirection;\n#if CC_USE_ATTRIBUTE_UV0 && (USE_DIFFUSE_TEXTURE || (USE_EMISSIVE && USE_EMISSIVE_TEXTURE) || (USE_SPECULAR && USE_SPECULAR_TEXTURE) || USE_NORMAL_TEXTURE)\n varying mediump vec2 v_uv0;\n#endif\n#if CC_USE_ATTRIBUTE_COLOR\n varying lowp vec4 v_color;\n#endif\n#if CC_USE_SHADOW_MAP && CC_NUM_SHADOW_LIGHTS > 0\n uniform vec4 cc_shadow_info[2];\n #if CC_NUM_SHADOW_LIGHTS > 0\n uniform sampler2D cc_shadow_map_0;\n #endif\n #if CC_NUM_SHADOW_LIGHTS > 1\n uniform sampler2D cc_shadow_map_1;\n #endif\n varying vec4 v_posLightSpace[2];\n varying float v_depth[2];\n#endif\nfloat unpackRGBAToDepth(vec4 color) {\n return dot(color, vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 160581375.0));\n}\nfloat getDepth(sampler2D shadowMap, vec2 shadowUV) {\n return unpackRGBAToDepth(texture2D(shadowMap, shadowUV));\n}\nfloat computeFallOff(float shadow, vec2 coords, float frustumEdgeFalloff) {\n return shadow;\n}\nfloat shadowSimple(sampler2D shadowMap, vec2 shadowUV, float currentDepth, float darkness) {\n float closestDepth = getDepth(shadowMap, shadowUV);\n return currentDepth > closestDepth ? 1.0 - darkness : 1.0;\n}\nfloat shadowPCF3X3(sampler2D shadowMap, vec2 shadowUV, float currentDepth, float darkness, float shadowSize) {\n float shadow = 0.0;\n for (int x = -1; x <= 1; ++x) {\n for (int y = -1; y <= 1; ++y) {\n float closestDepth = getDepth(shadowMap, shadowUV + vec2(x, y) * 1.0/shadowSize);\n shadow += currentDepth > closestDepth ? 1.0 - darkness : 1.0;\n }\n }\n shadow /= 9.0;\n return shadow;\n}\nfloat shadowPCF5X5(sampler2D shadowMap, vec2 shadowUV, float currentDepth, float darkness, float shadowSize) {\n float shadow = 0.0;\n for (int x = -2; x <= 2; ++x) {\n for (int y = -2; y <= 2; ++y) {\n float closestDepth = getDepth(shadowMap, shadowUV + vec2(x, y) * 1.0/shadowSize);\n shadow += currentDepth > closestDepth ? 1.0 - darkness : 1.0;\n }\n }\n shadow /= 25.0;\n return shadow;\n}\n#if CC_NUM_LIGHTS > 0\nuniform vec4 cc_lightPositionAndRange[4];\nuniform vec4 cc_lightDirection[4];\nuniform vec4 cc_lightColor[4];\n#endif\nstruct LightInfo {\n vec3 lightDir;\n vec3 radiance;\n vec4 lightColor;\n};\nLightInfo computeDirectionalLighting(\n vec4 lightDirection,\n vec4 lightColor\n) {\n LightInfo ret;\n ret.lightDir = -normalize(lightDirection.xyz);\n ret.radiance = lightColor.rgb;\n ret.lightColor = lightColor;\n return ret;\n}\nLightInfo computePointLighting(\n vec3 worldPosition,\n vec4 lightPositionAndRange,\n vec4 lightColor\n) {\n LightInfo ret;\n vec3 lightDir = lightPositionAndRange.xyz - worldPosition;\n float attenuation = max(0., 1.0 - length(lightDir) / lightPositionAndRange.w);\n ret.lightDir = normalize(lightDir);\n ret.radiance = lightColor.rgb * attenuation;\n ret.lightColor = lightColor;\n return ret;\n}\nLightInfo computeSpotLighting(\n vec3 worldPosition,\n vec4 lightPositionAndRange,\n vec4 lightDirection,\n vec4 lightColor\n) {\n LightInfo ret;\n vec3 lightDir = lightPositionAndRange.xyz - worldPosition;\n float attenuation = max(0., 1.0 - length(lightDir) / lightPositionAndRange.w);\n lightDir = normalize(lightDir);\n float cosConeAngle = max(0., dot(lightDirection.xyz, -lightDir));\n cosConeAngle = cosConeAngle < lightDirection.w ? 0. : cosConeAngle;\n cosConeAngle = pow(cosConeAngle, lightColor.w);\n ret.lightDir = lightDir;\n ret.radiance = lightColor.rgb * attenuation * cosConeAngle;\n ret.lightColor = lightColor;\n return ret;\n}\nstruct Lighting {\n vec3 diffuse;\n vec3 specular;\n};\nstruct PhongSurface {\n vec3 diffuse;\n vec3 emissive;\n vec3 specular;\n float opacity;\n float glossiness;\n vec3 position;\n vec3 normal;\n vec3 viewDirection;\n};\nLighting brdf (PhongSurface s, LightInfo info) {\n Lighting result;\n float ndh = 0.0;\n vec3 halfDir = normalize(s.viewDirection + info.lightDir);\n float NdotH = max(0.0, dot(s.normal, halfDir));\n NdotH = pow(NdotH, max(1.0, s.glossiness * 128.0));\n result.diffuse = info.radiance * max(0.0, dot(s.normal, info.lightDir));\n result.specular = info.radiance * NdotH;\n return result;\n}\nvec4 composePhongShading (Lighting lighting, PhongSurface s) {\n vec4 o = vec4(0.0, 0.0, 0.0, 1.0);\n o.rgb = lighting.diffuse * s.diffuse;\n #if USE_EMISSIVE\n o.rgb += s.emissive;\n #endif\n #if USE_SPECULAR\n o.rgb += lighting.specular * s.specular;\n #endif\n o.a = s.opacity;\n return o;\n}\nvec3 ambient(PhongSurface s, vec4 ambientColor) {\n return s.diffuse * ambientColor.rgb;\n}\nvec4 CCPhongShading (in PhongSurface s) {\n Lighting result;\n result.diffuse = vec3(0, 0, 0);\n result.specular = vec3(0, 0, 0);\n #if CC_NUM_LIGHTS > 0\n #if CC_LIGHT_0_TYPE == 3\n result.diffuse += ambient(s, cc_lightColor[0]);\n #else\n LightInfo info0;\n #if CC_LIGHT_0_TYPE == 0\n info0 = computeDirectionalLighting(cc_lightDirection[0], cc_lightColor[0]);\n #elif CC_LIGHT_0_TYPE == 1\n info0 = computePointLighting(s.position, cc_lightPositionAndRange[0], cc_lightColor[0]);\n #elif CC_LIGHT_0_TYPE == 2\n info0 = computeSpotLighting(s.position, cc_lightPositionAndRange[0], cc_lightDirection[0], cc_lightColor[0]);\n #endif\n Lighting result0 = brdf(s, info0);\n #if CC_USE_SHADOW_MAP && CC_NUM_SHADOW_LIGHTS > 0\n float shadow_0 = 1.0;\n vec2 projCoords0 = v_posLightSpace[0].xy / v_posLightSpace[0].w;\n vec2 shadowUV0 = projCoords0 * 0.5 + vec2(0.5);\n if (shadowUV0.x >= 0.0 && shadowUV0.x <= 1.0 && shadowUV0.y >= 0.0 && shadowUV0.y <= 1.0) {\n float currentDepth0 = clamp(v_depth[0], 0.0, 1.0);\n #if CC_SHADOW_0_TYPE == 3\n shadow_0 = shadowPCF3X3(cc_shadow_map_0, shadowUV0, currentDepth0, cc_shadow_info[0].w, cc_shadow_info[0].z);\n #elif CC_SHADOW_0_TYPE == 4\n shadow_0 = shadowPCF5X5(cc_shadow_map_0, shadowUV0, currentDepth0, cc_shadow_info[0].w, cc_shadow_info[0].z);\n #else\n shadow_0 = shadowSimple(cc_shadow_map_0, shadowUV0, currentDepth0, cc_shadow_info[0].w);\n #endif\n shadow_0 = computeFallOff(shadow_0, projCoords0, 0.0);\n }\n result0.diffuse *= shadow_0;\n result0.specular *= shadow_0;\n #endif\n result.diffuse += result0.diffuse;\n result.specular += result0.specular;\n #endif\n #endif\n #if CC_NUM_LIGHTS > 1\n #if CC_LIGHT_1_TYPE == 3\n result.diffuse += ambient(s, cc_lightColor[1]);\n #else\n LightInfo info1;\n #if CC_LIGHT_1_TYPE == 0\n info1 = computeDirectionalLighting(cc_lightDirection[1], cc_lightColor[1]);\n #elif CC_LIGHT_1_TYPE == 1\n info1 = computePointLighting(s.position, cc_lightPositionAndRange[1], cc_lightColor[1]);\n #elif CC_LIGHT_1_TYPE == 2\n info1 = computeSpotLighting(s.position, cc_lightPositionAndRange[1], cc_lightDirection[1], cc_lightColor[1]);\n #endif\n Lighting result1 = brdf(s, info1);\n #if CC_USE_SHADOW_MAP && CC_NUM_SHADOW_LIGHTS > 1\n float shadow_1 = 1.0;\n vec2 projCoords1 = v_posLightSpace[1].xy / v_posLightSpace[1].w;\n vec2 shadowUV1 = projCoords1 * 0.5 + vec2(0.5);\n if (shadowUV1.x >= 0.0 && shadowUV1.x <= 1.0 && shadowUV1.y >= 0.0 && shadowUV1.y <= 1.0) {\n float currentDepth1 = clamp(v_depth[1], 0.0, 1.0);\n #if CC_SHADOW_1_TYPE == 3\n shadow_1 = shadowPCF3X3(cc_shadow_map_1, shadowUV1, currentDepth1, cc_shadow_info[1].w, cc_shadow_info[1].z);\n #elif CC_SHADOW_1_TYPE == 4\n shadow_1 = shadowPCF5X5(cc_shadow_map_1, shadowUV1, currentDepth1, cc_shadow_info[1].w, cc_shadow_info[1].z);\n #else\n shadow_1 = shadowSimple(cc_shadow_map_1, shadowUV1, currentDepth1, cc_shadow_info[1].w);\n #endif\n shadow_1 = computeFallOff(shadow_1, projCoords1, 0.0);\n }\n result1.diffuse *= shadow_1;\n result1.specular *= shadow_1;\n #endif\n result.diffuse += result1.diffuse;\n result.specular += result1.specular;\n #endif\n #endif\n #if CC_NUM_LIGHTS > 2\n #if CC_LIGHT_2_TYPE == 3\n result.diffuse += ambient(s, cc_lightColor[2]);\n #else\n LightInfo info2;\n #if CC_LIGHT_2_TYPE == 0\n info2 = computeDirectionalLighting(cc_lightDirection[2], cc_lightColor[2]);\n #elif CC_LIGHT_2_TYPE == 1\n info2 = computePointLighting(s.position, cc_lightPositionAndRange[2], cc_lightColor[2]);\n #elif CC_LIGHT_2_TYPE == 2\n info2 = computeSpotLighting(s.position, cc_lightPositionAndRange[2], cc_lightDirection[2], cc_lightColor[2]);\n #endif\n Lighting result2 = brdf(s, info2);\n #if CC_USE_SHADOW_MAP && CC_NUM_SHADOW_LIGHTS > 2\n float shadow_2 = 1.0;\n vec2 projCoords2 = v_posLightSpace[2].xy / v_posLightSpace[2].w;\n vec2 shadowUV2 = projCoords2 * 0.5 + vec2(0.5);\n if (shadowUV2.x >= 0.0 && shadowUV2.x <= 1.0 && shadowUV2.y >= 0.0 && shadowUV2.y <= 1.0) {\n float currentDepth2 = clamp(v_depth[2], 0.0, 1.0);\n #if CC_SHADOW_2_TYPE == 3\n shadow_2 = shadowPCF3X3(cc_shadow_map_2, shadowUV2, currentDepth2, cc_shadow_info[2].w, cc_shadow_info[2].z);\n #elif CC_SHADOW_2_TYPE == 4\n shadow_2 = shadowPCF5X5(cc_shadow_map_2, shadowUV2, currentDepth2, cc_shadow_info[2].w, cc_shadow_info[2].z);\n #else\n shadow_2 = shadowSimple(cc_shadow_map_2, shadowUV2, currentDepth2, cc_shadow_info[2].w);\n #endif\n shadow_2 = computeFallOff(shadow_2, projCoords2, 0.0);\n }\n result2.diffuse *= shadow_2;\n result2.specular *= shadow_2;\n #endif\n result.diffuse += result2.diffuse;\n result.specular += result2.specular;\n #endif\n #endif\n #if CC_NUM_LIGHTS > 3\n #if CC_LIGHT_3_TYPE == 3\n result.diffuse += ambient(s, cc_lightColor[3]);\n #else\n LightInfo info3;\n #if CC_LIGHT_3_TYPE == 0\n info3 = computeDirectionalLighting(cc_lightDirection[3], cc_lightColor[3]);\n #elif CC_LIGHT_3_TYPE == 1\n info3 = computePointLighting(s.position, cc_lightPositionAndRange[3], cc_lightColor[3]);\n #elif CC_LIGHT_3_TYPE == 2\n info3 = computeSpotLighting(s.position, cc_lightPositionAndRange[3], cc_lightDirection[3], cc_lightColor[3]);\n #endif\n Lighting result3 = brdf(s, info3);\n #if CC_USE_SHADOW_MAP && CC_NUM_SHADOW_LIGHTS > 3\n float shadow_3 = 1.0;\n vec2 projCoords3 = v_posLightSpace[3].xy / v_posLightSpace[3].w;\n vec2 shadowUV3 = projCoords3 * 0.5 + vec2(0.5);\n if (shadowUV3.x >= 0.0 && shadowUV3.x <= 1.0 && shadowUV3.y >= 0.0 && shadowUV3.y <= 1.0) {\n float currentDepth3 = clamp(v_depth[3], 0.0, 1.0);\n #if CC_SHADOW_3_TYPE == 3\n shadow_3 = shadowPCF3X3(cc_shadow_map_3, shadowUV3, currentDepth3, cc_shadow_info[3].w, cc_shadow_info[3].z);\n #elif CC_SHADOW_3_TYPE == 4\n shadow_3 = shadowPCF5X5(cc_shadow_map_3, shadowUV3, currentDepth3, cc_shadow_info[3].w, cc_shadow_info[3].z);\n #else\n shadow_3 = shadowSimple(cc_shadow_map_3, shadowUV3, currentDepth3, cc_shadow_info[3].w);\n #endif\n shadow_3 = computeFallOff(shadow_3, projCoords3, 0.0);\n }\n result3.diffuse *= shadow_3;\n result3.specular *= shadow_3;\n #endif\n result.diffuse += result3.diffuse;\n result.specular += result3.specular;\n #endif\n #endif\n return composePhongShading(result, s);\n}\nvoid surf (out PhongSurface s) {\n vec4 diffuse = vec4(1, 1, 1, 1);\n #if CC_USE_ATTRIBUTE_COLOR\n diffuse *= v_color;\n #endif\n diffuse *= diffuseColor;\n #if USE_DIFFUSE_TEXTURE\n vec4 diffuseTexture_tmp = texture2D(diffuseTexture, v_uv0);\n #if CC_USE_ALPHA_ATLAS_diffuseTexture\n diffuseTexture_tmp.a *= texture2D(diffuseTexture, v_uv0 + vec2(0, 0.5)).r;\n #endif\n #if INPUT_IS_GAMMA\n diffuse.rgb *= (diffuseTexture_tmp.rgb * diffuseTexture_tmp.rgb);\n diffuse.a *= diffuseTexture_tmp.a;\n #else\n diffuse *= diffuseTexture_tmp;\n #endif\n #endif\n ALPHA_TEST(diffuse);\n s.diffuse = diffuse.rgb;\n s.opacity = diffuse.a;\n #if USE_EMISSIVE\n s.emissive = emissiveColor.rgb;\n #if USE_EMISSIVE_TEXTURE\n vec4 emissiveTexture_tmp = texture2D(emissiveTexture, v_uv0);\n #if CC_USE_ALPHA_ATLAS_emissiveTexture\n emissiveTexture_tmp.a *= texture2D(emissiveTexture, v_uv0 + vec2(0, 0.5)).r;\n #endif\n #if INPUT_IS_GAMMA\n s.emissive.rgb *= (emissiveTexture_tmp.rgb * emissiveTexture_tmp.rgb);\n #else\n s.emissive.rgb *= emissiveTexture_tmp.rgb;\n #endif\n #endif\n #endif\n #if USE_SPECULAR\n s.specular = specularColor.rgb;\n #if USE_SPECULAR_TEXTURE\n vec4 specularTexture_tmp = texture2D(specularTexture, v_uv0);\n #if CC_USE_ALPHA_ATLAS_specularTexture\n specularTexture_tmp.a *= texture2D(specularTexture, v_uv0 + vec2(0, 0.5)).r;\n #endif\n #if INPUT_IS_GAMMA\n s.specular.rgb *= (specularTexture_tmp.rgb * specularTexture_tmp.rgb);\n #else\n s.specular.rgb *= specularTexture_tmp.rgb;\n #endif\n #endif\n #endif\n s.normal = v_worldNormal;\n #if USE_NORMAL_TEXTURE\n vec3 nmmp = texture2D(normalTexture, v_uv0).xyz - vec3(0.5);\n s.normal =\n nmmp.x * normalize(v_tangent) +\n nmmp.y * normalize(v_bitangent) +\n nmmp.z * normalize(s.normal);\n s.normal = normalize(s.normal);\n #endif\n s.position = v_worldPos;\n s.viewDirection = v_viewDirection;\n s.glossiness = glossiness;\n}\nvoid main () {\n PhongSurface s;\n surf(s);\n vec4 color = CCPhongShading(s);\n gl_FragColor = CCFragOutput(color);\n}"
  126. },
  127. "builtins": {
  128. "globals": {
  129. "blocks": [
  130. {
  131. "name": "CCGlobal",
  132. "defines": []
  133. },
  134. {
  135. "name": "CC_SHADOW",
  136. "defines": [
  137. "CC_USE_SHADOW_MAP",
  138. "CC_NUM_SHADOW_LIGHTS"
  139. ]
  140. },
  141. {
  142. "name": "CCLIGHTS",
  143. "defines": [
  144. "CC_NUM_LIGHTS"
  145. ]
  146. }
  147. ],
  148. "samplers": [
  149. {
  150. "name": "cc_shadow_map_0",
  151. "defines": [
  152. "CC_USE_SHADOW_MAP",
  153. "CC_NUM_SHADOW_LIGHTS"
  154. ]
  155. },
  156. {
  157. "name": "cc_shadow_map_1",
  158. "defines": [
  159. "CC_USE_SHADOW_MAP",
  160. "CC_NUM_SHADOW_LIGHTS"
  161. ]
  162. }
  163. ]
  164. },
  165. "locals": {
  166. "blocks": [
  167. {
  168. "name": "CCLocal",
  169. "defines": []
  170. }
  171. ],
  172. "samplers": []
  173. }
  174. },
  175. "defines": [
  176. {
  177. "name": "CC_USE_SKINNING",
  178. "type": "boolean",
  179. "defines": []
  180. },
  181. {
  182. "name": "CC_USE_JOINTS_TEXTRUE",
  183. "type": "boolean",
  184. "defines": [
  185. "CC_USE_SKINNING"
  186. ]
  187. },
  188. {
  189. "name": "CC_JOINTS_TEXTURE_FLOAT32",
  190. "type": "boolean",
  191. "defines": [
  192. "CC_USE_SKINNING",
  193. "CC_USE_JOINTS_TEXTRUE"
  194. ]
  195. },
  196. {
  197. "name": "CC_USE_ATTRIBUTE_UV0",
  198. "type": "boolean",
  199. "defines": []
  200. },
  201. {
  202. "name": "CC_USE_ATTRIBUTE_COLOR",
  203. "type": "boolean",
  204. "defines": []
  205. },
  206. {
  207. "name": "CC_USE_ATTRIBUTE_NORMAL",
  208. "type": "boolean",
  209. "defines": []
  210. },
  211. {
  212. "name": "CC_USE_ATTRIBUTE_TANGENT",
  213. "type": "boolean",
  214. "defines": []
  215. },
  216. {
  217. "name": "CC_USE_SHADOW_MAP",
  218. "type": "boolean",
  219. "defines": []
  220. },
  221. {
  222. "name": "CC_NUM_SHADOW_LIGHTS",
  223. "type": "number",
  224. "defines": [
  225. "CC_USE_SHADOW_MAP"
  226. ],
  227. "range": [
  228. 0,
  229. 3
  230. ]
  231. },
  232. {
  233. "name": "USE_DIFFUSE_TEXTURE",
  234. "type": "boolean",
  235. "defines": []
  236. },
  237. {
  238. "name": "USE_NORMAL_TEXTURE",
  239. "type": "boolean",
  240. "defines": []
  241. },
  242. {
  243. "name": "OUTPUT_TO_GAMMA",
  244. "type": "boolean",
  245. "defines": []
  246. },
  247. {
  248. "name": "USE_ALPHA_TEST",
  249. "type": "boolean",
  250. "defines": []
  251. },
  252. {
  253. "name": "USE_SPECULAR",
  254. "type": "boolean",
  255. "defines": []
  256. },
  257. {
  258. "name": "USE_SPECULAR_TEXTURE",
  259. "type": "boolean",
  260. "defines": [
  261. "USE_SPECULAR"
  262. ]
  263. },
  264. {
  265. "name": "USE_EMISSIVE",
  266. "type": "boolean",
  267. "defines": []
  268. },
  269. {
  270. "name": "USE_EMISSIVE_TEXTURE",
  271. "type": "boolean",
  272. "defines": [
  273. "USE_EMISSIVE"
  274. ]
  275. },
  276. {
  277. "name": "CC_NUM_LIGHTS",
  278. "type": "number",
  279. "defines": [],
  280. "range": [
  281. 0,
  282. 3
  283. ]
  284. },
  285. {
  286. "name": "CC_LIGHT_0_TYPE",
  287. "type": "number",
  288. "defines": [
  289. "CC_NUM_LIGHTS"
  290. ],
  291. "range": [
  292. 0,
  293. 3
  294. ]
  295. },
  296. {
  297. "name": "CC_SHADOW_0_TYPE",
  298. "type": "number",
  299. "defines": [
  300. "CC_NUM_LIGHTS",
  301. "CC_USE_SHADOW_MAP",
  302. "CC_NUM_SHADOW_LIGHTS"
  303. ],
  304. "range": [
  305. 0,
  306. 3
  307. ]
  308. },
  309. {
  310. "name": "CC_LIGHT_1_TYPE",
  311. "type": "number",
  312. "defines": [
  313. "CC_NUM_LIGHTS"
  314. ],
  315. "range": [
  316. 0,
  317. 3
  318. ]
  319. },
  320. {
  321. "name": "CC_SHADOW_1_TYPE",
  322. "type": "number",
  323. "defines": [
  324. "CC_NUM_LIGHTS",
  325. "CC_USE_SHADOW_MAP",
  326. "CC_NUM_SHADOW_LIGHTS"
  327. ],
  328. "range": [
  329. 0,
  330. 3
  331. ]
  332. },
  333. {
  334. "name": "CC_LIGHT_2_TYPE",
  335. "type": "number",
  336. "defines": [
  337. "CC_NUM_LIGHTS"
  338. ],
  339. "range": [
  340. 0,
  341. 3
  342. ]
  343. },
  344. {
  345. "name": "CC_SHADOW_2_TYPE",
  346. "type": "number",
  347. "defines": [
  348. "CC_NUM_LIGHTS",
  349. "CC_USE_SHADOW_MAP",
  350. "CC_NUM_SHADOW_LIGHTS"
  351. ],
  352. "range": [
  353. 0,
  354. 3
  355. ]
  356. },
  357. {
  358. "name": "CC_LIGHT_3_TYPE",
  359. "type": "number",
  360. "defines": [
  361. "CC_NUM_LIGHTS"
  362. ],
  363. "range": [
  364. 0,
  365. 3
  366. ]
  367. },
  368. {
  369. "name": "CC_SHADOW_3_TYPE",
  370. "type": "number",
  371. "defines": [
  372. "CC_NUM_LIGHTS",
  373. "CC_USE_SHADOW_MAP",
  374. "CC_NUM_SHADOW_LIGHTS"
  375. ],
  376. "range": [
  377. 0,
  378. 3
  379. ]
  380. },
  381. {
  382. "name": "CC_USE_ALPHA_ATLAS_diffuseTexture",
  383. "type": "boolean",
  384. "defines": [
  385. "USE_DIFFUSE_TEXTURE"
  386. ]
  387. },
  388. {
  389. "name": "INPUT_IS_GAMMA",
  390. "type": "boolean",
  391. "defines": [
  392. "USE_DIFFUSE_TEXTURE"
  393. ]
  394. },
  395. {
  396. "name": "CC_USE_ALPHA_ATLAS_emissiveTexture",
  397. "type": "boolean",
  398. "defines": [
  399. "USE_EMISSIVE",
  400. "USE_EMISSIVE_TEXTURE"
  401. ]
  402. },
  403. {
  404. "name": "CC_USE_ALPHA_ATLAS_specularTexture",
  405. "type": "boolean",
  406. "defines": [
  407. "USE_SPECULAR",
  408. "USE_SPECULAR_TEXTURE"
  409. ]
  410. }
  411. ],
  412. "blocks": [
  413. {
  414. "name": "SKINNING",
  415. "members": [
  416. {
  417. "name": "jointsTextureSize",
  418. "type": 14,
  419. "count": 1
  420. }
  421. ],
  422. "defines": [
  423. "CC_USE_SKINNING",
  424. "CC_USE_JOINTS_TEXTRUE"
  425. ],
  426. "binding": 0
  427. },
  428. {
  429. "name": "JOINT_MATRIX",
  430. "members": [
  431. {
  432. "name": "jointMatrices",
  433. "type": 26,
  434. "count": 50
  435. }
  436. ],
  437. "defines": [
  438. "CC_USE_SKINNING"
  439. ],
  440. "binding": 1
  441. },
  442. {
  443. "name": "MAIN_TILING",
  444. "members": [
  445. {
  446. "name": "mainTiling",
  447. "type": 14,
  448. "count": 1
  449. },
  450. {
  451. "name": "mainOffset",
  452. "type": 14,
  453. "count": 1
  454. }
  455. ],
  456. "defines": [],
  457. "binding": 2
  458. },
  459. {
  460. "name": "ALPHA_TEST",
  461. "members": [
  462. {
  463. "name": "alphaThreshold",
  464. "type": 13,
  465. "count": 1
  466. }
  467. ],
  468. "defines": [
  469. "USE_ALPHA_TEST"
  470. ],
  471. "binding": 3
  472. },
  473. {
  474. "name": "PhongFrag",
  475. "members": [
  476. {
  477. "name": "diffuseColor",
  478. "type": 16,
  479. "count": 1
  480. },
  481. {
  482. "name": "specularColor",
  483. "type": 16,
  484. "count": 1
  485. },
  486. {
  487. "name": "emissiveColor",
  488. "type": 16,
  489. "count": 1
  490. },
  491. {
  492. "name": "glossiness",
  493. "type": 13,
  494. "count": 1
  495. }
  496. ],
  497. "defines": [],
  498. "binding": 4
  499. }
  500. ],
  501. "samplers": [
  502. {
  503. "name": "jointsTexture",
  504. "type": 29,
  505. "count": 1,
  506. "defines": [
  507. "CC_USE_SKINNING",
  508. "CC_USE_JOINTS_TEXTRUE"
  509. ],
  510. "binding": 30
  511. },
  512. {
  513. "name": "diffuseTexture",
  514. "type": 29,
  515. "count": 1,
  516. "defines": [
  517. "USE_DIFFUSE_TEXTURE"
  518. ],
  519. "binding": 31
  520. },
  521. {
  522. "name": "specularTexture",
  523. "type": 29,
  524. "count": 1,
  525. "defines": [
  526. "USE_SPECULAR",
  527. "USE_SPECULAR_TEXTURE"
  528. ],
  529. "binding": 32
  530. },
  531. {
  532. "name": "emissiveTexture",
  533. "type": 29,
  534. "count": 1,
  535. "defines": [
  536. "USE_EMISSIVE",
  537. "USE_EMISSIVE_TEXTURE"
  538. ],
  539. "binding": 33
  540. },
  541. {
  542. "name": "normalTexture",
  543. "type": 29,
  544. "count": 1,
  545. "defines": [
  546. "USE_NORMAL_TEXTURE"
  547. ],
  548. "binding": 34
  549. }
  550. ],
  551. "record": null,
  552. "name": "builtin-phong|phong-vs|phong-fs"
  553. },
  554. {
  555. "hash": 1165371292,
  556. "glsl3": {
  557. "vert": "\nprecision highp float;\nin vec3 a_position;\nuniform CCLocal {\n mat4 cc_matWorld;\n mat4 cc_matWorldIT;\n};\nuniform CC_SHADOW_MAP {\n mat4 cc_shadow_map_lightViewProjMatrix;\n vec4 cc_shadow_map_info;\n float cc_shadow_map_bias;\n};\nout float v_depth;\n#if CC_USE_SKINNING\n in vec4 a_weights;\n in vec4 a_joints;\n #if CC_USE_JOINTS_TEXTRUE\n uniform SKINNING {\n vec2 jointsTextureSize;\n };\n uniform sampler2D jointsTexture;\n #if CC_JOINTS_TEXTURE_FLOAT32\n mat4 getBoneMatrix(const in float i) {\n float width = jointsTextureSize.x;\n float height = jointsTextureSize.y;\n float j = i * 4.0;\n float x = mod(j, width);\n float y = floor(j / width);\n float dx = 1.0 / width;\n float dy = 1.0 / height;\n y = dy * (y + 0.5);\n vec4 v1 = texture(jointsTexture, vec2(dx * (x + 0.5), y));\n vec4 v2 = texture(jointsTexture, vec2(dx * (x + 1.5), y));\n vec4 v3 = texture(jointsTexture, vec2(dx * (x + 2.5), y));\n vec4 v4 = texture(jointsTexture, vec2(dx * (x + 3.5), y));\n return mat4(v1, v2, v3, v4);\n }\n #else\n float decode32(vec4 rgba) {\n float Sign = 1.0 - step(128.0, rgba[0]) * 2.0;\n float Exponent = 2.0 * mod(rgba[0], 128.0) + step(128.0, rgba[1]) - 127.0;\n float Mantissa = mod(rgba[1], 128.0) * 65536.0 + rgba[2] * 256.0 + rgba[3] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\n }\n vec4 decodevec4 (vec4 x, vec4 y, vec4 z, vec4 w) {\n return vec4(\n decode32(x.wzyx * 255.0),\n decode32(y.wzyx * 255.0),\n decode32(z.wzyx * 255.0),\n decode32(w.wzyx * 255.0)\n );\n }\n vec4 decodevec4 (float dx, float x, float y) {\n return decodevec4(\n texture(jointsTexture, vec2(dx * (x + 0.5), y)),\n texture(jointsTexture, vec2(dx * (x + 1.5), y)),\n texture(jointsTexture, vec2(dx * (x + 2.5), y)),\n texture(jointsTexture, vec2(dx * (x + 3.5), y))\n );\n }\n mat4 getBoneMatrix(const in float i) {\n float width = jointsTextureSize.x;\n float height = jointsTextureSize.y;\n float j = i * 16.0;\n float x = mod(j, width);\n float y = floor(j / width);\n float dx = 1.0 / width;\n float dy = 1.0 / height;\n y = dy * (y + 0.5);\n vec4 v1 = decodevec4(dx, x, y);\n vec4 v2 = decodevec4(dx, x+4.0, y);\n vec4 v3 = decodevec4(dx, x+8.0, y);\n vec4 v4 = decodevec4(dx, x+12.0, y);\n return mat4(v1, v2, v3, v4);\n }\n #endif\n #else\n uniform JOINT_MATRIX {\n mat4 jointMatrices[50];\n };\n mat4 getBoneMatrix(const in float i) {\n return jointMatrices[int(i)];\n }\n #endif\n mat4 skinMatrix() {\n return\n getBoneMatrix(a_joints.x) * a_weights.x +\n getBoneMatrix(a_joints.y) * a_weights.y +\n getBoneMatrix(a_joints.z) * a_weights.z +\n getBoneMatrix(a_joints.w) * a_weights.w\n ;\n }\n#endif\nvoid SKIN_VERTEX(inout vec4 a1) {\n #if CC_USE_SKINNING\n mat4 m = skinMatrix();\n a1 = m * a1;\n #endif\n}\nvoid SKIN_VERTEX(inout vec4 a1, inout vec4 a2) {\n #if CC_USE_SKINNING\n mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n #endif\n}\nvoid SKIN_VERTEX(inout vec4 a1, inout vec4 a2, inout vec4 a3) {\n #if CC_USE_SKINNING\n mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n a3 = m * a3;\n #endif\n}\nvoid main () {\n vec4 position = vec4(a_position, 1);\n SKIN_VERTEX(position);\n gl_Position = cc_shadow_map_lightViewProjMatrix * cc_matWorld * position;\n v_depth = ((gl_Position.z + cc_shadow_map_info.x) / (cc_shadow_map_info.x + cc_shadow_map_info.y)) + cc_shadow_map_bias;\n}",
  558. "frag": "\nprecision highp float;\nin float v_depth;\nvec4 packDepthToRGBA(float depth) {\n vec4 ret = vec4(1.0, 255.0, 65025.0, 160581375.0) * depth;\n ret = fract(ret);\n ret -= ret.yzww * vec4(1.0 / 255.0, 1.0 / 255.0, 1.0 / 255.0, 0.0);\n return ret;\n}\nvoid main () {\n gl_FragColor = packDepthToRGBA(v_depth);\n}"
  559. },
  560. "glsl1": {
  561. "vert": "\nprecision highp float;\nattribute vec3 a_position;\nuniform mat4 cc_matWorld;\nuniform mat4 cc_shadow_map_lightViewProjMatrix;\nuniform vec4 cc_shadow_map_info;\nuniform float cc_shadow_map_bias;\nvarying float v_depth;\n#if CC_USE_SKINNING\n attribute vec4 a_weights;\n attribute vec4 a_joints;\n #if CC_USE_JOINTS_TEXTRUE\n uniform vec2 jointsTextureSize;\n uniform sampler2D jointsTexture;\n #if CC_JOINTS_TEXTURE_FLOAT32\n mat4 getBoneMatrix(const in float i) {\n float width = jointsTextureSize.x;\n float height = jointsTextureSize.y;\n float j = i * 4.0;\n float x = mod(j, width);\n float y = floor(j / width);\n float dx = 1.0 / width;\n float dy = 1.0 / height;\n y = dy * (y + 0.5);\n vec4 v1 = texture2D(jointsTexture, vec2(dx * (x + 0.5), y));\n vec4 v2 = texture2D(jointsTexture, vec2(dx * (x + 1.5), y));\n vec4 v3 = texture2D(jointsTexture, vec2(dx * (x + 2.5), y));\n vec4 v4 = texture2D(jointsTexture, vec2(dx * (x + 3.5), y));\n return mat4(v1, v2, v3, v4);\n }\n #else\n float decode32(vec4 rgba) {\n float Sign = 1.0 - step(128.0, rgba[0]) * 2.0;\n float Exponent = 2.0 * mod(rgba[0], 128.0) + step(128.0, rgba[1]) - 127.0;\n float Mantissa = mod(rgba[1], 128.0) * 65536.0 + rgba[2] * 256.0 + rgba[3] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\n }\n vec4 decodevec4 (vec4 x, vec4 y, vec4 z, vec4 w) {\n return vec4(\n decode32(x.wzyx * 255.0),\n decode32(y.wzyx * 255.0),\n decode32(z.wzyx * 255.0),\n decode32(w.wzyx * 255.0)\n );\n }\n vec4 decodevec4 (float dx, float x, float y) {\n return decodevec4(\n texture2D(jointsTexture, vec2(dx * (x + 0.5), y)),\n texture2D(jointsTexture, vec2(dx * (x + 1.5), y)),\n texture2D(jointsTexture, vec2(dx * (x + 2.5), y)),\n texture2D(jointsTexture, vec2(dx * (x + 3.5), y))\n );\n }\n mat4 getBoneMatrix(const in float i) {\n float width = jointsTextureSize.x;\n float height = jointsTextureSize.y;\n float j = i * 16.0;\n float x = mod(j, width);\n float y = floor(j / width);\n float dx = 1.0 / width;\n float dy = 1.0 / height;\n y = dy * (y + 0.5);\n vec4 v1 = decodevec4(dx, x, y);\n vec4 v2 = decodevec4(dx, x+4.0, y);\n vec4 v3 = decodevec4(dx, x+8.0, y);\n vec4 v4 = decodevec4(dx, x+12.0, y);\n return mat4(v1, v2, v3, v4);\n }\n #endif\n #else\n uniform mat4 jointMatrices[50];\n mat4 getBoneMatrix(const in float i) {\n return jointMatrices[int(i)];\n }\n #endif\n mat4 skinMatrix() {\n return\n getBoneMatrix(a_joints.x) * a_weights.x +\n getBoneMatrix(a_joints.y) * a_weights.y +\n getBoneMatrix(a_joints.z) * a_weights.z +\n getBoneMatrix(a_joints.w) * a_weights.w\n ;\n }\n#endif\nvoid SKIN_VERTEX(inout vec4 a1) {\n #if CC_USE_SKINNING\n mat4 m = skinMatrix();\n a1 = m * a1;\n #endif\n}\nvoid SKIN_VERTEX(inout vec4 a1, inout vec4 a2) {\n #if CC_USE_SKINNING\n mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n #endif\n}\nvoid SKIN_VERTEX(inout vec4 a1, inout vec4 a2, inout vec4 a3) {\n #if CC_USE_SKINNING\n mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n a3 = m * a3;\n #endif\n}\nvoid main () {\n vec4 position = vec4(a_position, 1);\n SKIN_VERTEX(position);\n gl_Position = cc_shadow_map_lightViewProjMatrix * cc_matWorld * position;\n v_depth = ((gl_Position.z + cc_shadow_map_info.x) / (cc_shadow_map_info.x + cc_shadow_map_info.y)) + cc_shadow_map_bias;\n}",
  562. "frag": "\nprecision highp float;\nvarying float v_depth;\nvec4 packDepthToRGBA(float depth) {\n vec4 ret = vec4(1.0, 255.0, 65025.0, 160581375.0) * depth;\n ret = fract(ret);\n ret -= ret.yzww * vec4(1.0 / 255.0, 1.0 / 255.0, 1.0 / 255.0, 0.0);\n return ret;\n}\nvoid main () {\n gl_FragColor = packDepthToRGBA(v_depth);\n}"
  563. },
  564. "builtins": {
  565. "globals": {
  566. "blocks": [
  567. {
  568. "name": "CC_SHADOW_MAP",
  569. "defines": []
  570. }
  571. ],
  572. "samplers": []
  573. },
  574. "locals": {
  575. "blocks": [
  576. {
  577. "name": "CCLocal",
  578. "defines": []
  579. }
  580. ],
  581. "samplers": []
  582. }
  583. },
  584. "defines": [
  585. {
  586. "name": "CC_USE_SKINNING",
  587. "type": "boolean",
  588. "defines": []
  589. },
  590. {
  591. "name": "CC_USE_JOINTS_TEXTRUE",
  592. "type": "boolean",
  593. "defines": [
  594. "CC_USE_SKINNING"
  595. ]
  596. },
  597. {
  598. "name": "CC_JOINTS_TEXTURE_FLOAT32",
  599. "type": "boolean",
  600. "defines": [
  601. "CC_USE_SKINNING",
  602. "CC_USE_JOINTS_TEXTRUE"
  603. ]
  604. }
  605. ],
  606. "blocks": [
  607. {
  608. "name": "SKINNING",
  609. "members": [
  610. {
  611. "name": "jointsTextureSize",
  612. "type": 14,
  613. "count": 1
  614. }
  615. ],
  616. "defines": [
  617. "CC_USE_SKINNING",
  618. "CC_USE_JOINTS_TEXTRUE"
  619. ],
  620. "binding": 0
  621. },
  622. {
  623. "name": "JOINT_MATRIX",
  624. "members": [
  625. {
  626. "name": "jointMatrices",
  627. "type": 26,
  628. "count": 50
  629. }
  630. ],
  631. "defines": [
  632. "CC_USE_SKINNING"
  633. ],
  634. "binding": 1
  635. }
  636. ],
  637. "samplers": [
  638. {
  639. "name": "jointsTexture",
  640. "type": 29,
  641. "count": 1,
  642. "defines": [
  643. "CC_USE_SKINNING",
  644. "CC_USE_JOINTS_TEXTRUE"
  645. ],
  646. "binding": 30
  647. }
  648. ],
  649. "record": null,
  650. "name": "builtin-phong|shadow-map-vs|shadow-map-fs"
  651. }
  652. ]
  653. }