@babylonjs/lite 0.1.1 → 0.2.0
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.
- package/_mat4-storage-f64-Bvh5TymE.js +10 -0
- package/_mat4-storage-f64-Bvh5TymE.js.map +1 -0
- package/{alpha-test-fragment-CUiHCw7W.js → alpha-test-fragment-BCChpzaV.js} +2 -2
- package/{alpha-test-fragment-CUiHCw7W.js.map → alpha-test-fragment-BCChpzaV.js.map} +1 -1
- package/{background-dds-skybox-yHTqabU3.js → background-dds-skybox-ZjrSIxrT.js} +4 -4
- package/background-dds-skybox-ZjrSIxrT.js.map +1 -0
- package/{background-ground-DIw6D3qf.js → background-ground-B2Mie-MI.js} +3 -3
- package/background-ground-B2Mie-MI.js.map +1 -0
- package/{background-hdr-skybox-c4uuTmkP.js → background-hdr-skybox-DDRJYuT2.js} +3 -3
- package/background-hdr-skybox-DDRJYuT2.js.map +1 -0
- package/{background-solid-skybox-DPGBpPbm.js → background-solid-skybox-fjXlnWaD.js} +3 -3
- package/{background-solid-skybox-DPGBpPbm.js.map → background-solid-skybox-fjXlnWaD.js.map} +1 -1
- package/{billboard-renderable-D8mlVGCd.js → billboard-renderable-DKmlOgbM.js} +2 -2
- package/{billboard-renderable-D8mlVGCd.js.map → billboard-renderable-DKmlOgbM.js.map} +1 -1
- package/{clamp-block-BdII67hT.js → clamp-block-CxRBPlUq.js} +2 -2
- package/{clamp-block-BdII67hT.js.map → clamp-block-CxRBPlUq.js.map} +1 -1
- package/{clearcoat-fragment-LCiG98Rf.js → clearcoat-fragment-KbZAa0TA.js} +2 -2
- package/{clearcoat-fragment-LCiG98Rf.js.map → clearcoat-fragment-KbZAa0TA.js.map} +1 -1
- package/{create-skeleton-C9JdIJnb.js → create-skeleton-BBI5urcj.js} +2 -2
- package/{create-skeleton-C9JdIJnb.js.map → create-skeleton-BBI5urcj.js.map} +1 -1
- package/{cubemap-skybox-material-DvXMVc4k.js → cubemap-skybox-material-DvW81drX.js} +2 -2
- package/{cubemap-skybox-material-DvXMVc4k.js.map → cubemap-skybox-material-DvW81drX.js.map} +1 -1
- package/{curve-block-BlJpXVYv.js → curve-block-Dh_xdUj-.js} +2 -2
- package/{curve-block-BlJpXVYv.js.map → curve-block-Dh_xdUj-.js.map} +1 -1
- package/{emissive-fragment-BnNvbBCw.js → emissive-fragment-DD8cvHyx.js} +2 -2
- package/{emissive-fragment-BnNvbBCw.js.map → emissive-fragment-DD8cvHyx.js.map} +1 -1
- package/{esm-shadow-view-DGKdF1NI.js → esm-shadow-view-15S4JK6p.js} +2 -2
- package/{esm-shadow-view-DGKdF1NI.js.map → esm-shadow-view-15S4JK6p.js.map} +1 -1
- package/{esm-shadow-view-Dk9NFtLq.js → esm-shadow-view-DHVS9r7H.js} +2 -2
- package/{esm-shadow-view-Dk9NFtLq.js.map → esm-shadow-view-DHVS9r7H.js.map} +1 -1
- package/{esm-shadow-view-DN9HIaM4.js → esm-shadow-view-DYAc62Kl.js} +2 -2
- package/{esm-shadow-view-DN9HIaM4.js.map → esm-shadow-view-DYAc62Kl.js.map} +1 -1
- package/{gaussian-splatting-pipeline-sh-DgJl7l56.js → gaussian-splatting-pipeline-sh-BvkUhA9V.js} +2 -2
- package/{gaussian-splatting-pipeline-sh-DgJl7l56.js.map → gaussian-splatting-pipeline-sh-BvkUhA9V.js.map} +1 -1
- package/{gltf-animation-D7uyTyO3.js → gltf-animation-KnPzeOIY.js} +3 -3
- package/{gltf-animation-D7uyTyO3.js.map → gltf-animation-KnPzeOIY.js.map} +1 -1
- package/gltf-color-normalize-Qxl-9C48.js +29 -0
- package/gltf-color-normalize-Qxl-9C48.js.map +1 -0
- package/{gltf-ext-basisu-CPg5kPrx.js → gltf-ext-basisu-kmth3UWX.js} +7 -4
- package/gltf-ext-basisu-kmth3UWX.js.map +1 -0
- package/{gltf-ext-node-visibility-MafA9ot2.js → gltf-ext-node-visibility-BjRRd6si.js} +2 -2
- package/{gltf-ext-node-visibility-MafA9ot2.js.map → gltf-ext-node-visibility-BjRRd6si.js.map} +1 -1
- package/{gltf-ext-uv-transform-CE_-T1Tr.js → gltf-ext-uv-transform-MHmR-YyM.js} +2 -2
- package/{gltf-ext-uv-transform-CE_-T1Tr.js.map → gltf-ext-uv-transform-MHmR-YyM.js.map} +1 -1
- package/{gltf-feature-animation-pointer-BjpwOOqo.js → gltf-feature-animation-pointer-rFqLfbO_.js} +3 -3
- package/{gltf-feature-animation-pointer-BjpwOOqo.js.map → gltf-feature-animation-pointer-rFqLfbO_.js.map} +1 -1
- package/{gltf-feature-animations-CCizegp8.js → gltf-feature-animations-DikONdzi.js} +2 -2
- package/{gltf-feature-animations-CCizegp8.js.map → gltf-feature-animations-DikONdzi.js.map} +1 -1
- package/{gltf-feature-gpu-instancing-2e_CFQnl.js → gltf-feature-gpu-instancing-Cj1XjmM6.js} +5 -4
- package/gltf-feature-gpu-instancing-Cj1XjmM6.js.map +1 -0
- package/{gltf-feature-lights-punctual-DDDg4j0U.js → gltf-feature-lights-punctual-C-0SlGmD.js} +5 -5
- package/{gltf-feature-lights-punctual-DDDg4j0U.js.map → gltf-feature-lights-punctual-C-0SlGmD.js.map} +1 -1
- package/{gltf-feature-morph-CKCw6tkX.js → gltf-feature-morph-BAcY14XU.js} +3 -3
- package/{gltf-feature-morph-CKCw6tkX.js.map → gltf-feature-morph-BAcY14XU.js.map} +1 -1
- package/gltf-feature-registry-97sY_x5O.js +59 -0
- package/gltf-feature-registry-97sY_x5O.js.map +1 -0
- package/{gltf-feature-skeleton-D8hWLqi2.js → gltf-feature-skeleton-lVjkDfIU.js} +3 -3
- package/{gltf-feature-skeleton-D8hWLqi2.js.map → gltf-feature-skeleton-lVjkDfIU.js.map} +1 -1
- package/{gltf-feature-variants-Ds6v9byg.js → gltf-feature-variants-BphF4JmV.js} +2 -2
- package/{gltf-feature-variants-Ds6v9byg.js.map → gltf-feature-variants-BphF4JmV.js.map} +1 -1
- package/{gltf-interleave-DGnUlz28.js → gltf-interleave-C9eBqH_F.js} +2 -2
- package/{gltf-interleave-DGnUlz28.js.map → gltf-interleave-C9eBqH_F.js.map} +1 -1
- package/gltf-normals-b2h74380.js +37 -0
- package/gltf-normals-b2h74380.js.map +1 -0
- package/{gltf-pbr-builder-ext-BFOxOCnQ.js → gltf-pbr-builder-ext-DPC0zg_u.js} +2 -2
- package/{gltf-pbr-builder-ext-BFOxOCnQ.js.map → gltf-pbr-builder-ext-DPC0zg_u.js.map} +1 -1
- package/{gltf-variants-DFbr8EES.js → gltf-variants-CnBEZr0o.js} +4 -4
- package/{gltf-variants-DFbr8EES.js.map → gltf-variants-CnBEZr0o.js.map} +1 -1
- package/{gs-picking-pipeline-DzfMASL9.js → gs-picking-pipeline-Bx8LTav6.js} +2 -2
- package/{gs-picking-pipeline-DzfMASL9.js.map → gs-picking-pipeline-Bx8LTav6.js.map} +1 -1
- package/{index-C8HOR2sB.js → index-B7Qhw0xL.js} +3047 -1037
- package/index-B7Qhw0xL.js.map +1 -0
- package/index.d.ts +504 -17
- package/index.js +322 -304
- package/{input-block-DgAJBzN_.js → input-block-Coi_aZwl.js} +2 -2
- package/{input-block-DgAJBzN_.js.map → input-block-Coi_aZwl.js.map} +1 -1
- package/{iridescence-fragment-Gymp7or5.js → iridescence-fragment-DwZcCTdD.js} +2 -2
- package/{iridescence-fragment-Gymp7or5.js.map → iridescence-fragment-DwZcCTdD.js.map} +1 -1
- package/{light-block-B11ew7FA.js → light-block-Np_h5gPI.js} +2 -2
- package/{light-block-B11ew7FA.js.map → light-block-Np_h5gPI.js.map} +1 -1
- package/{loop-block-Bb23EOMb.js → loop-block-BFkLFYGm.js} +2 -2
- package/{loop-block-Bb23EOMb.js.map → loop-block-BFkLFYGm.js.map} +1 -1
- package/{mesh-features-BLENkYVt.js → mesh-features-BAJpbMog.js} +6 -3
- package/mesh-features-BAJpbMog.js.map +1 -0
- package/{morph-fragment-DOVo70gP.js → morph-fragment-DqH-w61u.js} +2 -2
- package/{morph-fragment-DOVo70gP.js.map → morph-fragment-DqH-w61u.js.map} +1 -1
- package/{multilight-wgsl-BGyiIOp3.js → multilight-wgsl-B9Mf9d-q.js} +4 -4
- package/{multilight-wgsl-BGyiIOp3.js.map → multilight-wgsl-B9Mf9d-q.js.map} +1 -1
- package/no-color-view-DsyLSL-W.js +8 -0
- package/no-color-view-DsyLSL-W.js.map +1 -0
- package/{node-registry-DwgC4yth.js → node-registry-Bd-AlrgC.js} +8 -8
- package/{node-registry-DwgC4yth.js.map → node-registry-Bd-AlrgC.js.map} +1 -1
- package/{node-registry-extra-compat-Dhrw8fDQ.js → node-registry-extra-compat-Ch7ApZHF.js} +2 -2
- package/{node-registry-extra-compat-Dhrw8fDQ.js.map → node-registry-extra-compat-Ch7ApZHF.js.map} +1 -1
- package/{node-registry-extra-math-CsAHvIZo.js → node-registry-extra-math-6ezzTkPj.js} +2 -2
- package/{node-registry-extra-math-CsAHvIZo.js.map → node-registry-extra-math-6ezzTkPj.js.map} +1 -1
- package/{node-renderable-DlLIdBmd.js → node-renderable-CS0CmsSp.js} +28 -11
- package/node-renderable-CS0CmsSp.js.map +1 -0
- package/{node-shadow-DKrcqmNg.js → node-shadow-CpnrdvtJ.js} +2 -2
- package/{node-shadow-DKrcqmNg.js.map → node-shadow-CpnrdvtJ.js.map} +1 -1
- package/{normal-map-fragment-DpsIXrJf.js → normal-map-fragment-DradEMl-.js} +3 -3
- package/{normal-map-fragment-DpsIXrJf.js.map → normal-map-fragment-DradEMl-.js.map} +1 -1
- package/pack-mat4-with-offset-BqB8Jqo7.js +37 -0
- package/pack-mat4-with-offset-BqB8Jqo7.js.map +1 -0
- package/package.json +3 -3
- package/{parse-camera-DM3oJJeT.js → parse-camera-CgV4bWc0.js} +2 -2
- package/{parse-camera-DM3oJJeT.js.map → parse-camera-CgV4bWc0.js.map} +1 -1
- package/pbr-fog-wgsl-BqdCid6r.js +8 -0
- package/pbr-fog-wgsl-BqdCid6r.js.map +1 -0
- package/{pbr-metallic-roughness-block-h_KAOZrW.js → pbr-metallic-roughness-block-BFwZj2Nw.js} +2 -2
- package/{pbr-metallic-roughness-block-h_KAOZrW.js.map → pbr-metallic-roughness-block-BFwZj2Nw.js.map} +1 -1
- package/{pbr-metallic-roughness-block-full-6vMm1Jk6.js → pbr-metallic-roughness-block-full-5t0HT3xl.js} +2 -2
- package/{pbr-metallic-roughness-block-full-6vMm1Jk6.js.map → pbr-metallic-roughness-block-full-5t0HT3xl.js.map} +1 -1
- package/{pbr-mr-helper-core-CIwm-T1G.js → pbr-mr-helper-core-R5tOZ8Ap.js} +2 -2
- package/{pbr-mr-helper-core-CIwm-T1G.js.map → pbr-mr-helper-core-R5tOZ8Ap.js.map} +1 -1
- package/{pbr-refraction-DGmMSa2v.js → pbr-refraction-Dd11HnaI.js} +2 -2
- package/{pbr-refraction-DGmMSa2v.js.map → pbr-refraction-Dd11HnaI.js.map} +1 -1
- package/{pbr-renderable-BJxUtPBb.js → pbr-renderable-BHAdF5Vw.js} +80 -38
- package/pbr-renderable-BHAdF5Vw.js.map +1 -0
- package/{pbr-shadow-fragment-LO9SlbJj.js → pbr-shadow-fragment-BxUrFJYZ.js} +6 -1
- package/pbr-shadow-fragment-BxUrFJYZ.js.map +1 -0
- package/{pbr-template-ext-8q7BcTDf.js → pbr-template-ext-CGgB2n2y.js} +3 -2
- package/{pbr-template-ext-8q7BcTDf.js.map → pbr-template-ext-CGgB2n2y.js.map} +1 -1
- package/{pbr-tracking-B3alzn91.js → pbr-tracking-D6i3yPb7.js} +2 -2
- package/{pbr-tracking-B3alzn91.js.map → pbr-tracking-D6i3yPb7.js.map} +1 -1
- package/pbr-transmission-ext-Dll8EYwE.js +190 -0
- package/pbr-transmission-ext-Dll8EYwE.js.map +1 -0
- package/{reflectance-fragment-BCrgPmrt.js → reflectance-fragment-ejMJ4O1o.js} +2 -2
- package/{reflectance-fragment-BCrgPmrt.js.map → reflectance-fragment-ejMJ4O1o.js.map} +1 -1
- package/{shader-renderable-D-6796KR.js → shader-renderable-BMf_vvO0.js} +41 -12
- package/shader-renderable-BMf_vvO0.js.map +1 -0
- package/shader-thin-instance-5_WUfi3m.js +150 -0
- package/shader-thin-instance-5_WUfi3m.js.map +1 -0
- package/shadow-fragment-core-DHN2G6FI.js.map +1 -1
- package/{sheen-fragment-Dze2f7XJ.js → sheen-fragment-CS6z29Fs.js} +2 -2
- package/{sheen-fragment-Dze2f7XJ.js.map → sheen-fragment-CS6z29Fs.js.map} +1 -1
- package/{singlelight-directional-wgsl-CmUDZxwz.js → singlelight-directional-wgsl-4MIgZMeC.js} +2 -2
- package/{singlelight-directional-wgsl-CmUDZxwz.js.map → singlelight-directional-wgsl-4MIgZMeC.js.map} +1 -1
- package/{singlelight-hemispheric-wgsl-t-83IP_s.js → singlelight-hemispheric-wgsl-CK-GUYWe.js} +2 -2
- package/{singlelight-hemispheric-wgsl-t-83IP_s.js.map → singlelight-hemispheric-wgsl-CK-GUYWe.js.map} +1 -1
- package/{singlelight-point-wgsl-CLzULIYV.js → singlelight-point-wgsl-CYtzqCbP.js} +2 -2
- package/{singlelight-point-wgsl-CLzULIYV.js.map → singlelight-point-wgsl-CYtzqCbP.js.map} +1 -1
- package/{singlelight-spot-wgsl-DEEUrfVM.js → singlelight-spot-wgsl-DVbaVufF.js} +2 -2
- package/{singlelight-spot-wgsl-DEEUrfVM.js.map → singlelight-spot-wgsl-DVbaVufF.js.map} +1 -1
- package/{skeleton-fragment-B_XlFbtx.js → skeleton-fragment-BOVmc8YS.js} +2 -2
- package/{skeleton-fragment-B_XlFbtx.js.map → skeleton-fragment-BOVmc8YS.js.map} +1 -1
- package/{skybox-renderable-DDwzu-PT.js → skybox-renderable-DDcCPSly.js} +3 -3
- package/{skybox-renderable-DDwzu-PT.js.map → skybox-renderable-DDcCPSly.js.map} +1 -1
- package/{standard-renderable-GjxL9xSf.js → standard-renderable-D1bhoF0K.js} +27 -81
- package/standard-renderable-D1bhoF0K.js.map +1 -0
- package/{std-ambient-fragment-BoUsD06w.js → std-ambient-fragment-C6WNm8dQ.js} +2 -2
- package/{std-ambient-fragment-BoUsD06w.js.map → std-ambient-fragment-C6WNm8dQ.js.map} +1 -1
- package/{std-cube-reflection-fragment-ulqc3bsP.js → std-cube-reflection-fragment-Bqutpy2q.js} +2 -2
- package/{std-cube-reflection-fragment-ulqc3bsP.js.map → std-cube-reflection-fragment-Bqutpy2q.js.map} +1 -1
- package/{std-emissive-fragment-DNGj1HdQ.js → std-emissive-fragment-B-A83rqX.js} +2 -2
- package/{std-emissive-fragment-DNGj1HdQ.js.map → std-emissive-fragment-B-A83rqX.js.map} +1 -1
- package/{std-lightmap-fragment-Bqj89aIe.js → std-lightmap-fragment-Df7KJezh.js} +2 -2
- package/{std-lightmap-fragment-Bqj89aIe.js.map → std-lightmap-fragment-Df7KJezh.js.map} +1 -1
- package/{std-opacity-fragment-KuPh5N2Z.js → std-opacity-fragment-D9et2jip.js} +2 -2
- package/{std-opacity-fragment-KuPh5N2Z.js.map → std-opacity-fragment-D9et2jip.js.map} +1 -1
- package/{std-reflection-fragment-BA5Ghn_M.js → std-reflection-fragment-DBJeT-yg.js} +2 -2
- package/{std-reflection-fragment-BA5Ghn_M.js.map → std-reflection-fragment-DBJeT-yg.js.map} +1 -1
- package/std-shadow-fragment-C6fD8rW-.js +13 -0
- package/std-shadow-fragment-C6fD8rW-.js.map +1 -0
- package/{std-specular-fragment-CE-6scqd.js → std-specular-fragment-C2ZOss-t.js} +2 -2
- package/{std-specular-fragment-CE-6scqd.js.map → std-specular-fragment-C2ZOss-t.js.map} +1 -1
- package/{std-tracking-CNKZ-hJN.js → std-tracking-C4L4nQGc.js} +2 -2
- package/{std-tracking-CNKZ-hJN.js.map → std-tracking-C4L4nQGc.js.map} +1 -1
- package/{subsurface-fragment-liM3y2-P.js → subsurface-fragment-C1H4ytqK.js} +2 -2
- package/{subsurface-fragment-liM3y2-P.js.map → subsurface-fragment-C1H4ytqK.js.map} +1 -1
- package/thin-instance-cull-binding-CCxrPNO6.js +310 -0
- package/thin-instance-cull-binding-CCxrPNO6.js.map +1 -0
- package/{thin-instance-gpu-C9Gv_Z1w.js → thin-instance-gpu-E8DBd8XL.js} +20 -3
- package/thin-instance-gpu-E8DBd8XL.js.map +1 -0
- package/{tracking-primitives-wgdBY85t.js → tracking-primitives-w4BVV9p9.js} +2 -2
- package/{tracking-primitives-wgdBY85t.js.map → tracking-primitives-w4BVV9p9.js.map} +1 -1
- package/{unlit-fragment-BIlhJpz6.js → unlit-fragment-DU9_mhzZ.js} +2 -2
- package/{unlit-fragment-BIlhJpz6.js.map → unlit-fragment-DU9_mhzZ.js.map} +1 -1
- package/{wgsl-helpers-DyzNzCeE.js → wgsl-helpers-D8sl1VVA.js} +4 -4
- package/{wgsl-helpers-DyzNzCeE.js.map → wgsl-helpers-D8sl1VVA.js.map} +1 -1
- package/background-dds-skybox-yHTqabU3.js.map +0 -1
- package/background-ground-DIw6D3qf.js.map +0 -1
- package/background-hdr-skybox-c4uuTmkP.js.map +0 -1
- package/gltf-ext-basisu-CPg5kPrx.js.map +0 -1
- package/gltf-feature-gpu-instancing-2e_CFQnl.js.map +0 -1
- package/index-C8HOR2sB.js.map +0 -1
- package/mesh-features-BLENkYVt.js.map +0 -1
- package/node-renderable-DlLIdBmd.js.map +0 -1
- package/pbr-renderable-BJxUtPBb.js.map +0 -1
- package/pbr-shadow-fragment-LO9SlbJj.js.map +0 -1
- package/pbr-transmission-ext-BxW4CEGu.js +0 -581
- package/pbr-transmission-ext-BxW4CEGu.js.map +0 -1
- package/shader-renderable-D-6796KR.js.map +0 -1
- package/standard-renderable-GjxL9xSf.js.map +0 -1
- package/std-shadow-fragment-FNQfrJuC.js +0 -8
- package/std-shadow-fragment-FNQfrJuC.js.map +0 -1
- package/thin-instance-gpu-C9Gv_Z1w.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pbr-template-ext-8q7BcTDf.js","sources":["../src/material/pbr/pbr-template-ext.ts"],"sourcesContent":["/**\n * PBR Template Extensions\n *\n * Feature-specific strings for UV transforms, UV2, vertex colors, etc.\n * Lazy-loaded only when these features are detected. This keeps the base\n * pbr-template.ts clean for simple scenes like scene1.\n */\n\nimport type { UboField, VertexAttribute, Varying, BindingDecl } from \"../../shader/fragment-types.js\";\n\nconst STAGE_FRAGMENT = 0x2;\n\n/**\n * Optional extensions config for PbrTemplateConfig.\n * Each field provides WGSL strings and UBO/attribute/varying lists\n * that are only needed for advanced features.\n */\nexport interface PbrTemplateExt {\n /** Extra vertex attributes (e.g., uv2, color). */\n readonly extraVertexAttributes: readonly VertexAttribute[];\n /** Extra varyings (e.g., uv2, vColor). */\n readonly extraVaryings: readonly Varying[];\n /** Extra material UBO fields (e.g., per-texture UV transforms). */\n readonly extraMaterialUboFields: readonly UboField[];\n /** Extra bindings (e.g., occlusion texture on UV2). */\n readonly extraBindings: readonly BindingDecl[];\n /** Vertex body extra code (e.g., `out.uv2 = uv2;`). */\n readonly vertexBodyExtra: string;\n /** Fragment helper functions (e.g., txfUV). */\n readonly fragmentHelpers: string;\n /** Fragment prelude (per-texture UV local vars). */\n readonly fragmentPrelude: string;\n /** UV expression for baseColorTexture (e.g., \"baseColorUV\"). */\n readonly uvForBaseColor: string;\n /** UV expression for normalTexture (e.g., \"normalUV\"). */\n readonly uvForNormal: string;\n /** UV expression for ormTexture (e.g., \"ormUV\"). */\n readonly uvForOrm: string;\n /** UV expression for emissiveTexture (e.g., \"emissiveUV\"). */\n readonly uvForEmissive: string;\n /** UV expression for specGlossTexture (e.g., \"specGlossUV\"). */\n readonly uvForSpecGloss: string;\n /** Base color modifier WGSL (e.g., vertex color multiply). */\n readonly baseColorMod: string;\n /** Normal scale modifier WGSL (empty or inline scaling). */\n readonly normalScaleMod: string;\n /** Occlusion sampling override (null = use default). */\n readonly occlusionOverride: string | null;\n}\n\n/**\n * Create a PbrTemplateExt from the given feature flags.\n * Each flag corresponds to a detected feature in the scene.\n */\nexport function createPbrTemplateExt(flags: {\n /** @internal */\n _hasUvTransform: boolean;\n /** @internal */\n _hasVertexColor: boolean;\n /** @internal */\n _hasUv2: boolean;\n /** @internal */\n _hasOcclusionUv2: boolean;\n /** @internal */\n _hasAnyNormal: boolean;\n /** @internal */\n _hasEmissiveTexture: boolean;\n /** @internal */\n _hasSpecGloss: boolean;\n}): PbrTemplateExt {\n const { _hasUvTransform, _hasVertexColor, _hasUv2, _hasOcclusionUv2, _hasAnyNormal, _hasEmissiveTexture, _hasSpecGloss } = flags;\n\n // ── UV transform helpers ────────────────────────────────────\n const uvTransformUboFields = (name: string): UboField[] => [\n { _name: `${name}UVm`, _type: \"vec4<f32>\" },\n { _name: `${name}UVt`, _type: \"vec4<f32>\" },\n ];\n const uvVarName = (name: string) => (_hasUvTransform ? `${name}UV` : \"input.uv\");\n const uvTransformDecl = (name: string) => (_hasUvTransform ? `let ${name}UV = txfUV(input.uv, material.${name}UVm, material.${name}UVt.xy);\\n` : \"\");\n const UV_TRANSFORM_HELPER_WGSL = _hasUvTransform\n ? `fn txfUV(uv: vec2<f32>, m: vec4<f32>, t: vec2<f32>) -> vec2<f32> {\nreturn vec2<f32>(dot(m.xy, uv), dot(m.zw, uv)) + t;\n}\n`\n : \"\";\n\n // ── Extra vertex attributes ────────────────────────────────\n const extraVertexAttributes: VertexAttribute[] = [];\n if (_hasUv2) {\n extraVertexAttributes.push({ _name: \"uv2\", _type: \"vec2<f32>\", _gpuFormat: \"float32x2\", _arrayStride: 8 });\n }\n if (_hasVertexColor) {\n extraVertexAttributes.push({ _name: \"color\", _type: \"vec3<f32>\", _gpuFormat: \"float32x3\", _arrayStride: 12 });\n }\n\n // ── Extra varyings ──────────────────────────────────────────\n const extraVaryings: Varying[] = [];\n if (_hasUv2) {\n extraVaryings.push({ _name: \"uv2\", _type: \"vec2<f32>\" });\n }\n if (_hasVertexColor) {\n extraVaryings.push({ _name: \"vColor\", _type: \"vec3<f32>\" });\n }\n\n // ── Extra material UBO fields ────────────────────────────────\n const extraMaterialUboFields: UboField[] = [];\n if (_hasUvTransform) {\n extraMaterialUboFields.push(...uvTransformUboFields(\"baseColor\"));\n if (_hasAnyNormal) {\n extraMaterialUboFields.push(...uvTransformUboFields(\"normal\"));\n }\n extraMaterialUboFields.push(...uvTransformUboFields(\"orm\"));\n if (_hasEmissiveTexture) {\n extraMaterialUboFields.push(...uvTransformUboFields(\"emissive\"));\n }\n if (_hasSpecGloss) {\n extraMaterialUboFields.push(...uvTransformUboFields(\"specGloss\"));\n }\n }\n\n // ── Extra bindings ──────────────────────────────────────────\n const extraBindings: BindingDecl[] = [];\n if (_hasOcclusionUv2) {\n extraBindings.push(\n { _name: \"occlusionTexture\", _type: { _kind: \"texture\", _textureType: \"texture_2d<f32>\" }, _visibility: STAGE_FRAGMENT },\n { _name: \"occlusionSampler_\", _type: { _kind: \"sampler\", _samplerType: \"sampler\" }, _visibility: STAGE_FRAGMENT }\n );\n }\n\n // ── Vertex body extra ───────────────────────────────────────\n let vertexBodyExtra = \"\";\n if (_hasUv2) {\n vertexBodyExtra += \"out.uv2 = uv2;\\n\";\n }\n if (_hasVertexColor) {\n vertexBodyExtra += \"out.vColor = color;\\n\";\n }\n\n // ── Fragment helpers ────────────────────────────────────────\n const fragmentHelpers = UV_TRANSFORM_HELPER_WGSL;\n\n // ── Fragment prelude ────────────────────────────────────────\n const fragmentPrelude = _hasUvTransform\n ? uvTransformDecl(\"baseColor\") +\n (_hasAnyNormal ? uvTransformDecl(\"normal\") : \"\") +\n uvTransformDecl(\"orm\") +\n (_hasEmissiveTexture ? uvTransformDecl(\"emissive\") : \"\") +\n (_hasSpecGloss ? uvTransformDecl(\"specGloss\") : \"\")\n : \"\";\n\n // ── UV expressions ──────────────────────────────────────────\n const uvForBaseColor = uvVarName(\"baseColor\");\n const uvForNormal = uvVarName(\"normal\");\n const uvForOrm = uvVarName(\"orm\");\n const uvForEmissive = uvVarName(\"emissive\");\n const uvForSpecGloss = uvVarName(\"specGloss\");\n\n // ── Base color modifier ─────────────────────────────────────\n const baseColorMod = _hasVertexColor ? \"\\nbaseColor *= input.vColor;\" : \"\";\n\n // ── Normal scale modifier ───────────────────────────────────\n // When ext is active, emit the scaledNormal line (replaces default normalMapRaw).\n // Scenes without ext get the master-style direct normalize(normalMapRaw).\n const normalScaleMod = \"let scaledNormal = vec3<f32>(normalMapRaw.xy * material.normalScale, normalMapRaw.z);\\n\";\n\n // ── Occlusion override ──────────────────────────────────────\n // When hasReflectanceExt=false AND _hasOcclusionUv2=true, override occlusion sampling.\n // When hasReflectanceExt=true, the reflectance fragment handles occlusion.\n const occlusionOverride = _hasOcclusionUv2 ? \"let occlusion = textureSample(occlusionTexture, occlusionSampler_, input.uv2).r;\" : null;\n\n return {\n extraVertexAttributes,\n extraVaryings,\n extraMaterialUboFields,\n extraBindings,\n vertexBodyExtra,\n fragmentHelpers,\n fragmentPrelude,\n uvForBaseColor,\n uvForNormal,\n uvForOrm,\n uvForEmissive,\n uvForSpecGloss,\n baseColorMod,\n normalScaleMod,\n occlusionOverride,\n };\n}\n"],"names":[],"mappings":"AAUA,MAAM,iBAAiB;AA4ChB,SAAS,qBAAqB,OAelB;AACf,QAAM,EAAE,iBAAiB,iBAAiB,SAAS,kBAAkB,eAAe,qBAAqB,kBAAkB;AAG3H,QAAM,uBAAuB,CAAC,SAA6B;AAAA,IACvD,EAAE,OAAO,GAAG,IAAI,OAAO,OAAO,YAAA;AAAA,IAC9B,EAAE,OAAO,GAAG,IAAI,OAAO,OAAO,YAAA;AAAA,EAAY;AAE9C,QAAM,YAAY,CAAC,SAAkB,kBAAkB,GAAG,IAAI,OAAO;AACrE,QAAM,kBAAkB,CAAC,SAAkB,kBAAkB,OAAO,IAAI,iCAAiC,IAAI,iBAAiB,IAAI;AAAA,IAAe;AACjJ,QAAM,2BAA2B,kBAC3B;AAAA;AAAA;AAAA,IAIA;AAGN,QAAM,wBAA2C,CAAA;AACjD,MAAI,SAAS;AACT,0BAAsB,KAAK,EAAE,OAAO,OAAO,OAAO,aAAa,YAAY,aAAa,cAAc,EAAA,CAAG;AA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AAgB,WAAW,IAAI,MAChD;AAGN,QAAM,iBAAiB,UAAU,WAAW;AAC5C,QAAM,cAAc,UAAU,QAAQ;AACtC,QAAM,WAAW,UAAU,KAAK;AAChC,QAAM,gBAAgB,UAAU,UAAU;AAC1C,QAAM,iBAAiB,UAAU,WAAW;AAG5C,QAAM,eAAe,kBAAkB,iCAAiC;AAKxE,QAAM,iBAAiB;AAKvB,QAAM,oBAAoB,mBAAmB,qFAAqF;AAElI,SAAO;AAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAER;"}
|
|
1
|
+
{"version":3,"file":"pbr-template-ext-CGgB2n2y.js","sources":["../src/material/pbr/pbr-template-ext.ts"],"sourcesContent":["/**\n * PBR Template Extensions\n *\n * Feature-specific strings for UV transforms, UV2, vertex colors, etc.\n * Lazy-loaded only when these features are detected. This keeps the base\n * pbr-template.ts clean for simple scenes like scene1.\n */\n\nimport type { UboField, VertexAttribute, Varying, BindingDecl } from \"../../shader/fragment-types.js\";\n\nconst STAGE_FRAGMENT = 0x2;\n\n/**\n * Optional extensions config for PbrTemplateConfig.\n * Each field provides WGSL strings and UBO/attribute/varying lists\n * that are only needed for advanced features.\n */\nexport interface PbrTemplateExt {\n /** Extra vertex attributes (e.g., uv2, color). */\n readonly extraVertexAttributes: readonly VertexAttribute[];\n /** Extra varyings (e.g., uv2, vColor). */\n readonly extraVaryings: readonly Varying[];\n /** Extra material UBO fields (e.g., per-texture UV transforms). */\n readonly extraMaterialUboFields: readonly UboField[];\n /** Extra bindings (e.g., occlusion texture on UV2). */\n readonly extraBindings: readonly BindingDecl[];\n /** Vertex body extra code (e.g., `out.uv2 = uv2;`). */\n readonly vertexBodyExtra: string;\n /** Fragment helper functions (e.g., txfUV). */\n readonly fragmentHelpers: string;\n /** Fragment prelude (per-texture UV local vars). */\n readonly fragmentPrelude: string;\n /** UV expression for baseColorTexture (e.g., \"baseColorUV\"). */\n readonly uvForBaseColor: string;\n /** UV expression for normalTexture (e.g., \"normalUV\"). */\n readonly uvForNormal: string;\n /** UV expression for ormTexture (e.g., \"ormUV\"). */\n readonly uvForOrm: string;\n /** UV expression for emissiveTexture (e.g., \"emissiveUV\"). */\n readonly uvForEmissive: string;\n /** UV expression for specGlossTexture (e.g., \"specGlossUV\"). */\n readonly uvForSpecGloss: string;\n /** Base color modifier WGSL (e.g., vertex color multiply). */\n readonly baseColorMod: string;\n /** Normal scale modifier WGSL (empty or inline scaling). */\n readonly normalScaleMod: string;\n /** Occlusion sampling override (null = use default). */\n readonly occlusionOverride: string | null;\n}\n\n/**\n * Create a PbrTemplateExt from the given feature flags.\n * Each flag corresponds to a detected feature in the scene.\n */\nexport function createPbrTemplateExt(flags: {\n /** @internal */\n _hasUvTransform: boolean;\n /** @internal */\n _hasVertexColor: boolean;\n /** @internal */\n _hasUv2: boolean;\n /** @internal */\n _hasOcclusionUv2: boolean;\n /** @internal */\n _hasAnyNormal: boolean;\n /** @internal */\n _hasEmissiveTexture: boolean;\n /** @internal */\n _hasSpecGloss: boolean;\n}): PbrTemplateExt {\n const { _hasUvTransform, _hasVertexColor, _hasUv2, _hasOcclusionUv2, _hasAnyNormal, _hasEmissiveTexture, _hasSpecGloss } = flags;\n\n // ── UV transform helpers ────────────────────────────────────\n const uvTransformUboFields = (name: string): UboField[] => [\n { _name: `${name}UVm`, _type: \"vec4<f32>\" },\n { _name: `${name}UVt`, _type: \"vec4<f32>\" },\n ];\n const uvVarName = (name: string) => (_hasUvTransform ? `${name}UV` : \"input.uv\");\n const uvTransformDecl = (name: string) => (_hasUvTransform ? `let ${name}UV = txfUV(input.uv, material.${name}UVm, material.${name}UVt.xy);\\n` : \"\");\n const UV_TRANSFORM_HELPER_WGSL = _hasUvTransform\n ? `fn txfUV(uv: vec2<f32>, m: vec4<f32>, t: vec2<f32>) -> vec2<f32> {\nreturn vec2<f32>(dot(m.xy, uv), dot(m.zw, uv)) + t;\n}\n`\n : \"\";\n\n // ── Extra vertex attributes ────────────────────────────────\n const extraVertexAttributes: VertexAttribute[] = [];\n if (_hasUv2) {\n extraVertexAttributes.push({ _name: \"uv2\", _type: \"vec2<f32>\", _gpuFormat: \"float32x2\", _arrayStride: 8 });\n }\n if (_hasVertexColor) {\n extraVertexAttributes.push({ _name: \"color\", _type: \"vec3<f32>\", _gpuFormat: \"float32x3\", _arrayStride: 12 });\n }\n\n // ── Extra varyings ──────────────────────────────────────────\n const extraVaryings: Varying[] = [];\n if (_hasUv2) {\n extraVaryings.push({ _name: \"uv2\", _type: \"vec2<f32>\" });\n }\n if (_hasVertexColor) {\n extraVaryings.push({ _name: \"vColor\", _type: \"vec3<f32>\" });\n }\n\n // ── Extra material UBO fields ────────────────────────────────\n const extraMaterialUboFields: UboField[] = [];\n if (_hasUvTransform) {\n extraMaterialUboFields.push(...uvTransformUboFields(\"baseColor\"));\n if (_hasAnyNormal) {\n extraMaterialUboFields.push(...uvTransformUboFields(\"normal\"));\n }\n extraMaterialUboFields.push(...uvTransformUboFields(\"orm\"));\n if (_hasEmissiveTexture) {\n extraMaterialUboFields.push(...uvTransformUboFields(\"emissive\"));\n }\n if (_hasSpecGloss) {\n extraMaterialUboFields.push(...uvTransformUboFields(\"specGloss\"));\n }\n }\n\n // ── Extra bindings ──────────────────────────────────────────\n const extraBindings: BindingDecl[] = [];\n if (_hasOcclusionUv2) {\n extraBindings.push(\n { _name: \"occlusionTexture\", _type: { _kind: \"texture\", _textureType: \"texture_2d<f32>\" }, _visibility: STAGE_FRAGMENT },\n { _name: \"occlusionSampler_\", _type: { _kind: \"sampler\", _samplerType: \"sampler\" }, _visibility: STAGE_FRAGMENT }\n );\n }\n\n // ── Vertex body extra ───────────────────────────────────────\n let vertexBodyExtra = \"\";\n if (_hasUv2) {\n vertexBodyExtra += \"out.uv2 = uv2;\\n\";\n }\n if (_hasVertexColor) {\n vertexBodyExtra += \"out.vColor = color;\\n\";\n }\n\n // ── Fragment helpers ────────────────────────────────────────\n const fragmentHelpers = UV_TRANSFORM_HELPER_WGSL;\n\n // ── Fragment prelude ────────────────────────────────────────\n const fragmentPrelude = _hasUvTransform\n ? uvTransformDecl(\"baseColor\") +\n (_hasAnyNormal ? uvTransformDecl(\"normal\") : \"\") +\n uvTransformDecl(\"orm\") +\n (_hasEmissiveTexture ? uvTransformDecl(\"emissive\") : \"\") +\n (_hasSpecGloss ? uvTransformDecl(\"specGloss\") : \"\")\n : \"\";\n\n // ── UV expressions ──────────────────────────────────────────\n const uvForBaseColor = uvVarName(\"baseColor\");\n const uvForNormal = uvVarName(\"normal\");\n const uvForOrm = uvVarName(\"orm\");\n const uvForEmissive = uvVarName(\"emissive\");\n const uvForSpecGloss = uvVarName(\"specGloss\");\n\n // ── Base color modifier ─────────────────────────────────────\n // NOTE: backtick (not double-quote) so the bundle's WGSL identifier mangler\n // rewrites `baseColor` here to match the mangled `var bc=` declaration in\n // pbr-template.ts. A plain string is skipped by the mangler and produces\n // `unresolved value 'baseColor'` in the bundled shader. See thin-instance-fragment.ts.\n const baseColorMod = _hasVertexColor ? `\\nbaseColor *= input.vColor;` : \"\";\n\n // ── Normal scale modifier ───────────────────────────────────\n // When ext is active, emit the scaledNormal line (replaces default normalMapRaw).\n // Scenes without ext get the master-style direct normalize(normalMapRaw).\n const normalScaleMod = \"let scaledNormal = vec3<f32>(normalMapRaw.xy * material.normalScale, normalMapRaw.z);\\n\";\n\n // ── Occlusion override ──────────────────────────────────────\n // When hasReflectanceExt=false AND _hasOcclusionUv2=true, override occlusion sampling.\n // When hasReflectanceExt=true, the reflectance fragment handles occlusion.\n const occlusionOverride = _hasOcclusionUv2 ? \"let occlusion = textureSample(occlusionTexture, occlusionSampler_, input.uv2).r;\" : null;\n\n return {\n extraVertexAttributes,\n extraVaryings,\n extraMaterialUboFields,\n extraBindings,\n vertexBodyExtra,\n fragmentHelpers,\n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@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as trackScalar, o as observableColor3, b as trackSubProps } from "./tracking-primitives-
|
|
1
|
+
import { t as trackScalar, o as observableColor3, b as trackSubProps } from "./tracking-primitives-w4BVV9p9.js";
|
|
2
2
|
function installPbrTracking(mat) {
|
|
3
3
|
for (const key of ["alpha", "environmentIntensity", "directIntensity", "reflectance", "occlusionStrength", "metallicF0Factor"]) {
|
|
4
4
|
if (mat[key] !== void 0) {
|
|
@@ -28,4 +28,4 @@ function installPbrTracking(mat) {
|
|
|
28
28
|
export {
|
|
29
29
|
installPbrTracking
|
|
30
30
|
};
|
|
31
|
-
//# sourceMappingURL=pbr-tracking-
|
|
31
|
+
//# sourceMappingURL=pbr-tracking-D6i3yPb7.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pbr-tracking-
|
|
1
|
+
{"version":3,"file":"pbr-tracking-D6i3yPb7.js","sources":["../src/material/tracking/pbr-tracking.ts"],"sourcesContent":["/** PBR material auto-dirty tracking. Dynamically imported by enableMaterialTracking(). */\n\nimport type { PbrMaterialProps, SheenProps } from \"../pbr/pbr-material.js\";\nimport { trackScalar, trackSubProps, observableColor3 } from \"./tracking-primitives.js\";\n\nexport function installPbrTracking(mat: PbrMaterialProps): void {\n for (const key of [\"alpha\", \"environmentIntensity\", \"directIntensity\", \"reflectance\", \"occlusionStrength\", \"metallicF0Factor\"]) {\n if ((mat as any)[key] !== undefined) {\n trackScalar(mat, key);\n }\n }\n if (mat.emissiveColor) {\n mat.emissiveColor = observableColor3(mat.emissiveColor[0], mat.emissiveColor[1], mat.emissiveColor[2], mat as any);\n }\n if (mat.metallicReflectanceColor) {\n mat.metallicReflectanceColor = observableColor3(mat.metallicReflectanceColor[0], mat.metallicReflectanceColor[1], mat.metallicReflectanceColor[2], mat as any);\n }\n if (mat.anisotropy) {\n trackSubProps(mat as any, mat.anisotropy, [\"intensity\"]);\n }\n if (mat.clearCoat) {\n trackSubProps(mat as any, mat.clearCoat, [\"intensity\", \"roughness\", \"indexOfRefraction\"]);\n }\n if (mat.sheen) {\n const sh = mat.sheen as SheenProps;\n trackSubProps(mat as any, sh, [\"intensity\", \"roughness\"]);\n if (sh.color) {\n sh.color = observableColor3(sh.color[0]!, sh.color[1]!, sh.color[2]!, mat as any);\n }\n }\n}\n"],"names":[],"mappings":";AAKO,SAAS,mBAAmB,KAA6B;AAC5D,aAAW,OAAO,CAAC,SAAS,wBAAwB,mBAAmB,eAAe,qBAAqB,kBAAkB,GAAG;AAC5H,QAAK,IAAY,GAAG,MAAM,QAAW;AACjC,kBAAY,KAAK,GAAG;AAAA,IACxB;AAAA,EACJ;AACA,MAAI,IAAI,eAAe;AACnB,QAAI,gBAAgB,iBAAiB,IAAI,cAAc,CAAC,GAAG,IAAI,cAAc,CAAC,GAAG,IAAI,cAAc,CAAC,GAAG,GAAU;AAAA,EACrH;AACA,MAAI,IAAI,0BAA0B;AAC9B,QAAI,2BAA2B,iBAAiB,IAAI,yBAAyB,CAAC,GAAG,IAAI,yBAAyB,CAAC,GAAG,IAAI,yBAAyB,CAAC,GAAG,GAAU;AAAA,EACjK;AACA,MAAI,IAAI,YAAY;AAChB,kBAAc,KAAY,IAAI,YAAY,CAAC,WAAW,CAAC;AAAA,EAC3D;AACA,MAAI,IAAI,WAAW;AACf,kBAAc,KAAY,IAAI,WAAW,CAAC,aAAa,aAAa,mBAAmB,CAAC;AAAA,EAC5F;AACA,MAAI,IAAI,OAAO;AACX,UAAM,KAAK,IAAI;AACf,kBAAc,KAAY,IAAI,CAAC,aAAa,WAAW,CAAC;AACxD,QAAI,GAAG,OAAO;AACV,SAAG,QAAQ,iBAAiB,GAAG,MAAM,CAAC,GAAI,GAAG,MAAM,CAAC,GAAI,GAAG,MAAM,CAAC,GAAI,GAAU;AAAA,IACpF;AAAA,EACJ;AACJ;"}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { b9 as PBR2_HAS_REFRACTION, ba as PBR2_HAS_REFRACTION_MAP, bb as getTrilinearAnisotropicSampler, av as PBR_HAS_THICKNESS_MAP, bc as PBR2_LINEAR_IMAGE_PROCESSING, bd as PBR2_HAS_DISPERSION, ax as PBR2_HAS_THICKNESS_GLTF_CHANNEL, be as PBR2_HAS_VOLUME, bf as enableSceneTransmission } from "./index-B7Qhw0xL.js";
|
|
2
|
+
const LINEAR_IMAGE_PROCESSING_SLOTS = { NI: `if(scene.vImageInfos.w>=0.0){`, BC: `}` };
|
|
3
|
+
function makeRefractionMod(hasVolume, hasMap, hasThicknessMap, useGltfThicknessChannel, hasDispersion, dispersionSampleWgsl) {
|
|
4
|
+
const thicknessScaleLine = hasVolume || hasThicknessMap ? `let ts=max(length(mesh.world[0].xyz),max(length(mesh.world[1].xyz),length(mesh.world[2].xyz)));` : ``;
|
|
5
|
+
const thicknessLine = hasThicknessMap ? `let ths=textureSample(thicknessTexture_,thicknessSampler_,input.uv).${useGltfThicknessChannel ? "g" : "r"};
|
|
6
|
+
let th=(material.thicknessParams.x+ths*material.thicknessParams.y)*ts;` : hasVolume ? `let th=material.refractionParams.z*ts;` : `let th=material.refractionParams.z;`;
|
|
7
|
+
const textureLine = hasMap ? `let ri=material.refractionParams.x*textureSample(refractionMapTexture,refractionMapSampler,input.uv).r;` : `let ri=material.refractionParams.x;`;
|
|
8
|
+
const absorptionLine = hasVolume ? `let ab=exp(material.volumeParams.rgb*th);` : ``;
|
|
9
|
+
const refractionLine = hasVolume ? `let fr=er*surfaceAlbedo*(ri*ab)*(vec3<f32>(1.0)-colorSpecularEnvReflectance.rgb);` : `let fr=er*surfaceAlbedo*ri*(vec3<f32>(1.0)-colorSpecularEnvReflectance.rgb);`;
|
|
10
|
+
const sampleLines = hasDispersion && dispersionSampleWgsl ? dispersionSampleWgsl : `let rd=refract(-V,N,material.refractionParams.y);
|
|
11
|
+
let cp=scene.viewProjection*vec4<f32>(input.worldPos+rd*th,1.0);
|
|
12
|
+
let ruv=(cp.xy/cp.w)*vec2<f32>(0.5,-0.5)+vec2<f32>(0.5,0.5);
|
|
13
|
+
let er=textureSampleLevel(refractionTexture,refractionSampler_,ruv,lv).rgb*material.environmentIntensity;`;
|
|
14
|
+
return `{
|
|
15
|
+
${thicknessScaleLine}
|
|
16
|
+
${textureLine}
|
|
17
|
+
${thicknessLine}
|
|
18
|
+
let ro=1.0-ri;
|
|
19
|
+
let ra=mix(alphaG,0.0,clamp(material.refractionParams.w*3.0-2.0,0.0,1.0));
|
|
20
|
+
let lv=clamp(log2(f32(textureDimensions(refractionTexture).x)*ra)-4.0,0.0,f32(textureNumLevels(refractionTexture)-1));
|
|
21
|
+
${sampleLines}
|
|
22
|
+
${absorptionLine}
|
|
23
|
+
${refractionLine}
|
|
24
|
+
color=finalIrradiance*ro*ro+finalRadianceScaled+finalSpecularScaled+directDiffuse*ro*ro+fr+emissive;
|
|
25
|
+
}`;
|
|
26
|
+
}
|
|
27
|
+
function createRefractionRttFragment(hasVolume, hasMap, hasThicknessMap, useGltfThicknessChannel, linearImageProcessing, hasDispersion, dispersionSampleWgsl) {
|
|
28
|
+
const uboFields = [{ _name: "refractionParams", _type: "vec4<f32>" }];
|
|
29
|
+
if (hasVolume) {
|
|
30
|
+
uboFields.push({ _name: "volumeParams", _type: "vec4<f32>" });
|
|
31
|
+
}
|
|
32
|
+
if (hasThicknessMap) {
|
|
33
|
+
uboFields.push({ _name: "thicknessParams", _type: "vec4<f32>" });
|
|
34
|
+
}
|
|
35
|
+
const bindings = [
|
|
36
|
+
{ _name: "refractionTexture", _type: { _kind: "texture", _textureType: "texture_2d<f32>" }, _visibility: 2 },
|
|
37
|
+
{ _name: "refractionSampler_", _type: { _kind: "sampler", _samplerType: "sampler" }, _visibility: 2 }
|
|
38
|
+
];
|
|
39
|
+
if (hasMap) {
|
|
40
|
+
bindings.push(
|
|
41
|
+
{ _name: "refractionMapTexture", _type: { _kind: "texture", _textureType: "texture_2d<f32>" }, _visibility: 2 },
|
|
42
|
+
{ _name: "refractionMapSampler", _type: { _kind: "sampler", _samplerType: "sampler" }, _visibility: 2 }
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
if (hasThicknessMap) {
|
|
46
|
+
bindings.push(
|
|
47
|
+
{ _name: "thicknessTexture_", _type: { _kind: "texture", _textureType: "texture_2d<f32>" }, _visibility: 2 },
|
|
48
|
+
{ _name: "thicknessSampler_", _type: { _kind: "sampler", _samplerType: "sampler" }, _visibility: 2 }
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
_id: "refraction",
|
|
53
|
+
_dependencies: ["ibl"],
|
|
54
|
+
_uboFields: uboFields,
|
|
55
|
+
_bindings: bindings,
|
|
56
|
+
_fragmentSlots: linearImageProcessing ? { AI: makeRefractionMod(hasVolume, hasMap, hasThicknessMap, useGltfThicknessChannel, hasDispersion, dispersionSampleWgsl), ...LINEAR_IMAGE_PROCESSING_SLOTS } : { AI: makeRefractionMod(hasVolume, hasMap, hasThicknessMap, useGltfThicknessChannel, hasDispersion, dispersionSampleWgsl) }
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function writeRefractionUBO(data, mat, offsets) {
|
|
60
|
+
var _a, _b;
|
|
61
|
+
const ss = mat.subsurface;
|
|
62
|
+
const refr = ss == null ? void 0 : ss.refraction;
|
|
63
|
+
if (!refr) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const off = offsets.get("refractionParams");
|
|
67
|
+
if (off === void 0) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const o = off / 4;
|
|
71
|
+
data[o] = refr.intensity ?? 0;
|
|
72
|
+
const ior = refr.indexOfRefraction ?? 1.5;
|
|
73
|
+
const thick = ss.thickness;
|
|
74
|
+
data[o + 1] = 1 / (refr.useThicknessAsDepth && (thick == null ? void 0 : thick.max) ? ior : 1);
|
|
75
|
+
data[o + 2] = refr.useThicknessAsDepth ? (thick == null ? void 0 : thick.max) ?? 0 : 1;
|
|
76
|
+
data[o + 3] = 1 / ior;
|
|
77
|
+
const vOff = offsets.get("volumeParams");
|
|
78
|
+
if (vOff !== void 0) {
|
|
79
|
+
const vo = vOff / 4;
|
|
80
|
+
const tint = ((_a = ss.tint) == null ? void 0 : _a.color) ?? [1, 1, 1];
|
|
81
|
+
const dist = Math.max(((_b = ss.tint) == null ? void 0 : _b.atDistance) ?? 1, 1e-4);
|
|
82
|
+
data[vo] = Math.log(Math.max(tint[0], 1e-6)) / dist;
|
|
83
|
+
data[vo + 1] = Math.log(Math.max(tint[1], 1e-6)) / dist;
|
|
84
|
+
data[vo + 2] = Math.log(Math.max(tint[2], 1e-6)) / dist;
|
|
85
|
+
data[vo + 3] = refr.dispersion ?? 0;
|
|
86
|
+
}
|
|
87
|
+
const tOff = offsets.get("thicknessParams");
|
|
88
|
+
if (tOff !== void 0) {
|
|
89
|
+
const to = tOff / 4;
|
|
90
|
+
const min = (thick == null ? void 0 : thick.min) ?? 0;
|
|
91
|
+
const max = (thick == null ? void 0 : thick.max) ?? 1;
|
|
92
|
+
data[to] = min;
|
|
93
|
+
data[to + 1] = max - min;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function makeRefractionRttExt(dispersionSampleWgsl) {
|
|
97
|
+
return {
|
|
98
|
+
id: "refraction",
|
|
99
|
+
phase: "fragment",
|
|
100
|
+
detect(mat) {
|
|
101
|
+
var _a, _b, _c;
|
|
102
|
+
const m = mat;
|
|
103
|
+
const ss = m.subsurface;
|
|
104
|
+
const refr = ss == null ? void 0 : ss.refraction;
|
|
105
|
+
const linearImageProcessing = m._linearImageProcessing ? PBR2_LINEAR_IMAGE_PROCESSING : 0;
|
|
106
|
+
const intensity = m.transmissive ? (refr == null ? void 0 : refr.intensity) ?? 0 : 0;
|
|
107
|
+
if (intensity <= 0) {
|
|
108
|
+
return { f: 0, f2: linearImageProcessing };
|
|
109
|
+
}
|
|
110
|
+
let f = 0;
|
|
111
|
+
let f2 = linearImageProcessing | PBR2_HAS_REFRACTION;
|
|
112
|
+
if (refr == null ? void 0 : refr.texture) {
|
|
113
|
+
f2 |= PBR2_HAS_REFRACTION_MAP;
|
|
114
|
+
}
|
|
115
|
+
if ((_a = ss == null ? void 0 : ss.thickness) == null ? void 0 : _a.texture) {
|
|
116
|
+
f |= PBR_HAS_THICKNESS_MAP;
|
|
117
|
+
}
|
|
118
|
+
if ((_b = ss == null ? void 0 : ss.thickness) == null ? void 0 : _b.useGlTFChannel) {
|
|
119
|
+
f2 |= PBR2_HAS_THICKNESS_GLTF_CHANNEL;
|
|
120
|
+
}
|
|
121
|
+
if (((_c = ss == null ? void 0 : ss.tint) == null ? void 0 : _c.atDistance) !== void 0) {
|
|
122
|
+
f2 |= PBR2_HAS_VOLUME;
|
|
123
|
+
if (refr == null ? void 0 : refr.dispersion) {
|
|
124
|
+
f2 |= PBR2_HAS_DISPERSION;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return { f, f2 };
|
|
128
|
+
},
|
|
129
|
+
frag(ctx) {
|
|
130
|
+
const linearImageProcessing = (ctx._features2 & PBR2_LINEAR_IMAGE_PROCESSING) !== 0;
|
|
131
|
+
if (!(ctx._features2 & PBR2_HAS_REFRACTION)) {
|
|
132
|
+
return linearImageProcessing ? { _id: "linear", _fragmentSlots: LINEAR_IMAGE_PROCESSING_SLOTS } : null;
|
|
133
|
+
}
|
|
134
|
+
return createRefractionRttFragment(
|
|
135
|
+
(ctx._features2 & PBR2_HAS_VOLUME) !== 0,
|
|
136
|
+
(ctx._features2 & PBR2_HAS_REFRACTION_MAP) !== 0,
|
|
137
|
+
(ctx._features & PBR_HAS_THICKNESS_MAP) !== 0,
|
|
138
|
+
(ctx._features2 & PBR2_HAS_THICKNESS_GLTF_CHANNEL) !== 0,
|
|
139
|
+
linearImageProcessing,
|
|
140
|
+
(ctx._features2 & PBR2_HAS_DISPERSION) !== 0,
|
|
141
|
+
dispersionSampleWgsl
|
|
142
|
+
);
|
|
143
|
+
},
|
|
144
|
+
writeUbo(data, mat, offsets) {
|
|
145
|
+
writeRefractionUBO(data, mat, offsets);
|
|
146
|
+
},
|
|
147
|
+
bind(ctx, entries, b) {
|
|
148
|
+
var _a, _b, _c, _d;
|
|
149
|
+
if (!(ctx._features2 & PBR2_HAS_REFRACTION)) {
|
|
150
|
+
return b;
|
|
151
|
+
}
|
|
152
|
+
const texture = ctx._refractionTexture;
|
|
153
|
+
if (!texture) {
|
|
154
|
+
throw new Error("PBR transmission requires a frame-graph refraction texture.");
|
|
155
|
+
}
|
|
156
|
+
entries.push({ binding: b++, resource: texture.view });
|
|
157
|
+
entries.push({ binding: b++, resource: texture.sampler });
|
|
158
|
+
if ((ctx._features2 & PBR2_HAS_REFRACTION_MAP) !== 0) {
|
|
159
|
+
const map = (_b = (_a = ctx._material.subsurface) == null ? void 0 : _a.refraction) == null ? void 0 : _b.texture;
|
|
160
|
+
entries.push({ binding: b++, resource: map.view });
|
|
161
|
+
entries.push({ binding: b++, resource: getTrilinearAnisotropicSampler(ctx._engine) });
|
|
162
|
+
}
|
|
163
|
+
if ((ctx._features & PBR_HAS_THICKNESS_MAP) !== 0) {
|
|
164
|
+
const thickness = (_d = (_c = ctx._material.subsurface) == null ? void 0 : _c.thickness) == null ? void 0 : _d.texture;
|
|
165
|
+
entries.push({ binding: b++, resource: thickness.view });
|
|
166
|
+
entries.push({ binding: b++, resource: thickness.sampler });
|
|
167
|
+
}
|
|
168
|
+
return b;
|
|
169
|
+
},
|
|
170
|
+
textures(mat, out) {
|
|
171
|
+
var _a, _b, _c, _d;
|
|
172
|
+
const tex = (_b = (_a = mat.subsurface) == null ? void 0 : _a.refraction) == null ? void 0 : _b.texture;
|
|
173
|
+
if (tex) {
|
|
174
|
+
out.push(tex);
|
|
175
|
+
}
|
|
176
|
+
const thickness = (_d = (_c = mat.subsurface) == null ? void 0 : _c.thickness) == null ? void 0 : _d.texture;
|
|
177
|
+
if (thickness) {
|
|
178
|
+
out.push(thickness);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
function registerPbrTransmission(scene, engine, register, dispersionSampleWgsl) {
|
|
184
|
+
enableSceneTransmission(scene, engine);
|
|
185
|
+
register(makeRefractionRttExt(dispersionSampleWgsl));
|
|
186
|
+
}
|
|
187
|
+
export {
|
|
188
|
+
registerPbrTransmission
|
|
189
|
+
};
|
|
190
|
+
//# sourceMappingURL=pbr-transmission-ext-Dll8EYwE.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pbr-transmission-ext-Dll8EYwE.js","sources":["../src/material/pbr/fragments/refraction-rtt-fragment.ts","../src/material/pbr/pbr-transmission-ext.ts"],"sourcesContent":["import type { ShaderFragment, UboField } from \"../../../shader/fragment-types.js\";\nimport type { PbrMaterialProps, SubSurfaceProps } from \"../pbr-material.js\";\nimport type { PbrExt } from \"../pbr-flags.js\";\nimport { getTrilinearAnisotropicSampler } from \"../../../resource/trilinear-anisotropic-sampler.js\";\nimport {\n PBR_HAS_THICKNESS_MAP,\n PBR2_HAS_DISPERSION,\n PBR2_HAS_REFRACTION,\n PBR2_HAS_REFRACTION_MAP,\n PBR2_HAS_THICKNESS_GLTF_CHANNEL,\n PBR2_HAS_VOLUME,\n PBR2_LINEAR_IMAGE_PROCESSING,\n} from \"../pbr-flag-bits.js\";\n\ntype TransmissionMat = PbrMaterialProps & { _linearImageProcessing?: boolean };\nconst LINEAR_IMAGE_PROCESSING_SLOTS = { NI: `if(scene.vImageInfos.w>=0.0){`, BC: `}` };\n\nfunction makeRefractionMod(\n hasVolume: boolean,\n hasMap: boolean,\n hasThicknessMap: boolean,\n useGltfThicknessChannel: boolean,\n hasDispersion: boolean,\n dispersionSampleWgsl: string | undefined\n): string {\n const thicknessScaleLine = hasVolume || hasThicknessMap ? `let ts=max(length(mesh.world[0].xyz),max(length(mesh.world[1].xyz),length(mesh.world[2].xyz)));` : ``;\n const thicknessLine = hasThicknessMap\n ? `let ths=textureSample(thicknessTexture_,thicknessSampler_,input.uv).${useGltfThicknessChannel ? \"g\" : \"r\"};\nlet th=(material.thicknessParams.x+ths*material.thicknessParams.y)*ts;`\n : hasVolume\n ? `let th=material.refractionParams.z*ts;`\n : `let th=material.refractionParams.z;`;\n const textureLine = hasMap ? `let ri=material.refractionParams.x*textureSample(refractionMapTexture,refractionMapSampler,input.uv).r;` : `let ri=material.refractionParams.x;`;\n const absorptionLine = hasVolume ? `let ab=exp(material.volumeParams.rgb*th);` : ``;\n const refractionLine = hasVolume\n ? `let fr=er*surfaceAlbedo*(ri*ab)*(vec3<f32>(1.0)-colorSpecularEnvReflectance.rgb);`\n : `let fr=er*surfaceAlbedo*ri*(vec3<f32>(1.0)-colorSpecularEnvReflectance.rgb);`;\n\n // Refracted environment sample. Dispersion splits the refracted ray into\n // per-RGB index-of-refraction offsets (chromatic aberration); that 3-ray WGSL\n // is injected from a dynamically-imported module (see refraction-dispersion-wgsl.ts)\n // so non-dispersion transmission scenes keep the lean single-ray path below.\n const sampleLines =\n hasDispersion && dispersionSampleWgsl\n ? dispersionSampleWgsl\n : `let rd=refract(-V,N,material.refractionParams.y);\nlet cp=scene.viewProjection*vec4<f32>(input.worldPos+rd*th,1.0);\nlet ruv=(cp.xy/cp.w)*vec2<f32>(0.5,-0.5)+vec2<f32>(0.5,0.5);\nlet er=textureSampleLevel(refractionTexture,refractionSampler_,ruv,lv).rgb*material.environmentIntensity;`;\n\n return `{\n${thicknessScaleLine}\n${textureLine}\n${thicknessLine}\nlet ro=1.0-ri;\nlet ra=mix(alphaG,0.0,clamp(material.refractionParams.w*3.0-2.0,0.0,1.0));\nlet lv=clamp(log2(f32(textureDimensions(refractionTexture).x)*ra)-4.0,0.0,f32(textureNumLevels(refractionTexture)-1));\n${sampleLines}\n${absorptionLine}\n${refractionLine}\ncolor=finalIrradiance*ro*ro+finalRadianceScaled+finalSpecularScaled+directDiffuse*ro*ro+fr+emissive;\n}`;\n}\n\nfunction createRefractionRttFragment(\n hasVolume: boolean,\n hasMap: boolean,\n hasThicknessMap: boolean,\n useGltfThicknessChannel: boolean,\n linearImageProcessing: boolean,\n hasDispersion: boolean,\n dispersionSampleWgsl: string | undefined\n): ShaderFragment {\n const uboFields: UboField[] = [{ _name: \"refractionParams\", _type: \"vec4<f32>\" as const }];\n if (hasVolume) {\n uboFields.push({ _name: \"volumeParams\", _type: \"vec4<f32>\" as const });\n }\n if (hasThicknessMap) {\n uboFields.push({ _name: \"thicknessParams\", _type: \"vec4<f32>\" as const });\n }\n const bindings = [\n { _name: \"refractionTexture\", _type: { _kind: \"texture\", _textureType: \"texture_2d<f32>\" } as const, _visibility: 2 },\n { _name: \"refractionSampler_\", _type: { _kind: \"sampler\", _samplerType: \"sampler\" } as const, _visibility: 2 },\n ];\n if (hasMap) {\n bindings.push(\n { _name: \"refractionMapTexture\", _type: { _kind: \"texture\", _textureType: \"texture_2d<f32>\" } as const, _visibility: 2 },\n { _name: \"refractionMapSampler\", _type: { _kind: \"sampler\", _samplerType: \"sampler\" } as const, _visibility: 2 }\n );\n }\n if (hasThicknessMap) {\n bindings.push(\n { _name: \"thicknessTexture_\", _type: { _kind: \"texture\", _textureType: \"texture_2d<f32>\" } as const, _visibility: 2 },\n { _name: \"thicknessSampler_\", _type: { _kind: \"sampler\", _samplerType: \"sampler\" } as const, _visibility: 2 }\n );\n }\n return {\n _id: \"refraction\",\n _dependencies: [\"ibl\"],\n _uboFields: uboFields,\n _bindings: bindings,\n _fragmentSlots: linearImageProcessing\n ? { AI: makeRefractionMod(hasVolume, hasMap, hasThicknessMap, useGltfThicknessChannel, hasDispersion, dispersionSampleWgsl), ...LINEAR_IMAGE_PROCESSING_SLOTS }\n : { AI: makeRefractionMod(hasVolume, hasMap, hasThicknessMap, useGltfThicknessChannel, hasDispersion, dispersionSampleWgsl) },\n };\n}\n\nfunction writeRefractionUBO(data: Float32Array, mat: PbrMaterialProps, offsets: ReadonlyMap<string, number>): void {\n const ss = mat.subsurface as SubSurfaceProps | undefined;\n const refr = ss?.refraction;\n if (!refr) {\n return;\n }\n const off = offsets.get(\"refractionParams\");\n if (off === undefined) {\n return;\n }\n const o = off / 4;\n data[o] = refr.intensity ?? 0;\n const ior = refr.indexOfRefraction ?? 1.5;\n const thick = ss!.thickness;\n data[o + 1] = 1.0 / (refr.useThicknessAsDepth && thick?.max ? ior : 1.0);\n data[o + 2] = refr.useThicknessAsDepth ? (thick?.max ?? 0.0) : 1.0;\n data[o + 3] = 1.0 / ior;\n\n const vOff = offsets.get(\"volumeParams\");\n if (vOff !== undefined) {\n const vo = vOff / 4;\n const tint = ss!.tint?.color ?? [1, 1, 1];\n const dist = Math.max(ss!.tint?.atDistance ?? 1, 0.0001);\n data[vo] = Math.log(Math.max(tint[0]!, 1e-6)) / dist;\n data[vo + 1] = Math.log(Math.max(tint[1]!, 1e-6)) / dist;\n data[vo + 2] = Math.log(Math.max(tint[2]!, 1e-6)) / dist;\n // w carries the chromatic dispersion strength (0 when no KHR_materials_dispersion).\n data[vo + 3] = refr.dispersion ?? 0;\n }\n\n const tOff = offsets.get(\"thicknessParams\");\n if (tOff !== undefined) {\n const to = tOff / 4;\n const min = thick?.min ?? 0;\n const max = thick?.max ?? 1;\n data[to] = min;\n data[to + 1] = max - min;\n }\n}\n\n/** Build the PBR refraction/transmission extension. When the scene contains a\n * dispersive material, `dispersionSampleWgsl` carries the per-RGB 3-ray sample\n * WGSL (dynamically imported, scene-isolated); otherwise it is undefined and the\n * lean single-ray refraction path is emitted. */\nexport function makeRefractionRttExt(dispersionSampleWgsl?: string): PbrExt {\n return {\n id: \"refraction\",\n phase: \"fragment\",\n detect(mat) {\n const m = mat as TransmissionMat;\n const ss = m.subsurface as SubSurfaceProps | undefined;\n const refr = ss?.refraction;\n const linearImageProcessing = m._linearImageProcessing ? PBR2_LINEAR_IMAGE_PROCESSING : 0;\n const intensity = m.transmissive ? (refr?.intensity ?? 0) : 0;\n if (intensity <= 0) {\n return { f: 0, f2: linearImageProcessing };\n }\n let f = 0;\n let f2 = linearImageProcessing | PBR2_HAS_REFRACTION;\n if (refr?.texture) {\n f2 |= PBR2_HAS_REFRACTION_MAP;\n }\n if (ss?.thickness?.texture) {\n f |= PBR_HAS_THICKNESS_MAP;\n }\n if (ss?.thickness?.useGlTFChannel) {\n f2 |= PBR2_HAS_THICKNESS_GLTF_CHANNEL;\n }\n if (ss?.tint?.atDistance !== undefined) {\n f2 |= PBR2_HAS_VOLUME;\n // Dispersion requires the volume path (per-channel etas + volumeParams.w storage).\n if (refr?.dispersion) {\n f2 |= PBR2_HAS_DISPERSION;\n }\n }\n return { f, f2 };\n },\n frag(ctx) {\n const linearImageProcessing = (ctx._features2 & PBR2_LINEAR_IMAGE_PROCESSING) !== 0;\n if (!(ctx._features2 & PBR2_HAS_REFRACTION)) {\n return linearImageProcessing ? { _id: \"linear\", _fragmentSlots: LINEAR_IMAGE_PROCESSING_SLOTS } : null;\n }\n return createRefractionRttFragment(\n (ctx._features2 & PBR2_HAS_VOLUME) !== 0,\n (ctx._features2 & PBR2_HAS_REFRACTION_MAP) !== 0,\n (ctx._features & PBR_HAS_THICKNESS_MAP) !== 0,\n (ctx._features2 & PBR2_HAS_THICKNESS_GLTF_CHANNEL) !== 0,\n linearImageProcessing,\n (ctx._features2 & PBR2_HAS_DISPERSION) !== 0,\n dispersionSampleWgsl\n );\n },\n writeUbo(data, mat, offsets) {\n writeRefractionUBO(data, mat as PbrMaterialProps, offsets);\n },\n bind(ctx, entries, b) {\n if (!(ctx._features2 & PBR2_HAS_REFRACTION)) {\n return b;\n }\n const texture = ctx._refractionTexture;\n if (!texture) {\n throw new Error(\"PBR transmission requires a frame-graph refraction texture.\");\n }\n entries.push({ binding: b++, resource: texture.view });\n entries.push({ binding: b++, resource: texture.sampler });\n if ((ctx._features2 & PBR2_HAS_REFRACTION_MAP) !== 0) {\n const map = ((ctx._material as PbrMaterialProps).subsurface?.refraction as SubSurfaceProps[\"refraction\"] | undefined)?.texture!;\n entries.push({ binding: b++, resource: map.view });\n entries.push({ binding: b++, resource: getTrilinearAnisotropicSampler(ctx._engine) });\n }\n if ((ctx._features & PBR_HAS_THICKNESS_MAP) !== 0) {\n const thickness = (ctx._material as PbrMaterialProps).subsurface?.thickness?.texture!;\n entries.push({ binding: b++, resource: thickness.view });\n entries.push({ binding: b++, resource: thickness.sampler });\n }\n return b;\n },\n textures(mat, out) {\n const tex = (mat as PbrMaterialProps).subsurface?.refraction?.texture;\n if (tex) {\n out.push(tex);\n }\n const thickness = (mat as PbrMaterialProps).subsurface?.thickness?.texture;\n if (thickness) {\n out.push(thickness);\n }\n },\n };\n}\n","import type { SceneContext } from \"../../scene/scene.js\";\nimport type { EngineContext } from \"../../engine/engine.js\";\nimport type { PbrExt } from \"./pbr-flags.js\";\nimport { enableSceneTransmission } from \"../../frame-graph/transmission.js\";\nimport { makeRefractionRttExt } from \"./fragments/refraction-rtt-fragment.js\";\n\nexport function registerPbrTransmission(scene: SceneContext, engine: EngineContext, register: (ext: PbrExt) => void, dispersionSampleWgsl?: string): void {\n enableSceneTransmission(scene, engine);\n register(makeRefractionRttExt(dispersionSampleWgsl));\n}\n"],"names":[],"mappings":";AAeA,MAAM,gCAAgC,EAAE,IAAI,iCAAiC,IAAI,IAAA;AAEjF,SAAS,kBACL,WACA,QACA,iBACA,yBACA,eACA,sBACM;AACN,QAAM,qBAAqB,aAAa,kBAAkB,oGAAoG;AAC9J,QAAM,gBAAgB,kBAChB,uEAAuE,0BAA0B,MAAM,GAAG;AAAA,0EAE1G,YACE,2CACA;AACR,QAAM,cAAc,SAAS,4GAA4G;AACzI,QAAM,iBAAiB,YAAY,8CAA8C;AACjF,QAAM,iBAAiB,YACjB,sFACA;AAMN,QAAM,cACF,iBAAiB,uBACX,uBACA;AAAA;AAAA;AAAA;AAKV,SAAO;AAAA,EACT,kBAAkB;AAAA,EAClB,WAAW;AAAA,EACX,aAAa;AAAA;AAAA;AAAA;AAAA,EAIb,WAAW;AAAA,EACX,cAAc;AAAA,EACd,cAAc;AAAA;AAAA;AAGhB;AAEA,SAAS,4BACL,WACA,QACA,iBACA,yBAC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ECTANCE_MAP, af as PBR_HAS_REFLECTANCE_MAP, ag as PBR2_HAS_REFLECTANCE_FACTORS, ah as PBR2_HAS_UV2, ai as PBR_HAS_USE_ALPHA_ONLY_MR } from "./index-B7Qhw0xL.js";
|
|
2
2
|
const STAGE_FRAGMENT = 2;
|
|
3
3
|
function writeReflectanceUBO(data, material, offsets) {
|
|
4
4
|
if (!offsets.has("occlusionStrength")) {
|
|
@@ -140,4 +140,4 @@ export {
|
|
|
140
140
|
pbrExt,
|
|
141
141
|
writeReflectanceUBO
|
|
142
142
|
};
|
|
143
|
-
//# sourceMappingURL=reflectance-fragment-
|
|
143
|
+
//# sourceMappingURL=reflectance-fragment-ejMJ4O1o.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reflectance-fragment-BCrgPmrt.js","sources":["../src/material/pbr/fragments/reflectance-fragment.ts"],"sourcesContent":["/**\n * Metallic Reflectance Fragment\n *\n * Advanced F0 computation with metallicReflectanceTexture and/or reflectanceTexture.\n * Only bundled when a scene uses these textures.\n *\n * Provides: UBO fields (occlusionStrength, metallicF0Factor, specularWeight, metallicReflectanceColor),\n * conditional texture bindings, F0 computation, and occlusion handling.\n */\n\nimport type { ShaderFragment, BindingDecl } from \"../../../shader/fragment-types.js\";\nimport type { PbrMaterialProps } from \"../pbr-material.js\";\nimport type { PbrExt } from \"../pbr-flags.js\";\nimport { PBR_HAS_METALLIC_REFLECTANCE_MAP, PBR_HAS_REFLECTANCE_MAP, PBR_HAS_USE_ALPHA_ONLY_MR, PBR2_HAS_REFLECTANCE_FACTORS, PBR2_HAS_UV2 } from \"../pbr-flag-bits.js\";\n\n// WebGPU shader stage constants\nconst STAGE_FRAGMENT = 0x2;\n\n/** Write the reflectance-extension material-UBO slice\n * (occlusionStrength, metallicF0Factor, specularWeight, metallicReflectanceColor).\n * Gated by the presence of the `occlusionStrength` field in the UBO spec,\n * which is added only when a metallic-reflectance or reflectance texture\n * is in use. */\nexport function writeReflectanceUBO(data: Float32Array, material: PbrMaterialProps, offsets: ReadonlyMap<string, number>): void {\n if (!offsets.has(\"occlusionStrength\")) {\n return;\n }\n const off = offsets.get(\"occlusionStrength\")! / 4;\n data[off] = material.occlusionStrength ?? 1.0;\n data[off + 1] = material.metallicF0Factor ?? 1.0;\n data[off + 2] = material.specularWeight ?? material.metallicF0Factor ?? 1.0;\n const mrc = material.metallicReflectanceColor;\n data[off + 4] = mrc ? mrc[0]! : 1.0;\n data[off + 5] = mrc ? mrc[1]! : 1.0;\n data[off + 6] = mrc ? mrc[2]! : 1.0;\n}\n\n/**\n * Create a metallic reflectance fragment.\n * @param hasMetallicReflectanceMap - Whether the material has a metallicReflectanceTexture.\n * @param hasReflectanceMap - Whether the material has a reflectanceTexture.\n * @param useAlphaOnlyMR - Whether to use only the alpha channel from the metallic reflectance map.\n */\nexport function createReflectanceFragment(\n hasMetallicReflectanceMap: boolean,\n hasReflectanceMap: boolean,\n useAlphaOnlyMR: boolean,\n hasOcclusionUv2: boolean = false\n): ShaderFragment {\n const bindings: BindingDecl[] = [];\n if (hasMetallicReflectanceMap) {\n bindings.push(\n { _name: \"metallicReflectanceMap\", _type: { _kind: \"texture\", _textureType: \"texture_2d<f32>\" }, _visibility: STAGE_FRAGMENT },\n { _name: \"metallicReflectanceMapSampler\", _type: { _kind: \"sampler\", _samplerType: \"sampler\" }, _visibility: STAGE_FRAGMENT }\n );\n }\n if (hasReflectanceMap) {\n bindings.push(\n { _name: \"reflectanceMap\", _type: { _kind: \"texture\", _textureType: \"texture_2d<f32>\" }, _visibility: STAGE_FRAGMENT },\n { _name: \"reflectanceMapSampler\", _type: { _kind: \"sampler\", _samplerType: \"sampler\" }, _visibility: STAGE_FRAGMENT }\n );\n }\n\n // Build F0 computation code\n let f0Code = `var mrFactors = vec4<f32>(material.metallicReflectanceColor, material.metallicF0Factor);\nvar specularWeight = material.specularWeight;`;\n if (hasReflectanceMap) {\n f0Code += `\n{ let rSample = textureSample(reflectanceMap, reflectanceMapSampler, input.uv);\n let rLinear = pow(rSample.rgb, vec3<f32>(2.2));\n mrFactors = vec4<f32>(mrFactors.rgb * rLinear, mrFactors.a); }`;\n }\n if (hasMetallicReflectanceMap) {\n if (!useAlphaOnlyMR) {\n f0Code += `\n{ let mrSample = textureSample(metallicReflectanceMap, metallicReflectanceMapSampler, input.uv);\n let mrLinear = pow(mrSample.rgb, vec3<f32>(2.2));\n mrFactors = vec4<f32>(mrFactors.rgb * mrLinear, mrFactors.a * mrSample.a);\n specularWeight *= mrSample.a; }`;\n } else {\n f0Code += `\n{ let mrSample = textureSample(metallicReflectanceMap, metallicReflectanceMapSampler, input.uv);\n mrFactors = vec4<f32>(mrFactors.rgb, mrFactors.a * mrSample.a);\n specularWeight *= mrSample.a; }`;\n }\n }\n f0Code += `\nlet dielectricF0 = material.reflectance * mrFactors.a;\nlet surfaceReflectivityColor = mrFactors.rgb;\nlet dielectricColorF0 = vec3<f32>(dielectricF0) * surfaceReflectivityColor;\nlet metallicColorF0 = baseColor;\nvar colorF0 = mix(dielectricColorF0, metallicColorF0, metallic);\nlet colorF90 = vec3<f32>(mix(specularWeight, 1.0, metallic));\nlet surfaceAlbedo = baseColor * (vec3<f32>(1.0) - vec3<f32>(dielectricF0) * surfaceReflectivityColor) * (1.0 - metallic);`;\n\n return {\n _id: \"reflectance\",\n\n _uboFields: [\n { _name: \"occlusionStrength\", _type: \"f32\" },\n { _name: \"metallicF0Factor\", _type: \"f32\" },\n { _name: \"specularWeight\", _type: \"f32\" },\n { _name: \"_mrPad1\", _type: \"f32\" },\n { _name: \"metallicReflectanceColor\", _type: \"vec3<f32>\" },\n { _name: \"_mrPad2\", _type: \"f32\" },\n ],\n\n _bindings: bindings,\n\n _fragmentSlots: {\n MF: f0Code,\n AT: hasOcclusionUv2\n ? `let occlusion = mix(1.0, textureSample(occlusionTexture, occlusionSampler_, input.uv2).r, material.occlusionStrength);`\n : `let occlusion = mix(1.0, orm.r, material.occlusionStrength);`,\n },\n };\n}\n\n/** Create the reflectance PBR extension (group 1, fragment phase). */\nexport const pbrExt: PbrExt = {\n id: \"reflectance\",\n phase: \"fragment\",\n detect(mat) {\n const m = mat as PbrMaterialProps;\n let f = 0;\n let f2 = 0;\n if (m.metallicReflectanceTexture) {\n f |= PBR_HAS_METALLIC_REFLECTANCE_MAP;\n }\n if (m.reflectanceTexture) {\n f |= PBR_HAS_REFLECTANCE_MAP;\n }\n if (f === 0) {\n const hasNonDefaultF0 = m.metallicF0Factor != null && Math.abs(m.metallicF0Factor - 1) > 1e-6;\n const mrc = m.metallicReflectanceColor;\n const hasNonDefaultColor = mrc != null && (mrc[0] !== 1 || mrc[1] !== 1 || mrc[2] !== 1);\n if (hasNonDefaultF0 || hasNonDefaultColor) {\n f2 |= PBR2_HAS_REFLECTANCE_FACTORS;\n }\n }\n if ((f !== 0 || f2 & PBR2_HAS_REFLECTANCE_FACTORS) && m.useOnlyMetallicFromMetallicReflectanceTexture) {\n f |= PBR_HAS_USE_ALPHA_ONLY_MR;\n }\n return { f, f2 };\n },\n frag(ctx) {\n const hasMR = (ctx._features & PBR_HAS_METALLIC_REFLECTANCE_MAP) !== 0;\n const hasR = (ctx._features & PBR_HAS_REFLECTANCE_MAP) !== 0;\n const hasFactors = (ctx._features2 & PBR2_HAS_REFLECTANCE_FACTORS) !== 0;\n if (!hasMR && !hasR && !hasFactors) {\n return null;\n }\n return createReflectanceFragment(hasMR, hasR, (ctx._features & PBR_HAS_USE_ALPHA_ONLY_MR) !== 0, (ctx._features2 & PBR2_HAS_UV2) !== 0);\n },\n writeUbo: writeReflectanceUBO as PbrExt[\"writeUbo\"],\n bind(ctx, entries, b) {\n if ((ctx._features & (PBR_HAS_METALLIC_REFLECTANCE_MAP | PBR_HAS_REFLECTANCE_MAP)) === 0) {\n return b;\n }\n const m = ctx._material as PbrMaterialProps;\n if (m.metallicReflectanceTexture) {\n entries.push({ binding: b++, resource: m.metallicReflectanceTexture.view });\n entries.push({ binding: b++, resource: m.metallicReflectanceTexture.sampler });\n }\n if (m.reflectanceTexture) {\n entries.push({ binding: b++, resource: m.reflectanceTexture.view });\n entries.push({ binding: b++, resource: m.reflectanceTexture.sampler });\n }\n return b;\n },\n textures(mat, t) {\n const m = mat as PbrMaterialProps;\n if (m.metallicReflectanceTexture) {\n t.push(m.metallicReflectanceTexture);\n }\n if (m.reflectanceTexture) {\n t.push(m.reflectanceTexture);\n }\n },\n};\n"],"names":[],"mappings":";AAgBA,MAAM,iBAAiB;AAOhB,SAAS,oBAAoB,MAAoB,UAA4B,SAA4C;AAC5H,MAAI,CAAC,QAAQ,IAAI,mBAAmB,GAAG;AACnC;AAAA,EACJ;AACA,QAAM,MAAM,QAAQ,IAAI,mBAAmB,IAAK;AAChD,OAAK,GAAG,IAAI,SAAS,qBAAqB;AAC1C,OAAK,MAAM,CAAC,IAAI,SAAS,oBAAoB;AAC7C,OAAK,MAAM,CAAC,IAAI,SAAS,kBAAkB,SAAS,oBAAoB;AACxE,QAAM,MAAM,SAAS;AACrB,OAAK,MAAM,CAAC,IAAI,MAAM,IAAI,CAAC,IAAK;AAChC,OAAK,MAAM,CAAC,IAAI,MAAM,IAAI,CAAC,IAAK;AAChC,OAAK,MAAM,CAAC,IAAI,MAAM,IAAI,CAAC,IAAK;AACpC;AAQO,SAAS,0BACZ,2BACA,mBACA,gBACA,kBAA2B,OACb;AACd,QAAM,WAA0B,CAAA;AAChC,MAAI,2BAA2B;AAC3B,aAAS;AAAA,MACL,EAAE,OAAO,0BAA0B,OAAO,EAAE,OAAO,WAAW,cAAc,kBAAA,GAAqB,aAAa,eAAA;AAAA,MAC9G,EAAE,OAAO,iCAAiC,OAAO,EAAE,OAAO,WAAW,cAAc,aAAa,aAAa,eAAA;AAAA,IAAe;AAAA,EAEpI;AACA,MAAI,mBAAmB;AACnB,aAAS;AAAA,MACL,EAAE,OAAO,kBAAkB,OAAO,EAAE,OAAO,WAAW,cAAc,kBAAA,GAAqB,aAAa,eAAA;AAAA,MACtG,EAAE,OAAO,yBAAyB,OAAO,EA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":"reflectance-fragment-ejMJ4O1o.js","sources":["../src/material/pbr/fragments/reflectance-fragment.ts"],"sourcesContent":["/**\n * Metallic Reflectance Fragment\n *\n * Advanced F0 computation with metallicReflectanceTexture and/or reflectanceTexture.\n * Only bundled when a scene uses these textures.\n *\n * Provides: UBO fields (occlusionStrength, metallicF0Factor, specularWeight, metallicReflectanceColor),\n * conditional texture bindings, F0 computation, and occlusion handling.\n */\n\nimport type { ShaderFragment, BindingDecl } from \"../../../shader/fragment-types.js\";\nimport type { PbrMaterialProps } from \"../pbr-material.js\";\nimport type { PbrExt } from \"../pbr-flags.js\";\nimport { PBR_HAS_METALLIC_REFLECTANCE_MAP, PBR_HAS_REFLECTANCE_MAP, PBR_HAS_USE_ALPHA_ONLY_MR, PBR2_HAS_REFLECTANCE_FACTORS, PBR2_HAS_UV2 } from \"../pbr-flag-bits.js\";\n\n// WebGPU shader stage constants\nconst STAGE_FRAGMENT = 0x2;\n\n/** Write the reflectance-extension material-UBO slice\n * (occlusionStrength, metallicF0Factor, specularWeight, metallicReflectanceColor).\n * Gated by the presence of the `occlusionStrength` field in the UBO spec,\n * which is added only when a metallic-reflectance or reflectance texture\n * is in use. */\nexport function writeReflectanceUBO(data: Float32Array, material: PbrMaterialProps, offsets: ReadonlyMap<string, number>): void {\n if (!offsets.has(\"occlusionStrength\")) {\n return;\n }\n const off = offsets.get(\"occlusionStrength\")! / 4;\n data[off] = material.occlusionStrength ?? 1.0;\n data[off + 1] = material.metallicF0Factor ?? 1.0;\n data[off + 2] = material.specularWeight ?? material.metallicF0Factor ?? 1.0;\n const mrc = material.metallicReflectanceColor;\n data[off + 4] = mrc ? mrc[0]! : 1.0;\n data[off + 5] = mrc ? mrc[1]! : 1.0;\n data[off + 6] = mrc ? mrc[2]! : 1.0;\n}\n\n/**\n * Create a metallic reflectance fragment.\n * @param hasMetallicReflectanceMap - Whether the material has a metallicReflectanceTexture.\n * @param hasReflectanceMap - Whether the material has a reflectanceTexture.\n * @param useAlphaOnlyMR - Whether to use only the alpha channel from the metallic reflectance map.\n */\nexport function createReflectanceFragment(\n hasMetallicReflectanceMap: boolean,\n hasReflectanceMap: boolean,\n useAlphaOnlyMR: boolean,\n hasOcclusionUv2: boolean = false\n): ShaderFragment {\n const bindings: BindingDecl[] = [];\n if (hasMetallicReflectanceMap) {\n bindings.push(\n { _name: \"metallicReflectanceMap\", _type: { _kind: \"texture\", _textureType: \"texture_2d<f32>\" }, _visibility: STAGE_FRAGMENT },\n { _name: \"metallicReflectanceMapSampler\", _type: { _kind: \"sampler\", _samplerType: \"sampler\" }, _visibility: STAGE_FRAGMENT }\n );\n }\n if (hasReflectanceMap) {\n bindings.push(\n { _name: \"reflectanceMap\", _type: { _kind: \"texture\", _textureType: \"texture_2d<f32>\" }, _visibility: STAGE_FRAGMENT },\n { _name: \"reflectanceMapSampler\", _type: { _kind: \"sampler\", _samplerType: \"sampler\" }, _visibility: STAGE_FRAGMENT }\n );\n }\n\n // Build F0 computation code\n let f0Code = `var mrFactors = vec4<f32>(material.metallicReflectanceColor, material.metallicF0Factor);\nvar specularWeight = material.specularWeight;`;\n if (hasReflectanceMap) {\n f0Code += `\n{ let rSample = textureSample(reflectanceMap, reflectanceMapSampler, input.uv);\n let rLinear = pow(rSample.rgb, vec3<f32>(2.2));\n mrFactors = vec4<f32>(mrFactors.rgb * rLinear, mrFactors.a); }`;\n }\n if (hasMetallicReflectanceMap) {\n if (!useAlphaOnlyMR) {\n f0Code += `\n{ let mrSample = textureSample(metallicReflectanceMap, metallicReflectanceMapSampler, input.uv);\n let mrLinear = pow(mrSample.rgb, vec3<f32>(2.2));\n mrFactors = vec4<f32>(mrFactors.rgb * mrLinear, mrFactors.a * mrSample.a);\n specularWeight *= mrSample.a; }`;\n } else {\n f0Code += `\n{ let mrSample = textureSample(metallicReflectanceMap, metallicReflectanceMapSampler, input.uv);\n mrFactors = vec4<f32>(mrFactors.rgb, mrFactors.a * mrSample.a);\n specularWeight *= mrSample.a; }`;\n }\n }\n f0Code += `\nlet dielectricF0 = material.reflectance * mrFactors.a;\nlet surfaceReflectivityColor = mrFactors.rgb;\nlet dielectricColorF0 = vec3<f32>(dielectricF0) * surfaceReflectivityColor;\nlet metallicColorF0 = baseColor;\nvar colorF0 = mix(dielectricColorF0, metallicColorF0, metallic);\nlet colorF90 = vec3<f32>(mix(specularWeight, 1.0, metallic));\nlet surfaceAlbedo = baseColor * (vec3<f32>(1.0) - vec3<f32>(dielectricF0) * surfaceReflectivityColor) * (1.0 - metallic);`;\n\n return {\n _id: \"reflectance\",\n\n _uboFields: [\n { _name: \"occlusionStrength\", _type: \"f32\" },\n { _name: \"metallicF0Factor\", _type: \"f32\" },\n { _name: \"specularWeight\", _type: \"f32\" },\n { _name: \"_mrPad1\", _type: \"f32\" },\n { _name: \"metallicReflectanceColor\", _type: \"vec3<f32>\" },\n { _name: \"_mrPad2\", _type: \"f32\" },\n ],\n\n _bindings: bindings,\n\n _fragmentSlots: {\n MF: f0Code,\n AT: hasOcclusionUv2\n ? `let occlusion = mix(1.0, textureSample(occlusionTexture, occlusionSampler_, input.uv2).r, material.occlusionStrength);`\n : `let occlusion = mix(1.0, orm.r, material.occlusionStrength);`,\n },\n };\n}\n\n/** Create the reflectance PBR extension (group 1, fragment phase). */\nexport const pbrExt: PbrExt = {\n id: \"reflectance\",\n phase: \"fragment\",\n detect(mat) {\n const m = mat as PbrMaterialProps;\n let f = 0;\n let f2 = 0;\n if (m.metallicReflectanceTexture) {\n f |= PBR_HAS_METALLIC_REFLECTANCE_MAP;\n }\n if (m.reflectanceTexture) {\n f |= PBR_HAS_REFLECTANCE_MAP;\n }\n if (f === 0) {\n const hasNonDefaultF0 = m.metallicF0Factor != null && Math.abs(m.metallicF0Factor - 1) > 1e-6;\n const mrc = m.metallicReflectanceColor;\n const hasNonDefaultColor = mrc != null && (mrc[0] !== 1 || mrc[1] !== 1 || mrc[2] !== 1);\n if (hasNonDefaultF0 || hasNonDefaultColor) {\n f2 |= PBR2_HAS_REFLECTANCE_FACTORS;\n }\n }\n if ((f !== 0 || f2 & PBR2_HAS_REFLECTANCE_FACTORS) && m.useOnlyMetallicFromMetallicReflectanceTexture) {\n f |= PBR_HAS_USE_ALPHA_ONLY_MR;\n }\n return { f, f2 };\n },\n frag(ctx) {\n const hasMR = (ctx._features & PBR_HAS_METALLIC_REFLECTANCE_MAP) !== 0;\n const hasR = (ctx._features & PBR_HAS_REFLECTANCE_MAP) !== 0;\n const hasFactors = (ctx._features2 & PBR2_HAS_REFLECTANCE_FACTORS) !== 0;\n if (!hasMR && !hasR && !hasFactors) {\n return null;\n }\n return createReflectanceFragment(hasMR, hasR, (ctx._features & PBR_HAS_USE_ALPHA_ONLY_MR) !== 0, (ctx._features2 & PBR2_HAS_UV2) !== 0);\n },\n writeUbo: writeReflectanceUBO as PbrExt[\"writeUbo\"],\n bind(ctx, entries, b) {\n if ((ctx._features & (PBR_HAS_METALLIC_REFLECTANCE_MAP | PBR_HAS_REFLECTANCE_MAP)) === 0) {\n return b;\n }\n const m = ctx._material as PbrMaterialProps;\n if (m.metallicReflectanceTexture) {\n entries.push({ binding: b++, resource: m.metallicReflectanceTexture.view });\n entries.push({ binding: b++, resource: m.metallicReflectanceTexture.sampler });\n }\n if (m.reflectanceTexture) {\n entries.push({ binding: b++, resource: m.reflectanceTexture.view });\n entries.push({ binding: b++, resource: m.reflectanceTexture.sampler });\n }\n return b;\n },\n textures(mat, t) {\n const m = mat as PbrMaterialProps;\n if (m.metallicReflectanceTexture) {\n t.push(m.metallicReflectanceTexture);\n }\n if (m.reflectanceTexture) {\n t.push(m.reflectanceTexture);\n }\n },\n};\n"],"names":[],"mappings":";AAgBA,MAAM,iBAAiB;AAOhB,SAAS,oBAAoB,MAAoB,UAA4B,SAA4C;AAC5H,MAAI,CAAC,QAAQ,IAAI,mBAAmB,GAAG;AACnC;AAAA,EACJ;AACA,QAAM,MAAM,QAAQ,IAAI,mBAAmB,IAAK;AAChD,OAAK,GAAG,IAAI,SAAS,qBAAqB;AAC1C,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AAkB,CAAC;AAAA,EAC1I;AAAA,EACA,UAAU;AAAA,EACV,KAAK,KAAK,SAAS,GAAG;AAClB,SAAK,IAAI,aAAa,mCAAmC,8BAA8B,GAAG;AACtF,aAAO;AAAA,IACX;AACA,UAAM,IAAI,IAAI;AACd,QAAI,EAAE,4BAA4B;AAC9B,cAAQ,KAAK,EAAE,SAAS,KAAK,UAAU,EAAE,2BAA2B,MAAM;AAC1E,cAAQ,KAAK,EAAE,SAAS,KAAK,UAAU,EAAE,2BAA2B,SAAS;AAAA,IACjF;AACA,QAAI,EAAE,oBAAoB;AACtB,cAAQ,KAAK,EAAE,SAAS,KAAK,UAAU,EAAE,mBAAmB,MAAM;AAClE,cAAQ,KAAK,EAAE,SAAS,KAAK,UAAU,EAAE,mBAAmB,SAAS;AAAA,IACzE;AACA,WAAO;AAAA,EACX;AAAA,EACA,SAAS,KAAK,GAAG;AACb,UAAM,IAAI;AACV,QAAI,EAAE,4BAA4B;AAC9B,QAAE,KAAK,EAAE,0BAA0B;AAAA,IACvC;AACA,QAAI,EAAE,oBAAoB;AACtB,QAAE,KAAK,EAAE,kBAAkB;AAAA,IAC/B;AAAA,EACJ;AACJ;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t as targetSignatureKey, j as getSceneBindGroupLayout, b3 as _isShaderSystemUniform, b1 as computeUboLayout, a$ as SCENE_UBO_WGSL, I as createEmptyUniformBuffer, b4 as acquireTexture, b5 as releaseTexture, b6 as getEffectiveAspectRatio, x as getViewMatrix, y as getProjectionMatrix, b2 as getViewProjectionMatrix, aH as mat4MultiplyInto } from "./index-B7Qhw0xL.js";
|
|
2
2
|
const SHADER_STAGE_ALL = GPUShaderStage.VERTEX | GPUShaderStage.FRAGMENT;
|
|
3
3
|
function getOrCreateShaderPipelineBindings(engine, material) {
|
|
4
4
|
const state = material;
|
|
@@ -28,14 +28,14 @@ function getOrCreateShaderPipelineBindings(engine, material) {
|
|
|
28
28
|
state._shaderCustomVersion = -1;
|
|
29
29
|
return bindings;
|
|
30
30
|
}
|
|
31
|
-
function getOrCreateShaderPipeline(engine, sig, material, bindings) {
|
|
32
|
-
const key = targetSignatureKey(sig)
|
|
31
|
+
function getOrCreateShaderPipeline(engine, sig, material, bindings, variantKey = "", vertexBuffers = bindings.vertexBuffers, instanceAttrs = "") {
|
|
32
|
+
const key = `${targetSignatureKey(sig)}${variantKey}`;
|
|
33
33
|
const cached = bindings.pipelines.get(key);
|
|
34
34
|
if (cached) {
|
|
35
35
|
return cached;
|
|
36
36
|
}
|
|
37
37
|
const device = engine._device;
|
|
38
|
-
const prelude = buildShaderPrelude(material, bindings.systemSpec, bindings.customSpec);
|
|
38
|
+
const prelude = buildShaderPrelude(material, bindings.systemSpec, bindings.customSpec, instanceAttrs);
|
|
39
39
|
const vertModule = device.createShaderModule({ label: `${material.name ?? "shader"}-vertex`, code: `${prelude}
|
|
40
40
|
${material.vertexSource}` });
|
|
41
41
|
const fragModule = sig._colorFormat ? device.createShaderModule({ label: `${material.name ?? "shader"}-fragment`, code: `${prelude}
|
|
@@ -55,7 +55,7 @@ ${material.fragmentSource}` }) : null;
|
|
|
55
55
|
const pipeline = device.createRenderPipeline({
|
|
56
56
|
label: `${material.name ?? "shader"}-pipeline`,
|
|
57
57
|
layout: device.createPipelineLayout({ bindGroupLayouts: [getSceneBindGroupLayout(engine), bindings.group1BGL] }),
|
|
58
|
-
vertex: { module: vertModule, entryPoint: "mainVertex", buffers:
|
|
58
|
+
vertex: { module: vertModule, entryPoint: "mainVertex", buffers: vertexBuffers },
|
|
59
59
|
...fragModule && colorTarget ? { fragment: { module: fragModule, entryPoint: "mainFragment", targets: [colorTarget] } } : {},
|
|
60
60
|
...sig._depthStencilFormat ? {
|
|
61
61
|
depthStencil: {
|
|
@@ -80,19 +80,20 @@ function buildBindGroupLayoutEntries(samplers, hasCustomUbo) {
|
|
|
80
80
|
entries.push({ binding: nextBinding++, visibility: SHADER_STAGE_ALL, buffer: { type: "uniform" } });
|
|
81
81
|
}
|
|
82
82
|
for (const sampler of samplers) {
|
|
83
|
-
const
|
|
83
|
+
const isArray = sampler.viewDimension === "2d-array";
|
|
84
|
+
const sampleType = sampler.comparison === true ? "depth" : sampler.sampleType ?? "float";
|
|
84
85
|
entries.push({
|
|
85
86
|
binding: nextBinding++,
|
|
86
87
|
visibility: SHADER_STAGE_ALL,
|
|
87
88
|
texture: {
|
|
88
89
|
sampleType,
|
|
89
|
-
viewDimension: "2d"
|
|
90
|
+
viewDimension: isArray ? "2d-array" : "2d"
|
|
90
91
|
}
|
|
91
92
|
});
|
|
92
93
|
entries.push({
|
|
93
94
|
binding: nextBinding++,
|
|
94
95
|
visibility: SHADER_STAGE_ALL,
|
|
95
|
-
sampler: { type: sampleType === "float" ? "filtering" : "non-filtering" }
|
|
96
|
+
sampler: { type: sampler.comparison === true ? "comparison" : sampleType === "float" ? "filtering" : "non-filtering" }
|
|
96
97
|
});
|
|
97
98
|
}
|
|
98
99
|
return entries;
|
|
@@ -110,7 +111,7 @@ function attributeLayout(name, shaderLocation) {
|
|
|
110
111
|
return { arrayStride: 16, attributes: [{ shaderLocation, offset: 0, format: "float32x4" }] };
|
|
111
112
|
}
|
|
112
113
|
}
|
|
113
|
-
function buildShaderPrelude(material, systemSpec, customSpec) {
|
|
114
|
+
function buildShaderPrelude(material, systemSpec, customSpec, instanceAttrs = "") {
|
|
114
115
|
let wgsl = `${SCENE_UBO_WGSL}
|
|
115
116
|
struct ShaderSystemUniforms {
|
|
116
117
|
${systemSpec._structBody}
|
|
@@ -126,9 +127,12 @@ ${customSpec._structBody}
|
|
|
126
127
|
}
|
|
127
128
|
let nextBinding = customSpec ? 2 : 1;
|
|
128
129
|
for (const sampler of material.samplerDecls) {
|
|
129
|
-
const
|
|
130
|
+
const isArray = sampler.viewDimension === "2d-array";
|
|
131
|
+
const isDepth = sampler.comparison === true || sampler.sampleType === "depth";
|
|
132
|
+
const texType = isDepth ? isArray ? "texture_depth_2d_array" : "texture_depth_2d" : isArray ? "texture_2d_array<f32>" : "texture_2d<f32>";
|
|
133
|
+
const samplerType = sampler.comparison === true ? "sampler_comparison" : "sampler";
|
|
130
134
|
wgsl += `@group(1) @binding(${nextBinding++}) var ${sampler.name}: ${texType};
|
|
131
|
-
@group(1) @binding(${nextBinding++}) var ${sampler.name}Sampler:
|
|
135
|
+
@group(1) @binding(${nextBinding++}) var ${sampler.name}Sampler: ${samplerType};
|
|
132
136
|
`;
|
|
133
137
|
}
|
|
134
138
|
for (const define of material.defines) {
|
|
@@ -142,6 +146,7 @@ ${customSpec._structBody}
|
|
|
142
146
|
wgsl += `@location(${i}) ${attr}: ${attributeWgslType(attr)},
|
|
143
147
|
`;
|
|
144
148
|
}
|
|
149
|
+
wgsl += instanceAttrs;
|
|
145
150
|
wgsl += `};
|
|
146
151
|
`;
|
|
147
152
|
return wgsl;
|
|
@@ -187,6 +192,28 @@ function buildShaderMaterialRenderables(scene, meshes) {
|
|
|
187
192
|
}
|
|
188
193
|
return { renderables, rebuildSingle };
|
|
189
194
|
}
|
|
195
|
+
async function buildShaderGroup(scene, meshes) {
|
|
196
|
+
if (!meshes.some((m) => !!m.thinInstances)) {
|
|
197
|
+
return buildShaderMaterialRenderables(scene, meshes);
|
|
198
|
+
}
|
|
199
|
+
const mod = await import("./shader-thin-instance-5_WUfi3m.js");
|
|
200
|
+
const cull = meshes.some((m) => {
|
|
201
|
+
var _a;
|
|
202
|
+
return !!((_a = m.thinInstances) == null ? void 0 : _a._gpuCullingEnabled);
|
|
203
|
+
}) ? await import("./thin-instance-cull-binding-CCxrPNO6.js") : void 0;
|
|
204
|
+
return mod.buildShaderRenderablesWithInstancing(
|
|
205
|
+
scene,
|
|
206
|
+
meshes,
|
|
207
|
+
buildShaderMaterialRenderables,
|
|
208
|
+
createPacket,
|
|
209
|
+
updatePacket,
|
|
210
|
+
updateCustomUbo,
|
|
211
|
+
getAttrBuffer,
|
|
212
|
+
getOrCreateShaderPipeline,
|
|
213
|
+
getOrCreateShaderPipelineBindings,
|
|
214
|
+
cull
|
|
215
|
+
);
|
|
216
|
+
}
|
|
190
217
|
function buildSingleShaderRenderable(scene, mesh, material, isOverride) {
|
|
191
218
|
return buildMaterialRenderables(scene, material, [mesh], isOverride)[0];
|
|
192
219
|
}
|
|
@@ -294,6 +321,7 @@ function createTransparentRenderable(scene, material, packet, isOverride) {
|
|
|
294
321
|
const r = {
|
|
295
322
|
order: packet.mesh.renderOrder ?? 200,
|
|
296
323
|
isTransparent: true,
|
|
324
|
+
_transmissive: material.transmissive,
|
|
297
325
|
mesh: packet.mesh,
|
|
298
326
|
_worldCenter: sortCenter,
|
|
299
327
|
bind(eng, sig) {
|
|
@@ -526,6 +554,7 @@ function getAttrBuffer(engine, gpu, name) {
|
|
|
526
554
|
}
|
|
527
555
|
}
|
|
528
556
|
export {
|
|
557
|
+
buildShaderGroup,
|
|
529
558
|
buildShaderMaterialRenderables
|
|
530
559
|
};
|
|
531
|
-
//# sourceMappingURL=shader-renderable-
|
|
560
|
+
//# sourceMappingURL=shader-renderable-BMf_vvO0.js.map
|