2399 lines
314 KiB
JSON
2399 lines
314 KiB
JSON
{
|
|
"__type__": "cc.EffectAsset",
|
|
"_name": "dcc/imported-specular-glossiness",
|
|
"_objFlags": 0,
|
|
"_native": "",
|
|
"techniques": [
|
|
{
|
|
"name": "opaque",
|
|
"passes": [
|
|
{
|
|
"program": "dcc/imported-specular-glossiness|standard-vs|standard-fs",
|
|
"properties": {
|
|
"mainTexture": {
|
|
"value": "grey",
|
|
"editor": {
|
|
"displayName": "DiffuseMap"
|
|
},
|
|
"type": 28,
|
|
"handleInfo": [
|
|
"albedoMap",
|
|
0,
|
|
28
|
|
]
|
|
},
|
|
"mainColor": {
|
|
"value": [
|
|
1,
|
|
1,
|
|
1,
|
|
1
|
|
],
|
|
"linear": true,
|
|
"editor": {
|
|
"displayName": "DiffuseColor",
|
|
"type": "color"
|
|
},
|
|
"type": 16,
|
|
"handleInfo": [
|
|
"diffuseColor",
|
|
0,
|
|
16
|
|
]
|
|
},
|
|
"albedoScale": {
|
|
"value": [
|
|
1
|
|
],
|
|
"editor": {
|
|
"displayName": "diffuseFactor"
|
|
},
|
|
"type": 13,
|
|
"handleInfo": [
|
|
"diffuseFactor",
|
|
0,
|
|
13
|
|
]
|
|
},
|
|
"alphaThreshold": {
|
|
"value": [
|
|
0.5
|
|
],
|
|
"editor": {
|
|
"parent": "USE_ALPHA_TEST",
|
|
"slide": true,
|
|
"range": [
|
|
0,
|
|
1
|
|
],
|
|
"step": 0.001
|
|
},
|
|
"type": 13
|
|
},
|
|
"emissive": {
|
|
"value": [
|
|
0,
|
|
0,
|
|
0,
|
|
1
|
|
],
|
|
"linear": true,
|
|
"editor": {
|
|
"type": "color"
|
|
},
|
|
"type": 16
|
|
},
|
|
"emissiveMap": {
|
|
"value": "grey",
|
|
"type": 28
|
|
},
|
|
"shininessExponentMap": {
|
|
"value": "grey",
|
|
"editor": {
|
|
"parent": "!HAS_EXPORTED_GLOSSINESS"
|
|
},
|
|
"type": 28
|
|
},
|
|
"shininessExponent": {
|
|
"value": [
|
|
100
|
|
],
|
|
"editor": {
|
|
"parent": "!HAS_EXPORTED_GLOSSINESS"
|
|
},
|
|
"type": 13
|
|
},
|
|
"specularGlossinessMap": {
|
|
"value": "grey",
|
|
"editor": {
|
|
"parent": "!HAS_EXPORTED_GLOSSINESS"
|
|
},
|
|
"type": 28
|
|
},
|
|
"specularColor": {
|
|
"value": [
|
|
0,
|
|
0,
|
|
0,
|
|
0
|
|
],
|
|
"linear": true,
|
|
"editor": {
|
|
"displayName": "SpecularColor",
|
|
"type": "color"
|
|
},
|
|
"type": 16
|
|
},
|
|
"specularMap": {
|
|
"value": "grey",
|
|
"editor": {
|
|
"parent": "!HAS_EXPORTED_METALLIC"
|
|
},
|
|
"type": 28
|
|
},
|
|
"specularFactor": {
|
|
"value": [
|
|
1
|
|
],
|
|
"editor": {
|
|
"parent": "!HAS_EXPORTED_METALLIC"
|
|
},
|
|
"type": 13
|
|
},
|
|
"transparencyMap": {
|
|
"value": "grey",
|
|
"editor": {
|
|
"displayName": "TransparencyMap"
|
|
},
|
|
"type": 28
|
|
},
|
|
"transparencyFactor": {
|
|
"value": [
|
|
1
|
|
],
|
|
"editor": {
|
|
"slide": true,
|
|
"range": [
|
|
0,
|
|
1
|
|
],
|
|
"step": 0.001
|
|
},
|
|
"type": 13
|
|
},
|
|
"tilingOffset": {
|
|
"value": [
|
|
1,
|
|
1,
|
|
0,
|
|
0
|
|
],
|
|
"type": 16
|
|
},
|
|
"normalStrength": {
|
|
"value": [
|
|
1
|
|
],
|
|
"editor": {
|
|
"displayName": "bumpFactor",
|
|
"parent": "USE_NORMAL_MAP",
|
|
"slide": true,
|
|
"range": [
|
|
0,
|
|
5
|
|
],
|
|
"step": 0.001
|
|
},
|
|
"type": 13,
|
|
"handleInfo": [
|
|
"normalScale",
|
|
0,
|
|
13
|
|
]
|
|
},
|
|
"normalMap": {
|
|
"value": "normal",
|
|
"type": 28
|
|
},
|
|
"glossiness": {
|
|
"value": [
|
|
0
|
|
],
|
|
"editor": {
|
|
"parent": "HAS_EXPORTED_GLOSSINESS",
|
|
"slide": true,
|
|
"range": [
|
|
0,
|
|
1
|
|
],
|
|
"step": 0.001
|
|
},
|
|
"type": 13
|
|
},
|
|
"metallic": {
|
|
"value": [
|
|
0
|
|
],
|
|
"editor": {
|
|
"parent": "HAS_EXPORTED_METALLIC",
|
|
"slide": true,
|
|
"range": [
|
|
0,
|
|
1
|
|
],
|
|
"step": 0.001
|
|
},
|
|
"type": 13
|
|
},
|
|
"metallicMap": {
|
|
"value": "grey",
|
|
"editor": {
|
|
"parent": "HAS_EXPORTED_METALLIC"
|
|
},
|
|
"type": 28
|
|
},
|
|
"albedoMap": {
|
|
"type": 28,
|
|
"editor": {
|
|
"visible": false,
|
|
"deprecated": true
|
|
},
|
|
"value": "grey"
|
|
},
|
|
"diffuseColor": {
|
|
"type": 16,
|
|
"editor": {
|
|
"visible": false,
|
|
"deprecated": true
|
|
},
|
|
"value": [
|
|
1,
|
|
1,
|
|
1,
|
|
1
|
|
]
|
|
},
|
|
"diffuseFactor": {
|
|
"type": 13,
|
|
"editor": {
|
|
"visible": false,
|
|
"deprecated": true
|
|
},
|
|
"value": [
|
|
1
|
|
]
|
|
},
|
|
"normalScale": {
|
|
"type": 13,
|
|
"editor": {
|
|
"visible": false,
|
|
"deprecated": true
|
|
},
|
|
"value": [
|
|
1
|
|
]
|
|
}
|
|
}
|
|
},
|
|
{
|
|
"phase": "forward-add",
|
|
"propertyIndex": 0,
|
|
"embeddedMacros": {
|
|
"CC_FORWARD_ADD": true
|
|
},
|
|
"blendState": {
|
|
"targets": [
|
|
{
|
|
"blend": true,
|
|
"blendSrc": 1,
|
|
"blendDst": 1,
|
|
"blendSrcAlpha": 0,
|
|
"blendDstAlpha": 1
|
|
}
|
|
]
|
|
},
|
|
"program": "dcc/imported-specular-glossiness|standard-vs|standard-fs",
|
|
"depthStencilState": {
|
|
"depthFunc": 2,
|
|
"depthTest": true,
|
|
"depthWrite": false
|
|
}
|
|
},
|
|
{
|
|
"phase": "shadow-caster",
|
|
"propertyIndex": 0,
|
|
"rasterizerState": {
|
|
"cullMode": 1
|
|
},
|
|
"program": "dcc/imported-specular-glossiness|shadow-caster-vs:vert|shadow-caster-fs:frag",
|
|
"properties": {
|
|
"tilingOffset": {
|
|
"value": [
|
|
1,
|
|
1,
|
|
0,
|
|
0
|
|
],
|
|
"type": 16
|
|
},
|
|
"mainColor": {
|
|
"value": [
|
|
1,
|
|
1,
|
|
1,
|
|
1
|
|
],
|
|
"editor": {
|
|
"displayName": "Albedo",
|
|
"type": "color"
|
|
},
|
|
"type": 16,
|
|
"handleInfo": [
|
|
"diffuseColor",
|
|
0,
|
|
16
|
|
]
|
|
},
|
|
"albedoScale": {
|
|
"value": [
|
|
1
|
|
],
|
|
"editor": {
|
|
"displayName": "diffuseFactor"
|
|
},
|
|
"type": 13,
|
|
"handleInfo": [
|
|
"diffuseFactor",
|
|
0,
|
|
13
|
|
]
|
|
},
|
|
"alphaThreshold": {
|
|
"value": [
|
|
0.5
|
|
],
|
|
"editor": {
|
|
"parent": "USE_ALPHA_TEST"
|
|
},
|
|
"type": 13
|
|
},
|
|
"mainTexture": {
|
|
"value": "grey",
|
|
"editor": {
|
|
"displayName": "AlbedoMap"
|
|
},
|
|
"type": 28,
|
|
"handleInfo": [
|
|
"albedoMap",
|
|
0,
|
|
28
|
|
]
|
|
},
|
|
"transparencyMap": {
|
|
"value": "grey",
|
|
"editor": {
|
|
"displayName": "TransparencyMap"
|
|
},
|
|
"type": 28
|
|
},
|
|
"transparencyFactor": {
|
|
"value": [
|
|
1
|
|
],
|
|
"editor": {
|
|
"slide": true,
|
|
"range": [
|
|
0,
|
|
1
|
|
],
|
|
"step": 0.001
|
|
},
|
|
"type": 13
|
|
},
|
|
"diffuseColor": {
|
|
"type": 16,
|
|
"editor": {
|
|
"visible": false,
|
|
"deprecated": true
|
|
},
|
|
"value": [
|
|
1,
|
|
1,
|
|
1,
|
|
1
|
|
]
|
|
},
|
|
"diffuseFactor": {
|
|
"type": 13,
|
|
"editor": {
|
|
"visible": false,
|
|
"deprecated": true
|
|
},
|
|
"value": [
|
|
1
|
|
]
|
|
},
|
|
"albedoMap": {
|
|
"type": 28,
|
|
"editor": {
|
|
"visible": false,
|
|
"deprecated": true
|
|
},
|
|
"value": "grey"
|
|
}
|
|
}
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"name": "transparent",
|
|
"passes": [
|
|
{
|
|
"embeddedMacros": {
|
|
"CC_FORCE_FORWARD_SHADING": true
|
|
},
|
|
"blendState": {
|
|
"targets": [
|
|
{
|
|
"blend": true,
|
|
"blendSrc": 2,
|
|
"blendDst": 4,
|
|
"blendDstAlpha": 4
|
|
}
|
|
]
|
|
},
|
|
"program": "dcc/imported-specular-glossiness|standard-vs|standard-fs",
|
|
"depthStencilState": {
|
|
"depthTest": true,
|
|
"depthWrite": false
|
|
},
|
|
"properties": {
|
|
"mainTexture": {
|
|
"value": "grey",
|
|
"editor": {
|
|
"displayName": "DiffuseMap"
|
|
},
|
|
"type": 28,
|
|
"handleInfo": [
|
|
"albedoMap",
|
|
0,
|
|
28
|
|
]
|
|
},
|
|
"mainColor": {
|
|
"value": [
|
|
1,
|
|
1,
|
|
1,
|
|
1
|
|
],
|
|
"linear": true,
|
|
"editor": {
|
|
"displayName": "DiffuseColor",
|
|
"type": "color"
|
|
},
|
|
"type": 16,
|
|
"handleInfo": [
|
|
"diffuseColor",
|
|
0,
|
|
16
|
|
]
|
|
},
|
|
"albedoScale": {
|
|
"value": [
|
|
1
|
|
],
|
|
"editor": {
|
|
"displayName": "diffuseFactor"
|
|
},
|
|
"type": 13,
|
|
"handleInfo": [
|
|
"diffuseFactor",
|
|
0,
|
|
13
|
|
]
|
|
},
|
|
"alphaThreshold": {
|
|
"value": [
|
|
0.5
|
|
],
|
|
"editor": {
|
|
"parent": "USE_ALPHA_TEST",
|
|
"slide": true,
|
|
"range": [
|
|
0,
|
|
1
|
|
],
|
|
"step": 0.001
|
|
},
|
|
"type": 13
|
|
},
|
|
"emissive": {
|
|
"value": [
|
|
0,
|
|
0,
|
|
0,
|
|
1
|
|
],
|
|
"linear": true,
|
|
"editor": {
|
|
"type": "color"
|
|
},
|
|
"type": 16
|
|
},
|
|
"emissiveMap": {
|
|
"value": "grey",
|
|
"type": 28
|
|
},
|
|
"shininessExponentMap": {
|
|
"value": "grey",
|
|
"editor": {
|
|
"parent": "!HAS_EXPORTED_GLOSSINESS"
|
|
},
|
|
"type": 28
|
|
},
|
|
"shininessExponent": {
|
|
"value": [
|
|
100
|
|
],
|
|
"editor": {
|
|
"parent": "!HAS_EXPORTED_GLOSSINESS"
|
|
},
|
|
"type": 13
|
|
},
|
|
"specularGlossinessMap": {
|
|
"value": "grey",
|
|
"editor": {
|
|
"parent": "!HAS_EXPORTED_GLOSSINESS"
|
|
},
|
|
"type": 28
|
|
},
|
|
"specularColor": {
|
|
"value": [
|
|
0,
|
|
0,
|
|
0,
|
|
0
|
|
],
|
|
"linear": true,
|
|
"editor": {
|
|
"displayName": "SpecularColor",
|
|
"type": "color"
|
|
},
|
|
"type": 16
|
|
},
|
|
"specularMap": {
|
|
"value": "grey",
|
|
"editor": {
|
|
"parent": "!HAS_EXPORTED_METALLIC"
|
|
},
|
|
"type": 28
|
|
},
|
|
"specularFactor": {
|
|
"value": [
|
|
1
|
|
],
|
|
"editor": {
|
|
"parent": "!HAS_EXPORTED_METALLIC"
|
|
},
|
|
"type": 13
|
|
},
|
|
"transparencyMap": {
|
|
"value": "grey",
|
|
"editor": {
|
|
"displayName": "TransparencyMap"
|
|
},
|
|
"type": 28
|
|
},
|
|
"transparencyFactor": {
|
|
"value": [
|
|
1
|
|
],
|
|
"editor": {
|
|
"slide": true,
|
|
"range": [
|
|
0,
|
|
1
|
|
],
|
|
"step": 0.001
|
|
},
|
|
"type": 13
|
|
},
|
|
"tilingOffset": {
|
|
"value": [
|
|
1,
|
|
1,
|
|
0,
|
|
0
|
|
],
|
|
"type": 16
|
|
},
|
|
"normalStrength": {
|
|
"value": [
|
|
1
|
|
],
|
|
"editor": {
|
|
"displayName": "bumpFactor",
|
|
"parent": "USE_NORMAL_MAP",
|
|
"slide": true,
|
|
"range": [
|
|
0,
|
|
5
|
|
],
|
|
"step": 0.001
|
|
},
|
|
"type": 13,
|
|
"handleInfo": [
|
|
"normalScale",
|
|
0,
|
|
13
|
|
]
|
|
},
|
|
"normalMap": {
|
|
"value": "normal",
|
|
"type": 28
|
|
},
|
|
"glossiness": {
|
|
"value": [
|
|
0
|
|
],
|
|
"editor": {
|
|
"parent": "HAS_EXPORTED_GLOSSINESS",
|
|
"slide": true,
|
|
"range": [
|
|
0,
|
|
1
|
|
],
|
|
"step": 0.001
|
|
},
|
|
"type": 13
|
|
},
|
|
"metallic": {
|
|
"value": [
|
|
0
|
|
],
|
|
"editor": {
|
|
"parent": "HAS_EXPORTED_METALLIC",
|
|
"slide": true,
|
|
"range": [
|
|
0,
|
|
1
|
|
],
|
|
"step": 0.001
|
|
},
|
|
"type": 13
|
|
},
|
|
"metallicMap": {
|
|
"value": "grey",
|
|
"editor": {
|
|
"parent": "HAS_EXPORTED_METALLIC"
|
|
},
|
|
"type": 28
|
|
},
|
|
"albedoMap": {
|
|
"type": 28,
|
|
"editor": {
|
|
"visible": false,
|
|
"deprecated": true
|
|
},
|
|
"value": "grey"
|
|
},
|
|
"diffuseColor": {
|
|
"type": 16,
|
|
"editor": {
|
|
"visible": false,
|
|
"deprecated": true
|
|
},
|
|
"value": [
|
|
1,
|
|
1,
|
|
1,
|
|
1
|
|
]
|
|
},
|
|
"diffuseFactor": {
|
|
"type": 13,
|
|
"editor": {
|
|
"visible": false,
|
|
"deprecated": true
|
|
},
|
|
"value": [
|
|
1
|
|
]
|
|
},
|
|
"normalScale": {
|
|
"type": 13,
|
|
"editor": {
|
|
"visible": false,
|
|
"deprecated": true
|
|
},
|
|
"value": [
|
|
1
|
|
]
|
|
}
|
|
}
|
|
},
|
|
{
|
|
"phase": "forward-add",
|
|
"propertyIndex": 0,
|
|
"embeddedMacros": {
|
|
"CC_FORWARD_ADD": true
|
|
},
|
|
"blendState": {
|
|
"targets": [
|
|
{
|
|
"blend": true,
|
|
"blendSrc": 1,
|
|
"blendDst": 1,
|
|
"blendSrcAlpha": 0,
|
|
"blendDstAlpha": 1
|
|
}
|
|
]
|
|
},
|
|
"program": "dcc/imported-specular-glossiness|standard-vs|standard-fs",
|
|
"depthStencilState": {
|
|
"depthFunc": 2,
|
|
"depthTest": true,
|
|
"depthWrite": false
|
|
}
|
|
},
|
|
{
|
|
"phase": "shadow-caster",
|
|
"propertyIndex": 0,
|
|
"rasterizerState": {
|
|
"cullMode": 1
|
|
},
|
|
"program": "dcc/imported-specular-glossiness|shadow-caster-vs:vert|shadow-caster-fs:frag",
|
|
"properties": {
|
|
"tilingOffset": {
|
|
"value": [
|
|
1,
|
|
1,
|
|
0,
|
|
0
|
|
],
|
|
"type": 16
|
|
},
|
|
"mainColor": {
|
|
"value": [
|
|
1,
|
|
1,
|
|
1,
|
|
1
|
|
],
|
|
"editor": {
|
|
"displayName": "Albedo",
|
|
"type": "color"
|
|
},
|
|
"type": 16,
|
|
"handleInfo": [
|
|
"diffuseColor",
|
|
0,
|
|
16
|
|
]
|
|
},
|
|
"albedoScale": {
|
|
"value": [
|
|
1
|
|
],
|
|
"editor": {
|
|
"displayName": "diffuseFactor"
|
|
},
|
|
"type": 13,
|
|
"handleInfo": [
|
|
"diffuseFactor",
|
|
0,
|
|
13
|
|
]
|
|
},
|
|
"alphaThreshold": {
|
|
"value": [
|
|
0.5
|
|
],
|
|
"editor": {
|
|
"parent": "USE_ALPHA_TEST"
|
|
},
|
|
"type": 13
|
|
},
|
|
"mainTexture": {
|
|
"value": "grey",
|
|
"editor": {
|
|
"displayName": "AlbedoMap"
|
|
},
|
|
"type": 28,
|
|
"handleInfo": [
|
|
"albedoMap",
|
|
0,
|
|
28
|
|
]
|
|
},
|
|
"transparencyMap": {
|
|
"value": "grey",
|
|
"editor": {
|
|
"displayName": "TransparencyMap"
|
|
},
|
|
"type": 28
|
|
},
|
|
"transparencyFactor": {
|
|
"value": [
|
|
1
|
|
],
|
|
"editor": {
|
|
"slide": true,
|
|
"range": [
|
|
0,
|
|
1
|
|
],
|
|
"step": 0.001
|
|
},
|
|
"type": 13
|
|
},
|
|
"diffuseColor": {
|
|
"type": 16,
|
|
"editor": {
|
|
"visible": false,
|
|
"deprecated": true
|
|
},
|
|
"value": [
|
|
1,
|
|
1,
|
|
1,
|
|
1
|
|
]
|
|
},
|
|
"diffuseFactor": {
|
|
"type": 13,
|
|
"editor": {
|
|
"visible": false,
|
|
"deprecated": true
|
|
},
|
|
"value": [
|
|
1
|
|
]
|
|
},
|
|
"albedoMap": {
|
|
"type": 28,
|
|
"editor": {
|
|
"visible": false,
|
|
"deprecated": true
|
|
},
|
|
"value": "grey"
|
|
}
|
|
}
|
|
}
|
|
]
|
|
}
|
|
],
|
|
"shaders": [
|
|
{
|
|
"blocks": [
|
|
{
|
|
"name": "Constants",
|
|
"members": [
|
|
{
|
|
"name": "tilingOffset",
|
|
"type": 16,
|
|
"count": 1
|
|
},
|
|
{
|
|
"name": "diffuseColor",
|
|
"type": 16,
|
|
"count": 1
|
|
},
|
|
{
|
|
"name": "specularColor",
|
|
"type": 16,
|
|
"count": 1
|
|
},
|
|
{
|
|
"name": "emissive",
|
|
"type": 16,
|
|
"count": 1
|
|
},
|
|
{
|
|
"name": "alphaThreshold",
|
|
"type": 13,
|
|
"count": 1
|
|
},
|
|
{
|
|
"name": "shininessExponent",
|
|
"type": 13,
|
|
"count": 1
|
|
},
|
|
{
|
|
"name": "glossiness",
|
|
"type": 13,
|
|
"count": 1
|
|
},
|
|
{
|
|
"name": "metallic",
|
|
"type": 13,
|
|
"count": 1
|
|
},
|
|
{
|
|
"name": "normalScale",
|
|
"type": 13,
|
|
"count": 1
|
|
},
|
|
{
|
|
"name": "transparencyFactor",
|
|
"type": 13,
|
|
"count": 1
|
|
},
|
|
{
|
|
"name": "diffuseFactor",
|
|
"type": 13,
|
|
"count": 1
|
|
},
|
|
{
|
|
"name": "specularFactor",
|
|
"type": 13,
|
|
"count": 1
|
|
}
|
|
],
|
|
"defines": [],
|
|
"stageFlags": 17,
|
|
"binding": 0
|
|
}
|
|
],
|
|
"samplerTextures": [
|
|
{
|
|
"name": "shininessExponentMap",
|
|
"type": 28,
|
|
"count": 1,
|
|
"defines": [
|
|
"USE_SHININESS_MAP"
|
|
],
|
|
"stageFlags": 16,
|
|
"binding": 1
|
|
},
|
|
{
|
|
"name": "specularGlossinessMap",
|
|
"type": 28,
|
|
"count": 1,
|
|
"defines": [
|
|
"USE_SPECULAR_GLOSSINESS_MAP"
|
|
],
|
|
"stageFlags": 16,
|
|
"binding": 2
|
|
},
|
|
{
|
|
"name": "specularMap",
|
|
"type": 28,
|
|
"count": 1,
|
|
"defines": [
|
|
"USE_SPECULAR_MAP"
|
|
],
|
|
"stageFlags": 16,
|
|
"binding": 3
|
|
},
|
|
{
|
|
"name": "metallicMap",
|
|
"type": 28,
|
|
"count": 1,
|
|
"defines": [
|
|
"USE_METALLIC_MAP"
|
|
],
|
|
"stageFlags": 16,
|
|
"binding": 4
|
|
},
|
|
{
|
|
"name": "albedoMap",
|
|
"type": 28,
|
|
"count": 1,
|
|
"defines": [
|
|
"USE_ALBEDO_MAP"
|
|
],
|
|
"stageFlags": 16,
|
|
"binding": 5
|
|
},
|
|
{
|
|
"name": "transparencyMap",
|
|
"type": 28,
|
|
"count": 1,
|
|
"defines": [
|
|
"USE_TRANSPARENCY_MAP"
|
|
],
|
|
"stageFlags": 16,
|
|
"binding": 6
|
|
},
|
|
{
|
|
"name": "normalMap",
|
|
"type": 28,
|
|
"count": 1,
|
|
"defines": [
|
|
"USE_NORMAL_MAP"
|
|
],
|
|
"stageFlags": 16,
|
|
"binding": 7
|
|
},
|
|
{
|
|
"name": "emissiveMap",
|
|
"type": 28,
|
|
"count": 1,
|
|
"defines": [
|
|
"USE_EMISSIVE_MAP"
|
|
],
|
|
"stageFlags": 16,
|
|
"binding": 8
|
|
}
|
|
],
|
|
"samplers": [],
|
|
"textures": [],
|
|
"buffers": [
|
|
{
|
|
"name": "b_ccLightsBuffer",
|
|
"memoryAccess": 1,
|
|
"defines": [
|
|
"CC_FORWARD_ADD"
|
|
],
|
|
"stageFlags": 16,
|
|
"binding": 9
|
|
},
|
|
{
|
|
"name": "b_clusterLightIndicesBuffer",
|
|
"memoryAccess": 1,
|
|
"defines": [
|
|
"CC_FORWARD_ADD"
|
|
],
|
|
"stageFlags": 16,
|
|
"binding": 10
|
|
},
|
|
{
|
|
"name": "b_clusterLightGridBuffer",
|
|
"memoryAccess": 1,
|
|
"defines": [
|
|
"CC_FORWARD_ADD"
|
|
],
|
|
"stageFlags": 16,
|
|
"binding": 11
|
|
}
|
|
],
|
|
"images": [],
|
|
"subpassInputs": [],
|
|
"attributes": [
|
|
{
|
|
"name": "a_position",
|
|
"defines": [],
|
|
"format": 32,
|
|
"location": 0
|
|
},
|
|
{
|
|
"name": "a_normal",
|
|
"defines": [],
|
|
"format": 32,
|
|
"location": 1
|
|
},
|
|
{
|
|
"name": "a_texCoord",
|
|
"defines": [],
|
|
"format": 21,
|
|
"location": 2
|
|
},
|
|
{
|
|
"name": "a_tangent",
|
|
"defines": [],
|
|
"format": 44,
|
|
"location": 3
|
|
},
|
|
{
|
|
"name": "a_joints",
|
|
"defines": [
|
|
"CC_USE_SKINNING"
|
|
],
|
|
"location": 4
|
|
},
|
|
{
|
|
"name": "a_weights",
|
|
"defines": [
|
|
"CC_USE_SKINNING"
|
|
],
|
|
"format": 44,
|
|
"location": 5
|
|
},
|
|
{
|
|
"name": "a_jointAnimInfo",
|
|
"defines": [
|
|
"USE_INSTANCING",
|
|
"CC_USE_BAKED_ANIMATION"
|
|
],
|
|
"format": 44,
|
|
"isInstanced": true,
|
|
"location": 6
|
|
},
|
|
{
|
|
"name": "a_matWorld0",
|
|
"defines": [
|
|
"USE_INSTANCING"
|
|
],
|
|
"format": 44,
|
|
"isInstanced": true,
|
|
"location": 7
|
|
},
|
|
{
|
|
"name": "a_matWorld1",
|
|
"defines": [
|
|
"USE_INSTANCING"
|
|
],
|
|
"format": 44,
|
|
"isInstanced": true,
|
|
"location": 8
|
|
},
|
|
{
|
|
"name": "a_matWorld2",
|
|
"defines": [
|
|
"USE_INSTANCING"
|
|
],
|
|
"format": 44,
|
|
"isInstanced": true,
|
|
"location": 9
|
|
},
|
|
{
|
|
"name": "a_lightingMapUVParam",
|
|
"defines": [
|
|
"USE_INSTANCING",
|
|
"CC_USE_LIGHTMAP"
|
|
],
|
|
"format": 44,
|
|
"isInstanced": true,
|
|
"location": 10
|
|
},
|
|
{
|
|
"name": "a_localShadowBias",
|
|
"defines": [
|
|
"USE_INSTANCING",
|
|
"CC_RECEIVE_SHADOW"
|
|
],
|
|
"format": 21,
|
|
"isInstanced": true,
|
|
"location": 11
|
|
},
|
|
{
|
|
"name": "a_dyn_batch_id",
|
|
"defines": [
|
|
"!USE_INSTANCING",
|
|
"USE_BATCHING"
|
|
],
|
|
"format": 11,
|
|
"location": 12
|
|
},
|
|
{
|
|
"name": "a_vertexId",
|
|
"defines": [
|
|
"CC_USE_MORPH"
|
|
],
|
|
"format": 11,
|
|
"location": 13
|
|
},
|
|
{
|
|
"name": "a_color",
|
|
"defines": [
|
|
"USE_VERTEX_COLOR"
|
|
],
|
|
"format": 44,
|
|
"location": 14
|
|
},
|
|
{
|
|
"name": "a_texCoord1",
|
|
"defines": [],
|
|
"format": 21,
|
|
"location": 15
|
|
}
|
|
],
|
|
"varyings": [
|
|
{
|
|
"name": "v_fog_factor",
|
|
"type": 13,
|
|
"count": 1,
|
|
"defines": [
|
|
"!CC_USE_ACCURATE_FOG"
|
|
],
|
|
"stageFlags": 17,
|
|
"location": 0
|
|
},
|
|
{
|
|
"name": "v_shadowPos",
|
|
"type": 16,
|
|
"count": 1,
|
|
"defines": [],
|
|
"stageFlags": 17,
|
|
"location": 1
|
|
},
|
|
{
|
|
"name": "v_color",
|
|
"type": 16,
|
|
"count": 1,
|
|
"defines": [
|
|
"USE_VERTEX_COLOR"
|
|
],
|
|
"stageFlags": 17,
|
|
"location": 2
|
|
},
|
|
{
|
|
"name": "v_position",
|
|
"type": 15,
|
|
"count": 1,
|
|
"defines": [],
|
|
"stageFlags": 17,
|
|
"location": 3
|
|
},
|
|
{
|
|
"name": "v_normal",
|
|
"type": 15,
|
|
"count": 1,
|
|
"defines": [],
|
|
"stageFlags": 17,
|
|
"location": 4
|
|
},
|
|
{
|
|
"name": "v_uv",
|
|
"type": 14,
|
|
"count": 1,
|
|
"defines": [],
|
|
"stageFlags": 17,
|
|
"location": 5
|
|
},
|
|
{
|
|
"name": "v_uv1",
|
|
"type": 14,
|
|
"count": 1,
|
|
"defines": [],
|
|
"stageFlags": 17,
|
|
"location": 6
|
|
},
|
|
{
|
|
"name": "v_tangent",
|
|
"type": 15,
|
|
"count": 1,
|
|
"defines": [
|
|
"USE_NORMAL_MAP"
|
|
],
|
|
"stageFlags": 17,
|
|
"location": 7
|
|
},
|
|
{
|
|
"name": "v_bitangent",
|
|
"type": 15,
|
|
"count": 1,
|
|
"defines": [
|
|
"USE_NORMAL_MAP"
|
|
],
|
|
"stageFlags": 17,
|
|
"location": 8
|
|
},
|
|
{
|
|
"name": "v_shadowBias",
|
|
"type": 14,
|
|
"count": 1,
|
|
"defines": [
|
|
"CC_RECEIVE_SHADOW"
|
|
],
|
|
"stageFlags": 17,
|
|
"location": 9
|
|
},
|
|
{
|
|
"name": "v_luv",
|
|
"type": 15,
|
|
"count": 1,
|
|
"defines": [
|
|
"CC_USE_LIGHTMAP",
|
|
"!USE_BATCHING",
|
|
"!CC_FORWARD_ADD"
|
|
],
|
|
"stageFlags": 17,
|
|
"location": 10
|
|
}
|
|
],
|
|
"fragColors": [
|
|
{
|
|
"name": "fragColorX",
|
|
"typename": "vec4",
|
|
"type": 16,
|
|
"count": 1,
|
|
"defines": [
|
|
"CC_FORWARD_ADD"
|
|
],
|
|
"stageFlags": 16,
|
|
"location": 0
|
|
},
|
|
{
|
|
"name": "fragColor0",
|
|
"typename": "vec4",
|
|
"type": 16,
|
|
"count": 1,
|
|
"defines": [
|
|
"!CC_FORWARD_ADD",
|
|
"CC_PIPELINE_TYPE"
|
|
],
|
|
"stageFlags": 16,
|
|
"location": 1
|
|
},
|
|
{
|
|
"name": "fragColor1",
|
|
"typename": "vec4",
|
|
"type": 16,
|
|
"count": 1,
|
|
"defines": [
|
|
"!CC_FORWARD_ADD",
|
|
"CC_PIPELINE_TYPE"
|
|
],
|
|
"stageFlags": 16,
|
|
"location": 2
|
|
},
|
|
{
|
|
"name": "fragColor2",
|
|
"typename": "vec4",
|
|
"type": 16,
|
|
"count": 1,
|
|
"defines": [
|
|
"!CC_FORWARD_ADD",
|
|
"CC_PIPELINE_TYPE"
|
|
],
|
|
"stageFlags": 16,
|
|
"location": 3
|
|
}
|
|
],
|
|
"hash": 2269931406,
|
|
"glsl4": {
|
|
"vert": "#extension GL_EXT_shader_explicit_arithmetic_types_int32: require\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\n rgba = rgba * 255.0;\n highp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\n highp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\n highp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\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;\n#if CC_USE_SKINNING\n layout(location = 4) in u32vec4 a_joints;\n layout(location = 5) in vec4 a_weights;\n#endif\n#if USE_INSTANCING\n #if CC_USE_BAKED_ANIMATION\n layout(location = 6) in highp vec4 a_jointAnimInfo;\n #endif\n layout(location = 7) in vec4 a_matWorld0;\n layout(location = 8) in vec4 a_matWorld1;\n layout(location = 9) in vec4 a_matWorld2;\n #if CC_USE_LIGHTMAP\n layout(location = 10) in vec4 a_lightingMapUVParam;\n #endif\n #if CC_RECEIVE_SHADOW\n layout(location = 11) in vec2 a_localShadowBias;\n #endif\n#elif USE_BATCHING\n layout(location = 12) in float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\n int getVertexId() {\n return gl_VertexIndex;\n }\n#endif\n#if CC_USE_MORPH\n layout(set = 2, binding = 4) uniform CCMorph {\n vec4 cc_displacementWeights[15];\n vec4 cc_displacementTextureInfo;\n };\n #if CC_MORPH_TARGET_HAS_POSITION\n layout(set = 2, binding = 7) uniform sampler2D cc_PositionDisplacements;\n #endif\n #if CC_MORPH_TARGET_HAS_NORMAL\n layout(set = 2, binding = 8) uniform sampler2D cc_NormalDisplacements;\n #endif\n #if CC_MORPH_TARGET_HAS_TANGENT\n layout(set = 2, binding = 9) uniform sampler2D cc_TangentDisplacements;\n #endif\n vec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\n float pixelIndexF = float(pixelIndex);\n float x = mod(pixelIndexF, textureResolution.x);\n float y = floor(pixelIndexF / textureResolution.x);\n return vec2(x, y);\n }\n vec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\n return (vec2(location.x, location.y) + .5) / textureResolution;\n }\n #if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\n vec4 fetchVec3ArrayFromTexture(sampler2D tex, int pixelIndex) {\n ivec2 texSize = textureSize(tex, 0);\n return texelFetch(tex, ivec2(pixelIndex % texSize.x, pixelIndex / texSize.x), 0);\n }\n #else\n vec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\n int pixelIndex = elementIndex * 4;\n vec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\n vec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\n vec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\n vec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\n return vec4(\n decode32(texture(tex, x)),\n decode32(texture(tex, y)),\n decode32(texture(tex, z)),\n 1.0\n );\n }\n #endif\n float getDisplacementWeight(int index) {\n int quot = index / 4;\n int remainder = index - quot * 4;\n if (remainder == 0) {\n return cc_displacementWeights[quot].x;\n } else if (remainder == 1) {\n return cc_displacementWeights[quot].y;\n } else if (remainder == 2) {\n return cc_displacementWeights[quot].z;\n } else {\n return cc_displacementWeights[quot].w;\n }\n }\n vec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n #if CC_MORPH_PRECOMPUTED\n return fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n #else\n vec3 result = vec3(0, 0, 0);\n int nVertices = int(cc_displacementTextureInfo.z);\n for (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\n result += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n }\n return result;\n #endif\n }\n #if CC_MORPH_TARGET_HAS_POSITION\n vec3 getPositionDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n }\n #endif\n #if CC_MORPH_TARGET_HAS_NORMAL\n vec3 getNormalDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n }\n #endif\n #if CC_MORPH_TARGET_HAS_TANGENT\n vec3 getTangentDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n }\n #endif\n void applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\n int vertexId = getVertexId();\n #if CC_MORPH_TARGET_HAS_POSITION\n position.xyz = position.xyz + getPositionDisplacement(vertexId);\n #endif\n #if CC_MORPH_TARGET_HAS_NORMAL\n normal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n #endif\n #if CC_MORPH_TARGET_HAS_TANGENT\n tangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n #endif\n }\n void 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\n #if CC_USE_BAKED_ANIMATION\n layout(set = 2, binding = 3) uniform CCSkinningTexture {\n highp vec4 cc_jointTextureInfo;\n };\n layout(set = 2, binding = 2) uniform CCSkinningAnimation {\n highp vec4 cc_jointAnimInfo;\n };\n layout(set = 2, binding = 6) uniform highp sampler2D cc_jointTexture;\n void CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n {\n #if USE_INSTANCING\n highp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n #else\n highp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n #endif\n invSize = cc_jointTextureInfo.w;\n highp float tempY = floor(temp * invSize);\n x = floor(temp - tempY * cc_jointTextureInfo.x);\n y = (tempY + 0.5) * invSize;\n }\n #else\n #if CC_USE_REAL_TIME_JOINT_TEXTURE\n layout(set = 2, binding = 6) uniform highp sampler2D cc_realtimeJoint;\n #else\n layout(set = 2, binding = 3) uniform CCSkinning {\n highp vec4 cc_joints[CC_JOINT_UNIFORM_CAPACITY * 3];\n };\n #endif\n #endif\n #if CC_USE_BAKED_ANIMATION\n #if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\n mat4 getJointMatrix (float i) {\n highp float x, y, invSize;\n CCGetJointTextureCoords(3.0, i, x, y, 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 highp float x, y, invSize;\n CCGetJointTextureCoords(12.0, i, x, y, 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 #if CC_USE_REAL_TIME_JOINT_TEXTURE\n #if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\n mat4 getJointMatrix (float i) {\n float x = i;\n vec4 v1 = texture(cc_realtimeJoint, vec2( x / 256.0, 0.5 / 3.0));\n vec4 v2 = texture(cc_realtimeJoint, vec2( x / 256.0, 1.5 / 3.0));\n vec4 v3 = texture(cc_realtimeJoint, vec2( x / 256.0, 2.5 / 3.0));\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 float x = 4.0 * i;\n vec4 v1 = vec4(\n decode32(texture(cc_realtimeJoint, vec2((x + 0.5)/ 1024.0, 0.5 / 3.0))),\n decode32(texture(cc_realtimeJoint, vec2((x + 1.5)/ 1024.0, 0.5 / 3.0))),\n decode32(texture(cc_realtimeJoint, vec2((x + 2.5)/ 1024.0, 0.5 / 3.0))),\n decode32(texture(cc_realtimeJoint, vec2((x + 3.5)/ 1024.0, 0.5 / 3.0)))\n );\n vec4 v2 = vec4(\n decode32(texture(cc_realtimeJoint, vec2((x + 0.5)/ 1024.0, 1.5 / 3.0))),\n decode32(texture(cc_realtimeJoint, vec2((x + 1.5)/ 1024.0, 1.5 / 3.0))),\n decode32(texture(cc_realtimeJoint, vec2((x + 2.5)/ 1024.0, 1.5 / 3.0))),\n decode32(texture(cc_realtimeJoint, vec2((x + 3.5)/ 1024.0, 1.5 / 3.0)))\n );\n vec4 v3 = vec4(\n decode32(texture(cc_realtimeJoint, vec2((x + 0.5)/ 1024.0, 2.5 / 3.0))),\n decode32(texture(cc_realtimeJoint, vec2((x + 1.5)/ 1024.0, 2.5 / 3.0))),\n decode32(texture(cc_realtimeJoint, vec2((x + 2.5)/ 1024.0, 2.5 / 3.0))),\n decode32(texture(cc_realtimeJoint, vec2((x + 3.5)/ 1024.0, 2.5 / 3.0)))\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\n #endif\n mat4 skinMatrix () {\n vec4 joints = vec4(a_joints);\n return getJointMatrix(joints.x) * a_weights.x\n + getJointMatrix(joints.y) * a_weights.y\n + getJointMatrix(joints.z) * a_weights.z\n + getJointMatrix(joints.w) * a_weights.w;\n }\n void CCSkin (inout vec4 position) {\n mat4 m = skinMatrix();\n position = m * position;\n }\n void CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\n mat4 m = skinMatrix();\n position = m * position;\n normal = (m * vec4(normal, 0.0)).xyz;\n tangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n }\n#endif\nvoid CCVertInput(inout StandardVertInput In)\n{\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.position, In.normal, In.tangent);\n #endif\n #if CC_USE_SKINNING\n CCSkin(In.position, In.normal, In.tangent);\n #endif\n}\nlayout(set = 0, binding = 0) uniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_nativeSize;\n mediump vec4 cc_debug_view_mode;\n mediump vec4 cc_debug_view_composite_pack_1;\n mediump vec4 cc_debug_view_composite_pack_2;\n mediump vec4 cc_debug_view_composite_pack_3;\n};\nlayout(set = 0, binding = 1) uniform CCCamera {\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_surfaceTransform;\n mediump vec4 cc_screenScale;\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 mediump vec4 cc_nearFar;\n mediump vec4 cc_viewPort;\n};\n#if !USE_INSTANCING\n #if USE_BATCHING\n layout(set = 2, binding = 0) uniform CCLocalBatched {\n highp mat4 cc_matWorlds[10];\n };\n #else\n layout(set = 2, binding = 0) uniform CCLocal {\n highp mat4 cc_matWorld;\n highp mat4 cc_matWorldIT;\n highp vec4 cc_lightingMapUVParam;\n highp vec4 cc_localShadowBias;\n };\n #endif\n#endif\nvoid CCGetWorldMatrixFull(out mat4 matWorld, out mat4 matWorldIT)\n{\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}\nlayout(set = 1, binding = 0) uniform Constants {\n vec4 tilingOffset;\n vec4 diffuseColor;\n vec4 specularColor;\n vec4 emissive;\n float alphaThreshold;\n float shininessExponent;\n float glossiness;\n float metallic;\n float normalScale;\n float transparencyFactor;\n float diffuseFactor;\n float specularFactor;\n};\n#if CC_USE_FOG != 4\n float LinearFog(vec4 pos, vec3 cameraPos, float fogStart, float fogEnd) {\n vec4 wPos = pos;\n float cam_dis = distance(cameraPos, wPos.xyz);\n return clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n }\n float ExpFog(vec4 pos, vec3 cameraPos, float fogStart, float fogDensity, float fogAtten) {\n vec4 wPos = pos;\n float cam_dis = max(distance(cameraPos, wPos.xyz) - fogStart, 0.0) / fogAtten * 4.;\n float f = exp(-cam_dis * fogDensity);\n return f;\n }\n float ExpSquaredFog(vec4 pos, vec3 cameraPos, float fogStart, float fogDensity, float fogAtten) {\n vec4 wPos = pos;\n float cam_dis = max(distance(cameraPos, wPos.xyz) - fogStart, 0.0) / fogAtten * 4.;\n float f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\n return f;\n }\n float LayeredFog(vec4 pos, vec3 cameraPos, float fogTop, float fogRange, float fogAtten) {\n vec4 wPos = pos;\n vec3 camWorldProj = 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 (cameraPos.y > fogTop) {\n if (wPos.y < fogTop) {\n fDeltaY = (fogTop - wPos.y) / fogRange * 2.0;\n fDensityIntegral = fDeltaY * fDeltaY * 0.5;\n }\n else {\n fDeltaY = 0.;\n fDensityIntegral = 0.;\n }\n }\n else {\n if (wPos.y < fogTop) {\n float fDeltaA = (fogTop - 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 }\n else {\n fDeltaY = abs(fogTop - 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 }\n else {\n fDensity = 0.;\n }\n float f = exp(-fDensity);\n return f;\n }\n#endif\nvoid CC_TRANSFER_FOG_BASE(vec4 pos, out float factor)\n{\n#if CC_USE_FOG == 0\n\tfactor = LinearFog(pos, cc_cameraPos.xyz, cc_fogBase.x, cc_fogBase.y);\n#elif CC_USE_FOG == 1\n\tfactor = ExpFog(pos, cc_cameraPos.xyz, cc_fogBase.x, cc_fogBase.z, cc_fogAdd.z);\n#elif CC_USE_FOG == 2\n\tfactor = ExpSquaredFog(pos, cc_cameraPos.xyz, cc_fogBase.x, cc_fogBase.z, cc_fogAdd.z);\n#elif CC_USE_FOG == 3\n\tfactor = LayeredFog(pos, cc_cameraPos.xyz, cc_fogAdd.x, cc_fogAdd.y, cc_fogAdd.z);\n#else\n\tfactor = 1.0;\n#endif\n}\n#if !CC_USE_ACCURATE_FOG\nlayout(location = 0) out float v_fog_factor;\n#endif\nvoid CC_TRANSFER_FOG(vec4 pos) {\n#if !CC_USE_ACCURATE_FOG\n CC_TRANSFER_FOG_BASE(pos, v_fog_factor);\n#endif\n}\nlayout(location = 1) out highp vec4 v_shadowPos;\nlayout(set = 0, binding = 2) uniform CCShadow {\n highp mat4 cc_matLightView;\n highp mat4 cc_matLightViewProj;\n highp vec4 cc_shadowInvProjDepthInfo;\n highp vec4 cc_shadowProjDepthInfo;\n highp vec4 cc_shadowProjInfo;\n mediump vec4 cc_shadowNFLSInfo;\n mediump vec4 cc_shadowWHPBInfo;\n mediump vec4 cc_shadowLPNNInfo;\n lowp vec4 cc_shadowColor;\n mediump vec4 cc_planarNDInfo;\n};\n#if CC_SUPPORT_CASCADED_SHADOW_MAP\n layout(set = 0, binding = 3) uniform CCCSM {\n highp vec4 cc_csmViewDir0[4];\n highp vec4 cc_csmViewDir1[4];\n highp vec4 cc_csmViewDir2[4];\n highp vec4 cc_csmAtlas[4];\n highp mat4 cc_matCSMViewProj[4];\n highp vec4 cc_csmProjDepthInfo[4];\n highp vec4 cc_csmProjInfo[4];\n highp vec4 cc_csmSplitsInfo;\n };\n#endif\n#if CC_RECEIVE_SHADOW\n layout(set = 0, binding = 4) uniform highp sampler2D cc_shadowMap;\n layout(set = 0, binding = 6) uniform highp sampler2D cc_spotShadowMap;\n #if CC_SUPPORT_CASCADED_SHADOW_MAP\n #else\n #endif\n#endif\n#if CC_RECEIVE_SHADOW\nvec2 CCGetShadowBias()\n{\n #if USE_INSTANCING\n return vec2(a_localShadowBias.x + cc_shadowWHPBInfo.w, a_localShadowBias.y + cc_shadowLPNNInfo.z);\n #elif !USE_BATCHING\n return vec2(cc_localShadowBias.x + cc_shadowWHPBInfo.w, cc_localShadowBias.y + cc_shadowLPNNInfo.z);\n #else\n return vec2(cc_shadowWHPBInfo.w, cc_shadowLPNNInfo.z);\n #endif\n}\n#endif\n#if USE_VERTEX_COLOR\n layout(location = 14) in vec4 a_color;\n layout(location = 2) out vec4 v_color;\n#endif\nlayout(location = 3) out vec3 v_position;\nlayout(location = 4) out vec3 v_normal;\nlayout(location = 5) out vec2 v_uv;\nlayout(location = 6) out vec2 v_uv1;\n#if USE_NORMAL_MAP\n layout(location = 7) out vec3 v_tangent;\n layout(location = 8) out vec3 v_bitangent;\n#endif\n#if CC_RECEIVE_SHADOW\n layout(location = 9) out mediump vec2 v_shadowBias;\n#endif\n#if HAS_SECOND_UV || CC_USE_LIGHTMAP\n layout(location = 15) in vec2 a_texCoord1;\n#endif\n#if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\n layout(location = 10) out vec3 v_luv;\n void CCLightingMapCaclUV()\n {\n #if !USE_INSTANCING\n v_luv.xy = cc_lightingMapUVParam.xy + a_texCoord1 * cc_lightingMapUVParam.z;\n v_luv.z = cc_lightingMapUVParam.w;\n #else\n v_luv.xy = a_lightingMapUVParam.xy + a_texCoord1 * a_lightingMapUVParam.z;\n v_luv.z = a_lightingMapUVParam.w;\n #endif\n }\n#endif\nvoid main () {\n StandardVertInput In;\n CCVertInput(In);\n mat4 matWorld, matWorldIT;\n CCGetWorldMatrixFull(matWorld, matWorldIT);\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_TWOSIDE\n vec3 viewDirect = normalize(cc_cameraPos.xyz - v_position);\n v_normal *= dot(v_normal, viewDirect) < 0.0 ? -1.0 : 1.0;\n #endif\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 CC_TRANSFER_FOG(pos);\n v_shadowPos = cc_matLightViewProj * pos;\n #if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\n CCLightingMapCaclUV();\n #endif\n #if CC_RECEIVE_SHADOW\n v_shadowBias = CCGetShadowBias();\n #endif\n gl_Position = cc_matProj * (cc_matView * matWorld) * In.position;\n}",
|
|
"frag": "\nprecision highp float;\nlayout(set = 0, binding = 0) uniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_nativeSize;\n mediump vec4 cc_debug_view_mode;\n mediump vec4 cc_debug_view_composite_pack_1;\n mediump vec4 cc_debug_view_composite_pack_2;\n mediump vec4 cc_debug_view_composite_pack_3;\n};\nlayout(set = 0, binding = 1) uniform CCCamera {\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_surfaceTransform;\n mediump vec4 cc_screenScale;\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 mediump vec4 cc_nearFar;\n mediump vec4 cc_viewPort;\n};\nlayout(set = 1, binding = 0) uniform Constants {\n vec4 tilingOffset;\n vec4 diffuseColor;\n vec4 specularColor;\n vec4 emissive;\n float alphaThreshold;\n float shininessExponent;\n float glossiness;\n float metallic;\n float normalScale;\n float transparencyFactor;\n float diffuseFactor;\n float specularFactor;\n};\n#if CC_USE_FOG != 4\n float LinearFog(vec4 pos, vec3 cameraPos, float fogStart, float fogEnd) {\n vec4 wPos = pos;\n float cam_dis = distance(cameraPos, wPos.xyz);\n return clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n }\n float ExpFog(vec4 pos, vec3 cameraPos, float fogStart, float fogDensity, float fogAtten) {\n vec4 wPos = pos;\n float cam_dis = max(distance(cameraPos, wPos.xyz) - fogStart, 0.0) / fogAtten * 4.;\n float f = exp(-cam_dis * fogDensity);\n return f;\n }\n float ExpSquaredFog(vec4 pos, vec3 cameraPos, float fogStart, float fogDensity, float fogAtten) {\n vec4 wPos = pos;\n float cam_dis = max(distance(cameraPos, wPos.xyz) - fogStart, 0.0) / fogAtten * 4.;\n float f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\n return f;\n }\n float LayeredFog(vec4 pos, vec3 cameraPos, float fogTop, float fogRange, float fogAtten) {\n vec4 wPos = pos;\n vec3 camWorldProj = 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 (cameraPos.y > fogTop) {\n if (wPos.y < fogTop) {\n fDeltaY = (fogTop - wPos.y) / fogRange * 2.0;\n fDensityIntegral = fDeltaY * fDeltaY * 0.5;\n }\n else {\n fDeltaY = 0.;\n fDensityIntegral = 0.;\n }\n }\n else {\n if (wPos.y < fogTop) {\n float fDeltaA = (fogTop - 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 }\n else {\n fDeltaY = abs(fogTop - 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 }\n else {\n fDensity = 0.;\n }\n float f = exp(-fDensity);\n return f;\n }\n#endif\nvoid CC_TRANSFER_FOG_BASE(vec4 pos, out float factor)\n{\n#if CC_USE_FOG == 0\n\tfactor = LinearFog(pos, cc_cameraPos.xyz, cc_fogBase.x, cc_fogBase.y);\n#elif CC_USE_FOG == 1\n\tfactor = ExpFog(pos, cc_cameraPos.xyz, cc_fogBase.x, cc_fogBase.z, cc_fogAdd.z);\n#elif CC_USE_FOG == 2\n\tfactor = ExpSquaredFog(pos, cc_cameraPos.xyz, cc_fogBase.x, cc_fogBase.z, cc_fogAdd.z);\n#elif CC_USE_FOG == 3\n\tfactor = LayeredFog(pos, cc_cameraPos.xyz, cc_fogAdd.x, cc_fogAdd.y, cc_fogAdd.z);\n#else\n\tfactor = 1.0;\n#endif\n}\nvoid CC_APPLY_FOG_BASE(inout vec4 color, float factor) {\n\tcolor = vec4(mix(cc_fogColor.rgb, color.rgb, factor), color.a);\n}\n#if !CC_USE_ACCURATE_FOG\nlayout(location = 0) in float v_fog_factor;\n#endif\nvoid CC_APPLY_FOG(inout vec4 color) {\n#if !CC_USE_ACCURATE_FOG\n CC_APPLY_FOG_BASE(color, v_fog_factor);\n#endif\n}\nvoid CC_APPLY_FOG(inout vec4 color, vec3 worldPos) {\n#if CC_USE_ACCURATE_FOG\n float factor;\n CC_TRANSFER_FOG_BASE(vec4(worldPos, 1.0), factor);\n#else\n float factor = v_fog_factor;\n#endif\n CC_APPLY_FOG_BASE(color, factor);\n}\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\n#define CC_SURFACES_DEBUG_VIEW_VERTEX_COLOR 1\n#define CC_SURFACES_DEBUG_VIEW_VERTEX_NORMAL CC_SURFACES_DEBUG_VIEW_VERTEX_COLOR + 1\n#define CC_SURFACES_DEBUG_VIEW_VERTEX_TANGENT CC_SURFACES_DEBUG_VIEW_VERTEX_NORMAL + 1\n#define CC_SURFACES_DEBUG_VIEW_WORLD_POS CC_SURFACES_DEBUG_VIEW_VERTEX_TANGENT + 1\n#define CC_SURFACES_DEBUG_VIEW_VERTEX_MIRROR CC_SURFACES_DEBUG_VIEW_WORLD_POS + 1\n#define CC_SURFACES_DEBUG_VIEW_FACE_SIDE CC_SURFACES_DEBUG_VIEW_VERTEX_MIRROR + 1\n#define CC_SURFACES_DEBUG_VIEW_UV0 CC_SURFACES_DEBUG_VIEW_FACE_SIDE + 1\n#define CC_SURFACES_DEBUG_VIEW_UV1 CC_SURFACES_DEBUG_VIEW_UV0 + 1\n#define CC_SURFACES_DEBUG_VIEW_UVLIGHTMAP CC_SURFACES_DEBUG_VIEW_UV1 + 1\n#define CC_SURFACES_DEBUG_VIEW_PROJ_DEPTH CC_SURFACES_DEBUG_VIEW_UVLIGHTMAP + 1\n#define CC_SURFACES_DEBUG_VIEW_LINEAR_DEPTH CC_SURFACES_DEBUG_VIEW_PROJ_DEPTH + 1\n#define CC_SURFACES_DEBUG_VIEW_FRAGMENT_NORMAL CC_SURFACES_DEBUG_VIEW_LINEAR_DEPTH + 1\n#define CC_SURFACES_DEBUG_VIEW_FRAGMENT_TANGENT CC_SURFACES_DEBUG_VIEW_FRAGMENT_NORMAL + 1\n#define CC_SURFACES_DEBUG_VIEW_FRAGMENT_BINORMAL CC_SURFACES_DEBUG_VIEW_FRAGMENT_TANGENT + 1\n#define CC_SURFACES_DEBUG_VIEW_BASE_COLOR CC_SURFACES_DEBUG_VIEW_FRAGMENT_BINORMAL + 1\n#define CC_SURFACES_DEBUG_VIEW_DIFFUSE_COLOR CC_SURFACES_DEBUG_VIEW_BASE_COLOR + 1\n#define CC_SURFACES_DEBUG_VIEW_SPECULAR_COLOR CC_SURFACES_DEBUG_VIEW_DIFFUSE_COLOR + 1\n#define CC_SURFACES_DEBUG_VIEW_TRANSPARENCY CC_SURFACES_DEBUG_VIEW_SPECULAR_COLOR + 1\n#define CC_SURFACES_DEBUG_VIEW_METALLIC CC_SURFACES_DEBUG_VIEW_TRANSPARENCY + 1\n#define CC_SURFACES_DEBUG_VIEW_ROUGHNESS CC_SURFACES_DEBUG_VIEW_METALLIC + 1\n#define CC_SURFACES_DEBUG_VIEW_SPECULAR_INTENSITY CC_SURFACES_DEBUG_VIEW_ROUGHNESS + 1\n#define CC_SURFACES_DEBUG_VIEW_DIRECT_DIFFUSE CC_SURFACES_DEBUG_VIEW_SPECULAR_INTENSITY + 1\n#define CC_SURFACES_DEBUG_VIEW_DIRECT_SPECULAR CC_SURFACES_DEBUG_VIEW_DIRECT_DIFFUSE + 1\n#define CC_SURFACES_DEBUG_VIEW_DIRECT_ALL CC_SURFACES_DEBUG_VIEW_DIRECT_SPECULAR + 1\n#define CC_SURFACES_DEBUG_VIEW_ENV_DIFFUSE CC_SURFACES_DEBUG_VIEW_DIRECT_ALL + 1\n#define CC_SURFACES_DEBUG_VIEW_ENV_SPECULAR CC_SURFACES_DEBUG_VIEW_ENV_DIFFUSE + 1\n#define CC_SURFACES_DEBUG_VIEW_ENV_ALL CC_SURFACES_DEBUG_VIEW_ENV_SPECULAR + 1\n#define CC_SURFACES_DEBUG_VIEW_EMISSIVE CC_SURFACES_DEBUG_VIEW_ENV_ALL + 1\n#define CC_SURFACES_DEBUG_VIEW_LIGHT_MAP CC_SURFACES_DEBUG_VIEW_EMISSIVE + 1\n#define CC_SURFACES_DEBUG_VIEW_SHADOW CC_SURFACES_DEBUG_VIEW_LIGHT_MAP + 1\n#define CC_SURFACES_DEBUG_VIEW_AO CC_SURFACES_DEBUG_VIEW_SHADOW + 1\n#define CC_SURFACES_DEBUG_VIEW_FOG CC_SURFACES_DEBUG_VIEW_AO + 1\n#define CC_SURFACES_DEBUG_VIEW_SINGLE 1\n#define CC_SURFACES_DEBUG_VIEW_COMPOSITE_AND_MISC 2\n#define IS_DEBUG_VIEW_LIGHTING_ENABLE_WITH_ALBEDO (cc_debug_view_mode.y > 0.0)\n#define IS_DEBUG_VIEW_MISC_ENABLE_CSM_LAYER_COLORATION (cc_debug_view_mode.z > 0.0)\n#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_DIRECT_DIFFUSE (cc_debug_view_composite_pack_1.x > 0.0)\n#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_DIRECT_SPECULAR (cc_debug_view_composite_pack_1.y > 0.0)\n#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_ENV_DIFFUSE (cc_debug_view_composite_pack_1.z > 0.0)\n#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_ENV_SPECULAR (cc_debug_view_composite_pack_1.w > 0.0)\n#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_EMISSIVE (cc_debug_view_composite_pack_2.x > 0.0)\n#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_LIGHT_MAP (cc_debug_view_composite_pack_2.y > 0.0)\n#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_SHADOW (cc_debug_view_composite_pack_2.z > 0.0)\n#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_AO (cc_debug_view_composite_pack_2.w > 0.0)\n#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_NORMAL_MAP (cc_debug_view_composite_pack_3.x > 0.0)\n#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_FOG (cc_debug_view_composite_pack_3.y > 0.0)\n#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_TONE_MAPPING (cc_debug_view_composite_pack_3.z > 0.0)\n#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_GAMMA_CORRECTION (cc_debug_view_composite_pack_3.w > 0.0)\nvec3 SRGBToLinear (vec3 gamma) {\n#ifdef CC_USE_SURFACE_SHADER\n #if CC_USE_DEBUG_VIEW == CC_SURFACES_DEBUG_VIEW_COMPOSITE_AND_MISC\n if (!IS_DEBUG_VIEW_COMPOSITE_ENABLE_GAMMA_CORRECTION) {\n return gamma;\n }\n #endif\n#endif\n return gamma * gamma;\n}\nvec3 LinearToSRGB(vec3 linear) {\n#ifdef CC_USE_SURFACE_SHADER\n #if CC_USE_DEBUG_VIEW == CC_SURFACES_DEBUG_VIEW_COMPOSITE_AND_MISC\n if (!IS_DEBUG_VIEW_COMPOSITE_ENABLE_GAMMA_CORRECTION) {\n return linear;\n }\n #endif\n#endif\n return sqrt(linear);\n}\nlayout(set = 0, binding = 2) uniform CCShadow {\n highp mat4 cc_matLightView;\n highp mat4 cc_matLightViewProj;\n highp vec4 cc_shadowInvProjDepthInfo;\n highp vec4 cc_shadowProjDepthInfo;\n highp vec4 cc_shadowProjInfo;\n mediump vec4 cc_shadowNFLSInfo;\n mediump vec4 cc_shadowWHPBInfo;\n mediump vec4 cc_shadowLPNNInfo;\n lowp vec4 cc_shadowColor;\n mediump vec4 cc_planarNDInfo;\n};\n#if CC_SUPPORT_CASCADED_SHADOW_MAP\n layout(set = 0, binding = 3) uniform CCCSM {\n highp vec4 cc_csmViewDir0[4];\n highp vec4 cc_csmViewDir1[4];\n highp vec4 cc_csmViewDir2[4];\n highp vec4 cc_csmAtlas[4];\n highp mat4 cc_matCSMViewProj[4];\n highp vec4 cc_csmProjDepthInfo[4];\n highp vec4 cc_csmProjInfo[4];\n highp vec4 cc_csmSplitsInfo;\n };\n#endif\nfloat GetLinearDepthFromViewSpace(vec3 viewPos, float near, float far) {\n float dist = length(viewPos);\n return (dist - near) / (far - near);\n}\nfloat CCGetLinearDepth(vec3 worldPos, float viewSpaceBias) {\n\tvec4 viewPos = cc_matLightView * vec4(worldPos.xyz, 1.0);\n viewPos.z += viewSpaceBias;\n\treturn GetLinearDepthFromViewSpace(viewPos.xyz, cc_shadowNFLSInfo.x, cc_shadowNFLSInfo.y);\n}\nfloat CCGetLinearDepth(vec3 worldPos) {\n\treturn CCGetLinearDepth(worldPos, 0.0);\n}\n#if CC_RECEIVE_SHADOW\n layout(set = 0, binding = 4) uniform highp sampler2D cc_shadowMap;\n layout(set = 0, binding = 6) uniform highp sampler2D cc_spotShadowMap;\n highp float unpackHighpData (float mainPart, float modPart) {\n highp float data = mainPart;\n return data + modPart;\n }\n void packHighpData (out float mainPart, out float modPart, highp float data) {\n mainPart = fract(data);\n modPart = data - mainPart;\n }\n highp float unpackHighpData (float mainPart, float modPart, const float modValue) {\n highp float data = mainPart * modValue;\n return data + modPart * modValue;\n }\n void packHighpData (out float mainPart, out float modPart, highp float data, const float modValue) {\n highp float divide = data / modValue;\n mainPart = floor(divide);\n modPart = (data - mainPart * modValue) / modValue;\n }\n highp vec2 unpackHighpData (vec2 mainPart, vec2 modPart) {\n highp vec2 data = mainPart;\n return data + modPart;\n }\n void packHighpData (out vec2 mainPart, out vec2 modPart, highp vec2 data) {\n mainPart = fract(data);\n modPart = data - mainPart;\n }\n highp vec2 unpackHighpData (vec2 mainPart, vec2 modPart, const float modValue) {\n highp vec2 data = mainPart * modValue;\n return data + modPart * modValue;\n }\n void packHighpData (out vec2 mainPart, out vec2 modPart, highp vec2 data, const float modValue) {\n highp vec2 divide = data / modValue;\n mainPart = floor(divide);\n modPart = (data - mainPart * modValue) / modValue;\n }\n highp vec3 unpackHighpData (vec3 mainPart, vec3 modPart) {\n highp vec3 data = mainPart;\n return data + modPart;\n }\n void packHighpData (out vec3 mainPart, out vec3 modPart, highp vec3 data) {\n mainPart = fract(data);\n modPart = data - mainPart;\n }\n highp vec3 unpackHighpData (vec3 mainPart, vec3 modPart, const float modValue) {\n highp vec3 data = mainPart * modValue;\n return data + modPart * modValue;\n }\n void packHighpData (out vec3 mainPart, out vec3 modPart, highp vec3 data, const float modValue) {\n highp vec3 divide = data / modValue;\n mainPart = floor(divide);\n modPart = (data - mainPart * modValue) / modValue;\n }\n highp vec4 unpackHighpData (vec4 mainPart, vec4 modPart) {\n highp vec4 data = mainPart;\n return data + modPart;\n }\n void packHighpData (out vec4 mainPart, out vec4 modPart, highp vec4 data) {\n mainPart = fract(data);\n modPart = data - mainPart;\n }\n highp vec4 unpackHighpData (vec4 mainPart, vec4 modPart, const float modValue) {\n highp vec4 data = mainPart * modValue;\n return data + modPart * modValue;\n }\n void packHighpData (out vec4 mainPart, out vec4 modPart, highp vec4 data, const float modValue) {\n highp vec4 divide = data / modValue;\n mainPart = floor(divide);\n modPart = (data - mainPart * modValue) / modValue;\n }\n float NativePCFShadowFactorHard (vec3 shadowNDCPos, sampler2D shadowMap, vec2 shadowMapResolution)\n {\n #if CC_SHADOWMAP_FORMAT == 1\n return step(shadowNDCPos.z, dot(texture(shadowMap, shadowNDCPos.xy), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n #else\n return step(shadowNDCPos.z, texture(shadowMap, shadowNDCPos.xy).x);\n #endif\n }\n float NativePCFShadowFactorSoft (vec3 shadowNDCPos, sampler2D shadowMap, vec2 shadowMapResolution)\n {\n vec2 oneTap = 1.0 / shadowMapResolution;\n vec2 shadowNDCPos_offset = shadowNDCPos.xy + oneTap;\n float block0, block1, block2, block3;\n #if CC_SHADOWMAP_FORMAT == 1\n block0 = step(shadowNDCPos.z, dot(texture(shadowMap, vec2(shadowNDCPos.x, shadowNDCPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n block1 = step(shadowNDCPos.z, dot(texture(shadowMap, vec2(shadowNDCPos_offset.x, shadowNDCPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n block2 = step(shadowNDCPos.z, dot(texture(shadowMap, vec2(shadowNDCPos.x, shadowNDCPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n block3 = step(shadowNDCPos.z, dot(texture(shadowMap, vec2(shadowNDCPos_offset.x, shadowNDCPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n #else\n block0 = step(shadowNDCPos.z, texture(shadowMap, vec2(shadowNDCPos.x, shadowNDCPos.y)).x);\n block1 = step(shadowNDCPos.z, texture(shadowMap, vec2(shadowNDCPos_offset.x, shadowNDCPos.y)).x);\n block2 = step(shadowNDCPos.z, texture(shadowMap, vec2(shadowNDCPos.x, shadowNDCPos_offset.y)).x);\n block3 = step(shadowNDCPos.z, texture(shadowMap, vec2(shadowNDCPos_offset.x, shadowNDCPos_offset.y)).x);\n #endif\n float coefX = mod(shadowNDCPos.x, oneTap.x) * shadowMapResolution.x;\n float resultX = mix(block0, block1, coefX);\n float resultY = mix(block2, block3, coefX);\n float coefY = mod(shadowNDCPos.y, oneTap.y) * shadowMapResolution.y;\n return mix(resultX, resultY, coefY);\n }\n float NativePCFShadowFactorSoft3X (vec3 shadowNDCPos, sampler2D shadowMap, vec2 shadowMapResolution)\n {\n vec2 oneTap = 1.0 / shadowMapResolution;\n float shadowNDCPos_offset_L = shadowNDCPos.x - oneTap.x;\n float shadowNDCPos_offset_R = shadowNDCPos.x + oneTap.x;\n float shadowNDCPos_offset_U = shadowNDCPos.y - oneTap.y;\n float shadowNDCPos_offset_D = shadowNDCPos.y + oneTap.y;\n float block0, block1, block2, block3, block4, block5, block6, block7, block8;\n #if CC_SHADOWMAP_FORMAT == 1\n block0 = step(shadowNDCPos.z, dot(texture(shadowMap, vec2(shadowNDCPos_offset_L, shadowNDCPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n block1 = step(shadowNDCPos.z, dot(texture(shadowMap, vec2(shadowNDCPos.x, shadowNDCPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n block2 = step(shadowNDCPos.z, dot(texture(shadowMap, vec2(shadowNDCPos_offset_R, shadowNDCPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n block3 = step(shadowNDCPos.z, dot(texture(shadowMap, vec2(shadowNDCPos_offset_L, shadowNDCPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n block4 = step(shadowNDCPos.z, dot(texture(shadowMap, vec2(shadowNDCPos.x, shadowNDCPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n block5 = step(shadowNDCPos.z, dot(texture(shadowMap, vec2(shadowNDCPos_offset_R, shadowNDCPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n block6 = step(shadowNDCPos.z, dot(texture(shadowMap, vec2(shadowNDCPos_offset_L, shadowNDCPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n block7 = step(shadowNDCPos.z, dot(texture(shadowMap, vec2(shadowNDCPos.x, shadowNDCPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n block8 = step(shadowNDCPos.z, dot(texture(shadowMap, vec2(shadowNDCPos_offset_R, shadowNDCPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n #else\n block0 = step(shadowNDCPos.z, texture(shadowMap, vec2(shadowNDCPos_offset_L, shadowNDCPos_offset_U)).x);\n block1 = step(shadowNDCPos.z, texture(shadowMap, vec2(shadowNDCPos.x, shadowNDCPos_offset_U)).x);\n block2 = step(shadowNDCPos.z, texture(shadowMap, vec2(shadowNDCPos_offset_R, shadowNDCPos_offset_U)).x);\n block3 = step(shadowNDCPos.z, texture(shadowMap, vec2(shadowNDCPos_offset_L, shadowNDCPos.y)).x);\n block4 = step(shadowNDCPos.z, texture(shadowMap, vec2(shadowNDCPos.x, shadowNDCPos.y)).x);\n block5 = step(shadowNDCPos.z, texture(shadowMap, vec2(shadowNDCPos_offset_R, shadowNDCPos.y)).x);\n block6 = step(shadowNDCPos.z, texture(shadowMap, vec2(shadowNDCPos_offset_L, shadowNDCPos_offset_D)).x);\n block7 = step(shadowNDCPos.z, texture(shadowMap, vec2(shadowNDCPos.x, shadowNDCPos_offset_D)).x);\n block8 = step(shadowNDCPos.z, texture(shadowMap, vec2(shadowNDCPos_offset_R, shadowNDCPos_offset_D)).x);\n #endif\n float coefX = mod(shadowNDCPos.x, oneTap.x) * shadowMapResolution.x;\n float coefY = mod(shadowNDCPos.y, oneTap.y) * shadowMapResolution.y;\n float shadow = 0.0;\n float resultX = mix(block0, block1, coefX);\n float resultY = mix(block3, block4, coefX);\n shadow += mix(resultX , resultY, coefY);\n resultX = mix(block1, block2, coefX);\n resultY = mix(block4, block5, coefX);\n shadow += mix(resultX , resultY, coefY);\n resultX = mix(block3, block4, coefX);\n resultY = mix(block6, block7, coefX);\n shadow += mix(resultX, resultY, coefY);\n resultX = mix(block4, block5, coefX);\n resultY = mix(block7, block8, coefX);\n shadow += mix(resultX, resultY, coefY);\n return shadow * 0.25;\n }\n bool GetShadowNDCPos(out vec3 shadowNDCPos, vec4 shadowPosWithDepthBias)\n {\n \tshadowNDCPos = shadowPosWithDepthBias.xyz / shadowPosWithDepthBias.w * 0.5 + 0.5;\n \tif (shadowNDCPos.x < 0.0 || shadowNDCPos.x > 1.0 ||\n \t\tshadowNDCPos.y < 0.0 || shadowNDCPos.y > 1.0 ||\n \t\tshadowNDCPos.z < 0.0 || shadowNDCPos.z > 1.0) {\n \t\treturn false;\n \t}\n \tshadowNDCPos.xy = cc_cameraPos.w == 1.0 ? vec2(shadowNDCPos.xy.x, 1.0 - shadowNDCPos.xy.y) : shadowNDCPos.xy;\n \treturn true;\n }\n vec4 ApplyShadowDepthBias_FaceNormal(vec4 shadowPos, vec3 worldNormal, float normalBias, vec3 matViewDir0, vec3 matViewDir1, vec3 matViewDir2, vec2 projScaleXY)\n {\n vec4 newShadowPos = shadowPos;\n if (normalBias > EPSILON_LOWP)\n {\n vec3 viewNormal = vec3(dot(matViewDir0, worldNormal), dot(matViewDir1, worldNormal), dot(matViewDir2, worldNormal));\n if (viewNormal.z < 0.1)\n newShadowPos.xy += viewNormal.xy * projScaleXY * normalBias * clamp(viewNormal.z, 0.001, 0.1);\n }\n return newShadowPos;\n }\n vec4 ApplyShadowDepthBias_FaceNormal(vec4 shadowPos, vec3 worldNormal, float normalBias, mat4 matLightView, vec2 projScaleXY)\n {\n \tvec4 newShadowPos = shadowPos;\n \tif (normalBias > EPSILON_LOWP)\n \t{\n \t\tvec4 viewNormal = matLightView * vec4(worldNormal, 0.0);\n \t\tif (viewNormal.z < 0.1)\n \t\t\tnewShadowPos.xy += viewNormal.xy * projScaleXY * normalBias * clamp(viewNormal.z, 0.001, 0.1);\n \t}\n \treturn newShadowPos;\n }\n vec4 ApplyShadowDepthBias_Perspective(vec4 shadowPos, float viewspaceDepthBias)\n {\n \tvec3 viewSpacePos;\n \tviewSpacePos.xy = shadowPos.xy * cc_shadowProjInfo.zw;\n \tviewSpacePos.z = shadowPos.z * cc_shadowInvProjDepthInfo.x + shadowPos.w * cc_shadowInvProjDepthInfo.y;\n \tviewSpacePos.xyz += cc_shadowProjDepthInfo.z * normalize(viewSpacePos.xyz) * viewspaceDepthBias;\n \tvec4 clipSpacePos;\n \tclipSpacePos.xy = viewSpacePos.xy * cc_shadowProjInfo.xy;\n \tclipSpacePos.zw = viewSpacePos.z * cc_shadowProjDepthInfo.xz + vec2(cc_shadowProjDepthInfo.y, 0.0);\n \t#if CC_SHADOWMAP_USE_LINEAR_DEPTH\n \t\tclipSpacePos.z = GetLinearDepthFromViewSpace(viewSpacePos.xyz, cc_shadowNFLSInfo.x, cc_shadowNFLSInfo.y);\n \t\tclipSpacePos.z = (clipSpacePos.z * 2.0 - 1.0) * clipSpacePos.w;\n \t#endif\n \treturn clipSpacePos;\n }\n vec4 ApplyShadowDepthBias_Orthographic(vec4 shadowPos, float viewspaceDepthBias, float projScaleZ, float projBiasZ)\n {\n \tfloat coeffA = projScaleZ;\n \tfloat coeffB = projBiasZ;\n \tfloat viewSpacePos_z = (shadowPos.z - coeffB) / coeffA;\n \tviewSpacePos_z += viewspaceDepthBias;\n \tvec4 result = shadowPos;\n \tresult.z = viewSpacePos_z * coeffA + coeffB;\n \treturn result;\n }\n vec4 ApplyShadowDepthBias_PerspectiveLinearDepth(vec4 shadowPos, float viewspaceDepthBias, vec3 worldPos)\n {\n shadowPos.z = CCGetLinearDepth(worldPos, viewspaceDepthBias) * 2.0 - 1.0;\n shadowPos.z *= shadowPos.w;\n return shadowPos;\n }\n float CCGetDirLightShadowFactorHard (vec4 shadowPosWithDepthBias) {\n\t vec3 shadowNDCPos;\n\t if (!GetShadowNDCPos(shadowNDCPos, shadowPosWithDepthBias)) {\n\t\t return 1.0;\n\t }\n return NativePCFShadowFactorHard(shadowNDCPos, cc_shadowMap, cc_shadowWHPBInfo.xy);\n }\n float CCGetDirLightShadowFactorSoft (vec4 shadowPosWithDepthBias) {\n\t vec3 shadowNDCPos;\n\t if (!GetShadowNDCPos(shadowNDCPos, shadowPosWithDepthBias)) {\n\t\t return 1.0;\n\t }\n return NativePCFShadowFactorSoft(shadowNDCPos, cc_shadowMap, cc_shadowWHPBInfo.xy);\n }\n float CCGetDirLightShadowFactorSoft3X (vec4 shadowPosWithDepthBias) {\n\t vec3 shadowNDCPos;\n\t if (!GetShadowNDCPos(shadowNDCPos, shadowPosWithDepthBias)) {\n\t\t return 1.0;\n\t }\n return NativePCFShadowFactorSoft3X(shadowNDCPos, cc_shadowMap, cc_shadowWHPBInfo.xy);\n }\n float CCGetSpotLightShadowFactorHard (vec4 shadowPosWithDepthBias, vec3 worldPos) {\n\t vec3 shadowNDCPos;\n\t if (!GetShadowNDCPos(shadowNDCPos, shadowPosWithDepthBias)) {\n\t\t return 1.0;\n\t }\n return NativePCFShadowFactorHard(shadowNDCPos, cc_spotShadowMap, cc_shadowWHPBInfo.xy);\n }\n float CCGetSpotLightShadowFactorSoft (vec4 shadowPosWithDepthBias, vec3 worldPos) {\n\t vec3 shadowNDCPos;\n\t if (!GetShadowNDCPos(shadowNDCPos, shadowPosWithDepthBias)) {\n\t\t return 1.0;\n\t }\n return NativePCFShadowFactorSoft(shadowNDCPos, cc_spotShadowMap, cc_shadowWHPBInfo.xy);\n }\n float CCGetSpotLightShadowFactorSoft3X (vec4 shadowPosWithDepthBias, vec3 worldPos) {\n\t vec3 shadowNDCPos;\n\t if (!GetShadowNDCPos(shadowNDCPos, shadowPosWithDepthBias)) {\n\t\t return 1.0;\n\t }\n return NativePCFShadowFactorSoft3X(shadowNDCPos, cc_spotShadowMap, cc_shadowWHPBInfo.xy);\n }\n float CCSpotShadowFactorBase(vec4 shadowPos, vec3 worldPos, vec2 shadowBias)\n {\n float pcf = cc_shadowWHPBInfo.z;\n vec4 pos = vec4(1.0);\n #if CC_SHADOWMAP_USE_LINEAR_DEPTH\n pos = ApplyShadowDepthBias_PerspectiveLinearDepth(shadowPos, shadowBias.x, worldPos);\n #else\n pos = ApplyShadowDepthBias_Perspective(shadowPos, shadowBias.x);\n #endif\n if (pcf > 1.9) {\n return CCGetSpotLightShadowFactorSoft3X(pos, worldPos);\n }else if (pcf > 0.9) {\n return CCGetSpotLightShadowFactorSoft(pos, worldPos);\n }else {\n return CCGetSpotLightShadowFactorHard(pos, worldPos);\n }\n }\n float CCShadowFactorBase(vec4 shadowPos, vec3 N, vec2 shadowBias)\n {\n float realtimeShadow = 1.0;\n vec4 pos = ApplyShadowDepthBias_FaceNormal(shadowPos, N, shadowBias.y, cc_matLightView, cc_shadowProjInfo.xy);\n pos = ApplyShadowDepthBias_Orthographic(pos, shadowBias.x, cc_shadowProjDepthInfo.x, cc_shadowProjDepthInfo.y);\n float pcf = cc_shadowWHPBInfo.z;\n if (pcf > 1.9) {\n realtimeShadow = CCGetDirLightShadowFactorSoft3X(pos);\n }else if (pcf > 0.9) {\n realtimeShadow = CCGetDirLightShadowFactorSoft(pos);\n }else {\n realtimeShadow = CCGetDirLightShadowFactorHard(pos);\n }\n return mix(realtimeShadow, 1.0, cc_shadowNFLSInfo.w);\n }\n #if CC_SUPPORT_CASCADED_SHADOW_MAP\n int CCGetCSMLevel(out vec4 csmPos, out vec4 shadowProjDepthInfo, out vec4 shadowProjInfo, out vec3 shadowViewDir0, out vec3 shadowViewDir1, out vec3 shadowViewDir2, vec3 worldPos) {\n int layer = -1;\n highp float layerThreshold = cc_csmViewDir0[0].w;\n for (int i = 0; i < 4; i++) {\n vec4 shadowPos = cc_matCSMViewProj[i] * vec4(worldPos.xyz, 1.0);\n vec3 clipPos = shadowPos.xyz / shadowPos.w * 0.5 + 0.5;\n if (clipPos.x >= (0.0 + layerThreshold) && clipPos.x <= (1.0 - layerThreshold) &&\n clipPos.y >= (0.0 + layerThreshold) && clipPos.y <= (1.0 - layerThreshold) &&\n clipPos.z >= 0.0 && clipPos.z <= 1.0 && layer < 0) {\n csmPos = cc_matCSMViewProj[i] * vec4(worldPos.xyz, 1.0);\n csmPos.xy = csmPos.xy * cc_csmAtlas[i].xy + cc_csmAtlas[i].zw;\n shadowProjDepthInfo = cc_csmProjDepthInfo[i];\n shadowProjInfo = cc_csmProjInfo[i];\n shadowViewDir0 = cc_csmViewDir0[i].xyz;\n shadowViewDir1 = cc_csmViewDir1[i].xyz;\n shadowViewDir2 = cc_csmViewDir2[i].xyz;\n layer = i;\n }\n }\n return layer;\n }\n float CCCSMFactorBase(vec3 worldPos, vec3 N, vec2 shadowBias)\n {\n vec4 csmPos = vec4(1.0);\n vec4 shadowProjDepthInfo, shadowProjInfo;\n vec3 shadowViewDir0, shadowViewDir1, shadowViewDir2;\n int level = CCGetCSMLevel(csmPos, shadowProjDepthInfo, shadowProjInfo, shadowViewDir0, shadowViewDir1, shadowViewDir2, worldPos);\n if (level < 0) { return 1.0; }\n float realtimeShadow = 1.0;\n vec4 pos = ApplyShadowDepthBias_FaceNormal(csmPos, N, shadowBias.y, shadowViewDir0, shadowViewDir1, shadowViewDir2, shadowProjInfo.xy);\n pos = ApplyShadowDepthBias_Orthographic(pos, shadowBias.x, shadowProjDepthInfo.x, shadowProjDepthInfo.y);\n float pcf = cc_shadowWHPBInfo.z;\n if (pcf > 1.9) {\n realtimeShadow = CCGetDirLightShadowFactorSoft3X(pos);\n } else if (pcf > 0.9) {\n realtimeShadow = CCGetDirLightShadowFactorSoft(pos);\n }else {\n realtimeShadow = CCGetDirLightShadowFactorHard(pos);\n }\n return mix(realtimeShadow, 1.0, cc_shadowNFLSInfo.w);\n }\n #else\n int CCGetCSMLevel(out vec4 csmPos, out vec4 shadowProjDepthInfo, out vec4 shadowProjInfo, out vec3 shadowViewDir0, out vec3 shadowViewDir1, out vec3 shadowViewDir2, vec3 worldPos) {\n return -1;\n }\n float CCCSMFactorBase(vec3 worldPos, vec3 N, vec2 shadowBias) {\n vec4 shadowPos = cc_matLightViewProj * vec4(worldPos, 1.0);\n return CCShadowFactorBase(shadowPos, N, shadowBias);\n }\n #endif\n#endif\n#if CC_USE_IBL\n layout(set = 0, binding = 5) uniform samplerCube cc_environment;\n vec4 fragTextureLod (sampler2D tex, vec2 coord, float lod) {\n return textureLod(tex, coord, lod);\n }\n vec4 fragTextureLod (samplerCube tex, vec3 coord, float lod) {\n return textureLod(tex, coord, lod);\n }\n vec3 unpackRGBE (vec4 rgbe) {\n return rgbe.rgb * pow(1.1, rgbe.a * 255.0 - 128.0);\n }\n #if CC_USE_DIFFUSEMAP\n layout(set = 0, binding = 7) uniform samplerCube cc_diffuseMap;\n #endif\n#endif\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}\n#if USE_REFLECTION_DENOISE\n vec3 GetEnvReflectionWithMipFiltering(vec3 R, float roughness, float mipCount, float denoiseIntensity) {\n #if CC_USE_IBL\n \tfloat mip = roughness * (mipCount - 1.0);\n \tfloat delta = (dot(dFdx(R), dFdy(R))) * 1000.0;\n \tfloat mipBias = mix(0.0, 5.0, clamp(delta, 0.0, 1.0));\n \tvec4 biased = fragTextureLod(cc_environment, R, mip + mipBias);\n \tvec4 filtered = texture(cc_environment, R);\n #if CC_USE_IBL == 2\n \tbiased.rgb = unpackRGBE(biased);\n \tfiltered.rgb = unpackRGBE(filtered);\n #else\n \tbiased.rgb = SRGBToLinear(biased.rgb);\n \tfiltered.rgb = SRGBToLinear(filtered.rgb);\n #endif\n return mix(biased.rgb, filtered.rgb, denoiseIntensity);\n #else\n return vec3(0.0, 0.0, 0.0);\n #endif\n }\n#endif\nstruct StandardSurface {\n vec4 albedo;\n #if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\n vec3 position, position_fract_part;\n #else\n vec3 position;\n #endif\n vec3 normal;\n vec3 emissive;\n vec3 lightmap;\n float lightmap_test;\n float roughness;\n float metallic;\n float occlusion;\n float specularIntensity;\n #if CC_RECEIVE_SHADOW\n vec2 shadowBias;\n #endif\n};\nvec4 CCStandardShadingBase (StandardSurface s, vec4 shadowPos) {\n vec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\n vec3 specular = mix(vec3(0.08 * s.specularIntensity), s.albedo.rgb, s.metallic);\n vec3 position;\n #if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\n position = unpackHighpData(s.position, s.position_fract_part);\n #else\n position = s.position;\n #endif\n vec3 N = normalize(s.normal);\n vec3 V = normalize(cc_cameraPos.xyz - position);\n vec3 L = normalize(-cc_mainLitDir.xyz);\n float NL = max(dot(N, L), 0.0);\n float shadow = 1.0;\n #if CC_RECEIVE_SHADOW\n if (NL > 0.0 && cc_mainLitDir.w > 0.0) {\n if (cc_shadowLPNNInfo.w > 0.0) {\n shadow = CCCSMFactorBase(position, N, s.shadowBias);\n } else {\n shadow = CCShadowFactorBase(shadowPos, N, s.shadowBias);\n }\n }\n #endif\n #if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\n vec3 finalColor = diffuse * s.lightmap.rgb * shadow;\n #else\n float NV = max(abs(dot(N, V)), 0.0);\n specular = BRDFApprox(specular, s.roughness, NV);\n vec3 H = normalize(L + V);\n float NH = max(dot(N, H), 0.0);\n vec3 finalColor = NL * cc_mainLitColor.rgb * cc_mainLitColor.w;\n vec3 diffuseContrib = diffuse / PI;\n vec3 specularContrib = specular * CalcSpecular(s.roughness, NH, H, N);\n vec3 dirlightContrib = (diffuseContrib + specularContrib);\n dirlightContrib *= shadow;\n finalColor *= dirlightContrib;\n #endif\n float fAmb = 0.5 - N.y * 0.5;\n vec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb);\n #if CC_USE_IBL\n #if CC_USE_DIFFUSEMAP\n vec4 diffuseMap = texture(cc_diffuseMap, N);\n #if CC_USE_DIFFUSEMAP == 2\n ambDiff = unpackRGBE(diffuseMap);\n #else\n ambDiff = SRGBToLinear(diffuseMap.rgb);\n #endif\n #endif\n vec3 R = normalize(reflect(-V, N));\n #if USE_REFLECTION_DENOISE && !CC_IBL_CONVOLUTED\n vec3 env = GetEnvReflectionWithMipFiltering(R, s.roughness, cc_ambientGround.w, 0.6);\n #else\n vec4 envmap = fragTextureLod(cc_environment, R, s.roughness * (cc_ambientGround.w - 1.0));\n #if CC_USE_IBL == 2\n vec3 env = unpackRGBE(envmap);\n #else\n vec3 env = SRGBToLinear(envmap.rgb);\n #endif\n #endif\n finalColor += env * cc_ambientSky.w * specular * s.occlusion;\n #endif\n finalColor += ambDiff.rgb * cc_ambientSky.w * diffuse * s.occlusion;\n finalColor += s.emissive;\n return vec4(finalColor, s.albedo.a);\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 = ACESToneMap(color.rgb);\n #endif\n color.rgb = LinearToSRGB(color.rgb);\n return color;\n}\nlayout(location = 1) in highp vec4 v_shadowPos;\n#if CC_RECEIVE_SHADOW\n#endif\nbool GetMetallicAlbedoFromDiffuseSpecularWithoutColor(out float metallic, out vec3 albedo, vec3 diffuse, vec3 specular, float f0 )\n{\n\tfloat d = max(max(diffuse.x, diffuse.y), diffuse.z);\n\tvec3 normalizedColor = diffuse / (d + (d < EPSILON_LOWP ? EPSILON_LOWP : 0.0));\n\tnormalizedColor = d < EPSILON_LOWP ? specular : normalizedColor;\n\tfloat s = max(max(specular.x, specular.y), specular.z);\n\tfloat delta = (d + s) * (d + s) - 4.0 * f0 * d;\n\tfloat deltaSqrt = sqrt(max(0.0, delta));\n\tfloat solverMetallic = (-d - s + 2.0 * f0 + deltaSqrt) / (2.0 * f0);\n\tvec3 solverAlbedo = (d + s) * normalizedColor - vec3(f0 * (1.0 - solverMetallic));\n\tbool isValidSolver = delta >= 0.0;\n\tmetallic = isValidSolver ? clamp(solverMetallic, 0.0, 1.0) : 0.0;\n\talbedo = isValidSolver ? vec3(max(0.0, solverAlbedo.x), max(0.0, solverAlbedo.y), max(0.0, solverAlbedo.z)) : diffuse;\n\treturn isValidSolver;\n}\n#if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\n layout(location = 10) in vec3 v_luv;\n layout(set = 2, binding = 10) uniform sampler2D cc_lightingMap;\n#endif\nlayout(location = 3) in vec3 v_position;\nlayout(location = 5) in vec2 v_uv;\nlayout(location = 6) in vec2 v_uv1;\nlayout(location = 4) in vec3 v_normal;\n#if CC_RECEIVE_SHADOW\n layout(location = 9) in mediump vec2 v_shadowBias;\n#endif\n#define DCC_APP_OTHERS 0\n#define DCC_APP_AUTODESK 1\n#define DCC_APP_BLENDER 2\n#define DCC_APP_CINEMA4D 3\n#define DCC_APP_GLTF 4\n#if USE_SHININESS_MAP\n layout(set = 1, binding = 1) uniform sampler2D shininessExponentMap;\n#endif\n#if USE_SPECULAR_GLOSSINESS_MAP\n layout(set = 1, binding = 2) uniform sampler2D specularGlossinessMap;\n#endif\n#if USE_SPECULAR_MAP\n layout(set = 1, binding = 3) uniform sampler2D specularMap;\n#endif\n #if USE_METALLIC_MAP\n layout(set = 1, binding = 4) uniform sampler2D metallicMap;\n#endif\n#if USE_VERTEX_COLOR\n layout(location = 2) in vec4 v_color;\n#endif\n#if USE_ALBEDO_MAP\n layout(set = 1, binding = 5) uniform sampler2D albedoMap;\n#endif\n#if USE_TRANSPARENCY_MAP\n layout(set = 1, binding = 6) uniform sampler2D transparencyMap;\n#endif\n#if USE_NORMAL_MAP\n layout(location = 7) in vec3 v_tangent;\n layout(location = 8) in vec3 v_bitangent;\n layout(set = 1, binding = 7) uniform sampler2D normalMap;\n#endif\n#if USE_EMISSIVE_MAP\n layout(set = 1, binding = 8) uniform sampler2D emissiveMap;\n#endif\nfloat discolor(vec3 srcColor) {\n return dot(GRAY_VECTOR, srcColor);\n}\nfloat convertShininessExponent(float shininessExp)\n{\n #if DCC_APP_NAME == DCC_APP_BLENDER\n float glossiness = clamp(sqrt(shininessExp) * 0.1, 0.0, 0.95);\n #elif DCC_APP_NAME == DCC_APP_AUTODESK\n float l2 = clamp(log(shininessExp + EPSILON) * 0.1442695 , 0.0, 1.0);\n float glossiness = pow(l2, 0.5);\n #else\n float glossiness = clamp(log(shininessExp + EPSILON) * 0.1442695 , 0.0, 1.0);\n #endif\n return glossiness;\n}\nfloat getSpecularIntensityFromRoughness(float roughness)\n{\n #if DCC_APP_NAME == DCC_APP_BLENDER\n float specularIntensityMultiplier = mix(1.0, 5.0, roughness);\n #elif DCC_APP_NAME == DCC_APP_CINEMA4D\n float specularIntensityMultiplier = mix(1.0, 50.0, roughness);\n #elif DCC_APP_NAME == DCC_APP_AUTODESK\n float specularIntensityMultiplier = mix(1.0, 20.0, roughness);\n #else\n float specularIntensityMultiplier = 1.0;\n #endif\n return specularIntensityMultiplier;\n}\nvec4 getSpecularColorAndFactor()\n{\n vec3 inSpecular = specularColor.rgb;\n #if USE_SPECULAR_GLOSSINESS_MAP\n inSpecular = SRGBToLinear(texture(specularGlossinessMap, TEXTURE_UV).rgb);\n #endif\n #if USE_SPECULAR_MAP\n vec4 specularTex = texture(specularMap, TEXTURE_UV);\n specularTex.rgb = SRGBToLinear(specularTex.rgb);\n inSpecular = specularTex.rgb;\n #endif\n return vec4(inSpecular, specularFactor);\n}\nvoid surf (out StandardSurface s) {\n vec4 baseColor = vec4(1.0);\n #if USE_VERTEX_COLOR\n baseColor.rgb *= SRGBToLinear(v_color.rgb);\n baseColor.a *= v_color.a;\n #endif\n #if USE_ALBEDO_MAP\n vec4 texColor = texture(albedoMap, TEXTURE_UV);\n texColor.rgb = SRGBToLinear(texColor.rgb);\n texColor.a *= transparencyFactor;\n baseColor *= texColor;\n #else\n baseColor *= diffuseColor;\n #endif\n baseColor.rgb *= diffuseFactor;\n #if USE_TRANSPARENCY_MAP\n baseColor.a = texture(transparencyMap, TEXTURE_UV).a;\n #endif\n #if USE_ALPHA_TEST\n if (baseColor.a < alphaThreshold) discard;\n #endif\n #if CC_RECEIVE_SHADOW\n s.shadowBias = v_shadowBias;\n #endif\n vec4 specularColorAndFactor = getSpecularColorAndFactor();\n float inGlossiness = 0.0, inSpecularIntensity = specularColorAndFactor.w;\n #if HAS_EXPORTED_GLOSSINESS\n #if USE_SPECULAR_GLOSSINESS_MAP\n inGlossiness = 1.0 - texture(specularGlossinessMap, TEXTURE_UV).a;\n #else\n inGlossiness = glossiness;\n #endif\n #else\n #if USE_SHININESS_MAP\n #if USE_SHININESS_MAP_CHANNEL\n inGlossiness = 1.0 - texture(shininessExponentMap, TEXTURE_UV).SHININESS_MAP_CHANNEL;\n #else\n inGlossiness = 1.0 - discolor(texture(shininessExponentMap, TEXTURE_UV).rgb);\n #endif\n #else\n inGlossiness = convertShininessExponent(shininessExponent);\n #endif\n inSpecularIntensity *= getSpecularIntensityFromRoughness(1.0 - inGlossiness);\n #endif\n float inMetallic = 0.0;\n vec4 albedo = baseColor;\n #if HAS_EXPORTED_METALLIC\n inMetallic = metallic;\n float spec = specularFactor;\n #if USE_SPECULAR_MAP\n spec = dot(GRAY_VECTOR, texture(specularMap, TEXTURE_UV).rgb);\n #endif\n inSpecularIntensity *= spec * 0.5;\n #else\n GetMetallicAlbedoFromDiffuseSpecularWithoutColor(inMetallic, albedo.rgb, baseColor.rgb, specularColorAndFactor.rgb, 0.04);\n inSpecularIntensity *= inMetallic;\n #endif\n s.normal = v_normal;\n #if USE_NORMAL_MAP\n vec3 nmmp = texture(normalMap, TEXTURE_UV).xyz - vec3(0.5);\n s.normal =\n (nmmp.x * normalScale) * normalize(v_tangent) +\n (nmmp.y * normalScale) * normalize(v_bitangent) +\n nmmp.z * normalize(s.normal);\n #endif\n #if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\n packHighpData(s.position, s.position_fract_part, v_position);\n #else\n s.position = v_position;\n #endif\n s.albedo = albedo;\n s.occlusion = 1.0;\n s.roughness = 1.0 - inGlossiness;\n s.metallic = inMetallic;\n s.specularIntensity = inSpecularIntensity * 0.5;\n s.emissive = vec3(0.0);\n#if USE_EMISSIVE_MAP\n s.emissive = texture(emissiveMap, TEXTURE_UV).xyz;\n#endif\n #if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\n vec4 lightColor = texture(cc_lightingMap, v_luv.xy);\n s.lightmap = lightColor.xyz * v_luv.z;\n s.lightmap_test = v_luv.z;\n #endif\n}\n#if CC_FORWARD_ADD\n #if CC_PIPELINE_TYPE == 0\n #define LIGHTS_PER_PASS 1\n #else\n #define LIGHTS_PER_PASS 10\n #endif\n #if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 0\n layout(set = 2, binding = 1) uniform CCForwardLight {\n highp vec4 cc_lightPos[LIGHTS_PER_PASS];\n vec4 cc_lightColor[LIGHTS_PER_PASS];\n vec4 cc_lightSizeRangeAngle[LIGHTS_PER_PASS];\n vec4 cc_lightDir[LIGHTS_PER_PASS];\n };\n #endif\n float 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 }\n float 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 }\n float 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 #if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 0\n vec4 CCStandardShadingAdditive (StandardSurface s, vec4 shadowPos) {\n vec3 position;\n #if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\n position = unpackHighpData(s.position, s.position_fract_part);\n #else\n position = s.position;\n #endif\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 / PI;\n vec3 N = normalize(s.normal);\n vec3 V = normalize(cc_cameraPos.xyz - position);\n float NV = max(abs(dot(N, V)), 0.0);\n specular = BRDFApprox(specular, s.roughness, NV);\n vec3 finalColor = vec3(0.0);\n int numLights = CC_PIPELINE_TYPE == 0 ? LIGHTS_PER_PASS : int(cc_lightDir[0].w);\n for (int i = 0; i < LIGHTS_PER_PASS; i++) {\n if (i >= numLights) break;\n vec3 SLU = cc_lightPos[i].xyz - position;\n vec3 SL = normalize(SLU);\n vec3 SH = normalize(SL + V);\n float SNL = max(dot(N, SL), 0.0);\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 = 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_lightPos[i].w > 0.0) {\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 }\n vec3 lightColor = cc_lightColor[i].rgb;\n float shadow = 1.0;\n #if CC_RECEIVE_SHADOW\n if (cc_lightPos[i].w > 0.0 && cc_lightSizeRangeAngle[i].w > 0.0) {\n shadow = CCSpotShadowFactorBase(shadowPos, position, s.shadowBias);\n }\n #endif\n lightColor *= shadow;\n finalColor += SNL * lightColor * cc_lightColor[i].w * illum * att * (diffuseContrib + lspec);\n }\n return vec4(finalColor, 0.0);\n }\n #endif\n #if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 1\n layout(set = 1, binding = 9) readonly buffer b_ccLightsBuffer { vec4 b_ccLights[]; };\n layout(set = 1, binding = 10) readonly buffer b_clusterLightIndicesBuffer { uint b_clusterLightIndices[]; };\n layout(set = 1, binding = 11) readonly buffer b_clusterLightGridBuffer { uvec4 b_clusterLightGrid[]; };\n struct CCLight\n {\n vec4 cc_lightPos;\n vec4 cc_lightColor;\n vec4 cc_lightSizeRangeAngle;\n vec4 cc_lightDir;\n };\n struct Cluster\n {\n vec3 minBounds;\n vec3 maxBounds;\n };\n struct LightGrid\n {\n uint offset;\n uint ccLights;\n };\n CCLight getCCLight(uint i)\n {\n CCLight light;\n light.cc_lightPos = b_ccLights[4u * i + 0u];\n light.cc_lightColor = b_ccLights[4u * i + 1u];\n light.cc_lightSizeRangeAngle = b_ccLights[4u * i + 2u];\n light.cc_lightDir = b_ccLights[4u * i + 3u];\n return light;\n }\n LightGrid getLightGrid(uint cluster)\n {\n uvec4 gridvec = b_clusterLightGrid[cluster];\n LightGrid grid;\n grid.offset = gridvec.x;\n grid.ccLights = gridvec.y;\n return grid;\n }\n uint getGridLightIndex(uint start, uint offset)\n {\n return b_clusterLightIndices[start + offset];\n }\n uint getClusterZIndex(vec4 worldPos)\n {\n float scale = float(24) / log(cc_nearFar.y / cc_nearFar.x);\n float bias = -(float(24) * log(cc_nearFar.x) / log(cc_nearFar.y / cc_nearFar.x));\n float eyeDepth = -(cc_matView * worldPos).z;\n uint zIndex = uint(max(log(eyeDepth) * scale + bias, 0.0));\n return zIndex;\n }\n uint getClusterIndex(vec4 fragCoord, vec4 worldPos)\n {\n uint zIndex = getClusterZIndex(worldPos);\n float clusterSizeX = ceil(cc_viewPort.z / float(16));\n float clusterSizeY = ceil(cc_viewPort.w / float(8));\n uvec3 indices = uvec3(uvec2(fragCoord.xy / vec2(clusterSizeX, clusterSizeY)), zIndex);\n uint cluster = (16u * 8u) * indices.z + 16u * indices.y + indices.x;\n return cluster;\n }\n vec4 CCClusterShadingAdditive (StandardSurface s, vec4 shadowPos) {\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 / PI;\n vec3 position;\n #if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\n position = unpackHighpData(s.position, s.position_fract_part);\n #else\n position = s.position;\n #endif\n vec3 N = normalize(s.normal);\n vec3 V = normalize(cc_cameraPos.xyz - 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 uint cluster = getClusterIndex(gl_FragCoord, vec4(position, 1.0));\n LightGrid grid = getLightGrid(cluster);\n uint numLights = grid.ccLights;\n for (uint i = 0u; i < 100u; i++) {\n if (i >= numLights) break;\n uint lightIndex = getGridLightIndex(grid.offset, i);\n CCLight light = getCCLight(lightIndex);\n vec3 SLU = light.cc_lightPos.xyz - 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 = light.cc_lightSizeRangeAngle.x;\n float litRadiusSqr = litRadius * litRadius;\n float illum = PI * (litRadiusSqr / max(litRadiusSqr , distSqr));\n float attRadiusSqrInv = 1.0 / max(light.cc_lightSizeRangeAngle.y, 0.01);\n attRadiusSqrInv *= attRadiusSqrInv;\n float att = GetDistAtt(distSqr, attRadiusSqrInv);\n vec3 lspec = specular * CalcSpecular(s.roughness, SNH, SH, N);\n if (light.cc_lightPos.w > 0.0) {\n float cosInner = max(dot(-light.cc_lightDir.xyz, SL), 0.01);\n float cosOuter = light.cc_lightSizeRangeAngle.z;\n float litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\n float litAngleOffset = -cosOuter * litAngleScale;\n att *= GetAngleAtt(SL, -light.cc_lightDir.xyz, litAngleScale, litAngleOffset);\n }\n vec3 lightColor = light.cc_lightColor.rgb;\n float shadow = 1.0;\n #if CC_RECEIVE_SHADOW\n if (light.cc_lightPos.w > 0.0) {\n shadow = CCSpotShadowFactorBase(shadowPos, position, s.shadowBias);\n }\n #endif\n lightColor *= shadow;\n finalColor += SNL * lightColor * light.cc_lightColor.w * illum * att * (diffuseContrib + lspec);\n }\n return vec4(finalColor, 0.0);\n }\n #endif\n layout(location = 0) out vec4 fragColorX;\n void main () {\n StandardSurface s; surf(s);\n #if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 1\n vec4 color = CCClusterShadingAdditive(s, v_shadowPos);\n #else\n vec4 color = CCStandardShadingAdditive(s, v_shadowPos);\n #endif\n fragColorX = CCFragOutput(color);\n }\n#elif (CC_PIPELINE_TYPE == 0 || CC_FORCE_FORWARD_SHADING)\n layout(location = 0) out vec4 fragColorX;\n void main () {\n StandardSurface s; surf(s);\n vec4 color = CCStandardShadingBase(s, v_shadowPos);\n CC_APPLY_FOG(color, s.position.xyz);\n fragColorX = CCFragOutput(color);\n }\n#elif CC_PIPELINE_TYPE == 1\n vec2 signNotZero(vec2 v) {\n return vec2((v.x >= 0.0) ? +1.0 : -1.0, (v.y >= 0.0) ? +1.0 : -1.0);\n }\n vec2 float32x3_to_oct(in vec3 v) {\n vec2 p = v.xy * (1.0 / (abs(v.x) + abs(v.y) + abs(v.z)));\n return (v.z <= 0.0) ? ((1.0 - abs(p.yx)) * signNotZero(p)) : p;\n }\n layout(location = 0) out vec4 fragColor0;\n layout(location = 1) out vec4 fragColor1;\n layout(location = 2) out vec4 fragColor2;\n void main () {\n StandardSurface s; surf(s);\n fragColor0 = s.albedo;\n fragColor1 = vec4(float32x3_to_oct(s.normal), s.roughness, s.metallic);\n fragColor2 = vec4(s.emissive, s.occlusion);\n }\n#endif"
|
|
},
|
|
"glsl3": {
|
|
"vert": "\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\n rgba = rgba * 255.0;\n highp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\n highp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\n highp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\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;\n#if CC_USE_SKINNING\n in vec4 a_joints;\n in vec4 a_weights;\n#endif\n#if USE_INSTANCING\n #if CC_USE_BAKED_ANIMATION\n in highp vec4 a_jointAnimInfo;\n #endif\n in vec4 a_matWorld0;\n in vec4 a_matWorld1;\n in vec4 a_matWorld2;\n #if CC_USE_LIGHTMAP\n in vec4 a_lightingMapUVParam;\n #endif\n #if CC_RECEIVE_SHADOW\n in vec2 a_localShadowBias;\n #endif\n#elif USE_BATCHING\n in float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\n in float a_vertexId;\n int getVertexId() {\n return int(a_vertexId);\n }\n#endif\n#if CC_USE_MORPH\n layout(std140) uniform CCMorph {\n vec4 cc_displacementWeights[15];\n vec4 cc_displacementTextureInfo;\n };\n #if CC_MORPH_TARGET_HAS_POSITION\n uniform sampler2D cc_PositionDisplacements;\n #endif\n #if CC_MORPH_TARGET_HAS_NORMAL\n uniform sampler2D cc_NormalDisplacements;\n #endif\n #if CC_MORPH_TARGET_HAS_TANGENT\n uniform sampler2D cc_TangentDisplacements;\n #endif\n vec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\n float pixelIndexF = float(pixelIndex);\n float x = mod(pixelIndexF, textureResolution.x);\n float y = floor(pixelIndexF / textureResolution.x);\n return vec2(x, y);\n }\n vec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\n return (vec2(location.x, location.y) + .5) / textureResolution;\n }\n #if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\n vec4 fetchVec3ArrayFromTexture(sampler2D tex, int pixelIndex) {\n ivec2 texSize = textureSize(tex, 0);\n return texelFetch(tex, ivec2(pixelIndex % texSize.x, pixelIndex / texSize.x), 0);\n }\n #else\n vec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\n int pixelIndex = elementIndex * 4;\n vec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\n vec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\n vec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\n vec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\n return vec4(\n decode32(texture(tex, x)),\n decode32(texture(tex, y)),\n decode32(texture(tex, z)),\n 1.0\n );\n }\n #endif\n float getDisplacementWeight(int index) {\n int quot = index / 4;\n int remainder = index - quot * 4;\n if (remainder == 0) {\n return cc_displacementWeights[quot].x;\n } else if (remainder == 1) {\n return cc_displacementWeights[quot].y;\n } else if (remainder == 2) {\n return cc_displacementWeights[quot].z;\n } else {\n return cc_displacementWeights[quot].w;\n }\n }\n vec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n #if CC_MORPH_PRECOMPUTED\n return fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n #else\n vec3 result = vec3(0, 0, 0);\n int nVertices = int(cc_displacementTextureInfo.z);\n for (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\n result += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n }\n return result;\n #endif\n }\n #if CC_MORPH_TARGET_HAS_POSITION\n vec3 getPositionDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n }\n #endif\n #if CC_MORPH_TARGET_HAS_NORMAL\n vec3 getNormalDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n }\n #endif\n #if CC_MORPH_TARGET_HAS_TANGENT\n vec3 getTangentDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n }\n #endif\n void applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\n int vertexId = getVertexId();\n #if CC_MORPH_TARGET_HAS_POSITION\n position.xyz = position.xyz + getPositionDisplacement(vertexId);\n #endif\n #if CC_MORPH_TARGET_HAS_NORMAL\n normal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n #endif\n #if CC_MORPH_TARGET_HAS_TANGENT\n tangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n #endif\n }\n void 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\n #if CC_USE_BAKED_ANIMATION\n layout(std140) uniform CCSkinningTexture {\n highp vec4 cc_jointTextureInfo;\n };\n layout(std140) uniform CCSkinningAnimation {\n highp vec4 cc_jointAnimInfo;\n };\n uniform highp sampler2D cc_jointTexture;\n void CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n {\n #if USE_INSTANCING\n highp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n #else\n highp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n #endif\n invSize = cc_jointTextureInfo.w;\n highp float tempY = floor(temp * invSize);\n x = floor(temp - tempY * cc_jointTextureInfo.x);\n y = (tempY + 0.5) * invSize;\n }\n #else\n #if CC_USE_REAL_TIME_JOINT_TEXTURE\n uniform highp sampler2D cc_realtimeJoint;\n #else\n layout(std140) uniform CCSkinning {\n highp vec4 cc_joints[CC_JOINT_UNIFORM_CAPACITY * 3];\n };\n #endif\n #endif\n #if CC_USE_BAKED_ANIMATION\n #if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\n mat4 getJointMatrix (float i) {\n highp float x, y, invSize;\n CCGetJointTextureCoords(3.0, i, x, y, 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 highp float x, y, invSize;\n CCGetJointTextureCoords(12.0, i, x, y, 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 #if CC_USE_REAL_TIME_JOINT_TEXTURE\n #if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\n mat4 getJointMatrix (float i) {\n float x = i;\n vec4 v1 = texture(cc_realtimeJoint, vec2( x / 256.0, 0.5 / 3.0));\n vec4 v2 = texture(cc_realtimeJoint, vec2( x / 256.0, 1.5 / 3.0));\n vec4 v3 = texture(cc_realtimeJoint, vec2( x / 256.0, 2.5 / 3.0));\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 float x = 4.0 * i;\n vec4 v1 = vec4(\n decode32(texture(cc_realtimeJoint, vec2((x + 0.5)/ 1024.0, 0.5 / 3.0))),\n decode32(texture(cc_realtimeJoint, vec2((x + 1.5)/ 1024.0, 0.5 / 3.0))),\n decode32(texture(cc_realtimeJoint, vec2((x + 2.5)/ 1024.0, 0.5 / 3.0))),\n decode32(texture(cc_realtimeJoint, vec2((x + 3.5)/ 1024.0, 0.5 / 3.0)))\n );\n vec4 v2 = vec4(\n decode32(texture(cc_realtimeJoint, vec2((x + 0.5)/ 1024.0, 1.5 / 3.0))),\n decode32(texture(cc_realtimeJoint, vec2((x + 1.5)/ 1024.0, 1.5 / 3.0))),\n decode32(texture(cc_realtimeJoint, vec2((x + 2.5)/ 1024.0, 1.5 / 3.0))),\n decode32(texture(cc_realtimeJoint, vec2((x + 3.5)/ 1024.0, 1.5 / 3.0)))\n );\n vec4 v3 = vec4(\n decode32(texture(cc_realtimeJoint, vec2((x + 0.5)/ 1024.0, 2.5 / 3.0))),\n decode32(texture(cc_realtimeJoint, vec2((x + 1.5)/ 1024.0, 2.5 / 3.0))),\n decode32(texture(cc_realtimeJoint, vec2((x + 2.5)/ 1024.0, 2.5 / 3.0))),\n decode32(texture(cc_realtimeJoint, vec2((x + 3.5)/ 1024.0, 2.5 / 3.0)))\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\n #endif\n mat4 skinMatrix () {\n vec4 joints = vec4(a_joints);\n return getJointMatrix(joints.x) * a_weights.x\n + getJointMatrix(joints.y) * a_weights.y\n + getJointMatrix(joints.z) * a_weights.z\n + getJointMatrix(joints.w) * a_weights.w;\n }\n void CCSkin (inout vec4 position) {\n mat4 m = skinMatrix();\n position = m * position;\n }\n void CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\n mat4 m = skinMatrix();\n position = m * position;\n normal = (m * vec4(normal, 0.0)).xyz;\n tangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n }\n#endif\nvoid CCVertInput(inout StandardVertInput In)\n{\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.position, In.normal, In.tangent);\n #endif\n #if CC_USE_SKINNING\n CCSkin(In.position, In.normal, In.tangent);\n #endif\n}\nlayout(std140) uniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_nativeSize;\n mediump vec4 cc_debug_view_mode;\n mediump vec4 cc_debug_view_composite_pack_1;\n mediump vec4 cc_debug_view_composite_pack_2;\n mediump vec4 cc_debug_view_composite_pack_3;\n};\nlayout(std140) uniform CCCamera {\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_surfaceTransform;\n mediump vec4 cc_screenScale;\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 mediump vec4 cc_nearFar;\n mediump vec4 cc_viewPort;\n};\n#if !USE_INSTANCING\n #if USE_BATCHING\n layout(std140) uniform CCLocalBatched {\n highp mat4 cc_matWorlds[10];\n };\n #else\n layout(std140) uniform CCLocal {\n highp mat4 cc_matWorld;\n highp mat4 cc_matWorldIT;\n highp vec4 cc_lightingMapUVParam;\n highp vec4 cc_localShadowBias;\n };\n #endif\n#endif\nvoid CCGetWorldMatrixFull(out mat4 matWorld, out mat4 matWorldIT)\n{\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}\nlayout(std140) uniform Constants {\n vec4 tilingOffset;\n vec4 diffuseColor;\n vec4 specularColor;\n vec4 emissive;\n float alphaThreshold;\n float shininessExponent;\n float glossiness;\n float metallic;\n float normalScale;\n float transparencyFactor;\n float diffuseFactor;\n float specularFactor;\n};\n#if CC_USE_FOG != 4\n float LinearFog(vec4 pos, vec3 cameraPos, float fogStart, float fogEnd) {\n vec4 wPos = pos;\n float cam_dis = distance(cameraPos, wPos.xyz);\n return clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n }\n float ExpFog(vec4 pos, vec3 cameraPos, float fogStart, float fogDensity, float fogAtten) {\n vec4 wPos = pos;\n float cam_dis = max(distance(cameraPos, wPos.xyz) - fogStart, 0.0) / fogAtten * 4.;\n float f = exp(-cam_dis * fogDensity);\n return f;\n }\n float ExpSquaredFog(vec4 pos, vec3 cameraPos, float fogStart, float fogDensity, float fogAtten) {\n vec4 wPos = pos;\n float cam_dis = max(distance(cameraPos, wPos.xyz) - fogStart, 0.0) / fogAtten * 4.;\n float f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\n return f;\n }\n float LayeredFog(vec4 pos, vec3 cameraPos, float fogTop, float fogRange, float fogAtten) {\n vec4 wPos = pos;\n vec3 camWorldProj = 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 (cameraPos.y > fogTop) {\n if (wPos.y < fogTop) {\n fDeltaY = (fogTop - wPos.y) / fogRange * 2.0;\n fDensityIntegral = fDeltaY * fDeltaY * 0.5;\n }\n else {\n fDeltaY = 0.;\n fDensityIntegral = 0.;\n }\n }\n else {\n if (wPos.y < fogTop) {\n float fDeltaA = (fogTop - 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 }\n else {\n fDeltaY = abs(fogTop - 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 }\n else {\n fDensity = 0.;\n }\n float f = exp(-fDensity);\n return f;\n }\n#endif\nvoid CC_TRANSFER_FOG_BASE(vec4 pos, out float factor)\n{\n#if CC_USE_FOG == 0\n\tfactor = LinearFog(pos, cc_cameraPos.xyz, cc_fogBase.x, cc_fogBase.y);\n#elif CC_USE_FOG == 1\n\tfactor = ExpFog(pos, cc_cameraPos.xyz, cc_fogBase.x, cc_fogBase.z, cc_fogAdd.z);\n#elif CC_USE_FOG == 2\n\tfactor = ExpSquaredFog(pos, cc_cameraPos.xyz, cc_fogBase.x, cc_fogBase.z, cc_fogAdd.z);\n#elif CC_USE_FOG == 3\n\tfactor = LayeredFog(pos, cc_cameraPos.xyz, cc_fogAdd.x, cc_fogAdd.y, cc_fogAdd.z);\n#else\n\tfactor = 1.0;\n#endif\n}\n#if !CC_USE_ACCURATE_FOG\nout float v_fog_factor;\n#endif\nvoid CC_TRANSFER_FOG(vec4 pos) {\n#if !CC_USE_ACCURATE_FOG\n CC_TRANSFER_FOG_BASE(pos, v_fog_factor);\n#endif\n}\nout highp vec4 v_shadowPos;\nlayout(std140) uniform CCShadow {\n highp mat4 cc_matLightView;\n highp mat4 cc_matLightViewProj;\n highp vec4 cc_shadowInvProjDepthInfo;\n highp vec4 cc_shadowProjDepthInfo;\n highp vec4 cc_shadowProjInfo;\n mediump vec4 cc_shadowNFLSInfo;\n mediump vec4 cc_shadowWHPBInfo;\n mediump vec4 cc_shadowLPNNInfo;\n lowp vec4 cc_shadowColor;\n mediump vec4 cc_planarNDInfo;\n};\n#if CC_SUPPORT_CASCADED_SHADOW_MAP\n layout(std140) uniform CCCSM {\n highp vec4 cc_csmViewDir0[4];\n highp vec4 cc_csmViewDir1[4];\n highp vec4 cc_csmViewDir2[4];\n highp vec4 cc_csmAtlas[4];\n highp mat4 cc_matCSMViewProj[4];\n highp vec4 cc_csmProjDepthInfo[4];\n highp vec4 cc_csmProjInfo[4];\n highp vec4 cc_csmSplitsInfo;\n };\n#endif\n#if CC_RECEIVE_SHADOW\n uniform highp sampler2D cc_shadowMap;\n uniform highp sampler2D cc_spotShadowMap;\n #if CC_SUPPORT_CASCADED_SHADOW_MAP\n #else\n #endif\n#endif\n#if CC_RECEIVE_SHADOW\nvec2 CCGetShadowBias()\n{\n #if USE_INSTANCING\n return vec2(a_localShadowBias.x + cc_shadowWHPBInfo.w, a_localShadowBias.y + cc_shadowLPNNInfo.z);\n #elif !USE_BATCHING\n return vec2(cc_localShadowBias.x + cc_shadowWHPBInfo.w, cc_localShadowBias.y + cc_shadowLPNNInfo.z);\n #else\n return vec2(cc_shadowWHPBInfo.w, cc_shadowLPNNInfo.z);\n #endif\n}\n#endif\n#if USE_VERTEX_COLOR\n in vec4 a_color;\n out vec4 v_color;\n#endif\nout vec3 v_position;\nout vec3 v_normal;\nout vec2 v_uv;\nout vec2 v_uv1;\n#if USE_NORMAL_MAP\n out vec3 v_tangent;\n out vec3 v_bitangent;\n#endif\n#if CC_RECEIVE_SHADOW\n out mediump vec2 v_shadowBias;\n#endif\n#if HAS_SECOND_UV || CC_USE_LIGHTMAP\n in vec2 a_texCoord1;\n#endif\n#if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\n out vec3 v_luv;\n void CCLightingMapCaclUV()\n {\n #if !USE_INSTANCING\n v_luv.xy = cc_lightingMapUVParam.xy + a_texCoord1 * cc_lightingMapUVParam.z;\n v_luv.z = cc_lightingMapUVParam.w;\n #else\n v_luv.xy = a_lightingMapUVParam.xy + a_texCoord1 * a_lightingMapUVParam.z;\n v_luv.z = a_lightingMapUVParam.w;\n #endif\n }\n#endif\nvoid main () {\n StandardVertInput In;\n CCVertInput(In);\n mat4 matWorld, matWorldIT;\n CCGetWorldMatrixFull(matWorld, matWorldIT);\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_TWOSIDE\n vec3 viewDirect = normalize(cc_cameraPos.xyz - v_position);\n v_normal *= dot(v_normal, viewDirect) < 0.0 ? -1.0 : 1.0;\n #endif\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 CC_TRANSFER_FOG(pos);\n v_shadowPos = cc_matLightViewProj * pos;\n #if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\n CCLightingMapCaclUV();\n #endif\n #if CC_RECEIVE_SHADOW\n v_shadowBias = CCGetShadowBias();\n #endif\n gl_Position = cc_matProj * (cc_matView * matWorld) * In.position;\n}",
|
|
"frag": "\nprecision highp float;\nlayout(std140) uniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_nativeSize;\n mediump vec4 cc_debug_view_mode;\n mediump vec4 cc_debug_view_composite_pack_1;\n mediump vec4 cc_debug_view_composite_pack_2;\n mediump vec4 cc_debug_view_composite_pack_3;\n};\nlayout(std140) uniform CCCamera {\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_surfaceTransform;\n mediump vec4 cc_screenScale;\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 mediump vec4 cc_nearFar;\n mediump vec4 cc_viewPort;\n};\nlayout(std140) uniform Constants {\n vec4 tilingOffset;\n vec4 diffuseColor;\n vec4 specularColor;\n vec4 emissive;\n float alphaThreshold;\n float shininessExponent;\n float glossiness;\n float metallic;\n float normalScale;\n float transparencyFactor;\n float diffuseFactor;\n float specularFactor;\n};\n#if CC_USE_FOG != 4\n float LinearFog(vec4 pos, vec3 cameraPos, float fogStart, float fogEnd) {\n vec4 wPos = pos;\n float cam_dis = distance(cameraPos, wPos.xyz);\n return clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n }\n float ExpFog(vec4 pos, vec3 cameraPos, float fogStart, float fogDensity, float fogAtten) {\n vec4 wPos = pos;\n float cam_dis = max(distance(cameraPos, wPos.xyz) - fogStart, 0.0) / fogAtten * 4.;\n float f = exp(-cam_dis * fogDensity);\n return f;\n }\n float ExpSquaredFog(vec4 pos, vec3 cameraPos, float fogStart, float fogDensity, float fogAtten) {\n vec4 wPos = pos;\n float cam_dis = max(distance(cameraPos, wPos.xyz) - fogStart, 0.0) / fogAtten * 4.;\n float f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\n return f;\n }\n float LayeredFog(vec4 pos, vec3 cameraPos, float fogTop, float fogRange, float fogAtten) {\n vec4 wPos = pos;\n vec3 camWorldProj = 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 (cameraPos.y > fogTop) {\n if (wPos.y < fogTop) {\n fDeltaY = (fogTop - wPos.y) / fogRange * 2.0;\n fDensityIntegral = fDeltaY * fDeltaY * 0.5;\n }\n else {\n fDeltaY = 0.;\n fDensityIntegral = 0.;\n }\n }\n else {\n if (wPos.y < fogTop) {\n float fDeltaA = (fogTop - 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 }\n else {\n fDeltaY = abs(fogTop - 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 }\n else {\n fDensity = 0.;\n }\n float f = exp(-fDensity);\n return f;\n }\n#endif\nvoid CC_TRANSFER_FOG_BASE(vec4 pos, out float factor)\n{\n#if CC_USE_FOG == 0\n\tfactor = LinearFog(pos, cc_cameraPos.xyz, cc_fogBase.x, cc_fogBase.y);\n#elif CC_USE_FOG == 1\n\tfactor = ExpFog(pos, cc_cameraPos.xyz, cc_fogBase.x, cc_fogBase.z, cc_fogAdd.z);\n#elif CC_USE_FOG == 2\n\tfactor = ExpSquaredFog(pos, cc_cameraPos.xyz, cc_fogBase.x, cc_fogBase.z, cc_fogAdd.z);\n#elif CC_USE_FOG == 3\n\tfactor = LayeredFog(pos, cc_cameraPos.xyz, cc_fogAdd.x, cc_fogAdd.y, cc_fogAdd.z);\n#else\n\tfactor = 1.0;\n#endif\n}\nvoid CC_APPLY_FOG_BASE(inout vec4 color, float factor) {\n\tcolor = vec4(mix(cc_fogColor.rgb, color.rgb, factor), color.a);\n}\n#if !CC_USE_ACCURATE_FOG\nin float v_fog_factor;\n#endif\nvoid CC_APPLY_FOG(inout vec4 color) {\n#if !CC_USE_ACCURATE_FOG\n CC_APPLY_FOG_BASE(color, v_fog_factor);\n#endif\n}\nvoid CC_APPLY_FOG(inout vec4 color, vec3 worldPos) {\n#if CC_USE_ACCURATE_FOG\n float factor;\n CC_TRANSFER_FOG_BASE(vec4(worldPos, 1.0), factor);\n#else\n float factor = v_fog_factor;\n#endif\n CC_APPLY_FOG_BASE(color, factor);\n}\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\n#define CC_SURFACES_DEBUG_VIEW_VERTEX_COLOR 1\n#define CC_SURFACES_DEBUG_VIEW_VERTEX_NORMAL CC_SURFACES_DEBUG_VIEW_VERTEX_COLOR + 1\n#define CC_SURFACES_DEBUG_VIEW_VERTEX_TANGENT CC_SURFACES_DEBUG_VIEW_VERTEX_NORMAL + 1\n#define CC_SURFACES_DEBUG_VIEW_WORLD_POS CC_SURFACES_DEBUG_VIEW_VERTEX_TANGENT + 1\n#define CC_SURFACES_DEBUG_VIEW_VERTEX_MIRROR CC_SURFACES_DEBUG_VIEW_WORLD_POS + 1\n#define CC_SURFACES_DEBUG_VIEW_FACE_SIDE CC_SURFACES_DEBUG_VIEW_VERTEX_MIRROR + 1\n#define CC_SURFACES_DEBUG_VIEW_UV0 CC_SURFACES_DEBUG_VIEW_FACE_SIDE + 1\n#define CC_SURFACES_DEBUG_VIEW_UV1 CC_SURFACES_DEBUG_VIEW_UV0 + 1\n#define CC_SURFACES_DEBUG_VIEW_UVLIGHTMAP CC_SURFACES_DEBUG_VIEW_UV1 + 1\n#define CC_SURFACES_DEBUG_VIEW_PROJ_DEPTH CC_SURFACES_DEBUG_VIEW_UVLIGHTMAP + 1\n#define CC_SURFACES_DEBUG_VIEW_LINEAR_DEPTH CC_SURFACES_DEBUG_VIEW_PROJ_DEPTH + 1\n#define CC_SURFACES_DEBUG_VIEW_FRAGMENT_NORMAL CC_SURFACES_DEBUG_VIEW_LINEAR_DEPTH + 1\n#define CC_SURFACES_DEBUG_VIEW_FRAGMENT_TANGENT CC_SURFACES_DEBUG_VIEW_FRAGMENT_NORMAL + 1\n#define CC_SURFACES_DEBUG_VIEW_FRAGMENT_BINORMAL CC_SURFACES_DEBUG_VIEW_FRAGMENT_TANGENT + 1\n#define CC_SURFACES_DEBUG_VIEW_BASE_COLOR CC_SURFACES_DEBUG_VIEW_FRAGMENT_BINORMAL + 1\n#define CC_SURFACES_DEBUG_VIEW_DIFFUSE_COLOR CC_SURFACES_DEBUG_VIEW_BASE_COLOR + 1\n#define CC_SURFACES_DEBUG_VIEW_SPECULAR_COLOR CC_SURFACES_DEBUG_VIEW_DIFFUSE_COLOR + 1\n#define CC_SURFACES_DEBUG_VIEW_TRANSPARENCY CC_SURFACES_DEBUG_VIEW_SPECULAR_COLOR + 1\n#define CC_SURFACES_DEBUG_VIEW_METALLIC CC_SURFACES_DEBUG_VIEW_TRANSPARENCY + 1\n#define CC_SURFACES_DEBUG_VIEW_ROUGHNESS CC_SURFACES_DEBUG_VIEW_METALLIC + 1\n#define CC_SURFACES_DEBUG_VIEW_SPECULAR_INTENSITY CC_SURFACES_DEBUG_VIEW_ROUGHNESS + 1\n#define CC_SURFACES_DEBUG_VIEW_DIRECT_DIFFUSE CC_SURFACES_DEBUG_VIEW_SPECULAR_INTENSITY + 1\n#define CC_SURFACES_DEBUG_VIEW_DIRECT_SPECULAR CC_SURFACES_DEBUG_VIEW_DIRECT_DIFFUSE + 1\n#define CC_SURFACES_DEBUG_VIEW_DIRECT_ALL CC_SURFACES_DEBUG_VIEW_DIRECT_SPECULAR + 1\n#define CC_SURFACES_DEBUG_VIEW_ENV_DIFFUSE CC_SURFACES_DEBUG_VIEW_DIRECT_ALL + 1\n#define CC_SURFACES_DEBUG_VIEW_ENV_SPECULAR CC_SURFACES_DEBUG_VIEW_ENV_DIFFUSE + 1\n#define CC_SURFACES_DEBUG_VIEW_ENV_ALL CC_SURFACES_DEBUG_VIEW_ENV_SPECULAR + 1\n#define CC_SURFACES_DEBUG_VIEW_EMISSIVE CC_SURFACES_DEBUG_VIEW_ENV_ALL + 1\n#define CC_SURFACES_DEBUG_VIEW_LIGHT_MAP CC_SURFACES_DEBUG_VIEW_EMISSIVE + 1\n#define CC_SURFACES_DEBUG_VIEW_SHADOW CC_SURFACES_DEBUG_VIEW_LIGHT_MAP + 1\n#define CC_SURFACES_DEBUG_VIEW_AO CC_SURFACES_DEBUG_VIEW_SHADOW + 1\n#define CC_SURFACES_DEBUG_VIEW_FOG CC_SURFACES_DEBUG_VIEW_AO + 1\n#define CC_SURFACES_DEBUG_VIEW_SINGLE 1\n#define CC_SURFACES_DEBUG_VIEW_COMPOSITE_AND_MISC 2\n#define IS_DEBUG_VIEW_LIGHTING_ENABLE_WITH_ALBEDO (cc_debug_view_mode.y > 0.0)\n#define IS_DEBUG_VIEW_MISC_ENABLE_CSM_LAYER_COLORATION (cc_debug_view_mode.z > 0.0)\n#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_DIRECT_DIFFUSE (cc_debug_view_composite_pack_1.x > 0.0)\n#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_DIRECT_SPECULAR (cc_debug_view_composite_pack_1.y > 0.0)\n#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_ENV_DIFFUSE (cc_debug_view_composite_pack_1.z > 0.0)\n#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_ENV_SPECULAR (cc_debug_view_composite_pack_1.w > 0.0)\n#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_EMISSIVE (cc_debug_view_composite_pack_2.x > 0.0)\n#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_LIGHT_MAP (cc_debug_view_composite_pack_2.y > 0.0)\n#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_SHADOW (cc_debug_view_composite_pack_2.z > 0.0)\n#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_AO (cc_debug_view_composite_pack_2.w > 0.0)\n#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_NORMAL_MAP (cc_debug_view_composite_pack_3.x > 0.0)\n#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_FOG (cc_debug_view_composite_pack_3.y > 0.0)\n#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_TONE_MAPPING (cc_debug_view_composite_pack_3.z > 0.0)\n#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_GAMMA_CORRECTION (cc_debug_view_composite_pack_3.w > 0.0)\nvec3 SRGBToLinear (vec3 gamma) {\n#ifdef CC_USE_SURFACE_SHADER\n #if CC_USE_DEBUG_VIEW == CC_SURFACES_DEBUG_VIEW_COMPOSITE_AND_MISC\n if (!IS_DEBUG_VIEW_COMPOSITE_ENABLE_GAMMA_CORRECTION) {\n return gamma;\n }\n #endif\n#endif\n return gamma * gamma;\n}\nvec3 LinearToSRGB(vec3 linear) {\n#ifdef CC_USE_SURFACE_SHADER\n #if CC_USE_DEBUG_VIEW == CC_SURFACES_DEBUG_VIEW_COMPOSITE_AND_MISC\n if (!IS_DEBUG_VIEW_COMPOSITE_ENABLE_GAMMA_CORRECTION) {\n return linear;\n }\n #endif\n#endif\n return sqrt(linear);\n}\nlayout(std140) uniform CCShadow {\n highp mat4 cc_matLightView;\n highp mat4 cc_matLightViewProj;\n highp vec4 cc_shadowInvProjDepthInfo;\n highp vec4 cc_shadowProjDepthInfo;\n highp vec4 cc_shadowProjInfo;\n mediump vec4 cc_shadowNFLSInfo;\n mediump vec4 cc_shadowWHPBInfo;\n mediump vec4 cc_shadowLPNNInfo;\n lowp vec4 cc_shadowColor;\n mediump vec4 cc_planarNDInfo;\n};\n#if CC_SUPPORT_CASCADED_SHADOW_MAP\n layout(std140) uniform CCCSM {\n highp vec4 cc_csmViewDir0[4];\n highp vec4 cc_csmViewDir1[4];\n highp vec4 cc_csmViewDir2[4];\n highp vec4 cc_csmAtlas[4];\n highp mat4 cc_matCSMViewProj[4];\n highp vec4 cc_csmProjDepthInfo[4];\n highp vec4 cc_csmProjInfo[4];\n highp vec4 cc_csmSplitsInfo;\n };\n#endif\nfloat GetLinearDepthFromViewSpace(vec3 viewPos, float near, float far) {\n float dist = length(viewPos);\n return (dist - near) / (far - near);\n}\nfloat CCGetLinearDepth(vec3 worldPos, float viewSpaceBias) {\n\tvec4 viewPos = cc_matLightView * vec4(worldPos.xyz, 1.0);\n viewPos.z += viewSpaceBias;\n\treturn GetLinearDepthFromViewSpace(viewPos.xyz, cc_shadowNFLSInfo.x, cc_shadowNFLSInfo.y);\n}\nfloat CCGetLinearDepth(vec3 worldPos) {\n\treturn CCGetLinearDepth(worldPos, 0.0);\n}\n#if CC_RECEIVE_SHADOW\n uniform highp sampler2D cc_shadowMap;\n uniform highp sampler2D cc_spotShadowMap;\n highp float unpackHighpData (float mainPart, float modPart) {\n highp float data = mainPart;\n return data + modPart;\n }\n void packHighpData (out float mainPart, out float modPart, highp float data) {\n mainPart = fract(data);\n modPart = data - mainPart;\n }\n highp float unpackHighpData (float mainPart, float modPart, const float modValue) {\n highp float data = mainPart * modValue;\n return data + modPart * modValue;\n }\n void packHighpData (out float mainPart, out float modPart, highp float data, const float modValue) {\n highp float divide = data / modValue;\n mainPart = floor(divide);\n modPart = (data - mainPart * modValue) / modValue;\n }\n highp vec2 unpackHighpData (vec2 mainPart, vec2 modPart) {\n highp vec2 data = mainPart;\n return data + modPart;\n }\n void packHighpData (out vec2 mainPart, out vec2 modPart, highp vec2 data) {\n mainPart = fract(data);\n modPart = data - mainPart;\n }\n highp vec2 unpackHighpData (vec2 mainPart, vec2 modPart, const float modValue) {\n highp vec2 data = mainPart * modValue;\n return data + modPart * modValue;\n }\n void packHighpData (out vec2 mainPart, out vec2 modPart, highp vec2 data, const float modValue) {\n highp vec2 divide = data / modValue;\n mainPart = floor(divide);\n modPart = (data - mainPart * modValue) / modValue;\n }\n highp vec3 unpackHighpData (vec3 mainPart, vec3 modPart) {\n highp vec3 data = mainPart;\n return data + modPart;\n }\n void packHighpData (out vec3 mainPart, out vec3 modPart, highp vec3 data) {\n mainPart = fract(data);\n modPart = data - mainPart;\n }\n highp vec3 unpackHighpData (vec3 mainPart, vec3 modPart, const float modValue) {\n highp vec3 data = mainPart * modValue;\n return data + modPart * modValue;\n }\n void packHighpData (out vec3 mainPart, out vec3 modPart, highp vec3 data, const float modValue) {\n highp vec3 divide = data / modValue;\n mainPart = floor(divide);\n modPart = (data - mainPart * modValue) / modValue;\n }\n highp vec4 unpackHighpData (vec4 mainPart, vec4 modPart) {\n highp vec4 data = mainPart;\n return data + modPart;\n }\n void packHighpData (out vec4 mainPart, out vec4 modPart, highp vec4 data) {\n mainPart = fract(data);\n modPart = data - mainPart;\n }\n highp vec4 unpackHighpData (vec4 mainPart, vec4 modPart, const float modValue) {\n highp vec4 data = mainPart * modValue;\n return data + modPart * modValue;\n }\n void packHighpData (out vec4 mainPart, out vec4 modPart, highp vec4 data, const float modValue) {\n highp vec4 divide = data / modValue;\n mainPart = floor(divide);\n modPart = (data - mainPart * modValue) / modValue;\n }\n float NativePCFShadowFactorHard (vec3 shadowNDCPos, sampler2D shadowMap, vec2 shadowMapResolution)\n {\n #if CC_SHADOWMAP_FORMAT == 1\n return step(shadowNDCPos.z, dot(texture(shadowMap, shadowNDCPos.xy), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n #else\n return step(shadowNDCPos.z, texture(shadowMap, shadowNDCPos.xy).x);\n #endif\n }\n float NativePCFShadowFactorSoft (vec3 shadowNDCPos, sampler2D shadowMap, vec2 shadowMapResolution)\n {\n vec2 oneTap = 1.0 / shadowMapResolution;\n vec2 shadowNDCPos_offset = shadowNDCPos.xy + oneTap;\n float block0, block1, block2, block3;\n #if CC_SHADOWMAP_FORMAT == 1\n block0 = step(shadowNDCPos.z, dot(texture(shadowMap, vec2(shadowNDCPos.x, shadowNDCPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n block1 = step(shadowNDCPos.z, dot(texture(shadowMap, vec2(shadowNDCPos_offset.x, shadowNDCPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n block2 = step(shadowNDCPos.z, dot(texture(shadowMap, vec2(shadowNDCPos.x, shadowNDCPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n block3 = step(shadowNDCPos.z, dot(texture(shadowMap, vec2(shadowNDCPos_offset.x, shadowNDCPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n #else\n block0 = step(shadowNDCPos.z, texture(shadowMap, vec2(shadowNDCPos.x, shadowNDCPos.y)).x);\n block1 = step(shadowNDCPos.z, texture(shadowMap, vec2(shadowNDCPos_offset.x, shadowNDCPos.y)).x);\n block2 = step(shadowNDCPos.z, texture(shadowMap, vec2(shadowNDCPos.x, shadowNDCPos_offset.y)).x);\n block3 = step(shadowNDCPos.z, texture(shadowMap, vec2(shadowNDCPos_offset.x, shadowNDCPos_offset.y)).x);\n #endif\n float coefX = mod(shadowNDCPos.x, oneTap.x) * shadowMapResolution.x;\n float resultX = mix(block0, block1, coefX);\n float resultY = mix(block2, block3, coefX);\n float coefY = mod(shadowNDCPos.y, oneTap.y) * shadowMapResolution.y;\n return mix(resultX, resultY, coefY);\n }\n float NativePCFShadowFactorSoft3X (vec3 shadowNDCPos, sampler2D shadowMap, vec2 shadowMapResolution)\n {\n vec2 oneTap = 1.0 / shadowMapResolution;\n float shadowNDCPos_offset_L = shadowNDCPos.x - oneTap.x;\n float shadowNDCPos_offset_R = shadowNDCPos.x + oneTap.x;\n float shadowNDCPos_offset_U = shadowNDCPos.y - oneTap.y;\n float shadowNDCPos_offset_D = shadowNDCPos.y + oneTap.y;\n float block0, block1, block2, block3, block4, block5, block6, block7, block8;\n #if CC_SHADOWMAP_FORMAT == 1\n block0 = step(shadowNDCPos.z, dot(texture(shadowMap, vec2(shadowNDCPos_offset_L, shadowNDCPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n block1 = step(shadowNDCPos.z, dot(texture(shadowMap, vec2(shadowNDCPos.x, shadowNDCPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n block2 = step(shadowNDCPos.z, dot(texture(shadowMap, vec2(shadowNDCPos_offset_R, shadowNDCPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n block3 = step(shadowNDCPos.z, dot(texture(shadowMap, vec2(shadowNDCPos_offset_L, shadowNDCPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n block4 = step(shadowNDCPos.z, dot(texture(shadowMap, vec2(shadowNDCPos.x, shadowNDCPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n block5 = step(shadowNDCPos.z, dot(texture(shadowMap, vec2(shadowNDCPos_offset_R, shadowNDCPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n block6 = step(shadowNDCPos.z, dot(texture(shadowMap, vec2(shadowNDCPos_offset_L, shadowNDCPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n block7 = step(shadowNDCPos.z, dot(texture(shadowMap, vec2(shadowNDCPos.x, shadowNDCPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n block8 = step(shadowNDCPos.z, dot(texture(shadowMap, vec2(shadowNDCPos_offset_R, shadowNDCPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n #else\n block0 = step(shadowNDCPos.z, texture(shadowMap, vec2(shadowNDCPos_offset_L, shadowNDCPos_offset_U)).x);\n block1 = step(shadowNDCPos.z, texture(shadowMap, vec2(shadowNDCPos.x, shadowNDCPos_offset_U)).x);\n block2 = step(shadowNDCPos.z, texture(shadowMap, vec2(shadowNDCPos_offset_R, shadowNDCPos_offset_U)).x);\n block3 = step(shadowNDCPos.z, texture(shadowMap, vec2(shadowNDCPos_offset_L, shadowNDCPos.y)).x);\n block4 = step(shadowNDCPos.z, texture(shadowMap, vec2(shadowNDCPos.x, shadowNDCPos.y)).x);\n block5 = step(shadowNDCPos.z, texture(shadowMap, vec2(shadowNDCPos_offset_R, shadowNDCPos.y)).x);\n block6 = step(shadowNDCPos.z, texture(shadowMap, vec2(shadowNDCPos_offset_L, shadowNDCPos_offset_D)).x);\n block7 = step(shadowNDCPos.z, texture(shadowMap, vec2(shadowNDCPos.x, shadowNDCPos_offset_D)).x);\n block8 = step(shadowNDCPos.z, texture(shadowMap, vec2(shadowNDCPos_offset_R, shadowNDCPos_offset_D)).x);\n #endif\n float coefX = mod(shadowNDCPos.x, oneTap.x) * shadowMapResolution.x;\n float coefY = mod(shadowNDCPos.y, oneTap.y) * shadowMapResolution.y;\n float shadow = 0.0;\n float resultX = mix(block0, block1, coefX);\n float resultY = mix(block3, block4, coefX);\n shadow += mix(resultX , resultY, coefY);\n resultX = mix(block1, block2, coefX);\n resultY = mix(block4, block5, coefX);\n shadow += mix(resultX , resultY, coefY);\n resultX = mix(block3, block4, coefX);\n resultY = mix(block6, block7, coefX);\n shadow += mix(resultX, resultY, coefY);\n resultX = mix(block4, block5, coefX);\n resultY = mix(block7, block8, coefX);\n shadow += mix(resultX, resultY, coefY);\n return shadow * 0.25;\n }\n bool GetShadowNDCPos(out vec3 shadowNDCPos, vec4 shadowPosWithDepthBias)\n {\n \tshadowNDCPos = shadowPosWithDepthBias.xyz / shadowPosWithDepthBias.w * 0.5 + 0.5;\n \tif (shadowNDCPos.x < 0.0 || shadowNDCPos.x > 1.0 ||\n \t\tshadowNDCPos.y < 0.0 || shadowNDCPos.y > 1.0 ||\n \t\tshadowNDCPos.z < 0.0 || shadowNDCPos.z > 1.0) {\n \t\treturn false;\n \t}\n \tshadowNDCPos.xy = cc_cameraPos.w == 1.0 ? vec2(shadowNDCPos.xy.x, 1.0 - shadowNDCPos.xy.y) : shadowNDCPos.xy;\n \treturn true;\n }\n vec4 ApplyShadowDepthBias_FaceNormal(vec4 shadowPos, vec3 worldNormal, float normalBias, vec3 matViewDir0, vec3 matViewDir1, vec3 matViewDir2, vec2 projScaleXY)\n {\n vec4 newShadowPos = shadowPos;\n if (normalBias > EPSILON_LOWP)\n {\n vec3 viewNormal = vec3(dot(matViewDir0, worldNormal), dot(matViewDir1, worldNormal), dot(matViewDir2, worldNormal));\n if (viewNormal.z < 0.1)\n newShadowPos.xy += viewNormal.xy * projScaleXY * normalBias * clamp(viewNormal.z, 0.001, 0.1);\n }\n return newShadowPos;\n }\n vec4 ApplyShadowDepthBias_FaceNormal(vec4 shadowPos, vec3 worldNormal, float normalBias, mat4 matLightView, vec2 projScaleXY)\n {\n \tvec4 newShadowPos = shadowPos;\n \tif (normalBias > EPSILON_LOWP)\n \t{\n \t\tvec4 viewNormal = matLightView * vec4(worldNormal, 0.0);\n \t\tif (viewNormal.z < 0.1)\n \t\t\tnewShadowPos.xy += viewNormal.xy * projScaleXY * normalBias * clamp(viewNormal.z, 0.001, 0.1);\n \t}\n \treturn newShadowPos;\n }\n vec4 ApplyShadowDepthBias_Perspective(vec4 shadowPos, float viewspaceDepthBias)\n {\n \tvec3 viewSpacePos;\n \tviewSpacePos.xy = shadowPos.xy * cc_shadowProjInfo.zw;\n \tviewSpacePos.z = shadowPos.z * cc_shadowInvProjDepthInfo.x + shadowPos.w * cc_shadowInvProjDepthInfo.y;\n \tviewSpacePos.xyz += cc_shadowProjDepthInfo.z * normalize(viewSpacePos.xyz) * viewspaceDepthBias;\n \tvec4 clipSpacePos;\n \tclipSpacePos.xy = viewSpacePos.xy * cc_shadowProjInfo.xy;\n \tclipSpacePos.zw = viewSpacePos.z * cc_shadowProjDepthInfo.xz + vec2(cc_shadowProjDepthInfo.y, 0.0);\n \t#if CC_SHADOWMAP_USE_LINEAR_DEPTH\n \t\tclipSpacePos.z = GetLinearDepthFromViewSpace(viewSpacePos.xyz, cc_shadowNFLSInfo.x, cc_shadowNFLSInfo.y);\n \t\tclipSpacePos.z = (clipSpacePos.z * 2.0 - 1.0) * clipSpacePos.w;\n \t#endif\n \treturn clipSpacePos;\n }\n vec4 ApplyShadowDepthBias_Orthographic(vec4 shadowPos, float viewspaceDepthBias, float projScaleZ, float projBiasZ)\n {\n \tfloat coeffA = projScaleZ;\n \tfloat coeffB = projBiasZ;\n \tfloat viewSpacePos_z = (shadowPos.z - coeffB) / coeffA;\n \tviewSpacePos_z += viewspaceDepthBias;\n \tvec4 result = shadowPos;\n \tresult.z = viewSpacePos_z * coeffA + coeffB;\n \treturn result;\n }\n vec4 ApplyShadowDepthBias_PerspectiveLinearDepth(vec4 shadowPos, float viewspaceDepthBias, vec3 worldPos)\n {\n shadowPos.z = CCGetLinearDepth(worldPos, viewspaceDepthBias) * 2.0 - 1.0;\n shadowPos.z *= shadowPos.w;\n return shadowPos;\n }\n float CCGetDirLightShadowFactorHard (vec4 shadowPosWithDepthBias) {\n\t vec3 shadowNDCPos;\n\t if (!GetShadowNDCPos(shadowNDCPos, shadowPosWithDepthBias)) {\n\t\t return 1.0;\n\t }\n return NativePCFShadowFactorHard(shadowNDCPos, cc_shadowMap, cc_shadowWHPBInfo.xy);\n }\n float CCGetDirLightShadowFactorSoft (vec4 shadowPosWithDepthBias) {\n\t vec3 shadowNDCPos;\n\t if (!GetShadowNDCPos(shadowNDCPos, shadowPosWithDepthBias)) {\n\t\t return 1.0;\n\t }\n return NativePCFShadowFactorSoft(shadowNDCPos, cc_shadowMap, cc_shadowWHPBInfo.xy);\n }\n float CCGetDirLightShadowFactorSoft3X (vec4 shadowPosWithDepthBias) {\n\t vec3 shadowNDCPos;\n\t if (!GetShadowNDCPos(shadowNDCPos, shadowPosWithDepthBias)) {\n\t\t return 1.0;\n\t }\n return NativePCFShadowFactorSoft3X(shadowNDCPos, cc_shadowMap, cc_shadowWHPBInfo.xy);\n }\n float CCGetSpotLightShadowFactorHard (vec4 shadowPosWithDepthBias, vec3 worldPos) {\n\t vec3 shadowNDCPos;\n\t if (!GetShadowNDCPos(shadowNDCPos, shadowPosWithDepthBias)) {\n\t\t return 1.0;\n\t }\n return NativePCFShadowFactorHard(shadowNDCPos, cc_spotShadowMap, cc_shadowWHPBInfo.xy);\n }\n float CCGetSpotLightShadowFactorSoft (vec4 shadowPosWithDepthBias, vec3 worldPos) {\n\t vec3 shadowNDCPos;\n\t if (!GetShadowNDCPos(shadowNDCPos, shadowPosWithDepthBias)) {\n\t\t return 1.0;\n\t }\n return NativePCFShadowFactorSoft(shadowNDCPos, cc_spotShadowMap, cc_shadowWHPBInfo.xy);\n }\n float CCGetSpotLightShadowFactorSoft3X (vec4 shadowPosWithDepthBias, vec3 worldPos) {\n\t vec3 shadowNDCPos;\n\t if (!GetShadowNDCPos(shadowNDCPos, shadowPosWithDepthBias)) {\n\t\t return 1.0;\n\t }\n return NativePCFShadowFactorSoft3X(shadowNDCPos, cc_spotShadowMap, cc_shadowWHPBInfo.xy);\n }\n float CCSpotShadowFactorBase(vec4 shadowPos, vec3 worldPos, vec2 shadowBias)\n {\n float pcf = cc_shadowWHPBInfo.z;\n vec4 pos = vec4(1.0);\n #if CC_SHADOWMAP_USE_LINEAR_DEPTH\n pos = ApplyShadowDepthBias_PerspectiveLinearDepth(shadowPos, shadowBias.x, worldPos);\n #else\n pos = ApplyShadowDepthBias_Perspective(shadowPos, shadowBias.x);\n #endif\n if (pcf > 1.9) {\n return CCGetSpotLightShadowFactorSoft3X(pos, worldPos);\n }else if (pcf > 0.9) {\n return CCGetSpotLightShadowFactorSoft(pos, worldPos);\n }else {\n return CCGetSpotLightShadowFactorHard(pos, worldPos);\n }\n }\n float CCShadowFactorBase(vec4 shadowPos, vec3 N, vec2 shadowBias)\n {\n float realtimeShadow = 1.0;\n vec4 pos = ApplyShadowDepthBias_FaceNormal(shadowPos, N, shadowBias.y, cc_matLightView, cc_shadowProjInfo.xy);\n pos = ApplyShadowDepthBias_Orthographic(pos, shadowBias.x, cc_shadowProjDepthInfo.x, cc_shadowProjDepthInfo.y);\n float pcf = cc_shadowWHPBInfo.z;\n if (pcf > 1.9) {\n realtimeShadow = CCGetDirLightShadowFactorSoft3X(pos);\n }else if (pcf > 0.9) {\n realtimeShadow = CCGetDirLightShadowFactorSoft(pos);\n }else {\n realtimeShadow = CCGetDirLightShadowFactorHard(pos);\n }\n return mix(realtimeShadow, 1.0, cc_shadowNFLSInfo.w);\n }\n #if CC_SUPPORT_CASCADED_SHADOW_MAP\n int CCGetCSMLevel(out vec4 csmPos, out vec4 shadowProjDepthInfo, out vec4 shadowProjInfo, out vec3 shadowViewDir0, out vec3 shadowViewDir1, out vec3 shadowViewDir2, vec3 worldPos) {\n int layer = -1;\n highp float layerThreshold = cc_csmViewDir0[0].w;\n for (int i = 0; i < 4; i++) {\n vec4 shadowPos = cc_matCSMViewProj[i] * vec4(worldPos.xyz, 1.0);\n vec3 clipPos = shadowPos.xyz / shadowPos.w * 0.5 + 0.5;\n if (clipPos.x >= (0.0 + layerThreshold) && clipPos.x <= (1.0 - layerThreshold) &&\n clipPos.y >= (0.0 + layerThreshold) && clipPos.y <= (1.0 - layerThreshold) &&\n clipPos.z >= 0.0 && clipPos.z <= 1.0 && layer < 0) {\n csmPos = cc_matCSMViewProj[i] * vec4(worldPos.xyz, 1.0);\n csmPos.xy = csmPos.xy * cc_csmAtlas[i].xy + cc_csmAtlas[i].zw;\n shadowProjDepthInfo = cc_csmProjDepthInfo[i];\n shadowProjInfo = cc_csmProjInfo[i];\n shadowViewDir0 = cc_csmViewDir0[i].xyz;\n shadowViewDir1 = cc_csmViewDir1[i].xyz;\n shadowViewDir2 = cc_csmViewDir2[i].xyz;\n layer = i;\n }\n }\n return layer;\n }\n float CCCSMFactorBase(vec3 worldPos, vec3 N, vec2 shadowBias)\n {\n vec4 csmPos = vec4(1.0);\n vec4 shadowProjDepthInfo, shadowProjInfo;\n vec3 shadowViewDir0, shadowViewDir1, shadowViewDir2;\n int level = CCGetCSMLevel(csmPos, shadowProjDepthInfo, shadowProjInfo, shadowViewDir0, shadowViewDir1, shadowViewDir2, worldPos);\n if (level < 0) { return 1.0; }\n float realtimeShadow = 1.0;\n vec4 pos = ApplyShadowDepthBias_FaceNormal(csmPos, N, shadowBias.y, shadowViewDir0, shadowViewDir1, shadowViewDir2, shadowProjInfo.xy);\n pos = ApplyShadowDepthBias_Orthographic(pos, shadowBias.x, shadowProjDepthInfo.x, shadowProjDepthInfo.y);\n float pcf = cc_shadowWHPBInfo.z;\n if (pcf > 1.9) {\n realtimeShadow = CCGetDirLightShadowFactorSoft3X(pos);\n } else if (pcf > 0.9) {\n realtimeShadow = CCGetDirLightShadowFactorSoft(pos);\n }else {\n realtimeShadow = CCGetDirLightShadowFactorHard(pos);\n }\n return mix(realtimeShadow, 1.0, cc_shadowNFLSInfo.w);\n }\n #else\n int CCGetCSMLevel(out vec4 csmPos, out vec4 shadowProjDepthInfo, out vec4 shadowProjInfo, out vec3 shadowViewDir0, out vec3 shadowViewDir1, out vec3 shadowViewDir2, vec3 worldPos) {\n return -1;\n }\n float CCCSMFactorBase(vec3 worldPos, vec3 N, vec2 shadowBias) {\n vec4 shadowPos = cc_matLightViewProj * vec4(worldPos, 1.0);\n return CCShadowFactorBase(shadowPos, N, shadowBias);\n }\n #endif\n#endif\n#if CC_USE_IBL\n uniform samplerCube cc_environment;\n vec4 fragTextureLod (sampler2D tex, vec2 coord, float lod) {\n return textureLod(tex, coord, lod);\n }\n vec4 fragTextureLod (samplerCube tex, vec3 coord, float lod) {\n return textureLod(tex, coord, lod);\n }\n vec3 unpackRGBE (vec4 rgbe) {\n return rgbe.rgb * pow(1.1, rgbe.a * 255.0 - 128.0);\n }\n #if CC_USE_DIFFUSEMAP\n uniform samplerCube cc_diffuseMap;\n #endif\n#endif\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}\n#if USE_REFLECTION_DENOISE\n vec3 GetEnvReflectionWithMipFiltering(vec3 R, float roughness, float mipCount, float denoiseIntensity) {\n #if CC_USE_IBL\n \tfloat mip = roughness * (mipCount - 1.0);\n \tfloat delta = (dot(dFdx(R), dFdy(R))) * 1000.0;\n \tfloat mipBias = mix(0.0, 5.0, clamp(delta, 0.0, 1.0));\n \tvec4 biased = fragTextureLod(cc_environment, R, mip + mipBias);\n \tvec4 filtered = texture(cc_environment, R);\n #if CC_USE_IBL == 2\n \tbiased.rgb = unpackRGBE(biased);\n \tfiltered.rgb = unpackRGBE(filtered);\n #else\n \tbiased.rgb = SRGBToLinear(biased.rgb);\n \tfiltered.rgb = SRGBToLinear(filtered.rgb);\n #endif\n return mix(biased.rgb, filtered.rgb, denoiseIntensity);\n #else\n return vec3(0.0, 0.0, 0.0);\n #endif\n }\n#endif\nstruct StandardSurface {\n vec4 albedo;\n #if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\n vec3 position, position_fract_part;\n #else\n vec3 position;\n #endif\n vec3 normal;\n vec3 emissive;\n vec3 lightmap;\n float lightmap_test;\n float roughness;\n float metallic;\n float occlusion;\n float specularIntensity;\n #if CC_RECEIVE_SHADOW\n vec2 shadowBias;\n #endif\n};\nvec4 CCStandardShadingBase (StandardSurface s, vec4 shadowPos) {\n vec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\n vec3 specular = mix(vec3(0.08 * s.specularIntensity), s.albedo.rgb, s.metallic);\n vec3 position;\n #if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\n position = unpackHighpData(s.position, s.position_fract_part);\n #else\n position = s.position;\n #endif\n vec3 N = normalize(s.normal);\n vec3 V = normalize(cc_cameraPos.xyz - position);\n vec3 L = normalize(-cc_mainLitDir.xyz);\n float NL = max(dot(N, L), 0.0);\n float shadow = 1.0;\n #if CC_RECEIVE_SHADOW\n if (NL > 0.0 && cc_mainLitDir.w > 0.0) {\n if (cc_shadowLPNNInfo.w > 0.0) {\n shadow = CCCSMFactorBase(position, N, s.shadowBias);\n } else {\n shadow = CCShadowFactorBase(shadowPos, N, s.shadowBias);\n }\n }\n #endif\n #if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\n vec3 finalColor = diffuse * s.lightmap.rgb * shadow;\n #else\n float NV = max(abs(dot(N, V)), 0.0);\n specular = BRDFApprox(specular, s.roughness, NV);\n vec3 H = normalize(L + V);\n float NH = max(dot(N, H), 0.0);\n vec3 finalColor = NL * cc_mainLitColor.rgb * cc_mainLitColor.w;\n vec3 diffuseContrib = diffuse / PI;\n vec3 specularContrib = specular * CalcSpecular(s.roughness, NH, H, N);\n vec3 dirlightContrib = (diffuseContrib + specularContrib);\n dirlightContrib *= shadow;\n finalColor *= dirlightContrib;\n #endif\n float fAmb = 0.5 - N.y * 0.5;\n vec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb);\n #if CC_USE_IBL\n #if CC_USE_DIFFUSEMAP\n vec4 diffuseMap = texture(cc_diffuseMap, N);\n #if CC_USE_DIFFUSEMAP == 2\n ambDiff = unpackRGBE(diffuseMap);\n #else\n ambDiff = SRGBToLinear(diffuseMap.rgb);\n #endif\n #endif\n vec3 R = normalize(reflect(-V, N));\n #if USE_REFLECTION_DENOISE && !CC_IBL_CONVOLUTED\n vec3 env = GetEnvReflectionWithMipFiltering(R, s.roughness, cc_ambientGround.w, 0.6);\n #else\n vec4 envmap = fragTextureLod(cc_environment, R, s.roughness * (cc_ambientGround.w - 1.0));\n #if CC_USE_IBL == 2\n vec3 env = unpackRGBE(envmap);\n #else\n vec3 env = SRGBToLinear(envmap.rgb);\n #endif\n #endif\n finalColor += env * cc_ambientSky.w * specular * s.occlusion;\n #endif\n finalColor += ambDiff.rgb * cc_ambientSky.w * diffuse * s.occlusion;\n finalColor += s.emissive;\n return vec4(finalColor, s.albedo.a);\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 = ACESToneMap(color.rgb);\n #endif\n color.rgb = LinearToSRGB(color.rgb);\n return color;\n}\nin highp vec4 v_shadowPos;\n#if CC_RECEIVE_SHADOW\n#endif\nbool GetMetallicAlbedoFromDiffuseSpecularWithoutColor(out float metallic, out vec3 albedo, vec3 diffuse, vec3 specular, float f0 )\n{\n\tfloat d = max(max(diffuse.x, diffuse.y), diffuse.z);\n\tvec3 normalizedColor = diffuse / (d + (d < EPSILON_LOWP ? EPSILON_LOWP : 0.0));\n\tnormalizedColor = d < EPSILON_LOWP ? specular : normalizedColor;\n\tfloat s = max(max(specular.x, specular.y), specular.z);\n\tfloat delta = (d + s) * (d + s) - 4.0 * f0 * d;\n\tfloat deltaSqrt = sqrt(max(0.0, delta));\n\tfloat solverMetallic = (-d - s + 2.0 * f0 + deltaSqrt) / (2.0 * f0);\n\tvec3 solverAlbedo = (d + s) * normalizedColor - vec3(f0 * (1.0 - solverMetallic));\n\tbool isValidSolver = delta >= 0.0;\n\tmetallic = isValidSolver ? clamp(solverMetallic, 0.0, 1.0) : 0.0;\n\talbedo = isValidSolver ? vec3(max(0.0, solverAlbedo.x), max(0.0, solverAlbedo.y), max(0.0, solverAlbedo.z)) : diffuse;\n\treturn isValidSolver;\n}\n#if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\n in vec3 v_luv;\n uniform sampler2D cc_lightingMap;\n#endif\nin vec3 v_position;\nin vec2 v_uv;\nin vec2 v_uv1;\nin vec3 v_normal;\n#if CC_RECEIVE_SHADOW\n in mediump vec2 v_shadowBias;\n#endif\n#define DCC_APP_OTHERS 0\n#define DCC_APP_AUTODESK 1\n#define DCC_APP_BLENDER 2\n#define DCC_APP_CINEMA4D 3\n#define DCC_APP_GLTF 4\n#if USE_SHININESS_MAP\n uniform sampler2D shininessExponentMap;\n#endif\n#if USE_SPECULAR_GLOSSINESS_MAP\n uniform sampler2D specularGlossinessMap;\n#endif\n#if USE_SPECULAR_MAP\n uniform sampler2D specularMap;\n#endif\n #if USE_METALLIC_MAP\n uniform sampler2D metallicMap;\n#endif\n#if USE_VERTEX_COLOR\n in vec4 v_color;\n#endif\n#if USE_ALBEDO_MAP\n uniform sampler2D albedoMap;\n#endif\n#if USE_TRANSPARENCY_MAP\n uniform sampler2D transparencyMap;\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_EMISSIVE_MAP\n uniform sampler2D emissiveMap;\n#endif\nfloat discolor(vec3 srcColor) {\n return dot(GRAY_VECTOR, srcColor);\n}\nfloat convertShininessExponent(float shininessExp)\n{\n #if DCC_APP_NAME == DCC_APP_BLENDER\n float glossiness = clamp(sqrt(shininessExp) * 0.1, 0.0, 0.95);\n #elif DCC_APP_NAME == DCC_APP_AUTODESK\n float l2 = clamp(log(shininessExp + EPSILON) * 0.1442695 , 0.0, 1.0);\n float glossiness = pow(l2, 0.5);\n #else\n float glossiness = clamp(log(shininessExp + EPSILON) * 0.1442695 , 0.0, 1.0);\n #endif\n return glossiness;\n}\nfloat getSpecularIntensityFromRoughness(float roughness)\n{\n #if DCC_APP_NAME == DCC_APP_BLENDER\n float specularIntensityMultiplier = mix(1.0, 5.0, roughness);\n #elif DCC_APP_NAME == DCC_APP_CINEMA4D\n float specularIntensityMultiplier = mix(1.0, 50.0, roughness);\n #elif DCC_APP_NAME == DCC_APP_AUTODESK\n float specularIntensityMultiplier = mix(1.0, 20.0, roughness);\n #else\n float specularIntensityMultiplier = 1.0;\n #endif\n return specularIntensityMultiplier;\n}\nvec4 getSpecularColorAndFactor()\n{\n vec3 inSpecular = specularColor.rgb;\n #if USE_SPECULAR_GLOSSINESS_MAP\n inSpecular = SRGBToLinear(texture(specularGlossinessMap, TEXTURE_UV).rgb);\n #endif\n #if USE_SPECULAR_MAP\n vec4 specularTex = texture(specularMap, TEXTURE_UV);\n specularTex.rgb = SRGBToLinear(specularTex.rgb);\n inSpecular = specularTex.rgb;\n #endif\n return vec4(inSpecular, specularFactor);\n}\nvoid surf (out StandardSurface s) {\n vec4 baseColor = vec4(1.0);\n #if USE_VERTEX_COLOR\n baseColor.rgb *= SRGBToLinear(v_color.rgb);\n baseColor.a *= v_color.a;\n #endif\n #if USE_ALBEDO_MAP\n vec4 texColor = texture(albedoMap, TEXTURE_UV);\n texColor.rgb = SRGBToLinear(texColor.rgb);\n texColor.a *= transparencyFactor;\n baseColor *= texColor;\n #else\n baseColor *= diffuseColor;\n #endif\n baseColor.rgb *= diffuseFactor;\n #if USE_TRANSPARENCY_MAP\n baseColor.a = texture(transparencyMap, TEXTURE_UV).a;\n #endif\n #if USE_ALPHA_TEST\n if (baseColor.a < alphaThreshold) discard;\n #endif\n #if CC_RECEIVE_SHADOW\n s.shadowBias = v_shadowBias;\n #endif\n vec4 specularColorAndFactor = getSpecularColorAndFactor();\n float inGlossiness = 0.0, inSpecularIntensity = specularColorAndFactor.w;\n #if HAS_EXPORTED_GLOSSINESS\n #if USE_SPECULAR_GLOSSINESS_MAP\n inGlossiness = 1.0 - texture(specularGlossinessMap, TEXTURE_UV).a;\n #else\n inGlossiness = glossiness;\n #endif\n #else\n #if USE_SHININESS_MAP\n #if USE_SHININESS_MAP_CHANNEL\n inGlossiness = 1.0 - texture(shininessExponentMap, TEXTURE_UV).SHININESS_MAP_CHANNEL;\n #else\n inGlossiness = 1.0 - discolor(texture(shininessExponentMap, TEXTURE_UV).rgb);\n #endif\n #else\n inGlossiness = convertShininessExponent(shininessExponent);\n #endif\n inSpecularIntensity *= getSpecularIntensityFromRoughness(1.0 - inGlossiness);\n #endif\n float inMetallic = 0.0;\n vec4 albedo = baseColor;\n #if HAS_EXPORTED_METALLIC\n inMetallic = metallic;\n float spec = specularFactor;\n #if USE_SPECULAR_MAP\n spec = dot(GRAY_VECTOR, texture(specularMap, TEXTURE_UV).rgb);\n #endif\n inSpecularIntensity *= spec * 0.5;\n #else\n GetMetallicAlbedoFromDiffuseSpecularWithoutColor(inMetallic, albedo.rgb, baseColor.rgb, specularColorAndFactor.rgb, 0.04);\n inSpecularIntensity *= inMetallic;\n #endif\n s.normal = v_normal;\n #if USE_NORMAL_MAP\n vec3 nmmp = texture(normalMap, TEXTURE_UV).xyz - vec3(0.5);\n s.normal =\n (nmmp.x * normalScale) * normalize(v_tangent) +\n (nmmp.y * normalScale) * normalize(v_bitangent) +\n nmmp.z * normalize(s.normal);\n #endif\n #if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\n packHighpData(s.position, s.position_fract_part, v_position);\n #else\n s.position = v_position;\n #endif\n s.albedo = albedo;\n s.occlusion = 1.0;\n s.roughness = 1.0 - inGlossiness;\n s.metallic = inMetallic;\n s.specularIntensity = inSpecularIntensity * 0.5;\n s.emissive = vec3(0.0);\n#if USE_EMISSIVE_MAP\n s.emissive = texture(emissiveMap, TEXTURE_UV).xyz;\n#endif\n #if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\n vec4 lightColor = texture(cc_lightingMap, v_luv.xy);\n s.lightmap = lightColor.xyz * v_luv.z;\n s.lightmap_test = v_luv.z;\n #endif\n}\n#if CC_FORWARD_ADD\n #if CC_PIPELINE_TYPE == 0\n #define LIGHTS_PER_PASS 1\n #else\n #define LIGHTS_PER_PASS 10\n #endif\n #if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 0\n layout(std140) uniform CCForwardLight {\n highp vec4 cc_lightPos[LIGHTS_PER_PASS];\n vec4 cc_lightColor[LIGHTS_PER_PASS];\n vec4 cc_lightSizeRangeAngle[LIGHTS_PER_PASS];\n vec4 cc_lightDir[LIGHTS_PER_PASS];\n };\n #endif\n float 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 }\n float 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 }\n float 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 #if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 0\n vec4 CCStandardShadingAdditive (StandardSurface s, vec4 shadowPos) {\n vec3 position;\n #if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\n position = unpackHighpData(s.position, s.position_fract_part);\n #else\n position = s.position;\n #endif\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 / PI;\n vec3 N = normalize(s.normal);\n vec3 V = normalize(cc_cameraPos.xyz - position);\n float NV = max(abs(dot(N, V)), 0.0);\n specular = BRDFApprox(specular, s.roughness, NV);\n vec3 finalColor = vec3(0.0);\n int numLights = CC_PIPELINE_TYPE == 0 ? LIGHTS_PER_PASS : int(cc_lightDir[0].w);\n for (int i = 0; i < LIGHTS_PER_PASS; i++) {\n if (i >= numLights) break;\n vec3 SLU = cc_lightPos[i].xyz - position;\n vec3 SL = normalize(SLU);\n vec3 SH = normalize(SL + V);\n float SNL = max(dot(N, SL), 0.0);\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 = 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_lightPos[i].w > 0.0) {\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 }\n vec3 lightColor = cc_lightColor[i].rgb;\n float shadow = 1.0;\n #if CC_RECEIVE_SHADOW\n if (cc_lightPos[i].w > 0.0 && cc_lightSizeRangeAngle[i].w > 0.0) {\n shadow = CCSpotShadowFactorBase(shadowPos, position, s.shadowBias);\n }\n #endif\n lightColor *= shadow;\n finalColor += SNL * lightColor * cc_lightColor[i].w * illum * att * (diffuseContrib + lspec);\n }\n return vec4(finalColor, 0.0);\n }\n #endif\n #if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 1\n layout(std430, binding = 4) readonly buffer b_ccLightsBuffer { vec4 b_ccLights[]; };\n layout(std430, binding = 5) readonly buffer b_clusterLightIndicesBuffer { uint b_clusterLightIndices[]; };\n layout(std430, binding = 6) readonly buffer b_clusterLightGridBuffer { uvec4 b_clusterLightGrid[]; };\n struct CCLight\n {\n vec4 cc_lightPos;\n vec4 cc_lightColor;\n vec4 cc_lightSizeRangeAngle;\n vec4 cc_lightDir;\n };\n struct Cluster\n {\n vec3 minBounds;\n vec3 maxBounds;\n };\n struct LightGrid\n {\n uint offset;\n uint ccLights;\n };\n CCLight getCCLight(uint i)\n {\n CCLight light;\n light.cc_lightPos = b_ccLights[4u * i + 0u];\n light.cc_lightColor = b_ccLights[4u * i + 1u];\n light.cc_lightSizeRangeAngle = b_ccLights[4u * i + 2u];\n light.cc_lightDir = b_ccLights[4u * i + 3u];\n return light;\n }\n LightGrid getLightGrid(uint cluster)\n {\n uvec4 gridvec = b_clusterLightGrid[cluster];\n LightGrid grid;\n grid.offset = gridvec.x;\n grid.ccLights = gridvec.y;\n return grid;\n }\n uint getGridLightIndex(uint start, uint offset)\n {\n return b_clusterLightIndices[start + offset];\n }\n uint getClusterZIndex(vec4 worldPos)\n {\n float scale = float(24) / log(cc_nearFar.y / cc_nearFar.x);\n float bias = -(float(24) * log(cc_nearFar.x) / log(cc_nearFar.y / cc_nearFar.x));\n float eyeDepth = -(cc_matView * worldPos).z;\n uint zIndex = uint(max(log(eyeDepth) * scale + bias, 0.0));\n return zIndex;\n }\n uint getClusterIndex(vec4 fragCoord, vec4 worldPos)\n {\n uint zIndex = getClusterZIndex(worldPos);\n float clusterSizeX = ceil(cc_viewPort.z / float(16));\n float clusterSizeY = ceil(cc_viewPort.w / float(8));\n uvec3 indices = uvec3(uvec2(fragCoord.xy / vec2(clusterSizeX, clusterSizeY)), zIndex);\n uint cluster = (16u * 8u) * indices.z + 16u * indices.y + indices.x;\n return cluster;\n }\n vec4 CCClusterShadingAdditive (StandardSurface s, vec4 shadowPos) {\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 / PI;\n vec3 position;\n #if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\n position = unpackHighpData(s.position, s.position_fract_part);\n #else\n position = s.position;\n #endif\n vec3 N = normalize(s.normal);\n vec3 V = normalize(cc_cameraPos.xyz - 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 uint cluster = getClusterIndex(gl_FragCoord, vec4(position, 1.0));\n LightGrid grid = getLightGrid(cluster);\n uint numLights = grid.ccLights;\n for (uint i = 0u; i < 100u; i++) {\n if (i >= numLights) break;\n uint lightIndex = getGridLightIndex(grid.offset, i);\n CCLight light = getCCLight(lightIndex);\n vec3 SLU = light.cc_lightPos.xyz - 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 = light.cc_lightSizeRangeAngle.x;\n float litRadiusSqr = litRadius * litRadius;\n float illum = PI * (litRadiusSqr / max(litRadiusSqr , distSqr));\n float attRadiusSqrInv = 1.0 / max(light.cc_lightSizeRangeAngle.y, 0.01);\n attRadiusSqrInv *= attRadiusSqrInv;\n float att = GetDistAtt(distSqr, attRadiusSqrInv);\n vec3 lspec = specular * CalcSpecular(s.roughness, SNH, SH, N);\n if (light.cc_lightPos.w > 0.0) {\n float cosInner = max(dot(-light.cc_lightDir.xyz, SL), 0.01);\n float cosOuter = light.cc_lightSizeRangeAngle.z;\n float litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\n float litAngleOffset = -cosOuter * litAngleScale;\n att *= GetAngleAtt(SL, -light.cc_lightDir.xyz, litAngleScale, litAngleOffset);\n }\n vec3 lightColor = light.cc_lightColor.rgb;\n float shadow = 1.0;\n #if CC_RECEIVE_SHADOW\n if (light.cc_lightPos.w > 0.0) {\n shadow = CCSpotShadowFactorBase(shadowPos, position, s.shadowBias);\n }\n #endif\n lightColor *= shadow;\n finalColor += SNL * lightColor * light.cc_lightColor.w * illum * att * (diffuseContrib + lspec);\n }\n return vec4(finalColor, 0.0);\n }\n #endif\n layout(location = 0) out vec4 fragColorX;\n void main () {\n StandardSurface s; surf(s);\n #if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 1\n vec4 color = CCClusterShadingAdditive(s, v_shadowPos);\n #else\n vec4 color = CCStandardShadingAdditive(s, v_shadowPos);\n #endif\n fragColorX = CCFragOutput(color);\n }\n#elif (CC_PIPELINE_TYPE == 0 || CC_FORCE_FORWARD_SHADING)\n layout(location = 0) out vec4 fragColorX;\n void main () {\n StandardSurface s; surf(s);\n vec4 color = CCStandardShadingBase(s, v_shadowPos);\n CC_APPLY_FOG(color, s.position.xyz);\n fragColorX = CCFragOutput(color);\n }\n#elif CC_PIPELINE_TYPE == 1\n vec2 signNotZero(vec2 v) {\n return vec2((v.x >= 0.0) ? +1.0 : -1.0, (v.y >= 0.0) ? +1.0 : -1.0);\n }\n vec2 float32x3_to_oct(in vec3 v) {\n vec2 p = v.xy * (1.0 / (abs(v.x) + abs(v.y) + abs(v.z)));\n return (v.z <= 0.0) ? ((1.0 - abs(p.yx)) * signNotZero(p)) : p;\n }\n layout(location = 0) out vec4 fragColor0;\n layout(location = 1) out vec4 fragColor1;\n layout(location = 2) out vec4 fragColor2;\n void main () {\n StandardSurface s; surf(s);\n fragColor0 = s.albedo;\n fragColor1 = vec4(float32x3_to_oct(s.normal), s.roughness, s.metallic);\n fragColor2 = vec4(s.emissive, s.occlusion);\n }\n#endif"
|
|
},
|
|
"glsl1": {
|
|
"vert": "\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\n rgba = rgba * 255.0;\n highp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\n highp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\n highp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\n}\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_SKINNING\n attribute vec4 a_joints;\n attribute vec4 a_weights;\n#endif\n#if USE_INSTANCING\n #if CC_USE_BAKED_ANIMATION\n attribute highp vec4 a_jointAnimInfo;\n #endif\n attribute vec4 a_matWorld0;\n attribute vec4 a_matWorld1;\n attribute vec4 a_matWorld2;\n #if CC_USE_LIGHTMAP\n attribute vec4 a_lightingMapUVParam;\n #endif\n #if CC_RECEIVE_SHADOW\n attribute vec2 a_localShadowBias;\n #endif\n#elif USE_BATCHING\n attribute float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\n attribute float a_vertexId;\n int getVertexId() {\n return int(a_vertexId);\n }\n#endif\n#if CC_USE_MORPH\n uniform vec4 cc_displacementWeights[15];\n uniform vec4 cc_displacementTextureInfo;\n #if CC_MORPH_TARGET_HAS_POSITION\n uniform sampler2D cc_PositionDisplacements;\n #endif\n #if CC_MORPH_TARGET_HAS_NORMAL\n uniform sampler2D cc_NormalDisplacements;\n #endif\n #if CC_MORPH_TARGET_HAS_TANGENT\n uniform sampler2D cc_TangentDisplacements;\n #endif\n vec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\n float pixelIndexF = float(pixelIndex);\n float x = mod(pixelIndexF, textureResolution.x);\n float y = floor(pixelIndexF / textureResolution.x);\n return vec2(x, y);\n }\n vec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\n return (vec2(location.x, location.y) + .5) / textureResolution;\n }\n #if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\n vec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\n int pixelIndex = elementIndex;\n vec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\n vec2 uv = getPixelCoordFromLocation(location, cc_displacementTextureInfo.xy);\n return texture2D(tex, uv);\n }\n #else\n vec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\n int pixelIndex = elementIndex * 4;\n vec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\n vec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\n vec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\n vec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\n return vec4(\n decode32(texture2D(tex, x)),\n decode32(texture2D(tex, y)),\n decode32(texture2D(tex, z)),\n 1.0\n );\n }\n #endif\n float getDisplacementWeight(int index) {\n int quot = index / 4;\n int remainder = index - quot * 4;\n if (remainder == 0) {\n return cc_displacementWeights[quot].x;\n } else if (remainder == 1) {\n return cc_displacementWeights[quot].y;\n } else if (remainder == 2) {\n return cc_displacementWeights[quot].z;\n } else {\n return cc_displacementWeights[quot].w;\n }\n }\n vec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n #if CC_MORPH_PRECOMPUTED\n return fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n #else\n vec3 result = vec3(0, 0, 0);\n int nVertices = int(cc_displacementTextureInfo.z);\n for (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\n result += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n }\n return result;\n #endif\n }\n #if CC_MORPH_TARGET_HAS_POSITION\n vec3 getPositionDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n }\n #endif\n #if CC_MORPH_TARGET_HAS_NORMAL\n vec3 getNormalDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n }\n #endif\n #if CC_MORPH_TARGET_HAS_TANGENT\n vec3 getTangentDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n }\n #endif\n void applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\n int vertexId = getVertexId();\n #if CC_MORPH_TARGET_HAS_POSITION\n position.xyz = position.xyz + getPositionDisplacement(vertexId);\n #endif\n #if CC_MORPH_TARGET_HAS_NORMAL\n normal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n #endif\n #if CC_MORPH_TARGET_HAS_TANGENT\n tangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n #endif\n }\n void 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\n #if CC_USE_BAKED_ANIMATION\n uniform highp vec4 cc_jointTextureInfo;\n uniform highp vec4 cc_jointAnimInfo;\n uniform highp sampler2D cc_jointTexture;\n void CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n {\n #if USE_INSTANCING\n highp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n #else\n highp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n #endif\n invSize = cc_jointTextureInfo.w;\n highp float tempY = floor(temp * invSize);\n x = floor(temp - tempY * cc_jointTextureInfo.x);\n y = (tempY + 0.5) * invSize;\n }\n #else\n #if CC_USE_REAL_TIME_JOINT_TEXTURE\n uniform highp sampler2D cc_realtimeJoint;\n #else\n uniform highp vec4 cc_joints[CC_JOINT_UNIFORM_CAPACITY * 3];\n #endif\n #endif\n #if CC_USE_BAKED_ANIMATION\n #if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\n mat4 getJointMatrix (float i) {\n highp float x, y, invSize;\n CCGetJointTextureCoords(3.0, i, x, y, 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 highp float x, y, invSize;\n CCGetJointTextureCoords(12.0, i, x, y, 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 #if CC_USE_REAL_TIME_JOINT_TEXTURE\n #if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\n mat4 getJointMatrix (float i) {\n float x = i;\n vec4 v1 = texture2D(cc_realtimeJoint, vec2( x / 256.0, 0.5 / 3.0));\n vec4 v2 = texture2D(cc_realtimeJoint, vec2( x / 256.0, 1.5 / 3.0));\n vec4 v3 = texture2D(cc_realtimeJoint, vec2( x / 256.0, 2.5 / 3.0));\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 float x = 4.0 * i;\n vec4 v1 = vec4(\n decode32(texture2D(cc_realtimeJoint, vec2((x + 0.5)/ 1024.0, 0.5 / 3.0))),\n decode32(texture2D(cc_realtimeJoint, vec2((x + 1.5)/ 1024.0, 0.5 / 3.0))),\n decode32(texture2D(cc_realtimeJoint, vec2((x + 2.5)/ 1024.0, 0.5 / 3.0))),\n decode32(texture2D(cc_realtimeJoint, vec2((x + 3.5)/ 1024.0, 0.5 / 3.0)))\n );\n vec4 v2 = vec4(\n decode32(texture2D(cc_realtimeJoint, vec2((x + 0.5)/ 1024.0, 1.5 / 3.0))),\n decode32(texture2D(cc_realtimeJoint, vec2((x + 1.5)/ 1024.0, 1.5 / 3.0))),\n decode32(texture2D(cc_realtimeJoint, vec2((x + 2.5)/ 1024.0, 1.5 / 3.0))),\n decode32(texture2D(cc_realtimeJoint, vec2((x + 3.5)/ 1024.0, 1.5 / 3.0)))\n );\n vec4 v3 = vec4(\n decode32(texture2D(cc_realtimeJoint, vec2((x + 0.5)/ 1024.0, 2.5 / 3.0))),\n decode32(texture2D(cc_realtimeJoint, vec2((x + 1.5)/ 1024.0, 2.5 / 3.0))),\n decode32(texture2D(cc_realtimeJoint, vec2((x + 2.5)/ 1024.0, 2.5 / 3.0))),\n decode32(texture2D(cc_realtimeJoint, vec2((x + 3.5)/ 1024.0, 2.5 / 3.0)))\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\n #endif\n mat4 skinMatrix () {\n vec4 joints = vec4(a_joints);\n return getJointMatrix(joints.x) * a_weights.x\n + getJointMatrix(joints.y) * a_weights.y\n + getJointMatrix(joints.z) * a_weights.z\n + getJointMatrix(joints.w) * a_weights.w;\n }\n void CCSkin (inout vec4 position) {\n mat4 m = skinMatrix();\n position = m * position;\n }\n void CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\n mat4 m = skinMatrix();\n position = m * position;\n normal = (m * vec4(normal, 0.0)).xyz;\n tangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n }\n#endif\nvoid CCVertInput(inout StandardVertInput In)\n{\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.position, In.normal, In.tangent);\n #endif\n #if CC_USE_SKINNING\n CCSkin(In.position, In.normal, In.tangent);\n #endif\n}\nuniform highp mat4 cc_matView;\n uniform highp mat4 cc_matProj;\n uniform highp vec4 cc_cameraPos;\n uniform mediump vec4 cc_fogBase;\n uniform mediump vec4 cc_fogAdd;\n#if !USE_INSTANCING\n #if USE_BATCHING\n uniform highp mat4 cc_matWorlds[10];\n #else\n uniform highp mat4 cc_matWorld;\n uniform highp mat4 cc_matWorldIT;\n uniform highp vec4 cc_lightingMapUVParam;\n uniform highp vec4 cc_localShadowBias;\n #endif\n#endif\nvoid CCGetWorldMatrixFull(out mat4 matWorld, out mat4 matWorldIT)\n{\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}\n uniform vec4 tilingOffset;\n#if CC_USE_FOG != 4\n float LinearFog(vec4 pos, vec3 cameraPos, float fogStart, float fogEnd) {\n vec4 wPos = pos;\n float cam_dis = distance(cameraPos, wPos.xyz);\n return clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n }\n float ExpFog(vec4 pos, vec3 cameraPos, float fogStart, float fogDensity, float fogAtten) {\n vec4 wPos = pos;\n float cam_dis = max(distance(cameraPos, wPos.xyz) - fogStart, 0.0) / fogAtten * 4.;\n float f = exp(-cam_dis * fogDensity);\n return f;\n }\n float ExpSquaredFog(vec4 pos, vec3 cameraPos, float fogStart, float fogDensity, float fogAtten) {\n vec4 wPos = pos;\n float cam_dis = max(distance(cameraPos, wPos.xyz) - fogStart, 0.0) / fogAtten * 4.;\n float f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\n return f;\n }\n float LayeredFog(vec4 pos, vec3 cameraPos, float fogTop, float fogRange, float fogAtten) {\n vec4 wPos = pos;\n vec3 camWorldProj = 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 (cameraPos.y > fogTop) {\n if (wPos.y < fogTop) {\n fDeltaY = (fogTop - wPos.y) / fogRange * 2.0;\n fDensityIntegral = fDeltaY * fDeltaY * 0.5;\n }\n else {\n fDeltaY = 0.;\n fDensityIntegral = 0.;\n }\n }\n else {\n if (wPos.y < fogTop) {\n float fDeltaA = (fogTop - 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 }\n else {\n fDeltaY = abs(fogTop - 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 }\n else {\n fDensity = 0.;\n }\n float f = exp(-fDensity);\n return f;\n }\n#endif\nvoid CC_TRANSFER_FOG_BASE(vec4 pos, out float factor)\n{\n#if CC_USE_FOG == 0\n\tfactor = LinearFog(pos, cc_cameraPos.xyz, cc_fogBase.x, cc_fogBase.y);\n#elif CC_USE_FOG == 1\n\tfactor = ExpFog(pos, cc_cameraPos.xyz, cc_fogBase.x, cc_fogBase.z, cc_fogAdd.z);\n#elif CC_USE_FOG == 2\n\tfactor = ExpSquaredFog(pos, cc_cameraPos.xyz, cc_fogBase.x, cc_fogBase.z, cc_fogAdd.z);\n#elif CC_USE_FOG == 3\n\tfactor = LayeredFog(pos, cc_cameraPos.xyz, cc_fogAdd.x, cc_fogAdd.y, cc_fogAdd.z);\n#else\n\tfactor = 1.0;\n#endif\n}\n#if !CC_USE_ACCURATE_FOG\nvarying float v_fog_factor;\n#endif\nvoid CC_TRANSFER_FOG(vec4 pos) {\n#if !CC_USE_ACCURATE_FOG\n CC_TRANSFER_FOG_BASE(pos, v_fog_factor);\n#endif\n}\nvarying highp vec4 v_shadowPos;\nuniform highp mat4 cc_matLightViewProj;\n uniform mediump vec4 cc_shadowWHPBInfo;\n uniform mediump vec4 cc_shadowLPNNInfo;\n#if CC_SUPPORT_CASCADED_SHADOW_MAP\n #endif\n#if CC_RECEIVE_SHADOW\n uniform highp sampler2D cc_shadowMap;\n uniform highp sampler2D cc_spotShadowMap;\n #if CC_SUPPORT_CASCADED_SHADOW_MAP\n #else\n #endif\n#endif\n#if CC_RECEIVE_SHADOW\nvec2 CCGetShadowBias()\n{\n #if USE_INSTANCING\n return vec2(a_localShadowBias.x + cc_shadowWHPBInfo.w, a_localShadowBias.y + cc_shadowLPNNInfo.z);\n #elif !USE_BATCHING\n return vec2(cc_localShadowBias.x + cc_shadowWHPBInfo.w, cc_localShadowBias.y + cc_shadowLPNNInfo.z);\n #else\n return vec2(cc_shadowWHPBInfo.w, cc_shadowLPNNInfo.z);\n #endif\n}\n#endif\n#if USE_VERTEX_COLOR\n attribute vec4 a_color;\n varying vec4 v_color;\n#endif\nvarying vec3 v_position;\nvarying vec3 v_normal;\nvarying vec2 v_uv;\nvarying vec2 v_uv1;\n#if USE_NORMAL_MAP\n varying vec3 v_tangent;\n varying vec3 v_bitangent;\n#endif\n#if CC_RECEIVE_SHADOW\n varying mediump vec2 v_shadowBias;\n#endif\n#if HAS_SECOND_UV || CC_USE_LIGHTMAP\n attribute vec2 a_texCoord1;\n#endif\n#if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\n varying vec3 v_luv;\n void CCLightingMapCaclUV()\n {\n #if !USE_INSTANCING\n v_luv.xy = cc_lightingMapUVParam.xy + a_texCoord1 * cc_lightingMapUVParam.z;\n v_luv.z = cc_lightingMapUVParam.w;\n #else\n v_luv.xy = a_lightingMapUVParam.xy + a_texCoord1 * a_lightingMapUVParam.z;\n v_luv.z = a_lightingMapUVParam.w;\n #endif\n }\n#endif\nvoid main () {\n StandardVertInput In;\n CCVertInput(In);\n mat4 matWorld, matWorldIT;\n CCGetWorldMatrixFull(matWorld, matWorldIT);\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_TWOSIDE\n vec3 viewDirect = normalize(cc_cameraPos.xyz - v_position);\n v_normal *= dot(v_normal, viewDirect) < 0.0 ? -1.0 : 1.0;\n #endif\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 CC_TRANSFER_FOG(pos);\n v_shadowPos = cc_matLightViewProj * pos;\n #if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\n CCLightingMapCaclUV();\n #endif\n #if CC_RECEIVE_SHADOW\n v_shadowBias = CCGetShadowBias();\n #endif\n gl_Position = cc_matProj * (cc_matView * matWorld) * In.position;\n}",
|
|
"frag": "\n#ifdef GL_EXT_draw_buffers\n#extension GL_EXT_draw_buffers: enable\n#endif\n#ifdef GL_OES_standard_derivatives\n#extension GL_OES_standard_derivatives: enable\n#endif\n#ifdef GL_EXT_shader_texture_lod\n#extension GL_EXT_shader_texture_lod: enable\n#endif\nprecision highp float;\nuniform mediump vec4 cc_debug_view_mode;\n uniform mediump vec4 cc_debug_view_composite_pack_1;\n uniform mediump vec4 cc_debug_view_composite_pack_2;\n uniform mediump vec4 cc_debug_view_composite_pack_3;\nuniform highp mat4 cc_matView;\n uniform highp vec4 cc_cameraPos;\n uniform mediump vec4 cc_mainLitDir;\n uniform mediump vec4 cc_mainLitColor;\n uniform mediump vec4 cc_ambientSky;\n uniform mediump vec4 cc_ambientGround;\n uniform mediump vec4 cc_fogColor;\n uniform mediump vec4 cc_fogBase;\n uniform mediump vec4 cc_fogAdd;\n uniform mediump vec4 cc_nearFar;\n uniform mediump vec4 cc_viewPort;\n uniform vec4 diffuseColor;\n uniform vec4 specularColor;\n uniform vec4 emissive;\n uniform float alphaThreshold;\n uniform float shininessExponent;\n uniform float glossiness;\n uniform float metallic;\n uniform float normalScale;\n uniform float transparencyFactor;\n uniform float diffuseFactor;\n uniform float specularFactor;\n#if CC_USE_FOG != 4\n float LinearFog(vec4 pos, vec3 cameraPos, float fogStart, float fogEnd) {\n vec4 wPos = pos;\n float cam_dis = distance(cameraPos, wPos.xyz);\n return clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n }\n float ExpFog(vec4 pos, vec3 cameraPos, float fogStart, float fogDensity, float fogAtten) {\n vec4 wPos = pos;\n float cam_dis = max(distance(cameraPos, wPos.xyz) - fogStart, 0.0) / fogAtten * 4.;\n float f = exp(-cam_dis * fogDensity);\n return f;\n }\n float ExpSquaredFog(vec4 pos, vec3 cameraPos, float fogStart, float fogDensity, float fogAtten) {\n vec4 wPos = pos;\n float cam_dis = max(distance(cameraPos, wPos.xyz) - fogStart, 0.0) / fogAtten * 4.;\n float f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\n return f;\n }\n float LayeredFog(vec4 pos, vec3 cameraPos, float fogTop, float fogRange, float fogAtten) {\n vec4 wPos = pos;\n vec3 camWorldProj = 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 (cameraPos.y > fogTop) {\n if (wPos.y < fogTop) {\n fDeltaY = (fogTop - wPos.y) / fogRange * 2.0;\n fDensityIntegral = fDeltaY * fDeltaY * 0.5;\n }\n else {\n fDeltaY = 0.;\n fDensityIntegral = 0.;\n }\n }\n else {\n if (wPos.y < fogTop) {\n float fDeltaA = (fogTop - 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 }\n else {\n fDeltaY = abs(fogTop - 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 }\n else {\n fDensity = 0.;\n }\n float f = exp(-fDensity);\n return f;\n }\n#endif\nvoid CC_TRANSFER_FOG_BASE(vec4 pos, out float factor)\n{\n#if CC_USE_FOG == 0\n\tfactor = LinearFog(pos, cc_cameraPos.xyz, cc_fogBase.x, cc_fogBase.y);\n#elif CC_USE_FOG == 1\n\tfactor = ExpFog(pos, cc_cameraPos.xyz, cc_fogBase.x, cc_fogBase.z, cc_fogAdd.z);\n#elif CC_USE_FOG == 2\n\tfactor = ExpSquaredFog(pos, cc_cameraPos.xyz, cc_fogBase.x, cc_fogBase.z, cc_fogAdd.z);\n#elif CC_USE_FOG == 3\n\tfactor = LayeredFog(pos, cc_cameraPos.xyz, cc_fogAdd.x, cc_fogAdd.y, cc_fogAdd.z);\n#else\n\tfactor = 1.0;\n#endif\n}\nvoid CC_APPLY_FOG_BASE(inout vec4 color, float factor) {\n\tcolor = vec4(mix(cc_fogColor.rgb, color.rgb, factor), color.a);\n}\n#if !CC_USE_ACCURATE_FOG\nvarying float v_fog_factor;\n#endif\nvoid CC_APPLY_FOG(inout vec4 color) {\n#if !CC_USE_ACCURATE_FOG\n CC_APPLY_FOG_BASE(color, v_fog_factor);\n#endif\n}\nvoid CC_APPLY_FOG(inout vec4 color, vec3 worldPos) {\n#if CC_USE_ACCURATE_FOG\n float factor;\n CC_TRANSFER_FOG_BASE(vec4(worldPos, 1.0), factor);\n#else\n float factor = v_fog_factor;\n#endif\n CC_APPLY_FOG_BASE(color, factor);\n}\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\n#define CC_SURFACES_DEBUG_VIEW_VERTEX_COLOR 1\n#define CC_SURFACES_DEBUG_VIEW_VERTEX_NORMAL CC_SURFACES_DEBUG_VIEW_VERTEX_COLOR + 1\n#define CC_SURFACES_DEBUG_VIEW_VERTEX_TANGENT CC_SURFACES_DEBUG_VIEW_VERTEX_NORMAL + 1\n#define CC_SURFACES_DEBUG_VIEW_WORLD_POS CC_SURFACES_DEBUG_VIEW_VERTEX_TANGENT + 1\n#define CC_SURFACES_DEBUG_VIEW_VERTEX_MIRROR CC_SURFACES_DEBUG_VIEW_WORLD_POS + 1\n#define CC_SURFACES_DEBUG_VIEW_FACE_SIDE CC_SURFACES_DEBUG_VIEW_VERTEX_MIRROR + 1\n#define CC_SURFACES_DEBUG_VIEW_UV0 CC_SURFACES_DEBUG_VIEW_FACE_SIDE + 1\n#define CC_SURFACES_DEBUG_VIEW_UV1 CC_SURFACES_DEBUG_VIEW_UV0 + 1\n#define CC_SURFACES_DEBUG_VIEW_UVLIGHTMAP CC_SURFACES_DEBUG_VIEW_UV1 + 1\n#define CC_SURFACES_DEBUG_VIEW_PROJ_DEPTH CC_SURFACES_DEBUG_VIEW_UVLIGHTMAP + 1\n#define CC_SURFACES_DEBUG_VIEW_LINEAR_DEPTH CC_SURFACES_DEBUG_VIEW_PROJ_DEPTH + 1\n#define CC_SURFACES_DEBUG_VIEW_FRAGMENT_NORMAL CC_SURFACES_DEBUG_VIEW_LINEAR_DEPTH + 1\n#define CC_SURFACES_DEBUG_VIEW_FRAGMENT_TANGENT CC_SURFACES_DEBUG_VIEW_FRAGMENT_NORMAL + 1\n#define CC_SURFACES_DEBUG_VIEW_FRAGMENT_BINORMAL CC_SURFACES_DEBUG_VIEW_FRAGMENT_TANGENT + 1\n#define CC_SURFACES_DEBUG_VIEW_BASE_COLOR CC_SURFACES_DEBUG_VIEW_FRAGMENT_BINORMAL + 1\n#define CC_SURFACES_DEBUG_VIEW_DIFFUSE_COLOR CC_SURFACES_DEBUG_VIEW_BASE_COLOR + 1\n#define CC_SURFACES_DEBUG_VIEW_SPECULAR_COLOR CC_SURFACES_DEBUG_VIEW_DIFFUSE_COLOR + 1\n#define CC_SURFACES_DEBUG_VIEW_TRANSPARENCY CC_SURFACES_DEBUG_VIEW_SPECULAR_COLOR + 1\n#define CC_SURFACES_DEBUG_VIEW_METALLIC CC_SURFACES_DEBUG_VIEW_TRANSPARENCY + 1\n#define CC_SURFACES_DEBUG_VIEW_ROUGHNESS CC_SURFACES_DEBUG_VIEW_METALLIC + 1\n#define CC_SURFACES_DEBUG_VIEW_SPECULAR_INTENSITY CC_SURFACES_DEBUG_VIEW_ROUGHNESS + 1\n#define CC_SURFACES_DEBUG_VIEW_DIRECT_DIFFUSE CC_SURFACES_DEBUG_VIEW_SPECULAR_INTENSITY + 1\n#define CC_SURFACES_DEBUG_VIEW_DIRECT_SPECULAR CC_SURFACES_DEBUG_VIEW_DIRECT_DIFFUSE + 1\n#define CC_SURFACES_DEBUG_VIEW_DIRECT_ALL CC_SURFACES_DEBUG_VIEW_DIRECT_SPECULAR + 1\n#define CC_SURFACES_DEBUG_VIEW_ENV_DIFFUSE CC_SURFACES_DEBUG_VIEW_DIRECT_ALL + 1\n#define CC_SURFACES_DEBUG_VIEW_ENV_SPECULAR CC_SURFACES_DEBUG_VIEW_ENV_DIFFUSE + 1\n#define CC_SURFACES_DEBUG_VIEW_ENV_ALL CC_SURFACES_DEBUG_VIEW_ENV_SPECULAR + 1\n#define CC_SURFACES_DEBUG_VIEW_EMISSIVE CC_SURFACES_DEBUG_VIEW_ENV_ALL + 1\n#define CC_SURFACES_DEBUG_VIEW_LIGHT_MAP CC_SURFACES_DEBUG_VIEW_EMISSIVE + 1\n#define CC_SURFACES_DEBUG_VIEW_SHADOW CC_SURFACES_DEBUG_VIEW_LIGHT_MAP + 1\n#define CC_SURFACES_DEBUG_VIEW_AO CC_SURFACES_DEBUG_VIEW_SHADOW + 1\n#define CC_SURFACES_DEBUG_VIEW_FOG CC_SURFACES_DEBUG_VIEW_AO + 1\n#define CC_SURFACES_DEBUG_VIEW_SINGLE 1\n#define CC_SURFACES_DEBUG_VIEW_COMPOSITE_AND_MISC 2\n#define IS_DEBUG_VIEW_LIGHTING_ENABLE_WITH_ALBEDO (cc_debug_view_mode.y > 0.0)\n#define IS_DEBUG_VIEW_MISC_ENABLE_CSM_LAYER_COLORATION (cc_debug_view_mode.z > 0.0)\n#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_DIRECT_DIFFUSE (cc_debug_view_composite_pack_1.x > 0.0)\n#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_DIRECT_SPECULAR (cc_debug_view_composite_pack_1.y > 0.0)\n#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_ENV_DIFFUSE (cc_debug_view_composite_pack_1.z > 0.0)\n#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_ENV_SPECULAR (cc_debug_view_composite_pack_1.w > 0.0)\n#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_EMISSIVE (cc_debug_view_composite_pack_2.x > 0.0)\n#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_LIGHT_MAP (cc_debug_view_composite_pack_2.y > 0.0)\n#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_SHADOW (cc_debug_view_composite_pack_2.z > 0.0)\n#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_AO (cc_debug_view_composite_pack_2.w > 0.0)\n#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_NORMAL_MAP (cc_debug_view_composite_pack_3.x > 0.0)\n#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_FOG (cc_debug_view_composite_pack_3.y > 0.0)\n#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_TONE_MAPPING (cc_debug_view_composite_pack_3.z > 0.0)\n#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_GAMMA_CORRECTION (cc_debug_view_composite_pack_3.w > 0.0)\nvec3 SRGBToLinear (vec3 gamma) {\n#ifdef CC_USE_SURFACE_SHADER\n #if CC_USE_DEBUG_VIEW == CC_SURFACES_DEBUG_VIEW_COMPOSITE_AND_MISC\n if (!IS_DEBUG_VIEW_COMPOSITE_ENABLE_GAMMA_CORRECTION) {\n return gamma;\n }\n #endif\n#endif\n return gamma * gamma;\n}\nvec3 LinearToSRGB(vec3 linear) {\n#ifdef CC_USE_SURFACE_SHADER\n #if CC_USE_DEBUG_VIEW == CC_SURFACES_DEBUG_VIEW_COMPOSITE_AND_MISC\n if (!IS_DEBUG_VIEW_COMPOSITE_ENABLE_GAMMA_CORRECTION) {\n return linear;\n }\n #endif\n#endif\n return sqrt(linear);\n}\nuniform highp mat4 cc_matLightView;\n uniform highp mat4 cc_matLightViewProj;\n uniform highp vec4 cc_shadowInvProjDepthInfo;\n uniform highp vec4 cc_shadowProjDepthInfo;\n uniform highp vec4 cc_shadowProjInfo;\n uniform mediump vec4 cc_shadowNFLSInfo;\n uniform mediump vec4 cc_shadowWHPBInfo;\n uniform mediump vec4 cc_shadowLPNNInfo;\n#if CC_SUPPORT_CASCADED_SHADOW_MAP\n uniform highp vec4 cc_csmViewDir0[4];\n uniform highp vec4 cc_csmViewDir1[4];\n uniform highp vec4 cc_csmViewDir2[4];\n uniform highp vec4 cc_csmAtlas[4];\n uniform highp mat4 cc_matCSMViewProj[4];\n uniform highp vec4 cc_csmProjDepthInfo[4];\n uniform highp vec4 cc_csmProjInfo[4];\n#endif\nfloat GetLinearDepthFromViewSpace(vec3 viewPos, float near, float far) {\n float dist = length(viewPos);\n return (dist - near) / (far - near);\n}\nfloat CCGetLinearDepth(vec3 worldPos, float viewSpaceBias) {\n\tvec4 viewPos = cc_matLightView * vec4(worldPos.xyz, 1.0);\n viewPos.z += viewSpaceBias;\n\treturn GetLinearDepthFromViewSpace(viewPos.xyz, cc_shadowNFLSInfo.x, cc_shadowNFLSInfo.y);\n}\nfloat CCGetLinearDepth(vec3 worldPos) {\n\treturn CCGetLinearDepth(worldPos, 0.0);\n}\n#if CC_RECEIVE_SHADOW\n uniform highp sampler2D cc_shadowMap;\n uniform highp sampler2D cc_spotShadowMap;\n highp float unpackHighpData (float mainPart, float modPart) {\n highp float data = mainPart;\n return data + modPart;\n }\n void packHighpData (out float mainPart, out float modPart, highp float data) {\n mainPart = fract(data);\n modPart = data - mainPart;\n }\n highp float unpackHighpData (float mainPart, float modPart, const float modValue) {\n highp float data = mainPart * modValue;\n return data + modPart * modValue;\n }\n void packHighpData (out float mainPart, out float modPart, highp float data, const float modValue) {\n highp float divide = data / modValue;\n mainPart = floor(divide);\n modPart = (data - mainPart * modValue) / modValue;\n }\n highp vec2 unpackHighpData (vec2 mainPart, vec2 modPart) {\n highp vec2 data = mainPart;\n return data + modPart;\n }\n void packHighpData (out vec2 mainPart, out vec2 modPart, highp vec2 data) {\n mainPart = fract(data);\n modPart = data - mainPart;\n }\n highp vec2 unpackHighpData (vec2 mainPart, vec2 modPart, const float modValue) {\n highp vec2 data = mainPart * modValue;\n return data + modPart * modValue;\n }\n void packHighpData (out vec2 mainPart, out vec2 modPart, highp vec2 data, const float modValue) {\n highp vec2 divide = data / modValue;\n mainPart = floor(divide);\n modPart = (data - mainPart * modValue) / modValue;\n }\n highp vec3 unpackHighpData (vec3 mainPart, vec3 modPart) {\n highp vec3 data = mainPart;\n return data + modPart;\n }\n void packHighpData (out vec3 mainPart, out vec3 modPart, highp vec3 data) {\n mainPart = fract(data);\n modPart = data - mainPart;\n }\n highp vec3 unpackHighpData (vec3 mainPart, vec3 modPart, const float modValue) {\n highp vec3 data = mainPart * modValue;\n return data + modPart * modValue;\n }\n void packHighpData (out vec3 mainPart, out vec3 modPart, highp vec3 data, const float modValue) {\n highp vec3 divide = data / modValue;\n mainPart = floor(divide);\n modPart = (data - mainPart * modValue) / modValue;\n }\n highp vec4 unpackHighpData (vec4 mainPart, vec4 modPart) {\n highp vec4 data = mainPart;\n return data + modPart;\n }\n void packHighpData (out vec4 mainPart, out vec4 modPart, highp vec4 data) {\n mainPart = fract(data);\n modPart = data - mainPart;\n }\n highp vec4 unpackHighpData (vec4 mainPart, vec4 modPart, const float modValue) {\n highp vec4 data = mainPart * modValue;\n return data + modPart * modValue;\n }\n void packHighpData (out vec4 mainPart, out vec4 modPart, highp vec4 data, const float modValue) {\n highp vec4 divide = data / modValue;\n mainPart = floor(divide);\n modPart = (data - mainPart * modValue) / modValue;\n }\n float NativePCFShadowFactorHard (vec3 shadowNDCPos, sampler2D shadowMap, vec2 shadowMapResolution)\n {\n #if CC_SHADOWMAP_FORMAT == 1\n return step(shadowNDCPos.z, dot(texture2D(shadowMap, shadowNDCPos.xy), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n #else\n return step(shadowNDCPos.z, texture2D(shadowMap, shadowNDCPos.xy).x);\n #endif\n }\n float NativePCFShadowFactorSoft (vec3 shadowNDCPos, sampler2D shadowMap, vec2 shadowMapResolution)\n {\n vec2 oneTap = 1.0 / shadowMapResolution;\n vec2 shadowNDCPos_offset = shadowNDCPos.xy + oneTap;\n float block0, block1, block2, block3;\n #if CC_SHADOWMAP_FORMAT == 1\n block0 = step(shadowNDCPos.z, dot(texture2D(shadowMap, vec2(shadowNDCPos.x, shadowNDCPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n block1 = step(shadowNDCPos.z, dot(texture2D(shadowMap, vec2(shadowNDCPos_offset.x, shadowNDCPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n block2 = step(shadowNDCPos.z, dot(texture2D(shadowMap, vec2(shadowNDCPos.x, shadowNDCPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n block3 = step(shadowNDCPos.z, dot(texture2D(shadowMap, vec2(shadowNDCPos_offset.x, shadowNDCPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n #else\n block0 = step(shadowNDCPos.z, texture2D(shadowMap, vec2(shadowNDCPos.x, shadowNDCPos.y)).x);\n block1 = step(shadowNDCPos.z, texture2D(shadowMap, vec2(shadowNDCPos_offset.x, shadowNDCPos.y)).x);\n block2 = step(shadowNDCPos.z, texture2D(shadowMap, vec2(shadowNDCPos.x, shadowNDCPos_offset.y)).x);\n block3 = step(shadowNDCPos.z, texture2D(shadowMap, vec2(shadowNDCPos_offset.x, shadowNDCPos_offset.y)).x);\n #endif\n float coefX = mod(shadowNDCPos.x, oneTap.x) * shadowMapResolution.x;\n float resultX = mix(block0, block1, coefX);\n float resultY = mix(block2, block3, coefX);\n float coefY = mod(shadowNDCPos.y, oneTap.y) * shadowMapResolution.y;\n return mix(resultX, resultY, coefY);\n }\n float NativePCFShadowFactorSoft3X (vec3 shadowNDCPos, sampler2D shadowMap, vec2 shadowMapResolution)\n {\n vec2 oneTap = 1.0 / shadowMapResolution;\n float shadowNDCPos_offset_L = shadowNDCPos.x - oneTap.x;\n float shadowNDCPos_offset_R = shadowNDCPos.x + oneTap.x;\n float shadowNDCPos_offset_U = shadowNDCPos.y - oneTap.y;\n float shadowNDCPos_offset_D = shadowNDCPos.y + oneTap.y;\n float block0, block1, block2, block3, block4, block5, block6, block7, block8;\n #if CC_SHADOWMAP_FORMAT == 1\n block0 = step(shadowNDCPos.z, dot(texture2D(shadowMap, vec2(shadowNDCPos_offset_L, shadowNDCPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n block1 = step(shadowNDCPos.z, dot(texture2D(shadowMap, vec2(shadowNDCPos.x, shadowNDCPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n block2 = step(shadowNDCPos.z, dot(texture2D(shadowMap, vec2(shadowNDCPos_offset_R, shadowNDCPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n block3 = step(shadowNDCPos.z, dot(texture2D(shadowMap, vec2(shadowNDCPos_offset_L, shadowNDCPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n block4 = step(shadowNDCPos.z, dot(texture2D(shadowMap, vec2(shadowNDCPos.x, shadowNDCPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n block5 = step(shadowNDCPos.z, dot(texture2D(shadowMap, vec2(shadowNDCPos_offset_R, shadowNDCPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n block6 = step(shadowNDCPos.z, dot(texture2D(shadowMap, vec2(shadowNDCPos_offset_L, shadowNDCPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n block7 = step(shadowNDCPos.z, dot(texture2D(shadowMap, vec2(shadowNDCPos.x, shadowNDCPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n block8 = step(shadowNDCPos.z, dot(texture2D(shadowMap, vec2(shadowNDCPos_offset_R, shadowNDCPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n #else\n block0 = step(shadowNDCPos.z, texture2D(shadowMap, vec2(shadowNDCPos_offset_L, shadowNDCPos_offset_U)).x);\n block1 = step(shadowNDCPos.z, texture2D(shadowMap, vec2(shadowNDCPos.x, shadowNDCPos_offset_U)).x);\n block2 = step(shadowNDCPos.z, texture2D(shadowMap, vec2(shadowNDCPos_offset_R, shadowNDCPos_offset_U)).x);\n block3 = step(shadowNDCPos.z, texture2D(shadowMap, vec2(shadowNDCPos_offset_L, shadowNDCPos.y)).x);\n block4 = step(shadowNDCPos.z, texture2D(shadowMap, vec2(shadowNDCPos.x, shadowNDCPos.y)).x);\n block5 = step(shadowNDCPos.z, texture2D(shadowMap, vec2(shadowNDCPos_offset_R, shadowNDCPos.y)).x);\n block6 = step(shadowNDCPos.z, texture2D(shadowMap, vec2(shadowNDCPos_offset_L, shadowNDCPos_offset_D)).x);\n block7 = step(shadowNDCPos.z, texture2D(shadowMap, vec2(shadowNDCPos.x, shadowNDCPos_offset_D)).x);\n block8 = step(shadowNDCPos.z, texture2D(shadowMap, vec2(shadowNDCPos_offset_R, shadowNDCPos_offset_D)).x);\n #endif\n float coefX = mod(shadowNDCPos.x, oneTap.x) * shadowMapResolution.x;\n float coefY = mod(shadowNDCPos.y, oneTap.y) * shadowMapResolution.y;\n float shadow = 0.0;\n float resultX = mix(block0, block1, coefX);\n float resultY = mix(block3, block4, coefX);\n shadow += mix(resultX , resultY, coefY);\n resultX = mix(block1, block2, coefX);\n resultY = mix(block4, block5, coefX);\n shadow += mix(resultX , resultY, coefY);\n resultX = mix(block3, block4, coefX);\n resultY = mix(block6, block7, coefX);\n shadow += mix(resultX, resultY, coefY);\n resultX = mix(block4, block5, coefX);\n resultY = mix(block7, block8, coefX);\n shadow += mix(resultX, resultY, coefY);\n return shadow * 0.25;\n }\n bool GetShadowNDCPos(out vec3 shadowNDCPos, vec4 shadowPosWithDepthBias)\n {\n \tshadowNDCPos = shadowPosWithDepthBias.xyz / shadowPosWithDepthBias.w * 0.5 + 0.5;\n \tif (shadowNDCPos.x < 0.0 || shadowNDCPos.x > 1.0 ||\n \t\tshadowNDCPos.y < 0.0 || shadowNDCPos.y > 1.0 ||\n \t\tshadowNDCPos.z < 0.0 || shadowNDCPos.z > 1.0) {\n \t\treturn false;\n \t}\n \tshadowNDCPos.xy = cc_cameraPos.w == 1.0 ? vec2(shadowNDCPos.xy.x, 1.0 - shadowNDCPos.xy.y) : shadowNDCPos.xy;\n \treturn true;\n }\n vec4 ApplyShadowDepthBias_FaceNormal(vec4 shadowPos, vec3 worldNormal, float normalBias, vec3 matViewDir0, vec3 matViewDir1, vec3 matViewDir2, vec2 projScaleXY)\n {\n vec4 newShadowPos = shadowPos;\n if (normalBias > EPSILON_LOWP)\n {\n vec3 viewNormal = vec3(dot(matViewDir0, worldNormal), dot(matViewDir1, worldNormal), dot(matViewDir2, worldNormal));\n if (viewNormal.z < 0.1)\n newShadowPos.xy += viewNormal.xy * projScaleXY * normalBias * clamp(viewNormal.z, 0.001, 0.1);\n }\n return newShadowPos;\n }\n vec4 ApplyShadowDepthBias_FaceNormal(vec4 shadowPos, vec3 worldNormal, float normalBias, mat4 matLightView, vec2 projScaleXY)\n {\n \tvec4 newShadowPos = shadowPos;\n \tif (normalBias > EPSILON_LOWP)\n \t{\n \t\tvec4 viewNormal = matLightView * vec4(worldNormal, 0.0);\n \t\tif (viewNormal.z < 0.1)\n \t\t\tnewShadowPos.xy += viewNormal.xy * projScaleXY * normalBias * clamp(viewNormal.z, 0.001, 0.1);\n \t}\n \treturn newShadowPos;\n }\n vec4 ApplyShadowDepthBias_Perspective(vec4 shadowPos, float viewspaceDepthBias)\n {\n \tvec3 viewSpacePos;\n \tviewSpacePos.xy = shadowPos.xy * cc_shadowProjInfo.zw;\n \tviewSpacePos.z = shadowPos.z * cc_shadowInvProjDepthInfo.x + shadowPos.w * cc_shadowInvProjDepthInfo.y;\n \tviewSpacePos.xyz += cc_shadowProjDepthInfo.z * normalize(viewSpacePos.xyz) * viewspaceDepthBias;\n \tvec4 clipSpacePos;\n \tclipSpacePos.xy = viewSpacePos.xy * cc_shadowProjInfo.xy;\n \tclipSpacePos.zw = viewSpacePos.z * cc_shadowProjDepthInfo.xz + vec2(cc_shadowProjDepthInfo.y, 0.0);\n \t#if CC_SHADOWMAP_USE_LINEAR_DEPTH\n \t\tclipSpacePos.z = GetLinearDepthFromViewSpace(viewSpacePos.xyz, cc_shadowNFLSInfo.x, cc_shadowNFLSInfo.y);\n \t\tclipSpacePos.z = (clipSpacePos.z * 2.0 - 1.0) * clipSpacePos.w;\n \t#endif\n \treturn clipSpacePos;\n }\n vec4 ApplyShadowDepthBias_Orthographic(vec4 shadowPos, float viewspaceDepthBias, float projScaleZ, float projBiasZ)\n {\n \tfloat coeffA = projScaleZ;\n \tfloat coeffB = projBiasZ;\n \tfloat viewSpacePos_z = (shadowPos.z - coeffB) / coeffA;\n \tviewSpacePos_z += viewspaceDepthBias;\n \tvec4 result = shadowPos;\n \tresult.z = viewSpacePos_z * coeffA + coeffB;\n \treturn result;\n }\n vec4 ApplyShadowDepthBias_PerspectiveLinearDepth(vec4 shadowPos, float viewspaceDepthBias, vec3 worldPos)\n {\n shadowPos.z = CCGetLinearDepth(worldPos, viewspaceDepthBias) * 2.0 - 1.0;\n shadowPos.z *= shadowPos.w;\n return shadowPos;\n }\n float CCGetDirLightShadowFactorHard (vec4 shadowPosWithDepthBias) {\n\t vec3 shadowNDCPos;\n\t if (!GetShadowNDCPos(shadowNDCPos, shadowPosWithDepthBias)) {\n\t\t return 1.0;\n\t }\n return NativePCFShadowFactorHard(shadowNDCPos, cc_shadowMap, cc_shadowWHPBInfo.xy);\n }\n float CCGetDirLightShadowFactorSoft (vec4 shadowPosWithDepthBias) {\n\t vec3 shadowNDCPos;\n\t if (!GetShadowNDCPos(shadowNDCPos, shadowPosWithDepthBias)) {\n\t\t return 1.0;\n\t }\n return NativePCFShadowFactorSoft(shadowNDCPos, cc_shadowMap, cc_shadowWHPBInfo.xy);\n }\n float CCGetDirLightShadowFactorSoft3X (vec4 shadowPosWithDepthBias) {\n\t vec3 shadowNDCPos;\n\t if (!GetShadowNDCPos(shadowNDCPos, shadowPosWithDepthBias)) {\n\t\t return 1.0;\n\t }\n return NativePCFShadowFactorSoft3X(shadowNDCPos, cc_shadowMap, cc_shadowWHPBInfo.xy);\n }\n float CCGetSpotLightShadowFactorHard (vec4 shadowPosWithDepthBias, vec3 worldPos) {\n\t vec3 shadowNDCPos;\n\t if (!GetShadowNDCPos(shadowNDCPos, shadowPosWithDepthBias)) {\n\t\t return 1.0;\n\t }\n return NativePCFShadowFactorHard(shadowNDCPos, cc_spotShadowMap, cc_shadowWHPBInfo.xy);\n }\n float CCGetSpotLightShadowFactorSoft (vec4 shadowPosWithDepthBias, vec3 worldPos) {\n\t vec3 shadowNDCPos;\n\t if (!GetShadowNDCPos(shadowNDCPos, shadowPosWithDepthBias)) {\n\t\t return 1.0;\n\t }\n return NativePCFShadowFactorSoft(shadowNDCPos, cc_spotShadowMap, cc_shadowWHPBInfo.xy);\n }\n float CCGetSpotLightShadowFactorSoft3X (vec4 shadowPosWithDepthBias, vec3 worldPos) {\n\t vec3 shadowNDCPos;\n\t if (!GetShadowNDCPos(shadowNDCPos, shadowPosWithDepthBias)) {\n\t\t return 1.0;\n\t }\n return NativePCFShadowFactorSoft3X(shadowNDCPos, cc_spotShadowMap, cc_shadowWHPBInfo.xy);\n }\n float CCSpotShadowFactorBase(vec4 shadowPos, vec3 worldPos, vec2 shadowBias)\n {\n float pcf = cc_shadowWHPBInfo.z;\n vec4 pos = vec4(1.0);\n #if CC_SHADOWMAP_USE_LINEAR_DEPTH\n pos = ApplyShadowDepthBias_PerspectiveLinearDepth(shadowPos, shadowBias.x, worldPos);\n #else\n pos = ApplyShadowDepthBias_Perspective(shadowPos, shadowBias.x);\n #endif\n if (pcf > 1.9) {\n return CCGetSpotLightShadowFactorSoft3X(pos, worldPos);\n }else if (pcf > 0.9) {\n return CCGetSpotLightShadowFactorSoft(pos, worldPos);\n }else {\n return CCGetSpotLightShadowFactorHard(pos, worldPos);\n }\n }\n float CCShadowFactorBase(vec4 shadowPos, vec3 N, vec2 shadowBias)\n {\n float realtimeShadow = 1.0;\n vec4 pos = ApplyShadowDepthBias_FaceNormal(shadowPos, N, shadowBias.y, cc_matLightView, cc_shadowProjInfo.xy);\n pos = ApplyShadowDepthBias_Orthographic(pos, shadowBias.x, cc_shadowProjDepthInfo.x, cc_shadowProjDepthInfo.y);\n float pcf = cc_shadowWHPBInfo.z;\n if (pcf > 1.9) {\n realtimeShadow = CCGetDirLightShadowFactorSoft3X(pos);\n }else if (pcf > 0.9) {\n realtimeShadow = CCGetDirLightShadowFactorSoft(pos);\n }else {\n realtimeShadow = CCGetDirLightShadowFactorHard(pos);\n }\n return mix(realtimeShadow, 1.0, cc_shadowNFLSInfo.w);\n }\n #if CC_SUPPORT_CASCADED_SHADOW_MAP\n int CCGetCSMLevel(out vec4 csmPos, out vec4 shadowProjDepthInfo, out vec4 shadowProjInfo, out vec3 shadowViewDir0, out vec3 shadowViewDir1, out vec3 shadowViewDir2, vec3 worldPos) {\n int layer = -1;\n highp float layerThreshold = cc_csmViewDir0[0].w;\n for (int i = 0; i < 4; i++) {\n vec4 shadowPos = cc_matCSMViewProj[i] * vec4(worldPos.xyz, 1.0);\n vec3 clipPos = shadowPos.xyz / shadowPos.w * 0.5 + 0.5;\n if (clipPos.x >= (0.0 + layerThreshold) && clipPos.x <= (1.0 - layerThreshold) &&\n clipPos.y >= (0.0 + layerThreshold) && clipPos.y <= (1.0 - layerThreshold) &&\n clipPos.z >= 0.0 && clipPos.z <= 1.0 && layer < 0) {\n csmPos = cc_matCSMViewProj[i] * vec4(worldPos.xyz, 1.0);\n csmPos.xy = csmPos.xy * cc_csmAtlas[i].xy + cc_csmAtlas[i].zw;\n shadowProjDepthInfo = cc_csmProjDepthInfo[i];\n shadowProjInfo = cc_csmProjInfo[i];\n shadowViewDir0 = cc_csmViewDir0[i].xyz;\n shadowViewDir1 = cc_csmViewDir1[i].xyz;\n shadowViewDir2 = cc_csmViewDir2[i].xyz;\n layer = i;\n }\n }\n return layer;\n }\n float CCCSMFactorBase(vec3 worldPos, vec3 N, vec2 shadowBias)\n {\n vec4 csmPos = vec4(1.0);\n vec4 shadowProjDepthInfo, shadowProjInfo;\n vec3 shadowViewDir0, shadowViewDir1, shadowViewDir2;\n int level = CCGetCSMLevel(csmPos, shadowProjDepthInfo, shadowProjInfo, shadowViewDir0, shadowViewDir1, shadowViewDir2, worldPos);\n if (level < 0) { return 1.0; }\n float realtimeShadow = 1.0;\n vec4 pos = ApplyShadowDepthBias_FaceNormal(csmPos, N, shadowBias.y, shadowViewDir0, shadowViewDir1, shadowViewDir2, shadowProjInfo.xy);\n pos = ApplyShadowDepthBias_Orthographic(pos, shadowBias.x, shadowProjDepthInfo.x, shadowProjDepthInfo.y);\n float pcf = cc_shadowWHPBInfo.z;\n if (pcf > 1.9) {\n realtimeShadow = CCGetDirLightShadowFactorSoft3X(pos);\n } else if (pcf > 0.9) {\n realtimeShadow = CCGetDirLightShadowFactorSoft(pos);\n }else {\n realtimeShadow = CCGetDirLightShadowFactorHard(pos);\n }\n return mix(realtimeShadow, 1.0, cc_shadowNFLSInfo.w);\n }\n #else\n int CCGetCSMLevel(out vec4 csmPos, out vec4 shadowProjDepthInfo, out vec4 shadowProjInfo, out vec3 shadowViewDir0, out vec3 shadowViewDir1, out vec3 shadowViewDir2, vec3 worldPos) {\n return -1;\n }\n float CCCSMFactorBase(vec3 worldPos, vec3 N, vec2 shadowBias) {\n vec4 shadowPos = cc_matLightViewProj * vec4(worldPos, 1.0);\n return CCShadowFactorBase(shadowPos, N, shadowBias);\n }\n #endif\n#endif\n#if CC_USE_IBL\n uniform samplerCube cc_environment;\n vec4 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 }\n vec4 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 vec3 unpackRGBE (vec4 rgbe) {\n return rgbe.rgb * pow(1.1, rgbe.a * 255.0 - 128.0);\n }\n #if CC_USE_DIFFUSEMAP\n uniform samplerCube cc_diffuseMap;\n #endif\n#endif\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}\n#if USE_REFLECTION_DENOISE\n vec3 GetEnvReflectionWithMipFiltering(vec3 R, float roughness, float mipCount, float denoiseIntensity) {\n #if CC_USE_IBL\n \tfloat mip = roughness * (mipCount - 1.0);\n \tfloat delta = (dot(dFdx(R), dFdy(R))) * 1000.0;\n \tfloat mipBias = mix(0.0, 5.0, clamp(delta, 0.0, 1.0));\n \tvec4 biased = fragTextureLod(cc_environment, R, mip + mipBias);\n \tvec4 filtered = textureCube(cc_environment, R);\n #if CC_USE_IBL == 2\n \tbiased.rgb = unpackRGBE(biased);\n \tfiltered.rgb = unpackRGBE(filtered);\n #else\n \tbiased.rgb = SRGBToLinear(biased.rgb);\n \tfiltered.rgb = SRGBToLinear(filtered.rgb);\n #endif\n return mix(biased.rgb, filtered.rgb, denoiseIntensity);\n #else\n return vec3(0.0, 0.0, 0.0);\n #endif\n }\n#endif\nstruct StandardSurface {\n vec4 albedo;\n #if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\n vec3 position, position_fract_part;\n #else\n vec3 position;\n #endif\n vec3 normal;\n vec3 emissive;\n vec3 lightmap;\n float lightmap_test;\n float roughness;\n float metallic;\n float occlusion;\n float specularIntensity;\n #if CC_RECEIVE_SHADOW\n vec2 shadowBias;\n #endif\n};\nvec4 CCStandardShadingBase (StandardSurface s, vec4 shadowPos) {\n vec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\n vec3 specular = mix(vec3(0.08 * s.specularIntensity), s.albedo.rgb, s.metallic);\n vec3 position;\n #if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\n position = unpackHighpData(s.position, s.position_fract_part);\n #else\n position = s.position;\n #endif\n vec3 N = normalize(s.normal);\n vec3 V = normalize(cc_cameraPos.xyz - position);\n vec3 L = normalize(-cc_mainLitDir.xyz);\n float NL = max(dot(N, L), 0.0);\n float shadow = 1.0;\n #if CC_RECEIVE_SHADOW\n if (NL > 0.0 && cc_mainLitDir.w > 0.0) {\n if (cc_shadowLPNNInfo.w > 0.0) {\n shadow = CCCSMFactorBase(position, N, s.shadowBias);\n } else {\n shadow = CCShadowFactorBase(shadowPos, N, s.shadowBias);\n }\n }\n #endif\n #if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\n vec3 finalColor = diffuse * s.lightmap.rgb * shadow;\n #else\n float NV = max(abs(dot(N, V)), 0.0);\n specular = BRDFApprox(specular, s.roughness, NV);\n vec3 H = normalize(L + V);\n float NH = max(dot(N, H), 0.0);\n vec3 finalColor = NL * cc_mainLitColor.rgb * cc_mainLitColor.w;\n vec3 diffuseContrib = diffuse / PI;\n vec3 specularContrib = specular * CalcSpecular(s.roughness, NH, H, N);\n vec3 dirlightContrib = (diffuseContrib + specularContrib);\n dirlightContrib *= shadow;\n finalColor *= dirlightContrib;\n #endif\n float fAmb = 0.5 - N.y * 0.5;\n vec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb);\n #if CC_USE_IBL\n #if CC_USE_DIFFUSEMAP\n vec4 diffuseMap = textureCube(cc_diffuseMap, N);\n #if CC_USE_DIFFUSEMAP == 2\n ambDiff = unpackRGBE(diffuseMap);\n #else\n ambDiff = SRGBToLinear(diffuseMap.rgb);\n #endif\n #endif\n vec3 R = normalize(reflect(-V, N));\n #if USE_REFLECTION_DENOISE && !CC_IBL_CONVOLUTED\n vec3 env = GetEnvReflectionWithMipFiltering(R, s.roughness, cc_ambientGround.w, 0.6);\n #else\n vec4 envmap = fragTextureLod(cc_environment, R, s.roughness * (cc_ambientGround.w - 1.0));\n #if CC_USE_IBL == 2\n vec3 env = unpackRGBE(envmap);\n #else\n vec3 env = SRGBToLinear(envmap.rgb);\n #endif\n #endif\n finalColor += env * cc_ambientSky.w * specular * s.occlusion;\n #endif\n finalColor += ambDiff.rgb * cc_ambientSky.w * diffuse * s.occlusion;\n finalColor += s.emissive;\n return vec4(finalColor, s.albedo.a);\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 = ACESToneMap(color.rgb);\n #endif\n color.rgb = LinearToSRGB(color.rgb);\n return color;\n}\nvarying highp vec4 v_shadowPos;\n#if CC_RECEIVE_SHADOW\n#endif\nbool GetMetallicAlbedoFromDiffuseSpecularWithoutColor(out float metallic, out vec3 albedo, vec3 diffuse, vec3 specular, float f0 )\n{\n\tfloat d = max(max(diffuse.x, diffuse.y), diffuse.z);\n\tvec3 normalizedColor = diffuse / (d + (d < EPSILON_LOWP ? EPSILON_LOWP : 0.0));\n\tnormalizedColor = d < EPSILON_LOWP ? specular : normalizedColor;\n\tfloat s = max(max(specular.x, specular.y), specular.z);\n\tfloat delta = (d + s) * (d + s) - 4.0 * f0 * d;\n\tfloat deltaSqrt = sqrt(max(0.0, delta));\n\tfloat solverMetallic = (-d - s + 2.0 * f0 + deltaSqrt) / (2.0 * f0);\n\tvec3 solverAlbedo = (d + s) * normalizedColor - vec3(f0 * (1.0 - solverMetallic));\n\tbool isValidSolver = delta >= 0.0;\n\tmetallic = isValidSolver ? clamp(solverMetallic, 0.0, 1.0) : 0.0;\n\talbedo = isValidSolver ? vec3(max(0.0, solverAlbedo.x), max(0.0, solverAlbedo.y), max(0.0, solverAlbedo.z)) : diffuse;\n\treturn isValidSolver;\n}\n#if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\n varying vec3 v_luv;\n uniform sampler2D cc_lightingMap;\n#endif\nvarying vec3 v_position;\nvarying vec2 v_uv;\nvarying vec2 v_uv1;\nvarying vec3 v_normal;\n#if CC_RECEIVE_SHADOW\n varying mediump vec2 v_shadowBias;\n#endif\n#define DCC_APP_OTHERS 0\n#define DCC_APP_AUTODESK 1\n#define DCC_APP_BLENDER 2\n#define DCC_APP_CINEMA4D 3\n#define DCC_APP_GLTF 4\n#if USE_SHININESS_MAP\n uniform sampler2D shininessExponentMap;\n#endif\n#if USE_SPECULAR_GLOSSINESS_MAP\n uniform sampler2D specularGlossinessMap;\n#endif\n#if USE_SPECULAR_MAP\n uniform sampler2D specularMap;\n#endif\n #if USE_METALLIC_MAP\n uniform sampler2D metallicMap;\n#endif\n#if USE_VERTEX_COLOR\n varying vec4 v_color;\n#endif\n#if USE_ALBEDO_MAP\n uniform sampler2D albedoMap;\n#endif\n#if USE_TRANSPARENCY_MAP\n uniform sampler2D transparencyMap;\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_EMISSIVE_MAP\n uniform sampler2D emissiveMap;\n#endif\nfloat discolor(vec3 srcColor) {\n return dot(GRAY_VECTOR, srcColor);\n}\nfloat convertShininessExponent(float shininessExp)\n{\n #if DCC_APP_NAME == DCC_APP_BLENDER\n float glossiness = clamp(sqrt(shininessExp) * 0.1, 0.0, 0.95);\n #elif DCC_APP_NAME == DCC_APP_AUTODESK\n float l2 = clamp(log(shininessExp + EPSILON) * 0.1442695 , 0.0, 1.0);\n float glossiness = pow(l2, 0.5);\n #else\n float glossiness = clamp(log(shininessExp + EPSILON) * 0.1442695 , 0.0, 1.0);\n #endif\n return glossiness;\n}\nfloat getSpecularIntensityFromRoughness(float roughness)\n{\n #if DCC_APP_NAME == DCC_APP_BLENDER\n float specularIntensityMultiplier = mix(1.0, 5.0, roughness);\n #elif DCC_APP_NAME == DCC_APP_CINEMA4D\n float specularIntensityMultiplier = mix(1.0, 50.0, roughness);\n #elif DCC_APP_NAME == DCC_APP_AUTODESK\n float specularIntensityMultiplier = mix(1.0, 20.0, roughness);\n #else\n float specularIntensityMultiplier = 1.0;\n #endif\n return specularIntensityMultiplier;\n}\nvec4 getSpecularColorAndFactor()\n{\n vec3 inSpecular = specularColor.rgb;\n #if USE_SPECULAR_GLOSSINESS_MAP\n inSpecular = SRGBToLinear(texture2D(specularGlossinessMap, TEXTURE_UV).rgb);\n #endif\n #if USE_SPECULAR_MAP\n vec4 specularTex = texture2D(specularMap, TEXTURE_UV);\n specularTex.rgb = SRGBToLinear(specularTex.rgb);\n inSpecular = specularTex.rgb;\n #endif\n return vec4(inSpecular, specularFactor);\n}\nvoid surf (out StandardSurface s) {\n vec4 baseColor = vec4(1.0);\n #if USE_VERTEX_COLOR\n baseColor.rgb *= SRGBToLinear(v_color.rgb);\n baseColor.a *= v_color.a;\n #endif\n #if USE_ALBEDO_MAP\n vec4 texColor = texture2D(albedoMap, TEXTURE_UV);\n texColor.rgb = SRGBToLinear(texColor.rgb);\n texColor.a *= transparencyFactor;\n baseColor *= texColor;\n #else\n baseColor *= diffuseColor;\n #endif\n baseColor.rgb *= diffuseFactor;\n #if USE_TRANSPARENCY_MAP\n baseColor.a = texture2D(transparencyMap, TEXTURE_UV).a;\n #endif\n #if USE_ALPHA_TEST\n if (baseColor.a < alphaThreshold) discard;\n #endif\n #if CC_RECEIVE_SHADOW\n s.shadowBias = v_shadowBias;\n #endif\n vec4 specularColorAndFactor = getSpecularColorAndFactor();\n float inGlossiness = 0.0, inSpecularIntensity = specularColorAndFactor.w;\n #if HAS_EXPORTED_GLOSSINESS\n #if USE_SPECULAR_GLOSSINESS_MAP\n inGlossiness = 1.0 - texture2D(specularGlossinessMap, TEXTURE_UV).a;\n #else\n inGlossiness = glossiness;\n #endif\n #else\n #if USE_SHININESS_MAP\n #if USE_SHININESS_MAP_CHANNEL\n inGlossiness = 1.0 - texture2D(shininessExponentMap, TEXTURE_UV).SHININESS_MAP_CHANNEL;\n #else\n inGlossiness = 1.0 - discolor(texture2D(shininessExponentMap, TEXTURE_UV).rgb);\n #endif\n #else\n inGlossiness = convertShininessExponent(shininessExponent);\n #endif\n inSpecularIntensity *= getSpecularIntensityFromRoughness(1.0 - inGlossiness);\n #endif\n float inMetallic = 0.0;\n vec4 albedo = baseColor;\n #if HAS_EXPORTED_METALLIC\n inMetallic = metallic;\n float spec = specularFactor;\n #if USE_SPECULAR_MAP\n spec = dot(GRAY_VECTOR, texture2D(specularMap, TEXTURE_UV).rgb);\n #endif\n inSpecularIntensity *= spec * 0.5;\n #else\n GetMetallicAlbedoFromDiffuseSpecularWithoutColor(inMetallic, albedo.rgb, baseColor.rgb, specularColorAndFactor.rgb, 0.04);\n inSpecularIntensity *= inMetallic;\n #endif\n s.normal = v_normal;\n #if USE_NORMAL_MAP\n vec3 nmmp = texture2D(normalMap, TEXTURE_UV).xyz - vec3(0.5);\n s.normal =\n (nmmp.x * normalScale) * normalize(v_tangent) +\n (nmmp.y * normalScale) * normalize(v_bitangent) +\n nmmp.z * normalize(s.normal);\n #endif\n #if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\n packHighpData(s.position, s.position_fract_part, v_position);\n #else\n s.position = v_position;\n #endif\n s.albedo = albedo;\n s.occlusion = 1.0;\n s.roughness = 1.0 - inGlossiness;\n s.metallic = inMetallic;\n s.specularIntensity = inSpecularIntensity * 0.5;\n s.emissive = vec3(0.0);\n#if USE_EMISSIVE_MAP\n s.emissive = texture2D(emissiveMap, TEXTURE_UV).xyz;\n#endif\n #if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\n vec4 lightColor = texture2D(cc_lightingMap, v_luv.xy);\n s.lightmap = lightColor.xyz * v_luv.z;\n s.lightmap_test = v_luv.z;\n #endif\n}\n#if CC_FORWARD_ADD\n #if CC_PIPELINE_TYPE == 0\n #define LIGHTS_PER_PASS 1\n #else\n #define LIGHTS_PER_PASS 10\n #endif\n #if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 0\n uniform highp vec4 cc_lightPos[LIGHTS_PER_PASS];\n uniform vec4 cc_lightColor[LIGHTS_PER_PASS];\n uniform vec4 cc_lightSizeRangeAngle[LIGHTS_PER_PASS];\n uniform vec4 cc_lightDir[LIGHTS_PER_PASS];\n #endif\n float 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 }\n float 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 }\n float 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 #if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 0\n vec4 CCStandardShadingAdditive (StandardSurface s, vec4 shadowPos) {\n vec3 position;\n #if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\n position = unpackHighpData(s.position, s.position_fract_part);\n #else\n position = s.position;\n #endif\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 / PI;\n vec3 N = normalize(s.normal);\n vec3 V = normalize(cc_cameraPos.xyz - position);\n float NV = max(abs(dot(N, V)), 0.0);\n specular = BRDFApprox(specular, s.roughness, NV);\n vec3 finalColor = vec3(0.0);\n int numLights = CC_PIPELINE_TYPE == 0 ? LIGHTS_PER_PASS : int(cc_lightDir[0].w);\n for (int i = 0; i < LIGHTS_PER_PASS; i++) {\n if (i >= numLights) break;\n vec3 SLU = cc_lightPos[i].xyz - position;\n vec3 SL = normalize(SLU);\n vec3 SH = normalize(SL + V);\n float SNL = max(dot(N, SL), 0.0);\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 = 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_lightPos[i].w > 0.0) {\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 }\n vec3 lightColor = cc_lightColor[i].rgb;\n float shadow = 1.0;\n #if CC_RECEIVE_SHADOW\n if (cc_lightPos[i].w > 0.0 && cc_lightSizeRangeAngle[i].w > 0.0) {\n shadow = CCSpotShadowFactorBase(shadowPos, position, s.shadowBias);\n }\n #endif\n lightColor *= shadow;\n finalColor += SNL * lightColor * cc_lightColor[i].w * illum * att * (diffuseContrib + lspec);\n }\n return vec4(finalColor, 0.0);\n }\n #endif\n #if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 1\n readonly buffer b_ccLightsBuffer { vec4 b_ccLights[]; };\n readonly buffer b_clusterLightIndicesBuffer { uint b_clusterLightIndices[]; };\n readonly buffer b_clusterLightGridBuffer { uvec4 b_clusterLightGrid[]; };\n struct CCLight\n {\n vec4 cc_lightPos;\n vec4 cc_lightColor;\n vec4 cc_lightSizeRangeAngle;\n vec4 cc_lightDir;\n };\n struct Cluster\n {\n vec3 minBounds;\n vec3 maxBounds;\n };\n struct LightGrid\n {\n uint offset;\n uint ccLights;\n };\n CCLight getCCLight(uint i)\n {\n CCLight light;\n light.cc_lightPos = b_ccLights[4u * i + 0u];\n light.cc_lightColor = b_ccLights[4u * i + 1u];\n light.cc_lightSizeRangeAngle = b_ccLights[4u * i + 2u];\n light.cc_lightDir = b_ccLights[4u * i + 3u];\n return light;\n }\n LightGrid getLightGrid(uint cluster)\n {\n uvec4 gridvec = b_clusterLightGrid[cluster];\n LightGrid grid;\n grid.offset = gridvec.x;\n grid.ccLights = gridvec.y;\n return grid;\n }\n uint getGridLightIndex(uint start, uint offset)\n {\n return b_clusterLightIndices[start + offset];\n }\n uint getClusterZIndex(vec4 worldPos)\n {\n float scale = float(24) / log(cc_nearFar.y / cc_nearFar.x);\n float bias = -(float(24) * log(cc_nearFar.x) / log(cc_nearFar.y / cc_nearFar.x));\n float eyeDepth = -(cc_matView * worldPos).z;\n uint zIndex = uint(max(log(eyeDepth) * scale + bias, 0.0));\n return zIndex;\n }\n uint getClusterIndex(vec4 fragCoord, vec4 worldPos)\n {\n uint zIndex = getClusterZIndex(worldPos);\n float clusterSizeX = ceil(cc_viewPort.z / float(16));\n float clusterSizeY = ceil(cc_viewPort.w / float(8));\n uvec3 indices = uvec3(uvec2(fragCoord.xy / vec2(clusterSizeX, clusterSizeY)), zIndex);\n uint cluster = (16u * 8u) * indices.z + 16u * indices.y + indices.x;\n return cluster;\n }\n vec4 CCClusterShadingAdditive (StandardSurface s, vec4 shadowPos) {\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 / PI;\n vec3 position;\n #if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\n position = unpackHighpData(s.position, s.position_fract_part);\n #else\n position = s.position;\n #endif\n vec3 N = normalize(s.normal);\n vec3 V = normalize(cc_cameraPos.xyz - 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 uint cluster = getClusterIndex(gl_FragCoord, vec4(position, 1.0));\n LightGrid grid = getLightGrid(cluster);\n uint numLights = grid.ccLights;\n for (uint i = 0u; i < 100u; i++) {\n if (i >= numLights) break;\n uint lightIndex = getGridLightIndex(grid.offset, i);\n CCLight light = getCCLight(lightIndex);\n vec3 SLU = light.cc_lightPos.xyz - 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 = light.cc_lightSizeRangeAngle.x;\n float litRadiusSqr = litRadius * litRadius;\n float illum = PI * (litRadiusSqr / max(litRadiusSqr , distSqr));\n float attRadiusSqrInv = 1.0 / max(light.cc_lightSizeRangeAngle.y, 0.01);\n attRadiusSqrInv *= attRadiusSqrInv;\n float att = GetDistAtt(distSqr, attRadiusSqrInv);\n vec3 lspec = specular * CalcSpecular(s.roughness, SNH, SH, N);\n if (light.cc_lightPos.w > 0.0) {\n float cosInner = max(dot(-light.cc_lightDir.xyz, SL), 0.01);\n float cosOuter = light.cc_lightSizeRangeAngle.z;\n float litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\n float litAngleOffset = -cosOuter * litAngleScale;\n att *= GetAngleAtt(SL, -light.cc_lightDir.xyz, litAngleScale, litAngleOffset);\n }\n vec3 lightColor = light.cc_lightColor.rgb;\n float shadow = 1.0;\n #if CC_RECEIVE_SHADOW\n if (light.cc_lightPos.w > 0.0) {\n shadow = CCSpotShadowFactorBase(shadowPos, position, s.shadowBias);\n }\n #endif\n lightColor *= shadow;\n finalColor += SNL * lightColor * light.cc_lightColor.w * illum * att * (diffuseContrib + lspec);\n }\n return vec4(finalColor, 0.0);\n }\n #endif\n void main () {\n StandardSurface s; surf(s);\n #if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 1\n vec4 color = CCClusterShadingAdditive(s, v_shadowPos);\n #else\n vec4 color = CCStandardShadingAdditive(s, v_shadowPos);\n #endif\n gl_FragData[0] = CCFragOutput(color);\n }\n#elif (CC_PIPELINE_TYPE == 0 || CC_FORCE_FORWARD_SHADING)\n void main () {\n StandardSurface s; surf(s);\n vec4 color = CCStandardShadingBase(s, v_shadowPos);\n CC_APPLY_FOG(color, s.position.xyz);\n gl_FragData[0] = CCFragOutput(color);\n }\n#elif CC_PIPELINE_TYPE == 1\n vec2 signNotZero(vec2 v) {\n return vec2((v.x >= 0.0) ? +1.0 : -1.0, (v.y >= 0.0) ? +1.0 : -1.0);\n }\n vec2 float32x3_to_oct(in vec3 v) {\n vec2 p = v.xy * (1.0 / (abs(v.x) + abs(v.y) + abs(v.z)));\n return (v.z <= 0.0) ? ((1.0 - abs(p.yx)) * signNotZero(p)) : p;\n }\n void main () {\n StandardSurface s; surf(s);\n gl_FragData[0] = s.albedo;\n gl_FragData[1] = vec4(float32x3_to_oct(s.normal), s.roughness, s.metallic);\n gl_FragData[2] = vec4(s.emissive, s.occlusion);\n }\n#endif"
|
|
},
|
|
"builtins": {
|
|
"globals": {
|
|
"blocks": [
|
|
{
|
|
"name": "CCGlobal",
|
|
"defines": []
|
|
},
|
|
{
|
|
"name": "CCCamera",
|
|
"defines": []
|
|
},
|
|
{
|
|
"name": "CCShadow",
|
|
"defines": []
|
|
},
|
|
{
|
|
"name": "CCCSM",
|
|
"defines": [
|
|
"CC_SUPPORT_CASCADED_SHADOW_MAP"
|
|
]
|
|
}
|
|
],
|
|
"samplerTextures": [
|
|
{
|
|
"name": "cc_shadowMap",
|
|
"defines": [
|
|
"CC_RECEIVE_SHADOW"
|
|
]
|
|
},
|
|
{
|
|
"name": "cc_spotShadowMap",
|
|
"defines": [
|
|
"CC_RECEIVE_SHADOW"
|
|
]
|
|
},
|
|
{
|
|
"name": "cc_environment",
|
|
"defines": [
|
|
"CC_USE_IBL"
|
|
]
|
|
},
|
|
{
|
|
"name": "cc_diffuseMap",
|
|
"defines": [
|
|
"CC_USE_DIFFUSEMAP"
|
|
]
|
|
}
|
|
],
|
|
"buffers": [],
|
|
"images": []
|
|
},
|
|
"locals": {
|
|
"blocks": [
|
|
{
|
|
"name": "CCMorph",
|
|
"defines": [
|
|
"CC_USE_MORPH"
|
|
]
|
|
},
|
|
{
|
|
"name": "CCSkinningTexture",
|
|
"defines": [
|
|
"CC_USE_SKINNING",
|
|
"CC_USE_BAKED_ANIMATION"
|
|
]
|
|
},
|
|
{
|
|
"name": "CCSkinningAnimation",
|
|
"defines": [
|
|
"CC_USE_SKINNING",
|
|
"CC_USE_BAKED_ANIMATION"
|
|
]
|
|
},
|
|
{
|
|
"name": "CCSkinning",
|
|
"defines": [
|
|
"CC_USE_SKINNING",
|
|
"!CC_USE_BAKED_ANIMATION",
|
|
"!CC_USE_REAL_TIME_JOINT_TEXTURE"
|
|
]
|
|
},
|
|
{
|
|
"name": "CCLocalBatched",
|
|
"defines": [
|
|
"!USE_INSTANCING",
|
|
"USE_BATCHING"
|
|
]
|
|
},
|
|
{
|
|
"name": "CCLocal",
|
|
"defines": [
|
|
"!USE_INSTANCING",
|
|
"!USE_BATCHING"
|
|
]
|
|
},
|
|
{
|
|
"name": "CCForwardLight",
|
|
"defines": [
|
|
"CC_FORWARD_ADD",
|
|
"CC_ENABLE_CLUSTERED_LIGHT_CULLING"
|
|
]
|
|
}
|
|
],
|
|
"samplerTextures": [
|
|
{
|
|
"name": "cc_PositionDisplacements",
|
|
"defines": [
|
|
"CC_USE_MORPH",
|
|
"CC_MORPH_TARGET_HAS_POSITION"
|
|
]
|
|
},
|
|
{
|
|
"name": "cc_NormalDisplacements",
|
|
"defines": [
|
|
"CC_USE_MORPH",
|
|
"CC_MORPH_TARGET_HAS_NORMAL"
|
|
]
|
|
},
|
|
{
|
|
"name": "cc_TangentDisplacements",
|
|
"defines": [
|
|
"CC_USE_MORPH",
|
|
"CC_MORPH_TARGET_HAS_TANGENT"
|
|
]
|
|
},
|
|
{
|
|
"name": "cc_jointTexture",
|
|
"defines": [
|
|
"CC_USE_SKINNING",
|
|
"CC_USE_BAKED_ANIMATION"
|
|
]
|
|
},
|
|
{
|
|
"name": "cc_realtimeJoint",
|
|
"defines": [
|
|
"CC_USE_SKINNING",
|
|
"!CC_USE_BAKED_ANIMATION",
|
|
"CC_USE_REAL_TIME_JOINT_TEXTURE"
|
|
]
|
|
},
|
|
{
|
|
"name": "cc_lightingMap",
|
|
"defines": [
|
|
"CC_USE_LIGHTMAP",
|
|
"!USE_BATCHING",
|
|
"!CC_FORWARD_ADD"
|
|
]
|
|
}
|
|
],
|
|
"buffers": [],
|
|
"images": []
|
|
},
|
|
"statistics": {
|
|
"CC_EFFECT_USED_VERTEX_UNIFORM_VECTORS": 181,
|
|
"CC_EFFECT_USED_FRAGMENT_UNIFORM_VECTORS": 113
|
|
}
|
|
},
|
|
"defines": [
|
|
{
|
|
"name": "USE_INSTANCING",
|
|
"type": "boolean",
|
|
"defines": [],
|
|
"editor": {
|
|
"elevated": true
|
|
}
|
|
},
|
|
{
|
|
"name": "USE_BATCHING",
|
|
"type": "boolean",
|
|
"defines": [
|
|
"!USE_INSTANCING"
|
|
],
|
|
"editor": {
|
|
"elevated": true
|
|
}
|
|
},
|
|
{
|
|
"name": "CC_USE_SKINNING",
|
|
"type": "boolean",
|
|
"defines": []
|
|
},
|
|
{
|
|
"name": "CC_USE_BAKED_ANIMATION",
|
|
"type": "boolean",
|
|
"defines": [
|
|
"USE_INSTANCING"
|
|
]
|
|
},
|
|
{
|
|
"name": "CC_USE_LIGHTMAP",
|
|
"type": "boolean",
|
|
"defines": []
|
|
},
|
|
{
|
|
"name": "CC_RECEIVE_SHADOW",
|
|
"type": "boolean",
|
|
"defines": []
|
|
},
|
|
{
|
|
"name": "CC_USE_MORPH",
|
|
"type": "boolean",
|
|
"defines": []
|
|
},
|
|
{
|
|
"name": "CC_MORPH_TARGET_COUNT",
|
|
"type": "number",
|
|
"defines": [
|
|
"CC_USE_MORPH"
|
|
],
|
|
"range": [
|
|
2,
|
|
8
|
|
]
|
|
},
|
|
{
|
|
"name": "CC_MORPH_TARGET_HAS_POSITION",
|
|
"type": "boolean",
|
|
"defines": [
|
|
"CC_USE_MORPH"
|
|
]
|
|
},
|
|
{
|
|
"name": "CC_MORPH_TARGET_HAS_NORMAL",
|
|
"type": "boolean",
|
|
"defines": [
|
|
"CC_USE_MORPH"
|
|
]
|
|
},
|
|
{
|
|
"name": "CC_MORPH_TARGET_HAS_TANGENT",
|
|
"type": "boolean",
|
|
"defines": [
|
|
"CC_USE_MORPH"
|
|
]
|
|
},
|
|
{
|
|
"name": "CC_MORPH_PRECOMPUTED",
|
|
"type": "boolean",
|
|
"defines": [
|
|
"CC_USE_MORPH"
|
|
]
|
|
},
|
|
{
|
|
"name": "CC_USE_REAL_TIME_JOINT_TEXTURE",
|
|
"type": "boolean",
|
|
"defines": [
|
|
"CC_USE_SKINNING",
|
|
"!CC_USE_BAKED_ANIMATION"
|
|
]
|
|
},
|
|
{
|
|
"name": "CC_USE_FOG",
|
|
"type": "number",
|
|
"defines": [],
|
|
"range": [
|
|
0,
|
|
4
|
|
]
|
|
},
|
|
{
|
|
"name": "CC_USE_ACCURATE_FOG",
|
|
"type": "boolean",
|
|
"defines": []
|
|
},
|
|
{
|
|
"name": "CC_SUPPORT_CASCADED_SHADOW_MAP",
|
|
"type": "boolean",
|
|
"defines": []
|
|
},
|
|
{
|
|
"name": "USE_VERTEX_COLOR",
|
|
"type": "boolean",
|
|
"defines": []
|
|
},
|
|
{
|
|
"name": "USE_NORMAL_MAP",
|
|
"type": "boolean",
|
|
"defines": []
|
|
},
|
|
{
|
|
"name": "HAS_SECOND_UV",
|
|
"type": "boolean",
|
|
"defines": []
|
|
},
|
|
{
|
|
"name": "CC_FORWARD_ADD",
|
|
"type": "boolean",
|
|
"defines": []
|
|
},
|
|
{
|
|
"name": "USE_TWOSIDE",
|
|
"type": "boolean",
|
|
"defines": []
|
|
},
|
|
{
|
|
"name": "CC_USE_DEBUG_VIEW",
|
|
"type": "number",
|
|
"defines": [],
|
|
"range": [
|
|
0,
|
|
3
|
|
]
|
|
},
|
|
{
|
|
"name": "CC_SHADOWMAP_FORMAT",
|
|
"type": "number",
|
|
"defines": [
|
|
"CC_RECEIVE_SHADOW"
|
|
],
|
|
"range": [
|
|
0,
|
|
3
|
|
]
|
|
},
|
|
{
|
|
"name": "CC_SHADOWMAP_USE_LINEAR_DEPTH",
|
|
"type": "boolean",
|
|
"defines": [
|
|
"CC_RECEIVE_SHADOW"
|
|
]
|
|
},
|
|
{
|
|
"name": "CC_USE_IBL",
|
|
"type": "number",
|
|
"defines": [],
|
|
"range": [
|
|
0,
|
|
2
|
|
]
|
|
},
|
|
{
|
|
"name": "CC_USE_DIFFUSEMAP",
|
|
"type": "number",
|
|
"defines": [],
|
|
"range": [
|
|
0,
|
|
2
|
|
]
|
|
},
|
|
{
|
|
"name": "USE_REFLECTION_DENOISE",
|
|
"type": "boolean",
|
|
"defines": []
|
|
},
|
|
{
|
|
"name": "CC_IBL_CONVOLUTED",
|
|
"type": "boolean",
|
|
"defines": [
|
|
"USE_REFLECTION_DENOISE",
|
|
"CC_USE_IBL"
|
|
]
|
|
},
|
|
{
|
|
"name": "CC_USE_HDR",
|
|
"type": "boolean",
|
|
"defines": []
|
|
},
|
|
{
|
|
"name": "TEXTURE_UV",
|
|
"type": "string",
|
|
"defines": [],
|
|
"options": [
|
|
"v_uv",
|
|
"v_uv1"
|
|
]
|
|
},
|
|
{
|
|
"name": "DCC_APP_NAME",
|
|
"type": "number",
|
|
"defines": [],
|
|
"range": [
|
|
0,
|
|
4
|
|
]
|
|
},
|
|
{
|
|
"name": "USE_SHININESS_MAP",
|
|
"type": "boolean",
|
|
"defines": []
|
|
},
|
|
{
|
|
"name": "SHININESS_MAP_CHANNEL",
|
|
"type": "string",
|
|
"defines": [
|
|
"USE_SHININESS_MAP"
|
|
],
|
|
"options": [
|
|
"a",
|
|
"r",
|
|
"g",
|
|
"b"
|
|
]
|
|
},
|
|
{
|
|
"name": "USE_SPECULAR_GLOSSINESS_MAP",
|
|
"type": "boolean",
|
|
"defines": []
|
|
},
|
|
{
|
|
"name": "USE_SPECULAR_MAP",
|
|
"type": "boolean",
|
|
"defines": []
|
|
},
|
|
{
|
|
"name": "USE_METALLIC_MAP",
|
|
"type": "boolean",
|
|
"defines": []
|
|
},
|
|
{
|
|
"name": "USE_ALBEDO_MAP",
|
|
"type": "boolean",
|
|
"defines": []
|
|
},
|
|
{
|
|
"name": "USE_TRANSPARENCY_MAP",
|
|
"type": "boolean",
|
|
"defines": []
|
|
},
|
|
{
|
|
"name": "USE_EMISSIVE_MAP",
|
|
"type": "boolean",
|
|
"defines": []
|
|
},
|
|
{
|
|
"name": "USE_ALPHA_TEST",
|
|
"type": "boolean",
|
|
"defines": []
|
|
},
|
|
{
|
|
"name": "HAS_EXPORTED_GLOSSINESS",
|
|
"type": "boolean",
|
|
"defines": []
|
|
},
|
|
{
|
|
"name": "USE_SHININESS_MAP_CHANNEL",
|
|
"type": "boolean",
|
|
"defines": [
|
|
"!HAS_EXPORTED_GLOSSINESS",
|
|
"USE_SHININESS_MAP"
|
|
]
|
|
},
|
|
{
|
|
"name": "HAS_EXPORTED_METALLIC",
|
|
"type": "boolean",
|
|
"defines": []
|
|
},
|
|
{
|
|
"name": "CC_PIPELINE_TYPE",
|
|
"type": "number",
|
|
"defines": [
|
|
"CC_FORWARD_ADD"
|
|
],
|
|
"range": [
|
|
0,
|
|
1
|
|
]
|
|
},
|
|
{
|
|
"name": "CC_FORCE_FORWARD_SHADING",
|
|
"type": "boolean",
|
|
"defines": [
|
|
"CC_FORWARD_ADD"
|
|
]
|
|
}
|
|
],
|
|
"name": "dcc/imported-specular-glossiness|standard-vs|standard-fs"
|
|
},
|
|
{
|
|
"blocks": [
|
|
{
|
|
"name": "Constants",
|
|
"members": [
|
|
{
|
|
"name": "tilingOffset",
|
|
"type": 16,
|
|
"count": 1
|
|
},
|
|
{
|
|
"name": "diffuseColor",
|
|
"type": 16,
|
|
"count": 1
|
|
},
|
|
{
|
|
"name": "specularColor",
|
|
"type": 16,
|
|
"count": 1
|
|
},
|
|
{
|
|
"name": "emissive",
|
|
"type": 16,
|
|
"count": 1
|
|
},
|
|
{
|
|
"name": "alphaThreshold",
|
|
"type": 13,
|
|
"count": 1
|
|
},
|
|
{
|
|
"name": "shininessExponent",
|
|
"type": 13,
|
|
"count": 1
|
|
},
|
|
{
|
|
"name": "glossiness",
|
|
"type": 13,
|
|
"count": 1
|
|
},
|
|
{
|
|
"name": "metallic",
|
|
"type": 13,
|
|
"count": 1
|
|
},
|
|
{
|
|
"name": "normalScale",
|
|
"type": 13,
|
|
"count": 1
|
|
},
|
|
{
|
|
"name": "transparencyFactor",
|
|
"type": 13,
|
|
"count": 1
|
|
},
|
|
{
|
|
"name": "diffuseFactor",
|
|
"type": 13,
|
|
"count": 1
|
|
},
|
|
{
|
|
"name": "specularFactor",
|
|
"type": 13,
|
|
"count": 1
|
|
}
|
|
],
|
|
"defines": [],
|
|
"stageFlags": 17,
|
|
"binding": 0
|
|
}
|
|
],
|
|
"samplerTextures": [
|
|
{
|
|
"name": "albedoMap",
|
|
"type": 28,
|
|
"count": 1,
|
|
"defines": [
|
|
"USE_ALBEDO_MAP"
|
|
],
|
|
"stageFlags": 16,
|
|
"binding": 1
|
|
},
|
|
{
|
|
"name": "transparencyMap",
|
|
"type": 28,
|
|
"count": 1,
|
|
"defines": [
|
|
"USE_TRANSPARENCY_MAP"
|
|
],
|
|
"stageFlags": 16,
|
|
"binding": 2
|
|
}
|
|
],
|
|
"samplers": [],
|
|
"textures": [],
|
|
"buffers": [],
|
|
"images": [],
|
|
"subpassInputs": [],
|
|
"attributes": [
|
|
{
|
|
"name": "a_position",
|
|
"defines": [],
|
|
"format": 32,
|
|
"location": 0
|
|
},
|
|
{
|
|
"name": "a_normal",
|
|
"defines": [],
|
|
"format": 32,
|
|
"location": 1
|
|
},
|
|
{
|
|
"name": "a_texCoord",
|
|
"defines": [],
|
|
"format": 21,
|
|
"location": 2
|
|
},
|
|
{
|
|
"name": "a_tangent",
|
|
"defines": [],
|
|
"format": 44,
|
|
"location": 3
|
|
},
|
|
{
|
|
"name": "a_joints",
|
|
"defines": [
|
|
"CC_USE_SKINNING"
|
|
],
|
|
"location": 4
|
|
},
|
|
{
|
|
"name": "a_weights",
|
|
"defines": [
|
|
"CC_USE_SKINNING"
|
|
],
|
|
"format": 44,
|
|
"location": 5
|
|
},
|
|
{
|
|
"name": "a_jointAnimInfo",
|
|
"defines": [
|
|
"USE_INSTANCING",
|
|
"CC_USE_BAKED_ANIMATION"
|
|
],
|
|
"format": 44,
|
|
"isInstanced": true,
|
|
"location": 6
|
|
},
|
|
{
|
|
"name": "a_matWorld0",
|
|
"defines": [
|
|
"USE_INSTANCING"
|
|
],
|
|
"format": 44,
|
|
"isInstanced": true,
|
|
"location": 7
|
|
},
|
|
{
|
|
"name": "a_matWorld1",
|
|
"defines": [
|
|
"USE_INSTANCING"
|
|
],
|
|
"format": 44,
|
|
"isInstanced": true,
|
|
"location": 8
|
|
},
|
|
{
|
|
"name": "a_matWorld2",
|
|
"defines": [
|
|
"USE_INSTANCING"
|
|
],
|
|
"format": 44,
|
|
"isInstanced": true,
|
|
"location": 9
|
|
},
|
|
{
|
|
"name": "a_lightingMapUVParam",
|
|
"defines": [
|
|
"USE_INSTANCING",
|
|
"CC_USE_LIGHTMAP"
|
|
],
|
|
"format": 44,
|
|
"isInstanced": true,
|
|
"location": 10
|
|
},
|
|
{
|
|
"name": "a_localShadowBias",
|
|
"defines": [
|
|
"USE_INSTANCING",
|
|
"CC_RECEIVE_SHADOW"
|
|
],
|
|
"format": 21,
|
|
"isInstanced": true,
|
|
"location": 11
|
|
},
|
|
{
|
|
"name": "a_dyn_batch_id",
|
|
"defines": [
|
|
"!USE_INSTANCING",
|
|
"USE_BATCHING"
|
|
],
|
|
"format": 11,
|
|
"location": 12
|
|
},
|
|
{
|
|
"name": "a_vertexId",
|
|
"defines": [
|
|
"CC_USE_MORPH"
|
|
],
|
|
"format": 11,
|
|
"location": 13
|
|
},
|
|
{
|
|
"name": "a_texCoord1",
|
|
"defines": [],
|
|
"format": 21,
|
|
"location": 14
|
|
},
|
|
{
|
|
"name": "a_color",
|
|
"defines": [
|
|
"USE_VERTEX_COLOR"
|
|
],
|
|
"format": 44,
|
|
"location": 15
|
|
}
|
|
],
|
|
"varyings": [
|
|
{
|
|
"name": "v_uv",
|
|
"type": 14,
|
|
"count": 1,
|
|
"defines": [],
|
|
"stageFlags": 17,
|
|
"location": 0
|
|
},
|
|
{
|
|
"name": "v_uv1",
|
|
"type": 14,
|
|
"count": 1,
|
|
"defines": [],
|
|
"stageFlags": 17,
|
|
"location": 1
|
|
},
|
|
{
|
|
"name": "v_worldPos",
|
|
"type": 16,
|
|
"count": 1,
|
|
"defines": [],
|
|
"stageFlags": 17,
|
|
"location": 2
|
|
},
|
|
{
|
|
"name": "v_clip_depth",
|
|
"type": 14,
|
|
"count": 1,
|
|
"defines": [],
|
|
"stageFlags": 17,
|
|
"location": 3
|
|
},
|
|
{
|
|
"name": "v_color",
|
|
"type": 16,
|
|
"count": 1,
|
|
"defines": [
|
|
"USE_VERTEX_COLOR"
|
|
],
|
|
"stageFlags": 17,
|
|
"location": 4
|
|
}
|
|
],
|
|
"fragColors": [
|
|
{
|
|
"name": "cc_FragColor",
|
|
"typename": "vec4",
|
|
"type": 16,
|
|
"count": 1,
|
|
"defines": [],
|
|
"stageFlags": 16,
|
|
"location": 0
|
|
}
|
|
],
|
|
"hash": 2706003509,
|
|
"glsl4": {
|
|
"vert": "#extension GL_EXT_shader_explicit_arithmetic_types_int32: require\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\n rgba = rgba * 255.0;\n highp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\n highp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\n highp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\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;\n#if CC_USE_SKINNING\n layout(location = 4) in u32vec4 a_joints;\n layout(location = 5) in vec4 a_weights;\n#endif\n#if USE_INSTANCING\n #if CC_USE_BAKED_ANIMATION\n layout(location = 6) in highp vec4 a_jointAnimInfo;\n #endif\n layout(location = 7) in vec4 a_matWorld0;\n layout(location = 8) in vec4 a_matWorld1;\n layout(location = 9) in vec4 a_matWorld2;\n #if CC_USE_LIGHTMAP\n layout(location = 10) in vec4 a_lightingMapUVParam;\n #endif\n #if CC_RECEIVE_SHADOW\n layout(location = 11) in vec2 a_localShadowBias;\n #endif\n#elif USE_BATCHING\n layout(location = 12) in float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\n int getVertexId() {\n return gl_VertexIndex;\n }\n#endif\n#if CC_USE_MORPH\n layout(set = 2, binding = 4) uniform CCMorph {\n vec4 cc_displacementWeights[15];\n vec4 cc_displacementTextureInfo;\n };\n #if CC_MORPH_TARGET_HAS_POSITION\n layout(set = 2, binding = 7) uniform sampler2D cc_PositionDisplacements;\n #endif\n #if CC_MORPH_TARGET_HAS_NORMAL\n layout(set = 2, binding = 8) uniform sampler2D cc_NormalDisplacements;\n #endif\n #if CC_MORPH_TARGET_HAS_TANGENT\n layout(set = 2, binding = 9) uniform sampler2D cc_TangentDisplacements;\n #endif\n vec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\n float pixelIndexF = float(pixelIndex);\n float x = mod(pixelIndexF, textureResolution.x);\n float y = floor(pixelIndexF / textureResolution.x);\n return vec2(x, y);\n }\n vec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\n return (vec2(location.x, location.y) + .5) / textureResolution;\n }\n #if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\n vec4 fetchVec3ArrayFromTexture(sampler2D tex, int pixelIndex) {\n ivec2 texSize = textureSize(tex, 0);\n return texelFetch(tex, ivec2(pixelIndex % texSize.x, pixelIndex / texSize.x), 0);\n }\n #else\n vec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\n int pixelIndex = elementIndex * 4;\n vec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\n vec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\n vec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\n vec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\n return vec4(\n decode32(texture(tex, x)),\n decode32(texture(tex, y)),\n decode32(texture(tex, z)),\n 1.0\n );\n }\n #endif\n float getDisplacementWeight(int index) {\n int quot = index / 4;\n int remainder = index - quot * 4;\n if (remainder == 0) {\n return cc_displacementWeights[quot].x;\n } else if (remainder == 1) {\n return cc_displacementWeights[quot].y;\n } else if (remainder == 2) {\n return cc_displacementWeights[quot].z;\n } else {\n return cc_displacementWeights[quot].w;\n }\n }\n vec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n #if CC_MORPH_PRECOMPUTED\n return fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n #else\n vec3 result = vec3(0, 0, 0);\n int nVertices = int(cc_displacementTextureInfo.z);\n for (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\n result += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n }\n return result;\n #endif\n }\n #if CC_MORPH_TARGET_HAS_POSITION\n vec3 getPositionDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n }\n #endif\n #if CC_MORPH_TARGET_HAS_NORMAL\n vec3 getNormalDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n }\n #endif\n #if CC_MORPH_TARGET_HAS_TANGENT\n vec3 getTangentDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n }\n #endif\n void applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\n int vertexId = getVertexId();\n #if CC_MORPH_TARGET_HAS_POSITION\n position.xyz = position.xyz + getPositionDisplacement(vertexId);\n #endif\n #if CC_MORPH_TARGET_HAS_NORMAL\n normal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n #endif\n #if CC_MORPH_TARGET_HAS_TANGENT\n tangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n #endif\n }\n void 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\n #if CC_USE_BAKED_ANIMATION\n layout(set = 2, binding = 3) uniform CCSkinningTexture {\n highp vec4 cc_jointTextureInfo;\n };\n layout(set = 2, binding = 2) uniform CCSkinningAnimation {\n highp vec4 cc_jointAnimInfo;\n };\n layout(set = 2, binding = 6) uniform highp sampler2D cc_jointTexture;\n void CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n {\n #if USE_INSTANCING\n highp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n #else\n highp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n #endif\n invSize = cc_jointTextureInfo.w;\n highp float tempY = floor(temp * invSize);\n x = floor(temp - tempY * cc_jointTextureInfo.x);\n y = (tempY + 0.5) * invSize;\n }\n #else\n #if CC_USE_REAL_TIME_JOINT_TEXTURE\n layout(set = 2, binding = 6) uniform highp sampler2D cc_realtimeJoint;\n #else\n layout(set = 2, binding = 3) uniform CCSkinning {\n highp vec4 cc_joints[CC_JOINT_UNIFORM_CAPACITY * 3];\n };\n #endif\n #endif\n #if CC_USE_BAKED_ANIMATION\n #if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\n mat4 getJointMatrix (float i) {\n highp float x, y, invSize;\n CCGetJointTextureCoords(3.0, i, x, y, 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 highp float x, y, invSize;\n CCGetJointTextureCoords(12.0, i, x, y, 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 #if CC_USE_REAL_TIME_JOINT_TEXTURE\n #if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\n mat4 getJointMatrix (float i) {\n float x = i;\n vec4 v1 = texture(cc_realtimeJoint, vec2( x / 256.0, 0.5 / 3.0));\n vec4 v2 = texture(cc_realtimeJoint, vec2( x / 256.0, 1.5 / 3.0));\n vec4 v3 = texture(cc_realtimeJoint, vec2( x / 256.0, 2.5 / 3.0));\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 float x = 4.0 * i;\n vec4 v1 = vec4(\n decode32(texture(cc_realtimeJoint, vec2((x + 0.5)/ 1024.0, 0.5 / 3.0))),\n decode32(texture(cc_realtimeJoint, vec2((x + 1.5)/ 1024.0, 0.5 / 3.0))),\n decode32(texture(cc_realtimeJoint, vec2((x + 2.5)/ 1024.0, 0.5 / 3.0))),\n decode32(texture(cc_realtimeJoint, vec2((x + 3.5)/ 1024.0, 0.5 / 3.0)))\n );\n vec4 v2 = vec4(\n decode32(texture(cc_realtimeJoint, vec2((x + 0.5)/ 1024.0, 1.5 / 3.0))),\n decode32(texture(cc_realtimeJoint, vec2((x + 1.5)/ 1024.0, 1.5 / 3.0))),\n decode32(texture(cc_realtimeJoint, vec2((x + 2.5)/ 1024.0, 1.5 / 3.0))),\n decode32(texture(cc_realtimeJoint, vec2((x + 3.5)/ 1024.0, 1.5 / 3.0)))\n );\n vec4 v3 = vec4(\n decode32(texture(cc_realtimeJoint, vec2((x + 0.5)/ 1024.0, 2.5 / 3.0))),\n decode32(texture(cc_realtimeJoint, vec2((x + 1.5)/ 1024.0, 2.5 / 3.0))),\n decode32(texture(cc_realtimeJoint, vec2((x + 2.5)/ 1024.0, 2.5 / 3.0))),\n decode32(texture(cc_realtimeJoint, vec2((x + 3.5)/ 1024.0, 2.5 / 3.0)))\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\n #endif\n mat4 skinMatrix () {\n vec4 joints = vec4(a_joints);\n return getJointMatrix(joints.x) * a_weights.x\n + getJointMatrix(joints.y) * a_weights.y\n + getJointMatrix(joints.z) * a_weights.z\n + getJointMatrix(joints.w) * a_weights.w;\n }\n void CCSkin (inout vec4 position) {\n mat4 m = skinMatrix();\n position = m * position;\n }\n void CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\n mat4 m = skinMatrix();\n position = m * position;\n normal = (m * vec4(normal, 0.0)).xyz;\n tangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n }\n#endif\nvoid CCVertInput(inout StandardVertInput In)\n{\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.position, In.normal, In.tangent);\n #endif\n #if CC_USE_SKINNING\n CCSkin(In.position, In.normal, In.tangent);\n #endif\n}\n#if !USE_INSTANCING\n #if USE_BATCHING\n layout(set = 2, binding = 0) uniform CCLocalBatched {\n highp mat4 cc_matWorlds[10];\n };\n #else\n layout(set = 2, binding = 0) uniform CCLocal {\n highp mat4 cc_matWorld;\n highp mat4 cc_matWorldIT;\n highp vec4 cc_lightingMapUVParam;\n highp vec4 cc_localShadowBias;\n };\n #endif\n#endif\nvoid CCGetWorldMatrixFull(out mat4 matWorld, out mat4 matWorldIT)\n{\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}\nlayout(set = 1, binding = 0) uniform Constants {\n vec4 tilingOffset;\n vec4 diffuseColor;\n vec4 specularColor;\n vec4 emissive;\n float alphaThreshold;\n float shininessExponent;\n float glossiness;\n float metallic;\n float normalScale;\n float transparencyFactor;\n float diffuseFactor;\n float specularFactor;\n};\nlayout(set = 0, binding = 2) uniform CCShadow {\n highp mat4 cc_matLightView;\n highp mat4 cc_matLightViewProj;\n highp vec4 cc_shadowInvProjDepthInfo;\n highp vec4 cc_shadowProjDepthInfo;\n highp vec4 cc_shadowProjInfo;\n mediump vec4 cc_shadowNFLSInfo;\n mediump vec4 cc_shadowWHPBInfo;\n mediump vec4 cc_shadowLPNNInfo;\n lowp vec4 cc_shadowColor;\n mediump vec4 cc_planarNDInfo;\n};\n#if HAS_SECOND_UV || CC_USE_LIGHTMAP\n layout(location = 14) in vec2 a_texCoord1;\n#endif\nlayout(location = 0) out vec2 v_uv;\nlayout(location = 1) out vec2 v_uv1;\nlayout(location = 2) out vec4 v_worldPos;\nlayout(location = 3) out highp vec2 v_clip_depth;\n#if USE_VERTEX_COLOR\n layout(location = 15) in vec4 a_color;\n layout(location = 4) out lowp vec4 v_color;\n#endif\nvec4 vert () {\n StandardVertInput In;\n CCVertInput(In);\n mat4 matWorld, matWorldIT;\n CCGetWorldMatrixFull(matWorld, matWorldIT);\n v_worldPos = matWorld * In.position;\n vec4 clipPos = cc_matLightViewProj * v_worldPos;\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 v_clip_depth = clipPos.zw;\n return clipPos;\n}\nvoid main() { gl_Position = vert(); }",
|
|
"frag": "\nprecision highp float;\nlayout(set = 1, binding = 0) uniform Constants {\n vec4 tilingOffset;\n vec4 diffuseColor;\n vec4 specularColor;\n vec4 emissive;\n float alphaThreshold;\n float shininessExponent;\n float glossiness;\n float metallic;\n float normalScale;\n float transparencyFactor;\n float diffuseFactor;\n float specularFactor;\n};\nvec4 packDepthToRGBA (float depth) {\n vec4 ret = vec4(1.0, 255.0, 65025.0, 16581375.0) * depth;\n ret = fract(ret);\n ret -= vec4(ret.yzw, 0.0) / 255.0;\n return ret;\n}\nlayout(set = 0, binding = 2) uniform CCShadow {\n highp mat4 cc_matLightView;\n highp mat4 cc_matLightViewProj;\n highp vec4 cc_shadowInvProjDepthInfo;\n highp vec4 cc_shadowProjDepthInfo;\n highp vec4 cc_shadowProjInfo;\n mediump vec4 cc_shadowNFLSInfo;\n mediump vec4 cc_shadowWHPBInfo;\n mediump vec4 cc_shadowLPNNInfo;\n lowp vec4 cc_shadowColor;\n mediump vec4 cc_planarNDInfo;\n};\n#if CC_SUPPORT_CASCADED_SHADOW_MAP\n layout(set = 0, binding = 3) uniform CCCSM {\n highp vec4 cc_csmViewDir0[4];\n highp vec4 cc_csmViewDir1[4];\n highp vec4 cc_csmViewDir2[4];\n highp vec4 cc_csmAtlas[4];\n highp mat4 cc_matCSMViewProj[4];\n highp vec4 cc_csmProjDepthInfo[4];\n highp vec4 cc_csmProjInfo[4];\n highp vec4 cc_csmSplitsInfo;\n };\n#endif\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nfloat GetLinearDepthFromViewSpace(vec3 viewPos, float near, float far) {\n float dist = length(viewPos);\n return (dist - near) / (far - near);\n}\nfloat CCGetLinearDepth(vec3 worldPos, float viewSpaceBias) {\n\tvec4 viewPos = cc_matLightView * vec4(worldPos.xyz, 1.0);\n viewPos.z += viewSpaceBias;\n\treturn GetLinearDepthFromViewSpace(viewPos.xyz, cc_shadowNFLSInfo.x, cc_shadowNFLSInfo.y);\n}\nfloat CCGetLinearDepth(vec3 worldPos) {\n\treturn CCGetLinearDepth(worldPos, 0.0);\n}\n#if CC_RECEIVE_SHADOW\n layout(set = 0, binding = 0) uniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_nativeSize;\n mediump vec4 cc_debug_view_mode;\n mediump vec4 cc_debug_view_composite_pack_1;\n mediump vec4 cc_debug_view_composite_pack_2;\n mediump vec4 cc_debug_view_composite_pack_3;\n };\n layout(set = 0, binding = 1) uniform CCCamera {\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_surfaceTransform;\n mediump vec4 cc_screenScale;\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 mediump vec4 cc_nearFar;\n mediump vec4 cc_viewPort;\n };\n layout(set = 0, binding = 4) uniform highp sampler2D cc_shadowMap;\n layout(set = 0, binding = 6) uniform highp sampler2D cc_spotShadowMap;\n #if CC_SUPPORT_CASCADED_SHADOW_MAP\n #else\n #endif\n#endif\nlayout(location = 0) in vec2 v_uv;\nlayout(location = 1) in vec2 v_uv1;\nlayout(location = 2) in vec4 v_worldPos;\nlayout(location = 3) in highp vec2 v_clip_depth;\n#if USE_ALBEDO_MAP\n layout(set = 1, binding = 1) uniform sampler2D albedoMap;\n#endif\n#if USE_TRANSPARENCY_MAP\n layout(set = 1, binding = 2) uniform sampler2D transparencyMap;\n#endif\n#if USE_VERTEX_COLOR\n layout(location = 4) in lowp vec4 v_color;\n#endif\nvec4 frag () {\n #if USE_ALPHA_TEST\n float alpha = diffuseColor.a;\n #if USE_VERTEX_COLOR\n alpha *= v_color.a;\n #endif\n #if USE_ALBEDO_MAP\n alpha *= texture(albedoMap, TEXTURE_UV).a * transparencyFactor;\n #endif\n #if USE_TRANSPARENCY_MAP\n alpha = texture(transparencyMap, TEXTURE_UV).a;\n #endif\n if (alpha < alphaThreshold) discard;\n #endif\n highp float clipDepth = v_clip_depth.x / v_clip_depth.y * 0.5 + 0.5;\n if(cc_shadowLPNNInfo.x > 0.000001 && cc_shadowLPNNInfo.x < 1.999999) {\n #if CC_SHADOWMAP_USE_LINEAR_DEPTH\n clipDepth = CCGetLinearDepth(v_worldPos.xyz);\n #endif\n }\n #if CC_SHADOWMAP_FORMAT == 1\n return packDepthToRGBA(clipDepth);\n #else\n return vec4(clipDepth, 1.0, 1.0, 1.0);\n #endif\n}\nlayout(location = 0) out vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }"
|
|
},
|
|
"glsl3": {
|
|
"vert": "\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\n rgba = rgba * 255.0;\n highp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\n highp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\n highp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\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;\n#if CC_USE_SKINNING\n in vec4 a_joints;\n in vec4 a_weights;\n#endif\n#if USE_INSTANCING\n #if CC_USE_BAKED_ANIMATION\n in highp vec4 a_jointAnimInfo;\n #endif\n in vec4 a_matWorld0;\n in vec4 a_matWorld1;\n in vec4 a_matWorld2;\n #if CC_USE_LIGHTMAP\n in vec4 a_lightingMapUVParam;\n #endif\n #if CC_RECEIVE_SHADOW\n in vec2 a_localShadowBias;\n #endif\n#elif USE_BATCHING\n in float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\n in float a_vertexId;\n int getVertexId() {\n return int(a_vertexId);\n }\n#endif\n#if CC_USE_MORPH\n layout(std140) uniform CCMorph {\n vec4 cc_displacementWeights[15];\n vec4 cc_displacementTextureInfo;\n };\n #if CC_MORPH_TARGET_HAS_POSITION\n uniform sampler2D cc_PositionDisplacements;\n #endif\n #if CC_MORPH_TARGET_HAS_NORMAL\n uniform sampler2D cc_NormalDisplacements;\n #endif\n #if CC_MORPH_TARGET_HAS_TANGENT\n uniform sampler2D cc_TangentDisplacements;\n #endif\n vec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\n float pixelIndexF = float(pixelIndex);\n float x = mod(pixelIndexF, textureResolution.x);\n float y = floor(pixelIndexF / textureResolution.x);\n return vec2(x, y);\n }\n vec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\n return (vec2(location.x, location.y) + .5) / textureResolution;\n }\n #if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\n vec4 fetchVec3ArrayFromTexture(sampler2D tex, int pixelIndex) {\n ivec2 texSize = textureSize(tex, 0);\n return texelFetch(tex, ivec2(pixelIndex % texSize.x, pixelIndex / texSize.x), 0);\n }\n #else\n vec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\n int pixelIndex = elementIndex * 4;\n vec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\n vec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\n vec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\n vec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\n return vec4(\n decode32(texture(tex, x)),\n decode32(texture(tex, y)),\n decode32(texture(tex, z)),\n 1.0\n );\n }\n #endif\n float getDisplacementWeight(int index) {\n int quot = index / 4;\n int remainder = index - quot * 4;\n if (remainder == 0) {\n return cc_displacementWeights[quot].x;\n } else if (remainder == 1) {\n return cc_displacementWeights[quot].y;\n } else if (remainder == 2) {\n return cc_displacementWeights[quot].z;\n } else {\n return cc_displacementWeights[quot].w;\n }\n }\n vec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n #if CC_MORPH_PRECOMPUTED\n return fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n #else\n vec3 result = vec3(0, 0, 0);\n int nVertices = int(cc_displacementTextureInfo.z);\n for (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\n result += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n }\n return result;\n #endif\n }\n #if CC_MORPH_TARGET_HAS_POSITION\n vec3 getPositionDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n }\n #endif\n #if CC_MORPH_TARGET_HAS_NORMAL\n vec3 getNormalDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n }\n #endif\n #if CC_MORPH_TARGET_HAS_TANGENT\n vec3 getTangentDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n }\n #endif\n void applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\n int vertexId = getVertexId();\n #if CC_MORPH_TARGET_HAS_POSITION\n position.xyz = position.xyz + getPositionDisplacement(vertexId);\n #endif\n #if CC_MORPH_TARGET_HAS_NORMAL\n normal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n #endif\n #if CC_MORPH_TARGET_HAS_TANGENT\n tangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n #endif\n }\n void 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\n #if CC_USE_BAKED_ANIMATION\n layout(std140) uniform CCSkinningTexture {\n highp vec4 cc_jointTextureInfo;\n };\n layout(std140) uniform CCSkinningAnimation {\n highp vec4 cc_jointAnimInfo;\n };\n uniform highp sampler2D cc_jointTexture;\n void CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n {\n #if USE_INSTANCING\n highp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n #else\n highp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n #endif\n invSize = cc_jointTextureInfo.w;\n highp float tempY = floor(temp * invSize);\n x = floor(temp - tempY * cc_jointTextureInfo.x);\n y = (tempY + 0.5) * invSize;\n }\n #else\n #if CC_USE_REAL_TIME_JOINT_TEXTURE\n uniform highp sampler2D cc_realtimeJoint;\n #else\n layout(std140) uniform CCSkinning {\n highp vec4 cc_joints[CC_JOINT_UNIFORM_CAPACITY * 3];\n };\n #endif\n #endif\n #if CC_USE_BAKED_ANIMATION\n #if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\n mat4 getJointMatrix (float i) {\n highp float x, y, invSize;\n CCGetJointTextureCoords(3.0, i, x, y, 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 highp float x, y, invSize;\n CCGetJointTextureCoords(12.0, i, x, y, 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 #if CC_USE_REAL_TIME_JOINT_TEXTURE\n #if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\n mat4 getJointMatrix (float i) {\n float x = i;\n vec4 v1 = texture(cc_realtimeJoint, vec2( x / 256.0, 0.5 / 3.0));\n vec4 v2 = texture(cc_realtimeJoint, vec2( x / 256.0, 1.5 / 3.0));\n vec4 v3 = texture(cc_realtimeJoint, vec2( x / 256.0, 2.5 / 3.0));\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 float x = 4.0 * i;\n vec4 v1 = vec4(\n decode32(texture(cc_realtimeJoint, vec2((x + 0.5)/ 1024.0, 0.5 / 3.0))),\n decode32(texture(cc_realtimeJoint, vec2((x + 1.5)/ 1024.0, 0.5 / 3.0))),\n decode32(texture(cc_realtimeJoint, vec2((x + 2.5)/ 1024.0, 0.5 / 3.0))),\n decode32(texture(cc_realtimeJoint, vec2((x + 3.5)/ 1024.0, 0.5 / 3.0)))\n );\n vec4 v2 = vec4(\n decode32(texture(cc_realtimeJoint, vec2((x + 0.5)/ 1024.0, 1.5 / 3.0))),\n decode32(texture(cc_realtimeJoint, vec2((x + 1.5)/ 1024.0, 1.5 / 3.0))),\n decode32(texture(cc_realtimeJoint, vec2((x + 2.5)/ 1024.0, 1.5 / 3.0))),\n decode32(texture(cc_realtimeJoint, vec2((x + 3.5)/ 1024.0, 1.5 / 3.0)))\n );\n vec4 v3 = vec4(\n decode32(texture(cc_realtimeJoint, vec2((x + 0.5)/ 1024.0, 2.5 / 3.0))),\n decode32(texture(cc_realtimeJoint, vec2((x + 1.5)/ 1024.0, 2.5 / 3.0))),\n decode32(texture(cc_realtimeJoint, vec2((x + 2.5)/ 1024.0, 2.5 / 3.0))),\n decode32(texture(cc_realtimeJoint, vec2((x + 3.5)/ 1024.0, 2.5 / 3.0)))\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\n #endif\n mat4 skinMatrix () {\n vec4 joints = vec4(a_joints);\n return getJointMatrix(joints.x) * a_weights.x\n + getJointMatrix(joints.y) * a_weights.y\n + getJointMatrix(joints.z) * a_weights.z\n + getJointMatrix(joints.w) * a_weights.w;\n }\n void CCSkin (inout vec4 position) {\n mat4 m = skinMatrix();\n position = m * position;\n }\n void CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\n mat4 m = skinMatrix();\n position = m * position;\n normal = (m * vec4(normal, 0.0)).xyz;\n tangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n }\n#endif\nvoid CCVertInput(inout StandardVertInput In)\n{\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.position, In.normal, In.tangent);\n #endif\n #if CC_USE_SKINNING\n CCSkin(In.position, In.normal, In.tangent);\n #endif\n}\n#if !USE_INSTANCING\n #if USE_BATCHING\n layout(std140) uniform CCLocalBatched {\n highp mat4 cc_matWorlds[10];\n };\n #else\n layout(std140) uniform CCLocal {\n highp mat4 cc_matWorld;\n highp mat4 cc_matWorldIT;\n highp vec4 cc_lightingMapUVParam;\n highp vec4 cc_localShadowBias;\n };\n #endif\n#endif\nvoid CCGetWorldMatrixFull(out mat4 matWorld, out mat4 matWorldIT)\n{\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}\nlayout(std140) uniform Constants {\n vec4 tilingOffset;\n vec4 diffuseColor;\n vec4 specularColor;\n vec4 emissive;\n float alphaThreshold;\n float shininessExponent;\n float glossiness;\n float metallic;\n float normalScale;\n float transparencyFactor;\n float diffuseFactor;\n float specularFactor;\n};\nlayout(std140) uniform CCShadow {\n highp mat4 cc_matLightView;\n highp mat4 cc_matLightViewProj;\n highp vec4 cc_shadowInvProjDepthInfo;\n highp vec4 cc_shadowProjDepthInfo;\n highp vec4 cc_shadowProjInfo;\n mediump vec4 cc_shadowNFLSInfo;\n mediump vec4 cc_shadowWHPBInfo;\n mediump vec4 cc_shadowLPNNInfo;\n lowp vec4 cc_shadowColor;\n mediump vec4 cc_planarNDInfo;\n};\n#if HAS_SECOND_UV || CC_USE_LIGHTMAP\n in vec2 a_texCoord1;\n#endif\nout vec2 v_uv;\nout vec2 v_uv1;\nout vec4 v_worldPos;\nout highp vec2 v_clip_depth;\n#if USE_VERTEX_COLOR\n in vec4 a_color;\n out lowp vec4 v_color;\n#endif\nvec4 vert () {\n StandardVertInput In;\n CCVertInput(In);\n mat4 matWorld, matWorldIT;\n CCGetWorldMatrixFull(matWorld, matWorldIT);\n v_worldPos = matWorld * In.position;\n vec4 clipPos = cc_matLightViewProj * v_worldPos;\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 v_clip_depth = clipPos.zw;\n return clipPos;\n}\nvoid main() { gl_Position = vert(); }",
|
|
"frag": "\nprecision highp float;\nlayout(std140) uniform Constants {\n vec4 tilingOffset;\n vec4 diffuseColor;\n vec4 specularColor;\n vec4 emissive;\n float alphaThreshold;\n float shininessExponent;\n float glossiness;\n float metallic;\n float normalScale;\n float transparencyFactor;\n float diffuseFactor;\n float specularFactor;\n};\nvec4 packDepthToRGBA (float depth) {\n vec4 ret = vec4(1.0, 255.0, 65025.0, 16581375.0) * depth;\n ret = fract(ret);\n ret -= vec4(ret.yzw, 0.0) / 255.0;\n return ret;\n}\nlayout(std140) uniform CCShadow {\n highp mat4 cc_matLightView;\n highp mat4 cc_matLightViewProj;\n highp vec4 cc_shadowInvProjDepthInfo;\n highp vec4 cc_shadowProjDepthInfo;\n highp vec4 cc_shadowProjInfo;\n mediump vec4 cc_shadowNFLSInfo;\n mediump vec4 cc_shadowWHPBInfo;\n mediump vec4 cc_shadowLPNNInfo;\n lowp vec4 cc_shadowColor;\n mediump vec4 cc_planarNDInfo;\n};\n#if CC_SUPPORT_CASCADED_SHADOW_MAP\n layout(std140) uniform CCCSM {\n highp vec4 cc_csmViewDir0[4];\n highp vec4 cc_csmViewDir1[4];\n highp vec4 cc_csmViewDir2[4];\n highp vec4 cc_csmAtlas[4];\n highp mat4 cc_matCSMViewProj[4];\n highp vec4 cc_csmProjDepthInfo[4];\n highp vec4 cc_csmProjInfo[4];\n highp vec4 cc_csmSplitsInfo;\n };\n#endif\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nfloat GetLinearDepthFromViewSpace(vec3 viewPos, float near, float far) {\n float dist = length(viewPos);\n return (dist - near) / (far - near);\n}\nfloat CCGetLinearDepth(vec3 worldPos, float viewSpaceBias) {\n\tvec4 viewPos = cc_matLightView * vec4(worldPos.xyz, 1.0);\n viewPos.z += viewSpaceBias;\n\treturn GetLinearDepthFromViewSpace(viewPos.xyz, cc_shadowNFLSInfo.x, cc_shadowNFLSInfo.y);\n}\nfloat CCGetLinearDepth(vec3 worldPos) {\n\treturn CCGetLinearDepth(worldPos, 0.0);\n}\n#if CC_RECEIVE_SHADOW\n layout(std140) uniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_nativeSize;\n mediump vec4 cc_debug_view_mode;\n mediump vec4 cc_debug_view_composite_pack_1;\n mediump vec4 cc_debug_view_composite_pack_2;\n mediump vec4 cc_debug_view_composite_pack_3;\n };\n layout(std140) uniform CCCamera {\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_surfaceTransform;\n mediump vec4 cc_screenScale;\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 mediump vec4 cc_nearFar;\n mediump vec4 cc_viewPort;\n };\n uniform highp sampler2D cc_shadowMap;\n uniform highp sampler2D cc_spotShadowMap;\n #if CC_SUPPORT_CASCADED_SHADOW_MAP\n #else\n #endif\n#endif\nin vec2 v_uv;\nin vec2 v_uv1;\nin vec4 v_worldPos;\nin highp vec2 v_clip_depth;\n#if USE_ALBEDO_MAP\n uniform sampler2D albedoMap;\n#endif\n#if USE_TRANSPARENCY_MAP\n uniform sampler2D transparencyMap;\n#endif\n#if USE_VERTEX_COLOR\n in lowp vec4 v_color;\n#endif\nvec4 frag () {\n #if USE_ALPHA_TEST\n float alpha = diffuseColor.a;\n #if USE_VERTEX_COLOR\n alpha *= v_color.a;\n #endif\n #if USE_ALBEDO_MAP\n alpha *= texture(albedoMap, TEXTURE_UV).a * transparencyFactor;\n #endif\n #if USE_TRANSPARENCY_MAP\n alpha = texture(transparencyMap, TEXTURE_UV).a;\n #endif\n if (alpha < alphaThreshold) discard;\n #endif\n highp float clipDepth = v_clip_depth.x / v_clip_depth.y * 0.5 + 0.5;\n if(cc_shadowLPNNInfo.x > 0.000001 && cc_shadowLPNNInfo.x < 1.999999) {\n #if CC_SHADOWMAP_USE_LINEAR_DEPTH\n clipDepth = CCGetLinearDepth(v_worldPos.xyz);\n #endif\n }\n #if CC_SHADOWMAP_FORMAT == 1\n return packDepthToRGBA(clipDepth);\n #else\n return vec4(clipDepth, 1.0, 1.0, 1.0);\n #endif\n}\nlayout(location = 0) out vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }"
|
|
},
|
|
"glsl1": {
|
|
"vert": "\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\n rgba = rgba * 255.0;\n highp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\n highp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\n highp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\n}\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_SKINNING\n attribute vec4 a_joints;\n attribute vec4 a_weights;\n#endif\n#if USE_INSTANCING\n #if CC_USE_BAKED_ANIMATION\n attribute highp vec4 a_jointAnimInfo;\n #endif\n attribute vec4 a_matWorld0;\n attribute vec4 a_matWorld1;\n attribute vec4 a_matWorld2;\n #if CC_USE_LIGHTMAP\n attribute vec4 a_lightingMapUVParam;\n #endif\n #if CC_RECEIVE_SHADOW\n attribute vec2 a_localShadowBias;\n #endif\n#elif USE_BATCHING\n attribute float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\n attribute float a_vertexId;\n int getVertexId() {\n return int(a_vertexId);\n }\n#endif\n#if CC_USE_MORPH\n uniform vec4 cc_displacementWeights[15];\n uniform vec4 cc_displacementTextureInfo;\n #if CC_MORPH_TARGET_HAS_POSITION\n uniform sampler2D cc_PositionDisplacements;\n #endif\n #if CC_MORPH_TARGET_HAS_NORMAL\n uniform sampler2D cc_NormalDisplacements;\n #endif\n #if CC_MORPH_TARGET_HAS_TANGENT\n uniform sampler2D cc_TangentDisplacements;\n #endif\n vec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\n float pixelIndexF = float(pixelIndex);\n float x = mod(pixelIndexF, textureResolution.x);\n float y = floor(pixelIndexF / textureResolution.x);\n return vec2(x, y);\n }\n vec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\n return (vec2(location.x, location.y) + .5) / textureResolution;\n }\n #if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\n vec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\n int pixelIndex = elementIndex;\n vec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\n vec2 uv = getPixelCoordFromLocation(location, cc_displacementTextureInfo.xy);\n return texture2D(tex, uv);\n }\n #else\n vec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\n int pixelIndex = elementIndex * 4;\n vec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\n vec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\n vec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\n vec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\n return vec4(\n decode32(texture2D(tex, x)),\n decode32(texture2D(tex, y)),\n decode32(texture2D(tex, z)),\n 1.0\n );\n }\n #endif\n float getDisplacementWeight(int index) {\n int quot = index / 4;\n int remainder = index - quot * 4;\n if (remainder == 0) {\n return cc_displacementWeights[quot].x;\n } else if (remainder == 1) {\n return cc_displacementWeights[quot].y;\n } else if (remainder == 2) {\n return cc_displacementWeights[quot].z;\n } else {\n return cc_displacementWeights[quot].w;\n }\n }\n vec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n #if CC_MORPH_PRECOMPUTED\n return fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n #else\n vec3 result = vec3(0, 0, 0);\n int nVertices = int(cc_displacementTextureInfo.z);\n for (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\n result += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n }\n return result;\n #endif\n }\n #if CC_MORPH_TARGET_HAS_POSITION\n vec3 getPositionDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n }\n #endif\n #if CC_MORPH_TARGET_HAS_NORMAL\n vec3 getNormalDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n }\n #endif\n #if CC_MORPH_TARGET_HAS_TANGENT\n vec3 getTangentDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n }\n #endif\n void applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\n int vertexId = getVertexId();\n #if CC_MORPH_TARGET_HAS_POSITION\n position.xyz = position.xyz + getPositionDisplacement(vertexId);\n #endif\n #if CC_MORPH_TARGET_HAS_NORMAL\n normal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n #endif\n #if CC_MORPH_TARGET_HAS_TANGENT\n tangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n #endif\n }\n void 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\n #if CC_USE_BAKED_ANIMATION\n uniform highp vec4 cc_jointTextureInfo;\n uniform highp vec4 cc_jointAnimInfo;\n uniform highp sampler2D cc_jointTexture;\n void CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n {\n #if USE_INSTANCING\n highp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n #else\n highp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n #endif\n invSize = cc_jointTextureInfo.w;\n highp float tempY = floor(temp * invSize);\n x = floor(temp - tempY * cc_jointTextureInfo.x);\n y = (tempY + 0.5) * invSize;\n }\n #else\n #if CC_USE_REAL_TIME_JOINT_TEXTURE\n uniform highp sampler2D cc_realtimeJoint;\n #else\n uniform highp vec4 cc_joints[CC_JOINT_UNIFORM_CAPACITY * 3];\n #endif\n #endif\n #if CC_USE_BAKED_ANIMATION\n #if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\n mat4 getJointMatrix (float i) {\n highp float x, y, invSize;\n CCGetJointTextureCoords(3.0, i, x, y, 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 highp float x, y, invSize;\n CCGetJointTextureCoords(12.0, i, x, y, 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 #if CC_USE_REAL_TIME_JOINT_TEXTURE\n #if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\n mat4 getJointMatrix (float i) {\n float x = i;\n vec4 v1 = texture2D(cc_realtimeJoint, vec2( x / 256.0, 0.5 / 3.0));\n vec4 v2 = texture2D(cc_realtimeJoint, vec2( x / 256.0, 1.5 / 3.0));\n vec4 v3 = texture2D(cc_realtimeJoint, vec2( x / 256.0, 2.5 / 3.0));\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 float x = 4.0 * i;\n vec4 v1 = vec4(\n decode32(texture2D(cc_realtimeJoint, vec2((x + 0.5)/ 1024.0, 0.5 / 3.0))),\n decode32(texture2D(cc_realtimeJoint, vec2((x + 1.5)/ 1024.0, 0.5 / 3.0))),\n decode32(texture2D(cc_realtimeJoint, vec2((x + 2.5)/ 1024.0, 0.5 / 3.0))),\n decode32(texture2D(cc_realtimeJoint, vec2((x + 3.5)/ 1024.0, 0.5 / 3.0)))\n );\n vec4 v2 = vec4(\n decode32(texture2D(cc_realtimeJoint, vec2((x + 0.5)/ 1024.0, 1.5 / 3.0))),\n decode32(texture2D(cc_realtimeJoint, vec2((x + 1.5)/ 1024.0, 1.5 / 3.0))),\n decode32(texture2D(cc_realtimeJoint, vec2((x + 2.5)/ 1024.0, 1.5 / 3.0))),\n decode32(texture2D(cc_realtimeJoint, vec2((x + 3.5)/ 1024.0, 1.5 / 3.0)))\n );\n vec4 v3 = vec4(\n decode32(texture2D(cc_realtimeJoint, vec2((x + 0.5)/ 1024.0, 2.5 / 3.0))),\n decode32(texture2D(cc_realtimeJoint, vec2((x + 1.5)/ 1024.0, 2.5 / 3.0))),\n decode32(texture2D(cc_realtimeJoint, vec2((x + 2.5)/ 1024.0, 2.5 / 3.0))),\n decode32(texture2D(cc_realtimeJoint, vec2((x + 3.5)/ 1024.0, 2.5 / 3.0)))\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\n #endif\n mat4 skinMatrix () {\n vec4 joints = vec4(a_joints);\n return getJointMatrix(joints.x) * a_weights.x\n + getJointMatrix(joints.y) * a_weights.y\n + getJointMatrix(joints.z) * a_weights.z\n + getJointMatrix(joints.w) * a_weights.w;\n }\n void CCSkin (inout vec4 position) {\n mat4 m = skinMatrix();\n position = m * position;\n }\n void CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\n mat4 m = skinMatrix();\n position = m * position;\n normal = (m * vec4(normal, 0.0)).xyz;\n tangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n }\n#endif\nvoid CCVertInput(inout StandardVertInput In)\n{\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.position, In.normal, In.tangent);\n #endif\n #if CC_USE_SKINNING\n CCSkin(In.position, In.normal, In.tangent);\n #endif\n}\n#if !USE_INSTANCING\n #if USE_BATCHING\n uniform highp mat4 cc_matWorlds[10];\n #else\n uniform highp mat4 cc_matWorld;\n uniform highp mat4 cc_matWorldIT;\n #endif\n#endif\nvoid CCGetWorldMatrixFull(out mat4 matWorld, out mat4 matWorldIT)\n{\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}\n uniform vec4 tilingOffset;\nuniform highp mat4 cc_matLightViewProj;\n#if HAS_SECOND_UV || CC_USE_LIGHTMAP\n attribute vec2 a_texCoord1;\n#endif\nvarying vec2 v_uv;\nvarying vec2 v_uv1;\nvarying vec4 v_worldPos;\nvarying highp vec2 v_clip_depth;\n#if USE_VERTEX_COLOR\n attribute vec4 a_color;\n varying lowp vec4 v_color;\n#endif\nvec4 vert () {\n StandardVertInput In;\n CCVertInput(In);\n mat4 matWorld, matWorldIT;\n CCGetWorldMatrixFull(matWorld, matWorldIT);\n v_worldPos = matWorld * In.position;\n vec4 clipPos = cc_matLightViewProj * v_worldPos;\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 v_clip_depth = clipPos.zw;\n return clipPos;\n}\nvoid main() { gl_Position = vert(); }",
|
|
"frag": "\nprecision highp float;\n uniform vec4 diffuseColor;\n uniform float alphaThreshold;\n uniform float transparencyFactor;\nvec4 packDepthToRGBA (float depth) {\n vec4 ret = vec4(1.0, 255.0, 65025.0, 16581375.0) * depth;\n ret = fract(ret);\n ret -= vec4(ret.yzw, 0.0) / 255.0;\n return ret;\n}\nuniform highp mat4 cc_matLightView;\n uniform mediump vec4 cc_shadowNFLSInfo;\n uniform mediump vec4 cc_shadowLPNNInfo;\n#if CC_SUPPORT_CASCADED_SHADOW_MAP\n #endif\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nfloat GetLinearDepthFromViewSpace(vec3 viewPos, float near, float far) {\n float dist = length(viewPos);\n return (dist - near) / (far - near);\n}\nfloat CCGetLinearDepth(vec3 worldPos, float viewSpaceBias) {\n\tvec4 viewPos = cc_matLightView * vec4(worldPos.xyz, 1.0);\n viewPos.z += viewSpaceBias;\n\treturn GetLinearDepthFromViewSpace(viewPos.xyz, cc_shadowNFLSInfo.x, cc_shadowNFLSInfo.y);\n}\nfloat CCGetLinearDepth(vec3 worldPos) {\n\treturn CCGetLinearDepth(worldPos, 0.0);\n}\n#if CC_RECEIVE_SHADOW\n uniform highp sampler2D cc_shadowMap;\n uniform highp sampler2D cc_spotShadowMap;\n #if CC_SUPPORT_CASCADED_SHADOW_MAP\n #else\n #endif\n#endif\nvarying vec2 v_uv;\nvarying vec2 v_uv1;\nvarying vec4 v_worldPos;\nvarying highp vec2 v_clip_depth;\n#if USE_ALBEDO_MAP\n uniform sampler2D albedoMap;\n#endif\n#if USE_TRANSPARENCY_MAP\n uniform sampler2D transparencyMap;\n#endif\n#if USE_VERTEX_COLOR\n varying lowp vec4 v_color;\n#endif\nvec4 frag () {\n #if USE_ALPHA_TEST\n float alpha = diffuseColor.a;\n #if USE_VERTEX_COLOR\n alpha *= v_color.a;\n #endif\n #if USE_ALBEDO_MAP\n alpha *= texture2D(albedoMap, TEXTURE_UV).a * transparencyFactor;\n #endif\n #if USE_TRANSPARENCY_MAP\n alpha = texture2D(transparencyMap, TEXTURE_UV).a;\n #endif\n if (alpha < alphaThreshold) discard;\n #endif\n highp float clipDepth = v_clip_depth.x / v_clip_depth.y * 0.5 + 0.5;\n if(cc_shadowLPNNInfo.x > 0.000001 && cc_shadowLPNNInfo.x < 1.999999) {\n #if CC_SHADOWMAP_USE_LINEAR_DEPTH\n clipDepth = CCGetLinearDepth(v_worldPos.xyz);\n #endif\n }\n #if CC_SHADOWMAP_FORMAT == 1\n return packDepthToRGBA(clipDepth);\n #else\n return vec4(clipDepth, 1.0, 1.0, 1.0);\n #endif\n}\nvoid main() { gl_FragColor = frag(); }"
|
|
},
|
|
"builtins": {
|
|
"globals": {
|
|
"blocks": [
|
|
{
|
|
"name": "CCShadow",
|
|
"defines": []
|
|
},
|
|
{
|
|
"name": "CCCSM",
|
|
"defines": [
|
|
"CC_SUPPORT_CASCADED_SHADOW_MAP"
|
|
]
|
|
},
|
|
{
|
|
"name": "CCGlobal",
|
|
"defines": [
|
|
"CC_RECEIVE_SHADOW"
|
|
]
|
|
},
|
|
{
|
|
"name": "CCCamera",
|
|
"defines": [
|
|
"CC_RECEIVE_SHADOW"
|
|
]
|
|
}
|
|
],
|
|
"samplerTextures": [
|
|
{
|
|
"name": "cc_shadowMap",
|
|
"defines": [
|
|
"CC_RECEIVE_SHADOW"
|
|
]
|
|
},
|
|
{
|
|
"name": "cc_spotShadowMap",
|
|
"defines": [
|
|
"CC_RECEIVE_SHADOW"
|
|
]
|
|
}
|
|
],
|
|
"buffers": [],
|
|
"images": []
|
|
},
|
|
"locals": {
|
|
"blocks": [
|
|
{
|
|
"name": "CCMorph",
|
|
"defines": [
|
|
"CC_USE_MORPH"
|
|
]
|
|
},
|
|
{
|
|
"name": "CCSkinningTexture",
|
|
"defines": [
|
|
"CC_USE_SKINNING",
|
|
"CC_USE_BAKED_ANIMATION"
|
|
]
|
|
},
|
|
{
|
|
"name": "CCSkinningAnimation",
|
|
"defines": [
|
|
"CC_USE_SKINNING",
|
|
"CC_USE_BAKED_ANIMATION"
|
|
]
|
|
},
|
|
{
|
|
"name": "CCSkinning",
|
|
"defines": [
|
|
"CC_USE_SKINNING",
|
|
"!CC_USE_BAKED_ANIMATION",
|
|
"!CC_USE_REAL_TIME_JOINT_TEXTURE"
|
|
]
|
|
},
|
|
{
|
|
"name": "CCLocalBatched",
|
|
"defines": [
|
|
"!USE_INSTANCING",
|
|
"USE_BATCHING"
|
|
]
|
|
},
|
|
{
|
|
"name": "CCLocal",
|
|
"defines": [
|
|
"!USE_INSTANCING",
|
|
"!USE_BATCHING"
|
|
]
|
|
}
|
|
],
|
|
"samplerTextures": [
|
|
{
|
|
"name": "cc_PositionDisplacements",
|
|
"defines": [
|
|
"CC_USE_MORPH",
|
|
"CC_MORPH_TARGET_HAS_POSITION"
|
|
]
|
|
},
|
|
{
|
|
"name": "cc_NormalDisplacements",
|
|
"defines": [
|
|
"CC_USE_MORPH",
|
|
"CC_MORPH_TARGET_HAS_NORMAL"
|
|
]
|
|
},
|
|
{
|
|
"name": "cc_TangentDisplacements",
|
|
"defines": [
|
|
"CC_USE_MORPH",
|
|
"CC_MORPH_TARGET_HAS_TANGENT"
|
|
]
|
|
},
|
|
{
|
|
"name": "cc_jointTexture",
|
|
"defines": [
|
|
"CC_USE_SKINNING",
|
|
"CC_USE_BAKED_ANIMATION"
|
|
]
|
|
},
|
|
{
|
|
"name": "cc_realtimeJoint",
|
|
"defines": [
|
|
"CC_USE_SKINNING",
|
|
"!CC_USE_BAKED_ANIMATION",
|
|
"CC_USE_REAL_TIME_JOINT_TEXTURE"
|
|
]
|
|
}
|
|
],
|
|
"buffers": [],
|
|
"images": []
|
|
},
|
|
"statistics": {
|
|
"CC_EFFECT_USED_VERTEX_UNIFORM_VECTORS": 96,
|
|
"CC_EFFECT_USED_FRAGMENT_UNIFORM_VECTORS": 113
|
|
}
|
|
},
|
|
"defines": [
|
|
{
|
|
"name": "USE_INSTANCING",
|
|
"type": "boolean",
|
|
"defines": [],
|
|
"editor": {
|
|
"elevated": true
|
|
}
|
|
},
|
|
{
|
|
"name": "USE_BATCHING",
|
|
"type": "boolean",
|
|
"defines": [
|
|
"!USE_INSTANCING"
|
|
],
|
|
"editor": {
|
|
"elevated": true
|
|
}
|
|
},
|
|
{
|
|
"name": "CC_USE_SKINNING",
|
|
"type": "boolean",
|
|
"defines": []
|
|
},
|
|
{
|
|
"name": "CC_USE_BAKED_ANIMATION",
|
|
"type": "boolean",
|
|
"defines": [
|
|
"USE_INSTANCING"
|
|
]
|
|
},
|
|
{
|
|
"name": "CC_USE_LIGHTMAP",
|
|
"type": "boolean",
|
|
"defines": [
|
|
"USE_INSTANCING"
|
|
]
|
|
},
|
|
{
|
|
"name": "CC_RECEIVE_SHADOW",
|
|
"type": "boolean",
|
|
"defines": []
|
|
},
|
|
{
|
|
"name": "CC_USE_MORPH",
|
|
"type": "boolean",
|
|
"defines": []
|
|
},
|
|
{
|
|
"name": "CC_MORPH_TARGET_COUNT",
|
|
"type": "number",
|
|
"defines": [
|
|
"CC_USE_MORPH"
|
|
],
|
|
"range": [
|
|
2,
|
|
8
|
|
]
|
|
},
|
|
{
|
|
"name": "CC_MORPH_TARGET_HAS_POSITION",
|
|
"type": "boolean",
|
|
"defines": [
|
|
"CC_USE_MORPH"
|
|
]
|
|
},
|
|
{
|
|
"name": "CC_MORPH_TARGET_HAS_NORMAL",
|
|
"type": "boolean",
|
|
"defines": [
|
|
"CC_USE_MORPH"
|
|
]
|
|
},
|
|
{
|
|
"name": "CC_MORPH_TARGET_HAS_TANGENT",
|
|
"type": "boolean",
|
|
"defines": [
|
|
"CC_USE_MORPH"
|
|
]
|
|
},
|
|
{
|
|
"name": "CC_MORPH_PRECOMPUTED",
|
|
"type": "boolean",
|
|
"defines": [
|
|
"CC_USE_MORPH"
|
|
]
|
|
},
|
|
{
|
|
"name": "CC_USE_REAL_TIME_JOINT_TEXTURE",
|
|
"type": "boolean",
|
|
"defines": [
|
|
"CC_USE_SKINNING",
|
|
"!CC_USE_BAKED_ANIMATION"
|
|
]
|
|
},
|
|
{
|
|
"name": "HAS_SECOND_UV",
|
|
"type": "boolean",
|
|
"defines": []
|
|
},
|
|
{
|
|
"name": "USE_VERTEX_COLOR",
|
|
"type": "boolean",
|
|
"defines": []
|
|
},
|
|
{
|
|
"name": "CC_SUPPORT_CASCADED_SHADOW_MAP",
|
|
"type": "boolean",
|
|
"defines": []
|
|
},
|
|
{
|
|
"name": "TEXTURE_UV",
|
|
"type": "string",
|
|
"defines": [],
|
|
"options": [
|
|
"v_uv",
|
|
"v_uv1"
|
|
]
|
|
},
|
|
{
|
|
"name": "USE_ALBEDO_MAP",
|
|
"type": "boolean",
|
|
"defines": []
|
|
},
|
|
{
|
|
"name": "USE_TRANSPARENCY_MAP",
|
|
"type": "boolean",
|
|
"defines": []
|
|
},
|
|
{
|
|
"name": "USE_ALPHA_TEST",
|
|
"type": "boolean",
|
|
"defines": []
|
|
},
|
|
{
|
|
"name": "CC_SHADOWMAP_USE_LINEAR_DEPTH",
|
|
"type": "boolean",
|
|
"defines": []
|
|
},
|
|
{
|
|
"name": "CC_SHADOWMAP_FORMAT",
|
|
"type": "number",
|
|
"defines": [],
|
|
"range": [
|
|
0,
|
|
3
|
|
]
|
|
}
|
|
],
|
|
"name": "dcc/imported-specular-glossiness|shadow-caster-vs:vert|shadow-caster-fs:frag"
|
|
}
|
|
],
|
|
"combinations": [],
|
|
"hideInEditor": false
|
|
} |