From 9ca7c2ce6e403bcc62bb2df920ba065e149cc8f2 Mon Sep 17 00:00:00 2001 From: Yun Hsiao Wu Date: Wed, 3 Jun 2020 15:02:57 +0800 Subject: [PATCH 01/28] directional light stack (#6813) * directional light stack * hasChangedFlags: bitwise or instead of direct assignment --- cocos/core/3d/framework/camera-component.ts | 2 +- cocos/core/3d/framework/light-component.ts | 17 +++++++---- cocos/core/3d/framework/model-component.ts | 5 ++-- cocos/core/renderer/scene/light.ts | 2 +- cocos/core/renderer/scene/render-scene.ts | 31 +++++++++++++++++++-- cocos/core/root.ts | 16 ++++------- cocos/core/scene-graph/node.ts | 2 +- 7 files changed, 51 insertions(+), 24 deletions(-) diff --git a/cocos/core/3d/framework/camera-component.ts b/cocos/core/3d/framework/camera-component.ts index 532ed4df89..d18529fb32 100644 --- a/cocos/core/3d/framework/camera-component.ts +++ b/cocos/core/3d/framework/camera-component.ts @@ -486,7 +486,7 @@ export class CameraComponent extends Component { } public onEnable () { - this.node.hasChangedFlags = TransformBit.POSITION; // trigger camera matrix update + this.node.hasChangedFlags |= TransformBit.POSITION; // trigger camera matrix update if (this._camera) { this._attachToScene(); return; diff --git a/cocos/core/3d/framework/light-component.ts b/cocos/core/3d/framework/light-component.ts index 6ff416ca78..9ce13de03c 100644 --- a/cocos/core/3d/framework/light-component.ts +++ b/cocos/core/3d/framework/light-component.ts @@ -50,6 +50,13 @@ export enum LightBakeType { } Enum(LightBakeType); +// tslint:disable: no-shadowed-variable +export namespace LightComponent { + export type Type = EnumAlias; + export type PhotometricTerm = EnumAlias; +} +// tslint:enable: no-shadowed-variable + @ccclass('cc.LightComponent') export class LightComponent extends Component { public static Type = LightType; @@ -197,6 +204,7 @@ export class LightComponent extends Component { if (this._light && !this._light.scene && this.node.scene) { switch (this._type) { case LightType.DIRECTIONAL: + this._getRenderScene().addDirectionalLight(this._light as DirectionalLight); this._getRenderScene().setMainLight(this._light as DirectionalLight); break; case LightType.SPHERE: @@ -213,7 +221,9 @@ export class LightComponent extends Component { if (this._light && this._light.scene) { switch (this._type) { case LightType.DIRECTIONAL: - this._light.scene.unsetMainLight(this._light as DirectionalLight); + const scene = this._light.scene; + scene.removeDirectionalLight(this._light as DirectionalLight); + scene.unsetMainLight(this._light as DirectionalLight); break; case LightType.SPHERE: this._light.scene.removeSphereLight(this._light as SphereLight); @@ -225,8 +235,3 @@ export class LightComponent extends Component { } } } - -export namespace LightComponent { - export type Type = EnumAlias; - export type PhotometricTerm = EnumAlias; -} diff --git a/cocos/core/3d/framework/model-component.ts b/cocos/core/3d/framework/model-component.ts index deedb858d0..01e4403da0 100644 --- a/cocos/core/3d/framework/model-component.ts +++ b/cocos/core/3d/framework/model-component.ts @@ -204,7 +204,7 @@ export class ModelComponent extends RenderableComponent { } @property({ - visible: function (this: ModelComponent) { + visible (this: ModelComponent) { return !!( this.mesh && this.mesh.struct.morph && @@ -344,7 +344,8 @@ export class ModelComponent extends RenderableComponent { protected _updateModelParams () { if (!this._mesh || !this._model) { return; } - this.node.hasChangedFlags = this._model.transform.hasChangedFlags = TransformBit.POSITION; + this.node.hasChangedFlags |= TransformBit.POSITION; + this._model.transform.hasChangedFlags |= TransformBit.POSITION; this._model.isDynamicBatching = this._isBatchingEnabled(); const meshCount = this._mesh ? this._mesh.subMeshCount : 0; const renderingMesh = this._mesh.renderingSubMeshes; diff --git a/cocos/core/renderer/scene/light.ts b/cocos/core/renderer/scene/light.ts index 39835830f8..0166818de1 100644 --- a/cocos/core/renderer/scene/light.ts +++ b/cocos/core/renderer/scene/light.ts @@ -73,7 +73,7 @@ export class Light { set node (n) { this._node = n; if (this._node) { - this._node.hasChangedFlags = TransformBit.ROTATION; + this._node.hasChangedFlags |= TransformBit.ROTATION; } } diff --git a/cocos/core/renderer/scene/render-scene.ts b/cocos/core/renderer/scene/render-scene.ts index 4aff4a5a46..6fe379d061 100644 --- a/cocos/core/renderer/scene/render-scene.ts +++ b/cocos/core/renderer/scene/render-scene.ts @@ -15,6 +15,7 @@ import { Skybox } from './skybox'; import { SphereLight } from './sphere-light'; import { SpotLight } from './spot-light'; import { PREVIEW } from 'internal:constants'; +import { TransformBit } from '../../scene-graph/node-enum'; export interface IRenderSceneInfo { name: string; @@ -116,6 +117,7 @@ export class RenderScene { private _skybox: Skybox; private _planarShadows: PlanarShadows; private _models: Model[] = []; + private _directionalLights: DirectionalLight[] = []; private _sphereLights: SphereLight[] = []; private _spotLights: SpotLight[] = []; private _mainLight: DirectionalLight | null = null; @@ -165,13 +167,36 @@ export class RenderScene { } public setMainLight (dl: DirectionalLight) { - dl.attachToScene(this); this._mainLight = dl; } public unsetMainLight (dl: DirectionalLight) { - dl.detachFromScene(); - this._mainLight = null; + if (this._mainLight === dl) { + const dlList = this._directionalLights; + if (dlList.length) { + this._mainLight = dlList[dlList.length - 1]; + if (this._mainLight.node) { // trigger update + this._mainLight.node.hasChangedFlags |= TransformBit.ROTATION; + } + } else { + this._mainLight = null; + } + } + } + + public addDirectionalLight (dl: DirectionalLight) { + dl.attachToScene(this); + this._directionalLights.push(dl); + } + + public removeDirectionalLight (dl: DirectionalLight) { + for (let i = 0; i < this._directionalLights.length; ++i) { + if (this._directionalLights[i] === dl) { + dl.detachFromScene(); + this._directionalLights.splice(i, 1); + return; + } + } } public addSphereLight (pl: SphereLight) { diff --git a/cocos/core/root.ts b/cocos/core/root.ts index 879387d0c0..385ee949c2 100644 --- a/cocos/core/root.ts +++ b/cocos/core/root.ts @@ -10,7 +10,6 @@ import { RenderPipeline } from './pipeline/render-pipeline'; import { IRenderViewInfo, RenderView } from './pipeline/render-view'; import { Camera, Light, Model } from './renderer'; import { DataPoolManager } from './renderer/data-pool-manager'; -import { DirectionalLight } from './renderer/scene/directional-light'; import { LightType } from './renderer/scene/light'; import { IRenderSceneInfo, RenderScene } from './renderer/scene/render-scene'; import { SphereLight } from './renderer/scene/sphere-light'; @@ -188,12 +187,9 @@ export class Root { private _dataPoolMgr: DataPoolManager; private _scenes: RenderScene[] = []; private _views: RenderView[] = []; - private _modelPools: Map> = new Map>(); + private _modelPools = new Map, Pool>(); private _cameraPool: Pool | null = null; - private _lightPools: Map> = new Map>(); - private _directLightPool: Pool | null = null; - private _sphereLightPool: Pool | null = null; - private _spotLightPool: Pool | null = null; + private _lightPools = new Map, Pool>(); private _time: number = 0; private _frameTime: number = 0; private _fpsTime: number = 0; @@ -490,11 +486,11 @@ export class Root { this._modelPools.set(mClass, new Pool(() => new mClass(), 10)); p = this._modelPools.get(mClass)!; } - return p.alloc(); + return p.alloc() as T; } public destroyModel (m: Model) { - const p = this._modelPools.get(m.constructor); + const p = this._modelPools.get(m.constructor as Constructor); if (p) { p.free(m); m.destroy(); @@ -525,11 +521,11 @@ export class Root { this._lightPools.set(lClass, new Pool(() => new lClass(), 4)); l = this._lightPools.get(lClass)!; } - return l.alloc(); + return l.alloc() as T; } public destroyLight (l: Light) { - const p = this._lightPools.get(l.constructor); + const p = this._lightPools.get(l.constructor as Constructor); l.destroy(); if (p) { p.free(l); diff --git a/cocos/core/scene-graph/node.ts b/cocos/core/scene-graph/node.ts index 2569efc60d..ae70bc4eb5 100644 --- a/cocos/core/scene-graph/node.ts +++ b/cocos/core/scene-graph/node.ts @@ -462,7 +462,7 @@ export class Node extends BaseNode { const len = this._children.length; for (let i = 0; i < len; ++i) { const child = this._children[i]; - child.isValid && child.invalidateChildren(dirtyBit); + if (child.isValid) { child.invalidateChildren(dirtyBit); } } } From e6cfa7115a2d210f524a020a0a9a071983e653e7 Mon Sep 17 00:00:00 2001 From: JayceLai Date: Wed, 3 Jun 2020 16:28:30 +0800 Subject: [PATCH 02/28] export PrimitiveType --- cocos/core/primitive/primitive.ts | 7 +++++++ exports/base.ts | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/cocos/core/primitive/primitive.ts b/cocos/core/primitive/primitive.ts index 235f2eb3ce..fd45949e98 100644 --- a/cocos/core/primitive/primitive.ts +++ b/cocos/core/primitive/primitive.ts @@ -28,6 +28,9 @@ ccenum(PrimitiveType); */ @ccclass('cc.Primitive') export class Primitive extends Mesh { + + public static PrimitiveType = PrimitiveType; + /** * @en * The type of the primitive mesh, set it before you call onLoaded. @@ -62,4 +65,8 @@ export class Primitive extends Mesh { } } +export namespace Primitive { + export type PrimitiveType = EnumAlias; +} + cc.Primitive = Primitive; diff --git a/exports/base.ts b/exports/base.ts index 37d4fba00d..902fd1f870 100644 --- a/exports/base.ts +++ b/exports/base.ts @@ -24,4 +24,5 @@ export { primitives, }; cc.primitives = primitives; -export * from '../cocos/core/primitive/primitive'; + +export { Primitive } from '../cocos/core/primitive/primitive'; From ca7b59229a1b4f626c4a8d74a172c43f1cab9c7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leslie=20Leigh=20=28=E6=9D=8E=E7=9A=84=E5=BA=8F=29?= Date: Wed, 3 Jun 2020 16:30:13 +0800 Subject: [PATCH 03/28] Bug fix: animation in normal wrap mode won't stop their blend state writers (#6808) * Bug fix: animation in normal wrap mode won't stop their blend state writers * Add test --- cocos/core/animation/animation-state.ts | 6 +++ .../animation/skeletal-animation-blending.ts | 8 +++ tests/animation/animation-clip.test.ts | 49 ++++++++++++++++++- tests/animation/animation-events.test.ts | 4 +- 4 files changed, 65 insertions(+), 2 deletions(-) diff --git a/cocos/core/animation/animation-state.ts b/cocos/core/animation/animation-state.ts index 33c4a0fe3e..d4e63cd323 100644 --- a/cocos/core/animation/animation-state.ts +++ b/cocos/core/animation/animation-state.ts @@ -680,6 +680,9 @@ export class AnimationState extends Playable { if (!this.isPaused) { this._onPauseOrStop(); } + for (let iBlendStateWriter = 0; iBlendStateWriter < this._blendStateWriters.length; ++iBlendStateWriter) { + this._blendStateWriters[iBlendStateWriter].enable(false); + } this.emit(EventType.STOP, this); } @@ -867,6 +870,9 @@ export class AnimationState extends Playable { } this._isBlendStateWriterInitialized = true; } + for (let iBlendStateWriter = 0; iBlendStateWriter < this._blendStateWriters.length; ++iBlendStateWriter) { + this._blendStateWriters[iBlendStateWriter].enable(true); + } cc.director.getAnimationManager().addAnimation(this); } diff --git a/cocos/core/animation/skeletal-animation-blending.ts b/cocos/core/animation/skeletal-animation-blending.ts index c160ec6c8f..97c03454a6 100644 --- a/cocos/core/animation/skeletal-animation-blending.ts +++ b/cocos/core/animation/skeletal-animation-blending.ts @@ -78,6 +78,7 @@ export class BlendStateBuffer { export type IBlendStateWriter = IValueProxyFactory & { initialize: () => void; destroy: () => void; + enable: (enabled: boolean) => void; }; export function createBlendStateWriter

( @@ -97,6 +98,7 @@ export function createBlendStateWriter

( let propertyBlendState: PropertyBlendState> | null = null; let isConstCacheValid = false; let lastWeight = -1; + let isEnabled = true; return { initialize () { if (!propertyBlendState) { @@ -109,9 +111,15 @@ export function createBlendStateWriter

( propertyBlendState = null; } }, + enable (enabled: boolean) { + isEnabled = enabled; + }, forTarget: () => { return { set: (value: BlendingPropertyValue

) => { + if (!isEnabled) { + return; + } if (!propertyBlendState) { return; } diff --git a/tests/animation/animation-clip.test.ts b/tests/animation/animation-clip.test.ts index f5a93573f0..9ee95d5da4 100644 --- a/tests/animation/animation-clip.test.ts +++ b/tests/animation/animation-clip.test.ts @@ -1,4 +1,4 @@ -import { AnimationClip, js, AnimationState, Node, Component, Vec3 } from '../../cocos/core'; +import { AnimationClip, js, AnimationState, Node, Component, Vec3, AnimationManager } from '../../cocos/core'; import { ComponentPath } from '../../cocos/core/animation/animation'; import { ccclass } from '../../cocos/core/data/class-decorator'; @@ -65,3 +65,50 @@ test('Common target', () => { expect(testComponent.c).toEqual(c); } }); + +test('animation state', () => { + const animationManager = new AnimationManager(); + const mockInstance = jest.spyOn((global as any).cc.director, 'getAnimationManager').mockImplementation(() => { + return animationManager; + }); + + const clip = new AnimationClip('default'); + clip.duration = 2.0; + const keys = [ + 0, + 0.1, + 0.2, + ]; + const values = [ + new Vec3(), + new Vec3(1), + new Vec3(2), + ]; + clip.keys = [keys]; + clip.curves = [{ + modifiers: [ + 'position', + ], + data: { + keys: 0, + values, + }, + }]; + + const state = new AnimationState(clip, clip.name); + state.weight = 1.0; + + const node = new Node(); + state.initialize(node); + + animationManager.update(0); + state.play(); + state.pause(); + + state.setTime(keys[1]); + state.update(0); + animationManager.update(0); + expect(node.getPosition()).toEqual(values[1]); + + mockInstance.mockRestore(); +}); diff --git a/tests/animation/animation-events.test.ts b/tests/animation/animation-events.test.ts index ce36e32b70..b85355ad5c 100644 --- a/tests/animation/animation-events.test.ts +++ b/tests/animation/animation-events.test.ts @@ -1,7 +1,7 @@ import { Node, AnimationComponent, director, AnimationClip, math, AnimationState } from '../../cocos/core'; test('Animation events(general)', () => { - jest.spyOn((global as any).cc.director, 'getAnimationManager').mockImplementation(() => { + const mockInstance = jest.spyOn((global as any).cc.director, 'getAnimationManager').mockImplementation(() => { return { addAnimation: () => { }, removeAnimation: () => { }, @@ -100,6 +100,8 @@ test('Animation events(general)', () => { testMagic.clear(); state.update(clip.duration / 2 + clip.duration / 4); testMagic.expectAndClear(AnimationComponent.EventType.LASTFRAME); + + mockInstance.mockRestore(); }); test('Animation event(last-frame event optimization)', () => { From b783e5fe92c77b67f2f737998f7962168fdeb36f Mon Sep 17 00:00:00 2001 From: Yun Hsiao Wu Date: Wed, 3 Jun 2020 18:00:29 +0800 Subject: [PATCH 04/28] handle restore operation (#6815) --- cocos/core/3d/framework/model-component.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cocos/core/3d/framework/model-component.ts b/cocos/core/3d/framework/model-component.ts index 01e4403da0..7a81a6b5c8 100644 --- a/cocos/core/3d/framework/model-component.ts +++ b/cocos/core/3d/framework/model-component.ts @@ -241,6 +241,11 @@ export class ModelComponent extends RenderableComponent { this._updateCastShadow(); } + // Redo, Undo, Prefab restore, etc. + public onRestore () { + this._updateModels(); + } + public onEnable () { if (!this._model) { this._updateModels(); From fca06642616f33dac7a3ce5734b07a4b88a359b8 Mon Sep 17 00:00:00 2001 From: ChiaNing Date: Thu, 4 Jun 2020 16:49:07 +0800 Subject: [PATCH 05/28] fix onHidden/onShow event bug (#6817) --- cocos/core/game.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/cocos/core/game.ts b/cocos/core/game.ts index a606ac5122..f27b565430 100644 --- a/cocos/core/game.ts +++ b/cocos/core/game.ts @@ -576,10 +576,6 @@ export class Game extends EventTarget { this._initEngine(); - if (!EDITOR) { - this._initEvents(); - } - if (!EDITOR && !PREVIEW && cc.internal.SplashScreenWebgl && this.canvas) { cc.internal.SplashScreenWebgl.instance.main(this.canvas); } @@ -595,6 +591,9 @@ export class Game extends EventTarget { * @param {Function} onStart - function to be executed after game initialized */ public run (onStart: Function | null, legacyOnStart?: Function | null) { + if (!EDITOR) { + this._initEvents(); + } if (typeof onStart !== 'function' && legacyOnStart) { const config: IGameConfig = this.onStart as IGameConfig; this.init(config); From e746d54086c83bfc67b7cf2fb733d960555fe7e7 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Sun, 7 Jun 2020 18:10:37 +0800 Subject: [PATCH 06/28] Fix image release for CLEANUP_IMAGE_CACHE (#6836) * Fix potential gl texture leak * reorder * Fix Model.recieveShadows deprecation * Fix image destroy for CLEANUP_IMAGE_CACHE --- cocos/core/3d/framework/deprecated.ts | 2 +- cocos/core/assets/image-asset.ts | 1 + cocos/core/assets/simple-texture.ts | 2 +- cocos/core/assets/texture-2d.ts | 10 +++++----- cocos/core/gfx/webgl/webgl-commands.ts | 3 +++ cocos/core/gfx/webgl2/webgl2-commands.ts | 3 +++ 6 files changed, 14 insertions(+), 7 deletions(-) diff --git a/cocos/core/3d/framework/deprecated.ts b/cocos/core/3d/framework/deprecated.ts index c3084c34a3..6ecfe6cade 100644 --- a/cocos/core/3d/framework/deprecated.ts +++ b/cocos/core/3d/framework/deprecated.ts @@ -11,7 +11,7 @@ removeProperty(ModelComponent.prototype, 'ModelComponent.prototype', [ name: 'enableDynamicBatching', }, { - name: 'receiveShadows', + name: 'recieveShadows', }, ]); diff --git a/cocos/core/assets/image-asset.ts b/cocos/core/assets/image-asset.ts index 6c66f18ee9..237a07b9e9 100644 --- a/cocos/core/assets/image-asset.ts +++ b/cocos/core/assets/image-asset.ts @@ -202,6 +202,7 @@ export class ImageAsset extends Asset { public destroy (): boolean { if (this.data && this.data instanceof HTMLImageElement) { this.data.src = ""; + this._setRawAsset(""); cc.loader.removeItem(this.data.id); } return super.destroy(); diff --git a/cocos/core/assets/simple-texture.ts b/cocos/core/assets/simple-texture.ts index 7d819cc69e..eff402e9a7 100644 --- a/cocos/core/assets/simple-texture.ts +++ b/cocos/core/assets/simple-texture.ts @@ -155,7 +155,7 @@ export class SimpleTexture extends TextureBase { this._checkTextureLoaded(); if (macro.CLEANUP_IMAGE_CACHE) { - image.destroy(); + cc.loader.release(image); } }; if (image.loaded) { diff --git a/cocos/core/assets/texture-2d.ts b/cocos/core/assets/texture-2d.ts index aa3853e3a4..2eeabd9b56 100644 --- a/cocos/core/assets/texture-2d.ts +++ b/cocos/core/assets/texture-2d.ts @@ -118,6 +118,10 @@ export class Texture2D extends SimpleTexture { super(true); } + public initialize () { + this.mipmaps = this._mipmaps; + } + public onLoaded () { this.initialize(); } @@ -241,10 +245,6 @@ export class Texture2D extends SimpleTexture { } } - public initialize () { - this.mipmaps = this._mipmaps; - } - protected _getGfxTextureCreateInfo (presumed: PresumedGFXTextureInfo) { return Object.assign({ type: GFXTextureType.TEX2D, @@ -269,7 +269,7 @@ export class Texture2D extends SimpleTexture { } } - if (ready){ + if (ready) { super._textureReady(); } } diff --git a/cocos/core/gfx/webgl/webgl-commands.ts b/cocos/core/gfx/webgl/webgl-commands.ts index 3d9a0f0b3e..290f26ef08 100644 --- a/cocos/core/gfx/webgl/webgl-commands.ts +++ b/cocos/core/gfx/webgl/webgl-commands.ts @@ -866,6 +866,9 @@ export function WebGLCmdFuncCreateTexture (device: WebGLGFXDevice, gpuTexture: W gl.texParameteri(gpuTexture.glTarget, gl.TEXTURE_MIN_FILTER, gpuTexture.glMinFilter); gl.texParameteri(gpuTexture.glTarget, gl.TEXTURE_MAG_FILTER, gpuTexture.glMagFilter); } + else { + gl.deleteTexture(glTexture); + } } break; diff --git a/cocos/core/gfx/webgl2/webgl2-commands.ts b/cocos/core/gfx/webgl2/webgl2-commands.ts index 2b01b92d55..67bb3afdc6 100644 --- a/cocos/core/gfx/webgl2/webgl2-commands.ts +++ b/cocos/core/gfx/webgl2/webgl2-commands.ts @@ -1050,6 +1050,9 @@ export function WebGL2CmdFuncCreateTexture (device: WebGL2GFXDevice, gpuTexture: gl.texParameteri(gpuTexture.glTarget, gl.TEXTURE_MAG_FILTER, gpuTexture.glMagFilter); */ } + else { + gl.deleteTexture(glTexture); + } } else { const glRenderbuffer = gl.createRenderbuffer(); if (glRenderbuffer && gpuTexture.size > 0) { From a955a7839e2058e48aa5a77586d5d08642abdf34 Mon Sep 17 00:00:00 2001 From: yinkaile <501251991@qq.com> Date: Mon, 8 Jun 2020 11:12:50 +0800 Subject: [PATCH 07/28] export CurveRange (#6835) * export CurveRange * no need export to cc manually --- cocos/particle/index.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cocos/particle/index.ts b/cocos/particle/index.ts index 9e8bd92bb9..a18eaf97c2 100644 --- a/cocos/particle/index.ts +++ b/cocos/particle/index.ts @@ -7,12 +7,15 @@ import { LineComponent } from './line-component'; import { ParticleSystemComponent } from './particle-system-component'; import { ParticleUtils } from './particle-utils'; import './deprecated'; +import CurveRange from './animator/curve-range'; + export { BillboardComponent, LineComponent, ParticleSystemComponent, - ParticleUtils + ParticleUtils, + CurveRange }; cc.ParticleSystemComponent = ParticleSystemComponent; From dac83d5f2474e256b48bb695ba59d950c448fd30 Mon Sep 17 00:00:00 2001 From: "jiaxin.lai" Date: Mon, 8 Jun 2020 17:35:09 +0800 Subject: [PATCH 08/28] adapt for alipay (#6838) --- cocos/core/splash-screen-webgl.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/cocos/core/splash-screen-webgl.ts b/cocos/core/splash-screen-webgl.ts index 78d766dd40..9f3fa4060b 100644 --- a/cocos/core/splash-screen-webgl.ts +++ b/cocos/core/splash-screen-webgl.ts @@ -239,10 +239,13 @@ export class SplashScreenWebgl { // adapt for alipay, adjust the canvas size if (ALIPAY) { - const w = screen.width; - this.gl.canvas.width = w; - const h = screen.height; - this.gl.canvas.height = h; + if (window._CCSettings.orientation === 'landscape') { + this.gl.canvas.width = screen.height * devicePixelRatio; + this.gl.canvas.height = screen.width * devicePixelRatio; + } else { + this.gl.canvas.width = screen.width * devicePixelRatio; + this.gl.canvas.height = screen.height * devicePixelRatio; + } } this.initMatrix(); From c31294342a429230ce899caf13e2a58d239c1121 Mon Sep 17 00:00:00 2001 From: "jiaxin.lai" Date: Mon, 8 Jun 2020 21:07:01 +0800 Subject: [PATCH 09/28] awake if change collisionFilterGroup&Mask (#6839) --- cocos/physics/cannon/cannon-rigid-body.ts | 6 ++++++ cocos/physics/cannon/shapes/cannon-shape.ts | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/cocos/physics/cannon/cannon-rigid-body.ts b/cocos/physics/cannon/cannon-rigid-body.ts index d875e3650b..cb59f1ee8d 100644 --- a/cocos/physics/cannon/cannon-rigid-body.ts +++ b/cocos/physics/cannon/cannon-rigid-body.ts @@ -226,14 +226,17 @@ export class CannonRigidBody implements IRigidBody { setGroup (v: number): void { this.impl.collisionFilterGroup = v; + if (!this.impl.isAwake()) this.impl.wakeUp(); } addGroup (v: number): void { this.impl.collisionFilterGroup |= v; + if (!this.impl.isAwake()) this.impl.wakeUp(); } removeGroup (v: number): void { this.impl.collisionFilterGroup &= ~v; + if (!this.impl.isAwake()) this.impl.wakeUp(); } /** mask */ @@ -243,14 +246,17 @@ export class CannonRigidBody implements IRigidBody { setMask (v: number): void { this.impl.collisionFilterMask = v; + if (!this.impl.isAwake()) this.impl.wakeUp(); } addMask (v: number): void { this.impl.collisionFilterMask |= v; + if (!this.impl.isAwake()) this.impl.wakeUp(); } removeMask (v: number): void { this.impl.collisionFilterMask &= ~v; + if (!this.impl.isAwake()) this.impl.wakeUp(); } } \ No newline at end of file diff --git a/cocos/physics/cannon/shapes/cannon-shape.ts b/cocos/physics/cannon/shapes/cannon-shape.ts index bff7134198..65d07b4e58 100644 --- a/cocos/physics/cannon/shapes/cannon-shape.ts +++ b/cocos/physics/cannon/shapes/cannon-shape.ts @@ -123,14 +123,17 @@ export class CannonShape implements IBaseShape { setGroup (v: number): void { this._body.collisionFilterGroup = v; + if (!this._body.isAwake()) this._body.wakeUp(); } addGroup (v: number): void { this._body.collisionFilterGroup |= v; + if (!this._body.isAwake()) this._body.wakeUp(); } removeGroup (v: number): void { this._body.collisionFilterGroup &= ~v; + if (!this._body.isAwake()) this._body.wakeUp(); } /** mask */ @@ -140,14 +143,17 @@ export class CannonShape implements IBaseShape { setMask (v: number): void { this._body.collisionFilterMask = v; + if (!this._body.isAwake()) this._body.wakeUp(); } addMask (v: number): void { this._body.collisionFilterMask |= v; + if (!this._body.isAwake()) this._body.wakeUp(); } removeMask (v: number): void { this._body.collisionFilterMask &= ~v; + if (!this._body.isAwake()) this._body.wakeUp(); } /** From 845fc81fce36511db79a500ce02a316f41ecbdf7 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Tue, 9 Jun 2020 11:23:20 +0800 Subject: [PATCH 10/28] Improve CallbacksInvoker to remove __eventTargets mechanism (#6837) * Improve CallbacksInvoker to remove __eventTargets mechanism * Fix return value in Eventify.once * Use isValid to check callback target validity * Ensure event processor destroy during node destroy * Fix node once can't remove touch/mouse listeners issue * Strict check to include TO_DESTROY and DESTROYED state * Remove execute and invoke directly in emit * Fix ci --- cocos/core/components/component.ts | 14 - cocos/core/data/object.ts | 2 +- cocos/core/event/callbacks-invoker.ts | 87 ++- cocos/core/event/eventify.ts | 60 +- cocos/core/scene-graph/base-node.ts | 26 +- .../core/scene-graph/node-event-processor.ts | 60 +- tests/core/callbacks-invoker.test.ts | 517 ++++++++++++++++++ tests/core/test-callbacks-invoker.js | 451 --------------- 8 files changed, 623 insertions(+), 594 deletions(-) create mode 100644 tests/core/callbacks-invoker.test.ts delete mode 100644 tests/core/test-callbacks-invoker.js diff --git a/cocos/core/components/component.ts b/cocos/core/components/component.ts index 77e177195a..5e247f48ec 100644 --- a/cocos/core/components/component.ts +++ b/cocos/core/components/component.ts @@ -206,12 +206,6 @@ class Component extends CCObject { */ public _id: string = idGenerator.getNewId(); - /** - * Register all related EventTargets, - * all event callbacks will be removed in _onPreDestroy - */ - private _eventTargets: any[] = []; - // private __scriptUuid = ''; public _getRenderScene (): RenderScene { @@ -376,14 +370,6 @@ class Component extends CCObject { // Schedules this.unscheduleAllCallbacks(); - // Remove all listeners - const eventTargets = this._eventTargets; - for (let i = 0, l = eventTargets.length; i < l; ++i) { - const target = eventTargets[i]; - target && target.targetOff(this); - } - eventTargets.length = 0; - // if (EDITOR && !TEST) { // @ts-ignore diff --git a/cocos/core/data/object.ts b/cocos/core/data/object.ts index 2abd9f68d0..9e89f9f806 100644 --- a/cocos/core/data/object.ts +++ b/cocos/core/data/object.ts @@ -327,7 +327,7 @@ class CCObject { this._onPreDestroy(); } - if ((TEST ? (/* make EDITOR mockable*/ Function('return !EDITOR'))() : !EDITOR) || cc.engine._isPlaying) { + if (!EDITOR || cc.engine._isPlaying) { this._destruct(); } diff --git a/cocos/core/event/callbacks-invoker.ts b/cocos/core/event/callbacks-invoker.ts index 8200e1a420..4017f25266 100644 --- a/cocos/core/event/callbacks-invoker.ts +++ b/cocos/core/event/callbacks-invoker.ts @@ -31,6 +31,7 @@ import { Pool } from '../memop'; import { array, createMap } from '../utils/js'; import { TEST } from 'internal:constants'; +import { CCObject, isValid } from '../data/object'; const fastRemoveAt = array.fastRemoveAt; function empty (){} @@ -41,16 +42,31 @@ class CallbackInfo { public once = false; public set (callback: Function, target?: Object, once?: boolean) { - this.callback = callback; + this.callback = callback || empty; this.target = target; this.once = !!once; } + + public reset () { + this.target = undefined; + this.callback = empty; + this.once = false; + } + + public check () { + // Validation + if (this.target instanceof CCObject && !isValid(this.target, true)) { + return false; + } + else { + return true; + } + } } const callbackInfoPool = new Pool(() => { return new CallbackInfo(); }, 32); - /** * @zh 事件监听器列表的简单封装。 * @en A simple list of event callbacks @@ -70,6 +86,7 @@ export class CallbackList { for (let i = 0; i < this.callbackInfos.length; ++i) { const info = this.callbackInfos[i]; if (info && info.callback === cb) { + info.reset(); callbackInfoPool.free(info); fastRemoveAt(this.callbackInfos, i); --i; @@ -85,6 +102,7 @@ export class CallbackList { for (let i = 0; i < this.callbackInfos.length; ++i) { const info = this.callbackInfos[i]; if (info && info.target === target) { + info.reset(); callbackInfoPool.free(info); fastRemoveAt(this.callbackInfos, i); --i; @@ -100,8 +118,14 @@ export class CallbackList { public cancel (index: number) { const info = this.callbackInfos[index]; if (info) { + info.reset(); + if (this.isInvoking) { + this.callbackInfos[index] = null; + } + else { + fastRemoveAt(this.callbackInfos, index); + } callbackInfoPool.free(info); - this.callbackInfos[index] = null; } this.containCanceled = true; } @@ -114,6 +138,7 @@ export class CallbackList { for (let i = 0; i < this.callbackInfos.length; i++) { const info = this.callbackInfos[i]; if (info) { + info.reset(); callbackInfoPool.free(info); this.callbackInfos[i] = null; } @@ -174,13 +199,16 @@ export class CallbacksInvoker { * @param once - Whether invoke the callback only once (and remove it) */ public on (key: string, callback: Function, target?: Object, once?: boolean) { - let list = this._callbackTable[key]; - if (!list) { - list = this._callbackTable[key] = callbackListPool.alloc(); + if (!this.hasEventListener(key, callback, target)) { + let list = this._callbackTable[key]; + if (!list) { + list = this._callbackTable[key] = callbackListPool.alloc(); + } + const info = callbackInfoPool.alloc(); + info.set(callback, target, once); + list.callbackInfos.push(info); } - const info = callbackInfoPool.alloc(); - info.set(callback, target, once); - list.callbackInfos.push(info); + return callback; } /** @@ -190,7 +218,7 @@ export class CallbacksInvoker { * @param callback - Callback function when event triggered * @param target - Callback callee */ - public hasEventListener (key: string, callback?: Function, target: Object | null = null) { + public hasEventListener (key: string, callback?: Function, target?: Object) { const list = this._callbackTable[key]; if (!list) { return false; @@ -201,8 +229,8 @@ export class CallbacksInvoker { if (!callback) { // Make sure no cancelled callbacks if (list.isInvoking) { - for (const info of infos) { - if (info) { + for (let i = 0; i < infos.length; ++i) { + if (infos[i]) { return true; } } @@ -213,8 +241,9 @@ export class CallbacksInvoker { } } - for (const info of infos) { - if (info && info.callback === callback && info.target === target) { + for (let i = 0; i < infos.length; ++i) { + let info = infos[i]; + if (info && info.check() && info.callback === callback && info.target === target) { return true; } } @@ -276,13 +305,7 @@ export class CallbacksInvoker { for (let i = 0; i < infos.length; ++i) { const info = infos[i]; if (info && info.callback === callback && info.target === target) { - if (list.isInvoking) { - list.cancel(i); - } - else { - fastRemoveAt(infos, i); - callbackInfoPool.free(info); - } + list.cancel(i); break; } } @@ -319,11 +342,18 @@ export class CallbacksInvoker { if (info.once) { this.off(key, callback, target); } - if (target) { - callback.call(target, arg0, arg1, arg2, arg3, arg4); + // Lazy check validity of callback target, + // if target is CCObject and is no longer valid, then remove the callback info directly + if (!info.check()) { + this.off(key, callback, target); } else { - callback(arg0, arg1, arg2, arg3, arg4); + if (target) { + callback.call(target, arg0, arg1, arg2, arg3, arg4); + } + else { + callback(arg0, arg1, arg2, arg3, arg4); + } } } } @@ -341,7 +371,14 @@ export class CallbacksInvoker { * 移除所有回调。 */ public clear () { - this._callbackTable = createMap(true); + for (let key in this._callbackTable) { + let list = this._callbackTable[key]; + if (list) { + list.clear(); + callbackListPool.free(list); + delete this._callbackTable[key]; + } + } } } diff --git a/cocos/core/event/eventify.ts b/cocos/core/event/eventify.ts index cc1d880eb0..5f5e9b9181 100644 --- a/cocos/core/event/eventify.ts +++ b/cocos/core/event/eventify.ts @@ -2,7 +2,6 @@ * @category event */ -import { fastRemove } from '../utils/array'; import { CallbacksInvoker } from './callbacks-invoker'; import { createMap } from '../utils/js'; @@ -10,13 +9,6 @@ type Constructor = new (...args: any[]) => T; type EventType = string; -const { - prototype: { - on: callbacksInvokerOn, - off: callbacksInvokerOff, - }, -} = CallbacksInvoker; - /** * @zh * 实现该接口的对象具有处理事件的能力。 @@ -137,57 +129,14 @@ export interface IEventified { export function Eventify (base: Constructor): Constructor { class Eventified extends (base as unknown as any) { private _callbackTable = createMap(true); - - public on (type: EventType, callback: Callback, target?: object) { - if (!this.hasEventListener(type, callback, target)) { - callbacksInvokerOn.call(this, type, callback, target); - if (target) { - this._registerThisIntoTarget(target); - } - } - return callback; - } public once (type: EventType, callback: Callback, target?: object) { - if (!this.hasEventListener(type, callback, target)) { - callbacksInvokerOn.call(this, type, callback, target, true); - if (target) { - this._registerThisIntoTarget(target); - } - } - return callback; - } - - public off (type: EventType, callback?: Function, target?: object) { - if (!callback) { - this.removeAll(type); - } else { - callbacksInvokerOff.call(this, type, callback, target); - if (target) { - this._unregisterThisIntoTarget(target); - } - } + return this.on(type, callback, target, true); } public targetOff (typeOrTarget: string | object) { this.removeAll(typeOrTarget); } - - private _registerThisIntoTarget (target: ITargetImpl) { - if (target.__eventTargets) { - target.__eventTargets.push(this); - } else if (target.node && target.node.__eventTargets) { - target.node.__eventTargets.push(this); - } - } - - private _unregisterThisIntoTarget (target: ITargetImpl) { - if (target.__eventTargets) { - fastRemove(target.__eventTargets, this); - } else if (target.node && target.node.__eventTargets) { - fastRemove(target.node.__eventTargets, this); - } - } }; // Mixin with `CallbacksInvokers`'s prototype @@ -199,9 +148,4 @@ export function Eventify (base: Constructor): Constructor(16); let _currentHovered: BaseNode | null = null; @@ -287,16 +287,15 @@ function _searchMaskInParent (node: Node | null) { function _checkListeners (node: BaseNode, events: string[]) { if (!node._persistNode) { - let i = 0; if (node.eventProcessor.bubblingTargets) { - for (; i < events.length; ++i) { + for (let i = 0; i < events.length; ++i) { if (node.eventProcessor.bubblingTargets.hasEventListener(events[i])) { return true; } } } if (node.eventProcessor.capturingTargets) { - for (; i < events.length; ++i) { + for (let i = 0; i < events.length; ++i) { if (node.eventProcessor.capturingTargets.hasEventListener(events[i])) { return true; } @@ -320,13 +319,13 @@ export class NodeEventProcessor { * @zh * 节点冒泡事件监听器 */ - public bubblingTargets: EventTarget | null = null; + public bubblingTargets: CallbacksInvoker | null = null; /** * @zh * 节点捕获事件监听器 */ - public capturingTargets: EventTarget | null = null; + public capturingTargets: CallbacksInvoker | null = null; /** * @zh * 触摸监听器 @@ -375,6 +374,9 @@ export class NodeEventProcessor { this.mouseListener = null; } } + + this.capturingTargets && this.capturingTargets.clear(); + this.bubblingTargets && this.bubblingTargets.clear(); } /** @@ -430,7 +432,7 @@ export class NodeEventProcessor { // break; // } if (!this.bubblingTargets) { - this.bubblingTargets = new EventTarget(); + this.bubblingTargets = new CallbacksInvoker(); } return this.bubblingTargets.on(type, callback, target); } @@ -458,15 +460,18 @@ export class NodeEventProcessor { public once (type: string, callback: Function, target?: Object, useCapture?: Object) { const forDispatch = this._checknSetupSysEvent(type); - let listeners: EventTarget; + let listeners: CallbacksInvoker; if (forDispatch && useCapture) { - listeners = this.capturingTargets = this.capturingTargets || new EventTarget(); + listeners = this.capturingTargets = this.capturingTargets || new CallbacksInvoker(); } else { - listeners = this.bubblingTargets = this.bubblingTargets || new EventTarget(); + listeners = this.bubblingTargets = this.bubblingTargets || new CallbacksInvoker(); } - listeners.once(type, callback, target); + listeners.on(type, callback, target, true); + listeners.on(type, () => { + this.off(type, callback, target); + }, undefined, true); } /** @@ -534,20 +539,20 @@ export class NodeEventProcessor { * 通过事件名发送自定义事件 * * @param type - 一个监听事件类型的字符串。 - * @param arg1 - 回调第一个参数。 - * @param arg2 - 回调第二个参数。 - * @param arg3 - 回调第三个参数。 - * @param arg4 - 回调第四个参数。 - * @param arg5 - 回调第五个参数。 + * @param arg0 - 回调第一个参数。 + * @param arg1 - 回调第二个参数。 + * @param arg2 - 回调第三个参数。 + * @param arg3 - 回调第四个参数。 + * @param arg4 - 回调第五个参数。 * @example * ```typescript * eventTarget.emit('fire', event); * eventTarget.emit('fire', message, emitter); * ``` */ - public emit (type: string, ...args: any[]) { +public emit (type: string, arg0?: any, arg1?: any, arg2?: any, arg3?: any, arg4?: any) { if (this.bubblingTargets) { - this.bubblingTargets.emit(type, ...args); + this.bubblingTargets.emit(type, arg0, arg1, arg2, arg3, arg4); } } @@ -567,15 +572,17 @@ export class NodeEventProcessor { * 是否监听过某事件。 * * @param type - 一个监听事件类型的字符串。 + * @param callback - The callback function of the event listener, if absent all event listeners for the given type will be removed + * @param target - The callback callee of the event listener * @return - 返回是否当前节点已监听该事件类型。 */ - public hasEventListener (type: string) { + public hasEventListener (type: string, callback?: Function, target?: Object) { let has = false; if (this.bubblingTargets) { - has = this.bubblingTargets.hasEventListener(type); + has = this.bubblingTargets.hasEventListener(type, callback, target); } if (!has && this.capturingTargets) { - has = this.capturingTargets.hasEventListener(type); + has = this.capturingTargets.hasEventListener(type, callback, target); } return has; } @@ -588,10 +595,10 @@ export class NodeEventProcessor { */ public targetOff (target: string | Object) { if (this.capturingTargets) { - this.capturingTargets.targetOff(target); + this.capturingTargets.removeAll(target); } if (this.bubblingTargets) { - this.bubblingTargets.targetOff(target); + this.bubblingTargets.removeAll(target); } if (this.touchListener && !_checkListeners(this.node, _touchEvents)) { @@ -702,11 +709,11 @@ export class NodeEventProcessor { return; } - let listeners: EventTarget | null = null; + let listeners: CallbacksInvoker | null = null; if (useCapture) { - listeners = this.capturingTargets = this.capturingTargets || new EventTarget(); + listeners = this.capturingTargets = this.capturingTargets || new CallbacksInvoker(); } else { - listeners = this.bubblingTargets = this.bubblingTargets || new EventTarget(); + listeners = this.bubblingTargets = this.bubblingTargets || new CallbacksInvoker(); } if (!listeners.hasEventListener(type, callback, target)) { @@ -735,7 +742,6 @@ export class NodeEventProcessor { if (listeners) { listeners.off(type, callback, target); } - } } } diff --git a/tests/core/callbacks-invoker.test.ts b/tests/core/callbacks-invoker.test.ts new file mode 100644 index 0000000000..3be2eb9e10 --- /dev/null +++ b/tests/core/callbacks-invoker.test.ts @@ -0,0 +1,517 @@ +import { CallbacksInvoker } from '../../cocos/core/event/callbacks-invoker'; +import Event from '../../cocos/core/event/event'; +import { Node } from '../../cocos/core/scene-graph/node'; +import { Component } from '../../cocos/core/components/component'; +import { CCObject } from '../../cocos/core/data/object'; + +test('test', function () { + let ci = new CallbacksInvoker(); + + let cb1 = jest.fn(); + let cb2 = jest.fn(); + let cb3 = jest.fn(); + ci.on('a', cb1); + expect(ci.hasEventListener('a', function () {})).toBeFalsy(); + expect(ci.hasEventListener('a', cb1)).toBeTruthy(); + ci.on('a', cb2); + ci.on('b', cb3); + ci.on('nil', undefined); + + ci.emit('a'); + expect(cb1.mock.calls.length).toBe(1); + expect(cb2.mock.calls.length).toBe(1); + + ci.emit('b'); + expect(cb3.mock.calls.length).toBe(1); + + ci.off('a', cb2); + ci.emit('a'); + expect(cb1.mock.calls.length).toBe(2); + expect(cb2.mock.calls.length).toBe(1); + + ci.on('a', cb2); + expect(ci.hasEventListener('a')).toBeTruthy(); + ci.removeAll('a'); + expect(ci.hasEventListener('a')).toBeFalsy(); + ci.emit('a'); + expect(cb1.mock.calls.length).toBe(2); + expect(cb2.mock.calls.length).toBe(1); +}); + +test('remove self during invoking', function () { + let ci = new CallbacksInvoker(); + let cb1 = jest.fn(function () { + ci.off('eve', cb1); + }); + let cb2 = jest.fn(); + + ci.on('eve', cb1); + ci.on('eve', cb2); + ci.emit('eve'); + expect(cb2.mock.calls.length).toBe(1); + + ci.emit('eve'); + expect(cb1.mock.calls.length).toBe(1); + expect(cb2.mock.calls.length).toBe(2); +}); + +test('remove self with target during invoking', function () { + let ci = new CallbacksInvoker(); + let cb1 = jest.fn(function () { + ci.off('eve', cb1, target); + }); + let cb2 = jest.fn(); + let target = {}; + + ci.on('eve', cb1, target); + ci.on('eve', cb2, target); + ci.emit('eve'); + expect(cb1.mock.calls.length).toBe(1); + expect(cb2.mock.calls.length).toBe(1); + + ci.emit('eve'); + expect(cb1.mock.calls.length).toBe(1); + expect(cb2.mock.calls.length).toBe(2); +}); + +test('remove previous during invoking', function () { + let ci = new CallbacksInvoker(); + let cb1 = jest.fn(); + let cb2 = jest.fn(function () { + ci.off('eve', cb1); + }); + + ci.on('eve', cb1); + ci.on('eve', cb2); + ci.emit('eve'); + + expect(ci.hasEventListener('eve', cb1)).toBeFalsy(); + expect(ci.hasEventListener('eve', cb2)).toBeTruthy(); +}); + +test('remove previous with target during invoking', function () { + let ci = new CallbacksInvoker(); + let cb1 = jest.fn(); + let cb2 = jest.fn(function () { + ci.off('eve', cb1, target); + }); + let target = {}; + + ci.on('eve', cb1, target); + ci.on('eve', cb2, target); + ci.emit('eve'); + + expect(ci.hasEventListener('eve', cb1, target)).toBeFalsy(); + expect(ci.hasEventListener('eve', cb2, target)).toBeTruthy(); +}); + +test('remove last during invoking', function () { + let ci = new CallbacksInvoker(); + let cb1 = jest.fn(); + let cb2 = jest.fn(function () { + ci.off('eve', cb2); + }); + + ci.on('eve', cb1); + ci.on('eve', cb2); + ci.emit('eve'); + + expect(ci.hasEventListener('eve', cb1)).toBeTruthy(); + expect(ci.hasEventListener('eve', cb2)).toBeFalsy(); +}); + +test('remove last with target during invoking', function () { + let ci = new CallbacksInvoker(); + let cb1 = jest.fn(); + let cb2 = jest.fn(function () { + ci.off('eve', cb2, target); + }); + let target = {}; + ci.on('eve', cb1, target); + ci.on('eve', cb2, target); + ci.emit('eve'); + + expect(ci.hasEventListener('eve', cb1, target)).toBeTruthy(); + expect(ci.hasEventListener('eve', cb2, target)).toBeFalsy(); +}); + +test('remove multiple callbacks during invoking', function () { + let ci = new CallbacksInvoker(); + let cb1 = jest.fn(); + let cb2 = jest.fn(function () { + ci.off('eve', cb1); + ci.off('eve', cb3, target); + }); + let cb3 = jest.fn(function () { + ci.off('eve', cb2, target); + }); + let target = {}; + ci.on('eve', cb1); + ci.on('eve', cb1, target); + ci.on('eve', cb2, target); + ci.on('eve', cb3); + ci.on('eve', cb3, target); + ci.emit('eve'); + + expect(cb1.mock.calls.length).toBe(2); + expect(cb2.mock.calls.length).toBe(1); + expect(cb3.mock.calls.length).toBe(1); + expect(ci.hasEventListener('eve', cb1, target)).toBeTruthy(); + expect(ci.hasEventListener('eve', cb1)).toBeFalsy(); + expect(ci.hasEventListener('eve', cb2, target)).toBeFalsy(); + expect(ci.hasEventListener('eve', cb3, target)).toBeFalsy(); +}); + +test('remove all callbacks during invoking', function () { + let ci = new CallbacksInvoker(); + let cb1 = jest.fn(); + let cb2 = jest.fn(function () { + ci.removeAll('eve'); + }); + let cb3 = jest.fn(function () { + ci.off('eve', cb2, target); + }); + let target = {}; + ci.on('eve', cb1); + ci.on('eve', cb1, target); + ci.on('eve', cb2, target); + ci.on('eve', cb3); + ci.on('eve', cb3, target); + ci.emit('eve'); + + expect(cb1.mock.calls.length).toBe(2); + expect(cb2.mock.calls.length).toBe(1); + expect(cb3.mock.calls.length).toBe(0); + expect(ci.hasEventListener('eve')).toBeFalsy(); +}); + +test('remove and add again during invoking (node)', function () { + let target = new Object(); + let node = new Node(); + + let cb1 = function () { + node.off('eve', cb1, target); + node.on('eve', cb1, target); + }; + + node.on('eve', cb1, target); + node.dispatchEvent(new Event('eve')); + + expect(node.hasEventListener('eve', cb1, target)).toBeTruthy(); +}); + +test('remove twice and add again during invoking (node)', function () { + let target = new Object(); + let node = new Node(); + + let cb1 = function () { + node.off('eve', cb1, target); + node.off('eve', cb1, target); + node.on('eve', cb1, target); + }; + + node.on('eve', cb1, target); + node.dispatchEvent(new Event('eve')); + + expect(node.hasEventListener('eve', cb1, target)).toBeTruthy(); +}); + +test('remove and check has during invoking (node)', function () { + let target = new Object(); + let node = new Node(); + + let cb1 = function () { + node.off('eve', cb1, target); + expect(node.hasEventListener('eve', cb1, target)).toBeFalsy(); + }; + + node.on('eve', cb1, target); + node.dispatchEvent(new Event('eve')); +}); + +test('CallbacksInvoker support target', function () { + let ci = new CallbacksInvoker(); + let cb1 = jest.fn(function () { + if (this && this.name) + this.count++; + }); + let cb2 = jest.fn(); + let cb3 = jest.fn(); + + let target1 = { + name: 'CallbackTarget1', + count: 0 + }; + let target2 = { + name: 'CallbackTarget2', + count: 0 + }; + + ci.on('a', cb1); + ci.on('a', cb1, target1); + ci.on('a', cb1); + ci.on('a', cb1, target2); + ci.on('a', cb2, target2); + ci.on('a', cb2, target1); + ci.on('a', cb3); + ci.on('a', cb3, target1); + ci.on('b', cb1, target1); + + expect(ci.hasEventListener('a', cb2)).toBeFalsy(); + expect(ci.hasEventListener('a', cb2, target1)).toBeTruthy(); + expect(ci.hasEventListener('a', cb3)).toBeTruthy(); + + ci.emit('a'); + expect(cb1.mock.calls.length).toBe(3); + expect(target1.count).toBe(1); + expect(target2.count).toBe(1); + + expect(cb2.mock.calls.length).toBe(2); + expect(cb3.mock.calls.length).toBe(2); + + expect(ci.hasEventListener('a', cb1.bind(target1))).toBeFalsy(); + + ci.off('b', cb1); + ci.off('b', cb1, target2); + expect(ci.hasEventListener('b', cb1, target1)).toBeTruthy(); + ci.off('b', cb1, target1); + expect(ci.hasEventListener('b', cb1, target1)).toBeFalsy(); + + cb1.mockClear(); + target1.count = 0; + target2.count = 0; + cb2.mockClear(); + cb3.mockClear(); + ci.off('a', cb1, target2); + ci.off('a', cb1, target1); + ci.off('a', cb2, target2); + ci.off('a', cb3, target2); + ci.emit('a'); + expect(target1.count).toBe(0); + expect(target2.count).toBe(0); + + expect(cb1.mock.calls.length).toBe(1); + expect(cb2.mock.calls.length).toBe(1); + expect(cb3.mock.calls.length).toBe(2); +}); + +test('CallbacksInvoker remove target', function () { + let ci = new CallbacksInvoker(); + let cb1 = jest.fn(); + let cb2 = jest.fn(); + let cb3 = jest.fn(); + + let target1 = { + name: 'CallbackTarget1', + count: 0 + }; + let target2 = { + name: 'CallbackTarget2', + count: 0 + }; + + ci.on('a', cb1); + ci.on('a', cb1, target1); + ci.on('a', cb1); + ci.on('a', cb1, target2); + ci.on('a', cb2, target2); + ci.on('a', cb2, target1); + ci.on('a', cb3); + ci.on('a', cb3, target1); + + ci.emit('a'); + expect(cb1.mock.calls.length).toBe(3); + expect(cb2.mock.calls.length).toBe(2); + expect(cb3.mock.calls.length).toBe(2); + + ci.removeAll(target1); + + cb1.mockClear(); + cb2.mockClear(); + cb3.mockClear(); + + ci.emit('a'); + expect(cb1.mock.calls.length).toBe(2); + expect(cb2.mock.calls.length).toBe(1); + expect(cb3.mock.calls.length).toBe(1); + + ci.removeAll(target2); + + cb1.mockClear(); + cb2.mockClear(); + cb3.mockClear(); + + ci.emit('a'); + expect(cb1.mock.calls.length).toBe(1); + expect(cb2.mock.calls.length).toBe(0); + expect(cb3.mock.calls.length).toBe(1); +}); + +test('event type conflict with object prototype', function () { + let ci = new CallbacksInvoker(); + let cb1 = jest.fn(function () { + ci.off('toString', cb1); + }); + let cb2 = jest.fn(); + + ci.on('toString', cb1); + ci.on('toString', cb2); + ci.emit('toString'); + expect(cb1.mock.calls.length).toBe(1); + expect(cb2.mock.calls.length).toBe(1); + + ci.emit('toString'); + expect(cb1.mock.calls.length).toBe(1); + expect(cb2.mock.calls.length).toBe(2); +}); + +test('nest invoke', function () { + let ci = new CallbacksInvoker(); + + let actualSequence = []; + let isParentLoop = true; + + let cb1 = function () { + actualSequence.push(cb1); + if (isParentLoop) { + isParentLoop = false; + ci.emit('visit'); + } + }; + let cb2 = function () { + actualSequence.push(cb2); + }; + + ci.on('visit', cb1); + ci.on('visit', cb2); + ci.emit('visit'); + + expect(actualSequence).toEqual([cb1, cb1, cb2, cb2]); +}); + +test('remove during nest invoke', function () { + let ci = new CallbacksInvoker(); + + let actualSequence = []; + let isParentLoop = true; + + let cb1 = function () { + actualSequence.push(cb1); + if (isParentLoop) { + isParentLoop = false; + ci.emit('visit'); + } + else { + ci.off('visit', cb1); + expect(ci.hasEventListener('visit')).toBeFalsy(); + } + }; + + ci.on('visit', cb1); + ci.emit('visit'); + + expect(actualSequence).toEqual([cb1, cb1]); +}); + +test('remove many during nest invoke', function () { + let ci = new CallbacksInvoker(); + + let actualSequence = []; + let isParentLoop = true; + + let cb1 = function () { + actualSequence.push(cb1); + }; + let cb2 = function () { + actualSequence.push(cb2); + if (isParentLoop) { + isParentLoop = false; + ci.emit('visit'); + } + else { + ci.off('visit', cb1); + ci.off('visit', cb2); + } + }; + let cb3 = function () { + actualSequence.push(cb3); + }; + + ci.on('visit', cb1); + ci.on('visit', cb2); + ci.on('visit', cb3); + ci.emit('visit'); + + expect(actualSequence).toEqual([cb1, cb2, cb1, cb2, cb3, cb3]); +}); + +test('Destroyed node should no longer be invoked as target', () => { + let ci = new CallbacksInvoker(); + let node = new Node(); + let cb1 = jest.fn(() => { + node.setPosition(100, 0, 0); + }); + + ci.on('test', cb1, node); + expect(ci.hasEventListener('test', cb1, node)).toBeTruthy(); + + ci.emit('test'); + expect(node.position.x).toBe(100); + expect(cb1.mock.calls.length).toBe(1); + + node.destroy(); + expect(ci.hasEventListener('test', cb1, node)).toBeFalsy(); + ci.emit('test'); + expect(cb1.mock.calls.length).toBe(1); + + node = new Node(); + let cb2 = jest.fn(() => { + node.destroy(); + }); + + ci.on('test', cb2, node); + expect(ci.hasEventListener('test', cb2, node)).toBeTruthy(); + + ci.emit('test'); + expect(cb1.mock.calls.length).toBe(1); + ci.emit('test'); + expect(cb1.mock.calls.length).toBe(1); + expect(ci.hasEventListener('test', cb2, node)).toBeFalsy(); +}); + +test('Destroyed component should no longer be invoked as target', () => { + let ci = new CallbacksInvoker(); + let node = new Node(); + let comp = node.addComponent(Component); + + let cb1 = jest.fn(function () { + this.node.setPosition(100, 0, 0); + }); + ci.on('test', cb1, comp); + expect(ci.hasEventListener('test', cb1, comp)).toBeTruthy(); + + ci.emit('test'); + expect(node.position.x).toBe(100); + expect(cb1.mock.calls.length).toBe(1); + + comp.destroy(); + expect(ci.hasEventListener('test', cb1, comp)).toBeFalsy(); + ci.emit('test'); + expect(cb1.mock.calls.length).toBe(1); + + node = new Node(); + comp = node.addComponent(Component); + let cb2 = jest.fn(() => { + node.destroy(); + // Force destroy node with the component + CCObject._deferredDestroy(); + }); + + ci.on('test', cb2, comp); + expect(ci.hasEventListener('test', cb2, comp)).toBeTruthy(); + + ci.emit('test'); + expect(cb1.mock.calls.length).toBe(1); + ci.emit('test'); + expect(cb1.mock.calls.length).toBe(1); +}); diff --git a/tests/core/test-callbacks-invoker.js b/tests/core/test-callbacks-invoker.js deleted file mode 100644 index b33001e7cd..0000000000 --- a/tests/core/test-callbacks-invoker.js +++ /dev/null @@ -1,451 +0,0 @@ -largeModule('CallbacksInvoker'); - -test('test', function () { - var ci = new cc._Test.CallbacksInvoker(); - - var cb1 = Callback(); - var cb2 = Callback(); - var cb3 = Callback(); - ci.on('a', cb1); - strictEqual(ci.hasEventListener('a', function () {}), false, '`has` should return false if the callback not exists'); - strictEqual(ci.hasEventListener('a', cb1), true, '`has` should return true if the callback exists'); - ci.on('a', cb2); - ci.on('b', cb3); - ci.on('nil', undefined); - - cb1.enable(); - cb2.enable(); - ci.emit('a'); - cb1.once('1 should be called'); - cb2.once('2 should be called'); - - cb3.enable(); - ci.emit('b'); - cb3.once('3 should be called'); - - ci.off('a', cb2); - cb2.setDisabledMessage('callback should not be emitted after removed'); - cb1.enable(); - ci.emit('a'); - cb1.once('callback should still be emitted if not excatly the one being removed'); - - ci.on('a', cb2); - strictEqual(ci.hasEventListener('a'), true, '`has` should return true if has any callback'); - ci.removeAll('a'); - strictEqual(ci.hasEventListener('a'), false, '`has` should return false if all callbacks removed'); - cb1.setDisabledMessage('should not be called after all removed'); - cb2.setDisabledMessage('should not be called after all removed'); - ci.emit('a'); -}); - -test('remove self during invoking', function () { - var ci = new cc._Test.CallbacksInvoker(); - var cb1 = Callback(function () { - ci.off('eve', cb1); - }).enable(); - var cb2 = Callback().enable(); - - ci.on('eve', cb1); - ci.on('eve', cb2); - ci.emit('eve'); - cb2.once('it should be called correctly if previous callback deregistered itself'); - - cb1.disable('should not call after removed'); - ci.emit('eve'); -}); - -test('remove self with target during invoking', function () { - var ci = new cc._Test.CallbacksInvoker(); - var cb1 = Callback(function () { - ci.off('eve', cb1, target); - }).enable(); - var cb2 = Callback().enable(); - var target = {}; - - ci.on('eve', cb1, target); - ci.on('eve', cb2, target); - ci.emit('eve'); - cb2.once('it should be called correctly if previous callback deregistered itself'); - - cb1.disable('should not call after removed'); - ci.emit('eve'); -}); - -test('remove previous during invoking', function () { - var ci = new cc._Test.CallbacksInvoker(); - var cb1 = Callback().enable(); - var cb2 = Callback(function () { - ci.off('eve', cb1); - }).enable(); - - ci.on('eve', cb1); - ci.on('eve', cb2); - ci.emit('eve'); - - strictEqual(ci.hasEventListener('eve', cb1), false, 'previous callback should be removed'); - strictEqual(ci.hasEventListener('eve', cb2), true, 'self callback should not be removed'); -}); - -test('remove previous with target during invoking', function () { - var ci = new cc._Test.CallbacksInvoker(); - var cb1 = Callback().enable(); - var cb2 = Callback(function () { - ci.off('eve', cb1, target); - }).enable(); - var target = {}; - - ci.on('eve', cb1, target); - ci.on('eve', cb2, target); - ci.emit('eve'); - - strictEqual(ci.hasEventListener('eve', cb1, target), false, 'previous callback should be removed'); - strictEqual(ci.hasEventListener('eve', cb2, target), true, 'self callback should not be removed'); -}); - -test('remove last during invoking', function () { - var ci = new cc._Test.CallbacksInvoker(); - var cb1 = Callback().enable(); - var cb2 = Callback(function () { - ci.off('eve', cb2); - }).enable(); - - ci.on('eve', cb1); - ci.on('eve', cb2); - ci.emit('eve'); - - strictEqual(ci.hasEventListener('eve', cb1), true, 'previous callback should not be removed'); - strictEqual(ci.hasEventListener('eve', cb2), false, 'self callback should be removed'); -}); - -test('remove last with target during invoking', function () { - var ci = new cc._Test.CallbacksInvoker(); - var cb1 = Callback().enable(); - var cb2 = Callback(function () { - ci.off('eve', cb2, target); - }).enable(); - var target = {}; - ci.on('eve', cb1, target); - ci.on('eve', cb2, target); - ci.emit('eve'); - - strictEqual(ci.hasEventListener('eve', cb1, target), true, 'previous callback should not be removed'); - strictEqual(ci.hasEventListener('eve', cb2, target), false, 'self callback should be removed'); -}); - -test('remove multiple callbacks during invoking', function () { - var ci = new cc._Test.CallbacksInvoker(); - var cb1 = Callback().enable(); - var cb2 = Callback(function () { - ci.off('eve', cb1); - ci.off('eve', cb3, target); - }).enable(); - var cb3 = Callback(function () { - ci.off('eve', cb2, target); - }).enable(); - var target = {}; - ci.on('eve', cb1); - ci.on('eve', cb1, target); - ci.on('eve', cb2, target); - ci.on('eve', cb3); - ci.on('eve', cb3, target); - ci.emit('eve'); - - cb1.expect(2, 'first callback should be invoked twice'); - cb2.expect(1, 'second callback should be invoked once'); - cb3.expect(1, 'third callback should be invoked once'); - strictEqual(ci.hasEventListener('eve', cb1, target), true, 'first callback with target should not be removed'); - strictEqual(ci.hasEventListener('eve', cb1), false, 'first callback should be removed'); - strictEqual(ci.hasEventListener('eve', cb2, target), false, 'second callback with target should be removed'); - strictEqual(ci.hasEventListener('eve', cb3, target), false, 'third callback with target should be removed'); -}); - -test('remove all callbacks during invoking', function () { - var ci = new cc._Test.CallbacksInvoker(); - var cb1 = Callback().enable(); - var cb2 = Callback(function () { - ci.removeAll('eve'); - }).enable(); - var cb3 = Callback(function () { - ci.off('eve', cb2, target); - }).enable(); - var target = {}; - ci.on('eve', cb1); - ci.on('eve', cb1, target); - ci.on('eve', cb2, target); - ci.on('eve', cb3); - ci.on('eve', cb3, target); - ci.emit('eve'); - - cb1.expect(2, 'first callback should be invoked twice'); - cb2.expect(1, 'second callback should be invoked once'); - cb3.expect(0, 'third callback should never invoked'); - strictEqual(ci.hasEventListener('eve'), false, 'All callbacks should be removed'); -}); - -test('remove and add again during invoking', function () { - var target = new Object(); - var ci = new cc._Test.EventListeners(); - - var cb1 = function () { - ci.off('eve', cb1, target); - ci.on('eve', cb1, target); - }; - - ci.on('eve', cb1, target); - ci.emit(new cc.Event.EventCustom('eve')); - - strictEqual(ci.hasEventListener('eve', cb1, target), true, 'first callback should be added back'); -}); - -test('remove twice and add again during invoking', function () { - var target = new Object(); - var ci = new cc._Test.EventListeners(); - - var cb1 = function () { - ci.off('eve', cb1, target); - ci.off('eve', cb1, target); - ci.on('eve', cb1, target); - }; - - ci.on('eve', cb1, target); - ci.emit(new cc.Event.EventCustom('eve')); - - strictEqual(ci.hasEventListener('eve', cb1, target), true, 'first callback should be added back'); -}); - -test('remove and check has during invoking', function () { - var target = new Object(); - var ci = new cc._Test.EventListeners(); - - var cb1 = function () { - ci.off('eve', cb1, target); - strictEqual(ci.hasEventListener('eve', cb1, target), false, 'first callback should be removed'); - }; - - ci.on('eve', cb1, target); - ci.emit(new cc.Event.EventCustom('eve')); -}); - -test('CallbacksInvoker support target', function () { - var ci = new cc._Test.CallbacksInvoker(); - var cb1 = function () { - cb1.count++; - if (this.name) - this.count++; - }; - cb1.count = 0; - var cb2 = Callback(); - var cb3 = Callback(); - - var target1 = { - name: 'CallbackTarget1', - count: 0 - }; - var target2 = { - name: 'CallbackTarget2', - count: 0 - }; - - ci.on('a', cb1); - ci.on('a', cb1, target1); - ci.on('a', cb1); - ci.on('a', cb1, target2); - ci.on('a', cb1, target2); - ci.on('a', cb2, target2); - ci.on('a', cb2, target1); - ci.on('a', cb3); - ci.on('a', cb3, target1); - ci.on('b', cb1, target1); - - strictEqual(ci.hasEventListener('a', cb2), false, '`has` should return false if the callback without target not exists'); - strictEqual(ci.hasEventListener('a', cb2, target1), true, '`has` should return true if the callback with correct target exists'); - strictEqual(ci.hasEventListener('a', cb3), true, '`has` should return true if the callback without target exists'); - - cb2.enable(); - cb3.enable(); - ci.emit('a'); - strictEqual(cb1.count, 5, 'callback1 should be invoked five times'); - strictEqual(target1.count, 1, 'callback1 should be invoked one time with target1'); - strictEqual(target2.count, 2, 'callback2 should be invoked two times with target2'); - - cb2.expect(2, 'callback2 should be called twice'); - cb3.expect(2, 'callback3 should be called twice'); - - strictEqual(ci.hasEventListener('a', target1), false, '`has` should return false if the target is given'); - - ci.off('b', cb1); - ci.off('b', cb1, target2); - strictEqual(ci.hasEventListener('b', cb1, target1), true, 'remove callback without the correct target should fail'); - ci.off('b', cb1, target1); - strictEqual(ci.hasEventListener('b', cb1, target1), false, 'remove callback with the correct callback and target should succeed'); - - cb1.count = 0; - target1.count = 0; - target2.count = 0; - cb2.calledCount = 0; - cb3.calledCount = 0; - ci.off('a', cb1, target2); - ci.off('a', cb1, target1); - ci.off('a', cb2, target2); - ci.off('a', cb3, target2); - ci.emit('a'); - strictEqual(target1.count, 0, 'callback1 with target1 should not be invoked after remove'); - strictEqual(target2.count, 1, 'callback1 with target2 should be invoked only once after remove one'); - - strictEqual(cb1.count, 3, 'callback1 should be invoked three times after removed two'); - cb2.expect(1, 'callback2 should be called once'); - cb3.expect(2, 'callback3 should be called twice'); -}); - -test('CallbacksInvoker remove target', function () { - var ci = new cc._Test.CallbacksInvoker(); - var cb1 = Callback(); - var cb2 = Callback(); - var cb3 = Callback(); - - var target1 = { - name: 'CallbackTarget1', - count: 0 - }; - var target2 = { - name: 'CallbackTarget2', - count: 0 - }; - - ci.on('a', cb1); - ci.on('a', cb1, target1); - ci.on('a', cb1); - ci.on('a', cb1, target2); - ci.on('a', cb1, target2); - ci.on('a', cb2, target2); - ci.on('a', cb2, target1); - ci.on('a', cb3); - ci.on('a', cb3, target1); - - cb1.enable(); - cb2.enable(); - cb3.enable(); - - ci.emit('a'); - cb1.expect(5, 'callback1 should be called five times'); - cb2.expect(2, 'callback2 should be called twice'); - cb3.expect(2, 'callback3 should be called twice'); - - ci.removeAll(target1); - - cb1.calledCount = 0; - cb2.calledCount = 0; - cb3.calledCount = 0; - - ci.emit('a'); - cb1.expect(4, 'removed one, callback1 should be called four times'); - cb2.expect(1, 'removed one, callback2 should be called once'); - cb3.expect(1, 'removed one, callback3 should be called once'); - - ci.removeAll(target2); - - cb1.calledCount = 0; - cb2.calledCount = 0; - cb3.calledCount = 0; - - ci.emit('a'); - cb1.expect(2, 'removed two, callback1 should be called twice'); - cb2.expect(0, 'removed one, callback2 should not be called'); - cb3.expect(1, 'callback3 should be called once'); -}); - -test('event type conflict with object prototype', function () { - var ci = new cc._Test.CallbacksInvoker(); - var cb1 = Callback(function () { - ci.off('toString', cb1); - }).enable(); - var cb2 = Callback().enable(); - - ci.on('toString', cb1); - ci.on('toString', cb2); - ci.emit('toString'); - cb2.once('it should be called correctly if previous callback deregistered itself'); - - cb1.disable('should not call after removed'); - ci.emit('toString'); -}); - -test('nest invoke', function () { - var ci = new cc._Test.CallbacksInvoker(); - - var actualSequence = []; - var isParentLoop = true; - - var cb1 = function () { - actualSequence.push(cb1); - if (isParentLoop) { - isParentLoop = false; - ci.emit('visit'); - } - }; - var cb2 = function () { - actualSequence.push(cb2); - }; - - ci.on('visit', cb1); - ci.on('visit', cb2); - ci.emit('visit'); - - deepEqual(actualSequence, [cb1, cb1, cb2, cb2], 'support nest invoke'); -}); - -test('remove during nest invoke', function () { - var ci = new cc._Test.CallbacksInvoker(); - - var actualSequence = []; - var isParentLoop = true; - - var cb1 = function () { - actualSequence.push(cb1); - if (isParentLoop) { - isParentLoop = false; - ci.emit('visit'); - } - else { - ci.off('visit', cb1); - strictEqual(ci.hasEventListener('visit'), false, 'all callbacks removed'); - } - }; - - ci.on('visit', cb1); - ci.emit('visit'); - - deepEqual(actualSequence, [cb1, cb1], 'invoke sequence'); -}); - -test('remove many during nest invoke', function () { - var ci = new cc._Test.CallbacksInvoker(); - - var actualSequence = []; - var isParentLoop = true; - - var cb1 = function () { - actualSequence.push(cb1); - }; - var cb2 = function () { - actualSequence.push(cb2); - if (isParentLoop) { - isParentLoop = false; - ci.emit('visit'); - } - else { - ci.off('visit', cb1); - ci.off('visit', cb2); - } - }; - var cb3 = function () { - actualSequence.push(cb3); - }; - - ci.on('visit', cb1); - ci.on('visit', cb2); - ci.on('visit', cb3); - ci.emit('visit'); - - deepEqual(actualSequence, [cb1, cb2, cb1, cb2, cb3, cb3], 'invoke sequence'); -}); From 780a3fce318d2ee45c0f205b0d2652b0bd41a961 Mon Sep 17 00:00:00 2001 From: ChiaNing Date: Wed, 10 Jun 2020 14:21:21 +0800 Subject: [PATCH 11/28] components help docs bug fix (#6848) --- editor/i18n/en/localization.js | 4 ++-- editor/i18n/zh/localization.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/editor/i18n/en/localization.js b/editor/i18n/en/localization.js index 5ecd91cc61..32be134eec 100755 --- a/editor/i18n/en/localization.js +++ b/editor/i18n/en/localization.js @@ -13,7 +13,7 @@ module.exports = { CameraComponent: 'https://docs.cocos.com/creator3d/manual/en/editor/components/camera-component.html', CanvasComponent: 'https://docs.cocos.com/creator3d/manual/en/ui-system/components/editor/canvas.html', SkinningModelComponent: 'https://docs.cocos.com/creator3d/manual/en/engine/animation/skeletal-animation.html', - BatchedSkinningModel: 'https://docs.cocos.com/creator3d/manual/en/engine/animation/skeletal-animation.html', + BatchedSkinningModelComponent: 'https://docs.cocos.com/creator3d/manual/en/engine/animation/skeletal-animation.html', DirectionalLightComponent: 'https://docs.cocos.com/creator3d/manual/en/concepts/scene/light/dir-light.html', SphereLightComponent: 'https://docs.cocos.com/creator3d/manual/en/concepts/scene/light/sphere-light.html', SpotLightComponent: 'https://docs.cocos.com/creator3d/manual/en/concepts/scene/light/spot-light.html', @@ -34,7 +34,7 @@ module.exports = { LabelOutlineComponent: 'https://docs.cocos.com/creator3d/manual/en/ui-system/components/editor/label-outline.html', RichTextComponent: 'https://docs.cocos.com/creator3d/manual/en/ui-system/components/editor/richtext.html', ScrollBarComponent: 'https://docs.cocos.com/creator3d/manual/en/ui-system/components/editor/scrollbar.html', - ScrollView: 'https://docs.cocos.com/creator3d/manual/en/ui-system/components/editor/scrollview.html', + ScrollViewComponent: 'https://docs.cocos.com/creator3d/manual/en/ui-system/components/editor/scrollview.html', SliderComponent: 'https://docs.cocos.com/creator3d/manual/en/ui-system/components/editor/slider.html', ToggleContainerComponent: 'https://docs.cocos.com/creator3d/manual/en/ui-system/components/editor/toggleContainer.html', ToggleComponent: 'https://docs.cocos.com/creator3d/manual/en/ui-system/components/editor/toggle.html', diff --git a/editor/i18n/zh/localization.js b/editor/i18n/zh/localization.js index 5390e61447..8aa6462fe8 100755 --- a/editor/i18n/zh/localization.js +++ b/editor/i18n/zh/localization.js @@ -13,7 +13,7 @@ module.exports = { CameraComponent: 'https://docs.cocos.com/creator3d/manual/zh/editor/components/camera-component.html', CanvasComponent: 'https://docs.cocos.com/creator3d/manual/zh/ui-system/components/editor/canvas.html', SkinningModelComponent: 'https://docs.cocos.com/creator3d/manual/zh/engine/animation/skeletal-animation.html', - BatchedSkinningModel: 'https://docs.cocos.com/creator3d/manual/zh/engine/animation/skeletal-animation.html', + BatchedSkinningModelComponent: 'https://docs.cocos.com/creator3d/manual/zh/engine/animation/skeletal-animation.html', DirectionalLightComponent: 'https://docs.cocos.com/creator3d/manual/zh/concepts/scene/light/dir-light.html', SphereLightComponent: 'https://docs.cocos.com/creator3d/manual/zh/concepts/scene/light/sphere-light.html', SpotLightComponent: 'https://docs.cocos.com/creator3d/manual/zh/concepts/scene/light/spot-light.html', @@ -34,7 +34,7 @@ module.exports = { LabelOutlineComponent: 'https://docs.cocos.com/creator3d/manual/zh/ui-system/components/editor/label-outline.html', RichTextComponent: 'https://docs.cocos.com/creator3d/manual/zh/ui-system/components/editor/richtext.html', ScrollBarComponent: 'https://docs.cocos.com/creator3d/manual/zh/ui-system/components/editor/scrollbar.html', - ScrollView: 'https://docs.cocos.com/creator3d/manual/zh/ui-system/components/editor/scrollview.html', + ScrollViewComponent: 'https://docs.cocos.com/creator3d/manual/zh/ui-system/components/editor/scrollview.html', SliderComponent: 'https://docs.cocos.com/creator3d/manual/zh/ui-system/components/editor/slider.html', ToggleContainerComponent: 'https://docs.cocos.com/creator3d/manual/zh/ui-system/components/editor/toggleContainer.html', ToggleComponent: 'https://docs.cocos.com/creator3d/manual/zh/ui-system/components/editor/toggle.html', From 896fcf3e3717bd05c100738d015165be88a020e2 Mon Sep 17 00:00:00 2001 From: Yun Hsiao Wu Date: Wed, 10 Jun 2020 15:06:29 +0800 Subject: [PATCH 12/28] fix node.setRTS (#6849) --- cocos/core/scene-graph/node.ts | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/cocos/core/scene-graph/node.ts b/cocos/core/scene-graph/node.ts index ae70bc4eb5..019dd41e12 100644 --- a/cocos/core/scene-graph/node.ts +++ b/cocos/core/scene-graph/node.ts @@ -933,14 +933,32 @@ export class Node extends BaseNode { * @param pos The position * @param scale The scale */ - public setRTS (rot?: Quat, pos?: Vec3, scale?: Vec3) { - if (rot) { Quat.copy(this._lrot, rot); } - if (pos) { Vec3.copy(this._lpos, pos); } - if (scale) { Vec3.copy(this._lscale, scale); } - this.invalidateChildren(TransformBit.TRS); - this._eulerDirty = true; - if (this._eventMask & TRANSFORM_ON) { - this.emit(SystemEventType.TRANSFORM_CHANGED, TransformBit.TRS); + public setRTS (rot?: Quat | Vec3, pos?: Vec3, scale?: Vec3) { + let dirtyBit: TransformBit = 0; + if (rot) { + dirtyBit |= TransformBit.ROTATION; + if ((rot as Quat).w !== undefined) { + Quat.copy(this._lrot, rot as Quat); + this._eulerDirty = true; + } else { + Vec3.copy(this._euler, rot); + Quat.fromEuler(this._lrot, rot.x, rot.y, rot.z); + this._eulerDirty = false; + } + } + if (pos) { + Vec3.copy(this._lpos, pos); + dirtyBit |= TransformBit.POSITION; + } + if (scale) { + Vec3.copy(this._lscale, scale); + dirtyBit |= TransformBit.SCALE; + } + if (dirtyBit) { + this.invalidateChildren(dirtyBit); + if (this._eventMask & TRANSFORM_ON) { + this.emit(SystemEventType.TRANSFORM_CHANGED, dirtyBit); + } } } From 95deee57a284f07247fc94c860d13e63e109c119 Mon Sep 17 00:00:00 2001 From: ChiaNing Date: Thu, 11 Jun 2020 15:38:43 +0800 Subject: [PATCH 13/28] update package.json for api doc (#6856) --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 45bcd03700..50a4a44aba 100644 --- a/package.json +++ b/package.json @@ -43,10 +43,10 @@ "stats.js": "^0.17.0", "tfig": "^1.2.4", "ts-jest": "^24.3.0", - "typedoc": "^0.14.2", - "typedoc-plugin-external-module-name": "github:cocos-creator/typedoc-plugin-external-module-name#master", - "typedoc-plugin-internal-external": "github:cocos-creator/typedoc-plugin-internal-external#master", - "typedoc-plugin-localization": "github:cocos-creator/typedoc-plugin-localization#master", + "typedoc": "^0.17.7", + "typedoc-plugin-external-module-name": "^4.0.3", + "@cocos/typedoc-plugin-internal-external": "^1.0.0", + "@cocos/typedoc-plugin-localization": "^1.0.0", "typescript": "^3.7.2", "vconsole": "^3.3.0", "yargs": "^12.0.5" From a9e5ed552c6aa2dc3f14f8e93f6258d18d23d0d6 Mon Sep 17 00:00:00 2001 From: Yun Hsiao Wu Date: Thu, 11 Jun 2020 16:06:46 +0800 Subject: [PATCH 14/28] fix node.setWorldScale (#6854) --- cocos/core/scene-graph/node.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cocos/core/scene-graph/node.ts b/cocos/core/scene-graph/node.ts index 019dd41e12..6354e65735 100644 --- a/cocos/core/scene-graph/node.ts +++ b/cocos/core/scene-graph/node.ts @@ -853,16 +853,16 @@ export class Node extends BaseNode { } const parent = this._parent; if (parent) { - parent.updateWorldTransform(); - Mat3.fromQuat(m3_1, Quat.conjugate(qt_1, parent._rot)); + this.updateWorldTransform(); + Mat3.fromQuat(m3_1, Quat.conjugate(qt_1, this._rot)); Mat3.multiplyMat4(m3_1, m3_1, parent._mat); m3_scaling.m00 = this._scale.x; m3_scaling.m04 = this._scale.y; m3_scaling.m08 = this._scale.z; Mat3.multiply(m3_1, m3_scaling, Mat3.invert(m3_1, m3_1)); - this._lscale.x = m3_1.m00; - this._lscale.y = m3_1.m04; - this._lscale.z = m3_1.m08; + this._lscale.x = Vec3.set(v3_a, m3_1.m00, m3_1.m01, m3_1.m02).length(); + this._lscale.y = Vec3.set(v3_a, m3_1.m03, m3_1.m04, m3_1.m05).length(); + this._lscale.z = Vec3.set(v3_a, m3_1.m06, m3_1.m07, m3_1.m08).length(); } else { Vec3.copy(this._lscale, this._scale); } From 282df6a9c1695e4b21a8e57bc48278f9b5848308 Mon Sep 17 00:00:00 2001 From: ChiaNing Date: Thu, 11 Jun 2020 17:52:17 +0800 Subject: [PATCH 15/28] fix acceleration event acc type error (#6862) --- cocos/core/platform/event-manager/events.ts | 5 +++-- cocos/core/platform/event-manager/input-manager.ts | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/cocos/core/platform/event-manager/events.ts b/cocos/core/platform/event-manager/events.ts index 9b3e1f9284..913e17d705 100644 --- a/cocos/core/platform/event-manager/events.ts +++ b/cocos/core/platform/event-manager/events.ts @@ -31,6 +31,7 @@ import Event from '../../event/event'; import { Vec2 } from '../../math/vec2'; import { Touch } from './touch'; +import { Acceleration } from './input-manager'; let _vec2 = new Vec2(); @@ -605,13 +606,13 @@ export class EventAcceleration extends Event { * @en The acceleration object * @zh 加速度对象 */ - public acc: Object; + public acc: Acceleration; /** * @param acc - The acceleration * @param bubbles - Indicate whether the event bubbles up through the hierarchy or not. */ - constructor (acc: Object, bubbles?: boolean) { + constructor (acc: Acceleration, bubbles?: boolean) { super(Event.ACCELERATION, bubbles); this.acc = acc; } diff --git a/cocos/core/platform/event-manager/input-manager.ts b/cocos/core/platform/event-manager/input-manager.ts index 451e9150d0..430f260e22 100644 --- a/cocos/core/platform/event-manager/input-manager.ts +++ b/cocos/core/platform/event-manager/input-manager.ts @@ -69,7 +69,7 @@ interface IView { * @en the device accelerometer reports values for each axis in units of g-force. * @zh 设备重力传感器传递的各个轴的数据。 */ -class Acceleration { +export class Acceleration { public x: number; public y: number; public z: number; From f6b7abe84530728e916ebe461355a4fc19160f4c Mon Sep 17 00:00:00 2001 From: Myway Date: Thu, 11 Jun 2020 17:56:16 +0800 Subject: [PATCH 16/28] check detailMap valid (#6861) --- cocos/terrain/terrain.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cocos/terrain/terrain.ts b/cocos/terrain/terrain.ts index 62d91045ef..f4bdc27855 100644 --- a/cocos/terrain/terrain.ts +++ b/cocos/terrain/terrain.ts @@ -1,7 +1,6 @@ /** * @category terrain */ - import { builtinResMgr } from '../core/3d/builtin'; import { RenderableComponent } from '../core/3d/framework/renderable-component'; import { Texture2D } from '../core/assets'; @@ -10,6 +9,7 @@ import { Material } from '../core/assets/material'; import { RenderingSubMesh } from '../core/assets/mesh'; import { Component } from '../core/components'; import { ccclass, disallowMultiple, executeInEditMode, help, menu, property } from '../core/data/class-decorator'; +import { isValid } from '../core/data/object'; import { director } from '../core/director'; import { GFXBuffer } from '../core/gfx/buffer'; import { GFXAttributeName, GFXBufferUsageBit, GFXFormat, GFXMemoryUsageBit, GFXPrimitiveMode } from '../core/gfx/define'; @@ -984,7 +984,7 @@ export class Terrain extends Component { for (let i = 0; i < this._layers.length; ++i) { const temp = this._layers[i]; - if (temp != null && temp.detailMap != null) { + if (temp && temp.detailMap && isValid(temp.detailMap)) { const layer = new TerrainLayerInfo(); layer.slot = i; layer.tileSize = temp.tileSize; From 1349990fb85f42e3a0af52e693c6536204ff8083 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Fri, 12 Jun 2020 12:18:14 +0800 Subject: [PATCH 17/28] Fix Color.set API (#6865) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * AudioClip & AudioPlayer playOneShot volume default value * revert changes * revert changes * Color 类型定义错误 * Fix ci Co-authored-by: k8w --- cocos/core/math/color.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cocos/core/math/color.ts b/cocos/core/math/color.ts index f339f2e1fc..9a2fd388a8 100644 --- a/cocos/core/math/color.ts +++ b/cocos/core/math/color.ts @@ -306,8 +306,10 @@ export class Color extends ValueType { super(); if (typeof r === 'string') { this.fromHEX(r); + } else if (g !== undefined) { + this.set(r as number, g, b, a); } else { - this.set(r as Color, g, b, a); + this.set(r as Color); } } @@ -572,8 +574,9 @@ export class Color extends ValueType { * @param [a=255] 指定的 Alpha 通道。 * @returns 当前颜色。 */ - public set (other: Color, g?: number, b?: number, a?: number): Color; - public set (r?: number | Color, g?: number, b?: number, a?: number) { + public set(other: Color): Color; + public set(r?: number, g?: number, b?: number, a?: number): Color; + public set(r?: number | Color, g?: number, b?: number, a?: number): Color { if (typeof r === 'object') { if (r._val != null) { this._val = r._val; From ccb9bdadd8661be7abc1f09ef5361d58171e5987 Mon Sep 17 00:00:00 2001 From: JoneLau <32630749+JoneLau@users.noreply.github.com> Date: Fri, 12 Jun 2020 19:31:48 +0800 Subject: [PATCH 18/28] use highp in builtin-sprite (#6873) --- cocos/core/3d/builtin/effects.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cocos/core/3d/builtin/effects.ts b/cocos/core/3d/builtin/effects.ts index e7a4403780..75173372e2 100644 --- a/cocos/core/3d/builtin/effects.ts +++ b/cocos/core/3d/builtin/effects.ts @@ -259,12 +259,12 @@ export default [ "name": "builtin-sprite|sprite-vs:vert|sprite-fs:frag", "hash": 543960898, "glsl3": { - "vert": `\nprecision mediump float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n};\n#if USE_LOCAL\nuniform CCLocal {\n highp mat4 cc_matWorld;\n highp mat4 cc_matWorldIT;\n};\n#endif\nin vec3 a_position;\nin vec4 a_color;\nout vec4 color;\nin vec2 a_texCoord;\nout vec2 uv0;\nvec4 vert () {\n vec4 pos = vec4(a_position, 1);\n #if USE_LOCAL\n pos = cc_matViewProj * cc_matWorld * pos;\n #else\n pos = cc_matViewProj * pos;\n #endif\n uv0 = a_texCoord;\n color = a_color;\n return pos;\n}\nvoid main() { gl_Position = vert(); }`, - "frag": `\nprecision mediump float;\nin vec4 color;\n#if USE_TEXTURE\n in vec2 uv0;\n uniform sampler2D mainTexture;\n#endif\nvec4 frag () {\n vec4 o = vec4(1, 1, 1, 1);\n #if USE_TEXTURE\n o *= texture(mainTexture, uv0);\n #if IS_GRAY\n float gray = 0.2126 * o.r + 0.7152 * o.g + 0.0722 * o.b;\n o.r = o.g = o.b = gray;\n #endif\n #endif\n o *= color;\n return o;\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }` + "vert": `\nprecision highp float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n};\n#if USE_LOCAL\nuniform CCLocal {\n highp mat4 cc_matWorld;\n highp mat4 cc_matWorldIT;\n};\n#endif\nin vec3 a_position;\nin vec4 a_color;\nout vec4 color;\nin vec2 a_texCoord;\nout vec2 uv0;\nvec4 vert () {\n vec4 pos = vec4(a_position, 1);\n #if USE_LOCAL\n pos = cc_matViewProj * cc_matWorld * pos;\n #else\n pos = cc_matViewProj * pos;\n #endif\n uv0 = a_texCoord;\n color = a_color;\n return pos;\n}\nvoid main() { gl_Position = vert(); }`, + "frag": `\nprecision highp float;\nin vec4 color;\n#if USE_TEXTURE\n in vec2 uv0;\n uniform sampler2D mainTexture;\n#endif\nvec4 frag () {\n vec4 o = vec4(1, 1, 1, 1);\n #if USE_TEXTURE\n o *= texture(mainTexture, uv0);\n #if IS_GRAY\n float gray = 0.2126 * o.r + 0.7152 * o.g + 0.0722 * o.b;\n o.r = o.g = o.b = gray;\n #endif\n #endif\n o *= color;\n return o;\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }` }, "glsl1": { - "vert": `\nprecision mediump float;\nuniform highp mat4 cc_matViewProj;\n#if USE_LOCAL\nuniform highp mat4 cc_matWorld;\n#endif\nattribute vec3 a_position;\nattribute vec4 a_color;\nvarying vec4 color;\nattribute vec2 a_texCoord;\nvarying vec2 uv0;\nvec4 vert () {\n vec4 pos = vec4(a_position, 1);\n #if USE_LOCAL\n pos = cc_matViewProj * cc_matWorld * pos;\n #else\n pos = cc_matViewProj * pos;\n #endif\n uv0 = a_texCoord;\n color = a_color;\n return pos;\n}\nvoid main() { gl_Position = vert(); }`, - "frag": `\nprecision mediump float;\nvarying vec4 color;\n#if USE_TEXTURE\n varying vec2 uv0;\n uniform sampler2D mainTexture;\n#endif\nvec4 frag () {\n vec4 o = vec4(1, 1, 1, 1);\n #if USE_TEXTURE\n o *= texture2D(mainTexture, uv0);\n #if IS_GRAY\n float gray = 0.2126 * o.r + 0.7152 * o.g + 0.0722 * o.b;\n o.r = o.g = o.b = gray;\n #endif\n #endif\n o *= color;\n return o;\n}\nvoid main() { gl_FragColor = frag(); }` + "vert": `\nprecision highp float;\nuniform highp mat4 cc_matViewProj;\n#if USE_LOCAL\nuniform highp mat4 cc_matWorld;\n#endif\nattribute vec3 a_position;\nattribute vec4 a_color;\nvarying vec4 color;\nattribute vec2 a_texCoord;\nvarying vec2 uv0;\nvec4 vert () {\n vec4 pos = vec4(a_position, 1);\n #if USE_LOCAL\n pos = cc_matViewProj * cc_matWorld * pos;\n #else\n pos = cc_matViewProj * pos;\n #endif\n uv0 = a_texCoord;\n color = a_color;\n return pos;\n}\nvoid main() { gl_Position = vert(); }`, + "frag": `\nprecision highp float;\nvarying vec4 color;\n#if USE_TEXTURE\n varying vec2 uv0;\n uniform sampler2D mainTexture;\n#endif\nvec4 frag () {\n vec4 o = vec4(1, 1, 1, 1);\n #if USE_TEXTURE\n o *= texture2D(mainTexture, uv0);\n #if IS_GRAY\n float gray = 0.2126 * o.r + 0.7152 * o.g + 0.0722 * o.b;\n o.r = o.g = o.b = gray;\n #endif\n #endif\n o *= color;\n return o;\n}\nvoid main() { gl_FragColor = frag(); }` }, "builtins": { "globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }], "samplers": [] }, From 878707fea6660ecabae994e686948fe5d516664a Mon Sep 17 00:00:00 2001 From: Myway Date: Tue, 2 Jun 2020 17:09:18 +0800 Subject: [PATCH 19/28] model component support lighting map (#6796) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 模型支持lighting map渲染 * change static lighting settings # Conflicts: # cocos/core/3d/builtin/effects.ts # cocos/core/3d/framework/model-component.ts # cocos/core/renderer/scene/model.ts # Conflicts: # cocos/core/3d/builtin/effects.ts --- cocos/core/3d/builtin/effects.ts | 215 +++++++++++---------- cocos/core/3d/builtin/init.ts | 13 ++ cocos/core/3d/framework/light-component.ts | 91 ++++++--- cocos/core/3d/framework/model-component.ts | 10 + cocos/core/pipeline/define.ts | 18 +- cocos/core/renderer/scene/model.ts | 59 +++++- 6 files changed, 273 insertions(+), 133 deletions(-) diff --git a/cocos/core/3d/builtin/effects.ts b/cocos/core/3d/builtin/effects.ts index 75173372e2..01f987c28c 100644 --- a/cocos/core/3d/builtin/effects.ts +++ b/cocos/core/3d/builtin/effects.ts @@ -12,8 +12,8 @@ export default [ "name": "builtin-billboard|vert:vs_main|tinted-fs:add", "hash": 3052980566, "glsl3": { - "vert": `\nprecision mediump float;\nuniform Constants {\n vec4 mainTiling_Offset;\n vec4 frameTile_velLenScale;\n vec4 scale;\n};\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n};\nuniform CCLocal {\n highp mat4 cc_matWorld;\n highp mat4 cc_matWorldIT;\n};\nvec4 quaternionFromAxis (vec3 xAxis,vec3 yAxis,vec3 zAxis){\n mat3 m = mat3(xAxis,yAxis,zAxis);\n float trace = m[0][0] + m[1][1] + m[2][2];\n vec4 quat;\n if (trace > 0.) {\n float s = 0.5 / sqrt(trace + 1.0);\n quat.w = 0.25 / s;\n quat.x = (m[2][1] - m[1][2]) * s;\n quat.y = (m[0][2] - m[2][0]) * s;\n quat.z = (m[1][0] - m[0][1]) * s;\n } else if ((m[0][0] > m[1][1]) && (m[0][0] > m[2][2])) {\n float s = 2.0 * sqrt(1.0 + m[0][0] - m[1][1] - m[2][2]);\n quat.w = (m[2][1] - m[1][2]) / s;\n quat.x = 0.25 * s;\n quat.y = (m[0][1] + m[1][0]) / s;\n quat.z = (m[0][2] + m[2][0]) / s;\n } else if (m[1][1] > m[2][2]) {\n float s = 2.0 * sqrt(1.0 + m[1][1] - m[0][0] - m[2][2]);\n quat.w = (m[0][2] - m[2][0]) / s;\n quat.x = (m[0][1] + m[1][0]) / s;\n quat.y = 0.25 * s;\n quat.z = (m[1][2] + m[2][1]) / s;\n } else {\n float s = 2.0 * sqrt(1.0 + m[2][2] - m[0][0] - m[1][1]);\n quat.w = (m[1][0] - m[0][1]) / s;\n quat.x = (m[0][2] + m[2][0]) / s;\n quat.y = (m[1][2] + m[2][1]) / s;\n quat.z = 0.25 * s;\n }\n float len = quat.x * quat.x + quat.y * quat.y + quat.z * quat.z + quat.w * quat.w;\n if (len > 0.) {\n len = 1. / sqrt(len);\n quat.x = quat.x * len;\n quat.y = quat.y * len;\n quat.z = quat.z * len;\n quat.w = quat.w * len;\n }\n return quat;\n}\nvec4 quaternionFromEuler (vec3 angle){\n float x = angle.x / 2.;\n float y = angle.y / 2.;\n float z = angle.z / 2.;\n float sx = sin(x);\n float cx = cos(x);\n float sy = sin(y);\n float cy = cos(y);\n float sz = sin(z);\n float cz = cos(z);\n vec4 quat = vec4(0);\n quat.x = sx * cy * cz + cx * sy * sz;\n quat.y = cx * sy * cz + sx * cy * sz;\n quat.z = cx * cy * sz - sx * sy * cz;\n quat.w = cx * cy * cz - sx * sy * sz;\n return quat;\n}\nvec4 quatMultiply (vec4 a, vec4 b){\n vec4 quat;\n quat.x = a.x * b.w + a.w * b.x + a.y * b.z - a.z * b.y;\n quat.y = a.y * b.w + a.w * b.y + a.z * b.x - a.x * b.z;\n quat.z = a.z * b.w + a.w * b.z + a.x * b.y - a.y * b.x;\n quat.w = a.w * b.w - a.x * b.x - a.y * b.y - a.z * b.z;\n return quat;\n}\nvoid rotateVecFromQuat (inout vec3 v, vec4 q){\n float ix = q.w * v.x + q.y * v.z - q.z * v.y;\n float iy = q.w * v.y + q.z * v.x - q.x * v.z;\n float iz = q.w * v.z + q.x * v.y - q.y * v.x;\n float iw = -q.x * v.x - q.y * v.y - q.z * v.z;\n v.x = ix * q.w + iw * -q.x + iy * -q.z - iz * -q.y;\n v.y = iy * q.w + iw * -q.y + iz * -q.x - ix * -q.z;\n v.z = iz * q.w + iw * -q.z + ix * -q.y - iy * -q.x;\n}\nvec3 rotateInLocalSpace (vec3 pos, vec3 xAxis, vec3 yAxis, vec3 zAxis, vec4 q){\n vec4 viewQuat = quaternionFromAxis(xAxis, yAxis, zAxis);\n vec4 rotQuat = quatMultiply(viewQuat, q);\n rotateVecFromQuat(pos, rotQuat);\n return pos;\n}\nvoid rotateCorner (inout vec2 corner, float angle){\n float xOS = cos(angle) * corner.x - sin(angle) * corner.y;\n float yOS = sin(angle) * corner.x + cos(angle) * corner.y;\n corner.x = xOS;\n corner.y = yOS;\n}\nout vec2 uv;\nout vec4 color;\nvoid computeVertPos (inout vec4 pos, vec2 vertOffset, vec4 q, vec3 s\n , mat4 viewInv\n) {\n vec3 viewSpaceVert = vec3(vertOffset.x * s.x, vertOffset.y * s.y, 0.);\n vec3 camX = normalize(vec3(viewInv[0][0], viewInv[1][0], viewInv[2][0]));\n vec3 camY = normalize(vec3(viewInv[0][1], viewInv[1][1], viewInv[2][1]));\n vec3 camZ = normalize(vec3(viewInv[0][2], viewInv[1][2], viewInv[2][2]));\n pos.xyz += rotateInLocalSpace(viewSpaceVert, camX, camY, camZ, q);\n}\nin vec3 a_position;\nin vec2 a_texCoord;\nin vec4 a_color;\nuniform builtin {\n vec4 cc_size_rotation;\n};\nvec4 vs_main() {\n vec4 pos = vec4(a_position, 1);\n pos = cc_matWorld * pos;\n vec2 vertOffset = a_texCoord.xy - 0.5;\n computeVertPos(pos, vertOffset, quaternionFromEuler(vec3(0., 0., cc_size_rotation.z)), vec3(cc_size_rotation.xy, 0.), cc_matViewInv);\n pos = cc_matViewProj * pos;\n uv = a_texCoord.xy;\n color = a_color;\n return pos;\n}\nvoid main() { gl_Position = vs_main(); }`, - "frag": `\nprecision mediump float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n};\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\n}\nvec4 CCFragOutput (vec4 color) {\n #if CC_USE_HDR\n color.rgb = mix(color.rgb, SRGBToLinear(color.rgb) * cc_exposure.w, vec3(cc_exposure.z));\n #endif\n return color;\n}\nin vec2 uv;\nin vec4 color;\nuniform sampler2D mainTexture;\nuniform FragConstants {\n vec4 tintColor;\n};\nvec4 add () {\n vec4 col = 2.0 * color * tintColor * texture(mainTexture, uv);\n return CCFragOutput(col);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = add(); }` + "vert": `\nprecision mediump float;\nuniform Constants {\n vec4 mainTiling_Offset;\n vec4 frameTile_velLenScale;\n vec4 scale;\n};\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\nuniform CCLocal {\n highp mat4 cc_matWorld;\n highp mat4 cc_matWorldIT;\n highp vec4 cc_lightingMapUVParam;\n};\nvec4 quaternionFromAxis (vec3 xAxis,vec3 yAxis,vec3 zAxis){\n mat3 m = mat3(xAxis,yAxis,zAxis);\n float trace = m[0][0] + m[1][1] + m[2][2];\n vec4 quat;\n if (trace > 0.) {\n float s = 0.5 / sqrt(trace + 1.0);\n quat.w = 0.25 / s;\n quat.x = (m[2][1] - m[1][2]) * s;\n quat.y = (m[0][2] - m[2][0]) * s;\n quat.z = (m[1][0] - m[0][1]) * s;\n } else if ((m[0][0] > m[1][1]) && (m[0][0] > m[2][2])) {\n float s = 2.0 * sqrt(1.0 + m[0][0] - m[1][1] - m[2][2]);\n quat.w = (m[2][1] - m[1][2]) / s;\n quat.x = 0.25 * s;\n quat.y = (m[0][1] + m[1][0]) / s;\n quat.z = (m[0][2] + m[2][0]) / s;\n } else if (m[1][1] > m[2][2]) {\n float s = 2.0 * sqrt(1.0 + m[1][1] - m[0][0] - m[2][2]);\n quat.w = (m[0][2] - m[2][0]) / s;\n quat.x = (m[0][1] + m[1][0]) / s;\n quat.y = 0.25 * s;\n quat.z = (m[1][2] + m[2][1]) / s;\n } else {\n float s = 2.0 * sqrt(1.0 + m[2][2] - m[0][0] - m[1][1]);\n quat.w = (m[1][0] - m[0][1]) / s;\n quat.x = (m[0][2] + m[2][0]) / s;\n quat.y = (m[1][2] + m[2][1]) / s;\n quat.z = 0.25 * s;\n }\n float len = quat.x * quat.x + quat.y * quat.y + quat.z * quat.z + quat.w * quat.w;\n if (len > 0.) {\n len = 1. / sqrt(len);\n quat.x = quat.x * len;\n quat.y = quat.y * len;\n quat.z = quat.z * len;\n quat.w = quat.w * len;\n }\n return quat;\n}\nvec4 quaternionFromEuler (vec3 angle){\n float x = angle.x / 2.;\n float y = angle.y / 2.;\n float z = angle.z / 2.;\n float sx = sin(x);\n float cx = cos(x);\n float sy = sin(y);\n float cy = cos(y);\n float sz = sin(z);\n float cz = cos(z);\n vec4 quat = vec4(0);\n quat.x = sx * cy * cz + cx * sy * sz;\n quat.y = cx * sy * cz + sx * cy * sz;\n quat.z = cx * cy * sz - sx * sy * cz;\n quat.w = cx * cy * cz - sx * sy * sz;\n return quat;\n}\nvec4 quatMultiply (vec4 a, vec4 b){\n vec4 quat;\n quat.x = a.x * b.w + a.w * b.x + a.y * b.z - a.z * b.y;\n quat.y = a.y * b.w + a.w * b.y + a.z * b.x - a.x * b.z;\n quat.z = a.z * b.w + a.w * b.z + a.x * b.y - a.y * b.x;\n quat.w = a.w * b.w - a.x * b.x - a.y * b.y - a.z * b.z;\n return quat;\n}\nvoid rotateVecFromQuat (inout vec3 v, vec4 q){\n float ix = q.w * v.x + q.y * v.z - q.z * v.y;\n float iy = q.w * v.y + q.z * v.x - q.x * v.z;\n float iz = q.w * v.z + q.x * v.y - q.y * v.x;\n float iw = -q.x * v.x - q.y * v.y - q.z * v.z;\n v.x = ix * q.w + iw * -q.x + iy * -q.z - iz * -q.y;\n v.y = iy * q.w + iw * -q.y + iz * -q.x - ix * -q.z;\n v.z = iz * q.w + iw * -q.z + ix * -q.y - iy * -q.x;\n}\nvec3 rotateInLocalSpace (vec3 pos, vec3 xAxis, vec3 yAxis, vec3 zAxis, vec4 q){\n vec4 viewQuat = quaternionFromAxis(xAxis, yAxis, zAxis);\n vec4 rotQuat = quatMultiply(viewQuat, q);\n rotateVecFromQuat(pos, rotQuat);\n return pos;\n}\nvoid rotateCorner (inout vec2 corner, float angle){\n float xOS = cos(angle) * corner.x - sin(angle) * corner.y;\n float yOS = sin(angle) * corner.x + cos(angle) * corner.y;\n corner.x = xOS;\n corner.y = yOS;\n}\nout vec2 uv;\nout vec4 color;\nvoid computeVertPos (inout vec4 pos, vec2 vertOffset, vec4 q, vec3 s\n , mat4 viewInv\n) {\n vec3 viewSpaceVert = vec3(vertOffset.x * s.x, vertOffset.y * s.y, 0.);\n vec3 camX = normalize(vec3(viewInv[0][0], viewInv[1][0], viewInv[2][0]));\n vec3 camY = normalize(vec3(viewInv[0][1], viewInv[1][1], viewInv[2][1]));\n vec3 camZ = normalize(vec3(viewInv[0][2], viewInv[1][2], viewInv[2][2]));\n pos.xyz += rotateInLocalSpace(viewSpaceVert, camX, camY, camZ, q);\n}\nin vec3 a_position;\nin vec2 a_texCoord;\nin vec4 a_color;\nuniform builtin {\n vec4 cc_size_rotation;\n};\nvec4 vs_main() {\n vec4 pos = vec4(a_position, 1);\n pos = cc_matWorld * pos;\n vec2 vertOffset = a_texCoord.xy - 0.5;\n computeVertPos(pos, vertOffset, quaternionFromEuler(vec3(0., 0., cc_size_rotation.z)), vec3(cc_size_rotation.xy, 0.), cc_matViewInv);\n pos = cc_matViewProj * pos;\n uv = a_texCoord.xy;\n color = a_color;\n return pos;\n}\nvoid main() { gl_Position = vs_main(); }`, + "frag": `\nprecision mediump float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\n}\nvec4 CCFragOutput (vec4 color) {\n #if CC_USE_HDR\n color.rgb = mix(color.rgb, SRGBToLinear(color.rgb) * cc_exposure.w, vec3(cc_exposure.z));\n #endif\n return color;\n}\nin vec2 uv;\nin vec4 color;\nuniform sampler2D mainTexture;\nuniform FragConstants {\n vec4 tintColor;\n};\nvec4 add () {\n vec4 col = 2.0 * color * tintColor * texture(mainTexture, uv);\n return CCFragOutput(col);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = add(); }` }, "glsl1": { "vert": `\nprecision mediump float;\nuniform highp mat4 cc_matView;\nuniform highp mat4 cc_matViewInv;\nuniform highp mat4 cc_matViewProj;\nuniform highp mat4 cc_matWorld;\nvec4 quaternionFromAxis (vec3 xAxis,vec3 yAxis,vec3 zAxis){\n mat3 m = mat3(xAxis,yAxis,zAxis);\n float trace = m[0][0] + m[1][1] + m[2][2];\n vec4 quat;\n if (trace > 0.) {\n float s = 0.5 / sqrt(trace + 1.0);\n quat.w = 0.25 / s;\n quat.x = (m[2][1] - m[1][2]) * s;\n quat.y = (m[0][2] - m[2][0]) * s;\n quat.z = (m[1][0] - m[0][1]) * s;\n } else if ((m[0][0] > m[1][1]) && (m[0][0] > m[2][2])) {\n float s = 2.0 * sqrt(1.0 + m[0][0] - m[1][1] - m[2][2]);\n quat.w = (m[2][1] - m[1][2]) / s;\n quat.x = 0.25 * s;\n quat.y = (m[0][1] + m[1][0]) / s;\n quat.z = (m[0][2] + m[2][0]) / s;\n } else if (m[1][1] > m[2][2]) {\n float s = 2.0 * sqrt(1.0 + m[1][1] - m[0][0] - m[2][2]);\n quat.w = (m[0][2] - m[2][0]) / s;\n quat.x = (m[0][1] + m[1][0]) / s;\n quat.y = 0.25 * s;\n quat.z = (m[1][2] + m[2][1]) / s;\n } else {\n float s = 2.0 * sqrt(1.0 + m[2][2] - m[0][0] - m[1][1]);\n quat.w = (m[1][0] - m[0][1]) / s;\n quat.x = (m[0][2] + m[2][0]) / s;\n quat.y = (m[1][2] + m[2][1]) / s;\n quat.z = 0.25 * s;\n }\n float len = quat.x * quat.x + quat.y * quat.y + quat.z * quat.z + quat.w * quat.w;\n if (len > 0.) {\n len = 1. / sqrt(len);\n quat.x = quat.x * len;\n quat.y = quat.y * len;\n quat.z = quat.z * len;\n quat.w = quat.w * len;\n }\n return quat;\n}\nvec4 quaternionFromEuler (vec3 angle){\n float x = angle.x / 2.;\n float y = angle.y / 2.;\n float z = angle.z / 2.;\n float sx = sin(x);\n float cx = cos(x);\n float sy = sin(y);\n float cy = cos(y);\n float sz = sin(z);\n float cz = cos(z);\n vec4 quat = vec4(0);\n quat.x = sx * cy * cz + cx * sy * sz;\n quat.y = cx * sy * cz + sx * cy * sz;\n quat.z = cx * cy * sz - sx * sy * cz;\n quat.w = cx * cy * cz - sx * sy * sz;\n return quat;\n}\nvec4 quatMultiply (vec4 a, vec4 b){\n vec4 quat;\n quat.x = a.x * b.w + a.w * b.x + a.y * b.z - a.z * b.y;\n quat.y = a.y * b.w + a.w * b.y + a.z * b.x - a.x * b.z;\n quat.z = a.z * b.w + a.w * b.z + a.x * b.y - a.y * b.x;\n quat.w = a.w * b.w - a.x * b.x - a.y * b.y - a.z * b.z;\n return quat;\n}\nvoid rotateVecFromQuat (inout vec3 v, vec4 q){\n float ix = q.w * v.x + q.y * v.z - q.z * v.y;\n float iy = q.w * v.y + q.z * v.x - q.x * v.z;\n float iz = q.w * v.z + q.x * v.y - q.y * v.x;\n float iw = -q.x * v.x - q.y * v.y - q.z * v.z;\n v.x = ix * q.w + iw * -q.x + iy * -q.z - iz * -q.y;\n v.y = iy * q.w + iw * -q.y + iz * -q.x - ix * -q.z;\n v.z = iz * q.w + iw * -q.z + ix * -q.y - iy * -q.x;\n}\nvec3 rotateInLocalSpace (vec3 pos, vec3 xAxis, vec3 yAxis, vec3 zAxis, vec4 q){\n vec4 viewQuat = quaternionFromAxis(xAxis, yAxis, zAxis);\n vec4 rotQuat = quatMultiply(viewQuat, q);\n rotateVecFromQuat(pos, rotQuat);\n return pos;\n}\nvoid rotateCorner (inout vec2 corner, float angle){\n float xOS = cos(angle) * corner.x - sin(angle) * corner.y;\n float yOS = sin(angle) * corner.x + cos(angle) * corner.y;\n corner.x = xOS;\n corner.y = yOS;\n}\nvarying vec2 uv;\nvarying vec4 color;\nvoid computeVertPos (inout vec4 pos, vec2 vertOffset, vec4 q, vec3 s\n , mat4 viewInv\n) {\n vec3 viewSpaceVert = vec3(vertOffset.x * s.x, vertOffset.y * s.y, 0.);\n vec3 camX = normalize(vec3(viewInv[0][0], viewInv[1][0], viewInv[2][0]));\n vec3 camY = normalize(vec3(viewInv[0][1], viewInv[1][1], viewInv[2][1]));\n vec3 camZ = normalize(vec3(viewInv[0][2], viewInv[1][2], viewInv[2][2]));\n pos.xyz += rotateInLocalSpace(viewSpaceVert, camX, camY, camZ, q);\n}\nattribute vec3 a_position;\nattribute vec2 a_texCoord;\nattribute vec4 a_color;\nuniform vec4 cc_size_rotation;\nvec4 vs_main() {\n vec4 pos = vec4(a_position, 1);\n pos = cc_matWorld * pos;\n vec2 vertOffset = a_texCoord.xy - 0.5;\n computeVertPos(pos, vertOffset, quaternionFromEuler(vec3(0., 0., cc_size_rotation.z)), vec3(cc_size_rotation.xy, 0.), cc_matViewInv);\n pos = cc_matViewProj * pos;\n uv = a_texCoord.xy;\n color = a_color;\n return pos;\n}\nvoid main() { gl_Position = vs_main(); }`, @@ -40,7 +40,7 @@ export default [ ]} ], "samplers": [ - { "name": "mainTexture", "type": 28, "count": 1, "defines": [], "binding": 30 } + { "name": "mainTexture", "type": 28, "count": 1, "defines": [], "binding": 31 } ], "attributes": [ { "name": "a_position", "type": 15, "count": 1, "defines": [], "format": 32, "location": 0 }, @@ -61,8 +61,8 @@ export default [ "name": "builtin-particle-gpu|particle-vs-gpu:gpvs_main|tinted-fs:add", "hash": 4003605751, "glsl3": { - "vert": `\nprecision mediump float;\nvec4 quaternionFromAxis (vec3 xAxis,vec3 yAxis,vec3 zAxis){\n mat3 m = mat3(xAxis,yAxis,zAxis);\n float trace = m[0][0] + m[1][1] + m[2][2];\n vec4 quat;\n if (trace > 0.) {\n float s = 0.5 / sqrt(trace + 1.0);\n quat.w = 0.25 / s;\n quat.x = (m[2][1] - m[1][2]) * s;\n quat.y = (m[0][2] - m[2][0]) * s;\n quat.z = (m[1][0] - m[0][1]) * s;\n } else if ((m[0][0] > m[1][1]) && (m[0][0] > m[2][2])) {\n float s = 2.0 * sqrt(1.0 + m[0][0] - m[1][1] - m[2][2]);\n quat.w = (m[2][1] - m[1][2]) / s;\n quat.x = 0.25 * s;\n quat.y = (m[0][1] + m[1][0]) / s;\n quat.z = (m[0][2] + m[2][0]) / s;\n } else if (m[1][1] > m[2][2]) {\n float s = 2.0 * sqrt(1.0 + m[1][1] - m[0][0] - m[2][2]);\n quat.w = (m[0][2] - m[2][0]) / s;\n quat.x = (m[0][1] + m[1][0]) / s;\n quat.y = 0.25 * s;\n quat.z = (m[1][2] + m[2][1]) / s;\n } else {\n float s = 2.0 * sqrt(1.0 + m[2][2] - m[0][0] - m[1][1]);\n quat.w = (m[1][0] - m[0][1]) / s;\n quat.x = (m[0][2] + m[2][0]) / s;\n quat.y = (m[1][2] + m[2][1]) / s;\n quat.z = 0.25 * s;\n }\n float len = quat.x * quat.x + quat.y * quat.y + quat.z * quat.z + quat.w * quat.w;\n if (len > 0.) {\n len = 1. / sqrt(len);\n quat.x = quat.x * len;\n quat.y = quat.y * len;\n quat.z = quat.z * len;\n quat.w = quat.w * len;\n }\n return quat;\n}\nvec4 quaternionFromEuler (vec3 angle){\n float x = angle.x / 2.;\n float y = angle.y / 2.;\n float z = angle.z / 2.;\n float sx = sin(x);\n float cx = cos(x);\n float sy = sin(y);\n float cy = cos(y);\n float sz = sin(z);\n float cz = cos(z);\n vec4 quat = vec4(0);\n quat.x = sx * cy * cz + cx * sy * sz;\n quat.y = cx * sy * cz + sx * cy * sz;\n quat.z = cx * cy * sz - sx * sy * cz;\n quat.w = cx * cy * cz - sx * sy * sz;\n return quat;\n}\nmat4 matrixFromRT (vec4 q, vec3 p){\n float x2 = q.x + q.x;\n float y2 = q.y + q.y;\n float z2 = q.z + q.z;\n float xx = q.x * x2;\n float xy = q.x * y2;\n float xz = q.x * z2;\n float yy = q.y * y2;\n float yz = q.y * z2;\n float zz = q.z * z2;\n float wx = q.w * x2;\n float wy = q.w * y2;\n float wz = q.w * z2;\n return mat4(\n 1. - (yy + zz), xy + wz, xz - wy, 0,\n xy - wz, 1. - (xx + zz), yz + wx, 0,\n xz + wy, yz - wx, 1. - (xx + yy), 0,\n p.x, p.y, p.z, 1\n );\n}\nmat4 matFromRTS (vec4 q, vec3 t, vec3 s){\n float x = q.x, y = q.y, z = q.z, w = q.w;\n float x2 = x + x;\n float y2 = y + y;\n float z2 = z + z;\n float xx = x * x2;\n float xy = x * y2;\n float xz = x * z2;\n float yy = y * y2;\n float yz = y * z2;\n float zz = z * z2;\n float wx = w * x2;\n float wy = w * y2;\n float wz = w * z2;\n float sx = s.x;\n float sy = s.y;\n float sz = s.z;\n return mat4((1. - (yy + zz)) * sx, (xy + wz) * sx, (xz - wy) * sx, 0,\n (xy - wz) * sy, (1. - (xx + zz)) * sy, (yz + wx) * sy, 0,\n (xz + wy) * sz, (yz - wx) * sz, (1. - (xx + yy)) * sz, 0,\n t.x, t.y, t.z, 1);\n}\nvec4 quatMultiply (vec4 a, vec4 b){\n vec4 quat;\n quat.x = a.x * b.w + a.w * b.x + a.y * b.z - a.z * b.y;\n quat.y = a.y * b.w + a.w * b.y + a.z * b.x - a.x * b.z;\n quat.z = a.z * b.w + a.w * b.z + a.x * b.y - a.y * b.x;\n quat.w = a.w * b.w - a.x * b.x - a.y * b.y - a.z * b.z;\n return quat;\n}\nvoid rotateVecFromQuat (inout vec3 v, vec4 q){\n float ix = q.w * v.x + q.y * v.z - q.z * v.y;\n float iy = q.w * v.y + q.z * v.x - q.x * v.z;\n float iz = q.w * v.z + q.x * v.y - q.y * v.x;\n float iw = -q.x * v.x - q.y * v.y - q.z * v.z;\n v.x = ix * q.w + iw * -q.x + iy * -q.z - iz * -q.y;\n v.y = iy * q.w + iw * -q.y + iz * -q.x - ix * -q.z;\n v.z = iz * q.w + iw * -q.z + ix * -q.y - iy * -q.x;\n}\nvec3 rotateInLocalSpace (vec3 pos, vec3 xAxis, vec3 yAxis, vec3 zAxis, vec4 q){\n vec4 viewQuat = quaternionFromAxis(xAxis, yAxis, zAxis);\n vec4 rotQuat = quatMultiply(viewQuat, q);\n rotateVecFromQuat(pos, rotQuat);\n return pos;\n}\nvoid rotateCorner (inout vec2 corner, float angle){\n float xOS = cos(angle) * corner.x - sin(angle) * corner.y;\n float yOS = sin(angle) * corner.x + cos(angle) * corner.y;\n corner.x = xOS;\n corner.y = yOS;\n}\nuniform Constants {\n vec4 mainTiling_Offset;\n vec4 frameTile_velLenScale;\n vec4 scale;\n};\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n};\nuniform CCLocal {\n highp mat4 cc_matWorld;\n highp mat4 cc_matWorldIT;\n};\nout vec2 uv;\nout vec4 color;\nvoid computeVertPos (inout vec4 pos, vec2 vertOffset, vec4 q, vec3 s\n#if CC_RENDER_MODE == 0 || CC_RENDER_MODE == 3\n , mat4 viewInv\n#endif\n#if CC_RENDER_MODE == 1\n , vec3 eye\n , vec4 velocity\n , float velocityScale\n , float lengthScale\n , float xIndex\n#endif\n) {\n#if CC_RENDER_MODE == 0\n vec3 viewSpaceVert = vec3(vertOffset.x * s.x, vertOffset.y * s.y, 0.);\n vec3 camX = normalize(vec3(viewInv[0][0], viewInv[1][0], viewInv[2][0]));\n vec3 camY = normalize(vec3(viewInv[0][1], viewInv[1][1], viewInv[2][1]));\n vec3 camZ = normalize(vec3(viewInv[0][2], viewInv[1][2], viewInv[2][2]));\n pos.xyz += rotateInLocalSpace(viewSpaceVert, camX, camY, camZ, q);\n#elif CC_RENDER_MODE == 1\n vec3 camRight = normalize(cross(pos.xyz - eye, velocity.xyz)) * s.x;\n vec3 camUp = velocity.xyz * velocityScale + normalize(velocity.xyz) * lengthScale * s.y;\n pos.xyz += (camRight * abs(vertOffset.x) * sign(vertOffset.y)) - camUp * xIndex;\n#elif CC_RENDER_MODE == 2\n vec3 viewSpaceVert = vec3(vertOffset.x * s.x, vertOffset.y * s.y, 0.);\n vec3 camX = vec3(1, 0, 0);\n vec3 camY = vec3(0, 0, -1);\n pos.xyz += rotateInLocalSpace(viewSpaceVert, camX, camY, cross(camX, camY), q);\n#elif CC_RENDER_MODE == 3\n vec2 viewSpaceVert = vec2(vertOffset.x * s.x, vertOffset.y * s.y);\n rotateCorner(viewSpaceVert, q.z);\n vec3 camX = normalize(vec3(cc_matView[0][0], cc_matView[1][0], cc_matView[2][0]));\n vec3 camY = vec3(0, 1, 0);\n vec3 offset = camX * viewSpaceVert.x + camY * viewSpaceVert.y;\n pos.xyz += offset;\n#else\n pos.x += vertOffset.x;\n pos.y += vertOffset.y;\n#endif\n}\nvec2 computeUV (float frameIndex, vec2 vertIndex, vec2 frameTile){\n vec2 aniUV = vec2(0, floor(frameIndex * frameTile.y));\n aniUV.x = floor(frameIndex * frameTile.x * frameTile.y - aniUV.y * frameTile.x);\n#if CC_RENDER_MODE != 4\n vertIndex.y = 1. - vertIndex.y;\n#endif\n return (aniUV.xy + vertIndex) / vec2(frameTile.x, frameTile.y);\n}\nuniform SampleConstants {\n vec4 u_sampleInfo;\n};\nuniform TickConstants {\n vec4 u_worldRot;\n vec4 u_timeDelta;\n};\nin vec4 a_position_starttime;\nin vec4 a_size_uv;\nin vec4 a_rotation_uv;\nin vec4 a_color;\nin vec4 a_dir_life;\nin float a_rndSeed;\n#if CC_RENDER_MODE == 4\n in vec3 a_texCoord;\n in vec3 a_texCoord3;\n in vec3 a_normal;\n in vec4 a_color1;\n#endif\nvec3 unpackCurveData (sampler2D tex, vec2 coord) {\n vec4 a = texture(tex, coord);\n vec4 b = texture(tex, coord + u_sampleInfo.y);\n float c = fract(coord.x * u_sampleInfo.x);\n return mix(a.xyz, b.xyz, c);\n}\nvec3 unpackCurveData (sampler2D tex, vec2 coord, out float w) {\n vec4 a = texture(tex, coord);\n vec4 b = texture(tex, coord + u_sampleInfo.y);\n float c = fract(coord.x * u_sampleInfo.x);\n w = mix(a.w, b.w, c);\n return mix(a.xyz, b.xyz, c);\n}\nfloat pseudoRandom (float seed) {\n seed = mod(seed, 233280.);\n float q = (seed * 9301. + 49297.) / 233280.;\n return fract(q);\n}\n#if COLOR_OVER_TIME_MODULE_ENABLE\n uniform sampler2D color_over_time_tex0;\n uniform ColorConstant {\n int u_color_mode;\n };\n#endif\n#if ROTATION_OVER_TIME_MODULE_ENABLE\n uniform sampler2D rotation_over_time_tex0;\n uniform RotationConstant {\n int u_rotation_mode;\n };\n#endif\n#if SIZE_OVER_TIME_MODULE_ENABLE\n uniform sampler2D size_over_time_tex0;\n uniform SizeConstant {\n int u_size_mode;\n };\n#endif\n#if FORCE_OVER_TIME_MODULE_ENABLE\n uniform sampler2D force_over_time_tex0;\n uniform ForceConstant {\n int u_force_mode;\n int u_force_space;\n };\n#endif\n#if VELOCITY_OVER_TIME_MODULE_ENABLE\n uniform sampler2D velocity_over_time_tex0;\n uniform VelocityConstant {\n int u_velocity_mode;\n int u_velocity_space;\n };\n#endif\n#if TEXTURE_ANIMATION_MODULE_ENABLE\n uniform sampler2D texture_animation_tex0;\n uniform AnimationConstant {\n vec4 u_anim_info;\n };\n#endif\nfloat repeat (float t, float length) {\n return t - floor(t / length) * length;\n}\nvec4 rotateQuat (vec4 p, vec4 q) {\n vec3 iv = cross(q.xyz, p.xyz) + q.w * p.xyz;\n vec3 res = p.xyz + 2.0 * cross(q.xyz, iv);\n return vec4(res.xyz, p.w);\n}\nvec4 gpvs_main () {\n float activeTime = u_timeDelta.x - a_position_starttime.w;\n float normalizedTime = clamp(activeTime / a_dir_life.w, 0.0, 1.0);\n vec2 timeCoord0 = vec2(normalizedTime, 0.);\n vec2 timeCoord1 = vec2(normalizedTime, 1.);\n #if CC_RENDER_MODE == 4\n vec2 vertIdx = vec2(a_texCoord.x, a_texCoord.y);\n #else\n vec2 vertIdx = vec2(a_size_uv.w, a_rotation_uv.w);\n #endif\n vec4 velocity = vec4(a_dir_life.xyz, 0.);\n vec4 pos = vec4(a_position_starttime.xyz, 1.);\n vec3 size = a_size_uv.xyz;\n #if SIZE_OVER_TIME_MODULE_ENABLE\n if (u_size_mode == 1) {\n size *= unpackCurveData(size_over_time_tex0, timeCoord0);\n } else {\n vec3 size_0 = unpackCurveData(size_over_time_tex0, timeCoord0);\n vec3 size_1 = unpackCurveData(size_over_time_tex0, timeCoord1);\n float factor_s = pseudoRandom(a_rndSeed + 39825.);\n size *= mix(size_0, size_1, factor_s);\n }\n #endif\n vec3 compScale = scale.xyz * size;\n #if FORCE_OVER_TIME_MODULE_ENABLE\n vec3 forceAnim = vec3(0.);\n if (u_force_mode == 1) {\n forceAnim = unpackCurveData(force_over_time_tex0, timeCoord0);\n } else {\n vec3 force_0 = unpackCurveData(force_over_time_tex0, timeCoord0);\n vec3 force_1 = unpackCurveData(force_over_time_tex0, timeCoord1);\n float factor_f = pseudoRandom(a_rndSeed + 212165.);\n forceAnim = mix(force_0, force_1, factor_f);\n }\n vec4 forceTrack = vec4(forceAnim, 0.);\n if (u_force_space == 0) {\n forceTrack = rotateQuat(forceTrack, u_worldRot);\n }\n velocity.xyz += forceTrack.xyz;\n #endif\n #if VELOCITY_OVER_TIME_MODULE_ENABLE\n float speedModifier0 = 1.;\n float speedModifier1 = 1.;\n vec3 velocityAnim = vec3(0.);\n if (u_velocity_mode == 1) {\n velocityAnim = unpackCurveData(velocity_over_time_tex0, timeCoord0, speedModifier0);\n } else {\n vec3 vectory_0 = unpackCurveData(velocity_over_time_tex0, timeCoord0, speedModifier0);\n vec3 vectory_1 = unpackCurveData(velocity_over_time_tex0, timeCoord1, speedModifier1);\n float factor_v = pseudoRandom(a_rndSeed + 197866.);\n velocityAnim = mix(vectory_0, vectory_1, factor_v);\n speedModifier0 = mix(speedModifier0, speedModifier1, factor_v);\n }\n vec4 velocityTrack = vec4(velocityAnim, 0.);\n if (u_velocity_space == 0) {\n velocityTrack = rotateQuat(velocityTrack, u_worldRot);\n }\n velocity.xyz += velocityTrack.xyz;\n velocity.xyz *= speedModifier0;\n #endif\n pos.xyz += velocity.xyz * normalizedTime * a_dir_life.w;\n #if !CC_USE_WORLD_SPACE\n pos = cc_matWorld * pos;\n #if CC_RENDER_MODE == 1\n velocity = rotateQuat(velocity, u_worldRot);\n #endif\n #endif\n vec3 rotation = a_rotation_uv.xyz;\n #if ROTATION_OVER_TIME_MODULE_ENABLE\n if (u_rotation_mode == 1) {\n rotation += unpackCurveData(rotation_over_time_tex0, timeCoord0) * normalizedTime * a_dir_life.w;\n } else {\n vec3 rotation_0 = unpackCurveData(rotation_over_time_tex0, timeCoord0);\n vec3 rotation_1 = unpackCurveData(rotation_over_time_tex0, timeCoord1);\n float factor_r = pseudoRandom(a_rndSeed + 125292.);\n rotation += mix(rotation_0, rotation_1, factor_r) * normalizedTime * a_dir_life.w;\n }\n #endif\n #if COLOR_OVER_TIME_MODULE_ENABLE\n if (u_color_mode == 1) {\n color = a_color * texture(color_over_time_tex0, timeCoord0);\n } else {\n vec4 color_0 = texture(color_over_time_tex0, timeCoord0);\n vec4 color_1 = texture(color_over_time_tex0, timeCoord1);\n float factor_c = pseudoRandom(a_rndSeed + 91041.);\n color = a_color * mix(color_0, color_1, factor_c);\n }\n #else\n color = a_color;\n #endif\n #if CC_RENDER_MODE != 4\n vec2 cornerOffset = vec2((vertIdx - 0.5));\n #if CC_RENDER_MODE == 0\n vec3 rotEuler = rotation.xyz;\n #elif CC_RENDER_MODE == 1\n vec3 rotEuler = vec3(0.);\n #else\n vec3 rotEuler = vec3(0., 0., rotation.z);\n #endif\n computeVertPos(pos, cornerOffset, quaternionFromEuler(rotEuler), compScale\n #if CC_RENDER_MODE == 0 || CC_RENDER_MODE == 3\n , cc_matViewInv\n #endif\n #if CC_RENDER_MODE == 1\n , cc_cameraPos.xyz\n , velocity\n , frameTile_velLenScale.z\n , frameTile_velLenScale.w\n , a_size_uv.w\n #endif\n );\n #else\n mat4 xformNoScale = matrixFromRT(quaternionFromEuler(rotation), pos.xyz);\n mat4 xform = matFromRTS(quaternionFromEuler(rotation), pos.xyz, compScale);\n pos = xform * vec4(a_texCoord3, 1);\n vec4 normal = xformNoScale * vec4(a_normal, 0);\n color *= a_color1;\n #endif\n pos = cc_matViewProj * pos;\n float frameIndex = 0.;\n #if TEXTURE_ANIMATION_MODULE_ENABLE\n float startFrame = 0.;\n vec3 frameInfo = vec3(0.);\n if (int(u_anim_info.x) == 1) {\n frameInfo = unpackCurveData(texture_animation_tex0, timeCoord0);\n } else {\n vec3 frameInfo0 = unpackCurveData(texture_animation_tex0, timeCoord0);\n vec3 frameInfo1 = unpackCurveData(texture_animation_tex0, timeCoord1);\n float factor_t = pseudoRandom(a_rndSeed + 90794.);\n frameInfo = mix(frameInfo0, frameInfo1, factor_t);\n }\n startFrame = frameInfo.x / u_anim_info.y;\n frameIndex = repeat(u_anim_info.z * (frameInfo.y + startFrame), 1.);\n #endif\n uv = computeUV(frameIndex, vertIdx, frameTile_velLenScale.xy) * mainTiling_Offset.xy + mainTiling_Offset.zw;\n return pos;\n}\nvoid main() { gl_Position = gpvs_main(); }`, - "frag": `\nprecision mediump float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n};\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\n}\nvec4 CCFragOutput (vec4 color) {\n #if CC_USE_HDR\n color.rgb = mix(color.rgb, SRGBToLinear(color.rgb) * cc_exposure.w, vec3(cc_exposure.z));\n #endif\n return color;\n}\nin vec2 uv;\nin vec4 color;\nuniform sampler2D mainTexture;\nuniform FragConstants {\n vec4 tintColor;\n};\nvec4 add () {\n vec4 col = 2.0 * color * tintColor * texture(mainTexture, uv);\n return CCFragOutput(col);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = add(); }` + "vert": `\nprecision mediump float;\nvec4 quaternionFromAxis (vec3 xAxis,vec3 yAxis,vec3 zAxis){\n mat3 m = mat3(xAxis,yAxis,zAxis);\n float trace = m[0][0] + m[1][1] + m[2][2];\n vec4 quat;\n if (trace > 0.) {\n float s = 0.5 / sqrt(trace + 1.0);\n quat.w = 0.25 / s;\n quat.x = (m[2][1] - m[1][2]) * s;\n quat.y = (m[0][2] - m[2][0]) * s;\n quat.z = (m[1][0] - m[0][1]) * s;\n } else if ((m[0][0] > m[1][1]) && (m[0][0] > m[2][2])) {\n float s = 2.0 * sqrt(1.0 + m[0][0] - m[1][1] - m[2][2]);\n quat.w = (m[2][1] - m[1][2]) / s;\n quat.x = 0.25 * s;\n quat.y = (m[0][1] + m[1][0]) / s;\n quat.z = (m[0][2] + m[2][0]) / s;\n } else if (m[1][1] > m[2][2]) {\n float s = 2.0 * sqrt(1.0 + m[1][1] - m[0][0] - m[2][2]);\n quat.w = (m[0][2] - m[2][0]) / s;\n quat.x = (m[0][1] + m[1][0]) / s;\n quat.y = 0.25 * s;\n quat.z = (m[1][2] + m[2][1]) / s;\n } else {\n float s = 2.0 * sqrt(1.0 + m[2][2] - m[0][0] - m[1][1]);\n quat.w = (m[1][0] - m[0][1]) / s;\n quat.x = (m[0][2] + m[2][0]) / s;\n quat.y = (m[1][2] + m[2][1]) / s;\n quat.z = 0.25 * s;\n }\n float len = quat.x * quat.x + quat.y * quat.y + quat.z * quat.z + quat.w * quat.w;\n if (len > 0.) {\n len = 1. / sqrt(len);\n quat.x = quat.x * len;\n quat.y = quat.y * len;\n quat.z = quat.z * len;\n quat.w = quat.w * len;\n }\n return quat;\n}\nvec4 quaternionFromEuler (vec3 angle){\n float x = angle.x / 2.;\n float y = angle.y / 2.;\n float z = angle.z / 2.;\n float sx = sin(x);\n float cx = cos(x);\n float sy = sin(y);\n float cy = cos(y);\n float sz = sin(z);\n float cz = cos(z);\n vec4 quat = vec4(0);\n quat.x = sx * cy * cz + cx * sy * sz;\n quat.y = cx * sy * cz + sx * cy * sz;\n quat.z = cx * cy * sz - sx * sy * cz;\n quat.w = cx * cy * cz - sx * sy * sz;\n return quat;\n}\nmat4 matrixFromRT (vec4 q, vec3 p){\n float x2 = q.x + q.x;\n float y2 = q.y + q.y;\n float z2 = q.z + q.z;\n float xx = q.x * x2;\n float xy = q.x * y2;\n float xz = q.x * z2;\n float yy = q.y * y2;\n float yz = q.y * z2;\n float zz = q.z * z2;\n float wx = q.w * x2;\n float wy = q.w * y2;\n float wz = q.w * z2;\n return mat4(\n 1. - (yy + zz), xy + wz, xz - wy, 0,\n xy - wz, 1. - (xx + zz), yz + wx, 0,\n xz + wy, yz - wx, 1. - (xx + yy), 0,\n p.x, p.y, p.z, 1\n );\n}\nmat4 matFromRTS (vec4 q, vec3 t, vec3 s){\n float x = q.x, y = q.y, z = q.z, w = q.w;\n float x2 = x + x;\n float y2 = y + y;\n float z2 = z + z;\n float xx = x * x2;\n float xy = x * y2;\n float xz = x * z2;\n float yy = y * y2;\n float yz = y * z2;\n float zz = z * z2;\n float wx = w * x2;\n float wy = w * y2;\n float wz = w * z2;\n float sx = s.x;\n float sy = s.y;\n float sz = s.z;\n return mat4((1. - (yy + zz)) * sx, (xy + wz) * sx, (xz - wy) * sx, 0,\n (xy - wz) * sy, (1. - (xx + zz)) * sy, (yz + wx) * sy, 0,\n (xz + wy) * sz, (yz - wx) * sz, (1. - (xx + yy)) * sz, 0,\n t.x, t.y, t.z, 1);\n}\nvec4 quatMultiply (vec4 a, vec4 b){\n vec4 quat;\n quat.x = a.x * b.w + a.w * b.x + a.y * b.z - a.z * b.y;\n quat.y = a.y * b.w + a.w * b.y + a.z * b.x - a.x * b.z;\n quat.z = a.z * b.w + a.w * b.z + a.x * b.y - a.y * b.x;\n quat.w = a.w * b.w - a.x * b.x - a.y * b.y - a.z * b.z;\n return quat;\n}\nvoid rotateVecFromQuat (inout vec3 v, vec4 q){\n float ix = q.w * v.x + q.y * v.z - q.z * v.y;\n float iy = q.w * v.y + q.z * v.x - q.x * v.z;\n float iz = q.w * v.z + q.x * v.y - q.y * v.x;\n float iw = -q.x * v.x - q.y * v.y - q.z * v.z;\n v.x = ix * q.w + iw * -q.x + iy * -q.z - iz * -q.y;\n v.y = iy * q.w + iw * -q.y + iz * -q.x - ix * -q.z;\n v.z = iz * q.w + iw * -q.z + ix * -q.y - iy * -q.x;\n}\nvec3 rotateInLocalSpace (vec3 pos, vec3 xAxis, vec3 yAxis, vec3 zAxis, vec4 q){\n vec4 viewQuat = quaternionFromAxis(xAxis, yAxis, zAxis);\n vec4 rotQuat = quatMultiply(viewQuat, q);\n rotateVecFromQuat(pos, rotQuat);\n return pos;\n}\nvoid rotateCorner (inout vec2 corner, float angle){\n float xOS = cos(angle) * corner.x - sin(angle) * corner.y;\n float yOS = sin(angle) * corner.x + cos(angle) * corner.y;\n corner.x = xOS;\n corner.y = yOS;\n}\nuniform Constants {\n vec4 mainTiling_Offset;\n vec4 frameTile_velLenScale;\n vec4 scale;\n};\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\nuniform CCLocal {\n highp mat4 cc_matWorld;\n highp mat4 cc_matWorldIT;\n highp vec4 cc_lightingMapUVParam;\n};\nout vec2 uv;\nout vec4 color;\nvoid computeVertPos (inout vec4 pos, vec2 vertOffset, vec4 q, vec3 s\n#if CC_RENDER_MODE == 0 || CC_RENDER_MODE == 3\n , mat4 viewInv\n#endif\n#if CC_RENDER_MODE == 1\n , vec3 eye\n , vec4 velocity\n , float velocityScale\n , float lengthScale\n , float xIndex\n#endif\n) {\n#if CC_RENDER_MODE == 0\n vec3 viewSpaceVert = vec3(vertOffset.x * s.x, vertOffset.y * s.y, 0.);\n vec3 camX = normalize(vec3(viewInv[0][0], viewInv[1][0], viewInv[2][0]));\n vec3 camY = normalize(vec3(viewInv[0][1], viewInv[1][1], viewInv[2][1]));\n vec3 camZ = normalize(vec3(viewInv[0][2], viewInv[1][2], viewInv[2][2]));\n pos.xyz += rotateInLocalSpace(viewSpaceVert, camX, camY, camZ, q);\n#elif CC_RENDER_MODE == 1\n vec3 camRight = normalize(cross(pos.xyz - eye, velocity.xyz)) * s.x;\n vec3 camUp = velocity.xyz * velocityScale + normalize(velocity.xyz) * lengthScale * s.y;\n pos.xyz += (camRight * abs(vertOffset.x) * sign(vertOffset.y)) - camUp * xIndex;\n#elif CC_RENDER_MODE == 2\n vec3 viewSpaceVert = vec3(vertOffset.x * s.x, vertOffset.y * s.y, 0.);\n vec3 camX = vec3(1, 0, 0);\n vec3 camY = vec3(0, 0, -1);\n pos.xyz += rotateInLocalSpace(viewSpaceVert, camX, camY, cross(camX, camY), q);\n#elif CC_RENDER_MODE == 3\n vec2 viewSpaceVert = vec2(vertOffset.x * s.x, vertOffset.y * s.y);\n rotateCorner(viewSpaceVert, q.z);\n vec3 camX = normalize(vec3(cc_matView[0][0], cc_matView[1][0], cc_matView[2][0]));\n vec3 camY = vec3(0, 1, 0);\n vec3 offset = camX * viewSpaceVert.x + camY * viewSpaceVert.y;\n pos.xyz += offset;\n#else\n pos.x += vertOffset.x;\n pos.y += vertOffset.y;\n#endif\n}\nvec2 computeUV (float frameIndex, vec2 vertIndex, vec2 frameTile){\n vec2 aniUV = vec2(0, floor(frameIndex * frameTile.y));\n aniUV.x = floor(frameIndex * frameTile.x * frameTile.y - aniUV.y * frameTile.x);\n#if CC_RENDER_MODE != 4\n vertIndex.y = 1. - vertIndex.y;\n#endif\n return (aniUV.xy + vertIndex) / vec2(frameTile.x, frameTile.y);\n}\nuniform SampleConstants {\n vec4 u_sampleInfo;\n};\nuniform TickConstants {\n vec4 u_worldRot;\n vec4 u_timeDelta;\n};\nin vec4 a_position_starttime;\nin vec4 a_size_uv;\nin vec4 a_rotation_uv;\nin vec4 a_color;\nin vec4 a_dir_life;\nin float a_rndSeed;\n#if CC_RENDER_MODE == 4\n in vec3 a_texCoord;\n in vec3 a_texCoord3;\n in vec3 a_normal;\n in vec4 a_color1;\n#endif\nvec3 unpackCurveData (sampler2D tex, vec2 coord) {\n vec4 a = texture(tex, coord);\n vec4 b = texture(tex, coord + u_sampleInfo.y);\n float c = fract(coord.x * u_sampleInfo.x);\n return mix(a.xyz, b.xyz, c);\n}\nvec3 unpackCurveData (sampler2D tex, vec2 coord, out float w) {\n vec4 a = texture(tex, coord);\n vec4 b = texture(tex, coord + u_sampleInfo.y);\n float c = fract(coord.x * u_sampleInfo.x);\n w = mix(a.w, b.w, c);\n return mix(a.xyz, b.xyz, c);\n}\nfloat pseudoRandom (float seed) {\n seed = mod(seed, 233280.);\n float q = (seed * 9301. + 49297.) / 233280.;\n return fract(q);\n}\n#if COLOR_OVER_TIME_MODULE_ENABLE\n uniform sampler2D color_over_time_tex0;\n uniform ColorConstant {\n int u_color_mode;\n };\n#endif\n#if ROTATION_OVER_TIME_MODULE_ENABLE\n uniform sampler2D rotation_over_time_tex0;\n uniform RotationConstant {\n int u_rotation_mode;\n };\n#endif\n#if SIZE_OVER_TIME_MODULE_ENABLE\n uniform sampler2D size_over_time_tex0;\n uniform SizeConstant {\n int u_size_mode;\n };\n#endif\n#if FORCE_OVER_TIME_MODULE_ENABLE\n uniform sampler2D force_over_time_tex0;\n uniform ForceConstant {\n int u_force_mode;\n int u_force_space;\n };\n#endif\n#if VELOCITY_OVER_TIME_MODULE_ENABLE\n uniform sampler2D velocity_over_time_tex0;\n uniform VelocityConstant {\n int u_velocity_mode;\n int u_velocity_space;\n };\n#endif\n#if TEXTURE_ANIMATION_MODULE_ENABLE\n uniform sampler2D texture_animation_tex0;\n uniform AnimationConstant {\n vec4 u_anim_info;\n };\n#endif\nfloat repeat (float t, float length) {\n return t - floor(t / length) * length;\n}\nvec4 rotateQuat (vec4 p, vec4 q) {\n vec3 iv = cross(q.xyz, p.xyz) + q.w * p.xyz;\n vec3 res = p.xyz + 2.0 * cross(q.xyz, iv);\n return vec4(res.xyz, p.w);\n}\nvec4 gpvs_main () {\n float activeTime = u_timeDelta.x - a_position_starttime.w;\n float normalizedTime = clamp(activeTime / a_dir_life.w, 0.0, 1.0);\n vec2 timeCoord0 = vec2(normalizedTime, 0.);\n vec2 timeCoord1 = vec2(normalizedTime, 1.);\n #if CC_RENDER_MODE == 4\n vec2 vertIdx = vec2(a_texCoord.x, a_texCoord.y);\n #else\n vec2 vertIdx = vec2(a_size_uv.w, a_rotation_uv.w);\n #endif\n vec4 velocity = vec4(a_dir_life.xyz, 0.);\n vec4 pos = vec4(a_position_starttime.xyz, 1.);\n vec3 size = a_size_uv.xyz;\n #if SIZE_OVER_TIME_MODULE_ENABLE\n if (u_size_mode == 1) {\n size *= unpackCurveData(size_over_time_tex0, timeCoord0);\n } else {\n vec3 size_0 = unpackCurveData(size_over_time_tex0, timeCoord0);\n vec3 size_1 = unpackCurveData(size_over_time_tex0, timeCoord1);\n float factor_s = pseudoRandom(a_rndSeed + 39825.);\n size *= mix(size_0, size_1, factor_s);\n }\n #endif\n vec3 compScale = scale.xyz * size;\n #if FORCE_OVER_TIME_MODULE_ENABLE\n vec3 forceAnim = vec3(0.);\n if (u_force_mode == 1) {\n forceAnim = unpackCurveData(force_over_time_tex0, timeCoord0);\n } else {\n vec3 force_0 = unpackCurveData(force_over_time_tex0, timeCoord0);\n vec3 force_1 = unpackCurveData(force_over_time_tex0, timeCoord1);\n float factor_f = pseudoRandom(a_rndSeed + 212165.);\n forceAnim = mix(force_0, force_1, factor_f);\n }\n vec4 forceTrack = vec4(forceAnim, 0.);\n if (u_force_space == 0) {\n forceTrack = rotateQuat(forceTrack, u_worldRot);\n }\n velocity.xyz += forceTrack.xyz;\n #endif\n #if VELOCITY_OVER_TIME_MODULE_ENABLE\n float speedModifier0 = 1.;\n float speedModifier1 = 1.;\n vec3 velocityAnim = vec3(0.);\n if (u_velocity_mode == 1) {\n velocityAnim = unpackCurveData(velocity_over_time_tex0, timeCoord0, speedModifier0);\n } else {\n vec3 vectory_0 = unpackCurveData(velocity_over_time_tex0, timeCoord0, speedModifier0);\n vec3 vectory_1 = unpackCurveData(velocity_over_time_tex0, timeCoord1, speedModifier1);\n float factor_v = pseudoRandom(a_rndSeed + 197866.);\n velocityAnim = mix(vectory_0, vectory_1, factor_v);\n speedModifier0 = mix(speedModifier0, speedModifier1, factor_v);\n }\n vec4 velocityTrack = vec4(velocityAnim, 0.);\n if (u_velocity_space == 0) {\n velocityTrack = rotateQuat(velocityTrack, u_worldRot);\n }\n velocity.xyz += velocityTrack.xyz;\n velocity.xyz *= speedModifier0;\n #endif\n pos.xyz += velocity.xyz * normalizedTime * a_dir_life.w;\n #if !CC_USE_WORLD_SPACE\n pos = cc_matWorld * pos;\n #if CC_RENDER_MODE == 1\n velocity = rotateQuat(velocity, u_worldRot);\n #endif\n #endif\n vec3 rotation = a_rotation_uv.xyz;\n #if ROTATION_OVER_TIME_MODULE_ENABLE\n if (u_rotation_mode == 1) {\n rotation += unpackCurveData(rotation_over_time_tex0, timeCoord0) * normalizedTime * a_dir_life.w;\n } else {\n vec3 rotation_0 = unpackCurveData(rotation_over_time_tex0, timeCoord0);\n vec3 rotation_1 = unpackCurveData(rotation_over_time_tex0, timeCoord1);\n float factor_r = pseudoRandom(a_rndSeed + 125292.);\n rotation += mix(rotation_0, rotation_1, factor_r) * normalizedTime * a_dir_life.w;\n }\n #endif\n #if COLOR_OVER_TIME_MODULE_ENABLE\n if (u_color_mode == 1) {\n color = a_color * texture(color_over_time_tex0, timeCoord0);\n } else {\n vec4 color_0 = texture(color_over_time_tex0, timeCoord0);\n vec4 color_1 = texture(color_over_time_tex0, timeCoord1);\n float factor_c = pseudoRandom(a_rndSeed + 91041.);\n color = a_color * mix(color_0, color_1, factor_c);\n }\n #else\n color = a_color;\n #endif\n #if CC_RENDER_MODE != 4\n vec2 cornerOffset = vec2((vertIdx - 0.5));\n #if CC_RENDER_MODE == 0\n vec3 rotEuler = rotation.xyz;\n #elif CC_RENDER_MODE == 1\n vec3 rotEuler = vec3(0.);\n #else\n vec3 rotEuler = vec3(0., 0., rotation.z);\n #endif\n computeVertPos(pos, cornerOffset, quaternionFromEuler(rotEuler), compScale\n #if CC_RENDER_MODE == 0 || CC_RENDER_MODE == 3\n , cc_matViewInv\n #endif\n #if CC_RENDER_MODE == 1\n , cc_cameraPos.xyz\n , velocity\n , frameTile_velLenScale.z\n , frameTile_velLenScale.w\n , a_size_uv.w\n #endif\n );\n #else\n mat4 xformNoScale = matrixFromRT(quaternionFromEuler(rotation), pos.xyz);\n mat4 xform = matFromRTS(quaternionFromEuler(rotation), pos.xyz, compScale);\n pos = xform * vec4(a_texCoord3, 1);\n vec4 normal = xformNoScale * vec4(a_normal, 0);\n color *= a_color1;\n #endif\n pos = cc_matViewProj * pos;\n float frameIndex = 0.;\n #if TEXTURE_ANIMATION_MODULE_ENABLE\n float startFrame = 0.;\n vec3 frameInfo = vec3(0.);\n if (int(u_anim_info.x) == 1) {\n frameInfo = unpackCurveData(texture_animation_tex0, timeCoord0);\n } else {\n vec3 frameInfo0 = unpackCurveData(texture_animation_tex0, timeCoord0);\n vec3 frameInfo1 = unpackCurveData(texture_animation_tex0, timeCoord1);\n float factor_t = pseudoRandom(a_rndSeed + 90794.);\n frameInfo = mix(frameInfo0, frameInfo1, factor_t);\n }\n startFrame = frameInfo.x / u_anim_info.y;\n frameIndex = repeat(u_anim_info.z * (frameInfo.y + startFrame), 1.);\n #endif\n uv = computeUV(frameIndex, vertIdx, frameTile_velLenScale.xy) * mainTiling_Offset.xy + mainTiling_Offset.zw;\n return pos;\n}\nvoid main() { gl_Position = gpvs_main(); }`, + "frag": `\nprecision mediump float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\n}\nvec4 CCFragOutput (vec4 color) {\n #if CC_USE_HDR\n color.rgb = mix(color.rgb, SRGBToLinear(color.rgb) * cc_exposure.w, vec3(cc_exposure.z));\n #endif\n return color;\n}\nin vec2 uv;\nin vec4 color;\nuniform sampler2D mainTexture;\nuniform FragConstants {\n vec4 tintColor;\n};\nvec4 add () {\n vec4 col = 2.0 * color * tintColor * texture(mainTexture, uv);\n return CCFragOutput(col);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = add(); }` }, "glsl1": { "vert": `\nprecision mediump float;\nvec4 quaternionFromAxis (vec3 xAxis,vec3 yAxis,vec3 zAxis){\n mat3 m = mat3(xAxis,yAxis,zAxis);\n float trace = m[0][0] + m[1][1] + m[2][2];\n vec4 quat;\n if (trace > 0.) {\n float s = 0.5 / sqrt(trace + 1.0);\n quat.w = 0.25 / s;\n quat.x = (m[2][1] - m[1][2]) * s;\n quat.y = (m[0][2] - m[2][0]) * s;\n quat.z = (m[1][0] - m[0][1]) * s;\n } else if ((m[0][0] > m[1][1]) && (m[0][0] > m[2][2])) {\n float s = 2.0 * sqrt(1.0 + m[0][0] - m[1][1] - m[2][2]);\n quat.w = (m[2][1] - m[1][2]) / s;\n quat.x = 0.25 * s;\n quat.y = (m[0][1] + m[1][0]) / s;\n quat.z = (m[0][2] + m[2][0]) / s;\n } else if (m[1][1] > m[2][2]) {\n float s = 2.0 * sqrt(1.0 + m[1][1] - m[0][0] - m[2][2]);\n quat.w = (m[0][2] - m[2][0]) / s;\n quat.x = (m[0][1] + m[1][0]) / s;\n quat.y = 0.25 * s;\n quat.z = (m[1][2] + m[2][1]) / s;\n } else {\n float s = 2.0 * sqrt(1.0 + m[2][2] - m[0][0] - m[1][1]);\n quat.w = (m[1][0] - m[0][1]) / s;\n quat.x = (m[0][2] + m[2][0]) / s;\n quat.y = (m[1][2] + m[2][1]) / s;\n quat.z = 0.25 * s;\n }\n float len = quat.x * quat.x + quat.y * quat.y + quat.z * quat.z + quat.w * quat.w;\n if (len > 0.) {\n len = 1. / sqrt(len);\n quat.x = quat.x * len;\n quat.y = quat.y * len;\n quat.z = quat.z * len;\n quat.w = quat.w * len;\n }\n return quat;\n}\nvec4 quaternionFromEuler (vec3 angle){\n float x = angle.x / 2.;\n float y = angle.y / 2.;\n float z = angle.z / 2.;\n float sx = sin(x);\n float cx = cos(x);\n float sy = sin(y);\n float cy = cos(y);\n float sz = sin(z);\n float cz = cos(z);\n vec4 quat = vec4(0);\n quat.x = sx * cy * cz + cx * sy * sz;\n quat.y = cx * sy * cz + sx * cy * sz;\n quat.z = cx * cy * sz - sx * sy * cz;\n quat.w = cx * cy * cz - sx * sy * sz;\n return quat;\n}\nmat4 matrixFromRT (vec4 q, vec3 p){\n float x2 = q.x + q.x;\n float y2 = q.y + q.y;\n float z2 = q.z + q.z;\n float xx = q.x * x2;\n float xy = q.x * y2;\n float xz = q.x * z2;\n float yy = q.y * y2;\n float yz = q.y * z2;\n float zz = q.z * z2;\n float wx = q.w * x2;\n float wy = q.w * y2;\n float wz = q.w * z2;\n return mat4(\n 1. - (yy + zz), xy + wz, xz - wy, 0,\n xy - wz, 1. - (xx + zz), yz + wx, 0,\n xz + wy, yz - wx, 1. - (xx + yy), 0,\n p.x, p.y, p.z, 1\n );\n}\nmat4 matFromRTS (vec4 q, vec3 t, vec3 s){\n float x = q.x, y = q.y, z = q.z, w = q.w;\n float x2 = x + x;\n float y2 = y + y;\n float z2 = z + z;\n float xx = x * x2;\n float xy = x * y2;\n float xz = x * z2;\n float yy = y * y2;\n float yz = y * z2;\n float zz = z * z2;\n float wx = w * x2;\n float wy = w * y2;\n float wz = w * z2;\n float sx = s.x;\n float sy = s.y;\n float sz = s.z;\n return mat4((1. - (yy + zz)) * sx, (xy + wz) * sx, (xz - wy) * sx, 0,\n (xy - wz) * sy, (1. - (xx + zz)) * sy, (yz + wx) * sy, 0,\n (xz + wy) * sz, (yz - wx) * sz, (1. - (xx + yy)) * sz, 0,\n t.x, t.y, t.z, 1);\n}\nvec4 quatMultiply (vec4 a, vec4 b){\n vec4 quat;\n quat.x = a.x * b.w + a.w * b.x + a.y * b.z - a.z * b.y;\n quat.y = a.y * b.w + a.w * b.y + a.z * b.x - a.x * b.z;\n quat.z = a.z * b.w + a.w * b.z + a.x * b.y - a.y * b.x;\n quat.w = a.w * b.w - a.x * b.x - a.y * b.y - a.z * b.z;\n return quat;\n}\nvoid rotateVecFromQuat (inout vec3 v, vec4 q){\n float ix = q.w * v.x + q.y * v.z - q.z * v.y;\n float iy = q.w * v.y + q.z * v.x - q.x * v.z;\n float iz = q.w * v.z + q.x * v.y - q.y * v.x;\n float iw = -q.x * v.x - q.y * v.y - q.z * v.z;\n v.x = ix * q.w + iw * -q.x + iy * -q.z - iz * -q.y;\n v.y = iy * q.w + iw * -q.y + iz * -q.x - ix * -q.z;\n v.z = iz * q.w + iw * -q.z + ix * -q.y - iy * -q.x;\n}\nvec3 rotateInLocalSpace (vec3 pos, vec3 xAxis, vec3 yAxis, vec3 zAxis, vec4 q){\n vec4 viewQuat = quaternionFromAxis(xAxis, yAxis, zAxis);\n vec4 rotQuat = quatMultiply(viewQuat, q);\n rotateVecFromQuat(pos, rotQuat);\n return pos;\n}\nvoid rotateCorner (inout vec2 corner, float angle){\n float xOS = cos(angle) * corner.x - sin(angle) * corner.y;\n float yOS = sin(angle) * corner.x + cos(angle) * corner.y;\n corner.x = xOS;\n corner.y = yOS;\n}\nuniform vec4 mainTiling_Offset;\nuniform vec4 frameTile_velLenScale;\nuniform vec4 scale;\nuniform highp mat4 cc_matView;\nuniform highp mat4 cc_matViewInv;\nuniform highp mat4 cc_matViewProj;\nuniform highp vec4 cc_cameraPos;\nuniform highp mat4 cc_matWorld;\nvarying vec2 uv;\nvarying vec4 color;\nvoid computeVertPos (inout vec4 pos, vec2 vertOffset, vec4 q, vec3 s\n#if CC_RENDER_MODE == 0 || CC_RENDER_MODE == 3\n , mat4 viewInv\n#endif\n#if CC_RENDER_MODE == 1\n , vec3 eye\n , vec4 velocity\n , float velocityScale\n , float lengthScale\n , float xIndex\n#endif\n) {\n#if CC_RENDER_MODE == 0\n vec3 viewSpaceVert = vec3(vertOffset.x * s.x, vertOffset.y * s.y, 0.);\n vec3 camX = normalize(vec3(viewInv[0][0], viewInv[1][0], viewInv[2][0]));\n vec3 camY = normalize(vec3(viewInv[0][1], viewInv[1][1], viewInv[2][1]));\n vec3 camZ = normalize(vec3(viewInv[0][2], viewInv[1][2], viewInv[2][2]));\n pos.xyz += rotateInLocalSpace(viewSpaceVert, camX, camY, camZ, q);\n#elif CC_RENDER_MODE == 1\n vec3 camRight = normalize(cross(pos.xyz - eye, velocity.xyz)) * s.x;\n vec3 camUp = velocity.xyz * velocityScale + normalize(velocity.xyz) * lengthScale * s.y;\n pos.xyz += (camRight * abs(vertOffset.x) * sign(vertOffset.y)) - camUp * xIndex;\n#elif CC_RENDER_MODE == 2\n vec3 viewSpaceVert = vec3(vertOffset.x * s.x, vertOffset.y * s.y, 0.);\n vec3 camX = vec3(1, 0, 0);\n vec3 camY = vec3(0, 0, -1);\n pos.xyz += rotateInLocalSpace(viewSpaceVert, camX, camY, cross(camX, camY), q);\n#elif CC_RENDER_MODE == 3\n vec2 viewSpaceVert = vec2(vertOffset.x * s.x, vertOffset.y * s.y);\n rotateCorner(viewSpaceVert, q.z);\n vec3 camX = normalize(vec3(cc_matView[0][0], cc_matView[1][0], cc_matView[2][0]));\n vec3 camY = vec3(0, 1, 0);\n vec3 offset = camX * viewSpaceVert.x + camY * viewSpaceVert.y;\n pos.xyz += offset;\n#else\n pos.x += vertOffset.x;\n pos.y += vertOffset.y;\n#endif\n}\nvec2 computeUV (float frameIndex, vec2 vertIndex, vec2 frameTile){\n vec2 aniUV = vec2(0, floor(frameIndex * frameTile.y));\n aniUV.x = floor(frameIndex * frameTile.x * frameTile.y - aniUV.y * frameTile.x);\n#if CC_RENDER_MODE != 4\n vertIndex.y = 1. - vertIndex.y;\n#endif\n return (aniUV.xy + vertIndex) / vec2(frameTile.x, frameTile.y);\n}\nuniform vec4 u_sampleInfo;\nuniform vec4 u_worldRot;\nuniform vec4 u_timeDelta;\nattribute vec4 a_position_starttime;\nattribute vec4 a_size_uv;\nattribute vec4 a_rotation_uv;\nattribute vec4 a_color;\nattribute vec4 a_dir_life;\nattribute float a_rndSeed;\n#if CC_RENDER_MODE == 4\n attribute vec3 a_texCoord;\n attribute vec3 a_texCoord3;\n attribute vec3 a_normal;\n attribute vec4 a_color1;\n#endif\nvec3 unpackCurveData (sampler2D tex, vec2 coord) {\n vec4 a = texture2D(tex, coord);\n vec4 b = texture2D(tex, coord + u_sampleInfo.y);\n float c = fract(coord.x * u_sampleInfo.x);\n return mix(a.xyz, b.xyz, c);\n}\nvec3 unpackCurveData (sampler2D tex, vec2 coord, out float w) {\n vec4 a = texture2D(tex, coord);\n vec4 b = texture2D(tex, coord + u_sampleInfo.y);\n float c = fract(coord.x * u_sampleInfo.x);\n w = mix(a.w, b.w, c);\n return mix(a.xyz, b.xyz, c);\n}\nfloat pseudoRandom (float seed) {\n seed = mod(seed, 233280.);\n float q = (seed * 9301. + 49297.) / 233280.;\n return fract(q);\n}\n#if COLOR_OVER_TIME_MODULE_ENABLE\n uniform sampler2D color_over_time_tex0;\n uniform int u_color_mode;\n#endif\n#if ROTATION_OVER_TIME_MODULE_ENABLE\n uniform sampler2D rotation_over_time_tex0;\n uniform int u_rotation_mode;\n#endif\n#if SIZE_OVER_TIME_MODULE_ENABLE\n uniform sampler2D size_over_time_tex0;\n uniform int u_size_mode;\n#endif\n#if FORCE_OVER_TIME_MODULE_ENABLE\n uniform sampler2D force_over_time_tex0;\n uniform int u_force_mode;\nuniform int u_force_space;\n#endif\n#if VELOCITY_OVER_TIME_MODULE_ENABLE\n uniform sampler2D velocity_over_time_tex0;\n uniform int u_velocity_mode;\nuniform int u_velocity_space;\n#endif\n#if TEXTURE_ANIMATION_MODULE_ENABLE\n uniform sampler2D texture_animation_tex0;\n uniform vec4 u_anim_info;\n#endif\nfloat repeat (float t, float length) {\n return t - floor(t / length) * length;\n}\nvec4 rotateQuat (vec4 p, vec4 q) {\n vec3 iv = cross(q.xyz, p.xyz) + q.w * p.xyz;\n vec3 res = p.xyz + 2.0 * cross(q.xyz, iv);\n return vec4(res.xyz, p.w);\n}\nvec4 gpvs_main () {\n float activeTime = u_timeDelta.x - a_position_starttime.w;\n float normalizedTime = clamp(activeTime / a_dir_life.w, 0.0, 1.0);\n vec2 timeCoord0 = vec2(normalizedTime, 0.);\n vec2 timeCoord1 = vec2(normalizedTime, 1.);\n #if CC_RENDER_MODE == 4\n vec2 vertIdx = vec2(a_texCoord.x, a_texCoord.y);\n #else\n vec2 vertIdx = vec2(a_size_uv.w, a_rotation_uv.w);\n #endif\n vec4 velocity = vec4(a_dir_life.xyz, 0.);\n vec4 pos = vec4(a_position_starttime.xyz, 1.);\n vec3 size = a_size_uv.xyz;\n #if SIZE_OVER_TIME_MODULE_ENABLE\n if (u_size_mode == 1) {\n size *= unpackCurveData(size_over_time_tex0, timeCoord0);\n } else {\n vec3 size_0 = unpackCurveData(size_over_time_tex0, timeCoord0);\n vec3 size_1 = unpackCurveData(size_over_time_tex0, timeCoord1);\n float factor_s = pseudoRandom(a_rndSeed + 39825.);\n size *= mix(size_0, size_1, factor_s);\n }\n #endif\n vec3 compScale = scale.xyz * size;\n #if FORCE_OVER_TIME_MODULE_ENABLE\n vec3 forceAnim = vec3(0.);\n if (u_force_mode == 1) {\n forceAnim = unpackCurveData(force_over_time_tex0, timeCoord0);\n } else {\n vec3 force_0 = unpackCurveData(force_over_time_tex0, timeCoord0);\n vec3 force_1 = unpackCurveData(force_over_time_tex0, timeCoord1);\n float factor_f = pseudoRandom(a_rndSeed + 212165.);\n forceAnim = mix(force_0, force_1, factor_f);\n }\n vec4 forceTrack = vec4(forceAnim, 0.);\n if (u_force_space == 0) {\n forceTrack = rotateQuat(forceTrack, u_worldRot);\n }\n velocity.xyz += forceTrack.xyz;\n #endif\n #if VELOCITY_OVER_TIME_MODULE_ENABLE\n float speedModifier0 = 1.;\n float speedModifier1 = 1.;\n vec3 velocityAnim = vec3(0.);\n if (u_velocity_mode == 1) {\n velocityAnim = unpackCurveData(velocity_over_time_tex0, timeCoord0, speedModifier0);\n } else {\n vec3 vectory_0 = unpackCurveData(velocity_over_time_tex0, timeCoord0, speedModifier0);\n vec3 vectory_1 = unpackCurveData(velocity_over_time_tex0, timeCoord1, speedModifier1);\n float factor_v = pseudoRandom(a_rndSeed + 197866.);\n velocityAnim = mix(vectory_0, vectory_1, factor_v);\n speedModifier0 = mix(speedModifier0, speedModifier1, factor_v);\n }\n vec4 velocityTrack = vec4(velocityAnim, 0.);\n if (u_velocity_space == 0) {\n velocityTrack = rotateQuat(velocityTrack, u_worldRot);\n }\n velocity.xyz += velocityTrack.xyz;\n velocity.xyz *= speedModifier0;\n #endif\n pos.xyz += velocity.xyz * normalizedTime * a_dir_life.w;\n #if !CC_USE_WORLD_SPACE\n pos = cc_matWorld * pos;\n #if CC_RENDER_MODE == 1\n velocity = rotateQuat(velocity, u_worldRot);\n #endif\n #endif\n vec3 rotation = a_rotation_uv.xyz;\n #if ROTATION_OVER_TIME_MODULE_ENABLE\n if (u_rotation_mode == 1) {\n rotation += unpackCurveData(rotation_over_time_tex0, timeCoord0) * normalizedTime * a_dir_life.w;\n } else {\n vec3 rotation_0 = unpackCurveData(rotation_over_time_tex0, timeCoord0);\n vec3 rotation_1 = unpackCurveData(rotation_over_time_tex0, timeCoord1);\n float factor_r = pseudoRandom(a_rndSeed + 125292.);\n rotation += mix(rotation_0, rotation_1, factor_r) * normalizedTime * a_dir_life.w;\n }\n #endif\n #if COLOR_OVER_TIME_MODULE_ENABLE\n if (u_color_mode == 1) {\n color = a_color * texture2D(color_over_time_tex0, timeCoord0);\n } else {\n vec4 color_0 = texture2D(color_over_time_tex0, timeCoord0);\n vec4 color_1 = texture2D(color_over_time_tex0, timeCoord1);\n float factor_c = pseudoRandom(a_rndSeed + 91041.);\n color = a_color * mix(color_0, color_1, factor_c);\n }\n #else\n color = a_color;\n #endif\n #if CC_RENDER_MODE != 4\n vec2 cornerOffset = vec2((vertIdx - 0.5));\n #if CC_RENDER_MODE == 0\n vec3 rotEuler = rotation.xyz;\n #elif CC_RENDER_MODE == 1\n vec3 rotEuler = vec3(0.);\n #else\n vec3 rotEuler = vec3(0., 0., rotation.z);\n #endif\n computeVertPos(pos, cornerOffset, quaternionFromEuler(rotEuler), compScale\n #if CC_RENDER_MODE == 0 || CC_RENDER_MODE == 3\n , cc_matViewInv\n #endif\n #if CC_RENDER_MODE == 1\n , cc_cameraPos.xyz\n , velocity\n , frameTile_velLenScale.z\n , frameTile_velLenScale.w\n , a_size_uv.w\n #endif\n );\n #else\n mat4 xformNoScale = matrixFromRT(quaternionFromEuler(rotation), pos.xyz);\n mat4 xform = matFromRTS(quaternionFromEuler(rotation), pos.xyz, compScale);\n pos = xform * vec4(a_texCoord3, 1);\n vec4 normal = xformNoScale * vec4(a_normal, 0);\n color *= a_color1;\n #endif\n pos = cc_matViewProj * pos;\n float frameIndex = 0.;\n #if TEXTURE_ANIMATION_MODULE_ENABLE\n float startFrame = 0.;\n vec3 frameInfo = vec3(0.);\n if (int(u_anim_info.x) == 1) {\n frameInfo = unpackCurveData(texture_animation_tex0, timeCoord0);\n } else {\n vec3 frameInfo0 = unpackCurveData(texture_animation_tex0, timeCoord0);\n vec3 frameInfo1 = unpackCurveData(texture_animation_tex0, timeCoord1);\n float factor_t = pseudoRandom(a_rndSeed + 90794.);\n frameInfo = mix(frameInfo0, frameInfo1, factor_t);\n }\n startFrame = frameInfo.x / u_anim_info.y;\n frameIndex = repeat(u_anim_info.z * (frameInfo.y + startFrame), 1.);\n #endif\n uv = computeUV(frameIndex, vertIdx, frameTile_velLenScale.xy) * mainTiling_Offset.xy + mainTiling_Offset.zw;\n return pos;\n}\nvoid main() { gl_Position = gpvs_main(); }`, @@ -121,13 +121,13 @@ export default [ ]} ], "samplers": [ - { "name": "color_over_time_tex0", "type": 28, "count": 1, "defines": ["COLOR_OVER_TIME_MODULE_ENABLE"], "binding": 30 }, - { "name": "rotation_over_time_tex0", "type": 28, "count": 1, "defines": ["ROTATION_OVER_TIME_MODULE_ENABLE"], "binding": 31 }, - { "name": "size_over_time_tex0", "type": 28, "count": 1, "defines": ["SIZE_OVER_TIME_MODULE_ENABLE"], "binding": 32 }, - { "name": "force_over_time_tex0", "type": 28, "count": 1, "defines": ["FORCE_OVER_TIME_MODULE_ENABLE"], "binding": 33 }, - { "name": "velocity_over_time_tex0", "type": 28, "count": 1, "defines": ["VELOCITY_OVER_TIME_MODULE_ENABLE"], "binding": 34 }, - { "name": "texture_animation_tex0", "type": 28, "count": 1, "defines": ["TEXTURE_ANIMATION_MODULE_ENABLE"], "binding": 35 }, - { "name": "mainTexture", "type": 28, "count": 1, "defines": [], "binding": 36 } + { "name": "color_over_time_tex0", "type": 28, "count": 1, "defines": ["COLOR_OVER_TIME_MODULE_ENABLE"], "binding": 31 }, + { "name": "rotation_over_time_tex0", "type": 28, "count": 1, "defines": ["ROTATION_OVER_TIME_MODULE_ENABLE"], "binding": 32 }, + { "name": "size_over_time_tex0", "type": 28, "count": 1, "defines": ["SIZE_OVER_TIME_MODULE_ENABLE"], "binding": 33 }, + { "name": "force_over_time_tex0", "type": 28, "count": 1, "defines": ["FORCE_OVER_TIME_MODULE_ENABLE"], "binding": 34 }, + { "name": "velocity_over_time_tex0", "type": 28, "count": 1, "defines": ["VELOCITY_OVER_TIME_MODULE_ENABLE"], "binding": 35 }, + { "name": "texture_animation_tex0", "type": 28, "count": 1, "defines": ["TEXTURE_ANIMATION_MODULE_ENABLE"], "binding": 36 }, + { "name": "mainTexture", "type": 28, "count": 1, "defines": [], "binding": 37 } ], "attributes": [ { "name": "a_position_starttime", "type": 16, "count": 1, "defines": [], "format": 43, "location": 0 }, @@ -155,8 +155,8 @@ export default [ "name": "builtin-particle-trail|particle-trail:vs_main|tinted-fs:add", "hash": 535523547, "glsl3": { - "vert": `\nprecision mediump float;\nuniform Constants {\n vec4 mainTiling_Offset;\n vec4 frameTile_velLenScale;\n vec4 scale;\n};\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n};\nuniform CCLocal {\n highp mat4 cc_matWorld;\n highp mat4 cc_matWorldIT;\n};\nout vec2 uv;\nout vec4 color;\nin vec3 a_position;\nin vec4 a_texCoord;\nin vec3 a_texCoord1;\nin vec3 a_texCoord2;\nin vec4 a_color;\n#if CC_DRAW_WIRE_FRAME\n out vec3 vBarycentric;\n#endif\nvec4 vs_main() {\n highp vec4 pos = vec4(a_position, 1);\n vec4 velocity = vec4(a_texCoord1.xyz, 0);\n #if !CC_USE_WORLD_SPACE\n pos = cc_matWorld * pos;\n velocity = cc_matWorld * velocity;\n #endif\n float vertOffset = (a_texCoord.x - 0.5) * a_texCoord.y;\n vec3 camUp = normalize(cross(pos.xyz - cc_cameraPos.xyz, velocity.xyz));\n pos.xyz += camUp * vertOffset;\n pos = cc_matViewProj * pos;\n uv = a_texCoord.zw * mainTiling_Offset.xy + mainTiling_Offset.zw;;\n color = a_color;\n #if CC_DRAW_WIRE_FRAME\n vBarycentric = a_texCoord2;\n #endif\n return pos;\n}\nvoid main() { gl_Position = vs_main(); }`, - "frag": `\n precision mediump float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n};\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\n}\nvec4 CCFragOutput (vec4 color) {\n #if CC_USE_HDR\n color.rgb = mix(color.rgb, SRGBToLinear(color.rgb) * cc_exposure.w, vec3(cc_exposure.z));\n #endif\n return color;\n}\n in vec2 uv;\n in vec4 color;\n #if CC_DRAW_WIRE_FRAME\n in vec3 vBarycentric;\n #endif\n uniform sampler2D mainTexture;\n uniform FragConstants {\n vec4 tintColor;\n };\n vec4 add () {\n vec4 col = 2.0 * color * tintColor * texture(mainTexture, uv);\n#if CC_DRAW_WIRE_FRAME\n if (any(lessThan(vBarycentric, vec3(0.02)))) {\n col = vec4(0., 1., 1., 1.);\n }\n#endif\n return CCFragOutput(col);\n }\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = add(); }` + "vert": `\nprecision mediump float;\nuniform Constants {\n vec4 mainTiling_Offset;\n vec4 frameTile_velLenScale;\n vec4 scale;\n};\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\nuniform CCLocal {\n highp mat4 cc_matWorld;\n highp mat4 cc_matWorldIT;\n highp vec4 cc_lightingMapUVParam;\n};\nout vec2 uv;\nout vec4 color;\nin vec3 a_position;\nin vec4 a_texCoord;\nin vec3 a_texCoord1;\nin vec3 a_texCoord2;\nin vec4 a_color;\n#if CC_DRAW_WIRE_FRAME\n out vec3 vBarycentric;\n#endif\nvec4 vs_main() {\n highp vec4 pos = vec4(a_position, 1);\n vec4 velocity = vec4(a_texCoord1.xyz, 0);\n #if !CC_USE_WORLD_SPACE\n pos = cc_matWorld * pos;\n velocity = cc_matWorld * velocity;\n #endif\n float vertOffset = (a_texCoord.x - 0.5) * a_texCoord.y;\n vec3 camUp = normalize(cross(pos.xyz - cc_cameraPos.xyz, velocity.xyz));\n pos.xyz += camUp * vertOffset;\n pos = cc_matViewProj * pos;\n uv = a_texCoord.zw * mainTiling_Offset.xy + mainTiling_Offset.zw;;\n color = a_color;\n #if CC_DRAW_WIRE_FRAME\n vBarycentric = a_texCoord2;\n #endif\n return pos;\n}\nvoid main() { gl_Position = vs_main(); }`, + "frag": `\n precision mediump float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\n}\nvec4 CCFragOutput (vec4 color) {\n #if CC_USE_HDR\n color.rgb = mix(color.rgb, SRGBToLinear(color.rgb) * cc_exposure.w, vec3(cc_exposure.z));\n #endif\n return color;\n}\n in vec2 uv;\n in vec4 color;\n #if CC_DRAW_WIRE_FRAME\n in vec3 vBarycentric;\n #endif\n uniform sampler2D mainTexture;\n uniform FragConstants {\n vec4 tintColor;\n };\n vec4 add () {\n vec4 col = 2.0 * color * tintColor * texture(mainTexture, uv);\n#if CC_DRAW_WIRE_FRAME\n if (any(lessThan(vBarycentric, vec3(0.02)))) {\n col = vec4(0., 1., 1., 1.);\n }\n#endif\n return CCFragOutput(col);\n }\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = add(); }` }, "glsl1": { "vert": `\nprecision mediump float;\nuniform vec4 mainTiling_Offset;\nuniform highp mat4 cc_matViewProj;\nuniform highp vec4 cc_cameraPos;\nuniform highp mat4 cc_matWorld;\nvarying vec2 uv;\nvarying vec4 color;\nattribute vec3 a_position;\nattribute vec4 a_texCoord;\nattribute vec3 a_texCoord1;\nattribute vec3 a_texCoord2;\nattribute vec4 a_color;\n#if CC_DRAW_WIRE_FRAME\n varying vec3 vBarycentric;\n#endif\nvec4 vs_main() {\n highp vec4 pos = vec4(a_position, 1);\n vec4 velocity = vec4(a_texCoord1.xyz, 0);\n #if !CC_USE_WORLD_SPACE\n pos = cc_matWorld * pos;\n velocity = cc_matWorld * velocity;\n #endif\n float vertOffset = (a_texCoord.x - 0.5) * a_texCoord.y;\n vec3 camUp = normalize(cross(pos.xyz - cc_cameraPos.xyz, velocity.xyz));\n pos.xyz += camUp * vertOffset;\n pos = cc_matViewProj * pos;\n uv = a_texCoord.zw * mainTiling_Offset.xy + mainTiling_Offset.zw;;\n color = a_color;\n #if CC_DRAW_WIRE_FRAME\n vBarycentric = a_texCoord2;\n #endif\n return pos;\n}\nvoid main() { gl_Position = vs_main(); }`, @@ -167,7 +167,7 @@ export default [ "locals": { "blocks": [{ "name": "CCLocal", "defines": [] }], "samplers": [] } }, "defines": [ - { "name": "CC_RENDER_MODE", "type": "number", "range": [0, 4] }, + { "name": "CC_RENDER_MODE", "type": "number", "dummyDependency": true, "range": [0, 4] }, { "name": "CC_DRAW_WIRE_FRAME", "type": "boolean" }, { "name": "CC_USE_WORLD_SPACE", "type": "boolean" }, { "name": "CC_USE_HDR", "type": "boolean" } @@ -183,7 +183,7 @@ export default [ ]} ], "samplers": [ - { "name": "mainTexture", "type": 28, "count": 1, "defines": [], "binding": 30 } + { "name": "mainTexture", "type": 28, "count": 1, "defines": [], "binding": 31 } ], "attributes": [ { "name": "a_position", "type": 15, "count": 1, "defines": [], "format": 32, "location": 0 }, @@ -206,8 +206,8 @@ export default [ "name": "builtin-particle|particle-vs-legacy:lpvs_main|tinted-fs:add", "hash": 2171161221, "glsl3": { - "vert": `\nprecision highp float;\nvec4 quaternionFromAxis (vec3 xAxis,vec3 yAxis,vec3 zAxis){\n mat3 m = mat3(xAxis,yAxis,zAxis);\n float trace = m[0][0] + m[1][1] + m[2][2];\n vec4 quat;\n if (trace > 0.) {\n float s = 0.5 / sqrt(trace + 1.0);\n quat.w = 0.25 / s;\n quat.x = (m[2][1] - m[1][2]) * s;\n quat.y = (m[0][2] - m[2][0]) * s;\n quat.z = (m[1][0] - m[0][1]) * s;\n } else if ((m[0][0] > m[1][1]) && (m[0][0] > m[2][2])) {\n float s = 2.0 * sqrt(1.0 + m[0][0] - m[1][1] - m[2][2]);\n quat.w = (m[2][1] - m[1][2]) / s;\n quat.x = 0.25 * s;\n quat.y = (m[0][1] + m[1][0]) / s;\n quat.z = (m[0][2] + m[2][0]) / s;\n } else if (m[1][1] > m[2][2]) {\n float s = 2.0 * sqrt(1.0 + m[1][1] - m[0][0] - m[2][2]);\n quat.w = (m[0][2] - m[2][0]) / s;\n quat.x = (m[0][1] + m[1][0]) / s;\n quat.y = 0.25 * s;\n quat.z = (m[1][2] + m[2][1]) / s;\n } else {\n float s = 2.0 * sqrt(1.0 + m[2][2] - m[0][0] - m[1][1]);\n quat.w = (m[1][0] - m[0][1]) / s;\n quat.x = (m[0][2] + m[2][0]) / s;\n quat.y = (m[1][2] + m[2][1]) / s;\n quat.z = 0.25 * s;\n }\n float len = quat.x * quat.x + quat.y * quat.y + quat.z * quat.z + quat.w * quat.w;\n if (len > 0.) {\n len = 1. / sqrt(len);\n quat.x = quat.x * len;\n quat.y = quat.y * len;\n quat.z = quat.z * len;\n quat.w = quat.w * len;\n }\n return quat;\n}\nvec4 quaternionFromEuler (vec3 angle){\n float x = angle.x / 2.;\n float y = angle.y / 2.;\n float z = angle.z / 2.;\n float sx = sin(x);\n float cx = cos(x);\n float sy = sin(y);\n float cy = cos(y);\n float sz = sin(z);\n float cz = cos(z);\n vec4 quat = vec4(0);\n quat.x = sx * cy * cz + cx * sy * sz;\n quat.y = cx * sy * cz + sx * cy * sz;\n quat.z = cx * cy * sz - sx * sy * cz;\n quat.w = cx * cy * cz - sx * sy * sz;\n return quat;\n}\nmat4 matrixFromRT (vec4 q, vec3 p){\n float x2 = q.x + q.x;\n float y2 = q.y + q.y;\n float z2 = q.z + q.z;\n float xx = q.x * x2;\n float xy = q.x * y2;\n float xz = q.x * z2;\n float yy = q.y * y2;\n float yz = q.y * z2;\n float zz = q.z * z2;\n float wx = q.w * x2;\n float wy = q.w * y2;\n float wz = q.w * z2;\n return mat4(\n 1. - (yy + zz), xy + wz, xz - wy, 0,\n xy - wz, 1. - (xx + zz), yz + wx, 0,\n xz + wy, yz - wx, 1. - (xx + yy), 0,\n p.x, p.y, p.z, 1\n );\n}\nmat4 matFromRTS (vec4 q, vec3 t, vec3 s){\n float x = q.x, y = q.y, z = q.z, w = q.w;\n float x2 = x + x;\n float y2 = y + y;\n float z2 = z + z;\n float xx = x * x2;\n float xy = x * y2;\n float xz = x * z2;\n float yy = y * y2;\n float yz = y * z2;\n float zz = z * z2;\n float wx = w * x2;\n float wy = w * y2;\n float wz = w * z2;\n float sx = s.x;\n float sy = s.y;\n float sz = s.z;\n return mat4((1. - (yy + zz)) * sx, (xy + wz) * sx, (xz - wy) * sx, 0,\n (xy - wz) * sy, (1. - (xx + zz)) * sy, (yz + wx) * sy, 0,\n (xz + wy) * sz, (yz - wx) * sz, (1. - (xx + yy)) * sz, 0,\n t.x, t.y, t.z, 1);\n}\nvec4 quatMultiply (vec4 a, vec4 b){\n vec4 quat;\n quat.x = a.x * b.w + a.w * b.x + a.y * b.z - a.z * b.y;\n quat.y = a.y * b.w + a.w * b.y + a.z * b.x - a.x * b.z;\n quat.z = a.z * b.w + a.w * b.z + a.x * b.y - a.y * b.x;\n quat.w = a.w * b.w - a.x * b.x - a.y * b.y - a.z * b.z;\n return quat;\n}\nvoid rotateVecFromQuat (inout vec3 v, vec4 q){\n float ix = q.w * v.x + q.y * v.z - q.z * v.y;\n float iy = q.w * v.y + q.z * v.x - q.x * v.z;\n float iz = q.w * v.z + q.x * v.y - q.y * v.x;\n float iw = -q.x * v.x - q.y * v.y - q.z * v.z;\n v.x = ix * q.w + iw * -q.x + iy * -q.z - iz * -q.y;\n v.y = iy * q.w + iw * -q.y + iz * -q.x - ix * -q.z;\n v.z = iz * q.w + iw * -q.z + ix * -q.y - iy * -q.x;\n}\nvec3 rotateInLocalSpace (vec3 pos, vec3 xAxis, vec3 yAxis, vec3 zAxis, vec4 q){\n vec4 viewQuat = quaternionFromAxis(xAxis, yAxis, zAxis);\n vec4 rotQuat = quatMultiply(viewQuat, q);\n rotateVecFromQuat(pos, rotQuat);\n return pos;\n}\nvoid rotateCorner (inout vec2 corner, float angle){\n float xOS = cos(angle) * corner.x - sin(angle) * corner.y;\n float yOS = sin(angle) * corner.x + cos(angle) * corner.y;\n corner.x = xOS;\n corner.y = yOS;\n}\nuniform Constants {\n vec4 mainTiling_Offset;\n vec4 frameTile_velLenScale;\n vec4 scale;\n};\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n};\nuniform CCLocal {\n highp mat4 cc_matWorld;\n highp mat4 cc_matWorldIT;\n};\nout vec2 uv;\nout vec4 color;\nvoid computeVertPos (inout vec4 pos, vec2 vertOffset, vec4 q, vec3 s\n#if CC_RENDER_MODE == 0 || CC_RENDER_MODE == 3\n , mat4 viewInv\n#endif\n#if CC_RENDER_MODE == 1\n , vec3 eye\n , vec4 velocity\n , float velocityScale\n , float lengthScale\n , float xIndex\n#endif\n) {\n#if CC_RENDER_MODE == 0\n vec3 viewSpaceVert = vec3(vertOffset.x * s.x, vertOffset.y * s.y, 0.);\n vec3 camX = normalize(vec3(viewInv[0][0], viewInv[1][0], viewInv[2][0]));\n vec3 camY = normalize(vec3(viewInv[0][1], viewInv[1][1], viewInv[2][1]));\n vec3 camZ = normalize(vec3(viewInv[0][2], viewInv[1][2], viewInv[2][2]));\n pos.xyz += rotateInLocalSpace(viewSpaceVert, camX, camY, camZ, q);\n#elif CC_RENDER_MODE == 1\n vec3 camRight = normalize(cross(pos.xyz - eye, velocity.xyz)) * s.x;\n vec3 camUp = velocity.xyz * velocityScale + normalize(velocity.xyz) * lengthScale * s.y;\n pos.xyz += (camRight * abs(vertOffset.x) * sign(vertOffset.y)) - camUp * xIndex;\n#elif CC_RENDER_MODE == 2\n vec3 viewSpaceVert = vec3(vertOffset.x * s.x, vertOffset.y * s.y, 0.);\n vec3 camX = vec3(1, 0, 0);\n vec3 camY = vec3(0, 0, -1);\n pos.xyz += rotateInLocalSpace(viewSpaceVert, camX, camY, cross(camX, camY), q);\n#elif CC_RENDER_MODE == 3\n vec2 viewSpaceVert = vec2(vertOffset.x * s.x, vertOffset.y * s.y);\n rotateCorner(viewSpaceVert, q.z);\n vec3 camX = normalize(vec3(cc_matView[0][0], cc_matView[1][0], cc_matView[2][0]));\n vec3 camY = vec3(0, 1, 0);\n vec3 offset = camX * viewSpaceVert.x + camY * viewSpaceVert.y;\n pos.xyz += offset;\n#else\n pos.x += vertOffset.x;\n pos.y += vertOffset.y;\n#endif\n}\nvec2 computeUV (float frameIndex, vec2 vertIndex, vec2 frameTile){\n vec2 aniUV = vec2(0, floor(frameIndex * frameTile.y));\n aniUV.x = floor(frameIndex * frameTile.x * frameTile.y - aniUV.y * frameTile.x);\n#if CC_RENDER_MODE != 4\n vertIndex.y = 1. - vertIndex.y;\n#endif\n return (aniUV.xy + vertIndex) / vec2(frameTile.x, frameTile.y);\n}\nin vec3 a_position;\nin vec3 a_texCoord;\nin vec3 a_texCoord1;\nin vec3 a_texCoord2;\nin vec4 a_color;\n#if CC_RENDER_MODE == 1\n in vec3 a_color1;\n#endif\n#if CC_RENDER_MODE == 4\n in vec3 a_texCoord3;\n in vec3 a_normal;\n in vec4 a_color1;\n#endif\nvec4 lpvs_main () {\n vec3 compScale = scale.xyz * a_texCoord1;\n vec4 pos = vec4(a_position, 1);\n #if CC_RENDER_MODE == 1\n vec4 velocity = vec4(a_color1.xyz, 0);\n #endif\n #if !CC_USE_WORLD_SPACE\n pos = cc_matWorld * pos;\n #if CC_RENDER_MODE == 1\n velocity = cc_matWorld * velocity;\n #endif\n #endif\n #if CC_RENDER_MODE != 4\n vec2 cornerOffset = vec2((a_texCoord.xy - 0.5));\n #if CC_RENDER_MODE == 0\n vec3 rotEuler = a_texCoord2;\n #elif CC_RENDER_MODE == 1\n vec3 rotEuler = vec3(0.);\n #else\n vec3 rotEuler = vec3(0., 0., a_texCoord2.z);\n #endif\n computeVertPos(pos, cornerOffset, quaternionFromEuler(rotEuler), compScale\n #if CC_RENDER_MODE == 0 || CC_RENDER_MODE == 3\n , cc_matViewInv\n #endif\n #if CC_RENDER_MODE == 1\n , cc_cameraPos.xyz\n , velocity\n , frameTile_velLenScale.z\n , frameTile_velLenScale.w\n , a_texCoord.x\n #endif\n );\n color = a_color;\n #else\n mat4 xformNoScale = matrixFromRT(quaternionFromEuler(a_texCoord2), pos.xyz);\n mat4 xform = matFromRTS(quaternionFromEuler(a_texCoord2), pos.xyz, compScale);\n pos = xform * vec4(a_texCoord3, 1);\n vec4 normal = xformNoScale * vec4(a_normal, 0);\n color = a_color * a_color1;\n #endif\n uv = computeUV(a_texCoord.z, a_texCoord.xy, frameTile_velLenScale.xy) * mainTiling_Offset.xy + mainTiling_Offset.zw;\n pos = cc_matViewProj * pos;\n return pos;\n}\nvoid main() { gl_Position = lpvs_main(); }`, - "frag": `\nprecision mediump float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n};\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\n}\nvec4 CCFragOutput (vec4 color) {\n #if CC_USE_HDR\n color.rgb = mix(color.rgb, SRGBToLinear(color.rgb) * cc_exposure.w, vec3(cc_exposure.z));\n #endif\n return color;\n}\nin vec2 uv;\nin vec4 color;\nuniform sampler2D mainTexture;\nuniform FragConstants {\n vec4 tintColor;\n};\nvec4 add () {\n vec4 col = 2.0 * color * tintColor * texture(mainTexture, uv);\n return CCFragOutput(col);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = add(); }` + "vert": `\nprecision highp float;\nvec4 quaternionFromAxis (vec3 xAxis,vec3 yAxis,vec3 zAxis){\n mat3 m = mat3(xAxis,yAxis,zAxis);\n float trace = m[0][0] + m[1][1] + m[2][2];\n vec4 quat;\n if (trace > 0.) {\n float s = 0.5 / sqrt(trace + 1.0);\n quat.w = 0.25 / s;\n quat.x = (m[2][1] - m[1][2]) * s;\n quat.y = (m[0][2] - m[2][0]) * s;\n quat.z = (m[1][0] - m[0][1]) * s;\n } else if ((m[0][0] > m[1][1]) && (m[0][0] > m[2][2])) {\n float s = 2.0 * sqrt(1.0 + m[0][0] - m[1][1] - m[2][2]);\n quat.w = (m[2][1] - m[1][2]) / s;\n quat.x = 0.25 * s;\n quat.y = (m[0][1] + m[1][0]) / s;\n quat.z = (m[0][2] + m[2][0]) / s;\n } else if (m[1][1] > m[2][2]) {\n float s = 2.0 * sqrt(1.0 + m[1][1] - m[0][0] - m[2][2]);\n quat.w = (m[0][2] - m[2][0]) / s;\n quat.x = (m[0][1] + m[1][0]) / s;\n quat.y = 0.25 * s;\n quat.z = (m[1][2] + m[2][1]) / s;\n } else {\n float s = 2.0 * sqrt(1.0 + m[2][2] - m[0][0] - m[1][1]);\n quat.w = (m[1][0] - m[0][1]) / s;\n quat.x = (m[0][2] + m[2][0]) / s;\n quat.y = (m[1][2] + m[2][1]) / s;\n quat.z = 0.25 * s;\n }\n float len = quat.x * quat.x + quat.y * quat.y + quat.z * quat.z + quat.w * quat.w;\n if (len > 0.) {\n len = 1. / sqrt(len);\n quat.x = quat.x * len;\n quat.y = quat.y * len;\n quat.z = quat.z * len;\n quat.w = quat.w * len;\n }\n return quat;\n}\nvec4 quaternionFromEuler (vec3 angle){\n float x = angle.x / 2.;\n float y = angle.y / 2.;\n float z = angle.z / 2.;\n float sx = sin(x);\n float cx = cos(x);\n float sy = sin(y);\n float cy = cos(y);\n float sz = sin(z);\n float cz = cos(z);\n vec4 quat = vec4(0);\n quat.x = sx * cy * cz + cx * sy * sz;\n quat.y = cx * sy * cz + sx * cy * sz;\n quat.z = cx * cy * sz - sx * sy * cz;\n quat.w = cx * cy * cz - sx * sy * sz;\n return quat;\n}\nmat4 matrixFromRT (vec4 q, vec3 p){\n float x2 = q.x + q.x;\n float y2 = q.y + q.y;\n float z2 = q.z + q.z;\n float xx = q.x * x2;\n float xy = q.x * y2;\n float xz = q.x * z2;\n float yy = q.y * y2;\n float yz = q.y * z2;\n float zz = q.z * z2;\n float wx = q.w * x2;\n float wy = q.w * y2;\n float wz = q.w * z2;\n return mat4(\n 1. - (yy + zz), xy + wz, xz - wy, 0,\n xy - wz, 1. - (xx + zz), yz + wx, 0,\n xz + wy, yz - wx, 1. - (xx + yy), 0,\n p.x, p.y, p.z, 1\n );\n}\nmat4 matFromRTS (vec4 q, vec3 t, vec3 s){\n float x = q.x, y = q.y, z = q.z, w = q.w;\n float x2 = x + x;\n float y2 = y + y;\n float z2 = z + z;\n float xx = x * x2;\n float xy = x * y2;\n float xz = x * z2;\n float yy = y * y2;\n float yz = y * z2;\n float zz = z * z2;\n float wx = w * x2;\n float wy = w * y2;\n float wz = w * z2;\n float sx = s.x;\n float sy = s.y;\n float sz = s.z;\n return mat4((1. - (yy + zz)) * sx, (xy + wz) * sx, (xz - wy) * sx, 0,\n (xy - wz) * sy, (1. - (xx + zz)) * sy, (yz + wx) * sy, 0,\n (xz + wy) * sz, (yz - wx) * sz, (1. - (xx + yy)) * sz, 0,\n t.x, t.y, t.z, 1);\n}\nvec4 quatMultiply (vec4 a, vec4 b){\n vec4 quat;\n quat.x = a.x * b.w + a.w * b.x + a.y * b.z - a.z * b.y;\n quat.y = a.y * b.w + a.w * b.y + a.z * b.x - a.x * b.z;\n quat.z = a.z * b.w + a.w * b.z + a.x * b.y - a.y * b.x;\n quat.w = a.w * b.w - a.x * b.x - a.y * b.y - a.z * b.z;\n return quat;\n}\nvoid rotateVecFromQuat (inout vec3 v, vec4 q){\n float ix = q.w * v.x + q.y * v.z - q.z * v.y;\n float iy = q.w * v.y + q.z * v.x - q.x * v.z;\n float iz = q.w * v.z + q.x * v.y - q.y * v.x;\n float iw = -q.x * v.x - q.y * v.y - q.z * v.z;\n v.x = ix * q.w + iw * -q.x + iy * -q.z - iz * -q.y;\n v.y = iy * q.w + iw * -q.y + iz * -q.x - ix * -q.z;\n v.z = iz * q.w + iw * -q.z + ix * -q.y - iy * -q.x;\n}\nvec3 rotateInLocalSpace (vec3 pos, vec3 xAxis, vec3 yAxis, vec3 zAxis, vec4 q){\n vec4 viewQuat = quaternionFromAxis(xAxis, yAxis, zAxis);\n vec4 rotQuat = quatMultiply(viewQuat, q);\n rotateVecFromQuat(pos, rotQuat);\n return pos;\n}\nvoid rotateCorner (inout vec2 corner, float angle){\n float xOS = cos(angle) * corner.x - sin(angle) * corner.y;\n float yOS = sin(angle) * corner.x + cos(angle) * corner.y;\n corner.x = xOS;\n corner.y = yOS;\n}\nuniform Constants {\n vec4 mainTiling_Offset;\n vec4 frameTile_velLenScale;\n vec4 scale;\n};\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\nuniform CCLocal {\n highp mat4 cc_matWorld;\n highp mat4 cc_matWorldIT;\n highp vec4 cc_lightingMapUVParam;\n};\nout vec2 uv;\nout vec4 color;\nvoid computeVertPos (inout vec4 pos, vec2 vertOffset, vec4 q, vec3 s\n#if CC_RENDER_MODE == 0 || CC_RENDER_MODE == 3\n , mat4 viewInv\n#endif\n#if CC_RENDER_MODE == 1\n , vec3 eye\n , vec4 velocity\n , float velocityScale\n , float lengthScale\n , float xIndex\n#endif\n) {\n#if CC_RENDER_MODE == 0\n vec3 viewSpaceVert = vec3(vertOffset.x * s.x, vertOffset.y * s.y, 0.);\n vec3 camX = normalize(vec3(viewInv[0][0], viewInv[1][0], viewInv[2][0]));\n vec3 camY = normalize(vec3(viewInv[0][1], viewInv[1][1], viewInv[2][1]));\n vec3 camZ = normalize(vec3(viewInv[0][2], viewInv[1][2], viewInv[2][2]));\n pos.xyz += rotateInLocalSpace(viewSpaceVert, camX, camY, camZ, q);\n#elif CC_RENDER_MODE == 1\n vec3 camRight = normalize(cross(pos.xyz - eye, velocity.xyz)) * s.x;\n vec3 camUp = velocity.xyz * velocityScale + normalize(velocity.xyz) * lengthScale * s.y;\n pos.xyz += (camRight * abs(vertOffset.x) * sign(vertOffset.y)) - camUp * xIndex;\n#elif CC_RENDER_MODE == 2\n vec3 viewSpaceVert = vec3(vertOffset.x * s.x, vertOffset.y * s.y, 0.);\n vec3 camX = vec3(1, 0, 0);\n vec3 camY = vec3(0, 0, -1);\n pos.xyz += rotateInLocalSpace(viewSpaceVert, camX, camY, cross(camX, camY), q);\n#elif CC_RENDER_MODE == 3\n vec2 viewSpaceVert = vec2(vertOffset.x * s.x, vertOffset.y * s.y);\n rotateCorner(viewSpaceVert, q.z);\n vec3 camX = normalize(vec3(cc_matView[0][0], cc_matView[1][0], cc_matView[2][0]));\n vec3 camY = vec3(0, 1, 0);\n vec3 offset = camX * viewSpaceVert.x + camY * viewSpaceVert.y;\n pos.xyz += offset;\n#else\n pos.x += vertOffset.x;\n pos.y += vertOffset.y;\n#endif\n}\nvec2 computeUV (float frameIndex, vec2 vertIndex, vec2 frameTile){\n vec2 aniUV = vec2(0, floor(frameIndex * frameTile.y));\n aniUV.x = floor(frameIndex * frameTile.x * frameTile.y - aniUV.y * frameTile.x);\n#if CC_RENDER_MODE != 4\n vertIndex.y = 1. - vertIndex.y;\n#endif\n return (aniUV.xy + vertIndex) / vec2(frameTile.x, frameTile.y);\n}\nin vec3 a_position;\nin vec3 a_texCoord;\nin vec3 a_texCoord1;\nin vec3 a_texCoord2;\nin vec4 a_color;\n#if CC_RENDER_MODE == 1\n in vec3 a_color1;\n#endif\n#if CC_RENDER_MODE == 4\n in vec3 a_texCoord3;\n in vec3 a_normal;\n in vec4 a_color1;\n#endif\nvec4 lpvs_main () {\n vec3 compScale = scale.xyz * a_texCoord1;\n vec4 pos = vec4(a_position, 1);\n #if CC_RENDER_MODE == 1\n vec4 velocity = vec4(a_color1.xyz, 0);\n #endif\n #if !CC_USE_WORLD_SPACE\n pos = cc_matWorld * pos;\n #if CC_RENDER_MODE == 1\n velocity = cc_matWorld * velocity;\n #endif\n #endif\n #if CC_RENDER_MODE != 4\n vec2 cornerOffset = vec2((a_texCoord.xy - 0.5));\n #if CC_RENDER_MODE == 0\n vec3 rotEuler = a_texCoord2;\n #elif CC_RENDER_MODE == 1\n vec3 rotEuler = vec3(0.);\n #else\n vec3 rotEuler = vec3(0., 0., a_texCoord2.z);\n #endif\n computeVertPos(pos, cornerOffset, quaternionFromEuler(rotEuler), compScale\n #if CC_RENDER_MODE == 0 || CC_RENDER_MODE == 3\n , cc_matViewInv\n #endif\n #if CC_RENDER_MODE == 1\n , cc_cameraPos.xyz\n , velocity\n , frameTile_velLenScale.z\n , frameTile_velLenScale.w\n , a_texCoord.x\n #endif\n );\n color = a_color;\n #else\n mat4 xformNoScale = matrixFromRT(quaternionFromEuler(a_texCoord2), pos.xyz);\n mat4 xform = matFromRTS(quaternionFromEuler(a_texCoord2), pos.xyz, compScale);\n pos = xform * vec4(a_texCoord3, 1);\n vec4 normal = xformNoScale * vec4(a_normal, 0);\n color = a_color * a_color1;\n #endif\n uv = computeUV(a_texCoord.z, a_texCoord.xy, frameTile_velLenScale.xy) * mainTiling_Offset.xy + mainTiling_Offset.zw;\n pos = cc_matViewProj * pos;\n return pos;\n}\nvoid main() { gl_Position = lpvs_main(); }`, + "frag": `\nprecision mediump float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\n}\nvec4 CCFragOutput (vec4 color) {\n #if CC_USE_HDR\n color.rgb = mix(color.rgb, SRGBToLinear(color.rgb) * cc_exposure.w, vec3(cc_exposure.z));\n #endif\n return color;\n}\nin vec2 uv;\nin vec4 color;\nuniform sampler2D mainTexture;\nuniform FragConstants {\n vec4 tintColor;\n};\nvec4 add () {\n vec4 col = 2.0 * color * tintColor * texture(mainTexture, uv);\n return CCFragOutput(col);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = add(); }` }, "glsl1": { "vert": `\nprecision highp float;\nvec4 quaternionFromAxis (vec3 xAxis,vec3 yAxis,vec3 zAxis){\n mat3 m = mat3(xAxis,yAxis,zAxis);\n float trace = m[0][0] + m[1][1] + m[2][2];\n vec4 quat;\n if (trace > 0.) {\n float s = 0.5 / sqrt(trace + 1.0);\n quat.w = 0.25 / s;\n quat.x = (m[2][1] - m[1][2]) * s;\n quat.y = (m[0][2] - m[2][0]) * s;\n quat.z = (m[1][0] - m[0][1]) * s;\n } else if ((m[0][0] > m[1][1]) && (m[0][0] > m[2][2])) {\n float s = 2.0 * sqrt(1.0 + m[0][0] - m[1][1] - m[2][2]);\n quat.w = (m[2][1] - m[1][2]) / s;\n quat.x = 0.25 * s;\n quat.y = (m[0][1] + m[1][0]) / s;\n quat.z = (m[0][2] + m[2][0]) / s;\n } else if (m[1][1] > m[2][2]) {\n float s = 2.0 * sqrt(1.0 + m[1][1] - m[0][0] - m[2][2]);\n quat.w = (m[0][2] - m[2][0]) / s;\n quat.x = (m[0][1] + m[1][0]) / s;\n quat.y = 0.25 * s;\n quat.z = (m[1][2] + m[2][1]) / s;\n } else {\n float s = 2.0 * sqrt(1.0 + m[2][2] - m[0][0] - m[1][1]);\n quat.w = (m[1][0] - m[0][1]) / s;\n quat.x = (m[0][2] + m[2][0]) / s;\n quat.y = (m[1][2] + m[2][1]) / s;\n quat.z = 0.25 * s;\n }\n float len = quat.x * quat.x + quat.y * quat.y + quat.z * quat.z + quat.w * quat.w;\n if (len > 0.) {\n len = 1. / sqrt(len);\n quat.x = quat.x * len;\n quat.y = quat.y * len;\n quat.z = quat.z * len;\n quat.w = quat.w * len;\n }\n return quat;\n}\nvec4 quaternionFromEuler (vec3 angle){\n float x = angle.x / 2.;\n float y = angle.y / 2.;\n float z = angle.z / 2.;\n float sx = sin(x);\n float cx = cos(x);\n float sy = sin(y);\n float cy = cos(y);\n float sz = sin(z);\n float cz = cos(z);\n vec4 quat = vec4(0);\n quat.x = sx * cy * cz + cx * sy * sz;\n quat.y = cx * sy * cz + sx * cy * sz;\n quat.z = cx * cy * sz - sx * sy * cz;\n quat.w = cx * cy * cz - sx * sy * sz;\n return quat;\n}\nmat4 matrixFromRT (vec4 q, vec3 p){\n float x2 = q.x + q.x;\n float y2 = q.y + q.y;\n float z2 = q.z + q.z;\n float xx = q.x * x2;\n float xy = q.x * y2;\n float xz = q.x * z2;\n float yy = q.y * y2;\n float yz = q.y * z2;\n float zz = q.z * z2;\n float wx = q.w * x2;\n float wy = q.w * y2;\n float wz = q.w * z2;\n return mat4(\n 1. - (yy + zz), xy + wz, xz - wy, 0,\n xy - wz, 1. - (xx + zz), yz + wx, 0,\n xz + wy, yz - wx, 1. - (xx + yy), 0,\n p.x, p.y, p.z, 1\n );\n}\nmat4 matFromRTS (vec4 q, vec3 t, vec3 s){\n float x = q.x, y = q.y, z = q.z, w = q.w;\n float x2 = x + x;\n float y2 = y + y;\n float z2 = z + z;\n float xx = x * x2;\n float xy = x * y2;\n float xz = x * z2;\n float yy = y * y2;\n float yz = y * z2;\n float zz = z * z2;\n float wx = w * x2;\n float wy = w * y2;\n float wz = w * z2;\n float sx = s.x;\n float sy = s.y;\n float sz = s.z;\n return mat4((1. - (yy + zz)) * sx, (xy + wz) * sx, (xz - wy) * sx, 0,\n (xy - wz) * sy, (1. - (xx + zz)) * sy, (yz + wx) * sy, 0,\n (xz + wy) * sz, (yz - wx) * sz, (1. - (xx + yy)) * sz, 0,\n t.x, t.y, t.z, 1);\n}\nvec4 quatMultiply (vec4 a, vec4 b){\n vec4 quat;\n quat.x = a.x * b.w + a.w * b.x + a.y * b.z - a.z * b.y;\n quat.y = a.y * b.w + a.w * b.y + a.z * b.x - a.x * b.z;\n quat.z = a.z * b.w + a.w * b.z + a.x * b.y - a.y * b.x;\n quat.w = a.w * b.w - a.x * b.x - a.y * b.y - a.z * b.z;\n return quat;\n}\nvoid rotateVecFromQuat (inout vec3 v, vec4 q){\n float ix = q.w * v.x + q.y * v.z - q.z * v.y;\n float iy = q.w * v.y + q.z * v.x - q.x * v.z;\n float iz = q.w * v.z + q.x * v.y - q.y * v.x;\n float iw = -q.x * v.x - q.y * v.y - q.z * v.z;\n v.x = ix * q.w + iw * -q.x + iy * -q.z - iz * -q.y;\n v.y = iy * q.w + iw * -q.y + iz * -q.x - ix * -q.z;\n v.z = iz * q.w + iw * -q.z + ix * -q.y - iy * -q.x;\n}\nvec3 rotateInLocalSpace (vec3 pos, vec3 xAxis, vec3 yAxis, vec3 zAxis, vec4 q){\n vec4 viewQuat = quaternionFromAxis(xAxis, yAxis, zAxis);\n vec4 rotQuat = quatMultiply(viewQuat, q);\n rotateVecFromQuat(pos, rotQuat);\n return pos;\n}\nvoid rotateCorner (inout vec2 corner, float angle){\n float xOS = cos(angle) * corner.x - sin(angle) * corner.y;\n float yOS = sin(angle) * corner.x + cos(angle) * corner.y;\n corner.x = xOS;\n corner.y = yOS;\n}\nuniform vec4 mainTiling_Offset;\nuniform vec4 frameTile_velLenScale;\nuniform vec4 scale;\nuniform highp mat4 cc_matView;\nuniform highp mat4 cc_matViewInv;\nuniform highp mat4 cc_matViewProj;\nuniform highp vec4 cc_cameraPos;\nuniform highp mat4 cc_matWorld;\nvarying vec2 uv;\nvarying vec4 color;\nvoid computeVertPos (inout vec4 pos, vec2 vertOffset, vec4 q, vec3 s\n#if CC_RENDER_MODE == 0 || CC_RENDER_MODE == 3\n , mat4 viewInv\n#endif\n#if CC_RENDER_MODE == 1\n , vec3 eye\n , vec4 velocity\n , float velocityScale\n , float lengthScale\n , float xIndex\n#endif\n) {\n#if CC_RENDER_MODE == 0\n vec3 viewSpaceVert = vec3(vertOffset.x * s.x, vertOffset.y * s.y, 0.);\n vec3 camX = normalize(vec3(viewInv[0][0], viewInv[1][0], viewInv[2][0]));\n vec3 camY = normalize(vec3(viewInv[0][1], viewInv[1][1], viewInv[2][1]));\n vec3 camZ = normalize(vec3(viewInv[0][2], viewInv[1][2], viewInv[2][2]));\n pos.xyz += rotateInLocalSpace(viewSpaceVert, camX, camY, camZ, q);\n#elif CC_RENDER_MODE == 1\n vec3 camRight = normalize(cross(pos.xyz - eye, velocity.xyz)) * s.x;\n vec3 camUp = velocity.xyz * velocityScale + normalize(velocity.xyz) * lengthScale * s.y;\n pos.xyz += (camRight * abs(vertOffset.x) * sign(vertOffset.y)) - camUp * xIndex;\n#elif CC_RENDER_MODE == 2\n vec3 viewSpaceVert = vec3(vertOffset.x * s.x, vertOffset.y * s.y, 0.);\n vec3 camX = vec3(1, 0, 0);\n vec3 camY = vec3(0, 0, -1);\n pos.xyz += rotateInLocalSpace(viewSpaceVert, camX, camY, cross(camX, camY), q);\n#elif CC_RENDER_MODE == 3\n vec2 viewSpaceVert = vec2(vertOffset.x * s.x, vertOffset.y * s.y);\n rotateCorner(viewSpaceVert, q.z);\n vec3 camX = normalize(vec3(cc_matView[0][0], cc_matView[1][0], cc_matView[2][0]));\n vec3 camY = vec3(0, 1, 0);\n vec3 offset = camX * viewSpaceVert.x + camY * viewSpaceVert.y;\n pos.xyz += offset;\n#else\n pos.x += vertOffset.x;\n pos.y += vertOffset.y;\n#endif\n}\nvec2 computeUV (float frameIndex, vec2 vertIndex, vec2 frameTile){\n vec2 aniUV = vec2(0, floor(frameIndex * frameTile.y));\n aniUV.x = floor(frameIndex * frameTile.x * frameTile.y - aniUV.y * frameTile.x);\n#if CC_RENDER_MODE != 4\n vertIndex.y = 1. - vertIndex.y;\n#endif\n return (aniUV.xy + vertIndex) / vec2(frameTile.x, frameTile.y);\n}\nattribute vec3 a_position;\nattribute vec3 a_texCoord;\nattribute vec3 a_texCoord1;\nattribute vec3 a_texCoord2;\nattribute vec4 a_color;\n#if CC_RENDER_MODE == 1\n attribute vec3 a_color1;\n#endif\n#if CC_RENDER_MODE == 4\n attribute vec3 a_texCoord3;\n attribute vec3 a_normal;\n attribute vec4 a_color1;\n#endif\nvec4 lpvs_main () {\n vec3 compScale = scale.xyz * a_texCoord1;\n vec4 pos = vec4(a_position, 1);\n #if CC_RENDER_MODE == 1\n vec4 velocity = vec4(a_color1.xyz, 0);\n #endif\n #if !CC_USE_WORLD_SPACE\n pos = cc_matWorld * pos;\n #if CC_RENDER_MODE == 1\n velocity = cc_matWorld * velocity;\n #endif\n #endif\n #if CC_RENDER_MODE != 4\n vec2 cornerOffset = vec2((a_texCoord.xy - 0.5));\n #if CC_RENDER_MODE == 0\n vec3 rotEuler = a_texCoord2;\n #elif CC_RENDER_MODE == 1\n vec3 rotEuler = vec3(0.);\n #else\n vec3 rotEuler = vec3(0., 0., a_texCoord2.z);\n #endif\n computeVertPos(pos, cornerOffset, quaternionFromEuler(rotEuler), compScale\n #if CC_RENDER_MODE == 0 || CC_RENDER_MODE == 3\n , cc_matViewInv\n #endif\n #if CC_RENDER_MODE == 1\n , cc_cameraPos.xyz\n , velocity\n , frameTile_velLenScale.z\n , frameTile_velLenScale.w\n , a_texCoord.x\n #endif\n );\n color = a_color;\n #else\n mat4 xformNoScale = matrixFromRT(quaternionFromEuler(a_texCoord2), pos.xyz);\n mat4 xform = matFromRTS(quaternionFromEuler(a_texCoord2), pos.xyz, compScale);\n pos = xform * vec4(a_texCoord3, 1);\n vec4 normal = xformNoScale * vec4(a_normal, 0);\n color = a_color * a_color1;\n #endif\n uv = computeUV(a_texCoord.z, a_texCoord.xy, frameTile_velLenScale.xy) * mainTiling_Offset.xy + mainTiling_Offset.zw;\n pos = cc_matViewProj * pos;\n return pos;\n}\nvoid main() { gl_Position = lpvs_main(); }`, @@ -233,7 +233,7 @@ export default [ ]} ], "samplers": [ - { "name": "mainTexture", "type": 28, "count": 1, "defines": [], "binding": 30 } + { "name": "mainTexture", "type": 28, "count": 1, "defines": [], "binding": 31 } ], "attributes": [ { "name": "a_position", "type": 15, "count": 1, "defines": [], "format": 32, "location": 0 }, @@ -259,12 +259,12 @@ export default [ "name": "builtin-sprite|sprite-vs:vert|sprite-fs:frag", "hash": 543960898, "glsl3": { - "vert": `\nprecision highp float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n};\n#if USE_LOCAL\nuniform CCLocal {\n highp mat4 cc_matWorld;\n highp mat4 cc_matWorldIT;\n};\n#endif\nin vec3 a_position;\nin vec4 a_color;\nout vec4 color;\nin vec2 a_texCoord;\nout vec2 uv0;\nvec4 vert () {\n vec4 pos = vec4(a_position, 1);\n #if USE_LOCAL\n pos = cc_matViewProj * cc_matWorld * pos;\n #else\n pos = cc_matViewProj * pos;\n #endif\n uv0 = a_texCoord;\n color = a_color;\n return pos;\n}\nvoid main() { gl_Position = vert(); }`, - "frag": `\nprecision highp float;\nin vec4 color;\n#if USE_TEXTURE\n in vec2 uv0;\n uniform sampler2D mainTexture;\n#endif\nvec4 frag () {\n vec4 o = vec4(1, 1, 1, 1);\n #if USE_TEXTURE\n o *= texture(mainTexture, uv0);\n #if IS_GRAY\n float gray = 0.2126 * o.r + 0.7152 * o.g + 0.0722 * o.b;\n o.r = o.g = o.b = gray;\n #endif\n #endif\n o *= color;\n return o;\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }` + "vert": `\nprecision mediump float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\n#if USE_LOCAL\nuniform CCLocal {\n highp mat4 cc_matWorld;\n highp mat4 cc_matWorldIT;\n highp vec4 cc_lightingMapUVParam;\n};\n#endif\nin vec3 a_position;\nin vec4 a_color;\nout vec4 color;\nin vec2 a_texCoord;\nout vec2 uv0;\nvec4 vert () {\n vec4 pos = vec4(a_position, 1);\n #if USE_LOCAL\n pos = cc_matViewProj * cc_matWorld * pos;\n #else\n pos = cc_matViewProj * pos;\n #endif\n uv0 = a_texCoord;\n color = a_color;\n return pos;\n}\nvoid main() { gl_Position = vert(); }`, + "frag": `\nprecision mediump float;\nin vec4 color;\n#if USE_TEXTURE\n in vec2 uv0;\n uniform sampler2D mainTexture;\n#endif\nvec4 frag () {\n vec4 o = vec4(1, 1, 1, 1);\n #if USE_TEXTURE\n o *= texture(mainTexture, uv0);\n #if IS_GRAY\n float gray = 0.2126 * o.r + 0.7152 * o.g + 0.0722 * o.b;\n o.r = o.g = o.b = gray;\n #endif\n #endif\n o *= color;\n return o;\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }` }, "glsl1": { - "vert": `\nprecision highp float;\nuniform highp mat4 cc_matViewProj;\n#if USE_LOCAL\nuniform highp mat4 cc_matWorld;\n#endif\nattribute vec3 a_position;\nattribute vec4 a_color;\nvarying vec4 color;\nattribute vec2 a_texCoord;\nvarying vec2 uv0;\nvec4 vert () {\n vec4 pos = vec4(a_position, 1);\n #if USE_LOCAL\n pos = cc_matViewProj * cc_matWorld * pos;\n #else\n pos = cc_matViewProj * pos;\n #endif\n uv0 = a_texCoord;\n color = a_color;\n return pos;\n}\nvoid main() { gl_Position = vert(); }`, - "frag": `\nprecision highp float;\nvarying vec4 color;\n#if USE_TEXTURE\n varying vec2 uv0;\n uniform sampler2D mainTexture;\n#endif\nvec4 frag () {\n vec4 o = vec4(1, 1, 1, 1);\n #if USE_TEXTURE\n o *= texture2D(mainTexture, uv0);\n #if IS_GRAY\n float gray = 0.2126 * o.r + 0.7152 * o.g + 0.0722 * o.b;\n o.r = o.g = o.b = gray;\n #endif\n #endif\n o *= color;\n return o;\n}\nvoid main() { gl_FragColor = frag(); }` + "vert": `\nprecision mediump float;\nuniform highp mat4 cc_matViewProj;\n#if USE_LOCAL\nuniform highp mat4 cc_matWorld;\n#endif\nattribute vec3 a_position;\nattribute vec4 a_color;\nvarying vec4 color;\nattribute vec2 a_texCoord;\nvarying vec2 uv0;\nvec4 vert () {\n vec4 pos = vec4(a_position, 1);\n #if USE_LOCAL\n pos = cc_matViewProj * cc_matWorld * pos;\n #else\n pos = cc_matViewProj * pos;\n #endif\n uv0 = a_texCoord;\n color = a_color;\n return pos;\n}\nvoid main() { gl_Position = vert(); }`, + "frag": `\nprecision mediump float;\nvarying vec4 color;\n#if USE_TEXTURE\n varying vec2 uv0;\n uniform sampler2D mainTexture;\n#endif\nvec4 frag () {\n vec4 o = vec4(1, 1, 1, 1);\n #if USE_TEXTURE\n o *= texture2D(mainTexture, uv0);\n #if IS_GRAY\n float gray = 0.2126 * o.r + 0.7152 * o.g + 0.0722 * o.b;\n o.r = o.g = o.b = gray;\n #endif\n #endif\n o *= color;\n return o;\n}\nvoid main() { gl_FragColor = frag(); }` }, "builtins": { "globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }], "samplers": [] }, @@ -277,7 +277,7 @@ export default [ ], "blocks": [], "samplers": [ - { "name": "mainTexture", "type": 28, "count": 1, "defines": ["USE_TEXTURE"], "binding": 30 } + { "name": "mainTexture", "type": 28, "count": 1, "defines": ["USE_TEXTURE"], "binding": 31 } ], "attributes": [ { "name": "a_position", "type": 15, "count": 1, "defines": [], "format": 32, "location": 0 }, @@ -296,52 +296,56 @@ export default [ "shaders": [ { "name": "builtin-standard|standard-vs:vert|standard-fs:frag", - "hash": 2048859965, + "hash": 2109082843, "glsl3": { - "vert": `\nprecision highp float;\nstruct StandardVertInput {\n highp vec4 position;\n vec3 normal;\n vec4 tangent;\n};\nin vec3 a_position;\nin vec3 a_normal;\nin vec4 a_tangent;\n#if CC_USE_MORPH\n in float a_vertexId;\n int getVertexId() {\n return int(a_vertexId);\n }\nuniform CCMorph {\n vec4 cc_displacementWeights[15];\n vec4 cc_displacementTextureInfo;\n};\n vec4 fetchFlatPixel(sampler2D tex, int pixelIndex) {\n float pixelIndexF = float(pixelIndex);\n vec2 textureResolution = vec2(float(cc_displacementTextureInfo.x), float(cc_displacementTextureInfo.y));\n float pixelX = mod(pixelIndexF, textureResolution.x);\n float pixelY = floor(pixelIndexF / textureResolution.x);\n vec2 uv = (vec2(pixelX, pixelY) + .5) / textureResolution;\n return texture(tex, uv);\n }\nfloat getDisplacementWeight(int index) {\n float m = mod(float(index), 4.0);\n if (m < 1.0) {\n return cc_displacementWeights[index / 4].x;\n } else if (m < 2.0) {\n return cc_displacementWeights[index / 4].y;\n } else if (m < 3.0) {\n return cc_displacementWeights[index / 4].z;\n } else {\n return cc_displacementWeights[index / 4].w;\n }\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\n return fetchFlatPixel(tex, vertexIndex).rgb;\n#else\n vec3 result = vec3(0, 0, 0);\n for (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\n int dataPixelStart = int(fetchFlatPixel(tex, iTarget).r);\n result += (fetchFlatPixel(tex, dataPixelStart + vertexIndex).rgb * getDisplacementWeight(iTarget));\n }\n return result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\n uniform sampler2D cc_PositionDisplacements;\n vec3 getPositionDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n uniform sampler2D cc_NormalDisplacements;\n vec3 getNormalDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n uniform sampler2D cc_TangentDisplacements;\n vec3 getTangentDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n }\n#endif\nvoid applyMorph (inout StandardVertInput attr) {\n int vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\n attr.position.xyz = attr.position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n attr.normal.xyz = attr.normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n attr.tangent.xyz = attr.tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\n position.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\nin vec4 a_weights;\nin vec4 a_joints;\n#if CC_USE_BAKED_ANIMATION\n #if USE_INSTANCING\n in highp vec4 a_jointAnimInfo;\n #endif\n uniform CCSkinningTexture {\n highp vec4 cc_jointTextureInfo;\n };\n uniform CCSkinningAnimation {\n highp vec4 cc_jointAnimInfo;\n };\n uniform sampler2D cc_jointTexture;\n #if !CC_SUPPORT_FLOAT_TEXTURE\n highp float decode32 (highp vec4 rgba) {\n rgba = rgba * 255.0;\n highp float Sign = 1.0 - step(128.0, rgba[3]) * 2.0;\n highp float Exponent = 2.0 * mod(rgba[3], 128.0) + step(128.0, rgba[2]) - 127.0;\n highp float Mantissa = mod(rgba[2], 128.0) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\n }\n #endif\n#else\n uniform CCSkinning {\n highp vec4 cc_joints[30 * 3];\n };\n#endif\n#if CC_USE_BAKED_ANIMATION\n #if CC_SUPPORT_FLOAT_TEXTURE\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 3.0 * (a_jointAnimInfo.x * a_jointAnimInfo.y + i) + a_jointAnimInfo.z;\n #else\n highp float j = 3.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = texture(cc_jointTexture, vec2((x + 0.5) * invSize, y));\n vec4 v2 = texture(cc_jointTexture, vec2((x + 1.5) * invSize, y));\n vec4 v3 = texture(cc_jointTexture, vec2((x + 2.5) * invSize, y));\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #else\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 12.0 * (a_jointAnimInfo.x * a_jointAnimInfo.y + i) + a_jointAnimInfo.z;\n #else\n highp float j = 12.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = vec4(\n decode32(texture(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n );\n vec4 v2 = vec4(\n decode32(texture(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n );\n vec4 v3 = vec4(\n decode32(texture(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n );\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #endif\n#else\n mat4 getJointMatrix (float i) {\n int idx = int(i);\n vec4 v1 = cc_joints[idx * 3];\n vec4 v2 = cc_joints[idx * 3 + 1];\n vec4 v3 = cc_joints[idx * 3 + 2];\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n#endif\nmat4 skinMatrix () {\n return getJointMatrix(a_joints.x) * a_weights.x\n + getJointMatrix(a_joints.y) * a_weights.y;\n + getJointMatrix(a_joints.z) * a_weights.z;\n + getJointMatrix(a_joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\n mat4 m = skinMatrix();\n position = m * position;\n}\nvoid CCSkin (inout StandardVertInput attr) {\n mat4 m = skinMatrix();\n attr.position = m * attr.position;\n attr.normal = (m * vec4(attr.normal, 0.0)).xyz;\n attr.tangent.xyz = (m * vec4(attr.tangent.xyz, 0.0)).xyz;\n}\n#endif\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n};\n#if USE_INSTANCING\n in vec4 a_matWorld0;\n in vec4 a_matWorld1;\n in vec4 a_matWorld2;\n#elif USE_BATCHING\n in float a_dyn_batch_id;\n uniform CCLocalBatched {\n highp mat4 cc_matWorlds[10];\n };\n#else\nuniform CCLocal {\n highp mat4 cc_matWorld;\n highp mat4 cc_matWorldIT;\n};\n#endif\nuniform Constants {\n vec4 tilingOffset;\n vec4 albedo;\n vec4 albedoScaleAndCutoff;\n vec4 pbrParams;\n vec4 emissive;\n vec4 emissiveScaleParam;\n};\n#if USE_VERTEX_COLOR\n in vec3 a_color;\n out vec3 v_color;\n#endif\nout vec3 v_position;\nout vec3 v_normal;\n#if USE_NORMAL_MAP\n out vec3 v_tangent;\n out vec3 v_bitangent;\n#endif\nin vec2 a_texCoord;\nout vec2 v_uv;\nin vec2 a_texCoord1;\nout vec2 v_uv1;\nvec4 vert () {\n StandardVertInput In;\n In.position = vec4(a_position, 1.0);\n In.normal = a_normal;\n In.tangent = a_tangent;\n #if CC_USE_MORPH\n applyMorph(In);\n #endif\n #if CC_USE_SKINNING\n CCSkin(In);\n #endif\n mat4 matWorld, matWorldIT;\n #if USE_INSTANCING\n matWorld = mat4(\n vec4(a_matWorld0.xyz, 0.0),\n vec4(a_matWorld1.xyz, 0.0),\n vec4(a_matWorld2.xyz, 0.0),\n vec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)\n );\n matWorldIT = matWorld;\n #elif USE_BATCHING\n matWorld = cc_matWorlds[int(a_dyn_batch_id)];\n matWorldIT = matWorld;\n #else\n matWorld = cc_matWorld;\n matWorldIT = cc_matWorldIT;\n #endif\n vec4 pos = matWorld * In.position;\n v_position = pos.xyz;\n v_normal = normalize((matWorldIT * vec4(In.normal, 0.0)).xyz);\n #if USE_NORMAL_MAP\n v_tangent = normalize((matWorld * vec4(In.tangent.xyz, 0.0)).xyz);\n v_bitangent = cross(v_normal, v_tangent) * In.tangent.w;\n #endif\n v_uv = a_texCoord * tilingOffset.xy + tilingOffset.zw;\n #if HAS_SECOND_UV\n v_uv1 = a_texCoord1 * tilingOffset.xy + tilingOffset.zw;\n #endif\n #if USE_VERTEX_COLOR\n v_color = a_color;\n #endif\n return cc_matProj * (cc_matView * matWorld) * In.position;\n}\nvoid main() { gl_Position = vert(); }`, - "frag": `\nprecision highp float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n};\n#if CC_USE_IBL\nuniform samplerCube cc_environment;\nvec3 unpackRGBE (vec4 rgbe) {\n return rgbe.rgb * pow(2.0, rgbe.a * 255.0 - 128.0);\n}\nvec4 fragTextureLod (sampler2D tex, vec2 coord, float lod) {\n return textureLod(tex, coord, lod);\n}\nvec4 fragTextureLod (samplerCube tex, vec3 coord, float lod) {\n return textureLod(tex, coord, lod);\n}\n#endif\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\n}\nuniform CCForwardLight {\n highp vec4 cc_sphereLitPos[2];\n vec4 cc_sphereLitSizeRange[2];\n vec4 cc_sphereLitColor[2];\n highp vec4 cc_spotLitPos[2];\n vec4 cc_spotLitSizeRangeAngle[2];\n vec4 cc_spotLitDir[2];\n vec4 cc_spotLitColor[2];\n};\nfloat SmoothDistAtt (float distSqr, float invSqrAttRadius) {\n float factor = distSqr * invSqrAttRadius;\n float smoothFactor = clamp(1.0 - factor * factor, 0.0, 1.0);\n return smoothFactor * smoothFactor;\n}\nfloat GetDistAtt (float distSqr, float invSqrAttRadius) {\n float attenuation = 1.0 / max(distSqr, 0.01*0.01);\n attenuation *= SmoothDistAtt(distSqr , invSqrAttRadius);\n return attenuation;\n}\nfloat GetAngleAtt (vec3 L, vec3 litDir, float litAngleScale, float litAngleOffset) {\n float cd = dot(litDir, L);\n float attenuation = clamp(cd * litAngleScale + litAngleOffset, 0.0, 1.0);\n return (attenuation * attenuation);\n}\nfloat GGXMobile (float roughness, float NoH, vec3 H, vec3 N) {\n vec3 NxH = cross(N, H);\n float OneMinusNoHSqr = dot(NxH, NxH);\n float a = roughness * roughness;\n float n = NoH * a;\n float p = a / (OneMinusNoHSqr + n * n);\n return p * p;\n}\nfloat CalcSpecular (float roughness, float NoH, vec3 H, vec3 N) {\n return (roughness*0.25 + 0.25) * GGXMobile(roughness, NoH, H, N);\n}\nvec3 BRDFApprox (vec3 specular, float roughness, float NoV) {\n const vec4 c0 = vec4(-1.0, -0.0275, -0.572, 0.022);\n const vec4 c1 = vec4(1.0, 0.0425, 1.04, -0.04);\n vec4 r = roughness * c0 + c1;\n float a004 = min( r.x * r.x, exp2( -9.28 * NoV ) ) * r.x + r.y;\n vec2 AB = vec2( -1.04, 1.04 ) * a004 + r.zw;\n AB.y *= clamp(50.0 * specular.g, 0.0, 1.0);\n return specular * AB.x + AB.y;\n}\nvec3 CalcDynamicLighting (vec3 worldPos, vec3 N, vec3 V, vec3 diffuse, vec3 specular, float roughness) {\n vec3 lighting = vec3(0.0);\n vec3 diffuseContrib = diffuse / 3.14159265359;\n for (int i = 0; i < 2; i++) {\n vec3 PLU = cc_sphereLitPos[i].xyz - worldPos;\n vec3 PL = normalize(PLU);\n vec3 PH = normalize(PL + V);\n float PNL = max(dot(N, PL), 0.001);\n float PNH = max(dot(N, PH), 0.0);\n float distSqr = dot(PLU, PLU);\n float litRadius = cc_sphereLitSizeRange[i].x;\n float litRadiusSqr = litRadius * litRadius;\n float illum = 3.14159265359 * (litRadiusSqr / max(litRadiusSqr , distSqr));\n float attRadiusSqrInv = 1.0 / max(cc_sphereLitSizeRange[i].y, 0.01);\n attRadiusSqrInv *= attRadiusSqrInv;\n float att = GetDistAtt(distSqr, attRadiusSqrInv);\n vec3 lspec = specular * CalcSpecular(roughness, PNH, PH, N);\n lighting += PNL * cc_sphereLitColor[i].rgb * cc_sphereLitColor[i].w * illum * att * (diffuseContrib + lspec);\n }\n for (int i = 0; i < 2; i++) {\n vec3 SLU = cc_spotLitPos[i].xyz - worldPos;\n vec3 SL = normalize(SLU);\n vec3 SH = normalize(SL + V);\n float SNL = max(dot(N, SL), 0.001);\n float SNH = max(dot(N, SH), 0.0);\n float distSqr = dot(SLU, SLU);\n float litRadius = cc_spotLitSizeRangeAngle[i].x;\n float litRadiusSqr = litRadius * litRadius;\n float illum = 3.14159265359 * (litRadiusSqr / max(litRadiusSqr , distSqr));\n float attRadiusSqrInv = 1.0 / max(cc_spotLitSizeRangeAngle[i].y, 0.01);\n attRadiusSqrInv *= attRadiusSqrInv;\n float cosInner = max(dot(-cc_spotLitDir[i].xyz, SL), 0.01);\n float cosOuter = cc_spotLitSizeRangeAngle[i].z;\n float litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\n float litAngleOffset = -cosOuter * litAngleScale;\n float att = GetDistAtt(distSqr, attRadiusSqrInv);\n att *= GetAngleAtt(SL, -cc_spotLitDir[i].xyz, litAngleScale, litAngleOffset);\n vec3 lspec = specular * CalcSpecular(roughness, SNH, SH, N);\n lighting += SNL * cc_spotLitColor[i].rgb * cc_spotLitColor[i].w * illum * att * (diffuseContrib + lspec);\n }\n return lighting;\n}\nstruct StandardSurface {\n vec4 albedo;\n vec3 position;\n vec3 normal;\n vec3 emissive;\n float roughness;\n float metallic;\n float occlusion;\n};\nvec4 CCStandardShading (StandardSurface s) {\n vec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\n vec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\n vec3 N = normalize(s.normal);\n vec3 V = normalize(cc_cameraPos.xyz - s.position);\n vec3 L = normalize(-cc_mainLitDir.xyz);\n vec3 H = normalize(L+V);\n float NV = max(abs(dot(N, V)), 0.001);\n float NL = max(dot(N, L), 0.001);\n float NH = max(dot(N, H), 0.0);\n specular = BRDFApprox(specular, s.roughness, NV);\n vec3 diffuseContrib = diffuse / 3.14159265359;\n vec3 specularContrib = specular * CalcSpecular(s.roughness, NH, H, N);\n vec3 finalColor = NL * cc_mainLitColor.rgb * cc_mainLitColor.w * (diffuseContrib + specularContrib);\n finalColor += CalcDynamicLighting(s.position, N, V, diffuse, specular, s.roughness);\n float fAmb = 0.5 - N.y * 0.5;\n vec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb) * cc_ambientSky.w;\n finalColor += (ambDiff.rgb * diffuse);\n #if CC_USE_IBL\n vec3 R = normalize(reflect(-V, N));\n vec4 envmap = fragTextureLod(cc_environment, R, s.roughness * cc_ambientGround.w);\n #if CC_USE_IBL == 2\n vec3 env = unpackRGBE(envmap);\n #else\n vec3 env = SRGBToLinear(envmap.rgb);\n #endif\n finalColor += env * cc_ambientSky.w * specular;\n #endif\n finalColor = finalColor * s.occlusion;\n #if CC_USE_HDR\n s.emissive *= cc_exposure.w;\n #endif\n finalColor += s.emissive;\n return vec4(finalColor, s.albedo.a);\n}\nvec3 ACESToneMap (vec3 color) {\n color = min(color, vec3(8.0));\n const float A = 2.51;\n const float B = 0.03;\n const float C = 2.43;\n const float D = 0.59;\n const float E = 0.14;\n return (color * (A * color + B)) / (color * (C * color + D) + E);\n}\nvec4 CCFragOutput (vec4 color) {\n #if !CC_USE_HDR\n color.rgb = sqrt(ACESToneMap(color.rgb));\n #endif\n return color;\n}\nuniform Constants {\n vec4 tilingOffset;\n vec4 albedo;\n vec4 albedoScaleAndCutoff;\n vec4 pbrParams;\n vec4 emissive;\n vec4 emissiveScaleParam;\n};\nin vec3 v_position;\nin vec2 v_uv;\nin vec2 v_uv1;\nin vec3 v_normal;\n#if USE_VERTEX_COLOR\n in vec3 v_color;\n#endif\n#if USE_ALBEDO_MAP\n uniform sampler2D albedoMap;\n#endif\n#if USE_NORMAL_MAP\n in vec3 v_tangent;\n in vec3 v_bitangent;\n uniform sampler2D normalMap;\n#endif\n#if USE_PBR_MAP\n uniform sampler2D pbrMap;\n#endif\n#if USE_METALLIC_ROUGHNESS_MAP\n uniform sampler2D metallicRoughnessMap;\n#endif\n#if USE_OCCLUSION_MAP\n uniform sampler2D occlusionMap;\n#endif\n#if USE_EMISSIVE_MAP\n uniform sampler2D emissiveMap;\n#endif\n#if USE_ALPHA_TEST\n#endif\nvoid surf (out StandardSurface s) {\n vec4 baseColor = albedo;\n #if USE_VERTEX_COLOR\n baseColor.rgb *= v_color;\n #endif\n #if USE_ALBEDO_MAP\n vec4 texColor = texture(albedoMap, ALBEDO_UV);\n texColor.rgb = SRGBToLinear(texColor.rgb);\n baseColor *= texColor;\n #endif\n s.albedo = baseColor;\n s.albedo.rgb *= albedoScaleAndCutoff.xyz;\n #if USE_ALPHA_TEST\n if (s.albedo.ALPHA_TEST_CHANNEL < albedoScaleAndCutoff.w) discard;\n #endif\n s.normal = v_normal;\n #if USE_NORMAL_MAP\n vec3 nmmp = texture(normalMap, NORMAL_UV).xyz - vec3(0.5);\n s.normal =\n (nmmp.x * pbrParams.w) * normalize(v_tangent) +\n (nmmp.y * pbrParams.w) * normalize(v_bitangent) +\n nmmp.z * normalize(s.normal);\n #endif\n s.position = v_position;\n vec4 pbr = pbrParams;\n #if USE_PBR_MAP\n vec4 res = texture(pbrMap, PBR_UV);\n pbr.x *= res.OCCLUSION_CHANNEL;\n pbr.y *= res.ROUGHNESS_CHANNEL;\n pbr.z *= res.METALLIC_CHANNEL;\n #endif\n #if USE_METALLIC_ROUGHNESS_MAP\n vec4 metallicRoughness = texture(metallicRoughnessMap, METALLIC_ROUGHNESS_UV);\n pbr.z *= metallicRoughness.METALLIC_CHANNEL;\n pbr.y *= metallicRoughness.ROUGHNESS_CHANNEL;\n #endif\n #if USE_OCCLUSION_MAP\n pbr.x *= texture(occlusionMap, OCCLUSION_UV).OCCLUSION_CHANNEL;\n #endif\n s.occlusion = clamp(pbr.x, 0.0, 0.96);\n s.roughness = clamp(pbr.y, 0.04, 1.0);\n s.metallic = pbr.z;\n s.emissive = emissive.rgb * emissiveScaleParam.xyz;\n #if USE_EMISSIVE_MAP\n s.emissive *= SRGBToLinear(texture(emissiveMap, EMISSIVE_UV).rgb);\n #endif\n}\nvec4 frag () {\n StandardSurface s; surf(s);\n vec4 color = CCStandardShading(s);\n return CCFragOutput(color);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }` + "vert": `\nprecision highp float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\n#if USE_INSTANCING\n in vec4 a_matWorld0;\n in vec4 a_matWorld1;\n in vec4 a_matWorld2;\n#elif USE_BATCHING\n in float a_dyn_batch_id;\n uniform CCLocalBatched {\n highp mat4 cc_matWorlds[10];\n };\n#else\nuniform CCLocal {\n highp mat4 cc_matWorld;\n highp mat4 cc_matWorldIT;\n highp vec4 cc_lightingMapUVParam;\n};\n#endif\nstruct StandardVertInput {\n highp vec4 position;\n vec3 normal;\n vec4 tangent;\n};\nin vec3 a_position;\nin vec3 a_normal;\nin vec4 a_tangent;\n#if CC_USE_MORPH\n in float a_vertexId;\n int getVertexId() {\n return int(a_vertexId);\n }\nuniform CCMorph {\n vec4 cc_displacementWeights[15];\n vec4 cc_displacementTextureInfo;\n};\n vec4 fetchFlatPixel(sampler2D tex, int pixelIndex) {\n float pixelIndexF = float(pixelIndex);\n vec2 textureResolution = vec2(float(cc_displacementTextureInfo.x), float(cc_displacementTextureInfo.y));\n float pixelX = mod(pixelIndexF, textureResolution.x);\n float pixelY = floor(pixelIndexF / textureResolution.x);\n vec2 uv = (vec2(pixelX, pixelY) + .5) / textureResolution;\n return texture(tex, uv);\n }\nfloat getDisplacementWeight(int index) {\n float m = mod(float(index), 4.0);\n if (m < 1.0) {\n return cc_displacementWeights[index / 4].x;\n } else if (m < 2.0) {\n return cc_displacementWeights[index / 4].y;\n } else if (m < 3.0) {\n return cc_displacementWeights[index / 4].z;\n } else {\n return cc_displacementWeights[index / 4].w;\n }\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\n return fetchFlatPixel(tex, vertexIndex).rgb;\n#else\n vec3 result = vec3(0, 0, 0);\n for (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\n int dataPixelStart = int(fetchFlatPixel(tex, iTarget).r);\n result += (fetchFlatPixel(tex, dataPixelStart + vertexIndex).rgb * getDisplacementWeight(iTarget));\n }\n return result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\n uniform sampler2D cc_PositionDisplacements;\n vec3 getPositionDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n uniform sampler2D cc_NormalDisplacements;\n vec3 getNormalDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n uniform sampler2D cc_TangentDisplacements;\n vec3 getTangentDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n }\n#endif\nvoid applyMorph (inout StandardVertInput attr) {\n int vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\n attr.position.xyz = attr.position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n attr.normal.xyz = attr.normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n attr.tangent.xyz = attr.tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\n position.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\nin vec4 a_weights;\nin vec4 a_joints;\n#if CC_USE_BAKED_ANIMATION\n #if USE_INSTANCING\n in vec4 a_jointAnimInfo;\n #endif\n uniform CCSkinningTexture {\n highp vec4 cc_jointTextureInfo;\n };\n uniform CCSkinningAnimation {\n highp vec4 cc_jointAnimInfo;\n };\n uniform sampler2D cc_jointTexture;\n #if !CC_SUPPORT_FLOAT_TEXTURE\n highp float decode32 (highp vec4 rgba) {\n rgba = rgba * 255.0;\n highp float Sign = 1.0 - step(128.0, rgba[3]) * 2.0;\n highp float Exponent = 2.0 * mod(rgba[3], 128.0) + step(128.0, rgba[2]) - 127.0;\n highp float Mantissa = mod(rgba[2], 128.0) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\n }\n #endif\n#else\n uniform CCSkinning {\n highp vec4 cc_joints[30 * 3];\n };\n#endif\n#if CC_USE_BAKED_ANIMATION\n #if CC_SUPPORT_FLOAT_TEXTURE\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 3.0 * i + a_jointAnimInfo.x;\n #else\n highp float j = 3.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = texture(cc_jointTexture, vec2((x + 0.5) * invSize, y));\n vec4 v2 = texture(cc_jointTexture, vec2((x + 1.5) * invSize, y));\n vec4 v3 = texture(cc_jointTexture, vec2((x + 2.5) * invSize, y));\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #else\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 12.0 * i + a_jointAnimInfo.x;\n #else\n highp float j = 12.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = vec4(\n decode32(texture(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n );\n vec4 v2 = vec4(\n decode32(texture(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n );\n vec4 v3 = vec4(\n decode32(texture(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n );\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #endif\n#else\n mat4 getJointMatrix (float i) {\n int idx = int(i);\n vec4 v1 = cc_joints[idx * 3];\n vec4 v2 = cc_joints[idx * 3 + 1];\n vec4 v3 = cc_joints[idx * 3 + 2];\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n#endif\nmat4 skinMatrix () {\n return getJointMatrix(a_joints.x) * a_weights.x\n + getJointMatrix(a_joints.y) * a_weights.y;\n + getJointMatrix(a_joints.z) * a_weights.z;\n + getJointMatrix(a_joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\n mat4 m = skinMatrix();\n position = m * position;\n}\nvoid CCSkin (inout StandardVertInput attr) {\n mat4 m = skinMatrix();\n attr.position = m * attr.position;\n attr.normal = (m * vec4(attr.normal, 0.0)).xyz;\n attr.tangent.xyz = (m * vec4(attr.tangent.xyz, 0.0)).xyz;\n}\n#endif\nuniform Constants {\n vec4 tilingOffset;\n vec4 albedo;\n vec4 albedoScaleAndCutoff;\n vec4 pbrParams;\n vec4 emissive;\n vec4 emissiveScaleParam;\n};\nfloat LinearFog(vec4 pos) {\n vec4 wPos = pos;\n float cam_dis = distance(cc_cameraPos, wPos);\n float fogStart = cc_fogBase.x;\n float fogEnd = cc_fogBase.y;\n return clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float fogDensity = cc_fogBase.z;\n float cam_dis = distance(cc_cameraPos, wPos) / fogAtten * 4.;\n float f = exp(-cam_dis * fogDensity);\n return f;\n}\nfloat ExpSquaredFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float fogDensity = cc_fogBase.z;\n float cam_dis = distance(cc_cameraPos, wPos) / fogAtten * 4.;\n float f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\n return f;\n}\nfloat LayeredFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float _FogTop = cc_fogAdd.x;\n float _FogRange = cc_fogAdd.y;\n vec3 camWorldProj = cc_cameraPos.xyz;\n camWorldProj.y = 0.;\n vec3 worldPosProj = wPos.xyz;\n worldPosProj.y = 0.;\n float fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\n float fDeltaY, fDensityIntegral;\n if (cc_cameraPos.y > _FogTop) {\n if (wPos.y < _FogTop) {\n fDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\n fDensityIntegral = fDeltaY * fDeltaY * 0.5;\n } else {\n fDeltaY = 0.;\n fDensityIntegral = 0.;\n }\n } else {\n if (wPos.y < _FogTop) {\n float fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\n float fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\n fDeltaY = abs(fDeltaA - fDeltaB);\n fDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n } else {\n fDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\n fDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n }\n }\n float fDensity;\n if (fDeltaY != 0.) {\n fDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n } else {\n fDensity = 0.;\n }\n float f = exp(-fDensity);\n return f;\n}\nfloat CC_TRANSFER_FOG(vec4 pos) {\n #if CC_USE_FOG == 1\n return LinearFog(pos);\n #elif CC_USE_FOG == 2\n return ExpFog(pos);\n #elif CC_USE_FOG == 3\n return ExpSquaredFog(pos);\n #elif CC_USE_FOG == 4\n return LayeredFog(pos);\n #endif\n return 1.;\n}\n#if USE_VERTEX_COLOR\n in vec3 a_color;\n out vec3 v_color;\n#endif\nout vec3 v_position;\nout vec3 v_normal;\n#if USE_NORMAL_MAP\n out vec3 v_tangent;\n out vec3 v_bitangent;\n#endif\nin vec2 a_texCoord;\nout vec2 v_uv;\nin vec2 a_texCoord1;\nout vec2 v_uv1;\nout float factor_fog;\n#if USE_LIGHTMAP && !USE_BATCHING && !USE_INSTANCING\n out vec2 v_luv;\n#endif\nvec4 vert () {\n StandardVertInput In;\n In.position = vec4(a_position, 1.0);\n In.normal = a_normal;\n In.tangent = a_tangent;\n #if CC_USE_MORPH\n applyMorph(In);\n #endif\n #if CC_USE_SKINNING\n CCSkin(In);\n #endif\n mat4 matWorld, matWorldIT;\n #if USE_INSTANCING\n matWorld = mat4(\n vec4(a_matWorld0.xyz, 0.0),\n vec4(a_matWorld1.xyz, 0.0),\n vec4(a_matWorld2.xyz, 0.0),\n vec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)\n );\n matWorldIT = matWorld;\n #elif USE_BATCHING\n matWorld = cc_matWorlds[int(a_dyn_batch_id)];\n matWorldIT = matWorld;\n #else\n matWorld = cc_matWorld;\n matWorldIT = cc_matWorldIT;\n #endif\n vec4 pos = matWorld * In.position;\n v_position = pos.xyz;\n v_normal = normalize((matWorldIT * vec4(In.normal, 0.0)).xyz);\n #if USE_NORMAL_MAP\n v_tangent = normalize((matWorld * vec4(In.tangent.xyz, 0.0)).xyz);\n v_bitangent = cross(v_normal, v_tangent) * In.tangent.w;\n #endif\n v_uv = a_texCoord * tilingOffset.xy + tilingOffset.zw;\n #if HAS_SECOND_UV\n v_uv1 = a_texCoord1 * tilingOffset.xy + tilingOffset.zw;\n #endif\n #if USE_VERTEX_COLOR\n v_color = a_color;\n #endif\n factor_fog = CC_TRANSFER_FOG(matWorld * In.position);\n #if USE_LIGHTMAP && HAS_SECOND_UV && !USE_BATCHING && !USE_INSTANCING\n v_luv = cc_lightingMapUVParam.xy + a_texCoord1 * cc_lightingMapUVParam.zw;\n #endif\n return cc_matProj * (cc_matView * matWorld) * In.position;\n}\nvoid main() { gl_Position = vert(); }`, + "frag": `\nprecision highp float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\n#if CC_USE_IBL\nuniform samplerCube cc_environment;\nvec3 unpackRGBE (vec4 rgbe) {\n return rgbe.rgb * pow(2.0, rgbe.a * 255.0 - 128.0);\n}\nvec4 fragTextureLod (sampler2D tex, vec2 coord, float lod) {\n return textureLod(tex, coord, lod);\n}\nvec4 fragTextureLod (samplerCube tex, vec3 coord, float lod) {\n return textureLod(tex, coord, lod);\n}\n#endif\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\n}\nfloat GGXMobile (float roughness, float NoH, vec3 H, vec3 N) {\n vec3 NxH = cross(N, H);\n float OneMinusNoHSqr = dot(NxH, NxH);\n float a = roughness * roughness;\n float n = NoH * a;\n float p = a / (OneMinusNoHSqr + n * n);\n return p * p;\n}\nfloat CalcSpecular (float roughness, float NoH, vec3 H, vec3 N) {\n return (roughness*0.25 + 0.25) * GGXMobile(roughness, NoH, H, N);\n}\nvec3 BRDFApprox (vec3 specular, float roughness, float NoV) {\n const vec4 c0 = vec4(-1.0, -0.0275, -0.572, 0.022);\n const vec4 c1 = vec4(1.0, 0.0425, 1.04, -0.04);\n vec4 r = roughness * c0 + c1;\n float a004 = min( r.x * r.x, exp2( -9.28 * NoV ) ) * r.x + r.y;\n vec2 AB = vec2( -1.04, 1.04 ) * a004 + r.zw;\n AB.y *= clamp(50.0 * specular.g, 0.0, 1.0);\n return specular * AB.x + AB.y;\n}\nstruct StandardSurface {\n vec4 albedo;\n vec3 position;\n vec3 normal;\n vec3 emissive;\n float roughness;\n float metallic;\n float occlusion;\n};\n#if CC_FOWARD_ADD\nuniform CCForwardLight {\n highp vec4 cc_lightPos[1];\n vec4 cc_lightColor[1];\n vec4 cc_lightSizeRangeAngle[1];\n vec4 cc_lightDir[1];\n};\nfloat SmoothDistAtt (float distSqr, float invSqrAttRadius) {\n float factor = distSqr * invSqrAttRadius;\n float smoothFactor = clamp(1.0 - factor * factor, 0.0, 1.0);\n return smoothFactor * smoothFactor;\n}\nfloat GetDistAtt (float distSqr, float invSqrAttRadius) {\n float attenuation = 1.0 / max(distSqr, 0.01*0.01);\n attenuation *= SmoothDistAtt(distSqr , invSqrAttRadius);\n return attenuation;\n}\nfloat GetAngleAtt (vec3 L, vec3 litDir, float litAngleScale, float litAngleOffset) {\n float cd = dot(litDir, L);\n float attenuation = clamp(cd * litAngleScale + litAngleOffset, 0.0, 1.0);\n return (attenuation * attenuation);\n}\n vec4 CCStandardShading (StandardSurface s) {\n vec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\n vec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\n vec3 diffuseContrib = diffuse / 3.14159265359;\n vec3 N = normalize(s.normal);\n vec3 V = normalize(cc_cameraPos.xyz - s.position);\n float NV = max(abs(dot(N, V)), 0.001);\n specular = BRDFApprox(specular, s.roughness, NV);\n vec3 finalColor = vec3(0.0);\n for (int i = 0; i < 1; i++) {\n vec3 SLU = cc_lightPos[i].xyz - s.position;\n vec3 SL = normalize(SLU);\n vec3 SH = normalize(SL + V);\n float SNL = max(dot(N, SL), 0.001);\n float SNH = max(dot(N, SH), 0.0);\n float distSqr = dot(SLU, SLU);\n float litRadius = cc_lightSizeRangeAngle[i].x;\n float litRadiusSqr = litRadius * litRadius;\n float illum = 3.14159265359 * (litRadiusSqr / max(litRadiusSqr , distSqr));\n float attRadiusSqrInv = 1.0 / max(cc_lightSizeRangeAngle[i].y, 0.01);\n attRadiusSqrInv *= attRadiusSqrInv;\n float att = GetDistAtt(distSqr, attRadiusSqrInv);\n vec3 lspec = specular * CalcSpecular(s.roughness, SNH, SH, N);\n #if CC_SPOTLIGHT\n float cosInner = max(dot(-cc_lightDir[i].xyz, SL), 0.01);\n float cosOuter = cc_lightSizeRangeAngle[i].z;\n float litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\n float litAngleOffset = -cosOuter * litAngleScale;\n att *= GetAngleAtt(SL, -cc_lightDir[i].xyz, litAngleScale, litAngleOffset);\n #endif\n finalColor += SNL * cc_lightColor[i].rgb * cc_lightColor[i].w * illum * att * (diffuseContrib + lspec);\n }\n return vec4(finalColor, 0.0);\n }\n#else\n vec4 CCStandardShading (StandardSurface s) {\n vec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\n vec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\n vec3 N = normalize(s.normal);\n vec3 V = normalize(cc_cameraPos.xyz - s.position);\n vec3 L = normalize(-cc_mainLitDir.xyz);\n vec3 H = normalize(L+V);\n float NV = max(abs(dot(N, V)), 0.001);\n float NL = max(dot(N, L), 0.001);\n float NH = max(dot(N, H), 0.0);\n specular = BRDFApprox(specular, s.roughness, NV);\n vec3 diffuseContrib = diffuse / 3.14159265359;\n vec3 specularContrib = specular * CalcSpecular(s.roughness, NH, H, N);\n vec3 finalColor = NL * cc_mainLitColor.rgb * cc_mainLitColor.w * (diffuseContrib + specularContrib);\n float fAmb = 0.5 - N.y * 0.5;\n vec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb) * cc_ambientSky.w;\n finalColor += (ambDiff.rgb * diffuse);\n #if CC_USE_IBL\n vec3 R = normalize(reflect(-V, N));\n vec4 envmap = fragTextureLod(cc_environment, R, s.roughness * cc_ambientGround.w);\n #if CC_USE_IBL == 2\n vec3 env = unpackRGBE(envmap);\n #else\n vec3 env = SRGBToLinear(envmap.rgb);\n #endif\n finalColor += env * cc_ambientSky.w * specular;\n #endif\n finalColor = finalColor * s.occlusion;\n #if CC_USE_HDR\n s.emissive *= cc_exposure.w;\n #endif\n finalColor += s.emissive;\n return vec4(finalColor, s.albedo.a);\n }\n#endif\nvec3 ACESToneMap (vec3 color) {\n color = min(color, vec3(8.0));\n const float A = 2.51;\n const float B = 0.03;\n const float C = 2.43;\n const float D = 0.59;\n const float E = 0.14;\n return (color * (A * color + B)) / (color * (C * color + D) + E);\n}\nvec4 CCFragOutput (vec4 color) {\n #if !CC_USE_HDR\n color.rgb = sqrt(ACESToneMap(color.rgb));\n #endif\n return color;\n}\nuniform Constants {\n vec4 tilingOffset;\n vec4 albedo;\n vec4 albedoScaleAndCutoff;\n vec4 pbrParams;\n vec4 emissive;\n vec4 emissiveScaleParam;\n};\nin vec3 v_position;\nin vec2 v_uv;\nin vec2 v_uv1;\nin vec3 v_normal;\n#if USE_VERTEX_COLOR\n in vec3 v_color;\n#endif\n#if USE_ALBEDO_MAP\n uniform sampler2D albedoMap;\n#endif\n#if USE_NORMAL_MAP\n in vec3 v_tangent;\n in vec3 v_bitangent;\n uniform sampler2D normalMap;\n#endif\n#if USE_PBR_MAP\n uniform sampler2D pbrMap;\n#endif\n#if USE_METALLIC_ROUGHNESS_MAP\n uniform sampler2D metallicRoughnessMap;\n#endif\n#if USE_OCCLUSION_MAP\n uniform sampler2D occlusionMap;\n#endif\n#if USE_EMISSIVE_MAP\n uniform sampler2D emissiveMap;\n#endif\n#if USE_LIGHTMAP\n in vec2 v_luv;\n uniform sampler2D cc_lightingMap;\n#endif\n#if USE_ALPHA_TEST\n#endif\nin float factor_fog;\nvoid surf (out StandardSurface s) {\n vec4 baseColor = albedo;\n #if USE_VERTEX_COLOR\n baseColor.rgb *= v_color;\n #endif\n #if USE_ALBEDO_MAP\n vec4 texColor = texture(albedoMap, ALBEDO_UV);\n texColor.rgb = SRGBToLinear(texColor.rgb);\n baseColor *= texColor;\n #endif\n s.albedo = baseColor;\n s.albedo.rgb *= albedoScaleAndCutoff.xyz;\n #if USE_ALPHA_TEST\n if (s.albedo.ALPHA_TEST_CHANNEL < albedoScaleAndCutoff.w) discard;\n #endif\n s.normal = v_normal;\n #if USE_NORMAL_MAP\n vec3 nmmp = texture(normalMap, NORMAL_UV).xyz - vec3(0.5);\n s.normal =\n (nmmp.x * pbrParams.w) * normalize(v_tangent) +\n (nmmp.y * pbrParams.w) * normalize(v_bitangent) +\n nmmp.z * normalize(s.normal);\n #endif\n s.position = v_position;\n vec4 pbr = pbrParams;\n #if USE_PBR_MAP\n vec4 res = texture(pbrMap, PBR_UV);\n pbr.x *= res.OCCLUSION_CHANNEL;\n pbr.y *= res.ROUGHNESS_CHANNEL;\n pbr.z *= res.METALLIC_CHANNEL;\n #endif\n #if USE_METALLIC_ROUGHNESS_MAP\n vec4 metallicRoughness = texture(metallicRoughnessMap, METALLIC_ROUGHNESS_UV);\n pbr.z *= metallicRoughness.METALLIC_CHANNEL;\n pbr.y *= metallicRoughness.ROUGHNESS_CHANNEL;\n #endif\n #if USE_OCCLUSION_MAP\n pbr.x *= texture(occlusionMap, OCCLUSION_UV).OCCLUSION_CHANNEL;\n #endif\n s.occlusion = clamp(pbr.x, 0.0, 0.96);\n s.roughness = clamp(pbr.y, 0.04, 1.0);\n s.metallic = pbr.z;\n s.emissive = emissive.rgb * emissiveScaleParam.xyz;\n #if USE_EMISSIVE_MAP\n s.emissive *= SRGBToLinear(texture(emissiveMap, EMISSIVE_UV).rgb);\n #endif\n}\nvec4 frag () {\n StandardSurface s; surf(s);\n vec4 color = CCStandardShading(s);\n #if USE_LIGHTMAP && !USE_BATCHING && !USE_INSTANCING && CC_FOWARD_ADD == 0\n vec4 lighting = texture(cc_lightingMap, v_luv);\n float fAmb = 0.5 - s.normal.y * 0.5;\n vec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb) * cc_ambientSky.w;\n vec3 finalColor = (ambDiff.rgb * s.albedo.rgb);\n finalColor += lighting.rgb * s.albedo.rgb;\n finalColor = finalColor * s.occlusion;\n finalColor += s.emissive;\n color.rgb = lighting.a * finalColor + (1.0 - lighting.a) * color.rgb;\n #endif\n color = mix(cc_fogColor, color, factor_fog);\n return CCFragOutput(color);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }` }, "glsl1": { - "vert": `\nprecision highp float;\nstruct StandardVertInput {\n highp vec4 position;\n vec3 normal;\n vec4 tangent;\n};\nattribute vec3 a_position;\nattribute vec3 a_normal;\nattribute vec4 a_tangent;\n#if CC_USE_MORPH\n attribute float a_vertexId;\n int getVertexId() {\n return int(a_vertexId);\n }\nuniform vec4 cc_displacementWeights[15];\nuniform vec4 cc_displacementTextureInfo;\n vec4 fetchFlatPixel(sampler2D tex, int pixelIndex) {\n float pixelIndexF = float(pixelIndex);\n vec2 textureResolution = vec2(float(cc_displacementTextureInfo.x), float(cc_displacementTextureInfo.y));\n float pixelX = mod(pixelIndexF, textureResolution.x);\n float pixelY = floor(pixelIndexF / textureResolution.x);\n vec2 uv = (vec2(pixelX, pixelY) + .5) / textureResolution;\n return texture2D(tex, uv);\n }\nfloat getDisplacementWeight(int index) {\n float m = mod(float(index), 4.0);\n if (m < 1.0) {\n return cc_displacementWeights[index / 4].x;\n } else if (m < 2.0) {\n return cc_displacementWeights[index / 4].y;\n } else if (m < 3.0) {\n return cc_displacementWeights[index / 4].z;\n } else {\n return cc_displacementWeights[index / 4].w;\n }\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\n return fetchFlatPixel(tex, vertexIndex).rgb;\n#else\n vec3 result = vec3(0, 0, 0);\n for (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\n int dataPixelStart = int(fetchFlatPixel(tex, iTarget).r);\n result += (fetchFlatPixel(tex, dataPixelStart + vertexIndex).rgb * getDisplacementWeight(iTarget));\n }\n return result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\n uniform sampler2D cc_PositionDisplacements;\n vec3 getPositionDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n uniform sampler2D cc_NormalDisplacements;\n vec3 getNormalDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n uniform sampler2D cc_TangentDisplacements;\n vec3 getTangentDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n }\n#endif\nvoid applyMorph (inout StandardVertInput attr) {\n int vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\n attr.position.xyz = attr.position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n attr.normal.xyz = attr.normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n attr.tangent.xyz = attr.tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\n position.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\nattribute vec4 a_weights;\nattribute vec4 a_joints;\n#if CC_USE_BAKED_ANIMATION\n #if USE_INSTANCING\n attribute highp vec4 a_jointAnimInfo;\n #endif\n uniform highp vec4 cc_jointTextureInfo;\n uniform highp vec4 cc_jointAnimInfo;\n uniform sampler2D cc_jointTexture;\n #if !CC_SUPPORT_FLOAT_TEXTURE\n highp float decode32 (highp vec4 rgba) {\n rgba = rgba * 255.0;\n highp float Sign = 1.0 - step(128.0, rgba[3]) * 2.0;\n highp float Exponent = 2.0 * mod(rgba[3], 128.0) + step(128.0, rgba[2]) - 127.0;\n highp float Mantissa = mod(rgba[2], 128.0) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\n }\n #endif\n#else\n uniform highp vec4 cc_joints[90];\n#endif\n#if CC_USE_BAKED_ANIMATION\n #if CC_SUPPORT_FLOAT_TEXTURE\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 3.0 * (a_jointAnimInfo.x * a_jointAnimInfo.y + i) + a_jointAnimInfo.z;\n #else\n highp float j = 3.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y));\n vec4 v2 = texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y));\n vec4 v3 = texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y));\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #else\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 12.0 * (a_jointAnimInfo.x * a_jointAnimInfo.y + i) + a_jointAnimInfo.z;\n #else\n highp float j = 12.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = vec4(\n decode32(texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n );\n vec4 v2 = vec4(\n decode32(texture2D(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n );\n vec4 v3 = vec4(\n decode32(texture2D(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n );\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #endif\n#else\n mat4 getJointMatrix (float i) {\n int idx = int(i);\n vec4 v1 = cc_joints[idx * 3];\n vec4 v2 = cc_joints[idx * 3 + 1];\n vec4 v3 = cc_joints[idx * 3 + 2];\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n#endif\nmat4 skinMatrix () {\n return getJointMatrix(a_joints.x) * a_weights.x\n + getJointMatrix(a_joints.y) * a_weights.y;\n + getJointMatrix(a_joints.z) * a_weights.z;\n + getJointMatrix(a_joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\n mat4 m = skinMatrix();\n position = m * position;\n}\nvoid CCSkin (inout StandardVertInput attr) {\n mat4 m = skinMatrix();\n attr.position = m * attr.position;\n attr.normal = (m * vec4(attr.normal, 0.0)).xyz;\n attr.tangent.xyz = (m * vec4(attr.tangent.xyz, 0.0)).xyz;\n}\n#endif\nuniform highp mat4 cc_matView;\nuniform highp mat4 cc_matProj;\n#if USE_INSTANCING\n attribute vec4 a_matWorld0;\n attribute vec4 a_matWorld1;\n attribute vec4 a_matWorld2;\n#elif USE_BATCHING\n attribute float a_dyn_batch_id;\n uniform highp mat4 cc_matWorlds[10];\n#else\nuniform highp mat4 cc_matWorld;\nuniform highp mat4 cc_matWorldIT;\n#endif\nuniform vec4 tilingOffset;\n#if USE_VERTEX_COLOR\n attribute vec3 a_color;\n varying vec3 v_color;\n#endif\nvarying vec3 v_position;\nvarying vec3 v_normal;\n#if USE_NORMAL_MAP\n varying vec3 v_tangent;\n varying vec3 v_bitangent;\n#endif\nattribute vec2 a_texCoord;\nvarying vec2 v_uv;\nattribute vec2 a_texCoord1;\nvarying vec2 v_uv1;\nvec4 vert () {\n StandardVertInput In;\n In.position = vec4(a_position, 1.0);\n In.normal = a_normal;\n In.tangent = a_tangent;\n #if CC_USE_MORPH\n applyMorph(In);\n #endif\n #if CC_USE_SKINNING\n CCSkin(In);\n #endif\n mat4 matWorld, matWorldIT;\n #if USE_INSTANCING\n matWorld = mat4(\n vec4(a_matWorld0.xyz, 0.0),\n vec4(a_matWorld1.xyz, 0.0),\n vec4(a_matWorld2.xyz, 0.0),\n vec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)\n );\n matWorldIT = matWorld;\n #elif USE_BATCHING\n matWorld = cc_matWorlds[int(a_dyn_batch_id)];\n matWorldIT = matWorld;\n #else\n matWorld = cc_matWorld;\n matWorldIT = cc_matWorldIT;\n #endif\n vec4 pos = matWorld * In.position;\n v_position = pos.xyz;\n v_normal = normalize((matWorldIT * vec4(In.normal, 0.0)).xyz);\n #if USE_NORMAL_MAP\n v_tangent = normalize((matWorld * vec4(In.tangent.xyz, 0.0)).xyz);\n v_bitangent = cross(v_normal, v_tangent) * In.tangent.w;\n #endif\n v_uv = a_texCoord * tilingOffset.xy + tilingOffset.zw;\n #if HAS_SECOND_UV\n v_uv1 = a_texCoord1 * tilingOffset.xy + tilingOffset.zw;\n #endif\n #if USE_VERTEX_COLOR\n v_color = a_color;\n #endif\n return cc_matProj * (cc_matView * matWorld) * In.position;\n}\nvoid main() { gl_Position = vert(); }`, - "frag": `\n #ifdef GL_EXT_shader_texture_lod\n #extension GL_EXT_shader_texture_lod : enable\n #endif\nprecision highp float;\nuniform highp vec4 cc_cameraPos;\nuniform mediump vec4 cc_exposure;\nuniform mediump vec4 cc_mainLitDir;\nuniform mediump vec4 cc_mainLitColor;\nuniform mediump vec4 cc_ambientSky;\nuniform mediump vec4 cc_ambientGround;\n#if CC_USE_IBL\nuniform samplerCube cc_environment;\nvec3 unpackRGBE (vec4 rgbe) {\n return rgbe.rgb * pow(2.0, rgbe.a * 255.0 - 128.0);\n}\nvec4 fragTextureLod (sampler2D tex, vec2 coord, float lod) {\n #ifdef GL_EXT_shader_texture_lod\n return texture2DLodEXT(tex, coord, lod);\n #else\n return texture2D(tex, coord, lod);\n #endif\n}\nvec4 fragTextureLod (samplerCube tex, vec3 coord, float lod) {\n #ifdef GL_EXT_shader_texture_lod\n return textureCubeLodEXT(tex, coord, lod);\n #else\n return textureCube(tex, coord, lod);\n #endif\n}\n#endif\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\n}\nuniform highp vec4 cc_sphereLitPos[2];\nuniform vec4 cc_sphereLitSizeRange[2];\nuniform vec4 cc_sphereLitColor[2];\nuniform highp vec4 cc_spotLitPos[2];\nuniform vec4 cc_spotLitSizeRangeAngle[2];\nuniform vec4 cc_spotLitDir[2];\nuniform vec4 cc_spotLitColor[2];\nfloat SmoothDistAtt (float distSqr, float invSqrAttRadius) {\n float factor = distSqr * invSqrAttRadius;\n float smoothFactor = clamp(1.0 - factor * factor, 0.0, 1.0);\n return smoothFactor * smoothFactor;\n}\nfloat GetDistAtt (float distSqr, float invSqrAttRadius) {\n float attenuation = 1.0 / max(distSqr, 0.01*0.01);\n attenuation *= SmoothDistAtt(distSqr , invSqrAttRadius);\n return attenuation;\n}\nfloat GetAngleAtt (vec3 L, vec3 litDir, float litAngleScale, float litAngleOffset) {\n float cd = dot(litDir, L);\n float attenuation = clamp(cd * litAngleScale + litAngleOffset, 0.0, 1.0);\n return (attenuation * attenuation);\n}\nfloat GGXMobile (float roughness, float NoH, vec3 H, vec3 N) {\n vec3 NxH = cross(N, H);\n float OneMinusNoHSqr = dot(NxH, NxH);\n float a = roughness * roughness;\n float n = NoH * a;\n float p = a / (OneMinusNoHSqr + n * n);\n return p * p;\n}\nfloat CalcSpecular (float roughness, float NoH, vec3 H, vec3 N) {\n return (roughness*0.25 + 0.25) * GGXMobile(roughness, NoH, H, N);\n}\nvec3 BRDFApprox (vec3 specular, float roughness, float NoV) {\n const vec4 c0 = vec4(-1.0, -0.0275, -0.572, 0.022);\n const vec4 c1 = vec4(1.0, 0.0425, 1.04, -0.04);\n vec4 r = roughness * c0 + c1;\n float a004 = min( r.x * r.x, exp2( -9.28 * NoV ) ) * r.x + r.y;\n vec2 AB = vec2( -1.04, 1.04 ) * a004 + r.zw;\n AB.y *= clamp(50.0 * specular.g, 0.0, 1.0);\n return specular * AB.x + AB.y;\n}\nvec3 CalcDynamicLighting (vec3 worldPos, vec3 N, vec3 V, vec3 diffuse, vec3 specular, float roughness) {\n vec3 lighting = vec3(0.0);\n vec3 diffuseContrib = diffuse / 3.14159265359;\n for (int i = 0; i < 2; i++) {\n vec3 PLU = cc_sphereLitPos[i].xyz - worldPos;\n vec3 PL = normalize(PLU);\n vec3 PH = normalize(PL + V);\n float PNL = max(dot(N, PL), 0.001);\n float PNH = max(dot(N, PH), 0.0);\n float distSqr = dot(PLU, PLU);\n float litRadius = cc_sphereLitSizeRange[i].x;\n float litRadiusSqr = litRadius * litRadius;\n float illum = 3.14159265359 * (litRadiusSqr / max(litRadiusSqr , distSqr));\n float attRadiusSqrInv = 1.0 / max(cc_sphereLitSizeRange[i].y, 0.01);\n attRadiusSqrInv *= attRadiusSqrInv;\n float att = GetDistAtt(distSqr, attRadiusSqrInv);\n vec3 lspec = specular * CalcSpecular(roughness, PNH, PH, N);\n lighting += PNL * cc_sphereLitColor[i].rgb * cc_sphereLitColor[i].w * illum * att * (diffuseContrib + lspec);\n }\n for (int i = 0; i < 2; i++) {\n vec3 SLU = cc_spotLitPos[i].xyz - worldPos;\n vec3 SL = normalize(SLU);\n vec3 SH = normalize(SL + V);\n float SNL = max(dot(N, SL), 0.001);\n float SNH = max(dot(N, SH), 0.0);\n float distSqr = dot(SLU, SLU);\n float litRadius = cc_spotLitSizeRangeAngle[i].x;\n float litRadiusSqr = litRadius * litRadius;\n float illum = 3.14159265359 * (litRadiusSqr / max(litRadiusSqr , distSqr));\n float attRadiusSqrInv = 1.0 / max(cc_spotLitSizeRangeAngle[i].y, 0.01);\n attRadiusSqrInv *= attRadiusSqrInv;\n float cosInner = max(dot(-cc_spotLitDir[i].xyz, SL), 0.01);\n float cosOuter = cc_spotLitSizeRangeAngle[i].z;\n float litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\n float litAngleOffset = -cosOuter * litAngleScale;\n float att = GetDistAtt(distSqr, attRadiusSqrInv);\n att *= GetAngleAtt(SL, -cc_spotLitDir[i].xyz, litAngleScale, litAngleOffset);\n vec3 lspec = specular * CalcSpecular(roughness, SNH, SH, N);\n lighting += SNL * cc_spotLitColor[i].rgb * cc_spotLitColor[i].w * illum * att * (diffuseContrib + lspec);\n }\n return lighting;\n}\nstruct StandardSurface {\n vec4 albedo;\n vec3 position;\n vec3 normal;\n vec3 emissive;\n float roughness;\n float metallic;\n float occlusion;\n};\nvec4 CCStandardShading (StandardSurface s) {\n vec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\n vec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\n vec3 N = normalize(s.normal);\n vec3 V = normalize(cc_cameraPos.xyz - s.position);\n vec3 L = normalize(-cc_mainLitDir.xyz);\n vec3 H = normalize(L+V);\n float NV = max(abs(dot(N, V)), 0.001);\n float NL = max(dot(N, L), 0.001);\n float NH = max(dot(N, H), 0.0);\n specular = BRDFApprox(specular, s.roughness, NV);\n vec3 diffuseContrib = diffuse / 3.14159265359;\n vec3 specularContrib = specular * CalcSpecular(s.roughness, NH, H, N);\n vec3 finalColor = NL * cc_mainLitColor.rgb * cc_mainLitColor.w * (diffuseContrib + specularContrib);\n finalColor += CalcDynamicLighting(s.position, N, V, diffuse, specular, s.roughness);\n float fAmb = 0.5 - N.y * 0.5;\n vec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb) * cc_ambientSky.w;\n finalColor += (ambDiff.rgb * diffuse);\n #if CC_USE_IBL\n vec3 R = normalize(reflect(-V, N));\n vec4 envmap = fragTextureLod(cc_environment, R, s.roughness * cc_ambientGround.w);\n #if CC_USE_IBL == 2\n vec3 env = unpackRGBE(envmap);\n #else\n vec3 env = SRGBToLinear(envmap.rgb);\n #endif\n finalColor += env * cc_ambientSky.w * specular;\n #endif\n finalColor = finalColor * s.occlusion;\n #if CC_USE_HDR\n s.emissive *= cc_exposure.w;\n #endif\n finalColor += s.emissive;\n return vec4(finalColor, s.albedo.a);\n}\nvec3 ACESToneMap (vec3 color) {\n color = min(color, vec3(8.0));\n const float A = 2.51;\n const float B = 0.03;\n const float C = 2.43;\n const float D = 0.59;\n const float E = 0.14;\n return (color * (A * color + B)) / (color * (C * color + D) + E);\n}\nvec4 CCFragOutput (vec4 color) {\n #if !CC_USE_HDR\n color.rgb = sqrt(ACESToneMap(color.rgb));\n #endif\n return color;\n}\nuniform vec4 albedo;\nuniform vec4 albedoScaleAndCutoff;\nuniform vec4 pbrParams;\nuniform vec4 emissive;\nuniform vec4 emissiveScaleParam;\nvarying vec3 v_position;\nvarying vec2 v_uv;\nvarying vec2 v_uv1;\nvarying vec3 v_normal;\n#if USE_VERTEX_COLOR\n varying vec3 v_color;\n#endif\n#if USE_ALBEDO_MAP\n uniform sampler2D albedoMap;\n#endif\n#if USE_NORMAL_MAP\n varying vec3 v_tangent;\n varying vec3 v_bitangent;\n uniform sampler2D normalMap;\n#endif\n#if USE_PBR_MAP\n uniform sampler2D pbrMap;\n#endif\n#if USE_METALLIC_ROUGHNESS_MAP\n uniform sampler2D metallicRoughnessMap;\n#endif\n#if USE_OCCLUSION_MAP\n uniform sampler2D occlusionMap;\n#endif\n#if USE_EMISSIVE_MAP\n uniform sampler2D emissiveMap;\n#endif\n#if USE_ALPHA_TEST\n#endif\nvoid surf (out StandardSurface s) {\n vec4 baseColor = albedo;\n #if USE_VERTEX_COLOR\n baseColor.rgb *= v_color;\n #endif\n #if USE_ALBEDO_MAP\n vec4 texColor = texture2D(albedoMap, ALBEDO_UV);\n texColor.rgb = SRGBToLinear(texColor.rgb);\n baseColor *= texColor;\n #endif\n s.albedo = baseColor;\n s.albedo.rgb *= albedoScaleAndCutoff.xyz;\n #if USE_ALPHA_TEST\n if (s.albedo.ALPHA_TEST_CHANNEL < albedoScaleAndCutoff.w) discard;\n #endif\n s.normal = v_normal;\n #if USE_NORMAL_MAP\n vec3 nmmp = texture2D(normalMap, NORMAL_UV).xyz - vec3(0.5);\n s.normal =\n (nmmp.x * pbrParams.w) * normalize(v_tangent) +\n (nmmp.y * pbrParams.w) * normalize(v_bitangent) +\n nmmp.z * normalize(s.normal);\n #endif\n s.position = v_position;\n vec4 pbr = pbrParams;\n #if USE_PBR_MAP\n vec4 res = texture2D(pbrMap, PBR_UV);\n pbr.x *= res.OCCLUSION_CHANNEL;\n pbr.y *= res.ROUGHNESS_CHANNEL;\n pbr.z *= res.METALLIC_CHANNEL;\n #endif\n #if USE_METALLIC_ROUGHNESS_MAP\n vec4 metallicRoughness = texture2D(metallicRoughnessMap, METALLIC_ROUGHNESS_UV);\n pbr.z *= metallicRoughness.METALLIC_CHANNEL;\n pbr.y *= metallicRoughness.ROUGHNESS_CHANNEL;\n #endif\n #if USE_OCCLUSION_MAP\n pbr.x *= texture2D(occlusionMap, OCCLUSION_UV).OCCLUSION_CHANNEL;\n #endif\n s.occlusion = clamp(pbr.x, 0.0, 0.96);\n s.roughness = clamp(pbr.y, 0.04, 1.0);\n s.metallic = pbr.z;\n s.emissive = emissive.rgb * emissiveScaleParam.xyz;\n #if USE_EMISSIVE_MAP\n s.emissive *= SRGBToLinear(texture2D(emissiveMap, EMISSIVE_UV).rgb);\n #endif\n}\nvec4 frag () {\n StandardSurface s; surf(s);\n vec4 color = CCStandardShading(s);\n return CCFragOutput(color);\n}\nvoid main() { gl_FragColor = frag(); }` + "vert": `\nprecision highp float;\nuniform highp mat4 cc_matView;\nuniform highp mat4 cc_matProj;\nuniform highp vec4 cc_cameraPos;\nuniform mediump vec4 cc_fogBase;\nuniform mediump vec4 cc_fogAdd;\n#if USE_INSTANCING\n attribute vec4 a_matWorld0;\n attribute vec4 a_matWorld1;\n attribute vec4 a_matWorld2;\n#elif USE_BATCHING\n attribute float a_dyn_batch_id;\n uniform highp mat4 cc_matWorlds[10];\n#else\nuniform highp mat4 cc_matWorld;\nuniform highp mat4 cc_matWorldIT;\nuniform highp vec4 cc_lightingMapUVParam;\n#endif\nstruct StandardVertInput {\n highp vec4 position;\n vec3 normal;\n vec4 tangent;\n};\nattribute vec3 a_position;\nattribute vec3 a_normal;\nattribute vec4 a_tangent;\n#if CC_USE_MORPH\n attribute float a_vertexId;\n int getVertexId() {\n return int(a_vertexId);\n }\nuniform vec4 cc_displacementWeights[15];\nuniform vec4 cc_displacementTextureInfo;\n vec4 fetchFlatPixel(sampler2D tex, int pixelIndex) {\n float pixelIndexF = float(pixelIndex);\n vec2 textureResolution = vec2(float(cc_displacementTextureInfo.x), float(cc_displacementTextureInfo.y));\n float pixelX = mod(pixelIndexF, textureResolution.x);\n float pixelY = floor(pixelIndexF / textureResolution.x);\n vec2 uv = (vec2(pixelX, pixelY) + .5) / textureResolution;\n return texture2D(tex, uv);\n }\nfloat getDisplacementWeight(int index) {\n float m = mod(float(index), 4.0);\n if (m < 1.0) {\n return cc_displacementWeights[index / 4].x;\n } else if (m < 2.0) {\n return cc_displacementWeights[index / 4].y;\n } else if (m < 3.0) {\n return cc_displacementWeights[index / 4].z;\n } else {\n return cc_displacementWeights[index / 4].w;\n }\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\n return fetchFlatPixel(tex, vertexIndex).rgb;\n#else\n vec3 result = vec3(0, 0, 0);\n for (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\n int dataPixelStart = int(fetchFlatPixel(tex, iTarget).r);\n result += (fetchFlatPixel(tex, dataPixelStart + vertexIndex).rgb * getDisplacementWeight(iTarget));\n }\n return result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\n uniform sampler2D cc_PositionDisplacements;\n vec3 getPositionDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n uniform sampler2D cc_NormalDisplacements;\n vec3 getNormalDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n uniform sampler2D cc_TangentDisplacements;\n vec3 getTangentDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n }\n#endif\nvoid applyMorph (inout StandardVertInput attr) {\n int vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\n attr.position.xyz = attr.position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n attr.normal.xyz = attr.normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n attr.tangent.xyz = attr.tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\n position.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\nattribute vec4 a_weights;\nattribute vec4 a_joints;\n#if CC_USE_BAKED_ANIMATION\n #if USE_INSTANCING\n attribute vec4 a_jointAnimInfo;\n #endif\n uniform highp vec4 cc_jointTextureInfo;\n uniform highp vec4 cc_jointAnimInfo;\n uniform sampler2D cc_jointTexture;\n #if !CC_SUPPORT_FLOAT_TEXTURE\n highp float decode32 (highp vec4 rgba) {\n rgba = rgba * 255.0;\n highp float Sign = 1.0 - step(128.0, rgba[3]) * 2.0;\n highp float Exponent = 2.0 * mod(rgba[3], 128.0) + step(128.0, rgba[2]) - 127.0;\n highp float Mantissa = mod(rgba[2], 128.0) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\n }\n #endif\n#else\n uniform highp vec4 cc_joints[90];\n#endif\n#if CC_USE_BAKED_ANIMATION\n #if CC_SUPPORT_FLOAT_TEXTURE\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 3.0 * i + a_jointAnimInfo.x;\n #else\n highp float j = 3.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y));\n vec4 v2 = texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y));\n vec4 v3 = texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y));\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #else\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 12.0 * i + a_jointAnimInfo.x;\n #else\n highp float j = 12.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = vec4(\n decode32(texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n );\n vec4 v2 = vec4(\n decode32(texture2D(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n );\n vec4 v3 = vec4(\n decode32(texture2D(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n );\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #endif\n#else\n mat4 getJointMatrix (float i) {\n int idx = int(i);\n vec4 v1 = cc_joints[idx * 3];\n vec4 v2 = cc_joints[idx * 3 + 1];\n vec4 v3 = cc_joints[idx * 3 + 2];\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n#endif\nmat4 skinMatrix () {\n return getJointMatrix(a_joints.x) * a_weights.x\n + getJointMatrix(a_joints.y) * a_weights.y;\n + getJointMatrix(a_joints.z) * a_weights.z;\n + getJointMatrix(a_joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\n mat4 m = skinMatrix();\n position = m * position;\n}\nvoid CCSkin (inout StandardVertInput attr) {\n mat4 m = skinMatrix();\n attr.position = m * attr.position;\n attr.normal = (m * vec4(attr.normal, 0.0)).xyz;\n attr.tangent.xyz = (m * vec4(attr.tangent.xyz, 0.0)).xyz;\n}\n#endif\nuniform vec4 tilingOffset;\nfloat LinearFog(vec4 pos) {\n vec4 wPos = pos;\n float cam_dis = distance(cc_cameraPos, wPos);\n float fogStart = cc_fogBase.x;\n float fogEnd = cc_fogBase.y;\n return clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float fogDensity = cc_fogBase.z;\n float cam_dis = distance(cc_cameraPos, wPos) / fogAtten * 4.;\n float f = exp(-cam_dis * fogDensity);\n return f;\n}\nfloat ExpSquaredFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float fogDensity = cc_fogBase.z;\n float cam_dis = distance(cc_cameraPos, wPos) / fogAtten * 4.;\n float f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\n return f;\n}\nfloat LayeredFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float _FogTop = cc_fogAdd.x;\n float _FogRange = cc_fogAdd.y;\n vec3 camWorldProj = cc_cameraPos.xyz;\n camWorldProj.y = 0.;\n vec3 worldPosProj = wPos.xyz;\n worldPosProj.y = 0.;\n float fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\n float fDeltaY, fDensityIntegral;\n if (cc_cameraPos.y > _FogTop) {\n if (wPos.y < _FogTop) {\n fDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\n fDensityIntegral = fDeltaY * fDeltaY * 0.5;\n } else {\n fDeltaY = 0.;\n fDensityIntegral = 0.;\n }\n } else {\n if (wPos.y < _FogTop) {\n float fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\n float fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\n fDeltaY = abs(fDeltaA - fDeltaB);\n fDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n } else {\n fDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\n fDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n }\n }\n float fDensity;\n if (fDeltaY != 0.) {\n fDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n } else {\n fDensity = 0.;\n }\n float f = exp(-fDensity);\n return f;\n}\nfloat CC_TRANSFER_FOG(vec4 pos) {\n #if CC_USE_FOG == 1\n return LinearFog(pos);\n #elif CC_USE_FOG == 2\n return ExpFog(pos);\n #elif CC_USE_FOG == 3\n return ExpSquaredFog(pos);\n #elif CC_USE_FOG == 4\n return LayeredFog(pos);\n #endif\n return 1.;\n}\n#if USE_VERTEX_COLOR\n attribute vec3 a_color;\n varying vec3 v_color;\n#endif\nvarying vec3 v_position;\nvarying vec3 v_normal;\n#if USE_NORMAL_MAP\n varying vec3 v_tangent;\n varying vec3 v_bitangent;\n#endif\nattribute vec2 a_texCoord;\nvarying vec2 v_uv;\nattribute vec2 a_texCoord1;\nvarying vec2 v_uv1;\nvarying float factor_fog;\n#if USE_LIGHTMAP && !USE_BATCHING && !USE_INSTANCING\n varying vec2 v_luv;\n#endif\nvec4 vert () {\n StandardVertInput In;\n In.position = vec4(a_position, 1.0);\n In.normal = a_normal;\n In.tangent = a_tangent;\n #if CC_USE_MORPH\n applyMorph(In);\n #endif\n #if CC_USE_SKINNING\n CCSkin(In);\n #endif\n mat4 matWorld, matWorldIT;\n #if USE_INSTANCING\n matWorld = mat4(\n vec4(a_matWorld0.xyz, 0.0),\n vec4(a_matWorld1.xyz, 0.0),\n vec4(a_matWorld2.xyz, 0.0),\n vec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)\n );\n matWorldIT = matWorld;\n #elif USE_BATCHING\n matWorld = cc_matWorlds[int(a_dyn_batch_id)];\n matWorldIT = matWorld;\n #else\n matWorld = cc_matWorld;\n matWorldIT = cc_matWorldIT;\n #endif\n vec4 pos = matWorld * In.position;\n v_position = pos.xyz;\n v_normal = normalize((matWorldIT * vec4(In.normal, 0.0)).xyz);\n #if USE_NORMAL_MAP\n v_tangent = normalize((matWorld * vec4(In.tangent.xyz, 0.0)).xyz);\n v_bitangent = cross(v_normal, v_tangent) * In.tangent.w;\n #endif\n v_uv = a_texCoord * tilingOffset.xy + tilingOffset.zw;\n #if HAS_SECOND_UV\n v_uv1 = a_texCoord1 * tilingOffset.xy + tilingOffset.zw;\n #endif\n #if USE_VERTEX_COLOR\n v_color = a_color;\n #endif\n factor_fog = CC_TRANSFER_FOG(matWorld * In.position);\n #if USE_LIGHTMAP && HAS_SECOND_UV && !USE_BATCHING && !USE_INSTANCING\n v_luv = cc_lightingMapUVParam.xy + a_texCoord1 * cc_lightingMapUVParam.zw;\n #endif\n return cc_matProj * (cc_matView * matWorld) * In.position;\n}\nvoid main() { gl_Position = vert(); }`, + "frag": `\n #ifdef GL_EXT_shader_texture_lod\n #extension GL_EXT_shader_texture_lod : enable\n #endif\nprecision highp float;\nuniform highp vec4 cc_cameraPos;\nuniform mediump vec4 cc_exposure;\nuniform mediump vec4 cc_mainLitDir;\nuniform mediump vec4 cc_mainLitColor;\nuniform mediump vec4 cc_ambientSky;\nuniform mediump vec4 cc_ambientGround;\nuniform mediump vec4 cc_fogColor;\n#if CC_USE_IBL\nuniform samplerCube cc_environment;\nvec3 unpackRGBE (vec4 rgbe) {\n return rgbe.rgb * pow(2.0, rgbe.a * 255.0 - 128.0);\n}\nvec4 fragTextureLod (sampler2D tex, vec2 coord, float lod) {\n #ifdef GL_EXT_shader_texture_lod\n return texture2DLodEXT(tex, coord, lod);\n #else\n return texture2D(tex, coord, lod);\n #endif\n}\nvec4 fragTextureLod (samplerCube tex, vec3 coord, float lod) {\n #ifdef GL_EXT_shader_texture_lod\n return textureCubeLodEXT(tex, coord, lod);\n #else\n return textureCube(tex, coord, lod);\n #endif\n}\n#endif\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\n}\nfloat GGXMobile (float roughness, float NoH, vec3 H, vec3 N) {\n vec3 NxH = cross(N, H);\n float OneMinusNoHSqr = dot(NxH, NxH);\n float a = roughness * roughness;\n float n = NoH * a;\n float p = a / (OneMinusNoHSqr + n * n);\n return p * p;\n}\nfloat CalcSpecular (float roughness, float NoH, vec3 H, vec3 N) {\n return (roughness*0.25 + 0.25) * GGXMobile(roughness, NoH, H, N);\n}\nvec3 BRDFApprox (vec3 specular, float roughness, float NoV) {\n const vec4 c0 = vec4(-1.0, -0.0275, -0.572, 0.022);\n const vec4 c1 = vec4(1.0, 0.0425, 1.04, -0.04);\n vec4 r = roughness * c0 + c1;\n float a004 = min( r.x * r.x, exp2( -9.28 * NoV ) ) * r.x + r.y;\n vec2 AB = vec2( -1.04, 1.04 ) * a004 + r.zw;\n AB.y *= clamp(50.0 * specular.g, 0.0, 1.0);\n return specular * AB.x + AB.y;\n}\nstruct StandardSurface {\n vec4 albedo;\n vec3 position;\n vec3 normal;\n vec3 emissive;\n float roughness;\n float metallic;\n float occlusion;\n};\n#if CC_FOWARD_ADD\nuniform highp vec4 cc_lightPos[1];\nuniform vec4 cc_lightColor[1];\nuniform vec4 cc_lightSizeRangeAngle[1];\nuniform vec4 cc_lightDir[1];\nfloat SmoothDistAtt (float distSqr, float invSqrAttRadius) {\n float factor = distSqr * invSqrAttRadius;\n float smoothFactor = clamp(1.0 - factor * factor, 0.0, 1.0);\n return smoothFactor * smoothFactor;\n}\nfloat GetDistAtt (float distSqr, float invSqrAttRadius) {\n float attenuation = 1.0 / max(distSqr, 0.01*0.01);\n attenuation *= SmoothDistAtt(distSqr , invSqrAttRadius);\n return attenuation;\n}\nfloat GetAngleAtt (vec3 L, vec3 litDir, float litAngleScale, float litAngleOffset) {\n float cd = dot(litDir, L);\n float attenuation = clamp(cd * litAngleScale + litAngleOffset, 0.0, 1.0);\n return (attenuation * attenuation);\n}\n vec4 CCStandardShading (StandardSurface s) {\n vec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\n vec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\n vec3 diffuseContrib = diffuse / 3.14159265359;\n vec3 N = normalize(s.normal);\n vec3 V = normalize(cc_cameraPos.xyz - s.position);\n float NV = max(abs(dot(N, V)), 0.001);\n specular = BRDFApprox(specular, s.roughness, NV);\n vec3 finalColor = vec3(0.0);\n for (int i = 0; i < 1; i++) {\n vec3 SLU = cc_lightPos[i].xyz - s.position;\n vec3 SL = normalize(SLU);\n vec3 SH = normalize(SL + V);\n float SNL = max(dot(N, SL), 0.001);\n float SNH = max(dot(N, SH), 0.0);\n float distSqr = dot(SLU, SLU);\n float litRadius = cc_lightSizeRangeAngle[i].x;\n float litRadiusSqr = litRadius * litRadius;\n float illum = 3.14159265359 * (litRadiusSqr / max(litRadiusSqr , distSqr));\n float attRadiusSqrInv = 1.0 / max(cc_lightSizeRangeAngle[i].y, 0.01);\n attRadiusSqrInv *= attRadiusSqrInv;\n float att = GetDistAtt(distSqr, attRadiusSqrInv);\n vec3 lspec = specular * CalcSpecular(s.roughness, SNH, SH, N);\n #if CC_SPOTLIGHT\n float cosInner = max(dot(-cc_lightDir[i].xyz, SL), 0.01);\n float cosOuter = cc_lightSizeRangeAngle[i].z;\n float litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\n float litAngleOffset = -cosOuter * litAngleScale;\n att *= GetAngleAtt(SL, -cc_lightDir[i].xyz, litAngleScale, litAngleOffset);\n #endif\n finalColor += SNL * cc_lightColor[i].rgb * cc_lightColor[i].w * illum * att * (diffuseContrib + lspec);\n }\n return vec4(finalColor, 0.0);\n }\n#else\n vec4 CCStandardShading (StandardSurface s) {\n vec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\n vec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\n vec3 N = normalize(s.normal);\n vec3 V = normalize(cc_cameraPos.xyz - s.position);\n vec3 L = normalize(-cc_mainLitDir.xyz);\n vec3 H = normalize(L+V);\n float NV = max(abs(dot(N, V)), 0.001);\n float NL = max(dot(N, L), 0.001);\n float NH = max(dot(N, H), 0.0);\n specular = BRDFApprox(specular, s.roughness, NV);\n vec3 diffuseContrib = diffuse / 3.14159265359;\n vec3 specularContrib = specular * CalcSpecular(s.roughness, NH, H, N);\n vec3 finalColor = NL * cc_mainLitColor.rgb * cc_mainLitColor.w * (diffuseContrib + specularContrib);\n float fAmb = 0.5 - N.y * 0.5;\n vec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb) * cc_ambientSky.w;\n finalColor += (ambDiff.rgb * diffuse);\n #if CC_USE_IBL\n vec3 R = normalize(reflect(-V, N));\n vec4 envmap = fragTextureLod(cc_environment, R, s.roughness * cc_ambientGround.w);\n #if CC_USE_IBL == 2\n vec3 env = unpackRGBE(envmap);\n #else\n vec3 env = SRGBToLinear(envmap.rgb);\n #endif\n finalColor += env * cc_ambientSky.w * specular;\n #endif\n finalColor = finalColor * s.occlusion;\n #if CC_USE_HDR\n s.emissive *= cc_exposure.w;\n #endif\n finalColor += s.emissive;\n return vec4(finalColor, s.albedo.a);\n }\n#endif\nvec3 ACESToneMap (vec3 color) {\n color = min(color, vec3(8.0));\n const float A = 2.51;\n const float B = 0.03;\n const float C = 2.43;\n const float D = 0.59;\n const float E = 0.14;\n return (color * (A * color + B)) / (color * (C * color + D) + E);\n}\nvec4 CCFragOutput (vec4 color) {\n #if !CC_USE_HDR\n color.rgb = sqrt(ACESToneMap(color.rgb));\n #endif\n return color;\n}\nuniform vec4 albedo;\nuniform vec4 albedoScaleAndCutoff;\nuniform vec4 pbrParams;\nuniform vec4 emissive;\nuniform vec4 emissiveScaleParam;\nvarying vec3 v_position;\nvarying vec2 v_uv;\nvarying vec2 v_uv1;\nvarying vec3 v_normal;\n#if USE_VERTEX_COLOR\n varying vec3 v_color;\n#endif\n#if USE_ALBEDO_MAP\n uniform sampler2D albedoMap;\n#endif\n#if USE_NORMAL_MAP\n varying vec3 v_tangent;\n varying vec3 v_bitangent;\n uniform sampler2D normalMap;\n#endif\n#if USE_PBR_MAP\n uniform sampler2D pbrMap;\n#endif\n#if USE_METALLIC_ROUGHNESS_MAP\n uniform sampler2D metallicRoughnessMap;\n#endif\n#if USE_OCCLUSION_MAP\n uniform sampler2D occlusionMap;\n#endif\n#if USE_EMISSIVE_MAP\n uniform sampler2D emissiveMap;\n#endif\n#if USE_LIGHTMAP\n varying vec2 v_luv;\n uniform sampler2D cc_lightingMap;\n#endif\n#if USE_ALPHA_TEST\n#endif\nvarying float factor_fog;\nvoid surf (out StandardSurface s) {\n vec4 baseColor = albedo;\n #if USE_VERTEX_COLOR\n baseColor.rgb *= v_color;\n #endif\n #if USE_ALBEDO_MAP\n vec4 texColor = texture2D(albedoMap, ALBEDO_UV);\n texColor.rgb = SRGBToLinear(texColor.rgb);\n baseColor *= texColor;\n #endif\n s.albedo = baseColor;\n s.albedo.rgb *= albedoScaleAndCutoff.xyz;\n #if USE_ALPHA_TEST\n if (s.albedo.ALPHA_TEST_CHANNEL < albedoScaleAndCutoff.w) discard;\n #endif\n s.normal = v_normal;\n #if USE_NORMAL_MAP\n vec3 nmmp = texture2D(normalMap, NORMAL_UV).xyz - vec3(0.5);\n s.normal =\n (nmmp.x * pbrParams.w) * normalize(v_tangent) +\n (nmmp.y * pbrParams.w) * normalize(v_bitangent) +\n nmmp.z * normalize(s.normal);\n #endif\n s.position = v_position;\n vec4 pbr = pbrParams;\n #if USE_PBR_MAP\n vec4 res = texture2D(pbrMap, PBR_UV);\n pbr.x *= res.OCCLUSION_CHANNEL;\n pbr.y *= res.ROUGHNESS_CHANNEL;\n pbr.z *= res.METALLIC_CHANNEL;\n #endif\n #if USE_METALLIC_ROUGHNESS_MAP\n vec4 metallicRoughness = texture2D(metallicRoughnessMap, METALLIC_ROUGHNESS_UV);\n pbr.z *= metallicRoughness.METALLIC_CHANNEL;\n pbr.y *= metallicRoughness.ROUGHNESS_CHANNEL;\n #endif\n #if USE_OCCLUSION_MAP\n pbr.x *= texture2D(occlusionMap, OCCLUSION_UV).OCCLUSION_CHANNEL;\n #endif\n s.occlusion = clamp(pbr.x, 0.0, 0.96);\n s.roughness = clamp(pbr.y, 0.04, 1.0);\n s.metallic = pbr.z;\n s.emissive = emissive.rgb * emissiveScaleParam.xyz;\n #if USE_EMISSIVE_MAP\n s.emissive *= SRGBToLinear(texture2D(emissiveMap, EMISSIVE_UV).rgb);\n #endif\n}\nvec4 frag () {\n StandardSurface s; surf(s);\n vec4 color = CCStandardShading(s);\n #if USE_LIGHTMAP && !USE_BATCHING && !USE_INSTANCING && CC_FOWARD_ADD == 0\n vec4 lighting = texture2D(cc_lightingMap, v_luv);\n float fAmb = 0.5 - s.normal.y * 0.5;\n vec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb) * cc_ambientSky.w;\n vec3 finalColor = (ambDiff.rgb * s.albedo.rgb);\n finalColor += lighting.rgb * s.albedo.rgb;\n finalColor = finalColor * s.occlusion;\n finalColor += s.emissive;\n color.rgb = lighting.a * finalColor + (1.0 - lighting.a) * color.rgb;\n #endif\n color = mix(cc_fogColor, color, factor_fog);\n return CCFragOutput(color);\n}\nvoid main() { gl_FragColor = frag(); }` }, "builtins": { "globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }], "samplers": [{ "name": "cc_environment", "defines": ["CC_USE_IBL"] }] }, - "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": [] }], "samplers": [{ "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"] }] } + "locals": { "blocks": [{ "name": "CCLocalBatched", "defines": ["!USE_INSTANCING", "USE_BATCHING"] }, { "name": "CCLocal", "defines": ["!USE_INSTANCING", "!USE_BATCHING"] }, { "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": "CCForwardLight", "defines": ["CC_FOWARD_ADD"] }], "samplers": [{ "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"] }] } }, "defines": [ + { "name": "USE_INSTANCING", "type": "boolean" }, + { "name": "USE_BATCHING", "type": "boolean" }, { "name": "CC_USE_MORPH", "type": "boolean" }, - { "name": "CC_MORPH_TARGET_COUNT", "type": "number", "range": [2, 8] }, + { "name": "CC_MORPH_TARGET_COUNT", "type": "number", "dummyDependency": true, "range": [2, 8] }, { "name": "CC_MORPH_PRECOMPUTED", "type": "boolean" }, { "name": "CC_MORPH_TARGET_HAS_POSITION", "type": "boolean" }, { "name": "CC_MORPH_TARGET_HAS_NORMAL", "type": "boolean" }, { "name": "CC_MORPH_TARGET_HAS_TANGENT", "type": "boolean" }, { "name": "CC_USE_SKINNING", "type": "boolean" }, { "name": "CC_USE_BAKED_ANIMATION", "type": "boolean" }, - { "name": "USE_INSTANCING", "type": "boolean" }, { "name": "CC_SUPPORT_FLOAT_TEXTURE", "type": "boolean" }, - { "name": "USE_BATCHING", "type": "boolean" }, + { "name": "CC_USE_FOG", "type": "number", "range": [0, 4] }, { "name": "USE_VERTEX_COLOR", "type": "boolean" }, { "name": "USE_NORMAL_MAP", "type": "boolean" }, + { "name": "USE_LIGHTMAP", "type": "boolean" }, { "name": "HAS_SECOND_UV", "type": "boolean" }, { "name": "CC_USE_IBL", "type": "number", "range": [0, 2] }, + { "name": "CC_FOWARD_ADD", "type": "number", "range": [0, 3] }, + { "name": "CC_SPOTLIGHT", "type": "boolean" }, { "name": "CC_USE_HDR", "type": "boolean" }, { "name": "USE_ALBEDO_MAP", "type": "boolean" }, - { "name": "ALBEDO_UV", "type": "string", "options": ["v_uv", "v_uv1"] }, - { "name": "NORMAL_UV", "type": "string", "options": ["v_uv", "v_uv1"] }, + { "name": "ALBEDO_UV", "type": "string", "dummyDependency": true, "options": ["v_uv", "v_uv1"] }, + { "name": "NORMAL_UV", "type": "string", "dummyDependency": true, "options": ["v_uv", "v_uv1"] }, { "name": "USE_PBR_MAP", "type": "boolean" }, - { "name": "PBR_UV", "type": "string", "options": ["v_uv", "v_uv1"] }, + { "name": "PBR_UV", "type": "string", "dummyDependency": true, "options": ["v_uv", "v_uv1"] }, { "name": "USE_METALLIC_ROUGHNESS_MAP", "type": "boolean" }, - { "name": "METALLIC_ROUGHNESS_UV", "type": "string", "options": ["v_uv", "v_uv1"] }, + { "name": "METALLIC_ROUGHNESS_UV", "type": "string", "dummyDependency": true, "options": ["v_uv", "v_uv1"] }, { "name": "USE_OCCLUSION_MAP", "type": "boolean" }, - { "name": "OCCLUSION_UV", "type": "string", "options": ["v_uv", "v_uv1"] }, + { "name": "OCCLUSION_UV", "type": "string", "dummyDependency": true, "options": ["v_uv", "v_uv1"] }, { "name": "USE_EMISSIVE_MAP", "type": "boolean" }, - { "name": "EMISSIVE_UV", "type": "string", "options": ["v_uv", "v_uv1"] }, - { "name": "OCCLUSION_CHANNEL", "type": "string", "options": ["r", "g", "b"] }, - { "name": "ROUGHNESS_CHANNEL", "type": "string", "options": ["g", "b", "r"] }, - { "name": "METALLIC_CHANNEL", "type": "string", "options": ["b", "r", "g"] }, + { "name": "EMISSIVE_UV", "type": "string", "dummyDependency": true, "options": ["v_uv", "v_uv1"] }, + { "name": "OCCLUSION_CHANNEL", "type": "string", "dummyDependency": true, "options": ["r", "g", "b"] }, + { "name": "ROUGHNESS_CHANNEL", "type": "string", "dummyDependency": true, "options": ["g", "b", "r"] }, + { "name": "METALLIC_CHANNEL", "type": "string", "dummyDependency": true, "options": ["b", "r", "g"] }, { "name": "USE_ALPHA_TEST", "type": "boolean" }, - { "name": "ALPHA_TEST_CHANNEL", "type": "string", "options": ["a", "r"] } + { "name": "ALPHA_TEST_CHANNEL", "type": "string", "dummyDependency": true, "options": ["a", "r"] } ], "blocks": [ {"name": "Constants", "defines": [], "binding": 0, "members": [ @@ -354,25 +358,25 @@ export default [ ]} ], "samplers": [ - { "name": "albedoMap", "type": 28, "count": 1, "defines": ["USE_ALBEDO_MAP"], "binding": 30 }, - { "name": "normalMap", "type": 28, "count": 1, "defines": ["USE_NORMAL_MAP"], "binding": 31 }, - { "name": "pbrMap", "type": 28, "count": 1, "defines": ["USE_PBR_MAP"], "binding": 32 }, - { "name": "metallicRoughnessMap", "type": 28, "count": 1, "defines": ["USE_METALLIC_ROUGHNESS_MAP"], "binding": 33 }, - { "name": "occlusionMap", "type": 28, "count": 1, "defines": ["USE_OCCLUSION_MAP"], "binding": 34 }, - { "name": "emissiveMap", "type": 28, "count": 1, "defines": ["USE_EMISSIVE_MAP"], "binding": 35 } + { "name": "albedoMap", "type": 28, "count": 1, "defines": ["USE_ALBEDO_MAP"], "binding": 31 }, + { "name": "normalMap", "type": 28, "count": 1, "defines": ["USE_NORMAL_MAP"], "binding": 32 }, + { "name": "pbrMap", "type": 28, "count": 1, "defines": ["USE_PBR_MAP"], "binding": 33 }, + { "name": "metallicRoughnessMap", "type": 28, "count": 1, "defines": ["USE_METALLIC_ROUGHNESS_MAP"], "binding": 34 }, + { "name": "occlusionMap", "type": 28, "count": 1, "defines": ["USE_OCCLUSION_MAP"], "binding": 35 }, + { "name": "emissiveMap", "type": 28, "count": 1, "defines": ["USE_EMISSIVE_MAP"], "binding": 36 } ], "attributes": [ + { "name": "a_matWorld0", "type": 16, "count": 1, "defines": ["USE_INSTANCING"], "format": 43, "isInstanced": true, "location": 4 }, + { "name": "a_matWorld1", "type": 16, "count": 1, "defines": ["USE_INSTANCING"], "format": 43, "isInstanced": true, "location": 5 }, + { "name": "a_matWorld2", "type": 16, "count": 1, "defines": ["USE_INSTANCING"], "format": 43, "isInstanced": true, "location": 6 }, + { "name": "a_dyn_batch_id", "type": 13, "count": 1, "defines": ["!USE_INSTANCING", "USE_BATCHING"], "format": 11, "location": 3 }, { "name": "a_position", "type": 15, "count": 1, "defines": [], "format": 32, "location": 0 }, { "name": "a_normal", "type": 15, "count": 1, "defines": [], "format": 32, "location": 1 }, { "name": "a_tangent", "type": 16, "count": 1, "defines": [], "format": 43, "location": 2 }, - { "name": "a_vertexId", "type": 13, "count": 1, "defines": ["CC_USE_MORPH"], "format": 11, "location": 3 }, - { "name": "a_weights", "type": 16, "count": 1, "defines": ["CC_USE_SKINNING"], "format": 43, "location": 4 }, - { "name": "a_joints", "type": 16, "count": 1, "defines": ["CC_USE_SKINNING"], "format": 43, "location": 5 }, - { "name": "a_jointAnimInfo", "type": 16, "count": 1, "precision": "highp ", "defines": ["CC_USE_SKINNING", "CC_USE_BAKED_ANIMATION", "USE_INSTANCING"], "format": 43, "isInstanced": true, "location": 6 }, - { "name": "a_matWorld0", "type": 16, "count": 1, "defines": ["USE_INSTANCING"], "format": 43, "isInstanced": true, "location": 7 }, - { "name": "a_matWorld1", "type": 16, "count": 1, "defines": ["USE_INSTANCING"], "format": 43, "isInstanced": true, "location": 8 }, - { "name": "a_matWorld2", "type": 16, "count": 1, "defines": ["USE_INSTANCING"], "format": 43, "isInstanced": true, "location": 9 }, - { "name": "a_dyn_batch_id", "type": 13, "count": 1, "defines": ["!USE_INSTANCING", "USE_BATCHING"], "format": 11, "location": 10 }, + { "name": "a_vertexId", "type": 13, "count": 1, "defines": ["CC_USE_MORPH"], "format": 11, "location": 7 }, + { "name": "a_weights", "type": 16, "count": 1, "defines": ["CC_USE_SKINNING"], "format": 43, "location": 8 }, + { "name": "a_joints", "type": 16, "count": 1, "defines": ["CC_USE_SKINNING"], "format": 43, "location": 9 }, + { "name": "a_jointAnimInfo", "type": 16, "count": 1, "defines": ["CC_USE_SKINNING", "CC_USE_BAKED_ANIMATION", "USE_INSTANCING"], "format": 43, "isInstanced": true, "location": 10 }, { "name": "a_color", "type": 15, "count": 1, "defines": ["USE_VERTEX_COLOR"], "format": 32, "location": 11 }, { "name": "a_texCoord", "type": 14, "count": 1, "defines": [], "format": 21, "location": 12 }, { "name": "a_texCoord1", "type": 14, "count": 1, "defines": [], "format": 21, "location": 13 } @@ -389,14 +393,14 @@ export default [ "shaders": [ { "name": "builtin-terrain|terrain-vs:vert|terrain-fs:frag", - "hash": 29493851, + "hash": 1557641563, "glsl3": { - "vert": `\n precision mediump float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n};\nuniform CCLocal {\n highp mat4 cc_matWorld;\n highp mat4 cc_matWorldIT;\n};\n in vec3 a_position;\n in vec3 a_normal;\n in vec2 a_texCoord;\n out vec2 uvw;\n out vec2 uv0;\n out vec2 uv1;\n out vec2 uv2;\n out vec2 uv3;\n out vec2 luv;\n out vec3 diffuse;\n uniform TexCoords {\n vec4 UVScale;\n vec4 lightMapUVParam;\n };\n vec4 vert () {\n vec3 worldPos;\n worldPos.x = cc_matWorld[3][0] + a_position.x;\n worldPos.y = cc_matWorld[3][1] + a_position.y;\n worldPos.z = cc_matWorld[3][2] + a_position.z;\n vec4 pos = vec4(worldPos, 1);\n pos = cc_matViewProj * pos;\n uvw = a_texCoord;\n uv0 = a_position.xz * UVScale.x;\n uv1 = a_position.xz * UVScale.y;\n uv2 = a_position.xz * UVScale.z;\n uv3 = a_position.xz * UVScale.w;\n float fAmb = dot(a_normal, vec3(0.0, -1.0, 0.0)) * 0.5 + 0.5;\n vec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb) * cc_ambientSky.w;\n#if LIGHT_MAP == 0\n vec3 L = normalize(-cc_mainLitDir.xyz);\n vec3 N = a_normal;\n diffuse = ambDiff + vec3(dot(N, L)) * cc_mainLitColor.rgb;\n#else\n diffuse = ambDiff;\n luv = lightMapUVParam.xy + a_texCoord * lightMapUVParam.zw;\n#endif\n return pos;\n }\nvoid main() { gl_Position = vert(); }`, - "frag": `\nprecision mediump float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n};\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\n}\nvec4 CCFragOutput (vec4 color) {\n #if CC_USE_HDR\n color.rgb = mix(color.rgb, SRGBToLinear(color.rgb) * cc_exposure.w, vec3(cc_exposure.z));\n #endif\n return color;\n}\n in vec2 uvw;\n in vec2 uv0;\n in vec2 uv1;\n in vec2 uv2;\n in vec2 uv3;\n in vec3 diffuse;\n in vec2 luv;\n uniform sampler2D weightMap;\n uniform sampler2D detailMap0;\n uniform sampler2D detailMap1;\n uniform sampler2D detailMap2;\n uniform sampler2D detailMap3;\n uniform sampler2D lightMap;\nvec4 frag () {\n vec4 color = vec4(0, 0, 0, 0);\n #if LAYERS == 1\n color = texture(detailMap0, uv0);\n #elif LAYERS == 2\n vec4 w = texture(weightMap, uvw);\n color += texture(detailMap0, uv0) * w.r;\n color += texture(detailMap1, uv1) * w.g;\n #elif LAYERS == 3\n vec4 w = texture(weightMap, uvw);\n color += texture(detailMap0, uv0) * w.r;\n color += texture(detailMap1, uv1) * w.g;\n color += texture(detailMap2, uv2) * w.b;\n #elif LAYERS == 4\n vec4 w = texture(weightMap, uvw);\n color += texture(detailMap0, uv0) * w.r;\n color += texture(detailMap1, uv1) * w.g;\n color += texture(detailMap2, uv2) * w.b;\n color += texture(detailMap3, uv3) * w.a;\n #else\n color = texture(detailMap0, uv0);\n #endif\n vec3 lighting = diffuse;\n #if LIGHT_MAP == 1\n lighting += texture(lightMap, luv).rgb;\n #endif\n color.rgb *= lighting;\n return CCFragOutput(color);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }` + "vert": `\n precision mediump float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\nuniform CCLocal {\n highp mat4 cc_matWorld;\n highp mat4 cc_matWorldIT;\n highp vec4 cc_lightingMapUVParam;\n};\nfloat LinearFog(vec4 pos) {\n vec4 wPos = pos;\n float cam_dis = distance(cc_cameraPos, wPos);\n float fogStart = cc_fogBase.x;\n float fogEnd = cc_fogBase.y;\n return clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float fogDensity = cc_fogBase.z;\n float cam_dis = distance(cc_cameraPos, wPos) / fogAtten * 4.;\n float f = exp(-cam_dis * fogDensity);\n return f;\n}\nfloat ExpSquaredFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float fogDensity = cc_fogBase.z;\n float cam_dis = distance(cc_cameraPos, wPos) / fogAtten * 4.;\n float f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\n return f;\n}\nfloat LayeredFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float _FogTop = cc_fogAdd.x;\n float _FogRange = cc_fogAdd.y;\n vec3 camWorldProj = cc_cameraPos.xyz;\n camWorldProj.y = 0.;\n vec3 worldPosProj = wPos.xyz;\n worldPosProj.y = 0.;\n float fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\n float fDeltaY, fDensityIntegral;\n if (cc_cameraPos.y > _FogTop) {\n if (wPos.y < _FogTop) {\n fDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\n fDensityIntegral = fDeltaY * fDeltaY * 0.5;\n } else {\n fDeltaY = 0.;\n fDensityIntegral = 0.;\n }\n } else {\n if (wPos.y < _FogTop) {\n float fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\n float fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\n fDeltaY = abs(fDeltaA - fDeltaB);\n fDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n } else {\n fDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\n fDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n }\n }\n float fDensity;\n if (fDeltaY != 0.) {\n fDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n } else {\n fDensity = 0.;\n }\n float f = exp(-fDensity);\n return f;\n}\nfloat CC_TRANSFER_FOG(vec4 pos) {\n #if CC_USE_FOG == 1\n return LinearFog(pos);\n #elif CC_USE_FOG == 2\n return ExpFog(pos);\n #elif CC_USE_FOG == 3\n return ExpSquaredFog(pos);\n #elif CC_USE_FOG == 4\n return LayeredFog(pos);\n #endif\n return 1.;\n}\n in vec3 a_position;\n in vec3 a_normal;\n in vec2 a_texCoord;\n out vec2 uvw;\n out vec2 uv0;\n out vec2 uv1;\n out vec2 uv2;\n out vec2 uv3;\n out vec2 luv;\n out vec3 diffuse;\n out float factor_fog;\n uniform TexCoords {\n vec4 UVScale;\n vec4 lightMapUVParam;\n };\n vec4 vert () {\n vec3 worldPos;\n worldPos.x = cc_matWorld[3][0] + a_position.x;\n worldPos.y = cc_matWorld[3][1] + a_position.y;\n worldPos.z = cc_matWorld[3][2] + a_position.z;\n vec4 pos = vec4(worldPos, 1);\n pos = cc_matViewProj * pos;\n uvw = a_texCoord;\n uv0 = a_position.xz * UVScale.x;\n uv1 = a_position.xz * UVScale.y;\n uv2 = a_position.xz * UVScale.z;\n uv3 = a_position.xz * UVScale.w;\n float fAmb = dot(a_normal, vec3(0.0, -1.0, 0.0)) * 0.5 + 0.5;\n vec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb) * cc_ambientSky.w;\n#if LIGHT_MAP == 0\n vec3 L = normalize(-cc_mainLitDir.xyz);\n vec3 N = a_normal;\n diffuse = ambDiff + vec3(dot(N, L)) * cc_mainLitColor.rgb;\n#else\n diffuse = ambDiff;\n luv = lightMapUVParam.xy + a_texCoord * lightMapUVParam.zw;\n#endif\n factor_fog = CC_TRANSFER_FOG(vec4(worldPos, 1));\n return pos;\n }\nvoid main() { gl_Position = vert(); }`, + "frag": `\nprecision mediump float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\n}\nvec4 CCFragOutput (vec4 color) {\n #if CC_USE_HDR\n color.rgb = mix(color.rgb, SRGBToLinear(color.rgb) * cc_exposure.w, vec3(cc_exposure.z));\n #endif\n return color;\n}\n in vec2 uvw;\n in vec2 uv0;\n in vec2 uv1;\n in vec2 uv2;\n in vec2 uv3;\n in vec3 diffuse;\n in vec2 luv;\n uniform sampler2D weightMap;\n uniform sampler2D detailMap0;\n uniform sampler2D detailMap1;\n uniform sampler2D detailMap2;\n uniform sampler2D detailMap3;\n uniform sampler2D lightMap;\n in float factor_fog;\nvec4 frag () {\n vec4 color = vec4(0, 0, 0, 0);\n #if LAYERS == 1\n color = texture(detailMap0, uv0);\n #elif LAYERS == 2\n vec4 w = texture(weightMap, uvw);\n color += texture(detailMap0, uv0) * w.r;\n color += texture(detailMap1, uv1) * w.g;\n #elif LAYERS == 3\n vec4 w = texture(weightMap, uvw);\n color += texture(detailMap0, uv0) * w.r;\n color += texture(detailMap1, uv1) * w.g;\n color += texture(detailMap2, uv2) * w.b;\n #elif LAYERS == 4\n vec4 w = texture(weightMap, uvw);\n color += texture(detailMap0, uv0) * w.r;\n color += texture(detailMap1, uv1) * w.g;\n color += texture(detailMap2, uv2) * w.b;\n color += texture(detailMap3, uv3) * w.a;\n #else\n color = texture(detailMap0, uv0);\n #endif\n vec3 lighting = diffuse;\n #if LIGHT_MAP == 1\n lighting += texture(lightMap, luv).rgb;\n #endif\n color.rgb *= lighting;\n color = mix(cc_fogColor, color, factor_fog);\n return CCFragOutput(color);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }` }, "glsl1": { - "vert": `\n precision mediump float;\nuniform highp mat4 cc_matViewProj;\nuniform mediump vec4 cc_mainLitDir;\nuniform mediump vec4 cc_mainLitColor;\nuniform mediump vec4 cc_ambientSky;\nuniform mediump vec4 cc_ambientGround;\nuniform highp mat4 cc_matWorld;\n attribute vec3 a_position;\n attribute vec3 a_normal;\n attribute vec2 a_texCoord;\n varying vec2 uvw;\n varying vec2 uv0;\n varying vec2 uv1;\n varying vec2 uv2;\n varying vec2 uv3;\n varying vec2 luv;\n varying vec3 diffuse;\n uniform vec4 UVScale;\nuniform vec4 lightMapUVParam;\n vec4 vert () {\n vec3 worldPos;\n worldPos.x = cc_matWorld[3][0] + a_position.x;\n worldPos.y = cc_matWorld[3][1] + a_position.y;\n worldPos.z = cc_matWorld[3][2] + a_position.z;\n vec4 pos = vec4(worldPos, 1);\n pos = cc_matViewProj * pos;\n uvw = a_texCoord;\n uv0 = a_position.xz * UVScale.x;\n uv1 = a_position.xz * UVScale.y;\n uv2 = a_position.xz * UVScale.z;\n uv3 = a_position.xz * UVScale.w;\n float fAmb = dot(a_normal, vec3(0.0, -1.0, 0.0)) * 0.5 + 0.5;\n vec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb) * cc_ambientSky.w;\n#if LIGHT_MAP == 0\n vec3 L = normalize(-cc_mainLitDir.xyz);\n vec3 N = a_normal;\n diffuse = ambDiff + vec3(dot(N, L)) * cc_mainLitColor.rgb;\n#else\n diffuse = ambDiff;\n luv = lightMapUVParam.xy + a_texCoord * lightMapUVParam.zw;\n#endif\n return pos;\n }\nvoid main() { gl_Position = vert(); }`, - "frag": `\nprecision mediump float;\nuniform mediump vec4 cc_exposure;\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\n}\nvec4 CCFragOutput (vec4 color) {\n #if CC_USE_HDR\n color.rgb = mix(color.rgb, SRGBToLinear(color.rgb) * cc_exposure.w, vec3(cc_exposure.z));\n #endif\n return color;\n}\n varying vec2 uvw;\n varying vec2 uv0;\n varying vec2 uv1;\n varying vec2 uv2;\n varying vec2 uv3;\n varying vec3 diffuse;\n varying vec2 luv;\n uniform sampler2D weightMap;\n uniform sampler2D detailMap0;\n uniform sampler2D detailMap1;\n uniform sampler2D detailMap2;\n uniform sampler2D detailMap3;\n uniform sampler2D lightMap;\nvec4 frag () {\n vec4 color = vec4(0, 0, 0, 0);\n #if LAYERS == 1\n color = texture2D(detailMap0, uv0);\n #elif LAYERS == 2\n vec4 w = texture2D(weightMap, uvw);\n color += texture2D(detailMap0, uv0) * w.r;\n color += texture2D(detailMap1, uv1) * w.g;\n #elif LAYERS == 3\n vec4 w = texture2D(weightMap, uvw);\n color += texture2D(detailMap0, uv0) * w.r;\n color += texture2D(detailMap1, uv1) * w.g;\n color += texture2D(detailMap2, uv2) * w.b;\n #elif LAYERS == 4\n vec4 w = texture2D(weightMap, uvw);\n color += texture2D(detailMap0, uv0) * w.r;\n color += texture2D(detailMap1, uv1) * w.g;\n color += texture2D(detailMap2, uv2) * w.b;\n color += texture2D(detailMap3, uv3) * w.a;\n #else\n color = texture2D(detailMap0, uv0);\n #endif\n vec3 lighting = diffuse;\n #if LIGHT_MAP == 1\n lighting += texture2D(lightMap, luv).rgb;\n #endif\n color.rgb *= lighting;\n return CCFragOutput(color);\n}\nvoid main() { gl_FragColor = frag(); }` + "vert": `\n precision mediump float;\nuniform highp mat4 cc_matViewProj;\nuniform highp vec4 cc_cameraPos;\nuniform mediump vec4 cc_mainLitDir;\nuniform mediump vec4 cc_mainLitColor;\nuniform mediump vec4 cc_ambientSky;\nuniform mediump vec4 cc_ambientGround;\nuniform mediump vec4 cc_fogBase;\nuniform mediump vec4 cc_fogAdd;\nuniform highp mat4 cc_matWorld;\nfloat LinearFog(vec4 pos) {\n vec4 wPos = pos;\n float cam_dis = distance(cc_cameraPos, wPos);\n float fogStart = cc_fogBase.x;\n float fogEnd = cc_fogBase.y;\n return clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float fogDensity = cc_fogBase.z;\n float cam_dis = distance(cc_cameraPos, wPos) / fogAtten * 4.;\n float f = exp(-cam_dis * fogDensity);\n return f;\n}\nfloat ExpSquaredFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float fogDensity = cc_fogBase.z;\n float cam_dis = distance(cc_cameraPos, wPos) / fogAtten * 4.;\n float f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\n return f;\n}\nfloat LayeredFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float _FogTop = cc_fogAdd.x;\n float _FogRange = cc_fogAdd.y;\n vec3 camWorldProj = cc_cameraPos.xyz;\n camWorldProj.y = 0.;\n vec3 worldPosProj = wPos.xyz;\n worldPosProj.y = 0.;\n float fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\n float fDeltaY, fDensityIntegral;\n if (cc_cameraPos.y > _FogTop) {\n if (wPos.y < _FogTop) {\n fDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\n fDensityIntegral = fDeltaY * fDeltaY * 0.5;\n } else {\n fDeltaY = 0.;\n fDensityIntegral = 0.;\n }\n } else {\n if (wPos.y < _FogTop) {\n float fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\n float fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\n fDeltaY = abs(fDeltaA - fDeltaB);\n fDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n } else {\n fDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\n fDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n }\n }\n float fDensity;\n if (fDeltaY != 0.) {\n fDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n } else {\n fDensity = 0.;\n }\n float f = exp(-fDensity);\n return f;\n}\nfloat CC_TRANSFER_FOG(vec4 pos) {\n #if CC_USE_FOG == 1\n return LinearFog(pos);\n #elif CC_USE_FOG == 2\n return ExpFog(pos);\n #elif CC_USE_FOG == 3\n return ExpSquaredFog(pos);\n #elif CC_USE_FOG == 4\n return LayeredFog(pos);\n #endif\n return 1.;\n}\n attribute vec3 a_position;\n attribute vec3 a_normal;\n attribute vec2 a_texCoord;\n varying vec2 uvw;\n varying vec2 uv0;\n varying vec2 uv1;\n varying vec2 uv2;\n varying vec2 uv3;\n varying vec2 luv;\n varying vec3 diffuse;\n varying float factor_fog;\n uniform vec4 UVScale;\nuniform vec4 lightMapUVParam;\n vec4 vert () {\n vec3 worldPos;\n worldPos.x = cc_matWorld[3][0] + a_position.x;\n worldPos.y = cc_matWorld[3][1] + a_position.y;\n worldPos.z = cc_matWorld[3][2] + a_position.z;\n vec4 pos = vec4(worldPos, 1);\n pos = cc_matViewProj * pos;\n uvw = a_texCoord;\n uv0 = a_position.xz * UVScale.x;\n uv1 = a_position.xz * UVScale.y;\n uv2 = a_position.xz * UVScale.z;\n uv3 = a_position.xz * UVScale.w;\n float fAmb = dot(a_normal, vec3(0.0, -1.0, 0.0)) * 0.5 + 0.5;\n vec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb) * cc_ambientSky.w;\n#if LIGHT_MAP == 0\n vec3 L = normalize(-cc_mainLitDir.xyz);\n vec3 N = a_normal;\n diffuse = ambDiff + vec3(dot(N, L)) * cc_mainLitColor.rgb;\n#else\n diffuse = ambDiff;\n luv = lightMapUVParam.xy + a_texCoord * lightMapUVParam.zw;\n#endif\n factor_fog = CC_TRANSFER_FOG(vec4(worldPos, 1));\n return pos;\n }\nvoid main() { gl_Position = vert(); }`, + "frag": `\nprecision mediump float;\nuniform mediump vec4 cc_exposure;\nuniform mediump vec4 cc_fogColor;\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\n}\nvec4 CCFragOutput (vec4 color) {\n #if CC_USE_HDR\n color.rgb = mix(color.rgb, SRGBToLinear(color.rgb) * cc_exposure.w, vec3(cc_exposure.z));\n #endif\n return color;\n}\n varying vec2 uvw;\n varying vec2 uv0;\n varying vec2 uv1;\n varying vec2 uv2;\n varying vec2 uv3;\n varying vec3 diffuse;\n varying vec2 luv;\n uniform sampler2D weightMap;\n uniform sampler2D detailMap0;\n uniform sampler2D detailMap1;\n uniform sampler2D detailMap2;\n uniform sampler2D detailMap3;\n uniform sampler2D lightMap;\n varying float factor_fog;\nvec4 frag () {\n vec4 color = vec4(0, 0, 0, 0);\n #if LAYERS == 1\n color = texture2D(detailMap0, uv0);\n #elif LAYERS == 2\n vec4 w = texture2D(weightMap, uvw);\n color += texture2D(detailMap0, uv0) * w.r;\n color += texture2D(detailMap1, uv1) * w.g;\n #elif LAYERS == 3\n vec4 w = texture2D(weightMap, uvw);\n color += texture2D(detailMap0, uv0) * w.r;\n color += texture2D(detailMap1, uv1) * w.g;\n color += texture2D(detailMap2, uv2) * w.b;\n #elif LAYERS == 4\n vec4 w = texture2D(weightMap, uvw);\n color += texture2D(detailMap0, uv0) * w.r;\n color += texture2D(detailMap1, uv1) * w.g;\n color += texture2D(detailMap2, uv2) * w.b;\n color += texture2D(detailMap3, uv3) * w.a;\n #else\n color = texture2D(detailMap0, uv0);\n #endif\n vec3 lighting = diffuse;\n #if LIGHT_MAP == 1\n lighting += texture2D(lightMap, luv).rgb;\n #endif\n color.rgb *= lighting;\n color = mix(cc_fogColor, color, factor_fog);\n return CCFragOutput(color);\n}\nvoid main() { gl_FragColor = frag(); }` }, "builtins": { "globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }], "samplers": [] }, @@ -414,12 +418,12 @@ export default [ ]} ], "samplers": [ - { "name": "weightMap", "type": 28, "count": 1, "defines": [], "binding": 30 }, - { "name": "detailMap0", "type": 28, "count": 1, "defines": [], "binding": 31 }, - { "name": "detailMap1", "type": 28, "count": 1, "defines": [], "binding": 32 }, - { "name": "detailMap2", "type": 28, "count": 1, "defines": [], "binding": 33 }, - { "name": "detailMap3", "type": 28, "count": 1, "defines": [], "binding": 34 }, - { "name": "lightMap", "type": 28, "count": 1, "defines": [], "binding": 35 } + { "name": "weightMap", "type": 28, "count": 1, "defines": [], "binding": 31 }, + { "name": "detailMap0", "type": 28, "count": 1, "defines": [], "binding": 32 }, + { "name": "detailMap1", "type": 28, "count": 1, "defines": [], "binding": 33 }, + { "name": "detailMap2", "type": 28, "count": 1, "defines": [], "binding": 34 }, + { "name": "detailMap3", "type": 28, "count": 1, "defines": [], "binding": 35 }, + { "name": "lightMap", "type": 28, "count": 1, "defines": [], "binding": 36 } ], "attributes": [ { "name": "a_position", "type": 15, "count": 1, "defines": [], "format": 32, "location": 0 }, @@ -438,37 +442,38 @@ export default [ "shaders": [ { "name": "builtin-unlit|unlit-vs:vert|unlit-fs:frag", - "hash": 3753129449, + "hash": 211923169, "glsl3": { - "vert": `\nprecision highp float;\nstruct StandardVertInput {\n highp vec4 position;\n vec3 normal;\n vec4 tangent;\n};\nin vec3 a_position;\n#if CC_USE_MORPH\n in float a_vertexId;\n int getVertexId() {\n return int(a_vertexId);\n }\nuniform CCMorph {\n vec4 cc_displacementWeights[15];\n vec4 cc_displacementTextureInfo;\n};\n vec4 fetchFlatPixel(sampler2D tex, int pixelIndex) {\n float pixelIndexF = float(pixelIndex);\n vec2 textureResolution = vec2(float(cc_displacementTextureInfo.x), float(cc_displacementTextureInfo.y));\n float pixelX = mod(pixelIndexF, textureResolution.x);\n float pixelY = floor(pixelIndexF / textureResolution.x);\n vec2 uv = (vec2(pixelX, pixelY) + .5) / textureResolution;\n return texture(tex, uv);\n }\nfloat getDisplacementWeight(int index) {\n float m = mod(float(index), 4.0);\n if (m < 1.0) {\n return cc_displacementWeights[index / 4].x;\n } else if (m < 2.0) {\n return cc_displacementWeights[index / 4].y;\n } else if (m < 3.0) {\n return cc_displacementWeights[index / 4].z;\n } else {\n return cc_displacementWeights[index / 4].w;\n }\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\n return fetchFlatPixel(tex, vertexIndex).rgb;\n#else\n vec3 result = vec3(0, 0, 0);\n for (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\n int dataPixelStart = int(fetchFlatPixel(tex, iTarget).r);\n result += (fetchFlatPixel(tex, dataPixelStart + vertexIndex).rgb * getDisplacementWeight(iTarget));\n }\n return result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\n uniform sampler2D cc_PositionDisplacements;\n vec3 getPositionDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n uniform sampler2D cc_NormalDisplacements;\n vec3 getNormalDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n uniform sampler2D cc_TangentDisplacements;\n vec3 getTangentDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n }\n#endif\nvoid applyMorph (inout StandardVertInput attr) {\n int vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\n attr.position.xyz = attr.position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n attr.normal.xyz = attr.normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n attr.tangent.xyz = attr.tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\n position.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\nin vec4 a_weights;\nin vec4 a_joints;\n#if CC_USE_BAKED_ANIMATION\n #if USE_INSTANCING\n in highp vec4 a_jointAnimInfo;\n #endif\n uniform CCSkinningTexture {\n highp vec4 cc_jointTextureInfo;\n };\n uniform CCSkinningAnimation {\n highp vec4 cc_jointAnimInfo;\n };\n uniform sampler2D cc_jointTexture;\n #if !CC_SUPPORT_FLOAT_TEXTURE\n highp float decode32 (highp vec4 rgba) {\n rgba = rgba * 255.0;\n highp float Sign = 1.0 - step(128.0, rgba[3]) * 2.0;\n highp float Exponent = 2.0 * mod(rgba[3], 128.0) + step(128.0, rgba[2]) - 127.0;\n highp float Mantissa = mod(rgba[2], 128.0) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\n }\n #endif\n#else\n uniform CCSkinning {\n highp vec4 cc_joints[30 * 3];\n };\n#endif\n#if CC_USE_BAKED_ANIMATION\n #if CC_SUPPORT_FLOAT_TEXTURE\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 3.0 * (a_jointAnimInfo.x * a_jointAnimInfo.y + i) + a_jointAnimInfo.z;\n #else\n highp float j = 3.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = texture(cc_jointTexture, vec2((x + 0.5) * invSize, y));\n vec4 v2 = texture(cc_jointTexture, vec2((x + 1.5) * invSize, y));\n vec4 v3 = texture(cc_jointTexture, vec2((x + 2.5) * invSize, y));\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #else\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 12.0 * (a_jointAnimInfo.x * a_jointAnimInfo.y + i) + a_jointAnimInfo.z;\n #else\n highp float j = 12.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = vec4(\n decode32(texture(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n );\n vec4 v2 = vec4(\n decode32(texture(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n );\n vec4 v3 = vec4(\n decode32(texture(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n );\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #endif\n#else\n mat4 getJointMatrix (float i) {\n int idx = int(i);\n vec4 v1 = cc_joints[idx * 3];\n vec4 v2 = cc_joints[idx * 3 + 1];\n vec4 v3 = cc_joints[idx * 3 + 2];\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n#endif\nmat4 skinMatrix () {\n return getJointMatrix(a_joints.x) * a_weights.x\n + getJointMatrix(a_joints.y) * a_weights.y;\n + getJointMatrix(a_joints.z) * a_weights.z;\n + getJointMatrix(a_joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\n mat4 m = skinMatrix();\n position = m * position;\n}\nvoid CCSkin (inout StandardVertInput attr) {\n mat4 m = skinMatrix();\n attr.position = m * attr.position;\n attr.normal = (m * vec4(attr.normal, 0.0)).xyz;\n attr.tangent.xyz = (m * vec4(attr.tangent.xyz, 0.0)).xyz;\n}\n#endif\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n};\n#if USE_INSTANCING\n in vec4 a_matWorld0;\n in vec4 a_matWorld1;\n in vec4 a_matWorld2;\n#elif USE_BATCHING\n in float a_dyn_batch_id;\n uniform CCLocalBatched {\n highp mat4 cc_matWorlds[10];\n };\n#else\nuniform CCLocal {\n highp mat4 cc_matWorld;\n highp mat4 cc_matWorldIT;\n};\n#endif\n#if USE_VERTEX_COLOR\n in vec4 a_color;\n out vec4 v_color;\n#endif\n#if USE_TEXTURE\n in vec2 a_texCoord;\n out vec2 v_uv;\n uniform TexCoords {\n vec4 tilingOffset;\n };\n#endif\nvec4 vert () {\n vec4 position;\n position = vec4(a_position, 1.0);\n #if CC_USE_MORPH\n applyMorph(position);\n #endif\n #if CC_USE_SKINNING\n CCSkin(position);\n #endif\n mat4 matWorld;\n #if USE_INSTANCING\n matWorld = mat4(\n vec4(a_matWorld0.xyz, 0.0),\n vec4(a_matWorld1.xyz, 0.0),\n vec4(a_matWorld2.xyz, 0.0),\n vec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)\n );\n #elif USE_BATCHING\n matWorld = cc_matWorlds[int(a_dyn_batch_id)];\n #else\n matWorld = cc_matWorld;\n #endif\n #if USE_TEXTURE\n v_uv = a_texCoord;\n #if FLIP_UV\n v_uv.y = 1.0 - v_uv.y;\n #endif\n v_uv = v_uv * tilingOffset.xy + tilingOffset.zw;\n #endif\n #if USE_VERTEX_COLOR\n v_color = a_color;\n #endif\n return cc_matProj * (cc_matView * matWorld) * position;\n}\nvoid main() { gl_Position = vert(); }`, - "frag": `\nprecision mediump float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n};\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\n}\nvec4 CCFragOutput (vec4 color) {\n #if CC_USE_HDR\n color.rgb = mix(color.rgb, SRGBToLinear(color.rgb) * cc_exposure.w, vec3(cc_exposure.z));\n #endif\n return color;\n}\n#if USE_ALPHA_TEST\n#endif\n#if USE_TEXTURE\n in vec2 v_uv;\n uniform sampler2D mainTexture;\n#endif\nuniform Constant {\n vec4 mainColor;\n vec4 colorScaleAndCutoff;\n};\n#if USE_VERTEX_COLOR\n in vec4 v_color;\n#endif\nvec4 frag () {\n vec4 o = mainColor;\n o.rgb *= colorScaleAndCutoff.xyz;\n #if USE_VERTEX_COLOR\n o *= v_color;\n #endif\n #if USE_TEXTURE\n o *= texture(mainTexture, v_uv);\n #endif\n #if USE_ALPHA_TEST\n if (o.ALPHA_TEST_CHANNEL < colorScaleAndCutoff.w) discard;\n #endif\n return CCFragOutput(o);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }` + "vert": `\nprecision highp float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\n#if USE_INSTANCING\n in vec4 a_matWorld0;\n in vec4 a_matWorld1;\n in vec4 a_matWorld2;\n#elif USE_BATCHING\n in float a_dyn_batch_id;\n uniform CCLocalBatched {\n highp mat4 cc_matWorlds[10];\n };\n#else\nuniform CCLocal {\n highp mat4 cc_matWorld;\n highp mat4 cc_matWorldIT;\n highp vec4 cc_lightingMapUVParam;\n};\n#endif\nstruct StandardVertInput {\n highp vec4 position;\n vec3 normal;\n vec4 tangent;\n};\nin vec3 a_position;\n#if CC_USE_MORPH\n in float a_vertexId;\n int getVertexId() {\n return int(a_vertexId);\n }\nuniform CCMorph {\n vec4 cc_displacementWeights[15];\n vec4 cc_displacementTextureInfo;\n};\n vec4 fetchFlatPixel(sampler2D tex, int pixelIndex) {\n float pixelIndexF = float(pixelIndex);\n vec2 textureResolution = vec2(float(cc_displacementTextureInfo.x), float(cc_displacementTextureInfo.y));\n float pixelX = mod(pixelIndexF, textureResolution.x);\n float pixelY = floor(pixelIndexF / textureResolution.x);\n vec2 uv = (vec2(pixelX, pixelY) + .5) / textureResolution;\n return texture(tex, uv);\n }\nfloat getDisplacementWeight(int index) {\n float m = mod(float(index), 4.0);\n if (m < 1.0) {\n return cc_displacementWeights[index / 4].x;\n } else if (m < 2.0) {\n return cc_displacementWeights[index / 4].y;\n } else if (m < 3.0) {\n return cc_displacementWeights[index / 4].z;\n } else {\n return cc_displacementWeights[index / 4].w;\n }\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\n return fetchFlatPixel(tex, vertexIndex).rgb;\n#else\n vec3 result = vec3(0, 0, 0);\n for (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\n int dataPixelStart = int(fetchFlatPixel(tex, iTarget).r);\n result += (fetchFlatPixel(tex, dataPixelStart + vertexIndex).rgb * getDisplacementWeight(iTarget));\n }\n return result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\n uniform sampler2D cc_PositionDisplacements;\n vec3 getPositionDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n uniform sampler2D cc_NormalDisplacements;\n vec3 getNormalDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n uniform sampler2D cc_TangentDisplacements;\n vec3 getTangentDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n }\n#endif\nvoid applyMorph (inout StandardVertInput attr) {\n int vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\n attr.position.xyz = attr.position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n attr.normal.xyz = attr.normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n attr.tangent.xyz = attr.tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\n position.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\nin vec4 a_weights;\nin vec4 a_joints;\n#if CC_USE_BAKED_ANIMATION\n #if USE_INSTANCING\n in vec4 a_jointAnimInfo;\n #endif\n uniform CCSkinningTexture {\n highp vec4 cc_jointTextureInfo;\n };\n uniform CCSkinningAnimation {\n highp vec4 cc_jointAnimInfo;\n };\n uniform sampler2D cc_jointTexture;\n #if !CC_SUPPORT_FLOAT_TEXTURE\n highp float decode32 (highp vec4 rgba) {\n rgba = rgba * 255.0;\n highp float Sign = 1.0 - step(128.0, rgba[3]) * 2.0;\n highp float Exponent = 2.0 * mod(rgba[3], 128.0) + step(128.0, rgba[2]) - 127.0;\n highp float Mantissa = mod(rgba[2], 128.0) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\n }\n #endif\n#else\n uniform CCSkinning {\n highp vec4 cc_joints[30 * 3];\n };\n#endif\n#if CC_USE_BAKED_ANIMATION\n #if CC_SUPPORT_FLOAT_TEXTURE\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 3.0 * i + a_jointAnimInfo.x;\n #else\n highp float j = 3.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = texture(cc_jointTexture, vec2((x + 0.5) * invSize, y));\n vec4 v2 = texture(cc_jointTexture, vec2((x + 1.5) * invSize, y));\n vec4 v3 = texture(cc_jointTexture, vec2((x + 2.5) * invSize, y));\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #else\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 12.0 * i + a_jointAnimInfo.x;\n #else\n highp float j = 12.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = vec4(\n decode32(texture(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n );\n vec4 v2 = vec4(\n decode32(texture(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n );\n vec4 v3 = vec4(\n decode32(texture(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n );\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #endif\n#else\n mat4 getJointMatrix (float i) {\n int idx = int(i);\n vec4 v1 = cc_joints[idx * 3];\n vec4 v2 = cc_joints[idx * 3 + 1];\n vec4 v3 = cc_joints[idx * 3 + 2];\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n#endif\nmat4 skinMatrix () {\n return getJointMatrix(a_joints.x) * a_weights.x\n + getJointMatrix(a_joints.y) * a_weights.y;\n + getJointMatrix(a_joints.z) * a_weights.z;\n + getJointMatrix(a_joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\n mat4 m = skinMatrix();\n position = m * position;\n}\nvoid CCSkin (inout StandardVertInput attr) {\n mat4 m = skinMatrix();\n attr.position = m * attr.position;\n attr.normal = (m * vec4(attr.normal, 0.0)).xyz;\n attr.tangent.xyz = (m * vec4(attr.tangent.xyz, 0.0)).xyz;\n}\n#endif\nfloat LinearFog(vec4 pos) {\n vec4 wPos = pos;\n float cam_dis = distance(cc_cameraPos, wPos);\n float fogStart = cc_fogBase.x;\n float fogEnd = cc_fogBase.y;\n return clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float fogDensity = cc_fogBase.z;\n float cam_dis = distance(cc_cameraPos, wPos) / fogAtten * 4.;\n float f = exp(-cam_dis * fogDensity);\n return f;\n}\nfloat ExpSquaredFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float fogDensity = cc_fogBase.z;\n float cam_dis = distance(cc_cameraPos, wPos) / fogAtten * 4.;\n float f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\n return f;\n}\nfloat LayeredFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float _FogTop = cc_fogAdd.x;\n float _FogRange = cc_fogAdd.y;\n vec3 camWorldProj = cc_cameraPos.xyz;\n camWorldProj.y = 0.;\n vec3 worldPosProj = wPos.xyz;\n worldPosProj.y = 0.;\n float fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\n float fDeltaY, fDensityIntegral;\n if (cc_cameraPos.y > _FogTop) {\n if (wPos.y < _FogTop) {\n fDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\n fDensityIntegral = fDeltaY * fDeltaY * 0.5;\n } else {\n fDeltaY = 0.;\n fDensityIntegral = 0.;\n }\n } else {\n if (wPos.y < _FogTop) {\n float fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\n float fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\n fDeltaY = abs(fDeltaA - fDeltaB);\n fDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n } else {\n fDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\n fDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n }\n }\n float fDensity;\n if (fDeltaY != 0.) {\n fDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n } else {\n fDensity = 0.;\n }\n float f = exp(-fDensity);\n return f;\n}\nfloat CC_TRANSFER_FOG(vec4 pos) {\n #if CC_USE_FOG == 1\n return LinearFog(pos);\n #elif CC_USE_FOG == 2\n return ExpFog(pos);\n #elif CC_USE_FOG == 3\n return ExpSquaredFog(pos);\n #elif CC_USE_FOG == 4\n return LayeredFog(pos);\n #endif\n return 1.;\n}\n#if USE_VERTEX_COLOR\n in vec4 a_color;\n out vec4 v_color;\n#endif\n#if USE_TEXTURE\n in vec2 a_texCoord;\n out vec2 v_uv;\n uniform TexCoords {\n vec4 tilingOffset;\n };\n#endif\nout float factor_fog;\nvec4 vert () {\n vec4 position;\n position = vec4(a_position, 1.0);\n #if CC_USE_MORPH\n applyMorph(position);\n #endif\n #if CC_USE_SKINNING\n CCSkin(position);\n #endif\n mat4 matWorld;\n #if USE_INSTANCING\n matWorld = mat4(\n vec4(a_matWorld0.xyz, 0.0),\n vec4(a_matWorld1.xyz, 0.0),\n vec4(a_matWorld2.xyz, 0.0),\n vec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)\n );\n #elif USE_BATCHING\n matWorld = cc_matWorlds[int(a_dyn_batch_id)];\n #else\n matWorld = cc_matWorld;\n #endif\n #if USE_TEXTURE\n v_uv = a_texCoord;\n #if FLIP_UV\n v_uv.y = 1.0 - v_uv.y;\n #endif\n v_uv = v_uv * tilingOffset.xy + tilingOffset.zw;\n #endif\n #if USE_VERTEX_COLOR\n v_color = a_color;\n #endif\n factor_fog = CC_TRANSFER_FOG(matWorld * position);\n return cc_matProj * (cc_matView * matWorld) * position;\n}\nvoid main() { gl_Position = vert(); }`, + "frag": `\nprecision mediump float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\n}\nvec4 CCFragOutput (vec4 color) {\n #if CC_USE_HDR\n color.rgb = mix(color.rgb, SRGBToLinear(color.rgb) * cc_exposure.w, vec3(cc_exposure.z));\n #endif\n return color;\n}\n#if USE_ALPHA_TEST\n#endif\n#if USE_TEXTURE\n in vec2 v_uv;\n uniform sampler2D mainTexture;\n#endif\nuniform Constant {\n vec4 mainColor;\n vec4 colorScaleAndCutoff;\n};\n#if USE_VERTEX_COLOR\n in vec4 v_color;\n#endif\nin float factor_fog;\nvec4 frag () {\n vec4 o = mainColor;\n o.rgb *= colorScaleAndCutoff.xyz;\n #if USE_VERTEX_COLOR\n o *= v_color;\n #endif\n #if USE_TEXTURE\n o *= texture(mainTexture, v_uv);\n #endif\n #if USE_ALPHA_TEST\n if (o.ALPHA_TEST_CHANNEL < colorScaleAndCutoff.w) discard;\n #endif\n o = mix(cc_fogColor, o, factor_fog);\n return CCFragOutput(o);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }` }, "glsl1": { - "vert": `\nprecision highp float;\nstruct StandardVertInput {\n highp vec4 position;\n vec3 normal;\n vec4 tangent;\n};\nattribute vec3 a_position;\n#if CC_USE_MORPH\n attribute float a_vertexId;\n int getVertexId() {\n return int(a_vertexId);\n }\nuniform vec4 cc_displacementWeights[15];\nuniform vec4 cc_displacementTextureInfo;\n vec4 fetchFlatPixel(sampler2D tex, int pixelIndex) {\n float pixelIndexF = float(pixelIndex);\n vec2 textureResolution = vec2(float(cc_displacementTextureInfo.x), float(cc_displacementTextureInfo.y));\n float pixelX = mod(pixelIndexF, textureResolution.x);\n float pixelY = floor(pixelIndexF / textureResolution.x);\n vec2 uv = (vec2(pixelX, pixelY) + .5) / textureResolution;\n return texture2D(tex, uv);\n }\nfloat getDisplacementWeight(int index) {\n float m = mod(float(index), 4.0);\n if (m < 1.0) {\n return cc_displacementWeights[index / 4].x;\n } else if (m < 2.0) {\n return cc_displacementWeights[index / 4].y;\n } else if (m < 3.0) {\n return cc_displacementWeights[index / 4].z;\n } else {\n return cc_displacementWeights[index / 4].w;\n }\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\n return fetchFlatPixel(tex, vertexIndex).rgb;\n#else\n vec3 result = vec3(0, 0, 0);\n for (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\n int dataPixelStart = int(fetchFlatPixel(tex, iTarget).r);\n result += (fetchFlatPixel(tex, dataPixelStart + vertexIndex).rgb * getDisplacementWeight(iTarget));\n }\n return result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\n uniform sampler2D cc_PositionDisplacements;\n vec3 getPositionDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n uniform sampler2D cc_NormalDisplacements;\n vec3 getNormalDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n uniform sampler2D cc_TangentDisplacements;\n vec3 getTangentDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n }\n#endif\nvoid applyMorph (inout StandardVertInput attr) {\n int vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\n attr.position.xyz = attr.position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n attr.normal.xyz = attr.normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n attr.tangent.xyz = attr.tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\n position.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\nattribute vec4 a_weights;\nattribute vec4 a_joints;\n#if CC_USE_BAKED_ANIMATION\n #if USE_INSTANCING\n attribute highp vec4 a_jointAnimInfo;\n #endif\n uniform highp vec4 cc_jointTextureInfo;\n uniform highp vec4 cc_jointAnimInfo;\n uniform sampler2D cc_jointTexture;\n #if !CC_SUPPORT_FLOAT_TEXTURE\n highp float decode32 (highp vec4 rgba) {\n rgba = rgba * 255.0;\n highp float Sign = 1.0 - step(128.0, rgba[3]) * 2.0;\n highp float Exponent = 2.0 * mod(rgba[3], 128.0) + step(128.0, rgba[2]) - 127.0;\n highp float Mantissa = mod(rgba[2], 128.0) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\n }\n #endif\n#else\n uniform highp vec4 cc_joints[90];\n#endif\n#if CC_USE_BAKED_ANIMATION\n #if CC_SUPPORT_FLOAT_TEXTURE\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 3.0 * (a_jointAnimInfo.x * a_jointAnimInfo.y + i) + a_jointAnimInfo.z;\n #else\n highp float j = 3.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y));\n vec4 v2 = texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y));\n vec4 v3 = texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y));\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #else\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 12.0 * (a_jointAnimInfo.x * a_jointAnimInfo.y + i) + a_jointAnimInfo.z;\n #else\n highp float j = 12.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = vec4(\n decode32(texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n );\n vec4 v2 = vec4(\n decode32(texture2D(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n );\n vec4 v3 = vec4(\n decode32(texture2D(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n );\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #endif\n#else\n mat4 getJointMatrix (float i) {\n int idx = int(i);\n vec4 v1 = cc_joints[idx * 3];\n vec4 v2 = cc_joints[idx * 3 + 1];\n vec4 v3 = cc_joints[idx * 3 + 2];\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n#endif\nmat4 skinMatrix () {\n return getJointMatrix(a_joints.x) * a_weights.x\n + getJointMatrix(a_joints.y) * a_weights.y;\n + getJointMatrix(a_joints.z) * a_weights.z;\n + getJointMatrix(a_joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\n mat4 m = skinMatrix();\n position = m * position;\n}\nvoid CCSkin (inout StandardVertInput attr) {\n mat4 m = skinMatrix();\n attr.position = m * attr.position;\n attr.normal = (m * vec4(attr.normal, 0.0)).xyz;\n attr.tangent.xyz = (m * vec4(attr.tangent.xyz, 0.0)).xyz;\n}\n#endif\nuniform highp mat4 cc_matView;\nuniform highp mat4 cc_matProj;\n#if USE_INSTANCING\n attribute vec4 a_matWorld0;\n attribute vec4 a_matWorld1;\n attribute vec4 a_matWorld2;\n#elif USE_BATCHING\n attribute float a_dyn_batch_id;\n uniform highp mat4 cc_matWorlds[10];\n#else\nuniform highp mat4 cc_matWorld;\n#endif\n#if USE_VERTEX_COLOR\n attribute vec4 a_color;\n varying vec4 v_color;\n#endif\n#if USE_TEXTURE\n attribute vec2 a_texCoord;\n varying vec2 v_uv;\n uniform vec4 tilingOffset;\n#endif\nvec4 vert () {\n vec4 position;\n position = vec4(a_position, 1.0);\n #if CC_USE_MORPH\n applyMorph(position);\n #endif\n #if CC_USE_SKINNING\n CCSkin(position);\n #endif\n mat4 matWorld;\n #if USE_INSTANCING\n matWorld = mat4(\n vec4(a_matWorld0.xyz, 0.0),\n vec4(a_matWorld1.xyz, 0.0),\n vec4(a_matWorld2.xyz, 0.0),\n vec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)\n );\n #elif USE_BATCHING\n matWorld = cc_matWorlds[int(a_dyn_batch_id)];\n #else\n matWorld = cc_matWorld;\n #endif\n #if USE_TEXTURE\n v_uv = a_texCoord;\n #if FLIP_UV\n v_uv.y = 1.0 - v_uv.y;\n #endif\n v_uv = v_uv * tilingOffset.xy + tilingOffset.zw;\n #endif\n #if USE_VERTEX_COLOR\n v_color = a_color;\n #endif\n return cc_matProj * (cc_matView * matWorld) * position;\n}\nvoid main() { gl_Position = vert(); }`, - "frag": `\nprecision mediump float;\nuniform mediump vec4 cc_exposure;\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\n}\nvec4 CCFragOutput (vec4 color) {\n #if CC_USE_HDR\n color.rgb = mix(color.rgb, SRGBToLinear(color.rgb) * cc_exposure.w, vec3(cc_exposure.z));\n #endif\n return color;\n}\n#if USE_ALPHA_TEST\n#endif\n#if USE_TEXTURE\n varying vec2 v_uv;\n uniform sampler2D mainTexture;\n#endif\nuniform vec4 mainColor;\nuniform vec4 colorScaleAndCutoff;\n#if USE_VERTEX_COLOR\n varying vec4 v_color;\n#endif\nvec4 frag () {\n vec4 o = mainColor;\n o.rgb *= colorScaleAndCutoff.xyz;\n #if USE_VERTEX_COLOR\n o *= v_color;\n #endif\n #if USE_TEXTURE\n o *= texture2D(mainTexture, v_uv);\n #endif\n #if USE_ALPHA_TEST\n if (o.ALPHA_TEST_CHANNEL < colorScaleAndCutoff.w) discard;\n #endif\n return CCFragOutput(o);\n}\nvoid main() { gl_FragColor = frag(); }` + "vert": `\nprecision highp float;\nuniform highp mat4 cc_matView;\nuniform highp mat4 cc_matProj;\nuniform highp vec4 cc_cameraPos;\nuniform mediump vec4 cc_fogBase;\nuniform mediump vec4 cc_fogAdd;\n#if USE_INSTANCING\n attribute vec4 a_matWorld0;\n attribute vec4 a_matWorld1;\n attribute vec4 a_matWorld2;\n#elif USE_BATCHING\n attribute float a_dyn_batch_id;\n uniform highp mat4 cc_matWorlds[10];\n#else\nuniform highp mat4 cc_matWorld;\n#endif\nstruct StandardVertInput {\n highp vec4 position;\n vec3 normal;\n vec4 tangent;\n};\nattribute vec3 a_position;\n#if CC_USE_MORPH\n attribute float a_vertexId;\n int getVertexId() {\n return int(a_vertexId);\n }\nuniform vec4 cc_displacementWeights[15];\nuniform vec4 cc_displacementTextureInfo;\n vec4 fetchFlatPixel(sampler2D tex, int pixelIndex) {\n float pixelIndexF = float(pixelIndex);\n vec2 textureResolution = vec2(float(cc_displacementTextureInfo.x), float(cc_displacementTextureInfo.y));\n float pixelX = mod(pixelIndexF, textureResolution.x);\n float pixelY = floor(pixelIndexF / textureResolution.x);\n vec2 uv = (vec2(pixelX, pixelY) + .5) / textureResolution;\n return texture2D(tex, uv);\n }\nfloat getDisplacementWeight(int index) {\n float m = mod(float(index), 4.0);\n if (m < 1.0) {\n return cc_displacementWeights[index / 4].x;\n } else if (m < 2.0) {\n return cc_displacementWeights[index / 4].y;\n } else if (m < 3.0) {\n return cc_displacementWeights[index / 4].z;\n } else {\n return cc_displacementWeights[index / 4].w;\n }\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\n return fetchFlatPixel(tex, vertexIndex).rgb;\n#else\n vec3 result = vec3(0, 0, 0);\n for (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\n int dataPixelStart = int(fetchFlatPixel(tex, iTarget).r);\n result += (fetchFlatPixel(tex, dataPixelStart + vertexIndex).rgb * getDisplacementWeight(iTarget));\n }\n return result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\n uniform sampler2D cc_PositionDisplacements;\n vec3 getPositionDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n uniform sampler2D cc_NormalDisplacements;\n vec3 getNormalDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n uniform sampler2D cc_TangentDisplacements;\n vec3 getTangentDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n }\n#endif\nvoid applyMorph (inout StandardVertInput attr) {\n int vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\n attr.position.xyz = attr.position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n attr.normal.xyz = attr.normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n attr.tangent.xyz = attr.tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\n position.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\nattribute vec4 a_weights;\nattribute vec4 a_joints;\n#if CC_USE_BAKED_ANIMATION\n #if USE_INSTANCING\n attribute vec4 a_jointAnimInfo;\n #endif\n uniform highp vec4 cc_jointTextureInfo;\n uniform highp vec4 cc_jointAnimInfo;\n uniform sampler2D cc_jointTexture;\n #if !CC_SUPPORT_FLOAT_TEXTURE\n highp float decode32 (highp vec4 rgba) {\n rgba = rgba * 255.0;\n highp float Sign = 1.0 - step(128.0, rgba[3]) * 2.0;\n highp float Exponent = 2.0 * mod(rgba[3], 128.0) + step(128.0, rgba[2]) - 127.0;\n highp float Mantissa = mod(rgba[2], 128.0) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\n }\n #endif\n#else\n uniform highp vec4 cc_joints[90];\n#endif\n#if CC_USE_BAKED_ANIMATION\n #if CC_SUPPORT_FLOAT_TEXTURE\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 3.0 * i + a_jointAnimInfo.x;\n #else\n highp float j = 3.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y));\n vec4 v2 = texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y));\n vec4 v3 = texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y));\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #else\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 12.0 * i + a_jointAnimInfo.x;\n #else\n highp float j = 12.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = vec4(\n decode32(texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n );\n vec4 v2 = vec4(\n decode32(texture2D(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n );\n vec4 v3 = vec4(\n decode32(texture2D(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n );\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #endif\n#else\n mat4 getJointMatrix (float i) {\n int idx = int(i);\n vec4 v1 = cc_joints[idx * 3];\n vec4 v2 = cc_joints[idx * 3 + 1];\n vec4 v3 = cc_joints[idx * 3 + 2];\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n#endif\nmat4 skinMatrix () {\n return getJointMatrix(a_joints.x) * a_weights.x\n + getJointMatrix(a_joints.y) * a_weights.y;\n + getJointMatrix(a_joints.z) * a_weights.z;\n + getJointMatrix(a_joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\n mat4 m = skinMatrix();\n position = m * position;\n}\nvoid CCSkin (inout StandardVertInput attr) {\n mat4 m = skinMatrix();\n attr.position = m * attr.position;\n attr.normal = (m * vec4(attr.normal, 0.0)).xyz;\n attr.tangent.xyz = (m * vec4(attr.tangent.xyz, 0.0)).xyz;\n}\n#endif\nfloat LinearFog(vec4 pos) {\n vec4 wPos = pos;\n float cam_dis = distance(cc_cameraPos, wPos);\n float fogStart = cc_fogBase.x;\n float fogEnd = cc_fogBase.y;\n return clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float fogDensity = cc_fogBase.z;\n float cam_dis = distance(cc_cameraPos, wPos) / fogAtten * 4.;\n float f = exp(-cam_dis * fogDensity);\n return f;\n}\nfloat ExpSquaredFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float fogDensity = cc_fogBase.z;\n float cam_dis = distance(cc_cameraPos, wPos) / fogAtten * 4.;\n float f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\n return f;\n}\nfloat LayeredFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float _FogTop = cc_fogAdd.x;\n float _FogRange = cc_fogAdd.y;\n vec3 camWorldProj = cc_cameraPos.xyz;\n camWorldProj.y = 0.;\n vec3 worldPosProj = wPos.xyz;\n worldPosProj.y = 0.;\n float fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\n float fDeltaY, fDensityIntegral;\n if (cc_cameraPos.y > _FogTop) {\n if (wPos.y < _FogTop) {\n fDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\n fDensityIntegral = fDeltaY * fDeltaY * 0.5;\n } else {\n fDeltaY = 0.;\n fDensityIntegral = 0.;\n }\n } else {\n if (wPos.y < _FogTop) {\n float fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\n float fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\n fDeltaY = abs(fDeltaA - fDeltaB);\n fDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n } else {\n fDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\n fDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n }\n }\n float fDensity;\n if (fDeltaY != 0.) {\n fDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n } else {\n fDensity = 0.;\n }\n float f = exp(-fDensity);\n return f;\n}\nfloat CC_TRANSFER_FOG(vec4 pos) {\n #if CC_USE_FOG == 1\n return LinearFog(pos);\n #elif CC_USE_FOG == 2\n return ExpFog(pos);\n #elif CC_USE_FOG == 3\n return ExpSquaredFog(pos);\n #elif CC_USE_FOG == 4\n return LayeredFog(pos);\n #endif\n return 1.;\n}\n#if USE_VERTEX_COLOR\n attribute vec4 a_color;\n varying vec4 v_color;\n#endif\n#if USE_TEXTURE\n attribute vec2 a_texCoord;\n varying vec2 v_uv;\n uniform vec4 tilingOffset;\n#endif\nvarying float factor_fog;\nvec4 vert () {\n vec4 position;\n position = vec4(a_position, 1.0);\n #if CC_USE_MORPH\n applyMorph(position);\n #endif\n #if CC_USE_SKINNING\n CCSkin(position);\n #endif\n mat4 matWorld;\n #if USE_INSTANCING\n matWorld = mat4(\n vec4(a_matWorld0.xyz, 0.0),\n vec4(a_matWorld1.xyz, 0.0),\n vec4(a_matWorld2.xyz, 0.0),\n vec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)\n );\n #elif USE_BATCHING\n matWorld = cc_matWorlds[int(a_dyn_batch_id)];\n #else\n matWorld = cc_matWorld;\n #endif\n #if USE_TEXTURE\n v_uv = a_texCoord;\n #if FLIP_UV\n v_uv.y = 1.0 - v_uv.y;\n #endif\n v_uv = v_uv * tilingOffset.xy + tilingOffset.zw;\n #endif\n #if USE_VERTEX_COLOR\n v_color = a_color;\n #endif\n factor_fog = CC_TRANSFER_FOG(matWorld * position);\n return cc_matProj * (cc_matView * matWorld) * position;\n}\nvoid main() { gl_Position = vert(); }`, + "frag": `\nprecision mediump float;\nuniform mediump vec4 cc_exposure;\nuniform mediump vec4 cc_fogColor;\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\n}\nvec4 CCFragOutput (vec4 color) {\n #if CC_USE_HDR\n color.rgb = mix(color.rgb, SRGBToLinear(color.rgb) * cc_exposure.w, vec3(cc_exposure.z));\n #endif\n return color;\n}\n#if USE_ALPHA_TEST\n#endif\n#if USE_TEXTURE\n varying vec2 v_uv;\n uniform sampler2D mainTexture;\n#endif\nuniform vec4 mainColor;\nuniform vec4 colorScaleAndCutoff;\n#if USE_VERTEX_COLOR\n varying vec4 v_color;\n#endif\nvarying float factor_fog;\nvec4 frag () {\n vec4 o = mainColor;\n o.rgb *= colorScaleAndCutoff.xyz;\n #if USE_VERTEX_COLOR\n o *= v_color;\n #endif\n #if USE_TEXTURE\n o *= texture2D(mainTexture, v_uv);\n #endif\n #if USE_ALPHA_TEST\n if (o.ALPHA_TEST_CHANNEL < colorScaleAndCutoff.w) discard;\n #endif\n o = mix(cc_fogColor, o, factor_fog);\n return CCFragOutput(o);\n}\nvoid main() { gl_FragColor = frag(); }` }, "builtins": { "globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }], "samplers": [] }, - "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"] }], "samplers": [{ "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"] }] } + "locals": { "blocks": [{ "name": "CCLocalBatched", "defines": ["!USE_INSTANCING", "USE_BATCHING"] }, { "name": "CCLocal", "defines": ["!USE_INSTANCING", "!USE_BATCHING"] }, { "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"] }], "samplers": [{ "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"] }] } }, "defines": [ + { "name": "USE_INSTANCING", "type": "boolean" }, + { "name": "USE_BATCHING", "type": "boolean" }, { "name": "CC_USE_MORPH", "type": "boolean" }, - { "name": "CC_MORPH_TARGET_COUNT", "type": "number", "range": [2, 8] }, + { "name": "CC_MORPH_TARGET_COUNT", "type": "number", "dummyDependency": true, "range": [2, 8] }, { "name": "CC_MORPH_PRECOMPUTED", "type": "boolean" }, { "name": "CC_MORPH_TARGET_HAS_POSITION", "type": "boolean" }, { "name": "CC_MORPH_TARGET_HAS_NORMAL", "type": "boolean" }, { "name": "CC_MORPH_TARGET_HAS_TANGENT", "type": "boolean" }, { "name": "CC_USE_SKINNING", "type": "boolean" }, { "name": "CC_USE_BAKED_ANIMATION", "type": "boolean" }, - { "name": "USE_INSTANCING", "type": "boolean" }, { "name": "CC_SUPPORT_FLOAT_TEXTURE", "type": "boolean" }, - { "name": "USE_BATCHING", "type": "boolean" }, + { "name": "CC_USE_FOG", "type": "number", "range": [0, 4] }, { "name": "USE_VERTEX_COLOR", "type": "boolean" }, { "name": "USE_TEXTURE", "type": "boolean" }, { "name": "FLIP_UV", "type": "boolean" }, { "name": "CC_USE_HDR", "type": "boolean" }, { "name": "USE_ALPHA_TEST", "type": "boolean" }, - { "name": "ALPHA_TEST_CHANNEL", "type": "string", "options": ["a", "r", "g", "b"] } + { "name": "ALPHA_TEST_CHANNEL", "type": "string", "dummyDependency": true, "options": ["a", "r", "g", "b"] } ], "blocks": [ {"name": "TexCoords", "defines": ["USE_TEXTURE"], "binding": 0, "members": [ @@ -480,18 +485,18 @@ export default [ ]} ], "samplers": [ - { "name": "mainTexture", "type": 28, "count": 1, "defines": ["USE_TEXTURE"], "binding": 30 } + { "name": "mainTexture", "type": 28, "count": 1, "defines": ["USE_TEXTURE"], "binding": 31 } ], "attributes": [ + { "name": "a_matWorld0", "type": 16, "count": 1, "defines": ["USE_INSTANCING"], "format": 43, "isInstanced": true, "location": 4 }, + { "name": "a_matWorld1", "type": 16, "count": 1, "defines": ["USE_INSTANCING"], "format": 43, "isInstanced": true, "location": 1 }, + { "name": "a_matWorld2", "type": 16, "count": 1, "defines": ["USE_INSTANCING"], "format": 43, "isInstanced": true, "location": 2 }, + { "name": "a_dyn_batch_id", "type": 13, "count": 1, "defines": ["!USE_INSTANCING", "USE_BATCHING"], "format": 11, "location": 3 }, { "name": "a_position", "type": 15, "count": 1, "defines": [], "format": 32, "location": 0 }, - { "name": "a_vertexId", "type": 13, "count": 1, "defines": ["CC_USE_MORPH"], "format": 11, "location": 1 }, - { "name": "a_weights", "type": 16, "count": 1, "defines": ["CC_USE_SKINNING"], "format": 43, "location": 2 }, - { "name": "a_joints", "type": 16, "count": 1, "defines": ["CC_USE_SKINNING"], "format": 43, "location": 3 }, - { "name": "a_jointAnimInfo", "type": 16, "count": 1, "precision": "highp ", "defines": ["CC_USE_SKINNING", "CC_USE_BAKED_ANIMATION", "USE_INSTANCING"], "format": 43, "isInstanced": true, "location": 4 }, - { "name": "a_matWorld0", "type": 16, "count": 1, "defines": ["USE_INSTANCING"], "format": 43, "isInstanced": true, "location": 5 }, - { "name": "a_matWorld1", "type": 16, "count": 1, "defines": ["USE_INSTANCING"], "format": 43, "isInstanced": true, "location": 6 }, - { "name": "a_matWorld2", "type": 16, "count": 1, "defines": ["USE_INSTANCING"], "format": 43, "isInstanced": true, "location": 7 }, - { "name": "a_dyn_batch_id", "type": 13, "count": 1, "defines": ["!USE_INSTANCING", "USE_BATCHING"], "format": 11, "location": 8 }, + { "name": "a_vertexId", "type": 13, "count": 1, "defines": ["CC_USE_MORPH"], "format": 11, "location": 5 }, + { "name": "a_weights", "type": 16, "count": 1, "defines": ["CC_USE_SKINNING"], "format": 43, "location": 6 }, + { "name": "a_joints", "type": 16, "count": 1, "defines": ["CC_USE_SKINNING"], "format": 43, "location": 7 }, + { "name": "a_jointAnimInfo", "type": 16, "count": 1, "defines": ["CC_USE_SKINNING", "CC_USE_BAKED_ANIMATION", "USE_INSTANCING"], "format": 43, "isInstanced": true, "location": 8 }, { "name": "a_color", "type": 16, "count": 1, "defines": ["USE_VERTEX_COLOR"], "format": 43, "location": 9 }, { "name": "a_texCoord", "type": 14, "count": 1, "defines": ["USE_TEXTURE"], "format": 21, "location": 10 } ] @@ -507,45 +512,45 @@ export default [ "shaders": [ { "name": "pipeline/planar-shadow|planar-shadow-vs:vert|planar-shadow-fs:frag", - "hash": 2011749318, + "hash": 2467023454, "glsl3": { - "vert": `\nprecision highp float;\nstruct StandardVertInput {\n highp vec4 position;\n vec3 normal;\n vec4 tangent;\n};\nin vec3 a_position;\n#if CC_USE_MORPH\n in float a_vertexId;\n int getVertexId() {\n return int(a_vertexId);\n }\nuniform CCMorph {\n vec4 cc_displacementWeights[15];\n vec4 cc_displacementTextureInfo;\n};\n vec4 fetchFlatPixel(sampler2D tex, int pixelIndex) {\n float pixelIndexF = float(pixelIndex);\n vec2 textureResolution = vec2(float(cc_displacementTextureInfo.x), float(cc_displacementTextureInfo.y));\n float pixelX = mod(pixelIndexF, textureResolution.x);\n float pixelY = floor(pixelIndexF / textureResolution.x);\n vec2 uv = (vec2(pixelX, pixelY) + .5) / textureResolution;\n return texture(tex, uv);\n }\nfloat getDisplacementWeight(int index) {\n float m = mod(float(index), 4.0);\n if (m < 1.0) {\n return cc_displacementWeights[index / 4].x;\n } else if (m < 2.0) {\n return cc_displacementWeights[index / 4].y;\n } else if (m < 3.0) {\n return cc_displacementWeights[index / 4].z;\n } else {\n return cc_displacementWeights[index / 4].w;\n }\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\n return fetchFlatPixel(tex, vertexIndex).rgb;\n#else\n vec3 result = vec3(0, 0, 0);\n for (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\n int dataPixelStart = int(fetchFlatPixel(tex, iTarget).r);\n result += (fetchFlatPixel(tex, dataPixelStart + vertexIndex).rgb * getDisplacementWeight(iTarget));\n }\n return result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\n uniform sampler2D cc_PositionDisplacements;\n vec3 getPositionDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n uniform sampler2D cc_NormalDisplacements;\n vec3 getNormalDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n uniform sampler2D cc_TangentDisplacements;\n vec3 getTangentDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n }\n#endif\nvoid applyMorph (inout StandardVertInput attr) {\n int vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\n attr.position.xyz = attr.position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n attr.normal.xyz = attr.normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n attr.tangent.xyz = attr.tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\n position.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\nin vec4 a_weights;\nin vec4 a_joints;\n#if CC_USE_BAKED_ANIMATION\n #if USE_INSTANCING\n in highp vec4 a_jointAnimInfo;\n #endif\n uniform CCSkinningTexture {\n highp vec4 cc_jointTextureInfo;\n };\n uniform CCSkinningAnimation {\n highp vec4 cc_jointAnimInfo;\n };\n uniform sampler2D cc_jointTexture;\n #if !CC_SUPPORT_FLOAT_TEXTURE\n highp float decode32 (highp vec4 rgba) {\n rgba = rgba * 255.0;\n highp float Sign = 1.0 - step(128.0, rgba[3]) * 2.0;\n highp float Exponent = 2.0 * mod(rgba[3], 128.0) + step(128.0, rgba[2]) - 127.0;\n highp float Mantissa = mod(rgba[2], 128.0) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\n }\n #endif\n#else\n uniform CCSkinning {\n highp vec4 cc_joints[30 * 3];\n };\n#endif\n#if CC_USE_BAKED_ANIMATION\n #if CC_SUPPORT_FLOAT_TEXTURE\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 3.0 * (a_jointAnimInfo.x * a_jointAnimInfo.y + i) + a_jointAnimInfo.z;\n #else\n highp float j = 3.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = texture(cc_jointTexture, vec2((x + 0.5) * invSize, y));\n vec4 v2 = texture(cc_jointTexture, vec2((x + 1.5) * invSize, y));\n vec4 v3 = texture(cc_jointTexture, vec2((x + 2.5) * invSize, y));\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #else\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 12.0 * (a_jointAnimInfo.x * a_jointAnimInfo.y + i) + a_jointAnimInfo.z;\n #else\n highp float j = 12.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = vec4(\n decode32(texture(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n );\n vec4 v2 = vec4(\n decode32(texture(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n );\n vec4 v3 = vec4(\n decode32(texture(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n );\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #endif\n#else\n mat4 getJointMatrix (float i) {\n int idx = int(i);\n vec4 v1 = cc_joints[idx * 3];\n vec4 v2 = cc_joints[idx * 3 + 1];\n vec4 v3 = cc_joints[idx * 3 + 2];\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n#endif\nmat4 skinMatrix () {\n return getJointMatrix(a_joints.x) * a_weights.x\n + getJointMatrix(a_joints.y) * a_weights.y;\n + getJointMatrix(a_joints.z) * a_weights.z;\n + getJointMatrix(a_joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\n mat4 m = skinMatrix();\n position = m * position;\n}\nvoid CCSkin (inout StandardVertInput attr) {\n mat4 m = skinMatrix();\n attr.position = m * attr.position;\n attr.normal = (m * vec4(attr.normal, 0.0)).xyz;\n attr.tangent.xyz = (m * vec4(attr.tangent.xyz, 0.0)).xyz;\n}\n#endif\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n};\n#if USE_INSTANCING\n in vec4 a_matWorld0;\n in vec4 a_matWorld1;\n in vec4 a_matWorld2;\n#elif USE_BATCHING\n in float a_dyn_batch_id;\n uniform CCLocalBatched {\n highp mat4 cc_matWorlds[10];\n };\n#else\nuniform CCLocal {\n highp mat4 cc_matWorld;\n highp mat4 cc_matWorldIT;\n};\n#endif\nuniform CCShadow {\n highp mat4 cc_matLightPlaneProj;\n lowp vec4 cc_shadowColor;\n};\nvec4 vert () {\n vec4 position;\n position = vec4(a_position, 1.0);\n #if CC_USE_MORPH\n applyMorph(position);\n #endif\n #if CC_USE_SKINNING\n CCSkin(position);\n #endif\n mat4 matWorld;\n #if USE_INSTANCING\n matWorld = mat4(\n vec4(a_matWorld0.xyz, 0.0),\n vec4(a_matWorld1.xyz, 0.0),\n vec4(a_matWorld2.xyz, 0.0),\n vec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)\n );\n #elif USE_BATCHING\n matWorld = cc_matWorlds[int(a_dyn_batch_id)];\n #else\n matWorld = cc_matWorld;\n #endif\n position = cc_matProj * (cc_matView * cc_matLightPlaneProj * matWorld) * position;\n position.z -= 0.0001;\n return position;\n}\nvoid main() { gl_Position = vert(); }`, - "frag": `\nprecision mediump float;\nuniform CCShadow {\n highp mat4 cc_matLightPlaneProj;\n lowp vec4 cc_shadowColor;\n};\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n};\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\n}\nvec4 CCFragOutput (vec4 color) {\n #if CC_USE_HDR\n color.rgb = mix(color.rgb, SRGBToLinear(color.rgb) * cc_exposure.w, vec3(cc_exposure.z));\n #endif\n return color;\n}\nvec4 frag () {\n return CCFragOutput(cc_shadowColor);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }` + "vert": `\nprecision highp float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\n#if USE_INSTANCING\n in vec4 a_matWorld0;\n in vec4 a_matWorld1;\n in vec4 a_matWorld2;\n#elif USE_BATCHING\n in float a_dyn_batch_id;\n uniform CCLocalBatched {\n highp mat4 cc_matWorlds[10];\n };\n#else\nuniform CCLocal {\n highp mat4 cc_matWorld;\n highp mat4 cc_matWorldIT;\n highp vec4 cc_lightingMapUVParam;\n};\n#endif\nuniform CCShadow {\n highp mat4 cc_matLightPlaneProj;\n lowp vec4 cc_shadowColor;\n};\nstruct StandardVertInput {\n highp vec4 position;\n vec3 normal;\n vec4 tangent;\n};\nin vec3 a_position;\n#if CC_USE_MORPH\n in float a_vertexId;\n int getVertexId() {\n return int(a_vertexId);\n }\nuniform CCMorph {\n vec4 cc_displacementWeights[15];\n vec4 cc_displacementTextureInfo;\n};\n vec4 fetchFlatPixel(sampler2D tex, int pixelIndex) {\n float pixelIndexF = float(pixelIndex);\n vec2 textureResolution = vec2(float(cc_displacementTextureInfo.x), float(cc_displacementTextureInfo.y));\n float pixelX = mod(pixelIndexF, textureResolution.x);\n float pixelY = floor(pixelIndexF / textureResolution.x);\n vec2 uv = (vec2(pixelX, pixelY) + .5) / textureResolution;\n return texture(tex, uv);\n }\nfloat getDisplacementWeight(int index) {\n float m = mod(float(index), 4.0);\n if (m < 1.0) {\n return cc_displacementWeights[index / 4].x;\n } else if (m < 2.0) {\n return cc_displacementWeights[index / 4].y;\n } else if (m < 3.0) {\n return cc_displacementWeights[index / 4].z;\n } else {\n return cc_displacementWeights[index / 4].w;\n }\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\n return fetchFlatPixel(tex, vertexIndex).rgb;\n#else\n vec3 result = vec3(0, 0, 0);\n for (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\n int dataPixelStart = int(fetchFlatPixel(tex, iTarget).r);\n result += (fetchFlatPixel(tex, dataPixelStart + vertexIndex).rgb * getDisplacementWeight(iTarget));\n }\n return result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\n uniform sampler2D cc_PositionDisplacements;\n vec3 getPositionDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n uniform sampler2D cc_NormalDisplacements;\n vec3 getNormalDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n uniform sampler2D cc_TangentDisplacements;\n vec3 getTangentDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n }\n#endif\nvoid applyMorph (inout StandardVertInput attr) {\n int vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\n attr.position.xyz = attr.position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n attr.normal.xyz = attr.normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n attr.tangent.xyz = attr.tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\n position.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\nin vec4 a_weights;\nin vec4 a_joints;\n#if CC_USE_BAKED_ANIMATION\n #if USE_INSTANCING\n in vec4 a_jointAnimInfo;\n #endif\n uniform CCSkinningTexture {\n highp vec4 cc_jointTextureInfo;\n };\n uniform CCSkinningAnimation {\n highp vec4 cc_jointAnimInfo;\n };\n uniform sampler2D cc_jointTexture;\n #if !CC_SUPPORT_FLOAT_TEXTURE\n highp float decode32 (highp vec4 rgba) {\n rgba = rgba * 255.0;\n highp float Sign = 1.0 - step(128.0, rgba[3]) * 2.0;\n highp float Exponent = 2.0 * mod(rgba[3], 128.0) + step(128.0, rgba[2]) - 127.0;\n highp float Mantissa = mod(rgba[2], 128.0) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\n }\n #endif\n#else\n uniform CCSkinning {\n highp vec4 cc_joints[30 * 3];\n };\n#endif\n#if CC_USE_BAKED_ANIMATION\n #if CC_SUPPORT_FLOAT_TEXTURE\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 3.0 * i + a_jointAnimInfo.x;\n #else\n highp float j = 3.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = texture(cc_jointTexture, vec2((x + 0.5) * invSize, y));\n vec4 v2 = texture(cc_jointTexture, vec2((x + 1.5) * invSize, y));\n vec4 v3 = texture(cc_jointTexture, vec2((x + 2.5) * invSize, y));\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #else\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 12.0 * i + a_jointAnimInfo.x;\n #else\n highp float j = 12.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = vec4(\n decode32(texture(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n );\n vec4 v2 = vec4(\n decode32(texture(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n );\n vec4 v3 = vec4(\n decode32(texture(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n );\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #endif\n#else\n mat4 getJointMatrix (float i) {\n int idx = int(i);\n vec4 v1 = cc_joints[idx * 3];\n vec4 v2 = cc_joints[idx * 3 + 1];\n vec4 v3 = cc_joints[idx * 3 + 2];\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n#endif\nmat4 skinMatrix () {\n return getJointMatrix(a_joints.x) * a_weights.x\n + getJointMatrix(a_joints.y) * a_weights.y;\n + getJointMatrix(a_joints.z) * a_weights.z;\n + getJointMatrix(a_joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\n mat4 m = skinMatrix();\n position = m * position;\n}\nvoid CCSkin (inout StandardVertInput attr) {\n mat4 m = skinMatrix();\n attr.position = m * attr.position;\n attr.normal = (m * vec4(attr.normal, 0.0)).xyz;\n attr.tangent.xyz = (m * vec4(attr.tangent.xyz, 0.0)).xyz;\n}\n#endif\nvec4 vert () {\n vec4 position;\n position = vec4(a_position, 1.0);\n #if CC_USE_MORPH\n applyMorph(position);\n #endif\n #if CC_USE_SKINNING\n CCSkin(position);\n #endif\n mat4 matWorld;\n #if USE_INSTANCING\n matWorld = mat4(\n vec4(a_matWorld0.xyz, 0.0),\n vec4(a_matWorld1.xyz, 0.0),\n vec4(a_matWorld2.xyz, 0.0),\n vec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)\n );\n #elif USE_BATCHING\n matWorld = cc_matWorlds[int(a_dyn_batch_id)];\n #else\n matWorld = cc_matWorld;\n #endif\n position = cc_matProj * (cc_matView * cc_matLightPlaneProj * matWorld) * position;\n position.z -= 0.0001;\n return position;\n}\nvoid main() { gl_Position = vert(); }`, + "frag": `\nprecision mediump float;\nuniform CCShadow {\n highp mat4 cc_matLightPlaneProj;\n lowp vec4 cc_shadowColor;\n};\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\n}\nvec4 CCFragOutput (vec4 color) {\n #if CC_USE_HDR\n color.rgb = mix(color.rgb, SRGBToLinear(color.rgb) * cc_exposure.w, vec3(cc_exposure.z));\n #endif\n return color;\n}\nvec4 frag () {\n return CCFragOutput(cc_shadowColor);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }` }, "glsl1": { - "vert": `\nprecision highp float;\nstruct StandardVertInput {\n highp vec4 position;\n vec3 normal;\n vec4 tangent;\n};\nattribute vec3 a_position;\n#if CC_USE_MORPH\n attribute float a_vertexId;\n int getVertexId() {\n return int(a_vertexId);\n }\nuniform vec4 cc_displacementWeights[15];\nuniform vec4 cc_displacementTextureInfo;\n vec4 fetchFlatPixel(sampler2D tex, int pixelIndex) {\n float pixelIndexF = float(pixelIndex);\n vec2 textureResolution = vec2(float(cc_displacementTextureInfo.x), float(cc_displacementTextureInfo.y));\n float pixelX = mod(pixelIndexF, textureResolution.x);\n float pixelY = floor(pixelIndexF / textureResolution.x);\n vec2 uv = (vec2(pixelX, pixelY) + .5) / textureResolution;\n return texture2D(tex, uv);\n }\nfloat getDisplacementWeight(int index) {\n float m = mod(float(index), 4.0);\n if (m < 1.0) {\n return cc_displacementWeights[index / 4].x;\n } else if (m < 2.0) {\n return cc_displacementWeights[index / 4].y;\n } else if (m < 3.0) {\n return cc_displacementWeights[index / 4].z;\n } else {\n return cc_displacementWeights[index / 4].w;\n }\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\n return fetchFlatPixel(tex, vertexIndex).rgb;\n#else\n vec3 result = vec3(0, 0, 0);\n for (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\n int dataPixelStart = int(fetchFlatPixel(tex, iTarget).r);\n result += (fetchFlatPixel(tex, dataPixelStart + vertexIndex).rgb * getDisplacementWeight(iTarget));\n }\n return result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\n uniform sampler2D cc_PositionDisplacements;\n vec3 getPositionDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n uniform sampler2D cc_NormalDisplacements;\n vec3 getNormalDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n uniform sampler2D cc_TangentDisplacements;\n vec3 getTangentDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n }\n#endif\nvoid applyMorph (inout StandardVertInput attr) {\n int vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\n attr.position.xyz = attr.position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n attr.normal.xyz = attr.normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n attr.tangent.xyz = attr.tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\n position.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\nattribute vec4 a_weights;\nattribute vec4 a_joints;\n#if CC_USE_BAKED_ANIMATION\n #if USE_INSTANCING\n attribute highp vec4 a_jointAnimInfo;\n #endif\n uniform highp vec4 cc_jointTextureInfo;\n uniform highp vec4 cc_jointAnimInfo;\n uniform sampler2D cc_jointTexture;\n #if !CC_SUPPORT_FLOAT_TEXTURE\n highp float decode32 (highp vec4 rgba) {\n rgba = rgba * 255.0;\n highp float Sign = 1.0 - step(128.0, rgba[3]) * 2.0;\n highp float Exponent = 2.0 * mod(rgba[3], 128.0) + step(128.0, rgba[2]) - 127.0;\n highp float Mantissa = mod(rgba[2], 128.0) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\n }\n #endif\n#else\n uniform highp vec4 cc_joints[90];\n#endif\n#if CC_USE_BAKED_ANIMATION\n #if CC_SUPPORT_FLOAT_TEXTURE\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 3.0 * (a_jointAnimInfo.x * a_jointAnimInfo.y + i) + a_jointAnimInfo.z;\n #else\n highp float j = 3.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y));\n vec4 v2 = texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y));\n vec4 v3 = texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y));\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #else\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 12.0 * (a_jointAnimInfo.x * a_jointAnimInfo.y + i) + a_jointAnimInfo.z;\n #else\n highp float j = 12.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = vec4(\n decode32(texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n );\n vec4 v2 = vec4(\n decode32(texture2D(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n );\n vec4 v3 = vec4(\n decode32(texture2D(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n );\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #endif\n#else\n mat4 getJointMatrix (float i) {\n int idx = int(i);\n vec4 v1 = cc_joints[idx * 3];\n vec4 v2 = cc_joints[idx * 3 + 1];\n vec4 v3 = cc_joints[idx * 3 + 2];\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n#endif\nmat4 skinMatrix () {\n return getJointMatrix(a_joints.x) * a_weights.x\n + getJointMatrix(a_joints.y) * a_weights.y;\n + getJointMatrix(a_joints.z) * a_weights.z;\n + getJointMatrix(a_joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\n mat4 m = skinMatrix();\n position = m * position;\n}\nvoid CCSkin (inout StandardVertInput attr) {\n mat4 m = skinMatrix();\n attr.position = m * attr.position;\n attr.normal = (m * vec4(attr.normal, 0.0)).xyz;\n attr.tangent.xyz = (m * vec4(attr.tangent.xyz, 0.0)).xyz;\n}\n#endif\nuniform highp mat4 cc_matView;\nuniform highp mat4 cc_matProj;\n#if USE_INSTANCING\n attribute vec4 a_matWorld0;\n attribute vec4 a_matWorld1;\n attribute vec4 a_matWorld2;\n#elif USE_BATCHING\n attribute float a_dyn_batch_id;\n uniform highp mat4 cc_matWorlds[10];\n#else\nuniform highp mat4 cc_matWorld;\n#endif\nuniform highp mat4 cc_matLightPlaneProj;\nvec4 vert () {\n vec4 position;\n position = vec4(a_position, 1.0);\n #if CC_USE_MORPH\n applyMorph(position);\n #endif\n #if CC_USE_SKINNING\n CCSkin(position);\n #endif\n mat4 matWorld;\n #if USE_INSTANCING\n matWorld = mat4(\n vec4(a_matWorld0.xyz, 0.0),\n vec4(a_matWorld1.xyz, 0.0),\n vec4(a_matWorld2.xyz, 0.0),\n vec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)\n );\n #elif USE_BATCHING\n matWorld = cc_matWorlds[int(a_dyn_batch_id)];\n #else\n matWorld = cc_matWorld;\n #endif\n position = cc_matProj * (cc_matView * cc_matLightPlaneProj * matWorld) * position;\n position.z -= 0.0001;\n return position;\n}\nvoid main() { gl_Position = vert(); }`, + "vert": `\nprecision highp float;\nuniform highp mat4 cc_matView;\nuniform highp mat4 cc_matProj;\n#if USE_INSTANCING\n attribute vec4 a_matWorld0;\n attribute vec4 a_matWorld1;\n attribute vec4 a_matWorld2;\n#elif USE_BATCHING\n attribute float a_dyn_batch_id;\n uniform highp mat4 cc_matWorlds[10];\n#else\nuniform highp mat4 cc_matWorld;\n#endif\nuniform highp mat4 cc_matLightPlaneProj;\nstruct StandardVertInput {\n highp vec4 position;\n vec3 normal;\n vec4 tangent;\n};\nattribute vec3 a_position;\n#if CC_USE_MORPH\n attribute float a_vertexId;\n int getVertexId() {\n return int(a_vertexId);\n }\nuniform vec4 cc_displacementWeights[15];\nuniform vec4 cc_displacementTextureInfo;\n vec4 fetchFlatPixel(sampler2D tex, int pixelIndex) {\n float pixelIndexF = float(pixelIndex);\n vec2 textureResolution = vec2(float(cc_displacementTextureInfo.x), float(cc_displacementTextureInfo.y));\n float pixelX = mod(pixelIndexF, textureResolution.x);\n float pixelY = floor(pixelIndexF / textureResolution.x);\n vec2 uv = (vec2(pixelX, pixelY) + .5) / textureResolution;\n return texture2D(tex, uv);\n }\nfloat getDisplacementWeight(int index) {\n float m = mod(float(index), 4.0);\n if (m < 1.0) {\n return cc_displacementWeights[index / 4].x;\n } else if (m < 2.0) {\n return cc_displacementWeights[index / 4].y;\n } else if (m < 3.0) {\n return cc_displacementWeights[index / 4].z;\n } else {\n return cc_displacementWeights[index / 4].w;\n }\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\n return fetchFlatPixel(tex, vertexIndex).rgb;\n#else\n vec3 result = vec3(0, 0, 0);\n for (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\n int dataPixelStart = int(fetchFlatPixel(tex, iTarget).r);\n result += (fetchFlatPixel(tex, dataPixelStart + vertexIndex).rgb * getDisplacementWeight(iTarget));\n }\n return result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\n uniform sampler2D cc_PositionDisplacements;\n vec3 getPositionDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n uniform sampler2D cc_NormalDisplacements;\n vec3 getNormalDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n uniform sampler2D cc_TangentDisplacements;\n vec3 getTangentDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n }\n#endif\nvoid applyMorph (inout StandardVertInput attr) {\n int vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\n attr.position.xyz = attr.position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n attr.normal.xyz = attr.normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n attr.tangent.xyz = attr.tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\n position.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\nattribute vec4 a_weights;\nattribute vec4 a_joints;\n#if CC_USE_BAKED_ANIMATION\n #if USE_INSTANCING\n attribute vec4 a_jointAnimInfo;\n #endif\n uniform highp vec4 cc_jointTextureInfo;\n uniform highp vec4 cc_jointAnimInfo;\n uniform sampler2D cc_jointTexture;\n #if !CC_SUPPORT_FLOAT_TEXTURE\n highp float decode32 (highp vec4 rgba) {\n rgba = rgba * 255.0;\n highp float Sign = 1.0 - step(128.0, rgba[3]) * 2.0;\n highp float Exponent = 2.0 * mod(rgba[3], 128.0) + step(128.0, rgba[2]) - 127.0;\n highp float Mantissa = mod(rgba[2], 128.0) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\n }\n #endif\n#else\n uniform highp vec4 cc_joints[90];\n#endif\n#if CC_USE_BAKED_ANIMATION\n #if CC_SUPPORT_FLOAT_TEXTURE\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 3.0 * i + a_jointAnimInfo.x;\n #else\n highp float j = 3.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y));\n vec4 v2 = texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y));\n vec4 v3 = texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y));\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #else\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 12.0 * i + a_jointAnimInfo.x;\n #else\n highp float j = 12.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = vec4(\n decode32(texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n );\n vec4 v2 = vec4(\n decode32(texture2D(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n );\n vec4 v3 = vec4(\n decode32(texture2D(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n );\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #endif\n#else\n mat4 getJointMatrix (float i) {\n int idx = int(i);\n vec4 v1 = cc_joints[idx * 3];\n vec4 v2 = cc_joints[idx * 3 + 1];\n vec4 v3 = cc_joints[idx * 3 + 2];\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n#endif\nmat4 skinMatrix () {\n return getJointMatrix(a_joints.x) * a_weights.x\n + getJointMatrix(a_joints.y) * a_weights.y;\n + getJointMatrix(a_joints.z) * a_weights.z;\n + getJointMatrix(a_joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\n mat4 m = skinMatrix();\n position = m * position;\n}\nvoid CCSkin (inout StandardVertInput attr) {\n mat4 m = skinMatrix();\n attr.position = m * attr.position;\n attr.normal = (m * vec4(attr.normal, 0.0)).xyz;\n attr.tangent.xyz = (m * vec4(attr.tangent.xyz, 0.0)).xyz;\n}\n#endif\nvec4 vert () {\n vec4 position;\n position = vec4(a_position, 1.0);\n #if CC_USE_MORPH\n applyMorph(position);\n #endif\n #if CC_USE_SKINNING\n CCSkin(position);\n #endif\n mat4 matWorld;\n #if USE_INSTANCING\n matWorld = mat4(\n vec4(a_matWorld0.xyz, 0.0),\n vec4(a_matWorld1.xyz, 0.0),\n vec4(a_matWorld2.xyz, 0.0),\n vec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)\n );\n #elif USE_BATCHING\n matWorld = cc_matWorlds[int(a_dyn_batch_id)];\n #else\n matWorld = cc_matWorld;\n #endif\n position = cc_matProj * (cc_matView * cc_matLightPlaneProj * matWorld) * position;\n position.z -= 0.0001;\n return position;\n}\nvoid main() { gl_Position = vert(); }`, "frag": `\nprecision mediump float;\nuniform lowp vec4 cc_shadowColor;\nuniform mediump vec4 cc_exposure;\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\n}\nvec4 CCFragOutput (vec4 color) {\n #if CC_USE_HDR\n color.rgb = mix(color.rgb, SRGBToLinear(color.rgb) * cc_exposure.w, vec3(cc_exposure.z));\n #endif\n return color;\n}\nvec4 frag () {\n return CCFragOutput(cc_shadowColor);\n}\nvoid main() { gl_FragColor = frag(); }` }, "builtins": { "globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }, { "name": "CCShadow", "defines": [] }], "samplers": [] }, - "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"] }], "samplers": [{ "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"] }] } + "locals": { "blocks": [{ "name": "CCLocalBatched", "defines": ["!USE_INSTANCING", "USE_BATCHING"] }, { "name": "CCLocal", "defines": ["!USE_INSTANCING", "!USE_BATCHING"] }, { "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"] }], "samplers": [{ "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"] }] } }, "defines": [ + { "name": "USE_INSTANCING", "type": "boolean" }, + { "name": "USE_BATCHING", "type": "boolean" }, { "name": "CC_USE_MORPH", "type": "boolean" }, - { "name": "CC_MORPH_TARGET_COUNT", "type": "number", "range": [2, 8] }, + { "name": "CC_MORPH_TARGET_COUNT", "type": "number", "dummyDependency": true, "range": [2, 8] }, { "name": "CC_MORPH_PRECOMPUTED", "type": "boolean" }, { "name": "CC_MORPH_TARGET_HAS_POSITION", "type": "boolean" }, { "name": "CC_MORPH_TARGET_HAS_NORMAL", "type": "boolean" }, { "name": "CC_MORPH_TARGET_HAS_TANGENT", "type": "boolean" }, { "name": "CC_USE_SKINNING", "type": "boolean" }, { "name": "CC_USE_BAKED_ANIMATION", "type": "boolean" }, - { "name": "USE_INSTANCING", "type": "boolean" }, { "name": "CC_SUPPORT_FLOAT_TEXTURE", "type": "boolean" }, - { "name": "USE_BATCHING", "type": "boolean" }, { "name": "CC_USE_HDR", "type": "boolean" } ], "blocks": [], "samplers": [], "attributes": [ + { "name": "a_matWorld0", "type": 16, "count": 1, "defines": ["USE_INSTANCING"], "format": 43, "isInstanced": true, "location": 4 }, + { "name": "a_matWorld1", "type": 16, "count": 1, "defines": ["USE_INSTANCING"], "format": 43, "isInstanced": true, "location": 1 }, + { "name": "a_matWorld2", "type": 16, "count": 1, "defines": ["USE_INSTANCING"], "format": 43, "isInstanced": true, "location": 2 }, + { "name": "a_dyn_batch_id", "type": 13, "count": 1, "defines": ["!USE_INSTANCING", "USE_BATCHING"], "format": 11, "location": 3 }, { "name": "a_position", "type": 15, "count": 1, "defines": [], "format": 32, "location": 0 }, - { "name": "a_vertexId", "type": 13, "count": 1, "defines": ["CC_USE_MORPH"], "format": 11, "location": 1 }, - { "name": "a_weights", "type": 16, "count": 1, "defines": ["CC_USE_SKINNING"], "format": 43, "location": 2 }, - { "name": "a_joints", "type": 16, "count": 1, "defines": ["CC_USE_SKINNING"], "format": 43, "location": 3 }, - { "name": "a_jointAnimInfo", "type": 16, "count": 1, "precision": "highp ", "defines": ["CC_USE_SKINNING", "CC_USE_BAKED_ANIMATION", "USE_INSTANCING"], "format": 43, "isInstanced": true, "location": 4 }, - { "name": "a_matWorld0", "type": 16, "count": 1, "defines": ["USE_INSTANCING"], "format": 43, "isInstanced": true, "location": 5 }, - { "name": "a_matWorld1", "type": 16, "count": 1, "defines": ["USE_INSTANCING"], "format": 43, "isInstanced": true, "location": 6 }, - { "name": "a_matWorld2", "type": 16, "count": 1, "defines": ["USE_INSTANCING"], "format": 43, "isInstanced": true, "location": 7 }, - { "name": "a_dyn_batch_id", "type": 13, "count": 1, "defines": ["!USE_INSTANCING", "USE_BATCHING"], "format": 11, "location": 8 } + { "name": "a_vertexId", "type": 13, "count": 1, "defines": ["CC_USE_MORPH"], "format": 11, "location": 5 }, + { "name": "a_weights", "type": 16, "count": 1, "defines": ["CC_USE_SKINNING"], "format": 43, "location": 6 }, + { "name": "a_joints", "type": 16, "count": 1, "defines": ["CC_USE_SKINNING"], "format": 43, "location": 7 }, + { "name": "a_jointAnimInfo", "type": 16, "count": 1, "defines": ["CC_USE_SKINNING", "CC_USE_BAKED_ANIMATION", "USE_INSTANCING"], "format": 43, "isInstanced": true, "location": 8 } ] } ] @@ -573,7 +578,7 @@ export default [ "locals": { "blocks": [], "samplers": [] } }, "defines": [ - { "name": "CC_USE_IBL", "type": "number", "range": [0, 2] }, + { "name": "CC_USE_IBL", "type": "number", "dummyDependency": true, "range": [0, 2] }, { "name": "CC_USE_HDR", "type": "boolean" }, { "name": "USE_RGBE_CUBEMAP", "type": "boolean" } ], @@ -619,7 +624,7 @@ export default [ ]} ], "samplers": [ - { "name": "mainTexture", "type": 28, "count": 1, "defines": [], "binding": 30 } + { "name": "mainTexture", "type": 28, "count": 1, "defines": [], "binding": 31 } ], "attributes": [ { "name": "a_position", "type": 15, "count": 1, "defines": [], "format": 32, "location": 0 }, diff --git a/cocos/core/3d/builtin/init.ts b/cocos/core/3d/builtin/init.ts index d5c59b932b..9a973c328d 100644 --- a/cocos/core/3d/builtin/init.ts +++ b/cocos/core/3d/builtin/init.ts @@ -31,6 +31,19 @@ class BuiltinResMgr { blackTexture.image = imgAsset; resources[blackTexture._uuid] = blackTexture; + // empty texture + context.fillStyle = 'rgba(0,0,0,0)'; + context.fillRect(0, 0, l, l); + const emptyBuffer = new Uint8Array(4 * 4); + for (let i = 0; i < emptyBuffer.length; ++i) { + emptyBuffer[i] = 0; + } + const emptyTexture = new Texture2D(); + emptyTexture._uuid = 'empty-texture'; + emptyTexture.image = imgAsset; + emptyTexture.uploadData(emptyBuffer); + resources[emptyTexture._uuid] = emptyTexture; + // black texture const blackCubeTexture = new TextureCube(); blackCubeTexture._uuid = 'black-cube-texture'; diff --git a/cocos/core/3d/framework/light-component.ts b/cocos/core/3d/framework/light-component.ts index 9ce13de03c..cdc83b8432 100644 --- a/cocos/core/3d/framework/light-component.ts +++ b/cocos/core/3d/framework/light-component.ts @@ -43,12 +43,57 @@ export const PhotometricTerm = Enum({ LUMINANCE: 1, }); -export enum LightBakeType { - NONE, - BAKE_ONLY, - BAKEABLE, +/** + * @en static light settings. + * @zh 静态灯光设置 + */ +@ccclass('cc.ModelLightmapSettings') +class StaticLightSettings { + @property + protected _editorOnly: boolean = false; + @property + protected _bakeable: boolean = false; + @property + protected _castShadow: boolean = false; + + /** + * @en editor only. + * @zh 是否只在编辑器里生效。 + */ + @property + get editorOnly () { + return this._editorOnly; + } + set editorOnly (val) { + this._editorOnly = val; + } + + /** + * @en bakeable. + * @zh 是否可烘培。 + */ + @property + get bakeable () { + return this._bakeable; + } + + set bakeable (val) { + this._bakeable = val; + } + + /** + * @en cast shadow. + * @zh 是否投射阴影。 + */ + @property + get castShadow () { + return this._castShadow; + } + + set castShadow (val) { + this._castShadow = val; + } } -Enum(LightBakeType); // tslint:disable: no-shadowed-variable export namespace LightComponent { @@ -69,29 +114,12 @@ export class LightComponent extends Component { @property protected _colorTemperature = 6550; @property - protected _bakeType = LightBakeType.NONE; + protected _staticSettings: StaticLightSettings = new StaticLightSettings(); protected _type = LightType.UNKNOWN; protected _lightType: typeof Light; protected _light: Light | null = null; - /** - * @en - * Bake type. - * @zh - * 烘培类型。 - */ - @property({ - type: LightBakeType, - }) - get bakeType () { - return this._bakeType; - } - - set bakeType (val) { - this._bakeType = val; - } - /** * @en * Color of the light. @@ -151,6 +179,23 @@ export class LightComponent extends Component { if (this._light) { this._light.colorTemperature = val; } } + /** + * @en + * static light setttings. + * @zh + * 静态灯光设置。 + */ + @property({ + type: StaticLightSettings, + }) + get staticSettings () { + return this._staticSettings; + } + + set staticSettings (val) { + this._staticSettings = val; + } + /** * @en * The light type. diff --git a/cocos/core/3d/framework/model-component.ts b/cocos/core/3d/framework/model-component.ts index 7a81a6b5c8..93ed279e19 100644 --- a/cocos/core/3d/framework/model-component.ts +++ b/cocos/core/3d/framework/model-component.ts @@ -127,6 +127,7 @@ class ModelLightmapSettings { * @en lightmap size. * @zh 光照图大小 */ + @property get lightmapSize () { return this._lightmapSize; } @@ -293,6 +294,10 @@ export class ModelComponent extends RenderableComponent { this.lightmapSettings.uvParam.y = vOff; this.lightmapSettings.uvParam.z = uScale; this.lightmapSettings.uvParam.w = vScale; + + if (this.model !== null) { + this.model.updateLightingmap(this.lightmapSettings.texture, this.lightmapSettings.uvParam); + } } protected _updateModels () { @@ -308,6 +313,10 @@ export class ModelComponent extends RenderableComponent { } this._updateModelParams(); + + if (this.model != null) { + this.model.updateLightingmap(this.lightmapSettings.texture, this.lightmapSettings.uvParam); + } } protected _createModel () { @@ -376,6 +385,7 @@ export class ModelComponent extends RenderableComponent { if (!this._model || !this._model.inited) { return; } this._model.isDynamicBatching = this._isBatchingEnabled(); this._model.setSubModelMaterial(idx, material); + this._model.updateLightingmap(this.lightmapSettings.texture, this.lightmapSettings.uvParam); } protected _onMeshChanged (old: Mesh | null) { diff --git a/cocos/core/pipeline/define.ts b/cocos/core/pipeline/define.ts index 3068103ff7..c68b7ddc8e 100644 --- a/cocos/core/pipeline/define.ts +++ b/cocos/core/pipeline/define.ts @@ -100,11 +100,12 @@ export enum UniformBinding { SAMPLER_MORPH_POSITION = MAX_BINDING_SUPPORTED + 3, SAMPLER_MORPH_NORMAL = MAX_BINDING_SUPPORTED + 4, SAMPLER_MORPH_TANGENT = MAX_BINDING_SUPPORTED + 5, + SAMPLER_LIGHTING_MAP = MAX_BINDING_SUPPORTED + 6, // rooms left for custom bindings // effect importer prepares bindings according to this CUSTUM_UBO_BINDING_END_POINT = UniformBinding.UBO_BUILTIN_BINDING_END, - CUSTOM_SAMPLER_BINDING_START_POINT = MAX_BINDING_SUPPORTED + 6, + CUSTOM_SAMPLER_BINDING_START_POINT = MAX_BINDING_SUPPORTED + 7, } export const isBuiltinBinding = (binding: number) => @@ -192,13 +193,15 @@ export const localBindingsDesc: Map = new Map = { + binding: UniformBinding.SAMPLER_LIGHTING_MAP, name: 'cc_lightingMap', type: GFXType.SAMPLER2D, count: 1, +}; +localBindingsDesc.set(UniformLightingMapSampler.name, { + type: GFXBindingType.SAMPLER, + samplerInfo: UniformLightingMapSampler, +}); + /** * 切线形变纹理采样器。 */ diff --git a/cocos/core/renderer/scene/model.ts b/cocos/core/renderer/scene/model.ts index d9eb7d0257..7e254db2d3 100644 --- a/cocos/core/renderer/scene/model.ts +++ b/cocos/core/renderer/scene/model.ts @@ -1,19 +1,23 @@ // Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. +import { builtinResMgr } from '../../3d/builtin/init'; import { Material } from '../../assets/material'; import { RenderingSubMesh } from '../../assets/mesh'; import { aabb } from '../../geometry'; import { GFXBuffer } from '../../gfx/buffer'; -import { getTypedArrayConstructor, GFXBufferUsageBit, GFXFormat, GFXFormatInfos, GFXMemoryUsageBit } from '../../gfx/define'; +import { getTypedArrayConstructor, GFXBufferUsageBit, GFXFormat, GFXFormatInfos, GFXMemoryUsageBit, GFXFilter, GFXAddress } from '../../gfx/define'; import { GFXDevice, GFXFeature } from '../../gfx/device'; import { GFXPipelineState } from '../../gfx/pipeline-state'; -import { Mat4, Vec3 } from '../../math'; +import { Mat4, Vec3, Vec4} from '../../math'; import { Pool } from '../../memop'; -import { INST_MAT_WORLD, UBOForwardLight, UBOLocal } from '../../pipeline/define'; +import { INST_MAT_WORLD, UBOForwardLight, UBOLocal, UniformBinding, UniformLightingMapSampler } from '../../pipeline/define'; import { Node } from '../../scene-graph'; import { Layers } from '../../scene-graph/layers'; import { IMacroPatch, Pass } from '../core/pass'; import { RenderScene } from './render-scene'; import { SubModel } from './submodel'; +import { Texture2D } from '../../assets/texture-2d'; +import { genSamplerHash, samplerLib} from '../../renderer/core/sampler-lib'; +import { GFXSampler } from '../../gfx'; import { programLib } from '../core/program-lib'; const m4_1 = new Mat4(); @@ -174,6 +178,55 @@ export class Model { } } + public updateLightingmap (tex: Texture2D|null, uvParam: Vec4) { + Vec4.toArray(this._localData, uvParam, UBOLocal.LIGHTINGMAP_UVPARAM); + + if (tex === null) { + tex = builtinResMgr.get('empty-texture'); + } + + const texture = tex; + const textureView = texture.getGFXTextureView(); + + if (textureView !== null) { + let sampler: GFXSampler; + if (tex.mipmaps.length > 1) { + const samplerHash = genSamplerHash([ + GFXFilter.LINEAR, + GFXFilter.LINEAR, + GFXFilter.LINEAR, + GFXAddress.CLAMP, + GFXAddress.CLAMP, + GFXAddress.CLAMP, + ]); + sampler = samplerLib.getSampler(this._device, samplerHash); + } + else { + const samplerHash = genSamplerHash([ + GFXFilter.NONE, + GFXFilter.NONE, + GFXFilter.NONE, + GFXAddress.CLAMP, + GFXAddress.CLAMP, + GFXAddress.CLAMP, + ]); + sampler = samplerLib.getSampler(this._device, samplerHash); + } + + for (const sub of this._subModels) { + if (sub.psos === null) { + continue; + } + + for (let i = 0; i < sub.psos.length; i++) { + sub.psos[i].pipelineLayout.layouts[0].bindTextureView(UniformLightingMapSampler.binding, textureView); + sub.psos[i].pipelineLayout.layouts[0].bindSampler(UniformLightingMapSampler.binding, sampler); + sub.psos[i].pipelineLayout.layouts[0].update(); + } + } + } + } + public updateUBOs (stamp: number) { this._matPSORecord.forEach(this._updatePass, this); this._updateStamp = stamp; From afa9418ba244d89306232cb3a2b496ddc9ee0311 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Fri, 12 Jun 2020 15:33:02 +0800 Subject: [PATCH 20/28] Update effects --- cocos/core/3d/builtin/effects.ts | 158 ++++++++++----------- cocos/core/3d/framework/light-component.ts | 2 +- 2 files changed, 78 insertions(+), 82 deletions(-) diff --git a/cocos/core/3d/builtin/effects.ts b/cocos/core/3d/builtin/effects.ts index 01f987c28c..d53e8dae68 100644 --- a/cocos/core/3d/builtin/effects.ts +++ b/cocos/core/3d/builtin/effects.ts @@ -12,8 +12,8 @@ export default [ "name": "builtin-billboard|vert:vs_main|tinted-fs:add", "hash": 3052980566, "glsl3": { - "vert": `\nprecision mediump float;\nuniform Constants {\n vec4 mainTiling_Offset;\n vec4 frameTile_velLenScale;\n vec4 scale;\n};\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\nuniform CCLocal {\n highp mat4 cc_matWorld;\n highp mat4 cc_matWorldIT;\n highp vec4 cc_lightingMapUVParam;\n};\nvec4 quaternionFromAxis (vec3 xAxis,vec3 yAxis,vec3 zAxis){\n mat3 m = mat3(xAxis,yAxis,zAxis);\n float trace = m[0][0] + m[1][1] + m[2][2];\n vec4 quat;\n if (trace > 0.) {\n float s = 0.5 / sqrt(trace + 1.0);\n quat.w = 0.25 / s;\n quat.x = (m[2][1] - m[1][2]) * s;\n quat.y = (m[0][2] - m[2][0]) * s;\n quat.z = (m[1][0] - m[0][1]) * s;\n } else if ((m[0][0] > m[1][1]) && (m[0][0] > m[2][2])) {\n float s = 2.0 * sqrt(1.0 + m[0][0] - m[1][1] - m[2][2]);\n quat.w = (m[2][1] - m[1][2]) / s;\n quat.x = 0.25 * s;\n quat.y = (m[0][1] + m[1][0]) / s;\n quat.z = (m[0][2] + m[2][0]) / s;\n } else if (m[1][1] > m[2][2]) {\n float s = 2.0 * sqrt(1.0 + m[1][1] - m[0][0] - m[2][2]);\n quat.w = (m[0][2] - m[2][0]) / s;\n quat.x = (m[0][1] + m[1][0]) / s;\n quat.y = 0.25 * s;\n quat.z = (m[1][2] + m[2][1]) / s;\n } else {\n float s = 2.0 * sqrt(1.0 + m[2][2] - m[0][0] - m[1][1]);\n quat.w = (m[1][0] - m[0][1]) / s;\n quat.x = (m[0][2] + m[2][0]) / s;\n quat.y = (m[1][2] + m[2][1]) / s;\n quat.z = 0.25 * s;\n }\n float len = quat.x * quat.x + quat.y * quat.y + quat.z * quat.z + quat.w * quat.w;\n if (len > 0.) {\n len = 1. / sqrt(len);\n quat.x = quat.x * len;\n quat.y = quat.y * len;\n quat.z = quat.z * len;\n quat.w = quat.w * len;\n }\n return quat;\n}\nvec4 quaternionFromEuler (vec3 angle){\n float x = angle.x / 2.;\n float y = angle.y / 2.;\n float z = angle.z / 2.;\n float sx = sin(x);\n float cx = cos(x);\n float sy = sin(y);\n float cy = cos(y);\n float sz = sin(z);\n float cz = cos(z);\n vec4 quat = vec4(0);\n quat.x = sx * cy * cz + cx * sy * sz;\n quat.y = cx * sy * cz + sx * cy * sz;\n quat.z = cx * cy * sz - sx * sy * cz;\n quat.w = cx * cy * cz - sx * sy * sz;\n return quat;\n}\nvec4 quatMultiply (vec4 a, vec4 b){\n vec4 quat;\n quat.x = a.x * b.w + a.w * b.x + a.y * b.z - a.z * b.y;\n quat.y = a.y * b.w + a.w * b.y + a.z * b.x - a.x * b.z;\n quat.z = a.z * b.w + a.w * b.z + a.x * b.y - a.y * b.x;\n quat.w = a.w * b.w - a.x * b.x - a.y * b.y - a.z * b.z;\n return quat;\n}\nvoid rotateVecFromQuat (inout vec3 v, vec4 q){\n float ix = q.w * v.x + q.y * v.z - q.z * v.y;\n float iy = q.w * v.y + q.z * v.x - q.x * v.z;\n float iz = q.w * v.z + q.x * v.y - q.y * v.x;\n float iw = -q.x * v.x - q.y * v.y - q.z * v.z;\n v.x = ix * q.w + iw * -q.x + iy * -q.z - iz * -q.y;\n v.y = iy * q.w + iw * -q.y + iz * -q.x - ix * -q.z;\n v.z = iz * q.w + iw * -q.z + ix * -q.y - iy * -q.x;\n}\nvec3 rotateInLocalSpace (vec3 pos, vec3 xAxis, vec3 yAxis, vec3 zAxis, vec4 q){\n vec4 viewQuat = quaternionFromAxis(xAxis, yAxis, zAxis);\n vec4 rotQuat = quatMultiply(viewQuat, q);\n rotateVecFromQuat(pos, rotQuat);\n return pos;\n}\nvoid rotateCorner (inout vec2 corner, float angle){\n float xOS = cos(angle) * corner.x - sin(angle) * corner.y;\n float yOS = sin(angle) * corner.x + cos(angle) * corner.y;\n corner.x = xOS;\n corner.y = yOS;\n}\nout vec2 uv;\nout vec4 color;\nvoid computeVertPos (inout vec4 pos, vec2 vertOffset, vec4 q, vec3 s\n , mat4 viewInv\n) {\n vec3 viewSpaceVert = vec3(vertOffset.x * s.x, vertOffset.y * s.y, 0.);\n vec3 camX = normalize(vec3(viewInv[0][0], viewInv[1][0], viewInv[2][0]));\n vec3 camY = normalize(vec3(viewInv[0][1], viewInv[1][1], viewInv[2][1]));\n vec3 camZ = normalize(vec3(viewInv[0][2], viewInv[1][2], viewInv[2][2]));\n pos.xyz += rotateInLocalSpace(viewSpaceVert, camX, camY, camZ, q);\n}\nin vec3 a_position;\nin vec2 a_texCoord;\nin vec4 a_color;\nuniform builtin {\n vec4 cc_size_rotation;\n};\nvec4 vs_main() {\n vec4 pos = vec4(a_position, 1);\n pos = cc_matWorld * pos;\n vec2 vertOffset = a_texCoord.xy - 0.5;\n computeVertPos(pos, vertOffset, quaternionFromEuler(vec3(0., 0., cc_size_rotation.z)), vec3(cc_size_rotation.xy, 0.), cc_matViewInv);\n pos = cc_matViewProj * pos;\n uv = a_texCoord.xy;\n color = a_color;\n return pos;\n}\nvoid main() { gl_Position = vs_main(); }`, - "frag": `\nprecision mediump float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\n}\nvec4 CCFragOutput (vec4 color) {\n #if CC_USE_HDR\n color.rgb = mix(color.rgb, SRGBToLinear(color.rgb) * cc_exposure.w, vec3(cc_exposure.z));\n #endif\n return color;\n}\nin vec2 uv;\nin vec4 color;\nuniform sampler2D mainTexture;\nuniform FragConstants {\n vec4 tintColor;\n};\nvec4 add () {\n vec4 col = 2.0 * color * tintColor * texture(mainTexture, uv);\n return CCFragOutput(col);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = add(); }` + "vert": `\nprecision mediump float;\nuniform Constants {\n vec4 mainTiling_Offset;\n vec4 frameTile_velLenScale;\n vec4 scale;\n};\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n};\nuniform CCLocal {\n highp mat4 cc_matWorld;\n highp mat4 cc_matWorldIT;\n highp vec4 cc_lightingMapUVParam;\n};\nvec4 quaternionFromAxis (vec3 xAxis,vec3 yAxis,vec3 zAxis){\n mat3 m = mat3(xAxis,yAxis,zAxis);\n float trace = m[0][0] + m[1][1] + m[2][2];\n vec4 quat;\n if (trace > 0.) {\n float s = 0.5 / sqrt(trace + 1.0);\n quat.w = 0.25 / s;\n quat.x = (m[2][1] - m[1][2]) * s;\n quat.y = (m[0][2] - m[2][0]) * s;\n quat.z = (m[1][0] - m[0][1]) * s;\n } else if ((m[0][0] > m[1][1]) && (m[0][0] > m[2][2])) {\n float s = 2.0 * sqrt(1.0 + m[0][0] - m[1][1] - m[2][2]);\n quat.w = (m[2][1] - m[1][2]) / s;\n quat.x = 0.25 * s;\n quat.y = (m[0][1] + m[1][0]) / s;\n quat.z = (m[0][2] + m[2][0]) / s;\n } else if (m[1][1] > m[2][2]) {\n float s = 2.0 * sqrt(1.0 + m[1][1] - m[0][0] - m[2][2]);\n quat.w = (m[0][2] - m[2][0]) / s;\n quat.x = (m[0][1] + m[1][0]) / s;\n quat.y = 0.25 * s;\n quat.z = (m[1][2] + m[2][1]) / s;\n } else {\n float s = 2.0 * sqrt(1.0 + m[2][2] - m[0][0] - m[1][1]);\n quat.w = (m[1][0] - m[0][1]) / s;\n quat.x = (m[0][2] + m[2][0]) / s;\n quat.y = (m[1][2] + m[2][1]) / s;\n quat.z = 0.25 * s;\n }\n float len = quat.x * quat.x + quat.y * quat.y + quat.z * quat.z + quat.w * quat.w;\n if (len > 0.) {\n len = 1. / sqrt(len);\n quat.x = quat.x * len;\n quat.y = quat.y * len;\n quat.z = quat.z * len;\n quat.w = quat.w * len;\n }\n return quat;\n}\nvec4 quaternionFromEuler (vec3 angle){\n float x = angle.x / 2.;\n float y = angle.y / 2.;\n float z = angle.z / 2.;\n float sx = sin(x);\n float cx = cos(x);\n float sy = sin(y);\n float cy = cos(y);\n float sz = sin(z);\n float cz = cos(z);\n vec4 quat = vec4(0);\n quat.x = sx * cy * cz + cx * sy * sz;\n quat.y = cx * sy * cz + sx * cy * sz;\n quat.z = cx * cy * sz - sx * sy * cz;\n quat.w = cx * cy * cz - sx * sy * sz;\n return quat;\n}\nvec4 quatMultiply (vec4 a, vec4 b){\n vec4 quat;\n quat.x = a.x * b.w + a.w * b.x + a.y * b.z - a.z * b.y;\n quat.y = a.y * b.w + a.w * b.y + a.z * b.x - a.x * b.z;\n quat.z = a.z * b.w + a.w * b.z + a.x * b.y - a.y * b.x;\n quat.w = a.w * b.w - a.x * b.x - a.y * b.y - a.z * b.z;\n return quat;\n}\nvoid rotateVecFromQuat (inout vec3 v, vec4 q){\n float ix = q.w * v.x + q.y * v.z - q.z * v.y;\n float iy = q.w * v.y + q.z * v.x - q.x * v.z;\n float iz = q.w * v.z + q.x * v.y - q.y * v.x;\n float iw = -q.x * v.x - q.y * v.y - q.z * v.z;\n v.x = ix * q.w + iw * -q.x + iy * -q.z - iz * -q.y;\n v.y = iy * q.w + iw * -q.y + iz * -q.x - ix * -q.z;\n v.z = iz * q.w + iw * -q.z + ix * -q.y - iy * -q.x;\n}\nvec3 rotateInLocalSpace (vec3 pos, vec3 xAxis, vec3 yAxis, vec3 zAxis, vec4 q){\n vec4 viewQuat = quaternionFromAxis(xAxis, yAxis, zAxis);\n vec4 rotQuat = quatMultiply(viewQuat, q);\n rotateVecFromQuat(pos, rotQuat);\n return pos;\n}\nvoid rotateCorner (inout vec2 corner, float angle){\n float xOS = cos(angle) * corner.x - sin(angle) * corner.y;\n float yOS = sin(angle) * corner.x + cos(angle) * corner.y;\n corner.x = xOS;\n corner.y = yOS;\n}\nout vec2 uv;\nout vec4 color;\nvoid computeVertPos (inout vec4 pos, vec2 vertOffset, vec4 q, vec3 s\n , mat4 viewInv\n) {\n vec3 viewSpaceVert = vec3(vertOffset.x * s.x, vertOffset.y * s.y, 0.);\n vec3 camX = normalize(vec3(viewInv[0][0], viewInv[1][0], viewInv[2][0]));\n vec3 camY = normalize(vec3(viewInv[0][1], viewInv[1][1], viewInv[2][1]));\n vec3 camZ = normalize(vec3(viewInv[0][2], viewInv[1][2], viewInv[2][2]));\n pos.xyz += rotateInLocalSpace(viewSpaceVert, camX, camY, camZ, q);\n}\nin vec3 a_position;\nin vec2 a_texCoord;\nin vec4 a_color;\nuniform builtin {\n vec4 cc_size_rotation;\n};\nvec4 vs_main() {\n vec4 pos = vec4(a_position, 1);\n pos = cc_matWorld * pos;\n vec2 vertOffset = a_texCoord.xy - 0.5;\n computeVertPos(pos, vertOffset, quaternionFromEuler(vec3(0., 0., cc_size_rotation.z)), vec3(cc_size_rotation.xy, 0.), cc_matViewInv);\n pos = cc_matViewProj * pos;\n uv = a_texCoord.xy;\n color = a_color;\n return pos;\n}\nvoid main() { gl_Position = vs_main(); }`, + "frag": `\nprecision mediump float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n};\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\n}\nvec4 CCFragOutput (vec4 color) {\n #if CC_USE_HDR\n color.rgb = mix(color.rgb, SRGBToLinear(color.rgb) * cc_exposure.w, vec3(cc_exposure.z));\n #endif\n return color;\n}\nin vec2 uv;\nin vec4 color;\nuniform sampler2D mainTexture;\nuniform FragConstants {\n vec4 tintColor;\n};\nvec4 add () {\n vec4 col = 2.0 * color * tintColor * texture(mainTexture, uv);\n return CCFragOutput(col);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = add(); }` }, "glsl1": { "vert": `\nprecision mediump float;\nuniform highp mat4 cc_matView;\nuniform highp mat4 cc_matViewInv;\nuniform highp mat4 cc_matViewProj;\nuniform highp mat4 cc_matWorld;\nvec4 quaternionFromAxis (vec3 xAxis,vec3 yAxis,vec3 zAxis){\n mat3 m = mat3(xAxis,yAxis,zAxis);\n float trace = m[0][0] + m[1][1] + m[2][2];\n vec4 quat;\n if (trace > 0.) {\n float s = 0.5 / sqrt(trace + 1.0);\n quat.w = 0.25 / s;\n quat.x = (m[2][1] - m[1][2]) * s;\n quat.y = (m[0][2] - m[2][0]) * s;\n quat.z = (m[1][0] - m[0][1]) * s;\n } else if ((m[0][0] > m[1][1]) && (m[0][0] > m[2][2])) {\n float s = 2.0 * sqrt(1.0 + m[0][0] - m[1][1] - m[2][2]);\n quat.w = (m[2][1] - m[1][2]) / s;\n quat.x = 0.25 * s;\n quat.y = (m[0][1] + m[1][0]) / s;\n quat.z = (m[0][2] + m[2][0]) / s;\n } else if (m[1][1] > m[2][2]) {\n float s = 2.0 * sqrt(1.0 + m[1][1] - m[0][0] - m[2][2]);\n quat.w = (m[0][2] - m[2][0]) / s;\n quat.x = (m[0][1] + m[1][0]) / s;\n quat.y = 0.25 * s;\n quat.z = (m[1][2] + m[2][1]) / s;\n } else {\n float s = 2.0 * sqrt(1.0 + m[2][2] - m[0][0] - m[1][1]);\n quat.w = (m[1][0] - m[0][1]) / s;\n quat.x = (m[0][2] + m[2][0]) / s;\n quat.y = (m[1][2] + m[2][1]) / s;\n quat.z = 0.25 * s;\n }\n float len = quat.x * quat.x + quat.y * quat.y + quat.z * quat.z + quat.w * quat.w;\n if (len > 0.) {\n len = 1. / sqrt(len);\n quat.x = quat.x * len;\n quat.y = quat.y * len;\n quat.z = quat.z * len;\n quat.w = quat.w * len;\n }\n return quat;\n}\nvec4 quaternionFromEuler (vec3 angle){\n float x = angle.x / 2.;\n float y = angle.y / 2.;\n float z = angle.z / 2.;\n float sx = sin(x);\n float cx = cos(x);\n float sy = sin(y);\n float cy = cos(y);\n float sz = sin(z);\n float cz = cos(z);\n vec4 quat = vec4(0);\n quat.x = sx * cy * cz + cx * sy * sz;\n quat.y = cx * sy * cz + sx * cy * sz;\n quat.z = cx * cy * sz - sx * sy * cz;\n quat.w = cx * cy * cz - sx * sy * sz;\n return quat;\n}\nvec4 quatMultiply (vec4 a, vec4 b){\n vec4 quat;\n quat.x = a.x * b.w + a.w * b.x + a.y * b.z - a.z * b.y;\n quat.y = a.y * b.w + a.w * b.y + a.z * b.x - a.x * b.z;\n quat.z = a.z * b.w + a.w * b.z + a.x * b.y - a.y * b.x;\n quat.w = a.w * b.w - a.x * b.x - a.y * b.y - a.z * b.z;\n return quat;\n}\nvoid rotateVecFromQuat (inout vec3 v, vec4 q){\n float ix = q.w * v.x + q.y * v.z - q.z * v.y;\n float iy = q.w * v.y + q.z * v.x - q.x * v.z;\n float iz = q.w * v.z + q.x * v.y - q.y * v.x;\n float iw = -q.x * v.x - q.y * v.y - q.z * v.z;\n v.x = ix * q.w + iw * -q.x + iy * -q.z - iz * -q.y;\n v.y = iy * q.w + iw * -q.y + iz * -q.x - ix * -q.z;\n v.z = iz * q.w + iw * -q.z + ix * -q.y - iy * -q.x;\n}\nvec3 rotateInLocalSpace (vec3 pos, vec3 xAxis, vec3 yAxis, vec3 zAxis, vec4 q){\n vec4 viewQuat = quaternionFromAxis(xAxis, yAxis, zAxis);\n vec4 rotQuat = quatMultiply(viewQuat, q);\n rotateVecFromQuat(pos, rotQuat);\n return pos;\n}\nvoid rotateCorner (inout vec2 corner, float angle){\n float xOS = cos(angle) * corner.x - sin(angle) * corner.y;\n float yOS = sin(angle) * corner.x + cos(angle) * corner.y;\n corner.x = xOS;\n corner.y = yOS;\n}\nvarying vec2 uv;\nvarying vec4 color;\nvoid computeVertPos (inout vec4 pos, vec2 vertOffset, vec4 q, vec3 s\n , mat4 viewInv\n) {\n vec3 viewSpaceVert = vec3(vertOffset.x * s.x, vertOffset.y * s.y, 0.);\n vec3 camX = normalize(vec3(viewInv[0][0], viewInv[1][0], viewInv[2][0]));\n vec3 camY = normalize(vec3(viewInv[0][1], viewInv[1][1], viewInv[2][1]));\n vec3 camZ = normalize(vec3(viewInv[0][2], viewInv[1][2], viewInv[2][2]));\n pos.xyz += rotateInLocalSpace(viewSpaceVert, camX, camY, camZ, q);\n}\nattribute vec3 a_position;\nattribute vec2 a_texCoord;\nattribute vec4 a_color;\nuniform vec4 cc_size_rotation;\nvec4 vs_main() {\n vec4 pos = vec4(a_position, 1);\n pos = cc_matWorld * pos;\n vec2 vertOffset = a_texCoord.xy - 0.5;\n computeVertPos(pos, vertOffset, quaternionFromEuler(vec3(0., 0., cc_size_rotation.z)), vec3(cc_size_rotation.xy, 0.), cc_matViewInv);\n pos = cc_matViewProj * pos;\n uv = a_texCoord.xy;\n color = a_color;\n return pos;\n}\nvoid main() { gl_Position = vs_main(); }`, @@ -61,8 +61,8 @@ export default [ "name": "builtin-particle-gpu|particle-vs-gpu:gpvs_main|tinted-fs:add", "hash": 4003605751, "glsl3": { - "vert": `\nprecision mediump float;\nvec4 quaternionFromAxis (vec3 xAxis,vec3 yAxis,vec3 zAxis){\n mat3 m = mat3(xAxis,yAxis,zAxis);\n float trace = m[0][0] + m[1][1] + m[2][2];\n vec4 quat;\n if (trace > 0.) {\n float s = 0.5 / sqrt(trace + 1.0);\n quat.w = 0.25 / s;\n quat.x = (m[2][1] - m[1][2]) * s;\n quat.y = (m[0][2] - m[2][0]) * s;\n quat.z = (m[1][0] - m[0][1]) * s;\n } else if ((m[0][0] > m[1][1]) && (m[0][0] > m[2][2])) {\n float s = 2.0 * sqrt(1.0 + m[0][0] - m[1][1] - m[2][2]);\n quat.w = (m[2][1] - m[1][2]) / s;\n quat.x = 0.25 * s;\n quat.y = (m[0][1] + m[1][0]) / s;\n quat.z = (m[0][2] + m[2][0]) / s;\n } else if (m[1][1] > m[2][2]) {\n float s = 2.0 * sqrt(1.0 + m[1][1] - m[0][0] - m[2][2]);\n quat.w = (m[0][2] - m[2][0]) / s;\n quat.x = (m[0][1] + m[1][0]) / s;\n quat.y = 0.25 * s;\n quat.z = (m[1][2] + m[2][1]) / s;\n } else {\n float s = 2.0 * sqrt(1.0 + m[2][2] - m[0][0] - m[1][1]);\n quat.w = (m[1][0] - m[0][1]) / s;\n quat.x = (m[0][2] + m[2][0]) / s;\n quat.y = (m[1][2] + m[2][1]) / s;\n quat.z = 0.25 * s;\n }\n float len = quat.x * quat.x + quat.y * quat.y + quat.z * quat.z + quat.w * quat.w;\n if (len > 0.) {\n len = 1. / sqrt(len);\n quat.x = quat.x * len;\n quat.y = quat.y * len;\n quat.z = quat.z * len;\n quat.w = quat.w * len;\n }\n return quat;\n}\nvec4 quaternionFromEuler (vec3 angle){\n float x = angle.x / 2.;\n float y = angle.y / 2.;\n float z = angle.z / 2.;\n float sx = sin(x);\n float cx = cos(x);\n float sy = sin(y);\n float cy = cos(y);\n float sz = sin(z);\n float cz = cos(z);\n vec4 quat = vec4(0);\n quat.x = sx * cy * cz + cx * sy * sz;\n quat.y = cx * sy * cz + sx * cy * sz;\n quat.z = cx * cy * sz - sx * sy * cz;\n quat.w = cx * cy * cz - sx * sy * sz;\n return quat;\n}\nmat4 matrixFromRT (vec4 q, vec3 p){\n float x2 = q.x + q.x;\n float y2 = q.y + q.y;\n float z2 = q.z + q.z;\n float xx = q.x * x2;\n float xy = q.x * y2;\n float xz = q.x * z2;\n float yy = q.y * y2;\n float yz = q.y * z2;\n float zz = q.z * z2;\n float wx = q.w * x2;\n float wy = q.w * y2;\n float wz = q.w * z2;\n return mat4(\n 1. - (yy + zz), xy + wz, xz - wy, 0,\n xy - wz, 1. - (xx + zz), yz + wx, 0,\n xz + wy, yz - wx, 1. - (xx + yy), 0,\n p.x, p.y, p.z, 1\n );\n}\nmat4 matFromRTS (vec4 q, vec3 t, vec3 s){\n float x = q.x, y = q.y, z = q.z, w = q.w;\n float x2 = x + x;\n float y2 = y + y;\n float z2 = z + z;\n float xx = x * x2;\n float xy = x * y2;\n float xz = x * z2;\n float yy = y * y2;\n float yz = y * z2;\n float zz = z * z2;\n float wx = w * x2;\n float wy = w * y2;\n float wz = w * z2;\n float sx = s.x;\n float sy = s.y;\n float sz = s.z;\n return mat4((1. - (yy + zz)) * sx, (xy + wz) * sx, (xz - wy) * sx, 0,\n (xy - wz) * sy, (1. - (xx + zz)) * sy, (yz + wx) * sy, 0,\n (xz + wy) * sz, (yz - wx) * sz, (1. - (xx + yy)) * sz, 0,\n t.x, t.y, t.z, 1);\n}\nvec4 quatMultiply (vec4 a, vec4 b){\n vec4 quat;\n quat.x = a.x * b.w + a.w * b.x + a.y * b.z - a.z * b.y;\n quat.y = a.y * b.w + a.w * b.y + a.z * b.x - a.x * b.z;\n quat.z = a.z * b.w + a.w * b.z + a.x * b.y - a.y * b.x;\n quat.w = a.w * b.w - a.x * b.x - a.y * b.y - a.z * b.z;\n return quat;\n}\nvoid rotateVecFromQuat (inout vec3 v, vec4 q){\n float ix = q.w * v.x + q.y * v.z - q.z * v.y;\n float iy = q.w * v.y + q.z * v.x - q.x * v.z;\n float iz = q.w * v.z + q.x * v.y - q.y * v.x;\n float iw = -q.x * v.x - q.y * v.y - q.z * v.z;\n v.x = ix * q.w + iw * -q.x + iy * -q.z - iz * -q.y;\n v.y = iy * q.w + iw * -q.y + iz * -q.x - ix * -q.z;\n v.z = iz * q.w + iw * -q.z + ix * -q.y - iy * -q.x;\n}\nvec3 rotateInLocalSpace (vec3 pos, vec3 xAxis, vec3 yAxis, vec3 zAxis, vec4 q){\n vec4 viewQuat = quaternionFromAxis(xAxis, yAxis, zAxis);\n vec4 rotQuat = quatMultiply(viewQuat, q);\n rotateVecFromQuat(pos, rotQuat);\n return pos;\n}\nvoid rotateCorner (inout vec2 corner, float angle){\n float xOS = cos(angle) * corner.x - sin(angle) * corner.y;\n float yOS = sin(angle) * corner.x + cos(angle) * corner.y;\n corner.x = xOS;\n corner.y = yOS;\n}\nuniform Constants {\n vec4 mainTiling_Offset;\n vec4 frameTile_velLenScale;\n vec4 scale;\n};\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\nuniform CCLocal {\n highp mat4 cc_matWorld;\n highp mat4 cc_matWorldIT;\n highp vec4 cc_lightingMapUVParam;\n};\nout vec2 uv;\nout vec4 color;\nvoid computeVertPos (inout vec4 pos, vec2 vertOffset, vec4 q, vec3 s\n#if CC_RENDER_MODE == 0 || CC_RENDER_MODE == 3\n , mat4 viewInv\n#endif\n#if CC_RENDER_MODE == 1\n , vec3 eye\n , vec4 velocity\n , float velocityScale\n , float lengthScale\n , float xIndex\n#endif\n) {\n#if CC_RENDER_MODE == 0\n vec3 viewSpaceVert = vec3(vertOffset.x * s.x, vertOffset.y * s.y, 0.);\n vec3 camX = normalize(vec3(viewInv[0][0], viewInv[1][0], viewInv[2][0]));\n vec3 camY = normalize(vec3(viewInv[0][1], viewInv[1][1], viewInv[2][1]));\n vec3 camZ = normalize(vec3(viewInv[0][2], viewInv[1][2], viewInv[2][2]));\n pos.xyz += rotateInLocalSpace(viewSpaceVert, camX, camY, camZ, q);\n#elif CC_RENDER_MODE == 1\n vec3 camRight = normalize(cross(pos.xyz - eye, velocity.xyz)) * s.x;\n vec3 camUp = velocity.xyz * velocityScale + normalize(velocity.xyz) * lengthScale * s.y;\n pos.xyz += (camRight * abs(vertOffset.x) * sign(vertOffset.y)) - camUp * xIndex;\n#elif CC_RENDER_MODE == 2\n vec3 viewSpaceVert = vec3(vertOffset.x * s.x, vertOffset.y * s.y, 0.);\n vec3 camX = vec3(1, 0, 0);\n vec3 camY = vec3(0, 0, -1);\n pos.xyz += rotateInLocalSpace(viewSpaceVert, camX, camY, cross(camX, camY), q);\n#elif CC_RENDER_MODE == 3\n vec2 viewSpaceVert = vec2(vertOffset.x * s.x, vertOffset.y * s.y);\n rotateCorner(viewSpaceVert, q.z);\n vec3 camX = normalize(vec3(cc_matView[0][0], cc_matView[1][0], cc_matView[2][0]));\n vec3 camY = vec3(0, 1, 0);\n vec3 offset = camX * viewSpaceVert.x + camY * viewSpaceVert.y;\n pos.xyz += offset;\n#else\n pos.x += vertOffset.x;\n pos.y += vertOffset.y;\n#endif\n}\nvec2 computeUV (float frameIndex, vec2 vertIndex, vec2 frameTile){\n vec2 aniUV = vec2(0, floor(frameIndex * frameTile.y));\n aniUV.x = floor(frameIndex * frameTile.x * frameTile.y - aniUV.y * frameTile.x);\n#if CC_RENDER_MODE != 4\n vertIndex.y = 1. - vertIndex.y;\n#endif\n return (aniUV.xy + vertIndex) / vec2(frameTile.x, frameTile.y);\n}\nuniform SampleConstants {\n vec4 u_sampleInfo;\n};\nuniform TickConstants {\n vec4 u_worldRot;\n vec4 u_timeDelta;\n};\nin vec4 a_position_starttime;\nin vec4 a_size_uv;\nin vec4 a_rotation_uv;\nin vec4 a_color;\nin vec4 a_dir_life;\nin float a_rndSeed;\n#if CC_RENDER_MODE == 4\n in vec3 a_texCoord;\n in vec3 a_texCoord3;\n in vec3 a_normal;\n in vec4 a_color1;\n#endif\nvec3 unpackCurveData (sampler2D tex, vec2 coord) {\n vec4 a = texture(tex, coord);\n vec4 b = texture(tex, coord + u_sampleInfo.y);\n float c = fract(coord.x * u_sampleInfo.x);\n return mix(a.xyz, b.xyz, c);\n}\nvec3 unpackCurveData (sampler2D tex, vec2 coord, out float w) {\n vec4 a = texture(tex, coord);\n vec4 b = texture(tex, coord + u_sampleInfo.y);\n float c = fract(coord.x * u_sampleInfo.x);\n w = mix(a.w, b.w, c);\n return mix(a.xyz, b.xyz, c);\n}\nfloat pseudoRandom (float seed) {\n seed = mod(seed, 233280.);\n float q = (seed * 9301. + 49297.) / 233280.;\n return fract(q);\n}\n#if COLOR_OVER_TIME_MODULE_ENABLE\n uniform sampler2D color_over_time_tex0;\n uniform ColorConstant {\n int u_color_mode;\n };\n#endif\n#if ROTATION_OVER_TIME_MODULE_ENABLE\n uniform sampler2D rotation_over_time_tex0;\n uniform RotationConstant {\n int u_rotation_mode;\n };\n#endif\n#if SIZE_OVER_TIME_MODULE_ENABLE\n uniform sampler2D size_over_time_tex0;\n uniform SizeConstant {\n int u_size_mode;\n };\n#endif\n#if FORCE_OVER_TIME_MODULE_ENABLE\n uniform sampler2D force_over_time_tex0;\n uniform ForceConstant {\n int u_force_mode;\n int u_force_space;\n };\n#endif\n#if VELOCITY_OVER_TIME_MODULE_ENABLE\n uniform sampler2D velocity_over_time_tex0;\n uniform VelocityConstant {\n int u_velocity_mode;\n int u_velocity_space;\n };\n#endif\n#if TEXTURE_ANIMATION_MODULE_ENABLE\n uniform sampler2D texture_animation_tex0;\n uniform AnimationConstant {\n vec4 u_anim_info;\n };\n#endif\nfloat repeat (float t, float length) {\n return t - floor(t / length) * length;\n}\nvec4 rotateQuat (vec4 p, vec4 q) {\n vec3 iv = cross(q.xyz, p.xyz) + q.w * p.xyz;\n vec3 res = p.xyz + 2.0 * cross(q.xyz, iv);\n return vec4(res.xyz, p.w);\n}\nvec4 gpvs_main () {\n float activeTime = u_timeDelta.x - a_position_starttime.w;\n float normalizedTime = clamp(activeTime / a_dir_life.w, 0.0, 1.0);\n vec2 timeCoord0 = vec2(normalizedTime, 0.);\n vec2 timeCoord1 = vec2(normalizedTime, 1.);\n #if CC_RENDER_MODE == 4\n vec2 vertIdx = vec2(a_texCoord.x, a_texCoord.y);\n #else\n vec2 vertIdx = vec2(a_size_uv.w, a_rotation_uv.w);\n #endif\n vec4 velocity = vec4(a_dir_life.xyz, 0.);\n vec4 pos = vec4(a_position_starttime.xyz, 1.);\n vec3 size = a_size_uv.xyz;\n #if SIZE_OVER_TIME_MODULE_ENABLE\n if (u_size_mode == 1) {\n size *= unpackCurveData(size_over_time_tex0, timeCoord0);\n } else {\n vec3 size_0 = unpackCurveData(size_over_time_tex0, timeCoord0);\n vec3 size_1 = unpackCurveData(size_over_time_tex0, timeCoord1);\n float factor_s = pseudoRandom(a_rndSeed + 39825.);\n size *= mix(size_0, size_1, factor_s);\n }\n #endif\n vec3 compScale = scale.xyz * size;\n #if FORCE_OVER_TIME_MODULE_ENABLE\n vec3 forceAnim = vec3(0.);\n if (u_force_mode == 1) {\n forceAnim = unpackCurveData(force_over_time_tex0, timeCoord0);\n } else {\n vec3 force_0 = unpackCurveData(force_over_time_tex0, timeCoord0);\n vec3 force_1 = unpackCurveData(force_over_time_tex0, timeCoord1);\n float factor_f = pseudoRandom(a_rndSeed + 212165.);\n forceAnim = mix(force_0, force_1, factor_f);\n }\n vec4 forceTrack = vec4(forceAnim, 0.);\n if (u_force_space == 0) {\n forceTrack = rotateQuat(forceTrack, u_worldRot);\n }\n velocity.xyz += forceTrack.xyz;\n #endif\n #if VELOCITY_OVER_TIME_MODULE_ENABLE\n float speedModifier0 = 1.;\n float speedModifier1 = 1.;\n vec3 velocityAnim = vec3(0.);\n if (u_velocity_mode == 1) {\n velocityAnim = unpackCurveData(velocity_over_time_tex0, timeCoord0, speedModifier0);\n } else {\n vec3 vectory_0 = unpackCurveData(velocity_over_time_tex0, timeCoord0, speedModifier0);\n vec3 vectory_1 = unpackCurveData(velocity_over_time_tex0, timeCoord1, speedModifier1);\n float factor_v = pseudoRandom(a_rndSeed + 197866.);\n velocityAnim = mix(vectory_0, vectory_1, factor_v);\n speedModifier0 = mix(speedModifier0, speedModifier1, factor_v);\n }\n vec4 velocityTrack = vec4(velocityAnim, 0.);\n if (u_velocity_space == 0) {\n velocityTrack = rotateQuat(velocityTrack, u_worldRot);\n }\n velocity.xyz += velocityTrack.xyz;\n velocity.xyz *= speedModifier0;\n #endif\n pos.xyz += velocity.xyz * normalizedTime * a_dir_life.w;\n #if !CC_USE_WORLD_SPACE\n pos = cc_matWorld * pos;\n #if CC_RENDER_MODE == 1\n velocity = rotateQuat(velocity, u_worldRot);\n #endif\n #endif\n vec3 rotation = a_rotation_uv.xyz;\n #if ROTATION_OVER_TIME_MODULE_ENABLE\n if (u_rotation_mode == 1) {\n rotation += unpackCurveData(rotation_over_time_tex0, timeCoord0) * normalizedTime * a_dir_life.w;\n } else {\n vec3 rotation_0 = unpackCurveData(rotation_over_time_tex0, timeCoord0);\n vec3 rotation_1 = unpackCurveData(rotation_over_time_tex0, timeCoord1);\n float factor_r = pseudoRandom(a_rndSeed + 125292.);\n rotation += mix(rotation_0, rotation_1, factor_r) * normalizedTime * a_dir_life.w;\n }\n #endif\n #if COLOR_OVER_TIME_MODULE_ENABLE\n if (u_color_mode == 1) {\n color = a_color * texture(color_over_time_tex0, timeCoord0);\n } else {\n vec4 color_0 = texture(color_over_time_tex0, timeCoord0);\n vec4 color_1 = texture(color_over_time_tex0, timeCoord1);\n float factor_c = pseudoRandom(a_rndSeed + 91041.);\n color = a_color * mix(color_0, color_1, factor_c);\n }\n #else\n color = a_color;\n #endif\n #if CC_RENDER_MODE != 4\n vec2 cornerOffset = vec2((vertIdx - 0.5));\n #if CC_RENDER_MODE == 0\n vec3 rotEuler = rotation.xyz;\n #elif CC_RENDER_MODE == 1\n vec3 rotEuler = vec3(0.);\n #else\n vec3 rotEuler = vec3(0., 0., rotation.z);\n #endif\n computeVertPos(pos, cornerOffset, quaternionFromEuler(rotEuler), compScale\n #if CC_RENDER_MODE == 0 || CC_RENDER_MODE == 3\n , cc_matViewInv\n #endif\n #if CC_RENDER_MODE == 1\n , cc_cameraPos.xyz\n , velocity\n , frameTile_velLenScale.z\n , frameTile_velLenScale.w\n , a_size_uv.w\n #endif\n );\n #else\n mat4 xformNoScale = matrixFromRT(quaternionFromEuler(rotation), pos.xyz);\n mat4 xform = matFromRTS(quaternionFromEuler(rotation), pos.xyz, compScale);\n pos = xform * vec4(a_texCoord3, 1);\n vec4 normal = xformNoScale * vec4(a_normal, 0);\n color *= a_color1;\n #endif\n pos = cc_matViewProj * pos;\n float frameIndex = 0.;\n #if TEXTURE_ANIMATION_MODULE_ENABLE\n float startFrame = 0.;\n vec3 frameInfo = vec3(0.);\n if (int(u_anim_info.x) == 1) {\n frameInfo = unpackCurveData(texture_animation_tex0, timeCoord0);\n } else {\n vec3 frameInfo0 = unpackCurveData(texture_animation_tex0, timeCoord0);\n vec3 frameInfo1 = unpackCurveData(texture_animation_tex0, timeCoord1);\n float factor_t = pseudoRandom(a_rndSeed + 90794.);\n frameInfo = mix(frameInfo0, frameInfo1, factor_t);\n }\n startFrame = frameInfo.x / u_anim_info.y;\n frameIndex = repeat(u_anim_info.z * (frameInfo.y + startFrame), 1.);\n #endif\n uv = computeUV(frameIndex, vertIdx, frameTile_velLenScale.xy) * mainTiling_Offset.xy + mainTiling_Offset.zw;\n return pos;\n}\nvoid main() { gl_Position = gpvs_main(); }`, - "frag": `\nprecision mediump float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\n}\nvec4 CCFragOutput (vec4 color) {\n #if CC_USE_HDR\n color.rgb = mix(color.rgb, SRGBToLinear(color.rgb) * cc_exposure.w, vec3(cc_exposure.z));\n #endif\n return color;\n}\nin vec2 uv;\nin vec4 color;\nuniform sampler2D mainTexture;\nuniform FragConstants {\n vec4 tintColor;\n};\nvec4 add () {\n vec4 col = 2.0 * color * tintColor * texture(mainTexture, uv);\n return CCFragOutput(col);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = add(); }` + "vert": `\nprecision mediump float;\nvec4 quaternionFromAxis (vec3 xAxis,vec3 yAxis,vec3 zAxis){\n mat3 m = mat3(xAxis,yAxis,zAxis);\n float trace = m[0][0] + m[1][1] + m[2][2];\n vec4 quat;\n if (trace > 0.) {\n float s = 0.5 / sqrt(trace + 1.0);\n quat.w = 0.25 / s;\n quat.x = (m[2][1] - m[1][2]) * s;\n quat.y = (m[0][2] - m[2][0]) * s;\n quat.z = (m[1][0] - m[0][1]) * s;\n } else if ((m[0][0] > m[1][1]) && (m[0][0] > m[2][2])) {\n float s = 2.0 * sqrt(1.0 + m[0][0] - m[1][1] - m[2][2]);\n quat.w = (m[2][1] - m[1][2]) / s;\n quat.x = 0.25 * s;\n quat.y = (m[0][1] + m[1][0]) / s;\n quat.z = (m[0][2] + m[2][0]) / s;\n } else if (m[1][1] > m[2][2]) {\n float s = 2.0 * sqrt(1.0 + m[1][1] - m[0][0] - m[2][2]);\n quat.w = (m[0][2] - m[2][0]) / s;\n quat.x = (m[0][1] + m[1][0]) / s;\n quat.y = 0.25 * s;\n quat.z = (m[1][2] + m[2][1]) / s;\n } else {\n float s = 2.0 * sqrt(1.0 + m[2][2] - m[0][0] - m[1][1]);\n quat.w = (m[1][0] - m[0][1]) / s;\n quat.x = (m[0][2] + m[2][0]) / s;\n quat.y = (m[1][2] + m[2][1]) / s;\n quat.z = 0.25 * s;\n }\n float len = quat.x * quat.x + quat.y * quat.y + quat.z * quat.z + quat.w * quat.w;\n if (len > 0.) {\n len = 1. / sqrt(len);\n quat.x = quat.x * len;\n quat.y = quat.y * len;\n quat.z = quat.z * len;\n quat.w = quat.w * len;\n }\n return quat;\n}\nvec4 quaternionFromEuler (vec3 angle){\n float x = angle.x / 2.;\n float y = angle.y / 2.;\n float z = angle.z / 2.;\n float sx = sin(x);\n float cx = cos(x);\n float sy = sin(y);\n float cy = cos(y);\n float sz = sin(z);\n float cz = cos(z);\n vec4 quat = vec4(0);\n quat.x = sx * cy * cz + cx * sy * sz;\n quat.y = cx * sy * cz + sx * cy * sz;\n quat.z = cx * cy * sz - sx * sy * cz;\n quat.w = cx * cy * cz - sx * sy * sz;\n return quat;\n}\nmat4 matrixFromRT (vec4 q, vec3 p){\n float x2 = q.x + q.x;\n float y2 = q.y + q.y;\n float z2 = q.z + q.z;\n float xx = q.x * x2;\n float xy = q.x * y2;\n float xz = q.x * z2;\n float yy = q.y * y2;\n float yz = q.y * z2;\n float zz = q.z * z2;\n float wx = q.w * x2;\n float wy = q.w * y2;\n float wz = q.w * z2;\n return mat4(\n 1. - (yy + zz), xy + wz, xz - wy, 0,\n xy - wz, 1. - (xx + zz), yz + wx, 0,\n xz + wy, yz - wx, 1. - (xx + yy), 0,\n p.x, p.y, p.z, 1\n );\n}\nmat4 matFromRTS (vec4 q, vec3 t, vec3 s){\n float x = q.x, y = q.y, z = q.z, w = q.w;\n float x2 = x + x;\n float y2 = y + y;\n float z2 = z + z;\n float xx = x * x2;\n float xy = x * y2;\n float xz = x * z2;\n float yy = y * y2;\n float yz = y * z2;\n float zz = z * z2;\n float wx = w * x2;\n float wy = w * y2;\n float wz = w * z2;\n float sx = s.x;\n float sy = s.y;\n float sz = s.z;\n return mat4((1. - (yy + zz)) * sx, (xy + wz) * sx, (xz - wy) * sx, 0,\n (xy - wz) * sy, (1. - (xx + zz)) * sy, (yz + wx) * sy, 0,\n (xz + wy) * sz, (yz - wx) * sz, (1. - (xx + yy)) * sz, 0,\n t.x, t.y, t.z, 1);\n}\nvec4 quatMultiply (vec4 a, vec4 b){\n vec4 quat;\n quat.x = a.x * b.w + a.w * b.x + a.y * b.z - a.z * b.y;\n quat.y = a.y * b.w + a.w * b.y + a.z * b.x - a.x * b.z;\n quat.z = a.z * b.w + a.w * b.z + a.x * b.y - a.y * b.x;\n quat.w = a.w * b.w - a.x * b.x - a.y * b.y - a.z * b.z;\n return quat;\n}\nvoid rotateVecFromQuat (inout vec3 v, vec4 q){\n float ix = q.w * v.x + q.y * v.z - q.z * v.y;\n float iy = q.w * v.y + q.z * v.x - q.x * v.z;\n float iz = q.w * v.z + q.x * v.y - q.y * v.x;\n float iw = -q.x * v.x - q.y * v.y - q.z * v.z;\n v.x = ix * q.w + iw * -q.x + iy * -q.z - iz * -q.y;\n v.y = iy * q.w + iw * -q.y + iz * -q.x - ix * -q.z;\n v.z = iz * q.w + iw * -q.z + ix * -q.y - iy * -q.x;\n}\nvec3 rotateInLocalSpace (vec3 pos, vec3 xAxis, vec3 yAxis, vec3 zAxis, vec4 q){\n vec4 viewQuat = quaternionFromAxis(xAxis, yAxis, zAxis);\n vec4 rotQuat = quatMultiply(viewQuat, q);\n rotateVecFromQuat(pos, rotQuat);\n return pos;\n}\nvoid rotateCorner (inout vec2 corner, float angle){\n float xOS = cos(angle) * corner.x - sin(angle) * corner.y;\n float yOS = sin(angle) * corner.x + cos(angle) * corner.y;\n corner.x = xOS;\n corner.y = yOS;\n}\nuniform Constants {\n vec4 mainTiling_Offset;\n vec4 frameTile_velLenScale;\n vec4 scale;\n};\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n};\nuniform CCLocal {\n highp mat4 cc_matWorld;\n highp mat4 cc_matWorldIT;\n highp vec4 cc_lightingMapUVParam;\n};\nout vec2 uv;\nout vec4 color;\nvoid computeVertPos (inout vec4 pos, vec2 vertOffset, vec4 q, vec3 s\n#if CC_RENDER_MODE == 0 || CC_RENDER_MODE == 3\n , mat4 viewInv\n#endif\n#if CC_RENDER_MODE == 1\n , vec3 eye\n , vec4 velocity\n , float velocityScale\n , float lengthScale\n , float xIndex\n#endif\n) {\n#if CC_RENDER_MODE == 0\n vec3 viewSpaceVert = vec3(vertOffset.x * s.x, vertOffset.y * s.y, 0.);\n vec3 camX = normalize(vec3(viewInv[0][0], viewInv[1][0], viewInv[2][0]));\n vec3 camY = normalize(vec3(viewInv[0][1], viewInv[1][1], viewInv[2][1]));\n vec3 camZ = normalize(vec3(viewInv[0][2], viewInv[1][2], viewInv[2][2]));\n pos.xyz += rotateInLocalSpace(viewSpaceVert, camX, camY, camZ, q);\n#elif CC_RENDER_MODE == 1\n vec3 camRight = normalize(cross(pos.xyz - eye, velocity.xyz)) * s.x;\n vec3 camUp = velocity.xyz * velocityScale + normalize(velocity.xyz) * lengthScale * s.y;\n pos.xyz += (camRight * abs(vertOffset.x) * sign(vertOffset.y)) - camUp * xIndex;\n#elif CC_RENDER_MODE == 2\n vec3 viewSpaceVert = vec3(vertOffset.x * s.x, vertOffset.y * s.y, 0.);\n vec3 camX = vec3(1, 0, 0);\n vec3 camY = vec3(0, 0, -1);\n pos.xyz += rotateInLocalSpace(viewSpaceVert, camX, camY, cross(camX, camY), q);\n#elif CC_RENDER_MODE == 3\n vec2 viewSpaceVert = vec2(vertOffset.x * s.x, vertOffset.y * s.y);\n rotateCorner(viewSpaceVert, q.z);\n vec3 camX = normalize(vec3(cc_matView[0][0], cc_matView[1][0], cc_matView[2][0]));\n vec3 camY = vec3(0, 1, 0);\n vec3 offset = camX * viewSpaceVert.x + camY * viewSpaceVert.y;\n pos.xyz += offset;\n#else\n pos.x += vertOffset.x;\n pos.y += vertOffset.y;\n#endif\n}\nvec2 computeUV (float frameIndex, vec2 vertIndex, vec2 frameTile){\n vec2 aniUV = vec2(0, floor(frameIndex * frameTile.y));\n aniUV.x = floor(frameIndex * frameTile.x * frameTile.y - aniUV.y * frameTile.x);\n#if CC_RENDER_MODE != 4\n vertIndex.y = 1. - vertIndex.y;\n#endif\n return (aniUV.xy + vertIndex) / vec2(frameTile.x, frameTile.y);\n}\nuniform SampleConstants {\n vec4 u_sampleInfo;\n};\nuniform TickConstants {\n vec4 u_worldRot;\n vec4 u_timeDelta;\n};\nin vec4 a_position_starttime;\nin vec4 a_size_uv;\nin vec4 a_rotation_uv;\nin vec4 a_color;\nin vec4 a_dir_life;\nin float a_rndSeed;\n#if CC_RENDER_MODE == 4\n in vec3 a_texCoord;\n in vec3 a_texCoord3;\n in vec3 a_normal;\n in vec4 a_color1;\n#endif\nvec3 unpackCurveData (sampler2D tex, vec2 coord) {\n vec4 a = texture(tex, coord);\n vec4 b = texture(tex, coord + u_sampleInfo.y);\n float c = fract(coord.x * u_sampleInfo.x);\n return mix(a.xyz, b.xyz, c);\n}\nvec3 unpackCurveData (sampler2D tex, vec2 coord, out float w) {\n vec4 a = texture(tex, coord);\n vec4 b = texture(tex, coord + u_sampleInfo.y);\n float c = fract(coord.x * u_sampleInfo.x);\n w = mix(a.w, b.w, c);\n return mix(a.xyz, b.xyz, c);\n}\nfloat pseudoRandom (float seed) {\n seed = mod(seed, 233280.);\n float q = (seed * 9301. + 49297.) / 233280.;\n return fract(q);\n}\n#if COLOR_OVER_TIME_MODULE_ENABLE\n uniform sampler2D color_over_time_tex0;\n uniform ColorConstant {\n int u_color_mode;\n };\n#endif\n#if ROTATION_OVER_TIME_MODULE_ENABLE\n uniform sampler2D rotation_over_time_tex0;\n uniform RotationConstant {\n int u_rotation_mode;\n };\n#endif\n#if SIZE_OVER_TIME_MODULE_ENABLE\n uniform sampler2D size_over_time_tex0;\n uniform SizeConstant {\n int u_size_mode;\n };\n#endif\n#if FORCE_OVER_TIME_MODULE_ENABLE\n uniform sampler2D force_over_time_tex0;\n uniform ForceConstant {\n int u_force_mode;\n int u_force_space;\n };\n#endif\n#if VELOCITY_OVER_TIME_MODULE_ENABLE\n uniform sampler2D velocity_over_time_tex0;\n uniform VelocityConstant {\n int u_velocity_mode;\n int u_velocity_space;\n };\n#endif\n#if TEXTURE_ANIMATION_MODULE_ENABLE\n uniform sampler2D texture_animation_tex0;\n uniform AnimationConstant {\n vec4 u_anim_info;\n };\n#endif\nfloat repeat (float t, float length) {\n return t - floor(t / length) * length;\n}\nvec4 rotateQuat (vec4 p, vec4 q) {\n vec3 iv = cross(q.xyz, p.xyz) + q.w * p.xyz;\n vec3 res = p.xyz + 2.0 * cross(q.xyz, iv);\n return vec4(res.xyz, p.w);\n}\nvec4 gpvs_main () {\n float activeTime = u_timeDelta.x - a_position_starttime.w;\n float normalizedTime = clamp(activeTime / a_dir_life.w, 0.0, 1.0);\n vec2 timeCoord0 = vec2(normalizedTime, 0.);\n vec2 timeCoord1 = vec2(normalizedTime, 1.);\n #if CC_RENDER_MODE == 4\n vec2 vertIdx = vec2(a_texCoord.x, a_texCoord.y);\n #else\n vec2 vertIdx = vec2(a_size_uv.w, a_rotation_uv.w);\n #endif\n vec4 velocity = vec4(a_dir_life.xyz, 0.);\n vec4 pos = vec4(a_position_starttime.xyz, 1.);\n vec3 size = a_size_uv.xyz;\n #if SIZE_OVER_TIME_MODULE_ENABLE\n if (u_size_mode == 1) {\n size *= unpackCurveData(size_over_time_tex0, timeCoord0);\n } else {\n vec3 size_0 = unpackCurveData(size_over_time_tex0, timeCoord0);\n vec3 size_1 = unpackCurveData(size_over_time_tex0, timeCoord1);\n float factor_s = pseudoRandom(a_rndSeed + 39825.);\n size *= mix(size_0, size_1, factor_s);\n }\n #endif\n vec3 compScale = scale.xyz * size;\n #if FORCE_OVER_TIME_MODULE_ENABLE\n vec3 forceAnim = vec3(0.);\n if (u_force_mode == 1) {\n forceAnim = unpackCurveData(force_over_time_tex0, timeCoord0);\n } else {\n vec3 force_0 = unpackCurveData(force_over_time_tex0, timeCoord0);\n vec3 force_1 = unpackCurveData(force_over_time_tex0, timeCoord1);\n float factor_f = pseudoRandom(a_rndSeed + 212165.);\n forceAnim = mix(force_0, force_1, factor_f);\n }\n vec4 forceTrack = vec4(forceAnim, 0.);\n if (u_force_space == 0) {\n forceTrack = rotateQuat(forceTrack, u_worldRot);\n }\n velocity.xyz += forceTrack.xyz;\n #endif\n #if VELOCITY_OVER_TIME_MODULE_ENABLE\n float speedModifier0 = 1.;\n float speedModifier1 = 1.;\n vec3 velocityAnim = vec3(0.);\n if (u_velocity_mode == 1) {\n velocityAnim = unpackCurveData(velocity_over_time_tex0, timeCoord0, speedModifier0);\n } else {\n vec3 vectory_0 = unpackCurveData(velocity_over_time_tex0, timeCoord0, speedModifier0);\n vec3 vectory_1 = unpackCurveData(velocity_over_time_tex0, timeCoord1, speedModifier1);\n float factor_v = pseudoRandom(a_rndSeed + 197866.);\n velocityAnim = mix(vectory_0, vectory_1, factor_v);\n speedModifier0 = mix(speedModifier0, speedModifier1, factor_v);\n }\n vec4 velocityTrack = vec4(velocityAnim, 0.);\n if (u_velocity_space == 0) {\n velocityTrack = rotateQuat(velocityTrack, u_worldRot);\n }\n velocity.xyz += velocityTrack.xyz;\n velocity.xyz *= speedModifier0;\n #endif\n pos.xyz += velocity.xyz * normalizedTime * a_dir_life.w;\n #if !CC_USE_WORLD_SPACE\n pos = cc_matWorld * pos;\n #if CC_RENDER_MODE == 1\n velocity = rotateQuat(velocity, u_worldRot);\n #endif\n #endif\n vec3 rotation = a_rotation_uv.xyz;\n #if ROTATION_OVER_TIME_MODULE_ENABLE\n if (u_rotation_mode == 1) {\n rotation += unpackCurveData(rotation_over_time_tex0, timeCoord0) * normalizedTime * a_dir_life.w;\n } else {\n vec3 rotation_0 = unpackCurveData(rotation_over_time_tex0, timeCoord0);\n vec3 rotation_1 = unpackCurveData(rotation_over_time_tex0, timeCoord1);\n float factor_r = pseudoRandom(a_rndSeed + 125292.);\n rotation += mix(rotation_0, rotation_1, factor_r) * normalizedTime * a_dir_life.w;\n }\n #endif\n #if COLOR_OVER_TIME_MODULE_ENABLE\n if (u_color_mode == 1) {\n color = a_color * texture(color_over_time_tex0, timeCoord0);\n } else {\n vec4 color_0 = texture(color_over_time_tex0, timeCoord0);\n vec4 color_1 = texture(color_over_time_tex0, timeCoord1);\n float factor_c = pseudoRandom(a_rndSeed + 91041.);\n color = a_color * mix(color_0, color_1, factor_c);\n }\n #else\n color = a_color;\n #endif\n #if CC_RENDER_MODE != 4\n vec2 cornerOffset = vec2((vertIdx - 0.5));\n #if CC_RENDER_MODE == 0\n vec3 rotEuler = rotation.xyz;\n #elif CC_RENDER_MODE == 1\n vec3 rotEuler = vec3(0.);\n #else\n vec3 rotEuler = vec3(0., 0., rotation.z);\n #endif\n computeVertPos(pos, cornerOffset, quaternionFromEuler(rotEuler), compScale\n #if CC_RENDER_MODE == 0 || CC_RENDER_MODE == 3\n , cc_matViewInv\n #endif\n #if CC_RENDER_MODE == 1\n , cc_cameraPos.xyz\n , velocity\n , frameTile_velLenScale.z\n , frameTile_velLenScale.w\n , a_size_uv.w\n #endif\n );\n #else\n mat4 xformNoScale = matrixFromRT(quaternionFromEuler(rotation), pos.xyz);\n mat4 xform = matFromRTS(quaternionFromEuler(rotation), pos.xyz, compScale);\n pos = xform * vec4(a_texCoord3, 1);\n vec4 normal = xformNoScale * vec4(a_normal, 0);\n color *= a_color1;\n #endif\n pos = cc_matViewProj * pos;\n float frameIndex = 0.;\n #if TEXTURE_ANIMATION_MODULE_ENABLE\n float startFrame = 0.;\n vec3 frameInfo = vec3(0.);\n if (int(u_anim_info.x) == 1) {\n frameInfo = unpackCurveData(texture_animation_tex0, timeCoord0);\n } else {\n vec3 frameInfo0 = unpackCurveData(texture_animation_tex0, timeCoord0);\n vec3 frameInfo1 = unpackCurveData(texture_animation_tex0, timeCoord1);\n float factor_t = pseudoRandom(a_rndSeed + 90794.);\n frameInfo = mix(frameInfo0, frameInfo1, factor_t);\n }\n startFrame = frameInfo.x / u_anim_info.y;\n frameIndex = repeat(u_anim_info.z * (frameInfo.y + startFrame), 1.);\n #endif\n uv = computeUV(frameIndex, vertIdx, frameTile_velLenScale.xy) * mainTiling_Offset.xy + mainTiling_Offset.zw;\n return pos;\n}\nvoid main() { gl_Position = gpvs_main(); }`, + "frag": `\nprecision mediump float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n};\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\n}\nvec4 CCFragOutput (vec4 color) {\n #if CC_USE_HDR\n color.rgb = mix(color.rgb, SRGBToLinear(color.rgb) * cc_exposure.w, vec3(cc_exposure.z));\n #endif\n return color;\n}\nin vec2 uv;\nin vec4 color;\nuniform sampler2D mainTexture;\nuniform FragConstants {\n vec4 tintColor;\n};\nvec4 add () {\n vec4 col = 2.0 * color * tintColor * texture(mainTexture, uv);\n return CCFragOutput(col);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = add(); }` }, "glsl1": { "vert": `\nprecision mediump float;\nvec4 quaternionFromAxis (vec3 xAxis,vec3 yAxis,vec3 zAxis){\n mat3 m = mat3(xAxis,yAxis,zAxis);\n float trace = m[0][0] + m[1][1] + m[2][2];\n vec4 quat;\n if (trace > 0.) {\n float s = 0.5 / sqrt(trace + 1.0);\n quat.w = 0.25 / s;\n quat.x = (m[2][1] - m[1][2]) * s;\n quat.y = (m[0][2] - m[2][0]) * s;\n quat.z = (m[1][0] - m[0][1]) * s;\n } else if ((m[0][0] > m[1][1]) && (m[0][0] > m[2][2])) {\n float s = 2.0 * sqrt(1.0 + m[0][0] - m[1][1] - m[2][2]);\n quat.w = (m[2][1] - m[1][2]) / s;\n quat.x = 0.25 * s;\n quat.y = (m[0][1] + m[1][0]) / s;\n quat.z = (m[0][2] + m[2][0]) / s;\n } else if (m[1][1] > m[2][2]) {\n float s = 2.0 * sqrt(1.0 + m[1][1] - m[0][0] - m[2][2]);\n quat.w = (m[0][2] - m[2][0]) / s;\n quat.x = (m[0][1] + m[1][0]) / s;\n quat.y = 0.25 * s;\n quat.z = (m[1][2] + m[2][1]) / s;\n } else {\n float s = 2.0 * sqrt(1.0 + m[2][2] - m[0][0] - m[1][1]);\n quat.w = (m[1][0] - m[0][1]) / s;\n quat.x = (m[0][2] + m[2][0]) / s;\n quat.y = (m[1][2] + m[2][1]) / s;\n quat.z = 0.25 * s;\n }\n float len = quat.x * quat.x + quat.y * quat.y + quat.z * quat.z + quat.w * quat.w;\n if (len > 0.) {\n len = 1. / sqrt(len);\n quat.x = quat.x * len;\n quat.y = quat.y * len;\n quat.z = quat.z * len;\n quat.w = quat.w * len;\n }\n return quat;\n}\nvec4 quaternionFromEuler (vec3 angle){\n float x = angle.x / 2.;\n float y = angle.y / 2.;\n float z = angle.z / 2.;\n float sx = sin(x);\n float cx = cos(x);\n float sy = sin(y);\n float cy = cos(y);\n float sz = sin(z);\n float cz = cos(z);\n vec4 quat = vec4(0);\n quat.x = sx * cy * cz + cx * sy * sz;\n quat.y = cx * sy * cz + sx * cy * sz;\n quat.z = cx * cy * sz - sx * sy * cz;\n quat.w = cx * cy * cz - sx * sy * sz;\n return quat;\n}\nmat4 matrixFromRT (vec4 q, vec3 p){\n float x2 = q.x + q.x;\n float y2 = q.y + q.y;\n float z2 = q.z + q.z;\n float xx = q.x * x2;\n float xy = q.x * y2;\n float xz = q.x * z2;\n float yy = q.y * y2;\n float yz = q.y * z2;\n float zz = q.z * z2;\n float wx = q.w * x2;\n float wy = q.w * y2;\n float wz = q.w * z2;\n return mat4(\n 1. - (yy + zz), xy + wz, xz - wy, 0,\n xy - wz, 1. - (xx + zz), yz + wx, 0,\n xz + wy, yz - wx, 1. - (xx + yy), 0,\n p.x, p.y, p.z, 1\n );\n}\nmat4 matFromRTS (vec4 q, vec3 t, vec3 s){\n float x = q.x, y = q.y, z = q.z, w = q.w;\n float x2 = x + x;\n float y2 = y + y;\n float z2 = z + z;\n float xx = x * x2;\n float xy = x * y2;\n float xz = x * z2;\n float yy = y * y2;\n float yz = y * z2;\n float zz = z * z2;\n float wx = w * x2;\n float wy = w * y2;\n float wz = w * z2;\n float sx = s.x;\n float sy = s.y;\n float sz = s.z;\n return mat4((1. - (yy + zz)) * sx, (xy + wz) * sx, (xz - wy) * sx, 0,\n (xy - wz) * sy, (1. - (xx + zz)) * sy, (yz + wx) * sy, 0,\n (xz + wy) * sz, (yz - wx) * sz, (1. - (xx + yy)) * sz, 0,\n t.x, t.y, t.z, 1);\n}\nvec4 quatMultiply (vec4 a, vec4 b){\n vec4 quat;\n quat.x = a.x * b.w + a.w * b.x + a.y * b.z - a.z * b.y;\n quat.y = a.y * b.w + a.w * b.y + a.z * b.x - a.x * b.z;\n quat.z = a.z * b.w + a.w * b.z + a.x * b.y - a.y * b.x;\n quat.w = a.w * b.w - a.x * b.x - a.y * b.y - a.z * b.z;\n return quat;\n}\nvoid rotateVecFromQuat (inout vec3 v, vec4 q){\n float ix = q.w * v.x + q.y * v.z - q.z * v.y;\n float iy = q.w * v.y + q.z * v.x - q.x * v.z;\n float iz = q.w * v.z + q.x * v.y - q.y * v.x;\n float iw = -q.x * v.x - q.y * v.y - q.z * v.z;\n v.x = ix * q.w + iw * -q.x + iy * -q.z - iz * -q.y;\n v.y = iy * q.w + iw * -q.y + iz * -q.x - ix * -q.z;\n v.z = iz * q.w + iw * -q.z + ix * -q.y - iy * -q.x;\n}\nvec3 rotateInLocalSpace (vec3 pos, vec3 xAxis, vec3 yAxis, vec3 zAxis, vec4 q){\n vec4 viewQuat = quaternionFromAxis(xAxis, yAxis, zAxis);\n vec4 rotQuat = quatMultiply(viewQuat, q);\n rotateVecFromQuat(pos, rotQuat);\n return pos;\n}\nvoid rotateCorner (inout vec2 corner, float angle){\n float xOS = cos(angle) * corner.x - sin(angle) * corner.y;\n float yOS = sin(angle) * corner.x + cos(angle) * corner.y;\n corner.x = xOS;\n corner.y = yOS;\n}\nuniform vec4 mainTiling_Offset;\nuniform vec4 frameTile_velLenScale;\nuniform vec4 scale;\nuniform highp mat4 cc_matView;\nuniform highp mat4 cc_matViewInv;\nuniform highp mat4 cc_matViewProj;\nuniform highp vec4 cc_cameraPos;\nuniform highp mat4 cc_matWorld;\nvarying vec2 uv;\nvarying vec4 color;\nvoid computeVertPos (inout vec4 pos, vec2 vertOffset, vec4 q, vec3 s\n#if CC_RENDER_MODE == 0 || CC_RENDER_MODE == 3\n , mat4 viewInv\n#endif\n#if CC_RENDER_MODE == 1\n , vec3 eye\n , vec4 velocity\n , float velocityScale\n , float lengthScale\n , float xIndex\n#endif\n) {\n#if CC_RENDER_MODE == 0\n vec3 viewSpaceVert = vec3(vertOffset.x * s.x, vertOffset.y * s.y, 0.);\n vec3 camX = normalize(vec3(viewInv[0][0], viewInv[1][0], viewInv[2][0]));\n vec3 camY = normalize(vec3(viewInv[0][1], viewInv[1][1], viewInv[2][1]));\n vec3 camZ = normalize(vec3(viewInv[0][2], viewInv[1][2], viewInv[2][2]));\n pos.xyz += rotateInLocalSpace(viewSpaceVert, camX, camY, camZ, q);\n#elif CC_RENDER_MODE == 1\n vec3 camRight = normalize(cross(pos.xyz - eye, velocity.xyz)) * s.x;\n vec3 camUp = velocity.xyz * velocityScale + normalize(velocity.xyz) * lengthScale * s.y;\n pos.xyz += (camRight * abs(vertOffset.x) * sign(vertOffset.y)) - camUp * xIndex;\n#elif CC_RENDER_MODE == 2\n vec3 viewSpaceVert = vec3(vertOffset.x * s.x, vertOffset.y * s.y, 0.);\n vec3 camX = vec3(1, 0, 0);\n vec3 camY = vec3(0, 0, -1);\n pos.xyz += rotateInLocalSpace(viewSpaceVert, camX, camY, cross(camX, camY), q);\n#elif CC_RENDER_MODE == 3\n vec2 viewSpaceVert = vec2(vertOffset.x * s.x, vertOffset.y * s.y);\n rotateCorner(viewSpaceVert, q.z);\n vec3 camX = normalize(vec3(cc_matView[0][0], cc_matView[1][0], cc_matView[2][0]));\n vec3 camY = vec3(0, 1, 0);\n vec3 offset = camX * viewSpaceVert.x + camY * viewSpaceVert.y;\n pos.xyz += offset;\n#else\n pos.x += vertOffset.x;\n pos.y += vertOffset.y;\n#endif\n}\nvec2 computeUV (float frameIndex, vec2 vertIndex, vec2 frameTile){\n vec2 aniUV = vec2(0, floor(frameIndex * frameTile.y));\n aniUV.x = floor(frameIndex * frameTile.x * frameTile.y - aniUV.y * frameTile.x);\n#if CC_RENDER_MODE != 4\n vertIndex.y = 1. - vertIndex.y;\n#endif\n return (aniUV.xy + vertIndex) / vec2(frameTile.x, frameTile.y);\n}\nuniform vec4 u_sampleInfo;\nuniform vec4 u_worldRot;\nuniform vec4 u_timeDelta;\nattribute vec4 a_position_starttime;\nattribute vec4 a_size_uv;\nattribute vec4 a_rotation_uv;\nattribute vec4 a_color;\nattribute vec4 a_dir_life;\nattribute float a_rndSeed;\n#if CC_RENDER_MODE == 4\n attribute vec3 a_texCoord;\n attribute vec3 a_texCoord3;\n attribute vec3 a_normal;\n attribute vec4 a_color1;\n#endif\nvec3 unpackCurveData (sampler2D tex, vec2 coord) {\n vec4 a = texture2D(tex, coord);\n vec4 b = texture2D(tex, coord + u_sampleInfo.y);\n float c = fract(coord.x * u_sampleInfo.x);\n return mix(a.xyz, b.xyz, c);\n}\nvec3 unpackCurveData (sampler2D tex, vec2 coord, out float w) {\n vec4 a = texture2D(tex, coord);\n vec4 b = texture2D(tex, coord + u_sampleInfo.y);\n float c = fract(coord.x * u_sampleInfo.x);\n w = mix(a.w, b.w, c);\n return mix(a.xyz, b.xyz, c);\n}\nfloat pseudoRandom (float seed) {\n seed = mod(seed, 233280.);\n float q = (seed * 9301. + 49297.) / 233280.;\n return fract(q);\n}\n#if COLOR_OVER_TIME_MODULE_ENABLE\n uniform sampler2D color_over_time_tex0;\n uniform int u_color_mode;\n#endif\n#if ROTATION_OVER_TIME_MODULE_ENABLE\n uniform sampler2D rotation_over_time_tex0;\n uniform int u_rotation_mode;\n#endif\n#if SIZE_OVER_TIME_MODULE_ENABLE\n uniform sampler2D size_over_time_tex0;\n uniform int u_size_mode;\n#endif\n#if FORCE_OVER_TIME_MODULE_ENABLE\n uniform sampler2D force_over_time_tex0;\n uniform int u_force_mode;\nuniform int u_force_space;\n#endif\n#if VELOCITY_OVER_TIME_MODULE_ENABLE\n uniform sampler2D velocity_over_time_tex0;\n uniform int u_velocity_mode;\nuniform int u_velocity_space;\n#endif\n#if TEXTURE_ANIMATION_MODULE_ENABLE\n uniform sampler2D texture_animation_tex0;\n uniform vec4 u_anim_info;\n#endif\nfloat repeat (float t, float length) {\n return t - floor(t / length) * length;\n}\nvec4 rotateQuat (vec4 p, vec4 q) {\n vec3 iv = cross(q.xyz, p.xyz) + q.w * p.xyz;\n vec3 res = p.xyz + 2.0 * cross(q.xyz, iv);\n return vec4(res.xyz, p.w);\n}\nvec4 gpvs_main () {\n float activeTime = u_timeDelta.x - a_position_starttime.w;\n float normalizedTime = clamp(activeTime / a_dir_life.w, 0.0, 1.0);\n vec2 timeCoord0 = vec2(normalizedTime, 0.);\n vec2 timeCoord1 = vec2(normalizedTime, 1.);\n #if CC_RENDER_MODE == 4\n vec2 vertIdx = vec2(a_texCoord.x, a_texCoord.y);\n #else\n vec2 vertIdx = vec2(a_size_uv.w, a_rotation_uv.w);\n #endif\n vec4 velocity = vec4(a_dir_life.xyz, 0.);\n vec4 pos = vec4(a_position_starttime.xyz, 1.);\n vec3 size = a_size_uv.xyz;\n #if SIZE_OVER_TIME_MODULE_ENABLE\n if (u_size_mode == 1) {\n size *= unpackCurveData(size_over_time_tex0, timeCoord0);\n } else {\n vec3 size_0 = unpackCurveData(size_over_time_tex0, timeCoord0);\n vec3 size_1 = unpackCurveData(size_over_time_tex0, timeCoord1);\n float factor_s = pseudoRandom(a_rndSeed + 39825.);\n size *= mix(size_0, size_1, factor_s);\n }\n #endif\n vec3 compScale = scale.xyz * size;\n #if FORCE_OVER_TIME_MODULE_ENABLE\n vec3 forceAnim = vec3(0.);\n if (u_force_mode == 1) {\n forceAnim = unpackCurveData(force_over_time_tex0, timeCoord0);\n } else {\n vec3 force_0 = unpackCurveData(force_over_time_tex0, timeCoord0);\n vec3 force_1 = unpackCurveData(force_over_time_tex0, timeCoord1);\n float factor_f = pseudoRandom(a_rndSeed + 212165.);\n forceAnim = mix(force_0, force_1, factor_f);\n }\n vec4 forceTrack = vec4(forceAnim, 0.);\n if (u_force_space == 0) {\n forceTrack = rotateQuat(forceTrack, u_worldRot);\n }\n velocity.xyz += forceTrack.xyz;\n #endif\n #if VELOCITY_OVER_TIME_MODULE_ENABLE\n float speedModifier0 = 1.;\n float speedModifier1 = 1.;\n vec3 velocityAnim = vec3(0.);\n if (u_velocity_mode == 1) {\n velocityAnim = unpackCurveData(velocity_over_time_tex0, timeCoord0, speedModifier0);\n } else {\n vec3 vectory_0 = unpackCurveData(velocity_over_time_tex0, timeCoord0, speedModifier0);\n vec3 vectory_1 = unpackCurveData(velocity_over_time_tex0, timeCoord1, speedModifier1);\n float factor_v = pseudoRandom(a_rndSeed + 197866.);\n velocityAnim = mix(vectory_0, vectory_1, factor_v);\n speedModifier0 = mix(speedModifier0, speedModifier1, factor_v);\n }\n vec4 velocityTrack = vec4(velocityAnim, 0.);\n if (u_velocity_space == 0) {\n velocityTrack = rotateQuat(velocityTrack, u_worldRot);\n }\n velocity.xyz += velocityTrack.xyz;\n velocity.xyz *= speedModifier0;\n #endif\n pos.xyz += velocity.xyz * normalizedTime * a_dir_life.w;\n #if !CC_USE_WORLD_SPACE\n pos = cc_matWorld * pos;\n #if CC_RENDER_MODE == 1\n velocity = rotateQuat(velocity, u_worldRot);\n #endif\n #endif\n vec3 rotation = a_rotation_uv.xyz;\n #if ROTATION_OVER_TIME_MODULE_ENABLE\n if (u_rotation_mode == 1) {\n rotation += unpackCurveData(rotation_over_time_tex0, timeCoord0) * normalizedTime * a_dir_life.w;\n } else {\n vec3 rotation_0 = unpackCurveData(rotation_over_time_tex0, timeCoord0);\n vec3 rotation_1 = unpackCurveData(rotation_over_time_tex0, timeCoord1);\n float factor_r = pseudoRandom(a_rndSeed + 125292.);\n rotation += mix(rotation_0, rotation_1, factor_r) * normalizedTime * a_dir_life.w;\n }\n #endif\n #if COLOR_OVER_TIME_MODULE_ENABLE\n if (u_color_mode == 1) {\n color = a_color * texture2D(color_over_time_tex0, timeCoord0);\n } else {\n vec4 color_0 = texture2D(color_over_time_tex0, timeCoord0);\n vec4 color_1 = texture2D(color_over_time_tex0, timeCoord1);\n float factor_c = pseudoRandom(a_rndSeed + 91041.);\n color = a_color * mix(color_0, color_1, factor_c);\n }\n #else\n color = a_color;\n #endif\n #if CC_RENDER_MODE != 4\n vec2 cornerOffset = vec2((vertIdx - 0.5));\n #if CC_RENDER_MODE == 0\n vec3 rotEuler = rotation.xyz;\n #elif CC_RENDER_MODE == 1\n vec3 rotEuler = vec3(0.);\n #else\n vec3 rotEuler = vec3(0., 0., rotation.z);\n #endif\n computeVertPos(pos, cornerOffset, quaternionFromEuler(rotEuler), compScale\n #if CC_RENDER_MODE == 0 || CC_RENDER_MODE == 3\n , cc_matViewInv\n #endif\n #if CC_RENDER_MODE == 1\n , cc_cameraPos.xyz\n , velocity\n , frameTile_velLenScale.z\n , frameTile_velLenScale.w\n , a_size_uv.w\n #endif\n );\n #else\n mat4 xformNoScale = matrixFromRT(quaternionFromEuler(rotation), pos.xyz);\n mat4 xform = matFromRTS(quaternionFromEuler(rotation), pos.xyz, compScale);\n pos = xform * vec4(a_texCoord3, 1);\n vec4 normal = xformNoScale * vec4(a_normal, 0);\n color *= a_color1;\n #endif\n pos = cc_matViewProj * pos;\n float frameIndex = 0.;\n #if TEXTURE_ANIMATION_MODULE_ENABLE\n float startFrame = 0.;\n vec3 frameInfo = vec3(0.);\n if (int(u_anim_info.x) == 1) {\n frameInfo = unpackCurveData(texture_animation_tex0, timeCoord0);\n } else {\n vec3 frameInfo0 = unpackCurveData(texture_animation_tex0, timeCoord0);\n vec3 frameInfo1 = unpackCurveData(texture_animation_tex0, timeCoord1);\n float factor_t = pseudoRandom(a_rndSeed + 90794.);\n frameInfo = mix(frameInfo0, frameInfo1, factor_t);\n }\n startFrame = frameInfo.x / u_anim_info.y;\n frameIndex = repeat(u_anim_info.z * (frameInfo.y + startFrame), 1.);\n #endif\n uv = computeUV(frameIndex, vertIdx, frameTile_velLenScale.xy) * mainTiling_Offset.xy + mainTiling_Offset.zw;\n return pos;\n}\nvoid main() { gl_Position = gpvs_main(); }`, @@ -155,8 +155,8 @@ export default [ "name": "builtin-particle-trail|particle-trail:vs_main|tinted-fs:add", "hash": 535523547, "glsl3": { - "vert": `\nprecision mediump float;\nuniform Constants {\n vec4 mainTiling_Offset;\n vec4 frameTile_velLenScale;\n vec4 scale;\n};\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\nuniform CCLocal {\n highp mat4 cc_matWorld;\n highp mat4 cc_matWorldIT;\n highp vec4 cc_lightingMapUVParam;\n};\nout vec2 uv;\nout vec4 color;\nin vec3 a_position;\nin vec4 a_texCoord;\nin vec3 a_texCoord1;\nin vec3 a_texCoord2;\nin vec4 a_color;\n#if CC_DRAW_WIRE_FRAME\n out vec3 vBarycentric;\n#endif\nvec4 vs_main() {\n highp vec4 pos = vec4(a_position, 1);\n vec4 velocity = vec4(a_texCoord1.xyz, 0);\n #if !CC_USE_WORLD_SPACE\n pos = cc_matWorld * pos;\n velocity = cc_matWorld * velocity;\n #endif\n float vertOffset = (a_texCoord.x - 0.5) * a_texCoord.y;\n vec3 camUp = normalize(cross(pos.xyz - cc_cameraPos.xyz, velocity.xyz));\n pos.xyz += camUp * vertOffset;\n pos = cc_matViewProj * pos;\n uv = a_texCoord.zw * mainTiling_Offset.xy + mainTiling_Offset.zw;;\n color = a_color;\n #if CC_DRAW_WIRE_FRAME\n vBarycentric = a_texCoord2;\n #endif\n return pos;\n}\nvoid main() { gl_Position = vs_main(); }`, - "frag": `\n precision mediump float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\n}\nvec4 CCFragOutput (vec4 color) {\n #if CC_USE_HDR\n color.rgb = mix(color.rgb, SRGBToLinear(color.rgb) * cc_exposure.w, vec3(cc_exposure.z));\n #endif\n return color;\n}\n in vec2 uv;\n in vec4 color;\n #if CC_DRAW_WIRE_FRAME\n in vec3 vBarycentric;\n #endif\n uniform sampler2D mainTexture;\n uniform FragConstants {\n vec4 tintColor;\n };\n vec4 add () {\n vec4 col = 2.0 * color * tintColor * texture(mainTexture, uv);\n#if CC_DRAW_WIRE_FRAME\n if (any(lessThan(vBarycentric, vec3(0.02)))) {\n col = vec4(0., 1., 1., 1.);\n }\n#endif\n return CCFragOutput(col);\n }\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = add(); }` + "vert": `\nprecision mediump float;\nuniform Constants {\n vec4 mainTiling_Offset;\n vec4 frameTile_velLenScale;\n vec4 scale;\n};\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n};\nuniform CCLocal {\n highp mat4 cc_matWorld;\n highp mat4 cc_matWorldIT;\n highp vec4 cc_lightingMapUVParam;\n};\nout vec2 uv;\nout vec4 color;\nin vec3 a_position;\nin vec4 a_texCoord;\nin vec3 a_texCoord1;\nin vec3 a_texCoord2;\nin vec4 a_color;\n#if CC_DRAW_WIRE_FRAME\n out vec3 vBarycentric;\n#endif\nvec4 vs_main() {\n highp vec4 pos = vec4(a_position, 1);\n vec4 velocity = vec4(a_texCoord1.xyz, 0);\n #if !CC_USE_WORLD_SPACE\n pos = cc_matWorld * pos;\n velocity = cc_matWorld * velocity;\n #endif\n float vertOffset = (a_texCoord.x - 0.5) * a_texCoord.y;\n vec3 camUp = normalize(cross(pos.xyz - cc_cameraPos.xyz, velocity.xyz));\n pos.xyz += camUp * vertOffset;\n pos = cc_matViewProj * pos;\n uv = a_texCoord.zw * mainTiling_Offset.xy + mainTiling_Offset.zw;;\n color = a_color;\n #if CC_DRAW_WIRE_FRAME\n vBarycentric = a_texCoord2;\n #endif\n return pos;\n}\nvoid main() { gl_Position = vs_main(); }`, + "frag": `\n precision mediump float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n};\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\n}\nvec4 CCFragOutput (vec4 color) {\n #if CC_USE_HDR\n color.rgb = mix(color.rgb, SRGBToLinear(color.rgb) * cc_exposure.w, vec3(cc_exposure.z));\n #endif\n return color;\n}\n in vec2 uv;\n in vec4 color;\n #if CC_DRAW_WIRE_FRAME\n in vec3 vBarycentric;\n #endif\n uniform sampler2D mainTexture;\n uniform FragConstants {\n vec4 tintColor;\n };\n vec4 add () {\n vec4 col = 2.0 * color * tintColor * texture(mainTexture, uv);\n#if CC_DRAW_WIRE_FRAME\n if (any(lessThan(vBarycentric, vec3(0.02)))) {\n col = vec4(0., 1., 1., 1.);\n }\n#endif\n return CCFragOutput(col);\n }\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = add(); }` }, "glsl1": { "vert": `\nprecision mediump float;\nuniform vec4 mainTiling_Offset;\nuniform highp mat4 cc_matViewProj;\nuniform highp vec4 cc_cameraPos;\nuniform highp mat4 cc_matWorld;\nvarying vec2 uv;\nvarying vec4 color;\nattribute vec3 a_position;\nattribute vec4 a_texCoord;\nattribute vec3 a_texCoord1;\nattribute vec3 a_texCoord2;\nattribute vec4 a_color;\n#if CC_DRAW_WIRE_FRAME\n varying vec3 vBarycentric;\n#endif\nvec4 vs_main() {\n highp vec4 pos = vec4(a_position, 1);\n vec4 velocity = vec4(a_texCoord1.xyz, 0);\n #if !CC_USE_WORLD_SPACE\n pos = cc_matWorld * pos;\n velocity = cc_matWorld * velocity;\n #endif\n float vertOffset = (a_texCoord.x - 0.5) * a_texCoord.y;\n vec3 camUp = normalize(cross(pos.xyz - cc_cameraPos.xyz, velocity.xyz));\n pos.xyz += camUp * vertOffset;\n pos = cc_matViewProj * pos;\n uv = a_texCoord.zw * mainTiling_Offset.xy + mainTiling_Offset.zw;;\n color = a_color;\n #if CC_DRAW_WIRE_FRAME\n vBarycentric = a_texCoord2;\n #endif\n return pos;\n}\nvoid main() { gl_Position = vs_main(); }`, @@ -167,7 +167,7 @@ export default [ "locals": { "blocks": [{ "name": "CCLocal", "defines": [] }], "samplers": [] } }, "defines": [ - { "name": "CC_RENDER_MODE", "type": "number", "dummyDependency": true, "range": [0, 4] }, + { "name": "CC_RENDER_MODE", "type": "number", "range": [0, 4] }, { "name": "CC_DRAW_WIRE_FRAME", "type": "boolean" }, { "name": "CC_USE_WORLD_SPACE", "type": "boolean" }, { "name": "CC_USE_HDR", "type": "boolean" } @@ -206,8 +206,8 @@ export default [ "name": "builtin-particle|particle-vs-legacy:lpvs_main|tinted-fs:add", "hash": 2171161221, "glsl3": { - "vert": `\nprecision highp float;\nvec4 quaternionFromAxis (vec3 xAxis,vec3 yAxis,vec3 zAxis){\n mat3 m = mat3(xAxis,yAxis,zAxis);\n float trace = m[0][0] + m[1][1] + m[2][2];\n vec4 quat;\n if (trace > 0.) {\n float s = 0.5 / sqrt(trace + 1.0);\n quat.w = 0.25 / s;\n quat.x = (m[2][1] - m[1][2]) * s;\n quat.y = (m[0][2] - m[2][0]) * s;\n quat.z = (m[1][0] - m[0][1]) * s;\n } else if ((m[0][0] > m[1][1]) && (m[0][0] > m[2][2])) {\n float s = 2.0 * sqrt(1.0 + m[0][0] - m[1][1] - m[2][2]);\n quat.w = (m[2][1] - m[1][2]) / s;\n quat.x = 0.25 * s;\n quat.y = (m[0][1] + m[1][0]) / s;\n quat.z = (m[0][2] + m[2][0]) / s;\n } else if (m[1][1] > m[2][2]) {\n float s = 2.0 * sqrt(1.0 + m[1][1] - m[0][0] - m[2][2]);\n quat.w = (m[0][2] - m[2][0]) / s;\n quat.x = (m[0][1] + m[1][0]) / s;\n quat.y = 0.25 * s;\n quat.z = (m[1][2] + m[2][1]) / s;\n } else {\n float s = 2.0 * sqrt(1.0 + m[2][2] - m[0][0] - m[1][1]);\n quat.w = (m[1][0] - m[0][1]) / s;\n quat.x = (m[0][2] + m[2][0]) / s;\n quat.y = (m[1][2] + m[2][1]) / s;\n quat.z = 0.25 * s;\n }\n float len = quat.x * quat.x + quat.y * quat.y + quat.z * quat.z + quat.w * quat.w;\n if (len > 0.) {\n len = 1. / sqrt(len);\n quat.x = quat.x * len;\n quat.y = quat.y * len;\n quat.z = quat.z * len;\n quat.w = quat.w * len;\n }\n return quat;\n}\nvec4 quaternionFromEuler (vec3 angle){\n float x = angle.x / 2.;\n float y = angle.y / 2.;\n float z = angle.z / 2.;\n float sx = sin(x);\n float cx = cos(x);\n float sy = sin(y);\n float cy = cos(y);\n float sz = sin(z);\n float cz = cos(z);\n vec4 quat = vec4(0);\n quat.x = sx * cy * cz + cx * sy * sz;\n quat.y = cx * sy * cz + sx * cy * sz;\n quat.z = cx * cy * sz - sx * sy * cz;\n quat.w = cx * cy * cz - sx * sy * sz;\n return quat;\n}\nmat4 matrixFromRT (vec4 q, vec3 p){\n float x2 = q.x + q.x;\n float y2 = q.y + q.y;\n float z2 = q.z + q.z;\n float xx = q.x * x2;\n float xy = q.x * y2;\n float xz = q.x * z2;\n float yy = q.y * y2;\n float yz = q.y * z2;\n float zz = q.z * z2;\n float wx = q.w * x2;\n float wy = q.w * y2;\n float wz = q.w * z2;\n return mat4(\n 1. - (yy + zz), xy + wz, xz - wy, 0,\n xy - wz, 1. - (xx + zz), yz + wx, 0,\n xz + wy, yz - wx, 1. - (xx + yy), 0,\n p.x, p.y, p.z, 1\n );\n}\nmat4 matFromRTS (vec4 q, vec3 t, vec3 s){\n float x = q.x, y = q.y, z = q.z, w = q.w;\n float x2 = x + x;\n float y2 = y + y;\n float z2 = z + z;\n float xx = x * x2;\n float xy = x * y2;\n float xz = x * z2;\n float yy = y * y2;\n float yz = y * z2;\n float zz = z * z2;\n float wx = w * x2;\n float wy = w * y2;\n float wz = w * z2;\n float sx = s.x;\n float sy = s.y;\n float sz = s.z;\n return mat4((1. - (yy + zz)) * sx, (xy + wz) * sx, (xz - wy) * sx, 0,\n (xy - wz) * sy, (1. - (xx + zz)) * sy, (yz + wx) * sy, 0,\n (xz + wy) * sz, (yz - wx) * sz, (1. - (xx + yy)) * sz, 0,\n t.x, t.y, t.z, 1);\n}\nvec4 quatMultiply (vec4 a, vec4 b){\n vec4 quat;\n quat.x = a.x * b.w + a.w * b.x + a.y * b.z - a.z * b.y;\n quat.y = a.y * b.w + a.w * b.y + a.z * b.x - a.x * b.z;\n quat.z = a.z * b.w + a.w * b.z + a.x * b.y - a.y * b.x;\n quat.w = a.w * b.w - a.x * b.x - a.y * b.y - a.z * b.z;\n return quat;\n}\nvoid rotateVecFromQuat (inout vec3 v, vec4 q){\n float ix = q.w * v.x + q.y * v.z - q.z * v.y;\n float iy = q.w * v.y + q.z * v.x - q.x * v.z;\n float iz = q.w * v.z + q.x * v.y - q.y * v.x;\n float iw = -q.x * v.x - q.y * v.y - q.z * v.z;\n v.x = ix * q.w + iw * -q.x + iy * -q.z - iz * -q.y;\n v.y = iy * q.w + iw * -q.y + iz * -q.x - ix * -q.z;\n v.z = iz * q.w + iw * -q.z + ix * -q.y - iy * -q.x;\n}\nvec3 rotateInLocalSpace (vec3 pos, vec3 xAxis, vec3 yAxis, vec3 zAxis, vec4 q){\n vec4 viewQuat = quaternionFromAxis(xAxis, yAxis, zAxis);\n vec4 rotQuat = quatMultiply(viewQuat, q);\n rotateVecFromQuat(pos, rotQuat);\n return pos;\n}\nvoid rotateCorner (inout vec2 corner, float angle){\n float xOS = cos(angle) * corner.x - sin(angle) * corner.y;\n float yOS = sin(angle) * corner.x + cos(angle) * corner.y;\n corner.x = xOS;\n corner.y = yOS;\n}\nuniform Constants {\n vec4 mainTiling_Offset;\n vec4 frameTile_velLenScale;\n vec4 scale;\n};\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\nuniform CCLocal {\n highp mat4 cc_matWorld;\n highp mat4 cc_matWorldIT;\n highp vec4 cc_lightingMapUVParam;\n};\nout vec2 uv;\nout vec4 color;\nvoid computeVertPos (inout vec4 pos, vec2 vertOffset, vec4 q, vec3 s\n#if CC_RENDER_MODE == 0 || CC_RENDER_MODE == 3\n , mat4 viewInv\n#endif\n#if CC_RENDER_MODE == 1\n , vec3 eye\n , vec4 velocity\n , float velocityScale\n , float lengthScale\n , float xIndex\n#endif\n) {\n#if CC_RENDER_MODE == 0\n vec3 viewSpaceVert = vec3(vertOffset.x * s.x, vertOffset.y * s.y, 0.);\n vec3 camX = normalize(vec3(viewInv[0][0], viewInv[1][0], viewInv[2][0]));\n vec3 camY = normalize(vec3(viewInv[0][1], viewInv[1][1], viewInv[2][1]));\n vec3 camZ = normalize(vec3(viewInv[0][2], viewInv[1][2], viewInv[2][2]));\n pos.xyz += rotateInLocalSpace(viewSpaceVert, camX, camY, camZ, q);\n#elif CC_RENDER_MODE == 1\n vec3 camRight = normalize(cross(pos.xyz - eye, velocity.xyz)) * s.x;\n vec3 camUp = velocity.xyz * velocityScale + normalize(velocity.xyz) * lengthScale * s.y;\n pos.xyz += (camRight * abs(vertOffset.x) * sign(vertOffset.y)) - camUp * xIndex;\n#elif CC_RENDER_MODE == 2\n vec3 viewSpaceVert = vec3(vertOffset.x * s.x, vertOffset.y * s.y, 0.);\n vec3 camX = vec3(1, 0, 0);\n vec3 camY = vec3(0, 0, -1);\n pos.xyz += rotateInLocalSpace(viewSpaceVert, camX, camY, cross(camX, camY), q);\n#elif CC_RENDER_MODE == 3\n vec2 viewSpaceVert = vec2(vertOffset.x * s.x, vertOffset.y * s.y);\n rotateCorner(viewSpaceVert, q.z);\n vec3 camX = normalize(vec3(cc_matView[0][0], cc_matView[1][0], cc_matView[2][0]));\n vec3 camY = vec3(0, 1, 0);\n vec3 offset = camX * viewSpaceVert.x + camY * viewSpaceVert.y;\n pos.xyz += offset;\n#else\n pos.x += vertOffset.x;\n pos.y += vertOffset.y;\n#endif\n}\nvec2 computeUV (float frameIndex, vec2 vertIndex, vec2 frameTile){\n vec2 aniUV = vec2(0, floor(frameIndex * frameTile.y));\n aniUV.x = floor(frameIndex * frameTile.x * frameTile.y - aniUV.y * frameTile.x);\n#if CC_RENDER_MODE != 4\n vertIndex.y = 1. - vertIndex.y;\n#endif\n return (aniUV.xy + vertIndex) / vec2(frameTile.x, frameTile.y);\n}\nin vec3 a_position;\nin vec3 a_texCoord;\nin vec3 a_texCoord1;\nin vec3 a_texCoord2;\nin vec4 a_color;\n#if CC_RENDER_MODE == 1\n in vec3 a_color1;\n#endif\n#if CC_RENDER_MODE == 4\n in vec3 a_texCoord3;\n in vec3 a_normal;\n in vec4 a_color1;\n#endif\nvec4 lpvs_main () {\n vec3 compScale = scale.xyz * a_texCoord1;\n vec4 pos = vec4(a_position, 1);\n #if CC_RENDER_MODE == 1\n vec4 velocity = vec4(a_color1.xyz, 0);\n #endif\n #if !CC_USE_WORLD_SPACE\n pos = cc_matWorld * pos;\n #if CC_RENDER_MODE == 1\n velocity = cc_matWorld * velocity;\n #endif\n #endif\n #if CC_RENDER_MODE != 4\n vec2 cornerOffset = vec2((a_texCoord.xy - 0.5));\n #if CC_RENDER_MODE == 0\n vec3 rotEuler = a_texCoord2;\n #elif CC_RENDER_MODE == 1\n vec3 rotEuler = vec3(0.);\n #else\n vec3 rotEuler = vec3(0., 0., a_texCoord2.z);\n #endif\n computeVertPos(pos, cornerOffset, quaternionFromEuler(rotEuler), compScale\n #if CC_RENDER_MODE == 0 || CC_RENDER_MODE == 3\n , cc_matViewInv\n #endif\n #if CC_RENDER_MODE == 1\n , cc_cameraPos.xyz\n , velocity\n , frameTile_velLenScale.z\n , frameTile_velLenScale.w\n , a_texCoord.x\n #endif\n );\n color = a_color;\n #else\n mat4 xformNoScale = matrixFromRT(quaternionFromEuler(a_texCoord2), pos.xyz);\n mat4 xform = matFromRTS(quaternionFromEuler(a_texCoord2), pos.xyz, compScale);\n pos = xform * vec4(a_texCoord3, 1);\n vec4 normal = xformNoScale * vec4(a_normal, 0);\n color = a_color * a_color1;\n #endif\n uv = computeUV(a_texCoord.z, a_texCoord.xy, frameTile_velLenScale.xy) * mainTiling_Offset.xy + mainTiling_Offset.zw;\n pos = cc_matViewProj * pos;\n return pos;\n}\nvoid main() { gl_Position = lpvs_main(); }`, - "frag": `\nprecision mediump float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\n}\nvec4 CCFragOutput (vec4 color) {\n #if CC_USE_HDR\n color.rgb = mix(color.rgb, SRGBToLinear(color.rgb) * cc_exposure.w, vec3(cc_exposure.z));\n #endif\n return color;\n}\nin vec2 uv;\nin vec4 color;\nuniform sampler2D mainTexture;\nuniform FragConstants {\n vec4 tintColor;\n};\nvec4 add () {\n vec4 col = 2.0 * color * tintColor * texture(mainTexture, uv);\n return CCFragOutput(col);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = add(); }` + "vert": `\nprecision highp float;\nvec4 quaternionFromAxis (vec3 xAxis,vec3 yAxis,vec3 zAxis){\n mat3 m = mat3(xAxis,yAxis,zAxis);\n float trace = m[0][0] + m[1][1] + m[2][2];\n vec4 quat;\n if (trace > 0.) {\n float s = 0.5 / sqrt(trace + 1.0);\n quat.w = 0.25 / s;\n quat.x = (m[2][1] - m[1][2]) * s;\n quat.y = (m[0][2] - m[2][0]) * s;\n quat.z = (m[1][0] - m[0][1]) * s;\n } else if ((m[0][0] > m[1][1]) && (m[0][0] > m[2][2])) {\n float s = 2.0 * sqrt(1.0 + m[0][0] - m[1][1] - m[2][2]);\n quat.w = (m[2][1] - m[1][2]) / s;\n quat.x = 0.25 * s;\n quat.y = (m[0][1] + m[1][0]) / s;\n quat.z = (m[0][2] + m[2][0]) / s;\n } else if (m[1][1] > m[2][2]) {\n float s = 2.0 * sqrt(1.0 + m[1][1] - m[0][0] - m[2][2]);\n quat.w = (m[0][2] - m[2][0]) / s;\n quat.x = (m[0][1] + m[1][0]) / s;\n quat.y = 0.25 * s;\n quat.z = (m[1][2] + m[2][1]) / s;\n } else {\n float s = 2.0 * sqrt(1.0 + m[2][2] - m[0][0] - m[1][1]);\n quat.w = (m[1][0] - m[0][1]) / s;\n quat.x = (m[0][2] + m[2][0]) / s;\n quat.y = (m[1][2] + m[2][1]) / s;\n quat.z = 0.25 * s;\n }\n float len = quat.x * quat.x + quat.y * quat.y + quat.z * quat.z + quat.w * quat.w;\n if (len > 0.) {\n len = 1. / sqrt(len);\n quat.x = quat.x * len;\n quat.y = quat.y * len;\n quat.z = quat.z * len;\n quat.w = quat.w * len;\n }\n return quat;\n}\nvec4 quaternionFromEuler (vec3 angle){\n float x = angle.x / 2.;\n float y = angle.y / 2.;\n float z = angle.z / 2.;\n float sx = sin(x);\n float cx = cos(x);\n float sy = sin(y);\n float cy = cos(y);\n float sz = sin(z);\n float cz = cos(z);\n vec4 quat = vec4(0);\n quat.x = sx * cy * cz + cx * sy * sz;\n quat.y = cx * sy * cz + sx * cy * sz;\n quat.z = cx * cy * sz - sx * sy * cz;\n quat.w = cx * cy * cz - sx * sy * sz;\n return quat;\n}\nmat4 matrixFromRT (vec4 q, vec3 p){\n float x2 = q.x + q.x;\n float y2 = q.y + q.y;\n float z2 = q.z + q.z;\n float xx = q.x * x2;\n float xy = q.x * y2;\n float xz = q.x * z2;\n float yy = q.y * y2;\n float yz = q.y * z2;\n float zz = q.z * z2;\n float wx = q.w * x2;\n float wy = q.w * y2;\n float wz = q.w * z2;\n return mat4(\n 1. - (yy + zz), xy + wz, xz - wy, 0,\n xy - wz, 1. - (xx + zz), yz + wx, 0,\n xz + wy, yz - wx, 1. - (xx + yy), 0,\n p.x, p.y, p.z, 1\n );\n}\nmat4 matFromRTS (vec4 q, vec3 t, vec3 s){\n float x = q.x, y = q.y, z = q.z, w = q.w;\n float x2 = x + x;\n float y2 = y + y;\n float z2 = z + z;\n float xx = x * x2;\n float xy = x * y2;\n float xz = x * z2;\n float yy = y * y2;\n float yz = y * z2;\n float zz = z * z2;\n float wx = w * x2;\n float wy = w * y2;\n float wz = w * z2;\n float sx = s.x;\n float sy = s.y;\n float sz = s.z;\n return mat4((1. - (yy + zz)) * sx, (xy + wz) * sx, (xz - wy) * sx, 0,\n (xy - wz) * sy, (1. - (xx + zz)) * sy, (yz + wx) * sy, 0,\n (xz + wy) * sz, (yz - wx) * sz, (1. - (xx + yy)) * sz, 0,\n t.x, t.y, t.z, 1);\n}\nvec4 quatMultiply (vec4 a, vec4 b){\n vec4 quat;\n quat.x = a.x * b.w + a.w * b.x + a.y * b.z - a.z * b.y;\n quat.y = a.y * b.w + a.w * b.y + a.z * b.x - a.x * b.z;\n quat.z = a.z * b.w + a.w * b.z + a.x * b.y - a.y * b.x;\n quat.w = a.w * b.w - a.x * b.x - a.y * b.y - a.z * b.z;\n return quat;\n}\nvoid rotateVecFromQuat (inout vec3 v, vec4 q){\n float ix = q.w * v.x + q.y * v.z - q.z * v.y;\n float iy = q.w * v.y + q.z * v.x - q.x * v.z;\n float iz = q.w * v.z + q.x * v.y - q.y * v.x;\n float iw = -q.x * v.x - q.y * v.y - q.z * v.z;\n v.x = ix * q.w + iw * -q.x + iy * -q.z - iz * -q.y;\n v.y = iy * q.w + iw * -q.y + iz * -q.x - ix * -q.z;\n v.z = iz * q.w + iw * -q.z + ix * -q.y - iy * -q.x;\n}\nvec3 rotateInLocalSpace (vec3 pos, vec3 xAxis, vec3 yAxis, vec3 zAxis, vec4 q){\n vec4 viewQuat = quaternionFromAxis(xAxis, yAxis, zAxis);\n vec4 rotQuat = quatMultiply(viewQuat, q);\n rotateVecFromQuat(pos, rotQuat);\n return pos;\n}\nvoid rotateCorner (inout vec2 corner, float angle){\n float xOS = cos(angle) * corner.x - sin(angle) * corner.y;\n float yOS = sin(angle) * corner.x + cos(angle) * corner.y;\n corner.x = xOS;\n corner.y = yOS;\n}\nuniform Constants {\n vec4 mainTiling_Offset;\n vec4 frameTile_velLenScale;\n vec4 scale;\n};\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n};\nuniform CCLocal {\n highp mat4 cc_matWorld;\n highp mat4 cc_matWorldIT;\n highp vec4 cc_lightingMapUVParam;\n};\nout vec2 uv;\nout vec4 color;\nvoid computeVertPos (inout vec4 pos, vec2 vertOffset, vec4 q, vec3 s\n#if CC_RENDER_MODE == 0 || CC_RENDER_MODE == 3\n , mat4 viewInv\n#endif\n#if CC_RENDER_MODE == 1\n , vec3 eye\n , vec4 velocity\n , float velocityScale\n , float lengthScale\n , float xIndex\n#endif\n) {\n#if CC_RENDER_MODE == 0\n vec3 viewSpaceVert = vec3(vertOffset.x * s.x, vertOffset.y * s.y, 0.);\n vec3 camX = normalize(vec3(viewInv[0][0], viewInv[1][0], viewInv[2][0]));\n vec3 camY = normalize(vec3(viewInv[0][1], viewInv[1][1], viewInv[2][1]));\n vec3 camZ = normalize(vec3(viewInv[0][2], viewInv[1][2], viewInv[2][2]));\n pos.xyz += rotateInLocalSpace(viewSpaceVert, camX, camY, camZ, q);\n#elif CC_RENDER_MODE == 1\n vec3 camRight = normalize(cross(pos.xyz - eye, velocity.xyz)) * s.x;\n vec3 camUp = velocity.xyz * velocityScale + normalize(velocity.xyz) * lengthScale * s.y;\n pos.xyz += (camRight * abs(vertOffset.x) * sign(vertOffset.y)) - camUp * xIndex;\n#elif CC_RENDER_MODE == 2\n vec3 viewSpaceVert = vec3(vertOffset.x * s.x, vertOffset.y * s.y, 0.);\n vec3 camX = vec3(1, 0, 0);\n vec3 camY = vec3(0, 0, -1);\n pos.xyz += rotateInLocalSpace(viewSpaceVert, camX, camY, cross(camX, camY), q);\n#elif CC_RENDER_MODE == 3\n vec2 viewSpaceVert = vec2(vertOffset.x * s.x, vertOffset.y * s.y);\n rotateCorner(viewSpaceVert, q.z);\n vec3 camX = normalize(vec3(cc_matView[0][0], cc_matView[1][0], cc_matView[2][0]));\n vec3 camY = vec3(0, 1, 0);\n vec3 offset = camX * viewSpaceVert.x + camY * viewSpaceVert.y;\n pos.xyz += offset;\n#else\n pos.x += vertOffset.x;\n pos.y += vertOffset.y;\n#endif\n}\nvec2 computeUV (float frameIndex, vec2 vertIndex, vec2 frameTile){\n vec2 aniUV = vec2(0, floor(frameIndex * frameTile.y));\n aniUV.x = floor(frameIndex * frameTile.x * frameTile.y - aniUV.y * frameTile.x);\n#if CC_RENDER_MODE != 4\n vertIndex.y = 1. - vertIndex.y;\n#endif\n return (aniUV.xy + vertIndex) / vec2(frameTile.x, frameTile.y);\n}\nin vec3 a_position;\nin vec3 a_texCoord;\nin vec3 a_texCoord1;\nin vec3 a_texCoord2;\nin vec4 a_color;\n#if CC_RENDER_MODE == 1\n in vec3 a_color1;\n#endif\n#if CC_RENDER_MODE == 4\n in vec3 a_texCoord3;\n in vec3 a_normal;\n in vec4 a_color1;\n#endif\nvec4 lpvs_main () {\n vec3 compScale = scale.xyz * a_texCoord1;\n vec4 pos = vec4(a_position, 1);\n #if CC_RENDER_MODE == 1\n vec4 velocity = vec4(a_color1.xyz, 0);\n #endif\n #if !CC_USE_WORLD_SPACE\n pos = cc_matWorld * pos;\n #if CC_RENDER_MODE == 1\n velocity = cc_matWorld * velocity;\n #endif\n #endif\n #if CC_RENDER_MODE != 4\n vec2 cornerOffset = vec2((a_texCoord.xy - 0.5));\n #if CC_RENDER_MODE == 0\n vec3 rotEuler = a_texCoord2;\n #elif CC_RENDER_MODE == 1\n vec3 rotEuler = vec3(0.);\n #else\n vec3 rotEuler = vec3(0., 0., a_texCoord2.z);\n #endif\n computeVertPos(pos, cornerOffset, quaternionFromEuler(rotEuler), compScale\n #if CC_RENDER_MODE == 0 || CC_RENDER_MODE == 3\n , cc_matViewInv\n #endif\n #if CC_RENDER_MODE == 1\n , cc_cameraPos.xyz\n , velocity\n , frameTile_velLenScale.z\n , frameTile_velLenScale.w\n , a_texCoord.x\n #endif\n );\n color = a_color;\n #else\n mat4 xformNoScale = matrixFromRT(quaternionFromEuler(a_texCoord2), pos.xyz);\n mat4 xform = matFromRTS(quaternionFromEuler(a_texCoord2), pos.xyz, compScale);\n pos = xform * vec4(a_texCoord3, 1);\n vec4 normal = xformNoScale * vec4(a_normal, 0);\n color = a_color * a_color1;\n #endif\n uv = computeUV(a_texCoord.z, a_texCoord.xy, frameTile_velLenScale.xy) * mainTiling_Offset.xy + mainTiling_Offset.zw;\n pos = cc_matViewProj * pos;\n return pos;\n}\nvoid main() { gl_Position = lpvs_main(); }`, + "frag": `\nprecision mediump float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n};\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\n}\nvec4 CCFragOutput (vec4 color) {\n #if CC_USE_HDR\n color.rgb = mix(color.rgb, SRGBToLinear(color.rgb) * cc_exposure.w, vec3(cc_exposure.z));\n #endif\n return color;\n}\nin vec2 uv;\nin vec4 color;\nuniform sampler2D mainTexture;\nuniform FragConstants {\n vec4 tintColor;\n};\nvec4 add () {\n vec4 col = 2.0 * color * tintColor * texture(mainTexture, uv);\n return CCFragOutput(col);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = add(); }` }, "glsl1": { "vert": `\nprecision highp float;\nvec4 quaternionFromAxis (vec3 xAxis,vec3 yAxis,vec3 zAxis){\n mat3 m = mat3(xAxis,yAxis,zAxis);\n float trace = m[0][0] + m[1][1] + m[2][2];\n vec4 quat;\n if (trace > 0.) {\n float s = 0.5 / sqrt(trace + 1.0);\n quat.w = 0.25 / s;\n quat.x = (m[2][1] - m[1][2]) * s;\n quat.y = (m[0][2] - m[2][0]) * s;\n quat.z = (m[1][0] - m[0][1]) * s;\n } else if ((m[0][0] > m[1][1]) && (m[0][0] > m[2][2])) {\n float s = 2.0 * sqrt(1.0 + m[0][0] - m[1][1] - m[2][2]);\n quat.w = (m[2][1] - m[1][2]) / s;\n quat.x = 0.25 * s;\n quat.y = (m[0][1] + m[1][0]) / s;\n quat.z = (m[0][2] + m[2][0]) / s;\n } else if (m[1][1] > m[2][2]) {\n float s = 2.0 * sqrt(1.0 + m[1][1] - m[0][0] - m[2][2]);\n quat.w = (m[0][2] - m[2][0]) / s;\n quat.x = (m[0][1] + m[1][0]) / s;\n quat.y = 0.25 * s;\n quat.z = (m[1][2] + m[2][1]) / s;\n } else {\n float s = 2.0 * sqrt(1.0 + m[2][2] - m[0][0] - m[1][1]);\n quat.w = (m[1][0] - m[0][1]) / s;\n quat.x = (m[0][2] + m[2][0]) / s;\n quat.y = (m[1][2] + m[2][1]) / s;\n quat.z = 0.25 * s;\n }\n float len = quat.x * quat.x + quat.y * quat.y + quat.z * quat.z + quat.w * quat.w;\n if (len > 0.) {\n len = 1. / sqrt(len);\n quat.x = quat.x * len;\n quat.y = quat.y * len;\n quat.z = quat.z * len;\n quat.w = quat.w * len;\n }\n return quat;\n}\nvec4 quaternionFromEuler (vec3 angle){\n float x = angle.x / 2.;\n float y = angle.y / 2.;\n float z = angle.z / 2.;\n float sx = sin(x);\n float cx = cos(x);\n float sy = sin(y);\n float cy = cos(y);\n float sz = sin(z);\n float cz = cos(z);\n vec4 quat = vec4(0);\n quat.x = sx * cy * cz + cx * sy * sz;\n quat.y = cx * sy * cz + sx * cy * sz;\n quat.z = cx * cy * sz - sx * sy * cz;\n quat.w = cx * cy * cz - sx * sy * sz;\n return quat;\n}\nmat4 matrixFromRT (vec4 q, vec3 p){\n float x2 = q.x + q.x;\n float y2 = q.y + q.y;\n float z2 = q.z + q.z;\n float xx = q.x * x2;\n float xy = q.x * y2;\n float xz = q.x * z2;\n float yy = q.y * y2;\n float yz = q.y * z2;\n float zz = q.z * z2;\n float wx = q.w * x2;\n float wy = q.w * y2;\n float wz = q.w * z2;\n return mat4(\n 1. - (yy + zz), xy + wz, xz - wy, 0,\n xy - wz, 1. - (xx + zz), yz + wx, 0,\n xz + wy, yz - wx, 1. - (xx + yy), 0,\n p.x, p.y, p.z, 1\n );\n}\nmat4 matFromRTS (vec4 q, vec3 t, vec3 s){\n float x = q.x, y = q.y, z = q.z, w = q.w;\n float x2 = x + x;\n float y2 = y + y;\n float z2 = z + z;\n float xx = x * x2;\n float xy = x * y2;\n float xz = x * z2;\n float yy = y * y2;\n float yz = y * z2;\n float zz = z * z2;\n float wx = w * x2;\n float wy = w * y2;\n float wz = w * z2;\n float sx = s.x;\n float sy = s.y;\n float sz = s.z;\n return mat4((1. - (yy + zz)) * sx, (xy + wz) * sx, (xz - wy) * sx, 0,\n (xy - wz) * sy, (1. - (xx + zz)) * sy, (yz + wx) * sy, 0,\n (xz + wy) * sz, (yz - wx) * sz, (1. - (xx + yy)) * sz, 0,\n t.x, t.y, t.z, 1);\n}\nvec4 quatMultiply (vec4 a, vec4 b){\n vec4 quat;\n quat.x = a.x * b.w + a.w * b.x + a.y * b.z - a.z * b.y;\n quat.y = a.y * b.w + a.w * b.y + a.z * b.x - a.x * b.z;\n quat.z = a.z * b.w + a.w * b.z + a.x * b.y - a.y * b.x;\n quat.w = a.w * b.w - a.x * b.x - a.y * b.y - a.z * b.z;\n return quat;\n}\nvoid rotateVecFromQuat (inout vec3 v, vec4 q){\n float ix = q.w * v.x + q.y * v.z - q.z * v.y;\n float iy = q.w * v.y + q.z * v.x - q.x * v.z;\n float iz = q.w * v.z + q.x * v.y - q.y * v.x;\n float iw = -q.x * v.x - q.y * v.y - q.z * v.z;\n v.x = ix * q.w + iw * -q.x + iy * -q.z - iz * -q.y;\n v.y = iy * q.w + iw * -q.y + iz * -q.x - ix * -q.z;\n v.z = iz * q.w + iw * -q.z + ix * -q.y - iy * -q.x;\n}\nvec3 rotateInLocalSpace (vec3 pos, vec3 xAxis, vec3 yAxis, vec3 zAxis, vec4 q){\n vec4 viewQuat = quaternionFromAxis(xAxis, yAxis, zAxis);\n vec4 rotQuat = quatMultiply(viewQuat, q);\n rotateVecFromQuat(pos, rotQuat);\n return pos;\n}\nvoid rotateCorner (inout vec2 corner, float angle){\n float xOS = cos(angle) * corner.x - sin(angle) * corner.y;\n float yOS = sin(angle) * corner.x + cos(angle) * corner.y;\n corner.x = xOS;\n corner.y = yOS;\n}\nuniform vec4 mainTiling_Offset;\nuniform vec4 frameTile_velLenScale;\nuniform vec4 scale;\nuniform highp mat4 cc_matView;\nuniform highp mat4 cc_matViewInv;\nuniform highp mat4 cc_matViewProj;\nuniform highp vec4 cc_cameraPos;\nuniform highp mat4 cc_matWorld;\nvarying vec2 uv;\nvarying vec4 color;\nvoid computeVertPos (inout vec4 pos, vec2 vertOffset, vec4 q, vec3 s\n#if CC_RENDER_MODE == 0 || CC_RENDER_MODE == 3\n , mat4 viewInv\n#endif\n#if CC_RENDER_MODE == 1\n , vec3 eye\n , vec4 velocity\n , float velocityScale\n , float lengthScale\n , float xIndex\n#endif\n) {\n#if CC_RENDER_MODE == 0\n vec3 viewSpaceVert = vec3(vertOffset.x * s.x, vertOffset.y * s.y, 0.);\n vec3 camX = normalize(vec3(viewInv[0][0], viewInv[1][0], viewInv[2][0]));\n vec3 camY = normalize(vec3(viewInv[0][1], viewInv[1][1], viewInv[2][1]));\n vec3 camZ = normalize(vec3(viewInv[0][2], viewInv[1][2], viewInv[2][2]));\n pos.xyz += rotateInLocalSpace(viewSpaceVert, camX, camY, camZ, q);\n#elif CC_RENDER_MODE == 1\n vec3 camRight = normalize(cross(pos.xyz - eye, velocity.xyz)) * s.x;\n vec3 camUp = velocity.xyz * velocityScale + normalize(velocity.xyz) * lengthScale * s.y;\n pos.xyz += (camRight * abs(vertOffset.x) * sign(vertOffset.y)) - camUp * xIndex;\n#elif CC_RENDER_MODE == 2\n vec3 viewSpaceVert = vec3(vertOffset.x * s.x, vertOffset.y * s.y, 0.);\n vec3 camX = vec3(1, 0, 0);\n vec3 camY = vec3(0, 0, -1);\n pos.xyz += rotateInLocalSpace(viewSpaceVert, camX, camY, cross(camX, camY), q);\n#elif CC_RENDER_MODE == 3\n vec2 viewSpaceVert = vec2(vertOffset.x * s.x, vertOffset.y * s.y);\n rotateCorner(viewSpaceVert, q.z);\n vec3 camX = normalize(vec3(cc_matView[0][0], cc_matView[1][0], cc_matView[2][0]));\n vec3 camY = vec3(0, 1, 0);\n vec3 offset = camX * viewSpaceVert.x + camY * viewSpaceVert.y;\n pos.xyz += offset;\n#else\n pos.x += vertOffset.x;\n pos.y += vertOffset.y;\n#endif\n}\nvec2 computeUV (float frameIndex, vec2 vertIndex, vec2 frameTile){\n vec2 aniUV = vec2(0, floor(frameIndex * frameTile.y));\n aniUV.x = floor(frameIndex * frameTile.x * frameTile.y - aniUV.y * frameTile.x);\n#if CC_RENDER_MODE != 4\n vertIndex.y = 1. - vertIndex.y;\n#endif\n return (aniUV.xy + vertIndex) / vec2(frameTile.x, frameTile.y);\n}\nattribute vec3 a_position;\nattribute vec3 a_texCoord;\nattribute vec3 a_texCoord1;\nattribute vec3 a_texCoord2;\nattribute vec4 a_color;\n#if CC_RENDER_MODE == 1\n attribute vec3 a_color1;\n#endif\n#if CC_RENDER_MODE == 4\n attribute vec3 a_texCoord3;\n attribute vec3 a_normal;\n attribute vec4 a_color1;\n#endif\nvec4 lpvs_main () {\n vec3 compScale = scale.xyz * a_texCoord1;\n vec4 pos = vec4(a_position, 1);\n #if CC_RENDER_MODE == 1\n vec4 velocity = vec4(a_color1.xyz, 0);\n #endif\n #if !CC_USE_WORLD_SPACE\n pos = cc_matWorld * pos;\n #if CC_RENDER_MODE == 1\n velocity = cc_matWorld * velocity;\n #endif\n #endif\n #if CC_RENDER_MODE != 4\n vec2 cornerOffset = vec2((a_texCoord.xy - 0.5));\n #if CC_RENDER_MODE == 0\n vec3 rotEuler = a_texCoord2;\n #elif CC_RENDER_MODE == 1\n vec3 rotEuler = vec3(0.);\n #else\n vec3 rotEuler = vec3(0., 0., a_texCoord2.z);\n #endif\n computeVertPos(pos, cornerOffset, quaternionFromEuler(rotEuler), compScale\n #if CC_RENDER_MODE == 0 || CC_RENDER_MODE == 3\n , cc_matViewInv\n #endif\n #if CC_RENDER_MODE == 1\n , cc_cameraPos.xyz\n , velocity\n , frameTile_velLenScale.z\n , frameTile_velLenScale.w\n , a_texCoord.x\n #endif\n );\n color = a_color;\n #else\n mat4 xformNoScale = matrixFromRT(quaternionFromEuler(a_texCoord2), pos.xyz);\n mat4 xform = matFromRTS(quaternionFromEuler(a_texCoord2), pos.xyz, compScale);\n pos = xform * vec4(a_texCoord3, 1);\n vec4 normal = xformNoScale * vec4(a_normal, 0);\n color = a_color * a_color1;\n #endif\n uv = computeUV(a_texCoord.z, a_texCoord.xy, frameTile_velLenScale.xy) * mainTiling_Offset.xy + mainTiling_Offset.zw;\n pos = cc_matViewProj * pos;\n return pos;\n}\nvoid main() { gl_Position = lpvs_main(); }`, @@ -259,7 +259,7 @@ export default [ "name": "builtin-sprite|sprite-vs:vert|sprite-fs:frag", "hash": 543960898, "glsl3": { - "vert": `\nprecision mediump float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\n#if USE_LOCAL\nuniform CCLocal {\n highp mat4 cc_matWorld;\n highp mat4 cc_matWorldIT;\n highp vec4 cc_lightingMapUVParam;\n};\n#endif\nin vec3 a_position;\nin vec4 a_color;\nout vec4 color;\nin vec2 a_texCoord;\nout vec2 uv0;\nvec4 vert () {\n vec4 pos = vec4(a_position, 1);\n #if USE_LOCAL\n pos = cc_matViewProj * cc_matWorld * pos;\n #else\n pos = cc_matViewProj * pos;\n #endif\n uv0 = a_texCoord;\n color = a_color;\n return pos;\n}\nvoid main() { gl_Position = vert(); }`, + "vert": `\nprecision mediump float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n};\n#if USE_LOCAL\nuniform CCLocal {\n highp mat4 cc_matWorld;\n highp mat4 cc_matWorldIT;\n highp vec4 cc_lightingMapUVParam;\n};\n#endif\nin vec3 a_position;\nin vec4 a_color;\nout vec4 color;\nin vec2 a_texCoord;\nout vec2 uv0;\nvec4 vert () {\n vec4 pos = vec4(a_position, 1);\n #if USE_LOCAL\n pos = cc_matViewProj * cc_matWorld * pos;\n #else\n pos = cc_matViewProj * pos;\n #endif\n uv0 = a_texCoord;\n color = a_color;\n return pos;\n}\nvoid main() { gl_Position = vert(); }`, "frag": `\nprecision mediump float;\nin vec4 color;\n#if USE_TEXTURE\n in vec2 uv0;\n uniform sampler2D mainTexture;\n#endif\nvec4 frag () {\n vec4 o = vec4(1, 1, 1, 1);\n #if USE_TEXTURE\n o *= texture(mainTexture, uv0);\n #if IS_GRAY\n float gray = 0.2126 * o.r + 0.7152 * o.g + 0.0722 * o.b;\n o.r = o.g = o.b = gray;\n #endif\n #endif\n o *= color;\n return o;\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }` }, "glsl1": { @@ -296,56 +296,53 @@ export default [ "shaders": [ { "name": "builtin-standard|standard-vs:vert|standard-fs:frag", - "hash": 2109082843, + "hash": 3063041897, "glsl3": { - "vert": `\nprecision highp float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\n#if USE_INSTANCING\n in vec4 a_matWorld0;\n in vec4 a_matWorld1;\n in vec4 a_matWorld2;\n#elif USE_BATCHING\n in float a_dyn_batch_id;\n uniform CCLocalBatched {\n highp mat4 cc_matWorlds[10];\n };\n#else\nuniform CCLocal {\n highp mat4 cc_matWorld;\n highp mat4 cc_matWorldIT;\n highp vec4 cc_lightingMapUVParam;\n};\n#endif\nstruct StandardVertInput {\n highp vec4 position;\n vec3 normal;\n vec4 tangent;\n};\nin vec3 a_position;\nin vec3 a_normal;\nin vec4 a_tangent;\n#if CC_USE_MORPH\n in float a_vertexId;\n int getVertexId() {\n return int(a_vertexId);\n }\nuniform CCMorph {\n vec4 cc_displacementWeights[15];\n vec4 cc_displacementTextureInfo;\n};\n vec4 fetchFlatPixel(sampler2D tex, int pixelIndex) {\n float pixelIndexF = float(pixelIndex);\n vec2 textureResolution = vec2(float(cc_displacementTextureInfo.x), float(cc_displacementTextureInfo.y));\n float pixelX = mod(pixelIndexF, textureResolution.x);\n float pixelY = floor(pixelIndexF / textureResolution.x);\n vec2 uv = (vec2(pixelX, pixelY) + .5) / textureResolution;\n return texture(tex, uv);\n }\nfloat getDisplacementWeight(int index) {\n float m = mod(float(index), 4.0);\n if (m < 1.0) {\n return cc_displacementWeights[index / 4].x;\n } else if (m < 2.0) {\n return cc_displacementWeights[index / 4].y;\n } else if (m < 3.0) {\n return cc_displacementWeights[index / 4].z;\n } else {\n return cc_displacementWeights[index / 4].w;\n }\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\n return fetchFlatPixel(tex, vertexIndex).rgb;\n#else\n vec3 result = vec3(0, 0, 0);\n for (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\n int dataPixelStart = int(fetchFlatPixel(tex, iTarget).r);\n result += (fetchFlatPixel(tex, dataPixelStart + vertexIndex).rgb * getDisplacementWeight(iTarget));\n }\n return result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\n uniform sampler2D cc_PositionDisplacements;\n vec3 getPositionDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n uniform sampler2D cc_NormalDisplacements;\n vec3 getNormalDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n uniform sampler2D cc_TangentDisplacements;\n vec3 getTangentDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n }\n#endif\nvoid applyMorph (inout StandardVertInput attr) {\n int vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\n attr.position.xyz = attr.position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n attr.normal.xyz = attr.normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n attr.tangent.xyz = attr.tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\n position.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\nin vec4 a_weights;\nin vec4 a_joints;\n#if CC_USE_BAKED_ANIMATION\n #if USE_INSTANCING\n in vec4 a_jointAnimInfo;\n #endif\n uniform CCSkinningTexture {\n highp vec4 cc_jointTextureInfo;\n };\n uniform CCSkinningAnimation {\n highp vec4 cc_jointAnimInfo;\n };\n uniform sampler2D cc_jointTexture;\n #if !CC_SUPPORT_FLOAT_TEXTURE\n highp float decode32 (highp vec4 rgba) {\n rgba = rgba * 255.0;\n highp float Sign = 1.0 - step(128.0, rgba[3]) * 2.0;\n highp float Exponent = 2.0 * mod(rgba[3], 128.0) + step(128.0, rgba[2]) - 127.0;\n highp float Mantissa = mod(rgba[2], 128.0) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\n }\n #endif\n#else\n uniform CCSkinning {\n highp vec4 cc_joints[30 * 3];\n };\n#endif\n#if CC_USE_BAKED_ANIMATION\n #if CC_SUPPORT_FLOAT_TEXTURE\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 3.0 * i + a_jointAnimInfo.x;\n #else\n highp float j = 3.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = texture(cc_jointTexture, vec2((x + 0.5) * invSize, y));\n vec4 v2 = texture(cc_jointTexture, vec2((x + 1.5) * invSize, y));\n vec4 v3 = texture(cc_jointTexture, vec2((x + 2.5) * invSize, y));\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #else\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 12.0 * i + a_jointAnimInfo.x;\n #else\n highp float j = 12.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = vec4(\n decode32(texture(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n );\n vec4 v2 = vec4(\n decode32(texture(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n );\n vec4 v3 = vec4(\n decode32(texture(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n );\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #endif\n#else\n mat4 getJointMatrix (float i) {\n int idx = int(i);\n vec4 v1 = cc_joints[idx * 3];\n vec4 v2 = cc_joints[idx * 3 + 1];\n vec4 v3 = cc_joints[idx * 3 + 2];\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n#endif\nmat4 skinMatrix () {\n return getJointMatrix(a_joints.x) * a_weights.x\n + getJointMatrix(a_joints.y) * a_weights.y;\n + getJointMatrix(a_joints.z) * a_weights.z;\n + getJointMatrix(a_joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\n mat4 m = skinMatrix();\n position = m * position;\n}\nvoid CCSkin (inout StandardVertInput attr) {\n mat4 m = skinMatrix();\n attr.position = m * attr.position;\n attr.normal = (m * vec4(attr.normal, 0.0)).xyz;\n attr.tangent.xyz = (m * vec4(attr.tangent.xyz, 0.0)).xyz;\n}\n#endif\nuniform Constants {\n vec4 tilingOffset;\n vec4 albedo;\n vec4 albedoScaleAndCutoff;\n vec4 pbrParams;\n vec4 emissive;\n vec4 emissiveScaleParam;\n};\nfloat LinearFog(vec4 pos) {\n vec4 wPos = pos;\n float cam_dis = distance(cc_cameraPos, wPos);\n float fogStart = cc_fogBase.x;\n float fogEnd = cc_fogBase.y;\n return clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float fogDensity = cc_fogBase.z;\n float cam_dis = distance(cc_cameraPos, wPos) / fogAtten * 4.;\n float f = exp(-cam_dis * fogDensity);\n return f;\n}\nfloat ExpSquaredFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float fogDensity = cc_fogBase.z;\n float cam_dis = distance(cc_cameraPos, wPos) / fogAtten * 4.;\n float f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\n return f;\n}\nfloat LayeredFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float _FogTop = cc_fogAdd.x;\n float _FogRange = cc_fogAdd.y;\n vec3 camWorldProj = cc_cameraPos.xyz;\n camWorldProj.y = 0.;\n vec3 worldPosProj = wPos.xyz;\n worldPosProj.y = 0.;\n float fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\n float fDeltaY, fDensityIntegral;\n if (cc_cameraPos.y > _FogTop) {\n if (wPos.y < _FogTop) {\n fDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\n fDensityIntegral = fDeltaY * fDeltaY * 0.5;\n } else {\n fDeltaY = 0.;\n fDensityIntegral = 0.;\n }\n } else {\n if (wPos.y < _FogTop) {\n float fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\n float fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\n fDeltaY = abs(fDeltaA - fDeltaB);\n fDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n } else {\n fDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\n fDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n }\n }\n float fDensity;\n if (fDeltaY != 0.) {\n fDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n } else {\n fDensity = 0.;\n }\n float f = exp(-fDensity);\n return f;\n}\nfloat CC_TRANSFER_FOG(vec4 pos) {\n #if CC_USE_FOG == 1\n return LinearFog(pos);\n #elif CC_USE_FOG == 2\n return ExpFog(pos);\n #elif CC_USE_FOG == 3\n return ExpSquaredFog(pos);\n #elif CC_USE_FOG == 4\n return LayeredFog(pos);\n #endif\n return 1.;\n}\n#if USE_VERTEX_COLOR\n in vec3 a_color;\n out vec3 v_color;\n#endif\nout vec3 v_position;\nout vec3 v_normal;\n#if USE_NORMAL_MAP\n out vec3 v_tangent;\n out vec3 v_bitangent;\n#endif\nin vec2 a_texCoord;\nout vec2 v_uv;\nin vec2 a_texCoord1;\nout vec2 v_uv1;\nout float factor_fog;\n#if USE_LIGHTMAP && !USE_BATCHING && !USE_INSTANCING\n out vec2 v_luv;\n#endif\nvec4 vert () {\n StandardVertInput In;\n In.position = vec4(a_position, 1.0);\n In.normal = a_normal;\n In.tangent = a_tangent;\n #if CC_USE_MORPH\n applyMorph(In);\n #endif\n #if CC_USE_SKINNING\n CCSkin(In);\n #endif\n mat4 matWorld, matWorldIT;\n #if USE_INSTANCING\n matWorld = mat4(\n vec4(a_matWorld0.xyz, 0.0),\n vec4(a_matWorld1.xyz, 0.0),\n vec4(a_matWorld2.xyz, 0.0),\n vec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)\n );\n matWorldIT = matWorld;\n #elif USE_BATCHING\n matWorld = cc_matWorlds[int(a_dyn_batch_id)];\n matWorldIT = matWorld;\n #else\n matWorld = cc_matWorld;\n matWorldIT = cc_matWorldIT;\n #endif\n vec4 pos = matWorld * In.position;\n v_position = pos.xyz;\n v_normal = normalize((matWorldIT * vec4(In.normal, 0.0)).xyz);\n #if USE_NORMAL_MAP\n v_tangent = normalize((matWorld * vec4(In.tangent.xyz, 0.0)).xyz);\n v_bitangent = cross(v_normal, v_tangent) * In.tangent.w;\n #endif\n v_uv = a_texCoord * tilingOffset.xy + tilingOffset.zw;\n #if HAS_SECOND_UV\n v_uv1 = a_texCoord1 * tilingOffset.xy + tilingOffset.zw;\n #endif\n #if USE_VERTEX_COLOR\n v_color = a_color;\n #endif\n factor_fog = CC_TRANSFER_FOG(matWorld * In.position);\n #if USE_LIGHTMAP && HAS_SECOND_UV && !USE_BATCHING && !USE_INSTANCING\n v_luv = cc_lightingMapUVParam.xy + a_texCoord1 * cc_lightingMapUVParam.zw;\n #endif\n return cc_matProj * (cc_matView * matWorld) * In.position;\n}\nvoid main() { gl_Position = vert(); }`, - "frag": `\nprecision highp float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\n#if CC_USE_IBL\nuniform samplerCube cc_environment;\nvec3 unpackRGBE (vec4 rgbe) {\n return rgbe.rgb * pow(2.0, rgbe.a * 255.0 - 128.0);\n}\nvec4 fragTextureLod (sampler2D tex, vec2 coord, float lod) {\n return textureLod(tex, coord, lod);\n}\nvec4 fragTextureLod (samplerCube tex, vec3 coord, float lod) {\n return textureLod(tex, coord, lod);\n}\n#endif\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\n}\nfloat GGXMobile (float roughness, float NoH, vec3 H, vec3 N) {\n vec3 NxH = cross(N, H);\n float OneMinusNoHSqr = dot(NxH, NxH);\n float a = roughness * roughness;\n float n = NoH * a;\n float p = a / (OneMinusNoHSqr + n * n);\n return p * p;\n}\nfloat CalcSpecular (float roughness, float NoH, vec3 H, vec3 N) {\n return (roughness*0.25 + 0.25) * GGXMobile(roughness, NoH, H, N);\n}\nvec3 BRDFApprox (vec3 specular, float roughness, float NoV) {\n const vec4 c0 = vec4(-1.0, -0.0275, -0.572, 0.022);\n const vec4 c1 = vec4(1.0, 0.0425, 1.04, -0.04);\n vec4 r = roughness * c0 + c1;\n float a004 = min( r.x * r.x, exp2( -9.28 * NoV ) ) * r.x + r.y;\n vec2 AB = vec2( -1.04, 1.04 ) * a004 + r.zw;\n AB.y *= clamp(50.0 * specular.g, 0.0, 1.0);\n return specular * AB.x + AB.y;\n}\nstruct StandardSurface {\n vec4 albedo;\n vec3 position;\n vec3 normal;\n vec3 emissive;\n float roughness;\n float metallic;\n float occlusion;\n};\n#if CC_FOWARD_ADD\nuniform CCForwardLight {\n highp vec4 cc_lightPos[1];\n vec4 cc_lightColor[1];\n vec4 cc_lightSizeRangeAngle[1];\n vec4 cc_lightDir[1];\n};\nfloat SmoothDistAtt (float distSqr, float invSqrAttRadius) {\n float factor = distSqr * invSqrAttRadius;\n float smoothFactor = clamp(1.0 - factor * factor, 0.0, 1.0);\n return smoothFactor * smoothFactor;\n}\nfloat GetDistAtt (float distSqr, float invSqrAttRadius) {\n float attenuation = 1.0 / max(distSqr, 0.01*0.01);\n attenuation *= SmoothDistAtt(distSqr , invSqrAttRadius);\n return attenuation;\n}\nfloat GetAngleAtt (vec3 L, vec3 litDir, float litAngleScale, float litAngleOffset) {\n float cd = dot(litDir, L);\n float attenuation = clamp(cd * litAngleScale + litAngleOffset, 0.0, 1.0);\n return (attenuation * attenuation);\n}\n vec4 CCStandardShading (StandardSurface s) {\n vec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\n vec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\n vec3 diffuseContrib = diffuse / 3.14159265359;\n vec3 N = normalize(s.normal);\n vec3 V = normalize(cc_cameraPos.xyz - s.position);\n float NV = max(abs(dot(N, V)), 0.001);\n specular = BRDFApprox(specular, s.roughness, NV);\n vec3 finalColor = vec3(0.0);\n for (int i = 0; i < 1; i++) {\n vec3 SLU = cc_lightPos[i].xyz - s.position;\n vec3 SL = normalize(SLU);\n vec3 SH = normalize(SL + V);\n float SNL = max(dot(N, SL), 0.001);\n float SNH = max(dot(N, SH), 0.0);\n float distSqr = dot(SLU, SLU);\n float litRadius = cc_lightSizeRangeAngle[i].x;\n float litRadiusSqr = litRadius * litRadius;\n float illum = 3.14159265359 * (litRadiusSqr / max(litRadiusSqr , distSqr));\n float attRadiusSqrInv = 1.0 / max(cc_lightSizeRangeAngle[i].y, 0.01);\n attRadiusSqrInv *= attRadiusSqrInv;\n float att = GetDistAtt(distSqr, attRadiusSqrInv);\n vec3 lspec = specular * CalcSpecular(s.roughness, SNH, SH, N);\n #if CC_SPOTLIGHT\n float cosInner = max(dot(-cc_lightDir[i].xyz, SL), 0.01);\n float cosOuter = cc_lightSizeRangeAngle[i].z;\n float litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\n float litAngleOffset = -cosOuter * litAngleScale;\n att *= GetAngleAtt(SL, -cc_lightDir[i].xyz, litAngleScale, litAngleOffset);\n #endif\n finalColor += SNL * cc_lightColor[i].rgb * cc_lightColor[i].w * illum * att * (diffuseContrib + lspec);\n }\n return vec4(finalColor, 0.0);\n }\n#else\n vec4 CCStandardShading (StandardSurface s) {\n vec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\n vec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\n vec3 N = normalize(s.normal);\n vec3 V = normalize(cc_cameraPos.xyz - s.position);\n vec3 L = normalize(-cc_mainLitDir.xyz);\n vec3 H = normalize(L+V);\n float NV = max(abs(dot(N, V)), 0.001);\n float NL = max(dot(N, L), 0.001);\n float NH = max(dot(N, H), 0.0);\n specular = BRDFApprox(specular, s.roughness, NV);\n vec3 diffuseContrib = diffuse / 3.14159265359;\n vec3 specularContrib = specular * CalcSpecular(s.roughness, NH, H, N);\n vec3 finalColor = NL * cc_mainLitColor.rgb * cc_mainLitColor.w * (diffuseContrib + specularContrib);\n float fAmb = 0.5 - N.y * 0.5;\n vec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb) * cc_ambientSky.w;\n finalColor += (ambDiff.rgb * diffuse);\n #if CC_USE_IBL\n vec3 R = normalize(reflect(-V, N));\n vec4 envmap = fragTextureLod(cc_environment, R, s.roughness * cc_ambientGround.w);\n #if CC_USE_IBL == 2\n vec3 env = unpackRGBE(envmap);\n #else\n vec3 env = SRGBToLinear(envmap.rgb);\n #endif\n finalColor += env * cc_ambientSky.w * specular;\n #endif\n finalColor = finalColor * s.occlusion;\n #if CC_USE_HDR\n s.emissive *= cc_exposure.w;\n #endif\n finalColor += s.emissive;\n return vec4(finalColor, s.albedo.a);\n }\n#endif\nvec3 ACESToneMap (vec3 color) {\n color = min(color, vec3(8.0));\n const float A = 2.51;\n const float B = 0.03;\n const float C = 2.43;\n const float D = 0.59;\n const float E = 0.14;\n return (color * (A * color + B)) / (color * (C * color + D) + E);\n}\nvec4 CCFragOutput (vec4 color) {\n #if !CC_USE_HDR\n color.rgb = sqrt(ACESToneMap(color.rgb));\n #endif\n return color;\n}\nuniform Constants {\n vec4 tilingOffset;\n vec4 albedo;\n vec4 albedoScaleAndCutoff;\n vec4 pbrParams;\n vec4 emissive;\n vec4 emissiveScaleParam;\n};\nin vec3 v_position;\nin vec2 v_uv;\nin vec2 v_uv1;\nin vec3 v_normal;\n#if USE_VERTEX_COLOR\n in vec3 v_color;\n#endif\n#if USE_ALBEDO_MAP\n uniform sampler2D albedoMap;\n#endif\n#if USE_NORMAL_MAP\n in vec3 v_tangent;\n in vec3 v_bitangent;\n uniform sampler2D normalMap;\n#endif\n#if USE_PBR_MAP\n uniform sampler2D pbrMap;\n#endif\n#if USE_METALLIC_ROUGHNESS_MAP\n uniform sampler2D metallicRoughnessMap;\n#endif\n#if USE_OCCLUSION_MAP\n uniform sampler2D occlusionMap;\n#endif\n#if USE_EMISSIVE_MAP\n uniform sampler2D emissiveMap;\n#endif\n#if USE_LIGHTMAP\n in vec2 v_luv;\n uniform sampler2D cc_lightingMap;\n#endif\n#if USE_ALPHA_TEST\n#endif\nin float factor_fog;\nvoid surf (out StandardSurface s) {\n vec4 baseColor = albedo;\n #if USE_VERTEX_COLOR\n baseColor.rgb *= v_color;\n #endif\n #if USE_ALBEDO_MAP\n vec4 texColor = texture(albedoMap, ALBEDO_UV);\n texColor.rgb = SRGBToLinear(texColor.rgb);\n baseColor *= texColor;\n #endif\n s.albedo = baseColor;\n s.albedo.rgb *= albedoScaleAndCutoff.xyz;\n #if USE_ALPHA_TEST\n if (s.albedo.ALPHA_TEST_CHANNEL < albedoScaleAndCutoff.w) discard;\n #endif\n s.normal = v_normal;\n #if USE_NORMAL_MAP\n vec3 nmmp = texture(normalMap, NORMAL_UV).xyz - vec3(0.5);\n s.normal =\n (nmmp.x * pbrParams.w) * normalize(v_tangent) +\n (nmmp.y * pbrParams.w) * normalize(v_bitangent) +\n nmmp.z * normalize(s.normal);\n #endif\n s.position = v_position;\n vec4 pbr = pbrParams;\n #if USE_PBR_MAP\n vec4 res = texture(pbrMap, PBR_UV);\n pbr.x *= res.OCCLUSION_CHANNEL;\n pbr.y *= res.ROUGHNESS_CHANNEL;\n pbr.z *= res.METALLIC_CHANNEL;\n #endif\n #if USE_METALLIC_ROUGHNESS_MAP\n vec4 metallicRoughness = texture(metallicRoughnessMap, METALLIC_ROUGHNESS_UV);\n pbr.z *= metallicRoughness.METALLIC_CHANNEL;\n pbr.y *= metallicRoughness.ROUGHNESS_CHANNEL;\n #endif\n #if USE_OCCLUSION_MAP\n pbr.x *= texture(occlusionMap, OCCLUSION_UV).OCCLUSION_CHANNEL;\n #endif\n s.occlusion = clamp(pbr.x, 0.0, 0.96);\n s.roughness = clamp(pbr.y, 0.04, 1.0);\n s.metallic = pbr.z;\n s.emissive = emissive.rgb * emissiveScaleParam.xyz;\n #if USE_EMISSIVE_MAP\n s.emissive *= SRGBToLinear(texture(emissiveMap, EMISSIVE_UV).rgb);\n #endif\n}\nvec4 frag () {\n StandardSurface s; surf(s);\n vec4 color = CCStandardShading(s);\n #if USE_LIGHTMAP && !USE_BATCHING && !USE_INSTANCING && CC_FOWARD_ADD == 0\n vec4 lighting = texture(cc_lightingMap, v_luv);\n float fAmb = 0.5 - s.normal.y * 0.5;\n vec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb) * cc_ambientSky.w;\n vec3 finalColor = (ambDiff.rgb * s.albedo.rgb);\n finalColor += lighting.rgb * s.albedo.rgb;\n finalColor = finalColor * s.occlusion;\n finalColor += s.emissive;\n color.rgb = lighting.a * finalColor + (1.0 - lighting.a) * color.rgb;\n #endif\n color = mix(cc_fogColor, color, factor_fog);\n return CCFragOutput(color);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }` + "vert": `\nprecision highp float;\nstruct StandardVertInput {\n highp vec4 position;\n vec3 normal;\n vec4 tangent;\n};\nin vec3 a_position;\nin vec3 a_normal;\nin vec4 a_tangent;\n#if CC_USE_MORPH\n in float a_vertexId;\n int getVertexId() {\n return int(a_vertexId);\n }\nuniform CCMorph {\n vec4 cc_displacementWeights[15];\n vec4 cc_displacementTextureInfo;\n};\n vec4 fetchFlatPixel(sampler2D tex, int pixelIndex) {\n float pixelIndexF = float(pixelIndex);\n vec2 textureResolution = vec2(float(cc_displacementTextureInfo.x), float(cc_displacementTextureInfo.y));\n float pixelX = mod(pixelIndexF, textureResolution.x);\n float pixelY = floor(pixelIndexF / textureResolution.x);\n vec2 uv = (vec2(pixelX, pixelY) + .5) / textureResolution;\n return texture(tex, uv);\n }\nfloat getDisplacementWeight(int index) {\n float m = mod(float(index), 4.0);\n if (m < 1.0) {\n return cc_displacementWeights[index / 4].x;\n } else if (m < 2.0) {\n return cc_displacementWeights[index / 4].y;\n } else if (m < 3.0) {\n return cc_displacementWeights[index / 4].z;\n } else {\n return cc_displacementWeights[index / 4].w;\n }\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\n return fetchFlatPixel(tex, vertexIndex).rgb;\n#else\n vec3 result = vec3(0, 0, 0);\n for (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\n int dataPixelStart = int(fetchFlatPixel(tex, iTarget).r);\n result += (fetchFlatPixel(tex, dataPixelStart + vertexIndex).rgb * getDisplacementWeight(iTarget));\n }\n return result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\n uniform sampler2D cc_PositionDisplacements;\n vec3 getPositionDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n uniform sampler2D cc_NormalDisplacements;\n vec3 getNormalDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n uniform sampler2D cc_TangentDisplacements;\n vec3 getTangentDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n }\n#endif\nvoid applyMorph (inout StandardVertInput attr) {\n int vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\n attr.position.xyz = attr.position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n attr.normal.xyz = attr.normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n attr.tangent.xyz = attr.tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\n position.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\nin vec4 a_weights;\nin vec4 a_joints;\n#if CC_USE_BAKED_ANIMATION\n #if USE_INSTANCING\n in highp vec4 a_jointAnimInfo;\n #endif\n uniform CCSkinningTexture {\n highp vec4 cc_jointTextureInfo;\n };\n uniform CCSkinningAnimation {\n highp vec4 cc_jointAnimInfo;\n };\n uniform sampler2D cc_jointTexture;\n #if !CC_SUPPORT_FLOAT_TEXTURE\n highp float decode32 (highp vec4 rgba) {\n rgba = rgba * 255.0;\n highp float Sign = 1.0 - step(128.0, rgba[3]) * 2.0;\n highp float Exponent = 2.0 * mod(rgba[3], 128.0) + step(128.0, rgba[2]) - 127.0;\n highp float Mantissa = mod(rgba[2], 128.0) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\n }\n #endif\n#else\n uniform CCSkinning {\n highp vec4 cc_joints[30 * 3];\n };\n#endif\n#if CC_USE_BAKED_ANIMATION\n #if CC_SUPPORT_FLOAT_TEXTURE\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 3.0 * (a_jointAnimInfo.x * a_jointAnimInfo.y + i) + a_jointAnimInfo.z;\n #else\n highp float j = 3.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = texture(cc_jointTexture, vec2((x + 0.5) * invSize, y));\n vec4 v2 = texture(cc_jointTexture, vec2((x + 1.5) * invSize, y));\n vec4 v3 = texture(cc_jointTexture, vec2((x + 2.5) * invSize, y));\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #else\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 12.0 * (a_jointAnimInfo.x * a_jointAnimInfo.y + i) + a_jointAnimInfo.z;\n #else\n highp float j = 12.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = vec4(\n decode32(texture(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n );\n vec4 v2 = vec4(\n decode32(texture(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n );\n vec4 v3 = vec4(\n decode32(texture(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n );\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #endif\n#else\n mat4 getJointMatrix (float i) {\n int idx = int(i);\n vec4 v1 = cc_joints[idx * 3];\n vec4 v2 = cc_joints[idx * 3 + 1];\n vec4 v3 = cc_joints[idx * 3 + 2];\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n#endif\nmat4 skinMatrix () {\n return getJointMatrix(a_joints.x) * a_weights.x\n + getJointMatrix(a_joints.y) * a_weights.y;\n + getJointMatrix(a_joints.z) * a_weights.z;\n + getJointMatrix(a_joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\n mat4 m = skinMatrix();\n position = m * position;\n}\nvoid CCSkin (inout StandardVertInput attr) {\n mat4 m = skinMatrix();\n attr.position = m * attr.position;\n attr.normal = (m * vec4(attr.normal, 0.0)).xyz;\n attr.tangent.xyz = (m * vec4(attr.tangent.xyz, 0.0)).xyz;\n}\n#endif\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n};\n#if USE_INSTANCING\n in vec4 a_matWorld0;\n in vec4 a_matWorld1;\n in vec4 a_matWorld2;\n#elif USE_BATCHING\n in float a_dyn_batch_id;\n uniform CCLocalBatched {\n highp mat4 cc_matWorlds[10];\n };\n#else\nuniform CCLocal {\n highp mat4 cc_matWorld;\n highp mat4 cc_matWorldIT;\n highp vec4 cc_lightingMapUVParam;\n};\n#endif\nuniform Constants {\n vec4 tilingOffset;\n vec4 albedo;\n vec4 albedoScaleAndCutoff;\n vec4 pbrParams;\n vec4 emissive;\n vec4 emissiveScaleParam;\n};\n#if USE_VERTEX_COLOR\n in vec3 a_color;\n out vec3 v_color;\n#endif\nout vec3 v_position;\nout vec3 v_normal;\n#if USE_NORMAL_MAP\n out vec3 v_tangent;\n out vec3 v_bitangent;\n#endif\nin vec2 a_texCoord;\nout vec2 v_uv;\nin vec2 a_texCoord1;\nout vec2 v_uv1;\n#if USE_LIGHTMAP && !USE_BATCHING && !USE_INSTANCING\n out vec2 v_luv;\n#endif\nvec4 vert () {\n StandardVertInput In;\n In.position = vec4(a_position, 1.0);\n In.normal = a_normal;\n In.tangent = a_tangent;\n #if CC_USE_MORPH\n applyMorph(In);\n #endif\n #if CC_USE_SKINNING\n CCSkin(In);\n #endif\n mat4 matWorld, matWorldIT;\n #if USE_INSTANCING\n matWorld = mat4(\n vec4(a_matWorld0.xyz, 0.0),\n vec4(a_matWorld1.xyz, 0.0),\n vec4(a_matWorld2.xyz, 0.0),\n vec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)\n );\n matWorldIT = matWorld;\n #elif USE_BATCHING\n matWorld = cc_matWorlds[int(a_dyn_batch_id)];\n matWorldIT = matWorld;\n #else\n matWorld = cc_matWorld;\n matWorldIT = cc_matWorldIT;\n #endif\n vec4 pos = matWorld * In.position;\n v_position = pos.xyz;\n v_normal = normalize((matWorldIT * vec4(In.normal, 0.0)).xyz);\n #if USE_NORMAL_MAP\n v_tangent = normalize((matWorld * vec4(In.tangent.xyz, 0.0)).xyz);\n v_bitangent = cross(v_normal, v_tangent) * In.tangent.w;\n #endif\n v_uv = a_texCoord * tilingOffset.xy + tilingOffset.zw;\n #if HAS_SECOND_UV\n v_uv1 = a_texCoord1 * tilingOffset.xy + tilingOffset.zw;\n #endif\n #if USE_VERTEX_COLOR\n v_color = a_color;\n #endif\n #if USE_LIGHTMAP && HAS_SECOND_UV && !USE_BATCHING && !USE_INSTANCING\n v_luv = cc_lightingMapUVParam.xy + a_texCoord1 * cc_lightingMapUVParam.zw;\n #endif\n return cc_matProj * (cc_matView * matWorld) * In.position;\n}\nvoid main() { gl_Position = vert(); }`, + "frag": `\nprecision highp float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n};\n#if CC_USE_IBL\nuniform samplerCube cc_environment;\nvec3 unpackRGBE (vec4 rgbe) {\n return rgbe.rgb * pow(2.0, rgbe.a * 255.0 - 128.0);\n}\nvec4 fragTextureLod (sampler2D tex, vec2 coord, float lod) {\n return textureLod(tex, coord, lod);\n}\nvec4 fragTextureLod (samplerCube tex, vec3 coord, float lod) {\n return textureLod(tex, coord, lod);\n}\n#endif\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\n}\nuniform CCForwardLight {\n highp vec4 cc_sphereLitPos[2];\n vec4 cc_sphereLitSizeRange[2];\n vec4 cc_sphereLitColor[2];\n highp vec4 cc_spotLitPos[2];\n vec4 cc_spotLitSizeRangeAngle[2];\n vec4 cc_spotLitDir[2];\n vec4 cc_spotLitColor[2];\n};\nfloat SmoothDistAtt (float distSqr, float invSqrAttRadius) {\n float factor = distSqr * invSqrAttRadius;\n float smoothFactor = clamp(1.0 - factor * factor, 0.0, 1.0);\n return smoothFactor * smoothFactor;\n}\nfloat GetDistAtt (float distSqr, float invSqrAttRadius) {\n float attenuation = 1.0 / max(distSqr, 0.01*0.01);\n attenuation *= SmoothDistAtt(distSqr , invSqrAttRadius);\n return attenuation;\n}\nfloat GetAngleAtt (vec3 L, vec3 litDir, float litAngleScale, float litAngleOffset) {\n float cd = dot(litDir, L);\n float attenuation = clamp(cd * litAngleScale + litAngleOffset, 0.0, 1.0);\n return (attenuation * attenuation);\n}\nfloat GGXMobile (float roughness, float NoH, vec3 H, vec3 N) {\n vec3 NxH = cross(N, H);\n float OneMinusNoHSqr = dot(NxH, NxH);\n float a = roughness * roughness;\n float n = NoH * a;\n float p = a / (OneMinusNoHSqr + n * n);\n return p * p;\n}\nfloat CalcSpecular (float roughness, float NoH, vec3 H, vec3 N) {\n return (roughness*0.25 + 0.25) * GGXMobile(roughness, NoH, H, N);\n}\nvec3 BRDFApprox (vec3 specular, float roughness, float NoV) {\n const vec4 c0 = vec4(-1.0, -0.0275, -0.572, 0.022);\n const vec4 c1 = vec4(1.0, 0.0425, 1.04, -0.04);\n vec4 r = roughness * c0 + c1;\n float a004 = min( r.x * r.x, exp2( -9.28 * NoV ) ) * r.x + r.y;\n vec2 AB = vec2( -1.04, 1.04 ) * a004 + r.zw;\n AB.y *= clamp(50.0 * specular.g, 0.0, 1.0);\n return specular * AB.x + AB.y;\n}\nvec3 CalcDynamicLighting (vec3 worldPos, vec3 N, vec3 V, vec3 diffuse, vec3 specular, float roughness) {\n vec3 lighting = vec3(0.0);\n vec3 diffuseContrib = diffuse / 3.14159265359;\n for (int i = 0; i < 2; i++) {\n vec3 PLU = cc_sphereLitPos[i].xyz - worldPos;\n vec3 PL = normalize(PLU);\n vec3 PH = normalize(PL + V);\n float PNL = max(dot(N, PL), 0.001);\n float PNH = max(dot(N, PH), 0.0);\n float distSqr = dot(PLU, PLU);\n float litRadius = cc_sphereLitSizeRange[i].x;\n float litRadiusSqr = litRadius * litRadius;\n float illum = 3.14159265359 * (litRadiusSqr / max(litRadiusSqr , distSqr));\n float attRadiusSqrInv = 1.0 / max(cc_sphereLitSizeRange[i].y, 0.01);\n attRadiusSqrInv *= attRadiusSqrInv;\n float att = GetDistAtt(distSqr, attRadiusSqrInv);\n vec3 lspec = specular * CalcSpecular(roughness, PNH, PH, N);\n lighting += PNL * cc_sphereLitColor[i].rgb * cc_sphereLitColor[i].w * illum * att * (diffuseContrib + lspec);\n }\n for (int i = 0; i < 2; i++) {\n vec3 SLU = cc_spotLitPos[i].xyz - worldPos;\n vec3 SL = normalize(SLU);\n vec3 SH = normalize(SL + V);\n float SNL = max(dot(N, SL), 0.001);\n float SNH = max(dot(N, SH), 0.0);\n float distSqr = dot(SLU, SLU);\n float litRadius = cc_spotLitSizeRangeAngle[i].x;\n float litRadiusSqr = litRadius * litRadius;\n float illum = 3.14159265359 * (litRadiusSqr / max(litRadiusSqr , distSqr));\n float attRadiusSqrInv = 1.0 / max(cc_spotLitSizeRangeAngle[i].y, 0.01);\n attRadiusSqrInv *= attRadiusSqrInv;\n float cosInner = max(dot(-cc_spotLitDir[i].xyz, SL), 0.01);\n float cosOuter = cc_spotLitSizeRangeAngle[i].z;\n float litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\n float litAngleOffset = -cosOuter * litAngleScale;\n float att = GetDistAtt(distSqr, attRadiusSqrInv);\n att *= GetAngleAtt(SL, -cc_spotLitDir[i].xyz, litAngleScale, litAngleOffset);\n vec3 lspec = specular * CalcSpecular(roughness, SNH, SH, N);\n lighting += SNL * cc_spotLitColor[i].rgb * cc_spotLitColor[i].w * illum * att * (diffuseContrib + lspec);\n }\n return lighting;\n}\nstruct StandardSurface {\n vec4 albedo;\n vec3 position;\n vec3 normal;\n vec3 emissive;\n float roughness;\n float metallic;\n float occlusion;\n};\nvec4 CCStandardShading (StandardSurface s) {\n vec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\n vec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\n vec3 N = normalize(s.normal);\n vec3 V = normalize(cc_cameraPos.xyz - s.position);\n vec3 L = normalize(-cc_mainLitDir.xyz);\n vec3 H = normalize(L+V);\n float NV = max(abs(dot(N, V)), 0.001);\n float NL = max(dot(N, L), 0.001);\n float NH = max(dot(N, H), 0.0);\n specular = BRDFApprox(specular, s.roughness, NV);\n vec3 diffuseContrib = diffuse / 3.14159265359;\n vec3 specularContrib = specular * CalcSpecular(s.roughness, NH, H, N);\n vec3 finalColor = NL * cc_mainLitColor.rgb * cc_mainLitColor.w * (diffuseContrib + specularContrib);\n finalColor += CalcDynamicLighting(s.position, N, V, diffuse, specular, s.roughness);\n float fAmb = 0.5 - N.y * 0.5;\n vec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb) * cc_ambientSky.w;\n finalColor += (ambDiff.rgb * diffuse);\n #if CC_USE_IBL\n vec3 R = normalize(reflect(-V, N));\n vec4 envmap = fragTextureLod(cc_environment, R, s.roughness * cc_ambientGround.w);\n #if CC_USE_IBL == 2\n vec3 env = unpackRGBE(envmap);\n #else\n vec3 env = SRGBToLinear(envmap.rgb);\n #endif\n finalColor += env * cc_ambientSky.w * specular;\n #endif\n finalColor = finalColor * s.occlusion;\n #if CC_USE_HDR\n s.emissive *= cc_exposure.w;\n #endif\n finalColor += s.emissive;\n return vec4(finalColor, s.albedo.a);\n}\nvec3 ACESToneMap (vec3 color) {\n color = min(color, vec3(8.0));\n const float A = 2.51;\n const float B = 0.03;\n const float C = 2.43;\n const float D = 0.59;\n const float E = 0.14;\n return (color * (A * color + B)) / (color * (C * color + D) + E);\n}\nvec4 CCFragOutput (vec4 color) {\n #if !CC_USE_HDR\n color.rgb = sqrt(ACESToneMap(color.rgb));\n #endif\n return color;\n}\nuniform Constants {\n vec4 tilingOffset;\n vec4 albedo;\n vec4 albedoScaleAndCutoff;\n vec4 pbrParams;\n vec4 emissive;\n vec4 emissiveScaleParam;\n};\nin vec3 v_position;\nin vec2 v_uv;\nin vec2 v_uv1;\nin vec3 v_normal;\n#if USE_VERTEX_COLOR\n in vec3 v_color;\n#endif\n#if USE_ALBEDO_MAP\n uniform sampler2D albedoMap;\n#endif\n#if USE_NORMAL_MAP\n in vec3 v_tangent;\n in vec3 v_bitangent;\n uniform sampler2D normalMap;\n#endif\n#if USE_PBR_MAP\n uniform sampler2D pbrMap;\n#endif\n#if USE_METALLIC_ROUGHNESS_MAP\n uniform sampler2D metallicRoughnessMap;\n#endif\n#if USE_OCCLUSION_MAP\n uniform sampler2D occlusionMap;\n#endif\n#if USE_EMISSIVE_MAP\n uniform sampler2D emissiveMap;\n#endif\n#if USE_LIGHTMAP\n in vec2 v_luv;\n uniform sampler2D cc_lightingMap;\n#endif\n#if USE_ALPHA_TEST\n#endif\nvoid surf (out StandardSurface s) {\n vec4 baseColor = albedo;\n #if USE_VERTEX_COLOR\n baseColor.rgb *= v_color;\n #endif\n #if USE_ALBEDO_MAP\n vec4 texColor = texture(albedoMap, ALBEDO_UV);\n texColor.rgb = SRGBToLinear(texColor.rgb);\n baseColor *= texColor;\n #endif\n s.albedo = baseColor;\n s.albedo.rgb *= albedoScaleAndCutoff.xyz;\n #if USE_ALPHA_TEST\n if (s.albedo.ALPHA_TEST_CHANNEL < albedoScaleAndCutoff.w) discard;\n #endif\n s.normal = v_normal;\n #if USE_NORMAL_MAP\n vec3 nmmp = texture(normalMap, NORMAL_UV).xyz - vec3(0.5);\n s.normal =\n (nmmp.x * pbrParams.w) * normalize(v_tangent) +\n (nmmp.y * pbrParams.w) * normalize(v_bitangent) +\n nmmp.z * normalize(s.normal);\n #endif\n s.position = v_position;\n vec4 pbr = pbrParams;\n #if USE_PBR_MAP\n vec4 res = texture(pbrMap, PBR_UV);\n pbr.x *= res.OCCLUSION_CHANNEL;\n pbr.y *= res.ROUGHNESS_CHANNEL;\n pbr.z *= res.METALLIC_CHANNEL;\n #endif\n #if USE_METALLIC_ROUGHNESS_MAP\n vec4 metallicRoughness = texture(metallicRoughnessMap, METALLIC_ROUGHNESS_UV);\n pbr.z *= metallicRoughness.METALLIC_CHANNEL;\n pbr.y *= metallicRoughness.ROUGHNESS_CHANNEL;\n #endif\n #if USE_OCCLUSION_MAP\n pbr.x *= texture(occlusionMap, OCCLUSION_UV).OCCLUSION_CHANNEL;\n #endif\n s.occlusion = clamp(pbr.x, 0.0, 0.96);\n s.roughness = clamp(pbr.y, 0.04, 1.0);\n s.metallic = pbr.z;\n s.emissive = emissive.rgb * emissiveScaleParam.xyz;\n #if USE_EMISSIVE_MAP\n s.emissive *= SRGBToLinear(texture(emissiveMap, EMISSIVE_UV).rgb);\n #endif\n}\nvec4 frag () {\n StandardSurface s; surf(s);\n vec4 color = CCStandardShading(s);\n #if USE_LIGHTMAP && !USE_BATCHING && !USE_INSTANCING\n vec4 lighting = texture(cc_lightingMap, v_luv);\n float fAmb = 0.5 - s.normal.y * 0.5;\n vec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb) * cc_ambientSky.w;\n vec3 finalColor = (ambDiff.rgb * s.albedo.rgb);\n finalColor += lighting.rgb * s.albedo.rgb;\n finalColor = finalColor * s.occlusion;\n finalColor += s.emissive;\n color.rgb = lighting.a * finalColor + (1.0 - lighting.a) * color.rgb;\n #endif\n return CCFragOutput(color);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }` }, "glsl1": { - "vert": `\nprecision highp float;\nuniform highp mat4 cc_matView;\nuniform highp mat4 cc_matProj;\nuniform highp vec4 cc_cameraPos;\nuniform mediump vec4 cc_fogBase;\nuniform mediump vec4 cc_fogAdd;\n#if USE_INSTANCING\n attribute vec4 a_matWorld0;\n attribute vec4 a_matWorld1;\n attribute vec4 a_matWorld2;\n#elif USE_BATCHING\n attribute float a_dyn_batch_id;\n uniform highp mat4 cc_matWorlds[10];\n#else\nuniform highp mat4 cc_matWorld;\nuniform highp mat4 cc_matWorldIT;\nuniform highp vec4 cc_lightingMapUVParam;\n#endif\nstruct StandardVertInput {\n highp vec4 position;\n vec3 normal;\n vec4 tangent;\n};\nattribute vec3 a_position;\nattribute vec3 a_normal;\nattribute vec4 a_tangent;\n#if CC_USE_MORPH\n attribute float a_vertexId;\n int getVertexId() {\n return int(a_vertexId);\n }\nuniform vec4 cc_displacementWeights[15];\nuniform vec4 cc_displacementTextureInfo;\n vec4 fetchFlatPixel(sampler2D tex, int pixelIndex) {\n float pixelIndexF = float(pixelIndex);\n vec2 textureResolution = vec2(float(cc_displacementTextureInfo.x), float(cc_displacementTextureInfo.y));\n float pixelX = mod(pixelIndexF, textureResolution.x);\n float pixelY = floor(pixelIndexF / textureResolution.x);\n vec2 uv = (vec2(pixelX, pixelY) + .5) / textureResolution;\n return texture2D(tex, uv);\n }\nfloat getDisplacementWeight(int index) {\n float m = mod(float(index), 4.0);\n if (m < 1.0) {\n return cc_displacementWeights[index / 4].x;\n } else if (m < 2.0) {\n return cc_displacementWeights[index / 4].y;\n } else if (m < 3.0) {\n return cc_displacementWeights[index / 4].z;\n } else {\n return cc_displacementWeights[index / 4].w;\n }\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\n return fetchFlatPixel(tex, vertexIndex).rgb;\n#else\n vec3 result = vec3(0, 0, 0);\n for (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\n int dataPixelStart = int(fetchFlatPixel(tex, iTarget).r);\n result += (fetchFlatPixel(tex, dataPixelStart + vertexIndex).rgb * getDisplacementWeight(iTarget));\n }\n return result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\n uniform sampler2D cc_PositionDisplacements;\n vec3 getPositionDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n uniform sampler2D cc_NormalDisplacements;\n vec3 getNormalDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n uniform sampler2D cc_TangentDisplacements;\n vec3 getTangentDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n }\n#endif\nvoid applyMorph (inout StandardVertInput attr) {\n int vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\n attr.position.xyz = attr.position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n attr.normal.xyz = attr.normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n attr.tangent.xyz = attr.tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\n position.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\nattribute vec4 a_weights;\nattribute vec4 a_joints;\n#if CC_USE_BAKED_ANIMATION\n #if USE_INSTANCING\n attribute vec4 a_jointAnimInfo;\n #endif\n uniform highp vec4 cc_jointTextureInfo;\n uniform highp vec4 cc_jointAnimInfo;\n uniform sampler2D cc_jointTexture;\n #if !CC_SUPPORT_FLOAT_TEXTURE\n highp float decode32 (highp vec4 rgba) {\n rgba = rgba * 255.0;\n highp float Sign = 1.0 - step(128.0, rgba[3]) * 2.0;\n highp float Exponent = 2.0 * mod(rgba[3], 128.0) + step(128.0, rgba[2]) - 127.0;\n highp float Mantissa = mod(rgba[2], 128.0) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\n }\n #endif\n#else\n uniform highp vec4 cc_joints[90];\n#endif\n#if CC_USE_BAKED_ANIMATION\n #if CC_SUPPORT_FLOAT_TEXTURE\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 3.0 * i + a_jointAnimInfo.x;\n #else\n highp float j = 3.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y));\n vec4 v2 = texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y));\n vec4 v3 = texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y));\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #else\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 12.0 * i + a_jointAnimInfo.x;\n #else\n highp float j = 12.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = vec4(\n decode32(texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n );\n vec4 v2 = vec4(\n decode32(texture2D(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n );\n vec4 v3 = vec4(\n decode32(texture2D(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n );\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #endif\n#else\n mat4 getJointMatrix (float i) {\n int idx = int(i);\n vec4 v1 = cc_joints[idx * 3];\n vec4 v2 = cc_joints[idx * 3 + 1];\n vec4 v3 = cc_joints[idx * 3 + 2];\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n#endif\nmat4 skinMatrix () {\n return getJointMatrix(a_joints.x) * a_weights.x\n + getJointMatrix(a_joints.y) * a_weights.y;\n + getJointMatrix(a_joints.z) * a_weights.z;\n + getJointMatrix(a_joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\n mat4 m = skinMatrix();\n position = m * position;\n}\nvoid CCSkin (inout StandardVertInput attr) {\n mat4 m = skinMatrix();\n attr.position = m * attr.position;\n attr.normal = (m * vec4(attr.normal, 0.0)).xyz;\n attr.tangent.xyz = (m * vec4(attr.tangent.xyz, 0.0)).xyz;\n}\n#endif\nuniform vec4 tilingOffset;\nfloat LinearFog(vec4 pos) {\n vec4 wPos = pos;\n float cam_dis = distance(cc_cameraPos, wPos);\n float fogStart = cc_fogBase.x;\n float fogEnd = cc_fogBase.y;\n return clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float fogDensity = cc_fogBase.z;\n float cam_dis = distance(cc_cameraPos, wPos) / fogAtten * 4.;\n float f = exp(-cam_dis * fogDensity);\n return f;\n}\nfloat ExpSquaredFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float fogDensity = cc_fogBase.z;\n float cam_dis = distance(cc_cameraPos, wPos) / fogAtten * 4.;\n float f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\n return f;\n}\nfloat LayeredFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float _FogTop = cc_fogAdd.x;\n float _FogRange = cc_fogAdd.y;\n vec3 camWorldProj = cc_cameraPos.xyz;\n camWorldProj.y = 0.;\n vec3 worldPosProj = wPos.xyz;\n worldPosProj.y = 0.;\n float fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\n float fDeltaY, fDensityIntegral;\n if (cc_cameraPos.y > _FogTop) {\n if (wPos.y < _FogTop) {\n fDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\n fDensityIntegral = fDeltaY * fDeltaY * 0.5;\n } else {\n fDeltaY = 0.;\n fDensityIntegral = 0.;\n }\n } else {\n if (wPos.y < _FogTop) {\n float fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\n float fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\n fDeltaY = abs(fDeltaA - fDeltaB);\n fDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n } else {\n fDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\n fDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n }\n }\n float fDensity;\n if (fDeltaY != 0.) {\n fDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n } else {\n fDensity = 0.;\n }\n float f = exp(-fDensity);\n return f;\n}\nfloat CC_TRANSFER_FOG(vec4 pos) {\n #if CC_USE_FOG == 1\n return LinearFog(pos);\n #elif CC_USE_FOG == 2\n return ExpFog(pos);\n #elif CC_USE_FOG == 3\n return ExpSquaredFog(pos);\n #elif CC_USE_FOG == 4\n return LayeredFog(pos);\n #endif\n return 1.;\n}\n#if USE_VERTEX_COLOR\n attribute vec3 a_color;\n varying vec3 v_color;\n#endif\nvarying vec3 v_position;\nvarying vec3 v_normal;\n#if USE_NORMAL_MAP\n varying vec3 v_tangent;\n varying vec3 v_bitangent;\n#endif\nattribute vec2 a_texCoord;\nvarying vec2 v_uv;\nattribute vec2 a_texCoord1;\nvarying vec2 v_uv1;\nvarying float factor_fog;\n#if USE_LIGHTMAP && !USE_BATCHING && !USE_INSTANCING\n varying vec2 v_luv;\n#endif\nvec4 vert () {\n StandardVertInput In;\n In.position = vec4(a_position, 1.0);\n In.normal = a_normal;\n In.tangent = a_tangent;\n #if CC_USE_MORPH\n applyMorph(In);\n #endif\n #if CC_USE_SKINNING\n CCSkin(In);\n #endif\n mat4 matWorld, matWorldIT;\n #if USE_INSTANCING\n matWorld = mat4(\n vec4(a_matWorld0.xyz, 0.0),\n vec4(a_matWorld1.xyz, 0.0),\n vec4(a_matWorld2.xyz, 0.0),\n vec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)\n );\n matWorldIT = matWorld;\n #elif USE_BATCHING\n matWorld = cc_matWorlds[int(a_dyn_batch_id)];\n matWorldIT = matWorld;\n #else\n matWorld = cc_matWorld;\n matWorldIT = cc_matWorldIT;\n #endif\n vec4 pos = matWorld * In.position;\n v_position = pos.xyz;\n v_normal = normalize((matWorldIT * vec4(In.normal, 0.0)).xyz);\n #if USE_NORMAL_MAP\n v_tangent = normalize((matWorld * vec4(In.tangent.xyz, 0.0)).xyz);\n v_bitangent = cross(v_normal, v_tangent) * In.tangent.w;\n #endif\n v_uv = a_texCoord * tilingOffset.xy + tilingOffset.zw;\n #if HAS_SECOND_UV\n v_uv1 = a_texCoord1 * tilingOffset.xy + tilingOffset.zw;\n #endif\n #if USE_VERTEX_COLOR\n v_color = a_color;\n #endif\n factor_fog = CC_TRANSFER_FOG(matWorld * In.position);\n #if USE_LIGHTMAP && HAS_SECOND_UV && !USE_BATCHING && !USE_INSTANCING\n v_luv = cc_lightingMapUVParam.xy + a_texCoord1 * cc_lightingMapUVParam.zw;\n #endif\n return cc_matProj * (cc_matView * matWorld) * In.position;\n}\nvoid main() { gl_Position = vert(); }`, - "frag": `\n #ifdef GL_EXT_shader_texture_lod\n #extension GL_EXT_shader_texture_lod : enable\n #endif\nprecision highp float;\nuniform highp vec4 cc_cameraPos;\nuniform mediump vec4 cc_exposure;\nuniform mediump vec4 cc_mainLitDir;\nuniform mediump vec4 cc_mainLitColor;\nuniform mediump vec4 cc_ambientSky;\nuniform mediump vec4 cc_ambientGround;\nuniform mediump vec4 cc_fogColor;\n#if CC_USE_IBL\nuniform samplerCube cc_environment;\nvec3 unpackRGBE (vec4 rgbe) {\n return rgbe.rgb * pow(2.0, rgbe.a * 255.0 - 128.0);\n}\nvec4 fragTextureLod (sampler2D tex, vec2 coord, float lod) {\n #ifdef GL_EXT_shader_texture_lod\n return texture2DLodEXT(tex, coord, lod);\n #else\n return texture2D(tex, coord, lod);\n #endif\n}\nvec4 fragTextureLod (samplerCube tex, vec3 coord, float lod) {\n #ifdef GL_EXT_shader_texture_lod\n return textureCubeLodEXT(tex, coord, lod);\n #else\n return textureCube(tex, coord, lod);\n #endif\n}\n#endif\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\n}\nfloat GGXMobile (float roughness, float NoH, vec3 H, vec3 N) {\n vec3 NxH = cross(N, H);\n float OneMinusNoHSqr = dot(NxH, NxH);\n float a = roughness * roughness;\n float n = NoH * a;\n float p = a / (OneMinusNoHSqr + n * n);\n return p * p;\n}\nfloat CalcSpecular (float roughness, float NoH, vec3 H, vec3 N) {\n return (roughness*0.25 + 0.25) * GGXMobile(roughness, NoH, H, N);\n}\nvec3 BRDFApprox (vec3 specular, float roughness, float NoV) {\n const vec4 c0 = vec4(-1.0, -0.0275, -0.572, 0.022);\n const vec4 c1 = vec4(1.0, 0.0425, 1.04, -0.04);\n vec4 r = roughness * c0 + c1;\n float a004 = min( r.x * r.x, exp2( -9.28 * NoV ) ) * r.x + r.y;\n vec2 AB = vec2( -1.04, 1.04 ) * a004 + r.zw;\n AB.y *= clamp(50.0 * specular.g, 0.0, 1.0);\n return specular * AB.x + AB.y;\n}\nstruct StandardSurface {\n vec4 albedo;\n vec3 position;\n vec3 normal;\n vec3 emissive;\n float roughness;\n float metallic;\n float occlusion;\n};\n#if CC_FOWARD_ADD\nuniform highp vec4 cc_lightPos[1];\nuniform vec4 cc_lightColor[1];\nuniform vec4 cc_lightSizeRangeAngle[1];\nuniform vec4 cc_lightDir[1];\nfloat SmoothDistAtt (float distSqr, float invSqrAttRadius) {\n float factor = distSqr * invSqrAttRadius;\n float smoothFactor = clamp(1.0 - factor * factor, 0.0, 1.0);\n return smoothFactor * smoothFactor;\n}\nfloat GetDistAtt (float distSqr, float invSqrAttRadius) {\n float attenuation = 1.0 / max(distSqr, 0.01*0.01);\n attenuation *= SmoothDistAtt(distSqr , invSqrAttRadius);\n return attenuation;\n}\nfloat GetAngleAtt (vec3 L, vec3 litDir, float litAngleScale, float litAngleOffset) {\n float cd = dot(litDir, L);\n float attenuation = clamp(cd * litAngleScale + litAngleOffset, 0.0, 1.0);\n return (attenuation * attenuation);\n}\n vec4 CCStandardShading (StandardSurface s) {\n vec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\n vec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\n vec3 diffuseContrib = diffuse / 3.14159265359;\n vec3 N = normalize(s.normal);\n vec3 V = normalize(cc_cameraPos.xyz - s.position);\n float NV = max(abs(dot(N, V)), 0.001);\n specular = BRDFApprox(specular, s.roughness, NV);\n vec3 finalColor = vec3(0.0);\n for (int i = 0; i < 1; i++) {\n vec3 SLU = cc_lightPos[i].xyz - s.position;\n vec3 SL = normalize(SLU);\n vec3 SH = normalize(SL + V);\n float SNL = max(dot(N, SL), 0.001);\n float SNH = max(dot(N, SH), 0.0);\n float distSqr = dot(SLU, SLU);\n float litRadius = cc_lightSizeRangeAngle[i].x;\n float litRadiusSqr = litRadius * litRadius;\n float illum = 3.14159265359 * (litRadiusSqr / max(litRadiusSqr , distSqr));\n float attRadiusSqrInv = 1.0 / max(cc_lightSizeRangeAngle[i].y, 0.01);\n attRadiusSqrInv *= attRadiusSqrInv;\n float att = GetDistAtt(distSqr, attRadiusSqrInv);\n vec3 lspec = specular * CalcSpecular(s.roughness, SNH, SH, N);\n #if CC_SPOTLIGHT\n float cosInner = max(dot(-cc_lightDir[i].xyz, SL), 0.01);\n float cosOuter = cc_lightSizeRangeAngle[i].z;\n float litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\n float litAngleOffset = -cosOuter * litAngleScale;\n att *= GetAngleAtt(SL, -cc_lightDir[i].xyz, litAngleScale, litAngleOffset);\n #endif\n finalColor += SNL * cc_lightColor[i].rgb * cc_lightColor[i].w * illum * att * (diffuseContrib + lspec);\n }\n return vec4(finalColor, 0.0);\n }\n#else\n vec4 CCStandardShading (StandardSurface s) {\n vec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\n vec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\n vec3 N = normalize(s.normal);\n vec3 V = normalize(cc_cameraPos.xyz - s.position);\n vec3 L = normalize(-cc_mainLitDir.xyz);\n vec3 H = normalize(L+V);\n float NV = max(abs(dot(N, V)), 0.001);\n float NL = max(dot(N, L), 0.001);\n float NH = max(dot(N, H), 0.0);\n specular = BRDFApprox(specular, s.roughness, NV);\n vec3 diffuseContrib = diffuse / 3.14159265359;\n vec3 specularContrib = specular * CalcSpecular(s.roughness, NH, H, N);\n vec3 finalColor = NL * cc_mainLitColor.rgb * cc_mainLitColor.w * (diffuseContrib + specularContrib);\n float fAmb = 0.5 - N.y * 0.5;\n vec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb) * cc_ambientSky.w;\n finalColor += (ambDiff.rgb * diffuse);\n #if CC_USE_IBL\n vec3 R = normalize(reflect(-V, N));\n vec4 envmap = fragTextureLod(cc_environment, R, s.roughness * cc_ambientGround.w);\n #if CC_USE_IBL == 2\n vec3 env = unpackRGBE(envmap);\n #else\n vec3 env = SRGBToLinear(envmap.rgb);\n #endif\n finalColor += env * cc_ambientSky.w * specular;\n #endif\n finalColor = finalColor * s.occlusion;\n #if CC_USE_HDR\n s.emissive *= cc_exposure.w;\n #endif\n finalColor += s.emissive;\n return vec4(finalColor, s.albedo.a);\n }\n#endif\nvec3 ACESToneMap (vec3 color) {\n color = min(color, vec3(8.0));\n const float A = 2.51;\n const float B = 0.03;\n const float C = 2.43;\n const float D = 0.59;\n const float E = 0.14;\n return (color * (A * color + B)) / (color * (C * color + D) + E);\n}\nvec4 CCFragOutput (vec4 color) {\n #if !CC_USE_HDR\n color.rgb = sqrt(ACESToneMap(color.rgb));\n #endif\n return color;\n}\nuniform vec4 albedo;\nuniform vec4 albedoScaleAndCutoff;\nuniform vec4 pbrParams;\nuniform vec4 emissive;\nuniform vec4 emissiveScaleParam;\nvarying vec3 v_position;\nvarying vec2 v_uv;\nvarying vec2 v_uv1;\nvarying vec3 v_normal;\n#if USE_VERTEX_COLOR\n varying vec3 v_color;\n#endif\n#if USE_ALBEDO_MAP\n uniform sampler2D albedoMap;\n#endif\n#if USE_NORMAL_MAP\n varying vec3 v_tangent;\n varying vec3 v_bitangent;\n uniform sampler2D normalMap;\n#endif\n#if USE_PBR_MAP\n uniform sampler2D pbrMap;\n#endif\n#if USE_METALLIC_ROUGHNESS_MAP\n uniform sampler2D metallicRoughnessMap;\n#endif\n#if USE_OCCLUSION_MAP\n uniform sampler2D occlusionMap;\n#endif\n#if USE_EMISSIVE_MAP\n uniform sampler2D emissiveMap;\n#endif\n#if USE_LIGHTMAP\n varying vec2 v_luv;\n uniform sampler2D cc_lightingMap;\n#endif\n#if USE_ALPHA_TEST\n#endif\nvarying float factor_fog;\nvoid surf (out StandardSurface s) {\n vec4 baseColor = albedo;\n #if USE_VERTEX_COLOR\n baseColor.rgb *= v_color;\n #endif\n #if USE_ALBEDO_MAP\n vec4 texColor = texture2D(albedoMap, ALBEDO_UV);\n texColor.rgb = SRGBToLinear(texColor.rgb);\n baseColor *= texColor;\n #endif\n s.albedo = baseColor;\n s.albedo.rgb *= albedoScaleAndCutoff.xyz;\n #if USE_ALPHA_TEST\n if (s.albedo.ALPHA_TEST_CHANNEL < albedoScaleAndCutoff.w) discard;\n #endif\n s.normal = v_normal;\n #if USE_NORMAL_MAP\n vec3 nmmp = texture2D(normalMap, NORMAL_UV).xyz - vec3(0.5);\n s.normal =\n (nmmp.x * pbrParams.w) * normalize(v_tangent) +\n (nmmp.y * pbrParams.w) * normalize(v_bitangent) +\n nmmp.z * normalize(s.normal);\n #endif\n s.position = v_position;\n vec4 pbr = pbrParams;\n #if USE_PBR_MAP\n vec4 res = texture2D(pbrMap, PBR_UV);\n pbr.x *= res.OCCLUSION_CHANNEL;\n pbr.y *= res.ROUGHNESS_CHANNEL;\n pbr.z *= res.METALLIC_CHANNEL;\n #endif\n #if USE_METALLIC_ROUGHNESS_MAP\n vec4 metallicRoughness = texture2D(metallicRoughnessMap, METALLIC_ROUGHNESS_UV);\n pbr.z *= metallicRoughness.METALLIC_CHANNEL;\n pbr.y *= metallicRoughness.ROUGHNESS_CHANNEL;\n #endif\n #if USE_OCCLUSION_MAP\n pbr.x *= texture2D(occlusionMap, OCCLUSION_UV).OCCLUSION_CHANNEL;\n #endif\n s.occlusion = clamp(pbr.x, 0.0, 0.96);\n s.roughness = clamp(pbr.y, 0.04, 1.0);\n s.metallic = pbr.z;\n s.emissive = emissive.rgb * emissiveScaleParam.xyz;\n #if USE_EMISSIVE_MAP\n s.emissive *= SRGBToLinear(texture2D(emissiveMap, EMISSIVE_UV).rgb);\n #endif\n}\nvec4 frag () {\n StandardSurface s; surf(s);\n vec4 color = CCStandardShading(s);\n #if USE_LIGHTMAP && !USE_BATCHING && !USE_INSTANCING && CC_FOWARD_ADD == 0\n vec4 lighting = texture2D(cc_lightingMap, v_luv);\n float fAmb = 0.5 - s.normal.y * 0.5;\n vec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb) * cc_ambientSky.w;\n vec3 finalColor = (ambDiff.rgb * s.albedo.rgb);\n finalColor += lighting.rgb * s.albedo.rgb;\n finalColor = finalColor * s.occlusion;\n finalColor += s.emissive;\n color.rgb = lighting.a * finalColor + (1.0 - lighting.a) * color.rgb;\n #endif\n color = mix(cc_fogColor, color, factor_fog);\n return CCFragOutput(color);\n}\nvoid main() { gl_FragColor = frag(); }` + "vert": `\nprecision highp float;\nstruct StandardVertInput {\n highp vec4 position;\n vec3 normal;\n vec4 tangent;\n};\nattribute vec3 a_position;\nattribute vec3 a_normal;\nattribute vec4 a_tangent;\n#if CC_USE_MORPH\n attribute float a_vertexId;\n int getVertexId() {\n return int(a_vertexId);\n }\nuniform vec4 cc_displacementWeights[15];\nuniform vec4 cc_displacementTextureInfo;\n vec4 fetchFlatPixel(sampler2D tex, int pixelIndex) {\n float pixelIndexF = float(pixelIndex);\n vec2 textureResolution = vec2(float(cc_displacementTextureInfo.x), float(cc_displacementTextureInfo.y));\n float pixelX = mod(pixelIndexF, textureResolution.x);\n float pixelY = floor(pixelIndexF / textureResolution.x);\n vec2 uv = (vec2(pixelX, pixelY) + .5) / textureResolution;\n return texture2D(tex, uv);\n }\nfloat getDisplacementWeight(int index) {\n float m = mod(float(index), 4.0);\n if (m < 1.0) {\n return cc_displacementWeights[index / 4].x;\n } else if (m < 2.0) {\n return cc_displacementWeights[index / 4].y;\n } else if (m < 3.0) {\n return cc_displacementWeights[index / 4].z;\n } else {\n return cc_displacementWeights[index / 4].w;\n }\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\n return fetchFlatPixel(tex, vertexIndex).rgb;\n#else\n vec3 result = vec3(0, 0, 0);\n for (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\n int dataPixelStart = int(fetchFlatPixel(tex, iTarget).r);\n result += (fetchFlatPixel(tex, dataPixelStart + vertexIndex).rgb * getDisplacementWeight(iTarget));\n }\n return result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\n uniform sampler2D cc_PositionDisplacements;\n vec3 getPositionDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n uniform sampler2D cc_NormalDisplacements;\n vec3 getNormalDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n uniform sampler2D cc_TangentDisplacements;\n vec3 getTangentDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n }\n#endif\nvoid applyMorph (inout StandardVertInput attr) {\n int vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\n attr.position.xyz = attr.position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n attr.normal.xyz = attr.normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n attr.tangent.xyz = attr.tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\n position.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\nattribute vec4 a_weights;\nattribute vec4 a_joints;\n#if CC_USE_BAKED_ANIMATION\n #if USE_INSTANCING\n attribute highp vec4 a_jointAnimInfo;\n #endif\n uniform highp vec4 cc_jointTextureInfo;\n uniform highp vec4 cc_jointAnimInfo;\n uniform sampler2D cc_jointTexture;\n #if !CC_SUPPORT_FLOAT_TEXTURE\n highp float decode32 (highp vec4 rgba) {\n rgba = rgba * 255.0;\n highp float Sign = 1.0 - step(128.0, rgba[3]) * 2.0;\n highp float Exponent = 2.0 * mod(rgba[3], 128.0) + step(128.0, rgba[2]) - 127.0;\n highp float Mantissa = mod(rgba[2], 128.0) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\n }\n #endif\n#else\n uniform highp vec4 cc_joints[90];\n#endif\n#if CC_USE_BAKED_ANIMATION\n #if CC_SUPPORT_FLOAT_TEXTURE\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 3.0 * (a_jointAnimInfo.x * a_jointAnimInfo.y + i) + a_jointAnimInfo.z;\n #else\n highp float j = 3.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y));\n vec4 v2 = texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y));\n vec4 v3 = texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y));\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #else\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 12.0 * (a_jointAnimInfo.x * a_jointAnimInfo.y + i) + a_jointAnimInfo.z;\n #else\n highp float j = 12.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = vec4(\n decode32(texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n );\n vec4 v2 = vec4(\n decode32(texture2D(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n );\n vec4 v3 = vec4(\n decode32(texture2D(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n );\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #endif\n#else\n mat4 getJointMatrix (float i) {\n int idx = int(i);\n vec4 v1 = cc_joints[idx * 3];\n vec4 v2 = cc_joints[idx * 3 + 1];\n vec4 v3 = cc_joints[idx * 3 + 2];\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n#endif\nmat4 skinMatrix () {\n return getJointMatrix(a_joints.x) * a_weights.x\n + getJointMatrix(a_joints.y) * a_weights.y;\n + getJointMatrix(a_joints.z) * a_weights.z;\n + getJointMatrix(a_joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\n mat4 m = skinMatrix();\n position = m * position;\n}\nvoid CCSkin (inout StandardVertInput attr) {\n mat4 m = skinMatrix();\n attr.position = m * attr.position;\n attr.normal = (m * vec4(attr.normal, 0.0)).xyz;\n attr.tangent.xyz = (m * vec4(attr.tangent.xyz, 0.0)).xyz;\n}\n#endif\nuniform highp mat4 cc_matView;\nuniform highp mat4 cc_matProj;\n#if USE_INSTANCING\n attribute vec4 a_matWorld0;\n attribute vec4 a_matWorld1;\n attribute vec4 a_matWorld2;\n#elif USE_BATCHING\n attribute float a_dyn_batch_id;\n uniform highp mat4 cc_matWorlds[10];\n#else\nuniform highp mat4 cc_matWorld;\nuniform highp mat4 cc_matWorldIT;\nuniform highp vec4 cc_lightingMapUVParam;\n#endif\nuniform vec4 tilingOffset;\n#if USE_VERTEX_COLOR\n attribute vec3 a_color;\n varying vec3 v_color;\n#endif\nvarying vec3 v_position;\nvarying vec3 v_normal;\n#if USE_NORMAL_MAP\n varying vec3 v_tangent;\n varying vec3 v_bitangent;\n#endif\nattribute vec2 a_texCoord;\nvarying vec2 v_uv;\nattribute vec2 a_texCoord1;\nvarying vec2 v_uv1;\n#if USE_LIGHTMAP && !USE_BATCHING && !USE_INSTANCING\n varying vec2 v_luv;\n#endif\nvec4 vert () {\n StandardVertInput In;\n In.position = vec4(a_position, 1.0);\n In.normal = a_normal;\n In.tangent = a_tangent;\n #if CC_USE_MORPH\n applyMorph(In);\n #endif\n #if CC_USE_SKINNING\n CCSkin(In);\n #endif\n mat4 matWorld, matWorldIT;\n #if USE_INSTANCING\n matWorld = mat4(\n vec4(a_matWorld0.xyz, 0.0),\n vec4(a_matWorld1.xyz, 0.0),\n vec4(a_matWorld2.xyz, 0.0),\n vec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)\n );\n matWorldIT = matWorld;\n #elif USE_BATCHING\n matWorld = cc_matWorlds[int(a_dyn_batch_id)];\n matWorldIT = matWorld;\n #else\n matWorld = cc_matWorld;\n matWorldIT = cc_matWorldIT;\n #endif\n vec4 pos = matWorld * In.position;\n v_position = pos.xyz;\n v_normal = normalize((matWorldIT * vec4(In.normal, 0.0)).xyz);\n #if USE_NORMAL_MAP\n v_tangent = normalize((matWorld * vec4(In.tangent.xyz, 0.0)).xyz);\n v_bitangent = cross(v_normal, v_tangent) * In.tangent.w;\n #endif\n v_uv = a_texCoord * tilingOffset.xy + tilingOffset.zw;\n #if HAS_SECOND_UV\n v_uv1 = a_texCoord1 * tilingOffset.xy + tilingOffset.zw;\n #endif\n #if USE_VERTEX_COLOR\n v_color = a_color;\n #endif\n #if USE_LIGHTMAP && HAS_SECOND_UV && !USE_BATCHING && !USE_INSTANCING\n v_luv = cc_lightingMapUVParam.xy + a_texCoord1 * cc_lightingMapUVParam.zw;\n #endif\n return cc_matProj * (cc_matView * matWorld) * In.position;\n}\nvoid main() { gl_Position = vert(); }`, + "frag": `\n #ifdef GL_EXT_shader_texture_lod\n #extension GL_EXT_shader_texture_lod : enable\n #endif\nprecision highp float;\nuniform highp vec4 cc_cameraPos;\nuniform mediump vec4 cc_exposure;\nuniform mediump vec4 cc_mainLitDir;\nuniform mediump vec4 cc_mainLitColor;\nuniform mediump vec4 cc_ambientSky;\nuniform mediump vec4 cc_ambientGround;\n#if CC_USE_IBL\nuniform samplerCube cc_environment;\nvec3 unpackRGBE (vec4 rgbe) {\n return rgbe.rgb * pow(2.0, rgbe.a * 255.0 - 128.0);\n}\nvec4 fragTextureLod (sampler2D tex, vec2 coord, float lod) {\n #ifdef GL_EXT_shader_texture_lod\n return texture2DLodEXT(tex, coord, lod);\n #else\n return texture2D(tex, coord, lod);\n #endif\n}\nvec4 fragTextureLod (samplerCube tex, vec3 coord, float lod) {\n #ifdef GL_EXT_shader_texture_lod\n return textureCubeLodEXT(tex, coord, lod);\n #else\n return textureCube(tex, coord, lod);\n #endif\n}\n#endif\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\n}\nuniform highp vec4 cc_sphereLitPos[2];\nuniform vec4 cc_sphereLitSizeRange[2];\nuniform vec4 cc_sphereLitColor[2];\nuniform highp vec4 cc_spotLitPos[2];\nuniform vec4 cc_spotLitSizeRangeAngle[2];\nuniform vec4 cc_spotLitDir[2];\nuniform vec4 cc_spotLitColor[2];\nfloat SmoothDistAtt (float distSqr, float invSqrAttRadius) {\n float factor = distSqr * invSqrAttRadius;\n float smoothFactor = clamp(1.0 - factor * factor, 0.0, 1.0);\n return smoothFactor * smoothFactor;\n}\nfloat GetDistAtt (float distSqr, float invSqrAttRadius) {\n float attenuation = 1.0 / max(distSqr, 0.01*0.01);\n attenuation *= SmoothDistAtt(distSqr , invSqrAttRadius);\n return attenuation;\n}\nfloat GetAngleAtt (vec3 L, vec3 litDir, float litAngleScale, float litAngleOffset) {\n float cd = dot(litDir, L);\n float attenuation = clamp(cd * litAngleScale + litAngleOffset, 0.0, 1.0);\n return (attenuation * attenuation);\n}\nfloat GGXMobile (float roughness, float NoH, vec3 H, vec3 N) {\n vec3 NxH = cross(N, H);\n float OneMinusNoHSqr = dot(NxH, NxH);\n float a = roughness * roughness;\n float n = NoH * a;\n float p = a / (OneMinusNoHSqr + n * n);\n return p * p;\n}\nfloat CalcSpecular (float roughness, float NoH, vec3 H, vec3 N) {\n return (roughness*0.25 + 0.25) * GGXMobile(roughness, NoH, H, N);\n}\nvec3 BRDFApprox (vec3 specular, float roughness, float NoV) {\n const vec4 c0 = vec4(-1.0, -0.0275, -0.572, 0.022);\n const vec4 c1 = vec4(1.0, 0.0425, 1.04, -0.04);\n vec4 r = roughness * c0 + c1;\n float a004 = min( r.x * r.x, exp2( -9.28 * NoV ) ) * r.x + r.y;\n vec2 AB = vec2( -1.04, 1.04 ) * a004 + r.zw;\n AB.y *= clamp(50.0 * specular.g, 0.0, 1.0);\n return specular * AB.x + AB.y;\n}\nvec3 CalcDynamicLighting (vec3 worldPos, vec3 N, vec3 V, vec3 diffuse, vec3 specular, float roughness) {\n vec3 lighting = vec3(0.0);\n vec3 diffuseContrib = diffuse / 3.14159265359;\n for (int i = 0; i < 2; i++) {\n vec3 PLU = cc_sphereLitPos[i].xyz - worldPos;\n vec3 PL = normalize(PLU);\n vec3 PH = normalize(PL + V);\n float PNL = max(dot(N, PL), 0.001);\n float PNH = max(dot(N, PH), 0.0);\n float distSqr = dot(PLU, PLU);\n float litRadius = cc_sphereLitSizeRange[i].x;\n float litRadiusSqr = litRadius * litRadius;\n float illum = 3.14159265359 * (litRadiusSqr / max(litRadiusSqr , distSqr));\n float attRadiusSqrInv = 1.0 / max(cc_sphereLitSizeRange[i].y, 0.01);\n attRadiusSqrInv *= attRadiusSqrInv;\n float att = GetDistAtt(distSqr, attRadiusSqrInv);\n vec3 lspec = specular * CalcSpecular(roughness, PNH, PH, N);\n lighting += PNL * cc_sphereLitColor[i].rgb * cc_sphereLitColor[i].w * illum * att * (diffuseContrib + lspec);\n }\n for (int i = 0; i < 2; i++) {\n vec3 SLU = cc_spotLitPos[i].xyz - worldPos;\n vec3 SL = normalize(SLU);\n vec3 SH = normalize(SL + V);\n float SNL = max(dot(N, SL), 0.001);\n float SNH = max(dot(N, SH), 0.0);\n float distSqr = dot(SLU, SLU);\n float litRadius = cc_spotLitSizeRangeAngle[i].x;\n float litRadiusSqr = litRadius * litRadius;\n float illum = 3.14159265359 * (litRadiusSqr / max(litRadiusSqr , distSqr));\n float attRadiusSqrInv = 1.0 / max(cc_spotLitSizeRangeAngle[i].y, 0.01);\n attRadiusSqrInv *= attRadiusSqrInv;\n float cosInner = max(dot(-cc_spotLitDir[i].xyz, SL), 0.01);\n float cosOuter = cc_spotLitSizeRangeAngle[i].z;\n float litAngleScale = 1.0 / max(0.001, cosInner - cosOuter);\n float litAngleOffset = -cosOuter * litAngleScale;\n float att = GetDistAtt(distSqr, attRadiusSqrInv);\n att *= GetAngleAtt(SL, -cc_spotLitDir[i].xyz, litAngleScale, litAngleOffset);\n vec3 lspec = specular * CalcSpecular(roughness, SNH, SH, N);\n lighting += SNL * cc_spotLitColor[i].rgb * cc_spotLitColor[i].w * illum * att * (diffuseContrib + lspec);\n }\n return lighting;\n}\nstruct StandardSurface {\n vec4 albedo;\n vec3 position;\n vec3 normal;\n vec3 emissive;\n float roughness;\n float metallic;\n float occlusion;\n};\nvec4 CCStandardShading (StandardSurface s) {\n vec3 diffuse = s.albedo.rgb * (1.0 - s.metallic);\n vec3 specular = mix(vec3(0.04), s.albedo.rgb, s.metallic);\n vec3 N = normalize(s.normal);\n vec3 V = normalize(cc_cameraPos.xyz - s.position);\n vec3 L = normalize(-cc_mainLitDir.xyz);\n vec3 H = normalize(L+V);\n float NV = max(abs(dot(N, V)), 0.001);\n float NL = max(dot(N, L), 0.001);\n float NH = max(dot(N, H), 0.0);\n specular = BRDFApprox(specular, s.roughness, NV);\n vec3 diffuseContrib = diffuse / 3.14159265359;\n vec3 specularContrib = specular * CalcSpecular(s.roughness, NH, H, N);\n vec3 finalColor = NL * cc_mainLitColor.rgb * cc_mainLitColor.w * (diffuseContrib + specularContrib);\n finalColor += CalcDynamicLighting(s.position, N, V, diffuse, specular, s.roughness);\n float fAmb = 0.5 - N.y * 0.5;\n vec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb) * cc_ambientSky.w;\n finalColor += (ambDiff.rgb * diffuse);\n #if CC_USE_IBL\n vec3 R = normalize(reflect(-V, N));\n vec4 envmap = fragTextureLod(cc_environment, R, s.roughness * cc_ambientGround.w);\n #if CC_USE_IBL == 2\n vec3 env = unpackRGBE(envmap);\n #else\n vec3 env = SRGBToLinear(envmap.rgb);\n #endif\n finalColor += env * cc_ambientSky.w * specular;\n #endif\n finalColor = finalColor * s.occlusion;\n #if CC_USE_HDR\n s.emissive *= cc_exposure.w;\n #endif\n finalColor += s.emissive;\n return vec4(finalColor, s.albedo.a);\n}\nvec3 ACESToneMap (vec3 color) {\n color = min(color, vec3(8.0));\n const float A = 2.51;\n const float B = 0.03;\n const float C = 2.43;\n const float D = 0.59;\n const float E = 0.14;\n return (color * (A * color + B)) / (color * (C * color + D) + E);\n}\nvec4 CCFragOutput (vec4 color) {\n #if !CC_USE_HDR\n color.rgb = sqrt(ACESToneMap(color.rgb));\n #endif\n return color;\n}\nuniform vec4 albedo;\nuniform vec4 albedoScaleAndCutoff;\nuniform vec4 pbrParams;\nuniform vec4 emissive;\nuniform vec4 emissiveScaleParam;\nvarying vec3 v_position;\nvarying vec2 v_uv;\nvarying vec2 v_uv1;\nvarying vec3 v_normal;\n#if USE_VERTEX_COLOR\n varying vec3 v_color;\n#endif\n#if USE_ALBEDO_MAP\n uniform sampler2D albedoMap;\n#endif\n#if USE_NORMAL_MAP\n varying vec3 v_tangent;\n varying vec3 v_bitangent;\n uniform sampler2D normalMap;\n#endif\n#if USE_PBR_MAP\n uniform sampler2D pbrMap;\n#endif\n#if USE_METALLIC_ROUGHNESS_MAP\n uniform sampler2D metallicRoughnessMap;\n#endif\n#if USE_OCCLUSION_MAP\n uniform sampler2D occlusionMap;\n#endif\n#if USE_EMISSIVE_MAP\n uniform sampler2D emissiveMap;\n#endif\n#if USE_LIGHTMAP\n varying vec2 v_luv;\n uniform sampler2D cc_lightingMap;\n#endif\n#if USE_ALPHA_TEST\n#endif\nvoid surf (out StandardSurface s) {\n vec4 baseColor = albedo;\n #if USE_VERTEX_COLOR\n baseColor.rgb *= v_color;\n #endif\n #if USE_ALBEDO_MAP\n vec4 texColor = texture2D(albedoMap, ALBEDO_UV);\n texColor.rgb = SRGBToLinear(texColor.rgb);\n baseColor *= texColor;\n #endif\n s.albedo = baseColor;\n s.albedo.rgb *= albedoScaleAndCutoff.xyz;\n #if USE_ALPHA_TEST\n if (s.albedo.ALPHA_TEST_CHANNEL < albedoScaleAndCutoff.w) discard;\n #endif\n s.normal = v_normal;\n #if USE_NORMAL_MAP\n vec3 nmmp = texture2D(normalMap, NORMAL_UV).xyz - vec3(0.5);\n s.normal =\n (nmmp.x * pbrParams.w) * normalize(v_tangent) +\n (nmmp.y * pbrParams.w) * normalize(v_bitangent) +\n nmmp.z * normalize(s.normal);\n #endif\n s.position = v_position;\n vec4 pbr = pbrParams;\n #if USE_PBR_MAP\n vec4 res = texture2D(pbrMap, PBR_UV);\n pbr.x *= res.OCCLUSION_CHANNEL;\n pbr.y *= res.ROUGHNESS_CHANNEL;\n pbr.z *= res.METALLIC_CHANNEL;\n #endif\n #if USE_METALLIC_ROUGHNESS_MAP\n vec4 metallicRoughness = texture2D(metallicRoughnessMap, METALLIC_ROUGHNESS_UV);\n pbr.z *= metallicRoughness.METALLIC_CHANNEL;\n pbr.y *= metallicRoughness.ROUGHNESS_CHANNEL;\n #endif\n #if USE_OCCLUSION_MAP\n pbr.x *= texture2D(occlusionMap, OCCLUSION_UV).OCCLUSION_CHANNEL;\n #endif\n s.occlusion = clamp(pbr.x, 0.0, 0.96);\n s.roughness = clamp(pbr.y, 0.04, 1.0);\n s.metallic = pbr.z;\n s.emissive = emissive.rgb * emissiveScaleParam.xyz;\n #if USE_EMISSIVE_MAP\n s.emissive *= SRGBToLinear(texture2D(emissiveMap, EMISSIVE_UV).rgb);\n #endif\n}\nvec4 frag () {\n StandardSurface s; surf(s);\n vec4 color = CCStandardShading(s);\n #if USE_LIGHTMAP && !USE_BATCHING && !USE_INSTANCING\n vec4 lighting = texture2D(cc_lightingMap, v_luv);\n float fAmb = 0.5 - s.normal.y * 0.5;\n vec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb) * cc_ambientSky.w;\n vec3 finalColor = (ambDiff.rgb * s.albedo.rgb);\n finalColor += lighting.rgb * s.albedo.rgb;\n finalColor = finalColor * s.occlusion;\n finalColor += s.emissive;\n color.rgb = lighting.a * finalColor + (1.0 - lighting.a) * color.rgb;\n #endif\n return CCFragOutput(color);\n}\nvoid main() { gl_FragColor = frag(); }` }, "builtins": { "globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }], "samplers": [{ "name": "cc_environment", "defines": ["CC_USE_IBL"] }] }, - "locals": { "blocks": [{ "name": "CCLocalBatched", "defines": ["!USE_INSTANCING", "USE_BATCHING"] }, { "name": "CCLocal", "defines": ["!USE_INSTANCING", "!USE_BATCHING"] }, { "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": "CCForwardLight", "defines": ["CC_FOWARD_ADD"] }], "samplers": [{ "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"] }] } + "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": [] }], "samplers": [{ "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"] }] } }, "defines": [ - { "name": "USE_INSTANCING", "type": "boolean" }, - { "name": "USE_BATCHING", "type": "boolean" }, { "name": "CC_USE_MORPH", "type": "boolean" }, - { "name": "CC_MORPH_TARGET_COUNT", "type": "number", "dummyDependency": true, "range": [2, 8] }, + { "name": "CC_MORPH_TARGET_COUNT", "type": "number", "range": [2, 8] }, { "name": "CC_MORPH_PRECOMPUTED", "type": "boolean" }, { "name": "CC_MORPH_TARGET_HAS_POSITION", "type": "boolean" }, { "name": "CC_MORPH_TARGET_HAS_NORMAL", "type": "boolean" }, { "name": "CC_MORPH_TARGET_HAS_TANGENT", "type": "boolean" }, { "name": "CC_USE_SKINNING", "type": "boolean" }, { "name": "CC_USE_BAKED_ANIMATION", "type": "boolean" }, + { "name": "USE_INSTANCING", "type": "boolean" }, { "name": "CC_SUPPORT_FLOAT_TEXTURE", "type": "boolean" }, - { "name": "CC_USE_FOG", "type": "number", "range": [0, 4] }, + { "name": "USE_BATCHING", "type": "boolean" }, { "name": "USE_VERTEX_COLOR", "type": "boolean" }, { "name": "USE_NORMAL_MAP", "type": "boolean" }, { "name": "USE_LIGHTMAP", "type": "boolean" }, { "name": "HAS_SECOND_UV", "type": "boolean" }, { "name": "CC_USE_IBL", "type": "number", "range": [0, 2] }, - { "name": "CC_FOWARD_ADD", "type": "number", "range": [0, 3] }, - { "name": "CC_SPOTLIGHT", "type": "boolean" }, { "name": "CC_USE_HDR", "type": "boolean" }, { "name": "USE_ALBEDO_MAP", "type": "boolean" }, - { "name": "ALBEDO_UV", "type": "string", "dummyDependency": true, "options": ["v_uv", "v_uv1"] }, - { "name": "NORMAL_UV", "type": "string", "dummyDependency": true, "options": ["v_uv", "v_uv1"] }, + { "name": "ALBEDO_UV", "type": "string", "options": ["v_uv", "v_uv1"] }, + { "name": "NORMAL_UV", "type": "string", "options": ["v_uv", "v_uv1"] }, { "name": "USE_PBR_MAP", "type": "boolean" }, - { "name": "PBR_UV", "type": "string", "dummyDependency": true, "options": ["v_uv", "v_uv1"] }, + { "name": "PBR_UV", "type": "string", "options": ["v_uv", "v_uv1"] }, { "name": "USE_METALLIC_ROUGHNESS_MAP", "type": "boolean" }, - { "name": "METALLIC_ROUGHNESS_UV", "type": "string", "dummyDependency": true, "options": ["v_uv", "v_uv1"] }, + { "name": "METALLIC_ROUGHNESS_UV", "type": "string", "options": ["v_uv", "v_uv1"] }, { "name": "USE_OCCLUSION_MAP", "type": "boolean" }, - { "name": "OCCLUSION_UV", "type": "string", "dummyDependency": true, "options": ["v_uv", "v_uv1"] }, + { "name": "OCCLUSION_UV", "type": "string", "options": ["v_uv", "v_uv1"] }, { "name": "USE_EMISSIVE_MAP", "type": "boolean" }, - { "name": "EMISSIVE_UV", "type": "string", "dummyDependency": true, "options": ["v_uv", "v_uv1"] }, - { "name": "OCCLUSION_CHANNEL", "type": "string", "dummyDependency": true, "options": ["r", "g", "b"] }, - { "name": "ROUGHNESS_CHANNEL", "type": "string", "dummyDependency": true, "options": ["g", "b", "r"] }, - { "name": "METALLIC_CHANNEL", "type": "string", "dummyDependency": true, "options": ["b", "r", "g"] }, + { "name": "EMISSIVE_UV", "type": "string", "options": ["v_uv", "v_uv1"] }, + { "name": "OCCLUSION_CHANNEL", "type": "string", "options": ["r", "g", "b"] }, + { "name": "ROUGHNESS_CHANNEL", "type": "string", "options": ["g", "b", "r"] }, + { "name": "METALLIC_CHANNEL", "type": "string", "options": ["b", "r", "g"] }, { "name": "USE_ALPHA_TEST", "type": "boolean" }, - { "name": "ALPHA_TEST_CHANNEL", "type": "string", "dummyDependency": true, "options": ["a", "r"] } + { "name": "ALPHA_TEST_CHANNEL", "type": "string", "options": ["a", "r"] } ], "blocks": [ {"name": "Constants", "defines": [], "binding": 0, "members": [ @@ -366,17 +363,17 @@ export default [ { "name": "emissiveMap", "type": 28, "count": 1, "defines": ["USE_EMISSIVE_MAP"], "binding": 36 } ], "attributes": [ - { "name": "a_matWorld0", "type": 16, "count": 1, "defines": ["USE_INSTANCING"], "format": 43, "isInstanced": true, "location": 4 }, - { "name": "a_matWorld1", "type": 16, "count": 1, "defines": ["USE_INSTANCING"], "format": 43, "isInstanced": true, "location": 5 }, - { "name": "a_matWorld2", "type": 16, "count": 1, "defines": ["USE_INSTANCING"], "format": 43, "isInstanced": true, "location": 6 }, - { "name": "a_dyn_batch_id", "type": 13, "count": 1, "defines": ["!USE_INSTANCING", "USE_BATCHING"], "format": 11, "location": 3 }, { "name": "a_position", "type": 15, "count": 1, "defines": [], "format": 32, "location": 0 }, { "name": "a_normal", "type": 15, "count": 1, "defines": [], "format": 32, "location": 1 }, { "name": "a_tangent", "type": 16, "count": 1, "defines": [], "format": 43, "location": 2 }, - { "name": "a_vertexId", "type": 13, "count": 1, "defines": ["CC_USE_MORPH"], "format": 11, "location": 7 }, - { "name": "a_weights", "type": 16, "count": 1, "defines": ["CC_USE_SKINNING"], "format": 43, "location": 8 }, - { "name": "a_joints", "type": 16, "count": 1, "defines": ["CC_USE_SKINNING"], "format": 43, "location": 9 }, - { "name": "a_jointAnimInfo", "type": 16, "count": 1, "defines": ["CC_USE_SKINNING", "CC_USE_BAKED_ANIMATION", "USE_INSTANCING"], "format": 43, "isInstanced": true, "location": 10 }, + { "name": "a_vertexId", "type": 13, "count": 1, "defines": ["CC_USE_MORPH"], "format": 11, "location": 3 }, + { "name": "a_weights", "type": 16, "count": 1, "defines": ["CC_USE_SKINNING"], "format": 43, "location": 4 }, + { "name": "a_joints", "type": 16, "count": 1, "defines": ["CC_USE_SKINNING"], "format": 43, "location": 5 }, + { "name": "a_jointAnimInfo", "type": 16, "count": 1, "precision": "highp ", "defines": ["CC_USE_SKINNING", "CC_USE_BAKED_ANIMATION", "USE_INSTANCING"], "format": 43, "isInstanced": true, "location": 6 }, + { "name": "a_matWorld0", "type": 16, "count": 1, "defines": ["USE_INSTANCING"], "format": 43, "isInstanced": true, "location": 7 }, + { "name": "a_matWorld1", "type": 16, "count": 1, "defines": ["USE_INSTANCING"], "format": 43, "isInstanced": true, "location": 8 }, + { "name": "a_matWorld2", "type": 16, "count": 1, "defines": ["USE_INSTANCING"], "format": 43, "isInstanced": true, "location": 9 }, + { "name": "a_dyn_batch_id", "type": 13, "count": 1, "defines": ["!USE_INSTANCING", "USE_BATCHING"], "format": 11, "location": 10 }, { "name": "a_color", "type": 15, "count": 1, "defines": ["USE_VERTEX_COLOR"], "format": 32, "location": 11 }, { "name": "a_texCoord", "type": 14, "count": 1, "defines": [], "format": 21, "location": 12 }, { "name": "a_texCoord1", "type": 14, "count": 1, "defines": [], "format": 21, "location": 13 } @@ -393,14 +390,14 @@ export default [ "shaders": [ { "name": "builtin-terrain|terrain-vs:vert|terrain-fs:frag", - "hash": 1557641563, + "hash": 29493851, "glsl3": { - "vert": `\n precision mediump float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\nuniform CCLocal {\n highp mat4 cc_matWorld;\n highp mat4 cc_matWorldIT;\n highp vec4 cc_lightingMapUVParam;\n};\nfloat LinearFog(vec4 pos) {\n vec4 wPos = pos;\n float cam_dis = distance(cc_cameraPos, wPos);\n float fogStart = cc_fogBase.x;\n float fogEnd = cc_fogBase.y;\n return clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float fogDensity = cc_fogBase.z;\n float cam_dis = distance(cc_cameraPos, wPos) / fogAtten * 4.;\n float f = exp(-cam_dis * fogDensity);\n return f;\n}\nfloat ExpSquaredFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float fogDensity = cc_fogBase.z;\n float cam_dis = distance(cc_cameraPos, wPos) / fogAtten * 4.;\n float f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\n return f;\n}\nfloat LayeredFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float _FogTop = cc_fogAdd.x;\n float _FogRange = cc_fogAdd.y;\n vec3 camWorldProj = cc_cameraPos.xyz;\n camWorldProj.y = 0.;\n vec3 worldPosProj = wPos.xyz;\n worldPosProj.y = 0.;\n float fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\n float fDeltaY, fDensityIntegral;\n if (cc_cameraPos.y > _FogTop) {\n if (wPos.y < _FogTop) {\n fDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\n fDensityIntegral = fDeltaY * fDeltaY * 0.5;\n } else {\n fDeltaY = 0.;\n fDensityIntegral = 0.;\n }\n } else {\n if (wPos.y < _FogTop) {\n float fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\n float fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\n fDeltaY = abs(fDeltaA - fDeltaB);\n fDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n } else {\n fDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\n fDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n }\n }\n float fDensity;\n if (fDeltaY != 0.) {\n fDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n } else {\n fDensity = 0.;\n }\n float f = exp(-fDensity);\n return f;\n}\nfloat CC_TRANSFER_FOG(vec4 pos) {\n #if CC_USE_FOG == 1\n return LinearFog(pos);\n #elif CC_USE_FOG == 2\n return ExpFog(pos);\n #elif CC_USE_FOG == 3\n return ExpSquaredFog(pos);\n #elif CC_USE_FOG == 4\n return LayeredFog(pos);\n #endif\n return 1.;\n}\n in vec3 a_position;\n in vec3 a_normal;\n in vec2 a_texCoord;\n out vec2 uvw;\n out vec2 uv0;\n out vec2 uv1;\n out vec2 uv2;\n out vec2 uv3;\n out vec2 luv;\n out vec3 diffuse;\n out float factor_fog;\n uniform TexCoords {\n vec4 UVScale;\n vec4 lightMapUVParam;\n };\n vec4 vert () {\n vec3 worldPos;\n worldPos.x = cc_matWorld[3][0] + a_position.x;\n worldPos.y = cc_matWorld[3][1] + a_position.y;\n worldPos.z = cc_matWorld[3][2] + a_position.z;\n vec4 pos = vec4(worldPos, 1);\n pos = cc_matViewProj * pos;\n uvw = a_texCoord;\n uv0 = a_position.xz * UVScale.x;\n uv1 = a_position.xz * UVScale.y;\n uv2 = a_position.xz * UVScale.z;\n uv3 = a_position.xz * UVScale.w;\n float fAmb = dot(a_normal, vec3(0.0, -1.0, 0.0)) * 0.5 + 0.5;\n vec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb) * cc_ambientSky.w;\n#if LIGHT_MAP == 0\n vec3 L = normalize(-cc_mainLitDir.xyz);\n vec3 N = a_normal;\n diffuse = ambDiff + vec3(dot(N, L)) * cc_mainLitColor.rgb;\n#else\n diffuse = ambDiff;\n luv = lightMapUVParam.xy + a_texCoord * lightMapUVParam.zw;\n#endif\n factor_fog = CC_TRANSFER_FOG(vec4(worldPos, 1));\n return pos;\n }\nvoid main() { gl_Position = vert(); }`, - "frag": `\nprecision mediump float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\n}\nvec4 CCFragOutput (vec4 color) {\n #if CC_USE_HDR\n color.rgb = mix(color.rgb, SRGBToLinear(color.rgb) * cc_exposure.w, vec3(cc_exposure.z));\n #endif\n return color;\n}\n in vec2 uvw;\n in vec2 uv0;\n in vec2 uv1;\n in vec2 uv2;\n in vec2 uv3;\n in vec3 diffuse;\n in vec2 luv;\n uniform sampler2D weightMap;\n uniform sampler2D detailMap0;\n uniform sampler2D detailMap1;\n uniform sampler2D detailMap2;\n uniform sampler2D detailMap3;\n uniform sampler2D lightMap;\n in float factor_fog;\nvec4 frag () {\n vec4 color = vec4(0, 0, 0, 0);\n #if LAYERS == 1\n color = texture(detailMap0, uv0);\n #elif LAYERS == 2\n vec4 w = texture(weightMap, uvw);\n color += texture(detailMap0, uv0) * w.r;\n color += texture(detailMap1, uv1) * w.g;\n #elif LAYERS == 3\n vec4 w = texture(weightMap, uvw);\n color += texture(detailMap0, uv0) * w.r;\n color += texture(detailMap1, uv1) * w.g;\n color += texture(detailMap2, uv2) * w.b;\n #elif LAYERS == 4\n vec4 w = texture(weightMap, uvw);\n color += texture(detailMap0, uv0) * w.r;\n color += texture(detailMap1, uv1) * w.g;\n color += texture(detailMap2, uv2) * w.b;\n color += texture(detailMap3, uv3) * w.a;\n #else\n color = texture(detailMap0, uv0);\n #endif\n vec3 lighting = diffuse;\n #if LIGHT_MAP == 1\n lighting += texture(lightMap, luv).rgb;\n #endif\n color.rgb *= lighting;\n color = mix(cc_fogColor, color, factor_fog);\n return CCFragOutput(color);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }` + "vert": `\n precision mediump float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n};\nuniform CCLocal {\n highp mat4 cc_matWorld;\n highp mat4 cc_matWorldIT;\n highp vec4 cc_lightingMapUVParam;\n};\n in vec3 a_position;\n in vec3 a_normal;\n in vec2 a_texCoord;\n out vec2 uvw;\n out vec2 uv0;\n out vec2 uv1;\n out vec2 uv2;\n out vec2 uv3;\n out vec2 luv;\n out vec3 diffuse;\n uniform TexCoords {\n vec4 UVScale;\n vec4 lightMapUVParam;\n };\n vec4 vert () {\n vec3 worldPos;\n worldPos.x = cc_matWorld[3][0] + a_position.x;\n worldPos.y = cc_matWorld[3][1] + a_position.y;\n worldPos.z = cc_matWorld[3][2] + a_position.z;\n vec4 pos = vec4(worldPos, 1);\n pos = cc_matViewProj * pos;\n uvw = a_texCoord;\n uv0 = a_position.xz * UVScale.x;\n uv1 = a_position.xz * UVScale.y;\n uv2 = a_position.xz * UVScale.z;\n uv3 = a_position.xz * UVScale.w;\n float fAmb = dot(a_normal, vec3(0.0, -1.0, 0.0)) * 0.5 + 0.5;\n vec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb) * cc_ambientSky.w;\n#if LIGHT_MAP == 0\n vec3 L = normalize(-cc_mainLitDir.xyz);\n vec3 N = a_normal;\n diffuse = ambDiff + vec3(dot(N, L)) * cc_mainLitColor.rgb;\n#else\n diffuse = ambDiff;\n luv = lightMapUVParam.xy + a_texCoord * lightMapUVParam.zw;\n#endif\n return pos;\n }\nvoid main() { gl_Position = vert(); }`, + "frag": `\nprecision mediump float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n};\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\n}\nvec4 CCFragOutput (vec4 color) {\n #if CC_USE_HDR\n color.rgb = mix(color.rgb, SRGBToLinear(color.rgb) * cc_exposure.w, vec3(cc_exposure.z));\n #endif\n return color;\n}\n in vec2 uvw;\n in vec2 uv0;\n in vec2 uv1;\n in vec2 uv2;\n in vec2 uv3;\n in vec3 diffuse;\n in vec2 luv;\n uniform sampler2D weightMap;\n uniform sampler2D detailMap0;\n uniform sampler2D detailMap1;\n uniform sampler2D detailMap2;\n uniform sampler2D detailMap3;\n uniform sampler2D lightMap;\nvec4 frag () {\n vec4 color = vec4(0, 0, 0, 0);\n #if LAYERS == 1\n color = texture(detailMap0, uv0);\n #elif LAYERS == 2\n vec4 w = texture(weightMap, uvw);\n color += texture(detailMap0, uv0) * w.r;\n color += texture(detailMap1, uv1) * w.g;\n #elif LAYERS == 3\n vec4 w = texture(weightMap, uvw);\n color += texture(detailMap0, uv0) * w.r;\n color += texture(detailMap1, uv1) * w.g;\n color += texture(detailMap2, uv2) * w.b;\n #elif LAYERS == 4\n vec4 w = texture(weightMap, uvw);\n color += texture(detailMap0, uv0) * w.r;\n color += texture(detailMap1, uv1) * w.g;\n color += texture(detailMap2, uv2) * w.b;\n color += texture(detailMap3, uv3) * w.a;\n #else\n color = texture(detailMap0, uv0);\n #endif\n vec3 lighting = diffuse;\n #if LIGHT_MAP == 1\n lighting += texture(lightMap, luv).rgb;\n #endif\n color.rgb *= lighting;\n return CCFragOutput(color);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }` }, "glsl1": { - "vert": `\n precision mediump float;\nuniform highp mat4 cc_matViewProj;\nuniform highp vec4 cc_cameraPos;\nuniform mediump vec4 cc_mainLitDir;\nuniform mediump vec4 cc_mainLitColor;\nuniform mediump vec4 cc_ambientSky;\nuniform mediump vec4 cc_ambientGround;\nuniform mediump vec4 cc_fogBase;\nuniform mediump vec4 cc_fogAdd;\nuniform highp mat4 cc_matWorld;\nfloat LinearFog(vec4 pos) {\n vec4 wPos = pos;\n float cam_dis = distance(cc_cameraPos, wPos);\n float fogStart = cc_fogBase.x;\n float fogEnd = cc_fogBase.y;\n return clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float fogDensity = cc_fogBase.z;\n float cam_dis = distance(cc_cameraPos, wPos) / fogAtten * 4.;\n float f = exp(-cam_dis * fogDensity);\n return f;\n}\nfloat ExpSquaredFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float fogDensity = cc_fogBase.z;\n float cam_dis = distance(cc_cameraPos, wPos) / fogAtten * 4.;\n float f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\n return f;\n}\nfloat LayeredFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float _FogTop = cc_fogAdd.x;\n float _FogRange = cc_fogAdd.y;\n vec3 camWorldProj = cc_cameraPos.xyz;\n camWorldProj.y = 0.;\n vec3 worldPosProj = wPos.xyz;\n worldPosProj.y = 0.;\n float fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\n float fDeltaY, fDensityIntegral;\n if (cc_cameraPos.y > _FogTop) {\n if (wPos.y < _FogTop) {\n fDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\n fDensityIntegral = fDeltaY * fDeltaY * 0.5;\n } else {\n fDeltaY = 0.;\n fDensityIntegral = 0.;\n }\n } else {\n if (wPos.y < _FogTop) {\n float fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\n float fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\n fDeltaY = abs(fDeltaA - fDeltaB);\n fDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n } else {\n fDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\n fDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n }\n }\n float fDensity;\n if (fDeltaY != 0.) {\n fDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n } else {\n fDensity = 0.;\n }\n float f = exp(-fDensity);\n return f;\n}\nfloat CC_TRANSFER_FOG(vec4 pos) {\n #if CC_USE_FOG == 1\n return LinearFog(pos);\n #elif CC_USE_FOG == 2\n return ExpFog(pos);\n #elif CC_USE_FOG == 3\n return ExpSquaredFog(pos);\n #elif CC_USE_FOG == 4\n return LayeredFog(pos);\n #endif\n return 1.;\n}\n attribute vec3 a_position;\n attribute vec3 a_normal;\n attribute vec2 a_texCoord;\n varying vec2 uvw;\n varying vec2 uv0;\n varying vec2 uv1;\n varying vec2 uv2;\n varying vec2 uv3;\n varying vec2 luv;\n varying vec3 diffuse;\n varying float factor_fog;\n uniform vec4 UVScale;\nuniform vec4 lightMapUVParam;\n vec4 vert () {\n vec3 worldPos;\n worldPos.x = cc_matWorld[3][0] + a_position.x;\n worldPos.y = cc_matWorld[3][1] + a_position.y;\n worldPos.z = cc_matWorld[3][2] + a_position.z;\n vec4 pos = vec4(worldPos, 1);\n pos = cc_matViewProj * pos;\n uvw = a_texCoord;\n uv0 = a_position.xz * UVScale.x;\n uv1 = a_position.xz * UVScale.y;\n uv2 = a_position.xz * UVScale.z;\n uv3 = a_position.xz * UVScale.w;\n float fAmb = dot(a_normal, vec3(0.0, -1.0, 0.0)) * 0.5 + 0.5;\n vec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb) * cc_ambientSky.w;\n#if LIGHT_MAP == 0\n vec3 L = normalize(-cc_mainLitDir.xyz);\n vec3 N = a_normal;\n diffuse = ambDiff + vec3(dot(N, L)) * cc_mainLitColor.rgb;\n#else\n diffuse = ambDiff;\n luv = lightMapUVParam.xy + a_texCoord * lightMapUVParam.zw;\n#endif\n factor_fog = CC_TRANSFER_FOG(vec4(worldPos, 1));\n return pos;\n }\nvoid main() { gl_Position = vert(); }`, - "frag": `\nprecision mediump float;\nuniform mediump vec4 cc_exposure;\nuniform mediump vec4 cc_fogColor;\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\n}\nvec4 CCFragOutput (vec4 color) {\n #if CC_USE_HDR\n color.rgb = mix(color.rgb, SRGBToLinear(color.rgb) * cc_exposure.w, vec3(cc_exposure.z));\n #endif\n return color;\n}\n varying vec2 uvw;\n varying vec2 uv0;\n varying vec2 uv1;\n varying vec2 uv2;\n varying vec2 uv3;\n varying vec3 diffuse;\n varying vec2 luv;\n uniform sampler2D weightMap;\n uniform sampler2D detailMap0;\n uniform sampler2D detailMap1;\n uniform sampler2D detailMap2;\n uniform sampler2D detailMap3;\n uniform sampler2D lightMap;\n varying float factor_fog;\nvec4 frag () {\n vec4 color = vec4(0, 0, 0, 0);\n #if LAYERS == 1\n color = texture2D(detailMap0, uv0);\n #elif LAYERS == 2\n vec4 w = texture2D(weightMap, uvw);\n color += texture2D(detailMap0, uv0) * w.r;\n color += texture2D(detailMap1, uv1) * w.g;\n #elif LAYERS == 3\n vec4 w = texture2D(weightMap, uvw);\n color += texture2D(detailMap0, uv0) * w.r;\n color += texture2D(detailMap1, uv1) * w.g;\n color += texture2D(detailMap2, uv2) * w.b;\n #elif LAYERS == 4\n vec4 w = texture2D(weightMap, uvw);\n color += texture2D(detailMap0, uv0) * w.r;\n color += texture2D(detailMap1, uv1) * w.g;\n color += texture2D(detailMap2, uv2) * w.b;\n color += texture2D(detailMap3, uv3) * w.a;\n #else\n color = texture2D(detailMap0, uv0);\n #endif\n vec3 lighting = diffuse;\n #if LIGHT_MAP == 1\n lighting += texture2D(lightMap, luv).rgb;\n #endif\n color.rgb *= lighting;\n color = mix(cc_fogColor, color, factor_fog);\n return CCFragOutput(color);\n}\nvoid main() { gl_FragColor = frag(); }` + "vert": `\n precision mediump float;\nuniform highp mat4 cc_matViewProj;\nuniform mediump vec4 cc_mainLitDir;\nuniform mediump vec4 cc_mainLitColor;\nuniform mediump vec4 cc_ambientSky;\nuniform mediump vec4 cc_ambientGround;\nuniform highp mat4 cc_matWorld;\n attribute vec3 a_position;\n attribute vec3 a_normal;\n attribute vec2 a_texCoord;\n varying vec2 uvw;\n varying vec2 uv0;\n varying vec2 uv1;\n varying vec2 uv2;\n varying vec2 uv3;\n varying vec2 luv;\n varying vec3 diffuse;\n uniform vec4 UVScale;\nuniform vec4 lightMapUVParam;\n vec4 vert () {\n vec3 worldPos;\n worldPos.x = cc_matWorld[3][0] + a_position.x;\n worldPos.y = cc_matWorld[3][1] + a_position.y;\n worldPos.z = cc_matWorld[3][2] + a_position.z;\n vec4 pos = vec4(worldPos, 1);\n pos = cc_matViewProj * pos;\n uvw = a_texCoord;\n uv0 = a_position.xz * UVScale.x;\n uv1 = a_position.xz * UVScale.y;\n uv2 = a_position.xz * UVScale.z;\n uv3 = a_position.xz * UVScale.w;\n float fAmb = dot(a_normal, vec3(0.0, -1.0, 0.0)) * 0.5 + 0.5;\n vec3 ambDiff = mix(cc_ambientSky.rgb, cc_ambientGround.rgb, fAmb) * cc_ambientSky.w;\n#if LIGHT_MAP == 0\n vec3 L = normalize(-cc_mainLitDir.xyz);\n vec3 N = a_normal;\n diffuse = ambDiff + vec3(dot(N, L)) * cc_mainLitColor.rgb;\n#else\n diffuse = ambDiff;\n luv = lightMapUVParam.xy + a_texCoord * lightMapUVParam.zw;\n#endif\n return pos;\n }\nvoid main() { gl_Position = vert(); }`, + "frag": `\nprecision mediump float;\nuniform mediump vec4 cc_exposure;\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\n}\nvec4 CCFragOutput (vec4 color) {\n #if CC_USE_HDR\n color.rgb = mix(color.rgb, SRGBToLinear(color.rgb) * cc_exposure.w, vec3(cc_exposure.z));\n #endif\n return color;\n}\n varying vec2 uvw;\n varying vec2 uv0;\n varying vec2 uv1;\n varying vec2 uv2;\n varying vec2 uv3;\n varying vec3 diffuse;\n varying vec2 luv;\n uniform sampler2D weightMap;\n uniform sampler2D detailMap0;\n uniform sampler2D detailMap1;\n uniform sampler2D detailMap2;\n uniform sampler2D detailMap3;\n uniform sampler2D lightMap;\nvec4 frag () {\n vec4 color = vec4(0, 0, 0, 0);\n #if LAYERS == 1\n color = texture2D(detailMap0, uv0);\n #elif LAYERS == 2\n vec4 w = texture2D(weightMap, uvw);\n color += texture2D(detailMap0, uv0) * w.r;\n color += texture2D(detailMap1, uv1) * w.g;\n #elif LAYERS == 3\n vec4 w = texture2D(weightMap, uvw);\n color += texture2D(detailMap0, uv0) * w.r;\n color += texture2D(detailMap1, uv1) * w.g;\n color += texture2D(detailMap2, uv2) * w.b;\n #elif LAYERS == 4\n vec4 w = texture2D(weightMap, uvw);\n color += texture2D(detailMap0, uv0) * w.r;\n color += texture2D(detailMap1, uv1) * w.g;\n color += texture2D(detailMap2, uv2) * w.b;\n color += texture2D(detailMap3, uv3) * w.a;\n #else\n color = texture2D(detailMap0, uv0);\n #endif\n vec3 lighting = diffuse;\n #if LIGHT_MAP == 1\n lighting += texture2D(lightMap, luv).rgb;\n #endif\n color.rgb *= lighting;\n return CCFragOutput(color);\n}\nvoid main() { gl_FragColor = frag(); }` }, "builtins": { "globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }], "samplers": [] }, @@ -442,38 +439,37 @@ export default [ "shaders": [ { "name": "builtin-unlit|unlit-vs:vert|unlit-fs:frag", - "hash": 211923169, + "hash": 3753129449, "glsl3": { - "vert": `\nprecision highp float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\n#if USE_INSTANCING\n in vec4 a_matWorld0;\n in vec4 a_matWorld1;\n in vec4 a_matWorld2;\n#elif USE_BATCHING\n in float a_dyn_batch_id;\n uniform CCLocalBatched {\n highp mat4 cc_matWorlds[10];\n };\n#else\nuniform CCLocal {\n highp mat4 cc_matWorld;\n highp mat4 cc_matWorldIT;\n highp vec4 cc_lightingMapUVParam;\n};\n#endif\nstruct StandardVertInput {\n highp vec4 position;\n vec3 normal;\n vec4 tangent;\n};\nin vec3 a_position;\n#if CC_USE_MORPH\n in float a_vertexId;\n int getVertexId() {\n return int(a_vertexId);\n }\nuniform CCMorph {\n vec4 cc_displacementWeights[15];\n vec4 cc_displacementTextureInfo;\n};\n vec4 fetchFlatPixel(sampler2D tex, int pixelIndex) {\n float pixelIndexF = float(pixelIndex);\n vec2 textureResolution = vec2(float(cc_displacementTextureInfo.x), float(cc_displacementTextureInfo.y));\n float pixelX = mod(pixelIndexF, textureResolution.x);\n float pixelY = floor(pixelIndexF / textureResolution.x);\n vec2 uv = (vec2(pixelX, pixelY) + .5) / textureResolution;\n return texture(tex, uv);\n }\nfloat getDisplacementWeight(int index) {\n float m = mod(float(index), 4.0);\n if (m < 1.0) {\n return cc_displacementWeights[index / 4].x;\n } else if (m < 2.0) {\n return cc_displacementWeights[index / 4].y;\n } else if (m < 3.0) {\n return cc_displacementWeights[index / 4].z;\n } else {\n return cc_displacementWeights[index / 4].w;\n }\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\n return fetchFlatPixel(tex, vertexIndex).rgb;\n#else\n vec3 result = vec3(0, 0, 0);\n for (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\n int dataPixelStart = int(fetchFlatPixel(tex, iTarget).r);\n result += (fetchFlatPixel(tex, dataPixelStart + vertexIndex).rgb * getDisplacementWeight(iTarget));\n }\n return result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\n uniform sampler2D cc_PositionDisplacements;\n vec3 getPositionDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n uniform sampler2D cc_NormalDisplacements;\n vec3 getNormalDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n uniform sampler2D cc_TangentDisplacements;\n vec3 getTangentDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n }\n#endif\nvoid applyMorph (inout StandardVertInput attr) {\n int vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\n attr.position.xyz = attr.position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n attr.normal.xyz = attr.normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n attr.tangent.xyz = attr.tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\n position.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\nin vec4 a_weights;\nin vec4 a_joints;\n#if CC_USE_BAKED_ANIMATION\n #if USE_INSTANCING\n in vec4 a_jointAnimInfo;\n #endif\n uniform CCSkinningTexture {\n highp vec4 cc_jointTextureInfo;\n };\n uniform CCSkinningAnimation {\n highp vec4 cc_jointAnimInfo;\n };\n uniform sampler2D cc_jointTexture;\n #if !CC_SUPPORT_FLOAT_TEXTURE\n highp float decode32 (highp vec4 rgba) {\n rgba = rgba * 255.0;\n highp float Sign = 1.0 - step(128.0, rgba[3]) * 2.0;\n highp float Exponent = 2.0 * mod(rgba[3], 128.0) + step(128.0, rgba[2]) - 127.0;\n highp float Mantissa = mod(rgba[2], 128.0) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\n }\n #endif\n#else\n uniform CCSkinning {\n highp vec4 cc_joints[30 * 3];\n };\n#endif\n#if CC_USE_BAKED_ANIMATION\n #if CC_SUPPORT_FLOAT_TEXTURE\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 3.0 * i + a_jointAnimInfo.x;\n #else\n highp float j = 3.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = texture(cc_jointTexture, vec2((x + 0.5) * invSize, y));\n vec4 v2 = texture(cc_jointTexture, vec2((x + 1.5) * invSize, y));\n vec4 v3 = texture(cc_jointTexture, vec2((x + 2.5) * invSize, y));\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #else\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 12.0 * i + a_jointAnimInfo.x;\n #else\n highp float j = 12.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = vec4(\n decode32(texture(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n );\n vec4 v2 = vec4(\n decode32(texture(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n );\n vec4 v3 = vec4(\n decode32(texture(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n );\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #endif\n#else\n mat4 getJointMatrix (float i) {\n int idx = int(i);\n vec4 v1 = cc_joints[idx * 3];\n vec4 v2 = cc_joints[idx * 3 + 1];\n vec4 v3 = cc_joints[idx * 3 + 2];\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n#endif\nmat4 skinMatrix () {\n return getJointMatrix(a_joints.x) * a_weights.x\n + getJointMatrix(a_joints.y) * a_weights.y;\n + getJointMatrix(a_joints.z) * a_weights.z;\n + getJointMatrix(a_joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\n mat4 m = skinMatrix();\n position = m * position;\n}\nvoid CCSkin (inout StandardVertInput attr) {\n mat4 m = skinMatrix();\n attr.position = m * attr.position;\n attr.normal = (m * vec4(attr.normal, 0.0)).xyz;\n attr.tangent.xyz = (m * vec4(attr.tangent.xyz, 0.0)).xyz;\n}\n#endif\nfloat LinearFog(vec4 pos) {\n vec4 wPos = pos;\n float cam_dis = distance(cc_cameraPos, wPos);\n float fogStart = cc_fogBase.x;\n float fogEnd = cc_fogBase.y;\n return clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float fogDensity = cc_fogBase.z;\n float cam_dis = distance(cc_cameraPos, wPos) / fogAtten * 4.;\n float f = exp(-cam_dis * fogDensity);\n return f;\n}\nfloat ExpSquaredFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float fogDensity = cc_fogBase.z;\n float cam_dis = distance(cc_cameraPos, wPos) / fogAtten * 4.;\n float f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\n return f;\n}\nfloat LayeredFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float _FogTop = cc_fogAdd.x;\n float _FogRange = cc_fogAdd.y;\n vec3 camWorldProj = cc_cameraPos.xyz;\n camWorldProj.y = 0.;\n vec3 worldPosProj = wPos.xyz;\n worldPosProj.y = 0.;\n float fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\n float fDeltaY, fDensityIntegral;\n if (cc_cameraPos.y > _FogTop) {\n if (wPos.y < _FogTop) {\n fDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\n fDensityIntegral = fDeltaY * fDeltaY * 0.5;\n } else {\n fDeltaY = 0.;\n fDensityIntegral = 0.;\n }\n } else {\n if (wPos.y < _FogTop) {\n float fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\n float fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\n fDeltaY = abs(fDeltaA - fDeltaB);\n fDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n } else {\n fDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\n fDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n }\n }\n float fDensity;\n if (fDeltaY != 0.) {\n fDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n } else {\n fDensity = 0.;\n }\n float f = exp(-fDensity);\n return f;\n}\nfloat CC_TRANSFER_FOG(vec4 pos) {\n #if CC_USE_FOG == 1\n return LinearFog(pos);\n #elif CC_USE_FOG == 2\n return ExpFog(pos);\n #elif CC_USE_FOG == 3\n return ExpSquaredFog(pos);\n #elif CC_USE_FOG == 4\n return LayeredFog(pos);\n #endif\n return 1.;\n}\n#if USE_VERTEX_COLOR\n in vec4 a_color;\n out vec4 v_color;\n#endif\n#if USE_TEXTURE\n in vec2 a_texCoord;\n out vec2 v_uv;\n uniform TexCoords {\n vec4 tilingOffset;\n };\n#endif\nout float factor_fog;\nvec4 vert () {\n vec4 position;\n position = vec4(a_position, 1.0);\n #if CC_USE_MORPH\n applyMorph(position);\n #endif\n #if CC_USE_SKINNING\n CCSkin(position);\n #endif\n mat4 matWorld;\n #if USE_INSTANCING\n matWorld = mat4(\n vec4(a_matWorld0.xyz, 0.0),\n vec4(a_matWorld1.xyz, 0.0),\n vec4(a_matWorld2.xyz, 0.0),\n vec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)\n );\n #elif USE_BATCHING\n matWorld = cc_matWorlds[int(a_dyn_batch_id)];\n #else\n matWorld = cc_matWorld;\n #endif\n #if USE_TEXTURE\n v_uv = a_texCoord;\n #if FLIP_UV\n v_uv.y = 1.0 - v_uv.y;\n #endif\n v_uv = v_uv * tilingOffset.xy + tilingOffset.zw;\n #endif\n #if USE_VERTEX_COLOR\n v_color = a_color;\n #endif\n factor_fog = CC_TRANSFER_FOG(matWorld * position);\n return cc_matProj * (cc_matView * matWorld) * position;\n}\nvoid main() { gl_Position = vert(); }`, - "frag": `\nprecision mediump float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\n}\nvec4 CCFragOutput (vec4 color) {\n #if CC_USE_HDR\n color.rgb = mix(color.rgb, SRGBToLinear(color.rgb) * cc_exposure.w, vec3(cc_exposure.z));\n #endif\n return color;\n}\n#if USE_ALPHA_TEST\n#endif\n#if USE_TEXTURE\n in vec2 v_uv;\n uniform sampler2D mainTexture;\n#endif\nuniform Constant {\n vec4 mainColor;\n vec4 colorScaleAndCutoff;\n};\n#if USE_VERTEX_COLOR\n in vec4 v_color;\n#endif\nin float factor_fog;\nvec4 frag () {\n vec4 o = mainColor;\n o.rgb *= colorScaleAndCutoff.xyz;\n #if USE_VERTEX_COLOR\n o *= v_color;\n #endif\n #if USE_TEXTURE\n o *= texture(mainTexture, v_uv);\n #endif\n #if USE_ALPHA_TEST\n if (o.ALPHA_TEST_CHANNEL < colorScaleAndCutoff.w) discard;\n #endif\n o = mix(cc_fogColor, o, factor_fog);\n return CCFragOutput(o);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }` + "vert": `\nprecision highp float;\nstruct StandardVertInput {\n highp vec4 position;\n vec3 normal;\n vec4 tangent;\n};\nin vec3 a_position;\n#if CC_USE_MORPH\n in float a_vertexId;\n int getVertexId() {\n return int(a_vertexId);\n }\nuniform CCMorph {\n vec4 cc_displacementWeights[15];\n vec4 cc_displacementTextureInfo;\n};\n vec4 fetchFlatPixel(sampler2D tex, int pixelIndex) {\n float pixelIndexF = float(pixelIndex);\n vec2 textureResolution = vec2(float(cc_displacementTextureInfo.x), float(cc_displacementTextureInfo.y));\n float pixelX = mod(pixelIndexF, textureResolution.x);\n float pixelY = floor(pixelIndexF / textureResolution.x);\n vec2 uv = (vec2(pixelX, pixelY) + .5) / textureResolution;\n return texture(tex, uv);\n }\nfloat getDisplacementWeight(int index) {\n float m = mod(float(index), 4.0);\n if (m < 1.0) {\n return cc_displacementWeights[index / 4].x;\n } else if (m < 2.0) {\n return cc_displacementWeights[index / 4].y;\n } else if (m < 3.0) {\n return cc_displacementWeights[index / 4].z;\n } else {\n return cc_displacementWeights[index / 4].w;\n }\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\n return fetchFlatPixel(tex, vertexIndex).rgb;\n#else\n vec3 result = vec3(0, 0, 0);\n for (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\n int dataPixelStart = int(fetchFlatPixel(tex, iTarget).r);\n result += (fetchFlatPixel(tex, dataPixelStart + vertexIndex).rgb * getDisplacementWeight(iTarget));\n }\n return result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\n uniform sampler2D cc_PositionDisplacements;\n vec3 getPositionDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n uniform sampler2D cc_NormalDisplacements;\n vec3 getNormalDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n uniform sampler2D cc_TangentDisplacements;\n vec3 getTangentDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n }\n#endif\nvoid applyMorph (inout StandardVertInput attr) {\n int vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\n attr.position.xyz = attr.position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n attr.normal.xyz = attr.normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n attr.tangent.xyz = attr.tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\n position.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\nin vec4 a_weights;\nin vec4 a_joints;\n#if CC_USE_BAKED_ANIMATION\n #if USE_INSTANCING\n in highp vec4 a_jointAnimInfo;\n #endif\n uniform CCSkinningTexture {\n highp vec4 cc_jointTextureInfo;\n };\n uniform CCSkinningAnimation {\n highp vec4 cc_jointAnimInfo;\n };\n uniform sampler2D cc_jointTexture;\n #if !CC_SUPPORT_FLOAT_TEXTURE\n highp float decode32 (highp vec4 rgba) {\n rgba = rgba * 255.0;\n highp float Sign = 1.0 - step(128.0, rgba[3]) * 2.0;\n highp float Exponent = 2.0 * mod(rgba[3], 128.0) + step(128.0, rgba[2]) - 127.0;\n highp float Mantissa = mod(rgba[2], 128.0) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\n }\n #endif\n#else\n uniform CCSkinning {\n highp vec4 cc_joints[30 * 3];\n };\n#endif\n#if CC_USE_BAKED_ANIMATION\n #if CC_SUPPORT_FLOAT_TEXTURE\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 3.0 * (a_jointAnimInfo.x * a_jointAnimInfo.y + i) + a_jointAnimInfo.z;\n #else\n highp float j = 3.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = texture(cc_jointTexture, vec2((x + 0.5) * invSize, y));\n vec4 v2 = texture(cc_jointTexture, vec2((x + 1.5) * invSize, y));\n vec4 v3 = texture(cc_jointTexture, vec2((x + 2.5) * invSize, y));\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #else\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 12.0 * (a_jointAnimInfo.x * a_jointAnimInfo.y + i) + a_jointAnimInfo.z;\n #else\n highp float j = 12.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = vec4(\n decode32(texture(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n );\n vec4 v2 = vec4(\n decode32(texture(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n );\n vec4 v3 = vec4(\n decode32(texture(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n );\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #endif\n#else\n mat4 getJointMatrix (float i) {\n int idx = int(i);\n vec4 v1 = cc_joints[idx * 3];\n vec4 v2 = cc_joints[idx * 3 + 1];\n vec4 v3 = cc_joints[idx * 3 + 2];\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n#endif\nmat4 skinMatrix () {\n return getJointMatrix(a_joints.x) * a_weights.x\n + getJointMatrix(a_joints.y) * a_weights.y;\n + getJointMatrix(a_joints.z) * a_weights.z;\n + getJointMatrix(a_joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\n mat4 m = skinMatrix();\n position = m * position;\n}\nvoid CCSkin (inout StandardVertInput attr) {\n mat4 m = skinMatrix();\n attr.position = m * attr.position;\n attr.normal = (m * vec4(attr.normal, 0.0)).xyz;\n attr.tangent.xyz = (m * vec4(attr.tangent.xyz, 0.0)).xyz;\n}\n#endif\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n};\n#if USE_INSTANCING\n in vec4 a_matWorld0;\n in vec4 a_matWorld1;\n in vec4 a_matWorld2;\n#elif USE_BATCHING\n in float a_dyn_batch_id;\n uniform CCLocalBatched {\n highp mat4 cc_matWorlds[10];\n };\n#else\nuniform CCLocal {\n highp mat4 cc_matWorld;\n highp mat4 cc_matWorldIT;\n highp vec4 cc_lightingMapUVParam;\n};\n#endif\n#if USE_VERTEX_COLOR\n in vec4 a_color;\n out vec4 v_color;\n#endif\n#if USE_TEXTURE\n in vec2 a_texCoord;\n out vec2 v_uv;\n uniform TexCoords {\n vec4 tilingOffset;\n };\n#endif\nvec4 vert () {\n vec4 position;\n position = vec4(a_position, 1.0);\n #if CC_USE_MORPH\n applyMorph(position);\n #endif\n #if CC_USE_SKINNING\n CCSkin(position);\n #endif\n mat4 matWorld;\n #if USE_INSTANCING\n matWorld = mat4(\n vec4(a_matWorld0.xyz, 0.0),\n vec4(a_matWorld1.xyz, 0.0),\n vec4(a_matWorld2.xyz, 0.0),\n vec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)\n );\n #elif USE_BATCHING\n matWorld = cc_matWorlds[int(a_dyn_batch_id)];\n #else\n matWorld = cc_matWorld;\n #endif\n #if USE_TEXTURE\n v_uv = a_texCoord;\n #if FLIP_UV\n v_uv.y = 1.0 - v_uv.y;\n #endif\n v_uv = v_uv * tilingOffset.xy + tilingOffset.zw;\n #endif\n #if USE_VERTEX_COLOR\n v_color = a_color;\n #endif\n return cc_matProj * (cc_matView * matWorld) * position;\n}\nvoid main() { gl_Position = vert(); }`, + "frag": `\nprecision mediump float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n};\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\n}\nvec4 CCFragOutput (vec4 color) {\n #if CC_USE_HDR\n color.rgb = mix(color.rgb, SRGBToLinear(color.rgb) * cc_exposure.w, vec3(cc_exposure.z));\n #endif\n return color;\n}\n#if USE_ALPHA_TEST\n#endif\n#if USE_TEXTURE\n in vec2 v_uv;\n uniform sampler2D mainTexture;\n#endif\nuniform Constant {\n vec4 mainColor;\n vec4 colorScaleAndCutoff;\n};\n#if USE_VERTEX_COLOR\n in vec4 v_color;\n#endif\nvec4 frag () {\n vec4 o = mainColor;\n o.rgb *= colorScaleAndCutoff.xyz;\n #if USE_VERTEX_COLOR\n o *= v_color;\n #endif\n #if USE_TEXTURE\n o *= texture(mainTexture, v_uv);\n #endif\n #if USE_ALPHA_TEST\n if (o.ALPHA_TEST_CHANNEL < colorScaleAndCutoff.w) discard;\n #endif\n return CCFragOutput(o);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }` }, "glsl1": { - "vert": `\nprecision highp float;\nuniform highp mat4 cc_matView;\nuniform highp mat4 cc_matProj;\nuniform highp vec4 cc_cameraPos;\nuniform mediump vec4 cc_fogBase;\nuniform mediump vec4 cc_fogAdd;\n#if USE_INSTANCING\n attribute vec4 a_matWorld0;\n attribute vec4 a_matWorld1;\n attribute vec4 a_matWorld2;\n#elif USE_BATCHING\n attribute float a_dyn_batch_id;\n uniform highp mat4 cc_matWorlds[10];\n#else\nuniform highp mat4 cc_matWorld;\n#endif\nstruct StandardVertInput {\n highp vec4 position;\n vec3 normal;\n vec4 tangent;\n};\nattribute vec3 a_position;\n#if CC_USE_MORPH\n attribute float a_vertexId;\n int getVertexId() {\n return int(a_vertexId);\n }\nuniform vec4 cc_displacementWeights[15];\nuniform vec4 cc_displacementTextureInfo;\n vec4 fetchFlatPixel(sampler2D tex, int pixelIndex) {\n float pixelIndexF = float(pixelIndex);\n vec2 textureResolution = vec2(float(cc_displacementTextureInfo.x), float(cc_displacementTextureInfo.y));\n float pixelX = mod(pixelIndexF, textureResolution.x);\n float pixelY = floor(pixelIndexF / textureResolution.x);\n vec2 uv = (vec2(pixelX, pixelY) + .5) / textureResolution;\n return texture2D(tex, uv);\n }\nfloat getDisplacementWeight(int index) {\n float m = mod(float(index), 4.0);\n if (m < 1.0) {\n return cc_displacementWeights[index / 4].x;\n } else if (m < 2.0) {\n return cc_displacementWeights[index / 4].y;\n } else if (m < 3.0) {\n return cc_displacementWeights[index / 4].z;\n } else {\n return cc_displacementWeights[index / 4].w;\n }\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\n return fetchFlatPixel(tex, vertexIndex).rgb;\n#else\n vec3 result = vec3(0, 0, 0);\n for (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\n int dataPixelStart = int(fetchFlatPixel(tex, iTarget).r);\n result += (fetchFlatPixel(tex, dataPixelStart + vertexIndex).rgb * getDisplacementWeight(iTarget));\n }\n return result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\n uniform sampler2D cc_PositionDisplacements;\n vec3 getPositionDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n uniform sampler2D cc_NormalDisplacements;\n vec3 getNormalDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n uniform sampler2D cc_TangentDisplacements;\n vec3 getTangentDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n }\n#endif\nvoid applyMorph (inout StandardVertInput attr) {\n int vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\n attr.position.xyz = attr.position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n attr.normal.xyz = attr.normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n attr.tangent.xyz = attr.tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\n position.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\nattribute vec4 a_weights;\nattribute vec4 a_joints;\n#if CC_USE_BAKED_ANIMATION\n #if USE_INSTANCING\n attribute vec4 a_jointAnimInfo;\n #endif\n uniform highp vec4 cc_jointTextureInfo;\n uniform highp vec4 cc_jointAnimInfo;\n uniform sampler2D cc_jointTexture;\n #if !CC_SUPPORT_FLOAT_TEXTURE\n highp float decode32 (highp vec4 rgba) {\n rgba = rgba * 255.0;\n highp float Sign = 1.0 - step(128.0, rgba[3]) * 2.0;\n highp float Exponent = 2.0 * mod(rgba[3], 128.0) + step(128.0, rgba[2]) - 127.0;\n highp float Mantissa = mod(rgba[2], 128.0) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\n }\n #endif\n#else\n uniform highp vec4 cc_joints[90];\n#endif\n#if CC_USE_BAKED_ANIMATION\n #if CC_SUPPORT_FLOAT_TEXTURE\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 3.0 * i + a_jointAnimInfo.x;\n #else\n highp float j = 3.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y));\n vec4 v2 = texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y));\n vec4 v3 = texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y));\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #else\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 12.0 * i + a_jointAnimInfo.x;\n #else\n highp float j = 12.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = vec4(\n decode32(texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n );\n vec4 v2 = vec4(\n decode32(texture2D(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n );\n vec4 v3 = vec4(\n decode32(texture2D(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n );\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #endif\n#else\n mat4 getJointMatrix (float i) {\n int idx = int(i);\n vec4 v1 = cc_joints[idx * 3];\n vec4 v2 = cc_joints[idx * 3 + 1];\n vec4 v3 = cc_joints[idx * 3 + 2];\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n#endif\nmat4 skinMatrix () {\n return getJointMatrix(a_joints.x) * a_weights.x\n + getJointMatrix(a_joints.y) * a_weights.y;\n + getJointMatrix(a_joints.z) * a_weights.z;\n + getJointMatrix(a_joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\n mat4 m = skinMatrix();\n position = m * position;\n}\nvoid CCSkin (inout StandardVertInput attr) {\n mat4 m = skinMatrix();\n attr.position = m * attr.position;\n attr.normal = (m * vec4(attr.normal, 0.0)).xyz;\n attr.tangent.xyz = (m * vec4(attr.tangent.xyz, 0.0)).xyz;\n}\n#endif\nfloat LinearFog(vec4 pos) {\n vec4 wPos = pos;\n float cam_dis = distance(cc_cameraPos, wPos);\n float fogStart = cc_fogBase.x;\n float fogEnd = cc_fogBase.y;\n return clamp((fogEnd - cam_dis) / (fogEnd - fogStart), 0., 1.);\n}\nfloat ExpFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float fogDensity = cc_fogBase.z;\n float cam_dis = distance(cc_cameraPos, wPos) / fogAtten * 4.;\n float f = exp(-cam_dis * fogDensity);\n return f;\n}\nfloat ExpSquaredFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float fogDensity = cc_fogBase.z;\n float cam_dis = distance(cc_cameraPos, wPos) / fogAtten * 4.;\n float f = exp(-cam_dis * cam_dis * fogDensity * fogDensity);\n return f;\n}\nfloat LayeredFog(vec4 pos) {\n vec4 wPos = pos;\n float fogAtten = cc_fogAdd.z;\n float _FogTop = cc_fogAdd.x;\n float _FogRange = cc_fogAdd.y;\n vec3 camWorldProj = cc_cameraPos.xyz;\n camWorldProj.y = 0.;\n vec3 worldPosProj = wPos.xyz;\n worldPosProj.y = 0.;\n float fDeltaD = distance(worldPosProj, camWorldProj) / fogAtten * 2.0;\n float fDeltaY, fDensityIntegral;\n if (cc_cameraPos.y > _FogTop) {\n if (wPos.y < _FogTop) {\n fDeltaY = (_FogTop - wPos.y) / _FogRange * 2.0;\n fDensityIntegral = fDeltaY * fDeltaY * 0.5;\n } else {\n fDeltaY = 0.;\n fDensityIntegral = 0.;\n }\n } else {\n if (wPos.y < _FogTop) {\n float fDeltaA = (_FogTop - cc_cameraPos.y) / _FogRange * 2.;\n float fDeltaB = (_FogTop - wPos.y) / _FogRange * 2.;\n fDeltaY = abs(fDeltaA - fDeltaB);\n fDensityIntegral = abs((fDeltaA * fDeltaA * 0.5) - (fDeltaB * fDeltaB * 0.5));\n } else {\n fDeltaY = abs(_FogTop - cc_cameraPos.y) / _FogRange * 2.;\n fDensityIntegral = abs(fDeltaY * fDeltaY * 0.5);\n }\n }\n float fDensity;\n if (fDeltaY != 0.) {\n fDensity = (sqrt(1.0 + ((fDeltaD / fDeltaY) * (fDeltaD / fDeltaY)))) * fDensityIntegral;\n } else {\n fDensity = 0.;\n }\n float f = exp(-fDensity);\n return f;\n}\nfloat CC_TRANSFER_FOG(vec4 pos) {\n #if CC_USE_FOG == 1\n return LinearFog(pos);\n #elif CC_USE_FOG == 2\n return ExpFog(pos);\n #elif CC_USE_FOG == 3\n return ExpSquaredFog(pos);\n #elif CC_USE_FOG == 4\n return LayeredFog(pos);\n #endif\n return 1.;\n}\n#if USE_VERTEX_COLOR\n attribute vec4 a_color;\n varying vec4 v_color;\n#endif\n#if USE_TEXTURE\n attribute vec2 a_texCoord;\n varying vec2 v_uv;\n uniform vec4 tilingOffset;\n#endif\nvarying float factor_fog;\nvec4 vert () {\n vec4 position;\n position = vec4(a_position, 1.0);\n #if CC_USE_MORPH\n applyMorph(position);\n #endif\n #if CC_USE_SKINNING\n CCSkin(position);\n #endif\n mat4 matWorld;\n #if USE_INSTANCING\n matWorld = mat4(\n vec4(a_matWorld0.xyz, 0.0),\n vec4(a_matWorld1.xyz, 0.0),\n vec4(a_matWorld2.xyz, 0.0),\n vec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)\n );\n #elif USE_BATCHING\n matWorld = cc_matWorlds[int(a_dyn_batch_id)];\n #else\n matWorld = cc_matWorld;\n #endif\n #if USE_TEXTURE\n v_uv = a_texCoord;\n #if FLIP_UV\n v_uv.y = 1.0 - v_uv.y;\n #endif\n v_uv = v_uv * tilingOffset.xy + tilingOffset.zw;\n #endif\n #if USE_VERTEX_COLOR\n v_color = a_color;\n #endif\n factor_fog = CC_TRANSFER_FOG(matWorld * position);\n return cc_matProj * (cc_matView * matWorld) * position;\n}\nvoid main() { gl_Position = vert(); }`, - "frag": `\nprecision mediump float;\nuniform mediump vec4 cc_exposure;\nuniform mediump vec4 cc_fogColor;\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\n}\nvec4 CCFragOutput (vec4 color) {\n #if CC_USE_HDR\n color.rgb = mix(color.rgb, SRGBToLinear(color.rgb) * cc_exposure.w, vec3(cc_exposure.z));\n #endif\n return color;\n}\n#if USE_ALPHA_TEST\n#endif\n#if USE_TEXTURE\n varying vec2 v_uv;\n uniform sampler2D mainTexture;\n#endif\nuniform vec4 mainColor;\nuniform vec4 colorScaleAndCutoff;\n#if USE_VERTEX_COLOR\n varying vec4 v_color;\n#endif\nvarying float factor_fog;\nvec4 frag () {\n vec4 o = mainColor;\n o.rgb *= colorScaleAndCutoff.xyz;\n #if USE_VERTEX_COLOR\n o *= v_color;\n #endif\n #if USE_TEXTURE\n o *= texture2D(mainTexture, v_uv);\n #endif\n #if USE_ALPHA_TEST\n if (o.ALPHA_TEST_CHANNEL < colorScaleAndCutoff.w) discard;\n #endif\n o = mix(cc_fogColor, o, factor_fog);\n return CCFragOutput(o);\n}\nvoid main() { gl_FragColor = frag(); }` + "vert": `\nprecision highp float;\nstruct StandardVertInput {\n highp vec4 position;\n vec3 normal;\n vec4 tangent;\n};\nattribute vec3 a_position;\n#if CC_USE_MORPH\n attribute float a_vertexId;\n int getVertexId() {\n return int(a_vertexId);\n }\nuniform vec4 cc_displacementWeights[15];\nuniform vec4 cc_displacementTextureInfo;\n vec4 fetchFlatPixel(sampler2D tex, int pixelIndex) {\n float pixelIndexF = float(pixelIndex);\n vec2 textureResolution = vec2(float(cc_displacementTextureInfo.x), float(cc_displacementTextureInfo.y));\n float pixelX = mod(pixelIndexF, textureResolution.x);\n float pixelY = floor(pixelIndexF / textureResolution.x);\n vec2 uv = (vec2(pixelX, pixelY) + .5) / textureResolution;\n return texture2D(tex, uv);\n }\nfloat getDisplacementWeight(int index) {\n float m = mod(float(index), 4.0);\n if (m < 1.0) {\n return cc_displacementWeights[index / 4].x;\n } else if (m < 2.0) {\n return cc_displacementWeights[index / 4].y;\n } else if (m < 3.0) {\n return cc_displacementWeights[index / 4].z;\n } else {\n return cc_displacementWeights[index / 4].w;\n }\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\n return fetchFlatPixel(tex, vertexIndex).rgb;\n#else\n vec3 result = vec3(0, 0, 0);\n for (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\n int dataPixelStart = int(fetchFlatPixel(tex, iTarget).r);\n result += (fetchFlatPixel(tex, dataPixelStart + vertexIndex).rgb * getDisplacementWeight(iTarget));\n }\n return result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\n uniform sampler2D cc_PositionDisplacements;\n vec3 getPositionDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n uniform sampler2D cc_NormalDisplacements;\n vec3 getNormalDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n uniform sampler2D cc_TangentDisplacements;\n vec3 getTangentDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n }\n#endif\nvoid applyMorph (inout StandardVertInput attr) {\n int vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\n attr.position.xyz = attr.position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n attr.normal.xyz = attr.normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n attr.tangent.xyz = attr.tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\n position.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\nattribute vec4 a_weights;\nattribute vec4 a_joints;\n#if CC_USE_BAKED_ANIMATION\n #if USE_INSTANCING\n attribute highp vec4 a_jointAnimInfo;\n #endif\n uniform highp vec4 cc_jointTextureInfo;\n uniform highp vec4 cc_jointAnimInfo;\n uniform sampler2D cc_jointTexture;\n #if !CC_SUPPORT_FLOAT_TEXTURE\n highp float decode32 (highp vec4 rgba) {\n rgba = rgba * 255.0;\n highp float Sign = 1.0 - step(128.0, rgba[3]) * 2.0;\n highp float Exponent = 2.0 * mod(rgba[3], 128.0) + step(128.0, rgba[2]) - 127.0;\n highp float Mantissa = mod(rgba[2], 128.0) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\n }\n #endif\n#else\n uniform highp vec4 cc_joints[90];\n#endif\n#if CC_USE_BAKED_ANIMATION\n #if CC_SUPPORT_FLOAT_TEXTURE\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 3.0 * (a_jointAnimInfo.x * a_jointAnimInfo.y + i) + a_jointAnimInfo.z;\n #else\n highp float j = 3.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y));\n vec4 v2 = texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y));\n vec4 v3 = texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y));\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #else\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 12.0 * (a_jointAnimInfo.x * a_jointAnimInfo.y + i) + a_jointAnimInfo.z;\n #else\n highp float j = 12.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = vec4(\n decode32(texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n );\n vec4 v2 = vec4(\n decode32(texture2D(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n );\n vec4 v3 = vec4(\n decode32(texture2D(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n );\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #endif\n#else\n mat4 getJointMatrix (float i) {\n int idx = int(i);\n vec4 v1 = cc_joints[idx * 3];\n vec4 v2 = cc_joints[idx * 3 + 1];\n vec4 v3 = cc_joints[idx * 3 + 2];\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n#endif\nmat4 skinMatrix () {\n return getJointMatrix(a_joints.x) * a_weights.x\n + getJointMatrix(a_joints.y) * a_weights.y;\n + getJointMatrix(a_joints.z) * a_weights.z;\n + getJointMatrix(a_joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\n mat4 m = skinMatrix();\n position = m * position;\n}\nvoid CCSkin (inout StandardVertInput attr) {\n mat4 m = skinMatrix();\n attr.position = m * attr.position;\n attr.normal = (m * vec4(attr.normal, 0.0)).xyz;\n attr.tangent.xyz = (m * vec4(attr.tangent.xyz, 0.0)).xyz;\n}\n#endif\nuniform highp mat4 cc_matView;\nuniform highp mat4 cc_matProj;\n#if USE_INSTANCING\n attribute vec4 a_matWorld0;\n attribute vec4 a_matWorld1;\n attribute vec4 a_matWorld2;\n#elif USE_BATCHING\n attribute float a_dyn_batch_id;\n uniform highp mat4 cc_matWorlds[10];\n#else\nuniform highp mat4 cc_matWorld;\n#endif\n#if USE_VERTEX_COLOR\n attribute vec4 a_color;\n varying vec4 v_color;\n#endif\n#if USE_TEXTURE\n attribute vec2 a_texCoord;\n varying vec2 v_uv;\n uniform vec4 tilingOffset;\n#endif\nvec4 vert () {\n vec4 position;\n position = vec4(a_position, 1.0);\n #if CC_USE_MORPH\n applyMorph(position);\n #endif\n #if CC_USE_SKINNING\n CCSkin(position);\n #endif\n mat4 matWorld;\n #if USE_INSTANCING\n matWorld = mat4(\n vec4(a_matWorld0.xyz, 0.0),\n vec4(a_matWorld1.xyz, 0.0),\n vec4(a_matWorld2.xyz, 0.0),\n vec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)\n );\n #elif USE_BATCHING\n matWorld = cc_matWorlds[int(a_dyn_batch_id)];\n #else\n matWorld = cc_matWorld;\n #endif\n #if USE_TEXTURE\n v_uv = a_texCoord;\n #if FLIP_UV\n v_uv.y = 1.0 - v_uv.y;\n #endif\n v_uv = v_uv * tilingOffset.xy + tilingOffset.zw;\n #endif\n #if USE_VERTEX_COLOR\n v_color = a_color;\n #endif\n return cc_matProj * (cc_matView * matWorld) * position;\n}\nvoid main() { gl_Position = vert(); }`, + "frag": `\nprecision mediump float;\nuniform mediump vec4 cc_exposure;\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\n}\nvec4 CCFragOutput (vec4 color) {\n #if CC_USE_HDR\n color.rgb = mix(color.rgb, SRGBToLinear(color.rgb) * cc_exposure.w, vec3(cc_exposure.z));\n #endif\n return color;\n}\n#if USE_ALPHA_TEST\n#endif\n#if USE_TEXTURE\n varying vec2 v_uv;\n uniform sampler2D mainTexture;\n#endif\nuniform vec4 mainColor;\nuniform vec4 colorScaleAndCutoff;\n#if USE_VERTEX_COLOR\n varying vec4 v_color;\n#endif\nvec4 frag () {\n vec4 o = mainColor;\n o.rgb *= colorScaleAndCutoff.xyz;\n #if USE_VERTEX_COLOR\n o *= v_color;\n #endif\n #if USE_TEXTURE\n o *= texture2D(mainTexture, v_uv);\n #endif\n #if USE_ALPHA_TEST\n if (o.ALPHA_TEST_CHANNEL < colorScaleAndCutoff.w) discard;\n #endif\n return CCFragOutput(o);\n}\nvoid main() { gl_FragColor = frag(); }` }, "builtins": { "globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }], "samplers": [] }, - "locals": { "blocks": [{ "name": "CCLocalBatched", "defines": ["!USE_INSTANCING", "USE_BATCHING"] }, { "name": "CCLocal", "defines": ["!USE_INSTANCING", "!USE_BATCHING"] }, { "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"] }], "samplers": [{ "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"] }] } + "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"] }], "samplers": [{ "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"] }] } }, "defines": [ - { "name": "USE_INSTANCING", "type": "boolean" }, - { "name": "USE_BATCHING", "type": "boolean" }, { "name": "CC_USE_MORPH", "type": "boolean" }, - { "name": "CC_MORPH_TARGET_COUNT", "type": "number", "dummyDependency": true, "range": [2, 8] }, + { "name": "CC_MORPH_TARGET_COUNT", "type": "number", "range": [2, 8] }, { "name": "CC_MORPH_PRECOMPUTED", "type": "boolean" }, { "name": "CC_MORPH_TARGET_HAS_POSITION", "type": "boolean" }, { "name": "CC_MORPH_TARGET_HAS_NORMAL", "type": "boolean" }, { "name": "CC_MORPH_TARGET_HAS_TANGENT", "type": "boolean" }, { "name": "CC_USE_SKINNING", "type": "boolean" }, { "name": "CC_USE_BAKED_ANIMATION", "type": "boolean" }, + { "name": "USE_INSTANCING", "type": "boolean" }, { "name": "CC_SUPPORT_FLOAT_TEXTURE", "type": "boolean" }, - { "name": "CC_USE_FOG", "type": "number", "range": [0, 4] }, + { "name": "USE_BATCHING", "type": "boolean" }, { "name": "USE_VERTEX_COLOR", "type": "boolean" }, { "name": "USE_TEXTURE", "type": "boolean" }, { "name": "FLIP_UV", "type": "boolean" }, { "name": "CC_USE_HDR", "type": "boolean" }, { "name": "USE_ALPHA_TEST", "type": "boolean" }, - { "name": "ALPHA_TEST_CHANNEL", "type": "string", "dummyDependency": true, "options": ["a", "r", "g", "b"] } + { "name": "ALPHA_TEST_CHANNEL", "type": "string", "options": ["a", "r", "g", "b"] } ], "blocks": [ {"name": "TexCoords", "defines": ["USE_TEXTURE"], "binding": 0, "members": [ @@ -488,15 +484,15 @@ export default [ { "name": "mainTexture", "type": 28, "count": 1, "defines": ["USE_TEXTURE"], "binding": 31 } ], "attributes": [ - { "name": "a_matWorld0", "type": 16, "count": 1, "defines": ["USE_INSTANCING"], "format": 43, "isInstanced": true, "location": 4 }, - { "name": "a_matWorld1", "type": 16, "count": 1, "defines": ["USE_INSTANCING"], "format": 43, "isInstanced": true, "location": 1 }, - { "name": "a_matWorld2", "type": 16, "count": 1, "defines": ["USE_INSTANCING"], "format": 43, "isInstanced": true, "location": 2 }, - { "name": "a_dyn_batch_id", "type": 13, "count": 1, "defines": ["!USE_INSTANCING", "USE_BATCHING"], "format": 11, "location": 3 }, { "name": "a_position", "type": 15, "count": 1, "defines": [], "format": 32, "location": 0 }, - { "name": "a_vertexId", "type": 13, "count": 1, "defines": ["CC_USE_MORPH"], "format": 11, "location": 5 }, - { "name": "a_weights", "type": 16, "count": 1, "defines": ["CC_USE_SKINNING"], "format": 43, "location": 6 }, - { "name": "a_joints", "type": 16, "count": 1, "defines": ["CC_USE_SKINNING"], "format": 43, "location": 7 }, - { "name": "a_jointAnimInfo", "type": 16, "count": 1, "defines": ["CC_USE_SKINNING", "CC_USE_BAKED_ANIMATION", "USE_INSTANCING"], "format": 43, "isInstanced": true, "location": 8 }, + { "name": "a_vertexId", "type": 13, "count": 1, "defines": ["CC_USE_MORPH"], "format": 11, "location": 1 }, + { "name": "a_weights", "type": 16, "count": 1, "defines": ["CC_USE_SKINNING"], "format": 43, "location": 2 }, + { "name": "a_joints", "type": 16, "count": 1, "defines": ["CC_USE_SKINNING"], "format": 43, "location": 3 }, + { "name": "a_jointAnimInfo", "type": 16, "count": 1, "precision": "highp ", "defines": ["CC_USE_SKINNING", "CC_USE_BAKED_ANIMATION", "USE_INSTANCING"], "format": 43, "isInstanced": true, "location": 4 }, + { "name": "a_matWorld0", "type": 16, "count": 1, "defines": ["USE_INSTANCING"], "format": 43, "isInstanced": true, "location": 5 }, + { "name": "a_matWorld1", "type": 16, "count": 1, "defines": ["USE_INSTANCING"], "format": 43, "isInstanced": true, "location": 6 }, + { "name": "a_matWorld2", "type": 16, "count": 1, "defines": ["USE_INSTANCING"], "format": 43, "isInstanced": true, "location": 7 }, + { "name": "a_dyn_batch_id", "type": 13, "count": 1, "defines": ["!USE_INSTANCING", "USE_BATCHING"], "format": 11, "location": 8 }, { "name": "a_color", "type": 16, "count": 1, "defines": ["USE_VERTEX_COLOR"], "format": 43, "location": 9 }, { "name": "a_texCoord", "type": 14, "count": 1, "defines": ["USE_TEXTURE"], "format": 21, "location": 10 } ] @@ -512,45 +508,45 @@ export default [ "shaders": [ { "name": "pipeline/planar-shadow|planar-shadow-vs:vert|planar-shadow-fs:frag", - "hash": 2467023454, + "hash": 2011749318, "glsl3": { - "vert": `\nprecision highp float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\n#if USE_INSTANCING\n in vec4 a_matWorld0;\n in vec4 a_matWorld1;\n in vec4 a_matWorld2;\n#elif USE_BATCHING\n in float a_dyn_batch_id;\n uniform CCLocalBatched {\n highp mat4 cc_matWorlds[10];\n };\n#else\nuniform CCLocal {\n highp mat4 cc_matWorld;\n highp mat4 cc_matWorldIT;\n highp vec4 cc_lightingMapUVParam;\n};\n#endif\nuniform CCShadow {\n highp mat4 cc_matLightPlaneProj;\n lowp vec4 cc_shadowColor;\n};\nstruct StandardVertInput {\n highp vec4 position;\n vec3 normal;\n vec4 tangent;\n};\nin vec3 a_position;\n#if CC_USE_MORPH\n in float a_vertexId;\n int getVertexId() {\n return int(a_vertexId);\n }\nuniform CCMorph {\n vec4 cc_displacementWeights[15];\n vec4 cc_displacementTextureInfo;\n};\n vec4 fetchFlatPixel(sampler2D tex, int pixelIndex) {\n float pixelIndexF = float(pixelIndex);\n vec2 textureResolution = vec2(float(cc_displacementTextureInfo.x), float(cc_displacementTextureInfo.y));\n float pixelX = mod(pixelIndexF, textureResolution.x);\n float pixelY = floor(pixelIndexF / textureResolution.x);\n vec2 uv = (vec2(pixelX, pixelY) + .5) / textureResolution;\n return texture(tex, uv);\n }\nfloat getDisplacementWeight(int index) {\n float m = mod(float(index), 4.0);\n if (m < 1.0) {\n return cc_displacementWeights[index / 4].x;\n } else if (m < 2.0) {\n return cc_displacementWeights[index / 4].y;\n } else if (m < 3.0) {\n return cc_displacementWeights[index / 4].z;\n } else {\n return cc_displacementWeights[index / 4].w;\n }\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\n return fetchFlatPixel(tex, vertexIndex).rgb;\n#else\n vec3 result = vec3(0, 0, 0);\n for (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\n int dataPixelStart = int(fetchFlatPixel(tex, iTarget).r);\n result += (fetchFlatPixel(tex, dataPixelStart + vertexIndex).rgb * getDisplacementWeight(iTarget));\n }\n return result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\n uniform sampler2D cc_PositionDisplacements;\n vec3 getPositionDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n uniform sampler2D cc_NormalDisplacements;\n vec3 getNormalDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n uniform sampler2D cc_TangentDisplacements;\n vec3 getTangentDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n }\n#endif\nvoid applyMorph (inout StandardVertInput attr) {\n int vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\n attr.position.xyz = attr.position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n attr.normal.xyz = attr.normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n attr.tangent.xyz = attr.tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\n position.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\nin vec4 a_weights;\nin vec4 a_joints;\n#if CC_USE_BAKED_ANIMATION\n #if USE_INSTANCING\n in vec4 a_jointAnimInfo;\n #endif\n uniform CCSkinningTexture {\n highp vec4 cc_jointTextureInfo;\n };\n uniform CCSkinningAnimation {\n highp vec4 cc_jointAnimInfo;\n };\n uniform sampler2D cc_jointTexture;\n #if !CC_SUPPORT_FLOAT_TEXTURE\n highp float decode32 (highp vec4 rgba) {\n rgba = rgba * 255.0;\n highp float Sign = 1.0 - step(128.0, rgba[3]) * 2.0;\n highp float Exponent = 2.0 * mod(rgba[3], 128.0) + step(128.0, rgba[2]) - 127.0;\n highp float Mantissa = mod(rgba[2], 128.0) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\n }\n #endif\n#else\n uniform CCSkinning {\n highp vec4 cc_joints[30 * 3];\n };\n#endif\n#if CC_USE_BAKED_ANIMATION\n #if CC_SUPPORT_FLOAT_TEXTURE\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 3.0 * i + a_jointAnimInfo.x;\n #else\n highp float j = 3.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = texture(cc_jointTexture, vec2((x + 0.5) * invSize, y));\n vec4 v2 = texture(cc_jointTexture, vec2((x + 1.5) * invSize, y));\n vec4 v3 = texture(cc_jointTexture, vec2((x + 2.5) * invSize, y));\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #else\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 12.0 * i + a_jointAnimInfo.x;\n #else\n highp float j = 12.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = vec4(\n decode32(texture(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n );\n vec4 v2 = vec4(\n decode32(texture(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n );\n vec4 v3 = vec4(\n decode32(texture(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n );\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #endif\n#else\n mat4 getJointMatrix (float i) {\n int idx = int(i);\n vec4 v1 = cc_joints[idx * 3];\n vec4 v2 = cc_joints[idx * 3 + 1];\n vec4 v3 = cc_joints[idx * 3 + 2];\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n#endif\nmat4 skinMatrix () {\n return getJointMatrix(a_joints.x) * a_weights.x\n + getJointMatrix(a_joints.y) * a_weights.y;\n + getJointMatrix(a_joints.z) * a_weights.z;\n + getJointMatrix(a_joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\n mat4 m = skinMatrix();\n position = m * position;\n}\nvoid CCSkin (inout StandardVertInput attr) {\n mat4 m = skinMatrix();\n attr.position = m * attr.position;\n attr.normal = (m * vec4(attr.normal, 0.0)).xyz;\n attr.tangent.xyz = (m * vec4(attr.tangent.xyz, 0.0)).xyz;\n}\n#endif\nvec4 vert () {\n vec4 position;\n position = vec4(a_position, 1.0);\n #if CC_USE_MORPH\n applyMorph(position);\n #endif\n #if CC_USE_SKINNING\n CCSkin(position);\n #endif\n mat4 matWorld;\n #if USE_INSTANCING\n matWorld = mat4(\n vec4(a_matWorld0.xyz, 0.0),\n vec4(a_matWorld1.xyz, 0.0),\n vec4(a_matWorld2.xyz, 0.0),\n vec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)\n );\n #elif USE_BATCHING\n matWorld = cc_matWorlds[int(a_dyn_batch_id)];\n #else\n matWorld = cc_matWorld;\n #endif\n position = cc_matProj * (cc_matView * cc_matLightPlaneProj * matWorld) * position;\n position.z -= 0.0001;\n return position;\n}\nvoid main() { gl_Position = vert(); }`, - "frag": `\nprecision mediump float;\nuniform CCShadow {\n highp mat4 cc_matLightPlaneProj;\n lowp vec4 cc_shadowColor;\n};\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n mediump vec4 cc_fogColor;\n mediump vec4 cc_fogBase;\n mediump vec4 cc_fogAdd;\n};\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\n}\nvec4 CCFragOutput (vec4 color) {\n #if CC_USE_HDR\n color.rgb = mix(color.rgb, SRGBToLinear(color.rgb) * cc_exposure.w, vec3(cc_exposure.z));\n #endif\n return color;\n}\nvec4 frag () {\n return CCFragOutput(cc_shadowColor);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }` + "vert": `\nprecision highp float;\nstruct StandardVertInput {\n highp vec4 position;\n vec3 normal;\n vec4 tangent;\n};\nin vec3 a_position;\n#if CC_USE_MORPH\n in float a_vertexId;\n int getVertexId() {\n return int(a_vertexId);\n }\nuniform CCMorph {\n vec4 cc_displacementWeights[15];\n vec4 cc_displacementTextureInfo;\n};\n vec4 fetchFlatPixel(sampler2D tex, int pixelIndex) {\n float pixelIndexF = float(pixelIndex);\n vec2 textureResolution = vec2(float(cc_displacementTextureInfo.x), float(cc_displacementTextureInfo.y));\n float pixelX = mod(pixelIndexF, textureResolution.x);\n float pixelY = floor(pixelIndexF / textureResolution.x);\n vec2 uv = (vec2(pixelX, pixelY) + .5) / textureResolution;\n return texture(tex, uv);\n }\nfloat getDisplacementWeight(int index) {\n float m = mod(float(index), 4.0);\n if (m < 1.0) {\n return cc_displacementWeights[index / 4].x;\n } else if (m < 2.0) {\n return cc_displacementWeights[index / 4].y;\n } else if (m < 3.0) {\n return cc_displacementWeights[index / 4].z;\n } else {\n return cc_displacementWeights[index / 4].w;\n }\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\n return fetchFlatPixel(tex, vertexIndex).rgb;\n#else\n vec3 result = vec3(0, 0, 0);\n for (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\n int dataPixelStart = int(fetchFlatPixel(tex, iTarget).r);\n result += (fetchFlatPixel(tex, dataPixelStart + vertexIndex).rgb * getDisplacementWeight(iTarget));\n }\n return result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\n uniform sampler2D cc_PositionDisplacements;\n vec3 getPositionDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n uniform sampler2D cc_NormalDisplacements;\n vec3 getNormalDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n uniform sampler2D cc_TangentDisplacements;\n vec3 getTangentDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n }\n#endif\nvoid applyMorph (inout StandardVertInput attr) {\n int vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\n attr.position.xyz = attr.position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n attr.normal.xyz = attr.normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n attr.tangent.xyz = attr.tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\n position.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\nin vec4 a_weights;\nin vec4 a_joints;\n#if CC_USE_BAKED_ANIMATION\n #if USE_INSTANCING\n in highp vec4 a_jointAnimInfo;\n #endif\n uniform CCSkinningTexture {\n highp vec4 cc_jointTextureInfo;\n };\n uniform CCSkinningAnimation {\n highp vec4 cc_jointAnimInfo;\n };\n uniform sampler2D cc_jointTexture;\n #if !CC_SUPPORT_FLOAT_TEXTURE\n highp float decode32 (highp vec4 rgba) {\n rgba = rgba * 255.0;\n highp float Sign = 1.0 - step(128.0, rgba[3]) * 2.0;\n highp float Exponent = 2.0 * mod(rgba[3], 128.0) + step(128.0, rgba[2]) - 127.0;\n highp float Mantissa = mod(rgba[2], 128.0) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\n }\n #endif\n#else\n uniform CCSkinning {\n highp vec4 cc_joints[30 * 3];\n };\n#endif\n#if CC_USE_BAKED_ANIMATION\n #if CC_SUPPORT_FLOAT_TEXTURE\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 3.0 * (a_jointAnimInfo.x * a_jointAnimInfo.y + i) + a_jointAnimInfo.z;\n #else\n highp float j = 3.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = texture(cc_jointTexture, vec2((x + 0.5) * invSize, y));\n vec4 v2 = texture(cc_jointTexture, vec2((x + 1.5) * invSize, y));\n vec4 v3 = texture(cc_jointTexture, vec2((x + 2.5) * invSize, y));\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #else\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 12.0 * (a_jointAnimInfo.x * a_jointAnimInfo.y + i) + a_jointAnimInfo.z;\n #else\n highp float j = 12.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = vec4(\n decode32(texture(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n );\n vec4 v2 = vec4(\n decode32(texture(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n );\n vec4 v3 = vec4(\n decode32(texture(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\n decode32(texture(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n );\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #endif\n#else\n mat4 getJointMatrix (float i) {\n int idx = int(i);\n vec4 v1 = cc_joints[idx * 3];\n vec4 v2 = cc_joints[idx * 3 + 1];\n vec4 v3 = cc_joints[idx * 3 + 2];\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n#endif\nmat4 skinMatrix () {\n return getJointMatrix(a_joints.x) * a_weights.x\n + getJointMatrix(a_joints.y) * a_weights.y;\n + getJointMatrix(a_joints.z) * a_weights.z;\n + getJointMatrix(a_joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\n mat4 m = skinMatrix();\n position = m * position;\n}\nvoid CCSkin (inout StandardVertInput attr) {\n mat4 m = skinMatrix();\n attr.position = m * attr.position;\n attr.normal = (m * vec4(attr.normal, 0.0)).xyz;\n attr.tangent.xyz = (m * vec4(attr.tangent.xyz, 0.0)).xyz;\n}\n#endif\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n};\n#if USE_INSTANCING\n in vec4 a_matWorld0;\n in vec4 a_matWorld1;\n in vec4 a_matWorld2;\n#elif USE_BATCHING\n in float a_dyn_batch_id;\n uniform CCLocalBatched {\n highp mat4 cc_matWorlds[10];\n };\n#else\nuniform CCLocal {\n highp mat4 cc_matWorld;\n highp mat4 cc_matWorldIT;\n highp vec4 cc_lightingMapUVParam;\n};\n#endif\nuniform CCShadow {\n highp mat4 cc_matLightPlaneProj;\n lowp vec4 cc_shadowColor;\n};\nvec4 vert () {\n vec4 position;\n position = vec4(a_position, 1.0);\n #if CC_USE_MORPH\n applyMorph(position);\n #endif\n #if CC_USE_SKINNING\n CCSkin(position);\n #endif\n mat4 matWorld;\n #if USE_INSTANCING\n matWorld = mat4(\n vec4(a_matWorld0.xyz, 0.0),\n vec4(a_matWorld1.xyz, 0.0),\n vec4(a_matWorld2.xyz, 0.0),\n vec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)\n );\n #elif USE_BATCHING\n matWorld = cc_matWorlds[int(a_dyn_batch_id)];\n #else\n matWorld = cc_matWorld;\n #endif\n position = cc_matProj * (cc_matView * cc_matLightPlaneProj * matWorld) * position;\n position.z -= 0.0001;\n return position;\n}\nvoid main() { gl_Position = vert(); }`, + "frag": `\nprecision mediump float;\nuniform CCShadow {\n highp mat4 cc_matLightPlaneProj;\n lowp vec4 cc_shadowColor;\n};\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n};\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\n}\nvec4 CCFragOutput (vec4 color) {\n #if CC_USE_HDR\n color.rgb = mix(color.rgb, SRGBToLinear(color.rgb) * cc_exposure.w, vec3(cc_exposure.z));\n #endif\n return color;\n}\nvec4 frag () {\n return CCFragOutput(cc_shadowColor);\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }` }, "glsl1": { - "vert": `\nprecision highp float;\nuniform highp mat4 cc_matView;\nuniform highp mat4 cc_matProj;\n#if USE_INSTANCING\n attribute vec4 a_matWorld0;\n attribute vec4 a_matWorld1;\n attribute vec4 a_matWorld2;\n#elif USE_BATCHING\n attribute float a_dyn_batch_id;\n uniform highp mat4 cc_matWorlds[10];\n#else\nuniform highp mat4 cc_matWorld;\n#endif\nuniform highp mat4 cc_matLightPlaneProj;\nstruct StandardVertInput {\n highp vec4 position;\n vec3 normal;\n vec4 tangent;\n};\nattribute vec3 a_position;\n#if CC_USE_MORPH\n attribute float a_vertexId;\n int getVertexId() {\n return int(a_vertexId);\n }\nuniform vec4 cc_displacementWeights[15];\nuniform vec4 cc_displacementTextureInfo;\n vec4 fetchFlatPixel(sampler2D tex, int pixelIndex) {\n float pixelIndexF = float(pixelIndex);\n vec2 textureResolution = vec2(float(cc_displacementTextureInfo.x), float(cc_displacementTextureInfo.y));\n float pixelX = mod(pixelIndexF, textureResolution.x);\n float pixelY = floor(pixelIndexF / textureResolution.x);\n vec2 uv = (vec2(pixelX, pixelY) + .5) / textureResolution;\n return texture2D(tex, uv);\n }\nfloat getDisplacementWeight(int index) {\n float m = mod(float(index), 4.0);\n if (m < 1.0) {\n return cc_displacementWeights[index / 4].x;\n } else if (m < 2.0) {\n return cc_displacementWeights[index / 4].y;\n } else if (m < 3.0) {\n return cc_displacementWeights[index / 4].z;\n } else {\n return cc_displacementWeights[index / 4].w;\n }\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\n return fetchFlatPixel(tex, vertexIndex).rgb;\n#else\n vec3 result = vec3(0, 0, 0);\n for (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\n int dataPixelStart = int(fetchFlatPixel(tex, iTarget).r);\n result += (fetchFlatPixel(tex, dataPixelStart + vertexIndex).rgb * getDisplacementWeight(iTarget));\n }\n return result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\n uniform sampler2D cc_PositionDisplacements;\n vec3 getPositionDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n uniform sampler2D cc_NormalDisplacements;\n vec3 getNormalDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n uniform sampler2D cc_TangentDisplacements;\n vec3 getTangentDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n }\n#endif\nvoid applyMorph (inout StandardVertInput attr) {\n int vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\n attr.position.xyz = attr.position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n attr.normal.xyz = attr.normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n attr.tangent.xyz = attr.tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\n position.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\nattribute vec4 a_weights;\nattribute vec4 a_joints;\n#if CC_USE_BAKED_ANIMATION\n #if USE_INSTANCING\n attribute vec4 a_jointAnimInfo;\n #endif\n uniform highp vec4 cc_jointTextureInfo;\n uniform highp vec4 cc_jointAnimInfo;\n uniform sampler2D cc_jointTexture;\n #if !CC_SUPPORT_FLOAT_TEXTURE\n highp float decode32 (highp vec4 rgba) {\n rgba = rgba * 255.0;\n highp float Sign = 1.0 - step(128.0, rgba[3]) * 2.0;\n highp float Exponent = 2.0 * mod(rgba[3], 128.0) + step(128.0, rgba[2]) - 127.0;\n highp float Mantissa = mod(rgba[2], 128.0) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\n }\n #endif\n#else\n uniform highp vec4 cc_joints[90];\n#endif\n#if CC_USE_BAKED_ANIMATION\n #if CC_SUPPORT_FLOAT_TEXTURE\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 3.0 * i + a_jointAnimInfo.x;\n #else\n highp float j = 3.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y));\n vec4 v2 = texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y));\n vec4 v3 = texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y));\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #else\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 12.0 * i + a_jointAnimInfo.x;\n #else\n highp float j = 12.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = vec4(\n decode32(texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n );\n vec4 v2 = vec4(\n decode32(texture2D(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n );\n vec4 v3 = vec4(\n decode32(texture2D(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n );\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #endif\n#else\n mat4 getJointMatrix (float i) {\n int idx = int(i);\n vec4 v1 = cc_joints[idx * 3];\n vec4 v2 = cc_joints[idx * 3 + 1];\n vec4 v3 = cc_joints[idx * 3 + 2];\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n#endif\nmat4 skinMatrix () {\n return getJointMatrix(a_joints.x) * a_weights.x\n + getJointMatrix(a_joints.y) * a_weights.y;\n + getJointMatrix(a_joints.z) * a_weights.z;\n + getJointMatrix(a_joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\n mat4 m = skinMatrix();\n position = m * position;\n}\nvoid CCSkin (inout StandardVertInput attr) {\n mat4 m = skinMatrix();\n attr.position = m * attr.position;\n attr.normal = (m * vec4(attr.normal, 0.0)).xyz;\n attr.tangent.xyz = (m * vec4(attr.tangent.xyz, 0.0)).xyz;\n}\n#endif\nvec4 vert () {\n vec4 position;\n position = vec4(a_position, 1.0);\n #if CC_USE_MORPH\n applyMorph(position);\n #endif\n #if CC_USE_SKINNING\n CCSkin(position);\n #endif\n mat4 matWorld;\n #if USE_INSTANCING\n matWorld = mat4(\n vec4(a_matWorld0.xyz, 0.0),\n vec4(a_matWorld1.xyz, 0.0),\n vec4(a_matWorld2.xyz, 0.0),\n vec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)\n );\n #elif USE_BATCHING\n matWorld = cc_matWorlds[int(a_dyn_batch_id)];\n #else\n matWorld = cc_matWorld;\n #endif\n position = cc_matProj * (cc_matView * cc_matLightPlaneProj * matWorld) * position;\n position.z -= 0.0001;\n return position;\n}\nvoid main() { gl_Position = vert(); }`, + "vert": `\nprecision highp float;\nstruct StandardVertInput {\n highp vec4 position;\n vec3 normal;\n vec4 tangent;\n};\nattribute vec3 a_position;\n#if CC_USE_MORPH\n attribute float a_vertexId;\n int getVertexId() {\n return int(a_vertexId);\n }\nuniform vec4 cc_displacementWeights[15];\nuniform vec4 cc_displacementTextureInfo;\n vec4 fetchFlatPixel(sampler2D tex, int pixelIndex) {\n float pixelIndexF = float(pixelIndex);\n vec2 textureResolution = vec2(float(cc_displacementTextureInfo.x), float(cc_displacementTextureInfo.y));\n float pixelX = mod(pixelIndexF, textureResolution.x);\n float pixelY = floor(pixelIndexF / textureResolution.x);\n vec2 uv = (vec2(pixelX, pixelY) + .5) / textureResolution;\n return texture2D(tex, uv);\n }\nfloat getDisplacementWeight(int index) {\n float m = mod(float(index), 4.0);\n if (m < 1.0) {\n return cc_displacementWeights[index / 4].x;\n } else if (m < 2.0) {\n return cc_displacementWeights[index / 4].y;\n } else if (m < 3.0) {\n return cc_displacementWeights[index / 4].z;\n } else {\n return cc_displacementWeights[index / 4].w;\n }\n}\nvec3 getVec3DisplacementFromTexture(sampler2D tex, int vertexIndex) {\n#if CC_MORPH_PRECOMPUTED\n return fetchFlatPixel(tex, vertexIndex).rgb;\n#else\n vec3 result = vec3(0, 0, 0);\n for (int iTarget = 0; iTarget < CC_MORPH_TARGET_COUNT; ++iTarget) {\n int dataPixelStart = int(fetchFlatPixel(tex, iTarget).r);\n result += (fetchFlatPixel(tex, dataPixelStart + vertexIndex).rgb * getDisplacementWeight(iTarget));\n }\n return result;\n#endif\n}\n#if CC_MORPH_TARGET_HAS_POSITION\n uniform sampler2D cc_PositionDisplacements;\n vec3 getPositionDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_PositionDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n uniform sampler2D cc_NormalDisplacements;\n vec3 getNormalDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_NormalDisplacements, vertexId);\n }\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n uniform sampler2D cc_TangentDisplacements;\n vec3 getTangentDisplacement(int vertexId) {\n return getVec3DisplacementFromTexture(cc_TangentDisplacements, vertexId);\n }\n#endif\nvoid applyMorph (inout StandardVertInput attr) {\n int vertexId = getVertexId();\n#if CC_MORPH_TARGET_HAS_POSITION\n attr.position.xyz = attr.position.xyz + getPositionDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_NORMAL\n attr.normal.xyz = attr.normal.xyz + getNormalDisplacement(vertexId);\n#endif\n#if CC_MORPH_TARGET_HAS_TANGENT\n attr.tangent.xyz = attr.tangent.xyz + getTangentDisplacement(vertexId);\n#endif\n}\nvoid applyMorph (inout vec4 position) {\n#if CC_MORPH_TARGET_HAS_POSITION\n position.xyz = position.xyz + getPositionDisplacement(getVertexId());\n#endif\n}\n#endif\n#if CC_USE_SKINNING\nattribute vec4 a_weights;\nattribute vec4 a_joints;\n#if CC_USE_BAKED_ANIMATION\n #if USE_INSTANCING\n attribute highp vec4 a_jointAnimInfo;\n #endif\n uniform highp vec4 cc_jointTextureInfo;\n uniform highp vec4 cc_jointAnimInfo;\n uniform sampler2D cc_jointTexture;\n #if !CC_SUPPORT_FLOAT_TEXTURE\n highp float decode32 (highp vec4 rgba) {\n rgba = rgba * 255.0;\n highp float Sign = 1.0 - step(128.0, rgba[3]) * 2.0;\n highp float Exponent = 2.0 * mod(rgba[3], 128.0) + step(128.0, rgba[2]) - 127.0;\n highp float Mantissa = mod(rgba[2], 128.0) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;\n return Sign * exp2(Exponent - 23.0) * Mantissa;\n }\n #endif\n#else\n uniform highp vec4 cc_joints[90];\n#endif\n#if CC_USE_BAKED_ANIMATION\n #if CC_SUPPORT_FLOAT_TEXTURE\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 3.0 * (a_jointAnimInfo.x * a_jointAnimInfo.y + i) + a_jointAnimInfo.z;\n #else\n highp float j = 3.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y));\n vec4 v2 = texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y));\n vec4 v3 = texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y));\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #else\n mat4 getJointMatrix (float i) {\n #if USE_INSTANCING\n highp float j = 12.0 * (a_jointAnimInfo.x * a_jointAnimInfo.y + i) + a_jointAnimInfo.z;\n #else\n highp float j = 12.0 * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + i) + cc_jointTextureInfo.z;\n #endif\n highp float invSize = cc_jointTextureInfo.w;\n highp float y = floor(j * invSize);\n highp float x = j - y * cc_jointTextureInfo.x;\n y = (y + 0.5) * invSize;\n vec4 v1 = vec4(\n decode32(texture2D(cc_jointTexture, vec2((x + 0.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 1.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 2.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 3.5) * invSize, y)))\n );\n vec4 v2 = vec4(\n decode32(texture2D(cc_jointTexture, vec2((x + 4.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 5.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 6.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 7.5) * invSize, y)))\n );\n vec4 v3 = vec4(\n decode32(texture2D(cc_jointTexture, vec2((x + 8.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 9.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 10.5) * invSize, y))),\n decode32(texture2D(cc_jointTexture, vec2((x + 11.5) * invSize, y)))\n );\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n #endif\n#else\n mat4 getJointMatrix (float i) {\n int idx = int(i);\n vec4 v1 = cc_joints[idx * 3];\n vec4 v2 = cc_joints[idx * 3 + 1];\n vec4 v3 = cc_joints[idx * 3 + 2];\n return mat4(vec4(v1.xyz, 0.0), vec4(v2.xyz, 0.0), vec4(v3.xyz, 0.0), vec4(v1.w, v2.w, v3.w, 1.0));\n }\n#endif\nmat4 skinMatrix () {\n return getJointMatrix(a_joints.x) * a_weights.x\n + getJointMatrix(a_joints.y) * a_weights.y;\n + getJointMatrix(a_joints.z) * a_weights.z;\n + getJointMatrix(a_joints.w) * a_weights.w;\n}\nvoid CCSkin (inout vec4 position) {\n mat4 m = skinMatrix();\n position = m * position;\n}\nvoid CCSkin (inout StandardVertInput attr) {\n mat4 m = skinMatrix();\n attr.position = m * attr.position;\n attr.normal = (m * vec4(attr.normal, 0.0)).xyz;\n attr.tangent.xyz = (m * vec4(attr.tangent.xyz, 0.0)).xyz;\n}\n#endif\nuniform highp mat4 cc_matView;\nuniform highp mat4 cc_matProj;\n#if USE_INSTANCING\n attribute vec4 a_matWorld0;\n attribute vec4 a_matWorld1;\n attribute vec4 a_matWorld2;\n#elif USE_BATCHING\n attribute float a_dyn_batch_id;\n uniform highp mat4 cc_matWorlds[10];\n#else\nuniform highp mat4 cc_matWorld;\n#endif\nuniform highp mat4 cc_matLightPlaneProj;\nvec4 vert () {\n vec4 position;\n position = vec4(a_position, 1.0);\n #if CC_USE_MORPH\n applyMorph(position);\n #endif\n #if CC_USE_SKINNING\n CCSkin(position);\n #endif\n mat4 matWorld;\n #if USE_INSTANCING\n matWorld = mat4(\n vec4(a_matWorld0.xyz, 0.0),\n vec4(a_matWorld1.xyz, 0.0),\n vec4(a_matWorld2.xyz, 0.0),\n vec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)\n );\n #elif USE_BATCHING\n matWorld = cc_matWorlds[int(a_dyn_batch_id)];\n #else\n matWorld = cc_matWorld;\n #endif\n position = cc_matProj * (cc_matView * cc_matLightPlaneProj * matWorld) * position;\n position.z -= 0.0001;\n return position;\n}\nvoid main() { gl_Position = vert(); }`, "frag": `\nprecision mediump float;\nuniform lowp vec4 cc_shadowColor;\nuniform mediump vec4 cc_exposure;\nvec3 SRGBToLinear (vec3 gamma) {\n return gamma * gamma;\n}\nvec4 CCFragOutput (vec4 color) {\n #if CC_USE_HDR\n color.rgb = mix(color.rgb, SRGBToLinear(color.rgb) * cc_exposure.w, vec3(cc_exposure.z));\n #endif\n return color;\n}\nvec4 frag () {\n return CCFragOutput(cc_shadowColor);\n}\nvoid main() { gl_FragColor = frag(); }` }, "builtins": { "globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }, { "name": "CCShadow", "defines": [] }], "samplers": [] }, - "locals": { "blocks": [{ "name": "CCLocalBatched", "defines": ["!USE_INSTANCING", "USE_BATCHING"] }, { "name": "CCLocal", "defines": ["!USE_INSTANCING", "!USE_BATCHING"] }, { "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"] }], "samplers": [{ "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"] }] } + "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"] }], "samplers": [{ "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"] }] } }, "defines": [ - { "name": "USE_INSTANCING", "type": "boolean" }, - { "name": "USE_BATCHING", "type": "boolean" }, { "name": "CC_USE_MORPH", "type": "boolean" }, - { "name": "CC_MORPH_TARGET_COUNT", "type": "number", "dummyDependency": true, "range": [2, 8] }, + { "name": "CC_MORPH_TARGET_COUNT", "type": "number", "range": [2, 8] }, { "name": "CC_MORPH_PRECOMPUTED", "type": "boolean" }, { "name": "CC_MORPH_TARGET_HAS_POSITION", "type": "boolean" }, { "name": "CC_MORPH_TARGET_HAS_NORMAL", "type": "boolean" }, { "name": "CC_MORPH_TARGET_HAS_TANGENT", "type": "boolean" }, { "name": "CC_USE_SKINNING", "type": "boolean" }, { "name": "CC_USE_BAKED_ANIMATION", "type": "boolean" }, + { "name": "USE_INSTANCING", "type": "boolean" }, { "name": "CC_SUPPORT_FLOAT_TEXTURE", "type": "boolean" }, + { "name": "USE_BATCHING", "type": "boolean" }, { "name": "CC_USE_HDR", "type": "boolean" } ], "blocks": [], "samplers": [], "attributes": [ - { "name": "a_matWorld0", "type": 16, "count": 1, "defines": ["USE_INSTANCING"], "format": 43, "isInstanced": true, "location": 4 }, - { "name": "a_matWorld1", "type": 16, "count": 1, "defines": ["USE_INSTANCING"], "format": 43, "isInstanced": true, "location": 1 }, - { "name": "a_matWorld2", "type": 16, "count": 1, "defines": ["USE_INSTANCING"], "format": 43, "isInstanced": true, "location": 2 }, - { "name": "a_dyn_batch_id", "type": 13, "count": 1, "defines": ["!USE_INSTANCING", "USE_BATCHING"], "format": 11, "location": 3 }, { "name": "a_position", "type": 15, "count": 1, "defines": [], "format": 32, "location": 0 }, - { "name": "a_vertexId", "type": 13, "count": 1, "defines": ["CC_USE_MORPH"], "format": 11, "location": 5 }, - { "name": "a_weights", "type": 16, "count": 1, "defines": ["CC_USE_SKINNING"], "format": 43, "location": 6 }, - { "name": "a_joints", "type": 16, "count": 1, "defines": ["CC_USE_SKINNING"], "format": 43, "location": 7 }, - { "name": "a_jointAnimInfo", "type": 16, "count": 1, "defines": ["CC_USE_SKINNING", "CC_USE_BAKED_ANIMATION", "USE_INSTANCING"], "format": 43, "isInstanced": true, "location": 8 } + { "name": "a_vertexId", "type": 13, "count": 1, "defines": ["CC_USE_MORPH"], "format": 11, "location": 1 }, + { "name": "a_weights", "type": 16, "count": 1, "defines": ["CC_USE_SKINNING"], "format": 43, "location": 2 }, + { "name": "a_joints", "type": 16, "count": 1, "defines": ["CC_USE_SKINNING"], "format": 43, "location": 3 }, + { "name": "a_jointAnimInfo", "type": 16, "count": 1, "precision": "highp ", "defines": ["CC_USE_SKINNING", "CC_USE_BAKED_ANIMATION", "USE_INSTANCING"], "format": 43, "isInstanced": true, "location": 4 }, + { "name": "a_matWorld0", "type": 16, "count": 1, "defines": ["USE_INSTANCING"], "format": 43, "isInstanced": true, "location": 5 }, + { "name": "a_matWorld1", "type": 16, "count": 1, "defines": ["USE_INSTANCING"], "format": 43, "isInstanced": true, "location": 6 }, + { "name": "a_matWorld2", "type": 16, "count": 1, "defines": ["USE_INSTANCING"], "format": 43, "isInstanced": true, "location": 7 }, + { "name": "a_dyn_batch_id", "type": 13, "count": 1, "defines": ["!USE_INSTANCING", "USE_BATCHING"], "format": 11, "location": 8 } ] } ] @@ -578,7 +574,7 @@ export default [ "locals": { "blocks": [], "samplers": [] } }, "defines": [ - { "name": "CC_USE_IBL", "type": "number", "dummyDependency": true, "range": [0, 2] }, + { "name": "CC_USE_IBL", "type": "number", "range": [0, 2] }, { "name": "CC_USE_HDR", "type": "boolean" }, { "name": "USE_RGBE_CUBEMAP", "type": "boolean" } ], diff --git a/cocos/core/3d/framework/light-component.ts b/cocos/core/3d/framework/light-component.ts index cdc83b8432..61cf07adb2 100644 --- a/cocos/core/3d/framework/light-component.ts +++ b/cocos/core/3d/framework/light-component.ts @@ -47,7 +47,7 @@ export const PhotometricTerm = Enum({ * @en static light settings. * @zh 静态灯光设置 */ -@ccclass('cc.ModelLightmapSettings') +@ccclass('cc.StaticLightSettings') class StaticLightSettings { @property protected _editorOnly: boolean = false; From 6b0a37d84ae635de0062b48613ba59c3fe80057a Mon Sep 17 00:00:00 2001 From: pandamicro Date: Fri, 12 Jun 2020 19:27:32 +0800 Subject: [PATCH 21/28] Fix typo --- cocos/core/3d/framework/light-component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/core/3d/framework/light-component.ts b/cocos/core/3d/framework/light-component.ts index 61cf07adb2..b972e072b0 100644 --- a/cocos/core/3d/framework/light-component.ts +++ b/cocos/core/3d/framework/light-component.ts @@ -181,7 +181,7 @@ export class LightComponent extends Component { /** * @en - * static light setttings. + * static light settings. * @zh * 静态灯光设置。 */ From a655f8189a28ca9f1fc142fe48c1600a3244630a Mon Sep 17 00:00:00 2001 From: pandamicro Date: Sun, 14 Jun 2020 19:38:02 +0800 Subject: [PATCH 22/28] Update effects --- cocos/core/3d/builtin/effects.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cocos/core/3d/builtin/effects.ts b/cocos/core/3d/builtin/effects.ts index d53e8dae68..b05804999e 100644 --- a/cocos/core/3d/builtin/effects.ts +++ b/cocos/core/3d/builtin/effects.ts @@ -257,14 +257,14 @@ export default [ "shaders": [ { "name": "builtin-sprite|sprite-vs:vert|sprite-fs:frag", - "hash": 543960898, + "hash": 447598955, "glsl3": { - "vert": `\nprecision mediump float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n};\n#if USE_LOCAL\nuniform CCLocal {\n highp mat4 cc_matWorld;\n highp mat4 cc_matWorldIT;\n highp vec4 cc_lightingMapUVParam;\n};\n#endif\nin vec3 a_position;\nin vec4 a_color;\nout vec4 color;\nin vec2 a_texCoord;\nout vec2 uv0;\nvec4 vert () {\n vec4 pos = vec4(a_position, 1);\n #if USE_LOCAL\n pos = cc_matViewProj * cc_matWorld * pos;\n #else\n pos = cc_matViewProj * pos;\n #endif\n uv0 = a_texCoord;\n color = a_color;\n return pos;\n}\nvoid main() { gl_Position = vert(); }`, - "frag": `\nprecision mediump float;\nin vec4 color;\n#if USE_TEXTURE\n in vec2 uv0;\n uniform sampler2D mainTexture;\n#endif\nvec4 frag () {\n vec4 o = vec4(1, 1, 1, 1);\n #if USE_TEXTURE\n o *= texture(mainTexture, uv0);\n #if IS_GRAY\n float gray = 0.2126 * o.r + 0.7152 * o.g + 0.0722 * o.b;\n o.r = o.g = o.b = gray;\n #endif\n #endif\n o *= color;\n return o;\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }` + "vert": `\nprecision highp float;\nuniform CCGlobal {\n highp vec4 cc_time;\n mediump vec4 cc_screenSize;\n mediump vec4 cc_screenScale;\n mediump vec4 cc_nativeSize;\n highp mat4 cc_matView;\n highp mat4 cc_matViewInv;\n highp mat4 cc_matProj;\n highp mat4 cc_matProjInv;\n highp mat4 cc_matViewProj;\n highp mat4 cc_matViewProjInv;\n highp vec4 cc_cameraPos;\n mediump vec4 cc_exposure;\n mediump vec4 cc_mainLitDir;\n mediump vec4 cc_mainLitColor;\n mediump vec4 cc_ambientSky;\n mediump vec4 cc_ambientGround;\n};\n#if USE_LOCAL\nuniform CCLocal {\n highp mat4 cc_matWorld;\n highp mat4 cc_matWorldIT;\n highp vec4 cc_lightingMapUVParam;\n};\n#endif\nin vec3 a_position;\nin vec4 a_color;\nout vec4 color;\nin vec2 a_texCoord;\nout vec2 uv0;\nvec4 vert () {\n vec4 pos = vec4(a_position, 1);\n #if USE_LOCAL\n pos = cc_matViewProj * cc_matWorld * pos;\n #else\n pos = cc_matViewProj * pos;\n #endif\n uv0 = a_texCoord;\n color = a_color;\n return pos;\n}\nvoid main() { gl_Position = vert(); }`, + "frag": `\nprecision highp float;\nin vec4 color;\n#if USE_TEXTURE\n in vec2 uv0;\n uniform sampler2D mainTexture;\n#endif\nvec4 frag () {\n vec4 o = vec4(1, 1, 1, 1);\n #if USE_TEXTURE\n o *= texture(mainTexture, uv0);\n #if IS_GRAY\n float gray = 0.2126 * o.r + 0.7152 * o.g + 0.0722 * o.b;\n o.r = o.g = o.b = gray;\n #endif\n #endif\n o *= color;\n return o;\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }` }, "glsl1": { - "vert": `\nprecision mediump float;\nuniform highp mat4 cc_matViewProj;\n#if USE_LOCAL\nuniform highp mat4 cc_matWorld;\n#endif\nattribute vec3 a_position;\nattribute vec4 a_color;\nvarying vec4 color;\nattribute vec2 a_texCoord;\nvarying vec2 uv0;\nvec4 vert () {\n vec4 pos = vec4(a_position, 1);\n #if USE_LOCAL\n pos = cc_matViewProj * cc_matWorld * pos;\n #else\n pos = cc_matViewProj * pos;\n #endif\n uv0 = a_texCoord;\n color = a_color;\n return pos;\n}\nvoid main() { gl_Position = vert(); }`, - "frag": `\nprecision mediump float;\nvarying vec4 color;\n#if USE_TEXTURE\n varying vec2 uv0;\n uniform sampler2D mainTexture;\n#endif\nvec4 frag () {\n vec4 o = vec4(1, 1, 1, 1);\n #if USE_TEXTURE\n o *= texture2D(mainTexture, uv0);\n #if IS_GRAY\n float gray = 0.2126 * o.r + 0.7152 * o.g + 0.0722 * o.b;\n o.r = o.g = o.b = gray;\n #endif\n #endif\n o *= color;\n return o;\n}\nvoid main() { gl_FragColor = frag(); }` + "vert": `\nprecision highp float;\nuniform highp mat4 cc_matViewProj;\n#if USE_LOCAL\nuniform highp mat4 cc_matWorld;\n#endif\nattribute vec3 a_position;\nattribute vec4 a_color;\nvarying vec4 color;\nattribute vec2 a_texCoord;\nvarying vec2 uv0;\nvec4 vert () {\n vec4 pos = vec4(a_position, 1);\n #if USE_LOCAL\n pos = cc_matViewProj * cc_matWorld * pos;\n #else\n pos = cc_matViewProj * pos;\n #endif\n uv0 = a_texCoord;\n color = a_color;\n return pos;\n}\nvoid main() { gl_Position = vert(); }`, + "frag": `\nprecision highp float;\nvarying vec4 color;\n#if USE_TEXTURE\n varying vec2 uv0;\n uniform sampler2D mainTexture;\n#endif\nvec4 frag () {\n vec4 o = vec4(1, 1, 1, 1);\n #if USE_TEXTURE\n o *= texture2D(mainTexture, uv0);\n #if IS_GRAY\n float gray = 0.2126 * o.r + 0.7152 * o.g + 0.0722 * o.b;\n o.r = o.g = o.b = gray;\n #endif\n #endif\n o *= color;\n return o;\n}\nvoid main() { gl_FragColor = frag(); }` }, "builtins": { "globals": { "blocks": [{ "name": "CCGlobal", "defines": [] }], "samplers": [] }, From ccf457a5942d3c623b01c88bda4369bc3cbce38f Mon Sep 17 00:00:00 2001 From: "jiaxin.lai" Date: Mon, 15 Jun 2020 14:21:18 +0800 Subject: [PATCH 23/28] emit some event before event processor destroy (#6878) * emit some event before event processor destroy * fix typing * tweaks --- cocos/core/scene-graph/base-node.ts | 38 +++++++++++++------------ cocos/core/scene-graph/node.ts | 4 --- cocos/physics/ammo/shapes/ammo-shape.ts | 4 +-- 3 files changed, 22 insertions(+), 24 deletions(-) diff --git a/cocos/core/scene-graph/base-node.ts b/cocos/core/scene-graph/base-node.ts index e9279f6900..8d536b38ba 100644 --- a/cocos/core/scene-graph/base-node.ts +++ b/cocos/core/scene-graph/base-node.ts @@ -1341,24 +1341,6 @@ export class BaseNode extends CCObject implements ISchedulable { this._registerIfAttached!(false); } - // Destroy node event processor - this._eventProcessor.destroy(); - - // destroy children - const children = this._children; - for (let i = 0; i < children.length; ++i) { - // destroy immediate so its _onPreDestroy can be called - children[i]._destroyImmediate(); - } - - // destroy self components - const comps = this._components; - for (let i = 0; i < comps.length; ++i) { - // destroy immediate so its _onPreDestroy can be called - // TO DO - comps[i]._destroyImmediate(); - } - // remove from persist if (this._persistNode) { cc.game.removePersistRootNode(this); @@ -1378,7 +1360,27 @@ export class BaseNode extends CCObject implements ISchedulable { } } + // emit node destroy event (this should before event processor destroy) this.emit(SystemEventType.NODE_DESTROYED, this); + + // Destroy node event processor + this._eventProcessor.destroy(); + + // destroy children + const children = this._children; + for (let i = 0; i < children.length; ++i) { + // destroy immediate so its _onPreDestroy can be called + children[i]._destroyImmediate(); + } + + // destroy self components + const comps = this._components; + for (let i = 0; i < comps.length; ++i) { + // destroy immediate so its _onPreDestroy can be called + // TO DO + comps[i]._destroyImmediate(); + } + return destroyByParent; } diff --git a/cocos/core/scene-graph/node.ts b/cocos/core/scene-graph/node.ts index 6354e65735..7902c06e6c 100644 --- a/cocos/core/scene-graph/node.ts +++ b/cocos/core/scene-graph/node.ts @@ -1021,10 +1021,6 @@ export class Node extends BaseNode { } } - public _onPreDestroy () { - this._eventProcessor.destroy(); - super._onPreDestroy(); - } } cc.Node = Node; diff --git a/cocos/physics/ammo/shapes/ammo-shape.ts b/cocos/physics/ammo/shapes/ammo-shape.ts index 927d07bc37..19f780f97b 100644 --- a/cocos/physics/ammo/shapes/ammo-shape.ts +++ b/cocos/physics/ammo/shapes/ammo-shape.ts @@ -119,7 +119,7 @@ export class AmmoShape implements IBaseShape { this._btCompound = null; (this._collider as any) = null; const shape = Ammo.castObject(this._btShape, Ammo.btCollisionShape); - shape.wrapped = null; + shape['wrapped'] = null; Ammo.destroy(this.transform); Ammo.destroy(this.pos); Ammo.destroy(this.quat); @@ -184,7 +184,7 @@ export class AmmoShape implements IBaseShape { setWrapper () { const shape = Ammo.castObject(this._btShape, Ammo.btCollisionShape); - shape.wrapped = this; + shape['wrapped'] = this; } setScale () { From 3dc17bd6344a848f63ce26eacf4ccf7f6f269d80 Mon Sep 17 00:00:00 2001 From: Yun Hsiao Wu Date: Tue, 16 Jun 2020 13:06:41 +0800 Subject: [PATCH 24/28] D16S8 fallback to D24S8 on WebGL backend (#6879) --- cocos/core/gfx/webgl/webgl-commands.ts | 4 ++-- cocos/core/gfx/webgl2/webgl2-commands.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cocos/core/gfx/webgl/webgl-commands.ts b/cocos/core/gfx/webgl/webgl-commands.ts index 290f26ef08..0ffc5f4756 100644 --- a/cocos/core/gfx/webgl/webgl-commands.ts +++ b/cocos/core/gfx/webgl/webgl-commands.ts @@ -102,11 +102,11 @@ export function GFXFormatToWebGLType (format: GFXFormat, gl: WebGLRenderingConte case GFXFormat.RGB9E5: return gl.UNSIGNED_BYTE; case GFXFormat.D16: return gl.UNSIGNED_SHORT; - case GFXFormat.D16S8: return gl.UNSIGNED_SHORT; + case GFXFormat.D16S8: return WebGLEXT.UNSIGNED_INT_24_8_WEBGL; // no D16S8 support case GFXFormat.D24: return gl.UNSIGNED_INT; case GFXFormat.D24S8: return WebGLEXT.UNSIGNED_INT_24_8_WEBGL; case GFXFormat.D32F: return gl.FLOAT; - case GFXFormat.D32F_S8: return gl.FLOAT; + case GFXFormat.D32F_S8: return WebGLEXT.UNSIGNED_INT_24_8_WEBGL; // no D32FS8 support case GFXFormat.BC1: return gl.UNSIGNED_BYTE; case GFXFormat.BC1_SRGB: return gl.UNSIGNED_BYTE; diff --git a/cocos/core/gfx/webgl2/webgl2-commands.ts b/cocos/core/gfx/webgl2/webgl2-commands.ts index 67bb3afdc6..8a41871863 100644 --- a/cocos/core/gfx/webgl2/webgl2-commands.ts +++ b/cocos/core/gfx/webgl2/webgl2-commands.ts @@ -135,7 +135,7 @@ export function GFXFormatToWebGLType (format: GFXFormat, gl: WebGL2RenderingCont case GFXFormat.RGB9E5: return gl.FLOAT; case GFXFormat.D16: return gl.UNSIGNED_SHORT; - case GFXFormat.D16S8: return gl.UNSIGNED_SHORT; + case GFXFormat.D16S8: return gl.UNSIGNED_INT_24_8; // no D16S8 support case GFXFormat.D24: return gl.UNSIGNED_INT; case GFXFormat.D24S8: return gl.UNSIGNED_INT_24_8; case GFXFormat.D32F: return gl.FLOAT; @@ -233,7 +233,7 @@ export function GFXFormatToWebGLInternalFormat (format: GFXFormat, gl: WebGL2Ren case GFXFormat.RGB10A2UI: return gl.RGB10_A2UI; case GFXFormat.R11G11B10F: return gl.R11F_G11F_B10F; case GFXFormat.D16: return gl.DEPTH_COMPONENT16; - case GFXFormat.D16S8: return gl.DEPTH_STENCIL; + case GFXFormat.D16S8: return gl.DEPTH24_STENCIL8; // no D16S8 support case GFXFormat.D24: return gl.DEPTH_COMPONENT24; case GFXFormat.D24S8: return gl.DEPTH24_STENCIL8; case GFXFormat.D32F: return gl.DEPTH_COMPONENT32F; From 83f553034e24d70a6b82e48b3565d3f9c974741f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leslie=20Leigh=20=28=E6=9D=8E=E7=9A=84=E5=BA=8F=29?= Date: Tue, 16 Jun 2020 13:39:02 +0800 Subject: [PATCH 25/28] Treat node:eulerAngle curve as skeletal curve; skeletal blending for common targets (#6850) * Treat node:eulerAngle curve as skeletal curve; skeletal blending for common targets * Fix * add test * Fix * Fix --- cocos/core/animation/animation-state.ts | 81 ++++++++++++------- .../animation/skeletal-animation-blending.ts | 34 ++++++-- tests/animation/animation-clip.test.ts | 50 +++++++++++- 3 files changed, 131 insertions(+), 34 deletions(-) diff --git a/cocos/core/animation/animation-state.ts b/cocos/core/animation/animation-state.ts index d4e63cd323..601316722e 100644 --- a/cocos/core/animation/animation-state.ts +++ b/cocos/core/animation/animation-state.ts @@ -34,9 +34,10 @@ import { createBoundTarget, createBufferedTarget, IBufferedTarget, IBoundTarget import { Playable } from './playable'; import { WrapMode, WrapModeMask, WrappedInfo } from './types'; import { EDITOR } from 'internal:constants'; -import { HierarchyPath, evaluatePath } from './target-path'; +import { HierarchyPath, evaluatePath, TargetPath } from './target-path'; import { BlendStateBuffer, createBlendStateWriter, IBlendStateWriter } from './skeletal-animation-blending'; import { ccenum } from '../value-types/enum'; +import { IValueProxyFactory } from './value-proxy'; /** * @en The event type supported by Animation @@ -356,8 +357,44 @@ export class AnimationState extends Playable { this.repeatCount = 1; } + /** + * Create the bound target. Especially optimized for skeletal case. + */ + const createBoundTargetOptimized = ( + createFn: (...args: Parameters) => BoundTargetT | null, + rootTarget: any, + path: TargetPath[], + valueAdapter: IValueProxyFactory | undefined, + isConstant: boolean, + ): BoundTargetT | null => { + if (!isTargetingTRS(path) || !this._blendStateBuffer) { + return createFn(rootTarget, path, valueAdapter); + } else { + const targetNode = evaluatePath(rootTarget, ...path.slice(0, path.length - 1)); + if (targetNode !== null && targetNode instanceof Node) { + const propertyName = path[path.length - 1] as 'position' | 'rotation' | 'scale' | 'eulerAngles'; + const blendStateWriter = createBlendStateWriter( + this._blendStateBuffer, + targetNode, + propertyName, + this, + isConstant, + ); + this._blendStateWriters.push(blendStateWriter); + return createFn(rootTarget, [], blendStateWriter); + } + } + return null; + }; + this._commonTargetStatuses = clip.commonTargets.map((commonTarget, index) => { - const target = createBufferedTarget(root, commonTarget.modifiers, commonTarget.valueAdapter); + const target = createBoundTargetOptimized( + createBufferedTarget, + root, + commonTarget.modifiers, + commonTarget.valueAdapter, + false, + ); if (target === null) { return null; } else { @@ -390,24 +427,13 @@ export class AnimationState extends Playable { rootTarget = commonTargetStatus.target.peek(); } - let boundTarget: IBoundTarget | null = null; - if (!isSkeletonCurve(propertyCurve) || !this._blendStateBuffer) { - boundTarget = createBoundTarget(rootTarget, propertyCurve.modifiers, propertyCurve.valueAdapter); - } else { - const targetNode = evaluatePath(rootTarget, ...propertyCurve.modifiers.slice(0, propertyCurve.modifiers.length - 1)); - if (targetNode !== null && targetNode instanceof Node) { - const propertyName = propertyCurve.modifiers[propertyCurve.modifiers.length - 1] as 'position' | 'rotation' | 'scale'; - const blendStateWriter = createBlendStateWriter( - this._blendStateBuffer, - targetNode, - propertyName, - this, - propertyCurve.curve.constant(), - ); - this._blendStateWriters.push(blendStateWriter); - boundTarget = createBoundTarget(rootTarget, [], blendStateWriter); - } - } + const boundTarget = createBoundTargetOptimized( + createBoundTarget, + rootTarget, + propertyCurve.modifiers, + propertyCurve.valueAdapter, + propertyCurve.curve.constant(), + ); if (boundTarget === null) { // warn(`Failed to bind "${root.name}" to curve in clip ${clip.name}: ${err}`); @@ -889,22 +915,23 @@ export class AnimationState extends Playable { } } -function isSkeletonCurve (curve: IRuntimeCurve) { +function isTargetingTRS (path: TargetPath[]) { let prs: string | undefined; - if (curve.modifiers.length === 1 && typeof curve.modifiers[0] === 'string') { - prs = curve.modifiers[0]; - } else if (curve.modifiers.length > 1) { - for (let i = 0; i < curve.modifiers.length - 1; ++i) { - if (!(curve.modifiers[i] instanceof HierarchyPath)) { + if (path.length === 1 && typeof path[0] === 'string') { + prs = path[0]; + } else if (path.length > 1) { + for (let i = 0; i < path.length - 1; ++i) { + if (!(path[i] instanceof HierarchyPath)) { return false; } } - prs = curve.modifiers[curve.modifiers.length - 1] as string; + prs = path[path.length - 1] as string; } switch (prs) { case 'position': case 'scale': case 'rotation': + case 'eulerAngles': return true; default: return false; diff --git a/cocos/core/animation/skeletal-animation-blending.ts b/cocos/core/animation/skeletal-animation-blending.ts index 97c03454a6..293000556f 100644 --- a/cocos/core/animation/skeletal-animation-blending.ts +++ b/cocos/core/animation/skeletal-animation-blending.ts @@ -20,7 +20,7 @@ export class BlendStateBuffer { propertyBlendState = nodeBlendState.properties[property] = { refCount: 0, weight: 0, - value: ((property === 'position' || property === 'scale') ? new Vec3() : new Quat()) as any, + value: (isVec3Property(property) ? new Vec3() : new Quat()) as any, }; } ++propertyBlendState.refCount; @@ -48,10 +48,10 @@ export class BlendStateBuffer { public apply () { this._nodeBlendStates.forEach((nodeBlendState, node) => { - const { position, scale, rotation } = nodeBlendState.properties; + const { position, scale, rotation, eulerAngles } = nodeBlendState.properties; let t: Vec3 | undefined; let s: Vec3 | undefined; - let r: Quat | undefined; + let r: Quat | Vec3 | undefined; let anyChanged = false; if (position && position.weight !== 0) { position.weight = 0; @@ -63,11 +63,19 @@ export class BlendStateBuffer { s = scale.value; anyChanged = true; } + + // Note: rotation and eulerAngles can not co-exist. if (rotation && rotation.weight !== 0) { rotation.weight = 0; r = rotation.value; anyChanged = true; } + if (eulerAngles && eulerAngles.weight !== 0) { + eulerAngles.weight = 0; + r = eulerAngles.value; + anyChanged = true; + } + if (anyChanged) { node.setRTS(r, t, s); } @@ -92,9 +100,7 @@ export function createBlendStateWriter

( constants: boolean, ): IBlendStateWriter { const blendFunction: BlendFunction> = - (property === 'position' || property === 'scale') ? - additive3D as any: - additiveQuat as any; + isVec3Property(property) ? additive3D as any: additiveQuat as any; let propertyBlendState: PropertyBlendState> | null = null; let isConstCacheValid = false; let lastWeight = -1; @@ -116,6 +122,12 @@ export function createBlendStateWriter

( }, forTarget: () => { return { + /** + * Gets the node's actual property for now. + */ + get: () => { + return node[property]; + }, set: (value: BlendingPropertyValue

) => { if (!isEnabled) { return; @@ -147,6 +159,14 @@ export function createBlendStateWriter

( }; } +function isQuatProperty (property: BlendingProperty) { + return property === 'rotation'; +} + +function isVec3Property (property: BlendingProperty) { + return !isQuatProperty(property); +} + type BlendingProperty = keyof NodeBlendState['properties']; type BlendingPropertyValue

= NonNullable['value']; @@ -165,6 +185,7 @@ interface NodeBlendState { properties: { position?: PropertyBlendState; rotation?: PropertyBlendState; + eulerAngles?: PropertyBlendState; scale?: PropertyBlendState; }; } @@ -173,6 +194,7 @@ function isEmptyNodeBlendState (nodeBlendState: NodeBlendState) { // Which is equal to `Object.keys(nodeBlendState.properties).length === 0`. return !nodeBlendState.properties.position && !nodeBlendState.properties.rotation && + !nodeBlendState.properties.eulerAngles && !nodeBlendState.properties.scale; } diff --git a/tests/animation/animation-clip.test.ts b/tests/animation/animation-clip.test.ts index 9ee95d5da4..d6c2824539 100644 --- a/tests/animation/animation-clip.test.ts +++ b/tests/animation/animation-clip.test.ts @@ -1,5 +1,5 @@ import { AnimationClip, js, AnimationState, Node, Component, Vec3, AnimationManager } from '../../cocos/core'; -import { ComponentPath } from '../../cocos/core/animation/animation'; +import { ComponentPath, HierarchyPath } from '../../cocos/core/animation/animation'; import { ccclass } from '../../cocos/core/data/class-decorator'; test('Common target', () => { @@ -66,6 +66,54 @@ test('Common target', () => { } }); +test('Common targets that modify eulerAngles', () => { + const animationManager = new AnimationManager(); + const mockInstance = jest.spyOn((global as any).cc.director, 'getAnimationManager').mockImplementation(() => { + return animationManager; + }); + + const partialNodeName = 'partial'; + + const clip = new AnimationClip('default'); + clip.duration = 2.0; + const keys = [0, 0.1, 0.2]; + const eulerValues = [new Vec3(), new Vec3(1), new Vec3(2)]; + const eulerXValues = [0, 1, 2]; + clip.keys = [keys]; + clip.commonTargets = [{ + modifiers: [new HierarchyPath(partialNodeName), 'eulerAngles'], + }]; + clip.curves = [{ + modifiers: ['eulerAngles'], + data: {keys: 0, values: eulerValues}, + }, { + commonTarget: 0, // euler angles + modifiers: ['x'], + data: {keys: 0, values: eulerXValues}, + }]; + + const state = new AnimationState(clip, clip.name); + state.weight = 1.0; + + const node = new Node(); + const partialNode = new Node(partialNodeName); + node.addChild(partialNode); + state.initialize(node); + + animationManager.update(0); + state.play(); + state.pause(); + + state.setTime(keys[1]); + state.update(0); + animationManager.update(0); + + expect(node.eulerAngles).toEqual(eulerValues[1]); + expect(partialNode.eulerAngles.x).toEqual(eulerXValues[1]); + + mockInstance.mockRestore(); +}); + test('animation state', () => { const animationManager = new AnimationManager(); const mockInstance = jest.spyOn((global as any).cc.director, 'getAnimationManager').mockImplementation(() => { From ee07c5e7417ab377348c5e3cf5141d1766d729c8 Mon Sep 17 00:00:00 2001 From: cary <39078800+caryliu1999@users.noreply.github.com> Date: Tue, 16 Jun 2020 15:45:34 +0800 Subject: [PATCH 26/28] Add fallback of particle system. (#6884) --- .../renderer/particle-system-renderer-cpu.ts | 4 ++ .../renderer/particle-system-renderer-data.ts | 37 +++++++++++++++++-- .../renderer/particle-system-renderer-gpu.ts | 35 ++++++++++++------ 3 files changed, 60 insertions(+), 16 deletions(-) diff --git a/cocos/particle/renderer/particle-system-renderer-cpu.ts b/cocos/particle/renderer/particle-system-renderer-cpu.ts index 778394b5a5..dd20f7c532 100644 --- a/cocos/particle/renderer/particle-system-renderer-cpu.ts +++ b/cocos/particle/renderer/particle-system-renderer-cpu.ts @@ -377,6 +377,7 @@ export default class ParticleSystemRendererCPU extends ParticleSystemRendererBas const shareMaterial = ps.sharedMaterial; if (shareMaterial != null) { const effectName = shareMaterial._effectAsset._name; + this._renderInfo!.mainTexture = shareMaterial.getProperty('mainTexture', 0); // reset material if (effectName.indexOf('particle') === -1 || effectName.indexOf('particle-gpu') !== -1) { ps.setMaterial(null, 0); @@ -388,6 +389,9 @@ export default class ParticleSystemRendererCPU extends ParticleSystemRendererBas _matInsInfo.owner = this._particleSystem; _matInsInfo.subModelIdx = 0; this._defaultMat = new MaterialInstance(_matInsInfo); + if (this._renderInfo!.mainTexture !== null) { + this._defaultMat.setProperty('mainTexture', this._renderInfo!.mainTexture); + } } const mat: Material = ps.getMaterialInstance(0) || this._defaultMat; if (ps._simulationSpace === Space.World) { diff --git a/cocos/particle/renderer/particle-system-renderer-data.ts b/cocos/particle/renderer/particle-system-renderer-data.ts index 1923973206..449c68daa4 100644 --- a/cocos/particle/renderer/particle-system-renderer-data.ts +++ b/cocos/particle/renderer/particle-system-renderer-data.ts @@ -1,11 +1,23 @@ -import { Material, Mesh } from '../../core/assets'; +import { Material, Mesh, Texture2D } from '../../core/assets'; import { ccclass, property } from '../../core/data/class-decorator'; import { RenderMode} from '../enum'; import ParticleSystemRendererCPU from './particle-system-renderer-cpu'; import ParticleSystemRendererGPU from './particle-system-renderer-gpu'; +import { director } from '../../core/director'; +import { GFXDevice, GFXFeature } from '../../core/gfx/device'; + +function isSupportGPUParticle () { + const device: GFXDevice = director.root!.device; + if (device.maxVertexTextureUnits >= 8 && device.hasFeature(GFXFeature.TEXTURE_FLOAT)) { + return true; + } + + cc.warn("Maybe the device has restrictions on vertex textures or does not support float textures."); + return false; +} + @ccclass('cc.ParticleSystemRenderer') export default class ParticleSystemRenderer { - /** * @zh 设定粒子生成模式。 */ @@ -136,6 +148,17 @@ export default class ParticleSystemRenderer { this._particleSystem.setMaterial(val, 1); } + @property + private _mainTexture: Texture2D | null = null; + + public get mainTexture () { + return this._mainTexture; + } + + public set mainTexture (val) { + this._mainTexture = val; + } + @property private _useGPU: boolean = false; @@ -152,7 +175,12 @@ export default class ParticleSystemRenderer { return; } - this._useGPU = val; + if (!isSupportGPUParticle()) { + this._useGPU = false; + } else { + this._useGPU = val; + } + this._switchProcessor(); } @@ -160,7 +188,8 @@ export default class ParticleSystemRenderer { onInit (ps: any) { this._particleSystem = ps; - this._particleSystem.processor = this._useGPU ? new ParticleSystemRendererGPU(this) : new ParticleSystemRendererCPU(this); + const useGPU = this._useGPU && isSupportGPUParticle(); + this._particleSystem.processor = useGPU ? new ParticleSystemRendererGPU(this) : new ParticleSystemRendererCPU(this); this._particleSystem.processor.onInit(ps); } diff --git a/cocos/particle/renderer/particle-system-renderer-gpu.ts b/cocos/particle/renderer/particle-system-renderer-gpu.ts index 401f659e33..87b4d09184 100644 --- a/cocos/particle/renderer/particle-system-renderer-gpu.ts +++ b/cocos/particle/renderer/particle-system-renderer-gpu.ts @@ -357,29 +357,40 @@ export default class ParticleSystemRendererGPU extends ParticleSystemRendererBas if (!this._particleSystem) { return; } - if (this._particleSystem.sharedMaterial != null && this._particleSystem.sharedMaterial._effectAsset._name.indexOf('particle-gpu') === -1) { - // reset material - this._particleSystem.setMaterial(null, 0); + const ps = this._particleSystem; + const shareMaterial = ps.sharedMaterial; + if (shareMaterial !== null) { + const effectName = shareMaterial._effectAsset._name; + this._renderInfo!.mainTexture = shareMaterial.getProperty('mainTexture', 0); + if (effectName.indexOf('particle-gpu') === -1) { + this._renderInfo!.mainTexture = shareMaterial.getProperty('mainTexture', 0); + // reset material + this._particleSystem.setMaterial(null, 0); + } } - if (this._particleSystem.sharedMaterial == null && this._defaultMat == null) { + + if (shareMaterial == null && this._defaultMat == null) { _matInsInfo.parent = builtinResMgr.get('default-particle-gpu-material'); - _matInsInfo.owner = this._particleSystem; + _matInsInfo.owner = ps; _matInsInfo.subModelIdx = 0; this._defaultMat = new MaterialInstance(_matInsInfo); + if (this._renderInfo!.mainTexture !== null) { + this._defaultMat.setProperty('mainTexture', this._renderInfo!.mainTexture); + } } - const mat: Material | null = this._particleSystem.getMaterialInstance(0) || this._defaultMat; + const mat: Material | null = ps.getMaterialInstance(0) || this._defaultMat; - this._particleSystem.node.getWorldMatrix(_tempWorldTrans); - switch (this._particleSystem.scaleSpace) { + ps.node.getWorldMatrix(_tempWorldTrans); + switch (ps.scaleSpace) { case Space.Local: - this._particleSystem.node.getScale(this._node_scale); + ps.node.getScale(this._node_scale); break; case Space.World: - this._particleSystem.node.getWorldScale(this._node_scale); + ps.node.getWorldScale(this._node_scale); break; } - if (this._particleSystem._simulationSpace === Space.World) { + if (ps._simulationSpace === Space.World) { this._defines[CC_USE_WORLD_SPACE] = true; } else { this._defines[CC_USE_WORLD_SPACE] = false; @@ -400,7 +411,7 @@ export default class ParticleSystemRendererGPU extends ParticleSystemRendererBas } else { console.warn(`particle system renderMode ${renderMode} not support.`); } - const textureModule = this._particleSystem._textureAnimationModule; + const textureModule = ps._textureAnimationModule; if (textureModule && textureModule.enable) { Vec2.set(this._frameTile_velLenScale, textureModule.numTilesX, textureModule.numTilesY); } From 41c11911175124f34d3e85465d19ad4c1fda4e4a Mon Sep 17 00:00:00 2001 From: "jiaxin.lai" Date: Tue, 16 Jun 2020 18:59:57 +0800 Subject: [PATCH 27/28] update @cocos/cannon to 1.1.1 (#6885) --- package-lock.json | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 17c1e66a1b..3d27bf95b1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2798,9 +2798,9 @@ } }, "@cocos/cannon": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/@cocos/cannon/-/cannon-1.1.0.tgz", - "integrity": "sha512-hdQsL7P7tugPP4y14cCW2ITNpmnrwjqT1nS+mCacfatQ+G5aA2kKPH55dimUjNsAkO5XdZQhM13f7GgF+Votog==" + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@cocos/cannon/-/cannon-1.1.1.tgz", + "integrity": "sha512-LkOCfgqD+jpypZ7U2/P+LCrG2z+OeiSG06HN9PX33HoTt216cmGkoFXhzezyBhtjsguXdFkeDl+Zc/eT5Qsezw==" }, "@jest/console": { "version": "24.9.0", diff --git a/package.json b/package.json index 50a4a44aba..3e7fed51a5 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,6 @@ }, "dependencies": { "@cocos/ammo": "^1.0.6", - "@cocos/cannon": "^1.1.0" + "@cocos/cannon": "^1.1.1" } } From 3b31edae6769c54fd7708c3c972a6dbb98a7eb12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leslie=20Leigh=20=28=E6=9D=8E=E7=9A=84=E5=BA=8F=29?= Date: Wed, 17 Jun 2020 12:01:11 +0800 Subject: [PATCH 28/28] Fix once bug (#6889) --- cocos/core/animation/animation-component.ts | 4 ++-- cocos/core/event/eventify.ts | 2 +- cocos/core/game.ts | 4 ++-- .../platform/event-manager/system-event.ts | 4 ++-- .../components/collider/collider-component.ts | 4 ++-- tests/core/eventify.test.ts | 20 +++++++++++++++++++ 6 files changed, 29 insertions(+), 9 deletions(-) diff --git a/cocos/core/animation/animation-component.ts b/cocos/core/animation/animation-component.ts index 7fac4010d9..11aa66b3ae 100644 --- a/cocos/core/animation/animation-component.ts +++ b/cocos/core/animation/animation-component.ts @@ -369,8 +369,8 @@ export class AnimationComponent extends Eventify(Component) { * animation.on('play', this.onPlay, this); * ``` */ - public on (type: EventType, callback: TFunction, thisArg?: any) { - const ret = super.on(type, callback, thisArg); + public on (type: EventType, callback: TFunction, thisArg?: any, once?: boolean) { + const ret = super.on(type, callback, thisArg, once); if (type === EventType.LASTFRAME) { this._syncAllowLastFrameEvent(); } diff --git a/cocos/core/event/eventify.ts b/cocos/core/event/eventify.ts index 5f5e9b9181..ce7fd08cd2 100644 --- a/cocos/core/event/eventify.ts +++ b/cocos/core/event/eventify.ts @@ -42,7 +42,7 @@ export interface IEventified { * cc.log("fire in the hole"); * }, node); */ - on (type: EventType, callback: TFunction, thisArg?: any): typeof callback; + on (type: EventType, callback: TFunction, thisArg?: any, once?: boolean): typeof callback; /** * @en diff --git a/cocos/core/game.ts b/cocos/core/game.ts index f27b565430..afac00432e 100644 --- a/cocos/core/game.ts +++ b/cocos/core/game.ts @@ -524,13 +524,13 @@ export class Game extends EventTarget { * @param {Object} [target] - The target (this object) to invoke the callback, can be null * @return {Function} - Just returns the incoming callback so you can save the anonymous function easier. */ - public on (type: string, callback: Function, target?: object): any { + public on (type: string, callback: Function, target?: object, once?: boolean): any { // Make sure EVENT_ENGINE_INITED callbacks to be invoked if (this._inited && type === Game.EVENT_ENGINE_INITED) { callback.call(target); } else { - this.eventTargetOn(type, callback, target); + this.eventTargetOn(type, callback, target, once); } } diff --git a/cocos/core/platform/event-manager/system-event.ts b/cocos/core/platform/event-manager/system-event.ts index c36e6a0442..d0779756c3 100644 --- a/cocos/core/platform/event-manager/system-event.ts +++ b/cocos/core/platform/event-manager/system-event.ts @@ -115,11 +115,11 @@ export class SystemEvent extends EventTarget { * @param callback - The event listener's callback * @param target - The event listener's target and callee */ - public on (type: string, callback: Function, target?: Object) { + public on (type: string, callback: Function, target?: Object, once?: boolean) { if (EDITOR) { return; } - super.on(type, callback, target); + super.on(type, callback, target, once); // Keyboard if (type === SystemEventType.KEY_DOWN || type === SystemEventType.KEY_UP) { diff --git a/cocos/physics/framework/components/collider/collider-component.ts b/cocos/physics/framework/components/collider/collider-component.ts index edc18eae3e..86aca2b3b0 100644 --- a/cocos/physics/framework/components/collider/collider-component.ts +++ b/cocos/physics/framework/components/collider/collider-component.ts @@ -185,8 +185,8 @@ export class ColliderComponent extends Eventify(Component) { * @param callback - The event callback, signature:`(event?:ICollisionEvent|ITriggerEvent)=>void`. * @param target - The event callback target. */ - public on (type: TriggerEventType | CollisionEventType, callback: Function, target?: Object): any { - super.on(type, callback, target); + public on (type: TriggerEventType | CollisionEventType, callback: Function, target?: Object, once?: boolean): any { + super.on(type, callback, target, once); } /** diff --git a/tests/core/eventify.test.ts b/tests/core/eventify.test.ts index 7883016548..8d5f2bd5c0 100644 --- a/tests/core/eventify.test.ts +++ b/tests/core/eventify.test.ts @@ -35,4 +35,24 @@ test('Eventify', () => { derived.once(eventName, eventCallback); derived.emit(eventName); expect(hookOnOff).toBeCalledTimes(2); +}); + +test('Overwrite Eventify.prototype.on', () => { + class Base {} + class Derived extends Eventify(Base) { + public on (type: string, callback: TFunction, thisArg?: any, once?: boolean) { + return super.on(type, callback, thisArg, once); + } + } + + const derived = new Derived(); + + const eventName = 'event'; + const onceFn = jest.fn(() => {}); + + derived.once(eventName, onceFn); + derived.emit(eventName); + expect(onceFn).toBeCalledTimes(1); + derived.emit(eventName); + expect(onceFn).toBeCalledTimes(1); }); \ No newline at end of file