diff --git a/.github/workflows/build-problem-matcher.json b/.github/workflows/build-problem-matcher.json index 3244c39f7f..90cf3caba6 100644 --- a/.github/workflows/build-problem-matcher.json +++ b/.github/workflows/build-problem-matcher.json @@ -2,7 +2,7 @@ { "problemMatcher": [ { - "owner": "circular-reference-check", + "owner": " build", "pattern": [ { "regexp": "^Circular dependency: (.*)$", diff --git a/.vscode/launch.json b/.vscode/launch.json index 4d2e6e6087..23f1727d5e 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -56,7 +56,8 @@ "program": "${workspaceFolder}/node_modules/jest/bin/jest.js" }, "args": [ - "${fileBasenameNoExtension}" + "--runTestsByPath", + "${relativeFileDirname}/${fileBasename}" ], "cwd": "${workspaceFolder}", "console": "integratedTerminal", diff --git a/cocos/2d/assembler/graphics/webgl/graphics-assembler.ts b/cocos/2d/assembler/graphics/webgl/graphics-assembler.ts index 88bb73b940..5a0a3ec9c1 100644 --- a/cocos/2d/assembler/graphics/webgl/graphics-assembler.ts +++ b/cocos/2d/assembler/graphics/webgl/graphics-assembler.ts @@ -22,12 +22,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ - -/** - * @packageDocumentation - * @module ui-assembler - */ - import { Color, Vec3 } from '../../../../core/math'; import { IAssembler } from '../../../renderer/base'; import { MeshRenderData } from '../../../renderer/render-data'; diff --git a/cocos/2d/assembler/index.ts b/cocos/2d/assembler/index.ts index b422354fb5..54f5a8c8e4 100644 --- a/cocos/2d/assembler/index.ts +++ b/cocos/2d/assembler/index.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module ui - */ - import './utils'; export * from './graphics'; diff --git a/cocos/2d/assembler/label/bmfont.ts b/cocos/2d/assembler/label/bmfont.ts index 4bb3e1722f..009183dc53 100644 --- a/cocos/2d/assembler/label/bmfont.ts +++ b/cocos/2d/assembler/label/bmfont.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module ui-assembler - */ - import { SpriteFrame } from '../../assets/sprite-frame'; import * as js from '../../../core/utils/js'; import { Color, Rect } from '../../../core/math'; diff --git a/cocos/2d/assembler/label/index.ts b/cocos/2d/assembler/label/index.ts index 92ec7af9f0..c466369f85 100644 --- a/cocos/2d/assembler/label/index.ts +++ b/cocos/2d/assembler/label/index.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module ui-assembler - */ - import { BitmapFont } from '../../assets'; import { Label } from '../../components'; import { IAssemblerManager } from '../../renderer/base'; diff --git a/cocos/2d/assembler/label/letter.ts b/cocos/2d/assembler/label/letter.ts index 5dceee06f0..2550a369b3 100644 --- a/cocos/2d/assembler/label/letter.ts +++ b/cocos/2d/assembler/label/letter.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module ui-assembler - */ - import { addon } from '../../../core/utils/js'; import { IBatcher } from '../../renderer/i-batcher'; import { Label } from '../../components/label'; diff --git a/cocos/2d/assembler/mask/index.ts b/cocos/2d/assembler/mask/index.ts index f59ed5f4f4..ae2cf72dc9 100644 --- a/cocos/2d/assembler/mask/index.ts +++ b/cocos/2d/assembler/mask/index.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { maskAssembler as mask, maskEndAssembler as maskEnd } from './mask-assembler'; export { diff --git a/cocos/2d/assembler/mask/mask-assembler.ts b/cocos/2d/assembler/mask/mask-assembler.ts index f2a12b5812..9373ac2307 100644 --- a/cocos/2d/assembler/mask/mask-assembler.ts +++ b/cocos/2d/assembler/mask/mask-assembler.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module ui-assembler - */ - import { IBatcher } from '../../renderer/i-batcher'; import { Mask, MaskType } from '../../components/mask'; import { IAssembler, IAssemblerManager } from '../../renderer/base'; diff --git a/cocos/2d/assembler/sprite/bar-filled.ts b/cocos/2d/assembler/sprite/bar-filled.ts index ee94de7533..8c4bbd3df4 100644 --- a/cocos/2d/assembler/sprite/bar-filled.ts +++ b/cocos/2d/assembler/sprite/bar-filled.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module ui-assembler - */ - import { Color, Mat4, Vec3 } from '../../../core/math'; import { IRenderData, RenderData } from '../../renderer/render-data'; import { IBatcher } from '../../renderer/i-batcher'; diff --git a/cocos/2d/assembler/sprite/radial-filled.ts b/cocos/2d/assembler/sprite/radial-filled.ts index 153846db63..94360df02a 100644 --- a/cocos/2d/assembler/sprite/radial-filled.ts +++ b/cocos/2d/assembler/sprite/radial-filled.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module ui-assembler - */ - import { SpriteFrame } from '../../assets'; import { Color, Mat4, Vec2, Vec3 } from '../../../core/math'; import { IRenderData, RenderData } from '../../renderer/render-data'; diff --git a/cocos/2d/assembler/sprite/simple.ts b/cocos/2d/assembler/sprite/simple.ts index 99cd370c6f..d773c944f0 100644 --- a/cocos/2d/assembler/sprite/simple.ts +++ b/cocos/2d/assembler/sprite/simple.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module ui-assembler - */ - import { Vec3 } from '../../../core/math'; import { IAssembler } from '../../renderer/base'; import { IRenderData, RenderData } from '../../renderer/render-data'; diff --git a/cocos/2d/assembler/sprite/sliced.ts b/cocos/2d/assembler/sprite/sliced.ts index c1ab2d260b..37b11f1d00 100644 --- a/cocos/2d/assembler/sprite/sliced.ts +++ b/cocos/2d/assembler/sprite/sliced.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module ui-assembler - */ - import { Mat4, Vec3 } from '../../../core/math'; import { IRenderData, RenderData } from '../../renderer/render-data'; import { IBatcher } from '../../renderer/i-batcher'; diff --git a/cocos/2d/assembler/utils.ts b/cocos/2d/assembler/utils.ts index 3471a8a056..e67ee93aeb 100644 --- a/cocos/2d/assembler/utils.ts +++ b/cocos/2d/assembler/utils.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { Color, Mat4, Vec3 } from '../../core/math'; import { RenderData } from '../renderer/render-data'; import { IBatcher } from '../renderer/i-batcher'; diff --git a/cocos/2d/assets/bitmap-font.ts b/cocos/2d/assets/bitmap-font.ts index 9081038b48..ecbda85704 100644 --- a/cocos/2d/assets/bitmap-font.ts +++ b/cocos/2d/assets/bitmap-font.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module asset - */ - import { ccclass, type, serializable, editable } from 'cc.decorator'; import { Font } from './font'; import { SpriteFrame } from './sprite-frame'; diff --git a/cocos/2d/assets/font.ts b/cocos/2d/assets/font.ts index b57a343e2a..77bb1aa523 100644 --- a/cocos/2d/assets/font.ts +++ b/cocos/2d/assets/font.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module asset - */ - import { ccclass } from 'cc.decorator'; import { Asset } from '../../core/assets'; import { legacyCC } from '../../core/global-exports'; diff --git a/cocos/2d/assets/index.ts b/cocos/2d/assets/index.ts index c7ca8ccf53..23f063af1d 100644 --- a/cocos/2d/assets/index.ts +++ b/cocos/2d/assets/index.ts @@ -1,7 +1,4 @@ -/** - * @packageDocumentation - * @module asset - */ + export * from './sprite-frame'; export { SpriteAtlas } from './sprite-atlas'; diff --git a/cocos/2d/assets/label-atlas.ts b/cocos/2d/assets/label-atlas.ts index dc9cde306a..339c480c18 100644 --- a/cocos/2d/assets/label-atlas.ts +++ b/cocos/2d/assets/label-atlas.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module asset - */ - import { ccclass } from 'cc.decorator'; import { BitmapFont } from './bitmap-font'; import { legacyCC } from '../../core/global-exports'; diff --git a/cocos/2d/assets/sprite-atlas.ts b/cocos/2d/assets/sprite-atlas.ts index 5262870b5e..b62b556166 100644 --- a/cocos/2d/assets/sprite-atlas.ts +++ b/cocos/2d/assets/sprite-atlas.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module asset - */ - import { EDITOR, TEST } from 'internal:constants'; import { ccclass, serializable, editable } from 'cc.decorator'; import * as js from '../../core/utils/js'; diff --git a/cocos/2d/assets/sprite-frame.ts b/cocos/2d/assets/sprite-frame.ts index cb245ce598..791954b03e 100644 --- a/cocos/2d/assets/sprite-frame.ts +++ b/cocos/2d/assets/sprite-frame.ts @@ -25,11 +25,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module asset - */ - import { ccclass } from 'cc.decorator'; import { EDITOR, TEST, BUILD } from 'internal:constants'; import { Rect, Size, Vec2 } from '../../core/math'; @@ -239,8 +234,8 @@ export class SpriteFrame extends Asset { } /** - * @en - * @zh + * @en uv update event + * @zh uv 更新事件 */ public static EVENT_UV_UPDATED = 'uv_updated'; @@ -661,7 +656,7 @@ export class SpriteFrame extends Asset { } /** - * @en Gets the related GFX [[Texture]] resource + * @en Gets the related GFX [[gfx.Texture]] resource * @zh 获取渲染贴图的 GFX 资源 */ public getGFXTexture () { diff --git a/cocos/2d/assets/ttf-font.ts b/cocos/2d/assets/ttf-font.ts index 542eb50e7c..6e1c7ad23e 100644 --- a/cocos/2d/assets/ttf-font.ts +++ b/cocos/2d/assets/ttf-font.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module asset - */ - import { ccclass, string, override, serializable } from 'cc.decorator'; import { extname } from '../../core/utils/path'; import { Font } from './font'; diff --git a/cocos/2d/components/deprecated.ts b/cocos/2d/components/deprecated.ts index 9d0edd1588..e482fb9edf 100644 --- a/cocos/2d/components/deprecated.ts +++ b/cocos/2d/components/deprecated.ts @@ -23,10 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module ui - */ import { Mask } from './mask'; import { Label } from './label'; import { LabelOutline } from './label-outline'; diff --git a/cocos/2d/components/graphics.ts b/cocos/2d/components/graphics.ts index b1da8b81f3..91f39aa852 100644 --- a/cocos/2d/components/graphics.ts +++ b/cocos/2d/components/graphics.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module ui - */ - import { ccclass, help, executionOrder, menu, tooltip, type, visible, override, editable, serializable } from 'cc.decorator'; import { builtinResMgr } from '../../core/builtin'; import { InstanceMaterialType, UIRenderer } from '../framework/ui-renderer'; @@ -299,8 +294,10 @@ export class Graphics extends UIRenderer { * @zh * 移动路径起点到坐标(x, y)。 * - * @param x - 移动坐标 x 轴。 - * @param y - 移动坐标 y 轴。 + * @param x @en The x-axis coordinate of the target position. + * @zh 目标位置的 X 轴坐标。 + * @param y @en The y-axis coordinate of the target position. + * @zh 目标位置的 y 轴坐标。 */ public moveTo (x: number, y: number) { if (!this.impl) { @@ -317,8 +314,10 @@ export class Graphics extends UIRenderer { * @zh * 绘制直线路径。 * - * @param x - 绘制路径坐标 x 轴。 - * @param y - 绘制路径坐标 y 轴。 + * @param x @en The x-axis coordinate of the target position. + * @zh 目标位置的 x 轴坐标。 + * @param y @en The x-axis coordinate of the target position. + * @zh 目标位置的 y 轴坐标。 */ public lineTo (x: number, y: number) { if (!this.impl) { @@ -335,12 +334,18 @@ export class Graphics extends UIRenderer { * @zh * 绘制三次贝赛尔曲线路径。 * - * @param c1x - 第一个控制点的坐标 x 轴。 - * @param c1y - 第一个控制点的坐标 y 轴。 - * @param c2x - 第二个控制点的坐标 x 轴。 - * @param c2y - 第二个控制点的坐标 y 轴。 - * @param x - 最后一个控制点的坐标 x 轴。 - * @param y - 最后一个控制点的坐标 y 轴。 + * @param c1x @en The x-axis coordinate of the first control point. + * @zh 第一个控制点的 x 轴坐标。 + * @param c1y @en The y-axis coordinate of the first control point. + * @zh 第一个控制点的 y 轴坐标。 + * @param c2x @en The x-axis coordinate of the second control point. + * @zh 第二个控制点的 x 轴坐标。 + * @param c2y @en The y-axis coordinate of the second control point. + * @zh 第二个控制点的 y 轴坐标。 + * @param x @en The x-axis coordinate of the last control point. + * @zh 最后一个控制点的 x 轴坐标。 + * @param y @en The y-axis coordinate of the last control point. + * @zh 最后一个控制点的 y 轴坐标。 */ public bezierCurveTo (c1x: number, c1y: number, c2x: number, c2y: number, x: number, y: number) { if (!this.impl) { @@ -357,10 +362,14 @@ export class Graphics extends UIRenderer { * @zh * 绘制二次贝赛尔曲线路径。 * - * @param cx - 起始控制点的坐标 x 轴。 - * @param cy - 起始控制点的坐标 y 轴。 - * @param x - 终点控制点的坐标 x 轴。 - * @param y - 终点控制点的坐标 x 轴。 + * @param cx @en The x-axis coordinate of the starting control point. + * @zh 起始控制点的 x 轴坐标。 + * @param cy @en The y-axis coordinate of the starting control point. + * @zh 起始控制点的 y 轴坐标。 + * @param x @en The x-axis coordinates of the endpoint control point. + * @zh 终点控制点的 x 轴坐标。 + * @param y @en The y-axis coordinates of the endpoint control point. + * @zh 终点控制点的 x 轴坐标。 */ public quadraticCurveTo (cx: number, cy: number, x: number, y: number) { if (!this.impl) { @@ -378,12 +387,18 @@ export class Graphics extends UIRenderer { * @zh * 绘制圆弧路径。圆弧路径的圆心在 (cx, cy) 位置,半径为 r ,根据 counterclockwise (默认为false)指定的方向从 startAngle 开始绘制,到 endAngle 结束。 * - * @param cx - 中心控制点的坐标 x 轴。 - * @param cy - 中心控制点的坐标 y 轴。 - * @param r - 圆弧弧度。 - * @param startAngle - 开始弧度,从正 x 轴顺时针方向测量。 - * @param endAngle - 结束弧度,从正 x 轴顺时针方向测量。 - * @param counterclockwise 如果为真,在两个角度之间逆时针绘制。默认顺时针。 + * @param cx @en The coordinate x-axis of the central control point. + * @zh 中心控制点的坐标 x 轴。 + * @param cy @en The coordinate y-axis of the central control point. + * @zh 中心控制点的坐标 y 轴。 + * @param r @en Angle in Radian. + * @zh 圆弧弧度。 + * @param startAngle @en The starting angle in radian, measured clockwise from the positive x-axis. + * @zh 弧度起点,从正 x 轴顺时针方向测量。 + * @param endAngle @en The ending angle in radian, measured clockwise from the positive x-axis. + * @zh 弧度终点,从正 x 轴顺时针方向测量。 + * @param counterclockwise @en If true, draws counterclockwise between the two angles. Default is clockwise. + * @zh 如果为真,在两个角度之间逆时针绘制。默认顺时针。 */ public arc (cx: number, cy: number, r: number, startAngle: number, endAngle: number, counterclockwise: boolean) { if (!this.impl) { @@ -400,10 +415,14 @@ export class Graphics extends UIRenderer { * @zh * 绘制椭圆路径。 * - * @param cx - 中心点的坐标 x 轴。 - * @param cy - 中心点的坐标 y 轴。 - * @param rx - 椭圆 x 轴半径。 - * @param ry - 椭圆 y 轴半径。 + * @param cx @en The x-axis coordinates of the center point. + * @zh 中心点的 x 轴坐标。 + * @param cy @en The y-axis coordinates of the center point. + * @zh 中心点的 y 轴坐标。 + * @param rx @en The radius of the x-axis of the ellipse. + * @zh 椭圆 x 轴半径。 + * @param ry @en The radius of the y-axis of the ellipse. + * @zh 椭圆 y 轴半径。 */ public ellipse (cx: number, cy: number, rx: number, ry: number) { if (!this.impl) { @@ -420,9 +439,12 @@ export class Graphics extends UIRenderer { * @zh * 绘制圆形路径。 * - * @param cx - 中心点的坐标 x 轴。 - * @param cy - 中心点的坐标 y 轴。 - * @param r - 圆半径。 + * @param cx @en The x-axis coordinates of the center point. + * @zh 中心点的 x 轴坐标。 + * @param cy @en The y-axis coordinates of the center point. + * @zh 中心点的 y 轴坐标。 + * @param r @en Radius. + * @zh 圆半径。 */ public circle (cx: number, cy: number, r: number) { if (!this.impl) { @@ -439,10 +461,14 @@ export class Graphics extends UIRenderer { * @zh * 绘制矩形路径。 * - * @param x - 矩形起始坐标 x 轴。 - * @param y - 矩形起始坐标 y 轴。 - * @param w - 矩形宽度。 - * @param h - 矩形高度。 + * @param x @en The x-axis coordinate of the top left point of the rectangle. + * @zh 矩形起始 x 轴坐标。 + * @param y @en The y-axis coordinate of the top left point of the rectangle. + * @zh 矩形起始 y 轴坐标。 + * @param w @en The width of the rectangle. + * @zh 矩形宽度。 + * @param h @en The height of the rectangle. + * @zh 矩形高度。 */ public rect (x: number, y: number, w: number, h: number) { if (!this.impl) { @@ -459,11 +485,16 @@ export class Graphics extends UIRenderer { * @zh * 绘制圆角矩形路径。 * - * @param x - 矩形起始坐标 x 轴。 - * @param y - 矩形起始坐标 y 轴。 - * @param w - 矩形宽度。 - * @param h - 矩形高度。 - * @param r - 矩形圆角半径。 + * @param x @en The x-axis coordinate of the top left point of the rectangle. + * @zh 矩形起始 x 轴坐标。 + * @param y @en The y-axis coordinate of the top left point of the rectangle. + * @zh 矩形起始 y 轴坐标。 + * @param w @en The width of the rectangle. + * @zh 矩形宽度。 + * @param h @en The height of the rectangle. + * @zh 矩形高度。 + * @param r @en Radius of rectangular rounded corners. + * @zh 矩形圆角半径。 */ public roundRect (x: number, y: number, w: number, h: number, r: number) { if (!this.impl) { @@ -480,10 +511,14 @@ export class Graphics extends UIRenderer { * @zh * 绘制填充矩形。 * - * @param x - 矩形起始坐标 x 轴。 - * @param y - 矩形起始坐标 y 轴。 - * @param w - 矩形宽度。 - * @param h - 矩形高度。 + * @param x @en The x-axis coordinate of the top left point of the rectangle. + * @zh 矩形起始 x 轴坐标。 + * @param y @en The y-axis coordinate of the top left point of the rectangle. + * @zh 矩形起始 y 轴坐标。 + * @param w @en The width of the rectangle. + * @zh 矩形宽度。 + * @param h @en The height of the rectangle. + * @zh 矩形高度。 */ public fillRect (x, y, w, h) { this.rect(x, y, w, h); diff --git a/cocos/2d/components/label-outline.ts b/cocos/2d/components/label-outline.ts index 68ff79713f..ddeb4e526f 100644 --- a/cocos/2d/components/label-outline.ts +++ b/cocos/2d/components/label-outline.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module ui - */ - import { ccclass, help, executionOrder, menu, tooltip, requireComponent, executeInEditMode, serializable } from 'cc.decorator'; import { Component } from '../../core/components/component'; import { Color } from '../../core/math'; diff --git a/cocos/2d/components/label-shadow.ts b/cocos/2d/components/label-shadow.ts index 9e094173b3..b56c31dfd7 100644 --- a/cocos/2d/components/label-shadow.ts +++ b/cocos/2d/components/label-shadow.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module ui - */ - import { ccclass, help, executionOrder, menu, tooltip, requireComponent, executeInEditMode, serializable } from 'cc.decorator'; import { Component } from '../../core/components/component'; import { Color, Vec2 } from '../../core/math'; diff --git a/cocos/2d/components/label.ts b/cocos/2d/components/label.ts index 404ce7e451..1097f9ba30 100644 --- a/cocos/2d/components/label.ts +++ b/cocos/2d/components/label.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module ui - */ - import { ccclass, help, executionOrder, menu, tooltip, displayOrder, visible, multiline, type, serializable, editable } from 'cc.decorator'; import { BYTEDANCE, EDITOR } from 'internal:constants'; import { minigame } from 'pal/minigame'; diff --git a/cocos/2d/components/mask.ts b/cocos/2d/components/mask.ts index 7466563a28..122672c010 100644 --- a/cocos/2d/components/mask.ts +++ b/cocos/2d/components/mask.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module ui - */ - import { ccclass, help, executionOrder, menu, tooltip, displayOrder, type, visible, override, serializable, range, slide } from 'cc.decorator'; import { InstanceMaterialType, UIRenderer } from '../framework/ui-renderer'; import { clamp, Color, Mat4, Vec2, Vec3 } from '../../core/math'; diff --git a/cocos/2d/components/rich-text.ts b/cocos/2d/components/rich-text.ts index 990d655506..8d59472278 100644 --- a/cocos/2d/components/rich-text.ts +++ b/cocos/2d/components/rich-text.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module ui - */ - import { ccclass, executeInEditMode, executionOrder, help, menu, tooltip, multiline, type, displayOrder, serializable } from 'cc.decorator'; import { DEV, EDITOR } from 'internal:constants'; import { Font, SpriteAtlas, TTFFont, SpriteFrame } from '../assets'; @@ -114,6 +109,7 @@ function getSegmentByPool (type: string, content: string | SpriteFrame) { seg.comp.string = content as string; seg.comp.horizontalAlign = HorizontalTextAlignment.LEFT; seg.comp.verticalAlign = VerticalTextAlignment.TOP; + seg.comp.underlineHeight = 2; } node.setPosition(0, 0, 0); const trans = node._uiProps.uiTransformComp!; diff --git a/cocos/2d/components/sprite.ts b/cocos/2d/components/sprite.ts index b199c018c3..ef1787056c 100644 --- a/cocos/2d/components/sprite.ts +++ b/cocos/2d/components/sprite.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module ui - */ - import { ccclass, help, executionOrder, menu, tooltip, displayOrder, type, range, editable, serializable, visible } from 'cc.decorator'; import { EDITOR } from 'internal:constants'; import { SpriteAtlas } from '../assets/sprite-atlas'; diff --git a/cocos/2d/components/ui-mesh-renderer.ts b/cocos/2d/components/ui-mesh-renderer.ts index dfc50e8549..cc147e34ca 100644 --- a/cocos/2d/components/ui-mesh-renderer.ts +++ b/cocos/2d/components/ui-mesh-renderer.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module ui - */ - import { ccclass, help, executionOrder, menu, executeInEditMode } from 'cc.decorator'; import { ModelRenderer } from '../../core/components/model-renderer'; import { RenderPriority } from '../../core/pipeline/define'; @@ -41,11 +36,11 @@ import { legacyCC } from '../../core/global-exports'; * @en * The component of model. * When you place particles or models in the UI, you must add this component to render. - * The component must be placed on a node with the [[MeshRenderer]] or the [[Particle]]. + * The component must be placed on a node with the [[MeshRenderer]] or the [[ParticleSystem]]. * * @zh * UI 模型基础组件。 - * 当你在 UI 中放置模型或者粒子的时候,必须添加该组件才能渲染。该组件必须放置在带有 [[MeshRenderer]] 或者 [[Particle]] 组件的节点上。 + * 当你在 UI 中放置模型或者粒子的时候,必须添加该组件才能渲染。该组件必须放置在带有 [[MeshRenderer]] 或者 [[ParticleSystem]] 组件的节点上。 */ @ccclass('cc.UIMeshRenderer') @help('i18n:cc.UIMeshRenderer') diff --git a/cocos/2d/components/ui-opacity.ts b/cocos/2d/components/ui-opacity.ts index 0bfcea196f..37d20d8e46 100644 --- a/cocos/2d/components/ui-opacity.ts +++ b/cocos/2d/components/ui-opacity.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module ui - */ - import { ccclass, disallowMultiple, editable, executeInEditMode, executionOrder, help, menu, serializable, tooltip } from 'cc.decorator'; import { Component } from '../../core/components/component'; import { clampf } from '../../core/utils/misc'; diff --git a/cocos/2d/components/ui-static-batch.ts b/cocos/2d/components/ui-static-batch.ts index 7a889f3e79..cbaaa6f7da 100644 --- a/cocos/2d/components/ui-static-batch.ts +++ b/cocos/2d/components/ui-static-batch.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module ui - */ - import { ccclass, help, menu, executionOrder, visible, override } from 'cc.decorator'; import { UIRenderer } from '../framework/ui-renderer'; import { IBatcher } from '../renderer/i-batcher'; diff --git a/cocos/2d/framework/canvas.ts b/cocos/2d/framework/canvas.ts index 1863e6d2c8..98e831135d 100644 --- a/cocos/2d/framework/canvas.ts +++ b/cocos/2d/framework/canvas.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module ui - */ - import { ccclass, help, disallowMultiple, executeInEditMode, executionOrder, menu, tooltip, type, serializable } from 'cc.decorator'; import { EDITOR } from 'internal:constants'; @@ -82,7 +77,7 @@ export class Canvas extends RenderRoot2D { * intersperse 下可以指定 Canvas 与场景中的相机的渲染顺序,overlay 下 Canvas 会在所有场景相机渲染完成后渲染。 * 注意:场景里的相机(包括 Canvas 内置的相机)必须有一个的 ClearFlag 选择 SOLID_COLOR,否则在移动端可能会出现闪屏。 * - * @deprecated since v3.0, please use [[cameraComponent.priority]] to control overlapping between cameras. + * @deprecated since v3.0, please use [[Camera.priority]] to control overlapping between cameras. */ get renderMode () { return this._renderMode; diff --git a/cocos/2d/framework/deprecated.ts b/cocos/2d/framework/deprecated.ts index fb89db4cc7..69223363d9 100644 --- a/cocos/2d/framework/deprecated.ts +++ b/cocos/2d/framework/deprecated.ts @@ -24,11 +24,6 @@ */ /* eslint-disable @typescript-eslint/no-unsafe-return */ -/** - * @packageDocumentation - * @module ui - */ - import { markAsWarning, removeProperty, replaceProperty } from '../../core/utils'; import { UIComponent } from './ui-component'; import { UITransform } from './ui-transform'; diff --git a/cocos/2d/framework/render-root-2d.ts b/cocos/2d/framework/render-root-2d.ts index 049fb2abd1..839dcc64dd 100644 --- a/cocos/2d/framework/render-root-2d.ts +++ b/cocos/2d/framework/render-root-2d.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module ui - */ - import { ccclass, disallowMultiple, executeInEditMode, executionOrder, menu, requireComponent } from 'cc.decorator'; import { Component } from '../../core/components/component'; diff --git a/cocos/2d/framework/ui-component.ts b/cocos/2d/framework/ui-component.ts index f726b57709..7aee8f2910 100644 --- a/cocos/2d/framework/ui-component.ts +++ b/cocos/2d/framework/ui-component.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module ui - */ - import { ccclass, disallowMultiple, executeInEditMode, executionOrder, requireComponent } from 'cc.decorator'; import { IBatcher } from '../renderer/i-batcher'; import { Component } from '../../core/components/component'; @@ -37,9 +32,9 @@ import { Stage } from '../renderer/stencil-manager'; /** * @en Legacy 2D base class for rendering component, please use [[Renderable2D]] instead. - * This component will setup [[NodeUIProperties.uiComp]] in its owner [[Node]] + * This component will setup NodeUIProperties.uiComp in its owner [[Node]] * @zh 旧的 2D 渲染组件基类,请使用 [[Renderable2D]] 替代。 - * 这个组件会设置 [[Node]] 上的 [[NodeUIProperties.uiComp]]。 + * 这个组件会设置 [[Node]] 上的 NodeUIProperties.uiComp。 * @deprecated since v3.4.1 */ @ccclass('cc.UIComponent') diff --git a/cocos/2d/framework/ui-renderer.ts b/cocos/2d/framework/ui-renderer.ts index 7412cd1571..40c8b4f004 100644 --- a/cocos/2d/framework/ui-renderer.ts +++ b/cocos/2d/framework/ui-renderer.ts @@ -101,10 +101,10 @@ export enum InstanceMaterialType { /** * @en Base class for UI components which supports rendering features. - * This component will setup [[NodeUIProperties.uiComp]] in its owner [[Node]] + * This component will setup NodeUIProperties.uiComp in its owner [[Node]] * * @zh 所有支持渲染的 UI 组件的基类。 - * 这个组件会设置 [[Node]] 上的 [[NodeUIProperties.uiComp]]。 + * 这个组件会设置 [[Node]] 上的 NodeUIProperties.uiComp。 */ @ccclass('cc.UIRenderer') @requireComponent(UITransform) @@ -114,7 +114,7 @@ export class UIRenderer extends Renderer { /** * @en The blend factor enums * @zh 混合模式枚举类型 - * @see [[BlendFactor]] + * @see [[gfx.BlendFactor]] */ public static BlendState = BlendFactor; /** diff --git a/cocos/2d/framework/ui-transform.ts b/cocos/2d/framework/ui-transform.ts index 9d4eb8409f..6f0e90814e 100644 --- a/cocos/2d/framework/ui-transform.ts +++ b/cocos/2d/framework/ui-transform.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module ui - */ - import { ccclass, help, executeInEditMode, executionOrder, menu, tooltip, displayOrder, serializable, disallowMultiple } from 'cc.decorator'; import { EDITOR } from 'internal:constants'; import { Component } from '../../core/components'; @@ -367,8 +362,10 @@ export class UITransform extends Component { * 默认的锚点是(0.5,0.5),因此它开始于节点的中心位置。
* 注意:Creator 中的锚点仅用于定位所在的节点,子节点的定位不受影响。 * - * @param point - 节点锚点或节点 x 轴锚。 - * @param y - 节点 y 轴锚。 + * @param point @en Node anchor point or node x-axis anchor. + * @zh 节点锚点或节点 x 轴锚。 + * @param y @en The y-axis anchor of the node. + * @zh 节点 y 轴锚。 * @example * ```ts * import { Vec2 } from 'cc'; @@ -401,7 +398,8 @@ export class UITransform extends Component { } /** - * Hit test with point in UI Space. + * @zh UI 空间中的点击测试。 + * @en Hit test with point in UI Space. * * @param uiPoint point in UI Space. * @deprecated since v3.5.0, please use `uiTransform.hitTest(screenPoint: Vec2)` instead. @@ -447,13 +445,13 @@ export class UITransform extends Component { return false; } - /** - * Hit test with point in Screen Space. + * @zh 屏幕空间中的点击测试。 + * @en Hit test with point in Screen Space. * * @param screenPoint point in Screen Space. */ - public hitTest (screenPoint: Vec2) { + public hitTest (screenPoint: Vec2) { const w = this._contentSize.width; const h = this._contentSize.height; const v3WorldPt = _vec3a; @@ -529,9 +527,12 @@ export class UITransform extends Component { * 将一个 UI 节点世界坐标系下点转换到另一个 UI 节点 (局部) 空间坐标系,这个坐标系以锚点为原点。 * 非 UI 节点转换到 UI 节点(局部) 空间坐标系,请走 Camera 的 `convertToUINode`。 * - * @param worldPoint - 世界坐标点。 - * @param out - 转换后坐标。 - * @returns - 返回与目标节点的相对位置。 + * @param worldPoint @en Point in world space. + * @zh 世界坐标点。 + * @param out @en Point in local space. + * @zh 转换后坐标。 + * @returns @en Return the relative position to the target node. + * @zh 返回与目标节点的相对位置。 * @example * ```ts * const newVec3 = uiTransform.convertToNodeSpaceAR(cc.v3(100, 100, 0)); @@ -554,9 +555,12 @@ export class UITransform extends Component { * @zh * 将距当前节点坐标系下的一个点转换到世界坐标系。 * - * @param nodePoint - 节点坐标。 - * @param out - 转换后坐标。 - * @returns - 返回 UI 世界坐标系。 + * @param nodePoint @en Point in local space. + * @zh 节点坐标。 + * @param out @en Point in world space. + * @zh 转换后坐标。 + * @returns @en Returns the coordinates in the UI world coordinate system. + * @zh 返回 UI 世界坐标系。 * @example * ```ts * const newVec3 = uiTransform.convertToWorldSpaceAR(3(100, 100, 0)); @@ -629,7 +633,8 @@ export class UITransform extends Component { * @zh * 返回包含当前包围盒及其子节点包围盒的最小包围盒。 * - * @param parentMat - 父节点矩阵。 + * @param parentMat @en The parent node matrix. + * @zh 父节点矩阵。 * @returns */ public getBoundingBoxTo (parentMat: Mat4) { diff --git a/cocos/2d/renderer/batcher-2d.ts b/cocos/2d/renderer/batcher-2d.ts index 10f5a93e27..221ef04204 100644 --- a/cocos/2d/renderer/batcher-2d.ts +++ b/cocos/2d/renderer/batcher-2d.ts @@ -148,7 +148,8 @@ export class Batcher2D implements IBatcher { * @zh * 添加屏幕组件管理。 * - * @param comp - 屏幕组件。 + * @param comp @en The render root of 2d. + * @zh 2d 渲染入口组件。 */ public addScreen (comp: RenderRoot2D) { this._screens.push(comp); @@ -159,7 +160,8 @@ export class Batcher2D implements IBatcher { * @zh * Removes the Canvas from the list. * - * @param comp - 被移除的屏幕。 + * @param comp @en The target to removed. + * @zh 被移除的屏幕。 */ public removeScreen (comp: RenderRoot2D) { const idx = this._screens.indexOf(comp); @@ -273,8 +275,9 @@ export class Batcher2D implements IBatcher { } /** - * Switch the mesh buffer for corresponding vertex layout if necessary. - * @param attributes use [[VertexFormat.vfmtPosUvColor]] by default + * @zh 如果有必要,为相应的顶点布局切换网格缓冲区。 + * @en Switch the mesh buffer for corresponding vertex layout if necessary. + * @param attributes use VertexFormat.vfmtPosUvColor by default */ public switchBufferAccessor (attributes: Attribute[] = vfmtPosUvColor) { const strideBytes = attributes === vfmtPosUvColor ? 36 /* 9x4 */ : getAttributeStride(attributes); @@ -368,12 +371,12 @@ export class Batcher2D implements IBatcher { /** * @en - * Render component data submission process for individual [[InputAssembler]] + * Render component data submission process for individual [[gfx.InputAssembler]] * @zh - * 渲染组件中针对独立 [[InputAssembler]] 的提交流程 + * 渲染组件中针对独立 [[gfx.InputAssembler]] 的提交流程 * 例如:Spine 和 DragonBones 等包含动态数据和材质的组件在内部管理 IA 并提交批次 * @param comp - The committed renderable component - * @param ia - The committed [[InputAssembler]] + * @param ia - The committed [[gfx.InputAssembler]] * @param tex - The texture used * @param mat - The material used * @param [transform] - The related node transform if the render data is based on node's local coordinates @@ -489,7 +492,8 @@ export class Batcher2D implements IBatcher { * * @zh * 提交独立渲染数据. - * @param comp 静态组件 + * @param comp @en The UIStaticBatch component. + * @zh 静态组件 */ public commitStaticBatch (comp: UIStaticBatch) { this._batches.concat(comp.drawBatchList); @@ -577,8 +581,10 @@ export class Batcher2D implements IBatcher { * @zh * 强行修改当前批次数据并合并。 * - * @param material - 当前批次的材质。 - * @param sprite - 当前批次的精灵帧。 + * @param material @en The material of the current batch. + * @zh 当前批次的材质。 + * @param sprite @en Sprite frame of current batch. + * @zh 当前批次的精灵帧。 */ public forceMergeBatches (material: Material, frame: TextureBase | SpriteFrame | null, renderComp: UIRenderer) { this._currMaterial = material; diff --git a/cocos/2d/renderer/buffer-accessor.ts b/cocos/2d/renderer/buffer-accessor.ts index c5979e7d9f..1e6794a5e6 100644 --- a/cocos/2d/renderer/buffer-accessor.ts +++ b/cocos/2d/renderer/buffer-accessor.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module ui - */ - import { Attribute, Device } from '../../core/gfx'; import type { MeshBuffer } from './mesh-buffer'; import { getComponentPerVertex } from './vertex-format'; diff --git a/cocos/2d/renderer/linear-buffer-accessor.ts b/cocos/2d/renderer/linear-buffer-accessor.ts index 1af212e838..8b26bd871f 100644 --- a/cocos/2d/renderer/linear-buffer-accessor.ts +++ b/cocos/2d/renderer/linear-buffer-accessor.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module ui - */ - import { InputAssembler, Device, Attribute } from '../../core/gfx'; import { MeshBuffer } from './mesh-buffer'; import { BufferAccessor } from './buffer-accessor'; diff --git a/cocos/2d/renderer/mesh-buffer.ts b/cocos/2d/renderer/mesh-buffer.ts index 5177e0d048..36efd84712 100644 --- a/cocos/2d/renderer/mesh-buffer.ts +++ b/cocos/2d/renderer/mesh-buffer.ts @@ -23,10 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module ui - */ import { Device, BufferUsageBit, MemoryUsageBit, Attribute, Buffer, BufferInfo, InputAssembler, InputAssemblerInfo } from '../../core/gfx'; import { getComponentPerVertex } from './vertex-format'; import { getError, warnID } from '../../core/platform/debug'; @@ -137,7 +133,7 @@ export class MeshBuffer { } public checkCapacity (vertexCount: number, indexCount: number) { - const maxVertex = this.vertexOffset + vertexCount; + const maxVertex = (this.vertexOffset + vertexCount) * this._floatsPerVertex; const maxIndex = this.indexOffset + indexCount; if (maxVertex > this._initVDataCount || maxIndex > this._initIDataCount) { return false; diff --git a/cocos/2d/renderer/render-data.ts b/cocos/2d/renderer/render-data.ts index 042647e692..df3b976bdb 100644 --- a/cocos/2d/renderer/render-data.ts +++ b/cocos/2d/renderer/render-data.ts @@ -36,6 +36,9 @@ import { getAttributeStride, vfmtPosUvColor } from './vertex-format'; import { Buffer, BufferInfo, BufferUsageBit, Device, InputAssembler, InputAssemblerInfo, MemoryUsageBit } from '../../core/gfx'; import { assertIsTrue } from '../../core/data/utils/asserts'; +/** + * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. + */ export interface IRenderData { x: number; y: number; @@ -58,6 +61,9 @@ const _dataPool = new Pool(() => ({ let _pool: RecyclePool = null!; +/** + * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. + */ export class BaseRenderData { public material: Material | null = null; get vertexCount () { @@ -96,6 +102,9 @@ export class BaseRenderData { } } +/** + * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. + */ export class RenderData extends BaseRenderData { public static add (vertexFormat = vfmtPosUvColor, accessor?: StaticVBAccessor) { if (!_pool) { @@ -305,6 +314,9 @@ export class RenderData extends BaseRenderData { } } +/** + * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. + */ export class MeshRenderData extends BaseRenderData { public static add (vertexFormat = vfmtPosUvColor) { const rd = _meshDataPool.add(); diff --git a/cocos/2d/renderer/static-vb-accessor.ts b/cocos/2d/renderer/static-vb-accessor.ts index aafc4defd9..191b6b20a7 100644 --- a/cocos/2d/renderer/static-vb-accessor.ts +++ b/cocos/2d/renderer/static-vb-accessor.ts @@ -23,12 +23,10 @@ THE SOFTWARE. */ - - import { Device, Attribute } from '../../core/gfx'; import { MeshBuffer } from './mesh-buffer'; import { BufferAccessor } from './buffer-accessor'; -import { assertID, warnID } from '../../core/platform/debug'; +import { assertID, errorID } from '../../core/platform/debug'; import { assertIsTrue } from '../../core/data/utils/asserts'; import { Pool } from '../../core/memop/pool'; import { macro } from '../../core/platform/macro'; @@ -170,7 +168,7 @@ export class StaticVBAccessor extends BufferAccessor { return new StaticVBChunk(this, bid, buf, vertexOffset, vb, indexCount); } else { - warnID(9004, byteLength); + errorID(9004, byteLength); return null; } } diff --git a/cocos/2d/renderer/stencil-manager.ts b/cocos/2d/renderer/stencil-manager.ts index 751aa7529a..75a253ac99 100644 --- a/cocos/2d/renderer/stencil-manager.ts +++ b/cocos/2d/renderer/stencil-manager.ts @@ -23,7 +23,6 @@ THE SOFTWARE. */ - import { ComparisonFunc, StencilOp, DepthStencilState } from '../../core/gfx'; import { Mask } from '../components/mask'; import { Material } from '../../core'; diff --git a/cocos/2d/utils/dynamic-atlas/atlas-manager.ts b/cocos/2d/utils/dynamic-atlas/atlas-manager.ts index d2d7423108..7eb651a10a 100644 --- a/cocos/2d/utils/dynamic-atlas/atlas-manager.ts +++ b/cocos/2d/utils/dynamic-atlas/atlas-manager.ts @@ -1,7 +1,3 @@ -/** - * @packageDocumentation - */ - import { EDITOR } from 'internal:constants'; import { Filter } from '../../../core/assets/asset-enum'; import { legacyCC } from '../../../core/global-exports'; diff --git a/cocos/2d/utils/dynamic-atlas/atlas.ts b/cocos/2d/utils/dynamic-atlas/atlas.ts index ebb580b312..6e7f29b5a2 100644 --- a/cocos/2d/utils/dynamic-atlas/atlas.ts +++ b/cocos/2d/utils/dynamic-atlas/atlas.ts @@ -1,7 +1,3 @@ -/** - * @packageDocumentation - */ - import { PixelFormat } from '../../../core/assets/asset-enum'; import { ImageAsset } from '../../../core/assets/image-asset'; import { Texture2D } from '../../../core/assets/texture-2d'; diff --git a/cocos/2d/utils/font-loader.ts b/cocos/2d/utils/font-loader.ts index d2550456ed..71d77ff2d1 100644 --- a/cocos/2d/utils/font-loader.ts +++ b/cocos/2d/utils/font-loader.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { warnID } from '../../core/platform/debug'; import { safeMeasureText } from './text-utils'; import { CompleteCallback, IDownloadParseOptions } from '../../core/asset-manager/shared'; diff --git a/cocos/2d/utils/html-text-parser.ts b/cocos/2d/utils/html-text-parser.ts index 23b3bec0d3..50658368ee 100644 --- a/cocos/2d/utils/html-text-parser.ts +++ b/cocos/2d/utils/html-text-parser.ts @@ -28,19 +28,23 @@ import { TEST } from 'internal:constants'; import { legacyCC } from '../../core/global-exports'; /** - * + * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. */ const eventRegx = /^(click)(\s)*=|(param)(\s)*=/; const imageAttrReg = /(\s)*src(\s)*=|(\s)*height(\s)*=|(\s)*width(\s)*=|(\s)*align(\s)*=|(\s)*offset(\s)*=|(\s)*click(\s)*=|(\s)*param(\s)*=/; + /** * A utils class for parsing HTML texts. The parsed results will be an object array. + * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. */ - export interface IHtmlTextParserResultObj{ text?: string; style?: IHtmlTextParserStack; } +/** + * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. + */ export interface IHtmlTextParserStack{ color?: string; size?: number; @@ -58,6 +62,9 @@ export interface IHtmlTextParserStack{ outline?: { color: string, width: number }; } +/** + * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. + */ export class HtmlTextParser { private _specialSymbolArray: Array<[RegExp, string]> = []; private _stack: IHtmlTextParserStack[] = []; @@ -165,6 +172,7 @@ export class HtmlTextParser { header = /^(img(\s)*src(\s)*=[^>]+\/)/.exec(attribute); let remainingArgument = ''; + let rightQuot = -1; if (header && header[0].length > 0) { tagName = header[0].trim(); if (tagName.startsWith('img') && tagName[tagName.length - 1] === '/') { @@ -177,7 +185,10 @@ export class HtmlTextParser { tagName = attribute.substr(0, header[0].length); // remove space and = character remainingArgument = attribute.substring(tagName.length).trim(); - nextSpace = remainingArgument.indexOf(' '); + + rightQuot = this.getRightQuotationIndex(remainingArgument); + + nextSpace = remainingArgument.indexOf(' ', rightQuot + 1 >= remainingArgument.length ? -1 : rightQuot + 1); tagValue = (nextSpace > -1) ? remainingArgument.substr(0, nextSpace) : remainingArgument; tagName = tagName.replace(/[^a-zA-Z]/g, '').trim(); @@ -301,6 +312,21 @@ export class HtmlTextParser { return obj; } + private getRightQuotationIndex (remainingArgument: string) { + let leftQuot = -1; + let rightQuot = -1; + // Skip a pair of quotations for avoiding spaces in image name are detected. + leftQuot = remainingArgument.indexOf('\''); + if (leftQuot > -1) { + rightQuot = remainingArgument.indexOf('\'', leftQuot + 1 >= remainingArgument.length ? -1 : leftQuot + 1); + } else { + leftQuot = remainingArgument.indexOf('"'); + rightQuot = remainingArgument.indexOf('"', leftQuot + 1 >= remainingArgument.length ? -1 : leftQuot + 1); + } + + return rightQuot; + } + private _processEventHandler (eventString: string) { const obj = {}; let index = 0; diff --git a/cocos/2d/utils/text-utils.ts b/cocos/2d/utils/text-utils.ts index ff4ec37c3a..6c2fe47d36 100644 --- a/cocos/2d/utils/text-utils.ts +++ b/cocos/2d/utils/text-utils.ts @@ -160,9 +160,9 @@ const measureCache = new LRUCache(MAX_CACHE_SIZE); const WORD_REG = /([a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôûа-яА-ЯЁё]+|\S)/; // eslint-disable-next-line no-useless-escape const SYMBOL_REG = /^[!,.:;'}\]%\?>、‘“》?。,!]/; -const LAST_WORD_REG = /([a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôûаíìÍÌïÁÀáàÉÈÒÓòóŐőÙÚŰúűñÑæÆœŒÃÂãÔõěščřžýáíéóúůťďňĚŠČŘŽÁÍÉÓÚŤżźśóńłęćąŻŹŚÓŃŁĘĆĄ-яА-ЯЁё]+|\S)$/; -const LAST_ENGLISH_REG = /[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôûаíìÍÌïÁÀáàÉÈÒÓòóŐőÙÚŰúűñÑæÆœŒÃÂãÔõěščřžýáíéóúůťďňĚŠČŘŽÁÍÉÓÚŤżźśóńłęćąŻŹŚÓŃŁĘĆĄ-яА-ЯЁё]+$/; -const FIRST_ENGLISH_REG = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôûаíìÍÌïÁÀáàÉÈÒÓòóŐőÙÚŰúűñÑæÆœŒÃÂãÔõěščřžýáíéóúůťďňĚŠČŘŽÁÍÉÓÚŤżźśóńłęćąŻŹŚÓŃŁĘĆĄ-яА-ЯЁё]/; +const LAST_WORD_REG = /([a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôûаíìÍÌïÁÀáàÉÈÒÓòóŐőÙÚŰúűñÑæÆœŒÃÂãÔõěščřžýáíéóúůťďňĚŠČŘŽÁÍÉÓÚŤżźśóńłęćąŻŹŚÓŃŁĘĆĄ-яА-ЯЁёáàảạãăắằẳẵặâấầẩẫậéèẻẽẹêếềểễệiíìỉĩịóòỏõọôốồổỗộơớờởỡợúùủũụưứừửữựýỳỷỹỵđÁÀẢẠÃĂẮẰẲẴẶÂẤẦẨẪẬÉÈẺẼẸÊẾỀỂỄỆIÍÌỈĨỊÓÒỎÕỌÔỐỒỔỖỘƠỚỜỞỠỢÚÙỦŨỤƯỨỪỬỮỰÝỲỶỸỴĐ]+|\S)$/; +const LAST_ENGLISH_REG = /[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôûаíìÍÌïÁÀáàÉÈÒÓòóŐőÙÚŰúűñÑæÆœŒÃÂãÔõěščřžýáíéóúůťďňĚŠČŘŽÁÍÉÓÚŤżźśóńłęćąŻŹŚÓŃŁĘĆĄ-яА-ЯЁёáàảạãăắằẳẵặâấầẩẫậéèẻẽẹêếềểễệiíìỉĩịóòỏõọôốồổỗộơớờởỡợúùủũụưứừửữựýỳỷỹỵđÁÀẢẠÃĂẮẰẲẴẶÂẤẦẨẪẬÉÈẺẼẸÊẾỀỂỄỆIÍÌỈĨỊÓÒỎÕỌÔỐỒỔỖỘƠỚỜỞỠỢÚÙỦŨỤƯỨỪỬỮỰÝỲỶỸỴĐ]+$/; +const FIRST_ENGLISH_REG = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôûаíìÍÌïÁÀáàÉÈÒÓòóŐőÙÚŰúűñÑæÆœŒÃÂãÔõěščřžýáíéóúůťďňĚŠČŘŽÁÍÉÓÚŤżźśóńłęćąŻŹŚÓŃŁĘĆĄ-яА-ЯЁёáàảạãăắằẳẵặâấầẩẫậéèẻẽẹêếềểễệiíìỉĩịóòỏõọôốồổỗộơớờởỡợúùủũụưứừửữựýỳỷỹỵđÁÀẢẠÃĂẮẰẲẴẶÂẤẦẨẪẬÉÈẺẼẸÊẾỀỂỄỆIÍÌỈĨỊÓÒỎÕỌÔỐỒỔỖỘƠỚỜỞỠỢÚÙỦŨỤƯỨỪỬỮỰÝỲỶỸỴĐ]/; const WRAP_INSPECTION = true; // The unicode standard will never assign a character from code point 0xD800 to 0xDFFF // high surrogate (0xD800-0xDBFF) and low surrogate(0xDC00-0xDFFF) combines to a character on the Supplementary Multilingual Plane diff --git a/cocos/3d/assets/index.ts b/cocos/3d/assets/index.ts index bcf222903b..233c1d6ce2 100644 --- a/cocos/3d/assets/index.ts +++ b/cocos/3d/assets/index.ts @@ -28,3 +28,4 @@ import './deprecated'; export { Mesh } from './mesh'; export { Skeleton } from './skeleton'; +export type { Morph, MorphTarget, SubMeshMorph } from './morph'; diff --git a/cocos/3d/assets/mesh.ts b/cocos/3d/assets/mesh.ts index 2928a12d6d..cb060de249 100644 --- a/cocos/3d/assets/mesh.ts +++ b/cocos/3d/assets/mesh.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module asset - */ - import { ccclass, serializable } from 'cc.decorator'; import { Asset } from '../../core/assets/asset'; import { IDynamicGeometry } from '../../primitive/define'; @@ -45,7 +40,8 @@ import { FormatInfos, FormatType, MemoryUsageBit, PrimitiveMode, getTypedArrayConstructor, DrawInfo, } from '../../core/gfx'; import { Mat4, Quat, Vec3 } from '../../core/math'; -import { Morph, MorphRendering, createMorphRendering } from './morph'; +import { Morph } from './morph'; +import { MorphRendering, createMorphRendering } from './morph-rendering'; function getIndexStrideCtor (stride: number) { switch (stride) { @@ -669,8 +665,9 @@ export class Mesh extends Asset { } /** - * @en Get [[AABB]] bounds in the skeleton's bone space - * @zh 获取骨骼变换空间内下的 [[AABB]] 包围盒 + * @en Get [[geometry.AABB]] bounds in the skeleton's bone space + * @zh 获取骨骼变换空间内下的 [[geometry.AABB]] 包围盒 + * @param skeleton @en skeleton data @zh 骨骼信息 * @param skeleton @en skeleton data @zh 骨骼信息 */ public getBoneSpaceBounds (skeleton: Skeleton) { diff --git a/cocos/3d/assets/morph-rendering.ts b/cocos/3d/assets/morph-rendering.ts index c0c4852bfc..0a87f7cc6b 100644 --- a/cocos/3d/assets/morph-rendering.ts +++ b/cocos/3d/assets/morph-rendering.ts @@ -23,11 +23,8 @@ THE SOFTWARE. */ - - import { - AttributeName, Buffer, BufferUsageBit, Device, Feature, MemoryUsageBit, DescriptorSet, BufferInfo, - FormatFeatureBit, Format, + AttributeName, Buffer, BufferUsageBit, Device, MemoryUsageBit, DescriptorSet, BufferInfo, FormatFeatureBit, Format, } from '../../core/gfx'; import { Mesh } from './mesh'; import { Texture2D } from '../../core/assets/texture-2d'; @@ -35,7 +32,7 @@ import { ImageAsset } from '../../core/assets/image-asset'; import { UBOMorph, UNIFORM_NORMAL_MORPH_TEXTURE_BINDING, UNIFORM_POSITION_MORPH_TEXTURE_BINDING, UNIFORM_TANGENT_MORPH_TEXTURE_BINDING } from '../../core/pipeline/define'; import { warn } from '../../core/platform/debug'; -import { Morph, MorphRendering, MorphRenderingInstance, SubMeshMorph } from './morph'; +import { Morph, SubMeshMorph } from './morph'; import { assertIsNonNullable, assertIsTrue } from '../../core/data/utils/asserts'; import { log2, nextPow2 } from '../../core/math/bits'; import { IMacroPatch } from '../../core/renderer'; @@ -44,13 +41,67 @@ import { PixelFormat } from '../../core/assets/asset-enum'; /** * True if force to use cpu computing based sub-mesh rendering. + * Only customizable by modify the internal engine code. */ const preferCpuComputing = false; /** - * Standard morph rendering. - * The standard morph rendering renders each of sub-mesh morph separately. - * Sub-mesh morph rendering may select different technique according sub-mesh morph itself. + * @en Interface for classes which control the rendering of morph resources. + * @zh 支持形变网格渲染的基类。 + */ +export interface MorphRendering { + createInstance (): MorphRenderingInstance; +} + +/** + * @en The instance of [[MorphRendering]] for dedicated control in the mesh renderer. + * The root [[MorphRendering]] is owned by [[Mesh]] asset, each [[MeshRenderer]] can have its own morph rendering instance. + * @zh 用于网格渲染器中独立控制 [[MorphRendering]] 的实例。原始 [[MorphRendering]] 被 [[Mesh]] 资源持有,每个 [[MeshRenderer]] 都持有自己的形变网格渲染实例。 + */ +export interface MorphRenderingInstance { + /** + * Sets weights of targets of specified sub mesh. + * @param subMeshIndex + * @param weights + */ + setWeights (subMeshIndex: number, weights: number[]): void; + + /** + * Adapts pipeline state to do the rendering. + * @param subMeshIndex + * @param pipelineState + */ + adaptPipelineState (subMeshIndex: number, descriptorSet: DescriptorSet): void; + + /** + * Acquire the define overrides needed to do the rendering. + */ + requiredPatches (subMeshIndex: number): IMacroPatch[] | null; + + /** + * Destroy the rendering instance. + */ + destroy (): void; +} + +/** + * @en Create morph rendering from mesh which contains morph targets data. + * @zh 从包含形变对象的网格资源中创建形变网格渲染对象。 + * @param mesh @en The mesh to create morph rendering from. @zh 用于创建形变网格渲染对象的原始网格资源。 + * @param gfxDevice @en The device instance acquired from [[Root]]. @zh 设备对象实例,可以从 [[Root]] 获取。 + */ +export function createMorphRendering (mesh: Mesh, gfxDevice: Device): MorphRendering { + return new StdMorphRendering(mesh, gfxDevice); +} + +/** + * @en Standard morph rendering class, it supports both GPU and CPU based morph blending. + * If sub mesh morph targets count is less than [[pipeline.UBOMorph.MAX_MORPH_TARGET_COUNT]], then GPU based blending is enabled. + * Each of the sub-mesh morph has its own [[MorphRenderingInstance]], + * its morph target weights, render pipeline state and strategy of morph blending are controlled separately. + * @zh 标准形变网格渲染类,它同时支持 CPU 和 GPU 的形变混合计算。 + * 如果子网格形变目标数量少于 [[pipeline.UBOMorph.MAX_MORPH_TARGET_COUNT]],那么就会使用基于 GPU 的形变混合计算。 + * 每个子网格形变都使用自己独立的 [[MorphRenderingInstance]],它的形变目标权重、渲染管线状态和形变混合计算策略都是独立控制的。 */ export class StdMorphRendering implements MorphRendering { private _mesh: Mesh; @@ -138,7 +189,8 @@ export class StdMorphRendering implements MorphRendering { } /** - * Describes how to render a sub-mesh morph. + * @en Sub-mesh morph rendering describes how to render a sub-mesh morph. + * @zh 子网格形变渲染定义如何渲染一个子网格形变。 */ interface SubMeshMorphRendering { /** @@ -148,7 +200,9 @@ interface SubMeshMorphRendering { } /** - * The instance of once sub-mesh morph rendering. + * @en The instance of sub-mesh morph rendering, each sub-mesh have its own instance + * for controlling its morph target weights, render pipeline state and strategy of morph blending. + * @zh 子网格形变渲染的实例,每个子网格都拥有自己独立的子网格形变渲染实例,用于独立控制形变目标权重、渲染管线状态和形变混合计算策略。 */ interface SubMeshMorphRenderingInstance { /** @@ -467,11 +521,6 @@ class MorphUniforms { } } -/** - * - * @param gfxDevice - * @param vec4Capacity Capacity of vec4. - */ function createVec4TextureFactory (gfxDevice: Device, vec4Capacity: number) { const hasFeatureFloatTexture = gfxDevice.getFormatFeatures(Format.RGBA32F) & FormatFeatureBit.SAMPLED_TEXTURE; @@ -563,12 +612,8 @@ function createVec4TextureFactory (gfxDevice: Device, vec4Capacity: number) { type MorphTexture = ReturnType['create']>; /** - * When use vertex-texture-fetch technique, we do need - * `gl_vertexId` when we sample per-vertex data. + * When use vertex-texture-fetch technique, we do need `gl_vertexId` when we sample per-vertex data. * WebGL 1.0 does not have `gl_vertexId`; WebGL 2.0, however, does. - * @param mesh - * @param subMeshIndex - * @param gfxDevice */ function enableVertexId (mesh: Mesh, subMeshIndex: number, gfxDevice: Device) { mesh.renderingSubMeshes[subMeshIndex].enableVertexIdChannel(gfxDevice); diff --git a/cocos/3d/assets/morph.ts b/cocos/3d/assets/morph.ts index 7611da99af..9ba9877fca 100644 --- a/cocos/3d/assets/morph.ts +++ b/cocos/3d/assets/morph.ts @@ -23,31 +23,13 @@ THE SOFTWARE. */ - - -import { AttributeName, Device, DescriptorSet } from '../../core/gfx'; +import { AttributeName } from '../../core/gfx'; import { Mesh } from './mesh'; -import { StdMorphRendering } from './morph-rendering'; -import { IMacroPatch } from '../../core/renderer'; - -export interface Morph { - /** - * Morph data of each sub-mesh. - */ - subMeshMorphs: (SubMeshMorph | null)[]; - - /** - * Common initial weights of each sub-mesh. - */ - weights?: number[]; - - /** - * Name of each target of each sub-mesh morph. - * This field is only meaningful if every sub-mesh has the same number of targets. - */ - targetNames?: string[]; -} +/** + * @en Morph target contains all displacements data of each vertex attribute like position and normal. + * @zh 形变目标数据包含网格顶点属性在形变下的变化值,可能包含位移、法线等属性 + */ export interface MorphTarget { /** * Displacement of each target attribute. @@ -55,6 +37,11 @@ export interface MorphTarget { displacements: Mesh.IBufferView[]; } +/** + * @en Sub mesh morph data describes all morph targets for one sub mesh, + * including attributes in each morph target, morph targets data and weights corresponding each targets. + * @zh 子网格形变数据描述一个子网格下所有的形变目标数据,包含顶点形变属性,形变目标数据和对应每个形变目标的权重。 + */ export interface SubMeshMorph { /** * Attributes to morph. @@ -72,39 +59,28 @@ export interface SubMeshMorph { weights?: number[]; } -export function createMorphRendering (mesh: Mesh, gfxDevice: Device): MorphRendering | null { - return new StdMorphRendering(mesh, gfxDevice); -} - /** - * Class which control rendering of a morph resource. + * @en Mesh morph data structure to describe the sub meshes data of all sub meshes, + * it also contains all sub mesh morphs, global weights configuration and target names. + * Normally the global weights configuration should be identical to the sub mesh morph weights, + * but if not, the global weights in morph is less prioritized. + * @zh 网格的形变数据结构,包含所有子网格形变数据,全局的权重配置和所有形变目标名称。 + * 一般来说,全局权重配置和子网格形变数据中保持一致,但如果有差异,以子网格形变数据中的权重配置为准。 */ -export interface MorphRendering { - createInstance (): MorphRenderingInstance; -} - -/** - * This rendering instance of a morph resource. - */ -export interface MorphRenderingInstance { - /** - * Sets weights of targets of specified sub mesh. - * @param subMeshIndex - * @param weights - */ - setWeights (subMeshIndex: number, weights: number[]): void; - - /** - * Adapts pipeline state to do the rendering. - * @param subMeshIndex - * @param pipelineState - */ - adaptPipelineState (subMeshIndex: number, descriptorSet: DescriptorSet): void; - - requiredPatches (subMeshIndex: number): IMacroPatch[] | null; - - /** - * Destroy the rendering instance. - */ - destroy (): void; +export interface Morph { + /** + * Morph data of each sub-mesh. + */ + subMeshMorphs: (SubMeshMorph | null)[]; + + /** + * Common initial weights of each sub-mesh. + */ + weights?: number[]; + + /** + * Name of each target of each sub-mesh morph. + * This field is only meaningful if every sub-mesh has the same number of targets. + */ + targetNames?: string[]; } diff --git a/cocos/3d/assets/skeleton.ts b/cocos/3d/assets/skeleton.ts index 39871a6c1f..fea8cbe7fa 100644 --- a/cocos/3d/assets/skeleton.ts +++ b/cocos/3d/assets/skeleton.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module asset - */ - import { ccclass, type, serializable } from 'cc.decorator'; import { CCString } from '../../core/data/utils/attribute'; import { Mat4 } from '../../core/math'; @@ -119,6 +114,11 @@ export class Skeleton extends Asset { return super.destroy(); } + /** + * @en Check whether the skeleton is validate which means it has both joints and bindposes data. + * @zh 检查当前骨骼对象是否是有效的,取决于它是否包含关节路径和绑定姿势数据。 + * @returns @en Whether the skeleton is valid or not @zh 此骨骼是否有效 + */ public validate () { return this.joints.length > 0 && this.bindposes.length > 0; } diff --git a/cocos/3d/framework/mesh-renderer.ts b/cocos/3d/framework/mesh-renderer.ts index 6f677da303..84a4d244bd 100644 --- a/cocos/3d/framework/mesh-renderer.ts +++ b/cocos/3d/framework/mesh-renderer.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module model - */ - import { ccclass, help, executeInEditMode, executionOrder, menu, tooltip, visible, type, formerlySerializedAs, serializable, editable, disallowAnimation } from 'cc.decorator'; import { Texture2D } from '../../core/assets'; @@ -41,7 +36,7 @@ import { TransformBit } from '../../core/scene-graph/node-enum'; import { Enum } from '../../core/value-types'; import { builtinResMgr } from '../../core/builtin'; import { ModelRenderer } from '../../core/components/model-renderer'; -import { MorphRenderingInstance } from '../assets/morph'; +import { MorphRenderingInstance } from '../assets/morph-rendering'; import { legacyCC } from '../../core/global-exports'; import { assertIsTrue } from '../../core/data/utils/asserts'; import { CCFloat } from '../../core/data/utils/attribute'; @@ -70,19 +65,19 @@ const ModelShadowCastingMode = Enum({ */ const ModelShadowReceivingMode = Enum({ /** - * @en Disable shadow projection. + * @en Disable shadow receiving. * @zh 不接收阴影。 */ OFF: 0, /** - * @en Enable shadow projection. + * @en Enable shadow receiving. * @zh 开启阴影投射。 */ ON: 1, }); /** - * @en model light map settings. + * @en Model's light map settings. * @zh 模型光照图设置 */ @ccclass('cc.ModelLightmapSettings') @@ -101,8 +96,10 @@ class ModelLightmapSettings { protected _lightmapSize = 64; /** - * @en bakeable. - * @zh 是否可烘培。 + * @en Whether the model is static and bake-able with light map. + * Notice: the model's vertex data must have the second UV attribute to enable light map baking. + * @zh 模型是否是静态的并可以烘培光照贴图。 + * 注意:模型顶点数据必须包含第二套 UV 属性来支持光照贴图烘焙。 */ @editable get bakeable () { @@ -114,8 +111,8 @@ class ModelLightmapSettings { } /** - * @en cast shadow. - * @zh 是否投射阴影。 + * @en Whether to cast shadow in light map baking. + * @zh 在光照贴图烘焙中是否投射阴影。 */ @editable get castShadow () { @@ -127,8 +124,8 @@ class ModelLightmapSettings { } /** - * @en receive shadow. - * @zh 是否接受阴影。 + * @en Whether to receive shadow in light map baking. + * @zh 在光照贴图烘焙中是否接受阴影。 */ @editable get receiveShadow () { @@ -140,8 +137,8 @@ class ModelLightmapSettings { } /** - * @en lightmap size. - * @zh 光照图大小 + * @en The lightmap size. + * @zh 光照图大小。 */ @editable get lightmapSize () { @@ -154,8 +151,10 @@ class ModelLightmapSettings { } /** - * @en Mesh renderer component - * @zh 网格渲染器组件。 + * @en Mesh renderer component for general 3d model rendering, it generates and link to a Model in the render scene. + * It supports real time lighting and shadow, baked light map, and morph rendering. + * @zh 用于通用模型渲染的网格渲染器组件,会创建并关联一个渲染场景中的模型对象。 + * 该组件支持实时光照和阴影,预烘焙光照贴图和形变网格渲染。 */ @ccclass('cc.MeshRenderer') @help('i18n:cc.MeshRenderer') @@ -163,9 +162,21 @@ class ModelLightmapSettings { @menu('Mesh/MeshRenderer') @executeInEditMode export class MeshRenderer extends ModelRenderer { + /** + * @en Shadow projection mode enumeration. + * @zh 阴影投射方式枚举。 + */ public static ShadowCastingMode = ModelShadowCastingMode; + /** + * @en Shadow receive mode enumeration. + * @zh 阴影接收方式枚举。 + */ public static ShadowReceivingMode = ModelShadowReceivingMode; + /** + * @en The settings for light map baking + * @zh 光照贴图烘焙的配置 + */ @serializable @editable @disallowAnimation @@ -180,18 +191,18 @@ export class MeshRenderer extends ModelRenderer { @serializable protected _shadowReceivingMode = ModelShadowReceivingMode.ON; - // @serializable - private _subMeshShapesWeights: number[][] = []; - @serializable protected _shadowBias = 0; @serializable protected _shadowNormalBias = 0; + // @serializable + private _subMeshShapesWeights: number[][] = []; + /** - * @en local shadow bias. - * @zh 模型局部的阴影偏移。 + * @en Local shadow bias for real time lighting. + * @zh 实时光照下模型局部的阴影偏移。 */ @type(CCFloat) @tooltip('i18n:model.shadow_bias') @@ -208,8 +219,8 @@ export class MeshRenderer extends ModelRenderer { } /** - * @en local shadow normal bias. - * @zh 模型局部的阴影法线偏移。 + * @en local shadow normal bias for real time lighting. + * @zh 实时光照下模型局部的阴影法线偏移。 */ @type(CCFloat) @tooltip('i18n:model.shadow_normal_bias') @@ -227,7 +238,7 @@ export class MeshRenderer extends ModelRenderer { /** * @en Shadow projection mode. - * @zh 阴影投射方式。 + * @zh 实时光照下阴影投射方式。 */ @type(ModelShadowCastingMode) @tooltip('i18n:model.shadow_casting_model') @@ -244,7 +255,7 @@ export class MeshRenderer extends ModelRenderer { /** * @en receive shadow. - * @zh 是否接受阴影。 + * @zh 实时光照下是否接受阴影。 */ @type(ModelShadowReceivingMode) @tooltip('i18n:model.shadow_receiving_model') @@ -261,9 +272,9 @@ export class MeshRenderer extends ModelRenderer { /** * @en Gets or sets the mesh of the model. - * Note, when set, all shape's weights would be reset to zero. + * Note, when set, all morph targets' weights would be reset to zero. * @zh 获取或设置模型的网格数据。 - * 注意,设置时,所有形状的权重都将归零。 + * 注意,设置时,所有形变目标的权重都将归零。 */ @type(Mesh) @tooltip('i18n:model.mesh') @@ -286,10 +297,18 @@ export class MeshRenderer extends ModelRenderer { this._updateReceiveShadow(); } + /** + * @en Gets the model in [[RenderScene]]. + * @zh 获取渲染场景 [[RenderScene]] 中对应的模型。 + */ get model () { return this._model; } + /** + * @en Whether to enable morph rendering. + * @zh 是否启用形变网格渲染。 + */ // eslint-disable-next-line func-names @visible(function (this: MeshRenderer) { return !!( @@ -384,10 +403,10 @@ export class MeshRenderer extends ModelRenderer { } /** - * @zh 获取子网格指定外形的权重。 - * @en Gets the weight at specified shape of specified sub mesh. + * @zh 获取子网格指定形变目标的权重。 + * @en Gets the weight at specified morph target of the specified sub mesh. * @param subMeshIndex Index to the sub mesh. - * @param shapeIndex Index to the shape of the sub mesh. + * @param shapeIndex Index to the morph target of the sub mesh. * @returns The weight. */ public getWeight (subMeshIndex: number, shapeIndex: number) { @@ -400,13 +419,11 @@ export class MeshRenderer extends ModelRenderer { /** * @zh - * 设置子网格所有外形的权重。 - * `subMeshIndex` 是无效索引或 `weights` 的长度不匹配子网格的外形数量时,此方法不会生效。 + * 设置子网格所有形变目标的权重。 + * `subMeshIndex` 是无效索引或 `weights` 的长度不匹配子网格的形变目标数量时,此方法不会生效。 * @en - * Sets weights of each shape of specified sub mesh. - * If takes no effect if - * `subMeshIndex` out of bounds or - * `weights` has a different length with shapes count of the sub mesh. + * Sets weights of each morph target of the specified sub mesh. + * If takes no effect if `subMeshIndex` is out of bounds or if `weights` has a different length with morph targets count of the sub mesh. * @param weights The weights. * @param subMeshIndex Index to the sub mesh. */ @@ -739,6 +756,14 @@ export class MeshRenderer extends ModelRenderer { } export declare namespace MeshRenderer { + /** + * @en Shadow projection mode. + * @zh 阴影投射方式。 + */ export type ShadowCastingMode = EnumAlias; + /** + * @en Shadow receive mode. + * @zh 阴影接收方式。 + */ export type ShadowReceivingMode = EnumAlias; } diff --git a/cocos/3d/lights/deprecated.ts b/cocos/3d/lights/deprecated.ts index d533d5b347..e9c901cac8 100644 --- a/cocos/3d/lights/deprecated.ts +++ b/cocos/3d/lights/deprecated.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module component - */ - import { Light } from './light-component'; import { SpotLight } from './spot-light-component'; import { SphereLight } from './sphere-light-component'; diff --git a/cocos/3d/lights/directional-light-component.ts b/cocos/3d/lights/directional-light-component.ts index 2d0e1e35d7..9d15b60fd0 100644 --- a/cocos/3d/lights/directional-light-component.ts +++ b/cocos/3d/lights/directional-light-component.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module component/light - */ - import { ccclass, range, slide, type, editable, visible, help, executeInEditMode, menu, tooltip, serializable, formerlySerializedAs } from 'cc.decorator'; import { Light } from './light-component'; @@ -39,6 +34,10 @@ import { property } from '../../core/data/class-decorator'; import { CCBoolean, CCFloat } from '../../core/data/utils/attribute'; import { clamp } from '../../core'; +/** + * @en The directional light component, only one real time directional light is permitted in one scene, it act as the main light of the scene. + * @zh 平行光源组件,一个场景只允许存在一个实时的平行光源,作为场景的主光源存在。 + */ @ccclass('cc.DirectionalLight') @help('i18n:cc.DirectionalLight') @menu('Light/DirectionalLight') @@ -83,10 +82,8 @@ export class DirectionalLight extends Light { protected _light: scene.DirectionalLight | null = null; /** - * @en - * The light source intensity. - * @zh - * 光源强度。 + * @en The light source intensity. + * @zh 光源强度。 */ @tooltip('i18n:lights.illuminance') get illuminance () { @@ -109,8 +106,8 @@ export class DirectionalLight extends Light { } /** - * @en Whether activate shadow - * @zh 是否启用阴影? + * @en Whether activate real time shadow. + * @zh 是否启用实时阴影? */ @visible(() => (legacyCC.director.root as Root).pipeline.pipelineSceneData.shadows.type === ShadowType.ShadowMap) @property({ group: { name: 'DynamicShadowSettings', displayOrder: 1 } }) @@ -127,8 +124,8 @@ export class DirectionalLight extends Light { } /** - * @en get or set shadow pcf. - * @zh 获取或者设置阴影pcf等级。 + * @en The shadow pcf for real time shadow. + * @zh 实时阴影计算中的阴影 pcf 等级。 */ @visible(() => (legacyCC.director.root as Root).pipeline.pipelineSceneData.shadows.type === ShadowType.ShadowMap) @property({ group: { name: 'DynamicShadowSettings', displayOrder: 5 } }) @@ -145,8 +142,8 @@ export class DirectionalLight extends Light { } /** - * @en get or set shadow map sampler offset - * @zh 获取或者设置阴影纹理偏移值 + * @en The shadow map sampler offset for real time shadow. + * @zh 实时阴影计算中的阴影纹理偏移值。 */ @visible(() => (legacyCC.director.root as Root).pipeline.pipelineSceneData.shadows.type === ShadowType.ShadowMap) @property({ group: { name: 'DynamicShadowSettings', displayOrder: 6 } }) @@ -163,8 +160,8 @@ export class DirectionalLight extends Light { } /** - * @en get or set normal bias. - * @zh 设置或者获取法线偏移。 + * @en The global normal bias for real time shadow. + * @zh 实时阴影计算中的法线偏移。 */ @visible(() => (legacyCC.director.root as Root).pipeline.pipelineSceneData.shadows.type === ShadowType.ShadowMap) @property({ group: { name: 'DynamicShadowSettings', displayOrder: 7 } }) @@ -181,8 +178,8 @@ export class DirectionalLight extends Light { } /** - * @en Shadow color saturation - * @zh 阴影颜色饱和度 + * @en The shadow color saturation for real time shadow. + * @zh 实时阴影计算中的阴影颜色饱和度。 */ @visible(() => (legacyCC.director.root as Root).pipeline.pipelineSceneData.shadows.type === ShadowType.ShadowMap) @property({ group: { name: 'DynamicShadowSettings', displayOrder: 8 } }) @@ -202,8 +199,8 @@ export class DirectionalLight extends Light { } /** - * @en get or set shadow camera far - * @zh 获取或者设置潜在阴影产生的范围 + * @en The potential shadow distance from the camera for real time shadow. + * @zh 实时阴影计算中潜在阴影产生的范围 */ @visible(function (this: DirectionalLight) { return (legacyCC.director.root as Root).pipeline.pipelineSceneData.shadows.type @@ -226,8 +223,8 @@ export class DirectionalLight extends Light { } /** - * @en get or set shadow camera far - * @zh 获取或者设置潜在阴影产生的范围 + * @en The occlusion range for real time shadow. + * @zh 实时阴影计算中剔除阴影的范围 */ @visible(function (this: DirectionalLight) { return (legacyCC.director.root as Root).pipeline.pipelineSceneData.shadows.type @@ -250,8 +247,8 @@ export class DirectionalLight extends Light { } /** - * @en get or set fixed area shadow - * @zh 是否是固定区域阴影 + * @en Whether to use fixed area shadow in real time shadow. + * @zh 实时阴影计算中是否使用固定区域阴影。 */ @visible(() => (legacyCC.director.root as Root).pipeline.pipelineSceneData.shadows.type === ShadowType.ShadowMap) @property({ group: { name: 'DynamicShadowSettings', displayOrder: 11 } }) @@ -268,8 +265,8 @@ export class DirectionalLight extends Light { } /** - * @en get or set shadow camera near - * @zh 获取或者设置阴影相机近裁剪面 + * @en The near clip plane of the shadow camera for fixed area shadow + * @zh 固定区域阴影设置中阴影相机近裁剪面 */ @visible(function (this: DirectionalLight) { return (legacyCC.director.root as Root).pipeline.pipelineSceneData.shadows.type @@ -289,8 +286,8 @@ export class DirectionalLight extends Light { } /** - * @en get or set shadow camera far - * @zh 获取或者设置阴影相机远裁剪面 + * @en The far clip plane of the shadow camera for fixed area shadow. + * @zh 固定区域阴影设置中阴影相机远裁剪面。 */ @visible(function (this: DirectionalLight) { return (legacyCC.director.root as Root).pipeline.pipelineSceneData.shadows.type @@ -310,8 +307,8 @@ export class DirectionalLight extends Light { } /** - * @en get or set shadow camera orthoSize - * @zh 获取或者设置阴影相机正交大小 + * @en The orthogonal size of the shadow camera for fixed area shadow. + * @zh 固定区域阴影设置中阴影相机的正交尺寸 */ @visible(function (this: DirectionalLight) { return (legacyCC.director.root as Root).pipeline.pipelineSceneData.shadows.type diff --git a/cocos/3d/lights/index.ts b/cocos/3d/lights/index.ts index 702e96c7c0..67d85771f6 100644 --- a/cocos/3d/lights/index.ts +++ b/cocos/3d/lights/index.ts @@ -24,7 +24,6 @@ THE SOFTWARE. */ - export { DirectionalLight } from './directional-light-component'; export { Light } from './light-component'; export { SphereLight } from './sphere-light-component'; diff --git a/cocos/3d/lights/light-component.ts b/cocos/3d/lights/light-component.ts index 95141a7d5e..1b7ba90699 100644 --- a/cocos/3d/lights/light-component.ts +++ b/cocos/3d/lights/light-component.ts @@ -23,27 +23,27 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module component/light - */ - import { ccclass, tooltip, range, slide, type, displayOrder, serializable, editable } from 'cc.decorator'; import { Component } from '../../core/components/component'; import { Color, Vec3 } from '../../core/math'; import { Enum } from '../../core/value-types'; - import { scene } from '../../core/renderer'; import { Root } from '../../core/root'; import { legacyCC } from '../../core/global-exports'; +const _color_tmp = new Vec3(); + +/** + * @en The physical term used for light. + * @zh 光源所使用的物理计量单位。 + */ export const PhotometricTerm = Enum({ LUMINOUS_FLUX: 0, LUMINANCE: 1, }); -const _color_tmp = new Vec3(); + /** - * @en static light settings. + * @en Static light settings. * @zh 静态灯光设置 */ @ccclass('cc.StaticLightSettings') @@ -58,7 +58,7 @@ class StaticLightSettings { protected _castShadow = false; /** - * @en editor only. + * @en Whether the light is editor only. * @zh 是否只在编辑器里生效。 */ @editable @@ -70,7 +70,8 @@ class StaticLightSettings { } /** - * bake state + * @en Whether the light is baked + * @zh 光源是否被烘焙 */ get baked () { return this._baked; @@ -81,8 +82,8 @@ class StaticLightSettings { } /** - * @en bakeable. - * @zh 是否可烘培。 + * @en Whether the light is bake-able. + * @zh 光源是否可烘培。 */ @editable get bakeable () { @@ -94,8 +95,8 @@ class StaticLightSettings { } /** - * @en cast shadow. - * @zh 是否投射阴影。 + * @en Whether the light will cast shadow during baking process. + * @zh 光源在烘焙时是否投射阴影。 */ @editable get castShadow () { @@ -112,9 +113,21 @@ export declare namespace Light { export type PhotometricTerm = EnumAlias; } +/** + * @en The base class of all light components, contains basic light settings for both real time light and baked light. + * @zh 光源组件基类,包含实时光源和烘焙光源的基本配置信息。 + */ @ccclass('cc.Light') export class Light extends Component { + /** + * @en The light type enumeration. + * @zh 光源类型枚举。 + */ public static Type = scene.LightType; + /** + * @en The physical term used for light. + * @zh 光源所使用的物理计量单位。 + */ public static PhotometricTerm = PhotometricTerm; @serializable @@ -131,10 +144,8 @@ export class Light extends Component { protected _light: scene.Light | null = null; /** - * @en - * Color of the light. - * @zh - * 光源颜色。 + * @en The color of the light. + * @zh 光源颜色。 */ @tooltip('i18n:lights.color') get color (): Readonly { @@ -200,17 +211,16 @@ export class Light extends Component { } /** - * @en - * The light type. - * @zh - * 光源类型。 + * @en The light type. + * @zh 光源类型。 */ get type () { return this._type; } /** - * bake state + * @en Whether the light is baked + * @zh 光源是否被烘焙 */ get baked () { return this.staticSettings.baked; diff --git a/cocos/3d/lights/sphere-light-component.ts b/cocos/3d/lights/sphere-light-component.ts index 71a87fc32d..1db1b4893d 100644 --- a/cocos/3d/lights/sphere-light-component.ts +++ b/cocos/3d/lights/sphere-light-component.ts @@ -22,10 +22,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/** - * @packageDocumentation - * @module component/light - */ import { ccclass, help, executeInEditMode, menu, tooltip, type, displayOrder, serializable, formerlySerializedAs } from 'cc.decorator'; import { scene } from '../../core/renderer'; @@ -34,6 +30,10 @@ import { legacyCC } from '../../core/global-exports'; import { Camera } from '../../core/renderer/scene'; import { Root } from '../../core/root'; +/** + * @en The sphere light component, multiple sphere lights can be added to one scene. + * @zh 球面光源组件,场景中可以添加多个球面光源。 + */ @ccclass('cc.SphereLight') @help('i18n:cc.SphereLight') @menu('Light/SphereLight') diff --git a/cocos/3d/lights/spot-light-component.ts b/cocos/3d/lights/spot-light-component.ts index bf1b6b622e..b79fdc0d9b 100644 --- a/cocos/3d/lights/spot-light-component.ts +++ b/cocos/3d/lights/spot-light-component.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module component/light - */ - import { ccclass, range, slide, type, editable, displayOrder, help, executeInEditMode, menu, tooltip, serializable, formerlySerializedAs, visible } from 'cc.decorator'; import { toRadian } from '../../core/math'; @@ -39,6 +34,10 @@ import { Camera, PCFType, ShadowType } from '../../core/renderer/scene'; import { property } from '../../core/data/class-decorator'; import { CCBoolean, CCFloat } from '../../core/data/utils/attribute'; +/** + * @en The spot light component, multiple spot lights can be added to one scene. + * @zh 聚光灯光源组件,场景中可以添加多个聚光灯光源。 + */ @ccclass('cc.SpotLight') @help('i18n:cc.SpotLight') @menu('Light/SpotLight') @@ -215,8 +214,8 @@ export class SpotLight extends Light { } /** - * @en get or set shadow pcf. - * @zh 获取或者设置阴影pcf等级。 + * @en The pcf level of the shadow generation. + * @zh 获取或者设置阴影 pcf 等级。 */ @visible(() => (legacyCC.director.root as Root).pipeline.pipelineSceneData.shadows.type === ShadowType.ShadowMap) @property({ group: { name: 'DynamicShadowSettings', displayOrder: 2 } }) @@ -233,8 +232,8 @@ export class SpotLight extends Light { } /** - * @en get or set shadow map sampler offset - * @zh 获取或者设置阴影纹理偏移值 + * @en The depth offset of shadow to avoid moire pattern artifacts + * @zh 阴影的深度偏移, 可以减弱跨像素导致的条纹状失真 */ @visible(() => (legacyCC.director.root as Root).pipeline.pipelineSceneData.shadows.type === ShadowType.ShadowMap) @property({ group: { name: 'DynamicShadowSettings', displayOrder: 3 } }) @@ -251,7 +250,7 @@ export class SpotLight extends Light { } /** - * @en get or set normal bias. + * @en The normal bias of the shadow map. * @zh 设置或者获取法线偏移。 */ @visible(() => (legacyCC.director.root as Root).pipeline.pipelineSceneData.shadows.type === ShadowType.ShadowMap) diff --git a/cocos/3d/misc/batch-utils.ts b/cocos/3d/misc/batch-utils.ts index c67a489102..3887c9095d 100644 --- a/cocos/3d/misc/batch-utils.ts +++ b/cocos/3d/misc/batch-utils.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module core - */ - import { MeshRenderer } from '../framework/mesh-renderer'; import { Mesh } from '../assets/mesh'; import { Mat4 } from '../../core/math/mat4'; @@ -52,12 +47,19 @@ function checkMaterialisSame (comp1: MeshRenderer, comp2: MeshRenderer): boolean */ export class BatchingUtility { /** + * @en * Collect the Models under `staticModelRoot`, * merge all the meshes statically into one (while disabling each component), * and attach it to a new Model on `batchedRoot`. * The world transform of each model is guaranteed to be preserved. * * For a more fine-grained control over the process, use `Mesh.merge` directly. + * @zh + * 在`staticModelRoot`下收集模型。 + * 将所有的网格静态地合并成一个(同时禁用每个组件)。 + * 并将其附加到 `batchedRoot` 上的一个新模型。 + * 每个模型的世界变换都被保证保留下来。 + * 如果要对这个过程进行更精细的控制,可以直接使用 `Mesh.merge`。 * @param staticModelRoot root of all the static models to be batched * @param batchedRoot the target output node */ @@ -96,7 +98,10 @@ export class BatchingUtility { } /** + * @en * Undoes everything `batchStaticModel` did. + * @zh + * 回退 `batchStaticModel` 做的工作 * * @param staticModelRoot root of all the static models to be batched * @param batchedRoot the target output node diff --git a/cocos/3d/misc/ppm.ts b/cocos/3d/misc/ppm.ts index 22bb9a0202..d87753b1d9 100644 --- a/cocos/3d/misc/ppm.ts +++ b/cocos/3d/misc/ppm.ts @@ -24,7 +24,13 @@ */ /** + * @en * save a color buffer to a PPM file + * @zh + * 保存一个颜色缓冲到 PPM 文件中 + * @param buffer color buffer + * @param w width + * @param h height */ export function toPPM (buffer: Uint8Array, w: number, h: number) { return `P3 ${w} ${h} 255\n${buffer.filter((e, i) => i % 4 < 3).toString()}\n`; diff --git a/cocos/3d/models/baked-skinning-model.ts b/cocos/3d/models/baked-skinning-model.ts index 4c2936de55..8103bbe9c6 100644 --- a/cocos/3d/models/baked-skinning-model.ts +++ b/cocos/3d/models/baked-skinning-model.ts @@ -53,11 +53,15 @@ const myPatches = [ /** * @en - * The skinning model that is using baked animation. + * The skinning model that is using GPU baked animation. * @zh - * 预烘焙动画的蒙皮模型。 + * GPU 预烘焙动画的蒙皮模型。 */ export class BakedSkinningModel extends MorphModel { + /** + * @en The animation clip that have been uploaded + * @zh 已被上传的动画片段 + */ public uploadedAnim: AnimationClip | null | undefined = undefined; // uninitialized private _jointsMedium: IJointsInfo; @@ -87,6 +91,7 @@ export class BakedSkinningModel extends MorphModel { super.destroy(); } + // Override public bindSkeleton (skeleton: Skeleton | null = null, skinningRoot: Node | null = null, mesh: Mesh | null = null) { this._skeleton = skeleton; this._mesh = mesh; @@ -104,6 +109,7 @@ export class BakedSkinningModel extends MorphModel { } } + // Override public updateTransform (stamp: number) { super.updateTransform(stamp); @@ -118,7 +124,7 @@ export class BakedSkinningModel extends MorphModel { } } - // update fid buffer only when visible + // Override, update fid buffer only when visible public updateUBOs (stamp: number) { super.updateUBOs(stamp); @@ -134,6 +140,21 @@ export class BakedSkinningModel extends MorphModel { return true; } + // Override + public getMacroPatches (subModelIndex: number): IMacroPatch[] | null { + const patches = super.getMacroPatches(subModelIndex); + return patches ? patches.concat(myPatches) : myPatches; + } + + /** + * @en Pre-simulate and store the frames data of the given animation clip to a joint texture and upload it to GPU. + * Normally, it's automatically managed by [[SkeletalAnimationState]]. + * But user can also use Joint Texture Layout Settings in the editor to manually organize the joint textures. + * @zh 预计算并存储一个指定动画片段的完整帧数据到一张骨骼贴图上,并将其上传到 GPU。 + * 一般情况下 [[SkeletalAnimationState]] 会自动管理所有骨骼贴图,但用户也可以使用编辑器的骨骼贴图布局设置面板来手动管理所有骨骼贴图。 + * @param anim @en The animation clip to be uploaded to the joint texture. @zh 需要上传到骨骼贴图上的动画片段。 + * @returns void + */ public uploadAnimation (anim: AnimationClip | null) { if (!this._skeleton || !this._mesh || this.uploadedAnim === anim) { return; } this.uploadedAnim = anim; @@ -146,7 +167,7 @@ export class BakedSkinningModel extends MorphModel { } else { texture = resMgr.jointTexturePool.getDefaultPoseTexture(this._skeleton, this._mesh, this.transform); this._jointsMedium.boundsInfo = null; - this._modelBounds = texture && texture.bounds.get(this._mesh.hash)![0]; + this._modelBounds = texture && texture.bounds.get(this._mesh.hash)![0]; } this._applyJointTexture(texture); } @@ -171,11 +192,6 @@ export class BakedSkinningModel extends MorphModel { } } - public getMacroPatches (subModelIndex: number): IMacroPatch[] | null { - const patches = super.getMacroPatches(subModelIndex); - return patches ? patches.concat(myPatches) : myPatches; - } - protected _updateLocalDescriptors (submodelIdx: number, descriptorSet: DescriptorSet) { super._updateLocalDescriptors(submodelIdx, descriptorSet); const { buffer, texture, animInfo } = this._jointsMedium; diff --git a/cocos/3d/models/morph-model.ts b/cocos/3d/models/morph-model.ts index 94b43eac48..ddab4f223e 100644 --- a/cocos/3d/models/morph-model.ts +++ b/cocos/3d/models/morph-model.ts @@ -24,27 +24,47 @@ */ import { Model } from '../../core/renderer/scene/model'; -import { MorphRenderingInstance } from '../assets/morph'; +import { MorphRenderingInstance } from '../assets/morph-rendering'; import { Material } from '../../core/assets/material'; import { RenderingSubMesh } from '../../core/assets/rendering-sub-mesh'; import { DescriptorSet } from '../../core/gfx'; import { IMacroPatch } from '../../core/renderer'; +/** + * @en + * The model that support morph target rendering. + * @zh + * 支持渲染蒙皮形变的模型。 + */ export class MorphModel extends Model { private _morphRenderingInstance: MorphRenderingInstance | null = null; private _usedMaterials = new Set(); + /** + * @en Acquire the material's macro patches for the given sub model. + * @zh 获取指定子模型的材质宏组合。 + * @param subModelIndex @en The index for the requested sub model. @zh 子模型的序号。 + * @returns @en The macro patches. @zh 材质宏组合 + */ public getMacroPatches (subModelIndex: number) : IMacroPatch[] | null { const superMacroPatches = super.getMacroPatches(subModelIndex); if (this._morphRenderingInstance) { const morphInstanceMacroPatches = this._morphRenderingInstance.requiredPatches(subModelIndex); if (morphInstanceMacroPatches) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-return return morphInstanceMacroPatches.concat(superMacroPatches ?? []); } } return superMacroPatches; } + /** + * @en Initialize a sub model with the sub mesh data and the material. + * @zh 用子网格数据和材质初始化一个子模型。 + * @param idx @en The index of the sub model @zh 子模型的序号 + * @param subMeshData @en The sub mesh data to be set @zh 需要设置的子网格 + * @param mat sub material + */ public initSubModel (subModelIndex: number, subMeshData: RenderingSubMesh, material: Material) { return super.initSubModel( subModelIndex, @@ -58,10 +78,25 @@ export class MorphModel extends Model { this._morphRenderingInstance = null; } + /** + * @en Sets the material for a given sub model. + * @zh 给指定的子模型设置材质。 + * @param subModelIndex @en The index of the sub model @zh 子模型的序号 + * @param material @en The material to be set @zh 需要设置的材质 + * @returns void + */ public setSubModelMaterial (subModelIndex: number, material: Material) { return super.setSubModelMaterial(subModelIndex, this._launderMaterial(material)); } + /** + * Sets morph rendering instance for the model, it's managed by the MeshRenderer + * @internal + */ + public setMorphRendering (morphRendering: MorphRenderingInstance) { + this._morphRenderingInstance = morphRendering; + } + protected _updateLocalDescriptors (submodelIdx: number, descriptorSet: DescriptorSet) { super._updateLocalDescriptors(submodelIdx, descriptorSet); @@ -81,8 +116,4 @@ export class MorphModel extends Model { // return material; // } } - - public setMorphRendering (morphRendering: MorphRenderingInstance) { - this._morphRenderingInstance = morphRendering; - } } diff --git a/cocos/3d/models/skinning-model.ts b/cocos/3d/models/skinning-model.ts index 14f0c2285f..267d8d12ba 100644 --- a/cocos/3d/models/skinning-model.ts +++ b/cocos/3d/models/skinning-model.ts @@ -80,8 +80,6 @@ const ab_1 = new AABB(); * 实时计算动画的蒙皮模型。 */ export class SkinningModel extends MorphModel { - public uploadAnimation = null; - private _buffers: Buffer[] = []; private _dataArray: Float32Array[] = []; private _joints: IJointInfo[] = []; @@ -102,6 +100,20 @@ export class SkinningModel extends MorphModel { super.destroy(); } + /** + * @en Abstract function for [[BakedSkinningModel]], empty implementation. + * @zh 由 [[BakedSkinningModel]] 继承的空函数。 + */ + public uploadAnimation () {} + + /** + * @en Bind the skeleton with its skinning root node and the mesh data. + * @zh 在模型中绑定一个骨骼,需要提供骨骼的蒙皮根节点和蒙皮网格数据。 + * @param skeleton @en The skeleton to be bound @zh 要绑定的骨骼 + * @param skinningRoot @en The skinning root of the skeleton @zh 骨骼的蒙皮根节点 + * @param mesh @en The mesh @zh 蒙皮网格 + * @returns void + */ public bindSkeleton (skeleton: Skeleton | null = null, skinningRoot: Node | null = null, mesh: Mesh | null = null) { for (let i = 0; i < this._joints.length; i++) { deleteTransform(this._joints[i].target); @@ -126,6 +138,11 @@ export class SkinningModel extends MorphModel { } } + /** + * @en Update world transform and bounding boxes for the model + * @zh 更新模型的世界矩阵和包围盒 + * @param stamp @en The update time stamp @zh 更新的时间戳 + */ public updateTransform (stamp: number) { const root = this.transform; // @ts-expect-error TS2445 @@ -153,6 +170,12 @@ export class SkinningModel extends MorphModel { } } + /** + * @en Update uniform buffer objects for rendering. + * @zh 更新用于渲染的 UBO + * @param stamp @en The update time stamp @zh 更新的时间戳 + * @returns @en successful or not @zh 更新是否成功 + */ public updateUBOs (stamp: number) { super.updateUBOs(stamp); for (let i = 0; i < this._joints.length; i++) { @@ -168,6 +191,13 @@ export class SkinningModel extends MorphModel { return true; } + /** + * @en Initialize sub model with the sub mesh data and the material + * @zh 用子网格数据和材质初始化一个子模型 + * @param idx @en The index of the sub model to be initialized @zh 需要初始化的子模型序号 + * @param subMeshData @en The sub mesh data @zh 子网格数据 + * @param mat @en The material @zh 子模型材质 + */ public initSubModel (idx: number, subMeshData: RenderingSubMesh, mat: Material) { const original = subMeshData.vertexBuffers; const iaInfo = subMeshData.iaInfo; @@ -176,6 +206,7 @@ export class SkinningModel extends MorphModel { iaInfo.vertexBuffers = original; } + // override public getMacroPatches (subModelIndex: number): IMacroPatch[] | null { const superMacroPatches = super.getMacroPatches(subModelIndex); diff --git a/cocos/3d/skeletal-animation/data-pool-manager.ts b/cocos/3d/skeletal-animation/data-pool-manager.ts index 89e6c77953..165812b5b5 100644 --- a/cocos/3d/skeletal-animation/data-pool-manager.ts +++ b/cocos/3d/skeletal-animation/data-pool-manager.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import type { AnimationClip } from '../../core/animation/animation-clip'; import type { Skeleton } from '../assets'; import { Device } from '../../core/gfx'; diff --git a/cocos/3d/skeletal-animation/index.ts b/cocos/3d/skeletal-animation/index.ts index fbdecc71e9..bb11159cb2 100644 --- a/cocos/3d/skeletal-animation/index.ts +++ b/cocos/3d/skeletal-animation/index.ts @@ -23,7 +23,6 @@ THE SOFTWARE. */ - import './data-pool-manager'; export * from './skeletal-animation-data-hub'; diff --git a/cocos/3d/skeletal-animation/skeletal-animation-blending.ts b/cocos/3d/skeletal-animation/skeletal-animation-blending.ts index 3de11f2919..b2ab97e4f6 100644 --- a/cocos/3d/skeletal-animation/skeletal-animation-blending.ts +++ b/cocos/3d/skeletal-animation/skeletal-animation-blending.ts @@ -24,10 +24,10 @@ */ import { DEBUG } from 'internal:constants'; -import { Vec3, Quat, approx } from '../../core/math'; +import { Vec3, Quat } from '../../core/math'; import { Node } from '../../core/scene-graph'; import { RuntimeBinding } from '../../core/animation/tracks/track'; -import { assertIsNonNullable, assertIsTrue } from '../../core/data/utils/asserts'; +import { assertIsTrue } from '../../core/data/utils/asserts'; import { MAX_ANIMATION_LAYER } from './limits'; export abstract class BlendStateBuffer< diff --git a/cocos/3d/skeletal-animation/skeletal-animation-data-hub.ts b/cocos/3d/skeletal-animation/skeletal-animation-data-hub.ts index 107b929176..0564780e09 100644 --- a/cocos/3d/skeletal-animation/skeletal-animation-data-hub.ts +++ b/cocos/3d/skeletal-animation/skeletal-animation-data-hub.ts @@ -31,8 +31,10 @@ import { BAKE_SKELETON_CURVE_SYMBOL } from '../../core/animation/internal-symbol type BakeData = ReturnType; /** - * @en The data conversion tool for skeleton animation - * @zh 骨骼动画数据转换中心。 + * @en + * The data conversion tool for skeleton animation + * @zh + * 骨骼动画数据转换中心。 * @internal */ export class SkelAnimDataHub { diff --git a/cocos/3d/skeletal-animation/skeletal-animation-state.ts b/cocos/3d/skeletal-animation/skeletal-animation-state.ts index 4b7727ee99..8535d475ab 100644 --- a/cocos/3d/skeletal-animation/skeletal-animation-state.ts +++ b/cocos/3d/skeletal-animation/skeletal-animation-state.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module animation - */ - import { Mat4, Quat, Vec3 } from '../../core/math'; import { IAnimInfo, JointAnimationInfo } from './skeletal-animation-utils'; import { Node } from '../../core/scene-graph/node'; @@ -52,6 +47,10 @@ interface ISocketData { frames: ITransform[]; } +/** + * @en The animation state for skeletal animations. + * @zh 骨骼动画的动画状态控制对象。 + */ export class SkeletalAnimationState extends AnimationState { protected _frames = 1; @@ -104,6 +103,12 @@ export class SkeletalAnimationState extends AnimationState { } } + /** + * @en Rebuild animation curves and register the socket transforms per frame to the sockets. It will replace the internal sockets list. + * @zh 为所有指定挂点更新动画曲线运算结果,并存储所有挂点的逐帧变换矩阵。这个方法会用传入的挂点更新取代内部挂点列表。 + * @param sockets @en The sockets need update @zh 需要重建的挂点列表 + * @returns void + */ public rebuildSocketCurves (sockets: Socket[]) { this._sockets.length = 0; if (!this._targetNode) { return; } diff --git a/cocos/3d/skeletal-animation/skeletal-animation-utils.ts b/cocos/3d/skeletal-animation/skeletal-animation-utils.ts index 519423162b..b78ffb4bb6 100644 --- a/cocos/3d/skeletal-animation/skeletal-animation-utils.ts +++ b/cocos/3d/skeletal-animation/skeletal-animation-utils.ts @@ -139,6 +139,10 @@ export interface ICustomJointTextureLayout { // For (Infinity - Infinity) evaluates to NaN const Inf = Number.MAX_SAFE_INTEGER; +/** + * The pool for joint textures. + * @internal + */ export class JointTexturePool { private _device: Device; diff --git a/cocos/3d/skeletal-animation/skeletal-animation.ts b/cocos/3d/skeletal-animation/skeletal-animation.ts index caa1283269..14e8c7b7d7 100644 --- a/cocos/3d/skeletal-animation/skeletal-animation.ts +++ b/cocos/3d/skeletal-animation/skeletal-animation.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module animation - */ - import { ccclass, executeInEditMode, executionOrder, help, menu, tooltip, type, serializable, editable, } from 'cc.decorator'; @@ -46,6 +41,10 @@ import type { AnimationState } from '../../core/animation/animation-state'; import { assertIsTrue } from '../../core/data/utils/asserts'; import { getGlobalAnimationManager } from '../../core/animation/global-animation-manager'; +/** + * @en The socket to synchronize transform from skeletal joint to target node. + * @zh 骨骼动画的挂点,用于将骨骼树的挂点节点变化矩阵同步到目标节点上 + */ @ccclass('cc.SkeletalAnimation.Socket') export class Socket { /** @@ -217,6 +216,11 @@ export class SkeletalAnimation extends Animation { } } + /** + * @en Query all socket paths + * @zh 获取所有挂点的骨骼路径 + * @returns @en All socket paths @zh 所有挂点的骨骼路径 + */ public querySockets () { const animPaths = (this._defaultClip && Object.keys(SkelAnimDataHub.getOrExtract(this._defaultClip).joints).sort() .reduce((acc, cur) => (cur.startsWith(acc[acc.length - 1]) ? acc : (acc.push(cur), acc)), [] as string[])) || []; @@ -232,6 +236,10 @@ export class SkeletalAnimation extends Animation { return out; } + /** + * @en Rebuild animations to synchronize immediately all sockets to their target node. + * @zh 重建动画并立即同步所有挂点的转换矩阵到它们的目标节点上。 + */ public rebuildSocketAnimations () { for (const socket of this._sockets) { const joint = this.node.getChildByPath(socket.path); @@ -250,6 +258,14 @@ export class SkeletalAnimation extends Animation { } } + /** + * @en Create or get the target node from a socket. + * If a socket haven't been created for the corresponding path, this function will register a new socket. + * @zh 创建或获取一个挂点的同步目标节点。 + * 如果对应路径还没有创建挂点,这个函数会创建一个新的挂点。 + * @param path @en Path of the target joint. @zh 此挂点的骨骼路径。 + * @returns @en The target node of the socket. @zh 挂点的目标节点 + */ public createSocket (path: string) { const socket = this._sockets.find((s) => s.path === path); if (socket) { return socket.target; } @@ -286,7 +302,7 @@ export class SkeletalAnimation extends Animation { * @internal This method only friends to skinned mesh renderer. */ public notifySkinnedMeshRemoved (skinnedMeshRenderer: SkinnedMeshRenderer) { - assertIsTrue(skinnedMeshRenderer.associatedAnimation === this); + assertIsTrue(skinnedMeshRenderer.associatedAnimation === this || skinnedMeshRenderer.associatedAnimation === null); skinnedMeshRenderer.setUseBakedAnimation(false); skinnedMeshRenderer.associatedAnimation = null; this._users.delete(skinnedMeshRenderer); diff --git a/cocos/3d/skinned-mesh-renderer/deprecated.ts b/cocos/3d/skinned-mesh-renderer/deprecated.ts index 6f251d7816..f4780bd92d 100644 --- a/cocos/3d/skinned-mesh-renderer/deprecated.ts +++ b/cocos/3d/skinned-mesh-renderer/deprecated.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module component - */ - import { SkinnedMeshRenderer } from './skinned-mesh-renderer'; import { SkinnedMeshBatchRenderer, SkinnedMeshUnit } from './skinned-mesh-batch-renderer'; import { js } from '../../core/utils/js'; diff --git a/cocos/3d/skinned-mesh-renderer/skinned-mesh-batch-renderer.ts b/cocos/3d/skinned-mesh-renderer/skinned-mesh-batch-renderer.ts index 0cbcd2b2a3..2bf278e24d 100644 --- a/cocos/3d/skinned-mesh-renderer/skinned-mesh-batch-renderer.ts +++ b/cocos/3d/skinned-mesh-renderer/skinned-mesh-batch-renderer.ts @@ -22,11 +22,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module model - */ - import { EDITOR } from 'internal:constants'; import { ccclass, help, executeInEditMode, executionOrder, menu, tooltip, type, visible, override, serializable, editable, @@ -73,6 +68,8 @@ export class SkinnedMeshUnit { public material: Material | null = null; /** + * @en Local transform matrix + * @zh 本地变换矩阵 * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. */ @serializable diff --git a/cocos/3d/skinned-mesh-renderer/skinned-mesh-renderer.ts b/cocos/3d/skinned-mesh-renderer/skinned-mesh-renderer.ts index 75f5791b97..1ad50a176d 100644 --- a/cocos/3d/skinned-mesh-renderer/skinned-mesh-renderer.ts +++ b/cocos/3d/skinned-mesh-renderer/skinned-mesh-renderer.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module model - */ - import { ccclass, executeInEditMode, executionOrder, help, menu, tooltip, type, } from 'cc.decorator'; @@ -77,7 +72,7 @@ export class SkinnedMeshRenderer extends MeshRenderer { /** * @en The skinning root. (The node where the controlling Animation is located) - * 骨骼根节点的引用,对应控制此模型的动画组件所在节点。 + * @zh 骨骼根节点的引用,对应控制此模型的动画组件所在节点。 */ @type(Node) @tooltip('i18n:model.skinning_root') diff --git a/cocos/audio/audio-clip.ts b/cocos/audio/audio-clip.ts index e21b5bdb90..e1c50c6c84 100644 --- a/cocos/audio/audio-clip.ts +++ b/cocos/audio/audio-clip.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module component/audio - */ - import { ccclass, type, serializable, override, } from 'cc.decorator'; diff --git a/cocos/audio/audio-source.ts b/cocos/audio/audio-source.ts index d483e8663d..f1af9b19a7 100644 --- a/cocos/audio/audio-source.ts +++ b/cocos/audio/audio-source.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module component/audio - */ - import { AudioPlayer } from 'pal/audio'; import { ccclass, help, menu, tooltip, type, range, serializable } from 'cc.decorator'; import { AudioState } from '../../pal/audio/type'; diff --git a/cocos/audio/deprecated.ts b/cocos/audio/deprecated.ts index b733daa73a..d305e82548 100644 --- a/cocos/audio/deprecated.ts +++ b/cocos/audio/deprecated.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { AudioSource } from './audio-source'; import { replaceProperty, markAsWarning } from '../core/utils/x-deprecated'; import { AudioClip } from './audio-clip'; diff --git a/cocos/audio/index.ts b/cocos/audio/index.ts index 10dd1eb83a..34e040ace9 100644 --- a/cocos/audio/index.ts +++ b/cocos/audio/index.ts @@ -23,8 +23,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ - - import './audio-downloader'; import { AudioSource } from './audio-source'; diff --git a/cocos/core/animation/animation-clip.ts b/cocos/core/animation/animation-clip.ts index 221b4c37b3..bef5ea8afc 100644 --- a/cocos/core/animation/animation-clip.ts +++ b/cocos/core/animation/animation-clip.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module animation - */ - import { ccclass, serializable } from 'cc.decorator'; import { Asset } from '../assets/asset'; import { SpriteFrame } from '../../2d/assets/sprite-frame'; @@ -63,7 +58,7 @@ export declare namespace AnimationClip { } /** - * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. + * @internal */ export type { legacy as _legacy }; } @@ -144,8 +139,7 @@ export class AnimationClip extends Asset { /** * Sets if node TRS curves in this animation can be blended. * Normally this flag is enabled for model animation and disabled for other case. - * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. - * This is an internal slot. Never use it in your code. + * @internal This is an internal slot. Never use it in your code. */ @serializable public enableTrsBlending = false; @@ -163,14 +157,20 @@ export class AnimationClip extends Asset { } /** + * @en * Gets the count of tracks this animation owns. + * @zh + * 获取此动画中的轨道数量。 */ get tracksCount () { return this._tracks.length; } /** + * @en * Gets an iterable to tracks. + * @zh + * 获取可用于迭代轨道的对象。 */ get tracks (): Iterable { return this._tracks; @@ -237,7 +237,10 @@ export class AnimationClip extends Asset { } /** - * Counts the time range this animation spans. + * @en + * Counts the time range that the tracks within this animation span. + * @zh + * 获取此动画所有轨道占据的时间范围。 * @returns The time range. */ public range () { @@ -254,7 +257,10 @@ export class AnimationClip extends Asset { } /** + * @en * Gets the specified track. + * @zh + * 获取指定的轨道。 * @param index Index to the track. * @returns The track. */ @@ -263,7 +269,10 @@ export class AnimationClip extends Asset { } /** + * @en * Adds a track into this animation. + * @zh + * 添加一个轨道到此动画中。 * @param track The track. * @returns Index to the track. */ @@ -274,7 +283,10 @@ export class AnimationClip extends Asset { } /** + * @en * Removes a track from this animation. + * @zh + * 移除此动画中的指定轨道。 * @param index Index to the track. */ public removeTrack (index: number) { @@ -282,7 +294,10 @@ export class AnimationClip extends Asset { } /** + * @en * Removes all tracks from this animation. + * @zh + * 移除此动画的所有轨道。 */ public clearTracks () { this._tracks.length = 0; @@ -291,9 +306,7 @@ export class AnimationClip extends Asset { /** * Creates an event evaluator for this animation. * @param targetNode Target node used to fire events. - * @returns - * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. - * Do not use this in your code. + * @internal Do not use this in your code. */ public createEventEvaluator (targetNode: Node) { return new EventEvaluator( @@ -308,8 +321,7 @@ export class AnimationClip extends Asset { * Creates an evaluator for this animation. * @param context The context. * @returns The evaluator. - * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. - * Do not use this in your code. + * @internal Do not use this in your code. */ public createEvaluator (context: AnimationClipEvalContext) { const { @@ -419,8 +431,7 @@ export class AnimationClip extends Asset { /** * Convert all untyped tracks into typed ones and delete the original. * @param refine How to decide the type on specified path. - * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. - * DO NOT USE THIS IN YOUR CODE. + * @internal DO NOT USE THIS IN YOUR CODE. */ public upgradeUntypedTracks (refine: UntypedTrackRefine) { const newTracks: Track[] = []; @@ -446,7 +457,7 @@ export class AnimationClip extends Asset { } /** - * Export for test. + * @internal Export for test. */ public [searchForRootBonePathSymbol] () { return this._searchForRootBonePath(); @@ -498,6 +509,9 @@ export class AnimationClip extends Asset { } /** + * @en + * The animation's data. + * @zh * 此动画的数据。 * @deprecated Since V3.3. Please reference to the track/channel/curve mechanism introduced in V3.3. */ @@ -513,7 +527,6 @@ export class AnimationClip extends Asset { } /** - * @protected * @deprecated Since V3.3. Please reference to the track/channel/curve mechanism introduced in V3.3. */ get eventGroups (): readonly IAnimationEventGroup[] { @@ -545,7 +558,7 @@ export class AnimationClip extends Asset { * Migrates legacy data into tracks. * NOTE: This method tend to be used as internal purpose or patch. * DO NOT use it in your code since it might be removed for the future at any time. - * @deprecated Since V3.3. Please reference to the track/channel/curve mechanism introduced in V3.3. + * @internal Since V3.3. Please reference to the track/channel/curve mechanism introduced in V3.3. */ public syncLegacyData () { if (this._legacyData) { diff --git a/cocos/core/animation/animation-component.ts b/cocos/core/animation/animation-component.ts index 8f43c15516..dd47eca6c4 100644 --- a/cocos/core/animation/animation-component.ts +++ b/cocos/core/animation/animation-component.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module animation - */ - import { ccclass, executeInEditMode, executionOrder, help, menu, tooltip, type, serializable } from 'cc.decorator'; import { EDITOR, TEST } from 'internal:constants'; import { Component } from '../components/component'; @@ -107,7 +102,7 @@ export class Animation extends Eventify(Component) { * @en * Gets or sets the default clip. * Two clips that both have same non-empty UUID are treat as equivalent. - * @en + * @zh * 获取或设置默认剪辑。 * 设置时,若指定的剪辑不在 `this.clips` 中则会被自动添加至 `this.clips`。 * 具有相同的非空 UUID 的两个动画剪辑将被视为是相同的。 @@ -145,13 +140,25 @@ export class Animation extends Eventify(Component) { @tooltip('i18n:animation.play_on_load') public playOnLoad = false; + /** + * @internal + */ protected _crossFade = new CrossFade(); + /** + * @internal + */ protected _nameToState: Record = createMap(true); + /** + * @internal + */ @type([AnimationClip]) protected _clips: (AnimationClip | null)[] = []; + /** + * @internal + */ @serializable protected _defaultClip: AnimationClip | null = null; @@ -306,7 +313,10 @@ export class Animation extends Eventify(Component) { } /** + * @zh * 添加一个动画剪辑到 `this.clips`中并以此剪辑创建动画状态。 + * @en + * Adds an animation clip into this component and creates a animation state for this clip. * @param clip The animation clip * @param name The animation state name, if absent, the default clip's name will be used * @returns The created animation state @@ -423,10 +433,16 @@ export class Animation extends Eventify(Component) { } } + /** + * @internal + */ protected _createState (clip: AnimationClip, name?: string) { return new AnimationState(clip, name); } + /** + * @internal + */ protected _doCreateState (clip: AnimationClip, name: string) { const state = this._createState(clip, name); state._setEventTarget(this); @@ -439,7 +455,6 @@ export class Animation extends Eventify(Component) { } /** - * * @internal This method only friends to skeletal animation component. */ protected doPlayOrCrossFade (state: AnimationState, duration: number) { diff --git a/cocos/core/animation/animation-curve.ts b/cocos/core/animation/animation-curve.ts index be5b09b429..eeeff2b43d 100644 --- a/cocos/core/animation/animation-curve.ts +++ b/cocos/core/animation/animation-curve.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module animation - */ - import { binarySearchEpsilon as binarySearch } from '../algorithm/binary-search'; import { lerp, Quat } from '../math'; import { errorID } from '../platform/debug'; @@ -72,6 +67,9 @@ export class RatioSampler { legacyCC.RatioSampler = RatioSampler; /** + * @en + * Animation curve. + * @zh * 动画曲线。 * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. */ @@ -236,11 +234,14 @@ export class EventInfo { } /** + * @zh * 采样动画曲线。 + * @en + * Samples an animation curve. * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. - * @param curve 动画曲线。 - * @param sampler 采样器。 - * @param ratio 采样比率。 + * @param curve @zh 动画曲线。@en The curve. + * @param sampler @zh 采样器。@en The sampler. + * @param ratio @zh 采样比率。@en Sample ratio([0, 1]). */ export function sampleAnimationCurve (curve: AnimCurve, sampler: RatioSampler, ratio: number) { let index = sampler.sample(ratio); @@ -263,7 +264,10 @@ export function sampleAnimationCurve (curve: AnimCurve, sampler: RatioSampler, r legacyCC.sampleAnimationCurve = sampleAnimationCurve; /** + * @en * Compute a new ratio by curve type. + * @zh + * 根据曲线类型计算新的比例。 * @param ratio - The origin ratio * @param type - If it's Array, then ratio will be computed with bezierByTime. * If it's string, then ratio will be computed with cc.easing function @@ -287,7 +291,6 @@ export function computeRatioByType (ratio: number, type: legacy.LegacyEasingMeth /** * Use this function if intervals between frames are same. - * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. */ function quickFindIndex (ratios: number[], ratio: number) { const length = ratios.length - 1; diff --git a/cocos/core/animation/animation-manager.ts b/cocos/core/animation/animation-manager.ts index 31a04f199a..fe960f6c8d 100644 --- a/cocos/core/animation/animation-manager.ts +++ b/cocos/core/animation/animation-manager.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module animation - */ - import { ccclass } from 'cc.decorator'; import System from '../components/system'; import { director, Director } from '../director'; diff --git a/cocos/core/animation/animation-state.ts b/cocos/core/animation/animation-state.ts index df34974546..49d412134f 100644 --- a/cocos/core/animation/animation-state.ts +++ b/cocos/core/animation/animation-state.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module animation - */ - import { EDITOR } from 'internal:constants'; import { Node } from '../scene-graph/node'; import { AnimationClip } from './animation-clip'; @@ -247,7 +242,10 @@ export class AnimationState extends Playable { } /** - * The weight. + * @en + * The weight of this animation state. + * @zh + * 此动画状态的权重。 */ get weight () { return this._weight; @@ -263,12 +261,12 @@ export class AnimationState extends Playable { public frameRate = 0; /** - * This field is only visible from within internal. + * @internal This field is only visible from within internal. */ protected _targetNode: Node | null = null; /** - * This field is only visible from within internal. + * @internal This field is only visible from within internal. */ protected _curveLoaded = false; @@ -300,7 +298,7 @@ export class AnimationState extends Playable { private _clipEval: ReturnType | undefined; private _clipEventEval: ReturnType | undefined; /** - * For internal usage. Really hack... + * @internal For internal usage. Really hack... */ protected _doNotCreateEval = false; @@ -443,7 +441,7 @@ export class AnimationState extends Playable { /** * This method is used for internal purpose only. - * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. + * @internal */ public _setEventTarget (target) { this._target = target; @@ -515,6 +513,9 @@ export class AnimationState extends Playable { this.emit(EventType.PAUSE, this); } + /** + * @internal + */ protected _sampleCurves (time: number) { const { _poseOutput: poseOutput, _clipEval: clipEval } = this; if (poseOutput) { diff --git a/cocos/core/animation/animation.ts b/cocos/core/animation/animation.ts index c066f9a6a0..0182b5ec69 100644 --- a/cocos/core/animation/animation.ts +++ b/cocos/core/animation/animation.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - export * from './target-path'; export * from './value-proxy'; export { UniformProxyFactory } from './value-proxy-factories/uniform'; diff --git a/cocos/core/animation/compression/compressed-data.ts b/cocos/core/animation/compression/compressed-data.ts index 7981e94bef..ac040e9e50 100644 --- a/cocos/core/animation/compression/compressed-data.ts +++ b/cocos/core/animation/compression/compressed-data.ts @@ -175,7 +175,7 @@ export class CompressedData { } /** - * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. + * @internal */ public _addQuatCurve (curve: QuatCurve): CompressedQuatCurvePointer { const times = Array.from(curve.times()); diff --git a/cocos/core/animation/cross-fade.ts b/cocos/core/animation/cross-fade.ts index acb6d7dd7f..1d4707d15e 100644 --- a/cocos/core/animation/cross-fade.ts +++ b/cocos/core/animation/cross-fade.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module animation - */ - import { clamp01 } from '../math/utils'; import { remove } from '../utils/array'; import { AnimationState } from './animation-state'; diff --git a/cocos/core/animation/cubic-spline-value.ts b/cocos/core/animation/cubic-spline-value.ts index 05b1cfb5d3..d2e6c4bf5b 100644 --- a/cocos/core/animation/cubic-spline-value.ts +++ b/cocos/core/animation/cubic-spline-value.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module animation - */ - import { ccclass, serializable } from 'cc.decorator'; import { Quat, Vec2, Vec3, Vec4 } from '../math'; import { ILerpable } from './types'; diff --git a/cocos/core/animation/exotic-animation/exotic-animation.ts b/cocos/core/animation/exotic-animation/exotic-animation.ts index 8320b64ba1..7fd9eac5d0 100644 --- a/cocos/core/animation/exotic-animation/exotic-animation.ts +++ b/cocos/core/animation/exotic-animation/exotic-animation.ts @@ -50,7 +50,7 @@ export class ExoticAnimation { } /** - * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. + * @internal */ public toHashString () { return this._nodeAnimations.map((nodeAnimation) => nodeAnimation.toHashString()).join('\n'); @@ -116,7 +116,7 @@ class ExoticNodeAnimation { } /** - * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. + * @internal */ public toHashString (): string { return `${this._path}\n${ @@ -183,7 +183,7 @@ class ExoticVectorLikeTrackValues { } /** - * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. + * @internal */ public toHashString (): string { const { _isQuantized: isQuantized, _values: values } = this; @@ -305,7 +305,7 @@ class ExoticTrack { public values!: TTrackValues; /** - * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. + * @internal */ public toHashString (): string { const { times, values } = this; @@ -802,7 +802,7 @@ class QuantizedFloatArray { } /** - * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. + * @internal */ public toHashString (): string { const { originalPrecision, min, extent, values } = this; diff --git a/cocos/core/animation/index.ts b/cocos/core/animation/index.ts index 3111253c36..8567e8a7dc 100644 --- a/cocos/core/animation/index.ts +++ b/cocos/core/animation/index.ts @@ -42,3 +42,4 @@ export { } from './animation-component'; export * from './transform-utils'; export { animation }; +export type { ILerpable } from './types'; diff --git a/cocos/core/animation/marionette/animation-controller.ts b/cocos/core/animation/marionette/animation-controller.ts index 8b75e3d978..9d0bde4f39 100644 --- a/cocos/core/animation/marionette/animation-controller.ts +++ b/cocos/core/animation/marionette/animation-controller.ts @@ -67,8 +67,8 @@ export class AnimationController extends Component { /** * @zh 设置动画图实例中变量的值。 * @en Sets the value of the variable in the animation graph instance. - * @param name 变量名称。 - * @param value 变量的值。 + * @param name @en Variable's name. @zh 变量的名称。 + * @param value @en Variable's value. @zh 变量的值。 * @example * ```ts * animationController.setValue('speed', 3.14); @@ -85,8 +85,8 @@ export class AnimationController extends Component { /** * @zh 获取动画图实例中变量的值。 * @en Gets the value of the variable in the animation graph instance. - * @param name 变量名称。 - * @returns 变量当前的值。 + * @param name @en Variable's name. @zh 变量的名称。 + * @returns @en Variable's value. @zh 变量的值。 */ public getValue (name: string) { const { _graphEval: graphEval } = this; @@ -97,8 +97,9 @@ export class AnimationController extends Component { /** * @zh 获取动画图实例中当前状态的运行状况。 * @en Gets the running status of the current state in the animation graph instance. - * @param layer 层级索引。(必须为 `0`) - * @returns 当前的状态运作状态对象。 + * @param layer @en Index of the layer. @zh 层级索引。 + * @returns @en The running status of the current state. + * @zh 当前的状态运作状态对象。 */ public getCurrentStateStatus (layer: number) { const { _graphEval: graphEval } = this; @@ -109,8 +110,9 @@ export class AnimationController extends Component { /** * @zh 获取动画图实例中当前状态上包含的所有动画剪辑的运行状况。 * @en Gets the running status of all the animation clips added on the current state in the animation graph instance. - * @param layer 层级索引。(必须为 `0`) - * @returns 到动画剪辑运作状态的迭代器。 + * @param layer @en Index of the layer. @zh 层级索引。 + * @returns @en Iterable to the animation clip statuses on current state. + * @zh 到动画剪辑运作状态的迭代器。 */ public getCurrentClipStatuses (layer: number) { const { _graphEval: graphEval } = this; @@ -121,8 +123,9 @@ export class AnimationController extends Component { /** * @zh 获取动画图实例中当前正在进行的过渡的运行状况。 * @en Gets the running status of the transition currently in progress in the animation graph instance. - * @param layer 层级索引。(必须为 `0`) - * @returns 当前正在进行的过渡,若没有进行任何过渡,则返回 `null`。 + * @param layer @en Index of the layer. @zh 层级索引。 + * @returns @en Current transition status. `null` is returned in case of no transition. + * @zh 当前正在进行的过渡,若没有进行任何过渡,则返回 `null`。 */ public getCurrentTransition (layer: number) { const { _graphEval: graphEval } = this; @@ -133,8 +136,9 @@ export class AnimationController extends Component { /** * @zh 获取动画图实例中下一个状态的运行状况。 * @en Gets the running status of the next state in the animation graph instance. - * @param layer 层级索引。(必须为 `0`) - * @returns 下一状态运作状态对象,若未在进行过渡,则返回 `null`。 + * @param layer @en Index of the layer. @zh 层级索引。 + * @returns @en The running status of the next state. `null` is returned in case of no transition. + * @zh 下一状态运作状态对象,若未在进行过渡,则返回 `null`。 */ public getNextStateStatus (layer: number) { const { _graphEval: graphEval } = this; @@ -145,8 +149,9 @@ export class AnimationController extends Component { /** * @zh 获取动画图实例中下一个状态上添加的所有动画剪辑的运行状况。 * @en Gets the running status of all the animation clips added on the next state in the animation graph instance. - * @param layer 层级索引。(必须为 `0`) - * @returns 到下一状态上包含的动画剪辑运作状态的迭代器,若未在进行过渡,则返回一个空的迭代器。 + * @param layer @en Index of the layer. @zh 层级索引。 + * @returns @en Iterable to the animation clip statuses on next state. An empty iterable is returned in case of no transition. + * @zh 到下一状态上包含的动画剪辑运作状态的迭代器,若未在进行过渡,则返回一个空的迭代器。 */ public getNextClipStatuses (layer: number) { const { _graphEval: graphEval } = this; @@ -154,6 +159,11 @@ export class AnimationController extends Component { return graphEval.getNextClipStatuses(layer); } + /** + * @zh 设置层级权重。 + * @en Sets the weight of specified layer. + * @param layer @en Index of the layer. @zh 层级索引。 + */ public setLayerWeight (layer: number, weight: number) { const { _graphEval: graphEval } = this; assertIsNonNullable(graphEval); diff --git a/cocos/core/animation/marionette/animation-graph.ts b/cocos/core/animation/marionette/animation-graph.ts index e75eeb2696..bcf49f7408 100644 --- a/cocos/core/animation/marionette/animation-graph.ts +++ b/cocos/core/animation/marionette/animation-graph.ts @@ -140,7 +140,7 @@ export class StateMachine extends EditorExtendable { /** * // TODO: HACK - * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. + * @internal */ public __callOnAfterDeserializeRecursive () { this[onAfterDeserializedTag](); @@ -631,7 +631,16 @@ class TriggerVariable implements BasicVariableDescription private _flags = TRIGGER_VARIABLE_DEFAULT_FLAGS; } +/** + * @en + * An opacity type which denotes what the animation graph seems like outside the engine. + * @zh + * 一个非透明的类型,它是动画图在引擎外部的表示。 + */ export interface AnimationGraphRunTime { + /** + * @internal + */ readonly __brand: 'AnimationGraph'; } diff --git a/cocos/core/animation/marionette/clip-motion.ts b/cocos/core/animation/marionette/clip-motion.ts index 374a5ccd95..1f27df5deb 100644 --- a/cocos/core/animation/marionette/clip-motion.ts +++ b/cocos/core/animation/marionette/clip-motion.ts @@ -33,7 +33,7 @@ export class ClipMotion extends EditorExtendable implements Motion { class ClipMotionEval implements MotionEval { /** - * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. + * @internal */ public declare __DEBUG__ID__?: string; diff --git a/cocos/core/animation/marionette/graph-eval.ts b/cocos/core/animation/marionette/graph-eval.ts index 7afdc56c23..00482a9583 100644 --- a/cocos/core/animation/marionette/graph-eval.ts +++ b/cocos/core/animation/marionette/graph-eval.ts @@ -167,30 +167,60 @@ export class AnimationGraphEval { private _hasAutoTrigger = false; } +/** + * @en + * Runtime status of a transition. + * @zh + * 过渡的运行状态。 + */ export interface TransitionStatus { /** + * @en * The duration of the transition. + * @zh + * 过渡的周期。 */ duration: number; /** + * @en * The progress of the transition. + * @zh + * 过渡的进度。 */ time: number; } +/** + * @en + * Runtime clip status of a motion state. + * @zh + * 动作状态中包含的剪辑的运行状态。 + */ export interface ClipStatus { /** + * @en * The clip object. + * @zh + * 剪辑对象。 */ clip: AnimationClip; /** + * @en * The clip's weight. + * @zh + * 剪辑的权重。 */ weight: number; } +/** + * @en + * Runtime status of a motion state. + * @zh + * 动作状态的运行状态。 + */ export interface MotionStateStatus { /** * For testing. @@ -200,7 +230,10 @@ export interface MotionStateStatus { __DEBUG_ID__?: string; /** + * @en * The normalized time of the state. + * @zh + * 状态的规范化进度。 */ progress: number; } @@ -1071,7 +1104,7 @@ enum NodeKind { export class StateEval { /** - * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. + * @internal */ public declare __DEBUG_ID__?: string; diff --git a/cocos/core/animation/marionette/state-machine-component.ts b/cocos/core/animation/marionette/state-machine-component.ts index 1a3d2a2987..875fe85120 100644 --- a/cocos/core/animation/marionette/state-machine-component.ts +++ b/cocos/core/animation/marionette/state-machine-component.ts @@ -2,10 +2,17 @@ import { ccclass } from 'cc.decorator'; import { CLASS_NAME_PREFIX_ANIM } from '../define'; import type { AnimationController, MotionStateStatus } from './animation-controller'; +/** + * @en State machine component. + * @zh 状态机组件。 + */ @ccclass(`${CLASS_NAME_PREFIX_ANIM}StateMachineComponent`) export class StateMachineComponent { /** + * @en * Called when a motion state right after it entered. + * @zh + * 在刚刚进入动作状态时调用。 * @param controller The animation controller it within. * @param motionStateStatus The status of the motion. */ @@ -14,7 +21,10 @@ export class StateMachineComponent { } /** + * @en * Called when a motion state is going to be exited. + * @zh + * 在即将退出动作状态时调用。 * @param controller The animation controller it within. * @param motionStateStatus The status of the motion. */ @@ -23,7 +33,10 @@ export class StateMachineComponent { } /** + * @en * Called when a motion state updated except for the first and last frame. + * @zh + * 在动作状态更新时调用,但不会在第一次和最后一次时调用。 * @param controller The animation controller it within. * @param motionStateStatus The status of the motion. */ @@ -32,7 +45,10 @@ export class StateMachineComponent { } /** + * @en * Called when a state machine right after it entered. + * @zh + * 在刚刚进入状态机时调用。 * @param controller The animation controller it within. */ public onStateMachineEnter (controller: AnimationController) { @@ -40,7 +56,10 @@ export class StateMachineComponent { } /** + * @en * Called when a state machine right after it entered. + * @zh + * 在即将退出状态机时调用。 * @param controller The animation controller it within. */ public onStateMachineExit (controller: AnimationController) { diff --git a/cocos/core/animation/marionette/variable.ts b/cocos/core/animation/marionette/variable.ts index ccc27ece0e..3906056fdc 100644 --- a/cocos/core/animation/marionette/variable.ts +++ b/cocos/core/animation/marionette/variable.ts @@ -1,25 +1,64 @@ +/** + * @en + * Represents variable's value. + * @zh + * 表示变量的值。 + */ export type Value = number | string | boolean; +/** + * @en + * Represents animation graph variable types. + * @zh + * 表示动画图变量的类型。 + */ export enum VariableType { + /** + * @en + * A floating. + * @zh + * 浮点数。 + */ FLOAT, + /** + * @en + * A boolean. + * @zh + * 布尔值。 + */ BOOLEAN, + /** + * @en + * A trigger. + * @zh + * 触发器。 + */ TRIGGER, + /** + * @en + * An integer. + * @zh + * 整数。 + */ INTEGER, } /** + * @en The reset mode of boolean variables. It indicates when to reset the variable as `false`. * @zh 布尔类型变量的重置模式,指示在哪些情况下将变量重置为 `false`。 */ export enum TriggerResetMode { /** + * @en The variable is reset when it's consumed by animation transition. * @zh 在该变量被动画过渡消耗后自动重置。 */ AFTER_CONSUMED, /** + * @en The variable is reset in next frame or when it's consumed by animation transition. * @zh 下一帧自动重置;在该变量被动画过渡消耗后也会自动重置。 */ NEXT_FRAME_OR_AFTER_CONSUMED, diff --git a/cocos/core/animation/motion-path-helper.ts b/cocos/core/animation/motion-path-helper.ts index 5f2a94fb9f..961d7f9dca 100644 --- a/cocos/core/animation/motion-path-helper.ts +++ b/cocos/core/animation/motion-path-helper.ts @@ -23,16 +23,12 @@ THE SOFTWARE. */ - - import { binarySearchEpsilon as binarySearch } from '../algorithm/binary-search'; import { errorID } from '../platform/debug'; import { Vec2, Vec3 } from '../math'; import { AnimCurve, computeRatioByType, CurveValue, EasingMethod } from './animation-curve'; import { bezier } from './bezier'; - - export class Curve { public beziers: Bezier[] = []; diff --git a/cocos/core/animation/playable.ts b/cocos/core/animation/playable.ts index 7c24c96e39..bf3e6c6019 100644 --- a/cocos/core/animation/playable.ts +++ b/cocos/core/animation/playable.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module animation - */ - import { getError } from '../platform/debug'; export class Playable { diff --git a/cocos/core/animation/skeletal-animation-utils.ts b/cocos/core/animation/skeletal-animation-utils.ts index 65563e0084..8f5d6dbd04 100644 --- a/cocos/core/animation/skeletal-animation-utils.ts +++ b/cocos/core/animation/skeletal-animation-utils.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { EDITOR } from 'internal:constants'; import { Mat4 } from '../math'; import { Node } from '../scene-graph/node'; diff --git a/cocos/core/animation/target-path.ts b/cocos/core/animation/target-path.ts index 317bc36681..6b7a061492 100644 --- a/cocos/core/animation/target-path.ts +++ b/cocos/core/animation/target-path.ts @@ -23,32 +23,53 @@ THE SOFTWARE. */ - - import { ccclass, serializable } from 'cc.decorator'; import { Node } from '../scene-graph/node'; import { warn, warnID } from '../platform/debug'; +/** + * @deprecated Since V3.3, use [[TrackPath]] instead. + */ export type PropertyPath = string | number; +/** + * @deprecated Since V3.3, use [[TrackPath]] instead. + */ export interface ICustomTargetPath { /** + * @en + * Gets next target from current target. * If errors are encountered, `null` should be returned. + * @zh + * 从当前目标中获取下一个目标。 + * 若错误发生,应返回 `null`。 * @param target */ get(target: any): any; } +/** + * @deprecated Since V3.3, use [[TrackPath]] instead. + */ export type TargetPath = PropertyPath | ICustomTargetPath; +/** + * @deprecated Since V3.3, use [[TrackPath]] instead. + */ export function isPropertyPath (path: TargetPath): path is PropertyPath { return typeof path === 'string' || typeof path === 'number'; } +/** + * @deprecated Since V3.3, use [[TrackPath]] instead. + */ export function isCustomPath (path: TargetPath, constructor: Constructor): path is T { return path instanceof constructor; } +/** + * @deprecated Since V3.3, use [[TrackPath]] instead. + */ @ccclass('cc.animation.HierarchyPath') export class HierarchyPath implements ICustomTargetPath { @serializable @@ -72,6 +93,9 @@ export class HierarchyPath implements ICustomTargetPath { } } +/** + * @deprecated Since V3.3, use [[TrackPath]] instead. + */ @ccclass('cc.animation.ComponentPath') export class ComponentPath implements ICustomTargetPath { @serializable diff --git a/cocos/core/animation/tracks/color-track.ts b/cocos/core/animation/tracks/color-track.ts index afe5e505d1..46a789a952 100644 --- a/cocos/core/animation/tracks/color-track.ts +++ b/cocos/core/animation/tracks/color-track.ts @@ -7,6 +7,12 @@ import { maskIfEmpty } from './utils'; const CHANNEL_NAMES: ReadonlyArray = ['Red', 'Green', 'Blue', 'Alpha']; +/** + * @en + * A color track animates a color attribute of target. + * @zh + * 颜色轨道描述目标上某个颜色属性的动画。 + */ @ccclass(`${CLASS_NAME_PREFIX_ANIM}ColorTrack`) export class ColorTrack extends Track { constructor () { @@ -19,6 +25,12 @@ export class ColorTrack extends Track { } } + /** + * @en The four channel of the track. + * @zh 返回此轨道的四条通道。 + * @returns An readonly four length array in which + * the element at n denotes the channel of n-th(in order of RGBA) color component(in form of integer within 0-255). + */ public channels () { return this._channels; } diff --git a/cocos/core/animation/tracks/object-track.ts b/cocos/core/animation/tracks/object-track.ts index ab88e20ed9..fbbd79b0c7 100644 --- a/cocos/core/animation/tracks/object-track.ts +++ b/cocos/core/animation/tracks/object-track.ts @@ -3,6 +3,12 @@ import { ObjectCurve } from '../../curves'; import { CLASS_NAME_PREFIX_ANIM, createEvalSymbol } from '../define'; import { SingleChannelTrack } from './track'; +/** + * @en + * An object track animates an object of attribute of target. + * @zh + * 对象轨道描述目标上某个对象类型的属性的动画。 + */ @ccclass(`${CLASS_NAME_PREFIX_ANIM}ObjectTrack`) export class ObjectTrack extends SingleChannelTrack> { /** diff --git a/cocos/core/animation/tracks/quat-track.ts b/cocos/core/animation/tracks/quat-track.ts index 47ce23338f..2bb73c2555 100644 --- a/cocos/core/animation/tracks/quat-track.ts +++ b/cocos/core/animation/tracks/quat-track.ts @@ -4,6 +4,12 @@ import { CLASS_NAME_PREFIX_ANIM, createEvalSymbol } from '../define'; import { SingleChannelTrack } from './track'; import { Quat } from '../../math'; +/** + * @en + * A quaternion track animates a quaternion(rotation) attribute of target. + * @zh + * 四元数轨道描述目标上某个四元数(旋转)属性的动画。 + */ @ccclass(`${CLASS_NAME_PREFIX_ANIM}QuatTrack`) export class QuatTrack extends SingleChannelTrack { /** diff --git a/cocos/core/animation/tracks/real-track.ts b/cocos/core/animation/tracks/real-track.ts index 2968a0acf6..60c2b4b324 100644 --- a/cocos/core/animation/tracks/real-track.ts +++ b/cocos/core/animation/tracks/real-track.ts @@ -3,6 +3,12 @@ import { RealCurve } from '../../curves'; import { CLASS_NAME_PREFIX_ANIM } from '../define'; import { SingleChannelTrack } from './track'; +/** + * @en + * A real track animates a scalar attribute of target. + * @zh + * 实数轨道描述目标上某个标量属性的动画。 + */ @ccclass(`${CLASS_NAME_PREFIX_ANIM}RealTrack`) export class RealTrack extends SingleChannelTrack { /** diff --git a/cocos/core/animation/tracks/size-track.ts b/cocos/core/animation/tracks/size-track.ts index a57b18c09a..c167381819 100644 --- a/cocos/core/animation/tracks/size-track.ts +++ b/cocos/core/animation/tracks/size-track.ts @@ -7,6 +7,12 @@ import { maskIfEmpty } from './utils'; const CHANNEL_NAMES: ReadonlyArray = ['Width', 'Height']; +/** + * @en + * A size track animates a size attribute of target. + * @zh + * 尺寸轨道描述目标上某个尺寸属性的动画。 + */ @ccclass(`${CLASS_NAME_PREFIX_ANIM}SizeTrack`) export class SizeTrack extends Track { constructor () { @@ -19,6 +25,12 @@ export class SizeTrack extends Track { } } + /** + * @en The width channel and the height channel of the track. + * @zh 返回此轨道的宽度通道和高度通道。 + * @returns An readonly array in which + * the first element is the width channel and the second element is the height channel. + */ public channels () { return this._channels; } diff --git a/cocos/core/animation/tracks/track.ts b/cocos/core/animation/tracks/track.ts index 5f070002ed..4f4389e9e7 100644 --- a/cocos/core/animation/tracks/track.ts +++ b/cocos/core/animation/tracks/track.ts @@ -28,27 +28,59 @@ export type Binder = (binding: TrackBinding) => undefined | RuntimeBinding; export type TrsTrackPath = [HierarchyPath, 'position' | 'rotation' | 'scale' | 'eulerAngles']; +/** + * @en Describes how to find the animation target. + * @zh 描述怎样寻址动画目标。 + */ @ccclass(`${CLASS_NAME_PREFIX_ANIM}TrackPath`) class TrackPath { + /** + * @en The length of the path. + * @zh 此路径的段数。 + */ get length () { return this._paths.length; } + /** + * @en Appends a property path. + * @zh 附加一段属性路径。 + * @param name The property's name. + * @returns `this` + */ public toProperty (name: string) { this._paths.push(name); return this; } + /** + * @en Appends an array element path. + * @zh 附加一段数组元素路径。 + * @param index The element's index. + * @returns `this` + */ public toElement (index: number) { this._paths.push(index); return this; } + /** + * @en Appends a hierarchy path. + * @zh 附加一段层级路径。 + * @param nodePath Path to the children. + * @returns `this` + */ public toHierarchy (nodePath: string) { this._paths.push(new HierarchyPath(nodePath)); return this; } + /** + * @en Appends a component path. + * @zh 附加一段组件路径。 + * @param constructor @en The constructor of the component. @zh 组件的构造函数。 + * @returns `this` + */ public toComponent (constructor: Constructor | string) { const path = new ComponentPath(typeof constructor === 'string' ? constructor : js.getClassName(constructor)); this._paths.push(path); @@ -56,60 +88,123 @@ class TrackPath { } /** - * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. Reserved for backward compatibility. - * DO NOT USE IT IN YOUR CODE. + * @internal Reserved for backward compatibility. DO NOT USE IT IN YOUR CODE. */ public toCustomized (resolver: CustomizedTrackPathResolver) { this._paths.push(resolver); return this; } + /** + * @en Appends paths to this path. + * @zh 附加指定路径到此路径后。 + * @param trackPaths Paths to append. + * @returns `this`. + */ public append (...trackPaths: TrackPath[]) { const paths = this._paths.concat(...trackPaths.map((trackPath) => trackPath._paths)); this._paths = paths; return this; } + /** + * @zh 判断指定路径段是否是属性路径。 + * @en Decides if the specific path segment is property path. + * @param index Index to the segment。 + * @returns The judgement result. + */ public isPropertyAt (index: number) { return typeof (this._paths[index]) === 'string'; } + /** + * @zh 将指定路径段视为属性路径,获取其描述的属性。 + * @en Treats the path segment as a property path. Obtains the property it describes. + * @param index Index to the segment。 + * @returns The property. + */ public parsePropertyAt (index: number): string { return this._paths[index] as string; } + /** + * @zh 判断指定路径段是否是数组元素路径。 + * @en Decides if the specific path segment is an array element path. + * @param index Index to the segment。 + * @returns The judgement result. + */ public isElementAt (index: number) { return typeof this._paths[index] === 'number'; } + /** + * @zh 将指定路径段视为数组元素路径,获取其描述的数组元素。 + * @en Treats the path segment as an array element path. Obtains the element index it describes. + * @param index Index to the segment。 + * @returns The element index. + */ public parseElementAt (index: number): number { return this._paths[index] as number; } + /** + * @zh 判断指定路径段是否是层级路径。 + * @en Decides if the specific path segment is a hierarchy path. + * @param index Index to the segment。 + * @returns The judgement result. + */ public isHierarchyAt (index: number) { return this._paths[index] instanceof HierarchyPath; } + /** + * @zh 将指定路径段视为层级路径,获取其描述的层级路径。 + * @en Treats the path segment as a hierarchy path. Obtains the hierarchy path it describes. + * @param index Index to the segment。 + * @returns The hierarchy path. + */ public parseHierarchyAt (index: number) { assertIsTrue(this.isHierarchyAt(index)); return (this._paths[index] as HierarchyPath).path; } + /** + * @zh 判断指定路径段是否是组件路径。 + * @en Decides if the specific path segment is a component path. + * @param index Index to the segment。 + * @returns The judgement result. + */ public isComponentAt (index: number) { return this._paths[index] instanceof ComponentPath; } + /** + * @zh 将指定路径段视为组件路径,获取其描述的组件路径。 + * @en Treats the path segment as a hierarchy path. Obtains the component path it describes. + * @param index Index to the segment。 + * @returns The component path. + */ public parseComponentAt (index: number) { assertIsTrue(this.isComponentAt(index)); return (this._paths[index] as ComponentPath).component; } + /** + * @en Slices a interval of the path. + * @zh 分割指定区段上的路径。 + * @param beginIndex Begin index to the segment. Default to 0. + * @param endIndex End index to the segment. Default to the last segment. + * @returns The new path. + */ public slice (beginIndex?: number, endIndex?: number) { const trackPath = new TrackPath(); trackPath._paths = this._paths.slice(beginIndex, endIndex); return trackPath; } + /** + * @internal + */ public trace (object: unknown, beginIndex?: number, endIndex?: number) { beginIndex ??= 0; endIndex ??= this._paths.length; @@ -292,11 +387,18 @@ interface CustomizedTrackPathResolver { export { TrackPath }; /** - * A track describes the path of animate a target. + * @en + * A track describes how to trace the target and how to animate it. * It's the basic unit of animation clip. + * @zh + * 轨道描述了动画目标的路径和动画的方式。它是动画剪辑的基础单元。 */ @ccclass(`${CLASS_NAME_PREFIX_ANIM}Track`) export abstract class Track { + /** + * @en Track path. + * @zh 轨道路径。 + */ get path () { return this._binding.path; } @@ -305,6 +407,10 @@ export abstract class Track { this._binding.path = value; } + /** + * @en Value proxy for the target. + * @zh 目标的值代理。 + */ get proxy () { return this._binding.proxy; } @@ -320,10 +426,20 @@ export abstract class Track { return this._binding; } + /** + * @en Channels on this track. + * @zh 此轨道上的通道。 + * @returns Iterator to the channels. + */ public channels (): Iterable { return []; } + /** + * @en Time range of this track. + * @zh 此轨道的时间范围。 + * @returns The time range. + */ public range (): Range { const range: Range = { min: Infinity, max: -Infinity }; for (const channel of this.channels()) { @@ -352,6 +468,12 @@ export interface TrackEval { export type Curve = RealCurve | QuatCurve | ObjectCurve; +/** + * @en + * Channel contains a curve. + * @zh + * 通道包含了一条曲线。 + */ @ccclass(`${CLASS_NAME_PREFIX_ANIM}Channel`) export class Channel { constructor (curve: T) { @@ -359,10 +481,14 @@ export class Channel { } /** - * Not used for now. + * @internal Not used for now. */ public name = ''; + /** + * @en The curve within the channel. + * @zh 通道中的曲线。 + */ get curve () { return this._curve; } @@ -375,6 +501,10 @@ export type RealChannel = Channel; export type QuatChannel = Channel; +/** + * @en 表示一个包含了单条通道的轨道。 + * @zh Describes a track which contains only single channel. + */ @ccclass(`${CLASS_NAME_PREFIX_ANIM}SingleChannelTrack`) export abstract class SingleChannelTrack extends Track { constructor () { @@ -382,6 +512,10 @@ export abstract class SingleChannelTrack extends Track { this._channel = new Channel(this.createCurve()); } + /** + * @en The channel within the track. + * @zh 轨道包含的通道。 + */ get channel () { return this._channel; } diff --git a/cocos/core/animation/tracks/vector-track.ts b/cocos/core/animation/tracks/vector-track.ts index 49e67a6e8b..a553f318f5 100644 --- a/cocos/core/animation/tracks/vector-track.ts +++ b/cocos/core/animation/tracks/vector-track.ts @@ -7,6 +7,12 @@ import { maskIfEmpty } from './utils'; const CHANNEL_NAMES: ReadonlyArray = ['X', 'Y', 'Z', 'W']; +/** + * @en + * A vector track animates a vector(in 2, 3, 4 dimension) attribute of target. + * @zh + * 向量轨道描述目标上某个(二、三、四维)向量属性的动画。 + */ @ccclass(`${CLASS_NAME_PREFIX_ANIM}VectorTrack`) export class VectorTrack extends Track { constructor () { @@ -19,6 +25,10 @@ export class VectorTrack extends Track { } } + /** + * @en Gets or sets the count of components(dimension) available while evaluating of this track. + * @zh 获取或设置此轨道在求值时有效的分量数(维度)。 + */ get componentsCount () { return this._nComponents; } @@ -27,6 +37,12 @@ export class VectorTrack extends Track { this._nComponents = value; } + /** + * @en The four channel of the track. + * @zh 返回此轨道的四条通道。 + * @returns An readonly four length array in which + * the element at n denotes the channel of n-th vector component. + */ public channels () { return this._channels; } diff --git a/cocos/core/animation/transform-utils.ts b/cocos/core/animation/transform-utils.ts index bdebaa3b94..670a34c972 100644 --- a/cocos/core/animation/transform-utils.ts +++ b/cocos/core/animation/transform-utils.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module animation - */ - import { Mat4 } from '../math'; import { Node } from '../scene-graph'; diff --git a/cocos/core/animation/types.ts b/cocos/core/animation/types.ts index 6ba36624fb..83450cc289 100644 --- a/cocos/core/animation/types.ts +++ b/cocos/core/animation/types.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module animation - */ - import { ccenum } from '../value-types/enum'; export enum WrapModeMask { diff --git a/cocos/core/animation/value-proxy-factories/index.ts b/cocos/core/animation/value-proxy-factories/index.ts index 0f44967c6b..f289d423b4 100644 --- a/cocos/core/animation/value-proxy-factories/index.ts +++ b/cocos/core/animation/value-proxy-factories/index.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - export * from './uniform'; export { MorphWeightValueProxy, MorphWeightsValueProxy, MorphWeightsAllValueProxy } from './morph-weights'; diff --git a/cocos/core/animation/value-proxy-factories/morph-weights.ts b/cocos/core/animation/value-proxy-factories/morph-weights.ts index 26c9ab3db0..42cccb000b 100644 --- a/cocos/core/animation/value-proxy-factories/morph-weights.ts +++ b/cocos/core/animation/value-proxy-factories/morph-weights.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { ccclass, serializable } from 'cc.decorator'; import { MeshRenderer } from '../../../3d/framework/mesh-renderer'; import { IValueProxyFactory } from '../value-proxy'; diff --git a/cocos/core/animation/value-proxy-factories/uniform.ts b/cocos/core/animation/value-proxy-factories/uniform.ts index 088a86366b..05599934aa 100644 --- a/cocos/core/animation/value-proxy-factories/uniform.ts +++ b/cocos/core/animation/value-proxy-factories/uniform.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { ccclass, float, serializable } from 'cc.decorator'; import { builtinResMgr } from '../../builtin/builtin-res-mgr'; import { Material } from '../../assets/material'; diff --git a/cocos/core/animation/value-proxy.ts b/cocos/core/animation/value-proxy.ts index ab84d194ec..cfb6d0dd89 100644 --- a/cocos/core/animation/value-proxy.ts +++ b/cocos/core/animation/value-proxy.ts @@ -24,17 +24,27 @@ */ /** - * @packageDocumentation - * @module animation - */ - -/** + * @en + * Value proxies are used to set curve value to target. They are "generalized assignment". + * Every value proxy associates with a target object. + * @zh * 曲线值代理用来设置曲线值到目标,是广义的赋值。 * 每个曲线值代理都关联着一个目标对象。 */ export interface IValueProxy { - get?: () => any; /** + * @en + * Gets the value from the target. + * This method is used for implementing component-wise animation in certain circumstance. + * @zh + * 从目标中获取值。某些情况下可能需要这个接口来实现分量动画。 + */ + get?: () => any; + + /** + * @en + * Sets a value. + * @zh * 设置曲线值到目标对象上。 */ set: (value: any) => void; @@ -42,8 +52,11 @@ export interface IValueProxy { export interface IValueProxyFactory { /** + * @en + * Returns a value proxy for specific target. + * @zh * 返回指定目标的曲线值代理。 - * @param target + * @param target The target acquiring the value proxy. */ forTarget (target: any): IValueProxy; } diff --git a/cocos/core/asset-manager/asset-manager.ts b/cocos/core/asset-manager/asset-manager.ts index ab842b132d..4df29945ad 100644 --- a/cocos/core/asset-manager/asset-manager.ts +++ b/cocos/core/asset-manager/asset-manager.ts @@ -22,10 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/** - * @packageDocumentation - * @module asset-manager - */ + import { BUILD, EDITOR, PREVIEW } from 'internal:constants'; import { Asset } from '../assets/asset'; import { legacyCC } from '../global-exports'; @@ -116,10 +113,10 @@ export interface IAssetManagerOptions { /** * @en * This module controls asset's behaviors and information, include loading, releasing etc. it is a singleton - * All member can be accessed with `cc.assetManager`. + * All member can be accessed with `assetManager`. * * @zh - * 此模块管理资源的行为和信息,包括加载,释放等,这是一个单例,所有成员能够通过 `cc.assetManager` 调用 + * 此模块管理资源的行为和信息,包括加载,释放等,这是一个单例,所有成员能够通过 `assetManager` 调用 * */ export class AssetManager { @@ -358,9 +355,9 @@ export class AssetManager { * * @example * // ${project}/assets/test1 - * cc.assetManager.getBundle('test1'); + * assetManager.getBundle('test1'); * - * cc.assetManager.getBundle('resources'); + * assetManager.getBundle('resources'); * */ public getBundle (name: string): Bundle | null { @@ -370,15 +367,15 @@ export class AssetManager { /** * @en * Remove this bundle. NOTE: The asset within this bundle will not be released automatically, - * you can call [[Bundle.releaseAll]] manually before remove it if you need + * you can call [[AssetManager.Bundle.releaseAll]] manually before remove it if you need * * @zh - * 移除此包, 注意:这个包内的资源不会自动释放, 如果需要的话你可以在摧毁之前手动调用 [[Bundle.releaseAll]] 进行释放 + * 移除此包, 注意:这个包内的资源不会自动释放, 如果需要的话你可以在摧毁之前手动调用 [[AssetManager.Bundle.releaseAll]] 进行释放 * * @param bundle - The bundle to be removed * * @typescript - * removeBundle(bundle: cc.AssetManager.Bundle): void + * removeBundle(bundle: AssetManager.Bundle): void */ public removeBundle (bundle: Bundle) { bundle._destroy(); @@ -420,20 +417,20 @@ export class AssetManager { * @param onComplete.data - The loaded content * * @example - * cc.assetManager.loadAny({url: 'http://example.com/a.png'}, (err, img) => cc.log(img)); - * cc.assetManager.loadAny(['60sVXiTH1D/6Aft4MRt9VC'], (err, assets) => cc.log(assets)); - * cc.assetManager.loadAny([{ uuid: '0cbZa5Y71CTZAccaIFluuZ'}, {url: 'http://example.com/a.png'}], (err, assets) => cc.log(assets)); - * cc.assetManager.downloader.register('.asset', (url, options, onComplete) => { + * assetManager.loadAny({url: 'http://example.com/a.png'}, (err, img) => log(img)); + * assetManager.loadAny(['60sVXiTH1D/6Aft4MRt9VC'], (err, assets) => log(assets)); + * assetManager.loadAny([{ uuid: '0cbZa5Y71CTZAccaIFluuZ'}, {url: 'http://example.com/a.png'}], (err, assets) => log(assets)); + * assetManager.downloader.register('.asset', (url, options, onComplete) => { * url += '?userName=' + options.userName + "&password=" + options.password; - * cc.assetManager.downloader.downloadFile(url, null, onComplete); + * assetManager.downloader.downloadFile(url, null, onComplete); * }); - * cc.assetManager.parser.register('.asset', (file, options, onComplete) => { + * assetManager.parser.register('.asset', (file, options, onComplete) => { * var json = JSON.parse(file); * var skin = json[options.skin]; * var model = json[options.model]; * onComplete(null, {skin, model}); * }); - * cc.assetManager.loadAny({ url: 'http://example.com/my.asset', skin: 'xxx', model: 'xxx', userName: 'xxx', password: 'xxx' }); + * assetManager.loadAny({ url: 'http://example.com/my.asset', skin: 'xxx', model: 'xxx', userName: 'xxx', password: 'xxx' }); * */ public loadAny (requests: Request, options: IOptions | null, onProgress: ProgressCallback | null, onComplete: CompleteCallbackWithData | null): void; @@ -458,13 +455,13 @@ export class AssetManager { /** * @en * General interface used to preload assets with a progression callback and a complete callback.It is highly recommended that you use - * more simple API, such as `preloadRes`, `preloadResDir` etc. Everything about preload is just likes `cc.assetManager.loadAny`, the - * difference is `cc.assetManager.preloadAny` will only download asset but not parse asset. You need to invoke `cc.assetManager.loadAny(preloadTask)` + * more simple API, such as `preloadRes`, `preloadResDir` etc. Everything about preload is just likes `assetManager.loadAny`, the + * difference is `assetManager.preloadAny` will only download asset but not parse asset. You need to invoke `assetManager.loadAny(preloadTask)` * to finish loading asset * * @zh * 通用预加载资源接口,可传入进度回调以及完成回调,非常建议你使用更简单的 API ,例如 `preloadRes`, `preloadResDir` 等。`preloadAny` 和 `loadAny` - * 几乎一样,区别在于 `preloadAny` 只会下载资源,不会去解析资源,你需要调用 `cc.assetManager.loadAny(preloadTask)` 来完成资源加载。 + * 几乎一样,区别在于 `preloadAny` 只会下载资源,不会去解析资源,你需要调用 `assetManager.loadAny(preloadTask)` 来完成资源加载。 * * @param requests - The request you want to preload * @param options - Optional parameters @@ -477,7 +474,7 @@ export class AssetManager { * @param onComplete.items - The preloaded content * * @example - * cc.assetManager.preloadAny('0cbZa5Y71CTZAccaIFluuZ', (err) => cc.assetManager.loadAny('0cbZa5Y71CTZAccaIFluuZ')); + * assetManager.preloadAny('0cbZa5Y71CTZAccaIFluuZ', (err) => assetManager.loadAny('0cbZa5Y71CTZAccaIFluuZ')); * */ public preloadAny ( @@ -517,9 +514,9 @@ export class AssetManager { * @param onComplete.asset - The loaded texture * * @example - * cc.assetManager.loadRemote('http://www.cloud.com/test1.jpg', (err, texture) => console.log(err)); - * cc.assetManager.loadRemote('http://www.cloud.com/test2.mp3', (err, audioClip) => console.log(err)); - * cc.assetManager.loadRemote('http://www.cloud.com/test3', { ext: '.png' }, (err, texture) => console.log(err)); + * assetManager.loadRemote('http://www.cloud.com/test1.jpg', (err, texture) => console.log(err)); + * assetManager.loadRemote('http://www.cloud.com/test2.mp3', (err, audioClip) => console.log(err)); + * assetManager.loadRemote('http://www.cloud.com/test3', { ext: '.png' }, (err, texture) => console.log(err)); * */ public loadRemote (url: string, options: IRemoteOptions | null, onComplete?: CompleteCallbackWithData | null): void; @@ -608,7 +605,7 @@ export class AssetManager { * * @example * // release a texture which is no longer need - * cc.assetManager.releaseAsset(texture); + * assetManager.releaseAsset(texture); * */ public releaseAsset (asset: Asset): void { diff --git a/cocos/core/asset-manager/bundle.ts b/cocos/core/asset-manager/bundle.ts index 2ef8438dab..bbc391ba76 100644 --- a/cocos/core/asset-manager/bundle.ts +++ b/cocos/core/asset-manager/bundle.ts @@ -22,10 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/** - * @packageDocumentation - * @module asset-manager - */ + import { Asset } from '../assets/asset'; import { SceneAsset } from '../assets/scene-asset'; import { legacyCC } from '../global-exports'; @@ -99,11 +96,11 @@ export default class Bundle { * 使用 path 获取资源的配置信息 * * @param path - The relative path of asset, such as 'images/a' - * @param type - The constructor of asset, such as `cc.Texture2D` + * @param type - The constructor of asset, such as `Texture2D` * @returns The asset info * * @example - * var info = bundle.getInfoWithPath('image/a', cc.Texture2D); + * var info = bundle.getInfoWithPath('image/a', Texture2D); * */ public getInfoWithPath (path: string, type?: AssetType | null): IAddressableInfo | null { @@ -124,7 +121,7 @@ export default class Bundle { * * @example * var infos = []; - * bundle.getDirWithPath('images', cc.Texture2D, infos); + * bundle.getDirWithPath('images', Texture2D, infos); */ public getDirWithPath (path: string, type?: AssetType | null, out?: IAddressableInfo[]): IAddressableInfo[] { return this._config.getDirWithPath(path, type, out); @@ -202,16 +199,16 @@ export default class Bundle { * * @example * // load the texture (${project}/assets/resources/textures/background.jpg) from resources - * cc.resources.load('textures/background', cc.Texture2D, (err, texture) => console.log(err)); + * resources.load('textures/background', Texture2D, (err, texture) => console.log(err)); * * // load the audio (${project}/assets/resources/music/hit.mp3) from resources - * cc.resources.load('music/hit', cc.AudioClip, (err, audio) => console.log(err)); + * resources.load('music/hit', AudioClip, (err, audio) => console.log(err)); * * // load the prefab (${project}/assets/bundle1/misc/character/cocos) from bundle1 folder - * bundle1.load('misc/character/cocos', cc.Prefab, (err, prefab) => console.log(err)); + * bundle1.load('misc/character/cocos', Prefab, (err, prefab) => console.log(err)); * * // load the sprite frame (${project}/assets/some/xxx/bundle2/imgs/cocos.png) from bundle2 folder - * bundle2.load('imgs/cocos', cc.SpriteFrame, null, (err, spriteFrame) => console.log(err)); + * bundle2.load('imgs/cocos', SpriteFrame, null, (err, spriteFrame) => console.log(err)); * */ public load ( @@ -263,20 +260,20 @@ export default class Bundle { * * @example * // preload the texture (${project}/assets/resources/textures/background.jpg) from resources - * cc.resources.preload('textures/background', cc.Texture2D); + * resources.preload('textures/background', Texture2D); * * // preload the audio (${project}/assets/resources/music/hit.mp3) from resources - * cc.resources.preload('music/hit', cc.AudioClip); + * resources.preload('music/hit', AudioClip); * // wait for while - * cc.resources.load('music/hit', cc.AudioClip, (err, audioClip) => {}); + * resources.load('music/hit', AudioClip, (err, audioClip) => {}); * * * // preload the prefab (${project}/assets/bundle1/misc/character/cocos) from bundle1 folder - * bundle1.preload('misc/character/cocos', cc.Prefab); + * bundle1.preload('misc/character/cocos', Prefab); * * // load the sprite frame of (${project}/assets/bundle2/imgs/cocos.png) from bundle2 folder - * bundle2.preload('imgs/cocos', cc.SpriteFrame); + * bundle2.preload('imgs/cocos', SpriteFrame); * // wait for while - * bundle2.load('imgs/cocos', cc.SpriteFrame, (err, spriteFrame) => {}); + * bundle2.load('imgs/cocos', SpriteFrame, (err, spriteFrame) => {}); * */ public preload (paths: string|string[], type: AssetType|null, onProgress: ProgressCallback|null, onComplete: CompleteCallbackWithData|null): void; @@ -315,19 +312,19 @@ export default class Bundle { * * @example * // load all audios (resources/audios/) - * cc.resources.loadDir('audios', cc.AudioClip, (err, audios) => {}); + * resources.loadDir('audios', AudioClip, (err, audios) => {}); * * // load all textures in "resources/imgs/" - * cc.resources.loadDir('imgs', cc.Texture2D, null, function (err, textures) { + * resources.loadDir('imgs', Texture2D, null, function (err, textures) { * var texture1 = textures[0]; * var texture2 = textures[1]; * }); * * // load all prefabs (${project}/assets/bundle1/misc/characters/) from bundle1 folder - * bundle1.loadDir('misc/characters', cc.Prefab, (err, prefabs) => console.log(err)); + * bundle1.loadDir('misc/characters', Prefab, (err, prefabs) => console.log(err)); * * // load all sprite frame (${project}/assets/some/xxx/bundle2/skills/) from bundle2 folder - * bundle2.loadDir('skills', cc.SpriteFrame, null, (err, spriteFrames) => console.log(err)); + * bundle2.loadDir('skills', SpriteFrame, null, (err, spriteFrames) => console.log(err)); * */ public loadDir (dir: string, type: AssetType | null, onProgress: ProgressCallback | null, onComplete: CompleteCallbackWithData | null): void; @@ -367,20 +364,20 @@ export default class Bundle { * * @example * // preload all audios (resources/audios/) - * cc.resources.preloadDir('audios', cc.AudioClip); + * resources.preloadDir('audios', AudioClip); * * // preload all textures in "resources/imgs/" - * cc.resources.preloadDir('imgs', cc.Texture2D); + * resources.preloadDir('imgs', Texture2D); * // wait for while - * cc.resources.loadDir('imgs', cc.Texture2D, (err, textures) => {}); + * resources.loadDir('imgs', Texture2D, (err, textures) => {}); * * // preload all prefabs (${project}/assets/bundle1/misc/characters/) from bundle1 folder - * bundle1.preloadDir('misc/characters', cc.Prefab); + * bundle1.preloadDir('misc/characters', Prefab); * * // preload all sprite frame (${project}/assets/some/xxx/bundle2/skills/) from bundle2 folder - * bundle2.preloadDir('skills', cc.SpriteFrame); + * bundle2.preloadDir('skills', SpriteFrame); * // wait for while - * bundle2.loadDir('skills', cc.SpriteFrame, (err, spriteFrames) => {}); + * bundle2.loadDir('skills', SpriteFrame, (err, spriteFrames) => {}); */ public preloadDir (dir: string, type: AssetType | null, onProgress: ProgressCallback | null, onComplete: CompleteCallbackWithData | null): void; public preloadDir (dir: string, onProgress: ProgressCallback | null, onComplete: CompleteCallbackWithData | null): void; @@ -414,7 +411,7 @@ export default class Bundle { * @param onComplete.sceneAsset - The scene asset * * @example - * bundle1.loadScene('first', (err, sceneAsset) => cc.director.runScene(sceneAsset)); + * bundle1.loadScene('first', (err, sceneAsset) => director.runScene(sceneAsset)); * */ public loadScene (sceneName: string, options: IAssetOptions | null, onProgress: ProgressCallback | null, onComplete: CompleteCallbackWithData | null): void; @@ -449,12 +446,12 @@ export default class Bundle { /** * @en * Preload the scene asset within this bundle by its name. After calling this method, you still need to finish loading - * by calling `Bundle.loadScene` or `cc.director.loadScene`.It will be totally fine to call `Bundle.loadDir` at any + * by calling `Bundle.loadScene` or `director.loadScene`.It will be totally fine to call `Bundle.loadDir` at any * time even if the preloading is not yet finished * * @zh - * 通过场景名称预加载分包中的场景资源.调用完后,你仍然需要通过 `Bundle.loadScene` 或 `cc.director.loadScene` 来完成加载。 - * 就算预加载还没完成,你也可以直接调用 `Bundle.loadScene` 或 `cc.director.loadScene`。 + * 通过场景名称预加载分包中的场景资源.调用完后,你仍然需要通过 `Bundle.loadScene` 或 `director.loadScene` 来完成加载。 + * 就算预加载还没完成,你也可以直接调用 `Bundle.loadScene` 或 `director.loadScene`。 * * @param sceneName - The name of the scene to preload. * @param options - Some optional parameters @@ -468,7 +465,7 @@ export default class Bundle { * @example * bundle1.preloadScene('first'); * // wait for a while - * bundle1.loadScene('first', (err, scene) => cc.director.runScene(scene)); + * bundle1.loadScene('first', (err, scene) => director.runScene(scene)); * */ public preloadScene (sceneName: string, options: IAssetOptions | null, onProgress: ProgressCallback, onComplete: CompleteCallbackNoData | null): void; @@ -512,7 +509,7 @@ export default class Bundle { * @returns - the asset has been cached * * @example - * bundle1.get('music/hit', cc.AudioClip); + * bundle1.get('music/hit', AudioClip); */ public get (path: string, type?: AssetType | null): T | null { const info = this.getInfoWithPath(path, type); diff --git a/cocos/core/asset-manager/cache-manager.ts b/cocos/core/asset-manager/cache-manager.ts index ab3ade133a..446eb42e10 100644 --- a/cocos/core/asset-manager/cache-manager.ts +++ b/cocos/core/asset-manager/cache-manager.ts @@ -23,19 +23,15 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module asset-manager - */ import Cache from './cache'; /** * @en * Cache manager is a module which controls all caches downloaded from server in non-web platform, it is a singleton - * All member can be accessed with `cc.assetManager.cacheManager`. + * All member can be accessed with `assetManager.cacheManager`. * * @zh - * 缓存管理器是一个模块,在非 WEB 平台上,用于管理所有从服务器上下载下来的缓存,这是一个单例,所有成员能通过 `cc.assetManager.cacheManager` 访问。 + * 缓存管理器是一个模块,在非 WEB 平台上,用于管理所有从服务器上下载下来的缓存,这是一个单例,所有成员能通过 `assetManager.cacheManager` 访问。 * */ export default abstract class CacheManager { diff --git a/cocos/core/asset-manager/cache.ts b/cocos/core/asset-manager/cache.ts index 774903f26c..9863f133eb 100644 --- a/cocos/core/asset-manager/cache.ts +++ b/cocos/core/asset-manager/cache.ts @@ -22,10 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/** - * @packageDocumentation - * @module asset-manager - */ + import { js } from '../utils/js'; export interface ICache { diff --git a/cocos/core/asset-manager/category.json b/cocos/core/asset-manager/category.json index 770668d7ac..3e5b97ef04 100644 --- a/cocos/core/asset-manager/category.json +++ b/cocos/core/asset-manager/category.json @@ -4,7 +4,7 @@ "en": "Asset" }, "description": { - "zh": "资源是游戏中的重要组成部分,Cocos Creator 支持导入大量类型的资源,并允许开发者将该资源运用在游戏中", - "en": "Assets are an important part of the game, and Cocos Creator supports importing a large number of types of resources and allows developers to use that resource in the game" + "zh": "资源是游戏中的重要组成部分,Cocos Creator 支持导入不同类型的资源,并允许开发者将该资源运用在游戏中", + "en": "Assets are crucial for game content, Cocos Creator supports importing various types of assets and allows developers to use these resources in the game logic in runtime" } } \ No newline at end of file diff --git a/cocos/core/asset-manager/depend-util.ts b/cocos/core/asset-manager/depend-util.ts index 95446a2fad..4ffe422c2b 100644 --- a/cocos/core/asset-manager/depend-util.ts +++ b/cocos/core/asset-manager/depend-util.ts @@ -22,10 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/** - * @packageDocumentation - * @module asset-manager - */ + import { BUILD, DEV, EDITOR } from 'internal:constants'; import { Asset } from '..'; import { hasNativeDep, isCompiledJson, parseUuidDependencies } from '../data/deserialize'; @@ -46,10 +43,10 @@ export interface IDependencies { /** * @en - * Control asset's dependency list, it is a singleton. All member can be accessed with `cc.assetManager.dependUtil` + * Control asset's dependency list, it is a singleton. All member can be accessed with `assetManager.dependUtil` * * @zh - * 控制资源的依赖列表,这是一个单例, 所有成员能通过 `cc.assetManager.dependUtil` 访问 + * 控制资源的依赖列表,这是一个单例, 所有成员能通过 `assetManager.dependUtil` 访问 * */ export class DependUtil { diff --git a/cocos/core/asset-manager/deprecated.ts b/cocos/core/asset-manager/deprecated.ts index d0bcb7ca2a..67ca877e0c 100644 --- a/cocos/core/asset-manager/deprecated.ts +++ b/cocos/core/asset-manager/deprecated.ts @@ -22,10 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/** - * @packageDocumentation - * @module loader - */ + import { BUILD, DEBUG } from 'internal:constants'; import { Asset } from '../assets'; import { director } from '../director'; @@ -138,15 +135,15 @@ export class CCLoader { * @example * ```TypeScript * loader.load('a.png', function (err, tex) { - * cc.log('Result should be a texture: ' + (tex instanceof cc.Texture2D)); + * log('Result should be a texture: ' + (tex instanceof Texture2D)); * }); * * loader.load('http://example.com/a.png', function (err, tex) { - * cc.log('Should load a texture from external url: ' + (tex instanceof cc.Texture2D)); + * log('Should load a texture from external url: ' + (tex instanceof Texture2D)); * }); * * loader.load({url: 'http://example.com/getImageREST?file=a.png', type: 'png'}, function (err, tex) { - * cc.log('Should load a texture from RESTful API by specify the type: ' + (tex instanceof cc.Texture2D)); + * log('Should load a texture from RESTful API by specify the type: ' + (tex instanceof Texture2D)); * }); * ``` * @@ -275,19 +272,19 @@ export class CCLoader { * // load the prefab (project/assets/resources/misc/character/cocos) from resources folder * loader.loadRes('misc/character/cocos', function (err, prefab) { * if (err) { - * cc.error(err.message || err); + * error(err.message || err); * return; * } - * cc.log('Result should be a prefab: ' + (prefab instanceof cc.Prefab)); + * log('Result should be a prefab: ' + (prefab instanceof Prefab)); * }); * * // load the sprite frame of (project/assets/resources/imgs/cocos.png) from resources folder - * loader.loadRes('imgs/cocos', cc.SpriteFrame, function (err, spriteFrame) { + * loader.loadRes('imgs/cocos', SpriteFrame, function (err, spriteFrame) { * if (err) { - * cc.error(err.message || err); + * error(err.message || err); * return; * } - * cc.log('Result should be a sprite frame: ' + (spriteFrame instanceof cc.SpriteFrame)); + * log('Result should be a sprite frame: ' + (spriteFrame instanceof SpriteFrame)); * }); * */ @@ -349,9 +346,9 @@ export class CCLoader { * // load the SpriteFrames from resources folder * let spriteFrames; * let urls = ['misc/characters/character_01', 'misc/weapons/weapons_01']; - * loader.loadResArray(urls, cc.SpriteFrame, function (err, assets) { + * loader.loadResArray(urls, SpriteFrame, function (err, assets) { * if (err) { - * cc.error(err); + * error(err); * return; * } * spriteFrames = assets; @@ -406,7 +403,7 @@ export class CCLoader { * // load the texture (resources/imgs/cocos.png) and the corresponding sprite frame * loader.loadResDir('imgs/cocos', function (err, assets) { * if (err) { - * cc.error(err); + * error(err); * return; * } * let texture = assets[0]; @@ -414,7 +411,7 @@ export class CCLoader { * }); * * // load all textures in "resources/imgs/" - * loader.loadResDir('imgs', cc.Texture2D, function (err, textures) { + * loader.loadResDir('imgs', Texture2D, function (err, textures) { * let texture1 = textures[0]; * let texture2 = textures[1]; * }); @@ -518,7 +515,7 @@ export class CCLoader { * let textures = []; * for (let i = 0; i < deps.length; ++i) { * let item = loader.getRes(deps[i]); - * if (item instanceof cc.Texture2D) { + * if (item instanceof Texture2D) { * textures.push(item); * } * } @@ -692,7 +689,7 @@ export class CCLoader { * @param res The asset url, it should be related path without extension to the `resources` folder. * @param type If type is provided, the asset for correspond type will be returned * - * @deprecated since v3.0 loader.releaseRes is deprecated, please use cc.assetManager.releaseRes instead + * @deprecated since v3.0 loader.releaseRes is deprecated, please use assetManager.releaseRes instead */ public releaseRes (res: string, type?: Constructor) { resources.release(res, type); @@ -713,11 +710,11 @@ export class CCLoader { /** * @en Removes an completed item in pipeline. * It will only remove the cache in the pipeline or loader, its dependencies won't be released. - * cc.loader provided another method to completely cleanup the resource and its dependencies, + * loader provided another method to completely cleanup the resource and its dependencies, * please refer to [[release]] * @zh 移除指定的已完成 item。 * 这将仅仅从 pipeline 或者 loader 中删除其缓存,并不会释放它所依赖的资源。 - * cc.loader 中提供了另一种删除资源及其依赖的清理方法,请参考 [[release]] + * loader 中提供了另一种删除资源及其依赖的清理方法,请参考 [[release]] * @param id The id of the item * @return succeed or not * @@ -817,7 +814,7 @@ export class CCLoader { * @method isAutoRelease * @param {Asset|String} asset - asset object or the raw asset's url * @returns {Boolean} - * @deprecated cc.loader.isAutoRelease is deprecated + * @deprecated loader.isAutoRelease is deprecated */ public isAutoRelease (asset: Asset|string): boolean { if (typeof asset === 'object') { asset = asset._uuid; } @@ -831,10 +828,10 @@ export class CCLoader { export const loader = new CCLoader(); /** - * /** + * @en + * Used to load/unload resources in the project + * @zh * 管理项目中加载/卸载资源的资源库。 - * @class AssetLibrary - * @static * * @deprecated since v3.0 AssetLibrary is deprecated, please backup your project and upgrade to assetManager */ @@ -882,7 +879,7 @@ export const AssetLibrary = { * @zh * 加载资源。 * @param {String} uuid - * @param {loadCallback} callback - 加载完成后执行的回调函数。 + * @param {loadCallback} callback - @en Callback function to be executed after loading asset. @zh 加载完成后执行的回调函数。 * @param {Object} options * @param {Boolean} options.readMainCache - 默认为true。如果为false,则资源及其所有依赖资源将重新加载并从库中创建新实例。 * @param {Boolean} options.writeMainCache - 默认为true。如果为true,则结果将缓存到 AssetLibrary,并且必须由用户手动卸载。 @@ -899,7 +896,7 @@ export const AssetLibrary = { * @class url * @static * - * @deprecated since v3.0 cc.url is deprecated + * @deprecated since v3.0 url is deprecated */ export const url = {}; @@ -931,7 +928,7 @@ replaceProperty(url, 'url', [ removeProperty(AssetLibrary, 'AssetLibrary', [ { name: 'getLibUrlNoExt', - suggest: 'AssetLibrary.getLibUrlNoExt was removed, if you want to transform url, please use cc.assetManager.utils.getUrlWithUuid instead', + suggest: 'AssetLibrary.getLibUrlNoExt was removed, if you want to transform url, please use assetManager.utils.getUrlWithUuid instead', }, { name: 'queryAssetInfo', @@ -950,7 +947,7 @@ removeProperty(loader, 'loader', [ }, { name: 'assetLoader', - suggest: 'cc.loader.assetLoader was removed, assetLoader and md5Pipe were merged into cc.assetManager.transformPipeline', + suggest: 'loader.assetLoader was removed, assetLoader and md5Pipe were merged into assetManager.transformPipeline', }, ]); @@ -982,7 +979,7 @@ replaceProperty(legacyCC, 'cc', [ removeProperty(legacyCC, 'cc', [{ name: 'LoadingItems', - suggest: getError(1400, 'cc.LoadingItems', 'cc.AssetManager.Task'), + suggest: getError(1400, 'LoadingItems', 'AssetManager.Task'), }]); replaceProperty(macro, 'macro', [ diff --git a/cocos/core/asset-manager/download-dom-image.ts b/cocos/core/asset-manager/download-dom-image.ts index 2041e2e2eb..81f69852c0 100644 --- a/cocos/core/asset-manager/download-dom-image.ts +++ b/cocos/core/asset-manager/download-dom-image.ts @@ -24,7 +24,6 @@ THE SOFTWARE. */ - import { getError } from '../platform/debug'; import { CompleteCallback, IDownloadParseOptions } from './shared'; diff --git a/cocos/core/asset-manager/downloader.ts b/cocos/core/asset-manager/downloader.ts index 6f5c3ff151..9e0e9ef4b5 100644 --- a/cocos/core/asset-manager/downloader.ts +++ b/cocos/core/asset-manager/downloader.ts @@ -22,10 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/** - * @packageDocumentation - * @module asset-manager - */ + import { BUILD, EDITOR } from 'internal:constants'; import { sys } from '../platform/sys'; import { js, path } from '../utils'; @@ -156,7 +153,7 @@ const downloadBundle = (nameOrUrl: string, options: IBundleOptions, onComplete: /** * @en * Control all download process, it is a singleton. - * All member can be accessed with `cc.assetManager.downloader`, it can download several types of files: + * All member can be accessed with `assetManager.downloader`, it can download several types of files: * 1. Text * 2. Image * 3. Audio @@ -164,7 +161,7 @@ const downloadBundle = (nameOrUrl: string, options: IBundleOptions, onComplete: * 5. Scripts * * @zh - * 管理所有下载过程,downloader 是个单例,所有成员能通过 `cc.assetManager.downloader` 访问,它能下载以下几种类型的文件: + * 管理所有下载过程,downloader 是个单例,所有成员能通过 `assetManager.downloader` 访问,它能下载以下几种类型的文件: * 1. 文本 * 2. 图片 * 3. 音频 diff --git a/cocos/core/asset-manager/factory.ts b/cocos/core/asset-manager/factory.ts index 2644c5b17b..1928f6cfd1 100644 --- a/cocos/core/asset-manager/factory.ts +++ b/cocos/core/asset-manager/factory.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { VideoClip } from '../../video/assets/video-clip'; import { ImageAsset, JsonAsset, TextAsset, Asset, diff --git a/cocos/core/asset-manager/fetch.ts b/cocos/core/asset-manager/fetch.ts index ec0cab2383..07538cb55f 100644 --- a/cocos/core/asset-manager/fetch.ts +++ b/cocos/core/asset-manager/fetch.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { Asset } from '../assets'; import { error } from '../platform/debug'; import packManager from './pack-manager'; diff --git a/cocos/core/asset-manager/helper.ts b/cocos/core/asset-manager/helper.ts index 4c1ff9babe..895481b765 100644 --- a/cocos/core/asset-manager/helper.ts +++ b/cocos/core/asset-manager/helper.ts @@ -32,11 +32,6 @@ const _uuidRegex = /.*[/\\][0-9a-fA-F]{2}[/\\]([0-9a-fA-F-@]{8,}).*/; export { default as decodeUuid } from '../utils/decode-uuid'; -/** - * @packageDocumentation - * @module asset-manager - */ - /** * @en * Extract uuid from url @@ -104,7 +99,7 @@ export function getUrlWithUuid (uuid: string, options?: { [k: string]: any, isNa * * @method isScene * @param {*} asset - asset - * @returns {boolean} - whether or not type is cc.SceneAsset + * @returns {boolean} - whether or not type is SceneAsset * */ export function isScene (asset) { diff --git a/cocos/core/asset-manager/index.ts b/cocos/core/asset-manager/index.ts index cbf185b7b4..53064a960a 100644 --- a/cocos/core/asset-manager/index.ts +++ b/cocos/core/asset-manager/index.ts @@ -24,8 +24,6 @@ THE SOFTWARE. */ - - export { default as assetManager, AssetManager } from './asset-manager'; export { resources } from './bundle'; export * from './deprecated'; diff --git a/cocos/core/asset-manager/load.ts b/cocos/core/asset-manager/load.ts index 5afedbaa17..47241d8d77 100644 --- a/cocos/core/asset-manager/load.ts +++ b/cocos/core/asset-manager/load.ts @@ -35,7 +35,6 @@ import { cache, checkCircleReference, clear, forEach, gatherAsset, getDepends, s import { legacyCC } from '../global-exports'; import { nativeDependMap, onLoadedInvokedMap } from './depend-maps'; - interface IProgress { finish: number; total: number; diff --git a/cocos/core/asset-manager/pack-manager.ts b/cocos/core/asset-manager/pack-manager.ts index 6bfc60b7a6..1c3c776a43 100644 --- a/cocos/core/asset-manager/pack-manager.ts +++ b/cocos/core/asset-manager/pack-manager.ts @@ -22,10 +22,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/** - * @packageDocumentation - * @module asset-manager - */ import { ImageAsset, Texture2D } from '../assets'; import { packCustomObjData, unpackJSONs } from '../data/deserialize'; @@ -46,10 +42,10 @@ interface IUnpackRequest { /** * @en - * Handle the packed asset, include unpacking, loading, cache and so on. It is a singleton. All member can be accessed with `cc.assetManager.packManager` + * Handle the packed asset, include unpacking, loading, cache and so on. It is a singleton. All member can be accessed with `assetManager.packManager` * * @zh - * 处理打包资源,包括拆包,加载,缓存等等,这是一个单例, 所有成员能通过 `cc.assetManager.packManager` 访问 + * 处理打包资源,包括拆包,加载,缓存等等,这是一个单例, 所有成员能通过 `assetManager.packManager` 访问 * */ export class PackManager { @@ -199,7 +195,7 @@ export class PackManager { * @param onComplete.data - The unpacked data retrieved from package * * @example - * var requestItem = cc.AssetManager.RequestItem.create(); + * var requestItem = AssetManager.RequestItem.create(); * requestItem.uuid = 'fcmR3XADNLgJ1ByKhqcC5Z'; * requestItem.info = config.getAssetInfo('fcmR3XADNLgJ1ByKhqcC5Z'); * packManager.load(requestItem, null, (err, data) => console.log(err)); diff --git a/cocos/core/asset-manager/parser.ts b/cocos/core/asset-manager/parser.ts index 76b2de9a31..f9eb2d42a0 100644 --- a/cocos/core/asset-manager/parser.ts +++ b/cocos/core/asset-manager/parser.ts @@ -22,10 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/** - * @packageDocumentation - * @module asset-manager - */ + import { Asset } from '..'; import { IMemoryImageSource } from '../assets/image-asset'; import { js } from '../utils'; @@ -132,10 +129,10 @@ export type ParseHandler = (file: any, options: IDownloadParseOptions, onComplet /** * @en - * Parse the downloaded file, it's a singleton, all member can be accessed with `cc.assetManager.parser` + * Parse the downloaded file, it's a singleton, all member can be accessed with `assetManager.parser` * * @zh - * 解析已下载的文件,parser 是一个单例, 所有成员能通过 `cc.assetManaager.parser` 访问 + * 解析已下载的文件,parser 是一个单例, 所有成员能通过 `assetManaager.parser` 访问 * */ export class Parser { diff --git a/cocos/core/asset-manager/pipeline.ts b/cocos/core/asset-manager/pipeline.ts index 68a1540a09..246ca4bf46 100644 --- a/cocos/core/asset-manager/pipeline.ts +++ b/cocos/core/asset-manager/pipeline.ts @@ -22,10 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/** - * @packageDocumentation - * @module asset-manager - */ + import { warnID } from '../platform/debug'; import { CompleteCallbackNoData } from './shared'; import Task from './task'; @@ -87,17 +84,17 @@ export class Pipeline { * the first is a `Task` flowed in pipeline, the second is complete callback * * @example - * var pipeline = new Pipeline('download', [ + * const pipeline = new Pipeline('download', [ * (task, done) => { - * var url = task.input; - * cc.assetManager.downloader.downloadFile(url, null, null, (err, result) => { + * const url = task.input; + * assetManager.downloader.downloadFile(url, null, null, (err, result) => { * task.output = result; * done(err); * }); * }, * (task, done) => { - * var text = task.input; - * var json = JSON.stringify(text); + * const text = task.input; + * const json = JSON.stringify(text); * task.output = json; * done(); * } diff --git a/cocos/core/asset-manager/plist-parser.ts b/cocos/core/asset-manager/plist-parser.ts index 40de3c6bf4..ef509d836a 100644 --- a/cocos/core/asset-manager/plist-parser.ts +++ b/cocos/core/asset-manager/plist-parser.ts @@ -25,8 +25,6 @@ THE SOFTWARE. */ - - import { EDITOR } from 'internal:constants'; import { warnID } from '../platform/debug'; diff --git a/cocos/core/asset-manager/preprocess.ts b/cocos/core/asset-manager/preprocess.ts index 6892a8c5cc..00d6434ad5 100644 --- a/cocos/core/asset-manager/preprocess.ts +++ b/cocos/core/asset-manager/preprocess.ts @@ -23,7 +23,6 @@ THE SOFTWARE. */ - import { CompleteCallbackNoData, RequestType, transformPipeline } from './shared'; import Task from './task'; diff --git a/cocos/core/asset-manager/request-item.ts b/cocos/core/asset-manager/request-item.ts index cde88b645b..b6f4577531 100644 --- a/cocos/core/asset-manager/request-item.ts +++ b/cocos/core/asset-manager/request-item.ts @@ -22,10 +22,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/** - * @packageDocumentation - * @module asset-manager - */ import Config, { IAssetInfo } from './config'; diff --git a/cocos/core/asset-manager/task.ts b/cocos/core/asset-manager/task.ts index 13c89a3106..22207ab1a6 100644 --- a/cocos/core/asset-manager/task.ts +++ b/cocos/core/asset-manager/task.ts @@ -22,10 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/** - * @packageDocumentation - * @module asset-manager - */ + export type TaskCompleteCallback = (err: Error | null | undefined, data: any) => void; export type TaskProgressCallback = (...args: any[]) => void; export type TaskErrorCallback = (...args: any[]) => void; diff --git a/cocos/core/assets/asset-enum.ts b/cocos/core/assets/asset-enum.ts index 2aa9d4f4a3..40a5e06952 100644 --- a/cocos/core/assets/asset-enum.ts +++ b/cocos/core/assets/asset-enum.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module asset - */ - import { Address, Filter as GFXFilter, Format } from '../gfx'; // define a specified number for the pixel format which gfx do not have a standard definition. diff --git a/cocos/core/assets/asset.ts b/cocos/core/assets/asset.ts index cfb08b5527..d359539adc 100644 --- a/cocos/core/assets/asset.ts +++ b/cocos/core/assets/asset.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module asset - */ - import { ccclass, serializable } from 'cc.decorator'; import { EDITOR, PREVIEW } from 'internal:constants'; import { property } from '../data/decorators/property'; @@ -65,6 +60,7 @@ import { debug, getError, warn } from '../platform/debug'; export class Asset extends Eventify(GCObject) { /** * 应 AssetDB 要求提供这个方法。 + * @internal * @method deserialize * @param {String} data * @return {Asset} @@ -89,6 +85,9 @@ export class Asset extends Eventify(GCObject) { */ public declare _uuid: string; + /** + * @internal + */ public declare isDefault: boolean; /** @@ -103,7 +102,7 @@ export class Asset extends Eventify(GCObject) { @serializable public _native = ''; /** - * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. + * @internal */ public _nativeUrl = ''; diff --git a/cocos/core/assets/buffer-asset.ts b/cocos/core/assets/buffer-asset.ts index b34589c4fb..fab1efeb27 100644 --- a/cocos/core/assets/buffer-asset.ts +++ b/cocos/core/assets/buffer-asset.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module asset - */ - import { ccclass, override } from 'cc.decorator'; import { legacyCC } from '../global-exports'; import { Asset } from './asset'; diff --git a/cocos/core/assets/deprecation.ts b/cocos/core/assets/deprecation.ts index da2bdc424a..5fc40f3a63 100644 --- a/cocos/core/assets/deprecation.ts +++ b/cocos/core/assets/deprecation.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { removeProperty, replaceProperty } from '../utils'; import { TextureBase } from './texture-base'; import { RenderTexture } from './render-texture'; diff --git a/cocos/core/assets/effect-asset.ts b/cocos/core/assets/effect-asset.ts index b5a676769e..ae825aced0 100644 --- a/cocos/core/assets/effect-asset.ts +++ b/cocos/core/assets/effect-asset.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module material - */ - import { ccclass, serializable, editable, editorOnly } from 'cc.decorator'; import { EDITOR } from 'internal:constants'; import { Root } from '../root'; @@ -252,8 +247,8 @@ export class EffectAsset extends Asset { public hideInEditor = false; /** - * @en The loaded callback which should be invoked by the [[Loader]], will automatically register the effect. - * @zh 通过 [[Loader]] 加载完成时的回调,将自动注册 effect 资源。 + * @en The loaded callback which should be invoked by the [[CCLoader]], will automatically register the effect. + * @zh 通过 [[CCLoader]] 加载完成时的回调,将自动注册 effect 资源。 */ public onLoaded () { programLib.register(this); diff --git a/cocos/core/assets/image-asset.ts b/cocos/core/assets/image-asset.ts index e5cefe8a15..85746d3091 100644 --- a/cocos/core/assets/image-asset.ts +++ b/cocos/core/assets/image-asset.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module asset - */ - // @ts-check import { ccclass, override } from 'cc.decorator'; import { EDITOR, MINIGAME, ALIPAY, XIAOMI, JSB, TEST, BAIDU } from 'internal:constants'; diff --git a/cocos/core/assets/index.ts b/cocos/core/assets/index.ts index 00f110f317..8ce78e1716 100644 --- a/cocos/core/assets/index.ts +++ b/cocos/core/assets/index.ts @@ -24,7 +24,6 @@ THE SOFTWARE. */ - import './deprecation'; export { Asset } from './asset'; @@ -39,5 +38,6 @@ export { ImageAsset } from './image-asset'; export { Texture2D } from './texture-2d'; export { TextureCube } from './texture-cube'; export { EffectAsset } from './effect-asset'; +export type { IMaterialInfo } from './material'; export { Material } from './material'; export { RenderTexture } from './render-texture'; diff --git a/cocos/core/assets/json-asset.ts b/cocos/core/assets/json-asset.ts index faab702c67..58615ddae7 100644 --- a/cocos/core/assets/json-asset.ts +++ b/cocos/core/assets/json-asset.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module asset - */ - import { ccclass, serializable, editable } from 'cc.decorator'; import { Asset } from './asset'; import { legacyCC } from '../global-exports'; diff --git a/cocos/core/assets/material.ts b/cocos/core/assets/material.ts index 426a5e7496..e9363c67f5 100644 --- a/cocos/core/assets/material.ts +++ b/cocos/core/assets/material.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module material - */ - import { ccclass, serializable, type } from 'cc.decorator'; import { Asset } from './asset'; import { EffectAsset } from './effect-asset'; @@ -48,7 +43,7 @@ const v4_1 = new Vec4(); * @en The basic infos for material initialization. * @zh 用来初始化材质的基本信息。 */ -interface IMaterialInfo { +export interface IMaterialInfo { /** * @en The EffectAsset to use. Must provide if `effectName` is not specified. * @zh @@ -246,8 +241,8 @@ export class Material extends Asset { } /** - * @en Callback function after material is loaded in [[Loader]]. Initialize the resources automatically. - * @zh 通过 [[Loader]] 加载完成时的回调,将自动初始化材质资源。 + * @en Callback function after material is loaded in [[CCLoader]]. Initialize the resources automatically. + * @zh 通过 [[CCLoader]] 加载完成时的回调,将自动初始化材质资源。 */ public onLoaded () { this._update(); @@ -271,10 +266,10 @@ export class Material extends Asset { /** * @en * Convenient property setter provided for quick material setup.
- * [[Pass.setUniform]] should be used instead if you need to do per-frame uniform update. + * [[renderer.Pass.setUniform]] should be used instead if you need to do per-frame uniform update. * @zh * 设置材质 uniform 参数的统一入口。
- * 注意如果需要每帧更新 uniform,建议使用 [[Pass.setUniform]] 以获得更好的性能。 + * 注意如果需要每帧更新 uniform,建议使用 [[renderer.Pass.setUniform]] 以获得更好的性能。 * @param name The target uniform name. * @param val The target value. * @param passIdx The pass to apply to. Will apply to all passes if not specified. @@ -308,11 +303,11 @@ export class Material extends Asset { * @en * Get the specified uniform value for this material.
* Note that only uniforms set through [[Material.setProperty]] can be acquired here.
- * For the complete rendering data, use [[Pass.getUniform]] instead. + * For the complete rendering data, use [[renderer.Pass.getUniform]] instead. * @zh * 获取当前材质的指定 uniform 参数的值。
* 注意只有通过 [[Material.setProperty]] 函数设置的参数才能从此函数取出,
- * 如需取出完整的渲染数据,请使用 [[Pass.getUniform]]。 + * 如需取出完整的渲染数据,请使用 [[renderer.Pass.getUniform]]。 * @param name The property or uniform name. * @param passIdx The target pass index. If not specified, return the first found value in all passes. */ @@ -486,6 +481,7 @@ export class Material extends Asset { this.initialize({ effectName: 'unlit', defines: { USE_COLOR: true }, + technique: 0, }); this.setProperty('mainColor', new Color('#ff00ff')); } diff --git a/cocos/core/assets/prefab.ts b/cocos/core/assets/prefab.ts index ca611c76b0..e837948b92 100644 --- a/cocos/core/assets/prefab.ts +++ b/cocos/core/assets/prefab.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module asset - */ - import { ccclass, serializable, editable } from 'cc.decorator'; import { SUPPORT_JIT, ALIPAY, RUNTIME_BASED } from 'internal:constants'; import { compile } from '../data/instantiate-jit'; diff --git a/cocos/core/assets/render-texture.ts b/cocos/core/assets/render-texture.ts index 4c8c1482b8..f4e0d896fb 100644 --- a/cocos/core/assets/render-texture.ts +++ b/cocos/core/assets/render-texture.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module asset - */ - import { ccclass } from 'cc.decorator'; import { EDITOR, TEST } from 'internal:constants'; import { clamp } from '../math/utils'; @@ -134,7 +129,7 @@ export class RenderTexture extends TextureBase { // To be compatible with material property interface /** - * @en Gets the related [[Texture]] resource, it's also the color attachment for the render window + * @en Gets the related [[gfx.Texture]] resource, it's also the color attachment for the render window * @zh 获取渲染贴图的 GFX 资源,同时也是渲染窗口所指向的颜色缓冲贴图资源 */ public getGFXTexture (): Texture | null { @@ -177,17 +172,12 @@ export class RenderTexture extends TextureBase { } /** - * @en Read pixel buffer from render texture - * @param x The location on x axis - * @param y The location on y axis - * @param width The pixel width - * @param height The pixel height - * @zh 从 render texture 读取像素数据 - * @param x 起始位置X轴坐标 - * @param y 起始位置Y轴坐标 - * @param width 像素宽度 - * @param height 像素高度 - * @param buffer 像素缓存 + * @en Read pixel buffer from render texture @zh 从 render texture 读取像素数据 + * @param x @en The location on x axis @zh 起始位置X轴坐标 + * @param y @en The location on y axis @zh 起始位置Y轴坐标 + * @param width @en The pixel width @zh 像素宽度 + * @param height @en The pixel height @zh 像素高度 + * @param buffer @en The buffer to hold pixel data @zh 像素缓存 */ public readPixels (x = 0, y = 0, width?: number, height?: number, buffer?: Uint8Array) : Uint8Array | null { width = width || this.width; diff --git a/cocos/core/assets/rendering-sub-mesh.ts b/cocos/core/assets/rendering-sub-mesh.ts index 58ceb4f4a3..538522fab5 100644 --- a/cocos/core/assets/rendering-sub-mesh.ts +++ b/cocos/core/assets/rendering-sub-mesh.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module asset - */ - import { legacyCC } from '../global-exports'; import { mapBuffer } from '../../3d/misc/buffer'; import { @@ -84,10 +79,8 @@ export interface IFlatBuffer { } /** - * @en A representation of a sub mesh - * Sub mesh for rendering which contains all geometry data, it can be used to create [[InputAssembler]]. - * @zh 代表一个子网格资源 - * 包含所有顶点数据的渲染子网格,可以用来创建 [[InputAssembler]]。 + * @en Sub mesh for rendering which contains all geometry data, it can be used to create [[gfx.InputAssembler]]. + * @zh 包含所有顶点数据的渲染子网格,可以用来创建 [[gfx.InputAssembler]]。 */ export class RenderingSubMesh { /** diff --git a/cocos/core/assets/scene-asset.ts b/cocos/core/assets/scene-asset.ts index be36a69cea..3970ea52ac 100644 --- a/cocos/core/assets/scene-asset.ts +++ b/cocos/core/assets/scene-asset.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module asset - */ - import { ccclass, editable, serializable } from 'cc.decorator'; import { Scene } from '../scene-graph'; import { Asset } from './asset'; diff --git a/cocos/core/assets/scripts.ts b/cocos/core/assets/scripts.ts index 3eb8fc5064..efda5018fe 100644 --- a/cocos/core/assets/scripts.ts +++ b/cocos/core/assets/scripts.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module asset - */ - import { ccclass } from 'cc.decorator'; import { Asset } from './asset'; import { legacyCC } from '../global-exports'; diff --git a/cocos/core/assets/simple-texture.ts b/cocos/core/assets/simple-texture.ts index 62ebbfc640..11ea6e27c0 100644 --- a/cocos/core/assets/simple-texture.ts +++ b/cocos/core/assets/simple-texture.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module asset - */ - import { ccclass } from 'cc.decorator'; import { DEV } from 'internal:constants'; import { TextureFlagBit, TextureUsageBit, API, Texture, TextureInfo, TextureViewInfo, Device, BufferTextureCopy } from '../gfx'; @@ -196,8 +191,11 @@ export class SimpleTexture extends TextureBase { } /** + * @en * Set mipmap level of this texture. * The value is passes as presumed info to `this._getGfxTextureCreateInfo()`. + * @zh + * 设置此贴图的 mipmap 层级 * @param value The mipmap level. */ protected _setMipmapLevel (value: number) { diff --git a/cocos/core/assets/text-asset.ts b/cocos/core/assets/text-asset.ts index 3e33cc2673..9714fd1a96 100644 --- a/cocos/core/assets/text-asset.ts +++ b/cocos/core/assets/text-asset.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module asset - */ - import { ccclass, serializable, editable } from 'cc.decorator'; import { Asset } from './asset'; import { legacyCC } from '../global-exports'; diff --git a/cocos/core/assets/texture-2d.ts b/cocos/core/assets/texture-2d.ts index 9990bc787e..4587ce879d 100644 --- a/cocos/core/assets/texture-2d.ts +++ b/cocos/core/assets/texture-2d.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module asset - */ - import { EDITOR, TEST } from 'internal:constants'; import { ccclass, type } from 'cc.decorator'; import { TextureType, TextureInfo, TextureViewInfo } from '../gfx'; @@ -223,7 +218,7 @@ export class Texture2D extends SimpleTexture { * @en If the level 0 mipmap image is a HTML element, then return it, otherwise return null. * @zh 若此贴图 0 级 Mipmap 的图像资源的实际源存在并为 HTML 元素则返回它,否则返回 `null`。 * @returns HTML element or `null` - * @deprecated Please use [[image.data]] instead + * @deprecated Please use [[ImageAsset.data]] instead */ public getHtmlElementObj () { return (this._mipmaps[0] && (this._mipmaps[0].data instanceof HTMLElement)) ? this._mipmaps[0].data : null; diff --git a/cocos/core/assets/texture-base.ts b/cocos/core/assets/texture-base.ts index 8b5cf85bf4..da535d3cc2 100644 --- a/cocos/core/assets/texture-base.ts +++ b/cocos/core/assets/texture-base.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module asset - */ - // @ts-check import { EDITOR, TEST } from 'internal:constants'; import { ccclass, serializable } from 'cc.decorator'; diff --git a/cocos/core/assets/texture-cube.ts b/cocos/core/assets/texture-cube.ts index f811a3535c..47958c68d8 100644 --- a/cocos/core/assets/texture-cube.ts +++ b/cocos/core/assets/texture-cube.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module asset - */ - import { EDITOR, TEST } from 'internal:constants'; import { ccclass, serializable } from 'cc.decorator'; import { TextureType, TextureInfo, TextureViewInfo } from '../gfx'; @@ -220,7 +215,8 @@ export class TextureCube extends SimpleTexture { } /** - * 销毁此贴图,清空所有 Mipmap 并释放占用的 GPU 资源。 + * @en Destroy this texture, clear all mipmaps and release GPU resources + * @zh 销毁此贴图,清空所有 Mipmap 并释放占用的 GPU 资源。 */ public destroy () { this._mipmaps = []; diff --git a/cocos/core/builtin/effects.ts b/cocos/core/builtin/effects.ts index d45850b18b..fcaeb42592 100644 --- a/cocos/core/builtin/effects.ts +++ b/cocos/core/builtin/effects.ts @@ -603,18 +603,18 @@ export const effects = [ "shaders": [ { "name": "standard|standard-vs|standard-fs", - "hash": 4029250200, + "hash": 240716757, "builtins": { "statistics": { "CC_EFFECT_USED_VERTEX_UNIFORM_VECTORS": 224, "CC_EFFECT_USED_FRAGMENT_UNIFORM_VECTORS": 76 }, "globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }, { "name": "CCCamera", "defines": [] }, { "name": "CCShadow", "defines": [] }], "samplerTextures": [{ "name": "cc_shadowMap", "defines": ["CC_RECEIVE_SHADOW"] }, { "name": "cc_spotLightingMap", "defines": ["CC_RECEIVE_SHADOW"] }, { "name": "cc_environment", "defines": ["CC_USE_IBL"] }, { "name": "cc_diffuseMap", "defines": ["CC_USE_DIFFUSEMAP"] }], "buffers": [], "images": [] }, - "locals": { "blocks": [{ "name": "CCMorph", "defines": ["CC_USE_MORPH"] }, { "name": "CCSkinningTexture", "defines": ["CC_USE_SKINNING", "CC_USE_BAKED_ANIMATION"] }, { "name": "CCSkinningAnimation", "defines": ["CC_USE_SKINNING", "CC_USE_BAKED_ANIMATION"] }, { "name": "CCSkinning", "defines": ["CC_USE_SKINNING", "!CC_USE_BAKED_ANIMATION"] }, { "name": "CCLocalBatched", "defines": ["!USE_INSTANCING", "USE_BATCHING"] }, { "name": "CCLocal", "defines": ["!USE_INSTANCING", "!USE_BATCHING"] }, { "name": "CCForwardLight", "defines": ["CC_FORWARD_ADD", "CC_ENABLE_CLUSTERED_LIGHT_CULLING"] }], "samplerTextures": [{ "name": "cc_PositionDisplacements", "defines": ["CC_USE_MORPH", "CC_MORPH_TARGET_HAS_POSITION"] }, { "name": "cc_NormalDisplacements", "defines": ["CC_USE_MORPH", "CC_MORPH_TARGET_HAS_NORMAL"] }, { "name": "cc_TangentDisplacements", "defines": ["CC_USE_MORPH", "CC_MORPH_TARGET_HAS_TANGENT"] }, { "name": "cc_jointTexture", "defines": ["CC_USE_SKINNING", "CC_USE_BAKED_ANIMATION"] }, { "name": "cc_lightingMap", "defines": ["USE_LIGHTMAP", "!USE_BATCHING", "!CC_FORWARD_ADD"] }], "buffers": [], "images": [] } + "locals": { "blocks": [{ "name": "CCMorph", "defines": ["CC_USE_MORPH"] }, { "name": "CCSkinningTexture", "defines": ["CC_USE_SKINNING", "CC_USE_BAKED_ANIMATION"] }, { "name": "CCSkinningAnimation", "defines": ["CC_USE_SKINNING", "CC_USE_BAKED_ANIMATION"] }, { "name": "CCSkinning", "defines": ["CC_USE_SKINNING", "!CC_USE_BAKED_ANIMATION"] }, { "name": "CCLocalBatched", "defines": ["!USE_INSTANCING", "USE_BATCHING"] }, { "name": "CCLocal", "defines": ["!USE_INSTANCING", "!USE_BATCHING"] }, { "name": "CCForwardLight", "defines": ["CC_FORWARD_ADD", "CC_ENABLE_CLUSTERED_LIGHT_CULLING"] }], "samplerTextures": [{ "name": "cc_PositionDisplacements", "defines": ["CC_USE_MORPH", "CC_MORPH_TARGET_HAS_POSITION"] }, { "name": "cc_NormalDisplacements", "defines": ["CC_USE_MORPH", "CC_MORPH_TARGET_HAS_NORMAL"] }, { "name": "cc_TangentDisplacements", "defines": ["CC_USE_MORPH", "CC_MORPH_TARGET_HAS_TANGENT"] }, { "name": "cc_jointTexture", "defines": ["CC_USE_SKINNING", "CC_USE_BAKED_ANIMATION"] }, { "name": "cc_lightingMap", "defines": ["CC_USE_LIGHTMAP", "!USE_BATCHING", "!CC_FORWARD_ADD"] }], "buffers": [], "images": [] } }, "defines": [ { "name": "USE_INSTANCING", "type": "boolean" }, { "name": "USE_BATCHING", "type": "boolean" }, { "name": "CC_USE_SKINNING", "type": "boolean" }, { "name": "CC_USE_BAKED_ANIMATION", "type": "boolean" }, - { "name": "USE_LIGHTMAP", "type": "boolean" }, + { "name": "CC_USE_LIGHTMAP", "type": "boolean" }, { "name": "CC_RECEIVE_SHADOW", "type": "boolean" }, { "name": "CC_USE_MORPH", "type": "boolean" }, { "name": "CC_MORPH_TARGET_COUNT", "type": "number", "range": [2, 8] }, @@ -659,7 +659,7 @@ export const effects = [ { "name": "a_matWorld0", "defines": ["USE_INSTANCING"], "format": 44, "isInstanced": true, "location": 7 }, { "name": "a_matWorld1", "defines": ["USE_INSTANCING"], "format": 44, "isInstanced": true, "location": 8 }, { "name": "a_matWorld2", "defines": ["USE_INSTANCING"], "format": 44, "isInstanced": true, "location": 9 }, - { "name": "a_lightingMapUVParam", "defines": ["USE_INSTANCING", "USE_LIGHTMAP"], "format": 44, "isInstanced": true, "location": 10 }, + { "name": "a_lightingMapUVParam", "defines": ["USE_INSTANCING", "CC_USE_LIGHTMAP"], "format": 44, "isInstanced": true, "location": 10 }, { "name": "a_localShadowBias", "defines": ["USE_INSTANCING", "CC_RECEIVE_SHADOW"], "format": 21, "isInstanced": true, "location": 11 }, { "name": "a_dyn_batch_id", "defines": ["!USE_INSTANCING", "USE_BATCHING"], "format": 11, "location": 12 }, { "name": "a_vertexId", "defines": ["CC_USE_MORPH"], "format": 11, "location": 13 }, @@ -696,7 +696,7 @@ export const effects = [ }, { "name": "standard|shadow-caster-vs:vert|shadow-caster-fs:frag", - "hash": 1251227823, + "hash": 593350669, "builtins": { "statistics": { "CC_EFFECT_USED_VERTEX_UNIFORM_VECTORS": 184, "CC_EFFECT_USED_FRAGMENT_UNIFORM_VECTORS": 76 }, "globals": { "blocks": [{ "name": "CCShadow", "defines": [] }, { "name": "CCGlobal", "defines": [] }, { "name": "CCCamera", "defines": [] }], "samplerTextures": [{ "name": "cc_shadowMap", "defines": ["CC_RECEIVE_SHADOW"] }, { "name": "cc_spotLightingMap", "defines": ["CC_RECEIVE_SHADOW"] }], "buffers": [], "images": [] }, @@ -707,7 +707,7 @@ export const effects = [ { "name": "USE_BATCHING", "type": "boolean" }, { "name": "CC_USE_SKINNING", "type": "boolean" }, { "name": "CC_USE_BAKED_ANIMATION", "type": "boolean" }, - { "name": "USE_LIGHTMAP", "type": "boolean" }, + { "name": "CC_USE_LIGHTMAP", "type": "boolean" }, { "name": "CC_RECEIVE_SHADOW", "type": "boolean" }, { "name": "CC_USE_MORPH", "type": "boolean" }, { "name": "CC_MORPH_TARGET_COUNT", "type": "number", "range": [2, 8] }, @@ -732,7 +732,7 @@ export const effects = [ { "name": "a_matWorld0", "defines": ["USE_INSTANCING"], "format": 44, "isInstanced": true, "location": 7 }, { "name": "a_matWorld1", "defines": ["USE_INSTANCING"], "format": 44, "isInstanced": true, "location": 8 }, { "name": "a_matWorld2", "defines": ["USE_INSTANCING"], "format": 44, "isInstanced": true, "location": 9 }, - { "name": "a_lightingMapUVParam", "defines": ["USE_INSTANCING", "USE_LIGHTMAP"], "format": 44, "isInstanced": true, "location": 10 }, + { "name": "a_lightingMapUVParam", "defines": ["USE_INSTANCING", "CC_USE_LIGHTMAP"], "format": 44, "isInstanced": true, "location": 10 }, { "name": "a_localShadowBias", "defines": ["USE_INSTANCING", "CC_RECEIVE_SHADOW"], "format": 21, "isInstanced": true, "location": 11 }, { "name": "a_dyn_batch_id", "defines": ["!USE_INSTANCING", "USE_BATCHING"], "format": 11, "location": 12 }, { "name": "a_vertexId", "defines": ["CC_USE_MORPH"], "format": 11, "location": 13 }, @@ -767,17 +767,17 @@ export const effects = [ "shaders": [ { "name": "terrain|terrain-vs|terrain-fs", - "hash": 2313801411, + "hash": 3585788190, "builtins": { "statistics": { "CC_EFFECT_USED_VERTEX_UNIFORM_VECTORS": 72, "CC_EFFECT_USED_FRAGMENT_UNIFORM_VECTORS": 72 }, "globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }, { "name": "CCCamera", "defines": [] }, { "name": "CCShadow", "defines": [] }], "samplerTextures": [{ "name": "cc_shadowMap", "defines": ["CC_RECEIVE_SHADOW"] }, { "name": "cc_spotLightingMap", "defines": ["CC_RECEIVE_SHADOW"] }, { "name": "cc_environment", "defines": ["CC_USE_IBL"] }, { "name": "cc_diffuseMap", "defines": ["CC_USE_DIFFUSEMAP"] }], "buffers": [], "images": [] }, - "locals": { "blocks": [{ "name": "CCLocal", "defines": [] }, { "name": "CCForwardLight", "defines": ["CC_FORWARD_ADD", "CC_ENABLE_CLUSTERED_LIGHT_CULLING"] }], "samplerTextures": [{ "name": "cc_lightingMap", "defines": ["USE_LIGHTMAP", "!USE_BATCHING", "!CC_FORWARD_ADD"] }], "buffers": [], "images": [] } + "locals": { "blocks": [{ "name": "CCLocal", "defines": [] }, { "name": "CCForwardLight", "defines": ["CC_FORWARD_ADD", "CC_ENABLE_CLUSTERED_LIGHT_CULLING"] }], "samplerTextures": [{ "name": "cc_lightingMap", "defines": ["CC_USE_LIGHTMAP", "!USE_BATCHING", "!CC_FORWARD_ADD"] }], "buffers": [], "images": [] } }, "defines": [ { "name": "CC_USE_FOG", "type": "number", "range": [0, 4] }, { "name": "CC_USE_ACCURATE_FOG", "type": "boolean" }, { "name": "CC_RECEIVE_SHADOW", "type": "boolean" }, - { "name": "USE_LIGHTMAP", "type": "boolean" }, + { "name": "CC_USE_LIGHTMAP", "type": "boolean" }, { "name": "CC_USE_IBL", "type": "number", "range": [0, 2] }, { "name": "CC_USE_DIFFUSEMAP", "type": "number", "range": [0, 2] }, { "name": "USE_REFLECTION_DENOISE", "type": "boolean" }, @@ -859,7 +859,7 @@ export const effects = [ "shaders": [ { "name": "unlit|unlit-vs:vert|unlit-fs:frag", - "hash": 3312991757, + "hash": 4199175795, "builtins": { "statistics": { "CC_EFFECT_USED_VERTEX_UNIFORM_VECTORS": 199, "CC_EFFECT_USED_FRAGMENT_UNIFORM_VECTORS": 42 }, "globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }, { "name": "CCCamera", "defines": [] }], "samplerTextures": [], "buffers": [], "images": [] }, @@ -870,7 +870,7 @@ export const effects = [ { "name": "USE_BATCHING", "type": "boolean" }, { "name": "CC_USE_SKINNING", "type": "boolean" }, { "name": "CC_USE_BAKED_ANIMATION", "type": "boolean" }, - { "name": "USE_LIGHTMAP", "type": "boolean" }, + { "name": "CC_USE_LIGHTMAP", "type": "boolean" }, { "name": "CC_RECEIVE_SHADOW", "type": "boolean" }, { "name": "CC_USE_MORPH", "type": "boolean" }, { "name": "CC_MORPH_TARGET_COUNT", "type": "number", "range": [2, 8] }, @@ -898,7 +898,7 @@ export const effects = [ { "name": "a_matWorld0", "defines": ["USE_INSTANCING"], "format": 44, "isInstanced": true, "location": 7 }, { "name": "a_matWorld1", "defines": ["USE_INSTANCING"], "format": 44, "isInstanced": true, "location": 8 }, { "name": "a_matWorld2", "defines": ["USE_INSTANCING"], "format": 44, "isInstanced": true, "location": 9 }, - { "name": "a_lightingMapUVParam", "defines": ["USE_INSTANCING", "USE_LIGHTMAP"], "format": 44, "isInstanced": true, "location": 10 }, + { "name": "a_lightingMapUVParam", "defines": ["USE_INSTANCING", "CC_USE_LIGHTMAP"], "format": 44, "isInstanced": true, "location": 10 }, { "name": "a_localShadowBias", "defines": ["USE_INSTANCING", "CC_RECEIVE_SHADOW"], "format": 21, "isInstanced": true, "location": 11 }, { "name": "a_dyn_batch_id", "defines": ["!USE_INSTANCING", "USE_BATCHING"], "format": 11, "location": 12 }, { "name": "a_vertexId", "defines": ["CC_USE_MORPH"], "format": 11, "location": 13 }, @@ -932,7 +932,7 @@ export const effects = [ "shaders": [ { "name": "bloom|bloom-vs|prefilter-fs", - "hash": 2386243266, + "hash": 696288644, "builtins": { "statistics": { "CC_EFFECT_USED_VERTEX_UNIFORM_VECTORS": 148, "CC_EFFECT_USED_FRAGMENT_UNIFORM_VECTORS": 41 }, "globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }, { "name": "CCCamera", "defines": [] }], "samplerTextures": [], "buffers": [], "images": [] }, @@ -943,7 +943,7 @@ export const effects = [ { "name": "USE_BATCHING", "type": "boolean" }, { "name": "CC_USE_SKINNING", "type": "boolean" }, { "name": "CC_USE_BAKED_ANIMATION", "type": "boolean" }, - { "name": "USE_LIGHTMAP", "type": "boolean" }, + { "name": "CC_USE_LIGHTMAP", "type": "boolean" }, { "name": "CC_RECEIVE_SHADOW", "type": "boolean" }, { "name": "CC_USE_MORPH", "type": "boolean" }, { "name": "CC_MORPH_TARGET_COUNT", "type": "number", "range": [2, 8] }, @@ -963,7 +963,7 @@ export const effects = [ { "name": "a_matWorld0", "defines": ["USE_INSTANCING"], "format": 44, "isInstanced": true, "location": 7 }, { "name": "a_matWorld1", "defines": ["USE_INSTANCING"], "format": 44, "isInstanced": true, "location": 8 }, { "name": "a_matWorld2", "defines": ["USE_INSTANCING"], "format": 44, "isInstanced": true, "location": 9 }, - { "name": "a_lightingMapUVParam", "defines": ["USE_INSTANCING", "USE_LIGHTMAP"], "format": 44, "isInstanced": true, "location": 10 }, + { "name": "a_lightingMapUVParam", "defines": ["USE_INSTANCING", "CC_USE_LIGHTMAP"], "format": 44, "isInstanced": true, "location": 10 }, { "name": "a_localShadowBias", "defines": ["USE_INSTANCING", "CC_RECEIVE_SHADOW"], "format": 21, "isInstanced": true, "location": 11 }, { "name": "a_dyn_batch_id", "defines": ["!USE_INSTANCING", "USE_BATCHING"], "format": 11, "location": 12 }, { "name": "a_vertexId", "defines": ["CC_USE_MORPH"], "format": 11, "location": 13 } @@ -984,7 +984,7 @@ export const effects = [ }, { "name": "bloom|bloom-vs|downsample-fs", - "hash": 4138051792, + "hash": 3434961402, "builtins": { "statistics": { "CC_EFFECT_USED_VERTEX_UNIFORM_VECTORS": 148, "CC_EFFECT_USED_FRAGMENT_UNIFORM_VECTORS": 41 }, "globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }, { "name": "CCCamera", "defines": [] }], "samplerTextures": [], "buffers": [], "images": [] }, @@ -995,7 +995,7 @@ export const effects = [ { "name": "USE_BATCHING", "type": "boolean" }, { "name": "CC_USE_SKINNING", "type": "boolean" }, { "name": "CC_USE_BAKED_ANIMATION", "type": "boolean" }, - { "name": "USE_LIGHTMAP", "type": "boolean" }, + { "name": "CC_USE_LIGHTMAP", "type": "boolean" }, { "name": "CC_RECEIVE_SHADOW", "type": "boolean" }, { "name": "CC_USE_MORPH", "type": "boolean" }, { "name": "CC_MORPH_TARGET_COUNT", "type": "number", "range": [2, 8] }, @@ -1015,7 +1015,7 @@ export const effects = [ { "name": "a_matWorld0", "defines": ["USE_INSTANCING"], "format": 44, "isInstanced": true, "location": 7 }, { "name": "a_matWorld1", "defines": ["USE_INSTANCING"], "format": 44, "isInstanced": true, "location": 8 }, { "name": "a_matWorld2", "defines": ["USE_INSTANCING"], "format": 44, "isInstanced": true, "location": 9 }, - { "name": "a_lightingMapUVParam", "defines": ["USE_INSTANCING", "USE_LIGHTMAP"], "format": 44, "isInstanced": true, "location": 10 }, + { "name": "a_lightingMapUVParam", "defines": ["USE_INSTANCING", "CC_USE_LIGHTMAP"], "format": 44, "isInstanced": true, "location": 10 }, { "name": "a_localShadowBias", "defines": ["USE_INSTANCING", "CC_RECEIVE_SHADOW"], "format": 21, "isInstanced": true, "location": 11 }, { "name": "a_dyn_batch_id", "defines": ["!USE_INSTANCING", "USE_BATCHING"], "format": 11, "location": 12 }, { "name": "a_vertexId", "defines": ["CC_USE_MORPH"], "format": 11, "location": 13 } @@ -1036,7 +1036,7 @@ export const effects = [ }, { "name": "bloom|bloom-vs|upsample-fs", - "hash": 11807071, + "hash": 2149583569, "builtins": { "statistics": { "CC_EFFECT_USED_VERTEX_UNIFORM_VECTORS": 148, "CC_EFFECT_USED_FRAGMENT_UNIFORM_VECTORS": 41 }, "globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }, { "name": "CCCamera", "defines": [] }], "samplerTextures": [], "buffers": [], "images": [] }, @@ -1047,7 +1047,7 @@ export const effects = [ { "name": "USE_BATCHING", "type": "boolean" }, { "name": "CC_USE_SKINNING", "type": "boolean" }, { "name": "CC_USE_BAKED_ANIMATION", "type": "boolean" }, - { "name": "USE_LIGHTMAP", "type": "boolean" }, + { "name": "CC_USE_LIGHTMAP", "type": "boolean" }, { "name": "CC_RECEIVE_SHADOW", "type": "boolean" }, { "name": "CC_USE_MORPH", "type": "boolean" }, { "name": "CC_MORPH_TARGET_COUNT", "type": "number", "range": [2, 8] }, @@ -1067,7 +1067,7 @@ export const effects = [ { "name": "a_matWorld0", "defines": ["USE_INSTANCING"], "format": 44, "isInstanced": true, "location": 7 }, { "name": "a_matWorld1", "defines": ["USE_INSTANCING"], "format": 44, "isInstanced": true, "location": 8 }, { "name": "a_matWorld2", "defines": ["USE_INSTANCING"], "format": 44, "isInstanced": true, "location": 9 }, - { "name": "a_lightingMapUVParam", "defines": ["USE_INSTANCING", "USE_LIGHTMAP"], "format": 44, "isInstanced": true, "location": 10 }, + { "name": "a_lightingMapUVParam", "defines": ["USE_INSTANCING", "CC_USE_LIGHTMAP"], "format": 44, "isInstanced": true, "location": 10 }, { "name": "a_localShadowBias", "defines": ["USE_INSTANCING", "CC_RECEIVE_SHADOW"], "format": 21, "isInstanced": true, "location": 11 }, { "name": "a_dyn_batch_id", "defines": ["!USE_INSTANCING", "USE_BATCHING"], "format": 11, "location": 12 }, { "name": "a_vertexId", "defines": ["CC_USE_MORPH"], "format": 11, "location": 13 } @@ -1088,7 +1088,7 @@ export const effects = [ }, { "name": "bloom|bloom-vs|combine-fs", - "hash": 3902981093, + "hash": 2129678041, "builtins": { "statistics": { "CC_EFFECT_USED_VERTEX_UNIFORM_VECTORS": 148, "CC_EFFECT_USED_FRAGMENT_UNIFORM_VECTORS": 41 }, "globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }, { "name": "CCCamera", "defines": [] }], "samplerTextures": [], "buffers": [], "images": [] }, @@ -1099,7 +1099,7 @@ export const effects = [ { "name": "USE_BATCHING", "type": "boolean" }, { "name": "CC_USE_SKINNING", "type": "boolean" }, { "name": "CC_USE_BAKED_ANIMATION", "type": "boolean" }, - { "name": "USE_LIGHTMAP", "type": "boolean" }, + { "name": "CC_USE_LIGHTMAP", "type": "boolean" }, { "name": "CC_RECEIVE_SHADOW", "type": "boolean" }, { "name": "CC_USE_MORPH", "type": "boolean" }, { "name": "CC_MORPH_TARGET_COUNT", "type": "number", "range": [2, 8] }, @@ -1119,7 +1119,7 @@ export const effects = [ { "name": "a_matWorld0", "defines": ["USE_INSTANCING"], "format": 44, "isInstanced": true, "location": 7 }, { "name": "a_matWorld1", "defines": ["USE_INSTANCING"], "format": 44, "isInstanced": true, "location": 8 }, { "name": "a_matWorld2", "defines": ["USE_INSTANCING"], "format": 44, "isInstanced": true, "location": 9 }, - { "name": "a_lightingMapUVParam", "defines": ["USE_INSTANCING", "USE_LIGHTMAP"], "format": 44, "isInstanced": true, "location": 10 }, + { "name": "a_lightingMapUVParam", "defines": ["USE_INSTANCING", "CC_USE_LIGHTMAP"], "format": 44, "isInstanced": true, "location": 10 }, { "name": "a_localShadowBias", "defines": ["USE_INSTANCING", "CC_RECEIVE_SHADOW"], "format": 21, "isInstanced": true, "location": 11 }, { "name": "a_dyn_batch_id", "defines": ["!USE_INSTANCING", "USE_BATCHING"], "format": 11, "location": 12 }, { "name": "a_vertexId", "defines": ["CC_USE_MORPH"], "format": 11, "location": 13 } @@ -1149,7 +1149,7 @@ export const effects = [ "shaders": [ { "name": "deferred-lighting|lighting-vs|lighting-fs", - "hash": 3839556198, + "hash": 4096516376, "builtins": { "statistics": { "CC_EFFECT_USED_VERTEX_UNIFORM_VECTORS": 40, "CC_EFFECT_USED_FRAGMENT_UNIFORM_VECTORS": 70 }, "globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }, { "name": "CCCamera", "defines": [] }, { "name": "CCShadow", "defines": [] }], "samplerTextures": [{ "name": "cc_shadowMap", "defines": ["CC_RECEIVE_SHADOW"] }, { "name": "cc_spotLightingMap", "defines": ["CC_RECEIVE_SHADOW"] }, { "name": "cc_environment", "defines": ["CC_USE_IBL"] }, { "name": "cc_diffuseMap", "defines": ["CC_USE_DIFFUSEMAP"] }], "buffers": [], "images": [] }, @@ -1160,7 +1160,7 @@ export const effects = [ { "name": "USE_BATCHING", "type": "boolean" }, { "name": "CC_USE_SKINNING", "type": "boolean" }, { "name": "CC_USE_BAKED_ANIMATION", "type": "boolean" }, - { "name": "USE_LIGHTMAP", "type": "boolean" }, + { "name": "CC_USE_LIGHTMAP", "type": "boolean" }, { "name": "CC_RECEIVE_SHADOW", "type": "boolean" }, { "name": "CC_USE_MORPH", "type": "boolean" }, { "name": "CC_USE_IBL", "type": "number", "range": [0, 2] }, @@ -1183,7 +1183,7 @@ export const effects = [ { "name": "a_matWorld0", "defines": ["USE_INSTANCING"], "format": 44, "isInstanced": true, "location": 7 }, { "name": "a_matWorld1", "defines": ["USE_INSTANCING"], "format": 44, "isInstanced": true, "location": 8 }, { "name": "a_matWorld2", "defines": ["USE_INSTANCING"], "format": 44, "isInstanced": true, "location": 9 }, - { "name": "a_lightingMapUVParam", "defines": ["USE_INSTANCING", "USE_LIGHTMAP"], "format": 44, "isInstanced": true, "location": 10 }, + { "name": "a_lightingMapUVParam", "defines": ["USE_INSTANCING", "CC_USE_LIGHTMAP"], "format": 44, "isInstanced": true, "location": 10 }, { "name": "a_localShadowBias", "defines": ["USE_INSTANCING", "CC_RECEIVE_SHADOW"], "format": 21, "isInstanced": true, "location": 11 }, { "name": "a_dyn_batch_id", "defines": ["!USE_INSTANCING", "USE_BATCHING"], "format": 11, "location": 12 }, { "name": "a_vertexId", "defines": ["CC_USE_MORPH"], "format": 11, "location": 13 } @@ -1215,7 +1215,7 @@ export const effects = [ "shaders": [ { "name": "planar-shadow|planar-shadow-vs:vert|planar-shadow-fs:frag", - "hash": 3028442430, + "hash": 2402869293, "builtins": { "statistics": { "CC_EFFECT_USED_VERTEX_UNIFORM_VECTORS": 218, "CC_EFFECT_USED_FRAGMENT_UNIFORM_VECTORS": 60 }, "globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }, { "name": "CCCamera", "defines": [] }, { "name": "CCShadow", "defines": [] }], "samplerTextures": [], "buffers": [], "images": [] }, @@ -1226,7 +1226,7 @@ export const effects = [ { "name": "USE_BATCHING", "type": "boolean" }, { "name": "CC_USE_SKINNING", "type": "boolean" }, { "name": "CC_USE_BAKED_ANIMATION", "type": "boolean" }, - { "name": "USE_LIGHTMAP", "type": "boolean" }, + { "name": "CC_USE_LIGHTMAP", "type": "boolean" }, { "name": "CC_RECEIVE_SHADOW", "type": "boolean" }, { "name": "CC_USE_MORPH", "type": "boolean" }, { "name": "CC_MORPH_TARGET_COUNT", "type": "number", "range": [2, 8] }, @@ -1246,7 +1246,7 @@ export const effects = [ { "name": "a_matWorld0", "defines": ["USE_INSTANCING"], "format": 44, "isInstanced": true, "location": 7 }, { "name": "a_matWorld1", "defines": ["USE_INSTANCING"], "format": 44, "isInstanced": true, "location": 8 }, { "name": "a_matWorld2", "defines": ["USE_INSTANCING"], "format": 44, "isInstanced": true, "location": 9 }, - { "name": "a_lightingMapUVParam", "defines": ["USE_INSTANCING", "USE_LIGHTMAP"], "format": 44, "isInstanced": true, "location": 10 }, + { "name": "a_lightingMapUVParam", "defines": ["USE_INSTANCING", "CC_USE_LIGHTMAP"], "format": 44, "isInstanced": true, "location": 10 }, { "name": "a_localShadowBias", "defines": ["USE_INSTANCING", "CC_RECEIVE_SHADOW"], "format": 21, "isInstanced": true, "location": 11 }, { "name": "a_dyn_batch_id", "defines": ["!USE_INSTANCING", "USE_BATCHING"], "format": 11, "location": 12 }, { "name": "a_vertexId", "defines": ["CC_USE_MORPH"], "format": 11, "location": 13 } @@ -1269,7 +1269,7 @@ export const effects = [ "shaders": [ { "name": "post-process|post-process-vs|post-process-fs", - "hash": 2703550928, + "hash": 1675033909, "builtins": { "statistics": { "CC_EFFECT_USED_VERTEX_UNIFORM_VECTORS": 148, "CC_EFFECT_USED_FRAGMENT_UNIFORM_VECTORS": 40 }, "globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }, { "name": "CCCamera", "defines": [] }], "samplerTextures": [], "buffers": [], "images": [] }, @@ -1280,7 +1280,7 @@ export const effects = [ { "name": "USE_BATCHING", "type": "boolean" }, { "name": "CC_USE_SKINNING", "type": "boolean" }, { "name": "CC_USE_BAKED_ANIMATION", "type": "boolean" }, - { "name": "USE_LIGHTMAP", "type": "boolean" }, + { "name": "CC_USE_LIGHTMAP", "type": "boolean" }, { "name": "CC_RECEIVE_SHADOW", "type": "boolean" }, { "name": "CC_USE_MORPH", "type": "boolean" }, { "name": "CC_MORPH_TARGET_COUNT", "type": "number", "range": [2, 8] }, @@ -1301,7 +1301,7 @@ export const effects = [ { "name": "a_matWorld0", "defines": ["USE_INSTANCING"], "format": 44, "isInstanced": true, "location": 7 }, { "name": "a_matWorld1", "defines": ["USE_INSTANCING"], "format": 44, "isInstanced": true, "location": 8 }, { "name": "a_matWorld2", "defines": ["USE_INSTANCING"], "format": 44, "isInstanced": true, "location": 9 }, - { "name": "a_lightingMapUVParam", "defines": ["USE_INSTANCING", "USE_LIGHTMAP"], "format": 44, "isInstanced": true, "location": 10 }, + { "name": "a_lightingMapUVParam", "defines": ["USE_INSTANCING", "CC_USE_LIGHTMAP"], "format": 44, "isInstanced": true, "location": 10 }, { "name": "a_localShadowBias", "defines": ["USE_INSTANCING", "CC_RECEIVE_SHADOW"], "format": 21, "isInstanced": true, "location": 11 }, { "name": "a_dyn_batch_id", "defines": ["!USE_INSTANCING", "USE_BATCHING"], "format": 11, "location": 12 }, { "name": "a_vertexId", "defines": ["CC_USE_MORPH"], "format": 11, "location": 13 } @@ -1326,7 +1326,7 @@ export const effects = [ "shaders": [ { "name": "skybox|sky-vs:vert|sky-fs:frag", - "hash": 1046209564, + "hash": 1670296498, "builtins": { "statistics": { "CC_EFFECT_USED_VERTEX_UNIFORM_VECTORS": 40, "CC_EFFECT_USED_FRAGMENT_UNIFORM_VECTORS": 40 }, "globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }, { "name": "CCCamera", "defines": [] }], "samplerTextures": [{ "name": "cc_environment", "defines": [] }], "buffers": [], "images": [] }, @@ -1337,7 +1337,7 @@ export const effects = [ { "name": "USE_BATCHING", "type": "boolean" }, { "name": "CC_USE_SKINNING", "type": "boolean" }, { "name": "CC_USE_BAKED_ANIMATION", "type": "boolean" }, - { "name": "USE_LIGHTMAP", "type": "boolean" }, + { "name": "CC_USE_LIGHTMAP", "type": "boolean" }, { "name": "CC_RECEIVE_SHADOW", "type": "boolean" }, { "name": "CC_USE_MORPH", "type": "boolean" }, { "name": "CC_USE_IBL", "type": "number", "range": [0, 2] }, @@ -1355,7 +1355,7 @@ export const effects = [ { "name": "a_matWorld0", "defines": ["USE_INSTANCING"], "format": 44, "isInstanced": true, "location": 7 }, { "name": "a_matWorld1", "defines": ["USE_INSTANCING"], "format": 44, "isInstanced": true, "location": 8 }, { "name": "a_matWorld2", "defines": ["USE_INSTANCING"], "format": 44, "isInstanced": true, "location": 9 }, - { "name": "a_lightingMapUVParam", "defines": ["USE_INSTANCING", "USE_LIGHTMAP"], "format": 44, "isInstanced": true, "location": 10 }, + { "name": "a_lightingMapUVParam", "defines": ["USE_INSTANCING", "CC_USE_LIGHTMAP"], "format": 44, "isInstanced": true, "location": 10 }, { "name": "a_localShadowBias", "defines": ["USE_INSTANCING", "CC_RECEIVE_SHADOW"], "format": 21, "isInstanced": true, "location": 11 }, { "name": "a_dyn_batch_id", "defines": ["!USE_INSTANCING", "USE_BATCHING"], "format": 11, "location": 12 }, { "name": "a_vertexId", "defines": ["CC_USE_MORPH"], "format": 11, "location": 13 } diff --git a/cocos/core/builtin/shader-sources/glsl1.ts b/cocos/core/builtin/shader-sources/glsl1.ts index dc9f1ad0d1..a1b66c6ddb 100644 --- a/cocos/core/builtin/shader-sources/glsl1.ts +++ b/cocos/core/builtin/shader-sources/glsl1.ts @@ -88,18 +88,18 @@ export const glsl1 = [ ], [ { - "vert": "\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\nrgba = rgba * 255.0;\nhighp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\nhighp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\nhighp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\nreturn Sign * exp2(Exponent - 23.0) * Mantissa;\n}\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nattribute vec3 a_position;\nattribute vec3 a_normal;\nattribute vec2 a_texCoord;\nattribute vec4 a_tangent;\n#if CC_USE_SKINNING\nattribute vec4 a_joints;\nattribute vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nattribute highp vec4 a_jointAnimInfo;\n#endif\nattribute vec4 a_matWorld0;\nattribute vec4 a_matWorld1;\nattribute vec4 a_matWorld2;\n#if USE_LIGHTMAP\nattribute vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nattribute vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nattribute float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nattribute float a_vertexId;\nint getVertexId() {\nreturn int(a_vertexId);\n}\n#endif\n#if CC_USE_MORPH\nuniform vec4 cc_displacementWeights[15];\nuniform vec4 cc_displacementTextureInfo;\nvec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\nfloat pixelIndexF = float(pixelIndex);\nfloat x = mod(pixelIndexF, textureResolution.x);\nfloat y = floor(pixelIndexF / textureResolution.x);\nreturn vec2(x, y);\n}\nvec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\nreturn (vec2(location.x, location.y) + .5) / textureResolution;\n}\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 uv = getPixelCoordFromLocation(location, cc_displacementTextureInfo.xy);\nreturn texture2D(tex, uv);\n}\n#else\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex * 4;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\nreturn vec4(\ndecode32(texture2D(tex, x)),\ndecode32(texture2D(tex, y)),\ndecode32(texture2D(tex, z)),\n1.0\n);\n}\n#endif\nfloat getDisplacementWeight(int index) {\nint quot = index / 4;\nint remainder = index - quot * 4;\nif (remainder == 0) {\nreturn cc_displacementWeights[quot].x;\n} else if (remainder == 1) {\nreturn cc_displacementWeights[quot].y;\n} else if (remainder == 2) {\nreturn cc_displacementWeights[quot].z;\n} else {\nreturn cc_displacementWeights[quot].w;\n}\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\nreturn fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n#else\nvec3 result = vec3(0, 0, 0);\nint nVertices = int(cc_displacementTextureInfo.z);\nfor (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\nresult += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n}\nreturn result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\nuniform sampler2D cc_PositionDisplacements;\nvec3 getPositionDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nuniform sampler2D cc_NormalDisplacements;\nvec3 getNormalDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\nuniform sampler2D cc_TangentDisplacements;\nvec3 getTangentDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n}\n#endif\nvoid applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nint vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nnormal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\ntangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\n#if CC_USE_BAKED_ANIMATION\nuniform highp vec4 cc_jointTextureInfo;\nuniform highp vec4 cc_jointAnimInfo;\nuniform highp sampler2D cc_jointTexture;\nvoid CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n{\n#if USE_INSTANCING\nhighp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n#else\nhighp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n#endif\ninvSize = cc_jointTextureInfo.w;\nhighp float tempY = floor(temp * invSize);\nx = floor(temp - tempY * cc_jointTextureInfo.x);\ny = (tempY + 0.5) * invSize;\n}\n#else\nuniform highp vec4 cc_joints[90];\n#endif\n#if CC_USE_BAKED_ANIMATION\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(3.0, i, x, y, invSize);\nvec4 v1 = texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y));\nvec4 v2 = texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y));\nvec4 v3 = texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y));\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#else\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(12.0, i, x, y, invSize);\nvec4 v1 = vec4(\ndecode32(texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n);\nvec4 v2 = vec4(\ndecode32(texture2D(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n);\nvec4 v3 = vec4(\ndecode32(texture2D(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n);\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\n#else\nmat4 getJointMatrix (float i) {\nint idx = int(i);\nvec4 v1 = cc_joints[idx * 3];\nvec4 v2 = cc_joints[idx * 3 + 1];\nvec4 v3 = cc_joints[idx * 3 + 2];\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\nmat4 skinMatrix () {\nvec4 joints = vec4(a_joints);\nreturn getJointMatrix(joints.x) * a_weights.x\n+ getJointMatrix(joints.y) * a_weights.y\n+ getJointMatrix(joints.z) * a_weights.z\n+ getJointMatrix(joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\nmat4 m = skinMatrix();\nposition = m * position;\n}\nvoid CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nmat4 m = skinMatrix();\nposition = m * position;\nnormal = (m * vec4(normal, 0.0)).xyz;\ntangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n}\n#endif\nvoid CCVertInput(inout StandardVertInput In)\n{\nIn.position = vec4(a_position, 1.0);\nIn.normal = a_normal;\nIn.tangent = a_tangent;\n#if CC_USE_MORPH\napplyMorph(In.position, In.normal, In.tangent);\n#endif\n#if CC_USE_SKINNING\nCCSkin(In.position, In.normal, In.tangent);\n#endif\n}\nuniform highp mat4 cc_matView;\nuniform highp mat4 cc_matProj;\nuniform highp vec4 cc_cameraPos;\nuniform mediump vec4 cc_fogBase;\nuniform mediump vec4 cc_fogAdd;\n#if !USE_INSTANCING\n#if USE_BATCHING\nuniform highp mat4 cc_matWorlds[10];\n#else\nuniform highp mat4 cc_matWorld;\nuniform highp mat4 cc_matWorldIT;\nuniform highp vec4 cc_lightingMapUVParam;\nuniform highp vec4 cc_localShadowBias;\n#endif\n#endif\nvoid CCGetWorldMatrixFull(out mat4 matWorld, out mat4 matWorldIT)\n{\n#if USE_INSTANCING\nmatWorld = mat4(\nvec4(a_matWorld0.xyz, 0.0),\nvec4(a_matWorld1.xyz, 0.0),\nvec4(a_matWorld2.xyz, 0.0),\nvec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)\n);\nmatWorldIT = matWorld;\n#elif USE_BATCHING\nmatWorld = cc_matWorlds[int(a_dyn_batch_id)];\nmatWorldIT = matWorld;\n#else\nmatWorld = cc_matWorld;\nmatWorldIT = cc_matWorldIT;\n#endif\n}\nuniform vec4 tilingOffset;\nfloat LinearFog(vec4 pos) {\nvec4 wPos = pos;\nfloat cam_dis = distance(cc_cameraPos, wPos);\nfloat fogStart = cc_fogBase.x;\nfloat fogEnd = cc_fogBase.y;\nreturn clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * fogDensity);\nreturn f;\n}\nfloat ExpSquaredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\nreturn f;\n}\nfloat LayeredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat _FogTop = cc_fogAdd.x;\nfloat _FogRange = cc_fogAdd.y;\nvec3 camWorldProj = cc_cameraPos.xyz;\ncamWorldProj.y = 0.;\nvec3 worldPosProj = wPos.xyz;\nworldPosProj.y = 0.;\nfloat fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\nfloat fDeltaY, fDensityIntegral;\nif (cc_cameraPos.y > _FogTop) {\nif (wPos.y < _FogTop) {\nfDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\nfDensityIntegral = fDeltaY * fDeltaY * 0.5;\n} else {\nfDeltaY = 0.;\nfDensityIntegral = 0.;\n}\n} else {\nif (wPos.y < _FogTop) {\nfloat fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfloat fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\nfDeltaY = abs(fDeltaA - fDeltaB);\nfDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n} else {\nfDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n}\n}\nfloat fDensity;\nif (fDeltaY != 0.) {\nfDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n} else {\nfDensity = 0.;\n}\nfloat f = exp(-fDensity);\nreturn f;\n}\nvoid CC_TRANSFER_FOG_BASE(vec4 pos, out float factor)\n{\n#if CC_USE_FOG == 0\nfactor = LinearFog(pos);\n#elif CC_USE_FOG == 1\nfactor = ExpFog(pos);\n#elif CC_USE_FOG == 2\nfactor = ExpSquaredFog(pos);\n#elif CC_USE_FOG == 3\nfactor = LayeredFog(pos);\n#else\nfactor = 1.0;\n#endif\n}\n#if !CC_USE_ACCURATE_FOG\nvarying float v_fog_factor;\n#endif\nvoid CC_TRANSFER_FOG(vec4 pos) {\n#if !CC_USE_ACCURATE_FOG\nCC_TRANSFER_FOG_BASE(pos, v_fog_factor);\n#endif\n}\nvarying highp vec4 v_shadowPos;\nuniform highp mat4 cc_matLightViewProj;\nuniform mediump vec4 cc_shadowWHPBInfo;\nuniform mediump vec4 cc_shadowLPNNInfo;\n#if CC_RECEIVE_SHADOW\nuniform highp sampler2D cc_shadowMap;\nuniform highp sampler2D cc_spotLightingMap;\n#endif\n#if CC_RECEIVE_SHADOW\nvec2 CCGetShadowBias()\n{\n#if USE_INSTANCING\nreturn vec2(a_localShadowBias.x + cc_shadowWHPBInfo.w, a_localShadowBias.y + cc_shadowLPNNInfo.z);\n#elif !USE_BATCHING\nreturn vec2(cc_localShadowBias.x + cc_shadowWHPBInfo.w, cc_localShadowBias.y + cc_shadowLPNNInfo.z);\n#else\nreturn vec2(cc_shadowWHPBInfo.w, cc_shadowLPNNInfo.z);\n#endif\n}\n#endif\n#if USE_VERTEX_COLOR\nattribute vec4 a_color;\nvarying lowp vec4 v_color;\n#endif\nvarying vec3 v_position;\nvarying mediump vec3 v_normal;\nvarying vec2 v_uv;\n#if HAS_SECOND_UV\nvarying mediump vec2 v_uv1;\n#endif\n#if CC_RECEIVE_SHADOW\nvarying mediump vec2 v_shadowBias;\n#endif\n#if USE_NORMAL_MAP\nvarying mediump vec4 v_tangent;\n#endif\n#if HAS_SECOND_UV || USE_LIGHTMAP\nattribute vec2 a_texCoord1;\n#endif\n#if USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\nvarying vec3 v_luv;\nvoid CCLightingMapCaclUV()\n{\n#if !USE_INSTANCING\nv_luv.xy = cc_lightingMapUVParam.xy + a_texCoord1 * cc_lightingMapUVParam.z;\nv_luv.z = cc_lightingMapUVParam.w;\n#else\nv_luv.xy = a_lightingMapUVParam.xy + a_texCoord1 * a_lightingMapUVParam.z;\nv_luv.z = a_lightingMapUVParam.w;\n#endif\n}\n#endif\nvoid main () {\nStandardVertInput In;\nCCVertInput(In);\nmat4 matWorld, matWorldIT;\nCCGetWorldMatrixFull(matWorld, matWorldIT);\nvec4 pos = matWorld * In.position;\nv_position = pos.xyz;\nv_normal = normalize((matWorldIT * vec4(In.normal, 0.0)).xyz);\n#if CC_RECEIVE_SHADOW\nv_shadowBias = CCGetShadowBias();\n#endif\n#if USE_TWOSIDE\nvec3 viewDirect = normalize(cc_cameraPos.xyz - v_position);\nv_normal *= dot(v_normal, viewDirect) < 0.0 ? -1.0 : 1.0;\n#endif\n#if USE_NORMAL_MAP\nv_tangent.xyz = normalize((matWorld * vec4(In.tangent.xyz, 0.0)).xyz);\nv_tangent.w = In.tangent.w;\n#endif\nv_uv = a_texCoord * tilingOffset.xy + tilingOffset.zw;\n#if SAMPLE_FROM_RT\nv_uv = cc_cameraPos.w > 1.0 ? vec2(v_uv.x, 1.0 - v_uv.y) : v_uv;\n#endif\n#if HAS_SECOND_UV\nv_uv1 = a_texCoord1 * tilingOffset.xy + tilingOffset.zw;\n#if SAMPLE_FROM_RT\nv_uv1 = cc_cameraPos.w > 1.0 ? vec2(v_uv1.x, 1.0 - v_uv1.y) : v_uv1;\n#endif\n#endif\n#if USE_VERTEX_COLOR\nv_color = a_color;\n#endif\nCC_TRANSFER_FOG(pos);\nv_shadowPos = cc_matLightViewProj * pos;\n#if USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\nCCLightingMapCaclUV();\n#endif\ngl_Position = cc_matProj * (cc_matView * matWorld) * In.position;\n}", - "frag": "\n#ifdef GL_EXT_draw_buffers\n#extension GL_EXT_draw_buffers: enable\n#endif\n#ifdef GL_OES_standard_derivatives\n#extension GL_OES_standard_derivatives: enable\n#endif\n#ifdef GL_EXT_shader_texture_lod\n#extension GL_EXT_shader_texture_lod: enable\n#endif\nprecision highp float;\nuniform highp mat4 cc_matView;\nuniform highp vec4 cc_cameraPos;\nuniform mediump vec4 cc_mainLitDir;\nuniform mediump vec4 cc_mainLitColor;\nuniform mediump vec4 cc_ambientSky;\nuniform mediump vec4 cc_ambientGround;\nuniform mediump vec4 cc_fogColor;\nuniform mediump vec4 cc_fogBase;\nuniform mediump vec4 cc_fogAdd;\nuniform mediump vec4 cc_nearFar;\nuniform mediump vec4 cc_viewPort;\nuniform vec4 albedo;\nuniform vec4 albedoScaleAndCutoff;\nuniform vec4 pbrParams;\nuniform vec4 emissive;\nuniform vec4 emissiveScaleParam;\nfloat LinearFog(vec4 pos) {\nvec4 wPos = pos;\nfloat cam_dis = distance(cc_cameraPos, wPos);\nfloat fogStart = cc_fogBase.x;\nfloat fogEnd = cc_fogBase.y;\nreturn clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * fogDensity);\nreturn f;\n}\nfloat ExpSquaredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\nreturn f;\n}\nfloat LayeredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat _FogTop = cc_fogAdd.x;\nfloat _FogRange = cc_fogAdd.y;\nvec3 camWorldProj = cc_cameraPos.xyz;\ncamWorldProj.y = 0.;\nvec3 worldPosProj = wPos.xyz;\nworldPosProj.y = 0.;\nfloat fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\nfloat fDeltaY, fDensityIntegral;\nif (cc_cameraPos.y > _FogTop) {\nif (wPos.y < _FogTop) {\nfDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\nfDensityIntegral = fDeltaY * fDeltaY * 0.5;\n} else {\nfDeltaY = 0.;\nfDensityIntegral = 0.;\n}\n} else {\nif (wPos.y < _FogTop) {\nfloat fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfloat fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\nfDeltaY = abs(fDeltaA - fDeltaB);\nfDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n} else {\nfDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n}\n}\nfloat fDensity;\nif (fDeltaY != 0.) {\nfDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n} else {\nfDensity = 0.;\n}\nfloat f = exp(-fDensity);\nreturn f;\n}\nvoid CC_TRANSFER_FOG_BASE(vec4 pos, out float factor)\n{\n#if CC_USE_FOG == 0\nfactor = LinearFog(pos);\n#elif CC_USE_FOG == 1\nfactor = ExpFog(pos);\n#elif CC_USE_FOG == 2\nfactor = ExpSquaredFog(pos);\n#elif CC_USE_FOG == 3\nfactor = LayeredFog(pos);\n#else\nfactor = 1.0;\n#endif\n}\nvoid CC_APPLY_FOG_BASE(inout vec4 color, float factor) {\ncolor = vec4(mix(cc_fogColor.rgb, color.rgb, factor), color.a);\n}\n#if !CC_USE_ACCURATE_FOG\nvarying float v_fog_factor;\n#endif\nvoid CC_APPLY_FOG(inout vec4 color) {\n#if !CC_USE_ACCURATE_FOG\nCC_APPLY_FOG_BASE(color, v_fog_factor);\n#endif\n}\nvoid CC_APPLY_FOG(inout vec4 color, vec3 worldPos) {\n#if CC_USE_ACCURATE_FOG\nfloat factor;\nCC_TRANSFER_FOG_BASE(vec4(worldPos, 1.0), factor);\n#else\nfloat factor = v_fog_factor;\n#endif\nCC_APPLY_FOG_BASE(color, factor);\n}\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nvec3 SRGBToLinear (vec3 gamma) {\nreturn gamma * gamma;\n}\nuniform highp mat4 cc_matLightView;\nuniform highp vec4 cc_shadowInvProjDepthInfo;\nuniform highp vec4 cc_shadowProjDepthInfo;\nuniform highp vec4 cc_shadowProjInfo;\nuniform mediump vec4 cc_shadowNFLSInfo;\nuniform mediump vec4 cc_shadowWHPBInfo;\nuniform mediump vec4 cc_shadowLPNNInfo;\nhighp float unpackHighpData (float mainPart, float modPart) {\nhighp float data = mainPart;\nreturn data + modPart;\n}\nvoid packHighpData (out float mainPart, out float modPart, highp float data) {\nmainPart = fract(data);\nmodPart = data - mainPart;\n}\nhighp float unpackHighpData (float mainPart, float modPart, const float modValue) {\nhighp float data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nvoid packHighpData (out float mainPart, out float modPart, highp float data, const float modValue) {\nhighp float divide = data / modValue;\nmainPart = floor(divide);\nmodPart = (data - mainPart * modValue) / modValue;\n}\nhighp vec2 unpackHighpData (vec2 mainPart, vec2 modPart) {\nhighp vec2 data = mainPart;\nreturn data + modPart;\n}\nvoid packHighpData (out vec2 mainPart, out vec2 modPart, highp vec2 data) {\nmainPart = fract(data);\nmodPart = data - mainPart;\n}\nhighp vec2 unpackHighpData (vec2 mainPart, vec2 modPart, const float modValue) {\nhighp vec2 data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nvoid packHighpData (out vec2 mainPart, out vec2 modPart, highp vec2 data, const float modValue) {\nhighp vec2 divide = data / modValue;\nmainPart = floor(divide);\nmodPart = (data - mainPart * modValue) / modValue;\n}\nhighp vec3 unpackHighpData (vec3 mainPart, vec3 modPart) {\nhighp vec3 data = mainPart;\nreturn data + modPart;\n}\nvoid packHighpData (out vec3 mainPart, out vec3 modPart, highp vec3 data) {\nmainPart = fract(data);\nmodPart = data - mainPart;\n}\nhighp vec3 unpackHighpData (vec3 mainPart, vec3 modPart, const float modValue) {\nhighp vec3 data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nvoid packHighpData (out vec3 mainPart, out vec3 modPart, highp vec3 data, const float modValue) {\nhighp vec3 divide = data / modValue;\nmainPart = floor(divide);\nmodPart = (data - mainPart * modValue) / modValue;\n}\nhighp vec4 unpackHighpData (vec4 mainPart, vec4 modPart) {\nhighp vec4 data = mainPart;\nreturn data + modPart;\n}\nvoid packHighpData (out vec4 mainPart, out vec4 modPart, highp vec4 data) {\nmainPart = fract(data);\nmodPart = data - mainPart;\n}\nhighp vec4 unpackHighpData (vec4 mainPart, vec4 modPart, const float modValue) {\nhighp vec4 data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nvoid packHighpData (out vec4 mainPart, out vec4 modPart, highp vec4 data, const float modValue) {\nhighp vec4 divide = data / modValue;\nmainPart = floor(divide);\nmodPart = (data - mainPart * modValue) / modValue;\n}\nfloat CCGetLinearDepthFromViewSpace(vec3 viewPos) {\nfloat dist = length(viewPos);\nreturn (dist - cc_shadowNFLSInfo.x) / (cc_shadowNFLSInfo.y - cc_shadowNFLSInfo.x);\n}\nfloat CCGetLinearDepth(vec3 worldPos) {\nvec4 viewStartPos = cc_matLightView * vec4(worldPos.xyz, 1.0);\nreturn CCGetLinearDepthFromViewSpace(viewStartPos.xyz);\n}\n#if CC_RECEIVE_SHADOW\nuniform highp sampler2D cc_shadowMap;\nuniform highp sampler2D cc_spotLightingMap;\nvec4 ApplyShadowDepthBias_FaceNormal(vec4 shadowPos, vec3 worldNormal, float normalBias)\n{\nvec4 newShadowPos = shadowPos;\nif(normalBias > EPSILON_LOWP)\n{\nvec4 viewNormal = cc_matLightView * vec4(worldNormal, 0.0);\nif(viewNormal.z < 0.1)\nnewShadowPos.xy += viewNormal.xy * cc_shadowProjInfo.xy * normalBias * clamp(viewNormal.z, 0.001, 0.1);\n}\nreturn newShadowPos;\n}\nvec4 ApplyShadowDepthBias_Perspective(vec4 shadowPos, float viewspaceDepthBias)\n{\nvec3 viewSpacePos;\nviewSpacePos.xy = shadowPos.xy * cc_shadowProjInfo.zw;\nviewSpacePos.z = shadowPos.z * cc_shadowInvProjDepthInfo.x + shadowPos.w * cc_shadowInvProjDepthInfo.y;\nviewSpacePos.xyz += cc_shadowProjDepthInfo.z * normalize(viewSpacePos.xyz) * viewspaceDepthBias;\nvec4 clipSpacePos;\nclipSpacePos.xy = viewSpacePos.xy * cc_shadowProjInfo.xy;\nclipSpacePos.zw = viewSpacePos.z * cc_shadowProjDepthInfo.xz + vec2(cc_shadowProjDepthInfo.y, 0.0);\nif (cc_shadowNFLSInfo.z > EPSILON) {\nclipSpacePos.z = CCGetLinearDepthFromViewSpace(viewSpacePos.xyz);\nclipSpacePos.z = (clipSpacePos.z * 2.0 - 1.0) * clipSpacePos.w;\n}\nreturn clipSpacePos;\n}\nvec4 ApplyShadowDepthBias_Orthographic(vec4 shadowPos, float viewspaceDepthBias)\n{\nfloat coeffA = cc_shadowProjDepthInfo.x;\nfloat coeffB = cc_shadowProjDepthInfo.y;\nfloat viewSpacePos_z = (shadowPos.z - coeffB) / coeffA;\nviewSpacePos_z += viewspaceDepthBias;\nvec4 result = shadowPos;\nresult.z = viewSpacePos_z * coeffA + coeffB;\nreturn result;\n}\nfloat CCGetShadowFactorHard (vec4 shadowPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Orthographic(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat shadow = 0.0;\nfloat closestDepth = 0.0;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nclosestDepth = dot(texture2D(cc_shadowMap, clipPos.xy), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0));\n} else {\nclosestDepth = texture2D(cc_shadowMap, clipPos.xy).x;\n}\nshadow = step(clipPos.z, closestDepth);\nreturn shadow;\n}\nfloat CCGetShadowFactorSoft (vec4 shadowPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Orthographic(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat offsetDepth = clipPos.z;\nvec2 mapSize = cc_shadowWHPBInfo.xy;\nvec2 oneTap = 1.0 / mapSize;\nvec2 clipPos_offset = clipPos.xy + oneTap;\nfloat block0, block1, block2, block3;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos_offset.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos_offset.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos.x, clipPos.y)).x);\nblock1 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos_offset.x, clipPos.y)).x);\nblock2 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos.x, clipPos_offset.y)).x);\nblock3 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos_offset.x, clipPos_offset.y)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * mapSize.x;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block2, block3, coefX);\nfloat coefY = mod(clipPos.y, oneTap.y) * mapSize.y;\nreturn mix(resultX, resultY, coefY);\n}\nfloat CCGetShadowFactorSoft2X (vec4 shadowPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Orthographic(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat offsetDepth = clipPos.z;\nvec2 mapSize = cc_shadowWHPBInfo.xy;\nvec2 oneTap = 1.0 / mapSize;\nfloat clipPos_offset_L = clipPos.x - oneTap.x;\nfloat clipPos_offset_R = clipPos.x + oneTap.x;\nfloat clipPos_offset_U = clipPos.y - oneTap.y;\nfloat clipPos_offset_D = clipPos.y + oneTap.y;\nfloat block0, block1, block2, block3, block4, block5, block6, block7, block8;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos.x, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos_offset_L, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock4 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock5 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos_offset_R, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock6 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock7 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos.x, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock8 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_U)).x);\nblock1 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos.x, clipPos_offset_U)).x);\nblock2 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_U)).x);\nblock3 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos_offset_L, clipPos.y)).x);\nblock4 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos.x, clipPos.y)).x);\nblock5 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos_offset_R, clipPos.y)).x);\nblock6 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_D)).x);\nblock7 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos.x, clipPos_offset_D)).x);\nblock8 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_D)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * mapSize.x;\nfloat coefY = mod(clipPos.y, oneTap.y) * mapSize.y;\nfloat shadow = 0.0;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block3, block4, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block1, block2, coefX);\nresultY = mix(block4, block5, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block3, block4, coefX);\nresultY = mix(block6, block7, coefX);\nshadow += mix(resultX, resultY, coefY);\nresultX = mix(block4, block5, coefX);\nresultY = mix(block7, block8, coefX);\nshadow += mix(resultX, resultY, coefY);\nreturn shadow * 0.25;\n}\nfloat CCGetSpotLightShadowFactorHard (vec4 shadowPos, vec3 worldPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Perspective(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat shadow = 0.0;\nfloat closestDepth = 0.0;\nfloat depth = clipPos.z;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nclosestDepth = dot(texture2D(cc_spotLightingMap, clipPos.xy), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0));\n} else {\nclosestDepth = texture2D(cc_spotLightingMap, clipPos.xy).x;\n}\nshadow = step(depth, closestDepth);\nreturn shadow;\n}\nfloat CCGetSpotLightShadowFactorSoft (vec4 shadowPos, vec3 worldPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Perspective(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat depth = 0.0;\nif (cc_shadowNFLSInfo.z > EPSILON) {\ndepth = CCGetLinearDepth(worldPos);\n} else {\ndepth = clipPos.z;\n}\nvec2 oneTap = 1.0 / cc_shadowWHPBInfo.xy;\nvec2 clipPos_offset = clipPos.xy + oneTap;\nfloat block0, block1, block2, block3;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)).x);\nblock1 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos.y)).x);\nblock2 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset.y)).x);\nblock3 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos_offset.y)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * cc_shadowWHPBInfo.x;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block2, block3, coefX);\nfloat coefY = mod(clipPos.y, oneTap.y) * cc_shadowWHPBInfo.y;\nreturn mix(resultX, resultY, coefY);\n}\nfloat CCGetSpotLightShadowFactorSoft2X (vec4 shadowPos, vec3 worldPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Perspective(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat depth = 0.0;\nif (cc_shadowNFLSInfo.z > EPSILON) {\ndepth = CCGetLinearDepth(worldPos);\n} else {\ndepth = clipPos.z;\n}\nvec2 mapSize = cc_shadowWHPBInfo.xy;\nvec2 oneTap = 1.0 / mapSize;\nfloat clipPos_offset_L = clipPos.x - oneTap.x;\nfloat clipPos_offset_R = clipPos.x + oneTap.x;\nfloat clipPos_offset_U = clipPos.y - oneTap.y;\nfloat clipPos_offset_D = clipPos.y + oneTap.y;\nfloat block0, block1, block2, block3, block4, block5, block6, block7, block8;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock4 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock5 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock6 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock7 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock8 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_U)).x);\nblock1 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_U)).x);\nblock2 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_U)).x);\nblock3 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos.y)).x);\nblock4 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)).x);\nblock5 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos.y)).x);\nblock6 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_D)).x);\nblock7 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_D)).x);\nblock8 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_D)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * mapSize.x;\nfloat coefY = mod(clipPos.y, oneTap.y) * mapSize.y;\nfloat shadow = 0.0;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block3, block4, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block1, block2, coefX);\nresultY = mix(block4, block5, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block3, block4, coefX);\nresultY = mix(block6, block7, coefX);\nshadow += mix(resultX, resultY, coefY);\nresultX = mix(block4, block5, coefX);\nresultY = mix(block7, block8, coefX);\nshadow += mix(resultX, resultY, coefY);\nreturn shadow * 0.25;\n}\nfloat CCSpotShadowFactorBase(vec4 shadowPos, vec3 worldPos, vec2 shadowBias)\n{\nfloat pcf = cc_shadowWHPBInfo.z;\nif (pcf > 1.9) {\nreturn CCGetSpotLightShadowFactorSoft2X(shadowPos, worldPos, shadowBias.x);\n}else if (pcf > 0.9) {\nreturn CCGetSpotLightShadowFactorSoft(shadowPos, worldPos, shadowBias.x);\n}else {\nreturn CCGetSpotLightShadowFactorHard(shadowPos, worldPos, shadowBias.x);\n}\n}\nfloat CCShadowFactorBase(vec4 shadowPos, vec3 N, vec2 shadowBias)\n{\nfloat realtimeShadow = 1.0;\nvec4 pos = ApplyShadowDepthBias_FaceNormal(shadowPos, N, shadowBias.y);\nfloat pcf = cc_shadowWHPBInfo.z;\nif (pcf > 1.9) {\nrealtimeShadow = CCGetShadowFactorSoft2X(pos, shadowBias.x);\n}else if (pcf > 0.9) {\nrealtimeShadow = CCGetShadowFactorSoft(pos, shadowBias.x);\n}else {\nrealtimeShadow = CCGetShadowFactorHard(pos, shadowBias.x);\n}\nreturn mix(realtimeShadow, 1.0, cc_shadowNFLSInfo.w);\n}\n#endif\n#if CC_USE_IBL\nuniform samplerCube cc_environment;\nvec4 fragTextureLod (sampler2D tex, vec2 coord, float lod) {\n#ifdef GL_EXT_shader_texture_lod\nreturn texture2DLodEXT(tex, coord, lod);\n#else\nreturn texture2D(tex, coord, lod);\n#endif\n}\nvec4 fragTextureLod (samplerCube tex, vec3 coord, float lod) {\n#ifdef GL_EXT_shader_texture_lod\nreturn textureCubeLodEXT(tex, coord, lod);\n#else\nreturn textureCube(tex, coord, lod);\n#endif\n}\nvec3 unpackRGBE (vec4 rgbe) {\nreturn rgbe.rgb * pow(1.1, rgbe.a * 255.0 - 128.0);\n}\n#if CC_USE_DIFFUSEMAP\nuniform samplerCube cc_diffuseMap;\n#endif\n#endif\nfloat GGXMobile (float roughness, float NoH, vec3 H, vec3 N) {\nvec3 NxH = cross(N, H);\nfloat OneMinusNoHSqr = dot(NxH, NxH);\nfloat a = roughness * roughness;\nfloat n = NoH * a;\nfloat p = a / (OneMinusNoHSqr + n * n);\nreturn p * p;\n}\nfloat CalcSpecular (float roughness, float NoH, vec3 H, vec3 N) {\nreturn (roughness * 0.25 + 0.25) * GGXMobile(roughness, NoH, H, N);\n}\nvec3 BRDFApprox (vec3 specular, float roughness, float NoV) {\nconst vec4 c0 = vec4(-1.0, -0.0275, -0.572, 0.022);\nconst vec4 c1 = vec4(1.0, 0.0425, 1.04, -0.04);\nvec4 r = roughness * c0 + c1;\nfloat a004 = min(r.x * r.x, exp2(-9.28 * NoV)) * r.x + r.y;\nvec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;\nAB.y *= clamp(50.0 * specular.g, 0.0, 1.0);\nreturn specular * AB.x + AB.y;\n}\n#if USE_REFLECTION_DENOISE\nvec3 GetEnvReflectionWithMipFiltering(vec3 R, float roughness, float mipCount, float denoiseIntensity) {\n#if CC_USE_IBL\nfloat mip = roughness * mipCount;\nfloat delta = (dot(dFdx(R), dFdy(R))) * 1000.0;\nfloat mipBias = mix(0.0, 5.0, clamp(delta, 0.0, 1.0));\nvec4 biased = fragTextureLod(cc_environment, R, mip + mipBias);\nvec4 filtered = textureCube(cc_environment, R);\n#if CC_USE_IBL == 2\nbiased.rgb = unpackRGBE(biased);\nfiltered.rgb = unpackRGBE(filtered);\n#else\nbiased.rgb = SRGBToLinear(biased.rgb);\nfiltered.rgb = SRGBToLinear(filtered.rgb);\n#endif\nreturn mix(biased.rgb, filtered.rgb, denoiseIntensity);\n#else\nreturn vec3(0.0, 0.0, 0.0);\n#endif\n}\n#endif\nstruct StandardSurface {\nvec4 albedo;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nvec3 position, position_fract_part;\n#else\nvec3 position;\n#endif\nvec3 normal;\nvec3 emissive;\nvec3 lightmap;\nfloat lightmap_test;\nfloat roughness;\nfloat metallic;\nfloat occlusion;\nfloat specularIntensity;\n#if CC_RECEIVE_SHADOW\nvec2 shadowBias;\n#endif\n};\nvec4 CCStandardShadingBase (StandardSurface s, vec4 shadowPos) {\nvec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\nvec3 specular = mix(vec3(0.08 * s.specularIntensity), s.albedo.rgb, s.metallic);\nvec3 position;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nposition = unpackHighpData(s.position, s.position_fract_part);\n#else\nposition = s.position;\n#endif\nvec3 N = normalize(s.normal);\nvec3 V = normalize(cc_cameraPos.xyz - position);\nfloat NV = max(abs(dot(N, V)), 0.0);\nspecular = BRDFApprox(specular, s.roughness, NV);\nvec3 L = normalize(-cc_mainLitDir.xyz);\nvec3 H = normalize(L + V);\nfloat NH = max(dot(N, H), 0.0);\nfloat NL = max(dot(N, L), 0.0);\nvec3 finalColor = NL * cc_mainLitColor.rgb * cc_mainLitColor.w;\nvec3 diffuseContrib = diffuse / PI;\nvec3 specularContrib = specular * CalcSpecular(s.roughness, NH, H, N);\nvec3 dirlightContrib = (diffuseContrib + specularContrib);\nfloat shadow = 1.0;\n#if CC_RECEIVE_SHADOW\nif (NL > 0.0 && cc_mainLitDir.w > 0.0) {\nshadow = CCShadowFactorBase(shadowPos, N, s.shadowBias);\n}\n#endif\ndirlightContrib *= shadow;\nfinalColor *= dirlightContrib;\n#if USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\nif (s.lightmap_test > EPSILON_LOWP) {\nfinalColor = diffuse * s.lightmap.rgb * shadow;\n}\n#endif\nfloat fAmb = 0.5 - N.y * 0.5;\nvec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb);\n#if CC_USE_IBL\n#if CC_USE_DIFFUSEMAP\nvec4 diffuseMap = textureCube(cc_diffuseMap, N);\n#if CC_USE_DIFFUSEMAP == 2\nambDiff = unpackRGBE(diffuseMap);\n#else\nambDiff = SRGBToLinear(diffuseMap.rgb);\n#endif\n#endif\nvec3 R = normalize(reflect(-V, N));\n#if USE_REFLECTION_DENOISE\nvec3 env = GetEnvReflectionWithMipFiltering(R, s.roughness, cc_ambientGround.w, 0.6);\n#else\nvec4 envmap = fragTextureLod(cc_environment, R, s.roughness * cc_ambientGround.w);\n#if CC_USE_IBL == 2\nvec3 env = unpackRGBE(envmap);\n#else\nvec3 env = SRGBToLinear(envmap.rgb);\n#endif\n#endif\nfinalColor += env * cc_ambientSky.w * specular * s.occlusion;\n#endif\nfinalColor += ambDiff.rgb * cc_ambientSky.w * diffuse * s.occlusion;\nfinalColor += s.emissive;\nreturn vec4(finalColor, s.albedo.a);\n}\nvec3 ACESToneMap (vec3 color) {\ncolor = min(color, vec3(8.0));\nconst float A = 2.51;\nconst float B = 0.03;\nconst float C = 2.43;\nconst float D = 0.59;\nconst float E = 0.14;\nreturn (color * (A * color + B)) / (color * (C * color + D) + E);\n}\nvec4 CCFragOutput (vec4 color) {\n#if CC_USE_HDR\ncolor.rgb = ACESToneMap(color.rgb);\n#endif\ncolor.rgb = sqrt(color.rgb);\nreturn color;\n}\nvarying highp vec4 v_shadowPos;\n#if CC_RECEIVE_SHADOW\n#endif\n#if USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\nvarying vec3 v_luv;\nuniform sampler2D cc_lightingMap;\n#endif\nvarying vec3 v_position;\nvarying vec2 v_uv;\n#if HAS_SECOND_UV\nvarying mediump vec2 v_uv1;\n#endif\nvarying mediump vec3 v_normal;\n#if CC_RECEIVE_SHADOW\nvarying mediump vec2 v_shadowBias;\n#endif\n#if USE_VERTEX_COLOR\nvarying lowp vec4 v_color;\n#endif\n#if USE_ALBEDO_MAP\nuniform sampler2D albedoMap;\n#endif\n#if USE_NORMAL_MAP\nvarying mediump vec4 v_tangent;\nuniform sampler2D normalMap;\n#endif\n#if USE_PBR_MAP\nuniform sampler2D pbrMap;\n#endif\n#if USE_METALLIC_ROUGHNESS_MAP\nuniform sampler2D metallicRoughnessMap;\n#endif\n#if USE_OCCLUSION_MAP\nuniform sampler2D occlusionMap;\n#endif\n#if USE_EMISSIVE_MAP\nuniform sampler2D emissiveMap;\n#endif\n#if USE_ALPHA_TEST\n#endif\nvoid surf (out StandardSurface s) {\nvec4 baseColor = albedo;\n#if USE_VERTEX_COLOR\nbaseColor.rgb *= SRGBToLinear(v_color.rgb);\nbaseColor.a *= v_color.a;\n#endif\n#if USE_ALBEDO_MAP\nvec4 texColor = texture2D(albedoMap, ALBEDO_UV);\ntexColor.rgb = SRGBToLinear(texColor.rgb);\nbaseColor *= texColor;\n#endif\ns.albedo = baseColor;\ns.albedo.rgb *= albedoScaleAndCutoff.xyz;\n#if USE_ALPHA_TEST\nif (s.albedo.ALPHA_TEST_CHANNEL < albedoScaleAndCutoff.w) discard;\n#endif\n#if USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\nvec4 lightColor = texture2D(cc_lightingMap, v_luv.xy);\ns.lightmap = lightColor.xyz * v_luv.z;\ns.lightmap_test = v_luv.z;\n#endif\ns.normal = v_normal;\n#if CC_RECEIVE_SHADOW\ns.shadowBias = v_shadowBias;\n#endif\n#if USE_NORMAL_MAP\nvec3 nmmp = texture2D(normalMap, NORMAL_UV).xyz - vec3(0.5);\nvec3 bitangent = cross(v_normal, v_tangent.xyz) * v_tangent.w;\ns.normal =\n(nmmp.x * emissiveScaleParam.w) * normalize(v_tangent.xyz) +\n(nmmp.y * emissiveScaleParam.w) * normalize(bitangent) +\nnmmp.z * normalize(s.normal);\n#endif\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\npackHighpData(s.position, s.position_fract_part, v_position);\n#else\ns.position = v_position;\n#endif\nvec4 pbr = pbrParams;\n#if USE_PBR_MAP\nvec4 res = texture2D(pbrMap, PBR_UV);\npbr.x *= res.r;\npbr.y *= res.g;\npbr.z *= res.b;\npbr.w *= res.a;\n#endif\n#if USE_METALLIC_ROUGHNESS_MAP\nvec4 metallicRoughness = texture2D(metallicRoughnessMap, PBR_UV);\npbr.z *= metallicRoughness.b;\npbr.y *= metallicRoughness.g;\n#endif\n#if USE_OCCLUSION_MAP\npbr.x *= texture2D(occlusionMap, PBR_UV).r;\n#endif\ns.occlusion = pbr.x;\ns.roughness = pbr.y;\ns.specularIntensity = 0.5;\ns.metallic = pbr.z;\ns.emissive = emissive.rgb * emissiveScaleParam.xyz;\n#if USE_EMISSIVE_MAP\ns.emissive *= SRGBToLinear(texture2D(emissiveMap, EMISSIVE_UV).rgb);\n#endif\n}\n#if CC_FORWARD_ADD\n#if CC_PIPELINE_TYPE == 0\n#define LIGHTS_PER_PASS 1\n#else\n#define LIGHTS_PER_PASS 10\n#endif\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 0\nuniform highp vec4 cc_lightPos[LIGHTS_PER_PASS];\nuniform vec4 cc_lightColor[LIGHTS_PER_PASS];\nuniform vec4 cc_lightSizeRangeAngle[LIGHTS_PER_PASS];\nuniform vec4 cc_lightDir[LIGHTS_PER_PASS];\n#endif\nfloat SmoothDistAtt (float distSqr, float invSqrAttRadius) {\nfloat factor = distSqr * invSqrAttRadius;\nfloat smoothFactor = clamp(1.0 - factor * factor, 0.0, 1.0);\nreturn smoothFactor * smoothFactor;\n}\nfloat GetDistAtt (float distSqr, float invSqrAttRadius) {\nfloat attenuation = 1.0 / max(distSqr, 0.01*0.01);\nattenuation *= SmoothDistAtt(distSqr , invSqrAttRadius);\nreturn attenuation;\n}\nfloat GetAngleAtt (vec3 L, vec3 litDir, float litAngleScale, float litAngleOffset) {\nfloat cd = dot(litDir, L);\nfloat attenuation = clamp(cd * litAngleScale + litAngleOffset, 0.0, 1.0);\nreturn (attenuation * attenuation);\n}\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 0\nvec4 CCStandardShadingAdditive (StandardSurface s, vec4 shadowPos) {\nvec3 position;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nposition = unpackHighpData(s.position, s.position_fract_part);\n#else\nposition = s.position;\n#endif\nvec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\nvec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\nvec3 diffuseContrib = diffuse / PI;\nvec3 N = normalize(s.normal);\nvec3 V = normalize(cc_cameraPos.xyz - position);\nfloat NV = max(abs(dot(N, V)), 0.0);\nspecular = BRDFApprox(specular, s.roughness, NV);\nvec3 finalColor = vec3(0.0);\nint numLights = CC_PIPELINE_TYPE == 0 ? LIGHTS_PER_PASS : int(cc_lightDir[0].w);\nfor (int i = 0; i < LIGHTS_PER_PASS; i++) {\nif (i >= numLights) break;\nvec3 SLU = cc_lightPos[i].xyz - position;\nvec3 SL = normalize(SLU);\nvec3 SH = normalize(SL + V);\nfloat SNL = max(dot(N, SL), 0.0);\nfloat SNH = max(dot(N, SH), 0.0);\nfloat distSqr = dot(SLU, SLU);\nfloat litRadius = cc_lightSizeRangeAngle[i].x;\nfloat litRadiusSqr = litRadius * litRadius;\nfloat illum = litRadiusSqr / max(litRadiusSqr, distSqr);\nfloat attRadiusSqrInv = 1.0 / max(cc_lightSizeRangeAngle[i].y, 0.01);\nattRadiusSqrInv *= attRadiusSqrInv;\nfloat att = GetDistAtt(distSqr, attRadiusSqrInv);\nvec3 lspec = specular * CalcSpecular(s.roughness, SNH, SH, N);\nif (cc_lightPos[i].w > 0.0) {\nfloat cosInner = max(dot(-cc_lightDir[i].xyz, SL), 0.01);\nfloat cosOuter = cc_lightSizeRangeAngle[i].z;\nfloat litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\nfloat litAngleOffset = -cosOuter * litAngleScale;\natt *= GetAngleAtt(SL, -cc_lightDir[i].xyz, litAngleScale, litAngleOffset);\n}\nvec3 lightColor = cc_lightColor[i].rgb;\nfloat shadow = 1.0;\n#if CC_RECEIVE_SHADOW\nif (cc_lightPos[i].w > 0.0 && cc_lightSizeRangeAngle[i].w > 0.0) {\nshadow = CCSpotShadowFactorBase(shadowPos, position, s.shadowBias);\n}\n#endif\nlightColor *= shadow;\nfinalColor += SNL * lightColor * cc_lightColor[i].w * illum * att * (diffuseContrib + lspec);\n}\nreturn vec4(finalColor, 0.0);\n}\n#endif\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 1\nreadonly buffer b_ccLightsBuffer { vec4 b_ccLights[]; };\nreadonly buffer b_clusterLightIndicesBuffer { uint b_clusterLightIndices[]; };\nreadonly buffer b_clusterLightGridBuffer { uvec4 b_clusterLightGrid[]; };\nstruct CCLight\n{\nvec4 cc_lightPos;\nvec4 cc_lightColor;\nvec4 cc_lightSizeRangeAngle;\nvec4 cc_lightDir;\n};\nstruct Cluster\n{\nvec3 minBounds;\nvec3 maxBounds;\n};\nstruct LightGrid\n{\nuint offset;\nuint ccLights;\n};\nCCLight getCCLight(uint i)\n{\nCCLight light;\nlight.cc_lightPos = b_ccLights[4u * i + 0u];\nlight.cc_lightColor = b_ccLights[4u * i + 1u];\nlight.cc_lightSizeRangeAngle = b_ccLights[4u * i + 2u];\nlight.cc_lightDir = b_ccLights[4u * i + 3u];\nreturn light;\n}\nLightGrid getLightGrid(uint cluster)\n{\nuvec4 gridvec = b_clusterLightGrid[cluster];\nLightGrid grid;\ngrid.offset = gridvec.x;\ngrid.ccLights = gridvec.y;\nreturn grid;\n}\nuint getGridLightIndex(uint start, uint offset)\n{\nreturn b_clusterLightIndices[start + offset];\n}\nuint getClusterZIndex(vec4 worldPos)\n{\nfloat scale = float(24) / log(cc_nearFar.y / cc_nearFar.x);\nfloat bias = -(float(24) * log(cc_nearFar.x) / log(cc_nearFar.y / cc_nearFar.x));\nfloat eyeDepth = -(cc_matView * worldPos).z;\nuint zIndex = uint(max(log(eyeDepth) * scale + bias, 0.0));\nreturn zIndex;\n}\nuint getClusterIndex(vec4 fragCoord, vec4 worldPos)\n{\nuint zIndex = getClusterZIndex(worldPos);\nfloat clusterSizeX = ceil(cc_viewPort.z / float(16));\nfloat clusterSizeY = ceil(cc_viewPort.w / float(8));\nuvec3 indices = uvec3(uvec2(fragCoord.xy / vec2(clusterSizeX, clusterSizeY)), zIndex);\nuint cluster = (16u * 8u) * indices.z + 16u * indices.y + indices.x;\nreturn cluster;\n}\nvec4 CCClusterShadingAdditive (StandardSurface s, vec4 shadowPos) {\nvec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\nvec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\nvec3 diffuseContrib = diffuse / PI;\nvec3 position;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nposition = unpackHighpData(s.position, s.position_fract_part);\n#else\nposition = s.position;\n#endif\nvec3 N = normalize(s.normal);\nvec3 V = normalize(cc_cameraPos.xyz - position);\nfloat NV = max(abs(dot(N, V)), 0.001);\nspecular = BRDFApprox(specular, s.roughness, NV);\nvec3 finalColor = vec3(0.0);\nuint cluster = getClusterIndex(gl_FragCoord, vec4(position, 1.0));\nLightGrid grid = getLightGrid(cluster);\nuint numLights = grid.ccLights;\nfor (uint i = 0u; i < 100u; i++) {\nif (i >= numLights) break;\nuint lightIndex = getGridLightIndex(grid.offset, i);\nCCLight light = getCCLight(lightIndex);\nvec3 SLU = light.cc_lightPos.xyz - position;\nvec3 SL = normalize(SLU);\nvec3 SH = normalize(SL + V);\nfloat SNL = max(dot(N, SL), 0.001);\nfloat SNH = max(dot(N, SH), 0.0);\nfloat distSqr = dot(SLU, SLU);\nfloat litRadius = light.cc_lightSizeRangeAngle.x;\nfloat litRadiusSqr = litRadius * litRadius;\nfloat illum = PI * (litRadiusSqr / max(litRadiusSqr , distSqr));\nfloat attRadiusSqrInv = 1.0 / max(light.cc_lightSizeRangeAngle.y, 0.01);\nattRadiusSqrInv *= attRadiusSqrInv;\nfloat att = GetDistAtt(distSqr, attRadiusSqrInv);\nvec3 lspec = specular * CalcSpecular(s.roughness, SNH, SH, N);\nif (light.cc_lightPos.w > 0.0) {\nfloat cosInner = max(dot(-light.cc_lightDir.xyz, SL), 0.01);\nfloat cosOuter = light.cc_lightSizeRangeAngle.z;\nfloat litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\nfloat litAngleOffset = -cosOuter * litAngleScale;\natt *= GetAngleAtt(SL, -light.cc_lightDir.xyz, litAngleScale, litAngleOffset);\n}\nvec3 lightColor = light.cc_lightColor.rgb;\nfloat shadow = 1.0;\n#if CC_RECEIVE_SHADOW\nif (light.cc_lightPos.w > 0.0) {\nshadow = CCSpotShadowFactorBase(shadowPos, position, s.shadowBias);\n}\n#endif\nlightColor *= shadow;\nfinalColor += SNL * lightColor * light.cc_lightColor.w * illum * att * (diffuseContrib + lspec);\n}\nreturn vec4(finalColor, 0.0);\n}\n#endif\nvoid main () {\nStandardSurface s; surf(s);\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 1\nvec4 color = CCClusterShadingAdditive(s, v_shadowPos);\n#else\nvec4 color = CCStandardShadingAdditive(s, v_shadowPos);\n#endif\ngl_FragData[0] = CCFragOutput(color);\n}\n#elif (CC_PIPELINE_TYPE == 0 || CC_FORCE_FORWARD_SHADING)\nvoid main () {\nStandardSurface s; surf(s);\nvec4 color = CCStandardShadingBase(s, v_shadowPos);\nCC_APPLY_FOG(color, s.position.xyz);\ngl_FragData[0] = CCFragOutput(color);\n}\n#elif CC_PIPELINE_TYPE == 1\nvec2 signNotZero(vec2 v) {\nreturn vec2((v.x >= 0.0) ? +1.0 : -1.0, (v.y >= 0.0) ? +1.0 : -1.0);\n}\nvec2 float32x3_to_oct(in vec3 v) {\nvec2 p = v.xy * (1.0 / (abs(v.x) + abs(v.y) + abs(v.z)));\nreturn (v.z <= 0.0) ? ((1.0 - abs(p.yx)) * signNotZero(p)) : p;\n}\nvoid main () {\nStandardSurface s; surf(s);\ngl_FragData[0] = s.albedo;\ngl_FragData[1] = vec4(float32x3_to_oct(s.normal), s.roughness, s.metallic);\ngl_FragData[2] = vec4(s.emissive, s.occlusion);\n}\n#endif", + "vert": "\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\nrgba = rgba * 255.0;\nhighp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\nhighp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\nhighp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\nreturn Sign * exp2(Exponent - 23.0) * Mantissa;\n}\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nattribute vec3 a_position;\nattribute vec3 a_normal;\nattribute vec2 a_texCoord;\nattribute vec4 a_tangent;\n#if CC_USE_SKINNING\nattribute vec4 a_joints;\nattribute vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nattribute highp vec4 a_jointAnimInfo;\n#endif\nattribute vec4 a_matWorld0;\nattribute vec4 a_matWorld1;\nattribute vec4 a_matWorld2;\n#if CC_USE_LIGHTMAP\nattribute vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nattribute vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nattribute float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nattribute float a_vertexId;\nint getVertexId() {\nreturn int(a_vertexId);\n}\n#endif\n#if CC_USE_MORPH\nuniform vec4 cc_displacementWeights[15];\nuniform vec4 cc_displacementTextureInfo;\nvec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\nfloat pixelIndexF = float(pixelIndex);\nfloat x = mod(pixelIndexF, textureResolution.x);\nfloat y = floor(pixelIndexF / textureResolution.x);\nreturn vec2(x, y);\n}\nvec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\nreturn (vec2(location.x, location.y) + .5) / textureResolution;\n}\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 uv = getPixelCoordFromLocation(location, cc_displacementTextureInfo.xy);\nreturn texture2D(tex, uv);\n}\n#else\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex * 4;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\nreturn vec4(\ndecode32(texture2D(tex, x)),\ndecode32(texture2D(tex, y)),\ndecode32(texture2D(tex, z)),\n1.0\n);\n}\n#endif\nfloat getDisplacementWeight(int index) {\nint quot = index / 4;\nint remainder = index - quot * 4;\nif (remainder == 0) {\nreturn cc_displacementWeights[quot].x;\n} else if (remainder == 1) {\nreturn cc_displacementWeights[quot].y;\n} else if (remainder == 2) {\nreturn cc_displacementWeights[quot].z;\n} else {\nreturn cc_displacementWeights[quot].w;\n}\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\nreturn fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n#else\nvec3 result = vec3(0, 0, 0);\nint nVertices = int(cc_displacementTextureInfo.z);\nfor (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\nresult += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n}\nreturn result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\nuniform sampler2D cc_PositionDisplacements;\nvec3 getPositionDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nuniform sampler2D cc_NormalDisplacements;\nvec3 getNormalDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\nuniform sampler2D cc_TangentDisplacements;\nvec3 getTangentDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n}\n#endif\nvoid applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nint vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nnormal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\ntangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\n#if CC_USE_BAKED_ANIMATION\nuniform highp vec4 cc_jointTextureInfo;\nuniform highp vec4 cc_jointAnimInfo;\nuniform highp sampler2D cc_jointTexture;\nvoid CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n{\n#if USE_INSTANCING\nhighp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n#else\nhighp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n#endif\ninvSize = cc_jointTextureInfo.w;\nhighp float tempY = floor(temp * invSize);\nx = floor(temp - tempY * cc_jointTextureInfo.x);\ny = (tempY + 0.5) * invSize;\n}\n#else\nuniform highp vec4 cc_joints[90];\n#endif\n#if CC_USE_BAKED_ANIMATION\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(3.0, i, x, y, invSize);\nvec4 v1 = texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y));\nvec4 v2 = texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y));\nvec4 v3 = texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y));\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#else\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(12.0, i, x, y, invSize);\nvec4 v1 = vec4(\ndecode32(texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n);\nvec4 v2 = vec4(\ndecode32(texture2D(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n);\nvec4 v3 = vec4(\ndecode32(texture2D(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n);\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\n#else\nmat4 getJointMatrix (float i) {\nint idx = int(i);\nvec4 v1 = cc_joints[idx * 3];\nvec4 v2 = cc_joints[idx * 3 + 1];\nvec4 v3 = cc_joints[idx * 3 + 2];\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\nmat4 skinMatrix () {\nvec4 joints = vec4(a_joints);\nreturn getJointMatrix(joints.x) * a_weights.x\n+ getJointMatrix(joints.y) * a_weights.y\n+ getJointMatrix(joints.z) * a_weights.z\n+ getJointMatrix(joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\nmat4 m = skinMatrix();\nposition = m * position;\n}\nvoid CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nmat4 m = skinMatrix();\nposition = m * position;\nnormal = (m * vec4(normal, 0.0)).xyz;\ntangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n}\n#endif\nvoid CCVertInput(inout StandardVertInput In)\n{\nIn.position = vec4(a_position, 1.0);\nIn.normal = a_normal;\nIn.tangent = a_tangent;\n#if CC_USE_MORPH\napplyMorph(In.position, In.normal, In.tangent);\n#endif\n#if CC_USE_SKINNING\nCCSkin(In.position, In.normal, In.tangent);\n#endif\n}\nuniform highp mat4 cc_matView;\nuniform highp mat4 cc_matProj;\nuniform highp vec4 cc_cameraPos;\nuniform mediump vec4 cc_fogBase;\nuniform mediump vec4 cc_fogAdd;\n#if !USE_INSTANCING\n#if USE_BATCHING\nuniform highp mat4 cc_matWorlds[10];\n#else\nuniform highp mat4 cc_matWorld;\nuniform highp mat4 cc_matWorldIT;\nuniform highp vec4 cc_lightingMapUVParam;\nuniform highp vec4 cc_localShadowBias;\n#endif\n#endif\nvoid CCGetWorldMatrixFull(out mat4 matWorld, out mat4 matWorldIT)\n{\n#if USE_INSTANCING\nmatWorld = mat4(\nvec4(a_matWorld0.xyz, 0.0),\nvec4(a_matWorld1.xyz, 0.0),\nvec4(a_matWorld2.xyz, 0.0),\nvec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)\n);\nmatWorldIT = matWorld;\n#elif USE_BATCHING\nmatWorld = cc_matWorlds[int(a_dyn_batch_id)];\nmatWorldIT = matWorld;\n#else\nmatWorld = cc_matWorld;\nmatWorldIT = cc_matWorldIT;\n#endif\n}\nuniform vec4 tilingOffset;\nfloat LinearFog(vec4 pos) {\nvec4 wPos = pos;\nfloat cam_dis = distance(cc_cameraPos, wPos);\nfloat fogStart = cc_fogBase.x;\nfloat fogEnd = cc_fogBase.y;\nreturn clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * fogDensity);\nreturn f;\n}\nfloat ExpSquaredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\nreturn f;\n}\nfloat LayeredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat _FogTop = cc_fogAdd.x;\nfloat _FogRange = cc_fogAdd.y;\nvec3 camWorldProj = cc_cameraPos.xyz;\ncamWorldProj.y = 0.;\nvec3 worldPosProj = wPos.xyz;\nworldPosProj.y = 0.;\nfloat fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\nfloat fDeltaY, fDensityIntegral;\nif (cc_cameraPos.y > _FogTop) {\nif (wPos.y < _FogTop) {\nfDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\nfDensityIntegral = fDeltaY * fDeltaY * 0.5;\n} else {\nfDeltaY = 0.;\nfDensityIntegral = 0.;\n}\n} else {\nif (wPos.y < _FogTop) {\nfloat fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfloat fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\nfDeltaY = abs(fDeltaA - fDeltaB);\nfDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n} else {\nfDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n}\n}\nfloat fDensity;\nif (fDeltaY != 0.) {\nfDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n} else {\nfDensity = 0.;\n}\nfloat f = exp(-fDensity);\nreturn f;\n}\nvoid CC_TRANSFER_FOG_BASE(vec4 pos, out float factor)\n{\n#if CC_USE_FOG == 0\nfactor = LinearFog(pos);\n#elif CC_USE_FOG == 1\nfactor = ExpFog(pos);\n#elif CC_USE_FOG == 2\nfactor = ExpSquaredFog(pos);\n#elif CC_USE_FOG == 3\nfactor = LayeredFog(pos);\n#else\nfactor = 1.0;\n#endif\n}\n#if !CC_USE_ACCURATE_FOG\nvarying float v_fog_factor;\n#endif\nvoid CC_TRANSFER_FOG(vec4 pos) {\n#if !CC_USE_ACCURATE_FOG\nCC_TRANSFER_FOG_BASE(pos, v_fog_factor);\n#endif\n}\nvarying highp vec4 v_shadowPos;\nuniform highp mat4 cc_matLightViewProj;\nuniform mediump vec4 cc_shadowWHPBInfo;\nuniform mediump vec4 cc_shadowLPNNInfo;\n#if CC_RECEIVE_SHADOW\nuniform highp sampler2D cc_shadowMap;\nuniform highp sampler2D cc_spotLightingMap;\n#endif\n#if CC_RECEIVE_SHADOW\nvec2 CCGetShadowBias()\n{\n#if USE_INSTANCING\nreturn vec2(a_localShadowBias.x + cc_shadowWHPBInfo.w, a_localShadowBias.y + cc_shadowLPNNInfo.z);\n#elif !USE_BATCHING\nreturn vec2(cc_localShadowBias.x + cc_shadowWHPBInfo.w, cc_localShadowBias.y + cc_shadowLPNNInfo.z);\n#else\nreturn vec2(cc_shadowWHPBInfo.w, cc_shadowLPNNInfo.z);\n#endif\n}\n#endif\n#if USE_VERTEX_COLOR\nattribute vec4 a_color;\nvarying lowp vec4 v_color;\n#endif\nvarying vec3 v_position;\nvarying mediump vec3 v_normal;\nvarying vec2 v_uv;\n#if HAS_SECOND_UV\nvarying mediump vec2 v_uv1;\n#endif\n#if CC_RECEIVE_SHADOW\nvarying mediump vec2 v_shadowBias;\n#endif\n#if USE_NORMAL_MAP\nvarying mediump vec4 v_tangent;\n#endif\n#if HAS_SECOND_UV || CC_USE_LIGHTMAP\nattribute vec2 a_texCoord1;\n#endif\n#if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\nvarying vec3 v_luv;\nvoid CCLightingMapCaclUV()\n{\n#if !USE_INSTANCING\nv_luv.xy = cc_lightingMapUVParam.xy + a_texCoord1 * cc_lightingMapUVParam.z;\nv_luv.z = cc_lightingMapUVParam.w;\n#else\nv_luv.xy = a_lightingMapUVParam.xy + a_texCoord1 * a_lightingMapUVParam.z;\nv_luv.z = a_lightingMapUVParam.w;\n#endif\n}\n#endif\nvoid main () {\nStandardVertInput In;\nCCVertInput(In);\nmat4 matWorld, matWorldIT;\nCCGetWorldMatrixFull(matWorld, matWorldIT);\nvec4 pos = matWorld * In.position;\nv_position = pos.xyz;\nv_normal = normalize((matWorldIT * vec4(In.normal, 0.0)).xyz);\n#if CC_RECEIVE_SHADOW\nv_shadowBias = CCGetShadowBias();\n#endif\n#if USE_TWOSIDE\nvec3 viewDirect = normalize(cc_cameraPos.xyz - v_position);\nv_normal *= dot(v_normal, viewDirect) < 0.0 ? -1.0 : 1.0;\n#endif\n#if USE_NORMAL_MAP\nv_tangent.xyz = normalize((matWorld * vec4(In.tangent.xyz, 0.0)).xyz);\nv_tangent.w = In.tangent.w;\n#endif\nv_uv = a_texCoord * tilingOffset.xy + tilingOffset.zw;\n#if SAMPLE_FROM_RT\nv_uv = cc_cameraPos.w > 1.0 ? vec2(v_uv.x, 1.0 - v_uv.y) : v_uv;\n#endif\n#if HAS_SECOND_UV\nv_uv1 = a_texCoord1 * tilingOffset.xy + tilingOffset.zw;\n#if SAMPLE_FROM_RT\nv_uv1 = cc_cameraPos.w > 1.0 ? vec2(v_uv1.x, 1.0 - v_uv1.y) : v_uv1;\n#endif\n#endif\n#if USE_VERTEX_COLOR\nv_color = a_color;\n#endif\nCC_TRANSFER_FOG(pos);\nv_shadowPos = cc_matLightViewProj * pos;\n#if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\nCCLightingMapCaclUV();\n#endif\ngl_Position = cc_matProj * (cc_matView * matWorld) * In.position;\n}", + "frag": "\n#ifdef GL_EXT_draw_buffers\n#extension GL_EXT_draw_buffers: enable\n#endif\n#ifdef GL_OES_standard_derivatives\n#extension GL_OES_standard_derivatives: enable\n#endif\n#ifdef GL_EXT_shader_texture_lod\n#extension GL_EXT_shader_texture_lod: enable\n#endif\nprecision highp float;\nuniform highp mat4 cc_matView;\nuniform highp vec4 cc_cameraPos;\nuniform mediump vec4 cc_mainLitDir;\nuniform mediump vec4 cc_mainLitColor;\nuniform mediump vec4 cc_ambientSky;\nuniform mediump vec4 cc_ambientGround;\nuniform mediump vec4 cc_fogColor;\nuniform mediump vec4 cc_fogBase;\nuniform mediump vec4 cc_fogAdd;\nuniform mediump vec4 cc_nearFar;\nuniform mediump vec4 cc_viewPort;\nuniform vec4 albedo;\nuniform vec4 albedoScaleAndCutoff;\nuniform vec4 pbrParams;\nuniform vec4 emissive;\nuniform vec4 emissiveScaleParam;\nfloat LinearFog(vec4 pos) {\nvec4 wPos = pos;\nfloat cam_dis = distance(cc_cameraPos, wPos);\nfloat fogStart = cc_fogBase.x;\nfloat fogEnd = cc_fogBase.y;\nreturn clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * fogDensity);\nreturn f;\n}\nfloat ExpSquaredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\nreturn f;\n}\nfloat LayeredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat _FogTop = cc_fogAdd.x;\nfloat _FogRange = cc_fogAdd.y;\nvec3 camWorldProj = cc_cameraPos.xyz;\ncamWorldProj.y = 0.;\nvec3 worldPosProj = wPos.xyz;\nworldPosProj.y = 0.;\nfloat fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\nfloat fDeltaY, fDensityIntegral;\nif (cc_cameraPos.y > _FogTop) {\nif (wPos.y < _FogTop) {\nfDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\nfDensityIntegral = fDeltaY * fDeltaY * 0.5;\n} else {\nfDeltaY = 0.;\nfDensityIntegral = 0.;\n}\n} else {\nif (wPos.y < _FogTop) {\nfloat fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfloat fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\nfDeltaY = abs(fDeltaA - fDeltaB);\nfDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n} else {\nfDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n}\n}\nfloat fDensity;\nif (fDeltaY != 0.) {\nfDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n} else {\nfDensity = 0.;\n}\nfloat f = exp(-fDensity);\nreturn f;\n}\nvoid CC_TRANSFER_FOG_BASE(vec4 pos, out float factor)\n{\n#if CC_USE_FOG == 0\nfactor = LinearFog(pos);\n#elif CC_USE_FOG == 1\nfactor = ExpFog(pos);\n#elif CC_USE_FOG == 2\nfactor = ExpSquaredFog(pos);\n#elif CC_USE_FOG == 3\nfactor = LayeredFog(pos);\n#else\nfactor = 1.0;\n#endif\n}\nvoid CC_APPLY_FOG_BASE(inout vec4 color, float factor) {\ncolor = vec4(mix(cc_fogColor.rgb, color.rgb, factor), color.a);\n}\n#if !CC_USE_ACCURATE_FOG\nvarying float v_fog_factor;\n#endif\nvoid CC_APPLY_FOG(inout vec4 color) {\n#if !CC_USE_ACCURATE_FOG\nCC_APPLY_FOG_BASE(color, v_fog_factor);\n#endif\n}\nvoid CC_APPLY_FOG(inout vec4 color, vec3 worldPos) {\n#if CC_USE_ACCURATE_FOG\nfloat factor;\nCC_TRANSFER_FOG_BASE(vec4(worldPos, 1.0), factor);\n#else\nfloat factor = v_fog_factor;\n#endif\nCC_APPLY_FOG_BASE(color, factor);\n}\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nvec3 SRGBToLinear (vec3 gamma) {\nreturn gamma * gamma;\n}\nuniform highp mat4 cc_matLightView;\nuniform highp vec4 cc_shadowInvProjDepthInfo;\nuniform highp vec4 cc_shadowProjDepthInfo;\nuniform highp vec4 cc_shadowProjInfo;\nuniform mediump vec4 cc_shadowNFLSInfo;\nuniform mediump vec4 cc_shadowWHPBInfo;\nuniform mediump vec4 cc_shadowLPNNInfo;\nhighp float unpackHighpData (float mainPart, float modPart) {\nhighp float data = mainPart;\nreturn data + modPart;\n}\nvoid packHighpData (out float mainPart, out float modPart, highp float data) {\nmainPart = fract(data);\nmodPart = data - mainPart;\n}\nhighp float unpackHighpData (float mainPart, float modPart, const float modValue) {\nhighp float data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nvoid packHighpData (out float mainPart, out float modPart, highp float data, const float modValue) {\nhighp float divide = data / modValue;\nmainPart = floor(divide);\nmodPart = (data - mainPart * modValue) / modValue;\n}\nhighp vec2 unpackHighpData (vec2 mainPart, vec2 modPart) {\nhighp vec2 data = mainPart;\nreturn data + modPart;\n}\nvoid packHighpData (out vec2 mainPart, out vec2 modPart, highp vec2 data) {\nmainPart = fract(data);\nmodPart = data - mainPart;\n}\nhighp vec2 unpackHighpData (vec2 mainPart, vec2 modPart, const float modValue) {\nhighp vec2 data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nvoid packHighpData (out vec2 mainPart, out vec2 modPart, highp vec2 data, const float modValue) {\nhighp vec2 divide = data / modValue;\nmainPart = floor(divide);\nmodPart = (data - mainPart * modValue) / modValue;\n}\nhighp vec3 unpackHighpData (vec3 mainPart, vec3 modPart) {\nhighp vec3 data = mainPart;\nreturn data + modPart;\n}\nvoid packHighpData (out vec3 mainPart, out vec3 modPart, highp vec3 data) {\nmainPart = fract(data);\nmodPart = data - mainPart;\n}\nhighp vec3 unpackHighpData (vec3 mainPart, vec3 modPart, const float modValue) {\nhighp vec3 data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nvoid packHighpData (out vec3 mainPart, out vec3 modPart, highp vec3 data, const float modValue) {\nhighp vec3 divide = data / modValue;\nmainPart = floor(divide);\nmodPart = (data - mainPart * modValue) / modValue;\n}\nhighp vec4 unpackHighpData (vec4 mainPart, vec4 modPart) {\nhighp vec4 data = mainPart;\nreturn data + modPart;\n}\nvoid packHighpData (out vec4 mainPart, out vec4 modPart, highp vec4 data) {\nmainPart = fract(data);\nmodPart = data - mainPart;\n}\nhighp vec4 unpackHighpData (vec4 mainPart, vec4 modPart, const float modValue) {\nhighp vec4 data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nvoid packHighpData (out vec4 mainPart, out vec4 modPart, highp vec4 data, const float modValue) {\nhighp vec4 divide = data / modValue;\nmainPart = floor(divide);\nmodPart = (data - mainPart * modValue) / modValue;\n}\nfloat CCGetLinearDepthFromViewSpace(vec3 viewPos) {\nfloat dist = length(viewPos);\nreturn (dist - cc_shadowNFLSInfo.x) / (cc_shadowNFLSInfo.y - cc_shadowNFLSInfo.x);\n}\nfloat CCGetLinearDepth(vec3 worldPos) {\nvec4 viewStartPos = cc_matLightView * vec4(worldPos.xyz, 1.0);\nreturn CCGetLinearDepthFromViewSpace(viewStartPos.xyz);\n}\n#if CC_RECEIVE_SHADOW\nuniform highp sampler2D cc_shadowMap;\nuniform highp sampler2D cc_spotLightingMap;\nvec4 ApplyShadowDepthBias_FaceNormal(vec4 shadowPos, vec3 worldNormal, float normalBias)\n{\nvec4 newShadowPos = shadowPos;\nif(normalBias > EPSILON_LOWP)\n{\nvec4 viewNormal = cc_matLightView * vec4(worldNormal, 0.0);\nif(viewNormal.z < 0.1)\nnewShadowPos.xy += viewNormal.xy * cc_shadowProjInfo.xy * normalBias * clamp(viewNormal.z, 0.001, 0.1);\n}\nreturn newShadowPos;\n}\nvec4 ApplyShadowDepthBias_Perspective(vec4 shadowPos, float viewspaceDepthBias)\n{\nvec3 viewSpacePos;\nviewSpacePos.xy = shadowPos.xy * cc_shadowProjInfo.zw;\nviewSpacePos.z = shadowPos.z * cc_shadowInvProjDepthInfo.x + shadowPos.w * cc_shadowInvProjDepthInfo.y;\nviewSpacePos.xyz += cc_shadowProjDepthInfo.z * normalize(viewSpacePos.xyz) * viewspaceDepthBias;\nvec4 clipSpacePos;\nclipSpacePos.xy = viewSpacePos.xy * cc_shadowProjInfo.xy;\nclipSpacePos.zw = viewSpacePos.z * cc_shadowProjDepthInfo.xz + vec2(cc_shadowProjDepthInfo.y, 0.0);\nif (cc_shadowNFLSInfo.z > EPSILON) {\nclipSpacePos.z = CCGetLinearDepthFromViewSpace(viewSpacePos.xyz);\nclipSpacePos.z = (clipSpacePos.z * 2.0 - 1.0) * clipSpacePos.w;\n}\nreturn clipSpacePos;\n}\nvec4 ApplyShadowDepthBias_Orthographic(vec4 shadowPos, float viewspaceDepthBias)\n{\nfloat coeffA = cc_shadowProjDepthInfo.x;\nfloat coeffB = cc_shadowProjDepthInfo.y;\nfloat viewSpacePos_z = (shadowPos.z - coeffB) / coeffA;\nviewSpacePos_z += viewspaceDepthBias;\nvec4 result = shadowPos;\nresult.z = viewSpacePos_z * coeffA + coeffB;\nreturn result;\n}\nfloat CCGetShadowFactorHard (vec4 shadowPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Orthographic(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat shadow = 0.0;\nfloat closestDepth = 0.0;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nclosestDepth = dot(texture2D(cc_shadowMap, clipPos.xy), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0));\n} else {\nclosestDepth = texture2D(cc_shadowMap, clipPos.xy).x;\n}\nshadow = step(clipPos.z, closestDepth);\nreturn shadow;\n}\nfloat CCGetShadowFactorSoft (vec4 shadowPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Orthographic(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat offsetDepth = clipPos.z;\nvec2 mapSize = cc_shadowWHPBInfo.xy;\nvec2 oneTap = 1.0 / mapSize;\nvec2 clipPos_offset = clipPos.xy + oneTap;\nfloat block0, block1, block2, block3;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos_offset.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos_offset.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos.x, clipPos.y)).x);\nblock1 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos_offset.x, clipPos.y)).x);\nblock2 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos.x, clipPos_offset.y)).x);\nblock3 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos_offset.x, clipPos_offset.y)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * mapSize.x;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block2, block3, coefX);\nfloat coefY = mod(clipPos.y, oneTap.y) * mapSize.y;\nreturn mix(resultX, resultY, coefY);\n}\nfloat CCGetShadowFactorSoft2X (vec4 shadowPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Orthographic(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat offsetDepth = clipPos.z;\nvec2 mapSize = cc_shadowWHPBInfo.xy;\nvec2 oneTap = 1.0 / mapSize;\nfloat clipPos_offset_L = clipPos.x - oneTap.x;\nfloat clipPos_offset_R = clipPos.x + oneTap.x;\nfloat clipPos_offset_U = clipPos.y - oneTap.y;\nfloat clipPos_offset_D = clipPos.y + oneTap.y;\nfloat block0, block1, block2, block3, block4, block5, block6, block7, block8;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos.x, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos_offset_L, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock4 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock5 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos_offset_R, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock6 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock7 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos.x, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock8 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_U)).x);\nblock1 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos.x, clipPos_offset_U)).x);\nblock2 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_U)).x);\nblock3 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos_offset_L, clipPos.y)).x);\nblock4 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos.x, clipPos.y)).x);\nblock5 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos_offset_R, clipPos.y)).x);\nblock6 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_D)).x);\nblock7 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos.x, clipPos_offset_D)).x);\nblock8 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_D)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * mapSize.x;\nfloat coefY = mod(clipPos.y, oneTap.y) * mapSize.y;\nfloat shadow = 0.0;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block3, block4, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block1, block2, coefX);\nresultY = mix(block4, block5, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block3, block4, coefX);\nresultY = mix(block6, block7, coefX);\nshadow += mix(resultX, resultY, coefY);\nresultX = mix(block4, block5, coefX);\nresultY = mix(block7, block8, coefX);\nshadow += mix(resultX, resultY, coefY);\nreturn shadow * 0.25;\n}\nfloat CCGetSpotLightShadowFactorHard (vec4 shadowPos, vec3 worldPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Perspective(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat shadow = 0.0;\nfloat closestDepth = 0.0;\nfloat depth = clipPos.z;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nclosestDepth = dot(texture2D(cc_spotLightingMap, clipPos.xy), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0));\n} else {\nclosestDepth = texture2D(cc_spotLightingMap, clipPos.xy).x;\n}\nshadow = step(depth, closestDepth);\nreturn shadow;\n}\nfloat CCGetSpotLightShadowFactorSoft (vec4 shadowPos, vec3 worldPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Perspective(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat depth = 0.0;\nif (cc_shadowNFLSInfo.z > EPSILON) {\ndepth = CCGetLinearDepth(worldPos);\n} else {\ndepth = clipPos.z;\n}\nvec2 oneTap = 1.0 / cc_shadowWHPBInfo.xy;\nvec2 clipPos_offset = clipPos.xy + oneTap;\nfloat block0, block1, block2, block3;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)).x);\nblock1 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos.y)).x);\nblock2 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset.y)).x);\nblock3 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos_offset.y)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * cc_shadowWHPBInfo.x;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block2, block3, coefX);\nfloat coefY = mod(clipPos.y, oneTap.y) * cc_shadowWHPBInfo.y;\nreturn mix(resultX, resultY, coefY);\n}\nfloat CCGetSpotLightShadowFactorSoft2X (vec4 shadowPos, vec3 worldPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Perspective(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat depth = 0.0;\nif (cc_shadowNFLSInfo.z > EPSILON) {\ndepth = CCGetLinearDepth(worldPos);\n} else {\ndepth = clipPos.z;\n}\nvec2 mapSize = cc_shadowWHPBInfo.xy;\nvec2 oneTap = 1.0 / mapSize;\nfloat clipPos_offset_L = clipPos.x - oneTap.x;\nfloat clipPos_offset_R = clipPos.x + oneTap.x;\nfloat clipPos_offset_U = clipPos.y - oneTap.y;\nfloat clipPos_offset_D = clipPos.y + oneTap.y;\nfloat block0, block1, block2, block3, block4, block5, block6, block7, block8;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock4 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock5 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock6 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock7 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock8 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_U)).x);\nblock1 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_U)).x);\nblock2 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_U)).x);\nblock3 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos.y)).x);\nblock4 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)).x);\nblock5 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos.y)).x);\nblock6 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_D)).x);\nblock7 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_D)).x);\nblock8 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_D)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * mapSize.x;\nfloat coefY = mod(clipPos.y, oneTap.y) * mapSize.y;\nfloat shadow = 0.0;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block3, block4, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block1, block2, coefX);\nresultY = mix(block4, block5, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block3, block4, coefX);\nresultY = mix(block6, block7, coefX);\nshadow += mix(resultX, resultY, coefY);\nresultX = mix(block4, block5, coefX);\nresultY = mix(block7, block8, coefX);\nshadow += mix(resultX, resultY, coefY);\nreturn shadow * 0.25;\n}\nfloat CCSpotShadowFactorBase(vec4 shadowPos, vec3 worldPos, vec2 shadowBias)\n{\nfloat pcf = cc_shadowWHPBInfo.z;\nif (pcf > 1.9) {\nreturn CCGetSpotLightShadowFactorSoft2X(shadowPos, worldPos, shadowBias.x);\n}else if (pcf > 0.9) {\nreturn CCGetSpotLightShadowFactorSoft(shadowPos, worldPos, shadowBias.x);\n}else {\nreturn CCGetSpotLightShadowFactorHard(shadowPos, worldPos, shadowBias.x);\n}\n}\nfloat CCShadowFactorBase(vec4 shadowPos, vec3 N, vec2 shadowBias)\n{\nfloat realtimeShadow = 1.0;\nvec4 pos = ApplyShadowDepthBias_FaceNormal(shadowPos, N, shadowBias.y);\nfloat pcf = cc_shadowWHPBInfo.z;\nif (pcf > 1.9) {\nrealtimeShadow = CCGetShadowFactorSoft2X(pos, shadowBias.x);\n}else if (pcf > 0.9) {\nrealtimeShadow = CCGetShadowFactorSoft(pos, shadowBias.x);\n}else {\nrealtimeShadow = CCGetShadowFactorHard(pos, shadowBias.x);\n}\nreturn mix(realtimeShadow, 1.0, cc_shadowNFLSInfo.w);\n}\n#endif\n#if CC_USE_IBL\nuniform samplerCube cc_environment;\nvec4 fragTextureLod (sampler2D tex, vec2 coord, float lod) {\n#ifdef GL_EXT_shader_texture_lod\nreturn texture2DLodEXT(tex, coord, lod);\n#else\nreturn texture2D(tex, coord, lod);\n#endif\n}\nvec4 fragTextureLod (samplerCube tex, vec3 coord, float lod) {\n#ifdef GL_EXT_shader_texture_lod\nreturn textureCubeLodEXT(tex, coord, lod);\n#else\nreturn textureCube(tex, coord, lod);\n#endif\n}\nvec3 unpackRGBE (vec4 rgbe) {\nreturn rgbe.rgb * pow(1.1, rgbe.a * 255.0 - 128.0);\n}\n#if CC_USE_DIFFUSEMAP\nuniform samplerCube cc_diffuseMap;\n#endif\n#endif\nfloat GGXMobile (float roughness, float NoH, vec3 H, vec3 N) {\nvec3 NxH = cross(N, H);\nfloat OneMinusNoHSqr = dot(NxH, NxH);\nfloat a = roughness * roughness;\nfloat n = NoH * a;\nfloat p = a / (OneMinusNoHSqr + n * n);\nreturn p * p;\n}\nfloat CalcSpecular (float roughness, float NoH, vec3 H, vec3 N) {\nreturn (roughness * 0.25 + 0.25) * GGXMobile(roughness, NoH, H, N);\n}\nvec3 BRDFApprox (vec3 specular, float roughness, float NoV) {\nconst vec4 c0 = vec4(-1.0, -0.0275, -0.572, 0.022);\nconst vec4 c1 = vec4(1.0, 0.0425, 1.04, -0.04);\nvec4 r = roughness * c0 + c1;\nfloat a004 = min(r.x * r.x, exp2(-9.28 * NoV)) * r.x + r.y;\nvec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;\nAB.y *= clamp(50.0 * specular.g, 0.0, 1.0);\nreturn specular * AB.x + AB.y;\n}\n#if USE_REFLECTION_DENOISE\nvec3 GetEnvReflectionWithMipFiltering(vec3 R, float roughness, float mipCount, float denoiseIntensity) {\n#if CC_USE_IBL\nfloat mip = roughness * mipCount;\nfloat delta = (dot(dFdx(R), dFdy(R))) * 1000.0;\nfloat mipBias = mix(0.0, 5.0, clamp(delta, 0.0, 1.0));\nvec4 biased = fragTextureLod(cc_environment, R, mip + mipBias);\nvec4 filtered = textureCube(cc_environment, R);\n#if CC_USE_IBL == 2\nbiased.rgb = unpackRGBE(biased);\nfiltered.rgb = unpackRGBE(filtered);\n#else\nbiased.rgb = SRGBToLinear(biased.rgb);\nfiltered.rgb = SRGBToLinear(filtered.rgb);\n#endif\nreturn mix(biased.rgb, filtered.rgb, denoiseIntensity);\n#else\nreturn vec3(0.0, 0.0, 0.0);\n#endif\n}\n#endif\nstruct StandardSurface {\nvec4 albedo;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nvec3 position, position_fract_part;\n#else\nvec3 position;\n#endif\nvec3 normal;\nvec3 emissive;\nvec3 lightmap;\nfloat lightmap_test;\nfloat roughness;\nfloat metallic;\nfloat occlusion;\nfloat specularIntensity;\n#if CC_RECEIVE_SHADOW\nvec2 shadowBias;\n#endif\n};\nvec4 CCStandardShadingBase (StandardSurface s, vec4 shadowPos) {\nvec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\nvec3 specular = mix(vec3(0.08 * s.specularIntensity), s.albedo.rgb, s.metallic);\nvec3 position;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nposition = unpackHighpData(s.position, s.position_fract_part);\n#else\nposition = s.position;\n#endif\nvec3 N = normalize(s.normal);\nvec3 V = normalize(cc_cameraPos.xyz - position);\nfloat NV = max(abs(dot(N, V)), 0.0);\nspecular = BRDFApprox(specular, s.roughness, NV);\nvec3 L = normalize(-cc_mainLitDir.xyz);\nvec3 H = normalize(L + V);\nfloat NH = max(dot(N, H), 0.0);\nfloat NL = max(dot(N, L), 0.0);\nvec3 finalColor = NL * cc_mainLitColor.rgb * cc_mainLitColor.w;\nvec3 diffuseContrib = diffuse / PI;\nvec3 specularContrib = specular * CalcSpecular(s.roughness, NH, H, N);\nvec3 dirlightContrib = (diffuseContrib + specularContrib);\nfloat shadow = 1.0;\n#if CC_RECEIVE_SHADOW\nif (NL > 0.0 && cc_mainLitDir.w > 0.0) {\nshadow = CCShadowFactorBase(shadowPos, N, s.shadowBias);\n}\n#endif\ndirlightContrib *= shadow;\nfinalColor *= dirlightContrib;\n#if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\nif (s.lightmap_test > EPSILON_LOWP) {\nfinalColor = diffuse * s.lightmap.rgb * shadow;\n}\n#endif\nfloat fAmb = 0.5 - N.y * 0.5;\nvec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb);\n#if CC_USE_IBL\n#if CC_USE_DIFFUSEMAP\nvec4 diffuseMap = textureCube(cc_diffuseMap, N);\n#if CC_USE_DIFFUSEMAP == 2\nambDiff = unpackRGBE(diffuseMap);\n#else\nambDiff = SRGBToLinear(diffuseMap.rgb);\n#endif\n#endif\nvec3 R = normalize(reflect(-V, N));\n#if USE_REFLECTION_DENOISE\nvec3 env = GetEnvReflectionWithMipFiltering(R, s.roughness, cc_ambientGround.w, 0.6);\n#else\nvec4 envmap = fragTextureLod(cc_environment, R, s.roughness * cc_ambientGround.w);\n#if CC_USE_IBL == 2\nvec3 env = unpackRGBE(envmap);\n#else\nvec3 env = SRGBToLinear(envmap.rgb);\n#endif\n#endif\nfinalColor += env * cc_ambientSky.w * specular * s.occlusion;\n#endif\nfinalColor += ambDiff.rgb * cc_ambientSky.w * diffuse * s.occlusion;\nfinalColor += s.emissive;\nreturn vec4(finalColor, s.albedo.a);\n}\nvec3 ACESToneMap (vec3 color) {\ncolor = min(color, vec3(8.0));\nconst float A = 2.51;\nconst float B = 0.03;\nconst float C = 2.43;\nconst float D = 0.59;\nconst float E = 0.14;\nreturn (color * (A * color + B)) / (color * (C * color + D) + E);\n}\nvec4 CCFragOutput (vec4 color) {\n#if CC_USE_HDR\ncolor.rgb = ACESToneMap(color.rgb);\n#endif\ncolor.rgb = sqrt(color.rgb);\nreturn color;\n}\nvarying highp vec4 v_shadowPos;\n#if CC_RECEIVE_SHADOW\n#endif\n#if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\nvarying vec3 v_luv;\nuniform sampler2D cc_lightingMap;\n#endif\nvarying vec3 v_position;\nvarying vec2 v_uv;\n#if HAS_SECOND_UV\nvarying mediump vec2 v_uv1;\n#endif\nvarying mediump vec3 v_normal;\n#if CC_RECEIVE_SHADOW\nvarying mediump vec2 v_shadowBias;\n#endif\n#if USE_VERTEX_COLOR\nvarying lowp vec4 v_color;\n#endif\n#if USE_ALBEDO_MAP\nuniform sampler2D albedoMap;\n#endif\n#if USE_NORMAL_MAP\nvarying mediump vec4 v_tangent;\nuniform sampler2D normalMap;\n#endif\n#if USE_PBR_MAP\nuniform sampler2D pbrMap;\n#endif\n#if USE_METALLIC_ROUGHNESS_MAP\nuniform sampler2D metallicRoughnessMap;\n#endif\n#if USE_OCCLUSION_MAP\nuniform sampler2D occlusionMap;\n#endif\n#if USE_EMISSIVE_MAP\nuniform sampler2D emissiveMap;\n#endif\n#if USE_ALPHA_TEST\n#endif\nvoid surf (out StandardSurface s) {\nvec4 baseColor = albedo;\n#if USE_VERTEX_COLOR\nbaseColor.rgb *= SRGBToLinear(v_color.rgb);\nbaseColor.a *= v_color.a;\n#endif\n#if USE_ALBEDO_MAP\nvec4 texColor = texture2D(albedoMap, ALBEDO_UV);\ntexColor.rgb = SRGBToLinear(texColor.rgb);\nbaseColor *= texColor;\n#endif\ns.albedo = baseColor;\ns.albedo.rgb *= albedoScaleAndCutoff.xyz;\n#if USE_ALPHA_TEST\nif (s.albedo.ALPHA_TEST_CHANNEL < albedoScaleAndCutoff.w) discard;\n#endif\n#if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\nvec4 lightColor = texture2D(cc_lightingMap, v_luv.xy);\ns.lightmap = lightColor.xyz * v_luv.z;\ns.lightmap_test = v_luv.z;\n#endif\ns.normal = v_normal;\n#if CC_RECEIVE_SHADOW\ns.shadowBias = v_shadowBias;\n#endif\n#if USE_NORMAL_MAP\nvec3 nmmp = texture2D(normalMap, NORMAL_UV).xyz - vec3(0.5);\nvec3 bitangent = cross(v_normal, v_tangent.xyz) * v_tangent.w;\ns.normal =\n(nmmp.x * emissiveScaleParam.w) * normalize(v_tangent.xyz) +\n(nmmp.y * emissiveScaleParam.w) * normalize(bitangent) +\nnmmp.z * normalize(s.normal);\n#endif\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\npackHighpData(s.position, s.position_fract_part, v_position);\n#else\ns.position = v_position;\n#endif\nvec4 pbr = pbrParams;\n#if USE_PBR_MAP\nvec4 res = texture2D(pbrMap, PBR_UV);\npbr.x *= res.r;\npbr.y *= res.g;\npbr.z *= res.b;\npbr.w *= res.a;\n#endif\n#if USE_METALLIC_ROUGHNESS_MAP\nvec4 metallicRoughness = texture2D(metallicRoughnessMap, PBR_UV);\npbr.z *= metallicRoughness.b;\npbr.y *= metallicRoughness.g;\n#endif\n#if USE_OCCLUSION_MAP\npbr.x *= texture2D(occlusionMap, PBR_UV).r;\n#endif\ns.occlusion = pbr.x;\ns.roughness = pbr.y;\ns.specularIntensity = 0.5;\ns.metallic = pbr.z;\ns.emissive = emissive.rgb * emissiveScaleParam.xyz;\n#if USE_EMISSIVE_MAP\ns.emissive *= SRGBToLinear(texture2D(emissiveMap, EMISSIVE_UV).rgb);\n#endif\n}\n#if CC_FORWARD_ADD\n#if CC_PIPELINE_TYPE == 0\n#define LIGHTS_PER_PASS 1\n#else\n#define LIGHTS_PER_PASS 10\n#endif\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 0\nuniform highp vec4 cc_lightPos[LIGHTS_PER_PASS];\nuniform vec4 cc_lightColor[LIGHTS_PER_PASS];\nuniform vec4 cc_lightSizeRangeAngle[LIGHTS_PER_PASS];\nuniform vec4 cc_lightDir[LIGHTS_PER_PASS];\n#endif\nfloat SmoothDistAtt (float distSqr, float invSqrAttRadius) {\nfloat factor = distSqr * invSqrAttRadius;\nfloat smoothFactor = clamp(1.0 - factor * factor, 0.0, 1.0);\nreturn smoothFactor * smoothFactor;\n}\nfloat GetDistAtt (float distSqr, float invSqrAttRadius) {\nfloat attenuation = 1.0 / max(distSqr, 0.01*0.01);\nattenuation *= SmoothDistAtt(distSqr , invSqrAttRadius);\nreturn attenuation;\n}\nfloat GetAngleAtt (vec3 L, vec3 litDir, float litAngleScale, float litAngleOffset) {\nfloat cd = dot(litDir, L);\nfloat attenuation = clamp(cd * litAngleScale + litAngleOffset, 0.0, 1.0);\nreturn (attenuation * attenuation);\n}\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 0\nvec4 CCStandardShadingAdditive (StandardSurface s, vec4 shadowPos) {\nvec3 position;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nposition = unpackHighpData(s.position, s.position_fract_part);\n#else\nposition = s.position;\n#endif\nvec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\nvec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\nvec3 diffuseContrib = diffuse / PI;\nvec3 N = normalize(s.normal);\nvec3 V = normalize(cc_cameraPos.xyz - position);\nfloat NV = max(abs(dot(N, V)), 0.0);\nspecular = BRDFApprox(specular, s.roughness, NV);\nvec3 finalColor = vec3(0.0);\nint numLights = CC_PIPELINE_TYPE == 0 ? LIGHTS_PER_PASS : int(cc_lightDir[0].w);\nfor (int i = 0; i < LIGHTS_PER_PASS; i++) {\nif (i >= numLights) break;\nvec3 SLU = cc_lightPos[i].xyz - position;\nvec3 SL = normalize(SLU);\nvec3 SH = normalize(SL + V);\nfloat SNL = max(dot(N, SL), 0.0);\nfloat SNH = max(dot(N, SH), 0.0);\nfloat distSqr = dot(SLU, SLU);\nfloat litRadius = cc_lightSizeRangeAngle[i].x;\nfloat litRadiusSqr = litRadius * litRadius;\nfloat illum = litRadiusSqr / max(litRadiusSqr, distSqr);\nfloat attRadiusSqrInv = 1.0 / max(cc_lightSizeRangeAngle[i].y, 0.01);\nattRadiusSqrInv *= attRadiusSqrInv;\nfloat att = GetDistAtt(distSqr, attRadiusSqrInv);\nvec3 lspec = specular * CalcSpecular(s.roughness, SNH, SH, N);\nif (cc_lightPos[i].w > 0.0) {\nfloat cosInner = max(dot(-cc_lightDir[i].xyz, SL), 0.01);\nfloat cosOuter = cc_lightSizeRangeAngle[i].z;\nfloat litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\nfloat litAngleOffset = -cosOuter * litAngleScale;\natt *= GetAngleAtt(SL, -cc_lightDir[i].xyz, litAngleScale, litAngleOffset);\n}\nvec3 lightColor = cc_lightColor[i].rgb;\nfloat shadow = 1.0;\n#if CC_RECEIVE_SHADOW\nif (cc_lightPos[i].w > 0.0 && cc_lightSizeRangeAngle[i].w > 0.0) {\nshadow = CCSpotShadowFactorBase(shadowPos, position, s.shadowBias);\n}\n#endif\nlightColor *= shadow;\nfinalColor += SNL * lightColor * cc_lightColor[i].w * illum * att * (diffuseContrib + lspec);\n}\nreturn vec4(finalColor, 0.0);\n}\n#endif\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 1\nreadonly buffer b_ccLightsBuffer { vec4 b_ccLights[]; };\nreadonly buffer b_clusterLightIndicesBuffer { uint b_clusterLightIndices[]; };\nreadonly buffer b_clusterLightGridBuffer { uvec4 b_clusterLightGrid[]; };\nstruct CCLight\n{\nvec4 cc_lightPos;\nvec4 cc_lightColor;\nvec4 cc_lightSizeRangeAngle;\nvec4 cc_lightDir;\n};\nstruct Cluster\n{\nvec3 minBounds;\nvec3 maxBounds;\n};\nstruct LightGrid\n{\nuint offset;\nuint ccLights;\n};\nCCLight getCCLight(uint i)\n{\nCCLight light;\nlight.cc_lightPos = b_ccLights[4u * i + 0u];\nlight.cc_lightColor = b_ccLights[4u * i + 1u];\nlight.cc_lightSizeRangeAngle = b_ccLights[4u * i + 2u];\nlight.cc_lightDir = b_ccLights[4u * i + 3u];\nreturn light;\n}\nLightGrid getLightGrid(uint cluster)\n{\nuvec4 gridvec = b_clusterLightGrid[cluster];\nLightGrid grid;\ngrid.offset = gridvec.x;\ngrid.ccLights = gridvec.y;\nreturn grid;\n}\nuint getGridLightIndex(uint start, uint offset)\n{\nreturn b_clusterLightIndices[start + offset];\n}\nuint getClusterZIndex(vec4 worldPos)\n{\nfloat scale = float(24) / log(cc_nearFar.y / cc_nearFar.x);\nfloat bias = -(float(24) * log(cc_nearFar.x) / log(cc_nearFar.y / cc_nearFar.x));\nfloat eyeDepth = -(cc_matView * worldPos).z;\nuint zIndex = uint(max(log(eyeDepth) * scale + bias, 0.0));\nreturn zIndex;\n}\nuint getClusterIndex(vec4 fragCoord, vec4 worldPos)\n{\nuint zIndex = getClusterZIndex(worldPos);\nfloat clusterSizeX = ceil(cc_viewPort.z / float(16));\nfloat clusterSizeY = ceil(cc_viewPort.w / float(8));\nuvec3 indices = uvec3(uvec2(fragCoord.xy / vec2(clusterSizeX, clusterSizeY)), zIndex);\nuint cluster = (16u * 8u) * indices.z + 16u * indices.y + indices.x;\nreturn cluster;\n}\nvec4 CCClusterShadingAdditive (StandardSurface s, vec4 shadowPos) {\nvec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\nvec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\nvec3 diffuseContrib = diffuse / PI;\nvec3 position;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nposition = unpackHighpData(s.position, s.position_fract_part);\n#else\nposition = s.position;\n#endif\nvec3 N = normalize(s.normal);\nvec3 V = normalize(cc_cameraPos.xyz - position);\nfloat NV = max(abs(dot(N, V)), 0.001);\nspecular = BRDFApprox(specular, s.roughness, NV);\nvec3 finalColor = vec3(0.0);\nuint cluster = getClusterIndex(gl_FragCoord, vec4(position, 1.0));\nLightGrid grid = getLightGrid(cluster);\nuint numLights = grid.ccLights;\nfor (uint i = 0u; i < 100u; i++) {\nif (i >= numLights) break;\nuint lightIndex = getGridLightIndex(grid.offset, i);\nCCLight light = getCCLight(lightIndex);\nvec3 SLU = light.cc_lightPos.xyz - position;\nvec3 SL = normalize(SLU);\nvec3 SH = normalize(SL + V);\nfloat SNL = max(dot(N, SL), 0.001);\nfloat SNH = max(dot(N, SH), 0.0);\nfloat distSqr = dot(SLU, SLU);\nfloat litRadius = light.cc_lightSizeRangeAngle.x;\nfloat litRadiusSqr = litRadius * litRadius;\nfloat illum = PI * (litRadiusSqr / max(litRadiusSqr , distSqr));\nfloat attRadiusSqrInv = 1.0 / max(light.cc_lightSizeRangeAngle.y, 0.01);\nattRadiusSqrInv *= attRadiusSqrInv;\nfloat att = GetDistAtt(distSqr, attRadiusSqrInv);\nvec3 lspec = specular * CalcSpecular(s.roughness, SNH, SH, N);\nif (light.cc_lightPos.w > 0.0) {\nfloat cosInner = max(dot(-light.cc_lightDir.xyz, SL), 0.01);\nfloat cosOuter = light.cc_lightSizeRangeAngle.z;\nfloat litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\nfloat litAngleOffset = -cosOuter * litAngleScale;\natt *= GetAngleAtt(SL, -light.cc_lightDir.xyz, litAngleScale, litAngleOffset);\n}\nvec3 lightColor = light.cc_lightColor.rgb;\nfloat shadow = 1.0;\n#if CC_RECEIVE_SHADOW\nif (light.cc_lightPos.w > 0.0) {\nshadow = CCSpotShadowFactorBase(shadowPos, position, s.shadowBias);\n}\n#endif\nlightColor *= shadow;\nfinalColor += SNL * lightColor * light.cc_lightColor.w * illum * att * (diffuseContrib + lspec);\n}\nreturn vec4(finalColor, 0.0);\n}\n#endif\nvoid main () {\nStandardSurface s; surf(s);\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 1\nvec4 color = CCClusterShadingAdditive(s, v_shadowPos);\n#else\nvec4 color = CCStandardShadingAdditive(s, v_shadowPos);\n#endif\ngl_FragData[0] = CCFragOutput(color);\n}\n#elif (CC_PIPELINE_TYPE == 0 || CC_FORCE_FORWARD_SHADING)\nvoid main () {\nStandardSurface s; surf(s);\nvec4 color = CCStandardShadingBase(s, v_shadowPos);\nCC_APPLY_FOG(color, s.position.xyz);\ngl_FragData[0] = CCFragOutput(color);\n}\n#elif CC_PIPELINE_TYPE == 1\nvec2 signNotZero(vec2 v) {\nreturn vec2((v.x >= 0.0) ? +1.0 : -1.0, (v.y >= 0.0) ? +1.0 : -1.0);\n}\nvec2 float32x3_to_oct(in vec3 v) {\nvec2 p = v.xy * (1.0 / (abs(v.x) + abs(v.y) + abs(v.z)));\nreturn (v.z <= 0.0) ? ((1.0 - abs(p.yx)) * signNotZero(p)) : p;\n}\nvoid main () {\nStandardSurface s; surf(s);\ngl_FragData[0] = s.albedo;\ngl_FragData[1] = vec4(float32x3_to_oct(s.normal), s.roughness, s.metallic);\ngl_FragData[2] = vec4(s.emissive, s.occlusion);\n}\n#endif", }, { - "vert": "\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\nrgba = rgba * 255.0;\nhighp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\nhighp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\nhighp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\nreturn Sign * exp2(Exponent - 23.0) * Mantissa;\n}\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nattribute vec3 a_position;\nattribute vec3 a_normal;\nattribute vec2 a_texCoord;\nattribute vec4 a_tangent;\n#if CC_USE_SKINNING\nattribute vec4 a_joints;\nattribute vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nattribute highp vec4 a_jointAnimInfo;\n#endif\nattribute vec4 a_matWorld0;\nattribute vec4 a_matWorld1;\nattribute vec4 a_matWorld2;\n#if USE_LIGHTMAP\nattribute vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nattribute vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nattribute float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nattribute float a_vertexId;\nint getVertexId() {\nreturn int(a_vertexId);\n}\n#endif\n#if CC_USE_MORPH\nuniform vec4 cc_displacementWeights[15];\nuniform vec4 cc_displacementTextureInfo;\nvec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\nfloat pixelIndexF = float(pixelIndex);\nfloat x = mod(pixelIndexF, textureResolution.x);\nfloat y = floor(pixelIndexF / textureResolution.x);\nreturn vec2(x, y);\n}\nvec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\nreturn (vec2(location.x, location.y) + .5) / textureResolution;\n}\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 uv = getPixelCoordFromLocation(location, cc_displacementTextureInfo.xy);\nreturn texture2D(tex, uv);\n}\n#else\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex * 4;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\nreturn vec4(\ndecode32(texture2D(tex, x)),\ndecode32(texture2D(tex, y)),\ndecode32(texture2D(tex, z)),\n1.0\n);\n}\n#endif\nfloat getDisplacementWeight(int index) {\nint quot = index / 4;\nint remainder = index - quot * 4;\nif (remainder == 0) {\nreturn cc_displacementWeights[quot].x;\n} else if (remainder == 1) {\nreturn cc_displacementWeights[quot].y;\n} else if (remainder == 2) {\nreturn cc_displacementWeights[quot].z;\n} else {\nreturn cc_displacementWeights[quot].w;\n}\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\nreturn fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n#else\nvec3 result = vec3(0, 0, 0);\nint nVertices = int(cc_displacementTextureInfo.z);\nfor (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\nresult += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n}\nreturn result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\nuniform sampler2D cc_PositionDisplacements;\nvec3 getPositionDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nuniform sampler2D cc_NormalDisplacements;\nvec3 getNormalDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\nuniform sampler2D cc_TangentDisplacements;\nvec3 getTangentDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n}\n#endif\nvoid applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nint vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nnormal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\ntangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\n#if CC_USE_BAKED_ANIMATION\nuniform highp vec4 cc_jointTextureInfo;\nuniform highp vec4 cc_jointAnimInfo;\nuniform highp sampler2D cc_jointTexture;\nvoid CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n{\n#if USE_INSTANCING\nhighp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n#else\nhighp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n#endif\ninvSize = cc_jointTextureInfo.w;\nhighp float tempY = floor(temp * invSize);\nx = floor(temp - tempY * cc_jointTextureInfo.x);\ny = (tempY + 0.5) * invSize;\n}\n#else\nuniform highp vec4 cc_joints[90];\n#endif\n#if CC_USE_BAKED_ANIMATION\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(3.0, i, x, y, invSize);\nvec4 v1 = texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y));\nvec4 v2 = texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y));\nvec4 v3 = texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y));\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#else\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(12.0, i, x, y, invSize);\nvec4 v1 = vec4(\ndecode32(texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n);\nvec4 v2 = vec4(\ndecode32(texture2D(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n);\nvec4 v3 = vec4(\ndecode32(texture2D(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n);\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\n#else\nmat4 getJointMatrix (float i) {\nint idx = int(i);\nvec4 v1 = cc_joints[idx * 3];\nvec4 v2 = cc_joints[idx * 3 + 1];\nvec4 v3 = cc_joints[idx * 3 + 2];\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\nmat4 skinMatrix () {\nvec4 joints = vec4(a_joints);\nreturn getJointMatrix(joints.x) * a_weights.x\n+ getJointMatrix(joints.y) * a_weights.y\n+ getJointMatrix(joints.z) * a_weights.z\n+ getJointMatrix(joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\nmat4 m = skinMatrix();\nposition = m * position;\n}\nvoid CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nmat4 m = skinMatrix();\nposition = m * position;\nnormal = (m * vec4(normal, 0.0)).xyz;\ntangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n}\n#endif\nvoid CCVertInput(inout StandardVertInput In)\n{\nIn.position = vec4(a_position, 1.0);\nIn.normal = a_normal;\nIn.tangent = a_tangent;\n#if CC_USE_MORPH\napplyMorph(In.position, In.normal, In.tangent);\n#endif\n#if CC_USE_SKINNING\nCCSkin(In.position, In.normal, In.tangent);\n#endif\n}\n#if !USE_INSTANCING\n#if USE_BATCHING\nuniform highp mat4 cc_matWorlds[10];\n#else\nuniform highp mat4 cc_matWorld;\nuniform highp mat4 cc_matWorldIT;\n#endif\n#endif\nvoid CCGetWorldMatrixFull(out mat4 matWorld, out mat4 matWorldIT)\n{\n#if USE_INSTANCING\nmatWorld = mat4(\nvec4(a_matWorld0.xyz, 0.0),\nvec4(a_matWorld1.xyz, 0.0),\nvec4(a_matWorld2.xyz, 0.0),\nvec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)\n);\nmatWorldIT = matWorld;\n#elif USE_BATCHING\nmatWorld = cc_matWorlds[int(a_dyn_batch_id)];\nmatWorldIT = matWorld;\n#else\nmatWorld = cc_matWorld;\nmatWorldIT = cc_matWorldIT;\n#endif\n}\nuniform vec4 tilingOffset;\nuniform highp mat4 cc_matLightViewProj;\n#if HAS_SECOND_UV || USE_LIGHTMAP\nattribute vec2 a_texCoord1;\n#endif\nvarying vec2 v_uv;\n#if HAS_SECOND_UV\nvarying vec2 v_uv1;\n#endif\nvarying vec4 v_worldPos;\nvarying float v_clip_depth;\nvec4 vert () {\nStandardVertInput In;\nCCVertInput(In);\nmat4 matWorld, matWorldIT;\nCCGetWorldMatrixFull(matWorld, matWorldIT);\nv_worldPos = matWorld * In.position;\nvec4 clipPos = cc_matLightViewProj * v_worldPos;\nv_uv = a_texCoord * tilingOffset.xy + tilingOffset.zw;\n#if HAS_SECOND_UV\nv_uv1 = a_texCoord1 * tilingOffset.xy + tilingOffset.zw;\n#endif\nv_clip_depth = clipPos.z / clipPos.w * 0.5 + 0.5;\nreturn clipPos;\n}\nvoid main() { gl_Position = vert(); }", + "vert": "\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\nrgba = rgba * 255.0;\nhighp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\nhighp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\nhighp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\nreturn Sign * exp2(Exponent - 23.0) * Mantissa;\n}\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nattribute vec3 a_position;\nattribute vec3 a_normal;\nattribute vec2 a_texCoord;\nattribute vec4 a_tangent;\n#if CC_USE_SKINNING\nattribute vec4 a_joints;\nattribute vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nattribute highp vec4 a_jointAnimInfo;\n#endif\nattribute vec4 a_matWorld0;\nattribute vec4 a_matWorld1;\nattribute vec4 a_matWorld2;\n#if CC_USE_LIGHTMAP\nattribute vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nattribute vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nattribute float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nattribute float a_vertexId;\nint getVertexId() {\nreturn int(a_vertexId);\n}\n#endif\n#if CC_USE_MORPH\nuniform vec4 cc_displacementWeights[15];\nuniform vec4 cc_displacementTextureInfo;\nvec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\nfloat pixelIndexF = float(pixelIndex);\nfloat x = mod(pixelIndexF, textureResolution.x);\nfloat y = floor(pixelIndexF / textureResolution.x);\nreturn vec2(x, y);\n}\nvec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\nreturn (vec2(location.x, location.y) + .5) / textureResolution;\n}\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 uv = getPixelCoordFromLocation(location, cc_displacementTextureInfo.xy);\nreturn texture2D(tex, uv);\n}\n#else\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex * 4;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\nreturn vec4(\ndecode32(texture2D(tex, x)),\ndecode32(texture2D(tex, y)),\ndecode32(texture2D(tex, z)),\n1.0\n);\n}\n#endif\nfloat getDisplacementWeight(int index) {\nint quot = index / 4;\nint remainder = index - quot * 4;\nif (remainder == 0) {\nreturn cc_displacementWeights[quot].x;\n} else if (remainder == 1) {\nreturn cc_displacementWeights[quot].y;\n} else if (remainder == 2) {\nreturn cc_displacementWeights[quot].z;\n} else {\nreturn cc_displacementWeights[quot].w;\n}\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\nreturn fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n#else\nvec3 result = vec3(0, 0, 0);\nint nVertices = int(cc_displacementTextureInfo.z);\nfor (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\nresult += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n}\nreturn result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\nuniform sampler2D cc_PositionDisplacements;\nvec3 getPositionDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nuniform sampler2D cc_NormalDisplacements;\nvec3 getNormalDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\nuniform sampler2D cc_TangentDisplacements;\nvec3 getTangentDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n}\n#endif\nvoid applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nint vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nnormal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\ntangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\n#if CC_USE_BAKED_ANIMATION\nuniform highp vec4 cc_jointTextureInfo;\nuniform highp vec4 cc_jointAnimInfo;\nuniform highp sampler2D cc_jointTexture;\nvoid CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n{\n#if USE_INSTANCING\nhighp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n#else\nhighp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n#endif\ninvSize = cc_jointTextureInfo.w;\nhighp float tempY = floor(temp * invSize);\nx = floor(temp - tempY * cc_jointTextureInfo.x);\ny = (tempY + 0.5) * invSize;\n}\n#else\nuniform highp vec4 cc_joints[90];\n#endif\n#if CC_USE_BAKED_ANIMATION\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(3.0, i, x, y, invSize);\nvec4 v1 = texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y));\nvec4 v2 = texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y));\nvec4 v3 = texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y));\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#else\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(12.0, i, x, y, invSize);\nvec4 v1 = vec4(\ndecode32(texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n);\nvec4 v2 = vec4(\ndecode32(texture2D(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n);\nvec4 v3 = vec4(\ndecode32(texture2D(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n);\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\n#else\nmat4 getJointMatrix (float i) {\nint idx = int(i);\nvec4 v1 = cc_joints[idx * 3];\nvec4 v2 = cc_joints[idx * 3 + 1];\nvec4 v3 = cc_joints[idx * 3 + 2];\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\nmat4 skinMatrix () {\nvec4 joints = vec4(a_joints);\nreturn getJointMatrix(joints.x) * a_weights.x\n+ getJointMatrix(joints.y) * a_weights.y\n+ getJointMatrix(joints.z) * a_weights.z\n+ getJointMatrix(joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\nmat4 m = skinMatrix();\nposition = m * position;\n}\nvoid CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nmat4 m = skinMatrix();\nposition = m * position;\nnormal = (m * vec4(normal, 0.0)).xyz;\ntangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n}\n#endif\nvoid CCVertInput(inout StandardVertInput In)\n{\nIn.position = vec4(a_position, 1.0);\nIn.normal = a_normal;\nIn.tangent = a_tangent;\n#if CC_USE_MORPH\napplyMorph(In.position, In.normal, In.tangent);\n#endif\n#if CC_USE_SKINNING\nCCSkin(In.position, In.normal, In.tangent);\n#endif\n}\n#if !USE_INSTANCING\n#if USE_BATCHING\nuniform highp mat4 cc_matWorlds[10];\n#else\nuniform highp mat4 cc_matWorld;\nuniform highp mat4 cc_matWorldIT;\n#endif\n#endif\nvoid CCGetWorldMatrixFull(out mat4 matWorld, out mat4 matWorldIT)\n{\n#if USE_INSTANCING\nmatWorld = mat4(\nvec4(a_matWorld0.xyz, 0.0),\nvec4(a_matWorld1.xyz, 0.0),\nvec4(a_matWorld2.xyz, 0.0),\nvec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)\n);\nmatWorldIT = matWorld;\n#elif USE_BATCHING\nmatWorld = cc_matWorlds[int(a_dyn_batch_id)];\nmatWorldIT = matWorld;\n#else\nmatWorld = cc_matWorld;\nmatWorldIT = cc_matWorldIT;\n#endif\n}\nuniform vec4 tilingOffset;\nuniform highp mat4 cc_matLightViewProj;\n#if HAS_SECOND_UV || CC_USE_LIGHTMAP\nattribute vec2 a_texCoord1;\n#endif\nvarying vec2 v_uv;\n#if HAS_SECOND_UV\nvarying vec2 v_uv1;\n#endif\nvarying vec4 v_worldPos;\nvarying float v_clip_depth;\nvec4 vert () {\nStandardVertInput In;\nCCVertInput(In);\nmat4 matWorld, matWorldIT;\nCCGetWorldMatrixFull(matWorld, matWorldIT);\nv_worldPos = matWorld * In.position;\nvec4 clipPos = cc_matLightViewProj * v_worldPos;\nv_uv = a_texCoord * tilingOffset.xy + tilingOffset.zw;\n#if HAS_SECOND_UV\nv_uv1 = a_texCoord1 * tilingOffset.xy + tilingOffset.zw;\n#endif\nv_clip_depth = clipPos.z / clipPos.w * 0.5 + 0.5;\nreturn clipPos;\n}\nvoid main() { gl_Position = vert(); }", "frag": "\nprecision highp float;\nuniform vec4 albedo;\nuniform vec4 albedoScaleAndCutoff;\nvec4 packDepthToRGBA (float depth) {\nvec4 ret = vec4(1.0, 255.0, 65025.0, 16581375.0) * depth;\nret = fract(ret);\nret -= vec4(ret.yzw, 0.0) / 255.0;\nreturn ret;\n}\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nuniform highp mat4 cc_matLightView;\nuniform mediump vec4 cc_shadowNFLSInfo;\nuniform mediump vec4 cc_shadowLPNNInfo;\nfloat CCGetLinearDepthFromViewSpace(vec3 viewPos) {\nfloat dist = length(viewPos);\nreturn (dist - cc_shadowNFLSInfo.x) / (cc_shadowNFLSInfo.y - cc_shadowNFLSInfo.x);\n}\nfloat CCGetLinearDepth(vec3 worldPos) {\nvec4 viewStartPos = cc_matLightView * vec4(worldPos.xyz, 1.0);\nreturn CCGetLinearDepthFromViewSpace(viewStartPos.xyz);\n}\n#if CC_RECEIVE_SHADOW\nuniform highp sampler2D cc_shadowMap;\nuniform highp sampler2D cc_spotLightingMap;\n#endif\nvarying vec2 v_uv;\n#if HAS_SECOND_UV\nvarying vec2 v_uv1;\n#endif\nvarying vec4 v_worldPos;\nvarying float v_clip_depth;\n#if USE_ALBEDO_MAP\nuniform sampler2D albedoMap;\n#endif\n#if USE_ALPHA_TEST\n#endif\nvec4 frag () {\nvec4 baseColor = albedo;\n#if USE_ALBEDO_MAP\nbaseColor *= texture2D(albedoMap, ALBEDO_UV);\n#endif\n#if USE_ALPHA_TEST\nif (baseColor.ALPHA_TEST_CHANNEL < albedoScaleAndCutoff.w) discard;\n#endif\nif(cc_shadowLPNNInfo.x > 0.000001 && cc_shadowLPNNInfo.x < 1.999999) {\nif (cc_shadowNFLSInfo.z > 0.000001) {\nreturn vec4(CCGetLinearDepth(v_worldPos.xyz), 1.0, 1.0, 1.0);\n}\n}\nif (cc_shadowLPNNInfo.y > 0.000001) {\nreturn packDepthToRGBA(v_clip_depth);\n}\nreturn vec4(v_clip_depth, 1.0, 1.0, 1.0);\n}\nvoid main() { gl_FragColor = frag(); }", } ], [ { - "vert": "\nprecision mediump float;\nuniform highp mat4 cc_matViewProj;\nuniform highp vec4 cc_cameraPos;\nuniform mediump vec4 cc_fogBase;\nuniform mediump vec4 cc_fogAdd;\nuniform highp mat4 cc_matWorld;\nfloat LinearFog(vec4 pos) {\nvec4 wPos = pos;\nfloat cam_dis = distance(cc_cameraPos, wPos);\nfloat fogStart = cc_fogBase.x;\nfloat fogEnd = cc_fogBase.y;\nreturn clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * fogDensity);\nreturn f;\n}\nfloat ExpSquaredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\nreturn f;\n}\nfloat LayeredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat _FogTop = cc_fogAdd.x;\nfloat _FogRange = cc_fogAdd.y;\nvec3 camWorldProj = cc_cameraPos.xyz;\ncamWorldProj.y = 0.;\nvec3 worldPosProj = wPos.xyz;\nworldPosProj.y = 0.;\nfloat fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\nfloat fDeltaY, fDensityIntegral;\nif (cc_cameraPos.y > _FogTop) {\nif (wPos.y < _FogTop) {\nfDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\nfDensityIntegral = fDeltaY * fDeltaY * 0.5;\n} else {\nfDeltaY = 0.;\nfDensityIntegral = 0.;\n}\n} else {\nif (wPos.y < _FogTop) {\nfloat fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfloat fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\nfDeltaY = abs(fDeltaA - fDeltaB);\nfDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n} else {\nfDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n}\n}\nfloat fDensity;\nif (fDeltaY != 0.) {\nfDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n} else {\nfDensity = 0.;\n}\nfloat f = exp(-fDensity);\nreturn f;\n}\nvoid CC_TRANSFER_FOG_BASE(vec4 pos, out float factor)\n{\n#if CC_USE_FOG == 0\nfactor = LinearFog(pos);\n#elif CC_USE_FOG == 1\nfactor = ExpFog(pos);\n#elif CC_USE_FOG == 2\nfactor = ExpSquaredFog(pos);\n#elif CC_USE_FOG == 3\nfactor = LayeredFog(pos);\n#else\nfactor = 1.0;\n#endif\n}\n#if !CC_USE_ACCURATE_FOG\nvarying float v_fog_factor;\n#endif\nvoid CC_TRANSFER_FOG(vec4 pos) {\n#if !CC_USE_ACCURATE_FOG\nCC_TRANSFER_FOG_BASE(pos, v_fog_factor);\n#endif\n}\nvarying highp vec4 v_shadowPos;\nuniform highp mat4 cc_matLightViewProj;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\n#if CC_RECEIVE_SHADOW\nuniform highp sampler2D cc_shadowMap;\nuniform highp sampler2D cc_spotLightingMap;\n#endif\n#if CC_RECEIVE_SHADOW\n#endif\nattribute vec3 a_position;\nattribute vec3 a_normal;\nattribute vec2 a_texCoord;\n#if CC_RECEIVE_SHADOW\nvarying vec2 v_shadowBias;\n#endif\nvarying highp vec3 v_position;\nvarying mediump vec3 v_normal;\nvarying mediump vec2 uvw;\nvarying mediump vec2 uv0;\nvarying mediump vec2 uv1;\nvarying mediump vec2 uv2;\nvarying mediump vec2 uv3;\nvarying mediump vec3 luv;\nvarying mediump vec3 diffuse;\nuniform vec4 UVScale;\nuniform vec4 lightMapUVParam;\nvoid main () {\nvec3 worldPos;\nworldPos.x = cc_matWorld[3][0] + a_position.x;\nworldPos.y = cc_matWorld[3][1] + a_position.y;\nworldPos.z = cc_matWorld[3][2] + a_position.z;\nvec4 pos = vec4(worldPos, 1.0);\npos = cc_matViewProj * pos;\nuvw = a_texCoord;\nuv0 = a_position.xz * UVScale.x;\nuv1 = a_position.xz * UVScale.y;\nuv2 = a_position.xz * UVScale.z;\nuv3 = a_position.xz * UVScale.w;\n#if USE_LIGHTMAP\nluv.xy = lightMapUVParam.xy + a_texCoord * lightMapUVParam.z;\nluv.z = lightMapUVParam.w;\n#endif\nv_position = worldPos;\nv_normal = a_normal;\nCC_TRANSFER_FOG(vec4(worldPos, 1.0));\n#if CC_RECEIVE_SHADOW\nv_shadowBias = vec2(0.0, 0.0);\n#endif\nv_shadowPos = cc_matLightViewProj * vec4(worldPos, 1.0);\ngl_Position = pos;\n}", - "frag": "\n#ifdef GL_EXT_draw_buffers\n#extension GL_EXT_draw_buffers: enable\n#endif\n#ifdef GL_OES_standard_derivatives\n#extension GL_OES_standard_derivatives: enable\n#endif\n#ifdef GL_EXT_shader_texture_lod\n#extension GL_EXT_shader_texture_lod: enable\n#endif\nprecision highp float;\nuniform highp mat4 cc_matView;\nuniform highp vec4 cc_cameraPos;\nuniform mediump vec4 cc_mainLitDir;\nuniform mediump vec4 cc_mainLitColor;\nuniform mediump vec4 cc_ambientSky;\nuniform mediump vec4 cc_ambientGround;\nuniform mediump vec4 cc_fogColor;\nuniform mediump vec4 cc_fogBase;\nuniform mediump vec4 cc_fogAdd;\nuniform mediump vec4 cc_nearFar;\nuniform mediump vec4 cc_viewPort;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nvec3 SRGBToLinear (vec3 gamma) {\nreturn gamma * gamma;\n}\nuniform highp mat4 cc_matLightView;\nuniform highp vec4 cc_shadowInvProjDepthInfo;\nuniform highp vec4 cc_shadowProjDepthInfo;\nuniform highp vec4 cc_shadowProjInfo;\nuniform mediump vec4 cc_shadowNFLSInfo;\nuniform mediump vec4 cc_shadowWHPBInfo;\nuniform mediump vec4 cc_shadowLPNNInfo;\nhighp float unpackHighpData (float mainPart, float modPart) {\nhighp float data = mainPart;\nreturn data + modPart;\n}\nvoid packHighpData (out float mainPart, out float modPart, highp float data) {\nmainPart = fract(data);\nmodPart = data - mainPart;\n}\nhighp float unpackHighpData (float mainPart, float modPart, const float modValue) {\nhighp float data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nvoid packHighpData (out float mainPart, out float modPart, highp float data, const float modValue) {\nhighp float divide = data / modValue;\nmainPart = floor(divide);\nmodPart = (data - mainPart * modValue) / modValue;\n}\nhighp vec2 unpackHighpData (vec2 mainPart, vec2 modPart) {\nhighp vec2 data = mainPart;\nreturn data + modPart;\n}\nvoid packHighpData (out vec2 mainPart, out vec2 modPart, highp vec2 data) {\nmainPart = fract(data);\nmodPart = data - mainPart;\n}\nhighp vec2 unpackHighpData (vec2 mainPart, vec2 modPart, const float modValue) {\nhighp vec2 data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nvoid packHighpData (out vec2 mainPart, out vec2 modPart, highp vec2 data, const float modValue) {\nhighp vec2 divide = data / modValue;\nmainPart = floor(divide);\nmodPart = (data - mainPart * modValue) / modValue;\n}\nhighp vec3 unpackHighpData (vec3 mainPart, vec3 modPart) {\nhighp vec3 data = mainPart;\nreturn data + modPart;\n}\nvoid packHighpData (out vec3 mainPart, out vec3 modPart, highp vec3 data) {\nmainPart = fract(data);\nmodPart = data - mainPart;\n}\nhighp vec3 unpackHighpData (vec3 mainPart, vec3 modPart, const float modValue) {\nhighp vec3 data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nvoid packHighpData (out vec3 mainPart, out vec3 modPart, highp vec3 data, const float modValue) {\nhighp vec3 divide = data / modValue;\nmainPart = floor(divide);\nmodPart = (data - mainPart * modValue) / modValue;\n}\nhighp vec4 unpackHighpData (vec4 mainPart, vec4 modPart) {\nhighp vec4 data = mainPart;\nreturn data + modPart;\n}\nvoid packHighpData (out vec4 mainPart, out vec4 modPart, highp vec4 data) {\nmainPart = fract(data);\nmodPart = data - mainPart;\n}\nhighp vec4 unpackHighpData (vec4 mainPart, vec4 modPart, const float modValue) {\nhighp vec4 data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nvoid packHighpData (out vec4 mainPart, out vec4 modPart, highp vec4 data, const float modValue) {\nhighp vec4 divide = data / modValue;\nmainPart = floor(divide);\nmodPart = (data - mainPart * modValue) / modValue;\n}\nfloat CCGetLinearDepthFromViewSpace(vec3 viewPos) {\nfloat dist = length(viewPos);\nreturn (dist - cc_shadowNFLSInfo.x) / (cc_shadowNFLSInfo.y - cc_shadowNFLSInfo.x);\n}\nfloat CCGetLinearDepth(vec3 worldPos) {\nvec4 viewStartPos = cc_matLightView * vec4(worldPos.xyz, 1.0);\nreturn CCGetLinearDepthFromViewSpace(viewStartPos.xyz);\n}\n#if CC_RECEIVE_SHADOW\nuniform highp sampler2D cc_shadowMap;\nuniform highp sampler2D cc_spotLightingMap;\nvec4 ApplyShadowDepthBias_FaceNormal(vec4 shadowPos, vec3 worldNormal, float normalBias)\n{\nvec4 newShadowPos = shadowPos;\nif(normalBias > EPSILON_LOWP)\n{\nvec4 viewNormal = cc_matLightView * vec4(worldNormal, 0.0);\nif(viewNormal.z < 0.1)\nnewShadowPos.xy += viewNormal.xy * cc_shadowProjInfo.xy * normalBias * clamp(viewNormal.z, 0.001, 0.1);\n}\nreturn newShadowPos;\n}\nvec4 ApplyShadowDepthBias_Perspective(vec4 shadowPos, float viewspaceDepthBias)\n{\nvec3 viewSpacePos;\nviewSpacePos.xy = shadowPos.xy * cc_shadowProjInfo.zw;\nviewSpacePos.z = shadowPos.z * cc_shadowInvProjDepthInfo.x + shadowPos.w * cc_shadowInvProjDepthInfo.y;\nviewSpacePos.xyz += cc_shadowProjDepthInfo.z * normalize(viewSpacePos.xyz) * viewspaceDepthBias;\nvec4 clipSpacePos;\nclipSpacePos.xy = viewSpacePos.xy * cc_shadowProjInfo.xy;\nclipSpacePos.zw = viewSpacePos.z * cc_shadowProjDepthInfo.xz + vec2(cc_shadowProjDepthInfo.y, 0.0);\nif (cc_shadowNFLSInfo.z > EPSILON) {\nclipSpacePos.z = CCGetLinearDepthFromViewSpace(viewSpacePos.xyz);\nclipSpacePos.z = (clipSpacePos.z * 2.0 - 1.0) * clipSpacePos.w;\n}\nreturn clipSpacePos;\n}\nvec4 ApplyShadowDepthBias_Orthographic(vec4 shadowPos, float viewspaceDepthBias)\n{\nfloat coeffA = cc_shadowProjDepthInfo.x;\nfloat coeffB = cc_shadowProjDepthInfo.y;\nfloat viewSpacePos_z = (shadowPos.z - coeffB) / coeffA;\nviewSpacePos_z += viewspaceDepthBias;\nvec4 result = shadowPos;\nresult.z = viewSpacePos_z * coeffA + coeffB;\nreturn result;\n}\nfloat CCGetShadowFactorHard (vec4 shadowPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Orthographic(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat shadow = 0.0;\nfloat closestDepth = 0.0;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nclosestDepth = dot(texture2D(cc_shadowMap, clipPos.xy), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0));\n} else {\nclosestDepth = texture2D(cc_shadowMap, clipPos.xy).x;\n}\nshadow = step(clipPos.z, closestDepth);\nreturn shadow;\n}\nfloat CCGetShadowFactorSoft (vec4 shadowPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Orthographic(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat offsetDepth = clipPos.z;\nvec2 mapSize = cc_shadowWHPBInfo.xy;\nvec2 oneTap = 1.0 / mapSize;\nvec2 clipPos_offset = clipPos.xy + oneTap;\nfloat block0, block1, block2, block3;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos_offset.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos_offset.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos.x, clipPos.y)).x);\nblock1 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos_offset.x, clipPos.y)).x);\nblock2 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos.x, clipPos_offset.y)).x);\nblock3 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos_offset.x, clipPos_offset.y)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * mapSize.x;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block2, block3, coefX);\nfloat coefY = mod(clipPos.y, oneTap.y) * mapSize.y;\nreturn mix(resultX, resultY, coefY);\n}\nfloat CCGetShadowFactorSoft2X (vec4 shadowPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Orthographic(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat offsetDepth = clipPos.z;\nvec2 mapSize = cc_shadowWHPBInfo.xy;\nvec2 oneTap = 1.0 / mapSize;\nfloat clipPos_offset_L = clipPos.x - oneTap.x;\nfloat clipPos_offset_R = clipPos.x + oneTap.x;\nfloat clipPos_offset_U = clipPos.y - oneTap.y;\nfloat clipPos_offset_D = clipPos.y + oneTap.y;\nfloat block0, block1, block2, block3, block4, block5, block6, block7, block8;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos.x, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos_offset_L, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock4 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock5 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos_offset_R, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock6 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock7 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos.x, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock8 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_U)).x);\nblock1 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos.x, clipPos_offset_U)).x);\nblock2 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_U)).x);\nblock3 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos_offset_L, clipPos.y)).x);\nblock4 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos.x, clipPos.y)).x);\nblock5 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos_offset_R, clipPos.y)).x);\nblock6 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_D)).x);\nblock7 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos.x, clipPos_offset_D)).x);\nblock8 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_D)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * mapSize.x;\nfloat coefY = mod(clipPos.y, oneTap.y) * mapSize.y;\nfloat shadow = 0.0;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block3, block4, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block1, block2, coefX);\nresultY = mix(block4, block5, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block3, block4, coefX);\nresultY = mix(block6, block7, coefX);\nshadow += mix(resultX, resultY, coefY);\nresultX = mix(block4, block5, coefX);\nresultY = mix(block7, block8, coefX);\nshadow += mix(resultX, resultY, coefY);\nreturn shadow * 0.25;\n}\nfloat CCGetSpotLightShadowFactorHard (vec4 shadowPos, vec3 worldPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Perspective(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat shadow = 0.0;\nfloat closestDepth = 0.0;\nfloat depth = clipPos.z;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nclosestDepth = dot(texture2D(cc_spotLightingMap, clipPos.xy), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0));\n} else {\nclosestDepth = texture2D(cc_spotLightingMap, clipPos.xy).x;\n}\nshadow = step(depth, closestDepth);\nreturn shadow;\n}\nfloat CCGetSpotLightShadowFactorSoft (vec4 shadowPos, vec3 worldPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Perspective(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat depth = 0.0;\nif (cc_shadowNFLSInfo.z > EPSILON) {\ndepth = CCGetLinearDepth(worldPos);\n} else {\ndepth = clipPos.z;\n}\nvec2 oneTap = 1.0 / cc_shadowWHPBInfo.xy;\nvec2 clipPos_offset = clipPos.xy + oneTap;\nfloat block0, block1, block2, block3;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)).x);\nblock1 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos.y)).x);\nblock2 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset.y)).x);\nblock3 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos_offset.y)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * cc_shadowWHPBInfo.x;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block2, block3, coefX);\nfloat coefY = mod(clipPos.y, oneTap.y) * cc_shadowWHPBInfo.y;\nreturn mix(resultX, resultY, coefY);\n}\nfloat CCGetSpotLightShadowFactorSoft2X (vec4 shadowPos, vec3 worldPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Perspective(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat depth = 0.0;\nif (cc_shadowNFLSInfo.z > EPSILON) {\ndepth = CCGetLinearDepth(worldPos);\n} else {\ndepth = clipPos.z;\n}\nvec2 mapSize = cc_shadowWHPBInfo.xy;\nvec2 oneTap = 1.0 / mapSize;\nfloat clipPos_offset_L = clipPos.x - oneTap.x;\nfloat clipPos_offset_R = clipPos.x + oneTap.x;\nfloat clipPos_offset_U = clipPos.y - oneTap.y;\nfloat clipPos_offset_D = clipPos.y + oneTap.y;\nfloat block0, block1, block2, block3, block4, block5, block6, block7, block8;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock4 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock5 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock6 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock7 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock8 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_U)).x);\nblock1 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_U)).x);\nblock2 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_U)).x);\nblock3 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos.y)).x);\nblock4 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)).x);\nblock5 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos.y)).x);\nblock6 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_D)).x);\nblock7 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_D)).x);\nblock8 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_D)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * mapSize.x;\nfloat coefY = mod(clipPos.y, oneTap.y) * mapSize.y;\nfloat shadow = 0.0;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block3, block4, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block1, block2, coefX);\nresultY = mix(block4, block5, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block3, block4, coefX);\nresultY = mix(block6, block7, coefX);\nshadow += mix(resultX, resultY, coefY);\nresultX = mix(block4, block5, coefX);\nresultY = mix(block7, block8, coefX);\nshadow += mix(resultX, resultY, coefY);\nreturn shadow * 0.25;\n}\nfloat CCSpotShadowFactorBase(vec4 shadowPos, vec3 worldPos, vec2 shadowBias)\n{\nfloat pcf = cc_shadowWHPBInfo.z;\nif (pcf > 1.9) {\nreturn CCGetSpotLightShadowFactorSoft2X(shadowPos, worldPos, shadowBias.x);\n}else if (pcf > 0.9) {\nreturn CCGetSpotLightShadowFactorSoft(shadowPos, worldPos, shadowBias.x);\n}else {\nreturn CCGetSpotLightShadowFactorHard(shadowPos, worldPos, shadowBias.x);\n}\n}\nfloat CCShadowFactorBase(vec4 shadowPos, vec3 N, vec2 shadowBias)\n{\nfloat realtimeShadow = 1.0;\nvec4 pos = ApplyShadowDepthBias_FaceNormal(shadowPos, N, shadowBias.y);\nfloat pcf = cc_shadowWHPBInfo.z;\nif (pcf > 1.9) {\nrealtimeShadow = CCGetShadowFactorSoft2X(pos, shadowBias.x);\n}else if (pcf > 0.9) {\nrealtimeShadow = CCGetShadowFactorSoft(pos, shadowBias.x);\n}else {\nrealtimeShadow = CCGetShadowFactorHard(pos, shadowBias.x);\n}\nreturn mix(realtimeShadow, 1.0, cc_shadowNFLSInfo.w);\n}\n#endif\n#if CC_USE_IBL\nuniform samplerCube cc_environment;\nvec4 fragTextureLod (sampler2D tex, vec2 coord, float lod) {\n#ifdef GL_EXT_shader_texture_lod\nreturn texture2DLodEXT(tex, coord, lod);\n#else\nreturn texture2D(tex, coord, lod);\n#endif\n}\nvec4 fragTextureLod (samplerCube tex, vec3 coord, float lod) {\n#ifdef GL_EXT_shader_texture_lod\nreturn textureCubeLodEXT(tex, coord, lod);\n#else\nreturn textureCube(tex, coord, lod);\n#endif\n}\nvec3 unpackRGBE (vec4 rgbe) {\nreturn rgbe.rgb * pow(1.1, rgbe.a * 255.0 - 128.0);\n}\n#if CC_USE_DIFFUSEMAP\nuniform samplerCube cc_diffuseMap;\n#endif\n#endif\nfloat GGXMobile (float roughness, float NoH, vec3 H, vec3 N) {\nvec3 NxH = cross(N, H);\nfloat OneMinusNoHSqr = dot(NxH, NxH);\nfloat a = roughness * roughness;\nfloat n = NoH * a;\nfloat p = a / (OneMinusNoHSqr + n * n);\nreturn p * p;\n}\nfloat CalcSpecular (float roughness, float NoH, vec3 H, vec3 N) {\nreturn (roughness * 0.25 + 0.25) * GGXMobile(roughness, NoH, H, N);\n}\nvec3 BRDFApprox (vec3 specular, float roughness, float NoV) {\nconst vec4 c0 = vec4(-1.0, -0.0275, -0.572, 0.022);\nconst vec4 c1 = vec4(1.0, 0.0425, 1.04, -0.04);\nvec4 r = roughness * c0 + c1;\nfloat a004 = min(r.x * r.x, exp2(-9.28 * NoV)) * r.x + r.y;\nvec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;\nAB.y *= clamp(50.0 * specular.g, 0.0, 1.0);\nreturn specular * AB.x + AB.y;\n}\n#if USE_REFLECTION_DENOISE\nvec3 GetEnvReflectionWithMipFiltering(vec3 R, float roughness, float mipCount, float denoiseIntensity) {\n#if CC_USE_IBL\nfloat mip = roughness * mipCount;\nfloat delta = (dot(dFdx(R), dFdy(R))) * 1000.0;\nfloat mipBias = mix(0.0, 5.0, clamp(delta, 0.0, 1.0));\nvec4 biased = fragTextureLod(cc_environment, R, mip + mipBias);\nvec4 filtered = textureCube(cc_environment, R);\n#if CC_USE_IBL == 2\nbiased.rgb = unpackRGBE(biased);\nfiltered.rgb = unpackRGBE(filtered);\n#else\nbiased.rgb = SRGBToLinear(biased.rgb);\nfiltered.rgb = SRGBToLinear(filtered.rgb);\n#endif\nreturn mix(biased.rgb, filtered.rgb, denoiseIntensity);\n#else\nreturn vec3(0.0, 0.0, 0.0);\n#endif\n}\n#endif\nstruct StandardSurface {\nvec4 albedo;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nvec3 position, position_fract_part;\n#else\nvec3 position;\n#endif\nvec3 normal;\nvec3 emissive;\nvec3 lightmap;\nfloat lightmap_test;\nfloat roughness;\nfloat metallic;\nfloat occlusion;\nfloat specularIntensity;\n#if CC_RECEIVE_SHADOW\nvec2 shadowBias;\n#endif\n};\nvec4 CCStandardShadingBase (StandardSurface s, vec4 shadowPos) {\nvec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\nvec3 specular = mix(vec3(0.08 * s.specularIntensity), s.albedo.rgb, s.metallic);\nvec3 position;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nposition = unpackHighpData(s.position, s.position_fract_part);\n#else\nposition = s.position;\n#endif\nvec3 N = normalize(s.normal);\nvec3 V = normalize(cc_cameraPos.xyz - position);\nfloat NV = max(abs(dot(N, V)), 0.0);\nspecular = BRDFApprox(specular, s.roughness, NV);\nvec3 L = normalize(-cc_mainLitDir.xyz);\nvec3 H = normalize(L + V);\nfloat NH = max(dot(N, H), 0.0);\nfloat NL = max(dot(N, L), 0.0);\nvec3 finalColor = NL * cc_mainLitColor.rgb * cc_mainLitColor.w;\nvec3 diffuseContrib = diffuse / PI;\nvec3 specularContrib = specular * CalcSpecular(s.roughness, NH, H, N);\nvec3 dirlightContrib = (diffuseContrib + specularContrib);\nfloat shadow = 1.0;\n#if CC_RECEIVE_SHADOW\nif (NL > 0.0 && cc_mainLitDir.w > 0.0) {\nshadow = CCShadowFactorBase(shadowPos, N, s.shadowBias);\n}\n#endif\ndirlightContrib *= shadow;\nfinalColor *= dirlightContrib;\n#if USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\nif (s.lightmap_test > EPSILON_LOWP) {\nfinalColor = diffuse * s.lightmap.rgb * shadow;\n}\n#endif\nfloat fAmb = 0.5 - N.y * 0.5;\nvec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb);\n#if CC_USE_IBL\n#if CC_USE_DIFFUSEMAP\nvec4 diffuseMap = textureCube(cc_diffuseMap, N);\n#if CC_USE_DIFFUSEMAP == 2\nambDiff = unpackRGBE(diffuseMap);\n#else\nambDiff = SRGBToLinear(diffuseMap.rgb);\n#endif\n#endif\nvec3 R = normalize(reflect(-V, N));\n#if USE_REFLECTION_DENOISE\nvec3 env = GetEnvReflectionWithMipFiltering(R, s.roughness, cc_ambientGround.w, 0.6);\n#else\nvec4 envmap = fragTextureLod(cc_environment, R, s.roughness * cc_ambientGround.w);\n#if CC_USE_IBL == 2\nvec3 env = unpackRGBE(envmap);\n#else\nvec3 env = SRGBToLinear(envmap.rgb);\n#endif\n#endif\nfinalColor += env * cc_ambientSky.w * specular * s.occlusion;\n#endif\nfinalColor += ambDiff.rgb * cc_ambientSky.w * diffuse * s.occlusion;\nfinalColor += s.emissive;\nreturn vec4(finalColor, s.albedo.a);\n}\nvec3 ACESToneMap (vec3 color) {\ncolor = min(color, vec3(8.0));\nconst float A = 2.51;\nconst float B = 0.03;\nconst float C = 2.43;\nconst float D = 0.59;\nconst float E = 0.14;\nreturn (color * (A * color + B)) / (color * (C * color + D) + E);\n}\nvec4 CCFragOutput (vec4 color) {\n#if CC_USE_HDR\ncolor.rgb = ACESToneMap(color.rgb);\n#endif\ncolor.rgb = sqrt(color.rgb);\nreturn color;\n}\nfloat LinearFog(vec4 pos) {\nvec4 wPos = pos;\nfloat cam_dis = distance(cc_cameraPos, wPos);\nfloat fogStart = cc_fogBase.x;\nfloat fogEnd = cc_fogBase.y;\nreturn clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * fogDensity);\nreturn f;\n}\nfloat ExpSquaredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\nreturn f;\n}\nfloat LayeredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat _FogTop = cc_fogAdd.x;\nfloat _FogRange = cc_fogAdd.y;\nvec3 camWorldProj = cc_cameraPos.xyz;\ncamWorldProj.y = 0.;\nvec3 worldPosProj = wPos.xyz;\nworldPosProj.y = 0.;\nfloat fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\nfloat fDeltaY, fDensityIntegral;\nif (cc_cameraPos.y > _FogTop) {\nif (wPos.y < _FogTop) {\nfDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\nfDensityIntegral = fDeltaY * fDeltaY * 0.5;\n} else {\nfDeltaY = 0.;\nfDensityIntegral = 0.;\n}\n} else {\nif (wPos.y < _FogTop) {\nfloat fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfloat fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\nfDeltaY = abs(fDeltaA - fDeltaB);\nfDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n} else {\nfDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n}\n}\nfloat fDensity;\nif (fDeltaY != 0.) {\nfDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n} else {\nfDensity = 0.;\n}\nfloat f = exp(-fDensity);\nreturn f;\n}\nvoid CC_TRANSFER_FOG_BASE(vec4 pos, out float factor)\n{\n#if CC_USE_FOG == 0\nfactor = LinearFog(pos);\n#elif CC_USE_FOG == 1\nfactor = ExpFog(pos);\n#elif CC_USE_FOG == 2\nfactor = ExpSquaredFog(pos);\n#elif CC_USE_FOG == 3\nfactor = LayeredFog(pos);\n#else\nfactor = 1.0;\n#endif\n}\nvoid CC_APPLY_FOG_BASE(inout vec4 color, float factor) {\ncolor = vec4(mix(cc_fogColor.rgb, color.rgb, factor), color.a);\n}\n#if !CC_USE_ACCURATE_FOG\nvarying float v_fog_factor;\n#endif\nvoid CC_APPLY_FOG(inout vec4 color) {\n#if !CC_USE_ACCURATE_FOG\nCC_APPLY_FOG_BASE(color, v_fog_factor);\n#endif\n}\nvoid CC_APPLY_FOG(inout vec4 color, vec3 worldPos) {\n#if CC_USE_ACCURATE_FOG\nfloat factor;\nCC_TRANSFER_FOG_BASE(vec4(worldPos, 1.0), factor);\n#else\nfloat factor = v_fog_factor;\n#endif\nCC_APPLY_FOG_BASE(color, factor);\n}\nvarying highp vec4 v_shadowPos;\n#if CC_RECEIVE_SHADOW\n#endif\n#if USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\nvarying vec3 v_luv;\nuniform sampler2D cc_lightingMap;\n#endif\nvarying highp vec3 v_position;\nvarying mediump vec3 v_normal;\n#if CC_RECEIVE_SHADOW\nvarying vec2 v_shadowBias;\n#endif\nvarying mediump vec2 uvw;\nvarying mediump vec2 uv0;\nvarying mediump vec2 uv1;\nvarying mediump vec2 uv2;\nvarying mediump vec2 uv3;\nvarying mediump vec3 diffuse;\nvarying mediump vec3 luv;\nuniform vec4 metallic;\nuniform vec4 roughness;\nuniform sampler2D weightMap;\nuniform sampler2D detailMap0;\nuniform sampler2D detailMap1;\nuniform sampler2D detailMap2;\nuniform sampler2D detailMap3;\nuniform sampler2D normalMap0;\nuniform sampler2D normalMap1;\nuniform sampler2D normalMap2;\nuniform sampler2D normalMap3;\nuniform sampler2D lightMap;\nvoid surf (out StandardSurface s) {\n#if LAYERS > 1\nvec4 w = texture2D(weightMap, uvw);\n#endif\nvec4 baseColor = vec4(0, 0, 0, 0);\n#if LAYERS == 1\nbaseColor = texture2D(detailMap0, uv0);\n#elif LAYERS == 2\nbaseColor += texture2D(detailMap0, uv0) * w.r;\nbaseColor += texture2D(detailMap1, uv1) * w.g;\n#elif LAYERS == 3\nbaseColor += texture2D(detailMap0, uv0) * w.r;\nbaseColor += texture2D(detailMap1, uv1) * w.g;\nbaseColor += texture2D(detailMap2, uv2) * w.b;\n#elif LAYERS == 4\nbaseColor += texture2D(detailMap0, uv0) * w.r;\nbaseColor += texture2D(detailMap1, uv1) * w.g;\nbaseColor += texture2D(detailMap2, uv2) * w.b;\nbaseColor += texture2D(detailMap3, uv3) * w.a;\n#else\nbaseColor = texture2D(detailMap0, uv0);\n#endif\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\npackHighpData(s.position, s.position_fract_part, v_position);\n#else\ns.position = v_position;\n#endif\n#if USE_NORMALMAP\nvec4 baseNormal = vec4(0, 0, 0, 0);\n#if LAYERS == 1\nbaseNormal = texture2D(normalMap0, uv0);\n#elif LAYERS == 2\nbaseNormal += texture2D(normalMap0, uv0) * w.r;\nbaseNormal += texture2D(normalMap1, uv1) * w.g;\n#elif LAYERS == 3\nbaseNormal += texture2D(normalMap0, uv0) * w.r;\nbaseNormal += texture2D(normalMap1, uv1) * w.g;\nbaseNormal += texture2D(normalMap2, uv2) * w.b;\n#elif LAYERS == 4\nbaseNormal += texture2D(normalMap0, uv0) * w.r;\nbaseNormal += texture2D(normalMap1, uv1) * w.g;\nbaseNormal += texture2D(normalMap2, uv2) * w.b;\nbaseNormal += texture2D(normalMap3, uv3) * w.a;\n#else\nbaseNormal = texture2D(normalMap0, uv0);\n#endif\nvec3 tangent = vec3(1.0, 0.0, 0.0);\nvec3 binormal = vec3(0.0, 0.0, 1.0);\nbinormal = cross(tangent, v_normal);\ntangent = cross(v_normal, binormal);\nvec3 nmmp = baseNormal.xyz - vec3(0.5);\ns.normal =\nnmmp.x * normalize(tangent) +\nnmmp.y * normalize(binormal) +\nnmmp.z * normalize(v_normal);\n#else\ns.normal = v_normal;\n#endif\n#if CC_RECEIVE_SHADOW\ns.shadowBias = v_shadowBias;\n#endif\ns.albedo = vec4(SRGBToLinear(baseColor.rgb), 1.0);\ns.occlusion = 1.0;\n#if USE_PBR\ns.roughness = 0.0;\n#if LAYERS == 1\ns.roughness = roughness.x;\n#elif LAYERS == 2\ns.roughness += roughness.x * w.r;\ns.roughness += roughness.y * w.g;\n#elif LAYERS == 3\ns.roughness += roughness.x * w.r;\ns.roughness += roughness.y * w.g;\ns.roughness += roughness.z * w.b;\n#elif LAYERS == 4\ns.roughness += roughness.x * w.r;\ns.roughness += roughness.y * w.g;\ns.roughness += roughness.z * w.b;\ns.roughness += roughness.w * w.a;\n#else\ns.roughness = 1.0;\n#endif\ns.specularIntensity = 0.5;\ns.metallic = 0.0;\n#if LAYERS == 1\ns.specularIntensity = 0.5;\ns.metallic = metallic.x;\n#elif LAYERS == 2\ns.metallic += metallic.x * w.r;\ns.metallic += metallic.y * w.g;\n#elif LAYERS == 3\ns.metallic += metallic.x * w.r;\ns.metallic += metallic.y * w.g;\ns.metallic += metallic.z * w.b;\n#elif LAYERS == 4\ns.metallic += metallic.x * w.r;\ns.metallic += metallic.y * w.g;\ns.metallic += metallic.z * w.b;\ns.metallic += metallic.w * w.a;\n#else\ns.specularIntensity = 0.5;\ns.metallic = 0.0;\n#endif\n#else\ns.roughness = 1.0;\ns.specularIntensity = 0.5;\ns.metallic = 0.0;\n#endif\ns.emissive = vec3(0.0, 0.0, 0.0);\n#if USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\nvec4 lightColor = texture2D(lightMap, luv.xy);\ns.lightmap = lightColor.xyz * luv.z;\ns.lightmap_test = luv.z;\n#endif\n}\n#if CC_FORWARD_ADD\n#if CC_PIPELINE_TYPE == 0\n#define LIGHTS_PER_PASS 1\n#else\n#define LIGHTS_PER_PASS 10\n#endif\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 0\nuniform highp vec4 cc_lightPos[LIGHTS_PER_PASS];\nuniform vec4 cc_lightColor[LIGHTS_PER_PASS];\nuniform vec4 cc_lightSizeRangeAngle[LIGHTS_PER_PASS];\nuniform vec4 cc_lightDir[LIGHTS_PER_PASS];\n#endif\nfloat SmoothDistAtt (float distSqr, float invSqrAttRadius) {\nfloat factor = distSqr * invSqrAttRadius;\nfloat smoothFactor = clamp(1.0 - factor * factor, 0.0, 1.0);\nreturn smoothFactor * smoothFactor;\n}\nfloat GetDistAtt (float distSqr, float invSqrAttRadius) {\nfloat attenuation = 1.0 / max(distSqr, 0.01*0.01);\nattenuation *= SmoothDistAtt(distSqr , invSqrAttRadius);\nreturn attenuation;\n}\nfloat GetAngleAtt (vec3 L, vec3 litDir, float litAngleScale, float litAngleOffset) {\nfloat cd = dot(litDir, L);\nfloat attenuation = clamp(cd * litAngleScale + litAngleOffset, 0.0, 1.0);\nreturn (attenuation * attenuation);\n}\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 0\nvec4 CCStandardShadingAdditive (StandardSurface s, vec4 shadowPos) {\nvec3 position;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nposition = unpackHighpData(s.position, s.position_fract_part);\n#else\nposition = s.position;\n#endif\nvec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\nvec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\nvec3 diffuseContrib = diffuse / PI;\nvec3 N = normalize(s.normal);\nvec3 V = normalize(cc_cameraPos.xyz - position);\nfloat NV = max(abs(dot(N, V)), 0.0);\nspecular = BRDFApprox(specular, s.roughness, NV);\nvec3 finalColor = vec3(0.0);\nint numLights = CC_PIPELINE_TYPE == 0 ? LIGHTS_PER_PASS : int(cc_lightDir[0].w);\nfor (int i = 0; i < LIGHTS_PER_PASS; i++) {\nif (i >= numLights) break;\nvec3 SLU = cc_lightPos[i].xyz - position;\nvec3 SL = normalize(SLU);\nvec3 SH = normalize(SL + V);\nfloat SNL = max(dot(N, SL), 0.0);\nfloat SNH = max(dot(N, SH), 0.0);\nfloat distSqr = dot(SLU, SLU);\nfloat litRadius = cc_lightSizeRangeAngle[i].x;\nfloat litRadiusSqr = litRadius * litRadius;\nfloat illum = litRadiusSqr / max(litRadiusSqr, distSqr);\nfloat attRadiusSqrInv = 1.0 / max(cc_lightSizeRangeAngle[i].y, 0.01);\nattRadiusSqrInv *= attRadiusSqrInv;\nfloat att = GetDistAtt(distSqr, attRadiusSqrInv);\nvec3 lspec = specular * CalcSpecular(s.roughness, SNH, SH, N);\nif (cc_lightPos[i].w > 0.0) {\nfloat cosInner = max(dot(-cc_lightDir[i].xyz, SL), 0.01);\nfloat cosOuter = cc_lightSizeRangeAngle[i].z;\nfloat litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\nfloat litAngleOffset = -cosOuter * litAngleScale;\natt *= GetAngleAtt(SL, -cc_lightDir[i].xyz, litAngleScale, litAngleOffset);\n}\nvec3 lightColor = cc_lightColor[i].rgb;\nfloat shadow = 1.0;\n#if CC_RECEIVE_SHADOW\nif (cc_lightPos[i].w > 0.0 && cc_lightSizeRangeAngle[i].w > 0.0) {\nshadow = CCSpotShadowFactorBase(shadowPos, position, s.shadowBias);\n}\n#endif\nlightColor *= shadow;\nfinalColor += SNL * lightColor * cc_lightColor[i].w * illum * att * (diffuseContrib + lspec);\n}\nreturn vec4(finalColor, 0.0);\n}\n#endif\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 1\nreadonly buffer b_ccLightsBuffer { vec4 b_ccLights[]; };\nreadonly buffer b_clusterLightIndicesBuffer { uint b_clusterLightIndices[]; };\nreadonly buffer b_clusterLightGridBuffer { uvec4 b_clusterLightGrid[]; };\nstruct CCLight\n{\nvec4 cc_lightPos;\nvec4 cc_lightColor;\nvec4 cc_lightSizeRangeAngle;\nvec4 cc_lightDir;\n};\nstruct Cluster\n{\nvec3 minBounds;\nvec3 maxBounds;\n};\nstruct LightGrid\n{\nuint offset;\nuint ccLights;\n};\nCCLight getCCLight(uint i)\n{\nCCLight light;\nlight.cc_lightPos = b_ccLights[4u * i + 0u];\nlight.cc_lightColor = b_ccLights[4u * i + 1u];\nlight.cc_lightSizeRangeAngle = b_ccLights[4u * i + 2u];\nlight.cc_lightDir = b_ccLights[4u * i + 3u];\nreturn light;\n}\nLightGrid getLightGrid(uint cluster)\n{\nuvec4 gridvec = b_clusterLightGrid[cluster];\nLightGrid grid;\ngrid.offset = gridvec.x;\ngrid.ccLights = gridvec.y;\nreturn grid;\n}\nuint getGridLightIndex(uint start, uint offset)\n{\nreturn b_clusterLightIndices[start + offset];\n}\nuint getClusterZIndex(vec4 worldPos)\n{\nfloat scale = float(24) / log(cc_nearFar.y / cc_nearFar.x);\nfloat bias = -(float(24) * log(cc_nearFar.x) / log(cc_nearFar.y / cc_nearFar.x));\nfloat eyeDepth = -(cc_matView * worldPos).z;\nuint zIndex = uint(max(log(eyeDepth) * scale + bias, 0.0));\nreturn zIndex;\n}\nuint getClusterIndex(vec4 fragCoord, vec4 worldPos)\n{\nuint zIndex = getClusterZIndex(worldPos);\nfloat clusterSizeX = ceil(cc_viewPort.z / float(16));\nfloat clusterSizeY = ceil(cc_viewPort.w / float(8));\nuvec3 indices = uvec3(uvec2(fragCoord.xy / vec2(clusterSizeX, clusterSizeY)), zIndex);\nuint cluster = (16u * 8u) * indices.z + 16u * indices.y + indices.x;\nreturn cluster;\n}\nvec4 CCClusterShadingAdditive (StandardSurface s, vec4 shadowPos) {\nvec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\nvec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\nvec3 diffuseContrib = diffuse / PI;\nvec3 position;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nposition = unpackHighpData(s.position, s.position_fract_part);\n#else\nposition = s.position;\n#endif\nvec3 N = normalize(s.normal);\nvec3 V = normalize(cc_cameraPos.xyz - position);\nfloat NV = max(abs(dot(N, V)), 0.001);\nspecular = BRDFApprox(specular, s.roughness, NV);\nvec3 finalColor = vec3(0.0);\nuint cluster = getClusterIndex(gl_FragCoord, vec4(position, 1.0));\nLightGrid grid = getLightGrid(cluster);\nuint numLights = grid.ccLights;\nfor (uint i = 0u; i < 100u; i++) {\nif (i >= numLights) break;\nuint lightIndex = getGridLightIndex(grid.offset, i);\nCCLight light = getCCLight(lightIndex);\nvec3 SLU = light.cc_lightPos.xyz - position;\nvec3 SL = normalize(SLU);\nvec3 SH = normalize(SL + V);\nfloat SNL = max(dot(N, SL), 0.001);\nfloat SNH = max(dot(N, SH), 0.0);\nfloat distSqr = dot(SLU, SLU);\nfloat litRadius = light.cc_lightSizeRangeAngle.x;\nfloat litRadiusSqr = litRadius * litRadius;\nfloat illum = PI * (litRadiusSqr / max(litRadiusSqr , distSqr));\nfloat attRadiusSqrInv = 1.0 / max(light.cc_lightSizeRangeAngle.y, 0.01);\nattRadiusSqrInv *= attRadiusSqrInv;\nfloat att = GetDistAtt(distSqr, attRadiusSqrInv);\nvec3 lspec = specular * CalcSpecular(s.roughness, SNH, SH, N);\nif (light.cc_lightPos.w > 0.0) {\nfloat cosInner = max(dot(-light.cc_lightDir.xyz, SL), 0.01);\nfloat cosOuter = light.cc_lightSizeRangeAngle.z;\nfloat litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\nfloat litAngleOffset = -cosOuter * litAngleScale;\natt *= GetAngleAtt(SL, -light.cc_lightDir.xyz, litAngleScale, litAngleOffset);\n}\nvec3 lightColor = light.cc_lightColor.rgb;\nfloat shadow = 1.0;\n#if CC_RECEIVE_SHADOW\nif (light.cc_lightPos.w > 0.0) {\nshadow = CCSpotShadowFactorBase(shadowPos, position, s.shadowBias);\n}\n#endif\nlightColor *= shadow;\nfinalColor += SNL * lightColor * light.cc_lightColor.w * illum * att * (diffuseContrib + lspec);\n}\nreturn vec4(finalColor, 0.0);\n}\n#endif\nvoid main () {\nStandardSurface s; surf(s);\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 1\nvec4 color = CCClusterShadingAdditive(s, v_shadowPos);\n#else\nvec4 color = CCStandardShadingAdditive(s, v_shadowPos);\n#endif\ngl_FragData[0] = CCFragOutput(color);\n}\n#elif (CC_PIPELINE_TYPE == 0 || CC_FORCE_FORWARD_SHADING)\nvoid main () {\nStandardSurface s; surf(s);\nvec4 color = CCStandardShadingBase(s, v_shadowPos);\nCC_APPLY_FOG(color, s.position.xyz);\ngl_FragData[0] = CCFragOutput(color);\n}\n#elif CC_PIPELINE_TYPE == 1\nvec2 signNotZero(vec2 v) {\nreturn vec2((v.x >= 0.0) ? +1.0 : -1.0, (v.y >= 0.0) ? +1.0 : -1.0);\n}\nvec2 float32x3_to_oct(in vec3 v) {\nvec2 p = v.xy * (1.0 / (abs(v.x) + abs(v.y) + abs(v.z)));\nreturn (v.z <= 0.0) ? ((1.0 - abs(p.yx)) * signNotZero(p)) : p;\n}\nvoid main () {\nStandardSurface s; surf(s);\ngl_FragData[0] = s.albedo;\ngl_FragData[1] = vec4(float32x3_to_oct(s.normal), s.roughness, s.metallic);\ngl_FragData[2] = vec4(s.emissive, s.occlusion);\n}\n#endif", + "vert": "\nprecision mediump float;\nuniform highp mat4 cc_matViewProj;\nuniform highp vec4 cc_cameraPos;\nuniform mediump vec4 cc_fogBase;\nuniform mediump vec4 cc_fogAdd;\nuniform highp mat4 cc_matWorld;\nfloat LinearFog(vec4 pos) {\nvec4 wPos = pos;\nfloat cam_dis = distance(cc_cameraPos, wPos);\nfloat fogStart = cc_fogBase.x;\nfloat fogEnd = cc_fogBase.y;\nreturn clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * fogDensity);\nreturn f;\n}\nfloat ExpSquaredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\nreturn f;\n}\nfloat LayeredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat _FogTop = cc_fogAdd.x;\nfloat _FogRange = cc_fogAdd.y;\nvec3 camWorldProj = cc_cameraPos.xyz;\ncamWorldProj.y = 0.;\nvec3 worldPosProj = wPos.xyz;\nworldPosProj.y = 0.;\nfloat fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\nfloat fDeltaY, fDensityIntegral;\nif (cc_cameraPos.y > _FogTop) {\nif (wPos.y < _FogTop) {\nfDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\nfDensityIntegral = fDeltaY * fDeltaY * 0.5;\n} else {\nfDeltaY = 0.;\nfDensityIntegral = 0.;\n}\n} else {\nif (wPos.y < _FogTop) {\nfloat fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfloat fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\nfDeltaY = abs(fDeltaA - fDeltaB);\nfDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n} else {\nfDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n}\n}\nfloat fDensity;\nif (fDeltaY != 0.) {\nfDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n} else {\nfDensity = 0.;\n}\nfloat f = exp(-fDensity);\nreturn f;\n}\nvoid CC_TRANSFER_FOG_BASE(vec4 pos, out float factor)\n{\n#if CC_USE_FOG == 0\nfactor = LinearFog(pos);\n#elif CC_USE_FOG == 1\nfactor = ExpFog(pos);\n#elif CC_USE_FOG == 2\nfactor = ExpSquaredFog(pos);\n#elif CC_USE_FOG == 3\nfactor = LayeredFog(pos);\n#else\nfactor = 1.0;\n#endif\n}\n#if !CC_USE_ACCURATE_FOG\nvarying float v_fog_factor;\n#endif\nvoid CC_TRANSFER_FOG(vec4 pos) {\n#if !CC_USE_ACCURATE_FOG\nCC_TRANSFER_FOG_BASE(pos, v_fog_factor);\n#endif\n}\nvarying highp vec4 v_shadowPos;\nuniform highp mat4 cc_matLightViewProj;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\n#if CC_RECEIVE_SHADOW\nuniform highp sampler2D cc_shadowMap;\nuniform highp sampler2D cc_spotLightingMap;\n#endif\n#if CC_RECEIVE_SHADOW\n#endif\nattribute vec3 a_position;\nattribute vec3 a_normal;\nattribute vec2 a_texCoord;\n#if CC_RECEIVE_SHADOW\nvarying vec2 v_shadowBias;\n#endif\nvarying highp vec3 v_position;\nvarying mediump vec3 v_normal;\nvarying mediump vec2 uvw;\nvarying mediump vec2 uv0;\nvarying mediump vec2 uv1;\nvarying mediump vec2 uv2;\nvarying mediump vec2 uv3;\nvarying mediump vec3 luv;\nvarying mediump vec3 diffuse;\nuniform vec4 UVScale;\nuniform vec4 lightMapUVParam;\nvoid main () {\nvec3 worldPos;\nworldPos.x = cc_matWorld[3][0] + a_position.x;\nworldPos.y = cc_matWorld[3][1] + a_position.y;\nworldPos.z = cc_matWorld[3][2] + a_position.z;\nvec4 pos = vec4(worldPos, 1.0);\npos = cc_matViewProj * pos;\nuvw = a_texCoord;\nuv0 = a_position.xz * UVScale.x;\nuv1 = a_position.xz * UVScale.y;\nuv2 = a_position.xz * UVScale.z;\nuv3 = a_position.xz * UVScale.w;\n#if CC_USE_LIGHTMAP\nluv.xy = lightMapUVParam.xy + a_texCoord * lightMapUVParam.z;\nluv.z = lightMapUVParam.w;\n#endif\nv_position = worldPos;\nv_normal = a_normal;\nCC_TRANSFER_FOG(vec4(worldPos, 1.0));\n#if CC_RECEIVE_SHADOW\nv_shadowBias = vec2(0.0, 0.0);\n#endif\nv_shadowPos = cc_matLightViewProj * vec4(worldPos, 1.0);\ngl_Position = pos;\n}", + "frag": "\n#ifdef GL_EXT_draw_buffers\n#extension GL_EXT_draw_buffers: enable\n#endif\n#ifdef GL_OES_standard_derivatives\n#extension GL_OES_standard_derivatives: enable\n#endif\n#ifdef GL_EXT_shader_texture_lod\n#extension GL_EXT_shader_texture_lod: enable\n#endif\nprecision highp float;\nuniform highp mat4 cc_matView;\nuniform highp vec4 cc_cameraPos;\nuniform mediump vec4 cc_mainLitDir;\nuniform mediump vec4 cc_mainLitColor;\nuniform mediump vec4 cc_ambientSky;\nuniform mediump vec4 cc_ambientGround;\nuniform mediump vec4 cc_fogColor;\nuniform mediump vec4 cc_fogBase;\nuniform mediump vec4 cc_fogAdd;\nuniform mediump vec4 cc_nearFar;\nuniform mediump vec4 cc_viewPort;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nvec3 SRGBToLinear (vec3 gamma) {\nreturn gamma * gamma;\n}\nuniform highp mat4 cc_matLightView;\nuniform highp vec4 cc_shadowInvProjDepthInfo;\nuniform highp vec4 cc_shadowProjDepthInfo;\nuniform highp vec4 cc_shadowProjInfo;\nuniform mediump vec4 cc_shadowNFLSInfo;\nuniform mediump vec4 cc_shadowWHPBInfo;\nuniform mediump vec4 cc_shadowLPNNInfo;\nhighp float unpackHighpData (float mainPart, float modPart) {\nhighp float data = mainPart;\nreturn data + modPart;\n}\nvoid packHighpData (out float mainPart, out float modPart, highp float data) {\nmainPart = fract(data);\nmodPart = data - mainPart;\n}\nhighp float unpackHighpData (float mainPart, float modPart, const float modValue) {\nhighp float data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nvoid packHighpData (out float mainPart, out float modPart, highp float data, const float modValue) {\nhighp float divide = data / modValue;\nmainPart = floor(divide);\nmodPart = (data - mainPart * modValue) / modValue;\n}\nhighp vec2 unpackHighpData (vec2 mainPart, vec2 modPart) {\nhighp vec2 data = mainPart;\nreturn data + modPart;\n}\nvoid packHighpData (out vec2 mainPart, out vec2 modPart, highp vec2 data) {\nmainPart = fract(data);\nmodPart = data - mainPart;\n}\nhighp vec2 unpackHighpData (vec2 mainPart, vec2 modPart, const float modValue) {\nhighp vec2 data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nvoid packHighpData (out vec2 mainPart, out vec2 modPart, highp vec2 data, const float modValue) {\nhighp vec2 divide = data / modValue;\nmainPart = floor(divide);\nmodPart = (data - mainPart * modValue) / modValue;\n}\nhighp vec3 unpackHighpData (vec3 mainPart, vec3 modPart) {\nhighp vec3 data = mainPart;\nreturn data + modPart;\n}\nvoid packHighpData (out vec3 mainPart, out vec3 modPart, highp vec3 data) {\nmainPart = fract(data);\nmodPart = data - mainPart;\n}\nhighp vec3 unpackHighpData (vec3 mainPart, vec3 modPart, const float modValue) {\nhighp vec3 data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nvoid packHighpData (out vec3 mainPart, out vec3 modPart, highp vec3 data, const float modValue) {\nhighp vec3 divide = data / modValue;\nmainPart = floor(divide);\nmodPart = (data - mainPart * modValue) / modValue;\n}\nhighp vec4 unpackHighpData (vec4 mainPart, vec4 modPart) {\nhighp vec4 data = mainPart;\nreturn data + modPart;\n}\nvoid packHighpData (out vec4 mainPart, out vec4 modPart, highp vec4 data) {\nmainPart = fract(data);\nmodPart = data - mainPart;\n}\nhighp vec4 unpackHighpData (vec4 mainPart, vec4 modPart, const float modValue) {\nhighp vec4 data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nvoid packHighpData (out vec4 mainPart, out vec4 modPart, highp vec4 data, const float modValue) {\nhighp vec4 divide = data / modValue;\nmainPart = floor(divide);\nmodPart = (data - mainPart * modValue) / modValue;\n}\nfloat CCGetLinearDepthFromViewSpace(vec3 viewPos) {\nfloat dist = length(viewPos);\nreturn (dist - cc_shadowNFLSInfo.x) / (cc_shadowNFLSInfo.y - cc_shadowNFLSInfo.x);\n}\nfloat CCGetLinearDepth(vec3 worldPos) {\nvec4 viewStartPos = cc_matLightView * vec4(worldPos.xyz, 1.0);\nreturn CCGetLinearDepthFromViewSpace(viewStartPos.xyz);\n}\n#if CC_RECEIVE_SHADOW\nuniform highp sampler2D cc_shadowMap;\nuniform highp sampler2D cc_spotLightingMap;\nvec4 ApplyShadowDepthBias_FaceNormal(vec4 shadowPos, vec3 worldNormal, float normalBias)\n{\nvec4 newShadowPos = shadowPos;\nif(normalBias > EPSILON_LOWP)\n{\nvec4 viewNormal = cc_matLightView * vec4(worldNormal, 0.0);\nif(viewNormal.z < 0.1)\nnewShadowPos.xy += viewNormal.xy * cc_shadowProjInfo.xy * normalBias * clamp(viewNormal.z, 0.001, 0.1);\n}\nreturn newShadowPos;\n}\nvec4 ApplyShadowDepthBias_Perspective(vec4 shadowPos, float viewspaceDepthBias)\n{\nvec3 viewSpacePos;\nviewSpacePos.xy = shadowPos.xy * cc_shadowProjInfo.zw;\nviewSpacePos.z = shadowPos.z * cc_shadowInvProjDepthInfo.x + shadowPos.w * cc_shadowInvProjDepthInfo.y;\nviewSpacePos.xyz += cc_shadowProjDepthInfo.z * normalize(viewSpacePos.xyz) * viewspaceDepthBias;\nvec4 clipSpacePos;\nclipSpacePos.xy = viewSpacePos.xy * cc_shadowProjInfo.xy;\nclipSpacePos.zw = viewSpacePos.z * cc_shadowProjDepthInfo.xz + vec2(cc_shadowProjDepthInfo.y, 0.0);\nif (cc_shadowNFLSInfo.z > EPSILON) {\nclipSpacePos.z = CCGetLinearDepthFromViewSpace(viewSpacePos.xyz);\nclipSpacePos.z = (clipSpacePos.z * 2.0 - 1.0) * clipSpacePos.w;\n}\nreturn clipSpacePos;\n}\nvec4 ApplyShadowDepthBias_Orthographic(vec4 shadowPos, float viewspaceDepthBias)\n{\nfloat coeffA = cc_shadowProjDepthInfo.x;\nfloat coeffB = cc_shadowProjDepthInfo.y;\nfloat viewSpacePos_z = (shadowPos.z - coeffB) / coeffA;\nviewSpacePos_z += viewspaceDepthBias;\nvec4 result = shadowPos;\nresult.z = viewSpacePos_z * coeffA + coeffB;\nreturn result;\n}\nfloat CCGetShadowFactorHard (vec4 shadowPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Orthographic(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat shadow = 0.0;\nfloat closestDepth = 0.0;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nclosestDepth = dot(texture2D(cc_shadowMap, clipPos.xy), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0));\n} else {\nclosestDepth = texture2D(cc_shadowMap, clipPos.xy).x;\n}\nshadow = step(clipPos.z, closestDepth);\nreturn shadow;\n}\nfloat CCGetShadowFactorSoft (vec4 shadowPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Orthographic(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat offsetDepth = clipPos.z;\nvec2 mapSize = cc_shadowWHPBInfo.xy;\nvec2 oneTap = 1.0 / mapSize;\nvec2 clipPos_offset = clipPos.xy + oneTap;\nfloat block0, block1, block2, block3;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos_offset.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos_offset.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos.x, clipPos.y)).x);\nblock1 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos_offset.x, clipPos.y)).x);\nblock2 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos.x, clipPos_offset.y)).x);\nblock3 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos_offset.x, clipPos_offset.y)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * mapSize.x;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block2, block3, coefX);\nfloat coefY = mod(clipPos.y, oneTap.y) * mapSize.y;\nreturn mix(resultX, resultY, coefY);\n}\nfloat CCGetShadowFactorSoft2X (vec4 shadowPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Orthographic(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat offsetDepth = clipPos.z;\nvec2 mapSize = cc_shadowWHPBInfo.xy;\nvec2 oneTap = 1.0 / mapSize;\nfloat clipPos_offset_L = clipPos.x - oneTap.x;\nfloat clipPos_offset_R = clipPos.x + oneTap.x;\nfloat clipPos_offset_U = clipPos.y - oneTap.y;\nfloat clipPos_offset_D = clipPos.y + oneTap.y;\nfloat block0, block1, block2, block3, block4, block5, block6, block7, block8;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos.x, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos_offset_L, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock4 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock5 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos_offset_R, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock6 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock7 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos.x, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock8 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_U)).x);\nblock1 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos.x, clipPos_offset_U)).x);\nblock2 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_U)).x);\nblock3 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos_offset_L, clipPos.y)).x);\nblock4 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos.x, clipPos.y)).x);\nblock5 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos_offset_R, clipPos.y)).x);\nblock6 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_D)).x);\nblock7 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos.x, clipPos_offset_D)).x);\nblock8 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_D)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * mapSize.x;\nfloat coefY = mod(clipPos.y, oneTap.y) * mapSize.y;\nfloat shadow = 0.0;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block3, block4, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block1, block2, coefX);\nresultY = mix(block4, block5, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block3, block4, coefX);\nresultY = mix(block6, block7, coefX);\nshadow += mix(resultX, resultY, coefY);\nresultX = mix(block4, block5, coefX);\nresultY = mix(block7, block8, coefX);\nshadow += mix(resultX, resultY, coefY);\nreturn shadow * 0.25;\n}\nfloat CCGetSpotLightShadowFactorHard (vec4 shadowPos, vec3 worldPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Perspective(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat shadow = 0.0;\nfloat closestDepth = 0.0;\nfloat depth = clipPos.z;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nclosestDepth = dot(texture2D(cc_spotLightingMap, clipPos.xy), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0));\n} else {\nclosestDepth = texture2D(cc_spotLightingMap, clipPos.xy).x;\n}\nshadow = step(depth, closestDepth);\nreturn shadow;\n}\nfloat CCGetSpotLightShadowFactorSoft (vec4 shadowPos, vec3 worldPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Perspective(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat depth = 0.0;\nif (cc_shadowNFLSInfo.z > EPSILON) {\ndepth = CCGetLinearDepth(worldPos);\n} else {\ndepth = clipPos.z;\n}\nvec2 oneTap = 1.0 / cc_shadowWHPBInfo.xy;\nvec2 clipPos_offset = clipPos.xy + oneTap;\nfloat block0, block1, block2, block3;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)).x);\nblock1 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos.y)).x);\nblock2 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset.y)).x);\nblock3 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos_offset.y)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * cc_shadowWHPBInfo.x;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block2, block3, coefX);\nfloat coefY = mod(clipPos.y, oneTap.y) * cc_shadowWHPBInfo.y;\nreturn mix(resultX, resultY, coefY);\n}\nfloat CCGetSpotLightShadowFactorSoft2X (vec4 shadowPos, vec3 worldPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Perspective(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat depth = 0.0;\nif (cc_shadowNFLSInfo.z > EPSILON) {\ndepth = CCGetLinearDepth(worldPos);\n} else {\ndepth = clipPos.z;\n}\nvec2 mapSize = cc_shadowWHPBInfo.xy;\nvec2 oneTap = 1.0 / mapSize;\nfloat clipPos_offset_L = clipPos.x - oneTap.x;\nfloat clipPos_offset_R = clipPos.x + oneTap.x;\nfloat clipPos_offset_U = clipPos.y - oneTap.y;\nfloat clipPos_offset_D = clipPos.y + oneTap.y;\nfloat block0, block1, block2, block3, block4, block5, block6, block7, block8;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock4 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock5 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock6 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock7 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock8 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_U)).x);\nblock1 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_U)).x);\nblock2 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_U)).x);\nblock3 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos.y)).x);\nblock4 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)).x);\nblock5 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos.y)).x);\nblock6 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_D)).x);\nblock7 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_D)).x);\nblock8 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_D)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * mapSize.x;\nfloat coefY = mod(clipPos.y, oneTap.y) * mapSize.y;\nfloat shadow = 0.0;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block3, block4, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block1, block2, coefX);\nresultY = mix(block4, block5, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block3, block4, coefX);\nresultY = mix(block6, block7, coefX);\nshadow += mix(resultX, resultY, coefY);\nresultX = mix(block4, block5, coefX);\nresultY = mix(block7, block8, coefX);\nshadow += mix(resultX, resultY, coefY);\nreturn shadow * 0.25;\n}\nfloat CCSpotShadowFactorBase(vec4 shadowPos, vec3 worldPos, vec2 shadowBias)\n{\nfloat pcf = cc_shadowWHPBInfo.z;\nif (pcf > 1.9) {\nreturn CCGetSpotLightShadowFactorSoft2X(shadowPos, worldPos, shadowBias.x);\n}else if (pcf > 0.9) {\nreturn CCGetSpotLightShadowFactorSoft(shadowPos, worldPos, shadowBias.x);\n}else {\nreturn CCGetSpotLightShadowFactorHard(shadowPos, worldPos, shadowBias.x);\n}\n}\nfloat CCShadowFactorBase(vec4 shadowPos, vec3 N, vec2 shadowBias)\n{\nfloat realtimeShadow = 1.0;\nvec4 pos = ApplyShadowDepthBias_FaceNormal(shadowPos, N, shadowBias.y);\nfloat pcf = cc_shadowWHPBInfo.z;\nif (pcf > 1.9) {\nrealtimeShadow = CCGetShadowFactorSoft2X(pos, shadowBias.x);\n}else if (pcf > 0.9) {\nrealtimeShadow = CCGetShadowFactorSoft(pos, shadowBias.x);\n}else {\nrealtimeShadow = CCGetShadowFactorHard(pos, shadowBias.x);\n}\nreturn mix(realtimeShadow, 1.0, cc_shadowNFLSInfo.w);\n}\n#endif\n#if CC_USE_IBL\nuniform samplerCube cc_environment;\nvec4 fragTextureLod (sampler2D tex, vec2 coord, float lod) {\n#ifdef GL_EXT_shader_texture_lod\nreturn texture2DLodEXT(tex, coord, lod);\n#else\nreturn texture2D(tex, coord, lod);\n#endif\n}\nvec4 fragTextureLod (samplerCube tex, vec3 coord, float lod) {\n#ifdef GL_EXT_shader_texture_lod\nreturn textureCubeLodEXT(tex, coord, lod);\n#else\nreturn textureCube(tex, coord, lod);\n#endif\n}\nvec3 unpackRGBE (vec4 rgbe) {\nreturn rgbe.rgb * pow(1.1, rgbe.a * 255.0 - 128.0);\n}\n#if CC_USE_DIFFUSEMAP\nuniform samplerCube cc_diffuseMap;\n#endif\n#endif\nfloat GGXMobile (float roughness, float NoH, vec3 H, vec3 N) {\nvec3 NxH = cross(N, H);\nfloat OneMinusNoHSqr = dot(NxH, NxH);\nfloat a = roughness * roughness;\nfloat n = NoH * a;\nfloat p = a / (OneMinusNoHSqr + n * n);\nreturn p * p;\n}\nfloat CalcSpecular (float roughness, float NoH, vec3 H, vec3 N) {\nreturn (roughness * 0.25 + 0.25) * GGXMobile(roughness, NoH, H, N);\n}\nvec3 BRDFApprox (vec3 specular, float roughness, float NoV) {\nconst vec4 c0 = vec4(-1.0, -0.0275, -0.572, 0.022);\nconst vec4 c1 = vec4(1.0, 0.0425, 1.04, -0.04);\nvec4 r = roughness * c0 + c1;\nfloat a004 = min(r.x * r.x, exp2(-9.28 * NoV)) * r.x + r.y;\nvec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;\nAB.y *= clamp(50.0 * specular.g, 0.0, 1.0);\nreturn specular * AB.x + AB.y;\n}\n#if USE_REFLECTION_DENOISE\nvec3 GetEnvReflectionWithMipFiltering(vec3 R, float roughness, float mipCount, float denoiseIntensity) {\n#if CC_USE_IBL\nfloat mip = roughness * mipCount;\nfloat delta = (dot(dFdx(R), dFdy(R))) * 1000.0;\nfloat mipBias = mix(0.0, 5.0, clamp(delta, 0.0, 1.0));\nvec4 biased = fragTextureLod(cc_environment, R, mip + mipBias);\nvec4 filtered = textureCube(cc_environment, R);\n#if CC_USE_IBL == 2\nbiased.rgb = unpackRGBE(biased);\nfiltered.rgb = unpackRGBE(filtered);\n#else\nbiased.rgb = SRGBToLinear(biased.rgb);\nfiltered.rgb = SRGBToLinear(filtered.rgb);\n#endif\nreturn mix(biased.rgb, filtered.rgb, denoiseIntensity);\n#else\nreturn vec3(0.0, 0.0, 0.0);\n#endif\n}\n#endif\nstruct StandardSurface {\nvec4 albedo;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nvec3 position, position_fract_part;\n#else\nvec3 position;\n#endif\nvec3 normal;\nvec3 emissive;\nvec3 lightmap;\nfloat lightmap_test;\nfloat roughness;\nfloat metallic;\nfloat occlusion;\nfloat specularIntensity;\n#if CC_RECEIVE_SHADOW\nvec2 shadowBias;\n#endif\n};\nvec4 CCStandardShadingBase (StandardSurface s, vec4 shadowPos) {\nvec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\nvec3 specular = mix(vec3(0.08 * s.specularIntensity), s.albedo.rgb, s.metallic);\nvec3 position;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nposition = unpackHighpData(s.position, s.position_fract_part);\n#else\nposition = s.position;\n#endif\nvec3 N = normalize(s.normal);\nvec3 V = normalize(cc_cameraPos.xyz - position);\nfloat NV = max(abs(dot(N, V)), 0.0);\nspecular = BRDFApprox(specular, s.roughness, NV);\nvec3 L = normalize(-cc_mainLitDir.xyz);\nvec3 H = normalize(L + V);\nfloat NH = max(dot(N, H), 0.0);\nfloat NL = max(dot(N, L), 0.0);\nvec3 finalColor = NL * cc_mainLitColor.rgb * cc_mainLitColor.w;\nvec3 diffuseContrib = diffuse / PI;\nvec3 specularContrib = specular * CalcSpecular(s.roughness, NH, H, N);\nvec3 dirlightContrib = (diffuseContrib + specularContrib);\nfloat shadow = 1.0;\n#if CC_RECEIVE_SHADOW\nif (NL > 0.0 && cc_mainLitDir.w > 0.0) {\nshadow = CCShadowFactorBase(shadowPos, N, s.shadowBias);\n}\n#endif\ndirlightContrib *= shadow;\nfinalColor *= dirlightContrib;\n#if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\nif (s.lightmap_test > EPSILON_LOWP) {\nfinalColor = diffuse * s.lightmap.rgb * shadow;\n}\n#endif\nfloat fAmb = 0.5 - N.y * 0.5;\nvec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb);\n#if CC_USE_IBL\n#if CC_USE_DIFFUSEMAP\nvec4 diffuseMap = textureCube(cc_diffuseMap, N);\n#if CC_USE_DIFFUSEMAP == 2\nambDiff = unpackRGBE(diffuseMap);\n#else\nambDiff = SRGBToLinear(diffuseMap.rgb);\n#endif\n#endif\nvec3 R = normalize(reflect(-V, N));\n#if USE_REFLECTION_DENOISE\nvec3 env = GetEnvReflectionWithMipFiltering(R, s.roughness, cc_ambientGround.w, 0.6);\n#else\nvec4 envmap = fragTextureLod(cc_environment, R, s.roughness * cc_ambientGround.w);\n#if CC_USE_IBL == 2\nvec3 env = unpackRGBE(envmap);\n#else\nvec3 env = SRGBToLinear(envmap.rgb);\n#endif\n#endif\nfinalColor += env * cc_ambientSky.w * specular * s.occlusion;\n#endif\nfinalColor += ambDiff.rgb * cc_ambientSky.w * diffuse * s.occlusion;\nfinalColor += s.emissive;\nreturn vec4(finalColor, s.albedo.a);\n}\nvec3 ACESToneMap (vec3 color) {\ncolor = min(color, vec3(8.0));\nconst float A = 2.51;\nconst float B = 0.03;\nconst float C = 2.43;\nconst float D = 0.59;\nconst float E = 0.14;\nreturn (color * (A * color + B)) / (color * (C * color + D) + E);\n}\nvec4 CCFragOutput (vec4 color) {\n#if CC_USE_HDR\ncolor.rgb = ACESToneMap(color.rgb);\n#endif\ncolor.rgb = sqrt(color.rgb);\nreturn color;\n}\nfloat LinearFog(vec4 pos) {\nvec4 wPos = pos;\nfloat cam_dis = distance(cc_cameraPos, wPos);\nfloat fogStart = cc_fogBase.x;\nfloat fogEnd = cc_fogBase.y;\nreturn clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * fogDensity);\nreturn f;\n}\nfloat ExpSquaredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\nreturn f;\n}\nfloat LayeredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat _FogTop = cc_fogAdd.x;\nfloat _FogRange = cc_fogAdd.y;\nvec3 camWorldProj = cc_cameraPos.xyz;\ncamWorldProj.y = 0.;\nvec3 worldPosProj = wPos.xyz;\nworldPosProj.y = 0.;\nfloat fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\nfloat fDeltaY, fDensityIntegral;\nif (cc_cameraPos.y > _FogTop) {\nif (wPos.y < _FogTop) {\nfDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\nfDensityIntegral = fDeltaY * fDeltaY * 0.5;\n} else {\nfDeltaY = 0.;\nfDensityIntegral = 0.;\n}\n} else {\nif (wPos.y < _FogTop) {\nfloat fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfloat fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\nfDeltaY = abs(fDeltaA - fDeltaB);\nfDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n} else {\nfDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n}\n}\nfloat fDensity;\nif (fDeltaY != 0.) {\nfDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n} else {\nfDensity = 0.;\n}\nfloat f = exp(-fDensity);\nreturn f;\n}\nvoid CC_TRANSFER_FOG_BASE(vec4 pos, out float factor)\n{\n#if CC_USE_FOG == 0\nfactor = LinearFog(pos);\n#elif CC_USE_FOG == 1\nfactor = ExpFog(pos);\n#elif CC_USE_FOG == 2\nfactor = ExpSquaredFog(pos);\n#elif CC_USE_FOG == 3\nfactor = LayeredFog(pos);\n#else\nfactor = 1.0;\n#endif\n}\nvoid CC_APPLY_FOG_BASE(inout vec4 color, float factor) {\ncolor = vec4(mix(cc_fogColor.rgb, color.rgb, factor), color.a);\n}\n#if !CC_USE_ACCURATE_FOG\nvarying float v_fog_factor;\n#endif\nvoid CC_APPLY_FOG(inout vec4 color) {\n#if !CC_USE_ACCURATE_FOG\nCC_APPLY_FOG_BASE(color, v_fog_factor);\n#endif\n}\nvoid CC_APPLY_FOG(inout vec4 color, vec3 worldPos) {\n#if CC_USE_ACCURATE_FOG\nfloat factor;\nCC_TRANSFER_FOG_BASE(vec4(worldPos, 1.0), factor);\n#else\nfloat factor = v_fog_factor;\n#endif\nCC_APPLY_FOG_BASE(color, factor);\n}\nvarying highp vec4 v_shadowPos;\n#if CC_RECEIVE_SHADOW\n#endif\n#if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\nvarying vec3 v_luv;\nuniform sampler2D cc_lightingMap;\n#endif\nvarying highp vec3 v_position;\nvarying mediump vec3 v_normal;\n#if CC_RECEIVE_SHADOW\nvarying vec2 v_shadowBias;\n#endif\nvarying mediump vec2 uvw;\nvarying mediump vec2 uv0;\nvarying mediump vec2 uv1;\nvarying mediump vec2 uv2;\nvarying mediump vec2 uv3;\nvarying mediump vec3 diffuse;\nvarying mediump vec3 luv;\nuniform vec4 metallic;\nuniform vec4 roughness;\nuniform sampler2D weightMap;\nuniform sampler2D detailMap0;\nuniform sampler2D detailMap1;\nuniform sampler2D detailMap2;\nuniform sampler2D detailMap3;\nuniform sampler2D normalMap0;\nuniform sampler2D normalMap1;\nuniform sampler2D normalMap2;\nuniform sampler2D normalMap3;\nuniform sampler2D lightMap;\nvoid surf (out StandardSurface s) {\n#if LAYERS > 1\nvec4 w = texture2D(weightMap, uvw);\n#endif\nvec4 baseColor = vec4(0, 0, 0, 0);\n#if LAYERS == 1\nbaseColor = texture2D(detailMap0, uv0);\n#elif LAYERS == 2\nbaseColor += texture2D(detailMap0, uv0) * w.r;\nbaseColor += texture2D(detailMap1, uv1) * w.g;\n#elif LAYERS == 3\nbaseColor += texture2D(detailMap0, uv0) * w.r;\nbaseColor += texture2D(detailMap1, uv1) * w.g;\nbaseColor += texture2D(detailMap2, uv2) * w.b;\n#elif LAYERS == 4\nbaseColor += texture2D(detailMap0, uv0) * w.r;\nbaseColor += texture2D(detailMap1, uv1) * w.g;\nbaseColor += texture2D(detailMap2, uv2) * w.b;\nbaseColor += texture2D(detailMap3, uv3) * w.a;\n#else\nbaseColor = texture2D(detailMap0, uv0);\n#endif\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\npackHighpData(s.position, s.position_fract_part, v_position);\n#else\ns.position = v_position;\n#endif\n#if USE_NORMALMAP\nvec4 baseNormal = vec4(0, 0, 0, 0);\n#if LAYERS == 1\nbaseNormal = texture2D(normalMap0, uv0);\n#elif LAYERS == 2\nbaseNormal += texture2D(normalMap0, uv0) * w.r;\nbaseNormal += texture2D(normalMap1, uv1) * w.g;\n#elif LAYERS == 3\nbaseNormal += texture2D(normalMap0, uv0) * w.r;\nbaseNormal += texture2D(normalMap1, uv1) * w.g;\nbaseNormal += texture2D(normalMap2, uv2) * w.b;\n#elif LAYERS == 4\nbaseNormal += texture2D(normalMap0, uv0) * w.r;\nbaseNormal += texture2D(normalMap1, uv1) * w.g;\nbaseNormal += texture2D(normalMap2, uv2) * w.b;\nbaseNormal += texture2D(normalMap3, uv3) * w.a;\n#else\nbaseNormal = texture2D(normalMap0, uv0);\n#endif\nvec3 tangent = vec3(1.0, 0.0, 0.0);\nvec3 binormal = vec3(0.0, 0.0, 1.0);\nbinormal = cross(tangent, v_normal);\ntangent = cross(v_normal, binormal);\nvec3 nmmp = baseNormal.xyz - vec3(0.5);\ns.normal =\nnmmp.x * normalize(tangent) +\nnmmp.y * normalize(binormal) +\nnmmp.z * normalize(v_normal);\n#else\ns.normal = v_normal;\n#endif\n#if CC_RECEIVE_SHADOW\ns.shadowBias = v_shadowBias;\n#endif\ns.albedo = vec4(SRGBToLinear(baseColor.rgb), 1.0);\ns.occlusion = 1.0;\n#if USE_PBR\ns.roughness = 0.0;\n#if LAYERS == 1\ns.roughness = roughness.x;\n#elif LAYERS == 2\ns.roughness += roughness.x * w.r;\ns.roughness += roughness.y * w.g;\n#elif LAYERS == 3\ns.roughness += roughness.x * w.r;\ns.roughness += roughness.y * w.g;\ns.roughness += roughness.z * w.b;\n#elif LAYERS == 4\ns.roughness += roughness.x * w.r;\ns.roughness += roughness.y * w.g;\ns.roughness += roughness.z * w.b;\ns.roughness += roughness.w * w.a;\n#else\ns.roughness = 1.0;\n#endif\ns.specularIntensity = 0.5;\ns.metallic = 0.0;\n#if LAYERS == 1\ns.specularIntensity = 0.5;\ns.metallic = metallic.x;\n#elif LAYERS == 2\ns.metallic += metallic.x * w.r;\ns.metallic += metallic.y * w.g;\n#elif LAYERS == 3\ns.metallic += metallic.x * w.r;\ns.metallic += metallic.y * w.g;\ns.metallic += metallic.z * w.b;\n#elif LAYERS == 4\ns.metallic += metallic.x * w.r;\ns.metallic += metallic.y * w.g;\ns.metallic += metallic.z * w.b;\ns.metallic += metallic.w * w.a;\n#else\ns.specularIntensity = 0.5;\ns.metallic = 0.0;\n#endif\n#else\ns.roughness = 1.0;\ns.specularIntensity = 0.5;\ns.metallic = 0.0;\n#endif\ns.emissive = vec3(0.0, 0.0, 0.0);\n#if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\nvec4 lightColor = texture2D(lightMap, luv.xy);\ns.lightmap = lightColor.xyz * luv.z;\ns.lightmap_test = luv.z;\n#endif\n}\n#if CC_FORWARD_ADD\n#if CC_PIPELINE_TYPE == 0\n#define LIGHTS_PER_PASS 1\n#else\n#define LIGHTS_PER_PASS 10\n#endif\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 0\nuniform highp vec4 cc_lightPos[LIGHTS_PER_PASS];\nuniform vec4 cc_lightColor[LIGHTS_PER_PASS];\nuniform vec4 cc_lightSizeRangeAngle[LIGHTS_PER_PASS];\nuniform vec4 cc_lightDir[LIGHTS_PER_PASS];\n#endif\nfloat SmoothDistAtt (float distSqr, float invSqrAttRadius) {\nfloat factor = distSqr * invSqrAttRadius;\nfloat smoothFactor = clamp(1.0 - factor * factor, 0.0, 1.0);\nreturn smoothFactor * smoothFactor;\n}\nfloat GetDistAtt (float distSqr, float invSqrAttRadius) {\nfloat attenuation = 1.0 / max(distSqr, 0.01*0.01);\nattenuation *= SmoothDistAtt(distSqr , invSqrAttRadius);\nreturn attenuation;\n}\nfloat GetAngleAtt (vec3 L, vec3 litDir, float litAngleScale, float litAngleOffset) {\nfloat cd = dot(litDir, L);\nfloat attenuation = clamp(cd * litAngleScale + litAngleOffset, 0.0, 1.0);\nreturn (attenuation * attenuation);\n}\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 0\nvec4 CCStandardShadingAdditive (StandardSurface s, vec4 shadowPos) {\nvec3 position;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nposition = unpackHighpData(s.position, s.position_fract_part);\n#else\nposition = s.position;\n#endif\nvec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\nvec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\nvec3 diffuseContrib = diffuse / PI;\nvec3 N = normalize(s.normal);\nvec3 V = normalize(cc_cameraPos.xyz - position);\nfloat NV = max(abs(dot(N, V)), 0.0);\nspecular = BRDFApprox(specular, s.roughness, NV);\nvec3 finalColor = vec3(0.0);\nint numLights = CC_PIPELINE_TYPE == 0 ? LIGHTS_PER_PASS : int(cc_lightDir[0].w);\nfor (int i = 0; i < LIGHTS_PER_PASS; i++) {\nif (i >= numLights) break;\nvec3 SLU = cc_lightPos[i].xyz - position;\nvec3 SL = normalize(SLU);\nvec3 SH = normalize(SL + V);\nfloat SNL = max(dot(N, SL), 0.0);\nfloat SNH = max(dot(N, SH), 0.0);\nfloat distSqr = dot(SLU, SLU);\nfloat litRadius = cc_lightSizeRangeAngle[i].x;\nfloat litRadiusSqr = litRadius * litRadius;\nfloat illum = litRadiusSqr / max(litRadiusSqr, distSqr);\nfloat attRadiusSqrInv = 1.0 / max(cc_lightSizeRangeAngle[i].y, 0.01);\nattRadiusSqrInv *= attRadiusSqrInv;\nfloat att = GetDistAtt(distSqr, attRadiusSqrInv);\nvec3 lspec = specular * CalcSpecular(s.roughness, SNH, SH, N);\nif (cc_lightPos[i].w > 0.0) {\nfloat cosInner = max(dot(-cc_lightDir[i].xyz, SL), 0.01);\nfloat cosOuter = cc_lightSizeRangeAngle[i].z;\nfloat litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\nfloat litAngleOffset = -cosOuter * litAngleScale;\natt *= GetAngleAtt(SL, -cc_lightDir[i].xyz, litAngleScale, litAngleOffset);\n}\nvec3 lightColor = cc_lightColor[i].rgb;\nfloat shadow = 1.0;\n#if CC_RECEIVE_SHADOW\nif (cc_lightPos[i].w > 0.0 && cc_lightSizeRangeAngle[i].w > 0.0) {\nshadow = CCSpotShadowFactorBase(shadowPos, position, s.shadowBias);\n}\n#endif\nlightColor *= shadow;\nfinalColor += SNL * lightColor * cc_lightColor[i].w * illum * att * (diffuseContrib + lspec);\n}\nreturn vec4(finalColor, 0.0);\n}\n#endif\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 1\nreadonly buffer b_ccLightsBuffer { vec4 b_ccLights[]; };\nreadonly buffer b_clusterLightIndicesBuffer { uint b_clusterLightIndices[]; };\nreadonly buffer b_clusterLightGridBuffer { uvec4 b_clusterLightGrid[]; };\nstruct CCLight\n{\nvec4 cc_lightPos;\nvec4 cc_lightColor;\nvec4 cc_lightSizeRangeAngle;\nvec4 cc_lightDir;\n};\nstruct Cluster\n{\nvec3 minBounds;\nvec3 maxBounds;\n};\nstruct LightGrid\n{\nuint offset;\nuint ccLights;\n};\nCCLight getCCLight(uint i)\n{\nCCLight light;\nlight.cc_lightPos = b_ccLights[4u * i + 0u];\nlight.cc_lightColor = b_ccLights[4u * i + 1u];\nlight.cc_lightSizeRangeAngle = b_ccLights[4u * i + 2u];\nlight.cc_lightDir = b_ccLights[4u * i + 3u];\nreturn light;\n}\nLightGrid getLightGrid(uint cluster)\n{\nuvec4 gridvec = b_clusterLightGrid[cluster];\nLightGrid grid;\ngrid.offset = gridvec.x;\ngrid.ccLights = gridvec.y;\nreturn grid;\n}\nuint getGridLightIndex(uint start, uint offset)\n{\nreturn b_clusterLightIndices[start + offset];\n}\nuint getClusterZIndex(vec4 worldPos)\n{\nfloat scale = float(24) / log(cc_nearFar.y / cc_nearFar.x);\nfloat bias = -(float(24) * log(cc_nearFar.x) / log(cc_nearFar.y / cc_nearFar.x));\nfloat eyeDepth = -(cc_matView * worldPos).z;\nuint zIndex = uint(max(log(eyeDepth) * scale + bias, 0.0));\nreturn zIndex;\n}\nuint getClusterIndex(vec4 fragCoord, vec4 worldPos)\n{\nuint zIndex = getClusterZIndex(worldPos);\nfloat clusterSizeX = ceil(cc_viewPort.z / float(16));\nfloat clusterSizeY = ceil(cc_viewPort.w / float(8));\nuvec3 indices = uvec3(uvec2(fragCoord.xy / vec2(clusterSizeX, clusterSizeY)), zIndex);\nuint cluster = (16u * 8u) * indices.z + 16u * indices.y + indices.x;\nreturn cluster;\n}\nvec4 CCClusterShadingAdditive (StandardSurface s, vec4 shadowPos) {\nvec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\nvec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\nvec3 diffuseContrib = diffuse / PI;\nvec3 position;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nposition = unpackHighpData(s.position, s.position_fract_part);\n#else\nposition = s.position;\n#endif\nvec3 N = normalize(s.normal);\nvec3 V = normalize(cc_cameraPos.xyz - position);\nfloat NV = max(abs(dot(N, V)), 0.001);\nspecular = BRDFApprox(specular, s.roughness, NV);\nvec3 finalColor = vec3(0.0);\nuint cluster = getClusterIndex(gl_FragCoord, vec4(position, 1.0));\nLightGrid grid = getLightGrid(cluster);\nuint numLights = grid.ccLights;\nfor (uint i = 0u; i < 100u; i++) {\nif (i >= numLights) break;\nuint lightIndex = getGridLightIndex(grid.offset, i);\nCCLight light = getCCLight(lightIndex);\nvec3 SLU = light.cc_lightPos.xyz - position;\nvec3 SL = normalize(SLU);\nvec3 SH = normalize(SL + V);\nfloat SNL = max(dot(N, SL), 0.001);\nfloat SNH = max(dot(N, SH), 0.0);\nfloat distSqr = dot(SLU, SLU);\nfloat litRadius = light.cc_lightSizeRangeAngle.x;\nfloat litRadiusSqr = litRadius * litRadius;\nfloat illum = PI * (litRadiusSqr / max(litRadiusSqr , distSqr));\nfloat attRadiusSqrInv = 1.0 / max(light.cc_lightSizeRangeAngle.y, 0.01);\nattRadiusSqrInv *= attRadiusSqrInv;\nfloat att = GetDistAtt(distSqr, attRadiusSqrInv);\nvec3 lspec = specular * CalcSpecular(s.roughness, SNH, SH, N);\nif (light.cc_lightPos.w > 0.0) {\nfloat cosInner = max(dot(-light.cc_lightDir.xyz, SL), 0.01);\nfloat cosOuter = light.cc_lightSizeRangeAngle.z;\nfloat litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\nfloat litAngleOffset = -cosOuter * litAngleScale;\natt *= GetAngleAtt(SL, -light.cc_lightDir.xyz, litAngleScale, litAngleOffset);\n}\nvec3 lightColor = light.cc_lightColor.rgb;\nfloat shadow = 1.0;\n#if CC_RECEIVE_SHADOW\nif (light.cc_lightPos.w > 0.0) {\nshadow = CCSpotShadowFactorBase(shadowPos, position, s.shadowBias);\n}\n#endif\nlightColor *= shadow;\nfinalColor += SNL * lightColor * light.cc_lightColor.w * illum * att * (diffuseContrib + lspec);\n}\nreturn vec4(finalColor, 0.0);\n}\n#endif\nvoid main () {\nStandardSurface s; surf(s);\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 1\nvec4 color = CCClusterShadingAdditive(s, v_shadowPos);\n#else\nvec4 color = CCStandardShadingAdditive(s, v_shadowPos);\n#endif\ngl_FragData[0] = CCFragOutput(color);\n}\n#elif (CC_PIPELINE_TYPE == 0 || CC_FORCE_FORWARD_SHADING)\nvoid main () {\nStandardSurface s; surf(s);\nvec4 color = CCStandardShadingBase(s, v_shadowPos);\nCC_APPLY_FOG(color, s.position.xyz);\ngl_FragData[0] = CCFragOutput(color);\n}\n#elif CC_PIPELINE_TYPE == 1\nvec2 signNotZero(vec2 v) {\nreturn vec2((v.x >= 0.0) ? +1.0 : -1.0, (v.y >= 0.0) ? +1.0 : -1.0);\n}\nvec2 float32x3_to_oct(in vec3 v) {\nvec2 p = v.xy * (1.0 / (abs(v.x) + abs(v.y) + abs(v.z)));\nreturn (v.z <= 0.0) ? ((1.0 - abs(p.yx)) * signNotZero(p)) : p;\n}\nvoid main () {\nStandardSurface s; surf(s);\ngl_FragData[0] = s.albedo;\ngl_FragData[1] = vec4(float32x3_to_oct(s.normal), s.roughness, s.metallic);\ngl_FragData[2] = vec4(s.emissive, s.occlusion);\n}\n#endif", }, { "vert": "\nprecision highp float;\nuniform highp mat4 cc_matWorld;\nuniform highp mat4 cc_matLightViewProj;\nattribute vec3 a_position;\nattribute vec3 a_normal;\nattribute vec2 a_texCoord;\nvarying vec2 v_clip_depth;\nvec4 vert () {\nvec4 worldPos;\nworldPos.x = cc_matWorld[3][0] + a_position.x;\nworldPos.y = cc_matWorld[3][1] + a_position.y;\nworldPos.z = cc_matWorld[3][2] + a_position.z;\nworldPos.w = 1.0;\nvec4 clipPos = cc_matLightViewProj * worldPos;\nv_clip_depth = clipPos.zw;\nreturn clipPos;\n}\nvoid main() { gl_Position = vert(); }", @@ -108,49 +108,49 @@ export const glsl1 = [ ], [ { - "vert": "\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\nrgba = rgba * 255.0;\nhighp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\nhighp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\nhighp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\nreturn Sign * exp2(Exponent - 23.0) * Mantissa;\n}\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nattribute vec3 a_position;\nattribute vec3 a_normal;\nattribute vec2 a_texCoord;\nattribute vec4 a_tangent;\n#if CC_USE_SKINNING\nattribute vec4 a_joints;\nattribute vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nattribute highp vec4 a_jointAnimInfo;\n#endif\nattribute vec4 a_matWorld0;\nattribute vec4 a_matWorld1;\nattribute vec4 a_matWorld2;\n#if USE_LIGHTMAP\nattribute vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nattribute vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nattribute float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nattribute float a_vertexId;\nint getVertexId() {\nreturn int(a_vertexId);\n}\n#endif\n#if CC_USE_MORPH\nuniform vec4 cc_displacementWeights[15];\nuniform vec4 cc_displacementTextureInfo;\nvec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\nfloat pixelIndexF = float(pixelIndex);\nfloat x = mod(pixelIndexF, textureResolution.x);\nfloat y = floor(pixelIndexF / textureResolution.x);\nreturn vec2(x, y);\n}\nvec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\nreturn (vec2(location.x, location.y) + .5) / textureResolution;\n}\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 uv = getPixelCoordFromLocation(location, cc_displacementTextureInfo.xy);\nreturn texture2D(tex, uv);\n}\n#else\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex * 4;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\nreturn vec4(\ndecode32(texture2D(tex, x)),\ndecode32(texture2D(tex, y)),\ndecode32(texture2D(tex, z)),\n1.0\n);\n}\n#endif\nfloat getDisplacementWeight(int index) {\nint quot = index / 4;\nint remainder = index - quot * 4;\nif (remainder == 0) {\nreturn cc_displacementWeights[quot].x;\n} else if (remainder == 1) {\nreturn cc_displacementWeights[quot].y;\n} else if (remainder == 2) {\nreturn cc_displacementWeights[quot].z;\n} else {\nreturn cc_displacementWeights[quot].w;\n}\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\nreturn fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n#else\nvec3 result = vec3(0, 0, 0);\nint nVertices = int(cc_displacementTextureInfo.z);\nfor (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\nresult += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n}\nreturn result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\nuniform sampler2D cc_PositionDisplacements;\nvec3 getPositionDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nuniform sampler2D cc_NormalDisplacements;\nvec3 getNormalDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\nuniform sampler2D cc_TangentDisplacements;\nvec3 getTangentDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n}\n#endif\nvoid applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nint vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nnormal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\ntangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\n#if CC_USE_BAKED_ANIMATION\nuniform highp vec4 cc_jointTextureInfo;\nuniform highp vec4 cc_jointAnimInfo;\nuniform highp sampler2D cc_jointTexture;\nvoid CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n{\n#if USE_INSTANCING\nhighp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n#else\nhighp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n#endif\ninvSize = cc_jointTextureInfo.w;\nhighp float tempY = floor(temp * invSize);\nx = floor(temp - tempY * cc_jointTextureInfo.x);\ny = (tempY + 0.5) * invSize;\n}\n#else\nuniform highp vec4 cc_joints[90];\n#endif\n#if CC_USE_BAKED_ANIMATION\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(3.0, i, x, y, invSize);\nvec4 v1 = texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y));\nvec4 v2 = texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y));\nvec4 v3 = texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y));\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#else\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(12.0, i, x, y, invSize);\nvec4 v1 = vec4(\ndecode32(texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n);\nvec4 v2 = vec4(\ndecode32(texture2D(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n);\nvec4 v3 = vec4(\ndecode32(texture2D(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n);\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\n#else\nmat4 getJointMatrix (float i) {\nint idx = int(i);\nvec4 v1 = cc_joints[idx * 3];\nvec4 v2 = cc_joints[idx * 3 + 1];\nvec4 v3 = cc_joints[idx * 3 + 2];\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\nmat4 skinMatrix () {\nvec4 joints = vec4(a_joints);\nreturn getJointMatrix(joints.x) * a_weights.x\n+ getJointMatrix(joints.y) * a_weights.y\n+ getJointMatrix(joints.z) * a_weights.z\n+ getJointMatrix(joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\nmat4 m = skinMatrix();\nposition = m * position;\n}\nvoid CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nmat4 m = skinMatrix();\nposition = m * position;\nnormal = (m * vec4(normal, 0.0)).xyz;\ntangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n}\n#endif\nvoid CCVertInput(inout vec4 In)\n{\nIn = vec4(a_position, 1.0);\n#if CC_USE_MORPH\napplyMorph(In);\n#endif\n#if CC_USE_SKINNING\nCCSkin(In);\n#endif\n}\nuniform highp mat4 cc_matView;\nuniform highp mat4 cc_matProj;\nuniform highp vec4 cc_cameraPos;\nuniform mediump vec4 cc_fogBase;\nuniform mediump vec4 cc_fogAdd;\n#if !USE_INSTANCING\n#if USE_BATCHING\nuniform highp mat4 cc_matWorlds[10];\n#else\nuniform highp mat4 cc_matWorld;\n#endif\n#endif\nvoid CCGetWorldMatrix(out mat4 matWorld)\n{\n#if USE_INSTANCING\nmatWorld = mat4(\nvec4(a_matWorld0.xyz, 0.0),\nvec4(a_matWorld1.xyz, 0.0),\nvec4(a_matWorld2.xyz, 0.0),\nvec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)\n);\n#elif USE_BATCHING\nmatWorld = cc_matWorlds[int(a_dyn_batch_id)];\n#else\nmatWorld = cc_matWorld;\n#endif\n}\nfloat LinearFog(vec4 pos) {\nvec4 wPos = pos;\nfloat cam_dis = distance(cc_cameraPos, wPos);\nfloat fogStart = cc_fogBase.x;\nfloat fogEnd = cc_fogBase.y;\nreturn clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * fogDensity);\nreturn f;\n}\nfloat ExpSquaredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\nreturn f;\n}\nfloat LayeredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat _FogTop = cc_fogAdd.x;\nfloat _FogRange = cc_fogAdd.y;\nvec3 camWorldProj = cc_cameraPos.xyz;\ncamWorldProj.y = 0.;\nvec3 worldPosProj = wPos.xyz;\nworldPosProj.y = 0.;\nfloat fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\nfloat fDeltaY, fDensityIntegral;\nif (cc_cameraPos.y > _FogTop) {\nif (wPos.y < _FogTop) {\nfDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\nfDensityIntegral = fDeltaY * fDeltaY * 0.5;\n} else {\nfDeltaY = 0.;\nfDensityIntegral = 0.;\n}\n} else {\nif (wPos.y < _FogTop) {\nfloat fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfloat fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\nfDeltaY = abs(fDeltaA - fDeltaB);\nfDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n} else {\nfDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n}\n}\nfloat fDensity;\nif (fDeltaY != 0.) {\nfDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n} else {\nfDensity = 0.;\n}\nfloat f = exp(-fDensity);\nreturn f;\n}\nvoid CC_TRANSFER_FOG_BASE(vec4 pos, out float factor)\n{\n#if CC_USE_FOG == 0\nfactor = LinearFog(pos);\n#elif CC_USE_FOG == 1\nfactor = ExpFog(pos);\n#elif CC_USE_FOG == 2\nfactor = ExpSquaredFog(pos);\n#elif CC_USE_FOG == 3\nfactor = LayeredFog(pos);\n#else\nfactor = 1.0;\n#endif\n}\n#if !CC_USE_ACCURATE_FOG\nvarying float v_fog_factor;\n#endif\nvoid CC_TRANSFER_FOG(vec4 pos) {\n#if !CC_USE_ACCURATE_FOG\nCC_TRANSFER_FOG_BASE(pos, v_fog_factor);\n#endif\n}\n#if USE_VERTEX_COLOR\nattribute lowp vec4 a_color;\nvarying lowp vec4 v_color;\n#endif\n#if USE_TEXTURE\nvarying vec2 v_uv;\nuniform vec4 tilingOffset;\n#endif\nvec4 vert () {\nvec4 position;\nCCVertInput(position);\nmat4 matWorld;\nCCGetWorldMatrix(matWorld);\n#if USE_TEXTURE\nv_uv = a_texCoord * tilingOffset.xy + tilingOffset.zw;\n#if SAMPLE_FROM_RT\nv_uv = cc_cameraPos.w > 1.0 ? vec2(v_uv.x, 1.0 - v_uv.y) : v_uv;\n#endif\n#endif\n#if USE_VERTEX_COLOR\nv_color = a_color;\n#endif\nCC_TRANSFER_FOG(matWorld * position);\nreturn cc_matProj * (cc_matView * matWorld) * position;\n}\nvoid main() { gl_Position = vert(); }", + "vert": "\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\nrgba = rgba * 255.0;\nhighp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\nhighp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\nhighp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\nreturn Sign * exp2(Exponent - 23.0) * Mantissa;\n}\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nattribute vec3 a_position;\nattribute vec3 a_normal;\nattribute vec2 a_texCoord;\nattribute vec4 a_tangent;\n#if CC_USE_SKINNING\nattribute vec4 a_joints;\nattribute vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nattribute highp vec4 a_jointAnimInfo;\n#endif\nattribute vec4 a_matWorld0;\nattribute vec4 a_matWorld1;\nattribute vec4 a_matWorld2;\n#if CC_USE_LIGHTMAP\nattribute vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nattribute vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nattribute float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nattribute float a_vertexId;\nint getVertexId() {\nreturn int(a_vertexId);\n}\n#endif\n#if CC_USE_MORPH\nuniform vec4 cc_displacementWeights[15];\nuniform vec4 cc_displacementTextureInfo;\nvec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\nfloat pixelIndexF = float(pixelIndex);\nfloat x = mod(pixelIndexF, textureResolution.x);\nfloat y = floor(pixelIndexF / textureResolution.x);\nreturn vec2(x, y);\n}\nvec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\nreturn (vec2(location.x, location.y) + .5) / textureResolution;\n}\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 uv = getPixelCoordFromLocation(location, cc_displacementTextureInfo.xy);\nreturn texture2D(tex, uv);\n}\n#else\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex * 4;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\nreturn vec4(\ndecode32(texture2D(tex, x)),\ndecode32(texture2D(tex, y)),\ndecode32(texture2D(tex, z)),\n1.0\n);\n}\n#endif\nfloat getDisplacementWeight(int index) {\nint quot = index / 4;\nint remainder = index - quot * 4;\nif (remainder == 0) {\nreturn cc_displacementWeights[quot].x;\n} else if (remainder == 1) {\nreturn cc_displacementWeights[quot].y;\n} else if (remainder == 2) {\nreturn cc_displacementWeights[quot].z;\n} else {\nreturn cc_displacementWeights[quot].w;\n}\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\nreturn fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n#else\nvec3 result = vec3(0, 0, 0);\nint nVertices = int(cc_displacementTextureInfo.z);\nfor (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\nresult += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n}\nreturn result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\nuniform sampler2D cc_PositionDisplacements;\nvec3 getPositionDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nuniform sampler2D cc_NormalDisplacements;\nvec3 getNormalDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\nuniform sampler2D cc_TangentDisplacements;\nvec3 getTangentDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n}\n#endif\nvoid applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nint vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nnormal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\ntangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\n#if CC_USE_BAKED_ANIMATION\nuniform highp vec4 cc_jointTextureInfo;\nuniform highp vec4 cc_jointAnimInfo;\nuniform highp sampler2D cc_jointTexture;\nvoid CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n{\n#if USE_INSTANCING\nhighp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n#else\nhighp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n#endif\ninvSize = cc_jointTextureInfo.w;\nhighp float tempY = floor(temp * invSize);\nx = floor(temp - tempY * cc_jointTextureInfo.x);\ny = (tempY + 0.5) * invSize;\n}\n#else\nuniform highp vec4 cc_joints[90];\n#endif\n#if CC_USE_BAKED_ANIMATION\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(3.0, i, x, y, invSize);\nvec4 v1 = texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y));\nvec4 v2 = texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y));\nvec4 v3 = texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y));\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#else\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(12.0, i, x, y, invSize);\nvec4 v1 = vec4(\ndecode32(texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n);\nvec4 v2 = vec4(\ndecode32(texture2D(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n);\nvec4 v3 = vec4(\ndecode32(texture2D(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n);\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\n#else\nmat4 getJointMatrix (float i) {\nint idx = int(i);\nvec4 v1 = cc_joints[idx * 3];\nvec4 v2 = cc_joints[idx * 3 + 1];\nvec4 v3 = cc_joints[idx * 3 + 2];\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\nmat4 skinMatrix () {\nvec4 joints = vec4(a_joints);\nreturn getJointMatrix(joints.x) * a_weights.x\n+ getJointMatrix(joints.y) * a_weights.y\n+ getJointMatrix(joints.z) * a_weights.z\n+ getJointMatrix(joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\nmat4 m = skinMatrix();\nposition = m * position;\n}\nvoid CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nmat4 m = skinMatrix();\nposition = m * position;\nnormal = (m * vec4(normal, 0.0)).xyz;\ntangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n}\n#endif\nvoid CCVertInput(inout vec4 In)\n{\nIn = vec4(a_position, 1.0);\n#if CC_USE_MORPH\napplyMorph(In);\n#endif\n#if CC_USE_SKINNING\nCCSkin(In);\n#endif\n}\nuniform highp mat4 cc_matView;\nuniform highp mat4 cc_matProj;\nuniform highp vec4 cc_cameraPos;\nuniform mediump vec4 cc_fogBase;\nuniform mediump vec4 cc_fogAdd;\n#if !USE_INSTANCING\n#if USE_BATCHING\nuniform highp mat4 cc_matWorlds[10];\n#else\nuniform highp mat4 cc_matWorld;\n#endif\n#endif\nvoid CCGetWorldMatrix(out mat4 matWorld)\n{\n#if USE_INSTANCING\nmatWorld = mat4(\nvec4(a_matWorld0.xyz, 0.0),\nvec4(a_matWorld1.xyz, 0.0),\nvec4(a_matWorld2.xyz, 0.0),\nvec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)\n);\n#elif USE_BATCHING\nmatWorld = cc_matWorlds[int(a_dyn_batch_id)];\n#else\nmatWorld = cc_matWorld;\n#endif\n}\nfloat LinearFog(vec4 pos) {\nvec4 wPos = pos;\nfloat cam_dis = distance(cc_cameraPos, wPos);\nfloat fogStart = cc_fogBase.x;\nfloat fogEnd = cc_fogBase.y;\nreturn clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * fogDensity);\nreturn f;\n}\nfloat ExpSquaredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\nreturn f;\n}\nfloat LayeredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat _FogTop = cc_fogAdd.x;\nfloat _FogRange = cc_fogAdd.y;\nvec3 camWorldProj = cc_cameraPos.xyz;\ncamWorldProj.y = 0.;\nvec3 worldPosProj = wPos.xyz;\nworldPosProj.y = 0.;\nfloat fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\nfloat fDeltaY, fDensityIntegral;\nif (cc_cameraPos.y > _FogTop) {\nif (wPos.y < _FogTop) {\nfDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\nfDensityIntegral = fDeltaY * fDeltaY * 0.5;\n} else {\nfDeltaY = 0.;\nfDensityIntegral = 0.;\n}\n} else {\nif (wPos.y < _FogTop) {\nfloat fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfloat fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\nfDeltaY = abs(fDeltaA - fDeltaB);\nfDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n} else {\nfDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n}\n}\nfloat fDensity;\nif (fDeltaY != 0.) {\nfDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n} else {\nfDensity = 0.;\n}\nfloat f = exp(-fDensity);\nreturn f;\n}\nvoid CC_TRANSFER_FOG_BASE(vec4 pos, out float factor)\n{\n#if CC_USE_FOG == 0\nfactor = LinearFog(pos);\n#elif CC_USE_FOG == 1\nfactor = ExpFog(pos);\n#elif CC_USE_FOG == 2\nfactor = ExpSquaredFog(pos);\n#elif CC_USE_FOG == 3\nfactor = LayeredFog(pos);\n#else\nfactor = 1.0;\n#endif\n}\n#if !CC_USE_ACCURATE_FOG\nvarying float v_fog_factor;\n#endif\nvoid CC_TRANSFER_FOG(vec4 pos) {\n#if !CC_USE_ACCURATE_FOG\nCC_TRANSFER_FOG_BASE(pos, v_fog_factor);\n#endif\n}\n#if USE_VERTEX_COLOR\nattribute lowp vec4 a_color;\nvarying lowp vec4 v_color;\n#endif\n#if USE_TEXTURE\nvarying vec2 v_uv;\nuniform vec4 tilingOffset;\n#endif\nvec4 vert () {\nvec4 position;\nCCVertInput(position);\nmat4 matWorld;\nCCGetWorldMatrix(matWorld);\n#if USE_TEXTURE\nv_uv = a_texCoord * tilingOffset.xy + tilingOffset.zw;\n#if SAMPLE_FROM_RT\nv_uv = cc_cameraPos.w > 1.0 ? vec2(v_uv.x, 1.0 - v_uv.y) : v_uv;\n#endif\n#endif\n#if USE_VERTEX_COLOR\nv_color = a_color;\n#endif\nCC_TRANSFER_FOG(matWorld * position);\nreturn cc_matProj * (cc_matView * matWorld) * position;\n}\nvoid main() { gl_Position = vert(); }", "frag": "\nprecision highp float;\nvec3 ACESToneMap (vec3 color) {\ncolor = min(color, vec3(8.0));\nconst float A = 2.51;\nconst float B = 0.03;\nconst float C = 2.43;\nconst float D = 0.59;\nconst float E = 0.14;\nreturn (color * (A * color + B)) / (color * (C * color + D) + E);\n}\nvec3 SRGBToLinear (vec3 gamma) {\nreturn gamma * gamma;\n}\nvec4 CCFragOutput (vec4 color) {\n#if CC_USE_HDR\ncolor.rgb = ACESToneMap(color.rgb);\n#endif\ncolor.rgb = sqrt(color.rgb);\nreturn color;\n}\nuniform highp vec4 cc_cameraPos;\nuniform mediump vec4 cc_fogColor;\nuniform mediump vec4 cc_fogBase;\nuniform mediump vec4 cc_fogAdd;\nfloat LinearFog(vec4 pos) {\nvec4 wPos = pos;\nfloat cam_dis = distance(cc_cameraPos, wPos);\nfloat fogStart = cc_fogBase.x;\nfloat fogEnd = cc_fogBase.y;\nreturn clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * fogDensity);\nreturn f;\n}\nfloat ExpSquaredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\nreturn f;\n}\nfloat LayeredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat _FogTop = cc_fogAdd.x;\nfloat _FogRange = cc_fogAdd.y;\nvec3 camWorldProj = cc_cameraPos.xyz;\ncamWorldProj.y = 0.;\nvec3 worldPosProj = wPos.xyz;\nworldPosProj.y = 0.;\nfloat fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\nfloat fDeltaY, fDensityIntegral;\nif (cc_cameraPos.y > _FogTop) {\nif (wPos.y < _FogTop) {\nfDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\nfDensityIntegral = fDeltaY * fDeltaY * 0.5;\n} else {\nfDeltaY = 0.;\nfDensityIntegral = 0.;\n}\n} else {\nif (wPos.y < _FogTop) {\nfloat fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfloat fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\nfDeltaY = abs(fDeltaA - fDeltaB);\nfDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n} else {\nfDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n}\n}\nfloat fDensity;\nif (fDeltaY != 0.) {\nfDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n} else {\nfDensity = 0.;\n}\nfloat f = exp(-fDensity);\nreturn f;\n}\nvoid CC_TRANSFER_FOG_BASE(vec4 pos, out float factor)\n{\n#if CC_USE_FOG == 0\nfactor = LinearFog(pos);\n#elif CC_USE_FOG == 1\nfactor = ExpFog(pos);\n#elif CC_USE_FOG == 2\nfactor = ExpSquaredFog(pos);\n#elif CC_USE_FOG == 3\nfactor = LayeredFog(pos);\n#else\nfactor = 1.0;\n#endif\n}\nvoid CC_APPLY_FOG_BASE(inout vec4 color, float factor) {\ncolor = vec4(mix(cc_fogColor.rgb, color.rgb, factor), color.a);\n}\n#if !CC_USE_ACCURATE_FOG\nvarying float v_fog_factor;\n#endif\nvoid CC_APPLY_FOG(inout vec4 color) {\n#if !CC_USE_ACCURATE_FOG\nCC_APPLY_FOG_BASE(color, v_fog_factor);\n#endif\n}\nvoid CC_APPLY_FOG(inout vec4 color, vec3 worldPos) {\n#if CC_USE_ACCURATE_FOG\nfloat factor;\nCC_TRANSFER_FOG_BASE(vec4(worldPos, 1.0), factor);\n#else\nfloat factor = v_fog_factor;\n#endif\nCC_APPLY_FOG_BASE(color, factor);\n}\n#if USE_ALPHA_TEST\n#endif\n#if USE_TEXTURE\nvarying vec2 v_uv;\nuniform sampler2D mainTexture;\n#endif\nuniform vec4 mainColor;\nuniform vec4 colorScaleAndCutoff;\n#if USE_VERTEX_COLOR\nvarying lowp vec4 v_color;\n#endif\nvec4 frag () {\nvec4 o = mainColor;\no.rgb *= colorScaleAndCutoff.xyz;\n#if USE_VERTEX_COLOR\no.rgb *= SRGBToLinear(v_color.rgb);\no.a *= v_color.a;\n#endif\n#if USE_TEXTURE\nvec4 texColor = texture2D(mainTexture, v_uv);\ntexColor.rgb = SRGBToLinear(texColor.rgb);\no *= texColor;\n#endif\n#if USE_ALPHA_TEST\nif (o.ALPHA_TEST_CHANNEL < colorScaleAndCutoff.w) discard;\n#endif\nCC_APPLY_FOG(o);\nreturn CCFragOutput(o);\n}\nvoid main() { gl_FragColor = frag(); }", } ], [ { - "vert": "\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\nrgba = rgba * 255.0;\nhighp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\nhighp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\nhighp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\nreturn Sign * exp2(Exponent - 23.0) * Mantissa;\n}\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nattribute vec3 a_position;\nattribute vec3 a_normal;\nattribute vec2 a_texCoord;\nattribute vec4 a_tangent;\n#if CC_USE_SKINNING\nattribute vec4 a_joints;\nattribute vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nattribute highp vec4 a_jointAnimInfo;\n#endif\nattribute vec4 a_matWorld0;\nattribute vec4 a_matWorld1;\nattribute vec4 a_matWorld2;\n#if USE_LIGHTMAP\nattribute vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nattribute vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nattribute float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nattribute float a_vertexId;\nint getVertexId() {\nreturn int(a_vertexId);\n}\n#endif\n#if CC_USE_MORPH\nuniform vec4 cc_displacementWeights[15];\nuniform vec4 cc_displacementTextureInfo;\nvec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\nfloat pixelIndexF = float(pixelIndex);\nfloat x = mod(pixelIndexF, textureResolution.x);\nfloat y = floor(pixelIndexF / textureResolution.x);\nreturn vec2(x, y);\n}\nvec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\nreturn (vec2(location.x, location.y) + .5) / textureResolution;\n}\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 uv = getPixelCoordFromLocation(location, cc_displacementTextureInfo.xy);\nreturn texture2D(tex, uv);\n}\n#else\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex * 4;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\nreturn vec4(\ndecode32(texture2D(tex, x)),\ndecode32(texture2D(tex, y)),\ndecode32(texture2D(tex, z)),\n1.0\n);\n}\n#endif\nfloat getDisplacementWeight(int index) {\nint quot = index / 4;\nint remainder = index - quot * 4;\nif (remainder == 0) {\nreturn cc_displacementWeights[quot].x;\n} else if (remainder == 1) {\nreturn cc_displacementWeights[quot].y;\n} else if (remainder == 2) {\nreturn cc_displacementWeights[quot].z;\n} else {\nreturn cc_displacementWeights[quot].w;\n}\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\nreturn fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n#else\nvec3 result = vec3(0, 0, 0);\nint nVertices = int(cc_displacementTextureInfo.z);\nfor (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\nresult += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n}\nreturn result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\nuniform sampler2D cc_PositionDisplacements;\nvec3 getPositionDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nuniform sampler2D cc_NormalDisplacements;\nvec3 getNormalDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\nuniform sampler2D cc_TangentDisplacements;\nvec3 getTangentDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n}\n#endif\nvoid applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nint vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nnormal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\ntangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\n#if CC_USE_BAKED_ANIMATION\nuniform highp vec4 cc_jointTextureInfo;\nuniform highp vec4 cc_jointAnimInfo;\nuniform highp sampler2D cc_jointTexture;\nvoid CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n{\n#if USE_INSTANCING\nhighp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n#else\nhighp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n#endif\ninvSize = cc_jointTextureInfo.w;\nhighp float tempY = floor(temp * invSize);\nx = floor(temp - tempY * cc_jointTextureInfo.x);\ny = (tempY + 0.5) * invSize;\n}\n#else\nuniform highp vec4 cc_joints[90];\n#endif\n#if CC_USE_BAKED_ANIMATION\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(3.0, i, x, y, invSize);\nvec4 v1 = texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y));\nvec4 v2 = texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y));\nvec4 v3 = texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y));\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#else\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(12.0, i, x, y, invSize);\nvec4 v1 = vec4(\ndecode32(texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n);\nvec4 v2 = vec4(\ndecode32(texture2D(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n);\nvec4 v3 = vec4(\ndecode32(texture2D(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n);\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\n#else\nmat4 getJointMatrix (float i) {\nint idx = int(i);\nvec4 v1 = cc_joints[idx * 3];\nvec4 v2 = cc_joints[idx * 3 + 1];\nvec4 v3 = cc_joints[idx * 3 + 2];\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\nmat4 skinMatrix () {\nvec4 joints = vec4(a_joints);\nreturn getJointMatrix(joints.x) * a_weights.x\n+ getJointMatrix(joints.y) * a_weights.y\n+ getJointMatrix(joints.z) * a_weights.z\n+ getJointMatrix(joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\nmat4 m = skinMatrix();\nposition = m * position;\n}\nvoid CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nmat4 m = skinMatrix();\nposition = m * position;\nnormal = (m * vec4(normal, 0.0)).xyz;\ntangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n}\n#endif\nvoid CCVertInput(inout StandardVertInput In)\n{\nIn.position = vec4(a_position, 1.0);\nIn.normal = a_normal;\nIn.tangent = a_tangent;\n#if CC_USE_MORPH\napplyMorph(In.position, In.normal, In.tangent);\n#endif\n#if CC_USE_SKINNING\nCCSkin(In.position, In.normal, In.tangent);\n#endif\n}\nuniform highp vec4 cc_cameraPos;\nvarying vec2 v_uv;\nvoid main () {\nStandardVertInput In;\nCCVertInput(In);\nIn.position.xy = cc_cameraPos.w == 0.0 ? vec2(In.position.xy.x, -In.position.xy.y) : In.position.xy;\ngl_Position = In.position;\ngl_Position.y = gl_Position.y;\nv_uv = a_texCoord;\n}", + "vert": "\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\nrgba = rgba * 255.0;\nhighp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\nhighp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\nhighp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\nreturn Sign * exp2(Exponent - 23.0) * Mantissa;\n}\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nattribute vec3 a_position;\nattribute vec3 a_normal;\nattribute vec2 a_texCoord;\nattribute vec4 a_tangent;\n#if CC_USE_SKINNING\nattribute vec4 a_joints;\nattribute vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nattribute highp vec4 a_jointAnimInfo;\n#endif\nattribute vec4 a_matWorld0;\nattribute vec4 a_matWorld1;\nattribute vec4 a_matWorld2;\n#if CC_USE_LIGHTMAP\nattribute vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nattribute vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nattribute float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nattribute float a_vertexId;\nint getVertexId() {\nreturn int(a_vertexId);\n}\n#endif\n#if CC_USE_MORPH\nuniform vec4 cc_displacementWeights[15];\nuniform vec4 cc_displacementTextureInfo;\nvec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\nfloat pixelIndexF = float(pixelIndex);\nfloat x = mod(pixelIndexF, textureResolution.x);\nfloat y = floor(pixelIndexF / textureResolution.x);\nreturn vec2(x, y);\n}\nvec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\nreturn (vec2(location.x, location.y) + .5) / textureResolution;\n}\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 uv = getPixelCoordFromLocation(location, cc_displacementTextureInfo.xy);\nreturn texture2D(tex, uv);\n}\n#else\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex * 4;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\nreturn vec4(\ndecode32(texture2D(tex, x)),\ndecode32(texture2D(tex, y)),\ndecode32(texture2D(tex, z)),\n1.0\n);\n}\n#endif\nfloat getDisplacementWeight(int index) {\nint quot = index / 4;\nint remainder = index - quot * 4;\nif (remainder == 0) {\nreturn cc_displacementWeights[quot].x;\n} else if (remainder == 1) {\nreturn cc_displacementWeights[quot].y;\n} else if (remainder == 2) {\nreturn cc_displacementWeights[quot].z;\n} else {\nreturn cc_displacementWeights[quot].w;\n}\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\nreturn fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n#else\nvec3 result = vec3(0, 0, 0);\nint nVertices = int(cc_displacementTextureInfo.z);\nfor (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\nresult += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n}\nreturn result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\nuniform sampler2D cc_PositionDisplacements;\nvec3 getPositionDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nuniform sampler2D cc_NormalDisplacements;\nvec3 getNormalDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\nuniform sampler2D cc_TangentDisplacements;\nvec3 getTangentDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n}\n#endif\nvoid applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nint vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nnormal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\ntangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\n#if CC_USE_BAKED_ANIMATION\nuniform highp vec4 cc_jointTextureInfo;\nuniform highp vec4 cc_jointAnimInfo;\nuniform highp sampler2D cc_jointTexture;\nvoid CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n{\n#if USE_INSTANCING\nhighp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n#else\nhighp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n#endif\ninvSize = cc_jointTextureInfo.w;\nhighp float tempY = floor(temp * invSize);\nx = floor(temp - tempY * cc_jointTextureInfo.x);\ny = (tempY + 0.5) * invSize;\n}\n#else\nuniform highp vec4 cc_joints[90];\n#endif\n#if CC_USE_BAKED_ANIMATION\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(3.0, i, x, y, invSize);\nvec4 v1 = texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y));\nvec4 v2 = texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y));\nvec4 v3 = texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y));\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#else\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(12.0, i, x, y, invSize);\nvec4 v1 = vec4(\ndecode32(texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n);\nvec4 v2 = vec4(\ndecode32(texture2D(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n);\nvec4 v3 = vec4(\ndecode32(texture2D(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n);\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\n#else\nmat4 getJointMatrix (float i) {\nint idx = int(i);\nvec4 v1 = cc_joints[idx * 3];\nvec4 v2 = cc_joints[idx * 3 + 1];\nvec4 v3 = cc_joints[idx * 3 + 2];\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\nmat4 skinMatrix () {\nvec4 joints = vec4(a_joints);\nreturn getJointMatrix(joints.x) * a_weights.x\n+ getJointMatrix(joints.y) * a_weights.y\n+ getJointMatrix(joints.z) * a_weights.z\n+ getJointMatrix(joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\nmat4 m = skinMatrix();\nposition = m * position;\n}\nvoid CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nmat4 m = skinMatrix();\nposition = m * position;\nnormal = (m * vec4(normal, 0.0)).xyz;\ntangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n}\n#endif\nvoid CCVertInput(inout StandardVertInput In)\n{\nIn.position = vec4(a_position, 1.0);\nIn.normal = a_normal;\nIn.tangent = a_tangent;\n#if CC_USE_MORPH\napplyMorph(In.position, In.normal, In.tangent);\n#endif\n#if CC_USE_SKINNING\nCCSkin(In.position, In.normal, In.tangent);\n#endif\n}\nuniform highp vec4 cc_cameraPos;\nvarying vec2 v_uv;\nvoid main () {\nStandardVertInput In;\nCCVertInput(In);\nIn.position.xy = cc_cameraPos.w == 0.0 ? vec2(In.position.xy.x, -In.position.xy.y) : In.position.xy;\ngl_Position = In.position;\ngl_Position.y = gl_Position.y;\nv_uv = a_texCoord;\n}", "frag": "\nprecision highp float;\nvec3 SRGBToLinear (vec3 gamma) {\nreturn gamma * gamma;\n}\nvarying vec2 v_uv;\nuniform mediump vec4 texSize;\nuniform sampler2D outputResultMap;\nfloat luminance(vec3 color) {\nreturn dot(color, vec3(0.2126, 0.7152, 0.0722));\n}\nvoid main() {\nvec3 color = texture2D(outputResultMap, v_uv).xyz;\nif (luminance(SRGBToLinear(color)) > texSize.z) {\ngl_FragColor = vec4(color, 1.0);\n} else {\ngl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);\n}\n}", }, { - "vert": "\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\nrgba = rgba * 255.0;\nhighp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\nhighp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\nhighp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\nreturn Sign * exp2(Exponent - 23.0) * Mantissa;\n}\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nattribute vec3 a_position;\nattribute vec3 a_normal;\nattribute vec2 a_texCoord;\nattribute vec4 a_tangent;\n#if CC_USE_SKINNING\nattribute vec4 a_joints;\nattribute vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nattribute highp vec4 a_jointAnimInfo;\n#endif\nattribute vec4 a_matWorld0;\nattribute vec4 a_matWorld1;\nattribute vec4 a_matWorld2;\n#if USE_LIGHTMAP\nattribute vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nattribute vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nattribute float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nattribute float a_vertexId;\nint getVertexId() {\nreturn int(a_vertexId);\n}\n#endif\n#if CC_USE_MORPH\nuniform vec4 cc_displacementWeights[15];\nuniform vec4 cc_displacementTextureInfo;\nvec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\nfloat pixelIndexF = float(pixelIndex);\nfloat x = mod(pixelIndexF, textureResolution.x);\nfloat y = floor(pixelIndexF / textureResolution.x);\nreturn vec2(x, y);\n}\nvec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\nreturn (vec2(location.x, location.y) + .5) / textureResolution;\n}\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 uv = getPixelCoordFromLocation(location, cc_displacementTextureInfo.xy);\nreturn texture2D(tex, uv);\n}\n#else\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex * 4;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\nreturn vec4(\ndecode32(texture2D(tex, x)),\ndecode32(texture2D(tex, y)),\ndecode32(texture2D(tex, z)),\n1.0\n);\n}\n#endif\nfloat getDisplacementWeight(int index) {\nint quot = index / 4;\nint remainder = index - quot * 4;\nif (remainder == 0) {\nreturn cc_displacementWeights[quot].x;\n} else if (remainder == 1) {\nreturn cc_displacementWeights[quot].y;\n} else if (remainder == 2) {\nreturn cc_displacementWeights[quot].z;\n} else {\nreturn cc_displacementWeights[quot].w;\n}\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\nreturn fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n#else\nvec3 result = vec3(0, 0, 0);\nint nVertices = int(cc_displacementTextureInfo.z);\nfor (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\nresult += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n}\nreturn result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\nuniform sampler2D cc_PositionDisplacements;\nvec3 getPositionDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nuniform sampler2D cc_NormalDisplacements;\nvec3 getNormalDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\nuniform sampler2D cc_TangentDisplacements;\nvec3 getTangentDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n}\n#endif\nvoid applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nint vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nnormal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\ntangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\n#if CC_USE_BAKED_ANIMATION\nuniform highp vec4 cc_jointTextureInfo;\nuniform highp vec4 cc_jointAnimInfo;\nuniform highp sampler2D cc_jointTexture;\nvoid CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n{\n#if USE_INSTANCING\nhighp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n#else\nhighp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n#endif\ninvSize = cc_jointTextureInfo.w;\nhighp float tempY = floor(temp * invSize);\nx = floor(temp - tempY * cc_jointTextureInfo.x);\ny = (tempY + 0.5) * invSize;\n}\n#else\nuniform highp vec4 cc_joints[90];\n#endif\n#if CC_USE_BAKED_ANIMATION\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(3.0, i, x, y, invSize);\nvec4 v1 = texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y));\nvec4 v2 = texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y));\nvec4 v3 = texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y));\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#else\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(12.0, i, x, y, invSize);\nvec4 v1 = vec4(\ndecode32(texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n);\nvec4 v2 = vec4(\ndecode32(texture2D(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n);\nvec4 v3 = vec4(\ndecode32(texture2D(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n);\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\n#else\nmat4 getJointMatrix (float i) {\nint idx = int(i);\nvec4 v1 = cc_joints[idx * 3];\nvec4 v2 = cc_joints[idx * 3 + 1];\nvec4 v3 = cc_joints[idx * 3 + 2];\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\nmat4 skinMatrix () {\nvec4 joints = vec4(a_joints);\nreturn getJointMatrix(joints.x) * a_weights.x\n+ getJointMatrix(joints.y) * a_weights.y\n+ getJointMatrix(joints.z) * a_weights.z\n+ getJointMatrix(joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\nmat4 m = skinMatrix();\nposition = m * position;\n}\nvoid CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nmat4 m = skinMatrix();\nposition = m * position;\nnormal = (m * vec4(normal, 0.0)).xyz;\ntangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n}\n#endif\nvoid CCVertInput(inout StandardVertInput In)\n{\nIn.position = vec4(a_position, 1.0);\nIn.normal = a_normal;\nIn.tangent = a_tangent;\n#if CC_USE_MORPH\napplyMorph(In.position, In.normal, In.tangent);\n#endif\n#if CC_USE_SKINNING\nCCSkin(In.position, In.normal, In.tangent);\n#endif\n}\nuniform highp vec4 cc_cameraPos;\nvarying vec2 v_uv;\nvoid main () {\nStandardVertInput In;\nCCVertInput(In);\nIn.position.xy = cc_cameraPos.w == 0.0 ? vec2(In.position.xy.x, -In.position.xy.y) : In.position.xy;\ngl_Position = In.position;\ngl_Position.y = gl_Position.y;\nv_uv = a_texCoord;\n}", + "vert": "\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\nrgba = rgba * 255.0;\nhighp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\nhighp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\nhighp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\nreturn Sign * exp2(Exponent - 23.0) * Mantissa;\n}\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nattribute vec3 a_position;\nattribute vec3 a_normal;\nattribute vec2 a_texCoord;\nattribute vec4 a_tangent;\n#if CC_USE_SKINNING\nattribute vec4 a_joints;\nattribute vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nattribute highp vec4 a_jointAnimInfo;\n#endif\nattribute vec4 a_matWorld0;\nattribute vec4 a_matWorld1;\nattribute vec4 a_matWorld2;\n#if CC_USE_LIGHTMAP\nattribute vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nattribute vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nattribute float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nattribute float a_vertexId;\nint getVertexId() {\nreturn int(a_vertexId);\n}\n#endif\n#if CC_USE_MORPH\nuniform vec4 cc_displacementWeights[15];\nuniform vec4 cc_displacementTextureInfo;\nvec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\nfloat pixelIndexF = float(pixelIndex);\nfloat x = mod(pixelIndexF, textureResolution.x);\nfloat y = floor(pixelIndexF / textureResolution.x);\nreturn vec2(x, y);\n}\nvec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\nreturn (vec2(location.x, location.y) + .5) / textureResolution;\n}\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 uv = getPixelCoordFromLocation(location, cc_displacementTextureInfo.xy);\nreturn texture2D(tex, uv);\n}\n#else\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex * 4;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\nreturn vec4(\ndecode32(texture2D(tex, x)),\ndecode32(texture2D(tex, y)),\ndecode32(texture2D(tex, z)),\n1.0\n);\n}\n#endif\nfloat getDisplacementWeight(int index) {\nint quot = index / 4;\nint remainder = index - quot * 4;\nif (remainder == 0) {\nreturn cc_displacementWeights[quot].x;\n} else if (remainder == 1) {\nreturn cc_displacementWeights[quot].y;\n} else if (remainder == 2) {\nreturn cc_displacementWeights[quot].z;\n} else {\nreturn cc_displacementWeights[quot].w;\n}\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\nreturn fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n#else\nvec3 result = vec3(0, 0, 0);\nint nVertices = int(cc_displacementTextureInfo.z);\nfor (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\nresult += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n}\nreturn result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\nuniform sampler2D cc_PositionDisplacements;\nvec3 getPositionDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nuniform sampler2D cc_NormalDisplacements;\nvec3 getNormalDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\nuniform sampler2D cc_TangentDisplacements;\nvec3 getTangentDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n}\n#endif\nvoid applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nint vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nnormal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\ntangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\n#if CC_USE_BAKED_ANIMATION\nuniform highp vec4 cc_jointTextureInfo;\nuniform highp vec4 cc_jointAnimInfo;\nuniform highp sampler2D cc_jointTexture;\nvoid CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n{\n#if USE_INSTANCING\nhighp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n#else\nhighp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n#endif\ninvSize = cc_jointTextureInfo.w;\nhighp float tempY = floor(temp * invSize);\nx = floor(temp - tempY * cc_jointTextureInfo.x);\ny = (tempY + 0.5) * invSize;\n}\n#else\nuniform highp vec4 cc_joints[90];\n#endif\n#if CC_USE_BAKED_ANIMATION\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(3.0, i, x, y, invSize);\nvec4 v1 = texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y));\nvec4 v2 = texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y));\nvec4 v3 = texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y));\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#else\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(12.0, i, x, y, invSize);\nvec4 v1 = vec4(\ndecode32(texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n);\nvec4 v2 = vec4(\ndecode32(texture2D(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n);\nvec4 v3 = vec4(\ndecode32(texture2D(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n);\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\n#else\nmat4 getJointMatrix (float i) {\nint idx = int(i);\nvec4 v1 = cc_joints[idx * 3];\nvec4 v2 = cc_joints[idx * 3 + 1];\nvec4 v3 = cc_joints[idx * 3 + 2];\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\nmat4 skinMatrix () {\nvec4 joints = vec4(a_joints);\nreturn getJointMatrix(joints.x) * a_weights.x\n+ getJointMatrix(joints.y) * a_weights.y\n+ getJointMatrix(joints.z) * a_weights.z\n+ getJointMatrix(joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\nmat4 m = skinMatrix();\nposition = m * position;\n}\nvoid CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nmat4 m = skinMatrix();\nposition = m * position;\nnormal = (m * vec4(normal, 0.0)).xyz;\ntangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n}\n#endif\nvoid CCVertInput(inout StandardVertInput In)\n{\nIn.position = vec4(a_position, 1.0);\nIn.normal = a_normal;\nIn.tangent = a_tangent;\n#if CC_USE_MORPH\napplyMorph(In.position, In.normal, In.tangent);\n#endif\n#if CC_USE_SKINNING\nCCSkin(In.position, In.normal, In.tangent);\n#endif\n}\nuniform highp vec4 cc_cameraPos;\nvarying vec2 v_uv;\nvoid main () {\nStandardVertInput In;\nCCVertInput(In);\nIn.position.xy = cc_cameraPos.w == 0.0 ? vec2(In.position.xy.x, -In.position.xy.y) : In.position.xy;\ngl_Position = In.position;\ngl_Position.y = gl_Position.y;\nv_uv = a_texCoord;\n}", "frag": "\nprecision highp float;\nvarying vec2 v_uv;\nuniform mediump vec4 texSize;\nuniform sampler2D bloomTexture;\nvec3 downsample4taps(vec2 uv, vec2 halfpixel) {\nvec3 sum = texture2D(bloomTexture, uv + vec2(-halfpixel.x, halfpixel.y)).xyz;\nsum += texture2D(bloomTexture, uv + vec2(halfpixel.x, halfpixel.y)).xyz;\nsum += texture2D(bloomTexture, uv + vec2(halfpixel.x, -halfpixel.y)).xyz;\nsum += texture2D(bloomTexture, uv + vec2(-halfpixel.x, -halfpixel.y)).xyz;\nreturn sum / 4.0;\n}\nvoid main()\n{\nvec3 result = downsample4taps(v_uv, 1.0 / texSize.xy).rgb;\ngl_FragColor = vec4(result, 1.0);\n}", }, { - "vert": "\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\nrgba = rgba * 255.0;\nhighp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\nhighp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\nhighp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\nreturn Sign * exp2(Exponent - 23.0) * Mantissa;\n}\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nattribute vec3 a_position;\nattribute vec3 a_normal;\nattribute vec2 a_texCoord;\nattribute vec4 a_tangent;\n#if CC_USE_SKINNING\nattribute vec4 a_joints;\nattribute vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nattribute highp vec4 a_jointAnimInfo;\n#endif\nattribute vec4 a_matWorld0;\nattribute vec4 a_matWorld1;\nattribute vec4 a_matWorld2;\n#if USE_LIGHTMAP\nattribute vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nattribute vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nattribute float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nattribute float a_vertexId;\nint getVertexId() {\nreturn int(a_vertexId);\n}\n#endif\n#if CC_USE_MORPH\nuniform vec4 cc_displacementWeights[15];\nuniform vec4 cc_displacementTextureInfo;\nvec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\nfloat pixelIndexF = float(pixelIndex);\nfloat x = mod(pixelIndexF, textureResolution.x);\nfloat y = floor(pixelIndexF / textureResolution.x);\nreturn vec2(x, y);\n}\nvec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\nreturn (vec2(location.x, location.y) + .5) / textureResolution;\n}\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 uv = getPixelCoordFromLocation(location, cc_displacementTextureInfo.xy);\nreturn texture2D(tex, uv);\n}\n#else\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex * 4;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\nreturn vec4(\ndecode32(texture2D(tex, x)),\ndecode32(texture2D(tex, y)),\ndecode32(texture2D(tex, z)),\n1.0\n);\n}\n#endif\nfloat getDisplacementWeight(int index) {\nint quot = index / 4;\nint remainder = index - quot * 4;\nif (remainder == 0) {\nreturn cc_displacementWeights[quot].x;\n} else if (remainder == 1) {\nreturn cc_displacementWeights[quot].y;\n} else if (remainder == 2) {\nreturn cc_displacementWeights[quot].z;\n} else {\nreturn cc_displacementWeights[quot].w;\n}\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\nreturn fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n#else\nvec3 result = vec3(0, 0, 0);\nint nVertices = int(cc_displacementTextureInfo.z);\nfor (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\nresult += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n}\nreturn result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\nuniform sampler2D cc_PositionDisplacements;\nvec3 getPositionDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nuniform sampler2D cc_NormalDisplacements;\nvec3 getNormalDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\nuniform sampler2D cc_TangentDisplacements;\nvec3 getTangentDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n}\n#endif\nvoid applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nint vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nnormal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\ntangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\n#if CC_USE_BAKED_ANIMATION\nuniform highp vec4 cc_jointTextureInfo;\nuniform highp vec4 cc_jointAnimInfo;\nuniform highp sampler2D cc_jointTexture;\nvoid CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n{\n#if USE_INSTANCING\nhighp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n#else\nhighp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n#endif\ninvSize = cc_jointTextureInfo.w;\nhighp float tempY = floor(temp * invSize);\nx = floor(temp - tempY * cc_jointTextureInfo.x);\ny = (tempY + 0.5) * invSize;\n}\n#else\nuniform highp vec4 cc_joints[90];\n#endif\n#if CC_USE_BAKED_ANIMATION\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(3.0, i, x, y, invSize);\nvec4 v1 = texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y));\nvec4 v2 = texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y));\nvec4 v3 = texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y));\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#else\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(12.0, i, x, y, invSize);\nvec4 v1 = vec4(\ndecode32(texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n);\nvec4 v2 = vec4(\ndecode32(texture2D(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n);\nvec4 v3 = vec4(\ndecode32(texture2D(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n);\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\n#else\nmat4 getJointMatrix (float i) {\nint idx = int(i);\nvec4 v1 = cc_joints[idx * 3];\nvec4 v2 = cc_joints[idx * 3 + 1];\nvec4 v3 = cc_joints[idx * 3 + 2];\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\nmat4 skinMatrix () {\nvec4 joints = vec4(a_joints);\nreturn getJointMatrix(joints.x) * a_weights.x\n+ getJointMatrix(joints.y) * a_weights.y\n+ getJointMatrix(joints.z) * a_weights.z\n+ getJointMatrix(joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\nmat4 m = skinMatrix();\nposition = m * position;\n}\nvoid CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nmat4 m = skinMatrix();\nposition = m * position;\nnormal = (m * vec4(normal, 0.0)).xyz;\ntangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n}\n#endif\nvoid CCVertInput(inout StandardVertInput In)\n{\nIn.position = vec4(a_position, 1.0);\nIn.normal = a_normal;\nIn.tangent = a_tangent;\n#if CC_USE_MORPH\napplyMorph(In.position, In.normal, In.tangent);\n#endif\n#if CC_USE_SKINNING\nCCSkin(In.position, In.normal, In.tangent);\n#endif\n}\nuniform highp vec4 cc_cameraPos;\nvarying vec2 v_uv;\nvoid main () {\nStandardVertInput In;\nCCVertInput(In);\nIn.position.xy = cc_cameraPos.w == 0.0 ? vec2(In.position.xy.x, -In.position.xy.y) : In.position.xy;\ngl_Position = In.position;\ngl_Position.y = gl_Position.y;\nv_uv = a_texCoord;\n}", + "vert": "\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\nrgba = rgba * 255.0;\nhighp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\nhighp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\nhighp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\nreturn Sign * exp2(Exponent - 23.0) * Mantissa;\n}\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nattribute vec3 a_position;\nattribute vec3 a_normal;\nattribute vec2 a_texCoord;\nattribute vec4 a_tangent;\n#if CC_USE_SKINNING\nattribute vec4 a_joints;\nattribute vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nattribute highp vec4 a_jointAnimInfo;\n#endif\nattribute vec4 a_matWorld0;\nattribute vec4 a_matWorld1;\nattribute vec4 a_matWorld2;\n#if CC_USE_LIGHTMAP\nattribute vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nattribute vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nattribute float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nattribute float a_vertexId;\nint getVertexId() {\nreturn int(a_vertexId);\n}\n#endif\n#if CC_USE_MORPH\nuniform vec4 cc_displacementWeights[15];\nuniform vec4 cc_displacementTextureInfo;\nvec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\nfloat pixelIndexF = float(pixelIndex);\nfloat x = mod(pixelIndexF, textureResolution.x);\nfloat y = floor(pixelIndexF / textureResolution.x);\nreturn vec2(x, y);\n}\nvec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\nreturn (vec2(location.x, location.y) + .5) / textureResolution;\n}\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 uv = getPixelCoordFromLocation(location, cc_displacementTextureInfo.xy);\nreturn texture2D(tex, uv);\n}\n#else\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex * 4;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\nreturn vec4(\ndecode32(texture2D(tex, x)),\ndecode32(texture2D(tex, y)),\ndecode32(texture2D(tex, z)),\n1.0\n);\n}\n#endif\nfloat getDisplacementWeight(int index) {\nint quot = index / 4;\nint remainder = index - quot * 4;\nif (remainder == 0) {\nreturn cc_displacementWeights[quot].x;\n} else if (remainder == 1) {\nreturn cc_displacementWeights[quot].y;\n} else if (remainder == 2) {\nreturn cc_displacementWeights[quot].z;\n} else {\nreturn cc_displacementWeights[quot].w;\n}\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\nreturn fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n#else\nvec3 result = vec3(0, 0, 0);\nint nVertices = int(cc_displacementTextureInfo.z);\nfor (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\nresult += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n}\nreturn result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\nuniform sampler2D cc_PositionDisplacements;\nvec3 getPositionDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nuniform sampler2D cc_NormalDisplacements;\nvec3 getNormalDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\nuniform sampler2D cc_TangentDisplacements;\nvec3 getTangentDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n}\n#endif\nvoid applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nint vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nnormal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\ntangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\n#if CC_USE_BAKED_ANIMATION\nuniform highp vec4 cc_jointTextureInfo;\nuniform highp vec4 cc_jointAnimInfo;\nuniform highp sampler2D cc_jointTexture;\nvoid CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n{\n#if USE_INSTANCING\nhighp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n#else\nhighp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n#endif\ninvSize = cc_jointTextureInfo.w;\nhighp float tempY = floor(temp * invSize);\nx = floor(temp - tempY * cc_jointTextureInfo.x);\ny = (tempY + 0.5) * invSize;\n}\n#else\nuniform highp vec4 cc_joints[90];\n#endif\n#if CC_USE_BAKED_ANIMATION\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(3.0, i, x, y, invSize);\nvec4 v1 = texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y));\nvec4 v2 = texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y));\nvec4 v3 = texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y));\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#else\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(12.0, i, x, y, invSize);\nvec4 v1 = vec4(\ndecode32(texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n);\nvec4 v2 = vec4(\ndecode32(texture2D(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n);\nvec4 v3 = vec4(\ndecode32(texture2D(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n);\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\n#else\nmat4 getJointMatrix (float i) {\nint idx = int(i);\nvec4 v1 = cc_joints[idx * 3];\nvec4 v2 = cc_joints[idx * 3 + 1];\nvec4 v3 = cc_joints[idx * 3 + 2];\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\nmat4 skinMatrix () {\nvec4 joints = vec4(a_joints);\nreturn getJointMatrix(joints.x) * a_weights.x\n+ getJointMatrix(joints.y) * a_weights.y\n+ getJointMatrix(joints.z) * a_weights.z\n+ getJointMatrix(joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\nmat4 m = skinMatrix();\nposition = m * position;\n}\nvoid CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nmat4 m = skinMatrix();\nposition = m * position;\nnormal = (m * vec4(normal, 0.0)).xyz;\ntangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n}\n#endif\nvoid CCVertInput(inout StandardVertInput In)\n{\nIn.position = vec4(a_position, 1.0);\nIn.normal = a_normal;\nIn.tangent = a_tangent;\n#if CC_USE_MORPH\napplyMorph(In.position, In.normal, In.tangent);\n#endif\n#if CC_USE_SKINNING\nCCSkin(In.position, In.normal, In.tangent);\n#endif\n}\nuniform highp vec4 cc_cameraPos;\nvarying vec2 v_uv;\nvoid main () {\nStandardVertInput In;\nCCVertInput(In);\nIn.position.xy = cc_cameraPos.w == 0.0 ? vec2(In.position.xy.x, -In.position.xy.y) : In.position.xy;\ngl_Position = In.position;\ngl_Position.y = gl_Position.y;\nv_uv = a_texCoord;\n}", "frag": "\nprecision highp float;\nvarying vec2 v_uv;\nuniform mediump vec4 texSize;\nuniform sampler2D bloomTexture;\nvec3 upsample4taps(vec2 uv, vec2 halfpixel) {\nvec3 sum = texture2D(bloomTexture, uv + vec2(-halfpixel.x, halfpixel.y)).xyz;\nsum += texture2D(bloomTexture, uv + vec2(halfpixel.x, halfpixel.y)).xyz;\nsum += texture2D(bloomTexture, uv + vec2(halfpixel.x, -halfpixel.y)).xyz;\nsum += texture2D(bloomTexture, uv + vec2(-halfpixel.x, -halfpixel.y)).xyz;\nreturn sum / 4.0;\n}\nvoid main() {\nvec3 result = upsample4taps(v_uv, 0.5 / texSize.xy).rgb;\ngl_FragColor = vec4(result, 1.0);\n}", }, { - "vert": "\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\nrgba = rgba * 255.0;\nhighp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\nhighp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\nhighp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\nreturn Sign * exp2(Exponent - 23.0) * Mantissa;\n}\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nattribute vec3 a_position;\nattribute vec3 a_normal;\nattribute vec2 a_texCoord;\nattribute vec4 a_tangent;\n#if CC_USE_SKINNING\nattribute vec4 a_joints;\nattribute vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nattribute highp vec4 a_jointAnimInfo;\n#endif\nattribute vec4 a_matWorld0;\nattribute vec4 a_matWorld1;\nattribute vec4 a_matWorld2;\n#if USE_LIGHTMAP\nattribute vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nattribute vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nattribute float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nattribute float a_vertexId;\nint getVertexId() {\nreturn int(a_vertexId);\n}\n#endif\n#if CC_USE_MORPH\nuniform vec4 cc_displacementWeights[15];\nuniform vec4 cc_displacementTextureInfo;\nvec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\nfloat pixelIndexF = float(pixelIndex);\nfloat x = mod(pixelIndexF, textureResolution.x);\nfloat y = floor(pixelIndexF / textureResolution.x);\nreturn vec2(x, y);\n}\nvec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\nreturn (vec2(location.x, location.y) + .5) / textureResolution;\n}\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 uv = getPixelCoordFromLocation(location, cc_displacementTextureInfo.xy);\nreturn texture2D(tex, uv);\n}\n#else\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex * 4;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\nreturn vec4(\ndecode32(texture2D(tex, x)),\ndecode32(texture2D(tex, y)),\ndecode32(texture2D(tex, z)),\n1.0\n);\n}\n#endif\nfloat getDisplacementWeight(int index) {\nint quot = index / 4;\nint remainder = index - quot * 4;\nif (remainder == 0) {\nreturn cc_displacementWeights[quot].x;\n} else if (remainder == 1) {\nreturn cc_displacementWeights[quot].y;\n} else if (remainder == 2) {\nreturn cc_displacementWeights[quot].z;\n} else {\nreturn cc_displacementWeights[quot].w;\n}\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\nreturn fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n#else\nvec3 result = vec3(0, 0, 0);\nint nVertices = int(cc_displacementTextureInfo.z);\nfor (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\nresult += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n}\nreturn result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\nuniform sampler2D cc_PositionDisplacements;\nvec3 getPositionDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nuniform sampler2D cc_NormalDisplacements;\nvec3 getNormalDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\nuniform sampler2D cc_TangentDisplacements;\nvec3 getTangentDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n}\n#endif\nvoid applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nint vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nnormal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\ntangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\n#if CC_USE_BAKED_ANIMATION\nuniform highp vec4 cc_jointTextureInfo;\nuniform highp vec4 cc_jointAnimInfo;\nuniform highp sampler2D cc_jointTexture;\nvoid CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n{\n#if USE_INSTANCING\nhighp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n#else\nhighp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n#endif\ninvSize = cc_jointTextureInfo.w;\nhighp float tempY = floor(temp * invSize);\nx = floor(temp - tempY * cc_jointTextureInfo.x);\ny = (tempY + 0.5) * invSize;\n}\n#else\nuniform highp vec4 cc_joints[90];\n#endif\n#if CC_USE_BAKED_ANIMATION\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(3.0, i, x, y, invSize);\nvec4 v1 = texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y));\nvec4 v2 = texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y));\nvec4 v3 = texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y));\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#else\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(12.0, i, x, y, invSize);\nvec4 v1 = vec4(\ndecode32(texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n);\nvec4 v2 = vec4(\ndecode32(texture2D(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n);\nvec4 v3 = vec4(\ndecode32(texture2D(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n);\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\n#else\nmat4 getJointMatrix (float i) {\nint idx = int(i);\nvec4 v1 = cc_joints[idx * 3];\nvec4 v2 = cc_joints[idx * 3 + 1];\nvec4 v3 = cc_joints[idx * 3 + 2];\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\nmat4 skinMatrix () {\nvec4 joints = vec4(a_joints);\nreturn getJointMatrix(joints.x) * a_weights.x\n+ getJointMatrix(joints.y) * a_weights.y\n+ getJointMatrix(joints.z) * a_weights.z\n+ getJointMatrix(joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\nmat4 m = skinMatrix();\nposition = m * position;\n}\nvoid CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nmat4 m = skinMatrix();\nposition = m * position;\nnormal = (m * vec4(normal, 0.0)).xyz;\ntangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n}\n#endif\nvoid CCVertInput(inout StandardVertInput In)\n{\nIn.position = vec4(a_position, 1.0);\nIn.normal = a_normal;\nIn.tangent = a_tangent;\n#if CC_USE_MORPH\napplyMorph(In.position, In.normal, In.tangent);\n#endif\n#if CC_USE_SKINNING\nCCSkin(In.position, In.normal, In.tangent);\n#endif\n}\nuniform highp vec4 cc_cameraPos;\nvarying vec2 v_uv;\nvoid main () {\nStandardVertInput In;\nCCVertInput(In);\nIn.position.xy = cc_cameraPos.w == 0.0 ? vec2(In.position.xy.x, -In.position.xy.y) : In.position.xy;\ngl_Position = In.position;\ngl_Position.y = gl_Position.y;\nv_uv = a_texCoord;\n}", + "vert": "\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\nrgba = rgba * 255.0;\nhighp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\nhighp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\nhighp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\nreturn Sign * exp2(Exponent - 23.0) * Mantissa;\n}\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nattribute vec3 a_position;\nattribute vec3 a_normal;\nattribute vec2 a_texCoord;\nattribute vec4 a_tangent;\n#if CC_USE_SKINNING\nattribute vec4 a_joints;\nattribute vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nattribute highp vec4 a_jointAnimInfo;\n#endif\nattribute vec4 a_matWorld0;\nattribute vec4 a_matWorld1;\nattribute vec4 a_matWorld2;\n#if CC_USE_LIGHTMAP\nattribute vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nattribute vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nattribute float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nattribute float a_vertexId;\nint getVertexId() {\nreturn int(a_vertexId);\n}\n#endif\n#if CC_USE_MORPH\nuniform vec4 cc_displacementWeights[15];\nuniform vec4 cc_displacementTextureInfo;\nvec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\nfloat pixelIndexF = float(pixelIndex);\nfloat x = mod(pixelIndexF, textureResolution.x);\nfloat y = floor(pixelIndexF / textureResolution.x);\nreturn vec2(x, y);\n}\nvec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\nreturn (vec2(location.x, location.y) + .5) / textureResolution;\n}\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 uv = getPixelCoordFromLocation(location, cc_displacementTextureInfo.xy);\nreturn texture2D(tex, uv);\n}\n#else\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex * 4;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\nreturn vec4(\ndecode32(texture2D(tex, x)),\ndecode32(texture2D(tex, y)),\ndecode32(texture2D(tex, z)),\n1.0\n);\n}\n#endif\nfloat getDisplacementWeight(int index) {\nint quot = index / 4;\nint remainder = index - quot * 4;\nif (remainder == 0) {\nreturn cc_displacementWeights[quot].x;\n} else if (remainder == 1) {\nreturn cc_displacementWeights[quot].y;\n} else if (remainder == 2) {\nreturn cc_displacementWeights[quot].z;\n} else {\nreturn cc_displacementWeights[quot].w;\n}\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\nreturn fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n#else\nvec3 result = vec3(0, 0, 0);\nint nVertices = int(cc_displacementTextureInfo.z);\nfor (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\nresult += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n}\nreturn result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\nuniform sampler2D cc_PositionDisplacements;\nvec3 getPositionDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nuniform sampler2D cc_NormalDisplacements;\nvec3 getNormalDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\nuniform sampler2D cc_TangentDisplacements;\nvec3 getTangentDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n}\n#endif\nvoid applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nint vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nnormal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\ntangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\n#if CC_USE_BAKED_ANIMATION\nuniform highp vec4 cc_jointTextureInfo;\nuniform highp vec4 cc_jointAnimInfo;\nuniform highp sampler2D cc_jointTexture;\nvoid CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n{\n#if USE_INSTANCING\nhighp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n#else\nhighp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n#endif\ninvSize = cc_jointTextureInfo.w;\nhighp float tempY = floor(temp * invSize);\nx = floor(temp - tempY * cc_jointTextureInfo.x);\ny = (tempY + 0.5) * invSize;\n}\n#else\nuniform highp vec4 cc_joints[90];\n#endif\n#if CC_USE_BAKED_ANIMATION\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(3.0, i, x, y, invSize);\nvec4 v1 = texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y));\nvec4 v2 = texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y));\nvec4 v3 = texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y));\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#else\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(12.0, i, x, y, invSize);\nvec4 v1 = vec4(\ndecode32(texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n);\nvec4 v2 = vec4(\ndecode32(texture2D(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n);\nvec4 v3 = vec4(\ndecode32(texture2D(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n);\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\n#else\nmat4 getJointMatrix (float i) {\nint idx = int(i);\nvec4 v1 = cc_joints[idx * 3];\nvec4 v2 = cc_joints[idx * 3 + 1];\nvec4 v3 = cc_joints[idx * 3 + 2];\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\nmat4 skinMatrix () {\nvec4 joints = vec4(a_joints);\nreturn getJointMatrix(joints.x) * a_weights.x\n+ getJointMatrix(joints.y) * a_weights.y\n+ getJointMatrix(joints.z) * a_weights.z\n+ getJointMatrix(joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\nmat4 m = skinMatrix();\nposition = m * position;\n}\nvoid CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nmat4 m = skinMatrix();\nposition = m * position;\nnormal = (m * vec4(normal, 0.0)).xyz;\ntangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n}\n#endif\nvoid CCVertInput(inout StandardVertInput In)\n{\nIn.position = vec4(a_position, 1.0);\nIn.normal = a_normal;\nIn.tangent = a_tangent;\n#if CC_USE_MORPH\napplyMorph(In.position, In.normal, In.tangent);\n#endif\n#if CC_USE_SKINNING\nCCSkin(In.position, In.normal, In.tangent);\n#endif\n}\nuniform highp vec4 cc_cameraPos;\nvarying vec2 v_uv;\nvoid main () {\nStandardVertInput In;\nCCVertInput(In);\nIn.position.xy = cc_cameraPos.w == 0.0 ? vec2(In.position.xy.x, -In.position.xy.y) : In.position.xy;\ngl_Position = In.position;\ngl_Position.y = gl_Position.y;\nv_uv = a_texCoord;\n}", "frag": "\nprecision highp float;\nvarying vec2 v_uv;\nuniform mediump vec4 texSize;\nuniform sampler2D outputResultMap;\nuniform sampler2D bloomTexture;\nvoid main() {\nvec4 hdrColor = texture2D(outputResultMap, v_uv);\nvec3 bloomColor = texture2D(bloomTexture, v_uv).rgb;\nvec3 result = hdrColor.rgb + bloomColor * texSize.w * hdrColor.a;\ngl_FragColor = vec4(result, hdrColor.a);\n}", } ], [ { - "vert": "\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nattribute vec3 a_position;\nattribute vec3 a_normal;\nattribute vec2 a_texCoord;\nattribute vec4 a_tangent;\n#if CC_USE_SKINNING\nattribute vec4 a_joints;\nattribute vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nattribute highp vec4 a_jointAnimInfo;\n#endif\nattribute vec4 a_matWorld0;\nattribute vec4 a_matWorld1;\nattribute vec4 a_matWorld2;\n#if USE_LIGHTMAP\nattribute vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nattribute vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nattribute float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nattribute float a_vertexId;\n#endif\nuniform highp vec4 cc_cameraPos;\nvarying vec2 v_uv;\nvoid main () {\nvec4 position;\nposition = vec4(a_position, 1.0);\nposition.xy = cc_cameraPos.w == 0.0 ? vec2(position.xy.x, -position.xy.y) : position.xy;\ngl_Position = vec4(position.x, position.y, 1.0, 1.0);\nv_uv = a_texCoord;\n}", - "frag": "\n#ifdef GL_EXT_shader_framebuffer_fetch\n#extension GL_EXT_shader_framebuffer_fetch: enable\n#endif\n#ifdef GL_OES_standard_derivatives\n#extension GL_OES_standard_derivatives: enable\n#endif\n#ifdef GL_EXT_shader_texture_lod\n#extension GL_EXT_shader_texture_lod: enable\n#endif\nprecision highp float;\nuniform highp mat4 cc_matView;\nuniform highp mat4 cc_matViewProjInv;\nuniform highp vec4 cc_cameraPos;\nuniform mediump vec4 cc_mainLitDir;\nuniform mediump vec4 cc_mainLitColor;\nuniform mediump vec4 cc_ambientSky;\nuniform mediump vec4 cc_ambientGround;\nuniform mediump vec4 cc_fogColor;\nuniform mediump vec4 cc_fogBase;\nuniform mediump vec4 cc_fogAdd;\nuniform mediump vec4 cc_nearFar;\nuniform mediump vec4 cc_viewPort;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nvec3 SRGBToLinear (vec3 gamma) {\nreturn gamma * gamma;\n}\nuniform highp mat4 cc_matLightView;\nuniform highp mat4 cc_matLightViewProj;\nuniform highp vec4 cc_shadowInvProjDepthInfo;\nuniform highp vec4 cc_shadowProjDepthInfo;\nuniform highp vec4 cc_shadowProjInfo;\nuniform mediump vec4 cc_shadowNFLSInfo;\nuniform mediump vec4 cc_shadowWHPBInfo;\nuniform mediump vec4 cc_shadowLPNNInfo;\nhighp float unpackHighpData (float mainPart, float modPart) {\nhighp float data = mainPart;\nreturn data + modPart;\n}\nhighp float unpackHighpData (float mainPart, float modPart, const float modValue) {\nhighp float data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nhighp vec2 unpackHighpData (vec2 mainPart, vec2 modPart) {\nhighp vec2 data = mainPart;\nreturn data + modPart;\n}\nhighp vec2 unpackHighpData (vec2 mainPart, vec2 modPart, const float modValue) {\nhighp vec2 data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nhighp vec3 unpackHighpData (vec3 mainPart, vec3 modPart) {\nhighp vec3 data = mainPart;\nreturn data + modPart;\n}\nhighp vec3 unpackHighpData (vec3 mainPart, vec3 modPart, const float modValue) {\nhighp vec3 data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nhighp vec4 unpackHighpData (vec4 mainPart, vec4 modPart) {\nhighp vec4 data = mainPart;\nreturn data + modPart;\n}\nhighp vec4 unpackHighpData (vec4 mainPart, vec4 modPart, const float modValue) {\nhighp vec4 data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nfloat CCGetLinearDepthFromViewSpace(vec3 viewPos) {\nfloat dist = length(viewPos);\nreturn (dist - cc_shadowNFLSInfo.x) / (cc_shadowNFLSInfo.y - cc_shadowNFLSInfo.x);\n}\nfloat CCGetLinearDepth(vec3 worldPos) {\nvec4 viewStartPos = cc_matLightView * vec4(worldPos.xyz, 1.0);\nreturn CCGetLinearDepthFromViewSpace(viewStartPos.xyz);\n}\n#if CC_RECEIVE_SHADOW\nuniform highp sampler2D cc_shadowMap;\nuniform highp sampler2D cc_spotLightingMap;\nvec4 ApplyShadowDepthBias_FaceNormal(vec4 shadowPos, vec3 worldNormal, float normalBias)\n{\nvec4 newShadowPos = shadowPos;\nif(normalBias > EPSILON_LOWP)\n{\nvec4 viewNormal = cc_matLightView * vec4(worldNormal, 0.0);\nif(viewNormal.z < 0.1)\nnewShadowPos.xy += viewNormal.xy * cc_shadowProjInfo.xy * normalBias * clamp(viewNormal.z, 0.001, 0.1);\n}\nreturn newShadowPos;\n}\nvec4 ApplyShadowDepthBias_Perspective(vec4 shadowPos, float viewspaceDepthBias)\n{\nvec3 viewSpacePos;\nviewSpacePos.xy = shadowPos.xy * cc_shadowProjInfo.zw;\nviewSpacePos.z = shadowPos.z * cc_shadowInvProjDepthInfo.x + shadowPos.w * cc_shadowInvProjDepthInfo.y;\nviewSpacePos.xyz += cc_shadowProjDepthInfo.z * normalize(viewSpacePos.xyz) * viewspaceDepthBias;\nvec4 clipSpacePos;\nclipSpacePos.xy = viewSpacePos.xy * cc_shadowProjInfo.xy;\nclipSpacePos.zw = viewSpacePos.z * cc_shadowProjDepthInfo.xz + vec2(cc_shadowProjDepthInfo.y, 0.0);\nif (cc_shadowNFLSInfo.z > EPSILON) {\nclipSpacePos.z = CCGetLinearDepthFromViewSpace(viewSpacePos.xyz);\nclipSpacePos.z = (clipSpacePos.z * 2.0 - 1.0) * clipSpacePos.w;\n}\nreturn clipSpacePos;\n}\nvec4 ApplyShadowDepthBias_Orthographic(vec4 shadowPos, float viewspaceDepthBias)\n{\nfloat coeffA = cc_shadowProjDepthInfo.x;\nfloat coeffB = cc_shadowProjDepthInfo.y;\nfloat viewSpacePos_z = (shadowPos.z - coeffB) / coeffA;\nviewSpacePos_z += viewspaceDepthBias;\nvec4 result = shadowPos;\nresult.z = viewSpacePos_z * coeffA + coeffB;\nreturn result;\n}\nfloat CCGetShadowFactorHard (vec4 shadowPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Orthographic(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat shadow = 0.0;\nfloat closestDepth = 0.0;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nclosestDepth = dot(texture2D(cc_shadowMap, clipPos.xy), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0));\n} else {\nclosestDepth = texture2D(cc_shadowMap, clipPos.xy).x;\n}\nshadow = step(clipPos.z, closestDepth);\nreturn shadow;\n}\nfloat CCGetShadowFactorSoft (vec4 shadowPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Orthographic(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat offsetDepth = clipPos.z;\nvec2 mapSize = cc_shadowWHPBInfo.xy;\nvec2 oneTap = 1.0 / mapSize;\nvec2 clipPos_offset = clipPos.xy + oneTap;\nfloat block0, block1, block2, block3;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos_offset.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos_offset.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos.x, clipPos.y)).x);\nblock1 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos_offset.x, clipPos.y)).x);\nblock2 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos.x, clipPos_offset.y)).x);\nblock3 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos_offset.x, clipPos_offset.y)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * mapSize.x;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block2, block3, coefX);\nfloat coefY = mod(clipPos.y, oneTap.y) * mapSize.y;\nreturn mix(resultX, resultY, coefY);\n}\nfloat CCGetShadowFactorSoft2X (vec4 shadowPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Orthographic(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat offsetDepth = clipPos.z;\nvec2 mapSize = cc_shadowWHPBInfo.xy;\nvec2 oneTap = 1.0 / mapSize;\nfloat clipPos_offset_L = clipPos.x - oneTap.x;\nfloat clipPos_offset_R = clipPos.x + oneTap.x;\nfloat clipPos_offset_U = clipPos.y - oneTap.y;\nfloat clipPos_offset_D = clipPos.y + oneTap.y;\nfloat block0, block1, block2, block3, block4, block5, block6, block7, block8;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos.x, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos_offset_L, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock4 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock5 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos_offset_R, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock6 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock7 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos.x, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock8 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_U)).x);\nblock1 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos.x, clipPos_offset_U)).x);\nblock2 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_U)).x);\nblock3 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos_offset_L, clipPos.y)).x);\nblock4 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos.x, clipPos.y)).x);\nblock5 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos_offset_R, clipPos.y)).x);\nblock6 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_D)).x);\nblock7 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos.x, clipPos_offset_D)).x);\nblock8 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_D)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * mapSize.x;\nfloat coefY = mod(clipPos.y, oneTap.y) * mapSize.y;\nfloat shadow = 0.0;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block3, block4, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block1, block2, coefX);\nresultY = mix(block4, block5, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block3, block4, coefX);\nresultY = mix(block6, block7, coefX);\nshadow += mix(resultX, resultY, coefY);\nresultX = mix(block4, block5, coefX);\nresultY = mix(block7, block8, coefX);\nshadow += mix(resultX, resultY, coefY);\nreturn shadow * 0.25;\n}\nfloat CCGetSpotLightShadowFactorHard (vec4 shadowPos, vec3 worldPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Perspective(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat shadow = 0.0;\nfloat closestDepth = 0.0;\nfloat depth = clipPos.z;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nclosestDepth = dot(texture2D(cc_spotLightingMap, clipPos.xy), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0));\n} else {\nclosestDepth = texture2D(cc_spotLightingMap, clipPos.xy).x;\n}\nshadow = step(depth, closestDepth);\nreturn shadow;\n}\nfloat CCGetSpotLightShadowFactorSoft (vec4 shadowPos, vec3 worldPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Perspective(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat depth = 0.0;\nif (cc_shadowNFLSInfo.z > EPSILON) {\ndepth = CCGetLinearDepth(worldPos);\n} else {\ndepth = clipPos.z;\n}\nvec2 oneTap = 1.0 / cc_shadowWHPBInfo.xy;\nvec2 clipPos_offset = clipPos.xy + oneTap;\nfloat block0, block1, block2, block3;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)).x);\nblock1 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos.y)).x);\nblock2 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset.y)).x);\nblock3 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos_offset.y)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * cc_shadowWHPBInfo.x;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block2, block3, coefX);\nfloat coefY = mod(clipPos.y, oneTap.y) * cc_shadowWHPBInfo.y;\nreturn mix(resultX, resultY, coefY);\n}\nfloat CCGetSpotLightShadowFactorSoft2X (vec4 shadowPos, vec3 worldPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Perspective(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat depth = 0.0;\nif (cc_shadowNFLSInfo.z > EPSILON) {\ndepth = CCGetLinearDepth(worldPos);\n} else {\ndepth = clipPos.z;\n}\nvec2 mapSize = cc_shadowWHPBInfo.xy;\nvec2 oneTap = 1.0 / mapSize;\nfloat clipPos_offset_L = clipPos.x - oneTap.x;\nfloat clipPos_offset_R = clipPos.x + oneTap.x;\nfloat clipPos_offset_U = clipPos.y - oneTap.y;\nfloat clipPos_offset_D = clipPos.y + oneTap.y;\nfloat block0, block1, block2, block3, block4, block5, block6, block7, block8;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock4 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock5 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock6 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock7 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock8 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_U)).x);\nblock1 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_U)).x);\nblock2 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_U)).x);\nblock3 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos.y)).x);\nblock4 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)).x);\nblock5 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos.y)).x);\nblock6 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_D)).x);\nblock7 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_D)).x);\nblock8 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_D)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * mapSize.x;\nfloat coefY = mod(clipPos.y, oneTap.y) * mapSize.y;\nfloat shadow = 0.0;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block3, block4, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block1, block2, coefX);\nresultY = mix(block4, block5, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block3, block4, coefX);\nresultY = mix(block6, block7, coefX);\nshadow += mix(resultX, resultY, coefY);\nresultX = mix(block4, block5, coefX);\nresultY = mix(block7, block8, coefX);\nshadow += mix(resultX, resultY, coefY);\nreturn shadow * 0.25;\n}\nfloat CCSpotShadowFactorBase(vec4 shadowPos, vec3 worldPos, vec2 shadowBias)\n{\nfloat pcf = cc_shadowWHPBInfo.z;\nif (pcf > 1.9) {\nreturn CCGetSpotLightShadowFactorSoft2X(shadowPos, worldPos, shadowBias.x);\n}else if (pcf > 0.9) {\nreturn CCGetSpotLightShadowFactorSoft(shadowPos, worldPos, shadowBias.x);\n}else {\nreturn CCGetSpotLightShadowFactorHard(shadowPos, worldPos, shadowBias.x);\n}\n}\nfloat CCShadowFactorBase(vec4 shadowPos, vec3 N, vec2 shadowBias)\n{\nfloat realtimeShadow = 1.0;\nvec4 pos = ApplyShadowDepthBias_FaceNormal(shadowPos, N, shadowBias.y);\nfloat pcf = cc_shadowWHPBInfo.z;\nif (pcf > 1.9) {\nrealtimeShadow = CCGetShadowFactorSoft2X(pos, shadowBias.x);\n}else if (pcf > 0.9) {\nrealtimeShadow = CCGetShadowFactorSoft(pos, shadowBias.x);\n}else {\nrealtimeShadow = CCGetShadowFactorHard(pos, shadowBias.x);\n}\nreturn mix(realtimeShadow, 1.0, cc_shadowNFLSInfo.w);\n}\n#endif\n#if CC_USE_IBL\nuniform samplerCube cc_environment;\nvec4 fragTextureLod (sampler2D tex, vec2 coord, float lod) {\n#ifdef GL_EXT_shader_texture_lod\nreturn texture2DLodEXT(tex, coord, lod);\n#else\nreturn texture2D(tex, coord, lod);\n#endif\n}\nvec4 fragTextureLod (samplerCube tex, vec3 coord, float lod) {\n#ifdef GL_EXT_shader_texture_lod\nreturn textureCubeLodEXT(tex, coord, lod);\n#else\nreturn textureCube(tex, coord, lod);\n#endif\n}\nvec3 unpackRGBE (vec4 rgbe) {\nreturn rgbe.rgb * pow(1.1, rgbe.a * 255.0 - 128.0);\n}\n#if CC_USE_DIFFUSEMAP\nuniform samplerCube cc_diffuseMap;\n#endif\n#endif\nfloat GGXMobile (float roughness, float NoH, vec3 H, vec3 N) {\nvec3 NxH = cross(N, H);\nfloat OneMinusNoHSqr = dot(NxH, NxH);\nfloat a = roughness * roughness;\nfloat n = NoH * a;\nfloat p = a / (OneMinusNoHSqr + n * n);\nreturn p * p;\n}\nfloat CalcSpecular (float roughness, float NoH, vec3 H, vec3 N) {\nreturn (roughness * 0.25 + 0.25) * GGXMobile(roughness, NoH, H, N);\n}\nvec3 BRDFApprox (vec3 specular, float roughness, float NoV) {\nconst vec4 c0 = vec4(-1.0, -0.0275, -0.572, 0.022);\nconst vec4 c1 = vec4(1.0, 0.0425, 1.04, -0.04);\nvec4 r = roughness * c0 + c1;\nfloat a004 = min(r.x * r.x, exp2(-9.28 * NoV)) * r.x + r.y;\nvec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;\nAB.y *= clamp(50.0 * specular.g, 0.0, 1.0);\nreturn specular * AB.x + AB.y;\n}\n#if USE_REFLECTION_DENOISE\nvec3 GetEnvReflectionWithMipFiltering(vec3 R, float roughness, float mipCount, float denoiseIntensity) {\n#if CC_USE_IBL\nfloat mip = roughness * mipCount;\nfloat delta = (dot(dFdx(R), dFdy(R))) * 1000.0;\nfloat mipBias = mix(0.0, 5.0, clamp(delta, 0.0, 1.0));\nvec4 biased = fragTextureLod(cc_environment, R, mip + mipBias);\nvec4 filtered = textureCube(cc_environment, R);\n#if CC_USE_IBL == 2\nbiased.rgb = unpackRGBE(biased);\nfiltered.rgb = unpackRGBE(filtered);\n#else\nbiased.rgb = SRGBToLinear(biased.rgb);\nfiltered.rgb = SRGBToLinear(filtered.rgb);\n#endif\nreturn mix(biased.rgb, filtered.rgb, denoiseIntensity);\n#else\nreturn vec3(0.0, 0.0, 0.0);\n#endif\n}\n#endif\nstruct StandardSurface {\nvec4 albedo;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nvec3 position, position_fract_part;\n#else\nvec3 position;\n#endif\nvec3 normal;\nvec3 emissive;\nvec3 lightmap;\nfloat lightmap_test;\nfloat roughness;\nfloat metallic;\nfloat occlusion;\nfloat specularIntensity;\n#if CC_RECEIVE_SHADOW\nvec2 shadowBias;\n#endif\n};\nvec4 CCStandardShadingBase (StandardSurface s, vec4 shadowPos) {\nvec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\nvec3 specular = mix(vec3(0.08 * s.specularIntensity), s.albedo.rgb, s.metallic);\nvec3 position;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nposition = unpackHighpData(s.position, s.position_fract_part);\n#else\nposition = s.position;\n#endif\nvec3 N = normalize(s.normal);\nvec3 V = normalize(cc_cameraPos.xyz - position);\nfloat NV = max(abs(dot(N, V)), 0.0);\nspecular = BRDFApprox(specular, s.roughness, NV);\nvec3 L = normalize(-cc_mainLitDir.xyz);\nvec3 H = normalize(L + V);\nfloat NH = max(dot(N, H), 0.0);\nfloat NL = max(dot(N, L), 0.0);\nvec3 finalColor = NL * cc_mainLitColor.rgb * cc_mainLitColor.w;\nvec3 diffuseContrib = diffuse / PI;\nvec3 specularContrib = specular * CalcSpecular(s.roughness, NH, H, N);\nvec3 dirlightContrib = (diffuseContrib + specularContrib);\nfloat shadow = 1.0;\n#if CC_RECEIVE_SHADOW\nif (NL > 0.0 && cc_mainLitDir.w > 0.0) {\nshadow = CCShadowFactorBase(shadowPos, N, s.shadowBias);\n}\n#endif\ndirlightContrib *= shadow;\nfinalColor *= dirlightContrib;\n#if USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\nif (s.lightmap_test > EPSILON_LOWP) {\nfinalColor = diffuse * s.lightmap.rgb * shadow;\n}\n#endif\nfloat fAmb = 0.5 - N.y * 0.5;\nvec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb);\n#if CC_USE_IBL\n#if CC_USE_DIFFUSEMAP\nvec4 diffuseMap = textureCube(cc_diffuseMap, N);\n#if CC_USE_DIFFUSEMAP == 2\nambDiff = unpackRGBE(diffuseMap);\n#else\nambDiff = SRGBToLinear(diffuseMap.rgb);\n#endif\n#endif\nvec3 R = normalize(reflect(-V, N));\n#if USE_REFLECTION_DENOISE\nvec3 env = GetEnvReflectionWithMipFiltering(R, s.roughness, cc_ambientGround.w, 0.6);\n#else\nvec4 envmap = fragTextureLod(cc_environment, R, s.roughness * cc_ambientGround.w);\n#if CC_USE_IBL == 2\nvec3 env = unpackRGBE(envmap);\n#else\nvec3 env = SRGBToLinear(envmap.rgb);\n#endif\n#endif\nfinalColor += env * cc_ambientSky.w * specular * s.occlusion;\n#endif\nfinalColor += ambDiff.rgb * cc_ambientSky.w * diffuse * s.occlusion;\nfinalColor += s.emissive;\nreturn vec4(finalColor, s.albedo.a);\n}\n#if CC_PIPELINE_TYPE == 0\n#define LIGHTS_PER_PASS 1\n#else\n#define LIGHTS_PER_PASS 10\n#endif\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 0\nuniform highp vec4 cc_lightPos[LIGHTS_PER_PASS];\nuniform vec4 cc_lightColor[LIGHTS_PER_PASS];\nuniform vec4 cc_lightSizeRangeAngle[LIGHTS_PER_PASS];\nuniform vec4 cc_lightDir[LIGHTS_PER_PASS];\n#endif\nfloat SmoothDistAtt (float distSqr, float invSqrAttRadius) {\nfloat factor = distSqr * invSqrAttRadius;\nfloat smoothFactor = clamp(1.0 - factor * factor, 0.0, 1.0);\nreturn smoothFactor * smoothFactor;\n}\nfloat GetDistAtt (float distSqr, float invSqrAttRadius) {\nfloat attenuation = 1.0 / max(distSqr, 0.01*0.01);\nattenuation *= SmoothDistAtt(distSqr , invSqrAttRadius);\nreturn attenuation;\n}\nfloat GetAngleAtt (vec3 L, vec3 litDir, float litAngleScale, float litAngleOffset) {\nfloat cd = dot(litDir, L);\nfloat attenuation = clamp(cd * litAngleScale + litAngleOffset, 0.0, 1.0);\nreturn (attenuation * attenuation);\n}\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 0\nvec4 CCStandardShadingAdditive (StandardSurface s, vec4 shadowPos) {\nvec3 position;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nposition = unpackHighpData(s.position, s.position_fract_part);\n#else\nposition = s.position;\n#endif\nvec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\nvec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\nvec3 diffuseContrib = diffuse / PI;\nvec3 N = normalize(s.normal);\nvec3 V = normalize(cc_cameraPos.xyz - position);\nfloat NV = max(abs(dot(N, V)), 0.0);\nspecular = BRDFApprox(specular, s.roughness, NV);\nvec3 finalColor = vec3(0.0);\nint numLights = CC_PIPELINE_TYPE == 0 ? LIGHTS_PER_PASS : int(cc_lightDir[0].w);\nfor (int i = 0; i < LIGHTS_PER_PASS; i++) {\nif (i >= numLights) break;\nvec3 SLU = cc_lightPos[i].xyz - position;\nvec3 SL = normalize(SLU);\nvec3 SH = normalize(SL + V);\nfloat SNL = max(dot(N, SL), 0.0);\nfloat SNH = max(dot(N, SH), 0.0);\nfloat distSqr = dot(SLU, SLU);\nfloat litRadius = cc_lightSizeRangeAngle[i].x;\nfloat litRadiusSqr = litRadius * litRadius;\nfloat illum = litRadiusSqr / max(litRadiusSqr, distSqr);\nfloat attRadiusSqrInv = 1.0 / max(cc_lightSizeRangeAngle[i].y, 0.01);\nattRadiusSqrInv *= attRadiusSqrInv;\nfloat att = GetDistAtt(distSqr, attRadiusSqrInv);\nvec3 lspec = specular * CalcSpecular(s.roughness, SNH, SH, N);\nif (cc_lightPos[i].w > 0.0) {\nfloat cosInner = max(dot(-cc_lightDir[i].xyz, SL), 0.01);\nfloat cosOuter = cc_lightSizeRangeAngle[i].z;\nfloat litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\nfloat litAngleOffset = -cosOuter * litAngleScale;\natt *= GetAngleAtt(SL, -cc_lightDir[i].xyz, litAngleScale, litAngleOffset);\n}\nvec3 lightColor = cc_lightColor[i].rgb;\nfloat shadow = 1.0;\n#if CC_RECEIVE_SHADOW\nif (cc_lightPos[i].w > 0.0 && cc_lightSizeRangeAngle[i].w > 0.0) {\nshadow = CCSpotShadowFactorBase(shadowPos, position, s.shadowBias);\n}\n#endif\nlightColor *= shadow;\nfinalColor += SNL * lightColor * cc_lightColor[i].w * illum * att * (diffuseContrib + lspec);\n}\nreturn vec4(finalColor, 0.0);\n}\n#endif\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 1\nreadonly buffer b_ccLightsBuffer { vec4 b_ccLights[]; };\nreadonly buffer b_clusterLightIndicesBuffer { uint b_clusterLightIndices[]; };\nreadonly buffer b_clusterLightGridBuffer { uvec4 b_clusterLightGrid[]; };\nstruct CCLight\n{\nvec4 cc_lightPos;\nvec4 cc_lightColor;\nvec4 cc_lightSizeRangeAngle;\nvec4 cc_lightDir;\n};\nstruct Cluster\n{\nvec3 minBounds;\nvec3 maxBounds;\n};\nstruct LightGrid\n{\nuint offset;\nuint ccLights;\n};\nCCLight getCCLight(uint i)\n{\nCCLight light;\nlight.cc_lightPos = b_ccLights[4u * i + 0u];\nlight.cc_lightColor = b_ccLights[4u * i + 1u];\nlight.cc_lightSizeRangeAngle = b_ccLights[4u * i + 2u];\nlight.cc_lightDir = b_ccLights[4u * i + 3u];\nreturn light;\n}\nLightGrid getLightGrid(uint cluster)\n{\nuvec4 gridvec = b_clusterLightGrid[cluster];\nLightGrid grid;\ngrid.offset = gridvec.x;\ngrid.ccLights = gridvec.y;\nreturn grid;\n}\nuint getGridLightIndex(uint start, uint offset)\n{\nreturn b_clusterLightIndices[start + offset];\n}\nuint getClusterZIndex(vec4 worldPos)\n{\nfloat scale = float(24) / log(cc_nearFar.y / cc_nearFar.x);\nfloat bias = -(float(24) * log(cc_nearFar.x) / log(cc_nearFar.y / cc_nearFar.x));\nfloat eyeDepth = -(cc_matView * worldPos).z;\nuint zIndex = uint(max(log(eyeDepth) * scale + bias, 0.0));\nreturn zIndex;\n}\nuint getClusterIndex(vec4 fragCoord, vec4 worldPos)\n{\nuint zIndex = getClusterZIndex(worldPos);\nfloat clusterSizeX = ceil(cc_viewPort.z / float(16));\nfloat clusterSizeY = ceil(cc_viewPort.w / float(8));\nuvec3 indices = uvec3(uvec2(fragCoord.xy / vec2(clusterSizeX, clusterSizeY)), zIndex);\nuint cluster = (16u * 8u) * indices.z + 16u * indices.y + indices.x;\nreturn cluster;\n}\nvec4 CCClusterShadingAdditive (StandardSurface s, vec4 shadowPos) {\nvec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\nvec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\nvec3 diffuseContrib = diffuse / PI;\nvec3 position;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nposition = unpackHighpData(s.position, s.position_fract_part);\n#else\nposition = s.position;\n#endif\nvec3 N = normalize(s.normal);\nvec3 V = normalize(cc_cameraPos.xyz - position);\nfloat NV = max(abs(dot(N, V)), 0.001);\nspecular = BRDFApprox(specular, s.roughness, NV);\nvec3 finalColor = vec3(0.0);\nuint cluster = getClusterIndex(gl_FragCoord, vec4(position, 1.0));\nLightGrid grid = getLightGrid(cluster);\nuint numLights = grid.ccLights;\nfor (uint i = 0u; i < 100u; i++) {\nif (i >= numLights) break;\nuint lightIndex = getGridLightIndex(grid.offset, i);\nCCLight light = getCCLight(lightIndex);\nvec3 SLU = light.cc_lightPos.xyz - position;\nvec3 SL = normalize(SLU);\nvec3 SH = normalize(SL + V);\nfloat SNL = max(dot(N, SL), 0.001);\nfloat SNH = max(dot(N, SH), 0.0);\nfloat distSqr = dot(SLU, SLU);\nfloat litRadius = light.cc_lightSizeRangeAngle.x;\nfloat litRadiusSqr = litRadius * litRadius;\nfloat illum = PI * (litRadiusSqr / max(litRadiusSqr , distSqr));\nfloat attRadiusSqrInv = 1.0 / max(light.cc_lightSizeRangeAngle.y, 0.01);\nattRadiusSqrInv *= attRadiusSqrInv;\nfloat att = GetDistAtt(distSqr, attRadiusSqrInv);\nvec3 lspec = specular * CalcSpecular(s.roughness, SNH, SH, N);\nif (light.cc_lightPos.w > 0.0) {\nfloat cosInner = max(dot(-light.cc_lightDir.xyz, SL), 0.01);\nfloat cosOuter = light.cc_lightSizeRangeAngle.z;\nfloat litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\nfloat litAngleOffset = -cosOuter * litAngleScale;\natt *= GetAngleAtt(SL, -light.cc_lightDir.xyz, litAngleScale, litAngleOffset);\n}\nvec3 lightColor = light.cc_lightColor.rgb;\nfloat shadow = 1.0;\n#if CC_RECEIVE_SHADOW\nif (light.cc_lightPos.w > 0.0) {\nshadow = CCSpotShadowFactorBase(shadowPos, position, s.shadowBias);\n}\n#endif\nlightColor *= shadow;\nfinalColor += SNL * lightColor * light.cc_lightColor.w * illum * att * (diffuseContrib + lspec);\n}\nreturn vec4(finalColor, 0.0);\n}\n#endif\nvec3 ACESToneMap (vec3 color) {\ncolor = min(color, vec3(8.0));\nconst float A = 2.51;\nconst float B = 0.03;\nconst float C = 2.43;\nconst float D = 0.59;\nconst float E = 0.14;\nreturn (color * (A * color + B)) / (color * (C * color + D) + E);\n}\nvec4 CCFragOutput (vec4 color) {\n#if CC_USE_HDR\ncolor.rgb = ACESToneMap(color.rgb);\n#endif\ncolor.rgb = sqrt(color.rgb);\nreturn color;\n}\nfloat LinearFog(vec4 pos) {\nvec4 wPos = pos;\nfloat cam_dis = distance(cc_cameraPos, wPos);\nfloat fogStart = cc_fogBase.x;\nfloat fogEnd = cc_fogBase.y;\nreturn clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * fogDensity);\nreturn f;\n}\nfloat ExpSquaredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\nreturn f;\n}\nfloat LayeredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat _FogTop = cc_fogAdd.x;\nfloat _FogRange = cc_fogAdd.y;\nvec3 camWorldProj = cc_cameraPos.xyz;\ncamWorldProj.y = 0.;\nvec3 worldPosProj = wPos.xyz;\nworldPosProj.y = 0.;\nfloat fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\nfloat fDeltaY, fDensityIntegral;\nif (cc_cameraPos.y > _FogTop) {\nif (wPos.y < _FogTop) {\nfDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\nfDensityIntegral = fDeltaY * fDeltaY * 0.5;\n} else {\nfDeltaY = 0.;\nfDensityIntegral = 0.;\n}\n} else {\nif (wPos.y < _FogTop) {\nfloat fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfloat fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\nfDeltaY = abs(fDeltaA - fDeltaB);\nfDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n} else {\nfDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n}\n}\nfloat fDensity;\nif (fDeltaY != 0.) {\nfDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n} else {\nfDensity = 0.;\n}\nfloat f = exp(-fDensity);\nreturn f;\n}\nvoid CC_TRANSFER_FOG_BASE(vec4 pos, out float factor)\n{\n#if CC_USE_FOG == 0\nfactor = LinearFog(pos);\n#elif CC_USE_FOG == 1\nfactor = ExpFog(pos);\n#elif CC_USE_FOG == 2\nfactor = ExpSquaredFog(pos);\n#elif CC_USE_FOG == 3\nfactor = LayeredFog(pos);\n#else\nfactor = 1.0;\n#endif\n}\nvoid CC_APPLY_FOG_BASE(inout vec4 color, float factor) {\ncolor = vec4(mix(cc_fogColor.rgb, color.rgb, factor), color.a);\n}\nvec2 signNotZero(vec2 v) {\nreturn vec2((v.x >= 0.0) ? +1.0 : -1.0, (v.y >= 0.0) ? +1.0 : -1.0);\n}\nvec3 oct_to_float32x3(vec2 e) {\nvec3 v = vec3(e.xy, 1.0 - abs(e.x) - abs(e.y));\nif (v.z < 0.0) v.xy = (1.0 - abs(v.yx)) * signNotZero(v.xy);\nreturn normalize(v);\n}\nvec4 screen2WS(vec3 coord) {\nvec3 ndc = vec3(\n2.0 * (coord.x - cc_viewPort.x) / cc_viewPort.z - 1.0,\n2.0 * (coord.y - cc_viewPort.y) / cc_viewPort.w - 1.0,\n2.0 * coord.z - 1.0);\nvec4 world = ((cc_matViewProjInv) * (vec4(ndc, 1.0)));\nworld = world / world.w;\nreturn world;\n}\nvarying vec2 v_uv;\n#if CC_DEVICE_CAN_BENEFIT_FROM_INPUT_ATTACHMENT\nuniform sampler2D depth_stencil;\n#else\nuniform sampler2D gbuffer_albedoMap;\nuniform sampler2D gbuffer_normalMap;\nuniform sampler2D gbuffer_emissiveMap;\nuniform sampler2D depth_stencil;\n#endif\n#if !CC_DEVICE_CAN_BENEFIT_FROM_INPUT_ATTACHMENT || __VERSION__ >= 450\n#endif\nvoid main () {\nStandardSurface s;\n#if CC_DEVICE_CAN_BENEFIT_FROM_INPUT_ATTACHMENT\nvec4 albedoMap = gl_LastFragData[0];\nvec4 normalMap = gl_LastFragData[1];\nvec4 emissiveMap = gl_LastFragData[2];\nfloat depth = texture2D(depth_stencil, v_uv).x;\n#else\nvec4 albedoMap = texture2D(gbuffer_albedoMap,v_uv);\nvec4 normalMap = texture2D(gbuffer_normalMap,v_uv);\nvec4 emissiveMap = texture2D(gbuffer_emissiveMap,v_uv);\nfloat depth = texture2D(depth_stencil, v_uv).x;\n#endif\ns.albedo = albedoMap;\nvec3 position = screen2WS(vec3(gl_FragCoord.xy, depth)).xyz;\ns.position = position;\ns.roughness = normalMap.z;\ns.normal = oct_to_float32x3(normalMap.xy);\ns.specularIntensity = 0.5;\ns.metallic = normalMap.w;\ns.emissive = emissiveMap.xyz;\ns.occlusion = emissiveMap.w;\nfloat fogFactor;\nCC_TRANSFER_FOG_BASE(vec4(position, 1), fogFactor);\nvec4 shadowPos;\nshadowPos = cc_matLightViewProj * vec4(position, 1);\nvec4 color = CCStandardShadingBase(s, shadowPos) +\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 1\nCCClusterShadingAdditive(s, shadowPos);\n#else\nCCStandardShadingAdditive(s, shadowPos);\n#endif\nCC_APPLY_FOG_BASE(color, fogFactor);\ncolor = CCFragOutput(color);\n#if CC_DEVICE_CAN_BENEFIT_FROM_INPUT_ATTACHMENT\ngl_FragData[2] = color;\n#else\ngl_FragColor = color;\n#endif\n}", + "vert": "\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nattribute vec3 a_position;\nattribute vec3 a_normal;\nattribute vec2 a_texCoord;\nattribute vec4 a_tangent;\n#if CC_USE_SKINNING\nattribute vec4 a_joints;\nattribute vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nattribute highp vec4 a_jointAnimInfo;\n#endif\nattribute vec4 a_matWorld0;\nattribute vec4 a_matWorld1;\nattribute vec4 a_matWorld2;\n#if CC_USE_LIGHTMAP\nattribute vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nattribute vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nattribute float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nattribute float a_vertexId;\n#endif\nuniform highp vec4 cc_cameraPos;\nvarying vec2 v_uv;\nvoid main () {\nvec4 position;\nposition = vec4(a_position, 1.0);\nposition.xy = cc_cameraPos.w == 0.0 ? vec2(position.xy.x, -position.xy.y) : position.xy;\ngl_Position = vec4(position.x, position.y, 1.0, 1.0);\nv_uv = a_texCoord;\n}", + "frag": "\n#ifdef GL_EXT_shader_framebuffer_fetch\n#extension GL_EXT_shader_framebuffer_fetch: enable\n#endif\n#ifdef GL_OES_standard_derivatives\n#extension GL_OES_standard_derivatives: enable\n#endif\n#ifdef GL_EXT_shader_texture_lod\n#extension GL_EXT_shader_texture_lod: enable\n#endif\nprecision highp float;\nuniform highp mat4 cc_matView;\nuniform highp mat4 cc_matProj;\nuniform highp mat4 cc_matViewProjInv;\nuniform highp vec4 cc_cameraPos;\nuniform mediump vec4 cc_mainLitDir;\nuniform mediump vec4 cc_mainLitColor;\nuniform mediump vec4 cc_ambientSky;\nuniform mediump vec4 cc_ambientGround;\nuniform mediump vec4 cc_fogColor;\nuniform mediump vec4 cc_fogBase;\nuniform mediump vec4 cc_fogAdd;\nuniform mediump vec4 cc_nearFar;\nuniform mediump vec4 cc_viewPort;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nvec3 SRGBToLinear (vec3 gamma) {\nreturn gamma * gamma;\n}\nuniform highp mat4 cc_matLightView;\nuniform highp mat4 cc_matLightViewProj;\nuniform highp vec4 cc_shadowInvProjDepthInfo;\nuniform highp vec4 cc_shadowProjDepthInfo;\nuniform highp vec4 cc_shadowProjInfo;\nuniform mediump vec4 cc_shadowNFLSInfo;\nuniform mediump vec4 cc_shadowWHPBInfo;\nuniform mediump vec4 cc_shadowLPNNInfo;\nhighp float unpackHighpData (float mainPart, float modPart) {\nhighp float data = mainPart;\nreturn data + modPart;\n}\nhighp float unpackHighpData (float mainPart, float modPart, const float modValue) {\nhighp float data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nhighp vec2 unpackHighpData (vec2 mainPart, vec2 modPart) {\nhighp vec2 data = mainPart;\nreturn data + modPart;\n}\nhighp vec2 unpackHighpData (vec2 mainPart, vec2 modPart, const float modValue) {\nhighp vec2 data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nhighp vec3 unpackHighpData (vec3 mainPart, vec3 modPart) {\nhighp vec3 data = mainPart;\nreturn data + modPart;\n}\nhighp vec3 unpackHighpData (vec3 mainPart, vec3 modPart, const float modValue) {\nhighp vec3 data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nhighp vec4 unpackHighpData (vec4 mainPart, vec4 modPart) {\nhighp vec4 data = mainPart;\nreturn data + modPart;\n}\nhighp vec4 unpackHighpData (vec4 mainPart, vec4 modPart, const float modValue) {\nhighp vec4 data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nfloat CCGetLinearDepthFromViewSpace(vec3 viewPos) {\nfloat dist = length(viewPos);\nreturn (dist - cc_shadowNFLSInfo.x) / (cc_shadowNFLSInfo.y - cc_shadowNFLSInfo.x);\n}\nfloat CCGetLinearDepth(vec3 worldPos) {\nvec4 viewStartPos = cc_matLightView * vec4(worldPos.xyz, 1.0);\nreturn CCGetLinearDepthFromViewSpace(viewStartPos.xyz);\n}\n#if CC_RECEIVE_SHADOW\nuniform highp sampler2D cc_shadowMap;\nuniform highp sampler2D cc_spotLightingMap;\nvec4 ApplyShadowDepthBias_FaceNormal(vec4 shadowPos, vec3 worldNormal, float normalBias)\n{\nvec4 newShadowPos = shadowPos;\nif(normalBias > EPSILON_LOWP)\n{\nvec4 viewNormal = cc_matLightView * vec4(worldNormal, 0.0);\nif(viewNormal.z < 0.1)\nnewShadowPos.xy += viewNormal.xy * cc_shadowProjInfo.xy * normalBias * clamp(viewNormal.z, 0.001, 0.1);\n}\nreturn newShadowPos;\n}\nvec4 ApplyShadowDepthBias_Perspective(vec4 shadowPos, float viewspaceDepthBias)\n{\nvec3 viewSpacePos;\nviewSpacePos.xy = shadowPos.xy * cc_shadowProjInfo.zw;\nviewSpacePos.z = shadowPos.z * cc_shadowInvProjDepthInfo.x + shadowPos.w * cc_shadowInvProjDepthInfo.y;\nviewSpacePos.xyz += cc_shadowProjDepthInfo.z * normalize(viewSpacePos.xyz) * viewspaceDepthBias;\nvec4 clipSpacePos;\nclipSpacePos.xy = viewSpacePos.xy * cc_shadowProjInfo.xy;\nclipSpacePos.zw = viewSpacePos.z * cc_shadowProjDepthInfo.xz + vec2(cc_shadowProjDepthInfo.y, 0.0);\nif (cc_shadowNFLSInfo.z > EPSILON) {\nclipSpacePos.z = CCGetLinearDepthFromViewSpace(viewSpacePos.xyz);\nclipSpacePos.z = (clipSpacePos.z * 2.0 - 1.0) * clipSpacePos.w;\n}\nreturn clipSpacePos;\n}\nvec4 ApplyShadowDepthBias_Orthographic(vec4 shadowPos, float viewspaceDepthBias)\n{\nfloat coeffA = cc_shadowProjDepthInfo.x;\nfloat coeffB = cc_shadowProjDepthInfo.y;\nfloat viewSpacePos_z = (shadowPos.z - coeffB) / coeffA;\nviewSpacePos_z += viewspaceDepthBias;\nvec4 result = shadowPos;\nresult.z = viewSpacePos_z * coeffA + coeffB;\nreturn result;\n}\nfloat CCGetShadowFactorHard (vec4 shadowPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Orthographic(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat shadow = 0.0;\nfloat closestDepth = 0.0;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nclosestDepth = dot(texture2D(cc_shadowMap, clipPos.xy), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0));\n} else {\nclosestDepth = texture2D(cc_shadowMap, clipPos.xy).x;\n}\nshadow = step(clipPos.z, closestDepth);\nreturn shadow;\n}\nfloat CCGetShadowFactorSoft (vec4 shadowPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Orthographic(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat offsetDepth = clipPos.z;\nvec2 mapSize = cc_shadowWHPBInfo.xy;\nvec2 oneTap = 1.0 / mapSize;\nvec2 clipPos_offset = clipPos.xy + oneTap;\nfloat block0, block1, block2, block3;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos_offset.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos_offset.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos.x, clipPos.y)).x);\nblock1 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos_offset.x, clipPos.y)).x);\nblock2 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos.x, clipPos_offset.y)).x);\nblock3 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos_offset.x, clipPos_offset.y)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * mapSize.x;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block2, block3, coefX);\nfloat coefY = mod(clipPos.y, oneTap.y) * mapSize.y;\nreturn mix(resultX, resultY, coefY);\n}\nfloat CCGetShadowFactorSoft2X (vec4 shadowPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Orthographic(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat offsetDepth = clipPos.z;\nvec2 mapSize = cc_shadowWHPBInfo.xy;\nvec2 oneTap = 1.0 / mapSize;\nfloat clipPos_offset_L = clipPos.x - oneTap.x;\nfloat clipPos_offset_R = clipPos.x + oneTap.x;\nfloat clipPos_offset_U = clipPos.y - oneTap.y;\nfloat clipPos_offset_D = clipPos.y + oneTap.y;\nfloat block0, block1, block2, block3, block4, block5, block6, block7, block8;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos.x, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos_offset_L, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock4 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock5 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos_offset_R, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock6 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock7 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos.x, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock8 = step(offsetDepth, dot(texture2D(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_U)).x);\nblock1 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos.x, clipPos_offset_U)).x);\nblock2 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_U)).x);\nblock3 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos_offset_L, clipPos.y)).x);\nblock4 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos.x, clipPos.y)).x);\nblock5 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos_offset_R, clipPos.y)).x);\nblock6 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_D)).x);\nblock7 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos.x, clipPos_offset_D)).x);\nblock8 = step(offsetDepth, texture2D(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_D)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * mapSize.x;\nfloat coefY = mod(clipPos.y, oneTap.y) * mapSize.y;\nfloat shadow = 0.0;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block3, block4, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block1, block2, coefX);\nresultY = mix(block4, block5, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block3, block4, coefX);\nresultY = mix(block6, block7, coefX);\nshadow += mix(resultX, resultY, coefY);\nresultX = mix(block4, block5, coefX);\nresultY = mix(block7, block8, coefX);\nshadow += mix(resultX, resultY, coefY);\nreturn shadow * 0.25;\n}\nfloat CCGetSpotLightShadowFactorHard (vec4 shadowPos, vec3 worldPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Perspective(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat shadow = 0.0;\nfloat closestDepth = 0.0;\nfloat depth = clipPos.z;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nclosestDepth = dot(texture2D(cc_spotLightingMap, clipPos.xy), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0));\n} else {\nclosestDepth = texture2D(cc_spotLightingMap, clipPos.xy).x;\n}\nshadow = step(depth, closestDepth);\nreturn shadow;\n}\nfloat CCGetSpotLightShadowFactorSoft (vec4 shadowPos, vec3 worldPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Perspective(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat depth = 0.0;\nif (cc_shadowNFLSInfo.z > EPSILON) {\ndepth = CCGetLinearDepth(worldPos);\n} else {\ndepth = clipPos.z;\n}\nvec2 oneTap = 1.0 / cc_shadowWHPBInfo.xy;\nvec2 clipPos_offset = clipPos.xy + oneTap;\nfloat block0, block1, block2, block3;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)).x);\nblock1 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos.y)).x);\nblock2 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset.y)).x);\nblock3 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos_offset.y)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * cc_shadowWHPBInfo.x;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block2, block3, coefX);\nfloat coefY = mod(clipPos.y, oneTap.y) * cc_shadowWHPBInfo.y;\nreturn mix(resultX, resultY, coefY);\n}\nfloat CCGetSpotLightShadowFactorSoft2X (vec4 shadowPos, vec3 worldPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Perspective(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat depth = 0.0;\nif (cc_shadowNFLSInfo.z > EPSILON) {\ndepth = CCGetLinearDepth(worldPos);\n} else {\ndepth = clipPos.z;\n}\nvec2 mapSize = cc_shadowWHPBInfo.xy;\nvec2 oneTap = 1.0 / mapSize;\nfloat clipPos_offset_L = clipPos.x - oneTap.x;\nfloat clipPos_offset_R = clipPos.x + oneTap.x;\nfloat clipPos_offset_U = clipPos.y - oneTap.y;\nfloat clipPos_offset_D = clipPos.y + oneTap.y;\nfloat block0, block1, block2, block3, block4, block5, block6, block7, block8;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock4 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock5 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock6 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock7 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock8 = step(depth, dot(texture2D(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_U)).x);\nblock1 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_U)).x);\nblock2 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_U)).x);\nblock3 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos.y)).x);\nblock4 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)).x);\nblock5 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos.y)).x);\nblock6 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_D)).x);\nblock7 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_D)).x);\nblock8 = step(depth, texture2D(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_D)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * mapSize.x;\nfloat coefY = mod(clipPos.y, oneTap.y) * mapSize.y;\nfloat shadow = 0.0;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block3, block4, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block1, block2, coefX);\nresultY = mix(block4, block5, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block3, block4, coefX);\nresultY = mix(block6, block7, coefX);\nshadow += mix(resultX, resultY, coefY);\nresultX = mix(block4, block5, coefX);\nresultY = mix(block7, block8, coefX);\nshadow += mix(resultX, resultY, coefY);\nreturn shadow * 0.25;\n}\nfloat CCSpotShadowFactorBase(vec4 shadowPos, vec3 worldPos, vec2 shadowBias)\n{\nfloat pcf = cc_shadowWHPBInfo.z;\nif (pcf > 1.9) {\nreturn CCGetSpotLightShadowFactorSoft2X(shadowPos, worldPos, shadowBias.x);\n}else if (pcf > 0.9) {\nreturn CCGetSpotLightShadowFactorSoft(shadowPos, worldPos, shadowBias.x);\n}else {\nreturn CCGetSpotLightShadowFactorHard(shadowPos, worldPos, shadowBias.x);\n}\n}\nfloat CCShadowFactorBase(vec4 shadowPos, vec3 N, vec2 shadowBias)\n{\nfloat realtimeShadow = 1.0;\nvec4 pos = ApplyShadowDepthBias_FaceNormal(shadowPos, N, shadowBias.y);\nfloat pcf = cc_shadowWHPBInfo.z;\nif (pcf > 1.9) {\nrealtimeShadow = CCGetShadowFactorSoft2X(pos, shadowBias.x);\n}else if (pcf > 0.9) {\nrealtimeShadow = CCGetShadowFactorSoft(pos, shadowBias.x);\n}else {\nrealtimeShadow = CCGetShadowFactorHard(pos, shadowBias.x);\n}\nreturn mix(realtimeShadow, 1.0, cc_shadowNFLSInfo.w);\n}\n#endif\n#if CC_USE_IBL\nuniform samplerCube cc_environment;\nvec4 fragTextureLod (sampler2D tex, vec2 coord, float lod) {\n#ifdef GL_EXT_shader_texture_lod\nreturn texture2DLodEXT(tex, coord, lod);\n#else\nreturn texture2D(tex, coord, lod);\n#endif\n}\nvec4 fragTextureLod (samplerCube tex, vec3 coord, float lod) {\n#ifdef GL_EXT_shader_texture_lod\nreturn textureCubeLodEXT(tex, coord, lod);\n#else\nreturn textureCube(tex, coord, lod);\n#endif\n}\nvec3 unpackRGBE (vec4 rgbe) {\nreturn rgbe.rgb * pow(1.1, rgbe.a * 255.0 - 128.0);\n}\n#if CC_USE_DIFFUSEMAP\nuniform samplerCube cc_diffuseMap;\n#endif\n#endif\nfloat GGXMobile (float roughness, float NoH, vec3 H, vec3 N) {\nvec3 NxH = cross(N, H);\nfloat OneMinusNoHSqr = dot(NxH, NxH);\nfloat a = roughness * roughness;\nfloat n = NoH * a;\nfloat p = a / (OneMinusNoHSqr + n * n);\nreturn p * p;\n}\nfloat CalcSpecular (float roughness, float NoH, vec3 H, vec3 N) {\nreturn (roughness * 0.25 + 0.25) * GGXMobile(roughness, NoH, H, N);\n}\nvec3 BRDFApprox (vec3 specular, float roughness, float NoV) {\nconst vec4 c0 = vec4(-1.0, -0.0275, -0.572, 0.022);\nconst vec4 c1 = vec4(1.0, 0.0425, 1.04, -0.04);\nvec4 r = roughness * c0 + c1;\nfloat a004 = min(r.x * r.x, exp2(-9.28 * NoV)) * r.x + r.y;\nvec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;\nAB.y *= clamp(50.0 * specular.g, 0.0, 1.0);\nreturn specular * AB.x + AB.y;\n}\n#if USE_REFLECTION_DENOISE\nvec3 GetEnvReflectionWithMipFiltering(vec3 R, float roughness, float mipCount, float denoiseIntensity) {\n#if CC_USE_IBL\nfloat mip = roughness * mipCount;\nfloat delta = (dot(dFdx(R), dFdy(R))) * 1000.0;\nfloat mipBias = mix(0.0, 5.0, clamp(delta, 0.0, 1.0));\nvec4 biased = fragTextureLod(cc_environment, R, mip + mipBias);\nvec4 filtered = textureCube(cc_environment, R);\n#if CC_USE_IBL == 2\nbiased.rgb = unpackRGBE(biased);\nfiltered.rgb = unpackRGBE(filtered);\n#else\nbiased.rgb = SRGBToLinear(biased.rgb);\nfiltered.rgb = SRGBToLinear(filtered.rgb);\n#endif\nreturn mix(biased.rgb, filtered.rgb, denoiseIntensity);\n#else\nreturn vec3(0.0, 0.0, 0.0);\n#endif\n}\n#endif\nstruct StandardSurface {\nvec4 albedo;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nvec3 position, position_fract_part;\n#else\nvec3 position;\n#endif\nvec3 normal;\nvec3 emissive;\nvec3 lightmap;\nfloat lightmap_test;\nfloat roughness;\nfloat metallic;\nfloat occlusion;\nfloat specularIntensity;\n#if CC_RECEIVE_SHADOW\nvec2 shadowBias;\n#endif\n};\nvec4 CCStandardShadingBase (StandardSurface s, vec4 shadowPos) {\nvec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\nvec3 specular = mix(vec3(0.08 * s.specularIntensity), s.albedo.rgb, s.metallic);\nvec3 position;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nposition = unpackHighpData(s.position, s.position_fract_part);\n#else\nposition = s.position;\n#endif\nvec3 N = normalize(s.normal);\nvec3 V = normalize(cc_cameraPos.xyz - position);\nfloat NV = max(abs(dot(N, V)), 0.0);\nspecular = BRDFApprox(specular, s.roughness, NV);\nvec3 L = normalize(-cc_mainLitDir.xyz);\nvec3 H = normalize(L + V);\nfloat NH = max(dot(N, H), 0.0);\nfloat NL = max(dot(N, L), 0.0);\nvec3 finalColor = NL * cc_mainLitColor.rgb * cc_mainLitColor.w;\nvec3 diffuseContrib = diffuse / PI;\nvec3 specularContrib = specular * CalcSpecular(s.roughness, NH, H, N);\nvec3 dirlightContrib = (diffuseContrib + specularContrib);\nfloat shadow = 1.0;\n#if CC_RECEIVE_SHADOW\nif (NL > 0.0 && cc_mainLitDir.w > 0.0) {\nshadow = CCShadowFactorBase(shadowPos, N, s.shadowBias);\n}\n#endif\ndirlightContrib *= shadow;\nfinalColor *= dirlightContrib;\n#if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\nif (s.lightmap_test > EPSILON_LOWP) {\nfinalColor = diffuse * s.lightmap.rgb * shadow;\n}\n#endif\nfloat fAmb = 0.5 - N.y * 0.5;\nvec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb);\n#if CC_USE_IBL\n#if CC_USE_DIFFUSEMAP\nvec4 diffuseMap = textureCube(cc_diffuseMap, N);\n#if CC_USE_DIFFUSEMAP == 2\nambDiff = unpackRGBE(diffuseMap);\n#else\nambDiff = SRGBToLinear(diffuseMap.rgb);\n#endif\n#endif\nvec3 R = normalize(reflect(-V, N));\n#if USE_REFLECTION_DENOISE\nvec3 env = GetEnvReflectionWithMipFiltering(R, s.roughness, cc_ambientGround.w, 0.6);\n#else\nvec4 envmap = fragTextureLod(cc_environment, R, s.roughness * cc_ambientGround.w);\n#if CC_USE_IBL == 2\nvec3 env = unpackRGBE(envmap);\n#else\nvec3 env = SRGBToLinear(envmap.rgb);\n#endif\n#endif\nfinalColor += env * cc_ambientSky.w * specular * s.occlusion;\n#endif\nfinalColor += ambDiff.rgb * cc_ambientSky.w * diffuse * s.occlusion;\nfinalColor += s.emissive;\nreturn vec4(finalColor, s.albedo.a);\n}\n#if CC_PIPELINE_TYPE == 0\n#define LIGHTS_PER_PASS 1\n#else\n#define LIGHTS_PER_PASS 10\n#endif\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 0\nuniform highp vec4 cc_lightPos[LIGHTS_PER_PASS];\nuniform vec4 cc_lightColor[LIGHTS_PER_PASS];\nuniform vec4 cc_lightSizeRangeAngle[LIGHTS_PER_PASS];\nuniform vec4 cc_lightDir[LIGHTS_PER_PASS];\n#endif\nfloat SmoothDistAtt (float distSqr, float invSqrAttRadius) {\nfloat factor = distSqr * invSqrAttRadius;\nfloat smoothFactor = clamp(1.0 - factor * factor, 0.0, 1.0);\nreturn smoothFactor * smoothFactor;\n}\nfloat GetDistAtt (float distSqr, float invSqrAttRadius) {\nfloat attenuation = 1.0 / max(distSqr, 0.01*0.01);\nattenuation *= SmoothDistAtt(distSqr , invSqrAttRadius);\nreturn attenuation;\n}\nfloat GetAngleAtt (vec3 L, vec3 litDir, float litAngleScale, float litAngleOffset) {\nfloat cd = dot(litDir, L);\nfloat attenuation = clamp(cd * litAngleScale + litAngleOffset, 0.0, 1.0);\nreturn (attenuation * attenuation);\n}\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 0\nvec4 CCStandardShadingAdditive (StandardSurface s, vec4 shadowPos) {\nvec3 position;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nposition = unpackHighpData(s.position, s.position_fract_part);\n#else\nposition = s.position;\n#endif\nvec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\nvec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\nvec3 diffuseContrib = diffuse / PI;\nvec3 N = normalize(s.normal);\nvec3 V = normalize(cc_cameraPos.xyz - position);\nfloat NV = max(abs(dot(N, V)), 0.0);\nspecular = BRDFApprox(specular, s.roughness, NV);\nvec3 finalColor = vec3(0.0);\nint numLights = CC_PIPELINE_TYPE == 0 ? LIGHTS_PER_PASS : int(cc_lightDir[0].w);\nfor (int i = 0; i < LIGHTS_PER_PASS; i++) {\nif (i >= numLights) break;\nvec3 SLU = cc_lightPos[i].xyz - position;\nvec3 SL = normalize(SLU);\nvec3 SH = normalize(SL + V);\nfloat SNL = max(dot(N, SL), 0.0);\nfloat SNH = max(dot(N, SH), 0.0);\nfloat distSqr = dot(SLU, SLU);\nfloat litRadius = cc_lightSizeRangeAngle[i].x;\nfloat litRadiusSqr = litRadius * litRadius;\nfloat illum = litRadiusSqr / max(litRadiusSqr, distSqr);\nfloat attRadiusSqrInv = 1.0 / max(cc_lightSizeRangeAngle[i].y, 0.01);\nattRadiusSqrInv *= attRadiusSqrInv;\nfloat att = GetDistAtt(distSqr, attRadiusSqrInv);\nvec3 lspec = specular * CalcSpecular(s.roughness, SNH, SH, N);\nif (cc_lightPos[i].w > 0.0) {\nfloat cosInner = max(dot(-cc_lightDir[i].xyz, SL), 0.01);\nfloat cosOuter = cc_lightSizeRangeAngle[i].z;\nfloat litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\nfloat litAngleOffset = -cosOuter * litAngleScale;\natt *= GetAngleAtt(SL, -cc_lightDir[i].xyz, litAngleScale, litAngleOffset);\n}\nvec3 lightColor = cc_lightColor[i].rgb;\nfloat shadow = 1.0;\n#if CC_RECEIVE_SHADOW\nif (cc_lightPos[i].w > 0.0 && cc_lightSizeRangeAngle[i].w > 0.0) {\nshadow = CCSpotShadowFactorBase(shadowPos, position, s.shadowBias);\n}\n#endif\nlightColor *= shadow;\nfinalColor += SNL * lightColor * cc_lightColor[i].w * illum * att * (diffuseContrib + lspec);\n}\nreturn vec4(finalColor, 0.0);\n}\n#endif\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 1\nreadonly buffer b_ccLightsBuffer { vec4 b_ccLights[]; };\nreadonly buffer b_clusterLightIndicesBuffer { uint b_clusterLightIndices[]; };\nreadonly buffer b_clusterLightGridBuffer { uvec4 b_clusterLightGrid[]; };\nstruct CCLight\n{\nvec4 cc_lightPos;\nvec4 cc_lightColor;\nvec4 cc_lightSizeRangeAngle;\nvec4 cc_lightDir;\n};\nstruct Cluster\n{\nvec3 minBounds;\nvec3 maxBounds;\n};\nstruct LightGrid\n{\nuint offset;\nuint ccLights;\n};\nCCLight getCCLight(uint i)\n{\nCCLight light;\nlight.cc_lightPos = b_ccLights[4u * i + 0u];\nlight.cc_lightColor = b_ccLights[4u * i + 1u];\nlight.cc_lightSizeRangeAngle = b_ccLights[4u * i + 2u];\nlight.cc_lightDir = b_ccLights[4u * i + 3u];\nreturn light;\n}\nLightGrid getLightGrid(uint cluster)\n{\nuvec4 gridvec = b_clusterLightGrid[cluster];\nLightGrid grid;\ngrid.offset = gridvec.x;\ngrid.ccLights = gridvec.y;\nreturn grid;\n}\nuint getGridLightIndex(uint start, uint offset)\n{\nreturn b_clusterLightIndices[start + offset];\n}\nuint getClusterZIndex(vec4 worldPos)\n{\nfloat scale = float(24) / log(cc_nearFar.y / cc_nearFar.x);\nfloat bias = -(float(24) * log(cc_nearFar.x) / log(cc_nearFar.y / cc_nearFar.x));\nfloat eyeDepth = -(cc_matView * worldPos).z;\nuint zIndex = uint(max(log(eyeDepth) * scale + bias, 0.0));\nreturn zIndex;\n}\nuint getClusterIndex(vec4 fragCoord, vec4 worldPos)\n{\nuint zIndex = getClusterZIndex(worldPos);\nfloat clusterSizeX = ceil(cc_viewPort.z / float(16));\nfloat clusterSizeY = ceil(cc_viewPort.w / float(8));\nuvec3 indices = uvec3(uvec2(fragCoord.xy / vec2(clusterSizeX, clusterSizeY)), zIndex);\nuint cluster = (16u * 8u) * indices.z + 16u * indices.y + indices.x;\nreturn cluster;\n}\nvec4 CCClusterShadingAdditive (StandardSurface s, vec4 shadowPos) {\nvec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\nvec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\nvec3 diffuseContrib = diffuse / PI;\nvec3 position;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nposition = unpackHighpData(s.position, s.position_fract_part);\n#else\nposition = s.position;\n#endif\nvec3 N = normalize(s.normal);\nvec3 V = normalize(cc_cameraPos.xyz - position);\nfloat NV = max(abs(dot(N, V)), 0.001);\nspecular = BRDFApprox(specular, s.roughness, NV);\nvec3 finalColor = vec3(0.0);\nuint cluster = getClusterIndex(gl_FragCoord, vec4(position, 1.0));\nLightGrid grid = getLightGrid(cluster);\nuint numLights = grid.ccLights;\nfor (uint i = 0u; i < 100u; i++) {\nif (i >= numLights) break;\nuint lightIndex = getGridLightIndex(grid.offset, i);\nCCLight light = getCCLight(lightIndex);\nvec3 SLU = light.cc_lightPos.xyz - position;\nvec3 SL = normalize(SLU);\nvec3 SH = normalize(SL + V);\nfloat SNL = max(dot(N, SL), 0.001);\nfloat SNH = max(dot(N, SH), 0.0);\nfloat distSqr = dot(SLU, SLU);\nfloat litRadius = light.cc_lightSizeRangeAngle.x;\nfloat litRadiusSqr = litRadius * litRadius;\nfloat illum = PI * (litRadiusSqr / max(litRadiusSqr , distSqr));\nfloat attRadiusSqrInv = 1.0 / max(light.cc_lightSizeRangeAngle.y, 0.01);\nattRadiusSqrInv *= attRadiusSqrInv;\nfloat att = GetDistAtt(distSqr, attRadiusSqrInv);\nvec3 lspec = specular * CalcSpecular(s.roughness, SNH, SH, N);\nif (light.cc_lightPos.w > 0.0) {\nfloat cosInner = max(dot(-light.cc_lightDir.xyz, SL), 0.01);\nfloat cosOuter = light.cc_lightSizeRangeAngle.z;\nfloat litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\nfloat litAngleOffset = -cosOuter * litAngleScale;\natt *= GetAngleAtt(SL, -light.cc_lightDir.xyz, litAngleScale, litAngleOffset);\n}\nvec3 lightColor = light.cc_lightColor.rgb;\nfloat shadow = 1.0;\n#if CC_RECEIVE_SHADOW\nif (light.cc_lightPos.w > 0.0) {\nshadow = CCSpotShadowFactorBase(shadowPos, position, s.shadowBias);\n}\n#endif\nlightColor *= shadow;\nfinalColor += SNL * lightColor * light.cc_lightColor.w * illum * att * (diffuseContrib + lspec);\n}\nreturn vec4(finalColor, 0.0);\n}\n#endif\nvec3 ACESToneMap (vec3 color) {\ncolor = min(color, vec3(8.0));\nconst float A = 2.51;\nconst float B = 0.03;\nconst float C = 2.43;\nconst float D = 0.59;\nconst float E = 0.14;\nreturn (color * (A * color + B)) / (color * (C * color + D) + E);\n}\nvec4 CCFragOutput (vec4 color) {\n#if CC_USE_HDR\ncolor.rgb = ACESToneMap(color.rgb);\n#endif\ncolor.rgb = sqrt(color.rgb);\nreturn color;\n}\nfloat LinearFog(vec4 pos) {\nvec4 wPos = pos;\nfloat cam_dis = distance(cc_cameraPos, wPos);\nfloat fogStart = cc_fogBase.x;\nfloat fogEnd = cc_fogBase.y;\nreturn clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * fogDensity);\nreturn f;\n}\nfloat ExpSquaredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\nreturn f;\n}\nfloat LayeredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat _FogTop = cc_fogAdd.x;\nfloat _FogRange = cc_fogAdd.y;\nvec3 camWorldProj = cc_cameraPos.xyz;\ncamWorldProj.y = 0.;\nvec3 worldPosProj = wPos.xyz;\nworldPosProj.y = 0.;\nfloat fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\nfloat fDeltaY, fDensityIntegral;\nif (cc_cameraPos.y > _FogTop) {\nif (wPos.y < _FogTop) {\nfDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\nfDensityIntegral = fDeltaY * fDeltaY * 0.5;\n} else {\nfDeltaY = 0.;\nfDensityIntegral = 0.;\n}\n} else {\nif (wPos.y < _FogTop) {\nfloat fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfloat fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\nfDeltaY = abs(fDeltaA - fDeltaB);\nfDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n} else {\nfDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n}\n}\nfloat fDensity;\nif (fDeltaY != 0.) {\nfDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n} else {\nfDensity = 0.;\n}\nfloat f = exp(-fDensity);\nreturn f;\n}\nvoid CC_TRANSFER_FOG_BASE(vec4 pos, out float factor)\n{\n#if CC_USE_FOG == 0\nfactor = LinearFog(pos);\n#elif CC_USE_FOG == 1\nfactor = ExpFog(pos);\n#elif CC_USE_FOG == 2\nfactor = ExpSquaredFog(pos);\n#elif CC_USE_FOG == 3\nfactor = LayeredFog(pos);\n#else\nfactor = 1.0;\n#endif\n}\nvoid CC_APPLY_FOG_BASE(inout vec4 color, float factor) {\ncolor = vec4(mix(cc_fogColor.rgb, color.rgb, factor), color.a);\n}\nvec2 signNotZero(vec2 v) {\nreturn vec2((v.x >= 0.0) ? +1.0 : -1.0, (v.y >= 0.0) ? +1.0 : -1.0);\n}\nvec3 oct_to_float32x3(vec2 e) {\nvec3 v = vec3(e.xy, 1.0 - abs(e.x) - abs(e.y));\nif (v.z < 0.0) v.xy = (1.0 - abs(v.yx)) * signNotZero(v.xy);\nreturn normalize(v);\n}\nfloat getCameraDepthRH(float ndcDepth, mat4 matProj)\n{\nreturn -matProj[3][2] / (ndcDepth + matProj[2][2]);\n}\nvec4 screen2WS(vec3 coord) {\nvec3 ndc = vec3(\n2.0 * (coord.x - cc_viewPort.x) / cc_viewPort.z - 1.0,\n2.0 * (coord.y - cc_viewPort.y) / cc_viewPort.w - 1.0,\n2.0 * coord.z - 1.0);\nfloat w = -getCameraDepthRH(ndc.z, cc_matProj);\nvec4 world = (cc_matViewProjInv * vec4(ndc * w, w));\nreturn world;\n}\nvarying vec2 v_uv;\n#if CC_DEVICE_CAN_BENEFIT_FROM_INPUT_ATTACHMENT\nuniform sampler2D depth_stencil;\n#else\nuniform sampler2D gbuffer_albedoMap;\nuniform sampler2D gbuffer_normalMap;\nuniform sampler2D gbuffer_emissiveMap;\nuniform sampler2D depth_stencil;\n#endif\n#if !CC_DEVICE_CAN_BENEFIT_FROM_INPUT_ATTACHMENT || __VERSION__ >= 450\n#endif\nvoid main () {\nStandardSurface s;\n#if CC_DEVICE_CAN_BENEFIT_FROM_INPUT_ATTACHMENT\nvec4 albedoMap = gl_LastFragData[0];\nvec4 normalMap = gl_LastFragData[1];\nvec4 emissiveMap = gl_LastFragData[2];\nfloat depth = texture2D(depth_stencil, v_uv).x;\n#else\nvec4 albedoMap = texture2D(gbuffer_albedoMap,v_uv);\nvec4 normalMap = texture2D(gbuffer_normalMap,v_uv);\nvec4 emissiveMap = texture2D(gbuffer_emissiveMap,v_uv);\nfloat depth = texture2D(depth_stencil, v_uv).x;\n#endif\ns.albedo = albedoMap;\nvec3 position = screen2WS(vec3(gl_FragCoord.xy, depth)).xyz;\ns.position = position;\ns.roughness = normalMap.z;\ns.normal = oct_to_float32x3(normalMap.xy);\ns.specularIntensity = 0.5;\ns.metallic = normalMap.w;\ns.emissive = emissiveMap.xyz;\ns.occlusion = emissiveMap.w;\nfloat fogFactor;\nCC_TRANSFER_FOG_BASE(vec4(position, 1), fogFactor);\nvec4 shadowPos;\nshadowPos = cc_matLightViewProj * vec4(position, 1);\nvec4 color = CCStandardShadingBase(s, shadowPos) +\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 1\nCCClusterShadingAdditive(s, shadowPos);\n#else\nCCStandardShadingAdditive(s, shadowPos);\n#endif\nCC_APPLY_FOG_BASE(color, fogFactor);\ncolor = CCFragOutput(color);\n#if CC_DEVICE_CAN_BENEFIT_FROM_INPUT_ATTACHMENT\ngl_FragData[2] = color;\n#else\ngl_FragColor = color;\n#endif\n}", } ], [ { - "vert": "\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\nrgba = rgba * 255.0;\nhighp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\nhighp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\nhighp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\nreturn Sign * exp2(Exponent - 23.0) * Mantissa;\n}\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nattribute vec3 a_position;\nattribute vec3 a_normal;\nattribute vec2 a_texCoord;\nattribute vec4 a_tangent;\n#if CC_USE_SKINNING\nattribute vec4 a_joints;\nattribute vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nattribute highp vec4 a_jointAnimInfo;\n#endif\nattribute vec4 a_matWorld0;\nattribute vec4 a_matWorld1;\nattribute vec4 a_matWorld2;\n#if USE_LIGHTMAP\nattribute vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nattribute vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nattribute float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nattribute float a_vertexId;\nint getVertexId() {\nreturn int(a_vertexId);\n}\n#endif\n#if CC_USE_MORPH\nuniform vec4 cc_displacementWeights[15];\nuniform vec4 cc_displacementTextureInfo;\nvec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\nfloat pixelIndexF = float(pixelIndex);\nfloat x = mod(pixelIndexF, textureResolution.x);\nfloat y = floor(pixelIndexF / textureResolution.x);\nreturn vec2(x, y);\n}\nvec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\nreturn (vec2(location.x, location.y) + .5) / textureResolution;\n}\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 uv = getPixelCoordFromLocation(location, cc_displacementTextureInfo.xy);\nreturn texture2D(tex, uv);\n}\n#else\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex * 4;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\nreturn vec4(\ndecode32(texture2D(tex, x)),\ndecode32(texture2D(tex, y)),\ndecode32(texture2D(tex, z)),\n1.0\n);\n}\n#endif\nfloat getDisplacementWeight(int index) {\nint quot = index / 4;\nint remainder = index - quot * 4;\nif (remainder == 0) {\nreturn cc_displacementWeights[quot].x;\n} else if (remainder == 1) {\nreturn cc_displacementWeights[quot].y;\n} else if (remainder == 2) {\nreturn cc_displacementWeights[quot].z;\n} else {\nreturn cc_displacementWeights[quot].w;\n}\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\nreturn fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n#else\nvec3 result = vec3(0, 0, 0);\nint nVertices = int(cc_displacementTextureInfo.z);\nfor (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\nresult += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n}\nreturn result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\nuniform sampler2D cc_PositionDisplacements;\nvec3 getPositionDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nuniform sampler2D cc_NormalDisplacements;\nvec3 getNormalDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\nuniform sampler2D cc_TangentDisplacements;\nvec3 getTangentDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n}\n#endif\nvoid applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nint vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nnormal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\ntangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\n#if CC_USE_BAKED_ANIMATION\nuniform highp vec4 cc_jointTextureInfo;\nuniform highp vec4 cc_jointAnimInfo;\nuniform highp sampler2D cc_jointTexture;\nvoid CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n{\n#if USE_INSTANCING\nhighp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n#else\nhighp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n#endif\ninvSize = cc_jointTextureInfo.w;\nhighp float tempY = floor(temp * invSize);\nx = floor(temp - tempY * cc_jointTextureInfo.x);\ny = (tempY + 0.5) * invSize;\n}\n#else\nuniform highp vec4 cc_joints[90];\n#endif\n#if CC_USE_BAKED_ANIMATION\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(3.0, i, x, y, invSize);\nvec4 v1 = texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y));\nvec4 v2 = texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y));\nvec4 v3 = texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y));\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#else\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(12.0, i, x, y, invSize);\nvec4 v1 = vec4(\ndecode32(texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n);\nvec4 v2 = vec4(\ndecode32(texture2D(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n);\nvec4 v3 = vec4(\ndecode32(texture2D(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n);\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\n#else\nmat4 getJointMatrix (float i) {\nint idx = int(i);\nvec4 v1 = cc_joints[idx * 3];\nvec4 v2 = cc_joints[idx * 3 + 1];\nvec4 v3 = cc_joints[idx * 3 + 2];\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\nmat4 skinMatrix () {\nvec4 joints = vec4(a_joints);\nreturn getJointMatrix(joints.x) * a_weights.x\n+ getJointMatrix(joints.y) * a_weights.y\n+ getJointMatrix(joints.z) * a_weights.z\n+ getJointMatrix(joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\nmat4 m = skinMatrix();\nposition = m * position;\n}\nvoid CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nmat4 m = skinMatrix();\nposition = m * position;\nnormal = (m * vec4(normal, 0.0)).xyz;\ntangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n}\n#endif\nvoid CCVertInput(inout vec4 In)\n{\nIn = vec4(a_position, 1.0);\n#if CC_USE_MORPH\napplyMorph(In);\n#endif\n#if CC_USE_SKINNING\nCCSkin(In);\n#endif\n}\nuniform highp mat4 cc_matView;\nuniform highp mat4 cc_matProj;\nuniform highp vec4 cc_cameraPos;\nuniform mediump vec4 cc_mainLitDir;\n#if !USE_INSTANCING\n#if USE_BATCHING\nuniform highp mat4 cc_matWorlds[10];\n#else\nuniform highp mat4 cc_matWorld;\n#endif\n#endif\nvoid CCGetWorldMatrix(out mat4 matWorld)\n{\n#if USE_INSTANCING\nmatWorld = mat4(\nvec4(a_matWorld0.xyz, 0.0),\nvec4(a_matWorld1.xyz, 0.0),\nvec4(a_matWorld2.xyz, 0.0),\nvec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)\n);\n#elif USE_BATCHING\nmatWorld = cc_matWorlds[int(a_dyn_batch_id)];\n#else\nmatWorld = cc_matWorld;\n#endif\n}\nuniform mediump vec4 cc_planarNDInfo;\nvarying float v_dist;\nvec4 vert () {\nvec4 position;\nCCVertInput(position);\nmat4 matWorld;\nCCGetWorldMatrix(matWorld);\nvec3 P = (matWorld * position).xyz;\nvec3 L = cc_mainLitDir.xyz;\nvec3 N = cc_planarNDInfo.xyz;\nfloat d = cc_planarNDInfo.w + 0.001;\nfloat dist = (-d - dot(P, N)) / (dot(L, N) + 0.0001);\nvec3 shadowPos = P + L * dist;\nvec3 view = normalize(cc_cameraPos.xyz - shadowPos);\nfloat viewLength = length(cc_cameraPos.xyz - shadowPos);\nshadowPos += view * min(1.0, 0.005 * viewLength);\nposition = cc_matProj * cc_matView * vec4(shadowPos, 1.0);\nv_dist = dist;\nreturn position;\n}\nvoid main() { gl_Position = vert(); }", + "vert": "\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\nrgba = rgba * 255.0;\nhighp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\nhighp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\nhighp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\nreturn Sign * exp2(Exponent - 23.0) * Mantissa;\n}\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nattribute vec3 a_position;\nattribute vec3 a_normal;\nattribute vec2 a_texCoord;\nattribute vec4 a_tangent;\n#if CC_USE_SKINNING\nattribute vec4 a_joints;\nattribute vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nattribute highp vec4 a_jointAnimInfo;\n#endif\nattribute vec4 a_matWorld0;\nattribute vec4 a_matWorld1;\nattribute vec4 a_matWorld2;\n#if CC_USE_LIGHTMAP\nattribute vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nattribute vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nattribute float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nattribute float a_vertexId;\nint getVertexId() {\nreturn int(a_vertexId);\n}\n#endif\n#if CC_USE_MORPH\nuniform vec4 cc_displacementWeights[15];\nuniform vec4 cc_displacementTextureInfo;\nvec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\nfloat pixelIndexF = float(pixelIndex);\nfloat x = mod(pixelIndexF, textureResolution.x);\nfloat y = floor(pixelIndexF / textureResolution.x);\nreturn vec2(x, y);\n}\nvec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\nreturn (vec2(location.x, location.y) + .5) / textureResolution;\n}\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 uv = getPixelCoordFromLocation(location, cc_displacementTextureInfo.xy);\nreturn texture2D(tex, uv);\n}\n#else\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex * 4;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\nreturn vec4(\ndecode32(texture2D(tex, x)),\ndecode32(texture2D(tex, y)),\ndecode32(texture2D(tex, z)),\n1.0\n);\n}\n#endif\nfloat getDisplacementWeight(int index) {\nint quot = index / 4;\nint remainder = index - quot * 4;\nif (remainder == 0) {\nreturn cc_displacementWeights[quot].x;\n} else if (remainder == 1) {\nreturn cc_displacementWeights[quot].y;\n} else if (remainder == 2) {\nreturn cc_displacementWeights[quot].z;\n} else {\nreturn cc_displacementWeights[quot].w;\n}\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\nreturn fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n#else\nvec3 result = vec3(0, 0, 0);\nint nVertices = int(cc_displacementTextureInfo.z);\nfor (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\nresult += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n}\nreturn result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\nuniform sampler2D cc_PositionDisplacements;\nvec3 getPositionDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nuniform sampler2D cc_NormalDisplacements;\nvec3 getNormalDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\nuniform sampler2D cc_TangentDisplacements;\nvec3 getTangentDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n}\n#endif\nvoid applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nint vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nnormal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\ntangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\n#if CC_USE_BAKED_ANIMATION\nuniform highp vec4 cc_jointTextureInfo;\nuniform highp vec4 cc_jointAnimInfo;\nuniform highp sampler2D cc_jointTexture;\nvoid CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n{\n#if USE_INSTANCING\nhighp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n#else\nhighp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n#endif\ninvSize = cc_jointTextureInfo.w;\nhighp float tempY = floor(temp * invSize);\nx = floor(temp - tempY * cc_jointTextureInfo.x);\ny = (tempY + 0.5) * invSize;\n}\n#else\nuniform highp vec4 cc_joints[90];\n#endif\n#if CC_USE_BAKED_ANIMATION\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(3.0, i, x, y, invSize);\nvec4 v1 = texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y));\nvec4 v2 = texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y));\nvec4 v3 = texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y));\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#else\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(12.0, i, x, y, invSize);\nvec4 v1 = vec4(\ndecode32(texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n);\nvec4 v2 = vec4(\ndecode32(texture2D(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n);\nvec4 v3 = vec4(\ndecode32(texture2D(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n);\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\n#else\nmat4 getJointMatrix (float i) {\nint idx = int(i);\nvec4 v1 = cc_joints[idx * 3];\nvec4 v2 = cc_joints[idx * 3 + 1];\nvec4 v3 = cc_joints[idx * 3 + 2];\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\nmat4 skinMatrix () {\nvec4 joints = vec4(a_joints);\nreturn getJointMatrix(joints.x) * a_weights.x\n+ getJointMatrix(joints.y) * a_weights.y\n+ getJointMatrix(joints.z) * a_weights.z\n+ getJointMatrix(joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\nmat4 m = skinMatrix();\nposition = m * position;\n}\nvoid CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nmat4 m = skinMatrix();\nposition = m * position;\nnormal = (m * vec4(normal, 0.0)).xyz;\ntangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n}\n#endif\nvoid CCVertInput(inout vec4 In)\n{\nIn = vec4(a_position, 1.0);\n#if CC_USE_MORPH\napplyMorph(In);\n#endif\n#if CC_USE_SKINNING\nCCSkin(In);\n#endif\n}\nuniform highp mat4 cc_matView;\nuniform highp mat4 cc_matProj;\nuniform highp vec4 cc_cameraPos;\nuniform mediump vec4 cc_mainLitDir;\n#if !USE_INSTANCING\n#if USE_BATCHING\nuniform highp mat4 cc_matWorlds[10];\n#else\nuniform highp mat4 cc_matWorld;\n#endif\n#endif\nvoid CCGetWorldMatrix(out mat4 matWorld)\n{\n#if USE_INSTANCING\nmatWorld = mat4(\nvec4(a_matWorld0.xyz, 0.0),\nvec4(a_matWorld1.xyz, 0.0),\nvec4(a_matWorld2.xyz, 0.0),\nvec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)\n);\n#elif USE_BATCHING\nmatWorld = cc_matWorlds[int(a_dyn_batch_id)];\n#else\nmatWorld = cc_matWorld;\n#endif\n}\nuniform mediump vec4 cc_planarNDInfo;\nvarying float v_dist;\nvec4 vert () {\nvec4 position;\nCCVertInput(position);\nmat4 matWorld;\nCCGetWorldMatrix(matWorld);\nvec3 P = (matWorld * position).xyz;\nvec3 L = cc_mainLitDir.xyz;\nvec3 N = cc_planarNDInfo.xyz;\nfloat d = cc_planarNDInfo.w + 0.001;\nfloat dist = (-d - dot(P, N)) / (dot(L, N) + 0.0001);\nvec3 shadowPos = P + L * dist;\nvec3 view = normalize(cc_cameraPos.xyz - shadowPos);\nfloat viewLength = length(cc_cameraPos.xyz - shadowPos);\nshadowPos += view * min(1.0, 0.005 * viewLength);\nposition = cc_matProj * cc_matView * vec4(shadowPos, 1.0);\nv_dist = dist;\nreturn position;\n}\nvoid main() { gl_Position = vert(); }", "frag": "\nprecision mediump float;\nuniform lowp vec4 cc_shadowColor;\nvec4 CCFragOutput (vec4 color) {\nreturn color;\n}\nvarying float v_dist;\nvec4 frag () {\nif(v_dist < 0.0)\ndiscard;\nreturn CCFragOutput(cc_shadowColor);\n}\nvoid main() { gl_FragColor = frag(); }", } ], [ { - "vert": "\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\nrgba = rgba * 255.0;\nhighp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\nhighp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\nhighp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\nreturn Sign * exp2(Exponent - 23.0) * Mantissa;\n}\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nattribute vec3 a_position;\nattribute vec3 a_normal;\nattribute vec2 a_texCoord;\nattribute vec4 a_tangent;\n#if CC_USE_SKINNING\nattribute vec4 a_joints;\nattribute vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nattribute highp vec4 a_jointAnimInfo;\n#endif\nattribute vec4 a_matWorld0;\nattribute vec4 a_matWorld1;\nattribute vec4 a_matWorld2;\n#if USE_LIGHTMAP\nattribute vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nattribute vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nattribute float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nattribute float a_vertexId;\nint getVertexId() {\nreturn int(a_vertexId);\n}\n#endif\n#if CC_USE_MORPH\nuniform vec4 cc_displacementWeights[15];\nuniform vec4 cc_displacementTextureInfo;\nvec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\nfloat pixelIndexF = float(pixelIndex);\nfloat x = mod(pixelIndexF, textureResolution.x);\nfloat y = floor(pixelIndexF / textureResolution.x);\nreturn vec2(x, y);\n}\nvec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\nreturn (vec2(location.x, location.y) + .5) / textureResolution;\n}\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 uv = getPixelCoordFromLocation(location, cc_displacementTextureInfo.xy);\nreturn texture2D(tex, uv);\n}\n#else\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex * 4;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\nreturn vec4(\ndecode32(texture2D(tex, x)),\ndecode32(texture2D(tex, y)),\ndecode32(texture2D(tex, z)),\n1.0\n);\n}\n#endif\nfloat getDisplacementWeight(int index) {\nint quot = index / 4;\nint remainder = index - quot * 4;\nif (remainder == 0) {\nreturn cc_displacementWeights[quot].x;\n} else if (remainder == 1) {\nreturn cc_displacementWeights[quot].y;\n} else if (remainder == 2) {\nreturn cc_displacementWeights[quot].z;\n} else {\nreturn cc_displacementWeights[quot].w;\n}\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\nreturn fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n#else\nvec3 result = vec3(0, 0, 0);\nint nVertices = int(cc_displacementTextureInfo.z);\nfor (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\nresult += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n}\nreturn result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\nuniform sampler2D cc_PositionDisplacements;\nvec3 getPositionDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nuniform sampler2D cc_NormalDisplacements;\nvec3 getNormalDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\nuniform sampler2D cc_TangentDisplacements;\nvec3 getTangentDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n}\n#endif\nvoid applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nint vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nnormal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\ntangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\n#if CC_USE_BAKED_ANIMATION\nuniform highp vec4 cc_jointTextureInfo;\nuniform highp vec4 cc_jointAnimInfo;\nuniform highp sampler2D cc_jointTexture;\nvoid CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n{\n#if USE_INSTANCING\nhighp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n#else\nhighp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n#endif\ninvSize = cc_jointTextureInfo.w;\nhighp float tempY = floor(temp * invSize);\nx = floor(temp - tempY * cc_jointTextureInfo.x);\ny = (tempY + 0.5) * invSize;\n}\n#else\nuniform highp vec4 cc_joints[90];\n#endif\n#if CC_USE_BAKED_ANIMATION\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(3.0, i, x, y, invSize);\nvec4 v1 = texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y));\nvec4 v2 = texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y));\nvec4 v3 = texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y));\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#else\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(12.0, i, x, y, invSize);\nvec4 v1 = vec4(\ndecode32(texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n);\nvec4 v2 = vec4(\ndecode32(texture2D(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n);\nvec4 v3 = vec4(\ndecode32(texture2D(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n);\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\n#else\nmat4 getJointMatrix (float i) {\nint idx = int(i);\nvec4 v1 = cc_joints[idx * 3];\nvec4 v2 = cc_joints[idx * 3 + 1];\nvec4 v3 = cc_joints[idx * 3 + 2];\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\nmat4 skinMatrix () {\nvec4 joints = vec4(a_joints);\nreturn getJointMatrix(joints.x) * a_weights.x\n+ getJointMatrix(joints.y) * a_weights.y\n+ getJointMatrix(joints.z) * a_weights.z\n+ getJointMatrix(joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\nmat4 m = skinMatrix();\nposition = m * position;\n}\nvoid CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nmat4 m = skinMatrix();\nposition = m * position;\nnormal = (m * vec4(normal, 0.0)).xyz;\ntangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n}\n#endif\nvoid CCVertInput(inout StandardVertInput In)\n{\nIn.position = vec4(a_position, 1.0);\nIn.normal = a_normal;\nIn.tangent = a_tangent;\n#if CC_USE_MORPH\napplyMorph(In.position, In.normal, In.tangent);\n#endif\n#if CC_USE_SKINNING\nCCSkin(In.position, In.normal, In.tangent);\n#endif\n}\nuniform highp vec4 cc_cameraPos;\nvarying vec2 v_uv;\nvoid main () {\nStandardVertInput In;\nCCVertInput(In);\nIn.position.xy = cc_cameraPos.w == 0.0 ? vec2(In.position.xy.x, -In.position.xy.y) : In.position.xy;\ngl_Position = In.position;\ngl_Position.y = gl_Position.y;\nv_uv = a_texCoord;\n}", + "vert": "\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\nrgba = rgba * 255.0;\nhighp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\nhighp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\nhighp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\nreturn Sign * exp2(Exponent - 23.0) * Mantissa;\n}\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nattribute vec3 a_position;\nattribute vec3 a_normal;\nattribute vec2 a_texCoord;\nattribute vec4 a_tangent;\n#if CC_USE_SKINNING\nattribute vec4 a_joints;\nattribute vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nattribute highp vec4 a_jointAnimInfo;\n#endif\nattribute vec4 a_matWorld0;\nattribute vec4 a_matWorld1;\nattribute vec4 a_matWorld2;\n#if CC_USE_LIGHTMAP\nattribute vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nattribute vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nattribute float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nattribute float a_vertexId;\nint getVertexId() {\nreturn int(a_vertexId);\n}\n#endif\n#if CC_USE_MORPH\nuniform vec4 cc_displacementWeights[15];\nuniform vec4 cc_displacementTextureInfo;\nvec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\nfloat pixelIndexF = float(pixelIndex);\nfloat x = mod(pixelIndexF, textureResolution.x);\nfloat y = floor(pixelIndexF / textureResolution.x);\nreturn vec2(x, y);\n}\nvec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\nreturn (vec2(location.x, location.y) + .5) / textureResolution;\n}\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 uv = getPixelCoordFromLocation(location, cc_displacementTextureInfo.xy);\nreturn texture2D(tex, uv);\n}\n#else\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex * 4;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\nreturn vec4(\ndecode32(texture2D(tex, x)),\ndecode32(texture2D(tex, y)),\ndecode32(texture2D(tex, z)),\n1.0\n);\n}\n#endif\nfloat getDisplacementWeight(int index) {\nint quot = index / 4;\nint remainder = index - quot * 4;\nif (remainder == 0) {\nreturn cc_displacementWeights[quot].x;\n} else if (remainder == 1) {\nreturn cc_displacementWeights[quot].y;\n} else if (remainder == 2) {\nreturn cc_displacementWeights[quot].z;\n} else {\nreturn cc_displacementWeights[quot].w;\n}\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\nreturn fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n#else\nvec3 result = vec3(0, 0, 0);\nint nVertices = int(cc_displacementTextureInfo.z);\nfor (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\nresult += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n}\nreturn result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\nuniform sampler2D cc_PositionDisplacements;\nvec3 getPositionDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nuniform sampler2D cc_NormalDisplacements;\nvec3 getNormalDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\nuniform sampler2D cc_TangentDisplacements;\nvec3 getTangentDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n}\n#endif\nvoid applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nint vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nnormal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\ntangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\n#if CC_USE_BAKED_ANIMATION\nuniform highp vec4 cc_jointTextureInfo;\nuniform highp vec4 cc_jointAnimInfo;\nuniform highp sampler2D cc_jointTexture;\nvoid CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n{\n#if USE_INSTANCING\nhighp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n#else\nhighp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n#endif\ninvSize = cc_jointTextureInfo.w;\nhighp float tempY = floor(temp * invSize);\nx = floor(temp - tempY * cc_jointTextureInfo.x);\ny = (tempY + 0.5) * invSize;\n}\n#else\nuniform highp vec4 cc_joints[90];\n#endif\n#if CC_USE_BAKED_ANIMATION\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(3.0, i, x, y, invSize);\nvec4 v1 = texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y));\nvec4 v2 = texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y));\nvec4 v3 = texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y));\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#else\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(12.0, i, x, y, invSize);\nvec4 v1 = vec4(\ndecode32(texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n);\nvec4 v2 = vec4(\ndecode32(texture2D(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n);\nvec4 v3 = vec4(\ndecode32(texture2D(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\ndecode32(texture2D(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n);\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\n#else\nmat4 getJointMatrix (float i) {\nint idx = int(i);\nvec4 v1 = cc_joints[idx * 3];\nvec4 v2 = cc_joints[idx * 3 + 1];\nvec4 v3 = cc_joints[idx * 3 + 2];\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\nmat4 skinMatrix () {\nvec4 joints = vec4(a_joints);\nreturn getJointMatrix(joints.x) * a_weights.x\n+ getJointMatrix(joints.y) * a_weights.y\n+ getJointMatrix(joints.z) * a_weights.z\n+ getJointMatrix(joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\nmat4 m = skinMatrix();\nposition = m * position;\n}\nvoid CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nmat4 m = skinMatrix();\nposition = m * position;\nnormal = (m * vec4(normal, 0.0)).xyz;\ntangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n}\n#endif\nvoid CCVertInput(inout StandardVertInput In)\n{\nIn.position = vec4(a_position, 1.0);\nIn.normal = a_normal;\nIn.tangent = a_tangent;\n#if CC_USE_MORPH\napplyMorph(In.position, In.normal, In.tangent);\n#endif\n#if CC_USE_SKINNING\nCCSkin(In.position, In.normal, In.tangent);\n#endif\n}\nuniform highp vec4 cc_cameraPos;\nvarying vec2 v_uv;\nvoid main () {\nStandardVertInput In;\nCCVertInput(In);\nIn.position.xy = cc_cameraPos.w == 0.0 ? vec2(In.position.xy.x, -In.position.xy.y) : In.position.xy;\ngl_Position = In.position;\ngl_Position.y = gl_Position.y;\nv_uv = a_texCoord;\n}", "frag": "\nprecision highp float;\nuniform mediump vec4 cc_screenSize;\n#if ANTIALIAS_TYPE == 1\nvec4 fxaa(sampler2D tex, vec2 fragCoord, vec2 resolution,\nvec2 v_rgbNW, vec2 v_rgbNE,\nvec2 v_rgbSW, vec2 v_rgbSE,\nvec2 v_rgbM) {\nvec4 color;\nmediump vec2 inverseVP = vec2(1.0 / resolution.x, 1.0 / resolution.y);\nvec3 rgbNW = texture2D(tex, v_rgbNW).xyz;\nvec3 rgbNE = texture2D(tex, v_rgbNE).xyz;\nvec3 rgbSW = texture2D(tex, v_rgbSW).xyz;\nvec3 rgbSE = texture2D(tex, v_rgbSE).xyz;\nvec4 texColor = texture2D(tex, v_rgbM);\nvec3 rgbM = texColor.xyz;\nvec3 luma = vec3(0.299, 0.587, 0.114);\nfloat lumaNW = dot(rgbNW, luma);\nfloat lumaNE = dot(rgbNE, luma);\nfloat lumaSW = dot(rgbSW, luma);\nfloat lumaSE = dot(rgbSE, luma);\nfloat lumaM = dot(rgbM, luma);\nfloat lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));\nfloat lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));\nmediump vec2 dir;\ndir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));\ndir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));\nfloat dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) *\n(0.25 * (1.0 / 8.0)), (1.0/ 128.0));\nfloat rcpDirMin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce);\ndir = min(vec2(8.0, 8.0),\nmax(vec2(-8.0, -8.0),\ndir * rcpDirMin)) * inverseVP;\nvec3 rgbA = 0.5 * (\ntexture2D(tex, fragCoord * inverseVP + dir * (1.0 / 3.0 - 0.5)).xyz +\ntexture2D(tex, fragCoord * inverseVP + dir * (2.0 / 3.0 - 0.5)).xyz);\nvec3 rgbB = rgbA * 0.5 + 0.25 * (\ntexture2D(tex, fragCoord * inverseVP + dir * -0.5).xyz +\ntexture2D(tex, fragCoord * inverseVP + dir * 0.5).xyz);\nfloat lumaB = dot(rgbB, luma);\nif ((lumaB < lumaMin) || (lumaB > lumaMax))\ncolor = vec4(rgbA, texColor.a);\nelse\ncolor = vec4(rgbB, texColor.a);\nreturn color;\n}\n#endif\nvarying vec2 v_uv;\nuniform sampler2D outputResultMap;\nvoid texcoords(vec2 fragCoord, vec2 resolution,\nout vec2 v_rgbNW, out vec2 v_rgbNE,\nout vec2 v_rgbSW, out vec2 v_rgbSE,\nout vec2 v_rgbM) {\nvec2 inverseVP = 1.0 / resolution.xy;\nv_rgbNW = (fragCoord + vec2(-1.0, -1.0)) * inverseVP;\nv_rgbNE = (fragCoord + vec2(1.0, -1.0)) * inverseVP;\nv_rgbSW = (fragCoord + vec2(-1.0, 1.0)) * inverseVP;\nv_rgbSE = (fragCoord + vec2(1.0, 1.0)) * inverseVP;\nv_rgbM = vec2(fragCoord * inverseVP);\n}\nvoid main () {\nmediump vec2 v_rgbNW;\nmediump vec2 v_rgbNE;\nmediump vec2 v_rgbSW;\nmediump vec2 v_rgbSE;\nmediump vec2 v_rgbM;\n#if ANTIALIAS_TYPE == 1\nvec2 resolution = cc_screenSize.xy;\nvec2 fragCoord = v_uv * resolution;\ntexcoords(fragCoord, resolution, v_rgbNW, v_rgbNE, v_rgbSW, v_rgbSE, v_rgbM);\ngl_FragColor = fxaa(outputResultMap, fragCoord, resolution, v_rgbNW, v_rgbNE, v_rgbSW, v_rgbSE, v_rgbM);\n#else\ngl_FragColor = texture2D(outputResultMap, v_uv);\n#endif\n}", } ], [ { - "vert": "\nprecision highp float;\nuniform highp mat4 cc_matView;\nuniform highp mat4 cc_matProj;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nattribute vec3 a_position;\nattribute vec3 a_normal;\nattribute vec2 a_texCoord;\nattribute vec4 a_tangent;\n#if CC_USE_SKINNING\nattribute vec4 a_joints;\nattribute vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nattribute highp vec4 a_jointAnimInfo;\n#endif\nattribute vec4 a_matWorld0;\nattribute vec4 a_matWorld1;\nattribute vec4 a_matWorld2;\n#if USE_LIGHTMAP\nattribute vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nattribute vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nattribute float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nattribute float a_vertexId;\n#endif\nvarying mediump vec4 viewDir;\nvec4 vert () {\nviewDir = vec4(a_position, 1.0);\nmat4 matViewRotOnly = mat4(mat3(cc_matView));\nvec4 pos = matViewRotOnly * viewDir;\nif (cc_matProj[3].w > 0.0) {\nmat4 matProj = cc_matProj;\nmatProj[0].x = 5.2;\nmatProj[1].y = 2.6;\nmatProj[2].zw = vec2(-1.0);\nmatProj[3].zw = vec2(0.0);\npos = matProj * pos;\n} else {\npos = cc_matProj * pos;\n}\npos.z = 0.99999 * pos.w;\nreturn pos;\n}\nvoid main() { gl_Position = vert(); }", + "vert": "\nprecision highp float;\nuniform highp mat4 cc_matView;\nuniform highp mat4 cc_matProj;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nattribute vec3 a_position;\nattribute vec3 a_normal;\nattribute vec2 a_texCoord;\nattribute vec4 a_tangent;\n#if CC_USE_SKINNING\nattribute vec4 a_joints;\nattribute vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nattribute highp vec4 a_jointAnimInfo;\n#endif\nattribute vec4 a_matWorld0;\nattribute vec4 a_matWorld1;\nattribute vec4 a_matWorld2;\n#if CC_USE_LIGHTMAP\nattribute vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nattribute vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nattribute float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nattribute float a_vertexId;\n#endif\nvarying mediump vec4 viewDir;\nvec4 vert () {\nviewDir = vec4(a_position, 1.0);\nmat4 matViewRotOnly = mat4(mat3(cc_matView));\nvec4 pos = matViewRotOnly * viewDir;\nif (cc_matProj[3].w > 0.0) {\nmat4 matProj = cc_matProj;\nmatProj[0].x = 5.2;\nmatProj[1].y = 2.6;\nmatProj[2].zw = vec2(-1.0);\nmatProj[3].zw = vec2(0.0);\npos = matProj * pos;\n} else {\npos = cc_matProj * pos;\n}\npos.z = 0.99999 * pos.w;\nreturn pos;\n}\nvoid main() { gl_Position = vert(); }", "frag": "\nprecision mediump float;\nuniform mediump vec4 cc_ambientSky;\nuniform samplerCube cc_environment;\nvec3 unpackRGBE (vec4 rgbe) {\nreturn rgbe.rgb * pow(1.1, rgbe.a * 255.0 - 128.0);\n}\nvec3 SRGBToLinear (vec3 gamma) {\nreturn gamma * gamma;\n}\nvec3 ACESToneMap (vec3 color) {\ncolor = min(color, vec3(8.0));\nconst float A = 2.51;\nconst float B = 0.03;\nconst float C = 2.43;\nconst float D = 0.59;\nconst float E = 0.14;\nreturn (color * (A * color + B)) / (color * (C * color + D) + E);\n}\nvec4 CCFragOutput (vec4 color) {\n#if CC_USE_HDR\ncolor.rgb = ACESToneMap(color.rgb);\n#endif\ncolor.rgb = sqrt(color.rgb);\nreturn color;\n}\nvarying mediump vec4 viewDir;\nvec4 frag () {\n#if USE_RGBE_CUBEMAP\nvec3 c = unpackRGBE(textureCube(cc_environment, viewDir.xyz));\n#else\nvec3 c = SRGBToLinear(textureCube(cc_environment, viewDir.xyz).rgb);\n#endif\nreturn CCFragOutput(vec4(c * cc_ambientSky.w, 1.0));\n}\nvoid main() { gl_FragColor = frag(); }", } ], diff --git a/cocos/core/builtin/shader-sources/glsl3.ts b/cocos/core/builtin/shader-sources/glsl3.ts index 4ec1d3883b..5ed02025dc 100644 --- a/cocos/core/builtin/shader-sources/glsl3.ts +++ b/cocos/core/builtin/shader-sources/glsl3.ts @@ -88,18 +88,18 @@ export const glsl3 = [ ], [ { - "vert": "\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\nrgba = rgba * 255.0;\nhighp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\nhighp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\nhighp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\nreturn Sign * exp2(Exponent - 23.0) * Mantissa;\n}\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nin vec3 a_position;\nin vec3 a_normal;\nin vec2 a_texCoord;\nin vec4 a_tangent;\n#if CC_USE_SKINNING\nin vec4 a_joints;\nin vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nin highp vec4 a_jointAnimInfo;\n#endif\nin vec4 a_matWorld0;\nin vec4 a_matWorld1;\nin vec4 a_matWorld2;\n#if USE_LIGHTMAP\nin vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nin vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nin float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nin float a_vertexId;\nint getVertexId() {\nreturn int(a_vertexId);\n}\n#endif\n#if CC_USE_MORPH\nlayout(std140) uniform CCMorph {\nvec4 cc_displacementWeights[15];\nvec4 cc_displacementTextureInfo;\n};\nvec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\nfloat pixelIndexF = float(pixelIndex);\nfloat x = mod(pixelIndexF, textureResolution.x);\nfloat y = floor(pixelIndexF / textureResolution.x);\nreturn vec2(x, y);\n}\nvec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\nreturn (vec2(location.x, location.y) + .5) / textureResolution;\n}\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int pixelIndex) {\nivec2 texSize = textureSize(tex, 0);\nreturn texelFetch(tex, ivec2(pixelIndex % texSize.x, pixelIndex / texSize.x), 0);\n}\n#else\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex * 4;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\nreturn vec4(\ndecode32(texture(tex, x)),\ndecode32(texture(tex, y)),\ndecode32(texture(tex, z)),\n1.0\n);\n}\n#endif\nfloat getDisplacementWeight(int index) {\nint quot = index / 4;\nint remainder = index - quot * 4;\nif (remainder == 0) {\nreturn cc_displacementWeights[quot].x;\n} else if (remainder == 1) {\nreturn cc_displacementWeights[quot].y;\n} else if (remainder == 2) {\nreturn cc_displacementWeights[quot].z;\n} else {\nreturn cc_displacementWeights[quot].w;\n}\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\nreturn fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n#else\nvec3 result = vec3(0, 0, 0);\nint nVertices = int(cc_displacementTextureInfo.z);\nfor (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\nresult += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n}\nreturn result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\nuniform sampler2D cc_PositionDisplacements;\nvec3 getPositionDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nuniform sampler2D cc_NormalDisplacements;\nvec3 getNormalDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\nuniform sampler2D cc_TangentDisplacements;\nvec3 getTangentDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n}\n#endif\nvoid applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nint vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nnormal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\ntangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\n#if CC_USE_BAKED_ANIMATION\nlayout(std140) uniform CCSkinningTexture {\nhighp vec4 cc_jointTextureInfo;\n};\nlayout(std140) uniform CCSkinningAnimation {\nhighp vec4 cc_jointAnimInfo;\n};\nuniform highp sampler2D cc_jointTexture;\nvoid CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n{\n#if USE_INSTANCING\nhighp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n#else\nhighp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n#endif\ninvSize = cc_jointTextureInfo.w;\nhighp float tempY = floor(temp * invSize);\nx = floor(temp - tempY * cc_jointTextureInfo.x);\ny = (tempY + 0.5) * invSize;\n}\n#else\nlayout(std140) uniform CCSkinning {\nhighp vec4 cc_joints[30 * 3];\n};\n#endif\n#if CC_USE_BAKED_ANIMATION\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(3.0, i, x, y, invSize);\nvec4 v1 = texture(cc_jointTexture, vec2((x + 0.5) * invSize, y));\nvec4 v2 = texture(cc_jointTexture, vec2((x + 1.5) * invSize, y));\nvec4 v3 = texture(cc_jointTexture, vec2((x + 2.5) * invSize, y));\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#else\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(12.0, i, x, y, invSize);\nvec4 v1 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n);\nvec4 v2 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n);\nvec4 v3 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n);\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\n#else\nmat4 getJointMatrix (float i) {\nint idx = int(i);\nvec4 v1 = cc_joints[idx * 3];\nvec4 v2 = cc_joints[idx * 3 + 1];\nvec4 v3 = cc_joints[idx * 3 + 2];\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\nmat4 skinMatrix () {\nvec4 joints = vec4(a_joints);\nreturn getJointMatrix(joints.x) * a_weights.x\n+ getJointMatrix(joints.y) * a_weights.y\n+ getJointMatrix(joints.z) * a_weights.z\n+ getJointMatrix(joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\nmat4 m = skinMatrix();\nposition = m * position;\n}\nvoid CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nmat4 m = skinMatrix();\nposition = m * position;\nnormal = (m * vec4(normal, 0.0)).xyz;\ntangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n}\n#endif\nvoid CCVertInput(inout StandardVertInput In)\n{\nIn.position = vec4(a_position, 1.0);\nIn.normal = a_normal;\nIn.tangent = a_tangent;\n#if CC_USE_MORPH\napplyMorph(In.position, In.normal, In.tangent);\n#endif\n#if CC_USE_SKINNING\nCCSkin(In.position, In.normal, In.tangent);\n#endif\n}\nlayout(std140) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(std140) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\n#if !USE_INSTANCING\n#if USE_BATCHING\nlayout(std140) uniform CCLocalBatched {\nhighp mat4 cc_matWorlds[10];\n};\n#else\nlayout(std140) uniform CCLocal {\nhighp mat4 cc_matWorld;\nhighp mat4 cc_matWorldIT;\nhighp vec4 cc_lightingMapUVParam;\nhighp vec4 cc_localShadowBias;\n};\n#endif\n#endif\nvoid CCGetWorldMatrixFull(out mat4 matWorld, out mat4 matWorldIT)\n{\n#if USE_INSTANCING\nmatWorld = mat4(\nvec4(a_matWorld0.xyz, 0.0),\nvec4(a_matWorld1.xyz, 0.0),\nvec4(a_matWorld2.xyz, 0.0),\nvec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)\n);\nmatWorldIT = matWorld;\n#elif USE_BATCHING\nmatWorld = cc_matWorlds[int(a_dyn_batch_id)];\nmatWorldIT = matWorld;\n#else\nmatWorld = cc_matWorld;\nmatWorldIT = cc_matWorldIT;\n#endif\n}\nlayout(std140) uniform Constants {\nvec4 tilingOffset;\nvec4 albedo;\nvec4 albedoScaleAndCutoff;\nvec4 pbrParams;\nvec4 emissive;\nvec4 emissiveScaleParam;\n};\nfloat LinearFog(vec4 pos) {\nvec4 wPos = pos;\nfloat cam_dis = distance(cc_cameraPos, wPos);\nfloat fogStart = cc_fogBase.x;\nfloat fogEnd = cc_fogBase.y;\nreturn clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * fogDensity);\nreturn f;\n}\nfloat ExpSquaredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\nreturn f;\n}\nfloat LayeredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat _FogTop = cc_fogAdd.x;\nfloat _FogRange = cc_fogAdd.y;\nvec3 camWorldProj = cc_cameraPos.xyz;\ncamWorldProj.y = 0.;\nvec3 worldPosProj = wPos.xyz;\nworldPosProj.y = 0.;\nfloat fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\nfloat fDeltaY, fDensityIntegral;\nif (cc_cameraPos.y > _FogTop) {\nif (wPos.y < _FogTop) {\nfDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\nfDensityIntegral = fDeltaY * fDeltaY * 0.5;\n} else {\nfDeltaY = 0.;\nfDensityIntegral = 0.;\n}\n} else {\nif (wPos.y < _FogTop) {\nfloat fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfloat fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\nfDeltaY = abs(fDeltaA - fDeltaB);\nfDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n} else {\nfDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n}\n}\nfloat fDensity;\nif (fDeltaY != 0.) {\nfDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n} else {\nfDensity = 0.;\n}\nfloat f = exp(-fDensity);\nreturn f;\n}\nvoid CC_TRANSFER_FOG_BASE(vec4 pos, out float factor)\n{\n#if CC_USE_FOG == 0\nfactor = LinearFog(pos);\n#elif CC_USE_FOG == 1\nfactor = ExpFog(pos);\n#elif CC_USE_FOG == 2\nfactor = ExpSquaredFog(pos);\n#elif CC_USE_FOG == 3\nfactor = LayeredFog(pos);\n#else\nfactor = 1.0;\n#endif\n}\n#if !CC_USE_ACCURATE_FOG\nout float v_fog_factor;\n#endif\nvoid CC_TRANSFER_FOG(vec4 pos) {\n#if !CC_USE_ACCURATE_FOG\nCC_TRANSFER_FOG_BASE(pos, v_fog_factor);\n#endif\n}\nout highp vec4 v_shadowPos;\nlayout(std140) uniform CCShadow {\nhighp mat4 cc_matLightPlaneProj;\nhighp mat4 cc_matLightView;\nhighp mat4 cc_matLightViewProj;\nhighp vec4 cc_shadowInvProjDepthInfo;\nhighp vec4 cc_shadowProjDepthInfo;\nhighp vec4 cc_shadowProjInfo;\nmediump vec4 cc_shadowNFLSInfo;\nmediump vec4 cc_shadowWHPBInfo;\nmediump vec4 cc_shadowLPNNInfo;\nlowp vec4 cc_shadowColor;\nmediump vec4 cc_planarNDInfo;\n};\n#if CC_RECEIVE_SHADOW\nuniform highp sampler2D cc_shadowMap;\nuniform highp sampler2D cc_spotLightingMap;\n#endif\n#if CC_RECEIVE_SHADOW\nvec2 CCGetShadowBias()\n{\n#if USE_INSTANCING\nreturn vec2(a_localShadowBias.x + cc_shadowWHPBInfo.w, a_localShadowBias.y + cc_shadowLPNNInfo.z);\n#elif !USE_BATCHING\nreturn vec2(cc_localShadowBias.x + cc_shadowWHPBInfo.w, cc_localShadowBias.y + cc_shadowLPNNInfo.z);\n#else\nreturn vec2(cc_shadowWHPBInfo.w, cc_shadowLPNNInfo.z);\n#endif\n}\n#endif\n#if USE_VERTEX_COLOR\nin vec4 a_color;\nout lowp vec4 v_color;\n#endif\nout vec3 v_position;\nout mediump vec3 v_normal;\nout vec2 v_uv;\n#if HAS_SECOND_UV\nout mediump vec2 v_uv1;\n#endif\n#if CC_RECEIVE_SHADOW\nout mediump vec2 v_shadowBias;\n#endif\n#if USE_NORMAL_MAP\nout mediump vec4 v_tangent;\n#endif\n#if HAS_SECOND_UV || USE_LIGHTMAP\nin vec2 a_texCoord1;\n#endif\n#if USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\nout vec3 v_luv;\nvoid CCLightingMapCaclUV()\n{\n#if !USE_INSTANCING\nv_luv.xy = cc_lightingMapUVParam.xy + a_texCoord1 * cc_lightingMapUVParam.z;\nv_luv.z = cc_lightingMapUVParam.w;\n#else\nv_luv.xy = a_lightingMapUVParam.xy + a_texCoord1 * a_lightingMapUVParam.z;\nv_luv.z = a_lightingMapUVParam.w;\n#endif\n}\n#endif\nvoid main () {\nStandardVertInput In;\nCCVertInput(In);\nmat4 matWorld, matWorldIT;\nCCGetWorldMatrixFull(matWorld, matWorldIT);\nvec4 pos = matWorld * In.position;\nv_position = pos.xyz;\nv_normal = normalize((matWorldIT * vec4(In.normal, 0.0)).xyz);\n#if CC_RECEIVE_SHADOW\nv_shadowBias = CCGetShadowBias();\n#endif\n#if USE_TWOSIDE\nvec3 viewDirect = normalize(cc_cameraPos.xyz - v_position);\nv_normal *= dot(v_normal, viewDirect) < 0.0 ? -1.0 : 1.0;\n#endif\n#if USE_NORMAL_MAP\nv_tangent.xyz = normalize((matWorld * vec4(In.tangent.xyz, 0.0)).xyz);\nv_tangent.w = In.tangent.w;\n#endif\nv_uv = a_texCoord * tilingOffset.xy + tilingOffset.zw;\n#if SAMPLE_FROM_RT\nv_uv = cc_cameraPos.w > 1.0 ? vec2(v_uv.x, 1.0 - v_uv.y) : v_uv;\n#endif\n#if HAS_SECOND_UV\nv_uv1 = a_texCoord1 * tilingOffset.xy + tilingOffset.zw;\n#if SAMPLE_FROM_RT\nv_uv1 = cc_cameraPos.w > 1.0 ? vec2(v_uv1.x, 1.0 - v_uv1.y) : v_uv1;\n#endif\n#endif\n#if USE_VERTEX_COLOR\nv_color = a_color;\n#endif\nCC_TRANSFER_FOG(pos);\nv_shadowPos = cc_matLightViewProj * pos;\n#if USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\nCCLightingMapCaclUV();\n#endif\ngl_Position = cc_matProj * (cc_matView * matWorld) * In.position;\n}", - "frag": "\nprecision highp float;\nlayout(std140) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(std140) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\nlayout(std140) uniform Constants {\nvec4 tilingOffset;\nvec4 albedo;\nvec4 albedoScaleAndCutoff;\nvec4 pbrParams;\nvec4 emissive;\nvec4 emissiveScaleParam;\n};\nfloat LinearFog(vec4 pos) {\nvec4 wPos = pos;\nfloat cam_dis = distance(cc_cameraPos, wPos);\nfloat fogStart = cc_fogBase.x;\nfloat fogEnd = cc_fogBase.y;\nreturn clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * fogDensity);\nreturn f;\n}\nfloat ExpSquaredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\nreturn f;\n}\nfloat LayeredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat _FogTop = cc_fogAdd.x;\nfloat _FogRange = cc_fogAdd.y;\nvec3 camWorldProj = cc_cameraPos.xyz;\ncamWorldProj.y = 0.;\nvec3 worldPosProj = wPos.xyz;\nworldPosProj.y = 0.;\nfloat fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\nfloat fDeltaY, fDensityIntegral;\nif (cc_cameraPos.y > _FogTop) {\nif (wPos.y < _FogTop) {\nfDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\nfDensityIntegral = fDeltaY * fDeltaY * 0.5;\n} else {\nfDeltaY = 0.;\nfDensityIntegral = 0.;\n}\n} else {\nif (wPos.y < _FogTop) {\nfloat fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfloat fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\nfDeltaY = abs(fDeltaA - fDeltaB);\nfDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n} else {\nfDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n}\n}\nfloat fDensity;\nif (fDeltaY != 0.) {\nfDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n} else {\nfDensity = 0.;\n}\nfloat f = exp(-fDensity);\nreturn f;\n}\nvoid CC_TRANSFER_FOG_BASE(vec4 pos, out float factor)\n{\n#if CC_USE_FOG == 0\nfactor = LinearFog(pos);\n#elif CC_USE_FOG == 1\nfactor = ExpFog(pos);\n#elif CC_USE_FOG == 2\nfactor = ExpSquaredFog(pos);\n#elif CC_USE_FOG == 3\nfactor = LayeredFog(pos);\n#else\nfactor = 1.0;\n#endif\n}\nvoid CC_APPLY_FOG_BASE(inout vec4 color, float factor) {\ncolor = vec4(mix(cc_fogColor.rgb, color.rgb, factor), color.a);\n}\n#if !CC_USE_ACCURATE_FOG\nin float v_fog_factor;\n#endif\nvoid CC_APPLY_FOG(inout vec4 color) {\n#if !CC_USE_ACCURATE_FOG\nCC_APPLY_FOG_BASE(color, v_fog_factor);\n#endif\n}\nvoid CC_APPLY_FOG(inout vec4 color, vec3 worldPos) {\n#if CC_USE_ACCURATE_FOG\nfloat factor;\nCC_TRANSFER_FOG_BASE(vec4(worldPos, 1.0), factor);\n#else\nfloat factor = v_fog_factor;\n#endif\nCC_APPLY_FOG_BASE(color, factor);\n}\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nvec3 SRGBToLinear (vec3 gamma) {\nreturn gamma * gamma;\n}\nlayout(std140) uniform CCShadow {\nhighp mat4 cc_matLightPlaneProj;\nhighp mat4 cc_matLightView;\nhighp mat4 cc_matLightViewProj;\nhighp vec4 cc_shadowInvProjDepthInfo;\nhighp vec4 cc_shadowProjDepthInfo;\nhighp vec4 cc_shadowProjInfo;\nmediump vec4 cc_shadowNFLSInfo;\nmediump vec4 cc_shadowWHPBInfo;\nmediump vec4 cc_shadowLPNNInfo;\nlowp vec4 cc_shadowColor;\nmediump vec4 cc_planarNDInfo;\n};\nhighp float unpackHighpData (float mainPart, float modPart) {\nhighp float data = mainPart;\nreturn data + modPart;\n}\nvoid packHighpData (out float mainPart, out float modPart, highp float data) {\nmainPart = fract(data);\nmodPart = data - mainPart;\n}\nhighp float unpackHighpData (float mainPart, float modPart, const float modValue) {\nhighp float data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nvoid packHighpData (out float mainPart, out float modPart, highp float data, const float modValue) {\nhighp float divide = data / modValue;\nmainPart = floor(divide);\nmodPart = (data - mainPart * modValue) / modValue;\n}\nhighp vec2 unpackHighpData (vec2 mainPart, vec2 modPart) {\nhighp vec2 data = mainPart;\nreturn data + modPart;\n}\nvoid packHighpData (out vec2 mainPart, out vec2 modPart, highp vec2 data) {\nmainPart = fract(data);\nmodPart = data - mainPart;\n}\nhighp vec2 unpackHighpData (vec2 mainPart, vec2 modPart, const float modValue) {\nhighp vec2 data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nvoid packHighpData (out vec2 mainPart, out vec2 modPart, highp vec2 data, const float modValue) {\nhighp vec2 divide = data / modValue;\nmainPart = floor(divide);\nmodPart = (data - mainPart * modValue) / modValue;\n}\nhighp vec3 unpackHighpData (vec3 mainPart, vec3 modPart) {\nhighp vec3 data = mainPart;\nreturn data + modPart;\n}\nvoid packHighpData (out vec3 mainPart, out vec3 modPart, highp vec3 data) {\nmainPart = fract(data);\nmodPart = data - mainPart;\n}\nhighp vec3 unpackHighpData (vec3 mainPart, vec3 modPart, const float modValue) {\nhighp vec3 data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nvoid packHighpData (out vec3 mainPart, out vec3 modPart, highp vec3 data, const float modValue) {\nhighp vec3 divide = data / modValue;\nmainPart = floor(divide);\nmodPart = (data - mainPart * modValue) / modValue;\n}\nhighp vec4 unpackHighpData (vec4 mainPart, vec4 modPart) {\nhighp vec4 data = mainPart;\nreturn data + modPart;\n}\nvoid packHighpData (out vec4 mainPart, out vec4 modPart, highp vec4 data) {\nmainPart = fract(data);\nmodPart = data - mainPart;\n}\nhighp vec4 unpackHighpData (vec4 mainPart, vec4 modPart, const float modValue) {\nhighp vec4 data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nvoid packHighpData (out vec4 mainPart, out vec4 modPart, highp vec4 data, const float modValue) {\nhighp vec4 divide = data / modValue;\nmainPart = floor(divide);\nmodPart = (data - mainPart * modValue) / modValue;\n}\nlayout(std140) uniform CCLocal {\nhighp mat4 cc_matWorld;\nhighp mat4 cc_matWorldIT;\nhighp vec4 cc_lightingMapUVParam;\nhighp vec4 cc_localShadowBias;\n};\nfloat CCGetLinearDepthFromViewSpace(vec3 viewPos) {\nfloat dist = length(viewPos);\nreturn (dist - cc_shadowNFLSInfo.x) / (cc_shadowNFLSInfo.y - cc_shadowNFLSInfo.x);\n}\nfloat CCGetLinearDepth(vec3 worldPos) {\nvec4 viewStartPos = cc_matLightView * vec4(worldPos.xyz, 1.0);\nreturn CCGetLinearDepthFromViewSpace(viewStartPos.xyz);\n}\n#if CC_RECEIVE_SHADOW\nuniform highp sampler2D cc_shadowMap;\nuniform highp sampler2D cc_spotLightingMap;\nvec4 ApplyShadowDepthBias_FaceNormal(vec4 shadowPos, vec3 worldNormal, float normalBias)\n{\nvec4 newShadowPos = shadowPos;\nif(normalBias > EPSILON_LOWP)\n{\nvec4 viewNormal = cc_matLightView * vec4(worldNormal, 0.0);\nif(viewNormal.z < 0.1)\nnewShadowPos.xy += viewNormal.xy * cc_shadowProjInfo.xy * normalBias * clamp(viewNormal.z, 0.001, 0.1);\n}\nreturn newShadowPos;\n}\nvec4 ApplyShadowDepthBias_Perspective(vec4 shadowPos, float viewspaceDepthBias)\n{\nvec3 viewSpacePos;\nviewSpacePos.xy = shadowPos.xy * cc_shadowProjInfo.zw;\nviewSpacePos.z = shadowPos.z * cc_shadowInvProjDepthInfo.x + shadowPos.w * cc_shadowInvProjDepthInfo.y;\nviewSpacePos.xyz += cc_shadowProjDepthInfo.z * normalize(viewSpacePos.xyz) * viewspaceDepthBias;\nvec4 clipSpacePos;\nclipSpacePos.xy = viewSpacePos.xy * cc_shadowProjInfo.xy;\nclipSpacePos.zw = viewSpacePos.z * cc_shadowProjDepthInfo.xz + vec2(cc_shadowProjDepthInfo.y, 0.0);\nif (cc_shadowNFLSInfo.z > EPSILON) {\nclipSpacePos.z = CCGetLinearDepthFromViewSpace(viewSpacePos.xyz);\nclipSpacePos.z = (clipSpacePos.z * 2.0 - 1.0) * clipSpacePos.w;\n}\nreturn clipSpacePos;\n}\nvec4 ApplyShadowDepthBias_Orthographic(vec4 shadowPos, float viewspaceDepthBias)\n{\nfloat coeffA = cc_shadowProjDepthInfo.x;\nfloat coeffB = cc_shadowProjDepthInfo.y;\nfloat viewSpacePos_z = (shadowPos.z - coeffB) / coeffA;\nviewSpacePos_z += viewspaceDepthBias;\nvec4 result = shadowPos;\nresult.z = viewSpacePos_z * coeffA + coeffB;\nreturn result;\n}\nfloat CCGetShadowFactorHard (vec4 shadowPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Orthographic(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat shadow = 0.0;\nfloat closestDepth = 0.0;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nclosestDepth = dot(texture(cc_shadowMap, clipPos.xy), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0));\n} else {\nclosestDepth = texture(cc_shadowMap, clipPos.xy).x;\n}\nshadow = step(clipPos.z, closestDepth);\nreturn shadow;\n}\nfloat CCGetShadowFactorSoft (vec4 shadowPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Orthographic(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat offsetDepth = clipPos.z;\nvec2 mapSize = cc_shadowWHPBInfo.xy;\nvec2 oneTap = 1.0 / mapSize;\nvec2 clipPos_offset = clipPos.xy + oneTap;\nfloat block0, block1, block2, block3;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos.y)).x);\nblock1 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset.x, clipPos.y)).x);\nblock2 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset.y)).x);\nblock3 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset.x, clipPos_offset.y)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * mapSize.x;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block2, block3, coefX);\nfloat coefY = mod(clipPos.y, oneTap.y) * mapSize.y;\nreturn mix(resultX, resultY, coefY);\n}\nfloat CCGetShadowFactorSoft2X (vec4 shadowPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Orthographic(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat offsetDepth = clipPos.z;\nvec2 mapSize = cc_shadowWHPBInfo.xy;\nvec2 oneTap = 1.0 / mapSize;\nfloat clipPos_offset_L = clipPos.x - oneTap.x;\nfloat clipPos_offset_R = clipPos.x + oneTap.x;\nfloat clipPos_offset_U = clipPos.y - oneTap.y;\nfloat clipPos_offset_D = clipPos.y + oneTap.y;\nfloat block0, block1, block2, block3, block4, block5, block6, block7, block8;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock4 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock5 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock6 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock7 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock8 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_U)).x);\nblock1 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset_U)).x);\nblock2 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_U)).x);\nblock3 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos.y)).x);\nblock4 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos.y)).x);\nblock5 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos.y)).x);\nblock6 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_D)).x);\nblock7 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset_D)).x);\nblock8 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_D)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * mapSize.x;\nfloat coefY = mod(clipPos.y, oneTap.y) * mapSize.y;\nfloat shadow = 0.0;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block3, block4, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block1, block2, coefX);\nresultY = mix(block4, block5, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block3, block4, coefX);\nresultY = mix(block6, block7, coefX);\nshadow += mix(resultX, resultY, coefY);\nresultX = mix(block4, block5, coefX);\nresultY = mix(block7, block8, coefX);\nshadow += mix(resultX, resultY, coefY);\nreturn shadow * 0.25;\n}\nfloat CCGetSpotLightShadowFactorHard (vec4 shadowPos, vec3 worldPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Perspective(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat shadow = 0.0;\nfloat closestDepth = 0.0;\nfloat depth = clipPos.z;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nclosestDepth = dot(texture(cc_spotLightingMap, clipPos.xy), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0));\n} else {\nclosestDepth = texture(cc_spotLightingMap, clipPos.xy).x;\n}\nshadow = step(depth, closestDepth);\nreturn shadow;\n}\nfloat CCGetSpotLightShadowFactorSoft (vec4 shadowPos, vec3 worldPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Perspective(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat depth = 0.0;\nif (cc_shadowNFLSInfo.z > EPSILON) {\ndepth = CCGetLinearDepth(worldPos);\n} else {\ndepth = clipPos.z;\n}\nvec2 oneTap = 1.0 / cc_shadowWHPBInfo.xy;\nvec2 clipPos_offset = clipPos.xy + oneTap;\nfloat block0, block1, block2, block3;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)).x);\nblock1 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos.y)).x);\nblock2 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset.y)).x);\nblock3 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos_offset.y)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * cc_shadowWHPBInfo.x;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block2, block3, coefX);\nfloat coefY = mod(clipPos.y, oneTap.y) * cc_shadowWHPBInfo.y;\nreturn mix(resultX, resultY, coefY);\n}\nfloat CCGetSpotLightShadowFactorSoft2X (vec4 shadowPos, vec3 worldPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Perspective(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat depth = 0.0;\nif (cc_shadowNFLSInfo.z > EPSILON) {\ndepth = CCGetLinearDepth(worldPos);\n} else {\ndepth = clipPos.z;\n}\nvec2 mapSize = cc_shadowWHPBInfo.xy;\nvec2 oneTap = 1.0 / mapSize;\nfloat clipPos_offset_L = clipPos.x - oneTap.x;\nfloat clipPos_offset_R = clipPos.x + oneTap.x;\nfloat clipPos_offset_U = clipPos.y - oneTap.y;\nfloat clipPos_offset_D = clipPos.y + oneTap.y;\nfloat block0, block1, block2, block3, block4, block5, block6, block7, block8;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock4 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock5 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock6 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock7 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock8 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_U)).x);\nblock1 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_U)).x);\nblock2 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_U)).x);\nblock3 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos.y)).x);\nblock4 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)).x);\nblock5 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos.y)).x);\nblock6 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_D)).x);\nblock7 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_D)).x);\nblock8 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_D)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * mapSize.x;\nfloat coefY = mod(clipPos.y, oneTap.y) * mapSize.y;\nfloat shadow = 0.0;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block3, block4, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block1, block2, coefX);\nresultY = mix(block4, block5, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block3, block4, coefX);\nresultY = mix(block6, block7, coefX);\nshadow += mix(resultX, resultY, coefY);\nresultX = mix(block4, block5, coefX);\nresultY = mix(block7, block8, coefX);\nshadow += mix(resultX, resultY, coefY);\nreturn shadow * 0.25;\n}\nfloat CCSpotShadowFactorBase(vec4 shadowPos, vec3 worldPos, vec2 shadowBias)\n{\nfloat pcf = cc_shadowWHPBInfo.z;\nif (pcf > 1.9) {\nreturn CCGetSpotLightShadowFactorSoft2X(shadowPos, worldPos, shadowBias.x);\n}else if (pcf > 0.9) {\nreturn CCGetSpotLightShadowFactorSoft(shadowPos, worldPos, shadowBias.x);\n}else {\nreturn CCGetSpotLightShadowFactorHard(shadowPos, worldPos, shadowBias.x);\n}\n}\nfloat CCShadowFactorBase(vec4 shadowPos, vec3 N, vec2 shadowBias)\n{\nfloat realtimeShadow = 1.0;\nvec4 pos = ApplyShadowDepthBias_FaceNormal(shadowPos, N, shadowBias.y);\nfloat pcf = cc_shadowWHPBInfo.z;\nif (pcf > 1.9) {\nrealtimeShadow = CCGetShadowFactorSoft2X(pos, shadowBias.x);\n}else if (pcf > 0.9) {\nrealtimeShadow = CCGetShadowFactorSoft(pos, shadowBias.x);\n}else {\nrealtimeShadow = CCGetShadowFactorHard(pos, shadowBias.x);\n}\nreturn mix(realtimeShadow, 1.0, cc_shadowNFLSInfo.w);\n}\n#endif\n#if CC_USE_IBL\nuniform samplerCube cc_environment;\nvec4 fragTextureLod (sampler2D tex, vec2 coord, float lod) {\nreturn textureLod(tex, coord, lod);\n}\nvec4 fragTextureLod (samplerCube tex, vec3 coord, float lod) {\nreturn textureLod(tex, coord, lod);\n}\nvec3 unpackRGBE (vec4 rgbe) {\nreturn rgbe.rgb * pow(1.1, rgbe.a * 255.0 - 128.0);\n}\n#if CC_USE_DIFFUSEMAP\nuniform samplerCube cc_diffuseMap;\n#endif\n#endif\nfloat GGXMobile (float roughness, float NoH, vec3 H, vec3 N) {\nvec3 NxH = cross(N, H);\nfloat OneMinusNoHSqr = dot(NxH, NxH);\nfloat a = roughness * roughness;\nfloat n = NoH * a;\nfloat p = a / (OneMinusNoHSqr + n * n);\nreturn p * p;\n}\nfloat CalcSpecular (float roughness, float NoH, vec3 H, vec3 N) {\nreturn (roughness * 0.25 + 0.25) * GGXMobile(roughness, NoH, H, N);\n}\nvec3 BRDFApprox (vec3 specular, float roughness, float NoV) {\nconst vec4 c0 = vec4(-1.0, -0.0275, -0.572, 0.022);\nconst vec4 c1 = vec4(1.0, 0.0425, 1.04, -0.04);\nvec4 r = roughness * c0 + c1;\nfloat a004 = min(r.x * r.x, exp2(-9.28 * NoV)) * r.x + r.y;\nvec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;\nAB.y *= clamp(50.0 * specular.g, 0.0, 1.0);\nreturn specular * AB.x + AB.y;\n}\n#if USE_REFLECTION_DENOISE\nvec3 GetEnvReflectionWithMipFiltering(vec3 R, float roughness, float mipCount, float denoiseIntensity) {\n#if CC_USE_IBL\nfloat mip = roughness * mipCount;\nfloat delta = (dot(dFdx(R), dFdy(R))) * 1000.0;\nfloat mipBias = mix(0.0, 5.0, clamp(delta, 0.0, 1.0));\nvec4 biased = fragTextureLod(cc_environment, R, mip + mipBias);\nvec4 filtered = texture(cc_environment, R);\n#if CC_USE_IBL == 2\nbiased.rgb = unpackRGBE(biased);\nfiltered.rgb = unpackRGBE(filtered);\n#else\nbiased.rgb = SRGBToLinear(biased.rgb);\nfiltered.rgb = SRGBToLinear(filtered.rgb);\n#endif\nreturn mix(biased.rgb, filtered.rgb, denoiseIntensity);\n#else\nreturn vec3(0.0, 0.0, 0.0);\n#endif\n}\n#endif\nstruct StandardSurface {\nvec4 albedo;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nvec3 position, position_fract_part;\n#else\nvec3 position;\n#endif\nvec3 normal;\nvec3 emissive;\nvec3 lightmap;\nfloat lightmap_test;\nfloat roughness;\nfloat metallic;\nfloat occlusion;\nfloat specularIntensity;\n#if CC_RECEIVE_SHADOW\nvec2 shadowBias;\n#endif\n};\nvec4 CCStandardShadingBase (StandardSurface s, vec4 shadowPos) {\nvec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\nvec3 specular = mix(vec3(0.08 * s.specularIntensity), s.albedo.rgb, s.metallic);\nvec3 position;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nposition = unpackHighpData(s.position, s.position_fract_part);\n#else\nposition = s.position;\n#endif\nvec3 N = normalize(s.normal);\nvec3 V = normalize(cc_cameraPos.xyz - position);\nfloat NV = max(abs(dot(N, V)), 0.0);\nspecular = BRDFApprox(specular, s.roughness, NV);\nvec3 L = normalize(-cc_mainLitDir.xyz);\nvec3 H = normalize(L + V);\nfloat NH = max(dot(N, H), 0.0);\nfloat NL = max(dot(N, L), 0.0);\nvec3 finalColor = NL * cc_mainLitColor.rgb * cc_mainLitColor.w;\nvec3 diffuseContrib = diffuse / PI;\nvec3 specularContrib = specular * CalcSpecular(s.roughness, NH, H, N);\nvec3 dirlightContrib = (diffuseContrib + specularContrib);\nfloat shadow = 1.0;\n#if CC_RECEIVE_SHADOW\nif (NL > 0.0 && cc_mainLitDir.w > 0.0) {\nshadow = CCShadowFactorBase(shadowPos, N, s.shadowBias);\n}\n#endif\ndirlightContrib *= shadow;\nfinalColor *= dirlightContrib;\n#if USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\nif (s.lightmap_test > EPSILON_LOWP) {\nfinalColor = diffuse * s.lightmap.rgb * shadow;\n}\n#endif\nfloat fAmb = 0.5 - N.y * 0.5;\nvec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb);\n#if CC_USE_IBL\n#if CC_USE_DIFFUSEMAP\nvec4 diffuseMap = texture(cc_diffuseMap, N);\n#if CC_USE_DIFFUSEMAP == 2\nambDiff = unpackRGBE(diffuseMap);\n#else\nambDiff = SRGBToLinear(diffuseMap.rgb);\n#endif\n#endif\nvec3 R = normalize(reflect(-V, N));\n#if USE_REFLECTION_DENOISE\nvec3 env = GetEnvReflectionWithMipFiltering(R, s.roughness, cc_ambientGround.w, 0.6);\n#else\nvec4 envmap = fragTextureLod(cc_environment, R, s.roughness * cc_ambientGround.w);\n#if CC_USE_IBL == 2\nvec3 env = unpackRGBE(envmap);\n#else\nvec3 env = SRGBToLinear(envmap.rgb);\n#endif\n#endif\nfinalColor += env * cc_ambientSky.w * specular * s.occlusion;\n#endif\nfinalColor += ambDiff.rgb * cc_ambientSky.w * diffuse * s.occlusion;\nfinalColor += s.emissive;\nreturn vec4(finalColor, s.albedo.a);\n}\nvec3 ACESToneMap (vec3 color) {\ncolor = min(color, vec3(8.0));\nconst float A = 2.51;\nconst float B = 0.03;\nconst float C = 2.43;\nconst float D = 0.59;\nconst float E = 0.14;\nreturn (color * (A * color + B)) / (color * (C * color + D) + E);\n}\nvec4 CCFragOutput (vec4 color) {\n#if CC_USE_HDR\ncolor.rgb = ACESToneMap(color.rgb);\n#endif\ncolor.rgb = sqrt(color.rgb);\nreturn color;\n}\nin highp vec4 v_shadowPos;\n#if CC_RECEIVE_SHADOW\n#endif\n#if USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\nin vec3 v_luv;\nuniform sampler2D cc_lightingMap;\n#endif\nin vec3 v_position;\nin vec2 v_uv;\n#if HAS_SECOND_UV\nin mediump vec2 v_uv1;\n#endif\nin mediump vec3 v_normal;\n#if CC_RECEIVE_SHADOW\nin mediump vec2 v_shadowBias;\n#endif\n#if USE_VERTEX_COLOR\nin lowp vec4 v_color;\n#endif\n#if USE_ALBEDO_MAP\nuniform sampler2D albedoMap;\n#endif\n#if USE_NORMAL_MAP\nin mediump vec4 v_tangent;\nuniform sampler2D normalMap;\n#endif\n#if USE_PBR_MAP\nuniform sampler2D pbrMap;\n#endif\n#if USE_METALLIC_ROUGHNESS_MAP\nuniform sampler2D metallicRoughnessMap;\n#endif\n#if USE_OCCLUSION_MAP\nuniform sampler2D occlusionMap;\n#endif\n#if USE_EMISSIVE_MAP\nuniform sampler2D emissiveMap;\n#endif\n#if USE_ALPHA_TEST\n#endif\nvoid surf (out StandardSurface s) {\nvec4 baseColor = albedo;\n#if USE_VERTEX_COLOR\nbaseColor.rgb *= SRGBToLinear(v_color.rgb);\nbaseColor.a *= v_color.a;\n#endif\n#if USE_ALBEDO_MAP\nvec4 texColor = texture(albedoMap, ALBEDO_UV);\ntexColor.rgb = SRGBToLinear(texColor.rgb);\nbaseColor *= texColor;\n#endif\ns.albedo = baseColor;\ns.albedo.rgb *= albedoScaleAndCutoff.xyz;\n#if USE_ALPHA_TEST\nif (s.albedo.ALPHA_TEST_CHANNEL < albedoScaleAndCutoff.w) discard;\n#endif\n#if USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\nvec4 lightColor = texture(cc_lightingMap, v_luv.xy);\ns.lightmap = lightColor.xyz * v_luv.z;\ns.lightmap_test = v_luv.z;\n#endif\ns.normal = v_normal;\n#if CC_RECEIVE_SHADOW\ns.shadowBias = v_shadowBias;\n#endif\n#if USE_NORMAL_MAP\nvec3 nmmp = texture(normalMap, NORMAL_UV).xyz - vec3(0.5);\nvec3 bitangent = cross(v_normal, v_tangent.xyz) * v_tangent.w;\ns.normal =\n(nmmp.x * emissiveScaleParam.w) * normalize(v_tangent.xyz) +\n(nmmp.y * emissiveScaleParam.w) * normalize(bitangent) +\nnmmp.z * normalize(s.normal);\n#endif\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\npackHighpData(s.position, s.position_fract_part, v_position);\n#else\ns.position = v_position;\n#endif\nvec4 pbr = pbrParams;\n#if USE_PBR_MAP\nvec4 res = texture(pbrMap, PBR_UV);\npbr.x *= res.r;\npbr.y *= res.g;\npbr.z *= res.b;\npbr.w *= res.a;\n#endif\n#if USE_METALLIC_ROUGHNESS_MAP\nvec4 metallicRoughness = texture(metallicRoughnessMap, PBR_UV);\npbr.z *= metallicRoughness.b;\npbr.y *= metallicRoughness.g;\n#endif\n#if USE_OCCLUSION_MAP\npbr.x *= texture(occlusionMap, PBR_UV).r;\n#endif\ns.occlusion = pbr.x;\ns.roughness = pbr.y;\ns.specularIntensity = 0.5;\ns.metallic = pbr.z;\ns.emissive = emissive.rgb * emissiveScaleParam.xyz;\n#if USE_EMISSIVE_MAP\ns.emissive *= SRGBToLinear(texture(emissiveMap, EMISSIVE_UV).rgb);\n#endif\n}\n#if CC_FORWARD_ADD\n#if CC_PIPELINE_TYPE == 0\n#define LIGHTS_PER_PASS 1\n#else\n#define LIGHTS_PER_PASS 10\n#endif\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 0\nlayout(std140) uniform CCForwardLight {\nhighp vec4 cc_lightPos[LIGHTS_PER_PASS];\nvec4 cc_lightColor[LIGHTS_PER_PASS];\nvec4 cc_lightSizeRangeAngle[LIGHTS_PER_PASS];\nvec4 cc_lightDir[LIGHTS_PER_PASS];\n};\n#endif\nfloat SmoothDistAtt (float distSqr, float invSqrAttRadius) {\nfloat factor = distSqr * invSqrAttRadius;\nfloat smoothFactor = clamp(1.0 - factor * factor, 0.0, 1.0);\nreturn smoothFactor * smoothFactor;\n}\nfloat GetDistAtt (float distSqr, float invSqrAttRadius) {\nfloat attenuation = 1.0 / max(distSqr, 0.01*0.01);\nattenuation *= SmoothDistAtt(distSqr , invSqrAttRadius);\nreturn attenuation;\n}\nfloat GetAngleAtt (vec3 L, vec3 litDir, float litAngleScale, float litAngleOffset) {\nfloat cd = dot(litDir, L);\nfloat attenuation = clamp(cd * litAngleScale + litAngleOffset, 0.0, 1.0);\nreturn (attenuation * attenuation);\n}\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 0\nvec4 CCStandardShadingAdditive (StandardSurface s, vec4 shadowPos) {\nvec3 position;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nposition = unpackHighpData(s.position, s.position_fract_part);\n#else\nposition = s.position;\n#endif\nvec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\nvec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\nvec3 diffuseContrib = diffuse / PI;\nvec3 N = normalize(s.normal);\nvec3 V = normalize(cc_cameraPos.xyz - position);\nfloat NV = max(abs(dot(N, V)), 0.0);\nspecular = BRDFApprox(specular, s.roughness, NV);\nvec3 finalColor = vec3(0.0);\nint numLights = CC_PIPELINE_TYPE == 0 ? LIGHTS_PER_PASS : int(cc_lightDir[0].w);\nfor (int i = 0; i < LIGHTS_PER_PASS; i++) {\nif (i >= numLights) break;\nvec3 SLU = cc_lightPos[i].xyz - position;\nvec3 SL = normalize(SLU);\nvec3 SH = normalize(SL + V);\nfloat SNL = max(dot(N, SL), 0.0);\nfloat SNH = max(dot(N, SH), 0.0);\nfloat distSqr = dot(SLU, SLU);\nfloat litRadius = cc_lightSizeRangeAngle[i].x;\nfloat litRadiusSqr = litRadius * litRadius;\nfloat illum = litRadiusSqr / max(litRadiusSqr, distSqr);\nfloat attRadiusSqrInv = 1.0 / max(cc_lightSizeRangeAngle[i].y, 0.01);\nattRadiusSqrInv *= attRadiusSqrInv;\nfloat att = GetDistAtt(distSqr, attRadiusSqrInv);\nvec3 lspec = specular * CalcSpecular(s.roughness, SNH, SH, N);\nif (cc_lightPos[i].w > 0.0) {\nfloat cosInner = max(dot(-cc_lightDir[i].xyz, SL), 0.01);\nfloat cosOuter = cc_lightSizeRangeAngle[i].z;\nfloat litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\nfloat litAngleOffset = -cosOuter * litAngleScale;\natt *= GetAngleAtt(SL, -cc_lightDir[i].xyz, litAngleScale, litAngleOffset);\n}\nvec3 lightColor = cc_lightColor[i].rgb;\nfloat shadow = 1.0;\n#if CC_RECEIVE_SHADOW\nif (cc_lightPos[i].w > 0.0 && cc_lightSizeRangeAngle[i].w > 0.0) {\nshadow = CCSpotShadowFactorBase(shadowPos, position, s.shadowBias);\n}\n#endif\nlightColor *= shadow;\nfinalColor += SNL * lightColor * cc_lightColor[i].w * illum * att * (diffuseContrib + lspec);\n}\nreturn vec4(finalColor, 0.0);\n}\n#endif\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 1\nlayout(std430, binding = 4) readonly buffer b_ccLightsBuffer { vec4 b_ccLights[]; };\nlayout(std430, binding = 5) readonly buffer b_clusterLightIndicesBuffer { uint b_clusterLightIndices[]; };\nlayout(std430, binding = 6) readonly buffer b_clusterLightGridBuffer { uvec4 b_clusterLightGrid[]; };\nstruct CCLight\n{\nvec4 cc_lightPos;\nvec4 cc_lightColor;\nvec4 cc_lightSizeRangeAngle;\nvec4 cc_lightDir;\n};\nstruct Cluster\n{\nvec3 minBounds;\nvec3 maxBounds;\n};\nstruct LightGrid\n{\nuint offset;\nuint ccLights;\n};\nCCLight getCCLight(uint i)\n{\nCCLight light;\nlight.cc_lightPos = b_ccLights[4u * i + 0u];\nlight.cc_lightColor = b_ccLights[4u * i + 1u];\nlight.cc_lightSizeRangeAngle = b_ccLights[4u * i + 2u];\nlight.cc_lightDir = b_ccLights[4u * i + 3u];\nreturn light;\n}\nLightGrid getLightGrid(uint cluster)\n{\nuvec4 gridvec = b_clusterLightGrid[cluster];\nLightGrid grid;\ngrid.offset = gridvec.x;\ngrid.ccLights = gridvec.y;\nreturn grid;\n}\nuint getGridLightIndex(uint start, uint offset)\n{\nreturn b_clusterLightIndices[start + offset];\n}\nuint getClusterZIndex(vec4 worldPos)\n{\nfloat scale = float(24) / log(cc_nearFar.y / cc_nearFar.x);\nfloat bias = -(float(24) * log(cc_nearFar.x) / log(cc_nearFar.y / cc_nearFar.x));\nfloat eyeDepth = -(cc_matView * worldPos).z;\nuint zIndex = uint(max(log(eyeDepth) * scale + bias, 0.0));\nreturn zIndex;\n}\nuint getClusterIndex(vec4 fragCoord, vec4 worldPos)\n{\nuint zIndex = getClusterZIndex(worldPos);\nfloat clusterSizeX = ceil(cc_viewPort.z / float(16));\nfloat clusterSizeY = ceil(cc_viewPort.w / float(8));\nuvec3 indices = uvec3(uvec2(fragCoord.xy / vec2(clusterSizeX, clusterSizeY)), zIndex);\nuint cluster = (16u * 8u) * indices.z + 16u * indices.y + indices.x;\nreturn cluster;\n}\nvec4 CCClusterShadingAdditive (StandardSurface s, vec4 shadowPos) {\nvec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\nvec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\nvec3 diffuseContrib = diffuse / PI;\nvec3 position;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nposition = unpackHighpData(s.position, s.position_fract_part);\n#else\nposition = s.position;\n#endif\nvec3 N = normalize(s.normal);\nvec3 V = normalize(cc_cameraPos.xyz - position);\nfloat NV = max(abs(dot(N, V)), 0.001);\nspecular = BRDFApprox(specular, s.roughness, NV);\nvec3 finalColor = vec3(0.0);\nuint cluster = getClusterIndex(gl_FragCoord, vec4(position, 1.0));\nLightGrid grid = getLightGrid(cluster);\nuint numLights = grid.ccLights;\nfor (uint i = 0u; i < 100u; i++) {\nif (i >= numLights) break;\nuint lightIndex = getGridLightIndex(grid.offset, i);\nCCLight light = getCCLight(lightIndex);\nvec3 SLU = light.cc_lightPos.xyz - position;\nvec3 SL = normalize(SLU);\nvec3 SH = normalize(SL + V);\nfloat SNL = max(dot(N, SL), 0.001);\nfloat SNH = max(dot(N, SH), 0.0);\nfloat distSqr = dot(SLU, SLU);\nfloat litRadius = light.cc_lightSizeRangeAngle.x;\nfloat litRadiusSqr = litRadius * litRadius;\nfloat illum = PI * (litRadiusSqr / max(litRadiusSqr , distSqr));\nfloat attRadiusSqrInv = 1.0 / max(light.cc_lightSizeRangeAngle.y, 0.01);\nattRadiusSqrInv *= attRadiusSqrInv;\nfloat att = GetDistAtt(distSqr, attRadiusSqrInv);\nvec3 lspec = specular * CalcSpecular(s.roughness, SNH, SH, N);\nif (light.cc_lightPos.w > 0.0) {\nfloat cosInner = max(dot(-light.cc_lightDir.xyz, SL), 0.01);\nfloat cosOuter = light.cc_lightSizeRangeAngle.z;\nfloat litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\nfloat litAngleOffset = -cosOuter * litAngleScale;\natt *= GetAngleAtt(SL, -light.cc_lightDir.xyz, litAngleScale, litAngleOffset);\n}\nvec3 lightColor = light.cc_lightColor.rgb;\nfloat shadow = 1.0;\n#if CC_RECEIVE_SHADOW\nif (light.cc_lightPos.w > 0.0) {\nshadow = CCSpotShadowFactorBase(shadowPos, position, s.shadowBias);\n}\n#endif\nlightColor *= shadow;\nfinalColor += SNL * lightColor * light.cc_lightColor.w * illum * att * (diffuseContrib + lspec);\n}\nreturn vec4(finalColor, 0.0);\n}\n#endif\nlayout(location = 0) out vec4 fragColorX;\nvoid main () {\nStandardSurface s; surf(s);\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 1\nvec4 color = CCClusterShadingAdditive(s, v_shadowPos);\n#else\nvec4 color = CCStandardShadingAdditive(s, v_shadowPos);\n#endif\nfragColorX = CCFragOutput(color);\n}\n#elif (CC_PIPELINE_TYPE == 0 || CC_FORCE_FORWARD_SHADING)\nlayout(location = 0) out vec4 fragColorX;\nvoid main () {\nStandardSurface s; surf(s);\nvec4 color = CCStandardShadingBase(s, v_shadowPos);\nCC_APPLY_FOG(color, s.position.xyz);\nfragColorX = CCFragOutput(color);\n}\n#elif CC_PIPELINE_TYPE == 1\nvec2 signNotZero(vec2 v) {\nreturn vec2((v.x >= 0.0) ? +1.0 : -1.0, (v.y >= 0.0) ? +1.0 : -1.0);\n}\nvec2 float32x3_to_oct(in vec3 v) {\nvec2 p = v.xy * (1.0 / (abs(v.x) + abs(v.y) + abs(v.z)));\nreturn (v.z <= 0.0) ? ((1.0 - abs(p.yx)) * signNotZero(p)) : p;\n}\nlayout(location = 0) out vec4 fragColor0;\nlayout(location = 1) out vec4 fragColor1;\nlayout(location = 2) out vec4 fragColor2;\nvoid main () {\nStandardSurface s; surf(s);\nfragColor0 = s.albedo;\nfragColor1 = vec4(float32x3_to_oct(s.normal), s.roughness, s.metallic);\nfragColor2 = vec4(s.emissive, s.occlusion);\n}\n#endif", + "vert": "\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\nrgba = rgba * 255.0;\nhighp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\nhighp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\nhighp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\nreturn Sign * exp2(Exponent - 23.0) * Mantissa;\n}\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nin vec3 a_position;\nin vec3 a_normal;\nin vec2 a_texCoord;\nin vec4 a_tangent;\n#if CC_USE_SKINNING\nin vec4 a_joints;\nin vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nin highp vec4 a_jointAnimInfo;\n#endif\nin vec4 a_matWorld0;\nin vec4 a_matWorld1;\nin vec4 a_matWorld2;\n#if CC_USE_LIGHTMAP\nin vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nin vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nin float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nin float a_vertexId;\nint getVertexId() {\nreturn int(a_vertexId);\n}\n#endif\n#if CC_USE_MORPH\nlayout(std140) uniform CCMorph {\nvec4 cc_displacementWeights[15];\nvec4 cc_displacementTextureInfo;\n};\nvec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\nfloat pixelIndexF = float(pixelIndex);\nfloat x = mod(pixelIndexF, textureResolution.x);\nfloat y = floor(pixelIndexF / textureResolution.x);\nreturn vec2(x, y);\n}\nvec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\nreturn (vec2(location.x, location.y) + .5) / textureResolution;\n}\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int pixelIndex) {\nivec2 texSize = textureSize(tex, 0);\nreturn texelFetch(tex, ivec2(pixelIndex % texSize.x, pixelIndex / texSize.x), 0);\n}\n#else\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex * 4;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\nreturn vec4(\ndecode32(texture(tex, x)),\ndecode32(texture(tex, y)),\ndecode32(texture(tex, z)),\n1.0\n);\n}\n#endif\nfloat getDisplacementWeight(int index) {\nint quot = index / 4;\nint remainder = index - quot * 4;\nif (remainder == 0) {\nreturn cc_displacementWeights[quot].x;\n} else if (remainder == 1) {\nreturn cc_displacementWeights[quot].y;\n} else if (remainder == 2) {\nreturn cc_displacementWeights[quot].z;\n} else {\nreturn cc_displacementWeights[quot].w;\n}\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\nreturn fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n#else\nvec3 result = vec3(0, 0, 0);\nint nVertices = int(cc_displacementTextureInfo.z);\nfor (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\nresult += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n}\nreturn result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\nuniform sampler2D cc_PositionDisplacements;\nvec3 getPositionDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nuniform sampler2D cc_NormalDisplacements;\nvec3 getNormalDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\nuniform sampler2D cc_TangentDisplacements;\nvec3 getTangentDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n}\n#endif\nvoid applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nint vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nnormal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\ntangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\n#if CC_USE_BAKED_ANIMATION\nlayout(std140) uniform CCSkinningTexture {\nhighp vec4 cc_jointTextureInfo;\n};\nlayout(std140) uniform CCSkinningAnimation {\nhighp vec4 cc_jointAnimInfo;\n};\nuniform highp sampler2D cc_jointTexture;\nvoid CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n{\n#if USE_INSTANCING\nhighp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n#else\nhighp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n#endif\ninvSize = cc_jointTextureInfo.w;\nhighp float tempY = floor(temp * invSize);\nx = floor(temp - tempY * cc_jointTextureInfo.x);\ny = (tempY + 0.5) * invSize;\n}\n#else\nlayout(std140) uniform CCSkinning {\nhighp vec4 cc_joints[30 * 3];\n};\n#endif\n#if CC_USE_BAKED_ANIMATION\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(3.0, i, x, y, invSize);\nvec4 v1 = texture(cc_jointTexture, vec2((x + 0.5) * invSize, y));\nvec4 v2 = texture(cc_jointTexture, vec2((x + 1.5) * invSize, y));\nvec4 v3 = texture(cc_jointTexture, vec2((x + 2.5) * invSize, y));\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#else\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(12.0, i, x, y, invSize);\nvec4 v1 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n);\nvec4 v2 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n);\nvec4 v3 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n);\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\n#else\nmat4 getJointMatrix (float i) {\nint idx = int(i);\nvec4 v1 = cc_joints[idx * 3];\nvec4 v2 = cc_joints[idx * 3 + 1];\nvec4 v3 = cc_joints[idx * 3 + 2];\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\nmat4 skinMatrix () {\nvec4 joints = vec4(a_joints);\nreturn getJointMatrix(joints.x) * a_weights.x\n+ getJointMatrix(joints.y) * a_weights.y\n+ getJointMatrix(joints.z) * a_weights.z\n+ getJointMatrix(joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\nmat4 m = skinMatrix();\nposition = m * position;\n}\nvoid CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nmat4 m = skinMatrix();\nposition = m * position;\nnormal = (m * vec4(normal, 0.0)).xyz;\ntangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n}\n#endif\nvoid CCVertInput(inout StandardVertInput In)\n{\nIn.position = vec4(a_position, 1.0);\nIn.normal = a_normal;\nIn.tangent = a_tangent;\n#if CC_USE_MORPH\napplyMorph(In.position, In.normal, In.tangent);\n#endif\n#if CC_USE_SKINNING\nCCSkin(In.position, In.normal, In.tangent);\n#endif\n}\nlayout(std140) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(std140) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\n#if !USE_INSTANCING\n#if USE_BATCHING\nlayout(std140) uniform CCLocalBatched {\nhighp mat4 cc_matWorlds[10];\n};\n#else\nlayout(std140) uniform CCLocal {\nhighp mat4 cc_matWorld;\nhighp mat4 cc_matWorldIT;\nhighp vec4 cc_lightingMapUVParam;\nhighp vec4 cc_localShadowBias;\n};\n#endif\n#endif\nvoid CCGetWorldMatrixFull(out mat4 matWorld, out mat4 matWorldIT)\n{\n#if USE_INSTANCING\nmatWorld = mat4(\nvec4(a_matWorld0.xyz, 0.0),\nvec4(a_matWorld1.xyz, 0.0),\nvec4(a_matWorld2.xyz, 0.0),\nvec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)\n);\nmatWorldIT = matWorld;\n#elif USE_BATCHING\nmatWorld = cc_matWorlds[int(a_dyn_batch_id)];\nmatWorldIT = matWorld;\n#else\nmatWorld = cc_matWorld;\nmatWorldIT = cc_matWorldIT;\n#endif\n}\nlayout(std140) uniform Constants {\nvec4 tilingOffset;\nvec4 albedo;\nvec4 albedoScaleAndCutoff;\nvec4 pbrParams;\nvec4 emissive;\nvec4 emissiveScaleParam;\n};\nfloat LinearFog(vec4 pos) {\nvec4 wPos = pos;\nfloat cam_dis = distance(cc_cameraPos, wPos);\nfloat fogStart = cc_fogBase.x;\nfloat fogEnd = cc_fogBase.y;\nreturn clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * fogDensity);\nreturn f;\n}\nfloat ExpSquaredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\nreturn f;\n}\nfloat LayeredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat _FogTop = cc_fogAdd.x;\nfloat _FogRange = cc_fogAdd.y;\nvec3 camWorldProj = cc_cameraPos.xyz;\ncamWorldProj.y = 0.;\nvec3 worldPosProj = wPos.xyz;\nworldPosProj.y = 0.;\nfloat fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\nfloat fDeltaY, fDensityIntegral;\nif (cc_cameraPos.y > _FogTop) {\nif (wPos.y < _FogTop) {\nfDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\nfDensityIntegral = fDeltaY * fDeltaY * 0.5;\n} else {\nfDeltaY = 0.;\nfDensityIntegral = 0.;\n}\n} else {\nif (wPos.y < _FogTop) {\nfloat fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfloat fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\nfDeltaY = abs(fDeltaA - fDeltaB);\nfDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n} else {\nfDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n}\n}\nfloat fDensity;\nif (fDeltaY != 0.) {\nfDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n} else {\nfDensity = 0.;\n}\nfloat f = exp(-fDensity);\nreturn f;\n}\nvoid CC_TRANSFER_FOG_BASE(vec4 pos, out float factor)\n{\n#if CC_USE_FOG == 0\nfactor = LinearFog(pos);\n#elif CC_USE_FOG == 1\nfactor = ExpFog(pos);\n#elif CC_USE_FOG == 2\nfactor = ExpSquaredFog(pos);\n#elif CC_USE_FOG == 3\nfactor = LayeredFog(pos);\n#else\nfactor = 1.0;\n#endif\n}\n#if !CC_USE_ACCURATE_FOG\nout float v_fog_factor;\n#endif\nvoid CC_TRANSFER_FOG(vec4 pos) {\n#if !CC_USE_ACCURATE_FOG\nCC_TRANSFER_FOG_BASE(pos, v_fog_factor);\n#endif\n}\nout highp vec4 v_shadowPos;\nlayout(std140) uniform CCShadow {\nhighp mat4 cc_matLightPlaneProj;\nhighp mat4 cc_matLightView;\nhighp mat4 cc_matLightViewProj;\nhighp vec4 cc_shadowInvProjDepthInfo;\nhighp vec4 cc_shadowProjDepthInfo;\nhighp vec4 cc_shadowProjInfo;\nmediump vec4 cc_shadowNFLSInfo;\nmediump vec4 cc_shadowWHPBInfo;\nmediump vec4 cc_shadowLPNNInfo;\nlowp vec4 cc_shadowColor;\nmediump vec4 cc_planarNDInfo;\n};\n#if CC_RECEIVE_SHADOW\nuniform highp sampler2D cc_shadowMap;\nuniform highp sampler2D cc_spotLightingMap;\n#endif\n#if CC_RECEIVE_SHADOW\nvec2 CCGetShadowBias()\n{\n#if USE_INSTANCING\nreturn vec2(a_localShadowBias.x + cc_shadowWHPBInfo.w, a_localShadowBias.y + cc_shadowLPNNInfo.z);\n#elif !USE_BATCHING\nreturn vec2(cc_localShadowBias.x + cc_shadowWHPBInfo.w, cc_localShadowBias.y + cc_shadowLPNNInfo.z);\n#else\nreturn vec2(cc_shadowWHPBInfo.w, cc_shadowLPNNInfo.z);\n#endif\n}\n#endif\n#if USE_VERTEX_COLOR\nin vec4 a_color;\nout lowp vec4 v_color;\n#endif\nout vec3 v_position;\nout mediump vec3 v_normal;\nout vec2 v_uv;\n#if HAS_SECOND_UV\nout mediump vec2 v_uv1;\n#endif\n#if CC_RECEIVE_SHADOW\nout mediump vec2 v_shadowBias;\n#endif\n#if USE_NORMAL_MAP\nout mediump vec4 v_tangent;\n#endif\n#if HAS_SECOND_UV || CC_USE_LIGHTMAP\nin vec2 a_texCoord1;\n#endif\n#if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\nout vec3 v_luv;\nvoid CCLightingMapCaclUV()\n{\n#if !USE_INSTANCING\nv_luv.xy = cc_lightingMapUVParam.xy + a_texCoord1 * cc_lightingMapUVParam.z;\nv_luv.z = cc_lightingMapUVParam.w;\n#else\nv_luv.xy = a_lightingMapUVParam.xy + a_texCoord1 * a_lightingMapUVParam.z;\nv_luv.z = a_lightingMapUVParam.w;\n#endif\n}\n#endif\nvoid main () {\nStandardVertInput In;\nCCVertInput(In);\nmat4 matWorld, matWorldIT;\nCCGetWorldMatrixFull(matWorld, matWorldIT);\nvec4 pos = matWorld * In.position;\nv_position = pos.xyz;\nv_normal = normalize((matWorldIT * vec4(In.normal, 0.0)).xyz);\n#if CC_RECEIVE_SHADOW\nv_shadowBias = CCGetShadowBias();\n#endif\n#if USE_TWOSIDE\nvec3 viewDirect = normalize(cc_cameraPos.xyz - v_position);\nv_normal *= dot(v_normal, viewDirect) < 0.0 ? -1.0 : 1.0;\n#endif\n#if USE_NORMAL_MAP\nv_tangent.xyz = normalize((matWorld * vec4(In.tangent.xyz, 0.0)).xyz);\nv_tangent.w = In.tangent.w;\n#endif\nv_uv = a_texCoord * tilingOffset.xy + tilingOffset.zw;\n#if SAMPLE_FROM_RT\nv_uv = cc_cameraPos.w > 1.0 ? vec2(v_uv.x, 1.0 - v_uv.y) : v_uv;\n#endif\n#if HAS_SECOND_UV\nv_uv1 = a_texCoord1 * tilingOffset.xy + tilingOffset.zw;\n#if SAMPLE_FROM_RT\nv_uv1 = cc_cameraPos.w > 1.0 ? vec2(v_uv1.x, 1.0 - v_uv1.y) : v_uv1;\n#endif\n#endif\n#if USE_VERTEX_COLOR\nv_color = a_color;\n#endif\nCC_TRANSFER_FOG(pos);\nv_shadowPos = cc_matLightViewProj * pos;\n#if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\nCCLightingMapCaclUV();\n#endif\ngl_Position = cc_matProj * (cc_matView * matWorld) * In.position;\n}", + "frag": "\nprecision highp float;\nlayout(std140) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(std140) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\nlayout(std140) uniform Constants {\nvec4 tilingOffset;\nvec4 albedo;\nvec4 albedoScaleAndCutoff;\nvec4 pbrParams;\nvec4 emissive;\nvec4 emissiveScaleParam;\n};\nfloat LinearFog(vec4 pos) {\nvec4 wPos = pos;\nfloat cam_dis = distance(cc_cameraPos, wPos);\nfloat fogStart = cc_fogBase.x;\nfloat fogEnd = cc_fogBase.y;\nreturn clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * fogDensity);\nreturn f;\n}\nfloat ExpSquaredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\nreturn f;\n}\nfloat LayeredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat _FogTop = cc_fogAdd.x;\nfloat _FogRange = cc_fogAdd.y;\nvec3 camWorldProj = cc_cameraPos.xyz;\ncamWorldProj.y = 0.;\nvec3 worldPosProj = wPos.xyz;\nworldPosProj.y = 0.;\nfloat fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\nfloat fDeltaY, fDensityIntegral;\nif (cc_cameraPos.y > _FogTop) {\nif (wPos.y < _FogTop) {\nfDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\nfDensityIntegral = fDeltaY * fDeltaY * 0.5;\n} else {\nfDeltaY = 0.;\nfDensityIntegral = 0.;\n}\n} else {\nif (wPos.y < _FogTop) {\nfloat fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfloat fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\nfDeltaY = abs(fDeltaA - fDeltaB);\nfDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n} else {\nfDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n}\n}\nfloat fDensity;\nif (fDeltaY != 0.) {\nfDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n} else {\nfDensity = 0.;\n}\nfloat f = exp(-fDensity);\nreturn f;\n}\nvoid CC_TRANSFER_FOG_BASE(vec4 pos, out float factor)\n{\n#if CC_USE_FOG == 0\nfactor = LinearFog(pos);\n#elif CC_USE_FOG == 1\nfactor = ExpFog(pos);\n#elif CC_USE_FOG == 2\nfactor = ExpSquaredFog(pos);\n#elif CC_USE_FOG == 3\nfactor = LayeredFog(pos);\n#else\nfactor = 1.0;\n#endif\n}\nvoid CC_APPLY_FOG_BASE(inout vec4 color, float factor) {\ncolor = vec4(mix(cc_fogColor.rgb, color.rgb, factor), color.a);\n}\n#if !CC_USE_ACCURATE_FOG\nin float v_fog_factor;\n#endif\nvoid CC_APPLY_FOG(inout vec4 color) {\n#if !CC_USE_ACCURATE_FOG\nCC_APPLY_FOG_BASE(color, v_fog_factor);\n#endif\n}\nvoid CC_APPLY_FOG(inout vec4 color, vec3 worldPos) {\n#if CC_USE_ACCURATE_FOG\nfloat factor;\nCC_TRANSFER_FOG_BASE(vec4(worldPos, 1.0), factor);\n#else\nfloat factor = v_fog_factor;\n#endif\nCC_APPLY_FOG_BASE(color, factor);\n}\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nvec3 SRGBToLinear (vec3 gamma) {\nreturn gamma * gamma;\n}\nlayout(std140) uniform CCShadow {\nhighp mat4 cc_matLightPlaneProj;\nhighp mat4 cc_matLightView;\nhighp mat4 cc_matLightViewProj;\nhighp vec4 cc_shadowInvProjDepthInfo;\nhighp vec4 cc_shadowProjDepthInfo;\nhighp vec4 cc_shadowProjInfo;\nmediump vec4 cc_shadowNFLSInfo;\nmediump vec4 cc_shadowWHPBInfo;\nmediump vec4 cc_shadowLPNNInfo;\nlowp vec4 cc_shadowColor;\nmediump vec4 cc_planarNDInfo;\n};\nhighp float unpackHighpData (float mainPart, float modPart) {\nhighp float data = mainPart;\nreturn data + modPart;\n}\nvoid packHighpData (out float mainPart, out float modPart, highp float data) {\nmainPart = fract(data);\nmodPart = data - mainPart;\n}\nhighp float unpackHighpData (float mainPart, float modPart, const float modValue) {\nhighp float data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nvoid packHighpData (out float mainPart, out float modPart, highp float data, const float modValue) {\nhighp float divide = data / modValue;\nmainPart = floor(divide);\nmodPart = (data - mainPart * modValue) / modValue;\n}\nhighp vec2 unpackHighpData (vec2 mainPart, vec2 modPart) {\nhighp vec2 data = mainPart;\nreturn data + modPart;\n}\nvoid packHighpData (out vec2 mainPart, out vec2 modPart, highp vec2 data) {\nmainPart = fract(data);\nmodPart = data - mainPart;\n}\nhighp vec2 unpackHighpData (vec2 mainPart, vec2 modPart, const float modValue) {\nhighp vec2 data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nvoid packHighpData (out vec2 mainPart, out vec2 modPart, highp vec2 data, const float modValue) {\nhighp vec2 divide = data / modValue;\nmainPart = floor(divide);\nmodPart = (data - mainPart * modValue) / modValue;\n}\nhighp vec3 unpackHighpData (vec3 mainPart, vec3 modPart) {\nhighp vec3 data = mainPart;\nreturn data + modPart;\n}\nvoid packHighpData (out vec3 mainPart, out vec3 modPart, highp vec3 data) {\nmainPart = fract(data);\nmodPart = data - mainPart;\n}\nhighp vec3 unpackHighpData (vec3 mainPart, vec3 modPart, const float modValue) {\nhighp vec3 data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nvoid packHighpData (out vec3 mainPart, out vec3 modPart, highp vec3 data, const float modValue) {\nhighp vec3 divide = data / modValue;\nmainPart = floor(divide);\nmodPart = (data - mainPart * modValue) / modValue;\n}\nhighp vec4 unpackHighpData (vec4 mainPart, vec4 modPart) {\nhighp vec4 data = mainPart;\nreturn data + modPart;\n}\nvoid packHighpData (out vec4 mainPart, out vec4 modPart, highp vec4 data) {\nmainPart = fract(data);\nmodPart = data - mainPart;\n}\nhighp vec4 unpackHighpData (vec4 mainPart, vec4 modPart, const float modValue) {\nhighp vec4 data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nvoid packHighpData (out vec4 mainPart, out vec4 modPart, highp vec4 data, const float modValue) {\nhighp vec4 divide = data / modValue;\nmainPart = floor(divide);\nmodPart = (data - mainPart * modValue) / modValue;\n}\nlayout(std140) uniform CCLocal {\nhighp mat4 cc_matWorld;\nhighp mat4 cc_matWorldIT;\nhighp vec4 cc_lightingMapUVParam;\nhighp vec4 cc_localShadowBias;\n};\nfloat CCGetLinearDepthFromViewSpace(vec3 viewPos) {\nfloat dist = length(viewPos);\nreturn (dist - cc_shadowNFLSInfo.x) / (cc_shadowNFLSInfo.y - cc_shadowNFLSInfo.x);\n}\nfloat CCGetLinearDepth(vec3 worldPos) {\nvec4 viewStartPos = cc_matLightView * vec4(worldPos.xyz, 1.0);\nreturn CCGetLinearDepthFromViewSpace(viewStartPos.xyz);\n}\n#if CC_RECEIVE_SHADOW\nuniform highp sampler2D cc_shadowMap;\nuniform highp sampler2D cc_spotLightingMap;\nvec4 ApplyShadowDepthBias_FaceNormal(vec4 shadowPos, vec3 worldNormal, float normalBias)\n{\nvec4 newShadowPos = shadowPos;\nif(normalBias > EPSILON_LOWP)\n{\nvec4 viewNormal = cc_matLightView * vec4(worldNormal, 0.0);\nif(viewNormal.z < 0.1)\nnewShadowPos.xy += viewNormal.xy * cc_shadowProjInfo.xy * normalBias * clamp(viewNormal.z, 0.001, 0.1);\n}\nreturn newShadowPos;\n}\nvec4 ApplyShadowDepthBias_Perspective(vec4 shadowPos, float viewspaceDepthBias)\n{\nvec3 viewSpacePos;\nviewSpacePos.xy = shadowPos.xy * cc_shadowProjInfo.zw;\nviewSpacePos.z = shadowPos.z * cc_shadowInvProjDepthInfo.x + shadowPos.w * cc_shadowInvProjDepthInfo.y;\nviewSpacePos.xyz += cc_shadowProjDepthInfo.z * normalize(viewSpacePos.xyz) * viewspaceDepthBias;\nvec4 clipSpacePos;\nclipSpacePos.xy = viewSpacePos.xy * cc_shadowProjInfo.xy;\nclipSpacePos.zw = viewSpacePos.z * cc_shadowProjDepthInfo.xz + vec2(cc_shadowProjDepthInfo.y, 0.0);\nif (cc_shadowNFLSInfo.z > EPSILON) {\nclipSpacePos.z = CCGetLinearDepthFromViewSpace(viewSpacePos.xyz);\nclipSpacePos.z = (clipSpacePos.z * 2.0 - 1.0) * clipSpacePos.w;\n}\nreturn clipSpacePos;\n}\nvec4 ApplyShadowDepthBias_Orthographic(vec4 shadowPos, float viewspaceDepthBias)\n{\nfloat coeffA = cc_shadowProjDepthInfo.x;\nfloat coeffB = cc_shadowProjDepthInfo.y;\nfloat viewSpacePos_z = (shadowPos.z - coeffB) / coeffA;\nviewSpacePos_z += viewspaceDepthBias;\nvec4 result = shadowPos;\nresult.z = viewSpacePos_z * coeffA + coeffB;\nreturn result;\n}\nfloat CCGetShadowFactorHard (vec4 shadowPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Orthographic(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat shadow = 0.0;\nfloat closestDepth = 0.0;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nclosestDepth = dot(texture(cc_shadowMap, clipPos.xy), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0));\n} else {\nclosestDepth = texture(cc_shadowMap, clipPos.xy).x;\n}\nshadow = step(clipPos.z, closestDepth);\nreturn shadow;\n}\nfloat CCGetShadowFactorSoft (vec4 shadowPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Orthographic(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat offsetDepth = clipPos.z;\nvec2 mapSize = cc_shadowWHPBInfo.xy;\nvec2 oneTap = 1.0 / mapSize;\nvec2 clipPos_offset = clipPos.xy + oneTap;\nfloat block0, block1, block2, block3;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos.y)).x);\nblock1 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset.x, clipPos.y)).x);\nblock2 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset.y)).x);\nblock3 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset.x, clipPos_offset.y)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * mapSize.x;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block2, block3, coefX);\nfloat coefY = mod(clipPos.y, oneTap.y) * mapSize.y;\nreturn mix(resultX, resultY, coefY);\n}\nfloat CCGetShadowFactorSoft2X (vec4 shadowPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Orthographic(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat offsetDepth = clipPos.z;\nvec2 mapSize = cc_shadowWHPBInfo.xy;\nvec2 oneTap = 1.0 / mapSize;\nfloat clipPos_offset_L = clipPos.x - oneTap.x;\nfloat clipPos_offset_R = clipPos.x + oneTap.x;\nfloat clipPos_offset_U = clipPos.y - oneTap.y;\nfloat clipPos_offset_D = clipPos.y + oneTap.y;\nfloat block0, block1, block2, block3, block4, block5, block6, block7, block8;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock4 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock5 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock6 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock7 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock8 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_U)).x);\nblock1 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset_U)).x);\nblock2 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_U)).x);\nblock3 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos.y)).x);\nblock4 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos.y)).x);\nblock5 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos.y)).x);\nblock6 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_D)).x);\nblock7 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset_D)).x);\nblock8 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_D)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * mapSize.x;\nfloat coefY = mod(clipPos.y, oneTap.y) * mapSize.y;\nfloat shadow = 0.0;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block3, block4, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block1, block2, coefX);\nresultY = mix(block4, block5, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block3, block4, coefX);\nresultY = mix(block6, block7, coefX);\nshadow += mix(resultX, resultY, coefY);\nresultX = mix(block4, block5, coefX);\nresultY = mix(block7, block8, coefX);\nshadow += mix(resultX, resultY, coefY);\nreturn shadow * 0.25;\n}\nfloat CCGetSpotLightShadowFactorHard (vec4 shadowPos, vec3 worldPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Perspective(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat shadow = 0.0;\nfloat closestDepth = 0.0;\nfloat depth = clipPos.z;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nclosestDepth = dot(texture(cc_spotLightingMap, clipPos.xy), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0));\n} else {\nclosestDepth = texture(cc_spotLightingMap, clipPos.xy).x;\n}\nshadow = step(depth, closestDepth);\nreturn shadow;\n}\nfloat CCGetSpotLightShadowFactorSoft (vec4 shadowPos, vec3 worldPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Perspective(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat depth = 0.0;\nif (cc_shadowNFLSInfo.z > EPSILON) {\ndepth = CCGetLinearDepth(worldPos);\n} else {\ndepth = clipPos.z;\n}\nvec2 oneTap = 1.0 / cc_shadowWHPBInfo.xy;\nvec2 clipPos_offset = clipPos.xy + oneTap;\nfloat block0, block1, block2, block3;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)).x);\nblock1 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos.y)).x);\nblock2 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset.y)).x);\nblock3 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos_offset.y)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * cc_shadowWHPBInfo.x;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block2, block3, coefX);\nfloat coefY = mod(clipPos.y, oneTap.y) * cc_shadowWHPBInfo.y;\nreturn mix(resultX, resultY, coefY);\n}\nfloat CCGetSpotLightShadowFactorSoft2X (vec4 shadowPos, vec3 worldPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Perspective(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat depth = 0.0;\nif (cc_shadowNFLSInfo.z > EPSILON) {\ndepth = CCGetLinearDepth(worldPos);\n} else {\ndepth = clipPos.z;\n}\nvec2 mapSize = cc_shadowWHPBInfo.xy;\nvec2 oneTap = 1.0 / mapSize;\nfloat clipPos_offset_L = clipPos.x - oneTap.x;\nfloat clipPos_offset_R = clipPos.x + oneTap.x;\nfloat clipPos_offset_U = clipPos.y - oneTap.y;\nfloat clipPos_offset_D = clipPos.y + oneTap.y;\nfloat block0, block1, block2, block3, block4, block5, block6, block7, block8;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock4 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock5 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock6 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock7 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock8 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_U)).x);\nblock1 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_U)).x);\nblock2 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_U)).x);\nblock3 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos.y)).x);\nblock4 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)).x);\nblock5 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos.y)).x);\nblock6 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_D)).x);\nblock7 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_D)).x);\nblock8 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_D)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * mapSize.x;\nfloat coefY = mod(clipPos.y, oneTap.y) * mapSize.y;\nfloat shadow = 0.0;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block3, block4, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block1, block2, coefX);\nresultY = mix(block4, block5, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block3, block4, coefX);\nresultY = mix(block6, block7, coefX);\nshadow += mix(resultX, resultY, coefY);\nresultX = mix(block4, block5, coefX);\nresultY = mix(block7, block8, coefX);\nshadow += mix(resultX, resultY, coefY);\nreturn shadow * 0.25;\n}\nfloat CCSpotShadowFactorBase(vec4 shadowPos, vec3 worldPos, vec2 shadowBias)\n{\nfloat pcf = cc_shadowWHPBInfo.z;\nif (pcf > 1.9) {\nreturn CCGetSpotLightShadowFactorSoft2X(shadowPos, worldPos, shadowBias.x);\n}else if (pcf > 0.9) {\nreturn CCGetSpotLightShadowFactorSoft(shadowPos, worldPos, shadowBias.x);\n}else {\nreturn CCGetSpotLightShadowFactorHard(shadowPos, worldPos, shadowBias.x);\n}\n}\nfloat CCShadowFactorBase(vec4 shadowPos, vec3 N, vec2 shadowBias)\n{\nfloat realtimeShadow = 1.0;\nvec4 pos = ApplyShadowDepthBias_FaceNormal(shadowPos, N, shadowBias.y);\nfloat pcf = cc_shadowWHPBInfo.z;\nif (pcf > 1.9) {\nrealtimeShadow = CCGetShadowFactorSoft2X(pos, shadowBias.x);\n}else if (pcf > 0.9) {\nrealtimeShadow = CCGetShadowFactorSoft(pos, shadowBias.x);\n}else {\nrealtimeShadow = CCGetShadowFactorHard(pos, shadowBias.x);\n}\nreturn mix(realtimeShadow, 1.0, cc_shadowNFLSInfo.w);\n}\n#endif\n#if CC_USE_IBL\nuniform samplerCube cc_environment;\nvec4 fragTextureLod (sampler2D tex, vec2 coord, float lod) {\nreturn textureLod(tex, coord, lod);\n}\nvec4 fragTextureLod (samplerCube tex, vec3 coord, float lod) {\nreturn textureLod(tex, coord, lod);\n}\nvec3 unpackRGBE (vec4 rgbe) {\nreturn rgbe.rgb * pow(1.1, rgbe.a * 255.0 - 128.0);\n}\n#if CC_USE_DIFFUSEMAP\nuniform samplerCube cc_diffuseMap;\n#endif\n#endif\nfloat GGXMobile (float roughness, float NoH, vec3 H, vec3 N) {\nvec3 NxH = cross(N, H);\nfloat OneMinusNoHSqr = dot(NxH, NxH);\nfloat a = roughness * roughness;\nfloat n = NoH * a;\nfloat p = a / (OneMinusNoHSqr + n * n);\nreturn p * p;\n}\nfloat CalcSpecular (float roughness, float NoH, vec3 H, vec3 N) {\nreturn (roughness * 0.25 + 0.25) * GGXMobile(roughness, NoH, H, N);\n}\nvec3 BRDFApprox (vec3 specular, float roughness, float NoV) {\nconst vec4 c0 = vec4(-1.0, -0.0275, -0.572, 0.022);\nconst vec4 c1 = vec4(1.0, 0.0425, 1.04, -0.04);\nvec4 r = roughness * c0 + c1;\nfloat a004 = min(r.x * r.x, exp2(-9.28 * NoV)) * r.x + r.y;\nvec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;\nAB.y *= clamp(50.0 * specular.g, 0.0, 1.0);\nreturn specular * AB.x + AB.y;\n}\n#if USE_REFLECTION_DENOISE\nvec3 GetEnvReflectionWithMipFiltering(vec3 R, float roughness, float mipCount, float denoiseIntensity) {\n#if CC_USE_IBL\nfloat mip = roughness * mipCount;\nfloat delta = (dot(dFdx(R), dFdy(R))) * 1000.0;\nfloat mipBias = mix(0.0, 5.0, clamp(delta, 0.0, 1.0));\nvec4 biased = fragTextureLod(cc_environment, R, mip + mipBias);\nvec4 filtered = texture(cc_environment, R);\n#if CC_USE_IBL == 2\nbiased.rgb = unpackRGBE(biased);\nfiltered.rgb = unpackRGBE(filtered);\n#else\nbiased.rgb = SRGBToLinear(biased.rgb);\nfiltered.rgb = SRGBToLinear(filtered.rgb);\n#endif\nreturn mix(biased.rgb, filtered.rgb, denoiseIntensity);\n#else\nreturn vec3(0.0, 0.0, 0.0);\n#endif\n}\n#endif\nstruct StandardSurface {\nvec4 albedo;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nvec3 position, position_fract_part;\n#else\nvec3 position;\n#endif\nvec3 normal;\nvec3 emissive;\nvec3 lightmap;\nfloat lightmap_test;\nfloat roughness;\nfloat metallic;\nfloat occlusion;\nfloat specularIntensity;\n#if CC_RECEIVE_SHADOW\nvec2 shadowBias;\n#endif\n};\nvec4 CCStandardShadingBase (StandardSurface s, vec4 shadowPos) {\nvec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\nvec3 specular = mix(vec3(0.08 * s.specularIntensity), s.albedo.rgb, s.metallic);\nvec3 position;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nposition = unpackHighpData(s.position, s.position_fract_part);\n#else\nposition = s.position;\n#endif\nvec3 N = normalize(s.normal);\nvec3 V = normalize(cc_cameraPos.xyz - position);\nfloat NV = max(abs(dot(N, V)), 0.0);\nspecular = BRDFApprox(specular, s.roughness, NV);\nvec3 L = normalize(-cc_mainLitDir.xyz);\nvec3 H = normalize(L + V);\nfloat NH = max(dot(N, H), 0.0);\nfloat NL = max(dot(N, L), 0.0);\nvec3 finalColor = NL * cc_mainLitColor.rgb * cc_mainLitColor.w;\nvec3 diffuseContrib = diffuse / PI;\nvec3 specularContrib = specular * CalcSpecular(s.roughness, NH, H, N);\nvec3 dirlightContrib = (diffuseContrib + specularContrib);\nfloat shadow = 1.0;\n#if CC_RECEIVE_SHADOW\nif (NL > 0.0 && cc_mainLitDir.w > 0.0) {\nshadow = CCShadowFactorBase(shadowPos, N, s.shadowBias);\n}\n#endif\ndirlightContrib *= shadow;\nfinalColor *= dirlightContrib;\n#if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\nif (s.lightmap_test > EPSILON_LOWP) {\nfinalColor = diffuse * s.lightmap.rgb * shadow;\n}\n#endif\nfloat fAmb = 0.5 - N.y * 0.5;\nvec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb);\n#if CC_USE_IBL\n#if CC_USE_DIFFUSEMAP\nvec4 diffuseMap = texture(cc_diffuseMap, N);\n#if CC_USE_DIFFUSEMAP == 2\nambDiff = unpackRGBE(diffuseMap);\n#else\nambDiff = SRGBToLinear(diffuseMap.rgb);\n#endif\n#endif\nvec3 R = normalize(reflect(-V, N));\n#if USE_REFLECTION_DENOISE\nvec3 env = GetEnvReflectionWithMipFiltering(R, s.roughness, cc_ambientGround.w, 0.6);\n#else\nvec4 envmap = fragTextureLod(cc_environment, R, s.roughness * cc_ambientGround.w);\n#if CC_USE_IBL == 2\nvec3 env = unpackRGBE(envmap);\n#else\nvec3 env = SRGBToLinear(envmap.rgb);\n#endif\n#endif\nfinalColor += env * cc_ambientSky.w * specular * s.occlusion;\n#endif\nfinalColor += ambDiff.rgb * cc_ambientSky.w * diffuse * s.occlusion;\nfinalColor += s.emissive;\nreturn vec4(finalColor, s.albedo.a);\n}\nvec3 ACESToneMap (vec3 color) {\ncolor = min(color, vec3(8.0));\nconst float A = 2.51;\nconst float B = 0.03;\nconst float C = 2.43;\nconst float D = 0.59;\nconst float E = 0.14;\nreturn (color * (A * color + B)) / (color * (C * color + D) + E);\n}\nvec4 CCFragOutput (vec4 color) {\n#if CC_USE_HDR\ncolor.rgb = ACESToneMap(color.rgb);\n#endif\ncolor.rgb = sqrt(color.rgb);\nreturn color;\n}\nin highp vec4 v_shadowPos;\n#if CC_RECEIVE_SHADOW\n#endif\n#if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\nin vec3 v_luv;\nuniform sampler2D cc_lightingMap;\n#endif\nin vec3 v_position;\nin vec2 v_uv;\n#if HAS_SECOND_UV\nin mediump vec2 v_uv1;\n#endif\nin mediump vec3 v_normal;\n#if CC_RECEIVE_SHADOW\nin mediump vec2 v_shadowBias;\n#endif\n#if USE_VERTEX_COLOR\nin lowp vec4 v_color;\n#endif\n#if USE_ALBEDO_MAP\nuniform sampler2D albedoMap;\n#endif\n#if USE_NORMAL_MAP\nin mediump vec4 v_tangent;\nuniform sampler2D normalMap;\n#endif\n#if USE_PBR_MAP\nuniform sampler2D pbrMap;\n#endif\n#if USE_METALLIC_ROUGHNESS_MAP\nuniform sampler2D metallicRoughnessMap;\n#endif\n#if USE_OCCLUSION_MAP\nuniform sampler2D occlusionMap;\n#endif\n#if USE_EMISSIVE_MAP\nuniform sampler2D emissiveMap;\n#endif\n#if USE_ALPHA_TEST\n#endif\nvoid surf (out StandardSurface s) {\nvec4 baseColor = albedo;\n#if USE_VERTEX_COLOR\nbaseColor.rgb *= SRGBToLinear(v_color.rgb);\nbaseColor.a *= v_color.a;\n#endif\n#if USE_ALBEDO_MAP\nvec4 texColor = texture(albedoMap, ALBEDO_UV);\ntexColor.rgb = SRGBToLinear(texColor.rgb);\nbaseColor *= texColor;\n#endif\ns.albedo = baseColor;\ns.albedo.rgb *= albedoScaleAndCutoff.xyz;\n#if USE_ALPHA_TEST\nif (s.albedo.ALPHA_TEST_CHANNEL < albedoScaleAndCutoff.w) discard;\n#endif\n#if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\nvec4 lightColor = texture(cc_lightingMap, v_luv.xy);\ns.lightmap = lightColor.xyz * v_luv.z;\ns.lightmap_test = v_luv.z;\n#endif\ns.normal = v_normal;\n#if CC_RECEIVE_SHADOW\ns.shadowBias = v_shadowBias;\n#endif\n#if USE_NORMAL_MAP\nvec3 nmmp = texture(normalMap, NORMAL_UV).xyz - vec3(0.5);\nvec3 bitangent = cross(v_normal, v_tangent.xyz) * v_tangent.w;\ns.normal =\n(nmmp.x * emissiveScaleParam.w) * normalize(v_tangent.xyz) +\n(nmmp.y * emissiveScaleParam.w) * normalize(bitangent) +\nnmmp.z * normalize(s.normal);\n#endif\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\npackHighpData(s.position, s.position_fract_part, v_position);\n#else\ns.position = v_position;\n#endif\nvec4 pbr = pbrParams;\n#if USE_PBR_MAP\nvec4 res = texture(pbrMap, PBR_UV);\npbr.x *= res.r;\npbr.y *= res.g;\npbr.z *= res.b;\npbr.w *= res.a;\n#endif\n#if USE_METALLIC_ROUGHNESS_MAP\nvec4 metallicRoughness = texture(metallicRoughnessMap, PBR_UV);\npbr.z *= metallicRoughness.b;\npbr.y *= metallicRoughness.g;\n#endif\n#if USE_OCCLUSION_MAP\npbr.x *= texture(occlusionMap, PBR_UV).r;\n#endif\ns.occlusion = pbr.x;\ns.roughness = pbr.y;\ns.specularIntensity = 0.5;\ns.metallic = pbr.z;\ns.emissive = emissive.rgb * emissiveScaleParam.xyz;\n#if USE_EMISSIVE_MAP\ns.emissive *= SRGBToLinear(texture(emissiveMap, EMISSIVE_UV).rgb);\n#endif\n}\n#if CC_FORWARD_ADD\n#if CC_PIPELINE_TYPE == 0\n#define LIGHTS_PER_PASS 1\n#else\n#define LIGHTS_PER_PASS 10\n#endif\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 0\nlayout(std140) uniform CCForwardLight {\nhighp vec4 cc_lightPos[LIGHTS_PER_PASS];\nvec4 cc_lightColor[LIGHTS_PER_PASS];\nvec4 cc_lightSizeRangeAngle[LIGHTS_PER_PASS];\nvec4 cc_lightDir[LIGHTS_PER_PASS];\n};\n#endif\nfloat SmoothDistAtt (float distSqr, float invSqrAttRadius) {\nfloat factor = distSqr * invSqrAttRadius;\nfloat smoothFactor = clamp(1.0 - factor * factor, 0.0, 1.0);\nreturn smoothFactor * smoothFactor;\n}\nfloat GetDistAtt (float distSqr, float invSqrAttRadius) {\nfloat attenuation = 1.0 / max(distSqr, 0.01*0.01);\nattenuation *= SmoothDistAtt(distSqr , invSqrAttRadius);\nreturn attenuation;\n}\nfloat GetAngleAtt (vec3 L, vec3 litDir, float litAngleScale, float litAngleOffset) {\nfloat cd = dot(litDir, L);\nfloat attenuation = clamp(cd * litAngleScale + litAngleOffset, 0.0, 1.0);\nreturn (attenuation * attenuation);\n}\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 0\nvec4 CCStandardShadingAdditive (StandardSurface s, vec4 shadowPos) {\nvec3 position;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nposition = unpackHighpData(s.position, s.position_fract_part);\n#else\nposition = s.position;\n#endif\nvec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\nvec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\nvec3 diffuseContrib = diffuse / PI;\nvec3 N = normalize(s.normal);\nvec3 V = normalize(cc_cameraPos.xyz - position);\nfloat NV = max(abs(dot(N, V)), 0.0);\nspecular = BRDFApprox(specular, s.roughness, NV);\nvec3 finalColor = vec3(0.0);\nint numLights = CC_PIPELINE_TYPE == 0 ? LIGHTS_PER_PASS : int(cc_lightDir[0].w);\nfor (int i = 0; i < LIGHTS_PER_PASS; i++) {\nif (i >= numLights) break;\nvec3 SLU = cc_lightPos[i].xyz - position;\nvec3 SL = normalize(SLU);\nvec3 SH = normalize(SL + V);\nfloat SNL = max(dot(N, SL), 0.0);\nfloat SNH = max(dot(N, SH), 0.0);\nfloat distSqr = dot(SLU, SLU);\nfloat litRadius = cc_lightSizeRangeAngle[i].x;\nfloat litRadiusSqr = litRadius * litRadius;\nfloat illum = litRadiusSqr / max(litRadiusSqr, distSqr);\nfloat attRadiusSqrInv = 1.0 / max(cc_lightSizeRangeAngle[i].y, 0.01);\nattRadiusSqrInv *= attRadiusSqrInv;\nfloat att = GetDistAtt(distSqr, attRadiusSqrInv);\nvec3 lspec = specular * CalcSpecular(s.roughness, SNH, SH, N);\nif (cc_lightPos[i].w > 0.0) {\nfloat cosInner = max(dot(-cc_lightDir[i].xyz, SL), 0.01);\nfloat cosOuter = cc_lightSizeRangeAngle[i].z;\nfloat litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\nfloat litAngleOffset = -cosOuter * litAngleScale;\natt *= GetAngleAtt(SL, -cc_lightDir[i].xyz, litAngleScale, litAngleOffset);\n}\nvec3 lightColor = cc_lightColor[i].rgb;\nfloat shadow = 1.0;\n#if CC_RECEIVE_SHADOW\nif (cc_lightPos[i].w > 0.0 && cc_lightSizeRangeAngle[i].w > 0.0) {\nshadow = CCSpotShadowFactorBase(shadowPos, position, s.shadowBias);\n}\n#endif\nlightColor *= shadow;\nfinalColor += SNL * lightColor * cc_lightColor[i].w * illum * att * (diffuseContrib + lspec);\n}\nreturn vec4(finalColor, 0.0);\n}\n#endif\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 1\nlayout(std430, binding = 4) readonly buffer b_ccLightsBuffer { vec4 b_ccLights[]; };\nlayout(std430, binding = 5) readonly buffer b_clusterLightIndicesBuffer { uint b_clusterLightIndices[]; };\nlayout(std430, binding = 6) readonly buffer b_clusterLightGridBuffer { uvec4 b_clusterLightGrid[]; };\nstruct CCLight\n{\nvec4 cc_lightPos;\nvec4 cc_lightColor;\nvec4 cc_lightSizeRangeAngle;\nvec4 cc_lightDir;\n};\nstruct Cluster\n{\nvec3 minBounds;\nvec3 maxBounds;\n};\nstruct LightGrid\n{\nuint offset;\nuint ccLights;\n};\nCCLight getCCLight(uint i)\n{\nCCLight light;\nlight.cc_lightPos = b_ccLights[4u * i + 0u];\nlight.cc_lightColor = b_ccLights[4u * i + 1u];\nlight.cc_lightSizeRangeAngle = b_ccLights[4u * i + 2u];\nlight.cc_lightDir = b_ccLights[4u * i + 3u];\nreturn light;\n}\nLightGrid getLightGrid(uint cluster)\n{\nuvec4 gridvec = b_clusterLightGrid[cluster];\nLightGrid grid;\ngrid.offset = gridvec.x;\ngrid.ccLights = gridvec.y;\nreturn grid;\n}\nuint getGridLightIndex(uint start, uint offset)\n{\nreturn b_clusterLightIndices[start + offset];\n}\nuint getClusterZIndex(vec4 worldPos)\n{\nfloat scale = float(24) / log(cc_nearFar.y / cc_nearFar.x);\nfloat bias = -(float(24) * log(cc_nearFar.x) / log(cc_nearFar.y / cc_nearFar.x));\nfloat eyeDepth = -(cc_matView * worldPos).z;\nuint zIndex = uint(max(log(eyeDepth) * scale + bias, 0.0));\nreturn zIndex;\n}\nuint getClusterIndex(vec4 fragCoord, vec4 worldPos)\n{\nuint zIndex = getClusterZIndex(worldPos);\nfloat clusterSizeX = ceil(cc_viewPort.z / float(16));\nfloat clusterSizeY = ceil(cc_viewPort.w / float(8));\nuvec3 indices = uvec3(uvec2(fragCoord.xy / vec2(clusterSizeX, clusterSizeY)), zIndex);\nuint cluster = (16u * 8u) * indices.z + 16u * indices.y + indices.x;\nreturn cluster;\n}\nvec4 CCClusterShadingAdditive (StandardSurface s, vec4 shadowPos) {\nvec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\nvec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\nvec3 diffuseContrib = diffuse / PI;\nvec3 position;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nposition = unpackHighpData(s.position, s.position_fract_part);\n#else\nposition = s.position;\n#endif\nvec3 N = normalize(s.normal);\nvec3 V = normalize(cc_cameraPos.xyz - position);\nfloat NV = max(abs(dot(N, V)), 0.001);\nspecular = BRDFApprox(specular, s.roughness, NV);\nvec3 finalColor = vec3(0.0);\nuint cluster = getClusterIndex(gl_FragCoord, vec4(position, 1.0));\nLightGrid grid = getLightGrid(cluster);\nuint numLights = grid.ccLights;\nfor (uint i = 0u; i < 100u; i++) {\nif (i >= numLights) break;\nuint lightIndex = getGridLightIndex(grid.offset, i);\nCCLight light = getCCLight(lightIndex);\nvec3 SLU = light.cc_lightPos.xyz - position;\nvec3 SL = normalize(SLU);\nvec3 SH = normalize(SL + V);\nfloat SNL = max(dot(N, SL), 0.001);\nfloat SNH = max(dot(N, SH), 0.0);\nfloat distSqr = dot(SLU, SLU);\nfloat litRadius = light.cc_lightSizeRangeAngle.x;\nfloat litRadiusSqr = litRadius * litRadius;\nfloat illum = PI * (litRadiusSqr / max(litRadiusSqr , distSqr));\nfloat attRadiusSqrInv = 1.0 / max(light.cc_lightSizeRangeAngle.y, 0.01);\nattRadiusSqrInv *= attRadiusSqrInv;\nfloat att = GetDistAtt(distSqr, attRadiusSqrInv);\nvec3 lspec = specular * CalcSpecular(s.roughness, SNH, SH, N);\nif (light.cc_lightPos.w > 0.0) {\nfloat cosInner = max(dot(-light.cc_lightDir.xyz, SL), 0.01);\nfloat cosOuter = light.cc_lightSizeRangeAngle.z;\nfloat litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\nfloat litAngleOffset = -cosOuter * litAngleScale;\natt *= GetAngleAtt(SL, -light.cc_lightDir.xyz, litAngleScale, litAngleOffset);\n}\nvec3 lightColor = light.cc_lightColor.rgb;\nfloat shadow = 1.0;\n#if CC_RECEIVE_SHADOW\nif (light.cc_lightPos.w > 0.0) {\nshadow = CCSpotShadowFactorBase(shadowPos, position, s.shadowBias);\n}\n#endif\nlightColor *= shadow;\nfinalColor += SNL * lightColor * light.cc_lightColor.w * illum * att * (diffuseContrib + lspec);\n}\nreturn vec4(finalColor, 0.0);\n}\n#endif\nlayout(location = 0) out vec4 fragColorX;\nvoid main () {\nStandardSurface s; surf(s);\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 1\nvec4 color = CCClusterShadingAdditive(s, v_shadowPos);\n#else\nvec4 color = CCStandardShadingAdditive(s, v_shadowPos);\n#endif\nfragColorX = CCFragOutput(color);\n}\n#elif (CC_PIPELINE_TYPE == 0 || CC_FORCE_FORWARD_SHADING)\nlayout(location = 0) out vec4 fragColorX;\nvoid main () {\nStandardSurface s; surf(s);\nvec4 color = CCStandardShadingBase(s, v_shadowPos);\nCC_APPLY_FOG(color, s.position.xyz);\nfragColorX = CCFragOutput(color);\n}\n#elif CC_PIPELINE_TYPE == 1\nvec2 signNotZero(vec2 v) {\nreturn vec2((v.x >= 0.0) ? +1.0 : -1.0, (v.y >= 0.0) ? +1.0 : -1.0);\n}\nvec2 float32x3_to_oct(in vec3 v) {\nvec2 p = v.xy * (1.0 / (abs(v.x) + abs(v.y) + abs(v.z)));\nreturn (v.z <= 0.0) ? ((1.0 - abs(p.yx)) * signNotZero(p)) : p;\n}\nlayout(location = 0) out vec4 fragColor0;\nlayout(location = 1) out vec4 fragColor1;\nlayout(location = 2) out vec4 fragColor2;\nvoid main () {\nStandardSurface s; surf(s);\nfragColor0 = s.albedo;\nfragColor1 = vec4(float32x3_to_oct(s.normal), s.roughness, s.metallic);\nfragColor2 = vec4(s.emissive, s.occlusion);\n}\n#endif", }, { - "vert": "\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\nrgba = rgba * 255.0;\nhighp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\nhighp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\nhighp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\nreturn Sign * exp2(Exponent - 23.0) * Mantissa;\n}\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nin vec3 a_position;\nin vec3 a_normal;\nin vec2 a_texCoord;\nin vec4 a_tangent;\n#if CC_USE_SKINNING\nin vec4 a_joints;\nin vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nin highp vec4 a_jointAnimInfo;\n#endif\nin vec4 a_matWorld0;\nin vec4 a_matWorld1;\nin vec4 a_matWorld2;\n#if USE_LIGHTMAP\nin vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nin vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nin float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nin float a_vertexId;\nint getVertexId() {\nreturn int(a_vertexId);\n}\n#endif\n#if CC_USE_MORPH\nlayout(std140) uniform CCMorph {\nvec4 cc_displacementWeights[15];\nvec4 cc_displacementTextureInfo;\n};\nvec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\nfloat pixelIndexF = float(pixelIndex);\nfloat x = mod(pixelIndexF, textureResolution.x);\nfloat y = floor(pixelIndexF / textureResolution.x);\nreturn vec2(x, y);\n}\nvec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\nreturn (vec2(location.x, location.y) + .5) / textureResolution;\n}\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int pixelIndex) {\nivec2 texSize = textureSize(tex, 0);\nreturn texelFetch(tex, ivec2(pixelIndex % texSize.x, pixelIndex / texSize.x), 0);\n}\n#else\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex * 4;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\nreturn vec4(\ndecode32(texture(tex, x)),\ndecode32(texture(tex, y)),\ndecode32(texture(tex, z)),\n1.0\n);\n}\n#endif\nfloat getDisplacementWeight(int index) {\nint quot = index / 4;\nint remainder = index - quot * 4;\nif (remainder == 0) {\nreturn cc_displacementWeights[quot].x;\n} else if (remainder == 1) {\nreturn cc_displacementWeights[quot].y;\n} else if (remainder == 2) {\nreturn cc_displacementWeights[quot].z;\n} else {\nreturn cc_displacementWeights[quot].w;\n}\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\nreturn fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n#else\nvec3 result = vec3(0, 0, 0);\nint nVertices = int(cc_displacementTextureInfo.z);\nfor (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\nresult += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n}\nreturn result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\nuniform sampler2D cc_PositionDisplacements;\nvec3 getPositionDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nuniform sampler2D cc_NormalDisplacements;\nvec3 getNormalDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\nuniform sampler2D cc_TangentDisplacements;\nvec3 getTangentDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n}\n#endif\nvoid applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nint vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nnormal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\ntangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\n#if CC_USE_BAKED_ANIMATION\nlayout(std140) uniform CCSkinningTexture {\nhighp vec4 cc_jointTextureInfo;\n};\nlayout(std140) uniform CCSkinningAnimation {\nhighp vec4 cc_jointAnimInfo;\n};\nuniform highp sampler2D cc_jointTexture;\nvoid CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n{\n#if USE_INSTANCING\nhighp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n#else\nhighp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n#endif\ninvSize = cc_jointTextureInfo.w;\nhighp float tempY = floor(temp * invSize);\nx = floor(temp - tempY * cc_jointTextureInfo.x);\ny = (tempY + 0.5) * invSize;\n}\n#else\nlayout(std140) uniform CCSkinning {\nhighp vec4 cc_joints[30 * 3];\n};\n#endif\n#if CC_USE_BAKED_ANIMATION\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(3.0, i, x, y, invSize);\nvec4 v1 = texture(cc_jointTexture, vec2((x + 0.5) * invSize, y));\nvec4 v2 = texture(cc_jointTexture, vec2((x + 1.5) * invSize, y));\nvec4 v3 = texture(cc_jointTexture, vec2((x + 2.5) * invSize, y));\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#else\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(12.0, i, x, y, invSize);\nvec4 v1 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n);\nvec4 v2 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n);\nvec4 v3 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n);\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\n#else\nmat4 getJointMatrix (float i) {\nint idx = int(i);\nvec4 v1 = cc_joints[idx * 3];\nvec4 v2 = cc_joints[idx * 3 + 1];\nvec4 v3 = cc_joints[idx * 3 + 2];\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\nmat4 skinMatrix () {\nvec4 joints = vec4(a_joints);\nreturn getJointMatrix(joints.x) * a_weights.x\n+ getJointMatrix(joints.y) * a_weights.y\n+ getJointMatrix(joints.z) * a_weights.z\n+ getJointMatrix(joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\nmat4 m = skinMatrix();\nposition = m * position;\n}\nvoid CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nmat4 m = skinMatrix();\nposition = m * position;\nnormal = (m * vec4(normal, 0.0)).xyz;\ntangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n}\n#endif\nvoid CCVertInput(inout StandardVertInput In)\n{\nIn.position = vec4(a_position, 1.0);\nIn.normal = a_normal;\nIn.tangent = a_tangent;\n#if CC_USE_MORPH\napplyMorph(In.position, In.normal, In.tangent);\n#endif\n#if CC_USE_SKINNING\nCCSkin(In.position, In.normal, In.tangent);\n#endif\n}\n#if !USE_INSTANCING\n#if USE_BATCHING\nlayout(std140) uniform CCLocalBatched {\nhighp mat4 cc_matWorlds[10];\n};\n#else\nlayout(std140) uniform CCLocal {\nhighp mat4 cc_matWorld;\nhighp mat4 cc_matWorldIT;\nhighp vec4 cc_lightingMapUVParam;\nhighp vec4 cc_localShadowBias;\n};\n#endif\n#endif\nvoid CCGetWorldMatrixFull(out mat4 matWorld, out mat4 matWorldIT)\n{\n#if USE_INSTANCING\nmatWorld = mat4(\nvec4(a_matWorld0.xyz, 0.0),\nvec4(a_matWorld1.xyz, 0.0),\nvec4(a_matWorld2.xyz, 0.0),\nvec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)\n);\nmatWorldIT = matWorld;\n#elif USE_BATCHING\nmatWorld = cc_matWorlds[int(a_dyn_batch_id)];\nmatWorldIT = matWorld;\n#else\nmatWorld = cc_matWorld;\nmatWorldIT = cc_matWorldIT;\n#endif\n}\nlayout(std140) uniform Constants {\nvec4 tilingOffset;\nvec4 albedo;\nvec4 albedoScaleAndCutoff;\nvec4 pbrParams;\nvec4 emissive;\nvec4 emissiveScaleParam;\n};\nlayout(std140) uniform CCShadow {\nhighp mat4 cc_matLightPlaneProj;\nhighp mat4 cc_matLightView;\nhighp mat4 cc_matLightViewProj;\nhighp vec4 cc_shadowInvProjDepthInfo;\nhighp vec4 cc_shadowProjDepthInfo;\nhighp vec4 cc_shadowProjInfo;\nmediump vec4 cc_shadowNFLSInfo;\nmediump vec4 cc_shadowWHPBInfo;\nmediump vec4 cc_shadowLPNNInfo;\nlowp vec4 cc_shadowColor;\nmediump vec4 cc_planarNDInfo;\n};\n#if HAS_SECOND_UV || USE_LIGHTMAP\nin vec2 a_texCoord1;\n#endif\nout vec2 v_uv;\n#if HAS_SECOND_UV\nout vec2 v_uv1;\n#endif\nout vec4 v_worldPos;\nout float v_clip_depth;\nvec4 vert () {\nStandardVertInput In;\nCCVertInput(In);\nmat4 matWorld, matWorldIT;\nCCGetWorldMatrixFull(matWorld, matWorldIT);\nv_worldPos = matWorld * In.position;\nvec4 clipPos = cc_matLightViewProj * v_worldPos;\nv_uv = a_texCoord * tilingOffset.xy + tilingOffset.zw;\n#if HAS_SECOND_UV\nv_uv1 = a_texCoord1 * tilingOffset.xy + tilingOffset.zw;\n#endif\nv_clip_depth = clipPos.z / clipPos.w * 0.5 + 0.5;\nreturn clipPos;\n}\nvoid main() { gl_Position = vert(); }", + "vert": "\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\nrgba = rgba * 255.0;\nhighp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\nhighp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\nhighp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\nreturn Sign * exp2(Exponent - 23.0) * Mantissa;\n}\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nin vec3 a_position;\nin vec3 a_normal;\nin vec2 a_texCoord;\nin vec4 a_tangent;\n#if CC_USE_SKINNING\nin vec4 a_joints;\nin vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nin highp vec4 a_jointAnimInfo;\n#endif\nin vec4 a_matWorld0;\nin vec4 a_matWorld1;\nin vec4 a_matWorld2;\n#if CC_USE_LIGHTMAP\nin vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nin vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nin float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nin float a_vertexId;\nint getVertexId() {\nreturn int(a_vertexId);\n}\n#endif\n#if CC_USE_MORPH\nlayout(std140) uniform CCMorph {\nvec4 cc_displacementWeights[15];\nvec4 cc_displacementTextureInfo;\n};\nvec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\nfloat pixelIndexF = float(pixelIndex);\nfloat x = mod(pixelIndexF, textureResolution.x);\nfloat y = floor(pixelIndexF / textureResolution.x);\nreturn vec2(x, y);\n}\nvec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\nreturn (vec2(location.x, location.y) + .5) / textureResolution;\n}\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int pixelIndex) {\nivec2 texSize = textureSize(tex, 0);\nreturn texelFetch(tex, ivec2(pixelIndex % texSize.x, pixelIndex / texSize.x), 0);\n}\n#else\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex * 4;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\nreturn vec4(\ndecode32(texture(tex, x)),\ndecode32(texture(tex, y)),\ndecode32(texture(tex, z)),\n1.0\n);\n}\n#endif\nfloat getDisplacementWeight(int index) {\nint quot = index / 4;\nint remainder = index - quot * 4;\nif (remainder == 0) {\nreturn cc_displacementWeights[quot].x;\n} else if (remainder == 1) {\nreturn cc_displacementWeights[quot].y;\n} else if (remainder == 2) {\nreturn cc_displacementWeights[quot].z;\n} else {\nreturn cc_displacementWeights[quot].w;\n}\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\nreturn fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n#else\nvec3 result = vec3(0, 0, 0);\nint nVertices = int(cc_displacementTextureInfo.z);\nfor (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\nresult += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n}\nreturn result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\nuniform sampler2D cc_PositionDisplacements;\nvec3 getPositionDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nuniform sampler2D cc_NormalDisplacements;\nvec3 getNormalDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\nuniform sampler2D cc_TangentDisplacements;\nvec3 getTangentDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n}\n#endif\nvoid applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nint vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nnormal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\ntangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\n#if CC_USE_BAKED_ANIMATION\nlayout(std140) uniform CCSkinningTexture {\nhighp vec4 cc_jointTextureInfo;\n};\nlayout(std140) uniform CCSkinningAnimation {\nhighp vec4 cc_jointAnimInfo;\n};\nuniform highp sampler2D cc_jointTexture;\nvoid CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n{\n#if USE_INSTANCING\nhighp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n#else\nhighp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n#endif\ninvSize = cc_jointTextureInfo.w;\nhighp float tempY = floor(temp * invSize);\nx = floor(temp - tempY * cc_jointTextureInfo.x);\ny = (tempY + 0.5) * invSize;\n}\n#else\nlayout(std140) uniform CCSkinning {\nhighp vec4 cc_joints[30 * 3];\n};\n#endif\n#if CC_USE_BAKED_ANIMATION\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(3.0, i, x, y, invSize);\nvec4 v1 = texture(cc_jointTexture, vec2((x + 0.5) * invSize, y));\nvec4 v2 = texture(cc_jointTexture, vec2((x + 1.5) * invSize, y));\nvec4 v3 = texture(cc_jointTexture, vec2((x + 2.5) * invSize, y));\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#else\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(12.0, i, x, y, invSize);\nvec4 v1 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n);\nvec4 v2 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n);\nvec4 v3 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n);\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\n#else\nmat4 getJointMatrix (float i) {\nint idx = int(i);\nvec4 v1 = cc_joints[idx * 3];\nvec4 v2 = cc_joints[idx * 3 + 1];\nvec4 v3 = cc_joints[idx * 3 + 2];\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\nmat4 skinMatrix () {\nvec4 joints = vec4(a_joints);\nreturn getJointMatrix(joints.x) * a_weights.x\n+ getJointMatrix(joints.y) * a_weights.y\n+ getJointMatrix(joints.z) * a_weights.z\n+ getJointMatrix(joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\nmat4 m = skinMatrix();\nposition = m * position;\n}\nvoid CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nmat4 m = skinMatrix();\nposition = m * position;\nnormal = (m * vec4(normal, 0.0)).xyz;\ntangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n}\n#endif\nvoid CCVertInput(inout StandardVertInput In)\n{\nIn.position = vec4(a_position, 1.0);\nIn.normal = a_normal;\nIn.tangent = a_tangent;\n#if CC_USE_MORPH\napplyMorph(In.position, In.normal, In.tangent);\n#endif\n#if CC_USE_SKINNING\nCCSkin(In.position, In.normal, In.tangent);\n#endif\n}\n#if !USE_INSTANCING\n#if USE_BATCHING\nlayout(std140) uniform CCLocalBatched {\nhighp mat4 cc_matWorlds[10];\n};\n#else\nlayout(std140) uniform CCLocal {\nhighp mat4 cc_matWorld;\nhighp mat4 cc_matWorldIT;\nhighp vec4 cc_lightingMapUVParam;\nhighp vec4 cc_localShadowBias;\n};\n#endif\n#endif\nvoid CCGetWorldMatrixFull(out mat4 matWorld, out mat4 matWorldIT)\n{\n#if USE_INSTANCING\nmatWorld = mat4(\nvec4(a_matWorld0.xyz, 0.0),\nvec4(a_matWorld1.xyz, 0.0),\nvec4(a_matWorld2.xyz, 0.0),\nvec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)\n);\nmatWorldIT = matWorld;\n#elif USE_BATCHING\nmatWorld = cc_matWorlds[int(a_dyn_batch_id)];\nmatWorldIT = matWorld;\n#else\nmatWorld = cc_matWorld;\nmatWorldIT = cc_matWorldIT;\n#endif\n}\nlayout(std140) uniform Constants {\nvec4 tilingOffset;\nvec4 albedo;\nvec4 albedoScaleAndCutoff;\nvec4 pbrParams;\nvec4 emissive;\nvec4 emissiveScaleParam;\n};\nlayout(std140) uniform CCShadow {\nhighp mat4 cc_matLightPlaneProj;\nhighp mat4 cc_matLightView;\nhighp mat4 cc_matLightViewProj;\nhighp vec4 cc_shadowInvProjDepthInfo;\nhighp vec4 cc_shadowProjDepthInfo;\nhighp vec4 cc_shadowProjInfo;\nmediump vec4 cc_shadowNFLSInfo;\nmediump vec4 cc_shadowWHPBInfo;\nmediump vec4 cc_shadowLPNNInfo;\nlowp vec4 cc_shadowColor;\nmediump vec4 cc_planarNDInfo;\n};\n#if HAS_SECOND_UV || CC_USE_LIGHTMAP\nin vec2 a_texCoord1;\n#endif\nout vec2 v_uv;\n#if HAS_SECOND_UV\nout vec2 v_uv1;\n#endif\nout vec4 v_worldPos;\nout float v_clip_depth;\nvec4 vert () {\nStandardVertInput In;\nCCVertInput(In);\nmat4 matWorld, matWorldIT;\nCCGetWorldMatrixFull(matWorld, matWorldIT);\nv_worldPos = matWorld * In.position;\nvec4 clipPos = cc_matLightViewProj * v_worldPos;\nv_uv = a_texCoord * tilingOffset.xy + tilingOffset.zw;\n#if HAS_SECOND_UV\nv_uv1 = a_texCoord1 * tilingOffset.xy + tilingOffset.zw;\n#endif\nv_clip_depth = clipPos.z / clipPos.w * 0.5 + 0.5;\nreturn clipPos;\n}\nvoid main() { gl_Position = vert(); }", "frag": "\nprecision highp float;\nlayout(std140) uniform Constants {\nvec4 tilingOffset;\nvec4 albedo;\nvec4 albedoScaleAndCutoff;\nvec4 pbrParams;\nvec4 emissive;\nvec4 emissiveScaleParam;\n};\nvec4 packDepthToRGBA (float depth) {\nvec4 ret = vec4(1.0, 255.0, 65025.0, 16581375.0) * depth;\nret = fract(ret);\nret -= vec4(ret.yzw, 0.0) / 255.0;\nreturn ret;\n}\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nlayout(std140) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(std140) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\nlayout(std140) uniform CCShadow {\nhighp mat4 cc_matLightPlaneProj;\nhighp mat4 cc_matLightView;\nhighp mat4 cc_matLightViewProj;\nhighp vec4 cc_shadowInvProjDepthInfo;\nhighp vec4 cc_shadowProjDepthInfo;\nhighp vec4 cc_shadowProjInfo;\nmediump vec4 cc_shadowNFLSInfo;\nmediump vec4 cc_shadowWHPBInfo;\nmediump vec4 cc_shadowLPNNInfo;\nlowp vec4 cc_shadowColor;\nmediump vec4 cc_planarNDInfo;\n};\nlayout(std140) uniform CCLocal {\nhighp mat4 cc_matWorld;\nhighp mat4 cc_matWorldIT;\nhighp vec4 cc_lightingMapUVParam;\nhighp vec4 cc_localShadowBias;\n};\nfloat CCGetLinearDepthFromViewSpace(vec3 viewPos) {\nfloat dist = length(viewPos);\nreturn (dist - cc_shadowNFLSInfo.x) / (cc_shadowNFLSInfo.y - cc_shadowNFLSInfo.x);\n}\nfloat CCGetLinearDepth(vec3 worldPos) {\nvec4 viewStartPos = cc_matLightView * vec4(worldPos.xyz, 1.0);\nreturn CCGetLinearDepthFromViewSpace(viewStartPos.xyz);\n}\n#if CC_RECEIVE_SHADOW\nuniform highp sampler2D cc_shadowMap;\nuniform highp sampler2D cc_spotLightingMap;\n#endif\nin vec2 v_uv;\n#if HAS_SECOND_UV\nin vec2 v_uv1;\n#endif\nin vec4 v_worldPos;\nin float v_clip_depth;\n#if USE_ALBEDO_MAP\nuniform sampler2D albedoMap;\n#endif\n#if USE_ALPHA_TEST\n#endif\nvec4 frag () {\nvec4 baseColor = albedo;\n#if USE_ALBEDO_MAP\nbaseColor *= texture(albedoMap, ALBEDO_UV);\n#endif\n#if USE_ALPHA_TEST\nif (baseColor.ALPHA_TEST_CHANNEL < albedoScaleAndCutoff.w) discard;\n#endif\nif(cc_shadowLPNNInfo.x > 0.000001 && cc_shadowLPNNInfo.x < 1.999999) {\nif (cc_shadowNFLSInfo.z > 0.000001) {\nreturn vec4(CCGetLinearDepth(v_worldPos.xyz), 1.0, 1.0, 1.0);\n}\n}\nif (cc_shadowLPNNInfo.y > 0.000001) {\nreturn packDepthToRGBA(v_clip_depth);\n}\nreturn vec4(v_clip_depth, 1.0, 1.0, 1.0);\n}\nlayout(location = 0) out vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }", } ], [ { - "vert": "\nprecision mediump float;\nlayout(std140) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(std140) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\nlayout(std140) uniform CCLocal {\nhighp mat4 cc_matWorld;\nhighp mat4 cc_matWorldIT;\nhighp vec4 cc_lightingMapUVParam;\nhighp vec4 cc_localShadowBias;\n};\nfloat LinearFog(vec4 pos) {\nvec4 wPos = pos;\nfloat cam_dis = distance(cc_cameraPos, wPos);\nfloat fogStart = cc_fogBase.x;\nfloat fogEnd = cc_fogBase.y;\nreturn clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * fogDensity);\nreturn f;\n}\nfloat ExpSquaredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\nreturn f;\n}\nfloat LayeredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat _FogTop = cc_fogAdd.x;\nfloat _FogRange = cc_fogAdd.y;\nvec3 camWorldProj = cc_cameraPos.xyz;\ncamWorldProj.y = 0.;\nvec3 worldPosProj = wPos.xyz;\nworldPosProj.y = 0.;\nfloat fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\nfloat fDeltaY, fDensityIntegral;\nif (cc_cameraPos.y > _FogTop) {\nif (wPos.y < _FogTop) {\nfDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\nfDensityIntegral = fDeltaY * fDeltaY * 0.5;\n} else {\nfDeltaY = 0.;\nfDensityIntegral = 0.;\n}\n} else {\nif (wPos.y < _FogTop) {\nfloat fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfloat fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\nfDeltaY = abs(fDeltaA - fDeltaB);\nfDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n} else {\nfDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n}\n}\nfloat fDensity;\nif (fDeltaY != 0.) {\nfDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n} else {\nfDensity = 0.;\n}\nfloat f = exp(-fDensity);\nreturn f;\n}\nvoid CC_TRANSFER_FOG_BASE(vec4 pos, out float factor)\n{\n#if CC_USE_FOG == 0\nfactor = LinearFog(pos);\n#elif CC_USE_FOG == 1\nfactor = ExpFog(pos);\n#elif CC_USE_FOG == 2\nfactor = ExpSquaredFog(pos);\n#elif CC_USE_FOG == 3\nfactor = LayeredFog(pos);\n#else\nfactor = 1.0;\n#endif\n}\n#if !CC_USE_ACCURATE_FOG\nout float v_fog_factor;\n#endif\nvoid CC_TRANSFER_FOG(vec4 pos) {\n#if !CC_USE_ACCURATE_FOG\nCC_TRANSFER_FOG_BASE(pos, v_fog_factor);\n#endif\n}\nout highp vec4 v_shadowPos;\nlayout(std140) uniform CCShadow {\nhighp mat4 cc_matLightPlaneProj;\nhighp mat4 cc_matLightView;\nhighp mat4 cc_matLightViewProj;\nhighp vec4 cc_shadowInvProjDepthInfo;\nhighp vec4 cc_shadowProjDepthInfo;\nhighp vec4 cc_shadowProjInfo;\nmediump vec4 cc_shadowNFLSInfo;\nmediump vec4 cc_shadowWHPBInfo;\nmediump vec4 cc_shadowLPNNInfo;\nlowp vec4 cc_shadowColor;\nmediump vec4 cc_planarNDInfo;\n};\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\n#if CC_RECEIVE_SHADOW\nuniform highp sampler2D cc_shadowMap;\nuniform highp sampler2D cc_spotLightingMap;\n#endif\n#if CC_RECEIVE_SHADOW\n#endif\nin vec3 a_position;\nin vec3 a_normal;\nin vec2 a_texCoord;\n#if CC_RECEIVE_SHADOW\nout vec2 v_shadowBias;\n#endif\nout highp vec3 v_position;\nout mediump vec3 v_normal;\nout mediump vec2 uvw;\nout mediump vec2 uv0;\nout mediump vec2 uv1;\nout mediump vec2 uv2;\nout mediump vec2 uv3;\nout mediump vec3 luv;\nout mediump vec3 diffuse;\nlayout(std140) uniform TexCoords {\nvec4 UVScale;\nvec4 lightMapUVParam;\n};\nvoid main () {\nvec3 worldPos;\nworldPos.x = cc_matWorld[3][0] + a_position.x;\nworldPos.y = cc_matWorld[3][1] + a_position.y;\nworldPos.z = cc_matWorld[3][2] + a_position.z;\nvec4 pos = vec4(worldPos, 1.0);\npos = cc_matViewProj * pos;\nuvw = a_texCoord;\nuv0 = a_position.xz * UVScale.x;\nuv1 = a_position.xz * UVScale.y;\nuv2 = a_position.xz * UVScale.z;\nuv3 = a_position.xz * UVScale.w;\n#if USE_LIGHTMAP\nluv.xy = lightMapUVParam.xy + a_texCoord * lightMapUVParam.z;\nluv.z = lightMapUVParam.w;\n#endif\nv_position = worldPos;\nv_normal = a_normal;\nCC_TRANSFER_FOG(vec4(worldPos, 1.0));\n#if CC_RECEIVE_SHADOW\nv_shadowBias = vec2(0.0, 0.0);\n#endif\nv_shadowPos = cc_matLightViewProj * vec4(worldPos, 1.0);\ngl_Position = pos;\n}", - "frag": "\nprecision highp float;\nlayout(std140) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(std140) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nvec3 SRGBToLinear (vec3 gamma) {\nreturn gamma * gamma;\n}\nlayout(std140) uniform CCShadow {\nhighp mat4 cc_matLightPlaneProj;\nhighp mat4 cc_matLightView;\nhighp mat4 cc_matLightViewProj;\nhighp vec4 cc_shadowInvProjDepthInfo;\nhighp vec4 cc_shadowProjDepthInfo;\nhighp vec4 cc_shadowProjInfo;\nmediump vec4 cc_shadowNFLSInfo;\nmediump vec4 cc_shadowWHPBInfo;\nmediump vec4 cc_shadowLPNNInfo;\nlowp vec4 cc_shadowColor;\nmediump vec4 cc_planarNDInfo;\n};\nhighp float unpackHighpData (float mainPart, float modPart) {\nhighp float data = mainPart;\nreturn data + modPart;\n}\nvoid packHighpData (out float mainPart, out float modPart, highp float data) {\nmainPart = fract(data);\nmodPart = data - mainPart;\n}\nhighp float unpackHighpData (float mainPart, float modPart, const float modValue) {\nhighp float data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nvoid packHighpData (out float mainPart, out float modPart, highp float data, const float modValue) {\nhighp float divide = data / modValue;\nmainPart = floor(divide);\nmodPart = (data - mainPart * modValue) / modValue;\n}\nhighp vec2 unpackHighpData (vec2 mainPart, vec2 modPart) {\nhighp vec2 data = mainPart;\nreturn data + modPart;\n}\nvoid packHighpData (out vec2 mainPart, out vec2 modPart, highp vec2 data) {\nmainPart = fract(data);\nmodPart = data - mainPart;\n}\nhighp vec2 unpackHighpData (vec2 mainPart, vec2 modPart, const float modValue) {\nhighp vec2 data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nvoid packHighpData (out vec2 mainPart, out vec2 modPart, highp vec2 data, const float modValue) {\nhighp vec2 divide = data / modValue;\nmainPart = floor(divide);\nmodPart = (data - mainPart * modValue) / modValue;\n}\nhighp vec3 unpackHighpData (vec3 mainPart, vec3 modPart) {\nhighp vec3 data = mainPart;\nreturn data + modPart;\n}\nvoid packHighpData (out vec3 mainPart, out vec3 modPart, highp vec3 data) {\nmainPart = fract(data);\nmodPart = data - mainPart;\n}\nhighp vec3 unpackHighpData (vec3 mainPart, vec3 modPart, const float modValue) {\nhighp vec3 data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nvoid packHighpData (out vec3 mainPart, out vec3 modPart, highp vec3 data, const float modValue) {\nhighp vec3 divide = data / modValue;\nmainPart = floor(divide);\nmodPart = (data - mainPart * modValue) / modValue;\n}\nhighp vec4 unpackHighpData (vec4 mainPart, vec4 modPart) {\nhighp vec4 data = mainPart;\nreturn data + modPart;\n}\nvoid packHighpData (out vec4 mainPart, out vec4 modPart, highp vec4 data) {\nmainPart = fract(data);\nmodPart = data - mainPart;\n}\nhighp vec4 unpackHighpData (vec4 mainPart, vec4 modPart, const float modValue) {\nhighp vec4 data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nvoid packHighpData (out vec4 mainPart, out vec4 modPart, highp vec4 data, const float modValue) {\nhighp vec4 divide = data / modValue;\nmainPart = floor(divide);\nmodPart = (data - mainPart * modValue) / modValue;\n}\nlayout(std140) uniform CCLocal {\nhighp mat4 cc_matWorld;\nhighp mat4 cc_matWorldIT;\nhighp vec4 cc_lightingMapUVParam;\nhighp vec4 cc_localShadowBias;\n};\nfloat CCGetLinearDepthFromViewSpace(vec3 viewPos) {\nfloat dist = length(viewPos);\nreturn (dist - cc_shadowNFLSInfo.x) / (cc_shadowNFLSInfo.y - cc_shadowNFLSInfo.x);\n}\nfloat CCGetLinearDepth(vec3 worldPos) {\nvec4 viewStartPos = cc_matLightView * vec4(worldPos.xyz, 1.0);\nreturn CCGetLinearDepthFromViewSpace(viewStartPos.xyz);\n}\n#if CC_RECEIVE_SHADOW\nuniform highp sampler2D cc_shadowMap;\nuniform highp sampler2D cc_spotLightingMap;\nvec4 ApplyShadowDepthBias_FaceNormal(vec4 shadowPos, vec3 worldNormal, float normalBias)\n{\nvec4 newShadowPos = shadowPos;\nif(normalBias > EPSILON_LOWP)\n{\nvec4 viewNormal = cc_matLightView * vec4(worldNormal, 0.0);\nif(viewNormal.z < 0.1)\nnewShadowPos.xy += viewNormal.xy * cc_shadowProjInfo.xy * normalBias * clamp(viewNormal.z, 0.001, 0.1);\n}\nreturn newShadowPos;\n}\nvec4 ApplyShadowDepthBias_Perspective(vec4 shadowPos, float viewspaceDepthBias)\n{\nvec3 viewSpacePos;\nviewSpacePos.xy = shadowPos.xy * cc_shadowProjInfo.zw;\nviewSpacePos.z = shadowPos.z * cc_shadowInvProjDepthInfo.x + shadowPos.w * cc_shadowInvProjDepthInfo.y;\nviewSpacePos.xyz += cc_shadowProjDepthInfo.z * normalize(viewSpacePos.xyz) * viewspaceDepthBias;\nvec4 clipSpacePos;\nclipSpacePos.xy = viewSpacePos.xy * cc_shadowProjInfo.xy;\nclipSpacePos.zw = viewSpacePos.z * cc_shadowProjDepthInfo.xz + vec2(cc_shadowProjDepthInfo.y, 0.0);\nif (cc_shadowNFLSInfo.z > EPSILON) {\nclipSpacePos.z = CCGetLinearDepthFromViewSpace(viewSpacePos.xyz);\nclipSpacePos.z = (clipSpacePos.z * 2.0 - 1.0) * clipSpacePos.w;\n}\nreturn clipSpacePos;\n}\nvec4 ApplyShadowDepthBias_Orthographic(vec4 shadowPos, float viewspaceDepthBias)\n{\nfloat coeffA = cc_shadowProjDepthInfo.x;\nfloat coeffB = cc_shadowProjDepthInfo.y;\nfloat viewSpacePos_z = (shadowPos.z - coeffB) / coeffA;\nviewSpacePos_z += viewspaceDepthBias;\nvec4 result = shadowPos;\nresult.z = viewSpacePos_z * coeffA + coeffB;\nreturn result;\n}\nfloat CCGetShadowFactorHard (vec4 shadowPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Orthographic(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat shadow = 0.0;\nfloat closestDepth = 0.0;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nclosestDepth = dot(texture(cc_shadowMap, clipPos.xy), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0));\n} else {\nclosestDepth = texture(cc_shadowMap, clipPos.xy).x;\n}\nshadow = step(clipPos.z, closestDepth);\nreturn shadow;\n}\nfloat CCGetShadowFactorSoft (vec4 shadowPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Orthographic(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat offsetDepth = clipPos.z;\nvec2 mapSize = cc_shadowWHPBInfo.xy;\nvec2 oneTap = 1.0 / mapSize;\nvec2 clipPos_offset = clipPos.xy + oneTap;\nfloat block0, block1, block2, block3;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos.y)).x);\nblock1 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset.x, clipPos.y)).x);\nblock2 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset.y)).x);\nblock3 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset.x, clipPos_offset.y)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * mapSize.x;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block2, block3, coefX);\nfloat coefY = mod(clipPos.y, oneTap.y) * mapSize.y;\nreturn mix(resultX, resultY, coefY);\n}\nfloat CCGetShadowFactorSoft2X (vec4 shadowPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Orthographic(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat offsetDepth = clipPos.z;\nvec2 mapSize = cc_shadowWHPBInfo.xy;\nvec2 oneTap = 1.0 / mapSize;\nfloat clipPos_offset_L = clipPos.x - oneTap.x;\nfloat clipPos_offset_R = clipPos.x + oneTap.x;\nfloat clipPos_offset_U = clipPos.y - oneTap.y;\nfloat clipPos_offset_D = clipPos.y + oneTap.y;\nfloat block0, block1, block2, block3, block4, block5, block6, block7, block8;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock4 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock5 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock6 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock7 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock8 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_U)).x);\nblock1 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset_U)).x);\nblock2 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_U)).x);\nblock3 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos.y)).x);\nblock4 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos.y)).x);\nblock5 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos.y)).x);\nblock6 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_D)).x);\nblock7 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset_D)).x);\nblock8 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_D)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * mapSize.x;\nfloat coefY = mod(clipPos.y, oneTap.y) * mapSize.y;\nfloat shadow = 0.0;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block3, block4, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block1, block2, coefX);\nresultY = mix(block4, block5, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block3, block4, coefX);\nresultY = mix(block6, block7, coefX);\nshadow += mix(resultX, resultY, coefY);\nresultX = mix(block4, block5, coefX);\nresultY = mix(block7, block8, coefX);\nshadow += mix(resultX, resultY, coefY);\nreturn shadow * 0.25;\n}\nfloat CCGetSpotLightShadowFactorHard (vec4 shadowPos, vec3 worldPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Perspective(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat shadow = 0.0;\nfloat closestDepth = 0.0;\nfloat depth = clipPos.z;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nclosestDepth = dot(texture(cc_spotLightingMap, clipPos.xy), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0));\n} else {\nclosestDepth = texture(cc_spotLightingMap, clipPos.xy).x;\n}\nshadow = step(depth, closestDepth);\nreturn shadow;\n}\nfloat CCGetSpotLightShadowFactorSoft (vec4 shadowPos, vec3 worldPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Perspective(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat depth = 0.0;\nif (cc_shadowNFLSInfo.z > EPSILON) {\ndepth = CCGetLinearDepth(worldPos);\n} else {\ndepth = clipPos.z;\n}\nvec2 oneTap = 1.0 / cc_shadowWHPBInfo.xy;\nvec2 clipPos_offset = clipPos.xy + oneTap;\nfloat block0, block1, block2, block3;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)).x);\nblock1 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos.y)).x);\nblock2 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset.y)).x);\nblock3 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos_offset.y)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * cc_shadowWHPBInfo.x;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block2, block3, coefX);\nfloat coefY = mod(clipPos.y, oneTap.y) * cc_shadowWHPBInfo.y;\nreturn mix(resultX, resultY, coefY);\n}\nfloat CCGetSpotLightShadowFactorSoft2X (vec4 shadowPos, vec3 worldPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Perspective(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat depth = 0.0;\nif (cc_shadowNFLSInfo.z > EPSILON) {\ndepth = CCGetLinearDepth(worldPos);\n} else {\ndepth = clipPos.z;\n}\nvec2 mapSize = cc_shadowWHPBInfo.xy;\nvec2 oneTap = 1.0 / mapSize;\nfloat clipPos_offset_L = clipPos.x - oneTap.x;\nfloat clipPos_offset_R = clipPos.x + oneTap.x;\nfloat clipPos_offset_U = clipPos.y - oneTap.y;\nfloat clipPos_offset_D = clipPos.y + oneTap.y;\nfloat block0, block1, block2, block3, block4, block5, block6, block7, block8;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock4 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock5 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock6 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock7 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock8 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_U)).x);\nblock1 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_U)).x);\nblock2 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_U)).x);\nblock3 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos.y)).x);\nblock4 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)).x);\nblock5 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos.y)).x);\nblock6 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_D)).x);\nblock7 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_D)).x);\nblock8 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_D)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * mapSize.x;\nfloat coefY = mod(clipPos.y, oneTap.y) * mapSize.y;\nfloat shadow = 0.0;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block3, block4, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block1, block2, coefX);\nresultY = mix(block4, block5, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block3, block4, coefX);\nresultY = mix(block6, block7, coefX);\nshadow += mix(resultX, resultY, coefY);\nresultX = mix(block4, block5, coefX);\nresultY = mix(block7, block8, coefX);\nshadow += mix(resultX, resultY, coefY);\nreturn shadow * 0.25;\n}\nfloat CCSpotShadowFactorBase(vec4 shadowPos, vec3 worldPos, vec2 shadowBias)\n{\nfloat pcf = cc_shadowWHPBInfo.z;\nif (pcf > 1.9) {\nreturn CCGetSpotLightShadowFactorSoft2X(shadowPos, worldPos, shadowBias.x);\n}else if (pcf > 0.9) {\nreturn CCGetSpotLightShadowFactorSoft(shadowPos, worldPos, shadowBias.x);\n}else {\nreturn CCGetSpotLightShadowFactorHard(shadowPos, worldPos, shadowBias.x);\n}\n}\nfloat CCShadowFactorBase(vec4 shadowPos, vec3 N, vec2 shadowBias)\n{\nfloat realtimeShadow = 1.0;\nvec4 pos = ApplyShadowDepthBias_FaceNormal(shadowPos, N, shadowBias.y);\nfloat pcf = cc_shadowWHPBInfo.z;\nif (pcf > 1.9) {\nrealtimeShadow = CCGetShadowFactorSoft2X(pos, shadowBias.x);\n}else if (pcf > 0.9) {\nrealtimeShadow = CCGetShadowFactorSoft(pos, shadowBias.x);\n}else {\nrealtimeShadow = CCGetShadowFactorHard(pos, shadowBias.x);\n}\nreturn mix(realtimeShadow, 1.0, cc_shadowNFLSInfo.w);\n}\n#endif\n#if CC_USE_IBL\nuniform samplerCube cc_environment;\nvec4 fragTextureLod (sampler2D tex, vec2 coord, float lod) {\nreturn textureLod(tex, coord, lod);\n}\nvec4 fragTextureLod (samplerCube tex, vec3 coord, float lod) {\nreturn textureLod(tex, coord, lod);\n}\nvec3 unpackRGBE (vec4 rgbe) {\nreturn rgbe.rgb * pow(1.1, rgbe.a * 255.0 - 128.0);\n}\n#if CC_USE_DIFFUSEMAP\nuniform samplerCube cc_diffuseMap;\n#endif\n#endif\nfloat GGXMobile (float roughness, float NoH, vec3 H, vec3 N) {\nvec3 NxH = cross(N, H);\nfloat OneMinusNoHSqr = dot(NxH, NxH);\nfloat a = roughness * roughness;\nfloat n = NoH * a;\nfloat p = a / (OneMinusNoHSqr + n * n);\nreturn p * p;\n}\nfloat CalcSpecular (float roughness, float NoH, vec3 H, vec3 N) {\nreturn (roughness * 0.25 + 0.25) * GGXMobile(roughness, NoH, H, N);\n}\nvec3 BRDFApprox (vec3 specular, float roughness, float NoV) {\nconst vec4 c0 = vec4(-1.0, -0.0275, -0.572, 0.022);\nconst vec4 c1 = vec4(1.0, 0.0425, 1.04, -0.04);\nvec4 r = roughness * c0 + c1;\nfloat a004 = min(r.x * r.x, exp2(-9.28 * NoV)) * r.x + r.y;\nvec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;\nAB.y *= clamp(50.0 * specular.g, 0.0, 1.0);\nreturn specular * AB.x + AB.y;\n}\n#if USE_REFLECTION_DENOISE\nvec3 GetEnvReflectionWithMipFiltering(vec3 R, float roughness, float mipCount, float denoiseIntensity) {\n#if CC_USE_IBL\nfloat mip = roughness * mipCount;\nfloat delta = (dot(dFdx(R), dFdy(R))) * 1000.0;\nfloat mipBias = mix(0.0, 5.0, clamp(delta, 0.0, 1.0));\nvec4 biased = fragTextureLod(cc_environment, R, mip + mipBias);\nvec4 filtered = texture(cc_environment, R);\n#if CC_USE_IBL == 2\nbiased.rgb = unpackRGBE(biased);\nfiltered.rgb = unpackRGBE(filtered);\n#else\nbiased.rgb = SRGBToLinear(biased.rgb);\nfiltered.rgb = SRGBToLinear(filtered.rgb);\n#endif\nreturn mix(biased.rgb, filtered.rgb, denoiseIntensity);\n#else\nreturn vec3(0.0, 0.0, 0.0);\n#endif\n}\n#endif\nstruct StandardSurface {\nvec4 albedo;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nvec3 position, position_fract_part;\n#else\nvec3 position;\n#endif\nvec3 normal;\nvec3 emissive;\nvec3 lightmap;\nfloat lightmap_test;\nfloat roughness;\nfloat metallic;\nfloat occlusion;\nfloat specularIntensity;\n#if CC_RECEIVE_SHADOW\nvec2 shadowBias;\n#endif\n};\nvec4 CCStandardShadingBase (StandardSurface s, vec4 shadowPos) {\nvec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\nvec3 specular = mix(vec3(0.08 * s.specularIntensity), s.albedo.rgb, s.metallic);\nvec3 position;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nposition = unpackHighpData(s.position, s.position_fract_part);\n#else\nposition = s.position;\n#endif\nvec3 N = normalize(s.normal);\nvec3 V = normalize(cc_cameraPos.xyz - position);\nfloat NV = max(abs(dot(N, V)), 0.0);\nspecular = BRDFApprox(specular, s.roughness, NV);\nvec3 L = normalize(-cc_mainLitDir.xyz);\nvec3 H = normalize(L + V);\nfloat NH = max(dot(N, H), 0.0);\nfloat NL = max(dot(N, L), 0.0);\nvec3 finalColor = NL * cc_mainLitColor.rgb * cc_mainLitColor.w;\nvec3 diffuseContrib = diffuse / PI;\nvec3 specularContrib = specular * CalcSpecular(s.roughness, NH, H, N);\nvec3 dirlightContrib = (diffuseContrib + specularContrib);\nfloat shadow = 1.0;\n#if CC_RECEIVE_SHADOW\nif (NL > 0.0 && cc_mainLitDir.w > 0.0) {\nshadow = CCShadowFactorBase(shadowPos, N, s.shadowBias);\n}\n#endif\ndirlightContrib *= shadow;\nfinalColor *= dirlightContrib;\n#if USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\nif (s.lightmap_test > EPSILON_LOWP) {\nfinalColor = diffuse * s.lightmap.rgb * shadow;\n}\n#endif\nfloat fAmb = 0.5 - N.y * 0.5;\nvec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb);\n#if CC_USE_IBL\n#if CC_USE_DIFFUSEMAP\nvec4 diffuseMap = texture(cc_diffuseMap, N);\n#if CC_USE_DIFFUSEMAP == 2\nambDiff = unpackRGBE(diffuseMap);\n#else\nambDiff = SRGBToLinear(diffuseMap.rgb);\n#endif\n#endif\nvec3 R = normalize(reflect(-V, N));\n#if USE_REFLECTION_DENOISE\nvec3 env = GetEnvReflectionWithMipFiltering(R, s.roughness, cc_ambientGround.w, 0.6);\n#else\nvec4 envmap = fragTextureLod(cc_environment, R, s.roughness * cc_ambientGround.w);\n#if CC_USE_IBL == 2\nvec3 env = unpackRGBE(envmap);\n#else\nvec3 env = SRGBToLinear(envmap.rgb);\n#endif\n#endif\nfinalColor += env * cc_ambientSky.w * specular * s.occlusion;\n#endif\nfinalColor += ambDiff.rgb * cc_ambientSky.w * diffuse * s.occlusion;\nfinalColor += s.emissive;\nreturn vec4(finalColor, s.albedo.a);\n}\nvec3 ACESToneMap (vec3 color) {\ncolor = min(color, vec3(8.0));\nconst float A = 2.51;\nconst float B = 0.03;\nconst float C = 2.43;\nconst float D = 0.59;\nconst float E = 0.14;\nreturn (color * (A * color + B)) / (color * (C * color + D) + E);\n}\nvec4 CCFragOutput (vec4 color) {\n#if CC_USE_HDR\ncolor.rgb = ACESToneMap(color.rgb);\n#endif\ncolor.rgb = sqrt(color.rgb);\nreturn color;\n}\nfloat LinearFog(vec4 pos) {\nvec4 wPos = pos;\nfloat cam_dis = distance(cc_cameraPos, wPos);\nfloat fogStart = cc_fogBase.x;\nfloat fogEnd = cc_fogBase.y;\nreturn clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * fogDensity);\nreturn f;\n}\nfloat ExpSquaredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\nreturn f;\n}\nfloat LayeredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat _FogTop = cc_fogAdd.x;\nfloat _FogRange = cc_fogAdd.y;\nvec3 camWorldProj = cc_cameraPos.xyz;\ncamWorldProj.y = 0.;\nvec3 worldPosProj = wPos.xyz;\nworldPosProj.y = 0.;\nfloat fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\nfloat fDeltaY, fDensityIntegral;\nif (cc_cameraPos.y > _FogTop) {\nif (wPos.y < _FogTop) {\nfDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\nfDensityIntegral = fDeltaY * fDeltaY * 0.5;\n} else {\nfDeltaY = 0.;\nfDensityIntegral = 0.;\n}\n} else {\nif (wPos.y < _FogTop) {\nfloat fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfloat fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\nfDeltaY = abs(fDeltaA - fDeltaB);\nfDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n} else {\nfDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n}\n}\nfloat fDensity;\nif (fDeltaY != 0.) {\nfDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n} else {\nfDensity = 0.;\n}\nfloat f = exp(-fDensity);\nreturn f;\n}\nvoid CC_TRANSFER_FOG_BASE(vec4 pos, out float factor)\n{\n#if CC_USE_FOG == 0\nfactor = LinearFog(pos);\n#elif CC_USE_FOG == 1\nfactor = ExpFog(pos);\n#elif CC_USE_FOG == 2\nfactor = ExpSquaredFog(pos);\n#elif CC_USE_FOG == 3\nfactor = LayeredFog(pos);\n#else\nfactor = 1.0;\n#endif\n}\nvoid CC_APPLY_FOG_BASE(inout vec4 color, float factor) {\ncolor = vec4(mix(cc_fogColor.rgb, color.rgb, factor), color.a);\n}\n#if !CC_USE_ACCURATE_FOG\nin float v_fog_factor;\n#endif\nvoid CC_APPLY_FOG(inout vec4 color) {\n#if !CC_USE_ACCURATE_FOG\nCC_APPLY_FOG_BASE(color, v_fog_factor);\n#endif\n}\nvoid CC_APPLY_FOG(inout vec4 color, vec3 worldPos) {\n#if CC_USE_ACCURATE_FOG\nfloat factor;\nCC_TRANSFER_FOG_BASE(vec4(worldPos, 1.0), factor);\n#else\nfloat factor = v_fog_factor;\n#endif\nCC_APPLY_FOG_BASE(color, factor);\n}\nin highp vec4 v_shadowPos;\n#if CC_RECEIVE_SHADOW\n#endif\n#if USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\nin vec3 v_luv;\nuniform sampler2D cc_lightingMap;\n#endif\nin highp vec3 v_position;\nin mediump vec3 v_normal;\n#if CC_RECEIVE_SHADOW\nin vec2 v_shadowBias;\n#endif\nin mediump vec2 uvw;\nin mediump vec2 uv0;\nin mediump vec2 uv1;\nin mediump vec2 uv2;\nin mediump vec2 uv3;\nin mediump vec3 diffuse;\nin mediump vec3 luv;\nlayout(std140) uniform PbrParams {\nvec4 metallic;\nvec4 roughness;\n};\nuniform sampler2D weightMap;\nuniform sampler2D detailMap0;\nuniform sampler2D detailMap1;\nuniform sampler2D detailMap2;\nuniform sampler2D detailMap3;\nuniform sampler2D normalMap0;\nuniform sampler2D normalMap1;\nuniform sampler2D normalMap2;\nuniform sampler2D normalMap3;\nuniform sampler2D lightMap;\nvoid surf (out StandardSurface s) {\n#if LAYERS > 1\nvec4 w = texture(weightMap, uvw);\n#endif\nvec4 baseColor = vec4(0, 0, 0, 0);\n#if LAYERS == 1\nbaseColor = texture(detailMap0, uv0);\n#elif LAYERS == 2\nbaseColor += texture(detailMap0, uv0) * w.r;\nbaseColor += texture(detailMap1, uv1) * w.g;\n#elif LAYERS == 3\nbaseColor += texture(detailMap0, uv0) * w.r;\nbaseColor += texture(detailMap1, uv1) * w.g;\nbaseColor += texture(detailMap2, uv2) * w.b;\n#elif LAYERS == 4\nbaseColor += texture(detailMap0, uv0) * w.r;\nbaseColor += texture(detailMap1, uv1) * w.g;\nbaseColor += texture(detailMap2, uv2) * w.b;\nbaseColor += texture(detailMap3, uv3) * w.a;\n#else\nbaseColor = texture(detailMap0, uv0);\n#endif\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\npackHighpData(s.position, s.position_fract_part, v_position);\n#else\ns.position = v_position;\n#endif\n#if USE_NORMALMAP\nvec4 baseNormal = vec4(0, 0, 0, 0);\n#if LAYERS == 1\nbaseNormal = texture(normalMap0, uv0);\n#elif LAYERS == 2\nbaseNormal += texture(normalMap0, uv0) * w.r;\nbaseNormal += texture(normalMap1, uv1) * w.g;\n#elif LAYERS == 3\nbaseNormal += texture(normalMap0, uv0) * w.r;\nbaseNormal += texture(normalMap1, uv1) * w.g;\nbaseNormal += texture(normalMap2, uv2) * w.b;\n#elif LAYERS == 4\nbaseNormal += texture(normalMap0, uv0) * w.r;\nbaseNormal += texture(normalMap1, uv1) * w.g;\nbaseNormal += texture(normalMap2, uv2) * w.b;\nbaseNormal += texture(normalMap3, uv3) * w.a;\n#else\nbaseNormal = texture(normalMap0, uv0);\n#endif\nvec3 tangent = vec3(1.0, 0.0, 0.0);\nvec3 binormal = vec3(0.0, 0.0, 1.0);\nbinormal = cross(tangent, v_normal);\ntangent = cross(v_normal, binormal);\nvec3 nmmp = baseNormal.xyz - vec3(0.5);\ns.normal =\nnmmp.x * normalize(tangent) +\nnmmp.y * normalize(binormal) +\nnmmp.z * normalize(v_normal);\n#else\ns.normal = v_normal;\n#endif\n#if CC_RECEIVE_SHADOW\ns.shadowBias = v_shadowBias;\n#endif\ns.albedo = vec4(SRGBToLinear(baseColor.rgb), 1.0);\ns.occlusion = 1.0;\n#if USE_PBR\ns.roughness = 0.0;\n#if LAYERS == 1\ns.roughness = roughness.x;\n#elif LAYERS == 2\ns.roughness += roughness.x * w.r;\ns.roughness += roughness.y * w.g;\n#elif LAYERS == 3\ns.roughness += roughness.x * w.r;\ns.roughness += roughness.y * w.g;\ns.roughness += roughness.z * w.b;\n#elif LAYERS == 4\ns.roughness += roughness.x * w.r;\ns.roughness += roughness.y * w.g;\ns.roughness += roughness.z * w.b;\ns.roughness += roughness.w * w.a;\n#else\ns.roughness = 1.0;\n#endif\ns.specularIntensity = 0.5;\ns.metallic = 0.0;\n#if LAYERS == 1\ns.specularIntensity = 0.5;\ns.metallic = metallic.x;\n#elif LAYERS == 2\ns.metallic += metallic.x * w.r;\ns.metallic += metallic.y * w.g;\n#elif LAYERS == 3\ns.metallic += metallic.x * w.r;\ns.metallic += metallic.y * w.g;\ns.metallic += metallic.z * w.b;\n#elif LAYERS == 4\ns.metallic += metallic.x * w.r;\ns.metallic += metallic.y * w.g;\ns.metallic += metallic.z * w.b;\ns.metallic += metallic.w * w.a;\n#else\ns.specularIntensity = 0.5;\ns.metallic = 0.0;\n#endif\n#else\ns.roughness = 1.0;\ns.specularIntensity = 0.5;\ns.metallic = 0.0;\n#endif\ns.emissive = vec3(0.0, 0.0, 0.0);\n#if USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\nvec4 lightColor = texture(lightMap, luv.xy);\ns.lightmap = lightColor.xyz * luv.z;\ns.lightmap_test = luv.z;\n#endif\n}\n#if CC_FORWARD_ADD\n#if CC_PIPELINE_TYPE == 0\n#define LIGHTS_PER_PASS 1\n#else\n#define LIGHTS_PER_PASS 10\n#endif\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 0\nlayout(std140) uniform CCForwardLight {\nhighp vec4 cc_lightPos[LIGHTS_PER_PASS];\nvec4 cc_lightColor[LIGHTS_PER_PASS];\nvec4 cc_lightSizeRangeAngle[LIGHTS_PER_PASS];\nvec4 cc_lightDir[LIGHTS_PER_PASS];\n};\n#endif\nfloat SmoothDistAtt (float distSqr, float invSqrAttRadius) {\nfloat factor = distSqr * invSqrAttRadius;\nfloat smoothFactor = clamp(1.0 - factor * factor, 0.0, 1.0);\nreturn smoothFactor * smoothFactor;\n}\nfloat GetDistAtt (float distSqr, float invSqrAttRadius) {\nfloat attenuation = 1.0 / max(distSqr, 0.01*0.01);\nattenuation *= SmoothDistAtt(distSqr , invSqrAttRadius);\nreturn attenuation;\n}\nfloat GetAngleAtt (vec3 L, vec3 litDir, float litAngleScale, float litAngleOffset) {\nfloat cd = dot(litDir, L);\nfloat attenuation = clamp(cd * litAngleScale + litAngleOffset, 0.0, 1.0);\nreturn (attenuation * attenuation);\n}\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 0\nvec4 CCStandardShadingAdditive (StandardSurface s, vec4 shadowPos) {\nvec3 position;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nposition = unpackHighpData(s.position, s.position_fract_part);\n#else\nposition = s.position;\n#endif\nvec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\nvec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\nvec3 diffuseContrib = diffuse / PI;\nvec3 N = normalize(s.normal);\nvec3 V = normalize(cc_cameraPos.xyz - position);\nfloat NV = max(abs(dot(N, V)), 0.0);\nspecular = BRDFApprox(specular, s.roughness, NV);\nvec3 finalColor = vec3(0.0);\nint numLights = CC_PIPELINE_TYPE == 0 ? LIGHTS_PER_PASS : int(cc_lightDir[0].w);\nfor (int i = 0; i < LIGHTS_PER_PASS; i++) {\nif (i >= numLights) break;\nvec3 SLU = cc_lightPos[i].xyz - position;\nvec3 SL = normalize(SLU);\nvec3 SH = normalize(SL + V);\nfloat SNL = max(dot(N, SL), 0.0);\nfloat SNH = max(dot(N, SH), 0.0);\nfloat distSqr = dot(SLU, SLU);\nfloat litRadius = cc_lightSizeRangeAngle[i].x;\nfloat litRadiusSqr = litRadius * litRadius;\nfloat illum = litRadiusSqr / max(litRadiusSqr, distSqr);\nfloat attRadiusSqrInv = 1.0 / max(cc_lightSizeRangeAngle[i].y, 0.01);\nattRadiusSqrInv *= attRadiusSqrInv;\nfloat att = GetDistAtt(distSqr, attRadiusSqrInv);\nvec3 lspec = specular * CalcSpecular(s.roughness, SNH, SH, N);\nif (cc_lightPos[i].w > 0.0) {\nfloat cosInner = max(dot(-cc_lightDir[i].xyz, SL), 0.01);\nfloat cosOuter = cc_lightSizeRangeAngle[i].z;\nfloat litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\nfloat litAngleOffset = -cosOuter * litAngleScale;\natt *= GetAngleAtt(SL, -cc_lightDir[i].xyz, litAngleScale, litAngleOffset);\n}\nvec3 lightColor = cc_lightColor[i].rgb;\nfloat shadow = 1.0;\n#if CC_RECEIVE_SHADOW\nif (cc_lightPos[i].w > 0.0 && cc_lightSizeRangeAngle[i].w > 0.0) {\nshadow = CCSpotShadowFactorBase(shadowPos, position, s.shadowBias);\n}\n#endif\nlightColor *= shadow;\nfinalColor += SNL * lightColor * cc_lightColor[i].w * illum * att * (diffuseContrib + lspec);\n}\nreturn vec4(finalColor, 0.0);\n}\n#endif\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 1\nlayout(std430, binding = 4) readonly buffer b_ccLightsBuffer { vec4 b_ccLights[]; };\nlayout(std430, binding = 5) readonly buffer b_clusterLightIndicesBuffer { uint b_clusterLightIndices[]; };\nlayout(std430, binding = 6) readonly buffer b_clusterLightGridBuffer { uvec4 b_clusterLightGrid[]; };\nstruct CCLight\n{\nvec4 cc_lightPos;\nvec4 cc_lightColor;\nvec4 cc_lightSizeRangeAngle;\nvec4 cc_lightDir;\n};\nstruct Cluster\n{\nvec3 minBounds;\nvec3 maxBounds;\n};\nstruct LightGrid\n{\nuint offset;\nuint ccLights;\n};\nCCLight getCCLight(uint i)\n{\nCCLight light;\nlight.cc_lightPos = b_ccLights[4u * i + 0u];\nlight.cc_lightColor = b_ccLights[4u * i + 1u];\nlight.cc_lightSizeRangeAngle = b_ccLights[4u * i + 2u];\nlight.cc_lightDir = b_ccLights[4u * i + 3u];\nreturn light;\n}\nLightGrid getLightGrid(uint cluster)\n{\nuvec4 gridvec = b_clusterLightGrid[cluster];\nLightGrid grid;\ngrid.offset = gridvec.x;\ngrid.ccLights = gridvec.y;\nreturn grid;\n}\nuint getGridLightIndex(uint start, uint offset)\n{\nreturn b_clusterLightIndices[start + offset];\n}\nuint getClusterZIndex(vec4 worldPos)\n{\nfloat scale = float(24) / log(cc_nearFar.y / cc_nearFar.x);\nfloat bias = -(float(24) * log(cc_nearFar.x) / log(cc_nearFar.y / cc_nearFar.x));\nfloat eyeDepth = -(cc_matView * worldPos).z;\nuint zIndex = uint(max(log(eyeDepth) * scale + bias, 0.0));\nreturn zIndex;\n}\nuint getClusterIndex(vec4 fragCoord, vec4 worldPos)\n{\nuint zIndex = getClusterZIndex(worldPos);\nfloat clusterSizeX = ceil(cc_viewPort.z / float(16));\nfloat clusterSizeY = ceil(cc_viewPort.w / float(8));\nuvec3 indices = uvec3(uvec2(fragCoord.xy / vec2(clusterSizeX, clusterSizeY)), zIndex);\nuint cluster = (16u * 8u) * indices.z + 16u * indices.y + indices.x;\nreturn cluster;\n}\nvec4 CCClusterShadingAdditive (StandardSurface s, vec4 shadowPos) {\nvec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\nvec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\nvec3 diffuseContrib = diffuse / PI;\nvec3 position;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nposition = unpackHighpData(s.position, s.position_fract_part);\n#else\nposition = s.position;\n#endif\nvec3 N = normalize(s.normal);\nvec3 V = normalize(cc_cameraPos.xyz - position);\nfloat NV = max(abs(dot(N, V)), 0.001);\nspecular = BRDFApprox(specular, s.roughness, NV);\nvec3 finalColor = vec3(0.0);\nuint cluster = getClusterIndex(gl_FragCoord, vec4(position, 1.0));\nLightGrid grid = getLightGrid(cluster);\nuint numLights = grid.ccLights;\nfor (uint i = 0u; i < 100u; i++) {\nif (i >= numLights) break;\nuint lightIndex = getGridLightIndex(grid.offset, i);\nCCLight light = getCCLight(lightIndex);\nvec3 SLU = light.cc_lightPos.xyz - position;\nvec3 SL = normalize(SLU);\nvec3 SH = normalize(SL + V);\nfloat SNL = max(dot(N, SL), 0.001);\nfloat SNH = max(dot(N, SH), 0.0);\nfloat distSqr = dot(SLU, SLU);\nfloat litRadius = light.cc_lightSizeRangeAngle.x;\nfloat litRadiusSqr = litRadius * litRadius;\nfloat illum = PI * (litRadiusSqr / max(litRadiusSqr , distSqr));\nfloat attRadiusSqrInv = 1.0 / max(light.cc_lightSizeRangeAngle.y, 0.01);\nattRadiusSqrInv *= attRadiusSqrInv;\nfloat att = GetDistAtt(distSqr, attRadiusSqrInv);\nvec3 lspec = specular * CalcSpecular(s.roughness, SNH, SH, N);\nif (light.cc_lightPos.w > 0.0) {\nfloat cosInner = max(dot(-light.cc_lightDir.xyz, SL), 0.01);\nfloat cosOuter = light.cc_lightSizeRangeAngle.z;\nfloat litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\nfloat litAngleOffset = -cosOuter * litAngleScale;\natt *= GetAngleAtt(SL, -light.cc_lightDir.xyz, litAngleScale, litAngleOffset);\n}\nvec3 lightColor = light.cc_lightColor.rgb;\nfloat shadow = 1.0;\n#if CC_RECEIVE_SHADOW\nif (light.cc_lightPos.w > 0.0) {\nshadow = CCSpotShadowFactorBase(shadowPos, position, s.shadowBias);\n}\n#endif\nlightColor *= shadow;\nfinalColor += SNL * lightColor * light.cc_lightColor.w * illum * att * (diffuseContrib + lspec);\n}\nreturn vec4(finalColor, 0.0);\n}\n#endif\nlayout(location = 0) out vec4 fragColorX;\nvoid main () {\nStandardSurface s; surf(s);\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 1\nvec4 color = CCClusterShadingAdditive(s, v_shadowPos);\n#else\nvec4 color = CCStandardShadingAdditive(s, v_shadowPos);\n#endif\nfragColorX = CCFragOutput(color);\n}\n#elif (CC_PIPELINE_TYPE == 0 || CC_FORCE_FORWARD_SHADING)\nlayout(location = 0) out vec4 fragColorX;\nvoid main () {\nStandardSurface s; surf(s);\nvec4 color = CCStandardShadingBase(s, v_shadowPos);\nCC_APPLY_FOG(color, s.position.xyz);\nfragColorX = CCFragOutput(color);\n}\n#elif CC_PIPELINE_TYPE == 1\nvec2 signNotZero(vec2 v) {\nreturn vec2((v.x >= 0.0) ? +1.0 : -1.0, (v.y >= 0.0) ? +1.0 : -1.0);\n}\nvec2 float32x3_to_oct(in vec3 v) {\nvec2 p = v.xy * (1.0 / (abs(v.x) + abs(v.y) + abs(v.z)));\nreturn (v.z <= 0.0) ? ((1.0 - abs(p.yx)) * signNotZero(p)) : p;\n}\nlayout(location = 0) out vec4 fragColor0;\nlayout(location = 1) out vec4 fragColor1;\nlayout(location = 2) out vec4 fragColor2;\nvoid main () {\nStandardSurface s; surf(s);\nfragColor0 = s.albedo;\nfragColor1 = vec4(float32x3_to_oct(s.normal), s.roughness, s.metallic);\nfragColor2 = vec4(s.emissive, s.occlusion);\n}\n#endif", + "vert": "\nprecision mediump float;\nlayout(std140) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(std140) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\nlayout(std140) uniform CCLocal {\nhighp mat4 cc_matWorld;\nhighp mat4 cc_matWorldIT;\nhighp vec4 cc_lightingMapUVParam;\nhighp vec4 cc_localShadowBias;\n};\nfloat LinearFog(vec4 pos) {\nvec4 wPos = pos;\nfloat cam_dis = distance(cc_cameraPos, wPos);\nfloat fogStart = cc_fogBase.x;\nfloat fogEnd = cc_fogBase.y;\nreturn clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * fogDensity);\nreturn f;\n}\nfloat ExpSquaredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\nreturn f;\n}\nfloat LayeredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat _FogTop = cc_fogAdd.x;\nfloat _FogRange = cc_fogAdd.y;\nvec3 camWorldProj = cc_cameraPos.xyz;\ncamWorldProj.y = 0.;\nvec3 worldPosProj = wPos.xyz;\nworldPosProj.y = 0.;\nfloat fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\nfloat fDeltaY, fDensityIntegral;\nif (cc_cameraPos.y > _FogTop) {\nif (wPos.y < _FogTop) {\nfDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\nfDensityIntegral = fDeltaY * fDeltaY * 0.5;\n} else {\nfDeltaY = 0.;\nfDensityIntegral = 0.;\n}\n} else {\nif (wPos.y < _FogTop) {\nfloat fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfloat fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\nfDeltaY = abs(fDeltaA - fDeltaB);\nfDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n} else {\nfDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n}\n}\nfloat fDensity;\nif (fDeltaY != 0.) {\nfDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n} else {\nfDensity = 0.;\n}\nfloat f = exp(-fDensity);\nreturn f;\n}\nvoid CC_TRANSFER_FOG_BASE(vec4 pos, out float factor)\n{\n#if CC_USE_FOG == 0\nfactor = LinearFog(pos);\n#elif CC_USE_FOG == 1\nfactor = ExpFog(pos);\n#elif CC_USE_FOG == 2\nfactor = ExpSquaredFog(pos);\n#elif CC_USE_FOG == 3\nfactor = LayeredFog(pos);\n#else\nfactor = 1.0;\n#endif\n}\n#if !CC_USE_ACCURATE_FOG\nout float v_fog_factor;\n#endif\nvoid CC_TRANSFER_FOG(vec4 pos) {\n#if !CC_USE_ACCURATE_FOG\nCC_TRANSFER_FOG_BASE(pos, v_fog_factor);\n#endif\n}\nout highp vec4 v_shadowPos;\nlayout(std140) uniform CCShadow {\nhighp mat4 cc_matLightPlaneProj;\nhighp mat4 cc_matLightView;\nhighp mat4 cc_matLightViewProj;\nhighp vec4 cc_shadowInvProjDepthInfo;\nhighp vec4 cc_shadowProjDepthInfo;\nhighp vec4 cc_shadowProjInfo;\nmediump vec4 cc_shadowNFLSInfo;\nmediump vec4 cc_shadowWHPBInfo;\nmediump vec4 cc_shadowLPNNInfo;\nlowp vec4 cc_shadowColor;\nmediump vec4 cc_planarNDInfo;\n};\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\n#if CC_RECEIVE_SHADOW\nuniform highp sampler2D cc_shadowMap;\nuniform highp sampler2D cc_spotLightingMap;\n#endif\n#if CC_RECEIVE_SHADOW\n#endif\nin vec3 a_position;\nin vec3 a_normal;\nin vec2 a_texCoord;\n#if CC_RECEIVE_SHADOW\nout vec2 v_shadowBias;\n#endif\nout highp vec3 v_position;\nout mediump vec3 v_normal;\nout mediump vec2 uvw;\nout mediump vec2 uv0;\nout mediump vec2 uv1;\nout mediump vec2 uv2;\nout mediump vec2 uv3;\nout mediump vec3 luv;\nout mediump vec3 diffuse;\nlayout(std140) uniform TexCoords {\nvec4 UVScale;\nvec4 lightMapUVParam;\n};\nvoid main () {\nvec3 worldPos;\nworldPos.x = cc_matWorld[3][0] + a_position.x;\nworldPos.y = cc_matWorld[3][1] + a_position.y;\nworldPos.z = cc_matWorld[3][2] + a_position.z;\nvec4 pos = vec4(worldPos, 1.0);\npos = cc_matViewProj * pos;\nuvw = a_texCoord;\nuv0 = a_position.xz * UVScale.x;\nuv1 = a_position.xz * UVScale.y;\nuv2 = a_position.xz * UVScale.z;\nuv3 = a_position.xz * UVScale.w;\n#if CC_USE_LIGHTMAP\nluv.xy = lightMapUVParam.xy + a_texCoord * lightMapUVParam.z;\nluv.z = lightMapUVParam.w;\n#endif\nv_position = worldPos;\nv_normal = a_normal;\nCC_TRANSFER_FOG(vec4(worldPos, 1.0));\n#if CC_RECEIVE_SHADOW\nv_shadowBias = vec2(0.0, 0.0);\n#endif\nv_shadowPos = cc_matLightViewProj * vec4(worldPos, 1.0);\ngl_Position = pos;\n}", + "frag": "\nprecision highp float;\nlayout(std140) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(std140) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nvec3 SRGBToLinear (vec3 gamma) {\nreturn gamma * gamma;\n}\nlayout(std140) uniform CCShadow {\nhighp mat4 cc_matLightPlaneProj;\nhighp mat4 cc_matLightView;\nhighp mat4 cc_matLightViewProj;\nhighp vec4 cc_shadowInvProjDepthInfo;\nhighp vec4 cc_shadowProjDepthInfo;\nhighp vec4 cc_shadowProjInfo;\nmediump vec4 cc_shadowNFLSInfo;\nmediump vec4 cc_shadowWHPBInfo;\nmediump vec4 cc_shadowLPNNInfo;\nlowp vec4 cc_shadowColor;\nmediump vec4 cc_planarNDInfo;\n};\nhighp float unpackHighpData (float mainPart, float modPart) {\nhighp float data = mainPart;\nreturn data + modPart;\n}\nvoid packHighpData (out float mainPart, out float modPart, highp float data) {\nmainPart = fract(data);\nmodPart = data - mainPart;\n}\nhighp float unpackHighpData (float mainPart, float modPart, const float modValue) {\nhighp float data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nvoid packHighpData (out float mainPart, out float modPart, highp float data, const float modValue) {\nhighp float divide = data / modValue;\nmainPart = floor(divide);\nmodPart = (data - mainPart * modValue) / modValue;\n}\nhighp vec2 unpackHighpData (vec2 mainPart, vec2 modPart) {\nhighp vec2 data = mainPart;\nreturn data + modPart;\n}\nvoid packHighpData (out vec2 mainPart, out vec2 modPart, highp vec2 data) {\nmainPart = fract(data);\nmodPart = data - mainPart;\n}\nhighp vec2 unpackHighpData (vec2 mainPart, vec2 modPart, const float modValue) {\nhighp vec2 data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nvoid packHighpData (out vec2 mainPart, out vec2 modPart, highp vec2 data, const float modValue) {\nhighp vec2 divide = data / modValue;\nmainPart = floor(divide);\nmodPart = (data - mainPart * modValue) / modValue;\n}\nhighp vec3 unpackHighpData (vec3 mainPart, vec3 modPart) {\nhighp vec3 data = mainPart;\nreturn data + modPart;\n}\nvoid packHighpData (out vec3 mainPart, out vec3 modPart, highp vec3 data) {\nmainPart = fract(data);\nmodPart = data - mainPart;\n}\nhighp vec3 unpackHighpData (vec3 mainPart, vec3 modPart, const float modValue) {\nhighp vec3 data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nvoid packHighpData (out vec3 mainPart, out vec3 modPart, highp vec3 data, const float modValue) {\nhighp vec3 divide = data / modValue;\nmainPart = floor(divide);\nmodPart = (data - mainPart * modValue) / modValue;\n}\nhighp vec4 unpackHighpData (vec4 mainPart, vec4 modPart) {\nhighp vec4 data = mainPart;\nreturn data + modPart;\n}\nvoid packHighpData (out vec4 mainPart, out vec4 modPart, highp vec4 data) {\nmainPart = fract(data);\nmodPart = data - mainPart;\n}\nhighp vec4 unpackHighpData (vec4 mainPart, vec4 modPart, const float modValue) {\nhighp vec4 data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nvoid packHighpData (out vec4 mainPart, out vec4 modPart, highp vec4 data, const float modValue) {\nhighp vec4 divide = data / modValue;\nmainPart = floor(divide);\nmodPart = (data - mainPart * modValue) / modValue;\n}\nlayout(std140) uniform CCLocal {\nhighp mat4 cc_matWorld;\nhighp mat4 cc_matWorldIT;\nhighp vec4 cc_lightingMapUVParam;\nhighp vec4 cc_localShadowBias;\n};\nfloat CCGetLinearDepthFromViewSpace(vec3 viewPos) {\nfloat dist = length(viewPos);\nreturn (dist - cc_shadowNFLSInfo.x) / (cc_shadowNFLSInfo.y - cc_shadowNFLSInfo.x);\n}\nfloat CCGetLinearDepth(vec3 worldPos) {\nvec4 viewStartPos = cc_matLightView * vec4(worldPos.xyz, 1.0);\nreturn CCGetLinearDepthFromViewSpace(viewStartPos.xyz);\n}\n#if CC_RECEIVE_SHADOW\nuniform highp sampler2D cc_shadowMap;\nuniform highp sampler2D cc_spotLightingMap;\nvec4 ApplyShadowDepthBias_FaceNormal(vec4 shadowPos, vec3 worldNormal, float normalBias)\n{\nvec4 newShadowPos = shadowPos;\nif(normalBias > EPSILON_LOWP)\n{\nvec4 viewNormal = cc_matLightView * vec4(worldNormal, 0.0);\nif(viewNormal.z < 0.1)\nnewShadowPos.xy += viewNormal.xy * cc_shadowProjInfo.xy * normalBias * clamp(viewNormal.z, 0.001, 0.1);\n}\nreturn newShadowPos;\n}\nvec4 ApplyShadowDepthBias_Perspective(vec4 shadowPos, float viewspaceDepthBias)\n{\nvec3 viewSpacePos;\nviewSpacePos.xy = shadowPos.xy * cc_shadowProjInfo.zw;\nviewSpacePos.z = shadowPos.z * cc_shadowInvProjDepthInfo.x + shadowPos.w * cc_shadowInvProjDepthInfo.y;\nviewSpacePos.xyz += cc_shadowProjDepthInfo.z * normalize(viewSpacePos.xyz) * viewspaceDepthBias;\nvec4 clipSpacePos;\nclipSpacePos.xy = viewSpacePos.xy * cc_shadowProjInfo.xy;\nclipSpacePos.zw = viewSpacePos.z * cc_shadowProjDepthInfo.xz + vec2(cc_shadowProjDepthInfo.y, 0.0);\nif (cc_shadowNFLSInfo.z > EPSILON) {\nclipSpacePos.z = CCGetLinearDepthFromViewSpace(viewSpacePos.xyz);\nclipSpacePos.z = (clipSpacePos.z * 2.0 - 1.0) * clipSpacePos.w;\n}\nreturn clipSpacePos;\n}\nvec4 ApplyShadowDepthBias_Orthographic(vec4 shadowPos, float viewspaceDepthBias)\n{\nfloat coeffA = cc_shadowProjDepthInfo.x;\nfloat coeffB = cc_shadowProjDepthInfo.y;\nfloat viewSpacePos_z = (shadowPos.z - coeffB) / coeffA;\nviewSpacePos_z += viewspaceDepthBias;\nvec4 result = shadowPos;\nresult.z = viewSpacePos_z * coeffA + coeffB;\nreturn result;\n}\nfloat CCGetShadowFactorHard (vec4 shadowPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Orthographic(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat shadow = 0.0;\nfloat closestDepth = 0.0;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nclosestDepth = dot(texture(cc_shadowMap, clipPos.xy), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0));\n} else {\nclosestDepth = texture(cc_shadowMap, clipPos.xy).x;\n}\nshadow = step(clipPos.z, closestDepth);\nreturn shadow;\n}\nfloat CCGetShadowFactorSoft (vec4 shadowPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Orthographic(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat offsetDepth = clipPos.z;\nvec2 mapSize = cc_shadowWHPBInfo.xy;\nvec2 oneTap = 1.0 / mapSize;\nvec2 clipPos_offset = clipPos.xy + oneTap;\nfloat block0, block1, block2, block3;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos.y)).x);\nblock1 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset.x, clipPos.y)).x);\nblock2 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset.y)).x);\nblock3 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset.x, clipPos_offset.y)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * mapSize.x;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block2, block3, coefX);\nfloat coefY = mod(clipPos.y, oneTap.y) * mapSize.y;\nreturn mix(resultX, resultY, coefY);\n}\nfloat CCGetShadowFactorSoft2X (vec4 shadowPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Orthographic(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat offsetDepth = clipPos.z;\nvec2 mapSize = cc_shadowWHPBInfo.xy;\nvec2 oneTap = 1.0 / mapSize;\nfloat clipPos_offset_L = clipPos.x - oneTap.x;\nfloat clipPos_offset_R = clipPos.x + oneTap.x;\nfloat clipPos_offset_U = clipPos.y - oneTap.y;\nfloat clipPos_offset_D = clipPos.y + oneTap.y;\nfloat block0, block1, block2, block3, block4, block5, block6, block7, block8;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock4 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock5 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock6 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock7 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock8 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_U)).x);\nblock1 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset_U)).x);\nblock2 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_U)).x);\nblock3 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos.y)).x);\nblock4 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos.y)).x);\nblock5 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos.y)).x);\nblock6 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_D)).x);\nblock7 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset_D)).x);\nblock8 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_D)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * mapSize.x;\nfloat coefY = mod(clipPos.y, oneTap.y) * mapSize.y;\nfloat shadow = 0.0;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block3, block4, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block1, block2, coefX);\nresultY = mix(block4, block5, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block3, block4, coefX);\nresultY = mix(block6, block7, coefX);\nshadow += mix(resultX, resultY, coefY);\nresultX = mix(block4, block5, coefX);\nresultY = mix(block7, block8, coefX);\nshadow += mix(resultX, resultY, coefY);\nreturn shadow * 0.25;\n}\nfloat CCGetSpotLightShadowFactorHard (vec4 shadowPos, vec3 worldPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Perspective(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat shadow = 0.0;\nfloat closestDepth = 0.0;\nfloat depth = clipPos.z;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nclosestDepth = dot(texture(cc_spotLightingMap, clipPos.xy), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0));\n} else {\nclosestDepth = texture(cc_spotLightingMap, clipPos.xy).x;\n}\nshadow = step(depth, closestDepth);\nreturn shadow;\n}\nfloat CCGetSpotLightShadowFactorSoft (vec4 shadowPos, vec3 worldPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Perspective(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat depth = 0.0;\nif (cc_shadowNFLSInfo.z > EPSILON) {\ndepth = CCGetLinearDepth(worldPos);\n} else {\ndepth = clipPos.z;\n}\nvec2 oneTap = 1.0 / cc_shadowWHPBInfo.xy;\nvec2 clipPos_offset = clipPos.xy + oneTap;\nfloat block0, block1, block2, block3;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)).x);\nblock1 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos.y)).x);\nblock2 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset.y)).x);\nblock3 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos_offset.y)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * cc_shadowWHPBInfo.x;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block2, block3, coefX);\nfloat coefY = mod(clipPos.y, oneTap.y) * cc_shadowWHPBInfo.y;\nreturn mix(resultX, resultY, coefY);\n}\nfloat CCGetSpotLightShadowFactorSoft2X (vec4 shadowPos, vec3 worldPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Perspective(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat depth = 0.0;\nif (cc_shadowNFLSInfo.z > EPSILON) {\ndepth = CCGetLinearDepth(worldPos);\n} else {\ndepth = clipPos.z;\n}\nvec2 mapSize = cc_shadowWHPBInfo.xy;\nvec2 oneTap = 1.0 / mapSize;\nfloat clipPos_offset_L = clipPos.x - oneTap.x;\nfloat clipPos_offset_R = clipPos.x + oneTap.x;\nfloat clipPos_offset_U = clipPos.y - oneTap.y;\nfloat clipPos_offset_D = clipPos.y + oneTap.y;\nfloat block0, block1, block2, block3, block4, block5, block6, block7, block8;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock4 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock5 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock6 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock7 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock8 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_U)).x);\nblock1 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_U)).x);\nblock2 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_U)).x);\nblock3 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos.y)).x);\nblock4 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)).x);\nblock5 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos.y)).x);\nblock6 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_D)).x);\nblock7 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_D)).x);\nblock8 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_D)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * mapSize.x;\nfloat coefY = mod(clipPos.y, oneTap.y) * mapSize.y;\nfloat shadow = 0.0;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block3, block4, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block1, block2, coefX);\nresultY = mix(block4, block5, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block3, block4, coefX);\nresultY = mix(block6, block7, coefX);\nshadow += mix(resultX, resultY, coefY);\nresultX = mix(block4, block5, coefX);\nresultY = mix(block7, block8, coefX);\nshadow += mix(resultX, resultY, coefY);\nreturn shadow * 0.25;\n}\nfloat CCSpotShadowFactorBase(vec4 shadowPos, vec3 worldPos, vec2 shadowBias)\n{\nfloat pcf = cc_shadowWHPBInfo.z;\nif (pcf > 1.9) {\nreturn CCGetSpotLightShadowFactorSoft2X(shadowPos, worldPos, shadowBias.x);\n}else if (pcf > 0.9) {\nreturn CCGetSpotLightShadowFactorSoft(shadowPos, worldPos, shadowBias.x);\n}else {\nreturn CCGetSpotLightShadowFactorHard(shadowPos, worldPos, shadowBias.x);\n}\n}\nfloat CCShadowFactorBase(vec4 shadowPos, vec3 N, vec2 shadowBias)\n{\nfloat realtimeShadow = 1.0;\nvec4 pos = ApplyShadowDepthBias_FaceNormal(shadowPos, N, shadowBias.y);\nfloat pcf = cc_shadowWHPBInfo.z;\nif (pcf > 1.9) {\nrealtimeShadow = CCGetShadowFactorSoft2X(pos, shadowBias.x);\n}else if (pcf > 0.9) {\nrealtimeShadow = CCGetShadowFactorSoft(pos, shadowBias.x);\n}else {\nrealtimeShadow = CCGetShadowFactorHard(pos, shadowBias.x);\n}\nreturn mix(realtimeShadow, 1.0, cc_shadowNFLSInfo.w);\n}\n#endif\n#if CC_USE_IBL\nuniform samplerCube cc_environment;\nvec4 fragTextureLod (sampler2D tex, vec2 coord, float lod) {\nreturn textureLod(tex, coord, lod);\n}\nvec4 fragTextureLod (samplerCube tex, vec3 coord, float lod) {\nreturn textureLod(tex, coord, lod);\n}\nvec3 unpackRGBE (vec4 rgbe) {\nreturn rgbe.rgb * pow(1.1, rgbe.a * 255.0 - 128.0);\n}\n#if CC_USE_DIFFUSEMAP\nuniform samplerCube cc_diffuseMap;\n#endif\n#endif\nfloat GGXMobile (float roughness, float NoH, vec3 H, vec3 N) {\nvec3 NxH = cross(N, H);\nfloat OneMinusNoHSqr = dot(NxH, NxH);\nfloat a = roughness * roughness;\nfloat n = NoH * a;\nfloat p = a / (OneMinusNoHSqr + n * n);\nreturn p * p;\n}\nfloat CalcSpecular (float roughness, float NoH, vec3 H, vec3 N) {\nreturn (roughness * 0.25 + 0.25) * GGXMobile(roughness, NoH, H, N);\n}\nvec3 BRDFApprox (vec3 specular, float roughness, float NoV) {\nconst vec4 c0 = vec4(-1.0, -0.0275, -0.572, 0.022);\nconst vec4 c1 = vec4(1.0, 0.0425, 1.04, -0.04);\nvec4 r = roughness * c0 + c1;\nfloat a004 = min(r.x * r.x, exp2(-9.28 * NoV)) * r.x + r.y;\nvec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;\nAB.y *= clamp(50.0 * specular.g, 0.0, 1.0);\nreturn specular * AB.x + AB.y;\n}\n#if USE_REFLECTION_DENOISE\nvec3 GetEnvReflectionWithMipFiltering(vec3 R, float roughness, float mipCount, float denoiseIntensity) {\n#if CC_USE_IBL\nfloat mip = roughness * mipCount;\nfloat delta = (dot(dFdx(R), dFdy(R))) * 1000.0;\nfloat mipBias = mix(0.0, 5.0, clamp(delta, 0.0, 1.0));\nvec4 biased = fragTextureLod(cc_environment, R, mip + mipBias);\nvec4 filtered = texture(cc_environment, R);\n#if CC_USE_IBL == 2\nbiased.rgb = unpackRGBE(biased);\nfiltered.rgb = unpackRGBE(filtered);\n#else\nbiased.rgb = SRGBToLinear(biased.rgb);\nfiltered.rgb = SRGBToLinear(filtered.rgb);\n#endif\nreturn mix(biased.rgb, filtered.rgb, denoiseIntensity);\n#else\nreturn vec3(0.0, 0.0, 0.0);\n#endif\n}\n#endif\nstruct StandardSurface {\nvec4 albedo;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nvec3 position, position_fract_part;\n#else\nvec3 position;\n#endif\nvec3 normal;\nvec3 emissive;\nvec3 lightmap;\nfloat lightmap_test;\nfloat roughness;\nfloat metallic;\nfloat occlusion;\nfloat specularIntensity;\n#if CC_RECEIVE_SHADOW\nvec2 shadowBias;\n#endif\n};\nvec4 CCStandardShadingBase (StandardSurface s, vec4 shadowPos) {\nvec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\nvec3 specular = mix(vec3(0.08 * s.specularIntensity), s.albedo.rgb, s.metallic);\nvec3 position;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nposition = unpackHighpData(s.position, s.position_fract_part);\n#else\nposition = s.position;\n#endif\nvec3 N = normalize(s.normal);\nvec3 V = normalize(cc_cameraPos.xyz - position);\nfloat NV = max(abs(dot(N, V)), 0.0);\nspecular = BRDFApprox(specular, s.roughness, NV);\nvec3 L = normalize(-cc_mainLitDir.xyz);\nvec3 H = normalize(L + V);\nfloat NH = max(dot(N, H), 0.0);\nfloat NL = max(dot(N, L), 0.0);\nvec3 finalColor = NL * cc_mainLitColor.rgb * cc_mainLitColor.w;\nvec3 diffuseContrib = diffuse / PI;\nvec3 specularContrib = specular * CalcSpecular(s.roughness, NH, H, N);\nvec3 dirlightContrib = (diffuseContrib + specularContrib);\nfloat shadow = 1.0;\n#if CC_RECEIVE_SHADOW\nif (NL > 0.0 && cc_mainLitDir.w > 0.0) {\nshadow = CCShadowFactorBase(shadowPos, N, s.shadowBias);\n}\n#endif\ndirlightContrib *= shadow;\nfinalColor *= dirlightContrib;\n#if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\nif (s.lightmap_test > EPSILON_LOWP) {\nfinalColor = diffuse * s.lightmap.rgb * shadow;\n}\n#endif\nfloat fAmb = 0.5 - N.y * 0.5;\nvec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb);\n#if CC_USE_IBL\n#if CC_USE_DIFFUSEMAP\nvec4 diffuseMap = texture(cc_diffuseMap, N);\n#if CC_USE_DIFFUSEMAP == 2\nambDiff = unpackRGBE(diffuseMap);\n#else\nambDiff = SRGBToLinear(diffuseMap.rgb);\n#endif\n#endif\nvec3 R = normalize(reflect(-V, N));\n#if USE_REFLECTION_DENOISE\nvec3 env = GetEnvReflectionWithMipFiltering(R, s.roughness, cc_ambientGround.w, 0.6);\n#else\nvec4 envmap = fragTextureLod(cc_environment, R, s.roughness * cc_ambientGround.w);\n#if CC_USE_IBL == 2\nvec3 env = unpackRGBE(envmap);\n#else\nvec3 env = SRGBToLinear(envmap.rgb);\n#endif\n#endif\nfinalColor += env * cc_ambientSky.w * specular * s.occlusion;\n#endif\nfinalColor += ambDiff.rgb * cc_ambientSky.w * diffuse * s.occlusion;\nfinalColor += s.emissive;\nreturn vec4(finalColor, s.albedo.a);\n}\nvec3 ACESToneMap (vec3 color) {\ncolor = min(color, vec3(8.0));\nconst float A = 2.51;\nconst float B = 0.03;\nconst float C = 2.43;\nconst float D = 0.59;\nconst float E = 0.14;\nreturn (color * (A * color + B)) / (color * (C * color + D) + E);\n}\nvec4 CCFragOutput (vec4 color) {\n#if CC_USE_HDR\ncolor.rgb = ACESToneMap(color.rgb);\n#endif\ncolor.rgb = sqrt(color.rgb);\nreturn color;\n}\nfloat LinearFog(vec4 pos) {\nvec4 wPos = pos;\nfloat cam_dis = distance(cc_cameraPos, wPos);\nfloat fogStart = cc_fogBase.x;\nfloat fogEnd = cc_fogBase.y;\nreturn clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * fogDensity);\nreturn f;\n}\nfloat ExpSquaredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\nreturn f;\n}\nfloat LayeredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat _FogTop = cc_fogAdd.x;\nfloat _FogRange = cc_fogAdd.y;\nvec3 camWorldProj = cc_cameraPos.xyz;\ncamWorldProj.y = 0.;\nvec3 worldPosProj = wPos.xyz;\nworldPosProj.y = 0.;\nfloat fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\nfloat fDeltaY, fDensityIntegral;\nif (cc_cameraPos.y > _FogTop) {\nif (wPos.y < _FogTop) {\nfDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\nfDensityIntegral = fDeltaY * fDeltaY * 0.5;\n} else {\nfDeltaY = 0.;\nfDensityIntegral = 0.;\n}\n} else {\nif (wPos.y < _FogTop) {\nfloat fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfloat fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\nfDeltaY = abs(fDeltaA - fDeltaB);\nfDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n} else {\nfDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n}\n}\nfloat fDensity;\nif (fDeltaY != 0.) {\nfDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n} else {\nfDensity = 0.;\n}\nfloat f = exp(-fDensity);\nreturn f;\n}\nvoid CC_TRANSFER_FOG_BASE(vec4 pos, out float factor)\n{\n#if CC_USE_FOG == 0\nfactor = LinearFog(pos);\n#elif CC_USE_FOG == 1\nfactor = ExpFog(pos);\n#elif CC_USE_FOG == 2\nfactor = ExpSquaredFog(pos);\n#elif CC_USE_FOG == 3\nfactor = LayeredFog(pos);\n#else\nfactor = 1.0;\n#endif\n}\nvoid CC_APPLY_FOG_BASE(inout vec4 color, float factor) {\ncolor = vec4(mix(cc_fogColor.rgb, color.rgb, factor), color.a);\n}\n#if !CC_USE_ACCURATE_FOG\nin float v_fog_factor;\n#endif\nvoid CC_APPLY_FOG(inout vec4 color) {\n#if !CC_USE_ACCURATE_FOG\nCC_APPLY_FOG_BASE(color, v_fog_factor);\n#endif\n}\nvoid CC_APPLY_FOG(inout vec4 color, vec3 worldPos) {\n#if CC_USE_ACCURATE_FOG\nfloat factor;\nCC_TRANSFER_FOG_BASE(vec4(worldPos, 1.0), factor);\n#else\nfloat factor = v_fog_factor;\n#endif\nCC_APPLY_FOG_BASE(color, factor);\n}\nin highp vec4 v_shadowPos;\n#if CC_RECEIVE_SHADOW\n#endif\n#if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\nin vec3 v_luv;\nuniform sampler2D cc_lightingMap;\n#endif\nin highp vec3 v_position;\nin mediump vec3 v_normal;\n#if CC_RECEIVE_SHADOW\nin vec2 v_shadowBias;\n#endif\nin mediump vec2 uvw;\nin mediump vec2 uv0;\nin mediump vec2 uv1;\nin mediump vec2 uv2;\nin mediump vec2 uv3;\nin mediump vec3 diffuse;\nin mediump vec3 luv;\nlayout(std140) uniform PbrParams {\nvec4 metallic;\nvec4 roughness;\n};\nuniform sampler2D weightMap;\nuniform sampler2D detailMap0;\nuniform sampler2D detailMap1;\nuniform sampler2D detailMap2;\nuniform sampler2D detailMap3;\nuniform sampler2D normalMap0;\nuniform sampler2D normalMap1;\nuniform sampler2D normalMap2;\nuniform sampler2D normalMap3;\nuniform sampler2D lightMap;\nvoid surf (out StandardSurface s) {\n#if LAYERS > 1\nvec4 w = texture(weightMap, uvw);\n#endif\nvec4 baseColor = vec4(0, 0, 0, 0);\n#if LAYERS == 1\nbaseColor = texture(detailMap0, uv0);\n#elif LAYERS == 2\nbaseColor += texture(detailMap0, uv0) * w.r;\nbaseColor += texture(detailMap1, uv1) * w.g;\n#elif LAYERS == 3\nbaseColor += texture(detailMap0, uv0) * w.r;\nbaseColor += texture(detailMap1, uv1) * w.g;\nbaseColor += texture(detailMap2, uv2) * w.b;\n#elif LAYERS == 4\nbaseColor += texture(detailMap0, uv0) * w.r;\nbaseColor += texture(detailMap1, uv1) * w.g;\nbaseColor += texture(detailMap2, uv2) * w.b;\nbaseColor += texture(detailMap3, uv3) * w.a;\n#else\nbaseColor = texture(detailMap0, uv0);\n#endif\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\npackHighpData(s.position, s.position_fract_part, v_position);\n#else\ns.position = v_position;\n#endif\n#if USE_NORMALMAP\nvec4 baseNormal = vec4(0, 0, 0, 0);\n#if LAYERS == 1\nbaseNormal = texture(normalMap0, uv0);\n#elif LAYERS == 2\nbaseNormal += texture(normalMap0, uv0) * w.r;\nbaseNormal += texture(normalMap1, uv1) * w.g;\n#elif LAYERS == 3\nbaseNormal += texture(normalMap0, uv0) * w.r;\nbaseNormal += texture(normalMap1, uv1) * w.g;\nbaseNormal += texture(normalMap2, uv2) * w.b;\n#elif LAYERS == 4\nbaseNormal += texture(normalMap0, uv0) * w.r;\nbaseNormal += texture(normalMap1, uv1) * w.g;\nbaseNormal += texture(normalMap2, uv2) * w.b;\nbaseNormal += texture(normalMap3, uv3) * w.a;\n#else\nbaseNormal = texture(normalMap0, uv0);\n#endif\nvec3 tangent = vec3(1.0, 0.0, 0.0);\nvec3 binormal = vec3(0.0, 0.0, 1.0);\nbinormal = cross(tangent, v_normal);\ntangent = cross(v_normal, binormal);\nvec3 nmmp = baseNormal.xyz - vec3(0.5);\ns.normal =\nnmmp.x * normalize(tangent) +\nnmmp.y * normalize(binormal) +\nnmmp.z * normalize(v_normal);\n#else\ns.normal = v_normal;\n#endif\n#if CC_RECEIVE_SHADOW\ns.shadowBias = v_shadowBias;\n#endif\ns.albedo = vec4(SRGBToLinear(baseColor.rgb), 1.0);\ns.occlusion = 1.0;\n#if USE_PBR\ns.roughness = 0.0;\n#if LAYERS == 1\ns.roughness = roughness.x;\n#elif LAYERS == 2\ns.roughness += roughness.x * w.r;\ns.roughness += roughness.y * w.g;\n#elif LAYERS == 3\ns.roughness += roughness.x * w.r;\ns.roughness += roughness.y * w.g;\ns.roughness += roughness.z * w.b;\n#elif LAYERS == 4\ns.roughness += roughness.x * w.r;\ns.roughness += roughness.y * w.g;\ns.roughness += roughness.z * w.b;\ns.roughness += roughness.w * w.a;\n#else\ns.roughness = 1.0;\n#endif\ns.specularIntensity = 0.5;\ns.metallic = 0.0;\n#if LAYERS == 1\ns.specularIntensity = 0.5;\ns.metallic = metallic.x;\n#elif LAYERS == 2\ns.metallic += metallic.x * w.r;\ns.metallic += metallic.y * w.g;\n#elif LAYERS == 3\ns.metallic += metallic.x * w.r;\ns.metallic += metallic.y * w.g;\ns.metallic += metallic.z * w.b;\n#elif LAYERS == 4\ns.metallic += metallic.x * w.r;\ns.metallic += metallic.y * w.g;\ns.metallic += metallic.z * w.b;\ns.metallic += metallic.w * w.a;\n#else\ns.specularIntensity = 0.5;\ns.metallic = 0.0;\n#endif\n#else\ns.roughness = 1.0;\ns.specularIntensity = 0.5;\ns.metallic = 0.0;\n#endif\ns.emissive = vec3(0.0, 0.0, 0.0);\n#if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\nvec4 lightColor = texture(lightMap, luv.xy);\ns.lightmap = lightColor.xyz * luv.z;\ns.lightmap_test = luv.z;\n#endif\n}\n#if CC_FORWARD_ADD\n#if CC_PIPELINE_TYPE == 0\n#define LIGHTS_PER_PASS 1\n#else\n#define LIGHTS_PER_PASS 10\n#endif\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 0\nlayout(std140) uniform CCForwardLight {\nhighp vec4 cc_lightPos[LIGHTS_PER_PASS];\nvec4 cc_lightColor[LIGHTS_PER_PASS];\nvec4 cc_lightSizeRangeAngle[LIGHTS_PER_PASS];\nvec4 cc_lightDir[LIGHTS_PER_PASS];\n};\n#endif\nfloat SmoothDistAtt (float distSqr, float invSqrAttRadius) {\nfloat factor = distSqr * invSqrAttRadius;\nfloat smoothFactor = clamp(1.0 - factor * factor, 0.0, 1.0);\nreturn smoothFactor * smoothFactor;\n}\nfloat GetDistAtt (float distSqr, float invSqrAttRadius) {\nfloat attenuation = 1.0 / max(distSqr, 0.01*0.01);\nattenuation *= SmoothDistAtt(distSqr , invSqrAttRadius);\nreturn attenuation;\n}\nfloat GetAngleAtt (vec3 L, vec3 litDir, float litAngleScale, float litAngleOffset) {\nfloat cd = dot(litDir, L);\nfloat attenuation = clamp(cd * litAngleScale + litAngleOffset, 0.0, 1.0);\nreturn (attenuation * attenuation);\n}\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 0\nvec4 CCStandardShadingAdditive (StandardSurface s, vec4 shadowPos) {\nvec3 position;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nposition = unpackHighpData(s.position, s.position_fract_part);\n#else\nposition = s.position;\n#endif\nvec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\nvec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\nvec3 diffuseContrib = diffuse / PI;\nvec3 N = normalize(s.normal);\nvec3 V = normalize(cc_cameraPos.xyz - position);\nfloat NV = max(abs(dot(N, V)), 0.0);\nspecular = BRDFApprox(specular, s.roughness, NV);\nvec3 finalColor = vec3(0.0);\nint numLights = CC_PIPELINE_TYPE == 0 ? LIGHTS_PER_PASS : int(cc_lightDir[0].w);\nfor (int i = 0; i < LIGHTS_PER_PASS; i++) {\nif (i >= numLights) break;\nvec3 SLU = cc_lightPos[i].xyz - position;\nvec3 SL = normalize(SLU);\nvec3 SH = normalize(SL + V);\nfloat SNL = max(dot(N, SL), 0.0);\nfloat SNH = max(dot(N, SH), 0.0);\nfloat distSqr = dot(SLU, SLU);\nfloat litRadius = cc_lightSizeRangeAngle[i].x;\nfloat litRadiusSqr = litRadius * litRadius;\nfloat illum = litRadiusSqr / max(litRadiusSqr, distSqr);\nfloat attRadiusSqrInv = 1.0 / max(cc_lightSizeRangeAngle[i].y, 0.01);\nattRadiusSqrInv *= attRadiusSqrInv;\nfloat att = GetDistAtt(distSqr, attRadiusSqrInv);\nvec3 lspec = specular * CalcSpecular(s.roughness, SNH, SH, N);\nif (cc_lightPos[i].w > 0.0) {\nfloat cosInner = max(dot(-cc_lightDir[i].xyz, SL), 0.01);\nfloat cosOuter = cc_lightSizeRangeAngle[i].z;\nfloat litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\nfloat litAngleOffset = -cosOuter * litAngleScale;\natt *= GetAngleAtt(SL, -cc_lightDir[i].xyz, litAngleScale, litAngleOffset);\n}\nvec3 lightColor = cc_lightColor[i].rgb;\nfloat shadow = 1.0;\n#if CC_RECEIVE_SHADOW\nif (cc_lightPos[i].w > 0.0 && cc_lightSizeRangeAngle[i].w > 0.0) {\nshadow = CCSpotShadowFactorBase(shadowPos, position, s.shadowBias);\n}\n#endif\nlightColor *= shadow;\nfinalColor += SNL * lightColor * cc_lightColor[i].w * illum * att * (diffuseContrib + lspec);\n}\nreturn vec4(finalColor, 0.0);\n}\n#endif\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 1\nlayout(std430, binding = 4) readonly buffer b_ccLightsBuffer { vec4 b_ccLights[]; };\nlayout(std430, binding = 5) readonly buffer b_clusterLightIndicesBuffer { uint b_clusterLightIndices[]; };\nlayout(std430, binding = 6) readonly buffer b_clusterLightGridBuffer { uvec4 b_clusterLightGrid[]; };\nstruct CCLight\n{\nvec4 cc_lightPos;\nvec4 cc_lightColor;\nvec4 cc_lightSizeRangeAngle;\nvec4 cc_lightDir;\n};\nstruct Cluster\n{\nvec3 minBounds;\nvec3 maxBounds;\n};\nstruct LightGrid\n{\nuint offset;\nuint ccLights;\n};\nCCLight getCCLight(uint i)\n{\nCCLight light;\nlight.cc_lightPos = b_ccLights[4u * i + 0u];\nlight.cc_lightColor = b_ccLights[4u * i + 1u];\nlight.cc_lightSizeRangeAngle = b_ccLights[4u * i + 2u];\nlight.cc_lightDir = b_ccLights[4u * i + 3u];\nreturn light;\n}\nLightGrid getLightGrid(uint cluster)\n{\nuvec4 gridvec = b_clusterLightGrid[cluster];\nLightGrid grid;\ngrid.offset = gridvec.x;\ngrid.ccLights = gridvec.y;\nreturn grid;\n}\nuint getGridLightIndex(uint start, uint offset)\n{\nreturn b_clusterLightIndices[start + offset];\n}\nuint getClusterZIndex(vec4 worldPos)\n{\nfloat scale = float(24) / log(cc_nearFar.y / cc_nearFar.x);\nfloat bias = -(float(24) * log(cc_nearFar.x) / log(cc_nearFar.y / cc_nearFar.x));\nfloat eyeDepth = -(cc_matView * worldPos).z;\nuint zIndex = uint(max(log(eyeDepth) * scale + bias, 0.0));\nreturn zIndex;\n}\nuint getClusterIndex(vec4 fragCoord, vec4 worldPos)\n{\nuint zIndex = getClusterZIndex(worldPos);\nfloat clusterSizeX = ceil(cc_viewPort.z / float(16));\nfloat clusterSizeY = ceil(cc_viewPort.w / float(8));\nuvec3 indices = uvec3(uvec2(fragCoord.xy / vec2(clusterSizeX, clusterSizeY)), zIndex);\nuint cluster = (16u * 8u) * indices.z + 16u * indices.y + indices.x;\nreturn cluster;\n}\nvec4 CCClusterShadingAdditive (StandardSurface s, vec4 shadowPos) {\nvec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\nvec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\nvec3 diffuseContrib = diffuse / PI;\nvec3 position;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nposition = unpackHighpData(s.position, s.position_fract_part);\n#else\nposition = s.position;\n#endif\nvec3 N = normalize(s.normal);\nvec3 V = normalize(cc_cameraPos.xyz - position);\nfloat NV = max(abs(dot(N, V)), 0.001);\nspecular = BRDFApprox(specular, s.roughness, NV);\nvec3 finalColor = vec3(0.0);\nuint cluster = getClusterIndex(gl_FragCoord, vec4(position, 1.0));\nLightGrid grid = getLightGrid(cluster);\nuint numLights = grid.ccLights;\nfor (uint i = 0u; i < 100u; i++) {\nif (i >= numLights) break;\nuint lightIndex = getGridLightIndex(grid.offset, i);\nCCLight light = getCCLight(lightIndex);\nvec3 SLU = light.cc_lightPos.xyz - position;\nvec3 SL = normalize(SLU);\nvec3 SH = normalize(SL + V);\nfloat SNL = max(dot(N, SL), 0.001);\nfloat SNH = max(dot(N, SH), 0.0);\nfloat distSqr = dot(SLU, SLU);\nfloat litRadius = light.cc_lightSizeRangeAngle.x;\nfloat litRadiusSqr = litRadius * litRadius;\nfloat illum = PI * (litRadiusSqr / max(litRadiusSqr , distSqr));\nfloat attRadiusSqrInv = 1.0 / max(light.cc_lightSizeRangeAngle.y, 0.01);\nattRadiusSqrInv *= attRadiusSqrInv;\nfloat att = GetDistAtt(distSqr, attRadiusSqrInv);\nvec3 lspec = specular * CalcSpecular(s.roughness, SNH, SH, N);\nif (light.cc_lightPos.w > 0.0) {\nfloat cosInner = max(dot(-light.cc_lightDir.xyz, SL), 0.01);\nfloat cosOuter = light.cc_lightSizeRangeAngle.z;\nfloat litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\nfloat litAngleOffset = -cosOuter * litAngleScale;\natt *= GetAngleAtt(SL, -light.cc_lightDir.xyz, litAngleScale, litAngleOffset);\n}\nvec3 lightColor = light.cc_lightColor.rgb;\nfloat shadow = 1.0;\n#if CC_RECEIVE_SHADOW\nif (light.cc_lightPos.w > 0.0) {\nshadow = CCSpotShadowFactorBase(shadowPos, position, s.shadowBias);\n}\n#endif\nlightColor *= shadow;\nfinalColor += SNL * lightColor * light.cc_lightColor.w * illum * att * (diffuseContrib + lspec);\n}\nreturn vec4(finalColor, 0.0);\n}\n#endif\nlayout(location = 0) out vec4 fragColorX;\nvoid main () {\nStandardSurface s; surf(s);\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 1\nvec4 color = CCClusterShadingAdditive(s, v_shadowPos);\n#else\nvec4 color = CCStandardShadingAdditive(s, v_shadowPos);\n#endif\nfragColorX = CCFragOutput(color);\n}\n#elif (CC_PIPELINE_TYPE == 0 || CC_FORCE_FORWARD_SHADING)\nlayout(location = 0) out vec4 fragColorX;\nvoid main () {\nStandardSurface s; surf(s);\nvec4 color = CCStandardShadingBase(s, v_shadowPos);\nCC_APPLY_FOG(color, s.position.xyz);\nfragColorX = CCFragOutput(color);\n}\n#elif CC_PIPELINE_TYPE == 1\nvec2 signNotZero(vec2 v) {\nreturn vec2((v.x >= 0.0) ? +1.0 : -1.0, (v.y >= 0.0) ? +1.0 : -1.0);\n}\nvec2 float32x3_to_oct(in vec3 v) {\nvec2 p = v.xy * (1.0 / (abs(v.x) + abs(v.y) + abs(v.z)));\nreturn (v.z <= 0.0) ? ((1.0 - abs(p.yx)) * signNotZero(p)) : p;\n}\nlayout(location = 0) out vec4 fragColor0;\nlayout(location = 1) out vec4 fragColor1;\nlayout(location = 2) out vec4 fragColor2;\nvoid main () {\nStandardSurface s; surf(s);\nfragColor0 = s.albedo;\nfragColor1 = vec4(float32x3_to_oct(s.normal), s.roughness, s.metallic);\nfragColor2 = vec4(s.emissive, s.occlusion);\n}\n#endif", }, { "vert": "\nprecision highp float;\nlayout(std140) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(std140) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\nlayout(std140) uniform CCLocal {\nhighp mat4 cc_matWorld;\nhighp mat4 cc_matWorldIT;\nhighp vec4 cc_lightingMapUVParam;\nhighp vec4 cc_localShadowBias;\n};\nlayout(std140) uniform CCShadow {\nhighp mat4 cc_matLightPlaneProj;\nhighp mat4 cc_matLightView;\nhighp mat4 cc_matLightViewProj;\nhighp vec4 cc_shadowInvProjDepthInfo;\nhighp vec4 cc_shadowProjDepthInfo;\nhighp vec4 cc_shadowProjInfo;\nmediump vec4 cc_shadowNFLSInfo;\nmediump vec4 cc_shadowWHPBInfo;\nmediump vec4 cc_shadowLPNNInfo;\nlowp vec4 cc_shadowColor;\nmediump vec4 cc_planarNDInfo;\n};\nin vec3 a_position;\nin vec3 a_normal;\nin vec2 a_texCoord;\nout vec2 v_clip_depth;\nvec4 vert () {\nvec4 worldPos;\nworldPos.x = cc_matWorld[3][0] + a_position.x;\nworldPos.y = cc_matWorld[3][1] + a_position.y;\nworldPos.z = cc_matWorld[3][2] + a_position.z;\nworldPos.w = 1.0;\nvec4 clipPos = cc_matLightViewProj * worldPos;\nv_clip_depth = clipPos.zw;\nreturn clipPos;\n}\nvoid main() { gl_Position = vert(); }", @@ -108,49 +108,49 @@ export const glsl3 = [ ], [ { - "vert": "\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\nrgba = rgba * 255.0;\nhighp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\nhighp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\nhighp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\nreturn Sign * exp2(Exponent - 23.0) * Mantissa;\n}\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nin vec3 a_position;\nin vec3 a_normal;\nin vec2 a_texCoord;\nin vec4 a_tangent;\n#if CC_USE_SKINNING\nin vec4 a_joints;\nin vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nin highp vec4 a_jointAnimInfo;\n#endif\nin vec4 a_matWorld0;\nin vec4 a_matWorld1;\nin vec4 a_matWorld2;\n#if USE_LIGHTMAP\nin vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nin vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nin float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nin float a_vertexId;\nint getVertexId() {\nreturn int(a_vertexId);\n}\n#endif\n#if CC_USE_MORPH\nlayout(std140) uniform CCMorph {\nvec4 cc_displacementWeights[15];\nvec4 cc_displacementTextureInfo;\n};\nvec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\nfloat pixelIndexF = float(pixelIndex);\nfloat x = mod(pixelIndexF, textureResolution.x);\nfloat y = floor(pixelIndexF / textureResolution.x);\nreturn vec2(x, y);\n}\nvec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\nreturn (vec2(location.x, location.y) + .5) / textureResolution;\n}\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int pixelIndex) {\nivec2 texSize = textureSize(tex, 0);\nreturn texelFetch(tex, ivec2(pixelIndex % texSize.x, pixelIndex / texSize.x), 0);\n}\n#else\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex * 4;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\nreturn vec4(\ndecode32(texture(tex, x)),\ndecode32(texture(tex, y)),\ndecode32(texture(tex, z)),\n1.0\n);\n}\n#endif\nfloat getDisplacementWeight(int index) {\nint quot = index / 4;\nint remainder = index - quot * 4;\nif (remainder == 0) {\nreturn cc_displacementWeights[quot].x;\n} else if (remainder == 1) {\nreturn cc_displacementWeights[quot].y;\n} else if (remainder == 2) {\nreturn cc_displacementWeights[quot].z;\n} else {\nreturn cc_displacementWeights[quot].w;\n}\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\nreturn fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n#else\nvec3 result = vec3(0, 0, 0);\nint nVertices = int(cc_displacementTextureInfo.z);\nfor (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\nresult += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n}\nreturn result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\nuniform sampler2D cc_PositionDisplacements;\nvec3 getPositionDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nuniform sampler2D cc_NormalDisplacements;\nvec3 getNormalDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\nuniform sampler2D cc_TangentDisplacements;\nvec3 getTangentDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n}\n#endif\nvoid applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nint vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nnormal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\ntangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\n#if CC_USE_BAKED_ANIMATION\nlayout(std140) uniform CCSkinningTexture {\nhighp vec4 cc_jointTextureInfo;\n};\nlayout(std140) uniform CCSkinningAnimation {\nhighp vec4 cc_jointAnimInfo;\n};\nuniform highp sampler2D cc_jointTexture;\nvoid CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n{\n#if USE_INSTANCING\nhighp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n#else\nhighp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n#endif\ninvSize = cc_jointTextureInfo.w;\nhighp float tempY = floor(temp * invSize);\nx = floor(temp - tempY * cc_jointTextureInfo.x);\ny = (tempY + 0.5) * invSize;\n}\n#else\nlayout(std140) uniform CCSkinning {\nhighp vec4 cc_joints[30 * 3];\n};\n#endif\n#if CC_USE_BAKED_ANIMATION\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(3.0, i, x, y, invSize);\nvec4 v1 = texture(cc_jointTexture, vec2((x + 0.5) * invSize, y));\nvec4 v2 = texture(cc_jointTexture, vec2((x + 1.5) * invSize, y));\nvec4 v3 = texture(cc_jointTexture, vec2((x + 2.5) * invSize, y));\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#else\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(12.0, i, x, y, invSize);\nvec4 v1 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n);\nvec4 v2 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n);\nvec4 v3 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n);\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\n#else\nmat4 getJointMatrix (float i) {\nint idx = int(i);\nvec4 v1 = cc_joints[idx * 3];\nvec4 v2 = cc_joints[idx * 3 + 1];\nvec4 v3 = cc_joints[idx * 3 + 2];\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\nmat4 skinMatrix () {\nvec4 joints = vec4(a_joints);\nreturn getJointMatrix(joints.x) * a_weights.x\n+ getJointMatrix(joints.y) * a_weights.y\n+ getJointMatrix(joints.z) * a_weights.z\n+ getJointMatrix(joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\nmat4 m = skinMatrix();\nposition = m * position;\n}\nvoid CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nmat4 m = skinMatrix();\nposition = m * position;\nnormal = (m * vec4(normal, 0.0)).xyz;\ntangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n}\n#endif\nvoid CCVertInput(inout vec4 In)\n{\nIn = vec4(a_position, 1.0);\n#if CC_USE_MORPH\napplyMorph(In);\n#endif\n#if CC_USE_SKINNING\nCCSkin(In);\n#endif\n}\nlayout(std140) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(std140) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\n#if !USE_INSTANCING\n#if USE_BATCHING\nlayout(std140) uniform CCLocalBatched {\nhighp mat4 cc_matWorlds[10];\n};\n#else\nlayout(std140) uniform CCLocal {\nhighp mat4 cc_matWorld;\nhighp mat4 cc_matWorldIT;\nhighp vec4 cc_lightingMapUVParam;\nhighp vec4 cc_localShadowBias;\n};\n#endif\n#endif\nvoid CCGetWorldMatrix(out mat4 matWorld)\n{\n#if USE_INSTANCING\nmatWorld = mat4(\nvec4(a_matWorld0.xyz, 0.0),\nvec4(a_matWorld1.xyz, 0.0),\nvec4(a_matWorld2.xyz, 0.0),\nvec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)\n);\n#elif USE_BATCHING\nmatWorld = cc_matWorlds[int(a_dyn_batch_id)];\n#else\nmatWorld = cc_matWorld;\n#endif\n}\nfloat LinearFog(vec4 pos) {\nvec4 wPos = pos;\nfloat cam_dis = distance(cc_cameraPos, wPos);\nfloat fogStart = cc_fogBase.x;\nfloat fogEnd = cc_fogBase.y;\nreturn clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * fogDensity);\nreturn f;\n}\nfloat ExpSquaredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\nreturn f;\n}\nfloat LayeredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat _FogTop = cc_fogAdd.x;\nfloat _FogRange = cc_fogAdd.y;\nvec3 camWorldProj = cc_cameraPos.xyz;\ncamWorldProj.y = 0.;\nvec3 worldPosProj = wPos.xyz;\nworldPosProj.y = 0.;\nfloat fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\nfloat fDeltaY, fDensityIntegral;\nif (cc_cameraPos.y > _FogTop) {\nif (wPos.y < _FogTop) {\nfDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\nfDensityIntegral = fDeltaY * fDeltaY * 0.5;\n} else {\nfDeltaY = 0.;\nfDensityIntegral = 0.;\n}\n} else {\nif (wPos.y < _FogTop) {\nfloat fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfloat fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\nfDeltaY = abs(fDeltaA - fDeltaB);\nfDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n} else {\nfDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n}\n}\nfloat fDensity;\nif (fDeltaY != 0.) {\nfDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n} else {\nfDensity = 0.;\n}\nfloat f = exp(-fDensity);\nreturn f;\n}\nvoid CC_TRANSFER_FOG_BASE(vec4 pos, out float factor)\n{\n#if CC_USE_FOG == 0\nfactor = LinearFog(pos);\n#elif CC_USE_FOG == 1\nfactor = ExpFog(pos);\n#elif CC_USE_FOG == 2\nfactor = ExpSquaredFog(pos);\n#elif CC_USE_FOG == 3\nfactor = LayeredFog(pos);\n#else\nfactor = 1.0;\n#endif\n}\n#if !CC_USE_ACCURATE_FOG\nout float v_fog_factor;\n#endif\nvoid CC_TRANSFER_FOG(vec4 pos) {\n#if !CC_USE_ACCURATE_FOG\nCC_TRANSFER_FOG_BASE(pos, v_fog_factor);\n#endif\n}\n#if USE_VERTEX_COLOR\nin lowp vec4 a_color;\nout lowp vec4 v_color;\n#endif\n#if USE_TEXTURE\nout vec2 v_uv;\nlayout(std140) uniform TexCoords {\nvec4 tilingOffset;\n};\n#endif\nvec4 vert () {\nvec4 position;\nCCVertInput(position);\nmat4 matWorld;\nCCGetWorldMatrix(matWorld);\n#if USE_TEXTURE\nv_uv = a_texCoord * tilingOffset.xy + tilingOffset.zw;\n#if SAMPLE_FROM_RT\nv_uv = cc_cameraPos.w > 1.0 ? vec2(v_uv.x, 1.0 - v_uv.y) : v_uv;\n#endif\n#endif\n#if USE_VERTEX_COLOR\nv_color = a_color;\n#endif\nCC_TRANSFER_FOG(matWorld * position);\nreturn cc_matProj * (cc_matView * matWorld) * position;\n}\nvoid main() { gl_Position = vert(); }", + "vert": "\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\nrgba = rgba * 255.0;\nhighp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\nhighp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\nhighp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\nreturn Sign * exp2(Exponent - 23.0) * Mantissa;\n}\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nin vec3 a_position;\nin vec3 a_normal;\nin vec2 a_texCoord;\nin vec4 a_tangent;\n#if CC_USE_SKINNING\nin vec4 a_joints;\nin vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nin highp vec4 a_jointAnimInfo;\n#endif\nin vec4 a_matWorld0;\nin vec4 a_matWorld1;\nin vec4 a_matWorld2;\n#if CC_USE_LIGHTMAP\nin vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nin vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nin float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nin float a_vertexId;\nint getVertexId() {\nreturn int(a_vertexId);\n}\n#endif\n#if CC_USE_MORPH\nlayout(std140) uniform CCMorph {\nvec4 cc_displacementWeights[15];\nvec4 cc_displacementTextureInfo;\n};\nvec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\nfloat pixelIndexF = float(pixelIndex);\nfloat x = mod(pixelIndexF, textureResolution.x);\nfloat y = floor(pixelIndexF / textureResolution.x);\nreturn vec2(x, y);\n}\nvec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\nreturn (vec2(location.x, location.y) + .5) / textureResolution;\n}\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int pixelIndex) {\nivec2 texSize = textureSize(tex, 0);\nreturn texelFetch(tex, ivec2(pixelIndex % texSize.x, pixelIndex / texSize.x), 0);\n}\n#else\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex * 4;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\nreturn vec4(\ndecode32(texture(tex, x)),\ndecode32(texture(tex, y)),\ndecode32(texture(tex, z)),\n1.0\n);\n}\n#endif\nfloat getDisplacementWeight(int index) {\nint quot = index / 4;\nint remainder = index - quot * 4;\nif (remainder == 0) {\nreturn cc_displacementWeights[quot].x;\n} else if (remainder == 1) {\nreturn cc_displacementWeights[quot].y;\n} else if (remainder == 2) {\nreturn cc_displacementWeights[quot].z;\n} else {\nreturn cc_displacementWeights[quot].w;\n}\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\nreturn fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n#else\nvec3 result = vec3(0, 0, 0);\nint nVertices = int(cc_displacementTextureInfo.z);\nfor (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\nresult += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n}\nreturn result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\nuniform sampler2D cc_PositionDisplacements;\nvec3 getPositionDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nuniform sampler2D cc_NormalDisplacements;\nvec3 getNormalDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\nuniform sampler2D cc_TangentDisplacements;\nvec3 getTangentDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n}\n#endif\nvoid applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nint vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nnormal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\ntangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\n#if CC_USE_BAKED_ANIMATION\nlayout(std140) uniform CCSkinningTexture {\nhighp vec4 cc_jointTextureInfo;\n};\nlayout(std140) uniform CCSkinningAnimation {\nhighp vec4 cc_jointAnimInfo;\n};\nuniform highp sampler2D cc_jointTexture;\nvoid CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n{\n#if USE_INSTANCING\nhighp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n#else\nhighp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n#endif\ninvSize = cc_jointTextureInfo.w;\nhighp float tempY = floor(temp * invSize);\nx = floor(temp - tempY * cc_jointTextureInfo.x);\ny = (tempY + 0.5) * invSize;\n}\n#else\nlayout(std140) uniform CCSkinning {\nhighp vec4 cc_joints[30 * 3];\n};\n#endif\n#if CC_USE_BAKED_ANIMATION\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(3.0, i, x, y, invSize);\nvec4 v1 = texture(cc_jointTexture, vec2((x + 0.5) * invSize, y));\nvec4 v2 = texture(cc_jointTexture, vec2((x + 1.5) * invSize, y));\nvec4 v3 = texture(cc_jointTexture, vec2((x + 2.5) * invSize, y));\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#else\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(12.0, i, x, y, invSize);\nvec4 v1 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n);\nvec4 v2 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n);\nvec4 v3 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n);\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\n#else\nmat4 getJointMatrix (float i) {\nint idx = int(i);\nvec4 v1 = cc_joints[idx * 3];\nvec4 v2 = cc_joints[idx * 3 + 1];\nvec4 v3 = cc_joints[idx * 3 + 2];\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\nmat4 skinMatrix () {\nvec4 joints = vec4(a_joints);\nreturn getJointMatrix(joints.x) * a_weights.x\n+ getJointMatrix(joints.y) * a_weights.y\n+ getJointMatrix(joints.z) * a_weights.z\n+ getJointMatrix(joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\nmat4 m = skinMatrix();\nposition = m * position;\n}\nvoid CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nmat4 m = skinMatrix();\nposition = m * position;\nnormal = (m * vec4(normal, 0.0)).xyz;\ntangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n}\n#endif\nvoid CCVertInput(inout vec4 In)\n{\nIn = vec4(a_position, 1.0);\n#if CC_USE_MORPH\napplyMorph(In);\n#endif\n#if CC_USE_SKINNING\nCCSkin(In);\n#endif\n}\nlayout(std140) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(std140) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\n#if !USE_INSTANCING\n#if USE_BATCHING\nlayout(std140) uniform CCLocalBatched {\nhighp mat4 cc_matWorlds[10];\n};\n#else\nlayout(std140) uniform CCLocal {\nhighp mat4 cc_matWorld;\nhighp mat4 cc_matWorldIT;\nhighp vec4 cc_lightingMapUVParam;\nhighp vec4 cc_localShadowBias;\n};\n#endif\n#endif\nvoid CCGetWorldMatrix(out mat4 matWorld)\n{\n#if USE_INSTANCING\nmatWorld = mat4(\nvec4(a_matWorld0.xyz, 0.0),\nvec4(a_matWorld1.xyz, 0.0),\nvec4(a_matWorld2.xyz, 0.0),\nvec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)\n);\n#elif USE_BATCHING\nmatWorld = cc_matWorlds[int(a_dyn_batch_id)];\n#else\nmatWorld = cc_matWorld;\n#endif\n}\nfloat LinearFog(vec4 pos) {\nvec4 wPos = pos;\nfloat cam_dis = distance(cc_cameraPos, wPos);\nfloat fogStart = cc_fogBase.x;\nfloat fogEnd = cc_fogBase.y;\nreturn clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * fogDensity);\nreturn f;\n}\nfloat ExpSquaredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\nreturn f;\n}\nfloat LayeredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat _FogTop = cc_fogAdd.x;\nfloat _FogRange = cc_fogAdd.y;\nvec3 camWorldProj = cc_cameraPos.xyz;\ncamWorldProj.y = 0.;\nvec3 worldPosProj = wPos.xyz;\nworldPosProj.y = 0.;\nfloat fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\nfloat fDeltaY, fDensityIntegral;\nif (cc_cameraPos.y > _FogTop) {\nif (wPos.y < _FogTop) {\nfDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\nfDensityIntegral = fDeltaY * fDeltaY * 0.5;\n} else {\nfDeltaY = 0.;\nfDensityIntegral = 0.;\n}\n} else {\nif (wPos.y < _FogTop) {\nfloat fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfloat fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\nfDeltaY = abs(fDeltaA - fDeltaB);\nfDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n} else {\nfDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n}\n}\nfloat fDensity;\nif (fDeltaY != 0.) {\nfDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n} else {\nfDensity = 0.;\n}\nfloat f = exp(-fDensity);\nreturn f;\n}\nvoid CC_TRANSFER_FOG_BASE(vec4 pos, out float factor)\n{\n#if CC_USE_FOG == 0\nfactor = LinearFog(pos);\n#elif CC_USE_FOG == 1\nfactor = ExpFog(pos);\n#elif CC_USE_FOG == 2\nfactor = ExpSquaredFog(pos);\n#elif CC_USE_FOG == 3\nfactor = LayeredFog(pos);\n#else\nfactor = 1.0;\n#endif\n}\n#if !CC_USE_ACCURATE_FOG\nout float v_fog_factor;\n#endif\nvoid CC_TRANSFER_FOG(vec4 pos) {\n#if !CC_USE_ACCURATE_FOG\nCC_TRANSFER_FOG_BASE(pos, v_fog_factor);\n#endif\n}\n#if USE_VERTEX_COLOR\nin lowp vec4 a_color;\nout lowp vec4 v_color;\n#endif\n#if USE_TEXTURE\nout vec2 v_uv;\nlayout(std140) uniform TexCoords {\nvec4 tilingOffset;\n};\n#endif\nvec4 vert () {\nvec4 position;\nCCVertInput(position);\nmat4 matWorld;\nCCGetWorldMatrix(matWorld);\n#if USE_TEXTURE\nv_uv = a_texCoord * tilingOffset.xy + tilingOffset.zw;\n#if SAMPLE_FROM_RT\nv_uv = cc_cameraPos.w > 1.0 ? vec2(v_uv.x, 1.0 - v_uv.y) : v_uv;\n#endif\n#endif\n#if USE_VERTEX_COLOR\nv_color = a_color;\n#endif\nCC_TRANSFER_FOG(matWorld * position);\nreturn cc_matProj * (cc_matView * matWorld) * position;\n}\nvoid main() { gl_Position = vert(); }", "frag": "\nprecision highp float;\nvec3 ACESToneMap (vec3 color) {\ncolor = min(color, vec3(8.0));\nconst float A = 2.51;\nconst float B = 0.03;\nconst float C = 2.43;\nconst float D = 0.59;\nconst float E = 0.14;\nreturn (color * (A * color + B)) / (color * (C * color + D) + E);\n}\nvec3 SRGBToLinear (vec3 gamma) {\nreturn gamma * gamma;\n}\nvec4 CCFragOutput (vec4 color) {\n#if CC_USE_HDR\ncolor.rgb = ACESToneMap(color.rgb);\n#endif\ncolor.rgb = sqrt(color.rgb);\nreturn color;\n}\nlayout(std140) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(std140) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\nfloat LinearFog(vec4 pos) {\nvec4 wPos = pos;\nfloat cam_dis = distance(cc_cameraPos, wPos);\nfloat fogStart = cc_fogBase.x;\nfloat fogEnd = cc_fogBase.y;\nreturn clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * fogDensity);\nreturn f;\n}\nfloat ExpSquaredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\nreturn f;\n}\nfloat LayeredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat _FogTop = cc_fogAdd.x;\nfloat _FogRange = cc_fogAdd.y;\nvec3 camWorldProj = cc_cameraPos.xyz;\ncamWorldProj.y = 0.;\nvec3 worldPosProj = wPos.xyz;\nworldPosProj.y = 0.;\nfloat fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\nfloat fDeltaY, fDensityIntegral;\nif (cc_cameraPos.y > _FogTop) {\nif (wPos.y < _FogTop) {\nfDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\nfDensityIntegral = fDeltaY * fDeltaY * 0.5;\n} else {\nfDeltaY = 0.;\nfDensityIntegral = 0.;\n}\n} else {\nif (wPos.y < _FogTop) {\nfloat fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfloat fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\nfDeltaY = abs(fDeltaA - fDeltaB);\nfDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n} else {\nfDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n}\n}\nfloat fDensity;\nif (fDeltaY != 0.) {\nfDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n} else {\nfDensity = 0.;\n}\nfloat f = exp(-fDensity);\nreturn f;\n}\nvoid CC_TRANSFER_FOG_BASE(vec4 pos, out float factor)\n{\n#if CC_USE_FOG == 0\nfactor = LinearFog(pos);\n#elif CC_USE_FOG == 1\nfactor = ExpFog(pos);\n#elif CC_USE_FOG == 2\nfactor = ExpSquaredFog(pos);\n#elif CC_USE_FOG == 3\nfactor = LayeredFog(pos);\n#else\nfactor = 1.0;\n#endif\n}\nvoid CC_APPLY_FOG_BASE(inout vec4 color, float factor) {\ncolor = vec4(mix(cc_fogColor.rgb, color.rgb, factor), color.a);\n}\n#if !CC_USE_ACCURATE_FOG\nin float v_fog_factor;\n#endif\nvoid CC_APPLY_FOG(inout vec4 color) {\n#if !CC_USE_ACCURATE_FOG\nCC_APPLY_FOG_BASE(color, v_fog_factor);\n#endif\n}\nvoid CC_APPLY_FOG(inout vec4 color, vec3 worldPos) {\n#if CC_USE_ACCURATE_FOG\nfloat factor;\nCC_TRANSFER_FOG_BASE(vec4(worldPos, 1.0), factor);\n#else\nfloat factor = v_fog_factor;\n#endif\nCC_APPLY_FOG_BASE(color, factor);\n}\n#if USE_ALPHA_TEST\n#endif\n#if USE_TEXTURE\nin vec2 v_uv;\nuniform sampler2D mainTexture;\n#endif\nlayout(std140) uniform Constant {\nvec4 mainColor;\nvec4 colorScaleAndCutoff;\n};\n#if USE_VERTEX_COLOR\nin lowp vec4 v_color;\n#endif\nvec4 frag () {\nvec4 o = mainColor;\no.rgb *= colorScaleAndCutoff.xyz;\n#if USE_VERTEX_COLOR\no.rgb *= SRGBToLinear(v_color.rgb);\no.a *= v_color.a;\n#endif\n#if USE_TEXTURE\nvec4 texColor = texture(mainTexture, v_uv);\ntexColor.rgb = SRGBToLinear(texColor.rgb);\no *= texColor;\n#endif\n#if USE_ALPHA_TEST\nif (o.ALPHA_TEST_CHANNEL < colorScaleAndCutoff.w) discard;\n#endif\nCC_APPLY_FOG(o);\nreturn CCFragOutput(o);\n}\nlayout(location = 0) out vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }", } ], [ { - "vert": "\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\nrgba = rgba * 255.0;\nhighp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\nhighp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\nhighp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\nreturn Sign * exp2(Exponent - 23.0) * Mantissa;\n}\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nin vec3 a_position;\nin vec3 a_normal;\nin vec2 a_texCoord;\nin vec4 a_tangent;\n#if CC_USE_SKINNING\nin vec4 a_joints;\nin vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nin highp vec4 a_jointAnimInfo;\n#endif\nin vec4 a_matWorld0;\nin vec4 a_matWorld1;\nin vec4 a_matWorld2;\n#if USE_LIGHTMAP\nin vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nin vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nin float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nin float a_vertexId;\nint getVertexId() {\nreturn int(a_vertexId);\n}\n#endif\n#if CC_USE_MORPH\nlayout(std140) uniform CCMorph {\nvec4 cc_displacementWeights[15];\nvec4 cc_displacementTextureInfo;\n};\nvec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\nfloat pixelIndexF = float(pixelIndex);\nfloat x = mod(pixelIndexF, textureResolution.x);\nfloat y = floor(pixelIndexF / textureResolution.x);\nreturn vec2(x, y);\n}\nvec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\nreturn (vec2(location.x, location.y) + .5) / textureResolution;\n}\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int pixelIndex) {\nivec2 texSize = textureSize(tex, 0);\nreturn texelFetch(tex, ivec2(pixelIndex % texSize.x, pixelIndex / texSize.x), 0);\n}\n#else\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex * 4;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\nreturn vec4(\ndecode32(texture(tex, x)),\ndecode32(texture(tex, y)),\ndecode32(texture(tex, z)),\n1.0\n);\n}\n#endif\nfloat getDisplacementWeight(int index) {\nint quot = index / 4;\nint remainder = index - quot * 4;\nif (remainder == 0) {\nreturn cc_displacementWeights[quot].x;\n} else if (remainder == 1) {\nreturn cc_displacementWeights[quot].y;\n} else if (remainder == 2) {\nreturn cc_displacementWeights[quot].z;\n} else {\nreturn cc_displacementWeights[quot].w;\n}\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\nreturn fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n#else\nvec3 result = vec3(0, 0, 0);\nint nVertices = int(cc_displacementTextureInfo.z);\nfor (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\nresult += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n}\nreturn result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\nuniform sampler2D cc_PositionDisplacements;\nvec3 getPositionDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nuniform sampler2D cc_NormalDisplacements;\nvec3 getNormalDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\nuniform sampler2D cc_TangentDisplacements;\nvec3 getTangentDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n}\n#endif\nvoid applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nint vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nnormal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\ntangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\n#if CC_USE_BAKED_ANIMATION\nlayout(std140) uniform CCSkinningTexture {\nhighp vec4 cc_jointTextureInfo;\n};\nlayout(std140) uniform CCSkinningAnimation {\nhighp vec4 cc_jointAnimInfo;\n};\nuniform highp sampler2D cc_jointTexture;\nvoid CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n{\n#if USE_INSTANCING\nhighp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n#else\nhighp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n#endif\ninvSize = cc_jointTextureInfo.w;\nhighp float tempY = floor(temp * invSize);\nx = floor(temp - tempY * cc_jointTextureInfo.x);\ny = (tempY + 0.5) * invSize;\n}\n#else\nlayout(std140) uniform CCSkinning {\nhighp vec4 cc_joints[30 * 3];\n};\n#endif\n#if CC_USE_BAKED_ANIMATION\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(3.0, i, x, y, invSize);\nvec4 v1 = texture(cc_jointTexture, vec2((x + 0.5) * invSize, y));\nvec4 v2 = texture(cc_jointTexture, vec2((x + 1.5) * invSize, y));\nvec4 v3 = texture(cc_jointTexture, vec2((x + 2.5) * invSize, y));\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#else\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(12.0, i, x, y, invSize);\nvec4 v1 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n);\nvec4 v2 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n);\nvec4 v3 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n);\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\n#else\nmat4 getJointMatrix (float i) {\nint idx = int(i);\nvec4 v1 = cc_joints[idx * 3];\nvec4 v2 = cc_joints[idx * 3 + 1];\nvec4 v3 = cc_joints[idx * 3 + 2];\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\nmat4 skinMatrix () {\nvec4 joints = vec4(a_joints);\nreturn getJointMatrix(joints.x) * a_weights.x\n+ getJointMatrix(joints.y) * a_weights.y\n+ getJointMatrix(joints.z) * a_weights.z\n+ getJointMatrix(joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\nmat4 m = skinMatrix();\nposition = m * position;\n}\nvoid CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nmat4 m = skinMatrix();\nposition = m * position;\nnormal = (m * vec4(normal, 0.0)).xyz;\ntangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n}\n#endif\nvoid CCVertInput(inout StandardVertInput In)\n{\nIn.position = vec4(a_position, 1.0);\nIn.normal = a_normal;\nIn.tangent = a_tangent;\n#if CC_USE_MORPH\napplyMorph(In.position, In.normal, In.tangent);\n#endif\n#if CC_USE_SKINNING\nCCSkin(In.position, In.normal, In.tangent);\n#endif\n}\nlayout(std140) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(std140) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\nout vec2 v_uv;\nvoid main () {\nStandardVertInput In;\nCCVertInput(In);\nIn.position.xy = cc_cameraPos.w == 0.0 ? vec2(In.position.xy.x, -In.position.xy.y) : In.position.xy;\ngl_Position = In.position;\ngl_Position.y = gl_Position.y;\nv_uv = a_texCoord;\n}", + "vert": "\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\nrgba = rgba * 255.0;\nhighp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\nhighp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\nhighp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\nreturn Sign * exp2(Exponent - 23.0) * Mantissa;\n}\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nin vec3 a_position;\nin vec3 a_normal;\nin vec2 a_texCoord;\nin vec4 a_tangent;\n#if CC_USE_SKINNING\nin vec4 a_joints;\nin vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nin highp vec4 a_jointAnimInfo;\n#endif\nin vec4 a_matWorld0;\nin vec4 a_matWorld1;\nin vec4 a_matWorld2;\n#if CC_USE_LIGHTMAP\nin vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nin vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nin float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nin float a_vertexId;\nint getVertexId() {\nreturn int(a_vertexId);\n}\n#endif\n#if CC_USE_MORPH\nlayout(std140) uniform CCMorph {\nvec4 cc_displacementWeights[15];\nvec4 cc_displacementTextureInfo;\n};\nvec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\nfloat pixelIndexF = float(pixelIndex);\nfloat x = mod(pixelIndexF, textureResolution.x);\nfloat y = floor(pixelIndexF / textureResolution.x);\nreturn vec2(x, y);\n}\nvec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\nreturn (vec2(location.x, location.y) + .5) / textureResolution;\n}\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int pixelIndex) {\nivec2 texSize = textureSize(tex, 0);\nreturn texelFetch(tex, ivec2(pixelIndex % texSize.x, pixelIndex / texSize.x), 0);\n}\n#else\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex * 4;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\nreturn vec4(\ndecode32(texture(tex, x)),\ndecode32(texture(tex, y)),\ndecode32(texture(tex, z)),\n1.0\n);\n}\n#endif\nfloat getDisplacementWeight(int index) {\nint quot = index / 4;\nint remainder = index - quot * 4;\nif (remainder == 0) {\nreturn cc_displacementWeights[quot].x;\n} else if (remainder == 1) {\nreturn cc_displacementWeights[quot].y;\n} else if (remainder == 2) {\nreturn cc_displacementWeights[quot].z;\n} else {\nreturn cc_displacementWeights[quot].w;\n}\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\nreturn fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n#else\nvec3 result = vec3(0, 0, 0);\nint nVertices = int(cc_displacementTextureInfo.z);\nfor (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\nresult += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n}\nreturn result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\nuniform sampler2D cc_PositionDisplacements;\nvec3 getPositionDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nuniform sampler2D cc_NormalDisplacements;\nvec3 getNormalDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\nuniform sampler2D cc_TangentDisplacements;\nvec3 getTangentDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n}\n#endif\nvoid applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nint vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nnormal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\ntangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\n#if CC_USE_BAKED_ANIMATION\nlayout(std140) uniform CCSkinningTexture {\nhighp vec4 cc_jointTextureInfo;\n};\nlayout(std140) uniform CCSkinningAnimation {\nhighp vec4 cc_jointAnimInfo;\n};\nuniform highp sampler2D cc_jointTexture;\nvoid CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n{\n#if USE_INSTANCING\nhighp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n#else\nhighp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n#endif\ninvSize = cc_jointTextureInfo.w;\nhighp float tempY = floor(temp * invSize);\nx = floor(temp - tempY * cc_jointTextureInfo.x);\ny = (tempY + 0.5) * invSize;\n}\n#else\nlayout(std140) uniform CCSkinning {\nhighp vec4 cc_joints[30 * 3];\n};\n#endif\n#if CC_USE_BAKED_ANIMATION\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(3.0, i, x, y, invSize);\nvec4 v1 = texture(cc_jointTexture, vec2((x + 0.5) * invSize, y));\nvec4 v2 = texture(cc_jointTexture, vec2((x + 1.5) * invSize, y));\nvec4 v3 = texture(cc_jointTexture, vec2((x + 2.5) * invSize, y));\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#else\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(12.0, i, x, y, invSize);\nvec4 v1 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n);\nvec4 v2 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n);\nvec4 v3 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n);\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\n#else\nmat4 getJointMatrix (float i) {\nint idx = int(i);\nvec4 v1 = cc_joints[idx * 3];\nvec4 v2 = cc_joints[idx * 3 + 1];\nvec4 v3 = cc_joints[idx * 3 + 2];\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\nmat4 skinMatrix () {\nvec4 joints = vec4(a_joints);\nreturn getJointMatrix(joints.x) * a_weights.x\n+ getJointMatrix(joints.y) * a_weights.y\n+ getJointMatrix(joints.z) * a_weights.z\n+ getJointMatrix(joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\nmat4 m = skinMatrix();\nposition = m * position;\n}\nvoid CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nmat4 m = skinMatrix();\nposition = m * position;\nnormal = (m * vec4(normal, 0.0)).xyz;\ntangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n}\n#endif\nvoid CCVertInput(inout StandardVertInput In)\n{\nIn.position = vec4(a_position, 1.0);\nIn.normal = a_normal;\nIn.tangent = a_tangent;\n#if CC_USE_MORPH\napplyMorph(In.position, In.normal, In.tangent);\n#endif\n#if CC_USE_SKINNING\nCCSkin(In.position, In.normal, In.tangent);\n#endif\n}\nlayout(std140) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(std140) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\nout vec2 v_uv;\nvoid main () {\nStandardVertInput In;\nCCVertInput(In);\nIn.position.xy = cc_cameraPos.w == 0.0 ? vec2(In.position.xy.x, -In.position.xy.y) : In.position.xy;\ngl_Position = In.position;\ngl_Position.y = gl_Position.y;\nv_uv = a_texCoord;\n}", "frag": "\nprecision highp float;\nlayout(std140) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(std140) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\nvec3 SRGBToLinear (vec3 gamma) {\nreturn gamma * gamma;\n}\nin vec2 v_uv;\nlayout(std140) uniform BloomUBO {\nmediump vec4 texSize;\n};\nuniform sampler2D outputResultMap;\nlayout(location = 0) out vec4 fragColor;\nfloat luminance(vec3 color) {\nreturn dot(color, vec3(0.2126, 0.7152, 0.0722));\n}\nvoid main() {\nvec3 color = texture(outputResultMap, v_uv).xyz;\nif (luminance(SRGBToLinear(color)) > texSize.z) {\nfragColor = vec4(color, 1.0);\n} else {\nfragColor = vec4(0.0, 0.0, 0.0, 1.0);\n}\n}", }, { - "vert": "\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\nrgba = rgba * 255.0;\nhighp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\nhighp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\nhighp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\nreturn Sign * exp2(Exponent - 23.0) * Mantissa;\n}\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nin vec3 a_position;\nin vec3 a_normal;\nin vec2 a_texCoord;\nin vec4 a_tangent;\n#if CC_USE_SKINNING\nin vec4 a_joints;\nin vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nin highp vec4 a_jointAnimInfo;\n#endif\nin vec4 a_matWorld0;\nin vec4 a_matWorld1;\nin vec4 a_matWorld2;\n#if USE_LIGHTMAP\nin vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nin vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nin float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nin float a_vertexId;\nint getVertexId() {\nreturn int(a_vertexId);\n}\n#endif\n#if CC_USE_MORPH\nlayout(std140) uniform CCMorph {\nvec4 cc_displacementWeights[15];\nvec4 cc_displacementTextureInfo;\n};\nvec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\nfloat pixelIndexF = float(pixelIndex);\nfloat x = mod(pixelIndexF, textureResolution.x);\nfloat y = floor(pixelIndexF / textureResolution.x);\nreturn vec2(x, y);\n}\nvec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\nreturn (vec2(location.x, location.y) + .5) / textureResolution;\n}\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int pixelIndex) {\nivec2 texSize = textureSize(tex, 0);\nreturn texelFetch(tex, ivec2(pixelIndex % texSize.x, pixelIndex / texSize.x), 0);\n}\n#else\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex * 4;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\nreturn vec4(\ndecode32(texture(tex, x)),\ndecode32(texture(tex, y)),\ndecode32(texture(tex, z)),\n1.0\n);\n}\n#endif\nfloat getDisplacementWeight(int index) {\nint quot = index / 4;\nint remainder = index - quot * 4;\nif (remainder == 0) {\nreturn cc_displacementWeights[quot].x;\n} else if (remainder == 1) {\nreturn cc_displacementWeights[quot].y;\n} else if (remainder == 2) {\nreturn cc_displacementWeights[quot].z;\n} else {\nreturn cc_displacementWeights[quot].w;\n}\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\nreturn fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n#else\nvec3 result = vec3(0, 0, 0);\nint nVertices = int(cc_displacementTextureInfo.z);\nfor (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\nresult += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n}\nreturn result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\nuniform sampler2D cc_PositionDisplacements;\nvec3 getPositionDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nuniform sampler2D cc_NormalDisplacements;\nvec3 getNormalDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\nuniform sampler2D cc_TangentDisplacements;\nvec3 getTangentDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n}\n#endif\nvoid applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nint vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nnormal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\ntangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\n#if CC_USE_BAKED_ANIMATION\nlayout(std140) uniform CCSkinningTexture {\nhighp vec4 cc_jointTextureInfo;\n};\nlayout(std140) uniform CCSkinningAnimation {\nhighp vec4 cc_jointAnimInfo;\n};\nuniform highp sampler2D cc_jointTexture;\nvoid CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n{\n#if USE_INSTANCING\nhighp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n#else\nhighp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n#endif\ninvSize = cc_jointTextureInfo.w;\nhighp float tempY = floor(temp * invSize);\nx = floor(temp - tempY * cc_jointTextureInfo.x);\ny = (tempY + 0.5) * invSize;\n}\n#else\nlayout(std140) uniform CCSkinning {\nhighp vec4 cc_joints[30 * 3];\n};\n#endif\n#if CC_USE_BAKED_ANIMATION\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(3.0, i, x, y, invSize);\nvec4 v1 = texture(cc_jointTexture, vec2((x + 0.5) * invSize, y));\nvec4 v2 = texture(cc_jointTexture, vec2((x + 1.5) * invSize, y));\nvec4 v3 = texture(cc_jointTexture, vec2((x + 2.5) * invSize, y));\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#else\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(12.0, i, x, y, invSize);\nvec4 v1 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n);\nvec4 v2 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n);\nvec4 v3 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n);\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\n#else\nmat4 getJointMatrix (float i) {\nint idx = int(i);\nvec4 v1 = cc_joints[idx * 3];\nvec4 v2 = cc_joints[idx * 3 + 1];\nvec4 v3 = cc_joints[idx * 3 + 2];\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\nmat4 skinMatrix () {\nvec4 joints = vec4(a_joints);\nreturn getJointMatrix(joints.x) * a_weights.x\n+ getJointMatrix(joints.y) * a_weights.y\n+ getJointMatrix(joints.z) * a_weights.z\n+ getJointMatrix(joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\nmat4 m = skinMatrix();\nposition = m * position;\n}\nvoid CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nmat4 m = skinMatrix();\nposition = m * position;\nnormal = (m * vec4(normal, 0.0)).xyz;\ntangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n}\n#endif\nvoid CCVertInput(inout StandardVertInput In)\n{\nIn.position = vec4(a_position, 1.0);\nIn.normal = a_normal;\nIn.tangent = a_tangent;\n#if CC_USE_MORPH\napplyMorph(In.position, In.normal, In.tangent);\n#endif\n#if CC_USE_SKINNING\nCCSkin(In.position, In.normal, In.tangent);\n#endif\n}\nlayout(std140) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(std140) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\nout vec2 v_uv;\nvoid main () {\nStandardVertInput In;\nCCVertInput(In);\nIn.position.xy = cc_cameraPos.w == 0.0 ? vec2(In.position.xy.x, -In.position.xy.y) : In.position.xy;\ngl_Position = In.position;\ngl_Position.y = gl_Position.y;\nv_uv = a_texCoord;\n}", + "vert": "\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\nrgba = rgba * 255.0;\nhighp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\nhighp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\nhighp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\nreturn Sign * exp2(Exponent - 23.0) * Mantissa;\n}\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nin vec3 a_position;\nin vec3 a_normal;\nin vec2 a_texCoord;\nin vec4 a_tangent;\n#if CC_USE_SKINNING\nin vec4 a_joints;\nin vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nin highp vec4 a_jointAnimInfo;\n#endif\nin vec4 a_matWorld0;\nin vec4 a_matWorld1;\nin vec4 a_matWorld2;\n#if CC_USE_LIGHTMAP\nin vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nin vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nin float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nin float a_vertexId;\nint getVertexId() {\nreturn int(a_vertexId);\n}\n#endif\n#if CC_USE_MORPH\nlayout(std140) uniform CCMorph {\nvec4 cc_displacementWeights[15];\nvec4 cc_displacementTextureInfo;\n};\nvec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\nfloat pixelIndexF = float(pixelIndex);\nfloat x = mod(pixelIndexF, textureResolution.x);\nfloat y = floor(pixelIndexF / textureResolution.x);\nreturn vec2(x, y);\n}\nvec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\nreturn (vec2(location.x, location.y) + .5) / textureResolution;\n}\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int pixelIndex) {\nivec2 texSize = textureSize(tex, 0);\nreturn texelFetch(tex, ivec2(pixelIndex % texSize.x, pixelIndex / texSize.x), 0);\n}\n#else\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex * 4;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\nreturn vec4(\ndecode32(texture(tex, x)),\ndecode32(texture(tex, y)),\ndecode32(texture(tex, z)),\n1.0\n);\n}\n#endif\nfloat getDisplacementWeight(int index) {\nint quot = index / 4;\nint remainder = index - quot * 4;\nif (remainder == 0) {\nreturn cc_displacementWeights[quot].x;\n} else if (remainder == 1) {\nreturn cc_displacementWeights[quot].y;\n} else if (remainder == 2) {\nreturn cc_displacementWeights[quot].z;\n} else {\nreturn cc_displacementWeights[quot].w;\n}\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\nreturn fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n#else\nvec3 result = vec3(0, 0, 0);\nint nVertices = int(cc_displacementTextureInfo.z);\nfor (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\nresult += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n}\nreturn result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\nuniform sampler2D cc_PositionDisplacements;\nvec3 getPositionDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nuniform sampler2D cc_NormalDisplacements;\nvec3 getNormalDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\nuniform sampler2D cc_TangentDisplacements;\nvec3 getTangentDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n}\n#endif\nvoid applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nint vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nnormal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\ntangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\n#if CC_USE_BAKED_ANIMATION\nlayout(std140) uniform CCSkinningTexture {\nhighp vec4 cc_jointTextureInfo;\n};\nlayout(std140) uniform CCSkinningAnimation {\nhighp vec4 cc_jointAnimInfo;\n};\nuniform highp sampler2D cc_jointTexture;\nvoid CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n{\n#if USE_INSTANCING\nhighp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n#else\nhighp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n#endif\ninvSize = cc_jointTextureInfo.w;\nhighp float tempY = floor(temp * invSize);\nx = floor(temp - tempY * cc_jointTextureInfo.x);\ny = (tempY + 0.5) * invSize;\n}\n#else\nlayout(std140) uniform CCSkinning {\nhighp vec4 cc_joints[30 * 3];\n};\n#endif\n#if CC_USE_BAKED_ANIMATION\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(3.0, i, x, y, invSize);\nvec4 v1 = texture(cc_jointTexture, vec2((x + 0.5) * invSize, y));\nvec4 v2 = texture(cc_jointTexture, vec2((x + 1.5) * invSize, y));\nvec4 v3 = texture(cc_jointTexture, vec2((x + 2.5) * invSize, y));\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#else\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(12.0, i, x, y, invSize);\nvec4 v1 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n);\nvec4 v2 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n);\nvec4 v3 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n);\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\n#else\nmat4 getJointMatrix (float i) {\nint idx = int(i);\nvec4 v1 = cc_joints[idx * 3];\nvec4 v2 = cc_joints[idx * 3 + 1];\nvec4 v3 = cc_joints[idx * 3 + 2];\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\nmat4 skinMatrix () {\nvec4 joints = vec4(a_joints);\nreturn getJointMatrix(joints.x) * a_weights.x\n+ getJointMatrix(joints.y) * a_weights.y\n+ getJointMatrix(joints.z) * a_weights.z\n+ getJointMatrix(joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\nmat4 m = skinMatrix();\nposition = m * position;\n}\nvoid CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nmat4 m = skinMatrix();\nposition = m * position;\nnormal = (m * vec4(normal, 0.0)).xyz;\ntangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n}\n#endif\nvoid CCVertInput(inout StandardVertInput In)\n{\nIn.position = vec4(a_position, 1.0);\nIn.normal = a_normal;\nIn.tangent = a_tangent;\n#if CC_USE_MORPH\napplyMorph(In.position, In.normal, In.tangent);\n#endif\n#if CC_USE_SKINNING\nCCSkin(In.position, In.normal, In.tangent);\n#endif\n}\nlayout(std140) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(std140) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\nout vec2 v_uv;\nvoid main () {\nStandardVertInput In;\nCCVertInput(In);\nIn.position.xy = cc_cameraPos.w == 0.0 ? vec2(In.position.xy.x, -In.position.xy.y) : In.position.xy;\ngl_Position = In.position;\ngl_Position.y = gl_Position.y;\nv_uv = a_texCoord;\n}", "frag": "\nprecision highp float;\nlayout(std140) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(std140) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\nin vec2 v_uv;\nlayout(std140) uniform BloomUBO {\nmediump vec4 texSize;\n};\nuniform sampler2D bloomTexture;\nlayout(location = 0) out vec4 fragColor;\nvec3 downsample4taps(vec2 uv, vec2 halfpixel) {\nvec3 sum = texture(bloomTexture, uv + vec2(-halfpixel.x, halfpixel.y)).xyz;\nsum += texture(bloomTexture, uv + vec2(halfpixel.x, halfpixel.y)).xyz;\nsum += texture(bloomTexture, uv + vec2(halfpixel.x, -halfpixel.y)).xyz;\nsum += texture(bloomTexture, uv + vec2(-halfpixel.x, -halfpixel.y)).xyz;\nreturn sum / 4.0;\n}\nvoid main()\n{\nvec3 result = downsample4taps(v_uv, 1.0 / texSize.xy).rgb;\nfragColor = vec4(result, 1.0);\n}", }, { - "vert": "\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\nrgba = rgba * 255.0;\nhighp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\nhighp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\nhighp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\nreturn Sign * exp2(Exponent - 23.0) * Mantissa;\n}\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nin vec3 a_position;\nin vec3 a_normal;\nin vec2 a_texCoord;\nin vec4 a_tangent;\n#if CC_USE_SKINNING\nin vec4 a_joints;\nin vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nin highp vec4 a_jointAnimInfo;\n#endif\nin vec4 a_matWorld0;\nin vec4 a_matWorld1;\nin vec4 a_matWorld2;\n#if USE_LIGHTMAP\nin vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nin vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nin float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nin float a_vertexId;\nint getVertexId() {\nreturn int(a_vertexId);\n}\n#endif\n#if CC_USE_MORPH\nlayout(std140) uniform CCMorph {\nvec4 cc_displacementWeights[15];\nvec4 cc_displacementTextureInfo;\n};\nvec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\nfloat pixelIndexF = float(pixelIndex);\nfloat x = mod(pixelIndexF, textureResolution.x);\nfloat y = floor(pixelIndexF / textureResolution.x);\nreturn vec2(x, y);\n}\nvec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\nreturn (vec2(location.x, location.y) + .5) / textureResolution;\n}\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int pixelIndex) {\nivec2 texSize = textureSize(tex, 0);\nreturn texelFetch(tex, ivec2(pixelIndex % texSize.x, pixelIndex / texSize.x), 0);\n}\n#else\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex * 4;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\nreturn vec4(\ndecode32(texture(tex, x)),\ndecode32(texture(tex, y)),\ndecode32(texture(tex, z)),\n1.0\n);\n}\n#endif\nfloat getDisplacementWeight(int index) {\nint quot = index / 4;\nint remainder = index - quot * 4;\nif (remainder == 0) {\nreturn cc_displacementWeights[quot].x;\n} else if (remainder == 1) {\nreturn cc_displacementWeights[quot].y;\n} else if (remainder == 2) {\nreturn cc_displacementWeights[quot].z;\n} else {\nreturn cc_displacementWeights[quot].w;\n}\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\nreturn fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n#else\nvec3 result = vec3(0, 0, 0);\nint nVertices = int(cc_displacementTextureInfo.z);\nfor (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\nresult += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n}\nreturn result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\nuniform sampler2D cc_PositionDisplacements;\nvec3 getPositionDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nuniform sampler2D cc_NormalDisplacements;\nvec3 getNormalDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\nuniform sampler2D cc_TangentDisplacements;\nvec3 getTangentDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n}\n#endif\nvoid applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nint vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nnormal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\ntangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\n#if CC_USE_BAKED_ANIMATION\nlayout(std140) uniform CCSkinningTexture {\nhighp vec4 cc_jointTextureInfo;\n};\nlayout(std140) uniform CCSkinningAnimation {\nhighp vec4 cc_jointAnimInfo;\n};\nuniform highp sampler2D cc_jointTexture;\nvoid CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n{\n#if USE_INSTANCING\nhighp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n#else\nhighp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n#endif\ninvSize = cc_jointTextureInfo.w;\nhighp float tempY = floor(temp * invSize);\nx = floor(temp - tempY * cc_jointTextureInfo.x);\ny = (tempY + 0.5) * invSize;\n}\n#else\nlayout(std140) uniform CCSkinning {\nhighp vec4 cc_joints[30 * 3];\n};\n#endif\n#if CC_USE_BAKED_ANIMATION\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(3.0, i, x, y, invSize);\nvec4 v1 = texture(cc_jointTexture, vec2((x + 0.5) * invSize, y));\nvec4 v2 = texture(cc_jointTexture, vec2((x + 1.5) * invSize, y));\nvec4 v3 = texture(cc_jointTexture, vec2((x + 2.5) * invSize, y));\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#else\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(12.0, i, x, y, invSize);\nvec4 v1 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n);\nvec4 v2 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n);\nvec4 v3 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n);\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\n#else\nmat4 getJointMatrix (float i) {\nint idx = int(i);\nvec4 v1 = cc_joints[idx * 3];\nvec4 v2 = cc_joints[idx * 3 + 1];\nvec4 v3 = cc_joints[idx * 3 + 2];\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\nmat4 skinMatrix () {\nvec4 joints = vec4(a_joints);\nreturn getJointMatrix(joints.x) * a_weights.x\n+ getJointMatrix(joints.y) * a_weights.y\n+ getJointMatrix(joints.z) * a_weights.z\n+ getJointMatrix(joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\nmat4 m = skinMatrix();\nposition = m * position;\n}\nvoid CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nmat4 m = skinMatrix();\nposition = m * position;\nnormal = (m * vec4(normal, 0.0)).xyz;\ntangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n}\n#endif\nvoid CCVertInput(inout StandardVertInput In)\n{\nIn.position = vec4(a_position, 1.0);\nIn.normal = a_normal;\nIn.tangent = a_tangent;\n#if CC_USE_MORPH\napplyMorph(In.position, In.normal, In.tangent);\n#endif\n#if CC_USE_SKINNING\nCCSkin(In.position, In.normal, In.tangent);\n#endif\n}\nlayout(std140) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(std140) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\nout vec2 v_uv;\nvoid main () {\nStandardVertInput In;\nCCVertInput(In);\nIn.position.xy = cc_cameraPos.w == 0.0 ? vec2(In.position.xy.x, -In.position.xy.y) : In.position.xy;\ngl_Position = In.position;\ngl_Position.y = gl_Position.y;\nv_uv = a_texCoord;\n}", + "vert": "\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\nrgba = rgba * 255.0;\nhighp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\nhighp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\nhighp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\nreturn Sign * exp2(Exponent - 23.0) * Mantissa;\n}\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nin vec3 a_position;\nin vec3 a_normal;\nin vec2 a_texCoord;\nin vec4 a_tangent;\n#if CC_USE_SKINNING\nin vec4 a_joints;\nin vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nin highp vec4 a_jointAnimInfo;\n#endif\nin vec4 a_matWorld0;\nin vec4 a_matWorld1;\nin vec4 a_matWorld2;\n#if CC_USE_LIGHTMAP\nin vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nin vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nin float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nin float a_vertexId;\nint getVertexId() {\nreturn int(a_vertexId);\n}\n#endif\n#if CC_USE_MORPH\nlayout(std140) uniform CCMorph {\nvec4 cc_displacementWeights[15];\nvec4 cc_displacementTextureInfo;\n};\nvec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\nfloat pixelIndexF = float(pixelIndex);\nfloat x = mod(pixelIndexF, textureResolution.x);\nfloat y = floor(pixelIndexF / textureResolution.x);\nreturn vec2(x, y);\n}\nvec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\nreturn (vec2(location.x, location.y) + .5) / textureResolution;\n}\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int pixelIndex) {\nivec2 texSize = textureSize(tex, 0);\nreturn texelFetch(tex, ivec2(pixelIndex % texSize.x, pixelIndex / texSize.x), 0);\n}\n#else\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex * 4;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\nreturn vec4(\ndecode32(texture(tex, x)),\ndecode32(texture(tex, y)),\ndecode32(texture(tex, z)),\n1.0\n);\n}\n#endif\nfloat getDisplacementWeight(int index) {\nint quot = index / 4;\nint remainder = index - quot * 4;\nif (remainder == 0) {\nreturn cc_displacementWeights[quot].x;\n} else if (remainder == 1) {\nreturn cc_displacementWeights[quot].y;\n} else if (remainder == 2) {\nreturn cc_displacementWeights[quot].z;\n} else {\nreturn cc_displacementWeights[quot].w;\n}\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\nreturn fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n#else\nvec3 result = vec3(0, 0, 0);\nint nVertices = int(cc_displacementTextureInfo.z);\nfor (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\nresult += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n}\nreturn result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\nuniform sampler2D cc_PositionDisplacements;\nvec3 getPositionDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nuniform sampler2D cc_NormalDisplacements;\nvec3 getNormalDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\nuniform sampler2D cc_TangentDisplacements;\nvec3 getTangentDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n}\n#endif\nvoid applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nint vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nnormal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\ntangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\n#if CC_USE_BAKED_ANIMATION\nlayout(std140) uniform CCSkinningTexture {\nhighp vec4 cc_jointTextureInfo;\n};\nlayout(std140) uniform CCSkinningAnimation {\nhighp vec4 cc_jointAnimInfo;\n};\nuniform highp sampler2D cc_jointTexture;\nvoid CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n{\n#if USE_INSTANCING\nhighp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n#else\nhighp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n#endif\ninvSize = cc_jointTextureInfo.w;\nhighp float tempY = floor(temp * invSize);\nx = floor(temp - tempY * cc_jointTextureInfo.x);\ny = (tempY + 0.5) * invSize;\n}\n#else\nlayout(std140) uniform CCSkinning {\nhighp vec4 cc_joints[30 * 3];\n};\n#endif\n#if CC_USE_BAKED_ANIMATION\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(3.0, i, x, y, invSize);\nvec4 v1 = texture(cc_jointTexture, vec2((x + 0.5) * invSize, y));\nvec4 v2 = texture(cc_jointTexture, vec2((x + 1.5) * invSize, y));\nvec4 v3 = texture(cc_jointTexture, vec2((x + 2.5) * invSize, y));\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#else\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(12.0, i, x, y, invSize);\nvec4 v1 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n);\nvec4 v2 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n);\nvec4 v3 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n);\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\n#else\nmat4 getJointMatrix (float i) {\nint idx = int(i);\nvec4 v1 = cc_joints[idx * 3];\nvec4 v2 = cc_joints[idx * 3 + 1];\nvec4 v3 = cc_joints[idx * 3 + 2];\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\nmat4 skinMatrix () {\nvec4 joints = vec4(a_joints);\nreturn getJointMatrix(joints.x) * a_weights.x\n+ getJointMatrix(joints.y) * a_weights.y\n+ getJointMatrix(joints.z) * a_weights.z\n+ getJointMatrix(joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\nmat4 m = skinMatrix();\nposition = m * position;\n}\nvoid CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nmat4 m = skinMatrix();\nposition = m * position;\nnormal = (m * vec4(normal, 0.0)).xyz;\ntangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n}\n#endif\nvoid CCVertInput(inout StandardVertInput In)\n{\nIn.position = vec4(a_position, 1.0);\nIn.normal = a_normal;\nIn.tangent = a_tangent;\n#if CC_USE_MORPH\napplyMorph(In.position, In.normal, In.tangent);\n#endif\n#if CC_USE_SKINNING\nCCSkin(In.position, In.normal, In.tangent);\n#endif\n}\nlayout(std140) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(std140) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\nout vec2 v_uv;\nvoid main () {\nStandardVertInput In;\nCCVertInput(In);\nIn.position.xy = cc_cameraPos.w == 0.0 ? vec2(In.position.xy.x, -In.position.xy.y) : In.position.xy;\ngl_Position = In.position;\ngl_Position.y = gl_Position.y;\nv_uv = a_texCoord;\n}", "frag": "\nprecision highp float;\nlayout(std140) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(std140) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\nin vec2 v_uv;\nlayout(std140) uniform BloomUBO {\nmediump vec4 texSize;\n};\nuniform sampler2D bloomTexture;\nlayout(location = 0) out vec4 fragColor;\nvec3 upsample4taps(vec2 uv, vec2 halfpixel) {\nvec3 sum = texture(bloomTexture, uv + vec2(-halfpixel.x, halfpixel.y)).xyz;\nsum += texture(bloomTexture, uv + vec2(halfpixel.x, halfpixel.y)).xyz;\nsum += texture(bloomTexture, uv + vec2(halfpixel.x, -halfpixel.y)).xyz;\nsum += texture(bloomTexture, uv + vec2(-halfpixel.x, -halfpixel.y)).xyz;\nreturn sum / 4.0;\n}\nvoid main() {\nvec3 result = upsample4taps(v_uv, 0.5 / texSize.xy).rgb;\nfragColor = vec4(result, 1.0);\n}", }, { - "vert": "\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\nrgba = rgba * 255.0;\nhighp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\nhighp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\nhighp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\nreturn Sign * exp2(Exponent - 23.0) * Mantissa;\n}\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nin vec3 a_position;\nin vec3 a_normal;\nin vec2 a_texCoord;\nin vec4 a_tangent;\n#if CC_USE_SKINNING\nin vec4 a_joints;\nin vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nin highp vec4 a_jointAnimInfo;\n#endif\nin vec4 a_matWorld0;\nin vec4 a_matWorld1;\nin vec4 a_matWorld2;\n#if USE_LIGHTMAP\nin vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nin vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nin float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nin float a_vertexId;\nint getVertexId() {\nreturn int(a_vertexId);\n}\n#endif\n#if CC_USE_MORPH\nlayout(std140) uniform CCMorph {\nvec4 cc_displacementWeights[15];\nvec4 cc_displacementTextureInfo;\n};\nvec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\nfloat pixelIndexF = float(pixelIndex);\nfloat x = mod(pixelIndexF, textureResolution.x);\nfloat y = floor(pixelIndexF / textureResolution.x);\nreturn vec2(x, y);\n}\nvec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\nreturn (vec2(location.x, location.y) + .5) / textureResolution;\n}\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int pixelIndex) {\nivec2 texSize = textureSize(tex, 0);\nreturn texelFetch(tex, ivec2(pixelIndex % texSize.x, pixelIndex / texSize.x), 0);\n}\n#else\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex * 4;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\nreturn vec4(\ndecode32(texture(tex, x)),\ndecode32(texture(tex, y)),\ndecode32(texture(tex, z)),\n1.0\n);\n}\n#endif\nfloat getDisplacementWeight(int index) {\nint quot = index / 4;\nint remainder = index - quot * 4;\nif (remainder == 0) {\nreturn cc_displacementWeights[quot].x;\n} else if (remainder == 1) {\nreturn cc_displacementWeights[quot].y;\n} else if (remainder == 2) {\nreturn cc_displacementWeights[quot].z;\n} else {\nreturn cc_displacementWeights[quot].w;\n}\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\nreturn fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n#else\nvec3 result = vec3(0, 0, 0);\nint nVertices = int(cc_displacementTextureInfo.z);\nfor (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\nresult += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n}\nreturn result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\nuniform sampler2D cc_PositionDisplacements;\nvec3 getPositionDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nuniform sampler2D cc_NormalDisplacements;\nvec3 getNormalDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\nuniform sampler2D cc_TangentDisplacements;\nvec3 getTangentDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n}\n#endif\nvoid applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nint vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nnormal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\ntangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\n#if CC_USE_BAKED_ANIMATION\nlayout(std140) uniform CCSkinningTexture {\nhighp vec4 cc_jointTextureInfo;\n};\nlayout(std140) uniform CCSkinningAnimation {\nhighp vec4 cc_jointAnimInfo;\n};\nuniform highp sampler2D cc_jointTexture;\nvoid CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n{\n#if USE_INSTANCING\nhighp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n#else\nhighp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n#endif\ninvSize = cc_jointTextureInfo.w;\nhighp float tempY = floor(temp * invSize);\nx = floor(temp - tempY * cc_jointTextureInfo.x);\ny = (tempY + 0.5) * invSize;\n}\n#else\nlayout(std140) uniform CCSkinning {\nhighp vec4 cc_joints[30 * 3];\n};\n#endif\n#if CC_USE_BAKED_ANIMATION\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(3.0, i, x, y, invSize);\nvec4 v1 = texture(cc_jointTexture, vec2((x + 0.5) * invSize, y));\nvec4 v2 = texture(cc_jointTexture, vec2((x + 1.5) * invSize, y));\nvec4 v3 = texture(cc_jointTexture, vec2((x + 2.5) * invSize, y));\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#else\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(12.0, i, x, y, invSize);\nvec4 v1 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n);\nvec4 v2 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n);\nvec4 v3 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n);\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\n#else\nmat4 getJointMatrix (float i) {\nint idx = int(i);\nvec4 v1 = cc_joints[idx * 3];\nvec4 v2 = cc_joints[idx * 3 + 1];\nvec4 v3 = cc_joints[idx * 3 + 2];\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\nmat4 skinMatrix () {\nvec4 joints = vec4(a_joints);\nreturn getJointMatrix(joints.x) * a_weights.x\n+ getJointMatrix(joints.y) * a_weights.y\n+ getJointMatrix(joints.z) * a_weights.z\n+ getJointMatrix(joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\nmat4 m = skinMatrix();\nposition = m * position;\n}\nvoid CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nmat4 m = skinMatrix();\nposition = m * position;\nnormal = (m * vec4(normal, 0.0)).xyz;\ntangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n}\n#endif\nvoid CCVertInput(inout StandardVertInput In)\n{\nIn.position = vec4(a_position, 1.0);\nIn.normal = a_normal;\nIn.tangent = a_tangent;\n#if CC_USE_MORPH\napplyMorph(In.position, In.normal, In.tangent);\n#endif\n#if CC_USE_SKINNING\nCCSkin(In.position, In.normal, In.tangent);\n#endif\n}\nlayout(std140) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(std140) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\nout vec2 v_uv;\nvoid main () {\nStandardVertInput In;\nCCVertInput(In);\nIn.position.xy = cc_cameraPos.w == 0.0 ? vec2(In.position.xy.x, -In.position.xy.y) : In.position.xy;\ngl_Position = In.position;\ngl_Position.y = gl_Position.y;\nv_uv = a_texCoord;\n}", + "vert": "\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\nrgba = rgba * 255.0;\nhighp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\nhighp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\nhighp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\nreturn Sign * exp2(Exponent - 23.0) * Mantissa;\n}\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nin vec3 a_position;\nin vec3 a_normal;\nin vec2 a_texCoord;\nin vec4 a_tangent;\n#if CC_USE_SKINNING\nin vec4 a_joints;\nin vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nin highp vec4 a_jointAnimInfo;\n#endif\nin vec4 a_matWorld0;\nin vec4 a_matWorld1;\nin vec4 a_matWorld2;\n#if CC_USE_LIGHTMAP\nin vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nin vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nin float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nin float a_vertexId;\nint getVertexId() {\nreturn int(a_vertexId);\n}\n#endif\n#if CC_USE_MORPH\nlayout(std140) uniform CCMorph {\nvec4 cc_displacementWeights[15];\nvec4 cc_displacementTextureInfo;\n};\nvec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\nfloat pixelIndexF = float(pixelIndex);\nfloat x = mod(pixelIndexF, textureResolution.x);\nfloat y = floor(pixelIndexF / textureResolution.x);\nreturn vec2(x, y);\n}\nvec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\nreturn (vec2(location.x, location.y) + .5) / textureResolution;\n}\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int pixelIndex) {\nivec2 texSize = textureSize(tex, 0);\nreturn texelFetch(tex, ivec2(pixelIndex % texSize.x, pixelIndex / texSize.x), 0);\n}\n#else\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex * 4;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\nreturn vec4(\ndecode32(texture(tex, x)),\ndecode32(texture(tex, y)),\ndecode32(texture(tex, z)),\n1.0\n);\n}\n#endif\nfloat getDisplacementWeight(int index) {\nint quot = index / 4;\nint remainder = index - quot * 4;\nif (remainder == 0) {\nreturn cc_displacementWeights[quot].x;\n} else if (remainder == 1) {\nreturn cc_displacementWeights[quot].y;\n} else if (remainder == 2) {\nreturn cc_displacementWeights[quot].z;\n} else {\nreturn cc_displacementWeights[quot].w;\n}\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\nreturn fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n#else\nvec3 result = vec3(0, 0, 0);\nint nVertices = int(cc_displacementTextureInfo.z);\nfor (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\nresult += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n}\nreturn result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\nuniform sampler2D cc_PositionDisplacements;\nvec3 getPositionDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nuniform sampler2D cc_NormalDisplacements;\nvec3 getNormalDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\nuniform sampler2D cc_TangentDisplacements;\nvec3 getTangentDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n}\n#endif\nvoid applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nint vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nnormal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\ntangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\n#if CC_USE_BAKED_ANIMATION\nlayout(std140) uniform CCSkinningTexture {\nhighp vec4 cc_jointTextureInfo;\n};\nlayout(std140) uniform CCSkinningAnimation {\nhighp vec4 cc_jointAnimInfo;\n};\nuniform highp sampler2D cc_jointTexture;\nvoid CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n{\n#if USE_INSTANCING\nhighp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n#else\nhighp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n#endif\ninvSize = cc_jointTextureInfo.w;\nhighp float tempY = floor(temp * invSize);\nx = floor(temp - tempY * cc_jointTextureInfo.x);\ny = (tempY + 0.5) * invSize;\n}\n#else\nlayout(std140) uniform CCSkinning {\nhighp vec4 cc_joints[30 * 3];\n};\n#endif\n#if CC_USE_BAKED_ANIMATION\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(3.0, i, x, y, invSize);\nvec4 v1 = texture(cc_jointTexture, vec2((x + 0.5) * invSize, y));\nvec4 v2 = texture(cc_jointTexture, vec2((x + 1.5) * invSize, y));\nvec4 v3 = texture(cc_jointTexture, vec2((x + 2.5) * invSize, y));\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#else\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(12.0, i, x, y, invSize);\nvec4 v1 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n);\nvec4 v2 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n);\nvec4 v3 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n);\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\n#else\nmat4 getJointMatrix (float i) {\nint idx = int(i);\nvec4 v1 = cc_joints[idx * 3];\nvec4 v2 = cc_joints[idx * 3 + 1];\nvec4 v3 = cc_joints[idx * 3 + 2];\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\nmat4 skinMatrix () {\nvec4 joints = vec4(a_joints);\nreturn getJointMatrix(joints.x) * a_weights.x\n+ getJointMatrix(joints.y) * a_weights.y\n+ getJointMatrix(joints.z) * a_weights.z\n+ getJointMatrix(joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\nmat4 m = skinMatrix();\nposition = m * position;\n}\nvoid CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nmat4 m = skinMatrix();\nposition = m * position;\nnormal = (m * vec4(normal, 0.0)).xyz;\ntangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n}\n#endif\nvoid CCVertInput(inout StandardVertInput In)\n{\nIn.position = vec4(a_position, 1.0);\nIn.normal = a_normal;\nIn.tangent = a_tangent;\n#if CC_USE_MORPH\napplyMorph(In.position, In.normal, In.tangent);\n#endif\n#if CC_USE_SKINNING\nCCSkin(In.position, In.normal, In.tangent);\n#endif\n}\nlayout(std140) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(std140) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\nout vec2 v_uv;\nvoid main () {\nStandardVertInput In;\nCCVertInput(In);\nIn.position.xy = cc_cameraPos.w == 0.0 ? vec2(In.position.xy.x, -In.position.xy.y) : In.position.xy;\ngl_Position = In.position;\ngl_Position.y = gl_Position.y;\nv_uv = a_texCoord;\n}", "frag": "\nprecision highp float;\nlayout(std140) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(std140) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\nin vec2 v_uv;\nlayout(std140) uniform BloomUBO {\nmediump vec4 texSize;\n};\nuniform sampler2D outputResultMap;\nuniform sampler2D bloomTexture;\nlayout(location = 0) out vec4 fragColor;\nvoid main() {\nvec4 hdrColor = texture(outputResultMap, v_uv);\nvec3 bloomColor = texture(bloomTexture, v_uv).rgb;\nvec3 result = hdrColor.rgb + bloomColor * texSize.w * hdrColor.a;\nfragColor = vec4(result, hdrColor.a);\n}", } ], [ { - "vert": "\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nin vec3 a_position;\nin vec3 a_normal;\nin vec2 a_texCoord;\nin vec4 a_tangent;\n#if CC_USE_SKINNING\nin vec4 a_joints;\nin vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nin highp vec4 a_jointAnimInfo;\n#endif\nin vec4 a_matWorld0;\nin vec4 a_matWorld1;\nin vec4 a_matWorld2;\n#if USE_LIGHTMAP\nin vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nin vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nin float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nin float a_vertexId;\n#endif\nlayout(std140) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(std140) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\nout vec2 v_uv;\nvoid main () {\nvec4 position;\nposition = vec4(a_position, 1.0);\nposition.xy = cc_cameraPos.w == 0.0 ? vec2(position.xy.x, -position.xy.y) : position.xy;\ngl_Position = vec4(position.x, position.y, 1.0, 1.0);\nv_uv = a_texCoord;\n}", - "frag": "\n#ifdef GL_EXT_shader_framebuffer_fetch\n#extension GL_EXT_shader_framebuffer_fetch: enable\n#endif\nprecision highp float;\nlayout(std140) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(std140) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nvec3 SRGBToLinear (vec3 gamma) {\nreturn gamma * gamma;\n}\nlayout(std140) uniform CCShadow {\nhighp mat4 cc_matLightPlaneProj;\nhighp mat4 cc_matLightView;\nhighp mat4 cc_matLightViewProj;\nhighp vec4 cc_shadowInvProjDepthInfo;\nhighp vec4 cc_shadowProjDepthInfo;\nhighp vec4 cc_shadowProjInfo;\nmediump vec4 cc_shadowNFLSInfo;\nmediump vec4 cc_shadowWHPBInfo;\nmediump vec4 cc_shadowLPNNInfo;\nlowp vec4 cc_shadowColor;\nmediump vec4 cc_planarNDInfo;\n};\nhighp float unpackHighpData (float mainPart, float modPart) {\nhighp float data = mainPart;\nreturn data + modPart;\n}\nhighp float unpackHighpData (float mainPart, float modPart, const float modValue) {\nhighp float data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nhighp vec2 unpackHighpData (vec2 mainPart, vec2 modPart) {\nhighp vec2 data = mainPart;\nreturn data + modPart;\n}\nhighp vec2 unpackHighpData (vec2 mainPart, vec2 modPart, const float modValue) {\nhighp vec2 data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nhighp vec3 unpackHighpData (vec3 mainPart, vec3 modPart) {\nhighp vec3 data = mainPart;\nreturn data + modPart;\n}\nhighp vec3 unpackHighpData (vec3 mainPart, vec3 modPart, const float modValue) {\nhighp vec3 data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nhighp vec4 unpackHighpData (vec4 mainPart, vec4 modPart) {\nhighp vec4 data = mainPart;\nreturn data + modPart;\n}\nhighp vec4 unpackHighpData (vec4 mainPart, vec4 modPart, const float modValue) {\nhighp vec4 data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nlayout(std140) uniform CCLocal {\nhighp mat4 cc_matWorld;\nhighp mat4 cc_matWorldIT;\nhighp vec4 cc_lightingMapUVParam;\nhighp vec4 cc_localShadowBias;\n};\nfloat CCGetLinearDepthFromViewSpace(vec3 viewPos) {\nfloat dist = length(viewPos);\nreturn (dist - cc_shadowNFLSInfo.x) / (cc_shadowNFLSInfo.y - cc_shadowNFLSInfo.x);\n}\nfloat CCGetLinearDepth(vec3 worldPos) {\nvec4 viewStartPos = cc_matLightView * vec4(worldPos.xyz, 1.0);\nreturn CCGetLinearDepthFromViewSpace(viewStartPos.xyz);\n}\n#if CC_RECEIVE_SHADOW\nuniform highp sampler2D cc_shadowMap;\nuniform highp sampler2D cc_spotLightingMap;\nvec4 ApplyShadowDepthBias_FaceNormal(vec4 shadowPos, vec3 worldNormal, float normalBias)\n{\nvec4 newShadowPos = shadowPos;\nif(normalBias > EPSILON_LOWP)\n{\nvec4 viewNormal = cc_matLightView * vec4(worldNormal, 0.0);\nif(viewNormal.z < 0.1)\nnewShadowPos.xy += viewNormal.xy * cc_shadowProjInfo.xy * normalBias * clamp(viewNormal.z, 0.001, 0.1);\n}\nreturn newShadowPos;\n}\nvec4 ApplyShadowDepthBias_Perspective(vec4 shadowPos, float viewspaceDepthBias)\n{\nvec3 viewSpacePos;\nviewSpacePos.xy = shadowPos.xy * cc_shadowProjInfo.zw;\nviewSpacePos.z = shadowPos.z * cc_shadowInvProjDepthInfo.x + shadowPos.w * cc_shadowInvProjDepthInfo.y;\nviewSpacePos.xyz += cc_shadowProjDepthInfo.z * normalize(viewSpacePos.xyz) * viewspaceDepthBias;\nvec4 clipSpacePos;\nclipSpacePos.xy = viewSpacePos.xy * cc_shadowProjInfo.xy;\nclipSpacePos.zw = viewSpacePos.z * cc_shadowProjDepthInfo.xz + vec2(cc_shadowProjDepthInfo.y, 0.0);\nif (cc_shadowNFLSInfo.z > EPSILON) {\nclipSpacePos.z = CCGetLinearDepthFromViewSpace(viewSpacePos.xyz);\nclipSpacePos.z = (clipSpacePos.z * 2.0 - 1.0) * clipSpacePos.w;\n}\nreturn clipSpacePos;\n}\nvec4 ApplyShadowDepthBias_Orthographic(vec4 shadowPos, float viewspaceDepthBias)\n{\nfloat coeffA = cc_shadowProjDepthInfo.x;\nfloat coeffB = cc_shadowProjDepthInfo.y;\nfloat viewSpacePos_z = (shadowPos.z - coeffB) / coeffA;\nviewSpacePos_z += viewspaceDepthBias;\nvec4 result = shadowPos;\nresult.z = viewSpacePos_z * coeffA + coeffB;\nreturn result;\n}\nfloat CCGetShadowFactorHard (vec4 shadowPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Orthographic(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat shadow = 0.0;\nfloat closestDepth = 0.0;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nclosestDepth = dot(texture(cc_shadowMap, clipPos.xy), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0));\n} else {\nclosestDepth = texture(cc_shadowMap, clipPos.xy).x;\n}\nshadow = step(clipPos.z, closestDepth);\nreturn shadow;\n}\nfloat CCGetShadowFactorSoft (vec4 shadowPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Orthographic(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat offsetDepth = clipPos.z;\nvec2 mapSize = cc_shadowWHPBInfo.xy;\nvec2 oneTap = 1.0 / mapSize;\nvec2 clipPos_offset = clipPos.xy + oneTap;\nfloat block0, block1, block2, block3;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos.y)).x);\nblock1 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset.x, clipPos.y)).x);\nblock2 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset.y)).x);\nblock3 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset.x, clipPos_offset.y)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * mapSize.x;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block2, block3, coefX);\nfloat coefY = mod(clipPos.y, oneTap.y) * mapSize.y;\nreturn mix(resultX, resultY, coefY);\n}\nfloat CCGetShadowFactorSoft2X (vec4 shadowPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Orthographic(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat offsetDepth = clipPos.z;\nvec2 mapSize = cc_shadowWHPBInfo.xy;\nvec2 oneTap = 1.0 / mapSize;\nfloat clipPos_offset_L = clipPos.x - oneTap.x;\nfloat clipPos_offset_R = clipPos.x + oneTap.x;\nfloat clipPos_offset_U = clipPos.y - oneTap.y;\nfloat clipPos_offset_D = clipPos.y + oneTap.y;\nfloat block0, block1, block2, block3, block4, block5, block6, block7, block8;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock4 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock5 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock6 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock7 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock8 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_U)).x);\nblock1 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset_U)).x);\nblock2 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_U)).x);\nblock3 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos.y)).x);\nblock4 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos.y)).x);\nblock5 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos.y)).x);\nblock6 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_D)).x);\nblock7 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset_D)).x);\nblock8 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_D)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * mapSize.x;\nfloat coefY = mod(clipPos.y, oneTap.y) * mapSize.y;\nfloat shadow = 0.0;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block3, block4, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block1, block2, coefX);\nresultY = mix(block4, block5, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block3, block4, coefX);\nresultY = mix(block6, block7, coefX);\nshadow += mix(resultX, resultY, coefY);\nresultX = mix(block4, block5, coefX);\nresultY = mix(block7, block8, coefX);\nshadow += mix(resultX, resultY, coefY);\nreturn shadow * 0.25;\n}\nfloat CCGetSpotLightShadowFactorHard (vec4 shadowPos, vec3 worldPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Perspective(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat shadow = 0.0;\nfloat closestDepth = 0.0;\nfloat depth = clipPos.z;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nclosestDepth = dot(texture(cc_spotLightingMap, clipPos.xy), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0));\n} else {\nclosestDepth = texture(cc_spotLightingMap, clipPos.xy).x;\n}\nshadow = step(depth, closestDepth);\nreturn shadow;\n}\nfloat CCGetSpotLightShadowFactorSoft (vec4 shadowPos, vec3 worldPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Perspective(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat depth = 0.0;\nif (cc_shadowNFLSInfo.z > EPSILON) {\ndepth = CCGetLinearDepth(worldPos);\n} else {\ndepth = clipPos.z;\n}\nvec2 oneTap = 1.0 / cc_shadowWHPBInfo.xy;\nvec2 clipPos_offset = clipPos.xy + oneTap;\nfloat block0, block1, block2, block3;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)).x);\nblock1 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos.y)).x);\nblock2 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset.y)).x);\nblock3 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos_offset.y)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * cc_shadowWHPBInfo.x;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block2, block3, coefX);\nfloat coefY = mod(clipPos.y, oneTap.y) * cc_shadowWHPBInfo.y;\nreturn mix(resultX, resultY, coefY);\n}\nfloat CCGetSpotLightShadowFactorSoft2X (vec4 shadowPos, vec3 worldPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Perspective(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat depth = 0.0;\nif (cc_shadowNFLSInfo.z > EPSILON) {\ndepth = CCGetLinearDepth(worldPos);\n} else {\ndepth = clipPos.z;\n}\nvec2 mapSize = cc_shadowWHPBInfo.xy;\nvec2 oneTap = 1.0 / mapSize;\nfloat clipPos_offset_L = clipPos.x - oneTap.x;\nfloat clipPos_offset_R = clipPos.x + oneTap.x;\nfloat clipPos_offset_U = clipPos.y - oneTap.y;\nfloat clipPos_offset_D = clipPos.y + oneTap.y;\nfloat block0, block1, block2, block3, block4, block5, block6, block7, block8;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock4 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock5 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock6 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock7 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock8 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_U)).x);\nblock1 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_U)).x);\nblock2 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_U)).x);\nblock3 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos.y)).x);\nblock4 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)).x);\nblock5 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos.y)).x);\nblock6 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_D)).x);\nblock7 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_D)).x);\nblock8 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_D)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * mapSize.x;\nfloat coefY = mod(clipPos.y, oneTap.y) * mapSize.y;\nfloat shadow = 0.0;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block3, block4, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block1, block2, coefX);\nresultY = mix(block4, block5, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block3, block4, coefX);\nresultY = mix(block6, block7, coefX);\nshadow += mix(resultX, resultY, coefY);\nresultX = mix(block4, block5, coefX);\nresultY = mix(block7, block8, coefX);\nshadow += mix(resultX, resultY, coefY);\nreturn shadow * 0.25;\n}\nfloat CCSpotShadowFactorBase(vec4 shadowPos, vec3 worldPos, vec2 shadowBias)\n{\nfloat pcf = cc_shadowWHPBInfo.z;\nif (pcf > 1.9) {\nreturn CCGetSpotLightShadowFactorSoft2X(shadowPos, worldPos, shadowBias.x);\n}else if (pcf > 0.9) {\nreturn CCGetSpotLightShadowFactorSoft(shadowPos, worldPos, shadowBias.x);\n}else {\nreturn CCGetSpotLightShadowFactorHard(shadowPos, worldPos, shadowBias.x);\n}\n}\nfloat CCShadowFactorBase(vec4 shadowPos, vec3 N, vec2 shadowBias)\n{\nfloat realtimeShadow = 1.0;\nvec4 pos = ApplyShadowDepthBias_FaceNormal(shadowPos, N, shadowBias.y);\nfloat pcf = cc_shadowWHPBInfo.z;\nif (pcf > 1.9) {\nrealtimeShadow = CCGetShadowFactorSoft2X(pos, shadowBias.x);\n}else if (pcf > 0.9) {\nrealtimeShadow = CCGetShadowFactorSoft(pos, shadowBias.x);\n}else {\nrealtimeShadow = CCGetShadowFactorHard(pos, shadowBias.x);\n}\nreturn mix(realtimeShadow, 1.0, cc_shadowNFLSInfo.w);\n}\n#endif\n#if CC_USE_IBL\nuniform samplerCube cc_environment;\nvec4 fragTextureLod (sampler2D tex, vec2 coord, float lod) {\nreturn textureLod(tex, coord, lod);\n}\nvec4 fragTextureLod (samplerCube tex, vec3 coord, float lod) {\nreturn textureLod(tex, coord, lod);\n}\nvec3 unpackRGBE (vec4 rgbe) {\nreturn rgbe.rgb * pow(1.1, rgbe.a * 255.0 - 128.0);\n}\n#if CC_USE_DIFFUSEMAP\nuniform samplerCube cc_diffuseMap;\n#endif\n#endif\nfloat GGXMobile (float roughness, float NoH, vec3 H, vec3 N) {\nvec3 NxH = cross(N, H);\nfloat OneMinusNoHSqr = dot(NxH, NxH);\nfloat a = roughness * roughness;\nfloat n = NoH * a;\nfloat p = a / (OneMinusNoHSqr + n * n);\nreturn p * p;\n}\nfloat CalcSpecular (float roughness, float NoH, vec3 H, vec3 N) {\nreturn (roughness * 0.25 + 0.25) * GGXMobile(roughness, NoH, H, N);\n}\nvec3 BRDFApprox (vec3 specular, float roughness, float NoV) {\nconst vec4 c0 = vec4(-1.0, -0.0275, -0.572, 0.022);\nconst vec4 c1 = vec4(1.0, 0.0425, 1.04, -0.04);\nvec4 r = roughness * c0 + c1;\nfloat a004 = min(r.x * r.x, exp2(-9.28 * NoV)) * r.x + r.y;\nvec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;\nAB.y *= clamp(50.0 * specular.g, 0.0, 1.0);\nreturn specular * AB.x + AB.y;\n}\n#if USE_REFLECTION_DENOISE\nvec3 GetEnvReflectionWithMipFiltering(vec3 R, float roughness, float mipCount, float denoiseIntensity) {\n#if CC_USE_IBL\nfloat mip = roughness * mipCount;\nfloat delta = (dot(dFdx(R), dFdy(R))) * 1000.0;\nfloat mipBias = mix(0.0, 5.0, clamp(delta, 0.0, 1.0));\nvec4 biased = fragTextureLod(cc_environment, R, mip + mipBias);\nvec4 filtered = texture(cc_environment, R);\n#if CC_USE_IBL == 2\nbiased.rgb = unpackRGBE(biased);\nfiltered.rgb = unpackRGBE(filtered);\n#else\nbiased.rgb = SRGBToLinear(biased.rgb);\nfiltered.rgb = SRGBToLinear(filtered.rgb);\n#endif\nreturn mix(biased.rgb, filtered.rgb, denoiseIntensity);\n#else\nreturn vec3(0.0, 0.0, 0.0);\n#endif\n}\n#endif\nstruct StandardSurface {\nvec4 albedo;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nvec3 position, position_fract_part;\n#else\nvec3 position;\n#endif\nvec3 normal;\nvec3 emissive;\nvec3 lightmap;\nfloat lightmap_test;\nfloat roughness;\nfloat metallic;\nfloat occlusion;\nfloat specularIntensity;\n#if CC_RECEIVE_SHADOW\nvec2 shadowBias;\n#endif\n};\nvec4 CCStandardShadingBase (StandardSurface s, vec4 shadowPos) {\nvec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\nvec3 specular = mix(vec3(0.08 * s.specularIntensity), s.albedo.rgb, s.metallic);\nvec3 position;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nposition = unpackHighpData(s.position, s.position_fract_part);\n#else\nposition = s.position;\n#endif\nvec3 N = normalize(s.normal);\nvec3 V = normalize(cc_cameraPos.xyz - position);\nfloat NV = max(abs(dot(N, V)), 0.0);\nspecular = BRDFApprox(specular, s.roughness, NV);\nvec3 L = normalize(-cc_mainLitDir.xyz);\nvec3 H = normalize(L + V);\nfloat NH = max(dot(N, H), 0.0);\nfloat NL = max(dot(N, L), 0.0);\nvec3 finalColor = NL * cc_mainLitColor.rgb * cc_mainLitColor.w;\nvec3 diffuseContrib = diffuse / PI;\nvec3 specularContrib = specular * CalcSpecular(s.roughness, NH, H, N);\nvec3 dirlightContrib = (diffuseContrib + specularContrib);\nfloat shadow = 1.0;\n#if CC_RECEIVE_SHADOW\nif (NL > 0.0 && cc_mainLitDir.w > 0.0) {\nshadow = CCShadowFactorBase(shadowPos, N, s.shadowBias);\n}\n#endif\ndirlightContrib *= shadow;\nfinalColor *= dirlightContrib;\n#if USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\nif (s.lightmap_test > EPSILON_LOWP) {\nfinalColor = diffuse * s.lightmap.rgb * shadow;\n}\n#endif\nfloat fAmb = 0.5 - N.y * 0.5;\nvec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb);\n#if CC_USE_IBL\n#if CC_USE_DIFFUSEMAP\nvec4 diffuseMap = texture(cc_diffuseMap, N);\n#if CC_USE_DIFFUSEMAP == 2\nambDiff = unpackRGBE(diffuseMap);\n#else\nambDiff = SRGBToLinear(diffuseMap.rgb);\n#endif\n#endif\nvec3 R = normalize(reflect(-V, N));\n#if USE_REFLECTION_DENOISE\nvec3 env = GetEnvReflectionWithMipFiltering(R, s.roughness, cc_ambientGround.w, 0.6);\n#else\nvec4 envmap = fragTextureLod(cc_environment, R, s.roughness * cc_ambientGround.w);\n#if CC_USE_IBL == 2\nvec3 env = unpackRGBE(envmap);\n#else\nvec3 env = SRGBToLinear(envmap.rgb);\n#endif\n#endif\nfinalColor += env * cc_ambientSky.w * specular * s.occlusion;\n#endif\nfinalColor += ambDiff.rgb * cc_ambientSky.w * diffuse * s.occlusion;\nfinalColor += s.emissive;\nreturn vec4(finalColor, s.albedo.a);\n}\n#if CC_PIPELINE_TYPE == 0\n#define LIGHTS_PER_PASS 1\n#else\n#define LIGHTS_PER_PASS 10\n#endif\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 0\nlayout(std140) uniform CCForwardLight {\nhighp vec4 cc_lightPos[LIGHTS_PER_PASS];\nvec4 cc_lightColor[LIGHTS_PER_PASS];\nvec4 cc_lightSizeRangeAngle[LIGHTS_PER_PASS];\nvec4 cc_lightDir[LIGHTS_PER_PASS];\n};\n#endif\nfloat SmoothDistAtt (float distSqr, float invSqrAttRadius) {\nfloat factor = distSqr * invSqrAttRadius;\nfloat smoothFactor = clamp(1.0 - factor * factor, 0.0, 1.0);\nreturn smoothFactor * smoothFactor;\n}\nfloat GetDistAtt (float distSqr, float invSqrAttRadius) {\nfloat attenuation = 1.0 / max(distSqr, 0.01*0.01);\nattenuation *= SmoothDistAtt(distSqr , invSqrAttRadius);\nreturn attenuation;\n}\nfloat GetAngleAtt (vec3 L, vec3 litDir, float litAngleScale, float litAngleOffset) {\nfloat cd = dot(litDir, L);\nfloat attenuation = clamp(cd * litAngleScale + litAngleOffset, 0.0, 1.0);\nreturn (attenuation * attenuation);\n}\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 0\nvec4 CCStandardShadingAdditive (StandardSurface s, vec4 shadowPos) {\nvec3 position;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nposition = unpackHighpData(s.position, s.position_fract_part);\n#else\nposition = s.position;\n#endif\nvec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\nvec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\nvec3 diffuseContrib = diffuse / PI;\nvec3 N = normalize(s.normal);\nvec3 V = normalize(cc_cameraPos.xyz - position);\nfloat NV = max(abs(dot(N, V)), 0.0);\nspecular = BRDFApprox(specular, s.roughness, NV);\nvec3 finalColor = vec3(0.0);\nint numLights = CC_PIPELINE_TYPE == 0 ? LIGHTS_PER_PASS : int(cc_lightDir[0].w);\nfor (int i = 0; i < LIGHTS_PER_PASS; i++) {\nif (i >= numLights) break;\nvec3 SLU = cc_lightPos[i].xyz - position;\nvec3 SL = normalize(SLU);\nvec3 SH = normalize(SL + V);\nfloat SNL = max(dot(N, SL), 0.0);\nfloat SNH = max(dot(N, SH), 0.0);\nfloat distSqr = dot(SLU, SLU);\nfloat litRadius = cc_lightSizeRangeAngle[i].x;\nfloat litRadiusSqr = litRadius * litRadius;\nfloat illum = litRadiusSqr / max(litRadiusSqr, distSqr);\nfloat attRadiusSqrInv = 1.0 / max(cc_lightSizeRangeAngle[i].y, 0.01);\nattRadiusSqrInv *= attRadiusSqrInv;\nfloat att = GetDistAtt(distSqr, attRadiusSqrInv);\nvec3 lspec = specular * CalcSpecular(s.roughness, SNH, SH, N);\nif (cc_lightPos[i].w > 0.0) {\nfloat cosInner = max(dot(-cc_lightDir[i].xyz, SL), 0.01);\nfloat cosOuter = cc_lightSizeRangeAngle[i].z;\nfloat litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\nfloat litAngleOffset = -cosOuter * litAngleScale;\natt *= GetAngleAtt(SL, -cc_lightDir[i].xyz, litAngleScale, litAngleOffset);\n}\nvec3 lightColor = cc_lightColor[i].rgb;\nfloat shadow = 1.0;\n#if CC_RECEIVE_SHADOW\nif (cc_lightPos[i].w > 0.0 && cc_lightSizeRangeAngle[i].w > 0.0) {\nshadow = CCSpotShadowFactorBase(shadowPos, position, s.shadowBias);\n}\n#endif\nlightColor *= shadow;\nfinalColor += SNL * lightColor * cc_lightColor[i].w * illum * att * (diffuseContrib + lspec);\n}\nreturn vec4(finalColor, 0.0);\n}\n#endif\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 1\nlayout(std430, binding = 4) readonly buffer b_ccLightsBuffer { vec4 b_ccLights[]; };\nlayout(std430, binding = 5) readonly buffer b_clusterLightIndicesBuffer { uint b_clusterLightIndices[]; };\nlayout(std430, binding = 6) readonly buffer b_clusterLightGridBuffer { uvec4 b_clusterLightGrid[]; };\nstruct CCLight\n{\nvec4 cc_lightPos;\nvec4 cc_lightColor;\nvec4 cc_lightSizeRangeAngle;\nvec4 cc_lightDir;\n};\nstruct Cluster\n{\nvec3 minBounds;\nvec3 maxBounds;\n};\nstruct LightGrid\n{\nuint offset;\nuint ccLights;\n};\nCCLight getCCLight(uint i)\n{\nCCLight light;\nlight.cc_lightPos = b_ccLights[4u * i + 0u];\nlight.cc_lightColor = b_ccLights[4u * i + 1u];\nlight.cc_lightSizeRangeAngle = b_ccLights[4u * i + 2u];\nlight.cc_lightDir = b_ccLights[4u * i + 3u];\nreturn light;\n}\nLightGrid getLightGrid(uint cluster)\n{\nuvec4 gridvec = b_clusterLightGrid[cluster];\nLightGrid grid;\ngrid.offset = gridvec.x;\ngrid.ccLights = gridvec.y;\nreturn grid;\n}\nuint getGridLightIndex(uint start, uint offset)\n{\nreturn b_clusterLightIndices[start + offset];\n}\nuint getClusterZIndex(vec4 worldPos)\n{\nfloat scale = float(24) / log(cc_nearFar.y / cc_nearFar.x);\nfloat bias = -(float(24) * log(cc_nearFar.x) / log(cc_nearFar.y / cc_nearFar.x));\nfloat eyeDepth = -(cc_matView * worldPos).z;\nuint zIndex = uint(max(log(eyeDepth) * scale + bias, 0.0));\nreturn zIndex;\n}\nuint getClusterIndex(vec4 fragCoord, vec4 worldPos)\n{\nuint zIndex = getClusterZIndex(worldPos);\nfloat clusterSizeX = ceil(cc_viewPort.z / float(16));\nfloat clusterSizeY = ceil(cc_viewPort.w / float(8));\nuvec3 indices = uvec3(uvec2(fragCoord.xy / vec2(clusterSizeX, clusterSizeY)), zIndex);\nuint cluster = (16u * 8u) * indices.z + 16u * indices.y + indices.x;\nreturn cluster;\n}\nvec4 CCClusterShadingAdditive (StandardSurface s, vec4 shadowPos) {\nvec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\nvec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\nvec3 diffuseContrib = diffuse / PI;\nvec3 position;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nposition = unpackHighpData(s.position, s.position_fract_part);\n#else\nposition = s.position;\n#endif\nvec3 N = normalize(s.normal);\nvec3 V = normalize(cc_cameraPos.xyz - position);\nfloat NV = max(abs(dot(N, V)), 0.001);\nspecular = BRDFApprox(specular, s.roughness, NV);\nvec3 finalColor = vec3(0.0);\nuint cluster = getClusterIndex(gl_FragCoord, vec4(position, 1.0));\nLightGrid grid = getLightGrid(cluster);\nuint numLights = grid.ccLights;\nfor (uint i = 0u; i < 100u; i++) {\nif (i >= numLights) break;\nuint lightIndex = getGridLightIndex(grid.offset, i);\nCCLight light = getCCLight(lightIndex);\nvec3 SLU = light.cc_lightPos.xyz - position;\nvec3 SL = normalize(SLU);\nvec3 SH = normalize(SL + V);\nfloat SNL = max(dot(N, SL), 0.001);\nfloat SNH = max(dot(N, SH), 0.0);\nfloat distSqr = dot(SLU, SLU);\nfloat litRadius = light.cc_lightSizeRangeAngle.x;\nfloat litRadiusSqr = litRadius * litRadius;\nfloat illum = PI * (litRadiusSqr / max(litRadiusSqr , distSqr));\nfloat attRadiusSqrInv = 1.0 / max(light.cc_lightSizeRangeAngle.y, 0.01);\nattRadiusSqrInv *= attRadiusSqrInv;\nfloat att = GetDistAtt(distSqr, attRadiusSqrInv);\nvec3 lspec = specular * CalcSpecular(s.roughness, SNH, SH, N);\nif (light.cc_lightPos.w > 0.0) {\nfloat cosInner = max(dot(-light.cc_lightDir.xyz, SL), 0.01);\nfloat cosOuter = light.cc_lightSizeRangeAngle.z;\nfloat litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\nfloat litAngleOffset = -cosOuter * litAngleScale;\natt *= GetAngleAtt(SL, -light.cc_lightDir.xyz, litAngleScale, litAngleOffset);\n}\nvec3 lightColor = light.cc_lightColor.rgb;\nfloat shadow = 1.0;\n#if CC_RECEIVE_SHADOW\nif (light.cc_lightPos.w > 0.0) {\nshadow = CCSpotShadowFactorBase(shadowPos, position, s.shadowBias);\n}\n#endif\nlightColor *= shadow;\nfinalColor += SNL * lightColor * light.cc_lightColor.w * illum * att * (diffuseContrib + lspec);\n}\nreturn vec4(finalColor, 0.0);\n}\n#endif\nvec3 ACESToneMap (vec3 color) {\ncolor = min(color, vec3(8.0));\nconst float A = 2.51;\nconst float B = 0.03;\nconst float C = 2.43;\nconst float D = 0.59;\nconst float E = 0.14;\nreturn (color * (A * color + B)) / (color * (C * color + D) + E);\n}\nvec4 CCFragOutput (vec4 color) {\n#if CC_USE_HDR\ncolor.rgb = ACESToneMap(color.rgb);\n#endif\ncolor.rgb = sqrt(color.rgb);\nreturn color;\n}\nfloat LinearFog(vec4 pos) {\nvec4 wPos = pos;\nfloat cam_dis = distance(cc_cameraPos, wPos);\nfloat fogStart = cc_fogBase.x;\nfloat fogEnd = cc_fogBase.y;\nreturn clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * fogDensity);\nreturn f;\n}\nfloat ExpSquaredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\nreturn f;\n}\nfloat LayeredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat _FogTop = cc_fogAdd.x;\nfloat _FogRange = cc_fogAdd.y;\nvec3 camWorldProj = cc_cameraPos.xyz;\ncamWorldProj.y = 0.;\nvec3 worldPosProj = wPos.xyz;\nworldPosProj.y = 0.;\nfloat fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\nfloat fDeltaY, fDensityIntegral;\nif (cc_cameraPos.y > _FogTop) {\nif (wPos.y < _FogTop) {\nfDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\nfDensityIntegral = fDeltaY * fDeltaY * 0.5;\n} else {\nfDeltaY = 0.;\nfDensityIntegral = 0.;\n}\n} else {\nif (wPos.y < _FogTop) {\nfloat fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfloat fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\nfDeltaY = abs(fDeltaA - fDeltaB);\nfDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n} else {\nfDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n}\n}\nfloat fDensity;\nif (fDeltaY != 0.) {\nfDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n} else {\nfDensity = 0.;\n}\nfloat f = exp(-fDensity);\nreturn f;\n}\nvoid CC_TRANSFER_FOG_BASE(vec4 pos, out float factor)\n{\n#if CC_USE_FOG == 0\nfactor = LinearFog(pos);\n#elif CC_USE_FOG == 1\nfactor = ExpFog(pos);\n#elif CC_USE_FOG == 2\nfactor = ExpSquaredFog(pos);\n#elif CC_USE_FOG == 3\nfactor = LayeredFog(pos);\n#else\nfactor = 1.0;\n#endif\n}\nvoid CC_APPLY_FOG_BASE(inout vec4 color, float factor) {\ncolor = vec4(mix(cc_fogColor.rgb, color.rgb, factor), color.a);\n}\nvec2 signNotZero(vec2 v) {\nreturn vec2((v.x >= 0.0) ? +1.0 : -1.0, (v.y >= 0.0) ? +1.0 : -1.0);\n}\nvec3 oct_to_float32x3(vec2 e) {\nvec3 v = vec3(e.xy, 1.0 - abs(e.x) - abs(e.y));\nif (v.z < 0.0) v.xy = (1.0 - abs(v.yx)) * signNotZero(v.xy);\nreturn normalize(v);\n}\nvec4 screen2WS(vec3 coord) {\nvec3 ndc = vec3(\n2.0 * (coord.x - cc_viewPort.x) / cc_viewPort.z - 1.0,\n2.0 * (coord.y - cc_viewPort.y) / cc_viewPort.w - 1.0,\n2.0 * coord.z - 1.0);\nvec4 world = ((cc_matViewProjInv) * (vec4(ndc, 1.0)));\nworld = world / world.w;\nreturn world;\n}\nin vec2 v_uv;\n#if CC_DEVICE_CAN_BENEFIT_FROM_INPUT_ATTACHMENT\nlayout(location = 0) inout vec4 gbuffer_albedoMap;\nlayout(location = 1) inout vec4 gbuffer_normalMap;\nlayout(location = 2) inout vec4 gbuffer_emissiveMap;\nuniform sampler2D depth_stencil;\n#else\nuniform sampler2D gbuffer_albedoMap;\nuniform sampler2D gbuffer_normalMap;\nuniform sampler2D gbuffer_emissiveMap;\nuniform sampler2D depth_stencil;\n#endif\n#if !CC_DEVICE_CAN_BENEFIT_FROM_INPUT_ATTACHMENT || __VERSION__ >= 450\nlayout(location = 0) out vec4 fragColor;\n#endif\nvoid main () {\nStandardSurface s;\n#if CC_DEVICE_CAN_BENEFIT_FROM_INPUT_ATTACHMENT\nvec4 albedoMap = gbuffer_albedoMap;\nvec4 normalMap = gbuffer_normalMap;\nvec4 emissiveMap = gbuffer_emissiveMap;\nfloat depth = texture(depth_stencil, v_uv).x;\n#else\nvec4 albedoMap = texture(gbuffer_albedoMap,v_uv);\nvec4 normalMap = texture(gbuffer_normalMap,v_uv);\nvec4 emissiveMap = texture(gbuffer_emissiveMap,v_uv);\nfloat depth = texture(depth_stencil, v_uv).x;\n#endif\ns.albedo = albedoMap;\nvec3 position = screen2WS(vec3(gl_FragCoord.xy, depth)).xyz;\ns.position = position;\ns.roughness = normalMap.z;\ns.normal = oct_to_float32x3(normalMap.xy);\ns.specularIntensity = 0.5;\ns.metallic = normalMap.w;\ns.emissive = emissiveMap.xyz;\ns.occlusion = emissiveMap.w;\nfloat fogFactor;\nCC_TRANSFER_FOG_BASE(vec4(position, 1), fogFactor);\nvec4 shadowPos;\nshadowPos = cc_matLightViewProj * vec4(position, 1);\nvec4 color = CCStandardShadingBase(s, shadowPos) +\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 1\nCCClusterShadingAdditive(s, shadowPos);\n#else\nCCStandardShadingAdditive(s, shadowPos);\n#endif\nCC_APPLY_FOG_BASE(color, fogFactor);\ncolor = CCFragOutput(color);\n#if CC_DEVICE_CAN_BENEFIT_FROM_INPUT_ATTACHMENT\ngbuffer_emissiveMap = color;\n#else\nfragColor = color;\n#endif\n}", + "vert": "\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nin vec3 a_position;\nin vec3 a_normal;\nin vec2 a_texCoord;\nin vec4 a_tangent;\n#if CC_USE_SKINNING\nin vec4 a_joints;\nin vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nin highp vec4 a_jointAnimInfo;\n#endif\nin vec4 a_matWorld0;\nin vec4 a_matWorld1;\nin vec4 a_matWorld2;\n#if CC_USE_LIGHTMAP\nin vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nin vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nin float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nin float a_vertexId;\n#endif\nlayout(std140) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(std140) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\nout vec2 v_uv;\nvoid main () {\nvec4 position;\nposition = vec4(a_position, 1.0);\nposition.xy = cc_cameraPos.w == 0.0 ? vec2(position.xy.x, -position.xy.y) : position.xy;\ngl_Position = vec4(position.x, position.y, 1.0, 1.0);\nv_uv = a_texCoord;\n}", + "frag": "\n#ifdef GL_EXT_shader_framebuffer_fetch\n#extension GL_EXT_shader_framebuffer_fetch: enable\n#endif\nprecision highp float;\nlayout(std140) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(std140) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nvec3 SRGBToLinear (vec3 gamma) {\nreturn gamma * gamma;\n}\nlayout(std140) uniform CCShadow {\nhighp mat4 cc_matLightPlaneProj;\nhighp mat4 cc_matLightView;\nhighp mat4 cc_matLightViewProj;\nhighp vec4 cc_shadowInvProjDepthInfo;\nhighp vec4 cc_shadowProjDepthInfo;\nhighp vec4 cc_shadowProjInfo;\nmediump vec4 cc_shadowNFLSInfo;\nmediump vec4 cc_shadowWHPBInfo;\nmediump vec4 cc_shadowLPNNInfo;\nlowp vec4 cc_shadowColor;\nmediump vec4 cc_planarNDInfo;\n};\nhighp float unpackHighpData (float mainPart, float modPart) {\nhighp float data = mainPart;\nreturn data + modPart;\n}\nhighp float unpackHighpData (float mainPart, float modPart, const float modValue) {\nhighp float data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nhighp vec2 unpackHighpData (vec2 mainPart, vec2 modPart) {\nhighp vec2 data = mainPart;\nreturn data + modPart;\n}\nhighp vec2 unpackHighpData (vec2 mainPart, vec2 modPart, const float modValue) {\nhighp vec2 data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nhighp vec3 unpackHighpData (vec3 mainPart, vec3 modPart) {\nhighp vec3 data = mainPart;\nreturn data + modPart;\n}\nhighp vec3 unpackHighpData (vec3 mainPart, vec3 modPart, const float modValue) {\nhighp vec3 data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nhighp vec4 unpackHighpData (vec4 mainPart, vec4 modPart) {\nhighp vec4 data = mainPart;\nreturn data + modPart;\n}\nhighp vec4 unpackHighpData (vec4 mainPart, vec4 modPart, const float modValue) {\nhighp vec4 data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nlayout(std140) uniform CCLocal {\nhighp mat4 cc_matWorld;\nhighp mat4 cc_matWorldIT;\nhighp vec4 cc_lightingMapUVParam;\nhighp vec4 cc_localShadowBias;\n};\nfloat CCGetLinearDepthFromViewSpace(vec3 viewPos) {\nfloat dist = length(viewPos);\nreturn (dist - cc_shadowNFLSInfo.x) / (cc_shadowNFLSInfo.y - cc_shadowNFLSInfo.x);\n}\nfloat CCGetLinearDepth(vec3 worldPos) {\nvec4 viewStartPos = cc_matLightView * vec4(worldPos.xyz, 1.0);\nreturn CCGetLinearDepthFromViewSpace(viewStartPos.xyz);\n}\n#if CC_RECEIVE_SHADOW\nuniform highp sampler2D cc_shadowMap;\nuniform highp sampler2D cc_spotLightingMap;\nvec4 ApplyShadowDepthBias_FaceNormal(vec4 shadowPos, vec3 worldNormal, float normalBias)\n{\nvec4 newShadowPos = shadowPos;\nif(normalBias > EPSILON_LOWP)\n{\nvec4 viewNormal = cc_matLightView * vec4(worldNormal, 0.0);\nif(viewNormal.z < 0.1)\nnewShadowPos.xy += viewNormal.xy * cc_shadowProjInfo.xy * normalBias * clamp(viewNormal.z, 0.001, 0.1);\n}\nreturn newShadowPos;\n}\nvec4 ApplyShadowDepthBias_Perspective(vec4 shadowPos, float viewspaceDepthBias)\n{\nvec3 viewSpacePos;\nviewSpacePos.xy = shadowPos.xy * cc_shadowProjInfo.zw;\nviewSpacePos.z = shadowPos.z * cc_shadowInvProjDepthInfo.x + shadowPos.w * cc_shadowInvProjDepthInfo.y;\nviewSpacePos.xyz += cc_shadowProjDepthInfo.z * normalize(viewSpacePos.xyz) * viewspaceDepthBias;\nvec4 clipSpacePos;\nclipSpacePos.xy = viewSpacePos.xy * cc_shadowProjInfo.xy;\nclipSpacePos.zw = viewSpacePos.z * cc_shadowProjDepthInfo.xz + vec2(cc_shadowProjDepthInfo.y, 0.0);\nif (cc_shadowNFLSInfo.z > EPSILON) {\nclipSpacePos.z = CCGetLinearDepthFromViewSpace(viewSpacePos.xyz);\nclipSpacePos.z = (clipSpacePos.z * 2.0 - 1.0) * clipSpacePos.w;\n}\nreturn clipSpacePos;\n}\nvec4 ApplyShadowDepthBias_Orthographic(vec4 shadowPos, float viewspaceDepthBias)\n{\nfloat coeffA = cc_shadowProjDepthInfo.x;\nfloat coeffB = cc_shadowProjDepthInfo.y;\nfloat viewSpacePos_z = (shadowPos.z - coeffB) / coeffA;\nviewSpacePos_z += viewspaceDepthBias;\nvec4 result = shadowPos;\nresult.z = viewSpacePos_z * coeffA + coeffB;\nreturn result;\n}\nfloat CCGetShadowFactorHard (vec4 shadowPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Orthographic(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat shadow = 0.0;\nfloat closestDepth = 0.0;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nclosestDepth = dot(texture(cc_shadowMap, clipPos.xy), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0));\n} else {\nclosestDepth = texture(cc_shadowMap, clipPos.xy).x;\n}\nshadow = step(clipPos.z, closestDepth);\nreturn shadow;\n}\nfloat CCGetShadowFactorSoft (vec4 shadowPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Orthographic(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat offsetDepth = clipPos.z;\nvec2 mapSize = cc_shadowWHPBInfo.xy;\nvec2 oneTap = 1.0 / mapSize;\nvec2 clipPos_offset = clipPos.xy + oneTap;\nfloat block0, block1, block2, block3;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos.y)).x);\nblock1 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset.x, clipPos.y)).x);\nblock2 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset.y)).x);\nblock3 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset.x, clipPos_offset.y)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * mapSize.x;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block2, block3, coefX);\nfloat coefY = mod(clipPos.y, oneTap.y) * mapSize.y;\nreturn mix(resultX, resultY, coefY);\n}\nfloat CCGetShadowFactorSoft2X (vec4 shadowPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Orthographic(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat offsetDepth = clipPos.z;\nvec2 mapSize = cc_shadowWHPBInfo.xy;\nvec2 oneTap = 1.0 / mapSize;\nfloat clipPos_offset_L = clipPos.x - oneTap.x;\nfloat clipPos_offset_R = clipPos.x + oneTap.x;\nfloat clipPos_offset_U = clipPos.y - oneTap.y;\nfloat clipPos_offset_D = clipPos.y + oneTap.y;\nfloat block0, block1, block2, block3, block4, block5, block6, block7, block8;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock4 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock5 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock6 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock7 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock8 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_U)).x);\nblock1 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset_U)).x);\nblock2 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_U)).x);\nblock3 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos.y)).x);\nblock4 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos.y)).x);\nblock5 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos.y)).x);\nblock6 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_D)).x);\nblock7 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset_D)).x);\nblock8 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_D)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * mapSize.x;\nfloat coefY = mod(clipPos.y, oneTap.y) * mapSize.y;\nfloat shadow = 0.0;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block3, block4, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block1, block2, coefX);\nresultY = mix(block4, block5, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block3, block4, coefX);\nresultY = mix(block6, block7, coefX);\nshadow += mix(resultX, resultY, coefY);\nresultX = mix(block4, block5, coefX);\nresultY = mix(block7, block8, coefX);\nshadow += mix(resultX, resultY, coefY);\nreturn shadow * 0.25;\n}\nfloat CCGetSpotLightShadowFactorHard (vec4 shadowPos, vec3 worldPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Perspective(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat shadow = 0.0;\nfloat closestDepth = 0.0;\nfloat depth = clipPos.z;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nclosestDepth = dot(texture(cc_spotLightingMap, clipPos.xy), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0));\n} else {\nclosestDepth = texture(cc_spotLightingMap, clipPos.xy).x;\n}\nshadow = step(depth, closestDepth);\nreturn shadow;\n}\nfloat CCGetSpotLightShadowFactorSoft (vec4 shadowPos, vec3 worldPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Perspective(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat depth = 0.0;\nif (cc_shadowNFLSInfo.z > EPSILON) {\ndepth = CCGetLinearDepth(worldPos);\n} else {\ndepth = clipPos.z;\n}\nvec2 oneTap = 1.0 / cc_shadowWHPBInfo.xy;\nvec2 clipPos_offset = clipPos.xy + oneTap;\nfloat block0, block1, block2, block3;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)).x);\nblock1 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos.y)).x);\nblock2 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset.y)).x);\nblock3 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos_offset.y)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * cc_shadowWHPBInfo.x;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block2, block3, coefX);\nfloat coefY = mod(clipPos.y, oneTap.y) * cc_shadowWHPBInfo.y;\nreturn mix(resultX, resultY, coefY);\n}\nfloat CCGetSpotLightShadowFactorSoft2X (vec4 shadowPos, vec3 worldPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Perspective(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat depth = 0.0;\nif (cc_shadowNFLSInfo.z > EPSILON) {\ndepth = CCGetLinearDepth(worldPos);\n} else {\ndepth = clipPos.z;\n}\nvec2 mapSize = cc_shadowWHPBInfo.xy;\nvec2 oneTap = 1.0 / mapSize;\nfloat clipPos_offset_L = clipPos.x - oneTap.x;\nfloat clipPos_offset_R = clipPos.x + oneTap.x;\nfloat clipPos_offset_U = clipPos.y - oneTap.y;\nfloat clipPos_offset_D = clipPos.y + oneTap.y;\nfloat block0, block1, block2, block3, block4, block5, block6, block7, block8;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock4 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock5 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock6 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock7 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock8 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_U)).x);\nblock1 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_U)).x);\nblock2 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_U)).x);\nblock3 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos.y)).x);\nblock4 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)).x);\nblock5 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos.y)).x);\nblock6 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_D)).x);\nblock7 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_D)).x);\nblock8 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_D)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * mapSize.x;\nfloat coefY = mod(clipPos.y, oneTap.y) * mapSize.y;\nfloat shadow = 0.0;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block3, block4, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block1, block2, coefX);\nresultY = mix(block4, block5, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block3, block4, coefX);\nresultY = mix(block6, block7, coefX);\nshadow += mix(resultX, resultY, coefY);\nresultX = mix(block4, block5, coefX);\nresultY = mix(block7, block8, coefX);\nshadow += mix(resultX, resultY, coefY);\nreturn shadow * 0.25;\n}\nfloat CCSpotShadowFactorBase(vec4 shadowPos, vec3 worldPos, vec2 shadowBias)\n{\nfloat pcf = cc_shadowWHPBInfo.z;\nif (pcf > 1.9) {\nreturn CCGetSpotLightShadowFactorSoft2X(shadowPos, worldPos, shadowBias.x);\n}else if (pcf > 0.9) {\nreturn CCGetSpotLightShadowFactorSoft(shadowPos, worldPos, shadowBias.x);\n}else {\nreturn CCGetSpotLightShadowFactorHard(shadowPos, worldPos, shadowBias.x);\n}\n}\nfloat CCShadowFactorBase(vec4 shadowPos, vec3 N, vec2 shadowBias)\n{\nfloat realtimeShadow = 1.0;\nvec4 pos = ApplyShadowDepthBias_FaceNormal(shadowPos, N, shadowBias.y);\nfloat pcf = cc_shadowWHPBInfo.z;\nif (pcf > 1.9) {\nrealtimeShadow = CCGetShadowFactorSoft2X(pos, shadowBias.x);\n}else if (pcf > 0.9) {\nrealtimeShadow = CCGetShadowFactorSoft(pos, shadowBias.x);\n}else {\nrealtimeShadow = CCGetShadowFactorHard(pos, shadowBias.x);\n}\nreturn mix(realtimeShadow, 1.0, cc_shadowNFLSInfo.w);\n}\n#endif\n#if CC_USE_IBL\nuniform samplerCube cc_environment;\nvec4 fragTextureLod (sampler2D tex, vec2 coord, float lod) {\nreturn textureLod(tex, coord, lod);\n}\nvec4 fragTextureLod (samplerCube tex, vec3 coord, float lod) {\nreturn textureLod(tex, coord, lod);\n}\nvec3 unpackRGBE (vec4 rgbe) {\nreturn rgbe.rgb * pow(1.1, rgbe.a * 255.0 - 128.0);\n}\n#if CC_USE_DIFFUSEMAP\nuniform samplerCube cc_diffuseMap;\n#endif\n#endif\nfloat GGXMobile (float roughness, float NoH, vec3 H, vec3 N) {\nvec3 NxH = cross(N, H);\nfloat OneMinusNoHSqr = dot(NxH, NxH);\nfloat a = roughness * roughness;\nfloat n = NoH * a;\nfloat p = a / (OneMinusNoHSqr + n * n);\nreturn p * p;\n}\nfloat CalcSpecular (float roughness, float NoH, vec3 H, vec3 N) {\nreturn (roughness * 0.25 + 0.25) * GGXMobile(roughness, NoH, H, N);\n}\nvec3 BRDFApprox (vec3 specular, float roughness, float NoV) {\nconst vec4 c0 = vec4(-1.0, -0.0275, -0.572, 0.022);\nconst vec4 c1 = vec4(1.0, 0.0425, 1.04, -0.04);\nvec4 r = roughness * c0 + c1;\nfloat a004 = min(r.x * r.x, exp2(-9.28 * NoV)) * r.x + r.y;\nvec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;\nAB.y *= clamp(50.0 * specular.g, 0.0, 1.0);\nreturn specular * AB.x + AB.y;\n}\n#if USE_REFLECTION_DENOISE\nvec3 GetEnvReflectionWithMipFiltering(vec3 R, float roughness, float mipCount, float denoiseIntensity) {\n#if CC_USE_IBL\nfloat mip = roughness * mipCount;\nfloat delta = (dot(dFdx(R), dFdy(R))) * 1000.0;\nfloat mipBias = mix(0.0, 5.0, clamp(delta, 0.0, 1.0));\nvec4 biased = fragTextureLod(cc_environment, R, mip + mipBias);\nvec4 filtered = texture(cc_environment, R);\n#if CC_USE_IBL == 2\nbiased.rgb = unpackRGBE(biased);\nfiltered.rgb = unpackRGBE(filtered);\n#else\nbiased.rgb = SRGBToLinear(biased.rgb);\nfiltered.rgb = SRGBToLinear(filtered.rgb);\n#endif\nreturn mix(biased.rgb, filtered.rgb, denoiseIntensity);\n#else\nreturn vec3(0.0, 0.0, 0.0);\n#endif\n}\n#endif\nstruct StandardSurface {\nvec4 albedo;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nvec3 position, position_fract_part;\n#else\nvec3 position;\n#endif\nvec3 normal;\nvec3 emissive;\nvec3 lightmap;\nfloat lightmap_test;\nfloat roughness;\nfloat metallic;\nfloat occlusion;\nfloat specularIntensity;\n#if CC_RECEIVE_SHADOW\nvec2 shadowBias;\n#endif\n};\nvec4 CCStandardShadingBase (StandardSurface s, vec4 shadowPos) {\nvec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\nvec3 specular = mix(vec3(0.08 * s.specularIntensity), s.albedo.rgb, s.metallic);\nvec3 position;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nposition = unpackHighpData(s.position, s.position_fract_part);\n#else\nposition = s.position;\n#endif\nvec3 N = normalize(s.normal);\nvec3 V = normalize(cc_cameraPos.xyz - position);\nfloat NV = max(abs(dot(N, V)), 0.0);\nspecular = BRDFApprox(specular, s.roughness, NV);\nvec3 L = normalize(-cc_mainLitDir.xyz);\nvec3 H = normalize(L + V);\nfloat NH = max(dot(N, H), 0.0);\nfloat NL = max(dot(N, L), 0.0);\nvec3 finalColor = NL * cc_mainLitColor.rgb * cc_mainLitColor.w;\nvec3 diffuseContrib = diffuse / PI;\nvec3 specularContrib = specular * CalcSpecular(s.roughness, NH, H, N);\nvec3 dirlightContrib = (diffuseContrib + specularContrib);\nfloat shadow = 1.0;\n#if CC_RECEIVE_SHADOW\nif (NL > 0.0 && cc_mainLitDir.w > 0.0) {\nshadow = CCShadowFactorBase(shadowPos, N, s.shadowBias);\n}\n#endif\ndirlightContrib *= shadow;\nfinalColor *= dirlightContrib;\n#if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\nif (s.lightmap_test > EPSILON_LOWP) {\nfinalColor = diffuse * s.lightmap.rgb * shadow;\n}\n#endif\nfloat fAmb = 0.5 - N.y * 0.5;\nvec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb);\n#if CC_USE_IBL\n#if CC_USE_DIFFUSEMAP\nvec4 diffuseMap = texture(cc_diffuseMap, N);\n#if CC_USE_DIFFUSEMAP == 2\nambDiff = unpackRGBE(diffuseMap);\n#else\nambDiff = SRGBToLinear(diffuseMap.rgb);\n#endif\n#endif\nvec3 R = normalize(reflect(-V, N));\n#if USE_REFLECTION_DENOISE\nvec3 env = GetEnvReflectionWithMipFiltering(R, s.roughness, cc_ambientGround.w, 0.6);\n#else\nvec4 envmap = fragTextureLod(cc_environment, R, s.roughness * cc_ambientGround.w);\n#if CC_USE_IBL == 2\nvec3 env = unpackRGBE(envmap);\n#else\nvec3 env = SRGBToLinear(envmap.rgb);\n#endif\n#endif\nfinalColor += env * cc_ambientSky.w * specular * s.occlusion;\n#endif\nfinalColor += ambDiff.rgb * cc_ambientSky.w * diffuse * s.occlusion;\nfinalColor += s.emissive;\nreturn vec4(finalColor, s.albedo.a);\n}\n#if CC_PIPELINE_TYPE == 0\n#define LIGHTS_PER_PASS 1\n#else\n#define LIGHTS_PER_PASS 10\n#endif\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 0\nlayout(std140) uniform CCForwardLight {\nhighp vec4 cc_lightPos[LIGHTS_PER_PASS];\nvec4 cc_lightColor[LIGHTS_PER_PASS];\nvec4 cc_lightSizeRangeAngle[LIGHTS_PER_PASS];\nvec4 cc_lightDir[LIGHTS_PER_PASS];\n};\n#endif\nfloat SmoothDistAtt (float distSqr, float invSqrAttRadius) {\nfloat factor = distSqr * invSqrAttRadius;\nfloat smoothFactor = clamp(1.0 - factor * factor, 0.0, 1.0);\nreturn smoothFactor * smoothFactor;\n}\nfloat GetDistAtt (float distSqr, float invSqrAttRadius) {\nfloat attenuation = 1.0 / max(distSqr, 0.01*0.01);\nattenuation *= SmoothDistAtt(distSqr , invSqrAttRadius);\nreturn attenuation;\n}\nfloat GetAngleAtt (vec3 L, vec3 litDir, float litAngleScale, float litAngleOffset) {\nfloat cd = dot(litDir, L);\nfloat attenuation = clamp(cd * litAngleScale + litAngleOffset, 0.0, 1.0);\nreturn (attenuation * attenuation);\n}\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 0\nvec4 CCStandardShadingAdditive (StandardSurface s, vec4 shadowPos) {\nvec3 position;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nposition = unpackHighpData(s.position, s.position_fract_part);\n#else\nposition = s.position;\n#endif\nvec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\nvec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\nvec3 diffuseContrib = diffuse / PI;\nvec3 N = normalize(s.normal);\nvec3 V = normalize(cc_cameraPos.xyz - position);\nfloat NV = max(abs(dot(N, V)), 0.0);\nspecular = BRDFApprox(specular, s.roughness, NV);\nvec3 finalColor = vec3(0.0);\nint numLights = CC_PIPELINE_TYPE == 0 ? LIGHTS_PER_PASS : int(cc_lightDir[0].w);\nfor (int i = 0; i < LIGHTS_PER_PASS; i++) {\nif (i >= numLights) break;\nvec3 SLU = cc_lightPos[i].xyz - position;\nvec3 SL = normalize(SLU);\nvec3 SH = normalize(SL + V);\nfloat SNL = max(dot(N, SL), 0.0);\nfloat SNH = max(dot(N, SH), 0.0);\nfloat distSqr = dot(SLU, SLU);\nfloat litRadius = cc_lightSizeRangeAngle[i].x;\nfloat litRadiusSqr = litRadius * litRadius;\nfloat illum = litRadiusSqr / max(litRadiusSqr, distSqr);\nfloat attRadiusSqrInv = 1.0 / max(cc_lightSizeRangeAngle[i].y, 0.01);\nattRadiusSqrInv *= attRadiusSqrInv;\nfloat att = GetDistAtt(distSqr, attRadiusSqrInv);\nvec3 lspec = specular * CalcSpecular(s.roughness, SNH, SH, N);\nif (cc_lightPos[i].w > 0.0) {\nfloat cosInner = max(dot(-cc_lightDir[i].xyz, SL), 0.01);\nfloat cosOuter = cc_lightSizeRangeAngle[i].z;\nfloat litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\nfloat litAngleOffset = -cosOuter * litAngleScale;\natt *= GetAngleAtt(SL, -cc_lightDir[i].xyz, litAngleScale, litAngleOffset);\n}\nvec3 lightColor = cc_lightColor[i].rgb;\nfloat shadow = 1.0;\n#if CC_RECEIVE_SHADOW\nif (cc_lightPos[i].w > 0.0 && cc_lightSizeRangeAngle[i].w > 0.0) {\nshadow = CCSpotShadowFactorBase(shadowPos, position, s.shadowBias);\n}\n#endif\nlightColor *= shadow;\nfinalColor += SNL * lightColor * cc_lightColor[i].w * illum * att * (diffuseContrib + lspec);\n}\nreturn vec4(finalColor, 0.0);\n}\n#endif\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 1\nlayout(std430, binding = 4) readonly buffer b_ccLightsBuffer { vec4 b_ccLights[]; };\nlayout(std430, binding = 5) readonly buffer b_clusterLightIndicesBuffer { uint b_clusterLightIndices[]; };\nlayout(std430, binding = 6) readonly buffer b_clusterLightGridBuffer { uvec4 b_clusterLightGrid[]; };\nstruct CCLight\n{\nvec4 cc_lightPos;\nvec4 cc_lightColor;\nvec4 cc_lightSizeRangeAngle;\nvec4 cc_lightDir;\n};\nstruct Cluster\n{\nvec3 minBounds;\nvec3 maxBounds;\n};\nstruct LightGrid\n{\nuint offset;\nuint ccLights;\n};\nCCLight getCCLight(uint i)\n{\nCCLight light;\nlight.cc_lightPos = b_ccLights[4u * i + 0u];\nlight.cc_lightColor = b_ccLights[4u * i + 1u];\nlight.cc_lightSizeRangeAngle = b_ccLights[4u * i + 2u];\nlight.cc_lightDir = b_ccLights[4u * i + 3u];\nreturn light;\n}\nLightGrid getLightGrid(uint cluster)\n{\nuvec4 gridvec = b_clusterLightGrid[cluster];\nLightGrid grid;\ngrid.offset = gridvec.x;\ngrid.ccLights = gridvec.y;\nreturn grid;\n}\nuint getGridLightIndex(uint start, uint offset)\n{\nreturn b_clusterLightIndices[start + offset];\n}\nuint getClusterZIndex(vec4 worldPos)\n{\nfloat scale = float(24) / log(cc_nearFar.y / cc_nearFar.x);\nfloat bias = -(float(24) * log(cc_nearFar.x) / log(cc_nearFar.y / cc_nearFar.x));\nfloat eyeDepth = -(cc_matView * worldPos).z;\nuint zIndex = uint(max(log(eyeDepth) * scale + bias, 0.0));\nreturn zIndex;\n}\nuint getClusterIndex(vec4 fragCoord, vec4 worldPos)\n{\nuint zIndex = getClusterZIndex(worldPos);\nfloat clusterSizeX = ceil(cc_viewPort.z / float(16));\nfloat clusterSizeY = ceil(cc_viewPort.w / float(8));\nuvec3 indices = uvec3(uvec2(fragCoord.xy / vec2(clusterSizeX, clusterSizeY)), zIndex);\nuint cluster = (16u * 8u) * indices.z + 16u * indices.y + indices.x;\nreturn cluster;\n}\nvec4 CCClusterShadingAdditive (StandardSurface s, vec4 shadowPos) {\nvec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\nvec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\nvec3 diffuseContrib = diffuse / PI;\nvec3 position;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nposition = unpackHighpData(s.position, s.position_fract_part);\n#else\nposition = s.position;\n#endif\nvec3 N = normalize(s.normal);\nvec3 V = normalize(cc_cameraPos.xyz - position);\nfloat NV = max(abs(dot(N, V)), 0.001);\nspecular = BRDFApprox(specular, s.roughness, NV);\nvec3 finalColor = vec3(0.0);\nuint cluster = getClusterIndex(gl_FragCoord, vec4(position, 1.0));\nLightGrid grid = getLightGrid(cluster);\nuint numLights = grid.ccLights;\nfor (uint i = 0u; i < 100u; i++) {\nif (i >= numLights) break;\nuint lightIndex = getGridLightIndex(grid.offset, i);\nCCLight light = getCCLight(lightIndex);\nvec3 SLU = light.cc_lightPos.xyz - position;\nvec3 SL = normalize(SLU);\nvec3 SH = normalize(SL + V);\nfloat SNL = max(dot(N, SL), 0.001);\nfloat SNH = max(dot(N, SH), 0.0);\nfloat distSqr = dot(SLU, SLU);\nfloat litRadius = light.cc_lightSizeRangeAngle.x;\nfloat litRadiusSqr = litRadius * litRadius;\nfloat illum = PI * (litRadiusSqr / max(litRadiusSqr , distSqr));\nfloat attRadiusSqrInv = 1.0 / max(light.cc_lightSizeRangeAngle.y, 0.01);\nattRadiusSqrInv *= attRadiusSqrInv;\nfloat att = GetDistAtt(distSqr, attRadiusSqrInv);\nvec3 lspec = specular * CalcSpecular(s.roughness, SNH, SH, N);\nif (light.cc_lightPos.w > 0.0) {\nfloat cosInner = max(dot(-light.cc_lightDir.xyz, SL), 0.01);\nfloat cosOuter = light.cc_lightSizeRangeAngle.z;\nfloat litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\nfloat litAngleOffset = -cosOuter * litAngleScale;\natt *= GetAngleAtt(SL, -light.cc_lightDir.xyz, litAngleScale, litAngleOffset);\n}\nvec3 lightColor = light.cc_lightColor.rgb;\nfloat shadow = 1.0;\n#if CC_RECEIVE_SHADOW\nif (light.cc_lightPos.w > 0.0) {\nshadow = CCSpotShadowFactorBase(shadowPos, position, s.shadowBias);\n}\n#endif\nlightColor *= shadow;\nfinalColor += SNL * lightColor * light.cc_lightColor.w * illum * att * (diffuseContrib + lspec);\n}\nreturn vec4(finalColor, 0.0);\n}\n#endif\nvec3 ACESToneMap (vec3 color) {\ncolor = min(color, vec3(8.0));\nconst float A = 2.51;\nconst float B = 0.03;\nconst float C = 2.43;\nconst float D = 0.59;\nconst float E = 0.14;\nreturn (color * (A * color + B)) / (color * (C * color + D) + E);\n}\nvec4 CCFragOutput (vec4 color) {\n#if CC_USE_HDR\ncolor.rgb = ACESToneMap(color.rgb);\n#endif\ncolor.rgb = sqrt(color.rgb);\nreturn color;\n}\nfloat LinearFog(vec4 pos) {\nvec4 wPos = pos;\nfloat cam_dis = distance(cc_cameraPos, wPos);\nfloat fogStart = cc_fogBase.x;\nfloat fogEnd = cc_fogBase.y;\nreturn clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * fogDensity);\nreturn f;\n}\nfloat ExpSquaredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\nreturn f;\n}\nfloat LayeredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat _FogTop = cc_fogAdd.x;\nfloat _FogRange = cc_fogAdd.y;\nvec3 camWorldProj = cc_cameraPos.xyz;\ncamWorldProj.y = 0.;\nvec3 worldPosProj = wPos.xyz;\nworldPosProj.y = 0.;\nfloat fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\nfloat fDeltaY, fDensityIntegral;\nif (cc_cameraPos.y > _FogTop) {\nif (wPos.y < _FogTop) {\nfDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\nfDensityIntegral = fDeltaY * fDeltaY * 0.5;\n} else {\nfDeltaY = 0.;\nfDensityIntegral = 0.;\n}\n} else {\nif (wPos.y < _FogTop) {\nfloat fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfloat fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\nfDeltaY = abs(fDeltaA - fDeltaB);\nfDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n} else {\nfDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n}\n}\nfloat fDensity;\nif (fDeltaY != 0.) {\nfDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n} else {\nfDensity = 0.;\n}\nfloat f = exp(-fDensity);\nreturn f;\n}\nvoid CC_TRANSFER_FOG_BASE(vec4 pos, out float factor)\n{\n#if CC_USE_FOG == 0\nfactor = LinearFog(pos);\n#elif CC_USE_FOG == 1\nfactor = ExpFog(pos);\n#elif CC_USE_FOG == 2\nfactor = ExpSquaredFog(pos);\n#elif CC_USE_FOG == 3\nfactor = LayeredFog(pos);\n#else\nfactor = 1.0;\n#endif\n}\nvoid CC_APPLY_FOG_BASE(inout vec4 color, float factor) {\ncolor = vec4(mix(cc_fogColor.rgb, color.rgb, factor), color.a);\n}\nvec2 signNotZero(vec2 v) {\nreturn vec2((v.x >= 0.0) ? +1.0 : -1.0, (v.y >= 0.0) ? +1.0 : -1.0);\n}\nvec3 oct_to_float32x3(vec2 e) {\nvec3 v = vec3(e.xy, 1.0 - abs(e.x) - abs(e.y));\nif (v.z < 0.0) v.xy = (1.0 - abs(v.yx)) * signNotZero(v.xy);\nreturn normalize(v);\n}\nfloat getCameraDepthRH(float ndcDepth, mat4 matProj)\n{\nreturn -matProj[3][2] / (ndcDepth + matProj[2][2]);\n}\nvec4 screen2WS(vec3 coord) {\nvec3 ndc = vec3(\n2.0 * (coord.x - cc_viewPort.x) / cc_viewPort.z - 1.0,\n2.0 * (coord.y - cc_viewPort.y) / cc_viewPort.w - 1.0,\n2.0 * coord.z - 1.0);\nfloat w = -getCameraDepthRH(ndc.z, cc_matProj);\nvec4 world = (cc_matViewProjInv * vec4(ndc * w, w));\nreturn world;\n}\nin vec2 v_uv;\n#if CC_DEVICE_CAN_BENEFIT_FROM_INPUT_ATTACHMENT\nlayout(location = 0) inout vec4 gbuffer_albedoMap;\nlayout(location = 1) inout vec4 gbuffer_normalMap;\nlayout(location = 2) inout vec4 gbuffer_emissiveMap;\nuniform sampler2D depth_stencil;\n#else\nuniform sampler2D gbuffer_albedoMap;\nuniform sampler2D gbuffer_normalMap;\nuniform sampler2D gbuffer_emissiveMap;\nuniform sampler2D depth_stencil;\n#endif\n#if !CC_DEVICE_CAN_BENEFIT_FROM_INPUT_ATTACHMENT || __VERSION__ >= 450\nlayout(location = 0) out vec4 fragColor;\n#endif\nvoid main () {\nStandardSurface s;\n#if CC_DEVICE_CAN_BENEFIT_FROM_INPUT_ATTACHMENT\nvec4 albedoMap = gbuffer_albedoMap;\nvec4 normalMap = gbuffer_normalMap;\nvec4 emissiveMap = gbuffer_emissiveMap;\nfloat depth = texture(depth_stencil, v_uv).x;\n#else\nvec4 albedoMap = texture(gbuffer_albedoMap,v_uv);\nvec4 normalMap = texture(gbuffer_normalMap,v_uv);\nvec4 emissiveMap = texture(gbuffer_emissiveMap,v_uv);\nfloat depth = texture(depth_stencil, v_uv).x;\n#endif\ns.albedo = albedoMap;\nvec3 position = screen2WS(vec3(gl_FragCoord.xy, depth)).xyz;\ns.position = position;\ns.roughness = normalMap.z;\ns.normal = oct_to_float32x3(normalMap.xy);\ns.specularIntensity = 0.5;\ns.metallic = normalMap.w;\ns.emissive = emissiveMap.xyz;\ns.occlusion = emissiveMap.w;\nfloat fogFactor;\nCC_TRANSFER_FOG_BASE(vec4(position, 1), fogFactor);\nvec4 shadowPos;\nshadowPos = cc_matLightViewProj * vec4(position, 1);\nvec4 color = CCStandardShadingBase(s, shadowPos) +\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 1\nCCClusterShadingAdditive(s, shadowPos);\n#else\nCCStandardShadingAdditive(s, shadowPos);\n#endif\nCC_APPLY_FOG_BASE(color, fogFactor);\ncolor = CCFragOutput(color);\n#if CC_DEVICE_CAN_BENEFIT_FROM_INPUT_ATTACHMENT\ngbuffer_emissiveMap = color;\n#else\nfragColor = color;\n#endif\n}", } ], [ { - "vert": "\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\nrgba = rgba * 255.0;\nhighp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\nhighp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\nhighp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\nreturn Sign * exp2(Exponent - 23.0) * Mantissa;\n}\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nin vec3 a_position;\nin vec3 a_normal;\nin vec2 a_texCoord;\nin vec4 a_tangent;\n#if CC_USE_SKINNING\nin vec4 a_joints;\nin vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nin highp vec4 a_jointAnimInfo;\n#endif\nin vec4 a_matWorld0;\nin vec4 a_matWorld1;\nin vec4 a_matWorld2;\n#if USE_LIGHTMAP\nin vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nin vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nin float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nin float a_vertexId;\nint getVertexId() {\nreturn int(a_vertexId);\n}\n#endif\n#if CC_USE_MORPH\nlayout(std140) uniform CCMorph {\nvec4 cc_displacementWeights[15];\nvec4 cc_displacementTextureInfo;\n};\nvec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\nfloat pixelIndexF = float(pixelIndex);\nfloat x = mod(pixelIndexF, textureResolution.x);\nfloat y = floor(pixelIndexF / textureResolution.x);\nreturn vec2(x, y);\n}\nvec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\nreturn (vec2(location.x, location.y) + .5) / textureResolution;\n}\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int pixelIndex) {\nivec2 texSize = textureSize(tex, 0);\nreturn texelFetch(tex, ivec2(pixelIndex % texSize.x, pixelIndex / texSize.x), 0);\n}\n#else\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex * 4;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\nreturn vec4(\ndecode32(texture(tex, x)),\ndecode32(texture(tex, y)),\ndecode32(texture(tex, z)),\n1.0\n);\n}\n#endif\nfloat getDisplacementWeight(int index) {\nint quot = index / 4;\nint remainder = index - quot * 4;\nif (remainder == 0) {\nreturn cc_displacementWeights[quot].x;\n} else if (remainder == 1) {\nreturn cc_displacementWeights[quot].y;\n} else if (remainder == 2) {\nreturn cc_displacementWeights[quot].z;\n} else {\nreturn cc_displacementWeights[quot].w;\n}\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\nreturn fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n#else\nvec3 result = vec3(0, 0, 0);\nint nVertices = int(cc_displacementTextureInfo.z);\nfor (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\nresult += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n}\nreturn result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\nuniform sampler2D cc_PositionDisplacements;\nvec3 getPositionDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nuniform sampler2D cc_NormalDisplacements;\nvec3 getNormalDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\nuniform sampler2D cc_TangentDisplacements;\nvec3 getTangentDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n}\n#endif\nvoid applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nint vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nnormal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\ntangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\n#if CC_USE_BAKED_ANIMATION\nlayout(std140) uniform CCSkinningTexture {\nhighp vec4 cc_jointTextureInfo;\n};\nlayout(std140) uniform CCSkinningAnimation {\nhighp vec4 cc_jointAnimInfo;\n};\nuniform highp sampler2D cc_jointTexture;\nvoid CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n{\n#if USE_INSTANCING\nhighp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n#else\nhighp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n#endif\ninvSize = cc_jointTextureInfo.w;\nhighp float tempY = floor(temp * invSize);\nx = floor(temp - tempY * cc_jointTextureInfo.x);\ny = (tempY + 0.5) * invSize;\n}\n#else\nlayout(std140) uniform CCSkinning {\nhighp vec4 cc_joints[30 * 3];\n};\n#endif\n#if CC_USE_BAKED_ANIMATION\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(3.0, i, x, y, invSize);\nvec4 v1 = texture(cc_jointTexture, vec2((x + 0.5) * invSize, y));\nvec4 v2 = texture(cc_jointTexture, vec2((x + 1.5) * invSize, y));\nvec4 v3 = texture(cc_jointTexture, vec2((x + 2.5) * invSize, y));\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#else\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(12.0, i, x, y, invSize);\nvec4 v1 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n);\nvec4 v2 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n);\nvec4 v3 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n);\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\n#else\nmat4 getJointMatrix (float i) {\nint idx = int(i);\nvec4 v1 = cc_joints[idx * 3];\nvec4 v2 = cc_joints[idx * 3 + 1];\nvec4 v3 = cc_joints[idx * 3 + 2];\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\nmat4 skinMatrix () {\nvec4 joints = vec4(a_joints);\nreturn getJointMatrix(joints.x) * a_weights.x\n+ getJointMatrix(joints.y) * a_weights.y\n+ getJointMatrix(joints.z) * a_weights.z\n+ getJointMatrix(joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\nmat4 m = skinMatrix();\nposition = m * position;\n}\nvoid CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nmat4 m = skinMatrix();\nposition = m * position;\nnormal = (m * vec4(normal, 0.0)).xyz;\ntangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n}\n#endif\nvoid CCVertInput(inout vec4 In)\n{\nIn = vec4(a_position, 1.0);\n#if CC_USE_MORPH\napplyMorph(In);\n#endif\n#if CC_USE_SKINNING\nCCSkin(In);\n#endif\n}\nlayout(std140) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(std140) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\n#if !USE_INSTANCING\n#if USE_BATCHING\nlayout(std140) uniform CCLocalBatched {\nhighp mat4 cc_matWorlds[10];\n};\n#else\nlayout(std140) uniform CCLocal {\nhighp mat4 cc_matWorld;\nhighp mat4 cc_matWorldIT;\nhighp vec4 cc_lightingMapUVParam;\nhighp vec4 cc_localShadowBias;\n};\n#endif\n#endif\nvoid CCGetWorldMatrix(out mat4 matWorld)\n{\n#if USE_INSTANCING\nmatWorld = mat4(\nvec4(a_matWorld0.xyz, 0.0),\nvec4(a_matWorld1.xyz, 0.0),\nvec4(a_matWorld2.xyz, 0.0),\nvec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)\n);\n#elif USE_BATCHING\nmatWorld = cc_matWorlds[int(a_dyn_batch_id)];\n#else\nmatWorld = cc_matWorld;\n#endif\n}\nlayout(std140) uniform CCShadow {\nhighp mat4 cc_matLightPlaneProj;\nhighp mat4 cc_matLightView;\nhighp mat4 cc_matLightViewProj;\nhighp vec4 cc_shadowInvProjDepthInfo;\nhighp vec4 cc_shadowProjDepthInfo;\nhighp vec4 cc_shadowProjInfo;\nmediump vec4 cc_shadowNFLSInfo;\nmediump vec4 cc_shadowWHPBInfo;\nmediump vec4 cc_shadowLPNNInfo;\nlowp vec4 cc_shadowColor;\nmediump vec4 cc_planarNDInfo;\n};\nout float v_dist;\nvec4 vert () {\nvec4 position;\nCCVertInput(position);\nmat4 matWorld;\nCCGetWorldMatrix(matWorld);\nvec3 P = (matWorld * position).xyz;\nvec3 L = cc_mainLitDir.xyz;\nvec3 N = cc_planarNDInfo.xyz;\nfloat d = cc_planarNDInfo.w + 0.001;\nfloat dist = (-d - dot(P, N)) / (dot(L, N) + 0.0001);\nvec3 shadowPos = P + L * dist;\nvec3 view = normalize(cc_cameraPos.xyz - shadowPos);\nfloat viewLength = length(cc_cameraPos.xyz - shadowPos);\nshadowPos += view * min(1.0, 0.005 * viewLength);\nposition = cc_matProj * cc_matView * vec4(shadowPos, 1.0);\nv_dist = dist;\nreturn position;\n}\nvoid main() { gl_Position = vert(); }", + "vert": "\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\nrgba = rgba * 255.0;\nhighp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\nhighp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\nhighp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\nreturn Sign * exp2(Exponent - 23.0) * Mantissa;\n}\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nin vec3 a_position;\nin vec3 a_normal;\nin vec2 a_texCoord;\nin vec4 a_tangent;\n#if CC_USE_SKINNING\nin vec4 a_joints;\nin vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nin highp vec4 a_jointAnimInfo;\n#endif\nin vec4 a_matWorld0;\nin vec4 a_matWorld1;\nin vec4 a_matWorld2;\n#if CC_USE_LIGHTMAP\nin vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nin vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nin float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nin float a_vertexId;\nint getVertexId() {\nreturn int(a_vertexId);\n}\n#endif\n#if CC_USE_MORPH\nlayout(std140) uniform CCMorph {\nvec4 cc_displacementWeights[15];\nvec4 cc_displacementTextureInfo;\n};\nvec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\nfloat pixelIndexF = float(pixelIndex);\nfloat x = mod(pixelIndexF, textureResolution.x);\nfloat y = floor(pixelIndexF / textureResolution.x);\nreturn vec2(x, y);\n}\nvec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\nreturn (vec2(location.x, location.y) + .5) / textureResolution;\n}\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int pixelIndex) {\nivec2 texSize = textureSize(tex, 0);\nreturn texelFetch(tex, ivec2(pixelIndex % texSize.x, pixelIndex / texSize.x), 0);\n}\n#else\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex * 4;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\nreturn vec4(\ndecode32(texture(tex, x)),\ndecode32(texture(tex, y)),\ndecode32(texture(tex, z)),\n1.0\n);\n}\n#endif\nfloat getDisplacementWeight(int index) {\nint quot = index / 4;\nint remainder = index - quot * 4;\nif (remainder == 0) {\nreturn cc_displacementWeights[quot].x;\n} else if (remainder == 1) {\nreturn cc_displacementWeights[quot].y;\n} else if (remainder == 2) {\nreturn cc_displacementWeights[quot].z;\n} else {\nreturn cc_displacementWeights[quot].w;\n}\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\nreturn fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n#else\nvec3 result = vec3(0, 0, 0);\nint nVertices = int(cc_displacementTextureInfo.z);\nfor (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\nresult += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n}\nreturn result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\nuniform sampler2D cc_PositionDisplacements;\nvec3 getPositionDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nuniform sampler2D cc_NormalDisplacements;\nvec3 getNormalDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\nuniform sampler2D cc_TangentDisplacements;\nvec3 getTangentDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n}\n#endif\nvoid applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nint vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nnormal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\ntangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\n#if CC_USE_BAKED_ANIMATION\nlayout(std140) uniform CCSkinningTexture {\nhighp vec4 cc_jointTextureInfo;\n};\nlayout(std140) uniform CCSkinningAnimation {\nhighp vec4 cc_jointAnimInfo;\n};\nuniform highp sampler2D cc_jointTexture;\nvoid CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n{\n#if USE_INSTANCING\nhighp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n#else\nhighp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n#endif\ninvSize = cc_jointTextureInfo.w;\nhighp float tempY = floor(temp * invSize);\nx = floor(temp - tempY * cc_jointTextureInfo.x);\ny = (tempY + 0.5) * invSize;\n}\n#else\nlayout(std140) uniform CCSkinning {\nhighp vec4 cc_joints[30 * 3];\n};\n#endif\n#if CC_USE_BAKED_ANIMATION\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(3.0, i, x, y, invSize);\nvec4 v1 = texture(cc_jointTexture, vec2((x + 0.5) * invSize, y));\nvec4 v2 = texture(cc_jointTexture, vec2((x + 1.5) * invSize, y));\nvec4 v3 = texture(cc_jointTexture, vec2((x + 2.5) * invSize, y));\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#else\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(12.0, i, x, y, invSize);\nvec4 v1 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n);\nvec4 v2 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n);\nvec4 v3 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n);\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\n#else\nmat4 getJointMatrix (float i) {\nint idx = int(i);\nvec4 v1 = cc_joints[idx * 3];\nvec4 v2 = cc_joints[idx * 3 + 1];\nvec4 v3 = cc_joints[idx * 3 + 2];\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\nmat4 skinMatrix () {\nvec4 joints = vec4(a_joints);\nreturn getJointMatrix(joints.x) * a_weights.x\n+ getJointMatrix(joints.y) * a_weights.y\n+ getJointMatrix(joints.z) * a_weights.z\n+ getJointMatrix(joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\nmat4 m = skinMatrix();\nposition = m * position;\n}\nvoid CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nmat4 m = skinMatrix();\nposition = m * position;\nnormal = (m * vec4(normal, 0.0)).xyz;\ntangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n}\n#endif\nvoid CCVertInput(inout vec4 In)\n{\nIn = vec4(a_position, 1.0);\n#if CC_USE_MORPH\napplyMorph(In);\n#endif\n#if CC_USE_SKINNING\nCCSkin(In);\n#endif\n}\nlayout(std140) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(std140) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\n#if !USE_INSTANCING\n#if USE_BATCHING\nlayout(std140) uniform CCLocalBatched {\nhighp mat4 cc_matWorlds[10];\n};\n#else\nlayout(std140) uniform CCLocal {\nhighp mat4 cc_matWorld;\nhighp mat4 cc_matWorldIT;\nhighp vec4 cc_lightingMapUVParam;\nhighp vec4 cc_localShadowBias;\n};\n#endif\n#endif\nvoid CCGetWorldMatrix(out mat4 matWorld)\n{\n#if USE_INSTANCING\nmatWorld = mat4(\nvec4(a_matWorld0.xyz, 0.0),\nvec4(a_matWorld1.xyz, 0.0),\nvec4(a_matWorld2.xyz, 0.0),\nvec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)\n);\n#elif USE_BATCHING\nmatWorld = cc_matWorlds[int(a_dyn_batch_id)];\n#else\nmatWorld = cc_matWorld;\n#endif\n}\nlayout(std140) uniform CCShadow {\nhighp mat4 cc_matLightPlaneProj;\nhighp mat4 cc_matLightView;\nhighp mat4 cc_matLightViewProj;\nhighp vec4 cc_shadowInvProjDepthInfo;\nhighp vec4 cc_shadowProjDepthInfo;\nhighp vec4 cc_shadowProjInfo;\nmediump vec4 cc_shadowNFLSInfo;\nmediump vec4 cc_shadowWHPBInfo;\nmediump vec4 cc_shadowLPNNInfo;\nlowp vec4 cc_shadowColor;\nmediump vec4 cc_planarNDInfo;\n};\nout float v_dist;\nvec4 vert () {\nvec4 position;\nCCVertInput(position);\nmat4 matWorld;\nCCGetWorldMatrix(matWorld);\nvec3 P = (matWorld * position).xyz;\nvec3 L = cc_mainLitDir.xyz;\nvec3 N = cc_planarNDInfo.xyz;\nfloat d = cc_planarNDInfo.w + 0.001;\nfloat dist = (-d - dot(P, N)) / (dot(L, N) + 0.0001);\nvec3 shadowPos = P + L * dist;\nvec3 view = normalize(cc_cameraPos.xyz - shadowPos);\nfloat viewLength = length(cc_cameraPos.xyz - shadowPos);\nshadowPos += view * min(1.0, 0.005 * viewLength);\nposition = cc_matProj * cc_matView * vec4(shadowPos, 1.0);\nv_dist = dist;\nreturn position;\n}\nvoid main() { gl_Position = vert(); }", "frag": "\nprecision mediump float;\nlayout(std140) uniform CCShadow {\nhighp mat4 cc_matLightPlaneProj;\nhighp mat4 cc_matLightView;\nhighp mat4 cc_matLightViewProj;\nhighp vec4 cc_shadowInvProjDepthInfo;\nhighp vec4 cc_shadowProjDepthInfo;\nhighp vec4 cc_shadowProjInfo;\nmediump vec4 cc_shadowNFLSInfo;\nmediump vec4 cc_shadowWHPBInfo;\nmediump vec4 cc_shadowLPNNInfo;\nlowp vec4 cc_shadowColor;\nmediump vec4 cc_planarNDInfo;\n};\nlayout(std140) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(std140) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\nvec4 CCFragOutput (vec4 color) {\nreturn color;\n}\nin float v_dist;\nvec4 frag () {\nif(v_dist < 0.0)\ndiscard;\nreturn CCFragOutput(cc_shadowColor);\n}\nlayout(location = 0) out vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }", } ], [ { - "vert": "\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\nrgba = rgba * 255.0;\nhighp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\nhighp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\nhighp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\nreturn Sign * exp2(Exponent - 23.0) * Mantissa;\n}\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nin vec3 a_position;\nin vec3 a_normal;\nin vec2 a_texCoord;\nin vec4 a_tangent;\n#if CC_USE_SKINNING\nin vec4 a_joints;\nin vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nin highp vec4 a_jointAnimInfo;\n#endif\nin vec4 a_matWorld0;\nin vec4 a_matWorld1;\nin vec4 a_matWorld2;\n#if USE_LIGHTMAP\nin vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nin vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nin float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nin float a_vertexId;\nint getVertexId() {\nreturn int(a_vertexId);\n}\n#endif\n#if CC_USE_MORPH\nlayout(std140) uniform CCMorph {\nvec4 cc_displacementWeights[15];\nvec4 cc_displacementTextureInfo;\n};\nvec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\nfloat pixelIndexF = float(pixelIndex);\nfloat x = mod(pixelIndexF, textureResolution.x);\nfloat y = floor(pixelIndexF / textureResolution.x);\nreturn vec2(x, y);\n}\nvec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\nreturn (vec2(location.x, location.y) + .5) / textureResolution;\n}\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int pixelIndex) {\nivec2 texSize = textureSize(tex, 0);\nreturn texelFetch(tex, ivec2(pixelIndex % texSize.x, pixelIndex / texSize.x), 0);\n}\n#else\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex * 4;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\nreturn vec4(\ndecode32(texture(tex, x)),\ndecode32(texture(tex, y)),\ndecode32(texture(tex, z)),\n1.0\n);\n}\n#endif\nfloat getDisplacementWeight(int index) {\nint quot = index / 4;\nint remainder = index - quot * 4;\nif (remainder == 0) {\nreturn cc_displacementWeights[quot].x;\n} else if (remainder == 1) {\nreturn cc_displacementWeights[quot].y;\n} else if (remainder == 2) {\nreturn cc_displacementWeights[quot].z;\n} else {\nreturn cc_displacementWeights[quot].w;\n}\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\nreturn fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n#else\nvec3 result = vec3(0, 0, 0);\nint nVertices = int(cc_displacementTextureInfo.z);\nfor (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\nresult += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n}\nreturn result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\nuniform sampler2D cc_PositionDisplacements;\nvec3 getPositionDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nuniform sampler2D cc_NormalDisplacements;\nvec3 getNormalDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\nuniform sampler2D cc_TangentDisplacements;\nvec3 getTangentDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n}\n#endif\nvoid applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nint vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nnormal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\ntangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\n#if CC_USE_BAKED_ANIMATION\nlayout(std140) uniform CCSkinningTexture {\nhighp vec4 cc_jointTextureInfo;\n};\nlayout(std140) uniform CCSkinningAnimation {\nhighp vec4 cc_jointAnimInfo;\n};\nuniform highp sampler2D cc_jointTexture;\nvoid CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n{\n#if USE_INSTANCING\nhighp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n#else\nhighp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n#endif\ninvSize = cc_jointTextureInfo.w;\nhighp float tempY = floor(temp * invSize);\nx = floor(temp - tempY * cc_jointTextureInfo.x);\ny = (tempY + 0.5) * invSize;\n}\n#else\nlayout(std140) uniform CCSkinning {\nhighp vec4 cc_joints[30 * 3];\n};\n#endif\n#if CC_USE_BAKED_ANIMATION\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(3.0, i, x, y, invSize);\nvec4 v1 = texture(cc_jointTexture, vec2((x + 0.5) * invSize, y));\nvec4 v2 = texture(cc_jointTexture, vec2((x + 1.5) * invSize, y));\nvec4 v3 = texture(cc_jointTexture, vec2((x + 2.5) * invSize, y));\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#else\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(12.0, i, x, y, invSize);\nvec4 v1 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n);\nvec4 v2 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n);\nvec4 v3 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n);\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\n#else\nmat4 getJointMatrix (float i) {\nint idx = int(i);\nvec4 v1 = cc_joints[idx * 3];\nvec4 v2 = cc_joints[idx * 3 + 1];\nvec4 v3 = cc_joints[idx * 3 + 2];\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\nmat4 skinMatrix () {\nvec4 joints = vec4(a_joints);\nreturn getJointMatrix(joints.x) * a_weights.x\n+ getJointMatrix(joints.y) * a_weights.y\n+ getJointMatrix(joints.z) * a_weights.z\n+ getJointMatrix(joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\nmat4 m = skinMatrix();\nposition = m * position;\n}\nvoid CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nmat4 m = skinMatrix();\nposition = m * position;\nnormal = (m * vec4(normal, 0.0)).xyz;\ntangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n}\n#endif\nvoid CCVertInput(inout StandardVertInput In)\n{\nIn.position = vec4(a_position, 1.0);\nIn.normal = a_normal;\nIn.tangent = a_tangent;\n#if CC_USE_MORPH\napplyMorph(In.position, In.normal, In.tangent);\n#endif\n#if CC_USE_SKINNING\nCCSkin(In.position, In.normal, In.tangent);\n#endif\n}\nlayout(std140) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(std140) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\nout vec2 v_uv;\nvoid main () {\nStandardVertInput In;\nCCVertInput(In);\nIn.position.xy = cc_cameraPos.w == 0.0 ? vec2(In.position.xy.x, -In.position.xy.y) : In.position.xy;\ngl_Position = In.position;\ngl_Position.y = gl_Position.y;\nv_uv = a_texCoord;\n}", + "vert": "\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\nrgba = rgba * 255.0;\nhighp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\nhighp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\nhighp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\nreturn Sign * exp2(Exponent - 23.0) * Mantissa;\n}\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nin vec3 a_position;\nin vec3 a_normal;\nin vec2 a_texCoord;\nin vec4 a_tangent;\n#if CC_USE_SKINNING\nin vec4 a_joints;\nin vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nin highp vec4 a_jointAnimInfo;\n#endif\nin vec4 a_matWorld0;\nin vec4 a_matWorld1;\nin vec4 a_matWorld2;\n#if CC_USE_LIGHTMAP\nin vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nin vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nin float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nin float a_vertexId;\nint getVertexId() {\nreturn int(a_vertexId);\n}\n#endif\n#if CC_USE_MORPH\nlayout(std140) uniform CCMorph {\nvec4 cc_displacementWeights[15];\nvec4 cc_displacementTextureInfo;\n};\nvec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\nfloat pixelIndexF = float(pixelIndex);\nfloat x = mod(pixelIndexF, textureResolution.x);\nfloat y = floor(pixelIndexF / textureResolution.x);\nreturn vec2(x, y);\n}\nvec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\nreturn (vec2(location.x, location.y) + .5) / textureResolution;\n}\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int pixelIndex) {\nivec2 texSize = textureSize(tex, 0);\nreturn texelFetch(tex, ivec2(pixelIndex % texSize.x, pixelIndex / texSize.x), 0);\n}\n#else\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex * 4;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\nreturn vec4(\ndecode32(texture(tex, x)),\ndecode32(texture(tex, y)),\ndecode32(texture(tex, z)),\n1.0\n);\n}\n#endif\nfloat getDisplacementWeight(int index) {\nint quot = index / 4;\nint remainder = index - quot * 4;\nif (remainder == 0) {\nreturn cc_displacementWeights[quot].x;\n} else if (remainder == 1) {\nreturn cc_displacementWeights[quot].y;\n} else if (remainder == 2) {\nreturn cc_displacementWeights[quot].z;\n} else {\nreturn cc_displacementWeights[quot].w;\n}\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\nreturn fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n#else\nvec3 result = vec3(0, 0, 0);\nint nVertices = int(cc_displacementTextureInfo.z);\nfor (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\nresult += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n}\nreturn result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\nuniform sampler2D cc_PositionDisplacements;\nvec3 getPositionDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nuniform sampler2D cc_NormalDisplacements;\nvec3 getNormalDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\nuniform sampler2D cc_TangentDisplacements;\nvec3 getTangentDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n}\n#endif\nvoid applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nint vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nnormal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\ntangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\n#if CC_USE_BAKED_ANIMATION\nlayout(std140) uniform CCSkinningTexture {\nhighp vec4 cc_jointTextureInfo;\n};\nlayout(std140) uniform CCSkinningAnimation {\nhighp vec4 cc_jointAnimInfo;\n};\nuniform highp sampler2D cc_jointTexture;\nvoid CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n{\n#if USE_INSTANCING\nhighp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n#else\nhighp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n#endif\ninvSize = cc_jointTextureInfo.w;\nhighp float tempY = floor(temp * invSize);\nx = floor(temp - tempY * cc_jointTextureInfo.x);\ny = (tempY + 0.5) * invSize;\n}\n#else\nlayout(std140) uniform CCSkinning {\nhighp vec4 cc_joints[30 * 3];\n};\n#endif\n#if CC_USE_BAKED_ANIMATION\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(3.0, i, x, y, invSize);\nvec4 v1 = texture(cc_jointTexture, vec2((x + 0.5) * invSize, y));\nvec4 v2 = texture(cc_jointTexture, vec2((x + 1.5) * invSize, y));\nvec4 v3 = texture(cc_jointTexture, vec2((x + 2.5) * invSize, y));\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#else\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(12.0, i, x, y, invSize);\nvec4 v1 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n);\nvec4 v2 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n);\nvec4 v3 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n);\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\n#else\nmat4 getJointMatrix (float i) {\nint idx = int(i);\nvec4 v1 = cc_joints[idx * 3];\nvec4 v2 = cc_joints[idx * 3 + 1];\nvec4 v3 = cc_joints[idx * 3 + 2];\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\nmat4 skinMatrix () {\nvec4 joints = vec4(a_joints);\nreturn getJointMatrix(joints.x) * a_weights.x\n+ getJointMatrix(joints.y) * a_weights.y\n+ getJointMatrix(joints.z) * a_weights.z\n+ getJointMatrix(joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\nmat4 m = skinMatrix();\nposition = m * position;\n}\nvoid CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nmat4 m = skinMatrix();\nposition = m * position;\nnormal = (m * vec4(normal, 0.0)).xyz;\ntangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n}\n#endif\nvoid CCVertInput(inout StandardVertInput In)\n{\nIn.position = vec4(a_position, 1.0);\nIn.normal = a_normal;\nIn.tangent = a_tangent;\n#if CC_USE_MORPH\napplyMorph(In.position, In.normal, In.tangent);\n#endif\n#if CC_USE_SKINNING\nCCSkin(In.position, In.normal, In.tangent);\n#endif\n}\nlayout(std140) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(std140) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\nout vec2 v_uv;\nvoid main () {\nStandardVertInput In;\nCCVertInput(In);\nIn.position.xy = cc_cameraPos.w == 0.0 ? vec2(In.position.xy.x, -In.position.xy.y) : In.position.xy;\ngl_Position = In.position;\ngl_Position.y = gl_Position.y;\nv_uv = a_texCoord;\n}", "frag": "\nprecision highp float;\nlayout(std140) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(std140) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\n#if ANTIALIAS_TYPE == 1\nvec4 fxaa(sampler2D tex, vec2 fragCoord, vec2 resolution,\nvec2 v_rgbNW, vec2 v_rgbNE,\nvec2 v_rgbSW, vec2 v_rgbSE,\nvec2 v_rgbM) {\nvec4 color;\nmediump vec2 inverseVP = vec2(1.0 / resolution.x, 1.0 / resolution.y);\nvec3 rgbNW = texture(tex, v_rgbNW).xyz;\nvec3 rgbNE = texture(tex, v_rgbNE).xyz;\nvec3 rgbSW = texture(tex, v_rgbSW).xyz;\nvec3 rgbSE = texture(tex, v_rgbSE).xyz;\nvec4 texColor = texture(tex, v_rgbM);\nvec3 rgbM = texColor.xyz;\nvec3 luma = vec3(0.299, 0.587, 0.114);\nfloat lumaNW = dot(rgbNW, luma);\nfloat lumaNE = dot(rgbNE, luma);\nfloat lumaSW = dot(rgbSW, luma);\nfloat lumaSE = dot(rgbSE, luma);\nfloat lumaM = dot(rgbM, luma);\nfloat lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));\nfloat lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));\nmediump vec2 dir;\ndir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));\ndir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));\nfloat dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) *\n(0.25 * (1.0 / 8.0)), (1.0/ 128.0));\nfloat rcpDirMin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce);\ndir = min(vec2(8.0, 8.0),\nmax(vec2(-8.0, -8.0),\ndir * rcpDirMin)) * inverseVP;\nvec3 rgbA = 0.5 * (\ntexture(tex, fragCoord * inverseVP + dir * (1.0 / 3.0 - 0.5)).xyz +\ntexture(tex, fragCoord * inverseVP + dir * (2.0 / 3.0 - 0.5)).xyz);\nvec3 rgbB = rgbA * 0.5 + 0.25 * (\ntexture(tex, fragCoord * inverseVP + dir * -0.5).xyz +\ntexture(tex, fragCoord * inverseVP + dir * 0.5).xyz);\nfloat lumaB = dot(rgbB, luma);\nif ((lumaB < lumaMin) || (lumaB > lumaMax))\ncolor = vec4(rgbA, texColor.a);\nelse\ncolor = vec4(rgbB, texColor.a);\nreturn color;\n}\n#endif\nin vec2 v_uv;\nuniform sampler2D outputResultMap;\nlayout(location = 0) out vec4 fragColor;\nvoid texcoords(vec2 fragCoord, vec2 resolution,\nout vec2 v_rgbNW, out vec2 v_rgbNE,\nout vec2 v_rgbSW, out vec2 v_rgbSE,\nout vec2 v_rgbM) {\nvec2 inverseVP = 1.0 / resolution.xy;\nv_rgbNW = (fragCoord + vec2(-1.0, -1.0)) * inverseVP;\nv_rgbNE = (fragCoord + vec2(1.0, -1.0)) * inverseVP;\nv_rgbSW = (fragCoord + vec2(-1.0, 1.0)) * inverseVP;\nv_rgbSE = (fragCoord + vec2(1.0, 1.0)) * inverseVP;\nv_rgbM = vec2(fragCoord * inverseVP);\n}\nvoid main () {\nmediump vec2 v_rgbNW;\nmediump vec2 v_rgbNE;\nmediump vec2 v_rgbSW;\nmediump vec2 v_rgbSE;\nmediump vec2 v_rgbM;\n#if ANTIALIAS_TYPE == 1\nvec2 resolution = cc_screenSize.xy;\nvec2 fragCoord = v_uv * resolution;\ntexcoords(fragCoord, resolution, v_rgbNW, v_rgbNE, v_rgbSW, v_rgbSE, v_rgbM);\nfragColor = fxaa(outputResultMap, fragCoord, resolution, v_rgbNW, v_rgbNE, v_rgbSW, v_rgbSE, v_rgbM);\n#else\nfragColor = texture(outputResultMap, v_uv);\n#endif\n}", } ], [ { - "vert": "\nprecision highp float;\nlayout(std140) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(std140) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nin vec3 a_position;\nin vec3 a_normal;\nin vec2 a_texCoord;\nin vec4 a_tangent;\n#if CC_USE_SKINNING\nin vec4 a_joints;\nin vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nin highp vec4 a_jointAnimInfo;\n#endif\nin vec4 a_matWorld0;\nin vec4 a_matWorld1;\nin vec4 a_matWorld2;\n#if USE_LIGHTMAP\nin vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nin vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nin float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nin float a_vertexId;\n#endif\nout mediump vec4 viewDir;\nvec4 vert () {\nviewDir = vec4(a_position, 1.0);\nmat4 matViewRotOnly = mat4(mat3(cc_matView));\nvec4 pos = matViewRotOnly * viewDir;\nif (cc_matProj[3].w > 0.0) {\nmat4 matProj = cc_matProj;\nmatProj[0].x = 5.2;\nmatProj[1].y = 2.6;\nmatProj[2].zw = vec2(-1.0);\nmatProj[3].zw = vec2(0.0);\npos = matProj * pos;\n} else {\npos = cc_matProj * pos;\n}\npos.z = 0.99999 * pos.w;\nreturn pos;\n}\nvoid main() { gl_Position = vert(); }", + "vert": "\nprecision highp float;\nlayout(std140) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(std140) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nin vec3 a_position;\nin vec3 a_normal;\nin vec2 a_texCoord;\nin vec4 a_tangent;\n#if CC_USE_SKINNING\nin vec4 a_joints;\nin vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nin highp vec4 a_jointAnimInfo;\n#endif\nin vec4 a_matWorld0;\nin vec4 a_matWorld1;\nin vec4 a_matWorld2;\n#if CC_USE_LIGHTMAP\nin vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nin vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nin float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nin float a_vertexId;\n#endif\nout mediump vec4 viewDir;\nvec4 vert () {\nviewDir = vec4(a_position, 1.0);\nmat4 matViewRotOnly = mat4(mat3(cc_matView));\nvec4 pos = matViewRotOnly * viewDir;\nif (cc_matProj[3].w > 0.0) {\nmat4 matProj = cc_matProj;\nmatProj[0].x = 5.2;\nmatProj[1].y = 2.6;\nmatProj[2].zw = vec2(-1.0);\nmatProj[3].zw = vec2(0.0);\npos = matProj * pos;\n} else {\npos = cc_matProj * pos;\n}\npos.z = 0.99999 * pos.w;\nreturn pos;\n}\nvoid main() { gl_Position = vert(); }", "frag": "\nprecision mediump float;\nlayout(std140) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(std140) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\nuniform samplerCube cc_environment;\nvec3 unpackRGBE (vec4 rgbe) {\nreturn rgbe.rgb * pow(1.1, rgbe.a * 255.0 - 128.0);\n}\nvec3 SRGBToLinear (vec3 gamma) {\nreturn gamma * gamma;\n}\nvec3 ACESToneMap (vec3 color) {\ncolor = min(color, vec3(8.0));\nconst float A = 2.51;\nconst float B = 0.03;\nconst float C = 2.43;\nconst float D = 0.59;\nconst float E = 0.14;\nreturn (color * (A * color + B)) / (color * (C * color + D) + E);\n}\nvec4 CCFragOutput (vec4 color) {\n#if CC_USE_HDR\ncolor.rgb = ACESToneMap(color.rgb);\n#endif\ncolor.rgb = sqrt(color.rgb);\nreturn color;\n}\nin mediump vec4 viewDir;\nvec4 frag () {\n#if USE_RGBE_CUBEMAP\nvec3 c = unpackRGBE(texture(cc_environment, viewDir.xyz));\n#else\nvec3 c = SRGBToLinear(texture(cc_environment, viewDir.xyz).rgb);\n#endif\nreturn CCFragOutput(vec4(c * cc_ambientSky.w, 1.0));\n}\nlayout(location = 0) out vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }", } ], diff --git a/cocos/core/builtin/shader-sources/glsl4.ts b/cocos/core/builtin/shader-sources/glsl4.ts index eaead44be5..b74523fb99 100644 --- a/cocos/core/builtin/shader-sources/glsl4.ts +++ b/cocos/core/builtin/shader-sources/glsl4.ts @@ -88,18 +88,18 @@ export const glsl4 = [ ], [ { - "vert": "#extension GL_EXT_shader_explicit_arithmetic_types_int32: require\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\nrgba = rgba * 255.0;\nhighp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\nhighp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\nhighp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\nreturn Sign * exp2(Exponent - 23.0) * Mantissa;\n}\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nlayout(location = 0) in vec3 a_position;\nlayout(location = 1) in vec3 a_normal;\nlayout(location = 2) in vec2 a_texCoord;\nlayout(location = 3) in vec4 a_tangent;\n#if CC_USE_SKINNING\nlayout(location = 4) in u32vec4 a_joints;\nlayout(location = 5) in vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nlayout(location = 6) in highp vec4 a_jointAnimInfo;\n#endif\nlayout(location = 7) in vec4 a_matWorld0;\nlayout(location = 8) in vec4 a_matWorld1;\nlayout(location = 9) in vec4 a_matWorld2;\n#if USE_LIGHTMAP\nlayout(location = 10) in vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nlayout(location = 11) in vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nlayout(location = 12) in float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nint getVertexId() {\nreturn gl_VertexIndex;\n}\n#endif\n#if CC_USE_MORPH\nlayout(set = 2, binding = 4) uniform CCMorph {\nvec4 cc_displacementWeights[15];\nvec4 cc_displacementTextureInfo;\n};\nvec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\nfloat pixelIndexF = float(pixelIndex);\nfloat x = mod(pixelIndexF, textureResolution.x);\nfloat y = floor(pixelIndexF / textureResolution.x);\nreturn vec2(x, y);\n}\nvec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\nreturn (vec2(location.x, location.y) + .5) / textureResolution;\n}\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int pixelIndex) {\nivec2 texSize = textureSize(tex, 0);\nreturn texelFetch(tex, ivec2(pixelIndex % texSize.x, pixelIndex / texSize.x), 0);\n}\n#else\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex * 4;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\nreturn vec4(\ndecode32(texture(tex, x)),\ndecode32(texture(tex, y)),\ndecode32(texture(tex, z)),\n1.0\n);\n}\n#endif\nfloat getDisplacementWeight(int index) {\nint quot = index / 4;\nint remainder = index - quot * 4;\nif (remainder == 0) {\nreturn cc_displacementWeights[quot].x;\n} else if (remainder == 1) {\nreturn cc_displacementWeights[quot].y;\n} else if (remainder == 2) {\nreturn cc_displacementWeights[quot].z;\n} else {\nreturn cc_displacementWeights[quot].w;\n}\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\nreturn fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n#else\nvec3 result = vec3(0, 0, 0);\nint nVertices = int(cc_displacementTextureInfo.z);\nfor (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\nresult += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n}\nreturn result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\nlayout(set = 2, binding = 7) uniform sampler2D cc_PositionDisplacements;\nvec3 getPositionDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nlayout(set = 2, binding = 8) uniform sampler2D cc_NormalDisplacements;\nvec3 getNormalDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\nlayout(set = 2, binding = 9) uniform sampler2D cc_TangentDisplacements;\nvec3 getTangentDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n}\n#endif\nvoid applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nint vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nnormal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\ntangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\n#if CC_USE_BAKED_ANIMATION\nlayout(set = 2, binding = 3) uniform CCSkinningTexture {\nhighp vec4 cc_jointTextureInfo;\n};\nlayout(set = 2, binding = 2) uniform CCSkinningAnimation {\nhighp vec4 cc_jointAnimInfo;\n};\nlayout(set = 2, binding = 6) uniform highp sampler2D cc_jointTexture;\nvoid CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n{\n#if USE_INSTANCING\nhighp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n#else\nhighp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n#endif\ninvSize = cc_jointTextureInfo.w;\nhighp float tempY = floor(temp * invSize);\nx = floor(temp - tempY * cc_jointTextureInfo.x);\ny = (tempY + 0.5) * invSize;\n}\n#else\nlayout(set = 2, binding = 3) uniform CCSkinning {\nhighp vec4 cc_joints[30 * 3];\n};\n#endif\n#if CC_USE_BAKED_ANIMATION\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(3.0, i, x, y, invSize);\nvec4 v1 = texture(cc_jointTexture, vec2((x + 0.5) * invSize, y));\nvec4 v2 = texture(cc_jointTexture, vec2((x + 1.5) * invSize, y));\nvec4 v3 = texture(cc_jointTexture, vec2((x + 2.5) * invSize, y));\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#else\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(12.0, i, x, y, invSize);\nvec4 v1 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n);\nvec4 v2 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n);\nvec4 v3 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n);\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\n#else\nmat4 getJointMatrix (float i) {\nint idx = int(i);\nvec4 v1 = cc_joints[idx * 3];\nvec4 v2 = cc_joints[idx * 3 + 1];\nvec4 v3 = cc_joints[idx * 3 + 2];\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\nmat4 skinMatrix () {\nvec4 joints = vec4(a_joints);\nreturn getJointMatrix(joints.x) * a_weights.x\n+ getJointMatrix(joints.y) * a_weights.y\n+ getJointMatrix(joints.z) * a_weights.z\n+ getJointMatrix(joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\nmat4 m = skinMatrix();\nposition = m * position;\n}\nvoid CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nmat4 m = skinMatrix();\nposition = m * position;\nnormal = (m * vec4(normal, 0.0)).xyz;\ntangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n}\n#endif\nvoid CCVertInput(inout StandardVertInput In)\n{\nIn.position = vec4(a_position, 1.0);\nIn.normal = a_normal;\nIn.tangent = a_tangent;\n#if CC_USE_MORPH\napplyMorph(In.position, In.normal, In.tangent);\n#endif\n#if CC_USE_SKINNING\nCCSkin(In.position, In.normal, In.tangent);\n#endif\n}\nlayout(set = 0, binding = 0) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(set = 0, binding = 1) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\n#if !USE_INSTANCING\n#if USE_BATCHING\nlayout(set = 2, binding = 0) uniform CCLocalBatched {\nhighp mat4 cc_matWorlds[10];\n};\n#else\nlayout(set = 2, binding = 0) uniform CCLocal {\nhighp mat4 cc_matWorld;\nhighp mat4 cc_matWorldIT;\nhighp vec4 cc_lightingMapUVParam;\nhighp vec4 cc_localShadowBias;\n};\n#endif\n#endif\nvoid CCGetWorldMatrixFull(out mat4 matWorld, out mat4 matWorldIT)\n{\n#if USE_INSTANCING\nmatWorld = mat4(\nvec4(a_matWorld0.xyz, 0.0),\nvec4(a_matWorld1.xyz, 0.0),\nvec4(a_matWorld2.xyz, 0.0),\nvec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)\n);\nmatWorldIT = matWorld;\n#elif USE_BATCHING\nmatWorld = cc_matWorlds[int(a_dyn_batch_id)];\nmatWorldIT = matWorld;\n#else\nmatWorld = cc_matWorld;\nmatWorldIT = cc_matWorldIT;\n#endif\n}\nlayout(set = 1, binding = 0) uniform Constants {\nvec4 tilingOffset;\nvec4 albedo;\nvec4 albedoScaleAndCutoff;\nvec4 pbrParams;\nvec4 emissive;\nvec4 emissiveScaleParam;\n};\nfloat LinearFog(vec4 pos) {\nvec4 wPos = pos;\nfloat cam_dis = distance(cc_cameraPos, wPos);\nfloat fogStart = cc_fogBase.x;\nfloat fogEnd = cc_fogBase.y;\nreturn clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * fogDensity);\nreturn f;\n}\nfloat ExpSquaredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\nreturn f;\n}\nfloat LayeredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat _FogTop = cc_fogAdd.x;\nfloat _FogRange = cc_fogAdd.y;\nvec3 camWorldProj = cc_cameraPos.xyz;\ncamWorldProj.y = 0.;\nvec3 worldPosProj = wPos.xyz;\nworldPosProj.y = 0.;\nfloat fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\nfloat fDeltaY, fDensityIntegral;\nif (cc_cameraPos.y > _FogTop) {\nif (wPos.y < _FogTop) {\nfDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\nfDensityIntegral = fDeltaY * fDeltaY * 0.5;\n} else {\nfDeltaY = 0.;\nfDensityIntegral = 0.;\n}\n} else {\nif (wPos.y < _FogTop) {\nfloat fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfloat fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\nfDeltaY = abs(fDeltaA - fDeltaB);\nfDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n} else {\nfDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n}\n}\nfloat fDensity;\nif (fDeltaY != 0.) {\nfDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n} else {\nfDensity = 0.;\n}\nfloat f = exp(-fDensity);\nreturn f;\n}\nvoid CC_TRANSFER_FOG_BASE(vec4 pos, out float factor)\n{\n#if CC_USE_FOG == 0\nfactor = LinearFog(pos);\n#elif CC_USE_FOG == 1\nfactor = ExpFog(pos);\n#elif CC_USE_FOG == 2\nfactor = ExpSquaredFog(pos);\n#elif CC_USE_FOG == 3\nfactor = LayeredFog(pos);\n#else\nfactor = 1.0;\n#endif\n}\n#if !CC_USE_ACCURATE_FOG\nlayout(location = 0) out float v_fog_factor;\n#endif\nvoid CC_TRANSFER_FOG(vec4 pos) {\n#if !CC_USE_ACCURATE_FOG\nCC_TRANSFER_FOG_BASE(pos, v_fog_factor);\n#endif\n}\nlayout(location = 1) out highp vec4 v_shadowPos;\nlayout(set = 0, binding = 2) uniform CCShadow {\nhighp mat4 cc_matLightPlaneProj;\nhighp mat4 cc_matLightView;\nhighp mat4 cc_matLightViewProj;\nhighp vec4 cc_shadowInvProjDepthInfo;\nhighp vec4 cc_shadowProjDepthInfo;\nhighp vec4 cc_shadowProjInfo;\nmediump vec4 cc_shadowNFLSInfo;\nmediump vec4 cc_shadowWHPBInfo;\nmediump vec4 cc_shadowLPNNInfo;\nlowp vec4 cc_shadowColor;\nmediump vec4 cc_planarNDInfo;\n};\n#if CC_RECEIVE_SHADOW\nlayout(set = 0, binding = 3) uniform highp sampler2D cc_shadowMap;\nlayout(set = 0, binding = 5) uniform highp sampler2D cc_spotLightingMap;\n#endif\n#if CC_RECEIVE_SHADOW\nvec2 CCGetShadowBias()\n{\n#if USE_INSTANCING\nreturn vec2(a_localShadowBias.x + cc_shadowWHPBInfo.w, a_localShadowBias.y + cc_shadowLPNNInfo.z);\n#elif !USE_BATCHING\nreturn vec2(cc_localShadowBias.x + cc_shadowWHPBInfo.w, cc_localShadowBias.y + cc_shadowLPNNInfo.z);\n#else\nreturn vec2(cc_shadowWHPBInfo.w, cc_shadowLPNNInfo.z);\n#endif\n}\n#endif\n#if USE_VERTEX_COLOR\nlayout(location = 14) in vec4 a_color;\nlayout(location = 2) out lowp vec4 v_color;\n#endif\nlayout(location = 3) out vec3 v_position;\nlayout(location = 4) out mediump vec3 v_normal;\nlayout(location = 5) out vec2 v_uv;\n#if HAS_SECOND_UV\nlayout(location = 6) out mediump vec2 v_uv1;\n#endif\n#if CC_RECEIVE_SHADOW\nlayout(location = 7) out mediump vec2 v_shadowBias;\n#endif\n#if USE_NORMAL_MAP\nlayout(location = 8) out mediump vec4 v_tangent;\n#endif\n#if HAS_SECOND_UV || USE_LIGHTMAP\nlayout(location = 15) in vec2 a_texCoord1;\n#endif\n#if USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\nlayout(location = 9) out vec3 v_luv;\nvoid CCLightingMapCaclUV()\n{\n#if !USE_INSTANCING\nv_luv.xy = cc_lightingMapUVParam.xy + a_texCoord1 * cc_lightingMapUVParam.z;\nv_luv.z = cc_lightingMapUVParam.w;\n#else\nv_luv.xy = a_lightingMapUVParam.xy + a_texCoord1 * a_lightingMapUVParam.z;\nv_luv.z = a_lightingMapUVParam.w;\n#endif\n}\n#endif\nvoid main () {\nStandardVertInput In;\nCCVertInput(In);\nmat4 matWorld, matWorldIT;\nCCGetWorldMatrixFull(matWorld, matWorldIT);\nvec4 pos = matWorld * In.position;\nv_position = pos.xyz;\nv_normal = normalize((matWorldIT * vec4(In.normal, 0.0)).xyz);\n#if CC_RECEIVE_SHADOW\nv_shadowBias = CCGetShadowBias();\n#endif\n#if USE_TWOSIDE\nvec3 viewDirect = normalize(cc_cameraPos.xyz - v_position);\nv_normal *= dot(v_normal, viewDirect) < 0.0 ? -1.0 : 1.0;\n#endif\n#if USE_NORMAL_MAP\nv_tangent.xyz = normalize((matWorld * vec4(In.tangent.xyz, 0.0)).xyz);\nv_tangent.w = In.tangent.w;\n#endif\nv_uv = a_texCoord * tilingOffset.xy + tilingOffset.zw;\n#if SAMPLE_FROM_RT\nv_uv = cc_cameraPos.w > 1.0 ? vec2(v_uv.x, 1.0 - v_uv.y) : v_uv;\n#endif\n#if HAS_SECOND_UV\nv_uv1 = a_texCoord1 * tilingOffset.xy + tilingOffset.zw;\n#if SAMPLE_FROM_RT\nv_uv1 = cc_cameraPos.w > 1.0 ? vec2(v_uv1.x, 1.0 - v_uv1.y) : v_uv1;\n#endif\n#endif\n#if USE_VERTEX_COLOR\nv_color = a_color;\n#endif\nCC_TRANSFER_FOG(pos);\nv_shadowPos = cc_matLightViewProj * pos;\n#if USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\nCCLightingMapCaclUV();\n#endif\ngl_Position = cc_matProj * (cc_matView * matWorld) * In.position;\n}", - "frag": "\nprecision highp float;\nlayout(set = 0, binding = 0) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(set = 0, binding = 1) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\nlayout(set = 1, binding = 0) uniform Constants {\nvec4 tilingOffset;\nvec4 albedo;\nvec4 albedoScaleAndCutoff;\nvec4 pbrParams;\nvec4 emissive;\nvec4 emissiveScaleParam;\n};\nfloat LinearFog(vec4 pos) {\nvec4 wPos = pos;\nfloat cam_dis = distance(cc_cameraPos, wPos);\nfloat fogStart = cc_fogBase.x;\nfloat fogEnd = cc_fogBase.y;\nreturn clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * fogDensity);\nreturn f;\n}\nfloat ExpSquaredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\nreturn f;\n}\nfloat LayeredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat _FogTop = cc_fogAdd.x;\nfloat _FogRange = cc_fogAdd.y;\nvec3 camWorldProj = cc_cameraPos.xyz;\ncamWorldProj.y = 0.;\nvec3 worldPosProj = wPos.xyz;\nworldPosProj.y = 0.;\nfloat fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\nfloat fDeltaY, fDensityIntegral;\nif (cc_cameraPos.y > _FogTop) {\nif (wPos.y < _FogTop) {\nfDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\nfDensityIntegral = fDeltaY * fDeltaY * 0.5;\n} else {\nfDeltaY = 0.;\nfDensityIntegral = 0.;\n}\n} else {\nif (wPos.y < _FogTop) {\nfloat fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfloat fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\nfDeltaY = abs(fDeltaA - fDeltaB);\nfDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n} else {\nfDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n}\n}\nfloat fDensity;\nif (fDeltaY != 0.) {\nfDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n} else {\nfDensity = 0.;\n}\nfloat f = exp(-fDensity);\nreturn f;\n}\nvoid CC_TRANSFER_FOG_BASE(vec4 pos, out float factor)\n{\n#if CC_USE_FOG == 0\nfactor = LinearFog(pos);\n#elif CC_USE_FOG == 1\nfactor = ExpFog(pos);\n#elif CC_USE_FOG == 2\nfactor = ExpSquaredFog(pos);\n#elif CC_USE_FOG == 3\nfactor = LayeredFog(pos);\n#else\nfactor = 1.0;\n#endif\n}\nvoid CC_APPLY_FOG_BASE(inout vec4 color, float factor) {\ncolor = vec4(mix(cc_fogColor.rgb, color.rgb, factor), color.a);\n}\n#if !CC_USE_ACCURATE_FOG\nlayout(location = 0) in float v_fog_factor;\n#endif\nvoid CC_APPLY_FOG(inout vec4 color) {\n#if !CC_USE_ACCURATE_FOG\nCC_APPLY_FOG_BASE(color, v_fog_factor);\n#endif\n}\nvoid CC_APPLY_FOG(inout vec4 color, vec3 worldPos) {\n#if CC_USE_ACCURATE_FOG\nfloat factor;\nCC_TRANSFER_FOG_BASE(vec4(worldPos, 1.0), factor);\n#else\nfloat factor = v_fog_factor;\n#endif\nCC_APPLY_FOG_BASE(color, factor);\n}\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nvec3 SRGBToLinear (vec3 gamma) {\nreturn gamma * gamma;\n}\nlayout(set = 0, binding = 2) uniform CCShadow {\nhighp mat4 cc_matLightPlaneProj;\nhighp mat4 cc_matLightView;\nhighp mat4 cc_matLightViewProj;\nhighp vec4 cc_shadowInvProjDepthInfo;\nhighp vec4 cc_shadowProjDepthInfo;\nhighp vec4 cc_shadowProjInfo;\nmediump vec4 cc_shadowNFLSInfo;\nmediump vec4 cc_shadowWHPBInfo;\nmediump vec4 cc_shadowLPNNInfo;\nlowp vec4 cc_shadowColor;\nmediump vec4 cc_planarNDInfo;\n};\nhighp float unpackHighpData (float mainPart, float modPart) {\nhighp float data = mainPart;\nreturn data + modPart;\n}\nvoid packHighpData (out float mainPart, out float modPart, highp float data) {\nmainPart = fract(data);\nmodPart = data - mainPart;\n}\nhighp float unpackHighpData (float mainPart, float modPart, const float modValue) {\nhighp float data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nvoid packHighpData (out float mainPart, out float modPart, highp float data, const float modValue) {\nhighp float divide = data / modValue;\nmainPart = floor(divide);\nmodPart = (data - mainPart * modValue) / modValue;\n}\nhighp vec2 unpackHighpData (vec2 mainPart, vec2 modPart) {\nhighp vec2 data = mainPart;\nreturn data + modPart;\n}\nvoid packHighpData (out vec2 mainPart, out vec2 modPart, highp vec2 data) {\nmainPart = fract(data);\nmodPart = data - mainPart;\n}\nhighp vec2 unpackHighpData (vec2 mainPart, vec2 modPart, const float modValue) {\nhighp vec2 data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nvoid packHighpData (out vec2 mainPart, out vec2 modPart, highp vec2 data, const float modValue) {\nhighp vec2 divide = data / modValue;\nmainPart = floor(divide);\nmodPart = (data - mainPart * modValue) / modValue;\n}\nhighp vec3 unpackHighpData (vec3 mainPart, vec3 modPart) {\nhighp vec3 data = mainPart;\nreturn data + modPart;\n}\nvoid packHighpData (out vec3 mainPart, out vec3 modPart, highp vec3 data) {\nmainPart = fract(data);\nmodPart = data - mainPart;\n}\nhighp vec3 unpackHighpData (vec3 mainPart, vec3 modPart, const float modValue) {\nhighp vec3 data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nvoid packHighpData (out vec3 mainPart, out vec3 modPart, highp vec3 data, const float modValue) {\nhighp vec3 divide = data / modValue;\nmainPart = floor(divide);\nmodPart = (data - mainPart * modValue) / modValue;\n}\nhighp vec4 unpackHighpData (vec4 mainPart, vec4 modPart) {\nhighp vec4 data = mainPart;\nreturn data + modPart;\n}\nvoid packHighpData (out vec4 mainPart, out vec4 modPart, highp vec4 data) {\nmainPart = fract(data);\nmodPart = data - mainPart;\n}\nhighp vec4 unpackHighpData (vec4 mainPart, vec4 modPart, const float modValue) {\nhighp vec4 data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nvoid packHighpData (out vec4 mainPart, out vec4 modPart, highp vec4 data, const float modValue) {\nhighp vec4 divide = data / modValue;\nmainPart = floor(divide);\nmodPart = (data - mainPart * modValue) / modValue;\n}\nlayout(set = 2, binding = 0) uniform CCLocal {\nhighp mat4 cc_matWorld;\nhighp mat4 cc_matWorldIT;\nhighp vec4 cc_lightingMapUVParam;\nhighp vec4 cc_localShadowBias;\n};\nfloat CCGetLinearDepthFromViewSpace(vec3 viewPos) {\nfloat dist = length(viewPos);\nreturn (dist - cc_shadowNFLSInfo.x) / (cc_shadowNFLSInfo.y - cc_shadowNFLSInfo.x);\n}\nfloat CCGetLinearDepth(vec3 worldPos) {\nvec4 viewStartPos = cc_matLightView * vec4(worldPos.xyz, 1.0);\nreturn CCGetLinearDepthFromViewSpace(viewStartPos.xyz);\n}\n#if CC_RECEIVE_SHADOW\nlayout(set = 0, binding = 3) uniform highp sampler2D cc_shadowMap;\nlayout(set = 0, binding = 5) uniform highp sampler2D cc_spotLightingMap;\nvec4 ApplyShadowDepthBias_FaceNormal(vec4 shadowPos, vec3 worldNormal, float normalBias)\n{\nvec4 newShadowPos = shadowPos;\nif(normalBias > EPSILON_LOWP)\n{\nvec4 viewNormal = cc_matLightView * vec4(worldNormal, 0.0);\nif(viewNormal.z < 0.1)\nnewShadowPos.xy += viewNormal.xy * cc_shadowProjInfo.xy * normalBias * clamp(viewNormal.z, 0.001, 0.1);\n}\nreturn newShadowPos;\n}\nvec4 ApplyShadowDepthBias_Perspective(vec4 shadowPos, float viewspaceDepthBias)\n{\nvec3 viewSpacePos;\nviewSpacePos.xy = shadowPos.xy * cc_shadowProjInfo.zw;\nviewSpacePos.z = shadowPos.z * cc_shadowInvProjDepthInfo.x + shadowPos.w * cc_shadowInvProjDepthInfo.y;\nviewSpacePos.xyz += cc_shadowProjDepthInfo.z * normalize(viewSpacePos.xyz) * viewspaceDepthBias;\nvec4 clipSpacePos;\nclipSpacePos.xy = viewSpacePos.xy * cc_shadowProjInfo.xy;\nclipSpacePos.zw = viewSpacePos.z * cc_shadowProjDepthInfo.xz + vec2(cc_shadowProjDepthInfo.y, 0.0);\nif (cc_shadowNFLSInfo.z > EPSILON) {\nclipSpacePos.z = CCGetLinearDepthFromViewSpace(viewSpacePos.xyz);\nclipSpacePos.z = (clipSpacePos.z * 2.0 - 1.0) * clipSpacePos.w;\n}\nreturn clipSpacePos;\n}\nvec4 ApplyShadowDepthBias_Orthographic(vec4 shadowPos, float viewspaceDepthBias)\n{\nfloat coeffA = cc_shadowProjDepthInfo.x;\nfloat coeffB = cc_shadowProjDepthInfo.y;\nfloat viewSpacePos_z = (shadowPos.z - coeffB) / coeffA;\nviewSpacePos_z += viewspaceDepthBias;\nvec4 result = shadowPos;\nresult.z = viewSpacePos_z * coeffA + coeffB;\nreturn result;\n}\nfloat CCGetShadowFactorHard (vec4 shadowPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Orthographic(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat shadow = 0.0;\nfloat closestDepth = 0.0;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nclosestDepth = dot(texture(cc_shadowMap, clipPos.xy), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0));\n} else {\nclosestDepth = texture(cc_shadowMap, clipPos.xy).x;\n}\nshadow = step(clipPos.z, closestDepth);\nreturn shadow;\n}\nfloat CCGetShadowFactorSoft (vec4 shadowPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Orthographic(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat offsetDepth = clipPos.z;\nvec2 mapSize = cc_shadowWHPBInfo.xy;\nvec2 oneTap = 1.0 / mapSize;\nvec2 clipPos_offset = clipPos.xy + oneTap;\nfloat block0, block1, block2, block3;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos.y)).x);\nblock1 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset.x, clipPos.y)).x);\nblock2 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset.y)).x);\nblock3 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset.x, clipPos_offset.y)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * mapSize.x;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block2, block3, coefX);\nfloat coefY = mod(clipPos.y, oneTap.y) * mapSize.y;\nreturn mix(resultX, resultY, coefY);\n}\nfloat CCGetShadowFactorSoft2X (vec4 shadowPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Orthographic(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat offsetDepth = clipPos.z;\nvec2 mapSize = cc_shadowWHPBInfo.xy;\nvec2 oneTap = 1.0 / mapSize;\nfloat clipPos_offset_L = clipPos.x - oneTap.x;\nfloat clipPos_offset_R = clipPos.x + oneTap.x;\nfloat clipPos_offset_U = clipPos.y - oneTap.y;\nfloat clipPos_offset_D = clipPos.y + oneTap.y;\nfloat block0, block1, block2, block3, block4, block5, block6, block7, block8;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock4 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock5 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock6 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock7 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock8 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_U)).x);\nblock1 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset_U)).x);\nblock2 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_U)).x);\nblock3 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos.y)).x);\nblock4 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos.y)).x);\nblock5 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos.y)).x);\nblock6 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_D)).x);\nblock7 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset_D)).x);\nblock8 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_D)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * mapSize.x;\nfloat coefY = mod(clipPos.y, oneTap.y) * mapSize.y;\nfloat shadow = 0.0;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block3, block4, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block1, block2, coefX);\nresultY = mix(block4, block5, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block3, block4, coefX);\nresultY = mix(block6, block7, coefX);\nshadow += mix(resultX, resultY, coefY);\nresultX = mix(block4, block5, coefX);\nresultY = mix(block7, block8, coefX);\nshadow += mix(resultX, resultY, coefY);\nreturn shadow * 0.25;\n}\nfloat CCGetSpotLightShadowFactorHard (vec4 shadowPos, vec3 worldPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Perspective(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat shadow = 0.0;\nfloat closestDepth = 0.0;\nfloat depth = clipPos.z;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nclosestDepth = dot(texture(cc_spotLightingMap, clipPos.xy), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0));\n} else {\nclosestDepth = texture(cc_spotLightingMap, clipPos.xy).x;\n}\nshadow = step(depth, closestDepth);\nreturn shadow;\n}\nfloat CCGetSpotLightShadowFactorSoft (vec4 shadowPos, vec3 worldPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Perspective(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat depth = 0.0;\nif (cc_shadowNFLSInfo.z > EPSILON) {\ndepth = CCGetLinearDepth(worldPos);\n} else {\ndepth = clipPos.z;\n}\nvec2 oneTap = 1.0 / cc_shadowWHPBInfo.xy;\nvec2 clipPos_offset = clipPos.xy + oneTap;\nfloat block0, block1, block2, block3;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)).x);\nblock1 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos.y)).x);\nblock2 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset.y)).x);\nblock3 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos_offset.y)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * cc_shadowWHPBInfo.x;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block2, block3, coefX);\nfloat coefY = mod(clipPos.y, oneTap.y) * cc_shadowWHPBInfo.y;\nreturn mix(resultX, resultY, coefY);\n}\nfloat CCGetSpotLightShadowFactorSoft2X (vec4 shadowPos, vec3 worldPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Perspective(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat depth = 0.0;\nif (cc_shadowNFLSInfo.z > EPSILON) {\ndepth = CCGetLinearDepth(worldPos);\n} else {\ndepth = clipPos.z;\n}\nvec2 mapSize = cc_shadowWHPBInfo.xy;\nvec2 oneTap = 1.0 / mapSize;\nfloat clipPos_offset_L = clipPos.x - oneTap.x;\nfloat clipPos_offset_R = clipPos.x + oneTap.x;\nfloat clipPos_offset_U = clipPos.y - oneTap.y;\nfloat clipPos_offset_D = clipPos.y + oneTap.y;\nfloat block0, block1, block2, block3, block4, block5, block6, block7, block8;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock4 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock5 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock6 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock7 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock8 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_U)).x);\nblock1 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_U)).x);\nblock2 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_U)).x);\nblock3 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos.y)).x);\nblock4 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)).x);\nblock5 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos.y)).x);\nblock6 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_D)).x);\nblock7 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_D)).x);\nblock8 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_D)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * mapSize.x;\nfloat coefY = mod(clipPos.y, oneTap.y) * mapSize.y;\nfloat shadow = 0.0;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block3, block4, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block1, block2, coefX);\nresultY = mix(block4, block5, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block3, block4, coefX);\nresultY = mix(block6, block7, coefX);\nshadow += mix(resultX, resultY, coefY);\nresultX = mix(block4, block5, coefX);\nresultY = mix(block7, block8, coefX);\nshadow += mix(resultX, resultY, coefY);\nreturn shadow * 0.25;\n}\nfloat CCSpotShadowFactorBase(vec4 shadowPos, vec3 worldPos, vec2 shadowBias)\n{\nfloat pcf = cc_shadowWHPBInfo.z;\nif (pcf > 1.9) {\nreturn CCGetSpotLightShadowFactorSoft2X(shadowPos, worldPos, shadowBias.x);\n}else if (pcf > 0.9) {\nreturn CCGetSpotLightShadowFactorSoft(shadowPos, worldPos, shadowBias.x);\n}else {\nreturn CCGetSpotLightShadowFactorHard(shadowPos, worldPos, shadowBias.x);\n}\n}\nfloat CCShadowFactorBase(vec4 shadowPos, vec3 N, vec2 shadowBias)\n{\nfloat realtimeShadow = 1.0;\nvec4 pos = ApplyShadowDepthBias_FaceNormal(shadowPos, N, shadowBias.y);\nfloat pcf = cc_shadowWHPBInfo.z;\nif (pcf > 1.9) {\nrealtimeShadow = CCGetShadowFactorSoft2X(pos, shadowBias.x);\n}else if (pcf > 0.9) {\nrealtimeShadow = CCGetShadowFactorSoft(pos, shadowBias.x);\n}else {\nrealtimeShadow = CCGetShadowFactorHard(pos, shadowBias.x);\n}\nreturn mix(realtimeShadow, 1.0, cc_shadowNFLSInfo.w);\n}\n#endif\n#if CC_USE_IBL\nlayout(set = 0, binding = 4) uniform samplerCube cc_environment;\nvec4 fragTextureLod (sampler2D tex, vec2 coord, float lod) {\nreturn textureLod(tex, coord, lod);\n}\nvec4 fragTextureLod (samplerCube tex, vec3 coord, float lod) {\nreturn textureLod(tex, coord, lod);\n}\nvec3 unpackRGBE (vec4 rgbe) {\nreturn rgbe.rgb * pow(1.1, rgbe.a * 255.0 - 128.0);\n}\n#if CC_USE_DIFFUSEMAP\nlayout(set = 0, binding = 6) uniform samplerCube cc_diffuseMap;\n#endif\n#endif\nfloat GGXMobile (float roughness, float NoH, vec3 H, vec3 N) {\nvec3 NxH = cross(N, H);\nfloat OneMinusNoHSqr = dot(NxH, NxH);\nfloat a = roughness * roughness;\nfloat n = NoH * a;\nfloat p = a / (OneMinusNoHSqr + n * n);\nreturn p * p;\n}\nfloat CalcSpecular (float roughness, float NoH, vec3 H, vec3 N) {\nreturn (roughness * 0.25 + 0.25) * GGXMobile(roughness, NoH, H, N);\n}\nvec3 BRDFApprox (vec3 specular, float roughness, float NoV) {\nconst vec4 c0 = vec4(-1.0, -0.0275, -0.572, 0.022);\nconst vec4 c1 = vec4(1.0, 0.0425, 1.04, -0.04);\nvec4 r = roughness * c0 + c1;\nfloat a004 = min(r.x * r.x, exp2(-9.28 * NoV)) * r.x + r.y;\nvec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;\nAB.y *= clamp(50.0 * specular.g, 0.0, 1.0);\nreturn specular * AB.x + AB.y;\n}\n#if USE_REFLECTION_DENOISE\nvec3 GetEnvReflectionWithMipFiltering(vec3 R, float roughness, float mipCount, float denoiseIntensity) {\n#if CC_USE_IBL\nfloat mip = roughness * mipCount;\nfloat delta = (dot(dFdx(R), dFdy(R))) * 1000.0;\nfloat mipBias = mix(0.0, 5.0, clamp(delta, 0.0, 1.0));\nvec4 biased = fragTextureLod(cc_environment, R, mip + mipBias);\nvec4 filtered = texture(cc_environment, R);\n#if CC_USE_IBL == 2\nbiased.rgb = unpackRGBE(biased);\nfiltered.rgb = unpackRGBE(filtered);\n#else\nbiased.rgb = SRGBToLinear(biased.rgb);\nfiltered.rgb = SRGBToLinear(filtered.rgb);\n#endif\nreturn mix(biased.rgb, filtered.rgb, denoiseIntensity);\n#else\nreturn vec3(0.0, 0.0, 0.0);\n#endif\n}\n#endif\nstruct StandardSurface {\nvec4 albedo;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nvec3 position, position_fract_part;\n#else\nvec3 position;\n#endif\nvec3 normal;\nvec3 emissive;\nvec3 lightmap;\nfloat lightmap_test;\nfloat roughness;\nfloat metallic;\nfloat occlusion;\nfloat specularIntensity;\n#if CC_RECEIVE_SHADOW\nvec2 shadowBias;\n#endif\n};\nvec4 CCStandardShadingBase (StandardSurface s, vec4 shadowPos) {\nvec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\nvec3 specular = mix(vec3(0.08 * s.specularIntensity), s.albedo.rgb, s.metallic);\nvec3 position;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nposition = unpackHighpData(s.position, s.position_fract_part);\n#else\nposition = s.position;\n#endif\nvec3 N = normalize(s.normal);\nvec3 V = normalize(cc_cameraPos.xyz - position);\nfloat NV = max(abs(dot(N, V)), 0.0);\nspecular = BRDFApprox(specular, s.roughness, NV);\nvec3 L = normalize(-cc_mainLitDir.xyz);\nvec3 H = normalize(L + V);\nfloat NH = max(dot(N, H), 0.0);\nfloat NL = max(dot(N, L), 0.0);\nvec3 finalColor = NL * cc_mainLitColor.rgb * cc_mainLitColor.w;\nvec3 diffuseContrib = diffuse / PI;\nvec3 specularContrib = specular * CalcSpecular(s.roughness, NH, H, N);\nvec3 dirlightContrib = (diffuseContrib + specularContrib);\nfloat shadow = 1.0;\n#if CC_RECEIVE_SHADOW\nif (NL > 0.0 && cc_mainLitDir.w > 0.0) {\nshadow = CCShadowFactorBase(shadowPos, N, s.shadowBias);\n}\n#endif\ndirlightContrib *= shadow;\nfinalColor *= dirlightContrib;\n#if USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\nif (s.lightmap_test > EPSILON_LOWP) {\nfinalColor = diffuse * s.lightmap.rgb * shadow;\n}\n#endif\nfloat fAmb = 0.5 - N.y * 0.5;\nvec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb);\n#if CC_USE_IBL\n#if CC_USE_DIFFUSEMAP\nvec4 diffuseMap = texture(cc_diffuseMap, N);\n#if CC_USE_DIFFUSEMAP == 2\nambDiff = unpackRGBE(diffuseMap);\n#else\nambDiff = SRGBToLinear(diffuseMap.rgb);\n#endif\n#endif\nvec3 R = normalize(reflect(-V, N));\n#if USE_REFLECTION_DENOISE\nvec3 env = GetEnvReflectionWithMipFiltering(R, s.roughness, cc_ambientGround.w, 0.6);\n#else\nvec4 envmap = fragTextureLod(cc_environment, R, s.roughness * cc_ambientGround.w);\n#if CC_USE_IBL == 2\nvec3 env = unpackRGBE(envmap);\n#else\nvec3 env = SRGBToLinear(envmap.rgb);\n#endif\n#endif\nfinalColor += env * cc_ambientSky.w * specular * s.occlusion;\n#endif\nfinalColor += ambDiff.rgb * cc_ambientSky.w * diffuse * s.occlusion;\nfinalColor += s.emissive;\nreturn vec4(finalColor, s.albedo.a);\n}\nvec3 ACESToneMap (vec3 color) {\ncolor = min(color, vec3(8.0));\nconst float A = 2.51;\nconst float B = 0.03;\nconst float C = 2.43;\nconst float D = 0.59;\nconst float E = 0.14;\nreturn (color * (A * color + B)) / (color * (C * color + D) + E);\n}\nvec4 CCFragOutput (vec4 color) {\n#if CC_USE_HDR\ncolor.rgb = ACESToneMap(color.rgb);\n#endif\ncolor.rgb = sqrt(color.rgb);\nreturn color;\n}\nlayout(location = 1) in highp vec4 v_shadowPos;\n#if CC_RECEIVE_SHADOW\n#endif\n#if USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\nlayout(location = 9) in vec3 v_luv;\nlayout(set = 2, binding = 10) uniform sampler2D cc_lightingMap;\n#endif\nlayout(location = 3) in vec3 v_position;\nlayout(location = 5) in vec2 v_uv;\n#if HAS_SECOND_UV\nlayout(location = 6) in mediump vec2 v_uv1;\n#endif\nlayout(location = 4) in mediump vec3 v_normal;\n#if CC_RECEIVE_SHADOW\nlayout(location = 7) in mediump vec2 v_shadowBias;\n#endif\n#if USE_VERTEX_COLOR\nlayout(location = 2) in lowp vec4 v_color;\n#endif\n#if USE_ALBEDO_MAP\nlayout(set = 1, binding = 1) uniform sampler2D albedoMap;\n#endif\n#if USE_NORMAL_MAP\nlayout(location = 8) in mediump vec4 v_tangent;\nlayout(set = 1, binding = 2) uniform sampler2D normalMap;\n#endif\n#if USE_PBR_MAP\nlayout(set = 1, binding = 3) uniform sampler2D pbrMap;\n#endif\n#if USE_METALLIC_ROUGHNESS_MAP\nlayout(set = 1, binding = 4) uniform sampler2D metallicRoughnessMap;\n#endif\n#if USE_OCCLUSION_MAP\nlayout(set = 1, binding = 5) uniform sampler2D occlusionMap;\n#endif\n#if USE_EMISSIVE_MAP\nlayout(set = 1, binding = 6) uniform sampler2D emissiveMap;\n#endif\n#if USE_ALPHA_TEST\n#endif\nvoid surf (out StandardSurface s) {\nvec4 baseColor = albedo;\n#if USE_VERTEX_COLOR\nbaseColor.rgb *= SRGBToLinear(v_color.rgb);\nbaseColor.a *= v_color.a;\n#endif\n#if USE_ALBEDO_MAP\nvec4 texColor = texture(albedoMap, ALBEDO_UV);\ntexColor.rgb = SRGBToLinear(texColor.rgb);\nbaseColor *= texColor;\n#endif\ns.albedo = baseColor;\ns.albedo.rgb *= albedoScaleAndCutoff.xyz;\n#if USE_ALPHA_TEST\nif (s.albedo.ALPHA_TEST_CHANNEL < albedoScaleAndCutoff.w) discard;\n#endif\n#if USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\nvec4 lightColor = texture(cc_lightingMap, v_luv.xy);\ns.lightmap = lightColor.xyz * v_luv.z;\ns.lightmap_test = v_luv.z;\n#endif\ns.normal = v_normal;\n#if CC_RECEIVE_SHADOW\ns.shadowBias = v_shadowBias;\n#endif\n#if USE_NORMAL_MAP\nvec3 nmmp = texture(normalMap, NORMAL_UV).xyz - vec3(0.5);\nvec3 bitangent = cross(v_normal, v_tangent.xyz) * v_tangent.w;\ns.normal =\n(nmmp.x * emissiveScaleParam.w) * normalize(v_tangent.xyz) +\n(nmmp.y * emissiveScaleParam.w) * normalize(bitangent) +\nnmmp.z * normalize(s.normal);\n#endif\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\npackHighpData(s.position, s.position_fract_part, v_position);\n#else\ns.position = v_position;\n#endif\nvec4 pbr = pbrParams;\n#if USE_PBR_MAP\nvec4 res = texture(pbrMap, PBR_UV);\npbr.x *= res.r;\npbr.y *= res.g;\npbr.z *= res.b;\npbr.w *= res.a;\n#endif\n#if USE_METALLIC_ROUGHNESS_MAP\nvec4 metallicRoughness = texture(metallicRoughnessMap, PBR_UV);\npbr.z *= metallicRoughness.b;\npbr.y *= metallicRoughness.g;\n#endif\n#if USE_OCCLUSION_MAP\npbr.x *= texture(occlusionMap, PBR_UV).r;\n#endif\ns.occlusion = pbr.x;\ns.roughness = pbr.y;\ns.specularIntensity = 0.5;\ns.metallic = pbr.z;\ns.emissive = emissive.rgb * emissiveScaleParam.xyz;\n#if USE_EMISSIVE_MAP\ns.emissive *= SRGBToLinear(texture(emissiveMap, EMISSIVE_UV).rgb);\n#endif\n}\n#if CC_FORWARD_ADD\n#if CC_PIPELINE_TYPE == 0\n#define LIGHTS_PER_PASS 1\n#else\n#define LIGHTS_PER_PASS 10\n#endif\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 0\nlayout(set = 2, binding = 1) uniform CCForwardLight {\nhighp vec4 cc_lightPos[LIGHTS_PER_PASS];\nvec4 cc_lightColor[LIGHTS_PER_PASS];\nvec4 cc_lightSizeRangeAngle[LIGHTS_PER_PASS];\nvec4 cc_lightDir[LIGHTS_PER_PASS];\n};\n#endif\nfloat SmoothDistAtt (float distSqr, float invSqrAttRadius) {\nfloat factor = distSqr * invSqrAttRadius;\nfloat smoothFactor = clamp(1.0 - factor * factor, 0.0, 1.0);\nreturn smoothFactor * smoothFactor;\n}\nfloat GetDistAtt (float distSqr, float invSqrAttRadius) {\nfloat attenuation = 1.0 / max(distSqr, 0.01*0.01);\nattenuation *= SmoothDistAtt(distSqr , invSqrAttRadius);\nreturn attenuation;\n}\nfloat GetAngleAtt (vec3 L, vec3 litDir, float litAngleScale, float litAngleOffset) {\nfloat cd = dot(litDir, L);\nfloat attenuation = clamp(cd * litAngleScale + litAngleOffset, 0.0, 1.0);\nreturn (attenuation * attenuation);\n}\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 0\nvec4 CCStandardShadingAdditive (StandardSurface s, vec4 shadowPos) {\nvec3 position;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nposition = unpackHighpData(s.position, s.position_fract_part);\n#else\nposition = s.position;\n#endif\nvec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\nvec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\nvec3 diffuseContrib = diffuse / PI;\nvec3 N = normalize(s.normal);\nvec3 V = normalize(cc_cameraPos.xyz - position);\nfloat NV = max(abs(dot(N, V)), 0.0);\nspecular = BRDFApprox(specular, s.roughness, NV);\nvec3 finalColor = vec3(0.0);\nint numLights = CC_PIPELINE_TYPE == 0 ? LIGHTS_PER_PASS : int(cc_lightDir[0].w);\nfor (int i = 0; i < LIGHTS_PER_PASS; i++) {\nif (i >= numLights) break;\nvec3 SLU = cc_lightPos[i].xyz - position;\nvec3 SL = normalize(SLU);\nvec3 SH = normalize(SL + V);\nfloat SNL = max(dot(N, SL), 0.0);\nfloat SNH = max(dot(N, SH), 0.0);\nfloat distSqr = dot(SLU, SLU);\nfloat litRadius = cc_lightSizeRangeAngle[i].x;\nfloat litRadiusSqr = litRadius * litRadius;\nfloat illum = litRadiusSqr / max(litRadiusSqr, distSqr);\nfloat attRadiusSqrInv = 1.0 / max(cc_lightSizeRangeAngle[i].y, 0.01);\nattRadiusSqrInv *= attRadiusSqrInv;\nfloat att = GetDistAtt(distSqr, attRadiusSqrInv);\nvec3 lspec = specular * CalcSpecular(s.roughness, SNH, SH, N);\nif (cc_lightPos[i].w > 0.0) {\nfloat cosInner = max(dot(-cc_lightDir[i].xyz, SL), 0.01);\nfloat cosOuter = cc_lightSizeRangeAngle[i].z;\nfloat litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\nfloat litAngleOffset = -cosOuter * litAngleScale;\natt *= GetAngleAtt(SL, -cc_lightDir[i].xyz, litAngleScale, litAngleOffset);\n}\nvec3 lightColor = cc_lightColor[i].rgb;\nfloat shadow = 1.0;\n#if CC_RECEIVE_SHADOW\nif (cc_lightPos[i].w > 0.0 && cc_lightSizeRangeAngle[i].w > 0.0) {\nshadow = CCSpotShadowFactorBase(shadowPos, position, s.shadowBias);\n}\n#endif\nlightColor *= shadow;\nfinalColor += SNL * lightColor * cc_lightColor[i].w * illum * att * (diffuseContrib + lspec);\n}\nreturn vec4(finalColor, 0.0);\n}\n#endif\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 1\nlayout(set = 1, binding = 7) readonly buffer b_ccLightsBuffer { vec4 b_ccLights[]; };\nlayout(set = 1, binding = 8) readonly buffer b_clusterLightIndicesBuffer { uint b_clusterLightIndices[]; };\nlayout(set = 1, binding = 9) readonly buffer b_clusterLightGridBuffer { uvec4 b_clusterLightGrid[]; };\nstruct CCLight\n{\nvec4 cc_lightPos;\nvec4 cc_lightColor;\nvec4 cc_lightSizeRangeAngle;\nvec4 cc_lightDir;\n};\nstruct Cluster\n{\nvec3 minBounds;\nvec3 maxBounds;\n};\nstruct LightGrid\n{\nuint offset;\nuint ccLights;\n};\nCCLight getCCLight(uint i)\n{\nCCLight light;\nlight.cc_lightPos = b_ccLights[4u * i + 0u];\nlight.cc_lightColor = b_ccLights[4u * i + 1u];\nlight.cc_lightSizeRangeAngle = b_ccLights[4u * i + 2u];\nlight.cc_lightDir = b_ccLights[4u * i + 3u];\nreturn light;\n}\nLightGrid getLightGrid(uint cluster)\n{\nuvec4 gridvec = b_clusterLightGrid[cluster];\nLightGrid grid;\ngrid.offset = gridvec.x;\ngrid.ccLights = gridvec.y;\nreturn grid;\n}\nuint getGridLightIndex(uint start, uint offset)\n{\nreturn b_clusterLightIndices[start + offset];\n}\nuint getClusterZIndex(vec4 worldPos)\n{\nfloat scale = float(24) / log(cc_nearFar.y / cc_nearFar.x);\nfloat bias = -(float(24) * log(cc_nearFar.x) / log(cc_nearFar.y / cc_nearFar.x));\nfloat eyeDepth = -(cc_matView * worldPos).z;\nuint zIndex = uint(max(log(eyeDepth) * scale + bias, 0.0));\nreturn zIndex;\n}\nuint getClusterIndex(vec4 fragCoord, vec4 worldPos)\n{\nuint zIndex = getClusterZIndex(worldPos);\nfloat clusterSizeX = ceil(cc_viewPort.z / float(16));\nfloat clusterSizeY = ceil(cc_viewPort.w / float(8));\nuvec3 indices = uvec3(uvec2(fragCoord.xy / vec2(clusterSizeX, clusterSizeY)), zIndex);\nuint cluster = (16u * 8u) * indices.z + 16u * indices.y + indices.x;\nreturn cluster;\n}\nvec4 CCClusterShadingAdditive (StandardSurface s, vec4 shadowPos) {\nvec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\nvec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\nvec3 diffuseContrib = diffuse / PI;\nvec3 position;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nposition = unpackHighpData(s.position, s.position_fract_part);\n#else\nposition = s.position;\n#endif\nvec3 N = normalize(s.normal);\nvec3 V = normalize(cc_cameraPos.xyz - position);\nfloat NV = max(abs(dot(N, V)), 0.001);\nspecular = BRDFApprox(specular, s.roughness, NV);\nvec3 finalColor = vec3(0.0);\nuint cluster = getClusterIndex(gl_FragCoord, vec4(position, 1.0));\nLightGrid grid = getLightGrid(cluster);\nuint numLights = grid.ccLights;\nfor (uint i = 0u; i < 100u; i++) {\nif (i >= numLights) break;\nuint lightIndex = getGridLightIndex(grid.offset, i);\nCCLight light = getCCLight(lightIndex);\nvec3 SLU = light.cc_lightPos.xyz - position;\nvec3 SL = normalize(SLU);\nvec3 SH = normalize(SL + V);\nfloat SNL = max(dot(N, SL), 0.001);\nfloat SNH = max(dot(N, SH), 0.0);\nfloat distSqr = dot(SLU, SLU);\nfloat litRadius = light.cc_lightSizeRangeAngle.x;\nfloat litRadiusSqr = litRadius * litRadius;\nfloat illum = PI * (litRadiusSqr / max(litRadiusSqr , distSqr));\nfloat attRadiusSqrInv = 1.0 / max(light.cc_lightSizeRangeAngle.y, 0.01);\nattRadiusSqrInv *= attRadiusSqrInv;\nfloat att = GetDistAtt(distSqr, attRadiusSqrInv);\nvec3 lspec = specular * CalcSpecular(s.roughness, SNH, SH, N);\nif (light.cc_lightPos.w > 0.0) {\nfloat cosInner = max(dot(-light.cc_lightDir.xyz, SL), 0.01);\nfloat cosOuter = light.cc_lightSizeRangeAngle.z;\nfloat litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\nfloat litAngleOffset = -cosOuter * litAngleScale;\natt *= GetAngleAtt(SL, -light.cc_lightDir.xyz, litAngleScale, litAngleOffset);\n}\nvec3 lightColor = light.cc_lightColor.rgb;\nfloat shadow = 1.0;\n#if CC_RECEIVE_SHADOW\nif (light.cc_lightPos.w > 0.0) {\nshadow = CCSpotShadowFactorBase(shadowPos, position, s.shadowBias);\n}\n#endif\nlightColor *= shadow;\nfinalColor += SNL * lightColor * light.cc_lightColor.w * illum * att * (diffuseContrib + lspec);\n}\nreturn vec4(finalColor, 0.0);\n}\n#endif\nlayout(location = 0) out vec4 fragColorX;\nvoid main () {\nStandardSurface s; surf(s);\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 1\nvec4 color = CCClusterShadingAdditive(s, v_shadowPos);\n#else\nvec4 color = CCStandardShadingAdditive(s, v_shadowPos);\n#endif\nfragColorX = CCFragOutput(color);\n}\n#elif (CC_PIPELINE_TYPE == 0 || CC_FORCE_FORWARD_SHADING)\nlayout(location = 0) out vec4 fragColorX;\nvoid main () {\nStandardSurface s; surf(s);\nvec4 color = CCStandardShadingBase(s, v_shadowPos);\nCC_APPLY_FOG(color, s.position.xyz);\nfragColorX = CCFragOutput(color);\n}\n#elif CC_PIPELINE_TYPE == 1\nvec2 signNotZero(vec2 v) {\nreturn vec2((v.x >= 0.0) ? +1.0 : -1.0, (v.y >= 0.0) ? +1.0 : -1.0);\n}\nvec2 float32x3_to_oct(in vec3 v) {\nvec2 p = v.xy * (1.0 / (abs(v.x) + abs(v.y) + abs(v.z)));\nreturn (v.z <= 0.0) ? ((1.0 - abs(p.yx)) * signNotZero(p)) : p;\n}\nlayout(location = 0) out vec4 fragColor0;\nlayout(location = 1) out vec4 fragColor1;\nlayout(location = 2) out vec4 fragColor2;\nvoid main () {\nStandardSurface s; surf(s);\nfragColor0 = s.albedo;\nfragColor1 = vec4(float32x3_to_oct(s.normal), s.roughness, s.metallic);\nfragColor2 = vec4(s.emissive, s.occlusion);\n}\n#endif", + "vert": "#extension GL_EXT_shader_explicit_arithmetic_types_int32: require\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\nrgba = rgba * 255.0;\nhighp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\nhighp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\nhighp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\nreturn Sign * exp2(Exponent - 23.0) * Mantissa;\n}\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nlayout(location = 0) in vec3 a_position;\nlayout(location = 1) in vec3 a_normal;\nlayout(location = 2) in vec2 a_texCoord;\nlayout(location = 3) in vec4 a_tangent;\n#if CC_USE_SKINNING\nlayout(location = 4) in u32vec4 a_joints;\nlayout(location = 5) in vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nlayout(location = 6) in highp vec4 a_jointAnimInfo;\n#endif\nlayout(location = 7) in vec4 a_matWorld0;\nlayout(location = 8) in vec4 a_matWorld1;\nlayout(location = 9) in vec4 a_matWorld2;\n#if CC_USE_LIGHTMAP\nlayout(location = 10) in vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nlayout(location = 11) in vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nlayout(location = 12) in float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nint getVertexId() {\nreturn gl_VertexIndex;\n}\n#endif\n#if CC_USE_MORPH\nlayout(set = 2, binding = 4) uniform CCMorph {\nvec4 cc_displacementWeights[15];\nvec4 cc_displacementTextureInfo;\n};\nvec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\nfloat pixelIndexF = float(pixelIndex);\nfloat x = mod(pixelIndexF, textureResolution.x);\nfloat y = floor(pixelIndexF / textureResolution.x);\nreturn vec2(x, y);\n}\nvec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\nreturn (vec2(location.x, location.y) + .5) / textureResolution;\n}\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int pixelIndex) {\nivec2 texSize = textureSize(tex, 0);\nreturn texelFetch(tex, ivec2(pixelIndex % texSize.x, pixelIndex / texSize.x), 0);\n}\n#else\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex * 4;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\nreturn vec4(\ndecode32(texture(tex, x)),\ndecode32(texture(tex, y)),\ndecode32(texture(tex, z)),\n1.0\n);\n}\n#endif\nfloat getDisplacementWeight(int index) {\nint quot = index / 4;\nint remainder = index - quot * 4;\nif (remainder == 0) {\nreturn cc_displacementWeights[quot].x;\n} else if (remainder == 1) {\nreturn cc_displacementWeights[quot].y;\n} else if (remainder == 2) {\nreturn cc_displacementWeights[quot].z;\n} else {\nreturn cc_displacementWeights[quot].w;\n}\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\nreturn fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n#else\nvec3 result = vec3(0, 0, 0);\nint nVertices = int(cc_displacementTextureInfo.z);\nfor (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\nresult += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n}\nreturn result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\nlayout(set = 2, binding = 7) uniform sampler2D cc_PositionDisplacements;\nvec3 getPositionDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nlayout(set = 2, binding = 8) uniform sampler2D cc_NormalDisplacements;\nvec3 getNormalDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\nlayout(set = 2, binding = 9) uniform sampler2D cc_TangentDisplacements;\nvec3 getTangentDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n}\n#endif\nvoid applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nint vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nnormal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\ntangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\n#if CC_USE_BAKED_ANIMATION\nlayout(set = 2, binding = 3) uniform CCSkinningTexture {\nhighp vec4 cc_jointTextureInfo;\n};\nlayout(set = 2, binding = 2) uniform CCSkinningAnimation {\nhighp vec4 cc_jointAnimInfo;\n};\nlayout(set = 2, binding = 6) uniform highp sampler2D cc_jointTexture;\nvoid CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n{\n#if USE_INSTANCING\nhighp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n#else\nhighp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n#endif\ninvSize = cc_jointTextureInfo.w;\nhighp float tempY = floor(temp * invSize);\nx = floor(temp - tempY * cc_jointTextureInfo.x);\ny = (tempY + 0.5) * invSize;\n}\n#else\nlayout(set = 2, binding = 3) uniform CCSkinning {\nhighp vec4 cc_joints[30 * 3];\n};\n#endif\n#if CC_USE_BAKED_ANIMATION\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(3.0, i, x, y, invSize);\nvec4 v1 = texture(cc_jointTexture, vec2((x + 0.5) * invSize, y));\nvec4 v2 = texture(cc_jointTexture, vec2((x + 1.5) * invSize, y));\nvec4 v3 = texture(cc_jointTexture, vec2((x + 2.5) * invSize, y));\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#else\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(12.0, i, x, y, invSize);\nvec4 v1 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n);\nvec4 v2 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n);\nvec4 v3 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n);\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\n#else\nmat4 getJointMatrix (float i) {\nint idx = int(i);\nvec4 v1 = cc_joints[idx * 3];\nvec4 v2 = cc_joints[idx * 3 + 1];\nvec4 v3 = cc_joints[idx * 3 + 2];\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\nmat4 skinMatrix () {\nvec4 joints = vec4(a_joints);\nreturn getJointMatrix(joints.x) * a_weights.x\n+ getJointMatrix(joints.y) * a_weights.y\n+ getJointMatrix(joints.z) * a_weights.z\n+ getJointMatrix(joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\nmat4 m = skinMatrix();\nposition = m * position;\n}\nvoid CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nmat4 m = skinMatrix();\nposition = m * position;\nnormal = (m * vec4(normal, 0.0)).xyz;\ntangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n}\n#endif\nvoid CCVertInput(inout StandardVertInput In)\n{\nIn.position = vec4(a_position, 1.0);\nIn.normal = a_normal;\nIn.tangent = a_tangent;\n#if CC_USE_MORPH\napplyMorph(In.position, In.normal, In.tangent);\n#endif\n#if CC_USE_SKINNING\nCCSkin(In.position, In.normal, In.tangent);\n#endif\n}\nlayout(set = 0, binding = 0) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(set = 0, binding = 1) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\n#if !USE_INSTANCING\n#if USE_BATCHING\nlayout(set = 2, binding = 0) uniform CCLocalBatched {\nhighp mat4 cc_matWorlds[10];\n};\n#else\nlayout(set = 2, binding = 0) uniform CCLocal {\nhighp mat4 cc_matWorld;\nhighp mat4 cc_matWorldIT;\nhighp vec4 cc_lightingMapUVParam;\nhighp vec4 cc_localShadowBias;\n};\n#endif\n#endif\nvoid CCGetWorldMatrixFull(out mat4 matWorld, out mat4 matWorldIT)\n{\n#if USE_INSTANCING\nmatWorld = mat4(\nvec4(a_matWorld0.xyz, 0.0),\nvec4(a_matWorld1.xyz, 0.0),\nvec4(a_matWorld2.xyz, 0.0),\nvec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)\n);\nmatWorldIT = matWorld;\n#elif USE_BATCHING\nmatWorld = cc_matWorlds[int(a_dyn_batch_id)];\nmatWorldIT = matWorld;\n#else\nmatWorld = cc_matWorld;\nmatWorldIT = cc_matWorldIT;\n#endif\n}\nlayout(set = 1, binding = 0) uniform Constants {\nvec4 tilingOffset;\nvec4 albedo;\nvec4 albedoScaleAndCutoff;\nvec4 pbrParams;\nvec4 emissive;\nvec4 emissiveScaleParam;\n};\nfloat LinearFog(vec4 pos) {\nvec4 wPos = pos;\nfloat cam_dis = distance(cc_cameraPos, wPos);\nfloat fogStart = cc_fogBase.x;\nfloat fogEnd = cc_fogBase.y;\nreturn clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * fogDensity);\nreturn f;\n}\nfloat ExpSquaredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\nreturn f;\n}\nfloat LayeredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat _FogTop = cc_fogAdd.x;\nfloat _FogRange = cc_fogAdd.y;\nvec3 camWorldProj = cc_cameraPos.xyz;\ncamWorldProj.y = 0.;\nvec3 worldPosProj = wPos.xyz;\nworldPosProj.y = 0.;\nfloat fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\nfloat fDeltaY, fDensityIntegral;\nif (cc_cameraPos.y > _FogTop) {\nif (wPos.y < _FogTop) {\nfDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\nfDensityIntegral = fDeltaY * fDeltaY * 0.5;\n} else {\nfDeltaY = 0.;\nfDensityIntegral = 0.;\n}\n} else {\nif (wPos.y < _FogTop) {\nfloat fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfloat fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\nfDeltaY = abs(fDeltaA - fDeltaB);\nfDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n} else {\nfDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n}\n}\nfloat fDensity;\nif (fDeltaY != 0.) {\nfDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n} else {\nfDensity = 0.;\n}\nfloat f = exp(-fDensity);\nreturn f;\n}\nvoid CC_TRANSFER_FOG_BASE(vec4 pos, out float factor)\n{\n#if CC_USE_FOG == 0\nfactor = LinearFog(pos);\n#elif CC_USE_FOG == 1\nfactor = ExpFog(pos);\n#elif CC_USE_FOG == 2\nfactor = ExpSquaredFog(pos);\n#elif CC_USE_FOG == 3\nfactor = LayeredFog(pos);\n#else\nfactor = 1.0;\n#endif\n}\n#if !CC_USE_ACCURATE_FOG\nlayout(location = 0) out float v_fog_factor;\n#endif\nvoid CC_TRANSFER_FOG(vec4 pos) {\n#if !CC_USE_ACCURATE_FOG\nCC_TRANSFER_FOG_BASE(pos, v_fog_factor);\n#endif\n}\nlayout(location = 1) out highp vec4 v_shadowPos;\nlayout(set = 0, binding = 2) uniform CCShadow {\nhighp mat4 cc_matLightPlaneProj;\nhighp mat4 cc_matLightView;\nhighp mat4 cc_matLightViewProj;\nhighp vec4 cc_shadowInvProjDepthInfo;\nhighp vec4 cc_shadowProjDepthInfo;\nhighp vec4 cc_shadowProjInfo;\nmediump vec4 cc_shadowNFLSInfo;\nmediump vec4 cc_shadowWHPBInfo;\nmediump vec4 cc_shadowLPNNInfo;\nlowp vec4 cc_shadowColor;\nmediump vec4 cc_planarNDInfo;\n};\n#if CC_RECEIVE_SHADOW\nlayout(set = 0, binding = 3) uniform highp sampler2D cc_shadowMap;\nlayout(set = 0, binding = 5) uniform highp sampler2D cc_spotLightingMap;\n#endif\n#if CC_RECEIVE_SHADOW\nvec2 CCGetShadowBias()\n{\n#if USE_INSTANCING\nreturn vec2(a_localShadowBias.x + cc_shadowWHPBInfo.w, a_localShadowBias.y + cc_shadowLPNNInfo.z);\n#elif !USE_BATCHING\nreturn vec2(cc_localShadowBias.x + cc_shadowWHPBInfo.w, cc_localShadowBias.y + cc_shadowLPNNInfo.z);\n#else\nreturn vec2(cc_shadowWHPBInfo.w, cc_shadowLPNNInfo.z);\n#endif\n}\n#endif\n#if USE_VERTEX_COLOR\nlayout(location = 14) in vec4 a_color;\nlayout(location = 2) out lowp vec4 v_color;\n#endif\nlayout(location = 3) out vec3 v_position;\nlayout(location = 4) out mediump vec3 v_normal;\nlayout(location = 5) out vec2 v_uv;\n#if HAS_SECOND_UV\nlayout(location = 6) out mediump vec2 v_uv1;\n#endif\n#if CC_RECEIVE_SHADOW\nlayout(location = 7) out mediump vec2 v_shadowBias;\n#endif\n#if USE_NORMAL_MAP\nlayout(location = 8) out mediump vec4 v_tangent;\n#endif\n#if HAS_SECOND_UV || CC_USE_LIGHTMAP\nlayout(location = 15) in vec2 a_texCoord1;\n#endif\n#if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\nlayout(location = 9) out vec3 v_luv;\nvoid CCLightingMapCaclUV()\n{\n#if !USE_INSTANCING\nv_luv.xy = cc_lightingMapUVParam.xy + a_texCoord1 * cc_lightingMapUVParam.z;\nv_luv.z = cc_lightingMapUVParam.w;\n#else\nv_luv.xy = a_lightingMapUVParam.xy + a_texCoord1 * a_lightingMapUVParam.z;\nv_luv.z = a_lightingMapUVParam.w;\n#endif\n}\n#endif\nvoid main () {\nStandardVertInput In;\nCCVertInput(In);\nmat4 matWorld, matWorldIT;\nCCGetWorldMatrixFull(matWorld, matWorldIT);\nvec4 pos = matWorld * In.position;\nv_position = pos.xyz;\nv_normal = normalize((matWorldIT * vec4(In.normal, 0.0)).xyz);\n#if CC_RECEIVE_SHADOW\nv_shadowBias = CCGetShadowBias();\n#endif\n#if USE_TWOSIDE\nvec3 viewDirect = normalize(cc_cameraPos.xyz - v_position);\nv_normal *= dot(v_normal, viewDirect) < 0.0 ? -1.0 : 1.0;\n#endif\n#if USE_NORMAL_MAP\nv_tangent.xyz = normalize((matWorld * vec4(In.tangent.xyz, 0.0)).xyz);\nv_tangent.w = In.tangent.w;\n#endif\nv_uv = a_texCoord * tilingOffset.xy + tilingOffset.zw;\n#if SAMPLE_FROM_RT\nv_uv = cc_cameraPos.w > 1.0 ? vec2(v_uv.x, 1.0 - v_uv.y) : v_uv;\n#endif\n#if HAS_SECOND_UV\nv_uv1 = a_texCoord1 * tilingOffset.xy + tilingOffset.zw;\n#if SAMPLE_FROM_RT\nv_uv1 = cc_cameraPos.w > 1.0 ? vec2(v_uv1.x, 1.0 - v_uv1.y) : v_uv1;\n#endif\n#endif\n#if USE_VERTEX_COLOR\nv_color = a_color;\n#endif\nCC_TRANSFER_FOG(pos);\nv_shadowPos = cc_matLightViewProj * pos;\n#if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\nCCLightingMapCaclUV();\n#endif\ngl_Position = cc_matProj * (cc_matView * matWorld) * In.position;\n}", + "frag": "\nprecision highp float;\nlayout(set = 0, binding = 0) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(set = 0, binding = 1) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\nlayout(set = 1, binding = 0) uniform Constants {\nvec4 tilingOffset;\nvec4 albedo;\nvec4 albedoScaleAndCutoff;\nvec4 pbrParams;\nvec4 emissive;\nvec4 emissiveScaleParam;\n};\nfloat LinearFog(vec4 pos) {\nvec4 wPos = pos;\nfloat cam_dis = distance(cc_cameraPos, wPos);\nfloat fogStart = cc_fogBase.x;\nfloat fogEnd = cc_fogBase.y;\nreturn clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * fogDensity);\nreturn f;\n}\nfloat ExpSquaredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\nreturn f;\n}\nfloat LayeredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat _FogTop = cc_fogAdd.x;\nfloat _FogRange = cc_fogAdd.y;\nvec3 camWorldProj = cc_cameraPos.xyz;\ncamWorldProj.y = 0.;\nvec3 worldPosProj = wPos.xyz;\nworldPosProj.y = 0.;\nfloat fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\nfloat fDeltaY, fDensityIntegral;\nif (cc_cameraPos.y > _FogTop) {\nif (wPos.y < _FogTop) {\nfDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\nfDensityIntegral = fDeltaY * fDeltaY * 0.5;\n} else {\nfDeltaY = 0.;\nfDensityIntegral = 0.;\n}\n} else {\nif (wPos.y < _FogTop) {\nfloat fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfloat fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\nfDeltaY = abs(fDeltaA - fDeltaB);\nfDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n} else {\nfDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n}\n}\nfloat fDensity;\nif (fDeltaY != 0.) {\nfDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n} else {\nfDensity = 0.;\n}\nfloat f = exp(-fDensity);\nreturn f;\n}\nvoid CC_TRANSFER_FOG_BASE(vec4 pos, out float factor)\n{\n#if CC_USE_FOG == 0\nfactor = LinearFog(pos);\n#elif CC_USE_FOG == 1\nfactor = ExpFog(pos);\n#elif CC_USE_FOG == 2\nfactor = ExpSquaredFog(pos);\n#elif CC_USE_FOG == 3\nfactor = LayeredFog(pos);\n#else\nfactor = 1.0;\n#endif\n}\nvoid CC_APPLY_FOG_BASE(inout vec4 color, float factor) {\ncolor = vec4(mix(cc_fogColor.rgb, color.rgb, factor), color.a);\n}\n#if !CC_USE_ACCURATE_FOG\nlayout(location = 0) in float v_fog_factor;\n#endif\nvoid CC_APPLY_FOG(inout vec4 color) {\n#if !CC_USE_ACCURATE_FOG\nCC_APPLY_FOG_BASE(color, v_fog_factor);\n#endif\n}\nvoid CC_APPLY_FOG(inout vec4 color, vec3 worldPos) {\n#if CC_USE_ACCURATE_FOG\nfloat factor;\nCC_TRANSFER_FOG_BASE(vec4(worldPos, 1.0), factor);\n#else\nfloat factor = v_fog_factor;\n#endif\nCC_APPLY_FOG_BASE(color, factor);\n}\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nvec3 SRGBToLinear (vec3 gamma) {\nreturn gamma * gamma;\n}\nlayout(set = 0, binding = 2) uniform CCShadow {\nhighp mat4 cc_matLightPlaneProj;\nhighp mat4 cc_matLightView;\nhighp mat4 cc_matLightViewProj;\nhighp vec4 cc_shadowInvProjDepthInfo;\nhighp vec4 cc_shadowProjDepthInfo;\nhighp vec4 cc_shadowProjInfo;\nmediump vec4 cc_shadowNFLSInfo;\nmediump vec4 cc_shadowWHPBInfo;\nmediump vec4 cc_shadowLPNNInfo;\nlowp vec4 cc_shadowColor;\nmediump vec4 cc_planarNDInfo;\n};\nhighp float unpackHighpData (float mainPart, float modPart) {\nhighp float data = mainPart;\nreturn data + modPart;\n}\nvoid packHighpData (out float mainPart, out float modPart, highp float data) {\nmainPart = fract(data);\nmodPart = data - mainPart;\n}\nhighp float unpackHighpData (float mainPart, float modPart, const float modValue) {\nhighp float data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nvoid packHighpData (out float mainPart, out float modPart, highp float data, const float modValue) {\nhighp float divide = data / modValue;\nmainPart = floor(divide);\nmodPart = (data - mainPart * modValue) / modValue;\n}\nhighp vec2 unpackHighpData (vec2 mainPart, vec2 modPart) {\nhighp vec2 data = mainPart;\nreturn data + modPart;\n}\nvoid packHighpData (out vec2 mainPart, out vec2 modPart, highp vec2 data) {\nmainPart = fract(data);\nmodPart = data - mainPart;\n}\nhighp vec2 unpackHighpData (vec2 mainPart, vec2 modPart, const float modValue) {\nhighp vec2 data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nvoid packHighpData (out vec2 mainPart, out vec2 modPart, highp vec2 data, const float modValue) {\nhighp vec2 divide = data / modValue;\nmainPart = floor(divide);\nmodPart = (data - mainPart * modValue) / modValue;\n}\nhighp vec3 unpackHighpData (vec3 mainPart, vec3 modPart) {\nhighp vec3 data = mainPart;\nreturn data + modPart;\n}\nvoid packHighpData (out vec3 mainPart, out vec3 modPart, highp vec3 data) {\nmainPart = fract(data);\nmodPart = data - mainPart;\n}\nhighp vec3 unpackHighpData (vec3 mainPart, vec3 modPart, const float modValue) {\nhighp vec3 data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nvoid packHighpData (out vec3 mainPart, out vec3 modPart, highp vec3 data, const float modValue) {\nhighp vec3 divide = data / modValue;\nmainPart = floor(divide);\nmodPart = (data - mainPart * modValue) / modValue;\n}\nhighp vec4 unpackHighpData (vec4 mainPart, vec4 modPart) {\nhighp vec4 data = mainPart;\nreturn data + modPart;\n}\nvoid packHighpData (out vec4 mainPart, out vec4 modPart, highp vec4 data) {\nmainPart = fract(data);\nmodPart = data - mainPart;\n}\nhighp vec4 unpackHighpData (vec4 mainPart, vec4 modPart, const float modValue) {\nhighp vec4 data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nvoid packHighpData (out vec4 mainPart, out vec4 modPart, highp vec4 data, const float modValue) {\nhighp vec4 divide = data / modValue;\nmainPart = floor(divide);\nmodPart = (data - mainPart * modValue) / modValue;\n}\nlayout(set = 2, binding = 0) uniform CCLocal {\nhighp mat4 cc_matWorld;\nhighp mat4 cc_matWorldIT;\nhighp vec4 cc_lightingMapUVParam;\nhighp vec4 cc_localShadowBias;\n};\nfloat CCGetLinearDepthFromViewSpace(vec3 viewPos) {\nfloat dist = length(viewPos);\nreturn (dist - cc_shadowNFLSInfo.x) / (cc_shadowNFLSInfo.y - cc_shadowNFLSInfo.x);\n}\nfloat CCGetLinearDepth(vec3 worldPos) {\nvec4 viewStartPos = cc_matLightView * vec4(worldPos.xyz, 1.0);\nreturn CCGetLinearDepthFromViewSpace(viewStartPos.xyz);\n}\n#if CC_RECEIVE_SHADOW\nlayout(set = 0, binding = 3) uniform highp sampler2D cc_shadowMap;\nlayout(set = 0, binding = 5) uniform highp sampler2D cc_spotLightingMap;\nvec4 ApplyShadowDepthBias_FaceNormal(vec4 shadowPos, vec3 worldNormal, float normalBias)\n{\nvec4 newShadowPos = shadowPos;\nif(normalBias > EPSILON_LOWP)\n{\nvec4 viewNormal = cc_matLightView * vec4(worldNormal, 0.0);\nif(viewNormal.z < 0.1)\nnewShadowPos.xy += viewNormal.xy * cc_shadowProjInfo.xy * normalBias * clamp(viewNormal.z, 0.001, 0.1);\n}\nreturn newShadowPos;\n}\nvec4 ApplyShadowDepthBias_Perspective(vec4 shadowPos, float viewspaceDepthBias)\n{\nvec3 viewSpacePos;\nviewSpacePos.xy = shadowPos.xy * cc_shadowProjInfo.zw;\nviewSpacePos.z = shadowPos.z * cc_shadowInvProjDepthInfo.x + shadowPos.w * cc_shadowInvProjDepthInfo.y;\nviewSpacePos.xyz += cc_shadowProjDepthInfo.z * normalize(viewSpacePos.xyz) * viewspaceDepthBias;\nvec4 clipSpacePos;\nclipSpacePos.xy = viewSpacePos.xy * cc_shadowProjInfo.xy;\nclipSpacePos.zw = viewSpacePos.z * cc_shadowProjDepthInfo.xz + vec2(cc_shadowProjDepthInfo.y, 0.0);\nif (cc_shadowNFLSInfo.z > EPSILON) {\nclipSpacePos.z = CCGetLinearDepthFromViewSpace(viewSpacePos.xyz);\nclipSpacePos.z = (clipSpacePos.z * 2.0 - 1.0) * clipSpacePos.w;\n}\nreturn clipSpacePos;\n}\nvec4 ApplyShadowDepthBias_Orthographic(vec4 shadowPos, float viewspaceDepthBias)\n{\nfloat coeffA = cc_shadowProjDepthInfo.x;\nfloat coeffB = cc_shadowProjDepthInfo.y;\nfloat viewSpacePos_z = (shadowPos.z - coeffB) / coeffA;\nviewSpacePos_z += viewspaceDepthBias;\nvec4 result = shadowPos;\nresult.z = viewSpacePos_z * coeffA + coeffB;\nreturn result;\n}\nfloat CCGetShadowFactorHard (vec4 shadowPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Orthographic(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat shadow = 0.0;\nfloat closestDepth = 0.0;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nclosestDepth = dot(texture(cc_shadowMap, clipPos.xy), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0));\n} else {\nclosestDepth = texture(cc_shadowMap, clipPos.xy).x;\n}\nshadow = step(clipPos.z, closestDepth);\nreturn shadow;\n}\nfloat CCGetShadowFactorSoft (vec4 shadowPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Orthographic(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat offsetDepth = clipPos.z;\nvec2 mapSize = cc_shadowWHPBInfo.xy;\nvec2 oneTap = 1.0 / mapSize;\nvec2 clipPos_offset = clipPos.xy + oneTap;\nfloat block0, block1, block2, block3;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos.y)).x);\nblock1 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset.x, clipPos.y)).x);\nblock2 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset.y)).x);\nblock3 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset.x, clipPos_offset.y)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * mapSize.x;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block2, block3, coefX);\nfloat coefY = mod(clipPos.y, oneTap.y) * mapSize.y;\nreturn mix(resultX, resultY, coefY);\n}\nfloat CCGetShadowFactorSoft2X (vec4 shadowPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Orthographic(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat offsetDepth = clipPos.z;\nvec2 mapSize = cc_shadowWHPBInfo.xy;\nvec2 oneTap = 1.0 / mapSize;\nfloat clipPos_offset_L = clipPos.x - oneTap.x;\nfloat clipPos_offset_R = clipPos.x + oneTap.x;\nfloat clipPos_offset_U = clipPos.y - oneTap.y;\nfloat clipPos_offset_D = clipPos.y + oneTap.y;\nfloat block0, block1, block2, block3, block4, block5, block6, block7, block8;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock4 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock5 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock6 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock7 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock8 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_U)).x);\nblock1 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset_U)).x);\nblock2 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_U)).x);\nblock3 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos.y)).x);\nblock4 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos.y)).x);\nblock5 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos.y)).x);\nblock6 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_D)).x);\nblock7 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset_D)).x);\nblock8 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_D)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * mapSize.x;\nfloat coefY = mod(clipPos.y, oneTap.y) * mapSize.y;\nfloat shadow = 0.0;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block3, block4, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block1, block2, coefX);\nresultY = mix(block4, block5, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block3, block4, coefX);\nresultY = mix(block6, block7, coefX);\nshadow += mix(resultX, resultY, coefY);\nresultX = mix(block4, block5, coefX);\nresultY = mix(block7, block8, coefX);\nshadow += mix(resultX, resultY, coefY);\nreturn shadow * 0.25;\n}\nfloat CCGetSpotLightShadowFactorHard (vec4 shadowPos, vec3 worldPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Perspective(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat shadow = 0.0;\nfloat closestDepth = 0.0;\nfloat depth = clipPos.z;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nclosestDepth = dot(texture(cc_spotLightingMap, clipPos.xy), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0));\n} else {\nclosestDepth = texture(cc_spotLightingMap, clipPos.xy).x;\n}\nshadow = step(depth, closestDepth);\nreturn shadow;\n}\nfloat CCGetSpotLightShadowFactorSoft (vec4 shadowPos, vec3 worldPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Perspective(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat depth = 0.0;\nif (cc_shadowNFLSInfo.z > EPSILON) {\ndepth = CCGetLinearDepth(worldPos);\n} else {\ndepth = clipPos.z;\n}\nvec2 oneTap = 1.0 / cc_shadowWHPBInfo.xy;\nvec2 clipPos_offset = clipPos.xy + oneTap;\nfloat block0, block1, block2, block3;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)).x);\nblock1 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos.y)).x);\nblock2 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset.y)).x);\nblock3 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos_offset.y)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * cc_shadowWHPBInfo.x;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block2, block3, coefX);\nfloat coefY = mod(clipPos.y, oneTap.y) * cc_shadowWHPBInfo.y;\nreturn mix(resultX, resultY, coefY);\n}\nfloat CCGetSpotLightShadowFactorSoft2X (vec4 shadowPos, vec3 worldPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Perspective(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat depth = 0.0;\nif (cc_shadowNFLSInfo.z > EPSILON) {\ndepth = CCGetLinearDepth(worldPos);\n} else {\ndepth = clipPos.z;\n}\nvec2 mapSize = cc_shadowWHPBInfo.xy;\nvec2 oneTap = 1.0 / mapSize;\nfloat clipPos_offset_L = clipPos.x - oneTap.x;\nfloat clipPos_offset_R = clipPos.x + oneTap.x;\nfloat clipPos_offset_U = clipPos.y - oneTap.y;\nfloat clipPos_offset_D = clipPos.y + oneTap.y;\nfloat block0, block1, block2, block3, block4, block5, block6, block7, block8;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock4 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock5 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock6 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock7 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock8 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_U)).x);\nblock1 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_U)).x);\nblock2 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_U)).x);\nblock3 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos.y)).x);\nblock4 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)).x);\nblock5 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos.y)).x);\nblock6 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_D)).x);\nblock7 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_D)).x);\nblock8 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_D)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * mapSize.x;\nfloat coefY = mod(clipPos.y, oneTap.y) * mapSize.y;\nfloat shadow = 0.0;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block3, block4, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block1, block2, coefX);\nresultY = mix(block4, block5, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block3, block4, coefX);\nresultY = mix(block6, block7, coefX);\nshadow += mix(resultX, resultY, coefY);\nresultX = mix(block4, block5, coefX);\nresultY = mix(block7, block8, coefX);\nshadow += mix(resultX, resultY, coefY);\nreturn shadow * 0.25;\n}\nfloat CCSpotShadowFactorBase(vec4 shadowPos, vec3 worldPos, vec2 shadowBias)\n{\nfloat pcf = cc_shadowWHPBInfo.z;\nif (pcf > 1.9) {\nreturn CCGetSpotLightShadowFactorSoft2X(shadowPos, worldPos, shadowBias.x);\n}else if (pcf > 0.9) {\nreturn CCGetSpotLightShadowFactorSoft(shadowPos, worldPos, shadowBias.x);\n}else {\nreturn CCGetSpotLightShadowFactorHard(shadowPos, worldPos, shadowBias.x);\n}\n}\nfloat CCShadowFactorBase(vec4 shadowPos, vec3 N, vec2 shadowBias)\n{\nfloat realtimeShadow = 1.0;\nvec4 pos = ApplyShadowDepthBias_FaceNormal(shadowPos, N, shadowBias.y);\nfloat pcf = cc_shadowWHPBInfo.z;\nif (pcf > 1.9) {\nrealtimeShadow = CCGetShadowFactorSoft2X(pos, shadowBias.x);\n}else if (pcf > 0.9) {\nrealtimeShadow = CCGetShadowFactorSoft(pos, shadowBias.x);\n}else {\nrealtimeShadow = CCGetShadowFactorHard(pos, shadowBias.x);\n}\nreturn mix(realtimeShadow, 1.0, cc_shadowNFLSInfo.w);\n}\n#endif\n#if CC_USE_IBL\nlayout(set = 0, binding = 4) uniform samplerCube cc_environment;\nvec4 fragTextureLod (sampler2D tex, vec2 coord, float lod) {\nreturn textureLod(tex, coord, lod);\n}\nvec4 fragTextureLod (samplerCube tex, vec3 coord, float lod) {\nreturn textureLod(tex, coord, lod);\n}\nvec3 unpackRGBE (vec4 rgbe) {\nreturn rgbe.rgb * pow(1.1, rgbe.a * 255.0 - 128.0);\n}\n#if CC_USE_DIFFUSEMAP\nlayout(set = 0, binding = 6) uniform samplerCube cc_diffuseMap;\n#endif\n#endif\nfloat GGXMobile (float roughness, float NoH, vec3 H, vec3 N) {\nvec3 NxH = cross(N, H);\nfloat OneMinusNoHSqr = dot(NxH, NxH);\nfloat a = roughness * roughness;\nfloat n = NoH * a;\nfloat p = a / (OneMinusNoHSqr + n * n);\nreturn p * p;\n}\nfloat CalcSpecular (float roughness, float NoH, vec3 H, vec3 N) {\nreturn (roughness * 0.25 + 0.25) * GGXMobile(roughness, NoH, H, N);\n}\nvec3 BRDFApprox (vec3 specular, float roughness, float NoV) {\nconst vec4 c0 = vec4(-1.0, -0.0275, -0.572, 0.022);\nconst vec4 c1 = vec4(1.0, 0.0425, 1.04, -0.04);\nvec4 r = roughness * c0 + c1;\nfloat a004 = min(r.x * r.x, exp2(-9.28 * NoV)) * r.x + r.y;\nvec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;\nAB.y *= clamp(50.0 * specular.g, 0.0, 1.0);\nreturn specular * AB.x + AB.y;\n}\n#if USE_REFLECTION_DENOISE\nvec3 GetEnvReflectionWithMipFiltering(vec3 R, float roughness, float mipCount, float denoiseIntensity) {\n#if CC_USE_IBL\nfloat mip = roughness * mipCount;\nfloat delta = (dot(dFdx(R), dFdy(R))) * 1000.0;\nfloat mipBias = mix(0.0, 5.0, clamp(delta, 0.0, 1.0));\nvec4 biased = fragTextureLod(cc_environment, R, mip + mipBias);\nvec4 filtered = texture(cc_environment, R);\n#if CC_USE_IBL == 2\nbiased.rgb = unpackRGBE(biased);\nfiltered.rgb = unpackRGBE(filtered);\n#else\nbiased.rgb = SRGBToLinear(biased.rgb);\nfiltered.rgb = SRGBToLinear(filtered.rgb);\n#endif\nreturn mix(biased.rgb, filtered.rgb, denoiseIntensity);\n#else\nreturn vec3(0.0, 0.0, 0.0);\n#endif\n}\n#endif\nstruct StandardSurface {\nvec4 albedo;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nvec3 position, position_fract_part;\n#else\nvec3 position;\n#endif\nvec3 normal;\nvec3 emissive;\nvec3 lightmap;\nfloat lightmap_test;\nfloat roughness;\nfloat metallic;\nfloat occlusion;\nfloat specularIntensity;\n#if CC_RECEIVE_SHADOW\nvec2 shadowBias;\n#endif\n};\nvec4 CCStandardShadingBase (StandardSurface s, vec4 shadowPos) {\nvec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\nvec3 specular = mix(vec3(0.08 * s.specularIntensity), s.albedo.rgb, s.metallic);\nvec3 position;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nposition = unpackHighpData(s.position, s.position_fract_part);\n#else\nposition = s.position;\n#endif\nvec3 N = normalize(s.normal);\nvec3 V = normalize(cc_cameraPos.xyz - position);\nfloat NV = max(abs(dot(N, V)), 0.0);\nspecular = BRDFApprox(specular, s.roughness, NV);\nvec3 L = normalize(-cc_mainLitDir.xyz);\nvec3 H = normalize(L + V);\nfloat NH = max(dot(N, H), 0.0);\nfloat NL = max(dot(N, L), 0.0);\nvec3 finalColor = NL * cc_mainLitColor.rgb * cc_mainLitColor.w;\nvec3 diffuseContrib = diffuse / PI;\nvec3 specularContrib = specular * CalcSpecular(s.roughness, NH, H, N);\nvec3 dirlightContrib = (diffuseContrib + specularContrib);\nfloat shadow = 1.0;\n#if CC_RECEIVE_SHADOW\nif (NL > 0.0 && cc_mainLitDir.w > 0.0) {\nshadow = CCShadowFactorBase(shadowPos, N, s.shadowBias);\n}\n#endif\ndirlightContrib *= shadow;\nfinalColor *= dirlightContrib;\n#if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\nif (s.lightmap_test > EPSILON_LOWP) {\nfinalColor = diffuse * s.lightmap.rgb * shadow;\n}\n#endif\nfloat fAmb = 0.5 - N.y * 0.5;\nvec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb);\n#if CC_USE_IBL\n#if CC_USE_DIFFUSEMAP\nvec4 diffuseMap = texture(cc_diffuseMap, N);\n#if CC_USE_DIFFUSEMAP == 2\nambDiff = unpackRGBE(diffuseMap);\n#else\nambDiff = SRGBToLinear(diffuseMap.rgb);\n#endif\n#endif\nvec3 R = normalize(reflect(-V, N));\n#if USE_REFLECTION_DENOISE\nvec3 env = GetEnvReflectionWithMipFiltering(R, s.roughness, cc_ambientGround.w, 0.6);\n#else\nvec4 envmap = fragTextureLod(cc_environment, R, s.roughness * cc_ambientGround.w);\n#if CC_USE_IBL == 2\nvec3 env = unpackRGBE(envmap);\n#else\nvec3 env = SRGBToLinear(envmap.rgb);\n#endif\n#endif\nfinalColor += env * cc_ambientSky.w * specular * s.occlusion;\n#endif\nfinalColor += ambDiff.rgb * cc_ambientSky.w * diffuse * s.occlusion;\nfinalColor += s.emissive;\nreturn vec4(finalColor, s.albedo.a);\n}\nvec3 ACESToneMap (vec3 color) {\ncolor = min(color, vec3(8.0));\nconst float A = 2.51;\nconst float B = 0.03;\nconst float C = 2.43;\nconst float D = 0.59;\nconst float E = 0.14;\nreturn (color * (A * color + B)) / (color * (C * color + D) + E);\n}\nvec4 CCFragOutput (vec4 color) {\n#if CC_USE_HDR\ncolor.rgb = ACESToneMap(color.rgb);\n#endif\ncolor.rgb = sqrt(color.rgb);\nreturn color;\n}\nlayout(location = 1) in highp vec4 v_shadowPos;\n#if CC_RECEIVE_SHADOW\n#endif\n#if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\nlayout(location = 9) in vec3 v_luv;\nlayout(set = 2, binding = 10) uniform sampler2D cc_lightingMap;\n#endif\nlayout(location = 3) in vec3 v_position;\nlayout(location = 5) in vec2 v_uv;\n#if HAS_SECOND_UV\nlayout(location = 6) in mediump vec2 v_uv1;\n#endif\nlayout(location = 4) in mediump vec3 v_normal;\n#if CC_RECEIVE_SHADOW\nlayout(location = 7) in mediump vec2 v_shadowBias;\n#endif\n#if USE_VERTEX_COLOR\nlayout(location = 2) in lowp vec4 v_color;\n#endif\n#if USE_ALBEDO_MAP\nlayout(set = 1, binding = 1) uniform sampler2D albedoMap;\n#endif\n#if USE_NORMAL_MAP\nlayout(location = 8) in mediump vec4 v_tangent;\nlayout(set = 1, binding = 2) uniform sampler2D normalMap;\n#endif\n#if USE_PBR_MAP\nlayout(set = 1, binding = 3) uniform sampler2D pbrMap;\n#endif\n#if USE_METALLIC_ROUGHNESS_MAP\nlayout(set = 1, binding = 4) uniform sampler2D metallicRoughnessMap;\n#endif\n#if USE_OCCLUSION_MAP\nlayout(set = 1, binding = 5) uniform sampler2D occlusionMap;\n#endif\n#if USE_EMISSIVE_MAP\nlayout(set = 1, binding = 6) uniform sampler2D emissiveMap;\n#endif\n#if USE_ALPHA_TEST\n#endif\nvoid surf (out StandardSurface s) {\nvec4 baseColor = albedo;\n#if USE_VERTEX_COLOR\nbaseColor.rgb *= SRGBToLinear(v_color.rgb);\nbaseColor.a *= v_color.a;\n#endif\n#if USE_ALBEDO_MAP\nvec4 texColor = texture(albedoMap, ALBEDO_UV);\ntexColor.rgb = SRGBToLinear(texColor.rgb);\nbaseColor *= texColor;\n#endif\ns.albedo = baseColor;\ns.albedo.rgb *= albedoScaleAndCutoff.xyz;\n#if USE_ALPHA_TEST\nif (s.albedo.ALPHA_TEST_CHANNEL < albedoScaleAndCutoff.w) discard;\n#endif\n#if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\nvec4 lightColor = texture(cc_lightingMap, v_luv.xy);\ns.lightmap = lightColor.xyz * v_luv.z;\ns.lightmap_test = v_luv.z;\n#endif\ns.normal = v_normal;\n#if CC_RECEIVE_SHADOW\ns.shadowBias = v_shadowBias;\n#endif\n#if USE_NORMAL_MAP\nvec3 nmmp = texture(normalMap, NORMAL_UV).xyz - vec3(0.5);\nvec3 bitangent = cross(v_normal, v_tangent.xyz) * v_tangent.w;\ns.normal =\n(nmmp.x * emissiveScaleParam.w) * normalize(v_tangent.xyz) +\n(nmmp.y * emissiveScaleParam.w) * normalize(bitangent) +\nnmmp.z * normalize(s.normal);\n#endif\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\npackHighpData(s.position, s.position_fract_part, v_position);\n#else\ns.position = v_position;\n#endif\nvec4 pbr = pbrParams;\n#if USE_PBR_MAP\nvec4 res = texture(pbrMap, PBR_UV);\npbr.x *= res.r;\npbr.y *= res.g;\npbr.z *= res.b;\npbr.w *= res.a;\n#endif\n#if USE_METALLIC_ROUGHNESS_MAP\nvec4 metallicRoughness = texture(metallicRoughnessMap, PBR_UV);\npbr.z *= metallicRoughness.b;\npbr.y *= metallicRoughness.g;\n#endif\n#if USE_OCCLUSION_MAP\npbr.x *= texture(occlusionMap, PBR_UV).r;\n#endif\ns.occlusion = pbr.x;\ns.roughness = pbr.y;\ns.specularIntensity = 0.5;\ns.metallic = pbr.z;\ns.emissive = emissive.rgb * emissiveScaleParam.xyz;\n#if USE_EMISSIVE_MAP\ns.emissive *= SRGBToLinear(texture(emissiveMap, EMISSIVE_UV).rgb);\n#endif\n}\n#if CC_FORWARD_ADD\n#if CC_PIPELINE_TYPE == 0\n#define LIGHTS_PER_PASS 1\n#else\n#define LIGHTS_PER_PASS 10\n#endif\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 0\nlayout(set = 2, binding = 1) uniform CCForwardLight {\nhighp vec4 cc_lightPos[LIGHTS_PER_PASS];\nvec4 cc_lightColor[LIGHTS_PER_PASS];\nvec4 cc_lightSizeRangeAngle[LIGHTS_PER_PASS];\nvec4 cc_lightDir[LIGHTS_PER_PASS];\n};\n#endif\nfloat SmoothDistAtt (float distSqr, float invSqrAttRadius) {\nfloat factor = distSqr * invSqrAttRadius;\nfloat smoothFactor = clamp(1.0 - factor * factor, 0.0, 1.0);\nreturn smoothFactor * smoothFactor;\n}\nfloat GetDistAtt (float distSqr, float invSqrAttRadius) {\nfloat attenuation = 1.0 / max(distSqr, 0.01*0.01);\nattenuation *= SmoothDistAtt(distSqr , invSqrAttRadius);\nreturn attenuation;\n}\nfloat GetAngleAtt (vec3 L, vec3 litDir, float litAngleScale, float litAngleOffset) {\nfloat cd = dot(litDir, L);\nfloat attenuation = clamp(cd * litAngleScale + litAngleOffset, 0.0, 1.0);\nreturn (attenuation * attenuation);\n}\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 0\nvec4 CCStandardShadingAdditive (StandardSurface s, vec4 shadowPos) {\nvec3 position;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nposition = unpackHighpData(s.position, s.position_fract_part);\n#else\nposition = s.position;\n#endif\nvec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\nvec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\nvec3 diffuseContrib = diffuse / PI;\nvec3 N = normalize(s.normal);\nvec3 V = normalize(cc_cameraPos.xyz - position);\nfloat NV = max(abs(dot(N, V)), 0.0);\nspecular = BRDFApprox(specular, s.roughness, NV);\nvec3 finalColor = vec3(0.0);\nint numLights = CC_PIPELINE_TYPE == 0 ? LIGHTS_PER_PASS : int(cc_lightDir[0].w);\nfor (int i = 0; i < LIGHTS_PER_PASS; i++) {\nif (i >= numLights) break;\nvec3 SLU = cc_lightPos[i].xyz - position;\nvec3 SL = normalize(SLU);\nvec3 SH = normalize(SL + V);\nfloat SNL = max(dot(N, SL), 0.0);\nfloat SNH = max(dot(N, SH), 0.0);\nfloat distSqr = dot(SLU, SLU);\nfloat litRadius = cc_lightSizeRangeAngle[i].x;\nfloat litRadiusSqr = litRadius * litRadius;\nfloat illum = litRadiusSqr / max(litRadiusSqr, distSqr);\nfloat attRadiusSqrInv = 1.0 / max(cc_lightSizeRangeAngle[i].y, 0.01);\nattRadiusSqrInv *= attRadiusSqrInv;\nfloat att = GetDistAtt(distSqr, attRadiusSqrInv);\nvec3 lspec = specular * CalcSpecular(s.roughness, SNH, SH, N);\nif (cc_lightPos[i].w > 0.0) {\nfloat cosInner = max(dot(-cc_lightDir[i].xyz, SL), 0.01);\nfloat cosOuter = cc_lightSizeRangeAngle[i].z;\nfloat litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\nfloat litAngleOffset = -cosOuter * litAngleScale;\natt *= GetAngleAtt(SL, -cc_lightDir[i].xyz, litAngleScale, litAngleOffset);\n}\nvec3 lightColor = cc_lightColor[i].rgb;\nfloat shadow = 1.0;\n#if CC_RECEIVE_SHADOW\nif (cc_lightPos[i].w > 0.0 && cc_lightSizeRangeAngle[i].w > 0.0) {\nshadow = CCSpotShadowFactorBase(shadowPos, position, s.shadowBias);\n}\n#endif\nlightColor *= shadow;\nfinalColor += SNL * lightColor * cc_lightColor[i].w * illum * att * (diffuseContrib + lspec);\n}\nreturn vec4(finalColor, 0.0);\n}\n#endif\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 1\nlayout(set = 1, binding = 7) readonly buffer b_ccLightsBuffer { vec4 b_ccLights[]; };\nlayout(set = 1, binding = 8) readonly buffer b_clusterLightIndicesBuffer { uint b_clusterLightIndices[]; };\nlayout(set = 1, binding = 9) readonly buffer b_clusterLightGridBuffer { uvec4 b_clusterLightGrid[]; };\nstruct CCLight\n{\nvec4 cc_lightPos;\nvec4 cc_lightColor;\nvec4 cc_lightSizeRangeAngle;\nvec4 cc_lightDir;\n};\nstruct Cluster\n{\nvec3 minBounds;\nvec3 maxBounds;\n};\nstruct LightGrid\n{\nuint offset;\nuint ccLights;\n};\nCCLight getCCLight(uint i)\n{\nCCLight light;\nlight.cc_lightPos = b_ccLights[4u * i + 0u];\nlight.cc_lightColor = b_ccLights[4u * i + 1u];\nlight.cc_lightSizeRangeAngle = b_ccLights[4u * i + 2u];\nlight.cc_lightDir = b_ccLights[4u * i + 3u];\nreturn light;\n}\nLightGrid getLightGrid(uint cluster)\n{\nuvec4 gridvec = b_clusterLightGrid[cluster];\nLightGrid grid;\ngrid.offset = gridvec.x;\ngrid.ccLights = gridvec.y;\nreturn grid;\n}\nuint getGridLightIndex(uint start, uint offset)\n{\nreturn b_clusterLightIndices[start + offset];\n}\nuint getClusterZIndex(vec4 worldPos)\n{\nfloat scale = float(24) / log(cc_nearFar.y / cc_nearFar.x);\nfloat bias = -(float(24) * log(cc_nearFar.x) / log(cc_nearFar.y / cc_nearFar.x));\nfloat eyeDepth = -(cc_matView * worldPos).z;\nuint zIndex = uint(max(log(eyeDepth) * scale + bias, 0.0));\nreturn zIndex;\n}\nuint getClusterIndex(vec4 fragCoord, vec4 worldPos)\n{\nuint zIndex = getClusterZIndex(worldPos);\nfloat clusterSizeX = ceil(cc_viewPort.z / float(16));\nfloat clusterSizeY = ceil(cc_viewPort.w / float(8));\nuvec3 indices = uvec3(uvec2(fragCoord.xy / vec2(clusterSizeX, clusterSizeY)), zIndex);\nuint cluster = (16u * 8u) * indices.z + 16u * indices.y + indices.x;\nreturn cluster;\n}\nvec4 CCClusterShadingAdditive (StandardSurface s, vec4 shadowPos) {\nvec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\nvec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\nvec3 diffuseContrib = diffuse / PI;\nvec3 position;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nposition = unpackHighpData(s.position, s.position_fract_part);\n#else\nposition = s.position;\n#endif\nvec3 N = normalize(s.normal);\nvec3 V = normalize(cc_cameraPos.xyz - position);\nfloat NV = max(abs(dot(N, V)), 0.001);\nspecular = BRDFApprox(specular, s.roughness, NV);\nvec3 finalColor = vec3(0.0);\nuint cluster = getClusterIndex(gl_FragCoord, vec4(position, 1.0));\nLightGrid grid = getLightGrid(cluster);\nuint numLights = grid.ccLights;\nfor (uint i = 0u; i < 100u; i++) {\nif (i >= numLights) break;\nuint lightIndex = getGridLightIndex(grid.offset, i);\nCCLight light = getCCLight(lightIndex);\nvec3 SLU = light.cc_lightPos.xyz - position;\nvec3 SL = normalize(SLU);\nvec3 SH = normalize(SL + V);\nfloat SNL = max(dot(N, SL), 0.001);\nfloat SNH = max(dot(N, SH), 0.0);\nfloat distSqr = dot(SLU, SLU);\nfloat litRadius = light.cc_lightSizeRangeAngle.x;\nfloat litRadiusSqr = litRadius * litRadius;\nfloat illum = PI * (litRadiusSqr / max(litRadiusSqr , distSqr));\nfloat attRadiusSqrInv = 1.0 / max(light.cc_lightSizeRangeAngle.y, 0.01);\nattRadiusSqrInv *= attRadiusSqrInv;\nfloat att = GetDistAtt(distSqr, attRadiusSqrInv);\nvec3 lspec = specular * CalcSpecular(s.roughness, SNH, SH, N);\nif (light.cc_lightPos.w > 0.0) {\nfloat cosInner = max(dot(-light.cc_lightDir.xyz, SL), 0.01);\nfloat cosOuter = light.cc_lightSizeRangeAngle.z;\nfloat litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\nfloat litAngleOffset = -cosOuter * litAngleScale;\natt *= GetAngleAtt(SL, -light.cc_lightDir.xyz, litAngleScale, litAngleOffset);\n}\nvec3 lightColor = light.cc_lightColor.rgb;\nfloat shadow = 1.0;\n#if CC_RECEIVE_SHADOW\nif (light.cc_lightPos.w > 0.0) {\nshadow = CCSpotShadowFactorBase(shadowPos, position, s.shadowBias);\n}\n#endif\nlightColor *= shadow;\nfinalColor += SNL * lightColor * light.cc_lightColor.w * illum * att * (diffuseContrib + lspec);\n}\nreturn vec4(finalColor, 0.0);\n}\n#endif\nlayout(location = 0) out vec4 fragColorX;\nvoid main () {\nStandardSurface s; surf(s);\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 1\nvec4 color = CCClusterShadingAdditive(s, v_shadowPos);\n#else\nvec4 color = CCStandardShadingAdditive(s, v_shadowPos);\n#endif\nfragColorX = CCFragOutput(color);\n}\n#elif (CC_PIPELINE_TYPE == 0 || CC_FORCE_FORWARD_SHADING)\nlayout(location = 0) out vec4 fragColorX;\nvoid main () {\nStandardSurface s; surf(s);\nvec4 color = CCStandardShadingBase(s, v_shadowPos);\nCC_APPLY_FOG(color, s.position.xyz);\nfragColorX = CCFragOutput(color);\n}\n#elif CC_PIPELINE_TYPE == 1\nvec2 signNotZero(vec2 v) {\nreturn vec2((v.x >= 0.0) ? +1.0 : -1.0, (v.y >= 0.0) ? +1.0 : -1.0);\n}\nvec2 float32x3_to_oct(in vec3 v) {\nvec2 p = v.xy * (1.0 / (abs(v.x) + abs(v.y) + abs(v.z)));\nreturn (v.z <= 0.0) ? ((1.0 - abs(p.yx)) * signNotZero(p)) : p;\n}\nlayout(location = 0) out vec4 fragColor0;\nlayout(location = 1) out vec4 fragColor1;\nlayout(location = 2) out vec4 fragColor2;\nvoid main () {\nStandardSurface s; surf(s);\nfragColor0 = s.albedo;\nfragColor1 = vec4(float32x3_to_oct(s.normal), s.roughness, s.metallic);\nfragColor2 = vec4(s.emissive, s.occlusion);\n}\n#endif", }, { - "vert": "#extension GL_EXT_shader_explicit_arithmetic_types_int32: require\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\nrgba = rgba * 255.0;\nhighp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\nhighp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\nhighp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\nreturn Sign * exp2(Exponent - 23.0) * Mantissa;\n}\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nlayout(location = 0) in vec3 a_position;\nlayout(location = 1) in vec3 a_normal;\nlayout(location = 2) in vec2 a_texCoord;\nlayout(location = 3) in vec4 a_tangent;\n#if CC_USE_SKINNING\nlayout(location = 4) in u32vec4 a_joints;\nlayout(location = 5) in vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nlayout(location = 6) in highp vec4 a_jointAnimInfo;\n#endif\nlayout(location = 7) in vec4 a_matWorld0;\nlayout(location = 8) in vec4 a_matWorld1;\nlayout(location = 9) in vec4 a_matWorld2;\n#if USE_LIGHTMAP\nlayout(location = 10) in vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nlayout(location = 11) in vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nlayout(location = 12) in float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nint getVertexId() {\nreturn gl_VertexIndex;\n}\n#endif\n#if CC_USE_MORPH\nlayout(set = 2, binding = 4) uniform CCMorph {\nvec4 cc_displacementWeights[15];\nvec4 cc_displacementTextureInfo;\n};\nvec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\nfloat pixelIndexF = float(pixelIndex);\nfloat x = mod(pixelIndexF, textureResolution.x);\nfloat y = floor(pixelIndexF / textureResolution.x);\nreturn vec2(x, y);\n}\nvec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\nreturn (vec2(location.x, location.y) + .5) / textureResolution;\n}\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int pixelIndex) {\nivec2 texSize = textureSize(tex, 0);\nreturn texelFetch(tex, ivec2(pixelIndex % texSize.x, pixelIndex / texSize.x), 0);\n}\n#else\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex * 4;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\nreturn vec4(\ndecode32(texture(tex, x)),\ndecode32(texture(tex, y)),\ndecode32(texture(tex, z)),\n1.0\n);\n}\n#endif\nfloat getDisplacementWeight(int index) {\nint quot = index / 4;\nint remainder = index - quot * 4;\nif (remainder == 0) {\nreturn cc_displacementWeights[quot].x;\n} else if (remainder == 1) {\nreturn cc_displacementWeights[quot].y;\n} else if (remainder == 2) {\nreturn cc_displacementWeights[quot].z;\n} else {\nreturn cc_displacementWeights[quot].w;\n}\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\nreturn fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n#else\nvec3 result = vec3(0, 0, 0);\nint nVertices = int(cc_displacementTextureInfo.z);\nfor (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\nresult += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n}\nreturn result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\nlayout(set = 2, binding = 7) uniform sampler2D cc_PositionDisplacements;\nvec3 getPositionDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nlayout(set = 2, binding = 8) uniform sampler2D cc_NormalDisplacements;\nvec3 getNormalDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\nlayout(set = 2, binding = 9) uniform sampler2D cc_TangentDisplacements;\nvec3 getTangentDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n}\n#endif\nvoid applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nint vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nnormal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\ntangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\n#if CC_USE_BAKED_ANIMATION\nlayout(set = 2, binding = 3) uniform CCSkinningTexture {\nhighp vec4 cc_jointTextureInfo;\n};\nlayout(set = 2, binding = 2) uniform CCSkinningAnimation {\nhighp vec4 cc_jointAnimInfo;\n};\nlayout(set = 2, binding = 6) uniform highp sampler2D cc_jointTexture;\nvoid CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n{\n#if USE_INSTANCING\nhighp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n#else\nhighp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n#endif\ninvSize = cc_jointTextureInfo.w;\nhighp float tempY = floor(temp * invSize);\nx = floor(temp - tempY * cc_jointTextureInfo.x);\ny = (tempY + 0.5) * invSize;\n}\n#else\nlayout(set = 2, binding = 3) uniform CCSkinning {\nhighp vec4 cc_joints[30 * 3];\n};\n#endif\n#if CC_USE_BAKED_ANIMATION\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(3.0, i, x, y, invSize);\nvec4 v1 = texture(cc_jointTexture, vec2((x + 0.5) * invSize, y));\nvec4 v2 = texture(cc_jointTexture, vec2((x + 1.5) * invSize, y));\nvec4 v3 = texture(cc_jointTexture, vec2((x + 2.5) * invSize, y));\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#else\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(12.0, i, x, y, invSize);\nvec4 v1 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n);\nvec4 v2 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n);\nvec4 v3 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n);\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\n#else\nmat4 getJointMatrix (float i) {\nint idx = int(i);\nvec4 v1 = cc_joints[idx * 3];\nvec4 v2 = cc_joints[idx * 3 + 1];\nvec4 v3 = cc_joints[idx * 3 + 2];\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\nmat4 skinMatrix () {\nvec4 joints = vec4(a_joints);\nreturn getJointMatrix(joints.x) * a_weights.x\n+ getJointMatrix(joints.y) * a_weights.y\n+ getJointMatrix(joints.z) * a_weights.z\n+ getJointMatrix(joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\nmat4 m = skinMatrix();\nposition = m * position;\n}\nvoid CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nmat4 m = skinMatrix();\nposition = m * position;\nnormal = (m * vec4(normal, 0.0)).xyz;\ntangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n}\n#endif\nvoid CCVertInput(inout StandardVertInput In)\n{\nIn.position = vec4(a_position, 1.0);\nIn.normal = a_normal;\nIn.tangent = a_tangent;\n#if CC_USE_MORPH\napplyMorph(In.position, In.normal, In.tangent);\n#endif\n#if CC_USE_SKINNING\nCCSkin(In.position, In.normal, In.tangent);\n#endif\n}\n#if !USE_INSTANCING\n#if USE_BATCHING\nlayout(set = 2, binding = 0) uniform CCLocalBatched {\nhighp mat4 cc_matWorlds[10];\n};\n#else\nlayout(set = 2, binding = 0) uniform CCLocal {\nhighp mat4 cc_matWorld;\nhighp mat4 cc_matWorldIT;\nhighp vec4 cc_lightingMapUVParam;\nhighp vec4 cc_localShadowBias;\n};\n#endif\n#endif\nvoid CCGetWorldMatrixFull(out mat4 matWorld, out mat4 matWorldIT)\n{\n#if USE_INSTANCING\nmatWorld = mat4(\nvec4(a_matWorld0.xyz, 0.0),\nvec4(a_matWorld1.xyz, 0.0),\nvec4(a_matWorld2.xyz, 0.0),\nvec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)\n);\nmatWorldIT = matWorld;\n#elif USE_BATCHING\nmatWorld = cc_matWorlds[int(a_dyn_batch_id)];\nmatWorldIT = matWorld;\n#else\nmatWorld = cc_matWorld;\nmatWorldIT = cc_matWorldIT;\n#endif\n}\nlayout(set = 1, binding = 0) uniform Constants {\nvec4 tilingOffset;\nvec4 albedo;\nvec4 albedoScaleAndCutoff;\nvec4 pbrParams;\nvec4 emissive;\nvec4 emissiveScaleParam;\n};\nlayout(set = 0, binding = 2) uniform CCShadow {\nhighp mat4 cc_matLightPlaneProj;\nhighp mat4 cc_matLightView;\nhighp mat4 cc_matLightViewProj;\nhighp vec4 cc_shadowInvProjDepthInfo;\nhighp vec4 cc_shadowProjDepthInfo;\nhighp vec4 cc_shadowProjInfo;\nmediump vec4 cc_shadowNFLSInfo;\nmediump vec4 cc_shadowWHPBInfo;\nmediump vec4 cc_shadowLPNNInfo;\nlowp vec4 cc_shadowColor;\nmediump vec4 cc_planarNDInfo;\n};\n#if HAS_SECOND_UV || USE_LIGHTMAP\nlayout(location = 14) in vec2 a_texCoord1;\n#endif\nlayout(location = 0) out vec2 v_uv;\n#if HAS_SECOND_UV\nlayout(location = 1) out vec2 v_uv1;\n#endif\nlayout(location = 2) out vec4 v_worldPos;\nlayout(location = 3) out float v_clip_depth;\nvec4 vert () {\nStandardVertInput In;\nCCVertInput(In);\nmat4 matWorld, matWorldIT;\nCCGetWorldMatrixFull(matWorld, matWorldIT);\nv_worldPos = matWorld * In.position;\nvec4 clipPos = cc_matLightViewProj * v_worldPos;\nv_uv = a_texCoord * tilingOffset.xy + tilingOffset.zw;\n#if HAS_SECOND_UV\nv_uv1 = a_texCoord1 * tilingOffset.xy + tilingOffset.zw;\n#endif\nv_clip_depth = clipPos.z / clipPos.w * 0.5 + 0.5;\nreturn clipPos;\n}\nvoid main() { gl_Position = vert(); }", + "vert": "#extension GL_EXT_shader_explicit_arithmetic_types_int32: require\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\nrgba = rgba * 255.0;\nhighp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\nhighp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\nhighp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\nreturn Sign * exp2(Exponent - 23.0) * Mantissa;\n}\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nlayout(location = 0) in vec3 a_position;\nlayout(location = 1) in vec3 a_normal;\nlayout(location = 2) in vec2 a_texCoord;\nlayout(location = 3) in vec4 a_tangent;\n#if CC_USE_SKINNING\nlayout(location = 4) in u32vec4 a_joints;\nlayout(location = 5) in vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nlayout(location = 6) in highp vec4 a_jointAnimInfo;\n#endif\nlayout(location = 7) in vec4 a_matWorld0;\nlayout(location = 8) in vec4 a_matWorld1;\nlayout(location = 9) in vec4 a_matWorld2;\n#if CC_USE_LIGHTMAP\nlayout(location = 10) in vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nlayout(location = 11) in vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nlayout(location = 12) in float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nint getVertexId() {\nreturn gl_VertexIndex;\n}\n#endif\n#if CC_USE_MORPH\nlayout(set = 2, binding = 4) uniform CCMorph {\nvec4 cc_displacementWeights[15];\nvec4 cc_displacementTextureInfo;\n};\nvec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\nfloat pixelIndexF = float(pixelIndex);\nfloat x = mod(pixelIndexF, textureResolution.x);\nfloat y = floor(pixelIndexF / textureResolution.x);\nreturn vec2(x, y);\n}\nvec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\nreturn (vec2(location.x, location.y) + .5) / textureResolution;\n}\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int pixelIndex) {\nivec2 texSize = textureSize(tex, 0);\nreturn texelFetch(tex, ivec2(pixelIndex % texSize.x, pixelIndex / texSize.x), 0);\n}\n#else\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex * 4;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\nreturn vec4(\ndecode32(texture(tex, x)),\ndecode32(texture(tex, y)),\ndecode32(texture(tex, z)),\n1.0\n);\n}\n#endif\nfloat getDisplacementWeight(int index) {\nint quot = index / 4;\nint remainder = index - quot * 4;\nif (remainder == 0) {\nreturn cc_displacementWeights[quot].x;\n} else if (remainder == 1) {\nreturn cc_displacementWeights[quot].y;\n} else if (remainder == 2) {\nreturn cc_displacementWeights[quot].z;\n} else {\nreturn cc_displacementWeights[quot].w;\n}\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\nreturn fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n#else\nvec3 result = vec3(0, 0, 0);\nint nVertices = int(cc_displacementTextureInfo.z);\nfor (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\nresult += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n}\nreturn result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\nlayout(set = 2, binding = 7) uniform sampler2D cc_PositionDisplacements;\nvec3 getPositionDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nlayout(set = 2, binding = 8) uniform sampler2D cc_NormalDisplacements;\nvec3 getNormalDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\nlayout(set = 2, binding = 9) uniform sampler2D cc_TangentDisplacements;\nvec3 getTangentDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n}\n#endif\nvoid applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nint vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nnormal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\ntangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\n#if CC_USE_BAKED_ANIMATION\nlayout(set = 2, binding = 3) uniform CCSkinningTexture {\nhighp vec4 cc_jointTextureInfo;\n};\nlayout(set = 2, binding = 2) uniform CCSkinningAnimation {\nhighp vec4 cc_jointAnimInfo;\n};\nlayout(set = 2, binding = 6) uniform highp sampler2D cc_jointTexture;\nvoid CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n{\n#if USE_INSTANCING\nhighp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n#else\nhighp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n#endif\ninvSize = cc_jointTextureInfo.w;\nhighp float tempY = floor(temp * invSize);\nx = floor(temp - tempY * cc_jointTextureInfo.x);\ny = (tempY + 0.5) * invSize;\n}\n#else\nlayout(set = 2, binding = 3) uniform CCSkinning {\nhighp vec4 cc_joints[30 * 3];\n};\n#endif\n#if CC_USE_BAKED_ANIMATION\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(3.0, i, x, y, invSize);\nvec4 v1 = texture(cc_jointTexture, vec2((x + 0.5) * invSize, y));\nvec4 v2 = texture(cc_jointTexture, vec2((x + 1.5) * invSize, y));\nvec4 v3 = texture(cc_jointTexture, vec2((x + 2.5) * invSize, y));\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#else\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(12.0, i, x, y, invSize);\nvec4 v1 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n);\nvec4 v2 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n);\nvec4 v3 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n);\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\n#else\nmat4 getJointMatrix (float i) {\nint idx = int(i);\nvec4 v1 = cc_joints[idx * 3];\nvec4 v2 = cc_joints[idx * 3 + 1];\nvec4 v3 = cc_joints[idx * 3 + 2];\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\nmat4 skinMatrix () {\nvec4 joints = vec4(a_joints);\nreturn getJointMatrix(joints.x) * a_weights.x\n+ getJointMatrix(joints.y) * a_weights.y\n+ getJointMatrix(joints.z) * a_weights.z\n+ getJointMatrix(joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\nmat4 m = skinMatrix();\nposition = m * position;\n}\nvoid CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nmat4 m = skinMatrix();\nposition = m * position;\nnormal = (m * vec4(normal, 0.0)).xyz;\ntangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n}\n#endif\nvoid CCVertInput(inout StandardVertInput In)\n{\nIn.position = vec4(a_position, 1.0);\nIn.normal = a_normal;\nIn.tangent = a_tangent;\n#if CC_USE_MORPH\napplyMorph(In.position, In.normal, In.tangent);\n#endif\n#if CC_USE_SKINNING\nCCSkin(In.position, In.normal, In.tangent);\n#endif\n}\n#if !USE_INSTANCING\n#if USE_BATCHING\nlayout(set = 2, binding = 0) uniform CCLocalBatched {\nhighp mat4 cc_matWorlds[10];\n};\n#else\nlayout(set = 2, binding = 0) uniform CCLocal {\nhighp mat4 cc_matWorld;\nhighp mat4 cc_matWorldIT;\nhighp vec4 cc_lightingMapUVParam;\nhighp vec4 cc_localShadowBias;\n};\n#endif\n#endif\nvoid CCGetWorldMatrixFull(out mat4 matWorld, out mat4 matWorldIT)\n{\n#if USE_INSTANCING\nmatWorld = mat4(\nvec4(a_matWorld0.xyz, 0.0),\nvec4(a_matWorld1.xyz, 0.0),\nvec4(a_matWorld2.xyz, 0.0),\nvec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)\n);\nmatWorldIT = matWorld;\n#elif USE_BATCHING\nmatWorld = cc_matWorlds[int(a_dyn_batch_id)];\nmatWorldIT = matWorld;\n#else\nmatWorld = cc_matWorld;\nmatWorldIT = cc_matWorldIT;\n#endif\n}\nlayout(set = 1, binding = 0) uniform Constants {\nvec4 tilingOffset;\nvec4 albedo;\nvec4 albedoScaleAndCutoff;\nvec4 pbrParams;\nvec4 emissive;\nvec4 emissiveScaleParam;\n};\nlayout(set = 0, binding = 2) uniform CCShadow {\nhighp mat4 cc_matLightPlaneProj;\nhighp mat4 cc_matLightView;\nhighp mat4 cc_matLightViewProj;\nhighp vec4 cc_shadowInvProjDepthInfo;\nhighp vec4 cc_shadowProjDepthInfo;\nhighp vec4 cc_shadowProjInfo;\nmediump vec4 cc_shadowNFLSInfo;\nmediump vec4 cc_shadowWHPBInfo;\nmediump vec4 cc_shadowLPNNInfo;\nlowp vec4 cc_shadowColor;\nmediump vec4 cc_planarNDInfo;\n};\n#if HAS_SECOND_UV || CC_USE_LIGHTMAP\nlayout(location = 14) in vec2 a_texCoord1;\n#endif\nlayout(location = 0) out vec2 v_uv;\n#if HAS_SECOND_UV\nlayout(location = 1) out vec2 v_uv1;\n#endif\nlayout(location = 2) out vec4 v_worldPos;\nlayout(location = 3) out float v_clip_depth;\nvec4 vert () {\nStandardVertInput In;\nCCVertInput(In);\nmat4 matWorld, matWorldIT;\nCCGetWorldMatrixFull(matWorld, matWorldIT);\nv_worldPos = matWorld * In.position;\nvec4 clipPos = cc_matLightViewProj * v_worldPos;\nv_uv = a_texCoord * tilingOffset.xy + tilingOffset.zw;\n#if HAS_SECOND_UV\nv_uv1 = a_texCoord1 * tilingOffset.xy + tilingOffset.zw;\n#endif\nv_clip_depth = clipPos.z / clipPos.w * 0.5 + 0.5;\nreturn clipPos;\n}\nvoid main() { gl_Position = vert(); }", "frag": "\nprecision highp float;\nlayout(set = 1, binding = 0) uniform Constants {\nvec4 tilingOffset;\nvec4 albedo;\nvec4 albedoScaleAndCutoff;\nvec4 pbrParams;\nvec4 emissive;\nvec4 emissiveScaleParam;\n};\nvec4 packDepthToRGBA (float depth) {\nvec4 ret = vec4(1.0, 255.0, 65025.0, 16581375.0) * depth;\nret = fract(ret);\nret -= vec4(ret.yzw, 0.0) / 255.0;\nreturn ret;\n}\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nlayout(set = 0, binding = 0) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(set = 0, binding = 1) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\nlayout(set = 0, binding = 2) uniform CCShadow {\nhighp mat4 cc_matLightPlaneProj;\nhighp mat4 cc_matLightView;\nhighp mat4 cc_matLightViewProj;\nhighp vec4 cc_shadowInvProjDepthInfo;\nhighp vec4 cc_shadowProjDepthInfo;\nhighp vec4 cc_shadowProjInfo;\nmediump vec4 cc_shadowNFLSInfo;\nmediump vec4 cc_shadowWHPBInfo;\nmediump vec4 cc_shadowLPNNInfo;\nlowp vec4 cc_shadowColor;\nmediump vec4 cc_planarNDInfo;\n};\nlayout(set = 2, binding = 0) uniform CCLocal {\nhighp mat4 cc_matWorld;\nhighp mat4 cc_matWorldIT;\nhighp vec4 cc_lightingMapUVParam;\nhighp vec4 cc_localShadowBias;\n};\nfloat CCGetLinearDepthFromViewSpace(vec3 viewPos) {\nfloat dist = length(viewPos);\nreturn (dist - cc_shadowNFLSInfo.x) / (cc_shadowNFLSInfo.y - cc_shadowNFLSInfo.x);\n}\nfloat CCGetLinearDepth(vec3 worldPos) {\nvec4 viewStartPos = cc_matLightView * vec4(worldPos.xyz, 1.0);\nreturn CCGetLinearDepthFromViewSpace(viewStartPos.xyz);\n}\n#if CC_RECEIVE_SHADOW\nlayout(set = 0, binding = 3) uniform highp sampler2D cc_shadowMap;\nlayout(set = 0, binding = 5) uniform highp sampler2D cc_spotLightingMap;\n#endif\nlayout(location = 0) in vec2 v_uv;\n#if HAS_SECOND_UV\nlayout(location = 1) in vec2 v_uv1;\n#endif\nlayout(location = 2) in vec4 v_worldPos;\nlayout(location = 3) in float v_clip_depth;\n#if USE_ALBEDO_MAP\nlayout(set = 1, binding = 1) uniform sampler2D albedoMap;\n#endif\n#if USE_ALPHA_TEST\n#endif\nvec4 frag () {\nvec4 baseColor = albedo;\n#if USE_ALBEDO_MAP\nbaseColor *= texture(albedoMap, ALBEDO_UV);\n#endif\n#if USE_ALPHA_TEST\nif (baseColor.ALPHA_TEST_CHANNEL < albedoScaleAndCutoff.w) discard;\n#endif\nif(cc_shadowLPNNInfo.x > 0.000001 && cc_shadowLPNNInfo.x < 1.999999) {\nif (cc_shadowNFLSInfo.z > 0.000001) {\nreturn vec4(CCGetLinearDepth(v_worldPos.xyz), 1.0, 1.0, 1.0);\n}\n}\nif (cc_shadowLPNNInfo.y > 0.000001) {\nreturn packDepthToRGBA(v_clip_depth);\n}\nreturn vec4(v_clip_depth, 1.0, 1.0, 1.0);\n}\nlayout(location = 0) out vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }", } ], [ { - "vert": "\nprecision mediump float;\nlayout(set = 0, binding = 0) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(set = 0, binding = 1) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\nlayout(set = 2, binding = 0) uniform CCLocal {\nhighp mat4 cc_matWorld;\nhighp mat4 cc_matWorldIT;\nhighp vec4 cc_lightingMapUVParam;\nhighp vec4 cc_localShadowBias;\n};\nfloat LinearFog(vec4 pos) {\nvec4 wPos = pos;\nfloat cam_dis = distance(cc_cameraPos, wPos);\nfloat fogStart = cc_fogBase.x;\nfloat fogEnd = cc_fogBase.y;\nreturn clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * fogDensity);\nreturn f;\n}\nfloat ExpSquaredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\nreturn f;\n}\nfloat LayeredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat _FogTop = cc_fogAdd.x;\nfloat _FogRange = cc_fogAdd.y;\nvec3 camWorldProj = cc_cameraPos.xyz;\ncamWorldProj.y = 0.;\nvec3 worldPosProj = wPos.xyz;\nworldPosProj.y = 0.;\nfloat fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\nfloat fDeltaY, fDensityIntegral;\nif (cc_cameraPos.y > _FogTop) {\nif (wPos.y < _FogTop) {\nfDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\nfDensityIntegral = fDeltaY * fDeltaY * 0.5;\n} else {\nfDeltaY = 0.;\nfDensityIntegral = 0.;\n}\n} else {\nif (wPos.y < _FogTop) {\nfloat fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfloat fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\nfDeltaY = abs(fDeltaA - fDeltaB);\nfDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n} else {\nfDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n}\n}\nfloat fDensity;\nif (fDeltaY != 0.) {\nfDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n} else {\nfDensity = 0.;\n}\nfloat f = exp(-fDensity);\nreturn f;\n}\nvoid CC_TRANSFER_FOG_BASE(vec4 pos, out float factor)\n{\n#if CC_USE_FOG == 0\nfactor = LinearFog(pos);\n#elif CC_USE_FOG == 1\nfactor = ExpFog(pos);\n#elif CC_USE_FOG == 2\nfactor = ExpSquaredFog(pos);\n#elif CC_USE_FOG == 3\nfactor = LayeredFog(pos);\n#else\nfactor = 1.0;\n#endif\n}\n#if !CC_USE_ACCURATE_FOG\nlayout(location = 0) out float v_fog_factor;\n#endif\nvoid CC_TRANSFER_FOG(vec4 pos) {\n#if !CC_USE_ACCURATE_FOG\nCC_TRANSFER_FOG_BASE(pos, v_fog_factor);\n#endif\n}\nlayout(location = 1) out highp vec4 v_shadowPos;\nlayout(set = 0, binding = 2) uniform CCShadow {\nhighp mat4 cc_matLightPlaneProj;\nhighp mat4 cc_matLightView;\nhighp mat4 cc_matLightViewProj;\nhighp vec4 cc_shadowInvProjDepthInfo;\nhighp vec4 cc_shadowProjDepthInfo;\nhighp vec4 cc_shadowProjInfo;\nmediump vec4 cc_shadowNFLSInfo;\nmediump vec4 cc_shadowWHPBInfo;\nmediump vec4 cc_shadowLPNNInfo;\nlowp vec4 cc_shadowColor;\nmediump vec4 cc_planarNDInfo;\n};\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\n#if CC_RECEIVE_SHADOW\nlayout(set = 0, binding = 3) uniform highp sampler2D cc_shadowMap;\nlayout(set = 0, binding = 5) uniform highp sampler2D cc_spotLightingMap;\n#endif\n#if CC_RECEIVE_SHADOW\n#endif\nlayout(location = 0) in vec3 a_position;\nlayout(location = 1) in vec3 a_normal;\nlayout(location = 2) in vec2 a_texCoord;\n#if CC_RECEIVE_SHADOW\nlayout(location = 2) out vec2 v_shadowBias;\n#endif\nlayout(location = 3) out highp vec3 v_position;\nlayout(location = 4) out mediump vec3 v_normal;\nlayout(location = 5) out mediump vec2 uvw;\nlayout(location = 6) out mediump vec2 uv0;\nlayout(location = 7) out mediump vec2 uv1;\nlayout(location = 8) out mediump vec2 uv2;\nlayout(location = 9) out mediump vec2 uv3;\nlayout(location = 10) out mediump vec3 luv;\nlayout(location = 11) out mediump vec3 diffuse;\nlayout(set = 1, binding = 0) uniform TexCoords {\nvec4 UVScale;\nvec4 lightMapUVParam;\n};\nvoid main () {\nvec3 worldPos;\nworldPos.x = cc_matWorld[3][0] + a_position.x;\nworldPos.y = cc_matWorld[3][1] + a_position.y;\nworldPos.z = cc_matWorld[3][2] + a_position.z;\nvec4 pos = vec4(worldPos, 1.0);\npos = cc_matViewProj * pos;\nuvw = a_texCoord;\nuv0 = a_position.xz * UVScale.x;\nuv1 = a_position.xz * UVScale.y;\nuv2 = a_position.xz * UVScale.z;\nuv3 = a_position.xz * UVScale.w;\n#if USE_LIGHTMAP\nluv.xy = lightMapUVParam.xy + a_texCoord * lightMapUVParam.z;\nluv.z = lightMapUVParam.w;\n#endif\nv_position = worldPos;\nv_normal = a_normal;\nCC_TRANSFER_FOG(vec4(worldPos, 1.0));\n#if CC_RECEIVE_SHADOW\nv_shadowBias = vec2(0.0, 0.0);\n#endif\nv_shadowPos = cc_matLightViewProj * vec4(worldPos, 1.0);\ngl_Position = pos;\n}", - "frag": "\nprecision highp float;\nlayout(set = 0, binding = 0) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(set = 0, binding = 1) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nvec3 SRGBToLinear (vec3 gamma) {\nreturn gamma * gamma;\n}\nlayout(set = 0, binding = 2) uniform CCShadow {\nhighp mat4 cc_matLightPlaneProj;\nhighp mat4 cc_matLightView;\nhighp mat4 cc_matLightViewProj;\nhighp vec4 cc_shadowInvProjDepthInfo;\nhighp vec4 cc_shadowProjDepthInfo;\nhighp vec4 cc_shadowProjInfo;\nmediump vec4 cc_shadowNFLSInfo;\nmediump vec4 cc_shadowWHPBInfo;\nmediump vec4 cc_shadowLPNNInfo;\nlowp vec4 cc_shadowColor;\nmediump vec4 cc_planarNDInfo;\n};\nhighp float unpackHighpData (float mainPart, float modPart) {\nhighp float data = mainPart;\nreturn data + modPart;\n}\nvoid packHighpData (out float mainPart, out float modPart, highp float data) {\nmainPart = fract(data);\nmodPart = data - mainPart;\n}\nhighp float unpackHighpData (float mainPart, float modPart, const float modValue) {\nhighp float data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nvoid packHighpData (out float mainPart, out float modPart, highp float data, const float modValue) {\nhighp float divide = data / modValue;\nmainPart = floor(divide);\nmodPart = (data - mainPart * modValue) / modValue;\n}\nhighp vec2 unpackHighpData (vec2 mainPart, vec2 modPart) {\nhighp vec2 data = mainPart;\nreturn data + modPart;\n}\nvoid packHighpData (out vec2 mainPart, out vec2 modPart, highp vec2 data) {\nmainPart = fract(data);\nmodPart = data - mainPart;\n}\nhighp vec2 unpackHighpData (vec2 mainPart, vec2 modPart, const float modValue) {\nhighp vec2 data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nvoid packHighpData (out vec2 mainPart, out vec2 modPart, highp vec2 data, const float modValue) {\nhighp vec2 divide = data / modValue;\nmainPart = floor(divide);\nmodPart = (data - mainPart * modValue) / modValue;\n}\nhighp vec3 unpackHighpData (vec3 mainPart, vec3 modPart) {\nhighp vec3 data = mainPart;\nreturn data + modPart;\n}\nvoid packHighpData (out vec3 mainPart, out vec3 modPart, highp vec3 data) {\nmainPart = fract(data);\nmodPart = data - mainPart;\n}\nhighp vec3 unpackHighpData (vec3 mainPart, vec3 modPart, const float modValue) {\nhighp vec3 data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nvoid packHighpData (out vec3 mainPart, out vec3 modPart, highp vec3 data, const float modValue) {\nhighp vec3 divide = data / modValue;\nmainPart = floor(divide);\nmodPart = (data - mainPart * modValue) / modValue;\n}\nhighp vec4 unpackHighpData (vec4 mainPart, vec4 modPart) {\nhighp vec4 data = mainPart;\nreturn data + modPart;\n}\nvoid packHighpData (out vec4 mainPart, out vec4 modPart, highp vec4 data) {\nmainPart = fract(data);\nmodPart = data - mainPart;\n}\nhighp vec4 unpackHighpData (vec4 mainPart, vec4 modPart, const float modValue) {\nhighp vec4 data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nvoid packHighpData (out vec4 mainPart, out vec4 modPart, highp vec4 data, const float modValue) {\nhighp vec4 divide = data / modValue;\nmainPart = floor(divide);\nmodPart = (data - mainPart * modValue) / modValue;\n}\nlayout(set = 2, binding = 0) uniform CCLocal {\nhighp mat4 cc_matWorld;\nhighp mat4 cc_matWorldIT;\nhighp vec4 cc_lightingMapUVParam;\nhighp vec4 cc_localShadowBias;\n};\nfloat CCGetLinearDepthFromViewSpace(vec3 viewPos) {\nfloat dist = length(viewPos);\nreturn (dist - cc_shadowNFLSInfo.x) / (cc_shadowNFLSInfo.y - cc_shadowNFLSInfo.x);\n}\nfloat CCGetLinearDepth(vec3 worldPos) {\nvec4 viewStartPos = cc_matLightView * vec4(worldPos.xyz, 1.0);\nreturn CCGetLinearDepthFromViewSpace(viewStartPos.xyz);\n}\n#if CC_RECEIVE_SHADOW\nlayout(set = 0, binding = 3) uniform highp sampler2D cc_shadowMap;\nlayout(set = 0, binding = 5) uniform highp sampler2D cc_spotLightingMap;\nvec4 ApplyShadowDepthBias_FaceNormal(vec4 shadowPos, vec3 worldNormal, float normalBias)\n{\nvec4 newShadowPos = shadowPos;\nif(normalBias > EPSILON_LOWP)\n{\nvec4 viewNormal = cc_matLightView * vec4(worldNormal, 0.0);\nif(viewNormal.z < 0.1)\nnewShadowPos.xy += viewNormal.xy * cc_shadowProjInfo.xy * normalBias * clamp(viewNormal.z, 0.001, 0.1);\n}\nreturn newShadowPos;\n}\nvec4 ApplyShadowDepthBias_Perspective(vec4 shadowPos, float viewspaceDepthBias)\n{\nvec3 viewSpacePos;\nviewSpacePos.xy = shadowPos.xy * cc_shadowProjInfo.zw;\nviewSpacePos.z = shadowPos.z * cc_shadowInvProjDepthInfo.x + shadowPos.w * cc_shadowInvProjDepthInfo.y;\nviewSpacePos.xyz += cc_shadowProjDepthInfo.z * normalize(viewSpacePos.xyz) * viewspaceDepthBias;\nvec4 clipSpacePos;\nclipSpacePos.xy = viewSpacePos.xy * cc_shadowProjInfo.xy;\nclipSpacePos.zw = viewSpacePos.z * cc_shadowProjDepthInfo.xz + vec2(cc_shadowProjDepthInfo.y, 0.0);\nif (cc_shadowNFLSInfo.z > EPSILON) {\nclipSpacePos.z = CCGetLinearDepthFromViewSpace(viewSpacePos.xyz);\nclipSpacePos.z = (clipSpacePos.z * 2.0 - 1.0) * clipSpacePos.w;\n}\nreturn clipSpacePos;\n}\nvec4 ApplyShadowDepthBias_Orthographic(vec4 shadowPos, float viewspaceDepthBias)\n{\nfloat coeffA = cc_shadowProjDepthInfo.x;\nfloat coeffB = cc_shadowProjDepthInfo.y;\nfloat viewSpacePos_z = (shadowPos.z - coeffB) / coeffA;\nviewSpacePos_z += viewspaceDepthBias;\nvec4 result = shadowPos;\nresult.z = viewSpacePos_z * coeffA + coeffB;\nreturn result;\n}\nfloat CCGetShadowFactorHard (vec4 shadowPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Orthographic(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat shadow = 0.0;\nfloat closestDepth = 0.0;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nclosestDepth = dot(texture(cc_shadowMap, clipPos.xy), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0));\n} else {\nclosestDepth = texture(cc_shadowMap, clipPos.xy).x;\n}\nshadow = step(clipPos.z, closestDepth);\nreturn shadow;\n}\nfloat CCGetShadowFactorSoft (vec4 shadowPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Orthographic(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat offsetDepth = clipPos.z;\nvec2 mapSize = cc_shadowWHPBInfo.xy;\nvec2 oneTap = 1.0 / mapSize;\nvec2 clipPos_offset = clipPos.xy + oneTap;\nfloat block0, block1, block2, block3;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos.y)).x);\nblock1 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset.x, clipPos.y)).x);\nblock2 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset.y)).x);\nblock3 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset.x, clipPos_offset.y)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * mapSize.x;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block2, block3, coefX);\nfloat coefY = mod(clipPos.y, oneTap.y) * mapSize.y;\nreturn mix(resultX, resultY, coefY);\n}\nfloat CCGetShadowFactorSoft2X (vec4 shadowPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Orthographic(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat offsetDepth = clipPos.z;\nvec2 mapSize = cc_shadowWHPBInfo.xy;\nvec2 oneTap = 1.0 / mapSize;\nfloat clipPos_offset_L = clipPos.x - oneTap.x;\nfloat clipPos_offset_R = clipPos.x + oneTap.x;\nfloat clipPos_offset_U = clipPos.y - oneTap.y;\nfloat clipPos_offset_D = clipPos.y + oneTap.y;\nfloat block0, block1, block2, block3, block4, block5, block6, block7, block8;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock4 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock5 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock6 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock7 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock8 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_U)).x);\nblock1 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset_U)).x);\nblock2 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_U)).x);\nblock3 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos.y)).x);\nblock4 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos.y)).x);\nblock5 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos.y)).x);\nblock6 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_D)).x);\nblock7 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset_D)).x);\nblock8 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_D)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * mapSize.x;\nfloat coefY = mod(clipPos.y, oneTap.y) * mapSize.y;\nfloat shadow = 0.0;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block3, block4, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block1, block2, coefX);\nresultY = mix(block4, block5, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block3, block4, coefX);\nresultY = mix(block6, block7, coefX);\nshadow += mix(resultX, resultY, coefY);\nresultX = mix(block4, block5, coefX);\nresultY = mix(block7, block8, coefX);\nshadow += mix(resultX, resultY, coefY);\nreturn shadow * 0.25;\n}\nfloat CCGetSpotLightShadowFactorHard (vec4 shadowPos, vec3 worldPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Perspective(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat shadow = 0.0;\nfloat closestDepth = 0.0;\nfloat depth = clipPos.z;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nclosestDepth = dot(texture(cc_spotLightingMap, clipPos.xy), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0));\n} else {\nclosestDepth = texture(cc_spotLightingMap, clipPos.xy).x;\n}\nshadow = step(depth, closestDepth);\nreturn shadow;\n}\nfloat CCGetSpotLightShadowFactorSoft (vec4 shadowPos, vec3 worldPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Perspective(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat depth = 0.0;\nif (cc_shadowNFLSInfo.z > EPSILON) {\ndepth = CCGetLinearDepth(worldPos);\n} else {\ndepth = clipPos.z;\n}\nvec2 oneTap = 1.0 / cc_shadowWHPBInfo.xy;\nvec2 clipPos_offset = clipPos.xy + oneTap;\nfloat block0, block1, block2, block3;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)).x);\nblock1 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos.y)).x);\nblock2 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset.y)).x);\nblock3 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos_offset.y)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * cc_shadowWHPBInfo.x;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block2, block3, coefX);\nfloat coefY = mod(clipPos.y, oneTap.y) * cc_shadowWHPBInfo.y;\nreturn mix(resultX, resultY, coefY);\n}\nfloat CCGetSpotLightShadowFactorSoft2X (vec4 shadowPos, vec3 worldPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Perspective(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat depth = 0.0;\nif (cc_shadowNFLSInfo.z > EPSILON) {\ndepth = CCGetLinearDepth(worldPos);\n} else {\ndepth = clipPos.z;\n}\nvec2 mapSize = cc_shadowWHPBInfo.xy;\nvec2 oneTap = 1.0 / mapSize;\nfloat clipPos_offset_L = clipPos.x - oneTap.x;\nfloat clipPos_offset_R = clipPos.x + oneTap.x;\nfloat clipPos_offset_U = clipPos.y - oneTap.y;\nfloat clipPos_offset_D = clipPos.y + oneTap.y;\nfloat block0, block1, block2, block3, block4, block5, block6, block7, block8;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock4 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock5 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock6 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock7 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock8 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_U)).x);\nblock1 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_U)).x);\nblock2 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_U)).x);\nblock3 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos.y)).x);\nblock4 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)).x);\nblock5 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos.y)).x);\nblock6 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_D)).x);\nblock7 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_D)).x);\nblock8 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_D)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * mapSize.x;\nfloat coefY = mod(clipPos.y, oneTap.y) * mapSize.y;\nfloat shadow = 0.0;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block3, block4, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block1, block2, coefX);\nresultY = mix(block4, block5, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block3, block4, coefX);\nresultY = mix(block6, block7, coefX);\nshadow += mix(resultX, resultY, coefY);\nresultX = mix(block4, block5, coefX);\nresultY = mix(block7, block8, coefX);\nshadow += mix(resultX, resultY, coefY);\nreturn shadow * 0.25;\n}\nfloat CCSpotShadowFactorBase(vec4 shadowPos, vec3 worldPos, vec2 shadowBias)\n{\nfloat pcf = cc_shadowWHPBInfo.z;\nif (pcf > 1.9) {\nreturn CCGetSpotLightShadowFactorSoft2X(shadowPos, worldPos, shadowBias.x);\n}else if (pcf > 0.9) {\nreturn CCGetSpotLightShadowFactorSoft(shadowPos, worldPos, shadowBias.x);\n}else {\nreturn CCGetSpotLightShadowFactorHard(shadowPos, worldPos, shadowBias.x);\n}\n}\nfloat CCShadowFactorBase(vec4 shadowPos, vec3 N, vec2 shadowBias)\n{\nfloat realtimeShadow = 1.0;\nvec4 pos = ApplyShadowDepthBias_FaceNormal(shadowPos, N, shadowBias.y);\nfloat pcf = cc_shadowWHPBInfo.z;\nif (pcf > 1.9) {\nrealtimeShadow = CCGetShadowFactorSoft2X(pos, shadowBias.x);\n}else if (pcf > 0.9) {\nrealtimeShadow = CCGetShadowFactorSoft(pos, shadowBias.x);\n}else {\nrealtimeShadow = CCGetShadowFactorHard(pos, shadowBias.x);\n}\nreturn mix(realtimeShadow, 1.0, cc_shadowNFLSInfo.w);\n}\n#endif\n#if CC_USE_IBL\nlayout(set = 0, binding = 4) uniform samplerCube cc_environment;\nvec4 fragTextureLod (sampler2D tex, vec2 coord, float lod) {\nreturn textureLod(tex, coord, lod);\n}\nvec4 fragTextureLod (samplerCube tex, vec3 coord, float lod) {\nreturn textureLod(tex, coord, lod);\n}\nvec3 unpackRGBE (vec4 rgbe) {\nreturn rgbe.rgb * pow(1.1, rgbe.a * 255.0 - 128.0);\n}\n#if CC_USE_DIFFUSEMAP\nlayout(set = 0, binding = 6) uniform samplerCube cc_diffuseMap;\n#endif\n#endif\nfloat GGXMobile (float roughness, float NoH, vec3 H, vec3 N) {\nvec3 NxH = cross(N, H);\nfloat OneMinusNoHSqr = dot(NxH, NxH);\nfloat a = roughness * roughness;\nfloat n = NoH * a;\nfloat p = a / (OneMinusNoHSqr + n * n);\nreturn p * p;\n}\nfloat CalcSpecular (float roughness, float NoH, vec3 H, vec3 N) {\nreturn (roughness * 0.25 + 0.25) * GGXMobile(roughness, NoH, H, N);\n}\nvec3 BRDFApprox (vec3 specular, float roughness, float NoV) {\nconst vec4 c0 = vec4(-1.0, -0.0275, -0.572, 0.022);\nconst vec4 c1 = vec4(1.0, 0.0425, 1.04, -0.04);\nvec4 r = roughness * c0 + c1;\nfloat a004 = min(r.x * r.x, exp2(-9.28 * NoV)) * r.x + r.y;\nvec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;\nAB.y *= clamp(50.0 * specular.g, 0.0, 1.0);\nreturn specular * AB.x + AB.y;\n}\n#if USE_REFLECTION_DENOISE\nvec3 GetEnvReflectionWithMipFiltering(vec3 R, float roughness, float mipCount, float denoiseIntensity) {\n#if CC_USE_IBL\nfloat mip = roughness * mipCount;\nfloat delta = (dot(dFdx(R), dFdy(R))) * 1000.0;\nfloat mipBias = mix(0.0, 5.0, clamp(delta, 0.0, 1.0));\nvec4 biased = fragTextureLod(cc_environment, R, mip + mipBias);\nvec4 filtered = texture(cc_environment, R);\n#if CC_USE_IBL == 2\nbiased.rgb = unpackRGBE(biased);\nfiltered.rgb = unpackRGBE(filtered);\n#else\nbiased.rgb = SRGBToLinear(biased.rgb);\nfiltered.rgb = SRGBToLinear(filtered.rgb);\n#endif\nreturn mix(biased.rgb, filtered.rgb, denoiseIntensity);\n#else\nreturn vec3(0.0, 0.0, 0.0);\n#endif\n}\n#endif\nstruct StandardSurface {\nvec4 albedo;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nvec3 position, position_fract_part;\n#else\nvec3 position;\n#endif\nvec3 normal;\nvec3 emissive;\nvec3 lightmap;\nfloat lightmap_test;\nfloat roughness;\nfloat metallic;\nfloat occlusion;\nfloat specularIntensity;\n#if CC_RECEIVE_SHADOW\nvec2 shadowBias;\n#endif\n};\nvec4 CCStandardShadingBase (StandardSurface s, vec4 shadowPos) {\nvec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\nvec3 specular = mix(vec3(0.08 * s.specularIntensity), s.albedo.rgb, s.metallic);\nvec3 position;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nposition = unpackHighpData(s.position, s.position_fract_part);\n#else\nposition = s.position;\n#endif\nvec3 N = normalize(s.normal);\nvec3 V = normalize(cc_cameraPos.xyz - position);\nfloat NV = max(abs(dot(N, V)), 0.0);\nspecular = BRDFApprox(specular, s.roughness, NV);\nvec3 L = normalize(-cc_mainLitDir.xyz);\nvec3 H = normalize(L + V);\nfloat NH = max(dot(N, H), 0.0);\nfloat NL = max(dot(N, L), 0.0);\nvec3 finalColor = NL * cc_mainLitColor.rgb * cc_mainLitColor.w;\nvec3 diffuseContrib = diffuse / PI;\nvec3 specularContrib = specular * CalcSpecular(s.roughness, NH, H, N);\nvec3 dirlightContrib = (diffuseContrib + specularContrib);\nfloat shadow = 1.0;\n#if CC_RECEIVE_SHADOW\nif (NL > 0.0 && cc_mainLitDir.w > 0.0) {\nshadow = CCShadowFactorBase(shadowPos, N, s.shadowBias);\n}\n#endif\ndirlightContrib *= shadow;\nfinalColor *= dirlightContrib;\n#if USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\nif (s.lightmap_test > EPSILON_LOWP) {\nfinalColor = diffuse * s.lightmap.rgb * shadow;\n}\n#endif\nfloat fAmb = 0.5 - N.y * 0.5;\nvec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb);\n#if CC_USE_IBL\n#if CC_USE_DIFFUSEMAP\nvec4 diffuseMap = texture(cc_diffuseMap, N);\n#if CC_USE_DIFFUSEMAP == 2\nambDiff = unpackRGBE(diffuseMap);\n#else\nambDiff = SRGBToLinear(diffuseMap.rgb);\n#endif\n#endif\nvec3 R = normalize(reflect(-V, N));\n#if USE_REFLECTION_DENOISE\nvec3 env = GetEnvReflectionWithMipFiltering(R, s.roughness, cc_ambientGround.w, 0.6);\n#else\nvec4 envmap = fragTextureLod(cc_environment, R, s.roughness * cc_ambientGround.w);\n#if CC_USE_IBL == 2\nvec3 env = unpackRGBE(envmap);\n#else\nvec3 env = SRGBToLinear(envmap.rgb);\n#endif\n#endif\nfinalColor += env * cc_ambientSky.w * specular * s.occlusion;\n#endif\nfinalColor += ambDiff.rgb * cc_ambientSky.w * diffuse * s.occlusion;\nfinalColor += s.emissive;\nreturn vec4(finalColor, s.albedo.a);\n}\nvec3 ACESToneMap (vec3 color) {\ncolor = min(color, vec3(8.0));\nconst float A = 2.51;\nconst float B = 0.03;\nconst float C = 2.43;\nconst float D = 0.59;\nconst float E = 0.14;\nreturn (color * (A * color + B)) / (color * (C * color + D) + E);\n}\nvec4 CCFragOutput (vec4 color) {\n#if CC_USE_HDR\ncolor.rgb = ACESToneMap(color.rgb);\n#endif\ncolor.rgb = sqrt(color.rgb);\nreturn color;\n}\nfloat LinearFog(vec4 pos) {\nvec4 wPos = pos;\nfloat cam_dis = distance(cc_cameraPos, wPos);\nfloat fogStart = cc_fogBase.x;\nfloat fogEnd = cc_fogBase.y;\nreturn clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * fogDensity);\nreturn f;\n}\nfloat ExpSquaredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\nreturn f;\n}\nfloat LayeredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat _FogTop = cc_fogAdd.x;\nfloat _FogRange = cc_fogAdd.y;\nvec3 camWorldProj = cc_cameraPos.xyz;\ncamWorldProj.y = 0.;\nvec3 worldPosProj = wPos.xyz;\nworldPosProj.y = 0.;\nfloat fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\nfloat fDeltaY, fDensityIntegral;\nif (cc_cameraPos.y > _FogTop) {\nif (wPos.y < _FogTop) {\nfDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\nfDensityIntegral = fDeltaY * fDeltaY * 0.5;\n} else {\nfDeltaY = 0.;\nfDensityIntegral = 0.;\n}\n} else {\nif (wPos.y < _FogTop) {\nfloat fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfloat fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\nfDeltaY = abs(fDeltaA - fDeltaB);\nfDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n} else {\nfDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n}\n}\nfloat fDensity;\nif (fDeltaY != 0.) {\nfDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n} else {\nfDensity = 0.;\n}\nfloat f = exp(-fDensity);\nreturn f;\n}\nvoid CC_TRANSFER_FOG_BASE(vec4 pos, out float factor)\n{\n#if CC_USE_FOG == 0\nfactor = LinearFog(pos);\n#elif CC_USE_FOG == 1\nfactor = ExpFog(pos);\n#elif CC_USE_FOG == 2\nfactor = ExpSquaredFog(pos);\n#elif CC_USE_FOG == 3\nfactor = LayeredFog(pos);\n#else\nfactor = 1.0;\n#endif\n}\nvoid CC_APPLY_FOG_BASE(inout vec4 color, float factor) {\ncolor = vec4(mix(cc_fogColor.rgb, color.rgb, factor), color.a);\n}\n#if !CC_USE_ACCURATE_FOG\nlayout(location = 0) in float v_fog_factor;\n#endif\nvoid CC_APPLY_FOG(inout vec4 color) {\n#if !CC_USE_ACCURATE_FOG\nCC_APPLY_FOG_BASE(color, v_fog_factor);\n#endif\n}\nvoid CC_APPLY_FOG(inout vec4 color, vec3 worldPos) {\n#if CC_USE_ACCURATE_FOG\nfloat factor;\nCC_TRANSFER_FOG_BASE(vec4(worldPos, 1.0), factor);\n#else\nfloat factor = v_fog_factor;\n#endif\nCC_APPLY_FOG_BASE(color, factor);\n}\nlayout(location = 1) in highp vec4 v_shadowPos;\n#if CC_RECEIVE_SHADOW\n#endif\n#if USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\nlayout(location = 12) in vec3 v_luv;\nlayout(set = 2, binding = 10) uniform sampler2D cc_lightingMap;\n#endif\nlayout(location = 3) in highp vec3 v_position;\nlayout(location = 4) in mediump vec3 v_normal;\n#if CC_RECEIVE_SHADOW\nlayout(location = 2) in vec2 v_shadowBias;\n#endif\nlayout(location = 5) in mediump vec2 uvw;\nlayout(location = 6) in mediump vec2 uv0;\nlayout(location = 7) in mediump vec2 uv1;\nlayout(location = 8) in mediump vec2 uv2;\nlayout(location = 9) in mediump vec2 uv3;\nlayout(location = 11) in mediump vec3 diffuse;\nlayout(location = 10) in mediump vec3 luv;\nlayout(set = 1, binding = 1) uniform PbrParams {\nvec4 metallic;\nvec4 roughness;\n};\nlayout(set = 1, binding = 2) uniform sampler2D weightMap;\nlayout(set = 1, binding = 3) uniform sampler2D detailMap0;\nlayout(set = 1, binding = 4) uniform sampler2D detailMap1;\nlayout(set = 1, binding = 5) uniform sampler2D detailMap2;\nlayout(set = 1, binding = 6) uniform sampler2D detailMap3;\nlayout(set = 1, binding = 7) uniform sampler2D normalMap0;\nlayout(set = 1, binding = 8) uniform sampler2D normalMap1;\nlayout(set = 1, binding = 9) uniform sampler2D normalMap2;\nlayout(set = 1, binding = 10) uniform sampler2D normalMap3;\nlayout(set = 1, binding = 11) uniform sampler2D lightMap;\nvoid surf (out StandardSurface s) {\n#if LAYERS > 1\nvec4 w = texture(weightMap, uvw);\n#endif\nvec4 baseColor = vec4(0, 0, 0, 0);\n#if LAYERS == 1\nbaseColor = texture(detailMap0, uv0);\n#elif LAYERS == 2\nbaseColor += texture(detailMap0, uv0) * w.r;\nbaseColor += texture(detailMap1, uv1) * w.g;\n#elif LAYERS == 3\nbaseColor += texture(detailMap0, uv0) * w.r;\nbaseColor += texture(detailMap1, uv1) * w.g;\nbaseColor += texture(detailMap2, uv2) * w.b;\n#elif LAYERS == 4\nbaseColor += texture(detailMap0, uv0) * w.r;\nbaseColor += texture(detailMap1, uv1) * w.g;\nbaseColor += texture(detailMap2, uv2) * w.b;\nbaseColor += texture(detailMap3, uv3) * w.a;\n#else\nbaseColor = texture(detailMap0, uv0);\n#endif\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\npackHighpData(s.position, s.position_fract_part, v_position);\n#else\ns.position = v_position;\n#endif\n#if USE_NORMALMAP\nvec4 baseNormal = vec4(0, 0, 0, 0);\n#if LAYERS == 1\nbaseNormal = texture(normalMap0, uv0);\n#elif LAYERS == 2\nbaseNormal += texture(normalMap0, uv0) * w.r;\nbaseNormal += texture(normalMap1, uv1) * w.g;\n#elif LAYERS == 3\nbaseNormal += texture(normalMap0, uv0) * w.r;\nbaseNormal += texture(normalMap1, uv1) * w.g;\nbaseNormal += texture(normalMap2, uv2) * w.b;\n#elif LAYERS == 4\nbaseNormal += texture(normalMap0, uv0) * w.r;\nbaseNormal += texture(normalMap1, uv1) * w.g;\nbaseNormal += texture(normalMap2, uv2) * w.b;\nbaseNormal += texture(normalMap3, uv3) * w.a;\n#else\nbaseNormal = texture(normalMap0, uv0);\n#endif\nvec3 tangent = vec3(1.0, 0.0, 0.0);\nvec3 binormal = vec3(0.0, 0.0, 1.0);\nbinormal = cross(tangent, v_normal);\ntangent = cross(v_normal, binormal);\nvec3 nmmp = baseNormal.xyz - vec3(0.5);\ns.normal =\nnmmp.x * normalize(tangent) +\nnmmp.y * normalize(binormal) +\nnmmp.z * normalize(v_normal);\n#else\ns.normal = v_normal;\n#endif\n#if CC_RECEIVE_SHADOW\ns.shadowBias = v_shadowBias;\n#endif\ns.albedo = vec4(SRGBToLinear(baseColor.rgb), 1.0);\ns.occlusion = 1.0;\n#if USE_PBR\ns.roughness = 0.0;\n#if LAYERS == 1\ns.roughness = roughness.x;\n#elif LAYERS == 2\ns.roughness += roughness.x * w.r;\ns.roughness += roughness.y * w.g;\n#elif LAYERS == 3\ns.roughness += roughness.x * w.r;\ns.roughness += roughness.y * w.g;\ns.roughness += roughness.z * w.b;\n#elif LAYERS == 4\ns.roughness += roughness.x * w.r;\ns.roughness += roughness.y * w.g;\ns.roughness += roughness.z * w.b;\ns.roughness += roughness.w * w.a;\n#else\ns.roughness = 1.0;\n#endif\ns.specularIntensity = 0.5;\ns.metallic = 0.0;\n#if LAYERS == 1\ns.specularIntensity = 0.5;\ns.metallic = metallic.x;\n#elif LAYERS == 2\ns.metallic += metallic.x * w.r;\ns.metallic += metallic.y * w.g;\n#elif LAYERS == 3\ns.metallic += metallic.x * w.r;\ns.metallic += metallic.y * w.g;\ns.metallic += metallic.z * w.b;\n#elif LAYERS == 4\ns.metallic += metallic.x * w.r;\ns.metallic += metallic.y * w.g;\ns.metallic += metallic.z * w.b;\ns.metallic += metallic.w * w.a;\n#else\ns.specularIntensity = 0.5;\ns.metallic = 0.0;\n#endif\n#else\ns.roughness = 1.0;\ns.specularIntensity = 0.5;\ns.metallic = 0.0;\n#endif\ns.emissive = vec3(0.0, 0.0, 0.0);\n#if USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\nvec4 lightColor = texture(lightMap, luv.xy);\ns.lightmap = lightColor.xyz * luv.z;\ns.lightmap_test = luv.z;\n#endif\n}\n#if CC_FORWARD_ADD\n#if CC_PIPELINE_TYPE == 0\n#define LIGHTS_PER_PASS 1\n#else\n#define LIGHTS_PER_PASS 10\n#endif\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 0\nlayout(set = 2, binding = 1) uniform CCForwardLight {\nhighp vec4 cc_lightPos[LIGHTS_PER_PASS];\nvec4 cc_lightColor[LIGHTS_PER_PASS];\nvec4 cc_lightSizeRangeAngle[LIGHTS_PER_PASS];\nvec4 cc_lightDir[LIGHTS_PER_PASS];\n};\n#endif\nfloat SmoothDistAtt (float distSqr, float invSqrAttRadius) {\nfloat factor = distSqr * invSqrAttRadius;\nfloat smoothFactor = clamp(1.0 - factor * factor, 0.0, 1.0);\nreturn smoothFactor * smoothFactor;\n}\nfloat GetDistAtt (float distSqr, float invSqrAttRadius) {\nfloat attenuation = 1.0 / max(distSqr, 0.01*0.01);\nattenuation *= SmoothDistAtt(distSqr , invSqrAttRadius);\nreturn attenuation;\n}\nfloat GetAngleAtt (vec3 L, vec3 litDir, float litAngleScale, float litAngleOffset) {\nfloat cd = dot(litDir, L);\nfloat attenuation = clamp(cd * litAngleScale + litAngleOffset, 0.0, 1.0);\nreturn (attenuation * attenuation);\n}\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 0\nvec4 CCStandardShadingAdditive (StandardSurface s, vec4 shadowPos) {\nvec3 position;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nposition = unpackHighpData(s.position, s.position_fract_part);\n#else\nposition = s.position;\n#endif\nvec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\nvec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\nvec3 diffuseContrib = diffuse / PI;\nvec3 N = normalize(s.normal);\nvec3 V = normalize(cc_cameraPos.xyz - position);\nfloat NV = max(abs(dot(N, V)), 0.0);\nspecular = BRDFApprox(specular, s.roughness, NV);\nvec3 finalColor = vec3(0.0);\nint numLights = CC_PIPELINE_TYPE == 0 ? LIGHTS_PER_PASS : int(cc_lightDir[0].w);\nfor (int i = 0; i < LIGHTS_PER_PASS; i++) {\nif (i >= numLights) break;\nvec3 SLU = cc_lightPos[i].xyz - position;\nvec3 SL = normalize(SLU);\nvec3 SH = normalize(SL + V);\nfloat SNL = max(dot(N, SL), 0.0);\nfloat SNH = max(dot(N, SH), 0.0);\nfloat distSqr = dot(SLU, SLU);\nfloat litRadius = cc_lightSizeRangeAngle[i].x;\nfloat litRadiusSqr = litRadius * litRadius;\nfloat illum = litRadiusSqr / max(litRadiusSqr, distSqr);\nfloat attRadiusSqrInv = 1.0 / max(cc_lightSizeRangeAngle[i].y, 0.01);\nattRadiusSqrInv *= attRadiusSqrInv;\nfloat att = GetDistAtt(distSqr, attRadiusSqrInv);\nvec3 lspec = specular * CalcSpecular(s.roughness, SNH, SH, N);\nif (cc_lightPos[i].w > 0.0) {\nfloat cosInner = max(dot(-cc_lightDir[i].xyz, SL), 0.01);\nfloat cosOuter = cc_lightSizeRangeAngle[i].z;\nfloat litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\nfloat litAngleOffset = -cosOuter * litAngleScale;\natt *= GetAngleAtt(SL, -cc_lightDir[i].xyz, litAngleScale, litAngleOffset);\n}\nvec3 lightColor = cc_lightColor[i].rgb;\nfloat shadow = 1.0;\n#if CC_RECEIVE_SHADOW\nif (cc_lightPos[i].w > 0.0 && cc_lightSizeRangeAngle[i].w > 0.0) {\nshadow = CCSpotShadowFactorBase(shadowPos, position, s.shadowBias);\n}\n#endif\nlightColor *= shadow;\nfinalColor += SNL * lightColor * cc_lightColor[i].w * illum * att * (diffuseContrib + lspec);\n}\nreturn vec4(finalColor, 0.0);\n}\n#endif\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 1\nlayout(set = 1, binding = 12) readonly buffer b_ccLightsBuffer { vec4 b_ccLights[]; };\nlayout(set = 1, binding = 13) readonly buffer b_clusterLightIndicesBuffer { uint b_clusterLightIndices[]; };\nlayout(set = 1, binding = 14) readonly buffer b_clusterLightGridBuffer { uvec4 b_clusterLightGrid[]; };\nstruct CCLight\n{\nvec4 cc_lightPos;\nvec4 cc_lightColor;\nvec4 cc_lightSizeRangeAngle;\nvec4 cc_lightDir;\n};\nstruct Cluster\n{\nvec3 minBounds;\nvec3 maxBounds;\n};\nstruct LightGrid\n{\nuint offset;\nuint ccLights;\n};\nCCLight getCCLight(uint i)\n{\nCCLight light;\nlight.cc_lightPos = b_ccLights[4u * i + 0u];\nlight.cc_lightColor = b_ccLights[4u * i + 1u];\nlight.cc_lightSizeRangeAngle = b_ccLights[4u * i + 2u];\nlight.cc_lightDir = b_ccLights[4u * i + 3u];\nreturn light;\n}\nLightGrid getLightGrid(uint cluster)\n{\nuvec4 gridvec = b_clusterLightGrid[cluster];\nLightGrid grid;\ngrid.offset = gridvec.x;\ngrid.ccLights = gridvec.y;\nreturn grid;\n}\nuint getGridLightIndex(uint start, uint offset)\n{\nreturn b_clusterLightIndices[start + offset];\n}\nuint getClusterZIndex(vec4 worldPos)\n{\nfloat scale = float(24) / log(cc_nearFar.y / cc_nearFar.x);\nfloat bias = -(float(24) * log(cc_nearFar.x) / log(cc_nearFar.y / cc_nearFar.x));\nfloat eyeDepth = -(cc_matView * worldPos).z;\nuint zIndex = uint(max(log(eyeDepth) * scale + bias, 0.0));\nreturn zIndex;\n}\nuint getClusterIndex(vec4 fragCoord, vec4 worldPos)\n{\nuint zIndex = getClusterZIndex(worldPos);\nfloat clusterSizeX = ceil(cc_viewPort.z / float(16));\nfloat clusterSizeY = ceil(cc_viewPort.w / float(8));\nuvec3 indices = uvec3(uvec2(fragCoord.xy / vec2(clusterSizeX, clusterSizeY)), zIndex);\nuint cluster = (16u * 8u) * indices.z + 16u * indices.y + indices.x;\nreturn cluster;\n}\nvec4 CCClusterShadingAdditive (StandardSurface s, vec4 shadowPos) {\nvec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\nvec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\nvec3 diffuseContrib = diffuse / PI;\nvec3 position;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nposition = unpackHighpData(s.position, s.position_fract_part);\n#else\nposition = s.position;\n#endif\nvec3 N = normalize(s.normal);\nvec3 V = normalize(cc_cameraPos.xyz - position);\nfloat NV = max(abs(dot(N, V)), 0.001);\nspecular = BRDFApprox(specular, s.roughness, NV);\nvec3 finalColor = vec3(0.0);\nuint cluster = getClusterIndex(gl_FragCoord, vec4(position, 1.0));\nLightGrid grid = getLightGrid(cluster);\nuint numLights = grid.ccLights;\nfor (uint i = 0u; i < 100u; i++) {\nif (i >= numLights) break;\nuint lightIndex = getGridLightIndex(grid.offset, i);\nCCLight light = getCCLight(lightIndex);\nvec3 SLU = light.cc_lightPos.xyz - position;\nvec3 SL = normalize(SLU);\nvec3 SH = normalize(SL + V);\nfloat SNL = max(dot(N, SL), 0.001);\nfloat SNH = max(dot(N, SH), 0.0);\nfloat distSqr = dot(SLU, SLU);\nfloat litRadius = light.cc_lightSizeRangeAngle.x;\nfloat litRadiusSqr = litRadius * litRadius;\nfloat illum = PI * (litRadiusSqr / max(litRadiusSqr , distSqr));\nfloat attRadiusSqrInv = 1.0 / max(light.cc_lightSizeRangeAngle.y, 0.01);\nattRadiusSqrInv *= attRadiusSqrInv;\nfloat att = GetDistAtt(distSqr, attRadiusSqrInv);\nvec3 lspec = specular * CalcSpecular(s.roughness, SNH, SH, N);\nif (light.cc_lightPos.w > 0.0) {\nfloat cosInner = max(dot(-light.cc_lightDir.xyz, SL), 0.01);\nfloat cosOuter = light.cc_lightSizeRangeAngle.z;\nfloat litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\nfloat litAngleOffset = -cosOuter * litAngleScale;\natt *= GetAngleAtt(SL, -light.cc_lightDir.xyz, litAngleScale, litAngleOffset);\n}\nvec3 lightColor = light.cc_lightColor.rgb;\nfloat shadow = 1.0;\n#if CC_RECEIVE_SHADOW\nif (light.cc_lightPos.w > 0.0) {\nshadow = CCSpotShadowFactorBase(shadowPos, position, s.shadowBias);\n}\n#endif\nlightColor *= shadow;\nfinalColor += SNL * lightColor * light.cc_lightColor.w * illum * att * (diffuseContrib + lspec);\n}\nreturn vec4(finalColor, 0.0);\n}\n#endif\nlayout(location = 0) out vec4 fragColorX;\nvoid main () {\nStandardSurface s; surf(s);\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 1\nvec4 color = CCClusterShadingAdditive(s, v_shadowPos);\n#else\nvec4 color = CCStandardShadingAdditive(s, v_shadowPos);\n#endif\nfragColorX = CCFragOutput(color);\n}\n#elif (CC_PIPELINE_TYPE == 0 || CC_FORCE_FORWARD_SHADING)\nlayout(location = 0) out vec4 fragColorX;\nvoid main () {\nStandardSurface s; surf(s);\nvec4 color = CCStandardShadingBase(s, v_shadowPos);\nCC_APPLY_FOG(color, s.position.xyz);\nfragColorX = CCFragOutput(color);\n}\n#elif CC_PIPELINE_TYPE == 1\nvec2 signNotZero(vec2 v) {\nreturn vec2((v.x >= 0.0) ? +1.0 : -1.0, (v.y >= 0.0) ? +1.0 : -1.0);\n}\nvec2 float32x3_to_oct(in vec3 v) {\nvec2 p = v.xy * (1.0 / (abs(v.x) + abs(v.y) + abs(v.z)));\nreturn (v.z <= 0.0) ? ((1.0 - abs(p.yx)) * signNotZero(p)) : p;\n}\nlayout(location = 0) out vec4 fragColor0;\nlayout(location = 1) out vec4 fragColor1;\nlayout(location = 2) out vec4 fragColor2;\nvoid main () {\nStandardSurface s; surf(s);\nfragColor0 = s.albedo;\nfragColor1 = vec4(float32x3_to_oct(s.normal), s.roughness, s.metallic);\nfragColor2 = vec4(s.emissive, s.occlusion);\n}\n#endif", + "vert": "\nprecision mediump float;\nlayout(set = 0, binding = 0) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(set = 0, binding = 1) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\nlayout(set = 2, binding = 0) uniform CCLocal {\nhighp mat4 cc_matWorld;\nhighp mat4 cc_matWorldIT;\nhighp vec4 cc_lightingMapUVParam;\nhighp vec4 cc_localShadowBias;\n};\nfloat LinearFog(vec4 pos) {\nvec4 wPos = pos;\nfloat cam_dis = distance(cc_cameraPos, wPos);\nfloat fogStart = cc_fogBase.x;\nfloat fogEnd = cc_fogBase.y;\nreturn clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * fogDensity);\nreturn f;\n}\nfloat ExpSquaredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\nreturn f;\n}\nfloat LayeredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat _FogTop = cc_fogAdd.x;\nfloat _FogRange = cc_fogAdd.y;\nvec3 camWorldProj = cc_cameraPos.xyz;\ncamWorldProj.y = 0.;\nvec3 worldPosProj = wPos.xyz;\nworldPosProj.y = 0.;\nfloat fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\nfloat fDeltaY, fDensityIntegral;\nif (cc_cameraPos.y > _FogTop) {\nif (wPos.y < _FogTop) {\nfDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\nfDensityIntegral = fDeltaY * fDeltaY * 0.5;\n} else {\nfDeltaY = 0.;\nfDensityIntegral = 0.;\n}\n} else {\nif (wPos.y < _FogTop) {\nfloat fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfloat fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\nfDeltaY = abs(fDeltaA - fDeltaB);\nfDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n} else {\nfDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n}\n}\nfloat fDensity;\nif (fDeltaY != 0.) {\nfDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n} else {\nfDensity = 0.;\n}\nfloat f = exp(-fDensity);\nreturn f;\n}\nvoid CC_TRANSFER_FOG_BASE(vec4 pos, out float factor)\n{\n#if CC_USE_FOG == 0\nfactor = LinearFog(pos);\n#elif CC_USE_FOG == 1\nfactor = ExpFog(pos);\n#elif CC_USE_FOG == 2\nfactor = ExpSquaredFog(pos);\n#elif CC_USE_FOG == 3\nfactor = LayeredFog(pos);\n#else\nfactor = 1.0;\n#endif\n}\n#if !CC_USE_ACCURATE_FOG\nlayout(location = 0) out float v_fog_factor;\n#endif\nvoid CC_TRANSFER_FOG(vec4 pos) {\n#if !CC_USE_ACCURATE_FOG\nCC_TRANSFER_FOG_BASE(pos, v_fog_factor);\n#endif\n}\nlayout(location = 1) out highp vec4 v_shadowPos;\nlayout(set = 0, binding = 2) uniform CCShadow {\nhighp mat4 cc_matLightPlaneProj;\nhighp mat4 cc_matLightView;\nhighp mat4 cc_matLightViewProj;\nhighp vec4 cc_shadowInvProjDepthInfo;\nhighp vec4 cc_shadowProjDepthInfo;\nhighp vec4 cc_shadowProjInfo;\nmediump vec4 cc_shadowNFLSInfo;\nmediump vec4 cc_shadowWHPBInfo;\nmediump vec4 cc_shadowLPNNInfo;\nlowp vec4 cc_shadowColor;\nmediump vec4 cc_planarNDInfo;\n};\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\n#if CC_RECEIVE_SHADOW\nlayout(set = 0, binding = 3) uniform highp sampler2D cc_shadowMap;\nlayout(set = 0, binding = 5) uniform highp sampler2D cc_spotLightingMap;\n#endif\n#if CC_RECEIVE_SHADOW\n#endif\nlayout(location = 0) in vec3 a_position;\nlayout(location = 1) in vec3 a_normal;\nlayout(location = 2) in vec2 a_texCoord;\n#if CC_RECEIVE_SHADOW\nlayout(location = 2) out vec2 v_shadowBias;\n#endif\nlayout(location = 3) out highp vec3 v_position;\nlayout(location = 4) out mediump vec3 v_normal;\nlayout(location = 5) out mediump vec2 uvw;\nlayout(location = 6) out mediump vec2 uv0;\nlayout(location = 7) out mediump vec2 uv1;\nlayout(location = 8) out mediump vec2 uv2;\nlayout(location = 9) out mediump vec2 uv3;\nlayout(location = 10) out mediump vec3 luv;\nlayout(location = 11) out mediump vec3 diffuse;\nlayout(set = 1, binding = 0) uniform TexCoords {\nvec4 UVScale;\nvec4 lightMapUVParam;\n};\nvoid main () {\nvec3 worldPos;\nworldPos.x = cc_matWorld[3][0] + a_position.x;\nworldPos.y = cc_matWorld[3][1] + a_position.y;\nworldPos.z = cc_matWorld[3][2] + a_position.z;\nvec4 pos = vec4(worldPos, 1.0);\npos = cc_matViewProj * pos;\nuvw = a_texCoord;\nuv0 = a_position.xz * UVScale.x;\nuv1 = a_position.xz * UVScale.y;\nuv2 = a_position.xz * UVScale.z;\nuv3 = a_position.xz * UVScale.w;\n#if CC_USE_LIGHTMAP\nluv.xy = lightMapUVParam.xy + a_texCoord * lightMapUVParam.z;\nluv.z = lightMapUVParam.w;\n#endif\nv_position = worldPos;\nv_normal = a_normal;\nCC_TRANSFER_FOG(vec4(worldPos, 1.0));\n#if CC_RECEIVE_SHADOW\nv_shadowBias = vec2(0.0, 0.0);\n#endif\nv_shadowPos = cc_matLightViewProj * vec4(worldPos, 1.0);\ngl_Position = pos;\n}", + "frag": "\nprecision highp float;\nlayout(set = 0, binding = 0) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(set = 0, binding = 1) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nvec3 SRGBToLinear (vec3 gamma) {\nreturn gamma * gamma;\n}\nlayout(set = 0, binding = 2) uniform CCShadow {\nhighp mat4 cc_matLightPlaneProj;\nhighp mat4 cc_matLightView;\nhighp mat4 cc_matLightViewProj;\nhighp vec4 cc_shadowInvProjDepthInfo;\nhighp vec4 cc_shadowProjDepthInfo;\nhighp vec4 cc_shadowProjInfo;\nmediump vec4 cc_shadowNFLSInfo;\nmediump vec4 cc_shadowWHPBInfo;\nmediump vec4 cc_shadowLPNNInfo;\nlowp vec4 cc_shadowColor;\nmediump vec4 cc_planarNDInfo;\n};\nhighp float unpackHighpData (float mainPart, float modPart) {\nhighp float data = mainPart;\nreturn data + modPart;\n}\nvoid packHighpData (out float mainPart, out float modPart, highp float data) {\nmainPart = fract(data);\nmodPart = data - mainPart;\n}\nhighp float unpackHighpData (float mainPart, float modPart, const float modValue) {\nhighp float data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nvoid packHighpData (out float mainPart, out float modPart, highp float data, const float modValue) {\nhighp float divide = data / modValue;\nmainPart = floor(divide);\nmodPart = (data - mainPart * modValue) / modValue;\n}\nhighp vec2 unpackHighpData (vec2 mainPart, vec2 modPart) {\nhighp vec2 data = mainPart;\nreturn data + modPart;\n}\nvoid packHighpData (out vec2 mainPart, out vec2 modPart, highp vec2 data) {\nmainPart = fract(data);\nmodPart = data - mainPart;\n}\nhighp vec2 unpackHighpData (vec2 mainPart, vec2 modPart, const float modValue) {\nhighp vec2 data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nvoid packHighpData (out vec2 mainPart, out vec2 modPart, highp vec2 data, const float modValue) {\nhighp vec2 divide = data / modValue;\nmainPart = floor(divide);\nmodPart = (data - mainPart * modValue) / modValue;\n}\nhighp vec3 unpackHighpData (vec3 mainPart, vec3 modPart) {\nhighp vec3 data = mainPart;\nreturn data + modPart;\n}\nvoid packHighpData (out vec3 mainPart, out vec3 modPart, highp vec3 data) {\nmainPart = fract(data);\nmodPart = data - mainPart;\n}\nhighp vec3 unpackHighpData (vec3 mainPart, vec3 modPart, const float modValue) {\nhighp vec3 data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nvoid packHighpData (out vec3 mainPart, out vec3 modPart, highp vec3 data, const float modValue) {\nhighp vec3 divide = data / modValue;\nmainPart = floor(divide);\nmodPart = (data - mainPart * modValue) / modValue;\n}\nhighp vec4 unpackHighpData (vec4 mainPart, vec4 modPart) {\nhighp vec4 data = mainPart;\nreturn data + modPart;\n}\nvoid packHighpData (out vec4 mainPart, out vec4 modPart, highp vec4 data) {\nmainPart = fract(data);\nmodPart = data - mainPart;\n}\nhighp vec4 unpackHighpData (vec4 mainPart, vec4 modPart, const float modValue) {\nhighp vec4 data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nvoid packHighpData (out vec4 mainPart, out vec4 modPart, highp vec4 data, const float modValue) {\nhighp vec4 divide = data / modValue;\nmainPart = floor(divide);\nmodPart = (data - mainPart * modValue) / modValue;\n}\nlayout(set = 2, binding = 0) uniform CCLocal {\nhighp mat4 cc_matWorld;\nhighp mat4 cc_matWorldIT;\nhighp vec4 cc_lightingMapUVParam;\nhighp vec4 cc_localShadowBias;\n};\nfloat CCGetLinearDepthFromViewSpace(vec3 viewPos) {\nfloat dist = length(viewPos);\nreturn (dist - cc_shadowNFLSInfo.x) / (cc_shadowNFLSInfo.y - cc_shadowNFLSInfo.x);\n}\nfloat CCGetLinearDepth(vec3 worldPos) {\nvec4 viewStartPos = cc_matLightView * vec4(worldPos.xyz, 1.0);\nreturn CCGetLinearDepthFromViewSpace(viewStartPos.xyz);\n}\n#if CC_RECEIVE_SHADOW\nlayout(set = 0, binding = 3) uniform highp sampler2D cc_shadowMap;\nlayout(set = 0, binding = 5) uniform highp sampler2D cc_spotLightingMap;\nvec4 ApplyShadowDepthBias_FaceNormal(vec4 shadowPos, vec3 worldNormal, float normalBias)\n{\nvec4 newShadowPos = shadowPos;\nif(normalBias > EPSILON_LOWP)\n{\nvec4 viewNormal = cc_matLightView * vec4(worldNormal, 0.0);\nif(viewNormal.z < 0.1)\nnewShadowPos.xy += viewNormal.xy * cc_shadowProjInfo.xy * normalBias * clamp(viewNormal.z, 0.001, 0.1);\n}\nreturn newShadowPos;\n}\nvec4 ApplyShadowDepthBias_Perspective(vec4 shadowPos, float viewspaceDepthBias)\n{\nvec3 viewSpacePos;\nviewSpacePos.xy = shadowPos.xy * cc_shadowProjInfo.zw;\nviewSpacePos.z = shadowPos.z * cc_shadowInvProjDepthInfo.x + shadowPos.w * cc_shadowInvProjDepthInfo.y;\nviewSpacePos.xyz += cc_shadowProjDepthInfo.z * normalize(viewSpacePos.xyz) * viewspaceDepthBias;\nvec4 clipSpacePos;\nclipSpacePos.xy = viewSpacePos.xy * cc_shadowProjInfo.xy;\nclipSpacePos.zw = viewSpacePos.z * cc_shadowProjDepthInfo.xz + vec2(cc_shadowProjDepthInfo.y, 0.0);\nif (cc_shadowNFLSInfo.z > EPSILON) {\nclipSpacePos.z = CCGetLinearDepthFromViewSpace(viewSpacePos.xyz);\nclipSpacePos.z = (clipSpacePos.z * 2.0 - 1.0) * clipSpacePos.w;\n}\nreturn clipSpacePos;\n}\nvec4 ApplyShadowDepthBias_Orthographic(vec4 shadowPos, float viewspaceDepthBias)\n{\nfloat coeffA = cc_shadowProjDepthInfo.x;\nfloat coeffB = cc_shadowProjDepthInfo.y;\nfloat viewSpacePos_z = (shadowPos.z - coeffB) / coeffA;\nviewSpacePos_z += viewspaceDepthBias;\nvec4 result = shadowPos;\nresult.z = viewSpacePos_z * coeffA + coeffB;\nreturn result;\n}\nfloat CCGetShadowFactorHard (vec4 shadowPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Orthographic(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat shadow = 0.0;\nfloat closestDepth = 0.0;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nclosestDepth = dot(texture(cc_shadowMap, clipPos.xy), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0));\n} else {\nclosestDepth = texture(cc_shadowMap, clipPos.xy).x;\n}\nshadow = step(clipPos.z, closestDepth);\nreturn shadow;\n}\nfloat CCGetShadowFactorSoft (vec4 shadowPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Orthographic(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat offsetDepth = clipPos.z;\nvec2 mapSize = cc_shadowWHPBInfo.xy;\nvec2 oneTap = 1.0 / mapSize;\nvec2 clipPos_offset = clipPos.xy + oneTap;\nfloat block0, block1, block2, block3;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos.y)).x);\nblock1 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset.x, clipPos.y)).x);\nblock2 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset.y)).x);\nblock3 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset.x, clipPos_offset.y)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * mapSize.x;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block2, block3, coefX);\nfloat coefY = mod(clipPos.y, oneTap.y) * mapSize.y;\nreturn mix(resultX, resultY, coefY);\n}\nfloat CCGetShadowFactorSoft2X (vec4 shadowPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Orthographic(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat offsetDepth = clipPos.z;\nvec2 mapSize = cc_shadowWHPBInfo.xy;\nvec2 oneTap = 1.0 / mapSize;\nfloat clipPos_offset_L = clipPos.x - oneTap.x;\nfloat clipPos_offset_R = clipPos.x + oneTap.x;\nfloat clipPos_offset_U = clipPos.y - oneTap.y;\nfloat clipPos_offset_D = clipPos.y + oneTap.y;\nfloat block0, block1, block2, block3, block4, block5, block6, block7, block8;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock4 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock5 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock6 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock7 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock8 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_U)).x);\nblock1 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset_U)).x);\nblock2 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_U)).x);\nblock3 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos.y)).x);\nblock4 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos.y)).x);\nblock5 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos.y)).x);\nblock6 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_D)).x);\nblock7 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset_D)).x);\nblock8 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_D)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * mapSize.x;\nfloat coefY = mod(clipPos.y, oneTap.y) * mapSize.y;\nfloat shadow = 0.0;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block3, block4, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block1, block2, coefX);\nresultY = mix(block4, block5, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block3, block4, coefX);\nresultY = mix(block6, block7, coefX);\nshadow += mix(resultX, resultY, coefY);\nresultX = mix(block4, block5, coefX);\nresultY = mix(block7, block8, coefX);\nshadow += mix(resultX, resultY, coefY);\nreturn shadow * 0.25;\n}\nfloat CCGetSpotLightShadowFactorHard (vec4 shadowPos, vec3 worldPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Perspective(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat shadow = 0.0;\nfloat closestDepth = 0.0;\nfloat depth = clipPos.z;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nclosestDepth = dot(texture(cc_spotLightingMap, clipPos.xy), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0));\n} else {\nclosestDepth = texture(cc_spotLightingMap, clipPos.xy).x;\n}\nshadow = step(depth, closestDepth);\nreturn shadow;\n}\nfloat CCGetSpotLightShadowFactorSoft (vec4 shadowPos, vec3 worldPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Perspective(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat depth = 0.0;\nif (cc_shadowNFLSInfo.z > EPSILON) {\ndepth = CCGetLinearDepth(worldPos);\n} else {\ndepth = clipPos.z;\n}\nvec2 oneTap = 1.0 / cc_shadowWHPBInfo.xy;\nvec2 clipPos_offset = clipPos.xy + oneTap;\nfloat block0, block1, block2, block3;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)).x);\nblock1 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos.y)).x);\nblock2 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset.y)).x);\nblock3 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos_offset.y)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * cc_shadowWHPBInfo.x;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block2, block3, coefX);\nfloat coefY = mod(clipPos.y, oneTap.y) * cc_shadowWHPBInfo.y;\nreturn mix(resultX, resultY, coefY);\n}\nfloat CCGetSpotLightShadowFactorSoft2X (vec4 shadowPos, vec3 worldPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Perspective(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat depth = 0.0;\nif (cc_shadowNFLSInfo.z > EPSILON) {\ndepth = CCGetLinearDepth(worldPos);\n} else {\ndepth = clipPos.z;\n}\nvec2 mapSize = cc_shadowWHPBInfo.xy;\nvec2 oneTap = 1.0 / mapSize;\nfloat clipPos_offset_L = clipPos.x - oneTap.x;\nfloat clipPos_offset_R = clipPos.x + oneTap.x;\nfloat clipPos_offset_U = clipPos.y - oneTap.y;\nfloat clipPos_offset_D = clipPos.y + oneTap.y;\nfloat block0, block1, block2, block3, block4, block5, block6, block7, block8;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock4 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock5 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock6 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock7 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock8 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_U)).x);\nblock1 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_U)).x);\nblock2 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_U)).x);\nblock3 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos.y)).x);\nblock4 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)).x);\nblock5 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos.y)).x);\nblock6 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_D)).x);\nblock7 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_D)).x);\nblock8 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_D)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * mapSize.x;\nfloat coefY = mod(clipPos.y, oneTap.y) * mapSize.y;\nfloat shadow = 0.0;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block3, block4, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block1, block2, coefX);\nresultY = mix(block4, block5, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block3, block4, coefX);\nresultY = mix(block6, block7, coefX);\nshadow += mix(resultX, resultY, coefY);\nresultX = mix(block4, block5, coefX);\nresultY = mix(block7, block8, coefX);\nshadow += mix(resultX, resultY, coefY);\nreturn shadow * 0.25;\n}\nfloat CCSpotShadowFactorBase(vec4 shadowPos, vec3 worldPos, vec2 shadowBias)\n{\nfloat pcf = cc_shadowWHPBInfo.z;\nif (pcf > 1.9) {\nreturn CCGetSpotLightShadowFactorSoft2X(shadowPos, worldPos, shadowBias.x);\n}else if (pcf > 0.9) {\nreturn CCGetSpotLightShadowFactorSoft(shadowPos, worldPos, shadowBias.x);\n}else {\nreturn CCGetSpotLightShadowFactorHard(shadowPos, worldPos, shadowBias.x);\n}\n}\nfloat CCShadowFactorBase(vec4 shadowPos, vec3 N, vec2 shadowBias)\n{\nfloat realtimeShadow = 1.0;\nvec4 pos = ApplyShadowDepthBias_FaceNormal(shadowPos, N, shadowBias.y);\nfloat pcf = cc_shadowWHPBInfo.z;\nif (pcf > 1.9) {\nrealtimeShadow = CCGetShadowFactorSoft2X(pos, shadowBias.x);\n}else if (pcf > 0.9) {\nrealtimeShadow = CCGetShadowFactorSoft(pos, shadowBias.x);\n}else {\nrealtimeShadow = CCGetShadowFactorHard(pos, shadowBias.x);\n}\nreturn mix(realtimeShadow, 1.0, cc_shadowNFLSInfo.w);\n}\n#endif\n#if CC_USE_IBL\nlayout(set = 0, binding = 4) uniform samplerCube cc_environment;\nvec4 fragTextureLod (sampler2D tex, vec2 coord, float lod) {\nreturn textureLod(tex, coord, lod);\n}\nvec4 fragTextureLod (samplerCube tex, vec3 coord, float lod) {\nreturn textureLod(tex, coord, lod);\n}\nvec3 unpackRGBE (vec4 rgbe) {\nreturn rgbe.rgb * pow(1.1, rgbe.a * 255.0 - 128.0);\n}\n#if CC_USE_DIFFUSEMAP\nlayout(set = 0, binding = 6) uniform samplerCube cc_diffuseMap;\n#endif\n#endif\nfloat GGXMobile (float roughness, float NoH, vec3 H, vec3 N) {\nvec3 NxH = cross(N, H);\nfloat OneMinusNoHSqr = dot(NxH, NxH);\nfloat a = roughness * roughness;\nfloat n = NoH * a;\nfloat p = a / (OneMinusNoHSqr + n * n);\nreturn p * p;\n}\nfloat CalcSpecular (float roughness, float NoH, vec3 H, vec3 N) {\nreturn (roughness * 0.25 + 0.25) * GGXMobile(roughness, NoH, H, N);\n}\nvec3 BRDFApprox (vec3 specular, float roughness, float NoV) {\nconst vec4 c0 = vec4(-1.0, -0.0275, -0.572, 0.022);\nconst vec4 c1 = vec4(1.0, 0.0425, 1.04, -0.04);\nvec4 r = roughness * c0 + c1;\nfloat a004 = min(r.x * r.x, exp2(-9.28 * NoV)) * r.x + r.y;\nvec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;\nAB.y *= clamp(50.0 * specular.g, 0.0, 1.0);\nreturn specular * AB.x + AB.y;\n}\n#if USE_REFLECTION_DENOISE\nvec3 GetEnvReflectionWithMipFiltering(vec3 R, float roughness, float mipCount, float denoiseIntensity) {\n#if CC_USE_IBL\nfloat mip = roughness * mipCount;\nfloat delta = (dot(dFdx(R), dFdy(R))) * 1000.0;\nfloat mipBias = mix(0.0, 5.0, clamp(delta, 0.0, 1.0));\nvec4 biased = fragTextureLod(cc_environment, R, mip + mipBias);\nvec4 filtered = texture(cc_environment, R);\n#if CC_USE_IBL == 2\nbiased.rgb = unpackRGBE(biased);\nfiltered.rgb = unpackRGBE(filtered);\n#else\nbiased.rgb = SRGBToLinear(biased.rgb);\nfiltered.rgb = SRGBToLinear(filtered.rgb);\n#endif\nreturn mix(biased.rgb, filtered.rgb, denoiseIntensity);\n#else\nreturn vec3(0.0, 0.0, 0.0);\n#endif\n}\n#endif\nstruct StandardSurface {\nvec4 albedo;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nvec3 position, position_fract_part;\n#else\nvec3 position;\n#endif\nvec3 normal;\nvec3 emissive;\nvec3 lightmap;\nfloat lightmap_test;\nfloat roughness;\nfloat metallic;\nfloat occlusion;\nfloat specularIntensity;\n#if CC_RECEIVE_SHADOW\nvec2 shadowBias;\n#endif\n};\nvec4 CCStandardShadingBase (StandardSurface s, vec4 shadowPos) {\nvec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\nvec3 specular = mix(vec3(0.08 * s.specularIntensity), s.albedo.rgb, s.metallic);\nvec3 position;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nposition = unpackHighpData(s.position, s.position_fract_part);\n#else\nposition = s.position;\n#endif\nvec3 N = normalize(s.normal);\nvec3 V = normalize(cc_cameraPos.xyz - position);\nfloat NV = max(abs(dot(N, V)), 0.0);\nspecular = BRDFApprox(specular, s.roughness, NV);\nvec3 L = normalize(-cc_mainLitDir.xyz);\nvec3 H = normalize(L + V);\nfloat NH = max(dot(N, H), 0.0);\nfloat NL = max(dot(N, L), 0.0);\nvec3 finalColor = NL * cc_mainLitColor.rgb * cc_mainLitColor.w;\nvec3 diffuseContrib = diffuse / PI;\nvec3 specularContrib = specular * CalcSpecular(s.roughness, NH, H, N);\nvec3 dirlightContrib = (diffuseContrib + specularContrib);\nfloat shadow = 1.0;\n#if CC_RECEIVE_SHADOW\nif (NL > 0.0 && cc_mainLitDir.w > 0.0) {\nshadow = CCShadowFactorBase(shadowPos, N, s.shadowBias);\n}\n#endif\ndirlightContrib *= shadow;\nfinalColor *= dirlightContrib;\n#if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\nif (s.lightmap_test > EPSILON_LOWP) {\nfinalColor = diffuse * s.lightmap.rgb * shadow;\n}\n#endif\nfloat fAmb = 0.5 - N.y * 0.5;\nvec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb);\n#if CC_USE_IBL\n#if CC_USE_DIFFUSEMAP\nvec4 diffuseMap = texture(cc_diffuseMap, N);\n#if CC_USE_DIFFUSEMAP == 2\nambDiff = unpackRGBE(diffuseMap);\n#else\nambDiff = SRGBToLinear(diffuseMap.rgb);\n#endif\n#endif\nvec3 R = normalize(reflect(-V, N));\n#if USE_REFLECTION_DENOISE\nvec3 env = GetEnvReflectionWithMipFiltering(R, s.roughness, cc_ambientGround.w, 0.6);\n#else\nvec4 envmap = fragTextureLod(cc_environment, R, s.roughness * cc_ambientGround.w);\n#if CC_USE_IBL == 2\nvec3 env = unpackRGBE(envmap);\n#else\nvec3 env = SRGBToLinear(envmap.rgb);\n#endif\n#endif\nfinalColor += env * cc_ambientSky.w * specular * s.occlusion;\n#endif\nfinalColor += ambDiff.rgb * cc_ambientSky.w * diffuse * s.occlusion;\nfinalColor += s.emissive;\nreturn vec4(finalColor, s.albedo.a);\n}\nvec3 ACESToneMap (vec3 color) {\ncolor = min(color, vec3(8.0));\nconst float A = 2.51;\nconst float B = 0.03;\nconst float C = 2.43;\nconst float D = 0.59;\nconst float E = 0.14;\nreturn (color * (A * color + B)) / (color * (C * color + D) + E);\n}\nvec4 CCFragOutput (vec4 color) {\n#if CC_USE_HDR\ncolor.rgb = ACESToneMap(color.rgb);\n#endif\ncolor.rgb = sqrt(color.rgb);\nreturn color;\n}\nfloat LinearFog(vec4 pos) {\nvec4 wPos = pos;\nfloat cam_dis = distance(cc_cameraPos, wPos);\nfloat fogStart = cc_fogBase.x;\nfloat fogEnd = cc_fogBase.y;\nreturn clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * fogDensity);\nreturn f;\n}\nfloat ExpSquaredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\nreturn f;\n}\nfloat LayeredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat _FogTop = cc_fogAdd.x;\nfloat _FogRange = cc_fogAdd.y;\nvec3 camWorldProj = cc_cameraPos.xyz;\ncamWorldProj.y = 0.;\nvec3 worldPosProj = wPos.xyz;\nworldPosProj.y = 0.;\nfloat fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\nfloat fDeltaY, fDensityIntegral;\nif (cc_cameraPos.y > _FogTop) {\nif (wPos.y < _FogTop) {\nfDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\nfDensityIntegral = fDeltaY * fDeltaY * 0.5;\n} else {\nfDeltaY = 0.;\nfDensityIntegral = 0.;\n}\n} else {\nif (wPos.y < _FogTop) {\nfloat fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfloat fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\nfDeltaY = abs(fDeltaA - fDeltaB);\nfDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n} else {\nfDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n}\n}\nfloat fDensity;\nif (fDeltaY != 0.) {\nfDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n} else {\nfDensity = 0.;\n}\nfloat f = exp(-fDensity);\nreturn f;\n}\nvoid CC_TRANSFER_FOG_BASE(vec4 pos, out float factor)\n{\n#if CC_USE_FOG == 0\nfactor = LinearFog(pos);\n#elif CC_USE_FOG == 1\nfactor = ExpFog(pos);\n#elif CC_USE_FOG == 2\nfactor = ExpSquaredFog(pos);\n#elif CC_USE_FOG == 3\nfactor = LayeredFog(pos);\n#else\nfactor = 1.0;\n#endif\n}\nvoid CC_APPLY_FOG_BASE(inout vec4 color, float factor) {\ncolor = vec4(mix(cc_fogColor.rgb, color.rgb, factor), color.a);\n}\n#if !CC_USE_ACCURATE_FOG\nlayout(location = 0) in float v_fog_factor;\n#endif\nvoid CC_APPLY_FOG(inout vec4 color) {\n#if !CC_USE_ACCURATE_FOG\nCC_APPLY_FOG_BASE(color, v_fog_factor);\n#endif\n}\nvoid CC_APPLY_FOG(inout vec4 color, vec3 worldPos) {\n#if CC_USE_ACCURATE_FOG\nfloat factor;\nCC_TRANSFER_FOG_BASE(vec4(worldPos, 1.0), factor);\n#else\nfloat factor = v_fog_factor;\n#endif\nCC_APPLY_FOG_BASE(color, factor);\n}\nlayout(location = 1) in highp vec4 v_shadowPos;\n#if CC_RECEIVE_SHADOW\n#endif\n#if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\nlayout(location = 12) in vec3 v_luv;\nlayout(set = 2, binding = 10) uniform sampler2D cc_lightingMap;\n#endif\nlayout(location = 3) in highp vec3 v_position;\nlayout(location = 4) in mediump vec3 v_normal;\n#if CC_RECEIVE_SHADOW\nlayout(location = 2) in vec2 v_shadowBias;\n#endif\nlayout(location = 5) in mediump vec2 uvw;\nlayout(location = 6) in mediump vec2 uv0;\nlayout(location = 7) in mediump vec2 uv1;\nlayout(location = 8) in mediump vec2 uv2;\nlayout(location = 9) in mediump vec2 uv3;\nlayout(location = 11) in mediump vec3 diffuse;\nlayout(location = 10) in mediump vec3 luv;\nlayout(set = 1, binding = 1) uniform PbrParams {\nvec4 metallic;\nvec4 roughness;\n};\nlayout(set = 1, binding = 2) uniform sampler2D weightMap;\nlayout(set = 1, binding = 3) uniform sampler2D detailMap0;\nlayout(set = 1, binding = 4) uniform sampler2D detailMap1;\nlayout(set = 1, binding = 5) uniform sampler2D detailMap2;\nlayout(set = 1, binding = 6) uniform sampler2D detailMap3;\nlayout(set = 1, binding = 7) uniform sampler2D normalMap0;\nlayout(set = 1, binding = 8) uniform sampler2D normalMap1;\nlayout(set = 1, binding = 9) uniform sampler2D normalMap2;\nlayout(set = 1, binding = 10) uniform sampler2D normalMap3;\nlayout(set = 1, binding = 11) uniform sampler2D lightMap;\nvoid surf (out StandardSurface s) {\n#if LAYERS > 1\nvec4 w = texture(weightMap, uvw);\n#endif\nvec4 baseColor = vec4(0, 0, 0, 0);\n#if LAYERS == 1\nbaseColor = texture(detailMap0, uv0);\n#elif LAYERS == 2\nbaseColor += texture(detailMap0, uv0) * w.r;\nbaseColor += texture(detailMap1, uv1) * w.g;\n#elif LAYERS == 3\nbaseColor += texture(detailMap0, uv0) * w.r;\nbaseColor += texture(detailMap1, uv1) * w.g;\nbaseColor += texture(detailMap2, uv2) * w.b;\n#elif LAYERS == 4\nbaseColor += texture(detailMap0, uv0) * w.r;\nbaseColor += texture(detailMap1, uv1) * w.g;\nbaseColor += texture(detailMap2, uv2) * w.b;\nbaseColor += texture(detailMap3, uv3) * w.a;\n#else\nbaseColor = texture(detailMap0, uv0);\n#endif\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\npackHighpData(s.position, s.position_fract_part, v_position);\n#else\ns.position = v_position;\n#endif\n#if USE_NORMALMAP\nvec4 baseNormal = vec4(0, 0, 0, 0);\n#if LAYERS == 1\nbaseNormal = texture(normalMap0, uv0);\n#elif LAYERS == 2\nbaseNormal += texture(normalMap0, uv0) * w.r;\nbaseNormal += texture(normalMap1, uv1) * w.g;\n#elif LAYERS == 3\nbaseNormal += texture(normalMap0, uv0) * w.r;\nbaseNormal += texture(normalMap1, uv1) * w.g;\nbaseNormal += texture(normalMap2, uv2) * w.b;\n#elif LAYERS == 4\nbaseNormal += texture(normalMap0, uv0) * w.r;\nbaseNormal += texture(normalMap1, uv1) * w.g;\nbaseNormal += texture(normalMap2, uv2) * w.b;\nbaseNormal += texture(normalMap3, uv3) * w.a;\n#else\nbaseNormal = texture(normalMap0, uv0);\n#endif\nvec3 tangent = vec3(1.0, 0.0, 0.0);\nvec3 binormal = vec3(0.0, 0.0, 1.0);\nbinormal = cross(tangent, v_normal);\ntangent = cross(v_normal, binormal);\nvec3 nmmp = baseNormal.xyz - vec3(0.5);\ns.normal =\nnmmp.x * normalize(tangent) +\nnmmp.y * normalize(binormal) +\nnmmp.z * normalize(v_normal);\n#else\ns.normal = v_normal;\n#endif\n#if CC_RECEIVE_SHADOW\ns.shadowBias = v_shadowBias;\n#endif\ns.albedo = vec4(SRGBToLinear(baseColor.rgb), 1.0);\ns.occlusion = 1.0;\n#if USE_PBR\ns.roughness = 0.0;\n#if LAYERS == 1\ns.roughness = roughness.x;\n#elif LAYERS == 2\ns.roughness += roughness.x * w.r;\ns.roughness += roughness.y * w.g;\n#elif LAYERS == 3\ns.roughness += roughness.x * w.r;\ns.roughness += roughness.y * w.g;\ns.roughness += roughness.z * w.b;\n#elif LAYERS == 4\ns.roughness += roughness.x * w.r;\ns.roughness += roughness.y * w.g;\ns.roughness += roughness.z * w.b;\ns.roughness += roughness.w * w.a;\n#else\ns.roughness = 1.0;\n#endif\ns.specularIntensity = 0.5;\ns.metallic = 0.0;\n#if LAYERS == 1\ns.specularIntensity = 0.5;\ns.metallic = metallic.x;\n#elif LAYERS == 2\ns.metallic += metallic.x * w.r;\ns.metallic += metallic.y * w.g;\n#elif LAYERS == 3\ns.metallic += metallic.x * w.r;\ns.metallic += metallic.y * w.g;\ns.metallic += metallic.z * w.b;\n#elif LAYERS == 4\ns.metallic += metallic.x * w.r;\ns.metallic += metallic.y * w.g;\ns.metallic += metallic.z * w.b;\ns.metallic += metallic.w * w.a;\n#else\ns.specularIntensity = 0.5;\ns.metallic = 0.0;\n#endif\n#else\ns.roughness = 1.0;\ns.specularIntensity = 0.5;\ns.metallic = 0.0;\n#endif\ns.emissive = vec3(0.0, 0.0, 0.0);\n#if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\nvec4 lightColor = texture(lightMap, luv.xy);\ns.lightmap = lightColor.xyz * luv.z;\ns.lightmap_test = luv.z;\n#endif\n}\n#if CC_FORWARD_ADD\n#if CC_PIPELINE_TYPE == 0\n#define LIGHTS_PER_PASS 1\n#else\n#define LIGHTS_PER_PASS 10\n#endif\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 0\nlayout(set = 2, binding = 1) uniform CCForwardLight {\nhighp vec4 cc_lightPos[LIGHTS_PER_PASS];\nvec4 cc_lightColor[LIGHTS_PER_PASS];\nvec4 cc_lightSizeRangeAngle[LIGHTS_PER_PASS];\nvec4 cc_lightDir[LIGHTS_PER_PASS];\n};\n#endif\nfloat SmoothDistAtt (float distSqr, float invSqrAttRadius) {\nfloat factor = distSqr * invSqrAttRadius;\nfloat smoothFactor = clamp(1.0 - factor * factor, 0.0, 1.0);\nreturn smoothFactor * smoothFactor;\n}\nfloat GetDistAtt (float distSqr, float invSqrAttRadius) {\nfloat attenuation = 1.0 / max(distSqr, 0.01*0.01);\nattenuation *= SmoothDistAtt(distSqr , invSqrAttRadius);\nreturn attenuation;\n}\nfloat GetAngleAtt (vec3 L, vec3 litDir, float litAngleScale, float litAngleOffset) {\nfloat cd = dot(litDir, L);\nfloat attenuation = clamp(cd * litAngleScale + litAngleOffset, 0.0, 1.0);\nreturn (attenuation * attenuation);\n}\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 0\nvec4 CCStandardShadingAdditive (StandardSurface s, vec4 shadowPos) {\nvec3 position;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nposition = unpackHighpData(s.position, s.position_fract_part);\n#else\nposition = s.position;\n#endif\nvec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\nvec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\nvec3 diffuseContrib = diffuse / PI;\nvec3 N = normalize(s.normal);\nvec3 V = normalize(cc_cameraPos.xyz - position);\nfloat NV = max(abs(dot(N, V)), 0.0);\nspecular = BRDFApprox(specular, s.roughness, NV);\nvec3 finalColor = vec3(0.0);\nint numLights = CC_PIPELINE_TYPE == 0 ? LIGHTS_PER_PASS : int(cc_lightDir[0].w);\nfor (int i = 0; i < LIGHTS_PER_PASS; i++) {\nif (i >= numLights) break;\nvec3 SLU = cc_lightPos[i].xyz - position;\nvec3 SL = normalize(SLU);\nvec3 SH = normalize(SL + V);\nfloat SNL = max(dot(N, SL), 0.0);\nfloat SNH = max(dot(N, SH), 0.0);\nfloat distSqr = dot(SLU, SLU);\nfloat litRadius = cc_lightSizeRangeAngle[i].x;\nfloat litRadiusSqr = litRadius * litRadius;\nfloat illum = litRadiusSqr / max(litRadiusSqr, distSqr);\nfloat attRadiusSqrInv = 1.0 / max(cc_lightSizeRangeAngle[i].y, 0.01);\nattRadiusSqrInv *= attRadiusSqrInv;\nfloat att = GetDistAtt(distSqr, attRadiusSqrInv);\nvec3 lspec = specular * CalcSpecular(s.roughness, SNH, SH, N);\nif (cc_lightPos[i].w > 0.0) {\nfloat cosInner = max(dot(-cc_lightDir[i].xyz, SL), 0.01);\nfloat cosOuter = cc_lightSizeRangeAngle[i].z;\nfloat litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\nfloat litAngleOffset = -cosOuter * litAngleScale;\natt *= GetAngleAtt(SL, -cc_lightDir[i].xyz, litAngleScale, litAngleOffset);\n}\nvec3 lightColor = cc_lightColor[i].rgb;\nfloat shadow = 1.0;\n#if CC_RECEIVE_SHADOW\nif (cc_lightPos[i].w > 0.0 && cc_lightSizeRangeAngle[i].w > 0.0) {\nshadow = CCSpotShadowFactorBase(shadowPos, position, s.shadowBias);\n}\n#endif\nlightColor *= shadow;\nfinalColor += SNL * lightColor * cc_lightColor[i].w * illum * att * (diffuseContrib + lspec);\n}\nreturn vec4(finalColor, 0.0);\n}\n#endif\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 1\nlayout(set = 1, binding = 12) readonly buffer b_ccLightsBuffer { vec4 b_ccLights[]; };\nlayout(set = 1, binding = 13) readonly buffer b_clusterLightIndicesBuffer { uint b_clusterLightIndices[]; };\nlayout(set = 1, binding = 14) readonly buffer b_clusterLightGridBuffer { uvec4 b_clusterLightGrid[]; };\nstruct CCLight\n{\nvec4 cc_lightPos;\nvec4 cc_lightColor;\nvec4 cc_lightSizeRangeAngle;\nvec4 cc_lightDir;\n};\nstruct Cluster\n{\nvec3 minBounds;\nvec3 maxBounds;\n};\nstruct LightGrid\n{\nuint offset;\nuint ccLights;\n};\nCCLight getCCLight(uint i)\n{\nCCLight light;\nlight.cc_lightPos = b_ccLights[4u * i + 0u];\nlight.cc_lightColor = b_ccLights[4u * i + 1u];\nlight.cc_lightSizeRangeAngle = b_ccLights[4u * i + 2u];\nlight.cc_lightDir = b_ccLights[4u * i + 3u];\nreturn light;\n}\nLightGrid getLightGrid(uint cluster)\n{\nuvec4 gridvec = b_clusterLightGrid[cluster];\nLightGrid grid;\ngrid.offset = gridvec.x;\ngrid.ccLights = gridvec.y;\nreturn grid;\n}\nuint getGridLightIndex(uint start, uint offset)\n{\nreturn b_clusterLightIndices[start + offset];\n}\nuint getClusterZIndex(vec4 worldPos)\n{\nfloat scale = float(24) / log(cc_nearFar.y / cc_nearFar.x);\nfloat bias = -(float(24) * log(cc_nearFar.x) / log(cc_nearFar.y / cc_nearFar.x));\nfloat eyeDepth = -(cc_matView * worldPos).z;\nuint zIndex = uint(max(log(eyeDepth) * scale + bias, 0.0));\nreturn zIndex;\n}\nuint getClusterIndex(vec4 fragCoord, vec4 worldPos)\n{\nuint zIndex = getClusterZIndex(worldPos);\nfloat clusterSizeX = ceil(cc_viewPort.z / float(16));\nfloat clusterSizeY = ceil(cc_viewPort.w / float(8));\nuvec3 indices = uvec3(uvec2(fragCoord.xy / vec2(clusterSizeX, clusterSizeY)), zIndex);\nuint cluster = (16u * 8u) * indices.z + 16u * indices.y + indices.x;\nreturn cluster;\n}\nvec4 CCClusterShadingAdditive (StandardSurface s, vec4 shadowPos) {\nvec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\nvec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\nvec3 diffuseContrib = diffuse / PI;\nvec3 position;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nposition = unpackHighpData(s.position, s.position_fract_part);\n#else\nposition = s.position;\n#endif\nvec3 N = normalize(s.normal);\nvec3 V = normalize(cc_cameraPos.xyz - position);\nfloat NV = max(abs(dot(N, V)), 0.001);\nspecular = BRDFApprox(specular, s.roughness, NV);\nvec3 finalColor = vec3(0.0);\nuint cluster = getClusterIndex(gl_FragCoord, vec4(position, 1.0));\nLightGrid grid = getLightGrid(cluster);\nuint numLights = grid.ccLights;\nfor (uint i = 0u; i < 100u; i++) {\nif (i >= numLights) break;\nuint lightIndex = getGridLightIndex(grid.offset, i);\nCCLight light = getCCLight(lightIndex);\nvec3 SLU = light.cc_lightPos.xyz - position;\nvec3 SL = normalize(SLU);\nvec3 SH = normalize(SL + V);\nfloat SNL = max(dot(N, SL), 0.001);\nfloat SNH = max(dot(N, SH), 0.0);\nfloat distSqr = dot(SLU, SLU);\nfloat litRadius = light.cc_lightSizeRangeAngle.x;\nfloat litRadiusSqr = litRadius * litRadius;\nfloat illum = PI * (litRadiusSqr / max(litRadiusSqr , distSqr));\nfloat attRadiusSqrInv = 1.0 / max(light.cc_lightSizeRangeAngle.y, 0.01);\nattRadiusSqrInv *= attRadiusSqrInv;\nfloat att = GetDistAtt(distSqr, attRadiusSqrInv);\nvec3 lspec = specular * CalcSpecular(s.roughness, SNH, SH, N);\nif (light.cc_lightPos.w > 0.0) {\nfloat cosInner = max(dot(-light.cc_lightDir.xyz, SL), 0.01);\nfloat cosOuter = light.cc_lightSizeRangeAngle.z;\nfloat litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\nfloat litAngleOffset = -cosOuter * litAngleScale;\natt *= GetAngleAtt(SL, -light.cc_lightDir.xyz, litAngleScale, litAngleOffset);\n}\nvec3 lightColor = light.cc_lightColor.rgb;\nfloat shadow = 1.0;\n#if CC_RECEIVE_SHADOW\nif (light.cc_lightPos.w > 0.0) {\nshadow = CCSpotShadowFactorBase(shadowPos, position, s.shadowBias);\n}\n#endif\nlightColor *= shadow;\nfinalColor += SNL * lightColor * light.cc_lightColor.w * illum * att * (diffuseContrib + lspec);\n}\nreturn vec4(finalColor, 0.0);\n}\n#endif\nlayout(location = 0) out vec4 fragColorX;\nvoid main () {\nStandardSurface s; surf(s);\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 1\nvec4 color = CCClusterShadingAdditive(s, v_shadowPos);\n#else\nvec4 color = CCStandardShadingAdditive(s, v_shadowPos);\n#endif\nfragColorX = CCFragOutput(color);\n}\n#elif (CC_PIPELINE_TYPE == 0 || CC_FORCE_FORWARD_SHADING)\nlayout(location = 0) out vec4 fragColorX;\nvoid main () {\nStandardSurface s; surf(s);\nvec4 color = CCStandardShadingBase(s, v_shadowPos);\nCC_APPLY_FOG(color, s.position.xyz);\nfragColorX = CCFragOutput(color);\n}\n#elif CC_PIPELINE_TYPE == 1\nvec2 signNotZero(vec2 v) {\nreturn vec2((v.x >= 0.0) ? +1.0 : -1.0, (v.y >= 0.0) ? +1.0 : -1.0);\n}\nvec2 float32x3_to_oct(in vec3 v) {\nvec2 p = v.xy * (1.0 / (abs(v.x) + abs(v.y) + abs(v.z)));\nreturn (v.z <= 0.0) ? ((1.0 - abs(p.yx)) * signNotZero(p)) : p;\n}\nlayout(location = 0) out vec4 fragColor0;\nlayout(location = 1) out vec4 fragColor1;\nlayout(location = 2) out vec4 fragColor2;\nvoid main () {\nStandardSurface s; surf(s);\nfragColor0 = s.albedo;\nfragColor1 = vec4(float32x3_to_oct(s.normal), s.roughness, s.metallic);\nfragColor2 = vec4(s.emissive, s.occlusion);\n}\n#endif", }, { "vert": "\nprecision highp float;\nlayout(set = 0, binding = 0) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(set = 0, binding = 1) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\nlayout(set = 2, binding = 0) uniform CCLocal {\nhighp mat4 cc_matWorld;\nhighp mat4 cc_matWorldIT;\nhighp vec4 cc_lightingMapUVParam;\nhighp vec4 cc_localShadowBias;\n};\nlayout(set = 0, binding = 2) uniform CCShadow {\nhighp mat4 cc_matLightPlaneProj;\nhighp mat4 cc_matLightView;\nhighp mat4 cc_matLightViewProj;\nhighp vec4 cc_shadowInvProjDepthInfo;\nhighp vec4 cc_shadowProjDepthInfo;\nhighp vec4 cc_shadowProjInfo;\nmediump vec4 cc_shadowNFLSInfo;\nmediump vec4 cc_shadowWHPBInfo;\nmediump vec4 cc_shadowLPNNInfo;\nlowp vec4 cc_shadowColor;\nmediump vec4 cc_planarNDInfo;\n};\nlayout(location = 0) in vec3 a_position;\nlayout(location = 1) in vec3 a_normal;\nlayout(location = 2) in vec2 a_texCoord;\nlayout(location = 0) out vec2 v_clip_depth;\nvec4 vert () {\nvec4 worldPos;\nworldPos.x = cc_matWorld[3][0] + a_position.x;\nworldPos.y = cc_matWorld[3][1] + a_position.y;\nworldPos.z = cc_matWorld[3][2] + a_position.z;\nworldPos.w = 1.0;\nvec4 clipPos = cc_matLightViewProj * worldPos;\nv_clip_depth = clipPos.zw;\nreturn clipPos;\n}\nvoid main() { gl_Position = vert(); }", @@ -108,49 +108,49 @@ export const glsl4 = [ ], [ { - "vert": "#extension GL_EXT_shader_explicit_arithmetic_types_int32: require\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\nrgba = rgba * 255.0;\nhighp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\nhighp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\nhighp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\nreturn Sign * exp2(Exponent - 23.0) * Mantissa;\n}\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nlayout(location = 0) in vec3 a_position;\nlayout(location = 1) in vec3 a_normal;\nlayout(location = 2) in vec2 a_texCoord;\nlayout(location = 3) in vec4 a_tangent;\n#if CC_USE_SKINNING\nlayout(location = 4) in u32vec4 a_joints;\nlayout(location = 5) in vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nlayout(location = 6) in highp vec4 a_jointAnimInfo;\n#endif\nlayout(location = 7) in vec4 a_matWorld0;\nlayout(location = 8) in vec4 a_matWorld1;\nlayout(location = 9) in vec4 a_matWorld2;\n#if USE_LIGHTMAP\nlayout(location = 10) in vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nlayout(location = 11) in vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nlayout(location = 12) in float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nint getVertexId() {\nreturn gl_VertexIndex;\n}\n#endif\n#if CC_USE_MORPH\nlayout(set = 2, binding = 4) uniform CCMorph {\nvec4 cc_displacementWeights[15];\nvec4 cc_displacementTextureInfo;\n};\nvec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\nfloat pixelIndexF = float(pixelIndex);\nfloat x = mod(pixelIndexF, textureResolution.x);\nfloat y = floor(pixelIndexF / textureResolution.x);\nreturn vec2(x, y);\n}\nvec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\nreturn (vec2(location.x, location.y) + .5) / textureResolution;\n}\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int pixelIndex) {\nivec2 texSize = textureSize(tex, 0);\nreturn texelFetch(tex, ivec2(pixelIndex % texSize.x, pixelIndex / texSize.x), 0);\n}\n#else\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex * 4;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\nreturn vec4(\ndecode32(texture(tex, x)),\ndecode32(texture(tex, y)),\ndecode32(texture(tex, z)),\n1.0\n);\n}\n#endif\nfloat getDisplacementWeight(int index) {\nint quot = index / 4;\nint remainder = index - quot * 4;\nif (remainder == 0) {\nreturn cc_displacementWeights[quot].x;\n} else if (remainder == 1) {\nreturn cc_displacementWeights[quot].y;\n} else if (remainder == 2) {\nreturn cc_displacementWeights[quot].z;\n} else {\nreturn cc_displacementWeights[quot].w;\n}\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\nreturn fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n#else\nvec3 result = vec3(0, 0, 0);\nint nVertices = int(cc_displacementTextureInfo.z);\nfor (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\nresult += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n}\nreturn result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\nlayout(set = 2, binding = 7) uniform sampler2D cc_PositionDisplacements;\nvec3 getPositionDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nlayout(set = 2, binding = 8) uniform sampler2D cc_NormalDisplacements;\nvec3 getNormalDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\nlayout(set = 2, binding = 9) uniform sampler2D cc_TangentDisplacements;\nvec3 getTangentDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n}\n#endif\nvoid applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nint vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nnormal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\ntangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\n#if CC_USE_BAKED_ANIMATION\nlayout(set = 2, binding = 3) uniform CCSkinningTexture {\nhighp vec4 cc_jointTextureInfo;\n};\nlayout(set = 2, binding = 2) uniform CCSkinningAnimation {\nhighp vec4 cc_jointAnimInfo;\n};\nlayout(set = 2, binding = 6) uniform highp sampler2D cc_jointTexture;\nvoid CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n{\n#if USE_INSTANCING\nhighp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n#else\nhighp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n#endif\ninvSize = cc_jointTextureInfo.w;\nhighp float tempY = floor(temp * invSize);\nx = floor(temp - tempY * cc_jointTextureInfo.x);\ny = (tempY + 0.5) * invSize;\n}\n#else\nlayout(set = 2, binding = 3) uniform CCSkinning {\nhighp vec4 cc_joints[30 * 3];\n};\n#endif\n#if CC_USE_BAKED_ANIMATION\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(3.0, i, x, y, invSize);\nvec4 v1 = texture(cc_jointTexture, vec2((x + 0.5) * invSize, y));\nvec4 v2 = texture(cc_jointTexture, vec2((x + 1.5) * invSize, y));\nvec4 v3 = texture(cc_jointTexture, vec2((x + 2.5) * invSize, y));\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#else\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(12.0, i, x, y, invSize);\nvec4 v1 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n);\nvec4 v2 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n);\nvec4 v3 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n);\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\n#else\nmat4 getJointMatrix (float i) {\nint idx = int(i);\nvec4 v1 = cc_joints[idx * 3];\nvec4 v2 = cc_joints[idx * 3 + 1];\nvec4 v3 = cc_joints[idx * 3 + 2];\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\nmat4 skinMatrix () {\nvec4 joints = vec4(a_joints);\nreturn getJointMatrix(joints.x) * a_weights.x\n+ getJointMatrix(joints.y) * a_weights.y\n+ getJointMatrix(joints.z) * a_weights.z\n+ getJointMatrix(joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\nmat4 m = skinMatrix();\nposition = m * position;\n}\nvoid CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nmat4 m = skinMatrix();\nposition = m * position;\nnormal = (m * vec4(normal, 0.0)).xyz;\ntangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n}\n#endif\nvoid CCVertInput(inout vec4 In)\n{\nIn = vec4(a_position, 1.0);\n#if CC_USE_MORPH\napplyMorph(In);\n#endif\n#if CC_USE_SKINNING\nCCSkin(In);\n#endif\n}\nlayout(set = 0, binding = 0) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(set = 0, binding = 1) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\n#if !USE_INSTANCING\n#if USE_BATCHING\nlayout(set = 2, binding = 0) uniform CCLocalBatched {\nhighp mat4 cc_matWorlds[10];\n};\n#else\nlayout(set = 2, binding = 0) uniform CCLocal {\nhighp mat4 cc_matWorld;\nhighp mat4 cc_matWorldIT;\nhighp vec4 cc_lightingMapUVParam;\nhighp vec4 cc_localShadowBias;\n};\n#endif\n#endif\nvoid CCGetWorldMatrix(out mat4 matWorld)\n{\n#if USE_INSTANCING\nmatWorld = mat4(\nvec4(a_matWorld0.xyz, 0.0),\nvec4(a_matWorld1.xyz, 0.0),\nvec4(a_matWorld2.xyz, 0.0),\nvec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)\n);\n#elif USE_BATCHING\nmatWorld = cc_matWorlds[int(a_dyn_batch_id)];\n#else\nmatWorld = cc_matWorld;\n#endif\n}\nfloat LinearFog(vec4 pos) {\nvec4 wPos = pos;\nfloat cam_dis = distance(cc_cameraPos, wPos);\nfloat fogStart = cc_fogBase.x;\nfloat fogEnd = cc_fogBase.y;\nreturn clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * fogDensity);\nreturn f;\n}\nfloat ExpSquaredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\nreturn f;\n}\nfloat LayeredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat _FogTop = cc_fogAdd.x;\nfloat _FogRange = cc_fogAdd.y;\nvec3 camWorldProj = cc_cameraPos.xyz;\ncamWorldProj.y = 0.;\nvec3 worldPosProj = wPos.xyz;\nworldPosProj.y = 0.;\nfloat fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\nfloat fDeltaY, fDensityIntegral;\nif (cc_cameraPos.y > _FogTop) {\nif (wPos.y < _FogTop) {\nfDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\nfDensityIntegral = fDeltaY * fDeltaY * 0.5;\n} else {\nfDeltaY = 0.;\nfDensityIntegral = 0.;\n}\n} else {\nif (wPos.y < _FogTop) {\nfloat fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfloat fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\nfDeltaY = abs(fDeltaA - fDeltaB);\nfDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n} else {\nfDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n}\n}\nfloat fDensity;\nif (fDeltaY != 0.) {\nfDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n} else {\nfDensity = 0.;\n}\nfloat f = exp(-fDensity);\nreturn f;\n}\nvoid CC_TRANSFER_FOG_BASE(vec4 pos, out float factor)\n{\n#if CC_USE_FOG == 0\nfactor = LinearFog(pos);\n#elif CC_USE_FOG == 1\nfactor = ExpFog(pos);\n#elif CC_USE_FOG == 2\nfactor = ExpSquaredFog(pos);\n#elif CC_USE_FOG == 3\nfactor = LayeredFog(pos);\n#else\nfactor = 1.0;\n#endif\n}\n#if !CC_USE_ACCURATE_FOG\nlayout(location = 0) out float v_fog_factor;\n#endif\nvoid CC_TRANSFER_FOG(vec4 pos) {\n#if !CC_USE_ACCURATE_FOG\nCC_TRANSFER_FOG_BASE(pos, v_fog_factor);\n#endif\n}\n#if USE_VERTEX_COLOR\nlayout(location = 14) in lowp vec4 a_color;\nlayout(location = 1) out lowp vec4 v_color;\n#endif\n#if USE_TEXTURE\nlayout(location = 2) out vec2 v_uv;\nlayout(set = 1, binding = 0) uniform TexCoords {\nvec4 tilingOffset;\n};\n#endif\nvec4 vert () {\nvec4 position;\nCCVertInput(position);\nmat4 matWorld;\nCCGetWorldMatrix(matWorld);\n#if USE_TEXTURE\nv_uv = a_texCoord * tilingOffset.xy + tilingOffset.zw;\n#if SAMPLE_FROM_RT\nv_uv = cc_cameraPos.w > 1.0 ? vec2(v_uv.x, 1.0 - v_uv.y) : v_uv;\n#endif\n#endif\n#if USE_VERTEX_COLOR\nv_color = a_color;\n#endif\nCC_TRANSFER_FOG(matWorld * position);\nreturn cc_matProj * (cc_matView * matWorld) * position;\n}\nvoid main() { gl_Position = vert(); }", + "vert": "#extension GL_EXT_shader_explicit_arithmetic_types_int32: require\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\nrgba = rgba * 255.0;\nhighp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\nhighp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\nhighp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\nreturn Sign * exp2(Exponent - 23.0) * Mantissa;\n}\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nlayout(location = 0) in vec3 a_position;\nlayout(location = 1) in vec3 a_normal;\nlayout(location = 2) in vec2 a_texCoord;\nlayout(location = 3) in vec4 a_tangent;\n#if CC_USE_SKINNING\nlayout(location = 4) in u32vec4 a_joints;\nlayout(location = 5) in vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nlayout(location = 6) in highp vec4 a_jointAnimInfo;\n#endif\nlayout(location = 7) in vec4 a_matWorld0;\nlayout(location = 8) in vec4 a_matWorld1;\nlayout(location = 9) in vec4 a_matWorld2;\n#if CC_USE_LIGHTMAP\nlayout(location = 10) in vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nlayout(location = 11) in vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nlayout(location = 12) in float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nint getVertexId() {\nreturn gl_VertexIndex;\n}\n#endif\n#if CC_USE_MORPH\nlayout(set = 2, binding = 4) uniform CCMorph {\nvec4 cc_displacementWeights[15];\nvec4 cc_displacementTextureInfo;\n};\nvec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\nfloat pixelIndexF = float(pixelIndex);\nfloat x = mod(pixelIndexF, textureResolution.x);\nfloat y = floor(pixelIndexF / textureResolution.x);\nreturn vec2(x, y);\n}\nvec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\nreturn (vec2(location.x, location.y) + .5) / textureResolution;\n}\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int pixelIndex) {\nivec2 texSize = textureSize(tex, 0);\nreturn texelFetch(tex, ivec2(pixelIndex % texSize.x, pixelIndex / texSize.x), 0);\n}\n#else\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex * 4;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\nreturn vec4(\ndecode32(texture(tex, x)),\ndecode32(texture(tex, y)),\ndecode32(texture(tex, z)),\n1.0\n);\n}\n#endif\nfloat getDisplacementWeight(int index) {\nint quot = index / 4;\nint remainder = index - quot * 4;\nif (remainder == 0) {\nreturn cc_displacementWeights[quot].x;\n} else if (remainder == 1) {\nreturn cc_displacementWeights[quot].y;\n} else if (remainder == 2) {\nreturn cc_displacementWeights[quot].z;\n} else {\nreturn cc_displacementWeights[quot].w;\n}\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\nreturn fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n#else\nvec3 result = vec3(0, 0, 0);\nint nVertices = int(cc_displacementTextureInfo.z);\nfor (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\nresult += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n}\nreturn result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\nlayout(set = 2, binding = 7) uniform sampler2D cc_PositionDisplacements;\nvec3 getPositionDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nlayout(set = 2, binding = 8) uniform sampler2D cc_NormalDisplacements;\nvec3 getNormalDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\nlayout(set = 2, binding = 9) uniform sampler2D cc_TangentDisplacements;\nvec3 getTangentDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n}\n#endif\nvoid applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nint vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nnormal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\ntangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\n#if CC_USE_BAKED_ANIMATION\nlayout(set = 2, binding = 3) uniform CCSkinningTexture {\nhighp vec4 cc_jointTextureInfo;\n};\nlayout(set = 2, binding = 2) uniform CCSkinningAnimation {\nhighp vec4 cc_jointAnimInfo;\n};\nlayout(set = 2, binding = 6) uniform highp sampler2D cc_jointTexture;\nvoid CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n{\n#if USE_INSTANCING\nhighp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n#else\nhighp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n#endif\ninvSize = cc_jointTextureInfo.w;\nhighp float tempY = floor(temp * invSize);\nx = floor(temp - tempY * cc_jointTextureInfo.x);\ny = (tempY + 0.5) * invSize;\n}\n#else\nlayout(set = 2, binding = 3) uniform CCSkinning {\nhighp vec4 cc_joints[30 * 3];\n};\n#endif\n#if CC_USE_BAKED_ANIMATION\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(3.0, i, x, y, invSize);\nvec4 v1 = texture(cc_jointTexture, vec2((x + 0.5) * invSize, y));\nvec4 v2 = texture(cc_jointTexture, vec2((x + 1.5) * invSize, y));\nvec4 v3 = texture(cc_jointTexture, vec2((x + 2.5) * invSize, y));\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#else\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(12.0, i, x, y, invSize);\nvec4 v1 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n);\nvec4 v2 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n);\nvec4 v3 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n);\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\n#else\nmat4 getJointMatrix (float i) {\nint idx = int(i);\nvec4 v1 = cc_joints[idx * 3];\nvec4 v2 = cc_joints[idx * 3 + 1];\nvec4 v3 = cc_joints[idx * 3 + 2];\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\nmat4 skinMatrix () {\nvec4 joints = vec4(a_joints);\nreturn getJointMatrix(joints.x) * a_weights.x\n+ getJointMatrix(joints.y) * a_weights.y\n+ getJointMatrix(joints.z) * a_weights.z\n+ getJointMatrix(joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\nmat4 m = skinMatrix();\nposition = m * position;\n}\nvoid CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nmat4 m = skinMatrix();\nposition = m * position;\nnormal = (m * vec4(normal, 0.0)).xyz;\ntangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n}\n#endif\nvoid CCVertInput(inout vec4 In)\n{\nIn = vec4(a_position, 1.0);\n#if CC_USE_MORPH\napplyMorph(In);\n#endif\n#if CC_USE_SKINNING\nCCSkin(In);\n#endif\n}\nlayout(set = 0, binding = 0) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(set = 0, binding = 1) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\n#if !USE_INSTANCING\n#if USE_BATCHING\nlayout(set = 2, binding = 0) uniform CCLocalBatched {\nhighp mat4 cc_matWorlds[10];\n};\n#else\nlayout(set = 2, binding = 0) uniform CCLocal {\nhighp mat4 cc_matWorld;\nhighp mat4 cc_matWorldIT;\nhighp vec4 cc_lightingMapUVParam;\nhighp vec4 cc_localShadowBias;\n};\n#endif\n#endif\nvoid CCGetWorldMatrix(out mat4 matWorld)\n{\n#if USE_INSTANCING\nmatWorld = mat4(\nvec4(a_matWorld0.xyz, 0.0),\nvec4(a_matWorld1.xyz, 0.0),\nvec4(a_matWorld2.xyz, 0.0),\nvec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)\n);\n#elif USE_BATCHING\nmatWorld = cc_matWorlds[int(a_dyn_batch_id)];\n#else\nmatWorld = cc_matWorld;\n#endif\n}\nfloat LinearFog(vec4 pos) {\nvec4 wPos = pos;\nfloat cam_dis = distance(cc_cameraPos, wPos);\nfloat fogStart = cc_fogBase.x;\nfloat fogEnd = cc_fogBase.y;\nreturn clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * fogDensity);\nreturn f;\n}\nfloat ExpSquaredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\nreturn f;\n}\nfloat LayeredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat _FogTop = cc_fogAdd.x;\nfloat _FogRange = cc_fogAdd.y;\nvec3 camWorldProj = cc_cameraPos.xyz;\ncamWorldProj.y = 0.;\nvec3 worldPosProj = wPos.xyz;\nworldPosProj.y = 0.;\nfloat fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\nfloat fDeltaY, fDensityIntegral;\nif (cc_cameraPos.y > _FogTop) {\nif (wPos.y < _FogTop) {\nfDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\nfDensityIntegral = fDeltaY * fDeltaY * 0.5;\n} else {\nfDeltaY = 0.;\nfDensityIntegral = 0.;\n}\n} else {\nif (wPos.y < _FogTop) {\nfloat fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfloat fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\nfDeltaY = abs(fDeltaA - fDeltaB);\nfDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n} else {\nfDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n}\n}\nfloat fDensity;\nif (fDeltaY != 0.) {\nfDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n} else {\nfDensity = 0.;\n}\nfloat f = exp(-fDensity);\nreturn f;\n}\nvoid CC_TRANSFER_FOG_BASE(vec4 pos, out float factor)\n{\n#if CC_USE_FOG == 0\nfactor = LinearFog(pos);\n#elif CC_USE_FOG == 1\nfactor = ExpFog(pos);\n#elif CC_USE_FOG == 2\nfactor = ExpSquaredFog(pos);\n#elif CC_USE_FOG == 3\nfactor = LayeredFog(pos);\n#else\nfactor = 1.0;\n#endif\n}\n#if !CC_USE_ACCURATE_FOG\nlayout(location = 0) out float v_fog_factor;\n#endif\nvoid CC_TRANSFER_FOG(vec4 pos) {\n#if !CC_USE_ACCURATE_FOG\nCC_TRANSFER_FOG_BASE(pos, v_fog_factor);\n#endif\n}\n#if USE_VERTEX_COLOR\nlayout(location = 14) in lowp vec4 a_color;\nlayout(location = 1) out lowp vec4 v_color;\n#endif\n#if USE_TEXTURE\nlayout(location = 2) out vec2 v_uv;\nlayout(set = 1, binding = 0) uniform TexCoords {\nvec4 tilingOffset;\n};\n#endif\nvec4 vert () {\nvec4 position;\nCCVertInput(position);\nmat4 matWorld;\nCCGetWorldMatrix(matWorld);\n#if USE_TEXTURE\nv_uv = a_texCoord * tilingOffset.xy + tilingOffset.zw;\n#if SAMPLE_FROM_RT\nv_uv = cc_cameraPos.w > 1.0 ? vec2(v_uv.x, 1.0 - v_uv.y) : v_uv;\n#endif\n#endif\n#if USE_VERTEX_COLOR\nv_color = a_color;\n#endif\nCC_TRANSFER_FOG(matWorld * position);\nreturn cc_matProj * (cc_matView * matWorld) * position;\n}\nvoid main() { gl_Position = vert(); }", "frag": "\nprecision highp float;\nvec3 ACESToneMap (vec3 color) {\ncolor = min(color, vec3(8.0));\nconst float A = 2.51;\nconst float B = 0.03;\nconst float C = 2.43;\nconst float D = 0.59;\nconst float E = 0.14;\nreturn (color * (A * color + B)) / (color * (C * color + D) + E);\n}\nvec3 SRGBToLinear (vec3 gamma) {\nreturn gamma * gamma;\n}\nvec4 CCFragOutput (vec4 color) {\n#if CC_USE_HDR\ncolor.rgb = ACESToneMap(color.rgb);\n#endif\ncolor.rgb = sqrt(color.rgb);\nreturn color;\n}\nlayout(set = 0, binding = 0) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(set = 0, binding = 1) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\nfloat LinearFog(vec4 pos) {\nvec4 wPos = pos;\nfloat cam_dis = distance(cc_cameraPos, wPos);\nfloat fogStart = cc_fogBase.x;\nfloat fogEnd = cc_fogBase.y;\nreturn clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * fogDensity);\nreturn f;\n}\nfloat ExpSquaredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\nreturn f;\n}\nfloat LayeredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat _FogTop = cc_fogAdd.x;\nfloat _FogRange = cc_fogAdd.y;\nvec3 camWorldProj = cc_cameraPos.xyz;\ncamWorldProj.y = 0.;\nvec3 worldPosProj = wPos.xyz;\nworldPosProj.y = 0.;\nfloat fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\nfloat fDeltaY, fDensityIntegral;\nif (cc_cameraPos.y > _FogTop) {\nif (wPos.y < _FogTop) {\nfDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\nfDensityIntegral = fDeltaY * fDeltaY * 0.5;\n} else {\nfDeltaY = 0.;\nfDensityIntegral = 0.;\n}\n} else {\nif (wPos.y < _FogTop) {\nfloat fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfloat fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\nfDeltaY = abs(fDeltaA - fDeltaB);\nfDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n} else {\nfDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n}\n}\nfloat fDensity;\nif (fDeltaY != 0.) {\nfDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n} else {\nfDensity = 0.;\n}\nfloat f = exp(-fDensity);\nreturn f;\n}\nvoid CC_TRANSFER_FOG_BASE(vec4 pos, out float factor)\n{\n#if CC_USE_FOG == 0\nfactor = LinearFog(pos);\n#elif CC_USE_FOG == 1\nfactor = ExpFog(pos);\n#elif CC_USE_FOG == 2\nfactor = ExpSquaredFog(pos);\n#elif CC_USE_FOG == 3\nfactor = LayeredFog(pos);\n#else\nfactor = 1.0;\n#endif\n}\nvoid CC_APPLY_FOG_BASE(inout vec4 color, float factor) {\ncolor = vec4(mix(cc_fogColor.rgb, color.rgb, factor), color.a);\n}\n#if !CC_USE_ACCURATE_FOG\nlayout(location = 0) in float v_fog_factor;\n#endif\nvoid CC_APPLY_FOG(inout vec4 color) {\n#if !CC_USE_ACCURATE_FOG\nCC_APPLY_FOG_BASE(color, v_fog_factor);\n#endif\n}\nvoid CC_APPLY_FOG(inout vec4 color, vec3 worldPos) {\n#if CC_USE_ACCURATE_FOG\nfloat factor;\nCC_TRANSFER_FOG_BASE(vec4(worldPos, 1.0), factor);\n#else\nfloat factor = v_fog_factor;\n#endif\nCC_APPLY_FOG_BASE(color, factor);\n}\n#if USE_ALPHA_TEST\n#endif\n#if USE_TEXTURE\nlayout(location = 2) in vec2 v_uv;\nlayout(set = 1, binding = 2) uniform sampler2D mainTexture;\n#endif\nlayout(set = 1, binding = 1) uniform Constant {\nvec4 mainColor;\nvec4 colorScaleAndCutoff;\n};\n#if USE_VERTEX_COLOR\nlayout(location = 1) in lowp vec4 v_color;\n#endif\nvec4 frag () {\nvec4 o = mainColor;\no.rgb *= colorScaleAndCutoff.xyz;\n#if USE_VERTEX_COLOR\no.rgb *= SRGBToLinear(v_color.rgb);\no.a *= v_color.a;\n#endif\n#if USE_TEXTURE\nvec4 texColor = texture(mainTexture, v_uv);\ntexColor.rgb = SRGBToLinear(texColor.rgb);\no *= texColor;\n#endif\n#if USE_ALPHA_TEST\nif (o.ALPHA_TEST_CHANNEL < colorScaleAndCutoff.w) discard;\n#endif\nCC_APPLY_FOG(o);\nreturn CCFragOutput(o);\n}\nlayout(location = 0) out vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }", } ], [ { - "vert": "#extension GL_EXT_shader_explicit_arithmetic_types_int32: require\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\nrgba = rgba * 255.0;\nhighp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\nhighp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\nhighp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\nreturn Sign * exp2(Exponent - 23.0) * Mantissa;\n}\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nlayout(location = 0) in vec3 a_position;\nlayout(location = 1) in vec3 a_normal;\nlayout(location = 2) in vec2 a_texCoord;\nlayout(location = 3) in vec4 a_tangent;\n#if CC_USE_SKINNING\nlayout(location = 4) in u32vec4 a_joints;\nlayout(location = 5) in vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nlayout(location = 6) in highp vec4 a_jointAnimInfo;\n#endif\nlayout(location = 7) in vec4 a_matWorld0;\nlayout(location = 8) in vec4 a_matWorld1;\nlayout(location = 9) in vec4 a_matWorld2;\n#if USE_LIGHTMAP\nlayout(location = 10) in vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nlayout(location = 11) in vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nlayout(location = 12) in float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nint getVertexId() {\nreturn gl_VertexIndex;\n}\n#endif\n#if CC_USE_MORPH\nlayout(set = 2, binding = 4) uniform CCMorph {\nvec4 cc_displacementWeights[15];\nvec4 cc_displacementTextureInfo;\n};\nvec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\nfloat pixelIndexF = float(pixelIndex);\nfloat x = mod(pixelIndexF, textureResolution.x);\nfloat y = floor(pixelIndexF / textureResolution.x);\nreturn vec2(x, y);\n}\nvec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\nreturn (vec2(location.x, location.y) + .5) / textureResolution;\n}\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int pixelIndex) {\nivec2 texSize = textureSize(tex, 0);\nreturn texelFetch(tex, ivec2(pixelIndex % texSize.x, pixelIndex / texSize.x), 0);\n}\n#else\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex * 4;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\nreturn vec4(\ndecode32(texture(tex, x)),\ndecode32(texture(tex, y)),\ndecode32(texture(tex, z)),\n1.0\n);\n}\n#endif\nfloat getDisplacementWeight(int index) {\nint quot = index / 4;\nint remainder = index - quot * 4;\nif (remainder == 0) {\nreturn cc_displacementWeights[quot].x;\n} else if (remainder == 1) {\nreturn cc_displacementWeights[quot].y;\n} else if (remainder == 2) {\nreturn cc_displacementWeights[quot].z;\n} else {\nreturn cc_displacementWeights[quot].w;\n}\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\nreturn fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n#else\nvec3 result = vec3(0, 0, 0);\nint nVertices = int(cc_displacementTextureInfo.z);\nfor (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\nresult += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n}\nreturn result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\nlayout(set = 2, binding = 7) uniform sampler2D cc_PositionDisplacements;\nvec3 getPositionDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nlayout(set = 2, binding = 8) uniform sampler2D cc_NormalDisplacements;\nvec3 getNormalDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\nlayout(set = 2, binding = 9) uniform sampler2D cc_TangentDisplacements;\nvec3 getTangentDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n}\n#endif\nvoid applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nint vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nnormal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\ntangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\n#if CC_USE_BAKED_ANIMATION\nlayout(set = 2, binding = 3) uniform CCSkinningTexture {\nhighp vec4 cc_jointTextureInfo;\n};\nlayout(set = 2, binding = 2) uniform CCSkinningAnimation {\nhighp vec4 cc_jointAnimInfo;\n};\nlayout(set = 2, binding = 6) uniform highp sampler2D cc_jointTexture;\nvoid CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n{\n#if USE_INSTANCING\nhighp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n#else\nhighp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n#endif\ninvSize = cc_jointTextureInfo.w;\nhighp float tempY = floor(temp * invSize);\nx = floor(temp - tempY * cc_jointTextureInfo.x);\ny = (tempY + 0.5) * invSize;\n}\n#else\nlayout(set = 2, binding = 3) uniform CCSkinning {\nhighp vec4 cc_joints[30 * 3];\n};\n#endif\n#if CC_USE_BAKED_ANIMATION\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(3.0, i, x, y, invSize);\nvec4 v1 = texture(cc_jointTexture, vec2((x + 0.5) * invSize, y));\nvec4 v2 = texture(cc_jointTexture, vec2((x + 1.5) * invSize, y));\nvec4 v3 = texture(cc_jointTexture, vec2((x + 2.5) * invSize, y));\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#else\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(12.0, i, x, y, invSize);\nvec4 v1 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n);\nvec4 v2 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n);\nvec4 v3 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n);\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\n#else\nmat4 getJointMatrix (float i) {\nint idx = int(i);\nvec4 v1 = cc_joints[idx * 3];\nvec4 v2 = cc_joints[idx * 3 + 1];\nvec4 v3 = cc_joints[idx * 3 + 2];\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\nmat4 skinMatrix () {\nvec4 joints = vec4(a_joints);\nreturn getJointMatrix(joints.x) * a_weights.x\n+ getJointMatrix(joints.y) * a_weights.y\n+ getJointMatrix(joints.z) * a_weights.z\n+ getJointMatrix(joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\nmat4 m = skinMatrix();\nposition = m * position;\n}\nvoid CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nmat4 m = skinMatrix();\nposition = m * position;\nnormal = (m * vec4(normal, 0.0)).xyz;\ntangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n}\n#endif\nvoid CCVertInput(inout StandardVertInput In)\n{\nIn.position = vec4(a_position, 1.0);\nIn.normal = a_normal;\nIn.tangent = a_tangent;\n#if CC_USE_MORPH\napplyMorph(In.position, In.normal, In.tangent);\n#endif\n#if CC_USE_SKINNING\nCCSkin(In.position, In.normal, In.tangent);\n#endif\n}\nlayout(set = 0, binding = 0) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(set = 0, binding = 1) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\nlayout(location = 0) out vec2 v_uv;\nvoid main () {\nStandardVertInput In;\nCCVertInput(In);\nIn.position.xy = cc_cameraPos.w == 0.0 ? vec2(In.position.xy.x, -In.position.xy.y) : In.position.xy;\ngl_Position = In.position;\ngl_Position.y = gl_Position.y;\nv_uv = a_texCoord;\n}", + "vert": "#extension GL_EXT_shader_explicit_arithmetic_types_int32: require\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\nrgba = rgba * 255.0;\nhighp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\nhighp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\nhighp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\nreturn Sign * exp2(Exponent - 23.0) * Mantissa;\n}\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nlayout(location = 0) in vec3 a_position;\nlayout(location = 1) in vec3 a_normal;\nlayout(location = 2) in vec2 a_texCoord;\nlayout(location = 3) in vec4 a_tangent;\n#if CC_USE_SKINNING\nlayout(location = 4) in u32vec4 a_joints;\nlayout(location = 5) in vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nlayout(location = 6) in highp vec4 a_jointAnimInfo;\n#endif\nlayout(location = 7) in vec4 a_matWorld0;\nlayout(location = 8) in vec4 a_matWorld1;\nlayout(location = 9) in vec4 a_matWorld2;\n#if CC_USE_LIGHTMAP\nlayout(location = 10) in vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nlayout(location = 11) in vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nlayout(location = 12) in float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nint getVertexId() {\nreturn gl_VertexIndex;\n}\n#endif\n#if CC_USE_MORPH\nlayout(set = 2, binding = 4) uniform CCMorph {\nvec4 cc_displacementWeights[15];\nvec4 cc_displacementTextureInfo;\n};\nvec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\nfloat pixelIndexF = float(pixelIndex);\nfloat x = mod(pixelIndexF, textureResolution.x);\nfloat y = floor(pixelIndexF / textureResolution.x);\nreturn vec2(x, y);\n}\nvec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\nreturn (vec2(location.x, location.y) + .5) / textureResolution;\n}\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int pixelIndex) {\nivec2 texSize = textureSize(tex, 0);\nreturn texelFetch(tex, ivec2(pixelIndex % texSize.x, pixelIndex / texSize.x), 0);\n}\n#else\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex * 4;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\nreturn vec4(\ndecode32(texture(tex, x)),\ndecode32(texture(tex, y)),\ndecode32(texture(tex, z)),\n1.0\n);\n}\n#endif\nfloat getDisplacementWeight(int index) {\nint quot = index / 4;\nint remainder = index - quot * 4;\nif (remainder == 0) {\nreturn cc_displacementWeights[quot].x;\n} else if (remainder == 1) {\nreturn cc_displacementWeights[quot].y;\n} else if (remainder == 2) {\nreturn cc_displacementWeights[quot].z;\n} else {\nreturn cc_displacementWeights[quot].w;\n}\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\nreturn fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n#else\nvec3 result = vec3(0, 0, 0);\nint nVertices = int(cc_displacementTextureInfo.z);\nfor (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\nresult += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n}\nreturn result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\nlayout(set = 2, binding = 7) uniform sampler2D cc_PositionDisplacements;\nvec3 getPositionDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nlayout(set = 2, binding = 8) uniform sampler2D cc_NormalDisplacements;\nvec3 getNormalDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\nlayout(set = 2, binding = 9) uniform sampler2D cc_TangentDisplacements;\nvec3 getTangentDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n}\n#endif\nvoid applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nint vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nnormal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\ntangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\n#if CC_USE_BAKED_ANIMATION\nlayout(set = 2, binding = 3) uniform CCSkinningTexture {\nhighp vec4 cc_jointTextureInfo;\n};\nlayout(set = 2, binding = 2) uniform CCSkinningAnimation {\nhighp vec4 cc_jointAnimInfo;\n};\nlayout(set = 2, binding = 6) uniform highp sampler2D cc_jointTexture;\nvoid CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n{\n#if USE_INSTANCING\nhighp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n#else\nhighp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n#endif\ninvSize = cc_jointTextureInfo.w;\nhighp float tempY = floor(temp * invSize);\nx = floor(temp - tempY * cc_jointTextureInfo.x);\ny = (tempY + 0.5) * invSize;\n}\n#else\nlayout(set = 2, binding = 3) uniform CCSkinning {\nhighp vec4 cc_joints[30 * 3];\n};\n#endif\n#if CC_USE_BAKED_ANIMATION\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(3.0, i, x, y, invSize);\nvec4 v1 = texture(cc_jointTexture, vec2((x + 0.5) * invSize, y));\nvec4 v2 = texture(cc_jointTexture, vec2((x + 1.5) * invSize, y));\nvec4 v3 = texture(cc_jointTexture, vec2((x + 2.5) * invSize, y));\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#else\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(12.0, i, x, y, invSize);\nvec4 v1 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n);\nvec4 v2 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n);\nvec4 v3 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n);\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\n#else\nmat4 getJointMatrix (float i) {\nint idx = int(i);\nvec4 v1 = cc_joints[idx * 3];\nvec4 v2 = cc_joints[idx * 3 + 1];\nvec4 v3 = cc_joints[idx * 3 + 2];\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\nmat4 skinMatrix () {\nvec4 joints = vec4(a_joints);\nreturn getJointMatrix(joints.x) * a_weights.x\n+ getJointMatrix(joints.y) * a_weights.y\n+ getJointMatrix(joints.z) * a_weights.z\n+ getJointMatrix(joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\nmat4 m = skinMatrix();\nposition = m * position;\n}\nvoid CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nmat4 m = skinMatrix();\nposition = m * position;\nnormal = (m * vec4(normal, 0.0)).xyz;\ntangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n}\n#endif\nvoid CCVertInput(inout StandardVertInput In)\n{\nIn.position = vec4(a_position, 1.0);\nIn.normal = a_normal;\nIn.tangent = a_tangent;\n#if CC_USE_MORPH\napplyMorph(In.position, In.normal, In.tangent);\n#endif\n#if CC_USE_SKINNING\nCCSkin(In.position, In.normal, In.tangent);\n#endif\n}\nlayout(set = 0, binding = 0) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(set = 0, binding = 1) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\nlayout(location = 0) out vec2 v_uv;\nvoid main () {\nStandardVertInput In;\nCCVertInput(In);\nIn.position.xy = cc_cameraPos.w == 0.0 ? vec2(In.position.xy.x, -In.position.xy.y) : In.position.xy;\ngl_Position = In.position;\ngl_Position.y = gl_Position.y;\nv_uv = a_texCoord;\n}", "frag": "\nprecision highp float;\nlayout(set = 0, binding = 0) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(set = 0, binding = 1) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\nvec3 SRGBToLinear (vec3 gamma) {\nreturn gamma * gamma;\n}\nlayout(location = 0) in vec2 v_uv;\nlayout(set = 1, binding = 0) uniform BloomUBO {\nmediump vec4 texSize;\n};\nlayout(set = 1, binding = 1) uniform sampler2D outputResultMap;\nlayout(location = 0) out vec4 fragColor;\nfloat luminance(vec3 color) {\nreturn dot(color, vec3(0.2126, 0.7152, 0.0722));\n}\nvoid main() {\nvec3 color = texture(outputResultMap, v_uv).xyz;\nif (luminance(SRGBToLinear(color)) > texSize.z) {\nfragColor = vec4(color, 1.0);\n} else {\nfragColor = vec4(0.0, 0.0, 0.0, 1.0);\n}\n}", }, { - "vert": "#extension GL_EXT_shader_explicit_arithmetic_types_int32: require\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\nrgba = rgba * 255.0;\nhighp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\nhighp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\nhighp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\nreturn Sign * exp2(Exponent - 23.0) * Mantissa;\n}\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nlayout(location = 0) in vec3 a_position;\nlayout(location = 1) in vec3 a_normal;\nlayout(location = 2) in vec2 a_texCoord;\nlayout(location = 3) in vec4 a_tangent;\n#if CC_USE_SKINNING\nlayout(location = 4) in u32vec4 a_joints;\nlayout(location = 5) in vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nlayout(location = 6) in highp vec4 a_jointAnimInfo;\n#endif\nlayout(location = 7) in vec4 a_matWorld0;\nlayout(location = 8) in vec4 a_matWorld1;\nlayout(location = 9) in vec4 a_matWorld2;\n#if USE_LIGHTMAP\nlayout(location = 10) in vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nlayout(location = 11) in vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nlayout(location = 12) in float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nint getVertexId() {\nreturn gl_VertexIndex;\n}\n#endif\n#if CC_USE_MORPH\nlayout(set = 2, binding = 4) uniform CCMorph {\nvec4 cc_displacementWeights[15];\nvec4 cc_displacementTextureInfo;\n};\nvec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\nfloat pixelIndexF = float(pixelIndex);\nfloat x = mod(pixelIndexF, textureResolution.x);\nfloat y = floor(pixelIndexF / textureResolution.x);\nreturn vec2(x, y);\n}\nvec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\nreturn (vec2(location.x, location.y) + .5) / textureResolution;\n}\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int pixelIndex) {\nivec2 texSize = textureSize(tex, 0);\nreturn texelFetch(tex, ivec2(pixelIndex % texSize.x, pixelIndex / texSize.x), 0);\n}\n#else\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex * 4;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\nreturn vec4(\ndecode32(texture(tex, x)),\ndecode32(texture(tex, y)),\ndecode32(texture(tex, z)),\n1.0\n);\n}\n#endif\nfloat getDisplacementWeight(int index) {\nint quot = index / 4;\nint remainder = index - quot * 4;\nif (remainder == 0) {\nreturn cc_displacementWeights[quot].x;\n} else if (remainder == 1) {\nreturn cc_displacementWeights[quot].y;\n} else if (remainder == 2) {\nreturn cc_displacementWeights[quot].z;\n} else {\nreturn cc_displacementWeights[quot].w;\n}\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\nreturn fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n#else\nvec3 result = vec3(0, 0, 0);\nint nVertices = int(cc_displacementTextureInfo.z);\nfor (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\nresult += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n}\nreturn result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\nlayout(set = 2, binding = 7) uniform sampler2D cc_PositionDisplacements;\nvec3 getPositionDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nlayout(set = 2, binding = 8) uniform sampler2D cc_NormalDisplacements;\nvec3 getNormalDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\nlayout(set = 2, binding = 9) uniform sampler2D cc_TangentDisplacements;\nvec3 getTangentDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n}\n#endif\nvoid applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nint vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nnormal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\ntangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\n#if CC_USE_BAKED_ANIMATION\nlayout(set = 2, binding = 3) uniform CCSkinningTexture {\nhighp vec4 cc_jointTextureInfo;\n};\nlayout(set = 2, binding = 2) uniform CCSkinningAnimation {\nhighp vec4 cc_jointAnimInfo;\n};\nlayout(set = 2, binding = 6) uniform highp sampler2D cc_jointTexture;\nvoid CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n{\n#if USE_INSTANCING\nhighp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n#else\nhighp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n#endif\ninvSize = cc_jointTextureInfo.w;\nhighp float tempY = floor(temp * invSize);\nx = floor(temp - tempY * cc_jointTextureInfo.x);\ny = (tempY + 0.5) * invSize;\n}\n#else\nlayout(set = 2, binding = 3) uniform CCSkinning {\nhighp vec4 cc_joints[30 * 3];\n};\n#endif\n#if CC_USE_BAKED_ANIMATION\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(3.0, i, x, y, invSize);\nvec4 v1 = texture(cc_jointTexture, vec2((x + 0.5) * invSize, y));\nvec4 v2 = texture(cc_jointTexture, vec2((x + 1.5) * invSize, y));\nvec4 v3 = texture(cc_jointTexture, vec2((x + 2.5) * invSize, y));\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#else\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(12.0, i, x, y, invSize);\nvec4 v1 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n);\nvec4 v2 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n);\nvec4 v3 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n);\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\n#else\nmat4 getJointMatrix (float i) {\nint idx = int(i);\nvec4 v1 = cc_joints[idx * 3];\nvec4 v2 = cc_joints[idx * 3 + 1];\nvec4 v3 = cc_joints[idx * 3 + 2];\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\nmat4 skinMatrix () {\nvec4 joints = vec4(a_joints);\nreturn getJointMatrix(joints.x) * a_weights.x\n+ getJointMatrix(joints.y) * a_weights.y\n+ getJointMatrix(joints.z) * a_weights.z\n+ getJointMatrix(joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\nmat4 m = skinMatrix();\nposition = m * position;\n}\nvoid CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nmat4 m = skinMatrix();\nposition = m * position;\nnormal = (m * vec4(normal, 0.0)).xyz;\ntangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n}\n#endif\nvoid CCVertInput(inout StandardVertInput In)\n{\nIn.position = vec4(a_position, 1.0);\nIn.normal = a_normal;\nIn.tangent = a_tangent;\n#if CC_USE_MORPH\napplyMorph(In.position, In.normal, In.tangent);\n#endif\n#if CC_USE_SKINNING\nCCSkin(In.position, In.normal, In.tangent);\n#endif\n}\nlayout(set = 0, binding = 0) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(set = 0, binding = 1) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\nlayout(location = 0) out vec2 v_uv;\nvoid main () {\nStandardVertInput In;\nCCVertInput(In);\nIn.position.xy = cc_cameraPos.w == 0.0 ? vec2(In.position.xy.x, -In.position.xy.y) : In.position.xy;\ngl_Position = In.position;\ngl_Position.y = gl_Position.y;\nv_uv = a_texCoord;\n}", + "vert": "#extension GL_EXT_shader_explicit_arithmetic_types_int32: require\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\nrgba = rgba * 255.0;\nhighp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\nhighp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\nhighp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\nreturn Sign * exp2(Exponent - 23.0) * Mantissa;\n}\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nlayout(location = 0) in vec3 a_position;\nlayout(location = 1) in vec3 a_normal;\nlayout(location = 2) in vec2 a_texCoord;\nlayout(location = 3) in vec4 a_tangent;\n#if CC_USE_SKINNING\nlayout(location = 4) in u32vec4 a_joints;\nlayout(location = 5) in vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nlayout(location = 6) in highp vec4 a_jointAnimInfo;\n#endif\nlayout(location = 7) in vec4 a_matWorld0;\nlayout(location = 8) in vec4 a_matWorld1;\nlayout(location = 9) in vec4 a_matWorld2;\n#if CC_USE_LIGHTMAP\nlayout(location = 10) in vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nlayout(location = 11) in vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nlayout(location = 12) in float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nint getVertexId() {\nreturn gl_VertexIndex;\n}\n#endif\n#if CC_USE_MORPH\nlayout(set = 2, binding = 4) uniform CCMorph {\nvec4 cc_displacementWeights[15];\nvec4 cc_displacementTextureInfo;\n};\nvec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\nfloat pixelIndexF = float(pixelIndex);\nfloat x = mod(pixelIndexF, textureResolution.x);\nfloat y = floor(pixelIndexF / textureResolution.x);\nreturn vec2(x, y);\n}\nvec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\nreturn (vec2(location.x, location.y) + .5) / textureResolution;\n}\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int pixelIndex) {\nivec2 texSize = textureSize(tex, 0);\nreturn texelFetch(tex, ivec2(pixelIndex % texSize.x, pixelIndex / texSize.x), 0);\n}\n#else\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex * 4;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\nreturn vec4(\ndecode32(texture(tex, x)),\ndecode32(texture(tex, y)),\ndecode32(texture(tex, z)),\n1.0\n);\n}\n#endif\nfloat getDisplacementWeight(int index) {\nint quot = index / 4;\nint remainder = index - quot * 4;\nif (remainder == 0) {\nreturn cc_displacementWeights[quot].x;\n} else if (remainder == 1) {\nreturn cc_displacementWeights[quot].y;\n} else if (remainder == 2) {\nreturn cc_displacementWeights[quot].z;\n} else {\nreturn cc_displacementWeights[quot].w;\n}\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\nreturn fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n#else\nvec3 result = vec3(0, 0, 0);\nint nVertices = int(cc_displacementTextureInfo.z);\nfor (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\nresult += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n}\nreturn result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\nlayout(set = 2, binding = 7) uniform sampler2D cc_PositionDisplacements;\nvec3 getPositionDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nlayout(set = 2, binding = 8) uniform sampler2D cc_NormalDisplacements;\nvec3 getNormalDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\nlayout(set = 2, binding = 9) uniform sampler2D cc_TangentDisplacements;\nvec3 getTangentDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n}\n#endif\nvoid applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nint vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nnormal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\ntangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\n#if CC_USE_BAKED_ANIMATION\nlayout(set = 2, binding = 3) uniform CCSkinningTexture {\nhighp vec4 cc_jointTextureInfo;\n};\nlayout(set = 2, binding = 2) uniform CCSkinningAnimation {\nhighp vec4 cc_jointAnimInfo;\n};\nlayout(set = 2, binding = 6) uniform highp sampler2D cc_jointTexture;\nvoid CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n{\n#if USE_INSTANCING\nhighp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n#else\nhighp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n#endif\ninvSize = cc_jointTextureInfo.w;\nhighp float tempY = floor(temp * invSize);\nx = floor(temp - tempY * cc_jointTextureInfo.x);\ny = (tempY + 0.5) * invSize;\n}\n#else\nlayout(set = 2, binding = 3) uniform CCSkinning {\nhighp vec4 cc_joints[30 * 3];\n};\n#endif\n#if CC_USE_BAKED_ANIMATION\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(3.0, i, x, y, invSize);\nvec4 v1 = texture(cc_jointTexture, vec2((x + 0.5) * invSize, y));\nvec4 v2 = texture(cc_jointTexture, vec2((x + 1.5) * invSize, y));\nvec4 v3 = texture(cc_jointTexture, vec2((x + 2.5) * invSize, y));\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#else\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(12.0, i, x, y, invSize);\nvec4 v1 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n);\nvec4 v2 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n);\nvec4 v3 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n);\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\n#else\nmat4 getJointMatrix (float i) {\nint idx = int(i);\nvec4 v1 = cc_joints[idx * 3];\nvec4 v2 = cc_joints[idx * 3 + 1];\nvec4 v3 = cc_joints[idx * 3 + 2];\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\nmat4 skinMatrix () {\nvec4 joints = vec4(a_joints);\nreturn getJointMatrix(joints.x) * a_weights.x\n+ getJointMatrix(joints.y) * a_weights.y\n+ getJointMatrix(joints.z) * a_weights.z\n+ getJointMatrix(joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\nmat4 m = skinMatrix();\nposition = m * position;\n}\nvoid CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nmat4 m = skinMatrix();\nposition = m * position;\nnormal = (m * vec4(normal, 0.0)).xyz;\ntangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n}\n#endif\nvoid CCVertInput(inout StandardVertInput In)\n{\nIn.position = vec4(a_position, 1.0);\nIn.normal = a_normal;\nIn.tangent = a_tangent;\n#if CC_USE_MORPH\napplyMorph(In.position, In.normal, In.tangent);\n#endif\n#if CC_USE_SKINNING\nCCSkin(In.position, In.normal, In.tangent);\n#endif\n}\nlayout(set = 0, binding = 0) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(set = 0, binding = 1) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\nlayout(location = 0) out vec2 v_uv;\nvoid main () {\nStandardVertInput In;\nCCVertInput(In);\nIn.position.xy = cc_cameraPos.w == 0.0 ? vec2(In.position.xy.x, -In.position.xy.y) : In.position.xy;\ngl_Position = In.position;\ngl_Position.y = gl_Position.y;\nv_uv = a_texCoord;\n}", "frag": "\nprecision highp float;\nlayout(set = 0, binding = 0) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(set = 0, binding = 1) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\nlayout(location = 0) in vec2 v_uv;\nlayout(set = 1, binding = 0) uniform BloomUBO {\nmediump vec4 texSize;\n};\nlayout(set = 1, binding = 1) uniform sampler2D bloomTexture;\nlayout(location = 0) out vec4 fragColor;\nvec3 downsample4taps(vec2 uv, vec2 halfpixel) {\nvec3 sum = texture(bloomTexture, uv + vec2(-halfpixel.x, halfpixel.y)).xyz;\nsum += texture(bloomTexture, uv + vec2(halfpixel.x, halfpixel.y)).xyz;\nsum += texture(bloomTexture, uv + vec2(halfpixel.x, -halfpixel.y)).xyz;\nsum += texture(bloomTexture, uv + vec2(-halfpixel.x, -halfpixel.y)).xyz;\nreturn sum / 4.0;\n}\nvoid main()\n{\nvec3 result = downsample4taps(v_uv, 1.0 / texSize.xy).rgb;\nfragColor = vec4(result, 1.0);\n}", }, { - "vert": "#extension GL_EXT_shader_explicit_arithmetic_types_int32: require\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\nrgba = rgba * 255.0;\nhighp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\nhighp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\nhighp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\nreturn Sign * exp2(Exponent - 23.0) * Mantissa;\n}\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nlayout(location = 0) in vec3 a_position;\nlayout(location = 1) in vec3 a_normal;\nlayout(location = 2) in vec2 a_texCoord;\nlayout(location = 3) in vec4 a_tangent;\n#if CC_USE_SKINNING\nlayout(location = 4) in u32vec4 a_joints;\nlayout(location = 5) in vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nlayout(location = 6) in highp vec4 a_jointAnimInfo;\n#endif\nlayout(location = 7) in vec4 a_matWorld0;\nlayout(location = 8) in vec4 a_matWorld1;\nlayout(location = 9) in vec4 a_matWorld2;\n#if USE_LIGHTMAP\nlayout(location = 10) in vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nlayout(location = 11) in vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nlayout(location = 12) in float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nint getVertexId() {\nreturn gl_VertexIndex;\n}\n#endif\n#if CC_USE_MORPH\nlayout(set = 2, binding = 4) uniform CCMorph {\nvec4 cc_displacementWeights[15];\nvec4 cc_displacementTextureInfo;\n};\nvec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\nfloat pixelIndexF = float(pixelIndex);\nfloat x = mod(pixelIndexF, textureResolution.x);\nfloat y = floor(pixelIndexF / textureResolution.x);\nreturn vec2(x, y);\n}\nvec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\nreturn (vec2(location.x, location.y) + .5) / textureResolution;\n}\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int pixelIndex) {\nivec2 texSize = textureSize(tex, 0);\nreturn texelFetch(tex, ivec2(pixelIndex % texSize.x, pixelIndex / texSize.x), 0);\n}\n#else\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex * 4;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\nreturn vec4(\ndecode32(texture(tex, x)),\ndecode32(texture(tex, y)),\ndecode32(texture(tex, z)),\n1.0\n);\n}\n#endif\nfloat getDisplacementWeight(int index) {\nint quot = index / 4;\nint remainder = index - quot * 4;\nif (remainder == 0) {\nreturn cc_displacementWeights[quot].x;\n} else if (remainder == 1) {\nreturn cc_displacementWeights[quot].y;\n} else if (remainder == 2) {\nreturn cc_displacementWeights[quot].z;\n} else {\nreturn cc_displacementWeights[quot].w;\n}\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\nreturn fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n#else\nvec3 result = vec3(0, 0, 0);\nint nVertices = int(cc_displacementTextureInfo.z);\nfor (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\nresult += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n}\nreturn result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\nlayout(set = 2, binding = 7) uniform sampler2D cc_PositionDisplacements;\nvec3 getPositionDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nlayout(set = 2, binding = 8) uniform sampler2D cc_NormalDisplacements;\nvec3 getNormalDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\nlayout(set = 2, binding = 9) uniform sampler2D cc_TangentDisplacements;\nvec3 getTangentDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n}\n#endif\nvoid applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nint vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nnormal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\ntangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\n#if CC_USE_BAKED_ANIMATION\nlayout(set = 2, binding = 3) uniform CCSkinningTexture {\nhighp vec4 cc_jointTextureInfo;\n};\nlayout(set = 2, binding = 2) uniform CCSkinningAnimation {\nhighp vec4 cc_jointAnimInfo;\n};\nlayout(set = 2, binding = 6) uniform highp sampler2D cc_jointTexture;\nvoid CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n{\n#if USE_INSTANCING\nhighp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n#else\nhighp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n#endif\ninvSize = cc_jointTextureInfo.w;\nhighp float tempY = floor(temp * invSize);\nx = floor(temp - tempY * cc_jointTextureInfo.x);\ny = (tempY + 0.5) * invSize;\n}\n#else\nlayout(set = 2, binding = 3) uniform CCSkinning {\nhighp vec4 cc_joints[30 * 3];\n};\n#endif\n#if CC_USE_BAKED_ANIMATION\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(3.0, i, x, y, invSize);\nvec4 v1 = texture(cc_jointTexture, vec2((x + 0.5) * invSize, y));\nvec4 v2 = texture(cc_jointTexture, vec2((x + 1.5) * invSize, y));\nvec4 v3 = texture(cc_jointTexture, vec2((x + 2.5) * invSize, y));\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#else\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(12.0, i, x, y, invSize);\nvec4 v1 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n);\nvec4 v2 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n);\nvec4 v3 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n);\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\n#else\nmat4 getJointMatrix (float i) {\nint idx = int(i);\nvec4 v1 = cc_joints[idx * 3];\nvec4 v2 = cc_joints[idx * 3 + 1];\nvec4 v3 = cc_joints[idx * 3 + 2];\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\nmat4 skinMatrix () {\nvec4 joints = vec4(a_joints);\nreturn getJointMatrix(joints.x) * a_weights.x\n+ getJointMatrix(joints.y) * a_weights.y\n+ getJointMatrix(joints.z) * a_weights.z\n+ getJointMatrix(joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\nmat4 m = skinMatrix();\nposition = m * position;\n}\nvoid CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nmat4 m = skinMatrix();\nposition = m * position;\nnormal = (m * vec4(normal, 0.0)).xyz;\ntangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n}\n#endif\nvoid CCVertInput(inout StandardVertInput In)\n{\nIn.position = vec4(a_position, 1.0);\nIn.normal = a_normal;\nIn.tangent = a_tangent;\n#if CC_USE_MORPH\napplyMorph(In.position, In.normal, In.tangent);\n#endif\n#if CC_USE_SKINNING\nCCSkin(In.position, In.normal, In.tangent);\n#endif\n}\nlayout(set = 0, binding = 0) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(set = 0, binding = 1) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\nlayout(location = 0) out vec2 v_uv;\nvoid main () {\nStandardVertInput In;\nCCVertInput(In);\nIn.position.xy = cc_cameraPos.w == 0.0 ? vec2(In.position.xy.x, -In.position.xy.y) : In.position.xy;\ngl_Position = In.position;\ngl_Position.y = gl_Position.y;\nv_uv = a_texCoord;\n}", + "vert": "#extension GL_EXT_shader_explicit_arithmetic_types_int32: require\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\nrgba = rgba * 255.0;\nhighp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\nhighp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\nhighp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\nreturn Sign * exp2(Exponent - 23.0) * Mantissa;\n}\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nlayout(location = 0) in vec3 a_position;\nlayout(location = 1) in vec3 a_normal;\nlayout(location = 2) in vec2 a_texCoord;\nlayout(location = 3) in vec4 a_tangent;\n#if CC_USE_SKINNING\nlayout(location = 4) in u32vec4 a_joints;\nlayout(location = 5) in vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nlayout(location = 6) in highp vec4 a_jointAnimInfo;\n#endif\nlayout(location = 7) in vec4 a_matWorld0;\nlayout(location = 8) in vec4 a_matWorld1;\nlayout(location = 9) in vec4 a_matWorld2;\n#if CC_USE_LIGHTMAP\nlayout(location = 10) in vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nlayout(location = 11) in vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nlayout(location = 12) in float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nint getVertexId() {\nreturn gl_VertexIndex;\n}\n#endif\n#if CC_USE_MORPH\nlayout(set = 2, binding = 4) uniform CCMorph {\nvec4 cc_displacementWeights[15];\nvec4 cc_displacementTextureInfo;\n};\nvec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\nfloat pixelIndexF = float(pixelIndex);\nfloat x = mod(pixelIndexF, textureResolution.x);\nfloat y = floor(pixelIndexF / textureResolution.x);\nreturn vec2(x, y);\n}\nvec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\nreturn (vec2(location.x, location.y) + .5) / textureResolution;\n}\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int pixelIndex) {\nivec2 texSize = textureSize(tex, 0);\nreturn texelFetch(tex, ivec2(pixelIndex % texSize.x, pixelIndex / texSize.x), 0);\n}\n#else\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex * 4;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\nreturn vec4(\ndecode32(texture(tex, x)),\ndecode32(texture(tex, y)),\ndecode32(texture(tex, z)),\n1.0\n);\n}\n#endif\nfloat getDisplacementWeight(int index) {\nint quot = index / 4;\nint remainder = index - quot * 4;\nif (remainder == 0) {\nreturn cc_displacementWeights[quot].x;\n} else if (remainder == 1) {\nreturn cc_displacementWeights[quot].y;\n} else if (remainder == 2) {\nreturn cc_displacementWeights[quot].z;\n} else {\nreturn cc_displacementWeights[quot].w;\n}\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\nreturn fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n#else\nvec3 result = vec3(0, 0, 0);\nint nVertices = int(cc_displacementTextureInfo.z);\nfor (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\nresult += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n}\nreturn result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\nlayout(set = 2, binding = 7) uniform sampler2D cc_PositionDisplacements;\nvec3 getPositionDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nlayout(set = 2, binding = 8) uniform sampler2D cc_NormalDisplacements;\nvec3 getNormalDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\nlayout(set = 2, binding = 9) uniform sampler2D cc_TangentDisplacements;\nvec3 getTangentDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n}\n#endif\nvoid applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nint vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nnormal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\ntangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\n#if CC_USE_BAKED_ANIMATION\nlayout(set = 2, binding = 3) uniform CCSkinningTexture {\nhighp vec4 cc_jointTextureInfo;\n};\nlayout(set = 2, binding = 2) uniform CCSkinningAnimation {\nhighp vec4 cc_jointAnimInfo;\n};\nlayout(set = 2, binding = 6) uniform highp sampler2D cc_jointTexture;\nvoid CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n{\n#if USE_INSTANCING\nhighp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n#else\nhighp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n#endif\ninvSize = cc_jointTextureInfo.w;\nhighp float tempY = floor(temp * invSize);\nx = floor(temp - tempY * cc_jointTextureInfo.x);\ny = (tempY + 0.5) * invSize;\n}\n#else\nlayout(set = 2, binding = 3) uniform CCSkinning {\nhighp vec4 cc_joints[30 * 3];\n};\n#endif\n#if CC_USE_BAKED_ANIMATION\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(3.0, i, x, y, invSize);\nvec4 v1 = texture(cc_jointTexture, vec2((x + 0.5) * invSize, y));\nvec4 v2 = texture(cc_jointTexture, vec2((x + 1.5) * invSize, y));\nvec4 v3 = texture(cc_jointTexture, vec2((x + 2.5) * invSize, y));\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#else\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(12.0, i, x, y, invSize);\nvec4 v1 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n);\nvec4 v2 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n);\nvec4 v3 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n);\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\n#else\nmat4 getJointMatrix (float i) {\nint idx = int(i);\nvec4 v1 = cc_joints[idx * 3];\nvec4 v2 = cc_joints[idx * 3 + 1];\nvec4 v3 = cc_joints[idx * 3 + 2];\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\nmat4 skinMatrix () {\nvec4 joints = vec4(a_joints);\nreturn getJointMatrix(joints.x) * a_weights.x\n+ getJointMatrix(joints.y) * a_weights.y\n+ getJointMatrix(joints.z) * a_weights.z\n+ getJointMatrix(joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\nmat4 m = skinMatrix();\nposition = m * position;\n}\nvoid CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nmat4 m = skinMatrix();\nposition = m * position;\nnormal = (m * vec4(normal, 0.0)).xyz;\ntangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n}\n#endif\nvoid CCVertInput(inout StandardVertInput In)\n{\nIn.position = vec4(a_position, 1.0);\nIn.normal = a_normal;\nIn.tangent = a_tangent;\n#if CC_USE_MORPH\napplyMorph(In.position, In.normal, In.tangent);\n#endif\n#if CC_USE_SKINNING\nCCSkin(In.position, In.normal, In.tangent);\n#endif\n}\nlayout(set = 0, binding = 0) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(set = 0, binding = 1) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\nlayout(location = 0) out vec2 v_uv;\nvoid main () {\nStandardVertInput In;\nCCVertInput(In);\nIn.position.xy = cc_cameraPos.w == 0.0 ? vec2(In.position.xy.x, -In.position.xy.y) : In.position.xy;\ngl_Position = In.position;\ngl_Position.y = gl_Position.y;\nv_uv = a_texCoord;\n}", "frag": "\nprecision highp float;\nlayout(set = 0, binding = 0) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(set = 0, binding = 1) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\nlayout(location = 0) in vec2 v_uv;\nlayout(set = 1, binding = 0) uniform BloomUBO {\nmediump vec4 texSize;\n};\nlayout(set = 1, binding = 1) uniform sampler2D bloomTexture;\nlayout(location = 0) out vec4 fragColor;\nvec3 upsample4taps(vec2 uv, vec2 halfpixel) {\nvec3 sum = texture(bloomTexture, uv + vec2(-halfpixel.x, halfpixel.y)).xyz;\nsum += texture(bloomTexture, uv + vec2(halfpixel.x, halfpixel.y)).xyz;\nsum += texture(bloomTexture, uv + vec2(halfpixel.x, -halfpixel.y)).xyz;\nsum += texture(bloomTexture, uv + vec2(-halfpixel.x, -halfpixel.y)).xyz;\nreturn sum / 4.0;\n}\nvoid main() {\nvec3 result = upsample4taps(v_uv, 0.5 / texSize.xy).rgb;\nfragColor = vec4(result, 1.0);\n}", }, { - "vert": "#extension GL_EXT_shader_explicit_arithmetic_types_int32: require\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\nrgba = rgba * 255.0;\nhighp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\nhighp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\nhighp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\nreturn Sign * exp2(Exponent - 23.0) * Mantissa;\n}\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nlayout(location = 0) in vec3 a_position;\nlayout(location = 1) in vec3 a_normal;\nlayout(location = 2) in vec2 a_texCoord;\nlayout(location = 3) in vec4 a_tangent;\n#if CC_USE_SKINNING\nlayout(location = 4) in u32vec4 a_joints;\nlayout(location = 5) in vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nlayout(location = 6) in highp vec4 a_jointAnimInfo;\n#endif\nlayout(location = 7) in vec4 a_matWorld0;\nlayout(location = 8) in vec4 a_matWorld1;\nlayout(location = 9) in vec4 a_matWorld2;\n#if USE_LIGHTMAP\nlayout(location = 10) in vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nlayout(location = 11) in vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nlayout(location = 12) in float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nint getVertexId() {\nreturn gl_VertexIndex;\n}\n#endif\n#if CC_USE_MORPH\nlayout(set = 2, binding = 4) uniform CCMorph {\nvec4 cc_displacementWeights[15];\nvec4 cc_displacementTextureInfo;\n};\nvec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\nfloat pixelIndexF = float(pixelIndex);\nfloat x = mod(pixelIndexF, textureResolution.x);\nfloat y = floor(pixelIndexF / textureResolution.x);\nreturn vec2(x, y);\n}\nvec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\nreturn (vec2(location.x, location.y) + .5) / textureResolution;\n}\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int pixelIndex) {\nivec2 texSize = textureSize(tex, 0);\nreturn texelFetch(tex, ivec2(pixelIndex % texSize.x, pixelIndex / texSize.x), 0);\n}\n#else\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex * 4;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\nreturn vec4(\ndecode32(texture(tex, x)),\ndecode32(texture(tex, y)),\ndecode32(texture(tex, z)),\n1.0\n);\n}\n#endif\nfloat getDisplacementWeight(int index) {\nint quot = index / 4;\nint remainder = index - quot * 4;\nif (remainder == 0) {\nreturn cc_displacementWeights[quot].x;\n} else if (remainder == 1) {\nreturn cc_displacementWeights[quot].y;\n} else if (remainder == 2) {\nreturn cc_displacementWeights[quot].z;\n} else {\nreturn cc_displacementWeights[quot].w;\n}\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\nreturn fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n#else\nvec3 result = vec3(0, 0, 0);\nint nVertices = int(cc_displacementTextureInfo.z);\nfor (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\nresult += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n}\nreturn result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\nlayout(set = 2, binding = 7) uniform sampler2D cc_PositionDisplacements;\nvec3 getPositionDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nlayout(set = 2, binding = 8) uniform sampler2D cc_NormalDisplacements;\nvec3 getNormalDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\nlayout(set = 2, binding = 9) uniform sampler2D cc_TangentDisplacements;\nvec3 getTangentDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n}\n#endif\nvoid applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nint vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nnormal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\ntangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\n#if CC_USE_BAKED_ANIMATION\nlayout(set = 2, binding = 3) uniform CCSkinningTexture {\nhighp vec4 cc_jointTextureInfo;\n};\nlayout(set = 2, binding = 2) uniform CCSkinningAnimation {\nhighp vec4 cc_jointAnimInfo;\n};\nlayout(set = 2, binding = 6) uniform highp sampler2D cc_jointTexture;\nvoid CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n{\n#if USE_INSTANCING\nhighp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n#else\nhighp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n#endif\ninvSize = cc_jointTextureInfo.w;\nhighp float tempY = floor(temp * invSize);\nx = floor(temp - tempY * cc_jointTextureInfo.x);\ny = (tempY + 0.5) * invSize;\n}\n#else\nlayout(set = 2, binding = 3) uniform CCSkinning {\nhighp vec4 cc_joints[30 * 3];\n};\n#endif\n#if CC_USE_BAKED_ANIMATION\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(3.0, i, x, y, invSize);\nvec4 v1 = texture(cc_jointTexture, vec2((x + 0.5) * invSize, y));\nvec4 v2 = texture(cc_jointTexture, vec2((x + 1.5) * invSize, y));\nvec4 v3 = texture(cc_jointTexture, vec2((x + 2.5) * invSize, y));\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#else\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(12.0, i, x, y, invSize);\nvec4 v1 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n);\nvec4 v2 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n);\nvec4 v3 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n);\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\n#else\nmat4 getJointMatrix (float i) {\nint idx = int(i);\nvec4 v1 = cc_joints[idx * 3];\nvec4 v2 = cc_joints[idx * 3 + 1];\nvec4 v3 = cc_joints[idx * 3 + 2];\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\nmat4 skinMatrix () {\nvec4 joints = vec4(a_joints);\nreturn getJointMatrix(joints.x) * a_weights.x\n+ getJointMatrix(joints.y) * a_weights.y\n+ getJointMatrix(joints.z) * a_weights.z\n+ getJointMatrix(joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\nmat4 m = skinMatrix();\nposition = m * position;\n}\nvoid CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nmat4 m = skinMatrix();\nposition = m * position;\nnormal = (m * vec4(normal, 0.0)).xyz;\ntangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n}\n#endif\nvoid CCVertInput(inout StandardVertInput In)\n{\nIn.position = vec4(a_position, 1.0);\nIn.normal = a_normal;\nIn.tangent = a_tangent;\n#if CC_USE_MORPH\napplyMorph(In.position, In.normal, In.tangent);\n#endif\n#if CC_USE_SKINNING\nCCSkin(In.position, In.normal, In.tangent);\n#endif\n}\nlayout(set = 0, binding = 0) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(set = 0, binding = 1) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\nlayout(location = 0) out vec2 v_uv;\nvoid main () {\nStandardVertInput In;\nCCVertInput(In);\nIn.position.xy = cc_cameraPos.w == 0.0 ? vec2(In.position.xy.x, -In.position.xy.y) : In.position.xy;\ngl_Position = In.position;\ngl_Position.y = gl_Position.y;\nv_uv = a_texCoord;\n}", + "vert": "#extension GL_EXT_shader_explicit_arithmetic_types_int32: require\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\nrgba = rgba * 255.0;\nhighp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\nhighp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\nhighp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\nreturn Sign * exp2(Exponent - 23.0) * Mantissa;\n}\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nlayout(location = 0) in vec3 a_position;\nlayout(location = 1) in vec3 a_normal;\nlayout(location = 2) in vec2 a_texCoord;\nlayout(location = 3) in vec4 a_tangent;\n#if CC_USE_SKINNING\nlayout(location = 4) in u32vec4 a_joints;\nlayout(location = 5) in vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nlayout(location = 6) in highp vec4 a_jointAnimInfo;\n#endif\nlayout(location = 7) in vec4 a_matWorld0;\nlayout(location = 8) in vec4 a_matWorld1;\nlayout(location = 9) in vec4 a_matWorld2;\n#if CC_USE_LIGHTMAP\nlayout(location = 10) in vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nlayout(location = 11) in vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nlayout(location = 12) in float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nint getVertexId() {\nreturn gl_VertexIndex;\n}\n#endif\n#if CC_USE_MORPH\nlayout(set = 2, binding = 4) uniform CCMorph {\nvec4 cc_displacementWeights[15];\nvec4 cc_displacementTextureInfo;\n};\nvec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\nfloat pixelIndexF = float(pixelIndex);\nfloat x = mod(pixelIndexF, textureResolution.x);\nfloat y = floor(pixelIndexF / textureResolution.x);\nreturn vec2(x, y);\n}\nvec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\nreturn (vec2(location.x, location.y) + .5) / textureResolution;\n}\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int pixelIndex) {\nivec2 texSize = textureSize(tex, 0);\nreturn texelFetch(tex, ivec2(pixelIndex % texSize.x, pixelIndex / texSize.x), 0);\n}\n#else\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex * 4;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\nreturn vec4(\ndecode32(texture(tex, x)),\ndecode32(texture(tex, y)),\ndecode32(texture(tex, z)),\n1.0\n);\n}\n#endif\nfloat getDisplacementWeight(int index) {\nint quot = index / 4;\nint remainder = index - quot * 4;\nif (remainder == 0) {\nreturn cc_displacementWeights[quot].x;\n} else if (remainder == 1) {\nreturn cc_displacementWeights[quot].y;\n} else if (remainder == 2) {\nreturn cc_displacementWeights[quot].z;\n} else {\nreturn cc_displacementWeights[quot].w;\n}\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\nreturn fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n#else\nvec3 result = vec3(0, 0, 0);\nint nVertices = int(cc_displacementTextureInfo.z);\nfor (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\nresult += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n}\nreturn result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\nlayout(set = 2, binding = 7) uniform sampler2D cc_PositionDisplacements;\nvec3 getPositionDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nlayout(set = 2, binding = 8) uniform sampler2D cc_NormalDisplacements;\nvec3 getNormalDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\nlayout(set = 2, binding = 9) uniform sampler2D cc_TangentDisplacements;\nvec3 getTangentDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n}\n#endif\nvoid applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nint vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nnormal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\ntangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\n#if CC_USE_BAKED_ANIMATION\nlayout(set = 2, binding = 3) uniform CCSkinningTexture {\nhighp vec4 cc_jointTextureInfo;\n};\nlayout(set = 2, binding = 2) uniform CCSkinningAnimation {\nhighp vec4 cc_jointAnimInfo;\n};\nlayout(set = 2, binding = 6) uniform highp sampler2D cc_jointTexture;\nvoid CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n{\n#if USE_INSTANCING\nhighp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n#else\nhighp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n#endif\ninvSize = cc_jointTextureInfo.w;\nhighp float tempY = floor(temp * invSize);\nx = floor(temp - tempY * cc_jointTextureInfo.x);\ny = (tempY + 0.5) * invSize;\n}\n#else\nlayout(set = 2, binding = 3) uniform CCSkinning {\nhighp vec4 cc_joints[30 * 3];\n};\n#endif\n#if CC_USE_BAKED_ANIMATION\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(3.0, i, x, y, invSize);\nvec4 v1 = texture(cc_jointTexture, vec2((x + 0.5) * invSize, y));\nvec4 v2 = texture(cc_jointTexture, vec2((x + 1.5) * invSize, y));\nvec4 v3 = texture(cc_jointTexture, vec2((x + 2.5) * invSize, y));\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#else\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(12.0, i, x, y, invSize);\nvec4 v1 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n);\nvec4 v2 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n);\nvec4 v3 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n);\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\n#else\nmat4 getJointMatrix (float i) {\nint idx = int(i);\nvec4 v1 = cc_joints[idx * 3];\nvec4 v2 = cc_joints[idx * 3 + 1];\nvec4 v3 = cc_joints[idx * 3 + 2];\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\nmat4 skinMatrix () {\nvec4 joints = vec4(a_joints);\nreturn getJointMatrix(joints.x) * a_weights.x\n+ getJointMatrix(joints.y) * a_weights.y\n+ getJointMatrix(joints.z) * a_weights.z\n+ getJointMatrix(joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\nmat4 m = skinMatrix();\nposition = m * position;\n}\nvoid CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nmat4 m = skinMatrix();\nposition = m * position;\nnormal = (m * vec4(normal, 0.0)).xyz;\ntangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n}\n#endif\nvoid CCVertInput(inout StandardVertInput In)\n{\nIn.position = vec4(a_position, 1.0);\nIn.normal = a_normal;\nIn.tangent = a_tangent;\n#if CC_USE_MORPH\napplyMorph(In.position, In.normal, In.tangent);\n#endif\n#if CC_USE_SKINNING\nCCSkin(In.position, In.normal, In.tangent);\n#endif\n}\nlayout(set = 0, binding = 0) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(set = 0, binding = 1) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\nlayout(location = 0) out vec2 v_uv;\nvoid main () {\nStandardVertInput In;\nCCVertInput(In);\nIn.position.xy = cc_cameraPos.w == 0.0 ? vec2(In.position.xy.x, -In.position.xy.y) : In.position.xy;\ngl_Position = In.position;\ngl_Position.y = gl_Position.y;\nv_uv = a_texCoord;\n}", "frag": "\nprecision highp float;\nlayout(set = 0, binding = 0) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(set = 0, binding = 1) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\nlayout(location = 0) in vec2 v_uv;\nlayout(set = 1, binding = 0) uniform BloomUBO {\nmediump vec4 texSize;\n};\nlayout(set = 1, binding = 1) uniform sampler2D outputResultMap;\nlayout(set = 1, binding = 2) uniform sampler2D bloomTexture;\nlayout(location = 0) out vec4 fragColor;\nvoid main() {\nvec4 hdrColor = texture(outputResultMap, v_uv);\nvec3 bloomColor = texture(bloomTexture, v_uv).rgb;\nvec3 result = hdrColor.rgb + bloomColor * texSize.w * hdrColor.a;\nfragColor = vec4(result, hdrColor.a);\n}", } ], [ { - "vert": "\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nlayout(location = 0) in vec3 a_position;\nlayout(location = 1) in vec3 a_normal;\nlayout(location = 2) in vec2 a_texCoord;\nlayout(location = 3) in vec4 a_tangent;\n#if CC_USE_SKINNING\nlayout(location = 4) in u32vec4 a_joints;\nlayout(location = 5) in vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nlayout(location = 6) in highp vec4 a_jointAnimInfo;\n#endif\nlayout(location = 7) in vec4 a_matWorld0;\nlayout(location = 8) in vec4 a_matWorld1;\nlayout(location = 9) in vec4 a_matWorld2;\n#if USE_LIGHTMAP\nlayout(location = 10) in vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nlayout(location = 11) in vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nlayout(location = 12) in float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\n#endif\nlayout(set = 0, binding = 0) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(set = 0, binding = 1) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\nlayout(location = 0) out vec2 v_uv;\nvoid main () {\nvec4 position;\nposition = vec4(a_position, 1.0);\nposition.xy = cc_cameraPos.w == 0.0 ? vec2(position.xy.x, -position.xy.y) : position.xy;\ngl_Position = vec4(position.x, position.y, 1.0, 1.0);\nv_uv = a_texCoord;\n}", - "frag": "\nprecision highp float;\nlayout(set = 0, binding = 0) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(set = 0, binding = 1) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nvec3 SRGBToLinear (vec3 gamma) {\nreturn gamma * gamma;\n}\nlayout(set = 0, binding = 2) uniform CCShadow {\nhighp mat4 cc_matLightPlaneProj;\nhighp mat4 cc_matLightView;\nhighp mat4 cc_matLightViewProj;\nhighp vec4 cc_shadowInvProjDepthInfo;\nhighp vec4 cc_shadowProjDepthInfo;\nhighp vec4 cc_shadowProjInfo;\nmediump vec4 cc_shadowNFLSInfo;\nmediump vec4 cc_shadowWHPBInfo;\nmediump vec4 cc_shadowLPNNInfo;\nlowp vec4 cc_shadowColor;\nmediump vec4 cc_planarNDInfo;\n};\nhighp float unpackHighpData (float mainPart, float modPart) {\nhighp float data = mainPart;\nreturn data + modPart;\n}\nhighp float unpackHighpData (float mainPart, float modPart, const float modValue) {\nhighp float data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nhighp vec2 unpackHighpData (vec2 mainPart, vec2 modPart) {\nhighp vec2 data = mainPart;\nreturn data + modPart;\n}\nhighp vec2 unpackHighpData (vec2 mainPart, vec2 modPart, const float modValue) {\nhighp vec2 data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nhighp vec3 unpackHighpData (vec3 mainPart, vec3 modPart) {\nhighp vec3 data = mainPart;\nreturn data + modPart;\n}\nhighp vec3 unpackHighpData (vec3 mainPart, vec3 modPart, const float modValue) {\nhighp vec3 data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nhighp vec4 unpackHighpData (vec4 mainPart, vec4 modPart) {\nhighp vec4 data = mainPart;\nreturn data + modPart;\n}\nhighp vec4 unpackHighpData (vec4 mainPart, vec4 modPart, const float modValue) {\nhighp vec4 data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nlayout(set = 2, binding = 0) uniform CCLocal {\nhighp mat4 cc_matWorld;\nhighp mat4 cc_matWorldIT;\nhighp vec4 cc_lightingMapUVParam;\nhighp vec4 cc_localShadowBias;\n};\nfloat CCGetLinearDepthFromViewSpace(vec3 viewPos) {\nfloat dist = length(viewPos);\nreturn (dist - cc_shadowNFLSInfo.x) / (cc_shadowNFLSInfo.y - cc_shadowNFLSInfo.x);\n}\nfloat CCGetLinearDepth(vec3 worldPos) {\nvec4 viewStartPos = cc_matLightView * vec4(worldPos.xyz, 1.0);\nreturn CCGetLinearDepthFromViewSpace(viewStartPos.xyz);\n}\n#if CC_RECEIVE_SHADOW\nlayout(set = 0, binding = 3) uniform highp sampler2D cc_shadowMap;\nlayout(set = 0, binding = 5) uniform highp sampler2D cc_spotLightingMap;\nvec4 ApplyShadowDepthBias_FaceNormal(vec4 shadowPos, vec3 worldNormal, float normalBias)\n{\nvec4 newShadowPos = shadowPos;\nif(normalBias > EPSILON_LOWP)\n{\nvec4 viewNormal = cc_matLightView * vec4(worldNormal, 0.0);\nif(viewNormal.z < 0.1)\nnewShadowPos.xy += viewNormal.xy * cc_shadowProjInfo.xy * normalBias * clamp(viewNormal.z, 0.001, 0.1);\n}\nreturn newShadowPos;\n}\nvec4 ApplyShadowDepthBias_Perspective(vec4 shadowPos, float viewspaceDepthBias)\n{\nvec3 viewSpacePos;\nviewSpacePos.xy = shadowPos.xy * cc_shadowProjInfo.zw;\nviewSpacePos.z = shadowPos.z * cc_shadowInvProjDepthInfo.x + shadowPos.w * cc_shadowInvProjDepthInfo.y;\nviewSpacePos.xyz += cc_shadowProjDepthInfo.z * normalize(viewSpacePos.xyz) * viewspaceDepthBias;\nvec4 clipSpacePos;\nclipSpacePos.xy = viewSpacePos.xy * cc_shadowProjInfo.xy;\nclipSpacePos.zw = viewSpacePos.z * cc_shadowProjDepthInfo.xz + vec2(cc_shadowProjDepthInfo.y, 0.0);\nif (cc_shadowNFLSInfo.z > EPSILON) {\nclipSpacePos.z = CCGetLinearDepthFromViewSpace(viewSpacePos.xyz);\nclipSpacePos.z = (clipSpacePos.z * 2.0 - 1.0) * clipSpacePos.w;\n}\nreturn clipSpacePos;\n}\nvec4 ApplyShadowDepthBias_Orthographic(vec4 shadowPos, float viewspaceDepthBias)\n{\nfloat coeffA = cc_shadowProjDepthInfo.x;\nfloat coeffB = cc_shadowProjDepthInfo.y;\nfloat viewSpacePos_z = (shadowPos.z - coeffB) / coeffA;\nviewSpacePos_z += viewspaceDepthBias;\nvec4 result = shadowPos;\nresult.z = viewSpacePos_z * coeffA + coeffB;\nreturn result;\n}\nfloat CCGetShadowFactorHard (vec4 shadowPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Orthographic(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat shadow = 0.0;\nfloat closestDepth = 0.0;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nclosestDepth = dot(texture(cc_shadowMap, clipPos.xy), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0));\n} else {\nclosestDepth = texture(cc_shadowMap, clipPos.xy).x;\n}\nshadow = step(clipPos.z, closestDepth);\nreturn shadow;\n}\nfloat CCGetShadowFactorSoft (vec4 shadowPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Orthographic(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat offsetDepth = clipPos.z;\nvec2 mapSize = cc_shadowWHPBInfo.xy;\nvec2 oneTap = 1.0 / mapSize;\nvec2 clipPos_offset = clipPos.xy + oneTap;\nfloat block0, block1, block2, block3;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos.y)).x);\nblock1 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset.x, clipPos.y)).x);\nblock2 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset.y)).x);\nblock3 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset.x, clipPos_offset.y)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * mapSize.x;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block2, block3, coefX);\nfloat coefY = mod(clipPos.y, oneTap.y) * mapSize.y;\nreturn mix(resultX, resultY, coefY);\n}\nfloat CCGetShadowFactorSoft2X (vec4 shadowPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Orthographic(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat offsetDepth = clipPos.z;\nvec2 mapSize = cc_shadowWHPBInfo.xy;\nvec2 oneTap = 1.0 / mapSize;\nfloat clipPos_offset_L = clipPos.x - oneTap.x;\nfloat clipPos_offset_R = clipPos.x + oneTap.x;\nfloat clipPos_offset_U = clipPos.y - oneTap.y;\nfloat clipPos_offset_D = clipPos.y + oneTap.y;\nfloat block0, block1, block2, block3, block4, block5, block6, block7, block8;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock4 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock5 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock6 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock7 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock8 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_U)).x);\nblock1 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset_U)).x);\nblock2 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_U)).x);\nblock3 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos.y)).x);\nblock4 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos.y)).x);\nblock5 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos.y)).x);\nblock6 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_D)).x);\nblock7 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset_D)).x);\nblock8 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_D)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * mapSize.x;\nfloat coefY = mod(clipPos.y, oneTap.y) * mapSize.y;\nfloat shadow = 0.0;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block3, block4, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block1, block2, coefX);\nresultY = mix(block4, block5, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block3, block4, coefX);\nresultY = mix(block6, block7, coefX);\nshadow += mix(resultX, resultY, coefY);\nresultX = mix(block4, block5, coefX);\nresultY = mix(block7, block8, coefX);\nshadow += mix(resultX, resultY, coefY);\nreturn shadow * 0.25;\n}\nfloat CCGetSpotLightShadowFactorHard (vec4 shadowPos, vec3 worldPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Perspective(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat shadow = 0.0;\nfloat closestDepth = 0.0;\nfloat depth = clipPos.z;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nclosestDepth = dot(texture(cc_spotLightingMap, clipPos.xy), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0));\n} else {\nclosestDepth = texture(cc_spotLightingMap, clipPos.xy).x;\n}\nshadow = step(depth, closestDepth);\nreturn shadow;\n}\nfloat CCGetSpotLightShadowFactorSoft (vec4 shadowPos, vec3 worldPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Perspective(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat depth = 0.0;\nif (cc_shadowNFLSInfo.z > EPSILON) {\ndepth = CCGetLinearDepth(worldPos);\n} else {\ndepth = clipPos.z;\n}\nvec2 oneTap = 1.0 / cc_shadowWHPBInfo.xy;\nvec2 clipPos_offset = clipPos.xy + oneTap;\nfloat block0, block1, block2, block3;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)).x);\nblock1 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos.y)).x);\nblock2 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset.y)).x);\nblock3 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos_offset.y)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * cc_shadowWHPBInfo.x;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block2, block3, coefX);\nfloat coefY = mod(clipPos.y, oneTap.y) * cc_shadowWHPBInfo.y;\nreturn mix(resultX, resultY, coefY);\n}\nfloat CCGetSpotLightShadowFactorSoft2X (vec4 shadowPos, vec3 worldPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Perspective(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat depth = 0.0;\nif (cc_shadowNFLSInfo.z > EPSILON) {\ndepth = CCGetLinearDepth(worldPos);\n} else {\ndepth = clipPos.z;\n}\nvec2 mapSize = cc_shadowWHPBInfo.xy;\nvec2 oneTap = 1.0 / mapSize;\nfloat clipPos_offset_L = clipPos.x - oneTap.x;\nfloat clipPos_offset_R = clipPos.x + oneTap.x;\nfloat clipPos_offset_U = clipPos.y - oneTap.y;\nfloat clipPos_offset_D = clipPos.y + oneTap.y;\nfloat block0, block1, block2, block3, block4, block5, block6, block7, block8;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock4 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock5 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock6 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock7 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock8 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_U)).x);\nblock1 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_U)).x);\nblock2 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_U)).x);\nblock3 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos.y)).x);\nblock4 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)).x);\nblock5 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos.y)).x);\nblock6 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_D)).x);\nblock7 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_D)).x);\nblock8 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_D)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * mapSize.x;\nfloat coefY = mod(clipPos.y, oneTap.y) * mapSize.y;\nfloat shadow = 0.0;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block3, block4, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block1, block2, coefX);\nresultY = mix(block4, block5, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block3, block4, coefX);\nresultY = mix(block6, block7, coefX);\nshadow += mix(resultX, resultY, coefY);\nresultX = mix(block4, block5, coefX);\nresultY = mix(block7, block8, coefX);\nshadow += mix(resultX, resultY, coefY);\nreturn shadow * 0.25;\n}\nfloat CCSpotShadowFactorBase(vec4 shadowPos, vec3 worldPos, vec2 shadowBias)\n{\nfloat pcf = cc_shadowWHPBInfo.z;\nif (pcf > 1.9) {\nreturn CCGetSpotLightShadowFactorSoft2X(shadowPos, worldPos, shadowBias.x);\n}else if (pcf > 0.9) {\nreturn CCGetSpotLightShadowFactorSoft(shadowPos, worldPos, shadowBias.x);\n}else {\nreturn CCGetSpotLightShadowFactorHard(shadowPos, worldPos, shadowBias.x);\n}\n}\nfloat CCShadowFactorBase(vec4 shadowPos, vec3 N, vec2 shadowBias)\n{\nfloat realtimeShadow = 1.0;\nvec4 pos = ApplyShadowDepthBias_FaceNormal(shadowPos, N, shadowBias.y);\nfloat pcf = cc_shadowWHPBInfo.z;\nif (pcf > 1.9) {\nrealtimeShadow = CCGetShadowFactorSoft2X(pos, shadowBias.x);\n}else if (pcf > 0.9) {\nrealtimeShadow = CCGetShadowFactorSoft(pos, shadowBias.x);\n}else {\nrealtimeShadow = CCGetShadowFactorHard(pos, shadowBias.x);\n}\nreturn mix(realtimeShadow, 1.0, cc_shadowNFLSInfo.w);\n}\n#endif\n#if CC_USE_IBL\nlayout(set = 0, binding = 4) uniform samplerCube cc_environment;\nvec4 fragTextureLod (sampler2D tex, vec2 coord, float lod) {\nreturn textureLod(tex, coord, lod);\n}\nvec4 fragTextureLod (samplerCube tex, vec3 coord, float lod) {\nreturn textureLod(tex, coord, lod);\n}\nvec3 unpackRGBE (vec4 rgbe) {\nreturn rgbe.rgb * pow(1.1, rgbe.a * 255.0 - 128.0);\n}\n#if CC_USE_DIFFUSEMAP\nlayout(set = 0, binding = 6) uniform samplerCube cc_diffuseMap;\n#endif\n#endif\nfloat GGXMobile (float roughness, float NoH, vec3 H, vec3 N) {\nvec3 NxH = cross(N, H);\nfloat OneMinusNoHSqr = dot(NxH, NxH);\nfloat a = roughness * roughness;\nfloat n = NoH * a;\nfloat p = a / (OneMinusNoHSqr + n * n);\nreturn p * p;\n}\nfloat CalcSpecular (float roughness, float NoH, vec3 H, vec3 N) {\nreturn (roughness * 0.25 + 0.25) * GGXMobile(roughness, NoH, H, N);\n}\nvec3 BRDFApprox (vec3 specular, float roughness, float NoV) {\nconst vec4 c0 = vec4(-1.0, -0.0275, -0.572, 0.022);\nconst vec4 c1 = vec4(1.0, 0.0425, 1.04, -0.04);\nvec4 r = roughness * c0 + c1;\nfloat a004 = min(r.x * r.x, exp2(-9.28 * NoV)) * r.x + r.y;\nvec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;\nAB.y *= clamp(50.0 * specular.g, 0.0, 1.0);\nreturn specular * AB.x + AB.y;\n}\n#if USE_REFLECTION_DENOISE\nvec3 GetEnvReflectionWithMipFiltering(vec3 R, float roughness, float mipCount, float denoiseIntensity) {\n#if CC_USE_IBL\nfloat mip = roughness * mipCount;\nfloat delta = (dot(dFdx(R), dFdy(R))) * 1000.0;\nfloat mipBias = mix(0.0, 5.0, clamp(delta, 0.0, 1.0));\nvec4 biased = fragTextureLod(cc_environment, R, mip + mipBias);\nvec4 filtered = texture(cc_environment, R);\n#if CC_USE_IBL == 2\nbiased.rgb = unpackRGBE(biased);\nfiltered.rgb = unpackRGBE(filtered);\n#else\nbiased.rgb = SRGBToLinear(biased.rgb);\nfiltered.rgb = SRGBToLinear(filtered.rgb);\n#endif\nreturn mix(biased.rgb, filtered.rgb, denoiseIntensity);\n#else\nreturn vec3(0.0, 0.0, 0.0);\n#endif\n}\n#endif\nstruct StandardSurface {\nvec4 albedo;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nvec3 position, position_fract_part;\n#else\nvec3 position;\n#endif\nvec3 normal;\nvec3 emissive;\nvec3 lightmap;\nfloat lightmap_test;\nfloat roughness;\nfloat metallic;\nfloat occlusion;\nfloat specularIntensity;\n#if CC_RECEIVE_SHADOW\nvec2 shadowBias;\n#endif\n};\nvec4 CCStandardShadingBase (StandardSurface s, vec4 shadowPos) {\nvec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\nvec3 specular = mix(vec3(0.08 * s.specularIntensity), s.albedo.rgb, s.metallic);\nvec3 position;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nposition = unpackHighpData(s.position, s.position_fract_part);\n#else\nposition = s.position;\n#endif\nvec3 N = normalize(s.normal);\nvec3 V = normalize(cc_cameraPos.xyz - position);\nfloat NV = max(abs(dot(N, V)), 0.0);\nspecular = BRDFApprox(specular, s.roughness, NV);\nvec3 L = normalize(-cc_mainLitDir.xyz);\nvec3 H = normalize(L + V);\nfloat NH = max(dot(N, H), 0.0);\nfloat NL = max(dot(N, L), 0.0);\nvec3 finalColor = NL * cc_mainLitColor.rgb * cc_mainLitColor.w;\nvec3 diffuseContrib = diffuse / PI;\nvec3 specularContrib = specular * CalcSpecular(s.roughness, NH, H, N);\nvec3 dirlightContrib = (diffuseContrib + specularContrib);\nfloat shadow = 1.0;\n#if CC_RECEIVE_SHADOW\nif (NL > 0.0 && cc_mainLitDir.w > 0.0) {\nshadow = CCShadowFactorBase(shadowPos, N, s.shadowBias);\n}\n#endif\ndirlightContrib *= shadow;\nfinalColor *= dirlightContrib;\n#if USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\nif (s.lightmap_test > EPSILON_LOWP) {\nfinalColor = diffuse * s.lightmap.rgb * shadow;\n}\n#endif\nfloat fAmb = 0.5 - N.y * 0.5;\nvec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb);\n#if CC_USE_IBL\n#if CC_USE_DIFFUSEMAP\nvec4 diffuseMap = texture(cc_diffuseMap, N);\n#if CC_USE_DIFFUSEMAP == 2\nambDiff = unpackRGBE(diffuseMap);\n#else\nambDiff = SRGBToLinear(diffuseMap.rgb);\n#endif\n#endif\nvec3 R = normalize(reflect(-V, N));\n#if USE_REFLECTION_DENOISE\nvec3 env = GetEnvReflectionWithMipFiltering(R, s.roughness, cc_ambientGround.w, 0.6);\n#else\nvec4 envmap = fragTextureLod(cc_environment, R, s.roughness * cc_ambientGround.w);\n#if CC_USE_IBL == 2\nvec3 env = unpackRGBE(envmap);\n#else\nvec3 env = SRGBToLinear(envmap.rgb);\n#endif\n#endif\nfinalColor += env * cc_ambientSky.w * specular * s.occlusion;\n#endif\nfinalColor += ambDiff.rgb * cc_ambientSky.w * diffuse * s.occlusion;\nfinalColor += s.emissive;\nreturn vec4(finalColor, s.albedo.a);\n}\n#if CC_PIPELINE_TYPE == 0\n#define LIGHTS_PER_PASS 1\n#else\n#define LIGHTS_PER_PASS 10\n#endif\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 0\nlayout(set = 2, binding = 1) uniform CCForwardLight {\nhighp vec4 cc_lightPos[LIGHTS_PER_PASS];\nvec4 cc_lightColor[LIGHTS_PER_PASS];\nvec4 cc_lightSizeRangeAngle[LIGHTS_PER_PASS];\nvec4 cc_lightDir[LIGHTS_PER_PASS];\n};\n#endif\nfloat SmoothDistAtt (float distSqr, float invSqrAttRadius) {\nfloat factor = distSqr * invSqrAttRadius;\nfloat smoothFactor = clamp(1.0 - factor * factor, 0.0, 1.0);\nreturn smoothFactor * smoothFactor;\n}\nfloat GetDistAtt (float distSqr, float invSqrAttRadius) {\nfloat attenuation = 1.0 / max(distSqr, 0.01*0.01);\nattenuation *= SmoothDistAtt(distSqr , invSqrAttRadius);\nreturn attenuation;\n}\nfloat GetAngleAtt (vec3 L, vec3 litDir, float litAngleScale, float litAngleOffset) {\nfloat cd = dot(litDir, L);\nfloat attenuation = clamp(cd * litAngleScale + litAngleOffset, 0.0, 1.0);\nreturn (attenuation * attenuation);\n}\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 0\nvec4 CCStandardShadingAdditive (StandardSurface s, vec4 shadowPos) {\nvec3 position;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nposition = unpackHighpData(s.position, s.position_fract_part);\n#else\nposition = s.position;\n#endif\nvec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\nvec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\nvec3 diffuseContrib = diffuse / PI;\nvec3 N = normalize(s.normal);\nvec3 V = normalize(cc_cameraPos.xyz - position);\nfloat NV = max(abs(dot(N, V)), 0.0);\nspecular = BRDFApprox(specular, s.roughness, NV);\nvec3 finalColor = vec3(0.0);\nint numLights = CC_PIPELINE_TYPE == 0 ? LIGHTS_PER_PASS : int(cc_lightDir[0].w);\nfor (int i = 0; i < LIGHTS_PER_PASS; i++) {\nif (i >= numLights) break;\nvec3 SLU = cc_lightPos[i].xyz - position;\nvec3 SL = normalize(SLU);\nvec3 SH = normalize(SL + V);\nfloat SNL = max(dot(N, SL), 0.0);\nfloat SNH = max(dot(N, SH), 0.0);\nfloat distSqr = dot(SLU, SLU);\nfloat litRadius = cc_lightSizeRangeAngle[i].x;\nfloat litRadiusSqr = litRadius * litRadius;\nfloat illum = litRadiusSqr / max(litRadiusSqr, distSqr);\nfloat attRadiusSqrInv = 1.0 / max(cc_lightSizeRangeAngle[i].y, 0.01);\nattRadiusSqrInv *= attRadiusSqrInv;\nfloat att = GetDistAtt(distSqr, attRadiusSqrInv);\nvec3 lspec = specular * CalcSpecular(s.roughness, SNH, SH, N);\nif (cc_lightPos[i].w > 0.0) {\nfloat cosInner = max(dot(-cc_lightDir[i].xyz, SL), 0.01);\nfloat cosOuter = cc_lightSizeRangeAngle[i].z;\nfloat litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\nfloat litAngleOffset = -cosOuter * litAngleScale;\natt *= GetAngleAtt(SL, -cc_lightDir[i].xyz, litAngleScale, litAngleOffset);\n}\nvec3 lightColor = cc_lightColor[i].rgb;\nfloat shadow = 1.0;\n#if CC_RECEIVE_SHADOW\nif (cc_lightPos[i].w > 0.0 && cc_lightSizeRangeAngle[i].w > 0.0) {\nshadow = CCSpotShadowFactorBase(shadowPos, position, s.shadowBias);\n}\n#endif\nlightColor *= shadow;\nfinalColor += SNL * lightColor * cc_lightColor[i].w * illum * att * (diffuseContrib + lspec);\n}\nreturn vec4(finalColor, 0.0);\n}\n#endif\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 1\nlayout(set = 1, binding = 4) readonly buffer b_ccLightsBuffer { vec4 b_ccLights[]; };\nlayout(set = 1, binding = 5) readonly buffer b_clusterLightIndicesBuffer { uint b_clusterLightIndices[]; };\nlayout(set = 1, binding = 6) readonly buffer b_clusterLightGridBuffer { uvec4 b_clusterLightGrid[]; };\nstruct CCLight\n{\nvec4 cc_lightPos;\nvec4 cc_lightColor;\nvec4 cc_lightSizeRangeAngle;\nvec4 cc_lightDir;\n};\nstruct Cluster\n{\nvec3 minBounds;\nvec3 maxBounds;\n};\nstruct LightGrid\n{\nuint offset;\nuint ccLights;\n};\nCCLight getCCLight(uint i)\n{\nCCLight light;\nlight.cc_lightPos = b_ccLights[4u * i + 0u];\nlight.cc_lightColor = b_ccLights[4u * i + 1u];\nlight.cc_lightSizeRangeAngle = b_ccLights[4u * i + 2u];\nlight.cc_lightDir = b_ccLights[4u * i + 3u];\nreturn light;\n}\nLightGrid getLightGrid(uint cluster)\n{\nuvec4 gridvec = b_clusterLightGrid[cluster];\nLightGrid grid;\ngrid.offset = gridvec.x;\ngrid.ccLights = gridvec.y;\nreturn grid;\n}\nuint getGridLightIndex(uint start, uint offset)\n{\nreturn b_clusterLightIndices[start + offset];\n}\nuint getClusterZIndex(vec4 worldPos)\n{\nfloat scale = float(24) / log(cc_nearFar.y / cc_nearFar.x);\nfloat bias = -(float(24) * log(cc_nearFar.x) / log(cc_nearFar.y / cc_nearFar.x));\nfloat eyeDepth = -(cc_matView * worldPos).z;\nuint zIndex = uint(max(log(eyeDepth) * scale + bias, 0.0));\nreturn zIndex;\n}\nuint getClusterIndex(vec4 fragCoord, vec4 worldPos)\n{\nuint zIndex = getClusterZIndex(worldPos);\nfloat clusterSizeX = ceil(cc_viewPort.z / float(16));\nfloat clusterSizeY = ceil(cc_viewPort.w / float(8));\nuvec3 indices = uvec3(uvec2(fragCoord.xy / vec2(clusterSizeX, clusterSizeY)), zIndex);\nuint cluster = (16u * 8u) * indices.z + 16u * indices.y + indices.x;\nreturn cluster;\n}\nvec4 CCClusterShadingAdditive (StandardSurface s, vec4 shadowPos) {\nvec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\nvec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\nvec3 diffuseContrib = diffuse / PI;\nvec3 position;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nposition = unpackHighpData(s.position, s.position_fract_part);\n#else\nposition = s.position;\n#endif\nvec3 N = normalize(s.normal);\nvec3 V = normalize(cc_cameraPos.xyz - position);\nfloat NV = max(abs(dot(N, V)), 0.001);\nspecular = BRDFApprox(specular, s.roughness, NV);\nvec3 finalColor = vec3(0.0);\nuint cluster = getClusterIndex(gl_FragCoord, vec4(position, 1.0));\nLightGrid grid = getLightGrid(cluster);\nuint numLights = grid.ccLights;\nfor (uint i = 0u; i < 100u; i++) {\nif (i >= numLights) break;\nuint lightIndex = getGridLightIndex(grid.offset, i);\nCCLight light = getCCLight(lightIndex);\nvec3 SLU = light.cc_lightPos.xyz - position;\nvec3 SL = normalize(SLU);\nvec3 SH = normalize(SL + V);\nfloat SNL = max(dot(N, SL), 0.001);\nfloat SNH = max(dot(N, SH), 0.0);\nfloat distSqr = dot(SLU, SLU);\nfloat litRadius = light.cc_lightSizeRangeAngle.x;\nfloat litRadiusSqr = litRadius * litRadius;\nfloat illum = PI * (litRadiusSqr / max(litRadiusSqr , distSqr));\nfloat attRadiusSqrInv = 1.0 / max(light.cc_lightSizeRangeAngle.y, 0.01);\nattRadiusSqrInv *= attRadiusSqrInv;\nfloat att = GetDistAtt(distSqr, attRadiusSqrInv);\nvec3 lspec = specular * CalcSpecular(s.roughness, SNH, SH, N);\nif (light.cc_lightPos.w > 0.0) {\nfloat cosInner = max(dot(-light.cc_lightDir.xyz, SL), 0.01);\nfloat cosOuter = light.cc_lightSizeRangeAngle.z;\nfloat litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\nfloat litAngleOffset = -cosOuter * litAngleScale;\natt *= GetAngleAtt(SL, -light.cc_lightDir.xyz, litAngleScale, litAngleOffset);\n}\nvec3 lightColor = light.cc_lightColor.rgb;\nfloat shadow = 1.0;\n#if CC_RECEIVE_SHADOW\nif (light.cc_lightPos.w > 0.0) {\nshadow = CCSpotShadowFactorBase(shadowPos, position, s.shadowBias);\n}\n#endif\nlightColor *= shadow;\nfinalColor += SNL * lightColor * light.cc_lightColor.w * illum * att * (diffuseContrib + lspec);\n}\nreturn vec4(finalColor, 0.0);\n}\n#endif\nvec3 ACESToneMap (vec3 color) {\ncolor = min(color, vec3(8.0));\nconst float A = 2.51;\nconst float B = 0.03;\nconst float C = 2.43;\nconst float D = 0.59;\nconst float E = 0.14;\nreturn (color * (A * color + B)) / (color * (C * color + D) + E);\n}\nvec4 CCFragOutput (vec4 color) {\n#if CC_USE_HDR\ncolor.rgb = ACESToneMap(color.rgb);\n#endif\ncolor.rgb = sqrt(color.rgb);\nreturn color;\n}\nfloat LinearFog(vec4 pos) {\nvec4 wPos = pos;\nfloat cam_dis = distance(cc_cameraPos, wPos);\nfloat fogStart = cc_fogBase.x;\nfloat fogEnd = cc_fogBase.y;\nreturn clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * fogDensity);\nreturn f;\n}\nfloat ExpSquaredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\nreturn f;\n}\nfloat LayeredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat _FogTop = cc_fogAdd.x;\nfloat _FogRange = cc_fogAdd.y;\nvec3 camWorldProj = cc_cameraPos.xyz;\ncamWorldProj.y = 0.;\nvec3 worldPosProj = wPos.xyz;\nworldPosProj.y = 0.;\nfloat fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\nfloat fDeltaY, fDensityIntegral;\nif (cc_cameraPos.y > _FogTop) {\nif (wPos.y < _FogTop) {\nfDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\nfDensityIntegral = fDeltaY * fDeltaY * 0.5;\n} else {\nfDeltaY = 0.;\nfDensityIntegral = 0.;\n}\n} else {\nif (wPos.y < _FogTop) {\nfloat fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfloat fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\nfDeltaY = abs(fDeltaA - fDeltaB);\nfDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n} else {\nfDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n}\n}\nfloat fDensity;\nif (fDeltaY != 0.) {\nfDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n} else {\nfDensity = 0.;\n}\nfloat f = exp(-fDensity);\nreturn f;\n}\nvoid CC_TRANSFER_FOG_BASE(vec4 pos, out float factor)\n{\n#if CC_USE_FOG == 0\nfactor = LinearFog(pos);\n#elif CC_USE_FOG == 1\nfactor = ExpFog(pos);\n#elif CC_USE_FOG == 2\nfactor = ExpSquaredFog(pos);\n#elif CC_USE_FOG == 3\nfactor = LayeredFog(pos);\n#else\nfactor = 1.0;\n#endif\n}\nvoid CC_APPLY_FOG_BASE(inout vec4 color, float factor) {\ncolor = vec4(mix(cc_fogColor.rgb, color.rgb, factor), color.a);\n}\nvec2 signNotZero(vec2 v) {\nreturn vec2((v.x >= 0.0) ? +1.0 : -1.0, (v.y >= 0.0) ? +1.0 : -1.0);\n}\nvec3 oct_to_float32x3(vec2 e) {\nvec3 v = vec3(e.xy, 1.0 - abs(e.x) - abs(e.y));\nif (v.z < 0.0) v.xy = (1.0 - abs(v.yx)) * signNotZero(v.xy);\nreturn normalize(v);\n}\nvec4 screen2WS(vec3 coord) {\nvec3 ndc = vec3(\n2.0 * (coord.x - cc_viewPort.x) / cc_viewPort.z - 1.0,\n2.0 * (coord.y - cc_viewPort.y) / cc_viewPort.w - 1.0,\ncoord.z);\nvec4 world = ((cc_matViewProjInv) * (vec4(ndc, 1.0)));\nworld = world / world.w;\nreturn world;\n}\nlayout(location = 0) in vec2 v_uv;\n#if CC_DEVICE_CAN_BENEFIT_FROM_INPUT_ATTACHMENT\nlayout(set = 1, binding = 0, input_attachment_index = 0) uniform subpassInput gbuffer_albedoMap;\nlayout(set = 1, binding = 1, input_attachment_index = 1) uniform subpassInput gbuffer_normalMap;\nlayout(set = 1, binding = 2, input_attachment_index = 2) uniform subpassInput gbuffer_emissiveMap;\nlayout(set = 1, binding = 3, input_attachment_index = 3) uniform subpassInput depth_stencil;\n#else\nlayout(set = 1, binding = 0) uniform sampler2D gbuffer_albedoMap;\nlayout(set = 1, binding = 1) uniform sampler2D gbuffer_normalMap;\nlayout(set = 1, binding = 2) uniform sampler2D gbuffer_emissiveMap;\nlayout(set = 1, binding = 3) uniform sampler2D depth_stencil;\n#endif\n#if !CC_DEVICE_CAN_BENEFIT_FROM_INPUT_ATTACHMENT || __VERSION__ >= 450\nlayout(location = 0) out vec4 fragColor;\n#endif\nvoid main () {\nStandardSurface s;\n#if CC_DEVICE_CAN_BENEFIT_FROM_INPUT_ATTACHMENT\nvec4 albedoMap = subpassLoad(gbuffer_albedoMap);\nvec4 normalMap = subpassLoad(gbuffer_normalMap);\nvec4 emissiveMap = subpassLoad(gbuffer_emissiveMap);\nfloat depth = subpassLoad(depth_stencil).x;\n#else\nvec4 albedoMap = texture(gbuffer_albedoMap,v_uv);\nvec4 normalMap = texture(gbuffer_normalMap,v_uv);\nvec4 emissiveMap = texture(gbuffer_emissiveMap,v_uv);\nfloat depth = texture(depth_stencil, v_uv).x;\n#endif\ns.albedo = albedoMap;\nvec3 position = screen2WS(vec3(gl_FragCoord.xy, depth)).xyz;\ns.position = position;\ns.roughness = normalMap.z;\ns.normal = oct_to_float32x3(normalMap.xy);\ns.specularIntensity = 0.5;\ns.metallic = normalMap.w;\ns.emissive = emissiveMap.xyz;\ns.occlusion = emissiveMap.w;\nfloat fogFactor;\nCC_TRANSFER_FOG_BASE(vec4(position, 1), fogFactor);\nvec4 shadowPos;\nshadowPos = cc_matLightViewProj * vec4(position, 1);\nvec4 color = CCStandardShadingBase(s, shadowPos) +\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 1\nCCClusterShadingAdditive(s, shadowPos);\n#else\nCCStandardShadingAdditive(s, shadowPos);\n#endif\nCC_APPLY_FOG_BASE(color, fogFactor);\ncolor = CCFragOutput(color);\n#if CC_DEVICE_CAN_BENEFIT_FROM_INPUT_ATTACHMENT\nfragColor = color;\n#else\nfragColor = color;\n#endif\n}", + "vert": "\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nlayout(location = 0) in vec3 a_position;\nlayout(location = 1) in vec3 a_normal;\nlayout(location = 2) in vec2 a_texCoord;\nlayout(location = 3) in vec4 a_tangent;\n#if CC_USE_SKINNING\nlayout(location = 4) in u32vec4 a_joints;\nlayout(location = 5) in vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nlayout(location = 6) in highp vec4 a_jointAnimInfo;\n#endif\nlayout(location = 7) in vec4 a_matWorld0;\nlayout(location = 8) in vec4 a_matWorld1;\nlayout(location = 9) in vec4 a_matWorld2;\n#if CC_USE_LIGHTMAP\nlayout(location = 10) in vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nlayout(location = 11) in vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nlayout(location = 12) in float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\n#endif\nlayout(set = 0, binding = 0) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(set = 0, binding = 1) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\nlayout(location = 0) out vec2 v_uv;\nvoid main () {\nvec4 position;\nposition = vec4(a_position, 1.0);\nposition.xy = cc_cameraPos.w == 0.0 ? vec2(position.xy.x, -position.xy.y) : position.xy;\ngl_Position = vec4(position.x, position.y, 1.0, 1.0);\nv_uv = a_texCoord;\n}", + "frag": "\nprecision highp float;\nlayout(set = 0, binding = 0) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(set = 0, binding = 1) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nvec3 SRGBToLinear (vec3 gamma) {\nreturn gamma * gamma;\n}\nlayout(set = 0, binding = 2) uniform CCShadow {\nhighp mat4 cc_matLightPlaneProj;\nhighp mat4 cc_matLightView;\nhighp mat4 cc_matLightViewProj;\nhighp vec4 cc_shadowInvProjDepthInfo;\nhighp vec4 cc_shadowProjDepthInfo;\nhighp vec4 cc_shadowProjInfo;\nmediump vec4 cc_shadowNFLSInfo;\nmediump vec4 cc_shadowWHPBInfo;\nmediump vec4 cc_shadowLPNNInfo;\nlowp vec4 cc_shadowColor;\nmediump vec4 cc_planarNDInfo;\n};\nhighp float unpackHighpData (float mainPart, float modPart) {\nhighp float data = mainPart;\nreturn data + modPart;\n}\nhighp float unpackHighpData (float mainPart, float modPart, const float modValue) {\nhighp float data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nhighp vec2 unpackHighpData (vec2 mainPart, vec2 modPart) {\nhighp vec2 data = mainPart;\nreturn data + modPart;\n}\nhighp vec2 unpackHighpData (vec2 mainPart, vec2 modPart, const float modValue) {\nhighp vec2 data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nhighp vec3 unpackHighpData (vec3 mainPart, vec3 modPart) {\nhighp vec3 data = mainPart;\nreturn data + modPart;\n}\nhighp vec3 unpackHighpData (vec3 mainPart, vec3 modPart, const float modValue) {\nhighp vec3 data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nhighp vec4 unpackHighpData (vec4 mainPart, vec4 modPart) {\nhighp vec4 data = mainPart;\nreturn data + modPart;\n}\nhighp vec4 unpackHighpData (vec4 mainPart, vec4 modPart, const float modValue) {\nhighp vec4 data = mainPart * modValue;\nreturn data + modPart * modValue;\n}\nlayout(set = 2, binding = 0) uniform CCLocal {\nhighp mat4 cc_matWorld;\nhighp mat4 cc_matWorldIT;\nhighp vec4 cc_lightingMapUVParam;\nhighp vec4 cc_localShadowBias;\n};\nfloat CCGetLinearDepthFromViewSpace(vec3 viewPos) {\nfloat dist = length(viewPos);\nreturn (dist - cc_shadowNFLSInfo.x) / (cc_shadowNFLSInfo.y - cc_shadowNFLSInfo.x);\n}\nfloat CCGetLinearDepth(vec3 worldPos) {\nvec4 viewStartPos = cc_matLightView * vec4(worldPos.xyz, 1.0);\nreturn CCGetLinearDepthFromViewSpace(viewStartPos.xyz);\n}\n#if CC_RECEIVE_SHADOW\nlayout(set = 0, binding = 3) uniform highp sampler2D cc_shadowMap;\nlayout(set = 0, binding = 5) uniform highp sampler2D cc_spotLightingMap;\nvec4 ApplyShadowDepthBias_FaceNormal(vec4 shadowPos, vec3 worldNormal, float normalBias)\n{\nvec4 newShadowPos = shadowPos;\nif(normalBias > EPSILON_LOWP)\n{\nvec4 viewNormal = cc_matLightView * vec4(worldNormal, 0.0);\nif(viewNormal.z < 0.1)\nnewShadowPos.xy += viewNormal.xy * cc_shadowProjInfo.xy * normalBias * clamp(viewNormal.z, 0.001, 0.1);\n}\nreturn newShadowPos;\n}\nvec4 ApplyShadowDepthBias_Perspective(vec4 shadowPos, float viewspaceDepthBias)\n{\nvec3 viewSpacePos;\nviewSpacePos.xy = shadowPos.xy * cc_shadowProjInfo.zw;\nviewSpacePos.z = shadowPos.z * cc_shadowInvProjDepthInfo.x + shadowPos.w * cc_shadowInvProjDepthInfo.y;\nviewSpacePos.xyz += cc_shadowProjDepthInfo.z * normalize(viewSpacePos.xyz) * viewspaceDepthBias;\nvec4 clipSpacePos;\nclipSpacePos.xy = viewSpacePos.xy * cc_shadowProjInfo.xy;\nclipSpacePos.zw = viewSpacePos.z * cc_shadowProjDepthInfo.xz + vec2(cc_shadowProjDepthInfo.y, 0.0);\nif (cc_shadowNFLSInfo.z > EPSILON) {\nclipSpacePos.z = CCGetLinearDepthFromViewSpace(viewSpacePos.xyz);\nclipSpacePos.z = (clipSpacePos.z * 2.0 - 1.0) * clipSpacePos.w;\n}\nreturn clipSpacePos;\n}\nvec4 ApplyShadowDepthBias_Orthographic(vec4 shadowPos, float viewspaceDepthBias)\n{\nfloat coeffA = cc_shadowProjDepthInfo.x;\nfloat coeffB = cc_shadowProjDepthInfo.y;\nfloat viewSpacePos_z = (shadowPos.z - coeffB) / coeffA;\nviewSpacePos_z += viewspaceDepthBias;\nvec4 result = shadowPos;\nresult.z = viewSpacePos_z * coeffA + coeffB;\nreturn result;\n}\nfloat CCGetShadowFactorHard (vec4 shadowPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Orthographic(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat shadow = 0.0;\nfloat closestDepth = 0.0;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nclosestDepth = dot(texture(cc_shadowMap, clipPos.xy), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0));\n} else {\nclosestDepth = texture(cc_shadowMap, clipPos.xy).x;\n}\nshadow = step(clipPos.z, closestDepth);\nreturn shadow;\n}\nfloat CCGetShadowFactorSoft (vec4 shadowPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Orthographic(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat offsetDepth = clipPos.z;\nvec2 mapSize = cc_shadowWHPBInfo.xy;\nvec2 oneTap = 1.0 / mapSize;\nvec2 clipPos_offset = clipPos.xy + oneTap;\nfloat block0, block1, block2, block3;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos.y)).x);\nblock1 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset.x, clipPos.y)).x);\nblock2 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset.y)).x);\nblock3 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset.x, clipPos_offset.y)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * mapSize.x;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block2, block3, coefX);\nfloat coefY = mod(clipPos.y, oneTap.y) * mapSize.y;\nreturn mix(resultX, resultY, coefY);\n}\nfloat CCGetShadowFactorSoft2X (vec4 shadowPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Orthographic(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat offsetDepth = clipPos.z;\nvec2 mapSize = cc_shadowWHPBInfo.xy;\nvec2 oneTap = 1.0 / mapSize;\nfloat clipPos_offset_L = clipPos.x - oneTap.x;\nfloat clipPos_offset_R = clipPos.x + oneTap.x;\nfloat clipPos_offset_U = clipPos.y - oneTap.y;\nfloat clipPos_offset_D = clipPos.y + oneTap.y;\nfloat block0, block1, block2, block3, block4, block5, block6, block7, block8;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock4 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock5 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock6 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock7 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock8 = step(offsetDepth, dot(texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_U)).x);\nblock1 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset_U)).x);\nblock2 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_U)).x);\nblock3 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos.y)).x);\nblock4 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos.y)).x);\nblock5 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos.y)).x);\nblock6 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_L, clipPos_offset_D)).x);\nblock7 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos.x, clipPos_offset_D)).x);\nblock8 = step(offsetDepth, texture(cc_shadowMap, vec2(clipPos_offset_R, clipPos_offset_D)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * mapSize.x;\nfloat coefY = mod(clipPos.y, oneTap.y) * mapSize.y;\nfloat shadow = 0.0;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block3, block4, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block1, block2, coefX);\nresultY = mix(block4, block5, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block3, block4, coefX);\nresultY = mix(block6, block7, coefX);\nshadow += mix(resultX, resultY, coefY);\nresultX = mix(block4, block5, coefX);\nresultY = mix(block7, block8, coefX);\nshadow += mix(resultX, resultY, coefY);\nreturn shadow * 0.25;\n}\nfloat CCGetSpotLightShadowFactorHard (vec4 shadowPos, vec3 worldPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Perspective(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat shadow = 0.0;\nfloat closestDepth = 0.0;\nfloat depth = clipPos.z;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nclosestDepth = dot(texture(cc_spotLightingMap, clipPos.xy), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0));\n} else {\nclosestDepth = texture(cc_spotLightingMap, clipPos.xy).x;\n}\nshadow = step(depth, closestDepth);\nreturn shadow;\n}\nfloat CCGetSpotLightShadowFactorSoft (vec4 shadowPos, vec3 worldPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Perspective(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat depth = 0.0;\nif (cc_shadowNFLSInfo.z > EPSILON) {\ndepth = CCGetLinearDepth(worldPos);\n} else {\ndepth = clipPos.z;\n}\nvec2 oneTap = 1.0 / cc_shadowWHPBInfo.xy;\nvec2 clipPos_offset = clipPos.xy + oneTap;\nfloat block0, block1, block2, block3;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos_offset.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)).x);\nblock1 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos.y)).x);\nblock2 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset.y)).x);\nblock3 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset.x, clipPos_offset.y)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * cc_shadowWHPBInfo.x;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block2, block3, coefX);\nfloat coefY = mod(clipPos.y, oneTap.y) * cc_shadowWHPBInfo.y;\nreturn mix(resultX, resultY, coefY);\n}\nfloat CCGetSpotLightShadowFactorSoft2X (vec4 shadowPos, vec3 worldPos, float bias) {\nvec4 clipPosNew = ApplyShadowDepthBias_Perspective(shadowPos, bias);\nvec3 clipPos = clipPosNew.xyz / clipPosNew.w * 0.5 + 0.5;\nif (clipPos.x < 0.0 || clipPos.x > 1.0 ||\nclipPos.y < 0.0 || clipPos.y > 1.0 ||\nclipPos.z < 0.0 || clipPos.z > 1.0) { return 1.0; }\nclipPos.xy = cc_cameraPos.w == 1.0 ? vec2(clipPos.xy.x, 1.0 - clipPos.xy.y) : clipPos.xy;\nfloat depth = 0.0;\nif (cc_shadowNFLSInfo.z > EPSILON) {\ndepth = CCGetLinearDepth(worldPos);\n} else {\ndepth = clipPos.z;\n}\nvec2 mapSize = cc_shadowWHPBInfo.xy;\nvec2 oneTap = 1.0 / mapSize;\nfloat clipPos_offset_L = clipPos.x - oneTap.x;\nfloat clipPos_offset_R = clipPos.x + oneTap.x;\nfloat clipPos_offset_U = clipPos.y - oneTap.y;\nfloat clipPos_offset_D = clipPos.y + oneTap.y;\nfloat block0, block1, block2, block3, block4, block5, block6, block7, block8;\nif (cc_shadowLPNNInfo.y > EPSILON) {\nblock0 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock1 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock2 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_U)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock3 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock4 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock5 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos.y)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock6 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock7 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\nblock8 = step(depth, dot(texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_D)), vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0)));\n} else {\nblock0 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_U)).x);\nblock1 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_U)).x);\nblock2 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_U)).x);\nblock3 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos.y)).x);\nblock4 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos.y)).x);\nblock5 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos.y)).x);\nblock6 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_L, clipPos_offset_D)).x);\nblock7 = step(depth, texture(cc_spotLightingMap, vec2(clipPos.x, clipPos_offset_D)).x);\nblock8 = step(depth, texture(cc_spotLightingMap, vec2(clipPos_offset_R, clipPos_offset_D)).x);\n}\nfloat coefX = mod(clipPos.x, oneTap.x) * mapSize.x;\nfloat coefY = mod(clipPos.y, oneTap.y) * mapSize.y;\nfloat shadow = 0.0;\nfloat resultX = mix(block0, block1, coefX);\nfloat resultY = mix(block3, block4, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block1, block2, coefX);\nresultY = mix(block4, block5, coefX);\nshadow += mix(resultX , resultY, coefY);\nresultX = mix(block3, block4, coefX);\nresultY = mix(block6, block7, coefX);\nshadow += mix(resultX, resultY, coefY);\nresultX = mix(block4, block5, coefX);\nresultY = mix(block7, block8, coefX);\nshadow += mix(resultX, resultY, coefY);\nreturn shadow * 0.25;\n}\nfloat CCSpotShadowFactorBase(vec4 shadowPos, vec3 worldPos, vec2 shadowBias)\n{\nfloat pcf = cc_shadowWHPBInfo.z;\nif (pcf > 1.9) {\nreturn CCGetSpotLightShadowFactorSoft2X(shadowPos, worldPos, shadowBias.x);\n}else if (pcf > 0.9) {\nreturn CCGetSpotLightShadowFactorSoft(shadowPos, worldPos, shadowBias.x);\n}else {\nreturn CCGetSpotLightShadowFactorHard(shadowPos, worldPos, shadowBias.x);\n}\n}\nfloat CCShadowFactorBase(vec4 shadowPos, vec3 N, vec2 shadowBias)\n{\nfloat realtimeShadow = 1.0;\nvec4 pos = ApplyShadowDepthBias_FaceNormal(shadowPos, N, shadowBias.y);\nfloat pcf = cc_shadowWHPBInfo.z;\nif (pcf > 1.9) {\nrealtimeShadow = CCGetShadowFactorSoft2X(pos, shadowBias.x);\n}else if (pcf > 0.9) {\nrealtimeShadow = CCGetShadowFactorSoft(pos, shadowBias.x);\n}else {\nrealtimeShadow = CCGetShadowFactorHard(pos, shadowBias.x);\n}\nreturn mix(realtimeShadow, 1.0, cc_shadowNFLSInfo.w);\n}\n#endif\n#if CC_USE_IBL\nlayout(set = 0, binding = 4) uniform samplerCube cc_environment;\nvec4 fragTextureLod (sampler2D tex, vec2 coord, float lod) {\nreturn textureLod(tex, coord, lod);\n}\nvec4 fragTextureLod (samplerCube tex, vec3 coord, float lod) {\nreturn textureLod(tex, coord, lod);\n}\nvec3 unpackRGBE (vec4 rgbe) {\nreturn rgbe.rgb * pow(1.1, rgbe.a * 255.0 - 128.0);\n}\n#if CC_USE_DIFFUSEMAP\nlayout(set = 0, binding = 6) uniform samplerCube cc_diffuseMap;\n#endif\n#endif\nfloat GGXMobile (float roughness, float NoH, vec3 H, vec3 N) {\nvec3 NxH = cross(N, H);\nfloat OneMinusNoHSqr = dot(NxH, NxH);\nfloat a = roughness * roughness;\nfloat n = NoH * a;\nfloat p = a / (OneMinusNoHSqr + n * n);\nreturn p * p;\n}\nfloat CalcSpecular (float roughness, float NoH, vec3 H, vec3 N) {\nreturn (roughness * 0.25 + 0.25) * GGXMobile(roughness, NoH, H, N);\n}\nvec3 BRDFApprox (vec3 specular, float roughness, float NoV) {\nconst vec4 c0 = vec4(-1.0, -0.0275, -0.572, 0.022);\nconst vec4 c1 = vec4(1.0, 0.0425, 1.04, -0.04);\nvec4 r = roughness * c0 + c1;\nfloat a004 = min(r.x * r.x, exp2(-9.28 * NoV)) * r.x + r.y;\nvec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;\nAB.y *= clamp(50.0 * specular.g, 0.0, 1.0);\nreturn specular * AB.x + AB.y;\n}\n#if USE_REFLECTION_DENOISE\nvec3 GetEnvReflectionWithMipFiltering(vec3 R, float roughness, float mipCount, float denoiseIntensity) {\n#if CC_USE_IBL\nfloat mip = roughness * mipCount;\nfloat delta = (dot(dFdx(R), dFdy(R))) * 1000.0;\nfloat mipBias = mix(0.0, 5.0, clamp(delta, 0.0, 1.0));\nvec4 biased = fragTextureLod(cc_environment, R, mip + mipBias);\nvec4 filtered = texture(cc_environment, R);\n#if CC_USE_IBL == 2\nbiased.rgb = unpackRGBE(biased);\nfiltered.rgb = unpackRGBE(filtered);\n#else\nbiased.rgb = SRGBToLinear(biased.rgb);\nfiltered.rgb = SRGBToLinear(filtered.rgb);\n#endif\nreturn mix(biased.rgb, filtered.rgb, denoiseIntensity);\n#else\nreturn vec3(0.0, 0.0, 0.0);\n#endif\n}\n#endif\nstruct StandardSurface {\nvec4 albedo;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nvec3 position, position_fract_part;\n#else\nvec3 position;\n#endif\nvec3 normal;\nvec3 emissive;\nvec3 lightmap;\nfloat lightmap_test;\nfloat roughness;\nfloat metallic;\nfloat occlusion;\nfloat specularIntensity;\n#if CC_RECEIVE_SHADOW\nvec2 shadowBias;\n#endif\n};\nvec4 CCStandardShadingBase (StandardSurface s, vec4 shadowPos) {\nvec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\nvec3 specular = mix(vec3(0.08 * s.specularIntensity), s.albedo.rgb, s.metallic);\nvec3 position;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nposition = unpackHighpData(s.position, s.position_fract_part);\n#else\nposition = s.position;\n#endif\nvec3 N = normalize(s.normal);\nvec3 V = normalize(cc_cameraPos.xyz - position);\nfloat NV = max(abs(dot(N, V)), 0.0);\nspecular = BRDFApprox(specular, s.roughness, NV);\nvec3 L = normalize(-cc_mainLitDir.xyz);\nvec3 H = normalize(L + V);\nfloat NH = max(dot(N, H), 0.0);\nfloat NL = max(dot(N, L), 0.0);\nvec3 finalColor = NL * cc_mainLitColor.rgb * cc_mainLitColor.w;\nvec3 diffuseContrib = diffuse / PI;\nvec3 specularContrib = specular * CalcSpecular(s.roughness, NH, H, N);\nvec3 dirlightContrib = (diffuseContrib + specularContrib);\nfloat shadow = 1.0;\n#if CC_RECEIVE_SHADOW\nif (NL > 0.0 && cc_mainLitDir.w > 0.0) {\nshadow = CCShadowFactorBase(shadowPos, N, s.shadowBias);\n}\n#endif\ndirlightContrib *= shadow;\nfinalColor *= dirlightContrib;\n#if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD\nif (s.lightmap_test > EPSILON_LOWP) {\nfinalColor = diffuse * s.lightmap.rgb * shadow;\n}\n#endif\nfloat fAmb = 0.5 - N.y * 0.5;\nvec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb);\n#if CC_USE_IBL\n#if CC_USE_DIFFUSEMAP\nvec4 diffuseMap = texture(cc_diffuseMap, N);\n#if CC_USE_DIFFUSEMAP == 2\nambDiff = unpackRGBE(diffuseMap);\n#else\nambDiff = SRGBToLinear(diffuseMap.rgb);\n#endif\n#endif\nvec3 R = normalize(reflect(-V, N));\n#if USE_REFLECTION_DENOISE\nvec3 env = GetEnvReflectionWithMipFiltering(R, s.roughness, cc_ambientGround.w, 0.6);\n#else\nvec4 envmap = fragTextureLod(cc_environment, R, s.roughness * cc_ambientGround.w);\n#if CC_USE_IBL == 2\nvec3 env = unpackRGBE(envmap);\n#else\nvec3 env = SRGBToLinear(envmap.rgb);\n#endif\n#endif\nfinalColor += env * cc_ambientSky.w * specular * s.occlusion;\n#endif\nfinalColor += ambDiff.rgb * cc_ambientSky.w * diffuse * s.occlusion;\nfinalColor += s.emissive;\nreturn vec4(finalColor, s.albedo.a);\n}\n#if CC_PIPELINE_TYPE == 0\n#define LIGHTS_PER_PASS 1\n#else\n#define LIGHTS_PER_PASS 10\n#endif\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 0\nlayout(set = 2, binding = 1) uniform CCForwardLight {\nhighp vec4 cc_lightPos[LIGHTS_PER_PASS];\nvec4 cc_lightColor[LIGHTS_PER_PASS];\nvec4 cc_lightSizeRangeAngle[LIGHTS_PER_PASS];\nvec4 cc_lightDir[LIGHTS_PER_PASS];\n};\n#endif\nfloat SmoothDistAtt (float distSqr, float invSqrAttRadius) {\nfloat factor = distSqr * invSqrAttRadius;\nfloat smoothFactor = clamp(1.0 - factor * factor, 0.0, 1.0);\nreturn smoothFactor * smoothFactor;\n}\nfloat GetDistAtt (float distSqr, float invSqrAttRadius) {\nfloat attenuation = 1.0 / max(distSqr, 0.01*0.01);\nattenuation *= SmoothDistAtt(distSqr , invSqrAttRadius);\nreturn attenuation;\n}\nfloat GetAngleAtt (vec3 L, vec3 litDir, float litAngleScale, float litAngleOffset) {\nfloat cd = dot(litDir, L);\nfloat attenuation = clamp(cd * litAngleScale + litAngleOffset, 0.0, 1.0);\nreturn (attenuation * attenuation);\n}\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 0\nvec4 CCStandardShadingAdditive (StandardSurface s, vec4 shadowPos) {\nvec3 position;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nposition = unpackHighpData(s.position, s.position_fract_part);\n#else\nposition = s.position;\n#endif\nvec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\nvec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\nvec3 diffuseContrib = diffuse / PI;\nvec3 N = normalize(s.normal);\nvec3 V = normalize(cc_cameraPos.xyz - position);\nfloat NV = max(abs(dot(N, V)), 0.0);\nspecular = BRDFApprox(specular, s.roughness, NV);\nvec3 finalColor = vec3(0.0);\nint numLights = CC_PIPELINE_TYPE == 0 ? LIGHTS_PER_PASS : int(cc_lightDir[0].w);\nfor (int i = 0; i < LIGHTS_PER_PASS; i++) {\nif (i >= numLights) break;\nvec3 SLU = cc_lightPos[i].xyz - position;\nvec3 SL = normalize(SLU);\nvec3 SH = normalize(SL + V);\nfloat SNL = max(dot(N, SL), 0.0);\nfloat SNH = max(dot(N, SH), 0.0);\nfloat distSqr = dot(SLU, SLU);\nfloat litRadius = cc_lightSizeRangeAngle[i].x;\nfloat litRadiusSqr = litRadius * litRadius;\nfloat illum = litRadiusSqr / max(litRadiusSqr, distSqr);\nfloat attRadiusSqrInv = 1.0 / max(cc_lightSizeRangeAngle[i].y, 0.01);\nattRadiusSqrInv *= attRadiusSqrInv;\nfloat att = GetDistAtt(distSqr, attRadiusSqrInv);\nvec3 lspec = specular * CalcSpecular(s.roughness, SNH, SH, N);\nif (cc_lightPos[i].w > 0.0) {\nfloat cosInner = max(dot(-cc_lightDir[i].xyz, SL), 0.01);\nfloat cosOuter = cc_lightSizeRangeAngle[i].z;\nfloat litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\nfloat litAngleOffset = -cosOuter * litAngleScale;\natt *= GetAngleAtt(SL, -cc_lightDir[i].xyz, litAngleScale, litAngleOffset);\n}\nvec3 lightColor = cc_lightColor[i].rgb;\nfloat shadow = 1.0;\n#if CC_RECEIVE_SHADOW\nif (cc_lightPos[i].w > 0.0 && cc_lightSizeRangeAngle[i].w > 0.0) {\nshadow = CCSpotShadowFactorBase(shadowPos, position, s.shadowBias);\n}\n#endif\nlightColor *= shadow;\nfinalColor += SNL * lightColor * cc_lightColor[i].w * illum * att * (diffuseContrib + lspec);\n}\nreturn vec4(finalColor, 0.0);\n}\n#endif\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 1\nlayout(set = 1, binding = 4) readonly buffer b_ccLightsBuffer { vec4 b_ccLights[]; };\nlayout(set = 1, binding = 5) readonly buffer b_clusterLightIndicesBuffer { uint b_clusterLightIndices[]; };\nlayout(set = 1, binding = 6) readonly buffer b_clusterLightGridBuffer { uvec4 b_clusterLightGrid[]; };\nstruct CCLight\n{\nvec4 cc_lightPos;\nvec4 cc_lightColor;\nvec4 cc_lightSizeRangeAngle;\nvec4 cc_lightDir;\n};\nstruct Cluster\n{\nvec3 minBounds;\nvec3 maxBounds;\n};\nstruct LightGrid\n{\nuint offset;\nuint ccLights;\n};\nCCLight getCCLight(uint i)\n{\nCCLight light;\nlight.cc_lightPos = b_ccLights[4u * i + 0u];\nlight.cc_lightColor = b_ccLights[4u * i + 1u];\nlight.cc_lightSizeRangeAngle = b_ccLights[4u * i + 2u];\nlight.cc_lightDir = b_ccLights[4u * i + 3u];\nreturn light;\n}\nLightGrid getLightGrid(uint cluster)\n{\nuvec4 gridvec = b_clusterLightGrid[cluster];\nLightGrid grid;\ngrid.offset = gridvec.x;\ngrid.ccLights = gridvec.y;\nreturn grid;\n}\nuint getGridLightIndex(uint start, uint offset)\n{\nreturn b_clusterLightIndices[start + offset];\n}\nuint getClusterZIndex(vec4 worldPos)\n{\nfloat scale = float(24) / log(cc_nearFar.y / cc_nearFar.x);\nfloat bias = -(float(24) * log(cc_nearFar.x) / log(cc_nearFar.y / cc_nearFar.x));\nfloat eyeDepth = -(cc_matView * worldPos).z;\nuint zIndex = uint(max(log(eyeDepth) * scale + bias, 0.0));\nreturn zIndex;\n}\nuint getClusterIndex(vec4 fragCoord, vec4 worldPos)\n{\nuint zIndex = getClusterZIndex(worldPos);\nfloat clusterSizeX = ceil(cc_viewPort.z / float(16));\nfloat clusterSizeY = ceil(cc_viewPort.w / float(8));\nuvec3 indices = uvec3(uvec2(fragCoord.xy / vec2(clusterSizeX, clusterSizeY)), zIndex);\nuint cluster = (16u * 8u) * indices.z + 16u * indices.y + indices.x;\nreturn cluster;\n}\nvec4 CCClusterShadingAdditive (StandardSurface s, vec4 shadowPos) {\nvec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\nvec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\nvec3 diffuseContrib = diffuse / PI;\nvec3 position;\n#if CC_PLATFORM_ANDROID_AND_WEBGL && CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES\nposition = unpackHighpData(s.position, s.position_fract_part);\n#else\nposition = s.position;\n#endif\nvec3 N = normalize(s.normal);\nvec3 V = normalize(cc_cameraPos.xyz - position);\nfloat NV = max(abs(dot(N, V)), 0.001);\nspecular = BRDFApprox(specular, s.roughness, NV);\nvec3 finalColor = vec3(0.0);\nuint cluster = getClusterIndex(gl_FragCoord, vec4(position, 1.0));\nLightGrid grid = getLightGrid(cluster);\nuint numLights = grid.ccLights;\nfor (uint i = 0u; i < 100u; i++) {\nif (i >= numLights) break;\nuint lightIndex = getGridLightIndex(grid.offset, i);\nCCLight light = getCCLight(lightIndex);\nvec3 SLU = light.cc_lightPos.xyz - position;\nvec3 SL = normalize(SLU);\nvec3 SH = normalize(SL + V);\nfloat SNL = max(dot(N, SL), 0.001);\nfloat SNH = max(dot(N, SH), 0.0);\nfloat distSqr = dot(SLU, SLU);\nfloat litRadius = light.cc_lightSizeRangeAngle.x;\nfloat litRadiusSqr = litRadius * litRadius;\nfloat illum = PI * (litRadiusSqr / max(litRadiusSqr , distSqr));\nfloat attRadiusSqrInv = 1.0 / max(light.cc_lightSizeRangeAngle.y, 0.01);\nattRadiusSqrInv *= attRadiusSqrInv;\nfloat att = GetDistAtt(distSqr, attRadiusSqrInv);\nvec3 lspec = specular * CalcSpecular(s.roughness, SNH, SH, N);\nif (light.cc_lightPos.w > 0.0) {\nfloat cosInner = max(dot(-light.cc_lightDir.xyz, SL), 0.01);\nfloat cosOuter = light.cc_lightSizeRangeAngle.z;\nfloat litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\nfloat litAngleOffset = -cosOuter * litAngleScale;\natt *= GetAngleAtt(SL, -light.cc_lightDir.xyz, litAngleScale, litAngleOffset);\n}\nvec3 lightColor = light.cc_lightColor.rgb;\nfloat shadow = 1.0;\n#if CC_RECEIVE_SHADOW\nif (light.cc_lightPos.w > 0.0) {\nshadow = CCSpotShadowFactorBase(shadowPos, position, s.shadowBias);\n}\n#endif\nlightColor *= shadow;\nfinalColor += SNL * lightColor * light.cc_lightColor.w * illum * att * (diffuseContrib + lspec);\n}\nreturn vec4(finalColor, 0.0);\n}\n#endif\nvec3 ACESToneMap (vec3 color) {\ncolor = min(color, vec3(8.0));\nconst float A = 2.51;\nconst float B = 0.03;\nconst float C = 2.43;\nconst float D = 0.59;\nconst float E = 0.14;\nreturn (color * (A * color + B)) / (color * (C * color + D) + E);\n}\nvec4 CCFragOutput (vec4 color) {\n#if CC_USE_HDR\ncolor.rgb = ACESToneMap(color.rgb);\n#endif\ncolor.rgb = sqrt(color.rgb);\nreturn color;\n}\nfloat LinearFog(vec4 pos) {\nvec4 wPos = pos;\nfloat cam_dis = distance(cc_cameraPos, wPos);\nfloat fogStart = cc_fogBase.x;\nfloat fogEnd = cc_fogBase.y;\nreturn clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * fogDensity);\nreturn f;\n}\nfloat ExpSquaredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat fogStart = cc_fogBase.x;\nfloat fogDensity = cc_fogBase.z;\nfloat cam_dis = max(distance(cc_cameraPos, wPos) - fogStart, 0.0) / fogAtten * 4.;\nfloat f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\nreturn f;\n}\nfloat LayeredFog(vec4 pos) {\nvec4 wPos = pos;\nfloat fogAtten = cc_fogAdd.z;\nfloat _FogTop = cc_fogAdd.x;\nfloat _FogRange = cc_fogAdd.y;\nvec3 camWorldProj = cc_cameraPos.xyz;\ncamWorldProj.y = 0.;\nvec3 worldPosProj = wPos.xyz;\nworldPosProj.y = 0.;\nfloat fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\nfloat fDeltaY, fDensityIntegral;\nif (cc_cameraPos.y > _FogTop) {\nif (wPos.y < _FogTop) {\nfDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\nfDensityIntegral = fDeltaY * fDeltaY * 0.5;\n} else {\nfDeltaY = 0.;\nfDensityIntegral = 0.;\n}\n} else {\nif (wPos.y < _FogTop) {\nfloat fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfloat fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\nfDeltaY = abs(fDeltaA - fDeltaB);\nfDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n} else {\nfDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\nfDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n}\n}\nfloat fDensity;\nif (fDeltaY != 0.) {\nfDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n} else {\nfDensity = 0.;\n}\nfloat f = exp(-fDensity);\nreturn f;\n}\nvoid CC_TRANSFER_FOG_BASE(vec4 pos, out float factor)\n{\n#if CC_USE_FOG == 0\nfactor = LinearFog(pos);\n#elif CC_USE_FOG == 1\nfactor = ExpFog(pos);\n#elif CC_USE_FOG == 2\nfactor = ExpSquaredFog(pos);\n#elif CC_USE_FOG == 3\nfactor = LayeredFog(pos);\n#else\nfactor = 1.0;\n#endif\n}\nvoid CC_APPLY_FOG_BASE(inout vec4 color, float factor) {\ncolor = vec4(mix(cc_fogColor.rgb, color.rgb, factor), color.a);\n}\nvec2 signNotZero(vec2 v) {\nreturn vec2((v.x >= 0.0) ? +1.0 : -1.0, (v.y >= 0.0) ? +1.0 : -1.0);\n}\nvec3 oct_to_float32x3(vec2 e) {\nvec3 v = vec3(e.xy, 1.0 - abs(e.x) - abs(e.y));\nif (v.z < 0.0) v.xy = (1.0 - abs(v.yx)) * signNotZero(v.xy);\nreturn normalize(v);\n}\nfloat getCameraDepthRH(float ndcDepth, mat4 matProj)\n{\nreturn -matProj[3][2] / (ndcDepth + matProj[2][2]);\n}\nvec4 screen2WS(vec3 coord) {\nvec3 ndc = vec3(\n2.0 * (coord.x - cc_viewPort.x) / cc_viewPort.z - 1.0,\n2.0 * (coord.y - cc_viewPort.y) / cc_viewPort.w - 1.0,\ncoord.z);\nfloat w = -getCameraDepthRH(ndc.z, cc_matProj);\nvec4 world = (cc_matViewProjInv * vec4(ndc * w, w));\nreturn world;\n}\nlayout(location = 0) in vec2 v_uv;\n#if CC_DEVICE_CAN_BENEFIT_FROM_INPUT_ATTACHMENT\nlayout(set = 1, binding = 0, input_attachment_index = 0) uniform subpassInput gbuffer_albedoMap;\nlayout(set = 1, binding = 1, input_attachment_index = 1) uniform subpassInput gbuffer_normalMap;\nlayout(set = 1, binding = 2, input_attachment_index = 2) uniform subpassInput gbuffer_emissiveMap;\nlayout(set = 1, binding = 3, input_attachment_index = 3) uniform subpassInput depth_stencil;\n#else\nlayout(set = 1, binding = 0) uniform sampler2D gbuffer_albedoMap;\nlayout(set = 1, binding = 1) uniform sampler2D gbuffer_normalMap;\nlayout(set = 1, binding = 2) uniform sampler2D gbuffer_emissiveMap;\nlayout(set = 1, binding = 3) uniform sampler2D depth_stencil;\n#endif\n#if !CC_DEVICE_CAN_BENEFIT_FROM_INPUT_ATTACHMENT || __VERSION__ >= 450\nlayout(location = 0) out vec4 fragColor;\n#endif\nvoid main () {\nStandardSurface s;\n#if CC_DEVICE_CAN_BENEFIT_FROM_INPUT_ATTACHMENT\nvec4 albedoMap = subpassLoad(gbuffer_albedoMap);\nvec4 normalMap = subpassLoad(gbuffer_normalMap);\nvec4 emissiveMap = subpassLoad(gbuffer_emissiveMap);\nfloat depth = subpassLoad(depth_stencil).x;\n#else\nvec4 albedoMap = texture(gbuffer_albedoMap,v_uv);\nvec4 normalMap = texture(gbuffer_normalMap,v_uv);\nvec4 emissiveMap = texture(gbuffer_emissiveMap,v_uv);\nfloat depth = texture(depth_stencil, v_uv).x;\n#endif\ns.albedo = albedoMap;\nvec3 position = screen2WS(vec3(gl_FragCoord.xy, depth)).xyz;\ns.position = position;\ns.roughness = normalMap.z;\ns.normal = oct_to_float32x3(normalMap.xy);\ns.specularIntensity = 0.5;\ns.metallic = normalMap.w;\ns.emissive = emissiveMap.xyz;\ns.occlusion = emissiveMap.w;\nfloat fogFactor;\nCC_TRANSFER_FOG_BASE(vec4(position, 1), fogFactor);\nvec4 shadowPos;\nshadowPos = cc_matLightViewProj * vec4(position, 1);\nvec4 color = CCStandardShadingBase(s, shadowPos) +\n#if CC_ENABLE_CLUSTERED_LIGHT_CULLING == 1\nCCClusterShadingAdditive(s, shadowPos);\n#else\nCCStandardShadingAdditive(s, shadowPos);\n#endif\nCC_APPLY_FOG_BASE(color, fogFactor);\ncolor = CCFragOutput(color);\n#if CC_DEVICE_CAN_BENEFIT_FROM_INPUT_ATTACHMENT\nfragColor = color;\n#else\nfragColor = color;\n#endif\n}", } ], [ { - "vert": "#extension GL_EXT_shader_explicit_arithmetic_types_int32: require\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\nrgba = rgba * 255.0;\nhighp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\nhighp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\nhighp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\nreturn Sign * exp2(Exponent - 23.0) * Mantissa;\n}\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nlayout(location = 0) in vec3 a_position;\nlayout(location = 1) in vec3 a_normal;\nlayout(location = 2) in vec2 a_texCoord;\nlayout(location = 3) in vec4 a_tangent;\n#if CC_USE_SKINNING\nlayout(location = 4) in u32vec4 a_joints;\nlayout(location = 5) in vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nlayout(location = 6) in highp vec4 a_jointAnimInfo;\n#endif\nlayout(location = 7) in vec4 a_matWorld0;\nlayout(location = 8) in vec4 a_matWorld1;\nlayout(location = 9) in vec4 a_matWorld2;\n#if USE_LIGHTMAP\nlayout(location = 10) in vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nlayout(location = 11) in vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nlayout(location = 12) in float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nint getVertexId() {\nreturn gl_VertexIndex;\n}\n#endif\n#if CC_USE_MORPH\nlayout(set = 2, binding = 4) uniform CCMorph {\nvec4 cc_displacementWeights[15];\nvec4 cc_displacementTextureInfo;\n};\nvec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\nfloat pixelIndexF = float(pixelIndex);\nfloat x = mod(pixelIndexF, textureResolution.x);\nfloat y = floor(pixelIndexF / textureResolution.x);\nreturn vec2(x, y);\n}\nvec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\nreturn (vec2(location.x, location.y) + .5) / textureResolution;\n}\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int pixelIndex) {\nivec2 texSize = textureSize(tex, 0);\nreturn texelFetch(tex, ivec2(pixelIndex % texSize.x, pixelIndex / texSize.x), 0);\n}\n#else\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex * 4;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\nreturn vec4(\ndecode32(texture(tex, x)),\ndecode32(texture(tex, y)),\ndecode32(texture(tex, z)),\n1.0\n);\n}\n#endif\nfloat getDisplacementWeight(int index) {\nint quot = index / 4;\nint remainder = index - quot * 4;\nif (remainder == 0) {\nreturn cc_displacementWeights[quot].x;\n} else if (remainder == 1) {\nreturn cc_displacementWeights[quot].y;\n} else if (remainder == 2) {\nreturn cc_displacementWeights[quot].z;\n} else {\nreturn cc_displacementWeights[quot].w;\n}\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\nreturn fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n#else\nvec3 result = vec3(0, 0, 0);\nint nVertices = int(cc_displacementTextureInfo.z);\nfor (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\nresult += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n}\nreturn result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\nlayout(set = 2, binding = 7) uniform sampler2D cc_PositionDisplacements;\nvec3 getPositionDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nlayout(set = 2, binding = 8) uniform sampler2D cc_NormalDisplacements;\nvec3 getNormalDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\nlayout(set = 2, binding = 9) uniform sampler2D cc_TangentDisplacements;\nvec3 getTangentDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n}\n#endif\nvoid applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nint vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nnormal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\ntangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\n#if CC_USE_BAKED_ANIMATION\nlayout(set = 2, binding = 3) uniform CCSkinningTexture {\nhighp vec4 cc_jointTextureInfo;\n};\nlayout(set = 2, binding = 2) uniform CCSkinningAnimation {\nhighp vec4 cc_jointAnimInfo;\n};\nlayout(set = 2, binding = 6) uniform highp sampler2D cc_jointTexture;\nvoid CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n{\n#if USE_INSTANCING\nhighp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n#else\nhighp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n#endif\ninvSize = cc_jointTextureInfo.w;\nhighp float tempY = floor(temp * invSize);\nx = floor(temp - tempY * cc_jointTextureInfo.x);\ny = (tempY + 0.5) * invSize;\n}\n#else\nlayout(set = 2, binding = 3) uniform CCSkinning {\nhighp vec4 cc_joints[30 * 3];\n};\n#endif\n#if CC_USE_BAKED_ANIMATION\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(3.0, i, x, y, invSize);\nvec4 v1 = texture(cc_jointTexture, vec2((x + 0.5) * invSize, y));\nvec4 v2 = texture(cc_jointTexture, vec2((x + 1.5) * invSize, y));\nvec4 v3 = texture(cc_jointTexture, vec2((x + 2.5) * invSize, y));\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#else\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(12.0, i, x, y, invSize);\nvec4 v1 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n);\nvec4 v2 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n);\nvec4 v3 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n);\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\n#else\nmat4 getJointMatrix (float i) {\nint idx = int(i);\nvec4 v1 = cc_joints[idx * 3];\nvec4 v2 = cc_joints[idx * 3 + 1];\nvec4 v3 = cc_joints[idx * 3 + 2];\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\nmat4 skinMatrix () {\nvec4 joints = vec4(a_joints);\nreturn getJointMatrix(joints.x) * a_weights.x\n+ getJointMatrix(joints.y) * a_weights.y\n+ getJointMatrix(joints.z) * a_weights.z\n+ getJointMatrix(joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\nmat4 m = skinMatrix();\nposition = m * position;\n}\nvoid CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nmat4 m = skinMatrix();\nposition = m * position;\nnormal = (m * vec4(normal, 0.0)).xyz;\ntangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n}\n#endif\nvoid CCVertInput(inout vec4 In)\n{\nIn = vec4(a_position, 1.0);\n#if CC_USE_MORPH\napplyMorph(In);\n#endif\n#if CC_USE_SKINNING\nCCSkin(In);\n#endif\n}\nlayout(set = 0, binding = 0) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(set = 0, binding = 1) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\n#if !USE_INSTANCING\n#if USE_BATCHING\nlayout(set = 2, binding = 0) uniform CCLocalBatched {\nhighp mat4 cc_matWorlds[10];\n};\n#else\nlayout(set = 2, binding = 0) uniform CCLocal {\nhighp mat4 cc_matWorld;\nhighp mat4 cc_matWorldIT;\nhighp vec4 cc_lightingMapUVParam;\nhighp vec4 cc_localShadowBias;\n};\n#endif\n#endif\nvoid CCGetWorldMatrix(out mat4 matWorld)\n{\n#if USE_INSTANCING\nmatWorld = mat4(\nvec4(a_matWorld0.xyz, 0.0),\nvec4(a_matWorld1.xyz, 0.0),\nvec4(a_matWorld2.xyz, 0.0),\nvec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)\n);\n#elif USE_BATCHING\nmatWorld = cc_matWorlds[int(a_dyn_batch_id)];\n#else\nmatWorld = cc_matWorld;\n#endif\n}\nlayout(set = 0, binding = 2) uniform CCShadow {\nhighp mat4 cc_matLightPlaneProj;\nhighp mat4 cc_matLightView;\nhighp mat4 cc_matLightViewProj;\nhighp vec4 cc_shadowInvProjDepthInfo;\nhighp vec4 cc_shadowProjDepthInfo;\nhighp vec4 cc_shadowProjInfo;\nmediump vec4 cc_shadowNFLSInfo;\nmediump vec4 cc_shadowWHPBInfo;\nmediump vec4 cc_shadowLPNNInfo;\nlowp vec4 cc_shadowColor;\nmediump vec4 cc_planarNDInfo;\n};\nlayout(location = 0) out float v_dist;\nvec4 vert () {\nvec4 position;\nCCVertInput(position);\nmat4 matWorld;\nCCGetWorldMatrix(matWorld);\nvec3 P = (matWorld * position).xyz;\nvec3 L = cc_mainLitDir.xyz;\nvec3 N = cc_planarNDInfo.xyz;\nfloat d = cc_planarNDInfo.w + 0.001;\nfloat dist = (-d - dot(P, N)) / (dot(L, N) + 0.0001);\nvec3 shadowPos = P + L * dist;\nvec3 view = normalize(cc_cameraPos.xyz - shadowPos);\nfloat viewLength = length(cc_cameraPos.xyz - shadowPos);\nshadowPos += view * min(1.0, 0.005 * viewLength);\nposition = cc_matProj * cc_matView * vec4(shadowPos, 1.0);\nv_dist = dist;\nreturn position;\n}\nvoid main() { gl_Position = vert(); }", + "vert": "#extension GL_EXT_shader_explicit_arithmetic_types_int32: require\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\nrgba = rgba * 255.0;\nhighp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\nhighp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\nhighp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\nreturn Sign * exp2(Exponent - 23.0) * Mantissa;\n}\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nlayout(location = 0) in vec3 a_position;\nlayout(location = 1) in vec3 a_normal;\nlayout(location = 2) in vec2 a_texCoord;\nlayout(location = 3) in vec4 a_tangent;\n#if CC_USE_SKINNING\nlayout(location = 4) in u32vec4 a_joints;\nlayout(location = 5) in vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nlayout(location = 6) in highp vec4 a_jointAnimInfo;\n#endif\nlayout(location = 7) in vec4 a_matWorld0;\nlayout(location = 8) in vec4 a_matWorld1;\nlayout(location = 9) in vec4 a_matWorld2;\n#if CC_USE_LIGHTMAP\nlayout(location = 10) in vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nlayout(location = 11) in vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nlayout(location = 12) in float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nint getVertexId() {\nreturn gl_VertexIndex;\n}\n#endif\n#if CC_USE_MORPH\nlayout(set = 2, binding = 4) uniform CCMorph {\nvec4 cc_displacementWeights[15];\nvec4 cc_displacementTextureInfo;\n};\nvec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\nfloat pixelIndexF = float(pixelIndex);\nfloat x = mod(pixelIndexF, textureResolution.x);\nfloat y = floor(pixelIndexF / textureResolution.x);\nreturn vec2(x, y);\n}\nvec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\nreturn (vec2(location.x, location.y) + .5) / textureResolution;\n}\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int pixelIndex) {\nivec2 texSize = textureSize(tex, 0);\nreturn texelFetch(tex, ivec2(pixelIndex % texSize.x, pixelIndex / texSize.x), 0);\n}\n#else\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex * 4;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\nreturn vec4(\ndecode32(texture(tex, x)),\ndecode32(texture(tex, y)),\ndecode32(texture(tex, z)),\n1.0\n);\n}\n#endif\nfloat getDisplacementWeight(int index) {\nint quot = index / 4;\nint remainder = index - quot * 4;\nif (remainder == 0) {\nreturn cc_displacementWeights[quot].x;\n} else if (remainder == 1) {\nreturn cc_displacementWeights[quot].y;\n} else if (remainder == 2) {\nreturn cc_displacementWeights[quot].z;\n} else {\nreturn cc_displacementWeights[quot].w;\n}\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\nreturn fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n#else\nvec3 result = vec3(0, 0, 0);\nint nVertices = int(cc_displacementTextureInfo.z);\nfor (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\nresult += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n}\nreturn result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\nlayout(set = 2, binding = 7) uniform sampler2D cc_PositionDisplacements;\nvec3 getPositionDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nlayout(set = 2, binding = 8) uniform sampler2D cc_NormalDisplacements;\nvec3 getNormalDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\nlayout(set = 2, binding = 9) uniform sampler2D cc_TangentDisplacements;\nvec3 getTangentDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n}\n#endif\nvoid applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nint vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nnormal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\ntangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\n#if CC_USE_BAKED_ANIMATION\nlayout(set = 2, binding = 3) uniform CCSkinningTexture {\nhighp vec4 cc_jointTextureInfo;\n};\nlayout(set = 2, binding = 2) uniform CCSkinningAnimation {\nhighp vec4 cc_jointAnimInfo;\n};\nlayout(set = 2, binding = 6) uniform highp sampler2D cc_jointTexture;\nvoid CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n{\n#if USE_INSTANCING\nhighp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n#else\nhighp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n#endif\ninvSize = cc_jointTextureInfo.w;\nhighp float tempY = floor(temp * invSize);\nx = floor(temp - tempY * cc_jointTextureInfo.x);\ny = (tempY + 0.5) * invSize;\n}\n#else\nlayout(set = 2, binding = 3) uniform CCSkinning {\nhighp vec4 cc_joints[30 * 3];\n};\n#endif\n#if CC_USE_BAKED_ANIMATION\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(3.0, i, x, y, invSize);\nvec4 v1 = texture(cc_jointTexture, vec2((x + 0.5) * invSize, y));\nvec4 v2 = texture(cc_jointTexture, vec2((x + 1.5) * invSize, y));\nvec4 v3 = texture(cc_jointTexture, vec2((x + 2.5) * invSize, y));\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#else\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(12.0, i, x, y, invSize);\nvec4 v1 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n);\nvec4 v2 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n);\nvec4 v3 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n);\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\n#else\nmat4 getJointMatrix (float i) {\nint idx = int(i);\nvec4 v1 = cc_joints[idx * 3];\nvec4 v2 = cc_joints[idx * 3 + 1];\nvec4 v3 = cc_joints[idx * 3 + 2];\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\nmat4 skinMatrix () {\nvec4 joints = vec4(a_joints);\nreturn getJointMatrix(joints.x) * a_weights.x\n+ getJointMatrix(joints.y) * a_weights.y\n+ getJointMatrix(joints.z) * a_weights.z\n+ getJointMatrix(joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\nmat4 m = skinMatrix();\nposition = m * position;\n}\nvoid CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nmat4 m = skinMatrix();\nposition = m * position;\nnormal = (m * vec4(normal, 0.0)).xyz;\ntangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n}\n#endif\nvoid CCVertInput(inout vec4 In)\n{\nIn = vec4(a_position, 1.0);\n#if CC_USE_MORPH\napplyMorph(In);\n#endif\n#if CC_USE_SKINNING\nCCSkin(In);\n#endif\n}\nlayout(set = 0, binding = 0) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(set = 0, binding = 1) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\n#if !USE_INSTANCING\n#if USE_BATCHING\nlayout(set = 2, binding = 0) uniform CCLocalBatched {\nhighp mat4 cc_matWorlds[10];\n};\n#else\nlayout(set = 2, binding = 0) uniform CCLocal {\nhighp mat4 cc_matWorld;\nhighp mat4 cc_matWorldIT;\nhighp vec4 cc_lightingMapUVParam;\nhighp vec4 cc_localShadowBias;\n};\n#endif\n#endif\nvoid CCGetWorldMatrix(out mat4 matWorld)\n{\n#if USE_INSTANCING\nmatWorld = mat4(\nvec4(a_matWorld0.xyz, 0.0),\nvec4(a_matWorld1.xyz, 0.0),\nvec4(a_matWorld2.xyz, 0.0),\nvec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)\n);\n#elif USE_BATCHING\nmatWorld = cc_matWorlds[int(a_dyn_batch_id)];\n#else\nmatWorld = cc_matWorld;\n#endif\n}\nlayout(set = 0, binding = 2) uniform CCShadow {\nhighp mat4 cc_matLightPlaneProj;\nhighp mat4 cc_matLightView;\nhighp mat4 cc_matLightViewProj;\nhighp vec4 cc_shadowInvProjDepthInfo;\nhighp vec4 cc_shadowProjDepthInfo;\nhighp vec4 cc_shadowProjInfo;\nmediump vec4 cc_shadowNFLSInfo;\nmediump vec4 cc_shadowWHPBInfo;\nmediump vec4 cc_shadowLPNNInfo;\nlowp vec4 cc_shadowColor;\nmediump vec4 cc_planarNDInfo;\n};\nlayout(location = 0) out float v_dist;\nvec4 vert () {\nvec4 position;\nCCVertInput(position);\nmat4 matWorld;\nCCGetWorldMatrix(matWorld);\nvec3 P = (matWorld * position).xyz;\nvec3 L = cc_mainLitDir.xyz;\nvec3 N = cc_planarNDInfo.xyz;\nfloat d = cc_planarNDInfo.w + 0.001;\nfloat dist = (-d - dot(P, N)) / (dot(L, N) + 0.0001);\nvec3 shadowPos = P + L * dist;\nvec3 view = normalize(cc_cameraPos.xyz - shadowPos);\nfloat viewLength = length(cc_cameraPos.xyz - shadowPos);\nshadowPos += view * min(1.0, 0.005 * viewLength);\nposition = cc_matProj * cc_matView * vec4(shadowPos, 1.0);\nv_dist = dist;\nreturn position;\n}\nvoid main() { gl_Position = vert(); }", "frag": "\nprecision mediump float;\nlayout(set = 0, binding = 2) uniform CCShadow {\nhighp mat4 cc_matLightPlaneProj;\nhighp mat4 cc_matLightView;\nhighp mat4 cc_matLightViewProj;\nhighp vec4 cc_shadowInvProjDepthInfo;\nhighp vec4 cc_shadowProjDepthInfo;\nhighp vec4 cc_shadowProjInfo;\nmediump vec4 cc_shadowNFLSInfo;\nmediump vec4 cc_shadowWHPBInfo;\nmediump vec4 cc_shadowLPNNInfo;\nlowp vec4 cc_shadowColor;\nmediump vec4 cc_planarNDInfo;\n};\nlayout(set = 0, binding = 0) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(set = 0, binding = 1) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\nvec4 CCFragOutput (vec4 color) {\nreturn color;\n}\nlayout(location = 0) in float v_dist;\nvec4 frag () {\nif(v_dist < 0.0)\ndiscard;\nreturn CCFragOutput(cc_shadowColor);\n}\nlayout(location = 0) out vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }", } ], [ { - "vert": "#extension GL_EXT_shader_explicit_arithmetic_types_int32: require\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\nrgba = rgba * 255.0;\nhighp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\nhighp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\nhighp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\nreturn Sign * exp2(Exponent - 23.0) * Mantissa;\n}\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nlayout(location = 0) in vec3 a_position;\nlayout(location = 1) in vec3 a_normal;\nlayout(location = 2) in vec2 a_texCoord;\nlayout(location = 3) in vec4 a_tangent;\n#if CC_USE_SKINNING\nlayout(location = 4) in u32vec4 a_joints;\nlayout(location = 5) in vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nlayout(location = 6) in highp vec4 a_jointAnimInfo;\n#endif\nlayout(location = 7) in vec4 a_matWorld0;\nlayout(location = 8) in vec4 a_matWorld1;\nlayout(location = 9) in vec4 a_matWorld2;\n#if USE_LIGHTMAP\nlayout(location = 10) in vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nlayout(location = 11) in vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nlayout(location = 12) in float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nint getVertexId() {\nreturn gl_VertexIndex;\n}\n#endif\n#if CC_USE_MORPH\nlayout(set = 2, binding = 4) uniform CCMorph {\nvec4 cc_displacementWeights[15];\nvec4 cc_displacementTextureInfo;\n};\nvec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\nfloat pixelIndexF = float(pixelIndex);\nfloat x = mod(pixelIndexF, textureResolution.x);\nfloat y = floor(pixelIndexF / textureResolution.x);\nreturn vec2(x, y);\n}\nvec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\nreturn (vec2(location.x, location.y) + .5) / textureResolution;\n}\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int pixelIndex) {\nivec2 texSize = textureSize(tex, 0);\nreturn texelFetch(tex, ivec2(pixelIndex % texSize.x, pixelIndex / texSize.x), 0);\n}\n#else\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex * 4;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\nreturn vec4(\ndecode32(texture(tex, x)),\ndecode32(texture(tex, y)),\ndecode32(texture(tex, z)),\n1.0\n);\n}\n#endif\nfloat getDisplacementWeight(int index) {\nint quot = index / 4;\nint remainder = index - quot * 4;\nif (remainder == 0) {\nreturn cc_displacementWeights[quot].x;\n} else if (remainder == 1) {\nreturn cc_displacementWeights[quot].y;\n} else if (remainder == 2) {\nreturn cc_displacementWeights[quot].z;\n} else {\nreturn cc_displacementWeights[quot].w;\n}\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\nreturn fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n#else\nvec3 result = vec3(0, 0, 0);\nint nVertices = int(cc_displacementTextureInfo.z);\nfor (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\nresult += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n}\nreturn result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\nlayout(set = 2, binding = 7) uniform sampler2D cc_PositionDisplacements;\nvec3 getPositionDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nlayout(set = 2, binding = 8) uniform sampler2D cc_NormalDisplacements;\nvec3 getNormalDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\nlayout(set = 2, binding = 9) uniform sampler2D cc_TangentDisplacements;\nvec3 getTangentDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n}\n#endif\nvoid applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nint vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nnormal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\ntangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\n#if CC_USE_BAKED_ANIMATION\nlayout(set = 2, binding = 3) uniform CCSkinningTexture {\nhighp vec4 cc_jointTextureInfo;\n};\nlayout(set = 2, binding = 2) uniform CCSkinningAnimation {\nhighp vec4 cc_jointAnimInfo;\n};\nlayout(set = 2, binding = 6) uniform highp sampler2D cc_jointTexture;\nvoid CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n{\n#if USE_INSTANCING\nhighp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n#else\nhighp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n#endif\ninvSize = cc_jointTextureInfo.w;\nhighp float tempY = floor(temp * invSize);\nx = floor(temp - tempY * cc_jointTextureInfo.x);\ny = (tempY + 0.5) * invSize;\n}\n#else\nlayout(set = 2, binding = 3) uniform CCSkinning {\nhighp vec4 cc_joints[30 * 3];\n};\n#endif\n#if CC_USE_BAKED_ANIMATION\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(3.0, i, x, y, invSize);\nvec4 v1 = texture(cc_jointTexture, vec2((x + 0.5) * invSize, y));\nvec4 v2 = texture(cc_jointTexture, vec2((x + 1.5) * invSize, y));\nvec4 v3 = texture(cc_jointTexture, vec2((x + 2.5) * invSize, y));\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#else\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(12.0, i, x, y, invSize);\nvec4 v1 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n);\nvec4 v2 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n);\nvec4 v3 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n);\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\n#else\nmat4 getJointMatrix (float i) {\nint idx = int(i);\nvec4 v1 = cc_joints[idx * 3];\nvec4 v2 = cc_joints[idx * 3 + 1];\nvec4 v3 = cc_joints[idx * 3 + 2];\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\nmat4 skinMatrix () {\nvec4 joints = vec4(a_joints);\nreturn getJointMatrix(joints.x) * a_weights.x\n+ getJointMatrix(joints.y) * a_weights.y\n+ getJointMatrix(joints.z) * a_weights.z\n+ getJointMatrix(joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\nmat4 m = skinMatrix();\nposition = m * position;\n}\nvoid CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nmat4 m = skinMatrix();\nposition = m * position;\nnormal = (m * vec4(normal, 0.0)).xyz;\ntangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n}\n#endif\nvoid CCVertInput(inout StandardVertInput In)\n{\nIn.position = vec4(a_position, 1.0);\nIn.normal = a_normal;\nIn.tangent = a_tangent;\n#if CC_USE_MORPH\napplyMorph(In.position, In.normal, In.tangent);\n#endif\n#if CC_USE_SKINNING\nCCSkin(In.position, In.normal, In.tangent);\n#endif\n}\nlayout(set = 0, binding = 0) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(set = 0, binding = 1) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\nlayout(location = 0) out vec2 v_uv;\nvoid main () {\nStandardVertInput In;\nCCVertInput(In);\nIn.position.xy = cc_cameraPos.w == 0.0 ? vec2(In.position.xy.x, -In.position.xy.y) : In.position.xy;\ngl_Position = In.position;\ngl_Position.y = gl_Position.y;\nv_uv = a_texCoord;\n}", + "vert": "#extension GL_EXT_shader_explicit_arithmetic_types_int32: require\nprecision highp float;\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nhighp float decode32 (highp vec4 rgba) {\nrgba = rgba * 255.0;\nhighp float Sign = 1.0 - (step(128.0, (rgba[3]) + 0.5)) * 2.0;\nhighp float Exponent = 2.0 * (mod(float(int((rgba[3]) + 0.5)), 128.0)) + (step(128.0, (rgba[2]) + 0.5)) - 127.0;\nhighp float Mantissa = (mod(float(int((rgba[2]) + 0.5)), 128.0)) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\nreturn Sign * exp2(Exponent - 23.0) * Mantissa;\n}\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nlayout(location = 0) in vec3 a_position;\nlayout(location = 1) in vec3 a_normal;\nlayout(location = 2) in vec2 a_texCoord;\nlayout(location = 3) in vec4 a_tangent;\n#if CC_USE_SKINNING\nlayout(location = 4) in u32vec4 a_joints;\nlayout(location = 5) in vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nlayout(location = 6) in highp vec4 a_jointAnimInfo;\n#endif\nlayout(location = 7) in vec4 a_matWorld0;\nlayout(location = 8) in vec4 a_matWorld1;\nlayout(location = 9) in vec4 a_matWorld2;\n#if CC_USE_LIGHTMAP\nlayout(location = 10) in vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nlayout(location = 11) in vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nlayout(location = 12) in float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\nint getVertexId() {\nreturn gl_VertexIndex;\n}\n#endif\n#if CC_USE_MORPH\nlayout(set = 2, binding = 4) uniform CCMorph {\nvec4 cc_displacementWeights[15];\nvec4 cc_displacementTextureInfo;\n};\nvec2 getPixelLocation(vec2 textureResolution, int pixelIndex) {\nfloat pixelIndexF = float(pixelIndex);\nfloat x = mod(pixelIndexF, textureResolution.x);\nfloat y = floor(pixelIndexF / textureResolution.x);\nreturn vec2(x, y);\n}\nvec2 getPixelCoordFromLocation(vec2 location, vec2 textureResolution) {\nreturn (vec2(location.x, location.y) + .5) / textureResolution;\n}\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int pixelIndex) {\nivec2 texSize = textureSize(tex, 0);\nreturn texelFetch(tex, ivec2(pixelIndex % texSize.x, pixelIndex / texSize.x), 0);\n}\n#else\nvec4 fetchVec3ArrayFromTexture(sampler2D tex, int elementIndex) {\nint pixelIndex = elementIndex * 4;\nvec2 location = getPixelLocation(cc_displacementTextureInfo.xy, pixelIndex);\nvec2 x = getPixelCoordFromLocation(location + vec2(0.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 y = getPixelCoordFromLocation(location + vec2(1.0, 0.0), cc_displacementTextureInfo.xy);\nvec2 z = getPixelCoordFromLocation(location + vec2(2.0, 0.0), cc_displacementTextureInfo.xy);\nreturn vec4(\ndecode32(texture(tex, x)),\ndecode32(texture(tex, y)),\ndecode32(texture(tex, z)),\n1.0\n);\n}\n#endif\nfloat getDisplacementWeight(int index) {\nint quot = index / 4;\nint remainder = index - quot * 4;\nif (remainder == 0) {\nreturn cc_displacementWeights[quot].x;\n} else if (remainder == 1) {\nreturn cc_displacementWeights[quot].y;\n} else if (remainder == 2) {\nreturn cc_displacementWeights[quot].z;\n} else {\nreturn cc_displacementWeights[quot].w;\n}\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\nreturn fetchVec3ArrayFromTexture(tex, vertexIndex).rgb;\n#else\nvec3 result = vec3(0, 0, 0);\nint nVertices = int(cc_displacementTextureInfo.z);\nfor (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\nresult += (fetchVec3ArrayFromTexture(tex, nVertices * iTarget + vertexIndex).rgb * getDisplacementWeight(iTarget));\n}\nreturn result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\nlayout(set = 2, binding = 7) uniform sampler2D cc_PositionDisplacements;\nvec3 getPositionDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nlayout(set = 2, binding = 8) uniform sampler2D cc_NormalDisplacements;\nvec3 getNormalDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n}\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\nlayout(set = 2, binding = 9) uniform sampler2D cc_TangentDisplacements;\nvec3 getTangentDisplacement(int vertexId) {\nreturn getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n}\n#endif\nvoid applyMorph (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nint vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\nnormal.xyz = normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\ntangent.xyz = tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\nposition.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\n#if CC_USE_BAKED_ANIMATION\nlayout(set = 2, binding = 3) uniform CCSkinningTexture {\nhighp vec4 cc_jointTextureInfo;\n};\nlayout(set = 2, binding = 2) uniform CCSkinningAnimation {\nhighp vec4 cc_jointAnimInfo;\n};\nlayout(set = 2, binding = 6) uniform highp sampler2D cc_jointTexture;\nvoid CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)\n{\n#if USE_INSTANCING\nhighp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;\n#else\nhighp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;\n#endif\ninvSize = cc_jointTextureInfo.w;\nhighp float tempY = floor(temp * invSize);\nx = floor(temp - tempY * cc_jointTextureInfo.x);\ny = (tempY + 0.5) * invSize;\n}\n#else\nlayout(set = 2, binding = 3) uniform CCSkinning {\nhighp vec4 cc_joints[30 * 3];\n};\n#endif\n#if CC_USE_BAKED_ANIMATION\n#if CC_DEVICE_SUPPORT_FLOAT_TEXTURE\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(3.0, i, x, y, invSize);\nvec4 v1 = texture(cc_jointTexture, vec2((x + 0.5) * invSize, y));\nvec4 v2 = texture(cc_jointTexture, vec2((x + 1.5) * invSize, y));\nvec4 v3 = texture(cc_jointTexture, vec2((x + 2.5) * invSize, y));\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#else\nmat4 getJointMatrix (float i) {\nhighp float x, y, invSize;\nCCGetJointTextureCoords(12.0, i, x, y, invSize);\nvec4 v1 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n);\nvec4 v2 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n);\nvec4 v3 = vec4(\ndecode32(texture(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\ndecode32(texture(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n);\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\n#else\nmat4 getJointMatrix (float i) {\nint idx = int(i);\nvec4 v1 = cc_joints[idx * 3];\nvec4 v2 = cc_joints[idx * 3 + 1];\nvec4 v3 = cc_joints[idx * 3 + 2];\nreturn mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n}\n#endif\nmat4 skinMatrix () {\nvec4 joints = vec4(a_joints);\nreturn getJointMatrix(joints.x) * a_weights.x\n+ getJointMatrix(joints.y) * a_weights.y\n+ getJointMatrix(joints.z) * a_weights.z\n+ getJointMatrix(joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\nmat4 m = skinMatrix();\nposition = m * position;\n}\nvoid CCSkin (inout vec4 position, inout vec3 normal, inout vec4 tangent) {\nmat4 m = skinMatrix();\nposition = m * position;\nnormal = (m * vec4(normal, 0.0)).xyz;\ntangent.xyz = (m * vec4(tangent.xyz, 0.0)).xyz;\n}\n#endif\nvoid CCVertInput(inout StandardVertInput In)\n{\nIn.position = vec4(a_position, 1.0);\nIn.normal = a_normal;\nIn.tangent = a_tangent;\n#if CC_USE_MORPH\napplyMorph(In.position, In.normal, In.tangent);\n#endif\n#if CC_USE_SKINNING\nCCSkin(In.position, In.normal, In.tangent);\n#endif\n}\nlayout(set = 0, binding = 0) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(set = 0, binding = 1) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\nlayout(location = 0) out vec2 v_uv;\nvoid main () {\nStandardVertInput In;\nCCVertInput(In);\nIn.position.xy = cc_cameraPos.w == 0.0 ? vec2(In.position.xy.x, -In.position.xy.y) : In.position.xy;\ngl_Position = In.position;\ngl_Position.y = gl_Position.y;\nv_uv = a_texCoord;\n}", "frag": "\nprecision highp float;\nlayout(set = 0, binding = 0) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(set = 0, binding = 1) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\n#if ANTIALIAS_TYPE == 1\nvec4 fxaa(sampler2D tex, vec2 fragCoord, vec2 resolution,\nvec2 v_rgbNW, vec2 v_rgbNE,\nvec2 v_rgbSW, vec2 v_rgbSE,\nvec2 v_rgbM) {\nvec4 color;\nmediump vec2 inverseVP = vec2(1.0 / resolution.x, 1.0 / resolution.y);\nvec3 rgbNW = texture(tex, v_rgbNW).xyz;\nvec3 rgbNE = texture(tex, v_rgbNE).xyz;\nvec3 rgbSW = texture(tex, v_rgbSW).xyz;\nvec3 rgbSE = texture(tex, v_rgbSE).xyz;\nvec4 texColor = texture(tex, v_rgbM);\nvec3 rgbM = texColor.xyz;\nvec3 luma = vec3(0.299, 0.587, 0.114);\nfloat lumaNW = dot(rgbNW, luma);\nfloat lumaNE = dot(rgbNE, luma);\nfloat lumaSW = dot(rgbSW, luma);\nfloat lumaSE = dot(rgbSE, luma);\nfloat lumaM = dot(rgbM, luma);\nfloat lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));\nfloat lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));\nmediump vec2 dir;\ndir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));\ndir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));\nfloat dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) *\n(0.25 * (1.0 / 8.0)), (1.0/ 128.0));\nfloat rcpDirMin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce);\ndir = min(vec2(8.0, 8.0),\nmax(vec2(-8.0, -8.0),\ndir * rcpDirMin)) * inverseVP;\nvec3 rgbA = 0.5 * (\ntexture(tex, fragCoord * inverseVP + dir * (1.0 / 3.0 - 0.5)).xyz +\ntexture(tex, fragCoord * inverseVP + dir * (2.0 / 3.0 - 0.5)).xyz);\nvec3 rgbB = rgbA * 0.5 + 0.25 * (\ntexture(tex, fragCoord * inverseVP + dir * -0.5).xyz +\ntexture(tex, fragCoord * inverseVP + dir * 0.5).xyz);\nfloat lumaB = dot(rgbB, luma);\nif ((lumaB < lumaMin) || (lumaB > lumaMax))\ncolor = vec4(rgbA, texColor.a);\nelse\ncolor = vec4(rgbB, texColor.a);\nreturn color;\n}\n#endif\nlayout(location = 0) in vec2 v_uv;\nlayout(set = 1, binding = 0) uniform sampler2D outputResultMap;\nlayout(location = 0) out vec4 fragColor;\nvoid texcoords(vec2 fragCoord, vec2 resolution,\nout vec2 v_rgbNW, out vec2 v_rgbNE,\nout vec2 v_rgbSW, out vec2 v_rgbSE,\nout vec2 v_rgbM) {\nvec2 inverseVP = 1.0 / resolution.xy;\nv_rgbNW = (fragCoord + vec2(-1.0, -1.0)) * inverseVP;\nv_rgbNE = (fragCoord + vec2(1.0, -1.0)) * inverseVP;\nv_rgbSW = (fragCoord + vec2(-1.0, 1.0)) * inverseVP;\nv_rgbSE = (fragCoord + vec2(1.0, 1.0)) * inverseVP;\nv_rgbM = vec2(fragCoord * inverseVP);\n}\nvoid main () {\nmediump vec2 v_rgbNW;\nmediump vec2 v_rgbNE;\nmediump vec2 v_rgbSW;\nmediump vec2 v_rgbSE;\nmediump vec2 v_rgbM;\n#if ANTIALIAS_TYPE == 1\nvec2 resolution = cc_screenSize.xy;\nvec2 fragCoord = v_uv * resolution;\ntexcoords(fragCoord, resolution, v_rgbNW, v_rgbNE, v_rgbSW, v_rgbSE, v_rgbM);\nfragColor = fxaa(outputResultMap, fragCoord, resolution, v_rgbNW, v_rgbNE, v_rgbSW, v_rgbSE, v_rgbM);\n#else\nfragColor = texture(outputResultMap, v_uv);\n#endif\n}", } ], [ { - "vert": "\nprecision highp float;\nlayout(set = 0, binding = 0) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(set = 0, binding = 1) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nlayout(location = 0) in vec3 a_position;\nlayout(location = 1) in vec3 a_normal;\nlayout(location = 2) in vec2 a_texCoord;\nlayout(location = 3) in vec4 a_tangent;\n#if CC_USE_SKINNING\nlayout(location = 4) in u32vec4 a_joints;\nlayout(location = 5) in vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nlayout(location = 6) in highp vec4 a_jointAnimInfo;\n#endif\nlayout(location = 7) in vec4 a_matWorld0;\nlayout(location = 8) in vec4 a_matWorld1;\nlayout(location = 9) in vec4 a_matWorld2;\n#if USE_LIGHTMAP\nlayout(location = 10) in vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nlayout(location = 11) in vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nlayout(location = 12) in float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\n#endif\nlayout(location = 0) out mediump vec4 viewDir;\nvec4 vert () {\nviewDir = vec4(a_position, 1.0);\nmat4 matViewRotOnly = mat4(mat3(cc_matView));\nvec4 pos = matViewRotOnly * viewDir;\nif (cc_matProj[3].w > 0.0) {\nmat4 matProj = cc_matProj;\nmatProj[0].x = 5.2;\nmatProj[1].y = 2.6;\nmatProj[2].zw = vec2(-1.0);\nmatProj[3].zw = vec2(0.0);\npos = matProj * pos;\n} else {\npos = cc_matProj * pos;\n}\npos.z = 0.99999 * pos.w;\nreturn pos;\n}\nvoid main() { gl_Position = vert(); }", + "vert": "\nprecision highp float;\nlayout(set = 0, binding = 0) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(set = 0, binding = 1) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\n#define QUATER_PI 0.78539816340\n#define HALF_PI 1.57079632679\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI4 12.5663706144\n#define INV_QUATER_PI 1.27323954474\n#define INV_HALF_PI 0.63661977237\n#define INV_PI 0.31830988618\n#define INV_PI2 0.15915494309\n#define INV_PI4 0.07957747155\n#define EPSILON 1e-6\n#define EPSILON_LOWP 1e-4\n#define LOG2 1.442695\n#define EXP_VALUE 2.71828183f\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\n#define GRAY_VECTOR vec3(0.299, 0.587, 0.114)\nstruct StandardVertInput {\nhighp vec4 position;\nvec3 normal;\nvec4 tangent;\n};\nlayout(location = 0) in vec3 a_position;\nlayout(location = 1) in vec3 a_normal;\nlayout(location = 2) in vec2 a_texCoord;\nlayout(location = 3) in vec4 a_tangent;\n#if CC_USE_SKINNING\nlayout(location = 4) in u32vec4 a_joints;\nlayout(location = 5) in vec4 a_weights;\n#endif\n#if USE_INSTANCING\n#if CC_USE_BAKED_ANIMATION\nlayout(location = 6) in highp vec4 a_jointAnimInfo;\n#endif\nlayout(location = 7) in vec4 a_matWorld0;\nlayout(location = 8) in vec4 a_matWorld1;\nlayout(location = 9) in vec4 a_matWorld2;\n#if CC_USE_LIGHTMAP\nlayout(location = 10) in vec4 a_lightingMapUVParam;\n#endif\n#if CC_RECEIVE_SHADOW\nlayout(location = 11) in vec2 a_localShadowBias;\n#endif\n#elif USE_BATCHING\nlayout(location = 12) in float a_dyn_batch_id;\n#endif\n#if CC_USE_MORPH\n#endif\nlayout(location = 0) out mediump vec4 viewDir;\nvec4 vert () {\nviewDir = vec4(a_position, 1.0);\nmat4 matViewRotOnly = mat4(mat3(cc_matView));\nvec4 pos = matViewRotOnly * viewDir;\nif (cc_matProj[3].w > 0.0) {\nmat4 matProj = cc_matProj;\nmatProj[0].x = 5.2;\nmatProj[1].y = 2.6;\nmatProj[2].zw = vec2(-1.0);\nmatProj[3].zw = vec2(0.0);\npos = matProj * pos;\n} else {\npos = cc_matProj * pos;\n}\npos.z = 0.99999 * pos.w;\nreturn pos;\n}\nvoid main() { gl_Position = vert(); }", "frag": "\nprecision mediump float;\nlayout(set = 0, binding = 0) uniform CCGlobal {\nhighp vec4 cc_time;\nmediump vec4 cc_screenSize;\nmediump vec4 cc_nativeSize;\n};\nlayout(set = 0, binding = 1) uniform CCCamera {\nhighp mat4 cc_matView;\nhighp mat4 cc_matViewInv;\nhighp mat4 cc_matProj;\nhighp mat4 cc_matProjInv;\nhighp mat4 cc_matViewProj;\nhighp mat4 cc_matViewProjInv;\nhighp vec4 cc_cameraPos;\nmediump vec4 cc_surfaceTransform;\nmediump vec4 cc_screenScale;\nmediump vec4 cc_exposure;\nmediump vec4 cc_mainLitDir;\nmediump vec4 cc_mainLitColor;\nmediump vec4 cc_ambientSky;\nmediump vec4 cc_ambientGround;\nmediump vec4 cc_fogColor;\nmediump vec4 cc_fogBase;\nmediump vec4 cc_fogAdd;\nmediump vec4 cc_nearFar;\nmediump vec4 cc_viewPort;\n};\nlayout(set = 0, binding = 4) uniform samplerCube cc_environment;\nvec3 unpackRGBE (vec4 rgbe) {\nreturn rgbe.rgb * pow(1.1, rgbe.a * 255.0 - 128.0);\n}\nvec3 SRGBToLinear (vec3 gamma) {\nreturn gamma * gamma;\n}\nvec3 ACESToneMap (vec3 color) {\ncolor = min(color, vec3(8.0));\nconst float A = 2.51;\nconst float B = 0.03;\nconst float C = 2.43;\nconst float D = 0.59;\nconst float E = 0.14;\nreturn (color * (A * color + B)) / (color * (C * color + D) + E);\n}\nvec4 CCFragOutput (vec4 color) {\n#if CC_USE_HDR\ncolor.rgb = ACESToneMap(color.rgb);\n#endif\ncolor.rgb = sqrt(color.rgb);\nreturn color;\n}\nlayout(location = 0) in mediump vec4 viewDir;\nvec4 frag () {\n#if USE_RGBE_CUBEMAP\nvec3 c = unpackRGBE(texture(cc_environment, viewDir.xyz));\n#else\nvec3 c = SRGBToLinear(texture(cc_environment, viewDir.xyz).rgb);\n#endif\nreturn CCFragOutput(vec4(c * cc_ambientSky.w, 1.0));\n}\nlayout(location = 0) out vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }", } ], diff --git a/cocos/core/components/camera-component.ts b/cocos/core/components/camera-component.ts index 3de45c07b0..d6b7964d61 100644 --- a/cocos/core/components/camera-component.ts +++ b/cocos/core/components/camera-component.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module component/camera - */ - import { EDITOR } from 'internal:constants'; import { ccclass, help, executeInEditMode, menu, tooltip, displayOrder, type, serializable, visible } from 'cc.decorator'; import { RenderTexture } from '../assets/render-texture'; @@ -85,12 +80,40 @@ export declare namespace Camera { @menu('Rendering/Camera') @executeInEditMode export class Camera extends Component { + /** + * @en The projection type enumeration of the camera. + * @zh 相机的投影类型枚举。 + */ public static ProjectionType = ProjectionType; + /** + * @en The axis type of the fov + * @zh FOV 的轴向枚举 + */ public static FOVAxis = FOVAxis; + /** + * @en The clear flag enumeration of the camera. + * @zh 相机的清除标志位枚举。 + */ public static ClearFlag = ClearFlag; + /** + * @en The aperture value's enumeration of the camera. + * @zh 相机的光圈值枚举。 + */ public static Aperture = Aperture; + /** + * @en The shutter value's enumeration of the camera. + * @zh 相机的快门值枚举。 + */ public static Shutter = Shutter; + /** + * @en The ISO value's enumeration of the camera. + * @zh 相机的感光度值枚举。 + */ public static ISO = ISO; + /** + * @en The event for target texture changing. + * @zh 目标贴图修改的事件。 + */ public static TARGET_TEXTURE_CHANGE = 'tex-change'; @serializable @@ -134,6 +157,10 @@ export class Camera extends Component { protected _inEditorMode = false; protected _flows: string[] | undefined = undefined; + /** + * @en The render camera representation. + * @zh 渲染场景中的相机对象。 + */ get camera () { return this._camera!; } @@ -447,6 +474,9 @@ export class Camera extends Component { if (this._camera) { this._camera.screenScale = val; } } + /** + * @internal + */ get inEditorMode () { return this._inEditorMode; } diff --git a/cocos/core/components/component-event-handler.ts b/cocos/core/components/component-event-handler.ts index f561ecf845..49a5687cfb 100644 --- a/cocos/core/components/component-event-handler.ts +++ b/cocos/core/components/component-event-handler.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module event - */ - import { ccclass, type, serializable, editable, tooltip } from 'cc.decorator'; import type { Node } from '../scene-graph'; import { legacyCC } from '../global-exports'; diff --git a/cocos/core/components/component.ts b/cocos/core/components/component.ts index 1e5f29a0c8..ad0d2c63cb 100644 --- a/cocos/core/components/component.ts +++ b/cocos/core/components/component.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module component - */ - import { ccclass, tooltip, displayName, type, serializable, disallowAnimation } from 'cc.decorator'; import { EDITOR, TEST } from 'internal:constants'; import { Script } from '../assets/scripts'; @@ -166,6 +161,7 @@ class Component extends CCObject { } public static system = null; + /** * @en The node this component is attached to. A component is always attached to a node. * @zh 该组件被附加到的节点。组件总会附加到一个节点。 @@ -185,13 +181,13 @@ class Component extends CCObject { public _enabled = true; /** - * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. + * @internal */ @serializable public __prefab: CompPrefabInfo | null = null; /** - * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. + * @internal */ public _sceneGetter: null | (() => RenderScene) = null; diff --git a/cocos/core/components/index.ts b/cocos/core/components/index.ts index c9c2590ddf..f039fda557 100644 --- a/cocos/core/components/index.ts +++ b/cocos/core/components/index.ts @@ -24,7 +24,6 @@ */ import './component-event-handler.schema'; - export { default as System } from './system'; export { default as MissingScript } from './missing-script'; export { EventHandler } from './component-event-handler'; diff --git a/cocos/core/components/missing-script.ts b/cocos/core/components/missing-script.ts index 23b4fdfd44..8398c9ee40 100644 --- a/cocos/core/components/missing-script.ts +++ b/cocos/core/components/missing-script.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module component - */ - import { ccclass, inspector, editorOnly, serializable, editable } from 'cc.decorator'; import { EDITOR } from 'internal:constants'; import { _getClassById } from '../utils/js'; diff --git a/cocos/core/components/system.ts b/cocos/core/components/system.ts index f4cdad50f7..927bc66334 100644 --- a/cocos/core/components/system.ts +++ b/cocos/core/components/system.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { ISchedulable } from '../scheduler'; import { Enum } from '../value-types/enum'; diff --git a/cocos/core/curves/bezier.ts b/cocos/core/curves/bezier.ts index 8efeb84f87..d083073272 100644 --- a/cocos/core/curves/bezier.ts +++ b/cocos/core/curves/bezier.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module animation - */ - import { legacyCC } from '../global-exports'; export type BezierControlPoints = [ number, number, number, number ]; diff --git a/cocos/core/curves/curve.ts b/cocos/core/curves/curve.ts index 920b17ea57..0791a8b3fc 100644 --- a/cocos/core/curves/curve.ts +++ b/cocos/core/curves/curve.ts @@ -296,6 +296,7 @@ export class RealCurve extends KeyframeCurve { * Defaults to `ExtrapolationMode.CLAMP`. * @zh * 获取或设置此曲线的前向外推模式。 + * 默认为 `ExtrapolationMode.CLAMP`。 */ public preExtrapolation: ExtrapolationMode = ExtrapolationMode.CLAMP; @@ -305,6 +306,7 @@ export class RealCurve extends KeyframeCurve { * Defaults to `ExtrapolationMode.CLAMP`. * @zh * 获取或设置此曲线的后向外推模式。 + * 默认为 `ExtrapolationMode.CLAMP`。 */ public postExtrapolation: ExtrapolationMode = ExtrapolationMode.CLAMP; @@ -312,7 +314,7 @@ export class RealCurve extends KeyframeCurve { * @en * Evaluates this curve at specified time. * @zh - * 求值此曲线在指定时间上的值。 + * 计算此曲线在指定时间上的值。 * @param time Input time. * @returns Result value. */ @@ -391,7 +393,10 @@ export class RealCurve extends KeyframeCurve { } /** + * @en * Adds a keyframe into this curve. + * @zh + * 添加一个关键帧到此曲线。 * @param time Time of the keyframe. * @param value Value of the keyframe. * @returns The index to the new keyframe. @@ -401,7 +406,10 @@ export class RealCurve extends KeyframeCurve { } /** + * @en * Assigns all keyframes. + * @zh + * 赋值所有关键帧。 * @param keyframes An iterable to keyframes. The keyframes should be sorted by their time. */ public assignSorted (keyframes: Iterable<[number, RealKeyframeValueParameters]>): void; @@ -433,7 +441,10 @@ export class RealCurve extends KeyframeCurve { } /** + * @en * Returns if this curve is constant. + * @zh + * 返回此曲线是否是常量曲线。 * @param tolerance The tolerance. * @returns Whether it is constant. */ @@ -445,6 +456,9 @@ export class RealCurve extends KeyframeCurve { return this._values.every((frame) => approx(frame.value, firstVal, tolerance)); } + /** + * @internal + */ public [serializeTag] (output: SerializationOutput, context: SerializationContext) { if (!context.toCCON) { output.writeThis(); @@ -492,6 +506,9 @@ export class RealCurve extends KeyframeCurve { } } + /** + * @internal + */ public [deserializeTag] (input: SerializationInput, context: DeserializationContext) { if (!context.fromCCON) { input.readThis(); diff --git a/cocos/core/curves/keyframe-curve.ts b/cocos/core/curves/keyframe-curve.ts index 64f3808a73..9ce1abf87a 100644 --- a/cocos/core/curves/keyframe-curve.ts +++ b/cocos/core/curves/keyframe-curve.ts @@ -8,32 +8,47 @@ import type { CurveBase } from './curve-base'; type KeyFrame = [number, TKeyframeValue]; /** - * Curve. + * @en + * Keyframe curve. + * @zh + * 关键帧曲线。 */ export class KeyframeCurve implements CurveBase, Iterable> { /** + * @en * Gets the count of keyframes. + * @zh + * 获取关键帧数量。 */ get keyFramesCount () { return this._times.length; } /** - * Gets the minimal time. + * @en + * Gets the minimal keyframe time on this curve. + * @zh + * 获取此曲线上最小的关键帧时间。 */ get rangeMin () { return this._times[0]; } /** - * Gets the maximum time. + * @en + * Gets the maximum keyframe time on this curve. + * @zh + * 获取此曲线上最大的关键帧时间。 */ get rangeMax () { return this._times[this._values.length - 1]; } /** + * @en * Returns an iterator to keyframe pairs. + * @zh + * 返回关键帧对的迭代器。 */ [Symbol.iterator] () { let index = 0; @@ -57,22 +72,40 @@ export class KeyframeCurve implements CurveBase, Iterable> { return this; } + /** + * @en + * Returns an iterator to keyframe times. + * @zh + * 返回关键帧时间的迭代器。 + */ public times (): Iterable { return this._times; } + /** + * @en + * Returns an iterator to keyframe values. + * @zh + * 返回关键帧值的迭代器。 + */ public values (): Iterable { return this._values; } /** + * @en * Gets the time of specified keyframe. + * @zh + * 获取指定关键帧上的时间。 * @param index Index to the keyframe. * @returns The keyframe 's time. */ @@ -81,7 +114,10 @@ export class KeyframeCurve implements CurveBase, Iterable implements CurveBase, Iterable implements CurveBase, Iterable implements CurveBase, Iterable implements CurveBase, Iterable implements CurveBase, Iterable): void; /** + * @en * Assigns all keyframes. + * @zh + * 赋值所有关键帧。 * @param times Times array. Should be sorted. * @param values Values array. Corresponding to each time in `times`. */ @@ -158,7 +212,10 @@ export class KeyframeCurve implements CurveBase, Iterable; @@ -87,29 +109,43 @@ function createQuatKeyframeValue (params: QuatKeyframeValueParameters) { } /** + * @en * Quaternion curve. + * @zh + * 四元数曲线 */ @ccclass('cc.QuatCurve') export class QuatCurve extends KeyframeCurve { /** - * Gets or sets the operation should be taken - * if input time is less than the time of first keyframe when evaluating this curve. + * @en + * Gets or sets the pre-extrapolation-mode of this curve. * Defaults to `ExtrapolationMode.CLAMP`. + * @zh + * 获取或设置此曲线的前向外推模式。 + * 默认为 `ExtrapolationMode.CLAMP`。 */ @serializable public preExtrapolation: ExtrapolationMode = ExtrapolationMode.CLAMP; /** - * Gets or sets the operation should be taken - * if input time is greater than the time of last keyframe when evaluating this curve. + * @en + * Gets or sets the post-extrapolation-mode of this curve. * Defaults to `ExtrapolationMode.CLAMP`. + * @zh + * 获取或设置此曲线的后向外推模式。 + * 默认为 `ExtrapolationMode.CLAMP`。 */ @serializable public postExtrapolation: ExtrapolationMode = ExtrapolationMode.CLAMP; /** + * @en * Evaluates this curve at specified time. + * @zh + * 计算此曲线在指定时间上的值。 * @param time Input time. + * @param quat If specified, this value will be filled and returned. + * Otherwise a new quaternion object will be filled and returned. * @returns Result value. */ public evaluate (time: number, quat?: Quat): Quat { @@ -235,6 +271,9 @@ export class QuatCurve extends KeyframeCurve { } } + /** + * @internal + */ public [serializeTag] (output: SerializationOutput, context: SerializationContext) { if (!context.toCCON) { output.writeThis(); @@ -328,6 +367,9 @@ export class QuatCurve extends KeyframeCurve { output.writeProperty('bytes', bytes); } + /** + * @internal + */ public [deserializeTag] (input: SerializationInput, context: DeserializationContext) { if (!context.fromCCON) { input.readThis(); diff --git a/cocos/core/data/class.ts b/cocos/core/data/class.ts index 9c5cbb1388..61dd08cc9e 100644 --- a/cocos/core/data/class.ts +++ b/cocos/core/data/class.ts @@ -24,8 +24,6 @@ THE SOFTWARE. */ - - import { DEV, EDITOR, SUPPORT_JIT, TEST } from 'internal:constants'; import { errorID, warnID, error } from '../platform/debug'; import * as js from '../utils/js'; @@ -440,6 +438,17 @@ CCClass.fastDefine = function (className, constructor, serializableFields) { CCClass.Attr = attributeUtils; CCClass.attr = attributeUtils.attr; +/** + * Returns if the class is a cc-class or is fast defined. + * @param constructor The constructor of the class. + * @returns Judge result. + */ +// eslint-disable-next-line @typescript-eslint/ban-types +export function isCCClassOrFastDefined (constructor: Constructor) { + // eslint-disable-next-line no-prototype-builtins, @typescript-eslint/no-unsafe-return + return constructor?.hasOwnProperty?.('__values__'); +} + /** * Return all super classes. * @param constructor The Constructor. diff --git a/cocos/core/data/custom-serializable.ts b/cocos/core/data/custom-serializable.ts index 29512d012c..8f44a1ab29 100644 --- a/cocos/core/data/custom-serializable.ts +++ b/cocos/core/data/custom-serializable.ts @@ -2,13 +2,13 @@ import { assertIsNonNullable, assertIsTrue } from './utils/asserts'; /** * Tag to define the custom serialization method. - * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. + * @internal */ export const serializeTag = Symbol('[[Serialize]]'); /** * Tag to define the custom deserialization method. - * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. + * @internal */ export const deserializeTag = Symbol('[[Deserialize]]'); diff --git a/cocos/core/data/decorators/ccclass.ts b/cocos/core/data/decorators/ccclass.ts index ff4be77b2d..0515ea6d80 100644 --- a/cocos/core/data/decorators/ccclass.ts +++ b/cocos/core/data/decorators/ccclass.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module decorator - */ - import { DEV } from 'internal:constants'; import { js } from '../../utils/js'; import { CCClass } from '../class'; diff --git a/cocos/core/data/decorators/component.ts b/cocos/core/data/decorators/component.ts index c6d796ef8d..3a07b3b90a 100644 --- a/cocos/core/data/decorators/component.ts +++ b/cocos/core/data/decorators/component.ts @@ -23,13 +23,8 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module decorator - */ - -import { CCClass } from '../class'; import { DEV } from 'internal:constants'; +import { CCClass } from '../class'; import { makeEditorClassDecoratorFn, makeSmartEditorClassDecorator, emptySmartClassDecorator } from './utils'; /** diff --git a/cocos/core/data/decorators/editable.ts b/cocos/core/data/decorators/editable.ts index e3dfce1d43..37ae87e38d 100644 --- a/cocos/core/data/decorators/editable.ts +++ b/cocos/core/data/decorators/editable.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module decorator - */ - import { DEV, EDITOR } from 'internal:constants'; import { IExposedAttributes } from '../utils/attribute-defines'; import { getOrCreatePropertyStash } from './property'; diff --git a/cocos/core/data/decorators/index.ts b/cocos/core/data/decorators/index.ts index 7fd0fcff25..0c2f2a065d 100644 --- a/cocos/core/data/decorators/index.ts +++ b/cocos/core/data/decorators/index.ts @@ -22,10 +22,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/** - * @packageDocumentation - * @module decorator - */ export { ccclass } from './ccclass'; export * from './component'; diff --git a/cocos/core/data/decorators/override.ts b/cocos/core/data/decorators/override.ts index 08f566e9e8..04211fc11e 100644 --- a/cocos/core/data/decorators/override.ts +++ b/cocos/core/data/decorators/override.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module decorator - */ - import { LegacyPropertyDecorator } from './utils'; import { getOrCreatePropertyStash } from './property'; diff --git a/cocos/core/data/decorators/property.ts b/cocos/core/data/decorators/property.ts index 56e3da23e9..6fb287e194 100644 --- a/cocos/core/data/decorators/property.ts +++ b/cocos/core/data/decorators/property.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module decorator - */ - import { DEV, EDITOR, TEST } from 'internal:constants'; import { CCString, CCInteger, CCFloat, CCBoolean } from '../utils/attribute'; import { IExposedAttributes } from '../utils/attribute-defines'; diff --git a/cocos/core/data/decorators/serializable.ts b/cocos/core/data/decorators/serializable.ts index 084b156715..3dfa64f3ee 100644 --- a/cocos/core/data/decorators/serializable.ts +++ b/cocos/core/data/decorators/serializable.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module decorator - */ - import { EDITOR, TEST } from 'internal:constants'; import { emptyDecorator, LegacyPropertyDecorator } from './utils'; import { getOrCreatePropertyStash } from './property'; diff --git a/cocos/core/data/decorators/type.ts b/cocos/core/data/decorators/type.ts index 5fdaba9d25..1f94d1d38b 100644 --- a/cocos/core/data/decorators/type.ts +++ b/cocos/core/data/decorators/type.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module decorator - */ - import { LegacyPropertyDecorator } from './utils'; import { property } from './property'; import { CCString, CCInteger, CCFloat, CCBoolean, PrimitiveType } from '../utils/attribute'; diff --git a/cocos/core/data/decorators/utils.ts b/cocos/core/data/decorators/utils.ts index 18c8846807..d5d28785b8 100644 --- a/cocos/core/data/decorators/utils.ts +++ b/cocos/core/data/decorators/utils.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module decorator - */ - import { DEV } from 'internal:constants'; import { CCClass } from '../class'; import { error } from '../../platform/debug'; diff --git a/cocos/core/data/deserialize-dynamic.ts b/cocos/core/data/deserialize-dynamic.ts index 4fd13a88fb..2aaded4c87 100644 --- a/cocos/core/data/deserialize-dynamic.ts +++ b/cocos/core/data/deserialize-dynamic.ts @@ -573,7 +573,6 @@ class _Deserializer { if (DEBUG) { error(`Deserialize ${klass.name} failed, ${(e as { stack: string; }).stack}`); } - this._reportMissingClass(type); const obj = createObject(MissingScript); this._deserializeInto(value, obj, MissingScript); return obj; @@ -665,14 +664,10 @@ class _Deserializer { object: Record, deserialized: Record, constructor: AnyFunction) { - try { - if (!JSON.parse(JSON.stringify(deserialized._$erialized))) { - error(`Unable to load previously serialized data. ${JSON.stringify(deserialized)}`); - } - } catch (e) { - error(`Error when checking MissingScript 7, ${e}`); - } rawDeserialize(deserializer, object, deserialized, constructor); + if (!object._$erialized) { + error(`Unable to stash previously serialized data. ${JSON.stringify(deserialized)}`); + } }; } } catch (e) { diff --git a/cocos/core/data/deserialize.ts b/cocos/core/data/deserialize.ts index c2d5236720..94b11adeab 100644 --- a/cocos/core/data/deserialize.ts +++ b/cocos/core/data/deserialize.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { EDITOR, TEST, PREVIEW, BUILD, DEBUG, JSB, DEV } from 'internal:constants'; import { legacyCC } from '../global-exports'; import { ValueType } from '../value-types'; @@ -536,20 +534,32 @@ interface ICustomClass { */ export class Details { /** - * the obj list whose field needs to load asset by uuid + * @en + * the object list whose field needs to load asset by uuid + * @zh + * 对象列表,其中每个对象有属性需要通过 uuid 进行资源加载 */ uuidObjList: IFileData[File.DependObjs] | null = null; /** + * @en * the corresponding field name which referenced to the asset + * @zh + * 引用着资源的字段名称 */ uuidPropList: IFileData[File.DependKeys] | null = null; /** + * @en * list of the depends assets' uuid + * @zh + * 依赖资源的 uuid 列表 */ uuidList: IFileData[File.DependUuidIndices] | null = null; /** + * @en * list of the depends assets' type + * @zh + * 依赖的资源类型列表 */ uuidTypeList: string[] = []; diff --git a/cocos/core/data/editor-extras-tag.ts b/cocos/core/data/editor-extras-tag.ts index 574ab8cd6e..fe47315fe3 100644 --- a/cocos/core/data/editor-extras-tag.ts +++ b/cocos/core/data/editor-extras-tag.ts @@ -1,13 +1,16 @@ /** * Tag to visit editor extras of an object. Never concern about its value please. + * @internal */ export const editorExtrasTag = '__editorExtras__'; /** * Engine classes with this kind of signatures are integrated with editor extendability. + * @internal */ export interface EditorExtendableObject { /** + * @en * The editor extras on this object. * * BE CAREFUL: this property is currently governed by Cocos Creator Editor. @@ -26,6 +29,24 @@ export interface EditorExtendableObject { * ```ts * node.__editorExtras__ = {}; // Error: might be break in future. * ``` + * @zh + * 此对象的编辑器额外数据。 + * + * **注意**:此属性目前由 Cocos Creator 编辑器管理。 + * 它的定义不管是对于引擎还是用户代码都是不可见的,也 **不应该** 操作该数据。 + * + * 你应该仅使用编辑器额外数据标签来访问此数据。 + * @example + * ```ts + * import { editorExtrasTag } from 'cc'; + * node[editorExtrasTag] = {}; + * node[editorExtrasTag].someWhat; + * ``` + * 即使你知道目前 `editorExtrasTag === '__editorExtras__'`, + * 也不要通过字符串属性来访问: + * ```ts + * node.__editorExtras__ = {}; // 错误:在未来可能无法生效 + * ``` */ [editorExtrasTag]: unknown; } diff --git a/cocos/core/data/gc-object.ts b/cocos/core/data/gc-object.ts index 14dfcc39c4..1f008e5eeb 100644 --- a/cocos/core/data/gc-object.ts +++ b/cocos/core/data/gc-object.ts @@ -26,7 +26,7 @@ import { CCObject } from './object'; @ccclass('cc.GCObject') export class GCObject extends CCObject { /** - * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. + * @internal */ public declare _finalizationToken: any; diff --git a/cocos/core/data/index.ts b/cocos/core/data/index.ts index acdf8ef66b..e348ce597f 100644 --- a/cocos/core/data/index.ts +++ b/cocos/core/data/index.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module core/data - */ - import * as _decorator from './class-decorator'; import { legacyCC } from '../global-exports'; diff --git a/cocos/core/data/instantiate-jit.ts b/cocos/core/data/instantiate-jit.ts index b83921d564..f1061e0f1f 100644 --- a/cocos/core/data/instantiate-jit.ts +++ b/cocos/core/data/instantiate-jit.ts @@ -28,7 +28,7 @@ import { TEST } from 'internal:constants'; import * as js from '../utils/js'; -import { CCClass } from './class'; +import { CCClass, isCCClassOrFastDefined } from './class'; import { CCObject, isCCObject } from './object'; import * as Attr from './utils/attribute'; import { flattenCodeArray } from './utils/compiler'; @@ -423,7 +423,7 @@ class Parser { // codeArray - the source code array for this object public enumerateObject (codeArray, obj) { const klass = obj.constructor; - if (legacyCC.Class._isCCClass(klass)) { + if (isCCClassOrFastDefined(klass)) { this.enumerateCCClass(codeArray, obj, klass); } else { // primitive javascript object @@ -458,7 +458,7 @@ class Parser { let createCode; const ctor = obj.constructor; - if (legacyCC.Class._isCCClass(ctor)) { + if (isCCClassOrFastDefined(ctor)) { if (this.parent) { if (this.parent instanceof legacyCC.Component) { if (obj instanceof legacyCC._BaseNode || obj instanceof legacyCC.Component) { diff --git a/cocos/core/data/instantiate.ts b/cocos/core/data/instantiate.ts index d2593c8eb9..175289ea88 100644 --- a/cocos/core/data/instantiate.ts +++ b/cocos/core/data/instantiate.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module core/data - */ - import { DEV } from 'internal:constants'; import { isDomNode } from '../utils/misc'; import { ValueType } from '../value-types'; @@ -40,6 +35,7 @@ import { Prefab } from '../assets/prefab'; import { Node } from '../scene-graph/node'; import { JSB } from '../default-constants'; import { updateChildrenForDeserialize } from '../utils/jsb-utils'; +import { isCCClassOrFastDefined } from './class'; const Destroyed = CCObject.Flags.Destroyed; const PersistentMask = CCObject.Flags.PersistentMask; @@ -206,7 +202,7 @@ function enumerateObject (obj, clone, parent) { js.value(obj, '_iN$t', clone, true); objsToClearTmpVar.push(obj); const klass = obj.constructor; - if (legacyCC.Class._isCCClass(klass)) { + if (isCCClassOrFastDefined(klass)) { enumerateCCClass(klass, obj, clone, parent); } else { // primitive javascript object @@ -283,7 +279,7 @@ function instantiateObj (obj, parent) { } const ctor = obj.constructor; - if (legacyCC.Class._isCCClass(ctor)) { + if (isCCClassOrFastDefined(ctor)) { if (parent) { if (parent instanceof legacyCC.Component) { if (obj instanceof legacyCC._BaseNode || obj instanceof legacyCC.Component) { diff --git a/cocos/core/data/object.ts b/cocos/core/data/object.ts index ceb0ddf9d0..1839f2e033 100644 --- a/cocos/core/data/object.ts +++ b/cocos/core/data/object.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module core/data - */ - import { SUPPORT_JIT, EDITOR, TEST, JSB } from 'internal:constants'; import * as js from '../utils/js'; import { CCClass } from './class'; @@ -196,12 +191,12 @@ class CCObject implements EditorExtendableObject { } /** - * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. + * @internal */ public declare [editorExtrasTag]: unknown; /** - * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. + * @internal */ public _objFlags: number; protected _name: string; @@ -333,10 +328,18 @@ class CCObject implements EditorExtendableObject { } /** + * @en * Clear all references in the instance. * * NOTE: this method will not clear the getter or setter functions which defined in the instance of CCObject. - * You can override the _destruct method if you need, for example: + * + * @zh + * 清理实例的所有引用 + * 注意:此方法不会清理实例上的 getter 与 setter 方法。 + * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. + * @example + * ``` + * // You can override the _destruct method if you need, for example: * _destruct: function () { * for (var key in this) { * if (this.hasOwnProperty(key)) { @@ -351,8 +354,7 @@ class CCObject implements EditorExtendableObject { * } * } * } - * - * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. + * ``` */ public _destruct () { const ctor: any = this.constructor; diff --git a/cocos/core/data/serialization-metadata.ts b/cocos/core/data/serialization-metadata.ts index 9922e85a3d..8c4a5106d3 100644 --- a/cocos/core/data/serialization-metadata.ts +++ b/cocos/core/data/serialization-metadata.ts @@ -1,7 +1,7 @@ const sMetadataTag = Symbol('cc:SerializationMetadata'); /** - * For internal usage only. DO NOT USE IT IN YOUR CODES. + * @internal DO NOT USE IT IN YOUR CODES. * @param constructor * @returns */ @@ -10,13 +10,16 @@ export function getSerializationMetadata (constructor: Function): SerializationM return (constructor as MayBeInjected)[sMetadataTag]; } +/** + * @internal + */ // eslint-disable-next-line @typescript-eslint/ban-types export function getOrCreateSerializationMetadata (constructor: Function): SerializationMetadata { return (constructor as MayBeInjected)[sMetadataTag] ??= {}; } /** - * For internal usage only. DO NOT USE IT IN YOUR CODES. + * @internal For internal usage only. DO NOT USE IT IN YOUR CODES. */ export interface SerializationMetadata { uniquelyReferenced?: boolean; diff --git a/cocos/core/data/utils/attribute.ts b/cocos/core/data/utils/attribute.ts index 8fb5e85f84..47228bd868 100644 --- a/cocos/core/data/utils/attribute.ts +++ b/cocos/core/data/utils/attribute.ts @@ -111,12 +111,15 @@ export class PrimitiveType { } /** + * @en + * Indicates that the editor should treats this property or array element as a Integer value. + * @zh * 指定编辑器以整数形式对待该属性或数组元素。 - * 例如: + * @example * ```ts - * import { CCInteger, _decorator } from "Cocos3D"; + * import { CCInteger, _decorator } from "cc"; * - * // 在 cc 类定义中: + * // in class definition: * * \@_decorator.property({type: CCInteger}) * count = 0; @@ -130,12 +133,15 @@ legacyCC.Integer = CCInteger; legacyCC.CCInteger = CCInteger; /** + * @en + * Indicates that the editor should treats this property or array element as a Float value. + * @zh * 指定编辑器以浮点数形式对待该属性或数组元素。 - * 例如: + * @example * ```ts - * import { CCFloat, _decorator } from "Cocos3D"; + * import { CCFloat, _decorator } from "cc"; * - * // 在 cc 类定义中: + * // in class definition: * * \@_decorator.property({type: CCFloat}) * x = 0; @@ -156,13 +162,15 @@ if (EDITOR) { } /** + * @en + * Indicates that the editor should treats this property or array element as a Boolean value. + * @zh * 指定编辑器以布尔值形式对待该属性或数组元素。 - * 例如: + * + * @example * ```ts - * import { CCBoolean, _decorator } from "Cocos3D"; - * - * // 在 cc 类定义中: - * + * import { CCBoolean, _decorator } from "cc"; + * // in class definition * \@_decorator.property({type: CCBoolean}) * isTrue = false; * @@ -175,12 +183,15 @@ legacyCC.Boolean = CCBoolean; legacyCC.CCBoolean = CCBoolean; /** + * @en + * Indicates that the editor should treats this property or array element as a String value. + * @zh * 指定编辑器以字符串形式对待该属性或数组元素。 - * 例如: + * @example * ```ts - * import { CCString, _decorator } from "Cocos3D"; + * import { CCString, _decorator } from "cc"; * - * // 在 cc 类定义中: + * // in class definition * * \@_decorator.property({type: CCString}) * name = ''; diff --git a/cocos/core/data/utils/compact-value-type-array.ts b/cocos/core/data/utils/compact-value-type-array.ts index a164f2fd6b..4594ffc456 100644 --- a/cocos/core/data/utils/compact-value-type-array.ts +++ b/cocos/core/data/utils/compact-value-type-array.ts @@ -56,6 +56,9 @@ export function extractStorageUnitElementType (combined: StorageUnitElementType) }; } +/** + * @deprecated Since V3.5.0. + */ @ccclass('cc.CompactValueTypeArray') export class CompactValueTypeArray { public static StorageUnit = StorageUnit; diff --git a/cocos/core/deprecated.ts b/cocos/core/deprecated.ts index beba96c36d..d06847f161 100644 --- a/cocos/core/deprecated.ts +++ b/cocos/core/deprecated.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { replaceProperty, removeProperty, markAsWarning } from './utils/x-deprecated'; import * as math from './math'; import { Scheduler } from './scheduler'; diff --git a/cocos/core/director.ts b/cocos/core/director.ts index 5f1659b6a9..bf0c396b56 100644 --- a/cocos/core/director.ts +++ b/cocos/core/director.ts @@ -27,11 +27,6 @@ /* spell-checker:words COORD, Quesada, INITED, Renerer */ -/** - * @packageDocumentation - * @module core - */ - import { DEBUG, EDITOR, BUILD, TEST } from 'internal:constants'; import { SceneAsset } from './assets'; import System from './components/system'; @@ -172,29 +167,29 @@ export class Director extends EventTarget { public static readonly EVENT_BEFORE_COMMIT = 'director_before_commit'; /** - * The event which will be triggered before the physics process.
- * 物理过程之前所触发的事件。 + * @en The event which will be triggered before the physics process.
+ * @zh 物理过程之前所触发的事件。 * @event Director.EVENT_BEFORE_PHYSICS */ public static readonly EVENT_BEFORE_PHYSICS = 'director_before_physics'; /** - * The event which will be triggered after the physics process.
- * 物理过程之后所触发的事件。 + * @en The event which will be triggered after the physics process.
+ * @zh 物理过程之后所触发的事件。 * @event Director.EVENT_AFTER_PHYSICS */ public static readonly EVENT_AFTER_PHYSICS = 'director_after_physics'; /** - * The event which will be triggered at the frame begin.
- * 一帧开始时所触发的事件。 + * @en The event which will be triggered at the frame begin.
+ * @zh 一帧开始时所触发的事件。 * @event Director.EVENT_BEGIN_FRAME */ public static readonly EVENT_BEGIN_FRAME = 'director_begin_frame'; /** - * The event which will be triggered at the frame end.
- * 一帧结束之后所触发的事件。 + * @en The event which will be triggered at the frame end.
+ * @zh 一帧结束之后所触发的事件。 * @event Director.EVENT_END_FRAME */ public static readonly EVENT_END_FRAME = 'director_end_frame'; @@ -484,8 +479,8 @@ export class Director extends EventTarget { * @zh 预加载场景资源,你可以在任何时候调用这个方法。 * 调用完后,你仍然需要通过 `director.loadScene` 来启动场景,因为这个方法不会执行场景加载操作。
* 就算预加载还没完成,你也可以直接调用 `director.loadScene`,加载完成后场景就会启动。 - * @param sceneName 场景名称。 - * @param onLoaded 加载回调。 + * @param sceneName @en The name of the scene to load @zh 场景名称。 + * @param onLoaded @en Callback to execute once the scene is loaded @zh 加载回调。 */ public preloadScene (sceneName: string, onLoaded?: Director.OnSceneLoaded): void; @@ -498,9 +493,9 @@ export class Director extends EventTarget { * @zh 预加载场景,你可以在任何时候调用这个方法。 * 调用完后,你仍然需要通过 `director.loadScene` 来启动场景,因为这个方法不会执行场景加载操作。
* 就算预加载还没完成,你也可以直接调用 `director.loadScene`,加载完成后场景就会启动。 - * @param sceneName 场景名称。 - * @param onProgress 加载进度回调。 - * @param onLoaded 加载回调。 + * @param sceneName @en The name of scene to load @zh 场景名称。 + * @param onProgress @en Callback to execute when the load progression change. @zh 加载进度回调。 + * @param onLoaded @en Callback to execute once the scene is loaded @zh 加载回调。 */ public preloadScene (sceneName: string, onProgress: Director.OnLoadSceneProgress, onLoaded: Director.OnSceneLoaded): void; @@ -766,6 +761,7 @@ export declare namespace Director { legacyCC.Director = Director; /** - * 导演类。 + * @en Director of the game, used to control game update loop and scene management + * @zh 游戏的导演,用于控制游戏更新循环与场景管理。 */ export const director: Director = Director.instance = legacyCC.director = new Director(); diff --git a/cocos/core/easing/easing.ts b/cocos/core/easing/easing.ts index e37c113604..c4b408f1f4 100644 --- a/cocos/core/easing/easing.ts +++ b/cocos/core/easing/easing.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module animation - */ - export function constant () { return 0; } diff --git a/cocos/core/event/defines.ts b/cocos/core/event/defines.ts index a8e62787c3..c208cc9473 100644 --- a/cocos/core/event/defines.ts +++ b/cocos/core/event/defines.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - export type EventArgumentsOf< K extends string, Map extends any, diff --git a/cocos/core/event/event-target-factory.ts b/cocos/core/event/event-target-factory.ts index 51237c1898..32420a9c01 100644 --- a/cocos/core/event/event-target-factory.ts +++ b/cocos/core/event/event-target-factory.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module event - */ - import { EventTarget } from './event-target'; export function applyMixins (derivedCtor: any, baseCtors: any[]) { diff --git a/cocos/core/event/event-target.ts b/cocos/core/event/event-target.ts index b96c9fc838..322c4c1d0a 100644 --- a/cocos/core/event/event-target.ts +++ b/cocos/core/event/event-target.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module event - */ - import { legacyCC } from '../global-exports'; import { Eventify } from './eventify'; diff --git a/cocos/core/event/eventify.ts b/cocos/core/event/eventify.ts index 57975d82cf..78b94e445c 100644 --- a/cocos/core/event/eventify.ts +++ b/cocos/core/event/eventify.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module event - */ - import { CallbacksInvoker } from './callbacks-invoker'; import { createMap } from '../utils/js'; diff --git a/cocos/core/event/index.ts b/cocos/core/event/index.ts index 5064d451d2..4203aeffc4 100644 --- a/cocos/core/event/index.ts +++ b/cocos/core/event/index.ts @@ -24,10 +24,5 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module event - */ - export { EventTarget } from './event-target'; export { Eventify } from './eventify'; diff --git a/cocos/core/game.ts b/cocos/core/game.ts index 15d36485b5..ef4b318192 100644 --- a/cocos/core/game.ts +++ b/cocos/core/game.ts @@ -23,10 +23,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/** - * @packageDocumentation - * @module core - */ import { EDITOR, HTML5, JSB, PREVIEW, RUNTIME_BASED, TEST } from 'internal:constants'; import { systemInfo } from 'pal/system-info'; @@ -135,37 +131,56 @@ export interface IGameConfig { scenes?: ISceneInfo[]; /** + * @internal * For internal use. */ jsList?: string[]; /** + * @en * Render pipeline resources + * @zh + * Render pipeline 资源 */ renderPipeline?: string; /** + * @en * Asset Manager initialization options + * @zh + * 资源管理器初始化设置 */ assetOptions?: IAssetManagerOptions; /** + * @en * GPU instancing options + * @zh + * GPU instancing 选项 */ customJointTextureLayouts?: ICustomJointTextureLayout[]; /** + * @en * Physics system config + * @zh + * 物理系统设置 */ physics?: IPhysicsConfig; /** + * @en * User layers config + * @zh + * 用户层级设置 */ layers?: LayerItem[]; /** + * @en * The adapter stores various platform-related objects. + * @zh + * 平台相关选项 */ adapter?: { canvas: HTMLCanvasElement, @@ -175,13 +190,19 @@ export interface IGameConfig { }; /** + * @en * The orientation from the builder configuration. * Available value can be 'auto', 'landscape', 'portrait'. + * @zh + * 屏幕旋转方向,可选 “自动”,“横屏”,“竖屏” */ orientation?: ConfigOrientation; /** + * @en * Determine whether the game frame exact fits the screen. * Now it only works on Web platform. + * @zh + * 是否让游戏外框对齐到屏幕上,目前只在 web 平台生效 */ exactFitScreen: boolean, } diff --git a/cocos/core/geometry/aabb.ts b/cocos/core/geometry/aabb.ts index c7dcd98aec..5516fc30d0 100644 --- a/cocos/core/geometry/aabb.ts +++ b/cocos/core/geometry/aabb.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module geometry - */ - import { Mat3, Mat4, Quat, Vec3 } from '../math'; import enums from './enums'; import { IVec3, IVec3Like } from '../math/type-define'; @@ -61,13 +56,13 @@ export class AABB { * create a new AABB * @zh * 创建一个新的 AABB 实例。 - * @param px - AABB 的原点的 X 坐标。 - * @param py - AABB 的原点的 Y 坐标。 - * @param pz - AABB 的原点的 Z 坐标。 - * @param hw - AABB 宽度的一半。 - * @param hh - AABB 高度的一半。 - * @param hl - AABB 长度的一半。 - * @returns 返回新创建的 AABB 实例。 + * @param px @zh AABB 的原点的 X 坐标。@en The x coordinate of the origin of the AABB. + * @param py @zh AABB 的原点的 Y 坐标。@en The y coordinate of the origin of the AABB. + * @param pz @zh AABB 的原点的 Z 坐标。 @en The z coordinate of the origin of the AABB. + * @param hw @zh AABB 宽度的一半。 @en Half the width of the AABB. + * @param hh @zh AABB 高度的一半。@en Half the height of the AABB. + * @param hl @zh AABB 长度的一半。@en Half the length of the AABB. + * @returns @zh 返回新创建的 AABB 实例。 @en A new instance of AABB. */ public static create (px?: number, py?: number, pz?: number, hw?: number, hh?: number, hl?: number) { return new AABB(px, py, pz, hw, hh, hl); @@ -78,8 +73,8 @@ export class AABB { * clone a new AABB * @zh * 克隆一个 AABB。 - * @param a - 克隆的目标。 - * @returns 克隆出的 AABB。 + * @param a @zh 克隆的目标。 @en Target object. + * @returns @zh 克隆出的 AABB。@en The new AABB. */ public static clone (a: AABB | Readonly) { return new AABB(a.center.x, a.center.y, a.center.z, @@ -91,9 +86,9 @@ export class AABB { * copy the values from one AABB to another * @zh * 将从一个 AABB 的值复制到另一个 AABB。 - * @param {AABB} out 接受操作的 AABB。 - * @param {AABB} a 被复制的 AABB。 - * @return {AABB} out 接受操作的 AABB。 + * @param out @zh 接受操作的 AABB。 @en The output AABB, copy destination. + * @param a @zh 被复制的 AABB。 @en Source object of copy operation. + * @returns @zh 接受操作的 AABB。 @en The reference of the first parameter `dst`, the new AABB. */ public static copy (out: AABB, a: AABB | Readonly): AABB { Vec3.copy(out.center, a.center); @@ -104,13 +99,13 @@ export class AABB { /** * @en - * create a new AABB from two corner points + * Construct a new AABB from two corner points * @zh * 从两个点创建一个新的 AABB。 - * @param out - 接受操作的 AABB。 - * @param minPos - AABB 的最小点。 - * @param maxPos - AABB 的最大点。 - * @returns {AABB} out 接受操作的 AABB。 + * @param out @zh 接受操作的 AABB。 @en The output AABB + * @param minPos @zh AABB 的最小点。 @en Minimum point of the axis-aligned 3d bounding box. + * @param maxPos @zh AABB 的最大点。 @en Maximum point of the axis-aligned 3d bounding box. + * @returns @zh out 接受操作的 AABB。 @en The new AABB */ public static fromPoints (out: AABB, minPos: IVec3, maxPos: IVec3): AABB { Vec3.add(_v3_tmp, maxPos, minPos); @@ -125,14 +120,14 @@ export class AABB { * Set the components of a AABB to the given values * @zh * 将 AABB 的属性设置为给定的值。 - * @param {AABB} out 接受操作的 AABB。 - * @param px - AABB 的原点的 X 坐标。 - * @param py - AABB 的原点的 Y 坐标。 - * @param pz - AABB 的原点的 Z 坐标。 - * @param hw - AABB 宽度的一半。 - * @param hh - AABB 高度的一半。 - * @param hl - AABB 长度度的一半。 - * @return {AABB} out 接受操作的 AABB。 + * @param @zh out 接受操作的 AABB。 @en The output AABB to set. + * @param px @zh - AABB 的原点的 X 坐标。 @en The x coordinate of the origin of the AABB. + * @param py @zh - AABB 的原点的 Y 坐标。 @en The y coordinate of the origin of the AABB. + * @param pz @zh - AABB 的原点的 Z 坐标。 @en The z coordinate of the origin of the AABB. + * @param hw @zh - AABB 宽度的一半。 @en Half the width of the AABB. + * @param hh @zh - AABB 高度的一半。 @en Half the height of the AABB. + * @param hl @zh - AABB 长度度的一半。 @en Half the length of the AABB. + * @returns @zh out 接受操作的 AABB。 @en The reference fo the first parameter `out`. */ public static set (out: AABB, px: number, py: number, pz: number, hw: number, hh: number, hl: number): AABB { out.center.set(px, py, pz); @@ -142,13 +137,13 @@ export class AABB { /** * @en - * Merge tow AABB. + * Merge two AABB into one. * @zh * 合并两个 AABB 到 out。 - * @param out 接受操作的 AABB。 - * @param a 输入的 AABB。 - * @param b 输入的 AABB。 - * @returns {AABB} out 接受操作的 AABB。 + * @param out @zh 接受操作的 AABB。 @en The output AABB to storge merge result. + * @param a @zh 输入的 AABB。 @en The first AABB to be merged. + * @param b @zh 输入的 AABB。 @en The second AABB to be merged. + * @returns @zh out 接受操作的 AABB。 @en The reference of the first parameter `out`. */ public static merge (out: AABB, a: AABB | Readonly, b: AABB | Readonly): AABB { Vec3.subtract(_v3_tmp, a.center, a.halfExtents); @@ -162,11 +157,12 @@ export class AABB { /** * @en - * AABB to sphere + * Convert AABB to sphere. * @zh * 包围盒转包围球 - * @param out 接受操作的 sphere。 - * @param a 输入的 AABB。 + * @param out @zh 接受操作的 sphere。 @en The output sphere. + * @param a @zh 输入的 AABB。 @en The input AABB. + * @returns @zh out 接受的 Sphere @en The reference of the first parameter `out`. */ public static toBoundingSphere (out: Sphere, a: AABB | Readonly) { out.center.set(a.center); @@ -179,10 +175,10 @@ export class AABB { * Transform this AABB. * @zh * 变换一个 AABB 到 out 中。 - * @param out 接受操作的 AABB。 - * @param a 输入的源 AABB。 - * @param matrix 矩阵。 - * @returns {AABB} out 接受操作的 AABB。 + * @param out @zh 接受操作的 AABB。 @en The output AABB. + * @param a @zh 输入的源 AABB。 @en The input AABB. + * @param matrix @zh 矩阵。 @en The transformation matrix. + * @returns @zh {AABB} out 接受操作的 AABB。 @en The reference of the first parameter `out`. */ public static transform (out: AABB, a: AABB | Readonly, matrix: Mat4 | Readonly): AABB { Vec3.transformMat4(out.center, a.center, matrix); @@ -191,12 +187,16 @@ export class AABB { } /** + * @en + * The origin point of the AABB * @zh * 本地坐标的中心点。 */ public center: Vec3; /** + * @en + * Half the size of the AABB * @zh * 长宽高的一半。 */ @@ -225,8 +225,8 @@ export class AABB { * Get the bounding points of this shape * @zh * 获取 AABB 的最小点和最大点。 - * @param {Vec3} minPos 最小点。 - * @param {Vec3} maxPos 最大点。 + * @param minPos @zh 最小点。 @en Minimum position of the axis-aligned 3d bounding box. + * @param maxPos @zh 最大点。 @en Maximum position of the axis-aligned 3d bounding box. */ public getBoundary (minPos: IVec3Like, maxPos: IVec3Like) { Vec3.subtract(minPos, this.center, this.halfExtents); @@ -238,11 +238,11 @@ export class AABB { * Transform this shape * @zh * 将 out 根据这个 AABB 的数据进行变换。 - * @param m 变换的矩阵。 - * @param pos 变换的位置部分。 - * @param rot 变换的旋转部分。 - * @param scale 变换的缩放部分。 - * @param out 变换的目标。 + * @param m @zh 变换的矩阵。 @en The transform matrix. + * @param pos @zh 变换的位置部分。 @en 3d-vector translation. + * @param rot @zh 变换的旋转部分。 @en Quaternion rotation . + * @param scale @zh 变换的缩放部分。 @en 3d-vector scale. + * @param out @zh 变换的目标。 @en The output AABB. */ public transform (m: Mat4, pos: Vec3 | null, rot: Quat | null, scale: Vec3 | null, out: AABB) { Vec3.transformMat4(out.center, this.center, m); @@ -250,19 +250,23 @@ export class AABB { } /** + * @en + * Clones the AABB * @zh * 获得克隆。 - * @returns {AABB} + * @returns @zh {AABB} @en A copy of the object. */ public clone (): AABB { return AABB.clone(this); } /** + * @en + * Copy the input to the receiver object. * @zh * 拷贝对象。 - * @param a 拷贝的目标。 - * @returns {AABB} + * @param a @zh 拷贝的目标。 @en Copy target + * @returns @zh This object @en The reference of this. */ public copy (a: AABB | Readonly): AABB { return AABB.copy(this, a); @@ -271,7 +275,7 @@ export class AABB { /** * @en AABB and point merge. * @zh AABB包围盒合并一个顶点。 - * @param point - 某一个位置的顶点。 + * @param point @zh - 某一个位置的顶点。 @en A point in 3d space. */ public mergePoint (point: IVec3) { // _v3_tmp is min pos @@ -291,10 +295,10 @@ export class AABB { } /** - * @en AABB and points merge. - * @zh AABB包围盒合并一系列顶点。 - * @param points - 某一个位置的顶点。 - */ + * @en AABB and points merge. + * @zh AABB包围盒合并一系列顶点。 + * @param points @zh - 某一个位置的顶点。 @en A list of points in 3d space. + */ public mergePoints (points: IVec3[]) { if (points.length < 1) { return; } for (let i = 0; i < points.length; i++) { @@ -305,7 +309,7 @@ export class AABB { /** * @en AABB and frustum merge. * @zh Frustum 合并到 AABB。 - * @param frustum 输入的 Frustum。 + * @param frustum @zh 输入的 Frustum。 @en The frustum object. */ public mergeFrustum (frustum: Frustum | Readonly) { return this.mergePoints(frustum.vertices); diff --git a/cocos/core/geometry/capsule.ts b/cocos/core/geometry/capsule.ts index 0351275a40..bc8bdd8b67 100644 --- a/cocos/core/geometry/capsule.ts +++ b/cocos/core/geometry/capsule.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module geometry - */ - import { Vec3, Quat, Mat4, absMaxComponent } from '../math'; import enums from './enums'; import { IVec3Like, IQuatLike } from '../math/type-define'; @@ -91,8 +86,14 @@ export class Capsule { */ readonly rotation: Quat; - /** cache, local center of ellipse */ + /** + * @internal + * cache, local center of ellipse + **/ readonly ellipseCenter0: Vec3; + /** + * @internal + */ readonly ellipseCenter1: Vec3; constructor (radius = 0.5, halfHeight = 0.5, axis = 1) { @@ -154,6 +155,8 @@ export class Capsule { this.ellipseCenter0.set(0, 0, halfHeight); this.ellipseCenter1.set(0, 0, -halfHeight); break; + default: + break; } } } diff --git a/cocos/core/geometry/curve.ts b/cocos/core/geometry/curve.ts index b796698af0..8dddaebb6b 100644 --- a/cocos/core/geometry/curve.ts +++ b/cocos/core/geometry/curve.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module geometry - */ - import { CCClass } from '../data/class'; import { clamp, inverseLerp, pingPong, repeat } from '../math/utils'; import { WrapModeMask } from '../animation/types'; @@ -120,7 +115,7 @@ export class AnimationCurve { /** * For internal usage only. - * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. + * @internal */ get _internalCurve () { return this._curve; @@ -157,9 +152,9 @@ export class AnimationCurve { /** * @en - * Loop mode [[WrapMode]] when the sampling time exceeds the left end. + * Loop mode [[AnimationClip.WrapMode]] when the sampling time exceeds the left end. * @zh - * 当采样时间超出左端时采用的循环模式[[WrapMode]]。 + * 当采样时间超出左端时采用的循环模式[[AnimationClip.WrapMode]]。 */ get preWrapMode () { return toLegacyWrapMode(this._curve.preExtrapolation); @@ -171,9 +166,9 @@ export class AnimationCurve { /** * @en - * Cycle mode [[WrapMode]] when the sampling time exceeds the right end. + * Cycle mode [[AnimationClip.WrapMode]] when the sampling time exceeds the right end. * @zh - * 当采样时间超出右端时采用的循环模式[[WrapMode]]。 + * 当采样时间超出右端时采用的循环模式[[AnimationClip.WrapMode]]。 */ get postWrapMode () { return toLegacyWrapMode(this._curve.postExtrapolation); @@ -186,8 +181,9 @@ export class AnimationCurve { private cachedKey: OptimizedKey; /** - * 构造函数。 - * @param keyFrames 关键帧。 + * @en Construct a curve with key frames + * @zh 通过关键帧构造一条曲线。 + * @param keyFrames @zh 关键帧 @en Key frames */ constructor (keyFrames: Keyframe[] | null | RealCurve = null) { if (keyFrames instanceof RealCurve) { @@ -219,7 +215,7 @@ export class AnimationCurve { * Add a keyframe. * @zh * 添加一个关键帧。 - * @param keyFrame 关键帧。 + * @param keyFrame @en A keyframe. @zh 关键帧。 */ public addKey (keyFrame: Keyframe | null) { if (!keyFrame) { @@ -247,7 +243,7 @@ export class AnimationCurve { * Calculate the curve interpolation at a given point in time. * @zh * 计算给定时间点的曲线插值。 - * @param time 时间。 + * @param time @en The time. @zh 时间。 */ public evaluate (time: number) { const { cachedKey, _curve: curve } = this; diff --git a/cocos/core/geometry/deprecated-3.0.0.ts b/cocos/core/geometry/deprecated-3.0.0.ts index ef0d56040f..55432581fb 100644 --- a/cocos/core/geometry/deprecated-3.0.0.ts +++ b/cocos/core/geometry/deprecated-3.0.0.ts @@ -151,8 +151,12 @@ function deprecatedClassMessage (oldClassName: string, newClassName) { } /** - * Alias of [[Line]] - * @deprecated Since v3.0 + * @en + * Alias of [[geometry.Line]] + * @zh + * [[geometry.Line]] 别名类 + * + * @deprecated Since v3.0, please use Line instead */ export class line extends Line { constructor () { @@ -162,8 +166,13 @@ export class line extends Line { } /** - * Alias of [[Plane]] - * @deprecated Since v3.0 + * @en + * Alias of [[geometry.Plane]] + * + * @zh + * [[geometry.Plane]] 别名类 + * + * @deprecated Since v3.0, please use Plane instead */ export class plane extends Plane { constructor () { @@ -173,8 +182,11 @@ export class plane extends Plane { } /** - * Alias of [[Ray]] - * @deprecated Since v3.0 + * @en + * Alias of [[geometry.Ray]] + * @zh + * [[geometry.Ray]] 别名类 + * @deprecated Since v3.0, please use Ray instead */ export class ray extends Ray { constructor () { @@ -184,8 +196,12 @@ export class ray extends Ray { } /** - * Alias of [[Triangle]] - * @deprecated Since v3.0 + * @en + * Alias of [[geometry.Triangle]] + * + * @zh + * [[geometry.Triangle]] 别名类 + * @deprecated Since v3.0, please use Triangle instead */ export class triangle extends Triangle { constructor () { @@ -195,8 +211,12 @@ export class triangle extends Triangle { } /** - * Alias of [[Sphere]] - * @deprecated Since v3.0 + * @en + * Alias of [[geometry.Sphere]] + * + * @zh + * [[geometry.Sphere]] 别名类 + * @deprecated Since v3.0, please use Sphere instead */ export class sphere extends Sphere { constructor () { @@ -206,8 +226,12 @@ export class sphere extends Sphere { } /** - * Alias of [[AABB]] - * @deprecated Since v3.0 + * @en + * Alias of [[geometry.AABB]] + * + * @zh + * [[geometry.AABB]] 别名类 + * @deprecated Since v3.0, please use AABB instead */ export class aabb extends AABB { constructor () { @@ -217,8 +241,12 @@ export class aabb extends AABB { } /** - * Alias of [[OBB]] - * @deprecated Since v3.0 + * @en + * Alias of [[geometry.OBB]] + * + * @zh + * [[geometry.OBB]] 别名类 + * @deprecated Since v3.0, please use OBB instead */ export class obb extends OBB { constructor () { @@ -228,8 +256,12 @@ export class obb extends OBB { } /** - * Alias of [[Capsule]] - * @deprecated Since v3.0 + * @en + * Alias of [[geometry.Capsule]] + * + * @zh + * [[geometry.Capsule]] 别名类 + * @deprecated Since v3.0, please use Capsule instead */ export class capsule extends Capsule { constructor () { @@ -239,8 +271,12 @@ export class capsule extends Capsule { } /** - * Alias of [[Frustum]] - * @deprecated Since v3.0 + * @en + * Alias of [[geometry.Frustum]] + * + * @zh + * [[geometry.Frustum]] 别名类 + * @deprecated Since v3.0, please use Frustum instead */ export class frustum extends Frustum { constructor () { diff --git a/cocos/core/geometry/distance.ts b/cocos/core/geometry/distance.ts index 322b9385cc..468b847c20 100644 --- a/cocos/core/geometry/distance.ts +++ b/cocos/core/geometry/distance.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module geometry - */ - import { Vec3 } from '../math'; import { AABB } from './aabb'; import { OBB } from './obb'; @@ -47,9 +42,9 @@ const e = new Array(3); * the distance between a point and a plane * @zh * 计算点和平面之间的距离。 - * @param {Vec3} point 点。 - * @param {Plane} plane 平面。 - * @return 距离。 + * @param {Vec3} point @en Target point @zh 目标点。 + * @param {Plane} plane @en Target plane @zh 目标平面。 + * @return @en The distance in between @zh 距离。 */ export function point_plane (point: Vec3, plane_: Plane) { return Vec3.dot(plane_.n, point) - plane_.d; @@ -60,10 +55,10 @@ export function point_plane (point: Vec3, plane_: Plane) { * the closest point on plane to a given point * @zh * 计算平面上最接近给定点的点。 - * @param out 最近点。 - * @param point 给定点。 - * @param plane 平面。 - * @return 最近点。 + * @param out @en The closest point, as a result @zh 最近点。 + * @param point @en The given point @zh 给定点。 + * @param plane @en Target plane @zh 平面。 + * @return @en The closest point, same as out @zh 最近点。 */ export function pt_point_plane (out: Vec3, point: Vec3, plane_: Plane) { const t = point_plane(point, plane_); @@ -75,10 +70,10 @@ export function pt_point_plane (out: Vec3, point: Vec3, plane_: Plane) { * the closest point on aabb to a given point * @zh * 计算 aabb 上最接近给定点的点。 - * @param {Vec3} out 最近点。 - * @param {Vec3} point 给定点。 - * @param {AABB} aabb 轴对齐包围盒。 - * @return {Vec3} 最近点。 + * @param {Vec3} out @en The closest point, as a result @zh 最近点。 + * @param {Vec3} point @en The given point @zh 给定点。 + * @param {AABB} aabb @en Target aabb to calculate @zh 轴对齐包围盒。 + * @return {Vec3} @en The closest point, same as out @zh 最近点。 */ export function pt_point_aabb (out: Vec3, point: Vec3, aabb_: AABB): Vec3 { Vec3.copy(out, point); @@ -100,10 +95,10 @@ export function pt_point_aabb (out: Vec3, point: Vec3, aabb_: AABB): Vec3 { * the closest point on obb to a given point * @zh * 计算 obb 上最接近给定点的点。 - * @param {Vec3} out 最近点。 - * @param {Vec3} point 给定点。 - * @param {OBB} obb 方向包围盒。 - * @return {Vec3} 最近点。 + * @param {Vec3} out @en The closest point, as a result @zh 最近点。 + * @param {Vec3} point @en The given point @zh 给定点。 + * @param {OBB} obb @en Target obb to calculate @zh 方向包围盒。 + * @return {Vec3} @en The closest point, same as out @zh 最近点。 */ export function pt_point_obb (out: Vec3, point: Vec3, obb_: OBB): Vec3 { Vec3.set(X, obb_.orientation.m00, obb_.orientation.m01, obb_.orientation.m02); @@ -146,13 +141,13 @@ export function pt_point_obb (out: Vec3, point: Vec3, obb_: OBB): Vec3 { /** * @en - * Calculate the nearest point on the line to the given point. + * Calculate the nearest point on the line, which is from A to B, to the given point * @zh - * 计算给定点距离直线上最近的一点。 - * @param out 最近点 - * @param point 给定点 - * @param linePointA 线上的某点 A - * @param linePointB 线上的某点 B + * 计算给定点距离线段上最近的一点。线段从A到B。 + * @param out @en The closest point, as a result @zh 最近点 + * @param point @en The given point @zh 给定点 + * @param linePointA @en Point A on the line @zh 线上的某点 A + * @param linePointB @en Point B on the line @zh 线上的某点 B */ export function pt_point_line (out: Vec3, point: Vec3, linePointA: Vec3, linePointB: Vec3) { Vec3.subtract(X, linePointA, linePointB); diff --git a/cocos/core/geometry/frustum.ts b/cocos/core/geometry/frustum.ts index 777e76f919..be38688864 100644 --- a/cocos/core/geometry/frustum.ts +++ b/cocos/core/geometry/frustum.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module geometry - */ - import { Mat4, Vec3 } from '../math'; import { Camera } from '../renderer/scene'; import enums from './enums'; diff --git a/cocos/core/geometry/index.ts b/cocos/core/geometry/index.ts index 122b83af58..f813ef18cc 100644 --- a/cocos/core/geometry/index.ts +++ b/cocos/core/geometry/index.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module geometry - */ - import * as distance from './distance'; import './deprecated'; diff --git a/cocos/core/geometry/intersect.ts b/cocos/core/geometry/intersect.ts index 2a5d217d31..af18f99efc 100644 --- a/cocos/core/geometry/intersect.ts +++ b/cocos/core/geometry/intersect.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module geometry - */ - import { EPSILON, Mat3, Vec3, Mat4 } from '../math'; import { AABB } from './aabb'; import { Capsule } from './capsule'; @@ -1432,11 +1427,12 @@ const intersect = { capsuleWithCapsule, /** - * @zh - * g1 和 g2 的相交性检测,可填入基础几何中的形状。 - * @param g1 几何1 - * @param g2 几何2 - * @param outPt 可选,相交点。(注:仅部分形状的检测带有这个返回值) + * @en Check intersection between two geometries, it accept all basic geometry types in [[geometry]] module. + * @zh 两个几何体的相交性检测,可填入 [[geometry]] 模块中的基础几何形状。 + * @param g1 @en The first geometry. @zh 第一个几何体。 + * @param g2 @en The second geometry. @zh 第二个几何体。 + * @param outPt @en A 3d point to store the intersection point result, only part of the geometries support this. + * @zh 可选,用于保存相交点的输出对象。(注:仅部分形状的检测带有这个返回值) */ resolve (g1: any, g2: any, outPt = null) { const type1 = g1._type; const type2 = g2._type; diff --git a/cocos/core/geometry/line.ts b/cocos/core/geometry/line.ts index 703cf6942d..c7ae915578 100644 --- a/cocos/core/geometry/line.ts +++ b/cocos/core/geometry/line.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module geometry - */ - import { Vec3 } from '../math'; import enums from './enums'; diff --git a/cocos/core/geometry/obb.ts b/cocos/core/geometry/obb.ts index 8554726d1c..433ac6de44 100644 --- a/cocos/core/geometry/obb.ts +++ b/cocos/core/geometry/obb.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module geometry - */ - import { Mat3, Mat4, Quat, Vec3 } from '../math'; import enums from './enums'; @@ -56,22 +51,22 @@ export class OBB { * create a new obb * @zh * 创建一个新的 obb 实例。 - * @param cx 形状的相对于原点的 X 坐标。 - * @param cy 形状的相对于原点的 Y 坐标。 - * @param cz 形状的相对于原点的 Z 坐标。 - * @param hw - obb 宽度的一半。 - * @param hh - obb 高度的一半。 - * @param hl - obb 长度的一半。 - * @param ox_1 方向矩阵参数。 - * @param ox_2 方向矩阵参数。 - * @param ox_3 方向矩阵参数。 - * @param oy_1 方向矩阵参数。 - * @param oy_2 方向矩阵参数。 - * @param oy_3 方向矩阵参数。 - * @param oz_1 方向矩阵参数。 - * @param oz_2 方向矩阵参数。 - * @param oz_3 方向矩阵参数。 - * @return 返回一个 obb。 + * @param cx @zh 形状的相对于原点的 X 坐标。 @en The x coordinate of origin. + * @param cy @zh 形状的相对于原点的 Y 坐标。 @en The y coordinate of origin. + * @param cz @zh 形状的相对于原点的 Z 坐标。 @en The z coordinate of origin. + * @param hw @zh - obb 宽度的一半。 @en Half the width of the OBB. + * @param hh @zh - obb 高度的一半。 @en Half the height of the OBB. + * @param hl @zh - obb 长度的一半。 @en Half the length of the OBB. + * @param ox_1 @zh 方向矩阵参数。 @en The x component of the one axis of the OBB. + * @param ox_2 @zh 方向矩阵参数。 @en The x component of the second axis of the OBB. + * @param ox_3 @zh 方向矩阵参数。 @en The x component of the third axis of the OBB. + * @param oy_1 @zh 方向矩阵参数。 @en The y component of the one axis of the OBB. + * @param oy_2 @zh 方向矩阵参数。 @en The y component of the second axis of the OBB. + * @param oy_3 @zh 方向矩阵参数。 @en The y component of the third axis of the OBB. + * @param oz_1 @zh 方向矩阵参数。 @en The z component of the one axis of the OBB. + * @param oz_2 @zh 方向矩阵参数。 @en The z component of the second axis of the OBB. + * @param oz_3 @zh 方向矩阵参数。 @en The z component of the third axis of the OBB. + * @return @zh 返回一个 obb。 @en A new OBB. */ public static create ( cx: number, cy: number, cz: number, @@ -88,8 +83,8 @@ export class OBB { * clone a new obb * @zh * 克隆一个 obb。 - * @param a 克隆的目标。 - * @returns 克隆出的新对象。 + * @param a @zh 克隆的目标。 @en The input OBB. + * @returns @zh The new OBB. @en 克隆出的新对象。 */ public static clone (a: OBB) { return new OBB(a.center.x, a.center.y, a.center.z, @@ -104,9 +99,9 @@ export class OBB { * copy the values from one obb to another * @zh * 将从一个 obb 的值复制到另一个 obb。 - * @param {OBB} out 接受操作的 obb。 - * @param {OBB} a 被复制的 obb。 - * @return {OBB} out 接受操作的 obb。 + * @param out @zh 接受操作的 obb。 @en The output OBB. + * @param a @zh 被复制的 obb。 @en The input OBB. + * @returns @zh out 接受操作的 obb。 @en The reference of the first parameter `out`. */ public static copy (out: OBB, a: OBB): OBB { Vec3.copy(out.center, a.center); @@ -121,10 +116,10 @@ export class OBB { * create a new obb from two corner points * @zh * 用两个点创建一个新的 obb。 - * @param out - 接受操作的 obb。 - * @param minPos - obb 的最小点。 - * @param maxPos - obb 的最大点。 - * @returns {OBB} out 接受操作的 obb。 + * @param out @zh - 接受操作的 obb。 @en The output OBB. + * @param minPos @zh - obb 的最小点。 @en The minimum position of the AABB. + * @param maxPos @zh - obb 的最大点。 @en The maximum position of the AABB. + * @returns @zh {OBB} out 接受操作的 obb。 @en The reference of the first parameter `out`. */ public static fromPoints (out: OBB, minPos: Vec3, maxPos: Vec3): OBB { Vec3.multiplyScalar(out.center, Vec3.add(_v3_tmp, minPos, maxPos), 0.5); @@ -138,22 +133,23 @@ export class OBB { * Set the components of a obb to the given values * @zh * 将给定 obb 的属性设置为给定的值。 - * @param cx - obb 的原点的 X 坐标。 - * @param cy - obb 的原点的 Y 坐标。 - * @param cz - obb 的原点的 Z 坐标。 - * @param hw - obb 宽度的一半。 - * @param hh - obb 高度的一半。 - * @param hl - obb 长度的一半。 - * @param ox_1 方向矩阵参数。 - * @param ox_2 方向矩阵参数。 - * @param ox_3 方向矩阵参数。 - * @param oy_1 方向矩阵参数。 - * @param oy_2 方向矩阵参数。 - * @param oy_3 方向矩阵参数。 - * @param oz_1 方向矩阵参数。 - * @param oz_2 方向矩阵参数。 - * @param oz_3 方向矩阵参数。 - * @return {OBB} out + * @param out @zh 目标 OBB @en The output OBB. + * @param cx @zh 形状的相对于原点的 X 坐标。 @en The x coordinate of origin. + * @param cy @zh 形状的相对于原点的 Y 坐标。 @en The y coordinate of origin. + * @param cz @zh 形状的相对于原点的 Z 坐标。 @en The z coordinate of origin. + * @param hw @zh - obb 宽度的一半。 @en Half the width of the OBB. + * @param hh @zh - obb 高度的一半。 @en Half the height of the OBB. + * @param hl @zh - obb 长度的一半。 @en Half the length of the OBB. + * @param ox_1 @zh 方向矩阵参数。 @en The x component of the one axis of the OBB. + * @param ox_2 @zh 方向矩阵参数。 @en The x component of the second axis of the OBB. + * @param ox_3 @zh 方向矩阵参数。 @en The x component of the third axis of the OBB. + * @param oy_1 @zh 方向矩阵参数。 @en The y component of the one axis of the OBB. + * @param oy_2 @zh 方向矩阵参数。 @en The y component of the second axis of the OBB. + * @param oy_3 @zh 方向矩阵参数。 @en The y component of the third axis of the OBB. + * @param oz_1 @zh 方向矩阵参数。 @en The z component of the one axis of the OBB. + * @param oz_2 @zh 方向矩阵参数。 @en The z component of the second axis of the OBB. + * @param oz_3 @zh 方向矩阵参数。 @en The z component of the third axis of the OBB. + * @returns @zh out 接受操作的 OBB @en The reference of the first parameter `out`. */ public static set ( out: OBB, @@ -170,18 +166,24 @@ export class OBB { } /** + * @en + * Center point of the OBB. * @zh * 本地坐标的中心点。 */ public center: Vec3; /** + * @en + * Half the distance across the OBB in each local axis. * @zh * 长宽高的一半。 */ public halfExtents: Vec3; /** + * @en + * Orientation matrix. * @zh * 方向矩阵。 */ @@ -215,8 +217,8 @@ export class OBB { * Get the bounding points of this shape * @zh * 获取 obb 的最小点和最大点。 - * @param {Vec3} minPos 最小点。 - * @param {Vec3} maxPos 最大点。 + * @param minPos @zh 最小点。 @en The out minimum position of the OBB. + * @param maxPos @zh 最大点。 @en The out maximum position of the OBB. */ public getBoundary (minPos: Vec3, maxPos: Vec3) { transform_extent_m3(_v3_tmp, this.halfExtents, this.orientation); @@ -225,14 +227,15 @@ export class OBB { } /** + * @en * Transform this shape * @zh * 将 out 根据这个 obb 的数据进行变换。 - * @param m 变换的矩阵。 - * @param pos 变换的位置部分。 - * @param rot 变换的旋转部分。 - * @param scale 变换的缩放部分。 - * @param out 变换的目标。 + * @param m @zh 变换的矩阵。 @en The transform matrix + * @param pos @zh 变换的位置部分。 @en 3d-vector translation. + * @param rot @zh 变换的旋转部分。 @en Quaternion rotation. + * @param scale @zh 变换的缩放部分。 @en 3d-vector scale. + * @param out @zh 变换的目标。 @en The output OBB. */ public transform (m: Mat4, pos: Vec3, rot: Quat, scale: Vec3, out: OBB) { Vec3.transformMat4(out.center, this.center, m); @@ -242,11 +245,13 @@ export class OBB { } /** + * @en + * Transform by matrix and rotation. * @zh * 将 out 根据这个 obb 的数据进行变换。 - * @param m 变换的矩阵。 - * @param rot 变换的旋转部分。 - * @param out 变换的目标。 + * @param m @zh 变换的矩阵。 @en The transform matrix. + * @param rot @zh 变换的旋转部分。 @en Quaternion rotation. + * @param out @zh 变换的目标。 @en The output OBB. */ public translateAndRotate (m: Mat4, rot: Quat, out: OBB) { Vec3.transformMat4(out.center, this.center, m); @@ -255,10 +260,12 @@ export class OBB { } /** + * @en + * Scale OBB by a 3d-vector. * @zh * 将 out 根据这个 obb 的数据进行缩放。 - * @param scale 缩放值。 - * @param out 缩放的目标。 + * @param scale @zh 缩放值。 @en 3d-vector scale. + * @param out @zh 缩放的目标。 @en The output OBB. */ public setScale (scale: Vec3, out: OBB) { Vec3.multiply(out.halfExtents, this.halfExtents, scale); diff --git a/cocos/core/geometry/plane.ts b/cocos/core/geometry/plane.ts index c506dad59d..31ed2299a4 100644 --- a/cocos/core/geometry/plane.ts +++ b/cocos/core/geometry/plane.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module geometry - */ - import { Mat4, Vec3, Vec4 } from '../math'; import enums from './enums'; import { legacyCC } from '../global-exports'; @@ -50,10 +45,10 @@ export class Plane { * create a new plane * @zh * 创建一个新的 plane。 - * @param nx 法向分量的 x 部分。 - * @param ny 法向分量的 y 部分。 - * @param nz 法向分量的 z 部分。 - * @param d 与原点的距离。 + * @param nx @en The x component of normal vector. @zh 法向分量的 x 部分。 + * @param ny @en The y component of normal vector. @zh 法向分量的 y 部分。 + * @param nz @en The z component of normal vector. @zh 法向分量的 z 部分。 + * @param d @en The distance between normal vector and the origin. @zh 与原点的距离。 * @return */ public static create (nx: number, ny: number, nz: number, d: number) { @@ -65,8 +60,8 @@ export class Plane { * clone a new plane * @zh * 克隆一个新的 plane。 - * @param p 克隆的来源。 - * @return 克隆出的对象。 + * @param p @en The Plane object to be cloned from. @zh 克隆的来源。 + * @return @en Cloned objects @zh 克隆出的对象。 */ public static clone (p: Plane) { return new Plane(p.n.x, p.n.y, p.n.z, p.d); @@ -77,9 +72,9 @@ export class Plane { * copy the values from one plane to another * @zh * 复制一个平面的值到另一个。 - * @param out 接受操作的对象。 - * @param p 复制的来源。 - * @return 接受操作的对象。 + * @param out @en The object to be operated on. @zh 接受操作的对象。 + * @param p @en The source of replication. @zh 复制的来源。 + * @return @en The object to be operated on. @zh 接受操作的对象。 */ public static copy (out: Plane, p: Plane) { Vec3.copy(out.n, p.n); @@ -93,11 +88,11 @@ export class Plane { * create a plane from three points * @zh * 用三个点创建一个平面。 - * @param out 接受操作的对象。 - * @param a 点 a。 - * @param b 点 b。 - * @param c 点 c。 - * @return out 接受操作的对象。 + * @param out @en The object to be operated on. @zh 接受操作的对象。 + * @param a @en Point a. @zh 点 a。 + * @param b @en Point b. @zh 点 b。 + * @param c @en Point c. @zh 点 c。 + * @return out @en The object to be operated on. @zh 接受操作的对象。 */ public static fromPoints (out: Plane, a: Vec3, b: Vec3, c: Vec3) { Vec3.subtract(v1, b, a); @@ -114,12 +109,12 @@ export class Plane { * Set the components of a plane to the given values * @zh * 将给定平面的属性设置为给定值。 - * @param out 接受操作的对象。 - * @param nx 法向分量的 x 部分。 - * @param ny 法向分量的 y 部分。 - * @param nz 法向分量的 z 部分。 - * @param d 与原点的距离。 - * @return out 接受操作的对象。 + * @param out @en The object to be operated on. @zh 接受操作的对象。 + * @param nx @en The x component of normal vector. @zh 法向分量的 x 部分。 + * @param ny @en The y component of normal vector. @zh 法向分量的 y 部分。 + * @param nz @en The z component of normal vector. @zh 法向分量的 z 部分。 + * @param d @en The distance between normal vector and the origin. @zh 与原点的距离。 + * @return out @en The object to be operated on. @zh 接受操作的对象。 */ public static set (out: Plane, nx: number, ny: number, nz: number, d: number) { out.n.x = nx; @@ -135,10 +130,10 @@ export class Plane { * create plane from normal and point * @zh * 用一条法线和一个点创建平面。 - * @param out 接受操作的对象。 - * @param normal 平面的法线。 - * @param point 平面上的一点。 - * @return out 接受操作的对象。 + * @param out @en The object to be operated on. @zh 接受操作的对象。 + * @param normal @en Normal of the plane. @zh 平面的法线。 + * @param point @en A point in the plane. @zh 平面上的一点。 + * @return out @en The object to be operated on. @zh 接受操作的对象。 */ public static fromNormalAndPoint (out: Plane, normal: Vec3, point: Vec3) { Vec3.copy(out.n, normal); @@ -152,9 +147,9 @@ export class Plane { * normalize a plane * @zh * 归一化一个平面。 - * @param out 接受操作的对象。 - * @param a 操作的源数据。 - * @return out 接受操作的对象。 + * @param out @en The object to be operated on. @zh 接受操作的对象。 + * @param a @en Source data for the operation. @zh 操作的源数据。 + * @return out @en The object to be operated on. @zh 接受操作的对象。 */ public static normalize (out: Plane, a: Plane) { const len = a.n.length(); @@ -208,10 +203,10 @@ export class Plane { * Construct a plane. * @zh * 构造一个平面。 - * @param nx 法向分量的 x 部分。 - * @param ny 法向分量的 y 部分。 - * @param nz 法向分量的 z 部分。 - * @param d 与原点的距离。 + * @param nx @en The x component of normal vector. @zh 法向分量的 x 部分。 + * @param ny @en The y component of normal vector. @zh 法向分量的 y 部分。 + * @param nz @en The z component of normal vector. @zh 法向分量的 z 部分。 + * @param d @en The distance between normal vector and the origin. @zh 与原点的距离。 */ constructor (nx = 0, ny = 1, nz = 0, d = 0) { this._type = enums.SHAPE_PLANE; diff --git a/cocos/core/geometry/ray.ts b/cocos/core/geometry/ray.ts index 7c5c3fac39..65de5c49be 100644 --- a/cocos/core/geometry/ray.ts +++ b/cocos/core/geometry/ray.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module geometry - */ - import { Vec3 } from '../math'; import enums from './enums'; import { IVec3Like } from '../math/type-define'; @@ -45,13 +40,13 @@ export class Ray { * create a new ray * @zh * 创建一条射线。 - * @param {number} ox 起点的 x 部分。 - * @param {number} oy 起点的 y 部分。 - * @param {number} oz 起点的 z 部分。 - * @param {number} dx 方向的 x 部分。 - * @param {number} dy 方向的 y 部分。 - * @param {number} dz 方向的 z 部分。 - * @return {Ray} 射线。 + * @param {number} ox @en x component of start point @zh 起点的 x 部分。 + * @param {number} oy @en y component of start point @zh 起点的 y 部分。 + * @param {number} oz @en z component of start point @zh 起点的 z 部分。 + * @param {number} dx @en Point in the x direction @zh 方向的 x 部分。 + * @param {number} dy @en Point in the y direction @zh 方向的 y 部分。 + * @param {number} dz @en Point in the z direction @zh 方向的 z 部分。 + * @return {Ray} @en Ray object @zh 射线。 */ public static create (ox = 0, oy = 0, oz = 0, dx = 0, dy = 0, dz = 1): Ray { return new Ray(ox, oy, oz, dx, dy, dz); @@ -62,8 +57,8 @@ export class Ray { * Creates a new ray initialized with values from an existing ray * @zh * 从一条射线克隆出一条新的射线。 - * @param {Ray} a 克隆的目标。 - * @return {Ray} 克隆出的新对象。 + * @param {Ray} a @en The Ray object to be cloned from @zh 克隆的目标。 + * @return {Ray} @en Clone new ray object @zh 克隆出的新对象。 */ public static clone (a: Ray): Ray { return new Ray( @@ -77,9 +72,9 @@ export class Ray { * Copy the values from one ray to another * @zh * 将从一个 ray 的值复制到另一个 ray。 - * @param {Ray} out 接受操作的 ray。 - * @param {Ray} a 被复制的 ray。 - * @return {Ray} out 接受操作的 ray。 + * @param {Ray} out @en The ray object to be modified @zh 接受操作的 ray。 + * @param {Ray} a @en The copied ray object @zh 被复制的 ray。 + * @return {Ray} @en Ray object @zh out 接受操作的 ray。 */ public static copy (out: Ray, a: Ray): Ray { Vec3.copy(out.o, a.o); @@ -93,10 +88,10 @@ export class Ray { * create a ray from two points * @zh * 用两个点创建一条射线。 - * @param {Ray} out 接受操作的射线。 - * @param {Vec3} origin 射线的起点。 - * @param {Vec3} target 射线上的一点。 - * @return {Ray} out 接受操作的射线。 + * @param {Ray} out @en The ray object to be modified @zh 接受操作的射线。 + * @param {Vec3} origin @en Starting point of the ray @zh 射线的起点。 + * @param {Vec3} target @en point on the ray @zh 射线上的一点。 + * @return {Ray} @en Ray object @zh out 接受操作的射线。 */ public static fromPoints (out: Ray, origin: Vec3, target: Vec3): Ray { Vec3.copy(out.o, origin); @@ -109,14 +104,14 @@ export class Ray { * Set the components of a ray to the given values * @zh * 将给定射线的属性设置为给定的值。 - * @param {Ray} out 接受操作的射线。 - * @param {number} ox 起点的 x 部分。 - * @param {number} oy 起点的 y 部分。 - * @param {number} oz 起点的 z 部分。 - * @param {number} dx 方向的 x 部分。 - * @param {number} dy 方向的 y 部分。 - * @param {number} dz 方向的 z 部分。 - * @return {Ray} out 接受操作的射线。 + * @param {Ray} out @en The ray object to be modified @zh 接受操作的射线。 + * @param {number} ox @en x component of start point @zh 起点的 x 部分。 + * @param {number} oy @en y component of start point @zh 起点的 y 部分。 + * @param {number} oz @en z component of start point @zh 起点的 z 部分。 + * @param {number} dx @en Point in the x direction @zh 方向的 x 部分。 + * @param {number} dy @en Point in the y direction @zh 方向的 y 部分。 + * @param {number} dz @en Point in the z direction @zh 方向的 z 部分。 + * @return {Ray} @en Ray object @zh out 接受操作的射线。 */ public static set (out: Ray, ox: number, oy: number, oz: number, dx: number, dy: number, dz: number): Ray { out.o.x = ox; @@ -162,12 +157,12 @@ export class Ray { * Construct a ray; * @zh * 构造一条射线。 - * @param {number} ox 起点的 x 部分。 - * @param {number} oy 起点的 y 部分。 - * @param {number} oz 起点的 z 部分。 - * @param {number} dx 方向的 x 部分。 - * @param {number} dy 方向的 y 部分。 - * @param {number} dz 方向的 z 部分。 + * @param {number} ox @en x component of start point @zh 起点的 x 部分。 + * @param {number} oy @en y component of start point @zh 起点的 y 部分。 + * @param {number} oz @en z component of start point @zh 起点的 z 部分。 + * @param {number} dx @en Point in the x direction @zh 方向的 x 部分。 + * @param {number} dy @en Point in the y direction @zh 方向的 y 部分。 + * @param {number} dz @en Point in the z direction @zh 方向的 z 部分。 */ constructor (ox = 0, oy = 0, oz = 0, dx = 0, dy = 0, dz = -1) { @@ -181,8 +176,8 @@ export class Ray { * Compute a point with the distance between the origin. * @zh * 根据给定距离计算出射线上的一点。 - * @param out 射线上的另一点。 - * @param distance 给定距离。 + * @param out @en Another point on the ray @zh 射线上的另一点。 + * @param distance @en Given distance @zh 给定距离。 */ public computeHit (out: IVec3Like, distance: number) { Vec3.normalize(out, this.d); diff --git a/cocos/core/geometry/spec.ts b/cocos/core/geometry/spec.ts index df68bcdb66..4d8e526d3c 100644 --- a/cocos/core/geometry/spec.ts +++ b/cocos/core/geometry/spec.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module geometry - */ - /** * @en * The raycast mode. diff --git a/cocos/core/geometry/sphere.ts b/cocos/core/geometry/sphere.ts index f056d2baa8..923ef493a4 100644 --- a/cocos/core/geometry/sphere.ts +++ b/cocos/core/geometry/sphere.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module geometry - */ - import { Mat4, Quat, Vec3 } from '../math'; import enums from './enums'; import { AABB } from './aabb'; @@ -51,11 +46,11 @@ export class Sphere { * create a new sphere * @zh * 创建一个新的 sphere 实例。 - * @param cx 形状的相对于原点的 X 坐标。 - * @param cy 形状的相对于原点的 Y 坐标。 - * @param cz 形状的相对于原点的 Z 坐标。 - * @param r 球体的半径 - * @return {Sphere} 返回一个 sphere。 + * @param cx @en X-Coordinate of center point relative to the origin. @zh 中心点的相对于原点的 X 坐标。 + * @param cy @en Y-Coordinate of center point relative to the origin. @zh 中心点的相对于原点的 Y 坐标。 + * @param cz @en Z-Coordinate of center point relative to the origin. @zh 中心点的相对于原点的 Z 坐标。 + * @param r @en Radius of the sphere. @zh 球体的半径 + * @return @en return a new sphere. @zh 返回一个 sphere。 */ public static create (cx: number, cy: number, cz: number, r: number): Sphere { return new Sphere(cx, cy, cz, r); @@ -66,8 +61,8 @@ export class Sphere { * clone a new sphere * @zh * 克隆一个新的 sphere 实例。 - * @param {Sphere} p 克隆的目标。 - * @return {Sphere} 克隆出的示例。 + * @param p @en The sphere object to clone from. @zh 克隆的目标。 + * @return @en The sphere object to clone to. @zh 克隆出的示例。 */ public static clone (p: Sphere): Sphere { return new Sphere(p.center.x, p.center.y, p.center.z, p.radius); @@ -78,9 +73,9 @@ export class Sphere { * copy the values from one sphere to another * @zh * 将从一个 sphere 的值复制到另一个 sphere。 - * @param {Sphere} out 接受操作的 sphere。 - * @param {Sphere} a 被复制的 sphere。 - * @return {Sphere} out 接受操作的 sphere。 + * @param out @en The sphere object to copy to. @zh 接受操作的 sphere。 + * @param a @en The sphere object to copy from. @zh 被复制的 sphere。 + * @return @en The sphere object to copy to. @zh 接受操作的 sphere。 */ public static copy (out: Sphere, p: Sphere): Sphere { Vec3.copy(out.center, p.center); @@ -94,10 +89,10 @@ export class Sphere { * create a new bounding sphere from two corner points * @zh * 从两个点创建一个新的 sphere。 - * @param out - 接受操作的 sphere。 - * @param minPos - sphere 的最小点。 - * @param maxPos - sphere 的最大点。 - * @returns {Sphere} out 接受操作的 sphere。 + * @param out - @en Sphere created from points. @zh 接受操作的 sphere。 + * @param minPos - @en Lower point of the sphere. @zh sphere 的较小点。 + * @param maxPos - @en Upper point of the sphere. @zh sphere 的较大点。 + * @returns @en The output sphere object to save the created sphere data. @zh 接受操作的 sphere。 */ public static fromPoints (out: Sphere, minPos: Vec3, maxPos: Vec3): Sphere { Vec3.multiplyScalar(out.center, Vec3.add(_v3_tmp, minPos, maxPos), 0.5); @@ -110,12 +105,12 @@ export class Sphere { * Set the components of a sphere to the given values * @zh * 将球体的属性设置为给定的值。 - * @param {Sphere} out 接受操作的 sphere。 - * @param cx 形状的相对于原点的 X 坐标。 - * @param cy 形状的相对于原点的 Y 坐标。 - * @param cz 形状的相对于原点的 Z 坐标。 - * @param {number} r 半径。 - * @return {Sphere} out 接受操作的 sphere。 + * @param out @en The sphere to set properties to. @zh 接受操作的 sphere。 + * @param cx @en X-Coordinate of center point relative to the origin. @zh 中心点的相对于原点的 X 坐标。 + * @param cy @en Y-Coordinate of center point relative to the origin. @zh 中心点的相对于原点的 Y 坐标。 + * @param cz @en Z-Coordinate of center point relative to the origin. @zh 中心点的相对于原点的 Z 坐标。 + * @param r @en Radius of the sphere. @zh 半径。 + * @return @en Sphere which the properties will be set to. @zh 接受操作的 sphere。 * @function */ public static set (out: Sphere, cx: number, cy: number, cz: number, r: number): Sphere { @@ -134,11 +129,11 @@ export class Sphere { * 本地坐标的中心点。 */ protected _center: Vec3 = new Vec3(0, 0, 0); - get center () : Vec3 { + get center (): Vec3 { return this._center; } - set center (val:Vec3) { + set center (val: Vec3) { this._center = val; } @@ -150,7 +145,7 @@ export class Sphere { * @zh * 半径。 */ - get radius () : number { + get radius (): number { return this._radius; } @@ -175,10 +170,10 @@ export class Sphere { * Construct a sphere. * @zh * 构造一个球。 - * @param cx 该球的世界坐标的 X 坐标。 - * @param cy 该球的世界坐标的 Y 坐标。 - * @param cz 该球的世界坐标的 Z 坐标。 - * @param {number} r 半径。 + * @param cx @en The X-Coordinate of the sphere. @zh 该球的世界坐标的 X 坐标。 + * @param cy @en The Y-Coordinate of the sphere. @zh 该球的世界坐标的 Y 坐标。 + * @param cz @en The Z-Coordinate of the sphere. @zh 该球的世界坐标的 Z 坐标。 + * @param r @en The radius. @zh 半径。 */ constructor (cx = 0, cy = 0, cz = 0, r = 1) { this._type = enums.SHAPE_SPHERE; @@ -204,7 +199,7 @@ export class Sphere { * Copy a sphere. * @zh * 拷贝对象。 - * @param a 拷贝的目标。 + * @param a @en The sphere to copy from. @zh 拷贝的目标。 */ public copy (a: Sphere) { return Sphere.copy(this, a); @@ -215,8 +210,8 @@ export class Sphere { * Get the bounding points of this shape * @zh * 获取此形状的边界点。 - * @param {Vec3} minPos 最小点。 - * @param {Vec3} maxPos 最大点。 + * @param minPos @en The point with maximum coordinates of the sphere. @zh 最小点。 + * @param maxPos @en The point with minimum coordinates of the sphere. @zh 最大点。 */ public getBoundary (minPos: Vec3, maxPos: Vec3) { Vec3.set(minPos, this.center.x - this.radius, this.center.y - this.radius, this.center.z - this.radius); @@ -228,11 +223,11 @@ export class Sphere { * Transform this shape * @zh * 将 out 根据这个 sphere 的数据进行变换。 - * @param m 变换的矩阵。 - * @param pos 变换的位置部分。 - * @param rot 变换的旋转部分。 - * @param scale 变换的缩放部分。 - * @param out 变换的目标。 + * @param m @en The transform matrix. @zh 变换的矩阵。 + * @param pos @en The position. @zh 变换的位置部分。 + * @param rot @en The rotation. @zh 变换的旋转部分。 + * @param scale @en The scale. @zh 变换的缩放部分。 + * @param out @en The sphere which the transform will be applied to. @zh 变换的目标。 */ public transform (m: Mat4, pos: Vec3, rot: Quat, scale: Vec3, out: Sphere) { Vec3.transformMat4(out.center, this.center, m); @@ -244,9 +239,9 @@ export class Sphere { * Translate and rotate this sphere. * @zh * 将 out 根据这个 sphere 的数据进行变换。 - * @param m 变换的矩阵。 - * @param rot 变换的旋转部分。 - * @param out 变换的目标。 + * @param m @en The transform matrix. @zh 变换的矩阵。 + * @param rot @en The rotation. @zh 变换的旋转部分。 + * @param out @en The sphere which the transform will be applied to. @zh 变换的目标。 */ public translateAndRotate (m: Mat4, rot: Quat, out: Sphere) { Vec3.transformMat4(out.center, this.center, m); @@ -257,17 +252,17 @@ export class Sphere { * Scaling this sphere. * @zh * 将 out 根据这个 sphere 的数据进行缩放。 - * @param scale 缩放值。 - * @param out 缩放的目标。 + * @param scale @en The scale. @zh 缩放值。 + * @param out @en The sphere which the scale will be applied to. @zh 缩放的目标。 */ public setScale (scale: Vec3, out: Sphere) { out.radius = this.radius * maxComponent(scale); } /** - * @en Sphere and point merge. + * @en The point to be merged. * @zh 球跟点合并 - * @param point 点 + * @param point @en The point to be merged. @zh 点 */ public mergePoint (point: Vec3) { // if sphere.radius Less than 0, @@ -290,9 +285,9 @@ export class Sphere { } /** - * @en Sphere and points merge. + * @en The sphere and points to be merged. * @zh 球跟一系列点合并 - * @param points 一系列点 + * @param points @en The point to be merged. @zh 一系列点 */ public mergePoints (points: Vec3[]) { const length = points.length; @@ -307,9 +302,9 @@ export class Sphere { } /** - * @en Sphere and AABB merge. + * @en The axis-aligned bounding box to be merged. * @zh 球跟立方体合并 - * @param a 立方体 + * @param a @en Cube. @zh 立方体 */ public mergeAABB (a: AABB) { a.getBoundary(_min, _max); diff --git a/cocos/core/geometry/triangle.ts b/cocos/core/geometry/triangle.ts index 6cc942545f..1bd73c1620 100644 --- a/cocos/core/geometry/triangle.ts +++ b/cocos/core/geometry/triangle.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module geometry - */ - import { Vec3 } from '../math'; import enums from './enums'; @@ -44,16 +39,16 @@ export class Triangle { * create a new triangle * @zh * 创建一个新的 triangle。 - * @param {number} ax a 点的 x 部分。 - * @param {number} ay a 点的 y 部分。 - * @param {number} az a 点的 z 部分。 - * @param {number} bx b 点的 x 部分。 - * @param {number} by b 点的 y 部分。 - * @param {number} bz b 点的 z 部分。 - * @param {number} cx c 点的 x 部分。 - * @param {number} cy c 点的 y 部分。 - * @param {number} cz c 点的 z 部分。 - * @return {Triangle} 一个新的 triangle。 + * @param {number} ax @en x component of point a @zh a 点的 x 部分。 + * @param {number} ay @en y component of point a @zh a 点的 y 部分。 + * @param {number} az @en z component of point a @zh a 点的 z 部分。 + * @param {number} bx @en x component of point b @zh b 点的 x 部分。 + * @param {number} by @en y component of point b @zh b 点的 y 部分。 + * @param {number} bz @en z component of point b @zh b 点的 z 部分。 + * @param {number} cx @en x component of point c @zh c 点的 x 部分。 + * @param {number} cy @en y component of point c @zh c 点的 y 部分。 + * @param {number} cz @en z component of point c @zh c 点的 z 部分。 + * @return {Triangle} @en A new triangle. @zh 一个新的 triangle。 */ public static create (ax = 1, ay = 0, az = 0, bx = 0, by = 0, bz = 0, @@ -66,8 +61,8 @@ export class Triangle { * clone a new triangle * @zh * 克隆一个新的 triangle。 - * @param {Triangle} t 克隆的目标。 - * @return {Triangle} 克隆出的新对象。 + * @param {Triangle} @en Triangle object to be cloned from. @zh t 克隆的目标。 + * @return {Triangle} @en A new cloned Triangle object. @zh 克隆出的新对象。 */ public static clone (t: Triangle): Triangle { return new Triangle( @@ -82,9 +77,9 @@ export class Triangle { * copy the values from one triangle to another * @zh * 将一个 triangle 的值复制到另一个 triangle。 - * @param {Triangle} out 接受操作的 triangle。 - * @param {Triangle} t 被复制的 triangle。 - * @return {Triangle} out 接受操作的 triangle。 + * @param {Triangle} out @en Target Triangle object to be copied to. @zh 接受操作的 triangle。 + * @param {Triangle} t @en A Triangle object to be copied from. @zh 被复制的 triangle。 + * @return {Triangle} @en The same as out. @zh out 接受操作的 triangle。 */ public static copy (out: Triangle, t: Triangle): Triangle { Vec3.copy(out.a, t.a); @@ -99,11 +94,11 @@ export class Triangle { * Create a triangle from three points * @zh * 用三个点创建一个 triangle。 - * @param {Triangle} out 接受操作的 triangle。 - * @param {Vec3} a a 点。 - * @param {Vec3} b b 点。 - * @param {Vec3} c c 点。 - * @return {Triangle} out 接受操作的 triangle。 + * @param {Triangle} out @en The Triangle object to be modified. @zh 接受操作的 triangle。 + * @param {Vec3} a @en The point value to set out.a. @zh a 点。 + * @param {Vec3} b @en The point value to set out.b. @zh b 点。 + * @param {Vec3} c @en The point value to set out.c. @zh c 点。 + * @return {Triangle} @en The same as out. @zh 接受操作的 triangle。 */ public static fromPoints (out: Triangle, a: Vec3, b: Vec3, c: Vec3): Triangle { Vec3.copy(out.a, a); @@ -117,17 +112,17 @@ export class Triangle { * Set the components of a triangle to the given values * @zh * 将给定三角形的属性设置为给定值。 - * @param {Triangle} out 给定的三角形。 - * @param {number} ax a 点的 x 部分。 - * @param {number} ay a 点的 y 部分。 - * @param {number} az a 点的 z 部分。 - * @param {number} bx b 点的 x 部分。 - * @param {number} by b 点的 y 部分。 - * @param {number} bz b 点的 z 部分。 - * @param {number} cx c 点的 x 部分。 - * @param {number} cy c 点的 y 部分。 - * @param {number} cz c 点的 z 部分。 - * @return {Triangle} + * @param {Triangle} out @en The Triangle object to be set. @zh 被修改的三角形。 + * @param {number} ax @en The value to set out.a.x. @zh a 点的 x 部分。 + * @param {number} ay @en The value to set out.a.y. @zh a 点的 y 部分。 + * @param {number} az @en The value to set out.a.z. @zh a 点的 z 部分。 + * @param {number} bx @en The value to set out.b.x. @zh b 点的 x 部分。 + * @param {number} by @en The value to set out.b.y. @zh b 点的 y 部分。 + * @param {number} bz @en The value to set out.b.z. @zh b 点的 z 部分。 + * @param {number} cx @en The value to set out.c.x. @zh c 点的 x 部分。 + * @param {number} cy @en The value to set out.c.y. @zh c 点的 y 部分。 + * @param {number} cz @en The value to set out.c.z. @zh c 点的 z 部分。 + * @return {Triangle} @en The same as out. @zh 传入的 out 对象。 * @function */ public static set (out: Triangle, @@ -190,15 +185,15 @@ export class Triangle { * Construct a triangle. * @zh * 构造一个三角形。 - * @param {number} ax a 点的 x 部分。 - * @param {number} ay a 点的 y 部分。 - * @param {number} az a 点的 z 部分。 - * @param {number} bx b 点的 x 部分。 - * @param {number} by b 点的 y 部分。 - * @param {number} bz b 点的 z 部分。 - * @param {number} cx c 点的 x 部分。 - * @param {number} cy c 点的 y 部分。 - * @param {number} cz c 点的 z 部分。 + * @param {number} ax @en x component of point a. @zh a 点的 x 部分。 + * @param {number} ay @en y component of point a. @zh a 点的 y 部分。 + * @param {number} az @en z component of point a. @zh a 点的 z 部分。 + * @param {number} bx @en x component of point b. @zh b 点的 x 部分。 + * @param {number} by @en y component of point b. @zh b 点的 y 部分。 + * @param {number} bz @en z component of point b. @zh b 点的 z 部分。 + * @param {number} cx @en x component of point c. @zh c 点的 x 部分。 + * @param {number} cy @en y component of point c. @zh c 点的 y 部分。 + * @param {number} cz @en z component of point c. @zh c 点的 z 部分。 */ constructor (ax = 0, ay = 0, az = 0, bx = 1, by = 0, bz = 0, diff --git a/cocos/core/gfx/base/buffer.ts b/cocos/core/gfx/base/buffer.ts index 92f29b93df..683f2cc0dc 100644 --- a/cocos/core/gfx/base/buffer.ts +++ b/cocos/core/gfx/base/buffer.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module gfx - */ - import { BufferFlagBit, BufferFlags, diff --git a/cocos/core/gfx/base/command-buffer.ts b/cocos/core/gfx/base/command-buffer.ts index 2caeb098d9..048f1f5947 100644 --- a/cocos/core/gfx/base/command-buffer.ts +++ b/cocos/core/gfx/base/command-buffer.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module gfx - */ - import { Buffer } from './buffer'; import { DescriptorSet } from './descriptor-set'; import { Framebuffer } from './framebuffer'; diff --git a/cocos/core/gfx/base/define.ts b/cocos/core/gfx/base/define.ts index 78066526e6..a615344959 100644 --- a/cocos/core/gfx/base/define.ts +++ b/cocos/core/gfx/base/define.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module gfx - */ - import { Queue } from './queue'; import { Buffer } from './buffer'; import { Texture } from './texture'; @@ -56,6 +51,10 @@ const deepCopy = (target: T[], source: T[], Ctor: Construct * ========================= !DO NOT CHANGE THE FOLLOWING SECTION MANUALLY! ========================= */ +/** + * @en Graphics object type + * @zh 图形API对象的类型 + */ export enum ObjectType { UNKNOWN, SWAPCHAIN, @@ -953,21 +952,6 @@ export class Color { } } -/** - * For non-vulkan backends, to maintain compatibility and maximize - * descriptor cache-locality, descriptor-set-based binding numbers need - * to be mapped to backend-specific bindings based on maximum limit - * of available descriptor slots in each set. - * - * The GFX layer assumes the binding numbers for each descriptor type inside each set - * are guaranteed to be consecutive, so the mapping procedure is reduced - * to a simple shifting operation. This data structure specifies the - * capacity for each descriptor type in each set. - * - * The `setIndices` field defines the binding ordering between different sets. - * The last set index is treated as the 'flexible set', whose capacity is dynamically - * assigned based on the total available descriptor slots on the runtime device. - */ export class BindingMappingInfo { declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object diff --git a/cocos/core/gfx/base/descriptor-set-layout.ts b/cocos/core/gfx/base/descriptor-set-layout.ts index d7b9c8e819..afd53e3b17 100644 --- a/cocos/core/gfx/base/descriptor-set-layout.ts +++ b/cocos/core/gfx/base/descriptor-set-layout.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module gfx - */ - import { GFXObject, ObjectType, DescriptorSetLayoutBinding, DescriptorSetLayoutInfo } from './define'; /** diff --git a/cocos/core/gfx/base/descriptor-set.ts b/cocos/core/gfx/base/descriptor-set.ts index 909c61f114..2fc14bbd38 100644 --- a/cocos/core/gfx/base/descriptor-set.ts +++ b/cocos/core/gfx/base/descriptor-set.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module gfx - */ - import { Buffer } from './buffer'; import { DescriptorSetLayout } from './descriptor-set-layout'; import { Sampler } from './states/sampler'; diff --git a/cocos/core/gfx/base/device.ts b/cocos/core/gfx/base/device.ts index 3339a0b742..b0c5df6d12 100644 --- a/cocos/core/gfx/base/device.ts +++ b/cocos/core/gfx/base/device.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module gfx - */ - import { API, Feature, MemoryStatus, CommandBufferInfo, BufferInfo, BufferViewInfo, TextureInfo, TextureViewInfo, SamplerInfo, DescriptorSetInfo, diff --git a/cocos/core/gfx/base/framebuffer.ts b/cocos/core/gfx/base/framebuffer.ts index 515b507c18..b5e89ac207 100644 --- a/cocos/core/gfx/base/framebuffer.ts +++ b/cocos/core/gfx/base/framebuffer.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module gfx - */ - import { RenderPass } from './render-pass'; import { Texture } from './texture'; import { GFXObject, ObjectType, FramebufferInfo } from './define'; diff --git a/cocos/core/gfx/base/input-assembler.ts b/cocos/core/gfx/base/input-assembler.ts index f008ab80bd..9f21f956e4 100644 --- a/cocos/core/gfx/base/input-assembler.ts +++ b/cocos/core/gfx/base/input-assembler.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module gfx - */ - import { Buffer } from './buffer'; import { murmurhash2_32_gc } from '../../utils/murmurhash2_gc'; import { Attribute, GFXObject, ObjectType, InputAssemblerInfo, DrawInfo } from './define'; diff --git a/cocos/core/gfx/base/pipeline-layout.ts b/cocos/core/gfx/base/pipeline-layout.ts index 3b6a401d03..413ef52ae3 100644 --- a/cocos/core/gfx/base/pipeline-layout.ts +++ b/cocos/core/gfx/base/pipeline-layout.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module gfx - */ - import { DescriptorSetLayout } from './descriptor-set-layout'; import { GFXObject, ObjectType, PipelineLayoutInfo } from './define'; diff --git a/cocos/core/gfx/base/pipeline-state.ts b/cocos/core/gfx/base/pipeline-state.ts index 39efa296e0..983d0a0e90 100644 --- a/cocos/core/gfx/base/pipeline-state.ts +++ b/cocos/core/gfx/base/pipeline-state.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module gfx - */ - import { PipelineLayout } from './pipeline-layout'; import { RenderPass } from './render-pass'; import { Shader } from './shader'; diff --git a/cocos/core/gfx/base/queue.ts b/cocos/core/gfx/base/queue.ts index d41fcf36e9..c1e1256d8b 100644 --- a/cocos/core/gfx/base/queue.ts +++ b/cocos/core/gfx/base/queue.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module gfx - */ - import { CommandBuffer } from './command-buffer'; import { GFXObject, ObjectType, QueueType, QueueInfo } from './define'; diff --git a/cocos/core/gfx/base/render-pass.ts b/cocos/core/gfx/base/render-pass.ts index 5b23e302cb..ad401ef710 100644 --- a/cocos/core/gfx/base/render-pass.ts +++ b/cocos/core/gfx/base/render-pass.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module gfx - */ - import { murmurhash2_32_gc } from '../../utils/murmurhash2_gc'; import { GFXObject, diff --git a/cocos/core/gfx/base/shader.ts b/cocos/core/gfx/base/shader.ts index 84df250ae6..0367cf74a1 100644 --- a/cocos/core/gfx/base/shader.ts +++ b/cocos/core/gfx/base/shader.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module gfx - */ - import { GFXObject, ObjectType, ShaderInfo, ShaderStage, UniformBlock, UniformSampler, Attribute } from './define'; /** diff --git a/cocos/core/gfx/base/states/general-barrier.ts b/cocos/core/gfx/base/states/general-barrier.ts index 5b6359e096..2fd851bfab 100644 --- a/cocos/core/gfx/base/states/general-barrier.ts +++ b/cocos/core/gfx/base/states/general-barrier.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module gfx - */ - import { murmurhash2_32_gc } from '../../../utils/murmurhash2_gc'; import { GFXObject, ObjectType, GeneralBarrierInfo } from '../define'; diff --git a/cocos/core/gfx/base/states/sampler.ts b/cocos/core/gfx/base/states/sampler.ts index abbaa4f21c..c161170409 100644 --- a/cocos/core/gfx/base/states/sampler.ts +++ b/cocos/core/gfx/base/states/sampler.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module gfx - */ - import { GFXObject, ObjectType, SamplerInfo } from '../define'; /** diff --git a/cocos/core/gfx/base/states/texture-barrier.ts b/cocos/core/gfx/base/states/texture-barrier.ts index 40ef82d234..5cb26157ac 100644 --- a/cocos/core/gfx/base/states/texture-barrier.ts +++ b/cocos/core/gfx/base/states/texture-barrier.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module gfx - */ - import { murmurhash2_32_gc } from '../../../utils/murmurhash2_gc'; import { GFXObject, ObjectType, TextureBarrierInfo } from '../define'; diff --git a/cocos/core/gfx/base/swapchain.ts b/cocos/core/gfx/base/swapchain.ts index 489aa0e6cd..f44f4f46d6 100644 --- a/cocos/core/gfx/base/swapchain.ts +++ b/cocos/core/gfx/base/swapchain.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module gfx - */ - import { GFXObject, ObjectType, SurfaceTransform, SwapchainInfo } from './define'; import { Texture } from './texture'; diff --git a/cocos/core/gfx/base/texture.ts b/cocos/core/gfx/base/texture.ts index 5f05486ecb..aa405017f6 100644 --- a/cocos/core/gfx/base/texture.ts +++ b/cocos/core/gfx/base/texture.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module gfx - */ - import { Format, GFXObject, diff --git a/cocos/core/gfx/deprecated-3.0.0.ts b/cocos/core/gfx/deprecated-3.0.0.ts index 405a9f4939..cc86babf67 100644 --- a/cocos/core/gfx/deprecated-3.0.0.ts +++ b/cocos/core/gfx/deprecated-3.0.0.ts @@ -23,7 +23,6 @@ THE SOFTWARE. */ - import { replaceProperty, removeProperty } from '../utils/x-deprecated'; import { legacyCC } from '../global-exports'; diff --git a/cocos/core/gfx/deprecated-3.5.0.ts b/cocos/core/gfx/deprecated-3.5.0.ts index 5618c55c8a..74e33a4477 100644 --- a/cocos/core/gfx/deprecated-3.5.0.ts +++ b/cocos/core/gfx/deprecated-3.5.0.ts @@ -23,7 +23,6 @@ THE SOFTWARE. */ - import { removeProperty, replaceProperty } from '../utils/x-deprecated'; import { Device } from './base/device'; import { Feature, ColorAttachment, DepthStencilAttachment } from './base/define'; diff --git a/cocos/core/gfx/index.jsb.ts b/cocos/core/gfx/index.jsb.ts index aeb4401513..652173a59a 100644 --- a/cocos/core/gfx/index.jsb.ts +++ b/cocos/core/gfx/index.jsb.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module gfx - */ - declare const gfx: any; import { legacyCC } from '../global-exports'; diff --git a/cocos/core/gfx/index.ts b/cocos/core/gfx/index.ts index d88bdd7ad5..532a74c049 100644 --- a/cocos/core/gfx/index.ts +++ b/cocos/core/gfx/index.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module gfx - */ - import './polyfill-legacy-cc'; import './deprecated-3.0.0'; import './deprecated-3.5.0'; diff --git a/cocos/core/gfx/pipeline-state.jsb.ts b/cocos/core/gfx/pipeline-state.jsb.ts index 8aca575b51..d043262574 100644 --- a/cocos/core/gfx/pipeline-state.jsb.ts +++ b/cocos/core/gfx/pipeline-state.jsb.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module gfx - */ - declare const gfx: any; declare type RecursivePartial = { @@ -554,7 +549,6 @@ function watchArrayElementsField (self: S, list: T[], eleField: string, ca } } - export class BlendState { private targets: BlendTarget[]; private _blendColor: Color; diff --git a/cocos/core/gfx/polyfill-legacy-cc.ts b/cocos/core/gfx/polyfill-legacy-cc.ts index e4485f0b4f..fb011b7339 100644 --- a/cocos/core/gfx/polyfill-legacy-cc.ts +++ b/cocos/core/gfx/polyfill-legacy-cc.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { Buffer } from './base/buffer'; import { CommandBuffer } from './base/command-buffer'; import { Device } from './base/device'; diff --git a/cocos/core/gfx/webgl2/webgl2-device.ts b/cocos/core/gfx/webgl2/webgl2-device.ts index ec51c2985d..e17104b881 100644 --- a/cocos/core/gfx/webgl2/webgl2-device.ts +++ b/cocos/core/gfx/webgl2/webgl2-device.ts @@ -290,8 +290,7 @@ export class WebGL2Device extends Device { this._formatFeatures[Format.RGB16F] = tempFeature; this._formatFeatures[Format.RGBA16F] = tempFeature; - tempFeature = FormatFeatureBit.RENDER_TARGET | FormatFeatureBit.STORAGE_TEXTURE - | FormatFeatureBit.SAMPLED_TEXTURE | FormatFeatureBit.VERTEX_ATTRIBUTE; + tempFeature = FormatFeatureBit.STORAGE_TEXTURE | FormatFeatureBit.SAMPLED_TEXTURE | FormatFeatureBit.VERTEX_ATTRIBUTE; this._formatFeatures[Format.R32F] = tempFeature; this._formatFeatures[Format.RG32F] = tempFeature; @@ -369,6 +368,10 @@ export class WebGL2Device extends Device { this._textureExclusive[Format.DEPTH_STENCIL] = false; if (exts.EXT_color_buffer_float) { + this._formatFeatures[Format.R32F] |= FormatFeatureBit.RENDER_TARGET; + this._formatFeatures[Format.RG32F] |= FormatFeatureBit.RENDER_TARGET; + this._formatFeatures[Format.RGBA32F] |= FormatFeatureBit.RENDER_TARGET; + this._textureExclusive[Format.R32F] = false; this._textureExclusive[Format.RG32F] = false; this._textureExclusive[Format.RGBA32F] = false; diff --git a/cocos/core/global-exports.ts b/cocos/core/global-exports.ts index 2f0b621123..eecc5e93b5 100644 --- a/cocos/core/global-exports.ts +++ b/cocos/core/global-exports.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module core - */ - import { ALIPAY, BAIDU, diff --git a/cocos/core/index.ts b/cocos/core/index.ts index c42480ff17..35469376de 100644 --- a/cocos/core/index.ts +++ b/cocos/core/index.ts @@ -23,10 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/** - * @packageDocumentation - * @module core - */ + import { legacyCC, VERSION } from './global-exports'; import * as geometry from './geometry'; diff --git a/cocos/core/legacy.ts b/cocos/core/legacy.ts index 9813310f6b..756b1aab93 100644 --- a/cocos/core/legacy.ts +++ b/cocos/core/legacy.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import * as debug from './platform/debug'; import { _normalize, basename, changeBasename, changeExtname, dirname, extname, getSeperator, join, mainFileName, stripSep } from './utils/path'; import { legacyCC } from './global-exports'; diff --git a/cocos/core/math/affine-transform.ts b/cocos/core/math/affine-transform.ts index 7f9d03f60f..e810dc1cc0 100644 --- a/cocos/core/math/affine-transform.ts +++ b/cocos/core/math/affine-transform.ts @@ -25,11 +25,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module core/math - */ - import { Mat4 } from './mat4'; import { Rect } from './rect'; import { Size } from './size'; diff --git a/cocos/core/math/bits.ts b/cocos/core/math/bits.ts index 4b76fd9202..4ab94bba59 100644 --- a/cocos/core/math/bits.ts +++ b/cocos/core/math/bits.ts @@ -23,12 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * 数学库 - * @module core/math/bits - */ - /** * Bit twiddling hacks for JavaScript. * @@ -38,9 +32,26 @@ * http://graphics.stanford.edu/~seander/bithacks.html */ -// Number of bits in an integer +/** + * @en + * Number of bits in an integer + * @zh + * 整型类型的 bit 数 + */ export const INT_BITS = 32; +/** + * @en + * The maximal signed integer number + * @zh + * 最大有符号整型数 + */ export const INT_MAX = 0x7fffffff; +/** + * @en + * The minimal signed integer number + * @zh + * 最小有符号整型数 + */ export const INT_MIN = -1 << (INT_BITS - 1); /** @@ -109,8 +120,8 @@ export function log10 (v: number) { } /** - * @zh Counts number of bits. - * @en 计算传入数字二进制表示中 1 的数量。 + * @en Counts number of bits. + * @zh 计算传入数字二进制表示中 1 的数量。 */ export function popCount (v: number) { v -= ((v >>> 1) & 0x55555555); @@ -261,8 +272,8 @@ export function interleave3 (x: number, y: number, z: number) { } /** - * @zh Extracts nth interleaved component of a 3-tuple. - * @en 提取三个数字中的第n个交错分量。 + * @en Extracts nth interleaved component of a 3-tuple. + * @zh 提取三个数字中的第n个交错分量。 */ export function deinterleave3 (v: number, n: number) { v = (v >>> n) & 1227133513; diff --git a/cocos/core/math/color.ts b/cocos/core/math/color.ts index f407263a2a..f1df9fa906 100644 --- a/cocos/core/math/color.ts +++ b/cocos/core/math/color.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module core/math - */ - import { CCClass } from '../data/class'; import { ValueType } from '../value-types/value-type'; import { IColorLike } from './type-define'; diff --git a/cocos/core/math/deprecated.ts b/cocos/core/math/deprecated.ts index 134f6bc58d..55b3bf8a4e 100644 --- a/cocos/core/math/deprecated.ts +++ b/cocos/core/math/deprecated.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { removeProperty, replaceProperty } from '../utils/x-deprecated'; import { Color } from './color'; import { Mat3 } from './mat3'; diff --git a/cocos/core/math/index.ts b/cocos/core/math/index.ts index d2bc048233..0568754fcd 100644 --- a/cocos/core/math/index.ts +++ b/cocos/core/math/index.ts @@ -24,8 +24,6 @@ THE SOFTWARE. */ - - import * as bits from './bits'; import './deprecated'; diff --git a/cocos/core/math/mat3.ts b/cocos/core/math/mat3.ts index 15272aa422..4120097593 100644 --- a/cocos/core/math/mat3.ts +++ b/cocos/core/math/mat3.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module core/math - */ - import { CCClass } from '../data/class'; import { ValueType } from '../value-types/value-type'; import { Quat } from './quat'; diff --git a/cocos/core/math/mat4.ts b/cocos/core/math/mat4.ts index 8a2f46676a..cbeedb1be5 100644 --- a/cocos/core/math/mat4.ts +++ b/cocos/core/math/mat4.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module core/math - */ - import { CCClass } from '../data/class'; import { ValueType } from '../value-types/value-type'; import { Mat3 } from './mat3'; diff --git a/cocos/core/math/quat.ts b/cocos/core/math/quat.ts index d6965d89d3..7595124822 100644 --- a/cocos/core/math/quat.ts +++ b/cocos/core/math/quat.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module core/math - */ - import { CCClass } from '../data/class'; import { ValueType } from '../value-types/value-type'; import { Mat3 } from './mat3'; diff --git a/cocos/core/math/rect.ts b/cocos/core/math/rect.ts index d0749a4f2b..25f20c306a 100644 --- a/cocos/core/math/rect.ts +++ b/cocos/core/math/rect.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module core/math - */ - import { CCClass } from '../data/class'; import { ValueType } from '../value-types/value-type'; import { Mat4 } from './mat4'; @@ -447,7 +442,16 @@ export class Rect extends ValueType { } /** + * @en + * Applies a matrix transformation to the current rectangle and outputs the result to the four vertices. + * @zh * 应用矩阵变换到当前矩形,并将结果输出到四个顶点上。 + * + * @param mat The mat4 to apply + * @param out_lb The left bottom point + * @param out_lt The left top point + * @param out_rb The right bottom point + * @param out_rt The right top point */ public transformMat4ToPoints (mat: Mat4, out_lb: Vec2, out_lt: Vec2, out_rt: Vec2, out_rb: Vec2) { const ol = this.x; diff --git a/cocos/core/math/size.ts b/cocos/core/math/size.ts index 96252a29cf..9e8a88587b 100644 --- a/cocos/core/math/size.ts +++ b/cocos/core/math/size.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module core/math - */ - import { CCClass } from '../data/class'; import { ValueType } from '../value-types/value-type'; import { ISizeLike } from './type-define'; diff --git a/cocos/core/math/type-define.ts b/cocos/core/math/type-define.ts index 9d630682ac..430fcea15a 100644 --- a/cocos/core/math/type-define.ts +++ b/cocos/core/math/type-define.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module core/math - */ - export interface IColorLike { r: number; g: number; diff --git a/cocos/core/math/utils.ts b/cocos/core/math/utils.ts index c3af8a4322..b5fc723ce9 100644 --- a/cocos/core/math/utils.ts +++ b/cocos/core/math/utils.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module core/math - */ - import { ValueType } from '../value-types'; import { IVec3Like } from './type-define'; @@ -146,7 +141,10 @@ export function randomRangeInt (min: number, max: number) { } /** - * Linear congruential generator using Hull-Dobell Theorem. + * @en + * Linear congruence generator using Hull-Dobell Theorem. + * @zh + * 使用 Hull-Dobell 算法的线性同余生成器构造伪随机数 * * @param seed The random seed. * @return The pseudo random. @@ -157,7 +155,10 @@ export function pseudoRandom (seed: number) { } /** + * @en * Returns a floating-point pseudo-random number between min (inclusive) and max (exclusive). + * @zh + * 返回一个在范围内的浮点伪随机数,注意,不包含边界值 * * @param seed * @param min @@ -181,18 +182,21 @@ export function pseudoRandomRangeInt (seed: number, min: number, max: number) { } /** + * @en * Returns the next power of two for the value.
+ * @zh + * 返回下一个最接近的 2 的幂 * * @param val * @return The the next power of two. */ export function nextPow2 (val: number) { --val; - val = (val >> 1) | val; - val = (val >> 2) | val; - val = (val >> 4) | val; - val = (val >> 8) | val; - val = (val >> 16) | val; + val |= (val >> 1); + val |= (val >> 2); + val |= (val >> 4); + val |= (val >> 8); + val |= (val >> 16); ++val; return val; } @@ -209,7 +213,10 @@ export function repeat (t: number, length: number) { } /** + * @en * Returns time wrapped in ping-pong mode. + * @zh + * 返回乒乓模式下的相对时间 * * @param t Time start at 0. * @param length Time of one cycle. @@ -234,9 +241,10 @@ export function inverseLerp (from: number, to: number, value: number) { } /** + * @en Compare the absolute values of all components and the component with the largest absolute value will be returned. * @zh 对所有分量的绝对值进行比较大小,返回绝对值最大的分量。 - * @param v 类 Vec3 结构 - * @returns 绝对值最大的分量 + * @param v vec3 like value + * @returns max absolute component */ export function absMaxComponent (v: IVec3Like) { if (Math.abs(v.x) > Math.abs(v.y)) { @@ -253,6 +261,7 @@ export function absMaxComponent (v: IVec3Like) { } /** + * @en Compare the absolute value of two values and return the value with the largest absolute value * @zh 对 a b 的绝对值进行比较大小,返回绝对值最大的值。 * @param a number * @param b number diff --git a/cocos/core/math/vec2.ts b/cocos/core/math/vec2.ts index b12225da1d..daff1dcde5 100644 --- a/cocos/core/math/vec2.ts +++ b/cocos/core/math/vec2.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module core/math - */ - import { CCClass } from '../data/class'; import { ValueType } from '../value-types/value-type'; import { Mat4 } from './mat4'; diff --git a/cocos/core/math/vec3.ts b/cocos/core/math/vec3.ts index be0af6cbb1..e02b052f99 100644 --- a/cocos/core/math/vec3.ts +++ b/cocos/core/math/vec3.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module core/math - */ - import { CCClass } from '../data/class'; import { ValueType } from '../value-types/value-type'; import { Mat4 } from './mat4'; diff --git a/cocos/core/math/vec4.ts b/cocos/core/math/vec4.ts index 82d2591971..5023669a68 100644 --- a/cocos/core/math/vec4.ts +++ b/cocos/core/math/vec4.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module core/math - */ - import { CCClass } from '../data/class'; import { ValueType } from '../value-types/value-type'; import { Mat4 } from './mat4'; diff --git a/cocos/core/memop/cached-array.ts b/cocos/core/memop/cached-array.ts index 2409b299da..1bfda8ce54 100644 --- a/cocos/core/memop/cached-array.ts +++ b/cocos/core/memop/cached-array.ts @@ -25,11 +25,6 @@ import { ScalableContainer } from './scalable-container'; -/** - * @packageDocumentation - * @module memop - */ - /** * @en * Cached array is a data structure for objects cache, it's designed for persistent data. diff --git a/cocos/core/memop/index.ts b/cocos/core/memop/index.ts index 0a18e3d10a..95c67962de 100644 --- a/cocos/core/memop/index.ts +++ b/cocos/core/memop/index.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - export * from './pool'; export * from './recycle-pool'; export * from './cached-array'; diff --git a/cocos/core/memop/pool.ts b/cocos/core/memop/pool.ts index 1a8572c06e..3aac1723b5 100644 --- a/cocos/core/memop/pool.ts +++ b/cocos/core/memop/pool.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module memop - */ - import { warnID } from '../platform/debug'; import { ScalableContainer } from './scalable-container'; diff --git a/cocos/core/memop/recycle-pool.ts b/cocos/core/memop/recycle-pool.ts index 85e8643fd0..7ba42726e5 100644 --- a/cocos/core/memop/recycle-pool.ts +++ b/cocos/core/memop/recycle-pool.ts @@ -25,11 +25,6 @@ import { ScalableContainer } from './scalable-container'; -/** - * @packageDocumentation - * @module memop - */ - /** * @en Recyclable object pool. It's designed to be entirely reused each time. * There is no put and get method, each time you get the [[data]], you can use all elements as new. diff --git a/cocos/core/memop/scalable-container.ts b/cocos/core/memop/scalable-container.ts index 1f31daae32..1ddf85db25 100644 --- a/cocos/core/memop/scalable-container.ts +++ b/cocos/core/memop/scalable-container.ts @@ -22,6 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + import { containerManager } from './container-manager'; export abstract class ScalableContainer { diff --git a/cocos/core/pipeline/custom/ubos.ts b/cocos/core/pipeline/custom/ubos.ts index e860dfea76..6955ffd745 100644 --- a/cocos/core/pipeline/custom/ubos.ts +++ b/cocos/core/pipeline/custom/ubos.ts @@ -129,7 +129,8 @@ export class PipelineUBO { cv[UBOCamera.AMBIENT_GROUND_OFFSET + 0] = ambient.groundAlbedo.x; cv[UBOCamera.AMBIENT_GROUND_OFFSET + 1] = ambient.groundAlbedo.y; cv[UBOCamera.AMBIENT_GROUND_OFFSET + 2] = ambient.groundAlbedo.z; - cv[UBOCamera.AMBIENT_GROUND_OFFSET + 3] = ambient.mipmapCount; + const skybox = pipeline.pipelineSceneData.skybox; + cv[UBOCamera.AMBIENT_GROUND_OFFSET + 3] = skybox.envmap ? skybox.envmap?.mipmapLevel : 1.0; Mat4.toArray(cv, camera.matView, UBOCamera.MAT_VIEW_OFFSET); Mat4.toArray(cv, camera.node.worldMatrix, UBOCamera.MAT_VIEW_INV_OFFSET); diff --git a/cocos/core/pipeline/deferred/deferred-pipeline.ts b/cocos/core/pipeline/deferred/deferred-pipeline.ts index dd5f388bd2..1fa9d9e7b9 100644 --- a/cocos/core/pipeline/deferred/deferred-pipeline.ts +++ b/cocos/core/pipeline/deferred/deferred-pipeline.ts @@ -310,12 +310,14 @@ export class DeferredPipeline extends RenderPipeline { data.outputRenderTargets, null, )); + + data.sampler = this.globalDSManager.pointSampler; + // Listens when the attachment texture is scaled this.on(PipelineEventType.ATTACHMENT_SCALE_CAHNGED, (val: number) => { data.sampler = val < 1 ? this.globalDSManager.pointSampler : this.globalDSManager.linearSampler; this.applyFramebufferRatio(data.gbufferFrameBuffer); this.applyFramebufferRatio(data.outputFrameBuffer); }); - data.sampler = this.globalDSManager.linearSampler; } } diff --git a/cocos/core/pipeline/define.ts b/cocos/core/pipeline/define.ts index 72770c2b5a..eec3a112e6 100644 --- a/cocos/core/pipeline/define.ts +++ b/cocos/core/pipeline/define.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module pipeline - */ - import { Pass } from '../renderer/core/pass'; import { Model } from '../renderer/scene/model'; import { SubModel } from '../renderer/scene/submodel'; @@ -290,7 +285,7 @@ globalDescriptorSetLayout.bindings[UBOShadow.BINDING] = UBOShadow.DESCRIPTOR; /** * @en The sampler for Main light shadow map - * @zn 主光源阴影纹理采样器 + * @zh 主光源阴影纹理采样器 */ const UNIFORM_SHADOWMAP_NAME = 'cc_shadowMap'; export const UNIFORM_SHADOWMAP_BINDING = PipelineGlobalBindings.SAMPLER_SHADOWMAP; @@ -315,7 +310,7 @@ globalDescriptorSetLayout.bindings[UNIFORM_DIFFUSEMAP_BINDING] = UNIFORM_DIFFUSE /** * @en The sampler for spot light shadow map - * @zn 聚光灯阴影纹理采样器 + * @zh 聚光灯阴影纹理采样器 */ const UNIFORM_SPOT_LIGHTING_MAP_TEXTURE_NAME = 'cc_spotLightingMap'; export const UNIFORM_SPOT_LIGHTING_MAP_TEXTURE_BINDING = PipelineGlobalBindings.SAMPLER_SPOT_LIGHTING_MAP; diff --git a/cocos/core/pipeline/enum.ts b/cocos/core/pipeline/enum.ts index 67e9c387d6..8526744713 100644 --- a/cocos/core/pipeline/enum.ts +++ b/cocos/core/pipeline/enum.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module pipeline - */ - export enum CommonStagePriority { BLOOM = 18, POST_PROCESS = 19, diff --git a/cocos/core/pipeline/forward/forward-flow.ts b/cocos/core/pipeline/forward/forward-flow.ts index 88099eac42..dd23aea696 100644 --- a/cocos/core/pipeline/forward/forward-flow.ts +++ b/cocos/core/pipeline/forward/forward-flow.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module pipeline - */ - import { ccclass } from 'cc.decorator'; import { PIPELINE_FLOW_FORWARD } from '../define'; import { IRenderFlowInfo, RenderFlow } from '../render-flow'; diff --git a/cocos/core/pipeline/forward/forward-pipeline.ts b/cocos/core/pipeline/forward/forward-pipeline.ts index b91d4e3a7e..8bb0a7c4b0 100644 --- a/cocos/core/pipeline/forward/forward-pipeline.ts +++ b/cocos/core/pipeline/forward/forward-pipeline.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module pipeline - */ - import { ccclass, displayOrder, type, serializable } from 'cc.decorator'; import { EDITOR } from 'internal:constants'; import { RenderPipeline, IRenderPipelineInfo } from '../render-pipeline'; diff --git a/cocos/core/pipeline/forward/forward-stage.ts b/cocos/core/pipeline/forward/forward-stage.ts index 21378e038d..bfb0c5b3a2 100644 --- a/cocos/core/pipeline/forward/forward-stage.ts +++ b/cocos/core/pipeline/forward/forward-stage.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module pipeline - */ - import { ccclass, displayOrder, type, serializable } from 'cc.decorator'; import { SetIndex } from '../define'; import { getPhaseID } from '../pass-phase'; diff --git a/cocos/core/pipeline/global-descriptor-set-manager.ts b/cocos/core/pipeline/global-descriptor-set-manager.ts index 4859a72da1..75dc67bb2f 100644 --- a/cocos/core/pipeline/global-descriptor-set-manager.ts +++ b/cocos/core/pipeline/global-descriptor-set-manager.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module pipeline - */ - import { Device, BufferUsageBit, MemoryUsageBit, BufferInfo, Filter, Address, Sampler, DescriptorSet, DescriptorSetInfo, Buffer, Texture, DescriptorSetLayoutInfo, DescriptorSetLayout, SamplerInfo } from '../gfx'; import { UBOShadow, globalDescriptorSetLayout, PipelineGlobalBindings } from './define'; diff --git a/cocos/core/pipeline/index.ts b/cocos/core/pipeline/index.ts index 6ee314435f..e2d405cc60 100644 --- a/cocos/core/pipeline/index.ts +++ b/cocos/core/pipeline/index.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module pipeline - */ - import * as pipeline from './define'; import { ForwardPipeline } from './forward/forward-pipeline'; diff --git a/cocos/core/pipeline/instanced-buffer.ts b/cocos/core/pipeline/instanced-buffer.ts index 6501086b95..a238225418 100644 --- a/cocos/core/pipeline/instanced-buffer.ts +++ b/cocos/core/pipeline/instanced-buffer.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { Pass } from '../renderer'; import { IInstancedAttributeBlock, SubModel } from '../renderer/scene'; import { UNIFORM_LIGHTMAP_TEXTURE_BINDING } from './define'; diff --git a/cocos/core/pipeline/pass-phase.ts b/cocos/core/pipeline/pass-phase.ts index 4b0c06c044..3ff6f54157 100644 --- a/cocos/core/pipeline/pass-phase.ts +++ b/cocos/core/pipeline/pass-phase.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - export const getPhaseID = (() => { const phases: Map = new Map(); let phaseNum = 0; diff --git a/cocos/core/pipeline/pipeline-funcs.ts b/cocos/core/pipeline/pipeline-funcs.ts index 4079859d59..2fecd03de5 100644 --- a/cocos/core/pipeline/pipeline-funcs.ts +++ b/cocos/core/pipeline/pipeline-funcs.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module pipeline - */ - import { CommandBuffer, Device, Rect, RenderPass, Swapchain, Viewport } from '../gfx'; import { IVec4Like } from '../math'; import { PipelineStateManager } from './pipeline-state-manager'; diff --git a/cocos/core/pipeline/pipeline-serialization.ts b/cocos/core/pipeline/pipeline-serialization.ts index 1401f5e3d0..ee87e3fb13 100644 --- a/cocos/core/pipeline/pipeline-serialization.ts +++ b/cocos/core/pipeline/pipeline-serialization.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module pipeline - */ - import { ccclass, type, serializable, editable } from 'cc.decorator'; import { CCString } from '../data/utils/attribute'; import { AccessFlagBit, Format, LoadOp, StoreOp, TextureType, TextureUsageBit } from '../gfx'; diff --git a/cocos/core/pipeline/pipeline-state-manager.ts b/cocos/core/pipeline/pipeline-state-manager.ts index 4f1e8072e3..030cdab8b1 100644 --- a/cocos/core/pipeline/pipeline-state-manager.ts +++ b/cocos/core/pipeline/pipeline-state-manager.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { Shader, RenderPass, InputAssembler, Device, PipelineState, InputState, PipelineStateInfo } from '../gfx'; import { Pass } from '../renderer/core/pass'; diff --git a/cocos/core/pipeline/pipeline-ubo.ts b/cocos/core/pipeline/pipeline-ubo.ts index 525b0b58e0..5839f8aa25 100644 --- a/cocos/core/pipeline/pipeline-ubo.ts +++ b/cocos/core/pipeline/pipeline-ubo.ts @@ -75,6 +75,7 @@ export class PipelineUBO { const mainLight = scene.mainLight; const sceneData = pipeline.pipelineSceneData; const ambient = sceneData.ambient; + const skybox = sceneData.skybox; const fog = sceneData.fog; const shadowInfo = sceneData.shadows; const cv = bufferView; @@ -129,7 +130,7 @@ export class PipelineUBO { cv[UBOCamera.AMBIENT_GROUND_OFFSET + 0] = ambient.groundAlbedo.x; cv[UBOCamera.AMBIENT_GROUND_OFFSET + 1] = ambient.groundAlbedo.y; cv[UBOCamera.AMBIENT_GROUND_OFFSET + 2] = ambient.groundAlbedo.z; - cv[UBOCamera.AMBIENT_GROUND_OFFSET + 3] = ambient.mipmapCount; + cv[UBOCamera.AMBIENT_GROUND_OFFSET + 3] = skybox.envmap ? skybox.envmap?.mipmapLevel : 1.0; Mat4.toArray(cv, camera.matView, UBOCamera.MAT_VIEW_OFFSET); Mat4.toArray(cv, camera.node.worldMatrix, UBOCamera.MAT_VIEW_INV_OFFSET); @@ -174,7 +175,7 @@ export class PipelineUBO { const sv = bufferView; if (shadowInfo.enabled) { - if (mainLight && shadowInfo.type === ShadowType.ShadowMap) { + if (mainLight && mainLight.shadowEnabled && shadowInfo.type === ShadowType.ShadowMap) { let near = 0.1; let far = 0; const matShadowView = shadowInfo.matShadowView; @@ -278,7 +279,7 @@ export class PipelineUBO { Mat4.invert(_matShadowView, (light as any).node.getWorldMatrix()); Mat4.toArray(sv, _matShadowView, UBOShadow.MAT_LIGHT_VIEW_OFFSET); - Mat4.perspective(_matShadowProj, (light as any).angle, (light as any).aspect, 0.001, (light as any).range); + Mat4.perspective(_matShadowProj, (light as any).angle, 1.0, 0.001, (light as any).range); Mat4.multiply(_matShadowViewProj, _matShadowProj, _matShadowView); Mat4.toArray(sv, _matShadowViewProj, UBOShadow.MAT_LIGHT_VIEW_PROJ_OFFSET); diff --git a/cocos/core/pipeline/render-additive-light-queue.ts b/cocos/core/pipeline/render-additive-light-queue.ts index ae398e8060..cbadd92d20 100644 --- a/cocos/core/pipeline/render-additive-light-queue.ts +++ b/cocos/core/pipeline/render-additive-light-queue.ts @@ -23,10 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module pipeline - */ import { BatchingSchemes, Pass } from '../renderer/core/pass'; import { RenderPipeline } from './render-pipeline'; import { Model } from '../renderer/scene/model'; @@ -205,10 +201,14 @@ export class RenderAdditiveLightQueue { } public recordCommandBuffer (device: Device, renderPass: RenderPass, cmdBuff: CommandBuffer) { - this._instancedQueue.recordCommandBuffer(device, renderPass, cmdBuff); - this._batchedQueue.recordCommandBuffer(device, renderPass, cmdBuff); - const globalDSManager: GlobalDSManager = this._pipeline.globalDSManager; + for (let i = 0; i < _lightIndices.length; i++) { + const light = _lightIndices[i]; + const descriptorSet = globalDSManager.getOrCreateDescriptorSet(light); + this._instancedQueue.recordCommandBuffer(device, renderPass, cmdBuff, descriptorSet); + this._batchedQueue.recordCommandBuffer(device, renderPass, cmdBuff, descriptorSet); + } + for (let i = 0; i < this._lightPasses.length; i++) { const { subModel, passIdx, dynamicOffsets, lights } = this._lightPasses[i]; const pass = subModel.passes[passIdx]; @@ -339,7 +339,7 @@ export class RenderAdditiveLightQueue { Mat4.invert(_matShadowView, (light as SpotLight).node!.getWorldMatrix()); // light proj - Mat4.perspective(_matShadowViewProj, (light as SpotLight).angle, (light as SpotLight).aspect, 0.001, (light as SpotLight).range); + Mat4.perspective(_matShadowViewProj, (light as SpotLight).angle, 1.0, 0.001, (light as SpotLight).range); matShadowProj = _matShadowViewProj.clone(); matShadowInvProj = _matShadowViewProj.clone().invert(); diff --git a/cocos/core/pipeline/render-batched-queue.ts b/cocos/core/pipeline/render-batched-queue.ts index ec74f25ee6..fb5a08ce16 100644 --- a/cocos/core/pipeline/render-batched-queue.ts +++ b/cocos/core/pipeline/render-batched-queue.ts @@ -23,14 +23,9 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module pipeline - */ - import { BatchedBuffer } from './batched-buffer'; import { PipelineStateManager } from './pipeline-state-manager'; -import { RenderPass, Device, CommandBuffer } from '../gfx'; +import { RenderPass, Device, CommandBuffer, DescriptorSet } from '../gfx'; import { SetIndex } from './define'; /** @@ -78,7 +73,7 @@ export class RenderBatchedQueue { * @zh 记录命令缓冲。 * @param cmdBuff The command buffer to store the result */ - public recordCommandBuffer (device: Device, renderPass: RenderPass, cmdBuff: CommandBuffer) { + public recordCommandBuffer (device: Device, renderPass: RenderPass, cmdBuff: CommandBuffer, descriptorSet: DescriptorSet | null = null) { const it = this.queue.values(); let res = it.next(); while (!res.done) { let boundPSO = false; @@ -92,6 +87,7 @@ export class RenderBatchedQueue { cmdBuff.bindDescriptorSet(SetIndex.MATERIAL, batch.pass.descriptorSet); boundPSO = true; } + if (descriptorSet) cmdBuff.bindDescriptorSet(SetIndex.GLOBAL, descriptorSet); cmdBuff.bindDescriptorSet(SetIndex.LOCAL, batch.descriptorSet, res.value.dynamicOffsets); cmdBuff.bindInputAssembler(batch.ia); cmdBuff.draw(batch.ia); diff --git a/cocos/core/pipeline/render-flow.ts b/cocos/core/pipeline/render-flow.ts index 6c244904f0..fa44f7e7b0 100644 --- a/cocos/core/pipeline/render-flow.ts +++ b/cocos/core/pipeline/render-flow.ts @@ -23,10 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module pipeline - */ import { ccclass, displayOrder, serializable, type } from 'cc.decorator'; import { RenderStage } from './render-stage'; import { RenderPipeline } from './render-pipeline'; diff --git a/cocos/core/pipeline/render-instanced-queue.ts b/cocos/core/pipeline/render-instanced-queue.ts index 1beae719de..042cfb68ac 100644 --- a/cocos/core/pipeline/render-instanced-queue.ts +++ b/cocos/core/pipeline/render-instanced-queue.ts @@ -23,13 +23,8 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module pipeline - */ - import { InstancedBuffer } from './instanced-buffer'; -import { Device, RenderPass, PipelineState, CommandBuffer } from '../gfx'; +import { Device, RenderPass, PipelineState, CommandBuffer, DescriptorSet } from '../gfx'; import { PipelineStateManager } from './pipeline-state-manager'; import { SetIndex } from './define'; @@ -70,7 +65,7 @@ export class RenderInstancedQueue { * @zh 记录命令缓冲。 * @param cmdBuff The command buffer to store the result */ - public recordCommandBuffer (device: Device, renderPass: RenderPass, cmdBuff: CommandBuffer) { + public recordCommandBuffer (device: Device, renderPass: RenderPass, cmdBuff: CommandBuffer, descriptorSet: DescriptorSet | null = null) { const it = this.queue.values(); let res = it.next(); while (!res.done) { const { instances, pass, hasPendingModels } = res.value; @@ -86,6 +81,7 @@ export class RenderInstancedQueue { cmdBuff.bindPipelineState(pso); lastPSO = pso; } + if (descriptorSet) cmdBuff.bindDescriptorSet(SetIndex.GLOBAL, descriptorSet); cmdBuff.bindDescriptorSet(SetIndex.LOCAL, instance.descriptorSet, res.value.dynamicOffsets); cmdBuff.bindInputAssembler(instance.ia); cmdBuff.draw(instance.ia); diff --git a/cocos/core/pipeline/render-pipeline.ts b/cocos/core/pipeline/render-pipeline.ts index a9a28e0dd8..ed398cdc98 100644 --- a/cocos/core/pipeline/render-pipeline.ts +++ b/cocos/core/pipeline/render-pipeline.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module pipeline - */ - import { ccclass, displayOrder, serializable, type } from 'cc.decorator'; import { systemInfo } from 'pal/system-info'; import { sceneCulling, validPunctualLightsCulling } from './scene-culling'; diff --git a/cocos/core/pipeline/render-queue.ts b/cocos/core/pipeline/render-queue.ts index 6f2cd1d934..bd504977b0 100644 --- a/cocos/core/pipeline/render-queue.ts +++ b/cocos/core/pipeline/render-queue.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module pipeline - */ - import { RecyclePool } from '../memop'; import { CachedArray } from '../memop/cached-array'; import { IRenderObject, IRenderPass, IRenderQueueDesc, SetIndex } from './define'; diff --git a/cocos/core/pipeline/render-shadow-map-batched-queue.ts b/cocos/core/pipeline/render-shadow-map-batched-queue.ts index 5e67a35d22..d0da00f2a2 100644 --- a/cocos/core/pipeline/render-shadow-map-batched-queue.ts +++ b/cocos/core/pipeline/render-shadow-map-batched-queue.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module pipeline - */ - import { SubModel } from '../renderer/scene/submodel'; import { SetIndex } from './define'; import { Device, RenderPass, Shader, CommandBuffer, DescriptorSet } from '../gfx'; @@ -109,7 +104,7 @@ export class RenderShadowMapBatchedQueue { break; case LightType.SPOT: Mat4.invert(_matShadowView, light.node!.getWorldMatrix()); - Mat4.perspective(_matShadowProj, (light as any).angle, (light as any).aspect, 0.001, (light as any).range); + Mat4.perspective(_matShadowProj, (light as any).angle, 1.0, 0.001, (light as any).range); Mat4.multiply(_matShadowViewProj, _matShadowProj, _matShadowView); for (let i = 0; i < castShadowObjects.length; i++) { const ro = castShadowObjects[i]; diff --git a/cocos/core/pipeline/render-stage.ts b/cocos/core/pipeline/render-stage.ts index 32483aa74c..802cdf44f0 100644 --- a/cocos/core/pipeline/render-stage.ts +++ b/cocos/core/pipeline/render-stage.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module pipeline - */ - import { ccclass, displayOrder, serializable } from 'cc.decorator'; import { legacyCC } from '../global-exports'; import { RenderPipeline } from './render-pipeline'; @@ -47,10 +42,10 @@ export interface IRenderStageInfo { } /** - * @en The render stage actually renders render objects to the output window or other GFX [[FrameBuffer]]. + * @en The render stage actually renders render objects to the output window or other GFX [[gfx.Framebuffer]]. * Typically, a render stage collects render objects it's responsible for, clear the camera, * record and execute command buffer, and at last present the render result. - * @zh 渲染阶段是实质上的渲染执行者,它负责收集渲染数据并执行渲染将渲染结果输出到屏幕或其他 GFX [[FrameBuffer]] 中。 + * @zh 渲染阶段是实质上的渲染执行者,它负责收集渲染数据并执行渲染将渲染结果输出到屏幕或其他 GFX [[gfx.Framebuffer]] 中。 * 典型的渲染阶段会收集它所管理的渲染对象,按照 [[Camera]] 的清除标记进行清屏,记录并执行渲染指令缓存,并最终呈现渲染结果。 */ @ccclass('RenderStage') diff --git a/cocos/core/pipeline/scene-culling.ts b/cocos/core/pipeline/scene-culling.ts index 991e77e0c3..2369e486c5 100644 --- a/cocos/core/pipeline/scene-culling.ts +++ b/cocos/core/pipeline/scene-culling.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { AABB, Frustum, intersect, Sphere } from '../geometry'; import { Model } from '../renderer/scene/model'; import { Camera, SKYBOX_FLAG } from '../renderer/scene/camera'; diff --git a/cocos/core/pipeline/shadow/shadow-flow.ts b/cocos/core/pipeline/shadow/shadow-flow.ts index ca0b2c5a7b..734755fe62 100644 --- a/cocos/core/pipeline/shadow/shadow-flow.ts +++ b/cocos/core/pipeline/shadow/shadow-flow.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module pipeline.forward - */ - import { ccclass } from 'cc.decorator'; import { PIPELINE_FLOW_SHADOW, supportsR32FloatTexture } from '../define'; import { IRenderFlowInfo, RenderFlow } from '../render-flow'; diff --git a/cocos/core/pipeline/shadow/shadow-stage.ts b/cocos/core/pipeline/shadow/shadow-stage.ts index 1f55f4c3cb..a0d367aa89 100644 --- a/cocos/core/pipeline/shadow/shadow-stage.ts +++ b/cocos/core/pipeline/shadow/shadow-stage.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module pipeline.forward - */ - import { ccclass } from 'cc.decorator'; import { Color, Rect, Framebuffer, DescriptorSet } from '../../gfx'; import { IRenderStageInfo, RenderStage } from '../render-stage'; diff --git a/cocos/core/platform/debug.ts b/cocos/core/platform/debug.ts index c10384a818..ec94f04d6f 100644 --- a/cocos/core/platform/debug.ts +++ b/cocos/core/platform/debug.ts @@ -22,13 +22,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/** - * @packageDocumentation - * @module core - */ /* eslint-disable no-console */ - import { EDITOR, JSB, DEV, DEBUG } from 'internal:constants'; import debugInfos from '../../../DebugInfos'; import { legacyCC } from '../global-exports'; diff --git a/cocos/core/platform/index.ts b/cocos/core/platform/index.ts index 833ae01e29..428c40e543 100644 --- a/cocos/core/platform/index.ts +++ b/cocos/core/platform/index.ts @@ -24,7 +24,6 @@ THE SOFTWARE. */ - import './deprecated'; export * from './sys'; diff --git a/cocos/core/platform/macro.ts b/cocos/core/platform/macro.ts index 32321e7ad0..630e80b421 100644 --- a/cocos/core/platform/macro.ts +++ b/cocos/core/platform/macro.ts @@ -25,11 +25,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module core - */ - import { legacyCC } from '../global-exports'; const SUPPORT_TEXTURE_FORMATS = ['.astc', '.pkm', '.pvr', '.webp', '.jpg', '.jpeg', '.bmp', '.png']; @@ -845,7 +840,16 @@ const KEY = { */ dpadCenter: 1005, }; - +/** + * @en + * Predefined constants, see [[Macro]] for detailed contents. + * @zh + * 预定义常量,具体内容参考 [[Macro]] 文档。 + */ +/** + * @en Interface declaration for predefined constants, for usage you should be importing [[macro]] directly. + * @zh 预定义常量的接口声明,实际使用应该直接导入 [[macro]]。 + */ interface Macro { /** * @en @@ -1068,9 +1072,9 @@ interface Macro { /** * @en - * Predefined constants + * Predefined constants, see [[Macro]] for detailed contents. * @zh - * 预定义常量。 + * 预定义常量,具体内容参考 [[Macro]] 文档。 */ const macro: Macro = { SUPPORT_TEXTURE_FORMATS, diff --git a/cocos/core/platform/screen.ts b/cocos/core/platform/screen.ts index 42e606d744..6038f3b2da 100644 --- a/cocos/core/platform/screen.ts +++ b/cocos/core/platform/screen.ts @@ -24,14 +24,10 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/** - * @packageDocumentation - * @module core - */ -import { ConfigOrientation, IScreenOptions, screenAdapter } from 'pal/screen-adapter'; +import { IScreenOptions, screenAdapter } from 'pal/screen-adapter'; import { legacyCC } from '../global-exports'; -import { Size, Vec2 } from '../math'; +import { Size } from '../math'; import { warnID } from './debug'; /** diff --git a/cocos/core/platform/sys.ts b/cocos/core/platform/sys.ts index f1d9b2b032..1d1f10fb20 100644 --- a/cocos/core/platform/sys.ts +++ b/cocos/core/platform/sys.ts @@ -24,10 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module core - */ import { systemInfo } from 'pal/system-info'; import { screenAdapter } from 'pal/screen-adapter'; import { WECHAT } from 'internal:constants'; @@ -59,7 +55,7 @@ export const sys = { /** * @en * Returns if the specified platform related feature is supported. - * @zn + * @zh * 返回指定的平台相关的特性是否支持。 */ hasFeature (feature: sys.Feature): boolean { diff --git a/cocos/core/platform/view.ts b/cocos/core/platform/view.ts index a20c511882..ba55eab22d 100644 --- a/cocos/core/platform/view.ts +++ b/cocos/core/platform/view.ts @@ -25,11 +25,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module core - */ - import '../data/class'; import { EDITOR, MINIGAME, JSB, RUNTIME_BASED } from 'internal:constants'; import { screenAdapter } from 'pal/screen-adapter'; @@ -883,41 +878,60 @@ class ContentStrategy { })(); /** - * ResolutionPolicy class is the root strategy class of scale strategy, - * its main task is to maintain the compatibility with Cocos2d-x

+ * @en ResolutionPolicy class is the root strategy class of scale strategy, + * its main task is to maintain the compatibility with Cocos2d-x. + * + * @zh ResolutionPolicy 类是适配策略的根策略类,它的主要任务是保持与 Cocos2d-x 的兼容性。 */ export class ResolutionPolicy { /** - * The entire application is visible in the specified area without trying to preserve the original aspect ratio.
+ * @en The entire application is visible in the specified area without trying to preserve the original aspect ratio. * Distortion can occur, and the application may appear stretched or compressed. + * + * @zh 整个应用程序在指定区域可见,无需尝试保留原始纵横比, + * 可能会发生变形,出现画面拉伸或压缩。 */ public static EXACT_FIT = 0; /** - * The entire application fills the specified area, without distortion but possibly with some cropping,
+ * @en The entire application fills the specified area, without distortion but possibly with some cropping, * while maintaining the original aspect ratio of the application. + * + * @zh 整个应用程序填充指定区域,没有变形,但可能有一些裁剪, + * 同时保持画面的原始纵横比。 */ public static NO_BORDER = 1; /** - * The entire application is visible in the specified area without distortion while maintaining the original
+ * @en The entire application is visible in the specified area without distortion while maintaining the original * aspect ratio of the application. Borders can appear on two sides of the application. + * + * @zh 整个应用程序在指定区域可见,没有变形,同时保持原始纵横比, + * 边框可能出现在画面的旁侧。 */ public static SHOW_ALL = 2; /** - * The application takes the height of the design resolution size and modifies the width of the internal
- * canvas so that it fits the aspect ratio of the device
- * no distortion will occur however you must make sure your application works on different
+ * @en The application takes the height of the design resolution size and modifies the width of the internal + * canvas so that it fits the aspect ratio of the device + * no distortion will occur however you must make sure your application works on different * aspect ratios + * + * @zh 该应用程序采用设计分辨率大小的高度并修改内部画布的宽度,使其适合设备的纵横比,不会发生变形, + * 但是您必须确保您的应用程序在不同的纵横比的设备下工作。 */ public static FIXED_HEIGHT = 3; /** - * The application takes the width of the design resolution size and modifies the height of the internal
- * canvas so that it fits the aspect ratio of the device
- * no distortion will occur however you must make sure your application works on different
+ * @en The application takes the width of the design resolution size and modifies the height of the internal + * canvas so that it fits the aspect ratio of the device + * no distortion will occur however you must make sure your application works on different * aspect ratios + * + * @zh 该应用程序采用设计分辨率大小的宽度并修改内部画布的高度,使其适合设备的纵横比,不会发生变形 + * 但是您必须确保您的应用程序在不同的纵横比的设备下工作。 */ public static FIXED_WIDTH = 4; /** - * Unknown policy + * @en Unknown policy + * + * @zh 未知的策略 */ public static UNKNOWN = 5; public static ContainerStrategy: typeof ContainerStrategy = ContainerStrategy; diff --git a/cocos/core/platform/visible-rect.ts b/cocos/core/platform/visible-rect.ts index 6ef4460747..d66ffd3848 100644 --- a/cocos/core/platform/visible-rect.ts +++ b/cocos/core/platform/visible-rect.ts @@ -24,8 +24,6 @@ THE SOFTWARE. */ - - import { Rect } from '../math'; import { legacyCC } from '../global-exports'; diff --git a/cocos/core/renderer/config.ts b/cocos/core/renderer/config.ts index 0984cfb415..4b1a9bba57 100644 --- a/cocos/core/renderer/config.ts +++ b/cocos/core/renderer/config.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - let _stageOffset = 0; const _name2stageID = {}; diff --git a/cocos/core/renderer/core/constants.ts b/cocos/core/renderer/core/constants.ts index e210a47ac0..c3bdb5ac45 100644 --- a/cocos/core/renderer/core/constants.ts +++ b/cocos/core/renderer/core/constants.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - export enum RenderQueue { OPAQUE = 0, TRANSPARENT = 1, diff --git a/cocos/core/renderer/core/material-instance.ts b/cocos/core/renderer/core/material-instance.ts index 9107a69ba9..b9e027f1d4 100644 --- a/cocos/core/renderer/core/material-instance.ts +++ b/cocos/core/renderer/core/material-instance.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module material - */ - import { Material } from '../../assets/material'; import { PassInstance } from './pass-instance'; import { MacroRecord } from './pass-utils'; diff --git a/cocos/core/renderer/core/native-pools.jsb.ts b/cocos/core/renderer/core/native-pools.jsb.ts index 49b79129e0..82cacca2a8 100644 --- a/cocos/core/renderer/core/native-pools.jsb.ts +++ b/cocos/core/renderer/core/native-pools.jsb.ts @@ -23,7 +23,6 @@ THE SOFTWARE. */ - declare const jsb: any; export const NativeBufferPool = jsb.NativeBufferPool; diff --git a/cocos/core/renderer/core/native-pools.ts b/cocos/core/renderer/core/native-pools.ts index e87cf8f57e..b846ae14fc 100644 --- a/cocos/core/renderer/core/native-pools.ts +++ b/cocos/core/renderer/core/native-pools.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - export class NativeBufferPool { private _arrayBuffers: ArrayBuffer[] = []; private _chunkSize: number; diff --git a/cocos/core/renderer/core/pass-instance.ts b/cocos/core/renderer/core/pass-instance.ts index c428265233..f5c063d262 100644 --- a/cocos/core/renderer/core/pass-instance.ts +++ b/cocos/core/renderer/core/pass-instance.ts @@ -23,19 +23,14 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module material - */ - import { EffectAsset } from '../../assets/effect-asset'; import { MaterialInstance } from './material-instance'; import { BatchingSchemes, Pass, PassOverrides } from './pass'; import { overrideMacros, MacroRecord } from './pass-utils'; /** - * @en A pass instance defines an variant version of the [[Pass]] - * @zh 表示 [[Pass]] 的一种特殊实例 + * @en A pass instance defines an variant version of the [[renderer.Pass]] + * @zh 表示 [[renderer.Pass]] 的一种特殊实例 */ export class PassInstance extends Pass { /** diff --git a/cocos/core/renderer/core/pass-utils.ts b/cocos/core/renderer/core/pass-utils.ts index d65e226f9a..48f38709c8 100644 --- a/cocos/core/renderer/core/pass-utils.ts +++ b/cocos/core/renderer/core/pass-utils.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module material - */ - import { Type } from '../../gfx'; import { Color, Mat3, Mat4, Vec2, Vec3, Vec4, Quat, IVec2Like, IVec3Like, IVec4Like, IMat3Like, IMat4Like } from '../../math'; diff --git a/cocos/core/renderer/core/pass.ts b/cocos/core/renderer/core/pass.ts index 65ec4d8032..458aecc3b2 100644 --- a/cocos/core/renderer/core/pass.ts +++ b/cocos/core/renderer/core/pass.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module material - */ - import { EDITOR } from 'internal:constants'; import { Root } from '../../root'; import { TextureBase } from '../../assets/texture-base'; @@ -147,8 +142,8 @@ export class Pass { } /** - * @en Get pass hash value by [[Pass]] hash information. - * @zh 根据 [[Pass]] 的哈希信息获取哈希值。 + * @en Get pass hash value by [[renderer.Pass]] hash information. + * @zh 根据 [[renderer.Pass]] 的哈希信息获取哈希值。 * * @param hPass Handle of the pass info used to compute hash value. */ @@ -302,8 +297,8 @@ export class Pass { } /** - * @en Bind a GFX [[Texture]] the the given uniform binding - * @zh 绑定实际 GFX [[Texture]] 到指定 binding。 + * @en Bind a GFX [[gfx.Texture]] the the given uniform binding + * @zh 绑定实际 GFX [[gfx.Texture]] 到指定 binding。 * @param binding The binding for target uniform of texture type * @param value Target texture */ @@ -312,8 +307,8 @@ export class Pass { } /** - * @en Bind a GFX [[Sampler]] the the given uniform binding - * @zh 绑定实际 GFX [[Sampler]] 到指定 binding。 + * @en Bind a GFX [[gfx.Sampler]] the the given uniform binding + * @zh 绑定实际 GFX [[gfx.Sampler]] 到指定 binding。 * @param binding The binding for target uniform of sampler type * @param value Target sampler */ diff --git a/cocos/core/renderer/core/program-lib.ts b/cocos/core/renderer/core/program-lib.ts index 26aa1ea199..ded9863292 100644 --- a/cocos/core/renderer/core/program-lib.ts +++ b/cocos/core/renderer/core/program-lib.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module material - */ - import { EffectAsset } from '../../assets/effect-asset'; import { SetIndex, IDescriptorSetLayoutInfo, globalDescriptorSetLayout, localDescriptorSetLayout } from '../../pipeline/define'; import { PipelineRuntime } from '../../pipeline/custom/pipeline'; diff --git a/cocos/core/renderer/core/render-window.ts b/cocos/core/renderer/core/render-window.ts index 3f82a0fdfd..13fe6c5e59 100644 --- a/cocos/core/renderer/core/render-window.ts +++ b/cocos/core/renderer/core/render-window.ts @@ -54,8 +54,8 @@ const orientationMap: Record = { export class RenderWindow { /** * @en Get window width. Pre-rotated (i.e. rotationally invariant, always in identity/portrait mode) if possible. - * If you want to get oriented size instead, you should use [[Camera.width]] which corresponds to the current screen rotation. - * @zh 获取窗口宽度。如果支持交换链预变换,返回值将始终处于单位旋转(竖屏)坐标系下。如果需要获取旋转后的尺寸,请使用 [[Camera.width]]。 + * If you want to get oriented size instead, you should use [[renderer.scene.Camera.width]] which corresponds to the current screen rotation. + * @zh 获取窗口宽度。如果支持交换链预变换,返回值将始终处于单位旋转(竖屏)坐标系下。如果需要获取旋转后的尺寸,请使用 [[renderer.scene.Camera.width]]。 */ get width (): number { return this._width; @@ -63,8 +63,8 @@ export class RenderWindow { /** * @en Get window height. Pre-rotated (i.e. rotationally invariant, always in identity/portrait mode) if possible. - * If you want to get oriented size instead, you should use [[Camera.width]] which corresponds to the current screen rotation. - * @zh 获取窗口高度。如果支持交换链预变换,返回值将始终处于单位旋转(竖屏)坐标系下。如果需要获取旋转后的尺寸,请使用 [[Camera.height]]。 + * If you want to get oriented size instead, you should use [[renderer.scene.Camera.width]] which corresponds to the current screen rotation. + * @zh 获取窗口高度。如果支持交换链预变换,返回值将始终处于单位旋转(竖屏)坐标系下。如果需要获取旋转后的尺寸,请使用 [[renderer.scene.Camera.height]]。 */ get height (): number { return this._height; diff --git a/cocos/core/renderer/core/texture-buffer-pool.ts b/cocos/core/renderer/core/texture-buffer-pool.ts index 0fe05ef773..4f6adbd65b 100644 --- a/cocos/core/renderer/core/texture-buffer-pool.ts +++ b/cocos/core/renderer/core/texture-buffer-pool.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { getTypedArrayConstructor, Format, FormatInfos, TextureType, TextureUsageBit, TextureFlagBit, Texture, TextureInfo, Device, BufferTextureCopy } from '../../gfx'; import { debug } from '../../platform/debug'; diff --git a/cocos/core/renderer/deprecated.ts b/cocos/core/renderer/deprecated.ts index bbacfa09c6..76ff0dc3a1 100644 --- a/cocos/core/renderer/deprecated.ts +++ b/cocos/core/renderer/deprecated.ts @@ -30,6 +30,7 @@ import { legacyCC } from '../global-exports'; import { Pass } from './core/pass'; import { Camera } from './scene/camera'; import { Shadows } from './scene/shadows'; +import { SpotLight } from './scene'; removeProperty(RenderScene.prototype, 'RenderScene.prototype', [ { name: 'raycastUI2DNode' }, @@ -224,3 +225,9 @@ removeProperty(Shadows.prototype, 'Shadows.prototype', [ name: 'saturation', }, ]); + +removeProperty(SpotLight.prototype, 'SpotLight.prototype', [ + { + name: 'aspect', + }, +]); diff --git a/cocos/core/renderer/scene/ambient.ts b/cocos/core/renderer/scene/ambient.ts index 9c568352ef..6e99d0c8d3 100644 --- a/cocos/core/renderer/scene/ambient.ts +++ b/cocos/core/renderer/scene/ambient.ts @@ -27,8 +27,22 @@ import { Vec4 } from '../../math'; import { legacyCC } from '../../global-exports'; import { AmbientInfo } from '../../scene-graph/scene-globals'; +/** + * @en Ambient lighting representation in the render scene. + * The initial data is setup in [[SceneGlobals.ambient]]. + * @zh 渲染场景中的环境光照设置。 + * 初始值是由 [[SceneGlobals.ambient]] 设置的。 + */ export class Ambient { + /** + * @en Default sun illuminance + * @zh 默认太阳亮度 + */ public static SUN_ILLUM = 65000.0; + /** + * @en Default sky illuminance + * @zh 默认天空亮度 + */ public static SKY_ILLUM = 20000.0; /** @@ -53,7 +67,6 @@ export class Ambient { return this._skyColorLDR; } } - set skyColor (color: Vec4) { const isHDR = (legacyCC.director.root).pipeline.pipelineSceneData.isHDR; if (isHDR) { @@ -75,7 +88,6 @@ export class Ambient { return this._skyIllumLDR; } } - set skyIllum (illum: number) { const isHDR = (legacyCC.director.root).pipeline.pipelineSceneData.isHDR; if (isHDR) { @@ -96,7 +108,6 @@ export class Ambient { return this._groundAlbedoLDR; } } - set groundAlbedo (color: Vec4) { const isHDR = (legacyCC.director.root).pipeline.pipelineSceneData.isHDR; if (isHDR) { @@ -106,14 +117,6 @@ export class Ambient { } } - get mipmapCount (): number { - return this._mipmapCount; - } - - set mipmapCount (count : number) { - this._mipmapCount = count; - } - protected _groundAlbedoHDR = new Vec4(0.2, 0.2, 0.2, 1.0); protected _skyColorHDR = new Vec4(0.2, 0.5, 0.8, 1.0); protected _skyIllumHDR = 0; diff --git a/cocos/core/renderer/scene/camera.ts b/cocos/core/renderer/scene/camera.ts index 4d11875e40..a9b8fabbc9 100644 --- a/cocos/core/renderer/scene/camera.ts +++ b/cocos/core/renderer/scene/camera.ts @@ -117,8 +117,409 @@ export const SKYBOX_FLAG = ClearFlagBit.STENCIL << 1; const correctionMatrices: Mat4[] = []; +/** + * @en The render camera representation in the render scene, it's managed by [[Camera]] + * @zh 渲染场景中的相机对象,由项目层的 [[Camera]] 管理。 + */ export class Camera { + /** + * @en This exposure value corresponding to default standard camera exposure parameters. + * @zh 默认相机的曝光值。 + */ + public static get standardExposureValue () { + return 1.0 / 38400.0; + } + + /** + * @en The luminance unit scale used by area lights. + * @zh 默认局部光源使用的亮度单位缩放。 + */ + public static get standardLightMeterScale () { + return 10000.0; + } + + /** + * @en The name of the camera + * @zh 相机的名称 + */ + get name () { + return this._name; + } + + /** + * @en The render scene to which the camera is attached + * @zh 相机所挂载的场景 + */ + get scene () { + return this._scene; + } + + /** + * @en The node of the camera which determines its transform in world space. + * @zh 相机绑定的节点,决定了它在世界空间的变换矩阵 + */ + set node (val: Node) { + this._node = val; + } + get node () { + return this._node!; + } + + /** + * @en The render window of the camera + * @zh 相机关联的渲染窗口 + */ + set window (val) { + this._window = val; + } + get window () { + return this._window!; + } + + /** + * @en Whether the camera is enabled, a disabled camera won't be processed in the render pipeline. + * @zh 相机是否启用,未启用的相机不会被渲染 + */ + set enabled (val) { + this._enabled = val; + } + get enabled () { + return this._enabled; + } + + /** + * @en Visibility mask of the camera, declaring a set of node layers that will be visible to this camera. + * @zh 相机的可见性掩码,声明在当前相机中可见的节点层级集合。 + */ + set visibility (vis: number) { + this._visibility = vis; + } + get visibility (): number { + return this._visibility; + } + + /** + * @en Render priority of the camera. Cameras with higher depth are rendered after cameras with lower depth. + * @zh 相机的渲染优先级,值越小越优先渲染。 + */ + get priority (): number { + return this._priority; + } + + set priority (val: number) { + this._priority = val; + } + + /** + * @en The width of the camera's view size + * @zh 相机的视图宽度 + */ + get width () { + return this._width; + } + + /** + * @en The height of the camera's view size + * @zh 相机的视图高度 + */ + get height () { + return this._height; + } + + /** + * @en The world position of the camera + * @zh 相机的世界坐标 + */ + set position (val) { + this._position = val; + } + get position () { + return this._position; + } + + /** + * @en The forward vector of the camera's look direction + * @zh 指向相机观察方向的向量 + */ + set forward (val) { + this._forward = val; + } + get forward () { + return this._forward; + } + + /** + * @en Camera aperture, controls the exposure parameter. + * @zh 相机光圈,影响相机的曝光参数。 + */ + set aperture (val: CameraAperture) { + this._aperture = val; + this._apertureValue = FSTOPS[this._aperture]; + this.updateExposure(); + } + get aperture (): CameraAperture { + return this._aperture; + } + + /** + * @en Camera aperture value. + * @zh 相机光圈值。 + */ + get apertureValue (): number { + return this._apertureValue; + } + + /** + * @en Camera shutter, controls the exposure parameter. + * @zh 相机快门,影响相机的曝光参数。 + */ + set shutter (val: CameraShutter) { + this._shutter = val; + this._shutterValue = SHUTTERS[this._shutter]; + this.updateExposure(); + } + get shutter (): CameraShutter { + return this._shutter; + } + + /** + * @en Camera shutter value. + * @zh 相机快门值。 + */ + get shutterValue (): number { + return this._shutterValue; + } + + /** + * @en Camera ISO, controls the exposure parameter. + * @zh 相机感光度,影响相机的曝光参数。 + */ + set iso (val: CameraISO) { + this._iso = val; + this._isoValue = ISOS[this._iso]; + this.updateExposure(); + } + get iso (): CameraISO { + return this._iso; + } + + /** + * @en Camera ISO value. + * @zh 相机感光度值。 + */ + get isoValue (): number { + return this._isoValue; + } + + /** + * @en The calculated exposure of the camera + * @zh 相机的曝光参数 + */ + get exposure (): number { + return this._exposure; + } + + /** + * @en Clearing flags of the camera, specifies which part of the framebuffer will be actually cleared every frame. + * @zh 相机的缓冲清除标志位,指定帧缓冲的哪部分要每帧清除。 + */ + get clearFlag () : ClearFlags { + return this._clearFlag; + } + set clearFlag (flag: ClearFlags) { + this._clearFlag = flag; + } + + /** + * @en Clearing color of the camera. + * @zh 相机的颜色缓冲默认值。 + */ + set clearColor (val) { + this._clearColor.x = val.x; + this._clearColor.y = val.y; + this._clearColor.z = val.z; + this._clearColor.w = val.w; + } + get clearColor () { + return this._clearColor as IVec4Like; + } + + /** + * @en Clearing depth of the camera. + * @zh 相机的深度缓冲默认值。 + */ + get clearDepth () : number { + return this._clearDepth; + } + set clearDepth (depth: number) { + this._clearDepth = depth; + } + + /** + * @en Clearing stencil of the camera. + * @zh 相机的模板缓冲默认值。 + */ + get clearStencil () : number { + return this._clearStencil; + } + set clearStencil (stencil: number) { + this._clearStencil = stencil; + } + + /** + * @en The projection type of the camera. + * @zh 相机的投影类型。 + */ + set projectionType (val) { + this._proj = val; + this._isProjDirty = true; + } + get projectionType () { + return this._proj; + } + + /** + * @en The aspect ratio of the camera + * @zh 相机视图的长宽比 + */ + get aspect () { + return this._aspect; + } + + /** + * @en The viewport height of the orthogonal type camera. + * @zh 正交相机的视角高度。 + */ + set orthoHeight (val) { + this._orthoHeight = val; + this._isProjDirty = true; + } + get orthoHeight () { + return this._orthoHeight; + } + + /** + * @en The axis on which the FOV would be fixed regardless of screen aspect changes. + * @zh 指定视角的固定轴向,在此轴上不会跟随屏幕长宽比例变化。 + */ + set fovAxis (axis) { + this._fovAxis = axis; + this._isProjDirty = true; + } + get fovAxis () { + return this._fovAxis; + } + + /** + * @en Field of view of the camera. + * @zh 相机的视角大小。 + */ + set fov (fov) { + this._fov = fov; + this._isProjDirty = true; + } + get fov () { + return this._fov; + } + + /** + * @en Near clipping distance of the camera, should be as large as possible within acceptable range. + * @zh 相机的近裁剪距离,应在可接受范围内尽量取最大。 + */ + set nearClip (nearClip) { + this._nearClip = nearClip; + this._isProjDirty = true; + } + get nearClip () { + return this._nearClip; + } + + /** + * @en Far clipping distance of the camera, should be as small as possible within acceptable range. + * @zh 相机的远裁剪距离,应在可接受范围内尽量取最小。 + */ + set farClip (farClip) { + this._farClip = farClip; + this._isProjDirty = true; + } + get farClip () { + return this._farClip; + } + + /** + * @en The viewport rect of the camera, pre-rotated (i.e. always in identity/portrait mode) if possible. + * @zh 相机的视口矩形,如果设备允许的话,这个视口会永远保持竖屏状态,由渲染流程保障旋转的正确。 + */ + get viewport () { + return this._viewport; + } + set viewport (val) { + warnID(8302); + this.setViewportInOrientedSpace(val); + } + + /** + * @en The view frustum of the camera + * @zh 相机的视锥体 + */ + set frustum (val) { + this._frustum = val; + } + get frustum () { + return this._frustum; + } + + /** + * @en The view matrix of the camera + * @zh 相机的视图矩阵 + */ + get matView () { + return this._matView; + } + + /** + * @en The projection matrix of the camera + * @zh 相机的投影矩阵 + */ + get matProj () { + return this._matProj; + } + + /** + * @en The inverse of the projection matrix of the camera + * @zh 相机的逆投影矩阵 + */ + get matProjInv () { + return this._matProjInv; + } + + /** + * @en The view projection matrix of the camera + * @zh 相机的视图投影矩阵 + */ + get matViewProj () { + return this._matViewProj; + } + + /** + * @en The inverse of the view projection matrix of the camera + * @zh 相机的逆视图投影矩阵 + */ + get matViewProjInv () { + return this._matViewProjInv; + } + + /** + * @en Whether the camera is fixed size or matching the window size. + * @zh 相机是固定尺寸还是跟随屏幕尺寸 + */ public isWindowSize = true; + + /** + * @en Scale of the internal buffer size, + * set to 1 to keep the same with the canvas size. + * @zh 相机内部缓冲尺寸的缩放值, 1 为与 canvas 尺寸相同。 + */ public screenScale: number; private _device: Device; @@ -153,7 +554,6 @@ export class Camera { private _shutterValue = 0.0; private _iso: CameraISO = CameraISO.ISO100; private _isoValue = 0.0; - private _ec = 0.0; private _window: RenderWindow | null = null; private _width = 1; private _height = 1; @@ -195,19 +595,9 @@ export class Camera { } /** - * this exposure value corresponding to default standard camera exposure parameters + * @en Initialize the camera, normally you shouldn't invoke this function, it's managed automatically. + * @zh 初始化相机,开发者通常不应该使用这个方法,初始化流程是自动管理的。 */ - public static get standardExposureValue () { - return 1.0 / 38400.0; - } - - /** - * luminance unit scale used by area lights - */ - public static get standardLightMeterScale () { - return 10000.0; - } - public initialize (info: ICameraInfo) { this.node = info.node; this._width = 1; @@ -223,6 +613,10 @@ export class Camera { this.changeTargetWindow(info.window); } + /** + * @en Destroy the camera, you shouldn't invoke this function, it's managed by the render scene. + * @zh 销毁相机,开发者不应该使用这个方法,销毁流程是由 RenderScene 管理的。 + */ public destroy () { if (this._window) { this._window.detachCamera(this); @@ -232,17 +626,32 @@ export class Camera { this._geometryRenderer?.destroy(); } + /** + * @en Attach the camera to the given render scene so that it will be rendered in it. + * @zh 将相机添加到相关的渲染场景中,以便可以被渲染器渲染。 + * @param scene @en The render scene @zh 渲染场景 + */ public attachToScene (scene: RenderScene) { this._enabled = true; this._scene = scene; } + /** + * @en Detach the camera from previously attached render scene. It will no longer be rendered. + * @zh 将相机从之前设置的渲染场景移除,之后将不会再被渲染。 + */ public detachFromScene () { this._enabled = false; this._scene = null; } - public resize (width: number, height: number) { + /** + * @en Resize the view size of the camera. + * @zh 重置相机视图尺寸 + * @param width The width of the view size + * @param height The height of the view size + */ + public resize (width: number, height: number): void { if (!this._window) return; this._width = width; @@ -252,6 +661,12 @@ export class Camera { this._isProjDirty = true; } + /** + * @en Set a fixed size for the camera view. + * @zh 设置固定相机视图尺寸 + * @param width The width of the view size + * @param height The height of the view size + */ public setFixedSize (width: number, height: number) { this._width = width; this._height = height; @@ -259,7 +674,10 @@ export class Camera { this.isWindowSize = false; } - // Editor specific gizmo camera logic + /** + * Editor specific gizmo camera logic + * @internal + */ public syncCameraEditor (camera) { if (EDITOR) { this.position = camera.position; @@ -271,7 +689,12 @@ export class Camera { } } - public update (forceUpdate = false) { // for lazy eval situations like the in-editor preview + /** + * @en Update the camera's builtin matrixes + * @zh 更新相机的视图、投影等矩阵 + * @param forceUpdate If force update, then dirty flag will be ignored + */ + public update (forceUpdate = false): void { // for lazy eval situations like the in-editor preview if (!this._node) return; let viewProjDirty = false; @@ -314,105 +737,13 @@ export class Camera { } } - set node (val: Node) { - this._node = val; - } - - get node () { - return this._node!; - } - - set enabled (val) { - this._enabled = val; - } - - get enabled () { - return this._enabled; - } - - set orthoHeight (val) { - this._orthoHeight = val; - this._isProjDirty = true; - } - - get orthoHeight () { - return this._orthoHeight; - } - - set projectionType (val) { - this._proj = val; - this._isProjDirty = true; - } - - get projectionType () { - return this._proj; - } - - set fovAxis (axis) { - this._fovAxis = axis; - this._isProjDirty = true; - } - - get fovAxis () { - return this._fovAxis; - } - - set fov (fov) { - this._fov = fov; - this._isProjDirty = true; - } - - get fov () { - return this._fov; - } - - set nearClip (nearClip) { - this._nearClip = nearClip; - this._isProjDirty = true; - } - - get nearClip () { - return this._nearClip; - } - - set farClip (farClip) { - this._farClip = farClip; - this._isProjDirty = true; - } - - get farClip () { - return this._farClip; - } - - get surfaceTransform() { + get surfaceTransform () { return this._curTransform; } - set clearColor (val) { - this._clearColor.x = val.x; - this._clearColor.y = val.y; - this._clearColor.z = val.z; - this._clearColor.w = val.w; - } - - get clearColor () { - return this._clearColor as IVec4Like; - } - /** - * Pre-rotated (i.e. always in identity/portrait mode) if possible. - */ - get viewport () { - return this._viewport; - } - - set viewport (val) { - warnID(8302); - this.setViewportInOrientedSpace(val); - } - - /** - * Set the viewport in oriented space (local to screen rotations) + * @en Set the viewport in oriented space (equal to the actual screen rotation) + * @zh 在目标朝向空间(实际屏幕朝向)内设置相机视口 */ public setViewportInOrientedSpace (val: Rect) { const { x, width, height } = val; @@ -457,175 +788,15 @@ export class Camera { this.resize(this.width, this.height); } - get scene () { - return this._scene; - } - - get name () { - return this._name; - } - - get width () { - return this._width; - } - - get height () { - return this._height; - } - - get aspect () { - return this._aspect; - } - - get matView () { - return this._matView; - } - - get matProj () { - return this._matProj; - } - - get matProjInv () { - return this._matProjInv; - } - - get matViewProj () { - return this._matViewProj; - } - - get matViewProjInv () { - return this._matViewProjInv; - } - - set frustum (val) { - this._frustum = val; - } - - get frustum () { - return this._frustum; - } - - set window (val) { - this._window = val; - } - - get window () { - return this._window!; - } - - set forward (val) { - this._forward = val; - } - - get forward () { - return this._forward; - } - - set position (val) { - this._position = val; - } - - get position () { - return this._position; - } - - set visibility (vis: number) { - this._visibility = vis; - } - get visibility (): number { - return this._visibility; - } - - get priority (): number { - return this._priority; - } - - set priority (val: number) { - this._priority = val; - } - - set aperture (val: CameraAperture) { - this._aperture = val; - this._apertureValue = FSTOPS[this._aperture]; - this.updateExposure(); - } - - get aperture (): CameraAperture { - return this._aperture; - } - - get apertureValue (): number { - return this._apertureValue; - } - - set shutter (val: CameraShutter) { - this._shutter = val; - this._shutterValue = SHUTTERS[this._shutter]; - this.updateExposure(); - } - - get shutter (): CameraShutter { - return this._shutter; - } - - get shutterValue (): number { - return this._shutterValue; - } - - set iso (val: CameraISO) { - this._iso = val; - this._isoValue = ISOS[this._iso]; - this.updateExposure(); - } - - get iso (): CameraISO { - return this._iso; - } - - get isoValue (): number { - return this._isoValue; - } - - set ec (val: number) { - this._ec = val; - } - - get ec (): number { - return this._ec; - } - - get exposure (): number { - return this._exposure; - } - - get clearFlag () : ClearFlags { - return this._clearFlag; - } - - set clearFlag (flag: ClearFlags) { - this._clearFlag = flag; - } - - get clearDepth () : number { - return this._clearDepth; - } - - set clearDepth (depth: number) { - this._clearDepth = depth; - } - - get clearStencil () : number { - return this._clearStencil; - } - - set clearStencil (stencil: number) { - this._clearStencil = stencil; - } - get geometryRenderer () { return this._geometryRenderer; } + /** + * @en Change the target render window to another one + * @zh 修改相机的目标渲染窗口 + * @param window The target render window, could be null + */ public changeTargetWindow (window: RenderWindow | null = null) { if (this._window) { this._window.detachCamera(this); @@ -643,6 +814,10 @@ export class Camera { } } + /** + * @en Detach camera from the render window + * @zh 将 camera 从渲染窗口移除 + */ public detachCamera () { if (this._window) { this._window.detachCamera(this); @@ -650,7 +825,12 @@ export class Camera { } /** - * transform a screen position (in oriented space) to a world space ray + * @en Transform a screen position (in oriented space) to a world space ray + * @zh 将一个屏幕空间(在实际朝向下)点转换到世界空间的射线 + * @param out the resulting ray + * @param x the screen x of the position + * @param y the screen y of the position + * @returns the resulting ray */ public screenPointToRay (out: Ray, x: number, y: number): Ray { if (!this._node) return null!; @@ -685,7 +865,11 @@ export class Camera { } /** - * transform a screen position (in oriented space) to world space + * @en Transform a screen position (in oriented space) to world space + * @zh 将一个屏幕空间(在实际朝向下)位置转换到世界空间 + * @param out the resulting vector + * @param screenPos the screen position to be transformed + * @returns the resulting vector */ public screenToWorld (out: Vec3, screenPos: Vec3): Vec3 { const width = this.width; @@ -731,7 +915,11 @@ export class Camera { } /** - * transform a world space position to screen space + * @en Transform a world space position to screen space rendered by the camera + * @zh 将一个世界空间位置转换到相机渲染后的屏幕空间 + * @param out the resulting vector + * @param worldPos the world position to be transformed + * @returns the resulting vector */ public worldToScreen (out: Vec3, worldPos: Vec3 | Readonly): Vec3 { const ySign = this._device.capabilities.clipSpaceSignY; @@ -758,12 +946,13 @@ export class Camera { } /** - * transform a world space matrix to screen space - * @param {Mat4} out the resulting vector - * @param {Mat4} worldMatrix the world space matrix to be transformed - * @param {number} width framebuffer width - * @param {number} height framebuffer height - * @returns {Mat4} the resulting vector + * @en Transform a world space matrix to screen space rendered by the camera + * @zh 将一个世界空间矩阵转换到相机渲染后的屏幕空间 + * @param out the resulting matrix + * @param worldMatrix the world space matrix to be transformed + * @param width framebuffer width + * @param height framebuffer height + * @returns the resulting matrix */ public worldMatrixToScreen (out: Mat4, worldMatrix: Mat4, width: number, height: number) { Mat4.multiply(out, this._matViewProj, worldMatrix); @@ -780,6 +969,11 @@ export class Camera { return out; } + /** + * @en Set exposure with actual value. + * @zh 设置相机的曝光值 + * @param ev100 + */ protected setExposure (ev100) { this._exposure = 0.833333 / (2.0 ** ev100); } diff --git a/cocos/core/renderer/scene/directional-light.ts b/cocos/core/renderer/scene/directional-light.ts index 0c3793fcd6..e36ce0691e 100644 --- a/cocos/core/renderer/scene/directional-light.ts +++ b/cocos/core/renderer/scene/directional-light.ts @@ -32,6 +32,11 @@ import { PCFType, Shadows } from './shadows'; const _forward = new Vec3(0, 0, -1); const _v3 = new Vec3(); +/** + * @en The directional light representation in the render scene, it acts as the main light source in a scene. + * As main light, only one directional light can be created in a scene, it can generate realtime shadows with configuration. + * @zh 渲染场景中的方向光抽象,这是场景中的主光源。作为主光源,每个场景只能有一个方向光,它也包含阴影配置,用来生成实时阴影。 + */ export class DirectionalLight extends Light { protected _dir: Vec3 = new Vec3(1.0, -1.0, -1.0); protected _illuminanceHDR: number = Ambient.SUN_ILLUM; @@ -54,6 +59,10 @@ export class DirectionalLight extends Light { protected _shadowFar = 10.0; protected _shadowOrthoSize = 5; + /** + * @en The direction vector of the light + * @zh 光源的方向 + */ set direction (dir: Vec3) { Vec3.normalize(this._dir, dir); } @@ -62,7 +71,10 @@ export class DirectionalLight extends Light { return this._dir; } - // in Lux(lx) + /** + * @en The illuminance of the light in Lux(lx) + * @zh 光源的辐照度,单位是 Lux(lx) + */ get illuminance (): number { const isHDR = (legacyCC.director.root).pipeline.pipelineSceneData.isHDR; if (isHDR) { @@ -80,6 +92,10 @@ export class DirectionalLight extends Light { } } + /** + * @en The illuminance of the light in HDR mode + * @zh HDR 模式下光源的辐照度 + */ get illuminanceHDR () { return this._illuminanceHDR; } @@ -87,6 +103,10 @@ export class DirectionalLight extends Light { this._illuminanceHDR = value; } + /** + * @en The illuminance of the light in LDR mode + * @zh LDR 模式下光源的辐照度 + */ get illuminanceLDR () { return this._illuminanceLDR; } @@ -106,9 +126,9 @@ export class DirectionalLight extends Light { } /** - * @en get or set shadow pcf. - * @zh 获取或者设置阴影pcf等级。 - */ + * @en get or set shadow pcf. + * @zh 获取或者设置阴影pcf等级。 + */ get shadowPcf () { return this._shadowPcf; } @@ -117,9 +137,9 @@ export class DirectionalLight extends Light { } /** - * @en get or set shadow map sampler offset - * @zh 获取或者设置阴影纹理偏移值 - */ + * @en get or set shadow map sampler offset + * @zh 获取或者设置阴影纹理偏移值 + */ get shadowBias () { return this._shadowBias; } @@ -128,9 +148,9 @@ export class DirectionalLight extends Light { } /** - * @en get or set normal bias. - * @zh 设置或者获取法线偏移。 - */ + * @en get or set normal bias. + * @zh 设置或者获取法线偏移。 + */ get shadowNormalBias () { return this._shadowNormalBias; } @@ -150,9 +170,9 @@ export class DirectionalLight extends Light { } /** - * @en get or set shadow camera far - * @zh 获取或者设置潜在阴影产生的范围 - */ + * @en get or set shadow camera far + * @zh 获取或者设置潜在阴影产生的范围 + */ get shadowDistance () { return this._shadowDistance; } @@ -161,8 +181,8 @@ export class DirectionalLight extends Light { } /** - * @en get or set shadow camera far - * @zh 获取或者设置潜在阴影产生的范围 + * @en get or set shadow camera far + * @zh 获取或者设置潜在阴影产生的范围 */ get shadowInvisibleOcclusionRange () { return this._shadowInvisibleOcclusionRange; @@ -172,9 +192,9 @@ export class DirectionalLight extends Light { } /** - * @en get or set fixed area shadow - * @zh 是否是固定区域阴影 - */ + * @en get or set fixed area shadow + * @zh 是否是固定区域阴影 + */ get shadowFixedArea () { return this._shadowFixedArea; } @@ -183,9 +203,9 @@ export class DirectionalLight extends Light { } /** - * @en get or set shadow camera near - * @zh 获取或者设置阴影相机近裁剪面 - */ + * @en The near clip plane of the shadow camera + * @zh 获取或者设置阴影相机近裁剪面 + */ get shadowNear () { return this._shadowNear; } @@ -194,9 +214,9 @@ export class DirectionalLight extends Light { } /** - * @en get or set shadow camera far - * @zh 获取或者设置阴影相机远裁剪面 - */ + * @en The far clip plane of the shadow camera + * @zh 获取或者设置阴影相机远裁剪面 + */ get shadowFar () { return this._shadowFar; } @@ -205,9 +225,9 @@ export class DirectionalLight extends Light { } /** - * @en get or set shadow camera orthoSize - * @zh 获取或者设置阴影相机正交大小 - */ + * @en get or set shadow camera orthoSize + * @zh 获取或者设置阴影相机正交大小 + */ get shadowOrthoSize () { return this._shadowOrthoSize; } @@ -227,6 +247,10 @@ export class DirectionalLight extends Light { this.direction = new Vec3(1.0, -1.0, -1.0); } + /** + * @en Update the direction + * @zh 更新方向 + */ public update () { if (this._node && this._node.hasChangedFlags) { this.direction = Vec3.transformQuat(_v3, _forward, this._node.worldRotation); diff --git a/cocos/core/renderer/scene/fog.ts b/cocos/core/renderer/scene/fog.ts index 51670cda92..928c8ce952 100644 --- a/cocos/core/renderer/scene/fog.ts +++ b/cocos/core/renderer/scene/fog.ts @@ -76,6 +76,10 @@ export const FogType = Enum({ const FOG_TYPE_NONE = FogType.LAYERED + 1; +/** + * @en The fog representation in the render scene. + * @zh 渲染场景中的全局雾效配置 + */ export class Fog { /** * @zh 是否启用全局雾效 diff --git a/cocos/core/renderer/scene/light.ts b/cocos/core/renderer/scene/light.ts index ed502320ca..a345172ab5 100644 --- a/cocos/core/renderer/scene/light.ts +++ b/cocos/core/renderer/scene/light.ts @@ -55,6 +55,10 @@ export function ColorTemperatureToRGB (rgb: Vec3, kelvin: number) { rgb.z = 0.0556434 * X + -0.2040259 + 1.0572252 * Z; } +/** + * @en The light type enumeration. + * @zh 光源类型枚举。 + */ export enum LightType { DIRECTIONAL, SPHERE, @@ -64,7 +68,15 @@ export enum LightType { export const nt2lm = (size: number) => 4 * Math.PI * Math.PI * size * size; +/** + * @en The abstract light class of the render scene + * @zh 渲染场景中的光源基类 + */ export class Light { + /** + * @en Whether it's a baked light source, baked light will be ignored in real time lighting pass + * @zh 是否是烘焙光源,烘焙光源会在实时光照计算中被忽略 + */ get baked () { return this._baked; } @@ -73,6 +85,10 @@ export class Light { this._baked = val; } + /** + * @en The color of the light + * @zh 光源的颜色 + */ set color (color: Vec3) { this._color.set(color); } @@ -81,6 +97,10 @@ export class Light { return this._color; } + /** + * @en Whether to use color temperature + * @zh 是否使用光源的色温 + */ set useColorTemperature (enable: boolean) { this._useColorTemperature = enable; } @@ -89,6 +109,10 @@ export class Light { return this._useColorTemperature; } + /** + * @en The color temperature of the light + * @zh 光源的色温 + */ set colorTemperature (val: number) { this._colorTemp = val; ColorTemperatureToRGB(this._colorTempRGB, this._colorTemp); @@ -98,6 +122,10 @@ export class Light { return this._colorTemp; } + /** + * @en The float RGB value of the color temperature, each channel is from 0 to 1 + * @zh 色温的浮点数颜色值,每个通道都是从 0 到 1 + */ get colorTemperatureRGB (): Vec3 { return this._colorTempRGB; } @@ -109,14 +137,26 @@ export class Light { } } + /** + * @en The node which owns the light source + * @zh 光源归属的节点 + */ get node () { return this._node; } + /** + * @en The type of the light source, e.g. directional light, spot light, etc + * @zh 光源的类型,比如方向光、聚光灯等 + */ get type () : LightType { return this._type; } + /** + * @en The name of the light source + * @zh 光源的名字 + */ get name () { return this._name; } @@ -125,6 +165,10 @@ export class Light { this._name = n; } + /** + * @en The render scene which owns the current light + * @zh 光源所属的渲染场景 + */ get scene () { return this._scene; } @@ -152,10 +196,19 @@ export class Light { this.colorTemperature = 6550.0; } + /** + * @en Attach the light to a render scene + * @zh 将光源挂载到渲染场景上 + * @param scene @en The render scene @zh 渲染场景 + */ public attachToScene (scene: RenderScene) { this._scene = scene; } + /** + * @en Detach the light from the render scene + * @zh 将光源从渲染场景上移除 + */ public detachFromScene () { this._scene = null; } diff --git a/cocos/core/renderer/scene/model.ts b/cocos/core/renderer/scene/model.ts index def92d9075..cedea79069 100644 --- a/cocos/core/renderer/scene/model.ts +++ b/cocos/core/renderer/scene/model.ts @@ -46,6 +46,10 @@ const shadowMapPatches: IMacroPatch[] = [ { name: 'CC_RECEIVE_SHADOW', value: true }, ]; +const lightMapPatches: IMacroPatch[] = [ + { name: 'CC_USE_LIGHTMAP', value: true }, +]; + export interface IInstancedAttributeBlock { buffer: Uint8Array; views: TypedArray[]; @@ -86,41 +90,86 @@ const lightmapSamplerWithMipHash = new SamplerInfo( ); /** - * A representation of a model + * @en A representation of a model instance + * The base model class, which is the core component of [[MeshRenderer]], + * adds its own Model to the rendered scene for rendering submissions when [[MeshRenderer]] is enabled. + * This type of object represents a rendering instance in a scene, and it can contain multiple sub models, + * each of which corresponds to a material. These sub models share the same location and form a complete object. + * Each sub model references a sub mesh resource, which provides vertex and index buffers for rendering. + * @zh 代表一个模型实例 + * 基础模型类,它是 [[MeshRenderer]] 的核心组成部分,在 [[MeshRenderer]] 启用时会将自己的 Model 添加到渲染场景中用于提交渲染。 + * 此类型对象代表一个场景中的渲染实例,它可以包含多个子模型,每个子模型对应一个材质。这些子模型共享同样的位置,组成一个完整的物体。 + * 每个子模型引用一个子网格资源,后者提供渲染所用的顶点与索引缓冲。 */ export class Model { + /** + * @en Sub models of the current model + * @zh 获取所有子模型 + */ get subModels () { return this._subModels; } + /** + * @en Whether the model is initialized + * @zh 是否初始化 + */ get inited (): boolean { return this._inited; } + /** + * @en The axis-aligned bounding box of the model in the world space + * @zh 获取世界空间包围盒 + */ get worldBounds () { return this._worldBounds!; } + /** + * @en The axis-aligned bounding box of the model in the model space + * @zh 获取模型空间包围盒 + */ get modelBounds () { return this._modelBounds; } + /** + * @en The ubo buffer of the model + * @zh 获取模型的 ubo 缓冲 + */ get localBuffer () { return this._localBuffer; } + /** + * @en The world bound ubo buffer + * @zh 获取世界包围盒 ubo 缓冲 + */ get worldBoundBuffer () { return this._worldBoundBuffer; } + /** + * @en The time stamp of last update + * @zh 获取上次更新时间戳 + */ get updateStamp () { return this._updateStamp; } + /** + * @en Whether GPU instancing is enabled for the current model + * @zh 是否开启实例化渲染 + */ get isInstancingEnabled () { return this._instMatWorldIdx >= 0; } + /** + * @en Model level shadow bias + * @zh 阴影偏移值 + */ get shadowBias () { return this._shadowBias; } @@ -129,6 +178,10 @@ export class Model { this._shadowBias = val; } + /** + * @en Model level shadow normal bias + * @zh 阴影法线偏移值 + */ get shadowNormalBias () { return this._shadowNormalBias; } @@ -137,6 +190,10 @@ export class Model { this._shadowNormalBias = val; } + /** + * @en Whether the model should receive shadow + * @zh 是否接收阴影 + */ get receiveShadow () { return this._receiveShadow; } @@ -146,6 +203,10 @@ export class Model { this.onMacroPatchesStateChanged(); } + /** + * @en Whether the model should cast shadow + * @zh 是否投射阴影 + */ get castShadow () { return this._castShadow; } @@ -154,6 +215,10 @@ export class Model { this._castShadow = val; } + /** + * @en The node to which the model belongs + * @zh 模型所在的节点 + */ get node () : Node { return this._node; } @@ -162,6 +227,10 @@ export class Model { this._node = n; } + /** + * @en Model's transform + * @zh 模型的变换 + */ get transform () : Node { return this._transform; } @@ -170,6 +239,13 @@ export class Model { this._transform = n; } + /** + * @en Model's visibility tag + * Model's visibility flags, it's different from [[Node.layer]], + * but it will also be compared with [[Camera.visibility]] during culling process. + * @zh 模型的可见性标志 + * 模型的可见性标志与 [[Node.layer]] 不同,它会在剔除阶段与 [[Camera.visibility]] 进行比较 + */ get visFlags () : number { return this._visFlags; } @@ -178,6 +254,10 @@ export class Model { this._visFlags = val; } + /** + * @en Whether the model is enabled in the render scene so that it will be rendered + * @zh 模型是否在渲染场景中启用并被渲染 + */ get enabled () : boolean { return this._enabled; } @@ -186,45 +266,175 @@ export class Model { this._enabled = val; } + /** + * @en The type of the model + * @zh 模型类型 + */ public type = ModelType.DEFAULT; + + /** + * @en The render scene to which the model belongs + * @zh 模型所在的场景 + */ public scene: RenderScene | null = null; + + /** + * @en Whether dynamic batching is enabled for model + * @zh 是否动态合批 + */ public isDynamicBatching = false; + + /** + * @en The instance attributes + * @zh 实例化属性 + */ public instancedAttributes: IInstancedAttributeBlock = { buffer: null!, views: [], attributes: [] }; + /** + * @en The world axis-aligned bounding box + * @zh 世界空间包围盒 + */ protected _worldBounds: AABB | null = null; + + /** + * @en The model axis-aligned bounding box + * @zh 模型空间包围盒 + */ protected _modelBounds: AABB | null = null; + + /** + * @en Sub models + * @zh 子模型 + */ protected _subModels: SubModel[] = []; + + /** + * @en The node to which the model belongs + * @zh 模型所在的节点 + */ protected _node: Node = null!; + + /** + * @en Model's transform + * @zh 子模型的变换 + */ protected _transform: Node = null!; + /** + * @en Current gfx device + * @zh 当前 GFX 设备 + */ protected _device: Device; + + /** + * @en Whether the model is initialized + * @zh 是否初始化过 + */ protected _inited = false; + + /** + * @en Descriptor set count + * @zh 描述符集合个数 + */ protected _descriptorSetCount = 1; + + /** + * @en Time stamp for last update + * @zh 更新时间戳 + */ protected _updateStamp = -1; + + /** + * @en Local ubo data dirty flag + * @zh 本地 ubo 数据是否修改过 + */ protected _localDataUpdated = true; + /** + * @en Local ubo data + * @zh 本地 ubo 数据 + */ protected _localData = new Float32Array(UBOLocal.COUNT); + + /** + * @en Local ubo buffer + * @zh 本地 ubo 缓冲 + */ protected _localBuffer: Buffer | null = null; + + /** + * @en Instance matrix id + * @zh 实例矩阵索引 + */ private _instMatWorldIdx = -1; private _lightmap: Texture2D | null = null; private _lightmapUVParam: Vec4 = new Vec4(); + /** + * @en World AABB buffer + * @zh 世界空间包围盒缓冲 + */ protected _worldBoundBuffer: Buffer | null = null; + /** + * @en Whether the model should receive shadow + * @zh 是否接收阴影 + */ protected _receiveShadow = false; + + /** + * @en Whether the model should cast shadow + * @zh 是否投射阴影 + */ protected _castShadow = false; + + /** + * @en Shadow bias + * @zh 阴影偏移 + */ protected _shadowBias = 0; + + /** + * @en Shadow normal bias + * @zh 阴影法线偏移 + */ protected _shadowNormalBias = 0; + + /** + * @en Whether the model is enabled in the render scene so that it will be rendered + * @zh 模型是否在渲染场景中启用并被渲染 + */ protected _enabled = true; + + /** + * @en The visibility flags + * @zh 可见性标志位 + */ protected _visFlags = Layers.Enum.NONE; /** - * Setup a default empty model + * @internal + * @en native object + * @zh 原生对象 + */ + + /** + * @internal + * @en return native object + * @zh 返回原生对象 + */ + /** + * @en Constructor to create an empty model + * @zh 创建一个空模型 */ constructor () { this._device = legacyCC.director.root.device; } + /** + * @en Initialize the model + * @zh 初始化模型 + */ public initialize () { if (this._inited) { return; @@ -236,6 +446,10 @@ export class Model { this._inited = true; } + /** + * @en Destroy the model + * @zh 销毁模型 + */ public destroy () { const subModels = this._subModels; for (let i = 0; i < subModels.length; i++) { @@ -259,15 +473,29 @@ export class Model { this.isDynamicBatching = false; } + /** + * @en Attach the model to a [[renderer.RenderScene]] + * @zh 添加模型到渲染场景 [[renderer.RenderScene]] 中 + * @param scene destination scene + */ public attachToScene (scene: RenderScene) { this.scene = scene; this._localDataUpdated = true; } + /** + * @en Detach the model from its render scene + * @zh 移除场景中的模型 + */ public detachFromScene () { this.scene = null; } + /** + * @en Update the model's transform + * @zh 更新模型的变换 + * @param stamp time stamp + */ public updateTransform (stamp: number) { const node = this.transform; // @ts-expect-error TS2445 @@ -282,6 +510,10 @@ export class Model { } } + /** + * @en Update the model's world AABB + * @zh 更新模型的世界空间包围盒 + */ public updateWorldBound () { const node = this.transform; if (node !== null) { @@ -295,6 +527,11 @@ export class Model { } } + /** + * @en Update the model's ubo + * @zh 更新模型的 ubo + * @param stamp time stamp + */ public updateUBOs (stamp: number) { const subModels = this._subModels; for (let i = 0; i < subModels.length; i++) { @@ -321,9 +558,10 @@ export class Model { } /** - * Create the bounding shape of this model - * @param minPos the min position of the model - * @param maxPos the max position of the model + * @en Create the model's AABB + * @zh 创建模型的包围盒 + * @param minPos min position of the AABB + * @param maxPos max position of the AABB */ public createBoundingShape (minPos?: Vec3, maxPos?: Vec3) { if (!minPos || !maxPos) { return; } @@ -335,6 +573,13 @@ export class Model { return new SubModel(); } + /** + * @en Initialize a sub model with the sub mesh data and the material. + * @zh 用子网格数据和材质初始化一个子模型。 + * @param idx sub model's index + * @param subMeshData sub mesh + * @param mat sub material + */ public initSubModel (idx: number, subMeshData: RenderingSubMesh, mat: Material) { this.initialize(); @@ -355,17 +600,33 @@ export class Model { this._updateAttributesAndBinding(idx); } + /** + * @en Set material for a given sub model + * @zh 为指定的子模型设置材质 + * @param idx sub model's index + * @param subMesh sub mesh + */ public setSubModelMesh (idx: number, subMesh: RenderingSubMesh) { if (!this._subModels[idx]) { return; } this._subModels[idx].subMesh = subMesh; } + /** + * @en Set a sub material + * @zh 设置一个子材质 + * @param idx sub model's index + * @param mat sub material + */ public setSubModelMaterial (idx: number, mat: Material) { if (!this._subModels[idx]) { return; } this._subModels[idx].passes = mat.passes; this._updateAttributesAndBinding(idx); } + /** + * @en Pipeline changed callback + * @zh 管线更新回调 + */ public onGlobalPipelineStateChanged () { const subModels = this._subModels; for (let i = 0; i < subModels.length; i++) { @@ -373,6 +634,10 @@ export class Model { } } + /** + * @en Shader macro changed callback + * @zh Shader 宏更新回调 + */ public onMacroPatchesStateChanged () { const subModels = this._subModels; for (let i = 0; i < subModels.length; i++) { @@ -387,12 +652,20 @@ export class Model { } } + /** + * @en Update the light map + * @zh 更新光照贴图 + * @param texture light map + * @param uvParam uv coordinate + */ public updateLightingmap (texture: Texture2D | null, uvParam: Vec4) { Vec4.toArray(this._localData, uvParam, UBOLocal.LIGHTINGMAP_UVPARAM); this._localDataUpdated = true; this._lightmap = texture; this._lightmapUVParam = uvParam; + this.onMacroPatchesStateChanged(); + if (texture === null) { texture = builtinResMgr.get('empty-texture'); } @@ -403,8 +676,6 @@ export class Model { const subModels = this._subModels; for (let i = 0; i < subModels.length; i++) { const { descriptorSet } = subModels[i]; - // TODO: should manage lightmap macro switches automatically - // USE_LIGHTMAP -> CC_USE_LIGHTMAP descriptorSet.bindTexture(UNIFORM_LIGHTMAP_TEXTURE_BINDING, gfxTexture); descriptorSet.bindSampler(UNIFORM_LIGHTMAP_TEXTURE_BINDING, sampler); descriptorSet.update(); @@ -412,6 +683,10 @@ export class Model { } } + /** + * @en Update the shadow bias + * @zh 更新阴影偏移 + */ public updateLocalShadowBias () { const sv = this._localData; sv[UBOLocal.LOCAL_SHADOW_BIAS + 0] = this._shadowBias; @@ -421,8 +696,17 @@ export class Model { this._localDataUpdated = true; } + /** + * @en Return shader's macro patches + * @zh 获取 shader 宏 + * @param subModelIndex sub model's index + */ public getMacroPatches (subModelIndex: number): IMacroPatch[] | null { - return this.receiveShadow ? shadowMapPatches : null; + let patches = this.receiveShadow ? shadowMapPatches : null; + if (this._lightmap != null) { + patches = patches ? patches.concat(lightMapPatches) : lightMapPatches; + } + return patches; } protected _updateAttributesAndBinding (subModelIndex: number) { diff --git a/cocos/core/renderer/scene/octree.ts b/cocos/core/renderer/scene/octree.ts index 65cb838427..4f67dd7970 100644 --- a/cocos/core/renderer/scene/octree.ts +++ b/cocos/core/renderer/scene/octree.ts @@ -26,9 +26,13 @@ import { Vec3 } from '../../math/vec3'; import { OctreeInfo } from '../../scene-graph/scene-globals'; +/** + * @en The octree culling configuration of the render scene + * @zh 渲染场景的八叉树剔除配置 + */ export class Octree { /** - * @en enable octree + * @en Whether octree culling is enabled in the render scene * @zh 是否开启八叉树加速剔除 */ set enabled (val: boolean) { @@ -39,7 +43,7 @@ export class Octree { } /** - * @en min pos of scene bounding box + * @en Minimum position of the scene's bounding box * @zh 场景包围盒最小值 */ get minPos (): Vec3 { @@ -50,7 +54,7 @@ export class Octree { } /** - * @en max pos of scene bounding box + * @en Maximum position of the scene's bounding box * @zh 场景包围盒最大值 */ get maxPos (): Vec3 { @@ -61,7 +65,7 @@ export class Octree { } /** - * @en depth of octree + * @en The depth of the octree * @zh 八叉树深度 */ get depth (): number { diff --git a/cocos/core/renderer/scene/shadows.ts b/cocos/core/renderer/scene/shadows.ts index 9b161cddac..77df409c7e 100644 --- a/cocos/core/renderer/scene/shadows.ts +++ b/cocos/core/renderer/scene/shadows.ts @@ -122,6 +122,10 @@ export const PCFType = Enum({ const SHADOW_TYPE_NONE = ShadowType.ShadowMap + 1; +/** + * @en The global shadow's configuration of the render scene + * @zh 渲染场景的全局阴影配置 + */ export class Shadows { /** * @en MAX_FAR. This is shadow camera max far. @@ -218,6 +222,10 @@ export class Shadows { this._shadowMapDirty = val; } + /** + * @en The transform matrix of the light source + * @zh 光源的变换矩阵 + */ public get matLight () { return this._matLight; } @@ -243,9 +251,28 @@ export class Shadows { public maxReceived = 4; // local set + /** + * @internal + */ + /** + * @en The far clip plane of the shadow camera + * @zh 阴影相机的远裁剪平面 + */ public shadowCameraFar = 0; + /** + * @en Shadow camera's view matrix + * @zh 阴影相机的视图矩阵 + */ public matShadowView = new Mat4(); + /** + * @en Shadow camera's projection matrix + * @zh 阴影相机的投影矩阵 + */ public matShadowProj = new Mat4(); + /** + * @en Shadow camera's view projection matrix + * @zh 阴影相机的视图投影矩阵 + */ public matShadowViewProj = new Mat4(); protected _matLight = new Mat4(); protected _material: Material | null = null; @@ -260,6 +287,12 @@ export class Shadows { protected _size: Vec2 = new Vec2(512, 512); protected _shadowMapDirty = false; + /** + * @en Get the shader for the planar shadow with macro patches + * @zh 通过指定宏获取平面阴影的 Shader 对象 + * @param patches The macro patches for the shader + * @returns The shader for the planar shadow + */ public getPlanarShader (patches: IMacroPatch[] | null): Shader | null { if (!this._material) { this._material = new Material(); @@ -269,6 +302,12 @@ export class Shadows { return this._material.passes[0].getShaderVariant(patches); } + /** + * @en Get the shader which support instancing draw for the planar shadow with macro patches + * @zh 通过指定宏获取支持实例化渲染的平面阴影的 Shader 对象 + * @param patches The macro patches for the shader + * @returns The shader for the planar shadow + */ public getPlanarInstanceShader (patches: IMacroPatch[] | null): Shader | null { if (!this._instancingMaterial) { this._instancingMaterial = new Material(); diff --git a/cocos/core/renderer/scene/skybox.ts b/cocos/core/renderer/scene/skybox.ts index de273f99fe..c467cfaab0 100644 --- a/cocos/core/renderer/scene/skybox.ts +++ b/cocos/core/renderer/scene/skybox.ts @@ -67,7 +67,16 @@ export const EnvironmentLightingType = Enum({ DIFFUSEMAP_WITH_REFLECTION: 2, }); +/** + * @en The skybox configuration of the render scene, + * currently some rendering options like hdr and ibl lighting configuration is also here. + * @zh 渲染场景的天空盒配置,目前一些渲染配置,比如 HDR 模式和环境光照配置也在 Skybox 中。 + */ export class Skybox { + /** + * @en The Model object of the skybox + * @zh 天空盒的 Model 对象 + */ get model (): Model | null { return this._model; } @@ -84,8 +93,9 @@ export class Skybox { this._enabled = val; if (val) this.activate(); else this._updatePipeline(); } + /** - * @en HDR + * @en Whether HDR mode is enabled * @zh 是否启用HDR? */ get useHDR (): boolean { @@ -98,7 +108,7 @@ export class Skybox { } /** - * @en Whether use IBL + * @en Whether use image based lighting for PBR materials * @zh 是否启用IBL? */ get useIBL (): boolean { @@ -200,6 +210,7 @@ export class Skybox { protected _useDiffuseMap = false; protected _editableMaterial: MaterialInstance | null = null; + public initialize (skyboxInfo: SkyboxInfo) { this._enabled = skyboxInfo.enabled; this._useIBL = skyboxInfo.useIBL; @@ -207,24 +218,26 @@ export class Skybox { this._useHDR = skyboxInfo.useHDR; } + /** + * @en Set the environment maps for HDR and LDR mode + * @zh 为 HDR 和 LDR 模式设置环境贴图 + * @param envmapHDR @en Environment map for HDR mode @zh HDR 模式下的环境贴图 + * @param envmapLDR @en Environment map for LDR mode @zh LDR 模式下的环境贴图 + */ public setEnvMaps (envmapHDR: TextureCube | null, envmapLDR: TextureCube | null) { this._envmapHDR = envmapHDR; this._envmapLDR = envmapLDR; - const root = legacyCC.director.root as Root; - const isHDR = root.pipeline.pipelineSceneData.isHDR; - if (isHDR) { - if (envmapHDR) { - root.pipeline.pipelineSceneData.ambient.mipmapCount = envmapHDR.mipmapLevel; - } - } else if (envmapLDR) { - root.pipeline.pipelineSceneData.ambient.mipmapCount = envmapLDR.mipmapLevel; - } - this._updateGlobalBinding(); this._updatePipeline(); } + /** + * @en Set the diffuse maps + * @zh 设置环境光漫反射贴图 + * @param diffuseMapHDR @en Diffuse map for HDR mode @zh HDR 模式下的漫反射贴图 + * @param diffuseMapLDR @en Diffuse map for LDR mode @zh LDR 模式下的漫反射贴图 + */ public setDiffuseMaps (diffuseMapHDR: TextureCube | null, diffuseMapLDR: TextureCube | null) { this._diffuseMapHDR = diffuseMapHDR; this._diffuseMapLDR = diffuseMapLDR; diff --git a/cocos/core/renderer/scene/sphere-light.ts b/cocos/core/renderer/scene/sphere-light.ts index 26f6230eed..f87ce08692 100644 --- a/cocos/core/renderer/scene/sphere-light.ts +++ b/cocos/core/renderer/scene/sphere-light.ts @@ -28,11 +28,24 @@ import { legacyCC } from '../../global-exports'; import { Vec3 } from '../../math'; import { Light, LightType, nt2lm } from './light'; +/** + * @en The sphere light representation in the render scene, it will light up a spherical area in the scene. + * It doesn't support shadow generation currently. + * @zh 渲染场景中的球面光抽象,可以照亮场景中的一个球形区域,目前还不支持生成阴影。 + */ export class SphereLight extends Light { + /** + * @en The world position of the light source + * @zh 光源中心点的世界坐标 + */ get position () { return this._pos; } + /** + * @en The size of the light source + * @zh 球面光源的尺寸 + */ set size (size: number) { this._size = size; } @@ -41,6 +54,10 @@ export class SphereLight extends Light { return this._size; } + /** + * @en The lighting range of the light source + * @zh 球面光源的光照范围 + */ set range (range: number) { this._range = range; @@ -51,6 +68,10 @@ export class SphereLight extends Light { return this._range; } + /** + * @en The luminance of the light source + * @zh 光源的亮度 + */ get luminance (): number { const isHDR = (legacyCC.director.root).pipeline.pipelineSceneData.isHDR; if (isHDR) { @@ -68,6 +89,10 @@ export class SphereLight extends Light { } } + /** + * @en The luminance of the light source in HDR mode + * @zh HDR 模式下光源的亮度 + */ get luminanceHDR () { return this._luminanceHDR; } @@ -75,10 +100,18 @@ export class SphereLight extends Light { this._luminanceHDR = value; } + /** + * @en The luminance of the light source in LDR mode + * @zh LDR 模式下光源的亮度 + */ set luminanceLDR (value: number) { this._luminanceLDR = value; } + /** + * @en The AABB bounding box of the lighting area + * @zh 受光源影响范围的 AABB 包围盒 + */ get aabb () { return this._aabb; } @@ -108,6 +141,10 @@ export class SphereLight extends Light { this.luminanceLDR = 1.0; } + /** + * @en Update the lighting area + * @zh 更新光源影响范围 + */ public update () { if (this._node && (this._node.hasChangedFlags || this._needUpdate)) { this._node.getWorldPosition(this._pos); diff --git a/cocos/core/renderer/scene/spot-light.ts b/cocos/core/renderer/scene/spot-light.ts index 1ff2100037..ca1fbe3501 100644 --- a/cocos/core/renderer/scene/spot-light.ts +++ b/cocos/core/renderer/scene/spot-light.ts @@ -36,15 +36,15 @@ const _matProj = new Mat4(); const _matViewProj = new Mat4(); const _matViewProjInv = new Mat4(); +/** + * @en The spot light representation in the render scene, it will light up a cone area in the direction of the light, it supports shadow generation. + * @zh 渲染场景中的聚光灯抽象,可以照亮光源方向上的一个锥形区域,支持生成阴影。 + */ export class SpotLight extends Light { protected _dir: Vec3 = new Vec3(1.0, -1.0, -1.0); protected _range = 5.0; - /** - * @en Cached uniform variables. - * @zh 缓存下来的 uniform 变量。 - */ protected _spotAngle: number = Math.cos(Math.PI / 6); protected _pos: Vec3; @@ -67,18 +67,24 @@ export class SpotLight extends Light { protected _luminanceLDR = 0; - protected _aspect = 0; - // Shadow map properties protected _shadowEnabled = false; protected _shadowPcf = PCFType.HARD; protected _shadowBias = 0.00001; protected _shadowNormalBias = 0.0; + /** + * @en The world position of the light source + * @zh 光源的世界坐标 + */ get position () { return this._pos; } + /** + * @en The size of the spot light source + * @zh 聚光灯的光源尺寸 + */ set size (size: number) { this._size = size; } @@ -87,6 +93,10 @@ export class SpotLight extends Light { return this._size; } + /** + * @en The lighting range of the spot light + * @zh 聚光灯的光照范围 + */ set range (range: number) { this._range = range; @@ -97,6 +107,10 @@ export class SpotLight extends Light { return this._range; } + /** + * @en The luminance of the light source + * @zh 光源的亮度 + */ get luminance (): number { const isHDR = (legacyCC.director.root).pipeline.pipelineSceneData.isHDR; if (isHDR) { @@ -114,6 +128,10 @@ export class SpotLight extends Light { } } + /** + * @en The luminance of the light source in HDR mode + * @zh HDR 模式下光源的亮度 + */ get luminanceHDR () { return this._luminanceHDR; } @@ -121,6 +139,10 @@ export class SpotLight extends Light { this._luminanceHDR = value; } + /** + * @en The luminance of the light source in LDR mode + * @zh LDR 模式下光源的亮度 + */ get luminanceLDR () { return this._luminanceLDR; } @@ -128,16 +150,25 @@ export class SpotLight extends Light { this._luminanceLDR = value; } + /** + * @en The direction of the spot light + * @zh 聚光灯的照明方向 + */ get direction (): Vec3 { return this._dir; } - // 获取 cache 下来的 cos(angle / 2) 属性值,uniform 里需要 + /** + * @en The setter will take the value as the cone angle, + * but the getter will give you the cosine value of the half cone angle: `cos(angle / 2)`. + * As the in-consistence is not acceptable for a property, please do not use it. + * @zh 赋值时这个属性会把输入值当做聚光灯光照区域的锥角,但是获取时返回的是 cos(angle / 2)。 + * 由于这种不一致性,请不要使用这个属性。 + * @internal + */ get spotAngle () { return this._spotAngle; } - - // 设置用户指定的全角弧度,同时计算 cache 下来的 cos(angle / 2) 属性值,uniform 里需要。 set spotAngle (val: number) { this._angle = val; this._spotAngle = Math.cos(val * 0.5); @@ -145,30 +176,28 @@ export class SpotLight extends Light { this._needUpdate = true; } + /** + * @en The cone angle of the lighting area + * @zh 聚光灯锥角 + */ get angle () { return this._angle; } - set aspect (val: number) { - this._aspect = val; - - this._needUpdate = true; - } - - get aspect (): number { - return this._aspect; - } - get aabb () { return this._aabb; } + /** + * @en The frustum of the lighting area + * @zh 受光源影响范围的截椎体 + */ get frustum () { return this._frustum; } /** - * @en Whether activate shadow + * @en Whether shadow casting is enabled * @zh 是否启用阴影? */ get shadowEnabled () { @@ -179,9 +208,9 @@ export class SpotLight extends Light { } /** - * @en get or set shadow pcf. - * @zh 获取或者设置阴影pcf等级。 - */ + * @en The pcf level of the shadow generation. + * @zh 获取或者设置阴影 pcf 等级。 + */ get shadowPcf () { return this._shadowPcf; } @@ -190,9 +219,9 @@ export class SpotLight extends Light { } /** - * @en get or set shadow map sampler offset - * @zh 获取或者设置阴影纹理偏移值 - */ + * @en The depth offset of shadow to avoid moire pattern artifacts + * @zh 阴影的深度偏移, 可以减弱跨像素导致的条纹状失真 + */ get shadowBias () { return this._shadowBias; } @@ -201,7 +230,7 @@ export class SpotLight extends Light { } /** - * @en get or set normal bias. + * @en The normal bias of the shadow map. * @zh 设置或者获取法线偏移。 */ get shadowNormalBias () { @@ -224,7 +253,6 @@ export class SpotLight extends Light { const size = 0.15; this.size = size; - this.aspect = 1.0; this.luminanceHDR = 1700 / nt2lm(size); this.luminanceLDR = 1.0; this.range = Math.cos(Math.PI / 6); diff --git a/cocos/core/renderer/scene/submodel.ts b/cocos/core/renderer/scene/submodel.ts index 3fec87adec..42fcaab37c 100644 --- a/cocos/core/renderer/scene/submodel.ts +++ b/cocos/core/renderer/scene/submodel.ts @@ -37,12 +37,10 @@ const _dsInfo = new DescriptorSetInfo(null!); const MAX_PASS_COUNT = 8; /** - * @en A representation of a sub model - * A model can contain multiple sub-models, each sub-model corresponds to a material and corresponds to a sub-mesh resource. - * Each submodel is a drawing unit, and in non-batch mode, a submodel makes one draw call. - * @zh 代表一个子模型 - * 一个模型可以包含多个子模型,每个子模型对应一个材质,并对应一个子网格资源。 - * 每个子模型是一个绘制单位,非合批模式下,一个子模型进行一次绘制调用。 + * @en A sub part of the model, it describes how to render a specific sub mesh. + * It contains geometry information in [[RenderingSubMesh]] and all sort of rendering configuration like shaders, macro patches, passes etc. + * @zh 组成模型对象的子模型,它用来描述如何渲染模型的一个子网格。 + * 它包含 [[RenderingSubMesh]] 代表的几何网格信息和所有渲染需要的数据,比如着色器程序,着色器宏定义,渲染 pass,等。 */ export class SubModel { protected _device: Device | null = null; @@ -66,6 +64,10 @@ export class SubModel { * 子模型的 passes * @param passes @en The passes @zh 设置的 passes */ + /** + * @en Render passes for the sub-model + * @zh 子模型的渲染 pass + */ set passes (passes) { const passLengh = passes.length; if (passLengh > MAX_PASS_COUNT) { @@ -91,22 +93,16 @@ export class SubModel { } /** - * @en - * sub model's shaders - * @zh - * 子模型的着色器 - * @returns @en The shaders @zh 返回的着色器 + * @en Shaders for the sub-model, each shader corresponds to one of the [[passes]] + * @zh 子模型的着色器程序列表,每个着色器程序对应其中一个渲染 [[passes]] */ get shaders (): Shader[] { return this._shaders!; } /** - * @en - * sub model's sub mesh - * @zh - * 子模型的子网格资源 - * @param subMesh @en The sub mesh @zh 设置的子网格 + * @en The rendering sub mesh for the sub-model, each sub-model can only have one sub mesh. + * @zh 用于渲染的子网格对象,每个子模型只能包含一个子网格。 */ set subMesh (subMesh) { this._inputAssembler!.destroy(); @@ -120,11 +116,8 @@ export class SubModel { } /** - * @en - * sub model's rendering proirity - * @zh - * 子模型的渲染优先级 - * @param val @en The rendering priority @zh 设置的渲染优先级 + * @en The rendering priority of the sub-model + * @zh 子模型的渲染优先级 */ set priority (val) { this._priority = val; @@ -135,66 +128,48 @@ export class SubModel { } /** - * @en - * sub model's input assembler - * @zh - * 子模型的输入汇集器 - * @returns @en The input assembler @zh 返回的输入汇集器 + * @en The low level input assembler which contains geometry data + * @zh 底层渲染用的输入汇集器,包含几何信息 */ get inputAssembler (): InputAssembler { return this._inputAssembler!; } /** - * @en - * sub model's descriptor set - * @zh - * 子模型的描述符集合 - * @returns @en The descriptor set @zh 返回的描述符集合 + * @en The descriptor set used for sub-model rendering + * @zh 底层渲染子模型用的描述符集组 */ get descriptorSet (): DescriptorSet { return this._descriptorSet!; } /** - * @en - * sub model's world bound descriptor set - * @zh - * 子模型的世界包围盒描述符集合 - * @returns @en The world bound descriptor set @zh 返回的世界包围盒描述符集合 + * @en The descriptor set for world bound + * @zh 用于存储世界包围盒的描述符集组 */ get worldBoundDescriptorSet (): DescriptorSet { return this._worldBoundDescriptorSet!; } /** - * @en - * shader's macro - * @zh - * 着色器的宏定义 - * @returns @en The shader's macro @zh 返回的着色器宏定义 + * @en The macro patches for the shaders + * @zh 着色器程序所用的宏定义组合 */ get patches (): IMacroPatch[] | null { return this._patches; } /** - * @en - * planar instance's shader - * @zh - * 平面投影实例化的着色器 - * @returns @en The planar instance's shader @zh 返回的平面投影实例化着色器 + * @en The shader for rendering the planar shadow, instancing draw version. + * @zh 用于渲染平面阴影的着色器,适用于实例化渲染(instancing draw) */ get planarInstanceShader (): Shader | null { return this._planarInstanceShader; } /** - * @en - * planar's shader - * @zh - * 平面投影的着色器 - * @returns @en The planar's shader @zh 返回的平面投影着色器 + * @en The shader for rendering the planar shadow. + * @zh 用于渲染平面阴影的着色器。 */ get planarShader (): Shader | null { return this._planarShader; @@ -288,6 +263,9 @@ export class SubModel { * @zh * 平面阴影实例着色器初始化 */ + /** + * @internal + */ public initPlanarShadowInstanceShader () { const pipeline = (legacyCC.director.root as Root).pipeline; const shadowInfo = pipeline.pipelineSceneData.shadows; @@ -339,10 +317,8 @@ export class SubModel { } /** - * @en - * pipeline state changed callback - * @zh - * 管线状态改变后的回调 + * @en Pipeline changed callback + * @zh 管线更新回调 */ public onPipelineStateChanged (): void { const passes = this._passes; @@ -358,12 +334,9 @@ export class SubModel { this._flushPassInfo(); } - /** - * @en - * macro changed callback - * @zh - * 着色器宏设置改变后的回调 - * @param patches @en The shader's macro @zh 着色器的宏定义 + /** + * @en Shader macro changed callback + * @zh Shader 宏更新回调 */ public onMacroPatchesStateChanged (patches: IMacroPatch[] | null): void { this._patches = patches; diff --git a/cocos/core/root.ts b/cocos/core/root.ts index 9b3c654eb8..c84464b462 100644 --- a/cocos/core/root.ts +++ b/cocos/core/root.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module core - */ - import { builtinResMgr } from './builtin'; import { Pool } from './memop'; import { RenderPipeline, createDefaultPipeline, DeferredPipeline } from './pipeline'; diff --git a/cocos/core/scene-graph/base-node-dev.ts b/cocos/core/scene-graph/base-node-dev.ts index bccb8ed588..0377b84386 100644 --- a/cocos/core/scene-graph/base-node-dev.ts +++ b/cocos/core/scene-graph/base-node-dev.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { EDITOR, DEV, TEST } from 'internal:constants'; import { CCObject } from '../data/object'; import * as js from '../utils/js'; diff --git a/cocos/core/scene-graph/base-node.ts b/cocos/core/scene-graph/base-node.ts index 99f98e79c4..e9b5659fb7 100644 --- a/cocos/core/scene-graph/base-node.ts +++ b/cocos/core/scene-graph/base-node.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module scene-graph - */ - import { ccclass, editable, serializable } from 'cc.decorator'; import { DEV, DEBUG, EDITOR } from 'internal:constants'; import { Component } from '../components/component'; @@ -219,14 +214,24 @@ export class BaseNode extends CCObject implements ISchedulable { return this._eventProcessor; } + /** + * @internal + */ protected static idGenerator = idGenerator; - // For walk + /** + * for walk + * @internal + */ protected static _stacks: Array> = [[]]; + /** + * @internal + */ protected static _stackId = 0; /** * Call `_updateScene` of specified node. + * @internal * @param node The node. */ protected static _setScene (node: BaseNode) { @@ -332,7 +337,10 @@ export class BaseNode extends CCObject implements ISchedulable { protected _siblingIndex = 0; /** + * @en * record scene's id when set this node as persist node + * @zh + * 当设置节点为常驻节点时记录场景的 id * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. */ public _originalSceneId = ''; @@ -340,6 +348,7 @@ export class BaseNode extends CCObject implements ISchedulable { /** * Set `_scene` field of this node. * The derived `Scene` overrides this method to behavior differently. + * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. */ protected _updateScene () { if (this._parent == null) { @@ -1403,7 +1412,10 @@ export class BaseNode extends CCObject implements ISchedulable { protected _onSiblingIndexChanged? (siblingIndex: number): void; /** + * @en * Ensures that this node has already had the specified component(s). If not, this method throws. + * @zh + * 检查节点已经包含对应的组件,如果没有,则抛出异常 * @param constructor Constructor of the component. * @throws If one or more component of same type have been existed in this node. */ diff --git a/cocos/core/scene-graph/component-scheduler.ts b/cocos/core/scene-graph/component-scheduler.ts index 139c47cbf1..88b74e7cca 100644 --- a/cocos/core/scene-graph/component-scheduler.ts +++ b/cocos/core/scene-graph/component-scheduler.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module scene-graph - */ - import { EDITOR, SUPPORT_JIT, DEV, TEST } from 'internal:constants'; import { CCObject } from '../data/object'; import { MutableForwardIterator } from '../utils/array'; diff --git a/cocos/core/scene-graph/find.ts b/cocos/core/scene-graph/find.ts index f24a598568..9d5f244fc1 100644 --- a/cocos/core/scene-graph/find.ts +++ b/cocos/core/scene-graph/find.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module scene-graph - */ - import { DEV } from 'internal:constants'; import { warnID } from '../platform/debug'; import { Node } from './node'; diff --git a/cocos/core/scene-graph/index.ts b/cocos/core/scene-graph/index.ts index a85d2b48f7..21c82d7227 100644 --- a/cocos/core/scene-graph/index.ts +++ b/cocos/core/scene-graph/index.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module scene-graph - */ - import './node-event-processor'; import './deprecated'; @@ -36,5 +31,6 @@ export { Node } from './node'; export { Scene } from './scene'; export { Layers } from './layers'; export { find } from './find'; +export * from './scene-globals'; export * from './deprecated'; export { default as NodeActivator } from './node-activator'; diff --git a/cocos/core/scene-graph/layers.ts b/cocos/core/scene-graph/layers.ts index b794c883af..570894ecb0 100644 --- a/cocos/core/scene-graph/layers.ts +++ b/cocos/core/scene-graph/layers.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module scene-graph - */ - import { BitMask, Enum } from '../value-types'; import { legacyCC } from '../global-exports'; import { log2 } from '../math/bits'; diff --git a/cocos/core/scene-graph/node-activator.ts b/cocos/core/scene-graph/node-activator.ts index 3bcbb1f4a2..45ac0d4fe3 100644 --- a/cocos/core/scene-graph/node-activator.ts +++ b/cocos/core/scene-graph/node-activator.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module scene-graph - */ - import { EDITOR, DEV, TEST, SUPPORT_JIT, DEBUG } from 'internal:constants'; import { CCObject, isValid } from '../data/object'; import { array, Pool } from '../utils/js'; diff --git a/cocos/core/scene-graph/node-enum.ts b/cocos/core/scene-graph/node-enum.ts index 8d365f6c0e..b087a9c002 100644 --- a/cocos/core/scene-graph/node-enum.ts +++ b/cocos/core/scene-graph/node-enum.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module scene-graph - */ - import { legacyCC } from '../global-exports'; /** diff --git a/cocos/core/scene-graph/node-event-processor.ts b/cocos/core/scene-graph/node-event-processor.ts index b6bdb106e0..89b72b5622 100644 --- a/cocos/core/scene-graph/node-event-processor.ts +++ b/cocos/core/scene-graph/node-event-processor.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { CallbacksInvoker } from '../event/callbacks-invoker'; import { Event, EventMouse, EventTouch } from '../../input/types'; import { Vec2 } from '../math/vec2'; @@ -37,7 +35,7 @@ import { InputEventType, SystemEventTypeUnion } from '../../input/types/event-en const _cachedArray = new Array(16); let _currentHovered: BaseNode | null = null; -let pos = new Vec2(); +const pos = new Vec2(); const _touchEvents = [ NodeEventType.TOUCH_START, @@ -67,8 +65,8 @@ export enum DispatcherEventType { } /** - * @zh - * 节点事件类。 + * @en The event processor for Node + * @zh 节点事件类。 */ export class NodeEventProcessor { public static _maskComp: Constructor | null = null; diff --git a/cocos/core/scene-graph/node-event.ts b/cocos/core/scene-graph/node-event.ts index 5f86ba748d..dd08cd665c 100644 --- a/cocos/core/scene-graph/node-event.ts +++ b/cocos/core/scene-graph/node-event.ts @@ -115,10 +115,10 @@ export enum NodeEventType { /** * @en - * The event type for position, rotation, scale changed.Use the type parameter as [[Node.TransformBit]] to check which part is changed + * The event type for position, rotation, scale changed.Use the type parameter as `Node.TransformBit` to check which part is changed * * @zh - * 节点改变位置、旋转或缩放事件。如果具体需要判断是哪一个事件,可通过判断回调的第一个参数类型是 [[Node.TransformBit]] 中的哪一个来获取 + * 节点改变位置、旋转或缩放事件。如果具体需要判断是哪一个事件,可通过判断回调的第一个参数类型是 `Node.TransformBit` 中的哪一个来获取 * @example * ``` * this.node.on(Node.EventType.TRANSFORM_CHANGED, (type)=>{ diff --git a/cocos/core/scene-graph/node-ui-properties.ts b/cocos/core/scene-graph/node-ui-properties.ts index 10847815c5..abddab4560 100644 --- a/cocos/core/scene-graph/node-ui-properties.ts +++ b/cocos/core/scene-graph/node-ui-properties.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module scene-graph - */ - import { JSB } from 'internal:constants'; import { UIRenderer } from '../../2d/framework/ui-renderer'; import { UITransform } from '../../2d/framework/ui-transform'; diff --git a/cocos/core/scene-graph/node.ts b/cocos/core/scene-graph/node.ts index 6c8cee215d..05efdb72a2 100644 --- a/cocos/core/scene-graph/node.ts +++ b/cocos/core/scene-graph/node.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module scene-graph - */ - import { ccclass, editable, serializable, type, } from 'cc.decorator'; @@ -441,6 +436,9 @@ export class Node extends BaseNode implements CustomSerializable { this._hasChangedFlagsChunk[this._hasChangedFlagsOffset] = val; } + /** + * @internal + */ public [serializeTag] (serializationOutput: SerializationOutput, context: SerializationContext) { if (!EDITOR) { serializationOutput.writeThis(); diff --git a/cocos/core/scene-graph/scene-globals.ts b/cocos/core/scene-graph/scene-globals.ts index 01a0e9de09..4844eac6db 100644 --- a/cocos/core/scene-graph/scene-globals.ts +++ b/cocos/core/scene-graph/scene-globals.ts @@ -19,11 +19,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module scene-graph - */ - import { ccclass, visible, type, displayOrder, readOnly, slide, range, rangeStep, editable, serializable, rangeMin, tooltip, formerlySerializedAs, displayName } from 'cc.decorator'; import { BAIDU } from 'internal:constants'; import { TextureCube } from '../assets/texture-cube'; diff --git a/cocos/core/scene-graph/scene.ts b/cocos/core/scene-graph/scene.ts index a2947551c8..eeff271e40 100644 --- a/cocos/core/scene-graph/scene.ts +++ b/cocos/core/scene-graph/scene.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module scene-graph - */ - import { ccclass, serializable, editable } from 'cc.decorator'; import { EDITOR, TEST } from 'internal:constants'; import { CCObject } from '../data/object'; @@ -170,92 +165,146 @@ export class Scene extends BaseNode { // transform helpers /** + * @en * Refer to [[Node.getPosition]] + * @zh + * 参考 [[Node.getPosition]] */ public getPosition (out?: Vec3): Vec3 { return Vec3.copy(out || new Vec3(), Vec3.ZERO); } /** + * @en * Refer to [[Node.getRotation]] + * @zh + * 参考 [[Node.getRotation]] */ public getRotation (out?: Quat): Quat { return Quat.copy(out || new Quat(), Quat.IDENTITY); } /** + * @en * Refer to [[Node.getScale]] + * @zh + * 参考 [[Node.getScale]] */ public getScale (out?: Vec3): Vec3 { return Vec3.copy(out || new Vec3(), Vec3.ONE); } /** + * @en * Refer to [[Node.getWorldPosition]] + * @zh + * 参考 [[Node.getWorldPosition]] */ public getWorldPosition (out?: Vec3) { return Vec3.copy(out || new Vec3(), Vec3.ZERO); } /** + * @en * Refer to [[Node.getWorldRotation]] + * @zh + * 参考 [[Node.getWorldRotation]] */ public getWorldRotation (out?: Quat) { return Quat.copy(out || new Quat(), Quat.IDENTITY); } /** + * @en * Refer to [[Node.getWorldScale]] + * @zh + * 参考 [[Node.getWorldScale]] */ public getWorldScale (out?: Vec3) { return Vec3.copy(out || new Vec3(), Vec3.ONE); } /** + * @en * Refer to [[Node.getWorldMatrix]] + * @zh + * 参考 [[Node.getWorldMatrix]] */ public getWorldMatrix (out?: Mat4): Mat4 { return Mat4.copy(out || new Mat4(), Mat4.IDENTITY); } /** + * @en * Refer to [[Node.getWorldRS]] + * @zh + * 参考 [[Node.getWorldRS]] */ public getWorldRS (out?: Mat4): Mat4 { return Mat4.copy(out || new Mat4(), Mat4.IDENTITY); } /** + * @en * Refer to [[Node.getWorldRT]] + * @zh + * 参考 [[Node.getWorldRT]] */ public getWorldRT (out?: Mat4): Mat4 { return Mat4.copy(out || new Mat4(), Mat4.IDENTITY); } /** + * @en * Refer to [[Node.position]] + * @zh + * 参考 [[Node.position]] */ public get position (): Readonly { return Vec3.ZERO; } /** + * @en * Refer to [[Node.worldPosition]] + * @zh + * 参考 [[Node.worldPosition]] */ public get worldPosition (): Readonly { return Vec3.ZERO; } /** + * @en * Refer to [[Node.rotation]] + * @zh + * 参考 [[Node.rotation]] */ public get rotation (): Readonly { return Quat.IDENTITY; } /** + * @en * Refer to [[Node.worldRotation]] + * @zh + * 参考 [[Node.worldRotation]] */ public get worldRotation (): Readonly { return Quat.IDENTITY; } /** + * @en * Refer to [[Node.scale]] + * @zh + * 参考 [[Node.scale]] */ public get scale (): Readonly { return Vec3.ONE; } /** + * @en * Refer to [[Node.worldScale]] + * @zh + * 参考 [[Node.worldScale]] */ public get worldScale (): Readonly { return Vec3.ONE; } /** + * @en * Refer to [[Node.eulerAngles]] + * @zh + * 参考 [[Node.eulerAngles]] */ public get eulerAngles (): Readonly { return Vec3.ZERO; } /** + * @en * Refer to [[Node.worldMatrix]] + * @zh + * 参考 [[Node.worldMatrix]] */ public get worldMatrix (): Readonly { return Mat4.IDENTITY; } /** + * @en * Refer to [[Node.updateWorldTransform]] + * @zh + * 参考 [[Node.updateWorldTransform]] */ public updateWorldTransform () {} diff --git a/cocos/core/scheduler.ts b/cocos/core/scheduler.ts index e6187f1f53..c14fc4bdc2 100644 --- a/cocos/core/scheduler.ts +++ b/cocos/core/scheduler.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module core - */ - import IdGenerator from './utils/id-generator'; import { createMap } from './utils/js'; import System from './components/system'; diff --git a/cocos/core/splash-screen.ts b/cocos/core/splash-screen.ts index ca8c264c28..116892a4d5 100644 --- a/cocos/core/splash-screen.ts +++ b/cocos/core/splash-screen.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import * as easing from './easing/easing'; import { Material } from './assets/material'; import { clamp01 } from './math/utils'; diff --git a/cocos/core/utils/array.ts b/cocos/core/utils/array.ts index a1b51e4f2e..2c597e8bed 100644 --- a/cocos/core/utils/array.ts +++ b/cocos/core/utils/array.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module core - */ - import { logID } from '../platform/debug'; export { default as MutableForwardIterator } from './mutable-forward-iterator'; diff --git a/cocos/core/utils/coordinates-converts-utils.ts b/cocos/core/utils/coordinates-converts-utils.ts index 6783091989..3e44ab9722 100644 --- a/cocos/core/utils/coordinates-converts-utils.ts +++ b/cocos/core/utils/coordinates-converts-utils.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module core - */ - import { Camera } from '../components/camera-component'; import { Vec3 } from '../math'; import { Node } from '../scene-graph'; @@ -41,11 +36,11 @@ const _vec3 = new Vec3(); * Conversion of non-UI nodes to UI Node (Local) Space coordinate system. * @zh * 非 UI 节点转换到 UI 节点(局部) 空间坐标系。 - * @deprecated 将在 1.2 移除,请使用 Camera 的 `convertToUINode`。 - * @param mainCamera 主相机。 - * @param wpos 世界空间位置。 - * @param uiNode UI节点。 - * @param out 返回局部坐标。 + * @deprecated since Cocos Creator 3D v1.2, please use [[Camera.convertToUINode]] + * @param mainCamera @en The main camera @zh 主相机 + * @param wpos @en The world space location. @zh 世界空间位置。 + * @param uiNode @en The UI node. @zh UI 节点。 + * @param out @en The output local position in UI @zh 返回 UI 节点局部坐标。 */ export function WorldNode3DToLocalNodeUI (mainCamera: Camera, wpos: Vec3, uiNode: Node, out?: Vec3) { if (!out) { @@ -62,11 +57,11 @@ export function WorldNode3DToLocalNodeUI (mainCamera: Camera, wpos: Vec3, uiNode * @en * Conversion of non-UI nodes to UI Node (World) Space coordinate system. * @zh - * 非 UI 节点转换到 UI 节点(世界) 空间坐标系。 - * @deprecated 将在 1.2 移除,请使用 Camera 的 `convertToUINode`。 - * @param mainCamera 主相机。 - * @param wpos 世界空间位置。 - * @param out 返回世界坐标。 + * 非 UI 节点转换到 UI 节点(世界)空间坐标系。 + * @deprecated since Cocos Creator 3D v1.2, please use [[Camera.convertToUINode]] + * @param mainCamera @en The main camera @zh 主相机 + * @param wpos @en The world space location. @zh 世界空间位置。 + * @param out @en The output world position in UI @zh 返回 UI 空间世界坐标。 */ export function WorldNode3DToWorldNodeUI (mainCamera: Camera, wpos: Vec3, out?: Vec3) { if (!out) { @@ -82,7 +77,7 @@ export function WorldNode3DToWorldNodeUI (mainCamera: Camera, wpos: Vec3, out?: /** * @en It will be removed in v1.2. Please use [[Camera.convertToUINode]]。 * @zh 将在 v1.2 移除,请使用 Camera 的 `convertToUINode`。 - * @deprecated + * @deprecated since Cocos Creator 3D v1.2 */ const convertUtils = { WorldNode3DToLocalNodeUI, @@ -102,6 +97,7 @@ replaceProperty(legacyCC.pipelineUtils, 'cc.pipelineUtils', [ const out = args[3] || _vec3; camera.convertToUINode(args[1], args[2], out); out.add(args[2].position); + // eslint-disable-next-line @typescript-eslint/no-unsafe-return return args[3] || out.clone(); }, }, diff --git a/cocos/core/utils/decode-uuid.ts b/cocos/core/utils/decode-uuid.ts index 9e3f63282f..4d21bd16da 100644 --- a/cocos/core/utils/decode-uuid.ts +++ b/cocos/core/utils/decode-uuid.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module core - */ - import { TEST } from 'internal:constants'; import { BASE64_VALUES } from './misc'; import { legacyCC } from '../global-exports'; diff --git a/cocos/core/utils/id-generator.ts b/cocos/core/utils/id-generator.ts index 87c5aa1406..a584ccf9c4 100644 --- a/cocos/core/utils/id-generator.ts +++ b/cocos/core/utils/id-generator.ts @@ -23,22 +23,25 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module core - */ - import { EDITOR } from 'internal:constants'; const NonUuidMark = '.'; /** + * @en * ID generator for runtime. + * + * @zh + * 运行时 ID 生成器 */ export default class IDGenerator { - /* + /** + * @en * The global id generator might have a conflict problem once every 365 days, * if the game runs at 60 FPS and each frame 4760273 counts of new id are requested. + * + * @zh + * 全局的 id 生成器,如果游戏以 60 FPS 运行,每帧获取 4760273 个新 id, 则可能在 365 天后发生冲突。 */ public static global = new IDGenerator('global'); @@ -47,7 +50,10 @@ export default class IDGenerator { public prefix: string; /** - * @param [category] You can specify a unique category to avoid id collision with other instance of IdGenerator. + * @en Construct a new id generator + * @zh 构造一个新的 id 生成器 + * + * @param [category] @en You can specify a unique category to avoid id collision with other instance of IdGenerator. @zh 你能指定一个唯一的标识用于避免与其他 id 生成器冲突 */ constructor (category?: string) { // Tnit with a random id to emphasize that the returns id should not be stored in persistence data. diff --git a/cocos/core/utils/js-typed.ts b/cocos/core/utils/js-typed.ts index 165703c12a..e5b2e8e148 100644 --- a/cocos/core/utils/js-typed.ts +++ b/cocos/core/utils/js-typed.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module core - */ - import { EDITOR, DEV, TEST } from 'internal:constants'; import { warnID, error, errorID } from '../platform/debug'; import IDGenerator from './id-generator'; @@ -39,25 +34,38 @@ const classNameTag = '__classname__'; const classIdTag = '__cid__'; /** + * @en * Check the object whether is number or not * If a number is created by using 'new Number(10086)', the typeof it will be "object"... * Then you can use this function if you care about this case. + * @zh + * 检查对象是否是 number 类型,如果通过 'new Number(10086)' 创建了一个数字,则使用 typeof 判断此数字时,将返回 'object' 类型,此时你可以通过此方法来进行判断 + * @param object object to be checked + * @return whether this object is number or not */ export function isNumber (object: any) { return typeof object === 'number' || object instanceof Number; } /** + * @en * Check the object whether is string or not. * If a string is created by using 'new String("blabla")', the typeof it will be "object"... * Then you can use this function if you care about this case. + * @zh + * 检查对象是否是 string 类型,如果通过 'new String("blabla")' 创建了一个字符串,则使用 typeof 判断此字符串时,将返回 'object' 类型,此时你可以通过此方法来进行判断 + * @param object object to be checked + * @return whether this object is string or not */ export function isString (object: any) { return typeof object === 'string' || object instanceof String; } /** + * @en * Checks if the object `obj` does not have one or more enumerable properties (including properties from proto chain). + * @zh + * 检查此对象是否为空对象 * @param obj The object. * @returns The result. Note that if the `obj` is not of type `'object'`, `true` is returned. */ @@ -69,8 +77,12 @@ export function isEmptyObject (obj: any) { } /** + * @en * Define value, just help to call Object.defineProperty.
* The configurable will be true. + * @zh + * 定义值,帮助调用 Object.defineProperty. + * 该属性默认可读写 * @param [writable=false] * @param [enumerable=false] */ @@ -91,7 +103,10 @@ export const value = (() => { })(); /** + * @en * Define get set accessor, just help to call Object.defineProperty(...). + * @zh + * 定义 get set 访问器,帮助调用 Object.defineProperty() * @param [setter=null] * @param [enumerable=false] * @param [configurable=false] @@ -118,7 +133,10 @@ export const getset = (() => { })(); /** + * @en * Define get accessor, just help to call Object.defineProperty(...). + * @zh + * 定义 get 访问器,帮助调用 Object.defineProperty() * @param [enumerable=false] * @param [configurable=false] */ @@ -138,7 +156,10 @@ export const get = (() => { })(); /** - * Define set accessor, just help to call Object.defineProperty(...). + * @en + * Define set accessor, just help to call Object.defineProperty(...) + * @zh + * 定义 set 访问器,帮助调用 Object.defineProperty * @param [enumerable=false] * @param [configurable=false] */ @@ -186,8 +207,11 @@ export function createMap (forceDictMode?: boolean): any { } /** + * @en * Get class name of the object, if object is just a {} (and which class named 'Object'), it will return "". * (modified from the code from this stackoverflow post) + * @zh + * 获取对象的类型名称,如果对象是 {} 字面量,将会返回 "" * @param objOrCtor instance or constructor */ export function getClassName (objOrCtor: any): string { @@ -208,11 +232,11 @@ export function getClassName (objOrCtor: any): string { if (str.charAt(0) === '[') { // str is "[object objectClass]" // eslint-disable-next-line @typescript-eslint/prefer-regexp-exec - arr = str.match(/\[\w+\s*(\w+)\]/); + arr = /\[\w+\s*(\w+)\]/.exec(str); } else { // str is function objectClass () {} for IE Firefox // eslint-disable-next-line @typescript-eslint/prefer-regexp-exec - arr = str.match(/function\s*(\w+)/); + arr = /function\s*(\w+)/.exec(str); } if (arr && arr.length === 2) { retval = arr[1]; @@ -226,7 +250,10 @@ export function getClassName (objOrCtor: any): string { } /** + * @en * Defines a polyfill field for obsoleted codes. + * @zh + * 为废弃代码定义一个填充字段 * @param object - YourObject or YourClass.prototype * @param obsoleted - "OldParam" or "YourClass.OldParam" * @param newExpr - "NewParam" or "YourClass.NewParam" @@ -257,7 +284,10 @@ export function obsolete (object: any, obsoleted: string, newExpr: string, writa } /** + * @en * Defines all polyfill fields for obsoleted codes corresponding to the enumerable properties of props. + * @zh + * 为所有可废弃属性定义填充字段 * @param obj - YourObject or YourClass.prototype * @param objName - "YourObject" or "YourClass" * @param props @@ -274,7 +304,10 @@ const REGEXP_NUM_OR_STR = /(%d)|(%s)/; const REGEXP_STR = /%s/; /** + * @en * A string tool to construct a string with format string. + * @zh + * 通过格式字符串构造一个字符串 * @param msg - A JavaScript string containing zero or more substitution strings (%s). * @param subst - JavaScript objects with which to replace substitution strings within msg. * This gives you additional control over the format of the output. @@ -357,7 +390,10 @@ export function copyAllProperties (source: any, target: any, excepts: Array, ...sources: any[]) } /** + * @en * Copy all properties from arguments[1...n] to object. + * @zh + * 拷贝源对象所有属性到目标对象上,如果有属性冲突,则以源对象为准 * @return The result object. */ export function mixin (object?: Record, ...sources: any[]) { @@ -401,9 +440,13 @@ export function mixin (object?: Record, ...sources: any[]) } /** + * @en * Derive the class from the supplied base class. * Both classes are just native javascript constructors, not created by `Class`, so - * usually you will want to inherit using [[Class]] instead. + * usually you will want to inherit using [[CCClass]] instead. + * @zh + * 将一个类型继承另一个类型 + * 两个类型都需要是 javascript 的构建函数,而不是 `Class`, 所以你通常可以用 [[CCClass]] 来代替 * @param base The baseclass to inherit. * @return The result class. */ @@ -436,7 +479,10 @@ export function extend (cls: Function, base: Function) { } /** + * @en * Get super class. + * @zh + * 获取父类 * @param constructor The constructor of subclass. */ // eslint-disable-next-line @typescript-eslint/ban-types @@ -448,7 +494,13 @@ export function getSuper (constructor: Function) { } /** + * @en * Checks whether subclass is child of superclass or equals to superclass. + * @zh + * 判断一类型是否是另一类型的子类或本身 + * @param subclass sub class to be checked + * @param superclass super class to be checked + * @return whether subclass is child of superclass */ export function isChildClassOf (subclass: unknown, superclass: unknown) { if (subclass && superclass) { @@ -479,7 +531,10 @@ export function isChildClassOf (subclass: unknown, superclass: unknown) { } /** + * @en * Removes all enumerable properties from object. + * @zh + * 移除对象中所有可枚举属性 */ export function clear (object: Record) { for (const key of Object.keys(object)) { @@ -532,7 +587,10 @@ js.unregisterClass to remove the id of unused class'; } /** + * @en * Register the class by specified id, if its classname is not defined, the class name will also be set. + * @zh + * 通过 id 注册类型 * @method _setClassId * @param classId * @param constructor @@ -543,7 +601,10 @@ export const _setClassId = setup('__cid__', _idToClass); const doSetClassName = setup('__classname__', _nameToClass); /** + * @en * Register the class by specified name manually + * @zh + * 通过指定的名称手动注册类型 * @method setClassName * @param className * @param constructor @@ -598,10 +659,14 @@ export function setClassAlias (target: Constructor, alias: string) { } /** - * Unregister a class from fireball. + * @en + * Unregister a class from cocos. * - * If you dont need a registered class anymore, you should unregister the class so that Fireball will not keep its reference anymore. + * If you dont need a registered class anymore, you should unregister the class so that cocos will not keep its reference anymore. * Please note that its still your responsibility to free other references to the class. + * @zh + * 取消注册类型,如果你不再需要一个注册的类,你应该取消注册这个类,这样 cocos 就不会再保留它的引用。 + * 请注意,你仍然有责任释放对该类的其他引用。 * * @param ...constructor - the class you will want to unregister, any number of classes can be added */ @@ -629,7 +694,10 @@ export function unregisterClass (...constructors: Function[]) { } /** + * @en * Get the registered class by id + * @zh + * 通过 id 获取已注册的类型 * @param classId * @return constructor * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. @@ -639,7 +707,10 @@ export function _getClassById (classId) { } /** + * @en * Get the registered class by name + * @zh + * 通过名字获取已注册的类型 * @param classname * @return constructor of the class */ @@ -648,7 +719,10 @@ export function getClassByName (classname) { } /** + * @en * Get class id of the object + * @zh + * 获取对象的 class id * @param obj - instance or constructor * @param [allowTempId = true] - can return temp id in editor * @return diff --git a/cocos/core/utils/misc.ts b/cocos/core/utils/misc.ts index 4566ce0f33..31bdf6d601 100644 --- a/cocos/core/utils/misc.ts +++ b/cocos/core/utils/misc.ts @@ -24,8 +24,6 @@ THE SOFTWARE. */ - - /* eslint-disable no-new-func */ import { EDITOR, DEV } from 'internal:constants'; @@ -45,6 +43,7 @@ for (let i = 0; i < 64; ++i) { values[BASE64_KEYS.charCodeAt(i)] = i; } export const BASE64_VALUES = values; /** + * @engineInternal * @param ctor * @param sameNameGetSets * @param diffNameGetSets @@ -159,15 +158,18 @@ export function isPlainEmptyObj_DEV (obj) { } /** - * @en Clamp a value between from and to. + * @en Clamp a value between from and to.
+ * if the original value is larger than max_inclusive, return max_inclusive.
+ * if the original value is smaller than min_inclusive, return min_inclusive.
+ * else return the original value. * @zh 限定浮点数的最大最小值。
* 数值大于 max_inclusive 则返回 max_inclusive。
* 数值小于 min_inclusive 则返回 min_inclusive。
* 否则返回自身。 - * @param value 目标值 - * @param min_inclusive 最小值 - * @param max_inclusive 最大值 - * @return {Number} + * @param value @en Original value @zh 初始值 + * @param min_inclusive @en Minimum value in between @zh 最小值 + * @param max_inclusive @en Maximum value in between @zh 最大值 + * @return {Number} @en The value clamped @zh 目标值 * @example * var v1 = clampf(20, 0, 20); // 20; * var v2 = clampf(-1, 0, 20); // 0; @@ -185,8 +187,8 @@ export function clampf (value: number, min_inclusive: number, max_inclusive: num /** * @en converts degrees to radians * @zh 角度转弧度 - * @param angle 角度 - * @return {Number} + * @param angle @en The degree to convert @zh 角度 + * @return {Number} The radian. @zh 弧度 */ export function degreesToRadians (angle: number) { return angle * macro.RAD; @@ -195,8 +197,8 @@ export function degreesToRadians (angle: number) { /** * @en converts radians to degrees * @zh 弧度转角度 - * @param angle 弧度 - * @return {Number} + * @param angle @en The radian to convert @zh 弧度 + * @return {Number} @en The degree @zh 角度 */ export function radiansToDegrees (angle) { return angle * macro.DEG; diff --git a/cocos/core/utils/murmurhash2_gc.ts b/cocos/core/utils/murmurhash2_gc.ts index 5465c92b27..18824abd12 100644 --- a/cocos/core/utils/murmurhash2_gc.ts +++ b/cocos/core/utils/murmurhash2_gc.ts @@ -36,8 +36,6 @@ * @return {number} 32-bit positive integer hash */ - - const getUint8ForString = String.prototype.charCodeAt; function getUint8ForArray (this: Uint8Array, idx: number) { return this[idx]; } diff --git a/cocos/core/utils/mutable-forward-iterator.ts b/cocos/core/utils/mutable-forward-iterator.ts index 0c7760513c..f324c709e2 100644 --- a/cocos/core/utils/mutable-forward-iterator.ts +++ b/cocos/core/utils/mutable-forward-iterator.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module core - */ - /** * @example * ``` diff --git a/cocos/core/utils/path.ts b/cocos/core/utils/path.ts index 725e0d0299..cdc452d327 100644 --- a/cocos/core/utils/path.ts +++ b/cocos/core/utils/path.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module core - */ - import { systemInfo } from 'pal/system-info'; import { OS } from '../../../pal/system-info/enum-type'; diff --git a/cocos/core/utils/pool.ts b/cocos/core/utils/pool.ts index 313b099d29..7a75264bfa 100644 --- a/cocos/core/utils/pool.ts +++ b/cocos/core/utils/pool.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module core - */ - type CleanUpFunction = (value: T) => boolean | void; /** diff --git a/cocos/core/utils/prefab/prefab-info.ts b/cocos/core/utils/prefab/prefab-info.ts index c2d937ba5c..36ca3fcc47 100644 --- a/cocos/core/utils/prefab/prefab-info.ts +++ b/cocos/core/utils/prefab/prefab-info.ts @@ -107,6 +107,7 @@ export class MountedComponentsInfo { /** * Prefab实例类 + * @internal */ @ccclass('cc.PrefabInstance') export class PrefabInstance { diff --git a/cocos/core/utils/prefab/utils.ts b/cocos/core/utils/prefab/utils.ts index e140b49b6c..3654e68850 100644 --- a/cocos/core/utils/prefab/utils.ts +++ b/cocos/core/utils/prefab/utils.ts @@ -24,8 +24,6 @@ THE SOFTWARE. */ - - import { EDITOR, SUPPORT_JIT } from 'internal:constants'; import { legacyCC } from '../../global-exports'; import type { Node } from '../../scene-graph/node'; diff --git a/cocos/core/value-types/bitmask.ts b/cocos/core/value-types/bitmask.ts index f81741cce2..acacd57a41 100644 --- a/cocos/core/value-types/bitmask.ts +++ b/cocos/core/value-types/bitmask.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module core/value-types - */ - import { EDITOR, TEST } from 'internal:constants'; import { value } from '../utils/js'; import { legacyCC } from '../global-exports'; @@ -38,8 +33,10 @@ import { errorID } from '../platform/debug'; * Define an BitMask type. * @zh * 定义一个位掩码类型。 - * @param obj A JavaScript literal object containing BitMask names and values - * @return The defined BitMask type + * @param obj + * @en A JavaScript literal object containing BitMask names and values. + * @zh 包含 BitMask 名称和值的 JavaScript 文字对象。 + * @return @en The defined BitMask type @zh 定义的位掩码类型。 */ export function BitMask (obj: T): T { if ('__bitmask__' in obj) { diff --git a/cocos/core/value-types/enum.ts b/cocos/core/value-types/enum.ts index 9b40a4a47d..9d53f730a2 100644 --- a/cocos/core/value-types/enum.ts +++ b/cocos/core/value-types/enum.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module core/value-types - */ - import { EDITOR, TEST, DEV } from 'internal:constants'; import { value } from '../utils/js'; import { legacyCC } from '../global-exports'; @@ -45,8 +40,10 @@ import { assertIsTrue } from '../data/utils/asserts'; * 定义一个枚举类型。
* 用户可以把枚举值设为任意的整数,如果设为 -1,系统将会分配为上一个枚举值 + 1。 * - * @param obj - a JavaScript literal object containing enum names and values, or a TypeScript enum type - * @return the defined enum type + * @param obj + * @en A JavaScript literal object containing enum names and values, or a TypeScript enum type. + * @zh 包含枚举名和值的 JavaScript literal 对象,或者是一个 TypeScript enum 类型。 + * @return @en The defined enum type. @zh 定义的枚举类型。 */ export function Enum (obj: T): T { if ('__enums__' in obj) { @@ -61,7 +58,7 @@ export function Enum (obj: T): T { * Update the enum object properties. * @zh * 更新枚举对象的属性列表。 - * @param obj + * @param obj @en The enum object to update. @zh 需要更新的枚举对象。 */ Enum.update = (obj: T): T => { let lastIndex = -1; @@ -115,7 +112,7 @@ interface EnumExtras { /** * Determines if the object is an enum type. - * @param enumType The object to judge. + * @param enumType @en The object to judge. @zh 需要判断的对象。 */ Enum.isEnum = (enumType: EnumT) => enumType && enumType.hasOwnProperty('__enums__'); @@ -125,7 +122,7 @@ function assertIsEnum (enumType: EnumT): asserts enumType is /** * Get the enumerators from the enum type. - * @param enumType An enum type. + * @param enumType @en An enum type. @zh 枚举类型。 */ Enum.getList = (enumType: EnumT): readonly Enum.Enumerator[] => { assertIsEnum(enumType); @@ -139,7 +136,7 @@ Enum.getList = (enumType: EnumT): readonly Enum.Enumerator (enumType: EnumT): readonly Enum.Enumerator[] { @@ -176,7 +173,9 @@ if (DEV) { * Formally, as a result of invocation on this function with enum type `enumType`: * - `Enum.isEnum(enumType)` returns `true`; * - `Enum.getList(enumType)` returns the enumerators of `enumType`. - * @param enumType An enum type, eg, a kind of type with similar semantic defined by TypeScript. + * @param + * @en enumType An enum type, eg, a kind of type with similar semantic defined by TypeScript. + * @zh 枚举类型,例如 TypeScript 中定义的类型。 */ export function ccenum (enumType: EnumT) { if (!('__enums__' in enumType)) { diff --git a/cocos/core/value-types/index.ts b/cocos/core/value-types/index.ts index a79dbb7e4b..364cfe807f 100644 --- a/cocos/core/value-types/index.ts +++ b/cocos/core/value-types/index.ts @@ -24,8 +24,6 @@ THE SOFTWARE. */ - - export { BitMask } from './bitmask'; export { Enum, ccenum } from './enum'; export { ValueType } from './value-type'; diff --git a/cocos/core/value-types/value-type.ts b/cocos/core/value-types/value-type.ts index c51809b105..530002a576 100644 --- a/cocos/core/value-types/value-type.ts +++ b/cocos/core/value-types/value-type.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module core/value-types - */ - import { errorID } from '../platform/debug'; import * as js from '../utils/js'; import { legacyCC } from '../global-exports'; @@ -40,14 +35,15 @@ import { legacyCC } from '../global-exports'; export class ValueType { /** * @en - * Clone the current object. The clone result of the object should be equal to the current object, i.e. satisfy `this.equals(this, value.clone())`. + * Clone the current object. The clone result of the object should be equal to the current object, + * i.e. satisfy `this.equals(this, value.clone())`. * The base version of this method do nothing and returns `this'. * The derived class **must** rewrite this method and the returned object should not be `this`, i.e. satisfy `this !== this.clone()`. * @zh * 克隆当前值。克隆的结果值应与当前值相等,即满足 `this.equals(this, value.clone())`。 * 本方法的基类版本简单地返回 `this`; * 派生类**必须**重写本方法,并且返回的对象不应当为 `this`,即满足 `this !== this.clone()`。 - * @returns The cloned object + * @returns @en The cloned object. @zh 克隆的对象。 */ public clone (): ValueType { errorID(100, `${js.getClassName(this)}.clone`); @@ -62,8 +58,8 @@ export class ValueType { * @zh * 判断当前值是否与指定值相等。此判断应当具有交换性,即满足 `this.equals(other) === other.equals(this)`。 * 本方法的基类版本简单地返回 `false`。 - * @param other 相比较的值。 - * @returns 相等则返回 `true`,否则返回 `false`。 + * @param other @en The other object @zh 指定值。 + * @returns @en `true` if equal, otherwise returns `false` @zh 如果相等,则返回 `true`,否则返回 `false`。 */ public equals (other: this) { // errorID(100, js.getClassName(this) + '.equals'); @@ -77,7 +73,7 @@ export class ValueType { * @zh * 赋值当前值使其与指定值相等。 * 本方法的基类版本简单地返回 `this`,派生类**必须**重写本方法。 - * @param other The other object + * @param other @en The other object. @zh 指定值。 */ public set (other: this) { errorID(100, `${js.getClassName(this)}.set`); @@ -90,10 +86,10 @@ export class ValueType { * @zh * 返回当前值的字符串表示。 * 本方法的基类版本返回空字符串。 - * @returns The string representation of the current object + * @returns @en The string representation of the current value. @zh 当前值的字符串表示。 */ public toString () { - return `${{}}`; + return `${''}`; } } js.setClassName('cc.ValueType', ValueType); diff --git a/cocos/dragon-bones/ArmatureCache.ts b/cocos/dragon-bones/ArmatureCache.ts index 1485a57c0e..67ecf6457f 100644 --- a/cocos/dragon-bones/ArmatureCache.ts +++ b/cocos/dragon-bones/ArmatureCache.ts @@ -1,6 +1,26 @@ -/** - * @packageDocumentation - * @module dragonBones +/* + Copyright (c) 2020-2022 Xiamen Yaji Software Co., Ltd. + + https://www.cocos.com/ + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ import { Armature, BlendMode, Matrix } from '@cocos/dragonbones-js'; diff --git a/cocos/dragon-bones/ArmatureDisplay.ts b/cocos/dragon-bones/ArmatureDisplay.ts index cb716fcaf9..277ed87a84 100644 --- a/cocos/dragon-bones/ArmatureDisplay.ts +++ b/cocos/dragon-bones/ArmatureDisplay.ts @@ -1,6 +1,26 @@ -/** - * @packageDocumentation - * @module dragonBones +/* + Copyright (c) 2020-2022 Xiamen Yaji Software Co., Ltd. + + https://www.cocos.com/ + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ import { EDITOR } from 'internal:constants'; @@ -367,19 +387,6 @@ export class ArmatureDisplay extends UIRenderer { this._debugBones = value; this._updateDebugDraw(); } - /** - * @en Enabled batch model, if skeleton is complex, do not enable batch, or will lower performance. - * @zh 开启合批,如果渲染大量相同纹理,且结构简单的骨骼动画,开启合批可以降低drawcall,否则请不要开启,cpu消耗会上升。 - * @property {Boolean} enableBatch - * @default false - */ - // @editable - // @tooltip('i18n:COMPONENT.dragon_bones.enabled_batch') - // get enableBatch () { return this._enableBatch; } - // set enableBatch (value) { - // this._enableBatch = value; - // this._updateBatch(); - // } /** * @en @@ -437,12 +444,6 @@ export class ArmatureDisplay extends UIRenderer { protected _debugBones = false; /* protected */ _debugDraw: Graphics | null = null; - /** - * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. - */ - @serializable - public _enableBatch = false; - // DragonBones data store key. /** * @internal @@ -610,37 +611,6 @@ export class ArmatureDisplay extends UIRenderer { } } - // if change use batch mode, just clear material cache - _updateBatch () { - // const baseMaterial = this.getMaterial(0); - // if (baseMaterial) { - // baseMaterial.define('CC_USE_MODEL', !this.enableBatch); - // } - this._materialCache = {}; - this.markForUpdateRenderData(); - } - - // override base class _updateMaterial to set define value and clear material cache - _updateMaterial () { - // const baseMaterial = this.getMaterial(0); - // if (baseMaterial) { - // baseMaterial.define('CC_USE_MODEL', !this.enableBatch); - // baseMaterial.define('USE_TEXTURE', true); - - // const srcBlendFactor = this.premultipliedAlpha ? cc.gfx.BLEND_ONE : cc.gfx.BLEND_SRC_ALPHA; - // const dstBlendFactor = cc.gfx.BLEND_ONE_MINUS_SRC_ALPHA; - - // baseMaterial.setBlend( - // true, - // ccBLEND_FUNC_ADD, - // srcBlendFactor, srcBlendFactor, - // cc.gfx.BLEND_FUNC_ADD, - // dstBlendFactor, dstBlendFactor - // ); - // } - this.markForUpdateRenderData(); - } - __preload () { super.__preload(); this._init(); @@ -945,8 +915,6 @@ export class ArmatureDisplay extends UIRenderer { const aabb = armatureData.aabb; this.node._uiProps.uiTransformComp!.setContentSize(aabb.width, aabb.height); } - - this._updateBatch(); this.attachUtil.init(this); if (this.animationName) { diff --git a/cocos/dragon-bones/ArmatureSystem.ts b/cocos/dragon-bones/ArmatureSystem.ts index f14e016e43..3d6ae5b3fe 100644 --- a/cocos/dragon-bones/ArmatureSystem.ts +++ b/cocos/dragon-bones/ArmatureSystem.ts @@ -1,8 +1,32 @@ +/* + Copyright (c) 2020-2022 Xiamen Yaji Software Co., Ltd. + + https://www.cocos.com/ + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + */ + import { director } from '../core/director'; import { System } from '../core/components'; import { ArmatureDisplay } from './ArmatureDisplay'; import { legacyCC } from '../core/global-exports'; -import { errorID } from '../core'; export class ArmatureSystem extends System { /** diff --git a/cocos/dragon-bones/AttachUtil.ts b/cocos/dragon-bones/AttachUtil.ts index 4c002333d7..715286ee82 100644 --- a/cocos/dragon-bones/AttachUtil.ts +++ b/cocos/dragon-bones/AttachUtil.ts @@ -1,6 +1,26 @@ -/** - * @packageDocumentation - * @module dragonBones +/* + Copyright (c) 2020-2022 Xiamen Yaji Software Co., Ltd. + + https://www.cocos.com/ + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ import { Armature, Matrix } from '@cocos/dragonbones-js'; diff --git a/cocos/dragon-bones/CCArmatureDisplay.ts b/cocos/dragon-bones/CCArmatureDisplay.ts index 56ad1746d9..a41a164c93 100644 --- a/cocos/dragon-bones/CCArmatureDisplay.ts +++ b/cocos/dragon-bones/CCArmatureDisplay.ts @@ -1,18 +1,40 @@ /* eslint-disable @typescript-eslint/no-unsafe-return */ +/* + Copyright (c) 2020-2022 Xiamen Yaji Software Co., Ltd. -/** - * @packageDocumentation - * @module dragonBones + https://www.cocos.com/ + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ import { Armature, DisplayData, IEventDispatcher, Slot } from '@cocos/dragonbones-js'; import { ccclass } from '../core/data/class-decorator'; -import { Vec2, Node, Vec3 } from '../core'; +import { Node, Vec3 } from '../core'; import { EventTarget } from '../core/event'; // eslint-disable-next-line import/named import { CCSlot } from './CCSlot'; import { ArmatureDisplay } from './ArmatureDisplay'; +/** +* @deprecated since v3.5.1, this is an engine private interface that will be removed in the future. +*/ @ccclass('dragonBones.CCArmatureDisplay') export class CCArmatureDisplay extends DisplayData implements IEventDispatcher { get node () { return this; } diff --git a/cocos/dragon-bones/CCFactory.ts b/cocos/dragon-bones/CCFactory.ts index a4fab5295b..6ba848c81e 100644 --- a/cocos/dragon-bones/CCFactory.ts +++ b/cocos/dragon-bones/CCFactory.ts @@ -1,6 +1,26 @@ -/** - * @packageDocumentation - * @module dragonBones +/* + Copyright (c) 2020-2022 Xiamen Yaji Software Co., Ltd. + + https://www.cocos.com/ + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ import { EDITOR } from 'internal:constants'; @@ -17,17 +37,23 @@ import { CCArmatureDisplay } from './CCArmatureDisplay'; * DragonBones factory * @class CCFactory * @extends BaseFactory + * @deprecated since v3.5.1, this is an engine private interface that will be removed in the future. */ @ccclass('CCFactory') export class CCFactory extends BaseFactory implements ISchedulable { + static _factory: CCFactory | null = null; + /** + * @en + * Get an CCFactory instance + * @zh + * 获取一个 CCFactory 实例 * @method getInstance * @return {CCFactory} * @static * @example * let factory = CCFactory.getInstance(); */ - static _factory: CCFactory | null = null; static getInstance () { if (!CCFactory._factory) { CCFactory._factory = new CCFactory(); diff --git a/cocos/dragon-bones/CCSlot.ts b/cocos/dragon-bones/CCSlot.ts index 61f3e8bb2e..4c742628c5 100644 --- a/cocos/dragon-bones/CCSlot.ts +++ b/cocos/dragon-bones/CCSlot.ts @@ -1,6 +1,26 @@ -/** - * @packageDocumentation - * @module dragonBones +/* + Copyright (c) 2020-2022 Xiamen Yaji Software Co., Ltd. + + https://www.cocos.com/ + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ import { BoneType, BinaryOffset, Slot } from '@cocos/dragonbones-js'; @@ -9,7 +29,9 @@ import { ccclass } from '../core/data/class-decorator'; import { CCTextureData } from './CCTextureData'; // @skipLibCheck - +/** +* @deprecated since v3.5.1, this is an engine private interface that will be removed in the future. +*/ @ccclass('dragonBones.CCSlot') export class CCSlot extends Slot { static toString () { @@ -17,27 +39,38 @@ export class CCSlot extends Slot { } /** + * @en Vertices in local coordinate system. + * @zh 局部坐标顶点数据 * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. */ _localVertices: number[]; /** + * @en Indices array of vertex data + * @zh 顶点数组索引 * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. */ _indices: number[]; /** + * @en Local transformation matrix + * @zh 局部坐标系变换矩阵 * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. */ _matrix: Mat4; /** + * @en World transformation matrix + * @zh 世界坐标系变换矩阵 * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. */ public _worldMatrix: Mat4; + protected _worldMatrixDirty: boolean; /** + * @en Color setting on a slot + * @zh 设置在 Slot 上的颜色 * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. */ _color: Color; diff --git a/cocos/dragon-bones/CCTextureData.ts b/cocos/dragon-bones/CCTextureData.ts index 78762e6848..50f0e70e1d 100644 --- a/cocos/dragon-bones/CCTextureData.ts +++ b/cocos/dragon-bones/CCTextureData.ts @@ -1,15 +1,37 @@ -/** - * @packageDocumentation - * @module dragonBones +/* + Copyright (c) 2020-2022 Xiamen Yaji Software Co., Ltd. + + https://www.cocos.com/ + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ import { BaseObject, TextureAtlasData, TextureData } from '@cocos/dragonbones-js'; -import { Size, Vec2 } from '../core'; import { SpriteFrame } from '../2d'; import { TextureBase } from '../core/assets/texture-base'; import { ccclass } from '../core/data/decorators'; import { Rect } from '../core/math/rect'; +/** +* @deprecated since v3.5.1, this is an engine private interface that will be removed in the future. +*/ @ccclass('dragonBones.CCTextureAtlasData') export class CCTextureAtlasData extends TextureAtlasData { get renderTexture () { @@ -63,6 +85,9 @@ export class CCTextureAtlasData extends TextureAtlasData { } } +/** +* @deprecated since v3.5.1, this is an engine private interface that will be removed in the future. +*/ @ccclass('dragonBones.CCTextureData') export class CCTextureData extends TextureData { spriteFrame: SpriteFrame | null = null diff --git a/cocos/dragon-bones/DragonBonesAsset.ts b/cocos/dragon-bones/DragonBonesAsset.ts index 99b6c8aaeb..9189f61516 100644 --- a/cocos/dragon-bones/DragonBonesAsset.ts +++ b/cocos/dragon-bones/DragonBonesAsset.ts @@ -1,18 +1,34 @@ -/* eslint-disable @typescript-eslint/no-unsafe-return */ +/* + Copyright (c) 2020-2022 Xiamen Yaji Software Co., Ltd. -/** - * @packageDocumentation - * @module dragonBones + https://www.cocos.com/ + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ import { EDITOR } from 'internal:constants'; -import { BinaryDataParser, DragonBonesData } from '@cocos/dragonbones-js'; import { Asset } from '../core/assets'; import { ccclass, serializable } from '../core/data/decorators'; import { ArmatureCache } from './ArmatureCache'; -import { Enum, JsonAsset, Node } from '../core'; +import { Enum, Node } from '../core'; import { CCFactory } from './CCFactory'; -import { property } from '../core/data/class-decorator'; import { legacyCC } from '../core/global-exports'; /** @@ -24,8 +40,10 @@ import { legacyCC } from '../core/global-exports'; @ccclass('dragonBones.DragonBonesAsset') export class DragonBonesAsset extends Asset { /** - * @en See http://developer.egret.com/cn/github/egret-docs/DB/dbLibs/dataFormat/index.html - * @zh 可查看 DragonBones 官方文档 http://developer.egret.com/cn/github/egret-docs/DB/dbLibs/dataFormat/index.html + * @en + * See http://developer.egret.com/cn/github/egret-docs/DB/dbLibs/dataFormat/index.html + * @zh + * 可查看 DragonBones 官方文档 http://developer.egret.com/cn/github/egret-docs/DB/dbLibs/dataFormat/index.html * @property {string} dragonBonesJson */ @serializable diff --git a/cocos/dragon-bones/DragonBonesAtlasAsset.ts b/cocos/dragon-bones/DragonBonesAtlasAsset.ts index 440a302c6e..bf6eeb5d4d 100644 --- a/cocos/dragon-bones/DragonBonesAtlasAsset.ts +++ b/cocos/dragon-bones/DragonBonesAtlasAsset.ts @@ -1,7 +1,28 @@ -/** - * @packageDocumentation - * @module dragonBones +/* + Copyright (c) 2020-2022 Xiamen Yaji Software Co., Ltd. + + https://www.cocos.com/ + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ + import { JSB } from 'internal:constants'; import { TextureAtlasData } from '@cocos/dragonbones-js'; import { Asset, Texture2D, Node } from '../core'; diff --git a/cocos/dragon-bones/assembler/index.ts b/cocos/dragon-bones/assembler/index.ts index 37e90a9ffa..63e7c389e6 100644 --- a/cocos/dragon-bones/assembler/index.ts +++ b/cocos/dragon-bones/assembler/index.ts @@ -1,7 +1,4 @@ -/** - * @packageDocumentation - * @module dragonBones - */ + import { IAssemblerManager } from '../../2d/renderer/base'; import { ArmatureDisplay } from '../ArmatureDisplay'; diff --git a/cocos/dragon-bones/assembler/simple.ts b/cocos/dragon-bones/assembler/simple.ts index f111751ae3..867c4b76e9 100644 --- a/cocos/dragon-bones/assembler/simple.ts +++ b/cocos/dragon-bones/assembler/simple.ts @@ -1,10 +1,30 @@ -/** - * @packageDocumentation - * @module dragonBones +/* + Copyright (c) 2020-2022 Xiamen Yaji Software Co., Ltd. + + https://www.cocos.com/ + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ import { Armature, BlendMode } from '@cocos/dragonbones-js'; -import { Color, Mat4, Node, Texture2D, Vec3, director } from '../../core'; +import { Color, Mat4, Node, Texture2D, director } from '../../core'; import { BlendFactor } from '../../core/gfx'; import { TextureBase } from '../../core/assets/texture-base'; import { vfmtPosUvColor } from '../../2d/renderer/vertex-format'; @@ -12,7 +32,7 @@ import { MaterialInstance } from '../../core/renderer/core/material-instance'; import { IAssembler } from '../../2d/renderer/base'; import { Batcher2D } from '../../2d/renderer/batcher-2d'; import { ArmatureFrame } from '../ArmatureCache'; -import { ArmatureDisplay, ArmatureDisplayDrawData } from '../ArmatureDisplay'; +import { ArmatureDisplay } from '../ArmatureDisplay'; import { CCSlot } from '../CCSlot'; import { legacyCC } from '../../core/global-exports'; import { StaticVBAccessor } from '../../2d/renderer/static-vb-accessor'; @@ -94,8 +114,6 @@ function _getSlotMaterial (tex: TextureBase | null, blendMode: BlendMode) { dst = BlendFactor.ONE_MINUS_SRC_ALPHA; break; } - - // const useModel = !_comp!.enableBatch; _comp!.setBlendHash(); return _comp!.getMaterialForBlend(src, dst); } @@ -426,11 +444,6 @@ function updateComponentRenderData (comp: ArmatureDisplay, batcher: Batcher2D) { } let worldMat: Mat4 | undefined; - if (_comp._enableBatch) { - worldMat = _node.worldMatrix as Mat4; - _mustFlush = false; - _handleVal |= NEED_BATCH; - } _vertexFloatCount = 0; _vertexOffset = 0; diff --git a/cocos/dragon-bones/category.json b/cocos/dragon-bones/category.json index 08bdb9836f..c99291e5bf 100644 --- a/cocos/dragon-bones/category.json +++ b/cocos/dragon-bones/category.json @@ -1,7 +1,7 @@ { "title": { - "zh": "Dragon Bones", - "en": "Dragon Bones" + "zh": "DragonBones", + "en": "DragonBones" }, "description": { "zh": "ArmatureDisplay 组件可以对 DragonBones(龙骨)资源进行渲染和播放。", diff --git a/cocos/dragon-bones/deprecated.ts b/cocos/dragon-bones/deprecated.ts new file mode 100644 index 0000000000..f1e1704c1a --- /dev/null +++ b/cocos/dragon-bones/deprecated.ts @@ -0,0 +1,34 @@ +/* + Copyright (c) 2020 Xiamen Yaji Software Co., Ltd. + + https://www.cocos.com/ + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + */ + +import { removeProperty } from '../core/utils/x-deprecated'; +import { ArmatureDisplay } from './ArmatureDisplay'; + +removeProperty(ArmatureDisplay.prototype, 'ArmatureDisplay', [ + { + name: '_enableBatch', + suggest: 'Not support batch render mode', + }, +]); diff --git a/cocos/dragon-bones/index.jsb.ts b/cocos/dragon-bones/index.jsb.ts index 47d2fa86de..193e2a6dfc 100644 --- a/cocos/dragon-bones/index.jsb.ts +++ b/cocos/dragon-bones/index.jsb.ts @@ -1,3 +1,28 @@ +/* + Copyright (c) 2020-2022 Xiamen Yaji Software Co., Ltd. + + https://www.cocos.com/ + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + */ + export enum ExtensionType { FFD = 0, AdjustColor = 10, diff --git a/cocos/dragon-bones/index.ts b/cocos/dragon-bones/index.ts index 8c1099d428..f61305b53b 100644 --- a/cocos/dragon-bones/index.ts +++ b/cocos/dragon-bones/index.ts @@ -1,45 +1,28 @@ -/** - * @packageDocumentation - * @module dragonBones +/* + Copyright (c) 2020-2022 Xiamen Yaji Software Co., Ltd. + + https://www.cocos.com/ + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ -import { EDITOR } from 'internal:constants'; - -/** - * @en - * The global time scale of DragonBones. - * @zh - * DragonBones 全局时间缩放率。 - * @example - * dragonBones.timeScale = 0.8; - */ -// const _timeScale = 1.0; - -// TODO timescale -// Object.defineProperty(dragonBones, 'timeScale', { -// get () { -// return this._timeScale; -// }, -// set (value) { -// this._timeScale = value; -// const factory = this.CCFactory.getInstance(); -// factory._dragonBones.clock.timeScale = value; -// }, -// configurable: true, -// }); - -// export enum DisplayType { -// Image = 0, -// Armature = 1, -// Mesh = 2 -// } - -// export enum ArmatureType { -// Armature = 0, -// MovieClip = 1, -// Stage = 2 -// } - export enum ExtensionType { FFD = 0, AdjustColor = 10, @@ -89,5 +72,6 @@ export * from './DragonBonesAtlasAsset'; export * from './ArmatureDisplay'; export * from './AttachUtil'; export * from './assembler'; +export * from './deprecated'; export * from '@cocos/dragonbones-js'; diff --git a/cocos/input/deprecated.ts b/cocos/input/deprecated.ts index cb6a79ca0d..9b9f0c0c30 100644 --- a/cocos/input/deprecated.ts +++ b/cocos/input/deprecated.ts @@ -23,7 +23,6 @@ THE SOFTWARE. */ - import { markAsWarning, replaceProperty } from '../core/utils/x-deprecated'; import { Event, EventKeyboard, EventMouse, EventTouch, SystemEventType } from './types'; import { SystemEvent } from './system-event'; diff --git a/cocos/input/input.ts b/cocos/input/input.ts index feb294a8d2..1f1a86f92b 100644 --- a/cocos/input/input.ts +++ b/cocos/input/input.ts @@ -24,8 +24,6 @@ THE SOFTWARE. */ - - import { EDITOR, NATIVE } from 'internal:constants'; import { TouchInputSource, MouseInputSource, KeyboardInputSource, AccelerometerInputSource } from 'pal/input'; import { touchManager } from '../../pal/input/touch-manager'; diff --git a/cocos/input/system-event.ts b/cocos/input/system-event.ts index 8c34b1d550..710d0a4337 100644 --- a/cocos/input/system-event.ts +++ b/cocos/input/system-event.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module event - */ - import { EventTarget } from '../core/event'; import { EventAcceleration, EventKeyboard, EventMouse, EventTouch, SystemEventType, Touch } from './types'; import { input, Input } from './input'; diff --git a/cocos/input/types/event-enum.ts b/cocos/input/types/event-enum.ts index e4a84d6ee4..9b74f9773f 100644 --- a/cocos/input/types/event-enum.ts +++ b/cocos/input/types/event-enum.ts @@ -23,10 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module event - */ import { legacyCC } from '../../core/global-exports'; import { NodeEventType } from '../../core/scene-graph/node-event'; diff --git a/cocos/input/types/event/event-keyboard.ts b/cocos/input/types/event/event-keyboard.ts index 77340bcd16..682cfd0c29 100644 --- a/cocos/input/types/event/event-keyboard.ts +++ b/cocos/input/types/event/event-keyboard.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module event - */ - import { Event } from './event'; import { SystemEventTypeUnion, SystemEventType } from '../event-enum'; import { KeyCode } from '../key-code'; diff --git a/cocos/input/types/event/event.ts b/cocos/input/types/event/event.ts index 550ef8e024..8361218363 100644 --- a/cocos/input/types/event/event.ts +++ b/cocos/input/types/event/event.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module event - */ - import { legacyCC } from '../../../core/global-exports'; import { SystemEventTypeUnion } from '../event-enum'; diff --git a/cocos/input/types/touch.ts b/cocos/input/types/touch.ts index ca8f675ce9..ad9c3b8944 100644 --- a/cocos/input/types/touch.ts +++ b/cocos/input/types/touch.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module event - */ - import { Vec2 } from '../../core/math'; import { legacyCC } from '../../core/global-exports'; diff --git a/cocos/particle-2d/define.ts b/cocos/particle-2d/define.ts index c1aac418a0..fd2b508e24 100644 --- a/cocos/particle-2d/define.ts +++ b/cocos/particle-2d/define.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module particle2d - */ - import { Enum } from '../core/value-types'; /** diff --git a/cocos/particle-2d/index.ts b/cocos/particle-2d/index.ts index 2e76f65e12..609a833f94 100644 --- a/cocos/particle-2d/index.ts +++ b/cocos/particle-2d/index.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module particle2d - */ - import { ParticleSystem2D } from './particle-system-2d'; import { MotionStreak } from './motion-streak-2d'; import { MotionStreakAssemblerManager } from './motion-streak-2d-assembler'; diff --git a/cocos/particle-2d/motion-streak-2d-assembler.ts b/cocos/particle-2d/motion-streak-2d-assembler.ts index 35443128d6..1864d4a548 100644 --- a/cocos/particle-2d/motion-streak-2d-assembler.ts +++ b/cocos/particle-2d/motion-streak-2d-assembler.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module particle2d - */ - import { IAssembler, IAssemblerManager } from '../2d/renderer/base'; import { MotionStreak } from './motion-streak-2d'; import { Vec2, Color } from '../core/math'; diff --git a/cocos/particle-2d/motion-streak-2d.ts b/cocos/particle-2d/motion-streak-2d.ts index 8c582c3251..03dd77d497 100644 --- a/cocos/particle-2d/motion-streak-2d.ts +++ b/cocos/particle-2d/motion-streak-2d.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module particle2d - */ - import { ccclass, executeInEditMode, serializable, playOnFocus, menu, help, editable, type } from 'cc.decorator'; import { EDITOR } from 'internal:constants'; import { UIRenderer } from '../2d/framework'; diff --git a/cocos/particle-2d/particle-asset.ts b/cocos/particle-2d/particle-asset.ts index 9e6a246541..ee2eee667a 100644 --- a/cocos/particle-2d/particle-asset.ts +++ b/cocos/particle-2d/particle-asset.ts @@ -24,18 +24,14 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module asset - */ - import { ccclass, serializable, editable } from '../core/data/decorators'; import { Asset } from '../core/assets/asset'; import { SpriteFrame } from '../2d/assets/sprite-frame'; import { legacyCC } from '../core/global-exports'; /** - * Class for particle asset handling. + * @en Class for 2D particle asset handling. + * @zh 2D 粒子资产 * @class ParticleAsset * @extends Asset */ diff --git a/cocos/particle-2d/particle-simulator-2d.ts b/cocos/particle-2d/particle-simulator-2d.ts index 05bfd0eaf6..b7663f60f0 100644 --- a/cocos/particle-2d/particle-simulator-2d.ts +++ b/cocos/particle-2d/particle-simulator-2d.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module particle2d - */ - import { Vec2, Color } from '../core/math'; import Pool from '../core/utils/pool'; import { clampf, degreesToRadians, radiansToDegrees } from '../core/utils/misc'; diff --git a/cocos/particle-2d/particle-system-2d-assembler.ts b/cocos/particle-2d/particle-system-2d-assembler.ts index ca898159f9..fc3f37f9a1 100644 --- a/cocos/particle-2d/particle-system-2d-assembler.ts +++ b/cocos/particle-2d/particle-system-2d-assembler.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module particle2d - */ - import { IAssembler, IAssemblerManager } from '../2d/renderer/base'; import { ParticleSystem2D } from './particle-system-2d'; import { MeshRenderData } from '../2d/renderer/render-data'; diff --git a/cocos/particle-2d/particle-system-2d.ts b/cocos/particle-2d/particle-system-2d.ts index 20eeeb6cc7..51ab06e00d 100644 --- a/cocos/particle-2d/particle-system-2d.ts +++ b/cocos/particle-2d/particle-system-2d.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module particle2d - */ - import { ccclass, editable, type, displayOrder, menu, executeInEditMode, serializable, playOnFocus, tooltip, visible, formerlySerializedAs } from 'cc.decorator'; import { EDITOR } from 'internal:constants'; @@ -143,43 +138,32 @@ function getParticleComponents (node): ParticleSystem2D[] { } /** - * Particle System base class. - * Attributes of a Particle System: - * - emmision rate of the particles - * - Gravity Mode (Mode A): - * - gravity - * - direction - * - speed +- variance - * - tangential acceleration +- variance - * - radial acceleration +- variance - * - Radius Mode (Mode B): - * - startRadius +- variance - * - endRadius +- variance - * - rotate +- variance - * - Properties common to all modes: - * - life +- life variance - * - start spin +- variance - * - end spin +- variance - * - start size +- variance - * - end size +- variance - * - start color +- variance - * - end color +- variance - * - life +- variance - * - blending function - * - texture - * Cocos also supports particles generated by Particle Designer (http://particledesigner.71squared.com/). - * 'Radius Mode' in Particle Designer uses a fixed emit rate of 30 hz. Since that can't be guaranteed in cocos, - * cocos uses a another approach, but the results are almost identical. - * cocos supports all the variables used by Particle Designer plus a bit more: + * @en Particle System base class. + * cocos2d also supports particles generated by Particle Designer (http://particledesigner.71squared.com/). + * 'Radius Mode' in Particle Designer uses a fixed emit rate of 30 hz. Since that can't be guarateed in cocos2d, + * cocos2d uses a another approach, but the results are almost identical. + * cocos2d supports all the variables used by Particle Designer plus a bit more: * - spinning particles (supported when using ParticleSystem) * - tangential acceleration (Gravity mode) * - radial acceleration (Gravity mode) * - radius direction (Radius mode) (Particle Designer supports outwards to inwards direction only) * It is possible to customize any of the above mentioned properties in runtime. Example: - * - * @example * emitter.radialAccel = 15; * emitter.startSpin = 0; + * + * @zh 2D 粒子基础类型 + * cocos2d 同样支 Particle Designer (http://particledesigner.71squared.com/) 生成的粒子 + * 粒子设计器中的 半径模式 使用 30 hz 的固定发射率。由于 cocos2d 无法保证, + * cocos2d 使用了另一种方法,但结果几乎相同。 + * cocos2d 支持 Particle Designer 使用的所有变量,还有: + * -旋转粒子(使用粒子系统时支持) + * -切向加速度(重力模式) + * -径向加速度(重力模式) + * -半径方向(半径模式)(Particle Designer 仅支持向外到向内的方向) + * 可以在运行时自定义上述任何属性。例如: + * emitter.radialAccel = 15; + * emitter.startSpin = 0; + * */ @ccclass('cc.ParticleSystem2D') @menu('Effects/ParticleSystem2D') @@ -698,11 +682,11 @@ export class ParticleSystem2D extends UIRenderer { public aspectRatio = 1; /** * The temporary SpriteFrame object used for the renderer. Because there is no corresponding asset, it can't be serialized. - * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. + * @internal since v3.5.0, this is an engine private interface that will be removed in the future. */ public declare _renderSpriteFrame: SpriteFrame | null; /** - * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. + * @internal since v3.5.0, this is an engine private interface that will be removed in the future. */ public declare _simulator: Simulator; diff --git a/cocos/particle-2d/png-reader.ts b/cocos/particle-2d/png-reader.ts index 51d3624ffe..2e25d14e23 100644 --- a/cocos/particle-2d/png-reader.ts +++ b/cocos/particle-2d/png-reader.ts @@ -26,11 +26,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module particle2d - */ - import { getError } from '../core/platform/debug'; import zlib from '../../external/compression/zlib.min'; diff --git a/cocos/particle-2d/tiff-reader.ts b/cocos/particle-2d/tiff-reader.ts index deaf428a61..1becc22e60 100644 --- a/cocos/particle-2d/tiff-reader.ts +++ b/cocos/particle-2d/tiff-reader.ts @@ -29,11 +29,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module particle2d - */ - import { getError, logID } from '../core/platform/debug'; interface IFile { diff --git a/cocos/particle/animator/color-overtime.ts b/cocos/particle/animator/color-overtime.ts index c28dce1c93..1e26c461b0 100644 --- a/cocos/particle/animator/color-overtime.ts +++ b/cocos/particle/animator/color-overtime.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module particle - */ - import { ccclass, displayOrder, type, serializable } from 'cc.decorator'; import { pseudoRandom } from '../../core/math'; import { Particle, PARTICLE_MODULE_NAME, ParticleModuleBase } from '../particle'; diff --git a/cocos/particle/animator/curve-range.ts b/cocos/particle/animator/curve-range.ts index 3dd2016fdf..88b93bdd89 100644 --- a/cocos/particle/animator/curve-range.ts +++ b/cocos/particle/animator/curve-range.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { ccclass, type, serializable, editable, formerlySerializedAs } from 'cc.decorator'; import { EDITOR } from 'internal:constants'; import { lerp } from '../../core/math'; diff --git a/cocos/particle/animator/force-overtime.ts b/cocos/particle/animator/force-overtime.ts index 8ea5277737..2b7d4fe05b 100644 --- a/cocos/particle/animator/force-overtime.ts +++ b/cocos/particle/animator/force-overtime.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module particle - */ - import { ccclass, tooltip, displayOrder, range, type, serializable } from 'cc.decorator'; import { pseudoRandom, Quat, Vec3 } from '../../core/math'; import { Space, ModuleRandSeed } from '../enum'; diff --git a/cocos/particle/animator/gradient-range.ts b/cocos/particle/animator/gradient-range.ts index e36b66d455..d0f38a0f8e 100644 --- a/cocos/particle/animator/gradient-range.ts +++ b/cocos/particle/animator/gradient-range.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { ccclass, type, serializable, editable } from 'cc.decorator'; import { EDITOR } from 'internal:constants'; import { Color } from '../../core/math'; diff --git a/cocos/particle/animator/gradient.ts b/cocos/particle/animator/gradient.ts index 17f9d89c07..7fa987bc72 100644 --- a/cocos/particle/animator/gradient.ts +++ b/cocos/particle/animator/gradient.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { ccclass, serializable, editable } from 'cc.decorator'; import { CCClass } from '../../core/data/class'; import { Color, lerp, repeat } from '../../core/math'; diff --git a/cocos/particle/animator/limit-velocity-overtime.ts b/cocos/particle/animator/limit-velocity-overtime.ts index d36e7b0bbe..75f8fe3c63 100644 --- a/cocos/particle/animator/limit-velocity-overtime.ts +++ b/cocos/particle/animator/limit-velocity-overtime.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module particle - */ - import { ccclass, tooltip, displayOrder, range, type, serializable } from 'cc.decorator'; import { lerp, pseudoRandom, Vec3, Mat4, Quat } from '../../core/math'; import { Space, ModuleRandSeed } from '../enum'; diff --git a/cocos/particle/animator/optimized-curve.ts b/cocos/particle/animator/optimized-curve.ts index 7442361073..88f996350c 100644 --- a/cocos/particle/animator/optimized-curve.ts +++ b/cocos/particle/animator/optimized-curve.ts @@ -23,14 +23,9 @@ THE SOFTWARE. */ - - - import { repeat } from '../../core/math'; import { AnimationCurve, evalOptCurve, OptimizedKey } from '../../core/geometry/curve'; - - const CURVE_MODE_CONSTANT = 0; const CURVE_MODE_RANDOM_CONSTANT = 1; const CURVE_MODE_CURVE = 2; diff --git a/cocos/particle/animator/rotation-overtime.ts b/cocos/particle/animator/rotation-overtime.ts index 0e65acbc97..a827935f30 100644 --- a/cocos/particle/animator/rotation-overtime.ts +++ b/cocos/particle/animator/rotation-overtime.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module particle - */ - import { ccclass, tooltip, displayOrder, range, type, radian, serializable } from 'cc.decorator'; import { Mat4, pseudoRandom, Quat, Vec4, Vec3 } from '../../core/math'; import { Particle, ParticleModuleBase, PARTICLE_MODULE_NAME } from '../particle'; diff --git a/cocos/particle/animator/size-overtime.ts b/cocos/particle/animator/size-overtime.ts index c9f687a841..5547c1c84f 100644 --- a/cocos/particle/animator/size-overtime.ts +++ b/cocos/particle/animator/size-overtime.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module particle - */ - import { ccclass, tooltip, displayOrder, type, serializable, range } from 'cc.decorator'; import { pseudoRandom, Vec3 } from '../../core/math'; import { Particle, ParticleModuleBase, PARTICLE_MODULE_NAME } from '../particle'; diff --git a/cocos/particle/animator/texture-animation.ts b/cocos/particle/animator/texture-animation.ts index 8654b42954..c7402e0c1a 100644 --- a/cocos/particle/animator/texture-animation.ts +++ b/cocos/particle/animator/texture-animation.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module particle - */ - import { ccclass, tooltip, displayOrder, type, formerlySerializedAs, serializable, range } from 'cc.decorator'; import { lerp, pseudoRandom, repeat } from '../../core/math'; import { Enum } from '../../core/value-types'; diff --git a/cocos/particle/animator/velocity-overtime.ts b/cocos/particle/animator/velocity-overtime.ts index fb8b5350eb..d3dad9a701 100644 --- a/cocos/particle/animator/velocity-overtime.ts +++ b/cocos/particle/animator/velocity-overtime.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module particle - */ - import { ccclass, tooltip, displayOrder, range, type, serializable } from 'cc.decorator'; import { Mat4, pseudoRandom, Quat, Vec3 } from '../../core/math'; import { Space, ModuleRandSeed } from '../enum'; diff --git a/cocos/particle/billboard.ts b/cocos/particle/billboard.ts index b3f60b4571..da8bb4aa29 100644 --- a/cocos/particle/billboard.ts +++ b/cocos/particle/billboard.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module particle - */ - import { ccclass, help, executeInEditMode, menu, tooltip, type, serializable } from 'cc.decorator'; import { builtinResMgr } from '../core/builtin'; import { createMesh } from '../3d/misc'; diff --git a/cocos/particle/burst.ts b/cocos/particle/burst.ts index fb23c80453..f95b32531e 100644 --- a/cocos/particle/burst.ts +++ b/cocos/particle/burst.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { ccclass, type, serializable, editable, range } from 'cc.decorator'; import { repeat } from '../core/math'; import CurveRange from './animator/curve-range'; diff --git a/cocos/particle/deprecated.ts b/cocos/particle/deprecated.ts index d04d3e275f..d5f342d5df 100644 --- a/cocos/particle/deprecated.ts +++ b/cocos/particle/deprecated.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module particle - */ - import { removeProperty, replaceProperty } from '../core/utils/x-deprecated'; import Burst from './burst'; import { ParticleSystem } from './particle-system'; diff --git a/cocos/particle/emitter/shape-module.ts b/cocos/particle/emitter/shape-module.ts index 7faca14e74..0f94543073 100644 --- a/cocos/particle/emitter/shape-module.ts +++ b/cocos/particle/emitter/shape-module.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module particle - */ - import { ccclass, tooltip, displayOrder, type, formerlySerializedAs, serializable, visible, range } from 'cc.decorator'; import { Mat4, Quat, Vec2, Vec3, clamp, pingPong, random, randomRange, repeat, toDegree, toRadian } from '../../core/math'; diff --git a/cocos/particle/index.ts b/cocos/particle/index.ts index c79f7f9012..d741bb3165 100644 --- a/cocos/particle/index.ts +++ b/cocos/particle/index.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { Billboard } from './billboard'; import { Line } from './line'; import { ParticleSystem } from './particle-system'; diff --git a/cocos/particle/line.ts b/cocos/particle/line.ts index d7871742c4..c43627c142 100644 --- a/cocos/particle/line.ts +++ b/cocos/particle/line.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module particle - */ - import { ccclass, help, executeInEditMode, menu, tooltip, displayOrder, type, serializable, range } from 'cc.decorator'; import { Material, Texture2D } from '../core/assets'; import { Component } from '../core/components'; @@ -103,7 +98,8 @@ export class Line extends Component { private _positions = []; /** - * 每段折线的拐点坐标。 + * @en Inflection point positions of each polyline + * @zh 每段折线的拐点坐标。 */ @type([Vec3]) @displayOrder(2) diff --git a/cocos/particle/models/line-model.ts b/cocos/particle/models/line-model.ts index e429e374f8..88f81ca0f9 100644 --- a/cocos/particle/models/line-model.ts +++ b/cocos/particle/models/line-model.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { RenderingSubMesh } from '../../core/assets/rendering-sub-mesh'; import { DRAW_INFO_SIZE, Buffer, IndirectBuffer, Attribute, BufferInfo, DrawInfo, AttributeName, BufferUsageBit, Format, FormatInfos, MemoryUsageBit, PrimitiveMode } from '../../core/gfx'; diff --git a/cocos/particle/models/particle-batch-model.ts b/cocos/particle/models/particle-batch-model.ts index 535d5c7412..7c0566f743 100644 --- a/cocos/particle/models/particle-batch-model.ts +++ b/cocos/particle/models/particle-batch-model.ts @@ -28,7 +28,6 @@ * @packageDocumentation * @hidden */ - import { Mesh } from '../../3d/assets/mesh'; import { AttributeName, BufferUsageBit, FormatInfos, MemoryUsageBit, PrimitiveMode, Attribute, DRAW_INFO_SIZE, Buffer, IndirectBuffer, BufferInfo, DrawInfo, Feature } from '../../core/gfx'; @@ -620,9 +619,14 @@ export default class ParticleBatchModel extends scene.Model { public doDestroy () { this._vBuffer = null; this._vdataF32 = null; + this._vdataUint32 = null; this._insBuffers = []; this._insIndices = null; + + this._vertAttrs = null; + this._material = null; + this._mesh = null; this.destroySubMeshData(); } diff --git a/cocos/particle/particle-general-function.ts b/cocos/particle/particle-general-function.ts index ad0c0550f6..c82a86f3db 100644 --- a/cocos/particle/particle-general-function.ts +++ b/cocos/particle/particle-general-function.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { Mat4, Quat, random, randomRange, randomRangeInt, Vec2, Vec3 } from '../core/math'; import { sign } from '../core/math/bits'; import { Space } from './enum'; diff --git a/cocos/particle/particle-system.ts b/cocos/particle/particle-system.ts index 986541f5a5..c3d62a307a 100644 --- a/cocos/particle/particle-system.ts +++ b/cocos/particle/particle-system.ts @@ -1,4 +1,3 @@ -/* eslint-disable max-len */ /* Copyright (c) 2020 Xiamen Yaji Software Co., Ltd. @@ -24,19 +23,12 @@ THE SOFTWARE. */ -// Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd. - -/** - * @packageDocumentation - * @module particle - */ - // eslint-disable-next-line max-len import { ccclass, help, executeInEditMode, executionOrder, menu, tooltip, displayOrder, type, range, displayName, formerlySerializedAs, override, radian, serializable, inspector, boolean, visible } from 'cc.decorator'; import { EDITOR } from 'internal:constants'; import { ModelRenderer } from '../core/components/model-renderer'; import { Material } from '../core/assets/material'; -import { Mat4, pseudoRandom, Quat, randomRangeInt, Vec2, Vec3, Vec4 } from '../core/math'; +import { Mat4, pseudoRandom, Quat, randomRangeInt, Vec2, Vec3 } from '../core/math'; import { INT_MAX } from '../core/math/bits'; import { scene } from '../core/renderer'; import ColorOverLifetimeModule from './animator/color-overtime'; @@ -50,12 +42,12 @@ import TextureAnimationModule from './animator/texture-animation'; import VelocityOvertimeModule from './animator/velocity-overtime'; import Burst from './burst'; import ShapeModule from './emitter/shape-module'; -import { CullingMode, RenderMode, Space } from './enum'; +import { CullingMode, Space } from './enum'; import { particleEmitZAxis } from './particle-general-function'; import ParticleSystemRenderer from './renderer/particle-system-renderer-data'; import TrailModule from './renderer/trail'; import { IParticleSystemRenderer } from './renderer/particle-system-renderer-base'; -import { Particle, PARTICLE_MODULE_PROPERTY } from './particle'; +import { PARTICLE_MODULE_PROPERTY } from './particle'; import { legacyCC } from '../core/global-exports'; import { TransformBit } from '../core/scene-graph/node-enum'; import { AABB, intersect } from '../core/geometry'; @@ -718,6 +710,8 @@ export class ParticleSystem extends ModelRenderer { private _subEmitters: any[]; // array of { emitter: ParticleSystem, type: 'birth', 'collision' or 'death'} + private _needAttach: boolean; + @serializable private _prewarm = false; @@ -743,6 +737,7 @@ export class ParticleSystem extends ModelRenderer { this._isStopped = true; this._isEmitting = false; this._needRefresh = true; + this._needAttach = false; this._time = 0.0; // playback position in seconds. this._emitRateTimeCounter = 0.0; @@ -844,7 +839,8 @@ export class ParticleSystem extends ModelRenderer { // } /** - * 播放粒子效果。 + * @en play particle system + * @zh 播放粒子效果。 */ public play () { if (this._isPaused) { @@ -877,7 +873,8 @@ export class ParticleSystem extends ModelRenderer { } /** - * 暂停播放粒子效果。 + * @en pause particle system + * @zh 暂停播放粒子效果。 */ public pause () { if (this._isStopped) { @@ -892,7 +889,8 @@ export class ParticleSystem extends ModelRenderer { } /** - * 停止播放粒子。 + * @en stop particle system + * @zh 停止播放粒子。 */ public stop () { if (this._isPlaying || this._isPaused) { @@ -919,9 +917,9 @@ export class ParticleSystem extends ModelRenderer { } } - // remove all particles from current particle system. /** - * 将所有粒子从粒子系统中清除。 + * @en remove all particles from current particle system. + * @zh 将所有粒子从粒子系统中清除。 */ public clear () { if (this.enabledInHierarchy) { @@ -1130,6 +1128,22 @@ export class ParticleSystem extends ModelRenderer { if (this._trailModule && this._trailModule.enable) { this._trailModule.updateRenderData(); } + + if (this._needAttach) { // Check whether this particle model should be reattached + if (this.getParticleCount() > 0) { + if (!this._isCulled) { + if (!this.processor.getModel()?.scene) { + this.processor.attachToScene(); + } + if (this._trailModule && this._trailModule.enable) { + if (!this._trailModule.getModel()?.scene) { + this._trailModule._attachToScene(); + } + } + this._needAttach = false; + } + } + } } protected beforeRender () { @@ -1138,6 +1152,18 @@ export class ParticleSystem extends ModelRenderer { if (this._trailModule && this._trailModule.enable) { this._trailModule.beforeRender(); } + + if (this.getParticleCount() <= 0) { + if (this.processor.getModel()?.scene) { + this.processor.detachFromScene(); + if (this._trailModule && this._trailModule.enable) { + this._trailModule._detachFromScene(); + } + this._needAttach = false; + } + } else if (!this.processor.getModel()?.scene) { + this._needAttach = true; + } } protected _onVisibilityChange (val) { diff --git a/cocos/particle/particle-utils.ts b/cocos/particle/particle-utils.ts index a80c619e9b..2aef3a267f 100644 --- a/cocos/particle/particle-utils.ts +++ b/cocos/particle/particle-utils.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { instantiate } from '../core/data'; import { CCObject } from '../core/data/object'; import { Director, director } from '../core/director'; @@ -34,7 +32,8 @@ import { ParticleSystem } from './particle-system'; export class ParticleUtils { /** - * instantiate + * @en instantiate particle system from prefab + * @zh 从 prefab 实例化粒子系统 */ public static instantiate (prefab) { if (!this.registeredSceneEvent) { @@ -42,6 +41,7 @@ export class ParticleUtils { this.registeredSceneEvent = true; } if (!this.particleSystemPool.has(prefab._uuid)) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-return this.particleSystemPool.set(prefab._uuid, new Pool(() => instantiate(prefab) || new Node(), 1, (prefab) => prefab.destroy())); } return this.particleSystemPool.get(prefab._uuid)!.alloc(); diff --git a/cocos/particle/particle.ts b/cocos/particle/particle.ts index 7ce67bd8a2..99988652a9 100644 --- a/cocos/particle/particle.ts +++ b/cocos/particle/particle.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { Color, Vec3, Mat4, Quat } from '../core/math'; import { ParticleSystem } from './particle-system'; import { IParticleSystemRenderer } from './renderer/particle-system-renderer-base'; diff --git a/cocos/particle/renderer/particle-system-renderer-cpu.ts b/cocos/particle/renderer/particle-system-renderer-cpu.ts index 2f9a55de5f..c7d2d9b375 100644 --- a/cocos/particle/renderer/particle-system-renderer-cpu.ts +++ b/cocos/particle/renderer/particle-system-renderer-cpu.ts @@ -208,6 +208,11 @@ export default class ParticleSystemRendererCPU extends ParticleSystemRendererBas this.setVertexAttributes(); } + public onDestroy (): void { + this._particles?.destroy(); + super.onDestroy(); + } + public getFreeParticle (): Particle | null { if (this._particles!.length >= this._particleSystem.capacity) { return null; diff --git a/cocos/particle/renderer/trail.ts b/cocos/particle/renderer/trail.ts index f1c5a38a89..8e601e27aa 100644 --- a/cocos/particle/renderer/trail.ts +++ b/cocos/particle/renderer/trail.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module particle - */ - import { ccclass, tooltip, displayOrder, type, serializable, range } from 'cc.decorator'; import { Material } from '../../core/assets/material'; import { RenderingSubMesh } from '../../core/assets/rendering-sub-mesh'; @@ -129,6 +124,7 @@ class TrailSegment { return this.trailElements[newEleLoc]; } + // eslint-disable-next-line max-len public iterateElement (target: TrailModule, f: (target: TrailModule, e: ITrailElement, p: Particle, dt: number) => boolean, p: Particle, dt: number) { const end = this.start >= this.end ? this.end + this.trailElements.length : this.end; for (let i = this.start; i < end; i++) { @@ -306,6 +302,15 @@ export default class TrailModule { @tooltip('i18n:trailSegment.colorOvertime') public colorOvertime = new GradientRange(); + /** + * @en Get trail model + * @zh 获取拖尾模型 + * @return Model of this trail and type is scene.Model + */ + public getModel () { + return this._trailModel; + } + /** * 轨迹设定时的坐标系。 */ diff --git a/cocos/physics-2d/framework/components/colliders/box-collider-2d.ts b/cocos/physics-2d/framework/components/colliders/box-collider-2d.ts index 225ce71611..29eb2acb6d 100644 --- a/cocos/physics-2d/framework/components/colliders/box-collider-2d.ts +++ b/cocos/physics-2d/framework/components/colliders/box-collider-2d.ts @@ -1,7 +1,4 @@ -/** - * @packageDocumentation - * @module physics2d - */ + import { ccclass, property, menu } from '../../../../core/data/class-decorator'; import { Vec2, Size } from '../../../../core'; diff --git a/cocos/physics-2d/framework/components/colliders/circle-collider-2d.ts b/cocos/physics-2d/framework/components/colliders/circle-collider-2d.ts index 9413ed66c5..4116e003da 100644 --- a/cocos/physics-2d/framework/components/colliders/circle-collider-2d.ts +++ b/cocos/physics-2d/framework/components/colliders/circle-collider-2d.ts @@ -1,7 +1,4 @@ -/** - * @packageDocumentation - * @module physics2d - */ + import { ccclass, property, menu } from '../../../../core/data/class-decorator'; import { Component, Vec2, Size } from '../../../../core'; diff --git a/cocos/physics-2d/framework/components/colliders/collider-2d.ts b/cocos/physics-2d/framework/components/colliders/collider-2d.ts index 580d772451..8080cab44d 100644 --- a/cocos/physics-2d/framework/components/colliders/collider-2d.ts +++ b/cocos/physics-2d/framework/components/colliders/collider-2d.ts @@ -1,7 +1,4 @@ -/** - * @packageDocumentation - * @module physics2d - */ + import { EDITOR } from 'internal:constants'; diff --git a/cocos/physics-2d/framework/components/colliders/polygon-collider-2d.ts b/cocos/physics-2d/framework/components/colliders/polygon-collider-2d.ts index bbbaa454f4..af8e27b76f 100644 --- a/cocos/physics-2d/framework/components/colliders/polygon-collider-2d.ts +++ b/cocos/physics-2d/framework/components/colliders/polygon-collider-2d.ts @@ -1,7 +1,4 @@ -/** - * @packageDocumentation - * @module physics2d - */ + import { ccclass, property, menu } from '../../../../core/data/class-decorator'; import { Component, Vec2, Size } from '../../../../core'; diff --git a/cocos/physics-2d/framework/components/joints/distance-joint-2d.ts b/cocos/physics-2d/framework/components/joints/distance-joint-2d.ts index cfa5275d2c..88c7074bb4 100644 --- a/cocos/physics-2d/framework/components/joints/distance-joint-2d.ts +++ b/cocos/physics-2d/framework/components/joints/distance-joint-2d.ts @@ -1,7 +1,4 @@ -/** - * @packageDocumentation - * @module physics2d - */ + import { Joint2D } from './joint-2d'; import { ccclass, property, menu, type } from '../../../../core/data/class-decorator'; import { IDistanceJoint } from '../../../spec/i-physics-joint'; diff --git a/cocos/physics-2d/framework/components/joints/fixed-joint-2d.ts b/cocos/physics-2d/framework/components/joints/fixed-joint-2d.ts index 883d25da5d..63e3b1decc 100644 --- a/cocos/physics-2d/framework/components/joints/fixed-joint-2d.ts +++ b/cocos/physics-2d/framework/components/joints/fixed-joint-2d.ts @@ -1,7 +1,4 @@ -/** - * @packageDocumentation - * @module physics2d - */ + import { Joint2D } from './joint-2d'; import { ccclass, property, menu, type } from '../../../../core/data/class-decorator'; import { IFixedJoint } from '../../../spec/i-physics-joint'; diff --git a/cocos/physics-2d/framework/components/joints/hinge-joint-2d.ts b/cocos/physics-2d/framework/components/joints/hinge-joint-2d.ts index efd14ec174..16bf9874f3 100644 --- a/cocos/physics-2d/framework/components/joints/hinge-joint-2d.ts +++ b/cocos/physics-2d/framework/components/joints/hinge-joint-2d.ts @@ -1,7 +1,4 @@ -/** - * @packageDocumentation - * @module physics2d - */ + import { Joint2D } from './joint-2d'; import { ccclass, property, menu, type } from '../../../../core/data/class-decorator'; diff --git a/cocos/physics-2d/framework/components/joints/joint-2d.ts b/cocos/physics-2d/framework/components/joints/joint-2d.ts index 72c531c377..93b0d4cd03 100644 --- a/cocos/physics-2d/framework/components/joints/joint-2d.ts +++ b/cocos/physics-2d/framework/components/joints/joint-2d.ts @@ -1,7 +1,4 @@ -/** - * @packageDocumentation - * @module physics2d - */ + import { EDITOR } from 'internal:constants'; import { Component, Vec2 } from '../../../../core'; diff --git a/cocos/physics-2d/framework/components/joints/mouse-joint-2d.ts b/cocos/physics-2d/framework/components/joints/mouse-joint-2d.ts index 4eb0083860..267ea8d054 100644 --- a/cocos/physics-2d/framework/components/joints/mouse-joint-2d.ts +++ b/cocos/physics-2d/framework/components/joints/mouse-joint-2d.ts @@ -1,7 +1,4 @@ -/** - * @packageDocumentation - * @module physics2d - */ + import { Joint2D } from './joint-2d'; import { ccclass, property, menu, type } from '../../../../core/data/class-decorator'; diff --git a/cocos/physics-2d/framework/components/joints/relative-joint-2d.ts b/cocos/physics-2d/framework/components/joints/relative-joint-2d.ts index cece817c06..76c711abb5 100644 --- a/cocos/physics-2d/framework/components/joints/relative-joint-2d.ts +++ b/cocos/physics-2d/framework/components/joints/relative-joint-2d.ts @@ -1,7 +1,4 @@ -/** - * @packageDocumentation - * @module physics2d - */ + import { Joint2D } from './joint-2d'; import { ccclass, property, menu, type } from '../../../../core/data/class-decorator'; diff --git a/cocos/physics-2d/framework/components/joints/slider-joint-2d.ts b/cocos/physics-2d/framework/components/joints/slider-joint-2d.ts index dc0040685d..daec80b3d2 100644 --- a/cocos/physics-2d/framework/components/joints/slider-joint-2d.ts +++ b/cocos/physics-2d/framework/components/joints/slider-joint-2d.ts @@ -1,7 +1,4 @@ -/** - * @packageDocumentation - * @module physics2d - */ + import { Joint2D } from './joint-2d'; import { ccclass, property, menu, type } from '../../../../core/data/class-decorator'; diff --git a/cocos/physics-2d/framework/components/joints/spring-joint-2d.ts b/cocos/physics-2d/framework/components/joints/spring-joint-2d.ts index ea6bb011dd..06e4b06790 100644 --- a/cocos/physics-2d/framework/components/joints/spring-joint-2d.ts +++ b/cocos/physics-2d/framework/components/joints/spring-joint-2d.ts @@ -1,7 +1,4 @@ -/** - * @packageDocumentation - * @module physics2d - */ + import { Joint2D } from './joint-2d'; import { ccclass, property, menu, type } from '../../../../core/data/class-decorator'; diff --git a/cocos/physics-2d/framework/components/joints/wheel-joint-2d.ts b/cocos/physics-2d/framework/components/joints/wheel-joint-2d.ts index 2c95afcb30..c4a97248c3 100644 --- a/cocos/physics-2d/framework/components/joints/wheel-joint-2d.ts +++ b/cocos/physics-2d/framework/components/joints/wheel-joint-2d.ts @@ -1,7 +1,4 @@ -/** - * @packageDocumentation - * @module physics2d - */ + import { Joint2D } from './joint-2d'; import { ccclass, property, menu, type } from '../../../../core/data/class-decorator'; diff --git a/cocos/physics-2d/framework/components/rigid-body-2d.ts b/cocos/physics-2d/framework/components/rigid-body-2d.ts index 1d0135103a..22ee8d47b4 100644 --- a/cocos/physics-2d/framework/components/rigid-body-2d.ts +++ b/cocos/physics-2d/framework/components/rigid-body-2d.ts @@ -1,7 +1,4 @@ -/** - * @packageDocumentation - * @module physics2d - */ + import { EDITOR } from 'internal:constants'; import { IRigidBody2D } from '../../spec/i-rigid-body'; diff --git a/cocos/physics-2d/framework/physics-system.ts b/cocos/physics-2d/framework/physics-system.ts index 6cfc9e5c62..aca9dd63fe 100644 --- a/cocos/physics-2d/framework/physics-system.ts +++ b/cocos/physics-2d/framework/physics-system.ts @@ -1,7 +1,4 @@ -/** - * @packageDocumentation - * @module physics2d - */ + import { EDITOR, DEBUG } from 'internal:constants'; import { System, Vec2, director, Director, game, error, IVec2Like, Rect, Eventify, Enum } from '../../core'; diff --git a/cocos/physics-2d/framework/physics-types.ts b/cocos/physics-2d/framework/physics-types.ts index 39ca0f34f5..9a2a1718fd 100644 --- a/cocos/physics-2d/framework/physics-types.ts +++ b/cocos/physics-2d/framework/physics-types.ts @@ -1,7 +1,4 @@ -/** - * @packageDocumentation - * @module physics2d - */ + import { Enum, Vec2 } from '../../core'; import { Collider2D } from './components/colliders/collider-2d'; diff --git a/cocos/physics-2d/spec/i-physics-contact.ts b/cocos/physics-2d/spec/i-physics-contact.ts index 9d6eb6c70e..dd22d36b2f 100644 --- a/cocos/physics-2d/spec/i-physics-contact.ts +++ b/cocos/physics-2d/spec/i-physics-contact.ts @@ -1,7 +1,4 @@ -/** - * @packageDocumentation - * @module physics2d - */ + import { Vec2 } from '../../core'; import { Collider2D } from '../framework/components/colliders/collider-2d'; diff --git a/cocos/physics-2d/spec/i-physics-joint.ts b/cocos/physics-2d/spec/i-physics-joint.ts index 5af415f0a9..d01d507047 100644 --- a/cocos/physics-2d/spec/i-physics-joint.ts +++ b/cocos/physics-2d/spec/i-physics-joint.ts @@ -1,7 +1,4 @@ -/** - * @packageDocumentation - * @module physics2d - */ + import { IVec2Like } from '../../core'; import { ILifecycle } from '../../physics/spec/i-lifecycle'; diff --git a/cocos/physics/bullet/bullet-cache.ts b/cocos/physics/bullet/bullet-cache.ts index a036d6442c..4401224134 100644 --- a/cocos/physics/bullet/bullet-cache.ts +++ b/cocos/physics/bullet/bullet-cache.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { Collider, TriggerEventType, CollisionEventType, IContactEquation } from '../../../exports/physics-framework'; import { Vec3, Quat } from '../../core'; import { bt } from './instantiated'; diff --git a/cocos/physics/bullet/bullet-contact-data.ts b/cocos/physics/bullet/bullet-contact-data.ts index 0ecfe5a7f6..b371def21f 100644 --- a/cocos/physics/bullet/bullet-contact-data.ts +++ b/cocos/physics/bullet/bullet-contact-data.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { IContactEquation, ICollisionEvent } from '../framework'; import { IVec3Like, Vec3, Quat } from '../../core'; import { BulletShape } from './shapes/bullet-shape'; diff --git a/cocos/physics/bullet/bullet-enum.ts b/cocos/physics/bullet/bullet-enum.ts index 492be73950..83eaa26b57 100644 --- a/cocos/physics/bullet/bullet-enum.ts +++ b/cocos/physics/bullet/bullet-enum.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - export enum EBtSharedBodyDirty { BODY_RE_ADD = 1, GHOST_RE_ADD = 2, diff --git a/cocos/physics/bullet/bullet-env.ts b/cocos/physics/bullet/bullet-env.ts index c92a64040f..0d6c22b729 100644 --- a/cocos/physics/bullet/bullet-env.ts +++ b/cocos/physics/bullet/bullet-env.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - // Wasm Memory Page Size is 65536 export const pageSize = 65536; // 64KiB diff --git a/cocos/physics/bullet/bullet-interface.ts b/cocos/physics/bullet/bullet-interface.ts index 4689e8d3d1..d17692ab6a 100644 --- a/cocos/physics/bullet/bullet-interface.ts +++ b/cocos/physics/bullet/bullet-interface.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { BulletShape } from './shapes/bullet-shape'; export interface IBulletBodyStruct { diff --git a/cocos/physics/bullet/bullet-rigid-body.ts b/cocos/physics/bullet/bullet-rigid-body.ts index 63915ee472..051fe085a4 100644 --- a/cocos/physics/bullet/bullet-rigid-body.ts +++ b/cocos/physics/bullet/bullet-rigid-body.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { Vec3 } from '../../core'; import { BulletWorld } from './bullet-world'; import { cocos2BulletVec3, bullet2CocosVec3 } from './bullet-utils'; diff --git a/cocos/physics/bullet/bullet-shared-body.ts b/cocos/physics/bullet/bullet-shared-body.ts index 9c0f0efde5..76b79bf111 100644 --- a/cocos/physics/bullet/bullet-shared-body.ts +++ b/cocos/physics/bullet/bullet-shared-body.ts @@ -38,8 +38,6 @@ import { fastRemoveAt } from '../../core/utils/array'; import { bt } from './instantiated'; import { BulletConstraint } from './constraints/bullet-constraint'; - - const v3_0 = CC_V3_0; const quat_0 = CC_QUAT_0; let IDCounter = 0; diff --git a/cocos/physics/bullet/bullet-utils.ts b/cocos/physics/bullet/bullet-utils.ts index 4948ef61e8..1a668b94b8 100644 --- a/cocos/physics/bullet/bullet-utils.ts +++ b/cocos/physics/bullet/bullet-utils.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { IVec3Like, IQuatLike } from '../../core/math/type-define'; import { Mesh } from '../../3d'; import { PrimitiveMode } from '../../core/gfx'; diff --git a/cocos/physics/bullet/bullet-world.ts b/cocos/physics/bullet/bullet-world.ts index 8115c5966c..fc7faff2d2 100644 --- a/cocos/physics/bullet/bullet-world.ts +++ b/cocos/physics/bullet/bullet-world.ts @@ -24,8 +24,6 @@ THE SOFTWARE. */ - - import { BulletSharedBody } from './bullet-shared-body'; import { BulletRigidBody } from './bullet-rigid-body'; import { BulletShape } from './shapes/bullet-shape'; diff --git a/cocos/physics/bullet/constraints/bullet-constraint.ts b/cocos/physics/bullet/constraints/bullet-constraint.ts index 999823a769..853b8a4745 100644 --- a/cocos/physics/bullet/constraints/bullet-constraint.ts +++ b/cocos/physics/bullet/constraints/bullet-constraint.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - /* eslint-disable new-cap */ import { IBaseConstraint } from '../../spec/i-physics-constraint'; import { Constraint, RigidBody } from '../../framework'; diff --git a/cocos/physics/bullet/constraints/bullet-hinge-constraint.ts b/cocos/physics/bullet/constraints/bullet-hinge-constraint.ts index 251842450e..130ed292c4 100644 --- a/cocos/physics/bullet/constraints/bullet-hinge-constraint.ts +++ b/cocos/physics/bullet/constraints/bullet-hinge-constraint.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - /* eslint-disable new-cap */ import { BulletConstraint } from './bullet-constraint'; import { IHingeConstraint } from '../../spec/i-physics-constraint'; diff --git a/cocos/physics/bullet/constraints/bullet-p2p-constraint.ts b/cocos/physics/bullet/constraints/bullet-p2p-constraint.ts index eb1532535e..0c6b9e5a57 100644 --- a/cocos/physics/bullet/constraints/bullet-p2p-constraint.ts +++ b/cocos/physics/bullet/constraints/bullet-p2p-constraint.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - /* eslint-disable new-cap */ import { BulletConstraint } from './bullet-constraint'; import { IPointToPointConstraint } from '../../spec/i-physics-constraint'; diff --git a/cocos/physics/bullet/instantiate.ts b/cocos/physics/bullet/instantiate.ts index 0812a076f9..1b10041c33 100644 --- a/cocos/physics/bullet/instantiate.ts +++ b/cocos/physics/bullet/instantiate.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { Game, game } from '../../core'; import { selector } from '../framework/physics-selector'; import { BulletRigidBody } from './bullet-rigid-body'; diff --git a/cocos/physics/bullet/shapes/bullet-box-shape.ts b/cocos/physics/bullet/shapes/bullet-box-shape.ts index 0f69b07ea3..66f2af7174 100644 --- a/cocos/physics/bullet/shapes/bullet-box-shape.ts +++ b/cocos/physics/bullet/shapes/bullet-box-shape.ts @@ -24,8 +24,6 @@ THE SOFTWARE. */ - - import { BulletShape } from './bullet-shape'; import { Vec3 } from '../../../core'; import { BoxCollider, PhysicsSystem } from '../../../../exports/physics-framework'; diff --git a/cocos/physics/bullet/shapes/bullet-capsule-shape.ts b/cocos/physics/bullet/shapes/bullet-capsule-shape.ts index c5da24b4ad..db7e6db079 100644 --- a/cocos/physics/bullet/shapes/bullet-capsule-shape.ts +++ b/cocos/physics/bullet/shapes/bullet-capsule-shape.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { absMax } from '../../../core'; import { BulletShape } from './bullet-shape'; import { CapsuleCollider } from '../../../../exports/physics-framework'; diff --git a/cocos/physics/bullet/shapes/bullet-cone-shape.ts b/cocos/physics/bullet/shapes/bullet-cone-shape.ts index c974d8539d..53ae7c4ca0 100644 --- a/cocos/physics/bullet/shapes/bullet-cone-shape.ts +++ b/cocos/physics/bullet/shapes/bullet-cone-shape.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { BulletShape } from './bullet-shape'; import { ConeCollider } from '../../../../exports/physics-framework'; import { ICylinderShape } from '../../spec/i-physics-shape'; diff --git a/cocos/physics/bullet/shapes/bullet-cylinder-shape.ts b/cocos/physics/bullet/shapes/bullet-cylinder-shape.ts index b649aa365e..ea39974116 100644 --- a/cocos/physics/bullet/shapes/bullet-cylinder-shape.ts +++ b/cocos/physics/bullet/shapes/bullet-cylinder-shape.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { BulletShape } from './bullet-shape'; import { CylinderCollider } from '../../../../exports/physics-framework'; import { ICylinderShape } from '../../spec/i-physics-shape'; diff --git a/cocos/physics/bullet/shapes/bullet-plane-shape.ts b/cocos/physics/bullet/shapes/bullet-plane-shape.ts index d519dad3ab..e940e80a96 100644 --- a/cocos/physics/bullet/shapes/bullet-plane-shape.ts +++ b/cocos/physics/bullet/shapes/bullet-plane-shape.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { BulletShape } from './bullet-shape'; import { PlaneCollider } from '../../../../exports/physics-framework'; import { cocos2BulletVec3 } from '../bullet-utils'; diff --git a/cocos/physics/bullet/shapes/bullet-shape.ts b/cocos/physics/bullet/shapes/bullet-shape.ts index 9d96d69aeb..c49f312cd0 100644 --- a/cocos/physics/bullet/shapes/bullet-shape.ts +++ b/cocos/physics/bullet/shapes/bullet-shape.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { Vec3 } from '../../../core/math'; import { Collider, PhysicsMaterial, PhysicsSystem } from '../../../../exports/physics-framework'; import { BulletWorld } from '../bullet-world'; diff --git a/cocos/physics/bullet/shapes/bullet-simplex-shape.ts b/cocos/physics/bullet/shapes/bullet-simplex-shape.ts index f996c6cba2..b873355f17 100644 --- a/cocos/physics/bullet/shapes/bullet-simplex-shape.ts +++ b/cocos/physics/bullet/shapes/bullet-simplex-shape.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { BulletShape } from './bullet-shape'; import { SimplexCollider } from '../../../../exports/physics-framework'; import { cocos2BulletVec3 } from '../bullet-utils'; diff --git a/cocos/physics/bullet/shapes/bullet-terrain-shape.ts b/cocos/physics/bullet/shapes/bullet-terrain-shape.ts index 83814e2b50..2621a19c79 100644 --- a/cocos/physics/bullet/shapes/bullet-terrain-shape.ts +++ b/cocos/physics/bullet/shapes/bullet-terrain-shape.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { BulletShape } from './bullet-shape'; import { Vec3, warn } from '../../../core'; import { TerrainCollider } from '../../../../exports/physics-framework'; diff --git a/cocos/physics/bullet/shapes/bullet-trimesh-shape.ts b/cocos/physics/bullet/shapes/bullet-trimesh-shape.ts index 4cf40dbfaa..f129d2ccbb 100644 --- a/cocos/physics/bullet/shapes/bullet-trimesh-shape.ts +++ b/cocos/physics/bullet/shapes/bullet-trimesh-shape.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { BulletShape } from './bullet-shape'; import { warnID } from '../../../core'; import { Mesh } from '../../../3d/assets'; diff --git a/cocos/physics/cannon/cannon-contact-equation.ts b/cocos/physics/cannon/cannon-contact-equation.ts index 3acea14a05..da77ad78fd 100644 --- a/cocos/physics/cannon/cannon-contact-equation.ts +++ b/cocos/physics/cannon/cannon-contact-equation.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { IContactEquation, ICollisionEvent } from '../framework'; import { IVec3Like, Quat, Vec3 } from '../../core'; import { CannonShape } from './shapes/cannon-shape'; diff --git a/cocos/physics/cannon/cannon-rigid-body.ts b/cocos/physics/cannon/cannon-rigid-body.ts index d6eec05f1c..ecb446bb42 100644 --- a/cocos/physics/cannon/cannon-rigid-body.ts +++ b/cocos/physics/cannon/cannon-rigid-body.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import CANNON from '@cocos/cannon'; import { Vec3 } from '../../core/math'; import { IRigidBody } from '../spec/i-rigid-body'; diff --git a/cocos/physics/cannon/cannon-shared-body.ts b/cocos/physics/cannon/cannon-shared-body.ts index 7784b3644c..b10d45fb69 100644 --- a/cocos/physics/cannon/cannon-shared-body.ts +++ b/cocos/physics/cannon/cannon-shared-body.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import CANNON from '@cocos/cannon'; import { Quat, Vec3 } from '../../core/math'; import { ERigidBodyType, PhysicsGroup } from '../framework/physics-enum'; diff --git a/cocos/physics/cannon/cannon-util.ts b/cocos/physics/cannon/cannon-util.ts index c79757871c..1f80015edc 100644 --- a/cocos/physics/cannon/cannon-util.ts +++ b/cocos/physics/cannon/cannon-util.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import CANNON from '@cocos/cannon'; import { getWrap } from '../utils/util'; import { IBaseShape } from '../spec/i-physics-shape'; diff --git a/cocos/physics/cannon/cannon-world.ts b/cocos/physics/cannon/cannon-world.ts index afd430b042..ddaf03419e 100644 --- a/cocos/physics/cannon/cannon-world.ts +++ b/cocos/physics/cannon/cannon-world.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import CANNON from '@cocos/cannon'; import { Vec3, Quat } from '../../core/math'; import { fillRaycastResult, toCannonRaycastOptions } from './cannon-util'; diff --git a/cocos/physics/cannon/constraints/cannon-constraint.ts b/cocos/physics/cannon/constraints/cannon-constraint.ts index 6052d0f682..7983727c39 100644 --- a/cocos/physics/cannon/constraints/cannon-constraint.ts +++ b/cocos/physics/cannon/constraints/cannon-constraint.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import CANNON from '@cocos/cannon'; import { IBaseConstraint } from '../../spec/i-physics-constraint'; import { Constraint, RigidBody } from '../../framework'; diff --git a/cocos/physics/cannon/constraints/cannon-hinge-constraint.ts b/cocos/physics/cannon/constraints/cannon-hinge-constraint.ts index e0591a26c3..ca8e8ff102 100644 --- a/cocos/physics/cannon/constraints/cannon-hinge-constraint.ts +++ b/cocos/physics/cannon/constraints/cannon-hinge-constraint.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import CANNON from '@cocos/cannon'; import { CannonConstraint } from './cannon-constraint'; import { IHingeConstraint } from '../../spec/i-physics-constraint'; diff --git a/cocos/physics/cannon/constraints/cannon-point-to-point-constraint.ts b/cocos/physics/cannon/constraints/cannon-point-to-point-constraint.ts index 1c0c34d389..8d3f1911f5 100644 --- a/cocos/physics/cannon/constraints/cannon-point-to-point-constraint.ts +++ b/cocos/physics/cannon/constraints/cannon-point-to-point-constraint.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import CANNON from '@cocos/cannon'; import { CannonConstraint } from './cannon-constraint'; import { IPointToPointConstraint } from '../../spec/i-physics-constraint'; diff --git a/cocos/physics/cannon/instantiate.ts b/cocos/physics/cannon/instantiate.ts index 7404a4f237..81ed3905cf 100644 --- a/cocos/physics/cannon/instantiate.ts +++ b/cocos/physics/cannon/instantiate.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { selector } from '../framework/physics-selector'; import { CannonRigidBody } from './cannon-rigid-body'; diff --git a/cocos/physics/cannon/shapes/cannon-box-shape.ts b/cocos/physics/cannon/shapes/cannon-box-shape.ts index 4250625894..0f820941ae 100644 --- a/cocos/physics/cannon/shapes/cannon-box-shape.ts +++ b/cocos/physics/cannon/shapes/cannon-box-shape.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import CANNON from '@cocos/cannon'; import { clamp, Vec3 } from '../../../core/math'; import { commitShapeUpdates } from '../cannon-util'; diff --git a/cocos/physics/cannon/shapes/cannon-cone-shape.ts b/cocos/physics/cannon/shapes/cannon-cone-shape.ts index 1895daa3e4..9f0e8161ca 100644 --- a/cocos/physics/cannon/shapes/cannon-cone-shape.ts +++ b/cocos/physics/cannon/shapes/cannon-cone-shape.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import CANNON from '@cocos/cannon'; import { Vec3 } from '../../../core/math'; import { CannonShape } from './cannon-shape'; diff --git a/cocos/physics/cannon/shapes/cannon-cylinder-shape.ts b/cocos/physics/cannon/shapes/cannon-cylinder-shape.ts index 9c00475d46..5f44172b8b 100644 --- a/cocos/physics/cannon/shapes/cannon-cylinder-shape.ts +++ b/cocos/physics/cannon/shapes/cannon-cylinder-shape.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import CANNON from '@cocos/cannon'; import { Vec3 } from '../../../core/math'; import { CannonShape } from './cannon-shape'; diff --git a/cocos/physics/cannon/shapes/cannon-plane-shape.ts b/cocos/physics/cannon/shapes/cannon-plane-shape.ts index 58187d976a..4f50ea5161 100644 --- a/cocos/physics/cannon/shapes/cannon-plane-shape.ts +++ b/cocos/physics/cannon/shapes/cannon-plane-shape.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import CANNON from '@cocos/cannon'; import { Vec3, Quat } from '../../../core/math'; import { commitShapeUpdates } from '../cannon-util'; diff --git a/cocos/physics/cannon/shapes/cannon-shape.ts b/cocos/physics/cannon/shapes/cannon-shape.ts index 57c3c70706..c66b52c413 100644 --- a/cocos/physics/cannon/shapes/cannon-shape.ts +++ b/cocos/physics/cannon/shapes/cannon-shape.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import CANNON from '@cocos/cannon'; import { Vec3, Quat } from '../../../core/math'; import { getWrap, setWrap } from '../../utils/util'; diff --git a/cocos/physics/cannon/shapes/cannon-simplex-shape.ts b/cocos/physics/cannon/shapes/cannon-simplex-shape.ts index 9ea4e177af..6530bc866d 100644 --- a/cocos/physics/cannon/shapes/cannon-simplex-shape.ts +++ b/cocos/physics/cannon/shapes/cannon-simplex-shape.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - /* eslint-disable func-names */ import CANNON from '@cocos/cannon'; import { Vec3 } from '../../../core/math'; diff --git a/cocos/physics/cannon/shapes/cannon-sphere-shape.ts b/cocos/physics/cannon/shapes/cannon-sphere-shape.ts index b8d056378a..6f7b7febc6 100644 --- a/cocos/physics/cannon/shapes/cannon-sphere-shape.ts +++ b/cocos/physics/cannon/shapes/cannon-sphere-shape.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import CANNON from '@cocos/cannon'; import { absMaxComponent, clamp, Vec3 } from '../../../core/math'; import { commitShapeUpdates } from '../cannon-util'; diff --git a/cocos/physics/cannon/shapes/cannon-terrain-shape.ts b/cocos/physics/cannon/shapes/cannon-terrain-shape.ts index 73c2ff69e4..2a0001bbcc 100644 --- a/cocos/physics/cannon/shapes/cannon-terrain-shape.ts +++ b/cocos/physics/cannon/shapes/cannon-terrain-shape.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import CANNON from '@cocos/cannon'; import { CannonShape } from './cannon-shape'; import { TerrainCollider } from '../../framework'; diff --git a/cocos/physics/cannon/shapes/cannon-trimesh-shape.ts b/cocos/physics/cannon/shapes/cannon-trimesh-shape.ts index d6ac57a845..2d0c8eafc2 100644 --- a/cocos/physics/cannon/shapes/cannon-trimesh-shape.ts +++ b/cocos/physics/cannon/shapes/cannon-trimesh-shape.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import CANNON from '@cocos/cannon'; import { CannonShape } from './cannon-shape'; import { MeshCollider } from '../../framework'; diff --git a/cocos/physics/cocos/builtin-interface.ts b/cocos/physics/cocos/builtin-interface.ts index 482463d26f..c424f9c9d6 100644 --- a/cocos/physics/cocos/builtin-interface.ts +++ b/cocos/physics/cocos/builtin-interface.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { Mat4, Quat, Vec3 } from '../../core/math'; import { IVec3Like, IQuatLike } from '../../core/math/type-define'; diff --git a/cocos/physics/cocos/builtin-rigid-body.ts b/cocos/physics/cocos/builtin-rigid-body.ts index 8ef6df1f20..e9e3383e19 100644 --- a/cocos/physics/cocos/builtin-rigid-body.ts +++ b/cocos/physics/cocos/builtin-rigid-body.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { IRigidBody } from '../spec/i-rigid-body'; import { IVec3Like } from '../../core'; import { RigidBody, PhysicsSystem, ERigidBodyType } from '../framework'; diff --git a/cocos/physics/cocos/builtin-shared-body.ts b/cocos/physics/cocos/builtin-shared-body.ts index 02a5bf529b..59ded5c221 100644 --- a/cocos/physics/cocos/builtin-shared-body.ts +++ b/cocos/physics/cocos/builtin-shared-body.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { Mat4, Quat, Vec3 } from '../../core/math'; import { intersect } from '../../core/geometry'; import { BuiltInWorld } from './builtin-world'; diff --git a/cocos/physics/cocos/builtin-world.ts b/cocos/physics/cocos/builtin-world.ts index bb13048c64..1956381f29 100644 --- a/cocos/physics/cocos/builtin-world.ts +++ b/cocos/physics/cocos/builtin-world.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { Vec3 } from '../../core/math'; import { PhysicsRayResult } from '../framework/physics-ray-result'; import { BuiltinSharedBody } from './builtin-shared-body'; diff --git a/cocos/physics/cocos/instantiate.ts b/cocos/physics/cocos/instantiate.ts index d0d7003959..af175938ab 100644 --- a/cocos/physics/cocos/instantiate.ts +++ b/cocos/physics/cocos/instantiate.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { selector } from '../framework/physics-selector'; import { BuiltInWorld } from './builtin-world'; import { BuiltinRigidBody } from './builtin-rigid-body'; diff --git a/cocos/physics/cocos/object/builtin-object.ts b/cocos/physics/cocos/object/builtin-object.ts index 15b0e052f1..1f08600bd5 100644 --- a/cocos/physics/cocos/object/builtin-object.ts +++ b/cocos/physics/cocos/object/builtin-object.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { PhysicsSystem } from '../../framework'; export class BuiltinObject { diff --git a/cocos/physics/framework/assets/physics-material.ts b/cocos/physics/framework/assets/physics-material.ts index 0ff3fc7f67..f7250b2b21 100644 --- a/cocos/physics/framework/assets/physics-material.ts +++ b/cocos/physics/framework/assets/physics-material.ts @@ -25,11 +25,6 @@ // @ts-check -/** - * @packageDocumentation - * @module physics - */ - import { ccclass, editable, serializable } from 'cc.decorator'; import { Asset } from '../../../core/assets/asset'; import { math } from '../../../core'; diff --git a/cocos/physics/framework/collision-matrix.ts b/cocos/physics/framework/collision-matrix.ts index 344501f746..642aef313f 100644 --- a/cocos/physics/framework/collision-matrix.ts +++ b/cocos/physics/framework/collision-matrix.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module physics - */ - import { PhysicsGroup } from './physics-enum'; export class CollisionMatrix { diff --git a/cocos/physics/framework/components/colliders/box-collider.ts b/cocos/physics/framework/components/colliders/box-collider.ts index 1e114abcc7..d8a0f34ba0 100644 --- a/cocos/physics/framework/components/colliders/box-collider.ts +++ b/cocos/physics/framework/components/colliders/box-collider.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module physics - */ - import { ccclass, help, diff --git a/cocos/physics/framework/components/colliders/capsule-collider.ts b/cocos/physics/framework/components/colliders/capsule-collider.ts index ae2074501e..2bacea503d 100644 --- a/cocos/physics/framework/components/colliders/capsule-collider.ts +++ b/cocos/physics/framework/components/colliders/capsule-collider.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module physics - */ - import { ccclass, help, diff --git a/cocos/physics/framework/components/colliders/collider.ts b/cocos/physics/framework/components/colliders/collider.ts index dc0e085828..77b8c62fe5 100644 --- a/cocos/physics/framework/components/colliders/collider.ts +++ b/cocos/physics/framework/components/colliders/collider.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module physics - */ - import { ccclass, tooltip, displayOrder, displayName, readOnly, type, serializable } from 'cc.decorator'; import { EDITOR } from 'internal:constants'; import { Eventify } from '../../../../core/event'; @@ -149,7 +144,7 @@ export class Collider extends Eventify(Component) { * @en * Gets or sets the collider is trigger, this will be always trigger if using builtin. * @zh - * 获取或设置碰撞器是否为触发器。(builtin中无论真假都为触发器) + * 获取或设置碰撞器是否为触发器。(builtin 中无论真假都为触发器) */ @displayOrder(0) @tooltip('i18n:physics3d.collider.isTrigger') @@ -312,7 +307,7 @@ export class Collider extends Eventify(Component) { * Gets the group value. * @zh * 获取分组值。 - * @returns 整数,范围为 2 的 0 次方 到 2 的 31 次方 + * @returns @zh 分组值,为 32 位整数,范围为 [2^0, 2^31] @en Group value which is a 32-bits integer, the range is [2^0, 2^31] */ public getGroup (): number { if (this._isInitialized) { @@ -326,7 +321,7 @@ export class Collider extends Eventify(Component) { * Sets the group value. * @zh * 设置分组值。 - * @param v - 整数,范围为 2 的 0 次方 到 2 的 31 次方 + * @param v @zh 分组值,为 32 位整数,范围为 [2^0, 2^31] @en Group value which is a 32-bits integer, the range is [2^0, 2^31] */ public setGroup (v: number): void { if (this._isInitialized) { @@ -339,7 +334,7 @@ export class Collider extends Eventify(Component) { * Add a grouping value to fill in the group you want to join. * @zh * 添加分组值,可填要加入的 group。 - * @param v - 整数,范围为 2 的 0 次方 到 2 的 31 次方 + * @param v @zh 分组值,为 32 位整数,范围为 [2^0, 2^31] @en Group value which is a 32-bits integer, the range is [2^0, 2^31] */ public addGroup (v: number) { if (this._isInitialized) { @@ -352,7 +347,7 @@ export class Collider extends Eventify(Component) { * Subtract the grouping value to fill in the group to be removed. * @zh * 减去分组值,可填要移除的 group。 - * @param v - 整数,范围为 2 的 0 次方 到 2 的 31 次方 + * @param v @zh 分组值,为 32 位整数,范围为 [2^0, 2^31] @en Group value which is a 32-bits integer, the range is [2^0, 2^31] */ public removeGroup (v: number) { if (this._isInitialized) { @@ -365,7 +360,7 @@ export class Collider extends Eventify(Component) { * Gets the mask value. * @zh * 获取掩码值。 - * @returns 整数,范围为 2 的 0 次方 到 2 的 31 次方 + * @returns @zh 掩码值,为 32 位整数,范围为 [2^0, 2^31] @en Mask value which is a 32-bits integer, the range is [2^0, 2^31] */ public getMask (): number { if (this._isInitialized) { @@ -379,7 +374,7 @@ export class Collider extends Eventify(Component) { * Sets the mask value. * @zh * 设置掩码值。 - * @param v - 整数,范围为 2 的 0 次方 到 2 的 31 次方 + * @param v @zh 掩码值,为 32 位整数,范围为 [2^0, 2^31] @en Mask value which is a 32-bits integer, the range is [2^0, 2^31] */ public setMask (v: number) { if (this._isInitialized) { @@ -392,7 +387,7 @@ export class Collider extends Eventify(Component) { * Add mask values to fill in groups that need to be checked. * @zh * 添加掩码值,可填入需要检查的 group。 - * @param v - 整数,范围为 2 的 0 次方 到 2 的 31 次方 + * @param v @zh 掩码值,为 32 位整数,范围为 [2^0, 2^31] @en Mask value which is a 32-bits integer, the range is [2^0, 2^31] */ public addMask (v: number) { if (this._isInitialized) { @@ -405,7 +400,7 @@ export class Collider extends Eventify(Component) { * Subtract the mask value to fill in the group that does not need to be checked. * @zh * 减去掩码值,可填入不需要检查的 group。 - * @param v - 整数,范围为 2 的 0 次方 到 2 的 31 次方 + * @param v @zh 掩码值,为 32 位整数,范围为 [2^0, 2^31] @en Mask value which is a 32-bits integer, the range is [2^0, 2^31] */ public removeMask (v: number) { if (this._isInitialized) { diff --git a/cocos/physics/framework/components/colliders/cone-collider.ts b/cocos/physics/framework/components/colliders/cone-collider.ts index ee4830a166..c4a1157a76 100644 --- a/cocos/physics/framework/components/colliders/cone-collider.ts +++ b/cocos/physics/framework/components/colliders/cone-collider.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module physics - */ - import { ccclass, help, diff --git a/cocos/physics/framework/components/colliders/cylinder-collider.ts b/cocos/physics/framework/components/colliders/cylinder-collider.ts index 3c5595e737..83a917f0b2 100644 --- a/cocos/physics/framework/components/colliders/cylinder-collider.ts +++ b/cocos/physics/framework/components/colliders/cylinder-collider.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module physics - */ - import { ccclass, help, diff --git a/cocos/physics/framework/components/colliders/mesh-collider.ts b/cocos/physics/framework/components/colliders/mesh-collider.ts index 01bf50f03f..daf7c09ec8 100644 --- a/cocos/physics/framework/components/colliders/mesh-collider.ts +++ b/cocos/physics/framework/components/colliders/mesh-collider.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module physics - */ - import { ccclass, help, diff --git a/cocos/physics/framework/components/colliders/plane-collider.ts b/cocos/physics/framework/components/colliders/plane-collider.ts index d985735b7b..cf329e5ddd 100644 --- a/cocos/physics/framework/components/colliders/plane-collider.ts +++ b/cocos/physics/framework/components/colliders/plane-collider.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module physics - */ - import { ccclass, help, diff --git a/cocos/physics/framework/components/colliders/simplex-collider.ts b/cocos/physics/framework/components/colliders/simplex-collider.ts index 5f9fd905b8..88a2735936 100644 --- a/cocos/physics/framework/components/colliders/simplex-collider.ts +++ b/cocos/physics/framework/components/colliders/simplex-collider.ts @@ -25,11 +25,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module physics - */ - import { ccclass, help, diff --git a/cocos/physics/framework/components/colliders/sphere-collider.ts b/cocos/physics/framework/components/colliders/sphere-collider.ts index b20f476487..c938d8b0ce 100644 --- a/cocos/physics/framework/components/colliders/sphere-collider.ts +++ b/cocos/physics/framework/components/colliders/sphere-collider.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module physics - */ - import { ccclass, help, diff --git a/cocos/physics/framework/components/colliders/terrain-collider.ts b/cocos/physics/framework/components/colliders/terrain-collider.ts index 0def7a1c8e..5dcc6f9440 100644 --- a/cocos/physics/framework/components/colliders/terrain-collider.ts +++ b/cocos/physics/framework/components/colliders/terrain-collider.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module physics - */ - import { ccclass, help, diff --git a/cocos/physics/framework/components/constant-force.ts b/cocos/physics/framework/components/constant-force.ts index 0f6fd8abbd..40470ab6e9 100644 --- a/cocos/physics/framework/components/constant-force.ts +++ b/cocos/physics/framework/components/constant-force.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module physics - */ - import { ccclass, help, diff --git a/cocos/physics/framework/components/constraints/constraint.ts b/cocos/physics/framework/components/constraints/constraint.ts index 7af7ba655a..b515fc9bf0 100644 --- a/cocos/physics/framework/components/constraints/constraint.ts +++ b/cocos/physics/framework/components/constraints/constraint.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module physics - */ - import { ccclass, requireComponent, displayOrder, type, readOnly, serializable } from 'cc.decorator'; import { EDITOR } from 'internal:constants'; import { Component } from '../../../../core'; diff --git a/cocos/physics/framework/components/constraints/hinge-constraint.ts b/cocos/physics/framework/components/constraints/hinge-constraint.ts index dd0279d4fb..e27ebb819b 100644 --- a/cocos/physics/framework/components/constraints/hinge-constraint.ts +++ b/cocos/physics/framework/components/constraints/hinge-constraint.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module physics - */ - import { ccclass, help, diff --git a/cocos/physics/framework/components/constraints/point-to-point-constraint.ts b/cocos/physics/framework/components/constraints/point-to-point-constraint.ts index 238e152b0e..6efde7fc6d 100644 --- a/cocos/physics/framework/components/constraints/point-to-point-constraint.ts +++ b/cocos/physics/framework/components/constraints/point-to-point-constraint.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module physics - */ - import { ccclass, help, diff --git a/cocos/physics/framework/components/rigid-body.ts b/cocos/physics/framework/components/rigid-body.ts index 5479144ba3..4f2f6f116a 100644 --- a/cocos/physics/framework/components/rigid-body.ts +++ b/cocos/physics/framework/components/rigid-body.ts @@ -25,11 +25,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module physics - */ - import { ccclass, help, @@ -440,8 +435,8 @@ export class RigidBody extends Component { * Apply force to a world point. This could, for example, be a point on the Body surface. * @zh * 在世界空间中,相对于刚体的质心的某点上对刚体施加作用力。 - * @param force - 作用力 - * @param relativePoint - 作用点,相对于刚体的质心 + * @param force @zh 作用力 @en The force applied + * @param relativePoint @zh 作用点,相对于刚体的质心 @en The point to apply the force on, relative to the center of mass of the rigid body */ public applyForce (force: Vec3, relativePoint?: Vec3) { if (this._isInitialized) this._body!.applyForce(force, relativePoint); @@ -452,8 +447,8 @@ export class RigidBody extends Component { * Apply force to a local point. This could, for example, be a point on the Body surface. * @zh * 在本地空间中,相对于刚体的质心的某点上对刚体施加作用力。 - * @param force - 作用力 - * @param localPoint - 作用点 + * @param force @zh 作用力 @en The force applied + * @param localPoint @zh 作用点 @en The point to apply the force on */ public applyLocalForce (force: Vec3, localPoint?: Vec3) { if (this._isInitialized) this._body!.applyLocalForce(force, localPoint); @@ -464,8 +459,8 @@ export class RigidBody extends Component { * In world space, impulse is applied to the rigid body at some point relative to the center of mass of the rigid body. * @zh * 在世界空间中,相对于刚体的质心的某点上对刚体施加冲量。 - * @param impulse - 冲量 - * @param relativePoint - 作用点,相对于刚体的中心点 + * @param impulse @zh 冲量 @en The impulse applied + * @param relativePoint @zh 作用点,相对于刚体的中心点 @en The point to apply the impulse, relative to the center of mass of the rigid body */ public applyImpulse (impulse: Vec3, relativePoint?: Vec3) { if (this._isInitialized) this._body!.applyImpulse(impulse, relativePoint); @@ -476,8 +471,8 @@ export class RigidBody extends Component { * In local space, impulse is applied to the rigid body at some point relative to the center of mass of the rigid body. * @zh * 在本地空间中,相对于刚体的质心的某点上对刚体施加冲量。 - * @param impulse - 冲量 - * @param localPoint - 作用点 + * @param impulse @zh 冲量 @en The impulse applied + * @param localPoint @zh 作用点 @en The point to apply the impulse */ public applyLocalImpulse (impulse: Vec3, localPoint?: Vec3) { if (this._isInitialized) this._body!.applyLocalImpulse(impulse, localPoint); @@ -488,7 +483,7 @@ export class RigidBody extends Component { * In world space, torque is applied to the rigid body. * @zh * 在世界空间中,对刚体施加扭矩。 - * @param torque - 扭矩 + * @param torque @zh 扭矩 @en The torque applied */ public applyTorque (torque: Vec3) { if (this._isInitialized) this._body!.applyTorque(torque); @@ -497,7 +492,9 @@ export class RigidBody extends Component { /** * @zh * 在本地空间中,对刚体施加扭矩。 - * @param torque - 扭矩 + * @zh + * In local space, torque is applied to the rigid body. + * @param torque @zh 扭矩 @en The torque applied */ public applyLocalTorque (torque: Vec3) { if (this._isInitialized) this._body!.applyLocalTorque(torque); @@ -558,7 +555,7 @@ export class RigidBody extends Component { * Gets the linear velocity. * @zh * 获取线性速度。 - * @param out 速度 Vec3 + * @param out @zh 速度向量 @en The velocity vector */ public getLinearVelocity (out: Vec3) { if (this._isInitialized) this._body!.getLinearVelocity(out); @@ -569,7 +566,7 @@ export class RigidBody extends Component { * Sets the linear velocity. * @zh * 设置线性速度。 - * @param value 速度 Vec3 + * @param value @zh 速度向量 @en The velocity vector */ public setLinearVelocity (value: Vec3): void { if (this._isInitialized) this._body!.setLinearVelocity(value); @@ -580,7 +577,7 @@ export class RigidBody extends Component { * Gets the angular velocity. * @zh * 获取旋转速度。 - * @param out 速度 Vec3 + * @param out @zh 角速度向量 @en The angular velocity vector */ public getAngularVelocity (out: Vec3) { if (this._isInitialized) this._body!.getAngularVelocity(out); @@ -591,7 +588,7 @@ export class RigidBody extends Component { * Sets the angular velocity. * @zh * 设置旋转速度。 - * @param value 速度 Vec3 + * @param value @zh 角速度向量 @en The angular velocity vector */ public setAngularVelocity (value: Vec3): void { if (this._isInitialized) this._body!.setAngularVelocity(value); @@ -604,7 +601,7 @@ export class RigidBody extends Component { * Gets the group value. * @zh * 获取分组值。 - * @returns 整数,范围为 2 的 0 次方 到 2 的 31 次方 + * @returns @zh 分组值,为 32 位整数,范围为 [2^0, 2^31] @en Group value which is a 32-bits integer, the range is [2^0, 2^31] */ public getGroup (): number { if (this._isInitialized) return this._body!.getGroup(); @@ -616,7 +613,7 @@ export class RigidBody extends Component { * Sets the group value. * @zh * 设置分组值。 - * @param v - 整数,范围为 2 的 0 次方 到 2 的 31 次方 + * @param v @zh 分组值,为 32 位整数,范围为 [2^0, 2^31] @en Group value which is a 32-bits integer, the range is [2^0, 2^31] */ public setGroup (v: number): void { if (this._isInitialized) this._body!.setGroup(v); @@ -627,7 +624,7 @@ export class RigidBody extends Component { * Add a grouping value to fill in the group you want to join. * @zh * 添加分组值,可填要加入的 group。 - * @param v - 整数,范围为 2 的 0 次方 到 2 的 31 次方 + * @param v @zh 分组值,为 32 位整数,范围为 [2^0, 2^31] @en Group value which is a 32-bits integer, the range is [2^0, 2^31] */ public addGroup (v: number) { if (this._isInitialized) this._body!.addGroup(v); @@ -638,7 +635,7 @@ export class RigidBody extends Component { * Subtract the grouping value to fill in the group to be removed. * @zh * 减去分组值,可填要移除的 group。 - * @param v - 整数,范围为 2 的 0 次方 到 2 的 31 次方 + * @param v @zh 分组值,为 32 位整数,范围为 [2^0, 2^31] @en Group value which is a 32-bits integer, the range is [2^0, 2^31] */ public removeGroup (v: number) { if (this._isInitialized) this._body!.removeGroup(v); @@ -649,7 +646,7 @@ export class RigidBody extends Component { * Gets the mask value. * @zh * 获取掩码值。 - * @returns 整数,范围为 2 的 0 次方 到 2 的 31 次方 + * @returns {number} @zh 掩码值,为 32 位整数,范围为 [2^0, 2^31] @en Mask value which is a 32-bits integer, the range is [2^0, 2^31] */ public getMask (): number { if (this._isInitialized) return this._body!.getMask(); @@ -661,7 +658,7 @@ export class RigidBody extends Component { * Sets the mask value. * @zh * 设置掩码值。 - * @param v - 整数,范围为 2 的 0 次方 到 2 的 31 次方 + * @param v @zh 掩码值,为 32 位整数,范围为 [2^0, 2^31] @en Mask value which is a 32-bits integer, the range is [2^0, 2^31] */ public setMask (v: number) { if (this._isInitialized) this._body!.setMask(v); @@ -672,7 +669,7 @@ export class RigidBody extends Component { * Add mask values to fill in groups that need to be checked. * @zh * 添加掩码值,可填入需要检查的 group。 - * @param v - 整数,范围为 2 的 0 次方 到 2 的 31 次方 + * @param v @zh 掩码值,为 32 位整数,范围为 [2^0, 2^31] @en Mask value which is a 32-bits integer, the range is [2^0, 2^31] */ public addMask (v: number) { if (this._isInitialized) this._body!.addMask(v); @@ -683,7 +680,7 @@ export class RigidBody extends Component { * Subtract the mask value to fill in the group that does not need to be checked. * @zh * 减去掩码值,可填入不需要检查的 group。 - * @param v - 整数,范围为 2 的 0 次方 到 2 的 31 次方 + * @param v @zh 掩码值,为 32 位整数,范围为 [2^0, 2^31] @en Mask value which is a 32-bits integer, the range is [2^0, 2^31] */ public removeMask (v: number) { if (this._isInitialized) this._body!.removeMask(v); diff --git a/cocos/physics/framework/deprecated.ts b/cocos/physics/framework/deprecated.ts index 78a79e0188..b0e75b5517 100644 --- a/cocos/physics/framework/deprecated.ts +++ b/cocos/physics/framework/deprecated.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module physics - */ - import { PhysicsSystem } from './physics-system'; import { replaceProperty, removeProperty } from '../../core/utils/x-deprecated'; import { BoxCollider } from './components/colliders/box-collider'; diff --git a/cocos/physics/framework/index.ts b/cocos/physics/framework/index.ts index 8742da8740..530128cbd5 100644 --- a/cocos/physics/framework/index.ts +++ b/cocos/physics/framework/index.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { PhysicsSystem } from './physics-system'; import { PhysicsMaterial } from './assets/physics-material'; import { PhysicsRayResult } from './physics-ray-result'; diff --git a/cocos/physics/framework/physics-config.ts b/cocos/physics/framework/physics-config.ts index 3aced326d5..090262d963 100644 --- a/cocos/physics/framework/physics-config.ts +++ b/cocos/physics/framework/physics-config.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { IVec3Like } from '../../core'; export interface ICollisionMatrix { diff --git a/cocos/physics/framework/physics-enum.ts b/cocos/physics/framework/physics-enum.ts index d02925c897..579de3f6d2 100644 --- a/cocos/physics/framework/physics-enum.ts +++ b/cocos/physics/framework/physics-enum.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module physics - */ - import { Enum } from '../../core'; export enum ERigidBodyType { diff --git a/cocos/physics/framework/physics-interface.ts b/cocos/physics/framework/physics-interface.ts index 43291f3ce0..f785d31b07 100644 --- a/cocos/physics/framework/physics-interface.ts +++ b/cocos/physics/framework/physics-interface.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module physics - */ - import { IVec3Like } from '../../core/math'; import { Collider } from './components/colliders/collider'; diff --git a/cocos/physics/framework/physics-ray-result.ts b/cocos/physics/framework/physics-ray-result.ts index d53e0529e4..177afdceed 100644 --- a/cocos/physics/framework/physics-ray-result.ts +++ b/cocos/physics/framework/physics-ray-result.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module physics - */ - import { Vec3 } from '../../core/math'; import { Collider } from '../../../exports/physics-framework'; import { IVec3Like } from '../../core/math/type-define'; diff --git a/cocos/physics/framework/physics-selector.ts b/cocos/physics/framework/physics-selector.ts index 6682b9b925..284a98d27c 100644 --- a/cocos/physics/framework/physics-selector.ts +++ b/cocos/physics/framework/physics-selector.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - /* eslint-disable import/no-mutable-exports */ /* eslint-disable @typescript-eslint/restrict-template-expressions */ /* eslint-disable @typescript-eslint/no-unsafe-return */ diff --git a/cocos/physics/framework/physics-system.ts b/cocos/physics/framework/physics-system.ts index a1fe60ae68..6244217579 100644 --- a/cocos/physics/framework/physics-system.ts +++ b/cocos/physics/framework/physics-system.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module physics - */ - import { EDITOR } from 'internal:constants'; import { Vec3 } from '../../core/math'; import { IRaycastOptions } from '../spec/i-physics-world'; @@ -408,11 +403,12 @@ export class PhysicsSystem extends System implements IWorldInitData { * Collision detect all collider, and record all the detected results, through PhysicsSystem.Instance.RaycastResults access to the results. * @zh * 检测所有的碰撞盒,并记录所有被检测到的结果,通过 PhysicsSystem.instance.raycastResults 访问结果。 - * @param worldRay 世界空间下的一条射线 - * @param mask 掩码,默认为 0xffffffff - * @param maxDistance 最大检测距离,默认为 10000000,目前请勿传入 Infinity 或 Number.MAX_VALUE - * @param queryTrigger 是否检测触发器 - * @return boolean 表示是否有检测到碰撞盒 + * @param worldRay @zh 世界空间下的一条射线 @en A ray in world space + * @param mask @zh 掩码,默认为 0xffffffff @en Mask, default value is 0xffffffff + * @param maxDistance @zh 最大检测距离,默认为 10000000,目前请勿传入 Infinity 或 Number.MAX_VALUE + * @en Maximum detection distance, default value is 10000000, do not pass Infinity or Number.MAX_VALUE for now + * @param queryTrigger @zh 是否检测触发器 @en Whether to detect triggers + * @return {boolean} @zh 表示是否有检测到碰撞 @en Indicates whether a collision has been detected */ raycast (worldRay: Ray, mask = 0xffffffff, maxDistance = 10000000, queryTrigger = true): boolean { if (!this.physicsWorld) return false; @@ -430,11 +426,12 @@ export class PhysicsSystem extends System implements IWorldInitData { * by PhysicsSystem.Instance.RaycastClosestResult access to the results. * @zh * 检测所有的碰撞盒,并记录与射线距离最短的检测结果,通过 PhysicsSystem.instance.raycastClosestResult 访问结果。 - * @param worldRay 世界空间下的一条射线 - * @param mask 掩码,默认为 0xffffffff - * @param maxDistance 最大检测距离,默认为 10000000,目前请勿传入 Infinity 或 Number.MAX_VALUE - * @param queryTrigger 是否检测触发器 - * @return boolean 表示是否有检测到碰撞盒 + * @param worldRay @zh 世界空间下的一条射线 @en A ray in world space + * @param mask @zh 掩码,默认为 0xffffffff @en Mask, default value is 0xffffffff + * @param maxDistance @zh 最大检测距离,默认为 10000000,目前请勿传入 Infinity 或 Number.MAX_VALUE + * @en Maximum detection distance, default value is 10000000, do not pass Infinity or Number.MAX_VALUE for now + * @param queryTrigger @zh 是否检测触发器 @en Whether to detect triggers + * @return {boolean} @zh 表示是否有检测到碰撞 @en Indicates whether a collision has been detected */ raycastClosest (worldRay: Ray, mask = 0xffffffff, maxDistance = 10000000, queryTrigger = true): boolean { if (!this.physicsWorld) return false; diff --git a/cocos/physics/physx/instantiate.jsb.ts b/cocos/physics/physx/instantiate.jsb.ts index d8ba7b2fa8..f5325cc416 100644 --- a/cocos/physics/physx/instantiate.jsb.ts +++ b/cocos/physics/physx/instantiate.jsb.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - /** * hack for jsb, shoule be refactor in futrue */ diff --git a/cocos/physics/physx/instantiate.ts b/cocos/physics/physx/instantiate.ts index 10856d1a60..2f8a01215b 100644 --- a/cocos/physics/physx/instantiate.ts +++ b/cocos/physics/physx/instantiate.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { selector } from '../framework/physics-selector'; import { PhysXWorld } from './physx-world'; diff --git a/cocos/physics/physx/joints/physx-distance-joint.ts b/cocos/physics/physx/joints/physx-distance-joint.ts index d006710098..743fb3777e 100644 --- a/cocos/physics/physx/joints/physx-distance-joint.ts +++ b/cocos/physics/physx/joints/physx-distance-joint.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { IVec3Like, Quat, Vec3 } from '../../../core'; import { PointToPointConstraint } from '../../framework'; import { IPointToPointConstraint } from '../../spec/i-physics-constraint'; diff --git a/cocos/physics/physx/joints/physx-fixed-joint.ts b/cocos/physics/physx/joints/physx-fixed-joint.ts index 2faa80ac1d..1af6df9159 100644 --- a/cocos/physics/physx/joints/physx-fixed-joint.ts +++ b/cocos/physics/physx/joints/physx-fixed-joint.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { IVec3Like } from '../../../core'; import { PointToPointConstraint } from '../../framework'; import { IPointToPointConstraint } from '../../spec/i-physics-constraint'; diff --git a/cocos/physics/physx/joints/physx-joint.ts b/cocos/physics/physx/joints/physx-joint.ts index 5d9e995cd5..53eddb1b8d 100644 --- a/cocos/physics/physx/joints/physx-joint.ts +++ b/cocos/physics/physx/joints/physx-joint.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - /* eslint-disable @typescript-eslint/no-unsafe-return */ import { Constraint, RigidBody } from '../../framework'; import { IBaseConstraint } from '../../spec/i-physics-constraint'; diff --git a/cocos/physics/physx/joints/physx-revolute-joint.ts b/cocos/physics/physx/joints/physx-revolute-joint.ts index 248a0fbc20..8110e588f2 100644 --- a/cocos/physics/physx/joints/physx-revolute-joint.ts +++ b/cocos/physics/physx/joints/physx-revolute-joint.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { IVec3Like, Quat, Vec3 } from '../../../core'; import { HingeConstraint } from '../../framework'; import { IHingeConstraint } from '../../spec/i-physics-constraint'; diff --git a/cocos/physics/physx/physx-adapter.ts b/cocos/physics/physx/physx-adapter.ts index ca00724b78..1fee301180 100644 --- a/cocos/physics/physx/physx-adapter.ts +++ b/cocos/physics/physx/physx-adapter.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - /* eslint-disable import/no-mutable-exports */ /* eslint-disable no-console */ /* eslint-disable @typescript-eslint/restrict-template-expressions */ diff --git a/cocos/physics/physx/physx-contact-equation.ts b/cocos/physics/physx/physx-contact-equation.ts index baa478cdf2..33016b59f7 100644 --- a/cocos/physics/physx/physx-contact-equation.ts +++ b/cocos/physics/physx/physx-contact-equation.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { IVec3Like, Vec3, Quat } from '../../core'; import { IContactEquation, ICollisionEvent, Collider } from '../framework'; import { getContactNormal, getContactPosition } from './physx-adapter'; diff --git a/cocos/physics/physx/physx-enum.ts b/cocos/physics/physx/physx-enum.ts index 8d52dae220..4b1cb94037 100644 --- a/cocos/physics/physx/physx-enum.ts +++ b/cocos/physics/physx/physx-enum.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - /* eslint-disable max-len */ /* eslint-disable no-tabs */ diff --git a/cocos/physics/physx/physx-rigid-body.ts b/cocos/physics/physx/physx-rigid-body.ts index 93746c7dad..3420a5f7ed 100644 --- a/cocos/physics/physx/physx-rigid-body.ts +++ b/cocos/physics/physx/physx-rigid-body.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - /* eslint-disable @typescript-eslint/no-unsafe-return */ import { IVec3Like, Vec3 } from '../../core'; import { ERigidBodyType, PhysicsSystem, RigidBody } from '../framework'; diff --git a/cocos/physics/physx/physx-shared-body.ts b/cocos/physics/physx/physx-shared-body.ts index 09b7611050..8dca8fb10a 100644 --- a/cocos/physics/physx/physx-shared-body.ts +++ b/cocos/physics/physx/physx-shared-body.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - /* eslint-disable @typescript-eslint/no-unsafe-return */ import { Node, Quat, Vec3 } from '../../core'; import { PhysXRigidBody } from './physx-rigid-body'; diff --git a/cocos/physics/physx/physx-world.ts b/cocos/physics/physx/physx-world.ts index 09ca294eae..c1bfe16614 100644 --- a/cocos/physics/physx/physx-world.ts +++ b/cocos/physics/physx/physx-world.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - /* eslint-disable @typescript-eslint/no-unsafe-return */ import { Ray } from '../../core/geometry'; import { IPhysicsWorld, IRaycastOptions } from '../spec/i-physics-world'; diff --git a/cocos/physics/physx/physx.asmjs.ts b/cocos/physics/physx/physx.asmjs.ts index 0fb16c86be..d01c92ab25 100644 --- a/cocos/physics/physx/physx.asmjs.ts +++ b/cocos/physics/physx/physx.asmjs.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - /** * export PhysX from internal module */ diff --git a/cocos/physics/physx/physx.null.ts b/cocos/physics/physx/physx.null.ts index 0e42db1ac4..adb72452f7 100644 --- a/cocos/physics/physx/physx.null.ts +++ b/cocos/physics/physx/physx.null.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - /** * export null for module elimination */ diff --git a/cocos/physics/physx/shapes/physx-box-shape.ts b/cocos/physics/physx/shapes/physx-box-shape.ts index 523409ce09..2f7413224e 100644 --- a/cocos/physics/physx/shapes/physx-box-shape.ts +++ b/cocos/physics/physx/shapes/physx-box-shape.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { BoxCollider } from '../../framework'; import { absolute, VEC3_0 } from '../../utils/util'; import { IBoxShape } from '../../spec/i-physics-shape'; diff --git a/cocos/physics/physx/shapes/physx-capsule-shape.ts b/cocos/physics/physx/shapes/physx-capsule-shape.ts index 57239c768e..81ae841e76 100644 --- a/cocos/physics/physx/shapes/physx-capsule-shape.ts +++ b/cocos/physics/physx/shapes/physx-capsule-shape.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { absMax, Quat } from '../../../core'; import { CapsuleCollider, EAxisDirection } from '../../framework'; import { ICapsuleShape } from '../../spec/i-physics-shape'; diff --git a/cocos/physics/physx/shapes/physx-cone-shape.ts b/cocos/physics/physx/shapes/physx-cone-shape.ts index 62d51ef88e..50ac6746f3 100644 --- a/cocos/physics/physx/shapes/physx-cone-shape.ts +++ b/cocos/physics/physx/shapes/physx-cone-shape.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { Quat, Vec3 } from '../../../core'; import cylinder from '../../../primitive/cylinder'; import { ConeCollider, EAxisDirection } from '../../framework'; diff --git a/cocos/physics/physx/shapes/physx-cylinder-shape.ts b/cocos/physics/physx/shapes/physx-cylinder-shape.ts index b12a830949..8fa0240212 100644 --- a/cocos/physics/physx/shapes/physx-cylinder-shape.ts +++ b/cocos/physics/physx/shapes/physx-cylinder-shape.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { Quat, Vec3 } from '../../../core'; import cylinder from '../../../primitive/cylinder'; import { CylinderCollider, EAxisDirection } from '../../framework'; diff --git a/cocos/physics/physx/shapes/physx-plane-shape.ts b/cocos/physics/physx/shapes/physx-plane-shape.ts index c0f06ad04d..28ea3e2f6f 100644 --- a/cocos/physics/physx/shapes/physx-plane-shape.ts +++ b/cocos/physics/physx/shapes/physx-plane-shape.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { IVec3Like, Quat, Vec3 } from '../../../core'; import { PlaneCollider } from '../../framework'; import { IPlaneShape } from '../../spec/i-physics-shape'; diff --git a/cocos/physics/physx/shapes/physx-shape.ts b/cocos/physics/physx/shapes/physx-shape.ts index a2b9cf2684..9f1cb4f9f0 100644 --- a/cocos/physics/physx/shapes/physx-shape.ts +++ b/cocos/physics/physx/shapes/physx-shape.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - /* eslint-disable @typescript-eslint/no-unsafe-return */ import { IVec3Like, Quat, Vec3 } from '../../../core'; import { AABB, Sphere } from '../../../core/geometry'; diff --git a/cocos/physics/physx/shapes/physx-sphere-shape.ts b/cocos/physics/physx/shapes/physx-sphere-shape.ts index 017cdbf5a7..2799023623 100644 --- a/cocos/physics/physx/shapes/physx-sphere-shape.ts +++ b/cocos/physics/physx/shapes/physx-sphere-shape.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { absMaxComponent } from '../../../core'; import { SphereCollider } from '../../framework'; import { ISphereShape } from '../../spec/i-physics-shape'; diff --git a/cocos/physics/physx/shapes/physx-terrain-shape.ts b/cocos/physics/physx/shapes/physx-terrain-shape.ts index 10c233f3a7..3a8fb9d4b4 100644 --- a/cocos/physics/physx/shapes/physx-terrain-shape.ts +++ b/cocos/physics/physx/shapes/physx-terrain-shape.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { IVec3Like } from '../../../core'; import { PhysicsMaterial, TerrainCollider } from '../../framework'; import { ITerrainAsset } from '../../spec/i-external'; diff --git a/cocos/physics/physx/shapes/physx-trimesh-shape.ts b/cocos/physics/physx/shapes/physx-trimesh-shape.ts index 780f4c07ea..51a049e05b 100644 --- a/cocos/physics/physx/shapes/physx-trimesh-shape.ts +++ b/cocos/physics/physx/shapes/physx-trimesh-shape.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { IVec3Like, Quat, Vec3 } from '../../../core'; import { Mesh } from '../../../3d/assets'; diff --git a/cocos/physics/spec/i-external.ts b/cocos/physics/spec/i-external.ts index 0b2a9a4634..7ce0bb3c8d 100644 --- a/cocos/physics/spec/i-external.ts +++ b/cocos/physics/spec/i-external.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - export interface ITerrainAsset { _uuid: string; tileSize: number; diff --git a/cocos/physics/spec/i-group-mask.ts b/cocos/physics/spec/i-group-mask.ts index 0bbc11c7e4..439698f353 100644 --- a/cocos/physics/spec/i-group-mask.ts +++ b/cocos/physics/spec/i-group-mask.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - export interface IGroupMask { setGroup (v: number): void; getGroup (): number; diff --git a/cocos/physics/spec/i-lifecycle.ts b/cocos/physics/spec/i-lifecycle.ts index 98322c5736..6b9c740925 100644 --- a/cocos/physics/spec/i-lifecycle.ts +++ b/cocos/physics/spec/i-lifecycle.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - export interface ILifecycle { /** * @en Update is called every frame, if the Component is enabled.
diff --git a/cocos/physics/spec/i-physics-constraint.ts b/cocos/physics/spec/i-physics-constraint.ts index 37c07964a1..8141bffa26 100644 --- a/cocos/physics/spec/i-physics-constraint.ts +++ b/cocos/physics/spec/i-physics-constraint.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { ILifecycle } from './i-lifecycle'; import { Constraint, RigidBody } from '../framework'; import { IVec3Like } from '../../core'; diff --git a/cocos/physics/spec/i-physics-shape.ts b/cocos/physics/spec/i-physics-shape.ts index 4875aa5d5f..8c218b1382 100644 --- a/cocos/physics/spec/i-physics-shape.ts +++ b/cocos/physics/spec/i-physics-shape.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { ILifecycle } from './i-lifecycle'; import { IGroupMask } from './i-group-mask'; import { IVec3Like } from '../../core/math/type-define'; diff --git a/cocos/physics/spec/i-physics-world.ts b/cocos/physics/spec/i-physics-world.ts index 722bcf1578..22544ffb57 100644 --- a/cocos/physics/spec/i-physics-world.ts +++ b/cocos/physics/spec/i-physics-world.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { IVec3Like } from '../../core/math/type-define'; import { PhysicsRayResult } from '../framework/physics-ray-result'; import { Ray } from '../../core/geometry'; diff --git a/cocos/physics/spec/i-rigid-body.ts b/cocos/physics/spec/i-rigid-body.ts index 1bf988460d..6300f27336 100644 --- a/cocos/physics/spec/i-rigid-body.ts +++ b/cocos/physics/spec/i-rigid-body.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - import { ILifecycle } from './i-lifecycle'; import { IGroupMask } from './i-group-mask'; import { IVec3Like } from '../../core/math/type-define'; diff --git a/cocos/physics/utils/array-collision-matrix.ts b/cocos/physics/utils/array-collision-matrix.ts index 0369b87f29..11e06373a1 100644 --- a/cocos/physics/utils/array-collision-matrix.ts +++ b/cocos/physics/utils/array-collision-matrix.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - /** * Collision "matrix". It's actually a triangular-shaped array of whether two bodies are touching this step, for reference next step * @class ArrayCollisionMatrix diff --git a/cocos/physics/utils/object-collision-matrix.ts b/cocos/physics/utils/object-collision-matrix.ts index 723755ceaf..3272e226f4 100644 --- a/cocos/physics/utils/object-collision-matrix.ts +++ b/cocos/physics/utils/object-collision-matrix.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - /** * Records what objects are colliding with each other * @class ObjectCollisionMatrix diff --git a/cocos/physics/utils/tuple-dictionary.ts b/cocos/physics/utils/tuple-dictionary.ts index ad491139fb..f89ff816b4 100644 --- a/cocos/physics/utils/tuple-dictionary.ts +++ b/cocos/physics/utils/tuple-dictionary.ts @@ -23,8 +23,6 @@ THE SOFTWARE. */ - - /** * @class TupleDictionary * @constructor diff --git a/cocos/physics/utils/util.ts b/cocos/physics/utils/util.ts index 03a2978bf1..c306656d06 100644 --- a/cocos/physics/utils/util.ts +++ b/cocos/physics/utils/util.ts @@ -23,7 +23,6 @@ THE SOFTWARE. */ - import { equals, Vec3 } from '../../core'; import { IVec3Like, IQuatLike } from '../../core/math/type-define'; import { Collider, CollisionEventType, IContactEquation, TriggerEventType } from '../framework'; diff --git a/cocos/primitive/box.ts b/cocos/primitive/box.ts index 8131865676..a0f9152ac1 100644 --- a/cocos/primitive/box.ts +++ b/cocos/primitive/box.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module 3d/primitive - */ - import { Vec3 } from '../core/math'; import { IGeometry, IGeometryOptions } from './define'; diff --git a/cocos/primitive/capsule.ts b/cocos/primitive/capsule.ts index d2047faa9d..54b98cb22d 100644 --- a/cocos/primitive/capsule.ts +++ b/cocos/primitive/capsule.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module 3d/primitive - */ - import { Vec3 } from '../core/math'; /** diff --git a/cocos/primitive/circle.ts b/cocos/primitive/circle.ts index 56733c742e..0c30b4a0d3 100644 --- a/cocos/primitive/circle.ts +++ b/cocos/primitive/circle.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module 3d/primitive - */ - import { PrimitiveMode } from '../core/gfx'; import { applyDefaultGeometryOptions, IGeometry, IGeometryOptions } from './define'; diff --git a/cocos/primitive/cone.ts b/cocos/primitive/cone.ts index bfcf3160ef..9af308d4a9 100644 --- a/cocos/primitive/cone.ts +++ b/cocos/primitive/cone.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module 3d/primitive - */ - import cylinder, { ICylinderOptions } from './cylinder'; import { IGeometry } from './define'; diff --git a/cocos/primitive/cylinder.ts b/cocos/primitive/cylinder.ts index 7701d837ca..7d75a35666 100644 --- a/cocos/primitive/cylinder.ts +++ b/cocos/primitive/cylinder.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module 3d/primitive - */ - import { Vec3 } from '../core/math'; import { IGeometry, IGeometryOptions } from './define'; @@ -38,10 +33,10 @@ import { IGeometry, IGeometryOptions } from './define'; * 圆柱参数选项。 */ export interface ICylinderOptions extends IGeometryOptions { - radialSegments: number; - heightSegments: number; - capped: boolean; - arc: number; + radialSegments: number; + heightSegments: number; + capped: boolean; + arc: number; } const temp1 = new Vec3(0, 0, 0); @@ -53,9 +48,10 @@ const temp2 = new Vec3(0, 0, 0); * but may be repositioned through the `center` option. * @zh * 生成一个圆柱。 - * @param radiusTop 顶部半径。 - * @param radiusBottom 底部半径。 - * @param opts 圆柱参数选项。 + * @param radiusTop @en Radius of top plane. @zh 顶部半径。 + * @param radiusBottom @en Radius of bottom plane. @zh 底部半径。 + * @param height @en The cylinder height. @zh 圆柱的高 + * @param opts @en Options of cylinder. @zh 圆柱参数选项。 */ export default function cylinder (radiusTop = 0.5, radiusBottom = 0.5, height = 2, opts: RecursivePartial = {}): IGeometry { const halfHeight = height * 0.5; diff --git a/cocos/primitive/define.ts b/cocos/primitive/define.ts index e6a57a13ef..f45b70b78f 100644 --- a/cocos/primitive/define.ts +++ b/cocos/primitive/define.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module 3d/primitive - */ - import { PrimitiveMode, Attribute } from '../core/gfx'; /** diff --git a/cocos/primitive/index.ts b/cocos/primitive/index.ts index baa6739a8b..77608aad3a 100644 --- a/cocos/primitive/index.ts +++ b/cocos/primitive/index.ts @@ -23,13 +23,6 @@ THE SOFTWARE. */ -/** - * @en A basic module for creating vertex data for 3D objects. - * @zh 一个创建 3D 物体顶点数据的基础模块。 - * @packageDocumentation - * @module 3d/primitive - */ - export * from './utils'; export * from './define'; export { default as box } from './box'; diff --git a/cocos/primitive/plane.ts b/cocos/primitive/plane.ts index 9ba2558ae5..1a4c069f2a 100644 --- a/cocos/primitive/plane.ts +++ b/cocos/primitive/plane.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module 3d/primitive - */ - import { Vec3 } from '../core/math'; import { applyDefaultGeometryOptions, IGeometry, IGeometryOptions } from './define'; diff --git a/cocos/primitive/primitive.ts b/cocos/primitive/primitive.ts index 4c41c3d7b8..286c2b31d4 100644 --- a/cocos/primitive/primitive.ts +++ b/cocos/primitive/primitive.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module 3d/primitive - */ - import { ccclass, type, serializable, editable } from 'cc.decorator'; import { createMesh } from '../3d/misc'; import { Mesh } from '../3d/assets/mesh'; diff --git a/cocos/primitive/quad.ts b/cocos/primitive/quad.ts index af22fa826d..e286315b7a 100644 --- a/cocos/primitive/quad.ts +++ b/cocos/primitive/quad.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module 3d/primitive - */ - import { applyDefaultGeometryOptions, IGeometry, IGeometryOptions } from './define'; /** diff --git a/cocos/primitive/sphere.ts b/cocos/primitive/sphere.ts index 254f95c416..678248ace2 100644 --- a/cocos/primitive/sphere.ts +++ b/cocos/primitive/sphere.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module 3d/primitive - */ - import { Vec3 } from '../core/math'; import { IGeometry, IGeometryOptions } from './define'; @@ -44,8 +39,8 @@ interface ISphereOptions extends IGeometryOptions { * Generate a shpere with radius 0.5. * @zh * 生成一个球。 - * @param radius 球半径。 - * @param options 参数选项。 + * @param radius @en The radius. @zh 球半径。 + * @param options @en The sphere creation options. @zh 参数选项。 */ export default function sphere (radius = 0.5, opts: RecursivePartial = {}): IGeometry { const segments = opts.segments !== undefined ? opts.segments : 32; diff --git a/cocos/primitive/torus.ts b/cocos/primitive/torus.ts index 03187c15b1..de5ca9cefe 100644 --- a/cocos/primitive/torus.ts +++ b/cocos/primitive/torus.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module 3d/primitive - */ - import { Vec3 } from '../core/math'; import { IGeometryOptions } from './define'; @@ -36,9 +31,9 @@ import { IGeometryOptions } from './define'; * 环面参数选项。 */ interface ITorusOptions extends IGeometryOptions { - radialSegments: number; - tubularSegments: number; - arc: number; + radialSegments: number; + tubularSegments: number; + arc: number; } /** diff --git a/cocos/primitive/transform.ts b/cocos/primitive/transform.ts index 428e80ae6f..a808077d02 100644 --- a/cocos/primitive/transform.ts +++ b/cocos/primitive/transform.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module 3d/primitive - */ - import { PrimitiveMode } from '../core/gfx'; import { IGeometry } from './define'; diff --git a/cocos/primitive/utils.ts b/cocos/primitive/utils.ts index 0b7f200d4e..de5a311e6b 100644 --- a/cocos/primitive/utils.ts +++ b/cocos/primitive/utils.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module 3d/primitive - */ - import { PrimitiveMode } from '../core/gfx'; import { IGeometry } from './define'; diff --git a/cocos/spine/assembler/simple.ts b/cocos/spine/assembler/simple.ts index a5608d863a..d6d01ab854 100644 --- a/cocos/spine/assembler/simple.ts +++ b/cocos/spine/assembler/simple.ts @@ -1,4 +1,27 @@ +/* + Copyright (c) 2020-2022 Xiamen Yaji Software Co., Ltd. + https://www.cocos.com/ + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + */ import spine from '../lib/spine-core.js'; import { IAssembler } from '../../2d/renderer/base'; @@ -14,10 +37,8 @@ import { legacyCC } from '../../core/global-exports'; import { StaticVBAccessor, StaticVBChunk } from '../../2d/renderer/static-vb-accessor'; import { RenderData } from '../../2d/renderer/render-data'; -const FLAG_BATCH = 0x10; const FLAG_TWO_COLOR = 0x01; -let _handleVal = 0x00; const _quadTriangles = [0, 1, 2, 2, 3, 0]; const _slotColor = new Color(0, 0, 255, 255); const _boneColor = new Color(255, 0, 0, 255); @@ -261,7 +282,6 @@ function updateComponentRenderData (comp: Skeleton, batcher: Batcher2D) { _mustFlush = true; _premultipliedAlpha = comp.premultipliedAlpha; _multiplier = 1.0; - _handleVal = 0x00; _needColor = false; _vertexEffect = comp._effectDelegate && comp._effectDelegate._vertexEffect as any; @@ -269,23 +289,12 @@ function updateComponentRenderData (comp: Skeleton, batcher: Batcher2D) { _needColor = true; } - if (_useTint) { - _handleVal |= FLAG_TWO_COLOR; - } - - let worldMat: Mat4 | undefined; - if (_comp.enableBatch) { - worldMat = _node.worldMatrix as Mat4; - _mustFlush = false; - _handleVal |= FLAG_BATCH; - } - if (comp.isAnimationCached()) { // Traverse input assembler. - cacheTraverse(worldMat); + cacheTraverse(); } else { if (_vertexEffect) _vertexEffect.begin(comp._skeleton); - realTimeTraverse(batcher, worldMat); + realTimeTraverse(batcher); if (_vertexEffect) _vertexEffect.end(); } // Ensure mesh buffer update @@ -454,7 +463,7 @@ function fillVertices (skeletonColor: spine.Color, } } -function realTimeTraverse (batcher: Batcher2D, worldMat?: Mat4) { +function realTimeTraverse (batcher: Batcher2D) { const rd = _renderData!; _vbuf = rd.chunk.vb; _ibuf = rd.indices!; @@ -637,21 +646,6 @@ function realTimeTraverse (batcher: Batcher2D, worldMat?: Mat4) { for (let ii = _indexOffset, nn = _indexOffset + _indexCount; ii < nn; ii++) { _ibuf[ii] += _vertexOffset + chunkOffset; } - - if (worldMat) { - _m00 = worldMat.m00; - _m04 = worldMat.m04; - _m12 = worldMat.m12; - _m01 = worldMat.m01; - _m05 = worldMat.m05; - _m13 = worldMat.m13; - for (let ii = _vertexFloatOffset, nn = _vertexFloatOffset + _vertexFloatCount; ii < nn; ii += _perVertexSize) { - _x = _vbuf[ii]; - _y = _vbuf[ii + 1]; - _vbuf[ii] = _x * _m00 + _y * _m04 + _m12; - _vbuf[ii + 1] = _x * _m01 + _y * _m05 + _m13; - } - } } _vertexFloatOffset += _vertexFloatCount; _vertexOffset += _vertexCount; @@ -694,7 +688,7 @@ function realTimeTraverse (batcher: Batcher2D, worldMat?: Mat4) { } } -function cacheTraverse (worldMat?: Mat4) { +function cacheTraverse () { const frame = _comp!._curFrame; if (!frame) return; @@ -715,18 +709,6 @@ function cacheTraverse (worldMat?: Mat4) { let frameVFOffset = 0; let frameIndexOffset = 0; let segVFCount = 0; - if (worldMat) { - _m00 = worldMat.m00; - _m01 = worldMat.m01; - _m04 = worldMat.m04; - _m05 = worldMat.m05; - _m12 = worldMat.m12; - _m13 = worldMat.m13; - } - - const justTranslate = _m00 === 1 && _m01 === 0 && _m04 === 0 && _m05 === 1; - const needBatch = (_handleVal & FLAG_BATCH); - const calcTranslate = needBatch && justTranslate; const colors = frame.colors; let colorOffset = 0; @@ -769,21 +751,6 @@ function cacheTraverse (worldMat?: Mat4) { segVFCount = segInfo.vfCount; vbuf.set(vertices.subarray(frameVFOffset, frameVFOffset + segVFCount), frameVFOffset); - // Update local position to world position - if (calcTranslate) { - for (let ii = frameVFOffset, il = frameVFOffset + segVFCount; ii < il; ii += _perVertexSize) { - vbuf[ii] += _m12; - vbuf[ii + 1] += _m13; - } - } else if (needBatch) { - for (let ii = frameVFOffset, il = frameVFOffset + segVFCount; ii < il; ii += _perVertexSize) { - _x = vbuf[ii]; - _y = vbuf[ii + 1]; - vbuf[ii] = _x * _m00 + _y * _m04 + _m12; - vbuf[ii + 1] = _x * _m01 + _y * _m05 + _m13; - } - } - // Update color if (_needColor) { // handle color diff --git a/cocos/spine/attach-util.ts b/cocos/spine/attach-util.ts index ef5a4445d4..22c215085e 100644 --- a/cocos/spine/attach-util.ts +++ b/cocos/spine/attach-util.ts @@ -1,9 +1,29 @@ -/** - * @packageDocumentation - * @module spine +/* + Copyright (c) 2020-2022 Xiamen Yaji Software Co., Ltd. + + https://www.cocos.com/ + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ -import { Mat4, Vec3, Node } from '../core'; +import { Mat4, Node } from '../core'; import { Skeleton } from './skeleton'; import spine from './lib/spine-core.js'; import { FrameBoneInfo } from './skeleton-cache'; diff --git a/cocos/spine/deprecated.ts b/cocos/spine/deprecated.ts new file mode 100644 index 0000000000..ab8bf92610 --- /dev/null +++ b/cocos/spine/deprecated.ts @@ -0,0 +1,34 @@ +/* + Copyright (c) 2020 Xiamen Yaji Software Co., Ltd. + + https://www.cocos.com/ + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + */ + +import { removeProperty } from '../core/utils/x-deprecated'; +import { Skeleton } from './skeleton'; + +removeProperty(Skeleton.prototype, 'Skeleton', [ + { + name: 'enableBatch', + suggest: 'Not support batch render mode', + }, +]); diff --git a/cocos/spine/index.jsb.ts b/cocos/spine/index.jsb.ts index 72cf3e9ce3..bf974f52ad 100644 --- a/cocos/spine/index.jsb.ts +++ b/cocos/spine/index.jsb.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module spine - */ - import { ccenum } from '../core'; import { legacyCC } from '../core/global-exports'; diff --git a/cocos/spine/index.ts b/cocos/spine/index.ts index 048f1455c8..bd25ed13d3 100644 --- a/cocos/spine/index.ts +++ b/cocos/spine/index.ts @@ -1,6 +1,26 @@ -/** - * @packageDocumentation - * @module spine +/* + Copyright (c) 2020-2022 Xiamen Yaji Software Co., Ltd. + + https://www.cocos.com/ + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ import { ccenum } from '../core'; @@ -29,19 +49,16 @@ export * from './skeleton-data'; export * from './skeleton-texture'; export * from './vertex-effect-delegate'; export * from './assembler'; +export * from './deprecated'; export { spine }; /** * @en - * The global time scale of Spine. + * The attachment type of spine. It contains three type: REGION(0), BOUNDING_BOX(1), MESH(2) and SKINNED_MESH * @zh - * Spine 全局时间缩放率。 - * @example - * sp.timeScale = 0.8; + * Attachment 类型枚举。类型包括 REGION,BOUNDING_BOX,MESH,SKINNED_MESH */ - -// The attachment type of spine. It contains three type: REGION(0), BOUNDING_BOX(1), MESH(2) and SKINNED_MESH. export enum ATTACHMENT_TYPE { REGION = 0, BOUNDING_BOX = 1, diff --git a/cocos/spine/skeleton-cache.ts b/cocos/spine/skeleton-cache.ts index e0089b3be0..525c332dc5 100644 --- a/cocos/spine/skeleton-cache.ts +++ b/cocos/spine/skeleton-cache.ts @@ -1,6 +1,26 @@ -/** - * @packageDocumentation - * @module spine +/* + Copyright (c) 2020-2022 Xiamen Yaji Software Co., Ltd. + + https://www.cocos.com/ + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ import { TrackEntryListeners } from './track-entry-listeners'; diff --git a/cocos/spine/skeleton-data.ts b/cocos/spine/skeleton-data.ts index 8b9862aa0d..664f77f6dc 100644 --- a/cocos/spine/skeleton-data.ts +++ b/cocos/spine/skeleton-data.ts @@ -1,6 +1,26 @@ -/** - * @packageDocumentation - * @module spine +/* + Copyright (c) 2020-2022 Xiamen Yaji Software Co., Ltd. + + https://www.cocos.com/ + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ import { EDITOR } from 'internal:constants'; @@ -21,6 +41,8 @@ import { legacyCC } from '../core/global-exports'; @ccclass('sp.SkeletonData') export class SkeletonData extends Asset { /** + * @en See http://en.esotericsoftware.com/spine-json-format + * @zh 可查看 Spine 官方文档 http://zh.esotericsoftware.com/spine-json-format * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. */ @serializable @@ -67,6 +89,8 @@ export class SkeletonData extends Asset { } /** + * @en Texture array + * @zh 纹理数组 * @property {Texture2D[]} textures */ diff --git a/cocos/spine/skeleton-system.ts b/cocos/spine/skeleton-system.ts index 9ca4ec82e4..68ba3c042b 100644 --- a/cocos/spine/skeleton-system.ts +++ b/cocos/spine/skeleton-system.ts @@ -1,7 +1,31 @@ +/* + Copyright (c) 2020-2022 Xiamen Yaji Software Co., Ltd. + + https://www.cocos.com/ + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + */ + import { director } from '../core/director'; import { System } from '../core/components'; import { Skeleton } from './skeleton'; -import { errorID } from '../core'; export class SkeletonSystem extends System { /** diff --git a/cocos/spine/skeleton-texture.ts b/cocos/spine/skeleton-texture.ts index fdd7bdcc99..e2e6e47361 100644 --- a/cocos/spine/skeleton-texture.ts +++ b/cocos/spine/skeleton-texture.ts @@ -1,6 +1,26 @@ -/** - * @packageDocumentation - * @module spine +/* + Copyright (c) 2020-2022 Xiamen Yaji Software Co., Ltd. + + https://www.cocos.com/ + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ import { Material, Texture2D } from '../core'; diff --git a/cocos/spine/skeleton.ts b/cocos/spine/skeleton.ts index cea6967d91..aa11c2a933 100644 --- a/cocos/spine/skeleton.ts +++ b/cocos/spine/skeleton.ts @@ -1,6 +1,26 @@ -/** - * @packageDocumentation - * @module spine +/* + Copyright (c) 2020-2022 Xiamen Yaji Software Co., Ltd. + + https://www.cocos.com/ + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ import { EDITOR } from 'internal:constants'; @@ -441,24 +461,6 @@ export class Skeleton extends UIRenderer { } get socketNodes () { return this._socketNodes; } - - /* - * @en Enabled batch model, if skeleton is complex, do not enable batch, or will lower performance. - * @zh 开启合批,如果渲染大量相同纹理,且结构简单的骨骼动画,开启合批可以降低drawcall,否则请不要开启,cpu消耗会上升。 - */ - // @tooltip('i18n:COMPONENT.skeleton.enabled_batch') - // get enableBatch () { return this._enableBatch; } - // set enableBatch (value) { - // if (value != this._enableBatch) { - // this._enableBatch = value; - // this._updateBatch(); - // } - // } - - // @serializable - // private _enableBatch: boolean = true; - - public enableBatch = false; // Frame cache /** * @internal @@ -574,8 +576,10 @@ export class Skeleton extends UIRenderer { // 由于 spine 的 skin 是无法二次替换的,所以只能设置默认的 skin /** - * @en The name of default skin. - * @zh 默认的皮肤名称。 + * @en + * The name of default skin. + * @zh + * 默认的皮肤名称。 * @property {String} defaultSkin */ @serializable @@ -583,8 +587,10 @@ export class Skeleton extends UIRenderer { protected defaultSkin = ''; /** - * @en The name of default animation. - * @zh 默认的动画名称。 + * @en + * The name of default animation. + * @zh + * 默认的动画名称。 * @property {String} defaultAnimation */ @visible(false) diff --git a/cocos/spine/track-entry-listeners.ts b/cocos/spine/track-entry-listeners.ts index c9bc4fdfec..c2af46bd42 100644 --- a/cocos/spine/track-entry-listeners.ts +++ b/cocos/spine/track-entry-listeners.ts @@ -1,6 +1,26 @@ -/** - * @packageDocumentation - * @module spine +/* + Copyright (c) 2020-2022 Xiamen Yaji Software Co., Ltd. + + https://www.cocos.com/ + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ import spine from './lib/spine-core.js'; diff --git a/cocos/spine/vertex-effect-delegate.ts b/cocos/spine/vertex-effect-delegate.ts index c1f38ee4c0..d642564fa7 100644 --- a/cocos/spine/vertex-effect-delegate.ts +++ b/cocos/spine/vertex-effect-delegate.ts @@ -1,6 +1,26 @@ -/** - * @packageDocumentation - * @module spine +/* + Copyright (c) 2020-2022 Xiamen Yaji Software Co., Ltd. + + https://www.cocos.com/ + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. */ import spine from './lib/spine-core.js'; diff --git a/cocos/terrain/height-field.ts b/cocos/terrain/height-field.ts index f232694a59..2f2176afb6 100644 --- a/cocos/terrain/height-field.ts +++ b/cocos/terrain/height-field.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module terrain - */ - import { clamp } from '../core/math'; export class HeightField { diff --git a/cocos/terrain/terrain-asset.ts b/cocos/terrain/terrain-asset.ts index 2407fb1846..d37cc1191a 100644 --- a/cocos/terrain/terrain-asset.ts +++ b/cocos/terrain/terrain-asset.ts @@ -23,13 +23,8 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module terrain - */ import { ccclass, serializable } from 'cc.decorator'; import { Asset, Texture2D } from '../core/assets'; -import { legacyCC } from '../core/global-exports'; export const TERRAIN_MAX_LEVELS = 4; export const TERRAIN_MAX_BLEND_LAYERS = 4; diff --git a/cocos/terrain/terrain.ts b/cocos/terrain/terrain.ts index e4bfb973df..cc217c894b 100644 --- a/cocos/terrain/terrain.ts +++ b/cocos/terrain/terrain.ts @@ -23,10 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module terrain - */ import { ccclass, disallowMultiple, executeInEditMode, help, visible, type, serializable, editable, disallowAnimation } from 'cc.decorator'; import { JSB } from 'internal:constants'; import { builtinResMgr } from '../core/builtin'; @@ -792,7 +788,7 @@ export class TerrainBlock { public _getMaterialDefines (nlayers: number): MacroRecord { return { LAYERS: nlayers + 1, - USE_LIGHTMAP: this.lightmap !== null ? 1 : 0, + CC_USE_LIGHTMAP: this.lightmap !== null ? 1 : 0, USE_NORMALMAP: this._terrain.useNormalMap ? 1 : 0, USE_PBR: this._terrain.usePBR ? 1 : 0, // CC_RECEIVE_SHADOW: this._terrain.receiveShadow ? 1 : 0, @@ -2209,7 +2205,7 @@ export class Terrain extends Component { } const terrainAsset = this.__asset; - if (this._buitinAsset != terrainAsset) { + if (this._buitinAsset !== terrainAsset) { this._buitinAsset = terrainAsset; } diff --git a/cocos/tiledmap/assembler/simple.ts b/cocos/tiledmap/assembler/simple.ts index 2334097516..571ace2dbc 100644 --- a/cocos/tiledmap/assembler/simple.ts +++ b/cocos/tiledmap/assembler/simple.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module ui-assembler - */ - import { Mat4, Size, Vec3 } from '../../core/math'; import { IAssembler } from '../../2d/renderer/base'; import { MeshRenderData } from '../../2d/renderer/render-data'; diff --git a/cocos/tiledmap/index.ts b/cocos/tiledmap/index.ts index 238caccfc5..9c4b8315d3 100644 --- a/cocos/tiledmap/index.ts +++ b/cocos/tiledmap/index.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module tiledmap - */ - export * from './tiled-map'; export * from './tiled-map-asset'; export * from './tiled-layer'; diff --git a/cocos/tiledmap/tiled-layer.ts b/cocos/tiledmap/tiled-layer.ts index cd5070401c..e41546ea7c 100644 --- a/cocos/tiledmap/tiled-layer.ts +++ b/cocos/tiledmap/tiled-layer.ts @@ -25,11 +25,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module tiledmap - */ - import { ccclass } from 'cc.decorator'; import { EDITOR } from 'internal:constants'; @@ -1441,6 +1436,10 @@ export class TiledLayer extends UIRenderer { } /** + * @en + * Index of mesh render data array + * @zh + * 网格渲染数据数组的索引 * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. */ public _meshRenderDataArrayIdx = 0; diff --git a/cocos/tiledmap/tiled-map-asset.ts b/cocos/tiledmap/tiled-map-asset.ts index 8cc4cb3aab..84f673a0db 100644 --- a/cocos/tiledmap/tiled-map-asset.ts +++ b/cocos/tiledmap/tiled-map-asset.ts @@ -24,17 +24,16 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module tiledmap - */ - import { ccclass, type, serializable } from 'cc.decorator'; import { Asset } from '../core/assets/asset'; import { CCString, Size, TextAsset } from '../core'; import { SpriteFrame } from '../2d/assets'; + /** + * @en * Class for tiled map asset handling. + * @zh + * 用于获取 tiled map 资源类 * @class TiledMapAsset * @extends Asset * @@ -53,13 +52,20 @@ export class TiledMapAsset extends Asset { tsxFileNames: string[] = []; /** - * @zh s + * @en + * SpriteFrame array + * @zh + * SpriteFrame 数组 */ @serializable @type([SpriteFrame]) spriteFrames: SpriteFrame[] = []; /** + * @en + * ImageLayerSpriteFrame array + * @zh + * ImageLayerSpriteFrame 数组 * @property {SpriteFrame[]} imageLayerSpriteFrame */ @serializable @@ -67,6 +73,10 @@ export class TiledMapAsset extends Asset { imageLayerSpriteFrame: SpriteFrame[] = [] /** + * @en + * Name of each object in imageLayerSpriteFrame + * @zh + * 每个 imageLayerSpriteFrame 名称 * @property {String[]} imageLayerTextureNames */ @serializable @@ -74,6 +84,10 @@ export class TiledMapAsset extends Asset { imageLayerSpriteFrameNames: string[] = []; /** + * @en + * Name of each object in spriteFrames + * @zh + * 每个 SpriteFrame 名称 * @property {String[]} spriteFrameNames */ @serializable @@ -81,6 +95,10 @@ export class TiledMapAsset extends Asset { spriteFrameNames: string[] = []; /** + * @en + * Size of each object in spriteFrames + * @zh + * 每个 SpriteFrame 的大小 * @property {Size[]} spriteFrameSizes */ @serializable diff --git a/cocos/tiledmap/tiled-map.ts b/cocos/tiledmap/tiled-map.ts index a49742c5dc..308c632d38 100644 --- a/cocos/tiledmap/tiled-map.ts +++ b/cocos/tiledmap/tiled-map.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module tiledmap - */ - import { ccclass, displayOrder, executeInEditMode, help, menu, requireComponent, type, serializable, editable } from 'cc.decorator'; import { EDITOR, JSB } from 'internal:constants'; import { Component } from '../core/components'; diff --git a/cocos/tiledmap/tiled-object-group.ts b/cocos/tiledmap/tiled-object-group.ts index a517b9583c..c4400cf52f 100644 --- a/cocos/tiledmap/tiled-object-group.ts +++ b/cocos/tiledmap/tiled-object-group.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module tiledmap - */ - import { ccclass, help, type, requireComponent } from 'cc.decorator'; import { Component } from '../core/components'; import { Sprite } from '../2d/components/sprite'; diff --git a/cocos/tiledmap/tiled-tile.ts b/cocos/tiledmap/tiled-tile.ts index 97ee500181..b15b399b02 100644 --- a/cocos/tiledmap/tiled-tile.ts +++ b/cocos/tiledmap/tiled-tile.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module tiledmap - */ - /** * @en TiledTile can control the specified map tile. * It will apply the node rotation, scale, translate to the map tile. diff --git a/cocos/tiledmap/tiled-types.ts b/cocos/tiledmap/tiled-types.ts index ec42f45690..4fee9256f3 100644 --- a/cocos/tiledmap/tiled-types.ts +++ b/cocos/tiledmap/tiled-types.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module tiledmap - */ - import { Color, Rect, Size, Texture2D, Vec2 } from '../core'; import { SpriteFrame } from '../2d/assets'; import { ccenum } from '../core/value-types/enum'; diff --git a/cocos/tiledmap/tiled-utils.ts b/cocos/tiledmap/tiled-utils.ts index 38b0378731..0522b1dd32 100644 --- a/cocos/tiledmap/tiled-utils.ts +++ b/cocos/tiledmap/tiled-utils.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module tiledmap - */ - import { SpriteFrame } from '../2d/assets'; import { Rect, Texture2D } from '../core'; import { GID, TiledGrid, TiledTextureGrids, TMXTilesetInfo } from './tiled-types'; diff --git a/cocos/tiledmap/tmx-xml-parser.ts b/cocos/tiledmap/tmx-xml-parser.ts index d125701f74..c4de98b48a 100644 --- a/cocos/tiledmap/tmx-xml-parser.ts +++ b/cocos/tiledmap/tmx-xml-parser.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module tiledmap - */ - import { Label, HorizontalTextAlignment, VerticalTextAlignment } from '../2d/components/label'; import codec from '../../external/compression/ZipUtils.js'; import zlib from '../../external/compression/zlib.min.js'; diff --git a/cocos/tween/actions/action-interval.ts b/cocos/tween/actions/action-interval.ts index bda182cf95..7ff1598cd1 100644 --- a/cocos/tween/actions/action-interval.ts +++ b/cocos/tween/actions/action-interval.ts @@ -222,7 +222,10 @@ export class ActionInterval extends FiniteTimeAction { } /** + * @en * Get this action speed. + * @zh + * 返回此动作速度 * @return {Number} */ getSpeed (): number { @@ -230,7 +233,10 @@ export class ActionInterval extends FiniteTimeAction { } /** + * @en * Set this action speed. + * @zh + * 设置此动作速度 * @param {Number} speed * @returns {ActionInterval} */ diff --git a/cocos/tween/export-api.ts b/cocos/tween/export-api.ts index e08dbd1e4a..cefff2361c 100644 --- a/cocos/tween/export-api.ts +++ b/cocos/tween/export-api.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module tween - */ - /** * @en * Built-in string value definition for the cache function. diff --git a/cocos/tween/tween-system.ts b/cocos/tween/tween-system.ts index 2acb285156..04155b1aa7 100644 --- a/cocos/tween/tween-system.ts +++ b/cocos/tween/tween-system.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module tween - */ - import { EDITOR } from 'internal:constants'; import { System, Director, director } from '../core'; import { ActionManager } from './actions/action-manager'; diff --git a/cocos/tween/tween.ts b/cocos/tween/tween.ts index 3068b2980b..03353a2f4d 100644 --- a/cocos/tween/tween.ts +++ b/cocos/tween/tween.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module tween - */ - import { TweenSystem } from './tween-system'; import { warn } from '../core'; import { ActionInterval, sequence, repeat, repeatForever, reverseTime, delayTime, spawn } from './actions/action-interval'; diff --git a/cocos/ui/block-input-events.ts b/cocos/ui/block-input-events.ts index f9b4fd751b..1450772f11 100644 --- a/cocos/ui/block-input-events.ts +++ b/cocos/ui/block-input-events.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module event - */ - import { ccclass, help, menu } from 'cc.decorator'; import { Component } from '../core/components/component'; import { Event } from '../input/types'; diff --git a/cocos/ui/button.ts b/cocos/ui/button.ts index 2a926cf31d..e03c808ed3 100644 --- a/cocos/ui/button.ts +++ b/cocos/ui/button.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module ui - */ - import { ccclass, help, executionOrder, menu, requireComponent, tooltip, displayOrder, type, rangeMin, rangeMax, serializable, executeInEditMode } from 'cc.decorator'; import { EDITOR } from 'internal:constants'; import { SpriteFrame } from '../2d/assets'; diff --git a/cocos/ui/deprecated.ts b/cocos/ui/deprecated.ts index f0b87d59cd..aa764a7a93 100644 --- a/cocos/ui/deprecated.ts +++ b/cocos/ui/deprecated.ts @@ -23,10 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module ui - */ import { UICoordinateTracker } from './ui-coordinate-tracker'; import { BlockInputEvents } from './block-input-events'; import { Button } from './button'; diff --git a/cocos/ui/editbox/edit-box.ts b/cocos/ui/editbox/edit-box.ts index 8ee3b82a2f..884340feaa 100644 --- a/cocos/ui/editbox/edit-box.ts +++ b/cocos/ui/editbox/edit-box.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module ui - */ - import { ccclass, help, executeInEditMode, executionOrder, menu, requireComponent, tooltip, displayOrder, type, serializable } from 'cc.decorator'; import { EDITOR, JSB, MINIGAME, RUNTIME_BASED } from 'internal:constants'; import { UITransform } from '../../2d/framework'; diff --git a/cocos/ui/layout.ts b/cocos/ui/layout.ts index 77c882539e..e7464c24f3 100644 --- a/cocos/ui/layout.ts +++ b/cocos/ui/layout.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module ui - */ - import { ccclass, help, executeInEditMode, executionOrder, menu, requireComponent, tooltip, type, displayOrder, serializable, visible, displayName } from 'cc.decorator'; import { Component } from '../core/components/component'; import { Rect, Size, Vec2, Vec3 } from '../core/math'; diff --git a/cocos/ui/page-view-indicator.ts b/cocos/ui/page-view-indicator.ts index dad6ca8894..e74563be3f 100644 --- a/cocos/ui/page-view-indicator.ts +++ b/cocos/ui/page-view-indicator.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module ui - */ - import { ccclass, help, executionOrder, menu, tooltip, type, serializable } from 'cc.decorator'; import { SpriteFrame } from '../2d/assets'; import { Component } from '../core/components'; diff --git a/cocos/ui/page-view.ts b/cocos/ui/page-view.ts index a99a74ada8..982db58a20 100644 --- a/cocos/ui/page-view.ts +++ b/cocos/ui/page-view.ts @@ -23,10 +23,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/** - * @packageDocumentation - * @module ui - */ import { ccclass, help, executionOrder, menu, tooltip, type, slide, range, visible, override, serializable, editable } from 'cc.decorator'; import { EDITOR } from 'internal:constants'; diff --git a/cocos/ui/progress-bar.ts b/cocos/ui/progress-bar.ts index ef330d5b6d..fb2735a993 100644 --- a/cocos/ui/progress-bar.ts +++ b/cocos/ui/progress-bar.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module ui - */ - import { ccclass, help, executionOrder, menu, requireComponent, tooltip, type, range, slide, serializable } from 'cc.decorator'; import { Component } from '../core/components/component'; import { UITransform } from '../2d/framework'; diff --git a/cocos/ui/safe-area.ts b/cocos/ui/safe-area.ts index 200ecb4f5a..5a1d6e51e2 100644 --- a/cocos/ui/safe-area.ts +++ b/cocos/ui/safe-area.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module ui - */ - import { ccclass, help, executionOrder, menu, executeInEditMode, requireComponent } from 'cc.decorator'; import { EDITOR } from 'internal:constants'; import { screenAdapter } from 'pal/screen-adapter'; diff --git a/cocos/ui/scroll-bar.ts b/cocos/ui/scroll-bar.ts index c9cf59ad17..9aa8c84485 100644 --- a/cocos/ui/scroll-bar.ts +++ b/cocos/ui/scroll-bar.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module ui - */ - import { ccclass, help, executionOrder, menu, requireComponent, tooltip, displayOrder, type, serializable } from 'cc.decorator'; import { Component } from '../core/components/component'; import { UITransform } from '../2d/framework'; diff --git a/cocos/ui/scroll-view.ts b/cocos/ui/scroll-view.ts index d2f5e88733..9b0d0a6bd4 100644 --- a/cocos/ui/scroll-view.ts +++ b/cocos/ui/scroll-view.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module ui - */ - import { ccclass, help, executionOrder, menu, requireComponent, tooltip, displayOrder, range, type, serializable } from 'cc.decorator'; import { EDITOR } from 'internal:constants'; import { EventHandler as ComponentEventHandler } from '../core/components/component-event-handler'; diff --git a/cocos/ui/slider.ts b/cocos/ui/slider.ts index f6ee21d7f4..81c9c801a7 100644 --- a/cocos/ui/slider.ts +++ b/cocos/ui/slider.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module ui - */ - import { ccclass, help, executionOrder, menu, requireComponent, tooltip, type, slide, range, serializable } from 'cc.decorator'; import { EDITOR } from 'internal:constants'; import { Component, EventHandler } from '../core/components'; diff --git a/cocos/ui/sub-context-view.ts b/cocos/ui/sub-context-view.ts index 295066eac0..eb1083ec21 100644 --- a/cocos/ui/sub-context-view.ts +++ b/cocos/ui/sub-context-view.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module component - */ - import { ccclass, help, menu, executionOrder, requireComponent, tooltip, serializable } from 'cc.decorator'; import { EDITOR, WECHAT } from 'internal:constants'; import { minigame } from 'pal/minigame'; @@ -171,7 +166,7 @@ export class SubContextView extends Component { } } sharedCanvas.width = designWidth; - sharedCanvas.height = designWidth; + sharedCanvas.height = designHeight; } } diff --git a/cocos/ui/toggle-container.ts b/cocos/ui/toggle-container.ts index fb80222f8f..00e35f73e7 100644 --- a/cocos/ui/toggle-container.ts +++ b/cocos/ui/toggle-container.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module ui - */ - import { ccclass, help, executeInEditMode, executionOrder, menu, tooltip, type, serializable } from 'cc.decorator'; import { Component, EventHandler as ComponentEventHandler } from '../core/components'; import { Toggle } from './toggle'; diff --git a/cocos/ui/toggle.ts b/cocos/ui/toggle.ts index 4a0507690d..f19bbb615e 100644 --- a/cocos/ui/toggle.ts +++ b/cocos/ui/toggle.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module ui - */ - import { ccclass, help, requireComponent, executionOrder, menu, tooltip, displayOrder, type, serializable } from 'cc.decorator'; import { EDITOR } from 'internal:constants'; import { EventHandler as ComponentEventHandler } from '../core/components/component-event-handler'; diff --git a/cocos/ui/ui-coordinate-tracker.ts b/cocos/ui/ui-coordinate-tracker.ts index d2fded3bb8..c52aabf8c7 100644 --- a/cocos/ui/ui-coordinate-tracker.ts +++ b/cocos/ui/ui-coordinate-tracker.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module component - */ - import { ccclass, help, menu, executionOrder, tooltip, type, serializable } from 'cc.decorator'; import { Component } from '../core/components/component'; import { EventHandler } from '../core/components/component-event-handler'; diff --git a/cocos/ui/view-group.ts b/cocos/ui/view-group.ts index 4d29937e82..6e0c86e8c6 100644 --- a/cocos/ui/view-group.ts +++ b/cocos/ui/view-group.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module ui - */ - /** * @en * Handling touch events in a ViewGroup takes special care, diff --git a/cocos/ui/widget.ts b/cocos/ui/widget.ts index 57555e0fe4..8731a549f4 100644 --- a/cocos/ui/widget.ts +++ b/cocos/ui/widget.ts @@ -24,11 +24,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module ui - */ - import { ccclass, help, executeInEditMode, executionOrder, menu, requireComponent, tooltip, type, editorOnly, editable, serializable, visible } from 'cc.decorator'; import { EDITOR, DEV } from 'internal:constants'; import { Component } from '../core/components'; diff --git a/cocos/video/assets/video-clip.ts b/cocos/video/assets/video-clip.ts index e45b4d0dbb..2fb407cab0 100644 --- a/cocos/video/assets/video-clip.ts +++ b/cocos/video/assets/video-clip.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module component/video - */ - import { ccclass, serializable } from 'cc.decorator'; import { Asset } from '../../core/assets'; diff --git a/cocos/video/video-downloader.ts b/cocos/video/video-downloader.ts index 3b71887f67..8a838cdd70 100644 --- a/cocos/video/video-downloader.ts +++ b/cocos/video/video-downloader.ts @@ -23,10 +23,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/** - * @packageDocumentation - * @module asset-manager - */ import downloader from '../core/asset-manager/downloader'; import factory from '../core/asset-manager/factory'; diff --git a/cocos/video/video-player-enums.ts b/cocos/video/video-player-enums.ts index c78636c3c8..c4e1065327 100644 --- a/cocos/video/video-player-enums.ts +++ b/cocos/video/video-player-enums.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module component/video - */ - /** * @en Enum for video resource type. * @zh 视频来源 diff --git a/cocos/video/video-player-impl-manager.ts b/cocos/video/video-player-impl-manager.ts index 3379916b91..4a1e653d86 100644 --- a/cocos/video/video-player-impl-manager.ts +++ b/cocos/video/video-player-impl-manager.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module component/video - */ - import { legacyCC } from '../core/global-exports'; import { VideoPlayer } from './video-player'; import { VideoPlayerImplWeb } from './video-player-impl-web'; diff --git a/cocos/video/video-player-impl-web.ts b/cocos/video/video-player-impl-web.ts index e65f3411f2..f2de1f58ff 100644 --- a/cocos/video/video-player-impl-web.ts +++ b/cocos/video/video-player-impl-web.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module component/video - */ - import { screenAdapter } from 'pal/screen-adapter'; import { mat4 } from '../core/math'; import { sys, screen, warn } from '../core/platform'; diff --git a/cocos/video/video-player-impl.ts b/cocos/video/video-player-impl.ts index 909e798dbe..dc9f11bfc0 100644 --- a/cocos/video/video-player-impl.ts +++ b/cocos/video/video-player-impl.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module component/video - */ - import { legacyCC } from '../core/global-exports'; import { UITransform } from '../2d/framework'; import { VideoPlayer } from './video-player'; diff --git a/cocos/video/video-player.ts b/cocos/video/video-player.ts index 1df5bf06c5..e043989146 100644 --- a/cocos/video/video-player.ts +++ b/cocos/video/video-player.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module component/video - */ - import { ccclass, displayOrder, executeInEditMode, help, menu, slide, range, requireComponent, tooltip, type, serializable } from 'cc.decorator'; import { EDITOR } from 'internal:constants'; import { warn } from '../core/platform'; diff --git a/cocos/web-view/web-view-enums.ts b/cocos/web-view/web-view-enums.ts index 27e554c61d..7996f3e80e 100644 --- a/cocos/web-view/web-view-enums.ts +++ b/cocos/web-view/web-view-enums.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module component/web-view - */ - export enum EventType { /** * @en None diff --git a/cocos/web-view/web-view-impl-manager.ts b/cocos/web-view/web-view-impl-manager.ts index a781745d23..0b9ddf3b02 100644 --- a/cocos/web-view/web-view-impl-manager.ts +++ b/cocos/web-view/web-view-impl-manager.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module component/web-view - */ - import { legacyCC } from '../core/global-exports'; import { WebViewImplWeb } from './web-view-impl-web'; diff --git a/cocos/web-view/web-view-impl-web.ts b/cocos/web-view/web-view-impl-web.ts index da15d356e0..06e48edf95 100644 --- a/cocos/web-view/web-view-impl-web.ts +++ b/cocos/web-view/web-view-impl-web.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module component/web-view - */ - import { screenAdapter } from 'pal/screen-adapter'; import { EventType } from './web-view-enums'; import { error, warn } from '../core/platform'; diff --git a/cocos/web-view/web-view-impl.ts b/cocos/web-view/web-view-impl.ts index 6135c173f2..64ee646003 100644 --- a/cocos/web-view/web-view-impl.ts +++ b/cocos/web-view/web-view-impl.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module component/web-view - */ - import { legacyCC } from '../core/global-exports'; import { WebView } from './web-view'; import { EventType } from './web-view-enums'; diff --git a/cocos/web-view/web-view.ts b/cocos/web-view/web-view.ts index 48b9616dbb..317ae25d49 100644 --- a/cocos/web-view/web-view.ts +++ b/cocos/web-view/web-view.ts @@ -23,11 +23,6 @@ THE SOFTWARE. */ -/** - * @packageDocumentation - * @module component/web-view - */ - import { ccclass, help, executeInEditMode, menu, tooltip, type, displayOrder, serializable, requireComponent } from 'cc.decorator'; import { EDITOR } from 'internal:constants'; import { UITransform } from '../2d/framework'; diff --git a/editor/assets/chunks/aces.chunk.meta b/editor/assets/chunks/aces.chunk.meta index eab88b41f8..0fee3c2f52 100644 --- a/editor/assets/chunks/aces.chunk.meta +++ b/editor/assets/chunks/aces.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "7efbe295-0202-4979-8cda-6cfe35e086cf", diff --git a/editor/assets/chunks/alpha-test.chunk.meta b/editor/assets/chunks/alpha-test.chunk.meta index 407ebeb0ca..c0aa3f5e17 100644 --- a/editor/assets/chunks/alpha-test.chunk.meta +++ b/editor/assets/chunks/alpha-test.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "2c3da5b6-0202-470a-a915-59f1e2968853", diff --git a/editor/assets/chunks/anti-aliasing.chunk.meta b/editor/assets/chunks/anti-aliasing.chunk.meta index 0451e74d58..a350a012a5 100644 --- a/editor/assets/chunks/anti-aliasing.chunk.meta +++ b/editor/assets/chunks/anti-aliasing.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "60bb7684-4cd7-4d19-96c4-262e12e0b025", diff --git a/editor/assets/chunks/builtin.meta b/editor/assets/chunks/builtin.meta new file mode 100644 index 0000000000..e011724c9b --- /dev/null +++ b/editor/assets/chunks/builtin.meta @@ -0,0 +1,12 @@ +{ + "ver": "1.1.0", + "importer": "directory", + "imported": true, + "uuid": "85f366b2-d149-4b14-aa1d-4634e3c28f69", + "files": [], + "subMetas": {}, + "userData": { + "compressionType": {}, + "isRemoteBundle": {} + } +} diff --git a/editor/assets/chunks/builtin/internal-functions.meta b/editor/assets/chunks/builtin/internal-functions.meta new file mode 100644 index 0000000000..fa8ad05d78 --- /dev/null +++ b/editor/assets/chunks/builtin/internal-functions.meta @@ -0,0 +1,12 @@ +{ + "ver": "1.1.0", + "importer": "directory", + "imported": true, + "uuid": "784eb20c-c955-4a9b-a320-571a5c392f79", + "files": [], + "subMetas": {}, + "userData": { + "compressionType": {}, + "isRemoteBundle": {} + } +} diff --git a/editor/assets/chunks/builtin/internal-functions/morph-animation.chunk b/editor/assets/chunks/builtin/internal-functions/morph-animation.chunk new file mode 100644 index 0000000000..a746bc41c0 --- /dev/null +++ b/editor/assets/chunks/builtin/internal-functions/morph-animation.chunk @@ -0,0 +1,113 @@ + +/** + * 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 +} diff --git a/editor/assets/chunks/builtin/internal-functions/morph-animation.chunk.meta b/editor/assets/chunks/builtin/internal-functions/morph-animation.chunk.meta new file mode 100644 index 0000000000..ac34f9abec --- /dev/null +++ b/editor/assets/chunks/builtin/internal-functions/morph-animation.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "3adaa06a-e674-487c-9d49-42bc398c255b", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/builtin/internal-functions/skinning-animation-dqs.chunk b/editor/assets/chunks/builtin/internal-functions/skinning-animation-dqs.chunk new file mode 100644 index 0000000000..97c9cee2f3 --- /dev/null +++ b/editor/assets/chunks/builtin/internal-functions/skinning-animation-dqs.chunk @@ -0,0 +1,75 @@ +// Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd. + +#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 + 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 + +// [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); +} diff --git a/editor/assets/chunks/builtin/internal-functions/skinning-animation-dqs.chunk.meta b/editor/assets/chunks/builtin/internal-functions/skinning-animation-dqs.chunk.meta new file mode 100644 index 0000000000..16475f8977 --- /dev/null +++ b/editor/assets/chunks/builtin/internal-functions/skinning-animation-dqs.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "80908463-4566-4fdf-9744-775605cd7ab7", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/builtin/internal-functions/skinning-animation-lbs.chunk b/editor/assets/chunks/builtin/internal-functions/skinning-animation-lbs.chunk new file mode 100644 index 0000000000..f0bcdeff4e --- /dev/null +++ b/editor/assets/chunks/builtin/internal-functions/skinning-animation-lbs.chunk @@ -0,0 +1,66 @@ +// Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd. + +#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 + 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 + +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; +} diff --git a/editor/assets/chunks/builtin/internal-functions/skinning-animation-lbs.chunk.meta b/editor/assets/chunks/builtin/internal-functions/skinning-animation-lbs.chunk.meta new file mode 100644 index 0000000000..81bf7555b7 --- /dev/null +++ b/editor/assets/chunks/builtin/internal-functions/skinning-animation-lbs.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "258a17ce-6c50-4e8a-92aa-8ecec1a6af24", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/builtin/internal-functions/world-transform.chunk b/editor/assets/chunks/builtin/internal-functions/world-transform.chunk new file mode 100644 index 0000000000..d40db41925 --- /dev/null +++ b/editor/assets/chunks/builtin/internal-functions/world-transform.chunk @@ -0,0 +1,36 @@ +// Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd. + +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) + ); + #elif USE_BATCHING + matWorld = cc_matWorlds[int(a_dyn_batch_id)]; + #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) + ); + matWorldIT = matWorld; + #elif USE_BATCHING + matWorld = cc_matWorlds[int(a_dyn_batch_id)]; + matWorldIT = matWorld; + #else + matWorld = cc_matWorld; + matWorldIT = cc_matWorldIT; + #endif +} diff --git a/editor/assets/chunks/builtin/internal-functions/world-transform.chunk.meta b/editor/assets/chunks/builtin/internal-functions/world-transform.chunk.meta new file mode 100644 index 0000000000..3afa4fb202 --- /dev/null +++ b/editor/assets/chunks/builtin/internal-functions/world-transform.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "c2885f54-4ff2-4284-8bbc-b77bc71965b4", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/builtin/uniforms.meta b/editor/assets/chunks/builtin/uniforms.meta new file mode 100644 index 0000000000..3966a7bbd4 --- /dev/null +++ b/editor/assets/chunks/builtin/uniforms.meta @@ -0,0 +1,12 @@ +{ + "ver": "1.1.0", + "importer": "directory", + "imported": true, + "uuid": "d81f2dfc-d5a9-49b9-a4ce-84a3cec1707a", + "files": [], + "subMetas": {}, + "userData": { + "compressionType": {}, + "isRemoteBundle": {} + } +} diff --git a/editor/assets/chunks/builtin/uniforms/cc-local-batched.chunk b/editor/assets/chunks/builtin/uniforms/cc-local-batched.chunk new file mode 100644 index 0000000000..853996d554 --- /dev/null +++ b/editor/assets/chunks/builtin/uniforms/cc-local-batched.chunk @@ -0,0 +1,13 @@ +// Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd. + +#if !USE_INSTANCING + #if USE_BATCHING + #pragma define BATCHING_COUNT 10 + #pragma builtin(local) + layout(set = 2, binding = 0) uniform CCLocalBatched { + highp mat4 cc_matWorlds[BATCHING_COUNT]; + }; + #else + #include + #endif +#endif diff --git a/editor/assets/chunks/builtin/uniforms/cc-local-batched.chunk.meta b/editor/assets/chunks/builtin/uniforms/cc-local-batched.chunk.meta new file mode 100644 index 0000000000..746ef79799 --- /dev/null +++ b/editor/assets/chunks/builtin/uniforms/cc-local-batched.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "21b24bc9-a158-488e-b27c-b98a461fb438", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/builtin/uniforms/cc-morph.chunk b/editor/assets/chunks/builtin/uniforms/cc-morph.chunk new file mode 100644 index 0000000000..6f0e769158 --- /dev/null +++ b/editor/assets/chunks/builtin/uniforms/cc-morph.chunk @@ -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 = 7) uniform sampler2D cc_PositionDisplacements; +#endif + +#if CC_MORPH_TARGET_HAS_NORMAL + #pragma builtin(local) + layout(set = 2, binding = 8) uniform sampler2D cc_NormalDisplacements; +#endif + +#if CC_MORPH_TARGET_HAS_TANGENT + #pragma builtin(local) + layout(set = 2, binding = 9) uniform sampler2D cc_TangentDisplacements; +#endif diff --git a/editor/assets/chunks/builtin/uniforms/cc-morph.chunk.meta b/editor/assets/chunks/builtin/uniforms/cc-morph.chunk.meta new file mode 100644 index 0000000000..750cb199d5 --- /dev/null +++ b/editor/assets/chunks/builtin/uniforms/cc-morph.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "94d19070-32c6-4900-a288-2258fda37f29", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/builtin/uniforms/cc-skinning-uniforms.chunk b/editor/assets/chunks/builtin/uniforms/cc-skinning-uniforms.chunk new file mode 100644 index 0000000000..1849e1ca6b --- /dev/null +++ b/editor/assets/chunks/builtin/uniforms/cc-skinning-uniforms.chunk @@ -0,0 +1,39 @@ +// 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 = 6) 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 + #pragma define JOINT_UNIFORM_CAPACITY 30 + #pragma builtin(local) + layout(set = 2, binding = 3) uniform CCSkinning { + highp vec4 cc_joints[JOINT_UNIFORM_CAPACITY * 3]; + }; +#endif diff --git a/editor/assets/chunks/builtin/uniforms/cc-skinning-uniforms.chunk.meta b/editor/assets/chunks/builtin/uniforms/cc-skinning-uniforms.chunk.meta new file mode 100644 index 0000000000..41438c9433 --- /dev/null +++ b/editor/assets/chunks/builtin/uniforms/cc-skinning-uniforms.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "99488fd6-220b-4d13-9a41-8b9439cd3944", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/cc-diffusemap.chunk.meta b/editor/assets/chunks/cc-diffusemap.chunk.meta index d2647ee43d..cd37967666 100644 --- a/editor/assets/chunks/cc-diffusemap.chunk.meta +++ b/editor/assets/chunks/cc-diffusemap.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "17e8e047-4c5e-412c-85c8-a76a98742f2a", diff --git a/editor/assets/chunks/cc-environment.chunk.meta b/editor/assets/chunks/cc-environment.chunk.meta index 418145bc0e..16fb615ec8 100644 --- a/editor/assets/chunks/cc-environment.chunk.meta +++ b/editor/assets/chunks/cc-environment.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "cd94308c-6959-4671-9dcb-6c58342273e2", diff --git a/editor/assets/chunks/cc-fog-base.chunk.meta b/editor/assets/chunks/cc-fog-base.chunk.meta index 88284d366a..674bf54934 100644 --- a/editor/assets/chunks/cc-fog-base.chunk.meta +++ b/editor/assets/chunks/cc-fog-base.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "879b9f55-e5da-4d8f-bc84-3a12a20533ad", diff --git a/editor/assets/chunks/cc-fog-fs.chunk.meta b/editor/assets/chunks/cc-fog-fs.chunk.meta index 7850128658..03f75a9074 100644 --- a/editor/assets/chunks/cc-fog-fs.chunk.meta +++ b/editor/assets/chunks/cc-fog-fs.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "5915ee07-9b06-4383-9b98-5b292bd116e9", diff --git a/editor/assets/chunks/cc-fog-vs.chunk.meta b/editor/assets/chunks/cc-fog-vs.chunk.meta index b7d58f30ef..f2fb871498 100644 --- a/editor/assets/chunks/cc-fog-vs.chunk.meta +++ b/editor/assets/chunks/cc-fog-vs.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "0bc1a9f5-9282-4192-a0d4-4818568f2b16", diff --git a/editor/assets/chunks/cc-forward-light.chunk.meta b/editor/assets/chunks/cc-forward-light.chunk.meta index fd9a56f06b..c60d4496e1 100644 --- a/editor/assets/chunks/cc-forward-light.chunk.meta +++ b/editor/assets/chunks/cc-forward-light.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "5e0f5e6e-5008-497f-b223-4e5f1801d8fd", diff --git a/editor/assets/chunks/cc-global.chunk.meta b/editor/assets/chunks/cc-global.chunk.meta index 00fc115831..0191017c7c 100644 --- a/editor/assets/chunks/cc-global.chunk.meta +++ b/editor/assets/chunks/cc-global.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "1ea907a3-a36e-432a-ae38-af712c77aaad", diff --git a/editor/assets/chunks/cc-local-batch.chunk.meta b/editor/assets/chunks/cc-local-batch.chunk.meta index 540a58a09c..ac84ea9ad1 100644 --- a/editor/assets/chunks/cc-local-batch.chunk.meta +++ b/editor/assets/chunks/cc-local-batch.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "21fbcb1c-648e-4700-b854-2a267fe50933", diff --git a/editor/assets/chunks/cc-local.chunk.meta b/editor/assets/chunks/cc-local.chunk.meta index 327706e160..929dad2669 100644 --- a/editor/assets/chunks/cc-local.chunk.meta +++ b/editor/assets/chunks/cc-local.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "e835c2d5-a377-4197-bdb8-382037573494", diff --git a/editor/assets/chunks/cc-shadow-map-base.chunk.meta b/editor/assets/chunks/cc-shadow-map-base.chunk.meta index ebcd528fb3..59cc2975b3 100644 --- a/editor/assets/chunks/cc-shadow-map-base.chunk.meta +++ b/editor/assets/chunks/cc-shadow-map-base.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "9b0e2f60-4c29-47e6-9b4c-ced160a61be6", diff --git a/editor/assets/chunks/cc-shadow-map-fs.chunk.meta b/editor/assets/chunks/cc-shadow-map-fs.chunk.meta index 73af35bdd5..cf73ffc551 100644 --- a/editor/assets/chunks/cc-shadow-map-fs.chunk.meta +++ b/editor/assets/chunks/cc-shadow-map-fs.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "5716d893-2ecc-4110-9291-88b7e939d37d", diff --git a/editor/assets/chunks/cc-shadow-map-vs.chunk.meta b/editor/assets/chunks/cc-shadow-map-vs.chunk.meta index 3c7b935b72..1a2f4ad7c2 100644 --- a/editor/assets/chunks/cc-shadow-map-vs.chunk.meta +++ b/editor/assets/chunks/cc-shadow-map-vs.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "b2e7c003-9c9f-40ee-82c6-32d920a759e8", diff --git a/editor/assets/chunks/cc-shadow.chunk.meta b/editor/assets/chunks/cc-shadow.chunk.meta index 96a083c2b0..848583ce68 100644 --- a/editor/assets/chunks/cc-shadow.chunk.meta +++ b/editor/assets/chunks/cc-shadow.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "69f8ecd8-cdc9-4655-a6ec-d39dacdffc2f", diff --git a/editor/assets/chunks/cc-skinning.chunk.meta b/editor/assets/chunks/cc-skinning.chunk.meta index 66e1f29d6b..e59a9d16b5 100644 --- a/editor/assets/chunks/cc-skinning.chunk.meta +++ b/editor/assets/chunks/cc-skinning.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "21191d65-d2ba-47a3-b9d2-c4afaaa713cd", diff --git a/editor/assets/chunks/cc-sprite-common.chunk.meta b/editor/assets/chunks/cc-sprite-common.chunk.meta index 980fe0321d..d39c415e5a 100644 --- a/editor/assets/chunks/cc-sprite-common.chunk.meta +++ b/editor/assets/chunks/cc-sprite-common.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "35822e78-bb35-405f-87bd-d42af6ac9ede", diff --git a/editor/assets/chunks/cc-sprite-texture.chunk.meta b/editor/assets/chunks/cc-sprite-texture.chunk.meta index a844493118..399988de38 100644 --- a/editor/assets/chunks/cc-sprite-texture.chunk.meta +++ b/editor/assets/chunks/cc-sprite-texture.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "4b48672e-e044-4035-9029-13afb50c1aee", diff --git a/editor/assets/chunks/cc-world-bound.chunk.meta b/editor/assets/chunks/cc-world-bound.chunk.meta index 32a114f8ff..72f5dda51a 100644 --- a/editor/assets/chunks/cc-world-bound.chunk.meta +++ b/editor/assets/chunks/cc-world-bound.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "669458fe-c428-40cd-8575-51607aa8edbc", diff --git a/editor/assets/chunks/common.chunk.meta b/editor/assets/chunks/common.chunk.meta index e106796444..927dfe490f 100644 --- a/editor/assets/chunks/common.chunk.meta +++ b/editor/assets/chunks/common.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "9d86a3e4-ec06-4e51-ba68-45f2b7739fbb", diff --git a/editor/assets/chunks/common.meta b/editor/assets/chunks/common.meta new file mode 100644 index 0000000000..02948fb6ba --- /dev/null +++ b/editor/assets/chunks/common.meta @@ -0,0 +1,12 @@ +{ + "ver": "1.1.0", + "importer": "directory", + "imported": true, + "uuid": "5dce7e3d-7c28-4f47-974c-e6904aeada37", + "files": [], + "subMetas": {}, + "userData": { + "compressionType": {}, + "isRemoteBundle": {} + } +} diff --git a/editor/assets/chunks/common/debug.meta b/editor/assets/chunks/common/debug.meta new file mode 100644 index 0000000000..3bbe82131b --- /dev/null +++ b/editor/assets/chunks/common/debug.meta @@ -0,0 +1,12 @@ +{ + "ver": "1.1.0", + "importer": "directory", + "imported": true, + "uuid": "a1b68389-649a-4208-9453-85db77a65771", + "files": [], + "subMetas": {}, + "userData": { + "compressionType": {}, + "isRemoteBundle": {} + } +} diff --git a/editor/assets/chunks/common/debug/debug-view-define.chunk b/editor/assets/chunks/common/debug/debug-view-define.chunk new file mode 100644 index 0000000000..719617e9f0 --- /dev/null +++ b/editor/assets/chunks/common/debug/debug-view-define.chunk @@ -0,0 +1,147 @@ +// 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 + +// lighting data +#define CC_SURFACES_DEBUG_VIEW_DIRECT_DIFFUSE CC_SURFACES_DEBUG_VIEW_SPECULAR_INTENSITY + 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 + +#define CC_SURFACES_DEBUG_VIEW_FOG CC_SURFACES_DEBUG_VIEW_AO + 1 + +// composite sign: base lighting functionality, all switches on == non debug mode +#define CC_SURFACES_DEBUG_VIEW_COMPOSITE_DIRECT_DIFFUSE 1 +#define CC_SURFACES_DEBUG_VIEW_COMPOSITE_DIRECT_SPECULAR CC_SURFACES_DEBUG_VIEW_COMPOSITE_DIRECT_DIFFUSE * 2 +#define CC_SURFACES_DEBUG_VIEW_COMPOSITE_ENV_DIFFUSE CC_SURFACES_DEBUG_VIEW_COMPOSITE_DIRECT_SPECULAR * 2 +#define CC_SURFACES_DEBUG_VIEW_COMPOSITE_ENV_SPECULAR CC_SURFACES_DEBUG_VIEW_COMPOSITE_ENV_DIFFUSE * 2 +#define CC_SURFACES_DEBUG_VIEW_COMPOSITE_EMISSIVE CC_SURFACES_DEBUG_VIEW_COMPOSITE_ENV_SPECULAR * 2 +#define CC_SURFACES_DEBUG_VIEW_COMPOSITE_LIGHT_MAP CC_SURFACES_DEBUG_VIEW_COMPOSITE_EMISSIVE * 2 +#define CC_SURFACES_DEBUG_VIEW_COMPOSITE_SHADOW CC_SURFACES_DEBUG_VIEW_COMPOSITE_LIGHT_MAP * 2 +#define CC_SURFACES_DEBUG_VIEW_COMPOSITE_AO CC_SURFACES_DEBUG_VIEW_COMPOSITE_SHADOW * 2 + +#define CC_SURFACES_DEBUG_VIEW_COMPOSITE_NORMAL_MAP CC_SURFACES_DEBUG_VIEW_COMPOSITE_AO * 2 +#define CC_SURFACES_DEBUG_VIEW_COMPOSITE_FOG CC_SURFACES_DEBUG_VIEW_COMPOSITE_NORMAL_MAP * 2 + +#define CC_SURFACES_DEBUG_VIEW_COMPOSITE_TONE_MAPPING CC_SURFACES_DEBUG_VIEW_COMPOSITE_FOG * 2 +#define CC_SURFACES_DEBUG_VIEW_COMPOSITE_GAMMA_CORRECTION CC_SURFACES_DEBUG_VIEW_COMPOSITE_TONE_MAPPING * 2 + +// Debug view UI and macros +// #pragma define-meta CC_SURFACES_DEBUG_VIEW_MODE range([0, 19]) +// #pragma define-meta CC_SURFACES_DEBUG_VIEW_COMPOSITE_MODE range([0, 16]) +// #pragma define-meta CC_SURFACES_DEBUG_VIEW_LIGHTING_WITH_ALBEDO range([0, 1]) +// #pragma define-meta CC_SURFACES_DEBUG_VIEW_MISC_ENABLE_CSM_LAYER_COLORATION range([0, 1]) + +// test +#pragma define CC_SURFACES_DEBUG_VIEW_LIGHTING_WITH_ALBEDO 0 +#pragma define CC_SURFACES_DEBUG_VIEW_MODE 0//CC_SURFACES_DEBUG_VIEW_LINEAR_DEPTH +#pragma define CC_SURFACES_DEBUG_VIEW_COMPOSITE_MODE 0 +#pragma define CC_SURFACES_DEBUG_VIEW_MISC_ENABLE_CSM_LAYER_COLORATION 0 +#pragma define CC_SURFACES_USE_DEBUG_VIEW 0 + +// use uniforms for fast toggling +// 逻辑: 只要单项调试开启,此宏即为1(ubo中设置view_single_mode) +// 当单项调试关闭时:当复合开关全开且misc也全关时此宏为0, 否则此宏为2(ubo中设置composite和misc相关项) +#define CC_SURFACES_DEBUG_VIEW_SINGLE 1 +#define CC_SURFACES_DEBUG_VIEW_COMPOSITE_AND_MISC 2 + +/* +#if CC_SURFACES_USE_DEBUG_VIEW + #pragma builtin(global) + layout(set = 0, binding = 3) uniform CCDebugView { + int cc_debug_view_single_mode; // single debug + float cc_debug_view_lighting_enable_with_albedo; + float cc_debug_view_misc_enable_csm_layer_coloration; // misc debug + float cc_debug_view_composite_enable_direct_diffuse; + float cc_debug_view_composite_enable_direct_specular; + float cc_debug_view_composite_enable_env_diffuse; + float cc_debug_view_composite_enable_env_specular; + float cc_debug_view_composite_enable_emissive; + float cc_debug_view_composite_enable_light_map; + float cc_debug_view_composite_enable_shadow; + float cc_debug_view_composite_enable_ao; + float cc_debug_view_composite_enable_normal_map; + float cc_debug_view_composite_enable_fog; + float cc_debug_view_composite_enable_tone_mapping; + float cc_debug_view_composite_enable_gamma_correction; + }; +#endif +*/ + // move to common.chunk +#pragma define equalf(data1, data2) (abs(float(data1) - float(data2)) < EPSILON) + + // define.ts: 增加PipelineGlobalBindings.UBO_DEBUGVIEW, cc_shadowMap / cc_spotLightingMap / cc_environment / cc_diffuseMap的binding加1 + /** + * @en The uniform buffer object for debug view + * @zh 渲染调试 UBO。 + */ +/* + export class UBODebugView { + public static readonly SINGLE_MODE = 0; + public static readonly LIGHTING_ENABLE_WITH_ALBEDO = UBODebugView.SINGLE_MODE + 1; + public static readonly MISC_ENABLE_CSM_LAYER_COLORATION = UBODebugView.LIGHTING_ENABLE_WITH_ALBEDO + 1; + public static readonly COMPOSITE_ENABLE_DIRECT_DIFFUSE = UBODebugView.MISC_ENABLE_CSM_LAYER_COLORATION + 1; + public static readonly COMPOSITE_ENABLE_DIRECT_SPECULAR = UBODebugView.COMPOSITE_ENABLE_DIRECT_DIFFUSE + 1; + public static readonly COMPOSITE_ENABLE_ENV_DIFFUSE = UBODebugView.COMPOSITE_ENABLE_DIRECT_SPECULAR + 1; + public static readonly COMPOSITE_ENABLE_ENV_SPECULAR = UBODebugView.COMPOSITE_ENABLE_ENV_DIFFUSE + 1; + public static readonly COMPOSITE_ENABLE_EMISSIVE = UBODebugView.COMPOSITE_ENABLE_ENV_SPECULAR + 1; + public static readonly COMPOSITE_ENABLE_LIGHT_MAP = UBODebugView.COMPOSITE_ENABLE_EMISSIVE + 1; + public static readonly COMPOSITE_ENABLE_SHADOW = UBODebugView.COMPOSITE_ENABLE_LIGHT_MAP + 1; + public static readonly COMPOSITE_ENABLE_AO = UBODebugView.COMPOSITE_ENABLE_SHADOW + 1; + public static readonly COMPOSITE_ENABLE_NORMAL_MAP = UBODebugView.COMPOSITE_ENABLE_AO + 1; + public static readonly COMPOSITE_ENABLE_FOG = UBODebugView.COMPOSITE_ENABLE_NORMAL_MAP + 1; + public static readonly COMPOSITE_ENABLE_TONE_MAPPING = UBODebugView.COMPOSITE_ENABLE_FOG + 1; + public static readonly COMPOSITE_ENABLE_GAMMA_CORRECTION = UBODebugView.COMPOSITE_ENABLE_TONE_MAPPING + 1; + public static readonly COUNT : number = UBODebugView.COMPOSITE_ENABLE_GAMMA_CORRECTION + 1; + public static readonly SIZE = UBODebugView.COUNT * 4; + public static readonly NAME = 'CCDebugView'; + public static readonly BINDING = PipelineGlobalBindings.UBO_DEBUGVIEW; + public static readonly DESCRIPTOR = new DescriptorSetLayoutBinding(UBODebugView.BINDING, DescriptorType.UNIFORM_BUFFER, 1, ShaderStageFlagBit.ALL); + public static readonly LAYOUT = new UniformBlock(SetIndex.GLOBAL, UBODebugView.BINDING, UBODebugView.NAME, [ + new Uniform('cc_debug_view_single_mode', Type.INT, 1), + new Uniform('cc_debug_view_lighting_enable_with_albedo', Type.FLOAT, 1), + new Uniform('cc_debug_view_misc_enable_csm_layer_coloration', Type.FLOAT, 1), + new Uniform('cc_debug_view_composite_enable_direct_diffuse', Type.FLOAT, 1), + new Uniform('cc_debug_view_composite_enable_direct_specular', Type.FLOAT, 1), + new Uniform('cc_debug_view_composite_enable_env_diffuse', Type.FLOAT, 1), + new Uniform('cc_debug_view_composite_enable_env_specular', Type.FLOAT, 1), + new Uniform('cc_debug_view_composite_enable_emissive', Type.FLOAT, 1), + new Uniform('cc_debug_view_composite_enable_light_map', Type.FLOAT, 1), + new Uniform('cc_debug_view_composite_enable_shadow', Type.FLOAT, 1), + new Uniform('cc_debug_view_composite_enable_ao', Type.FLOAT, 1), + new Uniform('cc_debug_view_composite_enable_normal_map', Type.FLOAT, 1), + new Uniform('cc_debug_view_composite_enable_fog', Type.FLOAT, 1), + new Uniform('cc_debug_view_composite_enable_tone_mapping', Type.FLOAT, 1), + new Uniform('cc_debug_view_composite_enable_gamma_correction', Type.FLOAT, 1), + ], 1); + } + globalDescriptorSetLayout.layouts[UBODebugView.NAME] = UBODebugView.LAYOUT; + globalDescriptorSetLayout.bindings[UBODebugView.BINDING] = UBODebugView.DESCRIPTOR; + */ diff --git a/editor/assets/chunks/common/debug/debug-view-define.chunk.meta b/editor/assets/chunks/common/debug/debug-view-define.chunk.meta new file mode 100644 index 0000000000..cc61ede78c --- /dev/null +++ b/editor/assets/chunks/common/debug/debug-view-define.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "9c973ee8-952a-4ee3-a617-ba6397db6bac", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/common/effect.meta b/editor/assets/chunks/common/effect.meta new file mode 100644 index 0000000000..8d4205ead6 --- /dev/null +++ b/editor/assets/chunks/common/effect.meta @@ -0,0 +1,12 @@ +{ + "ver": "1.1.0", + "importer": "directory", + "imported": true, + "uuid": "98420980-4268-402a-a26d-f66e6ee50a03", + "files": [], + "subMetas": {}, + "userData": { + "compressionType": {}, + "isRemoteBundle": {} + } +} diff --git a/editor/assets/chunks/common/effect/fog.chunk b/editor/assets/chunks/common/effect/fog.chunk new file mode 100644 index 0000000000..14d10ba454 --- /dev/null +++ b/editor/assets/chunks/common/effect/fog.chunk @@ -0,0 +1,65 @@ +// fog related calculations + +//pos, cc_cameraPos, 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); + return clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.); +} + +//pos, cc_cameraPos, 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) - 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) - fogStart, 0.0) / fogAtten * 4.; + float f = exp(-cam_dis * cam_dis * fogDensity * fogDensity); + return f; +} + +//pos, cc_cameraPos, 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; +} diff --git a/editor/assets/chunks/common/effect/fog.chunk.meta b/editor/assets/chunks/common/effect/fog.chunk.meta new file mode 100644 index 0000000000..4f8d522765 --- /dev/null +++ b/editor/assets/chunks/common/effect/fog.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "399f5890-dde1-40de-9751-a7aa91a56b93", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/common/internal-functions.meta b/editor/assets/chunks/common/internal-functions.meta new file mode 100644 index 0000000000..d2e456107a --- /dev/null +++ b/editor/assets/chunks/common/internal-functions.meta @@ -0,0 +1,12 @@ +{ + "ver": "1.1.0", + "importer": "directory", + "imported": true, + "uuid": "b67dfb5d-1a4d-469e-a35f-52e665ae1ea2", + "files": [], + "subMetas": {}, + "userData": { + "compressionType": {}, + "isRemoteBundle": {} + } +} diff --git a/editor/assets/chunks/common/lighting.meta b/editor/assets/chunks/common/lighting.meta new file mode 100644 index 0000000000..8c7abb84c1 --- /dev/null +++ b/editor/assets/chunks/common/lighting.meta @@ -0,0 +1,12 @@ +{ + "ver": "1.1.0", + "importer": "directory", + "imported": true, + "uuid": "a2ba2f72-737d-4b4b-84be-3e014d996327", + "files": [], + "subMetas": {}, + "userData": { + "compressionType": {}, + "isRemoteBundle": {} + } +} diff --git a/editor/assets/chunks/common/lighting/attenuation.chunk b/editor/assets/chunks/common/lighting/attenuation.chunk new file mode 100644 index 0000000000..f6ef44e5cd --- /dev/null +++ b/editor/assets/chunks/common/lighting/attenuation.chunk @@ -0,0 +1,26 @@ + +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); +} diff --git a/editor/assets/chunks/common/lighting/attenuation.chunk.meta b/editor/assets/chunks/common/lighting/attenuation.chunk.meta new file mode 100644 index 0000000000..2628f2bdad --- /dev/null +++ b/editor/assets/chunks/common/lighting/attenuation.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "077cca29-6f66-4aad-a3a7-4f0a7ecd523f", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/common/lighting/brdf.chunk b/editor/assets/chunks/common/lighting/brdf.chunk new file mode 100644 index 0000000000..63a70735c1 --- /dev/null +++ b/editor/assets/chunks/common/lighting/brdf.chunk @@ -0,0 +1,69 @@ +float D_GGX(float roughness, float NoH) +{ + float m = roughness * roughness; + float m2 = m * m; + float d = (NoH * m2 - NoH) * NoH + 1.0; + return m2 / max(EPSILON, d * d); +} + +float D_GGXMobile(float roughness, float NoH) { + float OneMinusNoHSqr = 1.0 - NoH * NoH; + float a = roughness * roughness; + float n = NoH * a; + float p = a / (OneMinusNoHSqr + n * n); + return p * p; +} + +void GetAnisotropicRoughness(float roughness, float anisotropyShape, out float roughnessX, out float roughnessY) +{ + float shapeSign = sign(anisotropyShape); + anisotropyShape *= anisotropyShape; + + float r1 = roughness, r2 = roughness; + float lerpedRoughness = mix(1.0, 10.0, anisotropyShape); + r2 *= shapeSign < 0.0 ? lerpedRoughness : 1.0; + r1 *= shapeSign > 0.0 ? lerpedRoughness : 1.0; + roughnessX = saturate(r1); + roughnessY = saturate(r2); +} + +float D_GGXAniso(float RoughnessX, float RoughnessY, float NoH, vec3 H, vec3 X, vec3 Y) +{ + float mx = max(EPSILON_LOWP, RoughnessX * RoughnessX); + float my = max(EPSILON_LOWP, RoughnessY * RoughnessY); + float XoH = dot(X, H); + float YoH = dot(Y, H); + float d = XoH * XoH / (mx * mx) + YoH * YoH / (my * my) + NoH * NoH; + return 1.0 / max(EPSILON_LOWP, mx * my * d * d); +} + +vec3 GetAnisotropicReflect(float roughness, float anisotropyShape, vec3 V, vec3 N, vec3 X, vec3 Y) +{ + float shapeSign = sign(anisotropyShape); + anisotropyShape *= anisotropyShape; + + //clamp to shape=0.6x for invert reflection artifact + anisotropyShape = min(anisotropyShape, 0.4); + + // roughness->0 means optical smooth surface (back to isotropic) + anisotropyShape *= smoothstep(0.0, 0.03, roughness); + + // use view co-planar vector instead of XoH->0 plane convolution, but not accuracy + vec3 reflectTarget = shapeSign < 0.0 ? mix(N, -Y, anisotropyShape) : + shapeSign > 0.0 ? mix(N, -X, anisotropyShape) : N; + return reflect(-V, reflectTarget); +} + +// EnvBRDFApprox +vec3 IntegratedGFApprox (vec3 specular, float roughness, float NoV) { + const vec4 c0 = vec4(-1.0, -0.0275, -0.572, 0.022); + const vec4 c1 = vec4(1.0, 0.0425, 1.04, -0.04); + vec4 r = roughness * c0 + c1; + float a004 = min(r.x * r.x, exp2(-9.28 * NoV)) * r.x + r.y; + vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw; + AB.y *= clamp(50.0 * specular.g, 0.0, 1.0); + return specular * AB.x + AB.y; +} + +//Diffuse_Lambert +#define DiffuseCoefficient_EnergyConservation INV_PI diff --git a/editor/assets/chunks/common/lighting/brdf.chunk.meta b/editor/assets/chunks/common/lighting/brdf.chunk.meta new file mode 100644 index 0000000000..40732d77b4 --- /dev/null +++ b/editor/assets/chunks/common/lighting/brdf.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "3a85eafd-0fd0-468f-8a2e-0c81493230c7", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/common/lighting/functions.chunk b/editor/assets/chunks/common/lighting/functions.chunk new file mode 100644 index 0000000000..7f48e073f9 --- /dev/null +++ b/editor/assets/chunks/common/lighting/functions.chunk @@ -0,0 +1,22 @@ +#include + +// helper functions for lighting model-functions + +float CalculateDistanceAttenuation(float distToLightSqr, float lightRadius, float lightRange) +{ + float litRadiusSqr = lightRadius * lightRadius; + float attRadiusSqrInv = 1.0 / max(lightRange, 0.01); + attRadiusSqrInv *= attRadiusSqrInv; + + // soft edge fading + float edgeAttenuation = 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); +} diff --git a/editor/assets/chunks/common/lighting/functions.chunk.meta b/editor/assets/chunks/common/lighting/functions.chunk.meta new file mode 100644 index 0000000000..a5bf067e79 --- /dev/null +++ b/editor/assets/chunks/common/lighting/functions.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "d360c347-a546-4967-bdd3-30cae323f123", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/common/lighting/lightmap.chunk b/editor/assets/chunks/common/lighting/lightmap.chunk new file mode 100644 index 0000000000..6b1a54b18c --- /dev/null +++ b/editor/assets/chunks/common/lighting/lightmap.chunk @@ -0,0 +1,16 @@ +#pragma builtin(local) +layout(set = 2, binding = 10) uniform sampler2D cc_lightingMap; + +vec4 GetLightMapColor(vec2 luv, float lum) +{ + vec4 lightmap = texture(cc_lightingMap, luv); + lightmap.rgb *= lum; + +#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 + lightmap.rgb *= cc_exposure.w * cc_exposure.x; +#endif + + return lightmap; +} \ No newline at end of file diff --git a/editor/assets/chunks/common/lighting/lightmap.chunk.meta b/editor/assets/chunks/common/lighting/lightmap.chunk.meta new file mode 100644 index 0000000000..1c61044fa6 --- /dev/null +++ b/editor/assets/chunks/common/lighting/lightmap.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "345abc7e-5211-479e-854e-03600d86f2cd", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/common/math.meta b/editor/assets/chunks/common/math.meta new file mode 100644 index 0000000000..c4e77402e7 --- /dev/null +++ b/editor/assets/chunks/common/math.meta @@ -0,0 +1,12 @@ +{ + "ver": "1.1.0", + "importer": "directory", + "imported": true, + "uuid": "328da6ff-910d-4cb5-904d-5c1a4ba35edd", + "files": [], + "subMetas": {}, + "userData": { + "compressionType": {}, + "isRemoteBundle": {} + } +} diff --git a/editor/assets/chunks/common/math/coordinates.chunk b/editor/assets/chunks/common/math/coordinates.chunk new file mode 100644 index 0000000000..6b9f3c011f --- /dev/null +++ b/editor/assets/chunks/common/math/coordinates.chunk @@ -0,0 +1,32 @@ +// params must be normalized +vec3 CalculateBinormal(vec3 normal, vec3 tangent, float mirrorNormal) +{ + return cross(normal.xyz, tangent) * mirrorNormal; +} + + +// param1 is normal from normalmap +// return value is un-normalized +vec3 CalculateNormalFromTangentSpace(vec3 normalFromTangentSpace, float normalStrength, vec3 normal, vec3 tangent, float mirrorNormal) +{ + vec3 binormal = CalculateBinormal(normal, tangent, mirrorNormal); + return (normalFromTangentSpace.x * normalStrength) * normalize(tangent) + + (normalFromTangentSpace.y * normalStrength) * normalize(binormal) + + normalFromTangentSpace.z * normalize(normal); +} + + +// rotationAngle: 0-1 stand for 0-180 rotation +void RotateTangentAndBinormal(inout vec3 tangent, inout vec3 binormal, vec3 normal, float rotationAngle) +{ + rotationAngle = clamp(rotationAngle, 0.0, 1.0 - EPSILON_LOWP); // 1.0 is invalid value that equals to 90 rotation (coef=0, angle>0.5) + float coef = fract(rotationAngle * 2.0); + bool isNegative = rotationAngle <= 0.5; + + // spherical interpolating is more accuracy and linear transitions but expensive, use simple pow fix instead + coef = pow(coef, isNegative ? 0.75 : 1.25); + vec3 binormalNew = isNegative ? mix(binormal, -tangent, coef) : mix(-tangent, -binormal, coef); + vec3 tangentNew = isNegative ? mix(tangent, binormal, coef) : mix(binormal, -tangent, coef); + tangent = normalize(tangentNew); + binormal = normalize(binormalNew); +} diff --git a/editor/assets/chunks/common/math/coordinates.chunk.meta b/editor/assets/chunks/common/math/coordinates.chunk.meta new file mode 100644 index 0000000000..54f7005b88 --- /dev/null +++ b/editor/assets/chunks/common/math/coordinates.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "e9d8b3bb-03e4-46b2-be29-ea58fac18c18", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/common/math/number.chunk b/editor/assets/chunks/common/math/number.chunk new file mode 100644 index 0000000000..9c9ae50f1c --- /dev/null +++ b/editor/assets/chunks/common/math/number.chunk @@ -0,0 +1,24 @@ +#if __VERSION__ <= 100 +bool isnan(float val) { + return (val < 0.0 || 0.0 < val || val == 0.0) ? false : true; +} +bool isinf(float x) { + return x == x * 2.0; +} +#endif + +bool isnans(vec3 val) { + return isnan(val.x) && isnan(val.y) && isnan(val.z); +} +bool isnans(vec4 val) { + return isnan(val.x) && isnan(val.y) && isnan(val.z) && isnan(val.w); +} +bool isinfs(vec4 val) { + return isinf(val.x) && isinf(val.y) && isinf(val.z) && isinf(val.w); +} +bool isinfs(vec3 val) { + return isinf(val.x) && isinf(val.y) && isinf(val.z); +} + + +// random number \ No newline at end of file diff --git a/editor/assets/chunks/common/math/number.chunk.meta b/editor/assets/chunks/common/math/number.chunk.meta new file mode 100644 index 0000000000..27780e4c40 --- /dev/null +++ b/editor/assets/chunks/common/math/number.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "9f84c121-c61b-499f-b400-81a5448d6078", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/common/mesh.meta b/editor/assets/chunks/common/mesh.meta new file mode 100644 index 0000000000..ab0c88b766 --- /dev/null +++ b/editor/assets/chunks/common/mesh.meta @@ -0,0 +1,12 @@ +{ + "ver": "1.1.0", + "importer": "directory", + "imported": true, + "uuid": "44c741c8-2cdd-41c1-b359-feb18b2f3c69", + "files": [], + "subMetas": {}, + "userData": { + "compressionType": {}, + "isRemoteBundle": {} + } +} diff --git a/editor/assets/chunks/common/mesh/material.chunk b/editor/assets/chunks/common/mesh/material.chunk new file mode 100644 index 0000000000..0f70837976 --- /dev/null +++ b/editor/assets/chunks/common/mesh/material.chunk @@ -0,0 +1,47 @@ +bool GetMetallicAlbedoFromDiffuseSpecularMathematic(out float metallic, out vec3 albedo, vec3 diffuse, vec3 specular, float channelFaultTolerant /*= 0.2*/, float f0 /*= 0.04*/) +{ + // inaccuracy match first + //GetMetallicAlbedoFromDiffuseSpecular(metallic, albedo, diffuse, specular); + + // avoid illegal solver + diffuse += vec3(f0 + 0.01); + specular += vec3(f0 + 0.01); + + vec3 delta = (diffuse + specular) * (diffuse + specular) - 4.0 * f0 * diffuse; + vec3 deltaSqrt = sqrt(max(vec3(0.0), delta)); + // solver + vec3 m = (-diffuse - specular + 2.0 * f0 + deltaSqrt) / (2.0 * f0); + vec3 weight = diffuse + specular; + weight /= dot(weight, vec3(1.0)); + float solverMetallic = dot(m, weight); + vec3 solverAlbedo = diffuse + specular - f0 * (1.0 - solverMetallic); + + bool isValidSolver = delta.x >= 0.0 && delta.y >= 0.0 && delta.z >= 0.0 + && abs(m.x - m.y) < channelFaultTolerant && abs(m.x - m.z) < channelFaultTolerant + && m.x >= 0.0 && m.y >= 0.0 && m.z >= 0.0 + && m.x <= 1.0 && m.y <= 1.0 && m.z <= 1.0; + + metallic = isValidSolver ? solverMetallic : metallic; + albedo = isValidSolver ? solverAlbedo : albedo; + return isValidSolver; +} + +bool GetMetallicAlbedoFromDiffuseSpecularWithoutColor(out float metallic, out vec3 albedo, vec3 diffuse, vec3 specular, float f0 /*= 0.04*/) +{ + float d = max(max(diffuse.x, diffuse.y), diffuse.z); + vec3 normalizedColor = diffuse / (d + (d < EPSILON_LOWP ? EPSILON_LOWP : 0.0)); + normalizedColor = d < EPSILON_LOWP ? specular : normalizedColor; //change specular to gray with intensity of max channel of specular + + float s = max(max(specular.x, specular.y), specular.z); + + float delta = (d + s) * (d + s) - 4.0 * f0 * d; + float deltaSqrt = sqrt(max(0.0, delta)); + // solver + float solverMetallic = (-d - s + 2.0 * f0 + deltaSqrt) / (2.0 * f0); + vec3 solverAlbedo = (d + s) * normalizedColor - vec3(f0 * (1.0 - solverMetallic)); + + bool isValidSolver = delta >= 0.0; + metallic = isValidSolver ? clamp(solverMetallic, 0.0, 1.0) : 0.0; + albedo = isValidSolver ? vec3(max(0.0, solverAlbedo.x), max(0.0, solverAlbedo.y), max(0.0, solverAlbedo.z)) : diffuse; + return isValidSolver; +} diff --git a/editor/assets/chunks/common/mesh/material.chunk.meta b/editor/assets/chunks/common/mesh/material.chunk.meta new file mode 100644 index 0000000000..821710ecf1 --- /dev/null +++ b/editor/assets/chunks/common/mesh/material.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "f992af76-5145-4f8e-beae-6d88be403e8e", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/common/sss.meta b/editor/assets/chunks/common/sss.meta new file mode 100644 index 0000000000..9f17ffb862 --- /dev/null +++ b/editor/assets/chunks/common/sss.meta @@ -0,0 +1,12 @@ +{ + "ver": "1.1.0", + "importer": "directory", + "imported": true, + "uuid": "22d0392f-1cc0-4bb1-8b84-577e3f4551e0", + "files": [], + "subMetas": {}, + "userData": { + "compressionType": {}, + "isRemoteBundle": {} + } +} diff --git a/editor/assets/chunks/common/texture.meta b/editor/assets/chunks/common/texture.meta new file mode 100644 index 0000000000..78b11e379d --- /dev/null +++ b/editor/assets/chunks/common/texture.meta @@ -0,0 +1,12 @@ +{ + "ver": "1.1.0", + "importer": "directory", + "imported": true, + "uuid": "fcd5dc66-1649-4a01-b94c-b528bb881cfb", + "files": [], + "subMetas": {}, + "userData": { + "compressionType": {}, + "isRemoteBundle": {} + } +} diff --git a/editor/assets/chunks/common/texture/cubemap.chunk b/editor/assets/chunks/common/texture/cubemap.chunk new file mode 100644 index 0000000000..32f426e17c --- /dev/null +++ b/editor/assets/chunks/common/texture/cubemap.chunk @@ -0,0 +1,48 @@ +#pragma extension([GL_OES_standard_derivatives, __VERSION__ < 110]) + vec3 EnvReflectionWithMipFiltering(vec3 R, float roughness, float mipCount, float denoiseIntensity) { + #if CC_USE_IBL + // simulate GGX convolution + #if !CC_SURFACES_USE_LEGACY_COMPATIBLE_LIGHTING //#todo: && !CC_IBL_CONVOLUTED + roughness = pow(roughness, 0.5); + #endif + + //#todo: add GL400 calcmip + float mip = roughness * mipCount; + float delta = (dot(dFdx(R), dFdy(R))) * 1000.0; + float mipBias = mix(0.0, 5.0, clamp(delta, 0.0, 1.0)); + + vec4 biased = fragTextureLod(cc_environment, R, mip + mipBias); + vec4 filtered = texture(cc_environment, R); + + #if CC_USE_IBL == IBL_RGBE + biased.rgb = unpackRGBE(biased); + filtered.rgb = unpackRGBE(filtered); + #else + biased.rgb = SRGBToLinear(biased.rgb); + filtered.rgb = SRGBToLinear(filtered.rgb); + #endif + + return mix(biased.rgb, filtered.rgb, denoiseIntensity); + #else + return vec3(0.0, 0.0, 0.0); + #endif + } + + vec3 EnvReflection(vec3 R, float roughness, float mipCount) { + #if CC_USE_IBL + // simulate GGX convolution + #if !CC_SURFACES_USE_LEGACY_COMPATIBLE_LIGHTING //#todo: && !CC_IBL_CONVOLUTED + roughness = pow(roughness, 0.5); + #endif + + vec4 envmap = fragTextureLod(cc_environment, R, roughness * mipCount); + + #if CC_USE_IBL == IBL_RGBE + return unpackRGBE(envmap); + #else + return SRGBToLinear(envmap.rgb); + #endif + #else + return vec3(0.0, 0.0, 0.0); + #endif + } diff --git a/editor/assets/chunks/common/texture/cubemap.chunk.meta b/editor/assets/chunks/common/texture/cubemap.chunk.meta new file mode 100644 index 0000000000..c795d62178 --- /dev/null +++ b/editor/assets/chunks/common/texture/cubemap.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "3931bd87-0a7b-4d2d-a5f1-9544227343a8", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/common/ubo.meta b/editor/assets/chunks/common/ubo.meta new file mode 100644 index 0000000000..a8c355114b --- /dev/null +++ b/editor/assets/chunks/common/ubo.meta @@ -0,0 +1,12 @@ +{ + "ver": "1.1.0", + "importer": "directory", + "imported": true, + "uuid": "2476d369-6d06-4dab-ade6-0d8b22ae0948", + "files": [], + "subMetas": {}, + "userData": { + "compressionType": {}, + "isRemoteBundle": {} + } +} diff --git a/editor/assets/chunks/decode-base.chunk b/editor/assets/chunks/decode-base.chunk index 1d3a532fc3..c7ca08bbbf 100644 --- a/editor/assets/chunks/decode-base.chunk +++ b/editor/assets/chunks/decode-base.chunk @@ -37,7 +37,7 @@ layout(location = 3) in vec4 a_tangent; in vec4 a_matWorld0; in vec4 a_matWorld1; in vec4 a_matWorld2; - #if USE_LIGHTMAP + #if CC_USE_LIGHTMAP in vec4 a_lightingMapUVParam; #endif #if CC_RECEIVE_SHADOW diff --git a/editor/assets/chunks/decode-base.chunk.meta b/editor/assets/chunks/decode-base.chunk.meta index f693d19c74..eb5b24ea16 100644 --- a/editor/assets/chunks/decode-base.chunk.meta +++ b/editor/assets/chunks/decode-base.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "e05f440c-0ba5-4c83-a039-5644d248bb87", diff --git a/editor/assets/chunks/decode-standard.chunk.meta b/editor/assets/chunks/decode-standard.chunk.meta index 7fb1eb3973..813d8eee16 100644 --- a/editor/assets/chunks/decode-standard.chunk.meta +++ b/editor/assets/chunks/decode-standard.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "8daa33da-9438-4294-aace-2a58d1b183ab", diff --git a/editor/assets/chunks/decode.chunk.meta b/editor/assets/chunks/decode.chunk.meta index 5a0fd7f9ab..da1645564a 100644 --- a/editor/assets/chunks/decode.chunk.meta +++ b/editor/assets/chunks/decode.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "385a7ca1-9421-475c-aa02-38d52ef3ba7f", diff --git a/editor/assets/chunks/deprecated.chunk.meta b/editor/assets/chunks/deprecated.chunk.meta index 43bfc3a5c6..5b4ab6e17c 100644 --- a/editor/assets/chunks/deprecated.chunk.meta +++ b/editor/assets/chunks/deprecated.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "355259fc-3a13-4fed-b553-a5e2caeb2e75", diff --git a/editor/assets/chunks/embedded-alpha.chunk.meta b/editor/assets/chunks/embedded-alpha.chunk.meta index 807614d9ae..126ca1ad37 100644 --- a/editor/assets/chunks/embedded-alpha.chunk.meta +++ b/editor/assets/chunks/embedded-alpha.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "ef4fb7de-9b39-4eeb-9ae8-d292ff94a452", diff --git a/editor/assets/chunks/fxaa.chunk.meta b/editor/assets/chunks/fxaa.chunk.meta index 8c6675f4bc..25e07541de 100644 --- a/editor/assets/chunks/fxaa.chunk.meta +++ b/editor/assets/chunks/fxaa.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "0afb4a28-945f-48ac-91e5-6f483345f8ab", diff --git a/editor/assets/chunks/gamma.chunk.meta b/editor/assets/chunks/gamma.chunk.meta index f3a006da12..1db7425c78 100644 --- a/editor/assets/chunks/gamma.chunk.meta +++ b/editor/assets/chunks/gamma.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "bb213412-2e68-43b3-9de5-73ca332acace", diff --git a/editor/assets/chunks/general-vs.chunk.meta b/editor/assets/chunks/general-vs.chunk.meta index 6ed03008b7..01808ffa98 100644 --- a/editor/assets/chunks/general-vs.chunk.meta +++ b/editor/assets/chunks/general-vs.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "2cdcf2a6-42f3-4142-a340-eabfe530ccbf", diff --git a/editor/assets/chunks/input-standard.chunk.meta b/editor/assets/chunks/input-standard.chunk.meta index 6d57cac8a5..39dc9cf94e 100644 --- a/editor/assets/chunks/input-standard.chunk.meta +++ b/editor/assets/chunks/input-standard.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "f957d7e0-a3eb-480c-b3c6-43a1a5273b71", diff --git a/editor/assets/chunks/input.chunk.meta b/editor/assets/chunks/input.chunk.meta index feab5b5856..71b62357e5 100644 --- a/editor/assets/chunks/input.chunk.meta +++ b/editor/assets/chunks/input.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "3b9a2995-9fa1-4862-9bcf-9b6fa2c64bd4", diff --git a/editor/assets/chunks/lighting-models.meta b/editor/assets/chunks/lighting-models.meta new file mode 100644 index 0000000000..2af6387735 --- /dev/null +++ b/editor/assets/chunks/lighting-models.meta @@ -0,0 +1,12 @@ +{ + "ver": "1.1.0", + "importer": "directory", + "imported": true, + "uuid": "fbccacc9-0f83-4d66-8bc5-afa9a6e54b36", + "files": [], + "subMetas": {}, + "userData": { + "compressionType": {}, + "isRemoteBundle": {} + } +} diff --git a/editor/assets/chunks/lighting-models/data-structures.meta b/editor/assets/chunks/lighting-models/data-structures.meta new file mode 100644 index 0000000000..6948d608f4 --- /dev/null +++ b/editor/assets/chunks/lighting-models/data-structures.meta @@ -0,0 +1,12 @@ +{ + "ver": "1.1.0", + "importer": "directory", + "imported": true, + "uuid": "91df99f8-d0d2-451e-9c9e-f2d776851f91", + "files": [], + "subMetas": {}, + "userData": { + "compressionType": {}, + "isRemoteBundle": {} + } +} diff --git a/editor/assets/chunks/lighting-models/data-structures/lighting-intermediate-data.chunk b/editor/assets/chunks/lighting-models/data-structures/lighting-intermediate-data.chunk new file mode 100644 index 0000000000..1da0b3f96d --- /dev/null +++ b/editor/assets/chunks/lighting-models/data-structures/lighting-intermediate-data.chunk @@ -0,0 +1,76 @@ +struct LightingIntermediateData +{ + vec3 N, H, L, V; // normalized + float distToLight, distToLightSqr; // (pos->light)^2 + float distToCamera, distToCameraSqr; // pos->camera + + float NoL, NoV, NoH;//, VoH; + float NoLSat, NoVSat, NoHSat;//, VoHSat; // clamped to 0-1 + float NoVAbsSat; // abs and clamped to 1 + + // for advanced material + vec3 T, B; + + // material data + float specularParam; // roughness or specular power +#if CC_SURFACES_LIGHTING_ANISOTROPIC + float anisotropyShape; +#endif + + // #if CC_SURFACES_LIGHTING_SPECULAR_2ND + // float specularParam2nd, specularIntensity2nd, specularRotation2nd; // for hair + // vec3 specularColor2nd; + // #endif + // #if CC_SURFACES_LIGHTING_CLEAR_COAT + // float ior; + // float roughnessClearCoat; // for clear coat or multi-layer pbr + // #endif +}; + +// add overrided functions for difference shading-models in +void CCSurfacesLightingGetIntermediateData_PerPixel(inout LightingIntermediateData data, vec3 worldNormal, vec3 worldPos, vec3 worldTangent, vec3 worldBinormal +#if CC_SURFACES_LIGHTING_ANISOTROPIC + , float anisotropyShape +#endif +) +{ + // N V + data.N = worldNormal; + + data.V = cc_cameraPos.xyz - worldPos; + data.distToCameraSqr = dot(data.V, data.V); + data.distToCamera = sqrt(data.distToCameraSqr); + data.V /= data.distToCamera; + + data.NoV = dot(data.N, data.V); + data.NoVSat = max(data.NoV, 0.0); + data.NoVAbsSat = max(abs(data.NoV), 0.0); + + data.T = worldTangent; + data.B = worldBinormal; + +#if CC_SURFACES_LIGHTING_ANISOTROPIC + data.anisotropyShape = anisotropyShape; +#endif +} + +void CCSurfacesLightingGetIntermediateData_PerLight(inout LightingIntermediateData data, vec3 lightDirWithDist) +{ + // L H + data.L = lightDirWithDist; + data.distToLightSqr = dot(data.L, data.L); + data.distToLight = sqrt(data.distToLightSqr); + + data.L /= data.distToLight; + + data.H = normalize(data.L + data.V); + + // dot + data.NoL = dot(data.N, data.L); + data.NoH = dot(data.N, data.H); + // data.VoH = dot(data.V, data.H); + + data.NoLSat = max(data.NoL, 0.0); + data.NoHSat = max(data.NoH, 0.0); + // data.VoHSat = max(data.VoH, 0.0); +} diff --git a/editor/assets/chunks/lighting-models/data-structures/lighting-intermediate-data.chunk.meta b/editor/assets/chunks/lighting-models/data-structures/lighting-intermediate-data.chunk.meta new file mode 100644 index 0000000000..b51f333b25 --- /dev/null +++ b/editor/assets/chunks/lighting-models/data-structures/lighting-intermediate-data.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "be2dc7d9-db45-4d0b-957b-aee1cb81bde0", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/lighting-models/data-structures/lighting-result.chunk b/editor/assets/chunks/lighting-models/data-structures/lighting-result.chunk new file mode 100644 index 0000000000..97fdda2eb7 --- /dev/null +++ b/editor/assets/chunks/lighting-models/data-structures/lighting-result.chunk @@ -0,0 +1,13 @@ +struct LightingResult +{ + // material-dependent lighting data + vec3 diffuseColorWithLighting, specularColorWithLighting; + + // pure lighting + vec3 directDiffuse, directSpecular; + vec3 environmentDiffuse, environmentSpecular; + float shadow, ao; + vec3 lightmapColor; + vec3 emissive; + //vec3 transmittance, scattered; +}; diff --git a/editor/assets/chunks/lighting-models/data-structures/lighting-result.chunk.meta b/editor/assets/chunks/lighting-models/data-structures/lighting-result.chunk.meta new file mode 100644 index 0000000000..b4006dc971 --- /dev/null +++ b/editor/assets/chunks/lighting-models/data-structures/lighting-result.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "7646cc74-5fcc-47c4-970b-5958505c17e5", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/lighting-models/default-functions.meta b/editor/assets/chunks/lighting-models/default-functions.meta new file mode 100644 index 0000000000..5648ba8f91 --- /dev/null +++ b/editor/assets/chunks/lighting-models/default-functions.meta @@ -0,0 +1,12 @@ +{ + "ver": "1.1.0", + "importer": "directory", + "imported": true, + "uuid": "77dddf0f-b81c-4797-9222-905cbea8dcd5", + "files": [], + "subMetas": {}, + "userData": { + "compressionType": {}, + "isRemoteBundle": {} + } +} diff --git a/editor/assets/chunks/lighting-models/default-functions/simple-skin.chunk b/editor/assets/chunks/lighting-models/default-functions/simple-skin.chunk new file mode 100644 index 0000000000..6691d26cdb --- /dev/null +++ b/editor/assets/chunks/lighting-models/default-functions/simple-skin.chunk @@ -0,0 +1,7 @@ +#ifndef CC_SURFACES_LIGHTING_MODIFY_SKIN_DIFFUSE_LIGHTING + vec3 SurfacesLightingModifySkinDiffuseLighting(in LightingIntermediateData lightingData, in float ssssCurvature) + { + // if user do not sample PreIntegratedSSS tex, fallback to default light model + return vec3(lightingData.NoL); + } +#endif diff --git a/editor/assets/chunks/lighting-models/default-functions/simple-skin.chunk.meta b/editor/assets/chunks/lighting-models/default-functions/simple-skin.chunk.meta new file mode 100644 index 0000000000..bc772acc79 --- /dev/null +++ b/editor/assets/chunks/lighting-models/default-functions/simple-skin.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "9ada82f2-4c4e-433f-8090-e8bfad31fcf2", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/lighting-models/includes.meta b/editor/assets/chunks/lighting-models/includes.meta new file mode 100644 index 0000000000..859cc26b67 --- /dev/null +++ b/editor/assets/chunks/lighting-models/includes.meta @@ -0,0 +1,12 @@ +{ + "ver": "1.1.0", + "importer": "directory", + "imported": true, + "uuid": "30b9fedf-84ec-49a1-be3b-9555317e980e", + "files": [], + "subMetas": {}, + "userData": { + "compressionType": {}, + "isRemoteBundle": {} + } +} diff --git a/editor/assets/chunks/lighting-models/includes/standard.chunk b/editor/assets/chunks/lighting-models/includes/standard.chunk new file mode 100644 index 0000000000..1da559d132 --- /dev/null +++ b/editor/assets/chunks/lighting-models/includes/standard.chunk @@ -0,0 +1,4 @@ +// Lighting-model includes +#include +#include +#include diff --git a/editor/assets/chunks/lighting-models/includes/standard.chunk.meta b/editor/assets/chunks/lighting-models/includes/standard.chunk.meta new file mode 100644 index 0000000000..19baf32ea9 --- /dev/null +++ b/editor/assets/chunks/lighting-models/includes/standard.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "cc12f5ac-3dcf-4455-aea9-b9be2dd9071e", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/lighting-models/includes/toon.chunk b/editor/assets/chunks/lighting-models/includes/toon.chunk new file mode 100644 index 0000000000..90a13e1dc8 --- /dev/null +++ b/editor/assets/chunks/lighting-models/includes/toon.chunk @@ -0,0 +1,4 @@ +// Lighting-model includes +#include +#include +#include diff --git a/editor/assets/chunks/lighting-models/includes/toon.chunk.meta b/editor/assets/chunks/lighting-models/includes/toon.chunk.meta new file mode 100644 index 0000000000..5419ba6bce --- /dev/null +++ b/editor/assets/chunks/lighting-models/includes/toon.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "2710ad01-b6c3-4048-b5d9-b3b69cec3e94", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/lighting-models/lighting-flow.meta b/editor/assets/chunks/lighting-models/lighting-flow.meta new file mode 100644 index 0000000000..b824a90ede --- /dev/null +++ b/editor/assets/chunks/lighting-models/lighting-flow.meta @@ -0,0 +1,12 @@ +{ + "ver": "1.1.0", + "importer": "directory", + "imported": true, + "uuid": "6fee360e-820e-45a0-81a2-3c4896c0838e", + "files": [], + "subMetas": {}, + "userData": { + "compressionType": {}, + "isRemoteBundle": {} + } +} diff --git a/editor/assets/chunks/lighting-models/lighting-flow/common-flow.chunk b/editor/assets/chunks/lighting-models/lighting-flow/common-flow.chunk new file mode 100644 index 0000000000..4a7264cfb1 --- /dev/null +++ b/editor/assets/chunks/lighting-models/lighting-flow/common-flow.chunk @@ -0,0 +1,95 @@ +#if (CC_PIPELINE_TYPE == CC_PIPELINE_TYPE_FORWARD || CC_FORCE_FORWARD_SHADING) + #if CC_FORWARD_ADD && !CC_ENABLE_CLUSTERED_LIGHT_CULLING + void CCSurfacesLighting(inout LightingResult lightingResult, in SurfacesMaterialData surfaceData, in vec4 shadowPos, in vec2 shadowBias) + { + vec3 worldPos; + HIGHP_VALUE_FROM_STRUCT_DEFINED(worldPos, surfaceData.worldPos); + + LightingIntermediateData lightingData; + CCSurfacesInitializeLightingIntermediateData(lightingData, surfaceData); + + CCSurfacesLightingInitializeColorWithLighting(lightingResult.diffuseColorWithLighting, lightingResult.specularColorWithLighting, surfaceData, lightingData); + + lightingResult.directDiffuse = lightingResult.directSpecular = vec3(0.0); + + int numLights = CC_PIPELINE_TYPE == CC_PIPELINE_TYPE_FORWARD ? LIGHTS_PER_PASS : int(cc_lightDir[0].w); + for (int i = 0; i < LIGHTS_PER_PASS; i++) { + if (i >= numLights) break; + + CCSurfacesLightingCalculateIntermediateData_PerLight(lightingData, surfaceData, cc_lightPos[i].xyz - worldPos); + CCSurfacesLightingCalculateColorWithLighting(lightingResult.diffuseColorWithLighting, lightingResult.specularColorWithLighting, surfaceData, lightingData); + + vec3 diffuseLighting, specularLighting; + CCSurfacesLightingCalculateDirect(diffuseLighting, specularLighting, lightingData, cc_lightColor[i]); + + float shadow = 1.0; + #if CC_RECEIVE_SHADOW + if (cc_lightPos[i].w > 0.0 && cc_lightSizeRangeAngle[i].w > 0.0) { + if (CCSurfacesLightingEnableShadow(lightingData.NoL)) { + shadow = CCSpotShadowFactorBase(shadowPos, worldPos, shadowBias); + } + } + #endif + + float distAtt = CCSurfacesLightingCalculateDistanceAttenuation(lightingData, cc_lightSizeRangeAngle[i]); + + float angleAtt = 1.0; + if (cc_lightPos[i].w > 0.0) { + angleAtt = CCSurfacesLightingCalculateAngleAttenuation(lightingData, cc_lightSizeRangeAngle[i], -cc_lightDir[i].xyz); + } + + float multiplier = distAtt * angleAtt * shadow; + + lightingResult.directDiffuse += diffuseLighting * multiplier; + lightingResult.directSpecular += specularLighting * multiplier; + } + } + #else + void CCSurfacesLighting(inout LightingResult lightingResult, in SurfacesMaterialData surfaceData, in vec4 shadowPos, in vec2 shadowBias) + { + LightingIntermediateData lightingData; + CCSurfacesInitializeLightingIntermediateData(lightingData, surfaceData); + CCSurfacesInitializeLightingResult(lightingResult, surfaceData); + + CCSurfacesLightingInitializeColorWithLighting(lightingResult.diffuseColorWithLighting, lightingResult.specularColorWithLighting, surfaceData, lightingData); + + CCSurfacesLightingCalculateIntermediateData_PerLight(lightingData, surfaceData, -cc_mainLitDir.xyz); + CCSurfacesLightingCalculateColorWithLighting(lightingResult.diffuseColorWithLighting, lightingResult.specularColorWithLighting, surfaceData, lightingData); + + CCSurfacesLightingCalculateDirect(lightingResult.directDiffuse, lightingResult.directSpecular, lightingData, cc_mainLitColor); + + // CCSurfacesLightingCalculateShadow: + lightingResult.shadow = 1.0; + #if CC_RECEIVE_SHADOW + if (cc_mainLitDir.w > 0.0) { + if (CCSurfacesLightingEnableShadow(lightingData.NoL)) { + lightingResult.shadow = CCShadowFactorBase(shadowPos, lightingData.N, shadowBias); + } + } + #endif + + // apply SSR, local probe & global probe + CCSurfacesLightingCalculateEnvironment(lightingResult, lightingData); + + // CCSurfacesLightingCalculateTransmittence(lightingResult, lightingData, shadowPos); + + // CCSurfacesLightingCalculateBaked: + lightingResult.lightmapColor = vec3(0.0); + #if CC_SURFACES_USE_LIGHT_MAP && !CC_SURFACES_USE_BATCHING && !CC_FORWARD_ADD + vec4 lightmap = GetLightMapColor(FSInput_lightMapUV.xy, FSInput_lightMapUV.z); + lightingResult.lightmapColor = lightmap.rgb; + // lightingResult.shadow/ao *= lightmap.a; + #endif + + // apply screen-space shadow and ao + // lightingResult.shadow/ao *= XXX; + + + + //#todo: cluster related lighting flow + #if CC_ENABLE_CLUSTERED_LIGHT_CULLING + //#include + #endif + } + #endif +#endif diff --git a/editor/assets/chunks/lighting-models/lighting-flow/common-flow.chunk.meta b/editor/assets/chunks/lighting-models/lighting-flow/common-flow.chunk.meta new file mode 100644 index 0000000000..cab49c8ec6 --- /dev/null +++ b/editor/assets/chunks/lighting-models/lighting-flow/common-flow.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "41c84281-f2e7-43e2-88bd-6ffcaf1daf5a", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/lighting-models/model-functions.meta b/editor/assets/chunks/lighting-models/model-functions.meta new file mode 100644 index 0000000000..d4064e1afa --- /dev/null +++ b/editor/assets/chunks/lighting-models/model-functions.meta @@ -0,0 +1,12 @@ +{ + "ver": "1.1.0", + "importer": "directory", + "imported": true, + "uuid": "78ea1b40-6c4b-4eb4-b91e-b5bbee21f992", + "files": [], + "subMetas": {}, + "userData": { + "compressionType": {}, + "isRemoteBundle": {} + } +} diff --git a/editor/assets/chunks/lighting-models/model-functions/standard.chunk b/editor/assets/chunks/lighting-models/model-functions/standard.chunk new file mode 100644 index 0000000000..c7161d938b --- /dev/null +++ b/editor/assets/chunks/lighting-models/model-functions/standard.chunk @@ -0,0 +1,117 @@ +#include +#include + +bool CCSurfacesLightingEnableShadow(in float NoL) +{ + return NoL > 0.0; +} + +float CCSurfacesLightingCalculateDistanceAttenuation(in LightingIntermediateData lightingData, in vec4 lightSizeRangeAngle) +{ + return CalculateDistanceAttenuation(lightingData.distToLightSqr, lightSizeRangeAngle.x, lightSizeRangeAngle.y); +} + +float CCSurfacesLightingCalculateAngleAttenuation(in LightingIntermediateData lightingData, in vec4 lightSizeRangeAngle, in vec3 spotLightDir) +{ + return CalculateAngleAttenuation(spotLightDir, lightingData.L, lightSizeRangeAngle.z); +} + +void CCSurfacesLightingCalculateDirect(out vec3 lightingDiffuse, out vec3 lightingSpecular, in LightingIntermediateData lightingData, in vec4 lightSourceColorAndIntensity) +{ + vec3 irradiance = vec3(lightingData.NoLSat) * lightSourceColorAndIntensity.rgb * lightSourceColorAndIntensity.w; + + lightingDiffuse = irradiance * DiffuseCoefficient_EnergyConservation; + + float roughness = lightingData.specularParam; +#if CC_SURFACES_LIGHTING_ANISOTROPIC + float rT, rB; + GetAnisotropicRoughness(roughness, lightingData.anisotropyShape, rT, rB); + float calcSpec = D_GGXAniso(rT, rB, lightingData.NoHSat, lightingData.H, lightingData.T, lightingData.B); +#else + #if CC_SURFACES_USE_LEGACY_COMPATIBLE_LIGHTING + float calcSpec = (roughness * 0.25 + 0.25) * D_GGXMobile(roughness, lightingData.NoHSat); + #else + float calcSpec = D_GGX(roughness, lightingData.NoHSat); + #endif +#endif + lightingSpecular = irradiance * calcSpec; +} + + +#if CC_SURFACES_LIGHTING_ANISOTROPIC_ENVCONVOLUTION_COUNT + vec3 EnvAnisotropicReflection(vec3 R, float roughness, float mipCount, float anisotropyShape, vec3 V, vec3 N, vec3 T, vec3 B) { + R = normalize(R); + float integratedBRDF = 0.0; + vec3 envSpec = vec3(0.0); + // One direction sample count + const int SAMPLE_STEP_COUNT = CC_SURFACES_LIGHTING_ANISOTROPIC_ENVCONVOLUTION_COUNT; + float sampleAngleRange = PI * abs(anisotropyShape); + vec3 anisoDirection = anisotropyShape < 0.0 ? T : B; + vec3 ROnNormalPlane = normalize(R - anisoDirection * dot(R, anisoDirection)); + //ROnTangentPlane = R; //for example: cross-style + vec3 stepOffset = normalize(ROnNormalPlane - N) * (sampleAngleRange / float(SAMPLE_STEP_COUNT * 2)); + + for (int i = -SAMPLE_STEP_COUNT; i <= SAMPLE_STEP_COUNT; ++i) + { + float rT, rB; + GetAnisotropicRoughness(roughness, anisotropyShape, rT, rB); + float coef = pow(abs(float(i)) / float(SAMPLE_STEP_COUNT), 1.3) * float(SAMPLE_STEP_COUNT); + vec3 H = normalize(N + stepOffset * sign(float(i)) * coef); + vec3 L = reflect(-V, H); + float NoHSat = saturate(dot(N, H)); + float calcSpec = D_GGXAniso(rT, rB, NoHSat, H, T, B); + + envSpec += calcSpec * EnvReflection(L, roughness, mipCount); + integratedBRDF += calcSpec; + } + envSpec /= integratedBRDF; + return envSpec; + } +#endif + + +void CCSurfacesLightingCalculateEnvironment(inout LightingResult lightingResult, in LightingIntermediateData lightingData) +{ + float roughness = lightingData.specularParam; + float fAmb = 0.5 - lightingData.N.y * 0.5; + vec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb); + vec3 envSpec = vec3(0.0); + + #if CC_USE_IBL + #if CC_USE_DIFFUSEMAP + // Diffuse irradiance + vec4 diffuseMap = texture(cc_diffuseMap, lightingData.N); + #if CC_USE_DIFFUSEMAP == IBL_RGBE + ambDiff = unpackRGBE(diffuseMap); + #else + ambDiff = SRGBToLinear(diffuseMap.rgb); + #endif + #endif + + #if CC_SURFACES_LIGHTING_ANISOTROPIC && !CC_SURFACES_LIGHTING_ANISOTROPIC_ENVCONVOLUTION_COUNT + vec3 R = GetAnisotropicReflect(roughness, lightingData.anisotropyShape, lightingData.V, lightingData.N, lightingData.T, lightingData.B); + #else + vec3 R = reflect(-lightingData.V, lightingData.N); + #endif + + #if CC_SURFACES_LIGHTING_ANISOTROPIC && CC_SURFACES_LIGHTING_ANISOTROPIC_ENVCONVOLUTION_COUNT + envSpec = EnvAnisotropicReflection(R, roughness, cc_ambientGround.w, lightingData.anisotropyShape, lightingData.V, lightingData.N, lightingData.T, lightingData.B); + #else + #if CC_SURFACES_USE_REFLECTION_DENOISE + envSpec = EnvReflectionWithMipFiltering(normalize(R), roughness, cc_ambientGround.w, 0.6); + #else + envSpec = EnvReflection(R, roughness, cc_ambientGround.w); + #endif + #endif + #endif + + lightingResult.environmentDiffuse = ambDiff.rgb * cc_ambientSky.w; + lightingResult.environmentSpecular = envSpec * cc_ambientSky.w; +} + +void CCSurfacesLightingCalculateTransmittence(inout LightingResult lightingResult, in LightingIntermediateData lightingData, vec3 shadowPos) +{ + vec3 irradiance = vec3(lightingData.NoLSat);// * lightSourceColorAndIntensity.rgb * lightSourceColorAndIntensity.w; + + vec3 transmittence = irradiance * DiffuseCoefficient_EnergyConservation; +} diff --git a/editor/assets/chunks/lighting-models/model-functions/standard.chunk.meta b/editor/assets/chunks/lighting-models/model-functions/standard.chunk.meta new file mode 100644 index 0000000000..0849c228a1 --- /dev/null +++ b/editor/assets/chunks/lighting-models/model-functions/standard.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "4c24618b-1e1d-40e4-883a-cd3fd2304233", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/lighting-models/model-functions/toon.chunk b/editor/assets/chunks/lighting-models/model-functions/toon.chunk new file mode 100644 index 0000000000..4e6be6f9c4 --- /dev/null +++ b/editor/assets/chunks/lighting-models/model-functions/toon.chunk @@ -0,0 +1,42 @@ +#include +#include + +bool CCSurfacesLightingEnableShadow(in float NoL) +{ + return NoL > 0.0; +} + +float CCSurfacesLightingCalculateDistanceAttenuation(in LightingIntermediateData lightingData, in vec4 lightSizeRangeAngle) +{ + return CalculateDistanceAttenuation(lightingData.distToLightSqr, lightSizeRangeAngle.x, lightSizeRangeAngle.y); +} + +float CCSurfacesLightingCalculateAngleAttenuation(in LightingIntermediateData lightingData, in vec4 lightSizeRangeAngle, in vec3 spotLightDir) +{ + return CalculateAngleAttenuation(spotLightDir, lightingData.L, lightSizeRangeAngle.z); +} + +void CCSurfacesLightingCalculateDirect(out vec3 lightingDiffuse, out vec3 lightingSpecular, in LightingIntermediateData lightingData, in vec4 lightSourceColorAndIntensity) +{ + vec3 irradiance = lightSourceColorAndIntensity.rgb * lightSourceColorAndIntensity.w; + + lightingDiffuse = irradiance; // no energy conservation + + // punctual lighting is different from dir lighting +#if CC_FORWARD_ADD || CC_ENABLE_CLUSTERED_LIGHT_CULLING + float NL = 0.5 * lightingData.NoL + 0.5; + lightingDiffuse *= NL; +#endif + + float NH = 0.5 * lightingData.NoH + 0.5; + float specularWeight = 1.0 - pow(lightingData.specularParam, 5.0); + float specularMask = step(specularWeight, NH); + lightingSpecular = irradiance * specularMask; +} + +void CCSurfacesLightingCalculateEnvironment(inout LightingResult lightingResult, in LightingIntermediateData lightingData) +{ + lightingResult.environmentDiffuse = vec3(0.0); + lightingResult.environmentSpecular = vec3(0.0); +} + diff --git a/editor/assets/chunks/lighting-models/model-functions/toon.chunk.meta b/editor/assets/chunks/lighting-models/model-functions/toon.chunk.meta new file mode 100644 index 0000000000..f075e8bb14 --- /dev/null +++ b/editor/assets/chunks/lighting-models/model-functions/toon.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "9276cd2c-6001-4f89-b024-f53f63628527", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/lighting.chunk.meta b/editor/assets/chunks/lighting.chunk.meta index ccf012ca87..3948321428 100644 --- a/editor/assets/chunks/lighting.chunk.meta +++ b/editor/assets/chunks/lighting.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "357618ca-4d71-41b6-af86-9534799c705e", diff --git a/editor/assets/chunks/lightingmap-fs.chunk.meta b/editor/assets/chunks/lightingmap-fs.chunk.meta index e5392020ba..96cde16ec4 100644 --- a/editor/assets/chunks/lightingmap-fs.chunk.meta +++ b/editor/assets/chunks/lightingmap-fs.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "bf771826-ab41-49bd-8058-1cd0fa7a7273", diff --git a/editor/assets/chunks/lightingmap-vs.chunk.meta b/editor/assets/chunks/lightingmap-vs.chunk.meta index 251df876ed..c1c00b70f6 100644 --- a/editor/assets/chunks/lightingmap-vs.chunk.meta +++ b/editor/assets/chunks/lightingmap-vs.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "d22a3ca1-78fe-442c-a604-0349f5c873f7", diff --git a/editor/assets/chunks/morph.chunk.meta b/editor/assets/chunks/morph.chunk.meta index 780801a95d..1c64e4e8f0 100644 --- a/editor/assets/chunks/morph.chunk.meta +++ b/editor/assets/chunks/morph.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "5e669fb5-203c-4e59-90b1-10e6ef5d7e29", diff --git a/editor/assets/chunks/octahedron-transform.chunk b/editor/assets/chunks/octahedron-transform.chunk index 6c4869de2d..ab7c8cb26f 100644 --- a/editor/assets/chunks/octahedron-transform.chunk +++ b/editor/assets/chunks/octahedron-transform.chunk @@ -17,6 +17,11 @@ vec3 oct_to_float32x3(vec2 e) { return normalize(v); } +float getCameraDepthRH(float ndcDepth, mat4 matProj) +{ + return -matProj[3][2] / (ndcDepth + matProj[2][2]); +} + vec4 screen2WS(vec3 coord) { vec3 ndc = vec3( 2.0 * (coord.x - cc_viewPort.x) / cc_viewPort.z - 1.0, @@ -26,7 +31,8 @@ vec4 screen2WS(vec3 coord) { #else 2.0 * coord.z - 1.0); #endif - vec4 world = ((cc_matViewProjInv) * (vec4(ndc, 1.0))); - world = world / world.w; + + float w = -getCameraDepthRH(ndc.z, cc_matProj); + vec4 world = (cc_matViewProjInv * vec4(ndc * w, w)); return world; } \ No newline at end of file diff --git a/editor/assets/chunks/octahedron-transform.chunk.meta b/editor/assets/chunks/octahedron-transform.chunk.meta index 3bda3bf8cb..eaba58d8f5 100644 --- a/editor/assets/chunks/octahedron-transform.chunk.meta +++ b/editor/assets/chunks/octahedron-transform.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "41f91fc1-5aec-45dd-91ca-39ab964f8054", diff --git a/editor/assets/chunks/outline-fs.chunk.meta b/editor/assets/chunks/outline-fs.chunk.meta index 2d8169ce5a..1db43dc3d5 100644 --- a/editor/assets/chunks/outline-fs.chunk.meta +++ b/editor/assets/chunks/outline-fs.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "4864e2f6-3eb5-4f08-a87a-5c98141cdef4", diff --git a/editor/assets/chunks/outline-vs.chunk.meta b/editor/assets/chunks/outline-vs.chunk.meta index 689b89766e..cf05e164f6 100644 --- a/editor/assets/chunks/outline-vs.chunk.meta +++ b/editor/assets/chunks/outline-vs.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "f71444cb-cecf-4692-a310-2a5fdb96b469", diff --git a/editor/assets/chunks/output-standard.chunk.meta b/editor/assets/chunks/output-standard.chunk.meta index c3fbe0d46a..53509470a7 100644 --- a/editor/assets/chunks/output-standard.chunk.meta +++ b/editor/assets/chunks/output-standard.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "a3c0cc1c-64de-4e52-9698-5f73f8db488e", diff --git a/editor/assets/chunks/output.chunk.meta b/editor/assets/chunks/output.chunk.meta index a2203d5e61..757b8947db 100644 --- a/editor/assets/chunks/output.chunk.meta +++ b/editor/assets/chunks/output.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "713f0582-5c82-484f-81f7-5006e5a4f48f", diff --git a/editor/assets/chunks/packing.chunk.meta b/editor/assets/chunks/packing.chunk.meta index b1ab533fe1..342fe84231 100644 --- a/editor/assets/chunks/packing.chunk.meta +++ b/editor/assets/chunks/packing.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "73866dd2-eaf5-40af-a061-1b9d38782204", diff --git a/editor/assets/chunks/particle-common.chunk.meta b/editor/assets/chunks/particle-common.chunk.meta index 4c2252d3d0..dd3cf33f0d 100644 --- a/editor/assets/chunks/particle-common.chunk.meta +++ b/editor/assets/chunks/particle-common.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "7a49db3a-930e-4ffc-8659-a82141dabebb", diff --git a/editor/assets/chunks/particle-trail.chunk.meta b/editor/assets/chunks/particle-trail.chunk.meta index 910011983b..9f1815a4cc 100644 --- a/editor/assets/chunks/particle-trail.chunk.meta +++ b/editor/assets/chunks/particle-trail.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "df7d02d8-559a-4c02-9aac-3732cfc83d7a", diff --git a/editor/assets/chunks/particle-vs-gpu.chunk.meta b/editor/assets/chunks/particle-vs-gpu.chunk.meta index c51d1602f3..7e57e88da4 100644 --- a/editor/assets/chunks/particle-vs-gpu.chunk.meta +++ b/editor/assets/chunks/particle-vs-gpu.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "b4b00c01-eca8-4ae4-a04d-e00bbeb6d0e0", diff --git a/editor/assets/chunks/particle-vs-legacy.chunk.meta b/editor/assets/chunks/particle-vs-legacy.chunk.meta index 0f14dcbc47..0b053e1f26 100644 --- a/editor/assets/chunks/particle-vs-legacy.chunk.meta +++ b/editor/assets/chunks/particle-vs-legacy.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "6e1b48cb-69c8-448c-8055-69ab9793fbab", diff --git a/editor/assets/chunks/rect-area-light.chunk.meta b/editor/assets/chunks/rect-area-light.chunk.meta index 1ab1daa523..a4d0acafa3 100644 --- a/editor/assets/chunks/rect-area-light.chunk.meta +++ b/editor/assets/chunks/rect-area-light.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "a24fb7a1-f7a5-430c-a8b2-e4c516131086", diff --git a/editor/assets/chunks/shading-cluster-additive.chunk.meta b/editor/assets/chunks/shading-cluster-additive.chunk.meta index 7112e9b999..2e7fa12ab2 100644 --- a/editor/assets/chunks/shading-cluster-additive.chunk.meta +++ b/editor/assets/chunks/shading-cluster-additive.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "b2d386c6-615b-4375-accd-574405611e35", diff --git a/editor/assets/chunks/shading-entries.meta b/editor/assets/chunks/shading-entries.meta new file mode 100644 index 0000000000..b7e1f7fbbb --- /dev/null +++ b/editor/assets/chunks/shading-entries.meta @@ -0,0 +1,12 @@ +{ + "ver": "1.1.0", + "importer": "directory", + "imported": true, + "uuid": "63ef0c7d-b48e-45d1-91ba-570e61a44c11", + "files": [], + "subMetas": {}, + "userData": { + "compressionType": {}, + "isRemoteBundle": {} + } +} diff --git a/editor/assets/chunks/shading-entries/data-structures.meta b/editor/assets/chunks/shading-entries/data-structures.meta new file mode 100644 index 0000000000..ebc567d20a --- /dev/null +++ b/editor/assets/chunks/shading-entries/data-structures.meta @@ -0,0 +1,12 @@ +{ + "ver": "1.1.0", + "importer": "directory", + "imported": true, + "uuid": "f4c3a799-80ef-49a2-b0d8-b8f35ec3ddfb", + "files": [], + "subMetas": {}, + "userData": { + "compressionType": {}, + "isRemoteBundle": {} + } +} diff --git a/editor/assets/chunks/shading-entries/data-structures/fs-input.chunk b/editor/assets/chunks/shading-entries/data-structures/fs-input.chunk new file mode 100644 index 0000000000..d676b0dbaa --- /dev/null +++ b/editor/assets/chunks/shading-entries/data-structures/fs-input.chunk @@ -0,0 +1,90 @@ +#if __VERSION__ < 300 + #define CC_SURFACES_VARING_MODIFIER varying +#else + #define CC_SURFACES_VARING_MODIFIER in +#endif + +#include + +// FS Input +/*struct SurfacesStandardFragmentInput +{ + HIGHP_VALUE_STRUCT_DEFINE(vec3, worldPos); + vec3 worldNormal; + vec2 texcoord; + +#if CC_SURFACES_USE_VERTEX_COLOR + vec4 vertexColor; +#endif + +#if CC_SURFACES_USE_TANGENT_SPACE + vec3 worldTangent, worldBitangent; + float mirrorNormal; +#endif + +#if CC_SURFACES_USE_SECOND_UV + vec2 texcoord1; +#endif + +#if CC_SURFACES_USE_LIGHT_MAP && !CC_SURFACES_USE_BATCHING && !CC_FORWARD_ADD + vec3 lightMapUV; +#endif + +#if CC_RECEIVE_SHADOW + highp vec4 shadowPos; + vec2 shadowBias; +#endif + +#if !CC_USE_ACCURATE_FOG + float fogFactor; +#endif +} +void CCSurfacesGetFragmentInput(out SurfacesStandardFragmentInput fsInput) +{ +} +*/ + +// Use macros instead of structure to avoid structure precision issues +#define FSInput_worldPos v_worldPos +#define FSInput_worldNormal v_normal.xyz +#define FSInput_faceSideSign v_normal.w +#define FSInput_texcoord v_uv + +#if CC_SURFACES_USE_VERTEX_COLOR + #define FSInput_vertexColor v_color +#else + #define FSInput_vertexColor vec4(1.0) // for compatible user-surface functions in other render usage +#endif + +#if CC_SURFACES_USE_TANGENT_SPACE + #define FSInput_worldTangent v_tangent.xyz + #define FSInput_mirrorNormal v_tangent.w +#else + #define FSInput_worldTangent vec3(0.0, 0.0, 0.0) + #define FSInput_mirrorNormal 1.0 +#endif + +#if CC_SURFACES_USE_SECOND_UV && !CC_SURFACES_USE_LIGHT_MAP + #define FSInput_texcoord1 v_uv1 +#else + #define FSInput_texcoord1 vec2(0.0, 0.0) +#endif + +#if CC_SURFACES_USE_LIGHT_MAP && !CC_SURFACES_USE_BATCHING && !CC_FORWARD_ADD + #define FSInput_lightMapUV v_luv +#endif + +#if CC_RECEIVE_SHADOW + #define FSInput_shadowPos v_shadowPos + #if CC_SURFACES_USE_INSTANCING + #define FSInput_shadowBias v_shadowBias + #endif +#endif + +#if !CC_USE_ACCURATE_FOG + #define FSInput_fogFactor v_fogFactor +#endif + +#if CC_SURFACES_TRANSFER_LOCAL_POS + #define FSInput_localPos v_localPos +#endif diff --git a/editor/assets/chunks/shading-entries/data-structures/fs-input.chunk.meta b/editor/assets/chunks/shading-entries/data-structures/fs-input.chunk.meta new file mode 100644 index 0000000000..ad5c2762a3 --- /dev/null +++ b/editor/assets/chunks/shading-entries/data-structures/fs-input.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "ec870cfb-9c88-4f70-929a-ae540a33075b", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/shading-entries/data-structures/vs-fs.chunk b/editor/assets/chunks/shading-entries/data-structures/vs-fs.chunk new file mode 100644 index 0000000000..2e5023f115 --- /dev/null +++ b/editor/assets/chunks/shading-entries/data-structures/vs-fs.chunk @@ -0,0 +1,35 @@ +//VS->PS +CC_SURFACES_VARING_MODIFIER highp vec3 v_worldPos; +CC_SURFACES_VARING_MODIFIER mediump vec4 v_normal; +CC_SURFACES_VARING_MODIFIER vec2 v_uv; + +#if CC_SURFACES_USE_VERTEX_COLOR + CC_SURFACES_VARING_MODIFIER lowp vec4 v_color; +#endif + +#if CC_SURFACES_USE_TANGENT_SPACE + CC_SURFACES_VARING_MODIFIER mediump vec4 v_tangent; +#endif + +#if CC_SURFACES_USE_SECOND_UV && !CC_SURFACES_USE_LIGHT_MAP + CC_SURFACES_VARING_MODIFIER mediump vec2 v_uv1; +#endif + +#if CC_SURFACES_USE_LIGHT_MAP && !CC_SURFACES_USE_BATCHING && !CC_FORWARD_ADD + CC_SURFACES_VARING_MODIFIER mediump vec3 v_luv; +#endif + +#if CC_RECEIVE_SHADOW + CC_SURFACES_VARING_MODIFIER highp vec4 v_shadowPos; + #if CC_SURFACES_USE_INSTANCING + CC_SURFACES_VARING_MODIFIER mediump vec2 v_shadowBias; + #endif +#endif + +#if !CC_USE_ACCURATE_FOG + CC_SURFACES_VARING_MODIFIER float v_fogFactor; +#endif + +#if CC_SURFACES_TRANSFER_LOCAL_POS + CC_SURFACES_VARING_MODIFIER highp vec4 v_localPos; +#endif diff --git a/editor/assets/chunks/shading-entries/data-structures/vs-fs.chunk.meta b/editor/assets/chunks/shading-entries/data-structures/vs-fs.chunk.meta new file mode 100644 index 0000000000..8d5234676c --- /dev/null +++ b/editor/assets/chunks/shading-entries/data-structures/vs-fs.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "f3454fd7-28d9-48dd-a761-ebc8e26834ed", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/shading-entries/data-structures/vs-input.chunk b/editor/assets/chunks/shading-entries/data-structures/vs-input.chunk new file mode 100644 index 0000000000..c76eac5c7f --- /dev/null +++ b/editor/assets/chunks/shading-entries/data-structures/vs-input.chunk @@ -0,0 +1,52 @@ +//IA Input +layout(location = 0) in vec3 a_position; +layout(location = 1) in vec3 a_normal; +layout(location = 2) in vec2 a_texCoord; +#if CC_SURFACES_USE_TANGENT_SPACE + layout(location = 3) in vec4 a_tangent; +#endif + +#if CC_SURFACES_USE_VERTEX_COLOR + in vec4 a_color; +#endif + +#if CC_SURFACES_USE_SECOND_UV || CC_SURFACES_USE_LIGHT_MAP + in vec2 a_texCoord1; +#endif + +#if CC_USE_SKINNING + #if __VERSION__ > 310 + // strictly speaking this should be u16vec4, but due to poor driver support + // somehow it seems we can get better results on many platforms using u32vec4 + layout(location = 4) in u32vec4 a_joints; + #else + #pragma format(RGBA16UI) + layout(location = 4) in vec4 a_joints; + #endif + + layout(location = 5) in vec4 a_weights; +#endif + +#if CC_SURFACES_USE_INSTANCING + #if CC_USE_BAKED_ANIMATION + in highp vec4 a_jointAnimInfo; // frameID, totalJoints, offset + #endif + in vec4 a_matWorld0; + in vec4 a_matWorld1; + in vec4 a_matWorld2; + #if CC_SURFACES_USE_LIGHT_MAP + in vec4 a_lightingMapUVParam; + #endif + #if CC_RECEIVE_SHADOW + in vec2 a_localShadowBias; // x:shadow bias, y:shadow normal bias. + #endif +#elif CC_SURFACES_USE_BATCHING + in float a_dyn_batch_id; +#endif + + +#if CC_USE_MORPH + #if __VERSION__ < 450 + in float a_vertexId; + #endif +#endif diff --git a/editor/assets/chunks/shading-entries/data-structures/vs-input.chunk.meta b/editor/assets/chunks/shading-entries/data-structures/vs-input.chunk.meta new file mode 100644 index 0000000000..f677aad75e --- /dev/null +++ b/editor/assets/chunks/shading-entries/data-structures/vs-input.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "65084d4a-ae7c-4ca9-8448-f4cd405144b7", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/shading-entries/data-structures/vs-intermediate.chunk b/editor/assets/chunks/shading-entries/data-structures/vs-intermediate.chunk new file mode 100644 index 0000000000..447f2bfd3a --- /dev/null +++ b/editor/assets/chunks/shading-entries/data-structures/vs-intermediate.chunk @@ -0,0 +1,54 @@ +struct SurfacesStandardVertexIntermediate +{ + //local space + highp vec4 position; + vec3 normal; +#if CC_SURFACES_USE_TANGENT_SPACE + vec4 tangent; +#endif + + //other data +#if CC_SURFACES_USE_VERTEX_COLOR + vec4 color; +#endif + + vec2 texCoord; +#if CC_SURFACES_USE_SECOND_UV && !CC_SURFACES_USE_LIGHT_MAP + vec2 texCoord1; +#endif + + //transformed + highp vec4 clipPos; + highp vec3 worldPos; + vec4 worldNormal; // a: two side sign + #if CC_SURFACES_USE_TANGENT_SPACE + vec3 worldTangent, worldBinormal; + #endif + + //transfered +#if CC_RECEIVE_SHADOW + highp vec4 shadowPos; + vec2 shadowBias; +#endif + +#if !CC_USE_ACCURATE_FOG + float fogFactor; +#endif + +#if CC_SURFACES_USE_LIGHT_MAP && !CC_SURFACES_USE_BATCHING && !CC_FORWARD_ADD + vec3 lightmapUV; +#endif +}; + + +#if CC_USE_MORPH + #if __VERSION__ < 450 + int getVertexId() { + return int(a_vertexId); + } + #else + int getVertexId() { + return gl_VertexIndex; // vulkan convension + } + #endif +#endif diff --git a/editor/assets/chunks/shading-entries/data-structures/vs-intermediate.chunk.meta b/editor/assets/chunks/shading-entries/data-structures/vs-intermediate.chunk.meta new file mode 100644 index 0000000000..2b6fd329e8 --- /dev/null +++ b/editor/assets/chunks/shading-entries/data-structures/vs-intermediate.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "45e6b403-a354-48de-a1e1-e59238bd30b1", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/shading-entries/data-structures/vs-output.chunk b/editor/assets/chunks/shading-entries/data-structures/vs-output.chunk new file mode 100644 index 0000000000..6a3d167838 --- /dev/null +++ b/editor/assets/chunks/shading-entries/data-structures/vs-output.chunk @@ -0,0 +1,46 @@ +#if __VERSION__ < 300 + #define CC_SURFACES_VARING_MODIFIER varying +#else + #define CC_SURFACES_VARING_MODIFIER out +#endif + +#include + + +// Output item macros +#define VSOutput_worldPos v_worldPos +#define VSOutput_worldNormal v_normal.xyz +#define VSOutput_faceSideSign v_normal.w +#define VSOutput_texcoord v_uv + +#if CC_SURFACES_USE_VERTEX_COLOR + #define VSOutput_vertexColor v_color +#endif + +#if CC_SURFACES_USE_TANGENT_SPACE + #define VSOutput_worldTangent v_tangent.xyz + #define VSOutput_mirrorNormal v_tangent.w +#endif + +#if CC_SURFACES_USE_SECOND_UV && !CC_SURFACES_USE_LIGHT_MAP + #define VSOutput_texcoord1 v_uv1 +#endif + +#if CC_SURFACES_USE_LIGHT_MAP && !CC_SURFACES_USE_BATCHING && !CC_FORWARD_ADD + #define VSOutput_lightMapUV v_luv +#endif + +#if CC_RECEIVE_SHADOW + #define VSOutput_shadowPos v_shadowPos + #if CC_SURFACES_USE_INSTANCING + #define VSOutput_shadowBias v_shadowBias + #endif +#endif + +#if !CC_USE_ACCURATE_FOG + #define VSOutput_fogFactor v_fogFactor +#endif + +#if CC_SURFACES_TRANSFER_LOCAL_POS + #define VSOutput_localPos v_localPos +#endif diff --git a/editor/assets/chunks/shading-entries/data-structures/vs-output.chunk.meta b/editor/assets/chunks/shading-entries/data-structures/vs-output.chunk.meta new file mode 100644 index 0000000000..c96afad8fa --- /dev/null +++ b/editor/assets/chunks/shading-entries/data-structures/vs-output.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "513eb9a6-0193-4ab1-a7da-2ab087936caa", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/shading-entries/main-functions.meta b/editor/assets/chunks/shading-entries/main-functions.meta new file mode 100644 index 0000000000..8beeb23d3a --- /dev/null +++ b/editor/assets/chunks/shading-entries/main-functions.meta @@ -0,0 +1,12 @@ +{ + "ver": "1.1.0", + "importer": "directory", + "imported": true, + "uuid": "06ae07af-f0bd-4133-acd2-f1f8580f797b", + "files": [], + "subMetas": {}, + "userData": { + "compressionType": {}, + "isRemoteBundle": {} + } +} diff --git a/editor/assets/chunks/shading-entries/main-functions/deferred.meta b/editor/assets/chunks/shading-entries/main-functions/deferred.meta new file mode 100644 index 0000000000..817d1ceccf --- /dev/null +++ b/editor/assets/chunks/shading-entries/main-functions/deferred.meta @@ -0,0 +1,12 @@ +{ + "ver": "1.1.0", + "importer": "directory", + "imported": true, + "uuid": "bf711db6-efd9-4505-b6cb-ab1583165328", + "files": [], + "subMetas": {}, + "userData": { + "compressionType": {}, + "isRemoteBundle": {} + } +} diff --git a/editor/assets/chunks/shading-entries/main-functions/forward.meta b/editor/assets/chunks/shading-entries/main-functions/forward.meta new file mode 100644 index 0000000000..9e44948a56 --- /dev/null +++ b/editor/assets/chunks/shading-entries/main-functions/forward.meta @@ -0,0 +1,12 @@ +{ + "ver": "1.1.0", + "importer": "directory", + "imported": true, + "uuid": "7698a66d-0cc2-4602-92b4-ced4196f5554", + "files": [], + "subMetas": {}, + "userData": { + "compressionType": {}, + "isRemoteBundle": {} + } +} diff --git a/editor/assets/chunks/shading-entries/main-functions/misc.meta b/editor/assets/chunks/shading-entries/main-functions/misc.meta new file mode 100644 index 0000000000..004c94499c --- /dev/null +++ b/editor/assets/chunks/shading-entries/main-functions/misc.meta @@ -0,0 +1,12 @@ +{ + "ver": "1.1.0", + "importer": "directory", + "imported": true, + "uuid": "2cf1e156-25bd-4e1c-8cda-d9f14512debf", + "files": [], + "subMetas": {}, + "userData": { + "compressionType": {}, + "isRemoteBundle": {} + } +} diff --git a/editor/assets/chunks/shading-entries/main-functions/misc/silhouette-edge-fs.chunk b/editor/assets/chunks/shading-entries/main-functions/misc/silhouette-edge-fs.chunk new file mode 100644 index 0000000000..b04440b2e4 --- /dev/null +++ b/editor/assets/chunks/shading-entries/main-functions/misc/silhouette-edge-fs.chunk @@ -0,0 +1,20 @@ +layout(location = 0) out vec4 fragColorX; + +void main () { + // for alpha clip + vec4 color = SurfacesFragmentModifyBaseColorAndTransparency(); + + //#uniformStyle need sync here + + // Color output +#if CC_USE_HDR + #if !CC_SURFACES_DEBUG_VIEW_COMPOSITE_MODE || (CC_SURFACES_DEBUG_VIEW_COMPOSITE_MODE & CC_SURFACES_DEBUG_VIEW_COMPOSITE_TONE_MAPPING) + color.rgb = ACESToneMap(color.rgb); + #endif +#endif +#if !CC_SURFACES_DEBUG_VIEW_COMPOSITE_MODE || (CC_SURFACES_DEBUG_VIEW_COMPOSITE_MODE & CC_SURFACES_DEBUG_VIEW_COMPOSITE_GAMMA_CORRECTION) + color.rgb = LinearToSRGB(color.rgb); +#endif + + fragColorX = color; +} diff --git a/editor/assets/chunks/shading-entries/main-functions/misc/silhouette-edge-fs.chunk.meta b/editor/assets/chunks/shading-entries/main-functions/misc/silhouette-edge-fs.chunk.meta new file mode 100644 index 0000000000..c074a8c6a7 --- /dev/null +++ b/editor/assets/chunks/shading-entries/main-functions/misc/silhouette-edge-fs.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "1d7d5670-83c4-4dab-acf3-edb7ae758881", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/shading-entries/main-functions/misc/silhouette-edge-vs.chunk b/editor/assets/chunks/shading-entries/main-functions/misc/silhouette-edge-vs.chunk new file mode 100644 index 0000000000..c8705aaad0 --- /dev/null +++ b/editor/assets/chunks/shading-entries/main-functions/misc/silhouette-edge-vs.chunk @@ -0,0 +1 @@ + #include diff --git a/editor/assets/chunks/shading-entries/main-functions/misc/silhouette-edge-vs.chunk.meta b/editor/assets/chunks/shading-entries/main-functions/misc/silhouette-edge-vs.chunk.meta new file mode 100644 index 0000000000..f7d04edfca --- /dev/null +++ b/editor/assets/chunks/shading-entries/main-functions/misc/silhouette-edge-vs.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "e25e8368-0f16-4322-981e-8b7eebc97afb", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/shading-entries/main-functions/render-to-scene.meta b/editor/assets/chunks/shading-entries/main-functions/render-to-scene.meta new file mode 100644 index 0000000000..2fdbbcc211 --- /dev/null +++ b/editor/assets/chunks/shading-entries/main-functions/render-to-scene.meta @@ -0,0 +1,12 @@ +{ + "ver": "1.1.0", + "importer": "directory", + "imported": true, + "uuid": "3178c6da-bf26-4546-b3f2-a4d0dddd82aa", + "files": [], + "subMetas": {}, + "userData": { + "compressionType": {}, + "isRemoteBundle": {} + } +} diff --git a/editor/assets/chunks/shading-entries/main-functions/render-to-scene/fs.chunk b/editor/assets/chunks/shading-entries/main-functions/render-to-scene/fs.chunk new file mode 100644 index 0000000000..74abf06c26 --- /dev/null +++ b/editor/assets/chunks/shading-entries/main-functions/render-to-scene/fs.chunk @@ -0,0 +1,5 @@ +#if (CC_PIPELINE_TYPE == CC_PIPELINE_TYPE_FORWARD || CC_FORCE_FORWARD_SHADING) + #include +#elif CC_PIPELINE_TYPE == CC_PIPELINE_TYPE_DEFERRED + #include +#endif diff --git a/editor/assets/chunks/shading-entries/main-functions/render-to-scene/fs.chunk.meta b/editor/assets/chunks/shading-entries/main-functions/render-to-scene/fs.chunk.meta new file mode 100644 index 0000000000..f03f9d5b00 --- /dev/null +++ b/editor/assets/chunks/shading-entries/main-functions/render-to-scene/fs.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "52b875e1-87c0-4dc5-a3f7-ce32cb4d93c6", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/shading-entries/main-functions/render-to-scene/pipeline.meta b/editor/assets/chunks/shading-entries/main-functions/render-to-scene/pipeline.meta new file mode 100644 index 0000000000..a4b519d6a2 --- /dev/null +++ b/editor/assets/chunks/shading-entries/main-functions/render-to-scene/pipeline.meta @@ -0,0 +1,12 @@ +{ + "ver": "1.1.0", + "importer": "directory", + "imported": true, + "uuid": "adef72f1-d7cf-4519-b83c-6fd861d8c703", + "files": [], + "subMetas": {}, + "userData": { + "compressionType": {}, + "isRemoteBundle": {} + } +} diff --git a/editor/assets/chunks/shading-entries/main-functions/render-to-scene/pipeline/deferred-fs.chunk b/editor/assets/chunks/shading-entries/main-functions/render-to-scene/pipeline/deferred-fs.chunk new file mode 100644 index 0000000000..75e7e1c512 --- /dev/null +++ b/editor/assets/chunks/shading-entries/main-functions/render-to-scene/pipeline/deferred-fs.chunk @@ -0,0 +1,13 @@ + layout(location = 0) out vec4 fragColor0; + layout(location = 1) out vec4 fragColor1; + layout(location = 2) out vec4 fragColor2; + + void main () { + // Surface + SurfacesMaterialData surfaceData; + CCSurfacesFragmentGetMaterialData(surfaceData); + + fragColor0 = CCSurfacesDeferredOutput0(surfaceData); + fragColor1 = CCSurfacesDeferredOutput1(surfaceData); + fragColor2 = CCSurfacesDeferredOutput2(surfaceData); + } diff --git a/editor/assets/chunks/shading-entries/main-functions/render-to-scene/pipeline/deferred-fs.chunk.meta b/editor/assets/chunks/shading-entries/main-functions/render-to-scene/pipeline/deferred-fs.chunk.meta new file mode 100644 index 0000000000..0650e1b8f5 --- /dev/null +++ b/editor/assets/chunks/shading-entries/main-functions/render-to-scene/pipeline/deferred-fs.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "1101cf65-cc90-486b-b6a5-29ae060e01c7", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/shading-entries/main-functions/render-to-scene/pipeline/forward-fs.chunk b/editor/assets/chunks/shading-entries/main-functions/render-to-scene/pipeline/forward-fs.chunk new file mode 100644 index 0000000000..884652ef8b --- /dev/null +++ b/editor/assets/chunks/shading-entries/main-functions/render-to-scene/pipeline/forward-fs.chunk @@ -0,0 +1,178 @@ +layout(location = 0) out vec4 fragColorX; + +void main() { +#if CC_DISABLE_STRUCTURE_IN_FRAGMENT_SHADER + float NoL = dot(-cc_mainLitDir.xyz, FSInput_worldNormal.xyz); //trigger ubo binding + vec4 color = SurfacesFragmentModifyBaseColorAndTransparency(); +#else + // Surface + SurfacesMaterialData surfaceData; + CCSurfacesFragmentGetMaterialData(surfaceData); + + // Shadow factor + highp vec4 shadowPos = vec4(0.0); + vec2 shadowBias = vec2(0.0); + vec3 colDebugCSMLayer = vec3(1.0); + #if CC_RECEIVE_SHADOW + shadowPos = FSInput_shadowPos; + shadowBias = vec2(cc_shadowWHPBInfo.w, cc_shadowLPNNInfo.z); + #if CC_SURFACES_USE_INSTANCING + shadowBias = FSInput_shadowBias; + #elif !CC_SURFACES_USE_BATCHING + shadowBias += cc_localShadowBias.xy; + #endif + #if !CC_FORWARD_ADD + //#uniformStyle + #if CC_SURFACES_DEBUG_VIEW_MISC_ENABLE_CSM_LAYER_COLORATION + //#if CC_SURFACES_USE_DEBUG_VIEW == CC_SURFACES_DEBUG_VIEW_COMPOSITE_AND_MISC + //if (cc_debug_view_misc_enable_csm_layer_coloration > 0.0) + { + int CSMLayer = 0; + bool OutOfRange = false; + if (OutOfRange) + colDebugCSMLayer = vec3(1.0); + else if (CSMLayer == 0) + colDebugCSMLayer = vec3(1.0, 0.0, 0.0); + else if (CSMLayer == 1) + colDebugCSMLayer = vec3(0.0, 1.0, 0.0); + else if (CSMLayer == 2) + colDebugCSMLayer = vec3(0.0, 0.0, 1.0); + else if (CSMLayer == 3) + colDebugCSMLayer = vec3(0.0, 1.0, 1.0); + } + #endif + #endif + #endif + + + // Fog factor + #if !CC_FORWARD_ADD + float fogFactor = 0.0; + #if !CC_USE_ACCURATE_FOG + fogFactor = FSInput_fogFactor; + #else + CC_TRANSFER_FOG_BASE(vec4(FSInput_worldPos, 1.0), fogFactor); + #endif + + #if CC_SURFACES_DEBUG_VIEW_COMPOSITE_MODE && !(CC_SURFACES_DEBUG_VIEW_COMPOSITE_MODE & CC_SURFACES_DEBUG_VIEW_COMPOSITE_FOG) + fogFactor = 0.0; + #endif + //#uniformStyle + #if CC_SURFACES_USE_DEBUG_VIEW == CC_SURFACES_DEBUG_VIEW_COMPOSITE_AND_MISC + if (cc_debug_view_composite_enable_fog <= 0.0) { + fogFactor = 0.0; + } + #endif + //----------------------------------------------- + #endif + + + // Lighting + LightingResult lightingResult; + CCSurfacesLighting(lightingResult, surfaceData, shadowPos, shadowBias); + + + // Debug view + #if CC_SURFACES_DEBUG_VIEW_MODE + vec4 debugColor = vec4(0.0, 0.0, 0.0, 1.0); + #if !CC_FORWARD_ADD + CCSurfacesDebugViewMeshData(debugColor); + CCSurfacesDebugViewSurfaceData(debugColor, surfaceData); + CCSurfacesDebugViewLightingResult(debugColor, lightingResult); + #if CC_SURFACES_DEBUG_VIEW_MODE == CC_SURFACES_DEBUG_VIEW_FOG + fogFactor = 1.0 - fogFactor; + debugColor = vec4(fogFactor, fogFactor, fogFactor, 1.0); + #endif + #endif + + // only base pass or direct lighting is enabled in add pass + #if !CC_FORWARD_ADD || CC_FORWARD_ADD && (CC_SURFACES_DEBUG_VIEW_MODE == CC_SURFACES_DEBUG_VIEW_DIRECT_DIFFUSE || CC_SURFACES_DEBUG_VIEW_MODE == CC_SURFACES_DEBUG_VIEW_DIRECT_SPECULAR || CC_SURFACES_DEBUG_VIEW_MODE == CC_SURFACES_DEBUG_VIEW_DIRECT_ALL) + CCSurfacesDebugViewLightingResult(debugColor, lightingResult); + #endif + + fragColorX = debugColor; + return; + #elif CC_SURFACES_DEBUG_VIEW_COMPOSITE_MODE + #if !CC_FORWARD_ADD || CC_FORWARD_ADD && ((CC_SURFACES_DEBUG_VIEW_COMPOSITE_MODE & CC_SURFACES_DEBUG_VIEW_COMPOSITE_DIRECT_DIFFUSE) || (CC_SURFACES_DEBUG_VIEW_COMPOSITE_MODE & CC_SURFACES_DEBUG_VIEW_COMPOSITE_DIRECT_SPECULAR)) + CCSurfacesDebugViewCompositeLightingResult(lightingResult); + #endif + #endif + + //#uniformStyle + #if CC_SURFACES_USE_DEBUG_VIEW == CC_SURFACES_DEBUG_VIEW_SINGLE + vec4 debugColor = vec4(0.0, 0.0, 0.0, 1.0); + #if !CC_FORWARD_ADD + CCSurfacesDebugViewMeshData(debugColor); + CCSurfacesDebugViewSurfaceData(debugColor, surfaceData); + CCSurfacesDebugViewLightingResult(debugColor, lightingResult); + if (equalf(cc_debug_view_single_mode, CC_SURFACES_DEBUG_VIEW_FOG)) + { + fogFactor = 1.0 - fogFactor; + debugColor = vec4(fogFactor, fogFactor, fogFactor, 1.0); + } + #endif + + // only base pass or direct lighting is enabled in add pass + #if CC_FORWARD_ADD + if (equalf(cc_debug_view_single_mode, CC_SURFACES_DEBUG_VIEW_DIRECT_DIFFUSE) || equalf(cc_debug_view_single_mode, CC_SURFACES_DEBUG_VIEW_DIRECT_SPECULAR) || equalf(cc_debug_view_single_mode, CC_SURFACES_DEBUG_VIEW_DIRECT_ALL)) + #endif + CCSurfacesDebugViewLightingResult(debugColor, lightingResult); + + fragColorX = debugColor; + return; + #elif CC_SURFACES_USE_DEBUG_VIEW == CC_SURFACES_DEBUG_VIEW_COMPOSITE_AND_MISC + #if CC_FORWARD_ADD + if(cc_debug_view_composite_enable_direct_diffuse > 0.0 || cc_debug_view_composite_enable_direct_specular > 0.0) + #endif + CCSurfacesDebugViewCompositeLightingResult(lightingResult); + #endif + //----------------------------------------------- + + // Shading and output + vec4 color = CCSurfacesShading(surfaceData, lightingResult); + + #if !CC_FORWARD_ADD + CC_APPLY_FOG_BASE(color, fogFactor); + #endif + + /* + // CSM Debug + #if CC_SURFACES_DEBUG_VIEW_MISC_ENABLE_CSM_LAYER_COLORATION + color.rgb *= colDebugCSMLayer.rgb; + #endif + + // Color output + #if CC_USE_HDR + #if !CC_SURFACES_DEBUG_VIEW_COMPOSITE_MODE || (CC_SURFACES_DEBUG_VIEW_COMPOSITE_MODE & CC_SURFACES_DEBUG_VIEW_COMPOSITE_TONE_MAPPING) + color.rgb = ACESToneMap(color.rgb); + #endif + #endif + #if !CC_SURFACES_DEBUG_VIEW_COMPOSITE_MODE || (CC_SURFACES_DEBUG_VIEW_COMPOSITE_MODE & CC_SURFACES_DEBUG_VIEW_COMPOSITE_GAMMA_CORRECTION) + color.rgb = LinearToSRGB(color.rgb); + #endif + */ + //#uniformStyle + // CSM Debug + #if CC_SURFACES_USE_DEBUG_VIEW == CC_SURFACES_DEBUG_VIEW_COMPOSITE_AND_MISC + if (cc_debug_view_misc_enable_csm_layer_coloration > 0.0) { + color.rgb *= colDebugCSMLayer.rgb; + } + #endif + + #if CC_USE_HDR + #if CC_SURFACES_USE_DEBUG_VIEW == CC_SURFACES_DEBUG_VIEW_COMPOSITE_AND_MISC + if (cc_debug_view_composite_enable_tone_mapping > 0.0) + #endif + color.rgb = ACESToneMap(color.rgb); + #endif + #if CC_SURFACES_USE_DEBUG_VIEW == CC_SURFACES_DEBUG_VIEW_COMPOSITE_AND_MISC + if (cc_debug_view_composite_enable_gamma_correction > 0.0) + #endif + color.rgb = LinearToSRGB(color.rgb); + //----------------------------------------------- + + CCSurfacesDebugDisplayInvalidNumber(color); +#endif + + fragColorX = color; +} diff --git a/editor/assets/chunks/shading-entries/main-functions/render-to-scene/pipeline/forward-fs.chunk.meta b/editor/assets/chunks/shading-entries/main-functions/render-to-scene/pipeline/forward-fs.chunk.meta new file mode 100644 index 0000000000..aa263fd2cf --- /dev/null +++ b/editor/assets/chunks/shading-entries/main-functions/render-to-scene/pipeline/forward-fs.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "349a2be0-c8d3-420c-9dd1-bf86e01a7055", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/shading-entries/main-functions/render-to-scene/vs.chunk b/editor/assets/chunks/shading-entries/main-functions/render-to-scene/vs.chunk new file mode 100644 index 0000000000..6d9239e75d --- /dev/null +++ b/editor/assets/chunks/shading-entries/main-functions/render-to-scene/vs.chunk @@ -0,0 +1,32 @@ +void main() +{ + SurfacesStandardVertexIntermediate In; + + // Local Space + CCSurfacesVertexInput(In); + CCSurfacesVertexAnimation(In); + In.position.xyz = SurfacesVertexModifyLocalPos(In); + + // World Space + CCSurfacesVertexWorldTransform(In); + In.worldPos = SurfacesVertexModifyWorldPos(In); + + // Clip Space + In.clipPos = cc_matProj * cc_matView * vec4(In.worldPos, 1.0); + In.clipPos = SurfacesVertexModifyClipPos(In); + + // Other Surfaces Function + SurfacesVertexModifyUV(In); + + vec3 viewDirect = normalize(cc_cameraPos.xyz - In.worldPos); + In.worldNormal.w = dot(In.worldNormal.xyz, viewDirect) < 0.0 ? -1.0 : 1.0; + In.worldNormal.xyz = SurfacesVertexModifyWorldNormal(In); + + // Other Data + CCSurfacesVertexTransformUV(In); + CCSurfacesVertexTransferFog(In); + CCSurfacesVertexTransferShadow(In); + CCSurfacesVertexTransferLightMapUV(In); + + CCSurfacesVertexOutput(In); +} diff --git a/editor/assets/chunks/shading-entries/main-functions/render-to-scene/vs.chunk.meta b/editor/assets/chunks/shading-entries/main-functions/render-to-scene/vs.chunk.meta new file mode 100644 index 0000000000..c64dcbc2aa --- /dev/null +++ b/editor/assets/chunks/shading-entries/main-functions/render-to-scene/vs.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "4306c0df-b6d6-4733-8a45-c85907f94d29", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/shading-entries/main-functions/render-to-shadowmap.meta b/editor/assets/chunks/shading-entries/main-functions/render-to-shadowmap.meta new file mode 100644 index 0000000000..91f6878c7c --- /dev/null +++ b/editor/assets/chunks/shading-entries/main-functions/render-to-shadowmap.meta @@ -0,0 +1,12 @@ +{ + "ver": "1.1.0", + "importer": "directory", + "imported": true, + "uuid": "f9762a24-4414-4234-82fd-5c6b37f1cb51", + "files": [], + "subMetas": {}, + "userData": { + "compressionType": {}, + "isRemoteBundle": {} + } +} diff --git a/editor/assets/chunks/shading-entries/main-functions/render-to-shadowmap/fs.chunk b/editor/assets/chunks/shading-entries/main-functions/render-to-shadowmap/fs.chunk new file mode 100644 index 0000000000..f9df74b7f6 --- /dev/null +++ b/editor/assets/chunks/shading-entries/main-functions/render-to-shadowmap/fs.chunk @@ -0,0 +1,23 @@ + in float v_clip_depth; + + layout(location = 0) out vec4 fragColorX; + + void main () { + // for alpha clip + SurfacesFragmentModifyBaseColorAndTransparency(); + + // spot use linear + if(cc_shadowLPNNInfo.x > EPSILON && cc_shadowLPNNInfo.x < 1.999999) { + // enabled linear depth + if (cc_shadowNFLSInfo.z > EPSILON) { + fragColorX = vec4(CCGetLinearDepth(FSInput_worldPos.xyz), 1.0, 1.0, 1.0); + return; + } + } + + if (cc_shadowLPNNInfo.y > EPSILON) { + fragColorX = packDepthToRGBA(v_clip_depth); + } else { + fragColorX = vec4(v_clip_depth, 1.0, 1.0, 1.0); + } + } \ No newline at end of file diff --git a/editor/assets/chunks/shading-entries/main-functions/render-to-shadowmap/fs.chunk.meta b/editor/assets/chunks/shading-entries/main-functions/render-to-shadowmap/fs.chunk.meta new file mode 100644 index 0000000000..b1162e9aa6 --- /dev/null +++ b/editor/assets/chunks/shading-entries/main-functions/render-to-shadowmap/fs.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "a734c67a-3ce2-4978-bf57-080d1dfbbb43", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/shading-entries/main-functions/render-to-shadowmap/vs.chunk b/editor/assets/chunks/shading-entries/main-functions/render-to-shadowmap/vs.chunk new file mode 100644 index 0000000000..9122256bb6 --- /dev/null +++ b/editor/assets/chunks/shading-entries/main-functions/render-to-shadowmap/vs.chunk @@ -0,0 +1,33 @@ +#include +#include + +out float v_clip_depth; + +void main() +{ + SurfacesStandardVertexIntermediate In; + + // Local Space + CCSurfacesVertexInput(In); + CCSurfacesVertexAnimation(In); + In.position.xyz = SurfacesVertexModifyLocalPos(In); + + // World Space + CCSurfacesVertexWorldTransform(In); + In.worldPos = SurfacesVertexModifyWorldPos(In); + + // Clip Space + In.clipPos = cc_matLightViewProj * vec4(In.worldPos, 1.0); + In.clipPos = SurfacesVertexModifyClipPos(In); + + // Other Surfaces Function + SurfacesVertexModifyUV(In); + + // Other Data + CCSurfacesVertexTransformUV(In); + + CCSurfacesVertexOutput(In); + + // Depth + v_clip_depth = In.clipPos.z / In.clipPos.w * 0.5 + 0.5; +} diff --git a/editor/assets/chunks/shading-entries/main-functions/render-to-shadowmap/vs.chunk.meta b/editor/assets/chunks/shading-entries/main-functions/render-to-shadowmap/vs.chunk.meta new file mode 100644 index 0000000000..1352797f1f --- /dev/null +++ b/editor/assets/chunks/shading-entries/main-functions/render-to-shadowmap/vs.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "7a668e36-d75e-488d-b47a-52591e07151d", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/shading-standard-additive.chunk.meta b/editor/assets/chunks/shading-standard-additive.chunk.meta index 91bdac4b31..6fd305c7af 100644 --- a/editor/assets/chunks/shading-standard-additive.chunk.meta +++ b/editor/assets/chunks/shading-standard-additive.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "a70c48b7-cf69-4c97-a857-21149cd71200", diff --git a/editor/assets/chunks/shading-standard-base.chunk b/editor/assets/chunks/shading-standard-base.chunk index f438889c48..e82175428a 100644 --- a/editor/assets/chunks/shading-standard-base.chunk +++ b/editor/assets/chunks/shading-standard-base.chunk @@ -124,7 +124,7 @@ vec4 CCStandardShadingBase (StandardSurface s, vec4 shadowPos) { dirlightContrib *= shadow; finalColor *= dirlightContrib; - #if USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD + #if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD if (s.lightmap_test > EPSILON_LOWP) { finalColor = diffuse * s.lightmap.rgb * shadow; } diff --git a/editor/assets/chunks/shading-standard-base.chunk.meta b/editor/assets/chunks/shading-standard-base.chunk.meta index 3585f00cd2..4bc9d740c5 100644 --- a/editor/assets/chunks/shading-standard-base.chunk.meta +++ b/editor/assets/chunks/shading-standard-base.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "9ae7cfaf-c5cc-4899-95a5-d6e1215c8964", diff --git a/editor/assets/chunks/shading-standard.chunk.meta b/editor/assets/chunks/shading-standard.chunk.meta index c068df4ee3..90d6765d17 100644 --- a/editor/assets/chunks/shading-standard.chunk.meta +++ b/editor/assets/chunks/shading-standard.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "f9ba1729-bacf-4e62-8c97-0103d940c464", diff --git a/editor/assets/chunks/shading-toon.chunk.meta b/editor/assets/chunks/shading-toon.chunk.meta index 49dc7e3349..1d5796ffff 100644 --- a/editor/assets/chunks/shading-toon.chunk.meta +++ b/editor/assets/chunks/shading-toon.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "bbfd1dfb-8f99-4b68-9aa6-817d5b67096d", diff --git a/editor/assets/chunks/skinning-dqs.chunk.meta b/editor/assets/chunks/skinning-dqs.chunk.meta index 344e7a5a86..4495eb796d 100644 --- a/editor/assets/chunks/skinning-dqs.chunk.meta +++ b/editor/assets/chunks/skinning-dqs.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "207a9764-f20a-4e41-997d-cadd0cdb65fd", diff --git a/editor/assets/chunks/skinning-lbs.chunk.meta b/editor/assets/chunks/skinning-lbs.chunk.meta index 35dc6382e9..a66ddab4bc 100644 --- a/editor/assets/chunks/skinning-lbs.chunk.meta +++ b/editor/assets/chunks/skinning-lbs.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "d875d091-0140-4a00-9517-6810755d394d", diff --git a/editor/assets/chunks/standard-surface-entry.chunk.meta b/editor/assets/chunks/standard-surface-entry.chunk.meta index 0725978f59..e025cf4dc4 100644 --- a/editor/assets/chunks/standard-surface-entry.chunk.meta +++ b/editor/assets/chunks/standard-surface-entry.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "31d0a199-05e2-422c-a019-8139a855841c", diff --git a/editor/assets/chunks/surfaces.meta b/editor/assets/chunks/surfaces.meta new file mode 100644 index 0000000000..c40fdf128b --- /dev/null +++ b/editor/assets/chunks/surfaces.meta @@ -0,0 +1,12 @@ +{ + "ver": "1.1.0", + "importer": "directory", + "imported": true, + "uuid": "a72601dc-aa97-42b1-b08b-89baead303e5", + "files": [], + "subMetas": {}, + "userData": { + "compressionType": {}, + "isRemoteBundle": {} + } +} diff --git a/editor/assets/chunks/surfaces/data-structures.meta b/editor/assets/chunks/surfaces/data-structures.meta new file mode 100644 index 0000000000..afad70e182 --- /dev/null +++ b/editor/assets/chunks/surfaces/data-structures.meta @@ -0,0 +1,12 @@ +{ + "ver": "1.1.0", + "importer": "directory", + "imported": true, + "uuid": "d1b7b36d-4023-435d-9223-6ed39e86dbfb", + "files": [], + "subMetas": {}, + "userData": { + "compressionType": {}, + "isRemoteBundle": {} + } +} diff --git a/editor/assets/chunks/surfaces/data-structures/standard.chunk b/editor/assets/chunks/surfaces/data-structures/standard.chunk new file mode 100644 index 0000000000..62711411f6 --- /dev/null +++ b/editor/assets/chunks/surfaces/data-structures/standard.chunk @@ -0,0 +1,21 @@ +struct SurfacesMaterialData +{ + HIGHP_VALUE_STRUCT_DEFINE(vec3, worldPos); + + vec4 baseColor; + vec3 worldNormal; + vec3 emissive; + + float specularIntensity; + float roughness; + float metallic; + float ao; + + // for advanced PBR + vec3 worldTangent, worldBinormal; +#if CC_SURFACES_LIGHTING_ANISOTROPIC + float anisotropyShape; +#endif + // float transmittanceFactor; + // float sssCurvature; +}; diff --git a/editor/assets/chunks/surfaces/data-structures/standard.chunk.meta b/editor/assets/chunks/surfaces/data-structures/standard.chunk.meta new file mode 100644 index 0000000000..6f0d6deb76 --- /dev/null +++ b/editor/assets/chunks/surfaces/data-structures/standard.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "29b8aed8-f4da-471e-a036-4fffc28868f3", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/surfaces/data-structures/toon.chunk b/editor/assets/chunks/surfaces/data-structures/toon.chunk new file mode 100644 index 0000000000..0fe329c835 --- /dev/null +++ b/editor/assets/chunks/surfaces/data-structures/toon.chunk @@ -0,0 +1,17 @@ +struct SurfacesMaterialData +{ + HIGHP_VALUE_STRUCT_DEFINE(vec3, worldPos); + + vec4 baseColor; + vec4 specular; + vec3 worldNormal; + vec3 emissive; + + vec3 shade1; + vec3 shade2; + float baseStep; + float baseFeather; + float shadeStep; + float shadeFeather; + float shadowCover; +}; diff --git a/editor/assets/chunks/surfaces/data-structures/toon.chunk.meta b/editor/assets/chunks/surfaces/data-structures/toon.chunk.meta new file mode 100644 index 0000000000..0d55495a36 --- /dev/null +++ b/editor/assets/chunks/surfaces/data-structures/toon.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "7ac0dc35-81bc-4b7c-9701-a401747deccf", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/surfaces/default-functions.meta b/editor/assets/chunks/surfaces/default-functions.meta new file mode 100644 index 0000000000..91a74700e7 --- /dev/null +++ b/editor/assets/chunks/surfaces/default-functions.meta @@ -0,0 +1,12 @@ +{ + "ver": "1.1.0", + "importer": "directory", + "imported": true, + "uuid": "eaa476cb-d357-463b-ae54-9807cb10e791", + "files": [], + "subMetas": {}, + "userData": { + "compressionType": {}, + "isRemoteBundle": {} + } +} diff --git a/editor/assets/chunks/surfaces/default-functions/common-vs.chunk b/editor/assets/chunks/surfaces/default-functions/common-vs.chunk new file mode 100644 index 0000000000..f864ee97e4 --- /dev/null +++ b/editor/assets/chunks/surfaces/default-functions/common-vs.chunk @@ -0,0 +1,41 @@ +#ifndef CC_SURFACES_VERTEX_MODIFY_LOCAL_POS +vec3 SurfacesVertexModifyLocalPos(in SurfacesStandardVertexIntermediate In) +{ + return In.position.xyz; +} +#endif + +#ifndef CC_SURFACES_VERTEX_MODIFY_WORLD_POS +vec3 SurfacesVertexModifyWorldPos(in SurfacesStandardVertexIntermediate In) +{ + return In.worldPos; +} +#endif + +#ifndef CC_SURFACES_VERTEX_MODIFY_CLIP_POS +vec4 SurfacesVertexModifyClipPos(in SurfacesStandardVertexIntermediate In) +{ + return In.clipPos; +} +#endif + +#ifndef CC_SURFACES_VERTEX_MODIFY_UV +void SurfacesVertexModifyUV(inout SurfacesStandardVertexIntermediate In) +{ + In.texCoord = In.texCoord; +#if CC_SURFACES_USE_SECOND_UV && !CC_SURFACES_USE_LIGHT_MAP + In.texCoord1 = In.texCoord1; +#endif +} +#endif + +#ifndef CC_SURFACES_VERTEX_MODIFY_WORLD_NORMAL +vec3 SurfacesVertexModifyWorldNormal(in SurfacesStandardVertexIntermediate In) +{ + vec3 worldNormal = In.worldNormal.xyz; + #if CC_SURFACES_USE_TWO_SIDED + worldNormal.xyz *= In.worldNormal.w; + #endif + return worldNormal; +} +#endif diff --git a/editor/assets/chunks/surfaces/default-functions/common-vs.chunk.meta b/editor/assets/chunks/surfaces/default-functions/common-vs.chunk.meta new file mode 100644 index 0000000000..e985640ba4 --- /dev/null +++ b/editor/assets/chunks/surfaces/default-functions/common-vs.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "b3d7cc71-db0a-4f76-a2e1-c145c679180f", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/surfaces/default-functions/standard-fs.chunk b/editor/assets/chunks/surfaces/default-functions/standard-fs.chunk new file mode 100644 index 0000000000..bfcd935630 --- /dev/null +++ b/editor/assets/chunks/surfaces/default-functions/standard-fs.chunk @@ -0,0 +1,62 @@ +#ifndef CC_SURFACES_FRAGMENT_MODIFY_BASECOLOR_AND_TRANSPARENCY +vec4 SurfacesFragmentModifyBaseColorAndTransparency() +{ + return FSInput_vertexColor; +} +#endif + + +#ifndef CC_SURFACES_FRAGMENT_MODIFY_WORLD_NORMAL +vec3 SurfacesFragmentModifyWorldNormal() +{ + return normalize(FSInput_worldNormal); +} +#endif + +#ifndef CC_SURFACES_FRAGMENT_MODIFY_WORLD_TANGENT_AND_BINORMAL +void SurfacesFragmentModifyWorldTangentAndBinormal(inout vec3 worldTangent, inout vec3 worldBinormal, vec3 worldNormal) +{ + vec3 tangent = FSInput_worldTangent; + +#if CC_SURFACES_USE_TANGENT_SPACE + vec3 binormal = normalize(CalculateBinormal(worldNormal.xyz, tangent, FSInput_mirrorNormal)); + tangent = normalize(cross(binormal, worldNormal)); +#else + vec3 binormal = vec3(0.0, 0.0, 0.0); +#endif + + worldTangent = tangent; + worldBinormal = binormal; +} +#endif + +#ifndef CC_SURFACES_FRAGMENT_MODIFY_ANISOTROPY_PARAMS +// rotation, shape, xx, xx +vec4 SurfacesFragmentModifyAnisotropyParams() +{ + return vec4(0.0, 1.0, 0.0, 0.0); +} +#endif + +#ifndef CC_SURFACES_FRAGMENT_MODIFY_EMISSIVE +vec3 SurfacesFragmentModifyEmissive() +{ + return vec3(0.0, 0.0, 0.0); +} +#endif + +#ifndef CC_SURFACES_FRAGMENT_MODIFY_PBRPARAMS +vec4 SurfacesFragmentModifyPBRParams() +{ + // ao, roughness, metallic, ao, specularIntensity + return vec4(1.0, 0.5, 0.0, 0.5); +} +#endif + +// some material datas use shared raw data, avoid sample / calculate same raw data multiply times, use this function for better performance +// this function invokes at last +#ifndef CC_SURFACES_FRAGMENT_MODIFY_SHARED_DATA +void SurfacesFragmentModifySharedData(inout SurfacesMaterialData surfaceData) +{ +} +#endif diff --git a/editor/assets/chunks/surfaces/default-functions/standard-fs.chunk.meta b/editor/assets/chunks/surfaces/default-functions/standard-fs.chunk.meta new file mode 100644 index 0000000000..1be7ce3ca4 --- /dev/null +++ b/editor/assets/chunks/surfaces/default-functions/standard-fs.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "57b9c877-9855-47c0-bb6f-da3a2c19414e", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/surfaces/default-functions/toon-fs.chunk b/editor/assets/chunks/surfaces/default-functions/toon-fs.chunk new file mode 100644 index 0000000000..d37ff7a50d --- /dev/null +++ b/editor/assets/chunks/surfaces/default-functions/toon-fs.chunk @@ -0,0 +1,30 @@ +#include + +#ifndef CC_SURFACES_FRAGMENT_MODIFY_BASECOLOR_AND_TOONSHADE +void SurfacesFragmentModifyBaseColorAndToonShade(out vec4 baseColorAndTransparency, out vec3 shade1, out vec3 shade2, in vec3 baseColor) +{ + baseColorAndTransparency = FSInput_vertexColor; + shade1 = shade2 = vec3(0.0); +} +#endif + +#ifndef CC_SURFACES_FRAGMENT_MODIFY_TOON_STEP_AND_FEATHER +vec4 SurfacesFragmentModifyToonStepAndFeather() +{ + return vec3(0.8, 0.001, 0.5, 0.001); +} +#endif + +#ifndef CC_SURFACES_FRAGMENT_MODIFY_TOON_SHADOW_COVER +float SurfacesFragmentModifyToonShadowCover() +{ + return 0.5; +} +#endif + +#ifndef CC_SURFACES_FRAGMENT_MODIFY_TOON_SPECULAR +vec4 SurfacesFragmentModifyToonSpecular() +{ + return vec4(1.0, 1.0, 1.0, 0.3); +} +#endif diff --git a/editor/assets/chunks/surfaces/default-functions/toon-fs.chunk.meta b/editor/assets/chunks/surfaces/default-functions/toon-fs.chunk.meta new file mode 100644 index 0000000000..512e297a48 --- /dev/null +++ b/editor/assets/chunks/surfaces/default-functions/toon-fs.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "3804c73c-5c8d-42cf-8382-6b64ab2ea7bc", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/surfaces/effect-macros.meta b/editor/assets/chunks/surfaces/effect-macros.meta new file mode 100644 index 0000000000..71beccfb44 --- /dev/null +++ b/editor/assets/chunks/surfaces/effect-macros.meta @@ -0,0 +1,12 @@ +{ + "ver": "1.1.0", + "importer": "directory", + "imported": true, + "uuid": "af5687e7-3bb4-438a-b00e-037a68d72478", + "files": [], + "subMetas": {}, + "userData": { + "compressionType": {}, + "isRemoteBundle": {} + } +} diff --git a/editor/assets/chunks/surfaces/effect-macros/common-macros.chunk b/editor/assets/chunks/surfaces/effect-macros/common-macros.chunk new file mode 100644 index 0000000000..7ba8bfaefc --- /dev/null +++ b/editor/assets/chunks/surfaces/effect-macros/common-macros.chunk @@ -0,0 +1,47 @@ +#pragma define-meta USE_INSTANCING editor(elevated: true) +#pragma define-meta USE_BATCHING editor(elevated: true) +// these two macros must be non-const +// use #pragma define to rename a macro with editor flag +#pragma define CC_SURFACES_USE_INSTANCING USE_INSTANCING +#pragma define CC_SURFACES_USE_BATCHING USE_BATCHING + + + +// all material->internal macros +#ifndef CC_SURFACES_USE_SECOND_UV + #define CC_SURFACES_USE_SECOND_UV 0 +#endif +#ifndef CC_SURFACES_USE_TWO_SIDED + #define CC_SURFACES_USE_TWO_SIDED 0 +#endif +#ifndef CC_SURFACES_USE_REFLECTION_DENOISE + #define CC_SURFACES_USE_REFLECTION_DENOISE 0 +#endif +#ifndef CC_SURFACES_USE_TANGENT_SPACE + #define CC_SURFACES_USE_TANGENT_SPACE 0 +#endif +#ifndef CC_SURFACES_USE_VERTEX_COLOR + #define CC_SURFACES_USE_VERTEX_COLOR 0 +#endif +#ifndef CC_SURFACES_TRANSFER_LOCAL_POS + #define CC_SURFACES_TRANSFER_LOCAL_POS 0 +#endif +#ifndef CC_SURFACES_LIGHTING_ANISOTROPIC + #define CC_SURFACES_LIGHTING_ANISOTROPIC 0 +#endif +#ifndef CC_SURFACES_LIGHTING_ANISOTROPIC_ENVCONVOLUTION_COUNT + #define CC_SURFACES_LIGHTING_ANISOTROPIC_ENVCONVOLUTION_COUNT 0 +#endif +#ifndef CC_SURFACES_USE_LEGACY_COMPATIBLE_LIGHTING + #define CC_SURFACES_USE_LEGACY_COMPATIBLE_LIGHTING 0 +#endif + +#if CC_USE_LIGHTMAP + #ifndef CC_SURFACES_USE_LIGHT_MAP + #define CC_SURFACES_USE_LIGHT_MAP 1 + #endif +#else + #ifndef CC_SURFACES_USE_LIGHT_MAP + #define CC_SURFACES_USE_LIGHT_MAP 0 + #endif +#endif diff --git a/editor/assets/chunks/surfaces/effect-macros/common-macros.chunk.meta b/editor/assets/chunks/surfaces/effect-macros/common-macros.chunk.meta new file mode 100644 index 0000000000..0cb228dd0f --- /dev/null +++ b/editor/assets/chunks/surfaces/effect-macros/common-macros.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "5fb14bc4-12ef-4b8f-b2d2-e0a7df233e31", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/surfaces/effect-macros/render-to-shadowmap.chunk b/editor/assets/chunks/surfaces/effect-macros/render-to-shadowmap.chunk new file mode 100644 index 0000000000..4c63ef3378 --- /dev/null +++ b/editor/assets/chunks/surfaces/effect-macros/render-to-shadowmap.chunk @@ -0,0 +1,12 @@ +// Copyright (c) 2017-2022 Xiamen Yaji Software Co., Ltd. + +// Rename some user macros to surface internal macros + +#define CC_SURFACES_USE_TANGENT_SPACE 0 +#define CC_SURFACES_USE_VERTEX_COLOR 0 +#define CC_SURFACES_USE_SECOND_UV 0 +#define CC_SURFACES_USE_TWO_SIDED 0 +#define CC_SURFACES_USE_REFLECTION_DENOISE 0 +#define CC_SURFACES_USE_LIGHT_MAP 0 + +#include diff --git a/editor/assets/chunks/surfaces/effect-macros/render-to-shadowmap.chunk.meta b/editor/assets/chunks/surfaces/effect-macros/render-to-shadowmap.chunk.meta new file mode 100644 index 0000000000..bbf168369e --- /dev/null +++ b/editor/assets/chunks/surfaces/effect-macros/render-to-shadowmap.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "f66020b7-1a8a-424a-abf4-a8cbe80e410f", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/surfaces/effect-macros/silhouette-edge.chunk b/editor/assets/chunks/surfaces/effect-macros/silhouette-edge.chunk new file mode 100644 index 0000000000..4c63ef3378 --- /dev/null +++ b/editor/assets/chunks/surfaces/effect-macros/silhouette-edge.chunk @@ -0,0 +1,12 @@ +// Copyright (c) 2017-2022 Xiamen Yaji Software Co., Ltd. + +// Rename some user macros to surface internal macros + +#define CC_SURFACES_USE_TANGENT_SPACE 0 +#define CC_SURFACES_USE_VERTEX_COLOR 0 +#define CC_SURFACES_USE_SECOND_UV 0 +#define CC_SURFACES_USE_TWO_SIDED 0 +#define CC_SURFACES_USE_REFLECTION_DENOISE 0 +#define CC_SURFACES_USE_LIGHT_MAP 0 + +#include diff --git a/editor/assets/chunks/surfaces/effect-macros/silhouette-edge.chunk.meta b/editor/assets/chunks/surfaces/effect-macros/silhouette-edge.chunk.meta new file mode 100644 index 0000000000..bccfa19912 --- /dev/null +++ b/editor/assets/chunks/surfaces/effect-macros/silhouette-edge.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "2f746ff4-a6d3-41ec-bcd7-52c8283f3a57", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/surfaces/effect-macros/terrain.chunk b/editor/assets/chunks/surfaces/effect-macros/terrain.chunk new file mode 100644 index 0000000000..f2f988a30c --- /dev/null +++ b/editor/assets/chunks/surfaces/effect-macros/terrain.chunk @@ -0,0 +1,23 @@ +// Copyright (c) 2017-2022 Xiamen Yaji Software Co., Ltd. + +// Rename some user macros to surface internal macros + +#pragma define-meta USE_NORMAL_MAP +#define CC_SURFACES_USE_TANGENT_SPACE USE_NORMAL_MAP + +#define CC_SURFACES_USE_VERTEX_COLOR 0 +#define CC_SURFACES_USE_SECOND_UV 0 +#define CC_SURFACES_USE_TWO_SIDED 0 + +#define CC_SURFACES_USE_LIGHT_MAP CC_USE_LIGHTMAP + +// vs-fs varing addon data +#define CC_SURFACES_TRANSFER_LOCAL_POS 1 + +#if USE_REFLECTION_DENOISE + #define CC_SURFACES_USE_REFLECTION_DENOISE USE_REFLECTION_DENOISE +#else + #define CC_SURFACES_USE_REFLECTION_DENOISE 0 +#endif + +#include diff --git a/editor/assets/chunks/surfaces/effect-macros/terrain.chunk.meta b/editor/assets/chunks/surfaces/effect-macros/terrain.chunk.meta new file mode 100644 index 0000000000..0cb64b9490 --- /dev/null +++ b/editor/assets/chunks/surfaces/effect-macros/terrain.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "1de87047-07ab-491a-b418-588ff145eaec", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/surfaces/includes.meta b/editor/assets/chunks/surfaces/includes.meta new file mode 100644 index 0000000000..a5ec2fdb8c --- /dev/null +++ b/editor/assets/chunks/surfaces/includes.meta @@ -0,0 +1,12 @@ +{ + "ver": "1.1.0", + "importer": "directory", + "imported": true, + "uuid": "7e22c0d7-a9df-4194-bdac-acddb43f365b", + "files": [], + "subMetas": {}, + "userData": { + "compressionType": {}, + "isRemoteBundle": {} + } +} diff --git a/editor/assets/chunks/surfaces/includes/common-fs.chunk b/editor/assets/chunks/surfaces/includes/common-fs.chunk new file mode 100644 index 0000000000..cd657cca27 --- /dev/null +++ b/editor/assets/chunks/surfaces/includes/common-fs.chunk @@ -0,0 +1,54 @@ +// defines +//#todo: #10131 Redmi5A = 1 +#pragma define-meta CC_DISABLE_STRUCTURE_IN_FRAGMENT_SHADER range([0, 1]) + +#pragma define CC_PIPELINE_TYPE_FORWARD 0 +#pragma define CC_PIPELINE_TYPE_DEFERRED 1 +#pragma define-meta CC_PIPELINE_TYPE range([0, 1]) +#pragma define-meta CC_FORCE_FORWARD_SHADING + + +// Surface +#include + +// Uniforms--UBO +#include +#if (CC_PIPELINE_TYPE == CC_PIPELINE_TYPE_FORWARD || CC_FORCE_FORWARD_SHADING) + #if CC_FORWARD_ADD + #include + #endif +#endif + +// Uniforms--Tex +#include +#if CC_USE_IBL + #include + #if CC_USE_DIFFUSEMAP + #include + #endif +#endif + +// Base +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// Functional +#include +#include + +#if CC_SURFACES_USE_LIGHT_MAP && !CC_SURFACES_USE_BATCHING && !CC_FORWARD_ADD + #include +#endif + + +// Debug view +#include diff --git a/editor/assets/chunks/surfaces/includes/common-fs.chunk.meta b/editor/assets/chunks/surfaces/includes/common-fs.chunk.meta new file mode 100644 index 0000000000..781864c659 --- /dev/null +++ b/editor/assets/chunks/surfaces/includes/common-fs.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "a6451dbc-fc4c-4a10-84f5-072c6e982fa5", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/surfaces/includes/common-vs.chunk b/editor/assets/chunks/surfaces/includes/common-vs.chunk new file mode 100644 index 0000000000..4561216297 --- /dev/null +++ b/editor/assets/chunks/surfaces/includes/common-vs.chunk @@ -0,0 +1,35 @@ +// Surface +#include +#include +#include + +// UBO +#include +#include + +#if CC_USE_MORPH + #include +#endif +#if CC_USE_SKINNING + #include +#endif + +// Functional +#include +#include + +#if CC_USE_MORPH + #include + //#include +#endif + +#if CC_USE_SKINNING + #include + //#include +#endif + +#if !CC_USE_ACCURATE_FOG + #include +#endif + +#include diff --git a/editor/assets/chunks/surfaces/includes/common-vs.chunk.meta b/editor/assets/chunks/surfaces/includes/common-vs.chunk.meta new file mode 100644 index 0000000000..f989bb4d65 --- /dev/null +++ b/editor/assets/chunks/surfaces/includes/common-vs.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "c66380b2-694f-40bd-afd8-91a2e58d904d", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/surfaces/includes/silhouette-edge-vs.chunk b/editor/assets/chunks/surfaces/includes/silhouette-edge-vs.chunk new file mode 100644 index 0000000000..56e839422a --- /dev/null +++ b/editor/assets/chunks/surfaces/includes/silhouette-edge-vs.chunk @@ -0,0 +1,2 @@ +#include +#include diff --git a/editor/assets/chunks/surfaces/includes/silhouette-edge-vs.chunk.meta b/editor/assets/chunks/surfaces/includes/silhouette-edge-vs.chunk.meta new file mode 100644 index 0000000000..a78f30b757 --- /dev/null +++ b/editor/assets/chunks/surfaces/includes/silhouette-edge-vs.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "6b061492-5e48-4193-b4f0-97f5aacae05d", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/surfaces/includes/standard-fs.chunk b/editor/assets/chunks/surfaces/includes/standard-fs.chunk new file mode 100644 index 0000000000..625767bbb1 --- /dev/null +++ b/editor/assets/chunks/surfaces/includes/standard-fs.chunk @@ -0,0 +1,5 @@ +// Surface includes +#include +#include +#include +#include diff --git a/editor/assets/chunks/surfaces/includes/standard-fs.chunk.meta b/editor/assets/chunks/surfaces/includes/standard-fs.chunk.meta new file mode 100644 index 0000000000..5a2d3620be --- /dev/null +++ b/editor/assets/chunks/surfaces/includes/standard-fs.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "0d0afa06-80d6-45b8-9fa6-6f6ad947c00b", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/surfaces/includes/standard-vs.chunk b/editor/assets/chunks/surfaces/includes/standard-vs.chunk new file mode 100644 index 0000000000..56e839422a --- /dev/null +++ b/editor/assets/chunks/surfaces/includes/standard-vs.chunk @@ -0,0 +1,2 @@ +#include +#include diff --git a/editor/assets/chunks/surfaces/includes/standard-vs.chunk.meta b/editor/assets/chunks/surfaces/includes/standard-vs.chunk.meta new file mode 100644 index 0000000000..2386a48176 --- /dev/null +++ b/editor/assets/chunks/surfaces/includes/standard-vs.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "698b9da6-3f0e-4113-8b1c-5ebc82e3ab3d", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/surfaces/includes/toon-fs.chunk b/editor/assets/chunks/surfaces/includes/toon-fs.chunk new file mode 100644 index 0000000000..221f1ce377 --- /dev/null +++ b/editor/assets/chunks/surfaces/includes/toon-fs.chunk @@ -0,0 +1,5 @@ +// Surface includes +#include +#include +#include +#include diff --git a/editor/assets/chunks/surfaces/includes/toon-fs.chunk.meta b/editor/assets/chunks/surfaces/includes/toon-fs.chunk.meta new file mode 100644 index 0000000000..5c8f4fb252 --- /dev/null +++ b/editor/assets/chunks/surfaces/includes/toon-fs.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "5a2c165c-7d8d-4ed5-9142-52f895dee13c", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/surfaces/includes/toon-vs.chunk b/editor/assets/chunks/surfaces/includes/toon-vs.chunk new file mode 100644 index 0000000000..56e839422a --- /dev/null +++ b/editor/assets/chunks/surfaces/includes/toon-vs.chunk @@ -0,0 +1,2 @@ +#include +#include diff --git a/editor/assets/chunks/surfaces/includes/toon-vs.chunk.meta b/editor/assets/chunks/surfaces/includes/toon-vs.chunk.meta new file mode 100644 index 0000000000..a0ee5cd548 --- /dev/null +++ b/editor/assets/chunks/surfaces/includes/toon-vs.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "ef0e1f2a-454f-4613-959c-3d9da0cae4f8", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/surfaces/module-functions.meta b/editor/assets/chunks/surfaces/module-functions.meta new file mode 100644 index 0000000000..666b1c9b85 --- /dev/null +++ b/editor/assets/chunks/surfaces/module-functions.meta @@ -0,0 +1,12 @@ +{ + "ver": "1.1.0", + "importer": "directory", + "imported": true, + "uuid": "e0dda21b-408d-4e5c-a519-71fad239c854", + "files": [], + "subMetas": {}, + "userData": { + "compressionType": {}, + "isRemoteBundle": {} + } +} diff --git a/editor/assets/chunks/surfaces/module-functions/common-vs.chunk b/editor/assets/chunks/surfaces/module-functions/common-vs.chunk new file mode 100644 index 0000000000..db09fb02ad --- /dev/null +++ b/editor/assets/chunks/surfaces/module-functions/common-vs.chunk @@ -0,0 +1,142 @@ +// IA Input->Intermediate +void CCSurfacesVertexInput(out SurfacesStandardVertexIntermediate In) +{ + In.position = vec4(a_position, 1.0); + In.normal = a_normal; + +#if CC_SURFACES_USE_TANGENT_SPACE + In.tangent = a_tangent; +#endif + +#if CC_SURFACES_USE_VERTEX_COLOR + In.color = a_color; +#endif + + In.texCoord = a_texCoord; +#if CC_SURFACES_USE_SECOND_UV && !CC_SURFACES_USE_LIGHT_MAP + In.texCoord1 = a_texCoord1; +#endif +} + +void CCSurfacesVertexOutput(in SurfacesStandardVertexIntermediate In) +{ + gl_Position = In.clipPos; + VSOutput_worldNormal = In.worldNormal.xyz; + VSOutput_faceSideSign = In.worldNormal.w; + VSOutput_worldPos = In.worldPos; + +#if CC_SURFACES_USE_TANGENT_SPACE + VSOutput_worldTangent = In.worldTangent.xyz; + // VSOutput_worldBitangent = In.worldBinormal; + VSOutput_mirrorNormal = In.tangent.w; +#endif + +#if CC_SURFACES_USE_VERTEX_COLOR + VSOutput_vertexColor = In.color; +#endif + + VSOutput_texcoord = In.texCoord; +#if CC_SURFACES_USE_SECOND_UV && !CC_SURFACES_USE_LIGHT_MAP + VSOutput_texcoord1 = In.texCoord1; +#endif + +#if !CC_USE_ACCURATE_FOG + VSOutput_fogFactor = In.fogFactor; +#endif + +#if CC_RECEIVE_SHADOW + VSOutput_shadowPos = In.shadowPos; + #if CC_SURFACES_USE_INSTANCING + VSOutput_shadowBias = In.shadowBias; + #endif +#endif + +#if CC_SURFACES_USE_LIGHT_MAP && !CC_SURFACES_USE_BATCHING && !CC_FORWARD_ADD + VSOutput_lightMapUV = In.lightmapUV; +#endif + +#if CC_SURFACES_TRANSFER_LOCAL_POS + VSOutput_localPos = In.position; +#endif +} + +// Morph & Skinning +void CCSurfacesVertexAnimation(inout SurfacesStandardVertexIntermediate In) +{ +vec4 temp = vec4(0.0); +#if CC_USE_MORPH + #if CC_SURFACES_USE_TANGENT_SPACE + applyMorph(In.position, In.normal, In.tangent); + #else + applyMorph(In.position, In.normal, temp); + #endif +#endif + +#if CC_USE_SKINNING + #if CC_SURFACES_USE_TANGENT_SPACE + CCSkin(In.position, In.normal, In.tangent); + #else + CCSkin(In.position, In.normal, temp); + #endif +#endif +} + +// Space Transform +void CCSurfacesVertexWorldTransform(inout SurfacesStandardVertexIntermediate In) +{ + mat4 matWorld, matWorldIT; + CCGetWorldMatrixFull(matWorld, matWorldIT); + + In.worldPos = (matWorld * In.position).xyz; + In.worldNormal.xyz = normalize((matWorldIT * vec4(In.normal.xyz, 0.0)).xyz); + + #if CC_SURFACES_USE_TANGENT_SPACE + In.worldTangent = normalize((matWorld * vec4(In.tangent.xyz, 0.0)).xyz); + In.worldBinormal = cross(In.worldNormal.xyz, In.worldTangent) * In.tangent.w; // note the cross order + #endif +} + +void CCSurfacesVertexTransformUV(inout SurfacesStandardVertexIntermediate In) +{ + #if SAMPLE_FROM_RT + CC_HANDLE_RT_SAMPLE_FLIP(In.texCoord); + #if CC_SURFACES_USE_SECOND_UV && !CC_SURFACES_USE_LIGHT_MAP + CC_HANDLE_RT_SAMPLE_FLIP(In.texCoord1); + #endif + #endif +} + +// Shading +void CCSurfacesVertexTransferFog(inout SurfacesStandardVertexIntermediate In) +{ +#if !CC_USE_ACCURATE_FOG + CC_TRANSFER_FOG_BASE(vec4(In.worldPos, 1.0), In.fogFactor); +#endif +} + +void CCSurfacesVertexTransferShadow(inout SurfacesStandardVertexIntermediate In) +{ + #if CC_RECEIVE_SHADOW + In.shadowPos = cc_matLightViewProj * vec4(In.worldPos, 1.0); + + In.shadowBias = vec2(cc_shadowWHPBInfo.w, cc_shadowLPNNInfo.z); + #if CC_SURFACES_USE_INSTANCING + In.shadowBias = vec2(a_localShadowBias.x + cc_shadowWHPBInfo.w, a_localShadowBias.y + cc_shadowLPNNInfo.z); + #elif !CC_SURFACES_USE_BATCHING + In.shadowBias += cc_localShadowBias.xy; + #endif + #endif +} + +void CCSurfacesVertexTransferLightMapUV(inout SurfacesStandardVertexIntermediate In) +{ +#if CC_SURFACES_USE_LIGHT_MAP && !CC_SURFACES_USE_BATCHING && !CC_FORWARD_ADD + #if CC_SURFACES_USE_INSTANCING + In.lightmapUV.xy = a_lightingMapUVParam.xy + a_texCoord1 * a_lightingMapUVParam.z; + In.lightmapUV.z = a_lightingMapUVParam.w; + #else + In.lightmapUV.xy = cc_lightingMapUVParam.xy + a_texCoord1 * cc_lightingMapUVParam.z; + In.lightmapUV.z = cc_lightingMapUVParam.w; + #endif +#endif +} diff --git a/editor/assets/chunks/surfaces/module-functions/common-vs.chunk.meta b/editor/assets/chunks/surfaces/module-functions/common-vs.chunk.meta new file mode 100644 index 0000000000..610b46a392 --- /dev/null +++ b/editor/assets/chunks/surfaces/module-functions/common-vs.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "e1feba3c-c7a2-4208-9c1f-732b7e46abd4", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/surfaces/module-functions/debug-view.chunk b/editor/assets/chunks/surfaces/module-functions/debug-view.chunk new file mode 100644 index 0000000000..efed83483a --- /dev/null +++ b/editor/assets/chunks/surfaces/module-functions/debug-view.chunk @@ -0,0 +1,154 @@ +// make divid-by-zero, non-rational pixel more obvious +void CCSurfacesDebugDisplayInvalidNumber(inout vec4 color) +{ + vec4 error = vec4(1.0, 0.0, 0.2, 1.0); + + color = (isnans(color.rgb) || isinfs(color.rgb)) ? error : color; +} + +#if (CC_SURFACES_DEBUG_VIEW_MODE || CC_SURFACES_USE_DEBUG_VIEW == CC_SURFACES_DEBUG_VIEW_SINGLE) && !CC_FORWARD_ADD + void CCSurfacesDebugViewMeshData(out vec4 color) + { + vec4 white = vec4(1.0, 1.0, 1.0, 1.0); + vec4 black = vec4(0.0, 0.0, 0.0, 1.0); + + // vertex input + #if CC_SURFACES_DEBUG_VIEW_MODE == CC_SURFACES_DEBUG_VIEW_VERTEX_COLOR + #if CC_SURFACES_USE_VERTEX_COLOR + color = FSInput_vertexColor; + #else + color = white; + #endif + #endif + + #if CC_SURFACES_DEBUG_VIEW_MODE == CC_SURFACES_DEBUG_VIEW_VERTEX_NORMAL + color = vec4(FSInput_worldNormal * 0.5 + vec3(0.5), 1.0); + #endif + + #if CC_SURFACES_DEBUG_VIEW_MODE == CC_SURFACES_DEBUG_VIEW_VERTEX_TANGENT + #if CC_SURFACES_USE_TANGENT_SPACE + color = vec4(FSInput_worldTangent * 0.5 + vec3(0.5), 1.0); + #else + color = black; + #endif + #endif + + #if CC_SURFACES_DEBUG_VIEW_MODE == CC_SURFACES_DEBUG_VIEW_VERTEX_MIRROR + #if CC_SURFACES_USE_TANGENT_SPACE + float sign = FSInput_mirrorNormal * 0.5 + 0.5; + color = vec4(sign, sign, sign, 1.0); + #else + color = black; + #endif + #endif + + #if CC_SURFACES_DEBUG_VIEW_MODE == CC_SURFACES_DEBUG_VIEW_FACE_SIDE + float scalar = clamp(FSInput_faceSideSign, 0.0, 1.0); + color = vec4(scalar, scalar, scalar, 1.0); + #endif + + #if CC_SURFACES_DEBUG_VIEW_MODE == CC_SURFACES_DEBUG_VIEW_UV0 + color = vec4(FSInput_texcoord.xy, 0.0, 1.0); + #endif + + #if CC_SURFACES_DEBUG_VIEW_MODE == CC_SURFACES_DEBUG_VIEW_UV1 + color = vec4(FSInput_texcoord1.xy, 0.0, 1.0); + #endif + + #if CC_SURFACES_DEBUG_VIEW_MODE == CC_SURFACES_DEBUG_VIEW_UVLIGHTMAP + #if CC_SURFACES_USE_LIGHT_MAP && !CC_SURFACES_USE_BATCHING && !CC_FORWARD_ADD + color = vec4(FSInput_lightMapUV.xy, 0.0, 1.0); + #else + color = vec4(0.0, 0.0, 0.0, 1.0); + #endif + #endif + + #if CC_SURFACES_DEBUG_VIEW_MODE == CC_SURFACES_DEBUG_VIEW_PROJ_DEPTH + vec4 clipPos = cc_matProj * cc_matView * vec4(FSInput_worldPos.xyz, 1.0); + float depth = clipPos.z / clipPos.w; + color = vec4(depth, depth, depth, 1.0); + #endif + + #if CC_SURFACES_DEBUG_VIEW_MODE == CC_SURFACES_DEBUG_VIEW_LINEAR_DEPTH + vec4 viewPos = cc_matView * vec4(FSInput_worldPos.xyz, 1.0); + float depth = (-viewPos.z - cc_nearFar.x) / cc_nearFar.y; + color = vec4(depth, depth, depth, 1.0); + #endif + + #if CC_SURFACES_DEBUG_VIEW_MODE == CC_SURFACES_DEBUG_VIEW_WORLD_POS + color = vec4(FSInput_worldPos.xyz, 1.0); + #endif + } +#endif + + + +#if CC_SURFACES_DEBUG_VIEW_MODE || CC_SURFACES_USE_DEBUG_VIEW == CC_SURFACES_DEBUG_VIEW_SINGLE + // Lighting related + void CCSurfacesDebugViewLightingResult(out vec4 color, in LightingResult lightingResult) + { + #if CC_SURFACES_DEBUG_VIEW_MODE == CC_SURFACES_DEBUG_VIEW_DIRECT_DIFFUSE + color.rgb = lightingResult.directDiffuse * lightingResult.diffuseColorWithLighting; + #endif + #if CC_SURFACES_DEBUG_VIEW_MODE == CC_SURFACES_DEBUG_VIEW_DIRECT_SPECULAR + color.rgb = lightingResult.directSpecular * lightingResult.specularColorWithLighting; + #endif + #if CC_SURFACES_DEBUG_VIEW_MODE == CC_SURFACES_DEBUG_VIEW_DIRECT_ALL + color.rgb = lightingResult.directDiffuse * lightingResult.diffuseColorWithLighting + lightingResult.directSpecular * lightingResult.specularColorWithLighting; + #endif + #if CC_SURFACES_DEBUG_VIEW_MODE == CC_SURFACES_DEBUG_VIEW_ENV_DIFFUSE + color.rgb = lightingResult.environmentDiffuse * lightingResult.diffuseColorWithLighting; + #endif + #if CC_SURFACES_DEBUG_VIEW_MODE == CC_SURFACES_DEBUG_VIEW_ENV_SPECULAR + color.rgb = lightingResult.environmentSpecular * lightingResult.specularColorWithLighting; + #endif + #if CC_SURFACES_DEBUG_VIEW_MODE == CC_SURFACES_DEBUG_VIEW_ENV_ALL + color.rgb = lightingResult.environmentDiffuse * lightingResult.diffuseColorWithLighting + lightingResult.environmentSpecular * lightingResult.specularColorWithLighting; + #endif + #if CC_SURFACES_DEBUG_VIEW_MODE == CC_SURFACES_DEBUG_VIEW_LIGHT_MAP + color.rgb = lightingResult.lightmapColor; + #endif + #if CC_SURFACES_DEBUG_VIEW_MODE == CC_SURFACES_DEBUG_VIEW_EMISSIVE + color.rgb = lightingResult.emissive; + #endif + #if CC_SURFACES_DEBUG_VIEW_MODE == CC_SURFACES_DEBUG_VIEW_AO + color.rgb = vec3(lightingResult.ao); + #endif + #if CC_SURFACES_DEBUG_VIEW_MODE == CC_SURFACES_DEBUG_VIEW_SHADOW + color.rgb = vec3(lightingResult.shadow); + #endif + } +#endif + + + +#if CC_SURFACES_DEBUG_VIEW_COMPOSITE_MODE || CC_SURFACES_USE_DEBUG_VIEW == CC_SURFACES_DEBUG_VIEW_COMPOSITE_AND_MISC + void CCSurfacesDebugViewCompositeLightingResult(inout LightingResult lightingResult) + { + #if !(CC_SURFACES_DEBUG_VIEW_COMPOSITE_MODE & CC_SURFACES_DEBUG_VIEW_COMPOSITE_DIRECT_DIFFUSE) + lightingResult.directDiffuse = vec3(0.0); + #endif + #if !(CC_SURFACES_DEBUG_VIEW_COMPOSITE_MODE & CC_SURFACES_DEBUG_VIEW_COMPOSITE_DIRECT_SPECULAR) + lightingResult.directSpecular = vec3(0.0); + #endif + #if !(CC_SURFACES_DEBUG_VIEW_COMPOSITE_MODE & CC_SURFACES_DEBUG_VIEW_COMPOSITE_ENV_DIFFUSE) + lightingResult.environmentDiffuse = vec3(0.0); + #endif + #if !(CC_SURFACES_DEBUG_VIEW_COMPOSITE_MODE & CC_SURFACES_DEBUG_VIEW_COMPOSITE_ENV_SPECULAR) + lightingResult.environmentSpecular = vec3(0.0); + #endif + #if !(CC_SURFACES_DEBUG_VIEW_COMPOSITE_MODE & CC_SURFACES_DEBUG_VIEW_COMPOSITE_EMISSIVE) + lightingResult.emissive = vec3(0.0); + #endif + #if !(CC_SURFACES_DEBUG_VIEW_COMPOSITE_MODE & CC_SURFACES_DEBUG_VIEW_COMPOSITE_LIGHT_MAP) + lightingResult.lightmapColor = vec3(0.0); + #endif + #if !(CC_SURFACES_DEBUG_VIEW_COMPOSITE_MODE & CC_SURFACES_DEBUG_VIEW_COMPOSITE_SHADOW) + lightingResult.shadow = 1.0; + #endif + #if !(CC_SURFACES_DEBUG_VIEW_COMPOSITE_MODE & CC_SURFACES_DEBUG_VIEW_COMPOSITE_AO) + lightingResult.ao = 1.0; + #endif + } +#endif + diff --git a/editor/assets/chunks/surfaces/module-functions/debug-view.chunk.meta b/editor/assets/chunks/surfaces/module-functions/debug-view.chunk.meta new file mode 100644 index 0000000000..9feec4dcf8 --- /dev/null +++ b/editor/assets/chunks/surfaces/module-functions/debug-view.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "30961f82-b8ef-4d3b-a9e5-944bb5e103f1", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/surfaces/module-functions/standard-fs.chunk b/editor/assets/chunks/surfaces/module-functions/standard-fs.chunk new file mode 100644 index 0000000000..83b65bddf3 --- /dev/null +++ b/editor/assets/chunks/surfaces/module-functions/standard-fs.chunk @@ -0,0 +1,179 @@ +#include + +// Surface +void CCSurfacesFragmentGetMaterialData(inout SurfacesMaterialData surfaceData) +{ + HIGHP_VALUE_TO_STRUCT_DEFINED(FSInput_worldPos, surfaceData.worldPos); + + surfaceData.baseColor = SurfacesFragmentModifyBaseColorAndTransparency(); + + surfaceData.worldNormal = SurfacesFragmentModifyWorldNormal(); + SurfacesFragmentModifyWorldTangentAndBinormal(surfaceData.worldTangent, surfaceData.worldBinormal, surfaceData.worldNormal); +#if CC_SURFACES_LIGHTING_ANISOTROPIC + vec4 anisotropyParams = SurfacesFragmentModifyAnisotropyParams(); + surfaceData.anisotropyShape = anisotropyParams.y; + RotateTangentAndBinormal(surfaceData.worldTangent, surfaceData.worldBinormal, surfaceData.worldNormal, anisotropyParams.x); +#endif + + surfaceData.emissive = SurfacesFragmentModifyEmissive(); + + vec4 pbr = SurfacesFragmentModifyPBRParams(); + surfaceData.ao = pbr.x; + surfaceData.roughness = pbr.y; + surfaceData.metallic = pbr.z; + surfaceData.specularIntensity = pbr.w; + + SurfacesFragmentModifySharedData(surfaceData); + +#if CC_SURFACES_DEBUG_VIEW_COMPOSITE_MODE && !(CC_SURFACES_DEBUG_VIEW_COMPOSITE_MODE & CC_SURFACES_DEBUG_VIEW_COMPOSITE_NORMAL_MAP) + surfaceData.worldNormal = FSInput_worldNormal; + surfaceData.worldTangent = FSInput_worldTangent; +#endif + +#if (CC_SURFACES_DEBUG_VIEW_MODE || CC_SURFACES_DEBUG_VIEW_COMPOSITE_MODE) && !CC_SURFACES_DEBUG_VIEW_LIGHTING_WITH_ALBEDO + surfaceData.baseColor.rgb = vec3(1.0); +#endif +} + +// Intrinsic function, make connection of material data and lighting data +vec3 CCSurfacesGetDiffuseColor(in SurfacesMaterialData surfaceData) +{ + return surfaceData.baseColor.rgb * (1.0 - surfaceData.metallic); +} +vec3 CCSurfacesGetSpecularColor(in SurfacesMaterialData surfaceData) +{ + float F0 = surfaceData.specularIntensity * 0.08; + return mix(vec3(F0), surfaceData.baseColor.rgb, surfaceData.metallic); +} + +// Diffuse/Specular Color with BRDF lighting preparation +void CCSurfacesLightingInitializeColorWithLighting(inout vec3 diffuseColorWithLighting, inout vec3 specularColorWithLighting, in SurfacesMaterialData surfaceData, in LightingIntermediateData lightingData) +{ + diffuseColorWithLighting = CCSurfacesGetDiffuseColor(surfaceData); + // (Intergrated) GF/4Pi use approximate value for both direct lighting and environment lighting + // accuracy value can be calculated in LightingCalculateDirect/Environment instead of IntegratedGFApprox + specularColorWithLighting = IntegratedGFApprox(CCSurfacesGetSpecularColor(surfaceData).xyz, surfaceData.roughness, lightingData.NoVAbsSat); +} +// Update two colors with BRDF which depend on lights (optional) +void CCSurfacesLightingCalculateColorWithLighting(inout vec3 diffuseColorWithLighting, inout vec3 specularColorWithLighting, in SurfacesMaterialData surfaceData, in LightingIntermediateData lightingData) +{ +} + +// Copy material data to lighting data +// such as tangent data for anisotropic materials +void CCSurfacesInitializeLightingIntermediateData(inout LightingIntermediateData lightingData, in SurfacesMaterialData surfaceData) +{ + vec3 worldPos; + HIGHP_VALUE_FROM_STRUCT_DEFINED(worldPos, surfaceData.worldPos); + CCSurfacesLightingGetIntermediateData_PerPixel(lightingData, surfaceData.worldNormal, worldPos, surfaceData.worldTangent, surfaceData.worldBinormal +#if CC_SURFACES_LIGHTING_ANISOTROPIC + , surfaceData.anisotropyShape +#endif + ); + lightingData.specularParam = surfaceData.roughness; +} +void CCSurfacesLightingCalculateIntermediateData_PerLight(inout LightingIntermediateData lightingData, in SurfacesMaterialData surfaceData, vec3 lightDirWithDist) +{ + CCSurfacesLightingGetIntermediateData_PerLight(lightingData, lightDirWithDist); +} + +// Copy material data to lighting results +void CCSurfacesInitializeLightingResult(inout LightingResult lightingResult, in SurfacesMaterialData surfaceData) +{ + lightingResult.ao = surfaceData.ao; + lightingResult.emissive = surfaceData.emissive; +} + + + +#if CC_PIPELINE_TYPE == CC_PIPELINE_TYPE_DEFERRED + vec4 CCSurfacesDeferredOutput0(in SurfacesMaterialData surfaceData) + { + return surfaceData.baseColor; + } + vec4 CCSurfacesDeferredOutput1(in SurfacesMaterialData surfaceData) + { + return vec4(float32x3_to_oct(surfaceData.worldNormal), surfaceData.roughness, surfaceData.metallic); + } + vec4 CCSurfacesDeferredOutput2(in SurfacesMaterialData surfaceData) + { + return vec4(surfaceData.emissive, surfaceData.ao); + } +#endif + + +// Shading +vec4 CCSurfacesShading(in SurfacesMaterialData surfaceData, in LightingResult lightingResult) +{ + vec4 color = vec4(0.0, 0.0, 0.0, surfaceData.baseColor.a); +#if CC_FORWARD_ADD + color.xyz += lightingResult.directDiffuse * lightingResult.diffuseColorWithLighting; + color.xyz += lightingResult.directSpecular * lightingResult.specularColorWithLighting; +#else + #if CC_SURFACES_USE_LIGHT_MAP && !CC_SURFACES_USE_BATCHING && !CC_FORWARD_ADD + float lum = FSInput_lightMapUV.z; + float lightmapCoef = step(lum, EPSILON_LOWP); + #else + float lightmapCoef = 0.0; + #endif + + color.xyz += ( + mix(lightingResult.directDiffuse, lightingResult.lightmapColor, lightmapCoef) * lightingResult.diffuseColorWithLighting + + lightingResult.directSpecular * lightingResult.specularColorWithLighting) + * lightingResult.shadow; + + color.xyz += ( + lightingResult.environmentDiffuse * lightingResult.diffuseColorWithLighting + + lightingResult.environmentSpecular * lightingResult.specularColorWithLighting) + * lightingResult.ao; + + color.xyz += lightingResult.emissive; +#endif + + return color; +} + + +// Debug view +void CCSurfacesDebugViewSurfaceData(out vec4 color, in SurfacesMaterialData surfaceData) +{ + float scalar; +#if CC_SURFACES_DEBUG_VIEW_MODE == CC_SURFACES_DEBUG_VIEW_FRAGMENT_NORMAL + color = vec4(surfaceData.worldNormal * 0.5 + vec3(0.5), 1.0); +#endif +#if CC_SURFACES_DEBUG_VIEW_MODE == CC_SURFACES_DEBUG_VIEW_FRAGMENT_TANGENT + color = vec4(surfaceData.worldTangent * 0.5 + vec3(0.5), 1.0); +#endif +#if CC_SURFACES_DEBUG_VIEW_MODE == CC_SURFACES_DEBUG_VIEW_FRAGMENT_BINORMAL + color = vec4(surfaceData.worldBinormal * 0.5 + vec3(0.5), 1.0); +#endif +#if CC_SURFACES_DEBUG_VIEW_MODE == CC_SURFACES_DEBUG_VIEW_TRANSPARENCY + scalar = surfaceData.baseColor.a; + color = vec4(scalar, scalar, scalar, 1.0); +#endif +#if CC_SURFACES_DEBUG_VIEW_MODE == CC_SURFACES_DEBUG_VIEW_BASE_COLOR + color = vec4(SRGBToLinear(surfaceData.baseColor.rgb), 1.0); +#endif +#if CC_SURFACES_DEBUG_VIEW_MODE == CC_SURFACES_DEBUG_VIEW_DIFFUSE_COLOR + color = vec4(SRGBToLinear(CCSurfacesGetDiffuseColor(surfaceData)), 1.0); +#endif +#if CC_SURFACES_DEBUG_VIEW_MODE == CC_SURFACES_DEBUG_VIEW_SPECULAR_COLOR + color = vec4(SRGBToLinear(CCSurfacesGetSpecularColor(surfaceData)), 1.0); +#endif +#if CC_SURFACES_DEBUG_VIEW_MODE == CC_SURFACES_DEBUG_VIEW_ROUGHNESS + scalar = surfaceData.roughness; + color = vec4(scalar, scalar, scalar, 1.0); +#endif +#if CC_SURFACES_DEBUG_VIEW_MODE == CC_SURFACES_DEBUG_VIEW_METALLIC + scalar = surfaceData.metallic; + color = vec4(scalar, scalar, scalar, 1.0); +#endif +#if CC_SURFACES_DEBUG_VIEW_MODE == CC_SURFACES_DEBUG_VIEW_SPECULAR_INTENSITY + scalar = surfaceData.specularIntensity; + color = vec4(scalar, scalar, scalar, 1.0); +#endif +} + + +// lighting flow module-function used by this material +#include diff --git a/editor/assets/chunks/surfaces/module-functions/standard-fs.chunk.meta b/editor/assets/chunks/surfaces/module-functions/standard-fs.chunk.meta new file mode 100644 index 0000000000..6faa52c0d9 --- /dev/null +++ b/editor/assets/chunks/surfaces/module-functions/standard-fs.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "6853f548-fd1c-4a96-94f3-ba6981fbefd4", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/surfaces/module-functions/toon-fs.chunk b/editor/assets/chunks/surfaces/module-functions/toon-fs.chunk new file mode 100644 index 0000000000..7f0df576c2 --- /dev/null +++ b/editor/assets/chunks/surfaces/module-functions/toon-fs.chunk @@ -0,0 +1,155 @@ +// Surface +void CCSurfacesFragmentGetMaterialData(inout SurfacesMaterialData surfaceData) +{ + HIGHP_VALUE_TO_STRUCT_DEFINED(FSInput_worldPos, surfaceData.worldPos); + + // common + surfaceData.worldNormal = SurfacesFragmentModifyWorldNormal(); + + surfaceData.emissive = SurfacesFragmentModifyEmissive(); + + // toon + SurfacesFragmentModifyBaseColorAndToonShade(surfaceData.baseColor, surfaceData.shade1, surfaceData.shade2); + + surfaceData.specular = SurfacesFragmentModifyToonSpecular(); + surfaceData.shadowCover = SurfacesFragmentModifyToonShadowCover(); + + vec4 shaderParams = SurfacesFragmentModifyToonStepAndFeather(); + surfaceData.baseStep = shadeParams.x; + surfaceData.baseFeather = shadeParams.y; + surfaceData.shadeStep = shadeParams.z; + surfaceData.shadeFeather = shadeParams.w; + + SurfacesFragmentModifySharedData(surfaceData); + + +#if CC_SURFACES_DEBUG_VIEW_COMPOSITE_MODE && !(CC_SURFACES_DEBUG_VIEW_COMPOSITE_MODE & CC_SURFACES_DEBUG_VIEW_COMPOSITE_NORMAL_MAP) + surfaceData.worldNormal = FSInput_worldNormal; +#endif + +#if (CC_SURFACES_DEBUG_VIEW_MODE || CC_SURFACES_DEBUG_VIEW_COMPOSITE_MODE) && !CC_SURFACES_DEBUG_VIEW_LIGHTING_WITH_ALBEDO + surfaceData.baseColor.rgb = vec3(1.0); + surfaceData.specular.rgb = vec3(1.0); +#endif +} + +// Intrinsic function +vec3 CCSurfacesGetDiffuseColor(in SurfacesMaterialData surfaceData) +{ + return surfaceData.shade1; +} +vec3 CCSurfacesGetSpecularColor(in SurfacesMaterialData surfaceData) +{ + return surfaceData.specular.xyz; +} +void CCSurfacesLightingInitializeColorWithLighting(inout vec3 diffuseColorWithLighting, inout vec3 specularColorWithLighting, in SurfacesMaterialData surfaceData, in LightingIntermediateData lightingData) +{ + specularColorWithLighting = surfaceData.specular.xyz * surfaceData.baseStep; +} +void CCSurfacesLightingCalculateColorWithLighting(inout vec3 diffuseColorWithLighting, inout vec3 specularColorWithLighting, in SurfacesMaterialData surfaceData, in LightingIntermediateData lightingData) +{ + float NL = 0.5 * lightingData.NoL + 0.5; + + vec3 diffuse = mix(surfaceData.shade1, surfaceData.shade2, + clamp(1.0 + (surfaceData.shadeStep - surfaceData.shadeFeather - NL) / surfaceData.shadeFeather, 0.0, 1.0)); + + diffuse = mix(surfaceData.baseColor.rgb, diffuse, + clamp(1.0 + (surfaceData.baseStep - surfaceData.baseFeather - NL) / surfaceData.baseFeather, 0.0, 1.0)); + + diffuseColorWithLighting = diffuse * surfaceData.baseStep; +} + + +// Copy material data to lighting data +// such as tangent data for anisotropic materials +void CCSurfacesInitializeLightingIntermediateData(inout LightingIntermediateData lightingData, in SurfacesMaterialData surfaceData) +{ + vec3 worldPos; + HIGHP_VALUE_FROM_STRUCT_DEFINED(worldPos, surfaceData.worldPos); + CCSurfacesLightingGetIntermediateData_PerPixel(lightingData, surfaceData.worldNormal, worldPos, vec3(0.0), vec3(0.0)); + lightingData.specularParam = surfaceData.specular.a; +} +void CCSurfacesLightingCalculateIntermediateData_PerLight(inout LightingIntermediateData lightingData, in SurfacesMaterialData surfaceData, vec3 lightDirWithDist) +{ + CCSurfacesLightingGetIntermediateData_PerLight(lightingData, lightDirWithDist); +} + +// Copy material data to lighting results +void CCSurfacesInitializeLightingResult(inout LightingResult lightingResult, in SurfacesMaterialData surfaceData) +{ + lightingResult.emissive = surfaceData.emissive; +} + +// Lighting +#if CC_PIPELINE_TYPE == CC_PIPELINE_TYPE_DEFERRED + vec4 CCSurfacesDeferredOutput0(in SurfacesMaterialData surfaceData) + { + return surfaceData.baseColor; + } + vec4 CCSurfacesDeferredOutput1(in SurfacesMaterialData surfaceData) + { + return vec4(float32x3_to_oct(surfaceData.worldNormal), 0.5, 0.0); + } + vec4 CCSurfacesDeferredOutput2(in SurfacesMaterialData surfaceData) + { + return vec4(surfaceData.emissive, 1.0); + } +#endif + +// Shading +vec4 CCSurfacesShading(in SurfacesMaterialData surfaceData, in LightingResult lightingResult) +{ + vec4 color = vec4(0.0, 0.0, 0.0, surfaceData.baseColor.a); +#if CC_FORWARD_ADD + color.xyz += lightingResult.directDiffuse * lightingResult.diffuseColorWithLighting; + color.xyz += lightingResult.directSpecular * lightingResult.specularColorWithLighting; +#else + float lightmapCoef = 0.0; + + color.xyz += ( + mix(lightingResult.directDiffuse, lightingResult.lightmapColor, lightmapCoef) * lightingResult.diffuseColorWithLighting + + lightingResult.directSpecular * lightingResult.specularColorWithLighting) + * lightingResult.shadow; + + color.xyz += lightingResult.emissive; +#endif + + return color; +} + + +// Debug view +void CCSurfacesDebugViewSurfaceData(out vec4 color, in SurfacesMaterialData surfaceData) +{ + float scalar; +#if CC_SURFACES_DEBUG_VIEW_MODE == CC_SURFACES_DEBUG_VIEW_FRAGMENT_NORMAL + color = vec4(surfaceData.worldNormal * 0.5 + vec3(0.5), 1.0); +#endif +#if CC_SURFACES_DEBUG_VIEW_MODE == CC_SURFACES_DEBUG_VIEW_FRAGMENT_TANGENT + color = vec4(surfaceData.worldTangent * 0.5 + vec3(0.5), 1.0); +#endif +#if CC_SURFACES_DEBUG_VIEW_MODE == CC_SURFACES_DEBUG_VIEW_FRAGMENT_BINORMAL + vec3 binormal = CalculateBinormal(surfaceData.worldNormal.xyz, surfaceData.worldTangent.xyz, FSInput_mirrorNormal); + color = vec4(binormal * 0.5 + vec3(0.5), 1.0); +#endif +#if CC_SURFACES_DEBUG_VIEW_MODE == CC_SURFACES_DEBUG_VIEW_TRANSPARENCY + scalar = surfaceData.baseColor.a; + color = vec4(scalar, scalar, scalar, 1.0); +#endif +#if CC_SURFACES_DEBUG_VIEW_MODE == CC_SURFACES_DEBUG_VIEW_BASE_COLOR + color = vec4(SRGBToLinear(surfaceData.baseColor.rgb), 1.0); +#endif +#if CC_SURFACES_DEBUG_VIEW_MODE == CC_SURFACES_DEBUG_VIEW_DIFFUSE_COLOR + color = vec4(SRGBToLinear(CCSurfacesGetDiffuseColor(surfaceData)), 1.0); +#endif +#if CC_SURFACES_DEBUG_VIEW_MODE == CC_SURFACES_DEBUG_VIEW_SPECULAR_COLOR + color = vec4(SRGBToLinear(CCSurfacesGetSpecularColor(surfaceData)), 1.0); +#endif +#if CC_SURFACES_DEBUG_VIEW_MODE == CC_SURFACES_DEBUG_VIEW_SPECULAR_INTENSITY + scalar = surfaceData.specular.a; + color = vec4(scalar, scalar, scalar, 1.0); +#endif +} + +// lighting flow module-function used by this material +#include diff --git a/editor/assets/chunks/surfaces/module-functions/toon-fs.chunk.meta b/editor/assets/chunks/surfaces/module-functions/toon-fs.chunk.meta new file mode 100644 index 0000000000..a6f4380e5e --- /dev/null +++ b/editor/assets/chunks/surfaces/module-functions/toon-fs.chunk.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.4", + "importer": "effect-header", + "imported": true, + "uuid": "218130cc-7167-4535-b6b8-99807138bb39", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/chunks/texture-lod.chunk.meta b/editor/assets/chunks/texture-lod.chunk.meta index ff25873856..45853d0851 100644 --- a/editor/assets/chunks/texture-lod.chunk.meta +++ b/editor/assets/chunks/texture-lod.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "d26f7be9-ac7f-4dfd-88ee-6657dfe3426e", diff --git a/editor/assets/chunks/transform.chunk.meta b/editor/assets/chunks/transform.chunk.meta index 3bd4f201fd..043f3e1892 100644 --- a/editor/assets/chunks/transform.chunk.meta +++ b/editor/assets/chunks/transform.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "0de81d5f-2a3e-467e-bcf5-84f7828edab6", diff --git a/editor/assets/chunks/unpack.chunk.meta b/editor/assets/chunks/unpack.chunk.meta index 9b4864e042..2313982390 100644 --- a/editor/assets/chunks/unpack.chunk.meta +++ b/editor/assets/chunks/unpack.chunk.meta @@ -1,5 +1,5 @@ { - "ver": "1.0.2", + "ver": "1.0.4", "importer": "effect-header", "imported": true, "uuid": "e3e5d086-acc9-4dd8-98e8-24ac02f547d5", diff --git a/editor/assets/default_file_content/scene-2d b/editor/assets/default_file_content/scene-2d index 6e3d691ad2..3b3ac017bb 100644 --- a/editor/assets/default_file_content/scene-2d +++ b/editor/assets/default_file_content/scene-2d @@ -148,7 +148,7 @@ }, "_depth": 1, "_stencil": 0, - "_clearFlags": 6, + "_clearFlags": 7, "_rect": { "__type__": "cc.Rect", "x": 0, diff --git a/editor/assets/default_file_content/ts-render-pipeline b/editor/assets/default_file_content/ts-render-pipeline index f8dc5951ee..d2991b5f07 100644 --- a/editor/assets/default_file_content/ts-render-pipeline +++ b/editor/assets/default_file_content/ts-render-pipeline @@ -1,7 +1,7 @@ import { _decorator, Component, Node, RenderPipeline } from "cc"; const { ccclass, property } = _decorator; -@ccclass("UnderscoreCaseClassName") +@ccclass("<%UnderscoreCaseClassName%>") export class <%UnderscoreCaseClassName%> extends RenderPipeline { destroy() { diff --git a/editor/assets/effects/builtin-billboard.effect.meta b/editor/assets/effects/builtin-billboard.effect.meta index 5bda6356de..6b5ed2cb86 100644 --- a/editor/assets/effects/builtin-billboard.effect.meta +++ b/editor/assets/effects/builtin-billboard.effect.meta @@ -1,5 +1,5 @@ { - "ver": "1.5.4", + "ver": "1.5.6", "importer": "effect", "imported": true, "uuid": "711ebe11-f673-4cd9-9a83-63c60ba54c5b", diff --git a/editor/assets/effects/builtin-camera-texture.effect.meta b/editor/assets/effects/builtin-camera-texture.effect.meta index 6c8bd1c76f..b4c5d74f2b 100644 --- a/editor/assets/effects/builtin-camera-texture.effect.meta +++ b/editor/assets/effects/builtin-camera-texture.effect.meta @@ -1,5 +1,5 @@ { - "ver": "1.5.4", + "ver": "1.5.6", "importer": "effect", "imported": true, "uuid": "bf4078d6-d2d7-4073-83bb-cd6f1802e880", diff --git a/editor/assets/effects/builtin-clear-stencil.effect.meta b/editor/assets/effects/builtin-clear-stencil.effect.meta index 5341d26897..637a62644d 100644 --- a/editor/assets/effects/builtin-clear-stencil.effect.meta +++ b/editor/assets/effects/builtin-clear-stencil.effect.meta @@ -1,5 +1,5 @@ { - "ver": "1.5.4", + "ver": "1.5.6", "importer": "effect", "imported": true, "uuid": "810e96e4-e456-4468-9b59-f4e8f39732c0", diff --git a/editor/assets/effects/builtin-geometry-renderer.effect.meta b/editor/assets/effects/builtin-geometry-renderer.effect.meta index 203f824cb6..ed85b54beb 100644 --- a/editor/assets/effects/builtin-geometry-renderer.effect.meta +++ b/editor/assets/effects/builtin-geometry-renderer.effect.meta @@ -1,5 +1,5 @@ { - "ver": "1.5.4", + "ver": "1.5.6", "importer": "effect", "imported": true, "uuid": "4bb480dd-8384-4bc9-987f-de67cc53052a", diff --git a/editor/assets/effects/builtin-graphics.effect.meta b/editor/assets/effects/builtin-graphics.effect.meta index 3013df8780..b4e0ba5ecc 100644 --- a/editor/assets/effects/builtin-graphics.effect.meta +++ b/editor/assets/effects/builtin-graphics.effect.meta @@ -1,5 +1,5 @@ { - "ver": "1.5.4", + "ver": "1.5.6", "importer": "effect", "imported": true, "uuid": "1c02ae6f-4492-4915-b8f8-7492a3b1e4cd", diff --git a/editor/assets/effects/builtin-occlusion-query.effect.meta b/editor/assets/effects/builtin-occlusion-query.effect.meta index 62359c7432..cfc859fc47 100644 --- a/editor/assets/effects/builtin-occlusion-query.effect.meta +++ b/editor/assets/effects/builtin-occlusion-query.effect.meta @@ -1,5 +1,5 @@ { - "ver": "1.5.4", + "ver": "1.5.6", "importer": "effect", "imported": true, "uuid": "d9937e59-61fe-4ec6-92ab-7ac5a19c89b0", diff --git a/editor/assets/effects/builtin-particle-gpu.effect.meta b/editor/assets/effects/builtin-particle-gpu.effect.meta index c71ab1b245..6d5aca1330 100644 --- a/editor/assets/effects/builtin-particle-gpu.effect.meta +++ b/editor/assets/effects/builtin-particle-gpu.effect.meta @@ -1,5 +1,5 @@ { - "ver": "1.5.4", + "ver": "1.5.6", "importer": "effect", "imported": true, "uuid": "971bdb23-3ff6-43eb-b422-1c30165a3663", diff --git a/editor/assets/effects/builtin-particle-trail.effect.meta b/editor/assets/effects/builtin-particle-trail.effect.meta index 70b455d6b4..82ee1cdad8 100644 --- a/editor/assets/effects/builtin-particle-trail.effect.meta +++ b/editor/assets/effects/builtin-particle-trail.effect.meta @@ -1,5 +1,5 @@ { - "ver": "1.5.4", + "ver": "1.5.6", "importer": "effect", "imported": true, "uuid": "17debcc3-0a6b-4b8a-b00b-dc58b885581e", diff --git a/editor/assets/effects/builtin-particle.effect.meta b/editor/assets/effects/builtin-particle.effect.meta index 5fd24a8955..541b065de2 100644 --- a/editor/assets/effects/builtin-particle.effect.meta +++ b/editor/assets/effects/builtin-particle.effect.meta @@ -1,5 +1,5 @@ { - "ver": "1.5.4", + "ver": "1.5.6", "importer": "effect", "imported": true, "uuid": "d1346436-ac96-4271-b863-1f4fdead95b0", diff --git a/editor/assets/effects/builtin-reflection-deferred.effect b/editor/assets/effects/builtin-reflection-deferred.effect index 7cd10b759e..6eb877ef8d 100644 --- a/editor/assets/effects/builtin-reflection-deferred.effect +++ b/editor/assets/effects/builtin-reflection-deferred.effect @@ -70,11 +70,11 @@ CCProgram standard-vs %{ out vec3 v_bitangent; #endif - #if HAS_SECOND_UV || USE_LIGHTMAP + #if HAS_SECOND_UV || CC_USE_LIGHTMAP in vec2 a_texCoord1; #endif - #if USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD + #if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD #include #endif @@ -106,7 +106,7 @@ CCProgram standard-vs %{ CC_TRANSFER_FOG(pos); CC_TRANSFER_SHADOW(pos); - #if USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD + #if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD CCLightingMapCaclUV(); #endif @@ -121,7 +121,7 @@ CCProgram standard-fs %{ #include #include #include - #if USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD + #if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD #include #endif @@ -184,7 +184,7 @@ CCProgram standard-fs %{ if (s.albedo.ALPHA_TEST_CHANNEL < albedoScaleAndCutoff.w) discard; #endif - #if USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD + #if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD s.lightmap = texture(cc_lightingMap, v_luv); #endif diff --git a/editor/assets/effects/builtin-reflection-deferred.effect.meta b/editor/assets/effects/builtin-reflection-deferred.effect.meta index e250c20e98..d402380361 100644 --- a/editor/assets/effects/builtin-reflection-deferred.effect.meta +++ b/editor/assets/effects/builtin-reflection-deferred.effect.meta @@ -1,5 +1,5 @@ { - "ver": "1.5.4", + "ver": "1.5.6", "importer": "effect", "imported": true, "uuid": "99498f84-efe6-43a6-a9a7-e6e93eb845c1", diff --git a/editor/assets/effects/builtin-spine.effect.meta b/editor/assets/effects/builtin-spine.effect.meta index 40c8f366a9..2d039228f7 100644 --- a/editor/assets/effects/builtin-spine.effect.meta +++ b/editor/assets/effects/builtin-spine.effect.meta @@ -1,5 +1,5 @@ { - "ver": "1.5.4", + "ver": "1.5.6", "importer": "effect", "imported": true, "uuid": "c27215d8-6835-4b68-bfbb-bdeac6100c04", diff --git a/editor/assets/effects/builtin-sprite.effect.meta b/editor/assets/effects/builtin-sprite.effect.meta index 4813af5d97..18902f2f6a 100644 --- a/editor/assets/effects/builtin-sprite.effect.meta +++ b/editor/assets/effects/builtin-sprite.effect.meta @@ -1,5 +1,5 @@ { - "ver": "1.5.4", + "ver": "1.5.6", "importer": "effect", "imported": true, "uuid": "60f7195c-ec2a-45eb-ba94-8955f60e81d0", diff --git a/editor/assets/effects/builtin-standard.effect b/editor/assets/effects/builtin-standard.effect index e9a2496794..0b38d5320e 100644 --- a/editor/assets/effects/builtin-standard.effect +++ b/editor/assets/effects/builtin-standard.effect @@ -114,11 +114,11 @@ CCProgram standard-vs %{ out mediump vec4 v_tangent; #endif - #if HAS_SECOND_UV || USE_LIGHTMAP + #if HAS_SECOND_UV || CC_USE_LIGHTMAP in vec2 a_texCoord1; #endif - #if USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD + #if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD #include #endif @@ -166,7 +166,7 @@ CCProgram standard-vs %{ CC_TRANSFER_FOG(pos); CC_TRANSFER_SHADOW(pos); - #if USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD + #if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD CCLightingMapCaclUV(); #endif @@ -180,7 +180,7 @@ CCProgram standard-fs %{ #include #include #include - #if USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD + #if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD #include #endif @@ -250,7 +250,7 @@ CCProgram standard-fs %{ if (s.albedo.ALPHA_TEST_CHANNEL < albedoScaleAndCutoff.w) discard; #endif - #if USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD + #if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD vec4 lightColor = texture(cc_lightingMap, v_luv.xy); s.lightmap = lightColor.xyz * v_luv.z; s.lightmap_test = v_luv.z; /*lum*/ @@ -311,7 +311,7 @@ CCProgram shadow-caster-vs %{ #include #include - #if HAS_SECOND_UV || USE_LIGHTMAP + #if HAS_SECOND_UV || CC_USE_LIGHTMAP in vec2 a_texCoord1; #endif diff --git a/editor/assets/effects/builtin-standard.effect.meta b/editor/assets/effects/builtin-standard.effect.meta index 00120e7a51..3f6521ba08 100644 --- a/editor/assets/effects/builtin-standard.effect.meta +++ b/editor/assets/effects/builtin-standard.effect.meta @@ -1,5 +1,5 @@ { - "ver": "1.5.4", + "ver": "1.5.6", "importer": "effect", "imported": true, "uuid": "1baf0fc9-befa-459c-8bdd-af1a450a0319", diff --git a/editor/assets/effects/builtin-terrain.effect b/editor/assets/effects/builtin-terrain.effect index c8086cd409..6ff1eba8d8 100644 --- a/editor/assets/effects/builtin-terrain.effect +++ b/editor/assets/effects/builtin-terrain.effect @@ -89,7 +89,7 @@ CCProgram terrain-vs %{ uv1 = a_position.xz * UVScale.y; uv2 = a_position.xz * UVScale.z; uv3 = a_position.xz * UVScale.w; - #if USE_LIGHTMAP + #if CC_USE_LIGHTMAP luv.xy = lightMapUVParam.xy + a_texCoord * lightMapUVParam.z; luv.z = lightMapUVParam.w; #endif @@ -113,7 +113,7 @@ CCProgram terrain-fs %{ #include #include #include - #if USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD + #if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD #include #endif #pragma define-meta LAYERS range([0, 4]) @@ -264,7 +264,7 @@ CCProgram terrain-fs %{ #endif s.emissive = vec3(0.0, 0.0, 0.0); - #if USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD + #if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD vec4 lightColor = texture(lightMap, luv.xy); s.lightmap = lightColor.xyz * luv.z; s.lightmap_test = luv.z; /*lum*/ diff --git a/editor/assets/effects/builtin-terrain.effect.meta b/editor/assets/effects/builtin-terrain.effect.meta index b3f10e8db8..5c01bc0082 100644 --- a/editor/assets/effects/builtin-terrain.effect.meta +++ b/editor/assets/effects/builtin-terrain.effect.meta @@ -1,5 +1,5 @@ { - "ver": "1.5.4", + "ver": "1.5.6", "importer": "effect", "imported": true, "uuid": "1d08ef62-a503-4ce2-8b9a-46c90873f7d3", diff --git a/editor/assets/effects/builtin-toon.effect.meta b/editor/assets/effects/builtin-toon.effect.meta index ea4bd3e1af..6a77346000 100644 --- a/editor/assets/effects/builtin-toon.effect.meta +++ b/editor/assets/effects/builtin-toon.effect.meta @@ -1,5 +1,5 @@ { - "ver": "1.5.4", + "ver": "1.5.6", "importer": "effect", "imported": true, "uuid": "a7612b54-35e3-4238-a1a9-4a7b54635839", diff --git a/editor/assets/effects/builtin-unlit.effect.meta b/editor/assets/effects/builtin-unlit.effect.meta index 73547a737a..241707a5bf 100644 --- a/editor/assets/effects/builtin-unlit.effect.meta +++ b/editor/assets/effects/builtin-unlit.effect.meta @@ -1,5 +1,5 @@ { - "ver": "1.5.4", + "ver": "1.5.6", "importer": "effect", "imported": true, "uuid": "a3cd009f-0ab0-420d-9278-b9fdab939bbc", diff --git a/editor/assets/effects/builtin-wireframe.effect.meta b/editor/assets/effects/builtin-wireframe.effect.meta index c7cd0afd49..be47067091 100644 --- a/editor/assets/effects/builtin-wireframe.effect.meta +++ b/editor/assets/effects/builtin-wireframe.effect.meta @@ -1,5 +1,5 @@ { - "ver": "1.5.4", + "ver": "1.5.6", "importer": "effect", "imported": true, "uuid": "81127eb0-7556-453c-b147-670782dd5e53", diff --git a/editor/assets/effects/dcc.meta b/editor/assets/effects/dcc.meta new file mode 100644 index 0000000000..c76976d314 --- /dev/null +++ b/editor/assets/effects/dcc.meta @@ -0,0 +1,12 @@ +{ + "ver": "1.1.0", + "importer": "directory", + "imported": true, + "uuid": "7318038e-8127-4c1b-9b93-e809f973ce6c", + "files": [], + "subMetas": {}, + "userData": { + "compressionType": {}, + "isRemoteBundle": {} + } +} diff --git a/editor/assets/effects/dcc/imported-metallic-roughness.effect b/editor/assets/effects/dcc/imported-metallic-roughness.effect new file mode 100644 index 0000000000..1122886ed3 --- /dev/null +++ b/editor/assets/effects/dcc/imported-metallic-roughness.effect @@ -0,0 +1,466 @@ +// Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd. + +CCEffect %{ + techniques: + - name: opaque + passes: + - vert: standard-vs + frag: standard-fs + properties: &props + tilingOffset: { value: [1.0, 1.0, 0.0, 0.0] } + mainColor: { value: [1.0, 1.0, 1.0, 1.0], target: albedo, linear: true, editor: { displayName: BaseColor, type: color } } + mainTexture: { value: grey, target: albedoMap, editor: { displayName: BaseColorMap } } + baseWeightMap: { value: grey } + albedoScale: { value: 1.0, editor: { displayName: BaseWeight } } + roughness: { value: 1.0 } + roughnessMap: { value: grey } + metallic: { value: 1.0 } + metallicMap: { value: grey } + occlusion: { value: 1.0 } + occlusionMap: { value: white } + emissiveScale: { value: 1.0, editor: { displayName: Emissive } } + emissiveScaleMap: { value: grey, editor: { displayName: EmissiveMap } } + emissive: { value: [0.0, 0.0, 0.0, 1.0], linear: true, editor: { displayName: EmissiveColor, type: color} } + emissiveMap: { value: grey, editor: { displayName: EmissiveColorMap } } + alphaSource: { value: 0.0, editor: { slide: true, range: [0, 1.0], step: 0.001 } } + alphaSourceMap: { value: grey, editor: { parent: USE_OPACITY_MAP } } + alphaThreshold: { value: 0.5, target: albedoScaleAndCutoff.w, editor: { parent: USE_ALPHA_TEST, slide: true, range: [0, 1.0], step: 0.001 } } + normalStrength: { value: 1.0, editor: { parent: USE_NORMAL_MAP, slide: true, range: [0, 1.0], step: 0.001 } } + normalMap: { value: normal } + - &forward-add + vert: standard-vs + frag: standard-fs + phase: forward-add + propertyIndex: 0 + embeddedMacros: { CC_FORWARD_ADD: true } + depthStencilState: + depthFunc: equal + depthTest: true + depthWrite: false + blendState: + targets: + - blend: true + blendSrc: one + blendDst: one + blendSrcAlpha: zero + blendDstAlpha: one + - &shadow-caster + vert: shadow-caster-vs:vert + frag: shadow-caster-fs:frag + phase: shadow-caster + propertyIndex: 0 + rasterizerState: + cullMode: front + properties: + tilingOffset: { value: [1.0, 1.0, 0.0, 0.0] } + mainColor: { value: [1.0, 1.0, 1.0, 1.0], target: albedo, editor: { displayName: Albedo, type: color } } + albedoScale: { value: [1.0, 1.0, 1.0], target: albedoScaleAndCutoff.xyz } + alphaThreshold: { value: 0.5, target: albedoScaleAndCutoff.w, editor: { parent: USE_ALPHA_TEST } } + mainTexture: { value: grey, target: albedoMap, editor: { displayName: AlbedoMap } } + - name: transparent + passes: + - vert: standard-vs + frag: standard-fs + embeddedMacros: { CC_FORCE_FORWARD_SHADING: true } + depthStencilState: + depthTest: true + depthWrite: false + blendState: + targets: + - blend: true + blendSrc: src_alpha + blendDst: one_minus_src_alpha + blendDstAlpha: one_minus_src_alpha + properties: *props + - *forward-add + - *shadow-caster +}% + +CCProgram shared-ubos %{ + uniform Constants { + vec4 tilingOffset; + vec4 albedo; + vec4 albedoScaleAndCutoff; + vec4 emissive; + float emissiveScale; + float occlusion; + float roughness; + float metallic; + float normalStrength; + float alphaSource; + float albedoScale; + }; +}% + +CCProgram standard-vs %{ + precision highp float; + #include + #include + #include + #include + #include + #include + #include + + #if USE_VERTEX_COLOR + in vec4 a_color; + out vec4 v_color; + #endif + + out vec3 v_position; + out vec3 v_normal; + out vec2 v_uv; + out vec2 v_uv1; + + #if CC_RECEIVE_SHADOW + out vec2 v_shadowBias; + #endif + + #if USE_NORMAL_MAP + out vec3 v_tangent; + out vec3 v_bitangent; + #endif + + #if HAS_SECOND_UV || CC_USE_LIGHTMAP + in vec2 a_texCoord1; + #endif + + #if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD + #include + #endif + + void main () { + StandardVertInput In; + CCVertInput(In); + + mat4 matWorld, matWorldIT; + CCGetWorldMatrixFull(matWorld, matWorldIT); + + vec4 pos = matWorld * In.position; + + v_position = pos.xyz; + v_normal = normalize((matWorldIT * vec4(In.normal, 0.0)).xyz); + + #if CC_RECEIVE_SHADOW + v_shadowBias = CCGetShadowBias(); + #endif + + #if USE_TWOSIDE + vec3 viewDirect = normalize(cc_cameraPos.xyz - v_position); + v_normal *= dot(v_normal, viewDirect) < 0.0 ? -1.0 : 1.0; + #endif + + #if USE_NORMAL_MAP + v_tangent = normalize((matWorld * vec4(In.tangent.xyz, 0.0)).xyz); + v_bitangent = cross(v_normal, v_tangent) * In.tangent.w; // note the cross order + #endif + + v_uv = a_texCoord * tilingOffset.xy + tilingOffset.zw; + #if SAMPLE_FROM_RT + CC_HANDLE_RT_SAMPLE_FLIP(v_uv); + #endif + #if HAS_SECOND_UV + v_uv1 = a_texCoord1 * tilingOffset.xy + tilingOffset.zw; + #if SAMPLE_FROM_RT + CC_HANDLE_RT_SAMPLE_FLIP(v_uv1); + #endif + #endif + + #if USE_VERTEX_COLOR + v_color = a_color; + #endif + + CC_TRANSFER_FOG(pos); + CC_TRANSFER_SHADOW(pos); + + #if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD + CCLightingMapCaclUV(); + #endif + + gl_Position = cc_matProj * (cc_matView * matWorld) * In.position; + } +}% + +CCProgram standard-fs %{ + precision highp float; + #include + #include + #include + #include + #if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD + #include + #endif + + in vec3 v_position; + in vec2 v_uv; + in vec2 v_uv1; + in vec3 v_normal; + + #if CC_RECEIVE_SHADOW + in vec2 v_shadowBias; + #endif + + #if USE_VERTEX_COLOR + in vec4 v_color; + #endif + + #pragma define-meta TEXTURE_UV options([v_uv, v_uv1]) + + #if USE_ALBEDO_MAP + uniform sampler2D albedoMap; + #endif + + #if USE_WEIGHT_MAP + uniform sampler2D baseWeightMap; + #endif + + #if USE_NORMAL_MAP + in vec3 v_tangent; + in vec3 v_bitangent; + uniform sampler2D normalMap; + #pragma define-meta NORMAL_UV options([v_uv, v_uv1]) + #endif + + #if USE_METALLIC_MAP + #pragma define-meta METALLIC_CHANNEL options([r, g, b, a]) + uniform sampler2D metallicMap; + #endif + + #if USE_ROUGHNESS_MAP + #pragma define-meta ROUGHNESS_CHANNEL options([r, g, b, a]) + uniform sampler2D roughnessMap; + #endif + + #if USE_OCCLUSION_MAP + #pragma define-meta OCCLUSION_CHANNEL options([r, g, b, a]) + uniform sampler2D occlusionMap; + #endif + + #if USE_TRANSPARENCY_MAP + uniform sampler2D transparencyMap; + #endif + + #if USE_TRANSPARENCYCOLOR_MAP + uniform sampler2D transparencyColorMap; + #endif + + #if USE_EMISSIVE_MAP + uniform sampler2D emissiveMap; + #endif + #if USE_EMISSIVESCALE_MAP + uniform sampler2D emissiveScaleMap; + #endif + + #if USE_OPACITY_MAP + #pragma define-meta ALPHA_SOURCE_CHANNEL options([r, g, b, a]) + uniform sampler2D alphaSourceMap; + #endif + + float discolor(vec3 srcColor) { + return dot(GRAY_VECTOR, srcColor); + } + + void surf (out StandardSurface s) { + vec4 baseColor = albedo; + #if USE_VERTEX_COLOR + baseColor.rgb *= SRGBToLinear(v_color.rgb); // use linear + baseColor.a *= v_color.a; + #endif + + #if USE_ALBEDO_MAP + vec4 texColor = texture(albedoMap, TEXTURE_UV); + texColor.rgb = SRGBToLinear(texColor.rgb); + baseColor *= texColor; + #endif + + #if USE_WEIGHT_MAP + vec4 weightColor = texture(baseWeightMap, TEXTURE_UV); + weightColor.rgb = SRGBToLinear(weightColor.rgb); + baseColor.rgb *= weightColor.rgb; + #else + baseColor.rgb *= albedoScale; + #endif + //////////////////////// + float metallicValue = metallic; + #if USE_METALLIC_MAP + vec4 metallicColor = texture(metallicMap, TEXTURE_UV); + metallicValue = discolor(metallicColor.rgb); + #if USE_METALLIC_CHANNEL + metallicColor.rgb = SRGBToLinear(metallicColor.rgb); + metallicValue = metallicColor.METALLIC_CHANNEL; + #endif + #endif + s.metallic = metallicValue; + + float roughnessValue = roughness; + #if USE_ROUGHNESS_MAP + vec4 roughnessColor = texture(roughnessMap, TEXTURE_UV); + roughnessValue = discolor(roughnessColor.rgb); + #if USE_ROUGHNESS_CHANNEL + roughnessColor.rgb = SRGBToLinear(roughnessColor.rgb); + roughnessValue = roughnessColor.ROUGHNESS_CHANNEL; + #endif + #endif + s.roughness = roughnessValue; + + + float occlusionValue = occlusion; + #if USE_OCCLUSION_MAP + vec4 occlusionColor = texture(occlusionMap, TEXTURE_UV); + occlusionValue = discolor(occlusionColor.rgb); + #if USE_OCCLUSION_CHANNEL + occlusionColor.rgb = SRGBToLinear(occlusionColor.rgb); + occlusionValue = occlusionColor.OCCLUSION_CHANNEL; + #endif + #endif + s.occlusion = occlusionValue; + + #if ALPHA_SOURCE_IS_OPACITY + #if USE_OPACITY_MAP + baseColor.a = 1.0 - texture(alphaSourceMap, TEXTURE_UV).ALPHA_SOURCE_CHANNEL; + #else + baseColor.a = 1.0 - alphaSource; + #endif + #else + #if USE_OPACITY_MAP + baseColor.a = texture(alphaSourceMap, TEXTURE_UV).ALPHA_SOURCE_CHANNEL; + #else + baseColor.a = alphaSource; + #endif + #endif + #if USE_ALPHA_TEST + if (baseColor.a < albedoScaleAndCutoff.w) discard; + #endif + ///////////////////////////// + s.albedo = baseColor; + + #if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD + vec4 lightColor = texture(cc_lightingMap, v_luv.xy); + s.lightmap = lightColor.xyz * v_luv.z; + s.lightmap_test = v_luv.z; /*lum*/ + #endif + + s.normal = v_normal; + + #if CC_RECEIVE_SHADOW + s.shadowBias = v_shadowBias; + #endif + + #if USE_NORMAL_MAP + vec3 nmmp = texture(normalMap, NORMAL_UV).xyz - vec3(0.5); + s.normal = + (nmmp.x * normalStrength) * normalize(v_tangent) + + (nmmp.y * normalStrength) * normalize(v_bitangent) + + nmmp.z * normalize(s.normal); + #endif + + HIGHP_VALUE_TO_STRUCT_DEFINED(v_position, s.position); + + s.specularIntensity = 0.5; + + //emissive color + vec3 emissiveColor = emissive.rgb; + #if USE_EMISSIVE_MAP + emissiveColor.rgb = SRGBToLinear(texture(emissiveMap, TEXTURE_UV).rgb); + #endif + //emissive color scale + #if USE_EMISSIVESCALE_MAP + vec4 emissiveScaleColor = texture(emissiveScaleMap, TEXTURE_UV); + emissiveScaleColor.rgb = SRGBToLinear(emissiveScaleColor.rgb); + emissiveColor.rgb *= emissiveScaleColor.rgb; + #else + emissiveColor.rgb *= emissiveScale; + #endif + + s.emissive = emissiveColor.rgb; + } + + CC_STANDARD_SURFACE_ENTRY() +}% + +CCProgram shadow-caster-vs %{ + precision highp float; + #include + #include + #include + #include + #include + #include + + #if HAS_SECOND_UV || CC_USE_LIGHTMAP + in vec2 a_texCoord1; + #endif + + out vec2 v_uv; + out vec2 v_uv1; + out vec4 v_worldPos; + + out float v_clip_depth; + + vec4 vert () { + StandardVertInput In; + CCVertInput(In); + + mat4 matWorld, matWorldIT; + CCGetWorldMatrixFull(matWorld, matWorldIT); + + v_worldPos = matWorld * In.position; + vec4 clipPos = cc_matLightViewProj * v_worldPos; + + v_uv = a_texCoord * tilingOffset.xy + tilingOffset.zw; + #if HAS_SECOND_UV + v_uv1 = a_texCoord1 * tilingOffset.xy + tilingOffset.zw; + #endif + + v_clip_depth = clipPos.z / clipPos.w * 0.5 + 0.5; + + return clipPos; + } +}% + +CCProgram shadow-caster-fs %{ + precision highp float; + #include + #include + #include + + in vec2 v_uv; + in vec2 v_uv1; + in vec4 v_worldPos; + in float v_clip_depth; + + #if USE_ALBEDO_MAP + uniform sampler2D albedoMap; + #pragma define-meta ALBEDO_UV options([v_uv, v_uv1]) + #endif + + #if USE_ALPHA_TEST + #pragma define-meta ALPHA_TEST_CHANNEL options([a, r]) + #endif + + vec4 frag () { + vec4 baseColor = albedo; + + #if USE_ALBEDO_MAP + baseColor *= texture(albedoMap, ALBEDO_UV); + #endif + + #if USE_ALPHA_TEST + if (baseColor.ALPHA_TEST_CHANNEL < albedoScaleAndCutoff.w) discard; + #endif + + // spot use linear + if(cc_shadowLPNNInfo.x > 0.000001 && cc_shadowLPNNInfo.x < 1.999999) { + // enabled linear depth + if (cc_shadowNFLSInfo.z > 0.000001) { + return vec4(CCGetLinearDepth(v_worldPos.xyz), 1.0, 1.0, 1.0); + } + } + + if (cc_shadowLPNNInfo.y > 0.000001) { + return packDepthToRGBA(v_clip_depth); + } + + return vec4(v_clip_depth, 1.0, 1.0, 1.0); + } +}% diff --git a/editor/assets/effects/dcc/imported-metallic-roughness.effect.meta b/editor/assets/effects/dcc/imported-metallic-roughness.effect.meta new file mode 100644 index 0000000000..bf390b2c82 --- /dev/null +++ b/editor/assets/effects/dcc/imported-metallic-roughness.effect.meta @@ -0,0 +1,11 @@ +{ + "ver": "1.5.6", + "importer": "effect", + "imported": true, + "uuid": "2ec11458-f855-4978-b14d-f3ed5cf697fa", + "files": [ + ".json" + ], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/effects/dcc/imported-specular-glossiness.effect b/editor/assets/effects/dcc/imported-specular-glossiness.effect new file mode 100644 index 0000000000..94accbc819 --- /dev/null +++ b/editor/assets/effects/dcc/imported-specular-glossiness.effect @@ -0,0 +1,459 @@ +// Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd. + +CCEffect %{ + techniques: + - name: opaque + passes: + - vert: standard-vs + frag: standard-fs + properties: &props + mainTexture: { value: grey, target: albedoMap, editor: { displayName: DiffuseMap }} + mainColor: { value: [1.0,1.0,1.0,1.0], target: diffuseColor, linear: true, editor: { displayName: DiffuseColor, type: color }} + albedoScale: { value: 1.0, target: diffuseFactor, editor: { displayName: diffuseFactor } } + alphaThreshold: { value: 0.5, target: albedoScaleAndCutoff.w, editor: { parent: USE_ALPHA_TEST } } + emissive: { value: [0.0, 0.0, 0.0, 1.0], linear: true, editor: { type: color } } + emissiveMap: { value: grey } + shininessExponentMap: { value: grey, editor: { parent: '!HAS_EXPORTED_GLOSSINESS' } } + shininessExponent: { value: 100.0, editor: { parent: '!HAS_EXPORTED_GLOSSINESS' } } + specularColor: { value: [0.0,0.0,0.0,0.0], linear: true, editor: { displayName: SpecularColor, type: color }} + specularMap: { value: grey, editor: { parent: '!HAS_EXPORTED_METALLIC' } } + specularFactor: { value: 1.0, editor: { parent: '!HAS_EXPORTED_METALLIC' } } + transparencyMap: { value: grey, editor: { displayName: TransparencyMap} } + transparencyFactor: { value: 0.0 } + tilingOffset: { value: [1.0, 1.0, 0.0, 0.0] } + normalStrength: { value: 1.0, target: normalScale, editor: { displayName: bumpFactor, parent: USE_NORMAL_MAP, slide: true, range: [0, 5.0], step: 0.001 } } + normalMap: { value: normal } + glossiness: { value: 0.0, editor: { parent: HAS_EXPORTED_GLOSSINESS, slide: true, range: [0, 1.0], step: 0.001 }} + metallic: { value: 0.0, editor: { parent: HAS_EXPORTED_METALLIC, slide: true, range: [0, 1.0], step: 0.001 }} + metallicMap: { value: grey, editor: {parent: HAS_EXPORTED_METALLIC } } + - &forward-add + vert: standard-vs + frag: standard-fs + phase: forward-add + propertyIndex: 0 + embeddedMacros: { CC_FORWARD_ADD: true } + depthStencilState: + depthFunc: equal + depthTest: true + depthWrite: false + blendState: + targets: + - blend: true + blendSrc: one + blendDst: one + blendSrcAlpha: zero + blendDstAlpha: one + - &shadow-caster + vert: shadow-caster-vs:vert + frag: shadow-caster-fs:frag + phase: shadow-caster + propertyIndex: 0 + rasterizerState: + cullMode: front + properties: + tilingOffset: { value: [1.0, 1.0, 0.0, 0.0] } + mainColor: { value: [1.0, 1.0, 1.0, 1.0], target: albedo, editor: { displayName: Albedo, type: color } } + albedoScale: { value: [1.0, 1.0, 1.0], target: albedoScaleAndCutoff.xyz } + alphaThreshold: { value: 0.5, target: albedoScaleAndCutoff.w, editor: { parent: USE_ALPHA_TEST } } + mainTexture: { value: grey, target: albedoMap, editor: { displayName: AlbedoMap } } + - name: transparent + passes: + - vert: standard-vs + frag: standard-fs + embeddedMacros: { CC_FORCE_FORWARD_SHADING: true } + depthStencilState: + depthTest: true + depthWrite: false + blendState: + targets: + - blend: true + blendSrc: src_alpha + blendDst: one_minus_src_alpha + blendDstAlpha: one_minus_src_alpha + properties: *props + - *forward-add + - *shadow-caster +}% + +CCProgram shared-ubos %{ + uniform Constants { + vec4 tilingOffset; + vec4 albedo; + vec4 albedoScaleAndCutoff; + + vec4 diffuseColor; + vec4 specularColor; + vec4 emissive; + float alphaThreshold; + float shininessExponent; + float glossiness; + float metallic; + float normalScale; + float transparencyFactor; + float diffuseFactor; + float specularFactor; + }; +}% + +CCProgram standard-vs %{ + precision highp float; + #include + #include + #include + #include + #include + #include + + #if USE_VERTEX_COLOR + in vec4 a_color; + out vec4 v_color; + #endif + + out vec3 v_position; + out vec3 v_normal; + out vec2 v_uv; + out vec2 v_uv1; + + #if USE_NORMAL_MAP + out vec3 v_tangent; + out vec3 v_bitangent; + #endif + + #if HAS_SECOND_UV || CC_USE_LIGHTMAP + in vec2 a_texCoord1; + #endif + + #if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD + #include + #endif + + void main () { + StandardVertInput In; + CCVertInput(In); + + mat4 matWorld, matWorldIT; + CCGetWorldMatrixFull(matWorld, matWorldIT); + + vec4 pos = matWorld * In.position; + + v_position = pos.xyz; + v_normal = normalize((matWorldIT * vec4(In.normal, 0.0)).xyz); + + #if USE_TWOSIDE + vec3 viewDirect = normalize(cc_cameraPos.xyz - v_position); + v_normal *= dot(v_normal, viewDirect) < 0.0 ? -1.0 : 1.0; + #endif + + #if USE_NORMAL_MAP + v_tangent = normalize((matWorld * vec4(In.tangent.xyz, 0.0)).xyz); + v_bitangent = cross(v_normal, v_tangent) * In.tangent.w; // note the cross order + #endif + + v_uv = a_texCoord * tilingOffset.xy + tilingOffset.zw; + + #if HAS_SECOND_UV + v_uv1 = a_texCoord1 * tilingOffset.xy + tilingOffset.zw; + #endif + + #if USE_VERTEX_COLOR + v_color = a_color; + #endif + + CC_TRANSFER_FOG(pos); + CC_TRANSFER_SHADOW(pos); + + #if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD + CCLightingMapCaclUV(); + #endif + + gl_Position = cc_matProj * (cc_matView * matWorld) * In.position; + } +}% + +CCProgram standard-fs %{ + precision highp float; + #include + #include + #include + #include + #if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD + #include + #endif + + in vec3 v_position; + in vec2 v_uv; + in vec2 v_uv1; + in vec3 v_normal; + + + #pragma define-meta TEXTURE_UV options([v_uv, v_uv1]) + #pragma define-meta DCC_APP_NAME range([0, 2]) + #define DCC_APP_AUTODESK 0 + #define DCC_APP_BLENDER 1 + #define DCC_APP_CINEMA4D 2 + + #if USE_SHININESS_MAP + uniform sampler2D shininessExponentMap; + #pragma define-meta GLOSSINESS_MAP_CHANNEL options([r,g,b,a]) + #endif + #if USE_SPECULAR_MAP + uniform sampler2D specularMap; + #endif + #if USE_METALLIC_MAP + uniform sampler2D metallicMap; + #endif + + #if USE_VERTEX_COLOR + in vec4 v_color; + #endif + + #if USE_ALBEDO_MAP + uniform sampler2D albedoMap; + #endif + #if USE_TRANSPARENCY_MAP + uniform sampler2D transparencyMap; + #endif + + #if USE_NORMAL_MAP + in vec3 v_tangent; + in vec3 v_bitangent; + uniform sampler2D normalMap; + #endif + + #if USE_EMISSIVE_MAP + uniform sampler2D emissiveMap; + #endif + +bool GetMetallicAlbedoFromDiffuseSpecularWithoutColor(out float metallic, out vec3 albedo, vec3 diffuse, vec3 specular, float f0 /*= 0.04*/) +{ + float d = max(max(diffuse.x, diffuse.y), diffuse.z); + vec3 normalizedColor = diffuse / (d + (d < EPSILON_LOWP ? EPSILON_LOWP : 0.0)); + normalizedColor = d < EPSILON_LOWP ? specular : normalizedColor; + + float s = max(max(specular.x, specular.y), specular.z); + + float delta = (d + s) * (d + s) - 4.0 * f0 * d; + float deltaSqrt = sqrt(max(0.0, delta)); + // solver + float solverMetallic = (-d - s + 2.0 * f0 + deltaSqrt) / (2.0 * f0); + vec3 solverAlbedo = (d + s) * normalizedColor - vec3(f0 * (1.0 - solverMetallic)); + + bool isValidSolver = delta >= 0.0; + metallic = isValidSolver ? clamp(solverMetallic, 0.0, 1.0) : 0.0; + albedo = isValidSolver ? vec3(max(0.0, solverAlbedo.x), max(0.0, solverAlbedo.y), max(0.0, solverAlbedo.z)) : diffuse; + return isValidSolver; +} + + float discolor(vec3 srcColor) { + return dot(GRAY_VECTOR, srcColor); + } + float convertShininessExponent(float shininessExp) + { + #if DCC_APP_NAME == DCC_APP_BLENDER + // 2-100 + float glossiness = clamp(sqrt(shininessExp) * 0.1/*/10.0*/, 0.0, 0.95); // glossiness=1 may leads to specular disappear + #elif DCC_APP_NAME == DCC_APP_CINEMA4D + // 2-1024 + float glossiness = clamp(log(shininessExp + EPSILON) * 0.1442695 /*/log(2.0)/10.0*/, 0.0, 1.0); + #else // DCC_APP_NAME == DCC_APP_AUTODESK + // 2-1024 + float l2 = clamp(log(shininessExp + EPSILON) * 0.1442695 /*/log(2.0)/10.0*/, 0.0, 1.0); + float glossiness = pow(l2, 0.5); + #endif + return glossiness; + } + float getSpecularIntensityFromRoughness(float roughness) + { + #if DCC_APP_NAME == DCC_APP_BLENDER + float specularIntensityMultiplier = mix(1.0, 5.0, roughness); + #elif DCC_APP_NAME == DCC_APP_CINEMA4D + float specularIntensityMultiplier = mix(1.0, 50.0, roughness); + #else // DCC_APP_NAME == DCC_APP_AUTODESK + float specularIntensityMultiplier = mix(1.0, 20.0, roughness); + #endif + return specularIntensityMultiplier; + } + + vec4 getSpecularColorAndFactor() + { + vec3 inSpecular = specularColor.rgb; + #if USE_SPECULAR_MAP + vec4 specularTex = texture(specularMap, TEXTURE_UV); + specularTex.rgb = SRGBToLinear(specularTex.rgb); + inSpecular = specularTex.rgb; + #endif + return vec4(inSpecular, specularFactor); + } + void surf (out StandardSurface s) { + //diffuse + vec4 baseColor = diffuseColor; + #if USE_VERTEX_COLOR + baseColor.rgb *= SRGBToLinear(v_color.rgb); + baseColor.a *= v_color.a; + #endif + float diffuseScale = diffuseFactor; + #if USE_ALBEDO_MAP + vec4 texColor = texture(albedoMap, TEXTURE_UV); + texColor.rgb = SRGBToLinear(texColor.rgb); + baseColor *= texColor; + diffuseScale = 1.0; + #endif + baseColor.rgb *= diffuseScale; + + #if USE_TRANSPARENCY_MAP + baseColor.a = texture(transparencyMap, TEXTURE_UV).a * transparencyFactor; + #endif + + #if USE_ALPHA_TEST + if (baseColor.a < albedoScaleAndCutoff.w) discard; + #endif + + vec4 specularColorAndFactor = getSpecularColorAndFactor(); + + //glossiness + float inGlossiness = 0.0, inSpecularIntensity = specularColorAndFactor.w; + #if HAS_EXPORTED_GLOSSINESS + inGlossiness = glossiness; + #else + #if USE_SHININESS_MAP + #if GLOSSINESS_MAP_USE_SINGLE_CHANNEL + inGlossiness = 1.0 - texture(shininessExponentMap, TEXTURE_UV).GLOSSINESS_MAP_CHANNEL; + #else + inGlossiness = 1.0 - discolor(texture(shininessExponentMap, TEXTURE_UV).rgb); + #endif + #else + inGlossiness = convertShininessExponent(shininessExponent); + #endif + inSpecularIntensity *= getSpecularIntensityFromRoughness(1.0 - inGlossiness); + #endif + + //metallic + float inMetallic = 0.0; + vec4 albedo = baseColor; + #if HAS_EXPORTED_METALLIC + inMetallic = metallic; + #else + GetMetallicAlbedoFromDiffuseSpecularWithoutColor(inMetallic, albedo.rgb, baseColor.rgb, specularColorAndFactor.rgb, 0.04); + inSpecularIntensity *= inMetallic; //simulate specular color is black + #endif + + s.normal = v_normal; + #if USE_NORMAL_MAP + vec3 nmmp = texture(normalMap, TEXTURE_UV).xyz - vec3(0.5); + s.normal = + (nmmp.x * normalScale) * normalize(v_tangent) + + (nmmp.y * normalScale) * normalize(v_bitangent) + + nmmp.z * normalize(s.normal); + #endif + + HIGHP_VALUE_TO_STRUCT_DEFINED(v_position, s.position); + + s.albedo = albedo; + s.occlusion = 1.0; + s.roughness = 1.0 - inGlossiness; + s.metallic = inMetallic; + s.specularIntensity = inSpecularIntensity * 0.5; + s.emissive = vec3(0.0); + #if USE_EMISSIVE_MAP + s.emissive = texture(emissiveMap, TEXTURE_UV).xyz; + #endif + + #if CC_USE_LIGHTMAP && !USE_BATCHING && !CC_FORWARD_ADD + vec4 lightColor = texture(cc_lightingMap, v_luv.xy); + s.lightmap = lightColor.xyz * v_luv.z; + s.lightmap_test = v_luv.z; /*lum*/ + #endif + } + + CC_STANDARD_SURFACE_ENTRY() +}% + +CCProgram shadow-caster-vs %{ + precision highp float; + #include + #include + #include + #include + + #if HAS_SECOND_UV || CC_USE_LIGHTMAP + in vec2 a_texCoord1; + #endif + + out vec2 v_uv; + out vec2 v_uv1; + out vec4 v_worldPos; + + out float v_clip_depth; + + vec4 vert () { + StandardVertInput In; + CCVertInput(In); + + mat4 matWorld, matWorldIT; + CCGetWorldMatrixFull(matWorld, matWorldIT); + + v_worldPos = matWorld * In.position; + vec4 clipPos = cc_matLightViewProj * v_worldPos; + + v_uv = a_texCoord * tilingOffset.xy + tilingOffset.zw; + #if HAS_SECOND_UV + v_uv1 = a_texCoord1 * tilingOffset.xy + tilingOffset.zw; + #endif + + v_clip_depth = clipPos.z / clipPos.w * 0.5 + 0.5; + + return clipPos; + } +}% + +CCProgram shadow-caster-fs %{ + precision highp float; + #include + #include + #include + + in vec2 v_uv; + in vec2 v_uv1; + in vec4 v_worldPos; + in float v_clip_depth; + + #pragma define-meta TEXTURE_UV options([v_uv, v_uv1]) + + #if USE_ALBEDO_MAP + uniform sampler2D albedoMap; + #endif + + #if USE_TRANSPARENCY_MAP + uniform sampler2D transparencyMap; + #endif + + vec4 frag () { + vec4 baseColor = diffuseColor; + #if USE_ALBEDO_MAP + vec4 texColor = texture(albedoMap, TEXTURE_UV); + baseColor *= texColor; + #endif + + #if USE_TRANSPARENCY_MAP + baseColor.a = texture(transparencyMap, TEXTURE_UV).a * transparencyFactor; + #endif + + #if USE_ALPHA_TEST + if (baseColor.a < albedoScaleAndCutoff.w) discard; + #endif + + // spot use linear + if(cc_shadowLPNNInfo.x > 0.000001 && cc_shadowLPNNInfo.x < 1.999999) { + // enabled linear depth + if (cc_shadowNFLSInfo.z > 0.000001) { + return vec4(CCGetLinearDepth(v_worldPos.xyz), 1.0, 1.0, 1.0); + } + } + + if (cc_shadowLPNNInfo.y > 0.000001) { + return packDepthToRGBA(v_clip_depth); + } + + return vec4(v_clip_depth, 1.0, 1.0, 1.0); + } +}% diff --git a/editor/assets/effects/dcc/imported-specular-glossiness.effect.meta b/editor/assets/effects/dcc/imported-specular-glossiness.effect.meta new file mode 100644 index 0000000000..626fcc68ff --- /dev/null +++ b/editor/assets/effects/dcc/imported-specular-glossiness.effect.meta @@ -0,0 +1,11 @@ +{ + "ver": "1.5.6", + "importer": "effect", + "imported": true, + "uuid": "f648964e-8d32-41fc-9ac9-7a1e714dd17b", + "files": [ + ".json" + ], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/effects/editor/gizmo.effect.meta b/editor/assets/effects/editor/gizmo.effect.meta index 720517c2cc..5905489260 100644 --- a/editor/assets/effects/editor/gizmo.effect.meta +++ b/editor/assets/effects/editor/gizmo.effect.meta @@ -1,5 +1,5 @@ { - "ver": "1.5.4", + "ver": "1.5.6", "importer": "effect", "imported": true, "uuid": "9d6c6bde-2fe2-44ee-883b-909608948b04", diff --git a/editor/assets/effects/editor/grid-2d.effect.meta b/editor/assets/effects/editor/grid-2d.effect.meta index 0b61508b44..6f8ebab825 100644 --- a/editor/assets/effects/editor/grid-2d.effect.meta +++ b/editor/assets/effects/editor/grid-2d.effect.meta @@ -1,5 +1,5 @@ { - "ver": "1.5.4", + "ver": "1.5.6", "importer": "effect", "imported": true, "uuid": "cb2c332a-fa5e-4235-a129-f011634bb7ad", diff --git a/editor/assets/effects/editor/grid-stroke.effect.meta b/editor/assets/effects/editor/grid-stroke.effect.meta index acc664be2f..7930eb612e 100644 --- a/editor/assets/effects/editor/grid-stroke.effect.meta +++ b/editor/assets/effects/editor/grid-stroke.effect.meta @@ -1,5 +1,5 @@ { - "ver": "1.5.4", + "ver": "1.5.6", "importer": "effect", "imported": true, "uuid": "4736e978-c8fa-449f-9cf6-fe0158ded9d7", diff --git a/editor/assets/effects/editor/grid.effect.meta b/editor/assets/effects/editor/grid.effect.meta index 2b8f061431..c360c31ef2 100644 --- a/editor/assets/effects/editor/grid.effect.meta +++ b/editor/assets/effects/editor/grid.effect.meta @@ -1,5 +1,5 @@ { - "ver": "1.5.4", + "ver": "1.5.6", "importer": "effect", "imported": true, "uuid": "ba35f02e-a81c-464c-bfc5-c788328da667", diff --git a/editor/assets/effects/editor/light.effect.meta b/editor/assets/effects/editor/light.effect.meta index 7ad4a5a359..6bfc0a1d63 100644 --- a/editor/assets/effects/editor/light.effect.meta +++ b/editor/assets/effects/editor/light.effect.meta @@ -1,5 +1,5 @@ { - "ver": "1.5.4", + "ver": "1.5.6", "importer": "effect", "imported": true, "uuid": "e4e4cb19-8dd2-450d-ad20-1a818263b8d3", diff --git a/editor/assets/effects/editor/terrain-circle-brush.effect.meta b/editor/assets/effects/editor/terrain-circle-brush.effect.meta index 8c7c73f187..ae9df61cfb 100644 --- a/editor/assets/effects/editor/terrain-circle-brush.effect.meta +++ b/editor/assets/effects/editor/terrain-circle-brush.effect.meta @@ -1,5 +1,5 @@ { - "ver": "1.5.4", + "ver": "1.5.6", "importer": "effect", "imported": true, "uuid": "a3e72674-c38f-4336-a285-1826b1799cd7", diff --git a/editor/assets/effects/editor/terrain-image-brush.effect.meta b/editor/assets/effects/editor/terrain-image-brush.effect.meta index 998366727f..3b63a9f667 100644 --- a/editor/assets/effects/editor/terrain-image-brush.effect.meta +++ b/editor/assets/effects/editor/terrain-image-brush.effect.meta @@ -1,5 +1,5 @@ { - "ver": "1.5.4", + "ver": "1.5.6", "importer": "effect", "imported": true, "uuid": "7a115de7-2d94-4620-8b89-766d7f8cbff9", diff --git a/editor/assets/effects/editor/terrain-select-brush.effect.meta b/editor/assets/effects/editor/terrain-select-brush.effect.meta index 91341ddfc8..42cd7a1ad5 100644 --- a/editor/assets/effects/editor/terrain-select-brush.effect.meta +++ b/editor/assets/effects/editor/terrain-select-brush.effect.meta @@ -1,5 +1,5 @@ { - "ver": "1.5.4", + "ver": "1.5.6", "importer": "effect", "imported": true, "uuid": "9b4d3fa5-89bf-4715-b69a-dbbd1efaf6a5", diff --git a/editor/assets/effects/pipeline/bloom.effect.meta b/editor/assets/effects/pipeline/bloom.effect.meta index ba8ce3c104..a990d89a9c 100644 --- a/editor/assets/effects/pipeline/bloom.effect.meta +++ b/editor/assets/effects/pipeline/bloom.effect.meta @@ -1,5 +1,5 @@ { - "ver": "1.5.4", + "ver": "1.5.6", "importer": "effect", "imported": true, "uuid": "28d6d6b8-3f66-4a73-9795-17a0852ba2d4", diff --git a/editor/assets/effects/pipeline/deferred-lighting.effect.meta b/editor/assets/effects/pipeline/deferred-lighting.effect.meta index 9cbceb645b..5dc2360e80 100644 --- a/editor/assets/effects/pipeline/deferred-lighting.effect.meta +++ b/editor/assets/effects/pipeline/deferred-lighting.effect.meta @@ -1,5 +1,5 @@ { - "ver": "1.5.4", + "ver": "1.5.6", "importer": "effect", "imported": true, "uuid": "5d45aa00-e064-4938-b314-4265f0c2258c", diff --git a/editor/assets/effects/pipeline/planar-shadow.effect.meta b/editor/assets/effects/pipeline/planar-shadow.effect.meta index e4abfa0bbe..d7f371cce6 100644 --- a/editor/assets/effects/pipeline/planar-shadow.effect.meta +++ b/editor/assets/effects/pipeline/planar-shadow.effect.meta @@ -1,5 +1,5 @@ { - "ver": "1.5.4", + "ver": "1.5.6", "importer": "effect", "imported": true, "uuid": "9361fd90-ba52-4f84-aa93-6e878fd576ca", diff --git a/editor/assets/effects/pipeline/post-process.effect.meta b/editor/assets/effects/pipeline/post-process.effect.meta index 50809d9909..d378952062 100644 --- a/editor/assets/effects/pipeline/post-process.effect.meta +++ b/editor/assets/effects/pipeline/post-process.effect.meta @@ -1,5 +1,5 @@ { - "ver": "1.5.4", + "ver": "1.5.6", "importer": "effect", "imported": true, "uuid": "ec8106fe-05bf-4e94-943c-e0d3b7bb5e45", diff --git a/editor/assets/effects/pipeline/skybox.effect.meta b/editor/assets/effects/pipeline/skybox.effect.meta index 2115dc760f..6e1d5345b2 100644 --- a/editor/assets/effects/pipeline/skybox.effect.meta +++ b/editor/assets/effects/pipeline/skybox.effect.meta @@ -1,5 +1,5 @@ { - "ver": "1.5.4", + "ver": "1.5.6", "importer": "effect", "imported": true, "uuid": "511d2633-09a7-4bdd-ac42-f778032124b3", diff --git a/editor/assets/effects/pipeline/smaa.effect.meta b/editor/assets/effects/pipeline/smaa.effect.meta index bb1bc86069..8f2fcfff7b 100644 --- a/editor/assets/effects/pipeline/smaa.effect.meta +++ b/editor/assets/effects/pipeline/smaa.effect.meta @@ -1,5 +1,5 @@ { - "ver": "1.5.4", + "ver": "1.5.6", "importer": "effect", "imported": true, "uuid": "6624c63c-0e3d-4d5f-bd15-a7805b71c521", diff --git a/editor/assets/effects/pipeline/tonemap.effect.meta b/editor/assets/effects/pipeline/tonemap.effect.meta index d4736287c9..41a82e631e 100644 --- a/editor/assets/effects/pipeline/tonemap.effect.meta +++ b/editor/assets/effects/pipeline/tonemap.effect.meta @@ -1,5 +1,5 @@ { - "ver": "1.5.4", + "ver": "1.5.6", "importer": "effect", "imported": true, "uuid": "31b152ff-f689-4082-a292-3eb5a0b33014", diff --git a/editor/assets/effects/surfaces.meta b/editor/assets/effects/surfaces.meta new file mode 100644 index 0000000000..3c19b6aeec --- /dev/null +++ b/editor/assets/effects/surfaces.meta @@ -0,0 +1,12 @@ +{ + "ver": "1.1.0", + "importer": "directory", + "imported": true, + "uuid": "943258e0-bb7e-46a9-8995-31c983e3b692", + "files": [], + "subMetas": {}, + "userData": { + "compressionType": {}, + "isRemoteBundle": {} + } +} diff --git a/editor/assets/effects/surfaces/standard.effect b/editor/assets/effects/surfaces/standard.effect new file mode 100644 index 0000000000..96ea17b9ff --- /dev/null +++ b/editor/assets/effects/surfaces/standard.effect @@ -0,0 +1,335 @@ +// Copyright (c) 2017-2022 Xiamen Yaji Software Co., Ltd. + +CCEffect %{ + techniques: + - name: opaque + passes: + - vert: standard-vs + frag: standard-fs + properties: &props + tilingOffset: { value: [1.0, 1.0, 0.0, 0.0] } + mainColor: { value: [1.0, 1.0, 1.0, 1.0], target: albedo, linear: true, editor: { displayName: Albedo, type: color } } + albedoScale: { value: [1.0, 1.0, 1.0], target: albedoScaleAndCutoff.xyz } + alphaThreshold: { value: 0.5, target: albedoScaleAndCutoff.w, editor: { parent: USE_ALPHA_TEST, slide: true, range: [0, 1.0], step: 0.001 } } + occlusion: { value: 1.0, target: pbrParams.x, editor: { slide: true, range: [0, 1.0], step: 0.001 } } + roughness: { value: 0.8, target: pbrParams.y, editor: { slide: true, range: [0, 1.0], step: 0.001 } } + metallic: { value: 0.6, target: pbrParams.z, editor: { slide: true, range: [0, 1.0], step: 0.001 } } + specularIntensity: { value: 0.5, target: pbrParams.w, editor: { slide: true, range: [0.0, 1.0], step: 0.001 } } + emissive: { value: [0.0, 0.0, 0.0, 1.0], linear: true, editor: { type: color } } + emissiveScale: { value: [1.0, 1.0, 1.0], target: emissiveScaleParam.xyz } + normalStrength: { value: 1.0, target: emissiveScaleParam.w, editor: { parent: USE_NORMAL_MAP, slide: true, range: [0, 5.0], step: 0.001 } } + anisotropyShape: { value: 1.0, target: anisotropyParam.x, editor: { parent: IS_ANISOTROPY, slide : true, range : [0.0, 1.0] , step : 0.0001 } } + anisotropyRotation: { value: 0.0, target: anisotropyParam.y, editor: { parent: IS_ANISOTROPY, slide : true, range : [0, 1.0] , step : 0.0001 } } + mainTexture: { value: grey, target: albedoMap, editor: { displayName: AlbedoMap } } + normalMap: { value: normal } + pbrMap: { value: grey } + metallicRoughnessMap: { value: grey } + occlusionMap: { value: white } + emissiveMap: { value: grey } + anisotropyRotationMap: { value: black, editor : { parent: IS_ANISOTROPY } } + - &forward-add + vert: standard-vs + frag: standard-fs + phase: forward-add + propertyIndex: 0 + embeddedMacros: { CC_FORWARD_ADD: true } + depthStencilState: + depthFunc: equal + depthTest: true + depthWrite: false + blendState: + targets: + - blend: true + blendSrc: one + blendDst: one + blendSrcAlpha: zero + blendDstAlpha: one + - &shadow-caster + vert: shadow-caster-vs + frag: shadow-caster-fs + phase: shadow-caster + propertyIndex: 0 + rasterizerState: + cullMode: front + properties: + tilingOffset: { value: [1.0, 1.0, 0.0, 0.0] } + mainColor: { value: [1.0, 1.0, 1.0, 1.0], target: albedo, editor: { displayName: Albedo, type: color } } + albedoScale: { value: [1.0, 1.0, 1.0], target: albedoScaleAndCutoff.xyz } + alphaThreshold: { value: 0.5, target: albedoScaleAndCutoff.w, editor: { parent: USE_ALPHA_TEST } } + mainTexture: { value: grey, target: albedoMap, editor: { displayName: AlbedoMap } } + - name: transparent + passes: + - vert: standard-vs + frag: standard-fs + embeddedMacros: { CC_FORCE_FORWARD_SHADING: true } + depthStencilState: + depthTest: true + depthWrite: false + blendState: + targets: + - blend: true + blendSrc: src_alpha + blendDst: one_minus_src_alpha + blendDstAlpha: one_minus_src_alpha + properties: *props + - *forward-add + - *shadow-caster +}% + +CCProgram shared-ubos %{ + uniform Constants { + vec4 tilingOffset; + vec4 albedo; + vec4 albedoScaleAndCutoff; + vec4 pbrParams; + vec4 emissive; + vec4 emissiveScaleParam; + vec2 anisotropyParam; + }; +}% + +CCProgram macro-remapping %{ + // ui displayed macros not used in this effect file + #pragma define-meta HAS_SECOND_UV + #pragma define-meta USE_TWOSIDE + #pragma define-meta USE_REFLECTION_DENOISE + #pragma define-meta IS_ANISOTROPY + + #define CC_SURFACES_USE_SECOND_UV HAS_SECOND_UV + #define CC_SURFACES_USE_TWO_SIDED USE_TWOSIDE + #define CC_SURFACES_USE_REFLECTION_DENOISE USE_REFLECTION_DENOISE + #define CC_SURFACES_LIGHTING_ANISOTROPIC IS_ANISOTROPY + + // if disabled, simulate convoluted IBL without convolution + #pragma define-meta USE_COMPATIBLE_LIGHTING + #define CC_SURFACES_USE_LEGACY_COMPATIBLE_LIGHTING USE_COMPATIBLE_LIGHTING + + // ui displayed macros used in this effect file + #define CC_SURFACES_USE_VERTEX_COLOR USE_VERTEX_COLOR +#if IS_ANISOTROPY || USE_NORMAL_MAP + #define CC_SURFACES_USE_TANGENT_SPACE 1 +#endif + + // functionality for each effect + #define CC_SURFACES_LIGHTING_ANISOTROPIC_ENVCONVOLUTION_COUNT 31 +}% + +CCProgram surface-vertex %{ + /*#define CC_SURFACES_VERTEX_MODIFY_WORLD_POS + vec3 SurfacesVertexModifyWorldPos(in SurfacesStandardVertexIntermediate In) + { + vec3 worldPos = In.worldPos; + worldPos.x += sin(cc_time.x * worldPos.z); + worldPos.y += cos(cc_time.x * worldPos.z); + return worldPos; + } + + #define CC_SURFACES_VERTEX_MODIFY_WORLD_NORMAL + vec3 SurfacesVertexModifyWorldNormal(in SurfacesStandardVertexIntermediate In) + { + vec3 worldNormal = In.worldNormal.xyz; + worldNormal.x += sin(cc_time.x * 3.0); + worldNormal.y += cos(cc_time.x * 3.0); + return normalize(worldNormal); + }*/ + + #define CC_SURFACES_VERTEX_MODIFY_UV + void SurfacesVertexModifyUV(inout SurfacesStandardVertexIntermediate In) + { + In.texCoord = In.texCoord * tilingOffset.xy + tilingOffset.zw; + #if CC_SURFACES_USE_SECOND_UV && !CC_SURFACES_USE_LIGHT_MAP + In.texCoord1 = In.texCoord1 * tilingOffset.xy + tilingOffset.zw; + #endif + } +}% + +CCProgram surface-fragment %{ + #if USE_ALBEDO_MAP + uniform sampler2D albedoMap; + #pragma define-meta ALBEDO_UV options([v_uv, v_uv1]) + #endif + #if USE_NORMAL_MAP + uniform sampler2D normalMap; + #pragma define-meta NORMAL_UV options([v_uv, v_uv1]) + #endif + #pragma define-meta DEFAULT_UV options([v_uv, v_uv1]) + #if USE_PBR_MAP + uniform sampler2D pbrMap; + #endif + #if USE_METALLIC_ROUGHNESS_MAP + uniform sampler2D metallicRoughnessMap; + #endif + #if USE_OCCLUSION_MAP + uniform sampler2D occlusionMap; + #endif + #if USE_EMISSIVE_MAP + uniform sampler2D emissiveMap; + #pragma define-meta EMISSIVE_UV options([v_uv, v_uv1]) + #endif + #if IS_ANISOTROPY && USE_ANISOTROPY_ROTATION_MAP + uniform sampler2D anisotropyRotationMap; + #endif + + #pragma define OCCLUSION_CHANNEL r + #pragma define ROUGHNESS_CHANNEL g + #pragma define METALLIC_CHANNEL b + #pragma define SPECULAR_INTENSITY_CHANNEL a + + #if USE_ALPHA_TEST + #pragma define-meta ALPHA_TEST_CHANNEL options([a, r]) + #endif + + + #define CC_SURFACES_FRAGMENT_MODIFY_BASECOLOR_AND_TRANSPARENCY + vec4 SurfacesFragmentModifyBaseColorAndTransparency() + { + vec4 baseColor = albedo; + + #if USE_VERTEX_COLOR + baseColor.rgb *= SRGBToLinear(FSInput_vertexColor.rgb); // use linear + baseColor.a *= FSInput_vertexColor.a; + #endif + + #if USE_ALBEDO_MAP + vec4 texColor = texture(albedoMap, ALBEDO_UV); + texColor.rgb = SRGBToLinear(texColor.rgb); + baseColor *= texColor; + #endif + + #if USE_ALPHA_TEST + if (baseColor.ALPHA_TEST_CHANNEL < albedoScaleAndCutoff.w) discard; + #endif + + baseColor.rgb *= albedoScaleAndCutoff.xyz; + return baseColor; + } + + + #define CC_SURFACES_FRAGMENT_MODIFY_WORLD_NORMAL + vec3 SurfacesFragmentModifyWorldNormal() + { + vec3 normal = FSInput_worldNormal; + #if USE_NORMAL_MAP + vec3 nmmp = texture(normalMap, NORMAL_UV).xyz - vec3(0.5); + normal = CalculateNormalFromTangentSpace(nmmp, emissiveScaleParam.w, normal.xyz, FSInput_worldTangent, FSInput_mirrorNormal); + #endif + + return normalize(normal); + } + + #define CC_SURFACES_FRAGMENT_MODIFY_ANISOTROPY_PARAMS + vec4 SurfacesFragmentModifyAnisotropyParams() + { + float anisotropyRotation = anisotropyParam.y; + float anisotropyShape = anisotropyParam.x; +#if IS_ANISOTROPY && USE_ANISOTROPY_ROTATION_MAP + anisotropyRotation = fract(anisotropyRotation + texture(anisotropyRotationMap, DEFAULT_UV).x); +#endif + return vec4(anisotropyRotation, anisotropyShape, 0.0, 0.0); + } + + #define CC_SURFACES_FRAGMENT_MODIFY_EMISSIVE + vec3 SurfacesFragmentModifyEmissive() + { + vec3 emissive = emissive.rgb * emissiveScaleParam.xyz; + #if USE_EMISSIVE_MAP + emissive *= SRGBToLinear(texture(emissiveMap, EMISSIVE_UV).rgb); + #endif + return emissive; + } + + #define CC_SURFACES_FRAGMENT_MODIFY_PBRPARAMS + vec4 SurfacesFragmentModifyPBRParams() + { + vec4 pbr = pbrParams; + #if USE_PBR_MAP + vec4 res = texture(pbrMap, DEFAULT_UV); + pbr.x *= res.OCCLUSION_CHANNEL; + pbr.y *= res.ROUGHNESS_CHANNEL; + pbr.z *= res.METALLIC_CHANNEL; + pbr.w *= res.SPECULAR_INTENSITY_CHANNEL; + #endif + #if USE_METALLIC_ROUGHNESS_MAP + vec4 metallicRoughness = texture(metallicRoughnessMap, DEFAULT_UV); + pbr.z *= metallicRoughness.METALLIC_CHANNEL; + pbr.y *= metallicRoughness.ROUGHNESS_CHANNEL; + #endif + #if USE_OCCLUSION_MAP + pbr.x *= texture(occlusionMap, DEFAULT_UV).OCCLUSION_CHANNEL; + #endif + + return pbr; + } +}% + +CCProgram standard-vs %{ + precision highp float; + + // 1. surface internal macros, for technique usage or remapping some user (material) macros to surface internal macros + #include + #include + + // 2. common include with corresponding shader stage + #include + + // 3. user surface functions that can use user (effect) parameters (ubo Constants) + // see surfaces/default-functions/xxx.chunk + #include + #include + + // 4. surface include with corresponding shader stage and shading-model (optional) + #include + + // 5. shader entry with corresponding shader stage and technique usage/type + #include +}% + + +CCProgram shadow-caster-vs %{ + precision highp float; + #include + #include + #include + #include + #include +}% + + + +CCProgram standard-fs %{ + // shading-model : standard + // lighting-model : standard (isotropy / anisotropy pbr) + // shader stage : fs + // technique usage/type : render-to-scene + + precision highp float; + // 1. surface internal macros, for technique usage or remapping some user (material) macros to surface internal macros + #include + #include + + // 2. common include with corresponding shader stage + #include + + // 3. user surface functions that can use user (effect) parameters (ubo Constants) + // see surfaces/default-functions/xxx.chunk + #include + #include + + // 4. lighting-model (optional) + #include + + // 5. surface include with corresponding shader stage and shading-model (optional) + #include + + // 6. shader entry with corresponding shader stage and technique usage/type + #include +}% + +CCProgram shadow-caster-fs %{ + precision highp float; + #include + #include + #include + #include + #include +}% diff --git a/editor/assets/effects/surfaces/standard.effect.meta b/editor/assets/effects/surfaces/standard.effect.meta new file mode 100644 index 0000000000..5657c8423c --- /dev/null +++ b/editor/assets/effects/surfaces/standard.effect.meta @@ -0,0 +1,16 @@ +{ + "ver": "1.5.6", + "importer": "effect", + "imported": true, + "uuid": "c8f66d17-351a-48da-a12c-0212d28575c4", + "files": [ + ".json" + ], + "subMetas": {}, + "userData": { + "combinations": [ + {}, + {} + ] + } +} diff --git a/editor/assets/effects/surfaces/toon.effect b/editor/assets/effects/surfaces/toon.effect new file mode 100644 index 0000000000..7f067f46f5 --- /dev/null +++ b/editor/assets/effects/surfaces/toon.effect @@ -0,0 +1,391 @@ +// Copyright (c) 2017-2022 Xiamen Yaji Software Co., Ltd. + +CCEffect %{ + techniques: + - passes: + - switch: USE_OUTLINE_PASS + vert: silhouette-edge-vs + frag: silhouette-edge-fs + rasterizerState: + cullMode: front + depthStencilState: + depthFunc: less_equal + depthTest: true + depthWrite: true + properties: + lineWidth: { value: 10, target: outlineParams.x } + depthBias: { value: 0, target: outlineParams.y } + baseColor: { editor: { type: color } } + baseColorMap: { value: grey } + - vert: toon-vs + frag: toon-fs + properties: &props + tilingOffset: { value: [1.0, 1.0, 0.0, 0.0] } + mainColor: { value: [0.6, 0.6, 0.6, 1.0], target: baseColor, linear: true, editor: { displayName: BaseColor, type: color } } + colorScale: { value: [1.0, 1.0, 1.0], target: colorScaleAndCutoff.xyz } + alphaThreshold: { value: 0.5, target: colorScaleAndCutoff.w, editor: { parent: USE_ALPHA_TEST } } + shadeColor1: { value: [0.4, 0.4, 0.4, 1.0], linear: true, editor: { type: color } } + shadeColor2: { value: [0.2, 0.2, 0.2, 1.0], linear: true, editor: { type: color } } + specular: { value: [1.0, 1.0, 1.0, 0.3], linear: true, editor: { type: color } } + baseStep: { value: 0.8, target: shadeParams.x } + baseFeather: { value: 0.001, target: shadeParams.y } + shadeStep: { value: 0.5, target: shadeParams.z } + shadeFeather: { value: 0.001, target: shadeParams.w } + shadowCover: { value: 0.5, target: miscParams.x, editor: { slide: true, range: [0, 1.0], step: 0.001 } } + emissive: { value: [0.0, 0.0, 0.0, 1.0], linear: true, editor: { type: color } } + emissiveScale: { value: [1.0, 1.0, 1.0], target: emissiveScaleAndStrenth.xyz } + normalStrength: { value: 1.0, target: emissiveScaleAndStrenth.w, editor: { parent: USE_NORMAL_MAP }, slide: true, range: [0, 5.0], step: 0.001 } + normalMap: { value: normal } + mainTexture: { value: white, target: baseColorMap, editor: { displayName: BaseColorMap } } + shadeMap1: { value: white } + shadeMap2: { value: white } + specularMap: { value: white } + emissiveMap: { value: grey } + - vert: toon-vs + frag: toon-fs + phase: forward-add + propertyIndex: 1 + embeddedMacros: { CC_FORWARD_ADD: true } + depthStencilState: + depthFunc: equal + depthTest: true + depthWrite: false + blendState: + targets: + - blend: true + blendSrc: one + blendDst: one + blendSrcAlpha: zero + blendDstAlpha: one + properties: *props + - vert: shadow-caster-vs + frag: shadow-caster-fs + phase: shadow-caster + propertyIndex: 1 + rasterizerState: + cullMode: front + properties: + tilingOffset: { value: [1.0, 1.0, 0.0, 0.0] } + mainColor: { value: [0.6, 0.6, 0.6, 1.0], target: baseColor, editor: { displayName: BaseColor, type: color } } + colorScale: { value: [1.0, 1.0, 1.0], target: colorScaleAndCutoff.xyz } + alphaThreshold: { value: 0.5, target: colorScaleAndCutoff.w, editor: { parent: USE_ALPHA_TEST } } + shadeColor1: { value: [0.4, 0.4, 0.4, 1.0], editor: { type: color } } + shadeColor2: { value: [0.2, 0.2, 0.2, 1.0], editor: { type: color } } + specular: { value: [1.0, 1.0, 1.0, 0.3], editor: { type: color } } + baseStep: { value: 0.8, target: shadeParams.x } + baseFeather: { value: 0.001, target: shadeParams.y } + shadeStep: { value: 0.5, target: shadeParams.z } + shadeFeather: { value: 0.001, target: shadeParams.w } + emissive: { value: [0.0, 0.0, 0.0, 1.0], editor: { type: color } } + emissiveScale: { value: [1.0, 1.0, 1.0], target: emissiveScaleAndStrenth.xyz } + normalStrenth: { value: 1.0, target: emissiveScaleAndStrenth.w, editor: { parent: USE_NORMAL_MAP } } + mainTexture: { value: white, target: baseColorMap, editor: { displayName: BaseColorMap } } +}% + +CCProgram shared-ubos %{ + uniform Constants { + vec4 tilingOffset; + vec4 baseColor; + vec4 colorScaleAndCutoff; + vec4 shadeColor1; + vec4 shadeColor2; + vec4 specular; // xyz: specular color, w: power + vec4 shadeParams; + vec4 miscParams; + vec4 emissive; + vec4 emissiveScaleAndStrenth; + };}% + +CCProgram macro-remapping %{ + #define CC_SURFACES_USE_TANGENT_SPACE USE_NORMAL_MAP +}% + +CCProgram surface-vertex %{ + #define CC_SURFACES_VERTEX_MODIFY_UV + void SurfacesVertexModifyUV(inout SurfacesStandardVertexIntermediate In) + { + In.texCoord = In.texCoord * tilingOffset.xy + tilingOffset.zw; + #if CC_SURFACES_USE_SECOND_UV && !CC_SURFACES_USE_LIGHT_MAP + In.texCoord1 = In.texCoord1 * tilingOffset.xy + tilingOffset.zw; + #endif + } +}% + +CCProgram surface-fragment %{ + #if USE_BASE_COLOR_MAP + uniform sampler2D baseColorMap; + #endif + + #if USE_NORMAL_MAP + uniform sampler2D normalMap; + #endif + + #if USE_1ST_SHADE_MAP + uniform sampler2D shadeMap1; + #endif + #if USE_2ND_SHADE_MAP + uniform sampler2D shadeMap2; + #endif + #if USE_SPECULAR_MAP + uniform sampler2D specularMap; + #endif + #if USE_EMISSIVE_MAP + uniform sampler2D emissiveMap; + #endif + + #if USE_ALPHA_TEST + #pragma define-meta ALPHA_TEST_CHANNEL options([a, r, g, b]) + #endif + + + #define CC_SURFACES_FRAGMENT_MODIFY_BASECOLOR_AND_TOONSHADE + void SurfacesFragmentModifyBaseColorAndToonShade(out vec4 baseColorAndTransparency, out vec3 shade1, out vec3 shade2) + { + shade2 = shadeColor2.rgb * colorScaleAndCutoff.rgb; + #if USE_2ND_SHADE_MAP + shade2 *= SRGBToLinear(texture(shadeMap2, FSInput_texcoord).rgb); + #endif + shade1 = shadeColor1.rgb * colorScaleAndCutoff.rgb; + #if USE_1ST_SHADE_MAP + shade1 *= SRGBToLinear(texture(shadeMap1, FSInput_texcoord).rgb); + #if SHADE_MAP_1_AS_SHADE_MAP_2 + shade2 *= shade1.rgb; + #endif + #endif + + vec4 color = baseColor; + #if USE_BASE_COLOR_MAP + vec4 texColor = texture(baseColorMap, FSInput_texcoord); + texColor.rgb = SRGBToLinear(texColor.rgb); + color *= texColor; + #if BASE_COLOR_MAP_AS_SHADE_MAP_1 + shade1 *= texColor.rgb; + #endif + #if BASE_COLOR_MAP_AS_SHADE_MAP_2 + shade2 *= texColor.rgb; + #endif + #endif + baseColorAndTransparency = color; + baseColorAndTransparency.rgb *= colorScaleAndCutoff.xyz; + + #if USE_ALPHA_TEST + if (baseColorAndTransparency.ALPHA_TEST_CHANNEL < colorScaleAndCutoff.w) discard; + #endif + } + + // only for render-to-shadow-map or misc usage + #define CC_SURFACES_FRAGMENT_MODIFY_BASECOLOR_AND_TRANSPARENCY + vec4 SurfacesFragmentModifyBaseColorAndTransparency() + { + vec4 color = baseColor; + #if USE_BASE_COLOR_MAP + vec4 texColor = texture(baseColorMap, FSInput_texcoord); + texColor.rgb = SRGBToLinear(texColor.rgb); + color *= texColor; + #endif + + #if USE_ALPHA_TEST + if (color.ALPHA_TEST_CHANNEL < colorScaleAndCutoff.w) discard; + #endif + + return color; + } + + #define CC_SURFACES_FRAGMENT_MODIFY_WORLD_NORMAL + vec3 SurfacesFragmentModifyWorldNormal() + { + vec3 normal = FSInput_worldNormal; + #if USE_NORMAL_MAP + vec3 nmmp = texture(normalMap, FSInput_texcoord).xyz - vec3(0.5); + normal = CalculateNormalFromTangentSpace(nmmp, emissiveScaleAndStrenth.w, normal.xyz, FSInput_worldTangent, FSInput_mirrorNormal); + #endif + + return normalize(normal); + } + + #define CC_SURFACES_FRAGMENT_MODIFY_EMISSIVE + vec3 SurfacesFragmentModifyEmissive() + { + vec3 emissive = emissive.rgb * emissiveScaleAndStrenth.xyz; + #if USE_EMISSIVE_MAP + emissive *= SRGBToLinear(texture(emissiveMap, FSInput_texcoord).rgb); + #endif + return emissive; + } + + #define CC_SURFACES_FRAGMENT_MODIFY_TOON_STEP_AND_FEATHER + vec4 SurfacesFragmentModifyToonStepAndFeather() + { + return shadeParams; + } + + #define CC_SURFACES_FRAGMENT_MODIFY_TOON_SHADOW_COVER + float SurfacesFragmentModifyToonShadowCover() + { + return miscParams.x; + } + + #define CC_SURFACES_FRAGMENT_MODIFY_TOON_SPECULAR + vec4 SurfacesFragmentModifyToonSpecular() + { + return vec4(1.0, 1.0, 1.0, 0.3); + } +}% + +CCProgram toon-vs %{ + precision highp float; + + // 1. surface internal macros, for technique usage or remapping some user (material) macros to surface internal macros + #include + #include + + // 2. common include with corresponding shader stage + #include + + // 3. user surface functions that can use user (effect) parameters (ubo Constants) + // see surfaces/default-functions/xxx.chunk + #include + #include + + // 4. surface include with corresponding shader stage and shading-model (optional) + #include + + // 5. shader entry with corresponding shader stage and technique usage/type + #include +}% + + +CCProgram shadow-caster-vs %{ + precision highp float; + #include + #include + #include + #include + #include +}% + +CCProgram toon-fs %{ + // shading-model : toon + // lighting-model : toon + // shader stage : fs + // technique usage/type : render-to-scene + + precision highp float; + // 1. surface internal macros, for technique usage or remapping some user (material) macros to surface internal macros + #include + #include + + // 2. common include with corresponding shader stage + #include + + // 3. user surface functions that can use user (effect) parameters (ubo Constants) + // see surfaces/default-functions/xxx.chunk + #include + #include + + // 4. lighting-model (optional) + #include + + // 5. surface include with corresponding shader stage and shading-model (optional) + #include + + // 6. shader entry with corresponding shader stage and technique usage/type + #include +}% + +CCProgram shadow-caster-fs %{ + precision highp float; + #include + #include + #include + #include + #include +}% + + + + + + + + + + + + + + + +////////////////////////////////////////////////silhouette-edge sample +// how to write a simple surface material +// change technique outline-vs/fs:vert/frag to silhouette-edge-vs/fs +CCProgram surface-vertex-silhouette-edge %{ + uniform OutlineVert { + vec4 outlineParams; // x: line width, y: depth hack +}; + + #define CC_SURFACES_VERTEX_MODIFY_LOCAL_POS + vec3 SurfacesVertexModifyLocalPos(in SurfacesStandardVertexIntermediate In) + { + float width = outlineParams.x * 0.001; + vec3 localPos = In.position.xyz; + + #if USE_POSITION_SCALING + vec3 dir = normalize(localPos); + float flip = dot(dir, normalize(In.normal)) < 0.0 ? -1.0 : 1.0; + localPos += flip * dir * width * 2.0; + #else + localPos += normalize(In.normal) * width; + #endif + return localPos; + } + + #define CC_SURFACES_VERTEX_MODIFY_CLIP_POS + vec4 SurfacesVertexModifyClipPos(in SurfacesStandardVertexIntermediate In) + { + vec4 clipPos = In.clipPos; + clipPos.z -= outlineParams.y * 0.002; + return clipPos; + } +}% + +CCProgram surface-fragment-silhouette-edge %{ + uniform OutlineFrag { + vec4 baseColor; + }; + #if USE_BASE_COLOR_MAP + uniform sampler2D baseColorMap; + #endif + + // only for render-to-shadow-map or misc usage + #define CC_SURFACES_FRAGMENT_MODIFY_BASECOLOR_AND_TRANSPARENCY + vec4 SurfacesFragmentModifyBaseColorAndTransparency() + { + vec4 color = vec4(cc_mainLitColor.rgb, 1.0); + color.rgb = SRGBToLinear(baseColor.rgb); + #if USE_BASE_COLOR_MAP + vec4 texColor = texture(baseColorMap, FSInput_texcoord); + texColor.rgb = SRGBToLinear(texColor.rgb); + color *= texColor; + #endif + + return color; + } +}% + +CCProgram silhouette-edge-vs %{ + precision highp float; + #include + #include + #include + #include + #include +}% + +CCProgram silhouette-edge-fs %{ + precision highp float; + #include + #include + #include + #include +}% diff --git a/editor/assets/effects/surfaces/toon.effect.meta b/editor/assets/effects/surfaces/toon.effect.meta new file mode 100644 index 0000000000..771b299d1c --- /dev/null +++ b/editor/assets/effects/surfaces/toon.effect.meta @@ -0,0 +1,11 @@ +{ + "ver": "1.5.6", + "importer": "effect", + "imported": true, + "uuid": "9b20a514-6cc3-49de-b216-b6b863046249", + "files": [ + ".json" + ], + "subMetas": {}, + "userData": {} +} diff --git a/editor/assets/effects/util/batched-unlit.effect.meta b/editor/assets/effects/util/batched-unlit.effect.meta index 1f8e010dc0..3177456ad0 100644 --- a/editor/assets/effects/util/batched-unlit.effect.meta +++ b/editor/assets/effects/util/batched-unlit.effect.meta @@ -1,5 +1,5 @@ { - "ver": "1.5.4", + "ver": "1.5.6", "importer": "effect", "imported": true, "uuid": "f1556893-88b6-4c65-8c16-a5256ef3ad25", diff --git a/editor/assets/effects/util/profiler.effect.meta b/editor/assets/effects/util/profiler.effect.meta index e91b38e1f7..03eb04da40 100644 --- a/editor/assets/effects/util/profiler.effect.meta +++ b/editor/assets/effects/util/profiler.effect.meta @@ -1,5 +1,5 @@ { - "ver": "1.5.4", + "ver": "1.5.6", "importer": "effect", "imported": true, "uuid": "871c3b6c-7379-419d-bda3-794b239ab90d", diff --git a/editor/assets/effects/util/sequence-anim.effect.meta b/editor/assets/effects/util/sequence-anim.effect.meta index 6a32880b3b..fd2f187bd8 100644 --- a/editor/assets/effects/util/sequence-anim.effect.meta +++ b/editor/assets/effects/util/sequence-anim.effect.meta @@ -1,5 +1,5 @@ { - "ver": "1.5.4", + "ver": "1.5.6", "importer": "effect", "imported": true, "uuid": "27cc5a0b-ec0b-4a67-98cf-b42d4fa971de", diff --git a/editor/assets/effects/util/splash-screen.effect.meta b/editor/assets/effects/util/splash-screen.effect.meta index e802147834..7035264a4b 100644 --- a/editor/assets/effects/util/splash-screen.effect.meta +++ b/editor/assets/effects/util/splash-screen.effect.meta @@ -1,5 +1,5 @@ { - "ver": "1.5.4", + "ver": "1.5.6", "importer": "effect", "imported": true, "uuid": "970b0598-bcb0-4714-91fb-2e81440dccd8", diff --git a/editor/assets/primitives.fbx.meta b/editor/assets/primitives.fbx.meta index 32cdace5e7..f979262dd8 100644 --- a/editor/assets/primitives.fbx.meta +++ b/editor/assets/primitives.fbx.meta @@ -1,5 +1,5 @@ { - "ver": "2.1.14", + "ver": "2.2.0", "importer": "fbx", "imported": true, "uuid": "1263d74c-8167-4928-91a6-4e2672411f47", @@ -216,7 +216,8 @@ "imageMetas": [], "legacyFbxImporter": false, "fbx": { - "preferLocalTimeSpan": false + "preferLocalTimeSpan": false, + "smartMaterialEnabled": false } } } diff --git a/editor/i18n/en/assets.js b/editor/i18n/en/assets.js index 01795c8174..3a36c9fdc7 100644 --- a/editor/i18n/en/assets.js +++ b/editor/i18n/en/assets.js @@ -318,10 +318,15 @@ module.exports = { preferLocalTimeSpan: { name: 'Prefer Local Time Span', title: - 'When exporting FBX animations, whether prefer to use the time range recorded in FBX file. ' + - 'If one is not preferred, or one is invalid for use, the time range is robustly calculated. ' + + 'When exporting FBX animations, whether prefer to use the time range recorded in FBX file.
' + + 'If one is not preferred, or one is invalid for use, the time range is robustly calculated.
' + 'Some FBX generators may not export this information.', }, + smartMaterialEnabled: { + name: 'Smart Material Conversion', + title: 'Convert DCC materials to engine builtin materials which match the internal lighting model.', + warn: 'The laboratory feature "Smart Material Conversion" in the preferences is turned off, please enable this feature to modify model level settings.', + }, }, textureCube: { anisotropy: 'Anisotropy', diff --git a/editor/i18n/en/localization.js b/editor/i18n/en/localization.js index 18d408d2af..2987ce4db3 100755 --- a/editor/i18n/en/localization.js +++ b/editor/i18n/en/localization.js @@ -12,22 +12,22 @@ module.exports = { MeshRenderer: `${url}/${version}/manual/en/engine/renderable/model-component.html`, UITransform: `${url}/${version}/manual/en/ui-system/components/editor/ui-transform.html`, Sprite: `${url}/${version}/manual/en/ui-system/components/editor/sprite.html`, - SubContextView: `${url}/${version}/manual/zh/editor/publish/build-open-data-context.html`, + SubContextView: `${url}/${version}/manual/en/editor/publish/build-open-data-context.html`, BlockInputEvents: `${url}/${version}/manual/en/ui-system/components/editor/block-input-events.html`, Camera: `${url}/${version}/manual/en/editor/components/camera-component.html`, Canvas: `${url}/${version}/manual/en/ui-system/components/editor/canvas.html`, - SkinnedMeshRenderer: `${url}/${version}/manual/en/engine/animation/skeletal-animation.html`, - SkinnedMeshBatchRenderer: `${url}/${version}/manual/en/engine/animation/skeletal-animation.html`, - Ambient: `${url}/${version}/manual/zh/concepts/scene/light/lighttype/ambient.html`, - Skybox: `${url}/${version}/manual/zh/concepts/scene/skybox.html`, - Fog: `${url}/${version}/manual/zh/concepts/scene/fog.html`, - Shadow: `${url}/${version}/manual/zh/concepts/scene/light/shadow.html`, - DirectionalLight: `${url}/${version}/manual/en/concepts/scene/light/dir-light.html`, - SphereLight: `${url}/${version}/manual/en/concepts/scene/light/sphere-light.html`, - SpotLight: `${url}/${version}/manual/en/concepts/scene/light/spot-light.html`, + SkinnedMeshRenderer: `${url}/${version}/manual/en/animation/skeletal-animation.html`, + SkinnedMeshBatchRenderer: `${url}/${version}/manual/en/animation/skeletal-animation.html`, + Ambient: `${url}/${version}/manual/en/concepts/scene/light/lightType/ambient.html`, + Skybox: `${url}/${version}/manual/en/concepts/scene/skybox.html`, + Fog: `${url}/${version}/manual/en/concepts/scene/fog.html`, + Shadow: `${url}/${version}/manual/en/concepts/scene/light/shadow.html`, + DirectionalLight: `${url}/${version}/manual/en/concepts/scene/light/lightType/dir-light.html`, + SphereLight: `${url}/${version}/manual/en/concepts/scene/light/lightType/sphere-light.html`, + SpotLight: `${url}/${version}/manual/en/concepts/scene/light/lightType/spot-light.html`, UICoordinateTracker: `${url}/${version}/manual/en/ui-system/components/editor/ui-coordinate-tracker.html`, - Animation: `${url}/${version}/manual/en/engine/animation/animation-component.html`, - SkeletalAnimation: `${url}/${version}/manual/en/engine/animation/skeletal-animation.html`, + Animation: `${url}/${version}/manual/en/animation/animation-component.html`, + SkeletalAnimation: `${url}/${version}/manual/en/animation/skeletal-animation.html`, AudioSource: `${url}/${version}/manual/en/audio-system/overview.html`, Billboard: `${url}/${version}/manual/en/particle-system/billboard-component.html`, Line: `${url}/${version}/manual/en/particle-system/line-component.html`, diff --git a/editor/i18n/zh/assets.js b/editor/i18n/zh/assets.js index 128ab1d085..d5a5f704b2 100644 --- a/editor/i18n/zh/assets.js +++ b/editor/i18n/zh/assets.js @@ -312,7 +312,12 @@ module.exports = { }, preferLocalTimeSpan: { name: '优先使用文件时间范围', - title: '在导出 FBX 动画时,是否优先使用 FBX 文件中记录的动画时间范围。若不使用该时间范围或此范围不可能用,则会粗略地计算动画时间范围。有些 FBX 生产工具中可能并未导出该信息。', + title: '在导出 FBX 动画时,是否优先使用 FBX 文件中记录的动画时间范围。
若不使用该时间范围或此范围不可能用,则会粗略地计算动画时间范围。有些 FBX 生产工具中可能并未导出该信息。', + }, + smartMaterialEnabled: { + name: '材质智能转换', + title: '将 DCC 材质转化为引擎材质, 并匹对 DCC 材质的光照模型', + warn: '偏好设置里的实验室功能 "材质智能转换" 已关闭,请启用此项功能来修改模型级别设置。', }, }, textureCube: { diff --git a/editor/i18n/zh/localization.js b/editor/i18n/zh/localization.js index b67fbfa9b6..b30961fbbd 100755 --- a/editor/i18n/zh/localization.js +++ b/editor/i18n/zh/localization.js @@ -16,18 +16,18 @@ module.exports = { BlockInputEvents: `${url}/${version}/manual/zh/ui-system/components/editor/block-input-events.html`, Camera: `${url}/${version}/manual/zh/editor/components/camera-component.html`, Canvas: `${url}/${version}/manual/zh/ui-system/components/editor/canvas.html`, - SkinnedMeshRenderer: `${url}/${version}/manual/zh/engine/animation/skeletal-animation.html`, - SkinnedMeshBatchRenderer: `${url}/${version}/manual/zh/engine/animation/skeletal-animation.html`, - Ambient: `${url}/${version}/manual/zh/concepts/scene/light/lighttype/ambient.html`, + SkinnedMeshRenderer: `${url}/${version}/manual/zh/animation/skeletal-animation.html`, + SkinnedMeshBatchRenderer: `${url}/${version}/manual/zh/animation/skeletal-animation.html`, + Ambient: `${url}/${version}/manual/zh/concepts/scene/light/lightType/ambient.html`, Skybox: `${url}/${version}/manual/zh/concepts/scene/skybox.html`, Fog: `${url}/${version}/manual/zh/concepts/scene/fog.html`, Shadow: `${url}/${version}/manual/zh/concepts/scene/light/shadow.html`, - DirectionalLight: `${url}/${version}/manual/zh/concepts/scene/light/dir-light.html`, - SphereLight: `${url}/${version}/manual/zh/concepts/scene/light/sphere-light.html`, - SpotLight: `${url}/${version}/manual/zh/concepts/scene/light/spot-light.html`, + DirectionalLight: `${url}/${version}/manual/zh/concepts/scene/light/lightType/dir-light.html`, + SphereLight: `${url}/${version}/manual/zh/concepts/scene/light/lightType/sphere-light.html`, + SpotLight: `${url}/${version}/manual/zh/concepts/scene/light/lightType/spot-light.html`, UICoordinateTracker: `${url}/${version}/manual/zh/ui-system/components/editor/ui-coordinate-tracker.html`, - Animation: `${url}/${version}/manual/zh/engine/animation/animation-component.html`, - SkeletalAnimation: `${url}/${version}/manual/zh/engine/animation/skeletal-animation.html`, + Animation: `${url}/${version}/manual/zh/animation/animation-component.html`, + SkeletalAnimation: `${url}/${version}/manual/zh/animation/skeletal-animation.html`, AudioSource: `${url}/${version}/manual/zh/audio-system/overview.html`, Billboard: `${url}/${version}/manual/zh/particle-system/billboard-component.html`, Line: `${url}/${version}/manual/zh/particle-system/line-component.html`, @@ -154,7 +154,7 @@ module.exports = { use_color_temperature: '是否启用光源色温', color_temperature: '光源色温', illuminance: '光源强度', - luminous_power: '光通量', + luminous_flux: '光通量', luminance: '光亮度', term: '当前使用的光度学计量单位', size: '光源大小', diff --git a/editor/inspector/assets/animation-mask.js b/editor/inspector/assets/animation-mask.js index 674d387ccc..319e0b542e 100644 --- a/editor/inspector/assets/animation-mask.js +++ b/editor/inspector/assets/animation-mask.js @@ -160,7 +160,7 @@ exports.methods = { }, updateTree() { - const convertData = this.convertData(this.queryData._jointMasks.value); + const convertData = this.convertData(this.queryData.joints.value); this.flatData = convertData.flatData; this.$.tree.tree = convertData.treeData; }, @@ -215,7 +215,7 @@ exports.ready = function() { timestamp: rawTimestamp, type: 'asset', assetFilter: { - importer: 'fbx', + importer: ['fbx', 'gltf'], }, events: { async confirm(uuid) { diff --git a/editor/inspector/assets/audio-clip.js b/editor/inspector/assets/audio-clip.js index ee69af99c1..beca784a2f 100644 --- a/editor/inspector/assets/audio-clip.js +++ b/editor/inspector/assets/audio-clip.js @@ -27,7 +27,7 @@ exports.update = function(assetList, metaList) { html += `
${asset.name}
`; } - html += ``; + html += ``; }); this.$.constainer.innerHTML = html; diff --git a/editor/inspector/assets/fbx/fbx.js b/editor/inspector/assets/fbx/fbx.js index aa1a89c014..ed3601c644 100644 --- a/editor/inspector/assets/fbx/fbx.js +++ b/editor/inspector/assets/fbx/fbx.js @@ -20,6 +20,13 @@ exports.template = ` + + + +
+ +
+
@@ -47,6 +54,19 @@ ui-section { display: none; margin-top: 10px; } +.smart-material-prop .warn-words { + display: none; +} + +.smart-material-prop[readonly] .warn-words { + display: block; + margin-top: 5px; + line-height: 20px; +} +.smart-material-prop[readonly] .smartMaterialEnabled-checkbox { + pointer-events: none; + opacity: 0.3; +} `; exports.$ = { @@ -57,6 +77,8 @@ exports.$ = { animationBakeRateSelect: '.animationBakeRate-select', promoteSingleRootNodeCheckbox: '.promoteSingleRootNode-checkbox', preferLocalTimeSpanCheckbox: '.preferLocalTimeSpan-checkbox', + smartMaterialEnabledCheckbox: '.smartMaterialEnabled-checkbox', + smartMaterialEnabledProp: '.smart-material-prop', }; /** @@ -154,9 +176,36 @@ const Elements = { panel.updateReadonly(panel.$.preferLocalTimeSpanCheckbox); }, }, + smartMaterialEnabled: { + ready() { + const panel = this; + + panel.$.smartMaterialEnabledCheckbox.addEventListener('change', panel.setProp.bind(panel, 'fbx.smartMaterialEnabled', 'boolean')); + }, + async update() { + const panel = this; + + const laboratoryExpectedValue = await Editor.Profile.getConfig('engine', 'asset.fbx.material.smart'); + if (!laboratoryExpectedValue) { + panel.$.smartMaterialEnabledProp.setAttribute('readonly', ''); + } else { + panel.$.smartMaterialEnabledProp.removeAttribute('readonly'); + } + + let defaultValue = false; + if (panel.meta.userData.fbx) { + defaultValue = panel.getDefault(panel.meta.userData.fbx.smartMaterialEnabled, defaultValue); + } + + panel.$.smartMaterialEnabledCheckbox.value = defaultValue; + + panel.updateInvalid(panel.$.smartMaterialEnabledCheckbox, 'fbx.smartMaterialEnabled'); + panel.updateReadonly(panel.$.smartMaterialEnabledCheckbox); + }, + }, }; -exports.update = function(assetList, metaList) { +exports.update = async function(assetList, metaList) { this.assetList = assetList; this.metaList = metaList; this.asset = assetList[0]; @@ -165,7 +214,7 @@ exports.update = function(assetList, metaList) { for (const prop in Elements) { const element = Elements[prop]; if (element.update) { - element.update.call(this); + await element.update.call(this); } } }; diff --git a/editor/inspector/assets/material.js b/editor/inspector/assets/material.js index 51a5bc813b..3f2d06dd36 100644 --- a/editor/inspector/assets/material.js +++ b/editor/inspector/assets/material.js @@ -192,7 +192,11 @@ exports.methods = { return; } - this.useCache(); + if (this.requestInitCache) { + this.initCache(); + } else { + this.useCache(); + } if (technique.passes) { // The interface is not a regular data loop, which needs to be completely cleared and placed, but the UI-prop element is still reusable @@ -349,6 +353,57 @@ exports.methods = { Editor.Message.broadcast('material-inspector:change-dump'); }, + initCache() { + const excludeNames = [ + 'children', + 'defines', + 'extends', + 'pipelineStates', + ]; + + const cacheData = this.cacheData; + this.technique.passes.forEach((pass, i) => { + if (pass.propertyIndex !== undefined && pass.propertyIndex.value !== i) { + return; + } + + cacheProperty(pass.value); + }); + + function cacheProperty(prop) { + for (const name in prop) { + // 这些字段是基础类型或配置性的数据,不需要变动 + if (excludeNames.includes(name)) { + continue; + } + + if (prop[name] && typeof prop[name] === 'object') { + if (!(name in cacheData)) { + const { type, value } = prop[name]; + if (type) { + if (value !== undefined) { + cacheData[name] = { type }; + if (value && typeof value === 'object') { + cacheData[name].value = JSON.parse(JSON.stringify(value)); + } else { + cacheData[name].value = value; + } + } + } + } + + if (prop[name].childMap && typeof prop[name].childMap === 'object') { + cacheProperty(prop[name].childMap); + } + } + } + } + + this.requestInitCache = false; + this.updateInstancing(); + this.updatePreview(); + }, + storeCache(dump) { const { name, type, value, default: defaultValue } = dump; @@ -418,6 +473,7 @@ exports.update = async function(assetList, metaList) { this.dirtyData.uuid = this.asset.uuid; this.dirtyData.origin = ''; this.cacheData = {}; + this.requestInitCache = true; } // set this.material.technique this.material = await Editor.Message.request('scene', 'query-material', this.asset.uuid); diff --git a/editor/inspector/assets/video-clip.js b/editor/inspector/assets/video-clip.js index 075faae8c5..e4f4f5654e 100644 --- a/editor/inspector/assets/video-clip.js +++ b/editor/inspector/assets/video-clip.js @@ -30,7 +30,7 @@ exports.update = function(assetList, metaList) { html += `
${asset.name}
`; } - html += ``; + html += ``; }); this.$.constainer.innerHTML = html; diff --git a/editor/inspector/components/class.js b/editor/inspector/components/class.js index 66273ef1ff..129dc31ba2 100644 --- a/editor/inspector/components/class.js +++ b/editor/inspector/components/class.js @@ -68,12 +68,7 @@ exports.methods = { }, appendChildByDisplayOrder(parent, newChild, displayOrder = 0) { const children = Array.from(parent.children); - const child = children.find((child) => { - if (child.dump && child.displayOrder > displayOrder) { - return child; - } - return null; - }); + const child = children.find(child => child.dump && child.displayOrder > displayOrder); if (child) { child.before(newChild); } else { @@ -119,30 +114,35 @@ async function update(dump) { $prop.setAttribute('type', 'dump'); $panel.$propList[id] = $prop; - $prop.displayOrder = info.displayOrder === undefined ? index : Number(info.displayOrder); + const _displayOrder = info.group?.displayOrder || info.displayOrder; + $prop.displayOrder = _displayOrder === undefined ? index : Number(_displayOrder); if (info.group && dump.groups) { - const key = info.group.id || 'default'; - const name = info.group.name; - if (!$panel.$groups[key] && dump.groups[key]) { - if (dump.groups[key].style === 'tab') { - $panel.$groups[key] = $panel.createTabGroup(dump.groups[key]); + const { id = 'default', name } = info.group; + if (!$panel.$groups[id] && dump.groups[id]) { + if (dump.groups[id].style === 'tab') { + $panel.$groups[id] = $panel.createTabGroup(dump.groups[id]); } } - if ($panel.$groups[key]) { - if (!$panel.$groups[key].isConnected) { - $panel.appendChildByDisplayOrder($section, $panel.$groups[key], dump.groups[key].displayOrder); + if ($panel.$groups[id]) { + if (!$panel.$groups[id].isConnected) { + $panel.appendChildByDisplayOrder($section, $panel.$groups[id], dump.groups[id].displayOrder); } - if (dump.groups[key].style === 'tab') { - $panel.appendToTabGroup($panel.$groups[key], name); + if (dump.groups[id].style === 'tab') { + $panel.appendToTabGroup($panel.$groups[id], name); } } - $panel.appendChildByDisplayOrder($panel.$groups[key].tabs[name], $prop, $prop.displayOrder); + $panel.appendChildByDisplayOrder($panel.$groups[id].tabs[name], $prop, $prop.displayOrder); } else { $panel.appendChildByDisplayOrder($section, $prop, $prop.displayOrder); } } else if (!$prop.isConnected || !$prop.parentElement) { - $panel.appendChildByDisplayOrder($section, $prop, $prop.displayOrder); + if (info.group && dump.groups) { + const { id = 'default', name } = info.group; + $panel.appendChildByDisplayOrder($panel.$groups[id].tabs[name], $prop, $prop.displayOrder); + } else { + $panel.appendChildByDisplayOrder($section, $prop, $prop.displayOrder); + } } $prop.render(info); }); diff --git a/editor/inspector/contributions/asset.js b/editor/inspector/contributions/asset.js index 14eef8e648..516adc5b54 100644 --- a/editor/inspector/contributions/asset.js +++ b/editor/inspector/contributions/asset.js @@ -577,7 +577,7 @@ exports.update = async function update(uuidList, renderMap, dropConfig) { } } - panel.history.snapshot(panel); + panel.history && panel.history.snapshot(panel); }; exports.ready = function ready() { diff --git a/editor/inspector/contributions/node.js b/editor/inspector/contributions/node.js index a85b582257..22d241db6f 100644 --- a/editor/inspector/contributions/node.js +++ b/editor/inspector/contributions/node.js @@ -156,7 +156,7 @@ exports.listeners = { }, }; -exports.template = ` +exports.template = /* html*/`