markc1d 2 months ago
commit
27ff4d4934
100 changed files with 3138 additions and 0 deletions
  1. 137 0
      .eslintrc.js
  2. BIN
      assets/Default-Particle.png
  3. 43 0
      assets/Default-Particle.png.meta
  4. 12 0
      assets/chunks.meta
  5. 12 0
      assets/chunks/builtin.meta
  6. 12 0
      assets/chunks/builtin/functionalities.meta
  7. 31 0
      assets/chunks/builtin/functionalities/fog.chunk
  8. 9 0
      assets/chunks/builtin/functionalities/fog.chunk.meta
  9. 114 0
      assets/chunks/builtin/functionalities/morph-animation.chunk
  10. 9 0
      assets/chunks/builtin/functionalities/morph-animation.chunk.meta
  11. 89 0
      assets/chunks/builtin/functionalities/probe.chunk
  12. 9 0
      assets/chunks/builtin/functionalities/probe.chunk.meta
  13. 40 0
      assets/chunks/builtin/functionalities/sh.chunk
  14. 9 0
      assets/chunks/builtin/functionalities/sh.chunk.meta
  15. 438 0
      assets/chunks/builtin/functionalities/shadow-map.chunk
  16. 9 0
      assets/chunks/builtin/functionalities/shadow-map.chunk.meta
  17. 113 0
      assets/chunks/builtin/functionalities/skinning-animation-dqs.chunk
  18. 9 0
      assets/chunks/builtin/functionalities/skinning-animation-dqs.chunk.meta
  19. 103 0
      assets/chunks/builtin/functionalities/skinning-animation-lbs.chunk
  20. 9 0
      assets/chunks/builtin/functionalities/skinning-animation-lbs.chunk.meta
  21. 40 0
      assets/chunks/builtin/functionalities/world-transform.chunk
  22. 9 0
      assets/chunks/builtin/functionalities/world-transform.chunk.meta
  23. 12 0
      assets/chunks/builtin/internal.meta
  24. 19 0
      assets/chunks/builtin/internal/alpha-test.chunk
  25. 9 0
      assets/chunks/builtin/internal/alpha-test.chunk.meta
  26. 12 0
      assets/chunks/builtin/internal/editor.meta
  27. 9 0
      assets/chunks/builtin/internal/embedded-alpha.chunk
  28. 9 0
      assets/chunks/builtin/internal/embedded-alpha.chunk.meta
  29. 69 0
      assets/chunks/builtin/internal/particle-common.chunk
  30. 9 0
      assets/chunks/builtin/internal/particle-common.chunk.meta
  31. 33 0
      assets/chunks/builtin/internal/particle-trail.chunk
  32. 9 0
      assets/chunks/builtin/internal/particle-trail.chunk.meta
  33. 389 0
      assets/chunks/builtin/internal/particle-vs-gpu.chunk
  34. 9 0
      assets/chunks/builtin/internal/particle-vs-gpu.chunk.meta
  35. 114 0
      assets/chunks/builtin/internal/particle-vs-legacy.chunk
  36. 9 0
      assets/chunks/builtin/internal/particle-vs-legacy.chunk.meta
  37. 9 0
      assets/chunks/builtin/internal/sprite-common.chunk
  38. 9 0
      assets/chunks/builtin/internal/sprite-common.chunk.meta
  39. 4 0
      assets/chunks/builtin/internal/sprite-texture.chunk
  40. 9 0
      assets/chunks/builtin/internal/sprite-texture.chunk.meta
  41. 12 0
      assets/chunks/builtin/uniforms.meta
  42. 14 0
      assets/chunks/builtin/uniforms/cc-csm.chunk
  43. 9 0
      assets/chunks/builtin/uniforms/cc-csm.chunk.meta
  44. 6 0
      assets/chunks/builtin/uniforms/cc-diffusemap.chunk
  45. 9 0
      assets/chunks/builtin/uniforms/cc-diffusemap.chunk.meta
  46. 8 0
      assets/chunks/builtin/uniforms/cc-environment.chunk
  47. 9 0
      assets/chunks/builtin/uniforms/cc-environment.chunk.meta
  48. 18 0
      assets/chunks/builtin/uniforms/cc-forward-light.chunk
  49. 9 0
      assets/chunks/builtin/uniforms/cc-forward-light.chunk.meta
  50. 36 0
      assets/chunks/builtin/uniforms/cc-global.chunk
  51. 9 0
      assets/chunks/builtin/uniforms/cc-global.chunk.meta
  52. 2 0
      assets/chunks/builtin/uniforms/cc-light-map.chunk
  53. 9 0
      assets/chunks/builtin/uniforms/cc-light-map.chunk.meta
  54. 5 0
      assets/chunks/builtin/uniforms/cc-local-batched.chunk
  55. 9 0
      assets/chunks/builtin/uniforms/cc-local-batched.chunk.meta
  56. 13 0
      assets/chunks/builtin/uniforms/cc-local.chunk
  57. 9 0
      assets/chunks/builtin/uniforms/cc-local.chunk.meta
  58. 24 0
      assets/chunks/builtin/uniforms/cc-morph.chunk
  59. 9 0
      assets/chunks/builtin/uniforms/cc-morph.chunk.meta
  60. 14 0
      assets/chunks/builtin/uniforms/cc-reflection-probe.chunk
  61. 9 0
      assets/chunks/builtin/uniforms/cc-reflection-probe.chunk.meta
  62. 12 0
      assets/chunks/builtin/uniforms/cc-sh.chunk
  63. 9 0
      assets/chunks/builtin/uniforms/cc-sh.chunk.meta
  64. 5 0
      assets/chunks/builtin/uniforms/cc-shadow-map.chunk
  65. 9 0
      assets/chunks/builtin/uniforms/cc-shadow-map.chunk.meta
  66. 16 0
      assets/chunks/builtin/uniforms/cc-shadow.chunk
  67. 9 0
      assets/chunks/builtin/uniforms/cc-shadow.chunk.meta
  68. 43 0
      assets/chunks/builtin/uniforms/cc-skinning.chunk
  69. 9 0
      assets/chunks/builtin/uniforms/cc-skinning.chunk.meta
  70. 7 0
      assets/chunks/builtin/uniforms/cc-world-bound.chunk
  71. 9 0
      assets/chunks/builtin/uniforms/cc-world-bound.chunk.meta
  72. 12 0
      assets/chunks/common.meta
  73. 12 0
      assets/chunks/common/color.meta
  74. 10 0
      assets/chunks/common/color/aces.chunk
  75. 9 0
      assets/chunks/common/color/aces.chunk.meta
  76. 27 0
      assets/chunks/common/color/gamma.chunk
  77. 9 0
      assets/chunks/common/color/gamma.chunk.meta
  78. 20 0
      assets/chunks/common/color/tone-mapping.chunk
  79. 9 0
      assets/chunks/common/color/tone-mapping.chunk.meta
  80. 94 0
      assets/chunks/common/common-define.chunk
  81. 9 0
      assets/chunks/common/common-define.chunk.meta
  82. 12 0
      assets/chunks/common/data.meta
  83. 84 0
      assets/chunks/common/data/packing.chunk
  84. 9 0
      assets/chunks/common/data/packing.chunk.meta
  85. 31 0
      assets/chunks/common/data/unpack.chunk
  86. 9 0
      assets/chunks/common/data/unpack.chunk.meta
  87. 12 0
      assets/chunks/common/debug.meta
  88. 89 0
      assets/chunks/common/debug/debug-view-define.chunk
  89. 9 0
      assets/chunks/common/debug/debug-view-define.chunk.meta
  90. 12 0
      assets/chunks/common/effect.meta
  91. 65 0
      assets/chunks/common/effect/fog.chunk
  92. 9 0
      assets/chunks/common/effect/fog.chunk.meta
  93. 41 0
      assets/chunks/common/effect/special-effects.chunk
  94. 9 0
      assets/chunks/common/effect/special-effects.chunk.meta
  95. 12 0
      assets/chunks/common/graph-expression.meta
  96. 63 0
      assets/chunks/common/graph-expression/base.chunk
  97. 9 0
      assets/chunks/common/graph-expression/base.chunk.meta
  98. 12 0
      assets/chunks/common/internal-functions.meta
  99. 12 0
      assets/chunks/common/lighting.meta
  100. 60 0
      assets/chunks/common/lighting/attenuation.chunk

+ 137 - 0
.eslintrc.js
View File

@@ -0,0 +1,137 @@
+module.exports = {
+    root: true,
+    env: {
+        browser: true,
+        commonjs: true,
+        es6: true,
+        node: true,
+    },
+    extends: [
+        'eslint:recommended',
+        'plugin:@typescript-eslint/eslint-recommended',
+    ],
+    globals: {
+        Atomics: 'readonly',
+        SharedArrayBuffer: 'readonly',
+    },
+    parser: '@typescript-eslint/parser',
+    parserOptions: {
+        // ES6 syntax
+        ecmaVersion: 6,
+        sourceType: 'module',
+        ecmaFeatures: {
+            modules: true,
+        },
+        // 'project': './tsconfig.json'
+    },
+    plugins: [
+        '@typescript-eslint',
+        // 'jsdoc',
+        // 'prettier',
+    ],
+    rules: {
+        'quote-props': ['error', 'as-needed'],
+        // 'prettier/prettier': 'warn',
+        'keyword-spacing': ['warn', {
+            before: true,
+            after: true,
+        }],
+        camelcase: ['warn', {
+            properties: 'always',
+        }],
+        indent: ['error', 4, { SwitchCase: 1, CallExpression: { arguments: 'off' }, ArrayExpression: 'first' }],
+        // 'no-else-return': 'error',
+        'object-curly-spacing': ['error', 'always'],
+        'array-bracket-spacing': ['error', 'never'],
+        'semi-spacing': ['error', {
+            before: false,
+            after: true,
+        }],
+        'rest-spread-spacing': ['error', 'never'],
+        'space-in-parens': ['error', 'never'],
+        curly: 'error',
+        semi: ['error', 'always'],
+        'no-multi-spaces': ['error', { ignoreEOLComments: true }],
+        'no-whitespace-before-property': 'error',
+        'no-tabs': ['error', { allowIndentationTabs: true }],
+
+        'no-unused-vars': ['warn', 'all'],
+        'no-empty': ['error', { allowEmptyCatch: true }],
+        'consistent-return': ['warn', { treatUndefinedAsUnspecified: true }],
+        eqeqeq: ['warn', 'always'],
+        // 'line-comment-position': ['warn', { 'position': 'above' }],
+        'max-len': ['warn', {
+            code: 180,
+        }],
+        'no-undef': 0,
+        'no-constant-condition': ['warn', {
+            checkLoops: false,
+        }],
+        'no-inner-declarations': ['warn'],
+        'no-case-declarations': ['warn'],
+
+        // 'jsdoc/check-alignment': 1,
+        // 'jsdoc/check-param-names': 1,
+        // 'jsdoc/check-tag-names': 1,
+        // 'jsdoc/check-types': 1,
+        // 'jsdoc/implements-on-classes': 1,
+        // 'jsdoc/newline-after-description': 1,
+        // 'jsdoc/no-undefined-types': 1,
+        // 'jsdoc/require-jsdoc': 1,
+        // 'jsdoc/require-param': 1,
+        // 'jsdoc/require-param-description': 1,
+        // 'jsdoc/require-param-name': 1,
+        // 'jsdoc/require-param-type': 1,
+        // 'jsdoc/require-returns': 1,
+        // 'jsdoc/require-returns-check': 1,
+        // 'jsdoc/require-returns-description': 1,
+        // 'jsdoc/require-returns-type': 1,
+        // 'jsdoc/valid-types': 1,
+
+        // 行尾逗号
+        'comma-style': ['error', 'last'],
+        'comma-dangle': ['error', {
+            arrays: 'always-multiline',
+            objects: 'always-multiline',
+            imports: 'always-multiline',
+            exports: 'always-multiline',
+            functions: 'only-multiline',
+        }],
+        'comma-spacing': ['error', {
+            before: false,
+            after: true,
+        }],
+
+        // 空格、空行约定
+        'unicode-bom': ['warn', 'never'],
+        'block-spacing': ['error', 'always'],
+        'arrow-spacing': ['error', {
+            before: true,
+            after: true,
+        }],
+        'space-before-function-paren': ['error', {
+            anonymous: 'never',
+            named: 'never',
+            asyncArrow: 'always',
+        }],
+        'space-before-blocks': ['error', 'always'],
+        'space-infix-ops': ['warn'],
+        'space-unary-ops': ['warn', {
+            words: true,
+            nonwords: false,
+        }],
+        'spaced-comment': ['warn', 'always', {
+            line: {
+                markers: ['/'],
+                exceptions: ['/', '*'],
+            },
+        },
+        ],
+        'switch-colon-spacing': ['warn', {
+            before: false,
+            after: true,
+        }],
+        'eol-last': ['error', 'always'],
+        'no-trailing-spaces': ['error', { ignoreComments: true }],
+    },
+};

BIN
assets/Default-Particle.png
View File


+ 43 - 0
assets/Default-Particle.png.meta
View File

@@ -0,0 +1,43 @@
+{
+  "ver": "1.0.27",
+  "importer": "image",
+  "imported": true,
+  "uuid": "b5b27ab1-e740-4398-b407-848fc2b2c897",
+  "files": [
+    ".json",
+    ".png"
+  ],
+  "subMetas": {
+    "6c48a": {
+      "ver": "1.0.22",
+      "importer": "texture",
+      "uuid": "b5b27ab1-e740-4398-b407-848fc2b2c897@6c48a",
+      "imported": true,
+      "files": [
+        ".json"
+      ],
+      "subMetas": {},
+      "userData": {
+        "wrapModeS": "repeat",
+        "wrapModeT": "repeat",
+        "minfilter": "linear",
+        "magfilter": "linear",
+        "mipfilter": "none",
+        "premultiplyAlpha": false,
+        "anisotropy": 0,
+        "isUuid": true,
+        "imageUuidOrDatabaseUri": "b5b27ab1-e740-4398-b407-848fc2b2c897",
+        "visible": false
+      },
+      "displayName": "Default-Particle",
+      "id": "6c48a",
+      "name": "texture"
+    }
+  },
+  "userData": {
+    "type": "texture",
+    "redirect": "b5b27ab1-e740-4398-b407-848fc2b2c897@6c48a",
+    "hasAlpha": true,
+    "fixAlphaTransparencyArtifacts": false
+  }
+}

+ 12 - 0
assets/chunks.meta
View File

@@ -0,0 +1,12 @@
+{
+  "ver": "1.2.0",
+  "importer": "directory",
+  "imported": true,
+  "uuid": "ce750465-15d2-42c5-b176-10f21578f3f0",
+  "files": [],
+  "subMetas": {},
+  "userData": {
+    "compressionType": {},
+    "isRemoteBundle": {}
+  }
+}

+ 12 - 0
assets/chunks/builtin.meta
View File

@@ -0,0 +1,12 @@
+{
+  "ver": "1.2.0",
+  "importer": "directory",
+  "imported": true,
+  "uuid": "85f366b2-d149-4b14-aa1d-4634e3c28f69",
+  "files": [],
+  "subMetas": {},
+  "userData": {
+    "compressionType": {},
+    "isRemoteBundle": {}
+  }
+}

+ 12 - 0
assets/chunks/builtin/functionalities.meta
View File

@@ -0,0 +1,12 @@
+{
+  "ver": "1.2.0",
+  "importer": "directory",
+  "imported": true,
+  "uuid": "784eb20c-c955-4a9b-a320-571a5c392f79",
+  "files": [],
+  "subMetas": {},
+  "userData": {
+    "compressionType": {},
+    "isRemoteBundle": {}
+  }
+}

+ 31 - 0
assets/chunks/builtin/functionalities/fog.chunk
View File

@@ -0,0 +1,31 @@
+#pragma define-meta CC_USE_FOG range([0, 4])
+#pragma define CC_FOG_LINEAR 0
+#pragma define CC_FOG_EXP 1
+#pragma define CC_FOG_EXP_SQUARED 2
+#pragma define CC_FOG_LAYERED 3
+#pragma define CC_FOG_NONE 4
+
+#include <builtin/uniforms/cc-global>
+#if CC_USE_FOG != CC_FOG_NONE
+  #include <common/effect/fog>
+#endif
+
+// Fog helper functions
+void CC_TRANSFER_FOG_BASE(vec4 pos, out float factor)
+{
+#if CC_USE_FOG == CC_FOG_LINEAR
+	factor = LinearFog(pos, cc_cameraPos.xyz, cc_fogBase.x, cc_fogBase.y);
+#elif CC_USE_FOG == CC_FOG_EXP
+	factor = ExpFog(pos, cc_cameraPos.xyz, cc_fogBase.x, cc_fogBase.z, cc_fogAdd.z);
+#elif CC_USE_FOG == CC_FOG_EXP_SQUARED
+	factor = ExpSquaredFog(pos, cc_cameraPos.xyz, cc_fogBase.x, cc_fogBase.z, cc_fogAdd.z);
+#elif CC_USE_FOG == CC_FOG_LAYERED
+	factor = LayeredFog(pos, cc_cameraPos.xyz, cc_fogAdd.x, cc_fogAdd.y, cc_fogAdd.z);
+#else
+	factor = 1.0;
+#endif
+}
+
+void CC_APPLY_FOG_BASE(inout vec4 color, float factor) {
+	color = vec4(mix(cc_fogColor.rgb, color.rgb, factor), color.a);
+}

+ 9 - 0
assets/chunks/builtin/functionalities/fog.chunk.meta
View File

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.7",
+  "importer": "effect-header",
+  "imported": true,
+  "uuid": "02a04bf3-4c27-4596-81fd-dfc35224f1d1",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 114 - 0
assets/chunks/builtin/functionalities/morph-animation.chunk
View File

@@ -0,0 +1,114 @@
+#include <builtin/uniforms/cc-morph>
+
+/**
+ * Fetch n-th pixel from texture, row by row.
+ */
+vec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {
+  float pixelIndexF = float(pixelIndex);
+  float x = mod(pixelIndexF, textureResolution.x);
+  float y = floor(pixelIndexF / textureResolution.x);
+  return vec2(x, y);
+}
+
+vec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {
+  return (vec2(location.x, location.y) + .5) / textureResolution;
+}
+
+#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE
+  #if __VERSION__ >= 300
+    vec4 fetchVec3ArrayFromTexture(sampler2D tex, int pixelIndex) {
+      ivec2 texSize = textureSize(tex, 0);
+      return texelFetch(tex, ivec2(pixelIndex % texSize.x, pixelIndex / texSize.x), 0);
+    }
+  #else
+    vec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {
+      int pixelIndex = elementIndex;
+      vec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);
+      vec2 uv = getPixelCoordFromLocation(location, cc_displacementTextureInfo.xy);
+      return texture(tex, uv);
+    }
+  #endif
+#else
+  vec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {
+    int pixelIndex = elementIndex * 4;
+    vec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);
+    // Here implies that the texture's width must be multiple of 4.
+    vec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);
+    vec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);
+    vec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);
+    return vec4(
+      decode32(texture(tex, x)),
+      decode32(texture(tex, y)),
+      decode32(texture(tex, z)),
+      1.0
+    );
+  }
+#endif
+
+float getDisplacementWeight(int index) {
+  int quot = index / 4;
+  int remainder = index - quot * 4;
+  if (remainder == 0) {
+    return cc_displacementWeights[quot].x;
+  } else if (remainder == 1) {
+    return cc_displacementWeights[quot].y;
+  } else if (remainder == 2) {
+    return cc_displacementWeights[quot].z;
+  } else {
+    return cc_displacementWeights[quot].w;
+  }
+}
+
+vec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {
+#if CC_MORPH_PRECOMPUTED
+  return fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;
+#else
+  vec3 result = vec3(0, 0, 0);
+  int nVertices = int(cc_displacementTextureInfo.z);
+  for (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {
+    result += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));
+  }
+  return result;
+#endif
+}
+
+
+#if CC_MORPH_TARGET_HAS_POSITION
+vec3 getPositionDisplacement(int vertexId) {
+    return getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);
+}
+#endif
+
+#if CC_MORPH_TARGET_HAS_NORMAL
+vec3 getNormalDisplacement(int vertexId) {
+    return getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);
+}
+#endif
+
+#if CC_MORPH_TARGET_HAS_TANGENT
+vec3 getTangentDisplacement(int vertexId) {
+    return getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);
+}
+#endif
+
+void applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {
+  int vertexId = getVertexId();
+
+#if CC_MORPH_TARGET_HAS_POSITION
+  position.xyz = position.xyz + getPositionDisplacement(vertexId);
+#endif
+
+#if CC_MORPH_TARGET_HAS_NORMAL
+  normal.xyz = normal.xyz + getNormalDisplacement(vertexId);
+#endif
+
+#if CC_MORPH_TARGET_HAS_TANGENT
+  tangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);
+#endif
+}
+
+void applyMorph (inout vec4 position) {
+#if CC_MORPH_TARGET_HAS_POSITION
+  position.xyz = position.xyz + getPositionDisplacement(getVertexId());
+#endif
+}

+ 9 - 0
assets/chunks/builtin/functionalities/morph-animation.chunk.meta
View File

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.7",
+  "importer": "effect-header",
+  "imported": true,
+  "uuid": "3adaa06a-e674-487c-9d49-42bc398c255b",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 89 - 0
assets/chunks/builtin/functionalities/probe.chunk
View File

@@ -0,0 +1,89 @@
+#include <builtin/uniforms/cc-local>
+vec4 GetTexData(sampler2D dataMap, float dataMapWidth, float x, float uv_y)
+{
+  return vec4(
+      decode32(texture(dataMap, vec2(((x + 0.5)/dataMapWidth), uv_y))),
+      decode32(texture(dataMap, vec2(((x + 1.5)/dataMapWidth), uv_y))),
+      decode32(texture(dataMap, vec2(((x + 2.5)/dataMapWidth), uv_y))),
+      decode32(texture(dataMap, vec2(((x + 3.5)/dataMapWidth), uv_y)))
+    );
+}
+void GetPlanarReflectionProbeData(out vec4 plane, out float planarReflectionDepthScale, out float mipCount, float probeId)
+{
+    #if USE_INSTANCING
+      float uv_y = (probeId + 0.5) / cc_probeInfo.x; //align to texel center
+      float dataMapWidth = 12.0;
+      vec4 texData1 = GetTexData(cc_reflectionProbeDataMap, dataMapWidth, 0.0, uv_y);
+      vec4 texData2 = GetTexData(cc_reflectionProbeDataMap, dataMapWidth, 4.0, uv_y);
+      plane.xyz = texData1.xyz;
+      plane.w = texData2.x;
+      planarReflectionDepthScale = texData2.y;
+      mipCount = texData2.z;
+    #else
+      plane = cc_reflectionProbeData1;
+      planarReflectionDepthScale = cc_reflectionProbeData2.x;
+      mipCount = cc_reflectionProbeData2.w;
+    #endif
+}
+
+void GetCubeReflectionProbeData(out vec3 centerPos, out vec3 boxHalfSize, out float mipCount, float probeId)
+{
+    #if USE_INSTANCING
+      float uv_y = (probeId + 0.5) / cc_probeInfo.x; //align to texel center
+      float dataMapWidth = 12.0;
+      vec4 texData1 = GetTexData(cc_reflectionProbeDataMap, dataMapWidth, 0.0, uv_y);
+      vec4 texData2 = GetTexData(cc_reflectionProbeDataMap, dataMapWidth, 4.0, uv_y);
+      vec4 texData3 = GetTexData(cc_reflectionProbeDataMap, dataMapWidth, 8.0, uv_y);
+      centerPos = texData1.xyz;
+      boxHalfSize = texData2.xyz;
+      mipCount = texData3.x;
+    #else
+      centerPos = cc_reflectionProbeData1.xyz;
+      boxHalfSize = cc_reflectionProbeData2.xyz;
+      mipCount = cc_reflectionProbeData2.w;
+    #endif
+    RESTORE_REFLECTION_PROBE_MIP_COUNT(mipCount);
+}
+
+bool isReflectProbeUsingRGBE(float probeId)
+{
+  #if USE_INSTANCING
+      float uv_y = (probeId + 0.5) / cc_probeInfo.x; //align to texel center
+      float dataMapWidth = 12.0;
+      vec4 texData3 = GetTexData(cc_reflectionProbeDataMap, dataMapWidth, 8.0, uv_y);
+      return IS_REFLECTION_PROBE_USE_RGBE(texData3.x);
+  #else
+    return IS_REFLECTION_PROBE_USE_RGBE(cc_reflectionProbeData2.w);
+  #endif
+}
+
+bool isBlendReflectProbeUsingRGBE(float probeId)
+{
+  #if USE_INSTANCING
+      float uv_y = (probeId + 0.5) / cc_probeInfo.x; //align to texel center
+      float dataMapWidth = 12.0;
+      vec4 texData3 = GetTexData(cc_reflectionProbeDataMap, dataMapWidth, 8.0, uv_y);
+      return IS_REFLECTION_PROBE_USE_RGBE(texData3.x);
+  #else
+    return IS_REFLECTION_PROBE_USE_RGBE(cc_reflectionProbeBlendData2.w);
+  #endif
+}
+
+void GetBlendCubeReflectionProbeData(out vec3 centerPos, out vec3 boxHalfSize, out float mipCount, float probeId)
+{
+    #if USE_INSTANCING
+      float uv_y = (probeId + 0.5) / cc_probeInfo.x; //align to texel center
+      float dataMapWidth = 12.0;
+      vec4 texData1 = GetTexData(cc_reflectionProbeDataMap, dataMapWidth, 0.0, uv_y);
+      vec4 texData2 = GetTexData(cc_reflectionProbeDataMap, dataMapWidth, 4.0, uv_y);
+      vec4 texData3 = GetTexData(cc_reflectionProbeDataMap, dataMapWidth, 8.0, uv_y);
+      centerPos = texData1.xyz;
+      boxHalfSize = texData2.xyz;
+      mipCount = texData3.x;
+    #else
+      centerPos = cc_reflectionProbeBlendData1.xyz;
+      boxHalfSize = cc_reflectionProbeBlendData2.xyz;
+      mipCount = cc_reflectionProbeBlendData2.w;
+    #endif
+    RESTORE_REFLECTION_PROBE_MIP_COUNT(mipCount);
+}

+ 9 - 0
assets/chunks/builtin/functionalities/probe.chunk.meta
View File

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.7",
+  "importer": "effect-header",
+  "imported": true,
+  "uuid": "92ac3587-8a8c-4405-87b0-5cf026196c64",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 40 - 0
assets/chunks/builtin/functionalities/sh.chunk
View File

@@ -0,0 +1,40 @@
+#pragma define-meta CC_USE_LIGHT_PROBE default(false)
+
+#if CC_USE_LIGHT_PROBE
+vec3 SHEvaluate(vec3 normal)
+{
+    vec3 result;
+
+#if USE_INSTANCING
+    // calculate linear and const terms
+    vec4 normal4 = vec4(normal, 1.0);
+    result.r = dot(v_sh_linear_const_r, normal4);
+    result.g = dot(v_sh_linear_const_g, normal4);
+    result.b = dot(v_sh_linear_const_b, normal4);
+
+#else
+    // calculate linear and const terms
+    vec4 normal4 = vec4(normal, 1.0);
+    result.r = dot(cc_sh_linear_const_r, normal4);
+    result.g = dot(cc_sh_linear_const_g, normal4);
+    result.b = dot(cc_sh_linear_const_b, normal4);
+
+    // calculate quadratic terms
+    vec4 n14 = normal.xyzz * normal.yzzx;
+    float n5 = normal.x * normal.x - normal.y * normal.y;
+
+    result.r += dot(cc_sh_quadratic_r, n14);
+    result.g += dot(cc_sh_quadratic_g, n14);
+    result.b += dot(cc_sh_quadratic_b, n14);
+    result += (cc_sh_quadratic_a.rgb * n5);
+#endif
+
+  #if CC_USE_HDR
+    // convert from standard camera exposure parameters to current exposure value
+    // baked in LDR scene still regarded as exposured with standard camera parameters
+    result *= cc_exposure.w * cc_exposure.x;
+  #endif
+
+  return result;
+}
+#endif

+ 9 - 0
assets/chunks/builtin/functionalities/sh.chunk.meta
View File

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.7",
+  "importer": "effect-header",
+  "imported": true,
+  "uuid": "c8728e39-6dca-4d22-a4ee-cc1aefb0198a",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 438 - 0
assets/chunks/builtin/functionalities/shadow-map.chunk
View File

@@ -0,0 +1,438 @@
+// used for replacing cc-shadow-map-base.chunk
+#include <builtin/uniforms/cc-shadow>
+#if CC_SUPPORT_CASCADED_SHADOW_MAP
+  #include <builtin/uniforms/cc-csm>
+#endif
+#include <common/common-define>
+#include <common/math/coordinates>
+
+#pragma define SHADOWMAP_FORMAT_RGBA8 1
+#pragma define SHADOWMAP_FORMAT_FLOAT 0
+
+#pragma define CC_DIR_LIGHT_SHADOW_NONE 0
+#pragma define CC_DIR_LIGHT_SHADOW_UNIFORM 1
+#pragma define CC_DIR_LIGHT_SHADOW_CASCADED 2
+#pragma define CC_DIR_LIGHT_SHADOW_VARIANCE 3
+
+#pragma define CC_SHADOW_NONE 0
+#pragma define CC_SHADOW_PLANAR 1
+#pragma define CC_SHADOW_MAP 2
+
+float CCGetLinearDepth(vec3 worldPos, float viewSpaceBias) {
+	vec4 viewPos = cc_matLightView * vec4(worldPos.xyz, 1.0);
+  viewPos.z += viewSpaceBias;
+	return GetLinearDepthFromViewSpace(viewPos.xyz, cc_shadowNFLSInfo.x, cc_shadowNFLSInfo.y);
+}
+
+float CCGetLinearDepth(vec3 worldPos) {
+	return CCGetLinearDepth(worldPos, 0.0);
+}
+
+#if CC_RECEIVE_SHADOW
+  #include <builtin/uniforms/cc-global>
+  #include <builtin/uniforms/cc-shadow-map>
+
+  #include <common/data/packing>
+  #include <common/shadow/native-pcf>
+
+
+  //////////////////////////////////////////////////////////Helper Functions
+  bool GetShadowNDCPos(out vec3 shadowNDCPos, vec4 shadowPosWithDepthBias)
+  {
+  	shadowNDCPos = shadowPosWithDepthBias.xyz / shadowPosWithDepthBias.w * 0.5 + 0.5;
+  	if (shadowNDCPos.x < 0.0 || shadowNDCPos.x > 1.0 ||
+  		shadowNDCPos.y < 0.0 || shadowNDCPos.y > 1.0 ||
+  		shadowNDCPos.z < 0.0 || shadowNDCPos.z > 1.0) {
+  		return false;
+  	}
+  	CC_HANDLE_NDC_SAMPLE_FLIP(shadowNDCPos.xy, cc_cameraPos.w);
+  	return true;
+  }
+
+  vec4 ApplyShadowDepthBias_FaceNormal(vec4 shadowPos, vec3 worldNormal, float normalBias, vec3 matViewDir0, vec3 matViewDir1, vec3 matViewDir2, vec2 projScaleXY)
+  {
+    vec4 newShadowPos = shadowPos;
+    if (normalBias > EPSILON_LOWP)
+    {
+      vec3 viewNormal = vec3(dot(matViewDir0, worldNormal), dot(matViewDir1, worldNormal), dot(matViewDir2, worldNormal));
+      if (viewNormal.z < 0.1)
+        newShadowPos.xy += viewNormal.xy * projScaleXY * normalBias * clamp(viewNormal.z, 0.001, 0.1);
+    }
+    return newShadowPos;
+  }
+
+  vec4 ApplyShadowDepthBias_FaceNormal(vec4 shadowPos, vec3 worldNormal, float normalBias, mat4 matLightView, vec2 projScaleXY)
+  {
+  	vec4 newShadowPos = shadowPos;
+  	if (normalBias > EPSILON_LOWP)
+  	{
+  		vec4 viewNormal = matLightView * vec4(worldNormal, 0.0);
+  		if (viewNormal.z < 0.1)
+  			newShadowPos.xy += viewNormal.xy * projScaleXY * normalBias * clamp(viewNormal.z, 0.001, 0.1);
+  	}
+  	return newShadowPos;
+  }
+
+  float GetViewSpaceDepthFromNDCDepth_Orthgraphic(float NDCDepth, float projScaleZ, float projBiasZ)
+  {
+  	return (NDCDepth - projBiasZ) / projScaleZ;
+  }
+  float GetViewSpaceDepthFromNDCDepth_Perspective(float NDCDepth, float homogenousDividW, float invProjScaleZ, float invProjBiasZ)
+  {
+  	return NDCDepth * invProjScaleZ + homogenousDividW * invProjBiasZ;
+  }
+
+  vec4 ApplyShadowDepthBias_Perspective(vec4 shadowPos, float viewspaceDepthBias)
+  {
+  	// Recover the coord in view space: cc_matLightInvProj * shadowPos
+  	vec3 viewSpacePos;
+  	viewSpacePos.xy = shadowPos.xy * cc_shadowProjInfo.zw;
+  	viewSpacePos.z = GetViewSpaceDepthFromNDCDepth_Perspective(shadowPos.z, shadowPos.w, cc_shadowInvProjDepthInfo.x, cc_shadowInvProjDepthInfo.y);
+
+  	// Apply bias
+  	viewSpacePos.xyz += cc_shadowProjDepthInfo.z * normalize(viewSpacePos.xyz) * viewspaceDepthBias;
+
+  	// Reconstuct clipspace: cc_matLightProj * viewSpacePos
+  	vec4 clipSpacePos;
+  	clipSpacePos.xy = viewSpacePos.xy * cc_shadowProjInfo.xy;
+  	clipSpacePos.zw = viewSpacePos.z * cc_shadowProjDepthInfo.xz + vec2(cc_shadowProjDepthInfo.y, 0.0);
+
+  	// enabled linear depth?
+  	#if CC_SHADOWMAP_USE_LINEAR_DEPTH
+  		clipSpacePos.z = GetLinearDepthFromViewSpace(viewSpacePos.xyz, cc_shadowNFLSInfo.x, cc_shadowNFLSInfo.y);
+  		clipSpacePos.z = (clipSpacePos.z * 2.0 - 1.0) * clipSpacePos.w;
+  	#endif
+
+  	return clipSpacePos;
+  }
+
+  // (projScaleZ, projBiasZ) = cc_shadowProjDepthInfo.xy
+  vec4 ApplyShadowDepthBias_Orthographic(vec4 shadowPos, float viewspaceDepthBias, float projScaleZ, float projBiasZ)
+  {
+  	float coeffA = projScaleZ;
+  	float coeffB = projBiasZ;
+
+  	// Recover the Z distance in view space:
+  	float viewSpacePos_z = GetViewSpaceDepthFromNDCDepth_Orthgraphic(shadowPos.z, projScaleZ, projBiasZ);
+
+  	// Apply bias
+  	viewSpacePos_z += viewspaceDepthBias;
+
+  	// Reconstuct clipspace
+  	vec4 result = shadowPos;
+  	result.z = viewSpacePos_z * coeffA + coeffB;
+  	return result;
+  }
+
+  vec4 ApplyShadowDepthBias_PerspectiveLinearDepth(vec4 shadowPos, float viewspaceDepthBias, vec3 worldPos)
+  {
+    // reverse operation for GetShadowNDCPos
+    shadowPos.z = CCGetLinearDepth(worldPos, viewspaceDepthBias) * 2.0 - 1.0;
+    shadowPos.z *= shadowPos.w;
+    return shadowPos;
+  }
+
+  //////////////////////////////////////////////////////////Directional Light Shadow
+  float CCGetDirLightShadowFactorHard (vec4 shadowPosWithDepthBias) {
+	  vec3 shadowNDCPos;
+	  if (!GetShadowNDCPos(shadowNDCPos, shadowPosWithDepthBias)) {
+		  return 1.0;
+	  }
+    return NativePCFShadowFactorHard(shadowNDCPos, cc_shadowMap, cc_shadowWHPBInfo.xy);
+  }
+
+  float CCGetDirLightShadowFactorSoft (vec4 shadowPosWithDepthBias) {
+	  vec3 shadowNDCPos;
+	  if (!GetShadowNDCPos(shadowNDCPos, shadowPosWithDepthBias)) {
+		  return 1.0;
+	  }
+    return NativePCFShadowFactorSoft(shadowNDCPos, cc_shadowMap, cc_shadowWHPBInfo.xy);
+  }
+
+  float CCGetDirLightShadowFactorSoft3X (vec4 shadowPosWithDepthBias) {
+	  vec3 shadowNDCPos;
+	  if (!GetShadowNDCPos(shadowNDCPos, shadowPosWithDepthBias)) {
+		  return 1.0;
+	  }
+    return NativePCFShadowFactorSoft3X(shadowNDCPos, cc_shadowMap, cc_shadowWHPBInfo.xy);
+  }
+
+  float CCGetDirLightShadowFactorSoft5X (vec4 shadowPosWithDepthBias) {
+	  vec3 shadowNDCPos;
+	  if (!GetShadowNDCPos(shadowNDCPos, shadowPosWithDepthBias)) {
+		  return 1.0;
+	  }
+    return NativePCFShadowFactorSoft5X(shadowNDCPos, cc_shadowMap, cc_shadowWHPBInfo.xy);
+  }
+
+
+  //////////////////////////////////////////////////////////Spot Light Shadow
+  float CCGetSpotLightShadowFactorHard (vec4 shadowPosWithDepthBias, vec3 worldPos) {
+	  vec3 shadowNDCPos;
+	  if (!GetShadowNDCPos(shadowNDCPos, shadowPosWithDepthBias)) {
+		  return 1.0;
+	  }
+    return NativePCFShadowFactorHard(shadowNDCPos, cc_spotShadowMap, cc_shadowWHPBInfo.xy);
+  }
+
+  float CCGetSpotLightShadowFactorSoft (vec4 shadowPosWithDepthBias, vec3 worldPos) {
+	  vec3 shadowNDCPos;
+	  if (!GetShadowNDCPos(shadowNDCPos, shadowPosWithDepthBias)) {
+		  return 1.0;
+	  }
+    return NativePCFShadowFactorSoft(shadowNDCPos, cc_spotShadowMap, cc_shadowWHPBInfo.xy);
+  }
+
+  float CCGetSpotLightShadowFactorSoft3X (vec4 shadowPosWithDepthBias, vec3 worldPos) {
+	  vec3 shadowNDCPos;
+	  if (!GetShadowNDCPos(shadowNDCPos, shadowPosWithDepthBias)) {
+		  return 1.0;
+	  }
+    return NativePCFShadowFactorSoft3X(shadowNDCPos, cc_spotShadowMap, cc_shadowWHPBInfo.xy);
+  }
+
+  float CCGetSpotLightShadowFactorSoft5X (vec4 shadowPosWithDepthBias, vec3 worldPos) {
+	  vec3 shadowNDCPos;
+	  if (!GetShadowNDCPos(shadowNDCPos, shadowPosWithDepthBias)) {
+		  return 1.0;
+	  }
+    return NativePCFShadowFactorSoft5X(shadowNDCPos, cc_spotShadowMap, cc_shadowWHPBInfo.xy);
+  }
+
+
+  //////////////////////////////////////////////////////////Main Functions
+  float CCSpotShadowFactorBase(out vec4 shadowPosWithDepthBias, vec4 shadowPos, vec3 worldPos, vec2 shadowBias)
+  {
+    float pcf = cc_shadowWHPBInfo.z;
+    vec4 pos = vec4(1.0);
+    #if CC_SHADOWMAP_USE_LINEAR_DEPTH
+      pos = ApplyShadowDepthBias_PerspectiveLinearDepth(shadowPos, shadowBias.x, worldPos);
+    #else
+      pos = ApplyShadowDepthBias_Perspective(shadowPos, shadowBias.x);
+    #endif
+
+    float realtimeShadow = 1.0;
+    if (pcf > 2.9) {
+      realtimeShadow = CCGetSpotLightShadowFactorSoft5X(pos, worldPos);
+    }else if (pcf > 1.9) {
+      realtimeShadow = CCGetSpotLightShadowFactorSoft3X(pos, worldPos);
+    }else if (pcf > 0.9) {
+      realtimeShadow = CCGetSpotLightShadowFactorSoft(pos, worldPos);
+    }else {
+      realtimeShadow = CCGetSpotLightShadowFactorHard(pos, worldPos);
+    }
+
+    shadowPosWithDepthBias = pos;
+    return mix(realtimeShadow, 1.0, cc_shadowNFLSInfo.w);
+  }
+
+  float CCShadowFactorBase(out vec4 shadowPosWithDepthBias, vec4 shadowPos, vec3 N, vec2 shadowBias)
+  {
+    vec4 pos = ApplyShadowDepthBias_FaceNormal(shadowPos, N, shadowBias.y, cc_matLightView, cc_shadowProjInfo.xy);
+    pos = ApplyShadowDepthBias_Orthographic(pos, shadowBias.x, cc_shadowProjDepthInfo.x, cc_shadowProjDepthInfo.y);
+
+    float realtimeShadow = 1.0;
+    #if CC_DIR_SHADOW_PCF_TYPE == CC_SHADOW_PCF_SOFT_5X
+      realtimeShadow = CCGetDirLightShadowFactorSoft5X(pos);
+    #endif
+    #if CC_DIR_SHADOW_PCF_TYPE == CC_SHADOW_PCF_SOFT_3X
+      realtimeShadow =  CCGetDirLightShadowFactorSoft3X(pos);
+    #endif
+    #if CC_DIR_SHADOW_PCF_TYPE == CC_SHADOW_PCF_SOFT
+      realtimeShadow = CCGetDirLightShadowFactorSoft(pos);
+    #endif
+    #if CC_DIR_SHADOW_PCF_TYPE == CC_SHADOW_PCF_HARD
+      realtimeShadow = CCGetDirLightShadowFactorHard(pos);
+    #endif
+
+    shadowPosWithDepthBias = pos;
+    return mix(realtimeShadow, 1.0, cc_shadowNFLSInfo.w);
+  }
+
+  #if CC_SUPPORT_CASCADED_SHADOW_MAP
+    bool CCGetCSMLevelWithTransition(out highp float ratio, vec3 clipPos) {
+      highp float maxRange = 1.0 - cc_csmSplitsInfo.x;
+      highp float minRange = cc_csmSplitsInfo.x;
+      highp float thresholdInvert = 1.0 / cc_csmSplitsInfo.x;
+      ratio = 0.0;
+      if (clipPos.x <= minRange) {
+        ratio = clipPos.x * thresholdInvert;
+        return true;
+      }
+      if (clipPos.x >= maxRange) {
+        ratio = 1.0 - (clipPos.x - maxRange) * thresholdInvert;
+        return true;
+      }
+      if (clipPos.y <= minRange) {
+        ratio = clipPos.y  * thresholdInvert;
+        return true;
+      }
+      if (clipPos.y >= maxRange) {
+        ratio = 1.0 - (clipPos.y - maxRange) * thresholdInvert;
+        return true;
+      }
+      return false;
+    }
+
+    bool CCHasCSMLevel(int level, vec3 worldPos) {
+      highp float layerThreshold = cc_csmViewDir0[0].w;
+      bool hasLevel = false;
+      for (int i = 0; i < NUMCASCADES; i++) {
+        if (i == level) {
+          vec4 shadowPos = cc_matCSMViewProj[i] * vec4(worldPos.xyz, 1.0);
+          vec3 clipPos = shadowPos.xyz / shadowPos.w * 0.5 + 0.5;
+          if (clipPos.x >= layerThreshold && clipPos.x <= (1.0 - layerThreshold) &&
+              clipPos.y >= layerThreshold && clipPos.y <= (1.0 - layerThreshold) &&
+              clipPos.z >= 0.0 && clipPos.z <= 1.0) {
+            hasLevel = true;
+          }
+        }
+      }
+      return hasLevel;
+    }
+
+    void CCGetCSMLevel(out vec4 csmPos, out vec4 shadowProjDepthInfo, out vec4 shadowProjInfo, out vec3 shadowViewDir0, out vec3 shadowViewDir1, out vec3 shadowViewDir2, vec3 worldPos, int level) {
+      highp float layerThreshold = cc_csmViewDir0[0].w;
+      for (int i = 0; i < NUMCASCADES; i++) {
+        vec4 shadowPos = cc_matCSMViewProj[i] * vec4(worldPos.xyz, 1.0);
+        vec3 clipPos = shadowPos.xyz / shadowPos.w * 0.5 + 0.5;
+        if (clipPos.x >= layerThreshold && clipPos.x <= (1.0 - layerThreshold) &&
+            clipPos.y >= layerThreshold && clipPos.y <= (1.0 - layerThreshold) &&
+            clipPos.z >= 0.0 && clipPos.z <= 1.0 && i == level) {
+          csmPos = cc_matCSMViewProj[i] * vec4(worldPos.xyz, 1.0);
+          csmPos.xy = csmPos.xy * cc_csmAtlas[i].xy + cc_csmAtlas[i].zw;
+          shadowProjDepthInfo = cc_csmProjDepthInfo[i];
+          shadowProjInfo = cc_csmProjInfo[i];
+          shadowViewDir0 = cc_csmViewDir0[i].xyz;
+          shadowViewDir1 = cc_csmViewDir1[i].xyz;
+          shadowViewDir2 = cc_csmViewDir2[i].xyz;
+        }
+      }
+    }
+
+    int CCGetCSMLevel(out bool isTransitionArea, out highp float transitionRatio, out vec4 csmPos, out vec4 shadowProjDepthInfo, out vec4 shadowProjInfo, out vec3 shadowViewDir0, out vec3 shadowViewDir1, out vec3 shadowViewDir2, vec3 worldPos)
+    {
+      int level = -1;
+      highp float layerThreshold = cc_csmViewDir0[0].w;
+      for (int i = 0; i < NUMCASCADES; i++) {
+        vec4 shadowPos = cc_matCSMViewProj[i] * vec4(worldPos.xyz, 1.0);
+        vec3 clipPos = shadowPos.xyz / shadowPos.w * 0.5 + 0.5;
+        if (clipPos.x >= layerThreshold && clipPos.x <= (1.0 - layerThreshold) &&
+            clipPos.y >= layerThreshold && clipPos.y <= (1.0 - layerThreshold) &&
+            clipPos.z >= 0.0 && clipPos.z <= 1.0 && level < 0) {
+          #if CC_CASCADED_LAYERS_TRANSITION
+            isTransitionArea = CCGetCSMLevelWithTransition(transitionRatio, clipPos);
+          #endif
+          csmPos = cc_matCSMViewProj[i] * vec4(worldPos.xyz, 1.0);
+          csmPos.xy = csmPos.xy * cc_csmAtlas[i].xy + cc_csmAtlas[i].zw;
+          shadowProjDepthInfo = cc_csmProjDepthInfo[i];
+          shadowProjInfo = cc_csmProjInfo[i];
+          shadowViewDir0 = cc_csmViewDir0[i].xyz;
+          shadowViewDir1 = cc_csmViewDir1[i].xyz;
+          shadowViewDir2 = cc_csmViewDir2[i].xyz;
+          level = i;
+        }
+      }
+      return level;
+    }
+
+    int CCGetCSMLevel(out vec4 csmPos, out vec4 shadowProjDepthInfo, out vec4 shadowProjInfo, out vec3 shadowViewDir0, out vec3 shadowViewDir1, out vec3 shadowViewDir2, vec3 worldPos)
+    {
+      bool isTransitionArea = false;
+      highp float transitionRatio = 0.0;
+      return CCGetCSMLevel(isTransitionArea, transitionRatio, csmPos, shadowProjDepthInfo, shadowProjInfo, shadowViewDir0, shadowViewDir1, shadowViewDir2, worldPos);
+    }
+
+    // output csmPos is non-biased position that can be used for sampling shadow map after homogeneous divid
+    float CCCSMFactorBase(out vec4 csmPos, out vec4 csmPosWithBias, vec3 worldPos, vec3 N, vec2 shadowBias)
+    {
+      bool isTransitionArea = false;
+      highp float ratio = 0.0;
+      csmPos = vec4(1.0);
+      vec4 shadowProjDepthInfo, shadowProjInfo;
+      vec3 shadowViewDir0, shadowViewDir1, shadowViewDir2;
+      int level = -1;
+      #if CC_CASCADED_LAYERS_TRANSITION
+        level = CCGetCSMLevel(isTransitionArea, ratio, csmPos, shadowProjDepthInfo, shadowProjInfo, shadowViewDir0, shadowViewDir1, shadowViewDir2, worldPos);
+      #else
+        level = CCGetCSMLevel(csmPos, shadowProjDepthInfo, shadowProjInfo, shadowViewDir0, shadowViewDir1, shadowViewDir2, worldPos);
+      #endif
+      if (level < 0) { return 1.0; }
+
+      vec4 pos = ApplyShadowDepthBias_FaceNormal(csmPos, N, shadowBias.y, shadowViewDir0, shadowViewDir1, shadowViewDir2, shadowProjInfo.xy);
+      pos = ApplyShadowDepthBias_Orthographic(pos, shadowBias.x, shadowProjDepthInfo.x, shadowProjDepthInfo.y);
+      csmPosWithBias = pos;
+
+      float realtimeShadow = 1.0;
+      #if CC_DIR_SHADOW_PCF_TYPE == CC_SHADOW_PCF_SOFT_5X
+        realtimeShadow = CCGetDirLightShadowFactorSoft5X(pos);
+      #endif
+      #if CC_DIR_SHADOW_PCF_TYPE == CC_SHADOW_PCF_SOFT_3X
+        realtimeShadow = CCGetDirLightShadowFactorSoft3X(pos);
+      #endif
+      #if CC_DIR_SHADOW_PCF_TYPE == CC_SHADOW_PCF_SOFT
+        realtimeShadow = CCGetDirLightShadowFactorSoft(pos);
+      #endif
+      #if CC_DIR_SHADOW_PCF_TYPE == CC_SHADOW_PCF_HARD
+        realtimeShadow = CCGetDirLightShadowFactorHard(pos);
+      #endif
+
+      #if CC_CASCADED_LAYERS_TRANSITION
+        vec4 nextCSMPos = vec4(1.0);
+        vec4 nextShadowProjDepthInfo, nextShadowProjInfo;
+        vec3 nextShadowViewDir0, nextShadowViewDir1, nextShadowViewDir2;
+        float nextRealtimeShadow = 1.0;
+        CCGetCSMLevel(nextCSMPos, nextShadowProjDepthInfo, nextShadowProjInfo, nextShadowViewDir0, nextShadowViewDir1, nextShadowViewDir2, worldPos, level + 1);
+        bool hasNextLevel = CCHasCSMLevel(level + 1, worldPos);
+        if (hasNextLevel && isTransitionArea) {
+          vec4 nexPos = ApplyShadowDepthBias_FaceNormal(nextCSMPos, N, shadowBias.y, nextShadowViewDir0, nextShadowViewDir1, nextShadowViewDir2, nextShadowProjInfo.xy);
+          nexPos = ApplyShadowDepthBias_Orthographic(nexPos, shadowBias.x, nextShadowProjDepthInfo.x, nextShadowProjDepthInfo.y);
+
+          #if CC_DIR_SHADOW_PCF_TYPE == CC_SHADOW_PCF_SOFT_5X
+            nextRealtimeShadow = CCGetDirLightShadowFactorSoft5X(nexPos);
+          #endif
+          #if CC_DIR_SHADOW_PCF_TYPE == CC_SHADOW_PCF_SOFT_3X
+            nextRealtimeShadow = CCGetDirLightShadowFactorSoft3X(nexPos);
+          #endif
+          #if CC_DIR_SHADOW_PCF_TYPE == CC_SHADOW_PCF_SOFT
+            nextRealtimeShadow = CCGetDirLightShadowFactorSoft(nexPos);
+          #endif
+          #if CC_DIR_SHADOW_PCF_TYPE == CC_SHADOW_PCF_HARD
+            nextRealtimeShadow = CCGetDirLightShadowFactorHard(nexPos);
+          #endif
+
+          return mix(mix(nextRealtimeShadow, realtimeShadow, ratio), 1.0, cc_shadowNFLSInfo.w);
+        }
+        return mix(realtimeShadow, 1.0, cc_shadowNFLSInfo.w);
+      #else
+        return mix(realtimeShadow, 1.0, cc_shadowNFLSInfo.w);
+      #endif
+    }
+  #else
+    int CCGetCSMLevel(out vec4 csmPos, out vec4 shadowProjDepthInfo, out vec4 shadowProjInfo, out vec3 shadowViewDir0, out vec3 shadowViewDir1, out vec3 shadowViewDir2, vec3 worldPos) {
+      return -1;
+    }
+
+    float CCCSMFactorBase(out vec4 csmPos, out vec4 csmPosWithBias, vec3 worldPos, vec3 N, vec2 shadowBias) {
+      csmPos = cc_matLightViewProj * vec4(worldPos, 1.0);
+      return CCShadowFactorBase(csmPosWithBias, csmPos, N, shadowBias);
+    }
+  #endif
+
+  // compatible version
+  float CCShadowFactorBase(vec4 shadowPos, vec3 N, vec2 shadowBias) {
+    vec4 shadowPosWithDepthBias;
+    return CCShadowFactorBase(shadowPosWithDepthBias, shadowPos, N, shadowBias);
+  }
+
+  float CCCSMFactorBase(vec3 worldPos, vec3 N, vec2 shadowBias) {
+    vec4 csmPos, csmPosWithBias;
+    return CCCSMFactorBase(csmPos, csmPosWithBias, worldPos, N, shadowBias);
+  }
+
+  float CCSpotShadowFactorBase(vec4 shadowPos, vec3 worldPos, vec2 shadowBias)
+  {
+    vec4 shadowPosWithDepthBias;
+    return CCSpotShadowFactorBase(shadowPosWithDepthBias, shadowPos, worldPos, shadowBias);
+  }
+#endif

+ 9 - 0
assets/chunks/builtin/functionalities/shadow-map.chunk.meta
View File

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.7",
+  "importer": "effect-header",
+  "imported": true,
+  "uuid": "d4c26490-0a2d-4b6a-9a52-55b5741f18a4",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 113 - 0
assets/chunks/builtin/functionalities/skinning-animation-dqs.chunk
View File

@@ -0,0 +1,113 @@
+// Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
+
+#include <builtin/uniforms/cc-skinning>
+
+#if CC_USE_BAKED_ANIMATION
+  #if CC_DEVICE_SUPPORT_FLOAT_TEXTURE
+    void getJointDQ (float i, out vec4 Qr, out vec4 Qt, out vec3 S) {
+      highp float x, y, invSize;
+      CCGetJointTextureCoords(3.0, i, x, y, invSize);
+      Qr = texture(cc_jointTexture, vec2((x + 0.5) * invSize, y));
+      Qt = texture(cc_jointTexture, vec2((x + 1.5) * invSize, y));
+      S = texture(cc_jointTexture, vec2((x + 2.5) * invSize, y)).xyz;
+    }
+  #else
+    void getJointDQ (float i, out vec4 Qr, out vec4 Qt, out vec3 S) {
+      highp float x, y, invSize;
+      CCGetJointTextureCoords(12.0, i, x, y, invSize);
+      Qr = vec4(
+        decode32(texture(cc_jointTexture, vec2((x + 0.5) * invSize, y))),
+        decode32(texture(cc_jointTexture, vec2((x + 1.5) * invSize, y))),
+        decode32(texture(cc_jointTexture, vec2((x + 2.5) * invSize, y))),
+        decode32(texture(cc_jointTexture, vec2((x + 3.5) * invSize, y)))
+      );
+      Qt = vec4(
+        decode32(texture(cc_jointTexture, vec2((x + 4.5) * invSize, y))),
+        decode32(texture(cc_jointTexture, vec2((x + 5.5) * invSize, y))),
+        decode32(texture(cc_jointTexture, vec2((x + 6.5) * invSize, y))),
+        decode32(texture(cc_jointTexture, vec2((x + 7.5) * invSize, y)))
+      );
+      S = vec3(
+        decode32(texture(cc_jointTexture, vec2((x + 8.5) * invSize, y))),
+        decode32(texture(cc_jointTexture, vec2((x + 9.5) * invSize, y))),
+        decode32(texture(cc_jointTexture, vec2((x + 10.5) * invSize, y)))
+      );
+    }
+  #endif
+#else
+  #if CC_USE_REAL_TIME_JOINT_TEXTURE
+    #if CC_DEVICE_SUPPORT_FLOAT_TEXTURE
+      void getJointDQ (float i, out vec4 Qr, out vec4 Qt, out vec3 S) {
+        float x = i;
+        Qr = texture(cc_realtimeJoint, vec2( x / 256.0, 0.5 / 3.0));
+        Qt = texture(cc_realtimeJoint, vec2( x / 256.0, 1.5 / 3.0));
+        S = texture(cc_realtimeJoint, vec2( x / 256.0, 2.5 / 3.0)).xyz;
+      }
+    #else
+      void getJointDQ (float i, out vec4 Qr, out vec4 Qt, out vec3 S) {
+        float x = 4.0 * i;
+        vec4 v1 = vec4(
+          decode32(texture(cc_realtimeJoint, vec2((x + 0.5)/ 1024.0, 0.5 / 3.0))),
+          decode32(texture(cc_realtimeJoint, vec2((x + 1.5)/ 1024.0, 0.5 / 3.0))),
+          decode32(texture(cc_realtimeJoint, vec2((x + 2.5)/ 1024.0, 0.5 / 3.0))),
+          decode32(texture(cc_realtimeJoint, vec2((x + 3.5)/ 1024.0, 0.5 / 3.0)))
+        );
+        vec4 v2 = vec4(
+          decode32(texture(cc_realtimeJoint, vec2((x + 0.5)/ 1024.0, 1.5 / 3.0))),
+          decode32(texture(cc_realtimeJoint, vec2((x + 1.5)/ 1024.0, 1.5 / 3.0))),
+          decode32(texture(cc_realtimeJoint, vec2((x + 2.5)/ 1024.0, 1.5 / 3.0))),
+          decode32(texture(cc_realtimeJoint, vec2((x + 3.5)/ 1024.0, 1.5 / 3.0)))
+        );
+        vec4 v3 = vec4(
+          decode32(texture(cc_realtimeJoint, vec2((x + 0.5)/ 1024.0, 2.5 / 3.0))),
+          decode32(texture(cc_realtimeJoint, vec2((x + 1.5)/ 1024.0, 2.5 / 3.0))),
+          decode32(texture(cc_realtimeJoint, vec2((x + 2.5)/ 1024.0, 2.5 / 3.0))),
+          decode32(texture(cc_realtimeJoint, vec2((x + 3.5)/ 1024.0, 2.5 / 3.0)))
+        );
+        Qr = v1;
+        Qt = v2;
+        S = v3.xyz;
+      }
+    #endif
+  #else
+    void getJointDQ (float i, out vec4 Qr, out vec4 Qt, out vec3 S) {
+      int idx = int(i);
+      Qr = cc_joints[idx * 3];
+      Qt = cc_joints[idx * 3 + 1];
+      S = cc_joints[idx * 3 + 2].xyz;
+    }
+  #endif
+#endif
+
+// [Kavan07] Skinning with Dual Quaternions
+void skinRTS (out vec4 R, out vec3 T, out vec3 S) {
+  vec4 r, t, Qt = vec4(0.0); vec3 s;
+  R = vec4(0.0); S = vec3(0.0);
+
+  for (int i = 0; i < 4; i++) {
+    float w = a_weights[i];
+    getJointDQ(a_joints[i], r, t, s);
+    S += s * w; R += r * w; Qt += t * w;
+  }
+
+  float invNorm = 1.0 / length(R); R *= invNorm; Qt *= invNorm;
+  T = 2.0 * (R.w * Qt.xyz - Qt.w * R.xyz + cross(R.xyz, Qt.xyz)); // 2 * Qt * conjugate(R)
+}
+
+vec3 VectorTransformQuat (vec3 v, vec4 Q) {
+  return v + 2.0 * cross(Q.xyz, cross(Q.xyz, v) + Q.w * v);
+}
+
+void CCSkin (inout vec4 position) {
+  vec4 R; vec3 T, S;
+  skinRTS(R, T, S);
+  position.xyz = VectorTransformQuat(position.xyz * S, R) + T;
+}
+
+void CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {
+  vec4 R; vec3 T, S;
+  skinRTS(R, T, S);
+  position.xyz = VectorTransformQuat(position.xyz * S, R) + T;
+  normal = VectorTransformQuat(normal, R);
+  tangent.xyz = VectorTransformQuat(tangent.xyz, R);
+}

+ 9 - 0
assets/chunks/builtin/functionalities/skinning-animation-dqs.chunk.meta
View File

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.7",
+  "importer": "effect-header",
+  "imported": true,
+  "uuid": "80908463-4566-4fdf-9744-775605cd7ab7",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 103 - 0
assets/chunks/builtin/functionalities/skinning-animation-lbs.chunk
View File

@@ -0,0 +1,103 @@
+// Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
+
+#include <builtin/uniforms/cc-skinning>
+
+#if CC_USE_BAKED_ANIMATION
+  #if CC_DEVICE_SUPPORT_FLOAT_TEXTURE
+    mat4 getJointMatrix (float i) {
+      highp float x, y, invSize;
+      CCGetJointTextureCoords(3.0, i, x, y, invSize);
+      vec4 v1 = texture(cc_jointTexture, vec2((x + 0.5) * invSize, y));
+      vec4 v2 = texture(cc_jointTexture, vec2((x + 1.5) * invSize, y));
+      vec4 v3 = texture(cc_jointTexture, vec2((x + 2.5) * invSize, y));
+      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));
+    }
+  #else
+    mat4 getJointMatrix (float i) {
+      highp float x, y, invSize;
+      CCGetJointTextureCoords(12.0, i, x, y, invSize);
+      vec4 v1 = vec4(
+        decode32(texture(cc_jointTexture, vec2((x + 0.5) * invSize, y))),
+        decode32(texture(cc_jointTexture, vec2((x + 1.5) * invSize, y))),
+        decode32(texture(cc_jointTexture, vec2((x + 2.5) * invSize, y))),
+        decode32(texture(cc_jointTexture, vec2((x + 3.5) * invSize, y)))
+      );
+      vec4 v2 = vec4(
+        decode32(texture(cc_jointTexture, vec2((x + 4.5) * invSize, y))),
+        decode32(texture(cc_jointTexture, vec2((x + 5.5) * invSize, y))),
+        decode32(texture(cc_jointTexture, vec2((x + 6.5) * invSize, y))),
+        decode32(texture(cc_jointTexture, vec2((x + 7.5) * invSize, y)))
+      );
+      vec4 v3 = vec4(
+        decode32(texture(cc_jointTexture, vec2((x + 8.5) * invSize, y))),
+        decode32(texture(cc_jointTexture, vec2((x + 9.5) * invSize, y))),
+        decode32(texture(cc_jointTexture, vec2((x + 10.5) * invSize, y))),
+        decode32(texture(cc_jointTexture, vec2((x + 11.5) * invSize, y)))
+      );
+      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));
+    }
+  #endif
+#else
+  #if CC_USE_REAL_TIME_JOINT_TEXTURE
+    #if CC_DEVICE_SUPPORT_FLOAT_TEXTURE
+      mat4 getJointMatrix (float i) {
+        float x = i;
+        vec4 v1 = texture(cc_realtimeJoint, vec2( x / 256.0, 0.5 / 3.0));
+        vec4 v2 = texture(cc_realtimeJoint, vec2( x / 256.0, 1.5 / 3.0));
+        vec4 v3 = texture(cc_realtimeJoint, vec2( x / 256.0, 2.5 / 3.0));
+        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));
+      }
+    #else
+      mat4 getJointMatrix (float i) {
+       float x = 4.0 * i;
+        vec4 v1 = vec4(
+          decode32(texture(cc_realtimeJoint, vec2((x + 0.5)/ 1024.0, 0.5 / 3.0))),
+          decode32(texture(cc_realtimeJoint, vec2((x + 1.5)/ 1024.0, 0.5 / 3.0))),
+          decode32(texture(cc_realtimeJoint, vec2((x + 2.5)/ 1024.0, 0.5 / 3.0))),
+          decode32(texture(cc_realtimeJoint, vec2((x + 3.5)/ 1024.0, 0.5 / 3.0)))
+        );
+        vec4 v2 = vec4(
+          decode32(texture(cc_realtimeJoint, vec2((x + 0.5)/ 1024.0, 1.5 / 3.0))),
+          decode32(texture(cc_realtimeJoint, vec2((x + 1.5)/ 1024.0, 1.5 / 3.0))),
+          decode32(texture(cc_realtimeJoint, vec2((x + 2.5)/ 1024.0, 1.5 / 3.0))),
+          decode32(texture(cc_realtimeJoint, vec2((x + 3.5)/ 1024.0, 1.5 / 3.0)))
+        );
+        vec4 v3 = vec4(
+          decode32(texture(cc_realtimeJoint, vec2((x + 0.5)/ 1024.0, 2.5 / 3.0))),
+          decode32(texture(cc_realtimeJoint, vec2((x + 1.5)/ 1024.0, 2.5 / 3.0))),
+          decode32(texture(cc_realtimeJoint, vec2((x + 2.5)/ 1024.0, 2.5 / 3.0))),
+          decode32(texture(cc_realtimeJoint, vec2((x + 3.5)/ 1024.0, 2.5 / 3.0)))
+        );
+        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));
+      }
+    #endif
+  #else
+    mat4 getJointMatrix (float i) {
+      int idx = int(i);
+      vec4 v1 = cc_joints[idx * 3];
+      vec4 v2 = cc_joints[idx * 3 + 1];
+      vec4 v3 = cc_joints[idx * 3 + 2];
+      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));
+    }
+  #endif
+#endif
+
+mat4 skinMatrix () {
+  vec4 joints = vec4(a_joints); //simple conversion of a_joints from unsigned integer to float to match function parameter type
+  return getJointMatrix(joints.x) * a_weights.x
+       + getJointMatrix(joints.y) * a_weights.y
+       + getJointMatrix(joints.z) * a_weights.z
+       + getJointMatrix(joints.w) * a_weights.w;
+}
+
+void CCSkin (inout vec4 position) {
+  mat4 m = skinMatrix();
+  position = m * position;
+}
+
+void CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {
+  mat4 m = skinMatrix();
+  position = m * position;
+  normal = (m * vec4(normal, 0.0)).xyz;
+  tangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;
+}

+ 9 - 0
assets/chunks/builtin/functionalities/skinning-animation-lbs.chunk.meta
View File

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.7",
+  "importer": "effect-header",
+  "imported": true,
+  "uuid": "258a17ce-6c50-4e8a-92aa-8ecec1a6af24",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 40 - 0
assets/chunks/builtin/functionalities/world-transform.chunk
View File

@@ -0,0 +1,40 @@
+#include <builtin/uniforms/cc-local-batched>
+
+void CCGetWorldMatrix(out mat4 matWorld)
+{
+  #if USE_INSTANCING
+    matWorld = mat4(
+      vec4(a_matWorld0.xyz, 0.0),
+      vec4(a_matWorld1.xyz, 0.0),
+      vec4(a_matWorld2.xyz, 0.0),
+      vec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)
+    );
+  #else
+    matWorld = cc_matWorld;
+  #endif
+}
+
+void CCGetWorldMatrixFull(out mat4 matWorld, out mat4 matWorldIT)
+{
+  #if USE_INSTANCING
+    matWorld = mat4(
+      vec4(a_matWorld0.xyz, 0.0),
+      vec4(a_matWorld1.xyz, 0.0),
+      vec4(a_matWorld2.xyz, 0.0),
+      vec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)
+    );
+
+    // non-uniform scaling for normals
+    vec3 scale = 1.0 / vec3(length(a_matWorld0.xyz), length(a_matWorld1.xyz), length(a_matWorld2.xyz));
+    vec3 scale2 = scale * scale;
+    matWorldIT = mat4(
+      vec4(a_matWorld0.xyz * scale2.x, 0.0),
+      vec4(a_matWorld1.xyz * scale2.y, 0.0),
+      vec4(a_matWorld2.xyz * scale2.z, 0.0),
+      vec4(0.0, 0.0, 0.0, 1.0)
+    );
+  #else
+    matWorld = cc_matWorld;
+    matWorldIT = cc_matWorldIT;
+  #endif
+}

+ 9 - 0
assets/chunks/builtin/functionalities/world-transform.chunk.meta
View File

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.7",
+  "importer": "effect-header",
+  "imported": true,
+  "uuid": "c2885f54-4ff2-4284-8bbc-b77bc71965b4",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 12 - 0
assets/chunks/builtin/internal.meta
View File

@@ -0,0 +1,12 @@
+{
+  "ver": "1.2.0",
+  "importer": "directory",
+  "imported": true,
+  "uuid": "16ce72cc-31ca-4b20-86d3-28d643645218",
+  "files": [],
+  "subMetas": {},
+  "userData": {
+    "compressionType": {},
+    "isRemoteBundle": {}
+  }
+}

+ 19 - 0
assets/chunks/builtin/internal/alpha-test.chunk
View File

@@ -0,0 +1,19 @@
+// you can write GLSL code directly in here
+
+#if USE_ALPHA_TEST
+  uniform ALPHA_TEST_DATA {
+    float alphaThreshold;
+  };
+#endif
+
+void ALPHA_TEST (in vec4 color) {
+  #if USE_ALPHA_TEST
+    if (color.a < alphaThreshold) discard;
+  #endif
+}
+
+void ALPHA_TEST (in float alpha) {
+  #if USE_ALPHA_TEST
+    if (alpha < alphaThreshold) discard;
+  #endif
+}

+ 9 - 0
assets/chunks/builtin/internal/alpha-test.chunk.meta
View File

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.7",
+  "importer": "effect-header",
+  "imported": true,
+  "uuid": "2c3da5b6-0202-470a-a915-59f1e2968853",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 12 - 0
assets/chunks/builtin/internal/editor.meta
View File

@@ -0,0 +1,12 @@
+{
+  "ver": "1.1.0",
+  "importer": "directory",
+  "imported": true,
+  "uuid": "44fb0616-db92-4f2b-a932-3d57e8a394e6",
+  "files": [],
+  "subMetas": {},
+  "userData": {
+    "compressionType": {},
+    "isRemoteBundle": {}
+  }
+}

+ 9 - 0
assets/chunks/builtin/internal/embedded-alpha.chunk
View File

@@ -0,0 +1,9 @@
+// Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
+
+vec4 CCSampleWithAlphaSeparated(sampler2D tex, vec2 uv) {
+#if CC_USE_EMBEDDED_ALPHA
+  return vec4(texture(tex, uv).rgb, texture(tex, uv + vec2(0.0, 0.5)).r);
+#else
+  return texture(tex, uv);
+#endif
+}

+ 9 - 0
assets/chunks/builtin/internal/embedded-alpha.chunk.meta
View File

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.7",
+  "importer": "effect-header",
+  "imported": true,
+  "uuid": "ef4fb7de-9b39-4eeb-9ae8-d292ff94a452",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 69 - 0
assets/chunks/builtin/internal/particle-common.chunk
View File

@@ -0,0 +1,69 @@
+#pragma define-meta CC_RENDER_MODE range([0, 4])
+#pragma define RENDER_MODE_BILLBOARD 0
+#pragma define RENDER_MODE_STRETCHED_BILLBOARD 1
+#pragma define RENDER_MODE_HORIZONTAL_BILLBOARD 2
+#pragma define RENDER_MODE_VERTICAL_BILLBOARD 3
+#pragma define RENDER_MODE_MESH 4
+
+uniform Constants {
+  vec4 mainTiling_Offset;
+  vec4 frameTile_velLenScale;
+  vec4 scale;
+  vec4 nodeRotation;
+};
+
+#include <builtin/uniforms/cc-global>
+#include <builtin/uniforms/cc-local>
+#include <common/math/transform>
+
+out mediump vec2 uv;
+out mediump vec4 color;
+
+void computeVertPos (inout vec4 pos, vec2 vertOffset, vec4 q, vec3 s
+#if CC_RENDER_MODE == RENDER_MODE_BILLBOARD || CC_RENDER_MODE == RENDER_MODE_VERTICAL_BILLBOARD
+  , mat4 viewInv
+#endif
+#if CC_RENDER_MODE == RENDER_MODE_STRETCHED_BILLBOARD
+  , vec3 eye
+  , vec4 velocity
+  , float velocityScale
+  , float lengthScale
+  , float xIndex
+#endif
+) {
+#if CC_RENDER_MODE == RENDER_MODE_BILLBOARD
+  vec3 viewSpaceVert = vec3(vertOffset.x * s.x, vertOffset.y * s.y, 0.);
+  vec3 camX = normalize(vec3(viewInv[0][0], viewInv[1][0], viewInv[2][0]));
+  vec3 camY = normalize(vec3(viewInv[0][1], viewInv[1][1], viewInv[2][1]));
+  vec3 camZ = normalize(vec3(viewInv[0][2], viewInv[1][2], viewInv[2][2]));
+  pos.xyz += rotateInLocalSpace(viewSpaceVert, camX, camY, camZ, q);
+#elif CC_RENDER_MODE == RENDER_MODE_STRETCHED_BILLBOARD
+  vec3 camRight = normalize(cross(pos.xyz - eye, velocity.xyz)) * s.x;
+  vec3 camUp = velocity.xyz * velocityScale + normalize(velocity.xyz) * lengthScale * s.y;
+  pos.xyz += (camRight * abs(vertOffset.x) * sign(vertOffset.y)) - camUp * xIndex;
+#elif CC_RENDER_MODE == RENDER_MODE_HORIZONTAL_BILLBOARD
+  vec3 viewSpaceVert = vec3(vertOffset.x * s.x, vertOffset.y * s.y, 0.);
+  vec3 camX = vec3(1, 0, 0);
+  vec3 camY = vec3(0, 0, -1);
+  pos.xyz += rotateInLocalSpace(viewSpaceVert, camX, camY, cross(camX, camY), q);
+#elif CC_RENDER_MODE == RENDER_MODE_VERTICAL_BILLBOARD
+  vec3 viewSpaceVert = vec3(vertOffset.x * s.x, vertOffset.y * s.y, 0.);
+  rotateVecFromQuat(viewSpaceVert, q);
+  vec3 camX = normalize(vec3(cc_matView[0][0], cc_matView[1][0], cc_matView[2][0]));
+  vec3 camY = vec3(0, 1, 0);
+  vec3 offset = camX * viewSpaceVert.x + camY * viewSpaceVert.y;
+  pos.xyz += offset;
+#else
+  pos.x += vertOffset.x;
+  pos.y += vertOffset.y;
+#endif
+}
+
+vec2 computeUV (float frameIndex, vec2 vertIndex, vec2 frameTile){
+  vec2 aniUV = vec2(0, floor(frameIndex * frameTile.y));
+  aniUV.x = floor(frameIndex * frameTile.x * frameTile.y - aniUV.y * frameTile.x);
+#if CC_RENDER_MODE != RENDER_MODE_MESH
+  vertIndex.y = 1. - vertIndex.y; // if using billboard ,y must be flipped.but mesh does not,why?
+#endif
+  return (aniUV.xy + vertIndex) / vec2(frameTile.x, frameTile.y);
+}

+ 9 - 0
assets/chunks/builtin/internal/particle-common.chunk.meta
View File

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.7",
+  "importer": "effect-header",
+  "imported": true,
+  "uuid": "7a49db3a-930e-4ffc-8659-a82141dabebb",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 33 - 0
assets/chunks/builtin/internal/particle-trail.chunk
View File

@@ -0,0 +1,33 @@
+
+precision mediump float;
+#include <builtin/internal/particle-common>
+in vec3 a_position; // center position
+in vec4 a_texCoord;  // x:index y:size zw:texcoord
+in vec3 a_texCoord1; // xyz:velocity
+in vec3 a_texCoord2;
+in vec4 a_color;
+
+#if CC_DRAW_WIRE_FRAME
+  out vec3 vBarycentric;
+#endif
+
+vec4 vs_main() {
+  highp vec4 pos = vec4(a_position, 1);
+  vec4 velocity = vec4(a_texCoord1.xyz, 0);
+
+  #if !CC_USE_WORLD_SPACE
+    pos = cc_matWorld * pos;
+    velocity = cc_matWorld * velocity;
+  #endif
+
+  float vertOffset = (a_texCoord.x - 0.5) * a_texCoord.y;
+  vec3 camUp = normalize(cross(pos.xyz - cc_cameraPos.xyz, velocity.xyz));
+  pos.xyz += camUp * vertOffset;
+  pos = cc_matViewProj * pos;
+  uv = a_texCoord.zw * mainTiling_Offset.xy + mainTiling_Offset.zw;;
+  color = a_color;
+  #if CC_DRAW_WIRE_FRAME
+    vBarycentric = a_texCoord2;
+  #endif
+  return pos;
+}

+ 9 - 0
assets/chunks/builtin/internal/particle-trail.chunk.meta
View File

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.7",
+  "importer": "effect-header",
+  "imported": true,
+  "uuid": "df7d02d8-559a-4c02-9aac-3732cfc83d7a",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 389 - 0
assets/chunks/builtin/internal/particle-vs-gpu.chunk
View File

@@ -0,0 +1,389 @@
+
+precision mediump float;
+#include <common/math/transform>
+#include <builtin/internal/particle-common>
+#include <builtin/uniforms/cc-local>
+
+#pragma define CURVE_MODE_FIX 1
+#pragma define CURVE_MODE_BLEND 2
+
+#pragma define GRADIENT_MODE_FIX 1
+#pragma define GRADIENT_MODE_BLEND 2
+
+#pragma define SIMULATE_SPACE_LOCAL 0
+#pragma define SIMULATE_SPACE_WORLD 1
+
+#pragma define ANIMATION_MODE_WHOLE_SHEET 0
+#pragma define ANIMATION_MODE_SINGLE_ROW 1
+
+#pragma define COLOR_OVERTIME_RAND_OFFSET 91041.
+#pragma define FORCE_OVERTIME_RAND_OFFSET 212165.
+#pragma define ROTATION_OVERTIME_RAND_OFFSET 125292.
+#pragma define SIZE_OVERTIME_RAND_OFFSET 39825.
+#pragma define TEXTURE_ANIMATION_RAND_OFFSET 90794.
+#pragma define VELOCITY_OVERTIME_RAND_OFFSET 197866.
+
+uniform SampleConstants {
+  vec4 u_sampleInfo;
+};
+
+uniform TickConstants {
+  vec4 u_worldRot;
+  vec4 u_timeDelta;
+};
+
+in vec4 a_position_starttime; // center position,particle start time
+in vec4 a_color;
+in vec4 a_dir_life;  // xyz:particle start velocity,w:particle lifetime
+in float a_rndSeed;
+
+#if !CC_INSTANCE_PARTICLE
+  in vec4 a_size_uv;  // xyz:size, w:uv_0
+  in vec4 a_rotation_uv;  // xyz:rotation, w:uv_1
+#endif
+#if CC_INSTANCE_PARTICLE
+  in vec4 a_size_fid;  // xyz:size, w:fid
+  in vec3 a_rotation;  // xyz:rotation
+  in vec3 a_uv;
+#endif
+
+#if CC_RENDER_MODE == RENDER_MODE_MESH
+  in vec3 a_texCoord;   // mesh uv
+  in vec3 a_texCoord3;  // mesh vertices
+  in vec3 a_normal;     // mesh normal
+  in vec4 a_color1;     // mesh color
+#endif
+
+vec3 unpackCurveData (sampler2D tex, vec2 coord) {
+  vec4 a = texture(tex, coord);
+  vec4 b = texture(tex, coord + u_sampleInfo.y);
+  float c = fract(coord.x * u_sampleInfo.x);
+
+  return mix(a.xyz, b.xyz, c);
+}
+
+vec3 unpackCurveData (sampler2D tex, vec2 coord, out float w) {
+  vec4 a = texture(tex, coord);
+  vec4 b = texture(tex, coord + u_sampleInfo.y);
+  float c = fract(coord.x * u_sampleInfo.x);
+
+  w = mix(a.w, b.w, c);
+
+  return mix(a.xyz, b.xyz, c);
+}
+
+vec4 unpackGradientData (sampler2D tex, vec2 coord) {
+  return texture(tex, coord);
+}
+
+vec4 scaleAndAdd (vec4 a, vec4 b, float scale) {
+  a.x += b.x * scale;
+  a.y += b.y * scale;
+  a.z += b.z * scale;
+
+  return a;
+}
+
+// Vulkan compatible issue#9858, do not use large number (more than 100) in mod function
+float pseudoRandom(float x) {
+#if USE_VK_SHADER
+  float o = x;
+  x = mod(x - 1.0, 2.0) - 1.0;
+  float freqVar = 10.16640753482; //3.1415927*(sqrt(5.0)+1.0);
+  float y = sin(freqVar * floor(o * 0.5 - 0.5)); // some pseudorandom hash
+  float v = max(0.0, 1.0-abs(x));
+  v *= 0.7071067812; // fix sheared 'distance' measurements - but this is 1D so unsure it's even a good thing to try
+  v = y < 0.0 ? -v : v;
+  return v;
+#endif
+#if !USE_VK_SHADER
+  float seed = mod(x, 233280.);
+  float q = (seed * 9301. + 49297.) / 233280.;
+  return fract(q);
+#endif
+}
+
+#if COLOR_OVER_TIME_MODULE_ENABLE
+  uniform sampler2D color_over_time_tex0;
+  uniform ColorConstant {
+    int u_color_mode;
+  };
+#endif
+
+#if ROTATION_OVER_TIME_MODULE_ENABLE
+  uniform sampler2D rotation_over_time_tex0;
+  uniform RotationConstant {
+    int u_rotation_mode;
+  };
+#endif
+
+#if SIZE_OVER_TIME_MODULE_ENABLE
+  uniform sampler2D size_over_time_tex0;
+  uniform SizeConstant {
+    int u_size_mode;
+  };
+#endif
+
+#if FORCE_OVER_TIME_MODULE_ENABLE
+  uniform sampler2D force_over_time_tex0;
+  uniform ForceConstant {
+    int u_force_mode;
+    int u_force_space;
+  };
+#endif
+
+#if VELOCITY_OVER_TIME_MODULE_ENABLE
+  uniform sampler2D velocity_over_time_tex0;
+  uniform VelocityConstant {
+    int u_velocity_mode;
+    int u_velocity_space;
+  };
+#endif
+
+#if TEXTURE_ANIMATION_MODULE_ENABLE
+  uniform sampler2D texture_animation_tex0;
+  uniform AnimationConstant {
+    vec4 u_anim_info;
+  };
+#endif
+
+float repeat (float t, float length) {
+  return t - floor(t / length) * length;
+}
+
+vec4 rotateQuat (vec4 p, vec4 q) {
+  vec3 iv = cross(q.xyz, p.xyz) + q.w * p.xyz;
+  vec3 res = p.xyz + 2.0 * cross(q.xyz, iv);
+  return vec4(res.xyz, p.w);
+}
+
+float random (float seed) {
+  seed = mod(seed, 233280.);
+  float q = (seed * 9301. + 49297.) / 233280.;
+  return fract(q);
+}
+
+#pragma define INDENTIFY_NEG_QUAT 10.0
+
+vec4 toQuat(vec3 rotation) {
+  vec3 rotTmp = rotation;
+  float mulFactor = 1.0;
+  if (rotTmp.x > INDENTIFY_NEG_QUAT * 0.5) {
+    rotTmp.x -= INDENTIFY_NEG_QUAT;
+    mulFactor = -1.0;
+  }
+  vec4 rot = vec4(rotTmp, 0.0);
+  rot.w = mulFactor * sqrt(abs(1.0 - rot.x * rot.x - rot.y * rot.y - rot.z * rot.z));
+  return rot;
+}
+
+vec4 gpvs_main () {
+  float activeTime = u_timeDelta.x - a_position_starttime.w;
+  float normalizedTime = clamp(activeTime / a_dir_life.w, 0.0, 1.0);
+
+  vec2 timeCoord0 = vec2(normalizedTime, 0.);
+  vec2 timeCoord1 = vec2(normalizedTime, 1.);
+
+  #if CC_RENDER_MODE == RENDER_MODE_MESH
+    vec2 vertIdx = vec2(a_texCoord.x, a_texCoord.y);
+  #endif
+  #if CC_RENDER_MODE != RENDER_MODE_MESH
+    #if !CC_INSTANCE_PARTICLE
+      vec2 vertIdx = vec2(a_size_uv.w, a_rotation_uv.w);
+    #endif
+    #if CC_INSTANCE_PARTICLE
+      vec2 vertIdx = a_uv.xy;
+    #endif
+  #endif
+
+  vec4 velocity = vec4(a_dir_life.xyz, 0.);
+  vec4 pos = vec4(a_position_starttime.xyz, 1.);
+
+  // size
+  #if !CC_INSTANCE_PARTICLE
+    vec3 size = a_size_uv.xyz;
+  #endif
+  #if CC_INSTANCE_PARTICLE
+    vec3 size = a_size_fid.xyz;
+  #endif
+  #if SIZE_OVER_TIME_MODULE_ENABLE
+    if (u_size_mode == CURVE_MODE_FIX) {
+      size *= unpackCurveData(size_over_time_tex0, timeCoord0);
+    } else {
+      vec3 size_0 = unpackCurveData(size_over_time_tex0, timeCoord0);
+      vec3 size_1 = unpackCurveData(size_over_time_tex0, timeCoord1);
+      float factor_s = pseudoRandom(a_rndSeed + SIZE_OVERTIME_RAND_OFFSET);
+      size *= mix(size_0, size_1, factor_s);
+    }
+  #endif
+
+  vec3 compScale = scale.xyz * size;
+
+  // force
+  #if FORCE_OVER_TIME_MODULE_ENABLE
+    vec3 forceAnim = vec3(0.);
+    if (u_force_mode == CURVE_MODE_FIX) {
+      forceAnim = unpackCurveData(force_over_time_tex0, timeCoord0);
+    } else {
+      vec3 force_0 = unpackCurveData(force_over_time_tex0, timeCoord0);
+      vec3 force_1 = unpackCurveData(force_over_time_tex0, timeCoord1);
+      float factor_f =  pseudoRandom(a_rndSeed + FORCE_OVERTIME_RAND_OFFSET);
+      forceAnim = mix(force_0, force_1, factor_f);
+    }
+    vec4 forceTrack = vec4(forceAnim, 0.);
+    if (u_force_space == SIMULATE_SPACE_LOCAL) {
+      forceTrack = rotateQuat(forceTrack, u_worldRot);
+    }
+    velocity.xyz += forceTrack.xyz;
+  #endif
+
+  // velocity
+  #if VELOCITY_OVER_TIME_MODULE_ENABLE
+    float speedModifier0 = 1.;
+    float speedModifier1 = 1.;
+    vec3 velocityAnim = vec3(0.);
+    if (u_velocity_mode == CURVE_MODE_FIX) {
+      velocityAnim = unpackCurveData(velocity_over_time_tex0, timeCoord0, speedModifier0);
+    } else {
+      vec3 vectory_0 = unpackCurveData(velocity_over_time_tex0, timeCoord0, speedModifier0);
+      vec3 vectory_1 = unpackCurveData(velocity_over_time_tex0, timeCoord1, speedModifier1);
+      float factor_v = pseudoRandom(a_rndSeed + VELOCITY_OVERTIME_RAND_OFFSET);
+      velocityAnim = mix(vectory_0, vectory_1, factor_v);
+      speedModifier0 = mix(speedModifier0, speedModifier1, factor_v);
+    }
+    vec4 velocityTrack = vec4(velocityAnim, 0.);
+    if (u_velocity_space == SIMULATE_SPACE_LOCAL) {
+      velocityTrack = rotateQuat(velocityTrack, u_worldRot);
+    }
+    velocity.xyz += velocityTrack.xyz;
+    velocity.xyz *= speedModifier0;
+  #endif
+
+  pos.xyz += velocity.xyz * normalizedTime * a_dir_life.w;
+
+  #if !CC_USE_WORLD_SPACE
+    pos = cc_matWorld * pos;
+    #if CC_RENDER_MODE == RENDER_MODE_STRETCHED_BILLBOARD
+      velocity = rotateQuat(velocity, u_worldRot);
+    #endif
+  #endif
+
+  // rotation
+  #if !CC_INSTANCE_PARTICLE
+    vec3 startRotation = a_rotation_uv.xyz;
+  #endif
+  #if CC_INSTANCE_PARTICLE
+    vec3 startRotation = a_rotation;
+  #endif
+  #if CC_RENDER_MODE != RENDER_MODE_MESH
+    #if CC_RENDER_MODE == RENDER_MODE_BILLBOARD
+      vec3 rotEuler = startRotation.xyz;
+    #elif CC_RENDER_MODE == RENDER_MODE_STRETCHED_BILLBOARD
+      vec3 rotEuler = vec3(0.);
+    #endif
+    #if CC_RENDER_MODE != RENDER_MODE_BILLBOARD && CC_RENDER_MODE != RENDER_MODE_STRETCHED_BILLBOARD
+      vec3 rotEuler = vec3(0., 0., startRotation.z);
+    #endif
+    vec4 rot = quaternionFromEuler(rotEuler);
+  #endif
+  #if CC_RENDER_MODE == RENDER_MODE_MESH
+    vec4 rot = quaternionFromEuler(startRotation);
+  #endif
+
+  #if ROTATION_OVER_TIME_MODULE_ENABLE
+    if (u_rotation_mode == CURVE_MODE_FIX) {
+      vec3 euler = unpackCurveData(rotation_over_time_tex0, timeCoord0) * normalizedTime * a_dir_life.w;
+      vec4 quat = eulerToQuat(euler);
+      mat3 mLocal = quatToMat3(quat);
+      mat3 mStart = quatToMat3(rot);
+      rot = mat3ToQuat(mStart * mLocal);
+    } else {
+      vec3 rotation_0 = unpackCurveData(rotation_over_time_tex0, timeCoord0);
+      vec3 rotation_1 = unpackCurveData(rotation_over_time_tex0, timeCoord1);
+      float factor_r = pseudoRandom(a_rndSeed + ROTATION_OVERTIME_RAND_OFFSET);
+      vec3 euler = mix(rotation_0, rotation_1, factor_r) * normalizedTime * a_dir_life.w;
+      #if CC_RENDER_MODE == RENDER_MODE_VERTICAL_BILLBOARD || CC_RENDER_MODE == RENDER_MODE_HORIZONTAL_BILLBOARD
+        euler = vec3(0.0, 0.0, euler.z);
+      #endif
+      vec4 quat = eulerToQuat(euler);
+      mat3 mLocal = quatToMat3(quat);
+      mat3 mStart = quatToMat3(rot);
+      rot = mat3ToQuat(mStart * mLocal);
+    }
+  #endif
+
+  // color
+  #if COLOR_OVER_TIME_MODULE_ENABLE
+    if (u_color_mode == GRADIENT_MODE_FIX) {
+      color = a_color * texture(color_over_time_tex0, timeCoord0);
+    } else {
+      vec4 color_0 = texture(color_over_time_tex0, timeCoord0);
+      vec4 color_1 = texture(color_over_time_tex0, timeCoord1);
+      float factor_c = pseudoRandom(a_rndSeed + COLOR_OVERTIME_RAND_OFFSET);
+      color = a_color * mix(color_0, color_1, factor_c);
+    }
+  #endif
+  #if !COLOR_OVER_TIME_MODULE_ENABLE
+    color = a_color;
+  #endif
+
+  #if CC_RENDER_MODE != RENDER_MODE_MESH
+    vec2 cornerOffset = vec2((vertIdx - 0.5));
+
+    #if CC_RENDER_MODE == RENDER_MODE_STRETCHED_BILLBOARD
+      rot = vec4(0.0, 0.0, 0.0, 1.0);
+    #endif
+
+    computeVertPos(pos, cornerOffset, rot, compScale
+      #if CC_RENDER_MODE == RENDER_MODE_BILLBOARD || CC_RENDER_MODE == RENDER_MODE_VERTICAL_BILLBOARD
+        , cc_matViewInv
+      #endif
+      #if CC_RENDER_MODE == RENDER_MODE_STRETCHED_BILLBOARD
+        , cc_cameraPos.xyz
+        , velocity
+        , frameTile_velLenScale.z
+        , frameTile_velLenScale.w
+        #if !CC_INSTANCE_PARTICLE
+          , a_size_uv.w
+        #endif
+        #if CC_INSTANCE_PARTICLE
+          , a_uv.x
+        #endif
+      #endif
+    );
+  #endif
+  #if CC_RENDER_MODE == RENDER_MODE_MESH
+    mat3 rotMat = quatToMat3(rot);
+    mat3 nodeMat = quatToMat3(nodeRotation);
+    rotMat = nodeMat * rotMat;
+    rot = mat3ToQuat(rotMat);
+
+    mat4 xformNoScale = matrixFromRT(rot, pos.xyz);
+    mat4 xform = matFromRTS(rot, pos.xyz, compScale);
+    pos = xform * vec4(a_texCoord3, 1);
+    vec4 normal = xformNoScale * vec4(a_normal, 0);
+    color *= a_color1;
+  #endif
+
+  pos = cc_matViewProj * pos;
+
+  float frameIndex = 0.;
+  #if TEXTURE_ANIMATION_MODULE_ENABLE
+    float startFrame = 0.;
+    vec3 frameInfo = vec3(0.);
+    if (int(u_anim_info.x) == GRADIENT_MODE_FIX) {
+      frameInfo = unpackCurveData(texture_animation_tex0, timeCoord0);
+    } else {
+      vec3 frameInfo0 = unpackCurveData(texture_animation_tex0, timeCoord0);
+      vec3 frameInfo1 = unpackCurveData(texture_animation_tex0, timeCoord1);
+      float factor_t = pseudoRandom(a_rndSeed + TEXTURE_ANIMATION_RAND_OFFSET);
+      frameInfo = mix(frameInfo0, frameInfo1, factor_t);
+    }
+    startFrame = frameInfo.x / u_anim_info.y;
+    float EPSILON = 1e-6;
+    frameIndex = repeat(u_anim_info.z * (frameInfo.y + startFrame), 1. + EPSILON);
+  #endif
+  uv = computeUV(frameIndex, vertIdx, frameTile_velLenScale.xy) * mainTiling_Offset.xy + mainTiling_Offset.zw;
+
+  return pos;
+}

+ 9 - 0
assets/chunks/builtin/internal/particle-vs-gpu.chunk.meta
View File

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.7",
+  "importer": "effect-header",
+  "imported": true,
+  "uuid": "b4b00c01-eca8-4ae4-a04d-e00bbeb6d0e0",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 114 - 0
assets/chunks/builtin/internal/particle-vs-legacy.chunk
View File

@@ -0,0 +1,114 @@
+
+precision highp float;
+#include <common/math/transform>
+#include <builtin/internal/particle-common>
+#include <builtin/uniforms/cc-local>
+
+in vec3 a_texCoord1;  // size
+in vec3 a_texCoord2;  // rotation
+in vec4 a_color;
+
+in vec3 a_texCoord;  // xy:vertex index,z:frame index
+#if !CC_INSTANCE_PARTICLE
+ in vec3 a_position;  // center position
+#endif
+#if CC_INSTANCE_PARTICLE
+ in vec4 a_texCoord4; // xyz:position,z:frame index
+#endif
+
+#if CC_RENDER_MODE == RENDER_MODE_STRETCHED_BILLBOARD
+  in vec3 a_color1; // velocity.x, velocity.y, velocity.z, scale
+#endif
+
+#if CC_RENDER_MODE == RENDER_MODE_MESH
+  in vec3 a_texCoord3;  // mesh vertices
+  in vec3 a_normal;     // mesh normal
+  in vec4 a_color1;     // mesh color
+#endif
+
+vec4 lpvs_main () {
+  vec3 compScale = scale.xyz * a_texCoord1;
+  #if !CC_INSTANCE_PARTICLE
+    vec4 pos = vec4(a_position.xyz, 1);
+  #endif
+  #if CC_INSTANCE_PARTICLE
+    vec4 pos = vec4(a_texCoord4.xyz, 1);
+  #endif
+  #if CC_RENDER_MODE == RENDER_MODE_STRETCHED_BILLBOARD
+    vec4 velocity = vec4(a_color1.xyz, 0);
+  #endif
+
+  #if !CC_USE_WORLD_SPACE
+    // simulate in world space. apply cc_matWorld matrix on CPU side.
+    pos = cc_matWorld * pos;
+    #if CC_RENDER_MODE == RENDER_MODE_STRETCHED_BILLBOARD
+      velocity = cc_matWorld * velocity;
+    #endif
+  #endif
+
+  #pragma define INDENTIFY_NEG_QUAT 10.0
+
+  #if ROTATION_OVER_TIME_MODULE_ENABLE
+    vec3 rotTmp = a_texCoord2;
+    float mulFactor = 1.0;
+    if (rotTmp.x > INDENTIFY_NEG_QUAT * 0.5) {
+        rotTmp.x -= INDENTIFY_NEG_QUAT;
+        mulFactor = -1.0;
+    }
+    vec4 rot = vec4(rotTmp, 0.0);
+    rot.w = mulFactor * sqrt(abs(1.0 - rot.x * rot.x - rot.y * rot.y - rot.z * rot.z));
+  #endif
+  #if !ROTATION_OVER_TIME_MODULE_ENABLE
+    #if CC_RENDER_MODE != RENDER_MODE_MESH
+      #if CC_RENDER_MODE == RENDER_MODE_BILLBOARD
+        vec3 rotEuler = a_texCoord2;
+      #elif CC_RENDER_MODE == RENDER_MODE_STRETCHED_BILLBOARD
+        vec3 rotEuler = vec3(0.);
+      #endif
+      #if CC_RENDER_MODE != RENDER_MODE_BILLBOARD && CC_RENDER_MODE != RENDER_MODE_STRETCHED_BILLBOARD
+        vec3 rotEuler = vec3(0., 0., a_texCoord2.z);
+      #endif
+      vec4 rot = quaternionFromEuler(rotEuler);
+    #endif
+    #if CC_RENDER_MODE == RENDER_MODE_MESH
+      vec4 rot = quaternionFromEuler(a_texCoord2);
+    #endif
+  #endif
+
+  #if CC_RENDER_MODE != RENDER_MODE_MESH
+    vec2 cornerOffset = vec2((a_texCoord.xy - 0.5));
+
+    #if CC_RENDER_MODE == RENDER_MODE_BILLBOARD || CC_RENDER_MODE == RENDER_MODE_VERTICAL_BILLBOARD
+      computeVertPos(pos, cornerOffset, rot, compScale, cc_matViewInv);
+    #elif CC_RENDER_MODE == RENDER_MODE_STRETCHED_BILLBOARD
+      computeVertPos(pos, cornerOffset, rot, compScale, cc_cameraPos.xyz, velocity, frameTile_velLenScale.z, frameTile_velLenScale.w, a_texCoord.x);
+    #elif RENDER_MODE_HORIZONTAL_BILLBOARD
+      computeVertPos(pos, cornerOffset, rot, compScale);
+    #endif
+
+    color = a_color;
+  #endif
+  #if CC_RENDER_MODE == RENDER_MODE_MESH
+    mat3 rotMat = quatToMat3(rot);
+    mat3 nodeMat = quatToMat3(nodeRotation);
+    rotMat = nodeMat * rotMat;
+    rot = mat3ToQuat(rotMat);
+
+    mat4 xformNoScale = matrixFromRT(rot, pos.xyz);
+    mat4 xform = matFromRTS(rot, pos.xyz, compScale);
+    pos = xform * vec4(a_texCoord3, 1);
+    vec4 normal = xformNoScale * vec4(a_normal, 0);
+    color = a_color * a_color1;
+  #endif
+
+  #if !CC_INSTANCE_PARTICLE
+    uv = computeUV(a_texCoord.z, a_texCoord.xy, frameTile_velLenScale.xy) * mainTiling_Offset.xy + mainTiling_Offset.zw;
+  #endif
+  #if CC_INSTANCE_PARTICLE
+    uv = computeUV(a_texCoord4.w, a_texCoord.xy, frameTile_velLenScale.xy) * mainTiling_Offset.xy + mainTiling_Offset.zw;
+  #endif
+
+  pos = cc_matViewProj * pos;
+
+  return pos;
+}

+ 9 - 0
assets/chunks/builtin/internal/particle-vs-legacy.chunk.meta
View File

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.7",
+  "importer": "effect-header",
+  "imported": true,
+  "uuid": "6e1b48cb-69c8-448c-8055-69ab9793fbab",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 9 - 0
assets/chunks/builtin/internal/sprite-common.chunk
View File

@@ -0,0 +1,9 @@
+
+struct SpriteVertexData {
+  vec4 position; // world position
+  vec4 color; // vertex color
+};
+
+struct SpriteFragmentData {
+  vec2 uv; // sampling UV
+};

+ 9 - 0
assets/chunks/builtin/internal/sprite-common.chunk.meta
View File

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.7",
+  "importer": "effect-header",
+  "imported": true,
+  "uuid": "35822e78-bb35-405f-87bd-d42af6ac9ede",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 4 - 0
assets/chunks/builtin/internal/sprite-texture.chunk
View File

@@ -0,0 +1,4 @@
+// Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
+
+#pragma builtin(local)
+layout(set = 2, binding = 12) uniform sampler2D cc_spriteTexture;

+ 9 - 0
assets/chunks/builtin/internal/sprite-texture.chunk.meta
View File

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.7",
+  "importer": "effect-header",
+  "imported": true,
+  "uuid": "4b48672e-e044-4035-9029-13afb50c1aee",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 12 - 0
assets/chunks/builtin/uniforms.meta
View File

@@ -0,0 +1,12 @@
+{
+  "ver": "1.2.0",
+  "importer": "directory",
+  "imported": true,
+  "uuid": "d81f2dfc-d5a9-49b9-a4ce-84a3cec1707a",
+  "files": [],
+  "subMetas": {},
+  "userData": {
+    "compressionType": {},
+    "isRemoteBundle": {}
+  }
+}

+ 14 - 0
assets/chunks/builtin/uniforms/cc-csm.chunk
View File

@@ -0,0 +1,14 @@
+// Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
+
+#pragma define NUMCASCADES 4
+#pragma builtin(global)
+layout(set = 0, binding = 3) uniform CCCSM {
+  highp vec4 cc_csmViewDir0[NUMCASCADES]; //[0].w->layer blank threshold
+  highp vec4 cc_csmViewDir1[NUMCASCADES]; //[i].w->layer split camera near
+  highp vec4 cc_csmViewDir2[NUMCASCADES]; //[i].w->layer split camera far
+  highp vec4 cc_csmAtlas[NUMCASCADES];
+  highp mat4 cc_matCSMViewProj[NUMCASCADES];
+  highp vec4 cc_csmProjDepthInfo[NUMCASCADES];
+  highp vec4 cc_csmProjInfo[NUMCASCADES];
+  highp vec4 cc_csmSplitsInfo;            // x-> Layers.skirtRange
+};

+ 9 - 0
assets/chunks/builtin/uniforms/cc-csm.chunk.meta
View File

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.7",
+  "importer": "effect-header",
+  "imported": true,
+  "uuid": "c3e3500f-370c-4da1-92f9-d0d9fd806bd8",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 6 - 0
assets/chunks/builtin/uniforms/cc-diffusemap.chunk
View File

@@ -0,0 +1,6 @@
+// Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
+
+#pragma define-meta CC_USE_DIFFUSEMAP range([0, 2])
+
+#pragma builtin(global)
+layout(set = 0, binding = 7) uniform samplerCube cc_diffuseMap;

+ 9 - 0
assets/chunks/builtin/uniforms/cc-diffusemap.chunk.meta
View File

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.7",
+  "importer": "effect-header",
+  "imported": true,
+  "uuid": "17e8e047-4c5e-412c-85c8-a76a98742f2a",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 8 - 0
assets/chunks/builtin/uniforms/cc-environment.chunk
View File

@@ -0,0 +1,8 @@
+// Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
+
+#pragma define IBL_RGBA 1
+#pragma define IBL_RGBE 2
+#pragma define-meta CC_USE_IBL range([0, 2])
+
+#pragma builtin(global)
+layout(set = 0, binding = 5) uniform samplerCube cc_environment;

+ 9 - 0
assets/chunks/builtin/uniforms/cc-environment.chunk.meta
View File

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.7",
+  "importer": "effect-header",
+  "imported": true,
+  "uuid": "cd94308c-6959-4671-9dcb-6c58342273e2",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 18 - 0
assets/chunks/builtin/uniforms/cc-forward-light.chunk
View File

@@ -0,0 +1,18 @@
+// Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
+
+#if CC_PIPELINE_TYPE == CC_PIPELINE_TYPE_FORWARD
+  #define LIGHTS_PER_PASS 1
+#else
+  #define LIGHTS_PER_PASS 10
+#endif
+
+#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 0
+#pragma builtin(local)
+layout(set = 2, binding = 1) uniform CCForwardLight {
+  highp vec4 cc_lightPos[LIGHTS_PER_PASS]; // xyz: pos, w: valid light type[0: directional light, 1: sphere light, 2: spot light, 3: point light, 4: ranged dir light, 5: unkown]
+  vec4 cc_lightColor[LIGHTS_PER_PASS]; // xyz: color, w: intensity
+  vec4 cc_lightSizeRangeAngle[LIGHTS_PER_PASS]; // x: size, y: range, z: cos(half outterAngle), w: enable shadow; ranged dir light: xyz is right
+  vec4 cc_lightDir[LIGHTS_PER_PASS]; // xyz: dir, w: unused
+  vec4 cc_lightBoundingSizeVS[LIGHTS_PER_PASS]; //xyz: ranged dir light node half scale, w: spot light angle attenuation strength
+};
+#endif

+ 9 - 0
assets/chunks/builtin/uniforms/cc-forward-light.chunk.meta
View File

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.7",
+  "importer": "effect-header",
+  "imported": true,
+  "uuid": "5e0f5e6e-5008-497f-b223-4e5f1801d8fd",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 36 - 0
assets/chunks/builtin/uniforms/cc-global.chunk
View File

@@ -0,0 +1,36 @@
+// Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
+
+// have to specify precisions explicitly
+// if shared among stages with different precisions
+#pragma builtin(global)
+layout(set = 0, binding = 0) uniform CCGlobal {
+  highp   vec4 cc_time; // x: global time since started in seconds, y: delta time for current frame, z: total frames since started, w: fractinal part of x, better precious, should be used with uv animation
+  mediump vec4 cc_screenSize; // xy: screen size, zw: inverse screen size
+  mediump vec4 cc_nativeSize; // xy: shading size, zw: inverse shading size
+  mediump vec4 cc_probeInfo; // x: reflection probe count
+
+  mediump vec4 cc_debug_view_mode; // x: single mode, yzw: composite and misc flags combination value
+};
+
+#pragma builtin(global)
+layout(set = 0, binding = 1) uniform CCCamera {
+  highp   mat4 cc_matView; // view matrix
+  highp   mat4 cc_matViewInv; // inverse view matrix
+  highp   mat4 cc_matProj; // projection matrix
+  highp   mat4 cc_matProjInv; // inverse projection matrix
+  highp   mat4 cc_matViewProj; // view-projection matrix
+  highp   mat4 cc_matViewProjInv; // inverse view-projection matrix
+  highp   vec4 cc_cameraPos; // xyz: camera position w: flip NDC sign
+  mediump vec4 cc_surfaceTransform; // x: surface transform y: camera usage zw: skybox rotation angle cos/sin value
+  mediump vec4 cc_screenScale; // xy: screen scale, zw: inverse screen scale
+  mediump vec4 cc_exposure; // x: exposure, y: inverse exposure, z: HDR flag, w: inverse standard exposure value
+  mediump vec4 cc_mainLitDir; // xyz: main direcitonal light direction, w: enable shadow
+  mediump vec4 cc_mainLitColor; // xyz: main direcitonal light color, w: intensity
+  mediump vec4 cc_ambientSky; //xyz: sky illumination color, w: intensity
+  mediump vec4 cc_ambientGround; // xyz: ground albedo color, w: envmap LOD
+  mediump vec4 cc_fogColor; // xyz: global fog color
+  mediump vec4 cc_fogBase; // xyz: fogStart, fogEnd, fogDensity
+  mediump vec4 cc_fogAdd; // xyz: fogTop, fogRange, fogAtten
+  mediump vec4 cc_nearFar; // xy: frustum near, frustum far z: clipspace minz (vulkan: 0 metal: 0 other: -1)
+  mediump vec4 cc_viewPort; // xyzw: camera view port, default(0, 0, 1, 1)
+};

+ 9 - 0
assets/chunks/builtin/uniforms/cc-global.chunk.meta
View File

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.7",
+  "importer": "effect-header",
+  "imported": true,
+  "uuid": "1ea907a3-a36e-432a-ae38-af712c77aaad",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 2 - 0
assets/chunks/builtin/uniforms/cc-light-map.chunk
View File

@@ -0,0 +1,2 @@
+#pragma builtin(local)
+layout(set = 2, binding = 11) uniform sampler2D cc_lightingMap;

+ 9 - 0
assets/chunks/builtin/uniforms/cc-light-map.chunk.meta
View File

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.7",
+  "importer": "effect-header",
+  "imported": true,
+  "uuid": "fa1c0cd1-03c6-45dd-8294-bf7a1e21aad4",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 5 - 0
assets/chunks/builtin/uniforms/cc-local-batched.chunk
View File

@@ -0,0 +1,5 @@
+// Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
+
+#if !USE_INSTANCING
+  #include <builtin/uniforms/cc-local>
+#endif

+ 9 - 0
assets/chunks/builtin/uniforms/cc-local-batched.chunk.meta
View File

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.7",
+  "importer": "effect-header",
+  "imported": true,
+  "uuid": "21b24bc9-a158-488e-b27c-b98a461fb438",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 13 - 0
assets/chunks/builtin/uniforms/cc-local.chunk
View File

@@ -0,0 +1,13 @@
+// Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
+
+#pragma builtin(local)
+layout(set = 2, binding = 0) uniform CCLocal {
+  highp mat4 cc_matWorld;
+  highp mat4 cc_matWorldIT;
+  highp vec4 cc_lightingMapUVParam;
+  highp vec4 cc_localShadowBias; // x:shadow bias, y:shadow normal bias, z: reflection probe id, w: blend reflection probe id
+  highp vec4 cc_reflectionProbeData1; // xyzw: plane                      or xyz: cube center
+  highp vec4 cc_reflectionProbeData2; // x: planar reflection depth scale or xyz: cube box half size, w: isRGBE(1000) and mipCount
+  highp vec4 cc_reflectionProbeBlendData1; //xyz: blend cube center w:blend weight
+  highp vec4 cc_reflectionProbeBlendData2; //xyz: blend cube box half size, w: isRGBE(1000) and mipCount
+};

+ 9 - 0
assets/chunks/builtin/uniforms/cc-local.chunk.meta
View File

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.7",
+  "importer": "effect-header",
+  "imported": true,
+  "uuid": "e835c2d5-a377-4197-bdb8-382037573494",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 24 - 0
assets/chunks/builtin/uniforms/cc-morph.chunk
View File

@@ -0,0 +1,24 @@
+// Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
+
+#pragma define-meta CC_MORPH_TARGET_COUNT range([2, 8])
+
+#pragma builtin(local)
+layout(set = 2, binding = 4) uniform CCMorph {
+  vec4 cc_displacementWeights[15];
+  vec4 cc_displacementTextureInfo;
+};
+
+#if CC_MORPH_TARGET_HAS_POSITION
+  #pragma builtin(local)
+  layout(set = 2, binding = 8) uniform sampler2D cc_PositionDisplacements;
+#endif
+
+#if CC_MORPH_TARGET_HAS_NORMAL
+  #pragma builtin(local)
+  layout(set = 2, binding = 9) uniform sampler2D cc_NormalDisplacements;
+#endif
+
+#if CC_MORPH_TARGET_HAS_TANGENT
+  #pragma builtin(local)
+  layout(set = 2, binding = 10) uniform sampler2D cc_TangentDisplacements;
+#endif

+ 9 - 0
assets/chunks/builtin/uniforms/cc-morph.chunk.meta
View File

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.7",
+  "importer": "effect-header",
+  "imported": true,
+  "uuid": "94d19070-32c6-4900-a288-2258fda37f29",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 14 - 0
assets/chunks/builtin/uniforms/cc-reflection-probe.chunk
View File

@@ -0,0 +1,14 @@
+// Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
+
+#pragma builtin(local)
+layout(set = 2, binding = 13) uniform samplerCube cc_reflectionProbeCubemap;
+
+#pragma builtin(local)
+layout(set = 2, binding = 14) uniform sampler2D cc_reflectionProbePlanarMap;
+
+#pragma builtin(local)
+layout(set = 2, binding = 15) uniform sampler2D cc_reflectionProbeDataMap;
+
+// Disable proble blend for WebGPU
+// #pragma builtin(local)
+// layout(set = 2, binding = 16) uniform samplerCube cc_reflectionProbeBlendCubemap;

+ 9 - 0
assets/chunks/builtin/uniforms/cc-reflection-probe.chunk.meta
View File

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.7",
+  "importer": "effect-header",
+  "imported": true,
+  "uuid": "960cff1c-912a-47d1-a3d9-9a25a9568508",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 12 - 0
assets/chunks/builtin/uniforms/cc-sh.chunk
View File

@@ -0,0 +1,12 @@
+// Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
+
+#pragma builtin(local)
+layout(set = 2, binding = 6) uniform CCSH {
+  vec4 cc_sh_linear_const_r;
+  vec4 cc_sh_linear_const_g;
+  vec4 cc_sh_linear_const_b;
+  vec4 cc_sh_quadratic_r;
+  vec4 cc_sh_quadratic_g;
+  vec4 cc_sh_quadratic_b;
+  vec4 cc_sh_quadratic_a;
+};

+ 9 - 0
assets/chunks/builtin/uniforms/cc-sh.chunk.meta
View File

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.7",
+  "importer": "effect-header",
+  "imported": true,
+  "uuid": "2c62fe23-f1f4-49f1-a08f-e5e6c650682f",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 5 - 0
assets/chunks/builtin/uniforms/cc-shadow-map.chunk
View File

@@ -0,0 +1,5 @@
+#pragma builtin(global)
+layout(set = 0, binding = 4) uniform highp sampler2D cc_shadowMap;
+
+#pragma builtin(global)
+layout(set = 0, binding = 6) uniform highp sampler2D cc_spotShadowMap;

+ 9 - 0
assets/chunks/builtin/uniforms/cc-shadow-map.chunk.meta
View File

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.7",
+  "importer": "effect-header",
+  "imported": true,
+  "uuid": "e8411010-e411-43ab-8f2e-4f4865dca4cf",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 16 - 0
assets/chunks/builtin/uniforms/cc-shadow.chunk
View File

@@ -0,0 +1,16 @@
+// Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
+
+#pragma define NUMCASCADES 4
+#pragma builtin(global)
+layout(set = 0, binding = 2) uniform CCShadow {
+  highp mat4 cc_matLightView;
+  highp mat4 cc_matLightViewProj;
+  highp vec4 cc_shadowInvProjDepthInfo; // x -> cc_matLightInvProj[10]([2][2]); y -> cc_matLightInvProj[14]([2][3]); z -> cc_matLightInvProj[11]([3][2]); w -> cc_matLightInvProj[15]([3][3]);
+  highp vec4 cc_shadowProjDepthInfo;    // x -> cc_matLightProj[10]([2][2]);    y -> cc_matLightProj[14]([2][3]);    z -> cc_matLightProj[11]([3][2]);    w -> cc_matLightProj[15]([3][3]);
+  highp vec4 cc_shadowProjInfo;         // x -> cc_matLightProj[0];             y -> cc_matLightProj[5];             z -> 1.0 / cc_matLightProj[0];        w -> 1.0 / cc_matLightProj[5];
+  mediump vec4 cc_shadowNFLSInfo;       // x -> near(N);      y -> far(F);       z -> reserved 0;   w -> shadow saturation(S);
+  mediump vec4 cc_shadowWHPBInfo;       // x -> width(W);     y -> height(H);    z -> pcf(P);        w -> bias(B);
+  mediump vec4 cc_shadowLPNNInfo;       // x -> lightType(L); y -> isPacking(P); z -> normalBias(N); w -> CSM level(N);
+  lowp vec4 cc_shadowColor;
+  mediump vec4 cc_planarNDInfo;         // xyz -> normalized plane (N);  w -> plane (D);
+};

+ 9 - 0
assets/chunks/builtin/uniforms/cc-shadow.chunk.meta
View File

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.7",
+  "importer": "effect-header",
+  "imported": true,
+  "uuid": "69f8ecd8-cdc9-4655-a6ec-d39dacdffc2f",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 43 - 0
assets/chunks/builtin/uniforms/cc-skinning.chunk
View File

@@ -0,0 +1,43 @@
+// Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
+
+#pragma extension([GL_EXT_shader_explicit_arithmetic_types_int32, __VERSION__ > 310, require])
+
+#if CC_USE_BAKED_ANIMATION
+  #pragma builtin(local)
+  layout(set = 2, binding = 3) uniform CCSkinningTexture {
+    highp vec4 cc_jointTextureInfo; // length, totalJoints, offset, invLength
+  };
+  #pragma builtin(local)
+  layout(set = 2, binding = 2) uniform CCSkinningAnimation {
+    highp vec4 cc_jointAnimInfo; // frameID
+  };
+  #pragma builtin(local)
+  layout(set = 2, binding = 7) uniform highp sampler2D cc_jointTexture;
+  /**
+   * Although tempting, don't opt the offset arithmetics out to CPU (could
+   * be reduced to a single MAD). The enlarged numerical range could require
+   * more precision than what's actually provided on some devices.
+   */
+  void CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)
+  {
+    #if USE_INSTANCING
+      highp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;
+    #else
+      highp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;
+    #endif
+    invSize = cc_jointTextureInfo.w;
+    highp float tempY = floor(temp * invSize);
+    x = floor(temp - tempY * cc_jointTextureInfo.x);
+    y = (tempY + 0.5) * invSize;
+  }
+#else
+  #if CC_USE_REAL_TIME_JOINT_TEXTURE
+    #pragma builtin(local)
+    layout(set = 2, binding = 7) uniform highp sampler2D cc_realtimeJoint;
+  #else
+    #pragma builtin(local)
+    layout(set = 2, binding = 3) uniform CCSkinning {
+      highp vec4 cc_joints[CC_JOINT_UNIFORM_CAPACITY * 3];
+    };
+  #endif
+#endif

+ 9 - 0
assets/chunks/builtin/uniforms/cc-skinning.chunk.meta
View File

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.7",
+  "importer": "effect-header",
+  "imported": true,
+  "uuid": "99488fd6-220b-4d13-9a41-8b9439cd3944",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 7 - 0
assets/chunks/builtin/uniforms/cc-world-bound.chunk
View File

@@ -0,0 +1,7 @@
+// Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
+
+#pragma builtin(local)
+layout(set = 2, binding = 0) uniform CCWorldBound {
+  highp vec4 cc_worldBoundCenter;
+  highp vec4 cc_worldBoundHalfExtents;
+};

+ 9 - 0
assets/chunks/builtin/uniforms/cc-world-bound.chunk.meta
View File

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.7",
+  "importer": "effect-header",
+  "imported": true,
+  "uuid": "669458fe-c428-40cd-8575-51607aa8edbc",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 12 - 0
assets/chunks/common.meta
View File

@@ -0,0 +1,12 @@
+{
+  "ver": "1.2.0",
+  "importer": "directory",
+  "imported": true,
+  "uuid": "5dce7e3d-7c28-4f47-974c-e6904aeada37",
+  "files": [],
+  "subMetas": {},
+  "userData": {
+    "compressionType": {},
+    "isRemoteBundle": {}
+  }
+}

+ 12 - 0
assets/chunks/common/color.meta
View File

@@ -0,0 +1,12 @@
+{
+  "ver": "1.2.0",
+  "importer": "directory",
+  "imported": true,
+  "uuid": "280afbca-66a6-4948-9a32-a207b2415f6d",
+  "files": [],
+  "subMetas": {},
+  "userData": {
+    "compressionType": {},
+    "isRemoteBundle": {}
+  }
+}

+ 10 - 0
assets/chunks/common/color/aces.chunk
View File

@@ -0,0 +1,10 @@
+
+vec3 ACESToneMap (vec3 color) {
+  color = min(color, vec3(8.0)); // guard against overflow
+  const float A = 2.51;
+  const float B = 0.03;
+  const float C = 2.43;
+  const float D = 0.59;
+  const float E = 0.14;
+  return (color * (A * color + B)) / (color * (C * color + D) + E);
+}

+ 9 - 0
assets/chunks/common/color/aces.chunk.meta
View File

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.7",
+  "importer": "effect-header",
+  "imported": true,
+  "uuid": "7efbe295-0202-4979-8cda-6cfe35e086cf",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 27 - 0
assets/chunks/common/color/gamma.chunk
View File

@@ -0,0 +1,27 @@
+// Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
+
+// #pragma define SRGBToLinear(gamma) pow(gamma, vec3(2.2))
+vec3 SRGBToLinear (vec3 gamma) {
+#ifdef CC_USE_SURFACE_SHADER
+  #if CC_USE_DEBUG_VIEW == CC_SURFACES_DEBUG_VIEW_COMPOSITE_AND_MISC && CC_SURFACES_ENABLE_DEBUG_VIEW
+    if (!IS_DEBUG_VIEW_COMPOSITE_ENABLE_GAMMA_CORRECTION) {
+      return gamma;
+    }
+  #endif
+#endif
+
+  return gamma * gamma;
+}
+
+// #pragma define LinearToSRGB(linear) pow(linear, vec3(0.454545))
+vec3 LinearToSRGB(vec3 linear) {
+#ifdef CC_USE_SURFACE_SHADER
+  #if CC_USE_DEBUG_VIEW == CC_SURFACES_DEBUG_VIEW_COMPOSITE_AND_MISC && CC_SURFACES_ENABLE_DEBUG_VIEW
+    if (!IS_DEBUG_VIEW_COMPOSITE_ENABLE_GAMMA_CORRECTION) {
+      return linear;
+    }
+  #endif
+#endif
+
+  return sqrt(linear);
+}

+ 9 - 0
assets/chunks/common/color/gamma.chunk.meta
View File

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.7",
+  "importer": "effect-header",
+  "imported": true,
+  "uuid": "bb213412-2e68-43b3-9de5-73ca332acace",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 20 - 0
assets/chunks/common/color/tone-mapping.chunk
View File

@@ -0,0 +1,20 @@
+// Copyright (c) 2017-2023 Xiamen Yaji Software Co., Ltd.
+
+#include <common/color/aces>
+
+vec3 HDRToLDR(vec3 color)
+{
+  #if CC_USE_HDR
+    #if CC_USE_DEBUG_VIEW == CC_SURFACES_DEBUG_VIEW_COMPOSITE_AND_MISC && CC_SURFACES_ENABLE_DEBUG_VIEW
+      if (IS_DEBUG_VIEW_COMPOSITE_ENABLE_TONE_MAPPING)
+    #endif
+    {
+    // linear exposure has already applied to light intensity
+    #if CC_TONE_MAPPING_TYPE == HDR_TONE_MAPPING_ACES
+      color.rgb = ACESToneMap(color.rgb);
+    #endif
+    }
+  #endif
+	
+  return color;
+}

+ 9 - 0
assets/chunks/common/color/tone-mapping.chunk.meta
View File

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.7",
+  "importer": "effect-header",
+  "imported": true,
+  "uuid": "077c9168-e907-405b-b7f6-b4d5f68ced4a",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 94 - 0
assets/chunks/common/common-define.chunk
View File

@@ -0,0 +1,94 @@
+// Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
+
+// common module
+
+// constant value
+#define QUATER_PI         0.78539816340
+#define HALF_PI           1.57079632679
+#define PI                3.14159265359
+#define PI2               6.28318530718
+#define PI4               12.5663706144
+
+#define INV_QUATER_PI     1.27323954474
+#define INV_HALF_PI       0.63661977237
+#define INV_PI            0.31830988618
+#define INV_PI2           0.15915494309
+#define INV_PI4           0.07957747155
+
+#define EPSILON           1e-6
+#define EPSILON_LOWP      1e-4
+#define LOG2              1.442695
+#define EXP_VALUE         2.71828183
+#define FP_MAX            65504.0
+#define FP_SCALE          0.0009765625
+#define FP_SCALE_INV      1024.0
+#define GRAY_VECTOR       vec3(0.299, 0.587, 0.114)
+
+// common functions
+#pragma define equalf(data1, data2) (abs(float(data1) - float(data2)) < EPSILON)
+#pragma define equalf_lowp(data1, data2) (abs(float(data1) - float(data2)) < EPSILON_LOWP)
+#pragma define equalf_epsilon(data1, data2, epsilonValue) (abs(float(data1) - float(data2)) < epsilonValue)
+#pragma define clip(value) if(value < 0.0) discard;
+#pragma define lerp(value1, value2, value2Multiplier) mix(value1, value2, value2Multiplier)
+
+float saturate(float value) { return clamp(value, 0.0, 1.0); }
+vec2 saturate(vec2 value) { return clamp(value, vec2(0.0), vec2(1.0)); }
+vec3 saturate(vec3 value) { return clamp(value, vec3(0.0), vec3(1.0)); }
+vec4 saturate(vec4 value) { return clamp(value, vec4(0.0), vec4(1.0)); }
+
+
+// runtime constants
+#pragma define-meta CC_DEVICE_SUPPORT_FLOAT_TEXTURE default(1)
+#pragma define-meta CC_DEVICE_MAX_FRAGMENT_UNIFORM_VECTORS default(1024)
+#pragma define-meta CC_DEVICE_MAX_VERTEX_UNIFORM_VECTORS default(1024)
+#pragma define-meta CC_EFFECT_USED_VERTEX_UNIFORM_VECTORS default(128)
+#pragma define-meta CC_EFFECT_USED_FRAGMENT_UNIFORM_VECTORS default(128)
+#pragma define-meta CC_DEVICE_CAN_BENEFIT_FROM_INPUT_ATTACHMENT default(0)
+#pragma define-meta CC_PLATFORM_ANDROID_AND_WEBGL default(0)
+#pragma define-meta CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES default(0)
+
+// When sampling RTs, Y-flip is needed if the screen space sign Y is positive (pointing upwards)
+#pragma define CC_HANDLE_RT_SAMPLE_FLIP(uv) uv = cc_cameraPos.w > 1.0 ? vec2(uv.x, 1.0 - uv.y) : uv
+#pragma define CC_HANDLE_GET_CLIP_FLIP(uv) uv = cc_cameraPos.w == 0.0 ? vec2(uv.x, -uv.y) : uv
+#pragma define CC_HANDLE_CLIP_FLIP_FROM_VAL(uv, flip) uv = flip == 0.0 ? vec2(uv.x, -uv.y) : uv
+// CC_USE_LIGHTMAP Values
+#define LIGHT_MAP_TYPE_DISABLED 0
+#define LIGHT_MAP_TYPE_ALL_IN_ONE 1
+#define LIGHT_MAP_TYPE_INDIRECT_OCCLUSION 2
+
+// CC_USE_REFLECTION_PROBE Values
+#define REFLECTION_PROBE_TYPE_NONE 0
+#define REFLECTION_PROBE_TYPE_CUBE 1
+#define REFLECTION_PROBE_TYPE_PLANAR 2
+#define REFLECTION_PROBE_TYPE_BLEND 3
+#define REFLECTION_PROBE_TYPE_BLEND_AND_SKYBOX 4
+#pragma define IS_REFLECTION_PROBE_USE_RGBE(mipcount) mipcount > 1000.0
+#pragma define RESTORE_REFLECTION_PROBE_MIP_COUNT(mipcount) if (mipcount > 1000.0) mipcount -= 1000.0
+
+// Light Type
+#define LIGHT_TYPE_DIRECTIONAL 0.0
+#define LIGHT_TYPE_SPHERE 1.0
+#define LIGHT_TYPE_SPOT 2.0
+#define LIGHT_TYPE_POINT 3.0
+#define LIGHT_TYPE_RANGED_DIRECTIONAL 4.0
+
+#define IS_DIRECTIONAL_LIGHT(light_type) equalf_lowp(light_type, LIGHT_TYPE_DIRECTIONAL)
+#define IS_SPHERE_LIGHT(light_type) equalf_lowp(light_type, LIGHT_TYPE_SPHERE)
+#define IS_SPOT_LIGHT(light_type) equalf_lowp(light_type, LIGHT_TYPE_SPOT)
+#define IS_POINT_LIGHT(light_type) equalf_lowp(light_type, LIGHT_TYPE_POINT)
+#define IS_RANGED_DIRECTIONAL_LIGHT(light_type) equalf_lowp(light_type, LIGHT_TYPE_RANGED_DIRECTIONAL)
+
+// CC_TONE_MAPPING_TYPE Values
+#define TONE_MAPPING_ACES 0
+#define TONE_MAPPING_LINEAR 1
+
+// Material
+#define SURFACES_MAX_TRANSMIT_DEPTH_VALUE 999999.0
+
+// CC_USE_DEBUG_VIEW Values
+#ifndef CC_SURFACES_DEBUG_VIEW_SINGLE
+  #define CC_SURFACES_DEBUG_VIEW_SINGLE 1
+#endif
+#ifndef CC_SURFACES_DEBUG_VIEW_COMPOSITE_AND_MISC
+  #define CC_SURFACES_DEBUG_VIEW_COMPOSITE_AND_MISC 2
+#endif

+ 9 - 0
assets/chunks/common/common-define.chunk.meta
View File

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.7",
+  "importer": "effect-header",
+  "imported": true,
+  "uuid": "9d86a3e4-ec06-4e51-ba68-45f2b7739fbb",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 12 - 0
assets/chunks/common/data.meta
View File

@@ -0,0 +1,12 @@
+{
+  "ver": "1.2.0",
+  "importer": "directory",
+  "imported": true,
+  "uuid": "23b6d452-21a8-41c8-a910-fdb93eb21c61",
+  "files": [],
+  "subMetas": {},
+  "userData": {
+    "compressionType": {},
+    "isRemoteBundle": {}
+  }
+}

+ 84 - 0
assets/chunks/common/data/packing.chunk
View File

@@ -0,0 +1,84 @@
+// Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
+
+// float <--> RGBA8
+vec4 packDepthToRGBA (float depth) {
+  vec4 ret = vec4(1.0, 255.0, 65025.0, 16581375.0) * depth;
+  ret = fract(ret);
+  ret -= vec4(ret.yzw, 0.0) / 255.0;
+  return ret;
+}
+
+#pragma define unpackRGBAToDepth(color) dot(color, vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0))
+
+
+// float <--> binary bits, max 8bits per float
+#define UnpackBitFromFloat(value, bit) (mod(floor(value / pow(10.0, float(bit))), 10.0) > 0.0)
+
+
+// highp <--> 2 * mediump
+#pragma define DEFINE_PACK_HIGHP_FUNC(type) \
+highp type unpackHighpData (type mainPart, type modPart) {\
+  highp type data = mainPart;\
+  return data + modPart;\
+}\
+void packHighpData (out type mainPart, out type modPart, highp type data) {\
+  mainPart = fract(data);\
+  modPart = data - mainPart;\
+}\
+highp type unpackHighpData (type mainPart, type modPart, const float modValue) {\
+  highp type data = mainPart * modValue;\
+  return data + modPart * modValue;\
+}\
+void packHighpData (out type mainPart, out type modPart, highp type data, const float modValue) {\
+  highp type divide = data / modValue;\
+  mainPart = floor(divide);\
+  modPart = (data - mainPart * modValue) / modValue;\
+}
+
+DEFINE_PACK_HIGHP_FUNC(float)
+DEFINE_PACK_HIGHP_FUNC(vec2)
+DEFINE_PACK_HIGHP_FUNC(vec3)
+DEFINE_PACK_HIGHP_FUNC(vec4)
+
+// Use these macros to define and assign high precision values in fs structs, otherwise will loss precisions with android + webgl platform
+#pragma define HIGHP_VALUE_STRUCT_DEFINE(type, name) \
+#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\
+type name, name##_fract_part;\
+#else\
+type name;\
+#endif\
+#pragma // empty pragma trick to get rid of trailing semicolons at effect compile time
+
+// used for large range such as position
+#pragma define HIGHP_VALUE_FROM_STRUCT_DEFINED(value, defined) \
+#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\
+value = unpackHighpData(defined, defined##_fract_part);\
+#else\
+value = defined;\
+#endif\
+#pragma // empty pragma trick to get rid of trailing semicolons at effect compile time
+
+#pragma define HIGHP_VALUE_TO_STRUCT_DEFINED(value, defined) \
+#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\
+packHighpData(defined, defined##_fract_part, value);\
+#else\
+defined = value;\
+#endif\
+#pragma // empty pragma trick to get rid of trailing semicolons at effect compile time
+
+// used for small range such as -1-1 normalized
+#pragma define HIGHP_VALUE_FROM_STRUCT_DEFINED_SMALL_RANGE(value, defined) \
+#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\
+value = unpackHighpData(defined, defined##_fract_part, 1000.0);\
+#else\
+value = defined;\
+#endif\
+#pragma // empty pragma trick to get rid of trailing semicolons at effect compile time
+
+#pragma define HIGHP_VALUE_TO_STRUCT_DEFINED_SMALL_RANGE(value, defined) \
+#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\
+packHighpData(defined, defined##_fract_part, value, 1000.0);\
+#else\
+defined = value;\
+#endif\
+#pragma // empty pragma trick to get rid of trailing semicolons at effect compile time

+ 9 - 0
assets/chunks/common/data/packing.chunk.meta
View File

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.7",
+  "importer": "effect-header",
+  "imported": true,
+  "uuid": "73866dd2-eaf5-40af-a061-1b9d38782204",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 31 - 0
assets/chunks/common/data/unpack.chunk
View File

@@ -0,0 +1,31 @@
+// Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
+
+#pragma define STEP_FINT_128(v) (step(128.0, (v) + 0.5))
+#pragma define MOD_FINT_128(v) (mod(float(int((v) + 0.5)), 128.0))
+
+highp float decode32 (highp vec4 rgba) {
+  rgba = rgba * 255.0;
+  highp float Sign = 1.0 - STEP_FINT_128(rgba[3]) * 2.0;
+  highp float Exponent = 2.0 * MOD_FINT_128(rgba[3]) + STEP_FINT_128(rgba[2]) - 127.0;
+  highp float Mantissa = MOD_FINT_128(rgba[2]) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;
+  return Sign * exp2(Exponent - 23.0) * Mantissa;
+}
+
+
+vec4 packRGBE (vec3 rgb) {
+  highp float maxComp = max(max(rgb.r, rgb.g), rgb.b);
+  highp float e = 128.0;
+  if (maxComp > 0.0001) {
+    e = log(maxComp) / log(1.1);
+    e = ceil(e);
+    e = clamp(e + 128.0, 0.0, 255.0);
+  }
+  highp float sc = 1.0 / pow(1.1, e - 128.0);
+  vec3 encode = clamp(rgb * sc, vec3(0.0), vec3(1.0)) * 255.0;
+  vec3 encode_rounded = floor(encode) + step(encode - floor(encode), vec3(0.5)); //equals to round(encode)
+  return vec4(encode_rounded, e) / 255.0;
+}
+
+vec3 unpackRGBE (vec4 rgbe) {
+  return rgbe.rgb * pow(1.1, rgbe.a * 255.0 - 128.0);
+}

+ 9 - 0
assets/chunks/common/data/unpack.chunk.meta
View File

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.7",
+  "importer": "effect-header",
+  "imported": true,
+  "uuid": "e3e5d086-acc9-4dd8-98e8-24ac02f547d5",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 12 - 0
assets/chunks/common/debug.meta
View File

@@ -0,0 +1,12 @@
+{
+  "ver": "1.2.0",
+  "importer": "directory",
+  "imported": true,
+  "uuid": "a1b68389-649a-4208-9453-85db77a65771",
+  "files": [],
+  "subMetas": {},
+  "userData": {
+    "compressionType": {},
+    "isRemoteBundle": {}
+  }
+}

+ 89 - 0
assets/chunks/common/debug/debug-view-define.chunk
View File

@@ -0,0 +1,89 @@
+// vertex & face data
+#define CC_SURFACES_DEBUG_VIEW_VERTEX_COLOR 1
+#define CC_SURFACES_DEBUG_VIEW_VERTEX_NORMAL CC_SURFACES_DEBUG_VIEW_VERTEX_COLOR + 1
+#define CC_SURFACES_DEBUG_VIEW_VERTEX_TANGENT CC_SURFACES_DEBUG_VIEW_VERTEX_NORMAL + 1
+#define CC_SURFACES_DEBUG_VIEW_WORLD_POS CC_SURFACES_DEBUG_VIEW_VERTEX_TANGENT + 1
+#define CC_SURFACES_DEBUG_VIEW_VERTEX_MIRROR CC_SURFACES_DEBUG_VIEW_WORLD_POS + 1
+#define CC_SURFACES_DEBUG_VIEW_FACE_SIDE CC_SURFACES_DEBUG_VIEW_VERTEX_MIRROR + 1
+#define CC_SURFACES_DEBUG_VIEW_UV0 CC_SURFACES_DEBUG_VIEW_FACE_SIDE + 1
+#define CC_SURFACES_DEBUG_VIEW_UV1 CC_SURFACES_DEBUG_VIEW_UV0 + 1
+#define CC_SURFACES_DEBUG_VIEW_UVLIGHTMAP CC_SURFACES_DEBUG_VIEW_UV1 + 1
+#define CC_SURFACES_DEBUG_VIEW_PROJ_DEPTH CC_SURFACES_DEBUG_VIEW_UVLIGHTMAP + 1
+#define CC_SURFACES_DEBUG_VIEW_LINEAR_DEPTH CC_SURFACES_DEBUG_VIEW_PROJ_DEPTH + 1
+
+// surface material data
+#define CC_SURFACES_DEBUG_VIEW_FRAGMENT_NORMAL CC_SURFACES_DEBUG_VIEW_LINEAR_DEPTH + 1
+#define CC_SURFACES_DEBUG_VIEW_FRAGMENT_TANGENT CC_SURFACES_DEBUG_VIEW_FRAGMENT_NORMAL + 1
+#define CC_SURFACES_DEBUG_VIEW_FRAGMENT_BINORMAL CC_SURFACES_DEBUG_VIEW_FRAGMENT_TANGENT + 1
+#define CC_SURFACES_DEBUG_VIEW_BASE_COLOR CC_SURFACES_DEBUG_VIEW_FRAGMENT_BINORMAL + 1
+#define CC_SURFACES_DEBUG_VIEW_DIFFUSE_COLOR CC_SURFACES_DEBUG_VIEW_BASE_COLOR + 1
+#define CC_SURFACES_DEBUG_VIEW_SPECULAR_COLOR CC_SURFACES_DEBUG_VIEW_DIFFUSE_COLOR + 1
+#define CC_SURFACES_DEBUG_VIEW_TRANSPARENCY CC_SURFACES_DEBUG_VIEW_SPECULAR_COLOR + 1
+#define CC_SURFACES_DEBUG_VIEW_METALLIC CC_SURFACES_DEBUG_VIEW_TRANSPARENCY + 1
+#define CC_SURFACES_DEBUG_VIEW_ROUGHNESS CC_SURFACES_DEBUG_VIEW_METALLIC + 1
+#define CC_SURFACES_DEBUG_VIEW_SPECULAR_INTENSITY CC_SURFACES_DEBUG_VIEW_ROUGHNESS + 1
+#define CC_SURFACES_DEBUG_VIEW_IOR CC_SURFACES_DEBUG_VIEW_SPECULAR_INTENSITY + 1
+
+// lighting data
+#define CC_SURFACES_DEBUG_VIEW_DIRECT_DIFFUSE CC_SURFACES_DEBUG_VIEW_IOR + 1
+#define CC_SURFACES_DEBUG_VIEW_DIRECT_SPECULAR CC_SURFACES_DEBUG_VIEW_DIRECT_DIFFUSE + 1
+#define CC_SURFACES_DEBUG_VIEW_DIRECT_ALL CC_SURFACES_DEBUG_VIEW_DIRECT_SPECULAR + 1
+#define CC_SURFACES_DEBUG_VIEW_ENV_DIFFUSE CC_SURFACES_DEBUG_VIEW_DIRECT_ALL + 1
+#define CC_SURFACES_DEBUG_VIEW_ENV_SPECULAR CC_SURFACES_DEBUG_VIEW_ENV_DIFFUSE + 1
+#define CC_SURFACES_DEBUG_VIEW_ENV_ALL CC_SURFACES_DEBUG_VIEW_ENV_SPECULAR + 1
+#define CC_SURFACES_DEBUG_VIEW_EMISSIVE CC_SURFACES_DEBUG_VIEW_ENV_ALL + 1
+#define CC_SURFACES_DEBUG_VIEW_LIGHT_MAP CC_SURFACES_DEBUG_VIEW_EMISSIVE + 1
+#define CC_SURFACES_DEBUG_VIEW_SHADOW CC_SURFACES_DEBUG_VIEW_LIGHT_MAP + 1
+#define CC_SURFACES_DEBUG_VIEW_AO CC_SURFACES_DEBUG_VIEW_SHADOW + 1
+
+// advanced lighting data
+#define CC_SURFACES_DEBUG_VIEW_FRESNEL CC_SURFACES_DEBUG_VIEW_AO + 1
+#define CC_SURFACES_DEBUG_VIEW_TRANSMIT_DIRECT_DIFFUSE CC_SURFACES_DEBUG_VIEW_FRESNEL + 1
+#define CC_SURFACES_DEBUG_VIEW_TRANSMIT_DIRECT_SPECULAR CC_SURFACES_DEBUG_VIEW_TRANSMIT_DIRECT_DIFFUSE + 1
+#define CC_SURFACES_DEBUG_VIEW_TRANSMIT_ENV_DIFFUSE CC_SURFACES_DEBUG_VIEW_TRANSMIT_DIRECT_SPECULAR + 1
+#define CC_SURFACES_DEBUG_VIEW_TRANSMIT_ENV_SPECULAR CC_SURFACES_DEBUG_VIEW_TRANSMIT_ENV_DIFFUSE + 1
+#define CC_SURFACES_DEBUG_VIEW_TRANSMIT_ALL CC_SURFACES_DEBUG_VIEW_TRANSMIT_ENV_SPECULAR + 1
+#define CC_SURFACES_DEBUG_VIEW_DIRECT_2ND_SPECULAR CC_SURFACES_DEBUG_VIEW_TRANSMIT_ALL + 1
+#define CC_SURFACES_DEBUG_VIEW_ENVIRONMENT_2ND_SPECULAR CC_SURFACES_DEBUG_VIEW_DIRECT_2ND_SPECULAR + 1
+#define CC_SURFACES_DEBUG_VIEW_2ND_SPECULAR_ALL CC_SURFACES_DEBUG_VIEW_ENVIRONMENT_2ND_SPECULAR + 1
+
+// misc data
+#define CC_SURFACES_DEBUG_VIEW_FOG CC_SURFACES_DEBUG_VIEW_2ND_SPECULAR_ALL + 1
+
+// Debug view UI and macros
+// #pragma define-meta CC_USE_DEBUG_VIEW range([0, 2])
+// #define CC_SURFACES_DEBUG_VIEW_SINGLE 1
+// #define CC_SURFACES_DEBUG_VIEW_COMPOSITE_AND_MISC 2
+
+#define IS_DEBUG_VIEW_ENABLE_WITH_CAMERA (cc_surfaceTransform.y != 3.0)
+bool equalf_mode(float data1, float data2) { return abs(float(data1) - float(data2)) < 0.001; }
+#pragma define IS_DEBUG_VIEW_SINGLE_MODE(mode) (equalf_mode(cc_debug_view_mode.x, float(mode)) && (cc_surfaceTransform.y != 3.0))
+#define IS_DEBUG_VIEW_LIGHTING_ENABLE_WITH_ALBEDO (UnpackBitFromFloat(cc_debug_view_mode.w, 6) || !IS_DEBUG_VIEW_ENABLE_WITH_CAMERA)
+#define IS_DEBUG_VIEW_MISC_ENABLE_CSM_LAYER_COLORATION (UnpackBitFromFloat(cc_debug_view_mode.w, 7) && IS_DEBUG_VIEW_ENABLE_WITH_CAMERA)
+#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_DIRECT_DIFFUSE (UnpackBitFromFloat(cc_debug_view_mode.y, 0) || !IS_DEBUG_VIEW_ENABLE_WITH_CAMERA)
+#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_DIRECT_SPECULAR (UnpackBitFromFloat(cc_debug_view_mode.y, 1) || !IS_DEBUG_VIEW_ENABLE_WITH_CAMERA)
+#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_ENV_DIFFUSE (UnpackBitFromFloat(cc_debug_view_mode.y, 2) || !IS_DEBUG_VIEW_ENABLE_WITH_CAMERA)
+#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_ENV_SPECULAR (UnpackBitFromFloat(cc_debug_view_mode.y, 3) || !IS_DEBUG_VIEW_ENABLE_WITH_CAMERA)
+#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_EMISSIVE (UnpackBitFromFloat(cc_debug_view_mode.y, 4) || !IS_DEBUG_VIEW_ENABLE_WITH_CAMERA)
+#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_LIGHT_MAP (UnpackBitFromFloat(cc_debug_view_mode.y, 5) || !IS_DEBUG_VIEW_ENABLE_WITH_CAMERA)
+#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_SHADOW (UnpackBitFromFloat(cc_debug_view_mode.y, 6) || !IS_DEBUG_VIEW_ENABLE_WITH_CAMERA)
+#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_AO (UnpackBitFromFloat(cc_debug_view_mode.y, 7) || !IS_DEBUG_VIEW_ENABLE_WITH_CAMERA)
+#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_NORMAL_MAP (UnpackBitFromFloat(cc_debug_view_mode.z, 0) || !IS_DEBUG_VIEW_ENABLE_WITH_CAMERA)
+#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_FOG (UnpackBitFromFloat(cc_debug_view_mode.z, 1) || !IS_DEBUG_VIEW_ENABLE_WITH_CAMERA)
+#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_TONE_MAPPING (UnpackBitFromFloat(cc_debug_view_mode.z, 2) || !IS_DEBUG_VIEW_ENABLE_WITH_CAMERA)
+#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_GAMMA_CORRECTION (UnpackBitFromFloat(cc_debug_view_mode.z, 3) || !IS_DEBUG_VIEW_ENABLE_WITH_CAMERA)
+#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_FRESNEL (UnpackBitFromFloat(cc_debug_view_mode.z, 4) || !IS_DEBUG_VIEW_ENABLE_WITH_CAMERA)
+#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_TRANSMIT_DIFFUSE (UnpackBitFromFloat(cc_debug_view_mode.z, 5) || !IS_DEBUG_VIEW_ENABLE_WITH_CAMERA)
+#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_TRANSMIT_SPECULAR (UnpackBitFromFloat(cc_debug_view_mode.z, 6) || !IS_DEBUG_VIEW_ENABLE_WITH_CAMERA)
+#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_2ND_SPECULAR (UnpackBitFromFloat(cc_debug_view_mode.z, 7) || !IS_DEBUG_VIEW_ENABLE_WITH_CAMERA)
+#define IS_DEBUG_VIEW_COMPOSITE_ENABLE_TT (UnpackBitFromFloat(cc_debug_view_mode.w, 0) || !IS_DEBUG_VIEW_ENABLE_WITH_CAMERA)
+
+// these mode shows non-lighting data, need ignore tone mapping and gamma correction
+bool DebugViewNeedDisplayOriginalData() {
+    return
+    IS_DEBUG_VIEW_SINGLE_MODE(CC_SURFACES_DEBUG_VIEW_FRAGMENT_NORMAL) || IS_DEBUG_VIEW_SINGLE_MODE(CC_SURFACES_DEBUG_VIEW_FRAGMENT_TANGENT) || IS_DEBUG_VIEW_SINGLE_MODE(CC_SURFACES_DEBUG_VIEW_FRAGMENT_BINORMAL) ||
+    IS_DEBUG_VIEW_SINGLE_MODE(CC_SURFACES_DEBUG_VIEW_TRANSPARENCY) || IS_DEBUG_VIEW_SINGLE_MODE(CC_SURFACES_DEBUG_VIEW_BASE_COLOR) || IS_DEBUG_VIEW_SINGLE_MODE(CC_SURFACES_DEBUG_VIEW_DIFFUSE_COLOR) ||
+    IS_DEBUG_VIEW_SINGLE_MODE(CC_SURFACES_DEBUG_VIEW_SPECULAR_COLOR) || IS_DEBUG_VIEW_SINGLE_MODE(CC_SURFACES_DEBUG_VIEW_ROUGHNESS) || IS_DEBUG_VIEW_SINGLE_MODE(CC_SURFACES_DEBUG_VIEW_METALLIC) ||
+    IS_DEBUG_VIEW_SINGLE_MODE(CC_SURFACES_DEBUG_VIEW_SPECULAR_INTENSITY) || IS_DEBUG_VIEW_SINGLE_MODE(CC_SURFACES_DEBUG_VIEW_IOR)
+    ;
+}

+ 9 - 0
assets/chunks/common/debug/debug-view-define.chunk.meta
View File

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.7",
+  "importer": "effect-header",
+  "imported": true,
+  "uuid": "9c973ee8-952a-4ee3-a617-ba6397db6bac",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 12 - 0
assets/chunks/common/effect.meta
View File

@@ -0,0 +1,12 @@
+{
+  "ver": "1.2.0",
+  "importer": "directory",
+  "imported": true,
+  "uuid": "98420980-4268-402a-a26d-f66e6ee50a03",
+  "files": [],
+  "subMetas": {},
+  "userData": {
+    "compressionType": {},
+    "isRemoteBundle": {}
+  }
+}

+ 65 - 0
assets/chunks/common/effect/fog.chunk
View File

@@ -0,0 +1,65 @@
+// fog related calculations
+
+//pos, cc_cameraPos.xyz, cc_fogBase.x, cc_fogBase.y
+float LinearFog(vec4 pos, vec3 cameraPos, float fogStart, float fogEnd) {
+    vec4 wPos = pos;
+    float cam_dis = distance(cameraPos, wPos.xyz);
+    return clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);
+}
+
+//pos, cc_cameraPos.xyz, cc_fogBase.x, cc_fogBase.z, cc_fogAdd.z
+float ExpFog(vec4 pos, vec3 cameraPos, float fogStart, float fogDensity, float fogAtten) {
+    vec4 wPos = pos;
+    float cam_dis = max(distance(cameraPos, wPos.xyz) - fogStart, 0.0) / fogAtten * 4.;
+    float f = exp(-cam_dis * fogDensity);
+    return f;
+}
+
+float ExpSquaredFog(vec4 pos, vec3 cameraPos, float fogStart, float fogDensity, float fogAtten) {
+    vec4 wPos = pos;
+    float cam_dis = max(distance(cameraPos, wPos.xyz) - fogStart, 0.0) / fogAtten * 4.;
+    float f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);
+    return f;
+}
+
+//pos, cc_cameraPos.xyz, cc_fogAdd.x, cc_fogAdd.y, cc_fogAdd.z
+float LayeredFog(vec4 pos, vec3 cameraPos, float fogTop, float fogRange, float fogAtten) {
+    vec4 wPos = pos;
+    vec3 camWorldProj = cameraPos.xyz;
+    camWorldProj.y = 0.;
+    vec3 worldPosProj = wPos.xyz;
+    worldPosProj.y = 0.;
+    float fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;
+    float fDeltaY, fDensityIntegral;
+    if (cameraPos.y > fogTop) {
+        if (wPos.y < fogTop) {
+            fDeltaY = (fogTop - wPos.y) / fogRange * 2.0;
+            fDensityIntegral = fDeltaY * fDeltaY * 0.5;
+        }
+        else {
+            fDeltaY = 0.;
+            fDensityIntegral = 0.;
+        }
+    }
+    else {
+        if (wPos.y < fogTop) {
+            float fDeltaA = (fogTop - cameraPos.y) / fogRange * 2.;
+            float fDeltaB = (fogTop - wPos.y) / fogRange * 2.;
+            fDeltaY = abs(fDeltaA - fDeltaB);
+            fDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));
+        }
+        else {
+            fDeltaY = abs(fogTop - cameraPos.y) / fogRange * 2.;
+            fDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);
+        }
+    }
+    float fDensity;
+    if (fDeltaY != 0.) {
+        fDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;
+    }
+    else {
+        fDensity = 0.;
+    }
+    float f = exp(-fDensity);
+    return f;
+}

+ 9 - 0
assets/chunks/common/effect/fog.chunk.meta
View File

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.7",
+  "importer": "effect-header",
+  "imported": true,
+  "uuid": "399f5890-dde1-40de-9751-a7aa91a56b93",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 41 - 0
assets/chunks/common/effect/special-effects.chunk
View File

@@ -0,0 +1,41 @@
+
+// dithered transparency (dithered alpha test), better looking with TAA
+// arguments: FSInput_clipPos, cc_viewPort.zw, baseColor.a
+void DitheredAlphaClip(vec4 clipPos, vec2 screen_resolution, float transparency)
+{
+  // can not be floor or ceil
+  vec2 screenPos = (clipPos.xy / clipPos.w * 0.5 + vec2(0.5)) * floor(screen_resolution);
+  float dither5 = fract( ( screenPos.x + screenPos.y * 2.0 - 1.5 /*+ ResolvedView.TemporalAAParams.x*/ ) / 5.0 );
+  float noiseValue = fract( dot( vec2( 171.0, 231.0 ) / 71.0, screenPos.xy ) );
+  float dither = ( dither5 * 5.0 + noiseValue ) * (1.0 / 6.0);
+  if( transparency + dither < 0.833333333 ) discard;
+}
+
+// NormalFromMap is: texture(normalmap) - 0.5
+vec3 BlendDetailedNormalMap(vec3 baseNormalFromMap, vec3 detailedNormalFromMap, float detailedIntensity)
+{
+    return normalize(vec3(baseNormalFromMap.xy + detailedNormalFromMap.xy * detailedIntensity, baseNormalFromMap.z));
+}
+
+
+float BlendDetailedColorMap(float baseColor, float detailedColor)
+{
+  float s = baseColor, d = detailedColor;
+  if (s < 0.5)
+  {
+    return 2.0 * s * d;
+  }
+  else
+  {
+    if (d >= 0.5)
+      return 1.0 - 2.0 * (1.0 - s) * (1.0 - d);
+    else
+      return mix(2.0 * s * d, s, (2.0 * s - 1.0) * (2.0 * s - 1.0));
+  }
+}
+vec3 BlendDetailedColorMap(vec3 baseColor, vec3 detailedColor)
+{
+    return vec3(BlendDetailedColorMap(baseColor.r, detailedColor.r),
+                BlendDetailedColorMap(baseColor.g, detailedColor.g),
+                BlendDetailedColorMap(baseColor.b, detailedColor.b));
+}

+ 9 - 0
assets/chunks/common/effect/special-effects.chunk.meta
View File

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.7",
+  "importer": "effect-header",
+  "imported": true,
+  "uuid": "a9f88e4b-6d43-4af4-8a58-f7d918adcb73",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 12 - 0
assets/chunks/common/graph-expression.meta
View File

@@ -0,0 +1,12 @@
+{
+  "ver": "1.2.0",
+  "importer": "directory",
+  "imported": true,
+  "uuid": "8cab82a8-3634-48c2-8853-021f200cf799",
+  "files": [],
+  "subMetas": {},
+  "userData": {
+    "compressionType": {},
+    "isRemoteBundle": {}
+  }
+}

+ 63 - 0
assets/chunks/common/graph-expression/base.chunk
View File

@@ -0,0 +1,63 @@
+// base coordinates & color expressions for shader-graph
+
+
+// fraction is saturation percentage, 0 means gray
+vec3 Desaturation(vec3 color, float fraction)
+{
+  vec3 gray = vec3(dot(color, GRAY_VECTOR));
+  return mix(color, gray, fraction);
+}
+
+vec2 Rotator(vec2 uv, vec2 centerUV, float time, float speed)
+{
+  uv -= centerUV;
+  vec3 dir = vec3(uv.x, 0.0, uv.y);
+  float dirLength = length(dir);
+  dir /= dirLength + EPSILON;
+  dir = RotationVecFromAxisY(dir, time * speed) * dirLength;
+  return vec2(dir.x, dir.z) + centerUV;
+}
+
+// return 0.0 when out of range
+// hardness: 0 - 1
+float SphereMask(vec2 center, vec2 point, float radius, float hardness)
+{
+  float length = length(center - point);
+  float coef = pow(saturate(length / radius), 1.0 / (1.0 - saturate(sqrt(hardness)) + EPSILON));
+  return length > radius ? 0.0 : 1.0 - coef;
+}
+float SphereMask(vec3 center, vec3 point, float radius, float hardness)
+{
+  float length = length(center - point);
+  float coef = pow(saturate(length / radius), 1.0 / (1.0 - saturate(sqrt(hardness)) + EPSILON));
+  return length > radius ? 0.0 : 1.0 - coef;
+}
+
+
+// For Fragment Shader
+
+// tangent space -> world space
+// same as TransformVector
+vec3 TransformNormalMap(vec3 vectorFromNormalMap)
+{
+  vec3 vectorTS = normalize(vectorFromNormalMap - vec3(0.5));
+  vec3 normal = normalize(FSInput_worldNormal);
+  vec3 tangent = normalize(FSInput_worldTangent);
+  vec3 binormal = CalculateBinormal(normal, tangent, FSInput_mirrorNormal);
+  vec3 vecWS = vectorTS.x * tangent + vectorTS.y * binormal + vectorTS.z * normal;
+  return vecWS * vec3(1.0, 1.0, -1.0); // inverse Z for RH
+}
+
+// WorldPos -> UV
+vec2 GetTriplanarMappingUV()
+{
+  vec3 Up = vec3(0.0, 1.0, 0.0);
+  vec3 U = cross(Up, FSInput_worldNormal.xyz);
+  if (length(U) < 0.01)
+    U = vec3(1.0, 0.0, 0.0);
+  else
+    U = normalize(U);
+  vec3 V = cross(U, FSInput_worldNormal.xyz);
+  V = normalize(V);
+  return fract(vec2(dot(FSInput_worldPos.xyz, U), dot(FSInput_worldPos.xyz, V)));
+}

+ 9 - 0
assets/chunks/common/graph-expression/base.chunk.meta
View File

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.7",
+  "importer": "effect-header",
+  "imported": true,
+  "uuid": "4b4d0c0f-1d50-4d50-84e7-226c8d0dbd6f",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 12 - 0
assets/chunks/common/internal-functions.meta
View File

@@ -0,0 +1,12 @@
+{
+  "ver": "1.1.0",
+  "importer": "directory",
+  "imported": true,
+  "uuid": "b67dfb5d-1a4d-469e-a35f-52e665ae1ea2",
+  "files": [],
+  "subMetas": {},
+  "userData": {
+    "compressionType": {},
+    "isRemoteBundle": {}
+  }
+}

+ 12 - 0
assets/chunks/common/lighting.meta
View File

@@ -0,0 +1,12 @@
+{
+  "ver": "1.2.0",
+  "importer": "directory",
+  "imported": true,
+  "uuid": "a2ba2f72-737d-4b4b-84be-3e014d996327",
+  "files": [],
+  "subMetas": {},
+  "userData": {
+    "compressionType": {},
+    "isRemoteBundle": {}
+  }
+}

+ 60 - 0
assets/chunks/common/lighting/attenuation.chunk
View File

@@ -0,0 +1,60 @@
+// base
+float SmoothDistAtt2 (float distSqr, float invSqrAttRadius) {
+  float factor = distSqr * invSqrAttRadius; // ^2
+  float factor2 = factor * factor; // ^4
+  float factor3 = factor2 * factor2; // ^8
+  float smoothFactor = clamp(1.0 - factor3 * factor3, 0.0, 1.0);
+  return smoothFactor * smoothFactor;
+}
+
+float SmoothDistAtt (float distSqr, float invSqrAttRadius) {
+  float factor = distSqr * invSqrAttRadius;
+  float smoothFactor = clamp(1.0 - factor * factor, 0.0, 1.0);
+  return smoothFactor * smoothFactor;
+}
+
+float GetDistAtt (float distSqr, float invSqrAttRadius) {
+  float attenuation = 1.0 / max(distSqr, 0.01*0.01);
+  attenuation *= SmoothDistAtt(distSqr , invSqrAttRadius);
+  return attenuation;
+}
+
+float GetAngleAtt (vec3 L, vec3 litDir, float litAngleScale, float litAngleOffset) {
+  float cd = dot(litDir, L);
+  float attenuation = clamp(cd * litAngleScale + litAngleOffset, 0.0, 1.0);
+  return (attenuation * attenuation);
+}
+
+
+float GetOutOfRange (vec3 worldPos, vec3 lightPos, vec3 lookAt, vec3 right, vec3 BoundingHalfSizeVS) {
+  vec3 v = vec3(0.0);
+  vec3 up = cross(right, lookAt);
+  worldPos -= lightPos;
+  v.x = dot(worldPos, right);
+  v.y = dot(worldPos, up);
+  v.z = dot(worldPos, lookAt);
+  vec3 result = step(abs(v), BoundingHalfSizeVS);
+  return result.x * result.y * result.z;
+}
+
+// advanced
+float CalculateDistanceAttenuation(float distToLightSqr, float lightRadius, float lightRange, float lightType)
+{
+  // physical attenuation
+  float attRadiusSqrInv = 1.0 / max(lightRange, 0.01);
+  attRadiusSqrInv *= attRadiusSqrInv;
+
+  // artical soft edge fading
+  float litRadiusSqr = lightRadius * lightRadius;
+  float edgeAttenuation = (IS_POINT_LIGHT(lightType) || IS_RANGED_DIRECTIONAL_LIGHT(lightType)) ? 1.0 : litRadiusSqr / max(litRadiusSqr, distToLightSqr);
+
+  return GetDistAtt(distToLightSqr, attRadiusSqrInv) * edgeAttenuation;
+}
+
+float CalculateAngleAttenuation(vec3 spotLightDir, vec3 L, float cosAngleOuter)
+{
+  float cosInner = max(dot(spotLightDir, L), 0.01);
+  float litAngleScale = 1.0 / max(0.001, cosInner - cosAngleOuter);
+  float litAngleOffset = -cosAngleOuter * litAngleScale;
+  return GetAngleAtt(L, spotLightDir, litAngleScale, litAngleOffset);
+}

Some files were not shown because too many files changed in this diff