mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 08:02:39 +08:00
Merge branch 'v3.6.2' of github.com:cocos-creator/engine into v3.6.1-sync
This commit is contained in:
@@ -1 +1,4 @@
|
||||
*.jsb.ts
|
||||
**/*.ems.ts
|
||||
cocos/core/gfx/webgpu/**/*
|
||||
cocos/webgpu/**/*
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
declare module 'url:native/external/emscripten/webgpu/webgpu_wasm.wasm' {
|
||||
const url: string;
|
||||
export default url;
|
||||
}
|
||||
|
||||
declare module 'url:native/external/emscripten/webgpu/glslang.wasm' {
|
||||
const url: string;
|
||||
export default url;
|
||||
}
|
||||
@@ -3284,6 +3284,10 @@ The shadow visible distance is so small that CSM stratification is not effective
|
||||
|
||||
The native folder may be generated from older versions, please refer https://docs.cocos.com/creator/manual/en/release-notes/ to upgrade.
|
||||
|
||||
### 15100
|
||||
|
||||
Camera '%s' clear flag is skybox, but skybox is disabled, may cause strange background effect, please set camera clear flag to solid color.
|
||||
|
||||
### 16000
|
||||
|
||||
'%s' is deprecated since v%s.
|
||||
|
||||
@@ -244,6 +244,13 @@
|
||||
"cocos/3d/misc/create-mesh.ts": "cocos/3d/misc/create-mesh.jsb.ts"
|
||||
}
|
||||
},
|
||||
{
|
||||
"test": "context.buildTimeConstants && context.buildTimeConstants.WEBGPU",
|
||||
"isVirtualModule": false,
|
||||
"overrides": {
|
||||
"cocos/core/gfx/index.ts": "cocos/core/gfx/index.ems.ts"
|
||||
}
|
||||
},
|
||||
{
|
||||
"test": "context.buildTimeConstants && context.buildTimeConstants.HTML5",
|
||||
"isVirtualModule": true,
|
||||
@@ -507,6 +514,12 @@
|
||||
"type": "number",
|
||||
"value": 0,
|
||||
"internal": false
|
||||
},
|
||||
"WEBGPU": {
|
||||
"comment": "Running with webgpu rendering backend.",
|
||||
"type": "boolean",
|
||||
"value": false,
|
||||
"internal": true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -308,28 +308,6 @@ export class Label extends UIRenderer {
|
||||
this.markForUpdateRenderData();
|
||||
}
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Font family of label, only take effect when useSystemFont property is true.
|
||||
*
|
||||
* @zh
|
||||
* 文本字体名称, 只在 useSystemFont 属性为 true 的时候生效。
|
||||
*/
|
||||
@displayOrder(8)
|
||||
@visible(function (this: Label) { return !this._isSystemFontUsed; })
|
||||
@tooltip('i18n:label.font_family')
|
||||
get fontFamily () {
|
||||
return this._fontFamily;
|
||||
}
|
||||
set fontFamily (value) {
|
||||
if (this._fontFamily === value) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._fontFamily = value;
|
||||
this.markForUpdateRenderData();
|
||||
}
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Line Height of label.
|
||||
@@ -418,6 +396,63 @@ export class Label extends UIRenderer {
|
||||
this.markForUpdateRenderData();
|
||||
}
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Whether use system font name or not.
|
||||
*
|
||||
* @zh
|
||||
* 是否使用系统字体。
|
||||
*/
|
||||
@displayOrder(12)
|
||||
@tooltip('i18n:label.system_font')
|
||||
get useSystemFont () {
|
||||
return this._isSystemFontUsed;
|
||||
}
|
||||
set useSystemFont (value) {
|
||||
if (this._isSystemFontUsed === value) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.destroyRenderData();
|
||||
|
||||
if (EDITOR) {
|
||||
if (!value && this._isSystemFontUsed && this._userDefinedFont) {
|
||||
this.font = this._userDefinedFont;
|
||||
this.spacingX = this._spacingX;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this._isSystemFontUsed = !!value;
|
||||
if (value) {
|
||||
this.font = null;
|
||||
}
|
||||
this._flushAssembler();
|
||||
this.markForUpdateRenderData();
|
||||
}
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Font family of label, only take effect when useSystemFont property is true.
|
||||
*
|
||||
* @zh
|
||||
* 文本字体名称, 只在 useSystemFont 属性为 true 的时候生效。
|
||||
*/
|
||||
@displayOrder(13)
|
||||
@visible(function (this: Label) { return this._isSystemFontUsed; })
|
||||
@tooltip('i18n:label.font_family')
|
||||
get fontFamily () {
|
||||
return this._fontFamily;
|
||||
}
|
||||
set fontFamily (value) {
|
||||
if (this._fontFamily === value) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._fontFamily = value;
|
||||
this.markForUpdateRenderData();
|
||||
}
|
||||
|
||||
/**
|
||||
* @en
|
||||
* The font of label.
|
||||
@@ -426,7 +461,7 @@ export class Label extends UIRenderer {
|
||||
* 文本字体。
|
||||
*/
|
||||
@type(Font)
|
||||
@displayOrder(12)
|
||||
@displayOrder(13)
|
||||
@visible(function (this: Label) { return !this._isSystemFontUsed; })
|
||||
@tooltip('i18n:label.font')
|
||||
get font () {
|
||||
@@ -456,41 +491,6 @@ export class Label extends UIRenderer {
|
||||
this.updateRenderData(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Whether use system font name or not.
|
||||
*
|
||||
* @zh
|
||||
* 是否使用系统字体。
|
||||
*/
|
||||
@displayOrder(13)
|
||||
@tooltip('i18n:label.system_font')
|
||||
get useSystemFont () {
|
||||
return this._isSystemFontUsed;
|
||||
}
|
||||
set useSystemFont (value) {
|
||||
if (this._isSystemFontUsed === value) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.destroyRenderData();
|
||||
|
||||
if (EDITOR) {
|
||||
if (!value && this._isSystemFontUsed && this._userDefinedFont) {
|
||||
this.font = this._userDefinedFont;
|
||||
this.spacingX = this._spacingX;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this._isSystemFontUsed = !!value;
|
||||
if (value) {
|
||||
this.font = null;
|
||||
}
|
||||
this._flushAssembler();
|
||||
this.markForUpdateRenderData();
|
||||
}
|
||||
|
||||
/**
|
||||
* @en
|
||||
* The cache mode of label. This mode only supports system fonts.
|
||||
|
||||
@@ -111,6 +111,13 @@ export class Batcher2D implements IBatcher {
|
||||
private _currIsStatic = false;
|
||||
private _currHash = 0;
|
||||
|
||||
//for middleware
|
||||
private _currIsMiddleware = false;
|
||||
private _middlewareEnableBatch = false;
|
||||
private _middlewareBuffer: MeshBuffer | null = null;
|
||||
private _middlewareIndexStart = 0;
|
||||
private _middlewareIndexCount = 0;
|
||||
|
||||
private _pOpacity = 1;
|
||||
private _opacityDirty = 0;
|
||||
|
||||
@@ -435,6 +442,7 @@ export class Batcher2D implements IBatcher {
|
||||
* @param tex - The texture used
|
||||
* @param mat - The material used
|
||||
* @param [transform] - The related node transform if the render data is based on node's local coordinates
|
||||
* @deprecated since v3.6.2, please use [[commitMiddleware]] instead
|
||||
*/
|
||||
public commitIA (renderComp: UIRenderer, ia: InputAssembler, tex?: TextureBase, mat?: Material, transform?: Node) {
|
||||
// if the last comp is spriteComp, previous comps should be batched.
|
||||
@@ -468,6 +476,53 @@ export class Batcher2D implements IBatcher {
|
||||
this._batches.push(curDrawBatch);
|
||||
}
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Render component data submission process for middleware2d components
|
||||
* @zh
|
||||
* 渲染组件中针对2D中间件组件渲染数据的提交流程
|
||||
* 例如:Spine 和 DragonBones 包含动态数据和材质的组件
|
||||
* @param comp - The committed renderable component
|
||||
* @param meshBuffer - The MeshBuffer used
|
||||
* @param indexOffset - indices offset
|
||||
* @param indexCount - indices count
|
||||
* @param tex - The texture used
|
||||
* @param mat - The material used
|
||||
* @param enableBatch - component support multi draw batch or not
|
||||
*/
|
||||
public commitMiddleware (comp: UIRenderer, meshBuffer: MeshBuffer, indexOffset: number,
|
||||
indexCount: number, tex: TextureBase, mat: Material, enableBatch: boolean) {
|
||||
// check if need merge draw batch
|
||||
const texture = tex.getGFXTexture();
|
||||
if (enableBatch && this._middlewareEnableBatch && this._middlewareBuffer === meshBuffer
|
||||
&& this._currTexture === texture
|
||||
&& this._currMaterial.hash === mat.hash
|
||||
&& this._middlewareIndexStart + this._middlewareIndexCount === indexOffset
|
||||
&& this._currLayer === comp.node.layer) {
|
||||
this._middlewareIndexCount += indexCount;
|
||||
} else {
|
||||
this.autoMergeBatches(this._currComponent!);
|
||||
this.resetRenderStates();
|
||||
|
||||
this._currComponent = comp;
|
||||
this._currTexture = texture;
|
||||
this._currSampler = tex.getGFXSampler();
|
||||
this._currTextureHash = tex.getHash();
|
||||
this._currLayer = comp.node.layer;
|
||||
this._currSamplerHash = this._currSampler.hash;
|
||||
this._currHash = 0;
|
||||
this._currTransform = enableBatch ? null : comp.node;
|
||||
|
||||
this._middlewareEnableBatch = enableBatch;
|
||||
this._middlewareBuffer = meshBuffer;
|
||||
this._currMaterial = mat;
|
||||
this._middlewareIndexStart = indexOffset;
|
||||
this._middlewareIndexCount = indexCount;
|
||||
}
|
||||
|
||||
this._currIsMiddleware = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Render component data submission process of UI.
|
||||
@@ -561,6 +616,10 @@ export class Batcher2D implements IBatcher {
|
||||
* 根据合批条件,结束一段渲染数据并提交。
|
||||
*/
|
||||
public autoMergeBatches (renderComp?: UIRenderer) {
|
||||
if (this._currIsMiddleware) {
|
||||
this.mergeBatchesForMiddleware(renderComp!);
|
||||
return;
|
||||
}
|
||||
const mat = this._currMaterial;
|
||||
if (!mat) {
|
||||
return;
|
||||
@@ -623,6 +682,36 @@ export class Batcher2D implements IBatcher {
|
||||
this._batches.push(curDrawBatch);
|
||||
}
|
||||
|
||||
private mergeBatchesForMiddleware (renderComp: UIRenderer) {
|
||||
let depthStencil;
|
||||
let dssHash = 0;
|
||||
renderComp.stencilStage = StencilManager.sharedManager!.stage;
|
||||
if (renderComp.customMaterial !== null) {
|
||||
depthStencil = StencilManager.sharedManager!.getStencilStage(renderComp.stencilStage, this._currMaterial);
|
||||
} else {
|
||||
depthStencil = StencilManager.sharedManager!.getStencilStage(renderComp.stencilStage);
|
||||
}
|
||||
dssHash = StencilManager.sharedManager!.getStencilHash(renderComp.stencilStage);
|
||||
|
||||
const curDrawBatch = this._currStaticRoot ? this._currStaticRoot._requireDrawBatch() : this._drawBatchPool.alloc();
|
||||
curDrawBatch.visFlags = renderComp.node.layer;
|
||||
const ia = this._middlewareBuffer!.requireFreeIA(this.device);
|
||||
ia.firstIndex = this._middlewareIndexStart;
|
||||
ia.indexCount = this._middlewareIndexCount;
|
||||
|
||||
curDrawBatch.inputAssembler = ia;
|
||||
curDrawBatch.useLocalData = this._currTransform;
|
||||
curDrawBatch.texture = this._currTexture;
|
||||
curDrawBatch.sampler = this._currSampler;
|
||||
curDrawBatch.textureHash = this._currTextureHash;
|
||||
curDrawBatch.samplerHash = this._currSamplerHash;
|
||||
curDrawBatch.fillPasses(this._currMaterial || null, depthStencil, dssHash, null);
|
||||
this._batches.push(curDrawBatch);
|
||||
|
||||
this._currIsMiddleware = false;
|
||||
this._middlewareBuffer = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Force changes to current batch data and merge
|
||||
|
||||
@@ -124,17 +124,6 @@ export class MeshBuffer {
|
||||
}
|
||||
}
|
||||
|
||||
protected _useLinkedData = false;
|
||||
get useLinkedData () {
|
||||
return this._useLinkedData;
|
||||
}
|
||||
set useLinkedData (val:boolean) {
|
||||
if (JSB && this._useLinkedData !== val) {
|
||||
this._nativeObj.useLinkData = val;
|
||||
}
|
||||
this._useLinkedData = val;
|
||||
}
|
||||
|
||||
private _vertexFormatBytes = 0;
|
||||
private _initVDataCount = 0;
|
||||
private _initIDataCount = 0;
|
||||
@@ -193,7 +182,7 @@ export class MeshBuffer {
|
||||
// Initialize the first ia
|
||||
this._iaPool.push(this.createNewIA(device));
|
||||
if (JSB) {
|
||||
this._nativeObj.initialize(device, attrs, vFloatCount, iCount);
|
||||
this._nativeObj.initialize(attrs);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -69,12 +69,10 @@ export declare class NativeUIMeshBuffer {
|
||||
set vData(val: Float32Array);
|
||||
get iData(): Uint16Array;
|
||||
set iData(val: Uint16Array);
|
||||
get useLinkData(): boolean;
|
||||
set useLinkData(val: boolean);
|
||||
|
||||
syncSharedBufferToNative(data: TypedArray);
|
||||
|
||||
initialize(device: Device, attrs: Attribute[], vFloatCount: number, iCount: number);
|
||||
initialize(attrs: Attribute[]);
|
||||
reset();
|
||||
destroy();
|
||||
setDirty();
|
||||
|
||||
@@ -32,7 +32,7 @@ export enum AttrUInt32ArrayView {
|
||||
export enum RenderDrawInfoType {
|
||||
COMP,
|
||||
MODEL,
|
||||
IA,
|
||||
MIDDLEWARE,
|
||||
SUB_NODE,
|
||||
}
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ import { legacyCC } from '../../core/global-exports';
|
||||
import { assertIsTrue } from '../../core/data/utils/asserts';
|
||||
import { CCFloat } from '../../core/data/utils/attribute';
|
||||
import { property } from '../../core/data/class-decorator';
|
||||
import { IInstancedAttributeBlock, SubModel } from '../../core/renderer/scene';
|
||||
|
||||
/**
|
||||
* @en Shadow projection mode.
|
||||
@@ -476,11 +477,15 @@ export class MeshRenderer extends ModelRenderer {
|
||||
if (JSB) {
|
||||
(this.model as any)._setInstancedAttribute(name, value);
|
||||
} else {
|
||||
const { attributes, views } = this.model.instancedAttributes;
|
||||
for (let i = 0; i < attributes.length; i++) {
|
||||
if (attributes[i].name === name) {
|
||||
views[i].set(value);
|
||||
break;
|
||||
const subModels = this.model.subModels;
|
||||
for (let i = 0; i < subModels.length; i++) {
|
||||
const subModel = subModels[i];
|
||||
const { attributes, views } = subModel.instancedAttributeBlock;
|
||||
for (let i = 0; i < attributes.length; i++) {
|
||||
if (attributes[i].name === name) {
|
||||
views[i].set(value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,6 +115,7 @@ export class DirectionalLight extends Light {
|
||||
* @en Whether activate real time shadow.
|
||||
* @zh 是否启用实时阴影?
|
||||
*/
|
||||
@tooltip('i18n:lights.shadowEnabled')
|
||||
@visible(() => (legacyCC.director.root as Root).pipeline.pipelineSceneData.shadows.enabled
|
||||
&& (legacyCC.director.root as Root).pipeline.pipelineSceneData.shadows.type === ShadowType.ShadowMap)
|
||||
@property({ group: { name: 'DynamicShadowSettings', displayOrder: 1 } })
|
||||
@@ -134,6 +135,7 @@ export class DirectionalLight extends Light {
|
||||
* @en The shadow pcf for real time shadow.
|
||||
* @zh 实时阴影计算中的阴影 pcf 等级。
|
||||
*/
|
||||
@tooltip('i18n:lights.shadowPcf')
|
||||
@visible(() => (legacyCC.director.root as Root).pipeline.pipelineSceneData.shadows.enabled
|
||||
&& (legacyCC.director.root as Root).pipeline.pipelineSceneData.shadows.type === ShadowType.ShadowMap)
|
||||
@property({ group: { name: 'DynamicShadowSettings', displayOrder: 5 } })
|
||||
@@ -153,6 +155,7 @@ export class DirectionalLight extends Light {
|
||||
* @en The shadow map sampler offset for real time shadow.
|
||||
* @zh 实时阴影计算中的阴影纹理偏移值。
|
||||
*/
|
||||
@tooltip('i18n:lights.shadowBias')
|
||||
@visible(() => (legacyCC.director.root as Root).pipeline.pipelineSceneData.shadows.enabled
|
||||
&& (legacyCC.director.root as Root).pipeline.pipelineSceneData.shadows.type === ShadowType.ShadowMap)
|
||||
@property({ group: { name: 'DynamicShadowSettings', displayOrder: 6 } })
|
||||
@@ -172,6 +175,7 @@ export class DirectionalLight extends Light {
|
||||
* @en The global normal bias for real time shadow.
|
||||
* @zh 实时阴影计算中的法线偏移。
|
||||
*/
|
||||
@tooltip('i18n:lights.shadowNormalBias')
|
||||
@visible(() => (legacyCC.director.root as Root).pipeline.pipelineSceneData.shadows.enabled
|
||||
&& (legacyCC.director.root as Root).pipeline.pipelineSceneData.shadows.type === ShadowType.ShadowMap)
|
||||
@property({ group: { name: 'DynamicShadowSettings', displayOrder: 7 } })
|
||||
@@ -191,6 +195,7 @@ export class DirectionalLight extends Light {
|
||||
* @en The shadow color saturation for real time shadow.
|
||||
* @zh 实时阴影计算中的阴影颜色饱和度。
|
||||
*/
|
||||
@tooltip('i18n:lights.shadowSaturation')
|
||||
@visible(() => (legacyCC.director.root as Root).pipeline.pipelineSceneData.shadows.enabled
|
||||
&& (legacyCC.director.root as Root).pipeline.pipelineSceneData.shadows.type === ShadowType.ShadowMap)
|
||||
@property({ group: { name: 'DynamicShadowSettings', displayOrder: 8 } })
|
||||
@@ -213,6 +218,7 @@ export class DirectionalLight extends Light {
|
||||
* @en The potential shadow distance from the camera for real time shadow.
|
||||
* @zh 实时阴影计算中潜在阴影产生的范围
|
||||
*/
|
||||
@tooltip('i18n:lights.shadowDistance')
|
||||
@visible(function (this: DirectionalLight) {
|
||||
return (legacyCC.director.root as Root).pipeline.pipelineSceneData.shadows.enabled
|
||||
&& (legacyCC.director.root as Root).pipeline.pipelineSceneData.shadows.type
|
||||
@@ -240,6 +246,7 @@ export class DirectionalLight extends Light {
|
||||
* @en The occlusion range for real time shadow.
|
||||
* @zh 实时阴影计算中剔除阴影的范围
|
||||
*/
|
||||
@tooltip('i18n:lights.shadowInvisibleOcclusionRange')
|
||||
@visible(function (this: DirectionalLight) {
|
||||
return (legacyCC.director.root as Root).pipeline.pipelineSceneData.shadows.enabled
|
||||
&& (legacyCC.director.root as Root).pipeline.pipelineSceneData.shadows.type
|
||||
@@ -286,6 +293,7 @@ export class DirectionalLight extends Light {
|
||||
* @en enable csm
|
||||
* @zh 开启或关闭 csm 模式
|
||||
*/
|
||||
@tooltip('i18n:lights.enableCSM')
|
||||
@visible(function (this: DirectionalLight) {
|
||||
return (legacyCC.director.root as Root).pipeline.pipelineSceneData.shadows.enabled
|
||||
&& (legacyCC.director.root as Root).pipeline.pipelineSceneData.shadows.type
|
||||
@@ -354,6 +362,7 @@ export class DirectionalLight extends Light {
|
||||
* @en Whether to use fixed area shadow in real time shadow.
|
||||
* @zh 实时阴影计算中是否使用固定区域阴影。
|
||||
*/
|
||||
@tooltip('i18n:lights.shadowFixedArea')
|
||||
@visible(() => (legacyCC.director.root as Root).pipeline.pipelineSceneData.shadows.enabled
|
||||
&& (legacyCC.director.root as Root).pipeline.pipelineSceneData.shadows.type === ShadowType.ShadowMap)
|
||||
@property({ group: { name: 'DynamicShadowSettings', displayOrder: 15 } })
|
||||
@@ -373,6 +382,7 @@ export class DirectionalLight extends Light {
|
||||
* @en The near clip plane of the shadow camera for fixed area shadow
|
||||
* @zh 固定区域阴影设置中阴影相机近裁剪面
|
||||
*/
|
||||
@tooltip('i18n:lights.shadowNear')
|
||||
@visible(function (this: DirectionalLight) {
|
||||
return (legacyCC.director.root as Root).pipeline.pipelineSceneData.shadows.enabled
|
||||
&& (legacyCC.director.root as Root).pipeline.pipelineSceneData.shadows.type
|
||||
@@ -395,6 +405,7 @@ export class DirectionalLight extends Light {
|
||||
* @en The far clip plane of the shadow camera for fixed area shadow.
|
||||
* @zh 固定区域阴影设置中阴影相机远裁剪面。
|
||||
*/
|
||||
@tooltip('i18n:lights.shadowFar')
|
||||
@visible(function (this: DirectionalLight) {
|
||||
return (legacyCC.director.root as Root).pipeline.pipelineSceneData.shadows.enabled
|
||||
&& (legacyCC.director.root as Root).pipeline.pipelineSceneData.shadows.type
|
||||
@@ -417,6 +428,7 @@ export class DirectionalLight extends Light {
|
||||
* @en The orthogonal size of the shadow camera for fixed area shadow.
|
||||
* @zh 固定区域阴影设置中阴影相机的正交尺寸
|
||||
*/
|
||||
@tooltip('i18n:lights.shadowOrthoSize')
|
||||
@visible(function (this: DirectionalLight) {
|
||||
return (legacyCC.director.root as Root).pipeline.pipelineSceneData.shadows.enabled
|
||||
&& (legacyCC.director.root as Root).pipeline.pipelineSceneData.shadows.type
|
||||
|
||||
@@ -199,6 +199,7 @@ export class SpotLight extends Light {
|
||||
* @en Whether activate shadow
|
||||
* @zh 是否启用阴影?
|
||||
*/
|
||||
@tooltip('i18n:lights.shadowEnabled')
|
||||
@visible(() => (legacyCC.director.root as Root).pipeline.pipelineSceneData.shadows.type === ShadowType.ShadowMap)
|
||||
@property({ group: { name: 'DynamicShadowSettings', displayOrder: 1 } })
|
||||
@editable
|
||||
@@ -217,6 +218,7 @@ export class SpotLight extends Light {
|
||||
* @en The pcf level of the shadow generation.
|
||||
* @zh 获取或者设置阴影 pcf 等级。
|
||||
*/
|
||||
@tooltip('i18n:lights.shadowPcf')
|
||||
@visible(() => (legacyCC.director.root as Root).pipeline.pipelineSceneData.shadows.type === ShadowType.ShadowMap)
|
||||
@property({ group: { name: 'DynamicShadowSettings', displayOrder: 2 } })
|
||||
@editable
|
||||
@@ -235,6 +237,7 @@ export class SpotLight extends Light {
|
||||
* @en The depth offset of shadow to avoid moire pattern artifacts
|
||||
* @zh 阴影的深度偏移, 可以减弱跨像素导致的条纹状失真
|
||||
*/
|
||||
@tooltip('i18n:lights.shadowBias')
|
||||
@visible(() => (legacyCC.director.root as Root).pipeline.pipelineSceneData.shadows.type === ShadowType.ShadowMap)
|
||||
@property({ group: { name: 'DynamicShadowSettings', displayOrder: 3 } })
|
||||
@editable
|
||||
@@ -253,6 +256,7 @@ export class SpotLight extends Light {
|
||||
* @en The normal bias of the shadow map.
|
||||
* @zh 设置或者获取法线偏移。
|
||||
*/
|
||||
@tooltip('i18n:lights.shadowNormalBias')
|
||||
@visible(() => (legacyCC.director.root as Root).pipeline.pipelineSceneData.shadows.type === ShadowType.ShadowMap)
|
||||
@property({ group: { name: 'DynamicShadowSettings', displayOrder: 4 } })
|
||||
@editable
|
||||
|
||||
@@ -37,6 +37,7 @@ import { IAnimInfo, IJointTextureHandle } from '../skeletal-animation/skeletal-a
|
||||
import { MorphModel } from './morph-model';
|
||||
import { legacyCC } from '../../core/global-exports';
|
||||
import { jointTextureSamplerInfo } from '../misc/joint-texture-sampler-info';
|
||||
import { SubModel } from '../../core/renderer/scene';
|
||||
|
||||
interface IJointsInfo {
|
||||
buffer: Buffer | null;
|
||||
@@ -129,11 +130,19 @@ export class BakedSkinningModel extends MorphModel {
|
||||
super.updateUBOs(stamp);
|
||||
|
||||
const info = this._jointsMedium.animInfo;
|
||||
|
||||
let hasNonInstancingPass = false;
|
||||
const idx = this._instAnimInfoIdx;
|
||||
if (idx >= 0) {
|
||||
const view = this.instancedAttributes.views[idx];
|
||||
view[0] = info.data[0];
|
||||
} else if (info.dirty) {
|
||||
for (let i = 0; i < this._subModels.length; i++) {
|
||||
const subModel = this._subModels[i];
|
||||
if (idx >= 0) {
|
||||
const view = subModel.instancedAttributeBlock.views[idx];
|
||||
view[0] = info.data[0];
|
||||
} else {
|
||||
hasNonInstancingPass = true;
|
||||
}
|
||||
}
|
||||
if (hasNonInstancingPass && info.dirty) {
|
||||
info.buffer.update(info.data);
|
||||
info.dirty = false;
|
||||
}
|
||||
@@ -167,7 +176,7 @@ export class BakedSkinningModel extends MorphModel {
|
||||
} else {
|
||||
texture = resMgr.jointTexturePool.getDefaultPoseTexture(this._skeleton, this._mesh, this.transform);
|
||||
this._jointsMedium.boundsInfo = null;
|
||||
this._modelBounds = texture && texture.bounds.get(this._mesh.hash)![0];
|
||||
this._modelBounds = texture && texture.bounds.get(this._mesh.hash)![0];
|
||||
}
|
||||
this._applyJointTexture(texture);
|
||||
}
|
||||
@@ -204,20 +213,24 @@ export class BakedSkinningModel extends MorphModel {
|
||||
}
|
||||
}
|
||||
|
||||
protected _updateInstancedAttributes (attributes: Attribute[], pass: Pass) {
|
||||
super._updateInstancedAttributes(attributes, pass);
|
||||
this._instAnimInfoIdx = this._getInstancedAttributeIndex(INST_JOINT_ANIM_INFO);
|
||||
protected _updateInstancedAttributes (attributes: Attribute[], subModel: SubModel) {
|
||||
super._updateInstancedAttributes(attributes, subModel);
|
||||
this._instAnimInfoIdx = subModel.getInstancedAttributeIndex(INST_JOINT_ANIM_INFO);
|
||||
this.updateInstancedJointTextureInfo();
|
||||
}
|
||||
|
||||
private updateInstancedJointTextureInfo () {
|
||||
const { jointTextureInfo, animInfo } = this._jointsMedium;
|
||||
const idx = this._instAnimInfoIdx;
|
||||
if (idx >= 0) { // update instancing data too
|
||||
const view = this.instancedAttributes.views[idx];
|
||||
view[0] = animInfo.data[0];
|
||||
view[1] = jointTextureInfo[1];
|
||||
view[2] = jointTextureInfo[2];
|
||||
for (let i = 0; i < this._subModels.length; i++) {
|
||||
const subModel = this._subModels[i];
|
||||
const views = subModel.instancedAttributeBlock.views;
|
||||
if (idx >= 0 && views.length > 0) { // update instancing data too
|
||||
const view = views[idx];
|
||||
view[0] = animInfo.data[0];
|
||||
view[1] = jointTextureInfo[1];
|
||||
view[2] = jointTextureInfo[2];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ import { warnID } from '../../core/platform/debug';
|
||||
import { director } from '../../game';
|
||||
import { PixelFormat } from '../../asset/assets/asset-enum';
|
||||
import { Texture2D, ImageAsset } from '../../asset/assets';
|
||||
import { SubModel } from '../../render-scene';
|
||||
|
||||
const uniformPatches: IMacroPatch[] = [
|
||||
{ name: 'CC_USE_SKINNING', value: true },
|
||||
@@ -264,12 +265,13 @@ export class SkinningModel extends MorphModel {
|
||||
}
|
||||
}
|
||||
|
||||
protected _updateInstancedAttributes (attributes: Attribute[], pass: Pass) {
|
||||
protected _updateInstancedAttributes (attributes: Attribute[], subModel: SubModel) {
|
||||
const pass = subModel.passes[0];
|
||||
if (pass.batchingScheme !== BatchingSchemes.NONE) {
|
||||
// TODO(holycanvas): #9203 better to print the complete path instead of only the current node
|
||||
warnID(3936, this.node.getPathInHierarchy());
|
||||
}
|
||||
super._updateInstancedAttributes(attributes, pass);
|
||||
super._updateInstancedAttributes(attributes, subModel);
|
||||
}
|
||||
|
||||
private _ensureEnoughBuffers (count: number) {
|
||||
|
||||
@@ -28,7 +28,7 @@ import { SpriteFrame } from '../../2d/assets/sprite-frame';
|
||||
import type { ImageSource } from '../assets/image-asset';
|
||||
import assetManager from '../asset-manager/asset-manager';
|
||||
import { BuiltinBundleName } from '../asset-manager/shared';
|
||||
import { TEST } from 'internal:constants';
|
||||
import { TEST, EDITOR } from 'internal:constants';
|
||||
import { Settings, settings } from '../../core/settings';
|
||||
import releaseManager from '../asset-manager/release-manager';
|
||||
|
||||
@@ -118,7 +118,8 @@ builtinResMgrProto.loadBuiltinAssets = function () {
|
||||
assets.forEach((asset) => {
|
||||
resources[asset.name] = asset;
|
||||
const url = asset.nativeUrl;
|
||||
releaseManager.addIgnoredAsset(asset);
|
||||
// In Editor, no need to ignore asset destroy, we use auto gc to handle destroy
|
||||
if (!EDITOR || legacyCC.GAME_VIEW) releaseManager.addIgnoredAsset(asset);
|
||||
this.addAsset(asset.name, asset);
|
||||
if (asset instanceof legacyCC.Material) {
|
||||
this._materialsToBeCompiled.push(asset);
|
||||
|
||||
@@ -331,7 +331,8 @@ class BuiltinResMgr {
|
||||
} else {
|
||||
assets.forEach((asset) => {
|
||||
resources[asset.name] = asset;
|
||||
releaseManager.addIgnoredAsset(asset);
|
||||
// In Editor, no need to ignore asset destroy, we use auto gc to handle destroy
|
||||
if (!EDITOR || legacyCC.GAME_VIEW) { releaseManager.addIgnoredAsset(asset); }
|
||||
if (asset instanceof legacyCC.Material) {
|
||||
this._materialsToBeCompiled.push(asset as Material);
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { EDITOR } from 'internal:constants';
|
||||
import { EDITOR, PREVIEW } from 'internal:constants';
|
||||
import { legacyCC } from '../../core/global-exports';
|
||||
import { warnID } from '../../core/platform/debug';
|
||||
import { js } from '../../core/utils/js';
|
||||
@@ -165,7 +165,7 @@ export function replaceOverrideAsset (task: Task) {
|
||||
const item = input[i] as RequestItem;
|
||||
if (assetsOverrideMap.has(item.uuid)) {
|
||||
const uuid = assetsOverrideMap.get(item.uuid)!;
|
||||
if (EDITOR) {
|
||||
if (EDITOR || PREVIEW) {
|
||||
// In EDITOR, there is no bundle, so just change uuid.
|
||||
item.overrideUuid = uuid;
|
||||
item.ext = item.isNative ? item.ext : '.json';
|
||||
|
||||
@@ -75,6 +75,17 @@ export class AudioSource extends Component {
|
||||
private _isLoaded = false;
|
||||
|
||||
private _lastSetClip: AudioClip | null = null;
|
||||
|
||||
private _resetPlayer () {
|
||||
if (this._player) {
|
||||
audioManager.removePlaying(this._player);
|
||||
this._player.offEnded();
|
||||
this._player.offInterruptionBegin();
|
||||
this._player.offInterruptionEnd();
|
||||
this._player.destroy();
|
||||
this._player = null;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @en
|
||||
* The default AudioClip to be played for this audio source.
|
||||
@@ -101,6 +112,7 @@ export class AudioSource extends Component {
|
||||
}
|
||||
if (!clip) {
|
||||
this._lastSetClip = null;
|
||||
this._resetPlayer();
|
||||
return;
|
||||
}
|
||||
if (!clip._nativeAsset) {
|
||||
@@ -121,13 +133,7 @@ export class AudioSource extends Component {
|
||||
}
|
||||
this._isLoaded = true;
|
||||
// clear old player
|
||||
if (this._player) {
|
||||
audioManager.removePlaying(this._player);
|
||||
this._player.offEnded();
|
||||
this._player.offInterruptionBegin();
|
||||
this._player.offInterruptionEnd();
|
||||
this._player.destroy();
|
||||
}
|
||||
this._resetPlayer();
|
||||
this._player = player;
|
||||
player.onEnded(() => {
|
||||
audioManager.removePlaying(player);
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
Copyright (c) 2020 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
https://www.cocos.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @packageDocumentation
|
||||
* @module gfx
|
||||
*/
|
||||
|
||||
import { legacyCC } from '../global-exports';
|
||||
import { gfx, webgpuAdapter } from '../../webgpu/instantiated';
|
||||
|
||||
import './deprecated-3.0.0';
|
||||
|
||||
export { BlendState, PipelineStateInfo, RasterizerState, DepthStencilState, BlendTarget } from './base/pipeline-state'
|
||||
export * from './base/define';
|
||||
export * from './device-manager';
|
||||
|
||||
|
||||
const polyfillCC: Record<string, unknown> = { ...gfx };
|
||||
polyfillCC.Device = gfx.CCWGPUDevice;
|
||||
polyfillCC.Swapchain = gfx.CCWGPUSwapchain;
|
||||
polyfillCC.Buffer = gfx.CCWGPUBuffer;
|
||||
polyfillCC.Texture = gfx.CCWGPUTexture;
|
||||
polyfillCC.Sampler = gfx.CCWGPUSampler;
|
||||
polyfillCC.Shader = gfx.CCWGPUShader;
|
||||
polyfillCC.InputAssembler = gfx.CCWGPUInputAssembler;
|
||||
polyfillCC.RenderPass = gfx.CCWGPURenderPass;
|
||||
polyfillCC.Framebuffer = gfx.CCWGPUFramebuffer;
|
||||
polyfillCC.DescriptorSet = gfx.CCWGPUDescriptorSet;
|
||||
polyfillCC.DescriptorSetLayout = gfx.CCWGPUDescriptorSetLayout;
|
||||
polyfillCC.PipelineLayout = gfx.CCWGPUPipelineLayout;
|
||||
polyfillCC.PipelineState = gfx.CCWGPUPipelineState;
|
||||
polyfillCC.CommandBuffer = gfx.CCWGPUCommandBuffer;
|
||||
polyfillCC.Queue = gfx.CCWGPUQueue;
|
||||
legacyCC.gfx = polyfillCC;
|
||||
|
||||
export * from './webgpu/override';
|
||||
export * from './webgpu/webgpu-define'
|
||||
|
||||
export const WGPU_WASM = true;
|
||||
|
||||
console.log(gfx.Device);
|
||||
@@ -0,0 +1,56 @@
|
||||
/* eslint-disable @typescript-eslint/no-unused-expressions */
|
||||
/* eslint-disable import/no-mutable-exports */
|
||||
import { WEBGPU } from 'internal:constants';
|
||||
import { gfx, promiseForWebGPUInstantiation } from '../../../webgpu/instantiated';
|
||||
|
||||
export let Device: any;
|
||||
export let WebGPUDevice: any;
|
||||
export let Queue: any;
|
||||
export let Swapchain: any;
|
||||
export let Buffer: any;
|
||||
export let Texture: any;
|
||||
export let Shader: any;
|
||||
export let Sampler: any;
|
||||
export let InputAssembler: any;
|
||||
export let RenderPass: any;
|
||||
export let Framebuffer: any;
|
||||
export let DescriptorSet: any;
|
||||
export let DescriptorSetLayout: any;
|
||||
export let PipelineLayout: any;
|
||||
export let PipelineState: any;
|
||||
export let CommandBuffer: any;
|
||||
export let GeneralBarrier: any;
|
||||
export let TextureBarrier: any;
|
||||
export let BufferBarrier: any;
|
||||
|
||||
WEBGPU && promiseForWebGPUInstantiation.then(() => {
|
||||
Device = gfx.CCWGPUDevice;
|
||||
WebGPUDevice = gfx.CCWGPUDevice;
|
||||
Queue = gfx.CCWGPUQueue;
|
||||
Swapchain = gfx.CCWGPUSwapchain;
|
||||
Buffer = gfx.CCWGPUBuffer;
|
||||
Texture = gfx.CCWGPUTexture;
|
||||
Shader = gfx.CCWGPUShader;
|
||||
Sampler = gfx.CCWGPUSampler;
|
||||
InputAssembler = gfx.CCWGPUInputAssembler;
|
||||
RenderPass = gfx.CCWGPURenderPass;
|
||||
Framebuffer = gfx.CCWGPUFramebuffer;
|
||||
DescriptorSet = gfx.CCWGPUDescriptorSet;
|
||||
DescriptorSetLayout = gfx.CCWGPUDescriptorSetLayout;
|
||||
PipelineLayout = gfx.CCWGPUPipelineLayout;
|
||||
PipelineState = gfx.CCWGPUPipelineState;
|
||||
CommandBuffer = gfx.CCWGPUCommandBuffer;
|
||||
GeneralBarrier = gfx.WGPUGeneralBarrier;
|
||||
TextureBarrier = gfx.WGPUTextureBarrier;
|
||||
BufferBarrier = gfx.WGPUBufferBarrier;
|
||||
|
||||
// immutable excluded
|
||||
[Device, Queue, Swapchain, Buffer, Texture, Shader, InputAssembler, RenderPass, Framebuffer, DescriptorSet,
|
||||
DescriptorSetLayout, PipelineState, CommandBuffer].forEach((ele) => {
|
||||
const oldDestroy = ele.prototype.destroy;
|
||||
ele.prototype.destroy = function () {
|
||||
oldDestroy.call(this);
|
||||
this.delete();
|
||||
};
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,597 @@
|
||||
/* eslint-disable @typescript-eslint/no-unused-expressions */
|
||||
/* eslint-disable max-len */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
||||
/* eslint-disable func-names */
|
||||
/*
|
||||
Copyright (c) 2022 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
https://www.cocos.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { WEBGPU } from 'internal:constants';
|
||||
import { gfx, webgpuAdapter, glslalgWasmModule, promiseForWebGPUInstantiation } from '../../../webgpu/instantiated';
|
||||
import {
|
||||
Texture, CommandBuffer, DescriptorSet, Device, InputAssembler, Buffer, Shader
|
||||
} from './override';
|
||||
import {
|
||||
DeviceInfo, BufferTextureCopy, ShaderInfo, ShaderStageFlagBit, TextureViewInfo, TextureInfo, DrawInfo, BufferViewInfo, BufferInfo,
|
||||
} from '../base/define';
|
||||
|
||||
WEBGPU && promiseForWebGPUInstantiation.then(() => {
|
||||
const originDeviceInitializeFunc = Device.prototype.initialize;
|
||||
Device.prototype.initialize = function (info: DeviceInfo) {
|
||||
const adapter = webgpuAdapter.adapter;
|
||||
const device = webgpuAdapter.device;
|
||||
gfx.preinitializedWebGPUDevice = device;
|
||||
device.lost.then((info) => {
|
||||
console.error('Device was lost.', info);
|
||||
throw new Error('Something bad happened');
|
||||
});
|
||||
console.log(adapter);
|
||||
|
||||
originDeviceInitializeFunc.call(this, info);
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
Device.prototype.flushCommands = function () {
|
||||
};
|
||||
|
||||
const oldCreateTexture = Device.prototype.createTexture;
|
||||
Device.prototype.createTexture = function (info: TextureInfo | TextureViewInfo) {
|
||||
if ('texture' in info) {
|
||||
return this.createTextureView(info);
|
||||
} else {
|
||||
return oldCreateTexture.call(this, info);
|
||||
}
|
||||
};
|
||||
|
||||
const oldCreateBuffer = Device.prototype.createBuffer;
|
||||
Device.prototype.createBuffer = function (info: BufferInfo | BufferViewInfo) {
|
||||
if ('buffer' in info) {
|
||||
return this.createBufferView(info);
|
||||
} else {
|
||||
return oldCreateBuffer.call(this, info);
|
||||
}
|
||||
};
|
||||
|
||||
const oldDraw = CommandBuffer.prototype.draw;
|
||||
CommandBuffer.prototype.draw = function (info: DrawInfo | typeof InputAssembler) {
|
||||
if ('attributesHash' in info) {
|
||||
return this.draw(info.drawInfo);
|
||||
} else {
|
||||
return this.drawByInfo(info);
|
||||
}
|
||||
};
|
||||
|
||||
const oldUpdateBuffer = Buffer.prototype.update;
|
||||
Buffer.prototype.update = function (data: BufferSource, size?: number) {
|
||||
const updateSize = size === undefined ? data.byteLength : size;
|
||||
if ('buffer' in data) {
|
||||
oldUpdateBuffer.call(this, new Uint8Array(data.buffer, data.byteOffset, data.byteLength), updateSize);
|
||||
} else {
|
||||
oldUpdateBuffer.call(this, new Uint8Array(data), updateSize);
|
||||
}
|
||||
};
|
||||
|
||||
const oldCmdUpdateBuffer = CommandBuffer.prototype.updateBuffer;
|
||||
CommandBuffer.prototype.updateBuffer = function (buffer: typeof Buffer, data: BufferSource, size?: number) {
|
||||
const updateSize = size === undefined ? data.byteLength : size;
|
||||
|
||||
if ('buffer' in data) {
|
||||
oldCmdUpdateBuffer.call(this, buffer, new Uint8Array(data.buffer, data.byteOffset, data.byteLength), updateSize);
|
||||
} else {
|
||||
oldCmdUpdateBuffer.call(this, buffer, new Uint8Array(data), updateSize);
|
||||
}
|
||||
};
|
||||
|
||||
const oldBindDescriptorSet = CommandBuffer.prototype.bindDescriptorSet;
|
||||
CommandBuffer.prototype.bindDescriptorSet = function (set: number, descriptorSet: typeof DescriptorSet, dynamicOffsets?: Readonly<number[]>) {
|
||||
if (dynamicOffsets === undefined) {
|
||||
oldBindDescriptorSet.call(this, set, descriptorSet, []);
|
||||
} else if ('buffer' in dynamicOffsets) {
|
||||
oldBindDescriptorSet.call(this, set, descriptorSet, new Uint32Array((dynamicOffsets as any).buffer, (dynamicOffsets as any).byteOffset, (dynamicOffsets as any).byteLength));
|
||||
} else {
|
||||
oldBindDescriptorSet.call(this, set, descriptorSet, new Uint32Array(dynamicOffsets));
|
||||
}
|
||||
};
|
||||
|
||||
const oldCmdCopyBuffersToTexture = CommandBuffer.prototype.copyBuffersToTexture;
|
||||
CommandBuffer.prototype.copyBuffersToTexture = function (buffers: Readonly<ArrayBufferView[]>, texture: typeof Texture, regions: Readonly<BufferTextureCopy[]>) {
|
||||
const ucharBuffers: Uint8Array[] = [];
|
||||
for (let i = 0; i < buffers.length; ++i) {
|
||||
const buffer = buffers[i];
|
||||
if ('buffer' in buffer) {
|
||||
ucharBuffers.push(new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength));
|
||||
} else {
|
||||
ucharBuffers.push(new Uint8Array(buffer as any));
|
||||
}
|
||||
}
|
||||
oldCmdCopyBuffersToTexture.call(this, ucharBuffers, texture, regions);
|
||||
};
|
||||
|
||||
const oldDeviceCopyBuffersToTexture = Device.prototype.copyBuffersToTexture;
|
||||
Device.prototype.copyBuffersToTexture = function (buffers: Readonly<ArrayBufferView[]>, texture: typeof Texture, regions: Readonly<BufferTextureCopy[]>) {
|
||||
const ucharBuffers: Uint8Array[] = [];
|
||||
for (let i = 0; i < buffers.length; ++i) {
|
||||
const buffer = buffers[i];
|
||||
if ('buffer' in buffer) {
|
||||
ucharBuffers.push(new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength));
|
||||
} else {
|
||||
ucharBuffers.push(new Uint8Array(buffer as any));
|
||||
}
|
||||
}
|
||||
oldDeviceCopyBuffersToTexture.call(this, ucharBuffers, texture, regions);
|
||||
};
|
||||
|
||||
Device.prototype.copyTexImagesToTexture = function (texImages: TexImageSource[], texture: typeof Texture, regions: BufferTextureCopy[]) {
|
||||
const buffers: Uint8Array[] = [];
|
||||
for (let i = 0; i < regions.length; i++) {
|
||||
if ('getContext' in texImages[i]) {
|
||||
const canvasElem = texImages[i] as HTMLCanvasElement;
|
||||
const imageData = canvasElem.getContext('2d')?.getImageData(0, 0, texImages[i].width, texImages[i].height);
|
||||
const buff = imageData!.data.buffer;
|
||||
let data;
|
||||
let rawBuffer;
|
||||
if ('buffer' in buff) {
|
||||
// es-lint as any
|
||||
data = new Uint8Array((buff as any).buffer, (buff as any).byteOffset, (buff as any).byteLength);
|
||||
} else {
|
||||
rawBuffer = buff;
|
||||
data = new Uint8Array(rawBuffer);
|
||||
}
|
||||
buffers[i] = data;
|
||||
} else if (texImages[i] instanceof HTMLImageElement) {
|
||||
const img = texImages[i] as HTMLImageElement;
|
||||
const canvas = document.createElement('canvas');
|
||||
canvas.width = img.width;
|
||||
canvas.height = img.height;
|
||||
const ctx = canvas.getContext('2d');
|
||||
ctx?.drawImage(img, 0, 0);
|
||||
const imageData = ctx?.getImageData(0, 0, img.width, img.height);
|
||||
const buff = imageData!.data.buffer;
|
||||
let data;
|
||||
let rawBuffer;
|
||||
if ('buffer' in buff) {
|
||||
// es-lint as any
|
||||
data = new Uint8Array((buff as any).buffer, (buff as any).byteOffset, (buff as any).byteLength);
|
||||
} else {
|
||||
rawBuffer = buff;
|
||||
data = new Uint8Array(rawBuffer);
|
||||
}
|
||||
buffers[i] = data;
|
||||
} else {
|
||||
console.log('imageBmp copy not impled!');
|
||||
}
|
||||
}
|
||||
|
||||
oldDeviceCopyBuffersToTexture.call(this, buffers, texture, regions);
|
||||
};
|
||||
|
||||
function seperateCombinedSamplerTexture (shaderSource: string) {
|
||||
// sampler and texture
|
||||
const samplerTexturArr = shaderSource.match(/(.*?)\(set = \d+, binding = \d+\) uniform(.*?)sampler\w* \w+;/g);
|
||||
const count = samplerTexturArr?.length ? samplerTexturArr?.length : 0;
|
||||
let code = shaderSource;
|
||||
|
||||
const referredFuncMap = new Map<string, [fnName: string, samplerType: string, samplerName: string]>();
|
||||
const samplerSet = new Set<string>();
|
||||
samplerTexturArr?.every((str) => {
|
||||
let textureName = str.match(/(?<=uniform(.*?)sampler\w* )(\w+)(?=;)/g)!.toString();
|
||||
let samplerStr = str.replace(textureName, `${textureName}Sampler`);
|
||||
let samplerFunc = samplerStr.match(/(?<=uniform(.*?))sampler(\w*)/g)!.toString();
|
||||
samplerFunc = samplerFunc.replace('sampler', '');
|
||||
if (samplerFunc === '') {
|
||||
textureName = textureName.replace('Sampler', '');
|
||||
} else {
|
||||
samplerStr = samplerStr.replace(/(?<=uniform(.*?))(sampler\w*)/g, 'sampler');
|
||||
|
||||
// layout (set = a, binding = b) uniform sampler2D cctex;
|
||||
// to:
|
||||
// layout (set = a, binding = b) uniform sampler cctexSampler;
|
||||
// layout (set = a, binding = b + maxTextureNum) uniform texture2D cctex;
|
||||
const samplerReg = /(?<=binding = )(\d+)(?=\))/g;
|
||||
const samplerBindingStr = str.match(samplerReg)!.toString();
|
||||
const samplerBinding = Number(samplerBindingStr) + 16;
|
||||
samplerStr = samplerStr.replace(samplerReg, samplerBinding.toString());
|
||||
|
||||
const textureStr = str.replace(/(?<=uniform(.*?))(sampler)(?=\w*)/g, 'texture');
|
||||
code = code.replace(str, `${textureStr}\n${samplerStr}`);
|
||||
}
|
||||
|
||||
if (!samplerSet.has(`${textureName}Sampler`)) {
|
||||
samplerSet.add(`${textureName}Sampler`);
|
||||
// gathering referred func
|
||||
let referredFuncStr = `([\\w]+)[\\s]*\\([0-9a-zA-Z_\\s,]*?sampler${samplerFunc}[^\\)]+\\)[\\s]*{`;
|
||||
if (samplerFunc === '') {
|
||||
referredFuncStr = `([\\w]+)[\\s]*\\([0-9a-zA-Z_\\s,]*?sampler([\\S]+)[^\\)]+\\)[\\s]*{`;
|
||||
}
|
||||
const referredFuncRe = new RegExp(referredFuncStr, 'g');
|
||||
let reArr = referredFuncRe.exec(code);
|
||||
while (reArr) {
|
||||
// first to see if it's wrapped by #if 0 \n ... \n #ndif
|
||||
let smpFunc = samplerFunc;
|
||||
if (smpFunc === '') {
|
||||
smpFunc = reArr[2];
|
||||
}
|
||||
const searchTarget = code.slice(0, reArr.index);
|
||||
const defValQueue: { str: string, b: boolean, condition: RegExpExecArray }[] = [];
|
||||
let searchIndex = 1;
|
||||
|
||||
while (searchIndex > 0) {
|
||||
let ifIndex = searchTarget.indexOf('#if', searchIndex);
|
||||
let elseIndex = searchTarget.indexOf('#else', searchIndex);
|
||||
let endIndex = searchTarget.indexOf('#endif', searchIndex);
|
||||
|
||||
if (ifIndex === -1 && elseIndex === -1 && endIndex === -1) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (ifIndex === -1) ifIndex = Number.MAX_SAFE_INTEGER;
|
||||
if (elseIndex === -1) elseIndex = Number.MAX_SAFE_INTEGER;
|
||||
if (endIndex === -1) endIndex = Number.MAX_SAFE_INTEGER;
|
||||
|
||||
// next start with '#' is #if(def)
|
||||
if (ifIndex < elseIndex && ifIndex < endIndex) {
|
||||
const ifdef = (new RegExp(`#if(def)?[\\s]+(!)?([\\S]+)([\\s+]?(==)?(!=)[\\s+]?([\\S]+))?`, 'gm')).exec(searchTarget.slice(ifIndex))!;
|
||||
defValQueue[defValQueue.length] = { str: ifdef[3], b: true, condition: ifdef };
|
||||
searchIndex = ifIndex + 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (elseIndex < endIndex && elseIndex < ifIndex) {
|
||||
defValQueue[defValQueue.length - 1].b = false;
|
||||
searchIndex = elseIndex + 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (endIndex < elseIndex && endIndex < ifIndex) {
|
||||
defValQueue.pop();
|
||||
searchIndex = endIndex + 1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
let defCheck = true;
|
||||
for (let i = 0; i < defValQueue.length; i++) {
|
||||
const ifdef = defValQueue[i].condition;
|
||||
let evalRes = false;
|
||||
if (ifdef[1]) {
|
||||
evalRes = !!(new RegExp(`#define[\\s]+${ifdef[3]}`, 'gm')).exec(searchTarget);
|
||||
} else {
|
||||
const defVal = (new RegExp(`#define[\\s]+${ifdef[3]}[\\s]+([\\S]+).*`, 'gm')).exec(searchTarget)![1];
|
||||
if (ifdef[4]) {
|
||||
const conditionVal = ifdef[7];
|
||||
evalRes = ifdef[5] ? defVal === conditionVal : defVal !== conditionVal;
|
||||
} else if (ifdef[3]) {
|
||||
evalRes = (defVal !== '0' && !ifdef[2]);
|
||||
}
|
||||
}
|
||||
|
||||
if (defValQueue[i].b !== evalRes) {
|
||||
defCheck = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const key = `${reArr[1]}_${smpFunc}_${textureName}Sampler`;
|
||||
if (!referredFuncMap.has(key) && defCheck) {
|
||||
referredFuncMap.set(key, [reArr[1], smpFunc, `${textureName}Sampler`]);
|
||||
}
|
||||
reArr = referredFuncRe.exec(code);
|
||||
}
|
||||
}
|
||||
|
||||
// cctex in main() called directly
|
||||
// .*?texture\(
|
||||
const regStr = `texture\\(\\b(${textureName})\\b`;
|
||||
const re = new RegExp(regStr);
|
||||
let reArr = re.exec(code);
|
||||
while (reArr) {
|
||||
code = code.replace(re, `texture(sampler${samplerFunc}(${textureName},${textureName}Sampler)`);
|
||||
reArr = re.exec(code);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
const functionTemplates = new Map<string, string>();
|
||||
const functionDeps = new Map<string, string[]>();
|
||||
let forwardDecls = '';
|
||||
// function
|
||||
referredFuncMap.forEach((pair) => {
|
||||
//pre: if existed, replace
|
||||
//getVec3DisplacementFromTexture\(cc_TangentDisplacements[^\\n]+
|
||||
const textureStr = pair[2].slice(0, -7);
|
||||
const codePieceStr = `${pair[0]}\\((.*?)${textureStr}[^\\n]+`;
|
||||
const codePieceRe = new RegExp(codePieceStr);
|
||||
let res = codePieceRe.exec(code);
|
||||
while (res) {
|
||||
let replaceStr = res[0].replace(`${pair[0]}(`, `${pair[0]}_${pair[1]}_${pair[2]}_specialized(`);
|
||||
replaceStr = replaceStr.replace(`${textureStr},`, '');
|
||||
code = code.replace(codePieceRe, replaceStr);
|
||||
res = codePieceRe.exec(code);
|
||||
}
|
||||
|
||||
// 1. fn definition
|
||||
const fnDeclReStr = `[\\n|\\W][\\w]+[\\W]+${pair[0]}[\\s]*\\((.*?)sampler${pair[1]}[^{]+`;
|
||||
const fnDeclRe = new RegExp(fnDeclReStr);
|
||||
const fnDecl = fnDeclRe.exec(code);
|
||||
|
||||
let redefFunc = '';
|
||||
if (!functionTemplates.has(`${pair[0]}_${pair[1]}`)) {
|
||||
const funcBodyStart = code.slice(fnDecl!.index);
|
||||
|
||||
const funcRedefine = (funcStr: string) => {
|
||||
const samplerType = `sampler${pair[1]}`;
|
||||
const textureRe = (new RegExp(`.*?${samplerType}[\\s]+([\\S]+)[,\\)]`)).exec(funcStr)!;
|
||||
const textureName = textureRe[1];
|
||||
const paramReStr = `${samplerType}[\\s]+${textureName}`;
|
||||
let funcDef = funcStr.replace(new RegExp(paramReStr), `texture${pair[1]} ${textureName}`);
|
||||
funcDef = funcDef.replace(pair[0], `${pair[0]}SAMPLER_SPEC`);
|
||||
// 2. texture(...) inside, builtin funcs
|
||||
const textureOpArr = ['texture', 'textureSize', 'texelFetch', 'textureLod'];
|
||||
for (let i = 0; i < textureOpArr.length; i++) {
|
||||
const texFuncReStr = `(${textureOpArr[i]})\\(${textureName},`;
|
||||
const texFuncRe = new RegExp(texFuncReStr, 'g');
|
||||
funcDef = funcDef.replace(texFuncRe, `$1(${samplerType}(${textureName}TEXTURE_HOLDER, ${textureName}SAMPLER_HOLDER),`);
|
||||
}
|
||||
return funcDef;
|
||||
};
|
||||
|
||||
const firstIfStatement = funcBodyStart.indexOf('#if');
|
||||
const firstElseStatement = funcBodyStart.indexOf('#e'); //#endif, #else, #elif maybe?
|
||||
if ((firstElseStatement !== -1 && firstIfStatement > firstElseStatement) || (firstElseStatement === -1 && firstElseStatement !== -1)) { // ooops, now func body starts in a #if statement.
|
||||
let startIndex = 0;
|
||||
let count = 1; // already in #if
|
||||
while (count > 0 && startIndex < funcBodyStart.length) {
|
||||
const nextSymbolIdx = funcBodyStart.indexOf('#', startIndex);
|
||||
const startSliceIdx = startIndex === 0 ? startIndex : startIndex - 1;
|
||||
if (funcBodyStart[nextSymbolIdx + 1] === 'i') { // #if
|
||||
count++;
|
||||
redefFunc += funcBodyStart.slice(startSliceIdx, nextSymbolIdx);
|
||||
} else if (funcBodyStart[nextSymbolIdx + 1] === 'e' && funcBodyStart[nextSymbolIdx + 2] === 'l') { //#elif, #else
|
||||
if (count === 1) {
|
||||
const tempFuncStr = funcBodyStart.slice(startSliceIdx, nextSymbolIdx - 1);
|
||||
const funcDefStr = funcRedefine(tempFuncStr);
|
||||
redefFunc += `\n${funcDefStr}`;
|
||||
} else {
|
||||
redefFunc += `\n${funcBodyStart.slice(startSliceIdx, nextSymbolIdx)}`;
|
||||
}
|
||||
} else if (funcBodyStart[nextSymbolIdx + 1] === 'e' && funcBodyStart[nextSymbolIdx + 2] === 'n') { //#endif
|
||||
count--;
|
||||
if (count === 0) {
|
||||
const tempFuncStr = funcBodyStart.slice(startSliceIdx, nextSymbolIdx - 1);
|
||||
const funcDefStr = funcRedefine(tempFuncStr);
|
||||
redefFunc += `\n${funcDefStr}`;
|
||||
} else {
|
||||
redefFunc += `\n${funcBodyStart.slice(startSliceIdx, nextSymbolIdx)}`;
|
||||
}
|
||||
} else { // #define, dont care
|
||||
redefFunc += funcBodyStart.slice(startSliceIdx, nextSymbolIdx);
|
||||
}
|
||||
startIndex = nextSymbolIdx + 1;
|
||||
}
|
||||
|
||||
//`(?:.(?!layout))+${pair[2]};`
|
||||
const searchTarget = code.slice(0, fnDecl!.index);
|
||||
const res = (new RegExp(`#if.+[\\s]*$`)).exec(searchTarget);
|
||||
redefFunc = `${res![0]}${redefFunc}\n#endif`;
|
||||
} else {
|
||||
let count = 0;
|
||||
let matchBegin = false;
|
||||
let startIndex = 0;
|
||||
let endIndex = 0;
|
||||
for (let i = 0; i < funcBodyStart.length; ++i) {
|
||||
if (funcBodyStart[i] === '{') {
|
||||
++count;
|
||||
if (!matchBegin) {
|
||||
matchBegin = true;
|
||||
startIndex = i;
|
||||
}
|
||||
} else if (funcBodyStart[i] === '}') {
|
||||
--count;
|
||||
}
|
||||
|
||||
if (matchBegin && count === 0) {
|
||||
endIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
const rawFunc = `${fnDecl![0]}${funcBodyStart.slice(startIndex, endIndex + 1)}`;
|
||||
redefFunc = funcRedefine(rawFunc);
|
||||
}
|
||||
|
||||
functionTemplates.set(`${pair[0]}_${pair[1]}`, redefFunc);
|
||||
} else {
|
||||
redefFunc = functionTemplates.get(`${pair[0]}_${pair[1]}`)!;
|
||||
}
|
||||
|
||||
const depsFuncs: string[] = [];
|
||||
|
||||
const iterator = referredFuncMap.values();
|
||||
let val = iterator.next().value;
|
||||
while (val) {
|
||||
const funcDepReStr = `\\b(${val[0] as string})\\b`;
|
||||
if (redefFunc.search(funcDepReStr) !== -1) {
|
||||
depsFuncs[depsFuncs.length] = val[0];
|
||||
}
|
||||
val = iterator.next().value;
|
||||
}
|
||||
// for (let i = 0; i < referredFuncMap.values.length; ++i) {
|
||||
// const funcDepReStr = `\\b(${referredFuncMap.values[i].fnName as string})\\b`;
|
||||
// if (redefFunc.search(funcDepReStr) !== -1) {
|
||||
// depsFuncs[depsFuncs.length] = referredFuncMap.values[i].fnName;
|
||||
// }
|
||||
// }
|
||||
functionDeps.set(`${pair[0]}_${pair[1]}`, depsFuncs);
|
||||
|
||||
const specializedFuncs = new Map<string, string>();
|
||||
const specialize = (funcs: string[]) => {
|
||||
funcs.every((str) => {
|
||||
if (!specializedFuncs.has(`${pair[0]}_${pair[2]}_specialized`)) {
|
||||
const samplerReStr = `(\\w+)SAMPLER_HOLDER`;
|
||||
const textureName = pair[2].slice(0, pair[2].length - 7); // xxxxSampler
|
||||
const textureStr = `(\\w+)TEXTURE_HOLDER`;
|
||||
let funcTemplate = functionTemplates.get(str);
|
||||
funcTemplate = funcTemplate!.replace(new RegExp(samplerReStr, 'g'), pair[2]);
|
||||
funcTemplate = funcTemplate.replace(new RegExp(textureStr, 'g'), textureName);
|
||||
funcTemplate = funcTemplate.replace(new RegExp('SAMPLER_SPEC', 'g'), `_${pair[1]}_${pair[2]}_specialized`);
|
||||
funcTemplate = funcTemplate.replace(new RegExp(`texture${pair[1]}\\s+\\w+,`, 'g'), '');
|
||||
// funcTemplate = funcTemplate.replace('SAMPLER_SPEC', `_${pair[2]}_specialized`);
|
||||
|
||||
for (let i = 0; i < depsFuncs.length; ++i) {
|
||||
const depFuncStr = `${depsFuncs[i]}([\\W]?)*\\([^,)]+(,)?`;
|
||||
funcTemplate = funcTemplate.replace(new RegExp(depFuncStr, 'g'), `${depsFuncs[i]}_${pair[1]}_${pair[2]}_specialized(`);
|
||||
}
|
||||
|
||||
let declStr = fnDecl![0].replace(pair[0], `${str}_${pair[2]}_specialized`);
|
||||
declStr = declStr.replace(new RegExp(`sampler${pair[1]}[^,)]+(,)?`, 'g'), ``);
|
||||
declStr += `;`;
|
||||
specializedFuncs.set(declStr, funcTemplate);
|
||||
} else {
|
||||
return specialize(functionDeps.get(str)!);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
return true;
|
||||
};
|
||||
specialize([`${pair[0]}_${pair[1]}`]);
|
||||
//(?:.(?!layout))+cc_PositionDisplacementsSampler;
|
||||
const samplerDefReStr = `(?:.(?!layout))+${pair[2]};`;
|
||||
const samplerDef = (new RegExp(samplerDefReStr)).exec(code);
|
||||
|
||||
let funcImpls = '';
|
||||
for (const [key, value] of specializedFuncs) {
|
||||
forwardDecls += `\n${key}\n`;
|
||||
funcImpls += `\n${value}\n`;
|
||||
}
|
||||
|
||||
code = code.replace(samplerDef![0], `${samplerDef![0]}\n${funcImpls}`);
|
||||
});
|
||||
|
||||
// some function appears before it's defined so forward declaration is needed
|
||||
forwardDecls += '\nvec3 SRGBToLinear (vec3 gamma);\nfloat getDisplacementWeight(int index);\n';
|
||||
|
||||
const highpIdx = code.indexOf('precision highp');
|
||||
const mediumpIdx = code.indexOf('precision mediump');
|
||||
const lowpIdx = code.indexOf('precision lowp');
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// isNan, isInf has been removed in dawn:tint
|
||||
|
||||
let functionDefs = '';
|
||||
const precisionKeyWord = 'highp';
|
||||
|
||||
// const getPrecision = (idx: number) => {
|
||||
// if (highpIdx !== -1 && highpIdx < idx) {
|
||||
// precisionKeyWord = 'highp';
|
||||
// } else if (mediumpIdx !== -1 && mediumpIdx < idx && highpIdx < mediumpIdx) {
|
||||
// precisionKeyWord = 'mediump';
|
||||
// } else if (lowpIdx !== -1 && lowpIdx < idx && mediumpIdx < lowpIdx && highpIdx < lowpIdx) {
|
||||
// precisionKeyWord = 'lowp';
|
||||
// }
|
||||
// };
|
||||
|
||||
const isNanIndex = code.indexOf('isnan');
|
||||
if (isNanIndex !== -1) {
|
||||
// getPrecision(isNanIndex);
|
||||
functionDefs += `\n
|
||||
bool isNan(${precisionKeyWord} float val) {
|
||||
return (val < 0.0 || 0.0 < val || val == 0.0) ? false : true;
|
||||
}
|
||||
\n`;
|
||||
code = code.replace(/isnan\(/gi, 'isNan(');
|
||||
}
|
||||
|
||||
const isInfIndex = code.indexOf('isinf');
|
||||
if (isInfIndex !== -1) {
|
||||
// getPrecision(isInfIndex);
|
||||
functionDefs += `\n
|
||||
bool isInf(${precisionKeyWord} float x) {
|
||||
return x == x * 2.0 && x != 0.0;
|
||||
}
|
||||
\n`;
|
||||
code = code.replace(/isinf\(/gi, 'isInf(');
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
let firstPrecisionIdx = code.indexOf('precision');
|
||||
firstPrecisionIdx = code.indexOf(';', firstPrecisionIdx);
|
||||
firstPrecisionIdx += 1;
|
||||
code = `${code.slice(0, firstPrecisionIdx)}\n${forwardDecls}\n${functionDefs}\n${code.slice(firstPrecisionIdx)}`;
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
const createShader = Device.prototype.createShader;
|
||||
Device.prototype.createShader = function (shaderInfo: ShaderInfo) {
|
||||
const spvDatas: any = [];
|
||||
for (let i = 0; i < shaderInfo.stages.length; ++i) {
|
||||
shaderInfo.stages[i].source = seperateCombinedSamplerTexture(shaderInfo.stages[i].source);
|
||||
const stageStr = shaderInfo.stages[i].stage === ShaderStageFlagBit.VERTEX ? 'vertex'
|
||||
: shaderInfo.stages[i].stage === ShaderStageFlagBit.FRAGMENT ? 'fragment' : 'compute';
|
||||
const sourceCode = `#version 450\n${shaderInfo.stages[i].source}`;
|
||||
const spv = glslalgWasmModule.glslang.compileGLSL(sourceCode, stageStr, true, '1.3');
|
||||
spvDatas.push(spv);
|
||||
}
|
||||
|
||||
const shader = this.createShaderNative(shaderInfo, spvDatas);
|
||||
return shader;
|
||||
};
|
||||
|
||||
// if property being frequently get in TS, try cache it
|
||||
// attention: invalid if got this object from a native object,
|
||||
// eg. inputAssembler.indexBuffer.objectID
|
||||
function cacheReadOnlyWGPUProperties<T> (type: T, props: string[]) {
|
||||
const descriptor = { writable: true };
|
||||
props.map((prop) => {
|
||||
return Object.defineProperty(type['prototype'], `_${prop}`, descriptor);
|
||||
});
|
||||
|
||||
// trick for emscripten object only, which contains a `name` indicates what type it is.
|
||||
const typename = type['name'].replace('CCWGPU', '');
|
||||
const oldCreate = Device.prototype[`create${typename}`];
|
||||
Device.prototype[`create${typename}`] = function (info) {
|
||||
const res = oldCreate.call(this, info);
|
||||
for (let prop of props) {
|
||||
res[`_${prop}`] = res[`${prop}`];
|
||||
Object.defineProperty(res, `${prop}`, {
|
||||
get () {
|
||||
return this[`_${prop}`];
|
||||
}
|
||||
});
|
||||
}
|
||||
return res;
|
||||
}
|
||||
const oldInit = type['prototype']['initialize'];
|
||||
type['prototype']['initialize'] = function (info) {
|
||||
oldInit.call(this, info);
|
||||
for (let prop of props) {
|
||||
this[`_${prop}`] = this[`${prop}`];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
cacheReadOnlyWGPUProperties(Buffer, ['objectID']);
|
||||
|
||||
});
|
||||
@@ -47,7 +47,7 @@ if (DEV) {
|
||||
legacyCC._Test = {};
|
||||
}
|
||||
|
||||
const engineVersion = '3.6.1';
|
||||
const engineVersion = '3.6.2';
|
||||
|
||||
/**
|
||||
* The current version of Cocos2d being used.<br/>
|
||||
|
||||
+77
-16
@@ -29,7 +29,8 @@ import { ValueType } from '../value-types/value-type';
|
||||
import { IColorLike } from './type-define';
|
||||
import { clamp, EPSILON } from './utils';
|
||||
import { legacyCC } from '../global-exports';
|
||||
import { mixin } from '../utils/js-typed';
|
||||
import { assertIsTrue } from '../data/utils/asserts';
|
||||
import { Vec4 } from './vec4';
|
||||
|
||||
const toFloat = 1 / 255;
|
||||
|
||||
@@ -88,7 +89,41 @@ export class Color extends ValueType {
|
||||
out.a = a;
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Convert 8bit color to Vec4
|
||||
* @zh 将当前颜色转换为到 Vec4
|
||||
* @returns Vec4 as float color value
|
||||
* @example
|
||||
* ```
|
||||
* const color = Color.YELLOW;
|
||||
* color.toVec4();
|
||||
* ```
|
||||
*/
|
||||
public static toVec4 (color:Color, out?: Vec4): Vec4 {
|
||||
out = out !== undefined ? out : new Vec4();
|
||||
out.x = srgb8BitToLinear(color.r);
|
||||
out.y = srgb8BitToLinear(color.g);
|
||||
out.z = srgb8BitToLinear(color.b);
|
||||
out.w = srgb8BitToLinear(color.a);
|
||||
return out;
|
||||
}
|
||||
/**
|
||||
* @en Set 8bit Color from Vec4
|
||||
* @zh 使用 Vec4 设置 8 bit 颜色
|
||||
* @returns 8 Bit srgb value
|
||||
* @example
|
||||
* ```
|
||||
* color.fromVec4(new Vec4(1,1,1,1));
|
||||
* ```
|
||||
*/
|
||||
public static fromVec4 (value: Vec4, out?: Color): Color {
|
||||
out = out === undefined ? new Color() : out;
|
||||
out.r = linearToSrgb8Bit(value.x);
|
||||
out.g = linearToSrgb8Bit(value.y);
|
||||
out.b = linearToSrgb8Bit(value.z);
|
||||
out.a = linearToSrgb8Bit(value.w);
|
||||
return out;
|
||||
}
|
||||
/**
|
||||
* @en Converts the hexadecimal formal color into rgb formal and save the results to out color.
|
||||
* @zh 从十六进制颜色字符串中读入颜色到 out 中
|
||||
@@ -382,11 +417,7 @@ export class Color extends ValueType {
|
||||
* @returns A string representation of the current color.
|
||||
*/
|
||||
public toString () {
|
||||
return `rgba(${
|
||||
this.r.toFixed()}, ${
|
||||
this.g.toFixed()}, ${
|
||||
this.b.toFixed()}, ${
|
||||
this.a.toFixed()})`;
|
||||
return `rgba(${this.r.toFixed()}, ${this.g.toFixed()}, ${this.b.toFixed()}, ${this.a.toFixed()})`;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -406,16 +437,9 @@ export class Color extends ValueType {
|
||||
*/
|
||||
public toCSS (opt: ('rgba' | 'rgb' | '#rrggbb' | '#rrggbbaa') = 'rgba') {
|
||||
if (opt === 'rgba') {
|
||||
return `rgba(${
|
||||
this.r},${
|
||||
this.g},${
|
||||
this.b},${
|
||||
(this.a * toFloat).toFixed(2)})`;
|
||||
return `rgba(${this.r},${this.g},${this.b},${(this.a * toFloat).toFixed(2)})`;
|
||||
} else if (opt === 'rgb') {
|
||||
return `rgb(${
|
||||
this.r},${
|
||||
this.g},${
|
||||
this.b})`;
|
||||
return `rgb(${this.r},${this.g},${this.b})`;
|
||||
} else {
|
||||
return `#${this.toHEX(opt)}`;
|
||||
}
|
||||
@@ -519,6 +543,9 @@ export class Color extends ValueType {
|
||||
const q = v * (1 - (s * f));
|
||||
const t = v * (1 - (s * (1 - f)));
|
||||
switch (i) {
|
||||
default:
|
||||
assertIsTrue(false);
|
||||
// eslint-disable-next-line no-fallthrough
|
||||
case 0:
|
||||
r = v;
|
||||
g = t;
|
||||
@@ -691,3 +718,37 @@ export function color (r?: number | Color | string, g?: number, b?: number, a?:
|
||||
}
|
||||
|
||||
legacyCC.color = color;
|
||||
|
||||
export function srgbToLinear (x: number): number {
|
||||
if (x <= 0) return 0;
|
||||
else if (x >= 1) return 1;
|
||||
else if (x < 0.04045) return x / 12.92;
|
||||
else return ((x + 0.055) / 1.055) ** 2.4;
|
||||
}
|
||||
|
||||
export function srgb8BitToLinear (x: number): number {
|
||||
if ((x | 0) !== x || (x >>> 8) !== 0) { throw new RangeError('Value out of 8-bit range'); }
|
||||
return SRGB_8BIT_TO_LINEAR[x];
|
||||
}
|
||||
|
||||
export function linearToSrgb (x: number): number {
|
||||
if (x <= 0) return 0;
|
||||
else if (x >= 1) return 1;
|
||||
else if (x < 0.0031308) return x * 12.92;
|
||||
else return x ** (1 / 2.4) * 1.055 - 0.055;
|
||||
}
|
||||
|
||||
export function linearToSrgb8Bit (x: number): number {
|
||||
if (x <= 0) { return 0; }
|
||||
const TABLE: Array<number> = SRGB_8BIT_TO_LINEAR;
|
||||
if (x >= 1) { return TABLE.length - 1; }
|
||||
let y = 0;
|
||||
for (let i = TABLE.length >>> 1; i !== 0; i >>>= 1) {
|
||||
if (TABLE[y | i] <= x) { y |= i; }
|
||||
}
|
||||
if (x - TABLE[y] <= TABLE[y + 1] - x) { return y; } else { return y + 1; }
|
||||
}
|
||||
|
||||
// use table for more consistent conversion between uint8 and float, offline processes only.
|
||||
let SRGB_8BIT_TO_LINEAR: Array<number> = [];
|
||||
for (let i = 0; i < 256; i++) { SRGB_8BIT_TO_LINEAR.push(srgbToLinear(i / 255.0)); }
|
||||
|
||||
@@ -44,7 +44,7 @@ import { ArmatureSystem } from './ArmatureSystem';
|
||||
import { Batcher2D } from '../2d/renderer/batcher-2d';
|
||||
import { RenderEntity, RenderEntityType } from '../2d/renderer/render-entity';
|
||||
import { RenderDrawInfo } from '../2d/renderer/render-draw-info';
|
||||
import { Material, Texture2D } from '../asset/assets';
|
||||
import { Material, Texture2D, builtinResMgr } from '../asset/assets';
|
||||
import { Node } from '../scene-graph';
|
||||
|
||||
enum DefaultArmaturesEnum {
|
||||
@@ -392,6 +392,20 @@ export class ArmatureDisplay extends UIRenderer {
|
||||
this._updateDebugDraw();
|
||||
}
|
||||
|
||||
/*
|
||||
* @en Enabled batch model, if mesh is complex, do not enable batch, or will lower performance.
|
||||
* @zh 开启合批,如果渲染大量相同纹理,且结构简单的龙骨动画,开启合批可以降低drawcall,否则请不要开启,cpu消耗会上升。
|
||||
*/
|
||||
@tooltip('i18n:COMPONENT.dragon_bones.enabled_batch')
|
||||
@editable
|
||||
get enableBatch () { return this._enableBatch; }
|
||||
set enableBatch (value) {
|
||||
if (value !== this._enableBatch) {
|
||||
this._enableBatch = value;
|
||||
this._updateBatch();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @en
|
||||
* The bone sockets this animation component maintains.<br>
|
||||
@@ -446,6 +460,10 @@ export class ArmatureDisplay extends UIRenderer {
|
||||
|
||||
@serializable
|
||||
protected _debugBones = false;
|
||||
|
||||
@serializable
|
||||
protected _enableBatch = false;
|
||||
|
||||
/* protected */ _debugDraw: Graphics | null = null;
|
||||
|
||||
// DragonBones data store key.
|
||||
@@ -573,20 +591,29 @@ export class ArmatureDisplay extends UIRenderer {
|
||||
super.destroyRenderData();
|
||||
}
|
||||
|
||||
private getMaterialTemplate () : Material {
|
||||
let material = this.customMaterial;
|
||||
if (material === null) {
|
||||
material = builtinResMgr.get<Material>('default-spine-material');
|
||||
}
|
||||
return material;
|
||||
}
|
||||
|
||||
public getMaterialForBlend (src: BlendFactor, dst: BlendFactor): MaterialInstance {
|
||||
const key = `${src}/${dst}`;
|
||||
let inst = this._materialCache[key];
|
||||
if (inst) {
|
||||
return inst;
|
||||
}
|
||||
const material = this.getMaterial(0)!;
|
||||
const material = this.getMaterialTemplate();
|
||||
const matInfo = {
|
||||
parent: material,
|
||||
subModelIdx: 0,
|
||||
owner: this,
|
||||
};
|
||||
|
||||
inst = new MaterialInstance(matInfo);
|
||||
inst.recompileShaders({ USE_LOCAL: true }, 0); // TODO: not supported by ui
|
||||
inst.recompileShaders({ TWO_COLORED: false, USE_LOCAL: false });
|
||||
this._materialCache[key] = inst;
|
||||
inst.overridePipelineStates({
|
||||
blendState: {
|
||||
@@ -613,6 +640,7 @@ export class ArmatureDisplay extends UIRenderer {
|
||||
}
|
||||
|
||||
protected _render (batcher: Batcher2D) {
|
||||
let indicesCount = 0;
|
||||
if (this.renderData && this._drawList) {
|
||||
const rd = this.renderData;
|
||||
const chunk = rd.chunk;
|
||||
@@ -620,20 +648,17 @@ export class ArmatureDisplay extends UIRenderer {
|
||||
const meshBuffer = rd.getMeshBuffer()!;
|
||||
const origin = meshBuffer.indexOffset;
|
||||
// Fill index buffer
|
||||
accessor.appendIndices(chunk.bufferId, rd.indices!);
|
||||
for (let i = 0; i < this._drawList.length; i++) {
|
||||
this._drawIdx = i;
|
||||
const dc = this._drawList.data[i];
|
||||
if (dc.texture) {
|
||||
// Construct IA
|
||||
const ia = meshBuffer.requireFreeIA(batcher.device);
|
||||
ia.firstIndex = origin + dc.indexOffset;
|
||||
ia.indexCount = dc.indexCount;
|
||||
// Commit IA
|
||||
batcher.commitIA(this, ia, dc.texture, dc.material!, this.node);
|
||||
batcher.commitMiddleware(this, meshBuffer, origin + dc.indexOffset,
|
||||
dc.indexCount, dc.texture, dc.material!, this._enableBatch);
|
||||
}
|
||||
indicesCount += dc.indexCount;
|
||||
}
|
||||
// this.node._static = true;
|
||||
const subIndices = rd.indices!.subarray(0, indicesCount);
|
||||
accessor.appendIndices(chunk.bufferId, subIndices);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -874,6 +899,11 @@ export class ArmatureDisplay extends UIRenderer {
|
||||
this.markForUpdateRenderData();
|
||||
}
|
||||
|
||||
protected _updateBatch () {
|
||||
this._cleanMaterialCache();
|
||||
this.markForUpdateRenderData();
|
||||
}
|
||||
|
||||
_buildArmature () {
|
||||
if (!this.dragonAsset || !this.dragonAtlasAsset || !this.armatureName) return;
|
||||
|
||||
@@ -1341,7 +1371,7 @@ export class ArmatureDisplay extends UIRenderer {
|
||||
|
||||
protected createRenderEntity () {
|
||||
const renderEntity = new RenderEntity(RenderEntityType.DYNAMIC);
|
||||
renderEntity.setUseLocal(true);
|
||||
renderEntity.setUseLocal(false);
|
||||
return renderEntity;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
*/
|
||||
|
||||
import { Armature, BlendMode } from '@cocos/dragonbones-js';
|
||||
import { Color, Mat4 } from '../../core';
|
||||
import { Color, Mat4, Vec3 } from '../../core';
|
||||
import { BlendFactor } from '../../gfx';
|
||||
import { vfmtPosUvColor } from '../../2d/renderer/vertex-format';
|
||||
import { MaterialInstance } from '../../render-scene/core/material-instance';
|
||||
@@ -77,18 +77,10 @@ let _prevDrawIndexOffset = 0;
|
||||
const LOCAL_FLOAT_PER_VERTEX = 4; //xyuv
|
||||
const PER_VERTEX_SIZE = 3 + 2 + 4; //xyz-uv-rgba;
|
||||
|
||||
let _x: number;
|
||||
let _y: number;
|
||||
const _c = new Float32Array(4);
|
||||
let _handleVal: number;
|
||||
let _m00: number;
|
||||
let _m04: number;
|
||||
let _m12: number;
|
||||
let _m01: number;
|
||||
let _m05: number;
|
||||
let _m13: number;
|
||||
const _tempVecPos = new Vec3(0, 0, 0);
|
||||
const _slotMat = new Mat4();
|
||||
let _batcher: Batcher2D;
|
||||
|
||||
let _currentMaterial: MaterialInstance | null = null;
|
||||
let _currentTexture: Texture2D | null = null;
|
||||
@@ -274,20 +266,17 @@ function realTimeTraverse (armature: Armature, parentOpacity: number, worldMat?:
|
||||
}
|
||||
}
|
||||
|
||||
_m00 = _slotMat.m00;
|
||||
_m04 = _slotMat.m04;
|
||||
_m12 = _slotMat.m12;
|
||||
_m01 = _slotMat.m01;
|
||||
_m05 = _slotMat.m05;
|
||||
_m13 = _slotMat.m13;
|
||||
// vertext format:
|
||||
// x y z u v r g b a
|
||||
for (let vi = 0, vl = vertices.length, v = _vertexFloatOffset; vi < vl; v += PER_VERTEX_SIZE) {
|
||||
_x = vertices[vi++];
|
||||
_y = vertices[vi++];
|
||||
_tempVecPos.x = vertices[vi++];
|
||||
_tempVecPos.y = vertices[vi++];
|
||||
_tempVecPos.z = 0;
|
||||
_tempVecPos.transformMat4(_slotMat);
|
||||
|
||||
_vbuf[v] = _x * _m00 + _y * _m04 + _m12; // x
|
||||
_vbuf[v + 1] = _x * _m01 + _y * _m05 + _m13; // y
|
||||
_vbuf[v] = _tempVecPos.x;
|
||||
_vbuf[v + 1] = _tempVecPos.y;
|
||||
_vbuf[v + 2] = _tempVecPos.z;
|
||||
|
||||
_vbuf[v + 3] = vertices[vi++]; // u
|
||||
_vbuf[v + 4] = vertices[vi++]; // v
|
||||
@@ -332,14 +321,6 @@ function cacheTraverse (frame: ArmatureFrame | null, parentMat?: Mat4) {
|
||||
let frameVFOffset = 0;
|
||||
let frameIndexOffset = 0;
|
||||
let segVFCount = 0;
|
||||
if (parentMat) {
|
||||
_m00 = parentMat.m00;
|
||||
_m01 = parentMat.m01;
|
||||
_m04 = parentMat.m04;
|
||||
_m05 = parentMat.m05;
|
||||
_m12 = parentMat.m12;
|
||||
_m13 = parentMat.m13;
|
||||
}
|
||||
|
||||
let colorOffset = 0;
|
||||
const colors = frame.colors;
|
||||
@@ -385,10 +366,13 @@ function cacheTraverse (frame: ArmatureFrame | null, parentMat?: Mat4) {
|
||||
let offset = 0;
|
||||
if (parentMat) {
|
||||
for (let ii = 0, il = _vertexCount; ii < il; ii++) {
|
||||
_x = vbuf[offset];
|
||||
_y = vbuf[offset + 1];
|
||||
vbuf[offset] = _x * _m00 + _y * _m04 + _m12;
|
||||
vbuf[offset + 1] = _x * _m01 + _y * _m05 + _m13;
|
||||
_tempVecPos.x = vbuf[offset];
|
||||
_tempVecPos.y = vbuf[offset + 1];
|
||||
_tempVecPos.z = 0;
|
||||
_tempVecPos.transformMat4(parentMat);
|
||||
vbuf[offset] = _tempVecPos.x;
|
||||
vbuf[offset + 1] = _tempVecPos.y;
|
||||
vbuf[offset + 2] = _tempVecPos.z;
|
||||
offset += PER_VERTEX_SIZE;
|
||||
}
|
||||
}
|
||||
@@ -445,7 +429,7 @@ function updateComponentRenderData (comp: ArmatureDisplay, batcher: Batcher2D) {
|
||||
_handleVal |= NEED_COLOR;
|
||||
}
|
||||
|
||||
let worldMat: Mat4 | undefined;
|
||||
const worldMat = comp.node.getWorldMatrix();
|
||||
|
||||
_vertexFloatCount = 0;
|
||||
_vertexOffset = 0;
|
||||
@@ -456,7 +440,6 @@ function updateComponentRenderData (comp: ArmatureDisplay, batcher: Batcher2D) {
|
||||
_actualVCount = _comp.maxVertexCount;
|
||||
_actualICount = _comp.maxIndexCount;
|
||||
|
||||
_batcher = batcher;
|
||||
if (comp.isAnimationCached()) {
|
||||
// Traverse input assembler.
|
||||
cacheTraverse(comp._curFrame, worldMat);
|
||||
|
||||
@@ -441,10 +441,6 @@ export class Director extends EventTarget {
|
||||
assertID(scene, 1205);
|
||||
assertID(scene instanceof Scene, 1216);
|
||||
|
||||
// ensure scene initialized
|
||||
// @ts-expect-error run private method
|
||||
scene._load();
|
||||
|
||||
// Delay run / replace scene to the end of the frame
|
||||
this.once(Director.EVENT_END_FRAME, () => {
|
||||
this.runSceneImmediate(scene, onBeforeLoadScene, onLaunched);
|
||||
|
||||
+33
-15
@@ -24,7 +24,7 @@
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { DEBUG, EDITOR, NATIVE, PREVIEW } from 'internal:constants';
|
||||
import { DEBUG, EDITOR, NATIVE, PREVIEW, WEBGPU } from 'internal:constants';
|
||||
import { systemInfo } from 'pal/system-info';
|
||||
import { findCanvas, loadJsFile } from 'pal/env';
|
||||
import { Pacer } from 'pal/pacer';
|
||||
@@ -84,7 +84,7 @@ export interface IGameConfig {
|
||||
* You can pass in parameters in game.init or override them in the [game.onPostBaseInitDelegate] event callback.
|
||||
* Note: you need to specify this option in the application.js template or add a delegate callback.
|
||||
*/
|
||||
overrideSettings : Partial<{ [ k in Settings.Category[keyof Settings.Category] ]: Record<string, any> }>
|
||||
overrideSettings: Partial<{ [k in Settings.Category[keyof Settings.Category]]: Record<string, any> }>
|
||||
|
||||
/**
|
||||
* @zh
|
||||
@@ -602,8 +602,8 @@ export class Game extends EventTarget {
|
||||
public on (type: string, callback: () => void, target?: any, once?: boolean): any {
|
||||
// Make sure EVENT_ENGINE_INITED callbacks to be invoked
|
||||
if ((this._engineInited && type === Game.EVENT_ENGINE_INITED)
|
||||
|| (this._inited && type === Game.EVENT_GAME_INITED)
|
||||
|| (this._rendererInitialized && type === Game.EVENT_RENDERER_INITED)) {
|
||||
|| (this._inited && type === Game.EVENT_GAME_INITED)
|
||||
|| (this._rendererInitialized && type === Game.EVENT_RENDERER_INITED)) {
|
||||
callback.call(target);
|
||||
}
|
||||
return this.eventTargetOn(type, callback, target, once);
|
||||
@@ -686,17 +686,6 @@ export class Game extends EventTarget {
|
||||
if (DEBUG) {
|
||||
console.timeEnd('Init Base');
|
||||
}
|
||||
|
||||
if (sys.isXR) {
|
||||
// XrEntry must not be destroyed
|
||||
xr.entry = xr.XrEntry.getInstance();
|
||||
|
||||
const xrMSAA = settings.querySettings(Settings.Category.RENDERING, 'msaa') ?? 1;
|
||||
const xrRenderingScale = settings.querySettings(Settings.Category.RENDERING, 'renderingScale') ?? 1.0;
|
||||
xr.entry.setMultisamplesRTT(xrMSAA);
|
||||
xr.entry.setRenderingScale(xrRenderingScale);
|
||||
}
|
||||
|
||||
this.emit(Game.EVENT_POST_BASE_INIT);
|
||||
return this.onPostBaseInitDelegate.dispatch();
|
||||
})
|
||||
@@ -711,6 +700,7 @@ export class Game extends EventTarget {
|
||||
console.time('Init Infrastructure');
|
||||
}
|
||||
macro.init();
|
||||
this._initXR();
|
||||
const adapter = findCanvas();
|
||||
if (adapter) {
|
||||
this.canvas = adapter.canvas;
|
||||
@@ -785,6 +775,7 @@ export class Game extends EventTarget {
|
||||
return Promise.resolve([]);
|
||||
})
|
||||
.then(() => this._loadProjectBundles())
|
||||
.then(() => this._loadCCEScripts())
|
||||
.then(() => this._setupRenderPipeline())
|
||||
.then(() => this._loadPreloadAssets())
|
||||
.then(() => {
|
||||
@@ -805,6 +796,18 @@ export class Game extends EventTarget {
|
||||
});
|
||||
}
|
||||
|
||||
private _initXR () {
|
||||
if (sys.isXR) {
|
||||
// XrEntry must not be destroyed
|
||||
xr.entry = xr.XrEntry.getInstance();
|
||||
|
||||
const xrMSAA = settings.querySettings(Settings.Category.RENDERING, 'msaa') ?? 1;
|
||||
const xrRenderingScale = settings.querySettings(Settings.Category.RENDERING, 'renderingScale') ?? 1.0;
|
||||
xr.entry.setMultisamplesRTT(xrMSAA);
|
||||
xr.entry.setRenderingScale(xrRenderingScale);
|
||||
}
|
||||
}
|
||||
|
||||
private _compatibleWithOldParams (config: IGameConfig) {
|
||||
const overrideSettings = config.overrideSettings = config.overrideSettings || {};
|
||||
if ('showFPS' in config) {
|
||||
@@ -859,6 +862,21 @@ export class Game extends EventTarget {
|
||||
})));
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal only for browser preview
|
||||
*/
|
||||
private _loadCCEScripts () {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
// Since there is no script in the bundle during preview, we need to load the user's script in the following way
|
||||
if (PREVIEW && !TEST && !EDITOR && !NATIVE) {
|
||||
const bundneName = 'cce:/internal/x/prerequisite-imports';
|
||||
import(bundneName).then(() => resolve(), (reason) => reject(reason));
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal only for game-view
|
||||
*/
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* eslint-disable max-len */
|
||||
/*
|
||||
Copyright (c) 2022 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
@@ -23,7 +24,7 @@
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { JSB } from 'internal:constants';
|
||||
import { JSB, WEBGPU } from 'internal:constants';
|
||||
import { legacyCC } from '../core/global-exports';
|
||||
import { error, getError } from '../core/platform/debug';
|
||||
import { sys } from '../core/platform/sys';
|
||||
@@ -88,6 +89,7 @@ export enum RenderType {
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
|
||||
export class DeviceManager {
|
||||
private initialized = false;
|
||||
private _gfxDevice!: Device;
|
||||
@@ -127,6 +129,9 @@ export class DeviceManager {
|
||||
}
|
||||
|
||||
const deviceCtors: Constructor<Device>[] = [];
|
||||
if (WEBGPU) {
|
||||
deviceCtors.push(legacyCC.WebGPUDevice);
|
||||
}
|
||||
if (useWebGL2 && legacyCC.WebGL2Device) {
|
||||
deviceCtors.push(legacyCC.WebGL2Device);
|
||||
}
|
||||
|
||||
@@ -424,7 +424,9 @@ export declare namespace native {
|
||||
/**
|
||||
* @en create a download task. The maximum size for a single download file is 4GB.
|
||||
* @zh 创建一个下载任务. 单个下载文件最大为4GB.
|
||||
* @param requestURL @en Request download resource URL @zh 请求下载资源的URL
|
||||
* @param requestURL
|
||||
* @en Request download resource URL. Node: Users need to encode the URL containing special characters except spaces (such as Chinese, etc.)
|
||||
* @zh 请求下载资源的URL. 注意: 当URL中包含除空格外特殊字符(如:中文等)时需要用户自行编码后传入.
|
||||
* @param storagePath @en Storage path for downloaded file @zh 下载文件存储路径
|
||||
* @param identifier @en identifier @zh 标识符
|
||||
* @return @en DownloadTask @zh 下载任务对象
|
||||
@@ -487,7 +489,9 @@ export declare namespace native {
|
||||
* @deprecated since v3.6.0, please use `createDownloadTask` to instead.
|
||||
* @en create a download task. The maximum size for a single download file is 4GB.
|
||||
* @zh 创建一个下载任务. 单个下载文件最大为4GB.
|
||||
* @param requestURL @en Request download resource URL @zh 请求下载资源的URL
|
||||
* @param requestURL
|
||||
* @en Request download resource URL. Node: Users need to encode the URL containing special characters except spaces (such as Chinese, etc.)
|
||||
* @zh 请求下载资源的URL. 注意: 当URL中包含除空格外特殊字符(如:中文等)时需要用户自行编码后传入.
|
||||
* @param storagePath @en Storage path for downloaded file @zh 下载文件存储路径
|
||||
* @param identifier @en identifier @zh 标识符
|
||||
* @return @en DownloadTask @zh 下载任务对象
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
// eslint-disable-next-line import/no-extraneous-dependencies
|
||||
import bulletModule, { bulletType } from '@cocos/bullet';
|
||||
import { WECHAT } from 'internal:constants';
|
||||
import { WECHAT, RUNTIME_BASED } from 'internal:constants';
|
||||
import { game } from '../../game';
|
||||
import { sys } from '../../core/platform';
|
||||
import { pageSize, pageCount, importFunc } from './bullet-env';
|
||||
@@ -92,7 +92,7 @@ export function waitForAmmoInstantiation () {
|
||||
}, errorReport);
|
||||
}
|
||||
|
||||
if (WECHAT) {
|
||||
if (WECHAT || RUNTIME_BASED) {
|
||||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
||||
const wasmFilePath = `cocos-js/${module}` as any;
|
||||
instantiateWasm(wasmFilePath);
|
||||
|
||||
@@ -100,6 +100,7 @@ export class RenderWindow {
|
||||
protected _hasOnScreenAttachments = false;
|
||||
protected _hasOffScreenAttachments = false;
|
||||
protected _framebuffer: Framebuffer | null = null;
|
||||
protected _device: Device | null = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
@@ -121,6 +122,7 @@ export class RenderWindow {
|
||||
|
||||
this._width = info.width;
|
||||
this._height = info.height;
|
||||
this._device = device;
|
||||
this._renderPass = device.createRenderPass(info.renderPassInfo);
|
||||
|
||||
if (info.swapchain) {
|
||||
@@ -177,6 +179,7 @@ export class RenderWindow {
|
||||
}
|
||||
}
|
||||
this._colorTextures.length = 0;
|
||||
this._device = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -203,7 +206,7 @@ export class RenderWindow {
|
||||
|
||||
if (this.framebuffer) {
|
||||
this.framebuffer.destroy();
|
||||
this.framebuffer.initialize(new FramebufferInfo(
|
||||
this._framebuffer = this._device!.createFramebuffer(new FramebufferInfo(
|
||||
this._renderPass!,
|
||||
this._colorTextures,
|
||||
this._depthStencilTexture,
|
||||
|
||||
@@ -30,7 +30,7 @@ import { legacyCC } from '../core/global-exports';
|
||||
import { Pass } from './core/pass';
|
||||
import { Camera } from './scene/camera';
|
||||
import { Shadows } from './scene/shadows';
|
||||
import { SpotLight } from './scene';
|
||||
import { SpotLight, Model } from './scene';
|
||||
import { SubModel } from './scene/submodel';
|
||||
|
||||
removeProperty(RenderScene.prototype, 'RenderScene.prototype', [
|
||||
@@ -49,6 +49,11 @@ removeProperty(RenderScene.prototype, 'RenderScene.prototype', [
|
||||
{ name: 'rayResultSingleModel' },
|
||||
]);
|
||||
|
||||
removeProperty(Model.prototype, 'Model.prototype', [
|
||||
{ name: 'isInstancingEnabled' },
|
||||
{ name: 'instancedAttributes' },
|
||||
]);
|
||||
|
||||
const CameraVisFlags = {};
|
||||
|
||||
removeProperty(CameraVisFlags, 'CameraVisFlags', [
|
||||
|
||||
@@ -33,7 +33,7 @@ import { Layers } from '../../scene-graph/layers';
|
||||
import { RenderScene } from '../core/render-scene';
|
||||
import { Texture2D } from '../../asset/assets/texture-2d';
|
||||
import { SubModel } from './submodel';
|
||||
import { Pass, IMacroPatch, BatchingSchemes } from '../core/pass';
|
||||
import { IMacroPatch, BatchingSchemes } from '../core/pass';
|
||||
import { Mat4, Vec3, Vec4 } from '../../core/math';
|
||||
import { Attribute, DescriptorSet, Device, Buffer, BufferInfo, getTypedArrayConstructor,
|
||||
BufferUsageBit, FormatInfos, MemoryUsageBit, Filter, Address, Feature, SamplerInfo, deviceManager } from '../../gfx';
|
||||
@@ -49,12 +49,6 @@ const lightMapPatches: IMacroPatch[] = [
|
||||
{ name: 'CC_USE_LIGHTMAP', value: true },
|
||||
];
|
||||
|
||||
export interface IInstancedAttributeBlock {
|
||||
buffer: Uint8Array;
|
||||
views: TypedArray[];
|
||||
attributes: Attribute[];
|
||||
}
|
||||
|
||||
export enum ModelType {
|
||||
DEFAULT,
|
||||
SKINNING,
|
||||
@@ -64,12 +58,6 @@ export enum ModelType {
|
||||
LINE,
|
||||
}
|
||||
|
||||
function uploadMat4AsVec4x3 (mat: Mat4, v1: ArrayBufferView, v2: ArrayBufferView, v3: ArrayBufferView) {
|
||||
v1[0] = mat.m00; v1[1] = mat.m01; v1[2] = mat.m02; v1[3] = mat.m12;
|
||||
v2[0] = mat.m04; v2[1] = mat.m05; v2[2] = mat.m06; v2[3] = mat.m13;
|
||||
v3[0] = mat.m08; v3[1] = mat.m09; v3[2] = mat.m10; v3[3] = mat.m14;
|
||||
}
|
||||
|
||||
const lightmapSamplerHash = new SamplerInfo(
|
||||
Filter.LINEAR,
|
||||
Filter.LINEAR,
|
||||
@@ -157,14 +145,6 @@ export class Model {
|
||||
return this._updateStamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Whether GPU instancing is enabled for the current model
|
||||
* @zh 是否开启实例化渲染
|
||||
*/
|
||||
get isInstancingEnabled () {
|
||||
return this._instMatWorldIdx >= 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Model level shadow bias
|
||||
* @zh 阴影偏移值
|
||||
@@ -295,12 +275,6 @@ export class Model {
|
||||
*/
|
||||
public isDynamicBatching = false;
|
||||
|
||||
/**
|
||||
* @en The instance attributes
|
||||
* @zh 实例化属性
|
||||
*/
|
||||
public instancedAttributes: IInstancedAttributeBlock = { buffer: null!, views: [], attributes: [] };
|
||||
|
||||
/**
|
||||
* @en The world axis-aligned bounding box
|
||||
* @zh 世界空间包围盒
|
||||
@@ -373,11 +347,6 @@ export class Model {
|
||||
*/
|
||||
protected _localBuffer: Buffer | null = null;
|
||||
|
||||
/**
|
||||
* @en Instance matrix id
|
||||
* @zh 实例矩阵索引
|
||||
*/
|
||||
private _instMatWorldIdx = -1;
|
||||
private _lightmap: Texture2D | null = null;
|
||||
private _lightmapUVParam: Vec4 = new Vec4();
|
||||
|
||||
@@ -557,11 +526,17 @@ export class Model {
|
||||
|
||||
// @ts-expect-error using private members here for efficiency
|
||||
const worldMatrix = this.transform._mat;
|
||||
const idx = this._instMatWorldIdx;
|
||||
if (idx >= 0) {
|
||||
const attrs = this.instancedAttributes.views;
|
||||
uploadMat4AsVec4x3(worldMatrix, attrs[idx], attrs[idx + 1], attrs[idx + 2]);
|
||||
} else if (this._localBuffer) {
|
||||
let hasNonInstancingPass = false;
|
||||
for (let i = 0; i < subModels.length; i++) {
|
||||
const subModel = subModels[i];
|
||||
const idx = subModel.instancedWorldMatrixIndex;
|
||||
if (idx >= 0) {
|
||||
subModel.updateInstancedWorldMatrix(worldMatrix, idx);
|
||||
} else {
|
||||
hasNonInstancingPass = true;
|
||||
}
|
||||
}
|
||||
if (hasNonInstancingPass && this._localBuffer) {
|
||||
Mat4.toArray(this._localData, worldMatrix, UBOLocal.MAT_WORLD_OFFSET);
|
||||
Mat4.inverseTranspose(m4_1, worldMatrix);
|
||||
|
||||
@@ -596,10 +571,8 @@ export class Model {
|
||||
public initSubModel (idx: number, subMeshData: RenderingSubMesh, mat: Material) {
|
||||
this.initialize();
|
||||
|
||||
let isNewSubModel = false;
|
||||
if (this._subModels[idx] == null) {
|
||||
this._subModels[idx] = this._createSubModel();
|
||||
isNewSubModel = true;
|
||||
} else {
|
||||
this._subModels[idx].destroy();
|
||||
}
|
||||
@@ -747,57 +720,14 @@ export class Model {
|
||||
}
|
||||
|
||||
const shader = subModel.passes[0].getShaderVariant(subModel.patches)!;
|
||||
this._updateInstancedAttributes(shader.attributes, subModel.passes[0]);
|
||||
}
|
||||
|
||||
protected _getInstancedAttributeIndex (name: string) {
|
||||
const { attributes } = this.instancedAttributes;
|
||||
for (let i = 0; i < attributes.length; i++) {
|
||||
if (attributes[i].name === name) { return i; }
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private _setInstMatWorldIdx (idx: number) {
|
||||
this._instMatWorldIdx = idx;
|
||||
this._updateInstancedAttributes(shader.attributes, subModel);
|
||||
}
|
||||
|
||||
// sub-classes can override the following functions if needed
|
||||
|
||||
// for now no submodel level instancing attributes
|
||||
protected _updateInstancedAttributes (attributes: Attribute[], pass: Pass) {
|
||||
if (!pass.device.hasFeature(Feature.INSTANCED_ARRAYS)) { return; }
|
||||
// free old data
|
||||
|
||||
let size = 0;
|
||||
for (let j = 0; j < attributes.length; j++) {
|
||||
const attribute = attributes[j];
|
||||
if (!attribute.isInstanced) { continue; }
|
||||
size += FormatInfos[attribute.format].size;
|
||||
}
|
||||
|
||||
const attrs = this.instancedAttributes;
|
||||
attrs.buffer = new Uint8Array(size);
|
||||
attrs.views.length = attrs.attributes.length = 0;
|
||||
let offset = 0;
|
||||
for (let j = 0; j < attributes.length; j++) {
|
||||
const attribute = attributes[j];
|
||||
if (!attribute.isInstanced) { continue; }
|
||||
const attr = new Attribute();
|
||||
attr.format = attribute.format;
|
||||
attr.name = attribute.name;
|
||||
attr.isNormalized = attribute.isNormalized;
|
||||
attr.location = attribute.location;
|
||||
attrs.attributes.push(attr);
|
||||
|
||||
const info = FormatInfos[attribute.format];
|
||||
|
||||
const typeViewArray = new (getTypedArrayConstructor(info))(attrs.buffer.buffer, offset, info.count);
|
||||
attrs.views.push(typeViewArray);
|
||||
offset += info.size;
|
||||
}
|
||||
if (pass.batchingScheme === BatchingSchemes.INSTANCING) { pass.getInstancedBuffer().destroy(); } // instancing IA changed
|
||||
this._setInstMatWorldIdx(this._getInstancedAttributeIndex(INST_MAT_WORLD));
|
||||
// for now no subModel level instancing attributes
|
||||
protected _updateInstancedAttributes (attributes: Attribute[], subModel: SubModel) {
|
||||
subModel.UpdateInstancedAttributes(attributes);
|
||||
this._localDataUpdated = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,18 +24,25 @@
|
||||
*/
|
||||
|
||||
import { RenderingSubMesh } from '../../asset/assets/rendering-sub-mesh';
|
||||
import { RenderPriority, UNIFORM_REFLECTION_TEXTURE_BINDING, UNIFORM_REFLECTION_STORAGE_BINDING } from '../../rendering/define';
|
||||
import { RenderPriority, UNIFORM_REFLECTION_TEXTURE_BINDING, UNIFORM_REFLECTION_STORAGE_BINDING, INST_MAT_WORLD } from '../../rendering/define';
|
||||
import { BatchingSchemes, IMacroPatch, Pass } from '../core/pass';
|
||||
import { DescriptorSet, DescriptorSetInfo, Device, InputAssembler, Texture, TextureType, TextureUsageBit, TextureInfo,
|
||||
Format, Sampler, Filter, Address, Shader, SamplerInfo, deviceManager } from '../../gfx';
|
||||
Format, Sampler, Filter, Address, Shader, SamplerInfo, deviceManager, Attribute, Feature, FormatInfos, getTypedArrayConstructor } from '../../gfx';
|
||||
import { legacyCC } from '../../core/global-exports';
|
||||
import { errorID } from '../../core/platform/debug';
|
||||
import { getPhaseID } from '../../rendering/pass-phase';
|
||||
import { Root } from '../../root';
|
||||
import { Mat4 } from '../../core';
|
||||
|
||||
const _dsInfo = new DescriptorSetInfo(null!);
|
||||
const MAX_PASS_COUNT = 8;
|
||||
|
||||
export interface IInstancedAttributeBlock {
|
||||
buffer: Uint8Array;
|
||||
views: TypedArray[];
|
||||
attributes: Attribute[];
|
||||
}
|
||||
|
||||
/**
|
||||
* @en A sub part of the model, it describes how to render a specific sub mesh.
|
||||
* It contains geometry information in [[RenderingSubMesh]] and all sort of rendering configuration like shaders, macro patches, passes etc.
|
||||
@@ -56,6 +63,8 @@ export class SubModel {
|
||||
protected _planarShader: Shader | null = null;
|
||||
protected _reflectionTex: Texture | null = null;
|
||||
protected _reflectionSampler: Sampler | null = null;
|
||||
protected _instancedAttributeBlock: IInstancedAttributeBlock = { buffer: null!, views: [], attributes: [] };
|
||||
protected _instancedWorldMatrixIndex = -1;
|
||||
|
||||
/**
|
||||
* @en
|
||||
@@ -106,7 +115,7 @@ export class SubModel {
|
||||
*/
|
||||
set subMesh (subMesh) {
|
||||
this._inputAssembler!.destroy();
|
||||
this._inputAssembler!.initialize(subMesh.iaInfo);
|
||||
this._inputAssembler = this._device!.createInputAssembler(subMesh.iaInfo);
|
||||
if (this._passes![0].batchingScheme === BatchingSchemes.VB_MERGING) { this.subMesh.genFlatBuffers(); }
|
||||
this._subMesh = subMesh;
|
||||
}
|
||||
@@ -175,6 +184,25 @@ export class SubModel {
|
||||
return this._planarShader;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en The instance attribute block, access by sub model
|
||||
* @zh 硬件实例化属性,通过子模型访问
|
||||
*/
|
||||
get instancedAttributeBlock () {
|
||||
return this._instancedAttributeBlock;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Get or set instance matrix id, access by sub model
|
||||
* @zh 获取或者设置硬件实例化中的矩阵索引,通过子模型访问
|
||||
*/
|
||||
set instancedWorldMatrixIndex (val : number) {
|
||||
this._instancedWorldMatrixIndex = val;
|
||||
}
|
||||
get instancedWorldMatrixIndex () {
|
||||
return this._instancedWorldMatrixIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en
|
||||
* init sub model
|
||||
@@ -371,10 +399,93 @@ export class SubModel {
|
||||
// update draw info
|
||||
const drawInfo = this._subMesh.drawInfo;
|
||||
if (this._inputAssembler && drawInfo) {
|
||||
this._inputAssembler.drawInfo.copy(drawInfo);
|
||||
Object.assign(this._inputAssembler.drawInfo, drawInfo);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @en
|
||||
* get instanced attribute index
|
||||
* @zh
|
||||
* 获取硬件实例化相关索引
|
||||
*/
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public getInstancedAttributeIndex (name: string) {
|
||||
const { attributes } = this.instancedAttributeBlock;
|
||||
for (let i = 0; i < attributes.length; i++) {
|
||||
if (attributes[i].name === name) { return i; }
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en
|
||||
* update instancing related data, invoked by model
|
||||
* @zh
|
||||
* 更新硬件实例化相关数据,一般由model调用
|
||||
*/
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public updateInstancedWorldMatrix (mat: Mat4, idx: number) {
|
||||
const attrs = this.instancedAttributeBlock.views;
|
||||
const v1 = attrs[idx];
|
||||
const v2 = attrs[idx + 1];
|
||||
const v3 = attrs[idx + 2];
|
||||
v1[0] = mat.m00; v1[1] = mat.m01; v1[2] = mat.m02; v1[3] = mat.m12;
|
||||
v2[0] = mat.m04; v2[1] = mat.m05; v2[2] = mat.m06; v2[3] = mat.m13;
|
||||
v3[0] = mat.m08; v3[1] = mat.m09; v3[2] = mat.m10; v3[3] = mat.m14;
|
||||
}
|
||||
/**
|
||||
* @en
|
||||
* update instancing related data, invoked by model
|
||||
* @zh
|
||||
* 更新硬件实例化相关数据,一般由model调用
|
||||
*/
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public UpdateInstancedAttributes (attributes: Attribute[]) {
|
||||
// initialize subModelWorldMatrixIndex
|
||||
this.instancedWorldMatrixIndex = -1;
|
||||
|
||||
const pass = this.passes[0];
|
||||
if (!pass.device.hasFeature(Feature.INSTANCED_ARRAYS)) { return; }
|
||||
// free old data
|
||||
|
||||
let size = 0;
|
||||
for (let j = 0; j < attributes.length; j++) {
|
||||
const attribute = attributes[j];
|
||||
if (!attribute.isInstanced) { continue; }
|
||||
size += FormatInfos[attribute.format].size;
|
||||
}
|
||||
|
||||
const attrs = this.instancedAttributeBlock;
|
||||
attrs.buffer = new Uint8Array(size);
|
||||
attrs.views.length = attrs.attributes.length = 0;
|
||||
let offset = 0;
|
||||
for (let j = 0; j < attributes.length; j++) {
|
||||
const attribute = attributes[j];
|
||||
if (!attribute.isInstanced) { continue; }
|
||||
const attr = new Attribute();
|
||||
attr.format = attribute.format;
|
||||
attr.name = attribute.name;
|
||||
attr.isNormalized = attribute.isNormalized;
|
||||
attr.location = attribute.location;
|
||||
attrs.attributes.push(attr);
|
||||
|
||||
const info = FormatInfos[attribute.format];
|
||||
|
||||
const typeViewArray = new (getTypedArrayConstructor(info))(attrs.buffer.buffer, offset, info.count);
|
||||
attrs.views.push(typeViewArray);
|
||||
offset += info.size;
|
||||
}
|
||||
if (pass.batchingScheme === BatchingSchemes.INSTANCING) { pass.getInstancedBuffer().destroy(); } // instancing IA changed
|
||||
this.instancedWorldMatrixIndex = this.getInstancedAttributeIndex(INST_MAT_WORLD);
|
||||
}
|
||||
|
||||
protected _flushPassInfo (): void {
|
||||
const passes = this._passes;
|
||||
if (!passes) { return; }
|
||||
|
||||
@@ -829,22 +829,22 @@ class DevicePreSceneTask extends WebSceneTask {
|
||||
if (isEmpty) {
|
||||
for (const ro of this.sceneData.renderObjects) {
|
||||
const subModels = ro.model.subModels;
|
||||
for (const submodel of subModels) {
|
||||
const passes = submodel.passes;
|
||||
for (const subModel of subModels) {
|
||||
const passes = subModel.passes;
|
||||
for (const p of passes) {
|
||||
if (p.phase !== this._currentQueue.phaseID) continue;
|
||||
const batchingScheme = p.batchingScheme;
|
||||
if (batchingScheme === BatchingSchemes.INSTANCING) {
|
||||
const instancedBuffer = p.getInstancedBuffer();
|
||||
instancedBuffer.merge(submodel, ro.model.instancedAttributes, passes.indexOf(p));
|
||||
instancedBuffer.merge(subModel, ro.model.instancedAttributes, passes.indexOf(p));
|
||||
this._submitInfo.instances.add(instancedBuffer);
|
||||
} else if (batchingScheme === BatchingSchemes.VB_MERGING) {
|
||||
const batchedBuffer = p.getBatchedBuffer();
|
||||
batchedBuffer.merge(submodel, passes.indexOf(p), ro.model);
|
||||
batchedBuffer.merge(subModel, passes.indexOf(p), ro.model);
|
||||
this._submitInfo.batches.add(batchedBuffer);
|
||||
} else {
|
||||
this._insertRenderList(ro, subModels.indexOf(submodel), passes.indexOf(p));
|
||||
this._insertRenderList(ro, subModels.indexOf(submodel), passes.indexOf(p), true);
|
||||
this._insertRenderList(ro, subModels.indexOf(subModel), passes.indexOf(p));
|
||||
this._insertRenderList(ro, subModels.indexOf(subModel), passes.indexOf(p), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -316,8 +316,8 @@ export class DeferredPipeline extends RenderPipeline {
|
||||
// Listens when the attachment texture is scaled
|
||||
this.on(PipelineEventType.ATTACHMENT_SCALE_CAHNGED, (val: number) => {
|
||||
data.sampler = val < 1 ? this.globalDSManager.pointSampler : this.globalDSManager.linearSampler;
|
||||
this.applyFramebufferRatio(data.gbufferFrameBuffer);
|
||||
this.applyFramebufferRatio(data.outputFrameBuffer);
|
||||
data.gbufferFrameBuffer = this.newFramebufferByRatio(data.gbufferFrameBuffer);
|
||||
data.gbufferFrameBuffer = this.newFramebufferByRatio(data.outputFrameBuffer);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ export class GbufferStage extends RenderStage {
|
||||
const batchingScheme = pass.batchingScheme;
|
||||
if (batchingScheme === BatchingSchemes.INSTANCING) {
|
||||
const instancedBuffer = pass.getInstancedBuffer();
|
||||
instancedBuffer.merge(subModel, ro.model.instancedAttributes, p);
|
||||
instancedBuffer.merge(subModel, p);
|
||||
this._instancedQueue.queue.add(instancedBuffer);
|
||||
} else if (batchingScheme === BatchingSchemes.VB_MERGING) {
|
||||
const batchedBuffer = pass.getBatchedBuffer();
|
||||
|
||||
@@ -92,6 +92,20 @@ export class ForwardStage extends RenderStage {
|
||||
this._uiPhase = new UIPhase();
|
||||
}
|
||||
|
||||
public addRenderInstancedQueue (queue: RenderInstancedQueue) {
|
||||
if (this.additiveInstanceQueues.includes(queue)) {
|
||||
return;
|
||||
}
|
||||
this.additiveInstanceQueues.push(queue);
|
||||
}
|
||||
|
||||
public removeRenderInstancedQueue (queue: RenderInstancedQueue) {
|
||||
const index = this.additiveInstanceQueues.indexOf(queue);
|
||||
if (index > -1) {
|
||||
this.additiveInstanceQueues.splice(index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
public initialize (info: IRenderStageInfo): boolean {
|
||||
super.initialize(info);
|
||||
if (info.renderQueues) {
|
||||
@@ -135,7 +149,7 @@ export class ForwardStage extends RenderStage {
|
||||
const batchingScheme = pass.batchingScheme;
|
||||
if (batchingScheme === BatchingSchemes.INSTANCING) {
|
||||
const instancedBuffer = pass.getInstancedBuffer();
|
||||
instancedBuffer.merge(subModel, ro.model.instancedAttributes, p);
|
||||
instancedBuffer.merge(subModel, p);
|
||||
this._instancedQueue.queue.add(instancedBuffer);
|
||||
} else if (batchingScheme === BatchingSchemes.VB_MERGING) {
|
||||
const batchedBuffer = pass.getBatchedBuffer();
|
||||
|
||||
@@ -65,22 +65,23 @@ export class InstancedBuffer {
|
||||
this.instances.length = 0;
|
||||
}
|
||||
|
||||
public merge (subModel: SubModel, attrs: IInstancedAttributeBlock, passIdx: number, shaderImplant: Shader | null = null) {
|
||||
public merge (subModel: SubModel, passIdx: number, shaderImplant: Shader | null = null) {
|
||||
const attrs = subModel.instancedAttributeBlock;
|
||||
const stride = attrs.buffer.length;
|
||||
if (!stride) { return; } // we assume per-instance attributes are always present
|
||||
const sourceIA = subModel.inputAssembler;
|
||||
const lightingMap = subModel.descriptorSet.getTexture(UNIFORM_LIGHTMAP_TEXTURE_BINDING);
|
||||
let shader = shaderImplant;
|
||||
let shader = shaderImplant;
|
||||
if (!shader) {
|
||||
shader = subModel.shaders[passIdx];
|
||||
}
|
||||
const descriptorSet = subModel.descriptorSet;
|
||||
for (let i = 0; i < this.instances.length; ++i) {
|
||||
const instance = this.instances[i];
|
||||
if (instance.ia.indexBuffer !== sourceIA.indexBuffer || instance.count >= MAX_CAPACITY) { continue; }
|
||||
if (instance.ia.indexBuffer?.objectID !== sourceIA.indexBuffer?.objectID || instance.count >= MAX_CAPACITY) { continue; }
|
||||
|
||||
// check same binding
|
||||
if (instance.lightingMap !== lightingMap) {
|
||||
if (instance.lightingMap.objectID !== lightingMap.objectID) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -97,8 +98,8 @@ export class InstancedBuffer {
|
||||
instance.data.set(oldData);
|
||||
instance.vb.resize(newSize);
|
||||
}
|
||||
if (instance.shader !== shader) { instance.shader = shader; }
|
||||
if (instance.descriptorSet !== descriptorSet) { instance.descriptorSet = descriptorSet; }
|
||||
instance.shader = shader;
|
||||
instance.descriptorSet = descriptorSet;
|
||||
instance.data.set(attrs.buffer, instance.stride * instance.count++);
|
||||
this.hasPendingModels = true;
|
||||
return;
|
||||
|
||||
@@ -514,7 +514,7 @@ export class PipelineUBO {
|
||||
globalDS.bindTexture(UNIFORM_SHADOWMAP_BINDING, builtinResMgr.get<Texture2D>('default-texture').getGFXTexture()!);
|
||||
globalDS.bindTexture(UNIFORM_SPOT_SHADOW_MAP_TEXTURE_BINDING, builtinResMgr.get<Texture2D>('default-texture').getGFXTexture()!);
|
||||
globalDS.update();
|
||||
globalDS.getBuffer(UBOShadow.BINDING).update(this._shadowUBO);
|
||||
this._pipeline.commandBuffers[0].updateBuffer(globalDS.getBuffer(UBOShadow.BINDING), this._shadowUBO);
|
||||
}
|
||||
|
||||
public updateShadowUBORange (offset: number, data: Mat4 | Color) {
|
||||
|
||||
@@ -27,16 +27,17 @@ import { AABB, intersect } from '../core/geometry';
|
||||
import { SetIndex } from './define';
|
||||
import { CommandBuffer, Device, RenderPass } from '../gfx';
|
||||
import { PipelineStateManager } from './pipeline-state-manager';
|
||||
import { Model, Camera } from '../render-scene/scene';
|
||||
import { Model, Camera, SubModel } from '../render-scene/scene';
|
||||
import { RenderInstancedQueue } from './render-instanced-queue';
|
||||
import { ShadowType } from '../render-scene/scene/shadows';
|
||||
import { Layers } from '../scene-graph/layers';
|
||||
import { PipelineRuntime } from './custom/pipeline';
|
||||
import { BatchingSchemes } from '../renderer/core/pass';
|
||||
|
||||
const _ab = new AABB();
|
||||
|
||||
export class PlanarShadowQueue {
|
||||
private _pendingModels: Model[] = [];
|
||||
private _pendingSubModels: SubModel[] = [];
|
||||
private _castModels:Model[] = [];
|
||||
private _instancedQueue = new RenderInstancedQueue();
|
||||
private _pipeline: PipelineRuntime;
|
||||
@@ -49,7 +50,7 @@ export class PlanarShadowQueue {
|
||||
const pipelineSceneData = this._pipeline.pipelineSceneData;
|
||||
const shadows = pipelineSceneData.shadows;
|
||||
this._instancedQueue.clear();
|
||||
this._pendingModels.length = 0;
|
||||
this._pendingSubModels.length = 0;
|
||||
this._castModels.length = 0;
|
||||
if (!shadows.enabled || shadows.type !== ShadowType.Planar || shadows.normal.length() < 0.000001) { return; }
|
||||
|
||||
@@ -72,14 +73,21 @@ export class PlanarShadowQueue {
|
||||
AABB.transform(_ab, model.worldBounds, shadows.matLight);
|
||||
if (!intersect.aabbFrustum(_ab, frustum)) { continue; }
|
||||
}
|
||||
if (model.isInstancingEnabled) {
|
||||
const subModels = model.subModels;
|
||||
for (let m = 0; m < subModels.length; m++) {
|
||||
const subModel = subModels[m];
|
||||
instancedBuffer.merge(subModel, model.instancedAttributes, 0, subModel.planarInstanceShader);
|
||||
|
||||
const subModels = model.subModels;
|
||||
for (let j = 0; j < subModels.length; j++) {
|
||||
const subModel = subModels[j];
|
||||
const passes = subModel.passes;
|
||||
for (let k = 0; k < passes.length; k++) {
|
||||
const pass = passes[k];
|
||||
const batchingScheme = pass.batchingScheme;
|
||||
if (batchingScheme === BatchingSchemes.INSTANCING) {
|
||||
instancedBuffer.merge(subModel, k, subModel.planarShader);
|
||||
this._instancedQueue.queue.add(instancedBuffer);
|
||||
} else {
|
||||
this._pendingSubModels.push(subModel);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this._pendingModels.push(model);
|
||||
}
|
||||
}
|
||||
this._instancedQueue.uploadBuffers(cmdBuff);
|
||||
@@ -91,26 +99,23 @@ export class PlanarShadowQueue {
|
||||
if (!shadows.enabled || shadows.type !== ShadowType.Planar) { return; }
|
||||
this._instancedQueue.recordCommandBuffer(device, renderPass, cmdBuff);
|
||||
|
||||
if (!this._pendingModels.length) { return; }
|
||||
if (!this._pendingSubModels.length) { return; }
|
||||
const pass = shadows.material.passes[0];
|
||||
const descriptorSet = pass.descriptorSet;
|
||||
cmdBuff.bindDescriptorSet(SetIndex.MATERIAL, descriptorSet);
|
||||
|
||||
const modelCount = this._pendingModels.length;
|
||||
for (let i = 0; i < modelCount; i++) {
|
||||
const model = this._pendingModels[i];
|
||||
for (let j = 0; j < model.subModels.length; j++) {
|
||||
const subModel = model.subModels[j];
|
||||
// This is a temporary solution
|
||||
// It should not be written in a fixed way, or modified by the user
|
||||
const shader = subModel.planarShader;
|
||||
const ia = subModel.inputAssembler;
|
||||
const pso = PipelineStateManager.getOrCreatePipelineState(device, pass, shader!, renderPass, ia);
|
||||
cmdBuff.bindPipelineState(pso);
|
||||
cmdBuff.bindDescriptorSet(SetIndex.LOCAL, subModel.descriptorSet);
|
||||
cmdBuff.bindInputAssembler(ia);
|
||||
cmdBuff.draw(ia);
|
||||
}
|
||||
const subModels = this._pendingSubModels;
|
||||
for (let j = 0; j < subModels.length; j++) {
|
||||
const subModel = subModels[j];
|
||||
// This is a temporary solution
|
||||
// It should not be written in a fixed way, or modified by the user
|
||||
const shader = subModel.planarShader;
|
||||
const ia = subModel.inputAssembler;
|
||||
const pso = PipelineStateManager.getOrCreatePipelineState(device, pass, shader!, renderPass, ia);
|
||||
cmdBuff.bindPipelineState(pso);
|
||||
cmdBuff.bindDescriptorSet(SetIndex.LOCAL, subModel.descriptorSet);
|
||||
cmdBuff.bindInputAssembler(ia);
|
||||
cmdBuff.draw(ia);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -301,7 +301,7 @@ export class RenderAdditiveLightQueue {
|
||||
const { batchingScheme } = pass;
|
||||
if (batchingScheme === BatchingSchemes.INSTANCING) { // instancing
|
||||
const buffer = pass.getInstancedBuffer();
|
||||
buffer.merge(subModel, model.instancedAttributes, lightPassIdx);
|
||||
buffer.merge(subModel, lightPassIdx);
|
||||
buffer.dynamicOffsets[0] = this._lightBufferStride;
|
||||
this._instancedQueue.queue.add(buffer);
|
||||
} else if (batchingScheme === BatchingSchemes.VB_MERGING) { // vb-merging
|
||||
|
||||
@@ -48,6 +48,7 @@ import { OS } from '../../pal/system-info/enum-type';
|
||||
import { macro } from '../core/platform/macro';
|
||||
import { UBOSkinning } from './define';
|
||||
import { PipelineRuntime } from './custom/pipeline';
|
||||
import { murmurhash2_32_gc } from '../utils';
|
||||
|
||||
/**
|
||||
* @en Render pipeline information descriptor
|
||||
@@ -94,6 +95,25 @@ export class PipelineInputAssemblerData {
|
||||
quadIA: InputAssembler|null = null;
|
||||
}
|
||||
|
||||
function hashFrameBuffer (fbo: Framebuffer) {
|
||||
let hash = 666;
|
||||
for (const color of fbo.colorTextures) {
|
||||
const info = color?.info;
|
||||
const hashStr = `${info!.type}_${info!.usage}_${info!.format}_${info!.width}_${info!.height}_${info!.flags}_
|
||||
${info!.layerCount}_${info!.levelCount}_${info!.samples}_${info!.depth}_${info!.externalRes}`;
|
||||
hash = murmurhash2_32_gc(hashStr, hash);
|
||||
}
|
||||
|
||||
if (fbo.depthStencilTexture) {
|
||||
const info = fbo.depthStencilTexture.info;
|
||||
const hashStr = `${info.type}_${info.usage}_${info.format}_${info.width}_${info.height}_${info.flags}_
|
||||
${info.layerCount}_${info.levelCount}_${info.samples}_${info.depth}_${info.externalRes}`;
|
||||
hash = murmurhash2_32_gc(hashStr, hash);
|
||||
}
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Render pipeline describes how we handle the rendering process for all render objects in the related render scene root.
|
||||
* It contains some general pipeline configurations, necessary rendering resources and some [[RenderFlow]]s.
|
||||
@@ -256,7 +276,7 @@ export abstract class RenderPipeline extends Asset implements IPipelineEvent, Pi
|
||||
protected _geometryRenderer: GeometryRenderer | null = null;
|
||||
protected declare _pipelineSceneData: PipelineSceneData;
|
||||
protected _pipelineRenderData: PipelineRenderData | null = null;
|
||||
protected _renderPasses = new Map<ClearFlags, RenderPass>();
|
||||
protected _renderPasses = new Map<number, RenderPass>();
|
||||
protected _width = 0;
|
||||
protected _height = 0;
|
||||
protected _lastUsedRenderArea: Rect = new Rect();
|
||||
@@ -310,30 +330,34 @@ export abstract class RenderPipeline extends Asset implements IPipelineEvent, Pi
|
||||
}
|
||||
|
||||
public getRenderPass (clearFlags: ClearFlags, fbo: Framebuffer): RenderPass {
|
||||
let renderPass = this._renderPasses.get(clearFlags);
|
||||
const fbHash = hashFrameBuffer(fbo);
|
||||
const hash = murmurhash2_32_gc(`${fbHash}_${clearFlags}`, 666);
|
||||
let renderPass = this._renderPasses.get(hash);
|
||||
if (renderPass) { return renderPass; }
|
||||
renderPass = this.createRenderPass(clearFlags, fbo.colorTextures[0]!.format, fbo.depthStencilTexture!.format);
|
||||
this._renderPasses.set(clearFlags, renderPass);
|
||||
this._renderPasses.set(hash, renderPass);
|
||||
return renderPass;
|
||||
}
|
||||
|
||||
public applyFramebufferRatio (framebuffer: Framebuffer) {
|
||||
public newFramebufferByRatio (dyingFramebuffer: Framebuffer) {
|
||||
const sceneData = this.pipelineSceneData;
|
||||
const width = this._width * sceneData.shadingScale;
|
||||
const height = this._height * sceneData.shadingScale;
|
||||
const colorTexArr: any = framebuffer.colorTextures;
|
||||
const colorTexArr: any = dyingFramebuffer.colorTextures;
|
||||
for (let i = 0; i < colorTexArr.length; i++) {
|
||||
colorTexArr[i]!.resize(width, height);
|
||||
}
|
||||
if (framebuffer.depthStencilTexture) {
|
||||
framebuffer.depthStencilTexture.resize(width, height);
|
||||
if (dyingFramebuffer.depthStencilTexture) {
|
||||
dyingFramebuffer.depthStencilTexture.resize(width, height);
|
||||
}
|
||||
framebuffer.destroy();
|
||||
framebuffer.initialize(new FramebufferInfo(
|
||||
framebuffer.renderPass,
|
||||
// move
|
||||
const newFramebuffer = this._device.createFramebuffer(new FramebufferInfo(
|
||||
dyingFramebuffer.renderPass,
|
||||
colorTexArr,
|
||||
framebuffer.depthStencilTexture,
|
||||
dyingFramebuffer.depthStencilTexture,
|
||||
));
|
||||
dyingFramebuffer.destroy();
|
||||
return newFramebuffer;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -143,7 +143,7 @@ export class RenderShadowMapBatchedQueue {
|
||||
|
||||
if (batchingScheme === BatchingSchemes.INSTANCING) { // instancing
|
||||
const buffer = pass.getInstancedBuffer();
|
||||
buffer.merge(subModel, model.instancedAttributes, shadowPassIdx);
|
||||
buffer.merge(subModel, shadowPassIdx);
|
||||
this._instancedQueue.queue.add(buffer);
|
||||
} else if (pass.batchingScheme === BatchingSchemes.VB_MERGING) { // vb-merging
|
||||
const buffer = pass.getBatchedBuffer();
|
||||
|
||||
@@ -33,6 +33,7 @@ import { IRenderObject, UBOShadow } from './define';
|
||||
import { ShadowType, CSMOptimizationMode } from '../render-scene/scene/shadows';
|
||||
import { PipelineSceneData } from './pipeline-scene-data';
|
||||
import { ShadowLayerVolume } from './shadow/csm-layers';
|
||||
import { warnID } from '../platform';
|
||||
|
||||
const _tempVec3 = new Vec3();
|
||||
const _sphere = Sphere.create(0, 0, 0, 1);
|
||||
@@ -145,8 +146,12 @@ export function sceneCulling (pipeline: RenderPipeline, camera: Camera) {
|
||||
}
|
||||
}
|
||||
|
||||
if (skybox.enabled && skybox.model && (camera.clearFlag & SKYBOX_FLAG)) {
|
||||
renderObjects.push(getRenderObject(skybox.model, camera));
|
||||
if ((camera.clearFlag & SKYBOX_FLAG)) {
|
||||
if (skybox.enabled && skybox.model) {
|
||||
renderObjects.push(getRenderObject(skybox.model, camera));
|
||||
} else {
|
||||
warnID(15100, camera.name);
|
||||
}
|
||||
}
|
||||
|
||||
const models = scene.models;
|
||||
|
||||
@@ -298,12 +298,9 @@ export class ShadowFlow extends RenderFlow {
|
||||
const shadowFrameBufferMap = pipeline.pipelineSceneData.shadowFrameBufferMap;
|
||||
const format = supportsR32FloatTexture(device) ? Format.R32F : Format.RGBA8;
|
||||
|
||||
const it = shadowFrameBufferMap.values();
|
||||
let res = it.next();
|
||||
while (!res.done) {
|
||||
const frameBuffer = res.value;
|
||||
for (const key of shadowFrameBufferMap.keys()) {
|
||||
const frameBuffer = shadowFrameBufferMap.get(key);
|
||||
if (!frameBuffer) {
|
||||
res = it.next();
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -321,13 +318,12 @@ export class ShadowFlow extends RenderFlow {
|
||||
|
||||
const shadowRenderPass = frameBuffer.renderPass;
|
||||
frameBuffer.destroy();
|
||||
frameBuffer.initialize(new FramebufferInfo(
|
||||
const newFrameBuffer = device.createFramebuffer(new FramebufferInfo(
|
||||
shadowRenderPass,
|
||||
renderTargets,
|
||||
depth,
|
||||
));
|
||||
|
||||
res = it.next();
|
||||
shadowFrameBufferMap.set(key, newFrameBuffer);
|
||||
}
|
||||
|
||||
shadows.shadowMapDirty = false;
|
||||
|
||||
@@ -824,6 +824,7 @@ export class ShadowsInfo {
|
||||
* @en The type of the shadow
|
||||
* @zh 阴影渲染的类型
|
||||
*/
|
||||
@tooltip('i18n:shadow.type')
|
||||
@editable
|
||||
@type(ShadowType)
|
||||
set type (val) {
|
||||
@@ -838,6 +839,7 @@ export class ShadowsInfo {
|
||||
* @en Shadow color
|
||||
* @zh 阴影颜色
|
||||
*/
|
||||
@tooltip('i18n:shadow.shadowColor')
|
||||
@visible(function (this: ShadowsInfo) { return this._type === ShadowType.Planar; })
|
||||
set shadowColor (val: Color) {
|
||||
this._shadowColor.set(val);
|
||||
@@ -851,8 +853,8 @@ export class ShadowsInfo {
|
||||
* @en The normal of the plane which receives shadow
|
||||
* @zh 阴影接收平面的法线
|
||||
*/
|
||||
@visible(function (this: ShadowsInfo) { return this._type === ShadowType.Planar; })
|
||||
@tooltip('i18n:shadow.planeDirection')
|
||||
@visible(function (this: ShadowsInfo) { return this._type === ShadowType.Planar; })
|
||||
set planeDirection (val: Vec3) {
|
||||
Vec3.copy(this._normal, val);
|
||||
if (this._resource) { this._resource.normal = val; }
|
||||
@@ -865,10 +867,10 @@ export class ShadowsInfo {
|
||||
* @en The distance from coordinate origin to the receiving plane.
|
||||
* @zh 阴影接收平面与原点的距离
|
||||
*/
|
||||
@tooltip('i18n:shadow.planeHeight')
|
||||
@editable
|
||||
@type(CCFloat)
|
||||
@visible(function (this: ShadowsInfo) { return this._type === ShadowType.Planar; })
|
||||
@tooltip('i18n:shadow.planeHeight')
|
||||
set planeHeight (val: number) {
|
||||
this._distance = val;
|
||||
if (this._resource) { this._resource.distance = val; }
|
||||
@@ -881,8 +883,8 @@ export class ShadowsInfo {
|
||||
* @en get or set shadow max received
|
||||
* @zh 获取或者设置阴影接收的最大光源数量
|
||||
*/
|
||||
@type(CCInteger)
|
||||
@tooltip('i18n:shadow.maxReceived')
|
||||
@type(CCInteger)
|
||||
@visible(function (this: ShadowsInfo) { return this._type === ShadowType.ShadowMap; })
|
||||
set maxReceived (val: number) {
|
||||
this._maxReceived = val;
|
||||
@@ -896,8 +898,8 @@ export class ShadowsInfo {
|
||||
* @en get or set shadow map size
|
||||
* @zh 获取或者设置阴影纹理大小
|
||||
*/
|
||||
@type(ShadowSize)
|
||||
@tooltip('i18n:shadow.shadowMapSize')
|
||||
@type(ShadowSize)
|
||||
@visible(function (this: ShadowsInfo) { return this._type === ShadowType.ShadowMap; })
|
||||
set shadowMapSize (value: number) {
|
||||
this._size.set(value, value);
|
||||
|
||||
@@ -32,7 +32,7 @@ import { MaterialInstance } from '../../render-scene';
|
||||
import { SkeletonTexture } from '../skeleton-texture';
|
||||
import { getAttributeStride, vfmtPosUvColor4B, vfmtPosUvTwoColor4B } from '../../2d/renderer/vertex-format';
|
||||
import { Skeleton, SpineMaterialType } from '../skeleton';
|
||||
import { Color } from '../../core';
|
||||
import { Color, Vec3 } from '../../core';
|
||||
import { BlendFactor } from '../../gfx';
|
||||
import { legacyCC } from '../../core/global-exports';
|
||||
import { StaticVBAccessor } from '../../2d/renderer/static-vb-accessor';
|
||||
@@ -81,6 +81,7 @@ let _tempg: number;
|
||||
let _tempb: number;
|
||||
let _inRange: boolean;
|
||||
let _mustFlush: boolean;
|
||||
const _tempVecPos = new Vec3(0, 0, 0);
|
||||
let _r: number;
|
||||
let _g: number;
|
||||
let _b: number;
|
||||
@@ -274,13 +275,16 @@ function updateComponentRenderData (comp: Skeleton, batcher: Batcher2D) {
|
||||
if (nodeColor._val !== 0xffffffff || _premultipliedAlpha) {
|
||||
_needColor = true;
|
||||
}
|
||||
|
||||
let nodeMat: Mat4 | null = null;
|
||||
if (comp.enableBatch) {
|
||||
nodeMat = comp.node.worldMatrix;
|
||||
}
|
||||
if (comp.isAnimationCached()) {
|
||||
// Traverse input assembler.
|
||||
cacheTraverse();
|
||||
cacheTraverse(nodeMat);
|
||||
} else {
|
||||
if (_vertexEffect) _vertexEffect.begin(comp._skeleton);
|
||||
realTimeTraverse(batcher);
|
||||
realTimeTraverse(nodeMat);
|
||||
if (_vertexEffect) _vertexEffect.end();
|
||||
}
|
||||
// Ensure mesh buffer update
|
||||
@@ -494,7 +498,7 @@ function fillVertices (skeletonColor: spine.Color,
|
||||
}
|
||||
}
|
||||
|
||||
function realTimeTraverse (batcher: Batcher2D) {
|
||||
function realTimeTraverse (worldMat: Mat4 | null) {
|
||||
const rd = _renderData!;
|
||||
_vbuf = rd.chunk.vb;
|
||||
_vUintBuf = new Uint32Array(_vbuf.buffer, _vbuf.byteOffset, _vbuf.length);
|
||||
@@ -678,6 +682,17 @@ function realTimeTraverse (batcher: Batcher2D) {
|
||||
for (let ii = _indexOffset, nn = _indexOffset + _indexCount; ii < nn; ii++) {
|
||||
_ibuf[ii] += _vertexOffset + chunkOffset;
|
||||
}
|
||||
if (worldMat) {
|
||||
for (let ii = _vertexFloatOffset, nn = _vertexFloatOffset + _vertexFloatCount; ii < nn; ii += _perVertexSize) {
|
||||
_tempVecPos.x = _vbuf[ii];
|
||||
_tempVecPos.y = _vbuf[ii + 1];
|
||||
_tempVecPos.z = 0;
|
||||
_tempVecPos.transformMat4(worldMat);
|
||||
_vbuf[ii] = _tempVecPos.x;
|
||||
_vbuf[ii + 1] = _tempVecPos.y;
|
||||
_vbuf[ii + 2] = _tempVecPos.z;
|
||||
}
|
||||
}
|
||||
}
|
||||
_vertexFloatOffset += _vertexFloatCount;
|
||||
_vertexOffset += _vertexCount;
|
||||
@@ -720,7 +735,7 @@ function realTimeTraverse (batcher: Batcher2D) {
|
||||
}
|
||||
}
|
||||
|
||||
function cacheTraverse () {
|
||||
function cacheTraverse (worldMat: Mat4 | null) {
|
||||
const frame = _comp!._curFrame;
|
||||
if (!frame) return;
|
||||
|
||||
@@ -782,6 +797,17 @@ function cacheTraverse () {
|
||||
// Fill vertices
|
||||
segVFCount = segInfo.vfCount;
|
||||
vbuf.set(vertices.subarray(frameVFOffset, frameVFOffset + segVFCount), frameVFOffset);
|
||||
if (worldMat) {
|
||||
for (let ii = frameVFOffset, il = frameVFOffset + segVFCount; ii < il; ii += _perVertexSize) {
|
||||
_tempVecPos.x = vbuf[ii];
|
||||
_tempVecPos.y = vbuf[ii + 1];
|
||||
_tempVecPos.z = 0;
|
||||
_tempVecPos.transformMat4(worldMat);
|
||||
vbuf[ii] = _tempVecPos.x;
|
||||
vbuf[ii + 1] = _tempVecPos.y;
|
||||
vbuf[ii + 2] = _tempVecPos.z;
|
||||
}
|
||||
}
|
||||
|
||||
// Update color
|
||||
if (_needColor) {
|
||||
|
||||
@@ -27,8 +27,4 @@ import { removeProperty } from '../core/utils/x-deprecated';
|
||||
import { Skeleton } from './skeleton';
|
||||
|
||||
removeProperty(Skeleton.prototype, 'Skeleton', [
|
||||
{
|
||||
name: 'enableBatch',
|
||||
suggest: 'Not support batch render mode',
|
||||
},
|
||||
]);
|
||||
|
||||
+40
-28
@@ -445,6 +445,20 @@ export class Skeleton extends UIRenderer {
|
||||
this._updateUseTint();
|
||||
}
|
||||
}
|
||||
/*
|
||||
* @en Enabled batch model, if skeleton is complex, do not enable batch, or will lower performance.
|
||||
* @zh 开启合批,如果渲染大量相同纹理,且结构简单的骨骼动画,开启合批可以降低drawcall,否则请不要开启,cpu消耗会上升。
|
||||
*/
|
||||
@editable
|
||||
@tooltip('i18n:COMPONENT.skeleton.enabled_batch')
|
||||
get enableBatch () { return this._enableBatch; }
|
||||
set enableBatch (value) {
|
||||
if (value !== this._enableBatch) {
|
||||
this._enableBatch = value;
|
||||
this._updateBatch();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @en
|
||||
* The bone sockets this animation component maintains.<br>
|
||||
@@ -468,6 +482,7 @@ export class Skeleton extends UIRenderer {
|
||||
}
|
||||
|
||||
get socketNodes () { return this._socketNodes; }
|
||||
|
||||
// Frame cache
|
||||
/**
|
||||
* @internal
|
||||
@@ -604,6 +619,9 @@ export class Skeleton extends UIRenderer {
|
||||
@serializable
|
||||
protected defaultAnimation = '';
|
||||
|
||||
@serializable
|
||||
protected _enableBatch = false;
|
||||
|
||||
@serializable
|
||||
protected _sockets: SpineSocket[] = [];
|
||||
|
||||
@@ -1337,6 +1355,14 @@ export class Skeleton extends UIRenderer {
|
||||
super.destroyRenderData();
|
||||
}
|
||||
|
||||
private getMaterialTemplate () : Material {
|
||||
let material = this.customMaterial;
|
||||
if (material === null) {
|
||||
material = builtinResMgr.get<Material>('default-spine-material');
|
||||
}
|
||||
return material;
|
||||
}
|
||||
|
||||
public getMaterialForBlendAndTint (src: BlendFactor, dst: BlendFactor, type: SpineMaterialType): MaterialInstance {
|
||||
const key = `${type}/${src}/${dst}`;
|
||||
let inst = this._materialCache[key];
|
||||
@@ -1344,20 +1370,7 @@ export class Skeleton extends UIRenderer {
|
||||
return inst;
|
||||
}
|
||||
|
||||
let material = this.customMaterial;
|
||||
if (material === null) {
|
||||
material = builtinResMgr.get<Material>('default-spine-material');
|
||||
}
|
||||
|
||||
let useTwoColor = false;
|
||||
switch (type) {
|
||||
case SpineMaterialType.TWO_COLORED:
|
||||
useTwoColor = true;
|
||||
break;
|
||||
case SpineMaterialType.COLORED_TEXTURED:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
const material = this.getMaterialTemplate();
|
||||
const matInfo = {
|
||||
parent: material,
|
||||
subModelIdx: 0,
|
||||
@@ -1378,7 +1391,12 @@ export class Skeleton extends UIRenderer {
|
||||
}],
|
||||
},
|
||||
});
|
||||
inst.recompileShaders({ TWO_COLORED: useTwoColor, USE_LOCAL: true });
|
||||
let useTwoColor = false;
|
||||
if (type === SpineMaterialType.TWO_COLORED) {
|
||||
useTwoColor = true;
|
||||
}
|
||||
const useLocal = !this._enableBatch;
|
||||
inst.recompileShaders({ TWO_COLORED: useTwoColor, USE_LOCAL: useLocal });
|
||||
return inst;
|
||||
}
|
||||
|
||||
@@ -1416,6 +1434,7 @@ export class Skeleton extends UIRenderer {
|
||||
}
|
||||
|
||||
protected _render (batcher: Batcher2D) {
|
||||
let indicesCount = 0;
|
||||
if (this.renderData && this._drawList) {
|
||||
const rd = this.renderData;
|
||||
const chunk = rd.chunk;
|
||||
@@ -1423,20 +1442,17 @@ export class Skeleton extends UIRenderer {
|
||||
const meshBuffer = rd.getMeshBuffer()!;
|
||||
const origin = meshBuffer.indexOffset;
|
||||
// Fill index buffer
|
||||
accessor.appendIndices(chunk.bufferId, rd.indices!);
|
||||
for (let i = 0; i < this._drawList.length; i++) {
|
||||
this._drawIdx = i;
|
||||
const dc = this._drawList.data[i];
|
||||
if (dc.texture) {
|
||||
// Construct IA
|
||||
const ia = meshBuffer.requireFreeIA(batcher.device);
|
||||
ia.firstIndex = origin + dc.indexOffset;
|
||||
ia.indexCount = dc.indexCount;
|
||||
// Commit IA
|
||||
batcher.commitIA(this, ia, dc.texture, dc.material!, this.node);
|
||||
batcher.commitMiddleware(this, meshBuffer, origin + dc.indexOffset,
|
||||
dc.indexCount, dc.texture, dc.material!, this._enableBatch);
|
||||
}
|
||||
indicesCount += dc.indexCount;
|
||||
}
|
||||
// this.node._static = true;
|
||||
const subIndices = rd.indices!.subarray(0, indicesCount);
|
||||
accessor.appendIndices(chunk.bufferId, subIndices);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1559,11 +1575,7 @@ export class Skeleton extends UIRenderer {
|
||||
}
|
||||
// if change use batch mode, just clear material cache
|
||||
protected _updateBatch () {
|
||||
// let baseMaterial = this.getMaterial(0);
|
||||
// if (baseMaterial) {
|
||||
// baseMaterial.define('CC_USE_MODEL', !this.enableBatch);
|
||||
// }
|
||||
// this._materialCache = {};
|
||||
this._cleanMaterialCache();
|
||||
this.markForUpdateRenderData();
|
||||
}
|
||||
|
||||
|
||||
@@ -310,7 +310,7 @@ function packRenderData () {
|
||||
const tiledData = _curLayer.requestTiledRenderData();
|
||||
if (JSB) {
|
||||
tiledData.renderData = RenderData.add(vfmtPosUvColor, _accessor);
|
||||
tiledData.renderData.drawInfoType = RenderDrawInfoType.IA;
|
||||
tiledData.renderData.drawInfoType = RenderDrawInfoType.MIDDLEWARE;
|
||||
} else {
|
||||
tiledData.renderData = RenderData.add(vfmtPosUvColor);
|
||||
}
|
||||
|
||||
@@ -180,7 +180,7 @@ export class TiledLayer extends UIRenderer {
|
||||
private requestDrawInfo (idx: number) {
|
||||
if (!this._drawInfoList[idx]) {
|
||||
this._drawInfoList[idx] = new RenderDrawInfo();
|
||||
this._drawInfoList[idx].setDrawInfoType(RenderDrawInfoType.IA);
|
||||
this._drawInfoList[idx].setDrawInfoType(RenderDrawInfoType.MIDDLEWARE);
|
||||
}
|
||||
return this._drawInfoList[idx];
|
||||
}
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
var Module = (function() {
|
||||
var _scriptDir = typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : undefined;
|
||||
|
||||
return (
|
||||
function(Module) {
|
||||
Module = Module || {};
|
||||
|
||||
var c;c||(c=typeof Module !== 'undefined' ? Module : {});
|
||||
c.compileGLSLZeroCopy=function(a,b,d,e){d=!!d;switch(b){case "vertex":var g=0;break;case "fragment":g=4;break;case "compute":g=5;break;default:throw Error("shader_stage must be 'vertex', 'fragment', or 'compute'.");}switch(e||"1.0"){case "1.0":var f=65536;break;case "1.1":f=65792;break;case "1.2":f=66048;break;case "1.3":f=66304;break;case "1.4":f=66560;break;case "1.5":f=66816;break;default:throw Error("spirv_version must be '1.0' ~ '1.5'.");}e=c._malloc(4);b=c._malloc(4);var h=aa([a,g,d,f,e,b]);
|
||||
d=k(e);a=k(b);c._free(e);c._free(b);if(0===h)throw Error("GLSL compilation failed");e={};d/=4;e.data=c.HEAPU32.subarray(d,d+a);e.free=function(){c._destroy_output_buffer(h)};return e};c.compileGLSL=function(a,b,d,e){a=c.compileGLSLZeroCopy(a,b,d,e);b=a.data.slice();a.free();return b};var p={},q;for(q in c)c.hasOwnProperty(q)&&(p[q]=c[q]);var r="./this.program",t=!1,u=!1;t="object"===typeof window;u="function"===typeof importScripts;var v="",w;
|
||||
if(t||u)u?v=self.location.href:document.currentScript&&(v=document.currentScript.src),_scriptDir&&(v=_scriptDir),0!==v.indexOf("blob:")?v=v.substr(0,v.lastIndexOf("/")+1):v="",u&&(w=function(a){var b=new XMLHttpRequest;b.open("GET",a,!1);b.responseType="arraybuffer";b.send(null);return new Uint8Array(b.response)});var x=c.print||console.log.bind(console),y=c.printErr||console.warn.bind(console);for(q in p)p.hasOwnProperty(q)&&(c[q]=p[q]);p=null;c.thisProgram&&(r=c.thisProgram);var A;
|
||||
c.wasmBinary&&(A=c.wasmBinary);"object"!==typeof WebAssembly&&y("no native wasm support detected");function k(a){var b="i32";"*"===b.charAt(b.length-1)&&(b="i32");switch(b){case "i1":return B[a>>0];case "i8":return B[a>>0];case "i16":return ba[a>>1];case "i32":return C[a>>2];case "i64":return C[a>>2];case "float":return ca[a>>2];case "double":return da[a>>3];default:D("invalid type for getValue: "+b)}return null}var E,ea=new WebAssembly.Table({initial:859,maximum:859,element:"anyfunc"}),fa=!1;
|
||||
function ha(){var a=c._convert_glsl_to_spirv;a||D("Assertion failed: Cannot call unknown function convert_glsl_to_spirv, make sure it is exported");return a}
|
||||
function aa(a){var b="string number boolean number number number".split(" "),d={string:function(a){var b=0;if(null!==a&&void 0!==a&&0!==a){var d=(a.length<<2)+1;b=G(d);ia(a,H,b,d)}return b},array:function(a){var b=G(a.length);B.set(a,b);return b}},e=ha(),g=[],f=0;if(a)for(var h=0;h<a.length;h++){var n=d[b[h]];n?(0===f&&(f=ja()),g[h]=n(a[h])):g[h]=a[h]}a=e.apply(null,g);0!==f&&ka(f);return a}var la="undefined"!==typeof TextDecoder?new TextDecoder("utf8"):void 0;
|
||||
function I(a,b,d){var e=b+d;for(d=b;a[d]&&!(d>=e);)++d;if(16<d-b&&a.subarray&&la)return la.decode(a.subarray(b,d));for(e="";b<d;){var g=a[b++];if(g&128){var f=a[b++]&63;if(192==(g&224))e+=String.fromCharCode((g&31)<<6|f);else{var h=a[b++]&63;g=224==(g&240)?(g&15)<<12|f<<6|h:(g&7)<<18|f<<12|h<<6|a[b++]&63;65536>g?e+=String.fromCharCode(g):(g-=65536,e+=String.fromCharCode(55296|g>>10,56320|g&1023))}}else e+=String.fromCharCode(g)}return e}
|
||||
function ia(a,b,d,e){if(0<e){e=d+e-1;for(var g=0;g<a.length;++g){var f=a.charCodeAt(g);if(55296<=f&&57343>=f){var h=a.charCodeAt(++g);f=65536+((f&1023)<<10)|h&1023}if(127>=f){if(d>=e)break;b[d++]=f}else{if(2047>=f){if(d+1>=e)break;b[d++]=192|f>>6}else{if(65535>=f){if(d+2>=e)break;b[d++]=224|f>>12}else{if(d+3>=e)break;b[d++]=240|f>>18;b[d++]=128|f>>12&63}b[d++]=128|f>>6&63}b[d++]=128|f&63}}b[d]=0}}"undefined"!==typeof TextDecoder&&new TextDecoder("utf-16le");var J,B,H,ba,C,ca,da;
|
||||
function ma(a){J=a;c.HEAP8=B=new Int8Array(a);c.HEAP16=ba=new Int16Array(a);c.HEAP32=C=new Int32Array(a);c.HEAPU8=H=new Uint8Array(a);c.HEAPU16=new Uint16Array(a);c.HEAPU32=new Uint32Array(a);c.HEAPF32=ca=new Float32Array(a);c.HEAPF64=da=new Float64Array(a)}var na=c.TOTAL_MEMORY||16777216;c.wasmMemory?E=c.wasmMemory:E=new WebAssembly.Memory({initial:na/65536});E&&(J=E.buffer);na=J.byteLength;ma(J);C[84916]=5582704;
|
||||
function K(a){for(;0<a.length;){var b=a.shift();if("function"==typeof b)b();else{var d=b.J;"number"===typeof d?void 0===b.H?c.dynCall_v(d):c.dynCall_vi(d,b.H):d(void 0===b.H?null:b.H)}}}var oa=[],pa=[],qa=[],ra=[];function sa(){var a=c.preRun.shift();oa.unshift(a)}var L=0,M=null,N=null;c.preloadedImages={};c.preloadedAudios={};function D(a){if(c.onAbort)c.onAbort(a);x(a);y(a);fa=!0;throw new WebAssembly.RuntimeError("abort("+a+"). Build with -s ASSERTIONS=1 for more info.");}
|
||||
function ta(){var a=O;return String.prototype.startsWith?a.startsWith("data:application/octet-stream;base64,"):0===a.indexOf("data:application/octet-stream;base64,")}var O="glslang.wasm";if(!ta()){var ua=O;O=c.locateFile?c.locateFile(ua,v):v+ua}function wa(){try{if(A)return new Uint8Array(A);if(w)return w(O);throw"both async and sync fetching of the wasm failed";}catch(a){D(a)}}
|
||||
function xa(){return A||!t&&!u||"function"!==typeof fetch?new Promise(function(a){a(wa())}):fetch(O,{credentials:"same-origin"}).then(function(a){if(!a.ok)throw"failed to load wasm binary file at '"+O+"'";return a.arrayBuffer()}).catch(function(){return wa()})}pa.push({J:function(){ya()}});var za=[null,[],[]],P=0;function Aa(){P+=4;return C[P-4>>2]}var Q={},Ba={};
|
||||
function Ca(){if(!R){var a={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:("object"===typeof navigator&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8",_:r},b;for(b in Ba)a[b]=Ba[b];var d=[];for(b in a)d.push(b+"="+a[b]);R=d}return R}var R;function S(a){return 0===a%4&&(0!==a%100||0===a%400)}function T(a,b){for(var d=0,e=0;e<=b;d+=a[e++]);return d}var U=[31,29,31,30,31,30,31,31,30,31,30,31],W=[31,28,31,30,31,30,31,31,30,31,30,31];
|
||||
function X(a,b){for(a=new Date(a.getTime());0<b;){var d=a.getMonth(),e=(S(a.getFullYear())?U:W)[d];if(b>e-a.getDate())b-=e-a.getDate()+1,a.setDate(1),11>d?a.setMonth(d+1):(a.setMonth(0),a.setFullYear(a.getFullYear()+1));else{a.setDate(a.getDate()+b);break}}return a}
|
||||
function Da(a,b,d,e){function g(a,b,d){for(a="number"===typeof a?a.toString():a||"";a.length<b;)a=d[0]+a;return a}function f(a,b){return g(a,b,"0")}function h(a,b){function V(a){return 0>a?-1:0<a?1:0}var d;0===(d=V(a.getFullYear()-b.getFullYear()))&&0===(d=V(a.getMonth()-b.getMonth()))&&(d=V(a.getDate()-b.getDate()));return d}function n(a){switch(a.getDay()){case 0:return new Date(a.getFullYear()-1,11,29);case 1:return a;case 2:return new Date(a.getFullYear(),0,3);case 3:return new Date(a.getFullYear(),
|
||||
0,2);case 4:return new Date(a.getFullYear(),0,1);case 5:return new Date(a.getFullYear()-1,11,31);case 6:return new Date(a.getFullYear()-1,11,30)}}function z(a){a=X(new Date(a.A+1900,0,1),a.G);var b=n(new Date(a.getFullYear()+1,0,4));return 0>=h(n(new Date(a.getFullYear(),0,4)),a)?0>=h(b,a)?a.getFullYear()+1:a.getFullYear():a.getFullYear()-1}var m=C[e+40>>2];e={N:C[e>>2],M:C[e+4>>2],D:C[e+8>>2],C:C[e+12>>2],B:C[e+16>>2],A:C[e+20>>2],F:C[e+24>>2],G:C[e+28>>2],X:C[e+32>>2],L:C[e+36>>2],O:m?m?I(H,m,void 0):
|
||||
"":""};d=d?I(H,d,void 0):"";m={"%c":"%a %b %d %H:%M:%S %Y","%D":"%m/%d/%y","%F":"%Y-%m-%d","%h":"%b","%r":"%I:%M:%S %p","%R":"%H:%M","%T":"%H:%M:%S","%x":"%m/%d/%y","%X":"%H:%M:%S","%Ec":"%c","%EC":"%C","%Ex":"%m/%d/%y","%EX":"%H:%M:%S","%Ey":"%y","%EY":"%Y","%Od":"%d","%Oe":"%e","%OH":"%H","%OI":"%I","%Om":"%m","%OM":"%M","%OS":"%S","%Ou":"%u","%OU":"%U","%OV":"%V","%Ow":"%w","%OW":"%W","%Oy":"%y"};for(var l in m)d=d.replace(new RegExp(l,"g"),m[l]);var F="Sunday Monday Tuesday Wednesday Thursday Friday Saturday".split(" "),
|
||||
va="January February March April May June July August September October November December".split(" ");m={"%a":function(a){return F[a.F].substring(0,3)},"%A":function(a){return F[a.F]},"%b":function(a){return va[a.B].substring(0,3)},"%B":function(a){return va[a.B]},"%C":function(a){return f((a.A+1900)/100|0,2)},"%d":function(a){return f(a.C,2)},"%e":function(a){return g(a.C,2," ")},"%g":function(a){return z(a).toString().substring(2)},"%G":function(a){return z(a)},"%H":function(a){return f(a.D,2)},
|
||||
"%I":function(a){a=a.D;0==a?a=12:12<a&&(a-=12);return f(a,2)},"%j":function(a){return f(a.C+T(S(a.A+1900)?U:W,a.B-1),3)},"%m":function(a){return f(a.B+1,2)},"%M":function(a){return f(a.M,2)},"%n":function(){return"\n"},"%p":function(a){return 0<=a.D&&12>a.D?"AM":"PM"},"%S":function(a){return f(a.N,2)},"%t":function(){return"\t"},"%u":function(a){return a.F||7},"%U":function(a){var b=new Date(a.A+1900,0,1),d=0===b.getDay()?b:X(b,7-b.getDay());a=new Date(a.A+1900,a.B,a.C);return 0>h(d,a)?f(Math.ceil((31-
|
||||
d.getDate()+(T(S(a.getFullYear())?U:W,a.getMonth()-1)-31)+a.getDate())/7),2):0===h(d,b)?"01":"00"},"%V":function(a){var b=n(new Date(a.A+1900,0,4)),d=n(new Date(a.A+1901,0,4)),e=X(new Date(a.A+1900,0,1),a.G);return 0>h(e,b)?"53":0>=h(d,e)?"01":f(Math.ceil((b.getFullYear()<a.A+1900?a.G+32-b.getDate():a.G+1-b.getDate())/7),2)},"%w":function(a){return a.F},"%W":function(a){var b=new Date(a.A,0,1),d=1===b.getDay()?b:X(b,0===b.getDay()?1:7-b.getDay()+1);a=new Date(a.A+1900,a.B,a.C);return 0>h(d,a)?f(Math.ceil((31-
|
||||
d.getDate()+(T(S(a.getFullYear())?U:W,a.getMonth()-1)-31)+a.getDate())/7),2):0===h(d,b)?"01":"00"},"%y":function(a){return(a.A+1900).toString().substring(2)},"%Y":function(a){return a.A+1900},"%z":function(a){a=a.L;var b=0<=a;a=Math.abs(a)/60;return(b?"+":"-")+String("0000"+(a/60*100+a%60)).slice(-4)},"%Z":function(a){return a.O},"%%":function(){return"%"}};for(l in m)0<=d.indexOf(l)&&(d=d.replace(new RegExp(l,"g"),m[l](e)));l=Ea(d);if(l.length>b)return 0;B.set(l,a);return l.length-1}
|
||||
function Ea(a){for(var b=0,d=0;d<a.length;++d){var e=a.charCodeAt(d);55296<=e&&57343>=e&&(e=65536+((e&1023)<<10)|a.charCodeAt(++d)&1023);127>=e?++b:b=2047>=e?b+2:65535>=e?b+3:b+4}b=Array(b+1);ia(a,b,0,b.length);return b}
|
||||
var Ga={f:function(){},c:function(){c.___errno_location&&(C[c.___errno_location()>>2]=63);return-1},n:function(a,b){P=b;try{var d=Aa();var e=Aa();if(-1===d||0===e)var g=-28;else{var f=Q.K[d];if(f&&e===f.U){var h=(void 0).T(f.S);Q.R(d,h,e,f.flags,f.offset);(void 0).W(h);Q.K[d]=null;f.P&&Fa(f.V)}g=0}return g}catch(n){return D(n),-n.I}},a:function(){},b:function(){D()},k:function(a,b,d){H.set(H.subarray(b,b+d),a)},l:function(a){var b=B.length;if(2147418112<a)return!1;for(var d=1;4>=d;d*=2){var e=b*(1+
|
||||
.2/d);e=Math.min(e,a+100663296);e=Math.max(16777216,a,e);0<e%65536&&(e+=65536-e%65536);a:{try{E.grow(Math.min(2147418112,e)-J.byteLength+65535>>16);ma(E.buffer);var g=1;break a}catch(f){}g=void 0}if(g)return!0}return!1},d:function(a,b){var d=0;Ca().forEach(function(e,g){var f=b+d;g=C[a+4*g>>2]=f;for(f=0;f<e.length;++f)B[g++>>0]=e.charCodeAt(f);B[g>>0]=0;d+=e.length+1});return 0},e:function(a,b){var d=Ca();C[a>>2]=d.length;var e=0;d.forEach(function(a){e+=a.length+1});C[b>>2]=e;return 0},h:function(){return 0},
|
||||
j:function(){return 0},g:function(a,b,d,e){try{for(var g=0,f=0;f<d;f++){for(var h=C[b+8*f>>2],n=C[b+(8*f+4)>>2],z=0;z<n;z++){var m=H[h+z],l=za[a];0===m||10===m?((1===a?x:y)(I(l,0)),l.length=0):l.push(m)}g+=n}C[e>>2]=g;return 0}catch(F){return D(F),F.I}},memory:E,o:function(){},i:function(){},m:function(a,b,d,e){return Da(a,b,d,e)},table:ea},Ha=function(){function a(a){c.asm=a.exports;L--;c.monitorRunDependencies&&c.monitorRunDependencies(L);0==L&&(null!==M&&(clearInterval(M),M=null),N&&(a=N,N=null,
|
||||
a()))}function b(b){a(b.instance)}function d(a){return xa().then(function(a){return WebAssembly.instantiate(a,e)}).then(a,function(a){y("failed to asynchronously prepare wasm: "+a);D(a)})}var e={env:Ga,wasi_snapshot_preview1:Ga};L++;c.monitorRunDependencies&&c.monitorRunDependencies(L);if(c.instantiateWasm)try{return c.instantiateWasm(e,a)}catch(g){return y("Module.instantiateWasm callback failed with error: "+g),!1}(function(){if(A||"function"!==typeof WebAssembly.instantiateStreaming||ta()||"function"!==
|
||||
typeof fetch)return d(b);fetch(O,{credentials:"same-origin"}).then(function(a){return WebAssembly.instantiateStreaming(a,e).then(b,function(a){y("wasm streaming compile failed: "+a);y("falling back to ArrayBuffer instantiation");d(b)})})})();return{}}();c.asm=Ha;var ya=c.___wasm_call_ctors=function(){return(ya=c.___wasm_call_ctors=c.asm.p).apply(null,arguments)};c._convert_glsl_to_spirv=function(){return(c._convert_glsl_to_spirv=c.asm.q).apply(null,arguments)};
|
||||
c._destroy_output_buffer=function(){return(c._destroy_output_buffer=c.asm.r).apply(null,arguments)};c._malloc=function(){return(c._malloc=c.asm.s).apply(null,arguments)};var Fa=c._free=function(){return(Fa=c._free=c.asm.t).apply(null,arguments)},ja=c.stackSave=function(){return(ja=c.stackSave=c.asm.u).apply(null,arguments)},G=c.stackAlloc=function(){return(G=c.stackAlloc=c.asm.v).apply(null,arguments)},ka=c.stackRestore=function(){return(ka=c.stackRestore=c.asm.w).apply(null,arguments)};
|
||||
c.dynCall_vi=function(){return(c.dynCall_vi=c.asm.x).apply(null,arguments)};c.dynCall_v=function(){return(c.dynCall_v=c.asm.y).apply(null,arguments)};c.asm=Ha;var Y;c.then=function(a){if(Y)a(c);else{var b=c.onRuntimeInitialized;c.onRuntimeInitialized=function(){b&&b();a(c)}}return c};N=function Ia(){Y||Z();Y||(N=Ia)};
|
||||
function Z(){function a(){if(!Y&&(Y=!0,!fa)){K(pa);K(qa);if(c.onRuntimeInitialized)c.onRuntimeInitialized();if(c.postRun)for("function"==typeof c.postRun&&(c.postRun=[c.postRun]);c.postRun.length;){var a=c.postRun.shift();ra.unshift(a)}K(ra)}}if(!(0<L)){if(c.preRun)for("function"==typeof c.preRun&&(c.preRun=[c.preRun]);c.preRun.length;)sa();K(oa);0<L||(c.setStatus?(c.setStatus("Running..."),setTimeout(function(){setTimeout(function(){c.setStatus("")},1);a()},1)):a())}}c.run=Z;
|
||||
if(c.preInit)for("function"==typeof c.preInit&&(c.preInit=[c.preInit]);0<c.preInit.length;)c.preInit.pop()();Z();
|
||||
|
||||
|
||||
return Module
|
||||
}
|
||||
);
|
||||
})();
|
||||
// if (typeof exports === 'object' && typeof module === 'object')
|
||||
// module.exports = Module;
|
||||
// else if (typeof define === 'function' && define['amd'])
|
||||
// define([], function() { return Module; });
|
||||
// else if (typeof exports === 'object')
|
||||
// exports["Module"] = Module;
|
||||
// export default (() => {
|
||||
// const initialize = () => {
|
||||
// return new Promise(resolve => {
|
||||
// Module({
|
||||
// locateFile() {
|
||||
// const i = import.meta.url.lastIndexOf('/')
|
||||
// return import.meta.url.substring(0, i) + '/glslang.wasm';
|
||||
// },
|
||||
// onRuntimeInitialized() {
|
||||
// resolve({
|
||||
// compileGLSLZeroCopy: this.compileGLSLZeroCopy,
|
||||
// compileGLSL: this.compileGLSL,
|
||||
// });
|
||||
// },
|
||||
// });
|
||||
// });
|
||||
// };
|
||||
|
||||
// let instance;
|
||||
// return () => {
|
||||
// if (!instance) {
|
||||
// instance = initialize();
|
||||
// }
|
||||
// return instance;
|
||||
// };
|
||||
// })();
|
||||
// (function tryToExport(root, factory) {
|
||||
// if (typeof exports === 'object' && typeof module === 'object')
|
||||
// module.exports = factory();
|
||||
// else if (typeof define === 'function' && define.amd)
|
||||
// define("glslang", [], factory);
|
||||
// else if (typeof exports === 'object')
|
||||
// exports["glslang"] = factory();
|
||||
// else
|
||||
// root["glslang"] = factory();
|
||||
// })(typeof self !== "undefined" ? self : typeof global !== "undefined" ? global : this, () => {
|
||||
// const initialize = (wasmPath) => {
|
||||
// wasmPath = 'http://localhost:7456/glslang.wasm'
|
||||
// return new Promise(resolve => {
|
||||
// Module({
|
||||
// locateFile() {
|
||||
// return wasmPath;
|
||||
// },
|
||||
// onRuntimeInitialized() {
|
||||
// resolve({
|
||||
// compileGLSLZeroCopy: this.compileGLSLZeroCopy,
|
||||
// compileGLSL: this.compileGLSL,
|
||||
// });
|
||||
// },
|
||||
// });
|
||||
// });
|
||||
// };
|
||||
|
||||
// let instance;
|
||||
// return (wasmPath) => {
|
||||
// if (!instance) {
|
||||
// instance = initialize(wasmPath);
|
||||
// }
|
||||
// return instance;
|
||||
// };
|
||||
// });
|
||||
|
||||
|
||||
const initialize = (wasmPath) => {
|
||||
return new Promise(resolve => {
|
||||
Module({
|
||||
locateFile() {
|
||||
return wasmPath;
|
||||
},
|
||||
onRuntimeInitialized() {
|
||||
resolve({
|
||||
compileGLSLZeroCopy: this.compileGLSLZeroCopy,
|
||||
compileGLSL: this.compileGLSL,
|
||||
});
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
let instance;
|
||||
export default (wasmPath) => {
|
||||
if (!instance) {
|
||||
instance = initialize(wasmPath);
|
||||
}
|
||||
return instance;
|
||||
};
|
||||
@@ -0,0 +1,89 @@
|
||||
/* eslint-disable @typescript-eslint/no-floating-promises */
|
||||
/* eslint-disable no-void */
|
||||
/*
|
||||
Copyright (c) 2022 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
https://www.cocos.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
import { WEBGPU } from 'internal:constants';
|
||||
import webgpuUrl from 'url:native/external/emscripten/webgpu/webgpu_wasm.wasm';
|
||||
import glslangUrl from 'url:native/external/emscripten/webgpu/glslang.wasm';
|
||||
import wasmDevice from './webgpu_wasm.js';
|
||||
import glslangLoader from './glslang.js';
|
||||
import { legacyCC } from '../core/global-exports';
|
||||
|
||||
export const glslalgWasmModule: any = {
|
||||
glslang: null,
|
||||
};
|
||||
|
||||
export const gfx: any = legacyCC.gfx = {
|
||||
wasmBinary: null,
|
||||
nativeDevice: null,
|
||||
};
|
||||
|
||||
export const webgpuAdapter: any = {
|
||||
adapter: null,
|
||||
device: null,
|
||||
};
|
||||
|
||||
export const promiseForWebGPUInstantiation = (() => {
|
||||
if (WEBGPU) {
|
||||
return Promise.all([
|
||||
// @ts-expect-error The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.
|
||||
glslangLoader(new URL(glslangUrl, import.meta.url).href).then((res) => {
|
||||
glslalgWasmModule.glslang = res;
|
||||
}),
|
||||
new Promise<void>((resolve) => {
|
||||
// @ts-expect-error The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.
|
||||
fetch(new URL(webgpuUrl, import.meta.url).href).then((response) => {
|
||||
response.arrayBuffer().then((buffer) => {
|
||||
gfx.wasmBinary = buffer;
|
||||
wasmDevice(gfx).then(() => {
|
||||
legacyCC.WebGPUDevice = gfx.CCWGPUDevice;
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
});
|
||||
}),
|
||||
new Promise<void>((resolve) => {
|
||||
(navigator as any).gpu.requestAdapter().then((adapter) => {
|
||||
adapter.requestDevice().then((device) => {
|
||||
webgpuAdapter.adapter = adapter;
|
||||
webgpuAdapter.device = device;
|
||||
console.log(gfx);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}),
|
||||
]).then(() => Promise.resolve());
|
||||
}
|
||||
return Promise.resolve();
|
||||
})();
|
||||
|
||||
if (WEBGPU) {
|
||||
const intervalId = setInterval(() => {
|
||||
if (legacyCC.game) {
|
||||
legacyCC.game.onPreInfrastructureInitDelegate.add(() => promiseForWebGPUInstantiation);
|
||||
clearInterval(intervalId);
|
||||
}
|
||||
}, 10);
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"ver": "1.0.24",
|
||||
"ver": "1.0.25",
|
||||
"importer": "image",
|
||||
"imported": true,
|
||||
"uuid": "b5b27ab1-e740-4398-b407-848fc2b2c897",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"ver": "1.0.6",
|
||||
"ver": "1.0.7",
|
||||
"importer": "effect-header",
|
||||
"imported": true,
|
||||
"uuid": "02a04bf3-4c27-4596-81fd-dfc35224f1d1",
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#include <common/common-define> // decode32
|
||||
#include <builtin/uniforms/cc-morph>
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"ver": "1.0.6",
|
||||
"ver": "1.0.7",
|
||||
"importer": "effect-header",
|
||||
"imported": true,
|
||||
"uuid": "3adaa06a-e674-487c-9d49-42bc398c255b",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"ver": "1.0.6",
|
||||
"ver": "1.0.7",
|
||||
"importer": "effect-header",
|
||||
"imported": true,
|
||||
"uuid": "d4c26490-0a2d-4b6a-9a52-55b5741f18a4",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"ver": "1.0.6",
|
||||
"ver": "1.0.7",
|
||||
"importer": "effect-header",
|
||||
"imported": true,
|
||||
"uuid": "80908463-4566-4fdf-9744-775605cd7ab7",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"ver": "1.0.6",
|
||||
"ver": "1.0.7",
|
||||
"importer": "effect-header",
|
||||
"imported": true,
|
||||
"uuid": "258a17ce-6c50-4e8a-92aa-8ecec1a6af24",
|
||||
|
||||
@@ -9,8 +9,6 @@ void CCGetWorldMatrix(out mat4 matWorld)
|
||||
vec4(a_matWorld2.xyz, 0.0),
|
||||
vec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)
|
||||
);
|
||||
#elif USE_BATCHING
|
||||
matWorld = cc_matWorlds[int(a_dyn_batch_id)];
|
||||
#else
|
||||
matWorld = cc_matWorld;
|
||||
#endif
|
||||
@@ -26,9 +24,6 @@ void CCGetWorldMatrixFull(out mat4 matWorld, out mat4 matWorldIT)
|
||||
vec4(a_matWorld0.w, a_matWorld1.w, a_matWorld2.w, 1.0)
|
||||
);
|
||||
matWorldIT = matWorld;
|
||||
#elif USE_BATCHING
|
||||
matWorld = cc_matWorlds[int(a_dyn_batch_id)];
|
||||
matWorldIT = matWorld;
|
||||
#else
|
||||
matWorld = cc_matWorld;
|
||||
matWorldIT = cc_matWorldIT;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"ver": "1.0.6",
|
||||
"ver": "1.0.7",
|
||||
"importer": "effect-header",
|
||||
"imported": true,
|
||||
"uuid": "c2885f54-4ff2-4284-8bbc-b77bc71965b4",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"ver": "1.0.6",
|
||||
"ver": "1.0.7",
|
||||
"importer": "effect-header",
|
||||
"imported": true,
|
||||
"uuid": "2c3da5b6-0202-470a-a915-59f1e2968853",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"ver": "1.0.6",
|
||||
"ver": "1.0.7",
|
||||
"importer": "effect-header",
|
||||
"imported": true,
|
||||
"uuid": "ef4fb7de-9b39-4eeb-9ae8-d292ff94a452",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"ver": "1.0.6",
|
||||
"ver": "1.0.7",
|
||||
"importer": "effect-header",
|
||||
"imported": true,
|
||||
"uuid": "7a49db3a-930e-4ffc-8659-a82141dabebb",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"ver": "1.0.6",
|
||||
"ver": "1.0.7",
|
||||
"importer": "effect-header",
|
||||
"imported": true,
|
||||
"uuid": "df7d02d8-559a-4c02-9aac-3732cfc83d7a",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"ver": "1.0.6",
|
||||
"ver": "1.0.7",
|
||||
"importer": "effect-header",
|
||||
"imported": true,
|
||||
"uuid": "b4b00c01-eca8-4ae4-a04d-e00bbeb6d0e0",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"ver": "1.0.6",
|
||||
"ver": "1.0.7",
|
||||
"importer": "effect-header",
|
||||
"imported": true,
|
||||
"uuid": "6e1b48cb-69c8-448c-8055-69ab9793fbab",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"ver": "1.0.6",
|
||||
"ver": "1.0.7",
|
||||
"importer": "effect-header",
|
||||
"imported": true,
|
||||
"uuid": "35822e78-bb35-405f-87bd-d42af6ac9ede",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"ver": "1.0.6",
|
||||
"ver": "1.0.7",
|
||||
"importer": "effect-header",
|
||||
"imported": true,
|
||||
"uuid": "4b48672e-e044-4035-9029-13afb50c1aee",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"ver": "1.0.6",
|
||||
"ver": "1.0.7",
|
||||
"importer": "effect-header",
|
||||
"imported": true,
|
||||
"uuid": "c3e3500f-370c-4da1-92f9-d0d9fd806bd8",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"ver": "1.0.6",
|
||||
"ver": "1.0.7",
|
||||
"importer": "effect-header",
|
||||
"imported": true,
|
||||
"uuid": "17e8e047-4c5e-412c-85c8-a76a98742f2a",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"ver": "1.0.6",
|
||||
"ver": "1.0.7",
|
||||
"importer": "effect-header",
|
||||
"imported": true,
|
||||
"uuid": "cd94308c-6959-4671-9dcb-6c58342273e2",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"ver": "1.0.6",
|
||||
"ver": "1.0.7",
|
||||
"importer": "effect-header",
|
||||
"imported": true,
|
||||
"uuid": "5e0f5e6e-5008-497f-b223-4e5f1801d8fd",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"ver": "1.0.6",
|
||||
"ver": "1.0.7",
|
||||
"importer": "effect-header",
|
||||
"imported": true,
|
||||
"uuid": "1ea907a3-a36e-432a-ae38-af712c77aaad",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"ver": "1.0.6",
|
||||
"ver": "1.0.7",
|
||||
"importer": "effect-header",
|
||||
"imported": true,
|
||||
"uuid": "fa1c0cd1-03c6-45dd-8294-bf7a1e21aad4",
|
||||
|
||||
@@ -1,13 +1,5 @@
|
||||
// Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
#if !USE_INSTANCING
|
||||
#if USE_BATCHING
|
||||
#pragma define BATCHING_COUNT 10
|
||||
#pragma builtin(local)
|
||||
layout(set = 2, binding = 0) uniform CCLocalBatched {
|
||||
highp mat4 cc_matWorlds[BATCHING_COUNT];
|
||||
};
|
||||
#else
|
||||
#include <builtin/uniforms/cc-local>
|
||||
#endif
|
||||
#include <builtin/uniforms/cc-local>
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"ver": "1.0.6",
|
||||
"ver": "1.0.7",
|
||||
"importer": "effect-header",
|
||||
"imported": true,
|
||||
"uuid": "21b24bc9-a158-488e-b27c-b98a461fb438",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"ver": "1.0.6",
|
||||
"ver": "1.0.7",
|
||||
"importer": "effect-header",
|
||||
"imported": true,
|
||||
"uuid": "e835c2d5-a377-4197-bdb8-382037573494",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"ver": "1.0.6",
|
||||
"ver": "1.0.7",
|
||||
"importer": "effect-header",
|
||||
"imported": true,
|
||||
"uuid": "94d19070-32c6-4900-a288-2258fda37f29",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"ver": "1.0.6",
|
||||
"ver": "1.0.7",
|
||||
"importer": "effect-header",
|
||||
"imported": true,
|
||||
"uuid": "e8411010-e411-43ab-8f2e-4f4865dca4cf",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"ver": "1.0.6",
|
||||
"ver": "1.0.7",
|
||||
"importer": "effect-header",
|
||||
"imported": true,
|
||||
"uuid": "69f8ecd8-cdc9-4655-a6ec-d39dacdffc2f",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"ver": "1.0.6",
|
||||
"ver": "1.0.7",
|
||||
"importer": "effect-header",
|
||||
"imported": true,
|
||||
"uuid": "99488fd6-220b-4d13-9a41-8b9439cd3944",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"ver": "1.0.6",
|
||||
"ver": "1.0.7",
|
||||
"importer": "effect-header",
|
||||
"imported": true,
|
||||
"uuid": "669458fe-c428-40cd-8575-51607aa8edbc",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"ver": "1.0.6",
|
||||
"ver": "1.0.7",
|
||||
"importer": "effect-header",
|
||||
"imported": true,
|
||||
"uuid": "7efbe295-0202-4979-8cda-6cfe35e086cf",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"ver": "1.0.6",
|
||||
"ver": "1.0.7",
|
||||
"importer": "effect-header",
|
||||
"imported": true,
|
||||
"uuid": "bb213412-2e68-43b3-9de5-73ca332acace",
|
||||
|
||||
@@ -43,17 +43,7 @@
|
||||
#pragma define CC_HANDLE_RT_SAMPLE_FLIP(uv) uv = cc_cameraPos.w > 1.0 ? vec2(uv.x, 1.0 - uv.y) : uv
|
||||
#pragma define CC_HANDLE_GET_CLIP_FLIP(uv) uv = cc_cameraPos.w == 0.0 ? vec2(uv.x, -uv.y) : uv
|
||||
|
||||
#pragma define STEP_FINT_128(v) (step(128.0, (v) + 0.5))
|
||||
#pragma define MOD_FINT_128(v) (mod(float(int((v) + 0.5)), 128.0))
|
||||
|
||||
highp float decode32 (highp vec4 rgba) {
|
||||
rgba = rgba * 255.0;
|
||||
highp float Sign = 1.0 - STEP_FINT_128(rgba[3]) * 2.0;
|
||||
highp float Exponent = 2.0 * MOD_FINT_128(rgba[3]) + STEP_FINT_128(rgba[2]) - 127.0;
|
||||
highp float Mantissa = MOD_FINT_128(rgba[2]) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;
|
||||
return Sign * exp2(Exponent - 23.0) * Mantissa;
|
||||
}
|
||||
|
||||
float isNan(float val) {
|
||||
return (val <= 0.0 || 0.0 <= val) ? 0.0 : 1.0;
|
||||
}
|
||||
// CC_USE_LIGHTMAP Values
|
||||
#define CC_LIGHTMAP_DISABLED 0
|
||||
#define CC_LIGHTMAP_ALL_IN_ONE 1
|
||||
#define CC_LIGHTMAP_CC_LIGHTMAP_INDIRECT_OCCLUSION 2
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"ver": "1.0.6",
|
||||
"ver": "1.0.7",
|
||||
"importer": "effect-header",
|
||||
"imported": true,
|
||||
"uuid": "9d86a3e4-ec06-4e51-ba68-45f2b7739fbb",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"ver": "1.0.6",
|
||||
"ver": "1.0.7",
|
||||
"importer": "effect-header",
|
||||
"imported": true,
|
||||
"uuid": "73866dd2-eaf5-40af-a061-1b9d38782204",
|
||||
|
||||
@@ -1,5 +1,17 @@
|
||||
// Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
#pragma define STEP_FINT_128(v) (step(128.0, (v) + 0.5))
|
||||
#pragma define MOD_FINT_128(v) (mod(float(int((v) + 0.5)), 128.0))
|
||||
|
||||
highp float decode32 (highp vec4 rgba) {
|
||||
rgba = rgba * 255.0;
|
||||
highp float Sign = 1.0 - STEP_FINT_128(rgba[3]) * 2.0;
|
||||
highp float Exponent = 2.0 * MOD_FINT_128(rgba[3]) + STEP_FINT_128(rgba[2]) - 127.0;
|
||||
highp float Mantissa = MOD_FINT_128(rgba[2]) * 65536.0 + rgba[1] * 256.0 + rgba[0] + 8388608.0;
|
||||
return Sign * exp2(Exponent - 23.0) * Mantissa;
|
||||
}
|
||||
|
||||
|
||||
vec4 packRGBE (vec3 rgb) {
|
||||
highp float maxComp = max(max(rgb.r, rgb.g), rgb.b);
|
||||
highp float e = 128.0;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"ver": "1.0.6",
|
||||
"ver": "1.0.7",
|
||||
"importer": "effect-header",
|
||||
"imported": true,
|
||||
"uuid": "e3e5d086-acc9-4dd8-98e8-24ac02f547d5",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"ver": "1.0.6",
|
||||
"ver": "1.0.7",
|
||||
"importer": "effect-header",
|
||||
"imported": true,
|
||||
"uuid": "9c973ee8-952a-4ee3-a617-ba6397db6bac",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"ver": "1.0.6",
|
||||
"ver": "1.0.7",
|
||||
"importer": "effect-header",
|
||||
"imported": true,
|
||||
"uuid": "399f5890-dde1-40de-9751-a7aa91a56b93",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"ver": "1.0.6",
|
||||
"ver": "1.0.7",
|
||||
"importer": "effect-header",
|
||||
"imported": true,
|
||||
"uuid": "077cca29-6f66-4aad-a3a7-4f0a7ecd523f",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"ver": "1.0.6",
|
||||
"ver": "1.0.7",
|
||||
"importer": "effect-header",
|
||||
"imported": true,
|
||||
"uuid": "3a85eafd-0fd0-468f-8a2e-0c81493230c7",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"ver": "1.0.6",
|
||||
"ver": "1.0.7",
|
||||
"importer": "effect-header",
|
||||
"imported": true,
|
||||
"uuid": "d360c347-a546-4967-bdd3-30cae323f123",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"ver": "1.0.6",
|
||||
"ver": "1.0.7",
|
||||
"importer": "effect-header",
|
||||
"imported": true,
|
||||
"uuid": "00e591cd-469d-4611-adb9-a5ca965a0552",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"ver": "1.0.6",
|
||||
"ver": "1.0.7",
|
||||
"importer": "effect-header",
|
||||
"imported": true,
|
||||
"uuid": "a24fb7a1-f7a5-430c-a8b2-e4c516131086",
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user