@zephyr3d/scene 0.9.8 → 0.9.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"esm.js","sources":["../../src/shadow/esm.ts"],"sourcesContent":["import type { FrameBuffer, TextureFormat, PBShaderExp, PBInsideFunctionScope } from '@zephyr3d/device';\nimport { ShadowImpl } from './shadow_impl';\nimport type { BlitType } from '../blitter';\nimport { GaussianBlurBlitter } from '../blitter';\nimport { computeShadowMapDepth, filterShadowESM } from '../shaders/shadow';\nimport { decodeNormalizedFloatFromRGBA, encodeNormalizedFloatToRGBA } from '../shaders/misc';\nimport { LIGHT_TYPE_POINT } from '../values';\nimport type { ShadowMapParams, ShadowMapType } from './shadowmapper';\nimport { ShaderHelper } from '../material/shader/helper';\nimport { getDevice } from '../app/api';\nimport { Vector4, type Nullable } from '@zephyr3d/base';\nimport { computeShadowBias, computeShadowBiasCSM } from './shader';\n\ntype ESMImplData = {\n blurFramebuffer: Nullable<FrameBuffer>;\n blurFramebuffer2: Nullable<FrameBuffer>;\n};\n\nclass BlurBlitter extends GaussianBlurBlitter {\n protected _packFloat = false;\n get packFloat() {\n return this._packFloat;\n }\n set packFloat(b) {\n if (this._packFloat !== !!b) {\n this._packFloat = !!b;\n this.invalidateHash();\n }\n }\n readTexel(\n scope: PBInsideFunctionScope,\n type: BlitType,\n srcTex: PBShaderExp,\n srcUV: PBShaderExp,\n srcLayer: PBShaderExp,\n sampleType: 'float' | 'int' | 'uint'\n ) {\n const pb = scope.$builder;\n const texel = super.readTexel(scope, type, srcTex, srcUV, srcLayer, sampleType);\n if (this.packFloat) {\n return pb.vec4(decodeNormalizedFloatFromRGBA(scope, texel), 1, 0, 1);\n } else {\n return texel;\n }\n }\n filter(\n scope: PBInsideFunctionScope,\n type: BlitType,\n srcTex: PBShaderExp,\n srcUV: PBShaderExp,\n srcLayer: PBShaderExp,\n sampleType: 'float' | 'int' | 'uint'\n ) {\n const that = this;\n const pb = scope.$builder;\n scope.incrementalGaussian = pb.vec3();\n scope.incrementalGaussian.x = pb.div(1, pb.mul(scope.sigma, Math.sqrt(2 * Math.PI)));\n scope.incrementalGaussian.y = pb.exp(pb.div(-0.5, pb.mul(scope.sigma, scope.sigma)));\n scope.incrementalGaussian.z = pb.mul(scope.incrementalGaussian.y, scope.incrementalGaussian.y);\n scope.coefficientSum = pb.float(0);\n scope.coverageSum = pb.float(0);\n scope.d0 = that.readTexel(scope, type, srcTex, srcUV, srcLayer, sampleType);\n scope.coverage0 = pb.clamp(scope.d0.y, 0, 1);\n scope.coefficientSum = pb.add(scope.coefficientSum, scope.incrementalGaussian.x);\n scope.coverageSum = pb.add(scope.coverageSum, pb.mul(scope.incrementalGaussian.x, scope.coverage0));\n\n if (that.logSpace) {\n scope.maxLogValue = pb.float(-1e20);\n scope.logValue0 = that._phase === 'horizonal' ? pb.mul(scope.d0.x, scope.multiplier) : scope.d0.x;\n scope.$if(pb.greaterThan(scope.coverage0, 0.000001), function () {\n this.maxLogValue = this.logValue0;\n });\n } else {\n scope.depthSum = pb.mul(scope.incrementalGaussian.x, scope.coverage0, scope.d0.x);\n }\n\n scope.incrementalGaussian = pb.vec3(\n pb.mul(scope.incrementalGaussian.xy, scope.incrementalGaussian.yz),\n scope.incrementalGaussian.z\n );\n scope.$for(pb.float('i'), 1, scope.numBlurPixelsPerSide, function () {\n this.$l.blurOffset = pb.mul(this.blurMultiplyVec, this.blurSize, this.i);\n this.$l.d1 = that.readTexel(scope, type, srcTex, pb.sub(srcUV, this.blurOffset), srcLayer, sampleType);\n this.$l.d2 = that.readTexel(scope, type, srcTex, pb.add(srcUV, this.blurOffset), srcLayer, sampleType);\n this.$l.coverage1 = pb.clamp(this.d1.y, 0, 1);\n this.$l.coverage2 = pb.clamp(this.d2.y, 0, 1);\n this.coefficientSum = pb.add(this.coefficientSum, pb.mul(this.incrementalGaussian.x, 2));\n this.coverageSum = pb.add(\n this.coverageSum,\n pb.mul(this.incrementalGaussian.x, pb.add(this.coverage1, this.coverage2))\n );\n if (that.logSpace) {\n this.$l.logValue1 = that._phase === 'horizonal' ? pb.mul(this.d1.x, this.multiplier) : this.d1.x;\n this.$l.logValue2 = that._phase === 'horizonal' ? pb.mul(this.d2.x, this.multiplier) : this.d2.x;\n this.$if(pb.greaterThan(this.coverage1, 0.000001), function () {\n this.maxLogValue = pb.max(this.maxLogValue, this.logValue1);\n });\n this.$if(pb.greaterThan(this.coverage2, 0.000001), function () {\n this.maxLogValue = pb.max(this.maxLogValue, this.logValue2);\n });\n } else {\n this.depthSum = pb.add(\n this.depthSum,\n pb.mul(\n this.incrementalGaussian.x,\n pb.add(pb.mul(this.coverage1, this.d1.x), pb.mul(this.coverage2, this.d2.x))\n )\n );\n }\n this.incrementalGaussian = pb.vec3(\n pb.mul(this.incrementalGaussian.xy, this.incrementalGaussian.yz),\n this.incrementalGaussian.z\n );\n });\n\n if (that.logSpace) {\n scope.incrementalGaussian.x = pb.div(1, pb.mul(scope.sigma, Math.sqrt(2 * Math.PI)));\n scope.incrementalGaussian.y = pb.exp(pb.div(-0.5, pb.mul(scope.sigma, scope.sigma)));\n scope.incrementalGaussian.z = pb.mul(scope.incrementalGaussian.y, scope.incrementalGaussian.y);\n scope.momentSum = pb.float(0);\n scope.$if(pb.greaterThan(scope.coverage0, 0.000001), function () {\n this.momentSum = pb.add(\n this.momentSum,\n pb.mul(\n this.incrementalGaussian.x,\n this.coverage0,\n pb.exp(pb.min(87, pb.sub(this.logValue0, this.maxLogValue)))\n )\n );\n });\n scope.incrementalGaussian = pb.vec3(\n pb.mul(scope.incrementalGaussian.xy, scope.incrementalGaussian.yz),\n scope.incrementalGaussian.z\n );\n scope.$for(pb.float('i'), 1, scope.numBlurPixelsPerSide, function () {\n this.$l.blurOffset = pb.mul(this.blurMultiplyVec, this.blurSize, this.i);\n this.$l.d1 = that.readTexel(\n scope,\n type,\n srcTex,\n pb.sub(srcUV, this.blurOffset),\n srcLayer,\n sampleType\n );\n this.$l.d2 = that.readTexel(\n scope,\n type,\n srcTex,\n pb.add(srcUV, this.blurOffset),\n srcLayer,\n sampleType\n );\n this.$l.coverage1 = pb.clamp(this.d1.y, 0, 1);\n this.$l.coverage2 = pb.clamp(this.d2.y, 0, 1);\n this.$l.logValue1 = that._phase === 'horizonal' ? pb.mul(this.d1.x, this.multiplier) : this.d1.x;\n this.$l.logValue2 = that._phase === 'horizonal' ? pb.mul(this.d2.x, this.multiplier) : this.d2.x;\n this.$if(pb.greaterThan(this.coverage1, 0.000001), function () {\n this.momentSum = pb.add(\n this.momentSum,\n pb.mul(\n this.incrementalGaussian.x,\n this.coverage1,\n pb.exp(pb.min(87, pb.sub(this.logValue1, this.maxLogValue)))\n )\n );\n });\n this.$if(pb.greaterThan(this.coverage2, 0.000001), function () {\n this.momentSum = pb.add(\n this.momentSum,\n pb.mul(\n this.incrementalGaussian.x,\n this.coverage2,\n pb.exp(pb.min(87, pb.sub(this.logValue2, this.maxLogValue)))\n )\n );\n });\n this.incrementalGaussian = pb.vec3(\n pb.mul(this.incrementalGaussian.xy, this.incrementalGaussian.yz),\n this.incrementalGaussian.z\n );\n });\n scope.$l.moment = pb.float(0);\n scope.$if(pb.greaterThan(scope.coverageSum, 0.000001), function () {\n this.moment = pb.add(this.maxLogValue, pb.log(pb.div(this.momentSum, this.coverageSum)));\n });\n return pb.vec4(scope.moment, pb.div(scope.coverageSum, scope.coefficientSum), 0, 1);\n } else {\n scope.$l.depth = pb.float(1);\n scope.$if(pb.greaterThan(scope.coverageSum, 0.000001), function () {\n this.depth = pb.div(this.depthSum, this.coverageSum);\n });\n return pb.vec4(scope.depth, pb.div(scope.coverageSum, scope.coefficientSum), 0, 1);\n }\n }\n writeTexel(scope: PBInsideFunctionScope, type: BlitType, srcUV: PBShaderExp, texel: PBShaderExp) {\n const outTexel = super.writeTexel(scope, type, srcUV, texel);\n if (this.packFloat) {\n return encodeNormalizedFloatToRGBA(scope, outTexel.r);\n } else {\n return outTexel;\n }\n }\n protected calcHash() {\n return `${super.calcHash()}-${Number(this.packFloat)}`;\n }\n}\n\n/** @internal */\nexport class ESM extends ShadowImpl {\n /** @internal */\n protected _depthScale: number;\n /** @internal */\n protected _blur: boolean;\n /** @internal */\n protected _kernelSize: number;\n /** @internal */\n protected _blurSize: number;\n /** @internal */\n protected _logSpace: boolean;\n /** @internal */\n protected _blitterH: BlurBlitter;\n /** @internal */\n protected _blitterV: BlurBlitter;\n /** @internal */\n protected _mipmap: boolean;\n constructor(kernelSize?: number, blurSize?: number, depthScale?: number) {\n super();\n this._blur = true;\n this._depthScale = depthScale ?? 500;\n this._kernelSize = kernelSize ?? 5;\n this._blurSize = blurSize ?? 1;\n this._logSpace = true;\n this._mipmap = true;\n this._blitterH = new BlurBlitter('horizonal', this._kernelSize, 4, 1 / 1024);\n this._blitterV = new BlurBlitter('vertical', this._kernelSize, 4, 1 / 1024);\n }\n resourceDirty() {\n return this._resourceDirty;\n }\n get blur() {\n return this._blur;\n }\n set blur(val) {\n if (this._blur !== !!val) {\n this._blur = !!val;\n this._resourceDirty = true;\n }\n }\n get mipmap() {\n return this._mipmap;\n }\n set mipmap(b) {\n if (this._mipmap !== !!b) {\n this._mipmap = !!b;\n if (this._blur) {\n this._resourceDirty = true;\n }\n }\n }\n get kernelSize() {\n return this._kernelSize;\n }\n set kernelSize(val) {\n this._kernelSize = val;\n }\n get blurSize() {\n return this._blurSize;\n }\n set blurSize(val) {\n this._blurSize = val;\n }\n get logSpace() {\n return this._logSpace;\n }\n set logSpace(val) {\n this._logSpace = !!val;\n }\n getType() {\n return 'esm' as const;\n }\n getShadowMapBorder(_shadowMapParams: ShadowMapParams) {\n return this._blur ? Math.ceil(((this._kernelSize + 1) / 2) * this._blurSize) : 0;\n }\n getShadowMapClearColor(shadowMapParams: ShadowMapParams) {\n const colorAttachment = shadowMapParams.shadowMapFramebuffer?.getColorAttachments()[0];\n return colorAttachment\n ? colorAttachment.format === 'rgba8unorm'\n ? new Vector4(0, 0, 0, 1)\n : new Vector4(1, 0, 0, 1)\n : null;\n }\n getShadowMap(shadowMapParams: ShadowMapParams) {\n const implData = shadowMapParams.implData as ESMImplData;\n return (\n implData\n ? implData.blurFramebuffer2!.getColorAttachments()[0]\n : shadowMapParams.shadowMapFramebuffer!.getColorAttachments()[0]\n ) as ShadowMapType;\n }\n /** @internal */\n fetchTemporalFramebuffer(\n autoRelease: boolean,\n lightType: number,\n numCascades: number,\n width: number,\n height: number,\n colorFormat: TextureFormat,\n depthFormat: Nullable<TextureFormat>,\n mipmapping?: boolean\n ) {\n const device = getDevice();\n const useTextureArray = numCascades > 1 && device.type !== 'webgl';\n const colorAttachments = colorFormat\n ? useTextureArray\n ? [\n device.pool.fetchTemporalTexture2DArray(\n false,\n colorFormat,\n width,\n height,\n numCascades,\n mipmapping\n )\n ]\n : lightType === LIGHT_TYPE_POINT\n ? [device.pool.fetchTemporalTextureCube(false, colorFormat, width, mipmapping)]\n : [device.pool.fetchTemporalTexture2D(false, colorFormat, width, height, mipmapping)]\n : null;\n const depthAttachment = depthFormat\n ? useTextureArray\n ? device.pool.fetchTemporalTexture2DArray(false, depthFormat, width, height, numCascades, false)\n : device.type !== 'webgl' && lightType === LIGHT_TYPE_POINT\n ? device.pool.fetchTemporalTextureCube(false, depthFormat, width, false)\n : device.pool.fetchTemporalTexture2D(false, depthFormat, width, height, false)\n : null;\n const fb = device.pool.createTemporalFramebuffer(autoRelease, colorAttachments!, depthAttachment);\n if (colorAttachments) {\n device.pool.releaseTexture(colorAttachments[0]);\n }\n if (depthAttachment) {\n device.pool.releaseTexture(depthAttachment);\n }\n return fb;\n }\n doUpdateResources(shadowMapParams: ShadowMapParams) {\n const implData: ESMImplData = {\n blurFramebuffer: null,\n blurFramebuffer2: null\n };\n shadowMapParams.implData = implData;\n const colorFormat = this.getShadowMapColorFormat(shadowMapParams)!;\n const shadowMapWidth = shadowMapParams.shadowMapFramebuffer!.getColorAttachments()[0].width;\n const shadowMapHeight = shadowMapParams.shadowMapFramebuffer!.getColorAttachments()[0].height;\n if (this._blur) {\n shadowMapParams.implData = {\n blurFramebuffer: this.fetchTemporalFramebuffer(\n true,\n shadowMapParams.lightType,\n shadowMapParams.numShadowCascades,\n shadowMapWidth,\n shadowMapHeight,\n colorFormat,\n null,\n false\n ),\n blurFramebuffer2: this.fetchTemporalFramebuffer(\n true,\n shadowMapParams.lightType,\n shadowMapParams.numShadowCascades,\n shadowMapWidth,\n shadowMapHeight,\n colorFormat,\n null,\n true\n )\n };\n } else {\n shadowMapParams.implData = null;\n }\n shadowMapParams.shadowMap = this.getShadowMap(shadowMapParams);\n shadowMapParams.shadowMapSampler = shadowMapParams.shadowMap?.getDefaultSampler(false) ?? null;\n }\n postRenderShadowMap(shadowMapParams: ShadowMapParams) {\n if (shadowMapParams.implData) {\n const implData = shadowMapParams.implData as ESMImplData;\n const colorAttachment = shadowMapParams.shadowMapFramebuffer!.getColorAttachments()[0];\n const packFloat = colorAttachment.format === 'rgba8unorm';\n const logSpace = this._logSpace && !packFloat;\n this._blitterH.blurSize = this._blurSize / colorAttachment.width;\n this._blitterH.kernelSize = this._kernelSize;\n this._blitterH.logSpace = logSpace;\n this._blitterH.logSpaceMultiplier = this._depthScale;\n this._blitterH.packFloat = packFloat;\n this._blitterV.blurSize = this._blurSize / colorAttachment.height;\n this._blitterV.kernelSize = this._kernelSize;\n this._blitterV.logSpace = logSpace;\n this._blitterV.logSpaceMultiplier = this._depthScale;\n this._blitterV.packFloat = packFloat;\n this._blitterH.blit(colorAttachment as any, implData.blurFramebuffer!);\n this._blitterV.blit(\n implData.blurFramebuffer!.getColorAttachments()[0] as any,\n implData.blurFramebuffer2!\n );\n }\n }\n getDepthScale() {\n return this._depthScale;\n }\n setDepthScale(val: number) {\n this._depthScale = val;\n }\n getShaderHash() {\n return `${this._blur ? 1 : 0}${this._logSpace ? 1 : 0}`;\n }\n getShadowMapColorFormat(_shadowMapParams: ShadowMapParams) {\n const device = getDevice();\n return device.getDeviceCaps().textureCaps.supportFloatColorBuffer &&\n device.getDeviceCaps().textureCaps.supportLinearFloatTexture\n ? device.type === 'webgl'\n ? 'rgba32f'\n : 'rg32f'\n : device.getDeviceCaps().textureCaps.supportHalfFloatColorBuffer &&\n device.getDeviceCaps().textureCaps.supportLinearHalfFloatTexture\n ? device.type === 'webgl'\n ? 'rgba16f'\n : 'rg16f'\n : 'rgba8unorm';\n }\n getShadowMapDepthFormat(_shadowMapParams: ShadowMapParams) {\n return 'd24s8' as const;\n }\n computeShadowMapDepth(\n shadowMapParams: ShadowMapParams,\n scope: PBInsideFunctionScope,\n worldPos: PBShaderExp\n ) {\n const pb = scope.$builder;\n const depth = computeShadowMapDepth(scope, worldPos, shadowMapParams.shadowMap!.format);\n return shadowMapParams.shadowMap!.format === 'rgba8unorm' ? depth : pb.vec4(depth.x, 1, 0, 1);\n }\n computeShadowCSM(\n shadowMapParams: ShadowMapParams,\n scope: PBInsideFunctionScope,\n shadowVertex: PBShaderExp,\n NdotL: PBShaderExp,\n split: PBShaderExp\n ) {\n const funcNameComputeShadowCSM = 'lib_computeShadowCSM';\n const pb = scope.$builder;\n const logSpace = this._blur && this._logSpace && shadowMapParams.shadowMap!.format !== 'rgba8unorm';\n pb.func(\n funcNameComputeShadowCSM,\n [pb.vec4('shadowVertex'), pb.float('NdotL'), pb.int('split')],\n function () {\n this.$l.shadowCoord = pb.div(this.shadowVertex, this.shadowVertex.w);\n this.$l.shadowCoord = pb.add(pb.mul(this.shadowCoord, 0.5), 0.5);\n this.$l.inShadow = pb.all(\n pb.bvec2(\n pb.all(\n pb.bvec4(\n pb.greaterThanEqual(this.shadowCoord.x, 0),\n pb.lessThanEqual(this.shadowCoord.x, 1),\n pb.greaterThanEqual(this.shadowCoord.y, 0),\n pb.lessThanEqual(this.shadowCoord.y, 1)\n )\n ),\n pb.lessThanEqual(this.shadowCoord.z, 1)\n )\n );\n this.$l.shadow = pb.float(1);\n this.$if(this.inShadow, function () {\n this.$l.shadowBias = computeShadowBiasCSM(this, this.NdotL, this.split);\n this.shadow = filterShadowESM(\n this,\n shadowMapParams.lightType,\n shadowMapParams.shadowMap!.format,\n logSpace,\n this.shadowCoord,\n this.split,\n this.shadowBias\n );\n });\n this.$return(this.shadow);\n }\n );\n return pb.getGlobalScope()[funcNameComputeShadowCSM](shadowVertex, NdotL, split) as PBShaderExp;\n }\n computeShadow(\n shadowMapParams: ShadowMapParams,\n scope: PBInsideFunctionScope,\n shadowVertex: PBShaderExp,\n NdotL: PBShaderExp\n ) {\n const funcNameComputeShadow = 'lib_computeShadow';\n const pb = scope.$builder;\n const logSpace = this._blur && this._logSpace && shadowMapParams.shadowMap!.format !== 'rgba8unorm';\n pb.func(funcNameComputeShadow, [pb.vec4('shadowVertex'), pb.float('NdotL')], function () {\n if (shadowMapParams.lightType === LIGHT_TYPE_POINT) {\n this.$l.dir = pb.sub(this.shadowVertex.xyz, ShaderHelper.getLightPositionAndRangeForShadow(this).xyz);\n this.$l.distance = pb.div(\n pb.length(this.dir),\n ShaderHelper.getLightPositionAndRangeForShadow(this).w\n );\n this.$l.shadowBias = computeShadowBias(\n shadowMapParams.lightType,\n this,\n this.distance,\n this.NdotL,\n true\n );\n this.$return(\n filterShadowESM(\n this,\n LIGHT_TYPE_POINT,\n shadowMapParams.shadowMap!.format,\n logSpace,\n this.dir,\n undefined,\n this.shadowBias\n )\n );\n } else {\n this.$l.shadowCoord = pb.div(this.shadowVertex, this.shadowVertex.w);\n this.$l.shadowCoord = pb.add(pb.mul(this.shadowCoord, 0.5), 0.5);\n this.$l.inShadow = pb.all(\n pb.bvec2(\n pb.all(\n pb.bvec4(\n pb.greaterThanEqual(this.shadowCoord.x, 0),\n pb.lessThanEqual(this.shadowCoord.x, 1),\n pb.greaterThanEqual(this.shadowCoord.y, 0),\n pb.lessThanEqual(this.shadowCoord.y, 1)\n )\n ),\n pb.lessThanEqual(this.shadowCoord.z, 1)\n )\n );\n this.$l.shadow = pb.float(1);\n this.$if(this.inShadow, function () {\n this.$l.shadowBias = computeShadowBias(\n shadowMapParams.lightType,\n this,\n this.shadowCoord.z,\n this.NdotL,\n false\n );\n this.shadow = filterShadowESM(\n this,\n shadowMapParams.lightType,\n shadowMapParams.shadowMap!.format,\n logSpace,\n this.shadowCoord,\n undefined,\n this.shadowBias\n );\n });\n this.$return(this.shadow);\n }\n });\n return pb.getGlobalScope()[funcNameComputeShadow](shadowVertex, NdotL) as PBShaderExp;\n }\n useNativeShadowMap(_shadowMapParams: ShadowMapParams) {\n return false;\n }\n}\n"],"names":["BlurBlitter","GaussianBlurBlitter","_packFloat","packFloat","b","invalidateHash","readTexel","scope","type","srcTex","srcUV","srcLayer","sampleType","pb","$builder","texel","vec4","decodeNormalizedFloatFromRGBA","filter","that","incrementalGaussian","vec3","x","div","mul","sigma","Math","sqrt","PI","y","exp","z","coefficientSum","float","coverageSum","d0","coverage0","clamp","add","logSpace","maxLogValue","logValue0","_phase","multiplier","$if","greaterThan","depthSum","xy","yz","$for","numBlurPixelsPerSide","$l","blurOffset","blurMultiplyVec","blurSize","i","d1","sub","d2","coverage1","coverage2","logValue1","logValue2","max","momentSum","min","moment","log","depth","writeTexel","outTexel","encodeNormalizedFloatToRGBA","r","calcHash","Number","ESM","ShadowImpl","kernelSize","depthScale","_blur","_depthScale","_kernelSize","_blurSize","_logSpace","_mipmap","_blitterH","_blitterV","resourceDirty","_resourceDirty","blur","val","mipmap","getType","getShadowMapBorder","_shadowMapParams","ceil","getShadowMapClearColor","shadowMapParams","colorAttachment","shadowMapFramebuffer","getColorAttachments","format","Vector4","getShadowMap","implData","blurFramebuffer2","fetchTemporalFramebuffer","autoRelease","lightType","numCascades","width","height","colorFormat","depthFormat","mipmapping","device","getDevice","useTextureArray","colorAttachments","pool","fetchTemporalTexture2DArray","LIGHT_TYPE_POINT","fetchTemporalTextureCube","fetchTemporalTexture2D","depthAttachment","fb","createTemporalFramebuffer","releaseTexture","doUpdateResources","blurFramebuffer","getShadowMapColorFormat","shadowMapWidth","shadowMapHeight","numShadowCascades","shadowMap","shadowMapSampler","getDefaultSampler","postRenderShadowMap","logSpaceMultiplier","blit","getDepthScale","setDepthScale","getShaderHash","getDeviceCaps","textureCaps","supportFloatColorBuffer","supportLinearFloatTexture","supportHalfFloatColorBuffer","supportLinearHalfFloatTexture","getShadowMapDepthFormat","computeShadowMapDepth","worldPos","computeShadowCSM","shadowVertex","NdotL","split","funcNameComputeShadowCSM","func","int","shadowCoord","w","inShadow","all","bvec2","bvec4","greaterThanEqual","lessThanEqual","shadow","shadowBias","computeShadowBiasCSM","filterShadowESM","$return","getGlobalScope","computeShadow","funcNameComputeShadow","dir","xyz","ShaderHelper","getLightPositionAndRangeForShadow","distance","length","computeShadowBias","undefined","useNativeShadowMap"],"mappings":";;;;;;;;;;;AAkBA,MAAMA,WAAoBC,SAAAA,mBAAAA,CAAAA;AACdC,IAAAA,UAAAA,GAAa,KAAM;AAC7B,IAAA,IAAIC,SAAY,GAAA;QACd,OAAO,IAAI,CAACD,UAAU;AACxB;IACA,IAAIC,SAAAA,CAAUC,CAAC,EAAE;AACf,QAAA,IAAI,IAAI,CAACF,UAAU,KAAK,CAAC,CAACE,CAAG,EAAA;AAC3B,YAAA,IAAI,CAACF,UAAU,GAAG,CAAC,CAACE,CAAAA;AACpB,YAAA,IAAI,CAACC,cAAc,EAAA;AACrB;AACF;IACAC,SACEC,CAAAA,KAA4B,EAC5BC,IAAc,EACdC,MAAmB,EACnBC,KAAkB,EAClBC,QAAqB,EACrBC,UAAoC,EACpC;QACA,MAAMC,EAAAA,GAAKN,MAAMO,QAAQ;QACzB,MAAMC,KAAAA,GAAQ,KAAK,CAACT,SAAAA,CAAUC,OAAOC,IAAMC,EAAAA,MAAAA,EAAQC,OAAOC,QAAUC,EAAAA,UAAAA,CAAAA;QACpE,IAAI,IAAI,CAACT,SAAS,EAAE;AAClB,YAAA,OAAOU,GAAGG,IAAI,CAACC,8BAA8BV,KAAOQ,EAAAA,KAAAA,CAAAA,EAAQ,GAAG,CAAG,EAAA,CAAA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ACA6B,IAAAA,kBAAAA,CAAmBzF,gBAAiC,EAAE;QACpD,OAAO,KAAA;AACT;AACF;;;;"}
1
+ {"version":3,"file":"esm.js","sources":["../../src/shadow/esm.ts"],"sourcesContent":["import type { FrameBuffer, TextureFormat, PBShaderExp, PBInsideFunctionScope } from '@zephyr3d/device';\r\nimport { ShadowImpl } from './shadow_impl';\r\nimport type { BlitType } from '../blitter';\r\nimport { GaussianBlurBlitter } from '../blitter';\r\nimport { computeShadowMapDepth, filterShadowESM } from '../shaders/shadow';\r\nimport { decodeNormalizedFloatFromRGBA, encodeNormalizedFloatToRGBA } from '../shaders/misc';\r\nimport { LIGHT_TYPE_POINT } from '../values';\r\nimport type { ShadowMapParams, ShadowMapType } from './shadowmapper';\r\nimport { ShaderHelper } from '../material/shader/helper';\r\nimport { getDevice } from '../app/api';\r\nimport { Vector4, type Nullable } from '@zephyr3d/base';\r\nimport { computeShadowBias, computeShadowBiasCSM } from './shader';\r\n\r\ntype ESMImplData = {\r\n blurFramebuffer: Nullable<FrameBuffer>;\r\n blurFramebuffer2: Nullable<FrameBuffer>;\r\n};\r\n\r\nclass BlurBlitter extends GaussianBlurBlitter {\r\n protected _packFloat = false;\r\n get packFloat() {\r\n return this._packFloat;\r\n }\r\n set packFloat(b) {\r\n if (this._packFloat !== !!b) {\r\n this._packFloat = !!b;\r\n this.invalidateHash();\r\n }\r\n }\r\n readTexel(\r\n scope: PBInsideFunctionScope,\r\n type: BlitType,\r\n srcTex: PBShaderExp,\r\n srcUV: PBShaderExp,\r\n srcLayer: PBShaderExp,\r\n sampleType: 'float' | 'int' | 'uint'\r\n ) {\r\n const pb = scope.$builder;\r\n const texel = super.readTexel(scope, type, srcTex, srcUV, srcLayer, sampleType);\r\n if (this.packFloat) {\r\n return pb.vec4(decodeNormalizedFloatFromRGBA(scope, texel), 1, 0, 1);\r\n } else {\r\n return texel;\r\n }\r\n }\r\n filter(\r\n scope: PBInsideFunctionScope,\r\n type: BlitType,\r\n srcTex: PBShaderExp,\r\n srcUV: PBShaderExp,\r\n srcLayer: PBShaderExp,\r\n sampleType: 'float' | 'int' | 'uint'\r\n ) {\r\n const that = this;\r\n const pb = scope.$builder;\r\n scope.incrementalGaussian = pb.vec3();\r\n scope.incrementalGaussian.x = pb.div(1, pb.mul(scope.sigma, Math.sqrt(2 * Math.PI)));\r\n scope.incrementalGaussian.y = pb.exp(pb.div(-0.5, pb.mul(scope.sigma, scope.sigma)));\r\n scope.incrementalGaussian.z = pb.mul(scope.incrementalGaussian.y, scope.incrementalGaussian.y);\r\n scope.coefficientSum = pb.float(0);\r\n scope.coverageSum = pb.float(0);\r\n scope.d0 = that.readTexel(scope, type, srcTex, srcUV, srcLayer, sampleType);\r\n scope.coverage0 = pb.clamp(scope.d0.y, 0, 1);\r\n scope.coefficientSum = pb.add(scope.coefficientSum, scope.incrementalGaussian.x);\r\n scope.coverageSum = pb.add(scope.coverageSum, pb.mul(scope.incrementalGaussian.x, scope.coverage0));\r\n\r\n if (that.logSpace) {\r\n scope.maxLogValue = pb.float(-1e20);\r\n scope.logValue0 = that._phase === 'horizonal' ? pb.mul(scope.d0.x, scope.multiplier) : scope.d0.x;\r\n scope.$if(pb.greaterThan(scope.coverage0, 0.000001), function () {\r\n this.maxLogValue = this.logValue0;\r\n });\r\n } else {\r\n scope.depthSum = pb.mul(scope.incrementalGaussian.x, scope.coverage0, scope.d0.x);\r\n }\r\n\r\n scope.incrementalGaussian = pb.vec3(\r\n pb.mul(scope.incrementalGaussian.xy, scope.incrementalGaussian.yz),\r\n scope.incrementalGaussian.z\r\n );\r\n scope.$for(pb.float('i'), 1, scope.numBlurPixelsPerSide, function () {\r\n this.$l.blurOffset = pb.mul(this.blurMultiplyVec, this.blurSize, this.i);\r\n this.$l.d1 = that.readTexel(scope, type, srcTex, pb.sub(srcUV, this.blurOffset), srcLayer, sampleType);\r\n this.$l.d2 = that.readTexel(scope, type, srcTex, pb.add(srcUV, this.blurOffset), srcLayer, sampleType);\r\n this.$l.coverage1 = pb.clamp(this.d1.y, 0, 1);\r\n this.$l.coverage2 = pb.clamp(this.d2.y, 0, 1);\r\n this.coefficientSum = pb.add(this.coefficientSum, pb.mul(this.incrementalGaussian.x, 2));\r\n this.coverageSum = pb.add(\r\n this.coverageSum,\r\n pb.mul(this.incrementalGaussian.x, pb.add(this.coverage1, this.coverage2))\r\n );\r\n if (that.logSpace) {\r\n this.$l.logValue1 = that._phase === 'horizonal' ? pb.mul(this.d1.x, this.multiplier) : this.d1.x;\r\n this.$l.logValue2 = that._phase === 'horizonal' ? pb.mul(this.d2.x, this.multiplier) : this.d2.x;\r\n this.$if(pb.greaterThan(this.coverage1, 0.000001), function () {\r\n this.maxLogValue = pb.max(this.maxLogValue, this.logValue1);\r\n });\r\n this.$if(pb.greaterThan(this.coverage2, 0.000001), function () {\r\n this.maxLogValue = pb.max(this.maxLogValue, this.logValue2);\r\n });\r\n } else {\r\n this.depthSum = pb.add(\r\n this.depthSum,\r\n pb.mul(\r\n this.incrementalGaussian.x,\r\n pb.add(pb.mul(this.coverage1, this.d1.x), pb.mul(this.coverage2, this.d2.x))\r\n )\r\n );\r\n }\r\n this.incrementalGaussian = pb.vec3(\r\n pb.mul(this.incrementalGaussian.xy, this.incrementalGaussian.yz),\r\n this.incrementalGaussian.z\r\n );\r\n });\r\n\r\n if (that.logSpace) {\r\n scope.incrementalGaussian.x = pb.div(1, pb.mul(scope.sigma, Math.sqrt(2 * Math.PI)));\r\n scope.incrementalGaussian.y = pb.exp(pb.div(-0.5, pb.mul(scope.sigma, scope.sigma)));\r\n scope.incrementalGaussian.z = pb.mul(scope.incrementalGaussian.y, scope.incrementalGaussian.y);\r\n scope.momentSum = pb.float(0);\r\n scope.$if(pb.greaterThan(scope.coverage0, 0.000001), function () {\r\n this.momentSum = pb.add(\r\n this.momentSum,\r\n pb.mul(\r\n this.incrementalGaussian.x,\r\n this.coverage0,\r\n pb.exp(pb.min(87, pb.sub(this.logValue0, this.maxLogValue)))\r\n )\r\n );\r\n });\r\n scope.incrementalGaussian = pb.vec3(\r\n pb.mul(scope.incrementalGaussian.xy, scope.incrementalGaussian.yz),\r\n scope.incrementalGaussian.z\r\n );\r\n scope.$for(pb.float('i'), 1, scope.numBlurPixelsPerSide, function () {\r\n this.$l.blurOffset = pb.mul(this.blurMultiplyVec, this.blurSize, this.i);\r\n this.$l.d1 = that.readTexel(\r\n scope,\r\n type,\r\n srcTex,\r\n pb.sub(srcUV, this.blurOffset),\r\n srcLayer,\r\n sampleType\r\n );\r\n this.$l.d2 = that.readTexel(\r\n scope,\r\n type,\r\n srcTex,\r\n pb.add(srcUV, this.blurOffset),\r\n srcLayer,\r\n sampleType\r\n );\r\n this.$l.coverage1 = pb.clamp(this.d1.y, 0, 1);\r\n this.$l.coverage2 = pb.clamp(this.d2.y, 0, 1);\r\n this.$l.logValue1 = that._phase === 'horizonal' ? pb.mul(this.d1.x, this.multiplier) : this.d1.x;\r\n this.$l.logValue2 = that._phase === 'horizonal' ? pb.mul(this.d2.x, this.multiplier) : this.d2.x;\r\n this.$if(pb.greaterThan(this.coverage1, 0.000001), function () {\r\n this.momentSum = pb.add(\r\n this.momentSum,\r\n pb.mul(\r\n this.incrementalGaussian.x,\r\n this.coverage1,\r\n pb.exp(pb.min(87, pb.sub(this.logValue1, this.maxLogValue)))\r\n )\r\n );\r\n });\r\n this.$if(pb.greaterThan(this.coverage2, 0.000001), function () {\r\n this.momentSum = pb.add(\r\n this.momentSum,\r\n pb.mul(\r\n this.incrementalGaussian.x,\r\n this.coverage2,\r\n pb.exp(pb.min(87, pb.sub(this.logValue2, this.maxLogValue)))\r\n )\r\n );\r\n });\r\n this.incrementalGaussian = pb.vec3(\r\n pb.mul(this.incrementalGaussian.xy, this.incrementalGaussian.yz),\r\n this.incrementalGaussian.z\r\n );\r\n });\r\n scope.$l.moment = pb.float(0);\r\n scope.$if(pb.greaterThan(scope.coverageSum, 0.000001), function () {\r\n this.moment = pb.add(this.maxLogValue, pb.log(pb.div(this.momentSum, this.coverageSum)));\r\n });\r\n return pb.vec4(scope.moment, pb.div(scope.coverageSum, scope.coefficientSum), 0, 1);\r\n } else {\r\n scope.$l.depth = pb.float(1);\r\n scope.$if(pb.greaterThan(scope.coverageSum, 0.000001), function () {\r\n this.depth = pb.div(this.depthSum, this.coverageSum);\r\n });\r\n return pb.vec4(scope.depth, pb.div(scope.coverageSum, scope.coefficientSum), 0, 1);\r\n }\r\n }\r\n writeTexel(scope: PBInsideFunctionScope, type: BlitType, srcUV: PBShaderExp, texel: PBShaderExp) {\r\n const outTexel = super.writeTexel(scope, type, srcUV, texel);\r\n if (this.packFloat) {\r\n return encodeNormalizedFloatToRGBA(scope, outTexel.r);\r\n } else {\r\n return outTexel;\r\n }\r\n }\r\n protected calcHash() {\r\n return `${super.calcHash()}-${Number(this.packFloat)}`;\r\n }\r\n}\r\n\r\n/** @internal */\r\nexport class ESM extends ShadowImpl {\r\n /** @internal */\r\n protected _depthScale: number;\r\n /** @internal */\r\n protected _blur: boolean;\r\n /** @internal */\r\n protected _kernelSize: number;\r\n /** @internal */\r\n protected _blurSize: number;\r\n /** @internal */\r\n protected _logSpace: boolean;\r\n /** @internal */\r\n protected _blitterH: BlurBlitter;\r\n /** @internal */\r\n protected _blitterV: BlurBlitter;\r\n /** @internal */\r\n protected _mipmap: boolean;\r\n constructor(kernelSize?: number, blurSize?: number, depthScale?: number) {\r\n super();\r\n this._blur = true;\r\n this._depthScale = depthScale ?? 500;\r\n this._kernelSize = kernelSize ?? 5;\r\n this._blurSize = blurSize ?? 1;\r\n this._logSpace = true;\r\n this._mipmap = true;\r\n this._blitterH = new BlurBlitter('horizonal', this._kernelSize, 4, 1 / 1024);\r\n this._blitterV = new BlurBlitter('vertical', this._kernelSize, 4, 1 / 1024);\r\n }\r\n resourceDirty() {\r\n return this._resourceDirty;\r\n }\r\n get blur() {\r\n return this._blur;\r\n }\r\n set blur(val) {\r\n if (this._blur !== !!val) {\r\n this._blur = !!val;\r\n this._resourceDirty = true;\r\n }\r\n }\r\n get mipmap() {\r\n return this._mipmap;\r\n }\r\n set mipmap(b) {\r\n if (this._mipmap !== !!b) {\r\n this._mipmap = !!b;\r\n if (this._blur) {\r\n this._resourceDirty = true;\r\n }\r\n }\r\n }\r\n get kernelSize() {\r\n return this._kernelSize;\r\n }\r\n set kernelSize(val) {\r\n this._kernelSize = val;\r\n }\r\n get blurSize() {\r\n return this._blurSize;\r\n }\r\n set blurSize(val) {\r\n this._blurSize = val;\r\n }\r\n get logSpace() {\r\n return this._logSpace;\r\n }\r\n set logSpace(val) {\r\n this._logSpace = !!val;\r\n }\r\n getType() {\r\n return 'esm' as const;\r\n }\r\n getShadowMapBorder(_shadowMapParams: ShadowMapParams) {\r\n return this._blur ? Math.ceil(((this._kernelSize + 1) / 2) * this._blurSize) : 0;\r\n }\r\n getShadowMapClearColor(shadowMapParams: ShadowMapParams) {\r\n const colorAttachment = shadowMapParams.shadowMapFramebuffer?.getColorAttachments()[0];\r\n return colorAttachment\r\n ? colorAttachment.format === 'rgba8unorm'\r\n ? new Vector4(0, 0, 0, 1)\r\n : new Vector4(1, 0, 0, 1)\r\n : null;\r\n }\r\n getShadowMap(shadowMapParams: ShadowMapParams) {\r\n const implData = shadowMapParams.implData as ESMImplData;\r\n return (\r\n implData\r\n ? implData.blurFramebuffer2!.getColorAttachments()[0]\r\n : shadowMapParams.shadowMapFramebuffer!.getColorAttachments()[0]\r\n ) as ShadowMapType;\r\n }\r\n /** @internal */\r\n fetchTemporalFramebuffer(\r\n autoRelease: boolean,\r\n lightType: number,\r\n numCascades: number,\r\n width: number,\r\n height: number,\r\n colorFormat: TextureFormat,\r\n depthFormat: Nullable<TextureFormat>,\r\n mipmapping?: boolean\r\n ) {\r\n const device = getDevice();\r\n const useTextureArray = numCascades > 1 && device.type !== 'webgl';\r\n const colorAttachments = colorFormat\r\n ? useTextureArray\r\n ? [\r\n device.pool.fetchTemporalTexture2DArray(\r\n false,\r\n colorFormat,\r\n width,\r\n height,\r\n numCascades,\r\n mipmapping\r\n )\r\n ]\r\n : lightType === LIGHT_TYPE_POINT\r\n ? [device.pool.fetchTemporalTextureCube(false, colorFormat, width, mipmapping)]\r\n : [device.pool.fetchTemporalTexture2D(false, colorFormat, width, height, mipmapping)]\r\n : null;\r\n const depthAttachment = depthFormat\r\n ? useTextureArray\r\n ? device.pool.fetchTemporalTexture2DArray(false, depthFormat, width, height, numCascades, false)\r\n : device.type !== 'webgl' && lightType === LIGHT_TYPE_POINT\r\n ? device.pool.fetchTemporalTextureCube(false, depthFormat, width, false)\r\n : device.pool.fetchTemporalTexture2D(false, depthFormat, width, height, false)\r\n : null;\r\n const fb = device.pool.createTemporalFramebuffer(autoRelease, colorAttachments!, depthAttachment);\r\n if (colorAttachments) {\r\n device.pool.releaseTexture(colorAttachments[0]);\r\n }\r\n if (depthAttachment) {\r\n device.pool.releaseTexture(depthAttachment);\r\n }\r\n return fb;\r\n }\r\n doUpdateResources(shadowMapParams: ShadowMapParams) {\r\n const implData: ESMImplData = {\r\n blurFramebuffer: null,\r\n blurFramebuffer2: null\r\n };\r\n shadowMapParams.implData = implData;\r\n const colorFormat = this.getShadowMapColorFormat(shadowMapParams)!;\r\n const shadowMapWidth = shadowMapParams.shadowMapFramebuffer!.getColorAttachments()[0].width;\r\n const shadowMapHeight = shadowMapParams.shadowMapFramebuffer!.getColorAttachments()[0].height;\r\n if (this._blur) {\r\n shadowMapParams.implData = {\r\n blurFramebuffer: this.fetchTemporalFramebuffer(\r\n true,\r\n shadowMapParams.lightType,\r\n shadowMapParams.numShadowCascades,\r\n shadowMapWidth,\r\n shadowMapHeight,\r\n colorFormat,\r\n null,\r\n false\r\n ),\r\n blurFramebuffer2: this.fetchTemporalFramebuffer(\r\n true,\r\n shadowMapParams.lightType,\r\n shadowMapParams.numShadowCascades,\r\n shadowMapWidth,\r\n shadowMapHeight,\r\n colorFormat,\r\n null,\r\n true\r\n )\r\n };\r\n } else {\r\n shadowMapParams.implData = null;\r\n }\r\n shadowMapParams.shadowMap = this.getShadowMap(shadowMapParams);\r\n shadowMapParams.shadowMapSampler = shadowMapParams.shadowMap?.getDefaultSampler(false) ?? null;\r\n }\r\n postRenderShadowMap(shadowMapParams: ShadowMapParams) {\r\n if (shadowMapParams.implData) {\r\n const implData = shadowMapParams.implData as ESMImplData;\r\n const colorAttachment = shadowMapParams.shadowMapFramebuffer!.getColorAttachments()[0];\r\n const packFloat = colorAttachment.format === 'rgba8unorm';\r\n const logSpace = this._logSpace && !packFloat;\r\n this._blitterH.blurSize = this._blurSize / colorAttachment.width;\r\n this._blitterH.kernelSize = this._kernelSize;\r\n this._blitterH.logSpace = logSpace;\r\n this._blitterH.logSpaceMultiplier = this._depthScale;\r\n this._blitterH.packFloat = packFloat;\r\n this._blitterV.blurSize = this._blurSize / colorAttachment.height;\r\n this._blitterV.kernelSize = this._kernelSize;\r\n this._blitterV.logSpace = logSpace;\r\n this._blitterV.logSpaceMultiplier = this._depthScale;\r\n this._blitterV.packFloat = packFloat;\r\n this._blitterH.blit(colorAttachment as any, implData.blurFramebuffer!);\r\n this._blitterV.blit(\r\n implData.blurFramebuffer!.getColorAttachments()[0] as any,\r\n implData.blurFramebuffer2!\r\n );\r\n }\r\n }\r\n getDepthScale() {\r\n return this._depthScale;\r\n }\r\n setDepthScale(val: number) {\r\n this._depthScale = val;\r\n }\r\n getShaderHash() {\r\n return `${this._blur ? 1 : 0}${this._logSpace ? 1 : 0}`;\r\n }\r\n getShadowMapColorFormat(_shadowMapParams: ShadowMapParams) {\r\n const device = getDevice();\r\n return device.getDeviceCaps().textureCaps.supportFloatColorBuffer &&\r\n device.getDeviceCaps().textureCaps.supportLinearFloatTexture\r\n ? device.type === 'webgl'\r\n ? 'rgba32f'\r\n : 'rg32f'\r\n : device.getDeviceCaps().textureCaps.supportHalfFloatColorBuffer &&\r\n device.getDeviceCaps().textureCaps.supportLinearHalfFloatTexture\r\n ? device.type === 'webgl'\r\n ? 'rgba16f'\r\n : 'rg16f'\r\n : 'rgba8unorm';\r\n }\r\n getShadowMapDepthFormat(_shadowMapParams: ShadowMapParams) {\r\n return 'd24s8' as const;\r\n }\r\n computeShadowMapDepth(\r\n shadowMapParams: ShadowMapParams,\r\n scope: PBInsideFunctionScope,\r\n worldPos: PBShaderExp\r\n ) {\r\n const pb = scope.$builder;\r\n const depth = computeShadowMapDepth(scope, worldPos, shadowMapParams.shadowMap!.format);\r\n return shadowMapParams.shadowMap!.format === 'rgba8unorm' ? depth : pb.vec4(depth.x, 1, 0, 1);\r\n }\r\n computeShadowCSM(\r\n shadowMapParams: ShadowMapParams,\r\n scope: PBInsideFunctionScope,\r\n shadowVertex: PBShaderExp,\r\n NdotL: PBShaderExp,\r\n split: PBShaderExp\r\n ) {\r\n const funcNameComputeShadowCSM = 'lib_computeShadowCSM';\r\n const pb = scope.$builder;\r\n const logSpace = this._blur && this._logSpace && shadowMapParams.shadowMap!.format !== 'rgba8unorm';\r\n pb.func(\r\n funcNameComputeShadowCSM,\r\n [pb.vec4('shadowVertex'), pb.float('NdotL'), pb.int('split')],\r\n function () {\r\n this.$l.shadowCoord = pb.div(this.shadowVertex, this.shadowVertex.w);\r\n this.$l.shadowCoord = pb.add(pb.mul(this.shadowCoord, 0.5), 0.5);\r\n this.$l.inShadow = pb.all(\r\n pb.bvec2(\r\n pb.all(\r\n pb.bvec4(\r\n pb.greaterThanEqual(this.shadowCoord.x, 0),\r\n pb.lessThanEqual(this.shadowCoord.x, 1),\r\n pb.greaterThanEqual(this.shadowCoord.y, 0),\r\n pb.lessThanEqual(this.shadowCoord.y, 1)\r\n )\r\n ),\r\n pb.lessThanEqual(this.shadowCoord.z, 1)\r\n )\r\n );\r\n this.$l.shadow = pb.float(1);\r\n this.$if(this.inShadow, function () {\r\n this.$l.shadowBias = computeShadowBiasCSM(this, this.NdotL, this.split);\r\n this.shadow = filterShadowESM(\r\n this,\r\n shadowMapParams.lightType,\r\n shadowMapParams.shadowMap!.format,\r\n logSpace,\r\n this.shadowCoord,\r\n this.split,\r\n this.shadowBias\r\n );\r\n });\r\n this.$return(this.shadow);\r\n }\r\n );\r\n return pb.getGlobalScope()[funcNameComputeShadowCSM](shadowVertex, NdotL, split) as PBShaderExp;\r\n }\r\n computeShadow(\r\n shadowMapParams: ShadowMapParams,\r\n scope: PBInsideFunctionScope,\r\n shadowVertex: PBShaderExp,\r\n NdotL: PBShaderExp\r\n ) {\r\n const funcNameComputeShadow = 'lib_computeShadow';\r\n const pb = scope.$builder;\r\n const logSpace = this._blur && this._logSpace && shadowMapParams.shadowMap!.format !== 'rgba8unorm';\r\n pb.func(funcNameComputeShadow, [pb.vec4('shadowVertex'), pb.float('NdotL')], function () {\r\n if (shadowMapParams.lightType === LIGHT_TYPE_POINT) {\r\n this.$l.dir = pb.sub(this.shadowVertex.xyz, ShaderHelper.getLightPositionAndRangeForShadow(this).xyz);\r\n this.$l.distance = pb.div(\r\n pb.length(this.dir),\r\n ShaderHelper.getLightPositionAndRangeForShadow(this).w\r\n );\r\n this.$l.shadowBias = computeShadowBias(\r\n shadowMapParams.lightType,\r\n this,\r\n this.distance,\r\n this.NdotL,\r\n true\r\n );\r\n this.$return(\r\n filterShadowESM(\r\n this,\r\n LIGHT_TYPE_POINT,\r\n shadowMapParams.shadowMap!.format,\r\n logSpace,\r\n this.dir,\r\n undefined,\r\n this.shadowBias\r\n )\r\n );\r\n } else {\r\n this.$l.shadowCoord = pb.div(this.shadowVertex, this.shadowVertex.w);\r\n this.$l.shadowCoord = pb.add(pb.mul(this.shadowCoord, 0.5), 0.5);\r\n this.$l.inShadow = pb.all(\r\n pb.bvec2(\r\n pb.all(\r\n pb.bvec4(\r\n pb.greaterThanEqual(this.shadowCoord.x, 0),\r\n pb.lessThanEqual(this.shadowCoord.x, 1),\r\n pb.greaterThanEqual(this.shadowCoord.y, 0),\r\n pb.lessThanEqual(this.shadowCoord.y, 1)\r\n )\r\n ),\r\n pb.lessThanEqual(this.shadowCoord.z, 1)\r\n )\r\n );\r\n this.$l.shadow = pb.float(1);\r\n this.$if(this.inShadow, function () {\r\n this.$l.shadowBias = computeShadowBias(\r\n shadowMapParams.lightType,\r\n this,\r\n this.shadowCoord.z,\r\n this.NdotL,\r\n false\r\n );\r\n this.shadow = filterShadowESM(\r\n this,\r\n shadowMapParams.lightType,\r\n shadowMapParams.shadowMap!.format,\r\n logSpace,\r\n this.shadowCoord,\r\n undefined,\r\n this.shadowBias\r\n );\r\n });\r\n this.$return(this.shadow);\r\n }\r\n });\r\n return pb.getGlobalScope()[funcNameComputeShadow](shadowVertex, NdotL) as PBShaderExp;\r\n }\r\n useNativeShadowMap(_shadowMapParams: ShadowMapParams) {\r\n return false;\r\n }\r\n}\r\n"],"names":["BlurBlitter","GaussianBlurBlitter","_packFloat","packFloat","b","invalidateHash","readTexel","scope","type","srcTex","srcUV","srcLayer","sampleType","pb","$builder","texel","vec4","decodeNormalizedFloatFromRGBA","filter","that","incrementalGaussian","vec3","x","div","mul","sigma","Math","sqrt","PI","y","exp","z","coefficientSum","float","coverageSum","d0","coverage0","clamp","add","logSpace","maxLogValue","logValue0","_phase","multiplier","$if","greaterThan","depthSum","xy","yz","$for","numBlurPixelsPerSide","$l","blurOffset","blurMultiplyVec","blurSize","i","d1","sub","d2","coverage1","coverage2","logValue1","logValue2","max","momentSum","min","moment","log","depth","writeTexel","outTexel","encodeNormalizedFloatToRGBA","r","calcHash","Number","ESM","ShadowImpl","kernelSize","depthScale","_blur","_depthScale","_kernelSize","_blurSize","_logSpace","_mipmap","_blitterH","_blitterV","resourceDirty","_resourceDirty","blur","val","mipmap","getType","getShadowMapBorder","_shadowMapParams","ceil","getShadowMapClearColor","shadowMapParams","colorAttachment","shadowMapFramebuffer","getColorAttachments","format","Vector4","getShadowMap","implData","blurFramebuffer2","fetchTemporalFramebuffer","autoRelease","lightType","numCascades","width","height","colorFormat","depthFormat","mipmapping","device","getDevice","useTextureArray","colorAttachments","pool","fetchTemporalTexture2DArray","LIGHT_TYPE_POINT","fetchTemporalTextureCube","fetchTemporalTexture2D","depthAttachment","fb","createTemporalFramebuffer","releaseTexture","doUpdateResources","blurFramebuffer","getShadowMapColorFormat","shadowMapWidth","shadowMapHeight","numShadowCascades","shadowMap","shadowMapSampler","getDefaultSampler","postRenderShadowMap","logSpaceMultiplier","blit","getDepthScale","setDepthScale","getShaderHash","getDeviceCaps","textureCaps","supportFloatColorBuffer","supportLinearFloatTexture","supportHalfFloatColorBuffer","supportLinearHalfFloatTexture","getShadowMapDepthFormat","computeShadowMapDepth","worldPos","computeShadowCSM","shadowVertex","NdotL","split","funcNameComputeShadowCSM","func","int","shadowCoord","w","inShadow","all","bvec2","bvec4","greaterThanEqual","lessThanEqual","shadow","shadowBias","computeShadowBiasCSM","filterShadowESM","$return","getGlobalScope","computeShadow","funcNameComputeShadow","dir","xyz","ShaderHelper","getLightPositionAndRangeForShadow","distance","length","computeShadowBias","undefined","useNativeShadowMap"],"mappings":";;;;;;;;;;;AAkBA,MAAMA,WAAoBC,SAAAA,mBAAAA,CAAAA;AACdC,IAAAA,UAAAA,GAAa,KAAM;AAC7B,IAAA,IAAIC,SAAY,GAAA;QACd,OAAO,IAAI,CAACD,UAAU;AACxB;IACA,IAAIC,SAAAA,CAAUC,CAAC,EAAE;AACf,QAAA,IAAI,IAAI,CAACF,UAAU,KAAK,CAAC,CAACE,CAAG,EAAA;AAC3B,YAAA,IAAI,CAACF,UAAU,GAAG,CAAC,CAACE,CAAAA;AACpB,YAAA,IAAI,CAACC,cAAc,EAAA;AACrB;AACF;IACAC,SACEC,CAAAA,KAA4B,EAC5BC,IAAc,EACdC,MAAmB,EACnBC,KAAkB,EAClBC,QAAqB,EACrBC,UAAoC,EACpC;QACA,MAAMC,EAAAA,GAAKN,MAAMO,QAAQ;QACzB,MAAMC,KAAAA,GAAQ,KAAK,CAACT,SAAAA,CAAUC,OAAOC,IAAMC,EAAAA,MAAAA,EAAQC,OAAOC,QAAUC,EAAAA,UAAAA,CAAAA;QACpE,IAAI,IAAI,CAACT,SAAS,EAAE;AAClB,YAAA,OAAOU,GAAGG,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G+J,cAAc,EAAE,CAACE,qBAAAA,CAAsB,CAACrB,YAAcC,EAAAA,KAAAA,CAAAA;AAClE;AACA6B,IAAAA,kBAAAA,CAAmBzF,gBAAiC,EAAE;QACpD,OAAO,KAAA;AACT;AACF;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zephyr3d/scene",
3
- "version": "0.9.8",
3
+ "version": "0.9.9",
4
4
  "description": "Scene API for zephyr3d",
5
5
  "homepage": "https://github.com/gavinyork/zephyr3d#readme",
6
6
  "type": "module",
@@ -1,320 +0,0 @@
1
- import { Matrix4x4, Vector3 } from '@zephyr3d/base';
2
- import { getVertexFormatComponentCount } from '@zephyr3d/device';
3
- import '../../scene/scene.js';
4
- import '../../values.js';
5
- import '../../render/render_queue.js';
6
- import '../../render/primitive.js';
7
- import '../../material/shader/helper.js';
8
- import '../../material/lambert.js';
9
- import '../../material/blinn.js';
10
- import '../../material/unlit.js';
11
- import '../../material/particle.js';
12
- import '../../material/subsurfaceprofile.js';
13
- import '../../material/meshmaterial.js';
14
- import '../../material/grassmaterial.js';
15
- import '../../material/terrain-cm.js';
16
- import '../../material/pbrmr.js';
17
- import '../../material/pbrsg.js';
18
- import '../../material/mtoon.js';
19
- import '../../material/pbrblueprint.js';
20
- import '../../material/sprite.js';
21
- import '../../material/sprite_std.js';
22
- import '../../utility/blueprint/material/texture.js';
23
- import '../../render/rendergraph/forward_plus_builder.js';
24
- import '../../render/lightpass.js';
25
- import '../../render/sky.js';
26
- import '../../render/clipmap.js';
27
- import '../../shaders/atmosphere.js';
28
- import { getSceneMeshAssetBinding } from '../../scene/scene_node.js';
29
- import '../../shadow/shadowmapper.js';
30
- import '../../scene/mesh.js';
31
- import '../../scene/basesprite.js';
32
- import '../../scene/meshdrawable.js';
33
- import '../../material/msdf_text.js';
34
- import '../../scene/water.js';
35
- import '../../scene/particlesys.js';
36
- import '../../scene/batchgroup.js';
37
- import '../../scene/terrain-cm/terrain-cm.js';
38
- import '../../scene/terrain-cm/grass.js';
39
- import '../../scene/raycast_visitor.js';
40
- import { ColliderForce } from './types.js';
41
-
42
- const EPS = 1e-6;
43
- /**
44
- * Generate convex JointDynamics colliders from skinned mesh bone weights.
45
- *
46
- * @public
47
- */ function generateJointDynamicsConvexCollidersFromSkinWeights(meshes, skinBinding, bones, options = {}) {
48
- const sources = collectSourcePrimitives(meshes);
49
- const results = [];
50
- for (const bone of bones){
51
- const jointIndex = skinBinding.joints.indexOf(bone);
52
- if (jointIndex < 0) {
53
- continue;
54
- }
55
- const points = collectBonePoints(sources, skinBinding, jointIndex, options);
56
- if (points.length < (options.minVertexCount ?? 8)) {
57
- continue;
58
- }
59
- const hull = buildConvexHull(points, options.maxHullVertices ?? 48, options.margin ?? 0);
60
- if (!hull || hull.vertices.length < 4 || hull.planes.length < 4) {
61
- continue;
62
- }
63
- results.push({
64
- bone,
65
- vertexCount: points.length,
66
- hullVertexCount: hull.vertices.length,
67
- collider: {
68
- radius: 0,
69
- radiusTailScale: 1,
70
- height: 0,
71
- friction: options.friction ?? 0,
72
- isInverseCollider: options.inversed ?? false,
73
- forceType: ColliderForce.Off,
74
- convex: hull
75
- }
76
- });
77
- }
78
- return results;
79
- }
80
- function collectSourcePrimitives(meshes) {
81
- const result = [];
82
- const seen = new Set();
83
- for (const mesh of meshes){
84
- const binding = getSceneMeshAssetBinding(mesh);
85
- const subMesh = binding?.subMesh;
86
- const primitive = subMesh?.primitive ?? null;
87
- if (primitive && !seen.has(primitive)) {
88
- seen.add(primitive);
89
- result.push({
90
- primitive,
91
- subMesh
92
- });
93
- }
94
- }
95
- return result;
96
- }
97
- function collectBonePoints(sources, skinBinding, jointIndex, options) {
98
- const points = [];
99
- const weightThreshold = options.weightThreshold ?? 0.45;
100
- const dominantBoneOnly = options.dominantBoneOnly ?? true;
101
- const inverseBind = skinBinding.inverseBindMatrices[jointIndex] ?? Matrix4x4.identity();
102
- for (const source of sources){
103
- const primitive = source.primitive;
104
- const positionInfo = primitive.vertices.position;
105
- const blendIndexInfo = primitive.vertices.blendIndices;
106
- const blendWeightInfo = primitive.vertices.blendWeights;
107
- if (!positionInfo || !blendIndexInfo || !blendWeightInfo) {
108
- continue;
109
- }
110
- const positions = positionInfo.data;
111
- const blendIndices = blendIndexInfo.data;
112
- const blendWeights = blendWeightInfo.data;
113
- const posStride = getVertexFormatComponentCount(positionInfo.format);
114
- const idxStride = getVertexFormatComponentCount(blendIndexInfo.format);
115
- const weightStride = getVertexFormatComponentCount(blendWeightInfo.format);
116
- const vertexCount = Math.floor(positions.length / posStride);
117
- for(let i = 0; i < vertexCount; i++){
118
- let weight = 0;
119
- let maxWeight = -1;
120
- let maxJoint = -1;
121
- const influenceCount = Math.min(4, idxStride, weightStride);
122
- for(let k = 0; k < influenceCount; k++){
123
- const idx = Number(blendIndices[i * idxStride + k]) | 0;
124
- const w = Number(blendWeights[i * weightStride + k]) || 0;
125
- if (idx === jointIndex) {
126
- weight = Math.max(weight, w);
127
- }
128
- if (w > maxWeight) {
129
- maxWeight = w;
130
- maxJoint = idx;
131
- }
132
- }
133
- if (weight < weightThreshold || dominantBoneOnly && maxJoint !== jointIndex) {
134
- continue;
135
- }
136
- const p = new Vector3(Number(positions[i * posStride]) || 0, Number(positions[i * posStride + 1]) || 0, Number(positions[i * posStride + 2]) || 0);
137
- points.push(inverseBind.transformPointAffine(p, p));
138
- }
139
- }
140
- return uniquePoints(points);
141
- }
142
- function uniquePoints(points) {
143
- const result = [];
144
- const keys = new Set();
145
- for (const point of points){
146
- const key = `${Math.round(point.x * 100000)}:${Math.round(point.y * 100000)}:${Math.round(point.z * 100000)}`;
147
- if (!keys.has(key)) {
148
- keys.add(key);
149
- result.push(point);
150
- }
151
- }
152
- return result;
153
- }
154
- function buildConvexHull(points, maxHullVertices, margin) {
155
- const sampled = sampleSupportPoints(points, Math.max(8, maxHullVertices));
156
- if (sampled.length < 4) {
157
- return null;
158
- }
159
- const faces = bruteForceHullFaces(sampled);
160
- if (faces.length < 4) {
161
- return null;
162
- }
163
- const planes = mergePlanes(faces);
164
- if (margin > 0) {
165
- for (const plane of planes){
166
- plane.distance -= margin;
167
- }
168
- }
169
- return {
170
- vertices: sampled.map((point)=>point.clone()),
171
- planes,
172
- edges: extractHullEdges(sampled, planes)
173
- };
174
- }
175
- function sampleSupportPoints(points, maxCount) {
176
- if (points.length <= maxCount) {
177
- return [
178
- ...points
179
- ];
180
- }
181
- const dirs = buildSampleDirections(maxCount);
182
- const selected = [];
183
- const indices = new Set();
184
- for (const dir of dirs){
185
- let bestIndex = -1;
186
- let bestDot = -Infinity;
187
- for(let i = 0; i < points.length; i++){
188
- const d = Vector3.dot(points[i], dir);
189
- if (d > bestDot) {
190
- bestDot = d;
191
- bestIndex = i;
192
- }
193
- }
194
- if (bestIndex >= 0 && !indices.has(bestIndex)) {
195
- indices.add(bestIndex);
196
- selected.push(points[bestIndex]);
197
- if (selected.length >= maxCount) {
198
- break;
199
- }
200
- }
201
- }
202
- return selected.length >= 4 ? selected : [
203
- ...points.slice(0, maxCount)
204
- ];
205
- }
206
- function buildSampleDirections(maxCount) {
207
- const dirs = [
208
- new Vector3(1, 0, 0),
209
- new Vector3(-1, 0, 0),
210
- new Vector3(0, 1, 0),
211
- new Vector3(0, -1, 0),
212
- new Vector3(0, 0, 1),
213
- new Vector3(0, 0, -1)
214
- ];
215
- const rings = Math.max(4, Math.ceil(Math.sqrt(maxCount)));
216
- for(let y = 0; y < rings && dirs.length < maxCount; y++){
217
- const v = rings === 1 ? 0 : -1 + 2 * y / (rings - 1);
218
- const r = Math.sqrt(Math.max(0, 1 - v * v));
219
- for(let x = 0; x < rings * 2 && dirs.length < maxCount; x++){
220
- const a = x / (rings * 2) * Math.PI * 2;
221
- dirs.push(new Vector3(Math.cos(a) * r, v, Math.sin(a) * r));
222
- }
223
- }
224
- return dirs;
225
- }
226
- function bruteForceHullFaces(points) {
227
- const center = new Vector3();
228
- for (const point of points){
229
- Vector3.add(center, point, center);
230
- }
231
- Vector3.scale(center, 1 / points.length, center);
232
- const faces = [];
233
- const faceKeys = new Set();
234
- for(let i = 0; i < points.length - 2; i++){
235
- for(let j = i + 1; j < points.length - 1; j++){
236
- for(let k = j + 1; k < points.length; k++){
237
- const ab = Vector3.sub(points[j], points[i]);
238
- const ac = Vector3.sub(points[k], points[i]);
239
- const normal = Vector3.cross(ab, ac);
240
- const len = normal.magnitude;
241
- if (len <= EPS) {
242
- continue;
243
- }
244
- Vector3.scale(normal, 1 / len, normal);
245
- let distance = -Vector3.dot(normal, points[i]);
246
- if (Vector3.dot(normal, center) + distance > 0) {
247
- Vector3.scale(normal, -1, normal);
248
- distance = -Vector3.dot(normal, points[i]);
249
- }
250
- let valid = true;
251
- for(let p = 0; p < points.length; p++){
252
- if (p === i || p === j || p === k) {
253
- continue;
254
- }
255
- if (Vector3.dot(normal, points[p]) + distance > 1e-5) {
256
- valid = false;
257
- break;
258
- }
259
- }
260
- if (!valid) {
261
- continue;
262
- }
263
- const key = planeKey(normal, distance);
264
- if (faceKeys.has(key)) {
265
- continue;
266
- }
267
- faceKeys.add(key);
268
- faces.push({
269
- a: i,
270
- b: j,
271
- c: k,
272
- normal: normal.clone(),
273
- distance
274
- });
275
- }
276
- }
277
- }
278
- return faces;
279
- }
280
- function mergePlanes(faces) {
281
- const planes = [];
282
- for (const face of faces){
283
- if (planes.some((plane)=>Math.abs(Vector3.dot(plane.normal, face.normal) - 1) < 1e-4 && Math.abs(plane.distance - face.distance) < 1e-4)) {
284
- continue;
285
- }
286
- planes.push({
287
- normal: face.normal.clone(),
288
- distance: face.distance
289
- });
290
- }
291
- return planes;
292
- }
293
- function extractHullEdges(vertices, planes) {
294
- const result = [];
295
- const keys = new Set();
296
- for(let i = 0; i < vertices.length - 1; i++){
297
- for(let j = i + 1; j < vertices.length; j++){
298
- const sharedPlaneCount = planes.reduce((count, plane)=>{
299
- const di = Math.abs(Vector3.dot(plane.normal, vertices[i]) + plane.distance);
300
- const dj = Math.abs(Vector3.dot(plane.normal, vertices[j]) + plane.distance);
301
- return count + (di < 1e-4 && dj < 1e-4 ? 1 : 0);
302
- }, 0);
303
- if (sharedPlaneCount < 2) {
304
- continue;
305
- }
306
- const key = `${i}:${j}`;
307
- if (!keys.has(key)) {
308
- keys.add(key);
309
- result.push(i, j);
310
- }
311
- }
312
- }
313
- return result;
314
- }
315
- function planeKey(normal, distance) {
316
- return `${Math.round(normal.x * 10000)}:${Math.round(normal.y * 10000)}:${Math.round(normal.z * 10000)}:${Math.round(distance * 10000)}`;
317
- }
318
-
319
- export { generateJointDynamicsConvexCollidersFromSkinWeights };
320
- //# sourceMappingURL=convex_collider.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"convex_collider.js","sources":["../../../src/animation/joint_dynamics/convex_collider.ts"],"sourcesContent":["import { Matrix4x4, Vector3 } from '@zephyr3d/base';\nimport { getVertexFormatComponentCount } from '@zephyr3d/device';\nimport type { Mesh, SceneNode } from '../../scene';\nimport { getSceneMeshAssetBinding } from '../../scene';\nimport type { AssetPrimitiveInfo, AssetSubMeshData } from '../../asset';\nimport type { SkinBinding } from '../skeleton';\nimport { ColliderForce, type ColliderR, type ConvexColliderPlane } from './types';\n\n/** @public */\nexport type JointDynamicsConvexColliderGenerationOptions = {\n weightThreshold?: number;\n dominantBoneOnly?: boolean;\n maxHullVertices?: number;\n margin?: number;\n minVertexCount?: number;\n friction?: number;\n inversed?: boolean;\n};\n\n/** @public */\nexport type JointDynamicsConvexColliderGenerationResult = {\n bone: SceneNode;\n collider: ColliderR;\n vertexCount: number;\n hullVertexCount: number;\n};\n\ntype SourcePrimitive = {\n primitive: AssetPrimitiveInfo;\n subMesh?: AssetSubMeshData;\n};\n\ntype Face = {\n a: number;\n b: number;\n c: number;\n normal: Vector3;\n distance: number;\n};\n\nconst EPS = 1e-6;\n\n/**\n * Generate convex JointDynamics colliders from skinned mesh bone weights.\n *\n * @public\n */\nexport function generateJointDynamicsConvexCollidersFromSkinWeights(\n meshes: readonly Mesh[],\n skinBinding: SkinBinding,\n bones: readonly SceneNode[],\n options: JointDynamicsConvexColliderGenerationOptions = {}\n): JointDynamicsConvexColliderGenerationResult[] {\n const sources = collectSourcePrimitives(meshes);\n const results: JointDynamicsConvexColliderGenerationResult[] = [];\n for (const bone of bones) {\n const jointIndex = skinBinding.joints.indexOf(bone);\n if (jointIndex < 0) {\n continue;\n }\n const points = collectBonePoints(sources, skinBinding, jointIndex, options);\n if (points.length < (options.minVertexCount ?? 8)) {\n continue;\n }\n const hull = buildConvexHull(points, options.maxHullVertices ?? 48, options.margin ?? 0);\n if (!hull || hull.vertices.length < 4 || hull.planes.length < 4) {\n continue;\n }\n results.push({\n bone,\n vertexCount: points.length,\n hullVertexCount: hull.vertices.length,\n collider: {\n radius: 0,\n radiusTailScale: 1,\n height: 0,\n friction: options.friction ?? 0,\n isInverseCollider: options.inversed ?? false,\n forceType: ColliderForce.Off,\n convex: hull\n }\n });\n }\n return results;\n}\n\nfunction collectSourcePrimitives(meshes: readonly Mesh[]): SourcePrimitive[] {\n const result: SourcePrimitive[] = [];\n const seen = new Set<AssetPrimitiveInfo>();\n for (const mesh of meshes) {\n const binding = getSceneMeshAssetBinding(mesh);\n const subMesh = binding?.subMesh as AssetSubMeshData | undefined;\n const primitive = subMesh?.primitive ?? null;\n if (primitive && !seen.has(primitive)) {\n seen.add(primitive);\n result.push({ primitive, subMesh });\n }\n }\n return result;\n}\n\nfunction collectBonePoints(\n sources: readonly SourcePrimitive[],\n skinBinding: SkinBinding,\n jointIndex: number,\n options: JointDynamicsConvexColliderGenerationOptions\n): Vector3[] {\n const points: Vector3[] = [];\n const weightThreshold = options.weightThreshold ?? 0.45;\n const dominantBoneOnly = options.dominantBoneOnly ?? true;\n const inverseBind = skinBinding.inverseBindMatrices[jointIndex] ?? Matrix4x4.identity();\n for (const source of sources) {\n const primitive = source.primitive;\n const positionInfo = primitive.vertices.position;\n const blendIndexInfo = primitive.vertices.blendIndices;\n const blendWeightInfo = primitive.vertices.blendWeights;\n if (!positionInfo || !blendIndexInfo || !blendWeightInfo) {\n continue;\n }\n const positions = positionInfo.data;\n const blendIndices = blendIndexInfo.data;\n const blendWeights = blendWeightInfo.data;\n const posStride = getVertexFormatComponentCount(positionInfo.format);\n const idxStride = getVertexFormatComponentCount(blendIndexInfo.format);\n const weightStride = getVertexFormatComponentCount(blendWeightInfo.format);\n const vertexCount = Math.floor(positions.length / posStride);\n for (let i = 0; i < vertexCount; i++) {\n let weight = 0;\n let maxWeight = -1;\n let maxJoint = -1;\n const influenceCount = Math.min(4, idxStride, weightStride);\n for (let k = 0; k < influenceCount; k++) {\n const idx = Number(blendIndices[i * idxStride + k]) | 0;\n const w = Number(blendWeights[i * weightStride + k]) || 0;\n if (idx === jointIndex) {\n weight = Math.max(weight, w);\n }\n if (w > maxWeight) {\n maxWeight = w;\n maxJoint = idx;\n }\n }\n if (weight < weightThreshold || (dominantBoneOnly && maxJoint !== jointIndex)) {\n continue;\n }\n const p = new Vector3(\n Number(positions[i * posStride]) || 0,\n Number(positions[i * posStride + 1]) || 0,\n Number(positions[i * posStride + 2]) || 0\n );\n points.push(inverseBind.transformPointAffine(p, p));\n }\n }\n return uniquePoints(points);\n}\n\nfunction uniquePoints(points: readonly Vector3[]): Vector3[] {\n const result: Vector3[] = [];\n const keys = new Set<string>();\n for (const point of points) {\n const key = `${Math.round(point.x * 100000)}:${Math.round(point.y * 100000)}:${Math.round(point.z * 100000)}`;\n if (!keys.has(key)) {\n keys.add(key);\n result.push(point);\n }\n }\n return result;\n}\n\nfunction buildConvexHull(points: readonly Vector3[], maxHullVertices: number, margin: number) {\n const sampled = sampleSupportPoints(points, Math.max(8, maxHullVertices));\n if (sampled.length < 4) {\n return null;\n }\n const faces = bruteForceHullFaces(sampled);\n if (faces.length < 4) {\n return null;\n }\n const planes = mergePlanes(faces);\n if (margin > 0) {\n for (const plane of planes) {\n plane.distance -= margin;\n }\n }\n return {\n vertices: sampled.map((point) => point.clone()),\n planes,\n edges: extractHullEdges(sampled, planes)\n };\n}\n\nfunction sampleSupportPoints(points: readonly Vector3[], maxCount: number): Vector3[] {\n if (points.length <= maxCount) {\n return [...points];\n }\n const dirs = buildSampleDirections(maxCount);\n const selected: Vector3[] = [];\n const indices = new Set<number>();\n for (const dir of dirs) {\n let bestIndex = -1;\n let bestDot = -Infinity;\n for (let i = 0; i < points.length; i++) {\n const d = Vector3.dot(points[i], dir);\n if (d > bestDot) {\n bestDot = d;\n bestIndex = i;\n }\n }\n if (bestIndex >= 0 && !indices.has(bestIndex)) {\n indices.add(bestIndex);\n selected.push(points[bestIndex]);\n if (selected.length >= maxCount) {\n break;\n }\n }\n }\n return selected.length >= 4 ? selected : [...points.slice(0, maxCount)];\n}\n\nfunction buildSampleDirections(maxCount: number): Vector3[] {\n const dirs = [\n new Vector3(1, 0, 0),\n new Vector3(-1, 0, 0),\n new Vector3(0, 1, 0),\n new Vector3(0, -1, 0),\n new Vector3(0, 0, 1),\n new Vector3(0, 0, -1)\n ];\n const rings = Math.max(4, Math.ceil(Math.sqrt(maxCount)));\n for (let y = 0; y < rings && dirs.length < maxCount; y++) {\n const v = rings === 1 ? 0 : -1 + (2 * y) / (rings - 1);\n const r = Math.sqrt(Math.max(0, 1 - v * v));\n for (let x = 0; x < rings * 2 && dirs.length < maxCount; x++) {\n const a = (x / (rings * 2)) * Math.PI * 2;\n dirs.push(new Vector3(Math.cos(a) * r, v, Math.sin(a) * r));\n }\n }\n return dirs;\n}\n\nfunction bruteForceHullFaces(points: readonly Vector3[]): Face[] {\n const center = new Vector3();\n for (const point of points) {\n Vector3.add(center, point, center);\n }\n Vector3.scale(center, 1 / points.length, center);\n const faces: Face[] = [];\n const faceKeys = new Set<string>();\n for (let i = 0; i < points.length - 2; i++) {\n for (let j = i + 1; j < points.length - 1; j++) {\n for (let k = j + 1; k < points.length; k++) {\n const ab = Vector3.sub(points[j], points[i]);\n const ac = Vector3.sub(points[k], points[i]);\n const normal = Vector3.cross(ab, ac);\n const len = normal.magnitude;\n if (len <= EPS) {\n continue;\n }\n Vector3.scale(normal, 1 / len, normal);\n let distance = -Vector3.dot(normal, points[i]);\n if (Vector3.dot(normal, center) + distance > 0) {\n Vector3.scale(normal, -1, normal);\n distance = -Vector3.dot(normal, points[i]);\n }\n let valid = true;\n for (let p = 0; p < points.length; p++) {\n if (p === i || p === j || p === k) {\n continue;\n }\n if (Vector3.dot(normal, points[p]) + distance > 1e-5) {\n valid = false;\n break;\n }\n }\n if (!valid) {\n continue;\n }\n const key = planeKey(normal, distance);\n if (faceKeys.has(key)) {\n continue;\n }\n faceKeys.add(key);\n faces.push({ a: i, b: j, c: k, normal: normal.clone(), distance });\n }\n }\n }\n return faces;\n}\n\nfunction mergePlanes(faces: readonly Face[]): ConvexColliderPlane[] {\n const planes: ConvexColliderPlane[] = [];\n for (const face of faces) {\n if (\n planes.some(\n (plane) =>\n Math.abs(Vector3.dot(plane.normal, face.normal) - 1) < 1e-4 &&\n Math.abs(plane.distance - face.distance) < 1e-4\n )\n ) {\n continue;\n }\n planes.push({ normal: face.normal.clone(), distance: face.distance });\n }\n return planes;\n}\n\nfunction extractHullEdges(\n vertices: readonly Vector3[],\n planes: readonly ConvexColliderPlane[]\n): number[] {\n const result: number[] = [];\n const keys = new Set<string>();\n for (let i = 0; i < vertices.length - 1; i++) {\n for (let j = i + 1; j < vertices.length; j++) {\n const sharedPlaneCount = planes.reduce((count, plane) => {\n const di = Math.abs(Vector3.dot(plane.normal, vertices[i]) + plane.distance);\n const dj = Math.abs(Vector3.dot(plane.normal, vertices[j]) + plane.distance);\n return count + (di < 1e-4 && dj < 1e-4 ? 1 : 0);\n }, 0);\n if (sharedPlaneCount < 2) {\n continue;\n }\n const key = `${i}:${j}`;\n if (!keys.has(key)) {\n keys.add(key);\n result.push(i, j);\n }\n }\n }\n return result;\n}\n\nfunction planeKey(normal: Vector3, distance: number): string {\n return `${Math.round(normal.x * 10000)}:${Math.round(normal.y * 10000)}:${Math.round(normal.z * 10000)}:${Math.round(distance * 10000)}`;\n}\n"],"names":["EPS","generateJointDynamicsConvexCollidersFromSkinWeights","meshes","skinBinding","bones","options","sources","collectSourcePrimitives","results","bone","jointIndex","joints","indexOf","points","collectBonePoints","length","minVertexCount","hull","buildConvexHull","maxHullVertices","margin","vertices","planes","push","vertexCount","hullVertexCount","collider","radius","radiusTailScale","height","friction","isInverseCollider","inversed","forceType","ColliderForce","Off","convex","result","seen","Set","mesh","binding","getSceneMeshAssetBinding","subMesh","primitive","has","add","weightThreshold","dominantBoneOnly","inverseBind","inverseBindMatrices","Matrix4x4","identity","source","positionInfo","position","blendIndexInfo","blendIndices","blendWeightInfo","blendWeights","positions","data","posStride","getVertexFormatComponentCount","format","idxStride","weightStride","Math","floor","i","weight","maxWeight","maxJoint","influenceCount","min","k","idx","Number","w","max","p","Vector3","transformPointAffine","uniquePoints","keys","point","key","round","x","y","z","sampled","sampleSupportPoints","faces","bruteForceHullFaces","mergePlanes","plane","distance","map","clone","edges","extractHullEdges","maxCount","dirs","buildSampleDirections","selected","indices","dir","bestIndex","bestDot","Infinity","d","dot","slice","rings","ceil","sqrt","v","r","a","PI","cos","sin","center","scale","faceKeys","j","ab","sub","ac","normal","cross","len","magnitude","valid","planeKey","b","c","face","some","abs","sharedPlaneCount","reduce","count","di","dj"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,MAAMA,GAAM,GAAA,IAAA;AAEZ;;;;IAKO,SAASC,mDAAAA,CACdC,MAAuB,EACvBC,WAAwB,EACxBC,KAA2B,EAC3BC,OAAwD,GAAA,EAAE,EAAA;AAE1D,IAAA,MAAMC,UAAUC,uBAAwBL,CAAAA,MAAAA,CAAAA;AACxC,IAAA,MAAMM,UAAyD,EAAE;IACjE,KAAK,MAAMC,QAAQL,KAAO,CAAA;AACxB,QAAA,MAAMM,UAAaP,GAAAA,WAAAA,CAAYQ,MAAM,CAACC,OAAO,CAACH,IAAAA,CAAAA;AAC9C,QAAA,IAAIC,aAAa,CAAG,EAAA;AAClB,YAAA;AAC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